-
Notifications
You must be signed in to change notification settings - Fork 193
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
Changes from all commits
Commits
Show all changes
22 commits
Select commit
Hold shift + click to select a range
240dffe
feat(perp): MsgDonateToPerpFund
Unique-Divine 596a840
changelog
Unique-Divine 5121341
Merge branch 'main' into realu/sg-perp
Unique-Divine 0090d2f
linter
Unique-Divine e43672a
test assertiong
Unique-Divine 42e4214
Squashed commit of the following:
Unique-Divine d3f0ce3
test(perp-cli_test): Grab module acc addr programatically
Unique-Divine 31d3bdb
impl wip! keeper version without msg server or protos
Unique-Divine 1164d6e
quicksave wip! - add protos and msg server + todos
Unique-Divine dfc1798
test(oracle): verify that params before are not equal
Unique-Divine 1316f18
Merge branch 'main' into realu/sg-perp
Unique-Divine e8effc2
refactor: sudo and admin name consistency + docs + remove struct
Unique-Divine b72b992
Squashed commit of the following:
Unique-Divine 1768d32
Merge branch 'main' into realu/sg-perp2
Unique-Divine cc89084
Merge branch 'main' into realu/sg-perp
Unique-Divine 512b236
Merge branch 'realu/sg-perp' into realu/sg-perp2
Unique-Divine 9c898cd
PR comments fix
Unique-Divine 1e952ae
Merge branch 'main' into realu/sg-perp2
Unique-Divine c49663c
test(oracle): fix unit test case with invalid slash window
Unique-Divine a9408cb
Merge branch 'realu/sg-pt push erp2' of https://github.com/NibiruChai…
Unique-Divine 5d4a0f6
Merge branch 'main' into realu/sg-perp2
Unique-Divine 990b5d5
Merge branch 'main' into realu/sg-perp2
k-yang File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
package keeper | ||
|
||
import ( | ||
"fmt" | ||
"time" | ||
|
||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
|
||
"github.com/NibiruChain/nibiru/x/common/asset" | ||
oracletypes "github.com/NibiruChain/nibiru/x/oracle/types" | ||
) | ||
|
||
// Sudo extends the Keeper with sudo functions. See sudo.go. Sudo is syntactic | ||
// sugar to separate admin calls off from the other Keeper methods. | ||
// | ||
// These Sudo functions should: | ||
// 1. Not be called in other methods in the x/perp module. | ||
// 2. Only be callable by the x/sudo root or sudo contracts. | ||
// | ||
// The intention behind "Keeper.Sudo()" is to make it more obvious to the | ||
// developer that an unsafe function is being used when it's called. | ||
func (k Keeper) Sudo() sudoExtension { return sudoExtension{k} } | ||
|
||
type sudoExtension struct{ Keeper } | ||
|
||
// ------------------------------------------------------------------ | ||
// Admin.EditOracleParams | ||
|
||
func (k sudoExtension) EditOracleParams( | ||
ctx sdk.Context, newParams oracletypes.MsgEditOracleParams, | ||
sender sdk.AccAddress, | ||
) (paramsAfter oracletypes.Params, err error) { | ||
if err := k.SudoKeeper.CheckPermissions(sender, ctx); err != nil { | ||
return paramsAfter, err | ||
} | ||
|
||
params, err := k.Params.Get(ctx) | ||
if err != nil { | ||
return paramsAfter, fmt.Errorf("%w: failed to read oracle params", err) | ||
} | ||
|
||
paramsAfter = MergeOracleParams(newParams, params) | ||
k.UpdateParams(ctx, paramsAfter) | ||
return paramsAfter, paramsAfter.Validate() | ||
} | ||
|
||
// MergeOracleParams: Takes the given oracle params and merges them into the | ||
// existing partial params, keeping any existing values that are not set in the | ||
// partial. | ||
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 | ||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 search results indicate that
TwapLookbackWindow
is generally treated as atime.Duration
throughout the codebase, with references to standard duration marshaling and unmarshaling functions, as well as direct assignments usingtime.Minute
. However, there is an instance inwasmbinding/exec_perp_test.go
whereTwapLookbackWindow
is set usingsdk.OneInt()
, which does not align with the expectedtime.Duration
type and could potentially lead to bugs related to time duration handling.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 theTwapLookbackWindow
field inpartial
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:
Length of output: 5437