mirror of https://github.com/logos-co/staking.git
WIP: more mp estimation debugging
This commit is contained in:
parent
780005d466
commit
14d73c8123
|
@ -128,10 +128,15 @@ contract StakeManager is Ownable {
|
|||
console.log("\tEstimating MPs for epoch...");
|
||||
epochs[currentEpoch].estimatedMP = _getMPToMint(
|
||||
totalSupplyBalance - totalMpMaxBoostLimitBalance,
|
||||
// block.timestamp - epochs[currentEpoch].startTime
|
||||
EPOCH_SIZE
|
||||
);
|
||||
pendingMPToBeMinted += epochs[currentEpoch].estimatedMP;
|
||||
|
||||
// if (pendingMPToBeMinted % 2 != 0) {
|
||||
// pendingMPToBeMinted += 1;
|
||||
// }
|
||||
|
||||
//finalize current epoch
|
||||
epochs[currentEpoch].epochReward = epochReward();
|
||||
epochs[currentEpoch].totalSupply = totalSupply();
|
||||
|
@ -227,6 +232,8 @@ contract StakeManager is Ownable {
|
|||
|
||||
uint256 reducedMP = Math.mulDiv(_amount, account.totalMP, account.balance, Math.Rounding.Up);
|
||||
uint256 reducedInitialMP = Math.mulDiv(_amount, account.bonusMP, account.balance, Math.Rounding.Up);
|
||||
// uint256 reducedMP = Math.mulDiv(_amount, account.totalMP, account.balance);
|
||||
// uint256 reducedInitialMP = Math.mulDiv(_amount, account.bonusMP, account.balance);
|
||||
|
||||
//mp estimation
|
||||
mpMaxBoostLimitEpochBalance[account.mpMaxBoostLimitEpoch] -= _amount; // some staked amount from the past
|
||||
|
@ -424,6 +431,7 @@ contract StakeManager is Ownable {
|
|||
_mintMP(account, iEpoch.startTime + EPOCH_SIZE, iEpoch);
|
||||
uint256 userSupply = account.balance + account.totalMP;
|
||||
uint256 userEpochReward = Math.mulDiv(userSupply, iEpoch.epochReward, iEpoch.totalSupply, Math.Rounding.Up);
|
||||
// uint256 userEpochReward = Math.mulDiv(userSupply, iEpoch.epochReward, iEpoch.totalSupply);
|
||||
|
||||
userReward += userEpochReward;
|
||||
iEpoch.epochReward -= userEpochReward;
|
||||
|
@ -526,7 +534,7 @@ contract StakeManager is Ownable {
|
|||
view
|
||||
returns (uint256 _maxMpToMint)
|
||||
{
|
||||
console.log("\t\t_getMaxMPToMint -> _getMPToMint..");
|
||||
// console.log("\t\t_getMaxMPToMint -> _getMPToMint..");
|
||||
// Maximum multiplier point for given balance
|
||||
_maxMpToMint = _getMPToMint(_balance, MAX_BOOST * YEAR) + _bonusMP;
|
||||
if (_mpToMint + _totalMP > _maxMpToMint) {
|
||||
|
@ -559,6 +567,7 @@ contract StakeManager is Ownable {
|
|||
console.log("\t\tYEAR: ", YEAR);
|
||||
|
||||
uint256 res = Math.mulDiv(_balance, _deltaTime, YEAR, Math.Rounding.Up) * MP_APY;
|
||||
// uint256 res = Math.mulDiv(_balance, _deltaTime, YEAR) * MP_APY;
|
||||
|
||||
console.log("\t\t(_balance * _deltaTime / YEAR) * MP_APY: ", res);
|
||||
return res;
|
||||
|
|
|
@ -639,6 +639,9 @@ contract ExecuteAccountTest is StakeManagerTest {
|
|||
}
|
||||
|
||||
contract UserFlowsTest is StakeManagerTest {
|
||||
|
||||
StakeVault[] private userVaults;
|
||||
|
||||
function test_StakedSupplyShouldIncreaseAndDecreaseAgain() public {
|
||||
uint256 lockTime = 0;
|
||||
uint256 stakeAmount = 100;
|
||||
|
@ -680,6 +683,40 @@ contract UserFlowsTest is StakeManagerTest {
|
|||
assertEq(ERC20(stakeToken).balanceOf(address(userVault)), 0);
|
||||
assertEq(stakeManager.totalSupplyBalance(), 0);
|
||||
}
|
||||
|
||||
// function test_PendingMPToBeMintedCannotBeGreaterThanTotalSupplyMP(uint8 accountNum) public {
|
||||
function test_PendingMPToBeMintedCannotBeGreaterThanTotalSupplyMP(uint8 accountNum) public {
|
||||
uint256 stakeAmount = 10_000_000;
|
||||
|
||||
for (uint256 i = 0; i <= accountNum; i++) {
|
||||
// deal(stakeToken, testUser, stakeAmount);
|
||||
userVaults.push(_createStakingAccount(makeAddr(
|
||||
string(abi.encode(keccak256(abi.encode(accountNum))))),
|
||||
stakeAmount,
|
||||
0
|
||||
));
|
||||
}
|
||||
|
||||
uint256 epochsAmountToReachCap = 1;
|
||||
|
||||
for (uint256 i = 0; i < epochsAmountToReachCap; i++) {
|
||||
vm.warp(stakeManager.epochEnd());
|
||||
stakeManager.executeEpoch();
|
||||
uint256 pendingMPToBeMintedBefore = stakeManager.pendingMPToBeMinted();
|
||||
uint256 totalSupplyMP = stakeManager.totalSupplyMP();
|
||||
for (uint256 j = 0; j < userVaults.length; j++) {
|
||||
(address rewardAddress,,, uint256 totalMPBefore, uint256 lastMintBefore,, uint256 epochBefore,) =
|
||||
stakeManager.accounts(address(userVaults[j]));
|
||||
|
||||
stakeManager.executeAccount(address(userVaults[j]), epochBefore + 1);
|
||||
}
|
||||
uint256 pendingMPToBeMintedAfter = stakeManager.pendingMPToBeMinted();
|
||||
|
||||
assertEq(pendingMPToBeMintedBefore + totalSupplyMP, stakeManager.totalSupplyMP());
|
||||
assertEq(pendingMPToBeMintedAfter, 0);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
contract MigrationStakeManagerTest is StakeManagerTest {
|
||||
|
|
Loading…
Reference in New Issue