From 5d1a0a36ae7dac3c6e7b3f04cd4166dd333542fd Mon Sep 17 00:00:00 2001 From: Sai Kumar <17549398+gsk967@users.noreply.github.com> Date: Mon, 30 Jan 2023 22:44:32 +0530 Subject: [PATCH] feat!: ibc transfer quota (#1568) * WIP: add ibc rate limit middleware to ibc transfer * WIP: add cll tx,query cmds 1. add cli queries for rate_limits and params 2. add updateProposal for rate_limits and ibcPause status * WIP: add check rate limits for ibc denom * remove ibc-rate-limits and move rate limits into ibctransfer module * move the umme ibctransfer into ics20 folder * fix: fix the lint * refactor: change the module structure to 'authz' type of cosmos-sdk * remove inflow_limit in rate limits * chore: check the rate limits by exchange rate * add denom exponent to calculate amount in USD * calculating the sent amount with exponent of registerd token * fix: fix the amount calculation * fix: fix the rate-limit reset issue * refactor: update the params 1. add token_quota, total_quota, quota_duration params 2. ibc-transfer token quota checking with token_quota and total_quota params * fix: fix the build * chore: update the limits and quota interval * chore: fix the lint issues * chore: fix the lint issues * chore: addree the pr comments 1. rename ibcratelimit to uibc module 2. update the uibc cli tx and queries 3. fix the quota expires of ibc-transfer * chore: remove the param subspace from uibc * refactor: refactor the proto and logic 1. ibc-transfer status now enum (enabled,disabled,paused) 2. get the exchange from base denom (ibc/xxx) * chore: address the pr comments 1. remove expire time for quota records 2. removed params subspace keys * fix: fix the buf lint * chore: get the exchange price from TokenValue of leverage * chore: convert uToken to baseToken in ibc-transfer quota checking * chore: add typed events for emit events * address the review comments 1. Rename ibc_denom to denom query * refactor the code 1. rename the GovUpdateTransferStatus to GovSetIBCPause 2. address the pr comments * address the pr comments * chore: fix the build issue * chore: add tests for params * fix: fix the update quota params * chore: address the pr comments * chore: fix the lint * address the pr comments++ * address the pr comments * update reset quota * move to Marshal to MustMarshal in uibc * add TODO for ibc middleware acknowledgement * add comment to outflow_sum --------- Co-authored-by: Robert Zaremba --- app/app.go | 103 +- proto/umee/uibc/v1/events.proto | 17 + proto/umee/uibc/v1/genesis.proto | 29 + proto/umee/uibc/v1/query.proto | 44 + proto/umee/uibc/v1/quota.proto | 57 + proto/umee/uibc/v1/tx.proto | 73 + starport.ci.yml | 68 +- x/leverage/README.md | 2 +- x/leverage/keeper/internal_test.go | 3 +- x/leverage/keeper/keeper.go | 4 +- x/uibc/README.md | 1 + x/uibc/client/cli/query.go | 79 ++ x/uibc/client/cli/tx.go | 22 + x/uibc/codec.go | 42 + x/uibc/errors.go | 10 + x/uibc/events.pb.go | 404 ++++++ .../types => uibc}/expected_keepers.go | 10 +- x/uibc/genesis.go | 42 + x/uibc/genesis.pb.go | 481 +++++++ x/{ibctransfer => uibc/ics20}/ibc_module.go | 4 +- .../ics20}/keeper/keeper.go | 6 +- .../ics20}/keeper/keeper_test.go | 4 +- .../ics20}/keeper/util_test.go | 0 x/uibc/keys.go | 36 + x/uibc/module/abci.go | 27 + x/uibc/module/module.go | 148 ++ x/uibc/msg.go | 114 ++ x/uibc/params.go | 81 ++ x/uibc/params_test.go | 29 + x/uibc/query.pb.go | 913 ++++++++++++ x/uibc/query.pb.gw.go | 254 ++++ x/uibc/quota.pb.go | 734 ++++++++++ x/uibc/quota/ibc_module.go | 176 +++ x/uibc/quota/ics4_wrapper.go | 26 + x/uibc/quota/keeper/genesis.go | 42 + x/uibc/quota/keeper/grpc_query.go | 50 + x/uibc/quota/keeper/keeper.go | 51 + x/uibc/quota/keeper/msg_server.go | 45 + x/uibc/quota/keeper/params.go | 30 + x/uibc/quota/keeper/quota.go | 249 ++++ x/uibc/quota/keeper/relay.go | 36 + x/uibc/tx.pb.go | 1235 +++++++++++++++++ 42 files changed, 5713 insertions(+), 68 deletions(-) create mode 100644 proto/umee/uibc/v1/events.proto create mode 100644 proto/umee/uibc/v1/genesis.proto create mode 100644 proto/umee/uibc/v1/query.proto create mode 100644 proto/umee/uibc/v1/quota.proto create mode 100644 proto/umee/uibc/v1/tx.proto create mode 100644 x/uibc/README.md create mode 100644 x/uibc/client/cli/query.go create mode 100644 x/uibc/client/cli/tx.go create mode 100644 x/uibc/codec.go create mode 100644 x/uibc/errors.go create mode 100644 x/uibc/events.pb.go rename x/{ibctransfer/types => uibc}/expected_keepers.go (54%) create mode 100644 x/uibc/genesis.go create mode 100644 x/uibc/genesis.pb.go rename x/{ibctransfer => uibc/ics20}/ibc_module.go (94%) rename x/{ibctransfer => uibc/ics20}/keeper/keeper.go (96%) rename x/{ibctransfer => uibc/ics20}/keeper/keeper_test.go (99%) rename x/{ibctransfer => uibc/ics20}/keeper/util_test.go (100%) create mode 100644 x/uibc/keys.go create mode 100644 x/uibc/module/abci.go create mode 100644 x/uibc/module/module.go create mode 100644 x/uibc/msg.go create mode 100644 x/uibc/params.go create mode 100644 x/uibc/params_test.go create mode 100644 x/uibc/query.pb.go create mode 100644 x/uibc/query.pb.gw.go create mode 100644 x/uibc/quota.pb.go create mode 100644 x/uibc/quota/ibc_module.go create mode 100644 x/uibc/quota/ics4_wrapper.go create mode 100644 x/uibc/quota/keeper/genesis.go create mode 100644 x/uibc/quota/keeper/grpc_query.go create mode 100644 x/uibc/quota/keeper/keeper.go create mode 100644 x/uibc/quota/keeper/msg_server.go create mode 100644 x/uibc/quota/keeper/params.go create mode 100644 x/uibc/quota/keeper/quota.go create mode 100644 x/uibc/quota/keeper/relay.go create mode 100644 x/uibc/tx.pb.go diff --git a/app/app.go b/app/app.go index 5cedd2ebd6..d4a804f87a 100644 --- a/app/app.go +++ b/app/app.go @@ -118,14 +118,20 @@ import ( appparams "github.com/umee-network/umee/v4/app/params" "github.com/umee-network/umee/v4/swagger" "github.com/umee-network/umee/v4/util/genmap" - uibctransfer "github.com/umee-network/umee/v4/x/ibctransfer" - uibctransferkeeper "github.com/umee-network/umee/v4/x/ibctransfer/keeper" "github.com/umee-network/umee/v4/x/leverage" leveragekeeper "github.com/umee-network/umee/v4/x/leverage/keeper" leveragetypes "github.com/umee-network/umee/v4/x/leverage/types" "github.com/umee-network/umee/v4/x/oracle" oraclekeeper "github.com/umee-network/umee/v4/x/oracle/keeper" oracletypes "github.com/umee-network/umee/v4/x/oracle/types" + + // umee ibc-transfer and quota for ibc-transfer + "github.com/umee-network/umee/v4/x/uibc" + uics20transfer "github.com/umee-network/umee/v4/x/uibc/ics20" + uibctransferkeeper "github.com/umee-network/umee/v4/x/uibc/ics20/keeper" + uibcmodule "github.com/umee-network/umee/v4/x/uibc/module" + uibcquota "github.com/umee-network/umee/v4/x/uibc/quota" + uibcquotakeeper "github.com/umee-network/umee/v4/x/uibc/quota/keeper" ) var ( @@ -174,7 +180,7 @@ func init() { } if Experimental { - moduleBasics = append(moduleBasics, wasm.AppModuleBasic{}) + moduleBasics = append(moduleBasics, wasm.AppModuleBasic{}, uibcmodule.AppModuleBasic{}) } ModuleBasics = module.NewBasicManager(moduleBasics...) @@ -196,6 +202,7 @@ func init() { if Experimental { maccPerms[wasm.ModuleName] = []string{authtypes.Burner} + maccPerms[uibc.ModuleName] = nil } } @@ -241,6 +248,7 @@ type UmeeApp struct { LeverageKeeper leveragekeeper.Keeper OracleKeeper oraclekeeper.Keeper bech32IbcKeeper bech32ibckeeper.Keeper + uibcQuotaKeeper uibcquotakeeper.Keeper // make scoped keepers public for testing purposes ScopedIBCKeeper capabilitykeeper.ScopedKeeper @@ -300,12 +308,11 @@ func New( govtypes.StoreKey, paramstypes.StoreKey, upgradetypes.StoreKey, feegrant.StoreKey, evidencetypes.StoreKey, capabilitytypes.StoreKey, authzkeeper.StoreKey, nftkeeper.StoreKey, group.StoreKey, - ibchost.StoreKey, ibctransfertypes.StoreKey, - gravitytypes.StoreKey, + ibchost.StoreKey, ibctransfertypes.StoreKey, gravitytypes.StoreKey, leveragetypes.StoreKey, oracletypes.StoreKey, bech32ibctypes.StoreKey, } if Experimental { - storeKeys = append(storeKeys, wasm.StoreKey) + storeKeys = append(storeKeys, wasm.StoreKey, uibc.StoreKey) } keys := sdk.NewKVStoreKeys(storeKeys...) @@ -442,8 +449,7 @@ func New( app.StakingKeeper, distrtypes.ModuleName, ) - var err error - app.LeverageKeeper, err = leveragekeeper.NewKeeper( + app.LeverageKeeper = leveragekeeper.NewKeeper( appCodec, keys[leveragetypes.ModuleName], app.GetSubspace(leveragetypes.ModuleName), @@ -451,9 +457,6 @@ func New( app.OracleKeeper, cast.ToBool(appOpts.Get(leveragetypes.FlagEnableLiquidatorQuery)), ) - if err != nil { - panic(err) - } app.LeverageKeeper = *app.LeverageKeeper.SetHooks( leveragetypes.NewMultiHooks( app.OracleKeeper.Hooks(), @@ -494,13 +497,35 @@ func New( // If evidence needs to be handled for the app, set routes in router here and seal app.EvidenceKeeper = *evidenceKeeper + app.IBCKeeper = ibckeeper.NewKeeper( + appCodec, + keys[ibchost.StoreKey], + app.GetSubspace(ibchost.ModuleName), + *app.StakingKeeper, + app.UpgradeKeeper, + app.ScopedIBCKeeper, + ) + + var ics4Wrapper ibcporttypes.ICS4Wrapper + if Experimental { + app.uibcQuotaKeeper = uibcquotakeeper.NewKeeper( + appCodec, + keys[uibc.StoreKey], + app.IBCKeeper.ChannelKeeper, app.LeverageKeeper, + ) + ics4Wrapper = app.uibcQuotaKeeper + } else { + ics4Wrapper = app.IBCKeeper.ChannelKeeper + } + + // Middleware Stacks // Create an original ICS-20 transfer keeper and AppModule and then use it to // created an Umee wrapped ICS-20 transfer keeper and AppModule. ibcTransferKeeper := ibctransferkeeper.NewKeeper( appCodec, keys[ibctransfertypes.StoreKey], app.GetSubspace(ibctransfertypes.ModuleName), - app.IBCKeeper.ChannelKeeper, + ics4Wrapper, // ISC4 Wrapper: IBC Rate Limit middleware app.IBCKeeper.ChannelKeeper, &app.IBCKeeper.PortKeeper, app.AccountKeeper, @@ -509,15 +534,34 @@ func New( ) app.UIBCTransferKeeper = uibctransferkeeper.New(ibcTransferKeeper, app.BankKeeper) - ibcTransferModule := ibctransfer.NewAppModule(ibcTransferKeeper) - uibcTransferIBCModule := uibctransfer.NewIBCModule( - ibctransfer.NewIBCModule(ibcTransferKeeper), app.UIBCTransferKeeper, + + // Create Transfer Stack + // SendPacket, since it is originating from the application to core IBC: + // transferKeeper.SendPacket -> uibcquota.SendPacket -> channel.SendPacket + + // RecvPacket, message that originates from core IBC and goes down to app, the flow is the other way + // channel.RecvPacket -> uibcquota.OnRecvPacket -> transfer.OnRecvPacket + + // transfer stack contains (from top to bottom): + // - Umee IBC Transfer + // - IBC Rate Limit Middleware + + // create IBC module from bottom to top of stack + var transferStack ibcporttypes.IBCModule + transferStack = uics20transfer.NewIBCModule( + ibctransfer.NewIBCModule(ibcTransferKeeper), + app.UIBCTransferKeeper, ) + if Experimental { + transferStack = uibcquota.NewIBCMiddleware(transferStack, app.uibcQuotaKeeper) + } + + // Create IBC Router // create static IBC router, add transfer route, then set and seal it ibcRouter := ibcporttypes.NewRouter() - ibcRouter.AddRoute(ibctransfertypes.ModuleName, uibcTransferIBCModule) - + // Add transfer stack to IBC Router + ibcRouter.AddRoute(ibctransfertypes.ModuleName, transferStack) ibcRouter.AddRoute(wasm.ModuleName, wasm.NewIBCHandler(app.WasmKeeper, app.IBCKeeper.ChannelKeeper)) app.IBCKeeper.SetRouter(ibcRouter) @@ -593,15 +637,18 @@ func New( groupmodule.NewAppModule(appCodec, app.GroupKeeper, app.AccountKeeper, app.BankKeeper, app.interfaceRegistry), nftmodule.NewAppModule(appCodec, app.NFTKeeper, app.AccountKeeper, app.BankKeeper, app.interfaceRegistry), - ibcTransferModule, + ibctransfer.NewAppModule(ibcTransferKeeper), gravity.NewAppModule(app.GravityKeeper, app.BankKeeper), leverage.NewAppModule(appCodec, app.LeverageKeeper, app.AccountKeeper, app.BankKeeper), oracle.NewAppModule(appCodec, app.OracleKeeper, app.AccountKeeper, app.BankKeeper), bech32ibc.NewAppModule(appCodec, app.bech32IbcKeeper), } if Experimental { - appModules = append(appModules, - wasm.NewAppModule(app.appCodec, &app.WasmKeeper, app.StakingKeeper, app.AccountKeeper, app.BankKeeper)) + appModules = append( + appModules, + wasm.NewAppModule(app.appCodec, &app.WasmKeeper, app.StakingKeeper, app.AccountKeeper, app.BankKeeper), + uibcmodule.NewAppModule(appCodec, app.uibcQuotaKeeper), + ) } app.mm = module.NewManager(appModules...) @@ -626,6 +673,7 @@ func New( gravitytypes.ModuleName, bech32ibctypes.ModuleName, } + endBlockers := []string{ crisistypes.ModuleName, oracletypes.ModuleName, // must be before gov and staking @@ -661,6 +709,7 @@ func New( gravitytypes.ModuleName, bech32ibctypes.ModuleName, } + orderMigrations := []string{ capabilitytypes.ModuleName, authtypes.ModuleName, banktypes.ModuleName, distrtypes.ModuleName, stakingtypes.ModuleName, slashingtypes.ModuleName, govtypes.ModuleName, minttypes.ModuleName, @@ -676,10 +725,10 @@ func New( } if Experimental { - beginBlockers = append(beginBlockers, wasm.ModuleName) - endBlockers = append(endBlockers, wasm.ModuleName) - initGenesis = append(initGenesis, wasm.ModuleName) - orderMigrations = append(orderMigrations, wasm.ModuleName) + beginBlockers = append(beginBlockers, wasm.ModuleName, uibc.ModuleName) + endBlockers = append(endBlockers, wasm.ModuleName, uibc.ModuleName) + initGenesis = append(initGenesis, wasm.ModuleName, uibc.ModuleName) + orderMigrations = append(orderMigrations, wasm.ModuleName, uibc.ModuleName) } app.mm.SetOrderBeginBlockers(beginBlockers...) @@ -704,8 +753,10 @@ func New( authtypes.ModuleName: auth.NewAppModule(app.appCodec, app.AccountKeeper, authsims.RandomGenesisAccounts), } - simStateModules := genmap.Pick(app.mm.Modules, - []string{stakingtypes.ModuleName, authtypes.ModuleName, oracletypes.ModuleName}) + simStateModules := genmap.Pick( + app.mm.Modules, + []string{stakingtypes.ModuleName, authtypes.ModuleName, oracletypes.ModuleName}, + ) // TODO: Ensure x/leverage implements simulator and add it here: simTestModules := genmap.Pick(simStateModules, []string{oracletypes.ModuleName}) diff --git a/proto/umee/uibc/v1/events.proto b/proto/umee/uibc/v1/events.proto new file mode 100644 index 0000000000..3728b14e0d --- /dev/null +++ b/proto/umee/uibc/v1/events.proto @@ -0,0 +1,17 @@ +syntax = "proto3"; +package umee.uibc.v1; + +import "gogoproto/gogo.proto"; + +option go_package = "github.com/umee-network/umee/v4/x/uibc"; +option (gogoproto.goproto_getters_all) = false; + +// EventBadRevert is emitted on failure of ibc-transfer quota. +message EventBadRevert { + // module name + string module = 1; + // failure event type + string failure_type = 2; + // ibc packet data + string packet = 3; +} diff --git a/proto/umee/uibc/v1/genesis.proto b/proto/umee/uibc/v1/genesis.proto new file mode 100644 index 0000000000..254bedc7d0 --- /dev/null +++ b/proto/umee/uibc/v1/genesis.proto @@ -0,0 +1,29 @@ +syntax = "proto3"; +package umee.uibc.v1; + +import "gogoproto/gogo.proto"; +import "cosmos_proto/cosmos.proto"; +import "google/protobuf/timestamp.proto"; +import "umee/uibc/v1/quota.proto"; + +option go_package = "github.com/umee-network/umee/v4/x/uibc"; +option (gogoproto.goproto_getters_all) = false; + +// GenesisState defines the uibc module's genesis state. +message GenesisState { + Params params = 1 [(gogoproto.nullable) = false]; + repeated Quota quotas = 2 [(gogoproto.nullable) = false]; + // total_outflow_sum defines the total outflow sum of ibc-transfer in USD + string total_outflow_sum = 3 [ + (cosmos_proto.scalar) = "cosmos.Dec", + (gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec", + (gogoproto.nullable) = false + ]; + // quota_expires defines quota expires for ibc-transfer denom in seconds + google.protobuf.Timestamp quota_expires = 4 [ + (gogoproto.nullable) = false, + (gogoproto.stdtime) = true, + (gogoproto.jsontag) = "quota_duration,omitempty", + (gogoproto.moretags) = "yaml:\"quota_expires\"" + ]; +} diff --git a/proto/umee/uibc/v1/query.proto b/proto/umee/uibc/v1/query.proto new file mode 100644 index 0000000000..7473b30ee1 --- /dev/null +++ b/proto/umee/uibc/v1/query.proto @@ -0,0 +1,44 @@ +syntax = "proto3"; +package umee.uibc.v1; + +import "google/api/annotations.proto"; +import "gogoproto/gogo.proto"; +import "umee/uibc/v1/quota.proto"; + +option go_package = "github.com/umee-network/umee/v4/x/uibc"; + +option (gogoproto.goproto_getters_all) = false; + +// Query defines the gRPC querier service. +service Query { + // Params queries the parameters of the x/uibc module. + rpc Params(QueryParams) returns (QueryParamsResponse) { + option (google.api.http).get = "/umee/uibc/v1/params"; + } + + // Quota queries the rate limits of ibc denoms. + // If denom is empty, returns quota for all tokens. + rpc Quota(QueryQuota) returns (QueryQuotaResponse) { + option (google.api.http).get = "/umee/uibc/v1/quota/{denom}"; + } +} + +// QueryParams defines the request structure for the Params gRPC service +// handler. +message QueryParams {} + +// QueryParamsResponse defines the response structure for the Params gRPC +// service handler. +message QueryParamsResponse { + Params params = 1 [(gogoproto.nullable) = false]; +} + +// QueryQuota defines request type for query the quota of denoms +message QueryQuota { + string denom = 1; +} + +// QueryQuotaResponse defines response type of Query/Quota +message QueryQuotaResponse { + repeated Quota quota = 1 [(gogoproto.nullable) = false]; +} diff --git a/proto/umee/uibc/v1/quota.proto b/proto/umee/uibc/v1/quota.proto new file mode 100644 index 0000000000..8889ae309b --- /dev/null +++ b/proto/umee/uibc/v1/quota.proto @@ -0,0 +1,57 @@ +syntax = "proto3"; +package umee.uibc.v1; + +import "gogoproto/gogo.proto"; +import "google/protobuf/duration.proto"; +import "cosmos_proto/cosmos.proto"; + +option go_package = "github.com/umee-network/umee/v4/x/uibc"; + +// Quota stores current sum of IBC outflow transfers of IBC Denom. +message Quota { + // ibc_denom defines the ibc denom + string ibc_denom = 1; + // outflow_sum defines the sum of price (USD) value of outflow tokens through ibc-transfer + string outflow_sum = 3 [ + (cosmos_proto.scalar) = "cosmos.Dec", + (gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec", + (gogoproto.nullable) = false + ]; +} + +// Params of x/uibc module +message Params { + // ibc_status defines the wethever ibc-transfer enabled, disbaled or paused + IBCTransferStatus ibc_pause = 1; + // total_quota defines the total outflow limit of ibc-transfer in USD + string total_quota = 2 [ + (cosmos_proto.scalar) = "cosmos.Dec", + (gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec", + (gogoproto.nullable) = false + ]; + // token_quota defines the outflow limit per token in USD + string token_quota = 3 [ + (cosmos_proto.scalar) = "cosmos.Dec", + (gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec", + (gogoproto.nullable) = false + ]; + // quota_duration defines quota expires for each ibc-transfer denom in seconds + google.protobuf.Duration quota_duration = 4 [ + (gogoproto.nullable) = false, + (gogoproto.stdduration) = true, + (gogoproto.jsontag) = "quota_duration,omitempty", + (gogoproto.moretags) = "yaml:\"quota_duration\"" + ]; +} + +// IBCTransferStatus status of ibc-transfer +enum IBCTransferStatus { + // UNSPECIFIED defines a no-op status. + IBC_TRANSFER_STATUS_UNSPECIFIED = 0; + // DISABLED defines the quota checking diabled for ibc-transfer. + IBC_TRANSFER_STATUS_DISABLED = 1; + // ENABLED defines the enable quota checking for ibc-transfer. + IBC_TRANSFER_STATUS_ENABLED = 2; + // PAUSED defines pause the ibc-transfer from app. + IBC_TRANSFER_STATUS_PAUSED = 3; +} diff --git a/proto/umee/uibc/v1/tx.proto b/proto/umee/uibc/v1/tx.proto new file mode 100644 index 0000000000..861f5daa64 --- /dev/null +++ b/proto/umee/uibc/v1/tx.proto @@ -0,0 +1,73 @@ +syntax = "proto3"; +package umee.uibc.v1; + +import "gogoproto/gogo.proto"; +import "google/protobuf/duration.proto"; +import "cosmos/msg/v1/msg.proto"; +import "cosmos_proto/cosmos.proto"; +import "umee/uibc/v1/quota.proto"; + +option go_package = "github.com/umee-network/umee/v4/x/uibc"; + +option (gogoproto.goproto_getters_all) = false; +option (gogoproto.messagename_all) = true; + +// Msg defines the x/uibc module's Msg service. +service Msg { + // GovUpdateQuota adds new quota for ibc denoms or + // updates the quota for existed ibc denoms. + rpc GovUpdateQuota(MsgGovUpdateQuota) returns (MsgGovUpdateQuotaResponse); + + // GovSetIBCPause update the status of ibc-transfer + rpc GovSetIBCPause(MsgGovSetIBCPause) returns (MsgGovSetIBCPauseResponse); +} + +// MsgGovUpdateQuota defines the Msg/GovUpdateQuota request type. +message MsgGovUpdateQuota { + option (gogoproto.goproto_getters) = false; + option (gogoproto.goproto_stringer) = false; + option (cosmos.msg.v1.signer) = "authority"; + + // authority is the address of the governance account. + string authority = 1 [(cosmos_proto.scalar) = "cosmos.AddressString"]; + string title = 2; + string description = 3; + // total quota defines the total outflow of ibc-transfer in USD + string total = 4 [ + (cosmos_proto.scalar) = "cosmos.Dec", + (gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec", + (gogoproto.nullable) = false + ]; + // per_denom quota for outflows per denom. All denoms have the same quota size. + string per_denom = 5 [ + (cosmos_proto.scalar) = "cosmos.Dec", + (gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec", + (gogoproto.nullable) = false + ]; + // quota_duration defines quota expires per denom, All denoms have the same expire time. + google.protobuf.Duration quota_duration = 6 [ + (gogoproto.nullable) = false, + (gogoproto.stdduration) = true, + (gogoproto.jsontag) = "quota_duration,omitempty", + (gogoproto.moretags) = "yaml:\"quota_duration\"" + ]; +} + +// MsgGovUpdateQuotaResponse defines response type for the Msg/GovUpdateQuota for with x/gov proposals. +message MsgGovUpdateQuotaResponse {}; + +// MsgGovSetIBCPause defines request type for UpdateIBCTransferStatus +message MsgGovSetIBCPause { + option (gogoproto.goproto_getters) = false; + option (gogoproto.goproto_stringer) = false; + option (cosmos.msg.v1.signer) = "authority"; + // authority is the address of the governance account. + string authority = 1 [(cosmos_proto.scalar) = "cosmos.AddressString"]; + string title = 2; + string description = 3; + // ibc_pause_status defines ibc transfer pause status + IBCTransferStatus ibc_pause_status = 4; +} + +// MsgGovSetIBCPauseResponse definesresponse type for Msg/MsgGovSetIBCPause for with x/gov proposals. +message MsgGovSetIBCPauseResponse {} diff --git a/starport.ci.yml b/starport.ci.yml index c5eb44d89c..9c265f98a5 100644 --- a/starport.ci.yml +++ b/starport.ci.yml @@ -1,34 +1,44 @@ +version: 1 build: - binary: "umeed" - main: "./cmd/umeed" + main: ./cmd/umeed + binary: umeed + proto: + path: proto + third_party_paths: + - third_party/proto + - proto_vendor +accounts: +- name: alice + coins: + - 39000000000000uumee + mnemonic: entry garbage bike poem grunt negative easily annual miss happy license + blur false fringe program picture inner tape dismiss eagle include quality drill + master +- name: bob + coins: + - 5500000000000uumee +- name: faucet + coins: + - 5500000000000uumee +faucet: + name: faucet + coins: + - 5500000000000uumee + coins_max: + - 1000000000uumee + host: 0.0.0.0:4500 + port: 4500 genesis: - chain_id: "umee-local-testnet" app_state: - staking: - params: - bond_denom: "uumee" gravity: delegate_keys: - - validator: "umeevaloper1zypqa76je7pxsdwkfah6mu9a583sju6xjettez" - orchestrator: "umee1zypqa76je7pxsdwkfah6mu9a583sju6xjavygg" - eth_address: "0x9fc56f2e851e1ab2b4c0fc4f6344800f29652ffe" -accounts: - - name: alice - coins: ["39000000000000uumee"] - mnemonic: "entry garbage bike poem grunt negative easily annual miss happy license blur false fringe program picture inner tape dismiss eagle include quality drill master" - - name: bob - coins: ["5500000000000uumee"] - - name: faucet - coins: ["5500000000000uumee"] -validator: - name: alice - staked: "33500000000000uumee" - eth_address: "0x9fc56f2e851e1ab2b4c0fc4f6344800f29652ffe" - orch_address: "umee1zypqa76je7pxsdwkfah6mu9a583sju6xjavygg" -servers: - dev-ui-address: "localhost:12345" -faucet: - port: 4500 - name: "faucet" - coins: ["5500000000000uumee"] - coins_max: ["1000000000uumee"] + - eth_address: 0x9fc56f2e851e1ab2b4c0fc4f6344800f29652ffe + orchestrator: umee1zypqa76je7pxsdwkfah6mu9a583sju6xjavygg + validator: umeevaloper1zypqa76je7pxsdwkfah6mu9a583sju6xjettez + staking: + params: + bond_denom: uumee + chain_id: umee-local-testnet +validators: +- name: alice + bonded: 33500000000000uumee diff --git a/x/leverage/README.md b/x/leverage/README.md index 922053cd42..c26b6df027 100644 --- a/x/leverage/README.md +++ b/x/leverage/README.md @@ -6,7 +6,7 @@ This document specifies the `x/leverage` module of the Umee chain. The leverage module allows users to supply and borrow assets, and implements various features to support this, such as a token accept-list, a dynamic interest rate module, incentivized liquidation of undercollateralized debt, and automatic reserve-based repayment of bad debt. -The leverage module depends directly on `x/oracle` for asset prices, and interacts indirectly with `x/ibctransfer`, `x/gravity`, and the cosmos `x/bank` module as these all affect account balances. +The leverage module depends directly on `x/oracle` for asset prices, and interacts indirectly with `x/uibc`, `x/gravity`, and the cosmos `x/bank` module as these all affect account balances. ## Contents diff --git a/x/leverage/keeper/internal_test.go b/x/leverage/keeper/internal_test.go index fd0148a34c..069e3af891 100644 --- a/x/leverage/keeper/internal_test.go +++ b/x/leverage/keeper/internal_test.go @@ -28,7 +28,7 @@ func NewTestKeeper( ok types.OracleKeeper, enableLiquidatorQuery bool, ) (Keeper, TestKeeper) { - k, err := NewKeeper( + k := NewKeeper( cdc, storeKey, paramSpace, @@ -36,7 +36,6 @@ func NewTestKeeper( ok, enableLiquidatorQuery, ) - require.NoError(err) return k, TestKeeper{&k} } diff --git a/x/leverage/keeper/keeper.go b/x/leverage/keeper/keeper.go index bdbb33b733..887f337224 100644 --- a/x/leverage/keeper/keeper.go +++ b/x/leverage/keeper/keeper.go @@ -32,7 +32,7 @@ func NewKeeper( bk types.BankKeeper, ok types.OracleKeeper, enableLiquidatorQuery bool, -) (Keeper, error) { +) Keeper { // set KeyTable if it has not already been set if !paramSpace.HasKeyTable() { paramSpace = paramSpace.WithKeyTable(types.ParamKeyTable()) @@ -45,7 +45,7 @@ func NewKeeper( bankKeeper: bk, oracleKeeper: ok, liquidatorQueryEnabled: enableLiquidatorQuery, - }, nil + } } func (k Keeper) Logger(ctx sdk.Context) log.Logger { diff --git a/x/uibc/README.md b/x/uibc/README.md new file mode 100644 index 0000000000..5388d5497a --- /dev/null +++ b/x/uibc/README.md @@ -0,0 +1 @@ +# IBC Transfer and Rate Limits for IBC Denoms diff --git a/x/uibc/client/cli/query.go b/x/uibc/client/cli/query.go new file mode 100644 index 0000000000..5dcc9300d6 --- /dev/null +++ b/x/uibc/client/cli/query.go @@ -0,0 +1,79 @@ +package cli + +import ( + "fmt" + + "github.com/cosmos/cosmos-sdk/client" + "github.com/cosmos/cosmos-sdk/client/flags" + "github.com/spf13/cobra" + "github.com/umee-network/umee/v4/util/cli" + "github.com/umee-network/umee/v4/x/uibc" +) + +// GetQueryCmd returns the CLI query commands for the x/uibc module. +func GetQueryCmd() *cobra.Command { + cmd := &cobra.Command{ + Use: uibc.ModuleName, + Short: fmt.Sprintf("Querying commands for the %s module", uibc.ModuleName), + DisableFlagParsing: true, + SuggestionsMinimumDistance: 2, + RunE: client.ValidateCmd, + } + + cmd.AddCommand( + GetCmdQueryParams(), + GetQuota(), + ) + + return cmd +} + +// GetCmdQueryParams creates a Cobra command to query for the x/uibc +// module parameters. +func GetCmdQueryParams() *cobra.Command { + cmd := &cobra.Command{ + Use: "params", + Args: cobra.NoArgs, + Short: "Query the x/uibc module parameters", + RunE: func(cmd *cobra.Command, args []string) error { + clientCtx, err := client.GetClientQueryContext(cmd) + if err != nil { + return err + } + + queryClient := uibc.NewQueryClient(clientCtx) + resp, err := queryClient.Params(cmd.Context(), &uibc.QueryParams{}) + return cli.PrintOrErr(resp, err, clientCtx) + }, + } + + flags.AddQueryFlagsToCmd(cmd) + + return cmd +} + +// GetQuota returns cmd to get the quota of ibc denoms. +func GetQuota() *cobra.Command { + cmd := &cobra.Command{ + Use: "quota [denom]", + Args: cobra.MaximumNArgs(1), + Short: "Get the quota for ibc and native denoms", + RunE: func(cmd *cobra.Command, args []string) error { + clientCtx, err := client.GetClientQueryContext(cmd) + if err != nil { + return err + } + + queryClient := uibc.NewQueryClient(clientCtx) + queryReq := uibc.QueryQuota{} + if len(args) > 0 { + queryReq.Denom = args[0] + } + resp, err := queryClient.Quota(cmd.Context(), &queryReq) + return cli.PrintOrErr(resp, err, clientCtx) + }, + } + + flags.AddQueryFlagsToCmd(cmd) + return cmd +} diff --git a/x/uibc/client/cli/tx.go b/x/uibc/client/cli/tx.go new file mode 100644 index 0000000000..5860e28885 --- /dev/null +++ b/x/uibc/client/cli/tx.go @@ -0,0 +1,22 @@ +package cli + +import ( + "fmt" + + "github.com/cosmos/cosmos-sdk/client" + "github.com/spf13/cobra" + "github.com/umee-network/umee/v4/x/uibc" +) + +// GetTxCmd returns the CLI transaction commands for the x/uibc module. +func GetTxCmd() *cobra.Command { + cmd := &cobra.Command{ + Use: uibc.ModuleName, + Short: fmt.Sprintf("Transaction commands for the %s module", uibc.ModuleName), + DisableFlagParsing: true, + SuggestionsMinimumDistance: 2, + RunE: client.ValidateCmd, + } + + return cmd +} diff --git a/x/uibc/codec.go b/x/uibc/codec.go new file mode 100644 index 0000000000..a790b3bcc6 --- /dev/null +++ b/x/uibc/codec.go @@ -0,0 +1,42 @@ +package uibc + +import ( + "github.com/cosmos/cosmos-sdk/codec" + cdctypes "github.com/cosmos/cosmos-sdk/codec/types" + cryptocodec "github.com/cosmos/cosmos-sdk/crypto/codec" + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/cosmos/cosmos-sdk/types/msgservice" +) + +var ( + amino = codec.NewLegacyAmino() + + // ModuleCdc references the global x/uibc module codec. Note, the codec + // should ONLY be used in certain instances of tests and for JSON encoding as + // Amino is still used for that purpose. + ModuleCdc = codec.NewAminoCodec(amino) +) + +func init() { + RegisterLegacyAminoCodec(amino) + cryptocodec.RegisterCrypto(amino) + amino.Seal() +} + +// RegisterLegacyAminoCodec registers the necessary x/uibc interfaces and +// concrete types on the provided LegacyAmino codec. These types are used for +// Amino JSON serialization. +func RegisterLegacyAminoCodec(cdc *codec.LegacyAmino) { + cdc.RegisterConcrete(&MsgGovUpdateQuota{}, "umee/uibc/MsgGovUpdateQuota", nil) + cdc.RegisterConcrete(&MsgGovSetIBCPause{}, "umee/uibc/MsgGovSetIBCPause", nil) +} + +func RegisterInterfaces(registry cdctypes.InterfaceRegistry) { + registry.RegisterImplementations( + (*sdk.Msg)(nil), + &MsgGovUpdateQuota{}, + &MsgGovSetIBCPause{}, + ) + + msgservice.RegisterMsgServiceDesc(registry, &_Msg_serviceDesc) +} diff --git a/x/uibc/errors.go b/x/uibc/errors.go new file mode 100644 index 0000000000..de93b08e22 --- /dev/null +++ b/x/uibc/errors.go @@ -0,0 +1,10 @@ +package uibc + +import ( + sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" +) + +var ( + ErrQuotaExceeded = sdkerrors.Register(ModuleName, 1, "quota transfer exceeded") + ErrNoQuotaForIBCDenom = sdkerrors.Register(ModuleName, 2, "no quota for ibc denom") +) diff --git a/x/uibc/events.pb.go b/x/uibc/events.pb.go new file mode 100644 index 0000000000..4ce87707a8 --- /dev/null +++ b/x/uibc/events.pb.go @@ -0,0 +1,404 @@ +// Code generated by protoc-gen-gogo. DO NOT EDIT. +// source: umee/uibc/v1/events.proto + +package uibc + +import ( + fmt "fmt" + _ "github.com/gogo/protobuf/gogoproto" + proto "github.com/gogo/protobuf/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 + +// EventBadRevert is emitted on failure of ibc-transfer quota. +type EventBadRevert struct { + // module name + Module string `protobuf:"bytes,1,opt,name=module,proto3" json:"module,omitempty"` + // failure event type + FailureType string `protobuf:"bytes,2,opt,name=failure_type,json=failureType,proto3" json:"failure_type,omitempty"` + // ibc packet data + Packet string `protobuf:"bytes,3,opt,name=packet,proto3" json:"packet,omitempty"` +} + +func (m *EventBadRevert) Reset() { *m = EventBadRevert{} } +func (m *EventBadRevert) String() string { return proto.CompactTextString(m) } +func (*EventBadRevert) ProtoMessage() {} +func (*EventBadRevert) Descriptor() ([]byte, []int) { + return fileDescriptor_c64e60b79cebf048, []int{0} +} +func (m *EventBadRevert) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *EventBadRevert) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_EventBadRevert.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 *EventBadRevert) XXX_Merge(src proto.Message) { + xxx_messageInfo_EventBadRevert.Merge(m, src) +} +func (m *EventBadRevert) XXX_Size() int { + return m.Size() +} +func (m *EventBadRevert) XXX_DiscardUnknown() { + xxx_messageInfo_EventBadRevert.DiscardUnknown(m) +} + +var xxx_messageInfo_EventBadRevert proto.InternalMessageInfo + +func init() { + proto.RegisterType((*EventBadRevert)(nil), "umee.uibc.v1.EventBadRevert") +} + +func init() { proto.RegisterFile("umee/uibc/v1/events.proto", fileDescriptor_c64e60b79cebf048) } + +var fileDescriptor_c64e60b79cebf048 = []byte{ + // 218 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0x92, 0x2c, 0xcd, 0x4d, 0x4d, + 0xd5, 0x2f, 0xcd, 0x4c, 0x4a, 0xd6, 0x2f, 0x33, 0xd4, 0x4f, 0x2d, 0x4b, 0xcd, 0x2b, 0x29, 0xd6, + 0x2b, 0x28, 0xca, 0x2f, 0xc9, 0x17, 0xe2, 0x01, 0x49, 0xe9, 0x81, 0xa4, 0xf4, 0xca, 0x0c, 0xa5, + 0x44, 0xd2, 0xf3, 0xd3, 0xf3, 0xc1, 0x12, 0xfa, 0x20, 0x16, 0x44, 0x8d, 0x52, 0x32, 0x17, 0x9f, + 0x2b, 0x48, 0x8f, 0x53, 0x62, 0x4a, 0x50, 0x6a, 0x59, 0x6a, 0x51, 0x89, 0x90, 0x18, 0x17, 0x5b, + 0x6e, 0x7e, 0x4a, 0x69, 0x4e, 0xaa, 0x04, 0xa3, 0x02, 0xa3, 0x06, 0x67, 0x10, 0x94, 0x27, 0xa4, + 0xc8, 0xc5, 0x93, 0x96, 0x98, 0x99, 0x53, 0x5a, 0x94, 0x1a, 0x5f, 0x52, 0x59, 0x90, 0x2a, 0xc1, + 0x04, 0x96, 0xe5, 0x86, 0x8a, 0x85, 0x54, 0x16, 0xa4, 0x82, 0xb4, 0x16, 0x24, 0x26, 0x67, 0xa7, + 0x96, 0x48, 0x30, 0x43, 0xb4, 0x42, 0x78, 0x4e, 0x2e, 0x27, 0x1e, 0xca, 0x31, 0x9c, 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, 0x5a, 0x7a, 0x66, 0x49, 0x46, 0x69, 0x92, 0x5e, + 0x72, 0x7e, 0xae, 0x3e, 0xc8, 0xc5, 0xba, 0x79, 0xa9, 0x25, 0xe5, 0xf9, 0x45, 0xd9, 0x60, 0x8e, + 0x7e, 0x99, 0x89, 0x7e, 0x05, 0xd8, 0x7b, 0x49, 0x6c, 0x60, 0x17, 0x1b, 0x03, 0x02, 0x00, 0x00, + 0xff, 0xff, 0xf1, 0x7b, 0x48, 0xea, 0xf2, 0x00, 0x00, 0x00, +} + +func (m *EventBadRevert) 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 *EventBadRevert) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *EventBadRevert) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if len(m.Packet) > 0 { + i -= len(m.Packet) + copy(dAtA[i:], m.Packet) + i = encodeVarintEvents(dAtA, i, uint64(len(m.Packet))) + i-- + dAtA[i] = 0x1a + } + if len(m.FailureType) > 0 { + i -= len(m.FailureType) + copy(dAtA[i:], m.FailureType) + i = encodeVarintEvents(dAtA, i, uint64(len(m.FailureType))) + i-- + dAtA[i] = 0x12 + } + if len(m.Module) > 0 { + i -= len(m.Module) + copy(dAtA[i:], m.Module) + i = encodeVarintEvents(dAtA, i, uint64(len(m.Module))) + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func encodeVarintEvents(dAtA []byte, offset int, v uint64) int { + offset -= sovEvents(v) + base := offset + for v >= 1<<7 { + dAtA[offset] = uint8(v&0x7f | 0x80) + v >>= 7 + offset++ + } + dAtA[offset] = uint8(v) + return base +} +func (m *EventBadRevert) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.Module) + if l > 0 { + n += 1 + l + sovEvents(uint64(l)) + } + l = len(m.FailureType) + if l > 0 { + n += 1 + l + sovEvents(uint64(l)) + } + l = len(m.Packet) + if l > 0 { + n += 1 + l + sovEvents(uint64(l)) + } + return n +} + +func sovEvents(x uint64) (n int) { + return (math_bits.Len64(x|1) + 6) / 7 +} +func sozEvents(x uint64) (n int) { + return sovEvents(uint64((x << 1) ^ uint64((int64(x) >> 63)))) +} +func (m *EventBadRevert) 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 ErrIntOverflowEvents + } + 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: EventBadRevert: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: EventBadRevert: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Module", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowEvents + } + 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 ErrInvalidLengthEvents + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthEvents + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Module = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field FailureType", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowEvents + } + 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 ErrInvalidLengthEvents + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthEvents + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.FailureType = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 3: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Packet", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowEvents + } + 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 ErrInvalidLengthEvents + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthEvents + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Packet = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipEvents(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthEvents + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func skipEvents(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, ErrIntOverflowEvents + } + 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, ErrIntOverflowEvents + } + 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, ErrIntOverflowEvents + } + 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, ErrInvalidLengthEvents + } + iNdEx += length + case 3: + depth++ + case 4: + if depth == 0 { + return 0, ErrUnexpectedEndOfGroupEvents + } + depth-- + case 5: + iNdEx += 4 + default: + return 0, fmt.Errorf("proto: illegal wireType %d", wireType) + } + if iNdEx < 0 { + return 0, ErrInvalidLengthEvents + } + if depth == 0 { + return iNdEx, nil + } + } + return 0, io.ErrUnexpectedEOF +} + +var ( + ErrInvalidLengthEvents = fmt.Errorf("proto: negative length found during unmarshaling") + ErrIntOverflowEvents = fmt.Errorf("proto: integer overflow") + ErrUnexpectedEndOfGroupEvents = fmt.Errorf("proto: unexpected end of group") +) diff --git a/x/ibctransfer/types/expected_keepers.go b/x/uibc/expected_keepers.go similarity index 54% rename from x/ibctransfer/types/expected_keepers.go rename to x/uibc/expected_keepers.go index e813b38fcc..af90cc7fb0 100644 --- a/x/ibctransfer/types/expected_keepers.go +++ b/x/uibc/expected_keepers.go @@ -1,8 +1,10 @@ -package types +package uibc import ( sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/x/bank/types" + + ltypes "github.com/umee-network/umee/v4/x/leverage/types" ) // BankKeeper defines the expected x/bank keeper interface. @@ -11,3 +13,9 @@ type BankKeeper interface { SetDenomMetaData(ctx sdk.Context, denomMetaData types.Metadata) IterateAllDenomMetaData(ctx sdk.Context, cb func(types.Metadata) bool) } + +type LeverageKeeper interface { + GetTokenSettings(ctx sdk.Context, baseDenom string) (ltypes.Token, error) + TokenValue(ctx sdk.Context, coin sdk.Coin, mode ltypes.PriceMode) (sdk.Dec, error) + ExchangeUToken(ctx sdk.Context, uToken sdk.Coin) (sdk.Coin, error) +} diff --git a/x/uibc/genesis.go b/x/uibc/genesis.go new file mode 100644 index 0000000000..ca4d1e8e2b --- /dev/null +++ b/x/uibc/genesis.go @@ -0,0 +1,42 @@ +package uibc + +import ( + fmt "fmt" + + sdk "github.com/cosmos/cosmos-sdk/types" +) + +func NewGenesisState(params Params, quotas []Quota, outflowSum sdk.Dec) *GenesisState { + return &GenesisState{ + Params: params, + Quotas: quotas, + TotalOutflowSum: outflowSum, + } +} + +func DefaultGenesisState() *GenesisState { + return &GenesisState{ + Params: DefaultParams(), + Quotas: nil, + TotalOutflowSum: sdk.NewDec(0), + } +} + +// Validate performs basic valida`tion of the interchain accounts GenesisState +func (gs GenesisState) Validate() error { + if err := gs.Params.Validate(); err != nil { + return err + } + + for _, quota := range gs.Quotas { + if err := quota.Validate(); err != nil { + return err + } + } + + if gs.TotalOutflowSum.IsNegative() { + return fmt.Errorf("total outflow sum shouldn't be negative : %s ", gs.TotalOutflowSum.String()) + } + + return nil +} diff --git a/x/uibc/genesis.pb.go b/x/uibc/genesis.pb.go new file mode 100644 index 0000000000..ef0fde0c6f --- /dev/null +++ b/x/uibc/genesis.pb.go @@ -0,0 +1,481 @@ +// Code generated by protoc-gen-gogo. DO NOT EDIT. +// source: umee/uibc/v1/genesis.proto + +package uibc + +import ( + fmt "fmt" + _ "github.com/cosmos/cosmos-proto" + github_com_cosmos_cosmos_sdk_types "github.com/cosmos/cosmos-sdk/types" + _ "github.com/gogo/protobuf/gogoproto" + proto "github.com/gogo/protobuf/proto" + github_com_gogo_protobuf_types "github.com/gogo/protobuf/types" + _ "google.golang.org/protobuf/types/known/timestamppb" + io "io" + math "math" + math_bits "math/bits" + time "time" +) + +// Reference imports to suppress errors if they are not otherwise used. +var _ = proto.Marshal +var _ = fmt.Errorf +var _ = math.Inf +var _ = time.Kitchen + +// 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 uibc module's genesis state. +type GenesisState struct { + Params Params `protobuf:"bytes,1,opt,name=params,proto3" json:"params"` + Quotas []Quota `protobuf:"bytes,2,rep,name=quotas,proto3" json:"quotas"` + // total_outflow_sum defines the total outflow sum of ibc-transfer in USD + TotalOutflowSum github_com_cosmos_cosmos_sdk_types.Dec `protobuf:"bytes,3,opt,name=total_outflow_sum,json=totalOutflowSum,proto3,customtype=github.com/cosmos/cosmos-sdk/types.Dec" json:"total_outflow_sum"` + // quota_expires defines quota expires for ibc-transfer denom in seconds + QuotaExpires time.Time `protobuf:"bytes,4,opt,name=quota_expires,json=quotaExpires,proto3,stdtime" json:"quota_duration,omitempty" yaml:"quota_expires"` +} + +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_0196ecf2d08401fb, []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 init() { + proto.RegisterType((*GenesisState)(nil), "umee.uibc.v1.GenesisState") +} + +func init() { proto.RegisterFile("umee/uibc/v1/genesis.proto", fileDescriptor_0196ecf2d08401fb) } + +var fileDescriptor_0196ecf2d08401fb = []byte{ + // 404 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x54, 0x91, 0x3f, 0xef, 0xd2, 0x40, + 0x18, 0xc7, 0x5b, 0x20, 0x24, 0x16, 0x8c, 0xb1, 0x32, 0xd4, 0x0e, 0x2d, 0x61, 0x30, 0x0c, 0x72, + 0x17, 0xd0, 0xc9, 0x38, 0x11, 0x8c, 0xa3, 0x0a, 0x4e, 0x2e, 0xcd, 0xb5, 0x1c, 0xa5, 0xa1, 0xc7, + 0x53, 0x7b, 0x77, 0xfc, 0x19, 0x7c, 0x0f, 0xbc, 0x18, 0x5f, 0x04, 0x23, 0x71, 0x32, 0x0e, 0x55, + 0x61, 0x73, 0xf4, 0x15, 0xfc, 0xd2, 0xbb, 0x92, 0xc0, 0xd4, 0x3e, 0xf7, 0xf9, 0x3e, 0xcf, 0x7d, + 0x9f, 0xef, 0x59, 0xae, 0x64, 0x94, 0x62, 0x99, 0x84, 0x11, 0xde, 0x0c, 0x71, 0x4c, 0xd7, 0x94, + 0x27, 0x1c, 0x65, 0x39, 0x08, 0xb0, 0xdb, 0x25, 0x43, 0x25, 0x43, 0x9b, 0xa1, 0xdb, 0x89, 0x21, + 0x06, 0x05, 0x70, 0xf9, 0xa7, 0x35, 0xee, 0xf3, 0x08, 0x38, 0x03, 0x1e, 0x68, 0xa0, 0x8b, 0x0a, + 0xf9, 0x31, 0x40, 0x9c, 0x52, 0xac, 0xaa, 0x50, 0x2e, 0xb0, 0x48, 0x18, 0xe5, 0x82, 0xb0, 0xac, + 0x12, 0x38, 0x77, 0x77, 0x7f, 0x95, 0x20, 0x88, 0x26, 0xbd, 0xa2, 0x66, 0xb5, 0xdf, 0x6b, 0x2f, + 0x33, 0x41, 0x04, 0xb5, 0x47, 0x56, 0x33, 0x23, 0x39, 0x61, 0xdc, 0x31, 0xbb, 0x66, 0xbf, 0x35, + 0xea, 0xa0, 0x5b, 0x6f, 0xe8, 0xa3, 0x62, 0xe3, 0xc6, 0xb1, 0xf0, 0x8d, 0x69, 0xa5, 0xb4, 0x87, + 0x56, 0x53, 0xcd, 0xe4, 0x4e, 0xad, 0x5b, 0xef, 0xb7, 0x46, 0xcf, 0xee, 0x7b, 0x3e, 0x95, 0xec, + 0xda, 0xa2, 0x85, 0xf6, 0xd2, 0x7a, 0x2a, 0x40, 0x90, 0x34, 0x00, 0x29, 0x16, 0x29, 0x6c, 0x03, + 0x2e, 0x99, 0x53, 0xef, 0x9a, 0xfd, 0x47, 0xe3, 0xb7, 0xa5, 0xf0, 0x57, 0xe1, 0xbf, 0x88, 0x13, + 0xb1, 0x94, 0x21, 0x8a, 0x80, 0x55, 0xeb, 0x56, 0x9f, 0x01, 0x9f, 0xaf, 0xb0, 0xd8, 0x67, 0x94, + 0xa3, 0x09, 0x8d, 0x7e, 0x7c, 0x1f, 0x58, 0x55, 0x1a, 0x13, 0x1a, 0x4d, 0x9f, 0xa8, 0xb1, 0x1f, + 0xf4, 0xd4, 0x99, 0x64, 0xf6, 0x37, 0xeb, 0xb1, 0xba, 0x33, 0xa0, 0xbb, 0x2c, 0xc9, 0x29, 0x77, + 0x1a, 0x6a, 0x2f, 0x17, 0xe9, 0xd0, 0xd0, 0x35, 0x34, 0xf4, 0xf9, 0x1a, 0x9a, 0x76, 0xf0, 0xaf, + 0xf0, 0x1d, 0xdd, 0x38, 0x97, 0x39, 0x11, 0x09, 0xac, 0x5f, 0x02, 0x4b, 0x04, 0x65, 0x99, 0xd8, + 0xff, 0x2f, 0xfc, 0xce, 0x9e, 0xb0, 0xf4, 0x4d, 0xef, 0x6e, 0x74, 0xef, 0xf0, 0xdb, 0x37, 0xa7, + 0x6d, 0x75, 0xf6, 0x4e, 0x1f, 0x8d, 0x27, 0xc7, 0xbf, 0x9e, 0x71, 0x3c, 0x7b, 0xe6, 0xe9, 0xec, + 0x99, 0x7f, 0xce, 0x9e, 0x79, 0xb8, 0x78, 0xc6, 0xe9, 0xe2, 0x19, 0x3f, 0x2f, 0x9e, 0xf1, 0xe5, + 0x76, 0xc7, 0x32, 0xb3, 0xc1, 0x9a, 0x8a, 0x2d, 0xe4, 0x2b, 0x55, 0xe0, 0xcd, 0x6b, 0xbc, 0x53, + 0xaf, 0x16, 0x36, 0x95, 0xcb, 0x57, 0x0f, 0x01, 0x00, 0x00, 0xff, 0xff, 0x8e, 0x99, 0xb7, 0x7f, + 0x45, 0x02, 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 + n1, err1 := github_com_gogo_protobuf_types.StdTimeMarshalTo(m.QuotaExpires, dAtA[i-github_com_gogo_protobuf_types.SizeOfStdTime(m.QuotaExpires):]) + if err1 != nil { + return 0, err1 + } + i -= n1 + i = encodeVarintGenesis(dAtA, i, uint64(n1)) + i-- + dAtA[i] = 0x22 + { + size := m.TotalOutflowSum.Size() + i -= size + if _, err := m.TotalOutflowSum.MarshalTo(dAtA[i:]); err != nil { + return 0, err + } + i = encodeVarintGenesis(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x1a + if len(m.Quotas) > 0 { + for iNdEx := len(m.Quotas) - 1; iNdEx >= 0; iNdEx-- { + { + size, err := m.Quotas[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.Quotas) > 0 { + for _, e := range m.Quotas { + l = e.Size() + n += 1 + l + sovGenesis(uint64(l)) + } + } + l = m.TotalOutflowSum.Size() + n += 1 + l + sovGenesis(uint64(l)) + l = github_com_gogo_protobuf_types.SizeOfStdTime(m.QuotaExpires) + 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 Quotas", 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.Quotas = append(m.Quotas, Quota{}) + if err := m.Quotas[len(m.Quotas)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 3: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field TotalOutflowSum", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowGenesis + } + 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 ErrInvalidLengthGenesis + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthGenesis + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if err := m.TotalOutflowSum.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 4: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field QuotaExpires", 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 := github_com_gogo_protobuf_types.StdTimeUnmarshal(&m.QuotaExpires, 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/ibctransfer/ibc_module.go b/x/uibc/ics20/ibc_module.go similarity index 94% rename from x/ibctransfer/ibc_module.go rename to x/uibc/ics20/ibc_module.go index 3544a6d374..e4f7587f38 100644 --- a/x/ibctransfer/ibc_module.go +++ b/x/uibc/ics20/ibc_module.go @@ -1,4 +1,4 @@ -package ibctransfer +package ics20 import ( sdk "github.com/cosmos/cosmos-sdk/types" @@ -7,7 +7,7 @@ import ( channeltypes "github.com/cosmos/ibc-go/v5/modules/core/04-channel/types" ibcexported "github.com/cosmos/ibc-go/v5/modules/core/exported" - "github.com/umee-network/umee/v4/x/ibctransfer/keeper" + "github.com/umee-network/umee/v4/x/uibc/ics20/keeper" ) // IBCModule embeds the ICS-20 transfer IBCModule where we only override specific diff --git a/x/ibctransfer/keeper/keeper.go b/x/uibc/ics20/keeper/keeper.go similarity index 96% rename from x/ibctransfer/keeper/keeper.go rename to x/uibc/ics20/keeper/keeper.go index c758e70c8e..86b88ce342 100644 --- a/x/ibctransfer/keeper/keeper.go +++ b/x/uibc/ics20/keeper/keeper.go @@ -11,7 +11,7 @@ import ( clienttypes "github.com/cosmos/ibc-go/v5/modules/core/02-client/types" channeltypes "github.com/cosmos/ibc-go/v5/modules/core/04-channel/types" - "github.com/umee-network/umee/v4/x/ibctransfer/types" + ibctransfer "github.com/umee-network/umee/v4/x/uibc" ) // Keeper embeds the ICS-20 transfer keeper where we only override specific @@ -20,10 +20,10 @@ type Keeper struct { // embed the ICS-20 transfer keeper ibctransferkeeper.Keeper - bankKeeper types.BankKeeper + bankKeeper ibctransfer.BankKeeper } -func New(tk ibctransferkeeper.Keeper, bk types.BankKeeper) Keeper { +func New(tk ibctransferkeeper.Keeper, bk ibctransfer.BankKeeper) Keeper { return Keeper{ Keeper: tk, bankKeeper: bk, diff --git a/x/ibctransfer/keeper/keeper_test.go b/x/uibc/ics20/keeper/keeper_test.go similarity index 99% rename from x/ibctransfer/keeper/keeper_test.go rename to x/uibc/ics20/keeper/keeper_test.go index facd00f75a..13ca670b93 100644 --- a/x/ibctransfer/keeper/keeper_test.go +++ b/x/uibc/ics20/keeper/keeper_test.go @@ -214,7 +214,7 @@ func (s *KeeperTestSuite) TestTrackMetadata() { denomTrace := ibctransfertypes.ParseDenomTrace(data.Denom) ibcDenom := denomTrace.IBCDenom() - registerDenom := func() { + registeredenom := func() { denomTrace := ibctransfertypes.ParseDenomTrace(denom) traceHash := denomTrace.Hash() if !s.GetUmeeApp(s.chainB).UIBCTransferKeeper.HasDenomTrace(s.chainB.GetContext(), traceHash) { @@ -222,7 +222,7 @@ func (s *KeeperTestSuite) TestTrackMetadata() { } } - registerDenom() + registeredenom() amount, err := strconv.Atoi(data.Amount) s.Require().NoError(err) diff --git a/x/ibctransfer/keeper/util_test.go b/x/uibc/ics20/keeper/util_test.go similarity index 100% rename from x/ibctransfer/keeper/util_test.go rename to x/uibc/ics20/keeper/util_test.go diff --git a/x/uibc/keys.go b/x/uibc/keys.go new file mode 100644 index 0000000000..121fb0f09e --- /dev/null +++ b/x/uibc/keys.go @@ -0,0 +1,36 @@ +package uibc + +import ( + "encoding/hex" + + "github.com/umee-network/umee/v4/util" +) + +const ( + // ModuleName defines the module name + ModuleName = "uibc" + + // StoreKey defines the primary module store key + StoreKey = ModuleName + + // RouterKey is the message route for uibc + RouterKey = ModuleName +) + +var ( + KeyPrefixDenomQuota = []byte{0x01} + KeyPrefixTotalOutflows = []byte{0x02} + // KeyPrefixParams is the key to query all gov params + KeyPrefixParams = []byte{0x03} + // KeyPrefixQuotaExpires is the key to store the next expire time of ibc-transfer quota + KeyPrefixQuotaExpires = []byte{0x04} +) + +func KeyTotalOutflows(ibcDenom string) []byte { + // KeyPrefixDenomQuota| denom + return util.ConcatBytes(0, KeyPrefixDenomQuota, []byte(ibcDenom)) +} + +func DenomFromKeyTotalOutflows(key []byte) string { + return hex.EncodeToString(key[2:]) +} diff --git a/x/uibc/module/abci.go b/x/uibc/module/abci.go new file mode 100644 index 0000000000..432a2cf9de --- /dev/null +++ b/x/uibc/module/abci.go @@ -0,0 +1,27 @@ +package uibc + +import ( + sdk "github.com/cosmos/cosmos-sdk/types" + abci "github.com/tendermint/tendermint/abci/types" + "github.com/umee-network/umee/v4/x/uibc/quota/keeper" +) + +// BeginBlock implements BeginBlock for the x/uibc module. +func BeginBlock(ctx sdk.Context, keeper keeper.Keeper) { + quotaExpires, err := keeper.GetExpire(ctx) + if err != nil { + panic(err) + } + + // reset quotas + if quotaExpires == nil || quotaExpires.Before(ctx.BlockTime()) { + if err := keeper.ResetQuota(ctx); err != nil { + panic(err) + } + } +} + +// EndBlocker implements EndBlock for the x/leverage module. +func EndBlocker(_ sdk.Context, _ keeper.Keeper) []abci.ValidatorUpdate { + return []abci.ValidatorUpdate{} +} diff --git a/x/uibc/module/module.go b/x/uibc/module/module.go new file mode 100644 index 0000000000..7f0fd42a5b --- /dev/null +++ b/x/uibc/module/module.go @@ -0,0 +1,148 @@ +package uibc + +import ( + "context" + "encoding/json" + "fmt" + + "github.com/cosmos/cosmos-sdk/client" + "github.com/cosmos/cosmos-sdk/codec" + codectypes "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" + abci "github.com/tendermint/tendermint/abci/types" + ibctransfer "github.com/umee-network/umee/v4/x/uibc" + "github.com/umee-network/umee/v4/x/uibc/client/cli" + "github.com/umee-network/umee/v4/x/uibc/quota/keeper" +) + +var ( + _ module.AppModule = AppModule{} + _ module.AppModuleBasic = AppModuleBasic{} +) + +// AppModuleBasic is the 29-fee AppModuleBasic +type AppModuleBasic struct { + cdc codec.Codec +} + +func NewAppModuleBasic(cdc codec.Codec) AppModuleBasic { + return AppModuleBasic{cdc: cdc} +} + +// DefaultGenesis implements module.AppModuleBasic +func (AppModuleBasic) DefaultGenesis(cdc codec.JSONCodec) json.RawMessage { + return cdc.MustMarshalJSON(ibctransfer.DefaultGenesisState()) +} + +// GetQueryCmd implements module.AppModuleBasic +func (AppModuleBasic) GetQueryCmd() *cobra.Command { + return cli.GetQueryCmd() +} + +// GetTxCmd implements module.AppModuleBasic +func (AppModuleBasic) GetTxCmd() *cobra.Command { + return cli.GetTxCmd() +} + +// Name implements module.AppModuleBasic +func (AppModuleBasic) Name() string { + return ibctransfer.ModuleName +} + +// RegisterGRPCGatewayRoutes implements module.AppModuleBasic +func (AppModuleBasic) RegisterGRPCGatewayRoutes(clientCtx client.Context, mux *runtime.ServeMux) { + if err := ibctransfer.RegisterQueryHandlerClient( + context.Background(), mux, ibctransfer.NewQueryClient(clientCtx), + ); err != nil { + panic(err) + } +} + +// RegisterInterfaces implements module.AppModuleBasic +func (AppModuleBasic) RegisterInterfaces(registry codectypes.InterfaceRegistry) { + ibctransfer.RegisterInterfaces(registry) +} + +// RegisterLegacyAminoCodec implements module.AppModuleBasic +func (AppModuleBasic) RegisterLegacyAminoCodec(cdc *codec.LegacyAmino) { + ibctransfer.RegisterLegacyAminoCodec(cdc) +} + +// ValidateGenesis implements module.AppModuleBasic +func (AppModuleBasic) ValidateGenesis(cdc codec.JSONCodec, _ client.TxEncodingConfig, bz json.RawMessage) error { + var gs ibctransfer.GenesisState + if err := cdc.UnmarshalJSON(bz, &gs); err != nil { + return fmt.Errorf("failed to unmarshal %s genesis state: %w", ibctransfer.ModuleName, err) + } + + return gs.Validate() +} + +// AppModule represents the AppModule for this module +type AppModule struct { + AppModuleBasic + keeper keeper.Keeper +} + +func NewAppModule(cdc codec.Codec, keeper keeper.Keeper) AppModule { + return AppModule{ + AppModuleBasic: NewAppModuleBasic(cdc), + keeper: keeper, + } +} + +// ExportGenesis implements module.AppModule +func (am AppModule) ExportGenesis(ctx sdk.Context, cdc codec.JSONCodec) json.RawMessage { + genState := am.keeper.ExportGenesis(ctx) + return cdc.MustMarshalJSON(genState) +} + +// InitGenesis implements module.AppModule +func (am AppModule) InitGenesis(ctx sdk.Context, cdc codec.JSONCodec, data json.RawMessage) []abci.ValidatorUpdate { + var genState ibctransfer.GenesisState + cdc.MustUnmarshalJSON(data, &genState) + am.keeper.InitGenesis(ctx, genState) + + return []abci.ValidatorUpdate{} +} + +// ConsensusVersion implements module.AppModule +func (AppModule) ConsensusVersion() uint64 { + return 1 +} + +// LegacyQuerierHandler implements module.AppModule +func (AppModule) LegacyQuerierHandler(*codec.LegacyAmino) sdk.Querier { + return nil +} + +// QuerierRoute implements module.AppModule +func (AppModule) QuerierRoute() string { return "" } + +// RegisterInvariants implements module.AppModule +func (AppModule) RegisterInvariants(sdk.InvariantRegistry) {} + +// RegisterServices implements module.AppModule +func (am AppModule) RegisterServices(cfg module.Configurator) { + ibctransfer.RegisterMsgServer(cfg.MsgServer(), keeper.NewMsgServerImpl(am.keeper)) + ibctransfer.RegisterQueryServer(cfg.QueryServer(), keeper.NewQuerier(am.keeper)) +} + +// Route implements module.AppModule +func (AppModule) Route() sdk.Route { + return sdk.Route{} +} + +// BeginBlock executes all ABCI BeginBlock logic respective to the x/uibc module. +func (am AppModule) BeginBlock(ctx sdk.Context, _ abci.RequestBeginBlock) { + BeginBlock(ctx, am.keeper) +} + +// EndBlock executes all ABCI EndBlock logic respective to the x/uibc module. +// It returns no validator updates. +func (am AppModule) EndBlock(ctx sdk.Context, _ abci.RequestEndBlock) []abci.ValidatorUpdate { + return EndBlocker(ctx, am.keeper) +} diff --git a/x/uibc/msg.go b/x/uibc/msg.go new file mode 100644 index 0000000000..1533d12ed1 --- /dev/null +++ b/x/uibc/msg.go @@ -0,0 +1,114 @@ +package uibc + +import ( + "encoding/json" + + sdk "github.com/cosmos/cosmos-sdk/types" + sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" + + "github.com/umee-network/umee/v4/util/checkers" +) + +var ( + _ sdk.Msg = &MsgGovUpdateQuota{} + _ sdk.Msg = &MsgGovSetIBCPause{} +) + +// GetTitle implements govv1b1.Content interface. +func (msg *MsgGovUpdateQuota) GetTitle() string { return msg.Title } + +// GetDescription implements govv1b1.Content interface. +func (msg *MsgGovUpdateQuota) GetDescription() string { return msg.Description } + +// Route implements Msg +func (msg MsgGovUpdateQuota) Route() string { return RouterKey } + +// Type implements Msg +func (msg MsgGovUpdateQuota) Type() string { return sdk.MsgTypeURL(&msg) } + +// String implements the Stringer interface. +func (msg *MsgGovUpdateQuota) String() string { + out, _ := json.Marshal(msg) + return string(out) +} + +// ValidateBasic implements Msg +func (msg *MsgGovUpdateQuota) ValidateBasic() error { + if _, err := sdk.AccAddressFromBech32(msg.Authority); err != nil { + return sdkerrors.Wrap(err, "invalid authority address") + } + + if msg.Total.IsNil() || !msg.Total.IsPositive() { + return sdkerrors.ErrInvalidRequest.Wrap("total quota must be positive") + } + + if msg.PerDenom.IsNil() || !msg.PerDenom.IsPositive() { + return sdkerrors.ErrInvalidRequest.Wrap("quota per denom must be positive") + } + + return checkers.ValidateProposal(msg.Title, msg.Description, msg.Authority) +} + +// GetSignBytes implements Msg +func (msg *MsgGovUpdateQuota) GetSignBytes() []byte { + return sdk.MustSortJSON(ModuleCdc.MustMarshalJSON(msg)) +} + +// GetSigners implements Msg +func (msg *MsgGovUpdateQuota) GetSigners() []sdk.AccAddress { + return checkers.Signers(msg.Authority) +} + +// GetTitle implements govv1b1.Content interface. +func (msg *MsgGovSetIBCPause) GetTitle() string { return msg.Title } + +// GetDescription implements govv1b1.Content interface. +func (msg *MsgGovSetIBCPause) GetDescription() string { return msg.Description } + +// Route implements Msg +func (msg MsgGovSetIBCPause) Route() string { return RouterKey } + +// Type implements Msg +func (msg MsgGovSetIBCPause) Type() string { return sdk.MsgTypeURL(&msg) } + +// String implements the Stringer interface. +func (msg *MsgGovSetIBCPause) String() string { + out, _ := json.Marshal(msg) + return string(out) +} + +// ValidateBasic implements Msg +func (msg *MsgGovSetIBCPause) ValidateBasic() error { + if _, err := sdk.AccAddressFromBech32(msg.Authority); err != nil { + return sdkerrors.Wrap(err, "invalid authority address") + } + + if err := validateIBCTransferStatus(msg.IbcPauseStatus); err != nil { + return err + } + + return checkers.ValidateProposal(msg.Title, msg.Description, msg.Authority) +} + +// GetSignBytes implements Msg +func (msg *MsgGovSetIBCPause) GetSignBytes() []byte { + bz := ModuleCdc.MustMarshalJSON(msg) + return sdk.MustSortJSON(bz) +} + +// GetSigners implements Msg +func (msg *MsgGovSetIBCPause) GetSigners() []sdk.AccAddress { + return checkers.Signers(msg.Authority) +} + +func (q *Quota) Validate() error { + if len(q.IbcDenom) == 0 { + return sdkerrors.ErrInvalidRequest.Wrap("ibc denom shouldn't be empty") + } + + if q.OutflowSum.IsNil() || q.OutflowSum.IsNegative() { + return sdkerrors.ErrInvalidRequest.Wrap("ibc denom quota expires shouldn't be empty") + } + + return nil +} diff --git a/x/uibc/params.go b/x/uibc/params.go new file mode 100644 index 0000000000..f9ffea7517 --- /dev/null +++ b/x/uibc/params.go @@ -0,0 +1,81 @@ +package uibc + +import ( + fmt "fmt" + "time" + + sdk "github.com/cosmos/cosmos-sdk/types" +) + +const ( + // Default ibc-transfer quota is disabled + DefaultIBCPause = IBCTransferStatus_IBC_TRANSFER_STATUS_DISABLED + // 24 hours time interval for ibc-transfer quota limit + DefaultQuotaDurationPerDenom = 60 * 60 * 24 +) + +var ( + // 1M USD daily limit for all denoms + DefaultTotalQuota = sdk.MustNewDecFromStr("1000000") + // 600K USD dail limit for each denom + DefaultQuotaPerIBCDenom = sdk.MustNewDecFromStr("600000") +) + +// DefaultParams returns default genesis params +func DefaultParams() Params { + return Params{ + IbcPause: DefaultIBCPause, + TotalQuota: DefaultTotalQuota, + TokenQuota: DefaultQuotaPerIBCDenom, + QuotaDuration: DefaultQuotaDurationPerDenom, + } +} + +func (p Params) Validate() error { + if err := validateIBCTransferStatus(p.IbcPause); err != nil { + return err + } + + if err := validateQuotaDuration(p.QuotaDuration); err != nil { + return err + } + + if err := validateQuota(p.TotalQuota, "total quota"); err != nil { + return err + } + + if err := validateQuota(p.TokenQuota, "quota per token"); err != nil { + return err + } + + if p.TotalQuota.LT(p.TokenQuota) { + return fmt.Errorf("token quota shouldn't be less than quota per denom") + } + + return nil +} + +func validateIBCTransferStatus(status IBCTransferStatus) error { + if status == IBCTransferStatus_IBC_TRANSFER_STATUS_DISABLED || + status == IBCTransferStatus_IBC_TRANSFER_STATUS_ENABLED || + status == IBCTransferStatus_IBC_TRANSFER_STATUS_PAUSED { + return nil + } + + return fmt.Errorf("invalid ibc-transfer status : %s", status.String()) +} + +func validateQuotaDuration(d time.Duration) error { + if d <= 0 { + return fmt.Errorf("quota duration time must be positive: %d", d) + } + + return nil +} + +func validateQuota(q sdk.Dec, typ string) error { + if q.IsNil() || q.IsNegative() { + return fmt.Errorf("%s must be not negative: %s", typ, q) + } + return nil +} diff --git a/x/uibc/params_test.go b/x/uibc/params_test.go new file mode 100644 index 0000000000..2a5c519195 --- /dev/null +++ b/x/uibc/params_test.go @@ -0,0 +1,29 @@ +package uibc + +import ( + "testing" + + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/stretchr/testify/require" +) + +func TestValidateIBCTransferStatus(t *testing.T) { + err := validateIBCTransferStatus(4) + require.ErrorContains(t, err, "invalid ibc-transfer status") + err = validateIBCTransferStatus(2) + require.NoError(t, err) +} + +func TestValidateQuotaDuration(t *testing.T) { + err := validateQuotaDuration(-1) + require.ErrorContains(t, err, "quota duration time must be positive") + err = validateQuotaDuration(10) + require.NoError(t, err) +} + +func TestValidateQuota(t *testing.T) { + err := validateQuota(sdk.NewDec(-1), "s") + require.ErrorContains(t, err, "must be not negative") + err = validateQuota(sdk.NewDec(100), "s") + require.NoError(t, err) +} diff --git a/x/uibc/query.pb.go b/x/uibc/query.pb.go new file mode 100644 index 0000000000..0c1b477f67 --- /dev/null +++ b/x/uibc/query.pb.go @@ -0,0 +1,913 @@ +// Code generated by protoc-gen-gogo. DO NOT EDIT. +// source: umee/uibc/v1/query.proto + +package uibc + +import ( + context "context" + fmt "fmt" + _ "github.com/gogo/protobuf/gogoproto" + grpc1 "github.com/gogo/protobuf/grpc" + proto "github.com/gogo/protobuf/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 + +// QueryParams defines the request structure for the Params gRPC service +// handler. +type QueryParams struct { +} + +func (m *QueryParams) Reset() { *m = QueryParams{} } +func (m *QueryParams) String() string { return proto.CompactTextString(m) } +func (*QueryParams) ProtoMessage() {} +func (*QueryParams) Descriptor() ([]byte, []int) { + return fileDescriptor_2ca7e17b0958935d, []int{0} +} +func (m *QueryParams) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *QueryParams) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_QueryParams.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 *QueryParams) XXX_Merge(src proto.Message) { + xxx_messageInfo_QueryParams.Merge(m, src) +} +func (m *QueryParams) XXX_Size() int { + return m.Size() +} +func (m *QueryParams) XXX_DiscardUnknown() { + xxx_messageInfo_QueryParams.DiscardUnknown(m) +} + +var xxx_messageInfo_QueryParams proto.InternalMessageInfo + +// QueryParamsResponse defines the response structure for the Params gRPC +// service handler. +type QueryParamsResponse struct { + 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_2ca7e17b0958935d, []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 + +// QueryQuota defines request type for query the quota of denoms +type QueryQuota struct { + Denom string `protobuf:"bytes,1,opt,name=denom,proto3" json:"denom,omitempty"` +} + +func (m *QueryQuota) Reset() { *m = QueryQuota{} } +func (m *QueryQuota) String() string { return proto.CompactTextString(m) } +func (*QueryQuota) ProtoMessage() {} +func (*QueryQuota) Descriptor() ([]byte, []int) { + return fileDescriptor_2ca7e17b0958935d, []int{2} +} +func (m *QueryQuota) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *QueryQuota) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_QueryQuota.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 *QueryQuota) XXX_Merge(src proto.Message) { + xxx_messageInfo_QueryQuota.Merge(m, src) +} +func (m *QueryQuota) XXX_Size() int { + return m.Size() +} +func (m *QueryQuota) XXX_DiscardUnknown() { + xxx_messageInfo_QueryQuota.DiscardUnknown(m) +} + +var xxx_messageInfo_QueryQuota proto.InternalMessageInfo + +// QueryQuotaResponse defines response type of Query/Quota +type QueryQuotaResponse struct { + Quota []Quota `protobuf:"bytes,1,rep,name=quota,proto3" json:"quota"` +} + +func (m *QueryQuotaResponse) Reset() { *m = QueryQuotaResponse{} } +func (m *QueryQuotaResponse) String() string { return proto.CompactTextString(m) } +func (*QueryQuotaResponse) ProtoMessage() {} +func (*QueryQuotaResponse) Descriptor() ([]byte, []int) { + return fileDescriptor_2ca7e17b0958935d, []int{3} +} +func (m *QueryQuotaResponse) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *QueryQuotaResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_QueryQuotaResponse.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 *QueryQuotaResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_QueryQuotaResponse.Merge(m, src) +} +func (m *QueryQuotaResponse) XXX_Size() int { + return m.Size() +} +func (m *QueryQuotaResponse) XXX_DiscardUnknown() { + xxx_messageInfo_QueryQuotaResponse.DiscardUnknown(m) +} + +var xxx_messageInfo_QueryQuotaResponse proto.InternalMessageInfo + +func init() { + proto.RegisterType((*QueryParams)(nil), "umee.uibc.v1.QueryParams") + proto.RegisterType((*QueryParamsResponse)(nil), "umee.uibc.v1.QueryParamsResponse") + proto.RegisterType((*QueryQuota)(nil), "umee.uibc.v1.QueryQuota") + proto.RegisterType((*QueryQuotaResponse)(nil), "umee.uibc.v1.QueryQuotaResponse") +} + +func init() { proto.RegisterFile("umee/uibc/v1/query.proto", fileDescriptor_2ca7e17b0958935d) } + +var fileDescriptor_2ca7e17b0958935d = []byte{ + // 356 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x74, 0x91, 0xcf, 0x4e, 0xf2, 0x40, + 0x14, 0xc5, 0xdb, 0xef, 0x13, 0x12, 0x07, 0xdd, 0x0c, 0x8d, 0xa9, 0x15, 0x47, 0xac, 0x89, 0x61, + 0x63, 0x27, 0x54, 0x9f, 0x80, 0xe8, 0xc2, 0x9d, 0xb0, 0x74, 0x57, 0x60, 0x52, 0x1a, 0x6d, 0x6f, + 0xed, 0x1f, 0xd4, 0x18, 0x37, 0x3e, 0x81, 0x89, 0x2f, 0xc5, 0x92, 0xc4, 0x85, 0xae, 0x8c, 0x82, + 0x0f, 0x62, 0xe6, 0x0e, 0x22, 0xa0, 0xec, 0x66, 0xe6, 0x9c, 0x39, 0xbf, 0x73, 0x67, 0x88, 0x99, + 0x87, 0x42, 0xf0, 0x3c, 0x68, 0x77, 0x78, 0xbf, 0xce, 0xaf, 0x72, 0x91, 0xdc, 0x3a, 0x71, 0x02, + 0x19, 0xd0, 0x35, 0xa9, 0x38, 0x52, 0x71, 0xfa, 0x75, 0xab, 0xe2, 0x03, 0xf8, 0x97, 0x82, 0x7b, + 0x71, 0xc0, 0xbd, 0x28, 0x82, 0xcc, 0xcb, 0x02, 0x88, 0x52, 0xe5, 0xb5, 0x0c, 0x1f, 0x7c, 0xc0, + 0x25, 0x97, 0xab, 0xc9, 0xe9, 0x62, 0x36, 0x64, 0x9e, 0x52, 0xec, 0x75, 0x52, 0x6a, 0x4a, 0xd4, + 0x99, 0x97, 0x78, 0x61, 0x6a, 0x9f, 0x92, 0xf2, 0xcc, 0xb6, 0x25, 0xd2, 0x18, 0xa2, 0x54, 0x50, + 0x97, 0x14, 0x63, 0x3c, 0x31, 0xf5, 0xaa, 0x5e, 0x2b, 0xb9, 0x86, 0x33, 0x5b, 0xc9, 0x51, 0xee, + 0xc6, 0xca, 0xe0, 0x6d, 0x47, 0x6b, 0x4d, 0x9c, 0xb6, 0x4d, 0x08, 0x46, 0x35, 0x25, 0x8d, 0x1a, + 0xa4, 0xd0, 0x15, 0x11, 0x84, 0x18, 0xb0, 0xda, 0x52, 0x1b, 0xfb, 0x84, 0xd0, 0x1f, 0xcf, 0x94, + 0xc6, 0x49, 0x01, 0x2b, 0x9a, 0x7a, 0xf5, 0x7f, 0xad, 0xe4, 0x96, 0xe7, 0x61, 0xe8, 0x9d, 0xb0, + 0x94, 0xcf, 0x7d, 0xd1, 0x49, 0x01, 0x73, 0x68, 0x97, 0x14, 0x55, 0x19, 0xba, 0xb9, 0x78, 0x6b, + 0x3a, 0x95, 0xb5, 0xbb, 0x54, 0xfa, 0xae, 0x60, 0x57, 0x1e, 0x9e, 0x3f, 0x9f, 0xfe, 0x6d, 0x50, + 0x83, 0xcf, 0xbd, 0x9c, 0x1a, 0x8d, 0xf6, 0x24, 0x4e, 0x4e, 0x65, 0xfe, 0x91, 0x84, 0x8a, 0x55, + 0x5d, 0xa6, 0x4c, 0x11, 0x7b, 0x88, 0xd8, 0xa6, 0x5b, 0xfc, 0xf7, 0xe7, 0xf0, 0x3b, 0x7c, 0x9f, + 0xfb, 0xc6, 0xf1, 0xe0, 0x83, 0x69, 0x83, 0x11, 0xd3, 0x87, 0x23, 0xa6, 0xbf, 0x8f, 0x98, 0xfe, + 0x38, 0x66, 0xda, 0x70, 0xcc, 0xb4, 0xd7, 0x31, 0xd3, 0xce, 0xf7, 0xfd, 0x20, 0xeb, 0xe5, 0x6d, + 0xa7, 0x03, 0x21, 0x86, 0x1c, 0x44, 0x22, 0xbb, 0x86, 0xe4, 0x42, 0x25, 0xf6, 0x8f, 0xf8, 0x0d, + 0xc6, 0xb6, 0x8b, 0xf8, 0xd7, 0x87, 0x5f, 0x01, 0x00, 0x00, 0xff, 0xff, 0x02, 0x64, 0xc4, 0x56, + 0x63, 0x02, 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 { + // Params queries the parameters of the x/uibc module. + Params(ctx context.Context, in *QueryParams, opts ...grpc.CallOption) (*QueryParamsResponse, error) + // Quota queries the rate limits of ibc denoms. + // If denom is empty, returns quota for all tokens. + Quota(ctx context.Context, in *QueryQuota, opts ...grpc.CallOption) (*QueryQuotaResponse, error) +} + +type queryClient struct { + cc grpc1.ClientConn +} + +func NewQueryClient(cc grpc1.ClientConn) QueryClient { + return &queryClient{cc} +} + +func (c *queryClient) Params(ctx context.Context, in *QueryParams, opts ...grpc.CallOption) (*QueryParamsResponse, error) { + out := new(QueryParamsResponse) + err := c.cc.Invoke(ctx, "/umee.uibc.v1.Query/Params", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *queryClient) Quota(ctx context.Context, in *QueryQuota, opts ...grpc.CallOption) (*QueryQuotaResponse, error) { + out := new(QueryQuotaResponse) + err := c.cc.Invoke(ctx, "/umee.uibc.v1.Query/Quota", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +// QueryServer is the server API for Query service. +type QueryServer interface { + // Params queries the parameters of the x/uibc module. + Params(context.Context, *QueryParams) (*QueryParamsResponse, error) + // Quota queries the rate limits of ibc denoms. + // If denom is empty, returns quota for all tokens. + Quota(context.Context, *QueryQuota) (*QueryQuotaResponse, error) +} + +// UnimplementedQueryServer can be embedded to have forward compatible implementations. +type UnimplementedQueryServer struct { +} + +func (*UnimplementedQueryServer) Params(ctx context.Context, req *QueryParams) (*QueryParamsResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method Params not implemented") +} +func (*UnimplementedQueryServer) Quota(ctx context.Context, req *QueryQuota) (*QueryQuotaResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method Quota 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(QueryParams) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(QueryServer).Params(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/umee.uibc.v1.Query/Params", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(QueryServer).Params(ctx, req.(*QueryParams)) + } + return interceptor(ctx, in, info, handler) +} + +func _Query_Quota_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(QueryQuota) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(QueryServer).Quota(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/umee.uibc.v1.Query/Quota", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(QueryServer).Quota(ctx, req.(*QueryQuota)) + } + return interceptor(ctx, in, info, handler) +} + +var _Query_serviceDesc = grpc.ServiceDesc{ + ServiceName: "umee.uibc.v1.Query", + HandlerType: (*QueryServer)(nil), + Methods: []grpc.MethodDesc{ + { + MethodName: "Params", + Handler: _Query_Params_Handler, + }, + { + MethodName: "Quota", + Handler: _Query_Quota_Handler, + }, + }, + Streams: []grpc.StreamDesc{}, + Metadata: "umee/uibc/v1/query.proto", +} + +func (m *QueryParams) 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 *QueryParams) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *QueryParams) 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 *QueryQuota) 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 *QueryQuota) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *QueryQuota) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if len(m.Denom) > 0 { + i -= len(m.Denom) + copy(dAtA[i:], m.Denom) + i = encodeVarintQuery(dAtA, i, uint64(len(m.Denom))) + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func (m *QueryQuotaResponse) 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 *QueryQuotaResponse) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *QueryQuotaResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if len(m.Quota) > 0 { + for iNdEx := len(m.Quota) - 1; iNdEx >= 0; iNdEx-- { + { + size, err := m.Quota[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 *QueryParams) 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 *QueryQuota) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.Denom) + if l > 0 { + n += 1 + l + sovQuery(uint64(l)) + } + return n +} + +func (m *QueryQuotaResponse) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if len(m.Quota) > 0 { + for _, e := range m.Quota { + l = e.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 *QueryParams) 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: QueryParams: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: QueryParams: 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 *QueryQuota) 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: QueryQuota: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: QueryQuota: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Denom", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + 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 ErrInvalidLengthQuery + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthQuery + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Denom = string(dAtA[iNdEx:postIndex]) + 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 *QueryQuotaResponse) 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: QueryQuotaResponse: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: QueryQuotaResponse: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Quota", 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.Quota = append(m.Quota, Quota{}) + if err := m.Quota[len(m.Quota)-1].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/uibc/query.pb.gw.go b/x/uibc/query.pb.gw.go new file mode 100644 index 0000000000..3f7919a464 --- /dev/null +++ b/x/uibc/query.pb.gw.go @@ -0,0 +1,254 @@ +// Code generated by protoc-gen-grpc-gateway. DO NOT EDIT. +// source: umee/uibc/v1/query.proto + +/* +Package uibc is a reverse proxy. + +It translates gRPC into RESTful JSON APIs. +*/ +package uibc + +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 QueryParams + 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 QueryParams + var metadata runtime.ServerMetadata + + msg, err := server.Params(ctx, &protoReq) + return msg, metadata, err + +} + +func request_Query_Quota_0(ctx context.Context, marshaler runtime.Marshaler, client QueryClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq QueryQuota + var metadata runtime.ServerMetadata + + var ( + val string + ok bool + err error + _ = err + ) + + val, ok = pathParams["denom"] + if !ok { + return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "denom") + } + + protoReq.Denom, err = runtime.String(val) + + if err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "denom", err) + } + + msg, err := client.Quota(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) + return msg, metadata, err + +} + +func local_request_Query_Quota_0(ctx context.Context, marshaler runtime.Marshaler, server QueryServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq QueryQuota + var metadata runtime.ServerMetadata + + var ( + val string + ok bool + err error + _ = err + ) + + val, ok = pathParams["denom"] + if !ok { + return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "denom") + } + + protoReq.Denom, err = runtime.String(val) + + if err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "denom", err) + } + + msg, err := server.Quota(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_Quota_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_Quota_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_Quota_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_Quota_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_Quota_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_Quota_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{"umee", "uibc", "v1", "params"}, "", runtime.AssumeColonVerbOpt(false))) + + pattern_Query_Quota_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 2, 3, 1, 0, 4, 1, 5, 4}, []string{"umee", "uibc", "v1", "quota", "denom"}, "", runtime.AssumeColonVerbOpt(false))) +) + +var ( + forward_Query_Params_0 = runtime.ForwardResponseMessage + + forward_Query_Quota_0 = runtime.ForwardResponseMessage +) diff --git a/x/uibc/quota.pb.go b/x/uibc/quota.pb.go new file mode 100644 index 0000000000..7e7b3607f6 --- /dev/null +++ b/x/uibc/quota.pb.go @@ -0,0 +1,734 @@ +// Code generated by protoc-gen-gogo. DO NOT EDIT. +// source: umee/uibc/v1/quota.proto + +package uibc + +import ( + fmt "fmt" + _ "github.com/cosmos/cosmos-proto" + github_com_cosmos_cosmos_sdk_types "github.com/cosmos/cosmos-sdk/types" + _ "github.com/gogo/protobuf/gogoproto" + proto "github.com/gogo/protobuf/proto" + github_com_gogo_protobuf_types "github.com/gogo/protobuf/types" + _ "google.golang.org/protobuf/types/known/durationpb" + io "io" + math "math" + math_bits "math/bits" + time "time" +) + +// Reference imports to suppress errors if they are not otherwise used. +var _ = proto.Marshal +var _ = fmt.Errorf +var _ = math.Inf +var _ = time.Kitchen + +// 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 + +// IBCTransferStatus status of ibc-transfer +type IBCTransferStatus int32 + +const ( + // UNSPECIFIED defines a no-op status. + IBCTransferStatus_IBC_TRANSFER_STATUS_UNSPECIFIED IBCTransferStatus = 0 + // DISABLED defines the quota checking diabled for ibc-transfer. + IBCTransferStatus_IBC_TRANSFER_STATUS_DISABLED IBCTransferStatus = 1 + // ENABLED defines the enable quota checking for ibc-transfer. + IBCTransferStatus_IBC_TRANSFER_STATUS_ENABLED IBCTransferStatus = 2 + // PAUSED defines pause the ibc-transfer from app. + IBCTransferStatus_IBC_TRANSFER_STATUS_PAUSED IBCTransferStatus = 3 +) + +var IBCTransferStatus_name = map[int32]string{ + 0: "IBC_TRANSFER_STATUS_UNSPECIFIED", + 1: "IBC_TRANSFER_STATUS_DISABLED", + 2: "IBC_TRANSFER_STATUS_ENABLED", + 3: "IBC_TRANSFER_STATUS_PAUSED", +} + +var IBCTransferStatus_value = map[string]int32{ + "IBC_TRANSFER_STATUS_UNSPECIFIED": 0, + "IBC_TRANSFER_STATUS_DISABLED": 1, + "IBC_TRANSFER_STATUS_ENABLED": 2, + "IBC_TRANSFER_STATUS_PAUSED": 3, +} + +func (x IBCTransferStatus) String() string { + return proto.EnumName(IBCTransferStatus_name, int32(x)) +} + +func (IBCTransferStatus) EnumDescriptor() ([]byte, []int) { + return fileDescriptor_651be1a0280abcb6, []int{0} +} + +// Quota stores current sum of IBC outflow transfers of IBC Denom. +type Quota struct { + // ibc_denom defines the ibc denom + IbcDenom string `protobuf:"bytes,1,opt,name=ibc_denom,json=ibcDenom,proto3" json:"ibc_denom,omitempty"` + // outflow_sum defines the sum of price (USD) value of outflow tokens through ibc-transfer + OutflowSum github_com_cosmos_cosmos_sdk_types.Dec `protobuf:"bytes,3,opt,name=outflow_sum,json=outflowSum,proto3,customtype=github.com/cosmos/cosmos-sdk/types.Dec" json:"outflow_sum"` +} + +func (m *Quota) Reset() { *m = Quota{} } +func (m *Quota) String() string { return proto.CompactTextString(m) } +func (*Quota) ProtoMessage() {} +func (*Quota) Descriptor() ([]byte, []int) { + return fileDescriptor_651be1a0280abcb6, []int{0} +} +func (m *Quota) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *Quota) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_Quota.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 *Quota) XXX_Merge(src proto.Message) { + xxx_messageInfo_Quota.Merge(m, src) +} +func (m *Quota) XXX_Size() int { + return m.Size() +} +func (m *Quota) XXX_DiscardUnknown() { + xxx_messageInfo_Quota.DiscardUnknown(m) +} + +var xxx_messageInfo_Quota proto.InternalMessageInfo + +func (m *Quota) GetIbcDenom() string { + if m != nil { + return m.IbcDenom + } + return "" +} + +// Params of x/uibc module +type Params struct { + // ibc_status defines the wethever ibc-transfer enabled, disbaled or paused + IbcPause IBCTransferStatus `protobuf:"varint,1,opt,name=ibc_pause,json=ibcPause,proto3,enum=umee.uibc.v1.IBCTransferStatus" json:"ibc_pause,omitempty"` + // total_quota defines the total outflow limit of ibc-transfer in USD + TotalQuota github_com_cosmos_cosmos_sdk_types.Dec `protobuf:"bytes,2,opt,name=total_quota,json=totalQuota,proto3,customtype=github.com/cosmos/cosmos-sdk/types.Dec" json:"total_quota"` + // token_quota defines the outflow limit per token in USD + TokenQuota github_com_cosmos_cosmos_sdk_types.Dec `protobuf:"bytes,3,opt,name=token_quota,json=tokenQuota,proto3,customtype=github.com/cosmos/cosmos-sdk/types.Dec" json:"token_quota"` + // quota_duration defines quota expires for each ibc-transfer denom in seconds + QuotaDuration time.Duration `protobuf:"bytes,4,opt,name=quota_duration,json=quotaDuration,proto3,stdduration" json:"quota_duration,omitempty" yaml:"quota_duration"` +} + +func (m *Params) Reset() { *m = Params{} } +func (m *Params) String() string { return proto.CompactTextString(m) } +func (*Params) ProtoMessage() {} +func (*Params) Descriptor() ([]byte, []int) { + return fileDescriptor_651be1a0280abcb6, []int{1} +} +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) GetIbcPause() IBCTransferStatus { + if m != nil { + return m.IbcPause + } + return IBCTransferStatus_IBC_TRANSFER_STATUS_UNSPECIFIED +} + +func (m *Params) GetQuotaDuration() time.Duration { + if m != nil { + return m.QuotaDuration + } + return 0 +} + +func init() { + proto.RegisterEnum("umee.uibc.v1.IBCTransferStatus", IBCTransferStatus_name, IBCTransferStatus_value) + proto.RegisterType((*Quota)(nil), "umee.uibc.v1.Quota") + proto.RegisterType((*Params)(nil), "umee.uibc.v1.Params") +} + +func init() { proto.RegisterFile("umee/uibc/v1/quota.proto", fileDescriptor_651be1a0280abcb6) } + +var fileDescriptor_651be1a0280abcb6 = []byte{ + // 511 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xac, 0x53, 0xc1, 0x8b, 0xd3, 0x4e, + 0x18, 0xed, 0x6c, 0x7f, 0xbf, 0xc5, 0x9d, 0xd5, 0xa5, 0x06, 0x85, 0x6c, 0x57, 0x92, 0x52, 0x41, + 0x16, 0xb1, 0x13, 0x76, 0xf5, 0x24, 0x2b, 0xd8, 0x34, 0x59, 0x08, 0x48, 0xa9, 0x49, 0x7b, 0x11, + 0x24, 0x24, 0xe9, 0x34, 0x86, 0x76, 0x32, 0x35, 0x99, 0xe9, 0xda, 0x93, 0x07, 0xf1, 0xee, 0x51, + 0xf0, 0xdf, 0xf0, 0x8f, 0xd8, 0xe3, 0xe2, 0x49, 0x3c, 0x54, 0x69, 0x6f, 0x1e, 0xfd, 0x0b, 0x64, + 0x26, 0x29, 0xec, 0x62, 0x8f, 0x7b, 0x4a, 0xbe, 0x79, 0xef, 0x7b, 0xdf, 0xe3, 0x7d, 0x33, 0x50, + 0xe5, 0x04, 0x63, 0x83, 0x27, 0x61, 0x64, 0xcc, 0x8e, 0x8c, 0xb7, 0x9c, 0xb2, 0x00, 0x4d, 0x33, + 0xca, 0xa8, 0x72, 0x53, 0x20, 0x48, 0x20, 0x68, 0x76, 0x54, 0xbf, 0x13, 0xd3, 0x98, 0x4a, 0xc0, + 0x10, 0x7f, 0x05, 0xa7, 0xae, 0xc5, 0x94, 0xc6, 0x13, 0x6c, 0xc8, 0x2a, 0xe4, 0x23, 0x63, 0xc8, + 0xb3, 0x80, 0x25, 0x34, 0x2d, 0xf1, 0xfd, 0x88, 0xe6, 0x84, 0xe6, 0x7e, 0xd1, 0x58, 0x14, 0x05, + 0xd4, 0xfc, 0x00, 0xe0, 0xff, 0x2f, 0xc5, 0x38, 0xe5, 0x00, 0xee, 0x24, 0x61, 0xe4, 0x0f, 0x71, + 0x4a, 0x89, 0x0a, 0x1a, 0xe0, 0x70, 0xc7, 0xbd, 0x91, 0x84, 0x91, 0x25, 0x6a, 0xe5, 0x35, 0xdc, + 0xa5, 0x9c, 0x8d, 0x26, 0xf4, 0xcc, 0xcf, 0x39, 0x51, 0xab, 0x02, 0x36, 0x4f, 0xce, 0x17, 0x7a, + 0xe5, 0xc7, 0x42, 0x7f, 0x10, 0x27, 0xec, 0x0d, 0x0f, 0x51, 0x44, 0x49, 0x29, 0x5e, 0x7e, 0x5a, + 0xf9, 0x70, 0x6c, 0xb0, 0xf9, 0x14, 0xe7, 0xc8, 0xc2, 0xd1, 0xb7, 0xaf, 0x2d, 0x58, 0xce, 0xb6, + 0x70, 0xe4, 0xc2, 0x52, 0xd0, 0xe3, 0xa4, 0xf9, 0xb1, 0x0a, 0xb7, 0x7b, 0x41, 0x16, 0x90, 0x5c, + 0x39, 0x29, 0x6c, 0x4c, 0x03, 0x9e, 0x63, 0x69, 0x63, 0xef, 0x58, 0x47, 0x97, 0x33, 0x40, 0x8e, + 0xd9, 0xe9, 0x67, 0x41, 0x9a, 0x8f, 0x70, 0xe6, 0xb1, 0x80, 0xf1, 0x5c, 0xfa, 0xec, 0x89, 0x06, + 0xe1, 0x93, 0x51, 0x16, 0x4c, 0x7c, 0x19, 0xa1, 0xba, 0x75, 0x1d, 0x3e, 0xa5, 0x60, 0x91, 0x91, + 0x94, 0x1f, 0xe3, 0xb4, 0x94, 0xaf, 0x5e, 0x8f, 0xfc, 0x18, 0xa7, 0x85, 0xfc, 0x7b, 0xb8, 0x27, + 0x85, 0xfd, 0xf5, 0xfe, 0xd4, 0xff, 0x1a, 0xe0, 0x70, 0xf7, 0x78, 0x1f, 0x15, 0x0b, 0x46, 0xeb, + 0x05, 0x23, 0xab, 0x24, 0x98, 0xcf, 0xc4, 0xf0, 0xdf, 0x0b, 0x5d, 0xbd, 0xda, 0xf8, 0x88, 0x92, + 0x84, 0x61, 0x32, 0x65, 0xf3, 0x3f, 0x0b, 0xfd, 0xee, 0x3c, 0x20, 0x93, 0xa7, 0xcd, 0xab, 0x8c, + 0xe6, 0xe7, 0x9f, 0x3a, 0x70, 0x6f, 0xc9, 0xc3, 0xb5, 0xda, 0xc3, 0x2f, 0x00, 0xde, 0xfe, 0x27, + 0x5e, 0xe5, 0x3e, 0xd4, 0x1d, 0xb3, 0xe3, 0xf7, 0xdd, 0x76, 0xd7, 0x3b, 0xb5, 0x5d, 0xdf, 0xeb, + 0xb7, 0xfb, 0x03, 0xcf, 0x1f, 0x74, 0xbd, 0x9e, 0xdd, 0x71, 0x4e, 0x1d, 0xdb, 0xaa, 0x55, 0x94, + 0x06, 0xbc, 0xb7, 0x89, 0x64, 0x39, 0x5e, 0xdb, 0x7c, 0x61, 0x5b, 0x35, 0xa0, 0xe8, 0xf0, 0x60, + 0x13, 0xc3, 0xee, 0x16, 0x84, 0x2d, 0x45, 0x83, 0xf5, 0x4d, 0x84, 0x5e, 0x7b, 0xe0, 0xd9, 0x56, + 0xad, 0x6a, 0x3e, 0x3f, 0x5f, 0x6a, 0xe0, 0x62, 0xa9, 0x81, 0x5f, 0x4b, 0x0d, 0x7c, 0x5a, 0x69, + 0x95, 0x8b, 0x95, 0x56, 0xf9, 0xbe, 0xd2, 0x2a, 0xaf, 0x2e, 0x47, 0x2f, 0xee, 0x4a, 0x2b, 0xc5, + 0xec, 0x8c, 0x66, 0x63, 0x59, 0x18, 0xb3, 0x27, 0xc6, 0x3b, 0xf9, 0xb6, 0xc2, 0x6d, 0x19, 0xe0, + 0xe3, 0xbf, 0x01, 0x00, 0x00, 0xff, 0xff, 0xf8, 0x41, 0x84, 0x5e, 0x6f, 0x03, 0x00, 0x00, +} + +func (m *Quota) 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 *Quota) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *Quota) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + { + size := m.OutflowSum.Size() + i -= size + if _, err := m.OutflowSum.MarshalTo(dAtA[i:]); err != nil { + return 0, err + } + i = encodeVarintQuota(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x1a + if len(m.IbcDenom) > 0 { + i -= len(m.IbcDenom) + copy(dAtA[i:], m.IbcDenom) + i = encodeVarintQuota(dAtA, i, uint64(len(m.IbcDenom))) + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +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 + n1, err1 := github_com_gogo_protobuf_types.StdDurationMarshalTo(m.QuotaDuration, dAtA[i-github_com_gogo_protobuf_types.SizeOfStdDuration(m.QuotaDuration):]) + if err1 != nil { + return 0, err1 + } + i -= n1 + i = encodeVarintQuota(dAtA, i, uint64(n1)) + i-- + dAtA[i] = 0x22 + { + size := m.TokenQuota.Size() + i -= size + if _, err := m.TokenQuota.MarshalTo(dAtA[i:]); err != nil { + return 0, err + } + i = encodeVarintQuota(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x1a + { + size := m.TotalQuota.Size() + i -= size + if _, err := m.TotalQuota.MarshalTo(dAtA[i:]); err != nil { + return 0, err + } + i = encodeVarintQuota(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x12 + if m.IbcPause != 0 { + i = encodeVarintQuota(dAtA, i, uint64(m.IbcPause)) + i-- + dAtA[i] = 0x8 + } + return len(dAtA) - i, nil +} + +func encodeVarintQuota(dAtA []byte, offset int, v uint64) int { + offset -= sovQuota(v) + base := offset + for v >= 1<<7 { + dAtA[offset] = uint8(v&0x7f | 0x80) + v >>= 7 + offset++ + } + dAtA[offset] = uint8(v) + return base +} +func (m *Quota) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.IbcDenom) + if l > 0 { + n += 1 + l + sovQuota(uint64(l)) + } + l = m.OutflowSum.Size() + n += 1 + l + sovQuota(uint64(l)) + return n +} + +func (m *Params) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if m.IbcPause != 0 { + n += 1 + sovQuota(uint64(m.IbcPause)) + } + l = m.TotalQuota.Size() + n += 1 + l + sovQuota(uint64(l)) + l = m.TokenQuota.Size() + n += 1 + l + sovQuota(uint64(l)) + l = github_com_gogo_protobuf_types.SizeOfStdDuration(m.QuotaDuration) + n += 1 + l + sovQuota(uint64(l)) + return n +} + +func sovQuota(x uint64) (n int) { + return (math_bits.Len64(x|1) + 6) / 7 +} +func sozQuota(x uint64) (n int) { + return sovQuota(uint64((x << 1) ^ uint64((int64(x) >> 63)))) +} +func (m *Quota) 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 ErrIntOverflowQuota + } + 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: Quota: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: Quota: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field IbcDenom", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuota + } + 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 ErrInvalidLengthQuota + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthQuota + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.IbcDenom = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 3: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field OutflowSum", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuota + } + 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 ErrInvalidLengthQuota + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthQuota + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if err := m.OutflowSum.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipQuota(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthQuota + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +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 ErrIntOverflowQuota + } + 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 != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field IbcPause", wireType) + } + m.IbcPause = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuota + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.IbcPause |= IBCTransferStatus(b&0x7F) << shift + if b < 0x80 { + break + } + } + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field TotalQuota", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuota + } + 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 ErrInvalidLengthQuota + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthQuota + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if err := m.TotalQuota.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 3: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field TokenQuota", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuota + } + 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 ErrInvalidLengthQuota + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthQuota + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if err := m.TokenQuota.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 4: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field QuotaDuration", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuota + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthQuota + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthQuota + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if err := github_com_gogo_protobuf_types.StdDurationUnmarshal(&m.QuotaDuration, dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipQuota(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthQuota + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func skipQuota(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, ErrIntOverflowQuota + } + 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, ErrIntOverflowQuota + } + 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, ErrIntOverflowQuota + } + 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, ErrInvalidLengthQuota + } + iNdEx += length + case 3: + depth++ + case 4: + if depth == 0 { + return 0, ErrUnexpectedEndOfGroupQuota + } + depth-- + case 5: + iNdEx += 4 + default: + return 0, fmt.Errorf("proto: illegal wireType %d", wireType) + } + if iNdEx < 0 { + return 0, ErrInvalidLengthQuota + } + if depth == 0 { + return iNdEx, nil + } + } + return 0, io.ErrUnexpectedEOF +} + +var ( + ErrInvalidLengthQuota = fmt.Errorf("proto: negative length found during unmarshaling") + ErrIntOverflowQuota = fmt.Errorf("proto: integer overflow") + ErrUnexpectedEndOfGroupQuota = fmt.Errorf("proto: unexpected end of group") +) diff --git a/x/uibc/quota/ibc_module.go b/x/uibc/quota/ibc_module.go new file mode 100644 index 0000000000..b5cbe64917 --- /dev/null +++ b/x/uibc/quota/ibc_module.go @@ -0,0 +1,176 @@ +package quota + +import ( + "encoding/json" + + sdkmath "cosmossdk.io/math" + sdk "github.com/cosmos/cosmos-sdk/types" + sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" + capabilitytypes "github.com/cosmos/cosmos-sdk/x/capability/types" + transfertypes "github.com/cosmos/ibc-go/v5/modules/apps/transfer/types" + channeltypes "github.com/cosmos/ibc-go/v5/modules/core/04-channel/types" + porttypes "github.com/cosmos/ibc-go/v5/modules/core/05-port/types" + "github.com/cosmos/ibc-go/v5/modules/core/exported" + + "github.com/umee-network/umee/v4/x/uibc" + "github.com/umee-network/umee/v4/x/uibc/quota/keeper" +) + +type IBCMiddleware struct { + app porttypes.IBCModule + keeper keeper.Keeper +} + +// NewIBCMiddleware creates a new IBCMiddlware given the keeper and underlying application +func NewIBCMiddleware(app porttypes.IBCModule, k keeper.Keeper) IBCMiddleware { + return IBCMiddleware{ + app: app, + keeper: k, + } +} + +// OnChanOpenInit implements types.Middleware +func (im IBCMiddleware) OnChanOpenInit(ctx sdk.Context, order channeltypes.Order, connectionHops []string, + portID string, channelID string, channelCap *capabilitytypes.Capability, counterparty channeltypes.Counterparty, + version string, +) (string, error) { + return im.app.OnChanOpenInit( + ctx, + order, + connectionHops, + portID, + channelID, + channelCap, + counterparty, + version, + ) +} + +// OnChanOpenTry implements types.Middleware +func (im IBCMiddleware) 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 im.app.OnChanOpenTry( + ctx, order, connectionHops, portID, channelID, channelCap, + counterparty, counterpartyVersion, + ) +} + +// OnChanOpenAck implements types.Middleware +func (im IBCMiddleware) OnChanOpenAck(ctx sdk.Context, portID string, channelID string, counterpartyChannelID string, + counterpartyVersion string, +) error { + return im.app.OnChanOpenAck(ctx, portID, channelID, counterpartyChannelID, counterpartyVersion) +} + +// OnChanOpenConfirm implements types.Middleware +func (im IBCMiddleware) OnChanOpenConfirm(ctx sdk.Context, portID string, channelID string) error { + return im.app.OnChanOpenConfirm(ctx, portID, channelID) +} + +// OnChanCloseInit implements types.Middleware +func (im IBCMiddleware) OnChanCloseInit(ctx sdk.Context, portID string, channelID string) error { + return im.app.OnChanCloseInit(ctx, portID, channelID) +} + +// OnChanCloseConfirm implements types.Middleware +func (im IBCMiddleware) OnChanCloseConfirm(ctx sdk.Context, portID string, channelID string) error { + return im.app.OnChanCloseConfirm(ctx, portID, channelID) +} + +// OnRecvPacket implements types.Middleware +func (im IBCMiddleware) OnRecvPacket(ctx sdk.Context, packet channeltypes.Packet, relayer sdk.AccAddress, +) exported.Acknowledgement { + // if this returns an Acknowledgement that isn't successful, all state changes are discarded + return im.app.OnRecvPacket(ctx, packet, relayer) +} + +// OnAcknowledgementPacket implements types.Middleware +func (im IBCMiddleware) OnAcknowledgementPacket(ctx sdk.Context, packet channeltypes.Packet, acknowledgement []byte, + relayer sdk.AccAddress, +) error { + // TODO: recheck the ibc acknowledgement error handling + var ack channeltypes.Acknowledgement + if err := json.Unmarshal(acknowledgement, &ack); err != nil { + return sdkerrors.ErrUnknownRequest.Wrapf("cannot unmarshal ICS-20 transfer packet acknowledgement: %v", err) + } + + if isAckError(acknowledgement) { + err := im.RevertSentPacket(ctx, packet) // If there is an error here we should still handle the timeout + if err != nil { + _ = ctx.EventManager().EmitTypedEvent(&uibc.EventBadRevert{ + Module: uibc.ModuleName, + FailureType: "acknowledgment", + Packet: string(packet.GetData()), + }) + } + } + + return im.app.OnAcknowledgementPacket(ctx, packet, acknowledgement, relayer) +} + +// IsAckError checks an IBC acknowledgement to see if it's an error. +// This is a replacement for ack.Success() which is currently not working on some circumstances +func isAckError(acknowledgement []byte) bool { + var ackErr channeltypes.Acknowledgement_Error + if err := json.Unmarshal(acknowledgement, &ackErr); err == nil && len(ackErr.Error) > 0 { + return true + } + return false +} + +// OnTimeoutPacket implements types.Middleware +func (im IBCMiddleware) OnTimeoutPacket(ctx sdk.Context, packet channeltypes.Packet, relayer sdk.AccAddress) error { + err := im.RevertSentPacket(ctx, packet) // If there is an error here we should still handle the timeout + if err != nil { + if err = ctx.EventManager().EmitTypedEvent(&uibc.EventBadRevert{ + Module: uibc.ModuleName, + FailureType: "timeout", + Packet: string(packet.GetData()), + }); err != nil { + return err + } + } + return im.app.OnTimeoutPacket(ctx, packet, relayer) +} + +// RevertSentPacket Notifies the contract that a sent packet wasn't properly received +func (im IBCMiddleware) RevertSentPacket( + ctx sdk.Context, + packet channeltypes.Packet, +) error { + var data transfertypes.FungibleTokenPacketData + if err := json.Unmarshal(packet.GetData(), &data); err != nil { + return sdkerrors.Wrapf(sdkerrors.ErrUnknownRequest, + "cannot unmarshal ICS-20 transfer packet data: %s", err.Error(), + ) + } + + amount, ok := sdkmath.NewIntFromString(data.Amount) + if !ok { + return sdkerrors.ErrInvalidRequest.Wrapf("invalid transfer amount %s", data.Amount) + } + + return im.keeper.UndoUpdateQuota( + ctx, + data.Denom, + amount, + ) +} + +func ValidateReceiverAddress(packet channeltypes.Packet) error { + var packetData transfertypes.FungibleTokenPacketData + if err := json.Unmarshal(packet.GetData(), &packetData); err != nil { + return err + } + if len(packetData.Receiver) >= 4096 { + return sdkerrors.Wrapf(sdkerrors.ErrInvalidAddress, + "IBC Receiver address too long. Max supported length is %d", 4096, + ) + } + return nil +} diff --git a/x/uibc/quota/ics4_wrapper.go b/x/uibc/quota/ics4_wrapper.go new file mode 100644 index 0000000000..ca42961434 --- /dev/null +++ b/x/uibc/quota/ics4_wrapper.go @@ -0,0 +1,26 @@ +package quota + +import ( + sdk "github.com/cosmos/cosmos-sdk/types" + capabilitytypes "github.com/cosmos/cosmos-sdk/x/capability/types" + "github.com/cosmos/ibc-go/v5/modules/core/exported" +) + +// GetAppVersion implements types.Middleware +func (im IBCMiddleware) GetAppVersion(ctx sdk.Context, portID string, channelID string) (string, bool) { + return im.keeper.GetAppVersion(ctx, portID, channelID) +} + +// SendPacket implements types.Middleware +func (im IBCMiddleware) SendPacket(ctx sdk.Context, chanCap *capabilitytypes.Capability, + packet exported.PacketI, +) error { + return im.keeper.SendPacket(ctx, chanCap, packet) +} + +// WriteAcknowledgement implements types.Middleware +func (im IBCMiddleware) WriteAcknowledgement(ctx sdk.Context, chanCap *capabilitytypes.Capability, + packet exported.PacketI, ack exported.Acknowledgement, +) error { + return im.keeper.WriteAcknowledgement(ctx, chanCap, packet, ack) +} diff --git a/x/uibc/quota/keeper/genesis.go b/x/uibc/quota/keeper/genesis.go new file mode 100644 index 0000000000..85a87635b2 --- /dev/null +++ b/x/uibc/quota/keeper/genesis.go @@ -0,0 +1,42 @@ +package keeper + +import ( + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/umee-network/umee/v4/x/uibc" +) + +// InitGenesis initializes the x/uibc module's state from a provided genesis +// state. +func (k Keeper) InitGenesis(ctx sdk.Context, genState uibc.GenesisState) { + if err := k.SetParams(ctx, genState.Params); err != nil { + panic(err) + } + + k.SetDenomQuotas(ctx, genState.Quotas) + + k.SetTotalOutflowSum(ctx, genState.TotalOutflowSum) + + if err := k.SetExpire(ctx, genState.QuotaExpires); err != nil { + panic(err) + } +} + +// ExportGenesis returns the x/uibc module's exported genesis state. +func (k Keeper) ExportGenesis(ctx sdk.Context) *uibc.GenesisState { + quotas, err := k.GetQuotaOfIBCDenoms(ctx) + if err != nil { + panic(err) + } + + quotaExpires, err := k.GetExpire(ctx) + if err != nil { + panic(err) + } + + return &uibc.GenesisState{ + Params: k.GetParams(ctx), + Quotas: quotas, + TotalOutflowSum: k.GetTotalOutflowSum(ctx), + QuotaExpires: *quotaExpires, + } +} diff --git a/x/uibc/quota/keeper/grpc_query.go b/x/uibc/quota/keeper/grpc_query.go new file mode 100644 index 0000000000..7ab9751647 --- /dev/null +++ b/x/uibc/quota/keeper/grpc_query.go @@ -0,0 +1,50 @@ +package keeper + +import ( + context "context" + + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/umee-network/umee/v4/x/uibc" +) + +var _ uibc.QueryServer = Querier{} + +// Querier implements a QueryServer for the x/uibc module. +type Querier struct { + Keeper +} + +func NewQuerier(k Keeper) Querier { + return Querier{Keeper: k} +} + +// Params returns params of the x/uibc module. +func (q Querier) Params(goCtx context.Context, _ *uibc.QueryParams) ( + *uibc.QueryParamsResponse, error, +) { + ctx := sdk.UnwrapSDKContext(goCtx) + params := q.Keeper.GetParams(ctx) + + return &uibc.QueryParamsResponse{Params: params}, nil +} + +// Quota returns quotas of denoms. +func (q Querier) Quota(goCtx context.Context, req *uibc.QueryQuota) ( + *uibc.QueryQuotaResponse, error, +) { + ctx := sdk.UnwrapSDKContext(goCtx) + + if len(req.Denom) == 0 { + quotaOfIBCDenoms, err := q.Keeper.GetQuotaOfIBCDenoms(ctx) + if err != nil { + return &uibc.QueryQuotaResponse{}, err + } + return &uibc.QueryQuotaResponse{Quota: quotaOfIBCDenoms}, nil + } + + quotaOfIBCDenom, err := q.Keeper.GetQuotaByDenom(ctx, req.Denom) + if err != nil { + return &uibc.QueryQuotaResponse{}, err + } + return &uibc.QueryQuotaResponse{Quota: []uibc.Quota{*quotaOfIBCDenom}}, nil +} diff --git a/x/uibc/quota/keeper/keeper.go b/x/uibc/quota/keeper/keeper.go new file mode 100644 index 0000000000..89b634d373 --- /dev/null +++ b/x/uibc/quota/keeper/keeper.go @@ -0,0 +1,51 @@ +package keeper + +import ( + "time" + + "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/v5/modules/apps/29-fee/types" + porttypes "github.com/cosmos/ibc-go/v5/modules/core/05-port/types" + + "github.com/umee-network/umee/v4/x/uibc" +) + +type Keeper struct { + storeKey storetypes.StoreKey + cdc codec.BinaryCodec + leverageKeeper uibc.LeverageKeeper + ics4Wrapper porttypes.ICS4Wrapper +} + +func NewKeeper( + cdc codec.BinaryCodec, key storetypes.StoreKey, ics4Wrapper types.ICS4Wrapper, leverageKeeper uibc.LeverageKeeper, +) Keeper { + + return Keeper{ + cdc: cdc, + storeKey: key, + ics4Wrapper: ics4Wrapper, + leverageKeeper: leverageKeeper, + } +} + +// UpdateQuotaParams update the ibc-transfer quota params for ibc denoms +func (k Keeper) UpdateQuotaParams(ctx sdk.Context, totalQuota, quotaPerDenom sdk.Dec, quotaDuration time.Duration, +) error { + params := k.GetParams(ctx) + params.TotalQuota = totalQuota + params.QuotaDuration = quotaDuration + params.TokenQuota = quotaPerDenom + + return k.SetParams(ctx, params) +} + +// SetIBCPause update the ibc pause status in module params. +func (k Keeper) SetIBCPause(ctx sdk.Context, ibcStatus uibc.IBCTransferStatus) error { + params := k.GetParams(ctx) + params.IbcPause = ibcStatus + + return k.SetParams(ctx, params) +} diff --git a/x/uibc/quota/keeper/msg_server.go b/x/uibc/quota/keeper/msg_server.go new file mode 100644 index 0000000000..c7fdc32cde --- /dev/null +++ b/x/uibc/quota/keeper/msg_server.go @@ -0,0 +1,45 @@ +package keeper + +import ( + context "context" + + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/umee-network/umee/v4/x/uibc" +) + +var _ uibc.MsgServer = msgServer{} + +type msgServer struct { + keeper Keeper +} + +// NewMsgServerImpl returns an implementation of MsgServer for the x/uibc +// module. +func NewMsgServerImpl(keeper Keeper) uibc.MsgServer { + return &msgServer{keeper: keeper} +} + +// GovUpdateQuota implements types.MsgServer +func (m msgServer) GovUpdateQuota(goCtx context.Context, msg *uibc.MsgGovUpdateQuota) ( + *uibc.MsgGovUpdateQuotaResponse, error, +) { + ctx := sdk.UnwrapSDKContext(goCtx) + if err := m.keeper.UpdateQuotaParams(ctx, msg.Total, msg.PerDenom, msg.QuotaDuration); err != nil { + return nil, err + } + // save the new ibc rate limits + return &uibc.MsgGovUpdateQuotaResponse{}, nil +} + +// GovSetIBCPause implements types.MsgServer +func (m msgServer) GovSetIBCPause( + goCtx context.Context, msg *uibc.MsgGovSetIBCPause, +) (*uibc.MsgGovSetIBCPauseResponse, error) { + ctx := sdk.UnwrapSDKContext(goCtx) + + if err := m.keeper.SetIBCPause(ctx, msg.IbcPauseStatus); err != nil { + return &uibc.MsgGovSetIBCPauseResponse{}, err + } + + return &uibc.MsgGovSetIBCPauseResponse{}, nil +} diff --git a/x/uibc/quota/keeper/params.go b/x/uibc/quota/keeper/params.go new file mode 100644 index 0000000000..a8c1ffca3c --- /dev/null +++ b/x/uibc/quota/keeper/params.go @@ -0,0 +1,30 @@ +package keeper + +import ( + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/umee-network/umee/v4/x/uibc" +) + +// SetParams sets the x/uibc module's parameters. +func (k Keeper) SetParams(ctx sdk.Context, params uibc.Params) error { + store := ctx.KVStore(k.storeKey) + bz, err := k.cdc.Marshal(¶ms) + if err != nil { + return err + } + store.Set(uibc.KeyPrefixParams, bz) + + return nil +} + +// GetParams gets the x/uibc module's parameters. +func (k Keeper) GetParams(ctx sdk.Context) (params uibc.Params) { + store := ctx.KVStore(k.storeKey) + bz := store.Get(uibc.KeyPrefixParams) + if bz == nil { + return params + } + + k.cdc.MustUnmarshal(bz, ¶ms) + return params +} diff --git a/x/uibc/quota/keeper/quota.go b/x/uibc/quota/keeper/quota.go new file mode 100644 index 0000000000..13c950454a --- /dev/null +++ b/x/uibc/quota/keeper/quota.go @@ -0,0 +1,249 @@ +package keeper + +import ( + "encoding/json" + "strings" + "time" + + sdkmath "cosmossdk.io/math" + sdk "github.com/cosmos/cosmos-sdk/types" + sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" + transfertypes "github.com/cosmos/ibc-go/v5/modules/apps/transfer/types" + "github.com/cosmos/ibc-go/v5/modules/core/exported" + + ltypes "github.com/umee-network/umee/v4/x/leverage/types" + "github.com/umee-network/umee/v4/x/uibc" +) + +// GetQuotaOfIBCDenoms returns quota of all tokens. +func (k Keeper) GetQuotaOfIBCDenoms(ctx sdk.Context) ([]uibc.Quota, error) { + var quotaOfIBCDenoms []uibc.Quota + + prefix := uibc.KeyPrefixDenomQuota + store := ctx.KVStore(k.storeKey) + + iter := sdk.KVStorePrefixIterator(store, prefix) + defer iter.Close() + + for ; iter.Valid(); iter.Next() { + var quotaOfIBCDenom uibc.Quota + if err := quotaOfIBCDenom.Unmarshal(iter.Value()); err != nil { + return nil, err + } + + quotaOfIBCDenoms = append(quotaOfIBCDenoms, quotaOfIBCDenom) + } + + return quotaOfIBCDenoms, nil +} + +// GetQuotaByDenom retunes the rate limits of ibc denom. +func (k Keeper) GetQuotaByDenom(ctx sdk.Context, ibcDenom string) (*uibc.Quota, error) { + store := ctx.KVStore(k.storeKey) + bz := store.Get(uibc.KeyTotalOutflows(ibcDenom)) + if bz == nil { + return nil, uibc.ErrNoQuotaForIBCDenom + } + + var quotaOfIBCDenom uibc.Quota + if err := k.cdc.Unmarshal(bz, "aOfIBCDenom); err != nil { + return nil, err + } + + return "aOfIBCDenom, nil +} + +// SetDenomQuotas save the updated token quota. +func (k Keeper) SetDenomQuotas(ctx sdk.Context, quotas []uibc.Quota) { + for _, quotaOfIBCDenom := range quotas { + k.SetDenomQuota(ctx, quotaOfIBCDenom) + } +} + +// SetDenomQuota save the quota of denom into store. +func (k Keeper) SetDenomQuota(ctx sdk.Context, quotaOfIBCDenom uibc.Quota) { + store := ctx.KVStore(k.storeKey) + key := uibc.KeyTotalOutflows(quotaOfIBCDenom.IbcDenom) + store.Set(key, k.cdc.MustMarshal("aOfIBCDenom)) +} + +// GetTotalOutflowSum returns the total outflow of ibc-transfer amount. +func (k Keeper) GetTotalOutflowSum(ctx sdk.Context) sdk.Dec { + store := ctx.KVStore(k.storeKey) + bz := store.Get(uibc.KeyPrefixTotalOutflows) + return sdk.MustNewDecFromStr(string(bz)) +} + +// SetTotalOutflowSum save the total outflow of ibc-transfer amount. +func (k Keeper) SetTotalOutflowSum(ctx sdk.Context, amount sdk.Dec) { + store := ctx.KVStore(k.storeKey) + store.Set(uibc.KeyPrefixTotalOutflows, []byte(amount.String())) +} + +// SetExpire save the quota expires time of ibc denom into store. +func (k Keeper) SetExpire(ctx sdk.Context, expires time.Time) error { + store := ctx.KVStore(k.storeKey) + bz, err := expires.MarshalBinary() + if err != nil { + return err + } + store.Set(uibc.KeyPrefixQuotaExpires, bz) + + return nil +} + +// GetExpire returns ibc-transfer quota expires time. +func (k Keeper) GetExpire(ctx sdk.Context) (*time.Time, error) { + store := ctx.KVStore(k.storeKey) + bz := store.Get(uibc.KeyPrefixQuotaExpires) + if bz == nil { + return nil, nil + } + quotaExpires := ctx.BlockTime() + if err := quotaExpires.UnmarshalBinary(bz); err != nil { + return "aExpires, err + } + return "aExpires, nil +} + +// ResetQuota will reset the ibc-transfer quotas +func (k Keeper) ResetQuota(ctx sdk.Context) error { + qd := k.GetParams(ctx).QuotaDuration + zero := sdk.NewDec(0) + newExpires := ctx.BlockTime().Add(qd) + if err := k.SetExpire(ctx, newExpires); err != nil { + return err + } + k.SetTotalOutflowSum(ctx, zero) + + store := ctx.KVStore(k.storeKey) + iter := sdk.KVStorePrefixIterator(store, uibc.KeyPrefixDenomQuota) + defer iter.Close() + for ; iter.Valid(); iter.Next() { + ibcDenom := uibc.DenomFromKeyTotalOutflows(iter.Key()) + q := uibc.Quota{IbcDenom: ibcDenom, OutflowSum: zero} + store.Set(uibc.KeyTotalOutflows(ibcDenom), k.cdc.MustMarshal(&q)) + } + return nil +} + +// CheckAndUpdateQuota checks the quota of ibc-transfer of denom +func (k Keeper) CheckAndUpdateQuota(ctx sdk.Context, denom string, amount sdkmath.Int) error { + params := k.GetParams(ctx) + + quotaOfIBCDenom, err := k.GetQuotaByDenom(ctx, denom) + if err != nil { + return err + } + + if quotaOfIBCDenom == nil { + return nil + } + + exchangePrice, err := k.getExchangePrice(ctx, denom, amount) + if err != nil { + // Note: skip the ibc-transfer quota checking if `denom` is not support by leverage + if err.Error() == sdkerrors.Wrap(ltypes.ErrNotRegisteredToken, denom).Error() { + return nil + } else if err != nil { + return err + } + } + + // checking ibc-transfer token quota + quotaOfIBCDenom.OutflowSum = quotaOfIBCDenom.OutflowSum.Add(exchangePrice) + if quotaOfIBCDenom.OutflowSum.GT(params.TokenQuota) { + return uibc.ErrQuotaExceeded + } + + // checking total outflow quota + totalOutflowSum := k.GetTotalOutflowSum(ctx).Add(exchangePrice) + if totalOutflowSum.GT(params.TotalQuota) { + return uibc.ErrQuotaExceeded + } + + // update the per token outflow sum + k.SetDenomQuota(ctx, *quotaOfIBCDenom) + // updating the total outflow sum + k.SetTotalOutflowSum(ctx, totalOutflowSum) + return nil +} + +func (k Keeper) getExchangePrice(ctx sdk.Context, denom string, amount sdkmath.Int) (sdk.Dec, error) { + transferCoin := sdk.NewCoin(denom, amount) + var err error + + // convert to base asset if it is `uToken` + if ltypes.HasUTokenPrefix(denom) { + transferCoin, err = k.leverageKeeper.ExchangeUToken(ctx, transferCoin) + if err != nil { + return sdk.Dec{}, err + } + } + + // get the exchange price (eg: UMEE) in USD from oracle using base denom eg: `uumee` + return k.leverageKeeper.TokenValue(ctx, transferCoin, ltypes.PriceModeSpot) +} + +// UndoUpdateQuota undo the quota of ibc denom +func (k Keeper) UndoUpdateQuota(ctx sdk.Context, denom string, amount sdkmath.Int) error { + quotaOfIBCDenom, err := k.GetQuotaByDenom(ctx, denom) + if err != nil { + return err + } + + if quotaOfIBCDenom == nil { + return nil + } + + exchangePrice, err := k.getExchangePrice(ctx, denom, amount) + if err != nil { + // Note: skip the ibc-transfer quota checking if `denom` is not support by leverage + if err.Error() == sdkerrors.Wrap(ltypes.ErrNotRegisteredToken, denom).Error() { + return nil + } else if err != nil { + return err + } + } + + // reset the outflow limit of token + quotaOfIBCDenom.OutflowSum = quotaOfIBCDenom.OutflowSum.Sub(exchangePrice) + k.SetDenomQuota(ctx, *quotaOfIBCDenom) + + // reset the total outflow sum + totalOutflowSum := k.GetTotalOutflowSum(ctx) + k.SetTotalOutflowSum(ctx, totalOutflowSum.Sub(exchangePrice)) + return nil +} + +// GetFundsFromPacket returns transfer amount and denom +func (k Keeper) GetFundsFromPacket(packet exported.PacketI) (sdkmath.Int, string, error) { + var packetData transfertypes.FungibleTokenPacketData + err := json.Unmarshal(packet.GetData(), &packetData) + if err != nil { + return sdkmath.Int{}, "", err + } + + amount, ok := sdkmath.NewIntFromString(packetData.Amount) + if !ok { + return sdkmath.Int{}, "", sdkerrors.ErrInvalidRequest.Wrapf("invalid transfer amount %s", packetData.Amount) + } + + return amount, k.GetLocalDenom(packetData.Denom), nil +} + +// GetLocalDenom retruns ibc denom +// Expected denoms in the following cases: +// +// send non-native: transfer/channel-0/denom -> ibc/xxx +// send native: denom -> denom +// recv (B)non-native: denom +// recv (B)native: transfer/channel-0/denom +func (k Keeper) GetLocalDenom(denom string) string { + if strings.HasPrefix(denom, "transfer/") { + denomTrace := transfertypes.ParseDenomTrace(denom) + return denomTrace.IBCDenom() + } + + return denom +} diff --git a/x/uibc/quota/keeper/relay.go b/x/uibc/quota/keeper/relay.go new file mode 100644 index 0000000000..de4a4238e6 --- /dev/null +++ b/x/uibc/quota/keeper/relay.go @@ -0,0 +1,36 @@ +package keeper + +import ( + sdk "github.com/cosmos/cosmos-sdk/types" + sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" + capabilitytypes "github.com/cosmos/cosmos-sdk/x/capability/types" + ibcexported "github.com/cosmos/ibc-go/v5/modules/core/exported" +) + +// SendPacket wraps IBC ChannelKeeper's SendPacket function +func (k Keeper) SendPacket(ctx sdk.Context, chanCap *capabilitytypes.Capability, packet ibcexported.PacketI) error { + funds, denom, err := k.GetFundsFromPacket(packet) + if err != nil { + return sdkerrors.Wrap(err, "bad packet in rate limit's SendPacket") + } + + if err := k.CheckAndUpdateQuota(ctx, denom, funds); err != nil { + return sdkerrors.Wrap(err, "bad packet in rate limit's SendPacket") + } + + return k.ics4Wrapper.SendPacket(ctx, chanCap, packet) +} + +// WriteAcknowledgement wraps IBC ChannelKeeper's WriteAcknowledgement function +// ICS29 WriteAcknowledgement is used for asynchronous acknowledgements +func (k Keeper) WriteAcknowledgement(ctx sdk.Context, chanCap *capabilitytypes.Capability, packet ibcexported.PacketI, + acknowledgement ibcexported.Acknowledgement, +) error { + // ics4Wrapper may be core IBC or higher-level middleware + return k.ics4Wrapper.WriteAcknowledgement(ctx, chanCap, packet, acknowledgement) +} + +// GetAppVersion returns the underlying application version. +func (k Keeper) GetAppVersion(ctx sdk.Context, portID, channelID string) (string, bool) { + return k.ics4Wrapper.GetAppVersion(ctx, portID, channelID) +} diff --git a/x/uibc/tx.pb.go b/x/uibc/tx.pb.go new file mode 100644 index 0000000000..1dd9fd71f9 --- /dev/null +++ b/x/uibc/tx.pb.go @@ -0,0 +1,1235 @@ +// Code generated by protoc-gen-gogo. DO NOT EDIT. +// source: umee/uibc/v1/tx.proto + +package uibc + +import ( + context "context" + fmt "fmt" + _ "github.com/cosmos/cosmos-proto" + github_com_cosmos_cosmos_sdk_types "github.com/cosmos/cosmos-sdk/types" + _ "github.com/cosmos/cosmos-sdk/types/msgservice" + _ "github.com/gogo/protobuf/gogoproto" + grpc1 "github.com/gogo/protobuf/grpc" + proto "github.com/gogo/protobuf/proto" + github_com_gogo_protobuf_types "github.com/gogo/protobuf/types" + grpc "google.golang.org/grpc" + codes "google.golang.org/grpc/codes" + status "google.golang.org/grpc/status" + _ "google.golang.org/protobuf/types/known/durationpb" + io "io" + math "math" + math_bits "math/bits" + time "time" +) + +// Reference imports to suppress errors if they are not otherwise used. +var _ = proto.Marshal +var _ = fmt.Errorf +var _ = math.Inf +var _ = time.Kitchen + +// 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 + +// MsgGovUpdateQuota defines the Msg/GovUpdateQuota request type. +type MsgGovUpdateQuota struct { + // authority is the address of the governance account. + Authority string `protobuf:"bytes,1,opt,name=authority,proto3" json:"authority,omitempty"` + Title string `protobuf:"bytes,2,opt,name=title,proto3" json:"title,omitempty"` + Description string `protobuf:"bytes,3,opt,name=description,proto3" json:"description,omitempty"` + // total quota defines the total outflow of ibc-transfer in USD + Total github_com_cosmos_cosmos_sdk_types.Dec `protobuf:"bytes,4,opt,name=total,proto3,customtype=github.com/cosmos/cosmos-sdk/types.Dec" json:"total"` + // per_denom quota for outflows per denom. All denoms have the same quota size. + PerDenom github_com_cosmos_cosmos_sdk_types.Dec `protobuf:"bytes,5,opt,name=per_denom,json=perDenom,proto3,customtype=github.com/cosmos/cosmos-sdk/types.Dec" json:"per_denom"` + // quota_duration defines quota expires per denom, All denoms have the same expire time. + QuotaDuration time.Duration `protobuf:"bytes,6,opt,name=quota_duration,json=quotaDuration,proto3,stdduration" json:"quota_duration,omitempty" yaml:"quota_duration"` +} + +func (m *MsgGovUpdateQuota) Reset() { *m = MsgGovUpdateQuota{} } +func (*MsgGovUpdateQuota) ProtoMessage() {} +func (*MsgGovUpdateQuota) Descriptor() ([]byte, []int) { + return fileDescriptor_1982abc7d531f4dc, []int{0} +} +func (m *MsgGovUpdateQuota) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *MsgGovUpdateQuota) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_MsgGovUpdateQuota.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 *MsgGovUpdateQuota) XXX_Merge(src proto.Message) { + xxx_messageInfo_MsgGovUpdateQuota.Merge(m, src) +} +func (m *MsgGovUpdateQuota) XXX_Size() int { + return m.Size() +} +func (m *MsgGovUpdateQuota) XXX_DiscardUnknown() { + xxx_messageInfo_MsgGovUpdateQuota.DiscardUnknown(m) +} + +var xxx_messageInfo_MsgGovUpdateQuota proto.InternalMessageInfo + +func (*MsgGovUpdateQuota) XXX_MessageName() string { + return "umee.uibc.v1.MsgGovUpdateQuota" +} + +// MsgGovUpdateQuotaResponse defines response type for the Msg/GovUpdateQuota for with x/gov proposals. +type MsgGovUpdateQuotaResponse struct { +} + +func (m *MsgGovUpdateQuotaResponse) Reset() { *m = MsgGovUpdateQuotaResponse{} } +func (m *MsgGovUpdateQuotaResponse) String() string { return proto.CompactTextString(m) } +func (*MsgGovUpdateQuotaResponse) ProtoMessage() {} +func (*MsgGovUpdateQuotaResponse) Descriptor() ([]byte, []int) { + return fileDescriptor_1982abc7d531f4dc, []int{1} +} +func (m *MsgGovUpdateQuotaResponse) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *MsgGovUpdateQuotaResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_MsgGovUpdateQuotaResponse.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 *MsgGovUpdateQuotaResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_MsgGovUpdateQuotaResponse.Merge(m, src) +} +func (m *MsgGovUpdateQuotaResponse) XXX_Size() int { + return m.Size() +} +func (m *MsgGovUpdateQuotaResponse) XXX_DiscardUnknown() { + xxx_messageInfo_MsgGovUpdateQuotaResponse.DiscardUnknown(m) +} + +var xxx_messageInfo_MsgGovUpdateQuotaResponse proto.InternalMessageInfo + +func (*MsgGovUpdateQuotaResponse) XXX_MessageName() string { + return "umee.uibc.v1.MsgGovUpdateQuotaResponse" +} + +// MsgGovSetIBCPause defines request type for UpdateIBCTransferStatus +type MsgGovSetIBCPause struct { + // authority is the address of the governance account. + Authority string `protobuf:"bytes,1,opt,name=authority,proto3" json:"authority,omitempty"` + Title string `protobuf:"bytes,2,opt,name=title,proto3" json:"title,omitempty"` + Description string `protobuf:"bytes,3,opt,name=description,proto3" json:"description,omitempty"` + // ibc_pause_status defines ibc transfer pause status + IbcPauseStatus IBCTransferStatus `protobuf:"varint,4,opt,name=ibc_pause_status,json=ibcPauseStatus,proto3,enum=umee.uibc.v1.IBCTransferStatus" json:"ibc_pause_status,omitempty"` +} + +func (m *MsgGovSetIBCPause) Reset() { *m = MsgGovSetIBCPause{} } +func (*MsgGovSetIBCPause) ProtoMessage() {} +func (*MsgGovSetIBCPause) Descriptor() ([]byte, []int) { + return fileDescriptor_1982abc7d531f4dc, []int{2} +} +func (m *MsgGovSetIBCPause) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *MsgGovSetIBCPause) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_MsgGovSetIBCPause.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 *MsgGovSetIBCPause) XXX_Merge(src proto.Message) { + xxx_messageInfo_MsgGovSetIBCPause.Merge(m, src) +} +func (m *MsgGovSetIBCPause) XXX_Size() int { + return m.Size() +} +func (m *MsgGovSetIBCPause) XXX_DiscardUnknown() { + xxx_messageInfo_MsgGovSetIBCPause.DiscardUnknown(m) +} + +var xxx_messageInfo_MsgGovSetIBCPause proto.InternalMessageInfo + +func (*MsgGovSetIBCPause) XXX_MessageName() string { + return "umee.uibc.v1.MsgGovSetIBCPause" +} + +// MsgGovSetIBCPauseResponse definesresponse type for Msg/MsgGovSetIBCPause for with x/gov proposals. +type MsgGovSetIBCPauseResponse struct { +} + +func (m *MsgGovSetIBCPauseResponse) Reset() { *m = MsgGovSetIBCPauseResponse{} } +func (m *MsgGovSetIBCPauseResponse) String() string { return proto.CompactTextString(m) } +func (*MsgGovSetIBCPauseResponse) ProtoMessage() {} +func (*MsgGovSetIBCPauseResponse) Descriptor() ([]byte, []int) { + return fileDescriptor_1982abc7d531f4dc, []int{3} +} +func (m *MsgGovSetIBCPauseResponse) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *MsgGovSetIBCPauseResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_MsgGovSetIBCPauseResponse.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 *MsgGovSetIBCPauseResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_MsgGovSetIBCPauseResponse.Merge(m, src) +} +func (m *MsgGovSetIBCPauseResponse) XXX_Size() int { + return m.Size() +} +func (m *MsgGovSetIBCPauseResponse) XXX_DiscardUnknown() { + xxx_messageInfo_MsgGovSetIBCPauseResponse.DiscardUnknown(m) +} + +var xxx_messageInfo_MsgGovSetIBCPauseResponse proto.InternalMessageInfo + +func (*MsgGovSetIBCPauseResponse) XXX_MessageName() string { + return "umee.uibc.v1.MsgGovSetIBCPauseResponse" +} +func init() { + proto.RegisterType((*MsgGovUpdateQuota)(nil), "umee.uibc.v1.MsgGovUpdateQuota") + proto.RegisterType((*MsgGovUpdateQuotaResponse)(nil), "umee.uibc.v1.MsgGovUpdateQuotaResponse") + proto.RegisterType((*MsgGovSetIBCPause)(nil), "umee.uibc.v1.MsgGovSetIBCPause") + proto.RegisterType((*MsgGovSetIBCPauseResponse)(nil), "umee.uibc.v1.MsgGovSetIBCPauseResponse") +} + +func init() { proto.RegisterFile("umee/uibc/v1/tx.proto", fileDescriptor_1982abc7d531f4dc) } + +var fileDescriptor_1982abc7d531f4dc = []byte{ + // 586 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xbc, 0x54, 0xbf, 0x6f, 0xd3, 0x40, + 0x14, 0xb6, 0x09, 0xa9, 0xc8, 0x15, 0x22, 0xb0, 0x52, 0x70, 0x82, 0x64, 0x47, 0x19, 0xa0, 0x42, + 0xc4, 0x56, 0x03, 0x62, 0xa8, 0x60, 0x20, 0x8d, 0x04, 0x19, 0x2a, 0x81, 0x03, 0x03, 0x5d, 0x22, + 0xff, 0xb8, 0xba, 0xa7, 0xc6, 0x3e, 0x73, 0x77, 0x0e, 0xcd, 0x84, 0xc4, 0xc4, 0xc8, 0xd8, 0xb1, + 0x7f, 0x02, 0x43, 0x57, 0xf6, 0x48, 0x2c, 0x55, 0x27, 0xc4, 0x10, 0x20, 0x91, 0x40, 0x62, 0xe4, + 0x2f, 0x40, 0x77, 0xb6, 0x55, 0xa7, 0x8d, 0xd4, 0x05, 0x31, 0xd9, 0xef, 0x7d, 0xdf, 0x7d, 0xef, + 0xdd, 0xfb, 0x9e, 0x0d, 0x56, 0xe2, 0x00, 0x42, 0x33, 0x46, 0x8e, 0x6b, 0x0e, 0xd7, 0x4c, 0xb6, + 0x67, 0x44, 0x04, 0x33, 0xac, 0x5c, 0xe6, 0x69, 0x83, 0xa7, 0x8d, 0xe1, 0x5a, 0xad, 0xe2, 0x63, + 0x1f, 0x0b, 0xc0, 0xe4, 0x6f, 0x09, 0xa7, 0xa6, 0xf9, 0x18, 0xfb, 0x03, 0x68, 0x8a, 0xc8, 0x89, + 0xb7, 0x4d, 0x2f, 0x26, 0x36, 0x43, 0x38, 0x4c, 0xf1, 0x1b, 0x2e, 0xa6, 0x01, 0xa6, 0x66, 0x40, + 0x7d, 0xae, 0x1d, 0x50, 0x3f, 0x05, 0xaa, 0x09, 0xd0, 0x4f, 0x14, 0x93, 0x20, 0x85, 0xd4, 0xb9, + 0x76, 0x5e, 0xc7, 0x98, 0xd9, 0x09, 0xd2, 0xf8, 0x5c, 0x00, 0xd7, 0x36, 0xa9, 0xff, 0x04, 0x0f, + 0x5f, 0x46, 0x9e, 0xcd, 0xe0, 0x73, 0x8e, 0x29, 0x0f, 0x40, 0xc9, 0x8e, 0xd9, 0x0e, 0x26, 0x88, + 0x8d, 0x54, 0xb9, 0x2e, 0xaf, 0x96, 0xda, 0xea, 0xf1, 0x61, 0xb3, 0x92, 0x8a, 0x3e, 0xf6, 0x3c, + 0x02, 0x29, 0xed, 0x31, 0x82, 0x42, 0xdf, 0x3a, 0xa1, 0x2a, 0x15, 0x50, 0x64, 0x88, 0x0d, 0xa0, + 0x7a, 0x81, 0x9f, 0xb1, 0x92, 0x40, 0xa9, 0x83, 0x65, 0x0f, 0x52, 0x97, 0xa0, 0x88, 0x5f, 0x43, + 0x2d, 0x08, 0x2c, 0x9f, 0x52, 0x2c, 0x50, 0x64, 0x98, 0xd9, 0x03, 0xf5, 0xa2, 0xa8, 0xf5, 0x70, + 0x3c, 0xd1, 0xa5, 0xaf, 0x13, 0xfd, 0x96, 0x8f, 0xd8, 0x4e, 0xec, 0x18, 0x2e, 0x0e, 0xd2, 0xfb, + 0xa4, 0x8f, 0x26, 0xf5, 0x76, 0x4d, 0x36, 0x8a, 0x20, 0x35, 0x3a, 0xd0, 0x3d, 0x3e, 0x6c, 0x82, + 0xb4, 0xb3, 0x0e, 0x74, 0xad, 0x44, 0x4a, 0x79, 0x05, 0x4a, 0x11, 0x24, 0x7d, 0x0f, 0x86, 0x38, + 0x50, 0x8b, 0xff, 0x40, 0xf7, 0x52, 0x04, 0x49, 0x87, 0xab, 0x29, 0x6f, 0x41, 0x59, 0xcc, 0xb0, + 0x9f, 0x59, 0xa3, 0x2e, 0xd5, 0xe5, 0xd5, 0xe5, 0x56, 0xd5, 0x48, 0xbc, 0x33, 0x32, 0xef, 0x8c, + 0x4e, 0x4a, 0x68, 0x3f, 0xe2, 0xa5, 0x7f, 0x4f, 0x74, 0x75, 0xfe, 0xe0, 0x5d, 0x1c, 0x20, 0x06, + 0x83, 0x88, 0x8d, 0xfe, 0x4c, 0xf4, 0x95, 0x91, 0x1d, 0x0c, 0xd6, 0x1b, 0xf3, 0x8c, 0xc6, 0xfe, + 0x37, 0x5d, 0xb6, 0xae, 0x88, 0x64, 0xa6, 0xb6, 0x7e, 0xfd, 0xfd, 0x81, 0x2e, 0xed, 0x1f, 0xe8, + 0xd2, 0xbb, 0x5f, 0x1f, 0xef, 0x9c, 0xcc, 0xbf, 0x71, 0x13, 0x54, 0xcf, 0x98, 0x69, 0x41, 0x1a, + 0xe1, 0x90, 0xc2, 0xc6, 0x4f, 0x39, 0xb3, 0xba, 0x07, 0x59, 0xb7, 0xbd, 0xf1, 0xcc, 0x8e, 0x29, + 0xfc, 0xef, 0x56, 0x77, 0xc1, 0x55, 0xe4, 0xb8, 0xfd, 0x88, 0x17, 0xef, 0x53, 0x66, 0xb3, 0x98, + 0x0a, 0xd7, 0xcb, 0x2d, 0xdd, 0xc8, 0x7f, 0x1d, 0x46, 0xb7, 0xbd, 0xf1, 0x82, 0xd8, 0x21, 0xdd, + 0x86, 0xa4, 0x27, 0x68, 0x56, 0x19, 0x39, 0xae, 0x68, 0x3a, 0x89, 0xcf, 0x9f, 0x42, 0xee, 0x9e, + 0xd9, 0x14, 0x5a, 0x9f, 0x64, 0x50, 0xd8, 0xa4, 0xbe, 0xb2, 0x05, 0xca, 0xa7, 0x96, 0xfe, 0x54, + 0xfd, 0x33, 0x83, 0xac, 0xdd, 0x3e, 0x87, 0x90, 0xd5, 0x48, 0xb5, 0xf3, 0x53, 0x5e, 0xa8, 0x9d, + 0x23, 0x2c, 0xd6, 0x5e, 0xd0, 0x7f, 0xfb, 0xe9, 0xf8, 0x87, 0x26, 0x8d, 0xa7, 0x9a, 0x7c, 0x34, + 0xd5, 0xe4, 0xef, 0x53, 0x4d, 0xfe, 0x30, 0xd3, 0xa4, 0xf1, 0x4c, 0x93, 0x8f, 0x66, 0x9a, 0xf4, + 0x65, 0xa6, 0x49, 0x5b, 0xf9, 0xed, 0xe6, 0xa2, 0xcd, 0x10, 0xb2, 0x37, 0x98, 0xec, 0x8a, 0xc0, + 0x1c, 0xde, 0x37, 0xf7, 0xc4, 0x9f, 0xc0, 0x59, 0x12, 0x5b, 0x7a, 0xef, 0x6f, 0x00, 0x00, 0x00, + 0xff, 0xff, 0x3b, 0x6f, 0x81, 0x19, 0xac, 0x04, 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 { + // GovUpdateQuota adds new quota for ibc denoms or + // updates the quota for existed ibc denoms. + GovUpdateQuota(ctx context.Context, in *MsgGovUpdateQuota, opts ...grpc.CallOption) (*MsgGovUpdateQuotaResponse, error) + // GovSetIBCPause update the status of ibc-transfer + GovSetIBCPause(ctx context.Context, in *MsgGovSetIBCPause, opts ...grpc.CallOption) (*MsgGovSetIBCPauseResponse, error) +} + +type msgClient struct { + cc grpc1.ClientConn +} + +func NewMsgClient(cc grpc1.ClientConn) MsgClient { + return &msgClient{cc} +} + +func (c *msgClient) GovUpdateQuota(ctx context.Context, in *MsgGovUpdateQuota, opts ...grpc.CallOption) (*MsgGovUpdateQuotaResponse, error) { + out := new(MsgGovUpdateQuotaResponse) + err := c.cc.Invoke(ctx, "/umee.uibc.v1.Msg/GovUpdateQuota", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *msgClient) GovSetIBCPause(ctx context.Context, in *MsgGovSetIBCPause, opts ...grpc.CallOption) (*MsgGovSetIBCPauseResponse, error) { + out := new(MsgGovSetIBCPauseResponse) + err := c.cc.Invoke(ctx, "/umee.uibc.v1.Msg/GovSetIBCPause", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +// MsgServer is the server API for Msg service. +type MsgServer interface { + // GovUpdateQuota adds new quota for ibc denoms or + // updates the quota for existed ibc denoms. + GovUpdateQuota(context.Context, *MsgGovUpdateQuota) (*MsgGovUpdateQuotaResponse, error) + // GovSetIBCPause update the status of ibc-transfer + GovSetIBCPause(context.Context, *MsgGovSetIBCPause) (*MsgGovSetIBCPauseResponse, error) +} + +// UnimplementedMsgServer can be embedded to have forward compatible implementations. +type UnimplementedMsgServer struct { +} + +func (*UnimplementedMsgServer) GovUpdateQuota(ctx context.Context, req *MsgGovUpdateQuota) (*MsgGovUpdateQuotaResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method GovUpdateQuota not implemented") +} +func (*UnimplementedMsgServer) GovSetIBCPause(ctx context.Context, req *MsgGovSetIBCPause) (*MsgGovSetIBCPauseResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method GovSetIBCPause not implemented") +} + +func RegisterMsgServer(s grpc1.Server, srv MsgServer) { + s.RegisterService(&_Msg_serviceDesc, srv) +} + +func _Msg_GovUpdateQuota_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(MsgGovUpdateQuota) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(MsgServer).GovUpdateQuota(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/umee.uibc.v1.Msg/GovUpdateQuota", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(MsgServer).GovUpdateQuota(ctx, req.(*MsgGovUpdateQuota)) + } + return interceptor(ctx, in, info, handler) +} + +func _Msg_GovSetIBCPause_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(MsgGovSetIBCPause) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(MsgServer).GovSetIBCPause(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/umee.uibc.v1.Msg/GovSetIBCPause", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(MsgServer).GovSetIBCPause(ctx, req.(*MsgGovSetIBCPause)) + } + return interceptor(ctx, in, info, handler) +} + +var _Msg_serviceDesc = grpc.ServiceDesc{ + ServiceName: "umee.uibc.v1.Msg", + HandlerType: (*MsgServer)(nil), + Methods: []grpc.MethodDesc{ + { + MethodName: "GovUpdateQuota", + Handler: _Msg_GovUpdateQuota_Handler, + }, + { + MethodName: "GovSetIBCPause", + Handler: _Msg_GovSetIBCPause_Handler, + }, + }, + Streams: []grpc.StreamDesc{}, + Metadata: "umee/uibc/v1/tx.proto", +} + +func (m *MsgGovUpdateQuota) 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 *MsgGovUpdateQuota) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *MsgGovUpdateQuota) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + n1, err1 := github_com_gogo_protobuf_types.StdDurationMarshalTo(m.QuotaDuration, dAtA[i-github_com_gogo_protobuf_types.SizeOfStdDuration(m.QuotaDuration):]) + if err1 != nil { + return 0, err1 + } + i -= n1 + i = encodeVarintTx(dAtA, i, uint64(n1)) + i-- + dAtA[i] = 0x32 + { + size := m.PerDenom.Size() + i -= size + if _, err := m.PerDenom.MarshalTo(dAtA[i:]); err != nil { + return 0, err + } + i = encodeVarintTx(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x2a + { + size := m.Total.Size() + i -= size + if _, err := m.Total.MarshalTo(dAtA[i:]); err != nil { + return 0, err + } + i = encodeVarintTx(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x22 + if len(m.Description) > 0 { + i -= len(m.Description) + copy(dAtA[i:], m.Description) + i = encodeVarintTx(dAtA, i, uint64(len(m.Description))) + i-- + dAtA[i] = 0x1a + } + if len(m.Title) > 0 { + i -= len(m.Title) + copy(dAtA[i:], m.Title) + i = encodeVarintTx(dAtA, i, uint64(len(m.Title))) + 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 *MsgGovUpdateQuotaResponse) 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 *MsgGovUpdateQuotaResponse) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *MsgGovUpdateQuotaResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + return len(dAtA) - i, nil +} + +func (m *MsgGovSetIBCPause) 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 *MsgGovSetIBCPause) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *MsgGovSetIBCPause) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if m.IbcPauseStatus != 0 { + i = encodeVarintTx(dAtA, i, uint64(m.IbcPauseStatus)) + i-- + dAtA[i] = 0x20 + } + if len(m.Description) > 0 { + i -= len(m.Description) + copy(dAtA[i:], m.Description) + i = encodeVarintTx(dAtA, i, uint64(len(m.Description))) + i-- + dAtA[i] = 0x1a + } + if len(m.Title) > 0 { + i -= len(m.Title) + copy(dAtA[i:], m.Title) + i = encodeVarintTx(dAtA, i, uint64(len(m.Title))) + 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 *MsgGovSetIBCPauseResponse) 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 *MsgGovSetIBCPauseResponse) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *MsgGovSetIBCPauseResponse) 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 *MsgGovUpdateQuota) 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 = len(m.Title) + if l > 0 { + n += 1 + l + sovTx(uint64(l)) + } + l = len(m.Description) + if l > 0 { + n += 1 + l + sovTx(uint64(l)) + } + l = m.Total.Size() + n += 1 + l + sovTx(uint64(l)) + l = m.PerDenom.Size() + n += 1 + l + sovTx(uint64(l)) + l = github_com_gogo_protobuf_types.SizeOfStdDuration(m.QuotaDuration) + n += 1 + l + sovTx(uint64(l)) + return n +} + +func (m *MsgGovUpdateQuotaResponse) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + return n +} + +func (m *MsgGovSetIBCPause) 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 = len(m.Title) + if l > 0 { + n += 1 + l + sovTx(uint64(l)) + } + l = len(m.Description) + if l > 0 { + n += 1 + l + sovTx(uint64(l)) + } + if m.IbcPauseStatus != 0 { + n += 1 + sovTx(uint64(m.IbcPauseStatus)) + } + return n +} + +func (m *MsgGovSetIBCPauseResponse) 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 *MsgGovUpdateQuota) 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: MsgGovUpdateQuota: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: MsgGovUpdateQuota: 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 Title", 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.Title = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 3: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Description", 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.Description = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 4: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Total", 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 + } + if err := m.Total.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 5: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field PerDenom", 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 + } + if err := m.PerDenom.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 6: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field QuotaDuration", 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 := github_com_gogo_protobuf_types.StdDurationUnmarshal(&m.QuotaDuration, 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 *MsgGovUpdateQuotaResponse) 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: MsgGovUpdateQuotaResponse: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: MsgGovUpdateQuotaResponse: 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 *MsgGovSetIBCPause) 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: MsgGovSetIBCPause: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: MsgGovSetIBCPause: 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 Title", 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.Title = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 3: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Description", 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.Description = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 4: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field IbcPauseStatus", wireType) + } + m.IbcPauseStatus = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.IbcPauseStatus |= IBCTransferStatus(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 *MsgGovSetIBCPauseResponse) 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: MsgGovSetIBCPauseResponse: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: MsgGovSetIBCPauseResponse: 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") +)