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

feat(perp): MsgShiftPegMultiplier, MsgShiftSwapInvariant #1680

Merged
merged 21 commits into from
Dec 3, 2023

Conversation

Unique-Divine
Copy link
Member

@Unique-Divine Unique-Divine commented Nov 28, 2023

Purpose

Summary by CodeRabbit

  • New Features

    • Introduced MsgShiftPegMultiplier to adjust peg multiplier parameters for perpetual contracts.
    • Added MsgShiftSwapInvariant for modifying swap invariant parameters in perpetual contracts.
  • Improvements

    • Enhanced admin functions with permission checks for modifying AMM pool parameters.
    • Streamlined event emission for peg multiplier and swap invariant adjustments.
  • Bug Fixes

    • Corrected error message from ErrNegativeSwapInvariant to ErrNonPositiveSwapInvariant for clarity.
  • Refactor

    • Renamed functions related to price multiplier and swap invariant adjustments for better readability.
    • Removed deprecated functions PegShift and DepthShift from various modules.
  • Tests

    • Updated and added new test cases to cover the new admin functionalities and message types.
    • Removed obsolete test functions related to removed peg and depth shift functionalities.
  • Documentation

    • Updated CHANGELOG.md to reflect new features and changes in the perpetual contracts module.

dependabot bot and others added 5 commits November 17, 2023 18:57
@Unique-Divine Unique-Divine requested a review from a team as a code owner November 28, 2023 15:41
Copy link
Contributor

coderabbitai bot commented Nov 28, 2023

Warning

Rate Limit Exceeded

@Unique-Divine has exceeded the limit for the number of files or commits that can be reviewed per hour. Please wait 14 minutes and 3 seconds before requesting another review.

How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.
Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.
Please see our FAQ for further information.

Commits Files that changed from the base of the PR and between 3ff816f and 7de9341.

Walkthrough

The updates revolve around the introduction of new admin functions for adjusting the peg multiplier and swap invariant parameters in an AMM pool. This includes the addition of MsgShiftPegMultiplier and MsgShiftSwapInvariant messages, along with corresponding changes in the keeper and test files. The changes streamline permission checks and error messages, and remove previous peg and depth shift functionalities, reflecting a shift towards a more controlled and secure parameter adjustment mechanism.

Changes

File Path Change Summary
CHANGELOG.md, proto/nibiru/perp/v2/tx.proto, x/perp/v2/types/codec.go, x/perp/v2/types/msgs.go Added MsgShiftPegMultiplier and MsgShiftSwapInvariant messages.
wasmbinding/..., x/perp/v2/keeper/msg_server.go Removed peg and depth shift functionalities; added new admin functions for peg multiplier and swap invariant.
x/perp/v2/keeper/amm.go, x/perp/v2/keeper/amm_test.go Renamed functions to UnsafeShiftPegMultiplier and UnsafeShiftSwapInvariant; updated tests and error handling.
x/perp/v2/types/errors.go, x/perp/v2/types/amm.go, x/perp/v2/types/amm_test.go Updated error messages from ErrNegativeSwapInvariant to ErrNonPositiveSwapInvariant.
x/perp/v2/keeper/admin.go, x/perp/v2/keeper/admin_test.go Introduced new admin functions with permission checks and updated tests.
x/perp/v2/integration/action/market.go Changed function calls to new UnsafeShiftPegMultiplier and UnsafeShiftSwapInvariant.
x/perp/v2/keeper/clearing_house_test.go Updated test cases to use new ShiftSwapInvariant function and numeric values.

"In the realm of code where the rabbits hop,
A change was made, and old functions drop.
New messages rise with a multiplier's tune,
Admins rejoice under the digital moon. 🌕🐰"


Tips

Chat with CodeRabbit Bot (@coderabbitai)

  • If you reply to a review comment from CodeRabbit, the bot will automatically respond.
  • To engage with CodeRabbit bot directly around the specific lines of code in the PR, mention @coderabbitai in your review comment
  • Note: Review comments are made on code diffs or files, not on the PR overview.
  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

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.

Note: For conversation with the bot, please use the review comments on code diffs or files.

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • The JSON schema for the configuration file is available here.
  • 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/coderabbit-overrides.v2.json

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.

Review Status

Actionable comments generated: 6

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 2d59c9d and 1220834.
Files ignored due to filter (1)
  • x/perp/v2/types/tx.pb.go
Files selected for processing (23)
  • CHANGELOG.md (1 hunks)
  • proto/nibiru/perp/v2/tx.proto (2 hunks)
  • wasmbinding/bindings/msg.go (2 hunks)
  • wasmbinding/exec_perp.go (1 hunks)
  • wasmbinding/exec_perp_test.go (4 hunks)
  • wasmbinding/exec_test.go (2 hunks)
  • wasmbinding/message_plugin.go (1 hunks)
  • x/perp/v2/integration/action/dnr.go (1 hunks)
  • x/perp/v2/integration/action/market.go (2 hunks)
  • x/perp/v2/keeper/admin.go (1 hunks)
  • x/perp/v2/keeper/admin_test.go (12 hunks)
  • x/perp/v2/keeper/amm.go (3 hunks)
  • x/perp/v2/keeper/amm_test.go (4 hunks)
  • x/perp/v2/keeper/fixture_test.go (1 hunks)
  • x/perp/v2/keeper/msg_server.go (2 hunks)
  • x/perp/v2/types/amm.go (1 hunks)
  • x/perp/v2/types/amm_test.go (1 hunks)
  • x/perp/v2/types/codec.go (2 hunks)
  • x/perp/v2/types/codec_test.go (1 hunks)
  • x/perp/v2/types/errors.go (2 hunks)
  • x/perp/v2/types/msgs.go (12 hunks)
  • x/perp/v2/types/msgs_test.go (4 hunks)
  • x/sudo/keeper/keeper.go (1 hunks)
