ERC-8076: Cross-Token Escrow Protocol

An escrow contract holds a payer's tokens until a liquidity provider delivers a different token to a designated recipient.


Metadata
Status: DraftStandards Track: ERCCreated: 2025-11-03
Authors
Xiang Gao (@GaoYiRu), Xiaoyu Liu (@elizabethxiaoyu), Hao Zou (@BruceZH0915), Yuxiang Fu (@tmac4096)
Requires

Abstract


This proposal defines an escrow interface for exchanging two different ERC-20 tokens on the same chain. A payer deposits input tokens and designates the recipient of the output tokens. A liquidity provider (LP) fills the order by delivering the specified output tokens to that recipient and receiving the escrowed input tokens in the same transaction. If an order expires unfilled, the payer can reclaim the input tokens.

Motivation


A payer and an LP may agree on a token pair, exact amounts, and a deadline off-chain. If the payer sends the input tokens to the LP first, delivery of the output tokens depends on a separate transaction. A wallet or payment application also needs to know how to track the order and recover the input tokens if settlement fails.

For example, a payment application could let a payer fund an order with 100 USDC for a recipient to receive 99 DAI. The escrow holds the USDC while the order is open. An LP who fills the order receives the USDC in the same transaction that delivers the DAI to the recipient. If no LP fills the order before it expires, the payer can reclaim the USDC. This proposal gives wallets, payment applications, and LP services a common interface to create, monitor, and settle such orders.

Specification


The key words "MUST", "MUST NOT", "REQUIRED", "SHALL", "SHALL NOT", "SHOULD", "SHOULD NOT", "RECOMMENDED", "NOT RECOMMENDED", "MAY", and "OPTIONAL" in this document are to be interpreted as described in RFC 2119 and RFC 8174.

Roles and Assets

  • The payer is the caller of createOrder and supplies the input tokens. Only the payer can reclaim them after expiry.
  • The recipient is the address supplied as to. It receives the output tokens and can be the payer or a different address.
  • The LP is the caller of completeOrder. Orders have no designated LP. Any caller other than the recipient can fill an open order by delivering the exact output amount.
  • Both assets MUST be different ERC-20 token contracts on the same chain. Amounts are positive integers in each token's smallest denomination. Native assets and tokens that charge transfer fees or adjust balances while in escrow are outside the scope of this interface.
  • For every transfer specified below, the source balance MUST decrease by the stated amount and the destination balance MUST increase by the same amount. A failed transfer, including a false return from an ERC-20 call, MUST revert the order operation and its token transfers.

Interface

interface IEscrowTrade {
    event OrderCreated(
        bytes32 indexed orderId,
        address indexed payer,
        address indexed to,
        address tokenFrom,
        address tokenTo,
        uint256 amountFrom,
        uint256 amountTo,
        uint256 deadline
    );
    event OrderCompleted(bytes32 indexed orderId);
    event OrderCancelled(bytes32 indexed orderId);

    function createOrder(
        address to,
        address tokenFrom,
        address tokenTo,
        uint256 amountFrom,
        uint256 amountTo,
        uint256 deadline
    ) external returns (bytes32 orderId);

    function completeOrder(bytes32 orderId) external;

    function cancelOrder(bytes32 orderId) external;
}

Order Lifecycle

An order becomes open when createOrder succeeds. A successful completeOrder or cancelOrder puts it into a terminal state. Both functions MUST revert for an unknown or terminal order. The deadline is a Unix timestamp in seconds. The order remains eligible for completion at block.timestamp == deadline and becomes eligible for cancellation once block.timestamp > deadline.

createOrder

The caller MUST give the escrow sufficient allowance to pull amountFrom of tokenFrom. The escrow MUST revert unless to is neither the zero address nor the escrow itself, both token addresses identify different ERC-20 contracts, both amounts are positive, and deadline is strictly greater than block.timestamp.

The escrow MUST record the payer, recipient, tokens, amounts, and deadline, and pull exactly amountFrom from the payer into escrow. It MUST return a bytes32 order ID unique within that escrow contract and MUST emit OrderCreated once the deposit succeeds. Identical order parameters MUST produce distinct IDs. A direct token transfer to the escrow does not create or fund an order.

