ERC-3589 NFT token bundling multiple assets (Assemble assets into NFTs)

Stagnant · NFTs & multi-token · created 2021-05-24

A standard that bundles ETH, ERC-20, ERC-721, and ERC-1155 assets into a single ERC-721 token (assembly token) so they can be transferred or exchanged all at once.

Why it is needed

Until now, collectors wanting to exchange NFT collectibles with each other have had only two options. One is listing each person's NFT on a marketplace and waiting for the other party to buy it, but exchanging multiple items this way incurs gas costs per trade and is a cumbersome process. The other is entrusting both sides' assets to a third party found on social media or in a chat room and asking them to carry out the exchange, which carries the risk that the third party disappears with the assets. To safely perform a batch swap of multiple assets at once, this needs to be converted into a one-to-one atomic exchange, which first requires a way to bundle assets such as ETH, ERC-20, ERC-721, and ERC-1155 together.

What to implement

In depth

How to represent assets using two arrays

_addresses is an array that concatenates the ERC-20, ERC-721, and ERC-1155 addresses in that order. _numbers is an array containing the ETH amount, the number of ERC-20 addresses, the number of ERC-721 addresses, the number of ERC-1155 addresses, followed by the ERC-20 transfer amounts, ERC-721 token IDs, and ERC-1155 token IDs and amounts. The layout in the reference implementation is eth | erc20.length | erc721.length | erc1155.length | erc20 amounts | erc721 ids | erc1155 ids | erc1155 amounts.

The hash function and token ID generation

_salt is a value used to prevent hash collisions and may (MAY) be derived from user input or an incrementing nonce in the contract, but the token ID must (MUST) be generated via the hash function. hash chains _salt, _addresses, and _numbers in order through keccak256 to produce a signature, which is used as the token ID.

The difference between mint and safeMint

mint is recommended (SHOULD) for use with ordinary ERC-20 tokens and the like that incur no loss on transfer. safeMint must (MUST) be implemented for lossy tokens such as the PIG token that charge a tax on transfer, and it records the difference in the contract's token balance before and after transfer as the amount actually received, adjusting the numbers array accordingly.

Restoring assets via burn

burn can only be called by the token owner, and it recomputes hash from the supplied _salt, _addresses, and _numbers to verify that it matches _tokenId. If it matches, the token is burned and the ETH, ERC-20, ERC-721, and ERC-1155 assets are returned in order to the _to address.

The role of the AssemblyAsset event

When mint or safeMint is executed, it emits an AssemblyAsset event containing firstHolder, tokenId, salt, addresses, and numbers. This lets a wallet show the user what assets and how much of each are contained in a given token ID just from the token ID.

Why ERC-721 was chosen as the wrapper

ERC-721 is already widely used and well supported by NFT wallets, and an assembly token itself can be reassembled into further tokens. An assembly token is also easier for smart contracts to handle than a bundle of assets in situations like batch transfers, batch swaps, and collection swaps.

Proposal status

This proposal is currently in Stagnant status. Discussion has stalled with no further progress, so the specification may change or may never be adopted.

Things to watch out for

Original ERC · ← ERCs