Files skipped from review due to trivial changes (6)
  • wasmbinding/exec_test.go
  • x/perp/v2/integration/action/dnr.go
  • x/perp/v2/keeper/fixture_test.go
  • x/perp/v2/types/amm.go
  • x/perp/v2/types/codec_test.go
  • x/perp/v2/types/errors.go
Additional comments: 41
CHANGELOG.md (1)
  • 60-63: The new feature entries for MsgShiftPegMultiplier and MsgShiftSwapInvariant are correctly placed under the "State Machine Breaking" section, as they likely introduce changes that could affect the state machine.
proto/nibiru/perp/v2/tx.proto (3)
  • 41-50: The addition of the ShiftPegMultiplier and ShiftSwapInvariant RPC methods with admin-only comments is clear and follows the existing code style.

  • 395-407: The MsgShiftPegMultiplier message structure is correctly defined with appropriate field types and non-nullable constraints.

  • 414-426: The MsgShiftSwapInvariant message structure is correctly defined with appropriate field types and non-nullable constraints.

wasmbinding/bindings/msg.go (2)
  • 20-25: The removal of PegShift and DepthShift types from the NibiruMsg struct aligns with the changes described in the summary. Ensure that any code that previously depended on these fields has been updated or removed accordingly.

  • 20-25: > Note: This review was outside the patches, so it was mapped to the patch with the greatest overlap. Original lines [1-68]

Verify that the removal of PegShift and DepthShift from the NibiruMsg struct does not result in any orphaned code or unhandled cases elsewhere in the codebase.

wasmbinding/exec_perp.go (2)
  • 140-142: The InsuranceFundWithdraw function lacks a sender parameter in its signature, which might be necessary for permission checks or logging. Please verify if this is intentional or an oversight.

  • 137-142: Ensure that all references to the removed PegShift and DepthShift methods have been updated or removed throughout the entire codebase to prevent any broken functionality.

wasmbinding/exec_perp_test.go (4)
  • 91-96: The changes in the test suite appear to be consistent with the removal of the DoPegShiftTest and DoDepthShiftTest functions as described in the summary. The remaining tests are well-structured and there are no signs of orphaned code or logic issues.

  • 211-216: The test function DoInsuranceFundWithdrawTest is correctly implemented and follows the expected test pattern. It's good to see that the test checks for the proper handling of module account funding before attempting the withdrawal.

  • 280-285: The TestSadPaths_Nil function correctly tests for nil inputs to various executor methods, ensuring that the system behaves as expected when provided with invalid arguments.

  • 319-324: The TestSadPaths_InvalidPair function is testing the system's behavior with an invalid trading pair. This is a good practice to ensure that the system can handle unexpected or malformed input gracefully.

wasmbinding/message_plugin.go (1)
  • 80-81: The changes in the DispatchMsg function appear to be correct and handle different message types as expected.
x/perp/v2/integration/action/market.go (2)
  • 142-144: The editPriceMultiplier action now uses UnsafeShiftPegMultiplier. Ensure that the necessary validations are performed before this action is invoked to prevent unintended consequences due to the "unsafe" nature of the method.

  • 159-160: Similarly, the editSwapInvariant action uses UnsafeShiftSwapInvariant. It is crucial to verify that appropriate checks are in place before this method is called to maintain system integrity.

x/perp/v2/keeper/admin.go (2)
  • 187-190: The permission check using SudoKeeper is correctly placed before the call to UnsafeShiftPegMultiplier, ensuring only authorized users can perform this action.

  • 202-205: The permission check using SudoKeeper is correctly placed before the call to UnsafeShiftSwapInvariant, ensuring only authorized users can perform this action.

x/perp/v2/keeper/admin_test.go (5)
  • 11-11: The addition of the "github.com/stretchr/testify/suite" import is appropriate for the new test suite TestSuiteAdmin.

  • 21-21: The renaming of the "types" package alias to "perptypes" is consistent and improves clarity.

  • 352-486: The addition of the TestSuiteAdmin test suite with setup, test, and helper functions is a good practice for organizing admin-related tests.

  • 410-486: The new test cases for admin permissions and admin functionality are well-structured and cover important scenarios.

  • 348-486: > Note: This review was outside the patches, so it was mapped to the patch with the greatest overlap. Original lines [1-486]

No issues found in the provided hunks regarding logic, security, performance, or consistency.

x/perp/v2/keeper/amm.go (4)
  • 14-21: The function UnsafeShiftPegMultiplier has been renamed and updated correctly according to the summary. Ensure that all references to this function in the codebase are updated to reflect the new name and signature.

  • 51-56: The function UnsafeShiftSwapInvariant has been renamed and updated correctly according to the summary. Ensure that all references to this function in the codebase are updated to reflect the new name and signature.

  • 85-86: The signature of the function handleMarketUpdateCost has been updated correctly according to the summary. Ensure that all calls to this function are updated to match the new signature.

  • 90-90: The error handling for insufficient funds in the margin vault is intentionally omitted, as explained in the comment. This is a business logic decision, but it's important to ensure that this behavior is well-documented and understood by the team to avoid confusion.

