ERC-4546 · Stagnant · ERC · 2021-12-11
ERC-4546: Wrapped Deposits
Proposed a single, immutable deposit contract that users approve once per token, which then forwards ETH, ERC-20, ERC-721 and ERC-1155 deposits to any app that opts in, so apps never need token approvals themselves.
What problem does it solve?
Depositing an ERC-20 into a dApp usually means first calling approve on the token for that dApp. Users choose between approving the exact amount every time (two transactions per deposit, costly and tedious) or granting an unlimited approval (convenient but risky if the dApp is compromised). And every dApp has to explain approvals to new users again.
ERC-4546 proposes a shared wrapped deposit contract. You approve it once per token; from then on any app that supports it can receive deposits from you, and none of those apps ever hold an allowance over your tokens.
How it works
- A singleton contract, deployed at a well-known address, non-upgradable and with no mutable state.
- It exposes deposit functions for each asset type:
depositERC20,depositERC721,safeDepositERC721,safeDepositERC1155,batchDepositERC1155anddepositEther. - Each deposit call:
- reverts if
tohas no code (deposits only go to contracts); - calls an
accept…Deposit(depositor, …)hook onto, which must returntrue; - moves the asset from the user straight to
tousing the user's approval of the deposit contract, reverting on failure.
- reverts if
- Receiving contracts implement only the hooks for assets they want, and must check that
msg.senderis the deposit contract, or anyone could fake a deposit.
Sample code
A vault accepting ERC-20 deposits through the shared contract:
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;
interface ERC20Receiver {
function acceptERC20Deposit(address depositor, address token, uint256 amount) external returns (bool);
}
contract Vault is ERC20Receiver {
address public immutable wrappedDeposit;
mapping(address => mapping(address => uint256)) public balances; // user => token => amount
constructor(address _wrappedDeposit) {
wrappedDeposit = _wrappedDeposit;
}
function acceptERC20Deposit(address depositor, address token, uint256 amount) external returns (bool) {
require(msg.sender == wrappedDeposit, "only wrapped deposit");
balances[depositor][token] += amount;
return true;
}
}
User side (ethers v6): one approval, then deposits to any supporting app:
await token.approve(WRAPPED_DEPOSIT, MaxUint256); // once per token
await wrappedDeposit.depositERC20(vaultAddress, tokenAddress, amount);
Things to know
- Status: Stagnant. No canonical deployment address was agreed; do not rely on the example address in the spec.
- The receiving hook is called before the asset arrives, so the receiver credits a balance on the promise that the transfer will follow. That is safe only because the whole call reverts if the transfer fails.
- Users still grant an allowance, just to one small, audited, immutable contract instead of to every dApp. That contract becomes a high-value target, which is why the spec stresses keeping it tiny.
- In the spec's reference code the ERC-1155 hooks pass
towhere the token address would be expected; treat it as illustrative, not production-ready. - Signature-based approvals such as ERC-2612
permittackle the same UX problem from another angle.