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

Math Refactor #740

Merged
merged 7 commits into from
Jan 19, 2022
Merged

Math Refactor #740

merged 7 commits into from
Jan 19, 2022

Conversation

mconcat
Copy link
Collaborator

@mconcat mconcat commented Jan 8, 2022

Swap math functions refactoring PR.
This PR does not (and should not) contain any mathematical level change(except for adding several Neg()s), only code level changes.

Description


For contributor use:

  • Targeted PR against correct branch (see CONTRIBUTING.md)
  • Updated relevant documentation (docs/) or specification (x/<module>/spec/)
  • Added a relevant changelog entry to the Unreleased section in CHANGELOG.md
  • Re-reviewed Files changed in the Github PR explorer

@codecov-commenter
Copy link

codecov-commenter commented Jan 8, 2022

Codecov Report

Merging #740 (dc1ebc0) into main (bc65a83) will increase coverage by 1.27%.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##             main     #740      +/-   ##
==========================================
+ Coverage   18.73%   20.00%   +1.27%     
==========================================
  Files         172      189      +17     
  Lines       23908    24559     +651     
==========================================
+ Hits         4478     4914     +436     
- Misses      18655    18790     +135     
- Partials      775      855      +80     
Impacted Files Coverage Δ
x/gamm/keeper/math.go 100.00% <100.00%> (ø)
x/gamm/keeper/pool_service.go 62.35% <100.00%> (ø)
x/gamm/types/key.go 7.69% <0.00%> (-25.65%) ⬇️
x/lockup/genesis.go 50.00% <0.00%> (-5.56%) ⬇️
x/lockup/keeper/utils.go 95.55% <0.00%> (-4.45%) ⬇️
x/claim/keeper/hooks.go 26.92% <0.00%> (-2.25%) ⬇️
x/txfees/keeper/feedecorator.go 72.09% <0.00%> (-1.60%) ⬇️
x/incentives/keeper/keeper.go 79.16% <0.00%> (-0.84%) ⬇️
x/lockup/keeper/lock.go 60.54% <0.00%> (-0.73%) ⬇️
x/lockup/abci.go 0.00% <0.00%> (ø)
... and 21 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update bc65a83...dc1ebc0. Read the comment docs.

x/gamm/keeper/math.go Outdated Show resolved Hide resolved
@mconcat mconcat marked this pull request as ready for review January 11, 2022 05:01
x/gamm/keeper/math.go Outdated Show resolved Hide resolved
x/gamm/keeper/math.go Outdated Show resolved Hide resolved
x/gamm/keeper/math.go Outdated Show resolved Hide resolved
x/gamm/keeper/math.go Outdated Show resolved Hide resolved
x/gamm/keeper/math.go Outdated Show resolved Hide resolved
@mconcat
Copy link
Collaborator Author

mconcat commented Jan 19, 2022

  • All comments are addressed.
  • poolDiffGivenTokenDiff and tokenDifGivenPoolDiff has been removed and replaced by solveConstantFunctionInvariant.
  • Randomized math invariant test added.

@@ -124,7 +124,7 @@ func (suite *KeeperTestSuite) TestCleanupPoolRandomized() {
for _, coin := range coinOf[acc.String()] {
amt := suite.app.BankKeeper.GetBalance(suite.ctx, acc, coin.Denom)
// the refund could have rounding error
suite.True(amt.Amount.Equal(coin.Amount) || amt.Amount.Equal(coin.Amount.SubRaw(1)),
suite.True(amt.Amount.Sub(coin.Amount).Abs().LTE(sdk.NewInt(2)),
Copy link
Member

Choose a reason for hiding this comment

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

Was there an error here, or just pro-actively changing it?

Copy link
Member

@ValarDragon ValarDragon left a comment

Choose a reason for hiding this comment

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

LGTM! Thanks for removing duplicate code on the tests as well! Its nice how much simpler this all is

I think we should get this into the v6.x line, just to ensure that no math broke (I don't think it should have)

@ValarDragon ValarDragon merged commit a1488e7 into main Jan 19, 2022
@ValarDragon ValarDragon deleted the mconcat/curve-math-refactor branch January 19, 2022 16:15
ValarDragon added a commit that referenced this pull request Jan 19, 2022
* refactor math

* factor out normalizedWeight

* unify into SolveConstantFunctionInvariant

* test in progress

* add randomized test

* Update x/gamm/keeper/math.go

Co-authored-by: Dev Ojha <[email protected]>

Co-authored-by: Dev Ojha <[email protected]>
@ValarDragon
Copy link
Member

This is on v6.x now, and syncing just fine!

@github-actions github-actions bot mentioned this pull request Mar 1, 2024
@github-actions github-actions bot mentioned this pull request Mar 15, 2024
@github-actions github-actions bot mentioned this pull request Apr 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

3 participants