x/perp/v2/keeper/amm_test.go (4)
  • 188-193: The error message checks in the test cases correctly reflect the new error types returned by the UnsafeShiftPegMultiplier function.

  • 214-215: The error message checks in the test cases correctly reflect the new error types returned by the UnsafeShiftPegMultiplier function.

  • 254-259: The error message checks in the test cases correctly reflect the new error types returned by the UnsafeShiftSwapInvariant function.

  • 280-285: The error message checks in the test cases correctly reflect the new error types returned by the UnsafeShiftSwapInvariant function.

x/perp/v2/keeper/msg_server.go (2)
  • 113-118: The implementation of SettlePosition appears to be correct and follows the standard pattern for gRPC service methods in the Cosmos SDK.

  • 192-218: The addition of ShiftPegMultiplier and ShiftSwapInvariant functions is consistent with the admin-only pattern for sensitive operations. Ensure that the permission checks for sudoers are properly implemented elsewhere in the codebase.

x/perp/v2/types/amm_test.go (1)
  • 589-593: The update from types.ErrNegativeSwapInvariant to types.ErrNonPositiveSwapInvariant correctly reflects the broader condition where the newSwapInvariant is not only negative but also when it is zero. This change should be verified across the codebase to ensure that all relevant error checks and associated tests are updated accordingly.
x/perp/v2/types/codec.go (2)
  • 16-20: The registration of new message types MsgShiftPegMultiplier and MsgShiftSwapInvariant in the codec is correct and aligns with the summary provided.

  • 31-35: The registration of new message types MsgShiftPegMultiplier and MsgShiftSwapInvariant in the interface registry is correct and aligns with the summary provided.

x/perp/v2/types/msgs_test.go (5)
  • 375-394: The test cases for MsgShiftPegMultiplier correctly check for an invalid pair and a nonpositive peg multiplier. This aligns with the expected validation logic for the message.

  • 397-414: The test cases for MsgShiftSwapInvariant correctly check for an invalid pair and a nonpositive swap invariant. This aligns with the expected validation logic for the message.

  • 441-445: The MsgShiftPegMultiplier and MsgShiftSwapInvariant messages have been correctly added to the msgValidSenderList for testing the GetSigners method with a valid sender.

  • 456-457: The MsgShiftPegMultiplier and MsgShiftSwapInvariant messages have been correctly added to the msgInvalidSenderList for testing the GetSigners method with an invalid sender.

  • 595-600: The MsgShiftPegMultiplier and MsgShiftSwapInvariant messages have been correctly added to the test cases for the GetSignBytes method, ensuring that the serialization of these messages is consistent and correct.

x/sudo/keeper/keeper.go (1)
  • 141-147: The use of %w for error wrapping in the CheckPermissions function is correct and allows for better error handling by enabling errors to be unwrapped later. This is a good practice in Go error handling.

x/perp/v2/types/msgs.go Outdated Show resolved Hide resolved
wasmbinding/message_plugin.go Show resolved Hide resolved
x/perp/v2/keeper/amm_test.go Outdated Show resolved Hide resolved
x/perp/v2/keeper/admin.go Outdated Show resolved Hide resolved
x/perp/v2/keeper/admin.go Outdated Show resolved Hide resolved
x/perp/v2/keeper/admin.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.

Review Status

Actionable comments generated: 0

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 1220834 and 696d636.
Files selected for processing (1)
  • CHANGELOG.md (1 hunks)
Additional comments: 1
CHANGELOG.md (1)
  • 60-63: The addition of MsgShiftPegMultiplier and MsgShiftSwapInvariant to the perpetual contracts module is a significant update that introduces new admin-only transaction messages for adjusting financial parameters. Ensure that the necessary documentation, user guides, and admin operational procedures are updated to reflect these new features.

Copy link

codecov bot commented Nov 28, 2023

Codecov Report

Merging #1680 (ad8c56b) into master (2d59c9d) will increase coverage by 0.25%.
Report is 4 commits behind head on master.
The diff coverage is 87.75%.

❗ Current head ad8c56b differs from pull request most recent head 7de9341. Consider uploading reports for the commit 7de9341 to get more accurate results

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1680      +/-   ##
==========================================
+ Coverage   73.92%   74.17%   +0.25%     
==========================================
  Files         192      192              
  Lines       15398    15451      +53     
==========================================
+ Hits        11383    11461      +78     
+ Misses       3355     3323      -32     
- Partials      660      667       +7     
Files Coverage Δ
app/genesis.go 19.51% <100.00%> (+2.01%) ⬆️
app/keepers.go 99.20% <100.00%> (ø)
wasmbinding/exec_perp.go 84.89% <ø> (-2.15%) ⬇️
wasmbinding/message_plugin.go 86.30% <ø> (-2.21%) ⬇️
x/perp/v2/keeper/msg_server.go 93.57% <100.00%> (+20.63%) ⬆️
x/perp/v2/types/amm.go 80.32% <100.00%> (ø)
x/perp/v2/types/codec.go 100.00% <100.00%> (ø)
x/sudo/keeper/keeper.go 74.41% <100.00%> (ø)
x/common/constants.go 0.00% <0.00%> (ø)
x/perp/v2/keeper/amm.go 89.15% <93.75%> (-0.68%) ⬇️
... and 2 more

... and 5 files with indirect coverage changes

Unique-Divine and others added 2 commits November 28, 2023 09:47
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
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.

Review Status

Actionable comments generated: 3

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 696d636 and b081818.
Files selected for processing (5)
  • x/perp/v2/keeper/admin.go (1 hunks)
  • x/perp/v2/keeper/admin_test.go (12 hunks)
  • x/perp/v2/keeper/amm.go (3 hunks)
  • x/perp/v2/keeper/amm_test.go (6 hunks)
  • x/perp/v2/types/msgs.go (12 hunks)
