Skip to content
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

feat: accounting for inflation update in tokenomics #200

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

kupermind
Copy link
Collaborator

  • Accounting for inflation update in tokenomics.

Comment on lines +1302 to +1304
if (msg.sender != owner) {
revert OwnerOnly(msg.sender, owner);
}
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This can be called by owner at any time, as the logic below accounts for it.

Comment on lines +1334 to +1336
maxBond = uint96(curMaxBond);
effectiveBond = uint96(curEffectiveBond);
inflationPerSecond = uint96(curInflationPerSecond);
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

These are critical values that need to be updated.

Copy link
Contributor

Choose a reason for hiding this comment

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

So we only need to do this for bonding?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Correct, bonding is the only one that is issued as a credit for epoch, the rest is end-of-epoch-computed.

@@ -251,7 +251,7 @@ module.exports = {
settings: {
optimizer: {
enabled: true,
runs: 1500,
runs: 750,
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Need to reduce optimization iterations in order to fit into deployment size

Comment on lines +1310 to +1313
// Revert if the year changes within the next epoch as it requires more complicated set of calculations
if (numYears > currentYear) {
revert Overflow(numYears, currentYear);
}
Copy link
Contributor

Choose a reason for hiding this comment

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

hm - can you be more explicit what happens then?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

When the year changes, the complex re-calculation of inflation before the exact second year end and the rest of the epoch happens, so it's better to avoid to perform another change during that time.

Copy link
Contributor

Choose a reason for hiding this comment

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

OK

Copy link
Contributor

Choose a reason for hiding this comment

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

Please add as much detail in the contract comment for future


// Ensure effectiveBond is bigger than maxBond
uint256 curEffectiveBond = effectiveBond;
uint256 curMaxBond = maxBond;
Copy link
Contributor

Choose a reason for hiding this comment

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

what's maxBond?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

max amount that can go for bonding per epoch.

// Adjust effective bond by reducing it with the on-going epoch maxBond value
curEffectiveBond -= curMaxBond;

// Recalculate inflation per second based on the updated current year inflation
Copy link
Contributor

Choose a reason for hiding this comment

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

If the curve hasn't changed, the value will be the same as before right? We should have a test

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Correct

Copy link
Contributor

Choose a reason for hiding this comment

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

Let's add this as a comment to the contract and also write a test for it

Comment on lines +1334 to +1336
maxBond = uint96(curMaxBond);
effectiveBond = uint96(curEffectiveBond);
inflationPerSecond = uint96(curInflationPerSecond);
Copy link
Contributor

Choose a reason for hiding this comment

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

So we only need to do this for bonding?

}

// Adjust effective bond by reducing it with the on-going epoch maxBond value
curEffectiveBond -= curMaxBond;
Copy link
Contributor

Choose a reason for hiding this comment

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

don't follow

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

maxBond is given as a credit for epoch, so we need to subtract what is already given in the current epoch based on previous inflation, and add it again later based on a new inflation.

curEffectiveBond -= curMaxBond;

// Recalculate inflation per second based on the updated current year inflation
uint256 curInflationPerSecond = getInflationForYear(currentYear) / ONE_YEAR;
Copy link
Collaborator

Choose a reason for hiding this comment

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

@kupermind @mariapiamo
Is there some unaccounted/side effect between the current implementation, when it changes strictly once a year and in the constants there is a mutually agreed table of inflation per year with the fact that now inflation can change an arbitrary number of times during the year.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

We just need to give an extra buffer accounting for the current inflation and for the time when it's going to change to another one.

curEffectiveBond -= curMaxBond;

// Recalculate inflation per second based on the updated current year inflation
uint256 curInflationPerSecond = getInflationForYear(currentYear) / ONE_YEAR;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Needing new implementation getInflationForYear()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants