ERC-6353 Charitable Donation Token Extension (Charity token)
Stagnant · Tokens · created 2022-05-13
An ERC-20 extension standard that automatically sends a fixed percentage to a charity address on every transaction. Token holders can specify their own donation recipient and rate, or turn it off.
Why it is needed
With existing ERC-20 tokens, the entire transfer amount goes straight to the recipient, so there is no standardized way to donate a portion to a charity on every transfer. As a result, each project ends up implementing its own donation rate, recipient address, and registration process, and wallet or app developers have no common way to find out which tokens support donations or what the rate is. Even if token holders want to change the donation recipient or rate themselves, without a standard interface they would have to learn a different method for each contract. This standard solves these problems by defining a common interface for registering charity addresses, querying rates, and setting donation recipients.
What to implement
event AddedToWhitelist (address toAdd);: Emitted when a charity address is added to the whitelist.event RemovedFromWhitelist (address toRemove);: Emitted when a charity address is removed from the whitelist.event DonnationAddressChanged (address whitelistedAddr);: Emitted when a token holder's default charity address is changed.event DonnationAddressAndRateChanged (address whitelistedAddr,uint256 rate);: Emitted when the default charity address and donation rate are changed together.event ModifiedCharityRate(address whitelistedAddr,uint256 rate);: Emitted when the donation rate for a specific whitelisted address is modified.function addToWhitelist(address toAdd) external;: Adds a charity address to the whitelist and sets the rate to the default value.function deleteFromWhitelist(address toRemove) external;: Removes a charity address from the whitelist and resets the rate to the default value.function getAllWhitelistedAddresses() external;: Queries the list of all registered charity addresses.function getRate() external view returns (uint256);: Queries the donation rate currently applied to the default charity address.function setSpecificDefaultAddress(address whitelistedAddr) external;: Specifies the default charity address to which a token holder's donations go (the default rate applies).function deleteDefaultAddress() external;: Deletes the default charity address setting, disabling donations.
In depth
Registering charity addresses (whitelist)
After review, the contract owner registers a charity address in whitelistedRate with addToWhitelist(toAdd), and at this point the rate is set to the global default value. The rate must not be 0 (null) to register. Registration can be revoked with deleteFromWhitelist(toRemove), and the AddedToWhitelist and RemovedFromWhitelist events are emitted on registration and removal respectively. getAllWhitelistedAddresses() lets you query all registered charity addresses.
Setting the donation rate
In addition to the default rate set by the owner at registration, setSpecificRate(whitelistedAddr, rate) can be used to assign a personalized rate to a specific whitelisted address. In this case, the rate cannot be lower than the default rate. When the rate changes, a ModifiedCharityRate event is emitted. Token holders can query the rate applied to their default charity address with getRate().
Token holders specifying a donation recipient
Token holders can use setSpecificDefaultAddress(whitelistedAddr) to designate a donation recipient to which the rate registered in the whitelist applies, or setSpecificDefaultAddressAndRate(whitelistedAddr, rate) to specify the rate directly as well (the rate cannot be lower than the default rate or the rate set by the owner). specificDefaultAddress() queries the current donation recipient, and deleteDefaultAddress() deletes the designation, disabling donations. The address must not be the zero address for donations to be active. When the setting changes, a DonnationAddressChanged or DonnationAddressAndRateChanged event is emitted.
Processing donations on transfer
When transfer or transferFrom is called while donations are active, the transfer amount and the donation amount are deducted together from the sender's balance. The transfer amount goes to the recipient and the donation amount goes to the designated charity address, and two Transfer events are emitted. If the sender's balance cannot cover the sum of the transfer amount and the donation amount, the entire transaction reverts. The approve function is also subject to being overridden.
Design rationale: arrays and storage approach
This standard manages whitelisted addresses as an array and tracks active status with the whitelistedRate mapping, allowing multiple donation recipients to be selected and ensuring transparency. For simplicity, donations are processed directly within transfer rather than through a separate function, but implementations could instead allow transfers without a donation even while donations are active, or hold the donation amount in the contract (or a separate contract) for the charity to claim directly. The donation amount is calculated as a percentage of the transfer amount, but implementers may choose other approaches such as rounding.
Backward compatibility and proposal status
This standard is an extension that otherwise preserves the core ERC-20 interface and functionality as is, but there is a minor compatibility issue. If an account's balance cannot cover the sum of the transfer amount and the donation amount, a transfer that would previously have succeeded may fail. The security considerations state that nothing is added beyond ERC-20. This proposal is in the Stagnant state, meaning it is no longer actively discussed and has stalled.