ERC-7681 A dual-nature multi-token protocol (Dual Nature Multi Token Protocol)
Draft · NFTs & multi-token · created 2024-04-08
A combined standard that implements the fungible token standard ERC-20 and the multi-token standard ERC-1155 together in a single contract, keeping the balances of the two tokens moving in sync with each other.
Why it is needed
There have been attempts in Ethereum to make a single token behave both as a quantity like a coin and as an individual item like an NFT. ERC-7631, which combines the fungible token standard ERC-20 and the NFT standard ERC-721 in a single contract, is one example. However, the two standards each define a Transfer(address, address, uint256) event with the same name and shape, which made it difficult for a single contract to fully comply with both standards at once. The multi-token standard ERC-1155, by contrast, does not have events that overlap with ERC-20, so the two standards can be combined into one while both are fully honored. This makes it possible to natively implement features inside the contract such as fractionalization, similar to NFT fractional ownership, where acquiring ERC-20 tokens automatically mints ERC-1155 tokens in proportion to the holder's balance. ERC-7681 standardizes this combination approach, along with a way for users to opt out of receiving ERC-1155 tokens during the synchronization process.
What to implement
event Transfer(address indexed _from, address indexed _to, uint256 _value);: An event emitted when ERC-20 tokens move.event Approval(address indexed _owner, address indexed _spender, uint256 _value);: An event emitted when permission to use ERC-20 tokens is granted to another address.event TransferSingle(address indexed _operator, address indexed _from, address indexed _to, uint256 _id, uint256 _value);: An event emitted when a single type of ERC-1155 token moves.event TransferBatch(address indexed _operator, address indexed _from, address indexed _to, uint256[] _ids, uint256[] _values);: An event emitted when multiple types of ERC-1155 tokens move at once.event ApprovalForAll(address indexed _owner, address indexed _operator, bool _approved);: An event emitted when operator permission over all ERC-1155 tokens is set or revoked.event URI(string _value, uint256 indexed _id);: An event emitted when the metadata address for an ERC-1155 token of a specific ID changes.function name() public view returns (string);: Returns the token name. An optional implementation item.function symbol() public view returns (string);: Returns the token symbol. An optional implementation item.function decimals() public view returns (uint8);: Returns the number of decimal places for the ERC-20 token. An optional implementation item.function totalSupply() public view returns (uint256);: Returns the total supply of the ERC-20 token.function balanceOf(address _owner) public view returns (uint256);: Returns the ERC-20 token balance of a specific address.function transfer(address _to, uint256 _value) public returns (bool);: Sends the caller's ERC-20 tokens to another address.function transferFrom(address _from, address _to, uint256 _value) public returns (bool);: Moves another address's ERC-20 tokens on their behalf within the approved allowance.function approve(address _spender, uint256 _value) public returns (bool);: Allows another address to spend up to a certain amount of my ERC-20 tokens.function allowance(address _owner, address _spender) public view returns (uint256);: Returns the remaining amount one address is allowed to spend of another address's ERC-20 tokens.function balanceOf(address _owner, uint256 _id) external view returns (uint256);: Returns the ERC-1155 balance of a specific ID held by a specific address.function balanceOfBatch(address[] calldata _owners, uint256[] calldata _ids) external view returns (uint256[] memory);: Queries ERC-1155 balances for multiple address and ID combinations at once.function setApprovalForAll(address _operator, bool _approved) external;: Turns operator permission over all of my ERC-1155 tokens on or off.function isApprovedForAll(address _owner, address _operator) external view returns (bool);: Checks whether an address is approved as an operator for another address.function safeTransferFrom(address _from, address _to, uint256 _id, uint256 _value, bytes calldata _data) external;: Safely sends an ERC-1155 token of a specific ID, including a receipt confirmation step.function safeBatchTransferFrom(address _from, address _to, uint256[] calldata _ids, uint256[] calldata _values, bytes calldata _data) external;: Safely sends ERC-1155 tokens of multiple IDs at once.event SkipTokenSet(address indexed owner, bool status);: An event emitted whenever an address's ERC-1155 skip status changes.function getSkipToken(address owner) external view returns (bool);: Returns whether the given address has set itself to skip ERC-1155 minting and transfers during synchronization.function setSkipToken(bool status) external;: Sets the caller's own ERC-1155 skip status.
In depth
Both standards' interfaces must be implemented
Every ERC-7681 contract MUST implement both the ERC20 and ERC1155 interfaces. On the ERC-20 side, totalSupply, balanceOf(address), transfer, transferFrom, approve, and allowance are required, while name, symbol, and decimals are optional (MAY). On the ERC-1155 side, balanceOf(address, uint256), balanceOfBatch, setApprovalForAll, isApprovedForAll, safeTransferFrom, and safeBatchTransferFrom are required. The events must also include ERC-20's Transfer and Approval, and ERC-1155's TransferSingle, TransferBatch, ApprovalForAll, and URI. This is a structure where balanceOf functions of the same name coexist, distinguished by the number of arguments.
Why ERC-1155 was combined instead of ERC-721
ERC-7631, which links ERC-20 and ERC-721, revealed the problem that full compatibility is difficult because both standards define a Transfer(address, address, uint256) event of the same shape. ERC-1155 has events such as TransferSingle and TransferBatch that do not overlap, making it possible to combine the two in a way that fully satisfies both standards. At the same time, this can provide benefits similar to NFT fractional ownership by default, such as automatically minting ERC-1155 tokens in proportion to the holder's balance when ERC-20 tokens are acquired. As with ERC-7631, users are also allowed to opt out of ERC-1155 minting and transfers during the synchronization process.
Synchronization logic was deliberately left unspecified
This proposal deliberately does not specify concrete synchronization logic for how the two tokens should be kept in sync. One-to-one synchronization is possible, as is a scheme that fractionalizes ERC-1155 tokens based on ERC-20 holdings. As long as implementers fully comply with the specifications of both token standards, they are free to set their own synchronization strategy, which is intended to accommodate a variety of implementation strategies and new use cases.
Behavior rules of the skip interface
IERC7681Skippable is an optional implementation (MAY). getSkipToken(owner) SHOULD return whether ERC-1155 minting and transfers to that address should be skipped during synchronization. This function may revert, but once it has returned true or false for a given owner, it MUST NOT revert for that owner again. If it reverts, the caller should treat it as if the setSkipToken feature does not exist, hide the related functionality, and interpret that address's skip status as undefined. setSkipToken(status) sets the caller's own skip status and may revert due to insufficient permissions or other reasons. The initial skip status can be freely set to either true or false, but whenever the status changes in any way, a SkipTokenSet event must be emitted.
Contract addresses benefit from defaulting to skip
If the recipient address is a smart contract, setting the default skip status to true can prevent unnecessary ERC-1155 minting when interacting with contracts such as decentralized exchanges (DEXs) or lending protocols. Such contracts often do not need ERC-1155 tokens, so skipping minting may reduce gas costs.
Backward compatibility and proposal status
This proposal is fully backward compatible with the existing ERC-20 and ERC-1155 standards, so existing contracts that rely on either standard continue to work as is. However, ERC-7681 is a proposal in Draft status submitted on April 8, 2024, so it should be kept in mind that its content may still change.
Things to watch out for
- Denial of service from gas exhaustion: When a user transfers ERC-20 tokens, the minting, transferring, and burning of multiple ERC-1155 tokens can happen automatically. Because of this, gas cost may grow proportionally to the number of operations, O(n), rather than being a fixed O(1) cost like an ordinary ERC-20 transfer, and the way ERC-1155 token IDs are chosen can increase gas further. Synchronization strategies must be designed with this cost growth in mind to avoid a denial-of-service situation where transfers are blocked by gas exhaustion.