EIPs Explained

ERC-7681 · Draft · ERC · 2024-04-08

ERC-7681: Dual Nature Multi Token Protocol

A single contract that is both an ERC-20 token and an ERC-1155 multi-token, with ERC-1155 balances kept in sync with ERC-20 holdings, giving native fractionalization of NFT-like items.

What problem does it solve?

Projects sometimes want a token that trades like a fungible coin on DEXs but also shows up as collectible items in wallets and marketplaces. ERC-7631 pairs ERC-20 with ERC-721 for this, but both standards define an event named Transfer(address,address,uint256), which makes full compatibility awkward.

ERC-7681 pairs ERC-20 with ERC-1155 instead. Their events and function signatures do not collide in the same way, so one contract can be fully compliant with both. Holding ERC-20 tokens can automatically give you a proportional amount of ERC-1155 tokens: in effect, natively fractionalized NFTs.

How it works

  • The contract must implement both the ERC-20 and the ERC-1155 interfaces, including all their events (Transfer, Approval, TransferSingle, TransferBatch, ApprovalForAll, URI). balanceOf(address) is the ERC-20 balance; balanceOf(address, id) is the ERC-1155 balance.
  • The synchronization logic is deliberately unspecified. An implementation might mint one ERC-1155 unit per whole ERC-20 token, spread holdings over several IDs, or anything else, as long as both standards stay satisfied.
  • An optional skippable interface lets an address opt out of ERC-1155 mints and transfers during synchronization:
    • getSkipToken(owner) returns whether ERC-1155 side effects are skipped for that address.
    • setSkipToken(bool) changes the caller's own status and emits SkipTokenSet.
    • Skipping is useful for contracts such as DEX pools and lending protocols, which only need the ERC-20 side; the spec suggests defaulting smart contracts to true.

Sample code

The optional skip interface, plus a sketch of a 1:1 "one whole ERC-20 token = one ERC-1155 unit" sync hook:

// SPDX-License-Identifier: CC0-1.0
pragma solidity ^0.8.20;

interface IERC7681Skippable {
    event SkipTokenSet(address indexed owner, bool status);
    function getSkipToken(address owner) external view returns (bool);
    function setSkipToken(bool status) external;
}

// Inside an ERC-7681 contract (illustrative only):
// after every ERC-20 balance change, reconcile the ERC-1155 side.
function _sync(address account) internal {
    if (account == address(0) || getSkipToken(account)) return;
    uint256 wanted = erc20BalanceOf[account] / 1e18;  // whole tokens
    uint256 held   = erc1155BalanceOf[account][ID];
    if (wanted > held) _mint1155(account, ID, wanted - held);
    else if (held > wanted) _burn1155(account, ID, held - wanted);
}

Things to know

  • Status is Draft: the interface may still change.
  • Because sync rules are left to implementers, two ERC-7681 tokens can behave very differently. Read the contract before assuming how ERC-1155 balances follow ERC-20 transfers.
  • Out-of-gas risk: an ERC-20 transfer can trigger several ERC-1155 mints, transfers or burns, so gas grows with the number of actions (O(n)) instead of being constant. Implementations must bound this to avoid denial of service.
  • Integrators that only see one side (a DEX, or an NFT marketplace) can be surprised by side effects on the other side, so test both views.

#token #erc20 #erc1155 #fractionalization #hybrid

Details

Authors
Sennett Lau (@sennett-lau)
Status
Draft
Type
Standards Track / ERC
Created
2024-04-08
Requires

Machine-readable: Markdown · JSON