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

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

Original ERC · ← ERCs