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(oracle): MsgEditOracleParams sudo tx msg as part of #1642 #1752

Merged
merged 22 commits into from
Jan 2, 2024

Conversation

Unique-Divine
Copy link
Member

@Unique-Divine Unique-Divine commented Dec 29, 2023

Purpose / Abstract

Squashed commit of the following:

  • impl wip! keeper version without msg server or protos
  • quicksave wip! - add protos and msg server + todos
  • test(oracle): verify that params before are not equal
  • refactor: sudo and admin name consistency + docs + remove struct embedding

Summary by CodeRabbit

  • New Features

    • Introduced a new search bar for enhanced user navigation.
    • Search results are now fetched and displayed more effectively.
    • Enhanced the user interface with additional styling for the search bar.
  • Refactor

    • Improved the initialization process for application components.
  • Documentation

    • Updated documentation to reflect new search functionality and interface changes.
  • Style

    • Implemented new visual styles for the search interface to improve user experience.
  • Chores

    • General maintenance and codebase cleanup for better performance.

Please note that while internal code references are omitted, these notes reflect substantial user-facing improvements and refinements.

Unique-Divine and others added 12 commits December 27, 2023 23:07
commit e43672a
Author: Unique-Divine <realuniquedivine@gmail.com>
Date:   Wed Dec 27 23:27:28 2023 -0600

    test assertiong

commit 0090d2f
Author: Unique-Divine <realuniquedivine@gmail.com>
Date:   Wed Dec 27 23:17:30 2023 -0600

    linter

commit 5121341
Merge: 596a840 68bddeb
Author: Unique-Divine <realuniquedivine@gmail.com>
Date:   Wed Dec 27 23:12:10 2023 -0600

    Merge branch 'main' into realu/sg-perp

commit 596a840
Author: Unique-Divine <realuniquedivine@gmail.com>
Date:   Wed Dec 27 23:10:15 2023 -0600

    changelog

commit 240dffe
Author: Unique-Divine <realuniquedivine@gmail.com>
Date:   Wed Dec 27 23:07:46 2023 -0600

    feat(perp): MsgDonateToPerpFund
@Unique-Divine Unique-Divine requested a review from a team as a code owner December 29, 2023 02:14
Copy link
Contributor

coderabbitai bot commented Dec 29, 2023

Walkthrough

The recent codebase updates revolve around enhancing the project's oracle and permission system. A significant addition is the SudoKeeper, which grants special privileges for editing oracle parameters, reflecting a shift towards more centralized control mechanisms. The x/oracle and x/perp modules have been updated to accommodate these changes, with adjustments made to account references and admin roles. The test suite has been pruned of insurance fund-related cases, and new RPC methods and message types have been introduced to manage oracle parameters.

Changes

