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

fix(StakeManager): initial MP should not increase when locking #94

Closed
wants to merge 2 commits into from

Conversation

0x-r4bbit
Copy link
Collaborator

@0x-r4bbit 0x-r4bbit commented Jun 19, 2024

When an account calls lock() on the StakeManager it ultimately
called _mintInitialMP() which besides increasing the accounts
currentMP, it also increases the accounts initialMP.

This seems incorrect, as initialMP should only increase at first
stake.

Also, notice how inside lock() it always passes an amount of 0 to
to _mintInitialMP(), so it only ever uses one code path of that
function.

This commit adjust lock() such that it no longer uses
_mintInitialMP(). Instead it makes use of _getMaxMPToMint based on
the lock up time delta.

It also removes a test that claims that initialMP should increase on
lock() and instead adds a test an a CVL rule ensure initialMP
doesn't increase when locking.

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?

Some of the functions on our contracts were confusing.
This commit changes them so they describe what they actually do.
@0x-r4bbit 0x-r4bbit requested a review from 3esmit June 19, 2024 10:44
@0x-r4bbit
Copy link
Collaborator Author

Interesting, this change broke the MPcantBeGreaterThanMaxMP invariant.
Investigating this now..

@0x-r4bbit
Copy link
Collaborator Author

The issue here is that, when we lock() we just mint the amount of MPs necessary for the given duration but we don't perform the max boost check. And since we're no longer increasing the initialMP when locking, we end up with currentMP > account.balance + account.initialMP.

@@ -222,9 +222,18 @@ contract StakeManager is Ownable {
if (deltaTime < MIN_LOCKUP_PERIOD || deltaTime > MAX_LOCKUP_PERIOD) {
revert StakeManager__InvalidLockTime();
}
_mintInitialMP(account, _timeToIncrease, 0);
//update account storage
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

_mintInitalMP() increases account.initialMP which I don't think we want when we lock()

account.balance,
account.initialMP,
account.currentMP
);
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Instead we want to mint whatever MPs the account is entitled for.

@3esmit this ultimately relies on getMPToMin(account.balance, _timeToIncrease) just like before.
However, I'm wondering if we shouldn't instead do

_getMPToMint(account.balance, _timeToIncrease - account.lastMint)

What do you think?

account.lockUntil = lockUntil;
account.lastMint = block.timestamp;
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

The are storage updates that were otherwise happening in _mintInitialMP().

Question @3esmit: I think we need to update currentEpoch.totalSupply as well no?
If yes, then we could potentially just leverage _mintMP() instead.

When an account calls `lock()` on the `StakeManager` it ultimately
called `_mintInitialMP()` which besides increasing the accounts
`currentMP`, it also increases the accounts `initialMP`.

This seems incorrect, as `initialMP` should only increase at first
stake.

Also, notice how inside `lock()` it always passes an `amount` of `0` to
to `_mintInitialMP()`, so it only ever uses one code path of that
function.

This commit adjust `lock()` such that it no longer uses
`_mintInitialMP()`. Instead it makes use of `_getMaxMPToMint` based on
the lock up time delta.

It also removes a test that claims that `initialMP` should increase on
`lock()` and instead adds a test an a CVL rule ensure `initialMP`
doesn't increase when locking.
@0x-r4bbit 0x-r4bbit changed the base branch from refactor/better-fn-names to develop June 24, 2024 15:16
@0x-r4bbit
Copy link
Collaborator Author

I'm closing this PR as invalid.
As discussed with @3esmit offline, initialMP has to be updated when lock() is called to properly calculate the max cap MP later on.

It turned out that initialMP is just a misleading name. Hence, we're proposing the changes done in #95 which renames it to bonusMP.

@0x-r4bbit 0x-r4bbit closed this Jun 25, 2024
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.

1 participant