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
Merged
Show file tree
Hide file tree
Changes from 20 commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
240dffe
feat(perp): MsgDonateToPerpFund
Unique-Divine Dec 28, 2023
596a840
changelog
Unique-Divine Dec 28, 2023
5121341
Merge branch 'main' into realu/sg-perp
Unique-Divine Dec 28, 2023
0090d2f
linter
Unique-Divine Dec 28, 2023
e43672a
test assertiong
Unique-Divine Dec 28, 2023
42e4214
Squashed commit of the following:
Unique-Divine Dec 28, 2023
d3f0ce3
test(perp-cli_test): Grab module acc addr programatically
Unique-Divine Dec 28, 2023
31d3bdb
impl wip! keeper version without msg server or protos
Unique-Divine Dec 28, 2023
1164d6e
quicksave wip! - add protos and msg server + todos
Unique-Divine Dec 28, 2023
dfc1798
test(oracle): verify that params before are not equal
Unique-Divine Dec 28, 2023
1316f18
Merge branch 'main' into realu/sg-perp
Unique-Divine Dec 28, 2023
e8effc2
refactor: sudo and admin name consistency + docs + remove struct
Unique-Divine Dec 29, 2023
b72b992
Squashed commit of the following:
Unique-Divine Dec 29, 2023
1768d32
Merge branch 'main' into realu/sg-perp2
Unique-Divine Dec 29, 2023
cc89084
Merge branch 'main' into realu/sg-perp
Unique-Divine Dec 29, 2023
512b236
Merge branch 'realu/sg-perp' into realu/sg-perp2
Unique-Divine Dec 29, 2023
9c898cd
PR comments fix
Unique-Divine Dec 29, 2023
1e952ae
Merge branch 'main' into realu/sg-perp2
Unique-Divine Dec 29, 2023
c49663c
test(oracle): fix unit test case with invalid slash window
Unique-Divine Dec 29, 2023
a9408cb
Merge branch 'realu/sg-pt push erp2' of https://github.com/NibiruChai…
Unique-Divine Dec 29, 2023
5d4a0f6
Merge branch 'main' into realu/sg-perp2
Unique-Divine Jan 2, 2024
990b5d5
Merge branch 'main' into realu/sg-perp2
k-yang Jan 2, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
* [#1573](https://github.com/NibiruChain/nibiru/pull/1573) - feat(perp): Close markets and compute settlement price
* [#1705](https://github.com/NibiruChain/nibiru/pull/1705) - feat(perp): Add oracle pair to market object
* [#1718](https://github.com/NibiruChain/nibiru/pull/1718) - fix: fees does not require additional funds
* [#1734](https://github.com/NibiruChain/nibiru/pull/1734) - feat(perp): MsgDonateToPerpFund
* [#1752](https://github.com/NibiruChain/nibiru/pull/1752) - feat(oracle): MsgEditOracleParams sudo tx msg as part of #1642

### Non-breaking/Compatible Improvements

Expand Down
14 changes: 8 additions & 6 deletions app/keepers.go
Original file line number Diff line number Diff line change
Expand Up @@ -357,18 +357,20 @@ func (app *NibiruApp) InitKeepers(
appCodec, keys[spottypes.StoreKey], app.GetSubspace(spottypes.ModuleName),
app.AccountKeeper, app.BankKeeper, app.DistrKeeper)

app.SudoKeeper = keeper.NewKeeper(
appCodec, keys[sudotypes.StoreKey],
)

app.OracleKeeper = oraclekeeper.NewKeeper(appCodec, keys[oracletypes.StoreKey],
app.AccountKeeper, app.BankKeeper, app.DistrKeeper, app.stakingKeeper, distrtypes.ModuleName,
app.AccountKeeper, app.BankKeeper, app.DistrKeeper, app.stakingKeeper,
app.SudoKeeper,
distrtypes.ModuleName,
)

app.EpochsKeeper = epochskeeper.NewKeeper(
appCodec, keys[epochstypes.StoreKey],
)

app.SudoKeeper = keeper.NewKeeper(
appCodec, keys[sudotypes.StoreKey],
)

app.PerpKeeperV2 = perpkeeper.NewKeeper(
appCodec, keys[perptypes.StoreKey],
app.AccountKeeper, app.BankKeeper, app.OracleKeeper, app.EpochsKeeper,
Expand Down Expand Up @@ -805,7 +807,7 @@ func ModuleAccPerms() map[string][]string {

perptypes.ModuleName: {},
perptypes.VaultModuleAccount: {},
perptypes.PerpEFModuleAccount: {},
perptypes.PerpFundModuleAccount: {},
perptypes.FeePoolModuleAccount: {},
perptypes.DNRAllocationModuleAccount: {},
perptypes.DNREscrowModuleAccount: {},
Expand Down
10 changes: 5 additions & 5 deletions proto/nibiru/oracle/v1/oracle.proto
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,8 @@ message Params {
(gogoproto.nullable) = false
];

// Amount of time to look back for TWAP calculations
// Amount of time to look back for TWAP calculations.
// Ex: "900.000000069s" corresponds to 900 seconds and 69 nanoseconds in JSON.
google.protobuf.Duration twap_lookback_window = 8 [
(gogoproto.nullable) = false,
(gogoproto.stdduration) = true,
Expand All @@ -79,9 +80,8 @@ message Params {
(gogoproto.nullable) = false
];

uint64 expiration_blocks = 11 [
(gogoproto.moretags) = "yaml:\"expiration_blocks\""
];
uint64 expiration_blocks = 11
[ (gogoproto.moretags) = "yaml:\"expiration_blocks\"" ];
}

// Struct for aggregate prevoting on the ExchangeRateVote.
Expand Down Expand Up @@ -154,4 +154,4 @@ message Rewards {
uint64 vote_periods = 2;
// Coins defines the amount of coins to distribute in a single vote period.
repeated cosmos.base.v1beta1.Coin coins = 3 [ (gogoproto.nullable) = false ];
}
}
68 changes: 68 additions & 0 deletions proto/nibiru/oracle/v1/tx.proto
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package nibiru.oracle.v1;

import "gogoproto/gogo.proto";
import "google/api/annotations.proto";
import "nibiru/oracle/v1/oracle.proto";

option go_package = "github.com/NibiruChain/nibiru/x/oracle/types";

Expand All @@ -29,6 +30,11 @@ service Msg {
returns (MsgDelegateFeedConsentResponse) {
option (google.api.http).post = "/nibiru/oracle/feeder-delegate";
}

rpc EditOracleParams(MsgEditOracleParams)
returns (MsgEditOracleParamsResponse) {
option (google.api.http).post = "/nibiru/oracle/edit-oracle-params";
}
}

// MsgAggregateExchangeRatePrevote represents a message to submit
Expand Down Expand Up @@ -84,3 +90,65 @@ message MsgDelegateFeedConsent {
// MsgDelegateFeedConsentResponse defines the Msg/DelegateFeedConsent response
// type.
message MsgDelegateFeedConsentResponse {}

// MsgEditOracleParams: gRPC tx message for updating the x/oracle module params
// [[SUDO][SUDO][SUDO][SUDO][SUDO]] O[SUDO]ly callable by su[SUDO]oers.
message MsgEditOracleParams {
string sender = 1;

string vote_period = 2 [
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Int",
(gogoproto.nullable) = true
];

// vote_threshold: [cosmossdk.io/math.LegacyDec] TODO:
string vote_threshold = 3 [
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec",
(gogoproto.nullable) = true
];

// reward_band: [cosmossdk.io/math.LegacyDec] TODO:
string reward_band = 4 [
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec",
(gogoproto.nullable) = true
];

repeated string whitelist = 5 [ (gogoproto.nullable) = true ];

// slash_fraction: [cosmossdk.io/math.LegacyDec] TODO:
string slash_fraction = 6 [
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec",
(gogoproto.nullable) = true
];

string slash_window = 7 [
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Int",
(gogoproto.nullable) = true
];

// min_valid_per_window: [cosmossdk.io/math.LegacyDec] TODO:
string min_valid_per_window = 8 [
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec",
(gogoproto.nullable) = true
];

string twap_lookback_window = 9 [
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Int",
(gogoproto.nullable) = true
];

string min_voters = 10 [
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Int",
(gogoproto.nullable) = true
];

// VoteThreshold: [cosmossdk.io/math.LegacyDec] TODO:
string validator_fee_ratio = 11 [
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec",
(gogoproto.nullable) = true
];
}

// MsgEditOracleParamsResponse defines the Msg/EditOracleParams response
// type.
message MsgEditOracleParamsResponse { nibiru.oracle.v1.Params new_params = 1; }
33 changes: 27 additions & 6 deletions proto/nibiru/perp/v2/tx.proto
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ service Msg {
returns (MsgDonateToEcosystemFundResponse) {}

// ChangeCollateralDenom: Updates the collateral denom. A denom is valid if it
// is possible to make an sdk.Coin using it. [Admin] Only callable by sudoers.
// is possible to make an sdk.Coin using it. [SUDO] Only callable by sudoers.
rpc ChangeCollateralDenom(MsgChangeCollateralDenom)
returns (MsgChangeCollateralDenomResponse) {}

Expand All @@ -41,14 +41,19 @@ service Msg {
returns (MsgWithdrawEpochRebatesResponse) {}

// ShiftPegMultiplier: gRPC tx msg for changing a market's peg multiplier.
// [Admin] Only callable by sudoers.
// [SUDO] Only callable by sudoers.
rpc ShiftPegMultiplier(MsgShiftPegMultiplier)
returns (MsgShiftPegMultiplierResponse) {}

// ShiftSwapInvariant: gRPC tx msg for changing a market's swap invariant.
// [Admin] Only callable by sudoers.
// [SUDO] Only callable by sudoers.
rpc ShiftSwapInvariant(MsgShiftSwapInvariant)
returns (MsgShiftSwapInvariantResponse) {}

// WithdrawFromPerpFund: gRPC tx msg to withdraw from the perp fund module
// account. [SUDO] Only callable by sudoers.
rpc WithdrawFromPerpFund(MsgWithdrawFromPerpFund)
returns (MsgWithdrawFromPerpFundResponse) {}
}

// -------------------------- Settle Position --------------------------
Expand Down Expand Up @@ -353,7 +358,7 @@ message MsgDonateToEcosystemFundResponse {}
// ----------------------- MsgChangeCollateralDenom -----------------------

// MsgChangeCollateralDenom: Changes the collateral denom for the module.
// [Admin] Only callable by sudoers.
// [SUDO] Only callable by sudoers.
message MsgChangeCollateralDenom {
string sender = 1;
string new_denom = 2;
Expand Down Expand Up @@ -395,7 +400,7 @@ message MsgWithdrawEpochRebatesResponse {
// -------------------------- ShiftPegMultiplier --------------------------

// ShiftPegMultiplier: gRPC tx msg for changing the peg multiplier.
// Admin-only.
// [SUDO] Only callable by sudoers.
message MsgShiftPegMultiplier {
string sender = 1;
string pair = 2 [
Expand All @@ -414,7 +419,7 @@ message MsgShiftPegMultiplierResponse {}
// -------------------------- ShiftSwapInvariant --------------------------

// ShiftSwapInvariant: gRPC tx msg for changing the swap invariant.
// Admin-only.
// [SUDO] Only callable by sudoers.
message MsgShiftSwapInvariant {
string sender = 1;
string pair = 2 [
Expand All @@ -429,3 +434,19 @@ message MsgShiftSwapInvariant {
}

message MsgShiftSwapInvariantResponse {}

// -------------------------- WithdrawFromPerpFund --------------------------

// WithdrawFromPerpFund: gRPC tx msg for changing the swap invariant.
// [SUDO] Only callable by sudoers.
message MsgWithdrawFromPerpFund {
string sender = 1;
string amount = 2 [
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Int",
(gogoproto.nullable) = false
];
string denom = 3;
string to_addr = 4;
}
Unique-Divine marked this conversation as resolved.
Show resolved Hide resolved

message MsgWithdrawFromPerpFundResponse {}
16 changes: 2 additions & 14 deletions wasmbinding/bindings/msg.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,22 +14,15 @@ import (
type NibiruMsg struct {
// bindings-perp ExecuteMsg enum types
// MultiLiquidate *MultiLiquidate `json:"multi_liquidate,omitempty"` // TODO
DonateToInsuranceFund *DonateToInsuranceFund `json:"donate_to_insurance_fund,omitempty"` // TODO
InsuranceFundWithdraw *InsuranceFundWithdraw `json:"insurance_fund_withdraw,omitempty"`
SetMarketEnabled *SetMarketEnabled `json:"set_market_enabled,omitempty"`
CreateMarket *CreateMarket `json:"create_market,omitempty"`
SetMarketEnabled *SetMarketEnabled `json:"set_market_enabled,omitempty"`
CreateMarket *CreateMarket `json:"create_market,omitempty"`

EditOracleParams *EditOracleParams `json:"edit_oracle_params,omitempty"`

// Short for "no operation". A wasm binding payload that does nothing.
NoOp *NoOp `json:"no_op,omitempty"`
}

type DonateToInsuranceFund struct {
Sender string `json:"sender"`
Donation sdk.Coin `json:"donation"`
}

type EditOracleParams struct {
VotePeriod *sdkmath.Int `json:"vote_period,omitempty"`
VoteThreshold *sdk.Dec `json:"vote_threshold,omitempty"`
Expand All @@ -43,11 +36,6 @@ type EditOracleParams struct {
ValidatorFeeRatio *sdk.Dec `json:"validator_fee_ratio,omitempty"`
}

type InsuranceFundWithdraw struct {
Amount sdkmath.Int `json:"amount"`
To string `json:"to"`
}

type SetMarketEnabled struct {
Pair string `json:"pair"`
Enabled bool `json:"enabled"`
Expand Down
23 changes: 2 additions & 21 deletions wasmbinding/exec_perp.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,25 +20,6 @@ func (exec *ExecutorPerp) MsgServer() perpv2types.MsgServer {
return perpv2keeper.NewMsgServerImpl(exec.PerpV2)
}

func (exec *ExecutorPerp) InsuranceFundWithdraw(
cwMsg *bindings.InsuranceFundWithdraw, ctx sdk.Context,
) (err error) {
if cwMsg == nil {
return wasmvmtypes.InvalidRequest{Err: "null msg"}
}

to, err := sdk.AccAddressFromBech32(cwMsg.To)
if err != nil {
return err
}

return exec.PerpV2.Admin.WithdrawFromInsuranceFund(
ctx,
cwMsg.Amount,
to,
)
}

// TODO: rename to CloseMarket
func (exec *ExecutorPerp) SetMarketEnabled(
cwMsg *bindings.SetMarketEnabled, ctx sdk.Context,
Expand All @@ -52,7 +33,7 @@ func (exec *ExecutorPerp) SetMarketEnabled(
return err
}

return exec.PerpV2.Admin.CloseMarket(ctx, pair)
return exec.PerpV2.Sudo().CloseMarket(ctx, pair)
}

func (exec *ExecutorPerp) CreateMarket(
Expand Down Expand Up @@ -90,7 +71,7 @@ func (exec *ExecutorPerp) CreateMarket(
}
}

return exec.PerpV2.Admin.CreateMarket(ctx, perpv2keeper.ArgsCreateMarket{
return exec.PerpV2.Sudo().CreateMarket(ctx, perpv2keeper.ArgsCreateMarket{
Pair: pair,
PriceMultiplier: cwMsg.PegMult,
SqrtDepth: cwMsg.SqrtDepth,
Expand Down
32 changes: 0 additions & 32 deletions wasmbinding/exec_perp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,33 +134,13 @@ func (s *TestSuitePerpExecutor) OnSetupEnd() {
// Happy path coverage
func (s *TestSuitePerpExecutor) TestPerpExecutorHappy() {
for _, err := range []error{
s.DoInsuranceFundWithdrawTest(sdk.NewInt(69), s.contractDeployer),
s.DoCreateMarketTest(asset.MustNewPair("ufoo:ubar")),
s.DoCreateMarketTestWithParams(asset.MustNewPair("ufoo2:ubar")),
} {
s.NoError(err)
}
}

func (s *TestSuitePerpExecutor) DoInsuranceFundWithdrawTest(
amt sdkmath.Int, to sdk.AccAddress,
) error {
cwMsg := &bindings.InsuranceFundWithdraw{
Amount: amt,
To: to.String(),
}

err := testapp.FundModuleAccount(
s.nibiru.BankKeeper,
s.ctx,
perpv2types.PerpEFModuleAccount,
sdk.NewCoins(sdk.NewCoin(perpv2types.TestingCollateralDenomNUSD, sdk.NewInt(420))),
)
s.NoError(err)

return s.exec.InsuranceFundWithdraw(cwMsg, s.ctx)
}

func (s *TestSuitePerpExecutor) DoCreateMarketTest(pair asset.Pair) error {
cwMsg := &bindings.CreateMarket{
Pair: pair.String(),
Expand Down Expand Up @@ -197,11 +177,6 @@ func (s *TestSuitePerpExecutor) DoCreateMarketTestWithParams(pair asset.Pair) er
return s.exec.CreateMarket(cwMsg, s.ctx)
}

func (s *TestSuitePerpExecutor) TestSadPaths_Nil() {
err := s.exec.InsuranceFundWithdraw(nil, s.ctx)
s.Error(err)
}

func (s *TestSuitePerpExecutor) DoSetMarketEnabledTest(
pair asset.Pair, enabled bool,
) error {
Expand All @@ -220,13 +195,6 @@ func (s *TestSuitePerpExecutor) DoSetMarketEnabledTest(
return err
}

func (s *TestSuitePerpExecutor) TestSadPath_InsuranceFundWithdraw() {
fundsToWithdraw := sdk.NewCoin(perpv2types.TestingCollateralDenomNUSD, sdk.NewInt(69_000))

err := s.DoInsuranceFundWithdrawTest(fundsToWithdraw.Amount, s.contractDeployer)
s.Error(err)
}

func (s *TestSuitePerpExecutor) TestSadPaths_InvalidPair() {
sadPair := asset.Pair("ftt:ust:doge")
pair := sadPair
Expand Down
Loading
Loading