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

Introducing the Aggeregate MP Estimation Logic #32

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions contracts/StakeManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ contract StakeManager is Ownable {
uint256 startTime;
uint256 epochReward;
uint256 totalSupply;
uint256 expMPsToBeMinted;
uint256 stakeIn;
}

uint256 public constant EPOCH_SIZE = 1 weeks;
Expand Down Expand Up @@ -152,7 +154,7 @@ contract StakeManager is Ownable {

function calcMaxMultiplierIncrease(uint256 _increasedMultiplier, uint256 _currentMp) private pure returns(uint256 _maxToIncrease) {
uint256 newMp = _increasedMultiplier + _currentMp;
return newMp > MAX_MP ? MAX_MP - newMp : _increasedMultiplier;
return newMp > MAX_MP ? MAX_MP - _currentMp : _increasedMultiplier;
}

function processEpoch() private {
Expand All @@ -164,6 +166,8 @@ contract StakeManager is Ownable {
//create new epoch
currentEpoch++;
epochs[currentEpoch].startTime = block.timestamp;
epochs[currentEpoch].expMPsToBeMinted = stakeSupply*MP_APY/52;
Copy link
Collaborator

@0x-r4bbit 0x-r4bbit Oct 9, 2023

Choose a reason for hiding this comment

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

Where is this 52 coming from? Is this for 52 weeks?
If yes, then let's introduce a constant for that.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

yes, 52 weeks = 1 year

epochs[currentEpoch].stakeIn = stakeSupply;
}
}

Expand All @@ -177,7 +181,8 @@ contract StakeManager is Ownable {
//mint multipliers to that epoch
mintMultiplier(account, iEpoch.startTime + EPOCH_SIZE);
uint256 userSupply = account.balance + account.multiplier;
uint256 userShare = userSupply / iEpoch.totalSupply; //TODO: might lose precision, multiply by 100 and divide back later?
uint256 epochSupply = iEpoch.stakeIn + iEpoch.expMPsToBeMinted;
uint256 userShare = userSupply / epochSupply; //TODO: might lose precision, multiply by 100 and divide back later?
userReward += userShare * iEpoch.epochReward;
}
account.epoch = userEpoch;
Expand All @@ -195,6 +200,7 @@ contract StakeManager is Ownable {
uint256 increasedMultiplier = calcMaxMultiplierIncrease(
account.balance * (MP_APY * deltaTime),
account.multiplier);
iEpoch.expMPsToBeMinted += account.balance * (MP_APY * deltaTime)-increasedMultiplier //TODO:this might need to be returned and done in the loop
Copy link
Collaborator

Choose a reason for hiding this comment

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

iEpoch does not exist inside this function.

Inside processAccount() it's created for every iteration: https://github.com/logos-co/staking/pull/32/files#diff-7c9d8f98d816b0c54f20f2c5790ef649167479fd4f527d3f4bf4b0c6c220f028R180

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yeah, I assumed this would be an issue. I need to think about how to circumvent this.

account.multiplier += increasedMultiplier;
multiplierSupply += increasedMultiplier;
}
Expand Down