-
Notifications
You must be signed in to change notification settings - Fork 202
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* feat(perp): MsgDonateToPerpFund * changelog * linter * test assertiong * Squashed commit of the following: commit e43672a Author: Unique-Divine <[email protected]> Date: Wed Dec 27 23:27:28 2023 -0600 test assertiong commit 0090d2f Author: Unique-Divine <[email protected]> Date: Wed Dec 27 23:17:30 2023 -0600 linter commit 5121341 Merge: 596a840 68bddeb Author: Unique-Divine <[email protected]> Date: Wed Dec 27 23:12:10 2023 -0600 Merge branch 'main' into realu/sg-perp commit 596a840 Author: Unique-Divine <[email protected]> Date: Wed Dec 27 23:10:15 2023 -0600 changelog commit 240dffe Author: Unique-Divine <[email protected]> Date: Wed Dec 27 23:07:46 2023 -0600 feat(perp): MsgDonateToPerpFund * test(perp-cli_test): Grab module acc addr programatically * 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 * Squashed commit of the following: commit d3f0ce3 Author: Unique-Divine <[email protected]> Date: Wed Dec 27 23:47:35 2023 -0600 test(perp-cli_test): Grab module acc addr programatically commit e43672a Author: Unique-Divine <[email protected]> Date: Wed Dec 27 23:27:28 2023 -0600 test assertiong commit 0090d2f Author: Unique-Divine <[email protected]> Date: Wed Dec 27 23:17:30 2023 -0600 linter commit 5121341 Merge: 596a840 68bddeb Author: Unique-Divine <[email protected]> Date: Wed Dec 27 23:12:10 2023 -0600 Merge branch 'main' into realu/sg-perp commit 596a840 Author: Unique-Divine <[email protected]> Date: Wed Dec 27 23:10:15 2023 -0600 changelog commit 240dffe Author: Unique-Divine <[email protected]> Date: Wed Dec 27 23:07:46 2023 -0600 feat(perp): MsgDonateToPerpFund * PR comments fix * test(oracle): fix unit test case with invalid slash window
- Loading branch information
1 parent
b4175f1
commit 1795b55
Showing
16 changed files
with
1,465 additions
and
70 deletions.
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.