|
| 1 | +// SPDX-License-Identifier: MIT |
| 2 | + |
| 3 | +pragma solidity ^0.8.0; |
| 4 | + |
| 5 | +/// @title IOriginSettler |
| 6 | +/// @notice Standard interface for settlement contracts on the origin chain |
| 7 | +interface IOriginSettler { |
| 8 | + /// @title GaslessCrossChainOrder CrossChainOrder type |
| 9 | + /// @notice Standard order struct to be signed by users, disseminated to fillers, and submitted to origin settler contracts |
| 10 | + struct GaslessCrossChainOrder { |
| 11 | + /// @dev The contract address that the order is meant to be settled by. |
| 12 | + /// Fillers send this order to this contract address on the origin chain |
| 13 | + address originSettler; |
| 14 | + /// @dev The address of the user who is initiating the swap, |
| 15 | + /// whose input tokens will be taken and escrowed |
| 16 | + address user; |
| 17 | + /// @dev Nonce to be used as replay protection for the order |
| 18 | + uint256 nonce; |
| 19 | + /// @dev The chainId of the origin chain |
| 20 | + uint256 originChainId; |
| 21 | + /// @dev The timestamp by which the order must be opened |
| 22 | + uint32 openDeadline; |
| 23 | + /// @dev The timestamp by which the order must be filled on the destination chain |
| 24 | + uint32 fillDeadline; |
| 25 | + /// @dev Type identifier for the order data. This is an EIP-712 typehash. |
| 26 | + bytes32 orderDataType; |
| 27 | + /// @dev Arbitrary implementation-specific data |
| 28 | + /// Can be used to define tokens, amounts, destination chains, fees, settlement parameters, |
| 29 | + /// or any other order-type specific information |
| 30 | + bytes orderData; |
| 31 | + } |
| 32 | + |
| 33 | + /// @title OnchainCrossChainOrder CrossChainOrder type |
| 34 | + /// @notice Standard order struct for user-opened orders, where the user is the msg.sender. |
| 35 | + struct OnchainCrossChainOrder { |
| 36 | + /// @dev The timestamp by which the order must be filled on the destination chain |
| 37 | + uint32 fillDeadline; |
| 38 | + /// @dev Type identifier for the order data. This is an EIP-712 typehash. |
| 39 | + bytes32 orderDataType; |
| 40 | + /// @dev Arbitrary implementation-specific data |
| 41 | + /// Can be used to define tokens, amounts, destination chains, fees, settlement parameters, |
| 42 | + /// or any other order-type specific information |
| 43 | + bytes orderData; |
| 44 | + } |
| 45 | + /// @title ResolvedCrossChainOrder type |
| 46 | + /// @notice An implementation-generic representation of an order intended for filler consumption |
| 47 | + /// @dev Defines all requirements for filling an order by unbundling the implementation-specific orderData. |
| 48 | + /// @dev Intended to improve integration generalization by allowing fillers to compute the exact input and output information of any order |
| 49 | + |
| 50 | + struct ResolvedCrossChainOrder { |
| 51 | + /// @dev The address of the user who is initiating the transfer |
| 52 | + address user; |
| 53 | + /// @dev The chainId of the origin chain |
| 54 | + uint256 originChainId; |
| 55 | + /// @dev The timestamp by which the order must be opened |
| 56 | + uint32 openDeadline; |
| 57 | + /// @dev The timestamp by which the order must be filled on the destination chain(s) |
| 58 | + uint32 fillDeadline; |
| 59 | + /// @dev The unique identifier for this order within this settlement system |
| 60 | + bytes32 orderId; |
| 61 | + /// @dev The max outputs that the filler will send. It's possible the actual amount depends on the state of the destination |
| 62 | + /// chain (destination dutch auction, for instance), so these outputs should be considered a cap on filler liabilities. |
| 63 | + Output[] maxSpent; |
| 64 | + /// @dev The minimum outputs that must be given to the filler as part of order settlement. Similar to maxSpent, it's possible |
| 65 | + /// that special order types may not be able to guarantee the exact amount at open time, so this should be considered |
| 66 | + /// a floor on filler receipts. |
| 67 | + Output[] minReceived; |
| 68 | + /// @dev Each instruction in this array is parameterizes a single leg of the fill. This provides the filler with the information |
| 69 | + /// necessary to perform the fill on the destination(s). |
| 70 | + FillInstruction[] fillInstructions; |
| 71 | + } |
| 72 | + |
| 73 | + /// @notice Tokens that must be received for a valid order fulfillment |
| 74 | + struct Output { |
| 75 | + /// @dev The address of the ERC20 token on the destination chain |
| 76 | + /// @dev address(0) used as a sentinel for the native token |
| 77 | + bytes32 token; |
| 78 | + /// @dev The amount of the token to be sent |
| 79 | + uint256 amount; |
| 80 | + /// @dev The address to receive the output tokens |
| 81 | + bytes32 recipient; |
| 82 | + /// @dev The destination chain for this output |
| 83 | + uint256 chainId; |
| 84 | + } |
| 85 | + |
| 86 | + /// @title FillInstruction type |
| 87 | + /// @notice Instructions to parameterize each leg of the fill |
| 88 | + /// @dev Provides all the origin-generated information required to produce a valid fill leg |
| 89 | + struct FillInstruction { |
| 90 | + /// @dev The contract address that the order is meant to be settled by |
| 91 | + uint256 destinationChainId; |
| 92 | + /// @dev The contract address that the order is meant to be filled on |
| 93 | + bytes32 destinationSettler; |
| 94 | + /// @dev The data generated on the origin chain needed by the destinationSettler to process the fill |
| 95 | + bytes originData; |
| 96 | + } |
| 97 | + |
| 98 | + /// @notice Signals that an order has been opened |
| 99 | + /// @param orderId a unique order identifier within this settlement system |
| 100 | + /// @param resolvedOrder resolved order that would be returned by resolve if called instead of Open |
| 101 | + event Open(bytes32 indexed orderId, ResolvedCrossChainOrder resolvedOrder); |
| 102 | + |
| 103 | + /// @notice Opens a gasless cross-chain order on behalf of a user. |
| 104 | + /// @dev To be called by the filler. |
| 105 | + /// @dev This method must emit the Open event |
| 106 | + /// @param order The GaslessCrossChainOrder definition |
| 107 | + /// @param signature The user's signature over the order |
| 108 | + /// @param originFillerData Any filler-defined data required by the settler |
| 109 | + function openFor(GaslessCrossChainOrder calldata order, bytes calldata signature, bytes calldata originFillerData) |
| 110 | + external; |
| 111 | + |
| 112 | + /// @notice Opens a cross-chain order |
| 113 | + /// @dev To be called by the user |
| 114 | + /// @dev This method must emit the Open event |
| 115 | + /// @param order The OnchainCrossChainOrder definition |
| 116 | + function open(OnchainCrossChainOrder calldata order) external; |
| 117 | + |
| 118 | + /// @notice Resolves a specific GaslessCrossChainOrder into a generic ResolvedCrossChainOrder |
| 119 | + /// @dev Intended to improve standardized integration of various order types and settlement contracts |
| 120 | + /// @param order The GaslessCrossChainOrder definition |
| 121 | + /// @param originFillerData Any filler-defined data required by the settler |
| 122 | + /// @return ResolvedCrossChainOrder hydrated order data including the inputs and outputs of the order |
| 123 | + function resolveFor(GaslessCrossChainOrder calldata order, bytes calldata originFillerData) |
| 124 | + external |
| 125 | + view |
| 126 | + returns (ResolvedCrossChainOrder memory); |
| 127 | + |
| 128 | + /// @notice Resolves a specific OnchainCrossChainOrder into a generic ResolvedCrossChainOrder |
| 129 | + /// @dev Intended to improve standardized integration of various order types and settlement contracts |
| 130 | + /// @param order The OnchainCrossChainOrder definition |
| 131 | + /// @return ResolvedCrossChainOrder hydrated order data including the inputs and outputs of the order |
| 132 | + function resolve(OnchainCrossChainOrder calldata order) external view returns (ResolvedCrossChainOrder memory); |
| 133 | +} |
0 commit comments