ERC-4931 General-purpose token upgrade standard (Generic Token Upgrade Standard)

Stagnant · Tokens · created 2021-11-02

An upgrade-only interface that allows one ERC20 token (source) to be exchanged for another ERC20 token (target) in a standardized way.

Why it is needed

When a token issuer switches to a new contract, developers typically build a custom screen and script on an ad hoc basis to swap the existing token for the new one. With this approach, holders and exchanges must analyze and trust unfamiliar contract code from scratch for every upgrade, creating a heavy verification burden, and the upgrade logic is mixed into the token contract itself rather than being separated from the token's functionality. Furthermore, if how the source token is handled (whether it is burned or sent somewhere) is not standardized, it becomes difficult to prevent the same token from being upgraded multiple times, which can call into question the reliability of the upgrade itself.

What to implement

In depth

The source/destination pair and ratio

upgradeSource and upgradeDestination each return the address of the token contract before and after the upgrade. ratio returns the exchange rate of target tokens relative to source tokens as a (numerator, denominator) tuple; for example, (3, 1) means 3 target tokens are given per 1 source token. This ratio is the baseline value applied consistently across computeUpgrade, computeDowngrade, and the execution of both upgrade and downgrade.

Remainder calculation in computeUpgrade and computeDowngrade

computeUpgrade(sourceAmount) is a lookup function that precomputes the result without actually calling upgrade, returning both the destinationAmount to be received and the sourceRemainder that does not divide evenly into the ratio and thus is not converted. The specification states that at a ratio of (3, 2), when sourceAmount is 5, computeUpgrade(5) must return (6, 1). In other words, 4 units of source are converted to give 6 units of target, leaving 1 unit of source as remainder. computeDowngrade calculates the reverse direction the same way; at the same (3, 2) ratio, when destinationAmount is 13, computeDowngrade(13) returns (4, 1), converting 12 units of target into 4 units of source and leaving 1 unit of target as remainder.

Conditions for executing upgrade and handling of the source token

upgrade(_to, sourceAmount) converts the caller's source tokens into destination tokens according to the ratio and sends them to the _to address. approve must have been called on the source contract beforehand, and the function must throw if the caller's source token balance is insufficient or if isUpgradeActive is false. The function must emit the Upgrade event, and the source token must be locked in the upgrade contract or burned. If the downgrade extension is implemented, it must be locked instead of burned.

Optional downgrade extension

downgrade is an Optional Ext., a feature that does not need to be implemented. If implemented, downgrade(_to, destinationAmount) must unwrap the destination token back into the source token and send it to the _to address. Before the call, approve must have already been called on the destination contract, and it must throw if the caller has insufficient destination tokens or if isDowngradeActive is false, and it must emit a Downgrade event. If downgrade is not implemented, isDowngradeActive must always return false to indicate that downgrade is unavailable.

The increase/decrease behavior of totalUpgraded

totalUpgraded returns the total amount upgraded from source to destination so far. If the downgrade extension is not implemented, only upgrade is possible, so this value only ever increases. Conversely, if downgrade is implemented, calling downgrade can decrease this value, so it may decrease between calls.

The rationale for the source token burn/lock principle

The Rationale views prior cases like Golem (GNT to GLM), which built the upgrade function directly into the token contract itself, as a suboptimal approach that couples the upgrade and token functionality too tightly. This standard separates the upgrade into a separate third-party contract so that the token contract's implementation does not interfere with the upgrade process. There is an agreed-upon rule for handling the source token: tokens that can be burned must be burned via burn, and tokens that cannot be must be sent to the 0x00 address to be effectively burned. If the downgrade extension is implemented, the source token is instead locked in the upgrade contract, to prevent the supply of the source or destination token from being artificially inflated by repeatedly calling upgrade and downgrade.

Backward compatibility

This standard has no backward compatibility issues that break existing functionality. However, it notes that existing token upgrades already implemented are likely not to follow this standard, and in such cases it is desirable for the asset issuer to disclose that their upgrade does not comply with EIP-4931.

Proposal status

This ERC is currently Stagnant, meaning discussion has stalled. It is not yet a finalized standard, so its content may change or may not be adopted.

Things to watch out for

Original ERC · ← ERCs