completeOrder

The LP MUST give the escrow sufficient allowance to pull amountTo of tokenTo. The escrow MUST revert if the order is past its deadline or the LP is the recipient. The escrow MUST transfer exactly amountTo from the LP to to and pay exactly amountFrom of tokenFrom from escrow to the LP in the same transaction. If either transfer fails, the order MUST remain open with its funds unchanged. On success, the escrow MUST mark the order as completed and emit OrderCompleted.

cancelOrder

The escrow MUST revert if the caller is not the payer or the order has not passed its deadline. On success, it MUST return exactly amountFrom of tokenFrom to the payer, mark the order as cancelled, and emit OrderCancelled. The payer initiates the refund by calling this method.

Events and Order Discovery

Clients can discover orders using OrderCreated and track terminal states using OrderCompleted and OrderCancelled. OrderCreated indexes the order ID, payer, and recipient, and stores the tokens, amounts, and deadline in the event data. The terminal events index the order ID. An order ID is opaque to callers. Clients SHOULD identify an order by chain, escrow contract address, and order ID.

Rationale


Contract custody lets an LP verify that the payer has deposited the input tokens before filling an order. The LP and recipient have separate roles so a payment application can route the output to a beneficiary without requiring that beneficiary to provide liquidity. Any eligible LP can fill the order at the quoted amounts. Fixed amounts let the contract enforce delivery without a price oracle or an on-chain slippage calculation.

The deadline divides the window in which an LP can fill an order from the window in which the payer can reclaim the deposit. This keeps an order available until its deadline and avoids giving fills and refunds overlapping eligibility. Using the same bytes32 type for every order ID lets clients use the returned ID directly in subsequent calls and event filters.

Backwards Compatibility


The interface is implemented by standalone contracts and requires no changes to ERC-20 token contracts or Ethereum consensus. Integrations built against earlier drafts need to update their ABI to use the bytes32 return value and the event topic layout specified here.

Test Cases


Each case starts with a fresh order unless stated otherwise. In the examples the order escrows 100 units of token A for 99 units of token B, and the payer, recipient, and LP are different accounts.

ScenarioExpected result
Create with sufficient allowanceThe escrow receives 100 units of A, the payer is debited 100 units of A, and OrderCreated contains the returned order ID.
Create two identical orders in the same blockBoth deposits succeed and the orders have different IDs.
Complete exactly at the deadlineThe recipient receives 99 units of B from the LP. The LP receives 100 units of A from escrow. OrderCompleted identifies the order.
Complete with insufficient output allowance, or attempt completion as the recipientThe call reverts and the order remains open without balance changes.
Fail the escrow's input payout after the output transferThe output transfer rolls back and the order remains open.
Cancel at the deadline, or complete after the deadlineThe call reverts.
Cancel after the deadline as the payerThe payer receives the full 100 units of A, and OrderCancelled identifies the order.
Cancel after the deadline as another account, or call either method for an unknown or terminal orderThe call reverts.

Reference Implementation


The Solidity reference implementation implements the escrow interface. It uses OpenZeppelin Contracts 5.x for safe ERC-20 calls and reentrancy protection. The implementation is non-normative and distributed under the MIT license.

Security Considerations


  • Token behavior. A token can revert, report misleading balances, freeze transfers, or change balances outside the escrow's control. Exact transfer checks enforce the quoted amounts for supported tokens. Integrators should evaluate both token contracts and any issuer controls before accepting an order.
  • Atomicity and reentrancy. Token calls can invoke external code. An implementation needs to prevent reentry into order mutations and avoid leaving an order actionable during a terminal transition. A failed transfer must allow the entire operation to revert.
  • Competing fills. Several LPs may submit fills for the same order. Only the first successful fill settles it. Later fills revert and may incur transaction fees. The fixed recipient and amounts prevent a competing LP from redirecting the output or changing the quote.
  • Expiry and liquidity. Escrow does not guarantee that an LP will fill an order or that a transaction will be included before the deadline. Applications should account for inclusion delays and give the payer a way to initiate a refund. Issuer restrictions or token failures can still block a refund.

Copyright


Copyright and related rights waived via CC0.