From f0fbd5e20f190b3f767ebf4860be0e6b09b7e2f2 Mon Sep 17 00:00:00 2001 From: Robert Zaremba Date: Mon, 20 Nov 2023 17:35:49 +0100 Subject: [PATCH 01/13] chore: rename uibc quota params --- proto/umee/uibc/v1/genesis.proto | 8 ++++---- proto/umee/uibc/v1/quota.proto | 4 ++-- x/uibc/README.md | 35 ++++++++++++++++++++------------ 3 files changed, 28 insertions(+), 19 deletions(-) diff --git a/proto/umee/uibc/v1/genesis.proto b/proto/umee/uibc/v1/genesis.proto index 84df483b26..423e0ab79d 100644 --- a/proto/umee/uibc/v1/genesis.proto +++ b/proto/umee/uibc/v1/genesis.proto @@ -17,8 +17,8 @@ message GenesisState { (gogoproto.castrepeated) = "github.com/cosmos/cosmos-sdk/types.DecCoins", (gogoproto.nullable) = false ]; - // total_outflow_sum defines the total outflow sum of ibc-transfer in USD. - string total_outflow_sum = 3 [ + // outflow_sum defines the total outflow sum of ibc-transfer in USD. + string outflow_sum = 3 [ (cosmos_proto.scalar) = "cosmos.Dec", (gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec", (gogoproto.nullable) = false @@ -35,8 +35,8 @@ message GenesisState { (gogoproto.castrepeated) = "github.com/cosmos/cosmos-sdk/types.DecCoins", (gogoproto.nullable) = false ]; - // total_inflow_sum defines tracks total sum of IBC inflow transfers (in USD) during quota period. - string total_inflow_sum = 6 [ + // inflow_sum defines tracks total sum of IBC inflow transfers (in USD) during quota period. + string inflow_sum = 6 [ (cosmos_proto.scalar) = "cosmos.Dec", (gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec", (gogoproto.nullable) = false diff --git a/proto/umee/uibc/v1/quota.proto b/proto/umee/uibc/v1/quota.proto index ca91a5609e..4c476dacf7 100644 --- a/proto/umee/uibc/v1/quota.proto +++ b/proto/umee/uibc/v1/quota.proto @@ -42,8 +42,8 @@ message Params { (gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec", (gogoproto.nullable) = false ]; - // inflow_outflow_quota_token_base defines the inflow outflow quota base for token - string inflow_outflow_quota_token_base = 7 [ + // inflow_outflow_token_quota_base defines the inflow outflow quota base for token + string inflow_outflow_token_quota_base = 7 [ (cosmos_proto.scalar) = "cosmos.Dec", (gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec", (gogoproto.nullable) = false diff --git a/x/uibc/README.md b/x/uibc/README.md index c9df2a0cad..406a7eaf64 100644 --- a/x/uibc/README.md +++ b/x/uibc/README.md @@ -25,28 +25,37 @@ IBC Quota is an upper limit in USD amount. All inflows and outflows are measured in token average USD value using our x/oracle `AvgKeeper`. The `AvgKeeper` aggregates TVWAP prices over 16h window. -We are only tracking inflows for tokens which are registered in x/leverage Token Registry. +We are tracking inflows and outflows for tokens which are registered in x/leverage Token Registry. +NOTE: we measure per token as defined in the x/leverage, not the IBC Denom Path (there can be multiple paths). Since creating a channel is permission less, we want to use the same quota token. +For inflows: -#### Inflow +- `inflows`: metric per token. +- `inflow_sum` : sum of all `inflows` from the previous point. -- `Inflows`: metric per token. -- `TotalInflowSum` : Sum of all `Inflows` from the previous point. +Similarly to inflows, we measure outflows per token and aggregates (sum): -#### Outflows +- `iutflows`: metric per token. +- `total_outflow_sum`: sum of `outflows` from the previous point. -All outflows are measured in token average USD value using our x/oracle `AvgKeeper`. The `AvgKeeper` aggregates TVWAP prices over 16h window. +The metrics above are reset every `params.quota_duration` in Begin Blocker. +Example: if the reset was done at 14:00 UTC, then the next reset will be done `quota_duration` later. You can observe the reset with `/umee/uibc/v1/EventQuotaReset` event, which will contain `next_expire` attribute. -We define 2 Quotas for ICS-20 transfers. Each quota only tracks tokens x/leverage Token Registry. +#### Outflow Quota. -- `Params.TokenQuota`: upper limit of a sum of all outflows per token. It's set to 1.2M USD per token. It limits the outflows value for each token. - NOTE: we measure per token as defined in the x/leverage, not the IBC Denom Path (there can be multiple paths). Since creating a channel is permission less, we want to use same quota token. -- `Params.TotalQuota`: upper limit of a sum of all token outflows combined. For example if it's set to 1.6M USD then IBC outflows reaching the total quota will be 600k USD worth of ATOM, 500k USD worth of STATOM, 250k USD worth of UMEE and 250k USD worth JUNO. +Inflows and outflows metrics above are used to **limit ICS-20 transfers** of tokens in the x/leverage Token Registry. The outflow transfer of token `X` is possible when: -If a quota parameter is set to zero then we consider it as unlimited. +1. Outflow quota after the transfer is not suppressed: +1. `total_outflow_sum <= params.total_quota`. For example if it's set to 1.6M USD then IBC outflows reaching the total quota will be 600k USD worth of ATOM, 500k USD worth of STATOM, 250k USD worth of UMEE and 250k USD worth JUNO. +1. `token_quota[X] <= params.token_quota` - the token X quota is not suppressed. +1. OR Outflow quota lifted by inflows is not reached: +1. `total_outflow_sum <= params.inflow_outflow_quota_base + params.inflow_outflow_quota_rate * total_inflow_sum` +1. `token_quota[X] <= params.inflow_outflow_token_quota_base + params.inflow_outflow_token_quota_rate * inflows[X]` -All quotas are reset in `BeginBlocker` whenever a time difference between the new block, and the previous reset is more than `Params.QuotaDuration` in seconds (initially set to 24h). +See `../../proto/umee/uibc/v1/quota.proto` for the list of all params. -Transfer is reverted whenever it breaks any quota. +If a any `total_quota` or `token_quota` parameter is set to zero then we consider it as unlimited. + +Transfer is **reverted** whenever it breaks any quota. Transfer of tokens, which are not registered in the x/leverage Token Registry are not subject to the quota limit. From 1f415b7d7e30640d100c26c7ca79c454517a00e8 Mon Sep 17 00:00:00 2001 From: Robert Zaremba Date: Mon, 20 Nov 2023 17:40:59 +0100 Subject: [PATCH 02/13] update go files --- CHANGELOG.md | 4 ++ app/upgrades.go | 2 +- swagger/swagger.yaml | 12 ++-- x/uibc/client/tests/cli_test.go | 2 +- x/uibc/genesis.go | 14 ++--- x/uibc/genesis.pb.go | 89 +++++++++++++++--------------- x/uibc/genesis_test.go | 2 +- x/uibc/params.go | 4 +- x/uibc/quota.pb.go | 88 ++++++++++++++--------------- x/uibc/quota/keeper/genesis.go | 8 +-- x/uibc/quota/keeper/migrations.go | 6 +- x/uibc/quota/keeper/params_test.go | 2 +- x/uibc/quota/keeper/quota.go | 12 ++-- x/uibc/quota/keeper/quota_test.go | 8 +-- 14 files changed, 128 insertions(+), 125 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f8039e6695..289e79aba4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -55,6 +55,10 @@ Ref: https://keepachangelog.com/en/1.0.0/ - [2299](https://github.com/umee-network/umee/pull/2299) Upgrade Cosmos SDK to v0.47. - [2301](https://github.com/umee-network/umee/pull/2301) use gov/v1 MinInitialDepositRatio and set it to 0.1. +### Breaking Changes + +- Rename: `TotalOutflowSum` to `OutflowSum`, `TotalInflowSum` to `InflowSum`. + ## v6.1.0 - 2023-10-17 ### Improvements diff --git a/app/upgrades.go b/app/upgrades.go index 47e504e426..930e1be316 100644 --- a/app/upgrades.go +++ b/app/upgrades.go @@ -124,7 +124,7 @@ func (app *UmeeApp) registerUpgrade6_2(upgradeInfo upgradetypes.Plan) { // uibc migrations uIBCKeeper := app.UIbcQuotaKeeperB.Keeper(&ctx) - uIBCKeeper.MigrateTotalOutflowSum() + uIBCKeeper.MigrateOutflowSum() err = uIBCKeeper.SetParams(uibc.DefaultParams()) return fromVM, err }, diff --git a/swagger/swagger.yaml b/swagger/swagger.yaml index 9c2a25bd69..f0ab5bc466 100644 --- a/swagger/swagger.yaml +++ b/swagger/swagger.yaml @@ -2534,10 +2534,10 @@ paths: title: >- inflow_outflow_quota_rate defines the rate of total inflows - inflow_outflow_quota_token_base: + inflow_outflow_token_quota_base: type: string title: >- - inflow_outflow_quota_token_base defines the inflow outflow + inflow_outflow_token_quota_base defines the inflow outflow quota base for token title: Params of x/uibc module description: >- @@ -6496,10 +6496,10 @@ definitions: inflow_outflow_quota_rate: type: string title: inflow_outflow_quota_rate defines the rate of total inflows - inflow_outflow_quota_token_base: + inflow_outflow_token_quota_base: type: string title: >- - inflow_outflow_quota_token_base defines the inflow outflow quota base + inflow_outflow_token_quota_base defines the inflow outflow quota base for token title: Params of x/uibc module umee.uibc.v1.QueryAllOutflowsResponse: @@ -6567,10 +6567,10 @@ definitions: inflow_outflow_quota_rate: type: string title: inflow_outflow_quota_rate defines the rate of total inflows - inflow_outflow_quota_token_base: + inflow_outflow_token_quota_base: type: string title: >- - inflow_outflow_quota_token_base defines the inflow outflow quota + inflow_outflow_token_quota_base defines the inflow outflow quota base for token title: Params of x/uibc module description: |- diff --git a/x/uibc/client/tests/cli_test.go b/x/uibc/client/tests/cli_test.go index 394974a539..a8629fa71b 100644 --- a/x/uibc/client/tests/cli_test.go +++ b/x/uibc/client/tests/cli_test.go @@ -22,7 +22,7 @@ func TestIntegrationSuite(t *testing.T) { var uibcGenState uibc.GenesisState assert.NilError(t, cfg.Codec.UnmarshalJSON(cfg.GenesisState[uibc.ModuleName], &uibcGenState)) uibcGenState.Outflows = sdk.DecCoins{sdk.NewInt64DecCoin("uumee", 0)} - uibcGenState.TotalOutflowSum = sdk.NewDec(10) + uibcGenState.OutflowSum = sdk.NewDec(10) bz, err := cfg.Codec.MarshalJSON(&uibcGenState) assert.NilError(t, err) diff --git a/x/uibc/genesis.go b/x/uibc/genesis.go index 473377eecb..a39d655d2f 100644 --- a/x/uibc/genesis.go +++ b/x/uibc/genesis.go @@ -11,7 +11,7 @@ func NewGenesisState(params Params, outflows sdk.DecCoins, outflowSum sdk.Dec) * return &GenesisState{ Params: params, Outflows: outflows, - TotalOutflowSum: outflowSum, + OutflowSum: outflowSum, } } @@ -20,8 +20,8 @@ func DefaultGenesisState() *GenesisState { Params: DefaultParams(), Inflows: nil, Outflows: nil, - TotalOutflowSum: sdk.NewDec(0), - TotalInflowSum: sdk.NewDec(0), + OutflowSum: sdk.NewDec(0), + InflowSum: sdk.NewDec(0), } } @@ -49,12 +49,12 @@ func (gs GenesisState) Validate() error { } } - if gs.TotalOutflowSum.IsNegative() { - return fmt.Errorf("total outflow sum cannot be negative : %s ", gs.TotalOutflowSum.String()) + if gs.OutflowSum.IsNegative() { + return fmt.Errorf("total outflow sum cannot be negative : %s ", gs.OutflowSum.String()) } - if gs.TotalInflowSum.IsNegative() { - return fmt.Errorf("total inflow sum cannot be negative : %s ", gs.TotalInflowSum.String()) + if gs.InflowSum.IsNegative() { + return fmt.Errorf("total inflow sum cannot be negative : %s ", gs.InflowSum.String()) } return nil diff --git a/x/uibc/genesis.pb.go b/x/uibc/genesis.pb.go index 5c2f1d014e..a186711dc3 100644 --- a/x/uibc/genesis.pb.go +++ b/x/uibc/genesis.pb.go @@ -34,14 +34,14 @@ const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package type GenesisState struct { Params Params `protobuf:"bytes,1,opt,name=params,proto3" json:"params"` Outflows github_com_cosmos_cosmos_sdk_types.DecCoins `protobuf:"bytes,2,rep,name=outflows,proto3,castrepeated=github.com/cosmos/cosmos-sdk/types.DecCoins" json:"outflows"` - // 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"` + // outflow_sum defines the total outflow sum of ibc-transfer in USD. + 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"` // quota_expires defines quota expire time (as unix timestamp) for ibc-transfer denom. QuotaExpires time.Time `protobuf:"bytes,4,opt,name=quota_expires,json=quotaExpires,proto3,stdtime" json:"quota_duration,omitempty" yaml:"quota_expires"` // inflows tracks IBC inflow transfers (in USD) for each denom during quota period. Inflows github_com_cosmos_cosmos_sdk_types.DecCoins `protobuf:"bytes,5,rep,name=inflows,proto3,castrepeated=github.com/cosmos/cosmos-sdk/types.DecCoins" json:"inflows"` - // total_inflow_sum defines tracks total sum of IBC inflow transfers (in USD) during quota period. - TotalInflowSum github_com_cosmos_cosmos_sdk_types.Dec `protobuf:"bytes,6,opt,name=total_inflow_sum,json=totalInflowSum,proto3,customtype=github.com/cosmos/cosmos-sdk/types.Dec" json:"total_inflow_sum"` + // inflow_sum defines tracks total sum of IBC inflow transfers (in USD) during quota period. + InflowSum github_com_cosmos_cosmos_sdk_types.Dec `protobuf:"bytes,6,opt,name=inflow_sum,json=inflowSum,proto3,customtype=github.com/cosmos/cosmos-sdk/types.Dec" json:"inflow_sum"` } func (m *GenesisState) Reset() { *m = GenesisState{} } @@ -84,37 +84,36 @@ func init() { func init() { proto.RegisterFile("umee/uibc/v1/genesis.proto", fileDescriptor_0196ecf2d08401fb) } var fileDescriptor_0196ecf2d08401fb = []byte{ - // 482 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xb4, 0x92, 0xbf, 0x8e, 0x13, 0x3d, - 0x14, 0xc5, 0x67, 0xbe, 0xcd, 0x17, 0xc0, 0x1b, 0xfe, 0x8d, 0x52, 0x0c, 0x11, 0x9a, 0x89, 0x52, - 0xa0, 0x48, 0x10, 0x5b, 0xc9, 0x4a, 0x14, 0x88, 0x2a, 0x04, 0x21, 0x2a, 0x50, 0x96, 0x8a, 0x26, - 0xf2, 0xcc, 0x3a, 0xb3, 0x56, 0xe2, 0xb9, 0xc3, 0xd8, 0xce, 0x6e, 0x0a, 0xde, 0x61, 0x9f, 0x83, - 0x9a, 0x87, 0x48, 0xb9, 0xa2, 0x42, 0x14, 0x59, 0x48, 0x3a, 0x1a, 0x24, 0x9e, 0x00, 0x8d, 0xed, - 0xa0, 0xdd, 0x8e, 0x02, 0xaa, 0x99, 0x7b, 0x8f, 0xef, 0xb9, 0xc7, 0x3f, 0x19, 0xb5, 0xb4, 0x60, - 0x8c, 0x68, 0x9e, 0xa4, 0x64, 0xd1, 0x27, 0x19, 0xcb, 0x99, 0xe4, 0x12, 0x17, 0x25, 0x28, 0x08, - 0x1a, 0x95, 0x86, 0x2b, 0x0d, 0x2f, 0xfa, 0xad, 0x66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zipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xb4, 0x92, 0x31, 0x8f, 0xd3, 0x30, + 0x14, 0xc7, 0x13, 0xae, 0x14, 0xce, 0x2d, 0x4b, 0xd4, 0x21, 0x54, 0x28, 0xa9, 0x3a, 0xa0, 0x4a, + 0x50, 0x5b, 0xed, 0x49, 0x0c, 0x88, 0xa9, 0x14, 0xb1, 0xa2, 0x96, 0x09, 0x84, 0x2a, 0x27, 0xe7, + 0x0b, 0x56, 0xeb, 0xbc, 0x10, 0xdb, 0xbd, 0xeb, 0xc0, 0x77, 0xb8, 0xcf, 0xc1, 0xcc, 0x87, 0xe8, + 0x78, 0x62, 0x02, 0x86, 0x1e, 0xb4, 0x1b, 0x23, 0x9f, 0x00, 0xc5, 0x76, 0xd1, 0xdd, 0xc6, 0xc0, + 0x4d, 0xf1, 0xcb, 0xff, 0xbd, 0xff, 0xfb, 0xfb, 0x27, 0xa3, 0xb6, 0x16, 0x8c, 0x11, 0xcd, 0x93, + 0x94, 0x2c, 0x07, 0x24, 0x63, 0x39, 0x93, 0x5c, 0xe2, 0xa2, 0x04, 0x05, 0x41, 0xb3, 0xd2, 0x70, + 0xa5, 0xe1, 0xe5, 0xa0, 0xdd, 0xca, 0x20, 0x03, 0x23, 0x90, 0xea, 0x64, 0x7b, 0xda, 0xf7, 0x53, + 0x90, 0x02, 0xe4, 0xcc, 0x0a, 0xb6, 0x70, 0x52, 0x64, 0x2b, 0x92, 0x50, 0xc9, 0xc8, 0x72, 0x90, + 0x30, 0x45, 0x07, 0x24, 0x05, 0x9e, 0x3b, 0x3d, 0xce, 0x00, 0xb2, 0x05, 0x23, 0xa6, 0x4a, 0xf4, + 0x09, 0x51, 0x5c, 0x30, 0xa9, 0xa8, 0x28, 0x5c, 0x43, 0x78, 0x2d, 0xdb, 0x07, 0x0d, 0x8a, 0x5a, + 0xa5, 0xfb, 0xad, 0x86, 0x9a, 0x2f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0x76, 0xaf, 0x59, 0x77, 0xcf, 0x2f, + 0x63, 0x7f, 0xd2, 0x34, 0xff, 0x5e, 0xd8, 0x5f, 0xc1, 0x1c, 0xdd, 0xe1, 0xb9, 0x65, 0x79, 0xfb, + 0xa6, 0x58, 0xee, 0x37, 0x04, 0x6f, 0x11, 0xb2, 0x47, 0x43, 0xb2, 0xfe, 0x1f, 0x48, 0x1e, 0x5a, + 0xbf, 0xa9, 0x16, 0xa3, 0xf1, 0xfa, 0x67, 0xe4, 0xad, 0xb7, 0x91, 0x7f, 0xb1, 0x8d, 0xfc, 0x1f, + 0xdb, 0xc8, 0x3f, 0xdf, 0x45, 0xde, 0xc5, 0x2e, 0xf2, 0xbe, 0xee, 0x22, 0xef, 0xcd, 0x55, 0xfb, + 0xea, 0x89, 0xf5, 0x73, 0xa6, 0x4e, 0xa1, 0x9c, 0x9b, 0x82, 0x2c, 0x9f, 0x90, 0x33, 0xf3, 0x60, + 0x93, 0xba, 0xe1, 0x7d, 0xf4, 0x27, 0x00, 0x00, 0xff, 0xff, 0x88, 0x33, 0x7c, 0xfa, 0x60, 0x03, 0x00, 0x00, } @@ -139,9 +138,9 @@ func (m *GenesisState) MarshalToSizedBuffer(dAtA []byte) (int, error) { var l int _ = l { - size := m.TotalInflowSum.Size() + size := m.InflowSum.Size() i -= size - if _, err := m.TotalInflowSum.MarshalTo(dAtA[i:]); err != nil { + if _, err := m.InflowSum.MarshalTo(dAtA[i:]); err != nil { return 0, err } i = encodeVarintGenesis(dAtA, i, uint64(size)) @@ -171,9 +170,9 @@ func (m *GenesisState) MarshalToSizedBuffer(dAtA []byte) (int, error) { i-- dAtA[i] = 0x22 { - size := m.TotalOutflowSum.Size() + size := m.OutflowSum.Size() i -= size - if _, err := m.TotalOutflowSum.MarshalTo(dAtA[i:]); err != nil { + if _, err := m.OutflowSum.MarshalTo(dAtA[i:]); err != nil { return 0, err } i = encodeVarintGenesis(dAtA, i, uint64(size)) @@ -232,7 +231,7 @@ func (m *GenesisState) Size() (n int) { n += 1 + l + sovGenesis(uint64(l)) } } - l = m.TotalOutflowSum.Size() + l = m.OutflowSum.Size() n += 1 + l + sovGenesis(uint64(l)) l = github_com_cosmos_gogoproto_types.SizeOfStdTime(m.QuotaExpires) n += 1 + l + sovGenesis(uint64(l)) @@ -242,7 +241,7 @@ func (m *GenesisState) Size() (n int) { n += 1 + l + sovGenesis(uint64(l)) } } - l = m.TotalInflowSum.Size() + l = m.InflowSum.Size() n += 1 + l + sovGenesis(uint64(l)) return n } @@ -351,7 +350,7 @@ func (m *GenesisState) Unmarshal(dAtA []byte) error { iNdEx = postIndex case 3: if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field TotalOutflowSum", wireType) + return fmt.Errorf("proto: wrong wireType = %d for field OutflowSum", wireType) } var stringLen uint64 for shift := uint(0); ; shift += 7 { @@ -379,7 +378,7 @@ func (m *GenesisState) Unmarshal(dAtA []byte) error { if postIndex > l { return io.ErrUnexpectedEOF } - if err := m.TotalOutflowSum.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + if err := m.OutflowSum.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { return err } iNdEx = postIndex @@ -452,7 +451,7 @@ func (m *GenesisState) Unmarshal(dAtA []byte) error { iNdEx = postIndex case 6: if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field TotalInflowSum", wireType) + return fmt.Errorf("proto: wrong wireType = %d for field InflowSum", wireType) } var stringLen uint64 for shift := uint(0); ; shift += 7 { @@ -480,7 +479,7 @@ func (m *GenesisState) Unmarshal(dAtA []byte) error { if postIndex > l { return io.ErrUnexpectedEOF } - if err := m.TotalInflowSum.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + if err := m.InflowSum.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { return err } iNdEx = postIndex diff --git a/x/uibc/genesis_test.go b/x/uibc/genesis_test.go index 5465034582..c22a307c9e 100644 --- a/x/uibc/genesis_test.go +++ b/x/uibc/genesis_test.go @@ -12,7 +12,7 @@ func TestGenesisValidation(t *testing.T) { err := gs.Validate() assert.NilError(t, err) - gs.TotalOutflowSum = sdk.NewDec(-123123) + gs.OutflowSum = sdk.NewDec(-123123) err = gs.Validate() assert.ErrorContains(t, err, "total outflow sum cannot be negative") diff --git a/x/uibc/params.go b/x/uibc/params.go index 4a6b756cce..a1913f19f3 100644 --- a/x/uibc/params.go +++ b/x/uibc/params.go @@ -16,7 +16,7 @@ func DefaultParams() Params { QuotaDuration: time.Second * 60 * 60 * 24, // 24h InflowOutflowQuotaBase: sdk.NewDec(1_000_000), // 1M InflowOutflowQuotaRate: sdk.MustNewDecFromStr("0.25"), - InflowOutflowQuotaTokenBase: sdk.NewDec(900_000), // $0.9M + InflowOutflowTokenQuotaBase: sdk.NewDec(900_000), // $0.9M } } @@ -39,7 +39,7 @@ func (p Params) Validate() error { if err := validateQuotaRate(p.InflowOutflowQuotaRate, "total inflow outflow quota rate"); err != nil { return err } - if err := validateQuota(p.InflowOutflowQuotaTokenBase, "total inflow outflow quota token base"); err != nil { + if err := validateQuota(p.InflowOutflowTokenQuotaBase, "total inflow outflow quota token base"); err != nil { return err } if p.TotalQuota.LT(p.TokenQuota) { diff --git a/x/uibc/quota.pb.go b/x/uibc/quota.pb.go index 10916eb2b9..8393ba51a8 100644 --- a/x/uibc/quota.pb.go +++ b/x/uibc/quota.pb.go @@ -87,8 +87,8 @@ type Params struct { InflowOutflowQuotaBase github_com_cosmos_cosmos_sdk_types.Dec `protobuf:"bytes,5,opt,name=inflow_outflow_quota_base,json=inflowOutflowQuotaBase,proto3,customtype=github.com/cosmos/cosmos-sdk/types.Dec" json:"inflow_outflow_quota_base"` // inflow_outflow_quota_rate defines the rate of total inflows InflowOutflowQuotaRate github_com_cosmos_cosmos_sdk_types.Dec `protobuf:"bytes,6,opt,name=inflow_outflow_quota_rate,json=inflowOutflowQuotaRate,proto3,customtype=github.com/cosmos/cosmos-sdk/types.Dec" json:"inflow_outflow_quota_rate"` - // inflow_outflow_quota_token_base defines the inflow outflow quota base for token - InflowOutflowQuotaTokenBase github_com_cosmos_cosmos_sdk_types.Dec `protobuf:"bytes,7,opt,name=inflow_outflow_quota_token_base,json=inflowOutflowQuotaTokenBase,proto3,customtype=github.com/cosmos/cosmos-sdk/types.Dec" json:"inflow_outflow_quota_token_base"` + // inflow_outflow_token_quota_base defines the inflow outflow quota base for token + InflowOutflowTokenQuotaBase github_com_cosmos_cosmos_sdk_types.Dec `protobuf:"bytes,7,opt,name=inflow_outflow_token_quota_base,json=inflowOutflowTokenQuotaBase,proto3,customtype=github.com/cosmos/cosmos-sdk/types.Dec" json:"inflow_outflow_token_quota_base"` } func (m *Params) Reset() { *m = Params{} } @@ -146,43 +146,43 @@ func init() { func init() { proto.RegisterFile("umee/uibc/v1/quota.proto", fileDescriptor_651be1a0280abcb6) } var fileDescriptor_651be1a0280abcb6 = []byte{ - // 571 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xb4, 0x94, 0xcf, 0x8b, 0xd3, 0x40, - 0x14, 0xc7, 0x9b, 0xfd, 0x25, 0x3b, 0xab, 0xcb, 0x1a, 0x54, 0xd2, 0x15, 0x92, 0x5a, 0xdd, 0x52, - 0x17, 0x9b, 0xb0, 0x2b, 0x78, 0x10, 0x15, 0x9b, 0x26, 0x0b, 0x01, 0x69, 0xbb, 0x49, 0x7a, 0x11, - 0x24, 0x4c, 0xb2, 0xd3, 0x1a, 0xda, 0x64, 0x6a, 0x32, 0x69, 0xed, 0x49, 0xf0, 0xe4, 0xd1, 0xa3, - 0x7f, 0x88, 0x7f, 0xc4, 0x1e, 0x17, 0x4f, 0xe2, 0xa1, 0x4a, 0x7b, 0xf3, 0xe8, 0x1f, 0x20, 0x92, - 0x99, 0x94, 0xdd, 0x65, 0xdb, 0x5b, 0x3d, 0xcd, 0xbc, 0xbc, 0xef, 0x7c, 0xbe, 0xef, 0xbd, 0x24, - 0x03, 0x84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x07, 0xee, 0x2d, 0xd6, 0xe9, 0x75, 0x26, 0x5b, 0xe1, 0xf7, 0x41, 0x69, 0xb1, 0xac, 0xd1, 0xb2, - 0xcf, 0x91, 0xab, 0xfc, 0x43, 0xb0, 0xb7, 0x58, 0x6b, 0xd4, 0xcf, 0xa5, 0x6b, 0x7c, 0x19, 0x3c, - 0x98, 0x27, 0x9d, 0xc5, 0x96, 0xd3, 0xac, 0xb6, 0x2c, 0x5d, 0xdb, 0x59, 0x57, 0x5f, 0x9e, 0x4e, - 0x44, 0xee, 0x6c, 0x22, 0x72, 0xbf, 0x26, 0x22, 0xf7, 0x79, 0x2a, 0xe6, 0xce, 0xa6, 0x62, 0xee, - 0xfb, 0x54, 0xcc, 0xbd, 0xbe, 0x38, 0xf7, 0xf4, 0x42, 0xa8, 0x84, 0x88, 0x0c, 0x71, 0xd4, 0xa5, - 0x81, 0x32, 0x78, 0xa2, 0xbc, 0xa7, 0x77, 0x97, 0xbb, 0x41, 0x7f, 0x92, 0xc7, 0xff, 0x02, 0x00, - 0x00, 0xff, 0xff, 0xf1, 0xe6, 0x9a, 0xe6, 0xcf, 0x04, 0x00, 0x00, + // 574 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xb4, 0x94, 0x4f, 0x6f, 0xd3, 0x4c, + 0x10, 0xc6, 0xe3, 0xfe, 0x7b, 0xd5, 0xed, 0x4b, 0x55, 0x2c, 0x40, 0x6e, 0x91, 0xec, 0x10, 0x68, + 0x14, 0x2a, 0x62, 0xab, 0x45, 0xe2, 0x80, 0x00, 0x11, 0xc7, 0xae, 0x64, 0x09, 0x25, 0xa9, 0xed, + 0x5c, 0x90, 0x90, 0xb5, 0x76, 0x37, 0xc1, 0x4a, 0xec, 0x0d, 0xf6, 0x3a, 0x21, 0x27, 0x24, 0x4e, + 0x1c, 0x39, 0xf2, 0x41, 0xf8, 0x10, 0x3d, 0x56, 0x9c, 0x10, 0x87, 0x80, 0x92, 0x1b, 0x47, 0x3e, + 0x00, 0x42, 0xde, 0x75, 0x68, 0x02, 0xcd, 0x2d, 0x9c, 0x76, 0x27, 0xf3, 0xec, 0xef, 0x99, 0x99, + 0x8d, 0x17, 0x08, 0x49, 0x80, 0x90, 0x92, 0xf8, 0xae, 0xa7, 0xf4, 0x0f, 0x95, 0x57, 0x09, 0x26, + 0x50, 0xee, 0x45, 0x98, 0x60, 0xfe, 0xff, 0x34, 0x23, 0xa7, 0x19, 0xb9, 0x7f, 0xb8, 0x77, 0xad, + 0x8d, 0xdb, 0x98, 0x26, 0x94, 0x74, 0xc7, 0x34, 0x7b, 0x62, 0x1b, 0xe3, 0x76, 0x17, 0x29, 0x34, + 0x72, 0x93, 0x96, 0x72, 0x9a, 0x44, 0x90, 0xf8, 0x38, 0xcc, 0xf2, 0xbb, 0x1e, 0x8e, 0x03, 0x1c, + 0x3b, 0xec, 0x20, 0x0b, 0x58, 0xaa, 0xf0, 0x73, 0x1d, 0x6c, 0x34, 0x60, 0x04, 0x83, 0x98, 0x7f, + 0x02, 0x80, 0xef, 0x7a, 0x4e, 0x4c, 0x20, 0x49, 0x62, 0x81, 0xcb, 0x73, 0xa5, 0xed, 0x23, 0x49, + 0x9e, 0xb5, 0x97, 0x0d, 0xb5, 0x6a, 0x47, 0x30, 0x8c, 0x5b, 0x28, 0xb2, 0xa8, 0xcc, 0xdc, 0xf4, + 0x5d, 0x8f, 0x6d, 0xf9, 0x17, 0x60, 0x8b, 0x60, 0x02, 0xbb, 0x0e, 0x2d, 0x5f, 0x58, 0xc9, 0x73, + 0xa5, 0x4d, 0xf5, 0xd1, 0xd9, 0x48, 0xca, 0x7d, 0x19, 0x49, 0xc5, 0xb6, 0x4f, 0x5e, 0x26, 0xae, + 0xec, 0xe1, 0x20, 0x2b, 0x20, 0x5b, 0xca, 0xf1, 0x69, 0x47, 0x21, 0xc3, 0x1e, 0x8a, 0x65, 0x0d, + 0x79, 0x9f, 0x3e, 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 0xc7, 0x86, 0xae, 0xed, 0xe4, 0xf8, + 0x22, 0x28, 0x5c, 0x26, 0x3a, 0x69, 0xd6, 0xed, 0x8a, 0xa3, 0x19, 0x56, 0x45, 0x7d, 0xa6, 0x6b, + 0x3b, 0x1c, 0xbf, 0x0f, 0x6e, 0x2d, 0xd6, 0xe9, 0x35, 0x26, 0x5b, 0xe1, 0x0f, 0x40, 0x71, 0xb1, + 0xac, 0xde, 0xb4, 0x2f, 0x90, 0xab, 0xfc, 0x5d, 0xb0, 0xbf, 0x58, 0x6b, 0xd4, 0x2e, 0xa4, 0x6b, + 0x7c, 0x09, 0xdc, 0xb9, 0x4c, 0x3a, 0x8d, 0x2d, 0xa7, 0x51, 0x69, 0x5a, 0xba, 0xb6, 0xb3, 0xae, + 0x3e, 0x3d, 0x1b, 0x8b, 0xdc, 0xf9, 0x58, 0xe4, 0xbe, 0x8d, 0x45, 0xee, 0xfd, 0x44, 0xcc, 0x9d, + 0x4f, 0xc4, 0xdc, 0xe7, 0x89, 0x98, 0x7b, 0x3e, 0x3b, 0xf7, 0xf4, 0x41, 0x28, 0x87, 0x88, 0x0c, + 0x70, 0xd4, 0xa1, 0x81, 0xd2, 0x7f, 0xa0, 0xbc, 0xa6, 0x6f, 0x97, 0xbb, 0x41, 0x3f, 0x92, 0xfb, + 0xbf, 0x02, 0x00, 0x00, 0xff, 0xff, 0x33, 0x81, 0x46, 0x7f, 0xcf, 0x04, 0x00, 0x00, } func (m *Params) Marshal() (dAtA []byte, err error) { @@ -206,9 +206,9 @@ func (m *Params) MarshalToSizedBuffer(dAtA []byte) (int, error) { var l int _ = l { - size := m.InflowOutflowQuotaTokenBase.Size() + size := m.InflowOutflowTokenQuotaBase.Size() i -= size - if _, err := m.InflowOutflowQuotaTokenBase.MarshalTo(dAtA[i:]); err != nil { + if _, err := m.InflowOutflowTokenQuotaBase.MarshalTo(dAtA[i:]); err != nil { return 0, err } i = encodeVarintQuota(dAtA, i, uint64(size)) @@ -301,7 +301,7 @@ func (m *Params) Size() (n int) { n += 1 + l + sovQuota(uint64(l)) l = m.InflowOutflowQuotaRate.Size() n += 1 + l + sovQuota(uint64(l)) - l = m.InflowOutflowQuotaTokenBase.Size() + l = m.InflowOutflowTokenQuotaBase.Size() n += 1 + l + sovQuota(uint64(l)) return n } @@ -531,7 +531,7 @@ func (m *Params) Unmarshal(dAtA []byte) error { iNdEx = postIndex case 7: if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field InflowOutflowQuotaTokenBase", wireType) + return fmt.Errorf("proto: wrong wireType = %d for field InflowOutflowTokenQuotaBase", wireType) } var stringLen uint64 for shift := uint(0); ; shift += 7 { @@ -559,7 +559,7 @@ func (m *Params) Unmarshal(dAtA []byte) error { if postIndex > l { return io.ErrUnexpectedEOF } - if err := m.InflowOutflowQuotaTokenBase.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + if err := m.InflowOutflowTokenQuotaBase.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { return err } iNdEx = postIndex diff --git a/x/uibc/quota/keeper/genesis.go b/x/uibc/quota/keeper/genesis.go index 2fd86cb0d4..4464086cdc 100644 --- a/x/uibc/quota/keeper/genesis.go +++ b/x/uibc/quota/keeper/genesis.go @@ -15,8 +15,8 @@ func (kb Builder) InitGenesis(ctx sdk.Context, genState uibc.GenesisState) { k.SetTokenOutflows(genState.Outflows) k.SetTokenInflows(genState.Inflows) - k.SetTotalOutflowSum(genState.TotalOutflowSum) - k.SetTotalInflow(genState.TotalInflowSum) + k.SetOutflowSum(genState.TotalOutflowSum) + k.SetTotalInflow(genState.InflowSum) err = k.SetExpire(genState.QuotaExpires) util.Panic(err) @@ -35,9 +35,9 @@ func (kb Builder) ExportGenesis(ctx sdk.Context) *uibc.GenesisState { return &uibc.GenesisState{ Params: k.GetParams(), Outflows: outflows, - TotalOutflowSum: k.GetTotalOutflow(), + OutflowSum: k.GetTotalOutflow(), QuotaExpires: *quotaExpires, Inflows: inflows, - TotalInflowSum: k.GetTotalInflow(), + InflowSum: k.GetTotalInflow(), } } diff --git a/x/uibc/quota/keeper/migrations.go b/x/uibc/quota/keeper/migrations.go index d1bf8d9b8f..68435abcef 100644 --- a/x/uibc/quota/keeper/migrations.go +++ b/x/uibc/quota/keeper/migrations.go @@ -9,9 +9,9 @@ func (k Keeper) getOldTotalOutflow() sdk.Dec { return sdk.MustNewDecFromStr(string(bz)) } -// MigrateTotalOutflowSum migrate the old total outflow type to new one +// MigrateOutflowSum migrate the old total outflow type to new one // Note: only use for v6.2 migration from v6.1.0 -func (k Keeper) MigrateTotalOutflowSum() { +func (k Keeper) MigrateOutflowSum() { oldTotalOutflow := k.getOldTotalOutflow() - k.SetTotalOutflowSum(oldTotalOutflow) + k.SetOutflowSum(oldTotalOutflow) } diff --git a/x/uibc/quota/keeper/params_test.go b/x/uibc/quota/keeper/params_test.go index 5c0a38be15..ffde415ac4 100644 --- a/x/uibc/quota/keeper/params_test.go +++ b/x/uibc/quota/keeper/params_test.go @@ -24,7 +24,7 @@ func TestUnitParams(t *testing.T) { params.TotalQuota = sdk.MustNewDecFromStr("3.4321") params.InflowOutflowQuotaBase = sdk.MustNewDecFromStr("3.4321") params.InflowOutflowQuotaRate = sdk.MustNewDecFromStr("0.2") - params.InflowOutflowQuotaTokenBase = sdk.MustNewDecFromStr("0.2") + params.InflowOutflowTokenQuotaBase = sdk.MustNewDecFromStr("0.2") err := k.SetParams(params) require.NoError(err) diff --git a/x/uibc/quota/keeper/quota.go b/x/uibc/quota/keeper/quota.go index b02ff66531..2c9aa55a8a 100644 --- a/x/uibc/quota/keeper/quota.go +++ b/x/uibc/quota/keeper/quota.go @@ -40,8 +40,8 @@ func (k Keeper) SetTokenOutflows(outflows sdk.DecCoins) { } } -// SetTotalOutflowSum save the total outflow of ibc-transfer amount. -func (k Keeper) SetTotalOutflowSum(amount sdk.Dec) { +// SetOutflowSum save the total outflow of ibc-transfer amount. +func (k Keeper) SetOutflowSum(amount sdk.Dec) { err := store.SetDec(k.store, keyTotalOutflows, amount, "total_outflow_sum") util.Panic(err) } @@ -121,7 +121,7 @@ func (k Keeper) ResetAllQuotas() error { } zero := sdk.NewDec(0) // outflows - k.SetTotalOutflowSum(zero) + k.SetOutflowSum(zero) ps := k.PrefixStore(keyPrefixDenomOutflows) store.DeleteByPrefixStore(ps) @@ -150,7 +150,7 @@ func (k Keeper) CheckAndUpdateQuota(denom string, newOutflow sdkmath.Int) error inToken := k.GetTokenInflow(denom) if !params.TokenQuota.IsZero() { if o.Amount.GT(params.TokenQuota) || - o.Amount.GT(params.InflowOutflowQuotaTokenBase.Add((params.InflowOutflowQuotaRate.Mul(inToken.Amount)))) { + o.Amount.GT(params.InflowOutflowTokenQuotaBase.Add((params.InflowOutflowQuotaRate.Mul(inToken.Amount)))) { return uibc.ErrQuotaExceeded } } @@ -168,7 +168,7 @@ func (k Keeper) CheckAndUpdateQuota(denom string, newOutflow sdkmath.Int) error } } k.SetTokenOutflow(o) - k.SetTotalOutflowSum(totalOutflowSum) + k.SetOutflowSum(totalOutflowSum) return nil } @@ -225,7 +225,7 @@ func (k Keeper) UndoUpdateQuota(denom string, amount sdkmath.Int) error { k.SetTokenOutflow(o) totalOutflowSum := k.GetTotalOutflow() - k.SetTotalOutflowSum(totalOutflowSum.Sub(exchangePrice)) + k.SetOutflowSum(totalOutflowSum.Sub(exchangePrice)) return nil } diff --git a/x/uibc/quota/keeper/quota_test.go b/x/uibc/quota/keeper/quota_test.go index 27a608810d..2591fd5701 100644 --- a/x/uibc/quota/keeper/quota_test.go +++ b/x/uibc/quota/keeper/quota_test.go @@ -46,7 +46,7 @@ func TestUnitCheckAndUpdateQuota(t *testing.T) { k.setQuotaParams(10, 100) k.SetTokenOutflow(sdk.NewInt64DecCoin(umee, 6)) k.SetTokenInflow(sdk.NewInt64DecCoin(umee, 6)) - k.SetTotalOutflowSum(sdk.NewDec(50)) + k.SetOutflowSum(sdk.NewDec(50)) k.SetTotalInflow(sdk.NewDec(50)) k.SetTokenInflow(sdk.NewDecCoin(umee, math.NewInt(50))) @@ -106,13 +106,13 @@ func TestUnitCheckAndUpdateQuota(t *testing.T) { dp := uibc.DefaultParams() dp.TotalQuota = sdk.NewDec(200) dp.TokenQuota = sdk.NewDec(500) - dp.InflowOutflowQuotaTokenBase = sdk.NewDec(100) + dp.InflowOutflowTokenQuotaBase = sdk.NewDec(100) err = k.SetParams(dp) assert.NilError(t, err) k.SetTokenOutflow(sdk.NewDecCoin(umee, math.NewInt(80))) k.SetTokenInflow(sdk.NewDecCoin(umee, math.NewInt(80))) - // 80*2 (160) > InflowOutflowQuotaTokenBase(100) + 25% of Token Inflow (80) = 160 > 100+20 + // 80*2 (160) > InflowOutflowTokenQuotaBase(100) + 25% of Token Inflow (80) = 160 > 100+20 err = k.CheckAndUpdateQuota(umee, sdk.NewInt(80)) // exceeds token quota assert.ErrorContains(t, err, "quota") err = k.CheckAndUpdateQuota(umee, sdk.NewInt(5)) @@ -123,7 +123,7 @@ func TestUnitCheckAndUpdateQuota(t *testing.T) { dp.InflowOutflowQuotaBase = sdk.NewDec(100) dp.TotalQuota = sdk.NewDec(100) err = k.SetParams(dp) - k.SetTotalOutflowSum(sdk.NewDec(80)) + k.SetOutflowSum(sdk.NewDec(80)) // 80+(20*2) > Total Outflow Quota Limit (100) err = k.CheckAndUpdateQuota(umee, sdk.NewInt(20)) // exceeds token quota assert.ErrorContains(t, err, "quota") From 0f89f6b6d94f0a674478eafccc76d59f5b0e1ebf Mon Sep 17 00:00:00 2001 From: Robert Zaremba Date: Mon, 20 Nov 2023 17:41:41 +0100 Subject: [PATCH 03/13] more updates --- x/uibc/quota/keeper/genesis.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/x/uibc/quota/keeper/genesis.go b/x/uibc/quota/keeper/genesis.go index 4464086cdc..1274060fda 100644 --- a/x/uibc/quota/keeper/genesis.go +++ b/x/uibc/quota/keeper/genesis.go @@ -15,7 +15,7 @@ func (kb Builder) InitGenesis(ctx sdk.Context, genState uibc.GenesisState) { k.SetTokenOutflows(genState.Outflows) k.SetTokenInflows(genState.Inflows) - k.SetOutflowSum(genState.TotalOutflowSum) + k.SetOutflowSum(genState.OutflowSum) k.SetTotalInflow(genState.InflowSum) err = k.SetExpire(genState.QuotaExpires) From 5612105006bd46b6718f7cb398eeebbb67410c66 Mon Sep 17 00:00:00 2001 From: Robert Zaremba Date: Mon, 20 Nov 2023 17:42:48 +0100 Subject: [PATCH 04/13] typo --- x/uibc/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/x/uibc/README.md b/x/uibc/README.md index 406a7eaf64..8d6df99aa6 100644 --- a/x/uibc/README.md +++ b/x/uibc/README.md @@ -34,7 +34,7 @@ For inflows: Similarly to inflows, we measure outflows per token and aggregates (sum): -- `iutflows`: metric per token. +- `outflows`: metric per token. - `total_outflow_sum`: sum of `outflows` from the previous point. The metrics above are reset every `params.quota_duration` in Begin Blocker. From b069a77da077701e88549e7b2fb267bd9cdf8108 Mon Sep 17 00:00:00 2001 From: Robert Zaremba Date: Mon, 20 Nov 2023 17:45:50 +0100 Subject: [PATCH 05/13] lint --- x/uibc/genesis.go | 10 +++++----- x/uibc/quota/keeper/genesis.go | 12 ++++++------ 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/x/uibc/genesis.go b/x/uibc/genesis.go index a39d655d2f..d5e544e094 100644 --- a/x/uibc/genesis.go +++ b/x/uibc/genesis.go @@ -9,17 +9,17 @@ import ( func NewGenesisState(params Params, outflows sdk.DecCoins, outflowSum sdk.Dec) *GenesisState { return &GenesisState{ - Params: params, - Outflows: outflows, + Params: params, + Outflows: outflows, OutflowSum: outflowSum, } } func DefaultGenesisState() *GenesisState { return &GenesisState{ - Params: DefaultParams(), - Inflows: nil, - Outflows: nil, + Params: DefaultParams(), + Inflows: nil, + Outflows: nil, OutflowSum: sdk.NewDec(0), InflowSum: sdk.NewDec(0), } diff --git a/x/uibc/quota/keeper/genesis.go b/x/uibc/quota/keeper/genesis.go index 1274060fda..52740f5756 100644 --- a/x/uibc/quota/keeper/genesis.go +++ b/x/uibc/quota/keeper/genesis.go @@ -33,11 +33,11 @@ func (kb Builder) ExportGenesis(ctx sdk.Context) *uibc.GenesisState { util.Panic(err) return &uibc.GenesisState{ - Params: k.GetParams(), - Outflows: outflows, - OutflowSum: k.GetTotalOutflow(), - QuotaExpires: *quotaExpires, - Inflows: inflows, - InflowSum: k.GetTotalInflow(), + Params: k.GetParams(), + Outflows: outflows, + OutflowSum: k.GetTotalOutflow(), + QuotaExpires: *quotaExpires, + Inflows: inflows, + InflowSum: k.GetTotalInflow(), } } From 1f5c09875454a608fa1b1f30779c82d3f7df68a9 Mon Sep 17 00:00:00 2001 From: Robert Zaremba Date: Mon, 20 Nov 2023 17:46:25 +0100 Subject: [PATCH 06/13] readme --- x/uibc/README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/x/uibc/README.md b/x/uibc/README.md index 8d6df99aa6..f4c21089ec 100644 --- a/x/uibc/README.md +++ b/x/uibc/README.md @@ -35,7 +35,7 @@ For inflows: Similarly to inflows, we measure outflows per token and aggregates (sum): - `outflows`: metric per token. -- `total_outflow_sum`: sum of `outflows` from the previous point. +- `outflow_sum`: sum of `outflows` from the previous point. The metrics above are reset every `params.quota_duration` in Begin Blocker. Example: if the reset was done at 14:00 UTC, then the next reset will be done `quota_duration` later. You can observe the reset with `/umee/uibc/v1/EventQuotaReset` event, which will contain `next_expire` attribute. @@ -45,10 +45,10 @@ Example: if the reset was done at 14:00 UTC, then the next reset will be done `q Inflows and outflows metrics above are used to **limit ICS-20 transfers** of tokens in the x/leverage Token Registry. The outflow transfer of token `X` is possible when: 1. Outflow quota after the transfer is not suppressed: -1. `total_outflow_sum <= params.total_quota`. For example if it's set to 1.6M USD then IBC outflows reaching the total quota will be 600k USD worth of ATOM, 500k USD worth of STATOM, 250k USD worth of UMEE and 250k USD worth JUNO. +1. `outflow_sum <= params.total_quota`. For example if it's set to 1.6M USD then IBC outflows reaching the total quota will be 600k USD worth of ATOM, 500k USD worth of STATOM, 250k USD worth of UMEE and 250k USD worth JUNO. 1. `token_quota[X] <= params.token_quota` - the token X quota is not suppressed. 1. OR Outflow quota lifted by inflows is not reached: -1. `total_outflow_sum <= params.inflow_outflow_quota_base + params.inflow_outflow_quota_rate * total_inflow_sum` +1. `outflow_sum <= params.inflow_outflow_quota_base + params.inflow_outflow_quota_rate * inflow_sum` 1. `token_quota[X] <= params.inflow_outflow_token_quota_base + params.inflow_outflow_token_quota_rate * inflows[X]` See `../../proto/umee/uibc/v1/quota.proto` for the list of all params. From 3d6aef2361aae10fae68056073d6d5e3fbc5e934 Mon Sep 17 00:00:00 2001 From: Robert Zaremba Date: Mon, 20 Nov 2023 17:55:28 +0100 Subject: [PATCH 07/13] ai suggestions --- x/uibc/genesis.go | 4 ++-- x/uibc/quota/keeper/genesis.go | 4 ++-- x/uibc/quota/keeper/quota.go | 29 ++++++++++++++--------------- x/uibc/quota/keeper/quota_test.go | 10 +++++----- 4 files changed, 23 insertions(+), 24 deletions(-) diff --git a/x/uibc/genesis.go b/x/uibc/genesis.go index d5e544e094..51a7643b9e 100644 --- a/x/uibc/genesis.go +++ b/x/uibc/genesis.go @@ -50,11 +50,11 @@ func (gs GenesisState) Validate() error { } if gs.OutflowSum.IsNegative() { - return fmt.Errorf("total outflow sum cannot be negative : %s ", gs.OutflowSum.String()) + return fmt.Errorf("outflow sum cannot be negative : %s ", gs.OutflowSum.String()) } if gs.InflowSum.IsNegative() { - return fmt.Errorf("total inflow sum cannot be negative : %s ", gs.InflowSum.String()) + return fmt.Errorf("inflow sum cannot be negative : %s ", gs.InflowSum.String()) } return nil diff --git a/x/uibc/quota/keeper/genesis.go b/x/uibc/quota/keeper/genesis.go index 52740f5756..f8814d2797 100644 --- a/x/uibc/quota/keeper/genesis.go +++ b/x/uibc/quota/keeper/genesis.go @@ -16,7 +16,7 @@ func (kb Builder) InitGenesis(ctx sdk.Context, genState uibc.GenesisState) { k.SetTokenOutflows(genState.Outflows) k.SetTokenInflows(genState.Inflows) k.SetOutflowSum(genState.OutflowSum) - k.SetTotalInflow(genState.InflowSum) + k.SetInflowSum(genState.InflowSum) err = k.SetExpire(genState.QuotaExpires) util.Panic(err) @@ -38,6 +38,6 @@ func (kb Builder) ExportGenesis(ctx sdk.Context) *uibc.GenesisState { OutflowSum: k.GetTotalOutflow(), QuotaExpires: *quotaExpires, Inflows: inflows, - InflowSum: k.GetTotalInflow(), + InflowSum: k.GetInflowSum(), } } diff --git a/x/uibc/quota/keeper/quota.go b/x/uibc/quota/keeper/quota.go index 2c9aa55a8a..031da8275d 100644 --- a/x/uibc/quota/keeper/quota.go +++ b/x/uibc/quota/keeper/quota.go @@ -89,15 +89,15 @@ func (k Keeper) GetTokenInflow(denom string) sdk.DecCoin { return sdk.NewDecCoinFromDec(denom, amount) } -// GetTotalInflow returns the total inflow of ibc-transfer amount. -func (k Keeper) GetTotalInflow() sdk.Dec { +// GetInflowSum returns the total inflow of ibc-transfer amount. +func (k Keeper) GetInflowSum() sdk.Dec { // When total inflow is not stored in store it will return 0 amount, _ := store.GetDec(k.store, keyTotalInflows, "total_inflows") return amount } -// SetTotalInflow save the total inflow of ibc-transfer amount. -func (k Keeper) SetTotalInflow(amount sdk.Dec) { +// SetInflowSum save the total inflow of ibc-transfer amount. +func (k Keeper) SetInflowSum(amount sdk.Dec) { err := store.SetDec(k.store, keyTotalInflows, amount, "total_inflows") util.Panic(err) } @@ -126,7 +126,7 @@ func (k Keeper) ResetAllQuotas() error { store.DeleteByPrefixStore(ps) // inflows - k.SetTotalInflow(zero) + k.SetInflowSum(zero) ps = k.PrefixStore(keyPrefixDenomInflows) store.DeleteByPrefixStore(ps) return nil @@ -156,19 +156,18 @@ func (k Keeper) CheckAndUpdateQuota(denom string, newOutflow sdkmath.Int) error } // Allow outflow either of two conditions - // 1. Total Outflow Sum <= Total Outflow Quota - // or - // 2. Total Outflow Sum <= params.InflowOutflowQuotaBase + (params.InflowOutflowQuotaRate * sum of all inflows) - totalOutflowSum := k.GetTotalOutflow().Add(exchangePrice) - ttlInSum := k.GetTotalInflow() + // 1. Outflow Sum <= Total Outflow Quota + // 2. OR Outflow Sum <= params.InflowOutflowQuotaBase + (params.InflowOutflowQuotaRate * sum of all inflows) + outflowSum := k.GetTotalOutflow().Add(exchangePrice) + inflowSum := k.GetInflowSum() if !params.TotalQuota.IsZero() { - if totalOutflowSum.GT(params.TotalQuota) || - totalOutflowSum.GT(params.InflowOutflowQuotaBase.Add(ttlInSum.Mul(params.InflowOutflowQuotaRate))) { + if outflowSum.GT(params.TotalQuota) || + outflowSum.GT(params.InflowOutflowQuotaBase.Add(inflowSum.Mul(params.InflowOutflowQuotaRate))) { return uibc.ErrQuotaExceeded } } k.SetTokenOutflow(o) - k.SetOutflowSum(totalOutflowSum) + k.SetOutflowSum(outflowSum) return nil } @@ -261,8 +260,8 @@ func (k Keeper) RecordIBCInflow(ctx sdk.Context, tokenInflow := sdk.NewDecCoinFromDec(ibcDenom, inflowInUSD) k.SetTokenInflow(tokenInflow) - totalInflowSum := k.GetTotalInflow() - k.SetTotalInflow(totalInflowSum.Add(inflowInUSD)) + totalInflowSum := k.GetInflowSum() + k.SetInflowSum(totalInflowSum.Add(inflowInUSD)) } return nil diff --git a/x/uibc/quota/keeper/quota_test.go b/x/uibc/quota/keeper/quota_test.go index 2591fd5701..e6fce7096f 100644 --- a/x/uibc/quota/keeper/quota_test.go +++ b/x/uibc/quota/keeper/quota_test.go @@ -47,7 +47,7 @@ func TestUnitCheckAndUpdateQuota(t *testing.T) { k.SetTokenOutflow(sdk.NewInt64DecCoin(umee, 6)) k.SetTokenInflow(sdk.NewInt64DecCoin(umee, 6)) k.SetOutflowSum(sdk.NewDec(50)) - k.SetTotalInflow(sdk.NewDec(50)) + k.SetInflowSum(sdk.NewDec(50)) k.SetTokenInflow(sdk.NewDecCoin(umee, math.NewInt(50))) err := k.CheckAndUpdateQuota(umee, sdk.NewInt(1)) @@ -125,7 +125,7 @@ func TestUnitCheckAndUpdateQuota(t *testing.T) { err = k.SetParams(dp) k.SetOutflowSum(sdk.NewDec(80)) // 80+(20*2) > Total Outflow Quota Limit (100) - err = k.CheckAndUpdateQuota(umee, sdk.NewInt(20)) // exceeds token quota + err = k.CheckAndUpdateQuota(umee, sdk.NewInt(20)) assert.ErrorContains(t, err, "quota") err = k.CheckAndUpdateQuota(umee, sdk.NewInt(10)) assert.NilError(t, err) @@ -134,7 +134,7 @@ func TestUnitCheckAndUpdateQuota(t *testing.T) { err = k.SetParams(dp) assert.NilError(t, err) - k.SetTotalInflow(sdk.NewDec(100)) + k.SetInflowSum(sdk.NewDec(100)) // 80+(80*2) > InflowOutflowQuotaBase(100) + 25% of Total Inflow Sum (100) = 240 > 100+25 err = k.CheckAndUpdateQuota(umee, sdk.NewInt(80)) // exceeds token quota assert.ErrorContains(t, err, "quota") @@ -161,9 +161,9 @@ func TestUnitGetExchangePrice(t *testing.T) { func TestSetAndGetIBCInflows(t *testing.T) { k := initKeeperSimpleMock(t) inflowSum := sdk.MustNewDecFromStr("123123") - k.SetTotalInflow(inflowSum) + k.SetInflowSum(inflowSum) - rv := k.GetTotalInflow() + rv := k.GetInflowSum() assert.DeepEqual(t, inflowSum, rv) // inflow of token From 6b7d6c2391e9ca4a2975fcafbd8e716d2442f3aa Mon Sep 17 00:00:00 2001 From: Robert Zaremba Date: Mon, 20 Nov 2023 17:58:34 +0100 Subject: [PATCH 08/13] changelog --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 289e79aba4..64d4966535 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -57,7 +57,7 @@ Ref: https://keepachangelog.com/en/1.0.0/ ### Breaking Changes -- Rename: `TotalOutflowSum` to `OutflowSum`, `TotalInflowSum` to `InflowSum`. +- [2332](https://github.com/umee-network/umee/pull/2332) Rename: `TotalOutflowSum` to `OutflowSum`, `TotalInflowSum` to `InflowSum`. ## v6.1.0 - 2023-10-17 From 6e92850a3c3c53c58b8c17fb98c59980836d3289 Mon Sep 17 00:00:00 2001 From: Robert Zaremba Date: Mon, 20 Nov 2023 18:01:33 +0100 Subject: [PATCH 09/13] more rename --- x/uibc/quota/keeper/genesis.go | 2 +- x/uibc/quota/keeper/grpc_query.go | 2 +- x/uibc/quota/keeper/quota.go | 8 ++++---- x/uibc/quota/keeper/unit_test.go | 2 +- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/x/uibc/quota/keeper/genesis.go b/x/uibc/quota/keeper/genesis.go index f8814d2797..da55d7f231 100644 --- a/x/uibc/quota/keeper/genesis.go +++ b/x/uibc/quota/keeper/genesis.go @@ -35,7 +35,7 @@ func (kb Builder) ExportGenesis(ctx sdk.Context) *uibc.GenesisState { return &uibc.GenesisState{ Params: k.GetParams(), Outflows: outflows, - OutflowSum: k.GetTotalOutflow(), + OutflowSum: k.GetOutflowSum(), QuotaExpires: *quotaExpires, Inflows: inflows, InflowSum: k.GetInflowSum(), diff --git a/x/uibc/quota/keeper/grpc_query.go b/x/uibc/quota/keeper/grpc_query.go index ba0f3a216f..bcc5e891b6 100644 --- a/x/uibc/quota/keeper/grpc_query.go +++ b/x/uibc/quota/keeper/grpc_query.go @@ -37,7 +37,7 @@ func (q Querier) Outflows(goCtx context.Context, req *uibc.QueryOutflows) ( k := q.Keeper(&ctx) var o sdk.Dec if len(req.Denom) == 0 { - o = k.GetTotalOutflow() + o = k.GetOutflowSum() } else { d := k.GetTokenOutflows(req.Denom) o = d.Amount diff --git a/x/uibc/quota/keeper/quota.go b/x/uibc/quota/keeper/quota.go index 031da8275d..f2b26edea8 100644 --- a/x/uibc/quota/keeper/quota.go +++ b/x/uibc/quota/keeper/quota.go @@ -46,8 +46,8 @@ func (k Keeper) SetOutflowSum(amount sdk.Dec) { util.Panic(err) } -// GetTotalOutflow returns the total outflow of ibc-transfer amount. -func (k Keeper) GetTotalOutflow() sdk.Dec { +// GetOutflowSum returns the total outflow of ibc-transfer amount. +func (k Keeper) GetOutflowSum() sdk.Dec { // When total outflow is not stored in store it will return 0 amount, _ := store.GetDec(k.store, keyTotalOutflows, "total_outflow") return amount @@ -158,7 +158,7 @@ func (k Keeper) CheckAndUpdateQuota(denom string, newOutflow sdkmath.Int) error // Allow outflow either of two conditions // 1. Outflow Sum <= Total Outflow Quota // 2. OR Outflow Sum <= params.InflowOutflowQuotaBase + (params.InflowOutflowQuotaRate * sum of all inflows) - outflowSum := k.GetTotalOutflow().Add(exchangePrice) + outflowSum := k.GetOutflowSum().Add(exchangePrice) inflowSum := k.GetInflowSum() if !params.TotalQuota.IsZero() { if outflowSum.GT(params.TotalQuota) || @@ -223,7 +223,7 @@ func (k Keeper) UndoUpdateQuota(denom string, amount sdkmath.Int) error { } k.SetTokenOutflow(o) - totalOutflowSum := k.GetTotalOutflow() + totalOutflowSum := k.GetOutflowSum() k.SetOutflowSum(totalOutflowSum.Sub(exchangePrice)) return nil } diff --git a/x/uibc/quota/keeper/unit_test.go b/x/uibc/quota/keeper/unit_test.go index d31d6e398e..7f766bbc1c 100644 --- a/x/uibc/quota/keeper/unit_test.go +++ b/x/uibc/quota/keeper/unit_test.go @@ -48,7 +48,7 @@ func (k TestKeeper) checkOutflows(denom string, perToken, total int64) { o := k.GetTokenOutflows(denom) require.Equal(k.t, sdk.NewDec(perToken), o.Amount) - d := k.GetTotalOutflow() + d := k.GetOutflowSum() require.Equal(k.t, sdk.NewDec(total), d) } From fa1a7bdee458a4c70e3267396289e73f6780e457 Mon Sep 17 00:00:00 2001 From: Robert Zaremba Date: Mon, 20 Nov 2023 18:03:17 +0100 Subject: [PATCH 10/13] lint --- x/uibc/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/x/uibc/README.md b/x/uibc/README.md index f4c21089ec..09ef7824f0 100644 --- a/x/uibc/README.md +++ b/x/uibc/README.md @@ -40,7 +40,7 @@ Similarly to inflows, we measure outflows per token and aggregates (sum): The metrics above are reset every `params.quota_duration` in Begin Blocker. Example: if the reset was done at 14:00 UTC, then the next reset will be done `quota_duration` later. You can observe the reset with `/umee/uibc/v1/EventQuotaReset` event, which will contain `next_expire` attribute. -#### Outflow Quota. +#### Outflow Quota Inflows and outflows metrics above are used to **limit ICS-20 transfers** of tokens in the x/leverage Token Registry. The outflow transfer of token `X` is possible when: From 8c594643ed82f927c563c269831eaca5ea210cb6 Mon Sep 17 00:00:00 2001 From: Robert Zaremba Date: Mon, 20 Nov 2023 18:12:34 +0100 Subject: [PATCH 11/13] fix tests --- x/uibc/genesis_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/x/uibc/genesis_test.go b/x/uibc/genesis_test.go index c22a307c9e..319603d001 100644 --- a/x/uibc/genesis_test.go +++ b/x/uibc/genesis_test.go @@ -14,7 +14,7 @@ func TestGenesisValidation(t *testing.T) { gs.OutflowSum = sdk.NewDec(-123123) err = gs.Validate() - assert.ErrorContains(t, err, "total outflow sum cannot be negative") + assert.ErrorContains(t, err, "outflow sum cannot be negative") gs.Outflows = []sdk.DecCoin{{Denom: "umee", Amount: sdk.NewDec(-11123123)}} err = gs.Validate() From cd8e69f59fb0622f24278c210f938c07b41e4faf Mon Sep 17 00:00:00 2001 From: Robert Zaremba Date: Mon, 20 Nov 2023 18:14:45 +0100 Subject: [PATCH 12/13] rename --- x/uibc/quota/keeper/quota.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/x/uibc/quota/keeper/quota.go b/x/uibc/quota/keeper/quota.go index f2b26edea8..8c9252e1c9 100644 --- a/x/uibc/quota/keeper/quota.go +++ b/x/uibc/quota/keeper/quota.go @@ -223,8 +223,8 @@ func (k Keeper) UndoUpdateQuota(denom string, amount sdkmath.Int) error { } k.SetTokenOutflow(o) - totalOutflowSum := k.GetOutflowSum() - k.SetOutflowSum(totalOutflowSum.Sub(exchangePrice)) + outflowSum := k.GetOutflowSum() + k.SetOutflowSum(outflowSum.Sub(exchangePrice)) return nil } From 2e321913290c1ebc05ddaf867f29077d814c30fd Mon Sep 17 00:00:00 2001 From: Robert Zaremba Date: Mon, 20 Nov 2023 18:17:10 +0100 Subject: [PATCH 13/13] rename --- x/uibc/quota/keeper/keys.go | 6 +++--- x/uibc/quota/keeper/migrations.go | 2 +- x/uibc/quota/keeper/quota.go | 12 ++++++------ 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/x/uibc/quota/keeper/keys.go b/x/uibc/quota/keeper/keys.go index 5867c8cb9d..b27cfc795a 100644 --- a/x/uibc/quota/keeper/keys.go +++ b/x/uibc/quota/keeper/keys.go @@ -6,14 +6,14 @@ import ( var ( keyPrefixDenomOutflows = []byte{0x01} - keyTotalOutflows = []byte{0x02} + keyOutflowSum = []byte{0x02} keyParams = []byte{0x03} keyQuotaExpires = []byte{0x04} keyPrefixDenomInflows = []byte{0x05} - keyTotalInflows = []byte{0x06} + keyInflowSum = []byte{0x06} ) -func keyTotalOutflow(ibcDenom string) []byte { +func keyTokenOutflow(ibcDenom string) []byte { // keyPrefixDenomOutflows | denom return util.ConcatBytes(0, keyPrefixDenomOutflows, []byte(ibcDenom)) } diff --git a/x/uibc/quota/keeper/migrations.go b/x/uibc/quota/keeper/migrations.go index 68435abcef..81450fa80e 100644 --- a/x/uibc/quota/keeper/migrations.go +++ b/x/uibc/quota/keeper/migrations.go @@ -5,7 +5,7 @@ import sdk "github.com/cosmos/cosmos-sdk/types" // getOldTotalOutflow returns the total outflow of ibc-transfer amount. // Note: only use for v6.2 migration from v6.1.0 func (k Keeper) getOldTotalOutflow() sdk.Dec { - bz := k.store.Get(keyTotalOutflows) + bz := k.store.Get(keyOutflowSum) return sdk.MustNewDecFromStr(string(bz)) } diff --git a/x/uibc/quota/keeper/quota.go b/x/uibc/quota/keeper/quota.go index 8c9252e1c9..09980d985d 100644 --- a/x/uibc/quota/keeper/quota.go +++ b/x/uibc/quota/keeper/quota.go @@ -28,7 +28,7 @@ func (k Keeper) GetAllOutflows() (sdk.DecCoins, error) { // GetTokenOutflows returns sum of denom outflows in USD value in the DecCoin structure. func (k Keeper) GetTokenOutflows(denom string) sdk.DecCoin { // When token outflow is not stored in store it will return 0 - amount, _ := store.GetDec(k.store, keyTotalOutflow(denom), "total_outflow") + amount, _ := store.GetDec(k.store, keyTokenOutflow(denom), "total_outflow") return sdk.NewDecCoinFromDec(denom, amount) } @@ -42,20 +42,20 @@ func (k Keeper) SetTokenOutflows(outflows sdk.DecCoins) { // SetOutflowSum save the total outflow of ibc-transfer amount. func (k Keeper) SetOutflowSum(amount sdk.Dec) { - err := store.SetDec(k.store, keyTotalOutflows, amount, "total_outflow_sum") + err := store.SetDec(k.store, keyOutflowSum, amount, "total_outflow_sum") util.Panic(err) } // GetOutflowSum returns the total outflow of ibc-transfer amount. func (k Keeper) GetOutflowSum() sdk.Dec { // When total outflow is not stored in store it will return 0 - amount, _ := store.GetDec(k.store, keyTotalOutflows, "total_outflow") + amount, _ := store.GetDec(k.store, keyOutflowSum, "total_outflow") return amount } // SetTokenOutflow save the outflows of denom into store. func (k Keeper) SetTokenOutflow(outflow sdk.DecCoin) { - key := keyTotalOutflow(outflow.Denom) + key := keyTokenOutflow(outflow.Denom) err := store.SetDec(k.store, key, outflow.Amount, "total_outflow") util.Panic(err) } @@ -92,13 +92,13 @@ func (k Keeper) GetTokenInflow(denom string) sdk.DecCoin { // GetInflowSum returns the total inflow of ibc-transfer amount. func (k Keeper) GetInflowSum() sdk.Dec { // When total inflow is not stored in store it will return 0 - amount, _ := store.GetDec(k.store, keyTotalInflows, "total_inflows") + amount, _ := store.GetDec(k.store, keyInflowSum, "total_inflows") return amount } // SetInflowSum save the total inflow of ibc-transfer amount. func (k Keeper) SetInflowSum(amount sdk.Dec) { - err := store.SetDec(k.store, keyTotalInflows, amount, "total_inflows") + err := store.SetDec(k.store, keyInflowSum, amount, "total_inflows") util.Panic(err) }