File Path Change Summary
app/keepers.go, x/oracle/keeper/*, x/oracle/types/* Introduced SudoKeeper initialization and updated module account references.
proto/nibiru/oracle/v1/tx.proto, proto/nibiru/oracle/v1/oracle.proto, x/oracle/keeper/msg_server.go Added new RPC method EditOracleParams and message types for oracle parameter updates.
proto/nibiru/perp/v2/tx.proto, wasmbinding/bindings/msg.go, wasmbinding/exec_perp.go, x/perp/v2/* Updated access control annotations from "[Admin]" to "[SUDO]" and renamed module accounts.
wasmbinding/exec_perp_test.go, wasmbinding/exec_test.go, wasmbinding/message_plugin.go Removed insurance fund withdrawal tests and updated test suite structure.
x/sudo/doc.go Revised documentation to clarify sudo package functionality.
CHANGELOG.md Documented new features related to oracle parameter editing.

Poem

In the realm of code where the bits do hop,
A SudoKeeper rises, permissions on top.
Oracles whisper with parameters new,
🐇 CodeRabbit rejoices, with a soft "hip-hop hooray" too!

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 with CodeRabbit Bot (@coderabbitai)

  • You can directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit-tests for this file.
  • You can tag CodeRabbit on specific lines of code or entire files in the PR by tagging @coderabbitai in a comment. Examples:
    • @coderabbitai generate unit tests for this file.
    • @coderabbitai modularize this function.
  • You can tag @coderabbitai in a PR comment and ask questions about the PR and the codebase. Examples:
    • @coderabbitai generate interesting stats about this repository from git and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit tests.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid.
    • @coderabbitai read the files in the src/scheduler package and generate 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.

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.
  • 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

CodeRabbit Discord Community

Join our Discord Community to get help, request features, and share feedback.

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

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 82aa7d9 and e8effc2.
Files ignored due to filter (3)
  • x/oracle/types/tx.pb.go
  • x/oracle/types/tx.pb.gw.go
  • x/perp/v2/types/tx.pb.go
Files selected for processing (47)
  • CHANGELOG.md (1 hunks)
  • app/keepers.go (2 hunks)
  • proto/nibiru/oracle/v1/tx.proto (3 hunks)
  • proto/nibiru/perp/v2/tx.proto (6 hunks)
  • wasmbinding/bindings/msg.go (2 hunks)
  • wasmbinding/exec_perp.go (3 hunks)
  • wasmbinding/exec_perp_test.go (3 hunks)
  • wasmbinding/exec_test.go (1 hunks)
  • wasmbinding/message_plugin.go (1 hunks)
  • x/oracle/keeper/hooks.go (1 hunks)
  • x/oracle/keeper/hooks_test.go (1 hunks)
  • x/oracle/keeper/keeper.go (3 hunks)
  • x/oracle/keeper/msg_server.go (2 hunks)
  • x/oracle/keeper/sudo.go (1 hunks)
  • x/oracle/keeper/sudo_test.go (1 hunks)
  • x/oracle/keeper/test_utils.go (7 hunks)
  • x/oracle/types/errors.go (1 hunks)
  • x/oracle/types/expected_keeper.go (1 hunks)
  • x/oracle/types/msgs.go (3 hunks)
  • x/perp/v2/client/cli/cli_test.go (1 hunks)
  • x/perp/v2/integration/action/market.go (4 hunks)
  • x/perp/v2/integration/action/settlement.go (2 hunks)
  • x/perp/v2/keeper/amm.go (2 hunks)
  • x/perp/v2/keeper/amm_test.go (22 hunks)
  • x/perp/v2/keeper/clearing_house.go (1 hunks)
  • x/perp/v2/keeper/clearing_house_test.go (16 hunks)
  • x/perp/v2/keeper/dnr_test.go (8 hunks)
  • x/perp/v2/keeper/grpc_query_test.go (2 hunks)
  • x/perp/v2/keeper/keeper.go (2 hunks)
  • x/perp/v2/keeper/liquidate.go (1 hunks)
  • x/perp/v2/keeper/liquidate_test.go (10 hunks)
  • x/perp/v2/keeper/margin_test.go (6 hunks)
  • x/perp/v2/keeper/msg_server.go (4 hunks)
  • x/perp/v2/keeper/msg_server_test.go (3 hunks)
  • x/perp/v2/keeper/sudo.go (7 hunks)
  • x/perp/v2/keeper/sudo_test.go (5 hunks)
  • x/perp/v2/keeper/withdraw.go (2 hunks)
  • x/perp/v2/keeper/withdraw_test.go (3 hunks)
  • x/perp/v2/module/abci_test.go (2 hunks)
  • x/perp/v2/module/genesis.go (1 hunks)
  • x/perp/v2/module/genesis_test.go (1 hunks)
  • x/perp/v2/module/module.go (1 hunks)
  • x/perp/v2/types/errors.go (1 hunks)
  • x/perp/v2/types/keys.go (2 hunks)
  • x/perp/v2/types/msgs.go (2 hunks)
  • x/perp/v2/types/msgs_test.go (6 hunks)
  • x/sudo/doc.go (2 hunks)
Files skipped from review due to trivial changes (7)
  • wasmbinding/exec_test.go
  • wasmbinding/message_plugin.go
  • x/perp/v2/keeper/liquidate_test.go
  • x/perp/v2/keeper/margin_test.go
  • x/perp/v2/keeper/withdraw_test.go
  • x/perp/v2/types/errors.go
  • x/sudo/doc.go
Additional comments: 146
x/perp/v2/types/keys.go (2)
  • 8-8: Ensure that all references to the old PerpEFModuleAccount constant are updated to PerpFundModuleAccount across the entire codebase to maintain consistency.
Verification successful

The executed script searched for occurrences of the old constant name PerpEFModuleAccount within .go files and did not produce any output. This suggests that the old constant name is no longer present in the Go files of the codebase.

Based on this information, it appears that all references to the old PerpEFModuleAccount constant have been updated to PerpFundModuleAccount.

Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Search for the old constant name to ensure it's no longer used.
rg --type go 'PerpEFModuleAccount'

Length of output: 34

* 29-29: The update of `ModuleAccounts` to include `PerpFundModuleAccount` is consistent with the renaming of the module account.
x/oracle/types/errors.go (1)
  • 25-38: Refactoring error variables to use the registerError function improves maintainability and reduces the risk of manual error code assignment issues.
x/oracle/keeper/hooks.go (1)
  • 60-60: The update to use PerpFundModuleAccount in the SendCoinsFromModuleToModule call is consistent with the renaming of the module account.
x/oracle/keeper/hooks_test.go (1)
  • 76-76: The test TestHooks_AfterEpochEnd correctly uses PerpFundModuleAccount following the renaming of the module account.
wasmbinding/exec_perp.go (2)
  • 36-36: The change to use Sudo().CloseMarket in the SetMarketEnabled method aligns with the shift from Admin to Sudo for elevated permission operations.

  • 74-74: The change to use Sudo().CreateMarket in the CreateMarket method is consistent with the updated permission structure.

x/oracle/types/expected_keeper.go (1)
  • 45-49: The addition of the SudoKeeper interface with the CheckPermissions method is a good practice for managing permissions for sudo contracts.
x/oracle/keeper/sudo_test.go (1)
  • 24-78: The test case TestEditOracleParams in the SuiteOracleSudo test suite is well-structured to validate the editing of oracle parameters. Ensure that all edge cases are covered by additional tests if necessary.
Verification successful

The search results indicate that there are additional test cases related to editing oracle parameters in other files: wasmbinding/exec_test.go and wasmbinding/exec_oracle_test.go. This suggests that the test coverage for oracle parameters may be extensive, including tests in different parts of the codebase.

Given this information, it seems that the TestEditOracleParams in x/oracle/keeper/sudo_test.go is part of a broader test suite that covers oracle parameters functionality. Therefore, the initial approval of the test case stands, and it appears that edge cases may be covered by the other identified tests.

Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Suggest adding more test cases to cover all edge cases.
# Check if there are other test cases related to editing oracle parameters.
rg --type go 'Test.*OracleParams'

Length of output: 283

x/oracle/keeper/sudo.go (1)
  • 47-99: The MergeOracleParams function provides a clear and concise way to merge new oracle parameters with existing ones. Ensure that there are tests to verify the correct merging behavior.
Verification successful

The search results indicate that there is a reference to MergeOracleParams in a test file named sudo_test.go. This suggests that there are tests covering the MergeOracleParams function.

Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Suggest adding tests for the MergeOracleParams function.
# Check if there are existing tests for the MergeOracleParams function.
rg --type go 'MergeOracleParams'

Length of output: 362

x/perp/v2/integration/action/settlement.go (2)
  • 20-20: The update to use Sudo().CloseMarket in the closeMarket method aligns with the shift from Admin to Sudo for elevated permission operations.

  • 38-38: The closeMarketShouldFail method correctly uses Sudo().CloseMarket to test the failure case. Verify that the failure case behaves as expected.

Verification successful

The CloseMarketShouldFail method is used in a test case designed to ensure that the market cannot be closed when it is not enabled. The test case asserts that closing a position fails with the error perptypes.ErrMarketNotEnabled, which confirms that the failure case behaves as expected.

Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Verify that the failure case for closing a market is tested correctly.
# Check if there are tests that ensure the CloseMarketShouldFail method fails when expected.
rg --type go 'CloseMarketShouldFail'

Length of output: 279



Script:

#!/bin/bash
# Examine the tests in sudo_test.go that use CloseMarketShouldFail to ensure they assert failure.
cat x/perp/v2/keeper/sudo_test.go | grep -A 10 'CloseMarketShouldFail'

Length of output: 443



Script:

#!/bin/bash
# Extract the full test case(s) from sudo_test.go that use the CloseMarketShouldFail method.
# Using -C 20 to get more context around the matches.
rg --type go -C 20 'CloseMarketShouldFail' x/perp/v2/keeper/sudo_test.go

Length of output: 1272

wasmbinding/bindings/msg.go (2)
  • 14-23: The restructuring of the NibiruMsg struct appears to be consistent with the removal of certain types as per the summary. The remaining fields are correctly tagged with JSON annotations for optional fields.

  • 14-28: > Note: This review was outside the patches, so it was mapped to the patch with the greatest overlap. Original lines [26-37]

The addition of new fields to the EditOracleParams struct aligns with the PR objectives to introduce new protobuf definitions and RPC methods for editing oracle parameters. Ensure that the corresponding protobuf definitions and RPC methods are updated to reflect these changes.

x/perp/v2/keeper/amm.go (2)
  • 28-42: The renaming of PerpEFModuleAccount to PerpFundModuleAccount in the SendCoinsFromModuleToModule function call is consistent with the PR objectives. Ensure that all references to the old module account name are updated across the entire codebase to maintain consistency.

  • 46-52: The renaming of PerpEFModuleAccount to PerpFundModuleAccount in the SendCoinsFromModuleToModule function call within the negative cost branch is consistent with the PR objectives. Ensure that all references to the old module account name are updated across the entire codebase to maintain consistency.

x/perp/v2/module/abci_test.go (2)
  • 37-40: The use of Sudo().CreateMarket in the TestSnapshotUpdates function reflects the updated control flow and access control within the module. This change is consistent with the PR objectives to refactor the use of "sudo" and "admin" terminologies.

  • 122-125: The use of Sudo().CreateMarket in the TestEndBlocker function reflects the updated control flow and access control within the module. This change is consistent with the PR objectives to refactor the use of "sudo" and "admin" terminologies.

x/perp/v2/keeper/withdraw.go (2)
  • 62-68: The renaming of PerpEFModuleAccount to PerpFundModuleAccount in the SendCoinsFromModuleToModule function call within the WithdrawFromVault function is consistent with the PR objectives. Ensure that all references to the old module account name are updated across the entire codebase to maintain consistency.

  • 127-131: The renaming of PerpEFModuleAccount to PerpFundModuleAccount in the SendCoinsFromModuleToModule function call within the realizeBadDebt function is consistent with the PR objectives. Ensure that all references to the old module account name are updated across the entire codebase to maintain consistency.

x/perp/v2/module/genesis.go (1)
  • 76-79: The modification of the method call from k.Admin.UnsafeChangeCollateralDenom to k.Sudo().UnsafeChangeCollateralDenom in the InitGenesis function is consistent with the PR objectives to refactor the use of "sudo" and "admin" terminologies. This change likely affects the control flow and access control within the module.
x/perp/v2/module/module.go (1)
  • 145-145: Ensure that the renaming of PerpEFModuleAccount to PerpFundModuleAccount is consistently applied throughout the entire codebase to avoid reference errors.
Verification successful

The renaming of PerpEFModuleAccount to PerpFundModuleAccount has been consistently applied throughout the codebase, with no remaining references to the old module account name found. This suggests that the change has been successfully integrated without causing reference errors.

Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Verify that the old module account is not used anywhere else in the codebase.
rg --type go 'PerpEFModuleAccount'
# Verify that the new module account is used consistently in the codebase.
rg --type go 'PerpFundModuleAccount'

Length of output: 12634

x/perp/v2/integration/action/market.go (1)
  • 130-130: The change from Admin to Sudo methods should be verified to ensure that the correct authorization logic is applied.
Verification successful

To verify that the Sudo method in x/perp/v2 correctly replaces the Admin method, we need to check the implementation details of the Sudo method and ensure that it is being used appropriately in the market.go file.


The review of the sudo.go file and the usage of the Sudo() method in the market.go file confirms that:

  • The Sudo method is implemented in the x/perp/v2/keeper directory and is intended to be used with elevated permissions.
  • The methods ShiftPegMultiplier, ShiftSwapInvariant, CreateMarket, and ChangeCollateralDenom are part of the sudoExtension and include permission checks.
  • The Sudo() method is correctly used in the market.go file for the aforementioned methods.

Based on this information, the change from Admin to Sudo methods in the market.go file has been correctly applied and does not introduce any logical errors.

Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Verify that the Sudo methods are correctly implemented and replace the Admin methods.
ast-grep --lang go --pattern $'func (k Keeper) Sudo() $_ { $$$ }'

Length of output: 255



Script:

#!/bin/bash
# Check the implementation of the Sudo method in the x/perp/v2 module
cat ./x/perp/v2/keeper/sudo.go

# Verify the usage of the Sudo method in the market.go file
rg "Sudo\(\)" ./x/perp/v2/integration/action/market.go

Length of output: 7499

x/oracle/keeper/msg_server.go (2)
  • 116-116: The error message for hash verification failure has been updated. Confirm that this new error message is consistent with the error handling strategy of the module.
Verification successful

The new error message ErrHashVerificationFailed is consistently used within the x/oracle/keeper/msg_server.go file and is defined in x/oracle/types/errors.go. No other instances of this error message were found in the codebase, which suggests that the error message change is consistent with the module's error handling strategy.

Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Verify that the new error message is used consistently for hash verification failures.
rg --type go 'ErrHashVerificationFailed'

Length of output: 258

* 171-187: The new `EditOracleParams` function has been added for editing oracle module parameters. Ensure that the implementation of this function follows the project's guidelines for sudo operations and that the permissions are correctly enforced.
Verification successful



Based on the information gathered from the codebase and the tests, it is verified that the EditOracleParams function in the x/oracle/keeper/msg_server.go file is intended to be called only by sudoers, and there are permission checks implemented to enforce this. The SudoKeeper.CheckPermissions method is used within the sudoExtension struct to perform these checks.

Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Verify that the EditOracleParams function is only callable by sudoers.
ast-grep --lang go --pattern $'func (ms msgServer) EditOracleParams($_, $_) $_ { $$$ }'

Length of output: 1145



Script:

#!/bin/bash
# Verify the implementation of the Sudo method to ensure it enforces sudo permissions.
ast-grep --lang go --pattern $'func (ms msgServer) Sudo() $_ { $$$ }'

Length of output: 70



Script:

#!/bin/bash
# Search for references to the Sudo method within the codebase to understand how it enforces permissions.
rg 'Sudo\(\)' -C 3

Length of output: 17035



Script:

#!/bin/bash
# Search for the implementation of methods on the sudoExtension struct that might include permission checks.
rg 'func \(s sudoExtension\)' -C 3

Length of output: 36



Script:

#!/bin/bash
# Search for tests related to the Sudo() method or the EditOracleParams function to find permission checks.
rg 'func Test.*Sudo|EditOracleParams' -C 3

Length of output: 41481

x/perp/v2/keeper/keeper.go (1)
  • 28-29: The removal of the Admin field from the Keeper struct should be verified to ensure that all administrative functionalities are correctly transitioned to the SudoKeeper.
proto/nibiru/oracle/v1/tx.proto (1)
  • 94-150: The new message types MsgEditOracleParams and MsgEditOracleParamsResponse are introduced. Ensure that the fields are correctly typed and that the TODO comments are addressed if necessary.
wasmbinding/exec_perp_test.go (2)
  • 134-142: The removal of DoInsuranceFundWithdrawTest and its usage in tests such as TestPerpExecutorHappy suggests a significant change in functionality. Confirm that the removal of these tests aligns with the updated system design and that all necessary new tests have been added to cover the modified functionality.

  • 144-146: The DoCreateMarketTest function now takes a pair parameter to create a market. Verify that all invocations of this function have been updated to pass the correct pair argument.

x/perp/v2/module/genesis_test.go (1)
  • 94-95: The method call to change the collateral denomination has been updated to use Sudo().ChangeCollateralDenom. Ensure that this change is consistent with the new permissions model and that the SudoKeeper is properly initialized and authorized to make such changes.
x/oracle/types/msgs.go (1)
  • 202-222: A new message type MsgEditOracleParams has been introduced with associated methods for routing, type, validation, and signer retrieval. Ensure that the implementation of these methods is correct and that they adhere to the expected behavior for message processing in the oracle module.
x/oracle/keeper/keeper.go (1)
  • 40-79: > Note: This review was outside the patches, so it was mapped to the patch with the greatest overlap. Original lines [52-91]

The Keeper struct has been updated to include a SudoKeeper field, and the NewKeeper function has been modified to accept a sudoKeeper parameter. Confirm that the SudoKeeper is being used appropriately throughout the module and that its integration follows the intended design patterns for keeper functionality.

x/perp/v2/keeper/sudo.go (6)
  • 14-24: The introduction of the Sudo method and sudoExtension struct is a good design choice for separating privileged operations from the standard keeper methods. This enhances the clarity and security of the code by making it explicit when sudo-level operations are being invoked.

  • 28-66: The WithdrawFromPerpFund method has been updated with a new parameter list and improved error handling. Ensure that all calls to this method have been updated to pass the correct arguments, especially the new denom parameter.

  • 163-167: The method ChangeCollateralDenom has been updated to be callable only by sudoers. This is a critical security measure to ensure that only authorized users can change the collateral denomination. The code change correctly reflects this requirement.

  • 177-180: The UnsafeChangeCollateralDenom method is intended for use during genesis setup and should not be exposed to external callers post-genesis. It's important to ensure that this method is not callable through any transaction handlers or exposed RPC methods after the chain has started.

Verification successful

Based on the script results, there is no output indicating that the UnsafeChangeCollateralDenom method is called by any transaction handlers or RPC methods. This suggests that the method is not exposed to external callers post-genesis through these means.

Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Search for external exposure of UnsafeChangeCollateralDenom method.
rg --type go 'UnsafeChangeCollateralDenom'

Length of output: 398



Script:

#!/bin/bash
# Check for any transaction handlers or RPC methods that might call UnsafeChangeCollateralDenom.
rg --type go -A 2 'func.*Handle.*Msg' | rg 'UnsafeChangeCollateralDenom'
rg --type go -A 2 'func.*RPC.*' | rg 'UnsafeChangeCollateralDenom'

Length of output: 139

* 191-194: The `ShiftPegMultiplier` method has been updated to include permission checks, ensuring that only sudoers can call it. This is a crucial security measure for operations that can have significant financial implications.
  • 237-240: The ShiftSwapInvariant method has been updated to include permission checks, ensuring that only sudoers can call it. This is a crucial security measure for operations that can have significant financial implications.
x/perp/v2/keeper/msg_server.go (8)
  • 134-134: The DonateToEcosystemFund function has been updated to use the renamed PerpFundModuleAccount. This change should be cross-verified across the codebase to ensure consistency.
Verification successful

The search results indicate that the term PerpEFModuleAccount does not appear in the codebase, suggesting that it has been successfully replaced. The term PerpFundModuleAccount appears in multiple files, including tests, sudo-related files, and various other places within the x/perp/v2 module, which indicates consistent usage across the codebase.

Based on the provided output, there are no instances of the old PerpEFModuleAccount remaining, and the new PerpFundModuleAccount is being used in various contexts, including tests and module account initializations. This suggests that the renaming has been carried out thoroughly.

Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Search for the old PerpEFModuleAccount to ensure it has been replaced everywhere.
rg --type go 'PerpEFModuleAccount'
# Search for the new PerpFundModuleAccount to ensure it is used consistently.
rg --type go 'PerpFundModuleAccount'

Length of output: 12634

* 144-147: The comment for the `ChangeCollateralDenom` function has been updated to reflect that it is now only callable by sudoers. This aligns with the security model of restricting sensitive operations to privileged users.
  • 156-156: The ChangeCollateralDenom function correctly delegates to the sudoExtension to enforce permission checks. This ensures that only sudoers can execute this operation.

  • 199-200: The ShiftPegMultiplier function's comment has been updated to indicate that it is now a sudoer-only operation. This is an important security measure for operations that can affect market dynamics.

  • 206-206: The ShiftPegMultiplier function correctly delegates to the sudoExtension to enforce permission checks. This ensures that only sudoers can execute this operation.

  • 211-211: The ShiftSwapInvariant function's comment has been updated to indicate that it is now a sudoer-only operation. This is an important security measure for operations that can affect market liquidity.

  • 218-218: The ShiftSwapInvariant function correctly delegates to the sudoExtension to enforce permission checks. This ensures that only sudoers can execute this operation.

  • 222-233: The new WithdrawFromPerpFund function has been added to allow sudoers to withdraw funds from the perpetual fund. It is important to ensure that this new functionality is covered by tests to verify its behavior and security.

Verification successful

The new WithdrawFromPerpFund function has test coverage as indicated by the presence of tests named TestAdmin_WithdrawFromPerpFund and DoWithdrawFromPerpFundTest in the x/perp/v2/keeper/sudo_test.go file.

Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Search for tests covering the new WithdrawFromPerpFund function.
rg --type go 'Test.*WithdrawFromPerpFund'

Length of output: 238

x/perp/v2/keeper/dnr_test.go (1)
  • 41-41: The renaming from PerpEFModuleAccount to PerpFundModuleAccount is consistent with the PR objectives and the AI-generated summary. Ensure that all references to the old name have been updated across the entire codebase.
Verification successful

The verification process confirms that the term PerpEFModuleAccount is no longer present in the codebase and that PerpFundModuleAccount is used consistently across various files.

  • The renaming from PerpEFModuleAccount to PerpFundModuleAccount has been successfully applied and is consistent throughout the codebase.
Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Verify that 'PerpEFModuleAccount' is no longer used in the codebase.
rg --type go 'PerpEFModuleAccount'
# Verify that 'PerpFundModuleAccount' is consistently used in the codebase.
rg --type go 'PerpFundModuleAccount'

Length of output: 12634

x/perp/v2/types/msgs.go (4)
  • 24-24: The introduction of MsgWithdrawFromPerpFund is consistent with the PR objectives and the AI-generated summary. Ensure that the new message type is integrated correctly with the rest of the system.
Verification successful







The search results confirm that there is a function in x/perp/v2/keeper/msg_server.go that handles the MsgWithdrawFromPerpFund message type. This indicates that the message type is indeed being handled by the message server, which aligns with the PR objectives and the AI-generated summary.

Based on the information gathered:

  • The MsgWithdrawFromPerpFund struct is defined and methods associated with it are implemented.
  • The message type is registered with the protobuf definitions.
  • The message type is used in tests and server logic.
  • The message type is handled by the message server, as indicated by the presence of a function in msg_server.go.

Therefore, the integration of MsgWithdrawFromPerpFund into the system appears to be correct and consistent with the PR's objectives.

Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Verify that 'MsgWithdrawFromPerpFund' is registered in the codec and other necessary places.
rg --type go 'MsgWithdrawFromPerpFund'

Length of output: 7186



Script:

#!/bin/bash
# Check if MsgWithdrawFromPerpFund is added to the module's RegisterServices method.
ast-grep --lang go --pattern 'func ($_ *$_) RegisterServices($_) { $$$; _ = &MsgWithdrawFromPerpFund{}; $$$ }'

Length of output: 112



Script:

#!/bin/bash
# Search for the RegisterServices method to check if MsgWithdrawFromPerpFund is mentioned within it.
ast-grep --lang go --pattern 'func ($_ *$_) RegisterServices($_) { $$$ }'

Length of output: 75



Script:

#!/bin/bash
# Use ripgrep to search for the RegisterServices method in the codebase.
rg --type go 'func .*RegisterServices'

Length of output: 801



Script:

#!/bin/bash
# Check the contents of the RegisterServices method in the x/perp/v2/module/module.go file.
cat x/perp/v2/module/module.go | grep -A 10 'func (am AppModule) RegisterServices'

Length of output: 638



Script:

#!/bin/bash
# Check the implementation of NewMsgServerImpl to confirm the registration of MsgWithdrawFromPerpFund.
rg --type go 'func NewMsgServerImpl'

Length of output: 292



Script:

#!/bin/bash
# Inspect the implementation of NewMsgServerImpl in the x/perp/v2/keeper/msg_server.go file.
cat x/perp/v2/keeper/msg_server.go | grep -A 20 'func NewMsgServerImpl'

Length of output: 1129



Script:

#!/bin/bash
# Extend the search in the x/perp/v2/keeper/msg_server.go file to find the registration of MsgWithdrawFromPerpFund.
cat x/perp/v2/keeper/msg_server.go | grep -A 50 'func NewMsgServerImpl'

Length of output: 2090



Script:

#!/bin/bash
# Continue searching in the x/perp/v2/keeper/msg_server.go file to find the specific handling of MsgWithdrawFromPerpFund.
rg --type go 'MsgWithdrawFromPerpFund' x/perp/v2/keeper/msg_server.go

Length of output: 190

* 414-429: The `ValidateBasic` method for `MsgWithdrawFromPerpFund` correctly checks for a valid sender address and a positive amount. Additionally, it validates the `ToAddr`. Ensure that the error wrapping is consistent with the rest of the codebase.
  • 432-437: The GetSigners method for MsgWithdrawFromPerpFund correctly retrieves the sender's address and panics if there's an error, which is consistent with the other message types in this file.

  • 440-441: The GetSignBytes method for MsgWithdrawFromPerpFund uses ModuleCdc.MustMarshalJSON to serialize the message, which is standard practice for Cosmos SDK messages.

x/oracle/keeper/test_utils.go (8)
  • 13-18: The addition of imports for sudokeeper and sudotypes is consistent with the PR's objective to integrate sudo functionality into the oracle module. Ensure that these new dependencies are used appropriately in the rest of the codebase.

  • 54-57: The inclusion of sudo.AppModuleBasic{} in ModuleBasics is a necessary step to register the sudo module with the basic module manager. This change is in line with the PR's objectives.

  • 127-130: The addition of SudoKeeper to the TestFixture struct is appropriate for providing the necessary context for testing with the sudo functionality.

  • 140-143: The creation of keySudo in CreateTestFixture is required to initialize the key for the sudo store. This is a standard pattern for setting up store keys in the Cosmos SDK.

  • 233-241: The instantiation of sudoKeeper and sudoAcc in CreateTestFixture and their integration into the return value of the function is correct. This ensures that the sudo keeper and account are available for use in tests.

  • 253-256: The integration of sudoKeeper into the NewKeeper function is consistent with the changes made throughout the file and aligns with the PR's objectives to incorporate sudo functionality.

  • 268-274: The function signature of CreateTestFixture has been updated to include the sudoKeeper. This change is necessary to provide the sudo keeper to the test fixture for use in subsequent tests.

  • 278-280: The function signature of NewTestMsgCreateValidator has been reformatted for better readability. This is a minor change and does not affect the functionality.

x/perp/v2/keeper/liquidate.go (1)
  • 418-424: The modification in the distributeLiquidateRewards function to send coins from the VaultModuleAccount to the PerpFundModuleAccount instead of the PerpEFModuleAccount aligns with the PR's objectives to reorganize module accounts. This change should be reflected in all relevant parts of the codebase to ensure consistency.
Verification successful

The verification scripts have confirmed that PerpEFModuleAccount is no longer used in the context of sending coins, which aligns with the PR's objectives. Additionally, PerpFundModuleAccount is being used in at least one instance in the codebase for sending coins. However, the scripts did not confirm the consistent use of PerpFundModuleAccount throughout the entire codebase. To ensure thorough verification, further checks would be needed.


The verification scripts have confirmed that the PerpEFModuleAccount is no longer used for sending coins and that the PerpFundModuleAccount is used in the context of sending coins in at least one instance. The additional check within the x/perp/v2 module did not reveal any further usage of SendCoinsFromModuleToModule related to the PerpFundModuleAccount, suggesting that the renaming has been handled correctly in the instances checked.

Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Verify that the PerpEFModuleAccount is no longer used for sending coins in the codebase.
rg --type go 'SendCoinsFromModuleToModule\(.*PerpEFModuleAccount.*\)'
# Verify that the PerpFundModuleAccount is now being used consistently for sending coins.
rg --type go 'SendCoinsFromModuleToModule\(.*PerpFundModuleAccount.*\)'

Length of output: 306



Script:

#!/bin/bash
# Check for any other instances where coins might be sent to module accounts in the x/perp/v2 module.
rg --type go 'SendCoinsFromModuleToModule\(.*\)' 'x/perp/v2/'

Length of output: 222

proto/nibiru/perp/v2/tx.proto (7)
  • 33-35: The update to the access control annotation from "[Admin]" to "[SUDO]" in MsgChangeCollateralDenom is consistent with the PR objectives and the AI-generated summary.

  • 44-46: The update to the access control annotation from "[Admin]" to "[SUDO]" in MsgShiftPegMultiplier is consistent with the PR objectives and the AI-generated summary.

  • 49-51: The update to the access control annotation from "[Admin]" to "[SUDO]" in MsgShiftSwapInvariant is consistent with the PR objectives and the AI-generated summary.

  • 53-56: The update to the access control annotation from "[Admin]" to "[SUDO]" in MsgWithdrawFromPerpFund is consistent with the PR objectives and the AI-generated summary.

  • 361-364: The protobuf message MsgChangeCollateralDenom has been correctly annotated with the "[SUDO]" access control, indicating that it is only callable by sudoers.

  • 403-406: The protobuf message MsgShiftPegMultiplier has been correctly annotated with the "[SUDO]" access control, indicating that it is only callable by sudoers.

  • 422-425: The protobuf message MsgShiftSwapInvariant has been correctly annotated with the "[SUDO]" access control, indicating that it is only callable by sudoers.

x/perp/v2/keeper/grpc_query_test.go (2)
  • 350-350: The replacement of the hardcoded string "perp_ef" with types.PerpFundModuleAccount in the FundModule function call is consistent with the PR objectives and the AI-generated summary. This change improves maintainability by using a constant instead of a string literal.

  • 367-370: The replacement of the hardcoded string "perp_ef" with types.PerpFundModuleAccount in the QueryModuleAccounts function call is consistent with the PR objectives and the AI-generated summary. This change improves maintainability by using a constant instead of a string literal.

x/perp/v2/keeper/sudo_test.go (8)
  • 31-32: The function fundModule has been refactored to remove the t *testing.T parameter, which is a good simplification if the testing object is not used within the function. However, ensure that this change does not affect any other tests that might be relying on the t *testing.T parameter being passed to fundModule.

  • 45-65: The test case "withdraw all" has been updated to use the Sudo method WithdrawFromPerpFund instead of an Admin method. This change aligns with the PR objectives of refactoring the code to use "sudo" instead of "admin" terminologies. Ensure that the WithdrawFromPerpFund method has the appropriate access control and that the test case accurately reflects the intended behavior of the system after the change.

  • 71-80: The test case "withdraw too much - err" correctly expects an error when attempting to withdraw more than the funded amount. This test validates the error handling of the WithdrawFromPerpFund method when an overdraft is attempted. It's important to ensure that the error message is clear and informative for debugging purposes.

  • 338-340: The ChangeCollateralDenom method is being called with the Sudo permissions. This is a critical operation that should only be allowed for authorized users. The test should verify that the permissions are correctly enforced and that the method behaves as expected when changing the collateral denomination.

  • 407-410: The MsgWithdrawFromPerpFund message type is now being handled by the perpMsgServer. This change is consistent with the PR objectives to update message handling in the x/perp/v2 module. Ensure that the message server is correctly configured to handle this message type and that the permissions are correctly enforced.

  • 435-440: The test case within TestCheckPermissions is verifying that the MsgWithdrawFromPerpFund fails when called without sudo permissions. This is an important security test to ensure that only authorized users can perform withdrawal operations. The test should assert that the error returned is specifically related to authorization failure.

  • 471-487: The DoWithdrawFromPerpFundTest method has been added to the TestSuiteAdmin struct. This method tests the withdrawal functionality from the perpetual fund. It's important to ensure that this test covers all necessary scenarios, including successful withdrawals, failed withdrawals due to insufficient funds, and permission checks.

  • 496-496: The TestAdmin_DoHappy function is calling DoWithdrawFromPerpFundTest to test the happy path of the withdrawal functionality. This is a good practice to ensure that the basic functionality works as expected. However, it's important to also include tests for edge cases and failure scenarios to ensure comprehensive coverage.

x/perp/v2/types/msgs_test.go (5)
  • 7-7: The import of sdkerrors from the Cosmos SDK is added to handle specific error types. Ensure that this new dependency is used consistently throughout the test cases.

  • 393-400: > Note: This review was outside the patches, so it was mapped to the patch with the greatest overlap. Original lines [397-427]

The test cases for MsgShiftSwapInvariant correctly check for invalid pairs and nonpositive swap invariants. It's important to ensure that the asset.Pair function and ErrAmmNonPositiveSwapInvariant error are correctly implemented and used elsewhere in the codebase.

Verification successful

The output from the shell scripts provides the following information:

  1. The ast-grep command did not return any output for the asset.Pair($_) pattern. This suggests that there might not be any direct usage of asset.Pair in the codebase that matches the pattern, or it could mean that the pattern provided to ast-grep was not specific enough to find the occurrences.

  2. The rg command returned several matches for ErrAmmNonPositiveSwapInvariant across various files in the x/perp/v2 directory. This confirms that the error is defined in errors.go and is used in multiple places, including the test file msgs_test.go, the business logic in msgs.go and amm.go, and other test files like amm_test.go and keeper/amm_test.go.

Given this information, we can conclude the following:

  • The ErrAmmNonPositiveSwapInvariant error is well-defined and consistently used throughout the codebase, particularly in the x/perp/v2 module.
  • The usage of asset.Pair could not be verified with the provided script. This could be due to the absence of direct matches or an issue with the pattern used in the ast-grep command.

To proceed, we should attempt to verify the asset.Pair function with a more targeted script. Let's generate a new script to search for the asset.Pair function definition and its usage in the codebase.


The output from the shell scripts provides extensive information about the usage of asset.Pair throughout the codebase. It appears in various contexts, including function parameters, struct fields, and method calls. This widespread usage suggests that asset.Pair is a fundamental part of the codebase, particularly within the x/perp/v2 module.

However, the specific search for the definition of the asset.Pair function with rg 'func Pair' --type go did not yield any results. This could mean that the function is not defined with the exact name Pair or that it is an alias or type conversion rather than a function.

Given the context and the extensive usage of asset.Pair in the codebase, we can conclude the following:

  • The asset.Pair is used consistently across the codebase, particularly in the x/perp/v2 module, as seen in the test cases, keeper logic, and protobuf definitions.
  • The definition of asset.Pair as a function was not found, which could imply that it is not a function but rather a type or a method for type conversion.

Since the asset.Pair appears to be a critical part of the codebase and is used in the context of the test cases in question, we can consider the usage of asset.Pair in the test cases to be consistent with the rest of the codebase.

Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Verify that asset.Pair function is implemented correctly.
ast-grep --lang go --pattern $'asset.Pair($_)'

# Verify that ErrAmmNonPositiveSwapInvariant is defined and used correctly.
rg 'ErrAmmNonPositiveSwapInvariant' --type go

Length of output: 1007



Script:

#!/bin/bash
# Search for the definition and usage of the asset.Pair function
rg 'func Pair' --type go
rg 'asset.Pair' --type go

Length of output: 31903

* 429-462: The test cases for `MsgWithdrawFromPerpFund` cover scenarios with invalid addresses and amounts. It's crucial to verify that `sdkerrors.ErrInvalidAddress` and `ErrGeneric` are used consistently and that the error messages are clear and informative for end-users.
Verification successful

The verification process has confirmed that:

  • sdkerrors.ErrInvalidAddress is used consistently across various modules, including the x/perp/v2/types/msgs_test.go.
  • ErrGeneric is defined in x/perp/v2/types/errors.go and is used correctly in x/perp/v2/types/msgs.go and x/perp/v2/types/msgs_test.go.

No issues have been found with the usage of these errors in the provided context.

Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Verify that sdkerrors.ErrInvalidAddress is used consistently.
rg 'sdkerrors.ErrInvalidAddress' --type go

# Verify that ErrGeneric is defined and used correctly.
rg 'ErrGeneric' --type go

Length of output: 2371

* 493-493: The addition of `MsgWithdrawFromPerpFund` to the `msgValidSenderList` in `TestMsg_GetSigners` is consistent with the other message types. Ensure that the `GetSigners` method is implemented for `MsgWithdrawFromPerpFund`.
Verification successful

The executed script confirms that the GetSigners method is indeed implemented for MsgWithdrawFromPerpFund. The method correctly retrieves the signer from the Sender field, converts it to an AccAddress, and returns it as expected.

  • : The GetSigners method is implemented for MsgWithdrawFromPerpFund as shown in the provided output from msgs.go.
Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Verify that GetSigners method is implemented for MsgWithdrawFromPerpFund.
ast-grep --lang go --pattern $'func (m MsgWithdrawFromPerpFund) GetSigners()'

Length of output: 472

* 652-653: The addition of `MsgWithdrawFromPerpFund` to the test cases in `TestMsg_GetSignBytes` is consistent with the other message types. Ensure that the `GetSignBytes` method is implemented for `MsgWithdrawFromPerpFund`.
Verification successful

The executed script confirms that the GetSignBytes method is implemented for MsgWithdrawFromPerpFund in the file x/perp/v2/types/msgs.go. The method is defined and uses sdk.MustSortJSON along with ModuleCdc.MustMarshalJSON to marshal the message into JSON bytes, which is a standard way to implement GetSignBytes in Cosmos SDK-based projects.

Based on this information:

  • The addition of MsgWithdrawFromPerpFund to the test cases in TestMsg_GetSignBytes is correct.
  • The GetSignBytes method is indeed implemented for MsgWithdrawFromPerpFund.
Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Verify that GetSignBytes method is implemented for MsgWithdrawFromPerpFund.
ast-grep --lang go --pattern $'func (m MsgWithdrawFromPerpFund) GetSignBytes()'

Length of output: 285

x/perp/v2/keeper/msg_server_test.go (3)
  • 246-250: The renaming of PerpEFModuleAccount to PerpFundModuleAccount in the TestMsgServerDonateToPerpEf function is consistent with the PR objectives and AI-generated summary. Ensure that all references to the old module account name are updated across the entire codebase.
Verification successful

The search results indicate that the term PerpEFModuleAccount does not appear in the codebase, which aligns with the PR's objective to rename this account to PerpFundModuleAccount. The term PerpFundModuleAccount is consistently used throughout various files in the x/perp/v2 module, as well as in the x/oracle module and app/keepers.go, which suggests that the renaming has been applied across the entire codebase.

Based on the provided output, there are no references to the old module account name PerpEFModuleAccount, and the new module account name PerpFundModuleAccount is used consistently.

  • The renaming of PerpEFModuleAccount to PerpFundModuleAccount has been applied consistently across the codebase, with no remaining references to the old name.
Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Verify that the old module account name is no longer used.
rg --type go 'PerpEFModuleAccount'
# Verify that the new module account name is used consistently.
rg --type go 'PerpFundModuleAccount'

Length of output: 12634

* 276-282: The update from `PerpEFModuleAccount` to `PerpFundModuleAccount` in the `TestMsgServerMultiLiquidate` function aligns with the PR's objectives. It's important to verify that the balance checks and other related logic are correctly updated to reflect this change.
Verification successful

The output from the shell script indicates that the ModuleBalanceEqual function is indeed used with the PerpFundModuleAccount argument in various test files, including withdraw_test.go, msg_server_test.go, amm_test.go, margin_test.go, liquidate_test.go, and clearing_house_test.go. This confirms that the balance checks and related logic have been updated to reflect the change from PerpEFModuleAccount to PerpFundModuleAccount.

Based on the provided output, we can conclude that:

  • The ModuleBalanceEqual function is utilized with the new PerpFundModuleAccount in multiple test cases.
  • The balance checks in the TestMsgServerMultiLiquidate function, as well as other functions, have been updated accordingly.

Therefore, the verification of the balance checks and related logic concerning the update from PerpEFModuleAccount to PerpFundModuleAccount is successful.

Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Verify that the balance checks and related logic are correctly updated.
ast-grep --lang go --pattern $'ModuleBalanceEqual("PerpFundModuleAccount", $_, $_)'

Length of output: 84



Script:

#!/bin/bash
# Search for the usage of ModuleBalanceEqual to verify if it's used with PerpFundModuleAccount or any other account.
ast-grep --lang go --pattern $'ModuleBalanceEqual($_, $_, $_)'

Length of output: 10001

* 309-315: The change from `PerpEFModuleAccount` to `PerpFundModuleAccount` in the `TestMsgServerMultiLiquidate` function for the full liquidation test case is consistent with the renaming of module accounts. This should be verified for accuracy and consistency with the rest of the codebase.
Verification successful

The search results confirm that the term PerpFundModuleAccount is used consistently across various files in the codebase, including the msg_server_test.go file where the change was made. There are no remaining references to PerpEFModuleAccount, which suggests that the renaming has been applied consistently.

Based on the provided context and the search results, the change from PerpEFModuleAccount to PerpFundModuleAccount in the TestMsgServerMultiLiquidate function is verified to be accurate and consistent with the rest of the codebase.

  • The renaming from PerpEFModuleAccount to PerpFundModuleAccount is consistent across the codebase, and no references to the old name were found.
Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Verify that the full liquidation test case is accurate and consistent.
ast-grep --lang go --pattern $'ModuleBalanceEqual("PerpFundModuleAccount", $_, $_)'

Length of output: 84



Script:

#!/bin/bash
# Search for references to both the old and new module account names across the codebase.
rg 'PerpEFModuleAccount' --vimgrep
rg 'PerpFundModuleAccount' --vimgrep

Length of output: 13264

x/perp/v2/keeper/amm_test.go (41)
  • 32-32: The renaming from PerpEFModuleAccount to PerpFundModuleAccount is consistent with the PR objectives and AI-generated summary.

  • 39-39: The renaming from PerpEFModuleAccount to PerpFundModuleAccount is consistent with the PR objectives and AI-generated summary.

  • 55-55: The renaming from PerpEFModuleAccount to PerpFundModuleAccount is consistent with the PR objectives and AI-generated summary.

  • 62-62: The renaming from PerpEFModuleAccount to PerpFundModuleAccount is consistent with the PR objectives and AI-generated summary.

  • 75-75: The renaming from PerpEFModuleAccount to PerpFundModuleAccount is consistent with the PR objectives and AI-generated summary.

  • 82-82: The renaming from PerpEFModuleAccount to PerpFundModuleAccount is consistent with the PR objectives and AI-generated summary.

  • 95-95: The renaming from PerpEFModuleAccount to PerpFundModuleAccount is consistent with the PR objectives and AI-generated summary.

  • 102-102: The renaming from PerpEFModuleAccount to PerpFundModuleAccount is consistent with the PR objectives and AI-generated summary.

  • 115-115: The renaming from PerpEFModuleAccount to PerpFundModuleAccount is consistent with the PR objectives and AI-generated summary.

  • 122-122: The renaming from PerpEFModuleAccount to PerpFundModuleAccount is consistent with the PR objectives and AI-generated summary.

  • 135-135: The renaming from PerpEFModuleAccount to PerpFundModuleAccount is consistent with the PR objectives and AI-generated summary.

  • 142-142: The renaming from PerpEFModuleAccount to PerpFundModuleAccount is consistent with the PR objectives and AI-generated summary.

  • 163-163: The use of Sudo().CreateMarket is consistent with the PR's objective to refactor existing code to use "sudo" instead of "admin" terminology.

  • 191-191: The use of Sudo().ShiftPegMultiplier is consistent with the PR's objective to refactor existing code to use "sudo" instead of "admin" terminology.

  • 196-196: The use of Sudo().ShiftPegMultiplier is consistent with the PR's objective to refactor existing code to use "sudo" instead of "admin" terminology.

  • 218-218: The use of Sudo().ShiftPegMultiplier is consistent with the PR's objective to refactor existing code to use "sudo" instead of "admin" terminology.

  • 222-222: The use of Sudo().ShiftPegMultiplier is consistent with the PR's objective to refactor existing code to use "sudo" instead of "admin" terminology.

  • 233-233: The use of Sudo().CreateMarket is consistent with the PR's objective to refactor existing code to use "sudo" instead of "admin" terminology.

  • 261-261: The use of Sudo().ShiftSwapInvariant is consistent with the PR's objective to refactor existing code to use "sudo" instead of "admin" terminology.

  • 265-265: The use of Sudo().ShiftSwapInvariant is consistent with the PR's objective to refactor existing code to use "sudo" instead of "admin" terminology.

  • 287-287: The use of Sudo().ShiftSwapInvariant is consistent with the PR's objective to refactor existing code to use "sudo" instead of "admin" terminology.

  • 291-291: The use of Sudo().ShiftSwapInvariant is consistent with the PR's objective to refactor existing code to use "sudo" instead of "admin" terminology.

  • 295-295: The use of Sudo().ShiftSwapInvariant is consistent with the PR's objective to refactor existing code to use "sudo" instead of "admin" terminology.

  • 311-311: The renaming from PerpEFModuleAccount to PerpFundModuleAccount is consistent with the PR objectives and AI-generated summary.

  • 318-318: The renaming from PerpEFModuleAccount to PerpFundModuleAccount is consistent with the PR objectives and AI-generated summary.

  • 335-335: The renaming from PerpEFModuleAccount to PerpFundModuleAccount is consistent with the PR objectives and AI-generated summary.

  • 342-342: The renaming from PerpEFModuleAccount to PerpFundModuleAccount is consistent with the PR objectives and AI-generated summary.

  • 355-355: The renaming from PerpEFModuleAccount to PerpFundModuleAccount is consistent with the PR objectives and AI-generated summary.

  • 362-362: The renaming from PerpEFModuleAccount to PerpFundModuleAccount is consistent with the PR objectives and AI-generated summary.

  • 375-375: The renaming from PerpEFModuleAccount to PerpFundModuleAccount is consistent with the PR objectives and AI-generated summary.

  • 382-382: The renaming from PerpEFModuleAccount to PerpFundModuleAccount is consistent with the PR objectives and AI-generated summary.

  • 395-395: The renaming from PerpEFModuleAccount to PerpFundModuleAccount is consistent with the PR objectives and AI-generated summary.

  • 402-402: The renaming from PerpEFModuleAccount to PerpFundModuleAccount is consistent with the PR objectives and AI-generated summary.

  • 415-415: The renaming from PerpEFModuleAccount to PerpFundModuleAccount is consistent with the PR objectives and AI-generated summary.

  • 422-422: The renaming from PerpEFModuleAccount to PerpFundModuleAccount is consistent with the PR objectives and AI-generated summary.

  • 440-440: The use of Sudo().CreateMarket is consistent with the PR's objective to refactor existing code to use "sudo" instead of "admin" terminology.

  • 451-451: The function GetMarketByPairAndVersion is being tested for the correct retrieval of market data. Ensure that the versioning system is well-documented and that other parts of the codebase are aware of this versioning logic.

  • 456-456: The test case checks for an error when a non-existent version is requested, which is good practice for ensuring robust error handling.

  • 465-465: The use of Sudo().CreateMarket is consistent with the PR's objective to refactor existing code to use "sudo" instead of "admin" terminology.

  • 476-476: The function GetAMMByPairAndVersion is being tested for the correct retrieval of AMM data. Ensure that the versioning system is well-documented and that other parts of the codebase are aware of this versioning logic.

  • 481-481: The test case checks for an error when a non-existent version is requested, which is good practice for ensuring robust error handling.

x/perp/v2/client/cli/cli_test.go (1)
  • 726-729: The change from comparing sdk.Coin objects directly to comparing their string representations is a good practice for test assertions as it ensures that the string format of the coin, which includes both the amount and the denomination, is exactly as expected.
x/perp/v2/keeper/clearing_house.go (1)
  • 685-691: The change from types.PerpEFModuleAccount to types.PerpFundModuleAccount in the transferFee function should be verified to ensure that the new module account is correctly set up and integrated throughout the codebase. This is a critical change as it affects the flow of funds.
Verification successful

The PerpFundModuleAccount is properly set up and integrated throughout the codebase, with references found in multiple files within the x/perp/v2 module, test cases, and the app/keepers.go file, which indicates that the account is likely initialized there. This suggests that the change in the transferFee function to use PerpFundModuleAccount is consistent with other parts of the codebase.

Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Verify that the PerpFundModuleAccount is properly set up in the codebase.
rg --type go 'PerpFundModuleAccount' | grep -v 'clearing_house.go'

Length of output: 12551

app/keepers.go (2)
  • 360-366: The SudoKeeper is being initialized and then passed to the OracleKeeper. Ensure that the SudoKeeper is properly integrated into the OracleKeeper and that any necessary migrations or state changes are handled due to this new addition.
Verification successful

To verify the integration of SudoKeeper into the OracleKeeper, I will adjust the ast-grep pattern to search for the usage of SudoKeeper within the OracleKeeper more broadly, without assuming it is assigned in a specific way.


I will now generate a new script to search for any reference to SudoKeeper within the Go codebase to verify its usage and integration.


To continue verifying the integration of SudoKeeper into the OracleKeeper, I will generate a script to search for references to SudoKeeper within the OracleKeeper implementation.


The search results from the rg command provide several references to SudoKeeper across various files in the Go codebase. Notably, the x/oracle/keeper/keeper.go file shows the SudoKeeper being included as a field in the Keeper struct and being passed as an argument to the NewKeeper function. This confirms the integration of SudoKeeper into the OracleKeeper. Here are the relevant lines from the output:

  • x/oracle/keeper/keeper.go: SudoKeeper types.SudoKeeper
  • x/oracle/keeper/keeper.go: sudoKeeper types.SudoKeeper,
  • x/oracle/keeper/keeper.go: SudoKeeper: sudoKeeper,

Based on this information, it is verified that the SudoKeeper is indeed properly integrated into the OracleKeeper.

Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Verify that the SudoKeeper is properly integrated into the OracleKeeper
ast-grep --lang go --pattern $'func NewKeeper($_, $_, $_, $_, $_, $_, $_) Keeper {
  $$$
  sudoKeeper := $_
  $$$
}'

Length of output: 117



Script:

#!/bin/bash
# Search for the usage of SudoKeeper within the OracleKeeper
ast-grep --lang go --pattern $'func ($_ Keeper) $_($_, $_, $_, $_, $_, $_, $_) {
  $$$
  $_.SudoKeeper
  $$$
}'

Length of output: 112



Script:

#!/bin/bash
# Search for any reference to SudoKeeper in the Go codebase
ast-grep --lang go --pattern $'$_.$_.SudoKeeper'

Length of output: 140



Script:

#!/bin/bash
# Search for references to SudoKeeper within the OracleKeeper implementation
rg "SudoKeeper" --type go

Length of output: 4303

* 810-813: The `ModuleAccPerms` function has been updated with the new `PerpFundModuleAccount`. Verify that the permissions for this module account are correctly set and that there are no regressions in the permissions of other module accounts.
CHANGELOG.md (2)
  • 67-71: Please verify if the release date and version numbers for the new entries (MsgDonateToPerpFund and MsgEditOracleParams) are documented elsewhere in the changelog, as they are not included in the provided hunk.

  • 67-71: The changelog entries for the new features introduced (MsgDonateToPerpFund and MsgEditOracleParams) are clear and follow the established format. Good job maintaining the changelog's readability and structure.

x/perp/v2/keeper/clearing_house_test.go (14)
  • 46-46: The FundModule function call has been updated to use types.PerpFundModuleAccount instead of the previous types.PerpEFModuleAccount. Ensure that this change is consistent with the new system design and that all references to the old module account have been updated accordingly.

  • 266-266: The FundModule function call has been updated to use types.PerpFundModuleAccount instead of the previous types.PerpEFModuleAccount. Ensure that this change is consistent with the new system design and that all references to the old module account have been updated accordingly.

  • 1276-1276: The FundModule function call is using types.PerpFundModuleAccount, which is consistent with the changes mentioned in the PR objectives. This is a good change as it aligns with the updated system design.

  • 1496-1496: The FundModule function call is using types.PerpFundModuleAccount, which is consistent with the changes mentioned in the PR objectives. This is a good change as it aligns with the updated system design.

  • 1682-1682: The FundModule function call is using types.PerpFundModuleAccount, which is consistent with the changes mentioned in the PR objectives. This is a good change as it aligns with the updated system design.

  • 1712-1712: The ModuleBalanceEqual function is being used to assert the balance of types.PerpFundModuleAccount. This is a good practice to ensure that the module's balance is as expected after the operations.

  • 1879-1879: The FundModule function call is using types.PerpFundModuleAccount, which is consistent with the changes mentioned in the PR objectives. This is a good change as it aligns with the updated system design.

  • 1894-1894: The FundModule function call is using types.PerpFundModuleAccount, which is consistent with the changes mentioned in the PR objectives. This is a good change as it aligns with the updated system design.

  • 1909-1909: The FundModule function call is using types.PerpFundModuleAccount, which is consistent with the changes mentioned in the PR objectives. This is a good change as it aligns with the updated system design.

  • 1929-1929: The FundModule function call is using types.PerpFundModuleAccount, which is consistent with the changes mentioned in the PR objectives. This is a good change as it aligns with the updated system design.

  • 1950-1950: The FundModule function call is using types.PerpFundModuleAccount, which is consistent with the changes mentioned in the PR objectives. This is a good change as it aligns with the updated system design.

  • 1972-1972: The FundModule function call is using types.PerpFundModuleAccount, which is consistent with the changes mentioned in the PR objectives. This is a good change as it aligns with the updated system design.

  • 2018-2018: The ModuleBalanceEqual function is being used to assert the balance of types.PerpFundModuleAccount. This is a good practice to ensure that the module's balance is as expected after the operations.

  • 1857-1857: The ModuleBalanceEqual function is being used to assert the balance of types.PerpFundModuleAccount. This is a good practice to ensure that the module's balance is as expected after the operations.

proto/nibiru/perp/v2/tx.proto Outdated Show resolved Hide resolved
Comment on lines +15 to +21
// registerError: Cleaner way of using 'sdkerrors.Register' without as much time
// manually writing integers.
func registerError(msg string) *sdkerrors.Error {
// Atomic for thread safety on concurrent calls
atomic.AddUint32(&moduleErrorCodeIdx, 1)
return sdkerrors.Register(ModuleName, moduleErrorCodeIdx, msg)
}
Copy link
Contributor

Choose a reason for hiding this comment

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

The use of atomic operations in registerError ensures thread safety when registering new errors. Consider adding a comment to clarify that the error code index starts at 1.

x/oracle/keeper/sudo.go Outdated Show resolved Hide resolved
proto/nibiru/oracle/v1/tx.proto Outdated Show resolved Hide resolved
commit d3f0ce3
Author: Unique-Divine <realuniquedivine@gmail.com>
Date:   Wed Dec 27 23:47:35 2023 -0600

    test(perp-cli_test): Grab module acc addr programatically

commit e43672a
Author: Unique-Divine <realuniquedivine@gmail.com>
Date:   Wed Dec 27 23:27:28 2023 -0600

    test assertiong

commit 0090d2f
Author: Unique-Divine <realuniquedivine@gmail.com>
Date:   Wed Dec 27 23:17:30 2023 -0600

    linter

commit 5121341
Merge: 596a840 68bddeb
Author: Unique-Divine <realuniquedivine@gmail.com>
Date:   Wed Dec 27 23:12:10 2023 -0600

    Merge branch 'main' into realu/sg-perp

commit 596a840
Author: Unique-Divine <realuniquedivine@gmail.com>
Date:   Wed Dec 27 23:10:15 2023 -0600

    changelog

commit 240dffe
Author: Unique-Divine <realuniquedivine@gmail.com>
Date:   Wed Dec 27 23:07:46 2023 -0600

    feat(perp): MsgDonateToPerpFund
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 e8effc2 and 1768d32.
Files selected for processing (3)
  • CHANGELOG.md (1 hunks)
  • app/keepers.go (2 hunks)
  • x/perp/v2/client/cli/cli_test.go (2 hunks)
Files skipped from review as they are similar to previous changes (3)
  • CHANGELOG.md
  • app/keepers.go
  • x/perp/v2/client/cli/cli_test.go

Copy link

codecov bot commented Dec 29, 2023

Codecov Report

Attention: 87 lines in your changes are missing coverage. Please review.

Comparison is base (d33dfe9) 73.89% compared to head (990b5d5) 73.39%.
Report is 17 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1752      +/-   ##
==========================================
- Coverage   73.89%   73.39%   -0.51%     
==========================================
  Files         192      196       +4     
  Lines       15142    15529     +387     
==========================================
+ Hits        11189    11397     +208     
- Misses       3297     3471     +174     
- Partials      656      661       +5     
Files Coverage Δ
app/app.go 58.06% <100.00%> (ø)
app/keepers.go 99.18% <100.00%> (-0.03%) ⬇️
app/upgrades.go 55.55% <100.00%> (ø)
cmd/nibid/cmd/root.go 80.51% <100.00%> (+0.10%) ⬆️
wasmbinding/exec_perp.go 0.00% <ø> (-81.67%) ⬇️
wasmbinding/message_plugin.go 72.22% <ø> (-10.24%) ⬇️
x/oracle/keeper/hooks.go 75.55% <100.00%> (ø)
x/oracle/keeper/keeper.go 81.25% <100.00%> (+0.34%) ⬆️
x/oracle/keeper/test_utils.go 96.75% <100.00%> (+0.19%) ⬆️
x/oracle/keeper/update_exchange_rates.go 94.73% <100.00%> (+0.68%) ⬆️
... and 20 more

... and 4 files with indirect coverage changes

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 1768d32 and 9c898cd.
Files ignored due to filter (2)
  • x/oracle/types/tx.pb.go
  • x/oracle/types/tx.pb.gw.go
Files selected for processing (2)
  • proto/nibiru/oracle/v1/tx.proto (3 hunks)
  • x/oracle/keeper/sudo.go (1 hunks)
Files skipped from review as they are similar to previous changes (1)
  • proto/nibiru/oracle/v1/tx.proto
Additional comments: 2
x/oracle/keeper/sudo.go (2)
  • 22-22: The Sudo method is a good use of syntactic sugar to make it clear when elevated permissions are being used. It's a simple and effective way to separate admin functionality.

  • 33-44: The EditOracleParams function properly checks permissions before proceeding with the update of oracle parameters. It follows a clear and logical sequence of operations: permission check, parameter retrieval, merging, updating, and validation. This sequence ensures that only authorized users can make changes and that the changes are validated before being finalized.

Comment on lines +50 to +99
func MergeOracleParams(
partial oracletypes.MsgEditOracleParams,
oracleParams oracletypes.Params,
) oracletypes.Params {
if partial.VotePeriod != nil {
oracleParams.VotePeriod = partial.VotePeriod.Uint64()
}

if partial.VoteThreshold != nil {
oracleParams.VoteThreshold = *partial.VoteThreshold
}

if partial.RewardBand != nil {
oracleParams.RewardBand = *partial.RewardBand
}

if partial.Whitelist != nil {
whitelist := make([]asset.Pair, len(partial.Whitelist))
for i, pair := range partial.Whitelist {
whitelist[i] = asset.MustNewPair(pair)
}

oracleParams.Whitelist = whitelist
}

if partial.SlashFraction != nil {
oracleParams.SlashFraction = *partial.SlashFraction
}

if partial.SlashWindow != nil {
oracleParams.SlashWindow = partial.SlashWindow.Uint64()
}

if partial.MinValidPerWindow != nil {
oracleParams.MinValidPerWindow = *partial.MinValidPerWindow
}

if partial.TwapLookbackWindow != nil {
oracleParams.TwapLookbackWindow = time.Duration(partial.TwapLookbackWindow.Int64())
}

if partial.MinVoters != nil {
oracleParams.MinVoters = partial.MinVoters.Uint64()
}

if partial.ValidatorFeeRatio != nil {
oracleParams.ValidatorFeeRatio = *partial.ValidatorFeeRatio
}

return oracleParams
Copy link
Contributor

Choose a reason for hiding this comment

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

💡 NOTE
Codebase verification is a beta feature.

The search results indicate that TwapLookbackWindow is generally treated as a time.Duration throughout the codebase, with references to standard duration marshaling and unmarshaling functions, as well as direct assignments using time.Minute. However, there is an instance in wasmbinding/exec_perp_test.go where TwapLookbackWindow is set using sdk.OneInt(), which does not align with the expected time.Duration type and could potentially lead to bugs related to time duration handling.

  • : The usage of TwapLookbackWindow in wasmbinding/exec_perp_test.go with sdk.OneInt() is inconsistent with its treatment as a time.Duration elsewhere in the codebase. This should be reviewed to ensure it is intentional and correctly handled.
Analysis chain

The MergeOracleParams function correctly checks for non-nil pointers before updating the oracle parameters. This prevents nil pointer dereferences and ensures that only specified fields are updated. However, the function assumes that the TwapLookbackWindow field in partial is a valid duration in nanoseconds. It's important to verify that this assumption holds true across the system to prevent potential bugs related to time duration handling.

Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Verify that TwapLookbackWindow is always set in nanoseconds across the codebase.
rg --type go 'TwapLookbackWindow' | grep -v 'time.Duration'

Length of output: 5437

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 9c898cd and a9408cb.
Files ignored due to filter (1)
  • x/oracle/types/oracle.pb.go
Files selected for processing (2)
  • proto/nibiru/oracle/v1/oracle.proto (3 hunks)
  • x/oracle/keeper/sudo_test.go (1 hunks)
Files skipped from review due to trivial changes (1)
  • proto/nibiru/oracle/v1/oracle.proto
Files skipped from review as they are similar to previous changes (1)
  • x/oracle/keeper/sudo_test.go

jgimeno pushed a commit that referenced this pull request Jan 1, 2024
* feat(perp): MsgDonateToPerpFund

* changelog

* linter

* test assertiong

* test(perp-cli_test): Grab module acc addr programatically

* consistent naming with #1752
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 a9408cb and 5d4a0f6.
Files ignored due to filter (1)
  • x/oracle/types/tx.pb.go
Files selected for processing (3)
  • CHANGELOG.md (1 hunks)
  • proto/nibiru/oracle/v1/tx.proto (3 hunks)
  • x/oracle/keeper/msg_server.go (2 hunks)
Files skipped from review as they are similar to previous changes (3)
  • CHANGELOG.md
  • proto/nibiru/oracle/v1/tx.proto
  • x/oracle/keeper/msg_server.go

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 5d4a0f6 and 990b5d5.
Files selected for processing (1)
  • CHANGELOG.md (1 hunks)
Files skipped from review as they are similar to previous changes (1)
  • CHANGELOG.md

@Unique-Divine Unique-Divine merged commit 1795b55 into main Jan 2, 2024
15 checks passed
@Unique-Divine Unique-Divine deleted the realu/sg-perp2 branch January 2, 2024 14:43
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