Additional comments: 11
x/perp/v2/keeper/admin.go (1)
  • 178-206: The new functions ShiftPegMultiplier and ShiftSwapInvariant are correctly checking permissions before proceeding with the operation. Ensure that these functions are not exposed to the MsgServer, are not called from other methods in the x/perp module, and are only callable from nibiru/wasmbinding via sudo contracts as intended.
x/perp/v2/keeper/amm.go (3)
  • 14-21: The function UnsafeShiftPegMultiplier has been correctly renamed and the comments have been updated to reflect the new functionality. The additional parameter pair asset.Pair has been added to the function signature as described in the summary.

  • 51-56: The function UnsafeShiftSwapInvariant has been correctly renamed and the comments have been updated to reflect the new functionality. The additional parameter pair asset.Pair has been added to the function signature as described in the summary.

  • 85-86: The signature of the handleMarketUpdateCost function has been correctly updated to include the additional parameter costAmt sdkmath.Int, aligning with the summary.

x/perp/v2/types/msgs.go (7)
  • 22-23: The addition of the new message types MsgShiftPegMultiplier and MsgShiftSwapInvariant is confirmed and the interface assertions are correctly in place.

  • 254-255: The renaming of the MsgPartialClose type string to "partial_close_msg" is correct and aligns with the summary.

  • 285-285: The renaming of the MsgChangeCollateralDenom type string to "change_collateral_denom_msg" is correct and aligns with the summary.

  • 366-367: The validation in MsgShiftPegMultiplier correctly checks for a positive NewPegMult, which aligns with the summary.

  • 393-394: The validation in MsgShiftSwapInvariant correctly checks for a positive NewSwapInvariant, which aligns with the summary.

  • 372-382: The GetSignBytes and GetSigners methods for MsgShiftPegMultiplier are correctly implemented.

  • 399-409: The GetSignBytes and GetSigners methods for MsgShiftSwapInvariant are correctly implemented.

x/perp/v2/keeper/amm.go Outdated Show resolved Hide resolved
x/perp/v2/keeper/amm_test.go Show resolved Hide resolved
x/perp/v2/keeper/amm_test.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.

Review Status

Actionable comments generated: 7

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between b081818 and 1b5c836.
Files ignored due to filter (1)
  • x/perp/v2/types/event.pb.go
Files selected for processing (7)
  • proto/nibiru/perp/v2/event.proto (1 hunks)
  • x/perp/v2/integration/action/market.go (2 hunks)
  • x/perp/v2/keeper/admin.go (1 hunks)
  • x/perp/v2/keeper/amm.go (6 hunks)
  • x/perp/v2/keeper/amm_test.go (12 hunks)
  • x/perp/v2/keeper/clearing_house_test.go (9 hunks)
  • x/perp/v2/keeper/msg_server.go (2 hunks)
Files skipped from review due to trivial changes (1)
  • x/perp/v2/keeper/clearing_house_test.go
Additional comments: 5
x/perp/v2/keeper/admin.go (1)
  • 178-205: The code does not show any logic for checking or transferring funds from the perp fund to cover the adjustments made by ShiftPegMultiplier and ShiftSwapInvariant. This is mentioned in the summary as an important aspect of these operations. Please ensure that the necessary logic for handling funds is implemented or clarify if it's handled elsewhere.
x/perp/v2/keeper/amm.go (4)
  • 11-21: The function UnsafeShiftPegMultiplier has been updated to include a new parameter newPriceMultiplier and to emit an event after updating the price multiplier. Ensure that all calls to this function are updated to pass the new parameter and that the event emission is handled correctly.

  • 56-62: The function UnsafeShiftSwapInvariant has been updated to include a new parameter newSwapInvariant and to emit an event after updating the swap invariant. Ensure that all calls to this function are updated to pass the new parameter and that the event emission is handled correctly.

  • 93-95: The handleMarketUpdateCost function now returns costPaid along with any error. Verify that the callers of this function handle the new return value correctly.

  • 129-146: > Note: This review was outside the patches, so it was mapped to the patch with the greatest overlap. Original lines [121-141]

The logic for handling negative costs in the handleMarketUpdateCost function does not treat a lack of funds in the vault as an error. This is an unusual approach and could potentially lead to bad debt in the system. It is recommended to verify this business logic decision with the stakeholders to ensure it aligns with the intended behavior of the system.

proto/nibiru/perp/v2/event.proto Show resolved Hide resolved
proto/nibiru/perp/v2/event.proto Show resolved Hide resolved
x/perp/v2/integration/action/market.go Outdated Show resolved Hide resolved
x/perp/v2/keeper/admin.go Outdated Show resolved Hide resolved
x/perp/v2/keeper/admin.go Outdated Show resolved Hide resolved
x/perp/v2/keeper/msg_server.go Show resolved Hide resolved
x/perp/v2/keeper/msg_server.go 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.

Review Status

Actionable comments generated: 7

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 1b5c836 and 2f0a125.
Files selected for processing (3)
  • x/perp/v2/keeper/amm.go (6 hunks)
  • x/perp/v2/keeper/amm_test.go (12 hunks)
  • x/perp/v2/types/errors.go (2 hunks)
Additional comments: 4
x/perp/v2/keeper/amm.go (3)
  • 24-32: > Note: This review was outside the patches, so it was mapped to the patch with the greatest overlap. Original lines [14-53]

The changes made to the UnsafeShiftPegMultiplier function, including the renaming, addition of the oldPriceMult parameter, early return optimization, and event emission, are consistent with the summary and appear to be correctly implemented.

  • 56-90: The changes made to the UnsafeShiftSwapInvariant function, including the renaming and event emission, are consistent with the summary and appear to be correctly implemented.

  • 129-146: > Note: This review was outside the patches, so it was mapped to the patch with the greatest overlap. Original lines [93-143]

