From f2b163e7de3002062036b8ef1be74fe62eec2b0f Mon Sep 17 00:00:00 2001 From: Puneet <59960662+puneet2019@users.noreply.github.com> Date: Wed, 20 Dec 2023 19:32:33 +0530 Subject: [PATCH] feat: create ratesync module. (#703) * create ratesync module. * add CHANGELOG.md * fix ibc routing issues, and fix portID representation. (#704) * update proto msg tags. id to i_d * fix: query name allhostchains * fix ibcrouting * more fixes * wire liquidstake keeper to ratesync keeper. * make time as int64 because wasm won't parse * register wasm types for unmarshalling * add wasm in app module so it will auto read codec. * fix: registerICA to use owner instead of portID * fix tests and code. * fix tests and code. * add more tests --- CHANGELOG.md | 1 + app/app.go | 55 +- app/const.go | 2 +- go.mod | 3 +- proto/pstake/ratesync/v1beta1/contract.proto | 28 + proto/pstake/ratesync/v1beta1/genesis.proto | 14 + proto/pstake/ratesync/v1beta1/params.proto | 14 + proto/pstake/ratesync/v1beta1/query.proto | 55 + proto/pstake/ratesync/v1beta1/ratesync.proto | 63 + proto/pstake/ratesync/v1beta1/tx.proto | 62 + x/liquidstakeibc/keeper/ibc.go | 6 +- x/liquidstakeibc/keeper/keeper.go | 2 +- x/liquidstakeibc/types/hooks.go | 6 +- x/ratesync/client/cli/query.go | 130 ++ x/ratesync/client/cli/tx.go | 194 ++ x/ratesync/genesis.go | 28 + x/ratesync/genesis_test.go | 43 + x/ratesync/keeper/abci.go | 46 + x/ratesync/keeper/chain.go | 101 + x/ratesync/keeper/chain_test.go | 86 + x/ratesync/keeper/hooks.go | 87 + x/ratesync/keeper/ibc.go | 422 +++++ x/ratesync/keeper/ica_tx.go | 172 ++ x/ratesync/keeper/keeper.go | 91 + x/ratesync/keeper/msg_server.go | 343 ++++ x/ratesync/keeper/msg_server_test.go | 150 ++ x/ratesync/keeper/params.go | 26 + x/ratesync/keeper/params_test.go | 14 + x/ratesync/keeper/query.go | 69 + x/ratesync/keeper/query_test.go | 117 ++ x/ratesync/keeper/setup_suite_test.go | 294 +++ x/ratesync/module.go | 152 ++ x/ratesync/module_ibc.go | 133 ++ x/ratesync/module_simulation.go | 85 + x/ratesync/simulation/helpers.go | 15 + x/ratesync/simulation/msg_update_params.go | 29 + x/ratesync/types/codec.go | 35 + x/ratesync/types/contract.pb.go | 819 ++++++++ x/ratesync/types/errors.go | 15 + x/ratesync/types/events.go | 34 + x/ratesync/types/expected_keepers.go | 45 + x/ratesync/types/genesis.go | 34 + x/ratesync/types/genesis.pb.go | 389 ++++ x/ratesync/types/genesis_test.go | 64 + x/ratesync/types/keys.go | 41 + x/ratesync/types/msgs.go | 206 ++ x/ratesync/types/msgs_test.go | 189 ++ x/ratesync/types/params.go | 34 + x/ratesync/types/params.pb.go | 323 ++++ x/ratesync/types/query.pb.go | 1374 ++++++++++++++ x/ratesync/types/query.pb.gw.go | 337 ++++ x/ratesync/types/ratesync.pb.go | 1394 ++++++++++++++ x/ratesync/types/tx.pb.go | 1752 ++++++++++++++++++ x/ratesync/types/types.go | 216 +++ x/ratesync/types/types_test.go | 45 + 55 files changed, 10457 insertions(+), 27 deletions(-) create mode 100644 proto/pstake/ratesync/v1beta1/contract.proto create mode 100644 proto/pstake/ratesync/v1beta1/genesis.proto create mode 100644 proto/pstake/ratesync/v1beta1/params.proto create mode 100644 proto/pstake/ratesync/v1beta1/query.proto create mode 100644 proto/pstake/ratesync/v1beta1/ratesync.proto create mode 100644 proto/pstake/ratesync/v1beta1/tx.proto create mode 100644 x/ratesync/client/cli/query.go create mode 100644 x/ratesync/client/cli/tx.go create mode 100644 x/ratesync/genesis.go create mode 100644 x/ratesync/genesis_test.go create mode 100644 x/ratesync/keeper/abci.go create mode 100644 x/ratesync/keeper/chain.go create mode 100644 x/ratesync/keeper/chain_test.go create mode 100644 x/ratesync/keeper/hooks.go create mode 100644 x/ratesync/keeper/ibc.go create mode 100644 x/ratesync/keeper/ica_tx.go create mode 100644 x/ratesync/keeper/keeper.go create mode 100644 x/ratesync/keeper/msg_server.go create mode 100644 x/ratesync/keeper/msg_server_test.go create mode 100644 x/ratesync/keeper/params.go create mode 100644 x/ratesync/keeper/params_test.go create mode 100644 x/ratesync/keeper/query.go create mode 100644 x/ratesync/keeper/query_test.go create mode 100644 x/ratesync/keeper/setup_suite_test.go create mode 100644 x/ratesync/module.go create mode 100644 x/ratesync/module_ibc.go create mode 100644 x/ratesync/module_simulation.go create mode 100644 x/ratesync/simulation/helpers.go create mode 100644 x/ratesync/simulation/msg_update_params.go create mode 100644 x/ratesync/types/codec.go create mode 100644 x/ratesync/types/contract.pb.go create mode 100644 x/ratesync/types/errors.go create mode 100644 x/ratesync/types/events.go create mode 100644 x/ratesync/types/expected_keepers.go create mode 100644 x/ratesync/types/genesis.go create mode 100644 x/ratesync/types/genesis.pb.go create mode 100644 x/ratesync/types/genesis_test.go create mode 100644 x/ratesync/types/keys.go create mode 100644 x/ratesync/types/msgs.go create mode 100644 x/ratesync/types/msgs_test.go create mode 100644 x/ratesync/types/params.go create mode 100644 x/ratesync/types/params.pb.go create mode 100644 x/ratesync/types/query.pb.go create mode 100644 x/ratesync/types/query.pb.gw.go create mode 100644 x/ratesync/types/ratesync.pb.go create mode 100644 x/ratesync/types/tx.pb.go create mode 100644 x/ratesync/types/types.go create mode 100644 x/ratesync/types/types_test.go diff --git a/CHANGELOG.md b/CHANGELOG.md index 25c753a92..70973d40a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -39,6 +39,7 @@ Ref: https://keepachangelog.com/en/1.0.0/ - [687](https://github.com/persistenceOne/pstake-native/pull/687) Add queries for redelegations and redelegation txs. - [696](https://github.com/persistenceOne/pstake-native/pull/696) Add capability to swap rewards. - [697](https://github.com/persistenceOne/pstake-native/pull/697) Add hooks for liquidstakeibc c_value updates. +- [703](https://github.com/persistenceOne/pstake-native/pull/703) Add ratesync module. ### Bug Fixes diff --git a/app/app.go b/app/app.go index 6444742ed..1d02344e0 100644 --- a/app/app.go +++ b/app/app.go @@ -10,6 +10,7 @@ import ( autocliv1 "cosmossdk.io/api/cosmos/autocli/v1" reflectionv1 "cosmossdk.io/api/cosmos/reflection/v1" + "github.com/CosmWasm/wasmd/x/wasm" dbm "github.com/cometbft/cometbft-db" abci "github.com/cometbft/cometbft/abci/types" tmjson "github.com/cometbft/cometbft/libs/json" @@ -133,7 +134,9 @@ import ( liquidstakeibckeeper "github.com/persistenceOne/pstake-native/v2/x/liquidstakeibc/keeper" liquidstakeibctypes "github.com/persistenceOne/pstake-native/v2/x/liquidstakeibc/types" "github.com/persistenceOne/pstake-native/v2/x/lscosmos" - lscosmostypes "github.com/persistenceOne/pstake-native/v2/x/lscosmos/types" + "github.com/persistenceOne/pstake-native/v2/x/ratesync" + ratesynckeeper "github.com/persistenceOne/pstake-native/v2/x/ratesync/keeper" + ratesynctypes "github.com/persistenceOne/pstake-native/v2/x/ratesync/types" ) var ( @@ -177,7 +180,9 @@ var ( lscosmos.AppModuleBasic{}, liquidstakeibc.AppModuleBasic{}, liquidstake.AppModuleBasic{}, + ratesync.AppModuleBasic{}, consensus.AppModuleBasic{}, + wasm.AppModuleBasic{}, ) // module account permissions @@ -252,6 +257,7 @@ type PstakeApp struct { InterchainQueryKeeper interchainquerykeeper.Keeper LiquidStakeIBCKeeper liquidstakeibckeeper.Keeper LiquidStakeKeeper liquidstakekeeper.Keeper + RatesyncKeeper *ratesynckeeper.Keeper // make scoped keepers public for test purposes ScopedIBCKeeper capabilitykeeper.ScopedKeeper @@ -305,6 +311,7 @@ func NewpStakeApp( capabilitytypes.StoreKey, feegrant.StoreKey, authzkeeper.StoreKey, icahosttypes.StoreKey, icacontrollertypes.StoreKey, epochstypes.StoreKey, interchainquerytypes.StoreKey, ibcfeetypes.StoreKey, liquidstakeibctypes.StoreKey, liquidstaketypes.StoreKey, consensusparamtypes.StoreKey, + ratesynctypes.StoreKey, ) tkeys := sdk.NewTransientStoreKeys(paramstypes.TStoreKey) memKeys := sdk.NewMemoryStoreKeys(capabilitytypes.MemStoreKey) @@ -420,6 +427,17 @@ func NewpStakeApp( stakingtypes.NewMultiStakingHooks(app.DistrKeeper.Hooks(), app.SlashingKeeper.Hooks()), ) + app.LiquidStakeKeeper = liquidstakekeeper.NewKeeper( + appCodec, + keys[liquidstaketypes.StoreKey], + app.AccountKeeper, + app.BankKeeper, + app.StakingKeeper, + app.DistrKeeper, + app.SlashingKeeper, + app.MsgServiceRouter(), + authtypes.NewModuleAddress(govtypes.ModuleName).String(), + ) app.IBCKeeper = ibckeeper.NewKeeper( appCodec, keys[ibcexported.StoreKey], @@ -489,6 +507,13 @@ func NewpStakeApp( authtypes.NewModuleAddress(govtypes.ModuleName).String(), ) + app.RatesyncKeeper = ratesynckeeper.NewKeeper(appCodec, keys[ratesynctypes.StoreKey], + app.EpochsKeeper, app.LiquidStakeKeeper, app.ICAControllerKeeper, app.IBCKeeper, + app.MsgServiceRouter(), authtypes.NewModuleAddress(govtypes.ModuleName).String()) + + app.LiquidStakeIBCKeeper = *app.LiquidStakeIBCKeeper.SetHooks(liquidstakeibctypes.NewMultiLiquidStakeIBCHooks( + app.RatesyncKeeper.LiquidStakeIBCHooks())) + _ = app.InterchainQueryKeeper.SetCallbackHandler(liquidstakeibctypes.ModuleName, app.LiquidStakeIBCKeeper.CallbackHandler()) liquidStakeIBCModule := liquidstakeibc.NewIBCModule(app.LiquidStakeIBCKeeper) @@ -508,6 +533,7 @@ func NewpStakeApp( icaHostStack = ibcfee.NewIBCMiddleware(icaHostStack, app.IBCFeeKeeper) var icaControllerStack porttypes.IBCModule = liquidStakeIBCModule + icaControllerStack = ratesync.NewIBCModule(icaControllerStack, *app.RatesyncKeeper) icaControllerStack = icacontroller.NewIBCMiddleware(icaControllerStack, app.ICAControllerKeeper) ibcRouter := porttypes.NewRouter() @@ -515,22 +541,11 @@ func NewpStakeApp( AddRoute(ibctransfertypes.ModuleName, transferStack). AddRoute(icahosttypes.SubModuleName, icaHostStack). AddRoute(icacontrollertypes.SubModuleName, icaControllerStack). - AddRoute(liquidstakeibctypes.ModuleName, icaControllerStack) + AddRoute(liquidstakeibctypes.ModuleName, icaControllerStack). + AddRoute(ratesynctypes.ModuleName, icaControllerStack) app.IBCKeeper.SetRouter(ibcRouter) - app.LiquidStakeKeeper = liquidstakekeeper.NewKeeper( - appCodec, - keys[liquidstaketypes.StoreKey], - app.AccountKeeper, - app.BankKeeper, - app.StakingKeeper, - app.DistrKeeper, - app.SlashingKeeper, - app.MsgServiceRouter(), - authtypes.NewModuleAddress(govtypes.ModuleName).String(), - ) - // register the proposal types // Register the proposal types @@ -573,6 +588,7 @@ func NewpStakeApp( app.EpochsKeeper.SetHooks( epochstypes.NewMultiEpochHooks( app.LiquidStakeIBCKeeper.NewEpochHooks(), + app.RatesyncKeeper.EpochHooks(), ), ) @@ -611,6 +627,7 @@ func NewpStakeApp( interchainQueryModule, liquidstakeibc.NewAppModule(app.LiquidStakeIBCKeeper), liquidstake.NewAppModule(app.LiquidStakeKeeper), + ratesync.NewAppModule(appCodec, *app.RatesyncKeeper, app.AccountKeeper, app.BankKeeper), consensus.NewAppModule(appCodec, app.ConsensusParamsKeeper), ) @@ -646,6 +663,7 @@ func NewpStakeApp( interchainquerytypes.ModuleName, liquidstakeibctypes.ModuleName, liquidstaketypes.ModuleName, + ratesynctypes.ModuleName, consensusparamtypes.ModuleName, ) app.mm.SetOrderEndBlockers( @@ -674,6 +692,7 @@ func NewpStakeApp( interchainquerytypes.ModuleName, liquidstakeibctypes.ModuleName, liquidstaketypes.ModuleName, + ratesynctypes.ModuleName, consensusparamtypes.ModuleName, ) @@ -709,6 +728,7 @@ func NewpStakeApp( interchainquerytypes.ModuleName, liquidstakeibctypes.ModuleName, liquidstaketypes.ModuleName, + ratesynctypes.ModuleName, consensusparamtypes.ModuleName, ) @@ -1009,11 +1029,8 @@ func (app *PstakeApp) RegisterUpgradeHandler() { if upgradeInfo.Name == UpgradeName && !app.UpgradeKeeper.IsSkipHeight(upgradeInfo.Height) { storeUpgrades := store.StoreUpgrades{ - Added: []string{}, - Deleted: []string{ - lscosmostypes.StoreKey, - "lspersistence", //if present - }, + Added: []string{ratesynctypes.StoreKey, liquidstaketypes.StoreKey}, + Deleted: []string{}, } // configure store loader that checks if version == upgradeHeight and applies store upgrades diff --git a/app/const.go b/app/const.go index e924f4b77..99b55ed20 100644 --- a/app/const.go +++ b/app/const.go @@ -2,5 +2,5 @@ package app const ( appName = "pStake" - UpgradeName = "v2.3.0" + UpgradeName = "v2.8.0" ) diff --git a/go.mod b/go.mod index 0ee37fe6f..0380d6762 100644 --- a/go.mod +++ b/go.mod @@ -26,6 +26,7 @@ require ( google.golang.org/genproto/googleapis/api v0.0.0-20230822172742-b8732ec3820d google.golang.org/grpc v1.59.0 google.golang.org/protobuf v1.31.0 + gopkg.in/yaml.v2 v2.4.0 ) require ( @@ -88,6 +89,7 @@ require ( github.com/golang/snappy v0.0.4 // indirect github.com/google/btree v1.1.2 // indirect github.com/google/go-cmp v0.5.9 // indirect + github.com/google/gofuzz v1.2.0 // indirect github.com/google/orderedcode v0.0.1 // indirect github.com/google/s2a-go v0.1.4 // indirect github.com/google/uuid v1.3.1 // indirect @@ -170,7 +172,6 @@ require ( google.golang.org/genproto v0.0.0-20230822172742-b8732ec3820d // indirect google.golang.org/genproto/googleapis/rpc v0.0.0-20230822172742-b8732ec3820d // indirect gopkg.in/ini.v1 v1.67.0 // indirect - gopkg.in/yaml.v2 v2.4.0 // indirect gopkg.in/yaml.v3 v3.0.1 // indirect nhooyr.io/websocket v1.8.6 // indirect pgregory.net/rapid v0.5.5 // indirect diff --git a/proto/pstake/ratesync/v1beta1/contract.proto b/proto/pstake/ratesync/v1beta1/contract.proto new file mode 100644 index 000000000..f150079a8 --- /dev/null +++ b/proto/pstake/ratesync/v1beta1/contract.proto @@ -0,0 +1,28 @@ +syntax = "proto3"; +package pstake.ratesync.v1beta1; + +import "gogoproto/gogo.proto"; +import "cosmos_proto/cosmos.proto"; +import "google/protobuf/timestamp.proto"; + +option go_package = "github.com/persistenceOne/pstake-native/v2/x/ratesync/types"; + +// msg blob for instantiate contract. +message InstantiateLiquidStakeRateContract { + string admin = 1[(cosmos_proto.scalar) = "cosmos.AddressString"]; +} + +// wrapper for liquidstakerate as wasm msg should be marshalled as encodedMsg = { wasmMsg: { wasm MsgDetails } } +message ExecuteLiquidStakeRate{ + LiquidStakeRate liquid_stake_rate = 1[(gogoproto.nullable) = false]; +} + +// msg blob for execute contract. +message LiquidStakeRate { + string default_bond_denom = 1; + string stk_denom = 2; + // cvalue = default_bond_denom_price/stk_denom_price + // cvalue = stk_denom_supply/default_bond_denom_supply + string c_value = 3[(gogoproto.nullable) = false, (cosmos_proto.scalar) = "cosmos.Dec", (gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec"]; + int64 controller_chain_time = 4; +} \ No newline at end of file diff --git a/proto/pstake/ratesync/v1beta1/genesis.proto b/proto/pstake/ratesync/v1beta1/genesis.proto new file mode 100644 index 000000000..21f7d0ae0 --- /dev/null +++ b/proto/pstake/ratesync/v1beta1/genesis.proto @@ -0,0 +1,14 @@ +syntax = "proto3"; +package pstake.ratesync.v1beta1; + +import "gogoproto/gogo.proto"; +import "pstake/ratesync/v1beta1/params.proto"; +import "pstake/ratesync/v1beta1/ratesync.proto"; + +option go_package = "github.com/persistenceOne/pstake-native/v2/x/ratesync/types"; + +// GenesisState defines the ratesync module's genesis state. +message GenesisState { + Params params = 1 [(gogoproto.nullable) = false]; + repeated HostChain host_chains = 2 [(gogoproto.nullable) = false]; +} diff --git a/proto/pstake/ratesync/v1beta1/params.proto b/proto/pstake/ratesync/v1beta1/params.proto new file mode 100644 index 000000000..e003b3152 --- /dev/null +++ b/proto/pstake/ratesync/v1beta1/params.proto @@ -0,0 +1,14 @@ +syntax = "proto3"; +package pstake.ratesync.v1beta1; + +import "gogoproto/gogo.proto"; +import "cosmos_proto/cosmos.proto"; + +option go_package = "github.com/persistenceOne/pstake-native/v2/x/ratesync/types"; + +// Params defines the parameters for the module. +message Params { + option (gogoproto.goproto_stringer) = false; + + string admin = 1[(cosmos_proto.scalar) = "cosmos.AddressString"]; +} diff --git a/proto/pstake/ratesync/v1beta1/query.proto b/proto/pstake/ratesync/v1beta1/query.proto new file mode 100644 index 000000000..f1bf40ab7 --- /dev/null +++ b/proto/pstake/ratesync/v1beta1/query.proto @@ -0,0 +1,55 @@ +syntax = "proto3"; +package pstake.ratesync.v1beta1; + +import "gogoproto/gogo.proto"; +import "google/api/annotations.proto"; +import "cosmos/base/query/v1beta1/pagination.proto"; +import "pstake/ratesync/v1beta1/params.proto"; +import "pstake/ratesync/v1beta1/ratesync.proto"; + +option go_package = "github.com/persistenceOne/pstake-native/v2/x/ratesync/types"; + +// Query defines the gRPC querier service. +service Query { + // Parameters queries the parameters of the module. + rpc Params(QueryParamsRequest) returns (QueryParamsResponse) { + option (google.api.http).get = "/pstake/ratesync/v1beta1/params"; + } + + + // Queries a list of Chain items. + rpc HostChain (QueryGetHostChainRequest) returns (QueryGetHostChainResponse) { + option (google.api.http).get = "/pstake-native/v2/ratesync/host_chain/{i_d}"; + + } + rpc AllHostChains (QueryAllHostChainsRequest) returns (QueryAllHostChainsResponse) { + option (google.api.http).get = "/pstake-native/v2/ratesync/host_chains"; + + } +} + +// QueryParamsRequest is request type for the Query/Params RPC method. +message QueryParamsRequest {} + +// QueryParamsResponse is response type for the Query/Params RPC method. +message QueryParamsResponse { + // params holds all the parameters of this module. + Params params = 1 [(gogoproto.nullable) = false]; +} + +message QueryGetHostChainRequest { + uint64 i_d = 1; +} + +message QueryGetHostChainResponse { + HostChain host_chain = 1 [(gogoproto.nullable) = false]; +} + +message QueryAllHostChainsRequest { + cosmos.base.query.v1beta1.PageRequest pagination = 1; +} + +message QueryAllHostChainsResponse { + repeated HostChain host_chains = 1 [(gogoproto.nullable) = false]; + cosmos.base.query.v1beta1.PageResponse pagination = 2; +} diff --git a/proto/pstake/ratesync/v1beta1/ratesync.proto b/proto/pstake/ratesync/v1beta1/ratesync.proto new file mode 100644 index 000000000..34b37d007 --- /dev/null +++ b/proto/pstake/ratesync/v1beta1/ratesync.proto @@ -0,0 +1,63 @@ +syntax = "proto3"; +package pstake.ratesync.v1beta1; + +import "gogoproto/gogo.proto"; +import "pstake/liquidstakeibc/v1beta1/liquidstakeibc.proto"; +import "amino/amino.proto"; + +option go_package = "github.com/persistenceOne/pstake-native/v2/x/ratesync/types"; + +// HostChain defines the ratesync module's HostChain state. +message HostChain{ + // unique id + uint64 i_d = 1; + string chain_i_d = 2; //not really required, just easier readability + string connection_i_d = 3; + pstake.liquidstakeibc.v1beta1.ICAAccount i_c_a_account = 4 [(gogoproto.nullable) = false, (amino.dont_omitempty) = true]; + Feature features = 5 [(gogoproto.nullable) = false, (amino.dont_omitempty) = true]; +} +message Feature{ + // triggers on hooks + LiquidStake liquid_stake_i_b_c = 1 [(gogoproto.nullable) = false, (amino.dont_omitempty) = true]; + + // triggers on hour epoch + LiquidStake liquid_stake = 2 [(gogoproto.nullable) = false, (amino.dont_omitempty) = true]; + + //add more features +} + +enum InstantiationState{ + // Not Initiated + INSTANTIATION_NOT_INITIATED = 0; + // Initiated + INSTANTIATION_INITIATED = 1; + // we should have an address + INSTANTIATION_COMPLETED = 2; +} + +enum FeatureType { + LIQUID_STAKE_IBC = 0; + LIQUID_STAKE = 1; +} + +message LiquidStake{ + FeatureType feature_type = 1; + + // needs to be uploaded before hand + uint64 code_i_d = 2; + // state of instantiation, do not support gov based instantiation. (need ICA to be atleast admin) + InstantiationState instantiation = 3; + // address of instantiated contract. + string contract_address = 4; + // allow * as default for all denoms in case of lsibc, or default bond denom in case of ls. + repeated string denoms = 5; + + bool enabled = 6; +} + +// aim to keep this smaller than 256 MaxCharLen in ICA memo. +message ICAMemo { + FeatureType feature_type = 1; + uint64 host_chain_i_d = 2; +} + diff --git a/proto/pstake/ratesync/v1beta1/tx.proto b/proto/pstake/ratesync/v1beta1/tx.proto new file mode 100644 index 000000000..87de83a71 --- /dev/null +++ b/proto/pstake/ratesync/v1beta1/tx.proto @@ -0,0 +1,62 @@ +syntax = "proto3"; +package pstake.ratesync.v1beta1; + +import "cosmos/msg/v1/msg.proto"; +import "cosmos/base/v1beta1/coin.proto"; +import "amino/amino.proto"; +import "cosmos_proto/cosmos.proto"; +import "pstake/ratesync/v1beta1/params.proto"; +import "pstake/ratesync/v1beta1/ratesync.proto"; +import "gogoproto/gogo.proto"; + +option go_package = "github.com/persistenceOne/pstake-native/v2/x/ratesync/types"; + +// Msg defines the Msg service. +service Msg { + rpc CreateHostChain (MsgCreateHostChain) returns (MsgCreateHostChainResponse); + rpc UpdateHostChain (MsgUpdateHostChain) returns (MsgUpdateHostChainResponse); + rpc DeleteHostChain (MsgDeleteHostChain) returns (MsgDeleteHostChainResponse); + rpc UpdateParams (MsgUpdateParams) returns (MsgUpdateParamsResponse); +} + +message MsgCreateHostChain { + option (cosmos.msg.v1.signer) = "authority"; + option (amino.name) = "pstake/ratesync/MsgCreateHostChain"; + + string authority = 1[(cosmos_proto.scalar) = "cosmos.AddressString"]; + HostChain host_chain = 2[(gogoproto.nullable) = false, (amino.dont_omitempty) = true]; +} + +message MsgCreateHostChainResponse { + uint64 i_d = 1; +} + +message MsgUpdateHostChain { + option (cosmos.msg.v1.signer) = "authority"; + option (amino.name) = "pstake/ratesync/MsgUpdateHostChain"; + + string authority = 1[(cosmos_proto.scalar) = "cosmos.AddressString"]; + HostChain host_chain = 2[(gogoproto.nullable) = false, (amino.dont_omitempty) = true]; +} + +message MsgUpdateHostChainResponse {} + +message MsgDeleteHostChain { + option (cosmos.msg.v1.signer) = "authority"; + option (amino.name) = "pstake/ratesync/MsgDeleteHostChain"; + + string authority = 1[(cosmos_proto.scalar) = "cosmos.AddressString"]; + uint64 i_d = 2; +} + +message MsgDeleteHostChainResponse {} + +message MsgUpdateParams { + option (cosmos.msg.v1.signer) = "authority"; + option (amino.name) = "pstake/ratesync/MsgUpdateParams"; + + string authority = 1 [(cosmos_proto.scalar) = "cosmos.AddressString"]; + Params params = 2[(gogoproto.nullable) = false, (amino.dont_omitempty) = true]; +} + +message MsgUpdateParamsResponse {} \ No newline at end of file diff --git a/x/liquidstakeibc/keeper/ibc.go b/x/liquidstakeibc/keeper/ibc.go index 8d1f930f1..0fa3a5490 100644 --- a/x/liquidstakeibc/keeper/ibc.go +++ b/x/liquidstakeibc/keeper/ibc.go @@ -63,7 +63,9 @@ func (k *Keeper) OnChanOpenAck( // get host chain hc, found := k.GetHostChain(ctx, chainID) if !found { - return fmt.Errorf("host chain with id %s is not registered", chainID) + // probably for non chain ica stack. + k.Logger(ctx).Info(fmt.Sprintf("liquidstakeibc host chain with id %s is not registered", chainID)) + return nil } switch { @@ -76,7 +78,7 @@ func (k *Keeper) OnChanOpenAck( hc.RewardsAccount.Owner = portOwner hc.RewardsAccount.ChannelState = types.ICAAccount_ICA_CHANNEL_CREATED default: - k.Logger(ctx).Error("Unrecognised ICA account type for the module", "port-id:", portID, "chain-id", chainID) + k.Logger(ctx).Info("Unrecognised ICA account type for the module", "port-id:", portID, "chain-id", chainID) return nil } diff --git a/x/liquidstakeibc/keeper/keeper.go b/x/liquidstakeibc/keeper/keeper.go index dbf602054..ef9eec7e1 100644 --- a/x/liquidstakeibc/keeper/keeper.go +++ b/x/liquidstakeibc/keeper/keeper.go @@ -305,7 +305,7 @@ func (k *Keeper) UpdateCValues(ctx sdk.Context) { hc.LastCValue = hc.CValue hc.CValue = cValue k.SetHostChain(ctx, hc) - if err := k.Hooks().PostCValueUpdate(ctx); err != nil { + if err := k.Hooks().PostCValueUpdate(ctx, hc.MintDenom(), hc.HostDenom, hc.CValue); err != nil { k.Logger(ctx).Error("PostCValueUpdate hook failed with ", "err:", err) } ctx.EventManager().EmitEvent( diff --git a/x/liquidstakeibc/types/hooks.go b/x/liquidstakeibc/types/hooks.go index e0b8018f6..89c75c00e 100644 --- a/x/liquidstakeibc/types/hooks.go +++ b/x/liquidstakeibc/types/hooks.go @@ -7,7 +7,7 @@ import ( ) type LiquidStakeIBCHooks interface { - PostCValueUpdate(ctx sdk.Context) error + PostCValueUpdate(ctx sdk.Context, mintDenom, hostDenom string, cValue sdk.Dec) error } var _ LiquidStakeIBCHooks = MultiLiquidStakeIBCHooks{} @@ -19,11 +19,11 @@ func NewMultiLiquidStakeIBCHooks(hooks ...LiquidStakeIBCHooks) MultiLiquidStakeI return hooks } -func (h MultiLiquidStakeIBCHooks) PostCValueUpdate(ctx sdk.Context) error { +func (h MultiLiquidStakeIBCHooks) PostCValueUpdate(ctx sdk.Context, mintDenom, hostDenom string, cValue sdk.Dec) error { for i := range h { wrappedHookFn := func(ctx sdk.Context) error { //nolint:scopelint - return h[i].PostCValueUpdate(ctx) + return h[i].PostCValueUpdate(ctx, mintDenom, hostDenom, cValue) } err := utils.ApplyFuncIfNoError(ctx, wrappedHookFn) diff --git a/x/ratesync/client/cli/query.go b/x/ratesync/client/cli/query.go new file mode 100644 index 000000000..9e14d9275 --- /dev/null +++ b/x/ratesync/client/cli/query.go @@ -0,0 +1,130 @@ +package cli + +import ( + "fmt" + "strconv" + + "github.com/cosmos/cosmos-sdk/client" + "github.com/cosmos/cosmos-sdk/client/flags" + "github.com/spf13/cobra" + + "github.com/persistenceOne/pstake-native/v2/x/ratesync/types" +) + +// GetQueryCmd returns the cli query commands for this module +func GetQueryCmd(queryRoute string) *cobra.Command { + // Group ratesync queries under a subcommand + cmd := &cobra.Command{ + Use: types.ModuleName, + Short: fmt.Sprintf("Querying commands for the %s module", types.ModuleName), + DisableFlagParsing: true, + SuggestionsMinimumDistance: 2, + RunE: client.ValidateCmd, + } + + cmd.AddCommand(CmdQueryParams()) + cmd.AddCommand(CmdListChain()) + cmd.AddCommand(CmdShowChain()) + // this line is used by starport scaffolding # 1 + + return cmd +} + +func CmdQueryParams() *cobra.Command { + cmd := &cobra.Command{ + Use: "params", + Short: "shows the parameters of the module", + Args: cobra.NoArgs, + RunE: func(cmd *cobra.Command, args []string) error { + clientCtx, err := client.GetClientQueryContext(cmd) + if err != nil { + return err + } + + queryClient := types.NewQueryClient(clientCtx) + + res, err := queryClient.Params(cmd.Context(), &types.QueryParamsRequest{}) + if err != nil { + return err + } + + return clientCtx.PrintProto(res) + }, + } + + flags.AddQueryFlagsToCmd(cmd) + + return cmd +} + +func CmdListChain() *cobra.Command { + cmd := &cobra.Command{ + Use: "host-chains", + Short: "list all host-chains", + RunE: func(cmd *cobra.Command, args []string) error { + clientCtx, err := client.GetClientQueryContext(cmd) + if err != nil { + return err + } + + pageReq, err := client.ReadPageRequest(cmd.Flags()) + if err != nil { + return err + } + + queryClient := types.NewQueryClient(clientCtx) + + params := &types.QueryAllHostChainsRequest{ + Pagination: pageReq, + } + + res, err := queryClient.AllHostChains(cmd.Context(), params) + if err != nil { + return err + } + + return clientCtx.PrintProto(res) + }, + } + + flags.AddPaginationFlagsToCmd(cmd, cmd.Use) + flags.AddQueryFlagsToCmd(cmd) + + return cmd +} + +func CmdShowChain() *cobra.Command { + cmd := &cobra.Command{ + Use: "host-chain-id [id]", + Short: "shows a host-chain with id", + Args: cobra.ExactArgs(1), + RunE: func(cmd *cobra.Command, args []string) (err error) { + clientCtx, err := client.GetClientQueryContext(cmd) + if err != nil { + return err + } + + queryClient := types.NewQueryClient(clientCtx) + + argIndex := args[0] + argInt, err := strconv.ParseUint(argIndex, 10, 64) + if err != nil { + return err + } + params := &types.QueryGetHostChainRequest{ + ID: argInt, + } + + res, err := queryClient.HostChain(cmd.Context(), params) + if err != nil { + return err + } + + return clientCtx.PrintProto(res) + }, + } + + flags.AddQueryFlagsToCmd(cmd) + + return cmd +} diff --git a/x/ratesync/client/cli/tx.go b/x/ratesync/client/cli/tx.go new file mode 100644 index 000000000..2c89d4f43 --- /dev/null +++ b/x/ratesync/client/cli/tx.go @@ -0,0 +1,194 @@ +package cli + +import ( + "encoding/json" + "fmt" + "os" + "strconv" + "time" + + "github.com/cosmos/cosmos-sdk/client" + "github.com/cosmos/cosmos-sdk/client/flags" + "github.com/cosmos/cosmos-sdk/client/tx" + "github.com/spf13/cobra" + + "github.com/persistenceOne/pstake-native/v2/x/ratesync/types" +) + +var ( + DefaultRelativePacketTimeoutTimestamp = uint64((time.Duration(10) * time.Minute).Nanoseconds()) +) + +const ( + flagPacketTimeoutTimestamp = "packet-timeout-timestamp" + listSeparator = "," +) + +// GetTxCmd returns the transaction commands for this module +func GetTxCmd() *cobra.Command { + cmd := &cobra.Command{ + Use: types.ModuleName, + Short: fmt.Sprintf("%s transactions subcommands", types.ModuleName), + DisableFlagParsing: true, + SuggestionsMinimumDistance: 2, + RunE: client.ValidateCmd, + } + + cmd.AddCommand(CmdMsgUpdateParams()) + cmd.AddCommand(CmdCreateChain()) + cmd.AddCommand(CmdUpdateChain()) + cmd.AddCommand(CmdDeleteChain()) + // this line is used by starport scaffolding # 1 + + return cmd +} + +func CmdMsgUpdateParams() *cobra.Command { + cmd := &cobra.Command{ + Use: "update-params [params-file]", + Short: "Broadcast message MsgUpdateParams", + Args: cobra.ExactArgs(1), + RunE: func(cmd *cobra.Command, args []string) (err error) { + clientCtx, err := client.GetClientTxContext(cmd) + if err != nil { + return err + } + + var params types.Params + + paramsInFile, err := os.ReadFile(args[0]) + if err != nil { + return err + } + + err = json.Unmarshal(paramsInFile, ¶ms) + if err != nil { + return err + } + authority := clientCtx.GetFromAddress() + + msg := types.NewMsgUpdateParams(authority.String(), params) + + return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), msg) + + }, + } + + flags.AddTxFlagsToCmd(cmd) + + return cmd +} + +func CmdCreateChain() *cobra.Command { + cmd := &cobra.Command{ + Use: "create-chain [path_to_file]", + Short: "Create a new chain", + Args: cobra.ExactArgs(1), + RunE: func(cmd *cobra.Command, args []string) (err error) { + clientCtx, err := client.GetClientTxContext(cmd) + if err != nil { + return err + } + + var hostChain types.HostChain + + hostChainInFile, err := os.ReadFile(args[0]) + if err != nil { + return err + } + + err = json.Unmarshal(hostChainInFile, &hostChain) + if err != nil { + return fmt.Errorf("err unmarshalling json err: %v, should be of type %v", err, hostChain) + } + + msg := types.NewMsgCreateHostChain( + clientCtx.GetFromAddress().String(), + hostChain, + ) + if err := msg.ValidateBasic(); err != nil { + return err + } + return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), msg) + }, + } + + flags.AddTxFlagsToCmd(cmd) + + return cmd +} + +func CmdUpdateChain() *cobra.Command { + cmd := &cobra.Command{ + Use: "update-chain [index]", + Short: "Update a chain", + Args: cobra.ExactArgs(1), + RunE: func(cmd *cobra.Command, args []string) (err error) { + + // Get value arguments + + clientCtx, err := client.GetClientTxContext(cmd) + if err != nil { + return err + } + + var hostChain types.HostChain + + hostChainInFile, err := os.ReadFile(args[0]) + if err != nil { + return err + } + + err = json.Unmarshal(hostChainInFile, &hostChain) + if err != nil { + return fmt.Errorf("err unmarshalling json err: %v, should be of type %v", err, hostChain) + } + + msg := types.NewMsgUpdateHostChain( + clientCtx.GetFromAddress().String(), + hostChain, + ) + if err := msg.ValidateBasic(); err != nil { + return err + } + return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), msg) + }, + } + + flags.AddTxFlagsToCmd(cmd) + + return cmd +} + +func CmdDeleteChain() *cobra.Command { + cmd := &cobra.Command{ + Use: "delete-chain [id]", + Short: "Delete a chain", + Args: cobra.ExactArgs(1), + RunE: func(cmd *cobra.Command, args []string) (err error) { + id := args[0] + + clientCtx, err := client.GetClientTxContext(cmd) + if err != nil { + return err + } + + idInt, err := strconv.ParseUint(id, 10, 64) + if err != nil { + return err + } + msg := types.NewMsgDeleteHostChain( + clientCtx.GetFromAddress().String(), + idInt, + ) + if err := msg.ValidateBasic(); err != nil { + return err + } + return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), msg) + }, + } + + flags.AddTxFlagsToCmd(cmd) + + return cmd +} diff --git a/x/ratesync/genesis.go b/x/ratesync/genesis.go new file mode 100644 index 000000000..03585dd1a --- /dev/null +++ b/x/ratesync/genesis.go @@ -0,0 +1,28 @@ +package ratesync + +import ( + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/persistenceOne/pstake-native/v2/x/ratesync/keeper" + "github.com/persistenceOne/pstake-native/v2/x/ratesync/types" +) + +// InitGenesis initializes the module's state from a provided genesis state. +func InitGenesis(ctx sdk.Context, k keeper.Keeper, genState types.GenesisState) { + // Set all the chain + for _, elem := range genState.HostChains { + k.SetHostChain(ctx, elem) + } + // this line is used by starport scaffolding # genesis/module/init + k.SetParams(ctx, genState.Params) +} + +// ExportGenesis returns the module's exported genesis +func ExportGenesis(ctx sdk.Context, k keeper.Keeper) *types.GenesisState { + genesis := types.DefaultGenesis() + genesis.Params = k.GetParams(ctx) + + genesis.HostChains = k.GetAllHostChain(ctx) + // this line is used by starport scaffolding # genesis/module/export + + return genesis +} diff --git a/x/ratesync/genesis_test.go b/x/ratesync/genesis_test.go new file mode 100644 index 000000000..d10dcbee0 --- /dev/null +++ b/x/ratesync/genesis_test.go @@ -0,0 +1,43 @@ +package ratesync_test + +import ( + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/persistenceOne/pstake-native/v2/app/helpers" + liquidstakeibctypes "github.com/persistenceOne/pstake-native/v2/x/liquidstakeibc/types" + "testing" + + "github.com/stretchr/testify/require" + + "github.com/persistenceOne/pstake-native/v2/x/ratesync" + "github.com/persistenceOne/pstake-native/v2/x/ratesync/types" +) + +func TestGenesis(t *testing.T) { + _, pStakeApp, ctx := helpers.CreateTestApp(t) + + genesisState := types.GenesisState{ + Params: types.DefaultParams(), + + HostChains: []types.HostChain{ + { + ID: 1, + ICAAccount: liquidstakeibctypes.ICAAccount{Balance: sdk.Coin{Amount: sdk.OneInt()}}, + }, + { + ID: 2, + ICAAccount: liquidstakeibctypes.ICAAccount{Balance: sdk.Coin{Amount: sdk.OneInt()}}, + }, + }, + // this line is used by starport scaffolding # genesis/test/state + } + + k := pStakeApp.RatesyncKeeper + ratesync.InitGenesis(ctx, *k, genesisState) + got := ratesync.ExportGenesis(ctx, *k) + require.NotNil(t, got) + + require.Equal(t, genesisState.Params, got.Params) + + require.ElementsMatch(t, genesisState.HostChains, got.HostChains) + // this line is used by starport scaffolding # genesis/test/assert +} diff --git a/x/ratesync/keeper/abci.go b/x/ratesync/keeper/abci.go new file mode 100644 index 000000000..f27a027a2 --- /dev/null +++ b/x/ratesync/keeper/abci.go @@ -0,0 +1,46 @@ +package keeper + +import ( + sdk "github.com/cosmos/cosmos-sdk/types" + + liquidstakeibctypes "github.com/persistenceOne/pstake-native/v2/x/liquidstakeibc/types" + "github.com/persistenceOne/pstake-native/v2/x/ratesync/types" +) + +func (k *Keeper) BeginBlock(ctx sdk.Context) { + + // perform BeginBlocker tasks for each chain + for _, hc := range k.GetAllHostChain(ctx) { + if !hc.IsActive() { + // don't do anything on inactive chains + continue + } + // attempt to recreate closed ICA channels + k.DoRecreateICA(ctx, hc) + + // reset hc before going into next function, as it might have changed in earlier function + // as we do not want to re-write and omit the last write. + } + +} + +func (k *Keeper) DoRecreateICA(ctx sdk.Context, hc types.HostChain) { + // return early if any of the accounts is currently being recreated + if hc.ICAAccount.ChannelState == liquidstakeibctypes.ICAAccount_ICA_CHANNEL_CREATING { + return + } + + // if the channel is closed, and it is not being recreated, recreate it + portID := types.MustICAPortIDFromOwner(hc.ICAAccount.Owner) + _, isActive := k.icaControllerKeeper.GetOpenActiveChannel(ctx, hc.ConnectionID, portID) + if !isActive { + if err := k.icaControllerKeeper.RegisterInterchainAccount(ctx, hc.ConnectionID, hc.ICAAccount.Owner, ""); err != nil { + k.Logger(ctx).Error("error recreating %s ratesync ica: %w", hc.ChainID, err) + } else { + k.Logger(ctx).Info("Recreating ratesync ICA.", "chain", hc.ChainID) + + hc.ICAAccount.ChannelState = liquidstakeibctypes.ICAAccount_ICA_CHANNEL_CREATING + k.SetHostChain(ctx, hc) + } + } +} diff --git a/x/ratesync/keeper/chain.go b/x/ratesync/keeper/chain.go new file mode 100644 index 000000000..6afd82a01 --- /dev/null +++ b/x/ratesync/keeper/chain.go @@ -0,0 +1,101 @@ +package keeper + +import ( + "encoding/binary" + + "github.com/cosmos/cosmos-sdk/store/prefix" + sdk "github.com/cosmos/cosmos-sdk/types" + + "github.com/persistenceOne/pstake-native/v2/x/ratesync/types" +) + +// IncrementHostChainID increments and returns a unique ID for an unbonding operation +func (k Keeper) IncrementHostChainID(ctx sdk.Context) (hostChainID uint64) { + store := ctx.KVStore(k.storeKey) + bz := store.Get(types.HostChainIDKeyPrefix) + if bz != nil { + hostChainID = binary.BigEndian.Uint64(bz) + } + + hostChainID++ + + // Convert back into bytes for storage + bz = make([]byte, 8) + binary.BigEndian.PutUint64(bz, hostChainID) + + store.Set(types.HostChainIDKeyPrefix, bz) + + return hostChainID +} + +// SetHostChain set a specific chain in the store from its index +func (k Keeper) SetHostChain(ctx sdk.Context, chain types.HostChain) { + store := prefix.NewStore(ctx.KVStore(k.storeKey), types.HostChainKeyPrefix) + b := k.cdc.MustMarshal(&chain) + store.Set(types.HostChainKey( + chain.ID, + ), b) +} + +// GetHostChain returns a chain from its index +func (k Keeper) GetHostChain( + ctx sdk.Context, + id uint64, + +) (val types.HostChain, found bool) { + store := prefix.NewStore(ctx.KVStore(k.storeKey), types.HostChainKeyPrefix) + + b := store.Get(types.HostChainKey( + id, + )) + if b == nil { + return val, false + } + + k.cdc.MustUnmarshal(b, &val) + return val, true +} + +// GetHostChain returns a chain from its index +func (k Keeper) GetHostChainsByChainID( + ctx sdk.Context, + chainID string, +) []types.HostChain { + store := prefix.NewStore(ctx.KVStore(k.storeKey), types.HostChainKeyPrefix) + iterator := sdk.KVStorePrefixIterator(store, nil) + + defer iterator.Close() + + var vals []types.HostChain + for ; iterator.Valid(); iterator.Next() { + var val types.HostChain + k.cdc.MustUnmarshal(iterator.Value(), &val) + if val.ChainID == chainID { + vals = append(vals, val) + } + } + return vals +} + +// RemoveHostChain removes a chain from the store +func (k Keeper) RemoveHostChain(ctx sdk.Context, id uint64) { + store := prefix.NewStore(ctx.KVStore(k.storeKey), types.HostChainKeyPrefix) + store.Delete(types.HostChainKey(id)) +} + +// GetAllHostChain returns all chain +func (k Keeper) GetAllHostChain(ctx sdk.Context) []types.HostChain { + store := prefix.NewStore(ctx.KVStore(k.storeKey), types.HostChainKeyPrefix) + iterator := sdk.KVStorePrefixIterator(store, nil) + + defer iterator.Close() + + var list []types.HostChain + for ; iterator.Valid(); iterator.Next() { + var val types.HostChain + k.cdc.MustUnmarshal(iterator.Value(), &val) + list = append(list, val) + } + + return list +} diff --git a/x/ratesync/keeper/chain_test.go b/x/ratesync/keeper/chain_test.go new file mode 100644 index 000000000..4bf5b6eab --- /dev/null +++ b/x/ratesync/keeper/chain_test.go @@ -0,0 +1,86 @@ +package keeper_test + +import ( + ibcexported "github.com/cosmos/ibc-go/v7/modules/core/exported" + liquidstakeibctypes "github.com/persistenceOne/pstake-native/v2/x/liquidstakeibc/types" + "strconv" + + "github.com/persistenceOne/pstake-native/v2/x/ratesync/keeper" + "github.com/persistenceOne/pstake-native/v2/x/ratesync/types" + + sdk "github.com/cosmos/cosmos-sdk/types" +) + +// Prevent strconv unused error +var _ = strconv.IntSize + +var ValidHostChainInMsg = func(id uint64) types.HostChain { + return types.HostChain{ + ID: id, + ChainID: "test-1", + ConnectionID: ibcexported.LocalhostConnectionID, + ICAAccount: liquidstakeibctypes.ICAAccount{ + Address: "", + Balance: sdk.Coin{Denom: "", Amount: sdk.ZeroInt()}, + Owner: types.DefaultPortOwner(id), + ChannelState: 0, + }, + Features: types.Feature{ + LiquidStakeIBC: types.LiquidStake{ + FeatureType: 0, + CodeID: 0, + Instantiation: 0, + ContractAddress: "", + Denoms: nil, + Enabled: false, + }, + LiquidStake: types.LiquidStake{ + FeatureType: 1, + CodeID: 0, + Instantiation: 0, + ContractAddress: "", + Denoms: nil, + Enabled: false, + }}, + } +} + +func createNChain(keeper *keeper.Keeper, ctx sdk.Context, n int) []types.HostChain { + items := make([]types.HostChain, n) + for i := range items { + items[i] = ValidHostChainInMsg(uint64(i)) + keeper.SetHostChain(ctx, items[i]) + } + return items +} + +func (suite *IntegrationTestSuite) TestHostChainGet() { + keeper, ctx := suite.app.RatesyncKeeper, suite.ctx + items := createNChain(keeper, ctx, 10) + for _, item := range items { + rst, found := keeper.GetHostChain(ctx, + item.ID, + ) + suite.Require().True(found) + suite.Require().Equal(&item, &rst) + } +} +func (suite *IntegrationTestSuite) TestHostChainRemove() { + keeper, ctx := suite.app.RatesyncKeeper, suite.ctx + items := createNChain(keeper, ctx, 10) + for _, item := range items { + keeper.RemoveHostChain(ctx, + item.ID, + ) + _, found := keeper.GetHostChain(ctx, + item.ID, + ) + suite.Require().False(found) + } +} + +func (suite *IntegrationTestSuite) TestHostChainGetAll() { + keeper, ctx := suite.app.RatesyncKeeper, suite.ctx + items := createNChain(keeper, ctx, 10) + suite.Require().ElementsMatch(items, keeper.GetAllHostChain(ctx)) +} diff --git a/x/ratesync/keeper/hooks.go b/x/ratesync/keeper/hooks.go new file mode 100644 index 000000000..9b4ee4fd8 --- /dev/null +++ b/x/ratesync/keeper/hooks.go @@ -0,0 +1,87 @@ +package keeper + +import ( + errorsmod "cosmossdk.io/errors" + sdk "github.com/cosmos/cosmos-sdk/types" + sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" + epochtypes "github.com/persistenceOne/persistence-sdk/v2/x/epochs/types" + liquidstakeibctypes "github.com/persistenceOne/pstake-native/v2/x/liquidstakeibc/types" + "github.com/persistenceOne/pstake-native/v2/x/ratesync/types" +) + +// Wrapper struct +type LiquidStakeIBCHooks struct { + k Keeper +} + +var _ liquidstakeibctypes.LiquidStakeIBCHooks = LiquidStakeIBCHooks{} + +// Create new lsibc hooks +func (k Keeper) LiquidStakeIBCHooks() LiquidStakeIBCHooks { + return LiquidStakeIBCHooks{k} +} + +func (h LiquidStakeIBCHooks) PostCValueUpdate(ctx sdk.Context, mintDenom, hostDenom string, cValue sdk.Dec) error { + h.k.Logger(ctx).Info("called ratesync hook for PostCValueUpdate") + return h.k.PostCValueUpdate(ctx, mintDenom, hostDenom, cValue) +} +func (k Keeper) PostCValueUpdate(ctx sdk.Context, mintDenom, hostDenom string, cValue sdk.Dec) error { + hcs := k.GetAllHostChain(ctx) + for _, hc := range hcs { + if hc.Features.LiquidStakeIBC.Enabled { + err := k.ExecuteLiquidStakeRateTx(ctx, hc.Features.LiquidStakeIBC, mintDenom, hostDenom, cValue, hc.ID, hc.ConnectionID, hc.ICAAccount) + if err != nil { + k.Logger(ctx).Error("cannot ExecuteLiquidStakeRateTx for host chain ", + "id", hc.ID, + "mint-denom", mintDenom, + "err:", err) + } + } + } + return nil +} + +// Wrapper struct +type EpochHooks struct { + k Keeper +} + +var _ epochtypes.EpochHooks = EpochHooks{} + +// Create new epoch hooks +func (k Keeper) EpochHooks() EpochHooks { + return EpochHooks{k} +} + +func (e EpochHooks) AfterEpochEnd(ctx sdk.Context, epochIdentifier string, epochNumber int64) error { + e.k.Logger(ctx).Info("called ratesync hook for AfterEpochEnd") + return e.k.AfterEpochEnd(ctx, epochIdentifier, epochNumber) +} + +func (k Keeper) AfterEpochEnd(ctx sdk.Context, epochIdentifier string, epochNumber int64) error { + nas := k.liquidStakeKeeper.GetNetAmountState(ctx) + liquidBondDenom := k.liquidStakeKeeper.LiquidBondDenom(ctx) + bondDenom, found := liquidstakeibctypes.MintDenomToHostDenom(liquidBondDenom) + if !found { + return errorsmod.Wrapf(sdkerrors.ErrNotFound, "bondDenom could not be derived from host denom") + } + hcs := k.GetAllHostChain(ctx) + for _, hc := range hcs { + if hc.Features.LiquidStake.Enabled && epochIdentifier == types.LiquidStakeEpoch { + // Add liquidstakekeeper and do stuff + err := k.ExecuteLiquidStakeRateTx(ctx, hc.Features.LiquidStakeIBC, liquidBondDenom, bondDenom, nas.MintRate, hc.ID, hc.ConnectionID, hc.ICAAccount) + if err != nil { + k.Logger(ctx).Error("cannot ExecuteLiquidStakeRateTx for host chain ", + "id", hc.ID, + "mint-denom", liquidBondDenom, + "err:", err) + } + } + + } + return nil +} +func (e EpochHooks) BeforeEpochStart(ctx sdk.Context, epochIdentifier string, epochNumber int64) error { + e.k.Logger(ctx).Info("called ratesync hook for BeforeEpochStart") + return nil +} diff --git a/x/ratesync/keeper/ibc.go b/x/ratesync/keeper/ibc.go new file mode 100644 index 000000000..994abb3d6 --- /dev/null +++ b/x/ratesync/keeper/ibc.go @@ -0,0 +1,422 @@ +package keeper + +import ( + errorsmod "cosmossdk.io/errors" + "encoding/json" + "fmt" + wasmtypes "github.com/CosmWasm/wasmd/x/wasm/types" + sdk "github.com/cosmos/cosmos-sdk/types" + sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" + icatypes "github.com/cosmos/ibc-go/v7/modules/apps/27-interchain-accounts/types" + ibctransfertypes "github.com/cosmos/ibc-go/v7/modules/apps/transfer/types" + channeltypes "github.com/cosmos/ibc-go/v7/modules/core/04-channel/types" + liquidstakeibctypes "github.com/persistenceOne/pstake-native/v2/x/liquidstakeibc/types" + "strconv" + + "github.com/persistenceOne/pstake-native/v2/x/ratesync/types" +) + +func (k *Keeper) OnChanOpenAck( + ctx sdk.Context, + portID string, + channelID string, + counterpartyChannelID string, + counterpartyVersion string, +) error { + // get the connection id from the port and channel identifiers + connID, _, err := k.ibcKeeper.ChannelKeeper.GetChannelConnection(ctx, portID, channelID) + if err != nil { + return fmt.Errorf("unable to get connection id using port %s: %w", portID, err) + } + + // get interchain account address + address, found := k.icaControllerKeeper.GetInterchainAccountAddress(ctx, connID, portID) + if !found { + return fmt.Errorf("couldn't find address for %s/%s", connID, portID) + } + + // get the port owner from the port id, duplicated check as of ibc-go controller stack + portOwner, err := types.OwnerFromPortID(portID) + if err != nil { + return fmt.Errorf("unable to parse port id %s, err: %v", portID, err) + } + + // get the chain id using the connection id + chainID, err := k.GetChainID(ctx, connID) + if err != nil { + return fmt.Errorf("unable to get chain id for connection %s: %w", connID, err) + } + + id, err := types.IDFromPortID(portID) + if err != nil { + // Port is not related to this module + return nil + } + // get host chain + hc, found := k.GetHostChain(ctx, id) + if !found { + k.Logger(ctx).Info(fmt.Sprintf("host chain with id %v is not registered", id)) + return nil + } + + switch { + case portOwner == hc.ICAAccount.Owner: + hc.ICAAccount.Address = address + hc.ICAAccount.ChannelState = liquidstakeibctypes.ICAAccount_ICA_CHANNEL_CREATED + default: + k.Logger(ctx).Error("Unrecognised ICA account type for the module", "port-id:", portID, "chain-id", chainID) + return nil + } + + // save the changes of the host chain + k.SetHostChain(ctx, hc) + + k.Logger(ctx).Info( + "Created new ICA.", + "host chain", + chainID, + "channel", + channelID, + "owner", + portOwner, + "address", + address, + ) + + ctx.EventManager().EmitEvent( + sdk.NewEvent( + types.EventICAChannelCreated, + sdk.NewAttribute(types.AttributeChainID, hc.ChainID), + sdk.NewAttribute(types.AttributeICAChannelID, channelID), + sdk.NewAttribute(types.AttributeICAPortOwner, portOwner), + sdk.NewAttribute(types.AttributeICAAddress, address), + ), + ) + + return nil +} + +func (k *Keeper) OnAcknowledgementPacket( + ctx sdk.Context, + packet channeltypes.Packet, + acknowledgement []byte, + relayer sdk.AccAddress, +) error { + + id, err := types.IDFromPortID(packet.SourcePort) + if err != nil { + // Port is not related to this module + return nil + } + // get host chain + hc, found := k.GetHostChain(ctx, id) + if !found { + return errorsmod.Wrapf(sdkerrors.ErrNotFound, "host chain with id %v is not present", id) + } + + var ack channeltypes.Acknowledgement + if err := ibctransfertypes.ModuleCdc.UnmarshalJSON(acknowledgement, &ack); err != nil { + return errorsmod.Wrapf(sdkerrors.ErrUnknownRequest, "cannot unmarshal packet acknowledgement: %v", err) + } + + var icaPacket icatypes.InterchainAccountPacketData + if err := icatypes.ModuleCdc.UnmarshalJSON(packet.GetData(), &icaPacket); err != nil { + return errorsmod.Wrapf(sdkerrors.ErrUnknownRequest, "cannot unmarshal ICS-27 packet data: %v", err) + } + + var icaMemo types.ICAMemo + err = json.Unmarshal([]byte(icaPacket.Memo), &icaMemo) + if err != nil { + return err + } + if hc.ID != icaMemo.HostChainID { + return errorsmod.Wrapf(types.ErrInvalid, "host chain ID should match ID in memo") + } + switch resp := ack.Response.(type) { + case *channeltypes.Acknowledgement_Error: + err := k.handleUnsuccessfulAck(ctx, icaPacket, packet, icaMemo) + if err != nil { + return err + } + k.Logger(ctx).Info(fmt.Sprintln("ICS-27 tx failed with ack:", ack.String())) + ctx.EventManager().EmitEvent( + sdk.NewEvent( + types.EventTypePacket, + sdk.NewAttribute(types.AttributeKeyAckError, resp.Error), + ), + ) + case *channeltypes.Acknowledgement_Result: + err := k.handleSuccessfulAck(ctx, ack, icaPacket, packet, icaMemo) + if err != nil { + return err + } + ctx.EventManager().EmitEvent( + sdk.NewEvent( + types.EventTypePacket, + sdk.NewAttribute(types.AttributeKeyAckSuccess, fmt.Sprintln(ack.Success())), + ), + ) + default: + // the acknowledgement succeeded on the receiving chain so nothing + // needs to be executed and no error needs to be returned + return nil + } + + ctx.EventManager().EmitEvent( + sdk.NewEvent( + types.EventTypePacket, + sdk.NewAttribute(sdk.AttributeKeyModule, types.ModuleName), + sdk.NewAttribute(types.AttributeKeyAck, ack.String()), + ), + ) + + return nil +} + +func (k *Keeper) OnTimeoutPacket( + ctx sdk.Context, + packet channeltypes.Packet, + relayer sdk.AccAddress, +) error { + + id, err := types.IDFromPortID(packet.SourcePort) + if err != nil { + // Port is not related to this module + return nil + } + // get host chain + hc, found := k.GetHostChain(ctx, id) + if !found { + return errorsmod.Wrapf(sdkerrors.ErrNotFound, "host chain with id %v is not present", id) + } + var icaPacket icatypes.InterchainAccountPacketData + if err := icatypes.ModuleCdc.UnmarshalJSON(packet.GetData(), &icaPacket); err != nil { + return errorsmod.Wrapf(sdkerrors.ErrUnknownRequest, "cannot unmarshal ICS-27 tx message data: %v", err) + } + + var icaMemo types.ICAMemo + err = json.Unmarshal([]byte(icaPacket.Memo), &icaMemo) + if err != nil { + return err + } + + if hc.ID != icaMemo.HostChainID { + return errorsmod.Wrapf(types.ErrInvalid, "host chain ID should match ID in memo") + } + if err := k.handleUnsuccessfulAck(ctx, icaPacket, packet, icaMemo); err != nil { + return err + } + + ctx.EventManager().EmitEvent( + sdk.NewEvent( + types.EventTypeTimeout, + sdk.NewAttribute(sdk.AttributeKeyModule, types.ModuleName), + ), + ) + + k.Logger(ctx).Info( + "ICA transaction timed out.", + "sequence", + packet.Sequence, + "channel", + packet.SourceChannel, + "port", + packet.SourcePort, + ) + + return nil +} + +func (k *Keeper) handleUnsuccessfulAck( + ctx sdk.Context, + icaPacket icatypes.InterchainAccountPacketData, + packet channeltypes.Packet, icaMemo types.ICAMemo, +) error { + messages, err := icatypes.DeserializeCosmosTx(k.cdc, icaPacket.GetData()) + if err != nil { + return errorsmod.Wrapf(sdkerrors.ErrUnknownRequest, "cannot deserialize ica packet data: %v", err) + } + hc, found := k.GetHostChain(ctx, icaMemo.HostChainID) + if !found { + return errorsmod.Wrapf(sdkerrors.ErrNotFound, "hostchain not found for id %v", icaMemo.HostChainID) + } + for _, msg := range messages { + switch sdk.MsgTypeURL(msg) { + case sdk.MsgTypeURL(&wasmtypes.MsgInstantiateContract{}): + // parse the MsgInstantiateContract to emit the instantiate error event + parsedMsg, ok := msg.(*wasmtypes.MsgInstantiateContract) + if !ok { + k.Logger(ctx).Error( + "Could not parse MsgInstantiateContract while handling unsuccessful ack.", + "channel", packet.SourceChannel, "sequence", packet.Sequence, + ) + continue + } + //reset instantiation state so can be retried. + switch icaMemo.FeatureType { + case types.FeatureType_LIQUID_STAKE_IBC: + hc.Features.LiquidStakeIBC.Instantiation = types.InstantiationState_INSTANTIATION_NOT_INITIATED + case types.FeatureType_LIQUID_STAKE: + hc.Features.LiquidStake.Instantiation = types.InstantiationState_INSTANTIATION_NOT_INITIATED + } + + // emit an event for the instantiate confirmation + ctx.EventManager().EmitEvent( + sdk.NewEvent( + types.EventTypeUnsuccessfulInstantiateContract, + sdk.NewAttribute(types.AttributeChainID, hc.ChainID), + sdk.NewAttribute(types.AttributeSender, parsedMsg.Sender), + sdk.NewAttribute(channeltypes.AttributeKeySequence, strconv.FormatUint(packet.Sequence, 10)), + sdk.NewAttribute(channeltypes.AttributeKeySrcChannel, packet.SourceChannel), + sdk.NewAttribute(channeltypes.AttributeKeyPortID, packet.SourcePort), + ), + ) + case sdk.MsgTypeURL(&wasmtypes.MsgExecuteContract{}): + + // parse the MsgExecuteContract to emit the execute error event + parsedMsg, ok := msg.(*wasmtypes.MsgExecuteContract) + if !ok { + k.Logger(ctx).Error( + "Could not parse MsgExecuteContract while handling unsuccessful ack.", + "channel", packet.SourceChannel, "sequence", packet.Sequence, + ) + continue + } + //Do nothing, relay next epoch + + // emit an event for the execution confirmation + ctx.EventManager().EmitEvent( + sdk.NewEvent( + types.EventTypeUnsuccessfulExecuteContract, + sdk.NewAttribute(types.AttributeChainID, hc.ChainID), + sdk.NewAttribute(types.AttributeSender, parsedMsg.Sender), + sdk.NewAttribute(channeltypes.AttributeKeySequence, strconv.FormatUint(packet.Sequence, 10)), + sdk.NewAttribute(channeltypes.AttributeKeySrcChannel, packet.SourceChannel), + sdk.NewAttribute(channeltypes.AttributeKeyPortID, packet.SourcePort), + ), + ) + + } + } + k.SetHostChain(ctx, hc) + + return nil +} + +func (k *Keeper) handleSuccessfulAck( + ctx sdk.Context, + ack channeltypes.Acknowledgement, + icaPacket icatypes.InterchainAccountPacketData, + packet channeltypes.Packet, icaMemo types.ICAMemo, +) error { + txMsgData := &sdk.TxMsgData{} + if err := k.cdc.Unmarshal(ack.GetResult(), txMsgData); err != nil { + return errorsmod.Wrapf(sdkerrors.ErrUnknownRequest, "cannot unmarshal ics-27 tx ack data: %v", err) + } + + messages, err := icatypes.DeserializeCosmosTx(k.cdc, icaPacket.GetData()) + if err != nil { + return errorsmod.Wrapf(sdkerrors.ErrUnknownRequest, "cannot deserialize ica packet data: %v", err) + } + + for i, msg := range messages { + switch sdk.MsgTypeURL(msg) { + case sdk.MsgTypeURL(&wasmtypes.MsgInstantiateContract{}): + var data []byte + if len(txMsgData.Data) == 0 { + data = txMsgData.GetMsgResponses()[i].Value + } else { + data = txMsgData.Data[i].Data + } + + var msgResponse wasmtypes.MsgInstantiateContractResponse + if err := k.cdc.Unmarshal(data, &msgResponse); err != nil { + return errorsmod.Wrapf( + sdkerrors.ErrJSONUnmarshal, "cannot unmarshal MsgInstantiateContract response message: %s", + err.Error(), + ) + } + parsedMsg, ok := msg.(*wasmtypes.MsgInstantiateContract) + if !ok { + return errorsmod.Wrapf( + sdkerrors.ErrInvalidType, + "unable to cast msg of type %s to MsgInstantiateContract", + sdk.MsgTypeURL(msg), + ) + } + if err = k.HandleInstantiateContractResponse(ctx, parsedMsg, msgResponse, icaMemo); err != nil { + return err + } + case sdk.MsgTypeURL(&wasmtypes.MsgExecuteContract{}): + var data []byte + if len(txMsgData.Data) == 0 { + data = txMsgData.GetMsgResponses()[i].Value + } else { + data = txMsgData.Data[i].Data + } + + var msgResponse wasmtypes.MsgExecuteContractResponse + if err := k.cdc.Unmarshal(data, &msgResponse); err != nil { + return errorsmod.Wrapf( + sdkerrors.ErrJSONUnmarshal, "cannot unmarshal MsgExecuteContract response message: %s", + err.Error(), + ) + } + parsedMsg, ok := msg.(*wasmtypes.MsgExecuteContract) + if !ok { + return errorsmod.Wrapf( + sdkerrors.ErrInvalidType, + "unable to cast msg of type %s to MsgExecuteContract", + sdk.MsgTypeURL(msg), + ) + } + + if err = k.HandleExecuteContractResponse(ctx, parsedMsg, msgResponse); err != nil { + return err + } + } + } + + k.Logger(ctx).Info( + "ICA transaction ACK success.", + "sequence", + packet.Sequence, + "channel", + packet.SourceChannel, + "messages", + messages, + ) + + return nil +} + +func (k Keeper) HandleInstantiateContractResponse(ctx sdk.Context, + msg *wasmtypes.MsgInstantiateContract, + resp wasmtypes.MsgInstantiateContractResponse, + icaMemo types.ICAMemo, +) error { + hc, found := k.GetHostChain(ctx, icaMemo.HostChainID) + if !found { + return errorsmod.Wrapf(sdkerrors.ErrNotFound, "hostchain not found for id %v", icaMemo.HostChainID) + } + switch icaMemo.FeatureType { + case types.FeatureType_LIQUID_STAKE_IBC: + hc.Features.LiquidStakeIBC.Instantiation = types.InstantiationState_INSTANTIATION_COMPLETED + hc.Features.LiquidStakeIBC.ContractAddress = resp.Address + hc.Features.LiquidStakeIBC.Enabled = true + case types.FeatureType_LIQUID_STAKE: + hc.Features.LiquidStake.Instantiation = types.InstantiationState_INSTANTIATION_COMPLETED + hc.Features.LiquidStake.ContractAddress = resp.Address + hc.Features.LiquidStake.Enabled = true + } + k.SetHostChain(ctx, hc) + return nil +} + +func (k Keeper) HandleExecuteContractResponse(ctx sdk.Context, + msg *wasmtypes.MsgExecuteContract, + resp wasmtypes.MsgExecuteContractResponse, +) error { + // cool do nothing + return nil +} diff --git a/x/ratesync/keeper/ica_tx.go b/x/ratesync/keeper/ica_tx.go new file mode 100644 index 000000000..0c5cbc6be --- /dev/null +++ b/x/ratesync/keeper/ica_tx.go @@ -0,0 +1,172 @@ +package keeper + +import ( + "encoding/json" + "fmt" + + errorsmod "cosmossdk.io/errors" + wasmtypes "github.com/CosmWasm/wasmd/x/wasm/types" + sdk "github.com/cosmos/cosmos-sdk/types" + sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" + "github.com/cosmos/gogoproto/proto" + icacontrollertypes "github.com/cosmos/ibc-go/v7/modules/apps/27-interchain-accounts/controller/types" + icatypes "github.com/cosmos/ibc-go/v7/modules/apps/27-interchain-accounts/types" + + liquidstakeibctypes "github.com/persistenceOne/pstake-native/v2/x/liquidstakeibc/types" + "github.com/persistenceOne/pstake-native/v2/x/ratesync/types" +) + +func (k *Keeper) GenerateAndExecuteICATx( + ctx sdk.Context, + connectionID string, + ownerID string, + messages []proto.Message, + memo string, +) (icacontrollertypes.MsgSendTxResponse, error) { + + msgData, err := icatypes.SerializeCosmosTx(k.cdc, messages) + if err != nil { + k.Logger(ctx).Error(fmt.Sprintf("could not serialize tx data: %v", err)) + return icacontrollertypes.MsgSendTxResponse{}, err + } + + icaPacketData := icatypes.InterchainAccountPacketData{ + Type: icatypes.EXECUTE_TX, + Data: msgData, + Memo: memo, + } + + msgSendTx := &icacontrollertypes.MsgSendTx{ + Owner: ownerID, + ConnectionId: connectionID, + PacketData: icaPacketData, + RelativeTimeout: uint64(types.ICATimeoutTimestamp.Nanoseconds()), + } + + handler := k.msgRouter.Handler(msgSendTx) + res, err := handler(ctx, msgSendTx) + if err != nil { + k.Logger(ctx).Error(fmt.Sprintf("sending ica tx with msg: %s failed with err: %v", msgData, err)) + return icacontrollertypes.MsgSendTxResponse{}, errorsmod.Wrapf(types.ErrICATxFailure, "failed to send ica msg with err: %v", err) + } + ctx.EventManager().EmitEvents(res.GetEvents()) + + portID, err := icatypes.NewControllerPortID(ownerID) + if err != nil { + return icacontrollertypes.MsgSendTxResponse{}, errorsmod.Wrapf( + types.ErrICATxFailure, + "failed to create portID from ownerID: %v", + err, + ) + } + _, found := k.icaControllerKeeper.GetOpenActiveChannel(ctx, connectionID, portID) + if !found { + return icacontrollertypes.MsgSendTxResponse{}, errorsmod.Wrapf( + types.ErrICATxFailure, + "failed to get ica active channel: %v", + err, + ) + } + + // responses length should always be 1 since we are just sending one MsgSendTx at a time + if len(res.MsgResponses) != 1 { + return icacontrollertypes.MsgSendTxResponse{}, errorsmod.Wrapf( + types.ErrInvalidResponses, + "not enough message responses for ica tx: %v", + err, + ) + } + + var msgSendTxResponse icacontrollertypes.MsgSendTxResponse + if err = k.cdc.Unmarshal(res.MsgResponses[0].Value, &msgSendTxResponse); err != nil { + return icacontrollertypes.MsgSendTxResponse{}, errorsmod.Wrapf( + sdkerrors.ErrJSONUnmarshal, + "cannot unmarshal ica send tx response message: %v", + err, + ) + } + k.Logger(ctx).Info( + fmt.Sprintf( + "sent ICA transactions with seq: %v, connectionID: %s, ownerID: %s, msgs: %s", + msgSendTxResponse.Sequence, + connectionID, + ownerID, + messages, + ), + ) + + return msgSendTxResponse, nil +} + +func (k *Keeper) ExecuteLiquidStakeRateTx(ctx sdk.Context, feature types.LiquidStake, + mintDenom, hostDenom string, cValue sdk.Dec, hostchainId uint64, + connectionID string, icaAccount liquidstakeibctypes.ICAAccount) error { + if feature.AllowsDenom(mintDenom) { + contractMsg := types.ExecuteLiquidStakeRate{ + LiquidStakeRate: types.LiquidStakeRate{ + DefaultBondDenom: hostDenom, + StkDenom: mintDenom, + CValue: cValue, + ControllerChainTime: ctx.BlockTime().Unix(), + }, + } + contractBz, err := json.Marshal(contractMsg) + if err != nil { + return err + } + msg := &wasmtypes.MsgExecuteContract{ + Sender: icaAccount.Address, + Contract: feature.ContractAddress, + Msg: contractBz, + Funds: nil, + } + memo := types.ICAMemo{ + FeatureType: feature.FeatureType, + HostChainID: hostchainId, + } + memoBz, err := json.Marshal(memo) + if err != nil { + return err + + } + _, err = k.GenerateAndExecuteICATx(ctx, connectionID, icaAccount.Owner, []proto.Message{msg}, string(memoBz)) + if err != nil { + return err + } + } + return nil +} + +func (k *Keeper) InstantiateLiquidStakeContract(ctx sdk.Context, icaAccount liquidstakeibctypes.ICAAccount, + feature types.LiquidStake, id uint64, connectionID string) error { + // generate contract msg{msg} + contractMsg := types.InstantiateLiquidStakeRateContract{ + Admin: icaAccount.Address, + } + contractMsgBz, err := json.Marshal(contractMsg) + if err != nil { + return errorsmod.Wrapf(err, "unable to marshal InstantiateLiquidStakeRateContract") + } + + msg := &wasmtypes.MsgInstantiateContract{ + Sender: icaAccount.Address, + Admin: icaAccount.Address, + CodeID: feature.CodeID, + Label: fmt.Sprintf("PSTAKE ratesync, ID-%v", id), + Msg: contractMsgBz, + Funds: sdk.Coins{}, + } + memo := types.ICAMemo{ + FeatureType: feature.FeatureType, + HostChainID: id, + } + memobz, err := json.Marshal(memo) + if err != nil { + return err + } + _, err = k.GenerateAndExecuteICATx(ctx, connectionID, icaAccount.Owner, []proto.Message{msg}, string(memobz)) + if err != nil { + return err + } + return nil +} diff --git a/x/ratesync/keeper/keeper.go b/x/ratesync/keeper/keeper.go new file mode 100644 index 000000000..2eb7f8dfa --- /dev/null +++ b/x/ratesync/keeper/keeper.go @@ -0,0 +1,91 @@ +package keeper + +import ( + "fmt" + + "github.com/cometbft/cometbft/libs/log" + "github.com/cosmos/cosmos-sdk/baseapp" + "github.com/cosmos/cosmos-sdk/codec" + storetypes "github.com/cosmos/cosmos-sdk/store/types" + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/cosmos/ibc-go/v7/modules/core/exported" + ibckeeper "github.com/cosmos/ibc-go/v7/modules/core/keeper" + ibctmtypes "github.com/cosmos/ibc-go/v7/modules/light-clients/07-tendermint" + ibclocalhosttypes "github.com/cosmos/ibc-go/v7/modules/light-clients/09-localhost" + + "github.com/persistenceOne/pstake-native/v2/x/ratesync/types" +) + +type ( + Keeper struct { + cdc codec.BinaryCodec + storeKey storetypes.StoreKey + + epochsKeeper types.EpochsKeeper + icaControllerKeeper types.ICAControllerKeeper + ibcKeeper *ibckeeper.Keeper + liquidStakeKeeper types.LiquidStakeKeeper + + msgRouter *baseapp.MsgServiceRouter + + authority string + } +) + +func NewKeeper( + cdc codec.BinaryCodec, + storeKey storetypes.StoreKey, + epochsKeeper types.EpochsKeeper, + liquidstakeKeeper types.LiquidStakeKeeper, + icaControllerKeeper types.ICAControllerKeeper, + ibcKeeper *ibckeeper.Keeper, + msgRouter *baseapp.MsgServiceRouter, + authority string, +) *Keeper { + return &Keeper{ + cdc: cdc, + storeKey: storeKey, + epochsKeeper: epochsKeeper, + liquidStakeKeeper: liquidstakeKeeper, + icaControllerKeeper: icaControllerKeeper, + ibcKeeper: ibcKeeper, + msgRouter: msgRouter, + authority: authority, + } +} + +func (k Keeper) Logger(ctx sdk.Context) log.Logger { + return ctx.Logger().With("module", fmt.Sprintf("x/%s", types.ModuleName)) +} + +// GetClientState retrieves the client state given a connection id +func (k *Keeper) GetClientState(ctx sdk.Context, connectionID string) (exported.ClientState, error) { + conn, found := k.ibcKeeper.ConnectionKeeper.GetConnection(ctx, connectionID) + if !found { + return nil, fmt.Errorf("invalid connection id, \"%s\" not found", connectionID) + } + + clientState, found := k.ibcKeeper.ClientKeeper.GetClientState(ctx, conn.ClientId) + if !found { + return nil, fmt.Errorf("client id \"%s\" not found for connection \"%s\"", conn.ClientId, connectionID) + } + + return clientState, nil +} + +// GetChainID gets the id of the host chain given a connection id +func (k *Keeper) GetChainID(ctx sdk.Context, connectionID string) (string, error) { + clientState, err := k.GetClientState(ctx, connectionID) + if err != nil { + return "", fmt.Errorf("client state not found for connection \"%s\": \"%s\"", connectionID, err.Error()) + } + + switch clientType := clientState.(type) { + case *ibctmtypes.ClientState: + return clientType.ChainId, nil + case *ibclocalhosttypes.ClientState: + return ctx.ChainID(), nil + default: + return "", fmt.Errorf("unexpected type of client, cannot determine chain-id: clientType: %s, connectionid: %s", clientState.ClientType(), connectionID) + } +} diff --git a/x/ratesync/keeper/msg_server.go b/x/ratesync/keeper/msg_server.go new file mode 100644 index 000000000..6832c5bd2 --- /dev/null +++ b/x/ratesync/keeper/msg_server.go @@ -0,0 +1,343 @@ +package keeper + +import ( + "context" + "encoding/json" + "fmt" + wasmtypes "github.com/CosmWasm/wasmd/x/wasm/types" + "github.com/cosmos/gogoproto/proto" + channeltypes "github.com/cosmos/ibc-go/v7/modules/core/04-channel/types" + "slices" + + errorsmod "cosmossdk.io/errors" + sdk "github.com/cosmos/cosmos-sdk/types" + sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" + liquidstakeibctypes "github.com/persistenceOne/pstake-native/v2/x/liquidstakeibc/types" + + "github.com/persistenceOne/pstake-native/v2/x/ratesync/types" +) + +type msgServer struct { + Keeper +} + +// NewMsgServerImpl returns an implementation of the MsgServer interface +// for the provided Keeper. +func NewMsgServerImpl(keeper Keeper) types.MsgServer { + return &msgServer{Keeper: keeper} +} + +var _ types.MsgServer = msgServer{} + +func (k msgServer) CreateHostChain(goCtx context.Context, msg *types.MsgCreateHostChain) (*types.MsgCreateHostChainResponse, error) { + ctx := sdk.UnwrapSDKContext(goCtx) + + params := k.GetParams(ctx) + // Checks if the msg creator is the same as the current owner + if msg.Authority != k.authority && msg.Authority != params.Admin { + return nil, errorsmod.Wrapf(sdkerrors.ErrorInvalidSigner, "tx signer is not a module authority") + } + + // get the host chain id + chainID, err := k.GetChainID(ctx, msg.HostChain.ConnectionID) + if err != nil { + return nil, errorsmod.Wrapf(sdkerrors.ErrNotFound, "chain id not found for connection \"%s\": \"%s\"", msg.HostChain.ConnectionID, err) + } + if chainID != msg.HostChain.ChainID { + return nil, errorsmod.Wrapf(sdkerrors.ErrInvalidChainID, "chain id does not match connection-chainID input \"%s\": found\"%s\"", msg.HostChain.ChainID, chainID) + } + + id := k.IncrementHostChainID(ctx) + msg.HostChain.ID = id + + if msg.HostChain.ICAAccount.Owner == "" { + msg.HostChain.ICAAccount.Owner = types.DefaultPortOwner(id) + } // else handled in msg.ValidateBasic() + // register ratesyn ICA + if msg.HostChain.ICAAccount.ChannelState == liquidstakeibctypes.ICAAccount_ICA_CHANNEL_CREATING { + err = k.icaControllerKeeper.RegisterInterchainAccount(ctx, msg.HostChain.ConnectionID, msg.HostChain.ICAAccount.Owner, "") + if err != nil { + return nil, errorsmod.Wrapf( + types.ErrRegisterFailed, + "error registering %s ratesync ica with owner: %s, err:%s", + chainID, msg.HostChain.ICAAccount.Owner, + err.Error(), + ) + } + } // else handled in validate basic (not allowed to create new host chain with previous ICA as portID is default and suffixed by ID + + k.SetHostChain( + ctx, + msg.HostChain, + ) + + ctx.EventManager().EmitEvents(sdk.Events{ + sdk.NewEvent( + types.EventTypeCreateHostChain, + sdk.NewAttribute(types.AttributeKeyAuthority, msg.Authority), + sdk.NewAttribute(types.AttributeChainID, msg.HostChain.ChainID), + sdk.NewAttribute(types.AttributeConnectionID, msg.HostChain.ConnectionID), + sdk.NewAttribute(types.AttributeID, fmt.Sprintf("%v", id)), + ), + }) + return &types.MsgCreateHostChainResponse{ID: id}, nil +} + +func (k msgServer) UpdateHostChain(goCtx context.Context, msg *types.MsgUpdateHostChain) (*types.MsgUpdateHostChainResponse, error) { + ctx := sdk.UnwrapSDKContext(goCtx) + + params := k.GetParams(ctx) + // Checks if the msg creator is the same as the current owner + if msg.Authority != k.authority && msg.Authority != params.Admin { + return nil, errorsmod.Wrapf(sdkerrors.ErrorInvalidSigner, "tx signer is not a module authority") + } + + // Check if the value exists + oldHC, isFound := k.GetHostChain( + ctx, + msg.HostChain.ID, + ) + if !isFound { + return nil, errorsmod.Wrap(sdkerrors.ErrKeyNotFound, "id not set, hostchain does not exist") + } + + // only allow enable disable feature && instantiate. + // to change chain-id etc, add delete and create new hostchain with same details + if msg.HostChain.ConnectionID != oldHC.ConnectionID { + return nil, errorsmod.Wrapf(types.ErrInvalid, "invalid connectionID, connectionID cannot be updated, "+ + "connectionID mismatch got %s, found %s", msg.HostChain.ConnectionID, oldHC.ConnectionID) + } + + if oldHC.ICAAccount.ChannelState != liquidstakeibctypes.ICAAccount_ICA_CHANNEL_CREATED { + return nil, errorsmod.Wrapf(types.ErrInvalid, "invalid ICAAccount state, should already be active") + } + if msg.HostChain.ICAAccount.ChannelState != oldHC.ICAAccount.ChannelState || + msg.HostChain.ICAAccount.Address != oldHC.ICAAccount.Address || + msg.HostChain.ICAAccount.Owner != oldHC.ICAAccount.Owner || + !msg.HostChain.ICAAccount.Balance.IsEqual(oldHC.ICAAccount.Balance) { + return nil, errorsmod.Wrapf(types.ErrInvalid, "invalid ICAAccount, ICA account cannot be updated, "+ + "ICAAccount mismatch got %s, found %s", msg.HostChain.ICAAccount, oldHC.ICAAccount) + } + + updateStr := "" + isOneUpdated := false + saveUpdate := func(updates string) (bool, string) { + return true, updates + } + + chainID, err := k.GetChainID(ctx, msg.HostChain.ConnectionID) + if err != nil { + return nil, errorsmod.Wrapf(sdkerrors.ErrNotFound, "chain id not found for connection \"%s\": \"%s\"", msg.HostChain.ConnectionID, err) + } + if chainID != msg.HostChain.ChainID { + return nil, errorsmod.Wrapf(sdkerrors.ErrInvalidChainID, "chain id does not match connection-chainID input \"%s\": found\"%s\"", msg.HostChain.ChainID, chainID) + } + if msg.HostChain.ChainID != oldHC.ChainID { + oldHC.ChainID = msg.HostChain.ChainID + isOneUpdated, updateStr = saveUpdate(fmt.Sprintf("updates host chain chainID %v to %v \n", oldHC.ChainID, msg.HostChain.ChainID)) + } + + //allow only one feature update per tx. + if !isOneUpdated && !msg.HostChain.Features.LiquidStakeIBC.Equals(oldHC.Features.LiquidStakeIBC) { + if oldHC.Features.LiquidStakeIBC.Instantiation == types.InstantiationState_INSTANTIATION_NOT_INITIATED { + // allow to add details and instantiate or just save if trying to recover. + switch msg.HostChain.Features.LiquidStakeIBC.Instantiation { + case types.InstantiationState_INSTANTIATION_NOT_INITIATED: + // just update oldhc, validate basic will take care of mismatch states. + oldHC.Features.LiquidStakeIBC = msg.HostChain.Features.LiquidStakeIBC + case types.InstantiationState_INSTANTIATION_INITIATED: + // update oldhc, generate and execute wasm instantiate + oldHC.Features.LiquidStakeIBC = msg.HostChain.Features.LiquidStakeIBC + + // generate contract msg{msg} + contractMsg := types.InstantiateLiquidStakeRateContract{ + Admin: oldHC.ICAAccount.Address, + } + contractMsgBz, err := json.Marshal(contractMsg) + if err != nil { + return nil, errorsmod.Wrapf(err, "unable to marshal InstantiateLiquidStakeRateContract") + } + + msg := &wasmtypes.MsgInstantiateContract{ + Sender: oldHC.ICAAccount.Address, + Admin: oldHC.ICAAccount.Address, + CodeID: oldHC.Features.LiquidStakeIBC.CodeID, + Label: fmt.Sprintf("PSTAKE ratesync, ID-%v", oldHC.ID), + Msg: contractMsgBz, + Funds: sdk.Coins{}, + } + memo := types.ICAMemo{ + FeatureType: types.FeatureType_LIQUID_STAKE_IBC, + HostChainID: oldHC.ID, + } + memobz, err := json.Marshal(memo) + if err != nil { + return nil, err + } + _, err = k.GenerateAndExecuteICATx(ctx, oldHC.ConnectionID, oldHC.ICAAccount.Owner, []proto.Message{msg}, string(memobz)) + if err != nil { + return nil, err + } + + case types.InstantiationState_INSTANTIATION_COMPLETED: + // just update oldhc, validate basic will take care of mismatch states. + oldHC.Features.LiquidStakeIBC = msg.HostChain.Features.LiquidStakeIBC + } + } + if !slices.Equal(oldHC.Features.LiquidStakeIBC.Denoms, msg.HostChain.Features.LiquidStakeIBC.Denoms) { + oldHC.Features.LiquidStakeIBC.Denoms = msg.HostChain.Features.LiquidStakeIBC.Denoms + } + isOneUpdated, updateStr = saveUpdate(fmt.Sprintf("updates LiquidStakeIBC feature from %v to %v \n", oldHC.Features.LiquidStakeIBC, msg.HostChain.Features.LiquidStakeIBC)) + } + if !isOneUpdated && !msg.HostChain.Features.LiquidStake.Equals(oldHC.Features.LiquidStake) { + if oldHC.Features.LiquidStake.Instantiation == types.InstantiationState_INSTANTIATION_NOT_INITIATED { + // allow to add details and instantiate or just save if trying to recover. + switch msg.HostChain.Features.LiquidStake.Instantiation { + case types.InstantiationState_INSTANTIATION_NOT_INITIATED: + // just update oldhc, validate basic will take care of mismatch states. + oldHC.Features.LiquidStake = msg.HostChain.Features.LiquidStake + case types.InstantiationState_INSTANTIATION_INITIATED: + // update oldhc, generate and execute wasm instantiate + oldHC.Features.LiquidStake = msg.HostChain.Features.LiquidStake + + // generate contract msg{msg} + contractMsg := types.InstantiateLiquidStakeRateContract{ + Admin: oldHC.ICAAccount.Address, + } + contractMsgBz, err := json.Marshal(contractMsg) + if err != nil { + return nil, errorsmod.Wrapf(err, "unable to marshal InstantiateLiquidStakeRateContract") + } + + msg := &wasmtypes.MsgInstantiateContract{ + Sender: oldHC.ICAAccount.Address, + Admin: oldHC.ICAAccount.Address, + CodeID: oldHC.Features.LiquidStake.CodeID, + Label: fmt.Sprintf("PSTAKE ratesync, ID-%v", oldHC.ID), + Msg: contractMsgBz, + Funds: sdk.Coins{}, + } + memo := types.ICAMemo{ + FeatureType: types.FeatureType_LIQUID_STAKE, + HostChainID: oldHC.ID, + } + memobz, err := json.Marshal(memo) + if err != nil { + return nil, err + } + _, err = k.GenerateAndExecuteICATx(ctx, oldHC.ConnectionID, oldHC.ICAAccount.Owner, []proto.Message{msg}, string(memobz)) + if err != nil { + return nil, err + } + + case types.InstantiationState_INSTANTIATION_COMPLETED: + // just update oldhc, validate basic will take care of mismatch states. + oldHC.Features.LiquidStake = msg.HostChain.Features.LiquidStake + } + } + if !slices.Equal(oldHC.Features.LiquidStake.Denoms, msg.HostChain.Features.LiquidStake.Denoms) { + oldHC.Features.LiquidStake.Denoms = msg.HostChain.Features.LiquidStake.Denoms + } + isOneUpdated, updateStr = saveUpdate(fmt.Sprintf("updates LiquidStake feature from %v to %v", oldHC.Features.LiquidStake, msg.HostChain.Features.LiquidStake)) + } + err = oldHC.Features.ValdidateBasic() + if err != nil { + return nil, err + } + + k.SetHostChain(ctx, oldHC) + + ctx.EventManager().EmitEvents(sdk.Events{ + sdk.NewEvent( + types.EventTypeUpdateHostChain, + sdk.NewAttribute(types.AttributeKeyAuthority, msg.Authority), + sdk.NewAttribute(types.AttributeChainID, oldHC.ChainID), + sdk.NewAttribute(types.AttributeConnectionID, oldHC.ConnectionID), + sdk.NewAttribute(types.AttributeID, fmt.Sprintf("%v", oldHC.ID)), + sdk.NewAttribute(types.AttributeUpdates, updateStr), + ), + }) + return &types.MsgUpdateHostChainResponse{}, nil +} + +func (k msgServer) DeleteHostChain(goCtx context.Context, msg *types.MsgDeleteHostChain) (*types.MsgDeleteHostChainResponse, error) { + ctx := sdk.UnwrapSDKContext(goCtx) + + params := k.GetParams(ctx) + // Checks if the msg creator is the same as the current owner + if msg.Authority != k.authority && msg.Authority != params.Admin { + return nil, errorsmod.Wrapf(sdkerrors.ErrorInvalidSigner, "tx signer is not a module authority") + } + + // Check if the value exists + hc, isFound := k.GetHostChain( + ctx, + msg.ID, + ) + if !isFound { + return nil, errorsmod.Wrap(sdkerrors.ErrKeyNotFound, "id not set") + } + + // check pending packets, do not allow to delete if packets are pending. + portID := types.MustICAPortIDFromOwner(hc.ICAAccount.Owner) + channelID, ok := k.icaControllerKeeper.GetOpenActiveChannel(ctx, hc.ConnectionID, portID) + if !ok { + return nil, errorsmod.Wrapf(channeltypes.ErrChannelNotFound, "PortID: %s, connectionID: %s", portID, hc.ConnectionID) + } + nextSendSeq, ok := k.ibcKeeper.ChannelKeeper.GetNextSequenceSend(ctx, portID, channelID) + if !ok { + return nil, errorsmod.Wrapf(channeltypes.ErrSequenceSendNotFound, "PortID: %s, channelID: %s", portID, channelID) + } + nextAckSeq, ok := k.ibcKeeper.ChannelKeeper.GetNextSequenceAck(ctx, portID, channelID) + if !ok { + return nil, errorsmod.Wrapf(channeltypes.ErrSequenceAckNotFound, "PortID: %s, channelID: %s", portID, channelID) + } + if nextSendSeq != nextAckSeq { + return nil, errorsmod.Wrapf(channeltypes.ErrPacketSequenceOutOfOrder, "PortID: %s, channelID: %s, NextSendSequence: %v, NextAckSequence: %v", portID, channelID, nextSendSeq, nextAckSeq) + } + + k.RemoveHostChain( + ctx, + msg.ID, + ) + + ctx.EventManager().EmitEvents(sdk.Events{ + sdk.NewEvent( + types.EventTypeDeleteHostChain, + sdk.NewAttribute(types.AttributeKeyAuthority, msg.Authority), + sdk.NewAttribute(types.AttributeChainID, hc.ChainID), + sdk.NewAttribute(types.AttributeConnectionID, hc.ConnectionID), + sdk.NewAttribute(types.AttributeID, fmt.Sprintf("%v", hc.ID)), + ), + }) + + return &types.MsgDeleteHostChainResponse{}, nil +} + +// UpdateParams defines a method for updating the module params +func (k msgServer) UpdateParams( + goCtx context.Context, + msg *types.MsgUpdateParams, +) (*types.MsgUpdateParamsResponse, error) { + ctx := sdk.UnwrapSDKContext(goCtx) + + params := k.GetParams(ctx) + + // authority needs to be either the gov module account (for proposals) + // or the module admin account (for normal txs) + if msg.Authority != k.authority && msg.Authority != params.Admin { + return nil, errorsmod.Wrapf(sdkerrors.ErrorInvalidSigner, "tx signer is not a module authority") + } + + k.SetParams(ctx, msg.Params) + + ctx.EventManager().EmitEvents(sdk.Events{ + sdk.NewEvent( + types.EventTypeUpdateParams, + sdk.NewAttribute(types.AttributeKeyAuthority, msg.Authority), + sdk.NewAttribute(types.AttributeKeyUpdatedParams, msg.Params.String()), + ), + }) + + return &types.MsgUpdateParamsResponse{}, nil +} diff --git a/x/ratesync/keeper/msg_server_test.go b/x/ratesync/keeper/msg_server_test.go new file mode 100644 index 000000000..702a703e8 --- /dev/null +++ b/x/ratesync/keeper/msg_server_test.go @@ -0,0 +1,150 @@ +package keeper_test + +import ( + "context" + liquidstakeibctypes "github.com/persistenceOne/pstake-native/v2/x/liquidstakeibc/types" + "testing" + + sdk "github.com/cosmos/cosmos-sdk/types" + sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" + + "github.com/persistenceOne/pstake-native/v2/x/ratesync/keeper" + "github.com/persistenceOne/pstake-native/v2/x/ratesync/types" +) + +func (suite *IntegrationTestSuite) setupMsgServer() (types.MsgServer, context.Context) { + k, ctx := suite.app.RatesyncKeeper, suite.ctx + return keeper.NewMsgServerImpl(*k), sdk.WrapSDKContext(ctx) +} + +func (suite *IntegrationTestSuite) TestMsgServer() { + ms, ctx := suite.setupMsgServer() + suite.Require().NotNil(ms) + suite.Require().NotNil(ctx) +} + +func (suite *IntegrationTestSuite) TestChainMsgServerCreate() { + k, ctx := suite.app.RatesyncKeeper, suite.ctx + srv := keeper.NewMsgServerImpl(*k) + wctx := sdk.WrapSDKContext(ctx) + + for i := 0; i < 5; i++ { + hc := ValidHostChainInMsg(0) + hc.ChainID = ctx.ChainID() + expected := &types.MsgCreateHostChain{Authority: GovAddress.String(), + HostChain: hc, + } + _, err := srv.CreateHostChain(wctx, expected) + suite.Require().NoError(err) + _, found := k.GetHostChain(ctx, + uint64(i+1)) + suite.Require().True(found) + } +} + +func (suite *IntegrationTestSuite) TestChainMsgServerUpdate() { + k, ctx := suite.app.RatesyncKeeper, suite.ctx + hc := createNChain(k, ctx, 1)[0] + hc.ICAAccount.ChannelState = liquidstakeibctypes.ICAAccount_ICA_CHANNEL_CREATED + hc.ChainID = ctx.ChainID() + k.SetHostChain(ctx, hc) + hc2 := types.HostChain{ID: 1} + tests := []struct { + desc string + request *types.MsgUpdateHostChain + err error + }{ + { + desc: "Completed", + request: &types.MsgUpdateHostChain{Authority: GovAddress.String(), + HostChain: hc, + }, + }, + { + desc: "Unauthorized", + request: &types.MsgUpdateHostChain{Authority: "B", + HostChain: hc, + }, + err: sdkerrors.ErrorInvalidSigner, + }, + { + desc: "KeyNotFound", + request: &types.MsgUpdateHostChain{Authority: GovAddress.String(), + HostChain: hc2, + }, + err: sdkerrors.ErrKeyNotFound, + }, + } + for _, tc := range tests { + suite.T().Run(tc.desc, func(t *testing.T) { + srv := keeper.NewMsgServerImpl(*k) + wctx := sdk.WrapSDKContext(ctx) + expected := &types.MsgCreateHostChain{Authority: GovAddress.String(), + HostChain: hc, + } + + _, err := srv.UpdateHostChain(wctx, tc.request) + if tc.err != nil { + suite.Require().ErrorIs(err, tc.err) + } else { + suite.Require().NoError(err) + _, found := k.GetHostChain(ctx, + expected.HostChain.ID, + ) + suite.Require().True(found) + } + }) + } +} + +func (suite *IntegrationTestSuite) TestChainMsgServerDelete() { + k, ctx := suite.app.RatesyncKeeper, suite.ctx + hcs := createNChain(k, ctx, 5) + hc := hcs[1] + hc.ChainID = ctx.ChainID() + hc.ConnectionID = "connection-0" + k.SetHostChain(ctx, hc) + tests := []struct { + desc string + request *types.MsgDeleteHostChain + err error + }{ + { + desc: "Completed", + request: &types.MsgDeleteHostChain{Authority: GovAddress.String(), + ID: 1, + }, + }, + { + desc: "Unauthorized", + request: &types.MsgDeleteHostChain{Authority: "B", + ID: 2, + }, + err: sdkerrors.ErrorInvalidSigner, + }, + { + desc: "KeyNotFound", + request: &types.MsgDeleteHostChain{Authority: GovAddress.String(), + ID: 10, + }, + err: sdkerrors.ErrKeyNotFound, + }, + } + for _, tc := range tests { + suite.T().Run(tc.desc, func(t *testing.T) { + srv := keeper.NewMsgServerImpl(*k) + wctx := sdk.WrapSDKContext(ctx) + + _, err := srv.DeleteHostChain(wctx, tc.request) + if tc.err != nil { + suite.Require().ErrorIs(err, tc.err) + } else { + suite.Require().NoError(err) + _, found := k.GetHostChain(ctx, + tc.request.ID, + ) + suite.Require().False(found) + } + }) + } +} diff --git a/x/ratesync/keeper/params.go b/x/ratesync/keeper/params.go new file mode 100644 index 000000000..63263f9f7 --- /dev/null +++ b/x/ratesync/keeper/params.go @@ -0,0 +1,26 @@ +package keeper + +import ( + sdk "github.com/cosmos/cosmos-sdk/types" + + "github.com/persistenceOne/pstake-native/v2/x/ratesync/types" +) + +// GetParams gets the parameters. +func (k *Keeper) GetParams(ctx sdk.Context) (params types.Params) { + store := ctx.KVStore(k.storeKey) + bz := store.Get(types.ParamsKeyPrefix) + if bz == nil { + return params + } + + k.cdc.MustUnmarshal(bz, ¶ms) + return params +} + +// SetParams sets the parameters. +func (k *Keeper) SetParams(ctx sdk.Context, params types.Params) { + store := ctx.KVStore(k.storeKey) + bytes := k.cdc.MustMarshal(¶ms) + store.Set(types.ParamsKeyPrefix, bytes) +} diff --git a/x/ratesync/keeper/params_test.go b/x/ratesync/keeper/params_test.go new file mode 100644 index 000000000..e2337bac2 --- /dev/null +++ b/x/ratesync/keeper/params_test.go @@ -0,0 +1,14 @@ +package keeper_test + +import ( + "github.com/persistenceOne/pstake-native/v2/x/ratesync/types" +) + +func (suite *IntegrationTestSuite) TestGetParams() { + k, ctx := suite.app.RatesyncKeeper, suite.ctx + params := types.DefaultParams() + + k.SetParams(ctx, params) + + suite.Require().EqualValues(params, k.GetParams(ctx)) +} diff --git a/x/ratesync/keeper/query.go b/x/ratesync/keeper/query.go new file mode 100644 index 000000000..82503ced5 --- /dev/null +++ b/x/ratesync/keeper/query.go @@ -0,0 +1,69 @@ +package keeper + +import ( + "context" + + "github.com/cosmos/cosmos-sdk/store/prefix" + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/cosmos/cosmos-sdk/types/query" + "google.golang.org/grpc/codes" + "google.golang.org/grpc/status" + + "github.com/persistenceOne/pstake-native/v2/x/ratesync/types" +) + +var _ types.QueryServer = Keeper{} + +func (k Keeper) Params(goCtx context.Context, req *types.QueryParamsRequest) (*types.QueryParamsResponse, error) { + if req == nil { + return nil, status.Error(codes.InvalidArgument, "invalid request") + } + ctx := sdk.UnwrapSDKContext(goCtx) + + return &types.QueryParamsResponse{Params: k.GetParams(ctx)}, nil +} + +func (k Keeper) AllHostChains(goCtx context.Context, req *types.QueryAllHostChainsRequest) (*types.QueryAllHostChainsResponse, error) { + if req == nil { + return nil, status.Error(codes.InvalidArgument, "invalid request") + } + + var chains []types.HostChain + ctx := sdk.UnwrapSDKContext(goCtx) + + store := ctx.KVStore(k.storeKey) + chainStore := prefix.NewStore(store, types.HostChainKeyPrefix) + + pageRes, err := query.Paginate(chainStore, req.Pagination, func(key []byte, value []byte) error { + var chain types.HostChain + if err := k.cdc.Unmarshal(value, &chain); err != nil { + return err + } + + chains = append(chains, chain) + return nil + }) + + if err != nil { + return nil, status.Error(codes.Internal, err.Error()) + } + + return &types.QueryAllHostChainsResponse{HostChains: chains, Pagination: pageRes}, nil +} + +func (k Keeper) HostChain(goCtx context.Context, req *types.QueryGetHostChainRequest) (*types.QueryGetHostChainResponse, error) { + if req == nil { + return nil, status.Error(codes.InvalidArgument, "invalid request") + } + ctx := sdk.UnwrapSDKContext(goCtx) + + val, found := k.GetHostChain( + ctx, + req.ID, + ) + if !found { + return nil, status.Error(codes.NotFound, "not found") + } + + return &types.QueryGetHostChainResponse{HostChain: val}, nil +} diff --git a/x/ratesync/keeper/query_test.go b/x/ratesync/keeper/query_test.go new file mode 100644 index 000000000..d5a017958 --- /dev/null +++ b/x/ratesync/keeper/query_test.go @@ -0,0 +1,117 @@ +package keeper_test + +import ( + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/cosmos/cosmos-sdk/types/query" + "github.com/persistenceOne/pstake-native/v2/x/ratesync/types" + "google.golang.org/grpc/codes" + "google.golang.org/grpc/status" + "testing" +) + +func (suite *IntegrationTestSuite) TestParamsQuery() { + keeper, ctx := suite.app.RatesyncKeeper, suite.ctx + wctx := sdk.WrapSDKContext(ctx) + params := types.DefaultParams() + keeper.SetParams(ctx, params) + + response, err := keeper.Params(wctx, &types.QueryParamsRequest{}) + suite.Require().NoError(err) + suite.Require().Equal(&types.QueryParamsResponse{Params: params}, response) +} + +func (suite *IntegrationTestSuite) TestChainQuerySingle() { + keeper, ctx := suite.app.RatesyncKeeper, suite.ctx + wctx := sdk.WrapSDKContext(ctx) + msgs := createNChain(keeper, ctx, 2) + tests := []struct { + desc string + request *types.QueryGetHostChainRequest + response *types.QueryGetHostChainResponse + err error + }{ + { + desc: "First", + request: &types.QueryGetHostChainRequest{ + ID: msgs[0].ID, + }, + response: &types.QueryGetHostChainResponse{HostChain: msgs[0]}, + }, + { + desc: "Second", + request: &types.QueryGetHostChainRequest{ + ID: msgs[1].ID, + }, + response: &types.QueryGetHostChainResponse{HostChain: msgs[1]}, + }, + { + desc: "KeyNotFound", + request: &types.QueryGetHostChainRequest{ + ID: uint64(100000), + }, + err: status.Error(codes.NotFound, "not found"), + }, + { + desc: "InvalidRequest", + err: status.Error(codes.InvalidArgument, "invalid request"), + }, + } + for _, tc := range tests { + suite.T().Run(tc.desc, func(t *testing.T) { + response, err := keeper.HostChain(wctx, tc.request) + if tc.err != nil { + suite.Require().ErrorIs(err, tc.err) + } else { + suite.Require().NoError(err) + suite.Require().Equal(tc.response, response) + } + }) + } +} + +func (suite *IntegrationTestSuite) TestAllHostChainsQueryPaginated() { + keeper, ctx := suite.app.RatesyncKeeper, suite.ctx + wctx := sdk.WrapSDKContext(ctx) + msgs := createNChain(keeper, ctx, 5) + + request := func(next []byte, offset, limit uint64, total bool) *types.QueryAllHostChainsRequest { + return &types.QueryAllHostChainsRequest{ + Pagination: &query.PageRequest{ + Key: next, + Offset: offset, + Limit: limit, + CountTotal: total, + }, + } + } + suite.T().Run("ByOffset", func(t *testing.T) { + step := 2 + for i := 0; i < len(msgs); i += step { + resp, err := keeper.AllHostChains(wctx, request(nil, uint64(i), uint64(step), false)) + suite.Require().NoError(err) + suite.Require().LessOrEqual(len(resp.HostChains), step) + suite.Require().Subset(msgs, resp.HostChains) + } + }) + suite.T().Run("ByKey", func(t *testing.T) { + step := 2 + var next []byte + for i := 0; i < len(msgs); i += step { + resp, err := keeper.AllHostChains(wctx, request(next, 0, uint64(step), false)) + suite.Require().NoError(err) + suite.Require().LessOrEqual(len(resp.HostChains), step) + suite.Require().Subset(msgs, resp.HostChains) + next = resp.Pagination.NextKey + } + }) + suite.T().Run("Total", func(t *testing.T) { + resp, err := keeper.AllHostChains(wctx, request(nil, 0, 0, true)) + suite.Require().NoError(err) + suite.Require().Equal(len(msgs), int(resp.Pagination.Total)) + suite.Require().ElementsMatch(msgs, resp.HostChains) + }) + suite.T().Run("InvalidRequest", func(t *testing.T) { + _, err := keeper.AllHostChains(wctx, nil) + suite.Require().ErrorIs(err, status.Error(codes.InvalidArgument, "invalid request")) + }) +} diff --git a/x/ratesync/keeper/setup_suite_test.go b/x/ratesync/keeper/setup_suite_test.go new file mode 100644 index 000000000..e0289f2b1 --- /dev/null +++ b/x/ratesync/keeper/setup_suite_test.go @@ -0,0 +1,294 @@ +package keeper_test + +import ( + "fmt" + sdk "github.com/cosmos/cosmos-sdk/types" + authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" + govtypes "github.com/cosmos/cosmos-sdk/x/gov/types/v1beta1" + icatypes "github.com/cosmos/ibc-go/v7/modules/apps/27-interchain-accounts/types" + ibctransfertypes "github.com/cosmos/ibc-go/v7/modules/apps/transfer/types" + clienttypes "github.com/cosmos/ibc-go/v7/modules/core/02-client/types" + channeltypes "github.com/cosmos/ibc-go/v7/modules/core/04-channel/types" + ibctesting "github.com/cosmos/ibc-go/v7/testing" + "github.com/persistenceOne/pstake-native/v2/x/ratesync/types" + "github.com/stretchr/testify/suite" + "strconv" + "testing" + + "github.com/persistenceOne/pstake-native/v2/app" + "github.com/persistenceOne/pstake-native/v2/app/helpers" +) + +var ( + HostDenom = "uatom" + MintDenom = "stk/uatom" + MinDeposit = sdk.NewInt(5) + PstakeFeeAddress = "persistence1xruvjju28j0a5ud5325rfdak8f5a04h0s30mld" + GovAddress = authtypes.NewModuleAddress("gov") + // TestVersion defines a reusable interchainaccounts version string for testing purposes + TestVersion = string(icatypes.ModuleCdc.MustMarshalJSON(&icatypes.Metadata{ + Version: icatypes.Version, + ControllerConnectionId: ibctesting.FirstConnectionID, + HostConnectionId: ibctesting.FirstConnectionID, + Encoding: icatypes.EncodingProtobuf, + TxType: icatypes.TxTypeSDKMultiMsg, + })) +) + +func init() { + ibctesting.DefaultTestingAppInit = helpers.SetupTestingApp +} + +type IntegrationTestSuite struct { + suite.Suite + + app *app.PstakeApp + ctx sdk.Context + govHandler govtypes.Handler + + coordinator *ibctesting.Coordinator + chainA *ibctesting.TestChain //pstake chain + chainB *ibctesting.TestChain //host chain, run tests of active chains + chainC *ibctesting.TestChain //host chain 2, run tests of to activate chains + + transferPathAB *ibctesting.Path // chainA - chainB transfer path + transferPathAC *ibctesting.Path // chainA - chainC transfer path + + ratesyncPathAB *ibctesting.Path // chainA - chain B ratesync ica path +} + +func TestKeeperTestSuite(t *testing.T) { + suite.Run(t, new(IntegrationTestSuite)) +} + +func (suite *IntegrationTestSuite) SetupTest() { + + suite.coordinator = ibctesting.NewCoordinator(suite.T(), 0) + + ibctesting.DefaultTestingAppInit = helpers.SetupTestingApp + sdk.DefaultBondDenom = "uxprt" + suite.chainA = ibctesting.NewTestChain(suite.T(), suite.coordinator, ibctesting.GetChainID(1)) + suite.ResetEpochs() + ibctesting.DefaultTestingAppInit = ibctesting.SetupTestingApp + sdk.DefaultBondDenom = HostDenom + suite.chainB = ibctesting.NewTestChain(suite.T(), suite.coordinator, ibctesting.GetChainID(2)) + sdk.DefaultBondDenom = "uosmo" + suite.chainC = ibctesting.NewTestChain(suite.T(), suite.coordinator, ibctesting.GetChainID(3)) + + suite.coordinator.Chains = map[string]*ibctesting.TestChain{ + ibctesting.GetChainID(1): suite.chainA, + ibctesting.GetChainID(2): suite.chainB, + ibctesting.GetChainID(3): suite.chainC, + } + + suite.transferPathAB = NewTransferPath(suite.chainA, suite.chainB) + suite.coordinator.Setup(suite.transferPathAB) + + suite.transferPathAC = NewTransferPath(suite.chainA, suite.chainC) + suite.coordinator.Setup(suite.transferPathAC) + + suite.app = suite.chainA.App.(*app.PstakeApp) + + //suite.SetupHostChainAB() + suite.SetupICAChannelsAB() + + suite.Transfer(suite.transferPathAB, sdk.NewCoin("uatom", sdk.NewInt(1000000000000))) + suite.Transfer(suite.transferPathAC, sdk.NewCoin("uosmo", sdk.NewInt(1000000000000))) + + //suite.SetupLSM() + + suite.CleanupSetup() + suite.ctx = suite.chainA.GetContext() +} + +func (suite *IntegrationTestSuite) CleanupSetup() { +} +func (suite *IntegrationTestSuite) ResetEpochs() { + ctx := suite.chainA.GetContext() + + //ctxCheck := app.BaseApp.NewContext(true, tmproto.Header{}) + epochsKeeper := suite.chainA.App.(*app.PstakeApp).EpochsKeeper + + for _, epoch := range epochsKeeper.AllEpochInfos(ctx) { + epoch.StartTime = ctx.BlockTime() + epoch.CurrentEpoch = int64(1) + epoch.CurrentEpochStartTime = ctx.BlockTime() + epoch.CurrentEpochStartHeight = ctx.BlockHeight() + epochsKeeper.DeleteEpochInfo(ctx, epoch.Identifier) + err := epochsKeeper.AddEpochInfo(ctx, epoch) + if err != nil { + panic(err) + } + } +} + +func NewTransferPath(chainA, chainB *ibctesting.TestChain) *ibctesting.Path { + path := ibctesting.NewPath(chainA, chainB) + path.EndpointA.ChannelConfig.PortID = ibctesting.TransferPort + path.EndpointB.ChannelConfig.PortID = ibctesting.TransferPort + path.EndpointA.ChannelConfig.Version = ibctransfertypes.Version + path.EndpointB.ChannelConfig.Version = ibctransfertypes.Version + + return path +} +func (suite *IntegrationTestSuite) Transfer(path *ibctesting.Path, coin sdk.Coin) { + transferMsg := ibctransfertypes.NewMsgTransfer(path.EndpointB.ChannelConfig.PortID, + path.EndpointB.ChannelID, coin, path.EndpointB.Chain.SenderAccount.GetAddress().String(), + path.EndpointA.Chain.SenderAccount.GetAddress().String(), path.EndpointA.Chain.GetTimeoutHeight(), + 0, "") + result, err := path.EndpointB.Chain.SendMsgs(transferMsg) + suite.Require().NoError(err) // message committed + + packet, err := ibctesting.ParsePacketFromEvents(result.GetEvents()) + suite.Require().NoError(err) + + err = path.RelayPacket(packet) + suite.Require().NoError(err) +} +func (suite *IntegrationTestSuite) SetupICAChannelsAB() { + icapath := NewICAPath(suite.chainA, suite.chainB) + icapath.EndpointA.ClientID = suite.transferPathAB.EndpointA.ClientID + icapath.EndpointB.ClientID = suite.transferPathAB.EndpointB.ClientID + icapath.EndpointA.ConnectionID = suite.transferPathAB.EndpointA.ConnectionID + icapath.EndpointB.ConnectionID = suite.transferPathAB.EndpointB.ConnectionID + icapath.EndpointA.ClientConfig = suite.transferPathAB.EndpointA.ClientConfig + icapath.EndpointB.ClientConfig = suite.transferPathAB.EndpointB.ClientConfig + icapath.EndpointA.ConnectionConfig = suite.transferPathAB.EndpointA.ConnectionConfig + icapath.EndpointB.ConnectionConfig = suite.transferPathAB.EndpointB.ConnectionConfig + suite.ratesyncPathAB = icapath + + err := suite.SetupICAPath(suite.ratesyncPathAB, types.DefaultPortOwner(1)) + suite.Require().NoError(err) + +} +func NewICAPath(chainA, chainB *ibctesting.TestChain) *ibctesting.Path { + path := ibctesting.NewPath(chainA, chainB) + path.EndpointA.ChannelConfig.PortID = icatypes.HostPortID + path.EndpointB.ChannelConfig.PortID = icatypes.HostPortID + path.EndpointA.ChannelConfig.Order = channeltypes.ORDERED + path.EndpointB.ChannelConfig.Order = channeltypes.ORDERED + path.EndpointA.ChannelConfig.Version = TestVersion + path.EndpointB.ChannelConfig.Version = TestVersion + + return path +} + +func (suite *IntegrationTestSuite) RegisterInterchainAccount(endpoint *ibctesting.Endpoint, owner string) error { + portID, err := icatypes.NewControllerPortID(owner) + if err != nil { + return err + } + + channelSequence := suite.app.GetIBCKeeper().ChannelKeeper.GetNextChannelSequence(endpoint.Chain.GetContext()) + + if err := suite.app.ICAControllerKeeper.RegisterInterchainAccount(endpoint.Chain.GetContext(), endpoint.ConnectionID, owner, TestVersion); err != nil { + return err + } + + // commit state changes for proof verification + endpoint.Chain.NextBlock() + + // update port/channel ids + endpoint.ChannelID = channeltypes.FormatChannelIdentifier(channelSequence) + endpoint.ChannelConfig.PortID = portID + endpoint.ChannelConfig.Version = TestVersion + + return nil +} + +// SetupICAPath invokes the InterchainAccounts entrypoint and subsequent channel handshake handlers +func (suite *IntegrationTestSuite) SetupICAPath(path *ibctesting.Path, owner string) error { + if err := suite.RegisterInterchainAccount(path.EndpointA, owner); err != nil { + return err + } + + if err := path.EndpointB.ChanOpenTry(); err != nil { + return err + } + + if err := path.EndpointA.ChanOpenAck(); err != nil { + return err + } + + if err := path.EndpointB.ChanOpenConfirm(); err != nil { + return err + } + + return nil +} + +func (suite *IntegrationTestSuite) RelayAllPacketsAB(packets []channeltypes.Packet) { + suite.Require().NotEqual(0, len(packets), "No packets to relay") + hc, _ := suite.app.LiquidStakeIBCKeeper.GetHostChain(suite.chainA.GetContext(), suite.chainB.ChainID) + for _, packet := range packets { + if packet.SourcePort == hc.PortId { + err := suite.transferPathAB.RelayPacket(packet) + suite.Require().NoError(err) + } else if packet.SourcePort == suite.app.LiquidStakeIBCKeeper.GetPortID(hc.DelegationAccount.Owner) { + err := suite.ratesyncPathAB.RelayPacket(packet) + suite.Require().NoError(err) + } + } +} + +// ParsePacketsFromEvents parses events emitted from a MsgRecvPacket and returns the +// acknowledgement. +func ParsePacketsFromEvents(events sdk.Events) ([]channeltypes.Packet, error) { + packets := make([]channeltypes.Packet, 0) + for _, ev := range events { + if ev.Type == channeltypes.EventTypeSendPacket { + packet := channeltypes.Packet{} + for _, attr := range ev.Attributes { + switch attr.Key { + case channeltypes.AttributeKeyData: //nolint:staticcheck // DEPRECATED + packet.Data = []byte(attr.Value) + + case channeltypes.AttributeKeySequence: + seq, err := strconv.ParseUint(attr.Value, 10, 64) + if err != nil { + return []channeltypes.Packet{}, err + } + + packet.Sequence = seq + + case channeltypes.AttributeKeySrcPort: + packet.SourcePort = attr.Value + + case channeltypes.AttributeKeySrcChannel: + packet.SourceChannel = attr.Value + + case channeltypes.AttributeKeyDstPort: + packet.DestinationPort = attr.Value + + case channeltypes.AttributeKeyDstChannel: + packet.DestinationChannel = attr.Value + + case channeltypes.AttributeKeyTimeoutHeight: + height, err := clienttypes.ParseHeight(attr.Value) + if err != nil { + return []channeltypes.Packet{}, err + } + + packet.TimeoutHeight = height + + case channeltypes.AttributeKeyTimeoutTimestamp: + timestamp, err := strconv.ParseUint(attr.Value, 10, 64) + if err != nil { + return []channeltypes.Packet{}, err + } + + packet.TimeoutTimestamp = timestamp + + default: + continue + } + } + packets = append(packets, packet) + } + } + if len(packets) == 0 { + return []channeltypes.Packet{}, fmt.Errorf("acknowledgement event attribute not found") + } else { + return packets, nil + } +} diff --git a/x/ratesync/module.go b/x/ratesync/module.go new file mode 100644 index 000000000..5e779104d --- /dev/null +++ b/x/ratesync/module.go @@ -0,0 +1,152 @@ +package ratesync + +import ( + "context" + "encoding/json" + "fmt" + // this line is used by starport scaffolding # 1 + + abci "github.com/cometbft/cometbft/abci/types" + "github.com/cosmos/cosmos-sdk/client" + "github.com/cosmos/cosmos-sdk/codec" + cdctypes "github.com/cosmos/cosmos-sdk/codec/types" + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/cosmos/cosmos-sdk/types/module" + "github.com/grpc-ecosystem/grpc-gateway/runtime" + "github.com/spf13/cobra" + + "github.com/persistenceOne/pstake-native/v2/x/ratesync/client/cli" + "github.com/persistenceOne/pstake-native/v2/x/ratesync/keeper" + "github.com/persistenceOne/pstake-native/v2/x/ratesync/types" +) + +var ( + _ module.AppModule = AppModule{} + _ module.AppModuleBasic = AppModuleBasic{} +) + +// ---------------------------------------------------------------------------- +// AppModuleBasic +// ---------------------------------------------------------------------------- + +// AppModuleBasic implements the AppModuleBasic interface that defines the independent methods a Cosmos SDK module needs to implement. +type AppModuleBasic struct { + cdc codec.BinaryCodec +} + +func NewAppModuleBasic(cdc codec.BinaryCodec) AppModuleBasic { + return AppModuleBasic{cdc: cdc} +} + +// Name returns the name of the module as a string +func (AppModuleBasic) Name() string { + return types.ModuleName +} + +// RegisterLegacyAminoCodec registers the amino codec for the module, which is used to marshal and unmarshal structs to/from []byte in order to persist them in the module's KVStore +func (AppModuleBasic) RegisterLegacyAminoCodec(cdc *codec.LegacyAmino) { + types.RegisterCodec(cdc) +} + +// RegisterInterfaces registers a module's interface types and their concrete implementations as proto.Message +func (a AppModuleBasic) RegisterInterfaces(reg cdctypes.InterfaceRegistry) { + types.RegisterInterfaces(reg) +} + +// DefaultGenesis returns a default GenesisState for the module, marshalled to json.RawMessage. The default GenesisState need to be defined by the module developer and is primarily used for testing +func (AppModuleBasic) DefaultGenesis(cdc codec.JSONCodec) json.RawMessage { + return cdc.MustMarshalJSON(types.DefaultGenesis()) +} + +// ValidateGenesis used to validate the GenesisState, given in its json.RawMessage form +func (AppModuleBasic) ValidateGenesis(cdc codec.JSONCodec, config client.TxEncodingConfig, bz json.RawMessage) error { + var genState types.GenesisState + if err := cdc.UnmarshalJSON(bz, &genState); err != nil { + return fmt.Errorf("failed to unmarshal %s genesis state: %w", types.ModuleName, err) + } + return genState.Validate() +} + +// RegisterGRPCGatewayRoutes registers the gRPC Gateway routes for the module +func (AppModuleBasic) RegisterGRPCGatewayRoutes(clientCtx client.Context, mux *runtime.ServeMux) { + err := types.RegisterQueryHandlerClient(context.Background(), mux, types.NewQueryClient(clientCtx)) + if err != nil { + panic(err) + } +} + +// GetTxCmd returns the root Tx command for the module. The subcommands of this root command are used by end-users to generate new transactions containing messages defined in the module +func (a AppModuleBasic) GetTxCmd() *cobra.Command { + return cli.GetTxCmd() +} + +// GetQueryCmd returns the root query command for the module. The subcommands of this root command are used by end-users to generate new queries to the subset of the state defined by the module +func (AppModuleBasic) GetQueryCmd() *cobra.Command { + return cli.GetQueryCmd(types.StoreKey) +} + +// ---------------------------------------------------------------------------- +// AppModule +// ---------------------------------------------------------------------------- + +// AppModule implements the AppModule interface that defines the inter-dependent methods that modules need to implement +type AppModule struct { + AppModuleBasic + + keeper keeper.Keeper + accountKeeper types.AccountKeeper + bankKeeper types.BankKeeper +} + +func NewAppModule( + cdc codec.Codec, + keeper keeper.Keeper, + accountKeeper types.AccountKeeper, + bankKeeper types.BankKeeper, +) AppModule { + return AppModule{ + AppModuleBasic: NewAppModuleBasic(cdc), + keeper: keeper, + accountKeeper: accountKeeper, + bankKeeper: bankKeeper, + } +} + +// RegisterServices registers a gRPC query service to respond to the module-specific gRPC queries +func (am AppModule) RegisterServices(cfg module.Configurator) { + types.RegisterMsgServer(cfg.MsgServer(), keeper.NewMsgServerImpl(am.keeper)) + types.RegisterQueryServer(cfg.QueryServer(), am.keeper) +} + +// RegisterInvariants registers the invariants of the module. If an invariant deviates from its predicted value, the InvariantRegistry triggers appropriate logic (most often the chain will be halted) +func (am AppModule) RegisterInvariants(_ sdk.InvariantRegistry) {} + +// InitGenesis performs the module's genesis initialization. It returns no validator updates. +func (am AppModule) InitGenesis(ctx sdk.Context, cdc codec.JSONCodec, gs json.RawMessage) []abci.ValidatorUpdate { + var genState types.GenesisState + // Initialize global index to index in genesis state + cdc.MustUnmarshalJSON(gs, &genState) + + InitGenesis(ctx, am.keeper, genState) + + return []abci.ValidatorUpdate{} +} + +// ExportGenesis returns the module's exported genesis state as raw JSON bytes. +func (am AppModule) ExportGenesis(ctx sdk.Context, cdc codec.JSONCodec) json.RawMessage { + genState := ExportGenesis(ctx, am.keeper) + return cdc.MustMarshalJSON(genState) +} + +// ConsensusVersion is a sequence number for state-breaking change of the module. It should be incremented on each consensus-breaking change introduced by the module. To avoid wrong/empty versions, the initial version should be set to 1 +func (AppModule) ConsensusVersion() uint64 { return 1 } + +// BeginBlock contains the logic that is automatically triggered at the beginning of each block +func (am AppModule) BeginBlock(ctx sdk.Context, _ abci.RequestBeginBlock) { + am.keeper.BeginBlock(ctx) +} + +// EndBlock contains the logic that is automatically triggered at the end of each block +func (am AppModule) EndBlock(_ sdk.Context, _ abci.RequestEndBlock) []abci.ValidatorUpdate { + return []abci.ValidatorUpdate{} +} diff --git a/x/ratesync/module_ibc.go b/x/ratesync/module_ibc.go new file mode 100644 index 000000000..de7566da5 --- /dev/null +++ b/x/ratesync/module_ibc.go @@ -0,0 +1,133 @@ +package ratesync + +import ( + sdk "github.com/cosmos/cosmos-sdk/types" + capabilitytypes "github.com/cosmos/cosmos-sdk/x/capability/types" + channeltypes "github.com/cosmos/ibc-go/v7/modules/core/04-channel/types" + porttypes "github.com/cosmos/ibc-go/v7/modules/core/05-port/types" + ibcexported "github.com/cosmos/ibc-go/v7/modules/core/exported" + + "github.com/persistenceOne/pstake-native/v2/x/ratesync/keeper" +) + +var _ porttypes.IBCModule = &IBCModule{} + +// IBCModule implements the ICS26 callbacks for the fee middleware given the +// fee keeper and the underlying application. +type IBCModule struct { + appStack porttypes.IBCModule + keeper keeper.Keeper +} + +func NewIBCModule(appStack porttypes.IBCModule, keeper keeper.Keeper) IBCModule { + return IBCModule{ + appStack: appStack, + keeper: keeper, + } +} + +func (m IBCModule) OnChanOpenInit( + ctx sdk.Context, + order channeltypes.Order, + connectionHops []string, + portID string, + channelID string, + channelCap *capabilitytypes.Capability, + counterparty channeltypes.Counterparty, + version string, +) (string, error) { + return m.appStack.OnChanOpenInit( + ctx, + order, + connectionHops, + portID, + channelID, + channelCap, + counterparty, + version, + ) +} + +func (m IBCModule) OnChanOpenAck( + ctx sdk.Context, + portID string, + channelID string, + counterpartyChannelID string, + counterpartyVersion string, +) error { + err := m.keeper.OnChanOpenAck( + ctx, + portID, + channelID, + counterpartyChannelID, + counterpartyVersion, + ) + if err != nil { + return err + } + return m.appStack.OnChanOpenAck(ctx, portID, channelID, counterpartyChannelID, counterpartyVersion) + +} + +func (m IBCModule) OnAcknowledgementPacket( + ctx sdk.Context, + packet channeltypes.Packet, + acknowledgement []byte, + relayer sdk.AccAddress, +) error { + err := m.keeper.OnAcknowledgementPacket( + ctx, + packet, + acknowledgement, + relayer, + ) + if err != nil { + return err + } + return m.appStack.OnAcknowledgementPacket(ctx, packet, acknowledgement, relayer) +} + +func (m IBCModule) OnTimeoutPacket( + ctx sdk.Context, + packet channeltypes.Packet, + relayer sdk.AccAddress, +) error { + err := m.keeper.OnTimeoutPacket( + ctx, + packet, + relayer, + ) + if err != nil { + return err + } + return m.appStack.OnTimeoutPacket(ctx, packet, relayer) +} + +func (m IBCModule) OnChanOpenTry( + ctx sdk.Context, + order channeltypes.Order, + connectionHops []string, + portID string, + channelID string, + channelCap *capabilitytypes.Capability, + counterparty channeltypes.Counterparty, + counterpartyVersion string, +) (version string, err error) { + return m.appStack.OnChanOpenTry(ctx, order, connectionHops, portID, channelID, channelCap, counterparty, counterpartyVersion) +} + +func (m IBCModule) OnChanOpenConfirm(ctx sdk.Context, portID, channelID string) error { + return m.appStack.OnChanOpenConfirm(ctx, portID, channelID) +} + +func (m IBCModule) OnChanCloseInit(ctx sdk.Context, portID, channelID string) error { + return m.appStack.OnChanCloseInit(ctx, portID, channelID) +} + +func (m IBCModule) OnChanCloseConfirm(ctx sdk.Context, portID, channelID string) error { + return m.appStack.OnChanCloseConfirm(ctx, portID, channelID) +} + +func (m IBCModule) OnRecvPacket(ctx sdk.Context, packet channeltypes.Packet, relayer sdk.AccAddress) ibcexported.Acknowledgement { + return m.appStack.OnRecvPacket(ctx, packet, relayer) +} diff --git a/x/ratesync/module_simulation.go b/x/ratesync/module_simulation.go new file mode 100644 index 000000000..57526ad33 --- /dev/null +++ b/x/ratesync/module_simulation.go @@ -0,0 +1,85 @@ +package ratesync + +import ( + "math/rand" + + "github.com/cosmos/cosmos-sdk/baseapp" + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/cosmos/cosmos-sdk/types/module" + simtypes "github.com/cosmos/cosmos-sdk/types/simulation" + "github.com/cosmos/cosmos-sdk/x/simulation" + ratesyncsimulation "github.com/persistenceOne/pstake-native/v2/x/ratesync/simulation" + "github.com/persistenceOne/pstake-native/v2/x/ratesync/types" +) + +// avoid unused import issue +var ( + _ = ratesyncsimulation.FindAccount + _ = simulation.MsgEntryKind + _ = baseapp.Paramspace + _ = rand.Rand{} +) + +const ( + opWeightMsgUpdateParams = "op_weight_msg_update_params" + // TODO: Determine the simulation weight value + defaultWeightMsgUpdateParams int = 100 + + // this line is used by starport scaffolding # simapp/module/const +) + +// GenerateGenesisState creates a randomized GenState of the module. +func (AppModule) GenerateGenesisState(simState *module.SimulationState) { + accs := make([]string, len(simState.Accounts)) + for i, acc := range simState.Accounts { + accs[i] = acc.Address.String() + } + ratesyncGenesis := types.GenesisState{ + Params: types.DefaultParams(), + // this line is used by starport scaffolding # simapp/module/genesisState + } + simState.GenState[types.ModuleName] = simState.Cdc.MustMarshalJSON(&ratesyncGenesis) +} + +// RegisterStoreDecoder registers a decoder. +func (am AppModule) RegisterStoreDecoder(_ sdk.StoreDecoderRegistry) {} + +// ProposalContents doesn't return any content functions for governance proposals. +func (AppModule) ProposalContents(_ module.SimulationState) []simtypes.WeightedProposalContent { + return nil +} + +// WeightedOperations returns the all the gov module operations with their respective weights. +func (am AppModule) WeightedOperations(simState module.SimulationState) []simtypes.WeightedOperation { + operations := make([]simtypes.WeightedOperation, 0) + + var weightMsgUpdateParams int + simState.AppParams.GetOrGenerate(simState.Cdc, opWeightMsgUpdateParams, &weightMsgUpdateParams, nil, + func(_ *rand.Rand) { + weightMsgUpdateParams = defaultWeightMsgUpdateParams + }, + ) + operations = append(operations, simulation.NewWeightedOperation( + weightMsgUpdateParams, + ratesyncsimulation.SimulateMsgUpdateParams(am.accountKeeper, am.bankKeeper, am.keeper), + )) + + // this line is used by starport scaffolding # simapp/module/operation + + return operations +} + +// ProposalMsgs returns msgs used for governance proposals for simulations. +func (am AppModule) ProposalMsgs(simState module.SimulationState) []simtypes.WeightedProposalMsg { + return []simtypes.WeightedProposalMsg{ + simulation.NewWeightedProposalMsg( + opWeightMsgUpdateParams, + defaultWeightMsgUpdateParams, + func(r *rand.Rand, ctx sdk.Context, accs []simtypes.Account) sdk.Msg { + ratesyncsimulation.SimulateMsgUpdateParams(am.accountKeeper, am.bankKeeper, am.keeper) + return nil + }, + ), + // this line is used by starport scaffolding # simapp/module/OpMsg + } +} diff --git a/x/ratesync/simulation/helpers.go b/x/ratesync/simulation/helpers.go new file mode 100644 index 000000000..92c437c0d --- /dev/null +++ b/x/ratesync/simulation/helpers.go @@ -0,0 +1,15 @@ +package simulation + +import ( + sdk "github.com/cosmos/cosmos-sdk/types" + simtypes "github.com/cosmos/cosmos-sdk/types/simulation" +) + +// FindAccount find a specific address from an account list +func FindAccount(accs []simtypes.Account, address string) (simtypes.Account, bool) { + creator, err := sdk.AccAddressFromBech32(address) + if err != nil { + panic(err) + } + return simtypes.FindAccount(accs, creator) +} diff --git a/x/ratesync/simulation/msg_update_params.go b/x/ratesync/simulation/msg_update_params.go new file mode 100644 index 000000000..e7e3e6068 --- /dev/null +++ b/x/ratesync/simulation/msg_update_params.go @@ -0,0 +1,29 @@ +package simulation + +import ( + "math/rand" + + "github.com/cosmos/cosmos-sdk/baseapp" + sdk "github.com/cosmos/cosmos-sdk/types" + simtypes "github.com/cosmos/cosmos-sdk/types/simulation" + "github.com/persistenceOne/pstake-native/v2/x/ratesync/keeper" + "github.com/persistenceOne/pstake-native/v2/x/ratesync/types" +) + +func SimulateMsgUpdateParams( + ak types.AccountKeeper, + bk types.BankKeeper, + k keeper.Keeper, +) simtypes.Operation { + return func(r *rand.Rand, app *baseapp.BaseApp, ctx sdk.Context, accs []simtypes.Account, chainID string, + ) (simtypes.OperationMsg, []simtypes.FutureOperation, error) { + simAccount, _ := simtypes.RandomAcc(r, accs) + msg := &types.MsgUpdateParams{ + Authority: simAccount.Address.String(), + } + + // TODO: Handling the MsgUpdateParams simulation + + return simtypes.NoOpMsg(types.ModuleName, msg.Type(), "MsgUpdateParams simulation not implemented"), nil, nil + } +} diff --git a/x/ratesync/types/codec.go b/x/ratesync/types/codec.go new file mode 100644 index 000000000..a9a3f267d --- /dev/null +++ b/x/ratesync/types/codec.go @@ -0,0 +1,35 @@ +package types + +import ( + "github.com/cosmos/cosmos-sdk/codec" + cdctypes "github.com/cosmos/cosmos-sdk/codec/types" + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/cosmos/cosmos-sdk/types/msgservice" +) + +func RegisterCodec(cdc *codec.LegacyAmino) { + cdc.RegisterConcrete(&MsgUpdateParams{}, "pstake/ratesync/MsgUpdateParams", nil) + cdc.RegisterConcrete(&MsgCreateHostChain{}, "pstake/ratesync/MsgCreateHostChain", nil) + cdc.RegisterConcrete(&MsgUpdateHostChain{}, "pstake/ratesync/MsgUpdateHostChain", nil) + cdc.RegisterConcrete(&MsgDeleteHostChain{}, "pstake/ratesync/MsgDeleteHostChain", nil) + // this line is used by starport scaffolding # 2 +} + +func RegisterInterfaces(registry cdctypes.InterfaceRegistry) { + registry.RegisterImplementations((*sdk.Msg)(nil), + &MsgUpdateParams{}, + &MsgCreateHostChain{}, + &MsgUpdateHostChain{}, + &MsgDeleteHostChain{}, + ) + + // this line is used by starport scaffolding # 3 + + msgservice.RegisterMsgServiceDesc(registry, &_Msg_serviceDesc) + +} + +var ( + Amino = codec.NewLegacyAmino() + ModuleCdc = codec.NewProtoCodec(cdctypes.NewInterfaceRegistry()) +) diff --git a/x/ratesync/types/contract.pb.go b/x/ratesync/types/contract.pb.go new file mode 100644 index 000000000..e8ae3a805 --- /dev/null +++ b/x/ratesync/types/contract.pb.go @@ -0,0 +1,819 @@ +// Code generated by protoc-gen-gogo. DO NOT EDIT. +// source: pstake/ratesync/v1beta1/contract.proto + +package types + +import ( + fmt "fmt" + _ "github.com/cosmos/cosmos-proto" + github_com_cosmos_cosmos_sdk_types "github.com/cosmos/cosmos-sdk/types" + _ "github.com/cosmos/gogoproto/gogoproto" + proto "github.com/cosmos/gogoproto/proto" + _ "google.golang.org/protobuf/types/known/timestamppb" + io "io" + math "math" + math_bits "math/bits" +) + +// Reference imports to suppress errors if they are not otherwise used. +var _ = proto.Marshal +var _ = fmt.Errorf +var _ = math.Inf + +// This is a compile-time assertion to ensure that this generated file +// is compatible with the proto package it is being compiled against. +// A compilation error at this line likely means your copy of the +// proto package needs to be updated. +const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package + +// msg blob for instantiate contract. +type InstantiateLiquidStakeRateContract struct { + Admin string `protobuf:"bytes,1,opt,name=admin,proto3" json:"admin,omitempty"` +} + +func (m *InstantiateLiquidStakeRateContract) Reset() { *m = InstantiateLiquidStakeRateContract{} } +func (m *InstantiateLiquidStakeRateContract) String() string { return proto.CompactTextString(m) } +func (*InstantiateLiquidStakeRateContract) ProtoMessage() {} +func (*InstantiateLiquidStakeRateContract) Descriptor() ([]byte, []int) { + return fileDescriptor_11a849967ac18085, []int{0} +} +func (m *InstantiateLiquidStakeRateContract) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *InstantiateLiquidStakeRateContract) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_InstantiateLiquidStakeRateContract.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *InstantiateLiquidStakeRateContract) XXX_Merge(src proto.Message) { + xxx_messageInfo_InstantiateLiquidStakeRateContract.Merge(m, src) +} +func (m *InstantiateLiquidStakeRateContract) XXX_Size() int { + return m.Size() +} +func (m *InstantiateLiquidStakeRateContract) XXX_DiscardUnknown() { + xxx_messageInfo_InstantiateLiquidStakeRateContract.DiscardUnknown(m) +} + +var xxx_messageInfo_InstantiateLiquidStakeRateContract proto.InternalMessageInfo + +func (m *InstantiateLiquidStakeRateContract) GetAdmin() string { + if m != nil { + return m.Admin + } + return "" +} + +// wrapper for liquidstakerate as wasm msg should be marshalled as encodedMsg = { wasmMsg: { wasm MsgDetails } } +type ExecuteLiquidStakeRate struct { + LiquidStakeRate LiquidStakeRate `protobuf:"bytes,1,opt,name=liquid_stake_rate,json=liquidStakeRate,proto3" json:"liquid_stake_rate"` +} + +func (m *ExecuteLiquidStakeRate) Reset() { *m = ExecuteLiquidStakeRate{} } +func (m *ExecuteLiquidStakeRate) String() string { return proto.CompactTextString(m) } +func (*ExecuteLiquidStakeRate) ProtoMessage() {} +func (*ExecuteLiquidStakeRate) Descriptor() ([]byte, []int) { + return fileDescriptor_11a849967ac18085, []int{1} +} +func (m *ExecuteLiquidStakeRate) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *ExecuteLiquidStakeRate) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_ExecuteLiquidStakeRate.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *ExecuteLiquidStakeRate) XXX_Merge(src proto.Message) { + xxx_messageInfo_ExecuteLiquidStakeRate.Merge(m, src) +} +func (m *ExecuteLiquidStakeRate) XXX_Size() int { + return m.Size() +} +func (m *ExecuteLiquidStakeRate) XXX_DiscardUnknown() { + xxx_messageInfo_ExecuteLiquidStakeRate.DiscardUnknown(m) +} + +var xxx_messageInfo_ExecuteLiquidStakeRate proto.InternalMessageInfo + +func (m *ExecuteLiquidStakeRate) GetLiquidStakeRate() LiquidStakeRate { + if m != nil { + return m.LiquidStakeRate + } + return LiquidStakeRate{} +} + +// msg blob for execute contract. +type LiquidStakeRate struct { + DefaultBondDenom string `protobuf:"bytes,1,opt,name=default_bond_denom,json=defaultBondDenom,proto3" json:"default_bond_denom,omitempty"` + StkDenom string `protobuf:"bytes,2,opt,name=stk_denom,json=stkDenom,proto3" json:"stk_denom,omitempty"` + // cvalue = default_bond_denom_price/stk_denom_price + // cvalue = stk_denom_supply/default_bond_denom_supply + CValue github_com_cosmos_cosmos_sdk_types.Dec `protobuf:"bytes,3,opt,name=c_value,json=cValue,proto3,customtype=github.com/cosmos/cosmos-sdk/types.Dec" json:"c_value"` + ControllerChainTime int64 `protobuf:"varint,4,opt,name=controller_chain_time,json=controllerChainTime,proto3" json:"controller_chain_time,omitempty"` +} + +func (m *LiquidStakeRate) Reset() { *m = LiquidStakeRate{} } +func (m *LiquidStakeRate) String() string { return proto.CompactTextString(m) } +func (*LiquidStakeRate) ProtoMessage() {} +func (*LiquidStakeRate) Descriptor() ([]byte, []int) { + return fileDescriptor_11a849967ac18085, []int{2} +} +func (m *LiquidStakeRate) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *LiquidStakeRate) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_LiquidStakeRate.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *LiquidStakeRate) XXX_Merge(src proto.Message) { + xxx_messageInfo_LiquidStakeRate.Merge(m, src) +} +func (m *LiquidStakeRate) XXX_Size() int { + return m.Size() +} +func (m *LiquidStakeRate) XXX_DiscardUnknown() { + xxx_messageInfo_LiquidStakeRate.DiscardUnknown(m) +} + +var xxx_messageInfo_LiquidStakeRate proto.InternalMessageInfo + +func (m *LiquidStakeRate) GetDefaultBondDenom() string { + if m != nil { + return m.DefaultBondDenom + } + return "" +} + +func (m *LiquidStakeRate) GetStkDenom() string { + if m != nil { + return m.StkDenom + } + return "" +} + +func (m *LiquidStakeRate) GetControllerChainTime() int64 { + if m != nil { + return m.ControllerChainTime + } + return 0 +} + +func init() { + proto.RegisterType((*InstantiateLiquidStakeRateContract)(nil), "pstake.ratesync.v1beta1.InstantiateLiquidStakeRateContract") + proto.RegisterType((*ExecuteLiquidStakeRate)(nil), "pstake.ratesync.v1beta1.ExecuteLiquidStakeRate") + proto.RegisterType((*LiquidStakeRate)(nil), "pstake.ratesync.v1beta1.LiquidStakeRate") +} + +func init() { + proto.RegisterFile("pstake/ratesync/v1beta1/contract.proto", fileDescriptor_11a849967ac18085) +} + +var fileDescriptor_11a849967ac18085 = []byte{ + // 452 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x74, 0x92, 0xc1, 0x6e, 0xd4, 0x30, + 0x10, 0x86, 0x37, 0xb4, 0x14, 0x6a, 0x0e, 0x85, 0x50, 0x60, 0x29, 0x52, 0xb6, 0xda, 0x43, 0xb5, + 0x07, 0x36, 0x56, 0x97, 0x23, 0x5c, 0xd8, 0x2e, 0x07, 0x24, 0x24, 0xa4, 0xb4, 0xe5, 0xd0, 0x4b, + 0xe4, 0xd8, 0xd3, 0xd4, 0xda, 0xc4, 0x0e, 0xf1, 0x24, 0x6a, 0xdf, 0x82, 0x87, 0xe9, 0x43, 0xf4, + 0x58, 0xf5, 0x84, 0x38, 0x54, 0x68, 0xf7, 0xc0, 0x6b, 0xa0, 0xd8, 0x46, 0x85, 0xa2, 0x9e, 0x12, + 0xcf, 0xff, 0x69, 0x66, 0xfe, 0xdf, 0x26, 0x3b, 0x95, 0x41, 0x36, 0x07, 0x5a, 0x33, 0x04, 0x73, + 0xa6, 0x38, 0x6d, 0x77, 0x33, 0x40, 0xb6, 0x4b, 0xb9, 0x56, 0x58, 0x33, 0x8e, 0x71, 0x55, 0x6b, + 0xd4, 0xe1, 0x0b, 0xc7, 0xc5, 0x7f, 0xb8, 0xd8, 0x73, 0x5b, 0x9b, 0xb9, 0xce, 0xb5, 0x65, 0x68, + 0xf7, 0xe7, 0xf0, 0xad, 0x97, 0x5c, 0x9b, 0x52, 0x9b, 0xd4, 0x09, 0xee, 0xe0, 0xa5, 0x41, 0xae, + 0x75, 0x5e, 0x00, 0xb5, 0xa7, 0xac, 0x39, 0xa6, 0x28, 0x4b, 0x30, 0xc8, 0xca, 0xca, 0x01, 0xc3, + 0x03, 0x32, 0xfc, 0xa8, 0x0c, 0x32, 0x85, 0x92, 0x21, 0x7c, 0x92, 0x5f, 0x1b, 0x29, 0xf6, 0xbb, + 0xe1, 0x09, 0x43, 0xd8, 0xf3, 0x6b, 0x85, 0x31, 0xb9, 0xcf, 0x44, 0x29, 0x55, 0x3f, 0xd8, 0x0e, + 0x46, 0xeb, 0xd3, 0xfe, 0xd5, 0xf9, 0x78, 0xd3, 0xcf, 0x79, 0x2f, 0x44, 0x0d, 0xc6, 0xec, 0x63, + 0x2d, 0x55, 0x9e, 0x38, 0x6c, 0x88, 0xe4, 0xf9, 0x87, 0x53, 0xe0, 0xcd, 0x7f, 0x1d, 0xc3, 0x23, + 0xf2, 0xa4, 0xb0, 0xa5, 0xd4, 0x5a, 0x4c, 0x3b, 0x8b, 0xb6, 0xeb, 0xa3, 0xc9, 0x28, 0xbe, 0xc3, + 0x76, 0x7c, 0xab, 0xc9, 0x74, 0xf5, 0xe2, 0x7a, 0xd0, 0x4b, 0x36, 0x8a, 0x7f, 0xcb, 0xc3, 0x5f, + 0x01, 0xd9, 0xb8, 0x3d, 0xef, 0x35, 0x09, 0x05, 0x1c, 0xb3, 0xa6, 0xc0, 0x34, 0xd3, 0x4a, 0xa4, + 0x02, 0x94, 0x2e, 0x9d, 0x8d, 0xe4, 0xb1, 0x57, 0xa6, 0x5a, 0x89, 0x59, 0x57, 0x0f, 0x5f, 0x91, + 0x75, 0x83, 0x73, 0x0f, 0xdd, 0xb3, 0xd0, 0x43, 0x83, 0x73, 0x27, 0x1e, 0x92, 0x07, 0x3c, 0x6d, + 0x59, 0xd1, 0x40, 0x7f, 0xc5, 0xc6, 0xf0, 0xae, 0x5b, 0xe3, 0xc7, 0xf5, 0x60, 0x27, 0x97, 0x78, + 0xd2, 0x64, 0x31, 0xd7, 0xa5, 0x4f, 0xdf, 0x7f, 0xc6, 0x46, 0xcc, 0x29, 0x9e, 0x55, 0x60, 0xe2, + 0x19, 0xf0, 0xab, 0xf3, 0x31, 0xf1, 0xa1, 0xcd, 0x80, 0x27, 0x6b, 0xfc, 0x4b, 0xd7, 0x2b, 0x9c, + 0x90, 0x67, 0xf6, 0xfa, 0x75, 0x51, 0x40, 0x9d, 0xf2, 0x13, 0x26, 0x55, 0xda, 0xdd, 0x52, 0x7f, + 0x75, 0x3b, 0x18, 0xad, 0x24, 0x4f, 0x6f, 0xc4, 0xbd, 0x4e, 0x3b, 0x90, 0x25, 0x4c, 0x0f, 0x2f, + 0x16, 0x51, 0x70, 0xb9, 0x88, 0x82, 0x9f, 0x8b, 0x28, 0xf8, 0xb6, 0x8c, 0x7a, 0x97, 0xcb, 0xa8, + 0xf7, 0x7d, 0x19, 0xf5, 0x8e, 0xde, 0xfe, 0xb5, 0x4b, 0x05, 0xb5, 0x91, 0x06, 0x41, 0x71, 0xf8, + 0xac, 0x80, 0xba, 0x74, 0xc7, 0x8a, 0xa1, 0x6c, 0x81, 0xb6, 0x13, 0x7a, 0x7a, 0xf3, 0x10, 0xed, + 0x92, 0xd9, 0x9a, 0x7d, 0x13, 0x6f, 0x7e, 0x07, 0x00, 0x00, 0xff, 0xff, 0x1f, 0x3b, 0x03, 0x81, + 0xa8, 0x02, 0x00, 0x00, +} + +func (m *InstantiateLiquidStakeRateContract) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *InstantiateLiquidStakeRateContract) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *InstantiateLiquidStakeRateContract) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if len(m.Admin) > 0 { + i -= len(m.Admin) + copy(dAtA[i:], m.Admin) + i = encodeVarintContract(dAtA, i, uint64(len(m.Admin))) + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func (m *ExecuteLiquidStakeRate) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *ExecuteLiquidStakeRate) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *ExecuteLiquidStakeRate) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + { + size, err := m.LiquidStakeRate.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintContract(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0xa + return len(dAtA) - i, nil +} + +func (m *LiquidStakeRate) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *LiquidStakeRate) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *LiquidStakeRate) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if m.ControllerChainTime != 0 { + i = encodeVarintContract(dAtA, i, uint64(m.ControllerChainTime)) + i-- + dAtA[i] = 0x20 + } + { + size := m.CValue.Size() + i -= size + if _, err := m.CValue.MarshalTo(dAtA[i:]); err != nil { + return 0, err + } + i = encodeVarintContract(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x1a + if len(m.StkDenom) > 0 { + i -= len(m.StkDenom) + copy(dAtA[i:], m.StkDenom) + i = encodeVarintContract(dAtA, i, uint64(len(m.StkDenom))) + i-- + dAtA[i] = 0x12 + } + if len(m.DefaultBondDenom) > 0 { + i -= len(m.DefaultBondDenom) + copy(dAtA[i:], m.DefaultBondDenom) + i = encodeVarintContract(dAtA, i, uint64(len(m.DefaultBondDenom))) + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func encodeVarintContract(dAtA []byte, offset int, v uint64) int { + offset -= sovContract(v) + base := offset + for v >= 1<<7 { + dAtA[offset] = uint8(v&0x7f | 0x80) + v >>= 7 + offset++ + } + dAtA[offset] = uint8(v) + return base +} +func (m *InstantiateLiquidStakeRateContract) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.Admin) + if l > 0 { + n += 1 + l + sovContract(uint64(l)) + } + return n +} + +func (m *ExecuteLiquidStakeRate) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = m.LiquidStakeRate.Size() + n += 1 + l + sovContract(uint64(l)) + return n +} + +func (m *LiquidStakeRate) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.DefaultBondDenom) + if l > 0 { + n += 1 + l + sovContract(uint64(l)) + } + l = len(m.StkDenom) + if l > 0 { + n += 1 + l + sovContract(uint64(l)) + } + l = m.CValue.Size() + n += 1 + l + sovContract(uint64(l)) + if m.ControllerChainTime != 0 { + n += 1 + sovContract(uint64(m.ControllerChainTime)) + } + return n +} + +func sovContract(x uint64) (n int) { + return (math_bits.Len64(x|1) + 6) / 7 +} +func sozContract(x uint64) (n int) { + return sovContract(uint64((x << 1) ^ uint64((int64(x) >> 63)))) +} +func (m *InstantiateLiquidStakeRateContract) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowContract + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: InstantiateLiquidStakeRateContract: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: InstantiateLiquidStakeRateContract: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Admin", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowContract + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthContract + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthContract + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Admin = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipContract(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthContract + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *ExecuteLiquidStakeRate) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowContract + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: ExecuteLiquidStakeRate: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: ExecuteLiquidStakeRate: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field LiquidStakeRate", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowContract + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthContract + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthContract + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if err := m.LiquidStakeRate.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipContract(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthContract + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *LiquidStakeRate) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowContract + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: LiquidStakeRate: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: LiquidStakeRate: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field DefaultBondDenom", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowContract + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthContract + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthContract + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.DefaultBondDenom = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field StkDenom", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowContract + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthContract + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthContract + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.StkDenom = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 3: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field CValue", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowContract + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthContract + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthContract + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if err := m.CValue.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 4: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field ControllerChainTime", wireType) + } + m.ControllerChainTime = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowContract + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.ControllerChainTime |= int64(b&0x7F) << shift + if b < 0x80 { + break + } + } + default: + iNdEx = preIndex + skippy, err := skipContract(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthContract + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func skipContract(dAtA []byte) (n int, err error) { + l := len(dAtA) + iNdEx := 0 + depth := 0 + for iNdEx < l { + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowContract + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= (uint64(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + wireType := int(wire & 0x7) + switch wireType { + case 0: + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowContract + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + iNdEx++ + if dAtA[iNdEx-1] < 0x80 { + break + } + } + case 1: + iNdEx += 8 + case 2: + var length int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowContract + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + length |= (int(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + if length < 0 { + return 0, ErrInvalidLengthContract + } + iNdEx += length + case 3: + depth++ + case 4: + if depth == 0 { + return 0, ErrUnexpectedEndOfGroupContract + } + depth-- + case 5: + iNdEx += 4 + default: + return 0, fmt.Errorf("proto: illegal wireType %d", wireType) + } + if iNdEx < 0 { + return 0, ErrInvalidLengthContract + } + if depth == 0 { + return iNdEx, nil + } + } + return 0, io.ErrUnexpectedEOF +} + +var ( + ErrInvalidLengthContract = fmt.Errorf("proto: negative length found during unmarshaling") + ErrIntOverflowContract = fmt.Errorf("proto: integer overflow") + ErrUnexpectedEndOfGroupContract = fmt.Errorf("proto: unexpected end of group") +) diff --git a/x/ratesync/types/errors.go b/x/ratesync/types/errors.go new file mode 100644 index 000000000..3eb0ed2cd --- /dev/null +++ b/x/ratesync/types/errors.go @@ -0,0 +1,15 @@ +package types + +// DONTCOVER + +import ( + errorsmod "cosmossdk.io/errors" +) + +// x/ratesync module sentinel errors +var ( + ErrRegisterFailed = errorsmod.Register(ModuleName, 3001, "host chain register failed") + ErrInvalid = errorsmod.Register(ModuleName, 3002, "Invalid data") + ErrICATxFailure = errorsmod.Register(ModuleName, 3003, "ica transaction failed") + ErrInvalidResponses = errorsmod.Register(ModuleName, 3004, "not enough message responses") +) diff --git a/x/ratesync/types/events.go b/x/ratesync/types/events.go new file mode 100644 index 000000000..6600e68d2 --- /dev/null +++ b/x/ratesync/types/events.go @@ -0,0 +1,34 @@ +package types + +const ( + EventTypePacket = "ics27_packet" + EventTypeTimeout = "timeout" + EventTypeUpdateParams = "update_params" + EventTypeCreateHostChain = "create_host_chain" + EventTypeUpdateHostChain = "update_host_chain" + EventTypeDeleteHostChain = "delete_host_chain" + EventTypeCValueUpdate = "c_value_update" + EventTypeUnsuccessfulInstantiateContract = "unsuccessful_instantiate_contract" + EventTypeUnsuccessfulExecuteContract = "unsuccessful_execute_contract" + EventICAChannelCreated = "ica_channel_created" + + AttributeID = "id" + AttributeChainID = "chain_id" + AttributeConnectionID = "connection_id" + AttributeUpdates = "connection_id" + AttributeNewCValue = "new_c_value" + AttributeOldCValue = "old_c_value" + AttributeEpoch = "epoch_number" + AttributeKeyAuthority = "authority" + AttributeKeyUpdatedParams = "updated_params" + AttributeKeyAck = "acknowledgement" + AttributeKeyAckSuccess = "success" + AttributeKeyAckError = "error" + AttributeICAMessages = "ica_messages" + AttributeICAPortOwner = "ica_port_owner" + AttributeICAChannelID = "ica_channel_id" + AttributeICAAddress = "ica_address" + AttributeSender = "msg_sender" + + AttributeValueCategory = ModuleName +) diff --git a/x/ratesync/types/expected_keepers.go b/x/ratesync/types/expected_keepers.go new file mode 100644 index 000000000..5bc557b3e --- /dev/null +++ b/x/ratesync/types/expected_keepers.go @@ -0,0 +1,45 @@ +package types + +import ( + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/cosmos/cosmos-sdk/x/auth/types" + persistencetypes "github.com/persistenceOne/persistence-sdk/v2/x/epochs/types" + liquidstaketypes "github.com/persistenceOne/pstake-native/v2/x/liquidstake/types" + liquidstakeibctypes "github.com/persistenceOne/pstake-native/v2/x/liquidstakeibc/types" +) + +type AccountKeeper interface { + GetAccount(ctx sdk.Context, addr sdk.AccAddress) types.AccountI + GetModuleAccount(ctx sdk.Context, moduleName string) types.ModuleAccountI +} + +type BankKeeper interface { + SpendableCoins(ctx sdk.Context, addr sdk.AccAddress) sdk.Coins + MintCoins(ctx sdk.Context, name string, amt sdk.Coins) error + BurnCoins(ctx sdk.Context, name string, amt sdk.Coins) error + GetSupply(ctx sdk.Context, denom string) sdk.Coin + GetBalance(ctx sdk.Context, addr sdk.AccAddress, denom string) sdk.Coin + SendCoins(ctx sdk.Context, fromAddr sdk.AccAddress, toAddr sdk.AccAddress, amt sdk.Coins) error + SendCoinsFromAccountToModule(ctx sdk.Context, senderAddr sdk.AccAddress, recipientModule string, amt sdk.Coins) error + SendCoinsFromModuleToAccount(ctx sdk.Context, senderModule string, recipientAddr sdk.AccAddress, amt sdk.Coins) error +} + +type ICAControllerKeeper interface { + RegisterInterchainAccount(ctx sdk.Context, connectionID, owner string, version string) error + GetInterchainAccountAddress(ctx sdk.Context, connectionID, portID string) (string, bool) + GetOpenActiveChannel(ctx sdk.Context, connectionID, portID string) (string, bool) +} + +type EpochsKeeper interface { + GetEpochInfo(ctx sdk.Context, identifier string) persistencetypes.EpochInfo +} + +type LiquidStakeIBCKeeper interface { + GetHostChain(ctx sdk.Context, chainID string) (*liquidstakeibctypes.HostChain, bool) +} + +type LiquidStakeKeeper interface { + // add for stkxprt + GetNetAmountState(ctx sdk.Context) liquidstaketypes.NetAmountState + LiquidBondDenom(ctx sdk.Context) string +} diff --git a/x/ratesync/types/genesis.go b/x/ratesync/types/genesis.go new file mode 100644 index 000000000..b486e63d1 --- /dev/null +++ b/x/ratesync/types/genesis.go @@ -0,0 +1,34 @@ +package types + +import ( + "fmt" +) + +// DefaultIndex is the default global index +const DefaultIndex uint64 = 1 + +// DefaultGenesis returns the default genesis state +func DefaultGenesis() *GenesisState { + return &GenesisState{ + // this line is used by starport scaffolding # genesis/types/default + Params: DefaultParams(), + } +} + +// Validate performs basic genesis state validation returning an error upon any +// failure. +func (gs GenesisState) Validate() error { + // Check for duplicated index in chain + chainIndexMap := make(map[string]struct{}) + + for _, elem := range gs.HostChains { + index := string(HostChainKey(elem.ID)) + if _, ok := chainIndexMap[index]; ok { + return fmt.Errorf("duplicated index for chain") + } + chainIndexMap[index] = struct{}{} + } + // this line is used by starport scaffolding # genesis/types/validate + + return gs.Params.Validate() +} diff --git a/x/ratesync/types/genesis.pb.go b/x/ratesync/types/genesis.pb.go new file mode 100644 index 000000000..2862ef6fc --- /dev/null +++ b/x/ratesync/types/genesis.pb.go @@ -0,0 +1,389 @@ +// Code generated by protoc-gen-gogo. DO NOT EDIT. +// source: pstake/ratesync/v1beta1/genesis.proto + +package types + +import ( + fmt "fmt" + _ "github.com/cosmos/gogoproto/gogoproto" + proto "github.com/cosmos/gogoproto/proto" + io "io" + math "math" + math_bits "math/bits" +) + +// Reference imports to suppress errors if they are not otherwise used. +var _ = proto.Marshal +var _ = fmt.Errorf +var _ = math.Inf + +// This is a compile-time assertion to ensure that this generated file +// is compatible with the proto package it is being compiled against. +// A compilation error at this line likely means your copy of the +// proto package needs to be updated. +const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package + +// GenesisState defines the ratesync module's genesis state. +type GenesisState struct { + Params Params `protobuf:"bytes,1,opt,name=params,proto3" json:"params"` + HostChains []HostChain `protobuf:"bytes,2,rep,name=host_chains,json=hostChains,proto3" json:"host_chains"` +} + +func (m *GenesisState) Reset() { *m = GenesisState{} } +func (m *GenesisState) String() string { return proto.CompactTextString(m) } +func (*GenesisState) ProtoMessage() {} +func (*GenesisState) Descriptor() ([]byte, []int) { + return fileDescriptor_354a30a9d533e27f, []int{0} +} +func (m *GenesisState) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *GenesisState) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_GenesisState.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *GenesisState) XXX_Merge(src proto.Message) { + xxx_messageInfo_GenesisState.Merge(m, src) +} +func (m *GenesisState) XXX_Size() int { + return m.Size() +} +func (m *GenesisState) XXX_DiscardUnknown() { + xxx_messageInfo_GenesisState.DiscardUnknown(m) +} + +var xxx_messageInfo_GenesisState proto.InternalMessageInfo + +func (m *GenesisState) GetParams() Params { + if m != nil { + return m.Params + } + return Params{} +} + +func (m *GenesisState) GetHostChains() []HostChain { + if m != nil { + return m.HostChains + } + return nil +} + +func init() { + proto.RegisterType((*GenesisState)(nil), "pstake.ratesync.v1beta1.GenesisState") +} + +func init() { + proto.RegisterFile("pstake/ratesync/v1beta1/genesis.proto", fileDescriptor_354a30a9d533e27f) +} + +var fileDescriptor_354a30a9d533e27f = []byte{ + // 271 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x74, 0xd0, 0x31, 0x4b, 0xc3, 0x40, + 0x14, 0xc0, 0xf1, 0x9c, 0x4a, 0x87, 0xc4, 0x29, 0x08, 0x96, 0x0c, 0xd7, 0x52, 0x54, 0xba, 0x78, + 0x47, 0xe3, 0x28, 0x2e, 0x75, 0x50, 0x27, 0x45, 0x71, 0x71, 0x91, 0x4b, 0x78, 0x24, 0x41, 0x7a, + 0x77, 0xe4, 0x3d, 0x83, 0xfd, 0x16, 0x8e, 0x7e, 0xa4, 0x8e, 0x1d, 0x9d, 0x44, 0x92, 0x2f, 0x22, + 0xcd, 0xa5, 0x76, 0xca, 0x16, 0xc2, 0xef, 0xfe, 0xef, 0xdd, 0xf9, 0xa7, 0x16, 0x49, 0xbd, 0x81, + 0x2c, 0x15, 0x01, 0x2e, 0x75, 0x2a, 0xab, 0x59, 0x02, 0xa4, 0x66, 0x32, 0x03, 0x0d, 0x58, 0xa0, + 0xb0, 0xa5, 0x21, 0x13, 0x1e, 0x3b, 0x26, 0xb6, 0x4c, 0x74, 0x2c, 0x3a, 0xca, 0x4c, 0x66, 0x5a, + 0x23, 0x37, 0x5f, 0x8e, 0x47, 0x27, 0x7d, 0x55, 0xab, 0x4a, 0xb5, 0xe8, 0xa2, 0xd1, 0x59, 0x9f, + 0xfa, 0x9f, 0xd2, 0xba, 0xc9, 0x17, 0xf3, 0x0f, 0x6f, 0xdc, 0x3a, 0x4f, 0xa4, 0x08, 0xc2, 0x2b, + 0x7f, 0xe0, 0x42, 0x43, 0x36, 0x66, 0xd3, 0x20, 0x1e, 0x89, 0x9e, 0xf5, 0xc4, 0x43, 0xcb, 0xe6, + 0x07, 0xab, 0x9f, 0x91, 0xf7, 0xd8, 0x1d, 0x0a, 0xef, 0xfc, 0x20, 0x37, 0x48, 0xaf, 0x69, 0xae, + 0x0a, 0x8d, 0xc3, 0xbd, 0xf1, 0xfe, 0x34, 0x88, 0x27, 0xbd, 0x8d, 0x5b, 0x83, 0x74, 0xbd, 0xa1, + 0x5d, 0xc6, 0xcf, 0xb7, 0x3f, 0x70, 0xfe, 0xbc, 0xaa, 0x39, 0x5b, 0xd7, 0x9c, 0xfd, 0xd6, 0x9c, + 0x7d, 0x36, 0xdc, 0x5b, 0x37, 0xdc, 0xfb, 0x6e, 0xb8, 0xf7, 0x72, 0x99, 0x15, 0x94, 0xbf, 0x27, + 0x22, 0x35, 0x0b, 0x69, 0xa1, 0xc4, 0x02, 0x09, 0x74, 0x0a, 0xf7, 0x1a, 0xa4, 0x1b, 0x74, 0xae, + 0x15, 0x15, 0x15, 0xc8, 0x2a, 0x96, 0x1f, 0xbb, 0x27, 0xa0, 0xa5, 0x05, 0x4c, 0x06, 0xed, 0xc5, + 0x2f, 0xfe, 0x02, 0x00, 0x00, 0xff, 0xff, 0x50, 0x6a, 0xa2, 0xa9, 0x9e, 0x01, 0x00, 0x00, +} + +func (m *GenesisState) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *GenesisState) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *GenesisState) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if len(m.HostChains) > 0 { + for iNdEx := len(m.HostChains) - 1; iNdEx >= 0; iNdEx-- { + { + size, err := m.HostChains[iNdEx].MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintGenesis(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x12 + } + } + { + size, err := m.Params.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintGenesis(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0xa + return len(dAtA) - i, nil +} + +func encodeVarintGenesis(dAtA []byte, offset int, v uint64) int { + offset -= sovGenesis(v) + base := offset + for v >= 1<<7 { + dAtA[offset] = uint8(v&0x7f | 0x80) + v >>= 7 + offset++ + } + dAtA[offset] = uint8(v) + return base +} +func (m *GenesisState) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = m.Params.Size() + n += 1 + l + sovGenesis(uint64(l)) + if len(m.HostChains) > 0 { + for _, e := range m.HostChains { + l = e.Size() + n += 1 + l + sovGenesis(uint64(l)) + } + } + return n +} + +func sovGenesis(x uint64) (n int) { + return (math_bits.Len64(x|1) + 6) / 7 +} +func sozGenesis(x uint64) (n int) { + return sovGenesis(uint64((x << 1) ^ uint64((int64(x) >> 63)))) +} +func (m *GenesisState) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowGenesis + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: GenesisState: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: GenesisState: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Params", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowGenesis + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthGenesis + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthGenesis + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if err := m.Params.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field HostChains", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowGenesis + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthGenesis + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthGenesis + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.HostChains = append(m.HostChains, HostChain{}) + if err := m.HostChains[len(m.HostChains)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipGenesis(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthGenesis + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func skipGenesis(dAtA []byte) (n int, err error) { + l := len(dAtA) + iNdEx := 0 + depth := 0 + for iNdEx < l { + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowGenesis + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= (uint64(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + wireType := int(wire & 0x7) + switch wireType { + case 0: + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowGenesis + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + iNdEx++ + if dAtA[iNdEx-1] < 0x80 { + break + } + } + case 1: + iNdEx += 8 + case 2: + var length int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowGenesis + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + length |= (int(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + if length < 0 { + return 0, ErrInvalidLengthGenesis + } + iNdEx += length + case 3: + depth++ + case 4: + if depth == 0 { + return 0, ErrUnexpectedEndOfGroupGenesis + } + depth-- + case 5: + iNdEx += 4 + default: + return 0, fmt.Errorf("proto: illegal wireType %d", wireType) + } + if iNdEx < 0 { + return 0, ErrInvalidLengthGenesis + } + if depth == 0 { + return iNdEx, nil + } + } + return 0, io.ErrUnexpectedEOF +} + +var ( + ErrInvalidLengthGenesis = fmt.Errorf("proto: negative length found during unmarshaling") + ErrIntOverflowGenesis = fmt.Errorf("proto: integer overflow") + ErrUnexpectedEndOfGroupGenesis = fmt.Errorf("proto: unexpected end of group") +) diff --git a/x/ratesync/types/genesis_test.go b/x/ratesync/types/genesis_test.go new file mode 100644 index 000000000..7e8c7888d --- /dev/null +++ b/x/ratesync/types/genesis_test.go @@ -0,0 +1,64 @@ +package types_test + +import ( + "testing" + + "github.com/persistenceOne/pstake-native/v2/x/ratesync/types" + "github.com/stretchr/testify/require" +) + +func TestGenesisState_Validate(t *testing.T) { + tests := []struct { + desc string + genState *types.GenesisState + valid bool + }{ + { + desc: "default is valid", + genState: types.DefaultGenesis(), + valid: true, + }, + { + desc: "valid genesis state", + genState: &types.GenesisState{ + Params: types.DefaultParams(), + HostChains: []types.HostChain{ + { + ID: 0, + }, + { + ID: 1, + }, + }, + // this line is used by starport scaffolding # types/genesis/validField + }, + valid: true, + }, + { + desc: "duplicated chain", + genState: &types.GenesisState{ + Params: types.DefaultParams(), + HostChains: []types.HostChain{ + { + ID: 0, + }, + { + ID: 0, + }, + }, + }, + valid: false, + }, + // this line is used by starport scaffolding # types/genesis/testcase + } + for _, tc := range tests { + t.Run(tc.desc, func(t *testing.T) { + err := tc.genState.Validate() + if tc.valid { + require.NoError(t, err) + } else { + require.Error(t, err) + } + }) + } +} diff --git a/x/ratesync/types/keys.go b/x/ratesync/types/keys.go new file mode 100644 index 000000000..97acd54c2 --- /dev/null +++ b/x/ratesync/types/keys.go @@ -0,0 +1,41 @@ +package types + +import ( + "encoding/binary" + "time" +) + +const ( + // ModuleName defines the module name + ModuleName = "ratesync" + + // StoreKey defines the primary module store key + StoreKey = ModuleName + + // RouterKey defines the module's message routing key + RouterKey = ModuleName + + // MemStoreKey defines the in-memory store key + MemStoreKey = "mem_ratesync" + + LiquidStakeAllowAllDenoms = "*" + LiquidStakeEpoch = "hour" + DefaultPortOwnerPrefix = "pstake_ratesync_" + + ICATimeoutTimestamp = 60 * time.Minute +) + +var ( + HostChainIDKeyPrefix = []byte{0x01} + HostChainKeyPrefix = []byte{0x02} + ParamsKeyPrefix = []byte{0x00} +) + +// HostChainKey returns the store key to retrieve a Chain from the index fields +func HostChainKey( + id uint64, +) []byte { + bz := make([]byte, 8) + binary.BigEndian.PutUint64(bz, id) + return bz +} diff --git a/x/ratesync/types/msgs.go b/x/ratesync/types/msgs.go new file mode 100644 index 000000000..751ad329e --- /dev/null +++ b/x/ratesync/types/msgs.go @@ -0,0 +1,206 @@ +package types + +import ( + "cosmossdk.io/errors" + sdk "github.com/cosmos/cosmos-sdk/types" + sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" + liquidstakeibctypes "github.com/persistenceOne/pstake-native/v2/x/liquidstakeibc/types" +) + +const TypeMsgUpdateParams = "msg_update_params" +const ( + TypeMsgCreateHostChain = "create_host_chain" + TypeMsgUpdateHostChain = "update_host_chain" + TypeMsgDeleteHostChain = "delete_host_chain" +) + +var _ sdk.Msg = &MsgUpdateParams{} + +func NewMsgUpdateParams(authority string, params Params) *MsgUpdateParams { + return &MsgUpdateParams{ + Authority: authority, + Params: params, + } +} + +func (msg *MsgUpdateParams) Route() string { + return RouterKey +} + +func (msg *MsgUpdateParams) Type() string { + return TypeMsgUpdateParams +} + +func (msg *MsgUpdateParams) GetSigners() []sdk.AccAddress { + authority, err := sdk.AccAddressFromBech32(msg.Authority) + if err != nil { + panic(err) + } + return []sdk.AccAddress{authority} +} + +func (msg *MsgUpdateParams) GetSignBytes() []byte { + bz := ModuleCdc.MustMarshalJSON(msg) + return sdk.MustSortJSON(bz) +} + +func (msg *MsgUpdateParams) ValidateBasic() error { + _, err := sdk.AccAddressFromBech32(msg.Authority) + if err != nil { + return errors.Wrapf(sdkerrors.ErrInvalidAddress, "invalid authority address (%s)", err) + } + return msg.Params.Validate() +} + +var _ sdk.Msg = &MsgCreateHostChain{} + +func NewMsgCreateHostChain( + authority string, + hc HostChain, + +) *MsgCreateHostChain { + return &MsgCreateHostChain{ + Authority: authority, + HostChain: hc, + } +} + +func (msg *MsgCreateHostChain) Route() string { + return RouterKey +} + +func (msg *MsgCreateHostChain) Type() string { + return TypeMsgCreateHostChain +} + +func (msg *MsgCreateHostChain) GetSigners() []sdk.AccAddress { + creator, err := sdk.AccAddressFromBech32(msg.Authority) + if err != nil { + panic(err) + } + return []sdk.AccAddress{creator} +} + +func (msg *MsgCreateHostChain) GetSignBytes() []byte { + bz := ModuleCdc.MustMarshalJSON(msg) + return sdk.MustSortJSON(bz) +} + +func (msg *MsgCreateHostChain) ValidateBasic() error { + _, err := sdk.AccAddressFromBech32(msg.Authority) + if err != nil { + return errors.Wrapf(sdkerrors.ErrInvalidAddress, "invalid creator address (%s)", err) + } + err = msg.HostChain.ValidateBasic() + if err != nil { + return err + } + + if msg.HostChain.ID != 0 { + return errors.Wrapf(sdkerrors.ErrInvalidRequest, "hostchain ID for create msg should be 0") + } + if msg.HostChain.ICAAccount.Owner != "" { + return errors.Wrapf(sdkerrors.ErrInvalidRequest, "owner should not be specified as app uses default") + } + if msg.HostChain.ICAAccount.ChannelState != liquidstakeibctypes.ICAAccount_ICA_CHANNEL_CREATING { + return errors.Wrapf(sdkerrors.ErrInvalidRequest, "channel state should be creating") + } + return nil +} + +var _ sdk.Msg = &MsgUpdateHostChain{} + +func NewMsgUpdateHostChain( + creator string, + hc HostChain, + +) *MsgUpdateHostChain { + return &MsgUpdateHostChain{ + Authority: creator, + HostChain: hc, + } +} + +func (msg *MsgUpdateHostChain) Route() string { + return RouterKey +} + +func (msg *MsgUpdateHostChain) Type() string { + return TypeMsgUpdateHostChain +} + +func (msg *MsgUpdateHostChain) GetSigners() []sdk.AccAddress { + creator, err := sdk.AccAddressFromBech32(msg.Authority) + if err != nil { + panic(err) + } + return []sdk.AccAddress{creator} +} + +func (msg *MsgUpdateHostChain) GetSignBytes() []byte { + bz := ModuleCdc.MustMarshalJSON(msg) + return sdk.MustSortJSON(bz) +} + +func (msg *MsgUpdateHostChain) ValidateBasic() error { + _, err := sdk.AccAddressFromBech32(msg.Authority) + if err != nil { + return errors.Wrapf(sdkerrors.ErrInvalidAddress, "invalid creator address (%s)", err) + } + + err = msg.HostChain.ValidateBasic() + if err != nil { + return err + } + + if msg.HostChain.ID == 0 { + return errors.Wrapf(sdkerrors.ErrInvalidRequest, "hostchain ID for update msg should not be 0") + } + + return nil +} + +var _ sdk.Msg = &MsgDeleteHostChain{} + +func NewMsgDeleteHostChain( + creator string, + id uint64, + +) *MsgDeleteHostChain { + return &MsgDeleteHostChain{ + Authority: creator, + ID: id, + } +} +func (msg *MsgDeleteHostChain) Route() string { + return RouterKey +} + +func (msg *MsgDeleteHostChain) Type() string { + return TypeMsgDeleteHostChain +} + +func (msg *MsgDeleteHostChain) GetSigners() []sdk.AccAddress { + creator, err := sdk.AccAddressFromBech32(msg.Authority) + if err != nil { + panic(err) + } + return []sdk.AccAddress{creator} +} + +func (msg *MsgDeleteHostChain) GetSignBytes() []byte { + bz := ModuleCdc.MustMarshalJSON(msg) + return sdk.MustSortJSON(bz) +} + +func (msg *MsgDeleteHostChain) ValidateBasic() error { + _, err := sdk.AccAddressFromBech32(msg.Authority) + if err != nil { + return errors.Wrapf(sdkerrors.ErrInvalidAddress, "invalid creator address (%s)", err) + } + if msg.ID == 0 { + return errors.Wrapf(sdkerrors.ErrInvalidRequest, "hostchain ID for delete msg should not be 0") + } + + return nil +} diff --git a/x/ratesync/types/msgs_test.go b/x/ratesync/types/msgs_test.go new file mode 100644 index 000000000..46868005e --- /dev/null +++ b/x/ratesync/types/msgs_test.go @@ -0,0 +1,189 @@ +package types + +import ( + sdk "github.com/cosmos/cosmos-sdk/types" + ibcexported "github.com/cosmos/ibc-go/v7/modules/core/exported" + "github.com/persistenceOne/pstake-native/v2/x/liquidstakeibc/types" + "testing" + + sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" + authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" + "github.com/stretchr/testify/require" +) + +var ValidHostChainInMsg = func(id uint64) HostChain { + return HostChain{ + ID: id, + ChainID: "test-1", + ConnectionID: ibcexported.LocalhostConnectionID, + ICAAccount: types.ICAAccount{ + Address: "", + Balance: sdk.Coin{}, + Owner: "", + ChannelState: 0, + }, + Features: Feature{ + LiquidStakeIBC: LiquidStake{ + FeatureType: 0, + CodeID: 0, + Instantiation: 0, + ContractAddress: "", + Denoms: []string{}, + Enabled: false, + }, + LiquidStake: LiquidStake{ + FeatureType: 1, + CodeID: 0, + Instantiation: 0, + ContractAddress: "", + Denoms: nil, + Enabled: false, + }}, + } +} + +func TestMsgUpdateParams_ValidateBasic(t *testing.T) { + tests := []struct { + name string + msg MsgUpdateParams + err error + }{ + { + name: "invalid address", + msg: MsgUpdateParams{ + Authority: "invalid_address", + }, + err: sdkerrors.ErrInvalidAddress, + }, { + name: "valid address", + msg: MsgUpdateParams{ + Authority: authtypes.NewModuleAddress("addr").String(), + Params: DefaultParams(), + }, + }, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + require.Equal(t, tt.msg.Type(), TypeMsgUpdateParams) + require.Equal(t, tt.msg.Route(), RouterKey) + err := tt.msg.ValidateBasic() + if tt.err != nil { + require.ErrorIs(t, err, tt.err) + return + } + require.NoError(t, err) + require.Equal(t, tt.msg.GetSigners()[0], sdk.MustAccAddressFromBech32(tt.msg.Authority)) + require.NotNil(t, tt.msg.GetSignBytes()) + }) + } +} + +func TestMsgCreateHostChain_ValidateBasic(t *testing.T) { + tests := []struct { + name string + msg MsgCreateHostChain + err error + }{ + { + name: "invalid address", + msg: MsgCreateHostChain{ + Authority: "invalid_address", + HostChain: ValidHostChainInMsg(0), + }, + err: sdkerrors.ErrInvalidAddress, + }, { + name: "valid address", + msg: MsgCreateHostChain{ + Authority: authtypes.NewModuleAddress("addr1").String(), + HostChain: ValidHostChainInMsg(0), + }, + }, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + require.Equal(t, tt.msg.Type(), TypeMsgCreateHostChain) + require.Equal(t, tt.msg.Route(), RouterKey) + err := tt.msg.ValidateBasic() + if tt.err != nil { + require.ErrorIs(t, err, tt.err) + return + } + require.NoError(t, err) + require.Equal(t, tt.msg.GetSigners()[0], sdk.MustAccAddressFromBech32(tt.msg.Authority)) + require.NotNil(t, tt.msg.GetSignBytes()) + }) + } +} + +func TestMsgUpdateHostChain_ValidateBasic(t *testing.T) { + tests := []struct { + name string + msg MsgUpdateHostChain + err error + }{ + { + name: "invalid address", + msg: MsgUpdateHostChain{ + Authority: "invalid_address", + HostChain: ValidHostChainInMsg(1), + }, + err: sdkerrors.ErrInvalidAddress, + }, { + name: "valid address", + msg: MsgUpdateHostChain{ + Authority: authtypes.NewModuleAddress("addr1").String(), + HostChain: ValidHostChainInMsg(1), + }, + }, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + require.Equal(t, tt.msg.Type(), TypeMsgUpdateHostChain) + require.Equal(t, tt.msg.Route(), RouterKey) + err := tt.msg.ValidateBasic() + if tt.err != nil { + require.ErrorIs(t, err, tt.err) + return + } + require.NoError(t, err) + require.Equal(t, tt.msg.GetSigners()[0], sdk.MustAccAddressFromBech32(tt.msg.Authority)) + require.NotNil(t, tt.msg.GetSignBytes()) + }) + } +} + +func TestMsgDeleteHostChain_ValidateBasic(t *testing.T) { + tests := []struct { + name string + msg MsgDeleteHostChain + err error + }{ + { + name: "invalid address", + msg: MsgDeleteHostChain{ + Authority: "invalid_address", + }, + err: sdkerrors.ErrInvalidAddress, + }, { + name: "valid address", + msg: MsgDeleteHostChain{ + Authority: authtypes.NewModuleAddress("addr1").String(), + ID: 1, + }, + }, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + require.Equal(t, tt.msg.Type(), TypeMsgDeleteHostChain) + require.Equal(t, tt.msg.Route(), RouterKey) + err := tt.msg.ValidateBasic() + if tt.err != nil { + require.ErrorIs(t, err, tt.err) + return + } + require.NoError(t, err) + require.Equal(t, tt.msg.GetSigners()[0], sdk.MustAccAddressFromBech32(tt.msg.Authority)) + require.NotNil(t, tt.msg.GetSignBytes()) + }) + } +} diff --git a/x/ratesync/types/params.go b/x/ratesync/types/params.go new file mode 100644 index 000000000..9d14b1ac4 --- /dev/null +++ b/x/ratesync/types/params.go @@ -0,0 +1,34 @@ +package types + +import ( + sdk "github.com/cosmos/cosmos-sdk/types" + authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" + govtypes "github.com/cosmos/cosmos-sdk/x/gov/types" + "gopkg.in/yaml.v2" +) + +var DefaultAdmin = authtypes.NewModuleAddress(govtypes.ModuleName) + +// NewParams creates a new Params instance +func NewParams(admin sdk.AccAddress) Params { + return Params{ + Admin: admin.String(), + } +} + +// DefaultParams returns a default set of parameters +func DefaultParams() Params { + return NewParams(DefaultAdmin) +} + +// Validate validates the set of params +func (p Params) Validate() error { + _, err := sdk.AccAddressFromBech32(p.Admin) + return err +} + +// String implements the Stringer interface. +func (p Params) String() string { + out, _ := yaml.Marshal(p) + return string(out) +} diff --git a/x/ratesync/types/params.pb.go b/x/ratesync/types/params.pb.go new file mode 100644 index 000000000..bf8754702 --- /dev/null +++ b/x/ratesync/types/params.pb.go @@ -0,0 +1,323 @@ +// Code generated by protoc-gen-gogo. DO NOT EDIT. +// source: pstake/ratesync/v1beta1/params.proto + +package types + +import ( + fmt "fmt" + _ "github.com/cosmos/cosmos-proto" + _ "github.com/cosmos/gogoproto/gogoproto" + proto "github.com/cosmos/gogoproto/proto" + io "io" + math "math" + math_bits "math/bits" +) + +// Reference imports to suppress errors if they are not otherwise used. +var _ = proto.Marshal +var _ = fmt.Errorf +var _ = math.Inf + +// This is a compile-time assertion to ensure that this generated file +// is compatible with the proto package it is being compiled against. +// A compilation error at this line likely means your copy of the +// proto package needs to be updated. +const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package + +// Params defines the parameters for the module. +type Params struct { + Admin string `protobuf:"bytes,1,opt,name=admin,proto3" json:"admin,omitempty"` +} + +func (m *Params) Reset() { *m = Params{} } +func (*Params) ProtoMessage() {} +func (*Params) Descriptor() ([]byte, []int) { + return fileDescriptor_874e04d586361014, []int{0} +} +func (m *Params) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *Params) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_Params.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *Params) XXX_Merge(src proto.Message) { + xxx_messageInfo_Params.Merge(m, src) +} +func (m *Params) XXX_Size() int { + return m.Size() +} +func (m *Params) XXX_DiscardUnknown() { + xxx_messageInfo_Params.DiscardUnknown(m) +} + +var xxx_messageInfo_Params proto.InternalMessageInfo + +func (m *Params) GetAdmin() string { + if m != nil { + return m.Admin + } + return "" +} + +func init() { + proto.RegisterType((*Params)(nil), "pstake.ratesync.v1beta1.Params") +} + +func init() { + proto.RegisterFile("pstake/ratesync/v1beta1/params.proto", fileDescriptor_874e04d586361014) +} + +var fileDescriptor_874e04d586361014 = []byte{ + // 234 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0x52, 0x29, 0x28, 0x2e, 0x49, + 0xcc, 0x4e, 0xd5, 0x2f, 0x4a, 0x2c, 0x49, 0x2d, 0xae, 0xcc, 0x4b, 0xd6, 0x2f, 0x33, 0x4c, 0x4a, + 0x2d, 0x49, 0x34, 0xd4, 0x2f, 0x48, 0x2c, 0x4a, 0xcc, 0x2d, 0xd6, 0x2b, 0x28, 0xca, 0x2f, 0xc9, + 0x17, 0x12, 0x87, 0xa8, 0xd2, 0x83, 0xa9, 0xd2, 0x83, 0xaa, 0x92, 0x12, 0x49, 0xcf, 0x4f, 0xcf, + 0x07, 0xab, 0xd1, 0x07, 0xb1, 0x20, 0xca, 0xa5, 0x24, 0x93, 0xf3, 0x8b, 0x73, 0xf3, 0x8b, 0xe3, + 0x21, 0x12, 0x10, 0x0e, 0x44, 0x4a, 0xc9, 0x8e, 0x8b, 0x2d, 0x00, 0x6c, 0xb2, 0x90, 0x1e, 0x17, + 0x6b, 0x62, 0x4a, 0x6e, 0x66, 0x9e, 0x04, 0xa3, 0x02, 0xa3, 0x06, 0xa7, 0x93, 0xc4, 0xa5, 0x2d, + 0xba, 0x22, 0x50, 0xa5, 0x8e, 0x29, 0x29, 0x45, 0xa9, 0xc5, 0xc5, 0xc1, 0x25, 0x45, 0x99, 0x79, + 0xe9, 0x41, 0x10, 0x65, 0x56, 0x2c, 0x33, 0x16, 0xc8, 0x33, 0x38, 0x85, 0x9e, 0x78, 0x24, 0xc7, + 0x78, 0xe1, 0x91, 0x1c, 0xe3, 0x83, 0x47, 0x72, 0x8c, 0x13, 0x1e, 0xcb, 0x31, 0x5c, 0x78, 0x2c, + 0xc7, 0x70, 0xe3, 0xb1, 0x1c, 0x43, 0x94, 0x75, 0x7a, 0x66, 0x49, 0x46, 0x69, 0x92, 0x5e, 0x72, + 0x7e, 0xae, 0x7e, 0x41, 0x6a, 0x51, 0x71, 0x66, 0x71, 0x49, 0x6a, 0x5e, 0x72, 0xaa, 0x7f, 0x5e, + 0xaa, 0x3e, 0xc4, 0xf5, 0xba, 0x79, 0x89, 0x25, 0x99, 0x65, 0xa9, 0xfa, 0x65, 0x46, 0xfa, 0x15, + 0x08, 0xff, 0x96, 0x54, 0x16, 0xa4, 0x16, 0x27, 0xb1, 0x81, 0x5d, 0x67, 0x0c, 0x08, 0x00, 0x00, + 0xff, 0xff, 0x60, 0xd5, 0xf3, 0x96, 0x0f, 0x01, 0x00, 0x00, +} + +func (m *Params) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *Params) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *Params) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if len(m.Admin) > 0 { + i -= len(m.Admin) + copy(dAtA[i:], m.Admin) + i = encodeVarintParams(dAtA, i, uint64(len(m.Admin))) + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func encodeVarintParams(dAtA []byte, offset int, v uint64) int { + offset -= sovParams(v) + base := offset + for v >= 1<<7 { + dAtA[offset] = uint8(v&0x7f | 0x80) + v >>= 7 + offset++ + } + dAtA[offset] = uint8(v) + return base +} +func (m *Params) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.Admin) + if l > 0 { + n += 1 + l + sovParams(uint64(l)) + } + return n +} + +func sovParams(x uint64) (n int) { + return (math_bits.Len64(x|1) + 6) / 7 +} +func sozParams(x uint64) (n int) { + return sovParams(uint64((x << 1) ^ uint64((int64(x) >> 63)))) +} +func (m *Params) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowParams + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: Params: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: Params: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Admin", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowParams + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthParams + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthParams + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Admin = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipParams(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthParams + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func skipParams(dAtA []byte) (n int, err error) { + l := len(dAtA) + iNdEx := 0 + depth := 0 + for iNdEx < l { + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowParams + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= (uint64(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + wireType := int(wire & 0x7) + switch wireType { + case 0: + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowParams + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + iNdEx++ + if dAtA[iNdEx-1] < 0x80 { + break + } + } + case 1: + iNdEx += 8 + case 2: + var length int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowParams + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + length |= (int(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + if length < 0 { + return 0, ErrInvalidLengthParams + } + iNdEx += length + case 3: + depth++ + case 4: + if depth == 0 { + return 0, ErrUnexpectedEndOfGroupParams + } + depth-- + case 5: + iNdEx += 4 + default: + return 0, fmt.Errorf("proto: illegal wireType %d", wireType) + } + if iNdEx < 0 { + return 0, ErrInvalidLengthParams + } + if depth == 0 { + return iNdEx, nil + } + } + return 0, io.ErrUnexpectedEOF +} + +var ( + ErrInvalidLengthParams = fmt.Errorf("proto: negative length found during unmarshaling") + ErrIntOverflowParams = fmt.Errorf("proto: integer overflow") + ErrUnexpectedEndOfGroupParams = fmt.Errorf("proto: unexpected end of group") +) diff --git a/x/ratesync/types/query.pb.go b/x/ratesync/types/query.pb.go new file mode 100644 index 000000000..169fafc5b --- /dev/null +++ b/x/ratesync/types/query.pb.go @@ -0,0 +1,1374 @@ +// Code generated by protoc-gen-gogo. DO NOT EDIT. +// source: pstake/ratesync/v1beta1/query.proto + +package types + +import ( + context "context" + fmt "fmt" + query "github.com/cosmos/cosmos-sdk/types/query" + _ "github.com/cosmos/gogoproto/gogoproto" + grpc1 "github.com/cosmos/gogoproto/grpc" + proto "github.com/cosmos/gogoproto/proto" + _ "google.golang.org/genproto/googleapis/api/annotations" + grpc "google.golang.org/grpc" + codes "google.golang.org/grpc/codes" + status "google.golang.org/grpc/status" + io "io" + math "math" + math_bits "math/bits" +) + +// Reference imports to suppress errors if they are not otherwise used. +var _ = proto.Marshal +var _ = fmt.Errorf +var _ = math.Inf + +// This is a compile-time assertion to ensure that this generated file +// is compatible with the proto package it is being compiled against. +// A compilation error at this line likely means your copy of the +// proto package needs to be updated. +const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package + +// QueryParamsRequest is request type for the Query/Params RPC method. +type QueryParamsRequest struct { +} + +func (m *QueryParamsRequest) Reset() { *m = QueryParamsRequest{} } +func (m *QueryParamsRequest) String() string { return proto.CompactTextString(m) } +func (*QueryParamsRequest) ProtoMessage() {} +func (*QueryParamsRequest) Descriptor() ([]byte, []int) { + return fileDescriptor_c98b0d6ed4c1c918, []int{0} +} +func (m *QueryParamsRequest) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *QueryParamsRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_QueryParamsRequest.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *QueryParamsRequest) XXX_Merge(src proto.Message) { + xxx_messageInfo_QueryParamsRequest.Merge(m, src) +} +func (m *QueryParamsRequest) XXX_Size() int { + return m.Size() +} +func (m *QueryParamsRequest) XXX_DiscardUnknown() { + xxx_messageInfo_QueryParamsRequest.DiscardUnknown(m) +} + +var xxx_messageInfo_QueryParamsRequest proto.InternalMessageInfo + +// QueryParamsResponse is response type for the Query/Params RPC method. +type QueryParamsResponse struct { + // params holds all the parameters of this module. + Params Params `protobuf:"bytes,1,opt,name=params,proto3" json:"params"` +} + +func (m *QueryParamsResponse) Reset() { *m = QueryParamsResponse{} } +func (m *QueryParamsResponse) String() string { return proto.CompactTextString(m) } +func (*QueryParamsResponse) ProtoMessage() {} +func (*QueryParamsResponse) Descriptor() ([]byte, []int) { + return fileDescriptor_c98b0d6ed4c1c918, []int{1} +} +func (m *QueryParamsResponse) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *QueryParamsResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_QueryParamsResponse.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *QueryParamsResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_QueryParamsResponse.Merge(m, src) +} +func (m *QueryParamsResponse) XXX_Size() int { + return m.Size() +} +func (m *QueryParamsResponse) XXX_DiscardUnknown() { + xxx_messageInfo_QueryParamsResponse.DiscardUnknown(m) +} + +var xxx_messageInfo_QueryParamsResponse proto.InternalMessageInfo + +func (m *QueryParamsResponse) GetParams() Params { + if m != nil { + return m.Params + } + return Params{} +} + +type QueryGetHostChainRequest struct { + ID uint64 `protobuf:"varint,1,opt,name=i_d,json=iD,proto3" json:"i_d,omitempty"` +} + +func (m *QueryGetHostChainRequest) Reset() { *m = QueryGetHostChainRequest{} } +func (m *QueryGetHostChainRequest) String() string { return proto.CompactTextString(m) } +func (*QueryGetHostChainRequest) ProtoMessage() {} +func (*QueryGetHostChainRequest) Descriptor() ([]byte, []int) { + return fileDescriptor_c98b0d6ed4c1c918, []int{2} +} +func (m *QueryGetHostChainRequest) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *QueryGetHostChainRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_QueryGetHostChainRequest.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *QueryGetHostChainRequest) XXX_Merge(src proto.Message) { + xxx_messageInfo_QueryGetHostChainRequest.Merge(m, src) +} +func (m *QueryGetHostChainRequest) XXX_Size() int { + return m.Size() +} +func (m *QueryGetHostChainRequest) XXX_DiscardUnknown() { + xxx_messageInfo_QueryGetHostChainRequest.DiscardUnknown(m) +} + +var xxx_messageInfo_QueryGetHostChainRequest proto.InternalMessageInfo + +func (m *QueryGetHostChainRequest) GetID() uint64 { + if m != nil { + return m.ID + } + return 0 +} + +type QueryGetHostChainResponse struct { + HostChain HostChain `protobuf:"bytes,1,opt,name=host_chain,json=hostChain,proto3" json:"host_chain"` +} + +func (m *QueryGetHostChainResponse) Reset() { *m = QueryGetHostChainResponse{} } +func (m *QueryGetHostChainResponse) String() string { return proto.CompactTextString(m) } +func (*QueryGetHostChainResponse) ProtoMessage() {} +func (*QueryGetHostChainResponse) Descriptor() ([]byte, []int) { + return fileDescriptor_c98b0d6ed4c1c918, []int{3} +} +func (m *QueryGetHostChainResponse) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *QueryGetHostChainResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_QueryGetHostChainResponse.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *QueryGetHostChainResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_QueryGetHostChainResponse.Merge(m, src) +} +func (m *QueryGetHostChainResponse) XXX_Size() int { + return m.Size() +} +func (m *QueryGetHostChainResponse) XXX_DiscardUnknown() { + xxx_messageInfo_QueryGetHostChainResponse.DiscardUnknown(m) +} + +var xxx_messageInfo_QueryGetHostChainResponse proto.InternalMessageInfo + +func (m *QueryGetHostChainResponse) GetHostChain() HostChain { + if m != nil { + return m.HostChain + } + return HostChain{} +} + +type QueryAllHostChainsRequest struct { + Pagination *query.PageRequest `protobuf:"bytes,1,opt,name=pagination,proto3" json:"pagination,omitempty"` +} + +func (m *QueryAllHostChainsRequest) Reset() { *m = QueryAllHostChainsRequest{} } +func (m *QueryAllHostChainsRequest) String() string { return proto.CompactTextString(m) } +func (*QueryAllHostChainsRequest) ProtoMessage() {} +func (*QueryAllHostChainsRequest) Descriptor() ([]byte, []int) { + return fileDescriptor_c98b0d6ed4c1c918, []int{4} +} +func (m *QueryAllHostChainsRequest) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *QueryAllHostChainsRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_QueryAllHostChainsRequest.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *QueryAllHostChainsRequest) XXX_Merge(src proto.Message) { + xxx_messageInfo_QueryAllHostChainsRequest.Merge(m, src) +} +func (m *QueryAllHostChainsRequest) XXX_Size() int { + return m.Size() +} +func (m *QueryAllHostChainsRequest) XXX_DiscardUnknown() { + xxx_messageInfo_QueryAllHostChainsRequest.DiscardUnknown(m) +} + +var xxx_messageInfo_QueryAllHostChainsRequest proto.InternalMessageInfo + +func (m *QueryAllHostChainsRequest) GetPagination() *query.PageRequest { + if m != nil { + return m.Pagination + } + return nil +} + +type QueryAllHostChainsResponse struct { + HostChains []HostChain `protobuf:"bytes,1,rep,name=host_chains,json=hostChains,proto3" json:"host_chains"` + Pagination *query.PageResponse `protobuf:"bytes,2,opt,name=pagination,proto3" json:"pagination,omitempty"` +} + +func (m *QueryAllHostChainsResponse) Reset() { *m = QueryAllHostChainsResponse{} } +func (m *QueryAllHostChainsResponse) String() string { return proto.CompactTextString(m) } +func (*QueryAllHostChainsResponse) ProtoMessage() {} +func (*QueryAllHostChainsResponse) Descriptor() ([]byte, []int) { + return fileDescriptor_c98b0d6ed4c1c918, []int{5} +} +func (m *QueryAllHostChainsResponse) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *QueryAllHostChainsResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_QueryAllHostChainsResponse.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *QueryAllHostChainsResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_QueryAllHostChainsResponse.Merge(m, src) +} +func (m *QueryAllHostChainsResponse) XXX_Size() int { + return m.Size() +} +func (m *QueryAllHostChainsResponse) XXX_DiscardUnknown() { + xxx_messageInfo_QueryAllHostChainsResponse.DiscardUnknown(m) +} + +var xxx_messageInfo_QueryAllHostChainsResponse proto.InternalMessageInfo + +func (m *QueryAllHostChainsResponse) GetHostChains() []HostChain { + if m != nil { + return m.HostChains + } + return nil +} + +func (m *QueryAllHostChainsResponse) GetPagination() *query.PageResponse { + if m != nil { + return m.Pagination + } + return nil +} + +func init() { + proto.RegisterType((*QueryParamsRequest)(nil), "pstake.ratesync.v1beta1.QueryParamsRequest") + proto.RegisterType((*QueryParamsResponse)(nil), "pstake.ratesync.v1beta1.QueryParamsResponse") + proto.RegisterType((*QueryGetHostChainRequest)(nil), "pstake.ratesync.v1beta1.QueryGetHostChainRequest") + proto.RegisterType((*QueryGetHostChainResponse)(nil), "pstake.ratesync.v1beta1.QueryGetHostChainResponse") + proto.RegisterType((*QueryAllHostChainsRequest)(nil), "pstake.ratesync.v1beta1.QueryAllHostChainsRequest") + proto.RegisterType((*QueryAllHostChainsResponse)(nil), "pstake.ratesync.v1beta1.QueryAllHostChainsResponse") +} + +func init() { + proto.RegisterFile("pstake/ratesync/v1beta1/query.proto", fileDescriptor_c98b0d6ed4c1c918) +} + +var fileDescriptor_c98b0d6ed4c1c918 = []byte{ + // 534 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x94, 0x94, 0x4f, 0x6b, 0x13, 0x4f, + 0x18, 0xc7, 0xb3, 0x49, 0x7f, 0x81, 0x3e, 0xe5, 0x87, 0x30, 0x16, 0xac, 0x8b, 0x6c, 0x74, 0x95, + 0xb4, 0x18, 0x3b, 0x43, 0x92, 0xa3, 0x78, 0xb0, 0x8a, 0xd5, 0x93, 0x1a, 0xf4, 0xe2, 0x25, 0x4c, + 0x36, 0xc3, 0x66, 0x31, 0x99, 0xd9, 0xee, 0x4c, 0x82, 0x41, 0xbc, 0x78, 0xf6, 0x20, 0xf8, 0x22, + 0xf4, 0xe8, 0xcb, 0xe8, 0xb1, 0xe0, 0xc5, 0x93, 0x48, 0xe2, 0xcd, 0x37, 0x21, 0x3b, 0x33, 0xd9, + 0x4d, 0x69, 0xb6, 0x6d, 0x6e, 0x61, 0xf2, 0xfd, 0x3e, 0xdf, 0xcf, 0xf3, 0x87, 0x85, 0xdb, 0xb1, + 0x54, 0xf4, 0x2d, 0x23, 0x09, 0x55, 0x4c, 0x4e, 0x79, 0x40, 0x26, 0xcd, 0x1e, 0x53, 0xb4, 0x49, + 0x8e, 0xc6, 0x2c, 0x99, 0xe2, 0x38, 0x11, 0x4a, 0xa0, 0x6b, 0x46, 0x84, 0x17, 0x22, 0x6c, 0x45, + 0xee, 0x76, 0x28, 0x42, 0xa1, 0x35, 0x24, 0xfd, 0x65, 0xe4, 0xee, 0x8d, 0x50, 0x88, 0x70, 0xc8, + 0x08, 0x8d, 0x23, 0x42, 0x39, 0x17, 0x8a, 0xaa, 0x48, 0x70, 0x69, 0xff, 0xbd, 0x1b, 0x08, 0x39, + 0x12, 0x92, 0xf4, 0xa8, 0x64, 0x26, 0x25, 0xcb, 0x8c, 0x69, 0x18, 0x71, 0x2d, 0xb6, 0xda, 0x3b, + 0x45, 0x74, 0x31, 0x4d, 0xe8, 0x68, 0x51, 0xb1, 0x5e, 0xa4, 0xca, 0x78, 0xb5, 0xce, 0xdf, 0x06, + 0xf4, 0x32, 0xcd, 0x7b, 0xa1, 0xcd, 0x1d, 0x76, 0x34, 0x66, 0x52, 0xf9, 0xaf, 0xe0, 0xea, 0xa9, + 0x57, 0x19, 0x0b, 0x2e, 0x19, 0x7a, 0x00, 0x55, 0x13, 0xb2, 0xe3, 0xdc, 0x74, 0xf6, 0xb6, 0x5a, + 0x35, 0x5c, 0x30, 0x04, 0x6c, 0x8c, 0x07, 0x1b, 0xc7, 0xbf, 0x6a, 0xa5, 0x8e, 0x35, 0xf9, 0x0d, + 0xd8, 0xd1, 0x55, 0x0f, 0x99, 0x7a, 0x2a, 0xa4, 0x7a, 0x34, 0xa0, 0x11, 0xb7, 0x89, 0xe8, 0x0a, + 0x54, 0xa2, 0x6e, 0x5f, 0xd7, 0xdd, 0xe8, 0x94, 0xa3, 0xc7, 0x7e, 0x1f, 0xae, 0xaf, 0x10, 0x5b, + 0x90, 0x43, 0x80, 0x81, 0x90, 0xaa, 0x1b, 0xa4, 0xaf, 0x16, 0xc6, 0x2f, 0x84, 0xc9, 0xfc, 0x96, + 0x67, 0x73, 0xb0, 0x78, 0xf0, 0x03, 0x9b, 0xf2, 0x70, 0x38, 0xcc, 0x54, 0x8b, 0x29, 0xa0, 0x27, + 0x00, 0xf9, 0xf4, 0x6d, 0x4a, 0x1d, 0x9b, 0x55, 0xe1, 0x74, 0x55, 0xd8, 0x1c, 0x44, 0xde, 0x74, + 0xc8, 0xac, 0xb7, 0xb3, 0xe4, 0xf4, 0xbf, 0x3b, 0xe0, 0xae, 0x4a, 0xb1, 0xcd, 0x3c, 0x83, 0xad, + 0xbc, 0x99, 0x74, 0xb4, 0x95, 0xb5, 0xba, 0x81, 0xac, 0x1b, 0x99, 0xce, 0x65, 0x89, 0xb8, 0xac, + 0x89, 0x77, 0x2f, 0x24, 0x36, 0x1c, 0xcb, 0xc8, 0xad, 0xbf, 0x15, 0xf8, 0x4f, 0x23, 0xa3, 0x4f, + 0x0e, 0x54, 0xcd, 0x36, 0x51, 0xa3, 0x90, 0xe9, 0xec, 0x09, 0xb9, 0xf7, 0x2e, 0x27, 0x36, 0xd9, + 0xfe, 0xee, 0xc7, 0x1f, 0x7f, 0xbe, 0x94, 0x6f, 0xa1, 0x1a, 0x39, 0xff, 0xba, 0xd1, 0x57, 0x07, + 0x36, 0xb3, 0x09, 0xa0, 0xe6, 0xf9, 0x21, 0x2b, 0x0e, 0xcd, 0x6d, 0xad, 0x63, 0xb1, 0x74, 0x6d, + 0x4d, 0xb7, 0x8f, 0x1a, 0x96, 0x6e, 0x3f, 0x9d, 0xd2, 0x84, 0x91, 0x49, 0x2b, 0xe7, 0xcc, 0x57, + 0x48, 0xde, 0x47, 0xdd, 0xfe, 0x07, 0xf4, 0xcd, 0x81, 0xff, 0x4f, 0x2d, 0x1c, 0x5d, 0x10, 0xbd, + 0xea, 0x06, 0xdd, 0xf6, 0x5a, 0x1e, 0xcb, 0x8b, 0x35, 0xef, 0x1e, 0xaa, 0x5f, 0x8a, 0x57, 0x1e, + 0xbc, 0x3e, 0x9e, 0x79, 0xce, 0xc9, 0xcc, 0x73, 0x7e, 0xcf, 0x3c, 0xe7, 0xf3, 0xdc, 0x2b, 0x9d, + 0xcc, 0xbd, 0xd2, 0xcf, 0xb9, 0x57, 0x7a, 0x73, 0x3f, 0x8c, 0xd4, 0x60, 0xdc, 0xc3, 0x81, 0x18, + 0x91, 0x98, 0x25, 0x32, 0x92, 0x8a, 0xf1, 0x80, 0x3d, 0xe7, 0xec, 0x6c, 0xe9, 0x77, 0x79, 0x71, + 0x35, 0x8d, 0x99, 0xec, 0x55, 0xf5, 0x27, 0xa6, 0xfd, 0x2f, 0x00, 0x00, 0xff, 0xff, 0x52, 0x72, + 0xb9, 0x85, 0x50, 0x05, 0x00, 0x00, +} + +// Reference imports to suppress errors if they are not otherwise used. +var _ context.Context +var _ grpc.ClientConn + +// This is a compile-time assertion to ensure that this generated file +// is compatible with the grpc package it is being compiled against. +const _ = grpc.SupportPackageIsVersion4 + +// QueryClient is the client API for Query service. +// +// For semantics around ctx use and closing/ending streaming RPCs, please refer to https://godoc.org/google.golang.org/grpc#ClientConn.NewStream. +type QueryClient interface { + // Parameters queries the parameters of the module. + Params(ctx context.Context, in *QueryParamsRequest, opts ...grpc.CallOption) (*QueryParamsResponse, error) + // Queries a list of Chain items. + HostChain(ctx context.Context, in *QueryGetHostChainRequest, opts ...grpc.CallOption) (*QueryGetHostChainResponse, error) + AllHostChains(ctx context.Context, in *QueryAllHostChainsRequest, opts ...grpc.CallOption) (*QueryAllHostChainsResponse, error) +} + +type queryClient struct { + cc grpc1.ClientConn +} + +func NewQueryClient(cc grpc1.ClientConn) QueryClient { + return &queryClient{cc} +} + +func (c *queryClient) Params(ctx context.Context, in *QueryParamsRequest, opts ...grpc.CallOption) (*QueryParamsResponse, error) { + out := new(QueryParamsResponse) + err := c.cc.Invoke(ctx, "/pstake.ratesync.v1beta1.Query/Params", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *queryClient) HostChain(ctx context.Context, in *QueryGetHostChainRequest, opts ...grpc.CallOption) (*QueryGetHostChainResponse, error) { + out := new(QueryGetHostChainResponse) + err := c.cc.Invoke(ctx, "/pstake.ratesync.v1beta1.Query/HostChain", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *queryClient) AllHostChains(ctx context.Context, in *QueryAllHostChainsRequest, opts ...grpc.CallOption) (*QueryAllHostChainsResponse, error) { + out := new(QueryAllHostChainsResponse) + err := c.cc.Invoke(ctx, "/pstake.ratesync.v1beta1.Query/AllHostChains", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +// QueryServer is the server API for Query service. +type QueryServer interface { + // Parameters queries the parameters of the module. + Params(context.Context, *QueryParamsRequest) (*QueryParamsResponse, error) + // Queries a list of Chain items. + HostChain(context.Context, *QueryGetHostChainRequest) (*QueryGetHostChainResponse, error) + AllHostChains(context.Context, *QueryAllHostChainsRequest) (*QueryAllHostChainsResponse, error) +} + +// UnimplementedQueryServer can be embedded to have forward compatible implementations. +type UnimplementedQueryServer struct { +} + +func (*UnimplementedQueryServer) Params(ctx context.Context, req *QueryParamsRequest) (*QueryParamsResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method Params not implemented") +} +func (*UnimplementedQueryServer) HostChain(ctx context.Context, req *QueryGetHostChainRequest) (*QueryGetHostChainResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method HostChain not implemented") +} +func (*UnimplementedQueryServer) AllHostChains(ctx context.Context, req *QueryAllHostChainsRequest) (*QueryAllHostChainsResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method AllHostChains not implemented") +} + +func RegisterQueryServer(s grpc1.Server, srv QueryServer) { + s.RegisterService(&_Query_serviceDesc, srv) +} + +func _Query_Params_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(QueryParamsRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(QueryServer).Params(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/pstake.ratesync.v1beta1.Query/Params", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(QueryServer).Params(ctx, req.(*QueryParamsRequest)) + } + return interceptor(ctx, in, info, handler) +} + +func _Query_HostChain_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(QueryGetHostChainRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(QueryServer).HostChain(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/pstake.ratesync.v1beta1.Query/HostChain", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(QueryServer).HostChain(ctx, req.(*QueryGetHostChainRequest)) + } + return interceptor(ctx, in, info, handler) +} + +func _Query_AllHostChains_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(QueryAllHostChainsRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(QueryServer).AllHostChains(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/pstake.ratesync.v1beta1.Query/AllHostChains", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(QueryServer).AllHostChains(ctx, req.(*QueryAllHostChainsRequest)) + } + return interceptor(ctx, in, info, handler) +} + +var _Query_serviceDesc = grpc.ServiceDesc{ + ServiceName: "pstake.ratesync.v1beta1.Query", + HandlerType: (*QueryServer)(nil), + Methods: []grpc.MethodDesc{ + { + MethodName: "Params", + Handler: _Query_Params_Handler, + }, + { + MethodName: "HostChain", + Handler: _Query_HostChain_Handler, + }, + { + MethodName: "AllHostChains", + Handler: _Query_AllHostChains_Handler, + }, + }, + Streams: []grpc.StreamDesc{}, + Metadata: "pstake/ratesync/v1beta1/query.proto", +} + +func (m *QueryParamsRequest) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *QueryParamsRequest) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *QueryParamsRequest) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + return len(dAtA) - i, nil +} + +func (m *QueryParamsResponse) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *QueryParamsResponse) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *QueryParamsResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + { + size, err := m.Params.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintQuery(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0xa + return len(dAtA) - i, nil +} + +func (m *QueryGetHostChainRequest) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *QueryGetHostChainRequest) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *QueryGetHostChainRequest) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if m.ID != 0 { + i = encodeVarintQuery(dAtA, i, uint64(m.ID)) + i-- + dAtA[i] = 0x8 + } + return len(dAtA) - i, nil +} + +func (m *QueryGetHostChainResponse) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *QueryGetHostChainResponse) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *QueryGetHostChainResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + { + size, err := m.HostChain.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintQuery(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0xa + return len(dAtA) - i, nil +} + +func (m *QueryAllHostChainsRequest) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *QueryAllHostChainsRequest) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *QueryAllHostChainsRequest) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if m.Pagination != nil { + { + size, err := m.Pagination.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintQuery(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func (m *QueryAllHostChainsResponse) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *QueryAllHostChainsResponse) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *QueryAllHostChainsResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if m.Pagination != nil { + { + size, err := m.Pagination.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintQuery(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x12 + } + if len(m.HostChains) > 0 { + for iNdEx := len(m.HostChains) - 1; iNdEx >= 0; iNdEx-- { + { + size, err := m.HostChains[iNdEx].MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintQuery(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0xa + } + } + return len(dAtA) - i, nil +} + +func encodeVarintQuery(dAtA []byte, offset int, v uint64) int { + offset -= sovQuery(v) + base := offset + for v >= 1<<7 { + dAtA[offset] = uint8(v&0x7f | 0x80) + v >>= 7 + offset++ + } + dAtA[offset] = uint8(v) + return base +} +func (m *QueryParamsRequest) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + return n +} + +func (m *QueryParamsResponse) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = m.Params.Size() + n += 1 + l + sovQuery(uint64(l)) + return n +} + +func (m *QueryGetHostChainRequest) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if m.ID != 0 { + n += 1 + sovQuery(uint64(m.ID)) + } + return n +} + +func (m *QueryGetHostChainResponse) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = m.HostChain.Size() + n += 1 + l + sovQuery(uint64(l)) + return n +} + +func (m *QueryAllHostChainsRequest) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if m.Pagination != nil { + l = m.Pagination.Size() + n += 1 + l + sovQuery(uint64(l)) + } + return n +} + +func (m *QueryAllHostChainsResponse) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if len(m.HostChains) > 0 { + for _, e := range m.HostChains { + l = e.Size() + n += 1 + l + sovQuery(uint64(l)) + } + } + if m.Pagination != nil { + l = m.Pagination.Size() + n += 1 + l + sovQuery(uint64(l)) + } + return n +} + +func sovQuery(x uint64) (n int) { + return (math_bits.Len64(x|1) + 6) / 7 +} +func sozQuery(x uint64) (n int) { + return sovQuery(uint64((x << 1) ^ uint64((int64(x) >> 63)))) +} +func (m *QueryParamsRequest) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: QueryParamsRequest: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: QueryParamsRequest: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + default: + iNdEx = preIndex + skippy, err := skipQuery(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthQuery + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *QueryParamsResponse) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: QueryParamsResponse: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: QueryParamsResponse: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Params", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthQuery + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthQuery + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if err := m.Params.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipQuery(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthQuery + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *QueryGetHostChainRequest) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: QueryGetHostChainRequest: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: QueryGetHostChainRequest: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field ID", wireType) + } + m.ID = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.ID |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + default: + iNdEx = preIndex + skippy, err := skipQuery(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthQuery + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *QueryGetHostChainResponse) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: QueryGetHostChainResponse: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: QueryGetHostChainResponse: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field HostChain", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthQuery + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthQuery + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if err := m.HostChain.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipQuery(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthQuery + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *QueryAllHostChainsRequest) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: QueryAllHostChainsRequest: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: QueryAllHostChainsRequest: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Pagination", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthQuery + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthQuery + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if m.Pagination == nil { + m.Pagination = &query.PageRequest{} + } + if err := m.Pagination.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipQuery(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthQuery + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *QueryAllHostChainsResponse) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: QueryAllHostChainsResponse: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: QueryAllHostChainsResponse: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field HostChains", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthQuery + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthQuery + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.HostChains = append(m.HostChains, HostChain{}) + if err := m.HostChains[len(m.HostChains)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Pagination", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthQuery + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthQuery + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if m.Pagination == nil { + m.Pagination = &query.PageResponse{} + } + if err := m.Pagination.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipQuery(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthQuery + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func skipQuery(dAtA []byte) (n int, err error) { + l := len(dAtA) + iNdEx := 0 + depth := 0 + for iNdEx < l { + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowQuery + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= (uint64(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + wireType := int(wire & 0x7) + switch wireType { + case 0: + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowQuery + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + iNdEx++ + if dAtA[iNdEx-1] < 0x80 { + break + } + } + case 1: + iNdEx += 8 + case 2: + var length int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowQuery + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + length |= (int(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + if length < 0 { + return 0, ErrInvalidLengthQuery + } + iNdEx += length + case 3: + depth++ + case 4: + if depth == 0 { + return 0, ErrUnexpectedEndOfGroupQuery + } + depth-- + case 5: + iNdEx += 4 + default: + return 0, fmt.Errorf("proto: illegal wireType %d", wireType) + } + if iNdEx < 0 { + return 0, ErrInvalidLengthQuery + } + if depth == 0 { + return iNdEx, nil + } + } + return 0, io.ErrUnexpectedEOF +} + +var ( + ErrInvalidLengthQuery = fmt.Errorf("proto: negative length found during unmarshaling") + ErrIntOverflowQuery = fmt.Errorf("proto: integer overflow") + ErrUnexpectedEndOfGroupQuery = fmt.Errorf("proto: unexpected end of group") +) diff --git a/x/ratesync/types/query.pb.gw.go b/x/ratesync/types/query.pb.gw.go new file mode 100644 index 000000000..3ea843ac8 --- /dev/null +++ b/x/ratesync/types/query.pb.gw.go @@ -0,0 +1,337 @@ +// Code generated by protoc-gen-grpc-gateway. DO NOT EDIT. +// source: pstake/ratesync/v1beta1/query.proto + +/* +Package types is a reverse proxy. + +It translates gRPC into RESTful JSON APIs. +*/ +package types + +import ( + "context" + "io" + "net/http" + + "github.com/golang/protobuf/descriptor" + "github.com/golang/protobuf/proto" + "github.com/grpc-ecosystem/grpc-gateway/runtime" + "github.com/grpc-ecosystem/grpc-gateway/utilities" + "google.golang.org/grpc" + "google.golang.org/grpc/codes" + "google.golang.org/grpc/grpclog" + "google.golang.org/grpc/metadata" + "google.golang.org/grpc/status" +) + +// Suppress "imported and not used" errors +var _ codes.Code +var _ io.Reader +var _ status.Status +var _ = runtime.String +var _ = utilities.NewDoubleArray +var _ = descriptor.ForMessage +var _ = metadata.Join + +func request_Query_Params_0(ctx context.Context, marshaler runtime.Marshaler, client QueryClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq QueryParamsRequest + var metadata runtime.ServerMetadata + + msg, err := client.Params(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) + return msg, metadata, err + +} + +func local_request_Query_Params_0(ctx context.Context, marshaler runtime.Marshaler, server QueryServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq QueryParamsRequest + var metadata runtime.ServerMetadata + + msg, err := server.Params(ctx, &protoReq) + return msg, metadata, err + +} + +func request_Query_HostChain_0(ctx context.Context, marshaler runtime.Marshaler, client QueryClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq QueryGetHostChainRequest + var metadata runtime.ServerMetadata + + var ( + val string + ok bool + err error + _ = err + ) + + val, ok = pathParams["i_d"] + if !ok { + return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "i_d") + } + + protoReq.ID, err = runtime.Uint64(val) + + if err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "i_d", err) + } + + msg, err := client.HostChain(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) + return msg, metadata, err + +} + +func local_request_Query_HostChain_0(ctx context.Context, marshaler runtime.Marshaler, server QueryServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq QueryGetHostChainRequest + var metadata runtime.ServerMetadata + + var ( + val string + ok bool + err error + _ = err + ) + + val, ok = pathParams["i_d"] + if !ok { + return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "i_d") + } + + protoReq.ID, err = runtime.Uint64(val) + + if err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "i_d", err) + } + + msg, err := server.HostChain(ctx, &protoReq) + return msg, metadata, err + +} + +var ( + filter_Query_AllHostChains_0 = &utilities.DoubleArray{Encoding: map[string]int{}, Base: []int(nil), Check: []int(nil)} +) + +func request_Query_AllHostChains_0(ctx context.Context, marshaler runtime.Marshaler, client QueryClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq QueryAllHostChainsRequest + var metadata runtime.ServerMetadata + + if err := req.ParseForm(); err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) + } + if err := runtime.PopulateQueryParameters(&protoReq, req.Form, filter_Query_AllHostChains_0); err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) + } + + msg, err := client.AllHostChains(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) + return msg, metadata, err + +} + +func local_request_Query_AllHostChains_0(ctx context.Context, marshaler runtime.Marshaler, server QueryServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq QueryAllHostChainsRequest + var metadata runtime.ServerMetadata + + if err := req.ParseForm(); err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) + } + if err := runtime.PopulateQueryParameters(&protoReq, req.Form, filter_Query_AllHostChains_0); err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) + } + + msg, err := server.AllHostChains(ctx, &protoReq) + return msg, metadata, err + +} + +// RegisterQueryHandlerServer registers the http handlers for service Query to "mux". +// UnaryRPC :call QueryServer directly. +// StreamingRPC :currently unsupported pending https://github.com/grpc/grpc-go/issues/906. +// Note that using this registration option will cause many gRPC library features to stop working. Consider using RegisterQueryHandlerFromEndpoint instead. +func RegisterQueryHandlerServer(ctx context.Context, mux *runtime.ServeMux, server QueryServer) error { + + mux.Handle("GET", pattern_Query_Params_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + ctx, cancel := context.WithCancel(req.Context()) + defer cancel() + var stream runtime.ServerTransportStream + ctx = grpc.NewContextWithServerTransportStream(ctx, &stream) + inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) + rctx, err := runtime.AnnotateIncomingContext(ctx, mux, req) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + resp, md, err := local_request_Query_Params_0(rctx, inboundMarshaler, server, req, pathParams) + md.HeaderMD, md.TrailerMD = metadata.Join(md.HeaderMD, stream.Header()), metadata.Join(md.TrailerMD, stream.Trailer()) + ctx = runtime.NewServerMetadataContext(ctx, md) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + + forward_Query_Params_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + + mux.Handle("GET", pattern_Query_HostChain_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + ctx, cancel := context.WithCancel(req.Context()) + defer cancel() + var stream runtime.ServerTransportStream + ctx = grpc.NewContextWithServerTransportStream(ctx, &stream) + inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) + rctx, err := runtime.AnnotateIncomingContext(ctx, mux, req) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + resp, md, err := local_request_Query_HostChain_0(rctx, inboundMarshaler, server, req, pathParams) + md.HeaderMD, md.TrailerMD = metadata.Join(md.HeaderMD, stream.Header()), metadata.Join(md.TrailerMD, stream.Trailer()) + ctx = runtime.NewServerMetadataContext(ctx, md) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + + forward_Query_HostChain_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + + mux.Handle("GET", pattern_Query_AllHostChains_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + ctx, cancel := context.WithCancel(req.Context()) + defer cancel() + var stream runtime.ServerTransportStream + ctx = grpc.NewContextWithServerTransportStream(ctx, &stream) + inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) + rctx, err := runtime.AnnotateIncomingContext(ctx, mux, req) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + resp, md, err := local_request_Query_AllHostChains_0(rctx, inboundMarshaler, server, req, pathParams) + md.HeaderMD, md.TrailerMD = metadata.Join(md.HeaderMD, stream.Header()), metadata.Join(md.TrailerMD, stream.Trailer()) + ctx = runtime.NewServerMetadataContext(ctx, md) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + + forward_Query_AllHostChains_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + + return nil +} + +// RegisterQueryHandlerFromEndpoint is same as RegisterQueryHandler but +// automatically dials to "endpoint" and closes the connection when "ctx" gets done. +func RegisterQueryHandlerFromEndpoint(ctx context.Context, mux *runtime.ServeMux, endpoint string, opts []grpc.DialOption) (err error) { + conn, err := grpc.Dial(endpoint, opts...) + if err != nil { + return err + } + defer func() { + if err != nil { + if cerr := conn.Close(); cerr != nil { + grpclog.Infof("Failed to close conn to %s: %v", endpoint, cerr) + } + return + } + go func() { + <-ctx.Done() + if cerr := conn.Close(); cerr != nil { + grpclog.Infof("Failed to close conn to %s: %v", endpoint, cerr) + } + }() + }() + + return RegisterQueryHandler(ctx, mux, conn) +} + +// RegisterQueryHandler registers the http handlers for service Query to "mux". +// The handlers forward requests to the grpc endpoint over "conn". +func RegisterQueryHandler(ctx context.Context, mux *runtime.ServeMux, conn *grpc.ClientConn) error { + return RegisterQueryHandlerClient(ctx, mux, NewQueryClient(conn)) +} + +// RegisterQueryHandlerClient registers the http handlers for service Query +// to "mux". The handlers forward requests to the grpc endpoint over the given implementation of "QueryClient". +// Note: the gRPC framework executes interceptors within the gRPC handler. If the passed in "QueryClient" +// doesn't go through the normal gRPC flow (creating a gRPC client etc.) then it will be up to the passed in +// "QueryClient" to call the correct interceptors. +func RegisterQueryHandlerClient(ctx context.Context, mux *runtime.ServeMux, client QueryClient) error { + + mux.Handle("GET", pattern_Query_Params_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + ctx, cancel := context.WithCancel(req.Context()) + defer cancel() + inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) + rctx, err := runtime.AnnotateContext(ctx, mux, req) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + resp, md, err := request_Query_Params_0(rctx, inboundMarshaler, client, req, pathParams) + ctx = runtime.NewServerMetadataContext(ctx, md) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + + forward_Query_Params_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + + mux.Handle("GET", pattern_Query_HostChain_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + ctx, cancel := context.WithCancel(req.Context()) + defer cancel() + inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) + rctx, err := runtime.AnnotateContext(ctx, mux, req) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + resp, md, err := request_Query_HostChain_0(rctx, inboundMarshaler, client, req, pathParams) + ctx = runtime.NewServerMetadataContext(ctx, md) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + + forward_Query_HostChain_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + + mux.Handle("GET", pattern_Query_AllHostChains_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + ctx, cancel := context.WithCancel(req.Context()) + defer cancel() + inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) + rctx, err := runtime.AnnotateContext(ctx, mux, req) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + resp, md, err := request_Query_AllHostChains_0(rctx, inboundMarshaler, client, req, pathParams) + ctx = runtime.NewServerMetadataContext(ctx, md) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + + forward_Query_AllHostChains_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + + return nil +} + +var ( + pattern_Query_Params_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 2, 3}, []string{"pstake", "ratesync", "v1beta1", "params"}, "", runtime.AssumeColonVerbOpt(false))) + + pattern_Query_HostChain_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 2, 3, 1, 0, 4, 1, 5, 4}, []string{"pstake-native", "v2", "ratesync", "host_chain", "i_d"}, "", runtime.AssumeColonVerbOpt(false))) + + pattern_Query_AllHostChains_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 2, 3}, []string{"pstake-native", "v2", "ratesync", "host_chains"}, "", runtime.AssumeColonVerbOpt(false))) +) + +var ( + forward_Query_Params_0 = runtime.ForwardResponseMessage + + forward_Query_HostChain_0 = runtime.ForwardResponseMessage + + forward_Query_AllHostChains_0 = runtime.ForwardResponseMessage +) diff --git a/x/ratesync/types/ratesync.pb.go b/x/ratesync/types/ratesync.pb.go new file mode 100644 index 000000000..d5a6afc25 --- /dev/null +++ b/x/ratesync/types/ratesync.pb.go @@ -0,0 +1,1394 @@ +// Code generated by protoc-gen-gogo. DO NOT EDIT. +// source: pstake/ratesync/v1beta1/ratesync.proto + +package types + +import ( + fmt "fmt" + _ "github.com/cosmos/cosmos-sdk/types/tx/amino" + _ "github.com/cosmos/gogoproto/gogoproto" + proto "github.com/cosmos/gogoproto/proto" + types "github.com/persistenceOne/pstake-native/v2/x/liquidstakeibc/types" + io "io" + math "math" + math_bits "math/bits" +) + +// Reference imports to suppress errors if they are not otherwise used. +var _ = proto.Marshal +var _ = fmt.Errorf +var _ = math.Inf + +// This is a compile-time assertion to ensure that this generated file +// is compatible with the proto package it is being compiled against. +// A compilation error at this line likely means your copy of the +// proto package needs to be updated. +const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package + +type InstantiationState int32 + +const ( + // Not Initiated + InstantiationState_INSTANTIATION_NOT_INITIATED InstantiationState = 0 + // Initiated + InstantiationState_INSTANTIATION_INITIATED InstantiationState = 1 + // we should have an address + InstantiationState_INSTANTIATION_COMPLETED InstantiationState = 2 +) + +var InstantiationState_name = map[int32]string{ + 0: "INSTANTIATION_NOT_INITIATED", + 1: "INSTANTIATION_INITIATED", + 2: "INSTANTIATION_COMPLETED", +} + +var InstantiationState_value = map[string]int32{ + "INSTANTIATION_NOT_INITIATED": 0, + "INSTANTIATION_INITIATED": 1, + "INSTANTIATION_COMPLETED": 2, +} + +func (x InstantiationState) String() string { + return proto.EnumName(InstantiationState_name, int32(x)) +} + +func (InstantiationState) EnumDescriptor() ([]byte, []int) { + return fileDescriptor_429540018f2469ab, []int{0} +} + +type FeatureType int32 + +const ( + FeatureType_LIQUID_STAKE_IBC FeatureType = 0 + FeatureType_LIQUID_STAKE FeatureType = 1 +) + +var FeatureType_name = map[int32]string{ + 0: "LIQUID_STAKE_IBC", + 1: "LIQUID_STAKE", +} + +var FeatureType_value = map[string]int32{ + "LIQUID_STAKE_IBC": 0, + "LIQUID_STAKE": 1, +} + +func (x FeatureType) String() string { + return proto.EnumName(FeatureType_name, int32(x)) +} + +func (FeatureType) EnumDescriptor() ([]byte, []int) { + return fileDescriptor_429540018f2469ab, []int{1} +} + +// HostChain defines the ratesync module's HostChain state. +type HostChain struct { + // unique id + ID uint64 `protobuf:"varint,1,opt,name=i_d,json=iD,proto3" json:"i_d,omitempty"` + ChainID string `protobuf:"bytes,2,opt,name=chain_i_d,json=chainID,proto3" json:"chain_i_d,omitempty"` + ConnectionID string `protobuf:"bytes,3,opt,name=connection_i_d,json=connectionID,proto3" json:"connection_i_d,omitempty"` + ICAAccount types.ICAAccount `protobuf:"bytes,4,opt,name=i_c_a_account,json=iCAAccount,proto3" json:"i_c_a_account"` + Features Feature `protobuf:"bytes,5,opt,name=features,proto3" json:"features"` +} + +func (m *HostChain) Reset() { *m = HostChain{} } +func (m *HostChain) String() string { return proto.CompactTextString(m) } +func (*HostChain) ProtoMessage() {} +func (*HostChain) Descriptor() ([]byte, []int) { + return fileDescriptor_429540018f2469ab, []int{0} +} +func (m *HostChain) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *HostChain) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_HostChain.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *HostChain) XXX_Merge(src proto.Message) { + xxx_messageInfo_HostChain.Merge(m, src) +} +func (m *HostChain) XXX_Size() int { + return m.Size() +} +func (m *HostChain) XXX_DiscardUnknown() { + xxx_messageInfo_HostChain.DiscardUnknown(m) +} + +var xxx_messageInfo_HostChain proto.InternalMessageInfo + +func (m *HostChain) GetID() uint64 { + if m != nil { + return m.ID + } + return 0 +} + +func (m *HostChain) GetChainID() string { + if m != nil { + return m.ChainID + } + return "" +} + +func (m *HostChain) GetConnectionID() string { + if m != nil { + return m.ConnectionID + } + return "" +} + +func (m *HostChain) GetICAAccount() types.ICAAccount { + if m != nil { + return m.ICAAccount + } + return types.ICAAccount{} +} + +func (m *HostChain) GetFeatures() Feature { + if m != nil { + return m.Features + } + return Feature{} +} + +type Feature struct { + // triggers on hooks + LiquidStakeIBC LiquidStake `protobuf:"bytes,1,opt,name=liquid_stake_i_b_c,json=liquidStakeIBC,proto3" json:"liquid_stake_i_b_c"` + // triggers on hour epoch + LiquidStake LiquidStake `protobuf:"bytes,2,opt,name=liquid_stake,json=liquidStake,proto3" json:"liquid_stake"` +} + +func (m *Feature) Reset() { *m = Feature{} } +func (m *Feature) String() string { return proto.CompactTextString(m) } +func (*Feature) ProtoMessage() {} +func (*Feature) Descriptor() ([]byte, []int) { + return fileDescriptor_429540018f2469ab, []int{1} +} +func (m *Feature) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *Feature) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_Feature.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *Feature) XXX_Merge(src proto.Message) { + xxx_messageInfo_Feature.Merge(m, src) +} +func (m *Feature) XXX_Size() int { + return m.Size() +} +func (m *Feature) XXX_DiscardUnknown() { + xxx_messageInfo_Feature.DiscardUnknown(m) +} + +var xxx_messageInfo_Feature proto.InternalMessageInfo + +func (m *Feature) GetLiquidStakeIBC() LiquidStake { + if m != nil { + return m.LiquidStakeIBC + } + return LiquidStake{} +} + +func (m *Feature) GetLiquidStake() LiquidStake { + if m != nil { + return m.LiquidStake + } + return LiquidStake{} +} + +type LiquidStake struct { + FeatureType FeatureType `protobuf:"varint,1,opt,name=feature_type,json=featureType,proto3,enum=pstake.ratesync.v1beta1.FeatureType" json:"feature_type,omitempty"` + // needs to be uploaded before hand + CodeID uint64 `protobuf:"varint,2,opt,name=code_i_d,json=codeID,proto3" json:"code_i_d,omitempty"` + // state of instantiation, do not support gov based instantiation. (need ICA to be atleast admin) + Instantiation InstantiationState `protobuf:"varint,3,opt,name=instantiation,proto3,enum=pstake.ratesync.v1beta1.InstantiationState" json:"instantiation,omitempty"` + // address of instantiated contract. + ContractAddress string `protobuf:"bytes,4,opt,name=contract_address,json=contractAddress,proto3" json:"contract_address,omitempty"` + // allow * as default for all denoms in case of lsibc, or default bond denom in case of ls. + Denoms []string `protobuf:"bytes,5,rep,name=denoms,proto3" json:"denoms,omitempty"` + Enabled bool `protobuf:"varint,6,opt,name=enabled,proto3" json:"enabled,omitempty"` +} + +func (m *LiquidStake) Reset() { *m = LiquidStake{} } +func (m *LiquidStake) String() string { return proto.CompactTextString(m) } +func (*LiquidStake) ProtoMessage() {} +func (*LiquidStake) Descriptor() ([]byte, []int) { + return fileDescriptor_429540018f2469ab, []int{2} +} +func (m *LiquidStake) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *LiquidStake) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_LiquidStake.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *LiquidStake) XXX_Merge(src proto.Message) { + xxx_messageInfo_LiquidStake.Merge(m, src) +} +func (m *LiquidStake) XXX_Size() int { + return m.Size() +} +func (m *LiquidStake) XXX_DiscardUnknown() { + xxx_messageInfo_LiquidStake.DiscardUnknown(m) +} + +var xxx_messageInfo_LiquidStake proto.InternalMessageInfo + +func (m *LiquidStake) GetFeatureType() FeatureType { + if m != nil { + return m.FeatureType + } + return FeatureType_LIQUID_STAKE_IBC +} + +func (m *LiquidStake) GetCodeID() uint64 { + if m != nil { + return m.CodeID + } + return 0 +} + +func (m *LiquidStake) GetInstantiation() InstantiationState { + if m != nil { + return m.Instantiation + } + return InstantiationState_INSTANTIATION_NOT_INITIATED +} + +func (m *LiquidStake) GetContractAddress() string { + if m != nil { + return m.ContractAddress + } + return "" +} + +func (m *LiquidStake) GetDenoms() []string { + if m != nil { + return m.Denoms + } + return nil +} + +func (m *LiquidStake) GetEnabled() bool { + if m != nil { + return m.Enabled + } + return false +} + +// aim to keep this smaller than 256 MaxCharLen in ICA memo. +type ICAMemo struct { + FeatureType FeatureType `protobuf:"varint,1,opt,name=feature_type,json=featureType,proto3,enum=pstake.ratesync.v1beta1.FeatureType" json:"feature_type,omitempty"` + HostChainID uint64 `protobuf:"varint,2,opt,name=host_chain_i_d,json=hostChainID,proto3" json:"host_chain_i_d,omitempty"` +} + +func (m *ICAMemo) Reset() { *m = ICAMemo{} } +func (m *ICAMemo) String() string { return proto.CompactTextString(m) } +func (*ICAMemo) ProtoMessage() {} +func (*ICAMemo) Descriptor() ([]byte, []int) { + return fileDescriptor_429540018f2469ab, []int{3} +} +func (m *ICAMemo) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *ICAMemo) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_ICAMemo.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *ICAMemo) XXX_Merge(src proto.Message) { + xxx_messageInfo_ICAMemo.Merge(m, src) +} +func (m *ICAMemo) XXX_Size() int { + return m.Size() +} +func (m *ICAMemo) XXX_DiscardUnknown() { + xxx_messageInfo_ICAMemo.DiscardUnknown(m) +} + +var xxx_messageInfo_ICAMemo proto.InternalMessageInfo + +func (m *ICAMemo) GetFeatureType() FeatureType { + if m != nil { + return m.FeatureType + } + return FeatureType_LIQUID_STAKE_IBC +} + +func (m *ICAMemo) GetHostChainID() uint64 { + if m != nil { + return m.HostChainID + } + return 0 +} + +func init() { + proto.RegisterEnum("pstake.ratesync.v1beta1.InstantiationState", InstantiationState_name, InstantiationState_value) + proto.RegisterEnum("pstake.ratesync.v1beta1.FeatureType", FeatureType_name, FeatureType_value) + proto.RegisterType((*HostChain)(nil), "pstake.ratesync.v1beta1.HostChain") + proto.RegisterType((*Feature)(nil), "pstake.ratesync.v1beta1.Feature") + proto.RegisterType((*LiquidStake)(nil), "pstake.ratesync.v1beta1.LiquidStake") + proto.RegisterType((*ICAMemo)(nil), "pstake.ratesync.v1beta1.ICAMemo") +} + +func init() { + proto.RegisterFile("pstake/ratesync/v1beta1/ratesync.proto", fileDescriptor_429540018f2469ab) +} + +var fileDescriptor_429540018f2469ab = []byte{ + // 652 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xac, 0x54, 0x4f, 0x4f, 0x13, 0x4d, + 0x18, 0xef, 0x96, 0xbe, 0x2d, 0x9d, 0x2d, 0xa5, 0xef, 0x84, 0xbc, 0x34, 0x90, 0x94, 0xa6, 0x2f, + 0x31, 0x05, 0xe3, 0x6e, 0xa8, 0xf1, 0xe4, 0x69, 0xdb, 0x45, 0x9c, 0x08, 0xad, 0x6c, 0x4b, 0x4c, + 0xf4, 0x30, 0x99, 0xce, 0x0e, 0x74, 0x22, 0x9d, 0xa9, 0xdd, 0x29, 0xca, 0xcd, 0x8f, 0xe0, 0x47, + 0xf0, 0xe8, 0xd1, 0xb3, 0x9f, 0x80, 0x23, 0x47, 0x4f, 0xc6, 0xc0, 0xc1, 0xaf, 0x61, 0x76, 0x76, + 0x69, 0xb7, 0x12, 0x3c, 0x18, 0x2f, 0x9b, 0x79, 0x7e, 0xcf, 0xef, 0xf9, 0x3d, 0xff, 0x76, 0x06, + 0xdc, 0x1b, 0x05, 0x8a, 0xbc, 0x66, 0xf6, 0x98, 0x28, 0x16, 0x9c, 0x0b, 0x6a, 0x9f, 0xed, 0xf4, + 0x99, 0x22, 0x3b, 0x53, 0xc0, 0x1a, 0x8d, 0xa5, 0x92, 0x70, 0x35, 0xe2, 0x59, 0x53, 0x38, 0xe6, + 0xad, 0xad, 0x9c, 0xc8, 0x13, 0xa9, 0x39, 0x76, 0x78, 0x8a, 0xe8, 0x6b, 0x8d, 0x58, 0xf6, 0x94, + 0xbf, 0x99, 0x70, 0x5f, 0x9f, 0x79, 0x7f, 0x26, 0x3e, 0x0f, 0xc7, 0x31, 0xff, 0x92, 0x21, 0x17, + 0xd2, 0xd6, 0xdf, 0x08, 0xaa, 0xbd, 0x4f, 0x83, 0xfc, 0x53, 0x19, 0xa8, 0xd6, 0x80, 0x70, 0x01, + 0x97, 0xc1, 0x02, 0xc7, 0x7e, 0xd9, 0xa8, 0x1a, 0xf5, 0x8c, 0x97, 0xe6, 0x2e, 0x5c, 0x03, 0x79, + 0x1a, 0x7a, 0x70, 0x08, 0xa7, 0xab, 0x46, 0x3d, 0xef, 0xe5, 0x34, 0x80, 0x5c, 0xb8, 0x09, 0x8a, + 0x54, 0x0a, 0xc1, 0xa8, 0xe2, 0x32, 0x22, 0x2c, 0x68, 0x42, 0x61, 0x86, 0x22, 0x17, 0xbe, 0x00, + 0x4b, 0x1c, 0x53, 0x4c, 0x30, 0xa1, 0x54, 0x4e, 0x84, 0x2a, 0x67, 0xaa, 0x46, 0xdd, 0x6c, 0x6c, + 0x59, 0x71, 0xbb, 0xbf, 0x14, 0x1a, 0xd7, 0x6f, 0xa1, 0x96, 0xe3, 0x44, 0x01, 0xcd, 0xfc, 0xc5, + 0xb7, 0x8d, 0xd4, 0xa7, 0x1f, 0x9f, 0xb7, 0x0d, 0x0f, 0xf0, 0x29, 0x0c, 0xf7, 0xc0, 0xe2, 0x31, + 0x23, 0x6a, 0x32, 0x66, 0x41, 0xf9, 0x1f, 0xad, 0x59, 0xb5, 0xee, 0x18, 0xa1, 0xf5, 0x24, 0x22, + 0x26, 0xa5, 0xa6, 0xc1, 0xb5, 0x2f, 0x06, 0xc8, 0xc5, 0x04, 0xf8, 0x0a, 0xc0, 0xa8, 0x20, 0xac, + 0x95, 0x30, 0xc7, 0x7d, 0x4c, 0xf5, 0x3c, 0xcc, 0xc6, 0xe6, 0x9d, 0xf2, 0xfb, 0x3a, 0xa4, 0x1b, + 0x3a, 0x93, 0x29, 0x8a, 0xa7, 0x33, 0x1c, 0x35, 0x5b, 0xd0, 0x03, 0x85, 0xa4, 0xb8, 0x9e, 0xe7, + 0x1f, 0xc8, 0x9a, 0x09, 0xd9, 0xda, 0xc7, 0x34, 0x30, 0x13, 0x3c, 0xb8, 0x07, 0x0a, 0x71, 0x63, + 0x58, 0x9d, 0x8f, 0x98, 0x2e, 0xbd, 0xf8, 0x9b, 0x1c, 0x71, 0xe3, 0xbd, 0xf3, 0x11, 0xf3, 0xcc, + 0xe3, 0x99, 0x01, 0xcb, 0x60, 0x91, 0x4a, 0x9f, 0x4d, 0x17, 0x9f, 0xf1, 0xb2, 0xa1, 0x8d, 0x5c, + 0x78, 0x08, 0x96, 0xb8, 0x08, 0x14, 0x11, 0x8a, 0x93, 0x70, 0xc9, 0x7a, 0xed, 0xc5, 0xc6, 0xfd, + 0x3b, 0x73, 0xa0, 0x24, 0xbb, 0xab, 0x88, 0x62, 0xde, 0xbc, 0x02, 0xdc, 0x02, 0x25, 0x2a, 0x85, + 0x1a, 0x13, 0xaa, 0x30, 0xf1, 0xfd, 0x31, 0x0b, 0x02, 0xfd, 0x9f, 0xe4, 0xbd, 0xe5, 0x1b, 0xdc, + 0x89, 0x60, 0xf8, 0x1f, 0xc8, 0xfa, 0x4c, 0xc8, 0x61, 0xb8, 0xf4, 0x85, 0x7a, 0xde, 0x8b, 0x2d, + 0x58, 0x06, 0x39, 0x26, 0x48, 0xff, 0x94, 0xf9, 0xe5, 0x6c, 0xd5, 0xa8, 0x2f, 0x7a, 0x37, 0x66, + 0xed, 0x2d, 0xc8, 0xa1, 0x96, 0x73, 0xc0, 0x86, 0xf2, 0xef, 0x4d, 0xe7, 0x7f, 0x50, 0x1c, 0xc8, + 0x40, 0xe1, 0xf9, 0xcb, 0x91, 0xf1, 0xcc, 0xc1, 0xcd, 0x5d, 0x42, 0xee, 0xb6, 0x04, 0xf0, 0x76, + 0xeb, 0x70, 0x03, 0xac, 0xa3, 0x76, 0xb7, 0xe7, 0xb4, 0x7b, 0xc8, 0xe9, 0xa1, 0x4e, 0x1b, 0xb7, + 0x3b, 0x3d, 0x8c, 0xda, 0x28, 0x34, 0x77, 0xdd, 0x52, 0x0a, 0xae, 0x83, 0xd5, 0x79, 0xc2, 0xcc, + 0x69, 0xdc, 0x76, 0xb6, 0x3a, 0x07, 0xcf, 0xf7, 0x77, 0x43, 0x67, 0x7a, 0xfb, 0x11, 0x30, 0x13, + 0x15, 0xc3, 0x15, 0x50, 0xda, 0x47, 0x87, 0x47, 0xc8, 0xc5, 0xdd, 0x9e, 0xf3, 0x6c, 0x17, 0xa3, + 0x66, 0xab, 0x94, 0x82, 0x25, 0x50, 0x48, 0xa2, 0x25, 0xa3, 0x79, 0x74, 0x71, 0x55, 0x31, 0x2e, + 0xaf, 0x2a, 0xc6, 0xf7, 0xab, 0x8a, 0xf1, 0xe1, 0xba, 0x92, 0xba, 0xbc, 0xae, 0xa4, 0xbe, 0x5e, + 0x57, 0x52, 0x2f, 0x1f, 0x9f, 0x70, 0x35, 0x98, 0xf4, 0x2d, 0x2a, 0x87, 0xf6, 0x88, 0x8d, 0x03, + 0x1e, 0x28, 0x26, 0x28, 0xeb, 0x08, 0x66, 0x47, 0x23, 0x7b, 0x20, 0x88, 0xe2, 0x67, 0xcc, 0x3e, + 0x6b, 0xd8, 0xef, 0x66, 0x2f, 0x5c, 0x38, 0xdb, 0xa0, 0x9f, 0xd5, 0x2f, 0xcc, 0xc3, 0x9f, 0x01, + 0x00, 0x00, 0xff, 0xff, 0x91, 0xa4, 0xe0, 0x5b, 0x01, 0x05, 0x00, 0x00, +} + +func (m *HostChain) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *HostChain) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *HostChain) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + { + size, err := m.Features.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintRatesync(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x2a + { + size, err := m.ICAAccount.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintRatesync(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x22 + if len(m.ConnectionID) > 0 { + i -= len(m.ConnectionID) + copy(dAtA[i:], m.ConnectionID) + i = encodeVarintRatesync(dAtA, i, uint64(len(m.ConnectionID))) + i-- + dAtA[i] = 0x1a + } + if len(m.ChainID) > 0 { + i -= len(m.ChainID) + copy(dAtA[i:], m.ChainID) + i = encodeVarintRatesync(dAtA, i, uint64(len(m.ChainID))) + i-- + dAtA[i] = 0x12 + } + if m.ID != 0 { + i = encodeVarintRatesync(dAtA, i, uint64(m.ID)) + i-- + dAtA[i] = 0x8 + } + return len(dAtA) - i, nil +} + +func (m *Feature) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *Feature) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *Feature) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + { + size, err := m.LiquidStake.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintRatesync(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x12 + { + size, err := m.LiquidStakeIBC.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintRatesync(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0xa + return len(dAtA) - i, nil +} + +func (m *LiquidStake) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *LiquidStake) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *LiquidStake) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if m.Enabled { + i-- + if m.Enabled { + dAtA[i] = 1 + } else { + dAtA[i] = 0 + } + i-- + dAtA[i] = 0x30 + } + if len(m.Denoms) > 0 { + for iNdEx := len(m.Denoms) - 1; iNdEx >= 0; iNdEx-- { + i -= len(m.Denoms[iNdEx]) + copy(dAtA[i:], m.Denoms[iNdEx]) + i = encodeVarintRatesync(dAtA, i, uint64(len(m.Denoms[iNdEx]))) + i-- + dAtA[i] = 0x2a + } + } + if len(m.ContractAddress) > 0 { + i -= len(m.ContractAddress) + copy(dAtA[i:], m.ContractAddress) + i = encodeVarintRatesync(dAtA, i, uint64(len(m.ContractAddress))) + i-- + dAtA[i] = 0x22 + } + if m.Instantiation != 0 { + i = encodeVarintRatesync(dAtA, i, uint64(m.Instantiation)) + i-- + dAtA[i] = 0x18 + } + if m.CodeID != 0 { + i = encodeVarintRatesync(dAtA, i, uint64(m.CodeID)) + i-- + dAtA[i] = 0x10 + } + if m.FeatureType != 0 { + i = encodeVarintRatesync(dAtA, i, uint64(m.FeatureType)) + i-- + dAtA[i] = 0x8 + } + return len(dAtA) - i, nil +} + +func (m *ICAMemo) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *ICAMemo) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *ICAMemo) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if m.HostChainID != 0 { + i = encodeVarintRatesync(dAtA, i, uint64(m.HostChainID)) + i-- + dAtA[i] = 0x10 + } + if m.FeatureType != 0 { + i = encodeVarintRatesync(dAtA, i, uint64(m.FeatureType)) + i-- + dAtA[i] = 0x8 + } + return len(dAtA) - i, nil +} + +func encodeVarintRatesync(dAtA []byte, offset int, v uint64) int { + offset -= sovRatesync(v) + base := offset + for v >= 1<<7 { + dAtA[offset] = uint8(v&0x7f | 0x80) + v >>= 7 + offset++ + } + dAtA[offset] = uint8(v) + return base +} +func (m *HostChain) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if m.ID != 0 { + n += 1 + sovRatesync(uint64(m.ID)) + } + l = len(m.ChainID) + if l > 0 { + n += 1 + l + sovRatesync(uint64(l)) + } + l = len(m.ConnectionID) + if l > 0 { + n += 1 + l + sovRatesync(uint64(l)) + } + l = m.ICAAccount.Size() + n += 1 + l + sovRatesync(uint64(l)) + l = m.Features.Size() + n += 1 + l + sovRatesync(uint64(l)) + return n +} + +func (m *Feature) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = m.LiquidStakeIBC.Size() + n += 1 + l + sovRatesync(uint64(l)) + l = m.LiquidStake.Size() + n += 1 + l + sovRatesync(uint64(l)) + return n +} + +func (m *LiquidStake) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if m.FeatureType != 0 { + n += 1 + sovRatesync(uint64(m.FeatureType)) + } + if m.CodeID != 0 { + n += 1 + sovRatesync(uint64(m.CodeID)) + } + if m.Instantiation != 0 { + n += 1 + sovRatesync(uint64(m.Instantiation)) + } + l = len(m.ContractAddress) + if l > 0 { + n += 1 + l + sovRatesync(uint64(l)) + } + if len(m.Denoms) > 0 { + for _, s := range m.Denoms { + l = len(s) + n += 1 + l + sovRatesync(uint64(l)) + } + } + if m.Enabled { + n += 2 + } + return n +} + +func (m *ICAMemo) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if m.FeatureType != 0 { + n += 1 + sovRatesync(uint64(m.FeatureType)) + } + if m.HostChainID != 0 { + n += 1 + sovRatesync(uint64(m.HostChainID)) + } + return n +} + +func sovRatesync(x uint64) (n int) { + return (math_bits.Len64(x|1) + 6) / 7 +} +func sozRatesync(x uint64) (n int) { + return sovRatesync(uint64((x << 1) ^ uint64((int64(x) >> 63)))) +} +func (m *HostChain) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowRatesync + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: HostChain: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: HostChain: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field ID", wireType) + } + m.ID = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowRatesync + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.ID |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field ChainID", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowRatesync + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthRatesync + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthRatesync + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.ChainID = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 3: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field ConnectionID", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowRatesync + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthRatesync + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthRatesync + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.ConnectionID = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 4: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field ICAAccount", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowRatesync + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthRatesync + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthRatesync + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if err := m.ICAAccount.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 5: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Features", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowRatesync + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthRatesync + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthRatesync + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if err := m.Features.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipRatesync(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthRatesync + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *Feature) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowRatesync + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: Feature: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: Feature: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field LiquidStakeIBC", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowRatesync + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthRatesync + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthRatesync + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if err := m.LiquidStakeIBC.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field LiquidStake", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowRatesync + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthRatesync + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthRatesync + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if err := m.LiquidStake.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipRatesync(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthRatesync + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *LiquidStake) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowRatesync + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: LiquidStake: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: LiquidStake: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field FeatureType", wireType) + } + m.FeatureType = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowRatesync + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.FeatureType |= FeatureType(b&0x7F) << shift + if b < 0x80 { + break + } + } + case 2: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field CodeID", wireType) + } + m.CodeID = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowRatesync + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.CodeID |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + case 3: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field Instantiation", wireType) + } + m.Instantiation = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowRatesync + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.Instantiation |= InstantiationState(b&0x7F) << shift + if b < 0x80 { + break + } + } + case 4: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field ContractAddress", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowRatesync + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthRatesync + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthRatesync + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.ContractAddress = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 5: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Denoms", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowRatesync + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthRatesync + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthRatesync + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Denoms = append(m.Denoms, string(dAtA[iNdEx:postIndex])) + iNdEx = postIndex + case 6: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field Enabled", wireType) + } + var v int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowRatesync + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + v |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + m.Enabled = bool(v != 0) + default: + iNdEx = preIndex + skippy, err := skipRatesync(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthRatesync + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *ICAMemo) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowRatesync + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: ICAMemo: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: ICAMemo: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field FeatureType", wireType) + } + m.FeatureType = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowRatesync + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.FeatureType |= FeatureType(b&0x7F) << shift + if b < 0x80 { + break + } + } + case 2: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field HostChainID", wireType) + } + m.HostChainID = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowRatesync + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.HostChainID |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + default: + iNdEx = preIndex + skippy, err := skipRatesync(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthRatesync + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func skipRatesync(dAtA []byte) (n int, err error) { + l := len(dAtA) + iNdEx := 0 + depth := 0 + for iNdEx < l { + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowRatesync + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= (uint64(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + wireType := int(wire & 0x7) + switch wireType { + case 0: + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowRatesync + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + iNdEx++ + if dAtA[iNdEx-1] < 0x80 { + break + } + } + case 1: + iNdEx += 8 + case 2: + var length int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowRatesync + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + length |= (int(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + if length < 0 { + return 0, ErrInvalidLengthRatesync + } + iNdEx += length + case 3: + depth++ + case 4: + if depth == 0 { + return 0, ErrUnexpectedEndOfGroupRatesync + } + depth-- + case 5: + iNdEx += 4 + default: + return 0, fmt.Errorf("proto: illegal wireType %d", wireType) + } + if iNdEx < 0 { + return 0, ErrInvalidLengthRatesync + } + if depth == 0 { + return iNdEx, nil + } + } + return 0, io.ErrUnexpectedEOF +} + +var ( + ErrInvalidLengthRatesync = fmt.Errorf("proto: negative length found during unmarshaling") + ErrIntOverflowRatesync = fmt.Errorf("proto: integer overflow") + ErrUnexpectedEndOfGroupRatesync = fmt.Errorf("proto: unexpected end of group") +) diff --git a/x/ratesync/types/tx.pb.go b/x/ratesync/types/tx.pb.go new file mode 100644 index 000000000..89e929a30 --- /dev/null +++ b/x/ratesync/types/tx.pb.go @@ -0,0 +1,1752 @@ +// Code generated by protoc-gen-gogo. DO NOT EDIT. +// source: pstake/ratesync/v1beta1/tx.proto + +package types + +import ( + context "context" + fmt "fmt" + _ "github.com/cosmos/cosmos-proto" + _ "github.com/cosmos/cosmos-sdk/types" + _ "github.com/cosmos/cosmos-sdk/types/msgservice" + _ "github.com/cosmos/cosmos-sdk/types/tx/amino" + _ "github.com/cosmos/gogoproto/gogoproto" + grpc1 "github.com/cosmos/gogoproto/grpc" + proto "github.com/cosmos/gogoproto/proto" + grpc "google.golang.org/grpc" + codes "google.golang.org/grpc/codes" + status "google.golang.org/grpc/status" + io "io" + math "math" + math_bits "math/bits" +) + +// Reference imports to suppress errors if they are not otherwise used. +var _ = proto.Marshal +var _ = fmt.Errorf +var _ = math.Inf + +// This is a compile-time assertion to ensure that this generated file +// is compatible with the proto package it is being compiled against. +// A compilation error at this line likely means your copy of the +// proto package needs to be updated. +const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package + +type MsgCreateHostChain struct { + Authority string `protobuf:"bytes,1,opt,name=authority,proto3" json:"authority,omitempty"` + HostChain HostChain `protobuf:"bytes,2,opt,name=host_chain,json=hostChain,proto3" json:"host_chain"` +} + +func (m *MsgCreateHostChain) Reset() { *m = MsgCreateHostChain{} } +func (m *MsgCreateHostChain) String() string { return proto.CompactTextString(m) } +func (*MsgCreateHostChain) ProtoMessage() {} +func (*MsgCreateHostChain) Descriptor() ([]byte, []int) { + return fileDescriptor_6173f0b1d1f1f64e, []int{0} +} +func (m *MsgCreateHostChain) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *MsgCreateHostChain) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_MsgCreateHostChain.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *MsgCreateHostChain) XXX_Merge(src proto.Message) { + xxx_messageInfo_MsgCreateHostChain.Merge(m, src) +} +func (m *MsgCreateHostChain) XXX_Size() int { + return m.Size() +} +func (m *MsgCreateHostChain) XXX_DiscardUnknown() { + xxx_messageInfo_MsgCreateHostChain.DiscardUnknown(m) +} + +var xxx_messageInfo_MsgCreateHostChain proto.InternalMessageInfo + +func (m *MsgCreateHostChain) GetAuthority() string { + if m != nil { + return m.Authority + } + return "" +} + +func (m *MsgCreateHostChain) GetHostChain() HostChain { + if m != nil { + return m.HostChain + } + return HostChain{} +} + +type MsgCreateHostChainResponse struct { + ID uint64 `protobuf:"varint,1,opt,name=i_d,json=iD,proto3" json:"i_d,omitempty"` +} + +func (m *MsgCreateHostChainResponse) Reset() { *m = MsgCreateHostChainResponse{} } +func (m *MsgCreateHostChainResponse) String() string { return proto.CompactTextString(m) } +func (*MsgCreateHostChainResponse) ProtoMessage() {} +func (*MsgCreateHostChainResponse) Descriptor() ([]byte, []int) { + return fileDescriptor_6173f0b1d1f1f64e, []int{1} +} +func (m *MsgCreateHostChainResponse) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *MsgCreateHostChainResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_MsgCreateHostChainResponse.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *MsgCreateHostChainResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_MsgCreateHostChainResponse.Merge(m, src) +} +func (m *MsgCreateHostChainResponse) XXX_Size() int { + return m.Size() +} +func (m *MsgCreateHostChainResponse) XXX_DiscardUnknown() { + xxx_messageInfo_MsgCreateHostChainResponse.DiscardUnknown(m) +} + +var xxx_messageInfo_MsgCreateHostChainResponse proto.InternalMessageInfo + +func (m *MsgCreateHostChainResponse) GetID() uint64 { + if m != nil { + return m.ID + } + return 0 +} + +type MsgUpdateHostChain struct { + Authority string `protobuf:"bytes,1,opt,name=authority,proto3" json:"authority,omitempty"` + HostChain HostChain `protobuf:"bytes,2,opt,name=host_chain,json=hostChain,proto3" json:"host_chain"` +} + +func (m *MsgUpdateHostChain) Reset() { *m = MsgUpdateHostChain{} } +func (m *MsgUpdateHostChain) String() string { return proto.CompactTextString(m) } +func (*MsgUpdateHostChain) ProtoMessage() {} +func (*MsgUpdateHostChain) Descriptor() ([]byte, []int) { + return fileDescriptor_6173f0b1d1f1f64e, []int{2} +} +func (m *MsgUpdateHostChain) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *MsgUpdateHostChain) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_MsgUpdateHostChain.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *MsgUpdateHostChain) XXX_Merge(src proto.Message) { + xxx_messageInfo_MsgUpdateHostChain.Merge(m, src) +} +func (m *MsgUpdateHostChain) XXX_Size() int { + return m.Size() +} +func (m *MsgUpdateHostChain) XXX_DiscardUnknown() { + xxx_messageInfo_MsgUpdateHostChain.DiscardUnknown(m) +} + +var xxx_messageInfo_MsgUpdateHostChain proto.InternalMessageInfo + +func (m *MsgUpdateHostChain) GetAuthority() string { + if m != nil { + return m.Authority + } + return "" +} + +func (m *MsgUpdateHostChain) GetHostChain() HostChain { + if m != nil { + return m.HostChain + } + return HostChain{} +} + +type MsgUpdateHostChainResponse struct { +} + +func (m *MsgUpdateHostChainResponse) Reset() { *m = MsgUpdateHostChainResponse{} } +func (m *MsgUpdateHostChainResponse) String() string { return proto.CompactTextString(m) } +func (*MsgUpdateHostChainResponse) ProtoMessage() {} +func (*MsgUpdateHostChainResponse) Descriptor() ([]byte, []int) { + return fileDescriptor_6173f0b1d1f1f64e, []int{3} +} +func (m *MsgUpdateHostChainResponse) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *MsgUpdateHostChainResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_MsgUpdateHostChainResponse.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *MsgUpdateHostChainResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_MsgUpdateHostChainResponse.Merge(m, src) +} +func (m *MsgUpdateHostChainResponse) XXX_Size() int { + return m.Size() +} +func (m *MsgUpdateHostChainResponse) XXX_DiscardUnknown() { + xxx_messageInfo_MsgUpdateHostChainResponse.DiscardUnknown(m) +} + +var xxx_messageInfo_MsgUpdateHostChainResponse proto.InternalMessageInfo + +type MsgDeleteHostChain struct { + Authority string `protobuf:"bytes,1,opt,name=authority,proto3" json:"authority,omitempty"` + ID uint64 `protobuf:"varint,2,opt,name=i_d,json=iD,proto3" json:"i_d,omitempty"` +} + +func (m *MsgDeleteHostChain) Reset() { *m = MsgDeleteHostChain{} } +func (m *MsgDeleteHostChain) String() string { return proto.CompactTextString(m) } +func (*MsgDeleteHostChain) ProtoMessage() {} +func (*MsgDeleteHostChain) Descriptor() ([]byte, []int) { + return fileDescriptor_6173f0b1d1f1f64e, []int{4} +} +func (m *MsgDeleteHostChain) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *MsgDeleteHostChain) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_MsgDeleteHostChain.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *MsgDeleteHostChain) XXX_Merge(src proto.Message) { + xxx_messageInfo_MsgDeleteHostChain.Merge(m, src) +} +func (m *MsgDeleteHostChain) XXX_Size() int { + return m.Size() +} +func (m *MsgDeleteHostChain) XXX_DiscardUnknown() { + xxx_messageInfo_MsgDeleteHostChain.DiscardUnknown(m) +} + +var xxx_messageInfo_MsgDeleteHostChain proto.InternalMessageInfo + +func (m *MsgDeleteHostChain) GetAuthority() string { + if m != nil { + return m.Authority + } + return "" +} + +func (m *MsgDeleteHostChain) GetID() uint64 { + if m != nil { + return m.ID + } + return 0 +} + +type MsgDeleteHostChainResponse struct { +} + +func (m *MsgDeleteHostChainResponse) Reset() { *m = MsgDeleteHostChainResponse{} } +func (m *MsgDeleteHostChainResponse) String() string { return proto.CompactTextString(m) } +func (*MsgDeleteHostChainResponse) ProtoMessage() {} +func (*MsgDeleteHostChainResponse) Descriptor() ([]byte, []int) { + return fileDescriptor_6173f0b1d1f1f64e, []int{5} +} +func (m *MsgDeleteHostChainResponse) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *MsgDeleteHostChainResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_MsgDeleteHostChainResponse.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *MsgDeleteHostChainResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_MsgDeleteHostChainResponse.Merge(m, src) +} +func (m *MsgDeleteHostChainResponse) XXX_Size() int { + return m.Size() +} +func (m *MsgDeleteHostChainResponse) XXX_DiscardUnknown() { + xxx_messageInfo_MsgDeleteHostChainResponse.DiscardUnknown(m) +} + +var xxx_messageInfo_MsgDeleteHostChainResponse proto.InternalMessageInfo + +type MsgUpdateParams struct { + Authority string `protobuf:"bytes,1,opt,name=authority,proto3" json:"authority,omitempty"` + Params Params `protobuf:"bytes,2,opt,name=params,proto3" json:"params"` +} + +func (m *MsgUpdateParams) Reset() { *m = MsgUpdateParams{} } +func (m *MsgUpdateParams) String() string { return proto.CompactTextString(m) } +func (*MsgUpdateParams) ProtoMessage() {} +func (*MsgUpdateParams) Descriptor() ([]byte, []int) { + return fileDescriptor_6173f0b1d1f1f64e, []int{6} +} +func (m *MsgUpdateParams) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *MsgUpdateParams) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_MsgUpdateParams.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *MsgUpdateParams) XXX_Merge(src proto.Message) { + xxx_messageInfo_MsgUpdateParams.Merge(m, src) +} +func (m *MsgUpdateParams) XXX_Size() int { + return m.Size() +} +func (m *MsgUpdateParams) XXX_DiscardUnknown() { + xxx_messageInfo_MsgUpdateParams.DiscardUnknown(m) +} + +var xxx_messageInfo_MsgUpdateParams proto.InternalMessageInfo + +func (m *MsgUpdateParams) GetAuthority() string { + if m != nil { + return m.Authority + } + return "" +} + +func (m *MsgUpdateParams) GetParams() Params { + if m != nil { + return m.Params + } + return Params{} +} + +type MsgUpdateParamsResponse struct { +} + +func (m *MsgUpdateParamsResponse) Reset() { *m = MsgUpdateParamsResponse{} } +func (m *MsgUpdateParamsResponse) String() string { return proto.CompactTextString(m) } +func (*MsgUpdateParamsResponse) ProtoMessage() {} +func (*MsgUpdateParamsResponse) Descriptor() ([]byte, []int) { + return fileDescriptor_6173f0b1d1f1f64e, []int{7} +} +func (m *MsgUpdateParamsResponse) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *MsgUpdateParamsResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_MsgUpdateParamsResponse.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *MsgUpdateParamsResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_MsgUpdateParamsResponse.Merge(m, src) +} +func (m *MsgUpdateParamsResponse) XXX_Size() int { + return m.Size() +} +func (m *MsgUpdateParamsResponse) XXX_DiscardUnknown() { + xxx_messageInfo_MsgUpdateParamsResponse.DiscardUnknown(m) +} + +var xxx_messageInfo_MsgUpdateParamsResponse proto.InternalMessageInfo + +func init() { + proto.RegisterType((*MsgCreateHostChain)(nil), "pstake.ratesync.v1beta1.MsgCreateHostChain") + proto.RegisterType((*MsgCreateHostChainResponse)(nil), "pstake.ratesync.v1beta1.MsgCreateHostChainResponse") + proto.RegisterType((*MsgUpdateHostChain)(nil), "pstake.ratesync.v1beta1.MsgUpdateHostChain") + proto.RegisterType((*MsgUpdateHostChainResponse)(nil), "pstake.ratesync.v1beta1.MsgUpdateHostChainResponse") + proto.RegisterType((*MsgDeleteHostChain)(nil), "pstake.ratesync.v1beta1.MsgDeleteHostChain") + proto.RegisterType((*MsgDeleteHostChainResponse)(nil), "pstake.ratesync.v1beta1.MsgDeleteHostChainResponse") + proto.RegisterType((*MsgUpdateParams)(nil), "pstake.ratesync.v1beta1.MsgUpdateParams") + proto.RegisterType((*MsgUpdateParamsResponse)(nil), "pstake.ratesync.v1beta1.MsgUpdateParamsResponse") +} + +func init() { proto.RegisterFile("pstake/ratesync/v1beta1/tx.proto", fileDescriptor_6173f0b1d1f1f64e) } + +var fileDescriptor_6173f0b1d1f1f64e = []byte{ + // 551 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xd4, 0x54, 0x31, 0x8f, 0x12, 0x41, + 0x14, 0x66, 0xc1, 0x5c, 0xc2, 0x68, 0x42, 0xdc, 0x5c, 0x02, 0x47, 0xcc, 0x42, 0x36, 0xc6, 0x10, + 0x0c, 0x3b, 0xc2, 0x45, 0x8b, 0xb3, 0x92, 0xbb, 0xc2, 0xc2, 0x8b, 0x06, 0x73, 0x8d, 0x0d, 0x19, + 0x96, 0xc9, 0xee, 0xa8, 0xbb, 0xb3, 0xd9, 0x37, 0x47, 0x8e, 0xd6, 0xd2, 0xca, 0xc2, 0x1f, 0x61, + 0x49, 0xe1, 0x1f, 0xb0, 0xbb, 0x12, 0xad, 0xac, 0x8c, 0x81, 0x82, 0xbf, 0x61, 0xd8, 0x99, 0x5d, + 0x74, 0xc8, 0xe2, 0x69, 0x6c, 0x6c, 0x80, 0x79, 0xf3, 0xcd, 0xfb, 0xbe, 0xf7, 0xde, 0xf7, 0x40, + 0xcd, 0x08, 0x04, 0x79, 0x45, 0x71, 0x4c, 0x04, 0x85, 0x69, 0xe8, 0xe2, 0x49, 0x77, 0x44, 0x05, + 0xe9, 0x62, 0x71, 0xe1, 0x44, 0x31, 0x17, 0xdc, 0xac, 0x4a, 0x84, 0x93, 0x22, 0x1c, 0x85, 0xa8, + 0x57, 0x5d, 0x0e, 0x01, 0x07, 0x1c, 0x80, 0x87, 0x27, 0xdd, 0xf5, 0x97, 0x7c, 0x51, 0xb7, 0xd4, + 0xc5, 0x88, 0x00, 0xcd, 0xf2, 0xb9, 0x9c, 0x85, 0xea, 0xfe, 0x26, 0x09, 0x58, 0xc8, 0x71, 0xf2, + 0xa9, 0x42, 0x07, 0xf2, 0xc9, 0x30, 0x39, 0x61, 0x79, 0x50, 0x57, 0xb7, 0xf3, 0x14, 0x46, 0x24, + 0x26, 0x41, 0x8a, 0xba, 0x93, 0x87, 0xca, 0x64, 0x4b, 0xdc, 0xbe, 0xc7, 0x3d, 0x2e, 0x59, 0xd6, + 0xbf, 0x64, 0xd4, 0xfe, 0x6c, 0x20, 0xf3, 0x14, 0xbc, 0xe3, 0x98, 0x12, 0x41, 0x1f, 0x73, 0x10, + 0xc7, 0x3e, 0x61, 0xa1, 0xf9, 0x00, 0x95, 0xc9, 0xb9, 0xf0, 0x79, 0xcc, 0xc4, 0xb4, 0x66, 0x34, + 0x8d, 0x56, 0xb9, 0x5f, 0xfb, 0xf2, 0xb1, 0xb3, 0xaf, 0xf4, 0x3d, 0x1a, 0x8f, 0x63, 0x0a, 0xf0, + 0x5c, 0xc4, 0x2c, 0xf4, 0x06, 0x1b, 0xa8, 0xf9, 0x04, 0x21, 0x9f, 0x83, 0x18, 0xba, 0xeb, 0x2c, + 0xb5, 0x62, 0xd3, 0x68, 0x5d, 0xef, 0xd9, 0x4e, 0x4e, 0x1f, 0x9d, 0x8c, 0xaf, 0x5f, 0xbe, 0xfc, + 0xd6, 0x28, 0x7c, 0x58, 0xcd, 0xda, 0xc6, 0xa0, 0xec, 0xa7, 0xd1, 0xa3, 0xfb, 0x6f, 0x56, 0xb3, + 0xf6, 0x26, 0xfb, 0xdb, 0xd5, 0xac, 0x6d, 0xeb, 0xd5, 0x6e, 0x8b, 0xb7, 0x3b, 0xa8, 0xbe, 0x1d, + 0x1d, 0x50, 0x88, 0x78, 0x08, 0xd4, 0xac, 0xa0, 0x12, 0x1b, 0x8e, 0x93, 0xa2, 0xae, 0x0d, 0x8a, + 0xec, 0x24, 0x6d, 0xc1, 0x59, 0x34, 0xfe, 0x7f, 0x5b, 0xa0, 0x89, 0xb7, 0x6f, 0x25, 0x2d, 0xd0, + 0xa2, 0x69, 0x0b, 0xec, 0xf7, 0xb2, 0xe2, 0x13, 0xfa, 0x9a, 0xfe, 0x8b, 0x8a, 0x55, 0x47, 0x8b, + 0x69, 0x47, 0xaf, 0x2a, 0x5a, 0xe3, 0x57, 0xa2, 0xb5, 0x68, 0x26, 0xfa, 0x93, 0x81, 0x2a, 0x59, + 0x4d, 0xcf, 0x92, 0x0d, 0xf8, 0x6b, 0xc5, 0x7d, 0xb4, 0x27, 0x77, 0x48, 0xcd, 0xa7, 0x91, 0x3b, + 0x1f, 0x49, 0xf4, 0xf3, 0x70, 0xd4, 0xcb, 0xa3, 0xde, 0x76, 0x91, 0x8d, 0xdc, 0xc9, 0xc8, 0x34, + 0xf6, 0x01, 0xaa, 0x6a, 0xa1, 0xb4, 0xbc, 0xde, 0xbc, 0x84, 0x4a, 0xa7, 0xe0, 0x99, 0x80, 0x2a, + 0xfa, 0x32, 0xde, 0xcd, 0x55, 0xb7, 0x6d, 0xf3, 0xfa, 0xe1, 0x1f, 0x80, 0xb3, 0x9d, 0x00, 0x54, + 0xd1, 0xed, 0xbf, 0x93, 0x54, 0x03, 0xef, 0x26, 0xcd, 0x71, 0xe1, 0x9a, 0x54, 0x77, 0xe0, 0x4e, + 0x52, 0x0d, 0xbc, 0x9b, 0x34, 0xc7, 0x45, 0xe6, 0x4b, 0x74, 0xe3, 0x17, 0x07, 0xb5, 0x7e, 0xaf, + 0x5c, 0x22, 0xeb, 0xf7, 0xae, 0x8a, 0x4c, 0xb9, 0xfa, 0x67, 0x97, 0x0b, 0xcb, 0x98, 0x2f, 0x2c, + 0xe3, 0xfb, 0xc2, 0x32, 0xde, 0x2d, 0xad, 0xc2, 0x7c, 0x69, 0x15, 0xbe, 0x2e, 0xad, 0xc2, 0x8b, + 0x87, 0x1e, 0x13, 0xfe, 0xf9, 0xc8, 0x71, 0x79, 0x80, 0x23, 0x1a, 0x03, 0x03, 0x41, 0x43, 0x97, + 0x3e, 0x0d, 0x29, 0x96, 0x24, 0x9d, 0x90, 0x08, 0x36, 0xa1, 0x78, 0xd2, 0xc3, 0x17, 0x1b, 0x3b, + 0x89, 0x69, 0x44, 0x61, 0xb4, 0x97, 0xfc, 0x73, 0x1f, 0xfe, 0x08, 0x00, 0x00, 0xff, 0xff, 0xbf, + 0x6c, 0xf7, 0xb8, 0xc1, 0x06, 0x00, 0x00, +} + +// Reference imports to suppress errors if they are not otherwise used. +var _ context.Context +var _ grpc.ClientConn + +// This is a compile-time assertion to ensure that this generated file +// is compatible with the grpc package it is being compiled against. +const _ = grpc.SupportPackageIsVersion4 + +// MsgClient is the client API for Msg service. +// +// For semantics around ctx use and closing/ending streaming RPCs, please refer to https://godoc.org/google.golang.org/grpc#ClientConn.NewStream. +type MsgClient interface { + CreateHostChain(ctx context.Context, in *MsgCreateHostChain, opts ...grpc.CallOption) (*MsgCreateHostChainResponse, error) + UpdateHostChain(ctx context.Context, in *MsgUpdateHostChain, opts ...grpc.CallOption) (*MsgUpdateHostChainResponse, error) + DeleteHostChain(ctx context.Context, in *MsgDeleteHostChain, opts ...grpc.CallOption) (*MsgDeleteHostChainResponse, error) + UpdateParams(ctx context.Context, in *MsgUpdateParams, opts ...grpc.CallOption) (*MsgUpdateParamsResponse, error) +} + +type msgClient struct { + cc grpc1.ClientConn +} + +func NewMsgClient(cc grpc1.ClientConn) MsgClient { + return &msgClient{cc} +} + +func (c *msgClient) CreateHostChain(ctx context.Context, in *MsgCreateHostChain, opts ...grpc.CallOption) (*MsgCreateHostChainResponse, error) { + out := new(MsgCreateHostChainResponse) + err := c.cc.Invoke(ctx, "/pstake.ratesync.v1beta1.Msg/CreateHostChain", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *msgClient) UpdateHostChain(ctx context.Context, in *MsgUpdateHostChain, opts ...grpc.CallOption) (*MsgUpdateHostChainResponse, error) { + out := new(MsgUpdateHostChainResponse) + err := c.cc.Invoke(ctx, "/pstake.ratesync.v1beta1.Msg/UpdateHostChain", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *msgClient) DeleteHostChain(ctx context.Context, in *MsgDeleteHostChain, opts ...grpc.CallOption) (*MsgDeleteHostChainResponse, error) { + out := new(MsgDeleteHostChainResponse) + err := c.cc.Invoke(ctx, "/pstake.ratesync.v1beta1.Msg/DeleteHostChain", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *msgClient) UpdateParams(ctx context.Context, in *MsgUpdateParams, opts ...grpc.CallOption) (*MsgUpdateParamsResponse, error) { + out := new(MsgUpdateParamsResponse) + err := c.cc.Invoke(ctx, "/pstake.ratesync.v1beta1.Msg/UpdateParams", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +// MsgServer is the server API for Msg service. +type MsgServer interface { + CreateHostChain(context.Context, *MsgCreateHostChain) (*MsgCreateHostChainResponse, error) + UpdateHostChain(context.Context, *MsgUpdateHostChain) (*MsgUpdateHostChainResponse, error) + DeleteHostChain(context.Context, *MsgDeleteHostChain) (*MsgDeleteHostChainResponse, error) + UpdateParams(context.Context, *MsgUpdateParams) (*MsgUpdateParamsResponse, error) +} + +// UnimplementedMsgServer can be embedded to have forward compatible implementations. +type UnimplementedMsgServer struct { +} + +func (*UnimplementedMsgServer) CreateHostChain(ctx context.Context, req *MsgCreateHostChain) (*MsgCreateHostChainResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method CreateHostChain not implemented") +} +func (*UnimplementedMsgServer) UpdateHostChain(ctx context.Context, req *MsgUpdateHostChain) (*MsgUpdateHostChainResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method UpdateHostChain not implemented") +} +func (*UnimplementedMsgServer) DeleteHostChain(ctx context.Context, req *MsgDeleteHostChain) (*MsgDeleteHostChainResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method DeleteHostChain not implemented") +} +func (*UnimplementedMsgServer) UpdateParams(ctx context.Context, req *MsgUpdateParams) (*MsgUpdateParamsResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method UpdateParams not implemented") +} + +func RegisterMsgServer(s grpc1.Server, srv MsgServer) { + s.RegisterService(&_Msg_serviceDesc, srv) +} + +func _Msg_CreateHostChain_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(MsgCreateHostChain) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(MsgServer).CreateHostChain(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/pstake.ratesync.v1beta1.Msg/CreateHostChain", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(MsgServer).CreateHostChain(ctx, req.(*MsgCreateHostChain)) + } + return interceptor(ctx, in, info, handler) +} + +func _Msg_UpdateHostChain_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(MsgUpdateHostChain) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(MsgServer).UpdateHostChain(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/pstake.ratesync.v1beta1.Msg/UpdateHostChain", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(MsgServer).UpdateHostChain(ctx, req.(*MsgUpdateHostChain)) + } + return interceptor(ctx, in, info, handler) +} + +func _Msg_DeleteHostChain_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(MsgDeleteHostChain) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(MsgServer).DeleteHostChain(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/pstake.ratesync.v1beta1.Msg/DeleteHostChain", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(MsgServer).DeleteHostChain(ctx, req.(*MsgDeleteHostChain)) + } + return interceptor(ctx, in, info, handler) +} + +func _Msg_UpdateParams_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(MsgUpdateParams) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(MsgServer).UpdateParams(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/pstake.ratesync.v1beta1.Msg/UpdateParams", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(MsgServer).UpdateParams(ctx, req.(*MsgUpdateParams)) + } + return interceptor(ctx, in, info, handler) +} + +var _Msg_serviceDesc = grpc.ServiceDesc{ + ServiceName: "pstake.ratesync.v1beta1.Msg", + HandlerType: (*MsgServer)(nil), + Methods: []grpc.MethodDesc{ + { + MethodName: "CreateHostChain", + Handler: _Msg_CreateHostChain_Handler, + }, + { + MethodName: "UpdateHostChain", + Handler: _Msg_UpdateHostChain_Handler, + }, + { + MethodName: "DeleteHostChain", + Handler: _Msg_DeleteHostChain_Handler, + }, + { + MethodName: "UpdateParams", + Handler: _Msg_UpdateParams_Handler, + }, + }, + Streams: []grpc.StreamDesc{}, + Metadata: "pstake/ratesync/v1beta1/tx.proto", +} + +func (m *MsgCreateHostChain) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *MsgCreateHostChain) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *MsgCreateHostChain) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + { + size, err := m.HostChain.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintTx(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x12 + if len(m.Authority) > 0 { + i -= len(m.Authority) + copy(dAtA[i:], m.Authority) + i = encodeVarintTx(dAtA, i, uint64(len(m.Authority))) + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func (m *MsgCreateHostChainResponse) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *MsgCreateHostChainResponse) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *MsgCreateHostChainResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if m.ID != 0 { + i = encodeVarintTx(dAtA, i, uint64(m.ID)) + i-- + dAtA[i] = 0x8 + } + return len(dAtA) - i, nil +} + +func (m *MsgUpdateHostChain) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *MsgUpdateHostChain) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *MsgUpdateHostChain) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + { + size, err := m.HostChain.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintTx(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x12 + if len(m.Authority) > 0 { + i -= len(m.Authority) + copy(dAtA[i:], m.Authority) + i = encodeVarintTx(dAtA, i, uint64(len(m.Authority))) + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func (m *MsgUpdateHostChainResponse) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *MsgUpdateHostChainResponse) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *MsgUpdateHostChainResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + return len(dAtA) - i, nil +} + +func (m *MsgDeleteHostChain) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *MsgDeleteHostChain) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *MsgDeleteHostChain) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if m.ID != 0 { + i = encodeVarintTx(dAtA, i, uint64(m.ID)) + i-- + dAtA[i] = 0x10 + } + if len(m.Authority) > 0 { + i -= len(m.Authority) + copy(dAtA[i:], m.Authority) + i = encodeVarintTx(dAtA, i, uint64(len(m.Authority))) + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func (m *MsgDeleteHostChainResponse) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *MsgDeleteHostChainResponse) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *MsgDeleteHostChainResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + return len(dAtA) - i, nil +} + +func (m *MsgUpdateParams) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *MsgUpdateParams) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *MsgUpdateParams) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + { + size, err := m.Params.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintTx(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x12 + if len(m.Authority) > 0 { + i -= len(m.Authority) + copy(dAtA[i:], m.Authority) + i = encodeVarintTx(dAtA, i, uint64(len(m.Authority))) + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func (m *MsgUpdateParamsResponse) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *MsgUpdateParamsResponse) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *MsgUpdateParamsResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + return len(dAtA) - i, nil +} + +func encodeVarintTx(dAtA []byte, offset int, v uint64) int { + offset -= sovTx(v) + base := offset + for v >= 1<<7 { + dAtA[offset] = uint8(v&0x7f | 0x80) + v >>= 7 + offset++ + } + dAtA[offset] = uint8(v) + return base +} +func (m *MsgCreateHostChain) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.Authority) + if l > 0 { + n += 1 + l + sovTx(uint64(l)) + } + l = m.HostChain.Size() + n += 1 + l + sovTx(uint64(l)) + return n +} + +func (m *MsgCreateHostChainResponse) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if m.ID != 0 { + n += 1 + sovTx(uint64(m.ID)) + } + return n +} + +func (m *MsgUpdateHostChain) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.Authority) + if l > 0 { + n += 1 + l + sovTx(uint64(l)) + } + l = m.HostChain.Size() + n += 1 + l + sovTx(uint64(l)) + return n +} + +func (m *MsgUpdateHostChainResponse) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + return n +} + +func (m *MsgDeleteHostChain) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.Authority) + if l > 0 { + n += 1 + l + sovTx(uint64(l)) + } + if m.ID != 0 { + n += 1 + sovTx(uint64(m.ID)) + } + return n +} + +func (m *MsgDeleteHostChainResponse) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + return n +} + +func (m *MsgUpdateParams) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.Authority) + if l > 0 { + n += 1 + l + sovTx(uint64(l)) + } + l = m.Params.Size() + n += 1 + l + sovTx(uint64(l)) + return n +} + +func (m *MsgUpdateParamsResponse) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + return n +} + +func sovTx(x uint64) (n int) { + return (math_bits.Len64(x|1) + 6) / 7 +} +func sozTx(x uint64) (n int) { + return sovTx(uint64((x << 1) ^ uint64((int64(x) >> 63)))) +} +func (m *MsgCreateHostChain) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: MsgCreateHostChain: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: MsgCreateHostChain: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Authority", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthTx + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthTx + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Authority = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field HostChain", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthTx + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthTx + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if err := m.HostChain.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipTx(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthTx + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *MsgCreateHostChainResponse) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: MsgCreateHostChainResponse: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: MsgCreateHostChainResponse: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field ID", wireType) + } + m.ID = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.ID |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + default: + iNdEx = preIndex + skippy, err := skipTx(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthTx + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *MsgUpdateHostChain) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: MsgUpdateHostChain: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: MsgUpdateHostChain: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Authority", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthTx + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthTx + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Authority = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field HostChain", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthTx + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthTx + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if err := m.HostChain.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipTx(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthTx + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *MsgUpdateHostChainResponse) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: MsgUpdateHostChainResponse: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: MsgUpdateHostChainResponse: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + default: + iNdEx = preIndex + skippy, err := skipTx(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthTx + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *MsgDeleteHostChain) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: MsgDeleteHostChain: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: MsgDeleteHostChain: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Authority", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthTx + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthTx + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Authority = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 2: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field ID", wireType) + } + m.ID = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.ID |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + default: + iNdEx = preIndex + skippy, err := skipTx(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthTx + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *MsgDeleteHostChainResponse) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: MsgDeleteHostChainResponse: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: MsgDeleteHostChainResponse: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + default: + iNdEx = preIndex + skippy, err := skipTx(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthTx + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *MsgUpdateParams) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: MsgUpdateParams: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: MsgUpdateParams: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Authority", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthTx + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthTx + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Authority = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Params", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthTx + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthTx + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if err := m.Params.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipTx(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthTx + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *MsgUpdateParamsResponse) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: MsgUpdateParamsResponse: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: MsgUpdateParamsResponse: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + default: + iNdEx = preIndex + skippy, err := skipTx(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthTx + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func skipTx(dAtA []byte) (n int, err error) { + l := len(dAtA) + iNdEx := 0 + depth := 0 + for iNdEx < l { + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowTx + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= (uint64(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + wireType := int(wire & 0x7) + switch wireType { + case 0: + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowTx + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + iNdEx++ + if dAtA[iNdEx-1] < 0x80 { + break + } + } + case 1: + iNdEx += 8 + case 2: + var length int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowTx + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + length |= (int(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + if length < 0 { + return 0, ErrInvalidLengthTx + } + iNdEx += length + case 3: + depth++ + case 4: + if depth == 0 { + return 0, ErrUnexpectedEndOfGroupTx + } + depth-- + case 5: + iNdEx += 4 + default: + return 0, fmt.Errorf("proto: illegal wireType %d", wireType) + } + if iNdEx < 0 { + return 0, ErrInvalidLengthTx + } + if depth == 0 { + return iNdEx, nil + } + } + return 0, io.ErrUnexpectedEOF +} + +var ( + ErrInvalidLengthTx = fmt.Errorf("proto: negative length found during unmarshaling") + ErrIntOverflowTx = fmt.Errorf("proto: integer overflow") + ErrUnexpectedEndOfGroupTx = fmt.Errorf("proto: unexpected end of group") +) diff --git a/x/ratesync/types/types.go b/x/ratesync/types/types.go new file mode 100644 index 000000000..c2156c96c --- /dev/null +++ b/x/ratesync/types/types.go @@ -0,0 +1,216 @@ +package types + +import ( + "fmt" + "slices" + "strconv" + "strings" + + "cosmossdk.io/errors" + "github.com/cosmos/cosmos-sdk/types/bech32" + sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" + icatypes "github.com/cosmos/ibc-go/v7/modules/apps/27-interchain-accounts/types" + host "github.com/cosmos/ibc-go/v7/modules/core/24-host" + ibcexported "github.com/cosmos/ibc-go/v7/modules/core/exported" + liquidstakeibctypes "github.com/persistenceOne/pstake-native/v2/x/liquidstakeibc/types" +) + +func (hc HostChain) ValidateBasic() error { + err := host.ConnectionIdentifierValidator(hc.ConnectionID) + if !(err == nil || hc.ConnectionID == ibcexported.LocalhostConnectionID) { + return errors.Wrapf(sdkerrors.ErrInvalidRequest, "hostchain connectionID invalid") + } + + if hc.ICAAccount.Owner != "" { + portID, err := icatypes.NewControllerPortID(hc.ICAAccount.Owner) + if err != nil { + return err + } + err = host.PortIdentifierValidator(portID) + if err != nil { + return err + } + //Make sure it matches default. + _, err = IDFromPortID(portID) + if err != nil { + return err + } + } + + switch hc.ICAAccount.ChannelState { + case liquidstakeibctypes.ICAAccount_ICA_CHANNEL_CREATING: + if hc.ICAAccount.Address != "" { + return fmt.Errorf("ica account address for ICAAccount_ICA_CHANNEL_CREATING should be empty") + } + // No features allowed without ICA account. + if hc.Features.LiquidStake.Enabled == true || hc.Features.LiquidStakeIBC.Enabled == true { + return fmt.Errorf("no features should be enabled without a valid ICA account") + } + case liquidstakeibctypes.ICAAccount_ICA_CHANNEL_CREATED: + if hc.ICAAccount.Address == "" { + return fmt.Errorf("ica account address for ICAAccount_ICA_CHANNEL_CREATED should not be empty") + } + _, _, err = bech32.DecodeAndConvert(hc.ICAAccount.Address) + if err != nil { + return err + } + } + + err = hc.Features.ValdidateBasic() + if err != nil { + return err + } + + return nil +} + +func (hc HostChain) IsActive() bool { + if hc.Features.LiquidStakeIBC.Enabled == true || + hc.Features.LiquidStake.Enabled == true { + return true + } + return false +} + +func (f Feature) ValdidateBasic() error { + if f.LiquidStakeIBC.FeatureType != FeatureType_LIQUID_STAKE_IBC { + return fmt.Errorf("invalid feature type expected %s, got %s", FeatureType_LIQUID_STAKE_IBC, f.LiquidStakeIBC.FeatureType) + } + err := f.LiquidStakeIBC.ValdidateBasic() + if err != nil { + return err + } + + if f.LiquidStake.FeatureType != FeatureType_LIQUID_STAKE { + return fmt.Errorf("invalid feature type expected %s, got %s", FeatureType_LIQUID_STAKE, f.LiquidStake.FeatureType) + } + err = f.LiquidStake.ValdidateBasic() + if err != nil { + return err + } + return nil +} + +func (lsConfig LiquidStake) ValdidateBasic() error { + if lsConfig.CodeID == 0 { + if lsConfig.Instantiation != InstantiationState_INSTANTIATION_NOT_INITIATED { + return fmt.Errorf("config with 0 code id should not have been initiated") + } + } + switch lsConfig.Instantiation { + case InstantiationState_INSTANTIATION_NOT_INITIATED: + if lsConfig.ContractAddress != "" { + return fmt.Errorf("InstantiationState_INSTANTIATION_NOT_INITIATED cannot have contract address") + } + if lsConfig.Enabled == true { + return fmt.Errorf("feature cannot be turned on without instantiation complete") + } + case InstantiationState_INSTANTIATION_INITIATED: + if lsConfig.ContractAddress != "" { + return fmt.Errorf("InstantiationState_INSTANTIATION_INITIATED cannot have contract address") + } + if lsConfig.CodeID == 0 { + return fmt.Errorf("InstantiationState_INSTANTIATION_INITIATED cannot have 0 codeID") + } + if lsConfig.Enabled == true { + return fmt.Errorf("feature cannot be turned on without instantiation complete") + } + case InstantiationState_INSTANTIATION_COMPLETED: + if lsConfig.ContractAddress == "" { + return fmt.Errorf("InstantiationState_INSTANTIATION_COMPLETED cannot have empty contract address") + } + _, _, err := bech32.DecodeAndConvert(lsConfig.ContractAddress) + if err != nil { + return err + } + if lsConfig.CodeID == 0 { + return fmt.Errorf("InstantiationState_INSTANTIATION_COMPLETED cannot have 0 codeID") + } + } + err := ValidateLiquidStakeDenoms(lsConfig.Denoms) + if err != nil { + return err + } + return nil +} +func (lsConfig LiquidStake) AllowsAllDenoms() bool { + if len(lsConfig.Denoms) == 1 && lsConfig.Denoms[0] == LiquidStakeAllowAllDenoms { + return true + } + return false +} +func (lsConfig LiquidStake) AllowsDenom(denom string) bool { + if lsConfig.AllowsAllDenoms() { + return true + } + return slices.Contains(lsConfig.Denoms, denom) +} +func (lsConfig LiquidStake) Equals(l2 LiquidStake) bool { + if lsConfig.CodeID != l2.CodeID { + return false + } + if lsConfig.Instantiation != l2.Instantiation { + return false + } + if lsConfig.ContractAddress != l2.ContractAddress { + return false + } + if !slices.Equal(lsConfig.Denoms, l2.Denoms) { + return false + } + if lsConfig.FeatureType != l2.FeatureType { + return false + } + if lsConfig.Enabled != l2.Enabled { + return false + } + return true +} + +func MustICAPortIDFromOwner(owner string) string { + id, err := icatypes.NewControllerPortID(owner) + if err != nil { + panic(err) + } + return id + +} + +func DefaultPortOwner(id uint64) string { + return fmt.Sprintf("%s%v", DefaultPortOwnerPrefix, id) +} +func OwnerFromPortID(portID string) (string, error) { + prefix := fmt.Sprintf("%s", icatypes.ControllerPortPrefix) + idStr, found := strings.CutPrefix(portID, prefix) + if !found { + return "", fmt.Errorf("invalid portID, expect prefix %s", prefix) + } + + return idStr, nil +} + +func IDFromPortID(portID string) (uint64, error) { + prefix := fmt.Sprintf("%s%s", icatypes.ControllerPortPrefix, DefaultPortOwnerPrefix) + idStr, found := strings.CutPrefix(portID, prefix) + if !found { + return 0, fmt.Errorf("invalid portID, expect prefix %s", prefix) + } + id, err := strconv.ParseUint(idStr, 10, 64) + if err != nil { + return 0, err + } + + return id, nil +} + +func ValidateLiquidStakeDenoms(denoms []string) error { + if len(denoms) == 1 && denoms[0] == LiquidStakeAllowAllDenoms { + return nil + } + for _, denom := range denoms { + if !liquidstakeibctypes.IsLiquidStakingDenom(denom) { + return fmt.Errorf("invalid denom, expected a liquidstaking denom got %s", denom) + } + } + return nil +} diff --git a/x/ratesync/types/types_test.go b/x/ratesync/types/types_test.go new file mode 100644 index 000000000..635aafaa0 --- /dev/null +++ b/x/ratesync/types/types_test.go @@ -0,0 +1,45 @@ +package types + +import ( + liquidstakeibctypes "github.com/persistenceOne/pstake-native/v2/x/liquidstakeibc/types" + "github.com/stretchr/testify/require" + "testing" +) + +func TestTypes(t *testing.T) { + hc := ValidHostChainInMsg(0) + require.NoError(t, hc.ValidateBasic()) + + hc2 := ValidHostChainInMsg(0) + hc2.ConnectionID = "invalid chars $%&/" + require.Error(t, hc2.ValidateBasic()) + + hc2 = ValidHostChainInMsg(0) + hc2.ICAAccount.Owner = DefaultPortOwner(1) + require.NoError(t, hc2.ValidateBasic()) + hc2.ICAAccount.Owner = "anything else" + require.Error(t, hc2.ValidateBasic()) + hc2.ICAAccount.Owner = "pstake_ratesync_notint" + require.Error(t, hc2.ValidateBasic()) + + hc2 = ValidHostChainInMsg(0) + hc2.Features.LiquidStake.Enabled = true + require.Error(t, hc2.ValidateBasic()) + hc2.ICAAccount.Address = "someAddr" + require.Error(t, hc2.ValidateBasic()) + + hc2 = ValidHostChainInMsg(0) + hc2.ICAAccount.ChannelState = liquidstakeibctypes.ICAAccount_ICA_CHANNEL_CREATED + require.Error(t, hc2.ValidateBasic()) + hc2.ICAAccount.Address = "someAddr" + require.Error(t, hc2.ValidateBasic()) + + hc2 = ValidHostChainInMsg(0) + hc2.Features.LiquidStake.FeatureType = FeatureType_LIQUID_STAKE_IBC + require.Error(t, hc2.ValidateBasic()) + + require.False(t, hc2.IsActive()) + hc2.Features.LiquidStake.Enabled = true + require.True(t, hc2.IsActive()) + +}