EIPs Explained

ERC-7837 · Final · ERC · 2024-12-07

ERC-7837: Diffusive Tokens

A fungible token where transfer mints new tokens to the recipient instead of moving the sender's, with a per-token ETH fee paid to the issuer and an owner-set supply cap.

What problem does it solve?

In an ERC-20 token, total supply is redistributed by transfers: if A sends 10 tokens to B, A has 10 fewer. ERC-7837 describes a different economic model, Diffusive Tokens (DIFF), aimed at cases where an issuer wants tokens to spread out on demand rather than be pre-minted and passed around.

The spec's example is a manufacturer issuing tokens for a batch of physical products: each token can later be burned to redeem one item. Holders "pass on" tokens by minting new ones to others, paying the issuer a fee for each, until a maximum supply is reached.

How it works

  • Transfer mints. transfer(to, amount) does not reduce the sender's balance. It mints amount new tokens to to and increases totalSupply.
  • Native fee. The sender must pay transferFee * amount in the chain's native currency via msg.value; otherwise the call reverts. Fees accumulate in the contract.
  • Supply cap. A transfer that would push totalSupply above maxSupply reverts.
  • Burn. Holders can burn(amount) to reduce their balance and the total supply, for example to redeem the underlying good.
  • Owner controls. The owner can setTransferFee, setMaxSupply (not below current supply) and withdrawFees(recipient).
  • Optional approvals. approve/transferFrom exist for compatibility; transferFrom consumes allowance but still mints to to without debiting from.

Events: Transfer, Burn, FeeUpdated, MaxSupplyUpdated.

Because transfer and transferFrom are payable and behave differently, DIFF is ERC-20 compatible only at the interface level, not in behavior.

Sample code

Core logic, condensed from the spec's reference implementation:

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

contract DiffusiveToken {
    uint256 public totalSupply;
    uint256 public maxSupply;
    uint256 public transferFee;          // wei per token
    address public owner;
    mapping(address => uint256) public balanceOf;

    event Transfer(address indexed from, address indexed to, uint256 amount);
    event Burn(address indexed burner, uint256 amount);

    constructor(uint256 _maxSupply, uint256 _fee) {
        maxSupply = _maxSupply;
        transferFee = _fee;
        owner = msg.sender;
    }

    function transfer(address to, uint256 amount) external payable returns (bool) {
        require(to != address(0) && amount > 0, "bad args");
        require(msg.value >= transferFee * amount, "insufficient fee");
        require(totalSupply + amount <= maxSupply, "cap");
        balanceOf[to] += amount;          // sender keeps their balance
        totalSupply += amount;
        emit Transfer(msg.sender, to, amount);
        return true;
    }

    function burn(uint256 amount) external {
        balanceOf[msg.sender] -= amount;  // reverts on underflow
        totalSupply -= amount;
        emit Burn(msg.sender, amount);
    }

    function withdrawFees(address payable to) external {
        require(msg.sender == owner, "owner");
        (bool ok, ) = to.call{value: address(this).balance}("");
        require(ok, "withdraw failed");
    }
}

Things to know

  • Status is Final.
  • Anyone can call transfer regardless of their own balance. As written in the spec, holding tokens is not required to mint them to others; the fee and the cap are the only limits.
  • DEXs, lending protocols and wallets assume ERC-20 transfers conserve supply. Integrating a DIFF token with them can produce wrong prices, accounting or balances, and payable transfers will fail in callers that send no value.
  • The owner can change the fee and raise the cap at any time, which is a significant trust assumption for holders.
  • The spec's reference contract has bugs if copied literally (for example it reads balances and allowances mappings it never declares); review and test before using any implementation.

#token #fungible #minting #erc-20 #fees

Details

Authors
Cheng Qian (@jamesavechives) <[email protected]>
Status
Final
Type
Standards Track / ERC
Created
2024-12-07

Machine-readable: Markdown · JSON