ERC-4546 Unified deposit contract (Wrapped Deposits)

Stagnant · Vaults & DeFi · created 2021-12-11

A single shared contract handles ETH, ERC-20, and NFT deposits on behalf of apps, so users only need to approve token spending once to deposit into multiple apps.

Why it is needed

To deposit ERC-20 tokens into an app, a user must first approve the token for spending. Sending a separate approval transaction for the exact amount on every deposit is cumbersome and incurs repeated fees, while approving an unlimited amount at once is convenient but creates a security risk, since that app could take the user's entire balance. In addition, the concept of approval is hard to explain to new or non-expert users, and this process must be repeated identically in every individual app that supports ERC-20 deposits.

What to implement

In depth

Singleton structure and immutability

The unified deposit contract SHOULD be deployed at an identifiable address (e.g. 0x1111119a9e30bceadf9f939390293ffacef93fe9) and MUST be non-upgradeable with unchangeable state variables. This is a requirement so that all users and apps can share a single trusted point.

Common rules for deposit functions

The depositERC20, depositERC721, safeDepositERC721, safeDepositERC1155, batchDepositERC1155, and depositEther functions must all revert if to is an address with zero code size (a regular account). Each function must also check whether to's accept function accepts the deposit, reverting if it does not return true, and must also revert if the asset transfer itself fails.

The accept interface of the receiving contract

The ERC20Receiver, ERC721Receiver, ERC1155Receiver, and EtherReceiver interfaces each define the functions acceptERC20Deposit, acceptERC721Deposit, acceptERC1155Deposit, acceptERC1155BatchDeposit, and acceptEtherDeposit. A receiving contract MAY implement only the functions it wants, and if it does not implement the accept function for a given asset type, deposits of that type MUST NOT be sent.

Design rationale

When a single contract handles all token transfers, users only need to approve a token once to deposit into multiple apps. Receiving contracts no longer need to entrust depositors with token spending approval, reducing trust requirements, and they also don't need to implement token transfer logic themselves, lowering implementation complexity. This lets the user experience be designed around a simple message: "enable this token for use in other apps."

Backward compatibility

This ERC is not backward compatible. Contracts that want to use this deposit system must implement the accept function themselves. Existing upgradeable contracts can add support later by adding an accept function, and can allow the existing method (approval on the contract itself) alongside the new deposit method, preserving existing approvals while guiding new users toward the new method.

The reference implementation's ERC-20 handling approach

The reference implementation's depositERC20 calls token's transferFrom via a low-level call, and if there is return data, decodes it as a bool to check whether it is true. This is backward-compatible handling so it also works with some ERC-20 tokens whose transferFrom does not return a bool as the standard specifies. All functions internally check first whether to is a contract (extcodesize > 0).

Proposal status

This ERC is in Stagnant status. It is no longer being actively discussed, so its content may change or it may never be adopted as a standard going forward.

Things to watch out for

Original ERC · ← ERCs