The handleMarketUpdateCost function has been updated to return costPaid sdk.Coin and includes detailed error handling and comments explaining the logic for handling negative costs. These changes are consistent with the summary and appear to be correctly implemented.

x/perp/v2/types/errors.go (1)
  • 38-42: The renaming of ErrNegativeSwapInvariant to ErrNonPositiveSwapInvariant and the updated error message for ErrNilSwapInvariant are consistent with the summary. Verify that all references to these errors in the codebase have been updated accordingly.

x/perp/v2/keeper/amm_test.go Show resolved Hide resolved
x/perp/v2/keeper/amm_test.go Show resolved Hide resolved
x/perp/v2/keeper/amm_test.go Show resolved Hide resolved
x/perp/v2/keeper/amm_test.go Show resolved Hide resolved
x/perp/v2/keeper/amm_test.go Show resolved Hide resolved
x/perp/v2/keeper/amm_test.go Show resolved Hide resolved
x/perp/v2/keeper/amm_test.go 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.

Review Status

Actionable comments generated: 0

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 2f0a125 and 552a2d5.
Files selected for processing (5)
  • x/perp/v2/integration/action/market.go (1 hunks)
  • x/perp/v2/keeper/admin.go (1 hunks)
  • x/perp/v2/keeper/amm.go (6 hunks)
  • x/perp/v2/keeper/amm_test.go (18 hunks)
  • x/perp/v2/keeper/clearing_house_test.go (9 hunks)
Additional comments: 12
x/perp/v2/integration/action/market.go (1)
  • 137-168: The changes to the shiftPegMultiplier and shiftSwapInvariant structs and their associated Do methods, as well as the functions to create these actions, are consistent with the summary provided and appear to be correctly implemented.
x/perp/v2/keeper/amm.go (10)
  • 11-21: The function UnsafeShiftPegMultiplier has been correctly renamed and updated to include the new logic for handling the peg multiplier change.

  • 24-32: The early return when the new price multiplier is the same as the old one is a good practice to avoid unnecessary computation and state changes.

  • 37-43: The error handling in UnsafeShiftPegMultiplier is consistent and ensures that any error from calculating the cost or handling the market update cost is returned immediately.

  • 46-53: The event emission in UnsafeShiftPegMultiplier has been updated to include the old and new peg multipliers as well as the cost paid, which aligns with the summary of changes.

  • 61-62: The addition of the newSwapInvariant parameter to the UnsafeShiftSwapInvariant function is consistent with the summary and allows for the necessary functionality to adjust the swap invariant.

  • 69-77: The error handling in UnsafeShiftSwapInvariant is consistent and ensures that any error from calculating the cost or handling the market update cost is returned immediately.

  • 79-90: The event emission in UnsafeShiftSwapInvariant has been updated to include the old and new swap invariants as well as the cost paid, which aligns with the summary of changes.

  • 93-95: The handleMarketUpdateCost function has been updated to return the costPaid as part of its return values, which is necessary for the updated event emissions in the UnsafeShiftPegMultiplier and UnsafeShiftSwapInvariant functions.

  • 110-117: The error handling in handleMarketUpdateCost when there's not enough funds in the perp EF to pay for a positive cost is clear and provides detailed information about the shortfall.

  • 129-141: The handling of a negative cost in handleMarketUpdateCost is unconventional as it does not return an error if there are insufficient funds in the vault. This behavior should be verified to ensure it aligns with the system's requirements and risk management strategy.

x/perp/v2/keeper/clearing_house_test.go (1)
  • 2040-2048: > Note: This review was outside the patches, so it was mapped to the patch with the greatest overlap. Original lines [1956-2125]

The test cases provided for the ShiftSwapInvariant function appear to be comprehensive and well-structured, covering a variety of scenarios including only long positions, only short positions, and both with increasing and decreasing swap invariants. The assertions after the swap invariant changes, such as AMMShouldBeEqual and ModuleBalanceShouldBeEqualTo, are correctly used to verify the expected state of the system. The tests also include cleanup checks to ensure that positions are closed and module balances are as expected at the end of the tests. Overall, the test cases seem to be maintainable and easy to understand, which is good for future test enhancements and debugging.

x/perp/v2/keeper/admin.go Outdated Show resolved Hide resolved
x/perp/v2/keeper/amm.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.

Review Status

Actionable comments generated: 3

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 552a2d5 and fe1fe03.
Files ignored due to filter (2)
  • x/perp/v2/types/event.pb.go
  • x/perp/v2/types/tx.pb.go
Files selected for processing (11)
  • proto/nibiru/perp/v2/event.proto (1 hunks)
  • proto/nibiru/perp/v2/tx.proto (2 hunks)
  • x/common/testutil/testapp/testapp.go (2 hunks)
  • x/perp/v2/integration/action/dnr.go (5 hunks)
  • x/perp/v2/integration/action/market.go (2 hunks)
  • x/perp/v2/integration/action/position.go (3 hunks)
  • x/perp/v2/keeper/admin.go (1 hunks)
  • x/perp/v2/keeper/amm.go (3 hunks)
  • x/perp/v2/keeper/amm_test.go (18 hunks)
  • x/perp/v2/keeper/msg_server.go (4 hunks)
  • x/perp/v2/keeper/msg_server_test.go (3 hunks)
Files skipped from review due to trivial changes (1)
  • x/perp/v2/keeper/msg_server_test.go
