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

Remove use of BigIntMulSignedPpm in favor of BigMulPpm #1589

Merged
merged 2 commits into from
May 29, 2024
Merged

Conversation

BrendanChou
Copy link
Contributor

@BrendanChou BrendanChou commented May 28, 2024

Changelist

Remove deprecated function

Test Plan

Existing unit tests

Copy link
Contributor

coderabbitai bot commented May 28, 2024

Walkthrough

The changes across the files involve replacing the function BigIntMulSignedPpm with BigMulPpm for calculating fees and rewards. This update impacts the fee calculation logic in various methods, ensuring a consistent and potentially more accurate approach to computing fees and rewards within the system.

Changes

File Path Change Summary
protocol/x/clob/keeper/mev.go Replaced BigIntMulSignedPpm with BigMulPpm in AddPnLForTradeWithFilledQuoteQuantums method.
protocol/x/clob/keeper/process_single_match.go Updated persistMatchedOrders method to use BigMulPpm instead of BigIntMulSignedPpm for fee calculations.
protocol/x/clob/types/pending_updates.go Changed AddPerpetualFill method to use BigMulPpm instead of BigIntMulSignedPpm for fee calculations.
protocol/x/rewards/keeper/keeper.go Modified AddRewardSharesForFill function to use BigMulPpm instead of BigIntMulSignedPpm.

Sequence Diagram(s) (Beta)

The changes are primarily focused on internal fee calculation logic and do not introduce new features or significantly alter control flows, so no sequence diagrams are necessary.


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.
    • @coderabbitai help me debug CodeRabbit configuration file.

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 an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to full the review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @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

@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: 0

Review Details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits Files that changed from the base of the PR and between 6f6ec38 and 782cb94.
Files selected for processing (5)
  • protocol/lib/big_math.go (1 hunks)
  • protocol/x/clob/keeper/mev.go (1 hunks)
  • protocol/x/clob/keeper/process_single_match.go (1 hunks)
  • protocol/x/clob/types/pending_updates.go (1 hunks)
  • protocol/x/rewards/keeper/keeper.go (1 hunks)
Additional Context Used
Path-based Instructions (5)
protocol/x/clob/types/pending_updates.go (1)

