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

chore(wasmbinding): delete CustomQuerier since we have QueryRequest::Stargate now #1687

Merged
merged 28 commits into from
Dec 4, 2023
Merged
Show file tree
Hide file tree
Changes from 22 commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
596c664
chore(deps): Bump cosmossdk.io/math from 1.1.2 to 1.2.0
dependabot[bot] Nov 17, 2023
8722fce
feat(perp): msg server methods for shift peg and shift swap invariant
Unique-Divine Nov 28, 2023
e295eb3
(wasmbinding): remove pegshitft and depth shift
Unique-Divine Nov 28, 2023
0232852
test(perp): msg tests
Unique-Divine Nov 28, 2023
1220834
change log
Unique-Divine Nov 28, 2023
696d636
Merge branch 'master' into realu/perp-sg
Unique-Divine Nov 28, 2023
63b72aa
Update x/perp/v2/types/msgs.go
Unique-Divine Nov 28, 2023
b081818
PR comments changes
Unique-Divine Nov 28, 2023
1b5c836
add events for logging purposes
Unique-Divine Nov 28, 2023
2f0a125
refactor: consistent error name usage PR comment
Unique-Divine Nov 28, 2023
552a2d5
refactor: more PR comments
Unique-Divine Nov 28, 2023
fe1fe03
Address Gimeno PR comments + more tests
Unique-Divine Nov 29, 2023
c3ef701
fix strange address name conflicts
Unique-Divine Nov 29, 2023
a2ee8aa
test: fix all tests
Unique-Divine Dec 1, 2023
ad8c56b
test: more calls of EnsureNibiruPrefix
Unique-Divine Dec 1, 2023
3ff816f
Merge branch 'master' into realu/perp-sg
Unique-Divine Dec 1, 2023
f5415fd
Merge branch 'master' into dependabot/go_modules/cosmossdk.io/math-1.2.0
Unique-Divine Dec 1, 2023
bd55994
Updated changelog - dependabot
Unique-Divine Dec 1, 2023
46cd514
Merge branch 'master' into dependabot/go_modules/cosmossdk.io/math-1.2.0
Unique-Divine Dec 1, 2023
05810f3
Merge branch 'dependabot/go_modules/cosmossdk.io/math-1.2.0' into rea…
Unique-Divine Dec 1, 2023
02600a4
chore(wasmbinding): delete CustomQuerier since we have QueryRequest::…
Unique-Divine Dec 1, 2023
e75f1ec
changelog
Unique-Divine Dec 1, 2023
b52ff66
change log
Unique-Divine Dec 1, 2023
7de9341
test: fix no error cases in tests
Unique-Divine Dec 1, 2023
9e9701e
Merge branch 'realu/perp-sg' into realu/perp-sg2
Unique-Divine Dec 1, 2023
0f13580
Merge branch 'master' into realu/perp-sg2
Unique-Divine Dec 3, 2023
5ad427d
changelog + address PR comments
Unique-Divine Dec 3, 2023
84b1831
ci(codecov.yml): handle removed code coverage relative to bse
Unique-Divine Dec 3, 2023
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 @@ -47,6 +47,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### State Machine Breaking

