|
| 1 | +// SPDX-License-Identifier: GPL-3.0-or-later |
| 2 | +pragma solidity ^0.8.0; |
| 3 | + |
| 4 | +/// @notice Tokens sent by the swapper as inputs to the order |
| 5 | +struct Input { |
| 6 | + /// @dev The address of the ERC20 token on the origin chain |
| 7 | + address token; |
| 8 | + /// @dev The amount of the token to be sent |
| 9 | + uint256 amount; |
| 10 | +} |
| 11 | + |
| 12 | +/// @notice Tokens that must be receive for a valid order fulfillment |
| 13 | +struct Output { |
| 14 | + /// @dev The address of the ERC20 token on the destination chain |
| 15 | + /// @dev address(0) used as a sentinel for the native token |
| 16 | + address token; |
| 17 | + /// @dev The amount of the token to be sent |
| 18 | + uint256 amount; |
| 19 | + /// @dev The address to receive the output tokens |
| 20 | + address recipient; |
| 21 | + /// @dev The destination chain for this output |
| 22 | + uint32 chainId; |
| 23 | +} |
| 24 | + |
| 25 | +/// @title CrossChainOrder type |
| 26 | +/// @notice Standard order struct to be signed by swappers, disseminated to fillers, and submitted to settlement contracts |
| 27 | +struct CrossChainOrder { |
| 28 | + /// @dev The contract address that the order is meant to be settled by. |
| 29 | + /// Fillers send this order to this contract address on the origin chain |
| 30 | + address settlementContract; |
| 31 | + /// @dev The address of the user who is initiating the swap, |
| 32 | + /// whose input tokens will be taken and escrowed |
| 33 | + address swapper; |
| 34 | + /// @dev Nonce to be used as replay protection for the order |
| 35 | + uint256 nonce; |
| 36 | + /// @dev The chainId of the origin chain |
| 37 | + uint32 originChainId; |
| 38 | + /// @dev The timestamp by which the order must be initiated |
| 39 | + uint32 initiateDeadline; |
| 40 | + /// @dev The timestamp by which the order must be filled on the destination chain |
| 41 | + uint32 fillDeadline; |
| 42 | + /// @dev Arbitrary implementation-specific data |
| 43 | + /// Can be used to define tokens, amounts, destination chains, fees, settlement parameters, |
| 44 | + /// or any other order-type specific information |
| 45 | + bytes orderData; |
| 46 | +} |
| 47 | + |
| 48 | +/// @title ResolvedCrossChainOrder type |
| 49 | +/// @notice An implementation-generic representation of an order |
| 50 | +/// @dev Defines all requirements for filling an order by unbundling the implementation-specific orderData. |
| 51 | +/// @dev Intended to improve integration generalization by allowing fillers to compute the exact input and output information of any order |
| 52 | +struct ResolvedCrossChainOrder { |
| 53 | + /// @dev The contract address that the order is meant to be settled by. |
| 54 | + address settlementContract; |
| 55 | + /// @dev The address of the user who is initiating the swap |
| 56 | + address swapper; |
| 57 | + /// @dev Nonce to be used as replay protection for the order |
| 58 | + uint256 nonce; |
| 59 | + /// @dev The chainId of the origin chain |
| 60 | + uint32 originChainId; |
| 61 | + /// @dev The timestamp by which the order must be initiated |
| 62 | + uint32 initiateDeadline; |
| 63 | + /// @dev The timestamp by which the order must be filled on the destination chain(s) |
| 64 | + uint32 fillDeadline; |
| 65 | + /// @dev The inputs to be taken from the swapper as part of order initiation |
| 66 | + Input[] swapperInputs; |
| 67 | + /// @dev The outputs to be given to the swapper as part of order fulfillment |
| 68 | + Output[] swapperOutputs; |
| 69 | + /// @dev The outputs to be given to the filler as part of order settlement |
| 70 | + Output[] fillerOutputs; |
| 71 | +} |
| 72 | + |
| 73 | +/// @title ISettlementContract |
| 74 | +/// @notice Standard interface for settlement contracts |
| 75 | +interface ISettlementContract { |
| 76 | + /// @notice Initiates the settlement of a cross-chain order |
| 77 | + /// @dev To be called by the filler |
| 78 | + /// @param order The CrossChainOrder definition |
| 79 | + /// @param signature The swapper's signature over the order |
| 80 | + /// @param fillerData Any filler-defined data required by the settler |
| 81 | + function initiate( |
| 82 | + CrossChainOrder memory order, |
| 83 | + bytes memory signature, |
| 84 | + bytes memory fillerData |
| 85 | + ) external; |
| 86 | + |
| 87 | + /// @notice Resolves a specific CrossChainOrder into a generic ResolvedCrossChainOrder |
| 88 | + /// @dev Intended to improve standardized integration of various order types and settlement contracts |
| 89 | + /// @param order The CrossChainOrder definition |
| 90 | + /// @param fillerData Any filler-defined data required by the settler |
| 91 | + /// @return ResolvedCrossChainOrder hydrated order data including the inputs and outputs of the order |
| 92 | + function resolve(CrossChainOrder memory order, bytes memory fillerData) |
| 93 | + external |
| 94 | + view |
| 95 | + returns (ResolvedCrossChainOrder memory); |
| 96 | +} |
0 commit comments