@@ -6,6 +6,7 @@ import { SafeERC20 } from "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.s
66
77// Import MulticallHandler
88import { MulticallHandler } from "../../handlers/MulticallHandler.sol " ;
9+ import { EVMFlowParams, CommonFlowParams } from "./Structs.sol " ;
910
1011/**
1112 * @title ArbitraryEVMFlowExecutor
@@ -43,52 +44,42 @@ abstract contract ArbitraryEVMFlowExecutor {
4344 /**
4445 * @notice Executes arbitrary actions by transferring tokens to MulticallHandler
4546 * @dev Decompresses CompressedCall[] to MulticallHandler.Call[] format (adds value: 0)
46- * @param amount Amount of tokens to transfer to MulticallHandler
47- * @param quoteNonce Unique nonce for this quote
48- * @param initialToken Token to transfer to MulticallHandler
49- * @param finalToken Expected final token after actions
50- * @param actionData Encoded actions: abi.encode(CompressedCall[] calls)
51- * @param extraFeesToSponsorTokenIn Extra fees to sponsor in initialToken
47+ * @param params Parameters of HyperEVM execution
48+ * @return commonParams Parameters to continue sponsored execution to transfer funds to final recipient at correct destination
5249 */
53- function _executeFlow (
54- uint256 amount ,
55- bytes32 quoteNonce ,
56- address initialToken ,
57- address finalToken ,
58- bytes memory actionData ,
59- uint256 extraFeesToSponsorTokenIn
60- ) internal returns (address /* finalToken */ , uint256 finalAmount , uint256 extraFeesToSponsorFinalToken ) {
50+ function _executeFlow (EVMFlowParams memory params ) internal returns (CommonFlowParams memory commonParams ) {
6151 // Decode the compressed action data
62- CompressedCall[] memory compressedCalls = abi.decode (actionData, (CompressedCall[]));
52+ CompressedCall[] memory compressedCalls = abi.decode (params. actionData, (CompressedCall[]));
6353
6454 // Snapshot balances
65- uint256 initialAmountSnapshot = IERC20 (initialToken).balanceOf (address (this ));
66- uint256 finalAmountSnapshot = IERC20 (finalToken).balanceOf (address (this ));
55+ uint256 initialAmountSnapshot = IERC20 (params. initialToken).balanceOf (address (this ));
56+ uint256 finalAmountSnapshot = IERC20 (params.commonParams. finalToken).balanceOf (address (this ));
6757
6858 // Transfer tokens to MulticallHandler
69- IERC20 (initialToken).safeTransfer (multicallHandler, amount );
59+ IERC20 (params. initialToken).safeTransfer (multicallHandler, params.commonParams.amountInEVM );
7060
7161 // Build instructions for MulticallHandler
7262 bytes memory instructions = _buildMulticallInstructions (
7363 compressedCalls,
74- finalToken,
64+ params.commonParams. finalToken,
7565 address (this ) // Send leftover tokens back to this contract
7666 );
7767
7868 // Execute via MulticallHandler
7969 MulticallHandler (payable (multicallHandler)).handleV3AcrossMessage (
80- initialToken,
81- amount ,
70+ params. initialToken,
71+ params.commonParams.amountInEVM ,
8272 address (this ),
8373 instructions
8474 );
8575
76+ uint256 finalAmount;
8677 // This means the swap (if one was intended) didn't happen (action failed), so we use the initial token as the final token.
87- if (initialAmountSnapshot == IERC20 (initialToken).balanceOf (address (this ))) {
88- finalToken = initialToken;
89- finalAmount = amount ;
78+ if (initialAmountSnapshot == IERC20 (params. initialToken).balanceOf (address (this ))) {
79+ params.commonParams. finalToken = params. initialToken;
80+ finalAmount = params.commonParams.amountInEVM ;
9081 } else {
91- uint256 finalBalance = IERC20 (finalToken).balanceOf (address (this ));
82+ uint256 finalBalance = IERC20 (params.commonParams. finalToken).balanceOf (address (this ));
9283 if (finalBalance >= finalAmountSnapshot) {
9384 // This means the swap did happen, so we check the balance of the output token and send it.
9485 finalAmount = finalBalance - finalAmountSnapshot;
@@ -98,11 +89,16 @@ abstract contract ArbitraryEVMFlowExecutor {
9889 }
9990 }
10091
101- extraFeesToSponsorFinalToken = _calcExtraFeesFinal (amount, extraFeesToSponsorTokenIn, finalAmount);
92+ params.commonParams.extraFeesIncurred = _calcExtraFeesFinal (
93+ params.commonParams.amountInEVM,
94+ params.commonParams.extraFeesIncurred,
95+ finalAmount
96+ );
97+ params.commonParams.amountInEVM = finalAmount;
10298
103- emit ArbitraryActionsExecuted (quoteNonce, compressedCalls.length , finalAmount);
99+ emit ArbitraryActionsExecuted (params.commonParams. quoteNonce, compressedCalls.length , finalAmount);
104100
105- return (finalToken, finalAmount, extraFeesToSponsorFinalToken) ;
101+ return params.commonParams ;
106102 }
107103
108104 /**
0 commit comments