Pattern **/**: Do not include a walkthrough. For all comments on line changes that are longer than 15 lines, add a prefix to the comment of what lines you are commenting on (for example: "The changes from lines 100 to 200...". Add your comment to be on the last 15 lines of the chunk rather than adding your comment to the entire chunk.

protocol/lib/big_math.go (1)

Pattern **/**: Do not include a walkthrough. For all comments on line changes that are longer than 15 lines, add a prefix to the comment of what lines you are commenting on (for example: "The changes from lines 100 to 200...". Add your comment to be on the last 15 lines of the chunk rather than adding your comment to the entire chunk.

protocol/x/rewards/keeper/keeper.go (1)

Pattern **/**: Do not include a walkthrough. For all comments on line changes that are longer than 15 lines, add a prefix to the comment of what lines you are commenting on (for example: "The changes from lines 100 to 200...". Add your comment to be on the last 15 lines of the chunk rather than adding your comment to the entire chunk.

protocol/x/clob/keeper/process_single_match.go (1)

Pattern **/**: Do not include a walkthrough. For all comments on line changes that are longer than 15 lines, add a prefix to the comment of what lines you are commenting on (for example: "The changes from lines 100 to 200...". Add your comment to be on the last 15 lines of the chunk rather than adding your comment to the entire chunk.

protocol/x/clob/keeper/mev.go (1)

Pattern **/**: Do not include a walkthrough. For all comments on line changes that are longer than 15 lines, add a prefix to the comment of what lines you are commenting on (for example: "The changes from lines 100 to 200...". Add your comment to be on the last 15 lines of the chunk rather than adding your comment to the entire chunk.

Additional comments not posted (5)
protocol/x/clob/types/pending_updates.go (1)

172-172: The replacement of BigIntMulSignedPpm with BigMulPpm aligns with the PR's objectives. Ensure BigMulPpm handles signed values correctly as this affects fee calculations.

Verification successful

To ensure BigMulPpm handles signed values correctly, let's review its implementation and test cases.


To ensure BigMulPpm handles signed values correctly, let's review the remaining test cases in protocol/lib/big_math_test.go.


To ensure BigMulPpm handles signed values correctly, let's retrieve the complete test cases for TestBigMulPpm.


The test cases for BigMulPpm in protocol/lib/big_math_test.go do include scenarios with signed values, such as "Negative round down" and "Negative round up". This confirms that BigMulPpm correctly handles signed values, ensuring the correctness of fee calculations.

  • protocol/lib/big_math_test.go: Test cases for BigMulPpm include handling of signed values.
Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify that `BigMulPpm` correctly handles signed values.

# Test: Search for the function usage with signed values. Expect: Correct handling of signed values.
rg --type go $'BigMulPpm'

Length of output: 1392



Script:

#!/bin/bash
# Description: Retrieve the implementation and test cases of `BigMulPpm`.

# Retrieve the implementation of `BigMulPpm`.
rg --type go --context 10 'func BigMulPpm' protocol/lib/big_math.go

# Retrieve the test cases for `BigMulPpm`.
rg --type go --context 10 'TestBigMulPpm' protocol/lib/big_math_test.go

Length of output: 1346



Script:

#!/bin/bash
# Description: Retrieve the remaining test cases for `BigMulPpm` to verify handling of signed values.

# Retrieve the remaining test cases for `BigMulPpm`.
rg --type go --context 10 'TestBigMulPpm' protocol/lib/big_math_test.go

Length of output: 619



Script:

#!/bin/bash
# Description: Retrieve the complete test cases for `TestBigMulPpm` to verify handling of signed values.

# Retrieve the complete test cases for `TestBigMulPpm`.
rg --type go --context 50 'TestBigMulPpm' protocol/lib/big_math_test.go

Length of output: 2850

protocol/lib/big_math.go (1)

Line range hint 28-34: The implementation of BigMulPpm correctly performs multiplication followed by division, with an option to round up. This rounding feature is crucial for accurate fee calculations.

protocol/x/rewards/keeper/keeper.go (1)

139-139: The replacement of BigIntMulSignedPpm with BigMulPpm in reward calculations is consistent with the PR's objectives. Verify that BigMulPpm is used correctly in this context.

Verification successful

The BigMulPpm function is used in multiple files, including keeper.go. To ensure its correct usage in the context of reward calculations, we need to review its implementation and test cases.


Let's re-verify the implementation and test cases of BigMulPpm with adjusted search patterns.


The implementation and test cases for BigMulPpm have been successfully retrieved. The function BigMulPpm correctly handles the multiplication and rounding as specified, and the test cases cover various scenarios, including rounding up and down, and handling large values.

The replacement of BigIntMulSignedPpm with BigMulPpm in keeper.go is consistent with the intended usage and the function's implementation.

Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify the correct usage of `BigMulPpm` in reward calculations.

# Test: Search for the function usage in reward calculations. Expect: Correct usage in the context.
rg --type go $'BigMulPpm'

Length of output: 1392



Script:

#!/bin/bash
# Description: Review the implementation and test cases of `BigMulPpm`.

# Retrieve the implementation of `BigMulPpm` from `big_math.go`.
ast-grep --lang go --pattern $'func BigMulPpm(val *big.Int, ppm *big.Int, roundUp bool) *big.Int {
  $$$
}' > big_mul_ppm_impl.txt

# Retrieve the test cases for `BigMulPpm` from `big_math_test.go`.
ast-grep --lang go --pattern $'func TestBigMulPpm(t *testing.T) {
  $$$
}' > big_mul_ppm_tests.txt

Length of output: 184



Script:

#!/bin/bash
# Description: Review the implementation and test cases of `BigMulPpm`.

# Retrieve the implementation of `BigMulPpm` from `big_math.go`.
rg --type go --context 10 'func BigMulPpm' protocol/lib/big_math.go

# Retrieve the test cases for `BigMulPpm` from `big_math_test.go`.
rg --type go --context 10 'BigMulPpm' protocol/lib/big_math_test.go

Length of output: 2566

protocol/x/clob/keeper/process_single_match.go (1)

320-321: The replacement of BigIntMulSignedPpm with BigMulPpm in fee calculations during order matching is consistent with the PR's objectives. Verify that BigMulPpm is used correctly in this context.

protocol/x/clob/keeper/mev.go (1)

877-877: Replace BigIntMulSignedPpm with BigMulPpm to align with updated practices.

Verification successful

The BigMulPpm function is used in multiple places across the codebase, and its implementation and tests are located in protocol/lib/big_math.go and protocol/lib/big_math_test.go, respectively. The tests cover various scenarios, including rounding up and down.

  • protocol/lib/big_math.go: Implementation of BigMulPpm.
  • protocol/lib/big_math_test.go: Tests for BigMulPpm.
Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify that `BigMulPpm` behaves as expected in all scenarios where it's used.

# Test: Search for the function usage. Expect: Only occurances of the new signature.
rg --type go $'BigMulPpm'

Length of output: 1392

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: 0

Review Details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits Files that changed from the base of the PR and between 782cb94 and 6f9916c.
Files selected for processing (4)
  • protocol/x/clob/keeper/mev.go (1 hunks)
  • protocol/x/clob/keeper/process_single_match.go (1 hunks)
  • protocol/x/clob/types/pending_updates.go (1 hunks)
  • protocol/x/rewards/keeper/keeper.go (1 hunks)
Files skipped from review as they are similar to previous changes (4)
  • protocol/x/clob/keeper/mev.go
  • protocol/x/clob/keeper/process_single_match.go
  • protocol/x/clob/types/pending_updates.go
  • protocol/x/rewards/keeper/keeper.go

@BrendanChou BrendanChou merged commit 9425122 into main May 29, 2024
17 of 18 checks passed
@BrendanChou BrendanChou deleted the bc/bigmulppm branch May 29, 2024 18:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

Successfully merging this pull request may close these issues.

2 participants