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

Speedup quo round up, start CL speedup integration #8014

Merged
merged 30 commits into from
Apr 12, 2024
Merged

Conversation

ValarDragon
Copy link
Member

@ValarDragon ValarDragon commented Apr 11, 2024

Significantly speedup quo round up by removing a second quo call, and lowering the big int size throughout by 2 words.

Also uses code reuse for panic checks as requested by @czarcas7ic

Summary by CodeRabbit

  • New Features

    • Introduced enhanced rounding logic for division operations in financial calculations.
    • Added a new function to support multiplication of decimal values, improving precision in financial computations.
  • Bug Fixes

    • Corrected rounding issues in division operations to accurately handle remainders.
    • Updated liquidity and price calculation methods to ensure accurate financial reporting in pools.

Copy link
Contributor

coderabbitai bot commented Apr 11, 2024

Walkthrough

The update enhances mathematical operations in BigDec by refining rounding logic and adding overflow checks. It also introduces a new function for creating BigDec from product operations. In the Pool struct, the calculation method for actual amounts has been revised to improve accuracy based on liquidity and prices.

Changes

File Path Change Summary
osmomath/decimal.go Revised rounding in QuoRoundUp functions, added overflow check, and new function for BigDec creation.
x/concentrated-liquidity/model/... Updated CalcActualAmounts method to refine actual amount calculations based on liquidity and prices.

Possibly related issues

🐰✨📜✨🐰
A rabbit hopped through the code,
Twisting logic where numbers flowed.
With a flick and a hop, a new path it paved,
Ensuring every decimal perfectly behaved.
Celebrate the math, so deftly saved!
🐰✨📜✨🐰


Recent Review Details

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between aabae07 and a33352f.
Files selected for processing (2)
  • osmomath/decimal.go (14 hunks)
  • x/concentrated-liquidity/model/pool.go (2 hunks)