* [#1682](https://github.com/NibiruChain/nibiru/pull/1682) - feat: add upgrade handler for v1.1.0
* [#xxx](https://github.com/NibiruChain/nibiru/pull/xxx) - chore(wasmbinding): delete CustomQuerier since we have QueryRequest::Stargate now

### Dependencies
- Bump `cosmossdk.io/math` from 1.1.2 to 1.2.0 ([#1676](https://github.com/NibiruChain/nibiru/pull/1676))
Expand Down Expand Up @@ -74,6 +75,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
* [#1617](https://github.com/NibiruChain/nibiru/pull/1617) - fix(app)!: non-nil snapshot manager is not guaranteed in testapp
* [#1645](https://github.com/NibiruChain/nibiru/pull/1645) - fix(tokenfactory)!: token supply in bank keeper must be correct after MsgBurn.
* [#1646](https://github.com/NibiruChain/nibiru/pull/1646) - feat(wasmbinding)!: whitelisted stargate queries for QueryRequest::Stargate: auth, bank, gov, tokenfactory, epochs, inflation, oracle, sudo, devgas
* [#1680](https://github.com/NibiruChain/nibiru/pull/1680) - feat(perp): MsgShiftPegMultiplier, MsgShiftSwapInvariant.

### Improvements

Expand Down
1 change: 1 addition & 0 deletions app/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ func NewDefaultGenesisState(cdc codec.JSONCodec) GenesisState {
gen := ModuleBasics.DefaultGenesis(cdc)

authGenesis := new(authtypes.GenesisState)
authtypes.DefaultGenesisState()
Copy link
Contributor

Choose a reason for hiding this comment

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

The call to authtypes.DefaultGenesisState() is made without using its return value. Please verify if this call is necessary and if the side effects are intended.

cdc.MustUnmarshalJSON(gen[authtypes.ModuleName], authGenesis)

return gen
Expand Down
1 change: 1 addition & 0 deletions app/ibc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import (
// init changes the value of 'DefaultTestingAppInit' to use custom initialization.
func init() {
ibctesting.DefaultTestingAppInit = SetupNibiruTestingApp
testapp.EnsureNibiruPrefix()
}

/*
Expand Down
22 changes: 11 additions & 11 deletions app/keepers.go
Original file line number Diff line number Diff line change
Expand Up @@ -238,13 +238,14 @@ func (app *NibiruApp) InitKeepers(
tkeys := app.tkeys
memKeys := app.memKeys

govModuleAddr := authtypes.NewModuleAddress(govtypes.ModuleName).String()
app.paramsKeeper = initParamsKeeper(
appCodec, legacyAmino, keys[paramstypes.StoreKey],
tkeys[paramstypes.TStoreKey],
)

// set the BaseApp's parameter store
app.ConsensusParamsKeeper = consensusparamkeeper.NewKeeper(appCodec, keys[consensusparamtypes.StoreKey], authtypes.NewModuleAddress(govtypes.ModuleName).String())
app.ConsensusParamsKeeper = consensusparamkeeper.NewKeeper(appCodec, keys[consensusparamtypes.StoreKey], govModuleAddr)
bApp.SetParamStore(&app.ConsensusParamsKeeper)

/* Add capabilityKeeper and ScopeToModule for the ibc module
Expand Down Expand Up @@ -274,21 +275,21 @@ func (app *NibiruApp) InitKeepers(
authtypes.ProtoBaseAccount,
maccPerms,
sdk.GetConfig().GetBech32AccountAddrPrefix(),
authtypes.NewModuleAddress(govtypes.ModuleName).String(),
govModuleAddr,
)
app.BankKeeper = bankkeeper.NewBaseKeeper(
appCodec,
keys[banktypes.StoreKey],
app.AccountKeeper,
BlockedAddresses(),
authtypes.NewModuleAddress(govtypes.ModuleName).String(),
govModuleAddr,
)
app.stakingKeeper = stakingkeeper.NewKeeper(
appCodec,
keys[stakingtypes.StoreKey],
app.AccountKeeper,
app.BankKeeper,
authtypes.NewModuleAddress(govtypes.ModuleName).String(),
govModuleAddr,
)
app.DistrKeeper = distrkeeper.NewKeeper(
appCodec,
Expand All @@ -297,7 +298,7 @@ func (app *NibiruApp) InitKeepers(
app.BankKeeper,
app.stakingKeeper,
authtypes.FeeCollectorName,
authtypes.NewModuleAddress(govtypes.ModuleName).String(),
govModuleAddr,
)

invCheckPeriod := cast.ToUint(appOpts.Get(server.FlagInvCheckPeriod))
Expand All @@ -307,7 +308,7 @@ func (app *NibiruApp) InitKeepers(
invCheckPeriod,
app.BankKeeper,
authtypes.FeeCollectorName,
authtypes.NewModuleAddress(govtypes.ModuleName).String(),
govModuleAddr,
)

app.FeeGrantKeeper = feegrantkeeper.NewKeeper(appCodec, keys[feegrant.StoreKey], app.AccountKeeper)
Expand All @@ -326,7 +327,7 @@ func (app *NibiruApp) InitKeepers(
appCodec,
homePath,
app.BaseApp,
authtypes.NewModuleAddress(govtypes.ModuleName).String(),
govModuleAddr,
)

// register the staking hooks
Expand All @@ -336,7 +337,7 @@ func (app *NibiruApp) InitKeepers(
legacyAmino,
keys[slashingtypes.StoreKey],
app.stakingKeeper,
authtypes.NewModuleAddress(govtypes.ModuleName).String(),
govModuleAddr,
)

app.stakingKeeper.SetHooks(
Expand Down Expand Up @@ -442,12 +443,11 @@ func (app *NibiruApp) InitKeepers(
wasmDir,
wasmConfig,
supportedFeatures,
authtypes.NewModuleAddress(govtypes.ModuleName).String(),
govModuleAddr,
GetWasmOpts(*app, appOpts)...,
)

// DevGas uses WasmKeeper
govModuleAddr := authtypes.NewModuleAddress(govtypes.ModuleName).String()
app.DevGasKeeper = devgaskeeper.NewKeeper(
keys[devgastypes.StoreKey],
appCodec,
Expand Down Expand Up @@ -553,7 +553,7 @@ func (app *NibiruApp) InitKeepers(
app.stakingKeeper,
app.MsgServiceRouter(),
govConfig,
authtypes.NewModuleAddress(govtypes.ModuleName).String(),
govModuleAddr,
)
govKeeper.SetLegacyRouter(govRouter)

Expand Down
26 changes: 26 additions & 0 deletions proto/nibiru/perp/v2/event.proto
Original file line number Diff line number Diff line change
Expand Up @@ -234,3 +234,29 @@ message MarketUpdatedEvent {
// the final state of the market
nibiru.perp.v2.Market final_market = 1 [ (gogoproto.nullable) = false ];
}

// EventShiftPegMultiplier: ABCI event emitted from MsgShiftPegMultiplier
message EventShiftPegMultiplier {
string old_peg_multiplier = 1 [
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec",
(gogoproto.nullable) = false
];
string new_peg_multiplier = 2 [
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec",
(gogoproto.nullable) = false
];
cosmos.base.v1beta1.Coin cost_paid = 3 [ (gogoproto.nullable) = false ];
}

// EventShiftSwapInvariant: ABCI event emitted from MsgShiftSwapInvariant
message EventShiftSwapInvariant {
string old_swap_invariant = 1 [
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Int",
(gogoproto.nullable) = false
];
string new_swap_invariant = 2 [
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Int",
(gogoproto.nullable) = false
];
cosmos.base.v1beta1.Coin cost_paid = 3 [ (gogoproto.nullable) = false ];
}
58 changes: 55 additions & 3 deletions proto/nibiru/perp/v2/tx.proto
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,26 @@ service Msg {
rpc DonateToEcosystemFund(MsgDonateToEcosystemFund)
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.
rpc ChangeCollateralDenom(MsgChangeCollateralDenom)
returns (MsgChangeCollateralDenomResponse) {}

rpc AllocateEpochRebates(MsgAllocateEpochRebates) returns (MsgAllocateEpochRebatesResponse) {}
rpc AllocateEpochRebates(MsgAllocateEpochRebates)
returns (MsgAllocateEpochRebatesResponse) {}

rpc WithdrawEpochRebates(MsgWithdrawEpochRebates) returns (MsgWithdrawEpochRebatesResponse) {}
rpc WithdrawEpochRebates(MsgWithdrawEpochRebates)
returns (MsgWithdrawEpochRebatesResponse) {}

// ShiftPegMultiplier: gRPC tx msg for changing a market's peg multiplier.
// [Admin] 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.
rpc ShiftSwapInvariant(MsgShiftSwapInvariant)
returns (MsgShiftSwapInvariantResponse) {}
}

// -------------------------- Settle Position --------------------------
Expand Down Expand Up @@ -376,4 +390,42 @@ message MsgWithdrawEpochRebatesResponse {
(gogoproto.nullable) = false,
(gogoproto.castrepeated) = "github.com/cosmos/cosmos-sdk/types.Coins"
];
}
}

// -------------------------- ShiftPegMultiplier --------------------------

// ShiftPegMultiplier: gRPC tx msg for changing the peg multiplier.
// Admin-only.
message MsgShiftPegMultiplier {
string sender = 1;
string pair = 2 [
(gogoproto.customtype) =
"github.com/NibiruChain/nibiru/x/common/asset.Pair",
(gogoproto.nullable) = false
];
string new_peg_mult = 3 [
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec",
(gogoproto.nullable) = false
];
}

message MsgShiftPegMultiplierResponse {}

// -------------------------- ShiftSwapInvariant --------------------------

// ShiftSwapInvariant: gRPC tx msg for changing the swap invariant.
// Admin-only.
message MsgShiftSwapInvariant {
string sender = 1;
string pair = 2 [
(gogoproto.customtype) =
"github.com/NibiruChain/nibiru/x/common/asset.Pair",
(gogoproto.nullable) = false
];
string new_swap_invariant = 3 [
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Int",
(gogoproto.nullable) = false
];
}

message MsgShiftSwapInvariantResponse {}
58 changes: 0 additions & 58 deletions wasmbinding/bindings/marshalling_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import (

"github.com/NibiruChain/nibiru/app"
"github.com/NibiruChain/nibiru/wasmbinding/bindings"
"github.com/NibiruChain/nibiru/x/common/testutil/genesis"
)

type TestSuiteBindingJsonTypes struct {
Expand All @@ -36,57 +35,6 @@ func (s *TestSuiteBindingJsonTypes) SetupSuite() {
s.fileJson = fileJson
}

func (s *TestSuiteBindingJsonTypes) TestQueries() {
testCaseMap := map[string]any{
"all_markets": new(bindings.AllMarketsResponse),
"reserves": new(bindings.ReservesResponse),
"base_price": new(bindings.BasePriceResponse),
"position": new(bindings.PositionResponse),
"positions": new(bindings.PositionsResponse),
"module_params": new(bindings.PerpParamsResponse),
"premium_fraction": new(bindings.PremiumFractionResponse),
"metrics": new(bindings.MetricsResponse),
"module_accounts": new(bindings.ModuleAccountsResponse),
"oracle_prices": new(bindings.OraclePricesResponse),
}

for name, cwRespPtr := range testCaseMap {
s.T().Run(name, func(t *testing.T) {
err := json.Unmarshal(s.fileJson[name], cwRespPtr)
s.Assert().NoErrorf(err, "name: %v", name)
jsonBz, err := json.Marshal(cwRespPtr)
s.NoErrorf(err, "jsonBz: %s", jsonBz)
})
}
}

func (s *TestSuiteBindingJsonTypes) TestToAppMarket() {
var lastCwMarket bindings.Market
for _, ammMarket := range genesis.START_MARKETS {
dummyBlockHeight := int64(1)
cwMarket := bindings.NewMarket(
ammMarket.Market,
ammMarket.Amm,
"index price",
ammMarket.Amm.InstMarkPrice().String(),
dummyBlockHeight,
)

// Test the ToAppMarket fn
gotAppMarket, err := cwMarket.ToAppMarket()
s.Assert().NoError(err)
s.Assert().EqualValues(ammMarket.Market, gotAppMarket)

lastCwMarket = cwMarket
}

// Test failure case
sadCwMarket := lastCwMarket
sadCwMarket.Pair = "ftt:ust:xxx-yyy!!!"
_, err := sadCwMarket.ToAppMarket()
s.Error(err)
}

func getFileJson(t *testing.T) (fileJson map[string]json.RawMessage) {
file, err := os.Open("execute_msg.json")
require.NoError(t, err)
Expand All @@ -102,13 +50,7 @@ func (s *TestSuiteBindingJsonTypes) TestExecuteMsgs() {
fileJson := getFileJson(t)

testCaseMap := []string{
"market_order",
"close_position",
"add_margin",
"remove_margin",
"donate_to_insurance_fund",
"peg_shift",
"depth_shift",
"edit_oracle_params",
"set_market_enabled",
"insurance_fund_withdraw",
Expand Down
47 changes: 0 additions & 47 deletions wasmbinding/bindings/msg.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,9 @@ import (
// - https://github.com/NibiruChain/cw-nibiru/blob/90df123f8d32d47b5b280ec6ae7dde0f9dbf2787/contracts/bindings-perp/src/msg.rs
type NibiruMsg struct {
// bindings-perp ExecuteMsg enum types
MarketOrder *MarketOrder `json:"market_order,omitempty"`
ClosePosition *ClosePosition `json:"close_position,omitempty"`
// MultiLiquidate *MultiLiquidate `json:"multi_liquidate,omitempty"` // TODO
AddMargin *AddMargin `json:"add_margin,omitempty"`
RemoveMargin *RemoveMargin `json:"remove_margin,omitempty"`
DonateToInsuranceFund *DonateToInsuranceFund `json:"donate_to_insurance_fund,omitempty"` // TODO
InsuranceFundWithdraw *InsuranceFundWithdraw `json:"insurance_fund_withdraw,omitempty"`
PegShift *PegShift `json:"peg_shift,omitempty"`
DepthShift *DepthShift `json:"depth_shift,omitempty"`
SetMarketEnabled *SetMarketEnabled `json:"set_market_enabled,omitempty"`
CreateMarket *CreateMarket `json:"create_market,omitempty"`

Expand All @@ -31,47 +25,6 @@ type NibiruMsg struct {
NoOp *NoOp `json:"no_op,omitempty"`
}

type MarketOrder struct {
Pair string `json:"pair"`
IsLong bool `json:"is_long"`
QuoteAmount sdkmath.Int `json:"quote_amount"`
Leverage sdk.Dec `json:"leverage"`
BaseAmountLimit sdkmath.Int `json:"base_amount_limit"`
}

type ClosePosition struct {
Pair string `json:"pair"`
}

type MultiLiquidate struct {
Liquidations []LiquidationArgs `json:"liquidations"`
}

type LiquidationArgs struct {
Pair string `json:"pair"`
Trader string `json:"trader"`
}

type AddMargin struct {
Pair string `json:"pair"`
Margin sdk.Coin `json:"margin"`
}

type RemoveMargin struct {
Pair string `json:"pair"`
Margin sdk.Coin `json:"margin"`
}

type PegShift struct {
Pair string `json:"pair"`
PegMult sdk.Dec `json:"peg_mult"`
}

type DepthShift struct {
Pair string `json:"pair"`
DepthMult sdk.Dec `json:"depth_mult"`
}

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