-
Notifications
You must be signed in to change notification settings - Fork 4
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
Refactor Initial Multiplier Logic #52
Conversation
f312393
to
4ae9e9e
Compare
@3esmit I've merged #53 and #59 as discussed offline so you can rebase this PR on top of it (now latest Once done I will review your changes. Let me know if you need any help with this! |
5731477
to
e76b17c
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Very nice changes @3esmit !
As mentioned offline, i'd like to see some tests on this that show MPs are calculated properly.
@mart1n-xyz would you be able to give us some numbers for 2-3 scenarios (with lockup time, without lockup time, different amount of epochs etc) ?
We can then create tests in which we put in these numbers and see if the code behaves as expected.
contracts/StakeManager.sol
Outdated
*/ | ||
function unstake(uint256 _amount) external onlyVault noMigration { | ||
function unstake() external onlyVault noMigration processEpoch { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So we no longer allow for unstaking less than current stake amount?
@mart1n-xyz Double checking: is this desired?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I removed because this function would give too much losses to user. It could be reimplemented if needed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we want to allow partial unstaking (with proportional slashing of MPs).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure, we would have to define how thats calculated.
Currently it would work like that:
initial MP (bonus): reduce on 20% of balance, reduce 20% of initial MP.
current MP: reduce on 20% of balance, reduce 20% of current MP.
This might not be the most precise way to go for it, and we would have to consider if this causes other issues.
Tests to be written:
|
Here's the cases we were simulating. |
if (_time > MAX_LOCKUP_PERIOD) { | ||
revert StakeManager__InvalidLockupPeriod(); | ||
} | ||
Account storage account = accounts[msg.sender]; | ||
processAccount(account, currentEpoch); | ||
if (account.lockUntil + _time < block.timestamp) { | ||
revert StakeManager__InvalidLockTime(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So one thing I've realised, is that I keep confusing lockUntil with locktime.
The former is a threshold, the latter is a period.
If we treat _time
as something that can only be added to the existing lockUntil
, then maybe we can consider renaming lock()
to increaseLockTime()
?
Not something that has to happen in this commit/PR, but maybe something to consider in the future.
I always thought lock()
would allow me to set my lockup time (say, from 2 years, to 4 years)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, that can be renamed like that to avoid confusions on development and audits.
Anyway, the UX would have to solve that for the user, no matter how its named or how the interface behaves.
Thanks for the updates! Let's add some tests related to the multiplier/reward calculation, then I think this is good to go. We can then add all the other tests you've mentioned in your comment in a follow-up PR |
As I am writing tests I am finding other bugs, so I guess this will be a mega PR fixing many bugs. |
@3esmit I think it's fine if these are part of the refactor changes you've made. If not, I think it'd be better if we isolate the changes made in this PR so it closes the 1-2 issues it was supposed to close. Sometimes it can't be avoided, but we should strive for keep PRs as small as possible |
48a2ec7
to
10b3a2f
Compare
Description
Checklist
Ensure you completed all of the steps below before submitting your pull request:
forge snapshot
?pnpm lint
?forge test
?pnpm verify
?