Files skipped from review as they are similar to previous changes (2)
  • osmomath/decimal.go
  • x/concentrated-liquidity/model/pool.go

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share
Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (invoked as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger a review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

Important Notice

This PR modifies an in-repo Go module. It is one of:

  • osmomath
  • osmoutils
  • x/ibc-hooks
  • x/epochs

The dependent Go modules, especially the root one, will have to be
updated to reflect the changes. Failing to do so might cause e2e to fail.

Please follow the instructions below:

  1. Open https://github.com/osmosis-labs/osmosis/actions/workflows/go-mod-auto-bump.yml
  2. Provide the current branch name
  3. On success, confirm if an automated commit corretly updated the go.mod and go.sum files

Please let us know if you need any help.

@ValarDragon ValarDragon added V:state/compatible/backport State machine compatible PR, should be backported A:backport/v23.x backport patches to v23.x branch A:backport/v24.x backport patches to v24.x branch labels Apr 11, 2024
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 3

osmomath/decimal_test.go Outdated Show resolved Hide resolved
osmomath/decimal_test.go Outdated Show resolved Hide resolved
x/concentrated-liquidity/swapstrategy/one_for_zero.go Outdated Show resolved Hide resolved
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 5

x/concentrated-liquidity/position_test.go Show resolved Hide resolved
x/concentrated-liquidity/model/pool.go Outdated Show resolved Hide resolved
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

Copy link
Member

@p0mvn p0mvn left a comment

Choose a reason for hiding this comment

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

LGTM

Great speed-ups!

I will backport this and run a node for testing state compat

@p0mvn p0mvn merged commit 7b599d5 into main Apr 12, 2024
1 check passed
@p0mvn p0mvn deleted the dev/speedup_quoroundup branch April 12, 2024 16:31
@p0mvn p0mvn restored the dev/speedup_quoroundup branch April 12, 2024 16:32
@p0mvn p0mvn added A:backport/v24.x backport patches to v24.x branch and removed A:backport/v24.x backport patches to v24.x branch labels Apr 12, 2024
mergify bot pushed a commit that referenced this pull request Apr 12, 2024
* Speedup quo round up

* Code reuse

* Missed a code re-use point

* Add future notes

* Comment cleanup

* Auto: update go.mod after push to dev/speedup_quoroundup that modified dependencies locally

* Add new fn: NewBigDecFromDecMulDec

* Auto: update go.mod after push to dev/speedup_quoroundup that modified dependencies locally

* Remove some extra ops from CL

* Further perf notes

* Make faster QuoRoundUpNextIntMut

* Auto: update go.mod after push to dev/speedup_quoroundup that modified dependencies locally

* Remove another 2 BigDec ops

* Add another dec op

* Auto: update go.mod after push to dev/speedup_quoroundup that modified dependencies locally

* Start moving some liquidity calls to Dec not BigDec

* One more BigDec x Dec op

* Auto: update go.mod after push to dev/speedup_quoroundup that modified dependencies locally

* Another liq BigDec -> Dec

* Missed one step

* Move another Liquidity BigDec -> Dec

* Minor spread reward update

* Make CalcAmount1Dec use Dec for Liquidity

* Make one more op mutative

* One more speedup

* Fix test

* Speedup SpotPrice impl

---------

Co-authored-by: github-actions <[email protected]>
(cherry picked from commit 7b599d5)

# Conflicts:
#	CHANGELOG.md
#	go.mod
#	go.sum
#	osmomath/decimal.go
#	osmomath/go.mod
#	osmomath/go.sum
#	osmoutils/go.mod
#	osmoutils/go.sum
#	x/concentrated-liquidity/math/math.go
#	x/concentrated-liquidity/swapstrategy/one_for_zero.go
#	x/epochs/go.mod
#	x/epochs/go.sum
#	x/ibc-hooks/go.mod
#	x/ibc-hooks/go.sum
mergify bot pushed a commit that referenced this pull request Apr 12, 2024
* Speedup quo round up

* Code reuse

* Missed a code re-use point

* Add future notes

* Comment cleanup

* Auto: update go.mod after push to dev/speedup_quoroundup that modified dependencies locally

* Add new fn: NewBigDecFromDecMulDec

* Auto: update go.mod after push to dev/speedup_quoroundup that modified dependencies locally

* Remove some extra ops from CL

* Further perf notes

* Make faster QuoRoundUpNextIntMut

* Auto: update go.mod after push to dev/speedup_quoroundup that modified dependencies locally

* Remove another 2 BigDec ops

* Add another dec op

* Auto: update go.mod after push to dev/speedup_quoroundup that modified dependencies locally

* Start moving some liquidity calls to Dec not BigDec

* One more BigDec x Dec op

* Auto: update go.mod after push to dev/speedup_quoroundup that modified dependencies locally

* Another liq BigDec -> Dec

* Missed one step

* Move another Liquidity BigDec -> Dec

* Minor spread reward update

* Make CalcAmount1Dec use Dec for Liquidity

* Make one more op mutative

* One more speedup

* Fix test

* Speedup SpotPrice impl

---------

Co-authored-by: github-actions <[email protected]>
(cherry picked from commit 7b599d5)

# Conflicts:
#	CHANGELOG.md
#	go.mod
#	go.sum
#	osmomath/decimal.go
#	osmomath/go.mod
#	osmomath/go.sum
#	osmoutils/go.mod
#	osmoutils/go.sum
#	x/concentrated-liquidity/math/math.go
#	x/concentrated-liquidity/swapstrategy/one_for_zero.go
#	x/epochs/go.mod
#	x/epochs/go.sum
#	x/ibc-hooks/go.mod
#	x/ibc-hooks/go.sum
mergify bot pushed a commit that referenced this pull request Apr 12, 2024
* Speedup quo round up

* Code reuse

* Missed a code re-use point

* Add future notes

* Comment cleanup

* Auto: update go.mod after push to dev/speedup_quoroundup that modified dependencies locally

* Add new fn: NewBigDecFromDecMulDec

* Auto: update go.mod after push to dev/speedup_quoroundup that modified dependencies locally

* Remove some extra ops from CL

* Further perf notes

* Make faster QuoRoundUpNextIntMut

* Auto: update go.mod after push to dev/speedup_quoroundup that modified dependencies locally

* Remove another 2 BigDec ops

* Add another dec op

* Auto: update go.mod after push to dev/speedup_quoroundup that modified dependencies locally

* Start moving some liquidity calls to Dec not BigDec

* One more BigDec x Dec op

* Auto: update go.mod after push to dev/speedup_quoroundup that modified dependencies locally

* Another liq BigDec -> Dec

* Missed one step

* Move another Liquidity BigDec -> Dec

* Minor spread reward update

* Make CalcAmount1Dec use Dec for Liquidity

* Make one more op mutative

* One more speedup

* Fix test

* Speedup SpotPrice impl

---------

Co-authored-by: github-actions <[email protected]>
(cherry picked from commit 7b599d5)

# Conflicts:
#	CHANGELOG.md
#	go.mod
#	go.sum
#	osmomath/decimal.go
#	osmomath/go.mod
#	osmomath/go.sum
#	osmoutils/go.mod
#	osmoutils/go.sum
#	x/concentrated-liquidity/math/math.go
#	x/concentrated-liquidity/swapstrategy/one_for_zero.go
#	x/epochs/go.mod
#	x/epochs/go.sum
#	x/ibc-hooks/go.mod
#	x/ibc-hooks/go.sum
p0mvn pushed a commit that referenced this pull request Apr 12, 2024
* Speedup quo round up

* Code reuse

* Missed a code re-use point

* Add future notes

* Comment cleanup

* Auto: update go.mod after push to dev/speedup_quoroundup that modified dependencies locally

* Add new fn: NewBigDecFromDecMulDec

* Auto: update go.mod after push to dev/speedup_quoroundup that modified dependencies locally

* Remove some extra ops from CL

* Further perf notes

* Make faster QuoRoundUpNextIntMut

* Auto: update go.mod after push to dev/speedup_quoroundup that modified dependencies locally

* Remove another 2 BigDec ops

* Add another dec op

* Auto: update go.mod after push to dev/speedup_quoroundup that modified dependencies locally

* Start moving some liquidity calls to Dec not BigDec

* One more BigDec x Dec op

* Auto: update go.mod after push to dev/speedup_quoroundup that modified dependencies locally

* Another liq BigDec -> Dec

* Missed one step

* Move another Liquidity BigDec -> Dec

* Minor spread reward update

* Make CalcAmount1Dec use Dec for Liquidity

* Make one more op mutative

* One more speedup

* Fix test

* Speedup SpotPrice impl

---------

Co-authored-by: github-actions <[email protected]>
ValarDragon added a commit that referenced this pull request Apr 15, 2024
* BigDec operation speedups (backport #8006)

* Speedup quo round up, start CL speedup integration (#8014)

* Speedup quo round up

* Code reuse

* Missed a code re-use point

* Add future notes

* Comment cleanup

* Auto: update go.mod after push to dev/speedup_quoroundup that modified dependencies locally

* Add new fn: NewBigDecFromDecMulDec

* Auto: update go.mod after push to dev/speedup_quoroundup that modified dependencies locally

* Remove some extra ops from CL

* Further perf notes

* Make faster QuoRoundUpNextIntMut

* Auto: update go.mod after push to dev/speedup_quoroundup that modified dependencies locally

* Remove another 2 BigDec ops

* Add another dec op

* Auto: update go.mod after push to dev/speedup_quoroundup that modified dependencies locally

* Start moving some liquidity calls to Dec not BigDec

* One more BigDec x Dec op

* Auto: update go.mod after push to dev/speedup_quoroundup that modified dependencies locally

* Another liq BigDec -> Dec

* Missed one step

* Move another Liquidity BigDec -> Dec

* Minor spread reward update

* Make CalcAmount1Dec use Dec for Liquidity

* Make one more op mutative

* One more speedup

* Fix test

* Speedup SpotPrice impl

---------

Co-authored-by: github-actions <[email protected]>

* updates

* updates

---------

Co-authored-by: Dev Ojha <[email protected]>
Co-authored-by: github-actions <[email protected]>
@github-actions github-actions bot mentioned this pull request Apr 15, 2024
@github-actions github-actions bot mentioned this pull request May 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A:backport/v23.x backport patches to v23.x branch A:backport/v24.x backport patches to v24.x branch C:x/concentrated-liquidity C:x/epochs V:state/compatible/backport State machine compatible PR, should be backported
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants