|
| 1 | +--- |
| 2 | +eip: 0000 |
| 3 | +title: Diffusive Tokens |
| 4 | +description: A fungible token that mints new tokens on transfer, charges a per-token native fee, and enforces a capped supply. |
| 5 | +author: James Savechives (@jamesavechives) |
| 6 | +discussions-to: https://ethereum-magicians.org/t/discussion-on-eip-0000-diffusive-tokens/20890 |
| 7 | +status: Draft |
| 8 | +type: Standards Track |
| 9 | +category: ERC |
| 10 | +created: 2024-12-07 |
| 11 | +--- |
| 12 | + |
| 13 | +## Abstract |
| 14 | + |
| 15 | +This ERC proposes a standard for a new type of fungible token, called **Diffusive Tokens (DIFF)**. Unlike traditional [ERC-20](./eip-20.md) tokens, transferring DIFF tokens does not decrease the sender’s balance. Instead, it *mints* new tokens directly to the recipient, increasing the total supply on every transfer action. A fixed native currency fee is charged per token transferred, and this fee is paid by the sender to the contract owner. The supply growth is limited by a maximum supply set by the owner. Token holders can also burn their tokens to reduce the total supply. These features enable a controlled, incentivized token distribution model that merges fungibility with a built-in economic mechanism. |
| 16 | + |
| 17 | +## Motivation |
| 18 | + |
| 19 | +Traditional [ERC-20](./eip-20.md) tokens maintain a constant total supply and simply redistribute balances on transfers. While this model is widespread, certain use cases benefit from a token design that continuously expands supply during transfers, simulating a controlled "diffusion" of value. The Diffusive Token model may be suitable for representing claims on real-world goods (e.g., a product batch like iPhone 15 units), digital goods, or controlled asset distributions where initial token distribution and ongoing availability need to be managed differently. |
| 20 | + |
| 21 | +This model also includes a native currency fee per token transferred, incentivizing careful, value-driven transfers and providing a revenue stream for the token’s issuer. The maximum supply cap prevents unbounded inflation, ensuring long-term scarcity. The ability for owners to burn tokens to redeem underlying goods or services directly maps on-chain assets to real-world redemptions. |
| 22 | + |
| 23 | +## Specification |
| 24 | + |
| 25 | +### Terminology |
| 26 | + |
| 27 | +- **Diffusive Token**: A fungible token unit that is minted on transfers. |
| 28 | +- **Max Supply**: The maximum total supply the token can reach. |
| 29 | +- **Transfer Fee**: A fee in native blockchain currency (e.g., ETH) that must be paid by the sender for each token transferred. The total fee = `transferFee * amount`. |
| 30 | +- **Burn**: The action of destroying tokens, reducing both the holder’s balance and the total supply. |
| 31 | + |
| 32 | +### Data Structures |
| 33 | + |
| 34 | +- **Balances Mapping**: `balances[address] = uint256` tracks the number of tokens owned by each address. |
| 35 | + |
| 36 | + ```solidity |
| 37 | + mapping(address => uint256) private balances; |
| 38 | + ``` |
| 39 | + |
| 40 | +- **Total Supply and Max Supply**: |
| 41 | + |
| 42 | + ```solidity |
| 43 | + uint256 public totalSupply; |
| 44 | + uint256 public maxSupply; |
| 45 | + ``` |
| 46 | + |
| 47 | +- **Transfer Fee**: |
| 48 | + |
| 49 | + ```solidity |
| 50 | + uint256 public transferFee; // fee per token transferred in wei |
| 51 | + address public owner; |
| 52 | + ``` |
| 53 | + |
| 54 | + The `owner` sets and updates `transferFee` and `maxSupply`. |
| 55 | + |
| 56 | +### Token Semantics |
| 57 | + |
| 58 | +1. **Minting on Transfer** |
| 59 | + When a transfer occurs from `A` to `B`: |
| 60 | + - `A` does not lose any tokens. |
| 61 | + - `B` receives newly minted tokens (increasing their balance and totalSupply). |
| 62 | + - The `totalSupply` increases by the transferred amount, but must not exceed `maxSupply`. |
| 63 | + |
| 64 | +2. **Fixed Transfer Fee in Native Currency** |
| 65 | + Each transfer requires the sender to pay `transferFee * amount` in the native currency. If `msg.value` is insufficient, the transaction reverts. |
| 66 | + |
| 67 | +3. **Maximum Supply** |
| 68 | + If a transfer would cause `totalSupply + amount > maxSupply`, it must revert. |
| 69 | + |
| 70 | +4. **Burning Tokens** |
| 71 | + Token holders can burn tokens to: |
| 72 | + - Reduce their balance by the burned amount. |
| 73 | + - Decrease `totalSupply` by the burned amount. |
| 74 | + |
| 75 | + This can map to redeeming underlying goods or simply deflating the token. |
| 76 | + |
| 77 | +### Interface |
| 78 | + |
| 79 | +The DIFF standard aligns partially with [ERC-20](./eip-20.md), but redefines certain behaviors: |
| 80 | + |
| 81 | +**Core Functions:** |
| 82 | + |
| 83 | +- `function balanceOf(address account) external view returns (uint256);` |
| 84 | + |
| 85 | +- `function transfer(address to, uint256 amount) external payable returns (bool);` |
| 86 | + |
| 87 | + - **Modified behavior**: Mints `amount` tokens to `to`, requires `msg.value >= transferFee * amount`. |
| 88 | + |
| 89 | +- `function burn(uint256 amount) external;` |
| 90 | + |
| 91 | + - Reduces sender’s balance and `totalSupply`. |
| 92 | + |
| 93 | +**Administration Functions (Owner Only):** |
| 94 | + |
| 95 | +- `function setMaxSupply(uint256 newMax) external;` |
| 96 | + |
| 97 | +- `function setTransferFee(uint256 newFee) external;` |
| 98 | + |
| 99 | +- `function withdrawFees(address payable recipient) external;` |
| 100 | + |
| 101 | + - Withdraws accumulated native currency fees. |
| 102 | + |
| 103 | +**Optional Approval Interface (For Compatibility):** |
| 104 | + |
| 105 | +- `function approve(address spender, uint256 amount) external returns (bool);` |
| 106 | +- `function transferFrom(address from, address to, uint256 amount) external payable returns (bool);` |
| 107 | + |
| 108 | + - **Modified behavior**: Similar to `transfer`, but uses allowance and still mints tokens to `to` rather than redistributing from `from`. |
| 109 | + |
| 110 | +### Events |
| 111 | + |
| 112 | +- `event Transfer(address indexed from, address indexed to, uint256 amount);` |
| 113 | + |
| 114 | + Emitted when tokens are minted to `to` via a transfer call. |
| 115 | + |
| 116 | +- `event Burn(address indexed burner, uint256 amount);` |
| 117 | + |
| 118 | + Emitted when `amount` of tokens are burned from an address. |
| 119 | + |
| 120 | +- `event FeeUpdated(uint256 newFee);` |
| 121 | + |
| 122 | + Emitted when the owner updates the `transferFee`. |
| 123 | + |
| 124 | +- `event MaxSupplyUpdated(uint256 newMaxSupply);` |
| 125 | + |
| 126 | + Emitted when the owner updates `maxSupply`. |
| 127 | + |
| 128 | +### Compliance with ERC-20 |
| 129 | + |
| 130 | +The DIFF standard implements the ERC-20 interface but significantly alters the `transfer` and `transferFrom` semantics: |
| 131 | + |
| 132 | +- **Fungibility**: Each token unit is identical and divisible as in ERC-20. |
| 133 | +- **Balances and Transfers**: The `balanceOf` function works as normal. However, `transfer` and `transferFrom` no longer redistribute tokens. Instead, they mint new tokens (up to `maxSupply`). |
| 134 | +- **Approvals**: The `approve` and `transferFrom` functions remain, but their logic is unconventional since the sender’s balance is never reduced by transfers. |
| 135 | + |
| 136 | +While the DIFF standard can be seen as ERC-20 compatible at the interface level, the underlying economics differ substantially. |
| 137 | + |
| 138 | +## Rationale |
| 139 | + |
| 140 | +**Use Cases**: |
| 141 | + |
| 142 | +- **Real-World Asset Backing**: A manufacturer can issue DIFF tokens representing a batch of products (e.g., iPhones). Each token can be redeemed (burned) for one physical item. |
| 143 | + |
| 144 | +- **Fee-Driven Incentives**: The transfer fee ensures that infinite minting by constant transferring is economically disincentivized. The fee also supports the token issuer or provides a funding mechanism. |
| 145 | + |
| 146 | +**Design Decisions**: |
| 147 | + |
| 148 | +- **Unlimited Minting vs. Max Supply**: Allowing minting on every transfer provides a “diffusive” spread of tokens. The `maxSupply` prevents uncontrolled inflation. |
| 149 | + |
| 150 | +- **Burn Mechanism**: Enables redemption or deflation as tokens are taken out of circulation. |
| 151 | + |
| 152 | +- **Owner Controls**: The owner (e.g., issuer) can adjust fees and max supply, maintaining flexibility as market conditions change. |
| 153 | + |
| 154 | +## Backwards Compatibility |
| 155 | + |
| 156 | +The DIFF standard is interface-compatible with ERC-20 but not behaviorally identical. Any system integrating DIFF tokens should understand the difference in minting on transfer. |
| 157 | + |
| 158 | +- **Wallets and Exchanges**: Most ERC-20 compatible tools can display balances and initiate transfers. However, the unusual economics (mint on transfer) may confuse users and pricing mechanisms. |
| 159 | +- **Allowances and TransferFrom**: Still implemented for interoperability, but the expected logic (debiting `from` balance) does not apply. |
| 160 | + |
| 161 | +## Test Cases |
| 162 | + |
| 163 | +1. **Initial Conditions**: |
| 164 | + - Deploy contract with `maxSupply = 1,000,000 DIFF`, `transferFee = 0.001 ETH`. |
| 165 | + - `totalSupply = 0`. |
| 166 | + - Owner sets parameters and verifies via `maxSupply()` and `transferFee()` getters. |
| 167 | + |
| 168 | +2. **Minting on Transfer**: |
| 169 | + - User A calls `transfer(B, 100)` with `msg.value = 0.1 ETH` (assuming `transferFee = 0.001 ETH`). |
| 170 | + - Check `balances[B] == 100`, `totalSupply == 100`. |
| 171 | + - Check that the contract now holds 0.1 ETH from the fee. |
| 172 | + |
| 173 | +3. **Exceeding Max Supply**: |
| 174 | + - If `totalSupply = 999,950` and someone tries to transfer 100 tokens, causing `totalSupply` to exceed `1,000,000`, the transaction reverts. |
| 175 | + |
| 176 | +4. **Burning Tokens**: |
| 177 | + - User B calls `burn(50)`. |
| 178 | + - Check `balances[B] == 50`, `totalSupply == 50` less than before. |
| 179 | + - `Burn` event emitted. |
| 180 | + |
| 181 | +5. **Updating Fee and Withdrawing Funds**: |
| 182 | + - Owner calls `setTransferFee(0.002 ETH)`. |
| 183 | + - `FeeUpdated` event emitted. |
| 184 | + - Owner calls `withdrawFees(ownerAddress)`. |
| 185 | + - Check that `ownerAddress` receives accumulated fees. |
| 186 | + |
| 187 | +## Reference Implementation |
| 188 | + |
| 189 | +A reference implementation is provided under the asset folder in the EIPs repository. The implementation includes: |
| 190 | + |
| 191 | +- [`DiffusiveToken.sol`]((../assets/eip-0000/DiffusiveToken.sol)): A basic contract implementing the DIFF standard. |
| 192 | +- Interfaces and helper contracts for testing and demonstration purposes. |
| 193 | + |
| 194 | +## Security Considerations |
| 195 | + |
| 196 | +- **Reentrancy**: Handle fee transfers using the Checks-Effects-Interactions pattern. Consider `ReentrancyGuard` from OpenZeppelin to prevent reentrant calls. |
| 197 | +- **Overflow/Underflow**: Solidity 0.8.x guards against this by default. |
| 198 | +- **Contract Balance Management**: Ensure enough native currency is sent to cover fees. Revert on insufficient fees. |
| 199 | +- **Access Control**: Only the owner can update `transferFee` and `maxSupply`. Use proper `onlyOwner` modifiers. |
| 200 | + |
| 201 | +## Copyright |
| 202 | + |
| 203 | +Copyright and related rights waived via [CC0](../LICENSE.md). |
0 commit comments