ERC-2917 Staking reward calculation standard (Staking Reward Calculation)

Stagnant · Vaults & DeFi · created 2020-08-28

A common interface that calculates and pays out staking rewards on-chain in real time, proportional to a user's collateral and deposit duration.

Why it is needed

Existing DeFi projects' reward distribution methods had two problems. One was not distributing rewards until all users exited the contract, which made the distribution cycle too long and meant users had to withdraw their collateral first to receive rewards, which could actually put them at a disadvantage. The other was computing on-chain data off-chain and then only posting the result on-chain for distribution, which made it difficult to guarantee fairness and transparency since the core computation happened off-chain, creating a barrier to investment for users. Even as new DeFi projects emerged daily, users found it hard to know how much interest they would receive, how it was calculated, or how their contribution compared to that of all participants.

What to implement

In depth

Principle behind the reward calculation formula

ERC-2917 rewards are calculated based on the product of effective collateral and deposit duration. Between consecutive block numbers t_i-1 and t_i, the share for each interval (Δp_i/ΔP_i x ΔG_i) is computed using user U's individual productivity change (Δp_i), the total productivity change (ΔP_i), and the total reward amount for that interval (ΔG_i), and these shares are summed across all intervals. This formula is designed so that exiting early or entering late carries neither advantage nor disadvantage.

When recalculation occurs

The contract triggers reward calculation whenever a user's productivity increases or decreases, and whenever a user withdraws rewards. Because these two events serve as the trigger points, fair distribution is possible on-chain in real time without any separate off-chain computation.

Limitations of the two existing distribution methods

According to the Motivation section, existing DeFi projects used two methods. The first distributes rewards only when all users exit the contract, which has a long distribution cycle and can be disadvantageous since users must remove their collateral first to receive rewards. The second is a semi-decentralized approach that aggregates on-chain data, computes it off-chain, and then posts the result on-chain for distribution, which reduces fairness and transparency since the core algorithm runs off-chain, creating a barrier to investment for users.

Three groups within the interface

IERC2917 inherits from IERC20, and its functionality is divided into three groups: the interest rate management group (interestsPerBlock, changeInterestRatePerBlock), the productivity management group (getProductivity, increaseProductivity, decreaseProductivity), and the reward query/claim group (take, takeWithBlock, mint).

Recommendation on access restriction

It is recommended best practice to restrict changeInterestRatePerBlock so that only the contract address providing the gross product can call it. It is also recommended that increaseProductivity and decreaseProductivity be restricted so that only the contract proving productivity can call them. However, this is a recommendation in the @dev comments and is not enforced by the interface itself.

Difference between take() and takeWithBlock()

take() returns only the amount of interest mintable as of the current block height. takeWithBlock() returns the same interest amount together with the block height on which it was calculated, for example in the form (_amount, _block), allowing you to know the amount of interest accrued as of a specific block.

Proposal status

For this ERC, both the Rationale and Security Considerations sections are left as TBD, and its status is Stagnant. In other words, the detailed rationale and security considerations have not yet been filled in, and discussion on this proposal has stalled.

Original ERC · ← ERCs