Additional comments: 29
proto/nibiru/perp/v2/tx.proto (2)
  • 43-51: The addition of the ShiftPegMultiplier and ShiftSwapInvariant RPC methods aligns with the summary and pull request details, providing admin-level management of market parameters. Ensure that appropriate access controls are implemented to restrict these operations to admin users only.

  • 395-429: The message definitions for MsgShiftPegMultiplier and MsgShiftSwapInvariant are consistent with the summary and pull request details. The use of github.com/cosmos/cosmos-sdk/types.Dec and github.com/cosmos/cosmos-sdk/types.Int for the new peg multiplier and swap invariant ensures that the values are handled with the correct precision and type.

x/common/testutil/testapp/testapp.go (5)
  • 21-21: The import of sudotypes is correctly added and used within the file.

  • 40-40: The app.SudoKeeper.Sudoers.Set method call is correctly added and uses the DefaultSudoers function to set the initial sudoers state.

  • 46-50: The NewContext function is correctly implemented and used to create a fresh sdk.Context for the given NibiruApp.

  • 54-60: The DefaultSudoers function is correctly implemented, providing a sudotypes.Sudoers type with the root address set for both the root and contracts fields.

  • 63-65: The DefaultSudoRoot function is correctly implemented, returning an sdk.AccAddress in the correct Bech32 format.

x/perp/v2/integration/action/dnr.go (1)
  • 217-236: In the fundDnREpoch Do method, a temporary account is funded and then used to call AllocateEpochRebates. It's important to ensure that this temporary account is securely handled and that its usage here does not introduce any security risks, such as the potential for unauthorized access to funds.
x/perp/v2/integration/action/market.go (9)
  • 9-12: The addition of the testutil/testapp package is appropriate as it is used within the new ShiftPegMultiplier and ShiftSwapInvariant functions.

  • 138-140: The new type shiftPegMultiplier is correctly defined to encapsulate the parameters for the ShiftPegMultiplier function.

  • 157-159: The new type shiftSwapInvariant is correctly defined to encapsulate the parameters for the ShiftSwapInvariant function.

  • 143-147: The ShiftPegMultiplier function is correctly implemented to use the PerpKeeperV2.Admin.ShiftPegMultiplier method with the provided parameters.

  • 162-166: The ShiftSwapInvariant function is correctly implemented to use the PerpKeeperV2.Admin.ShiftSwapInvariant method with the provided parameters.

  • 138-140: The fields of the shiftPegMultiplier struct are unexported, which is suitable for encapsulation within the package.

  • 157-159: The fields of the shiftSwapInvariant struct are unexported, which is suitable for encapsulation within the package.

  • 143-147: The Do method of shiftPegMultiplier correctly calls the ShiftPegMultiplier admin function and returns the expected values.

  • 162-166: The Do method of shiftSwapInvariant correctly calls the ShiftSwapInvariant admin function and returns the expected values.

x/perp/v2/integration/action/position.go (2)
  • 13-17: The addition of the perpkeeper import is appropriate for the new usage of perpkeeper.NewMsgServerImpl in the partialClose and partialCloseFails functions.

  • 346-357: The refactoring of the partialClose function to use the MsgPartialClose type and the PartialClose method on perpkeeper.MsgServerImpl is consistent with the summary.

x/perp/v2/keeper/admin.go (2)
  • 174-175: The change to UnsafeChangeCollateralDenom to set the collateral denom is correct and aligns with the summary.

  • 178-262: The new functions ShiftPegMultiplier and ShiftSwapInvariant are implemented correctly. They include permission checks, error handling, and event emission. Ensure that all dependent code and documentation are updated to reflect these new admin capabilities.

x/perp/v2/keeper/amm.go (2)
  • 50-67: > Note: This review was outside the patches, so it was mapped to the patch with the greatest overlap. Original lines [14-64]

The handleMarketUpdateCost function now assigns a costPaid value even in error scenarios. Ensure that this behavior is well-documented and understood by the team, as it represents a significant change in the function's contract. The comments provide some context, but it's crucial that all stakeholders are aware of this change and its implications.

  • 52-52: The use of nolint:staticcheck suppresses lint warnings. Confirm that this is the best approach and that no potential issues are being masked by this directive. It's important to ensure that code quality tools are used effectively and that exceptions are made with careful consideration.
x/perp/v2/keeper/amm_test.go (6)
  • 24-27: The test function name TestShiftPegMultiplier correctly reflects the updated functionality.

  • 35-35: The test case is correctly using the ShiftPegMultiplier function to test the new functionality.

  • 192-192: The ShiftPegMultiplier function call within the TestShiftPegMultiplier_Fail test case correctly includes the adminAddr parameter.

  • 265-265: The ShiftSwapInvariant function call within the TestShiftSwapInvariant_Fail test case correctly replaces the deprecated EditSwapInvariant.

  • 314-314: The test case is correctly using the ShiftSwapInvariant function to test the new functionality.

  • 358-358: The test case is correctly using the ShiftSwapInvariant function to test the new functionality.

x/perp/v2/integration/action/position.go Show resolved Hide resolved
x/perp/v2/integration/action/dnr.go Show resolved Hide resolved
x/perp/v2/integration/action/dnr.go 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.

Review Status

Actionable comments generated: 0

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between fe1fe03 and c3ef701.
Files selected for processing (7)
  • x/common/constants.go (1 hunks)
  • x/common/testutil/const.go (1 hunks)
  • x/common/testutil/testapp/testapp.go (2 hunks)
  • x/perp/v2/integration/action/market.go (4 hunks)
  • x/perp/v2/module/genesis_test.go (1 hunks)
  • x/spot/genesis_test.go (1 hunks)
  • x/spot/keeper/balances_test.go (1 hunks)
