ERC-8076 Cross-Token Escrow Swap Standard (Cross-Token Escrow Protocol)
Draft · Vaults & DeFi · created 2025-11-03
An escrow standard in which the contract holds the token deposited by the payer, and the swap completes atomically within the same transaction once a liquidity provider delivers a different token to the designated recipient.
Why it is needed
Even if the payer and liquidity provider agree off-chain on the token pair, amount, and deadline, once the payer sends the input token first, delivery of the output token is left to a separate transaction. In this case, there is a risk that the liquidity provider receives the deposit but never sends the output token. Wallets and payment apps also each have to implement their own way of tracking orders and handling refunds when settlement fails. Without a common interface, escrow logic and event structures differ from service to service, making it hard for wallets, payment apps, and liquidity provider services to interoperate. This standard reduces this trust problem by having the contract hold the input token and bundling it so that the input token is received in the same transaction the moment the liquidity provider delivers the output token.
What to implement
event OrderCompleted(bytes32 indexed orderId);: An event emitted when an order is settled and completed.event OrderCancelled(bytes32 indexed orderId);: An event emitted when an order is cancelled.function completeOrder(bytes32 orderId) external;: Called by the liquidity provider to send the output token to the recipient and receive the input token deposited in escrow in return.function cancelOrder(bytes32 orderId) external;: Called by the payer after the deadline has passed to reclaim the deposited input token.
In depth
Roles and Asset Scope
The payer is the one who calls createOrder to supply the input token, and only the payer can receive a refund after the deadline. The recipient is the address specified as 'to', which may be the payer themselves or a different address. The liquidity provider is not predetermined for the order and is whoever calls completeOrder; anyone other than the recipient can settle it by sending the exact output amount. The two tokens must be different ERC-20 contracts on the same chain, and the amounts must be positive integers denominated in each token's smallest unit. Native assets, tokens that take a fee on transfer, or tokens whose balance changes while held in escrow are out of scope for this interface. Every transfer must reduce the source balance and increase the destination balance by exactly that amount, and if a transfer fails, including cases where an ERC-20 call returns false, the entire order operation and token transfer must revert.
Conditions for createOrder
The caller must set a sufficient allowance in advance so the escrow can take amountFrom of tokenFrom. The call reverts if 'to' is the zero address or the escrow itself, if the two token addresses are the same, if either amount is not positive, or if deadline is not greater than the current block timestamp (block.timestamp). The escrow records the payer, recipient, the two tokens, the two amounts, and the deadline, and takes and holds exactly amountFrom from the payer. If the deposit succeeds, it must return a bytes32 order ID unique within that escrow contract and emit OrderCreated. Orders created with the same parameters must have different IDs, and a simple token transfer to the escrow alone does not create or fund an order.
Conditions for completeOrder
The liquidity provider must set an allowance so the escrow can take amountTo of tokenTo. The call reverts if the order's deadline has passed or if the caller is the recipient themselves. Within the same transaction, the escrow must deliver exactly amountTo from the liquidity provider to 'to', and pay out exactly amountFrom held in escrow to the liquidity provider. If either transfer fails, the order must remain open with no change in funds. On success, it marks the order as completed and emits OrderCompleted.
Conditions for cancelOrder
The call reverts if the caller is not the payer or if the order's deadline has not yet passed. On success, the escrow returns the full amountFrom held in escrow to the payer, marks the order as cancelled, and emits OrderCancelled. A refund is only initiated when the payer calls this function themselves.
Order Lifecycle and Deadline Boundaries
An order becomes open once createOrder succeeds, and becomes final once completeOrder or cancelOrder succeeds. Both functions must revert for an unknown order or an order that is already final. deadline is a Unix timestamp in seconds; completion is possible up until the moment block.timestamp equals deadline, and cancellation becomes possible only once block.timestamp exceeds deadline. This divides the completion window and the cancellation window so they never overlap.
Design Rationale: Contract Custody and Fixed Amounts
Because the contract holds the funds, the liquidity provider can verify before settling that the payer has actually deposited the input token. Separating the payer and recipient roles lets a payment app send the output token to a beneficiary who is not the one providing liquidity. Since no specific liquidity provider is predetermined, anyone who is qualified can settle at the stated amount. Because the amount is fixed, the contract can enforce delivery of the exact specified amount without needing a price oracle or on-chain slippage calculations.
Proposal status
This proposal is currently a Draft. Details may still change, or progress may stall, as it goes through further review and discussion.
Things to watch out for
- Token Behavior: A token may revert, display an incorrect balance, freeze transfers, or change its balance in ways the escrow cannot control. Since exact transfer-amount verification only guarantees the stated amount for tokens without such issues, integrators must evaluate both token contracts and the issuer's control privileges before accepting an order.
- Atomicity and Reentrancy: Token calls can execute external code. Implementations must prevent reentrancy during order state changes and ensure the order cannot be manipulated again while a finalizing transition is underway. If the transfer fails, the entire operation must be reverted.
- Competing fills: Multiple liquidity providers may attempt to fill the same order simultaneously. Only the first successful fill settles; the rest are reverted, wasting only gas fees. Because the recipient and amount are fixed, a competing liquidity provider cannot redirect the output elsewhere or alter the terms.
- Expiry and insufficient liquidity: Escrow does not guarantee that a liquidity provider will fill the order or that the transaction will be included before the deadline. Applications must account for inclusion delays and provide payers a way to initiate a refund. Issuer restrictions or token errors can block even refunds.