ERC-7720 Deferred token transfer

Draft · Tokens · created 2024-06-09

A Deferred Transfer standard that holds an ERC-20 token in escrow for a recipient, allowing it to be withdrawn only after a predetermined future point in time.

Why it is needed

There are many cases where tokens should be sent now but usable by the recipient only after a certain point in time, such as vesting that pays employees in stages, escrow held by a third party until conditions are met, or rewards given only after a certain period has passed. However, a standard ERC-20 transfer gives the recipient the token the moment it is sent, so no time condition can be attached. Without this standard, each service would have to build its own ad hoc time-lock mechanism, and there would be no common way to guarantee that a token is delivered only after a set point in time. This standard assigns a unique ID to each deposited transfer and records the token address, sender, recipient, amount, unlock time, and withdrawal status, enabling structured deferred payments that can only be claimed once enough time has passed.

What to implement

In depth

Required interface structure

Implementations of this standard MUST have all functions of the ITokenTransfer interface. The structure consists of three functions: transferFrom, which creates a scheduled transfer, withdraw, which withdraws it, and getTransaction, which queries the status, plus two events, Transfer and Withdraw. Each deposit is assigned a unique ID, and the token address, sender, recipient, amount, unlock time, and withdrawal status are recorded together with it. The recipient can only withdraw the token after the specified future timestamp.

Behavior of transferFrom and the txnId return value

transferFrom takes _token, _from, _to, _amount, _unlockTime, and _reference, creates a scheduled transfer, and returns a transaction number txnId. The reason each transaction returns a unique ID is to make it easy to track and reference each transaction independently. Users can manage and refer to a specific transaction with this ID, which reduces confusion and keeps the status of each transaction managed independently, simplifying the withdrawal process as well. In the reference implementation, lastTxnId is incremented by 1 to issue IDs, _amount must be greater than 0, the token is moved from the sender to the contract via safeTransferFrom, and then the transaction record is stored and a Transfer event is emitted.

Validation conditions in withdraw

The withdraw function in the reference implementation checks three things. The transaction's amount must be greater than 0 for it to be recognized as a valid transaction number, block.timestamp must be greater than or equal to unlockTime, and a transaction that has already been withdrawn (withdrawn is true) cannot be withdrawn again. If these conditions pass, the token is sent via safeTransfer to the recipient address designated at deposit time, withdrawn is recorded as true, and a Withdraw event is emitted. The token is always sent only to the to address recorded in the transaction.

Why uint40 is used for unlockTime

uint40 was chosen as the type for the unlock time _unlockTime. This is because uint40's range is large enough to cover all realistic time-lock scenarios. This also makes it possible to handle delayed payments that require precise timing over long periods, such as vesting schedules or long-term escrow.

A separate interface design that does not modify ERC-20

This standard is designed as a separate interface rather than an extension of ERC-20. Because it does not modify the ERC-20 standard itself, it can be used together with any already-deployed ERC-20 token without any contract changes. It can be applied as-is to the wide range of tokens already in circulation, which increases its utility and likelihood of adoption.

Note on proposal status

This proposal is in Draft status, created on June 9, 2024. Since it has not yet been finalized, its contents may change or progress may stall, so the latest original text should be checked before implementing or referencing it.

Things to watch out for

Original ERC · ← ERCs