Files skipped from review due to trivial changes (2)
  • x/common/testutil/const.go
  • x/perp/v2/module/genesis_test.go
Additional comments: 13
x/common/constants.go (2)
  • 10-10: The change from NibiruTeam to NIBIRU_TEAM aligns with Go's naming conventions for constants, which is a good practice for code readability and maintainability.

  • 13-14: The function NibiruTeamAddr correctly uses the updated constant NIBIRU_TEAM. Ensure that all references to this constant throughout the codebase have been updated accordingly.

x/common/testutil/testapp/testapp.go (4)
  • 15-22: The import statements for the new packages github.com/NibiruChain/nibiru/x/common/testutil and sudotypes have been added correctly.

  • 54-65: The new functions DefaultSudoers and DefaultSudoRoot have been added as per the summary and appear to be correctly implemented.

  • 38-43: The NewNibiruTestAppAndContext function has been updated to include setting up the oracle prices and default sudoers, which aligns with the summary.

  • 67-69: The NewNibiruTestAppAndContextAtTime function is a new utility function for testing purposes, allowing the creation of an app and context with a specified block time.

x/perp/v2/integration/action/market.go (5)
  • 9-12: The import statement for "github.com/NibiruChain/nibiru/x/common/testutil/testapp" has been added, ensure that it is used appropriately in the new functions and there are no unused imports.

  • 138-154: The new type "shiftPegMultiplier" and its associated function "ShiftPegMultiplier" have been added. Verify that the new action is correctly integrated into the system and that the function is being used as intended.

  • 157-173: The new type "shiftSwapInvariant" and its associated function "ShiftSwapInvariant" have been added. Verify that the new action is correctly integrated into the system and that the function is being used as intended.

  • 207-210: The "setCollateral" struct has been modified to use "common.NIBIRU_TEAM" as the root sudoer. Ensure that this change is consistent with the intended use of the sudoers in the system and that it does not introduce any security or permission issues.

  • 221-224: The "SetCollateral" function has been modified to use "common.NIBIRU_TEAM" as the sender. Ensure that this change is consistent with the intended use of the sender in the system and that it does not introduce any security or permission issues.

x/spot/genesis_test.go (1)
  • 16-16: The addition of testapp.EnsureNibiruPrefix() is noted. Ensure that this function is necessary for the test setup and does not introduce side effects that could affect the test outcomes.
x/spot/keeper/balances_test.go (1)
  • 55-55: The addition of testapp.EnsureNibiruPrefix() is a good practice to ensure that the address prefix is correctly set for the test environment. This helps in maintaining consistency across tests and avoids potential issues with address formatting.

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.

Review Status

Actionable comments generated: 0

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between c3ef701 and a2ee8aa.
Files selected for processing (5)
  • app/keepers.go (8 hunks)
  • x/common/testutil/testapp/testapp.go (2 hunks)
  • x/devgas/v1/ante/ante_test.go (1 hunks)
  • x/inflation/keeper/inflation_test.go (1 hunks)
  • x/oracle/keeper/hooks_test.go (1 hunks)
Files skipped from review due to trivial changes (1)
  • x/oracle/keeper/hooks_test.go
Additional comments: 11
app/keepers.go (1)
  • 241-241: The introduction of the govModuleAddr variable to store the result of authtypes.NewModuleAddress(govtypes.ModuleName).String() and its subsequent use in the initialization of various keepers is a good practice. It avoids repeated function calls, which is a performance optimization.
x/common/testutil/testapp/testapp.go (6)
  • 29-29: The call to EnsureNibiruPrefix() is correctly placed to set the address prefix before any test logic that depends on Bech32 addresses is executed.

  • 42-45: The code correctly sets default values for the OracleKeeper and SudoKeeper within the NewNibiruTestAppAndContext function, ensuring that the test app is initialized with a consistent state.

  • 50-55: The NewContext function is well-defined and returns a fresh sdk.Context with a height of 1 and the current UTC time, which is consistent with the typical setup for a new blockchain context in tests.

  • 58-64: The DefaultSudoers function correctly initializes the sudotypes.Sudoers struct with the default sudo root address, which is necessary for setting up the x/sudo module state in tests.

  • 67-68: The DefaultSudoRoot function correctly retrieves the default sudo root address from the testutil package, which is a common pattern for setting up test addresses.

  • 73-73: The function NewNibiruTestAppAndContextAtTime is not mentioned in the summary. It appears to be a refactoring to use the NewContext function, which should be noted for clarity.

x/devgas/v1/ante/ante_test.go (2)
  • 27-30: The addition of testapp.EnsureNibiruPrefix() in the TestAnteSuite function is confirmed and should ensure the correct setup for the AnteTestSuite.

  • 25-31: No further issues or changes detected in the provided hunk.

x/inflation/keeper/inflation_test.go (2)
  • 72-82: The removal of the conditional block around the SudoKeeper method call is not reflected in the provided hunk. The test still contains logic that checks tc.rootAccount for an empty string before setting the strategic reserve balance. If the conditional block was indeed removed, this could lead to unintended behavior when tc.rootAccount is an empty string. Please verify the intended behavior and update the test accordingly.

  • 76-77: The direct assignment of tc.rootAccount to the Root field in the Sudoers struct has been changed to use the value without conversion. Ensure that tc.rootAccount is provided in the correct format expected by the Sudoers struct, as this could potentially lead to issues if the format is not as expected.

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.

Review Status

