-
Notifications
You must be signed in to change notification settings - Fork 202
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
Conversation
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
WalkthroughThe recent codebase updates revolve around enhancing the project's oracle and permission system. A significant addition is the Changes
Poem
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? TipsChat with CodeRabbit Bot (
|
There was a problem hiding this 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
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 toPerpFundModuleAccount
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 toPerpFundModuleAccount
.* 29-29: The update of `ModuleAccounts` to include `PerpFundModuleAccount` is consistent with the renaming of the module account.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
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 theSendCoinsFromModuleToModule
call is consistent with the renaming of the module account.x/oracle/keeper/hooks_test.go (1)
- 76-76: The test
TestHooks_AfterEpochEnd
correctly usesPerpFundModuleAccount
following the renaming of the module account.wasmbinding/exec_perp.go (2)
36-36: The change to use
Sudo().CloseMarket
in theSetMarketEnabled
method aligns with the shift fromAdmin
toSudo
for elevated permission operations.74-74: The change to use
Sudo().CreateMarket
in theCreateMarket
method is consistent with the updated permission structure.x/oracle/types/expected_keeper.go (1)
- 45-49: The addition of the
SudoKeeper
interface with theCheckPermissions
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 theSuiteOracleSudo
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
andwasmbinding/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
inx/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 namedsudo_test.go
. This suggests that there are tests covering theMergeOracleParams
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 thecloseMarket
method aligns with the shift fromAdmin
toSudo
for elevated permission operations.38-38: The
closeMarketShouldFail
method correctly usesSudo().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 errorperptypes.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.goLength 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
toPerpFundModuleAccount
in theSendCoinsFromModuleToModule
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
toPerpFundModuleAccount
in theSendCoinsFromModuleToModule
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 theTestSnapshotUpdates
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 theTestEndBlocker
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
toPerpFundModuleAccount
in theSendCoinsFromModuleToModule
function call within theWithdrawFromVault
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
toPerpFundModuleAccount
in theSendCoinsFromModuleToModule
function call within therealizeBadDebt
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
tok.Sudo().UnsafeChangeCollateralDenom
in theInitGenesis
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
toPerpFundModuleAccount
is consistently applied throughout the entire codebase to avoid reference errors.Verification successful
The renaming of
PerpEFModuleAccount
toPerpFundModuleAccount
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
toSudo
methods should be verified to ensure that the correct authorization logic is applied.Verification successful
To verify that the
Sudo
method inx/perp/v2
correctly replaces theAdmin
method, we need to check the implementation details of theSudo
method and ensure that it is being used appropriately in themarket.go
file.
The review of the
sudo.go
file and the usage of theSudo()
method in themarket.go
file confirms that:
- The
Sudo
method is implemented in thex/perp/v2/keeper
directory and is intended to be used with elevated permissions.- The methods
ShiftPegMultiplier
,ShiftSwapInvariant
,CreateMarket
, andChangeCollateralDenom
are part of thesudoExtension
and include permission checks.- The
Sudo()
method is correctly used in themarket.go
file for the aforementioned methods.Based on this information, the change from
Admin
toSudo
methods in themarket.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.goLength 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 thex/oracle/keeper/msg_server.go
file and is defined inx/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.* 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.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
Verification successful
Based on the information gathered from the codebase and the tests, it is verified that the
EditOracleParams
function in thex/oracle/keeper/msg_server.go
file is intended to be called only by sudoers, and there are permission checks implemented to enforce this. TheSudoKeeper.CheckPermissions
method is used within thesudoExtension
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 3Length 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 3Length 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 3Length of output: 41481
x/perp/v2/keeper/keeper.go (1)
- 28-29: The removal of the
Admin
field from theKeeper
struct should be verified to ensure that all administrative functionalities are correctly transitioned to theSudoKeeper
.proto/nibiru/oracle/v1/tx.proto (1)
- 94-150: The new message types
MsgEditOracleParams
andMsgEditOracleParamsResponse
are introduced. Ensure that the fields are correctly typed and that theTODO
comments are addressed if necessary.wasmbinding/exec_perp_test.go (2)
134-142: The removal of
DoInsuranceFundWithdrawTest
and its usage in tests such asTestPerpExecutorHappy
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 apair
parameter to create a market. Verify that all invocations of this function have been updated to pass the correctpair
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 theSudoKeeper
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 aSudoKeeper
field, and theNewKeeper
function has been modified to accept asudoKeeper
parameter. Confirm that theSudoKeeper
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 andsudoExtension
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 newdenom
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.* 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.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
- 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 renamedPerpFundModuleAccount
. 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 termPerpFundModuleAccount
appears in multiple files, including tests, sudo-related files, and various other places within thex/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 newPerpFundModuleAccount
is being used in various contexts, including tests and module account initializations. This suggests that the renaming has been carried out thoroughly.* 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.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
156-156: The
ChangeCollateralDenom
function correctly delegates to thesudoExtension
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 thesudoExtension
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 thesudoExtension
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 namedTestAdmin_WithdrawFromPerpFund
andDoWithdrawFromPerpFundTest
in thex/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
toPerpFundModuleAccount
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 thatPerpFundModuleAccount
is used consistently across various files.
- The renaming from
PerpEFModuleAccount
toPerpFundModuleAccount
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 theMsgWithdrawFromPerpFund
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.* 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.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.goLength of output: 190
432-437: The
GetSigners
method forMsgWithdrawFromPerpFund
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 forMsgWithdrawFromPerpFund
usesModuleCdc.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
andsudotypes
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{}
inModuleBasics
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 theTestFixture
struct is appropriate for providing the necessary context for testing with the sudo functionality.140-143: The creation of
keySudo
inCreateTestFixture
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
andsudoAcc
inCreateTestFixture
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 theNewKeeper
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 thesudoKeeper
. 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 theVaultModuleAccount
to thePerpFundModuleAccount
instead of thePerpEFModuleAccount
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 ofPerpFundModuleAccount
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 thePerpFundModuleAccount
is used in the context of sending coins in at least one instance. The additional check within thex/perp/v2
module did not reveal any further usage ofSendCoinsFromModuleToModule
related to thePerpFundModuleAccount
, 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 theFundModule
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 theQueryModuleAccounts
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 thet *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 thet *testing.T
parameter being passed tofundModule
.45-65: The test case "withdraw all" has been updated to use the
Sudo
methodWithdrawFromPerpFund
instead of anAdmin
method. This change aligns with the PR objectives of refactoring the code to use "sudo" instead of "admin" terminologies. Ensure that theWithdrawFromPerpFund
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 theSudo
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 theperpMsgServer
. This change is consistent with the PR objectives to update message handling in thex/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 theMsgWithdrawFromPerpFund
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 theTestSuiteAdmin
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 callingDoWithdrawFromPerpFundTest
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 theasset.Pair
function andErrAmmNonPositiveSwapInvariant
error are correctly implemented and used elsewhere in the codebase.Verification successful
The output from the shell scripts provides the following information:
The
ast-grep
command did not return any output for theasset.Pair($_)
pattern. This suggests that there might not be any direct usage ofasset.Pair
in the codebase that matches the pattern, or it could mean that the pattern provided toast-grep
was not specific enough to find the occurrences.The
rg
command returned several matches forErrAmmNonPositiveSwapInvariant
across various files in thex/perp/v2
directory. This confirms that the error is defined inerrors.go
and is used in multiple places, including the test filemsgs_test.go
, the business logic inmsgs.go
andamm.go
, and other test files likeamm_test.go
andkeeper/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 thex/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 theast-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 theasset.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 thatasset.Pair
is a fundamental part of the codebase, particularly within thex/perp/v2
module.However, the specific search for the definition of the
asset.Pair
function withrg 'func Pair' --type go
did not yield any results. This could mean that the function is not defined with the exact namePair
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 thex/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 ofasset.Pair
in the test cases to be consistent with the rest of the codebase.* 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.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 goLength 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 goLength of output: 31903
Verification successful
The verification process has confirmed that:
sdkerrors.ErrInvalidAddress
is used consistently across various modules, including thex/perp/v2/types/msgs_test.go
.ErrGeneric
is defined inx/perp/v2/types/errors.go
and is used correctly inx/perp/v2/types/msgs.go
andx/perp/v2/types/msgs_test.go
.No issues have been found with the usage of these errors in the provided context.
* 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`.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 goLength of output: 2371
Verification successful
The executed script confirms that the
GetSigners
method is indeed implemented forMsgWithdrawFromPerpFund
. The method correctly retrieves the signer from theSender
field, converts it to anAccAddress
, and returns it as expected.
- : The
GetSigners
method is implemented forMsgWithdrawFromPerpFund
as shown in the provided output frommsgs.go
.* 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`.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
Verification successful
The executed script confirms that the
GetSignBytes
method is implemented forMsgWithdrawFromPerpFund
in the filex/perp/v2/types/msgs.go
. The method is defined and usessdk.MustSortJSON
along withModuleCdc.MustMarshalJSON
to marshal the message into JSON bytes, which is a standard way to implementGetSignBytes
in Cosmos SDK-based projects.Based on this information:
- The addition of
MsgWithdrawFromPerpFund
to the test cases inTestMsg_GetSignBytes
is correct.- The
GetSignBytes
method is indeed implemented forMsgWithdrawFromPerpFund
.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
toPerpFundModuleAccount
in theTestMsgServerDonateToPerpEf
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 toPerpFundModuleAccount
. The termPerpFundModuleAccount
is consistently used throughout various files in thex/perp/v2
module, as well as in thex/oracle
module andapp/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 namePerpFundModuleAccount
is used consistently.
- The renaming of
PerpEFModuleAccount
toPerpFundModuleAccount
has been applied consistently across the codebase, with no remaining references to the old name.* 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.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
Verification successful
The output from the shell script indicates that the
ModuleBalanceEqual
function is indeed used with thePerpFundModuleAccount
argument in various test files, includingwithdraw_test.go
,msg_server_test.go
,amm_test.go
,margin_test.go
,liquidate_test.go
, andclearing_house_test.go
. This confirms that the balance checks and related logic have been updated to reflect the change fromPerpEFModuleAccount
toPerpFundModuleAccount
.Based on the provided output, we can conclude that:
- The
ModuleBalanceEqual
function is utilized with the newPerpFundModuleAccount
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
toPerpFundModuleAccount
is successful.* 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.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
Verification successful
The search results confirm that the term
PerpFundModuleAccount
is used consistently across various files in the codebase, including themsg_server_test.go
file where the change was made. There are no remaining references toPerpEFModuleAccount
, which suggests that the renaming has been applied consistently.Based on the provided context and the search results, the change from
PerpEFModuleAccount
toPerpFundModuleAccount
in theTestMsgServerMultiLiquidate
function is verified to be accurate and consistent with the rest of the codebase.
- The renaming from
PerpEFModuleAccount
toPerpFundModuleAccount
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' --vimgrepLength of output: 13264
x/perp/v2/keeper/amm_test.go (41)
32-32: The renaming from
PerpEFModuleAccount
toPerpFundModuleAccount
is consistent with the PR objectives and AI-generated summary.39-39: The renaming from
PerpEFModuleAccount
toPerpFundModuleAccount
is consistent with the PR objectives and AI-generated summary.55-55: The renaming from
PerpEFModuleAccount
toPerpFundModuleAccount
is consistent with the PR objectives and AI-generated summary.62-62: The renaming from
PerpEFModuleAccount
toPerpFundModuleAccount
is consistent with the PR objectives and AI-generated summary.75-75: The renaming from
PerpEFModuleAccount
toPerpFundModuleAccount
is consistent with the PR objectives and AI-generated summary.82-82: The renaming from
PerpEFModuleAccount
toPerpFundModuleAccount
is consistent with the PR objectives and AI-generated summary.95-95: The renaming from
PerpEFModuleAccount
toPerpFundModuleAccount
is consistent with the PR objectives and AI-generated summary.102-102: The renaming from
PerpEFModuleAccount
toPerpFundModuleAccount
is consistent with the PR objectives and AI-generated summary.115-115: The renaming from
PerpEFModuleAccount
toPerpFundModuleAccount
is consistent with the PR objectives and AI-generated summary.122-122: The renaming from
PerpEFModuleAccount
toPerpFundModuleAccount
is consistent with the PR objectives and AI-generated summary.135-135: The renaming from
PerpEFModuleAccount
toPerpFundModuleAccount
is consistent with the PR objectives and AI-generated summary.142-142: The renaming from
PerpEFModuleAccount
toPerpFundModuleAccount
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
toPerpFundModuleAccount
is consistent with the PR objectives and AI-generated summary.318-318: The renaming from
PerpEFModuleAccount
toPerpFundModuleAccount
is consistent with the PR objectives and AI-generated summary.335-335: The renaming from
PerpEFModuleAccount
toPerpFundModuleAccount
is consistent with the PR objectives and AI-generated summary.342-342: The renaming from
PerpEFModuleAccount
toPerpFundModuleAccount
is consistent with the PR objectives and AI-generated summary.355-355: The renaming from
PerpEFModuleAccount
toPerpFundModuleAccount
is consistent with the PR objectives and AI-generated summary.362-362: The renaming from
PerpEFModuleAccount
toPerpFundModuleAccount
is consistent with the PR objectives and AI-generated summary.375-375: The renaming from
PerpEFModuleAccount
toPerpFundModuleAccount
is consistent with the PR objectives and AI-generated summary.382-382: The renaming from
PerpEFModuleAccount
toPerpFundModuleAccount
is consistent with the PR objectives and AI-generated summary.395-395: The renaming from
PerpEFModuleAccount
toPerpFundModuleAccount
is consistent with the PR objectives and AI-generated summary.402-402: The renaming from
PerpEFModuleAccount
toPerpFundModuleAccount
is consistent with the PR objectives and AI-generated summary.415-415: The renaming from
PerpEFModuleAccount
toPerpFundModuleAccount
is consistent with the PR objectives and AI-generated summary.422-422: The renaming from
PerpEFModuleAccount
toPerpFundModuleAccount
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
totypes.PerpFundModuleAccount
in thetransferFee
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 thex/perp/v2
module, test cases, and theapp/keepers.go
file, which indicates that the account is likely initialized there. This suggests that the change in thetransferFee
function to usePerpFundModuleAccount
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 theOracleKeeper
. Ensure that theSudoKeeper
is properly integrated into theOracleKeeper
and that any necessary migrations or state changes are handled due to this new addition.Verification successful
To verify the integration of
SudoKeeper
into theOracleKeeper
, I will adjust the ast-grep pattern to search for the usage ofSudoKeeper
within theOracleKeeper
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 theOracleKeeper
, I will generate a script to search for references toSudoKeeper
within theOracleKeeper
implementation.
The search results from the
rg
command provide several references toSudoKeeper
across various files in the Go codebase. Notably, thex/oracle/keeper/keeper.go
file shows theSudoKeeper
being included as a field in theKeeper
struct and being passed as an argument to theNewKeeper
function. This confirms the integration ofSudoKeeper
into theOracleKeeper
. 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 theOracleKeeper
.* 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.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 goLength of output: 4303
CHANGELOG.md (2)
67-71: Please verify if the release date and version numbers for the new entries (
MsgDonateToPerpFund
andMsgEditOracleParams
) 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
andMsgEditOracleParams
) 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 usetypes.PerpFundModuleAccount
instead of the previoustypes.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 usetypes.PerpFundModuleAccount
instead of the previoustypes.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 usingtypes.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 usingtypes.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 usingtypes.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 oftypes.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 usingtypes.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 usingtypes.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 usingtypes.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 usingtypes.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 usingtypes.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 usingtypes.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 oftypes.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 oftypes.PerpFundModuleAccount
. This is a good practice to ensure that the module's balance is as expected after the operations.
// 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) | ||
} |
There was a problem hiding this comment.
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.
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
There was a problem hiding this 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
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
Codecov ReportAttention:
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
|
There was a problem hiding this 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
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.
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 |
There was a problem hiding this comment.
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
inwasmbinding/exec_perp_test.go
withsdk.OneInt()
is inconsistent with its treatment as atime.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
There was a problem hiding this 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
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
There was a problem hiding this 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
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
There was a problem hiding this 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
Files selected for processing (1)
- CHANGELOG.md (1 hunks)
Files skipped from review as they are similar to previous changes (1)
- CHANGELOG.md
Purpose / Abstract
Squashed commit of the following:
Summary by CodeRabbit
New Features
Refactor
Documentation
Style
Chores
Please note that while internal code references are omitted, these notes reflect substantial user-facing improvements and refinements.