refactor(StakeManager): initialMP -> bonusMP, currentMP -> totalMP

After discussing this offline, we've decided that the naming of these
properties was misleading. This commit performs the following changes:

- `account.initialMP` becomes `account.bonusMP`
- `account.currentMP` becomes `account.totalMP`

Rationale:

`initialMP` indicates that this is an immutable field which is not the
case as in scenarios where accounts increase the `lock()` time, they'll
also increase their bonus multiplier (`initialMP`).

`currentMP` was misleading in combination with `initialMP`. Really what
it reflects is the total multiplier points of an account **including**
its bonus multiplier points.
This commit is contained in:
r4bbit 2024-06-25 12:48:23 +02:00 committed by Ricardo Guilherme Schmidt
parent d18df07b28
commit 4a04b46e14
3 changed files with 107 additions and 111 deletions

View File

@ -23,18 +23,18 @@ function getAccountBalance(address addr) returns uint256 {
return balance;
}
function getAccountInitialMultiplierPoints(address addr) returns uint256 {
uint256 initialMP;
_, _, initialMP, _, _, _, _ = accounts(addr);
function getAccountBonusMultiplierPoints(address addr) returns uint256 {
uint256 bonusMP;
_, _, bonusMP, _, _, _, _ = accounts(addr);
return initialMP;
return bonusMP;
}
function getAccountCurrentMultiplierPoints(address addr) returns uint256 {
uint256 currentMP;
_, _, _, currentMP, _, _, _ = accounts(addr);
uint256 totalMP;
_, _, _, totalMP, _, _, _ = accounts(addr);
return currentMP;
return totalMP;
}
function getAccountLockUntil(address addr) returns uint256 {
@ -91,7 +91,7 @@ hook Sstore accounts[KEY address addr].balance uint256 newValue (uint256 oldValu
sumOfBalances = sumOfBalances - oldValue + newValue;
}
hook Sstore accounts[KEY address addr].currentMP uint256 newValue (uint256 oldValue) {
hook Sstore accounts[KEY address addr].totalMP uint256 newValue (uint256 oldValue) {
sumOfMultipliers = sumOfMultipliers - oldValue + newValue;
}
@ -121,19 +121,19 @@ invariant highEpochsAreNull(uint256 epochNumber)
}
invariant InitialMPIsNeverSmallerThanBalance(address addr)
to_mathint(getAccountInitialMultiplierPoints(addr)) >= to_mathint(getAccountBalance(addr))
to_mathint(getAccountBonusMultiplierPoints(addr)) >= to_mathint(getAccountBalance(addr))
filtered {
f -> f.selector != sig:migrateFrom(address,bool,StakeManager.Account).selector
}
invariant CurrentMPIsNeverSmallerThanInitialMP(address addr)
to_mathint(getAccountCurrentMultiplierPoints(addr)) >= to_mathint(getAccountInitialMultiplierPoints(addr))
to_mathint(getAccountCurrentMultiplierPoints(addr)) >= to_mathint(getAccountBonusMultiplierPoints(addr))
filtered {
f -> f.selector != sig:migrateFrom(address,bool,StakeManager.Account).selector
}
invariant MPcantBeGreaterThanMaxMP(address addr)
to_mathint(getAccountCurrentMultiplierPoints(addr)) <= (getAccountBalance(addr) * 8) + getAccountInitialMultiplierPoints(addr)
to_mathint(getAccountCurrentMultiplierPoints(addr)) <= (getAccountBalance(addr) * 8) + getAccountBonusMultiplierPoints(addr)
filtered {
f -> f.selector != sig:migrateFrom(address,bool,StakeManager.Account).selector
}
@ -164,9 +164,9 @@ rule stakingMintsMultiplierPoints1To1Ratio {
require getAccountLockUntil(e.msg.sender) <= e.block.timestamp;
multiplierPointsBefore = getAccountInitialMultiplierPoints(e.msg.sender);
multiplierPointsBefore = getAccountBonusMultiplierPoints(e.msg.sender);
stake(e, amount, lockupTime);
multiplierPointsAfter = getAccountInitialMultiplierPoints(e.msg.sender);
multiplierPointsAfter = getAccountBonusMultiplierPoints(e.msg.sender);
assert lockupTime == 0 => to_mathint(multiplierPointsAfter) == multiplierPointsBefore + amount;
assert to_mathint(multiplierPointsAfter) >= multiplierPointsBefore + amount;
@ -184,10 +184,10 @@ rule stakingGreaterLockupTimeMeansGreaterMPs {
storage initalStorage = lastStorage;
stake(e, amount, lockupTime1);
multiplierPointsAfter1 = getAccountInitialMultiplierPoints(e.msg.sender);
multiplierPointsAfter1 = getAccountBonusMultiplierPoints(e.msg.sender);
stake(e, amount, lockupTime2) at initalStorage;
multiplierPointsAfter2 = getAccountInitialMultiplierPoints(e.msg.sender);
multiplierPointsAfter2 = getAccountBonusMultiplierPoints(e.msg.sender);
assert lockupTime1 >= lockupTime2 => to_mathint(multiplierPointsAfter1) >= to_mathint(multiplierPointsAfter2);
satisfy to_mathint(multiplierPointsAfter1) > to_mathint(multiplierPointsAfter2);

View File

@ -24,8 +24,8 @@ contract StakeManager is Ownable {
struct Account {
address rewardAddress;
uint256 balance;
uint256 initialMP;
uint256 currentMP;
uint256 bonusMP;
uint256 totalMP;
uint256 lastMint;
uint256 lockUntil;
uint256 epoch;
@ -157,7 +157,7 @@ contract StakeManager is Ownable {
revert StakeManager__InvalidLockTime();
}
}
_mintInitialMP(account, deltaTime, _amount);
_mintBonusMP(account, deltaTime, _amount);
//update storage
totalSupplyBalance += _amount;
@ -184,13 +184,13 @@ contract StakeManager is Ownable {
}
_processAccount(account, currentEpoch);
uint256 reducedMP = Math.mulDiv(_amount, account.currentMP, account.balance);
uint256 reducedInitialMP = Math.mulDiv(_amount, account.initialMP, account.balance);
uint256 reducedMP = Math.mulDiv(_amount, account.totalMP, account.balance);
uint256 reducedInitialMP = Math.mulDiv(_amount, account.bonusMP, account.balance);
//update storage
account.balance -= _amount;
account.initialMP -= reducedInitialMP;
account.currentMP -= reducedMP;
account.bonusMP -= reducedInitialMP;
account.totalMP -= reducedMP;
totalSupplyBalance -= _amount;
totalSupplyMP -= reducedMP;
}
@ -222,7 +222,7 @@ contract StakeManager is Ownable {
if (deltaTime < MIN_LOCKUP_PERIOD || deltaTime > MAX_LOCKUP_PERIOD) {
revert StakeManager__InvalidLockTime();
}
_mintInitialMP(account, _timeToIncrease, 0);
_mintBonusMP(account, _timeToIncrease, 0);
//update account storage
account.lockUntil = lockUntil;
}
@ -322,7 +322,7 @@ contract StakeManager is Ownable {
{
_processAccount(accounts[msg.sender], currentEpoch);
Account memory account = accounts[msg.sender];
totalSupplyMP -= account.currentMP;
totalSupplyMP -= account.totalMP;
totalSupplyBalance -= account.balance;
delete accounts[msg.sender];
migration.migrateFrom(msg.sender, _acceptMigration, account);
@ -340,7 +340,7 @@ contract StakeManager is Ownable {
if (_acceptMigration) {
accounts[_vault] = _account;
} else {
totalSupplyMP -= _account.currentMP;
totalSupplyMP -= _account.totalMP;
totalSupplyBalance -= _account.balance;
}
}
@ -365,11 +365,11 @@ contract StakeManager is Ownable {
}
uint256 userReward;
uint256 userEpoch = account.epoch;
uint256 mpDifference = account.currentMP;
uint256 mpDifference = account.totalMP;
for (Epoch storage iEpoch = epochs[userEpoch]; userEpoch < _limitEpoch; userEpoch++) {
//mint multiplier points to that epoch
_mintMP(account, iEpoch.startTime + EPOCH_SIZE, iEpoch);
uint256 userSupply = account.balance + account.currentMP;
uint256 userSupply = account.balance + account.totalMP;
uint256 userEpochReward = Math.mulDiv(userSupply, iEpoch.epochReward, iEpoch.totalSupply);
userReward += userEpochReward;
@ -381,7 +381,7 @@ contract StakeManager is Ownable {
pendingReward -= userReward;
stakedToken.transfer(account.rewardAddress, userReward);
}
mpDifference = account.currentMP - mpDifference;
mpDifference = account.totalMP - mpDifference;
if (address(migration) != address(0)) {
migration.increaseTotalMP(mpDifference);
} else if (userEpoch == currentEpoch) {
@ -390,14 +390,14 @@ contract StakeManager is Ownable {
}
/**
* @notice Mint initial multiplier points for given staking amount and time
* @notice Mint bonus multiplier points for given staking amount and time
* @dev if amount is greater 0, it increases difference of amount for current remaining lock time
* @dev if increased lock time, increases difference of total new balance for increased lock time
* @param account Account to mint multiplier points
* @param increasedLockTime increased lock time
* @param amount amount to stake
*/
function _mintInitialMP(Account storage account, uint256 increasedLockTime, uint256 amount) private {
function _mintBonusMP(Account storage account, uint256 increasedLockTime, uint256 amount) private {
uint256 mpToMint;
if (amount > 0) {
mpToMint += amount; //initial multiplier points
@ -413,8 +413,8 @@ contract StakeManager is Ownable {
}
//update storage
totalSupplyMP += mpToMint;
account.initialMP += mpToMint;
account.currentMP += mpToMint;
account.bonusMP += mpToMint;
account.totalMP += mpToMint;
account.lastMint = block.timestamp;
}
@ -428,13 +428,13 @@ contract StakeManager is Ownable {
uint256 increasedMP = _getMaxMPToMint( //check for MAX_BOOST
_getMPToMint(account.balance, processTime - account.lastMint),
account.balance,
account.initialMP,
account.currentMP
account.bonusMP,
account.totalMP
);
//update storage
account.lastMint = processTime;
account.currentMP += increasedMP;
account.totalMP += increasedMP;
totalSupplyMP += increasedMP;
epoch.totalSupply += increasedMP;
}
@ -443,25 +443,25 @@ contract StakeManager is Ownable {
* @notice Calculates maximum multiplier point increase for given balance
* @param _mpToMint tested value
* @param _balance balance of account
* @param _currentMP current multiplier point of the account
* @param _initialMP initial multiplier point of the account
* @param _totalMP total multiplier point of the account
* @param _bonusMP bonus multiplier point of the account
* @return _maxToIncrease maximum multiplier point increase
*/
function _getMaxMPToMint(
uint256 _mpToMint,
uint256 _balance,
uint256 _initialMP,
uint256 _currentMP
uint256 _bonusMP,
uint256 _totalMP
)
private
pure
returns (uint256 _maxToIncrease)
{
// Maximum multiplier point for given balance
_maxToIncrease = _getMPToMint(_balance, MAX_BOOST * YEAR) + _initialMP;
if (_mpToMint + _currentMP > _maxToIncrease) {
_maxToIncrease = _getMPToMint(_balance, MAX_BOOST * YEAR) + _bonusMP;
if (_mpToMint + _totalMP > _maxToIncrease) {
//reached cap when increasing MP
return _maxToIncrease - _currentMP; //how much left to reach cap
return _maxToIncrease - _totalMP; //how much left to reach cap
} else {
//not reached capw hen increasing MP
return _mpToMint; //just return tested value

View File

@ -108,16 +108,16 @@ contract StakeTest is StakeManagerTest {
uint256 stakeAmount = 100;
StakeVault userVault = _createStakingAccount(testUser, stakeAmount, 0, stakeAmount * 10);
(,, uint256 currentMP,,,,) = stakeManager.accounts(address(userVault));
(,, uint256 totalMP,,,,) = stakeManager.accounts(address(userVault));
assertEq(stakeManager.totalSupplyMP(), stakeAmount, "total multiplier point supply");
assertEq(currentMP, stakeAmount, "user multiplier points");
assertEq(totalMP, stakeAmount, "user multiplier points");
vm.prank(testUser);
userVault.unstake(stakeAmount);
(,,, currentMP,,,) = stakeManager.accounts(address(userVault));
(,,, totalMP,,,) = stakeManager.accounts(address(userVault));
assertEq(stakeManager.totalSupplyMP(), 0, "totalSupplyMP burned after unstaking");
assertEq(currentMP, 0, "userMP burned after unstaking");
assertEq(totalMP, 0, "userMP burned after unstaking");
}
function test_restakeOnLocked() public {
@ -131,18 +131,18 @@ contract StakeTest is StakeManagerTest {
vm.prank(testUser);
userVault.stake(stakeAmount2, 0);
(, uint256 balance,, uint256 currentMP,,,) = stakeManager.accounts(address(userVault));
(, uint256 balance,, uint256 totalMP,,,) = stakeManager.accounts(address(userVault));
assertEq(balance, stakeAmount + stakeAmount2, "account balance");
assertGt(currentMP, stakeAmount + stakeAmount2, "account MP");
assertGt(totalMP, stakeAmount + stakeAmount2, "account MP");
vm.warp(stakeManager.epochEnd());
vm.prank(testUser);
userVault.stake(stakeAmount3, 0);
(, balance,, currentMP,,,) = stakeManager.accounts(address(userVault));
(, balance,, totalMP,,,) = stakeManager.accounts(address(userVault));
assertEq(balance, stakeAmount + stakeAmount2 + stakeAmount3, "account balance 2");
assertGt(currentMP, stakeAmount + stakeAmount2 + stakeAmount3, "account MP 2");
assertGt(totalMP, stakeAmount + stakeAmount2 + stakeAmount3, "account MP 2");
}
function test_restakeJustStake() public {
@ -158,12 +158,12 @@ contract StakeTest is StakeManagerTest {
vm.prank(testUser2);
userVault2.stake(stakeAmount2, 0);
(, uint256 balance,, uint256 currentMP,,,) = stakeManager.accounts(address(userVault));
(, uint256 balance,, uint256 totalMP,,,) = stakeManager.accounts(address(userVault));
assertEq(balance, stakeAmount + stakeAmount2, "account balance");
assertEq(currentMP, stakeAmount + stakeAmount2, "account MP");
(, balance,, currentMP,,,) = stakeManager.accounts(address(userVault2));
assertEq(totalMP, stakeAmount + stakeAmount2, "account MP");
(, balance,, totalMP,,,) = stakeManager.accounts(address(userVault2));
assertEq(balance, stakeAmount + stakeAmount2, "account 2 balance");
assertGt(currentMP, stakeAmount + stakeAmount2, "account 2 MP");
assertGt(totalMP, stakeAmount + stakeAmount2, "account 2 MP");
vm.warp(stakeManager.epochEnd());
@ -172,12 +172,12 @@ contract StakeTest is StakeManagerTest {
vm.prank(testUser2);
userVault2.stake(stakeAmount2, 0);
(, balance,, currentMP,,,) = stakeManager.accounts(address(userVault));
(, balance,, totalMP,,,) = stakeManager.accounts(address(userVault));
assertEq(balance, stakeAmount + stakeAmount2 + stakeAmount2, "account balance 2");
assertGt(currentMP, stakeAmount + stakeAmount2 + stakeAmount2, "account MP 2");
(, balance,, currentMP,,,) = stakeManager.accounts(address(userVault2));
assertGt(totalMP, stakeAmount + stakeAmount2 + stakeAmount2, "account MP 2");
(, balance,, totalMP,,,) = stakeManager.accounts(address(userVault2));
assertEq(balance, stakeAmount + stakeAmount2 + stakeAmount2, "account 2 balance 2");
assertGt(currentMP, stakeAmount + stakeAmount2 + stakeAmount2, "account 2 MP 2");
assertGt(totalMP, stakeAmount + stakeAmount2 + stakeAmount2, "account 2 MP 2");
}
function test_restakeJustLock() public {
@ -191,12 +191,12 @@ contract StakeTest is StakeManagerTest {
vm.prank(testUser2);
userVault2.stake(0, lockToIncrease);
(, uint256 balance,, uint256 currentMP,,,) = stakeManager.accounts(address(userVault));
(, uint256 balance,, uint256 totalMP,,,) = stakeManager.accounts(address(userVault));
assertEq(balance, stakeAmount, "account balance");
assertGt(currentMP, stakeAmount, "account MP");
(, balance,, currentMP,,,) = stakeManager.accounts(address(userVault2));
assertGt(totalMP, stakeAmount, "account MP");
(, balance,, totalMP,,,) = stakeManager.accounts(address(userVault2));
assertEq(balance, stakeAmount, "account 2 balance");
assertGt(currentMP, stakeAmount, "account 2 MP");
assertGt(totalMP, stakeAmount, "account 2 MP");
vm.warp(stakeManager.epochEnd());
@ -205,12 +205,12 @@ contract StakeTest is StakeManagerTest {
vm.prank(testUser2);
userVault2.stake(0, lockToIncrease);
(, balance,, currentMP,,,) = stakeManager.accounts(address(userVault));
(, balance,, totalMP,,,) = stakeManager.accounts(address(userVault));
assertEq(balance, stakeAmount, "account balance 2");
assertGt(currentMP, stakeAmount, "account MP 2");
(, balance,, currentMP,,,) = stakeManager.accounts(address(userVault2));
assertGt(totalMP, stakeAmount, "account MP 2");
(, balance,, totalMP,,,) = stakeManager.accounts(address(userVault2));
assertEq(balance, stakeAmount, "account 2 balance 2");
assertGt(currentMP, stakeAmount, "account 2 MP 2");
assertGt(totalMP, stakeAmount, "account 2 MP 2");
}
function test_restakeStakeAndLock() public {
@ -226,12 +226,12 @@ contract StakeTest is StakeManagerTest {
vm.prank(testUser2);
userVault2.stake(stakeAmount2, lockToIncrease);
(, uint256 balance,, uint256 currentMP,,,) = stakeManager.accounts(address(userVault));
(, uint256 balance,, uint256 totalMP,,,) = stakeManager.accounts(address(userVault));
assertEq(balance, stakeAmount + stakeAmount2, "account balance");
assertGt(currentMP, stakeAmount + stakeAmount2, "account MP");
(, balance,, currentMP,,,) = stakeManager.accounts(address(userVault2));
assertGt(totalMP, stakeAmount + stakeAmount2, "account MP");
(, balance,, totalMP,,,) = stakeManager.accounts(address(userVault2));
assertEq(balance, stakeAmount + stakeAmount2, "account 2 balance");
assertGt(currentMP, stakeAmount + stakeAmount2, "account 2 MP");
assertGt(totalMP, stakeAmount + stakeAmount2, "account 2 MP");
vm.warp(stakeManager.epochEnd());
@ -240,12 +240,12 @@ contract StakeTest is StakeManagerTest {
vm.prank(testUser2);
userVault2.stake(stakeAmount2, lockToIncrease);
(, balance,, currentMP,,,) = stakeManager.accounts(address(userVault));
(, balance,, totalMP,,,) = stakeManager.accounts(address(userVault));
assertEq(balance, stakeAmount + stakeAmount2 + stakeAmount2, "account balance 2");
assertGt(currentMP, stakeAmount + stakeAmount2 + stakeAmount2, "account MP 2");
(, balance,, currentMP,,,) = stakeManager.accounts(address(userVault2));
assertGt(totalMP, stakeAmount + stakeAmount2 + stakeAmount2, "account MP 2");
(, balance,, totalMP,,,) = stakeManager.accounts(address(userVault2));
assertEq(balance, stakeAmount + stakeAmount2 + stakeAmount2, "account 2 balance 2");
assertGt(currentMP, stakeAmount + stakeAmount2 + stakeAmount2, "account 2 MP 2");
assertGt(totalMP, stakeAmount + stakeAmount2 + stakeAmount2, "account 2 MP 2");
}
}
@ -314,7 +314,7 @@ contract UnstakeTest is StakeManagerTest {
vm.warp(stakeManager.epochEnd());
stakeManager.executeAccount(address(userVault), i + 1);
}
(, uint256 balanceBefore, uint256 initialMPBefore, uint256 currentMPBefore,,,) =
(, uint256 balanceBefore, uint256 bonusMPBefore, uint256 totalMPBefore,,,) =
stakeManager.accounts(address(userVault));
uint256 totalSupplyMPBefore = stakeManager.totalSupplyMP();
uint256 unstakeAmount = stakeAmount * percentToBurn / 100;
@ -322,7 +322,7 @@ contract UnstakeTest is StakeManagerTest {
assertEq(ERC20(stakeToken).balanceOf(testUser), 0);
userVault.unstake(unstakeAmount);
(, uint256 balanceAfter, uint256 initialMPAfter, uint256 currentMPAfter,,,) =
(, uint256 balanceAfter, uint256 bonusMPAfter, uint256 totalMPAfter,,,) =
stakeManager.accounts(address(userVault));
uint256 totalSupplyMPAfter = stakeManager.totalSupplyMP();
@ -330,15 +330,15 @@ contract UnstakeTest is StakeManagerTest {
console.log("totalSupplyMPAfter", totalSupplyMPAfter);
console.log("balanceBefore", balanceBefore);
console.log("balanceAfter", balanceAfter);
console.log("initialMPBefore", initialMPBefore);
console.log("initialMPAfter", initialMPAfter);
console.log("currentMPBefore", currentMPBefore);
console.log("currentMPAfter", currentMPAfter);
console.log("bonusMPBefore", bonusMPBefore);
console.log("bonusMPAfter", bonusMPAfter);
console.log("totalMPBefore", totalMPBefore);
console.log("totalMPAfter", totalMPAfter);
assertEq(balanceAfter, balanceBefore - (balanceBefore * percentToBurn / 100));
assertEq(initialMPAfter, initialMPBefore - (initialMPBefore * percentToBurn / 100));
assertEq(currentMPAfter, currentMPBefore - (currentMPBefore * percentToBurn / 100));
assertEq(totalSupplyMPAfter, totalSupplyMPBefore - (currentMPBefore * percentToBurn / 100));
assertEq(bonusMPAfter, bonusMPBefore - (bonusMPBefore * percentToBurn / 100));
assertEq(totalMPAfter, totalMPBefore - (totalMPBefore * percentToBurn / 100));
assertEq(totalSupplyMPAfter, totalSupplyMPBefore - (totalMPBefore * percentToBurn / 100));
assertEq(ERC20(stakeToken).balanceOf(testUser), unstakeAmount);
}
@ -364,11 +364,11 @@ contract LockTest is StakeManagerTest {
vm.startPrank(testUser);
userVault.lock(lockTime);
(, uint256 balance, uint256 initialMP, uint256 currentMP,,,) = stakeManager.accounts(address(userVault));
(, uint256 balance, uint256 bonusMP, uint256 totalMP,,,) = stakeManager.accounts(address(userVault));
console.log("balance", balance);
console.log("initialMP", initialMP);
console.log("currentMP", currentMP);
console.log("bonusMP", bonusMP);
console.log("totalMP", totalMP);
}
function test_RevertWhen_InvalidNewLockupPeriod() public {
@ -386,12 +386,12 @@ contract LockTest is StakeManagerTest {
vm.warp(block.timestamp + stakeManager.MIN_LOCKUP_PERIOD() - 1);
stakeManager.executeAccount(address(userVault), 1);
(, uint256 balance, uint256 initialMP, uint256 currentMP,, uint256 lockUntil,) =
(, uint256 balance, uint256 bonusMP, uint256 totalMP,, uint256 lockUntil,) =
stakeManager.accounts(address(userVault));
vm.startPrank(testUser);
userVault.lock(minLockup - 1);
(, balance, initialMP, currentMP,, lockUntil,) = stakeManager.accounts(address(userVault));
(, balance, bonusMP, totalMP,, lockUntil,) = stakeManager.accounts(address(userVault));
assertEq(lockUntil, block.timestamp + minLockup);
@ -413,22 +413,21 @@ contract LockTest is StakeManagerTest {
userVault.lock(minLockup - 1);
}
function test_ShouldIncreaseInitialMP() public {
function test_ShouldIncreaseBonusMP() 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 balance, uint256 bonusMP, uint256 totalMP,,,) = 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 newBalance, uint256 newBonusMP, uint256 newCurrentMP,,,) = stakeManager.accounts(address(userVault));
uint256 totalSupplyMPAfter = stakeManager.totalSupplyMP();
assertGt(totalSupplyMPAfter, totalSupplyMPBefore, "totalSupplyMP");
assertGt(newInitialMP, initialMP, "initialMP");
assertGt(newCurrentMP, currentMP, "currentMP");
assertGt(newBonusMP, bonusMP, "bonusMP");
assertGt(newCurrentMP, totalMP, "totalMP");
assertEq(newBalance, balance, "balance");
}
}
@ -540,22 +539,21 @@ contract ExecuteAccountTest is StakeManagerTest {
console.log("# PND_REWARDS", stakeManager.pendingReward());
for (uint256 j = 0; j < userVaults.length; j++) {
(address rewardAddress,,, uint256 currentMPBefore, uint256 lastMintBefore,, uint256 epochBefore) =
(address rewardAddress,,, uint256 totalMPBefore, uint256 lastMintBefore,, uint256 epochBefore) =
stakeManager.accounts(address(userVaults[j]));
uint256 rewardsBefore = ERC20(stakeToken).balanceOf(rewardAddress);
console.log("-Vault number", j);
console.log("--=====BEFORE=====");
console.log("---### currentMP :", currentMPBefore);
console.log("---### totalMP :", totalMPBefore);
console.log("---#### lastMint :", lastMintBefore);
console.log("---## user_epoch :", epochBefore);
console.log("---##### rewards :", rewardsBefore);
console.log("--=====AFTER======");
stakeManager.executeAccount(address(userVaults[j]), epochBefore + 1);
(,,, uint256 currentMP, uint256 lastMint,, uint256 epoch) =
stakeManager.accounts(address(userVaults[j]));
(,,, uint256 totalMP, uint256 lastMint,, uint256 epoch) = stakeManager.accounts(address(userVaults[j]));
uint256 rewards = ERC20(stakeToken).balanceOf(rewardAddress);
console.log("---### deltaTime :", lastMint - lastMintBefore);
console.log("---### currentMP :", currentMP);
console.log("---### totalMP :", totalMP);
console.log("---#### lastMint :", lastMint);
console.log("---## user_epoch :", epoch);
console.log("---##### rewards :", rewards);
@ -564,11 +562,11 @@ contract ExecuteAccountTest is StakeManagerTest {
console.log("--# PND_REWARDS", stakeManager.pendingReward());
assertEq(lastMint, lastMintBefore + stakeManager.EPOCH_SIZE(), "must increaase lastMint");
assertEq(epoch, epochBefore + 1, "must increase epoch");
assertGt(currentMP, currentMPBefore, "must increase MPs");
assertGt(totalMP, totalMPBefore, "must increase MPs");
assertGt(rewards, rewardsBefore, "must increase rewards");
lastMintBefore = lastMint;
epochBefore = epoch;
currentMPBefore = currentMP;
totalMPBefore = totalMP;
}
}
}
@ -586,21 +584,20 @@ contract ExecuteAccountTest is StakeManagerTest {
vm.warp(stakeManager.epochEnd());
stakeManager.executeEpoch();
for (uint256 j = 0; j < userVaults.length; j++) {
(address rewardAddress,,, uint256 currentMPBefore, uint256 lastMintBefore,, uint256 epochBefore) =
(address rewardAddress,,, uint256 totalMPBefore, uint256 lastMintBefore,, uint256 epochBefore) =
stakeManager.accounts(address(userVaults[j]));
uint256 rewardsBefore = ERC20(stakeToken).balanceOf(rewardAddress);
stakeManager.executeAccount(address(userVaults[j]), epochBefore + 1);
(,,, uint256 currentMP, uint256 lastMint,, uint256 epoch) =
stakeManager.accounts(address(userVaults[j]));
(,,, uint256 totalMP, uint256 lastMint,, uint256 epoch) = stakeManager.accounts(address(userVaults[j]));
uint256 rewards = ERC20(stakeToken).balanceOf(rewardAddress);
assertEq(lastMint, lastMintBefore + stakeManager.EPOCH_SIZE(), "must increaase lastMint");
assertEq(epoch, epochBefore + 1, "must increase epoch");
assertGt(currentMP, currentMPBefore, "must increase MPs");
assertGt(totalMP, totalMPBefore, "must increase MPs");
assertGt(rewards, rewardsBefore, "must increase rewards");
lastMintBefore = lastMint;
epochBefore = epoch;
currentMPBefore = currentMP;
totalMPBefore = totalMP;
}
}
@ -609,21 +606,20 @@ contract ExecuteAccountTest is StakeManagerTest {
vm.warp(stakeManager.epochEnd());
stakeManager.executeEpoch();
for (uint256 j = 0; j < userVaults.length; j++) {
(address rewardAddress,,, uint256 currentMPBefore, uint256 lastMintBefore,, uint256 epochBefore) =
(address rewardAddress,,, uint256 totalMPBefore, uint256 lastMintBefore,, uint256 epochBefore) =
stakeManager.accounts(address(userVaults[j]));
uint256 rewardsBefore = ERC20(stakeToken).balanceOf(rewardAddress);
stakeManager.executeAccount(address(userVaults[j]), epochBefore + 1);
(,,, uint256 currentMP, uint256 lastMint,, uint256 epoch) =
stakeManager.accounts(address(userVaults[j]));
(,,, uint256 totalMP, uint256 lastMint,, uint256 epoch) = stakeManager.accounts(address(userVaults[j]));
uint256 rewards = ERC20(stakeToken).balanceOf(rewardAddress);
assertEq(lastMint, lastMintBefore + stakeManager.EPOCH_SIZE(), "must increaase lastMint");
assertEq(epoch, epochBefore + 1, "must increase epoch");
assertEq(currentMP, currentMPBefore, "must NOT increase MPs");
assertEq(totalMP, totalMPBefore, "must NOT increase MPs");
assertGt(rewards, rewardsBefore, "must increase rewards");
lastMintBefore = lastMint;
epochBefore = epoch;
currentMPBefore = currentMP;
totalMPBefore = totalMP;
}
}
}