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(StakeManager): implement multiplier points estimation #97

Merged
merged 2 commits into from
Sep 10, 2024

Conversation

0x-r4bbit
Copy link
Collaborator

@0x-r4bbit 0x-r4bbit commented Aug 8, 2024

Description

This commit introduces the internal accounting logic for accrueing
multiplier points, that will later be used to determine how many
experience points an account is eligible to.

The majority of the work here was done by @3esmit.

Checklist

Ensure you completed all of the steps below before submitting your pull request:

  • Added natspec comments?
  • Ran forge snapshot?
  • Ran pnpm gas-report?
  • Ran pnpm lint?
  • Ran forge test?
  • Ran pnpm verify?

contracts/StakeManager.sol Outdated Show resolved Hide resolved
contracts/StakeManager.sol Outdated Show resolved Hide resolved
contracts/StakeManager.sol Outdated Show resolved Hide resolved
contracts/StakeManager.sol Outdated Show resolved Hide resolved
@0x-r4bbit 0x-r4bbit force-pushed the mp-estimate branch 2 times, most recently from 502254c to 31dde1a Compare September 4, 2024 08:01
contracts/StakeManager.sol Outdated Show resolved Hide resolved

StakeRewardEstimate public stakeRewardEstimate;

uint256 public currentEpochExpiredMP;
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

How about currentEpochMissedMP ?

userReward += userEpochReward;
iEpoch.epochReward -= userEpochReward;
iEpoch.totalSupply -= userSupply;
//TODO: remove epoch when iEpoch.totalSupply reaches zero
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@3esmit I think this TODO should be part of this PR

}
account.epoch = userEpoch;
if (userReward > 0) {
pendingReward -= userReward;
stakedToken.transfer(account.rewardAddress, userReward);
}
mpDifference = account.totalMP - mpDifference;
mpDifference = account.totalMP - mpDifference; //TODO: optimize, this only needed for migration
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Can we resolve this as well?

contracts/StakeManager.sol Outdated Show resolved Hide resolved
foundry.toml Outdated Show resolved Hide resolved
assertEq(stakeManager.totalSupplyMP(), 0, "totalSupplyMP burned after unstaking");
assertEq(totalMP, 0, "userMP burned after unstaking");
}

function test_restakeOnLocked() public {
function _test_restakeOnLocked() public {
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I wonder if we should remove all the tests related to restaking altogether.

There's also #103 , maybe we make it as part of that?

Copy link
Collaborator

Choose a reason for hiding this comment

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

I guess so, or refactor onto not tests.

test/StakeManager.t.sol Outdated Show resolved Hide resolved
// only perform the assert below one epoch after *that*
if (i > 0) {
assertEq(totalMP, totalMPBefore, "must NOT increase MPs");
}
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@3esmit this is a fix I've introduced as it would otherwise immediately have a failing assertion.
Reason being is that we always have that 1 epoch after maxlimit epoch in which MPs will be minted, if there's accounts that started staking after the start time of any given epoch (which is likely 99% the case in reality).

So we have to check for greater 0 here to perform the assertion only after we've really minted the last MPs.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Is not always, I am not sure about that. And in some cases (really small staking values), can be 2 epochs.

It should use the same calculations as in the smart contract, or better, use precalculated values and precalculated static checks.

test/StakeManager.t.sol Outdated Show resolved Hide resolved
@0x-r4bbit 0x-r4bbit changed the title WIP: MP estimation logic feat(StakeManager): implement multiplier points estimation Sep 4, 2024
@0x-r4bbit 0x-r4bbit force-pushed the mp-estimate branch 6 times, most recently from 620a4b6 to 44d16c4 Compare September 5, 2024 11:41
@0x-r4bbit 0x-r4bbit mentioned this pull request Sep 5, 2024
6 tasks
This commit introduces the internal accounting logic for accrueing
multiplier points, that will later be used to determine how many
experience points an account is eligible to.

The majority of the work here was done by @3esmit.
if (iEpoch.totalSupply == 0) {
pendingReward -= iEpoch.epochReward;
delete epochs[userEpoch];
}
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Hm.. This seems a bit odd.
We're subtracting iEpoch.epochReward from pendingReward, and we're also subtracting userReward from pendingReward in line 459.

Shouldn't we only subtract the userReward from pendingReward? And shouldn't we only do this once, not twice?

Also, this changes causes the rule to fail that subOfEpochRewards == pendingReward
Need to check this.

@0x-r4bbit
Copy link
Collaborator Author

@3esmit I've removed the optimization changes and put them back in a separate PR via #105
Reason being is that those changes are breaking a rule on certora and we first have to figure out how that one can be fixed.

I don't want those optimizations to block this one here from landing.

@0x-r4bbit 0x-r4bbit merged commit 5dec595 into develop Sep 10, 2024
8 checks passed
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.

2 participants