@@ -509,14 +509,6 @@ abstract contract EvmHost is IIsmpHost, IHostManager, Context {
509
509
return _hostParams.stateCommitmentFee;
510
510
}
511
511
512
- /**
513
- * @dev Returns the fisherman responsible for vetoing the given state machine height.
514
- * @return the `fisherman` address
515
- */
516
- function vetoes (uint256 paraId , uint256 height ) external view returns (address ) {
517
- return _vetoes[paraId][height];
518
- }
519
-
520
512
/**
521
513
* @dev Returns the nonce immediately available for requests
522
514
* @return the `nonce`
@@ -525,51 +517,6 @@ abstract contract EvmHost is IIsmpHost, IHostManager, Context {
525
517
return _nonce;
526
518
}
527
519
528
- /**
529
- * @notice Charges the stateCommitmentFee to 3rd party applications.
530
- * If native tokens are provided, will attempt to swap them for the stateCommitmentFee.
531
- * If not enough native tokens are supplied, will revert.
532
- *
533
- * If no native tokens are provided then it will try to collect payment from the calling contract in
534
- * the IIsmpHost.feeToken.
535
- *
536
- * @param height - state machine height
537
- * @return the state commitment at `height`
538
- */
539
- function stateMachineCommitment (
540
- StateMachineHeight memory height
541
- ) external payable returns (StateCommitment memory ) {
542
- address caller = _msgSender ();
543
- if (caller != _hostParams.handler) {
544
- uint256 fee = _hostParams.stateCommitmentFee;
545
- if (msg .value > 0 ) {
546
- address [] memory path = new address [](2 );
547
- address uniswapV2 = _hostParams.uniswapV2;
548
- path[0 ] = IUniswapV2Router02 (uniswapV2).WETH ();
549
- path[1 ] = feeToken ();
550
- IUniswapV2Router02 (uniswapV2).swapETHForExactTokens {value: msg .value }(
551
- fee,
552
- path,
553
- address (this ),
554
- block .timestamp
555
- );
556
- } else {
557
- SafeERC20.safeTransferFrom (IERC20 (feeToken ()), caller, address (this ), fee);
558
- }
559
- emit StateCommitmentRead ({caller: caller, fee: fee});
560
- }
561
-
562
- return _stateCommitments[height.stateMachineId][height.height];
563
- }
564
-
565
- /**
566
- * @param height - state machine height
567
- * @return the state machine update time at `height`
568
- */
569
- function stateMachineCommitmentUpdateTime (StateMachineHeight memory height ) external view returns (uint256 ) {
570
- return _stateCommitmentsUpdateTime[height.stateMachineId][height.height];
571
- }
572
-
573
520
/**
574
521
* @dev Should return a handle to the consensus client based on the id
575
522
* @return the consensus client contract
@@ -599,6 +546,13 @@ abstract contract EvmHost is IIsmpHost, IHostManager, Context {
599
546
return _hostParams.challengePeriod;
600
547
}
601
548
549
+ /**
550
+ * @return the unstaking period
551
+ */
552
+ function unStakingPeriod () external view returns (uint256 ) {
553
+ return _hostParams.unStakingPeriod;
554
+ }
555
+
602
556
/**
603
557
* @dev Check the response status for a given request.
604
558
* @param commitment - commitment to the request
@@ -615,13 +569,6 @@ abstract contract EvmHost is IIsmpHost, IHostManager, Context {
615
569
return _latestStateMachineHeight[id];
616
570
}
617
571
618
- /**
619
- * @return the unstaking period
620
- */
621
- function unStakingPeriod () external view returns (uint256 ) {
622
- return _hostParams.unStakingPeriod;
623
- }
624
-
625
572
/**
626
573
* @param commitment - commitment to the request
627
574
* @return existence status of an incoming request commitment
@@ -654,6 +601,59 @@ abstract contract EvmHost is IIsmpHost, IHostManager, Context {
654
601
return _responseCommitments[commitment];
655
602
}
656
603
604
+ /**
605
+ * @dev Returns the fisherman responsible for vetoing the given state machine height.
606
+ * @return the `fisherman` address
607
+ */
608
+ function vetoes (uint256 paraId , uint256 height ) external view returns (address ) {
609
+ return _vetoes[paraId][height];
610
+ }
611
+
612
+ /**
613
+ * @param height - state machine height
614
+ * @return the state machine update time at `height`
615
+ */
616
+ function stateMachineCommitmentUpdateTime (StateMachineHeight memory height ) external view returns (uint256 ) {
617
+ return _stateCommitmentsUpdateTime[height.stateMachineId][height.height];
618
+ }
619
+
620
+ /**
621
+ * @notice Charges the stateCommitmentFee to 3rd party applications.
622
+ * If native tokens are provided, will attempt to swap them for the stateCommitmentFee.
623
+ * If not enough native tokens are supplied, will revert.
624
+ *
625
+ * If no native tokens are provided then it will try to collect payment from the calling contract in
626
+ * the IIsmpHost.feeToken.
627
+ *
628
+ * @param height - state machine height
629
+ * @return the state commitment at `height`
630
+ */
631
+ function stateMachineCommitment (
632
+ StateMachineHeight memory height
633
+ ) external payable returns (StateCommitment memory ) {
634
+ address caller = _msgSender ();
635
+ if (caller != _hostParams.handler) {
636
+ uint256 fee = _hostParams.stateCommitmentFee;
637
+ if (msg .value > 0 ) {
638
+ address [] memory path = new address [](2 );
639
+ address uniswapV2 = _hostParams.uniswapV2;
640
+ path[0 ] = IUniswapV2Router02 (uniswapV2).WETH ();
641
+ path[1 ] = feeToken ();
642
+ IUniswapV2Router02 (uniswapV2).swapETHForExactTokens {value: msg .value }(
643
+ fee,
644
+ path,
645
+ address (this ),
646
+ block .timestamp
647
+ );
648
+ } else {
649
+ SafeERC20.safeTransferFrom (IERC20 (feeToken ()), caller, address (this ), fee);
650
+ }
651
+ emit StateCommitmentRead ({caller: caller, fee: fee});
652
+ }
653
+
654
+ return _stateCommitments[height.stateMachineId][height.height];
655
+ }
656
+
657
657
/**
658
658
* @dev Updates the HostParams, can only be called by cross-chain governance
659
659
* @param params, the new host params.
@@ -705,7 +705,7 @@ abstract contract EvmHost is IIsmpHost, IHostManager, Context {
705
705
address (params.consensusClient).code.length == 0 ||
706
706
! IERC165 (params.consensusClient).supportsInterface (type (IConsensusClient).interfaceId)
707
707
) {
708
- // otherwise cannot process new datagrams
708
+ // otherwise cannot process new consensus datagrams
709
709
revert InvalidConsensusClient ();
710
710
}
711
711
uint256 stateMachinesLen = params.stateMachines.length ;
@@ -1189,6 +1189,18 @@ abstract contract EvmHost is IIsmpHost, IHostManager, Context {
1189
1189
* @return commitment - the request commitment
1190
1190
*/
1191
1191
function dispatch (DispatchPostResponse memory post ) external payable notFrozen returns (bytes32 commitment ) {
1192
+ bytes32 receipt = post.request.hash ();
1193
+ address caller = _msgSender ();
1194
+
1195
+ // known request?
1196
+ if (_requestReceipts[receipt] == address (0 )) revert UnknownRequest ();
1197
+
1198
+ // check that the authorized application is issuing this response
1199
+ if (_bytesToAddress (post.request.to) != caller) revert UnauthorizedResponse ();
1200
+
1201
+ // check that request has not already been respond to
1202
+ if (_responded[receipt]) revert DuplicateResponse ();
1203
+
1192
1204
// minimum charge is the size of one word
1193
1205
uint256 length = 32 > post.response.length ? 32 : post.response.length ;
1194
1206
uint256 fee = (_hostParams.perByteFee * length) + post.fee;
@@ -1208,18 +1220,6 @@ abstract contract EvmHost is IIsmpHost, IHostManager, Context {
1208
1220
SafeERC20.safeTransferFrom (IERC20 (feeToken ()), _msgSender (), address (this ), fee);
1209
1221
}
1210
1222
1211
- bytes32 receipt = post.request.hash ();
1212
- address caller = _msgSender ();
1213
-
1214
- // known request?
1215
- if (_requestReceipts[receipt] == address (0 )) revert UnknownRequest ();
1216
-
1217
- // check that the authorized application is issuing this response
1218
- if (_bytesToAddress (post.request.to) != caller) revert UnauthorizedResponse ();
1219
-
1220
- // check that request has not already been respond to
1221
- if (_responded[receipt]) revert DuplicateResponse ();
1222
-
1223
1223
// adjust the timeout
1224
1224
uint256 timeout = _hostParams.defaultTimeout > post.timeout ? _hostParams.defaultTimeout : post.timeout;
1225
1225
uint64 timeoutTimestamp = post.timeout == 0 ? 0 : uint64 (block .timestamp ) + uint64 (timeout);
0 commit comments