EIPs Explained

ERC-7837 · Final(확정) · ERC · 2024-12-07

ERC-7837: Diffusive Tokens

transfer가 발신자의 토큰을 옮기는 대신 수신자에게 새 토큰을 민팅하는 대체 가능 토큰. 토큰당 ETH 수수료를 발행자에게 내며, 공급 상한은 소유자가 설정한다.

어떤 문제를 해결하나요?

ERC-20 토큰에서는 총 공급량이 전송을 통해 재분배됩니다. A가 B에게 10개를 보내면 A는 10개가 줄어듭니다. ERC-7837은 **Diffusive Tokens(DIFF)**라는 다른 경제 모델을 설명합니다. 발행자가 토큰을 미리 민팅해 돌리는 대신 수요에 따라 퍼져 나가게 하고 싶은 경우를 겨냥합니다.

스펙의 예시는 제조사가 실물 제품 한 묶음에 대해 토큰을 발행하는 경우입니다. 각 토큰은 나중에 소각해 제품 하나로 교환할 수 있습니다. 보유자는 다른 사람에게 새 토큰을 민팅하는 방식으로 토큰을 "넘겨주고", 그때마다 발행자에게 수수료를 내며, 최대 공급량에 도달할 때까지 이어집니다.

어떻게 동작하나요?

  • transfer가 민팅한다. transfer(to, amount)는 발신자의 잔액을 줄이지 않습니다. to에게 amount만큼의 새 토큰을 민팅하고 totalSupply를 늘립니다.
  • 네이티브 수수료. 발신자는 msg.value를 통해 체인의 네이티브 통화로 transferFee * amount를 내야 하며, 그렇지 않으면 호출이 revert됩니다. 수수료는 컨트랙트에 쌓입니다.
  • 공급 상한. totalSupply가 maxSupply를 넘기게 되는 전송은 revert됩니다.
  • 소각. 보유자는 burn(amount)로 자신의 잔액과 총 공급량을 줄일 수 있습니다. 예를 들어 기초 상품으로 교환할 때 씁니다.
  • 소유자 권한. 소유자는 setTransferFee, setMaxSupply(현재 공급량 미만으로는 불가), withdrawFees(recipient)를 실행할 수 있습니다.
  • 선택적 승인. 호환성을 위해 approve/transferFrom이 있습니다. transferFrom은 allowance를 소모하지만, from의 잔액을 차감하지 않고 to에게 민팅합니다.

이벤트: Transfer, Burn, FeeUpdated, MaxSupplyUpdated.

transfer와 transferFrom은 payable이고 동작도 다르므로, DIFF는 인터페이스 수준에서만 ERC-20과 호환되고 동작은 호환되지 않습니다.

샘플 코드

스펙의 참조 구현에서 핵심 로직만 간추린 것:

// 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");
    }
}

알아둘 점

  • 상태는 Final입니다.
  • 누구나 자신의 잔액과 무관하게 transfer를 호출할 수 있습니다. 스펙에 쓰인 대로, 다른 사람에게 민팅하기 위해 토큰을 보유할 필요는 없으며 수수료와 상한만이 제약입니다.
  • DEX, 대출 프로토콜, 지갑은 ERC-20 전송이 공급량을 보존한다고 가정합니다. DIFF 토큰을 이들과 연동하면 가격, 회계, 잔액이 잘못될 수 있고, payable 전송은 value를 보내지 않는 호출자에서는 실패합니다.
  • 소유자는 언제든 수수료를 바꾸고 상한을 올릴 수 있으며, 이는 보유자에게 상당한 신뢰 가정입니다.
  • 스펙의 참조 컨트랙트는 글자 그대로 복사하면 버그가 있습니다(예: 선언한 적 없는 balances와 allowances 매핑을 읽습니다). 어떤 구현이든 사용하기 전에 검토하고 테스트하세요.

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

상세 정보

저자
Cheng Qian (@jamesavechives) <[email protected]>
상태
Final(확정)
유형
Standards Track / ERC
작성일
2024-12-07

기계 판독용 데이터: Markdown · JSON