Skip to content

Rewards: fix calculation by using a snapshot of token supply at the time that signal was last updated #569

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Jul 27, 2022

Conversation

pcarranzav
Copy link
Member

Current rewards calculation tries to follow a curve p*r^(t-b) - p, where p is token supply, r is issuance rate plus one, t is current block and b is the block when signal was last updated on any subgraph.

For this to follow the expected curve, however, p must correspond to the token supply at block b, and not to the time-varying instant supply. This PR fixes the calculation by adding a token supply snapshot, and adds two regression tests that are fixed by this PR and that exemplify the consequences of this bug.

Note that this also changes the RewardsManager.initialize() function by removing the call to set issuance rate, since we now need the address of the GraphToken contract (to get the supply snapshot) that is not available at initialization time.

@codecov
Copy link

codecov bot commented May 16, 2022

Codecov Report

Merging #569 (7d00cbf) into dev (5272f4a) will not change coverage.
The diff coverage is 100.00%.

@@           Coverage Diff           @@
##              dev     #569   +/-   ##
=======================================
  Coverage   90.28%   90.28%           
=======================================
  Files          35       35           
  Lines        1750     1750           
  Branches      291      291           
=======================================
  Hits         1580     1580           
  Misses        170      170           
Flag Coverage Δ
unittests 90.28% <100.00%> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
contracts/rewards/RewardsManager.sol 95.95% <100.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 5272f4a...7d00cbf. Read the comment docs.

abarmat
abarmat previously approved these changes May 16, 2022
Copy link
Contributor

@abarmat abarmat left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking good! 🥇

@abarmat abarmat added bug Something isn't working protocol change labels May 19, 2022
@abarmat abarmat merged commit 7c6e27d into dev Jul 27, 2022
@abarmat abarmat deleted the pcv/rewards-supply-fixes branch July 27, 2022 14:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working protocol change
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants