ERC-7204 Contract wallet token management (Contract wallet management token)

Draft · Accounts & wallets · created 2023-06-21

A standard that lets a smart contract wallet manage token approval and transfer directly within the wallet rather than in the token contract. It provides features such as wallet-level approval, bulk approval of all tokens, and pre/post transfer hooks.

Why it is needed

Under the current ERC-20 scheme, approval records granting permission to use tokens are stored inside each token contract, and the approval rules are also set by the token contract. As a result, users must approve separately for each token and are left bearing the implementation risks of some existing ERC-20 contracts as is. Risks such as over-approval, granting a larger amount than necessary, are also hard to reduce. Meanwhile, a regular wallet, an externally owned account (EOA), cannot store state or code, so the wallet itself has no way to program rules such as conditional approval or time-limited approval. This standard proposes bringing token asset management into the user's wallet by letting a smart contract wallet, which can hold state and code, handle approval and transfer directly.

What to implement

In depth

ERC-165 implementation requirement and interface identifier

A contract conforming to this standard must implement the ERC-165 interface. According to the original code comments, the ERC-165 identifier for this interface is 0xf73edcda. External contracts or apps can use this identifier to check whether a given wallet supports this standard.

tokenApprove and tokenAllowance

tokenApprove(asset, spender, value) allows the spender to draw on that token from the wallet account, across multiple calls, up to the value limit. Calling the same function again overwrites the current limit with the new value, and the call must emit a TokenApproval event. tokenAllowance(asset, spender) queries the remaining amount the spender can still draw from the owner. In traditional ERC-20, this approval state was stored by the token contract, but under this standard the user's wallet stores and sets it directly.

tokenApproveForAll and tokenIsApproveForAll

tokenApproveForAll(spender, approved) sets with a single boolean value whether the spender can draw on all of the wallet's tokens, and the call must emit a TokenApprovalForAll event. The setting can be queried with tokenIsApproveForAll(spender). The original Rationale describes this as a universal setting covering all tokens, and providing both per-token approval and all-token approval from the wallet is one of this proposal's goals.

Mandatory rules for tokenTransfer

tokenTransfer(asset, to, value) must internally call asset.transfer(). Also, if the caller is not the wallet itself, it must verify the approval limit and update the limit value. In other words, a transfer initiated by the wallet itself executes immediately, while a transfer initiated by a third party must go through the allowance stored in the wallet. The original Motivation explains that users can attach hook functions before and after tokenTransfer to extend functionality, and can optionally implement a tokenReceive function.

Batch processing and design intent

The original text states that a user's wallet can choose batch approvals and batch transfers. The Rationale explains that handling multiple approve and transfer operations at once improves transaction efficiency and improves the management experience for users with many assets. It also cites moving approval control into the wallet as reducing risks such as over-approval, and enabling advanced strategies such as conditional approvals or time-limited approvals to be programmed.

Relationship with ERC-4337

This ERC can be used as an extension of ERC-4337, the account abstraction standard, and is backward compatible with ERC-4337. The original text also mentions implementing it as a plugin form of the wallet. It also explains that, on the premise that ERC-20 is backward compatible with the simple token standard referred to as ERC-X in the original text, it can be made compatible with managing all fungible tokens in the existing market.

Proposal status

This proposal is in Draft status. Since it is at a draft stage where the content may still change, the latest original text should be checked before implementing or referencing it. The original Security Considerations section only states that no security considerations have been identified.

Original ERC · ← ERCs