diff --git a/CHANGELOG.md b/CHANGELOG.md index 15ecc72b0..833e6acc4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -50,32 +50,33 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 * [#1712](https://github.com/NibiruChain/nibiru/pull/1712) - refactor(inflation): turn inflation off by default * [#1713](https://github.com/NibiruChain/nibiru/pull/1713) - chore(build-release): use new rocksdb libraries and link required libs * [#1715](https://github.com/NibiruChain/nibiru/pull/1715) - fix(build): revert! to working build + cherry-picks -* [#1731](https://github.com/NibiruChain/nibiru/pull/1731) - feat(cli): add cli command to decode stargate base64 messages +* [#1766](https://github.com/NibiruChain/nibiru/pull/1766) - refactor(app-wasmext)!: remove wasmbinding `CosmosMsg::Custom` bindings. #### Dapp modules: perp, spot, etc -* [#1687](https://github.com/NibiruChain/nibiru/pull/1687) - chore(wasmbinding): delete CustomQuerier since we have QueryRequest::Stargate now -* [#1686](https://github.com/NibiruChain/nibiru/pull/1686) - test(perp): add more tests for perp module msg server for DnR -* [#1683](https://github.com/NibiruChain/nibiru/pull/1683) - feat(perp): Add `StartDnREpoch` to `AfterEpochEnd` hook -* [#1680](https://github.com/NibiruChain/nibiru/pull/1680) - feat(perp): MsgShiftPegMultiplier, MsgShiftSwapInvariant. -* [#1677](https://github.com/NibiruChain/nibiru/pull/1677) - fix(perp): make Gen_market set initial perp versions -* [#1669](https://github.com/NibiruChain/nibiru/pull/1669) - feat(perp): add query to get collateral metadata -* [#1663](https://github.com/NibiruChain/nibiru/pull/1663) - feat(perp): Add volume based rebates -* [#1656](https://github.com/NibiruChain/nibiru/pull/1656) - feat(perp): Make the collateral denom a stateful collections.Item -* [#1632](https://github.com/NibiruChain/nibiru/pull/1632) - feat(perp): Add settle position transaction * [#1573](https://github.com/NibiruChain/nibiru/pull/1573) - feat(perp): Close markets and compute settlement price +* [#1632](https://github.com/NibiruChain/nibiru/pull/1632) - feat(perp): Add settle position transaction +* [#1656](https://github.com/NibiruChain/nibiru/pull/1656) - feat(perp): Make the collateral denom a stateful collections.Item +* [#1663](https://github.com/NibiruChain/nibiru/pull/1663) - feat(perp): Add volume based rebates +* [#1669](https://github.com/NibiruChain/nibiru/pull/1669) - feat(perp): add query to get collateral metadata +* [#1677](https://github.com/NibiruChain/nibiru/pull/1677) - fix(perp): make Gen_market set initial perp versions +* [#1680](https://github.com/NibiruChain/nibiru/pull/1680) - feat(perp): MsgShiftPegMultiplier, MsgShiftSwapInvariant. +* [#1683](https://github.com/NibiruChain/nibiru/pull/1683) - feat(perp): Add `StartDnREpoch` to `AfterEpochEnd` hook +* [#1686](https://github.com/NibiruChain/nibiru/pull/1686) - test(perp): add more tests for perp module msg server for DnR +* [#1687](https://github.com/NibiruChain/nibiru/pull/1687) - chore(wasmbinding): delete CustomQuerier since we have QueryRequest::Stargate now * [#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 sudo call as part of #1642 +* [#1749](https://github.com/NibiruChain/nibiru/pull/1749) - feat(perp): move close market from Wasm Binding to MsgCloseMarket * [#1752](https://github.com/NibiruChain/nibiru/pull/1752) - feat(oracle): MsgEditOracleParams sudo tx msg as part of #1642 * [#1755](https://github.com/NibiruChain/nibiru/pull/1755) - feat(oracle): Add more events on validator's performance -* [#1749](https://github.com/NibiruChain/nibiru/pull/1749) - feat(perp): move close market from Wasm Binding to MsgCloseMarket +* [#1764](https://github.com/NibiruChain/nibiru/pull/1764) - fix(perp): make updateswapinvariant aware of total short supply to avoid panics ### Non-breaking/Compatible Improvements -* [#1690](https://github.com/NibiruChain/nibiru/pull/1690) - docs(CHANGELOG.md): Correct the change log, providing clarity on what's released. * [#1679](https://github.com/NibiruChain/nibiru/pull/1679) - test(perp): add more tests for perp module msg server +* [#1690](https://github.com/NibiruChain/nibiru/pull/1690) - docs(CHANGELOG.md): Correct the change log, providing clarity on what's released. * [#1695](https://github.com/NibiruChain/nibiru/pull/1695) - feat(inflation): add events for inflation distribution * [#1695](https://github.com/NibiruChain/nibiru/pull/1695) - fix(sudo): Make blank sudoers root invalid at genesis time. * [#1710](https://github.com/NibiruChain/nibiru/pull/1710) - refactor(perp): Clean and organize module errors for x/perp @@ -83,10 +84,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 * [#1719](https://github.com/NibiruChain/nibiru/pull/1719) - refactor(test): add is not mandatory interface to action * [#1723](https://github.com/NibiruChain/nibiru/pull/1723) - ci(e2e-wasm.yml): rm unused workflow * [#1728](https://github.com/NibiruChain/nibiru/pull/1728) - test(devgas-cli): CLI tests for devgas txs +* [#1731](https://github.com/NibiruChain/nibiru/pull/1731) - feat(cli): add cli command to decode stargate base64 messages * [#1735](https://github.com/NibiruChain/nibiru/pull/1735) - test(sim): fix simulation tests -* [#1754](https://github.com/NibiruChain/nibiru/pull/1754) - refactor(decode-base64): clean code improvements and fn docs * [#1736](https://github.com/NibiruChain/nibiru/pull/1736) - test(sim): add sim genesis state for all cusom modules -* [#1764](https://github.com/NibiruChain/nibiru/pull/1764) - fix(perp): make updateswapinvariant aware of total short supply to avoid panics +* [#1754](https://github.com/NibiruChain/nibiru/pull/1754) - refactor(decode-base64): clean code improvements and fn docs ### Dependencies - Bump `github.com/cometbft/cometbft-db` from 0.9.0 to 0.9.1 ([#1760](https://github.com/NibiruChain/nibiru/pull/1760)) diff --git a/README.md b/README.md index a3de5b04f..a85248c0c 100644 --- a/README.md +++ b/README.md @@ -8,16 +8,17 @@ **Nibiru Chain** is a breakthrough smart contract platform providing superior throughput, reduced latency, and improved security, all driven by Web Assembly (Wasm) smart contracts. -- [⚙️ — Documentation](#%EF%B8%8F--documentation) -- [💬 — Community](#--community) -- [🧱 — Components of Nibiru](#--components-of-nibiru) -- [⛓️ — Building: `make` commands](#%EF%B8%8F--building-make-commands) - - [Nibid CLI](#nibid-cli) - - [Running a Local Node](#running-a-local-node) - - [Generate the protobufs](#generate-the-protobufs) - - [Linter](#linter) - - [Multiple Nodes](#multiple-nodes) -- [License](#license) +- [Nibiru Chain](#nibiru-chain) + - [⚙️ — Documentation](#️--documentation) + - [💬 — Community](#--community) + - [🧱 — Components of Nibiru](#--components-of-nibiru) + - [⛓️ — Building: `make` commands](#️--building-make-commands) + - [Nibid CLI](#nibid-cli) + - [Running a Local Node](#running-a-local-node) + - [Generate the protobufs](#generate-the-protobufs) + - [Linter](#linter) + - [Multiple Nodes](#multiple-nodes) + - [License](#license) ## ⚙️ — Documentation @@ -66,7 +67,6 @@ If you have questions or concerns, feel free to connect with a developer or comm [code-x-oracle]: https://github.com/NibiruChain/nibiru/tree/main/x/oracle [code-x-perp]: https://github.com/NibiruChain/nibiru/tree/main/x/perp [code-x-spot]: https://github.com/NibiruChain/nibiru/tree/main/x/spot -[code-x-wasm]: https://github.com/NibiruChain/nibiru/tree/main/wasmbinding Nibiru is built with the [Cosmos-SDK][cosmos-sdk-repo] on [Tendermint Core](https://tendermint.com/core/) consensus and communicates with other blockchain chains using the [Inter-Blockchain Communication (IBC)](https://github.com/cosmos/ibc) protocol. diff --git a/app/app.go b/app/app.go index 943ecc4d8..2f8de8dff 100644 --- a/app/app.go +++ b/app/app.go @@ -10,6 +10,9 @@ import ( wasmkeeper "github.com/CosmWasm/wasmd/x/wasm/keeper" wasmtypes "github.com/CosmWasm/wasmd/x/wasm/types" + + "github.com/NibiruChain/nibiru/app/wasmext" + dbm "github.com/cometbft/cometbft-db" abci "github.com/cometbft/cometbft/abci/types" "github.com/cometbft/cometbft/libs/log" @@ -43,8 +46,6 @@ import ( "github.com/prometheus/client_golang/prometheus" "github.com/rakyll/statik/fs" "github.com/spf13/cast" - - wasmbinding "github.com/NibiruChain/nibiru/wasmbinding" ) const ( @@ -115,16 +116,10 @@ func GetWasmOpts(nibiru NibiruApp, appOpts servertypes.AppOptions) []wasmkeeper. wasmOpts = append(wasmOpts, wasmkeeper.WithVMCacheMetrics(prometheus.DefaultRegisterer)) } - // Add the bindings to the app's set of []wasmkeeper.Option. - wasmOpts = append(wasmOpts, wasmbinding.NibiruWasmOptions( + return append(wasmOpts, wasmext.NibiruWasmOptions( nibiru.GRPCQueryRouter(), nibiru.appCodec, - nibiru.PerpKeeperV2, - nibiru.SudoKeeper, - nibiru.OracleKeeper, )...) - - return wasmOpts } // NewNibiruApp returns a reference to an initialized NibiruApp. diff --git a/app/keepers.go b/app/keepers.go index efefdc215..10418a946 100644 --- a/app/keepers.go +++ b/app/keepers.go @@ -460,7 +460,6 @@ func (app *NibiruApp) InitKeepers( govModuleAddr, ) - // TokenFactory has wasm bindings app.TokenFactoryKeeper = tokenfactorykeeper.NewKeeper( keys[tokenfactorytypes.StoreKey], appCodec, diff --git a/wasmbinding/stargate_query.go b/app/wasmext/stargate_query.go similarity index 98% rename from wasmbinding/stargate_query.go rename to app/wasmext/stargate_query.go index 04e05aefb..3a08dd327 100644 --- a/wasmbinding/stargate_query.go +++ b/app/wasmext/stargate_query.go @@ -1,4 +1,4 @@ -package wasmbinding +package wasmext import ( wasmkeeper "github.com/CosmWasm/wasmd/x/wasm/keeper" @@ -140,9 +140,5 @@ func WasmAcceptedStargateQueries() wasmkeeper.AcceptedStargateQueries { "/nibiru.devgas.v1.Query/FeeShare": new(devgas.QueryFeeShareResponse), "/nibiru.devgas.v1.Query/Params": new(devgas.QueryParamsResponse), "/nibiru.devgas.v1.Query/FeeSharesByWithdrawer": new(devgas.QueryFeeSharesByWithdrawerResponse), - - // TODO: for post v1 - // nibiru.perp - // nibiru.spot } } diff --git a/wasmbinding/stargate_query_test.go b/app/wasmext/stargate_query_test.go similarity index 98% rename from wasmbinding/stargate_query_test.go rename to app/wasmext/stargate_query_test.go index e809753ae..330ccf765 100644 --- a/wasmbinding/stargate_query_test.go +++ b/app/wasmext/stargate_query_test.go @@ -1,4 +1,4 @@ -package wasmbinding_test +package wasmext_test import ( "fmt" @@ -9,7 +9,7 @@ import ( "github.com/stretchr/testify/assert" "google.golang.org/grpc" - "github.com/NibiruChain/nibiru/wasmbinding" + wasmbinding "github.com/NibiruChain/nibiru/app/wasmext" "github.com/NibiruChain/nibiru/x/common/set" diff --git a/wasmbinding/wasm.go b/app/wasmext/wasm.go similarity index 54% rename from wasmbinding/wasm.go rename to app/wasmext/wasm.go index 972e5067f..c71c38a23 100644 --- a/wasmbinding/wasm.go +++ b/app/wasmext/wasm.go @@ -1,14 +1,9 @@ -package wasmbinding +package wasmext import ( wasmkeeper "github.com/CosmWasm/wasmd/x/wasm/keeper" "github.com/cosmos/cosmos-sdk/baseapp" "github.com/cosmos/cosmos-sdk/codec" - - "github.com/NibiruChain/nibiru/x/sudo/keeper" - - oraclekeeper "github.com/NibiruChain/nibiru/x/oracle/keeper" - perpv2keeper "github.com/NibiruChain/nibiru/x/perp/v2/keeper" ) // NibiruWasmOptions: Wasm Options are extension points to instantiate the Wasm @@ -16,9 +11,6 @@ import ( func NibiruWasmOptions( grpcQueryRouter *baseapp.GRPCQueryRouter, appCodec codec.Codec, - perpv2 perpv2keeper.Keeper, - sudoKeeper keeper.Keeper, - oracleKeeper oraclekeeper.Keeper, ) []wasmkeeper.Option { wasmQueryOption := wasmkeeper.WithQueryPlugins(&wasmkeeper.QueryPlugins{ Stargate: wasmkeeper.AcceptListStargateQuerier( @@ -28,9 +20,5 @@ func NibiruWasmOptions( ), }) - wasmExecuteOption := wasmkeeper.WithMessageHandlerDecorator( - CustomMessageDecorator(perpv2, sudoKeeper, oracleKeeper), - ) - - return []wasmkeeper.Option{wasmQueryOption, wasmExecuteOption} + return []wasmkeeper.Option{wasmQueryOption} } diff --git a/wasmbinding/test/cli_test.go b/app/wasmext/wasm_cli_test/cli_test.go similarity index 65% rename from wasmbinding/test/cli_test.go rename to app/wasmext/wasm_cli_test/cli_test.go index 26801f08b..cf13bf196 100644 --- a/wasmbinding/test/cli_test.go +++ b/app/wasmext/wasm_cli_test/cli_test.go @@ -1,10 +1,9 @@ -package test +package wasm_cli_test import ( "encoding/hex" "fmt" "testing" - "time" wasmcli "github.com/CosmWasm/wasmd/x/wasm/client/cli" @@ -15,22 +14,19 @@ import ( "github.com/stretchr/testify/suite" "github.com/NibiruChain/nibiru/app" - "github.com/NibiruChain/nibiru/x/common" - "github.com/NibiruChain/nibiru/x/common/asset" "github.com/NibiruChain/nibiru/x/common/denoms" "github.com/NibiruChain/nibiru/x/common/testutil" testutilcli "github.com/NibiruChain/nibiru/x/common/testutil/cli" "github.com/NibiruChain/nibiru/x/common/testutil/genesis" "github.com/NibiruChain/nibiru/x/common/testutil/testapp" - epochstypes "github.com/NibiruChain/nibiru/x/epochs/types" - perpv2types "github.com/NibiruChain/nibiru/x/perp/v2/types" ) // commonArgs is args for CLI test commands. var commonArgs = []string{ fmt.Sprintf("--%s=true", flags.FlagSkipConfirmation), fmt.Sprintf("--%s=%s", flags.FlagBroadcastMode, flags.BroadcastSync), - fmt.Sprintf("--%s=%s", flags.FlagFees, sdk.NewCoins(sdk.NewCoin(denoms.NIBI, sdk.NewInt(10000000))).String()), + fmt.Sprintf("--%s=%s", flags.FlagFees, + sdk.NewCoins(sdk.NewCoin(denoms.NIBI, sdk.NewInt(10_000_000))).String()), } type IntegrationTestSuite struct { @@ -46,38 +42,6 @@ func (s *IntegrationTestSuite) SetupSuite() { encodingConfig := app.MakeEncodingConfig() genesisState := genesis.NewTestGenesisState(encodingConfig) - perpv2Gen := perpv2types.DefaultGenesis() - perpv2Gen.Markets = []perpv2types.Market{ - { - Pair: asset.Registry.Pair(denoms.ETH, denoms.NUSD), - Enabled: true, - MaintenanceMarginRatio: sdk.MustNewDecFromStr("0.0625"), - MaxLeverage: sdk.MustNewDecFromStr("15"), - LatestCumulativePremiumFraction: sdk.ZeroDec(), - ExchangeFeeRatio: sdk.MustNewDecFromStr("0.0005"), - EcosystemFundFeeRatio: sdk.MustNewDecFromStr("0.0005"), - LiquidationFeeRatio: sdk.MustNewDecFromStr("0.001"), - PartialLiquidationRatio: sdk.MustNewDecFromStr("0.5"), - FundingRateEpochId: epochstypes.ThirtyMinuteEpochID, - MaxFundingRate: sdk.OneDec(), - TwapLookbackWindow: 30 * time.Minute, - PrepaidBadDebt: sdk.NewCoin(denoms.NUSD, sdk.ZeroInt()), - OraclePair: asset.Registry.Pair(denoms.ETH, denoms.USD), - }, - } - perpv2Gen.Amms = []perpv2types.AMM{ - { - Pair: asset.Registry.Pair(denoms.ETH, denoms.NUSD), - BaseReserve: sdk.NewDec(10 * common.TO_MICRO), - QuoteReserve: sdk.NewDec(10 * common.TO_MICRO), - SqrtDepth: common.MustSqrtDec(sdk.NewDec(10 * 10 * common.TO_MICRO * common.TO_MICRO)), - PriceMultiplier: sdk.NewDec(6000), - TotalLong: sdk.ZeroDec(), - TotalShort: sdk.ZeroDec(), - }, - } - genesisState[perpv2types.ModuleName] = encodingConfig.Marshaler.MustMarshalJSON(perpv2Gen) - s.cfg = testutilcli.BuildNetworkConfig(genesisState) network, err := testutilcli.New(s.T(), s.T().TempDir(), s.cfg) s.Require().NoError(err) diff --git a/wasmbinding/test/testdata/cw_nameservice.wasm b/app/wasmext/wasm_cli_test/testdata/cw_nameservice.wasm similarity index 100% rename from wasmbinding/test/testdata/cw_nameservice.wasm rename to app/wasmext/wasm_cli_test/testdata/cw_nameservice.wasm diff --git a/wasmbinding/bindings/execute_msg.json b/wasmbinding/bindings/execute_msg.json deleted file mode 100644 index 3e4e7f9ac..000000000 --- a/wasmbinding/bindings/execute_msg.json +++ /dev/null @@ -1,109 +0,0 @@ -{ - "market_order": { - "market_order": { - "pair": "ETH:USD", - "is_long": true, - "quote_amount": "100", - "leverage": "5", - "base_amount_limit": "1000" - } - }, - "close_position": { - "close_position": { - "pair": "ETH:USD" - } - }, - "add_margin": { - "add_margin": { - "pair": "ETH:USD", - "margin": { - "denom": "uusd", - "amount": "100" - } - } - }, - "remove_margin": { - "remove_margin": { - "pair": "ETH:USD", - "margin": { - "denom": "uusd", - "amount": "100" - } - } - }, - "multi_liquidate": { - "multi_liquidate": { - "pair": "ETH:USD", - "liquidations": [ - { - "pair": "ETH:USD", - "trader": "nibi1zaavvzxez0elundtn32qnk9lkm8kmcsz44g7xl" - }, - { - "pair": "ETH:USD", - "trader": "nibi1ah8gqrtjllhc5ld4rxgl4uglvwl93ag0sh6e6v" - } - ] - } - }, - "donate_to_insurance_fund": { - "donate_to_insurance_fund": { - "donation": { - "denom": "uusd", - "amount": "100" - } - } - }, - "peg_shift": { - "peg_shift": { - "pair": "ETH:USD", - "peg_mult": "420" - } - }, - "depth_shift": { - "depth_shift": { - "pair": "ETH:USD", - "depth_mult": "420" - } - }, - "no_op": { - "no_op": {} - }, - "insurance_fund_withdraw": { - "insurance_fund_withdraw": { - "amount": "420", - "to": "nibi1ah8gqrtjllhc5ld4rxgl4uglvwl93ag0sh6e6v" - } - }, - "set_market_enabled": { - "set_market_enabled": { - "pair": "ETH:USD", - "enabled": true - } - }, - "edit_oracle_params": { - "edit_oracle_params": { - "vote_period": "420", - "vote_threshold": "420", - "reward_band": "420", - "whitelist": [ - "nibi1zaavvzxez0elundtn32qnk9lkm8kmcsz44g7xl", - "nibi1ah8gqrtjllhc5ld4rxgl4uglvwl93ag0sh6e6v" - ], - "slash_fraction": "420", - "slash_window": "420", - "min_valid_per_window": "420", - "twap_lookback_window": "420", - "min_voters": "420", - "validator_fee_ratio": "420" - } - }, - "create_market": { - "create_market": { - "pair": "ETH:USD", - "peg_mult": "420", - "sqrt_depth": "420", - "market_params": null - } - } -} \ No newline at end of file diff --git a/wasmbinding/bindings/marshalling_test.go b/wasmbinding/bindings/marshalling_test.go deleted file mode 100644 index 931ecdd49..000000000 --- a/wasmbinding/bindings/marshalling_test.go +++ /dev/null @@ -1,97 +0,0 @@ -package bindings_test - -import ( - "bytes" - "encoding/json" - "os" - "testing" - - "github.com/stretchr/testify/assert" - "github.com/stretchr/testify/require" - "github.com/stretchr/testify/suite" - - "github.com/NibiruChain/nibiru/app" - "github.com/NibiruChain/nibiru/wasmbinding/bindings" -) - -type TestSuiteBindingJsonTypes struct { - suite.Suite - fileJson map[string]json.RawMessage -} - -func TestSuiteBindingJsonTypes_RunAll(t *testing.T) { - suite.Run(t, new(TestSuiteBindingJsonTypes)) -} - -func (s *TestSuiteBindingJsonTypes) SetupSuite() { - app.SetPrefixes(app.AccountAddressPrefix) - file, err := os.Open("query_resp.json") - s.NoError(err) - defer file.Close() - - var fileJson map[string]json.RawMessage - err = json.NewDecoder(file).Decode(&fileJson) - s.NoError(err) - s.fileJson = fileJson -} - -func getFileJson(t *testing.T) (fileJson map[string]json.RawMessage) { - file, err := os.Open("execute_msg.json") - require.NoError(t, err) - defer file.Close() - - err = json.NewDecoder(file).Decode(&fileJson) - require.NoError(t, err) - return fileJson -} - -func (s *TestSuiteBindingJsonTypes) TestExecuteMsgs() { - t := s.T() - fileJson := getFileJson(t) - - testCaseMap := []string{ - "donate_to_insurance_fund", - "edit_oracle_params", - "set_market_enabled", - "insurance_fund_withdraw", - "create_market", - "no_op", - } - - for _, name := range testCaseMap { - t.Run(name, func(t *testing.T) { - var bindingMsg bindings.NibiruMsg - err := json.Unmarshal(fileJson[name], &bindingMsg) - assert.NoErrorf(t, err, "name: %v", name) - - jsonBz, err := json.Marshal(bindingMsg) - assert.NoErrorf(t, err, "jsonBz: %s", jsonBz) - - // Json files are not compacted, so we need to compact them before comparing - compactJsonBz, err := compactJsonData(jsonBz) - require.NoError(t, err) - - fileBytes, err := fileJson[name].MarshalJSON() - require.NoError(t, err) - compactFileBytes, err := compactJsonData(fileBytes) - require.NoError(t, err) - - var reconsitutedBindingMsg bindings.NibiruMsg - err = json.Unmarshal(compactFileBytes.Bytes(), &reconsitutedBindingMsg) - require.NoError(t, err) - - compactFileStr := compactFileBytes.String() - compactJsonStr := compactJsonBz.String() - require.EqualValuesf( - t, bindingMsg, reconsitutedBindingMsg, - "compactFileStr: %s\ncompactJsonStr: ", compactFileStr, compactJsonStr, - ) - }) - } -} - -func compactJsonData(data []byte) (*bytes.Buffer, error) { - compactData := new(bytes.Buffer) - err := json.Compact(compactData, data) - return compactData, err -} diff --git a/wasmbinding/bindings/msg.go b/wasmbinding/bindings/msg.go deleted file mode 100644 index bbef598d1..000000000 --- a/wasmbinding/bindings/msg.go +++ /dev/null @@ -1,69 +0,0 @@ -package bindings - -import ( - sdkmath "cosmossdk.io/math" - sdk "github.com/cosmos/cosmos-sdk/types" -) - -// NibiruMsg corresponds to the 'ExecuteMsg' enum in the CosmWasm binding -// contracts (Rust). It specifies which wasm execute messages can be called with -// Nibiru bindings and specifies the JSON schema that connects app ⇔ Wasm. -// -// See: -// - https://github.com/NibiruChain/cw-nibiru/blob/90df123f8d32d47b5b280ec6ae7dde0f9dbf2787/contracts/bindings-perp/src/msg.rs -type NibiruMsg struct { - // bindings-perp ExecuteMsg enum types - // MultiLiquidate *MultiLiquidate `json:"multi_liquidate,omitempty"` // TODO - 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 EditOracleParams struct { - VotePeriod *sdkmath.Int `json:"vote_period,omitempty"` - VoteThreshold *sdk.Dec `json:"vote_threshold,omitempty"` - RewardBand *sdk.Dec `json:"reward_band,omitempty"` - Whitelist []string `json:"whitelist,omitempty"` - SlashFraction *sdk.Dec `json:"slash_fraction,omitempty"` - SlashWindow *sdkmath.Int `json:"slash_window,omitempty"` - MinValidPerWindow *sdk.Dec `json:"min_valid_per_window,omitempty"` - TwapLookbackWindow *sdkmath.Int `json:"twap_lookback_window,omitempty"` - MinVoters *sdkmath.Int `json:"min_voters,omitempty"` - ValidatorFeeRatio *sdk.Dec `json:"validator_fee_ratio,omitempty"` -} - -type MarketParams struct { - Pair string - Enabled bool `json:"enabled,omitempty"` - // the minimum margin ratio which a user must maintain on this market - MaintenanceMarginRatio sdk.Dec `json:"maintenance_margin_ratio"` - // the maximum leverage a user is able to be taken on this market - MaxLeverage sdk.Dec `json:"max_leverage"` - // Latest cumulative premium fraction for a given pair. - // Calculated once per funding rate interval. - // A premium fraction is the difference between mark and index, divided by the - // number of payments per day. (mark - index) / # payments in a day - LatestCumulativePremiumFraction sdk.Dec `json:"latest_cumulative_premium_fraction"` - // the percentage of the notional given to the exchange when trading - ExchangeFeeRatio sdk.Dec `json:"exchange_fee_ratio"` - // the percentage of the notional transferred to the ecosystem fund when - // trading - EcosystemFundFeeRatio sdk.Dec `json:"ecosystem_fund_fee_ratio"` - // the percentage of liquidated position that will be - // given to out as a reward. Half of the liquidation fee is given to the - // liquidator, and the other half is given to the ecosystem fund. - LiquidationFeeRatio sdk.Dec `json:"liquidation_fee_ratio"` - // the portion of the position size we try to liquidate if the available - // margin is higher than liquidation fee - PartialLiquidationRatio sdk.Dec `json:"partial_liquidation_ratio"` - // specifies the interval on which the funding rate is updated - FundingRateEpochId string `json:"funding_rate_epoch_id,omitempty"` - // specifies the maximum premium fraction to be paid out - MaxFundingRate sdk.Dec `json:"max_funding_rate,omitempty"` - // amount of time to look back for TWAP calculations - TwapLookbackWindow sdkmath.Int `json:"twap_lookback_window"` - OraclePair string `json:"oracle_pair"` -} - -type NoOp struct{} diff --git a/wasmbinding/bindings/query_resp.json b/wasmbinding/bindings/query_resp.json deleted file mode 100644 index eb2eb2c07..000000000 --- a/wasmbinding/bindings/query_resp.json +++ /dev/null @@ -1,120 +0,0 @@ -{ - "all_markets": { - "market_map": { - "ETH:USD": { - "pair": "ETH:USD", - "base_reserve": "69", - "quote_reserve": "69", - "sqrt_depth": "69", - "depth": "4761", - "total_long": "420", - "total_short": "69", - "peg_mult": "420", - "config": { - "maintenance_margin_ratio": "420", - "max_leverage": "420" - }, - "mark_price": "420", - "index_price": "123", - "twap_mark": "456", - "block_number": "42" - } - } - }, - "reserves": { - "pair": "ETH:USD", - "base_reserve": "420", - "quote_reserve": "69" - }, - "base_price": { - "pair": "ETH:USD", - "base_amount": "1", - "quote_amount": "420", - "is_long": false - }, - "position": { - "position": { - "trader_addr": "nibi1zaavvzxez0elundtn32qnk9lkm8kmcsz44g7xl", - "pair": "ETH:USD", - "size": "420", - "margin": "420", - "open_notional": "420", - "latest_cpf": "0", - "block_number": "1" - }, - "notional": "420", - "upnl": "69", - "margin_ratio_mark": "0", - "margin_ratio_index": "0", - "block_number": "0" - }, - "positions": { - "positions": { - "ETH:USD": { - "trader_addr": "nibi1zaavvzxez0elundtn32qnk9lkm8kmcsz44g7xl", - "pair": "ETH:USD", - "size": "420", - "margin": "420", - "open_notional": "420", - "latest_cpf": "0", - "block_number": "1" - }, - "BTC:USD": { - "trader_addr": "nibi1zaavvzxez0elundtn32qnk9lkm8kmcsz44g7xl", - "pair": "BTC:USD", - "size": "420", - "margin": "420", - "open_notional": "420", - "latest_cpf": "0", - "block_number": "1" - } - } - }, - "module_params": { - "module_params": { - "stopped": false, - "fee_pool_fee_ratio": "420", - "ecosystem_fund_fee_ratio": "69", - "liquidation_fee_ratio": "69", - "partial_liquidation_ratio": "0", - "funding_rate_interval": "1h", - "twap_lookback_window": "3600", - "whitelisted_liquidators": [ - "nibi1ah8gqrtjllhc5ld4rxgl4uglvwl93ag0sh6e6v", - "nibi1zaavvzxez0elundtn32qnk9lkm8kmcsz44g7xl" - ] - } - }, - "premium_fraction": { - "pair": "ETH:USD", - "cpf": "0", - "estimated_next_cpf": "69" - }, - "metrics": { - "metrics": { - "pair": "ETH:USD", - "net_size": "420", - "volume_quote": "1", - "volume_base": "420", - "block_number": "42" - } - }, - "module_accounts": { - "module_accounts": { - "acc1": { - "name": "acc1", - "addr": "nibi1x5zknk8va44th5vjpg0fagf0lxx0rvurpmp8gs", - "balance": [ - { - "denom": "foocoin", - "amount": "420" - } - ] - } - } - }, - "oracle_prices": { - "ETH:USD": "420", - "NIBI:USD": "69" - } -} \ No newline at end of file diff --git a/wasmbinding/exec_oracle.go b/wasmbinding/exec_oracle.go deleted file mode 100644 index 606f993b4..000000000 --- a/wasmbinding/exec_oracle.go +++ /dev/null @@ -1,80 +0,0 @@ -package wasmbinding - -import ( - "fmt" - "time" - - sdk "github.com/cosmos/cosmos-sdk/types" - - "github.com/NibiruChain/nibiru/wasmbinding/bindings" - "github.com/NibiruChain/nibiru/x/common/asset" - oraclekeeper "github.com/NibiruChain/nibiru/x/oracle/keeper" - oracletypes "github.com/NibiruChain/nibiru/x/oracle/types" -) - -type ExecutorOracle struct { - Oracle oraclekeeper.Keeper -} - -func (o ExecutorOracle) SetOracleParams(msg *bindings.EditOracleParams, ctx sdk.Context) error { - params, err := o.Oracle.Params.Get(ctx) - if err != nil { - return fmt.Errorf("get oracle params error: %s", err.Error()) - } - - mergedParams := mergeOracleParams(msg, params) - - o.Oracle.UpdateParams(ctx, mergedParams) - return nil -} - -// mergeOracleParams takes the oracle params from the wasm msg and merges them into the existing params -// keeping any existing values if not set in the wasm msg -func mergeOracleParams(msg *bindings.EditOracleParams, oracleParams oracletypes.Params) oracletypes.Params { - if msg.VotePeriod != nil { - oracleParams.VotePeriod = msg.VotePeriod.Uint64() - } - - if msg.VoteThreshold != nil { - oracleParams.VoteThreshold = *msg.VoteThreshold - } - - if msg.RewardBand != nil { - oracleParams.RewardBand = *msg.RewardBand - } - - if msg.Whitelist != nil { - whitelist := make([]asset.Pair, len(msg.Whitelist)) - for i, pair := range msg.Whitelist { - whitelist[i] = asset.MustNewPair(pair) - } - - oracleParams.Whitelist = whitelist - } - - if msg.SlashFraction != nil { - oracleParams.SlashFraction = *msg.SlashFraction - } - - if msg.SlashWindow != nil { - oracleParams.SlashWindow = msg.SlashWindow.Uint64() - } - - if msg.MinValidPerWindow != nil { - oracleParams.MinValidPerWindow = *msg.MinValidPerWindow - } - - if msg.TwapLookbackWindow != nil { - oracleParams.TwapLookbackWindow = time.Duration(msg.TwapLookbackWindow.Int64()) - } - - if msg.MinVoters != nil { - oracleParams.MinVoters = msg.MinVoters.Uint64() - } - - if msg.ValidatorFeeRatio != nil { - oracleParams.ValidatorFeeRatio = *msg.ValidatorFeeRatio - } - - return oracleParams -} diff --git a/wasmbinding/exec_oracle_test.go b/wasmbinding/exec_oracle_test.go deleted file mode 100644 index ceb531181..000000000 --- a/wasmbinding/exec_oracle_test.go +++ /dev/null @@ -1,233 +0,0 @@ -package wasmbinding_test - -import ( - "testing" - "time" - - wasmkeeper "github.com/CosmWasm/wasmd/x/wasm/keeper" - tmproto "github.com/cometbft/cometbft/proto/tendermint/types" - sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/stretchr/testify/suite" - - "github.com/NibiruChain/nibiru/app" - "github.com/NibiruChain/nibiru/wasmbinding" - "github.com/NibiruChain/nibiru/wasmbinding/bindings" - "github.com/NibiruChain/nibiru/wasmbinding/wasmbin" - "github.com/NibiruChain/nibiru/x/common/denoms" - "github.com/NibiruChain/nibiru/x/common/testutil" - "github.com/NibiruChain/nibiru/x/common/testutil/testapp" -) - -func TestSuiteOracleExecutor_RunAll(t *testing.T) { - suite.Run(t, new(TestSuiteOracleExecutor)) -} - -type TestSuiteOracleExecutor struct { - suite.Suite - - nibiru app.NibiruApp - contractDeployer sdk.AccAddress - exec wasmbinding.ExecutorOracle - contract sdk.AccAddress - ctx sdk.Context -} - -func (s *TestSuiteOracleExecutor) SetupSuite() { - sender := testutil.AccAddress() - s.contractDeployer = sender - - genesisState := SetupPerpGenesis() - nibiru := testapp.NewNibiruTestApp(genesisState) - ctx := nibiru.NewContext(false, tmproto.Header{ - Height: 1, - ChainID: "nibiru-wasmnet-1", - Time: time.Now().UTC(), - }) - - coins := sdk.NewCoins( - sdk.NewCoin(denoms.NIBI, sdk.TokensFromConsensusPower(1, sdk.DefaultPowerReduction)), - sdk.NewCoin(denoms.NUSD, sdk.TokensFromConsensusPower(1, sdk.DefaultPowerReduction)), - ) - s.NoError(testapp.FundAccount(nibiru.BankKeeper, ctx, sender, coins)) - - nibiru, ctx = SetupAllContracts(s.T(), sender, nibiru, ctx) - s.nibiru = *nibiru - s.ctx = ctx - - wasmkeeper.NewMsgServerImpl(&nibiru.WasmKeeper) - s.contract = ContractMap[wasmbin.WasmKeyController] - s.exec = wasmbinding.ExecutorOracle{ - Oracle: nibiru.OracleKeeper, - } -} - -func (s *TestSuiteOracleExecutor) TestExecuteOracleParams() { - period := sdk.NewInt(1234) - cwMsg := &bindings.EditOracleParams{ - VotePeriod: &period, - } - - // Vote Period - params, err := s.nibiru.OracleKeeper.Params.Get(s.ctx) - s.Require().NoError(err) - s.Equal(uint64(1_000), params.VotePeriod) - - err = s.exec.SetOracleParams(cwMsg, s.ctx) - s.Require().NoError(err) - - params, err = s.nibiru.OracleKeeper.Params.Get(s.ctx) - s.Require().NoError(err) - s.Equal(uint64(1234), params.VotePeriod) - - // Vote Threshold - params, err = s.nibiru.OracleKeeper.Params.Get(s.ctx) - s.Require().NoError(err) - s.Equal(sdk.OneDec().Quo(sdk.NewDec(3)), params.VoteThreshold) - - threshold := sdk.MustNewDecFromStr("0.4") - cwMsg = &bindings.EditOracleParams{ - VoteThreshold: &threshold, - } - - err = s.exec.SetOracleParams(cwMsg, s.ctx) - s.Require().NoError(err) - - params, err = s.nibiru.OracleKeeper.Params.Get(s.ctx) - s.Require().NoError(err) - s.Equal(threshold, params.VoteThreshold) - - // Reward Band - params, err = s.nibiru.OracleKeeper.Params.Get(s.ctx) - s.Require().NoError(err) - s.Equal(sdk.NewDecWithPrec(2, 2), params.RewardBand) - - band := sdk.MustNewDecFromStr("0.5") - cwMsg = &bindings.EditOracleParams{ - RewardBand: &band, - } - - err = s.exec.SetOracleParams(cwMsg, s.ctx) - s.Require().NoError(err) - - params, err = s.nibiru.OracleKeeper.Params.Get(s.ctx) - s.Require().NoError(err) - s.Equal(band, params.RewardBand) - - // White List - params, err = s.nibiru.OracleKeeper.Params.Get(s.ctx) - s.Require().NoError(err) - s.Assert().Equal(6, len(params.Whitelist)) - - whitelist := []string{"aave:usdc", "sol:usdc"} - cwMsg = &bindings.EditOracleParams{ - Whitelist: whitelist, - } - err = s.exec.SetOracleParams(cwMsg, s.ctx) - s.Require().NoError(err) - - params, err = s.nibiru.OracleKeeper.Params.Get(s.ctx) - s.Require().NoError(err) - s.Equal(2, len(params.Whitelist)) - - // Slash Fraction - params, err = s.nibiru.OracleKeeper.Params.Get(s.ctx) - s.Require().NoError(err) - s.Equal(sdk.NewDecWithPrec(5, 3), params.SlashFraction) - - slashFraction := sdk.MustNewDecFromStr("0.5") - cwMsg = &bindings.EditOracleParams{ - SlashFraction: &slashFraction, - } - - err = s.exec.SetOracleParams(cwMsg, s.ctx) - s.Require().NoError(err) - - params, err = s.nibiru.OracleKeeper.Params.Get(s.ctx) - s.Require().NoError(err) - s.Equal(slashFraction, params.SlashFraction) - - // Slash Window - params, err = s.nibiru.OracleKeeper.Params.Get(s.ctx) - s.Require().NoError(err) - s.Equal(uint64(3600), params.SlashWindow) - - slashWindow := sdk.NewInt(2) - cwMsg = &bindings.EditOracleParams{ - SlashWindow: &slashWindow, - } - - err = s.exec.SetOracleParams(cwMsg, s.ctx) - s.Require().NoError(err) - - params, err = s.nibiru.OracleKeeper.Params.Get(s.ctx) - s.Require().NoError(err) - s.Equal(slashWindow.Uint64(), params.SlashWindow) - - // Min valid per window - params, err = s.nibiru.OracleKeeper.Params.Get(s.ctx) - s.Require().NoError(err) - s.Equal(sdk.NewDecWithPrec(69, 2), params.MinValidPerWindow) - - minValidPerWindow := sdk.MustNewDecFromStr("0.5") - cwMsg = &bindings.EditOracleParams{ - MinValidPerWindow: &minValidPerWindow, - } - - err = s.exec.SetOracleParams(cwMsg, s.ctx) - s.Require().NoError(err) - - params, err = s.nibiru.OracleKeeper.Params.Get(s.ctx) - s.Require().NoError(err) - s.Equal(minValidPerWindow, params.MinValidPerWindow) - - // Twap lookback window - params, err = s.nibiru.OracleKeeper.Params.Get(s.ctx) - s.Require().NoError(err) - s.Equal(time.Minute*15, params.TwapLookbackWindow) - - twapLookbackWindow := sdk.NewInt(int64(time.Second * 30)) - cwMsg = &bindings.EditOracleParams{ - TwapLookbackWindow: &twapLookbackWindow, - } - - err = s.exec.SetOracleParams(cwMsg, s.ctx) - s.Require().NoError(err) - - params, err = s.nibiru.OracleKeeper.Params.Get(s.ctx) - s.Require().NoError(err) - s.Equal(time.Duration(twapLookbackWindow.Int64()), params.TwapLookbackWindow) - - // Min Voters - params, err = s.nibiru.OracleKeeper.Params.Get(s.ctx) - s.Require().NoError(err) - s.Equal(uint64(4), params.MinVoters) - - minVoters := sdk.NewInt(2) - cwMsg = &bindings.EditOracleParams{ - MinVoters: &minVoters, - } - - err = s.exec.SetOracleParams(cwMsg, s.ctx) - s.Require().NoError(err) - - params, err = s.nibiru.OracleKeeper.Params.Get(s.ctx) - s.Require().NoError(err) - s.Equal(minVoters.Uint64(), params.MinVoters) - - // Validator Fee Ratio - params, err = s.nibiru.OracleKeeper.Params.Get(s.ctx) - s.Require().NoError(err) - s.Equal(sdk.NewDecWithPrec(5, 2), params.ValidatorFeeRatio) - - validatorFeeRatio := sdk.MustNewDecFromStr("0.7") - cwMsg = &bindings.EditOracleParams{ - ValidatorFeeRatio: &validatorFeeRatio, - } - - err = s.exec.SetOracleParams(cwMsg, s.ctx) - s.Require().NoError(err) - - params, err = s.nibiru.OracleKeeper.Params.Get(s.ctx) - s.Require().NoError(err) - s.Equal(validatorFeeRatio, params.ValidatorFeeRatio) -} diff --git a/wasmbinding/exec_perp.go b/wasmbinding/exec_perp.go deleted file mode 100644 index da485fda1..000000000 --- a/wasmbinding/exec_perp.go +++ /dev/null @@ -1,14 +0,0 @@ -package wasmbinding - -import ( - perpv2keeper "github.com/NibiruChain/nibiru/x/perp/v2/keeper" - perpv2types "github.com/NibiruChain/nibiru/x/perp/v2/types" -) - -type ExecutorPerp struct { - PerpV2 perpv2keeper.Keeper -} - -func (exec *ExecutorPerp) MsgServer() perpv2types.MsgServer { - return perpv2keeper.NewMsgServerImpl(exec.PerpV2) -} diff --git a/wasmbinding/exec_perp_test.go b/wasmbinding/exec_perp_test.go deleted file mode 100644 index 5848cde59..000000000 --- a/wasmbinding/exec_perp_test.go +++ /dev/null @@ -1,131 +0,0 @@ -package wasmbinding_test - -import ( - "testing" - "time" - - sdkmath "cosmossdk.io/math" - tmproto "github.com/cometbft/cometbft/proto/tendermint/types" - sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/stretchr/testify/suite" - - "github.com/NibiruChain/nibiru/app" - "github.com/NibiruChain/nibiru/wasmbinding" - "github.com/NibiruChain/nibiru/wasmbinding/wasmbin" - "github.com/NibiruChain/nibiru/x/common/asset" - "github.com/NibiruChain/nibiru/x/common/denoms" - "github.com/NibiruChain/nibiru/x/common/testutil" - "github.com/NibiruChain/nibiru/x/common/testutil/genesis" - "github.com/NibiruChain/nibiru/x/common/testutil/testapp" - oracletypes "github.com/NibiruChain/nibiru/x/oracle/types" - perpv2types "github.com/NibiruChain/nibiru/x/perp/v2/types" -) - -func TestSuitePerpExecutor_RunAll(t *testing.T) { - suite.Run(t, new(TestSuitePerpExecutor)) -} - -type TestSuitePerpExecutor struct { - suite.Suite - - nibiru *app.NibiruApp - ctx sdk.Context - contractDeployer sdk.AccAddress - exec *wasmbinding.ExecutorPerp - - contractPerp sdk.AccAddress - ratesMap map[asset.Pair]sdk.Dec - happyFields ExampleFields -} - -func SetExchangeRates( - testSuite *suite.Suite, - nibiru *app.NibiruApp, - ctx sdk.Context, -) (exchangeRateMap map[asset.Pair]sdk.Dec) { - s := testSuite - exchangeRateTuples := []oracletypes.ExchangeRateTuple{ - { - Pair: asset.Registry.Pair(denoms.ETH, denoms.NUSD), - ExchangeRate: sdk.NewDec(1_000), - }, - { - Pair: asset.Registry.Pair(denoms.NIBI, denoms.NUSD), - ExchangeRate: sdk.NewDec(10), - }, - } - - for _, exchangeRateTuple := range exchangeRateTuples { - pair := exchangeRateTuple.Pair - exchangeRate := exchangeRateTuple.ExchangeRate - nibiru.OracleKeeper.SetPrice(ctx, pair, exchangeRate) - - rate, err := nibiru.OracleKeeper.ExchangeRates.Get(ctx, pair) - s.Assert().NoError(err) - s.Assert().EqualValues(exchangeRate, rate.ExchangeRate) - } - - return oracletypes.ExchangeRateTuples(exchangeRateTuples).ToMap() -} - -type ExampleFields struct { - Pair string - Trader sdk.AccAddress - Dec sdk.Dec - Int sdkmath.Int -} - -func GetHappyFields() ExampleFields { - return ExampleFields{ - Pair: asset.Registry.Pair(denoms.ETH, denoms.NUSD).String(), - Trader: sdk.AccAddress([]byte("trader")), - Dec: sdk.NewDec(50), - Int: sdk.NewInt(420), - } -} - -func SetupPerpGenesis() app.GenesisState { - genesisState := genesis.NewTestGenesisState(app.MakeEncodingConfig()) - genesisState = genesis.AddOracleGenesis(genesisState) - genesisState = genesis.AddPerpV2Genesis(genesisState) - return genesisState -} - -func (s *TestSuitePerpExecutor) SetupSuite() { - s.happyFields = GetHappyFields() - sender := testutil.AccAddress() - s.contractDeployer = sender - - genesisState := SetupPerpGenesis() - nibiru := testapp.NewNibiruTestApp(genesisState) - ctx := nibiru.NewContext(false, tmproto.Header{ - Height: 1, - ChainID: "nibiru-wasmnet-1", - Time: time.Now().UTC(), - }) - coins := sdk.NewCoins( - sdk.NewCoin(denoms.NIBI, sdk.NewInt(1_000_000)), - sdk.NewCoin(perpv2types.TestingCollateralDenomNUSD, sdk.NewInt(420_000*69)), - sdk.NewCoin(denoms.USDT, sdk.NewInt(420_000*69)), - ) - s.NoError(testapp.FundAccount(nibiru.BankKeeper, ctx, sender, coins)) - - nibiru, ctx = SetupAllContracts(s.T(), sender, nibiru, ctx) - s.nibiru = nibiru - s.ctx = ctx - s.contractPerp = ContractMap[wasmbin.WasmKeyPerpBinding] - - s.NoError(testapp.FundAccount(nibiru.BankKeeper, ctx, s.contractPerp, coins)) - s.exec = &wasmbinding.ExecutorPerp{ - PerpV2: nibiru.PerpKeeperV2, - } - s.nibiru.PerpKeeperV2.Collateral.Set(s.ctx, perpv2types.TestingCollateralDenomNUSD) - s.NoError(testapp.FundAccount(nibiru.BankKeeper, ctx, s.contractPerp, coins)) - - s.OnSetupEnd() -} - -func (s *TestSuitePerpExecutor) OnSetupEnd() { - s.contractPerp = ContractMap[wasmbin.WasmKeyPerpBinding] - s.ratesMap = SetExchangeRates(&s.Suite, s.nibiru, s.ctx) -} diff --git a/wasmbinding/exec_test.go b/wasmbinding/exec_test.go deleted file mode 100644 index cecf66007..000000000 --- a/wasmbinding/exec_test.go +++ /dev/null @@ -1,313 +0,0 @@ -package wasmbinding_test - -import ( - "encoding/json" - "testing" - "time" - - wasmkeeper "github.com/CosmWasm/wasmd/x/wasm/keeper" - tmproto "github.com/cometbft/cometbft/proto/tendermint/types" - sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/stretchr/testify/suite" - - "github.com/NibiruChain/nibiru/app" - "github.com/NibiruChain/nibiru/wasmbinding/bindings" - "github.com/NibiruChain/nibiru/wasmbinding/wasmbin" - "github.com/NibiruChain/nibiru/x/common/asset" - "github.com/NibiruChain/nibiru/x/common/denoms" - "github.com/NibiruChain/nibiru/x/common/testutil" - "github.com/NibiruChain/nibiru/x/common/testutil/testapp" - "github.com/NibiruChain/nibiru/x/oracle/types" - perpv2types "github.com/NibiruChain/nibiru/x/perp/v2/types" - sudokeeper "github.com/NibiruChain/nibiru/x/sudo/keeper" - sudotypes "github.com/NibiruChain/nibiru/x/sudo/types" -) - -// Keeper only used for testing, never for production -type TestOnlySudoKeeper struct { - sudokeeper.Keeper -} - -// SetSudoContracts overwrites the state. This function is a convenience -// function for testing with permissioned contracts in other modules.. -func (k TestOnlySudoKeeper) SetSudoContracts(contracts []string, ctx sdk.Context) { - k.Sudoers.Set(ctx, sudotypes.Sudoers{ - Root: "", - Contracts: contracts, - }) -} - -func TestSuiteExecutor_RunAll(t *testing.T) { - suite.Run(t, new(TestSuiteExecutor)) -} - -func DoCustomBindingExecute( - ctx sdk.Context, - nibiru *app.NibiruApp, - contract sdk.AccAddress, - sender sdk.AccAddress, - cwMsg bindings.NibiruMsg, - funds sdk.Coins, -) (contractRespBz []byte, err error) { - jsonCwMsg, err := json.Marshal(cwMsg) - if err != nil { - return contractRespBz, err - } - - if err := funds.Validate(); err != nil { - return contractRespBz, err - } - - return wasmkeeper.NewDefaultPermissionKeeper(nibiru.WasmKeeper). - Execute(ctx, contract, sender, jsonCwMsg, funds) -} - -func (s *TestSuiteExecutor) ExecuteAgainstContract( - contract sdk.AccAddress, execMsg bindings.NibiruMsg, -) (contractRespBz []byte, err error) { - return DoCustomBindingExecute( - s.ctx, s.nibiru, contract, s.contractDeployer, execMsg, sdk.Coins{}) -} - -type TestSuiteExecutor struct { - suite.Suite - - nibiru *app.NibiruApp - ctx sdk.Context - contractDeployer sdk.AccAddress - - keeper TestOnlySudoKeeper - wasmKeeper *wasmkeeper.PermissionedKeeper - - contractPerp sdk.AccAddress - contractController sdk.AccAddress - contractShifter sdk.AccAddress - happyFields ExampleFields -} - -func (s *TestSuiteExecutor) SetupSuite() { - s.happyFields = GetHappyFields() - sender := testutil.AccAddress() - s.contractDeployer = sender - - genesisState := SetupPerpGenesis() - nibiru := testapp.NewNibiruTestApp(genesisState) - ctx := nibiru.NewContext(false, tmproto.Header{ - Height: 1, - ChainID: "nibiru-wasmnet-1", - Time: time.Now().UTC(), - }) - nibiru.PerpKeeperV2.Collateral.Set(ctx, perpv2types.TestingCollateralDenomNUSD) - - coins := sdk.NewCoins( - sdk.NewCoin(denoms.NIBI, sdk.NewInt(10_000_000)), - sdk.NewCoin(perpv2types.TestingCollateralDenomNUSD, sdk.NewInt(420_000*69)), - ) - - s.NoError(testapp.FundAccount(nibiru.BankKeeper, ctx, sender, coins)) - - nibiru, ctx = SetupAllContracts(s.T(), sender, nibiru, ctx) - s.nibiru = nibiru - s.ctx = ctx - s.keeper = TestOnlySudoKeeper{Keeper: s.nibiru.SudoKeeper} - s.wasmKeeper = wasmkeeper.NewDefaultPermissionKeeper(nibiru.WasmKeeper) - s.nibiru.PerpKeeperV2.Collateral.Set(s.ctx, perpv2types.TestingCollateralDenomNUSD) - - s.contractPerp = ContractMap[wasmbin.WasmKeyPerpBinding] - s.contractController = ContractMap[wasmbin.WasmKeyController] - s.contractShifter = ContractMap[wasmbin.WasmKeyShifter] - s.contractController = ContractMap[wasmbin.WasmKeyController] - s.T().Logf("contract bindings-perp: %s", s.contractPerp) - s.T().Logf("contract shifter: %s", s.contractShifter) - s.OnSetupEnd() -} - -func (s *TestSuiteExecutor) OnSetupEnd() { - SetExchangeRates(&s.Suite, s.nibiru, s.ctx) -} - -func (s *TestSuiteExecutor) TestOracleParams() { - defaultParams := types.DefaultParams() - defaultParams.VotePeriod = 1_000 - theVotePeriod := sdk.NewInt(1234) - execMsg := bindings.NibiruMsg{ - EditOracleParams: &bindings.EditOracleParams{ - VotePeriod: &theVotePeriod, - }, - } - - params, err := s.nibiru.OracleKeeper.Params.Get(s.ctx) - s.Require().NoError(err) - s.Require().Equal(defaultParams, params) - - s.T().Log("Executing without permission should fail") - s.keeper.SetSudoContracts( - []string{}, s.ctx, - ) - contractRespBz, err := s.ExecuteAgainstContract(s.contractController, execMsg) - s.Errorf(err, "contractRespBz: %s", contractRespBz) - - s.T().Log("Executing with permission should succeed") - s.keeper.SetSudoContracts( - []string{s.contractController.String()}, s.ctx, - ) - - // VotePeriod should be updated - theVotePeriod = sdk.NewInt(1234) - execMsg = bindings.NibiruMsg{ - EditOracleParams: &bindings.EditOracleParams{ - VotePeriod: &theVotePeriod, - }, - } - - contractRespBz, err = s.ExecuteAgainstContract(s.contractController, execMsg) - s.NoErrorf(err, "contractRespBz: %s", contractRespBz) - - params, err = s.nibiru.OracleKeeper.Params.Get(s.ctx) - s.Require().NoError(err) - s.Require().Equal(uint64(1_234), params.VotePeriod) - - // VoteThreshold should be updated - theVoteThreshold := sdk.NewDecWithPrec(1, 1) - execMsg = bindings.NibiruMsg{ - EditOracleParams: &bindings.EditOracleParams{ - VoteThreshold: &theVoteThreshold, - }, - } - - contractRespBz, err = s.ExecuteAgainstContract(s.contractController, execMsg) - s.NoErrorf(err, "contractRespBz: %s", contractRespBz) - - params, err = s.nibiru.OracleKeeper.Params.Get(s.ctx) - s.Require().NoError(err) - s.Require().Equal(theVoteThreshold, params.VoteThreshold) - - // RewardBand should be updated - theRewardBand := sdk.NewDecWithPrec(1, 1) - execMsg = bindings.NibiruMsg{ - EditOracleParams: &bindings.EditOracleParams{ - RewardBand: &theRewardBand, - }, - } - - contractRespBz, err = s.ExecuteAgainstContract(s.contractController, execMsg) - s.NoErrorf(err, "contractRespBz: %s", contractRespBz) - - params, err = s.nibiru.OracleKeeper.Params.Get(s.ctx) - s.Require().NoError(err) - s.Require().Equal(theRewardBand, params.RewardBand) - - // Whitelist should be updated - theWhitelist := []string{"BTC:USDC"} - execMsg = bindings.NibiruMsg{ - EditOracleParams: &bindings.EditOracleParams{ - Whitelist: theWhitelist, - }, - } - - contractRespBz, err = s.ExecuteAgainstContract(s.contractController, execMsg) - s.NoErrorf(err, "contractRespBz: %s", contractRespBz) - - params, err = s.nibiru.OracleKeeper.Params.Get(s.ctx) - s.Require().NoError(err) - s.Require().Equal([]asset.Pair{asset.NewPair("BTC", "USDC")}, params.Whitelist) - - // SlashFraction should be updated - theSlashFraction := sdk.NewDecWithPrec(1, 4) - execMsg = bindings.NibiruMsg{ - EditOracleParams: &bindings.EditOracleParams{ - SlashFraction: &theSlashFraction, - }, - } - - contractRespBz, err = s.ExecuteAgainstContract(s.contractController, execMsg) - s.NoErrorf(err, "contractRespBz: %s", contractRespBz) - - params, err = s.nibiru.OracleKeeper.Params.Get(s.ctx) - s.Require().NoError(err) - s.Require().Equal(theSlashFraction, params.SlashFraction) - - // SlashWindow should be updated - theSlashWindow := sdk.NewInt(1234) - execMsg = bindings.NibiruMsg{ - EditOracleParams: &bindings.EditOracleParams{ - SlashWindow: &theSlashWindow, - }, - } - - contractRespBz, err = s.ExecuteAgainstContract(s.contractController, execMsg) - s.NoErrorf(err, "contractRespBz: %s", contractRespBz) - - params, err = s.nibiru.OracleKeeper.Params.Get(s.ctx) - s.Require().NoError(err) - s.Require().Equal(uint64(1234), params.SlashWindow) - - // MinValidPerWindow should be updated - theMinValidPerWindow := sdk.NewDecWithPrec(1, 4) - execMsg = bindings.NibiruMsg{ - EditOracleParams: &bindings.EditOracleParams{ - MinValidPerWindow: &theMinValidPerWindow, - }, - } - - contractRespBz, err = s.ExecuteAgainstContract(s.contractController, execMsg) - s.NoErrorf(err, "contractRespBz: %s", contractRespBz) - - params, err = s.nibiru.OracleKeeper.Params.Get(s.ctx) - s.Require().NoError(err) - s.Require().Equal(theMinValidPerWindow, params.MinValidPerWindow) - - // TwapLookback should be updated - theTwapLookback := sdk.NewInt(1234) - execMsg = bindings.NibiruMsg{ - EditOracleParams: &bindings.EditOracleParams{ - TwapLookbackWindow: &theTwapLookback, - }, - } - - contractRespBz, err = s.ExecuteAgainstContract(s.contractController, execMsg) - s.NoErrorf(err, "contractRespBz: %s", contractRespBz) - - params, err = s.nibiru.OracleKeeper.Params.Get(s.ctx) - s.Require().NoError(err) - s.Require().Equal(time.Duration(1234), params.TwapLookbackWindow) - - // MinVoters should be updated - theMinVoters := sdk.NewInt(1234) - execMsg = bindings.NibiruMsg{ - EditOracleParams: &bindings.EditOracleParams{ - MinVoters: &theMinVoters, - }, - } - - contractRespBz, err = s.ExecuteAgainstContract(s.contractController, execMsg) - s.NoErrorf(err, "contractRespBz: %s", contractRespBz) - - params, err = s.nibiru.OracleKeeper.Params.Get(s.ctx) - s.Require().NoError(err) - s.Require().Equal(uint64(1234), params.MinVoters) - - // Validator Fee Ratio should be updated - theValidatorFeeRatio := sdk.NewDecWithPrec(1, 4) - execMsg = bindings.NibiruMsg{ - EditOracleParams: &bindings.EditOracleParams{ - ValidatorFeeRatio: &theValidatorFeeRatio, - }, - } - - contractRespBz, err = s.ExecuteAgainstContract(s.contractController, execMsg) - s.NoErrorf(err, "contractRespBz: %s", contractRespBz) - - params, err = s.nibiru.OracleKeeper.Params.Get(s.ctx) - s.Require().NoError(err) - s.Require().Equal(theValidatorFeeRatio, params.ValidatorFeeRatio) -} - -func (s *TestSuiteExecutor) TestNoOp() { - contract := s.contractShifter - execMsg := bindings.NibiruMsg{ - NoOp: &bindings.NoOp{}, - } - contractRespBz, err := s.ExecuteAgainstContract(contract, execMsg) - s.NoErrorf(err, "contractRespBz: %s", contractRespBz) -} diff --git a/wasmbinding/message_plugin.go b/wasmbinding/message_plugin.go deleted file mode 100644 index 05e9c1162..000000000 --- a/wasmbinding/message_plugin.go +++ /dev/null @@ -1,100 +0,0 @@ -package wasmbinding - -import ( - "encoding/json" - - "github.com/NibiruChain/nibiru/wasmbinding/bindings" - "github.com/NibiruChain/nibiru/x/sudo/keeper" - - sdkerrors "cosmossdk.io/errors" - wasmkeeper "github.com/CosmWasm/wasmd/x/wasm/keeper" - wasmvmtypes "github.com/CosmWasm/wasmvm/types" - sdk "github.com/cosmos/cosmos-sdk/types" - - oraclekeeper "github.com/NibiruChain/nibiru/x/oracle/keeper" - perpv2keeper "github.com/NibiruChain/nibiru/x/perp/v2/keeper" -) - -var _ wasmkeeper.Messenger = (*CustomMessenger)(nil) - -// CustomMessenger is an extension of wasm/keeper.Messenger with its -// own custom `DispatchMsg` for CosmWasm execute calls on Nibiru. -type CustomMessenger struct { - Wasm wasmkeeper.Messenger - Perp ExecutorPerp - Sudo keeper.Keeper - Oracle ExecutorOracle -} - -// NibiruMsgWrapper is a n override of CosmosMsg::Custom -// (json.RawMessage), which corresponds to `NibiruMsgWrapper` in -// the bindings-perp.rs contract. -type NibiruMsgWrapper struct { - // Routes here refer to groups of modules on Nibiru. The idea behind setting - // routes alongside the messae payload is to add information on which module - // or group of modules a particular execute message belongs to. - // For example, the perp bindings have route "perp". - Route *string `json:"route,omitempty"` - // ExecuteMsg is a json struct for ExecuteMsg::{ - // MarketOrder, ClosePosition, AddMargin, RemoveMargin, ...} from the - // bindings smart contracts. - ExecuteMsg *bindings.NibiruMsg `json:"msg,omitempty"` -} - -// DispatchMsg encodes the wasmVM message and dispatches it. -func (messenger *CustomMessenger) DispatchMsg( - ctx sdk.Context, - contractAddr sdk.AccAddress, - contractIBCPortID string, - wasmMsg wasmvmtypes.CosmosMsg, -) (events []sdk.Event, data [][]byte, err error) { - // If the "Custom" field is set, we handle a BindingMsg. - if wasmMsg.Custom != nil { - var contractExecuteMsg NibiruMsgWrapper - if err := json.Unmarshal(wasmMsg.Custom, &contractExecuteMsg); err != nil { - return events, data, sdkerrors.Wrapf(err, "wasmMsg: %s", wasmMsg.Custom) - } - - isNoOp := contractExecuteMsg.ExecuteMsg == nil || contractExecuteMsg.ExecuteMsg.NoOp != nil - if isNoOp { - ctx.Logger().Info("execute DispatchMsg: NoOp (no operation)") - return events, data, nil - } - - switch { - // Oracle module - case contractExecuteMsg.ExecuteMsg.EditOracleParams != nil: - if err := messenger.Sudo.CheckPermissions(contractAddr, ctx); err != nil { - return events, data, err - } - cwMsg := contractExecuteMsg.ExecuteMsg.EditOracleParams - err = messenger.Oracle.SetOracleParams(cwMsg, ctx) - return events, data, err - - default: - err = wasmvmtypes.InvalidRequest{ - Err: "invalid bindings request", - Request: wasmMsg.Custom, - } - return events, data, err - } - } - - // The default execution path is to use the wasmkeeper.Messenger. - return messenger.Wasm.DispatchMsg(ctx, contractAddr, contractIBCPortID, wasmMsg) -} - -func CustomMessageDecorator( - perpv2 perpv2keeper.Keeper, - sudoKeeper keeper.Keeper, - oracleKeeper oraclekeeper.Keeper, -) func(wasmkeeper.Messenger) wasmkeeper.Messenger { - return func(originalWasmMessenger wasmkeeper.Messenger) wasmkeeper.Messenger { - return &CustomMessenger{ - Wasm: originalWasmMessenger, - Perp: ExecutorPerp{PerpV2: perpv2}, - Sudo: sudoKeeper, - Oracle: ExecutorOracle{Oracle: oracleKeeper}, - } - } -} diff --git a/wasmbinding/wasmbin/bindings_perp.wasm b/wasmbinding/wasmbin/bindings_perp.wasm deleted file mode 100644 index 4d20de3af..000000000 Binary files a/wasmbinding/wasmbin/bindings_perp.wasm and /dev/null differ diff --git a/wasmbinding/wasmbin/contracts.go b/wasmbinding/wasmbin/contracts.go deleted file mode 100644 index 07433b5ba..000000000 --- a/wasmbinding/wasmbin/contracts.go +++ /dev/null @@ -1,36 +0,0 @@ -package wasmbin - -import ( - "os" - "strings" -) - -// WasmKey is an enum type for the available module binding contracts. -type WasmKey int - -const ( - WasmKeyPerpBinding WasmKey = iota - WasmKeyShifter - WasmKeyController - // WasmKeyEpochsBinding // for example... -) - -// Returns a relative file path to compile Wasm bytecode. Wasm bytecode refers -// to compiled WebAssembly binary format that can be executed on the Wasm VM. -func (wasmKey WasmKey) ToPath(pathToWasmbin string) string { - wasmFileName := WasmBzMap[wasmKey] - return strings.Join([]string{pathToWasmbin, wasmFileName}, "/") -} - -// Returns the Wasm bytecode corresponding to the WasmKey. This can be stored -// directly with the WasmKeeper. -func (wasmKey WasmKey) ToByteCode(pathToWasmbin string) (wasmBytecode []byte, err error) { - return os.ReadFile(wasmKey.ToPath(pathToWasmbin)) -} - -// WasmBzMap is a map from WasmKey to the filename for its wasm bytecode. -var WasmBzMap = map[WasmKey]string{ - WasmKeyPerpBinding: "bindings_perp.wasm", - WasmKeyShifter: "shifter.wasm", - WasmKeyController: "controller.wasm", -} diff --git a/wasmbinding/wasmbin/contracts_test.go b/wasmbinding/wasmbin/contracts_test.go deleted file mode 100644 index f266d1f05..000000000 --- a/wasmbinding/wasmbin/contracts_test.go +++ /dev/null @@ -1,35 +0,0 @@ -package wasmbin_test - -import ( - "fmt" - "os" - "testing" - - "github.com/stretchr/testify/assert" - - "github.com/NibiruChain/nibiru/wasmbinding/wasmbin" -) - -func TestExpectedBytecodeExists(t *testing.T) { - wasmKeys := []wasmbin.WasmKey{ - wasmbin.WasmKeyPerpBinding, - } - - for _, wasmKey := range wasmKeys { - testName := wasmbin.WasmBzMap[wasmKey] - t.Run(testName, func(t *testing.T) { - pathToWasmbin := wasmbin.GetPackageDir(t) - pathToWasmBytecode := wasmKey.ToPath(pathToWasmbin) - _, err := os.Stat(pathToWasmBytecode) - errMsg := "" - if os.IsNotExist(err) { - fileName := testName - errMsg = fmt.Sprintf("File %s does not exist\n", fileName) - } - assert.NoErrorf(t, err, errMsg) - - _, err = wasmKey.ToByteCode(pathToWasmbin) - assert.NoError(t, err) - }) - } -} diff --git a/wasmbinding/wasmbin/controller.wasm b/wasmbinding/wasmbin/controller.wasm deleted file mode 100644 index 053eab413..000000000 Binary files a/wasmbinding/wasmbin/controller.wasm and /dev/null differ diff --git a/wasmbinding/wasmbin/export.go b/wasmbinding/wasmbin/export.go deleted file mode 100644 index 8c9546cff..000000000 --- a/wasmbinding/wasmbin/export.go +++ /dev/null @@ -1,22 +0,0 @@ -package wasmbin - -import ( - "path" - "path/filepath" - "runtime" - "testing" - - "github.com/stretchr/testify/require" -) - -func GetPackageDir(t *testing.T) string { - // Get the import path of the current package - _, filename, _, _ := runtime.Caller(0) - pkgDir := path.Dir(filename) - pkgPath := path.Join(path.Base(pkgDir), "..") - - // Get the directory path of the package - absPkgPath, err := filepath.Abs(pkgPath) - require.NoError(t, err) - return absPkgPath -} diff --git a/wasmbinding/wasmbin/shifter.wasm b/wasmbinding/wasmbin/shifter.wasm deleted file mode 100644 index 11df9614e..000000000 Binary files a/wasmbinding/wasmbin/shifter.wasm and /dev/null differ diff --git a/wasmbinding/wasmbin_test.go b/wasmbinding/wasmbin_test.go deleted file mode 100644 index 3b4c50532..000000000 --- a/wasmbinding/wasmbin_test.go +++ /dev/null @@ -1,142 +0,0 @@ -package wasmbinding_test - -import ( - "fmt" - "testing" - "time" - - wasmkeeper "github.com/CosmWasm/wasmd/x/wasm/keeper" - wasmtypes "github.com/CosmWasm/wasmd/x/wasm/types" - tmproto "github.com/cometbft/cometbft/proto/tendermint/types" - sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/stretchr/testify/require" - - "github.com/NibiruChain/nibiru/app" - "github.com/NibiruChain/nibiru/wasmbinding/wasmbin" - "github.com/NibiruChain/nibiru/x/common/denoms" - "github.com/NibiruChain/nibiru/x/common/testutil" - "github.com/NibiruChain/nibiru/x/common/testutil/testapp" -) - -func init() { - testapp.EnsureNibiruPrefix() -} - -// TestSetupContracts acts as an integration test by storing and instantiating -// each production smart contract is expected to interact with x/wasm/binding. -func TestSetupContracts(t *testing.T) { - sender := testutil.AccAddress() - nibiru, _ := testapp.NewNibiruTestAppAndContext() - ctx := nibiru.NewContext(false, tmproto.Header{ - Height: 1, - ChainID: "nibiru-wasmnet-1", - Time: time.Now().UTC(), - }) - coins := sdk.NewCoins(sdk.NewCoin(denoms.NIBI, sdk.NewInt(10))) - require.NoError(t, testapp.FundAccount(nibiru.BankKeeper, ctx, sender, coins)) - _, _ = SetupAllContracts(t, sender, nibiru, ctx) -} - -var ContractMap = make(map[wasmbin.WasmKey]sdk.AccAddress) - -// SetupAllContracts stores and instantiates all of wasm binding contracts. -func SetupAllContracts( - t *testing.T, sender sdk.AccAddress, nibiru *app.NibiruApp, ctx sdk.Context, -) (*app.NibiruApp, sdk.Context) { - wasmKey := wasmbin.WasmKeyPerpBinding - codeId := StoreContract(t, wasmKey, ctx, nibiru, sender) - deposit := sdk.NewCoins(sdk.NewCoin(denoms.NIBI, sdk.OneInt())) - contract := Instantiate.PerpBindingContract(t, ctx, nibiru, codeId, sender, deposit) - ContractMap[wasmKey] = contract - - wasmKey = wasmbin.WasmKeyShifter - codeId = StoreContract(t, wasmKey, ctx, nibiru, sender) - contract = Instantiate.ShifterContract(t, ctx, nibiru, codeId, sender, deposit) - ContractMap[wasmKey] = contract - - wasmKey = wasmbin.WasmKeyController - codeId = StoreContract(t, wasmKey, ctx, nibiru, sender) - contract = Instantiate.ControllerContract(t, ctx, nibiru, codeId, sender, deposit) - ContractMap[wasmKey] = contract - - return nibiru, ctx -} - -// StoreContract submits Wasm bytecode for storage on the chain. -func StoreContract( - t *testing.T, - wasmKey wasmbin.WasmKey, - ctx sdk.Context, - nibiru *app.NibiruApp, - sender sdk.AccAddress, -) (codeId uint64) { - pathToWasmBin := wasmbin.GetPackageDir(t) + "/wasmbin" - wasmBytecode, err := wasmKey.ToByteCode(pathToWasmBin) - require.NoError(t, err) - - // The "Create" fn is private on the nibiru.WasmKeeper. By placing it as the - // decorated keeper in PermissionedKeeper type, we can access "Create" as a - // public fn. - wasmPermissionedKeeper := wasmkeeper.NewDefaultPermissionKeeper(nibiru.WasmKeeper) - instantiateAccess := &wasmtypes.AccessConfig{ - Permission: wasmtypes.AccessTypeEverybody, - } - codeId, _, err = wasmPermissionedKeeper.Create( - ctx, sender, wasmBytecode, instantiateAccess, - ) - require.NoError(t, err) - return codeId -} - -func InstantiateContract( - t *testing.T, ctx sdk.Context, nibiru *app.NibiruApp, codeId uint64, - initMsg []byte, sender sdk.AccAddress, label string, deposit sdk.Coins, -) (contractAddr sdk.AccAddress) { - wasmPermissionedKeeper := wasmkeeper.NewDefaultPermissionKeeper(nibiru.WasmKeeper) - contractAddr, _, err := wasmPermissionedKeeper.Instantiate( - ctx, codeId, sender, sender, initMsg, label, deposit, - ) - require.NoError(t, err) - return contractAddr -} - -// Instantiate is a empty struct type with conventience functions for -// instantiating specific smart contracts. -var Instantiate = inst{} - -type inst struct{} - -func (i inst) PerpBindingContract( - t *testing.T, ctx sdk.Context, nibiru *app.NibiruApp, codeId uint64, - sender sdk.AccAddress, deposit sdk.Coins, -) (contractAddr sdk.AccAddress) { - initMsg := []byte("{}") - label := "x/perp module bindings" - return InstantiateContract( - t, ctx, nibiru, codeId, initMsg, sender, label, deposit, - ) -} - -// Instantiates the shifter contract with the sender set as the admin. -func (i inst) ShifterContract( - t *testing.T, ctx sdk.Context, nibiru *app.NibiruApp, codeId uint64, - sender sdk.AccAddress, deposit sdk.Coins, -) (contractAddr sdk.AccAddress) { - initMsg := []byte(fmt.Sprintf(`{ "admin": "%s"}`, sender)) - label := "contract for calling peg shift and depth shift in x/perp" - return InstantiateContract( - t, ctx, nibiru, codeId, initMsg, sender, label, deposit, - ) -} - -// Instantiates the controller contract with the sender set as the admin. -func (i inst) ControllerContract( - t *testing.T, ctx sdk.Context, nibiru *app.NibiruApp, codeId uint64, - sender sdk.AccAddress, deposit sdk.Coins, -) (contractAddr sdk.AccAddress) { - initMsg := []byte(fmt.Sprintf(`{ "admin": "%s"}`, sender)) - label := "contract for admin functions" - return InstantiateContract( - t, ctx, nibiru, codeId, initMsg, sender, label, deposit, - ) -} diff --git a/x/tokenfactory/keeper/msg_server.go b/x/tokenfactory/keeper/msg_server.go index 9f0a939b1..2ef592a2e 100644 --- a/x/tokenfactory/keeper/msg_server.go +++ b/x/tokenfactory/keeper/msg_server.go @@ -22,7 +22,7 @@ func (k Keeper) CreateDenom( return resp, errNilMsg } if err := txMsg.ValidateBasic(); err != nil { - return resp, err // ValidateBasic needs to be guaranteed for Wasm bindings + return resp, err } ctx := sdk.UnwrapSDKContext(goCtx) @@ -47,7 +47,7 @@ func (k Keeper) ChangeAdmin( return resp, errNilMsg } if err := txMsg.ValidateBasic(); err != nil { - return resp, err // ValidateBasic needs to be guaranteed for Wasm bindings + return resp, err } ctx := sdk.UnwrapSDKContext(goCtx) @@ -81,7 +81,7 @@ func (k Keeper) UpdateModuleParams( return resp, errNilMsg } if err := txMsg.ValidateBasic(); err != nil { - return resp, err // ValidateBasic needs to be guaranteed for Wasm bindings + return resp, err } if k.authority != txMsg.Authority { @@ -105,7 +105,7 @@ func (k Keeper) Mint( return resp, errNilMsg } if err := txMsg.ValidateBasic(); err != nil { - return resp, err // ValidateBasic needs to be guaranteed for Wasm bindings + return resp, err } ctx := sdk.UnwrapSDKContext(goCtx) @@ -178,7 +178,7 @@ func (k Keeper) Burn( return resp, errNilMsg } if err := txMsg.ValidateBasic(); err != nil { - return resp, err // ValidateBasic needs to be guaranteed for Wasm bindings + return resp, err } ctx := sdk.UnwrapSDKContext(goCtx) @@ -248,7 +248,7 @@ func (k Keeper) SetDenomMetadata( return resp, errNilMsg } if err := txMsg.ValidateBasic(); err != nil { - return resp, err // ValidateBasic needs to be guaranteed for Wasm bindings + return resp, err } ctx := sdk.UnwrapSDKContext(goCtx)