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

Update locking formula #375

Merged
merged 14 commits into from
Feb 22, 2024
Merged

Update locking formula #375

merged 14 commits into from
Feb 22, 2024

Conversation

bowd
Copy link
Contributor

@bowd bowd commented Feb 19, 2024

Description

Currently the voting power formula looks like this (slightly simplified):

$$P(t,s,c) = t * (0.2 + 0.8 * c / c_{max} + 0.6 * s / s_{max})$$

We want to bring the system closer to the classical veCurve formula, by changing it to:

$$P(t,s,c) = t * min(s/s_{max} + c/c_{max}, 1)$$

More details can be seen here #373

Since this formula sits in the core of the voting power calculations, reviews should be on a broader level. Please go through code changes, test calculations and more importantly how this may affect the whole locking mechanism.

Known issues:

  • users can lock with a suboptimal schedule if the summed multiplier goes above 1.

Other changes

Updated the tests to use the exact amounts and not approximations
Removed unused imports

Tested

Fixed the tests related to change. Actual calculations are added as comments.
Some extra fuzz tests are WIP and will be added with a separate PR

Related issues

Copy link

openzeppelin-code bot commented Feb 19, 2024

Update locking formula

Generated at commit: 2b142290b076a39be8f9d818a229b9520cb3592c

🚨 Report Summary

Severity Level Results
Contracts Critical
High
Medium
Low
Note
Total
3
3
0
13
38
57
Dependencies Critical
High
Medium
Low
Note
Total
0
0
0
0
0
0

For more details view the full report in OpenZeppelin Code Inspector

@baroooo baroooo self-assigned this Feb 20, 2024
@baroooo baroooo marked this pull request as ready for review February 21, 2024 11:11
Copy link
Contributor

@chapati23 chapati23 left a comment

Choose a reason for hiding this comment

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

great work (esp given deadline pressure!)

  • i took some time to understand the new requirements and read through the rarible docs again as well
  • reviewed the code changes
  • reviewed the tests (although my review here wasn't as deep, so 2nd review should dig a bit deeper here)
  • ran the tests locally

think @bowd should be final reviewer on this

contracts/governance/locking/LockingBase.sol Outdated Show resolved Hide resolved
contracts/governance/locking/LockingBase.sol Outdated Show resolved Hide resolved
contracts/governance/locking/LockingBase.sol Outdated Show resolved Hide resolved
contracts/governance/locking/LockingBase.sol Outdated Show resolved Hide resolved
contracts/governance/locking/LockingBase.sol Outdated Show resolved Hide resolved
Copy link
Contributor

@chapati23 chapati23 left a comment

Choose a reason for hiding this comment

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

🚀

contracts/governance/locking/LockingBase.sol Outdated Show resolved Hide resolved
contracts/governance/locking/LockingBase.sol Outdated Show resolved Hide resolved
contracts/governance/locking/LockingBase.sol Outdated Show resolved Hide resolved
test/governance/Locking/locking.t.sol Outdated Show resolved Hide resolved
@baroooo baroooo merged commit 472a1d9 into develop Feb 22, 2024
6 checks passed
@baroooo baroooo deleted the feat/locking-formula branch February 22, 2024 15:44

uint256 amountMultiplied = uint256(amount) * uint256(multiplier);
lockAmount = uint96(amountMultiplied / (ST_FORMULA_DIVIDER));
lockAmount = uint96(amountMultiplied / (ST_FORMULA_BASIS));
require(lockAmount > 0, "voting power is 0");
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not sure if this require is really needed anymore unless both minCliffPeriod and minSlopePeriod are configured to 0, but it's probably good to have anyway

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Modify locking voting power formula
4 participants