Skip to content

Commit

Permalink
fix(StakeManager): initial MP should not increase when locking
Browse files Browse the repository at this point in the history
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()` and simply inlines the calculation of the new MP to be
minted based on the lock up time delta.

It also removes a test that claims that `initialMP` should increase on
`lock()`.
  • Loading branch information
0x-r4bbit committed Jun 19, 2024
1 parent 3c4c463 commit c163c88
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 20 deletions.
7 changes: 6 additions & 1 deletion contracts/StakeManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -222,9 +222,14 @@ contract StakeManager is Ownable {
if (deltaTime < MIN_LOCKUP_PERIOD || deltaTime > MAX_LOCKUP_PERIOD) {
revert StakeManager__InvalidLockTime();
}
_mintInitialMP(account, _timeToIncrease, 0);

uint256 mpToMint = _getMPToMint(account.balance, _timeToIncrease);

//update account storage
totalSupplyMP += mpToMint;
account.currentMP += mpToMint;
account.lockUntil = lockUntil;
account.lastMint = block.timestamp;
}

/**
Expand Down
19 changes: 0 additions & 19 deletions test/StakeManager.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -412,25 +412,6 @@ contract LockTest is StakeManagerTest {
vm.expectRevert(StakeManager.StakeManager__InvalidLockTime.selector);
userVault.lock(minLockup - 1);
}

function test_ShouldIncreaseInitialMP() public {
uint256 stakeAmount = 100;
uint256 lockTime = stakeManager.MAX_LOCKUP_PERIOD();
StakeVault userVault = _createStakingAccount(testUser, stakeAmount);
(, uint256 balance, uint256 initialMP, uint256 currentMP,,,) = stakeManager.accounts(address(userVault));
uint256 totalSupplyMPBefore = stakeManager.totalSupplyMP();

vm.startPrank(testUser);
userVault.lock(lockTime);

(, uint256 newBalance, uint256 newInitialMP, uint256 newCurrentMP,,,) =
stakeManager.accounts(address(userVault));
uint256 totalSupplyMPAfter = stakeManager.totalSupplyMP();
assertGt(totalSupplyMPAfter, totalSupplyMPBefore, "totalSupplyMP");
assertGt(newInitialMP, initialMP, "initialMP");
assertGt(newCurrentMP, currentMP, "currentMP");
assertEq(newBalance, balance, "balance");
}
}

contract LeaveTest is StakeManagerTest {
Expand Down

0 comments on commit c163c88

Please sign in to comment.