Hello Everyone...
Welcome to another day of exploring Web3 Engineering. Today, we are looking into a ERC standard proposed by Uniswap Labs and Across Protocol to standardize the cross chain trading / order execution and simplify it's implementation. Its main use is to enable more efficient and user-friendly cross-chain interactions. So, without any further ado, let's dive deeper into this.
Cross-chain Intents
Here, the intent means the expected user outcome by the trade. Before getting into it's working, let us understand some technical words involved in it. ERC-7683 protocol has 2 user roles.
Swapper - User who placed a cross-chain trade / swap.
Filler (Relayer) - Off-chain system that fulfills the user order.
DataStructure
CrossChainOrder
struct CrossChainOrder {
address settlementContract;
address swapper;
uint256 nonce;
uint32 originChainId;
uint32 initiateDeadline;
uint32 fillDeadline;
bytes orderData;
}
settlementContract - address of the settlement contract on the source network
swapper - address of the user(swapper) on the source network
nonce - nonce value to prevent double spending
ordiginChainId - chainId assigned to the source network
initiateDeadline - deadline to initiate the call on the source chain
fillDeadline - deadline for the order to be filled on the destination chain
orderData - any access data in bytes form required to execute the order on the destination chain such as token address, token amount, receiver address etc
the standard interface for the Settlement contract is shown as below:
/// @title ISettlementContract
/// @notice Standard interface for settlement contracts
interface ISettlementContract {
/// @notice Initiates the settlement of a cross-chain order
/// @dev To be called by the filler
/// @param order The CrossChainOrder definition
/// @param signature The swapper's signature over the order
/// @param fillerData Any filler-defined data required by the settler
function initiate(CrossChainOrder order, bytes signature, bytes fillerData) external;
/// @notice Resolves a specific CrossChainOrder into a generic ResolvedCrossChainOrder
/// @dev Intended to improve standardized integration of various order types and settlement contracts
/// @param order The CrossChainOrder definition
/// @param fillerData Any filler-defined data required by the settler
/// @returns ResolvedCrossChainOrder hydrated order data including the inputs and outputs of the order
function resolve(CrossChainOrder order, bytes fillerData) external view returns (ResolvedCrossChainOrder);
}
Step to Step Guide
To place a cross-chain order, user will sign the
CrosshChainOrder
struct data.Once the order is signed, it will be broadcast against the network of fillers. The fillers will compete against each other in order to execute it.
Once a filler is finalized, they will call the
initiate
function on the source side Settlement Contract to lock the funds on the source contract.Once the confirmation is received on the source side to the filler, they will continue to execute the trade on the destination network. The settlement contract ensures that the tokens are sent to the specified receiver address, which is included in the orderData of the original order.
The standard also have a generic data structure called ResolvedCrossChainOrder
for unbundling the orderData in order to provide a standard way to execute the order on the destination contract. And the settlement contract must implement the resolve
function which converts the CrossChainOrder
into ResolvedCrossChainOrder
struct ResolvedCrossChainOrder {
address settlementContract;
address swapper;
uint256 nonce;
uint32 originChainId;
uint32 initiateDeadline;
uint32 fillDeadline;
Input[] swapperInputs;
Output[] swapperOutputs;
Output[] fillerOutputs;
}
/// @notice Tokens sent by the swapper as inputs to the order
struct Input {
address token;
uint256 amount;
}
/// @notice Tokens that must be receive for a valid order fulfillment
struct Output {
address token;
uint256 amount;
address recipient;
uint32 chainId;
}
ResolvedCrossChainOrder
settlementContract - Settlement contract address on the destination chain.
swapper - address of the user(swapper) on the source network
nonce - nonce value to prevent double spending
ordiginChainId - chainId assigned to the source network
initiateDeadline - deadline to initiate the call on the source chain
fillDeadline - deadline for the order to be filled on the destination chain
swapperInputs - array of Input (token) data which are taken from the swapper to initiate the transaction.
swapperOutputs - The outputs to be given to the swapper as part of order fulfillment
fillerOutputs - The outputs to be given to the filler as part of order settlement. It could include fees, commission etc.
Input
token - address of the ERC20 token on the origin chain
amount - amount of the token to be sent
Output
token - address of the ERC20 token on the destination chain. zero address must be used in order to specify native token.
amount - amount of the token to be sent to the receiver
recipient - address of the output tokens receiver
chainId - destination chainId for the output.
Protocols implementing ERC-7683
At the time of publishing this article, currently there are two projects that are implementing this standard. They are:
Uniswap
Across Protocol
Hope you found this helpful!
Drop a comment if you want to chat more about it.