Actionable comments generated: 1

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between a2ee8aa and 3ff816f.
Files selected for processing (9)
  • CHANGELOG.md (1 hunks)
  • app/genesis.go (1 hunks)
  • app/ibc_test.go (1 hunks)
  • app/keepers.go (8 hunks)
  • wasmbinding/wasmbin_test.go (1 hunks)
  • x/perp/v2/integration/action/position.go (4 hunks)
  • x/perp/v2/keeper/msg_server.go (3 hunks)
  • x/perp/v2/keeper/msg_server_test.go (4 hunks)
  • x/perp/v2/module/genesis_test.go (1 hunks)
Files skipped from review due to trivial changes (1)
  • app/ibc_test.go
Additional comments: 23
CHANGELOG.md (1)
  • 74-77: The changelog correctly documents the introduction of MsgShiftPegMultiplier and MsgShiftSwapInvariant as state machine breaking changes, which aligns with the summary provided. The entries are clear and specify the pull request numbers for reference.
app/keepers.go (10)
  • 241-249: The change to store the result of authtypes.NewModuleAddress(govtypes.ModuleName).String() in govModuleAddr and use it in the ConsensusParamsKeeper initialization is correctly implemented.

  • 275-286: The change to store the result of authtypes.NewModuleAddress(govtypes.ModuleName).String() in govModuleAddr and use it in the BankKeeper initialization is correctly implemented.

  • 287-293: The change to store the result of authtypes.NewModuleAddress(govtypes.ModuleName).String() in govModuleAddr and use it in the stakingKeeper initialization is correctly implemented.

  • 298-304: > Note: This review was outside the patches, so it was mapped to the patch with the greatest overlap. Original lines [294-302]

The change to store the result of authtypes.NewModuleAddress(govtypes.ModuleName).String() in govModuleAddr and use it in the DistrKeeper initialization is correctly implemented.

  • 308-314: The change to store the result of authtypes.NewModuleAddress(govtypes.ModuleName).String() in govModuleAddr and use it in the crisisKeeper initialization is correctly implemented.

  • 327-331: The change to store the result of authtypes.NewModuleAddress(govtypes.ModuleName).String() in govModuleAddr and use it in the upgradeKeeper initialization is correctly implemented.

  • 337-341: The change to store the result of authtypes.NewModuleAddress(govtypes.ModuleName).String() in govModuleAddr and use it in the slashingKeeper initialization is correctly implemented.

  • 443-448: The change to store the result of authtypes.NewModuleAddress(govtypes.ModuleName).String() in govModuleAddr and use it in the WasmKeeper initialization is correctly implemented.

  • 451-453: The change to store the result of authtypes.NewModuleAddress(govtypes.ModuleName).String() in govModuleAddr and use it in the DevGasKeeper initialization is correctly implemented.

  • 553-557: The change to store the result of authtypes.NewModuleAddress(govtypes.ModuleName).String() in govModuleAddr and use it in the GovKeeper initialization is correctly implemented.

wasmbinding/wasmbin_test.go (2)
  • 21-23: The addition of the init function to set a specific prefix is a critical change. Verify that this does not interfere with the initialization sequence of other packages or the global state.

  • 25-27: The TestSetupContracts function appears to be correctly setting up the contracts for testing. Ensure that the unchanged status of this function is consistent with the intended behavior and that the function interacts correctly with the new init function.

x/perp/v2/integration/action/position.go (4)
  • 13-18: The addition of the "perpkeeper" import aligns with the summary.

  • 344-357: The refactoring of the partialClose method to use MsgPartialClose and PartialClose method on perpkeeper.MsgServerImpl is consistent with the summary.

  • 376-390: The refactoring of the partialCloseFails method to use MsgPartialClose and PartialClose method on perpkeeper.MsgServerImpl is consistent with the summary.

  • 396-403: The correction of the spelling of the "expectedErr" parameter in the PartialCloseFails function signature is consistent with the summary.

x/perp/v2/keeper/msg_server.go (1)
  • 197-218: Verify that proper access control is implemented for the new admin-only functions ShiftPegMultiplier and ShiftSwapInvariant to ensure that only sudoers can call them.
x/perp/v2/keeper/msg_server_test.go (4)
  • 17-22: The import alias change from keeper to perpkeeper is correctly reflected in the code.

  • 324-330: The usage of the new alias perpkeeper in TestFailMsgServer is correct and consistent with the changes.

  • 372-377: The usage of the new alias perpkeeper in TestMsgChangeCollateralDenom is correct and consistent with the changes.

  • 447-452: The usage of the new alias perpkeeper in TestAllocateEpochRebates is correct and consistent with the changes.

x/perp/v2/module/genesis_test.go (1)
  • 87-90: The change from common.NibiruTeam to common.NIBIRU_TEAM should be verified across the entire codebase to ensure that all references to this constant are updated accordingly, and that the change does not break any functionality that relies on the specific case of the variable value.

@@ -78,6 +78,7 @@ func NewDefaultGenesisState(cdc codec.JSONCodec) GenesisState {
gen := ModuleBasics.DefaultGenesis(cdc)

authGenesis := new(authtypes.GenesisState)
authtypes.DefaultGenesisState()
Copy link
Contributor

Choose a reason for hiding this comment

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

The call to authtypes.DefaultGenesisState() is not being used. If the intention was to set the default genesis state for the auth module, it should be assigned to authGenesis:

- authtypes.DefaultGenesisState()
+ *authGenesis = authtypes.DefaultGenesisState()

Committable suggestion

IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
authtypes.DefaultGenesisState()
*authGenesis = authtypes.DefaultGenesisState()

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.

2 participants