diff --git a/CHANGELOG.md b/CHANGELOG.md index 9667f7d7ab..e1b49b5366 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -74,6 +74,8 @@ Ref: https://keepachangelog.com/en/1.0.0/ - `/umee/ugov/v1/min-gas-price` --> `/umee/ugov/v1/min_gas_price` - `/umee/ugov/v1/emergency-group` --> `/umee/ugov/v1/emergency_group` - `/umee/uibc/v1/all-outflows` --> `/umee/uibc/v1/all_outflows` +- [2180](https://github.com/umee-network/umee/pull/2180) Rename leverage `Keeper.ExchangeToken -> ToUToken`, `Keeper.ExchangeUToken -> ToToken` and `Keeper.ExchangeUTokens -> ToTokens`. +- [2183](https://github.com/umee-network/umee/pull/2183) Move `ToUTokenDenom`, `StripUTokenDenom` and `HasUTokenPrefix` from `leverage/keeper` to `coin` package. ## [v5.1.0](https://github.com/umee-network/umee/releases/tag/v5.1.0) - 2023-07-07 diff --git a/app/app.go b/app/app.go index a17d21c567..31cb7f7c5b 100644 --- a/app/app.go +++ b/app/app.go @@ -644,7 +644,8 @@ func New( availableCapabilities := "iterator,staking,stargate,cosmwasm_1_1,cosmwasm_1_2,umee" // Register umee custom plugin to wasm - wasmOpts = append(uwasm.RegisterCustomPlugins(app.LeverageKeeper, app.OracleKeeper, app.IncentiveKeeper), wasmOpts...) + wasmOpts = append(uwasm.RegisterCustomPlugins(app.LeverageKeeper, app.OracleKeeper, app.IncentiveKeeper, + app.MetokenKeeperB), wasmOpts...) // Register stargate queries wasmOpts = append(wasmOpts, uwasm.RegisterStargateQueries(*bApp.GRPCQueryRouter(), appCodec)...) @@ -674,7 +675,7 @@ func New( skipGenesisInvariants := cast.ToBool(appOpts.Get(crisis.FlagSkipGenesisInvariants)) inflationClaculator := inflation.Calculator{ - UgovKeeperB: app.UGovKeeperB, + UgovKeeperB: app.UGovKeeperB.Params, MintKeeper: &app.MintKeeper, } diff --git a/app/inflation/expected_keepers.go b/app/inflation/expected_keepers.go index 755da2ba5c..1ef525092e 100644 --- a/app/inflation/expected_keepers.go +++ b/app/inflation/expected_keepers.go @@ -4,19 +4,9 @@ import ( "cosmossdk.io/math" sdk "github.com/cosmos/cosmos-sdk/types" minttypes "github.com/cosmos/cosmos-sdk/x/mint/types" - - ugovkeeper "github.com/umee-network/umee/v5/x/ugov/keeper" ) type MintKeeper interface { StakingTokenSupply(ctx sdk.Context) math.Int SetParams(ctx sdk.Context, params minttypes.Params) } - -type UGovKeeper interface { - ugovkeeper.IKeeper -} - -type UGovBKeeperI interface { - ugovkeeper.BKeeperI -} diff --git a/app/inflation/inflation.go b/app/inflation/inflation.go index 431358d5e5..ecdfef7823 100644 --- a/app/inflation/inflation.go +++ b/app/inflation/inflation.go @@ -7,17 +7,18 @@ import ( "github.com/umee-network/umee/v5/util" "github.com/umee-network/umee/v5/util/bpmath" + "github.com/umee-network/umee/v5/x/ugov" ) type Calculator struct { - UgovKeeperB UGovBKeeperI + UgovKeeperB ugov.ParamsKeeperBuilder MintKeeper MintKeeper } func (c Calculator) InflationRate(ctx sdk.Context, minter minttypes.Minter, mintParams minttypes.Params, bondedRatio sdk.Dec) sdk.Dec { - ugovKeeper := c.UgovKeeperB.Keeper(&ctx) + ugovKeeper := c.UgovKeeperB(&ctx) inflationParams := ugovKeeper.InflationParams() maxSupplyAmount := inflationParams.MaxSupply.Amount @@ -27,7 +28,7 @@ func (c Calculator) InflationRate(ctx sdk.Context, minter minttypes.Minter, mint return sdk.ZeroDec() } - cycleEnd := ugovKeeper.GetInflationCycleEnd() + cycleEnd := ugovKeeper.InflationCycleEnd() if ctx.BlockTime().After(cycleEnd) { // new inflation cycle is starting, so we need to update the inflation max and min rate factor := bpmath.One - inflationParams.InflationReductionRate diff --git a/app/inflation/inflation_test.go b/app/inflation/inflation_test.go index 6122be1324..5008775b2f 100644 --- a/app/inflation/inflation_test.go +++ b/app/inflation/inflation_test.go @@ -9,6 +9,8 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" minttypes "github.com/cosmos/cosmos-sdk/x/mint/types" "github.com/golang/mock/gomock" + "gotest.tools/v3/assert" + "github.com/umee-network/umee/v5/app/inflation" mocks "github.com/umee-network/umee/v5/app/inflation/mocks" appparams "github.com/umee-network/umee/v5/app/params" @@ -16,7 +18,7 @@ import ( "github.com/umee-network/umee/v5/util/bpmath" "github.com/umee-network/umee/v5/util/coin" "github.com/umee-network/umee/v5/x/ugov" - "gotest.tools/v3/assert" + ugovmocks "github.com/umee-network/umee/v5/x/ugov/mocks" ) func TestAdjustInflation(t *testing.T) { @@ -203,31 +205,25 @@ func TestInflationRate(t *testing.T) { } for _, test := range tests { t.Run(test.name, func(t *testing.T) { - ctrl := gomock.NewController(t) - // Create the mock MintKeeper and UgovKeeper mockMintKeeper := mocks.NewMockMintKeeper(ctrl) - mockUGovBuilder := mocks.NewMockUGovBKeeperI(ctrl) - mockUGovKeeper := mocks.NewMockUGovKeeper(ctrl) - - calc := inflation.Calculator{ - MintKeeper: mockMintKeeper, - UgovKeeperB: mockUGovBuilder, - } + mockUGovKeeper := ugovmocks.NewMockParamsKeeper(ctrl) - // mockUGovBuilder returns the mockUGovKeeper - mockUGovBuilder.EXPECT().Keeper(gomock.Any()).Return(mockUGovKeeper) - - // Set up the mock behavior for MintKeeper and UgovKeeper - mockUGovKeeper.EXPECT().InflationParams().Return(test.inflationParams(mockInflationParams)) mockMintKeeper.EXPECT().StakingTokenSupply(gomock.Any()).Return(test.totalSupply) mockMintKeeper.EXPECT().SetParams(gomock.Any(), gomock.Any()).AnyTimes() - mockUGovKeeper.EXPECT().GetInflationCycleEnd().Return(test.cycleEndTime()).AnyTimes() + + mockUGovKeeper.EXPECT().InflationParams().Return(test.inflationParams(mockInflationParams)) + mockUGovKeeper.EXPECT().InflationCycleEnd().Return(test.cycleEndTime()).AnyTimes() mockUGovKeeper.EXPECT().SetInflationCycleEnd(gomock.Any()).Return(nil).AnyTimes() + calc := inflation.Calculator{ + MintKeeper: mockMintKeeper, + UgovKeeperB: ugovmocks.NewUgovParamsBuilder(mockUGovKeeper), + } result := calc.InflationRate(test.ctx(), test.minter, test.mintParams(mintParams), test.bondedRatio) - assert.DeepEqual(t, test.expectedResult(test.minter.Inflation, test.bondedRatio, test.mintParams(mintParams)), result) + assert.DeepEqual(t, + test.expectedResult(test.minter.Inflation, test.bondedRatio, test.mintParams(mintParams)), result) ctrl.Finish() }) } diff --git a/app/inflation/mocks/keepers.go b/app/inflation/mocks/keepers.go index 4ac3d65b18..60041b1305 100644 --- a/app/inflation/mocks/keepers.go +++ b/app/inflation/mocks/keepers.go @@ -6,14 +6,11 @@ package mocks import ( reflect "reflect" - time "time" math "cosmossdk.io/math" types "github.com/cosmos/cosmos-sdk/types" types0 "github.com/cosmos/cosmos-sdk/x/mint/types" gomock "github.com/golang/mock/gomock" - ugov "github.com/umee-network/umee/v5/x/ugov" - keeper "github.com/umee-network/umee/v5/x/ugov/keeper" ) // MockMintKeeper is a mock of MintKeeper interface. @@ -64,201 +61,3 @@ func (mr *MockMintKeeperMockRecorder) StakingTokenSupply(ctx interface{}) *gomoc mr.mock.ctrl.T.Helper() return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "StakingTokenSupply", reflect.TypeOf((*MockMintKeeper)(nil).StakingTokenSupply), ctx) } - -// MockUGovKeeper is a mock of UGovKeeper interface. -type MockUGovKeeper struct { - ctrl *gomock.Controller - recorder *MockUGovKeeperMockRecorder -} - -// MockUGovKeeperMockRecorder is the mock recorder for MockUGovKeeper. -type MockUGovKeeperMockRecorder struct { - mock *MockUGovKeeper -} - -// NewMockUGovKeeper creates a new mock instance. -func NewMockUGovKeeper(ctrl *gomock.Controller) *MockUGovKeeper { - mock := &MockUGovKeeper{ctrl: ctrl} - mock.recorder = &MockUGovKeeperMockRecorder{mock} - return mock -} - -// EXPECT returns an object that allows the caller to indicate expected use. -func (m *MockUGovKeeper) EXPECT() *MockUGovKeeperMockRecorder { - return m.recorder -} - -// EmergencyGroup mocks base method. -func (m *MockUGovKeeper) EmergencyGroup() types.AccAddress { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "EmergencyGroup") - ret0, _ := ret[0].(types.AccAddress) - return ret0 -} - -// EmergencyGroup indicates an expected call of EmergencyGroup. -func (mr *MockUGovKeeperMockRecorder) EmergencyGroup() *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "EmergencyGroup", reflect.TypeOf((*MockUGovKeeper)(nil).EmergencyGroup)) -} - -// ExportGenesis mocks base method. -func (m *MockUGovKeeper) ExportGenesis() *ugov.GenesisState { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "ExportGenesis") - ret0, _ := ret[0].(*ugov.GenesisState) - return ret0 -} - -// ExportGenesis indicates an expected call of ExportGenesis. -func (mr *MockUGovKeeperMockRecorder) ExportGenesis() *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ExportGenesis", reflect.TypeOf((*MockUGovKeeper)(nil).ExportGenesis)) -} - -// GetInflationCycleEnd mocks base method. -func (m *MockUGovKeeper) GetInflationCycleEnd() time.Time { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "GetInflationCycleEnd") - ret0, _ := ret[0].(time.Time) - return ret0 -} - -// GetInflationCycleEnd indicates an expected call of GetInflationCycleEnd. -func (mr *MockUGovKeeperMockRecorder) GetInflationCycleEnd() *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetInflationCycleEnd", reflect.TypeOf((*MockUGovKeeper)(nil).GetInflationCycleEnd)) -} - -// InflationParams mocks base method. -func (m *MockUGovKeeper) InflationParams() ugov.InflationParams { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "InflationParams") - ret0, _ := ret[0].(ugov.InflationParams) - return ret0 -} - -// InflationParams indicates an expected call of InflationParams. -func (mr *MockUGovKeeperMockRecorder) InflationParams() *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "InflationParams", reflect.TypeOf((*MockUGovKeeper)(nil).InflationParams)) -} - -// InitGenesis mocks base method. -func (m *MockUGovKeeper) InitGenesis(gs *ugov.GenesisState) error { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "InitGenesis", gs) - ret0, _ := ret[0].(error) - return ret0 -} - -// InitGenesis indicates an expected call of InitGenesis. -func (mr *MockUGovKeeperMockRecorder) InitGenesis(gs interface{}) *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "InitGenesis", reflect.TypeOf((*MockUGovKeeper)(nil).InitGenesis), gs) -} - -// MinGasPrice mocks base method. -func (m *MockUGovKeeper) MinGasPrice() types.DecCoin { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "MinGasPrice") - ret0, _ := ret[0].(types.DecCoin) - return ret0 -} - -// MinGasPrice indicates an expected call of MinGasPrice. -func (mr *MockUGovKeeperMockRecorder) MinGasPrice() *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "MinGasPrice", reflect.TypeOf((*MockUGovKeeper)(nil).MinGasPrice)) -} - -// SetEmergencyGroup mocks base method. -func (m *MockUGovKeeper) SetEmergencyGroup(p types.AccAddress) { - m.ctrl.T.Helper() - m.ctrl.Call(m, "SetEmergencyGroup", p) -} - -// SetEmergencyGroup indicates an expected call of SetEmergencyGroup. -func (mr *MockUGovKeeperMockRecorder) SetEmergencyGroup(p interface{}) *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "SetEmergencyGroup", reflect.TypeOf((*MockUGovKeeper)(nil).SetEmergencyGroup), p) -} - -// SetInflationCycleEnd mocks base method. -func (m *MockUGovKeeper) SetInflationCycleEnd(startTime time.Time) error { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "SetInflationCycleEnd", startTime) - ret0, _ := ret[0].(error) - return ret0 -} - -// SetInflationCycleEnd indicates an expected call of SetInflationCycleEnd. -func (mr *MockUGovKeeperMockRecorder) SetInflationCycleEnd(startTime interface{}) *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "SetInflationCycleEnd", reflect.TypeOf((*MockUGovKeeper)(nil).SetInflationCycleEnd), startTime) -} - -// SetInflationParams mocks base method. -func (m *MockUGovKeeper) SetInflationParams(lp ugov.InflationParams) error { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "SetInflationParams", lp) - ret0, _ := ret[0].(error) - return ret0 -} - -// SetInflationParams indicates an expected call of SetInflationParams. -func (mr *MockUGovKeeperMockRecorder) SetInflationParams(lp interface{}) *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "SetInflationParams", reflect.TypeOf((*MockUGovKeeper)(nil).SetInflationParams), lp) -} - -// SetMinGasPrice mocks base method. -func (m *MockUGovKeeper) SetMinGasPrice(p types.DecCoin) error { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "SetMinGasPrice", p) - ret0, _ := ret[0].(error) - return ret0 -} - -// SetMinGasPrice indicates an expected call of SetMinGasPrice. -func (mr *MockUGovKeeperMockRecorder) SetMinGasPrice(p interface{}) *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "SetMinGasPrice", reflect.TypeOf((*MockUGovKeeper)(nil).SetMinGasPrice), p) -} - -// MockUGovBKeeperI is a mock of UGovBKeeperI interface. -type MockUGovBKeeperI struct { - ctrl *gomock.Controller - recorder *MockUGovBKeeperIMockRecorder -} - -// MockUGovBKeeperIMockRecorder is the mock recorder for MockUGovBKeeperI. -type MockUGovBKeeperIMockRecorder struct { - mock *MockUGovBKeeperI -} - -// NewMockUGovBKeeperI creates a new mock instance. -func NewMockUGovBKeeperI(ctrl *gomock.Controller) *MockUGovBKeeperI { - mock := &MockUGovBKeeperI{ctrl: ctrl} - mock.recorder = &MockUGovBKeeperIMockRecorder{mock} - return mock -} - -// EXPECT returns an object that allows the caller to indicate expected use. -func (m *MockUGovBKeeperI) EXPECT() *MockUGovBKeeperIMockRecorder { - return m.recorder -} - -// Keeper mocks base method. -func (m *MockUGovBKeeperI) Keeper(ctx *types.Context) keeper.IKeeper { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "Keeper", ctx) - ret0, _ := ret[0].(keeper.IKeeper) - return ret0 -} - -// Keeper indicates an expected call of Keeper. -func (mr *MockUGovBKeeperIMockRecorder) Keeper(ctx interface{}) *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Keeper", reflect.TypeOf((*MockUGovBKeeperI)(nil).Keeper), ctx) -} diff --git a/app/wasm/custom_plugins.go b/app/wasm/custom_plugins.go index 7a3a493c0f..19f33c095f 100644 --- a/app/wasm/custom_plugins.go +++ b/app/wasm/custom_plugins.go @@ -10,6 +10,7 @@ import ( "github.com/umee-network/umee/v5/app/wasm/query" inckeeper "github.com/umee-network/umee/v5/x/incentive/keeper" leveragekeeper "github.com/umee-network/umee/v5/x/leverage/keeper" + metokenkeeper "github.com/umee-network/umee/v5/x/metoken/keeper" oraclekeeper "github.com/umee-network/umee/v5/x/oracle/keeper" ) @@ -18,8 +19,9 @@ func RegisterCustomPlugins( leverageKeeper leveragekeeper.Keeper, oracleKeeper oraclekeeper.Keeper, incentiveKeeper inckeeper.Keeper, + metokenBuilder metokenkeeper.Builder, ) []wasmkeeper.Option { - wasmQueryPlugin := query.NewQueryPlugin(leverageKeeper, oracleKeeper, incentiveKeeper) + wasmQueryPlugin := query.NewQueryPlugin(leverageKeeper, oracleKeeper, incentiveKeeper, metokenBuilder) queryPluginOpt := wasmkeeper.WithQueryPlugins(&wasmkeeper.QueryPlugins{ Custom: wasmQueryPlugin.CustomQuerier(), }) diff --git a/app/wasm/query/handle_metoken.go b/app/wasm/query/handle_metoken.go new file mode 100644 index 0000000000..ac34d54c7c --- /dev/null +++ b/app/wasm/query/handle_metoken.go @@ -0,0 +1,61 @@ +package query + +import ( + "context" + + "github.com/gogo/protobuf/proto" + "github.com/umee-network/umee/v5/x/metoken" +) + +// HandleMeTokenParams handles the get for x/metoken module's parameters. +func (q UmeeQuery) HandleMeTokenParams( + ctx context.Context, + qs metoken.QueryServer, +) (proto.Message, error) { + return qs.Params(ctx, &metoken.QueryParams{}) +} + +// HandleMeTokenIndexes handles the get for x/metoken indexes. +func (q UmeeQuery) HandleMeTokenIndexes( + ctx context.Context, + qs metoken.QueryServer, +) (proto.Message, error) { + req := metoken.QueryIndexes{MetokenDenom: q.Indexes.MetokenDenom} + return qs.Indexes(ctx, &req) +} + +// HandleMeTokenSwapFee handles the get for x/metoken swap fee. +func (q UmeeQuery) HandleMeTokenSwapFee( + ctx context.Context, + qs metoken.QueryServer, +) (proto.Message, error) { + req := metoken.QuerySwapFee{Asset: q.SwapFee.Asset, MetokenDenom: q.SwapFee.MetokenDenom} + return qs.SwapFee(ctx, &req) +} + +// HandleMeTokenRedeemFee handles the get for x/metoken redeem fee. +func (q UmeeQuery) HandleMeTokenRedeemFee( + ctx context.Context, + qs metoken.QueryServer, +) (proto.Message, error) { + req := metoken.QueryRedeemFee{AssetDenom: q.RedeemFee.AssetDenom, Metoken: q.RedeemFee.Metoken} + return qs.RedeemFee(ctx, &req) +} + +// HandleMeTokenIndexBalances handles the get for x/metoken indexes balances. +func (q UmeeQuery) HandleMeTokenIndexBalances( + ctx context.Context, + qs metoken.QueryServer, +) (proto.Message, error) { + req := metoken.QueryIndexBalances{MetokenDenom: q.IndexBalances.MetokenDenom} + return qs.IndexBalances(ctx, &req) +} + +// HandleMeTokenIndexPrice handles the get for x/metoken indexe price. +func (q UmeeQuery) HandleMeTokenIndexPrice( + ctx context.Context, + qs metoken.QueryServer, +) (proto.Message, error) { + req := metoken.QueryIndexPrice{MetokenDenom: q.IndexPrice.MetokenDenom} + return qs.IndexPrice(ctx, &req) +} diff --git a/app/wasm/query/plugin.go b/app/wasm/query/plugin.go index b58e848c41..eea23f115b 100644 --- a/app/wasm/query/plugin.go +++ b/app/wasm/query/plugin.go @@ -13,15 +13,18 @@ import ( inckeeper "github.com/umee-network/umee/v5/x/incentive/keeper" lvkeeper "github.com/umee-network/umee/v5/x/leverage/keeper" lvtypes "github.com/umee-network/umee/v5/x/leverage/types" + "github.com/umee-network/umee/v5/x/metoken" + metokenkeeper "github.com/umee-network/umee/v5/x/metoken/keeper" ockeeper "github.com/umee-network/umee/v5/x/oracle/keeper" ocpes "github.com/umee-network/umee/v5/x/oracle/types" ) // Plugin wraps the query plugin with queriers. type Plugin struct { - lvQueryServer lvtypes.QueryServer - ocQueryServer ocpes.QueryServer - incQueryServer incentive.QueryServer + lvQueryServer lvtypes.QueryServer + ocQueryServer ocpes.QueryServer + incQueryServer incentive.QueryServer + metokenQueryServer metoken.QueryServer } // NewQueryPlugin creates a plugin to query native modules. @@ -29,11 +32,13 @@ func NewQueryPlugin( leverageKeeper lvkeeper.Keeper, oracleKeeper ockeeper.Keeper, incentiveKeeper inckeeper.Keeper, + metokenBuilder metokenkeeper.Builder, ) *Plugin { return &Plugin{ - lvQueryServer: lvkeeper.NewQuerier(leverageKeeper), - ocQueryServer: ockeeper.NewQuerier(oracleKeeper), - incQueryServer: inckeeper.NewQuerier(incentiveKeeper), + lvQueryServer: lvkeeper.NewQuerier(leverageKeeper), + ocQueryServer: ockeeper.NewQuerier(oracleKeeper), + incQueryServer: inckeeper.NewQuerier(incentiveKeeper), + metokenQueryServer: metokenkeeper.NewQuerier(metokenBuilder), } } @@ -119,6 +124,20 @@ func (plugin *Plugin) CustomQuerier() func(ctx sdk.Context, request json.RawMess case smartcontractQuery.LastRewardTime != nil: resp, err = smartcontractQuery.HandleLastRewardTime(ctx, plugin.incQueryServer) + // metoken + case smartcontractQuery.MeTokenParameters != nil: + resp, err = smartcontractQuery.HandleMeTokenParams(ctx, plugin.metokenQueryServer) + case smartcontractQuery.Indexes != nil: + resp, err = smartcontractQuery.HandleMeTokenIndexes(ctx, plugin.metokenQueryServer) + case smartcontractQuery.SwapFee != nil: + resp, err = smartcontractQuery.HandleMeTokenSwapFee(ctx, plugin.metokenQueryServer) + case smartcontractQuery.RedeemFee != nil: + resp, err = smartcontractQuery.HandleMeTokenRedeemFee(ctx, plugin.metokenQueryServer) + case smartcontractQuery.IndexBalances != nil: + resp, err = smartcontractQuery.HandleMeTokenIndexBalances(ctx, plugin.metokenQueryServer) + case smartcontractQuery.IndexPrice != nil: + resp, err = smartcontractQuery.HandleMeTokenIndexPrice(ctx, plugin.metokenQueryServer) + default: return nil, wasmvmtypes.UnsupportedRequest{Kind: "invalid umee query"} } diff --git a/app/wasm/query/types.go b/app/wasm/query/types.go index cce53fd6fb..3daa4cff50 100644 --- a/app/wasm/query/types.go +++ b/app/wasm/query/types.go @@ -7,6 +7,7 @@ import ( wasmvmtypes "github.com/CosmWasm/wasmvm/types" "github.com/umee-network/umee/v5/x/incentive" lvtypes "github.com/umee-network/umee/v5/x/leverage/types" + "github.com/umee-network/umee/v5/x/metoken" octypes "github.com/umee-network/umee/v5/x/oracle/types" ) @@ -90,6 +91,14 @@ type UmeeQuery struct { ActualRates *incentive.QueryActualRates `json:"actual_rates,omitempty"` // LastRewardTime queries the last block time at which incentive rewards were calculated. LastRewardTime *incentive.QueryLastRewardTime `json:"last_reward_time,omitempty"` + + // metoken queries + MeTokenParameters *metoken.QueryParams `json:"metoken_parameters,omitempty"` + Indexes *metoken.QueryIndexes `json:"metoken_indexes,omitempty"` + SwapFee *metoken.QuerySwapFee `json:"metoken_swapfee,omitempty"` + RedeemFee *metoken.QueryRedeemFee `json:"metoken_redeemfee,omitempty"` + IndexBalances *metoken.QueryIndexBalances `json:"metoken_indexbalances,omitempty"` + IndexPrice *metoken.QueryIndexPrice `json:"metoken_indexprice,omitempty"` } // MarshalResponse marshals any response. diff --git a/app/wasm/query/whitelist.go b/app/wasm/query/whitelist.go index 524f6130b9..9cd68af802 100644 --- a/app/wasm/query/whitelist.go +++ b/app/wasm/query/whitelist.go @@ -16,6 +16,7 @@ import ( "github.com/umee-network/umee/v5/x/incentive" ltypes "github.com/umee-network/umee/v5/x/leverage/types" + "github.com/umee-network/umee/v5/x/metoken" otypes "github.com/umee-network/umee/v5/x/oracle/types" ugovtypes "github.com/umee-network/umee/v5/x/ugov" uibctypes "github.com/umee-network/umee/v5/x/uibc" @@ -43,6 +44,7 @@ const ( oracleBaseQueryPath = "/umee.oracle.v1.Query/" uibcBaseQueryPath = "/umee.uibc.v1.Query/" incentiveBaseQueryPath = "/umee.incentive.v1.Query/" + metokenBaseQueryPath = "/umee.metoken.v1.Query/" // #nosec G101 ) func init() { @@ -134,6 +136,14 @@ func init() { setWhitelistedQuery(incentiveBaseQueryPath+"CurrentRates", &incentive.QueryCurrentRatesResponse{}) setWhitelistedQuery(incentiveBaseQueryPath+"ActualRates", &incentive.QueryActualRates{}) setWhitelistedQuery(incentiveBaseQueryPath+"LastRewardTime", &incentive.QueryLastRewardTimeResponse{}) + + // metoken + setWhitelistedQuery(metokenBaseQueryPath+"Params", &metoken.QueryParamsResponse{}) + setWhitelistedQuery(metokenBaseQueryPath+"Indexes", &metoken.QueryIndexesResponse{}) + setWhitelistedQuery(metokenBaseQueryPath+"SwapFee", &metoken.QuerySwapFeeResponse{}) + setWhitelistedQuery(metokenBaseQueryPath+"RedeemFee", &metoken.QueryRedeemFeeResponse{}) + setWhitelistedQuery(metokenBaseQueryPath+"IndexBalances", &metoken.QueryIndexBalancesResponse{}) + setWhitelistedQuery(metokenBaseQueryPath+"IndexPrice", &metoken.QueryIndexPriceResponse{}) } // GetWhitelistedQuery returns the whitelisted query at the provided path. diff --git a/app/wasm/test/cosmwasm_test.go b/app/wasm/test/cosmwasm_test.go index 7ea7806573..acc70ac9a6 100644 --- a/app/wasm/test/cosmwasm_test.go +++ b/app/wasm/test/cosmwasm_test.go @@ -20,4 +20,8 @@ func TestCosmwasm(t *testing.T) { its.TestOracleQueries() its.TestLeverageTxs() its.TestIncentiveQueries() + its.TestMetokenQueries() + + // stargate queries + its.TestStargateQueries() } diff --git a/app/wasm/test/umee_cw_test.go b/app/wasm/test/umee_cw_test.go index fa9389d9c6..14a5421ab8 100644 --- a/app/wasm/test/umee_cw_test.go +++ b/app/wasm/test/umee_cw_test.go @@ -15,6 +15,7 @@ import ( wq "github.com/umee-network/umee/v5/app/wasm/query" "github.com/umee-network/umee/v5/x/incentive" lvtypes "github.com/umee-network/umee/v5/x/leverage/types" + "github.com/umee-network/umee/v5/x/metoken" "github.com/umee-network/umee/v5/x/oracle/types" ) @@ -133,30 +134,6 @@ func (s *IntegrationTestSuite) TestLeverageQueries() { } } -func (s *IntegrationTestSuite) TestStargateQueries() { - data := lvtypes.QueryMarketSummary{ - Denom: appparams.BondDenom, - } - d, err := data.Marshal() - assert.NilError(s.T, err) - sq := StargateQuery{} - sq.Chain.Stargate = wasmvmtypes.StargateQuery{ - Path: "/umee.leverage.v1.Query/MarketSummary", - Data: d, - } - - cq, err := json.Marshal(sq) - assert.NilError(s.T, err) - resp, err := s.wasmQueryClient.SmartContractState(sdk.WrapSDKContext(s.ctx), &wasmtypes.QuerySmartContractStateRequest{ - Address: s.contractAddr, QueryData: cq, - }) - assert.NilError(s.T, err) - var rr lvtypes.QueryMarketSummaryResponse - err = s.encfg.Codec.UnmarshalJSON(resp.Data, &rr) - assert.NilError(s.T, err) - assert.Equal(s.T, "UMEE", rr.SymbolDenom) -} - func (s *IntegrationTestSuite) TestOracleQueries() { tests := []struct { Name string @@ -196,6 +173,88 @@ func (s *IntegrationTestSuite) TestOracleQueries() { } } +func (s *IntegrationTestSuite) TestStargateQueries() { + tests := []struct { + name string + sq func() StargateQuery + resp func(resp wasmtypes.QuerySmartContractStateResponse) + }{ + { + name: "stargate: leverage params ", + sq: func() StargateQuery { + data := lvtypes.QueryParams{} + d, err := data.Marshal() + assert.NilError(s.T, err) + sq := StargateQuery{} + sq.Chain.Stargate = wasmvmtypes.StargateQuery{ + Path: "/umee.leverage.v1.Query/Params", + Data: d, + } + return sq + }, + resp: func(resp wasmtypes.QuerySmartContractStateResponse) { + var rr lvtypes.QueryParamsResponse + err := s.encfg.Codec.UnmarshalJSON(resp.Data, &rr) + assert.NilError(s.T, err) + assert.DeepEqual(s.T, lvtypes.DefaultParams(), rr.Params) + }, + }, + { + name: "stargate: metoken queries ", + sq: func() StargateQuery { + data := metoken.QueryParams{} + d, err := data.Marshal() + assert.NilError(s.T, err) + sq := StargateQuery{} + sq.Chain.Stargate = wasmvmtypes.StargateQuery{ + Path: "/umee.metoken.v1.Query/Params", + Data: d, + } + return sq + }, + resp: func(resp wasmtypes.QuerySmartContractStateResponse) { + var rr metoken.QueryParamsResponse + err := s.encfg.Codec.UnmarshalJSON(resp.Data, &rr) + assert.NilError(s.T, err) + assert.DeepEqual(s.T, metoken.DefaultParams(), rr.Params) + }, + }, { + name: "stargate: leverage market summary", + sq: func() StargateQuery { + data := lvtypes.QueryMarketSummary{ + Denom: appparams.BondDenom, + } + d, err := data.Marshal() + assert.NilError(s.T, err) + sq := StargateQuery{} + sq.Chain.Stargate = wasmvmtypes.StargateQuery{ + Path: "/umee.leverage.v1.Query/MarketSummary", + Data: d, + } + return sq + }, + resp: func(resp wasmtypes.QuerySmartContractStateResponse) { + var rr lvtypes.QueryMarketSummaryResponse + err := s.encfg.Codec.UnmarshalJSON(resp.Data, &rr) + assert.NilError(s.T, err) + assert.Equal(s.T, "UMEE", rr.SymbolDenom) + }, + }, + } + + for _, test := range tests { + s.T.Run(test.name, func(t *testing.T) { + cq, err := json.Marshal(test.sq()) + assert.NilError(s.T, err) + resp, err := s.wasmQueryClient.SmartContractState(sdk.WrapSDKContext(s.ctx), &wasmtypes.QuerySmartContractStateRequest{ + Address: s.contractAddr, QueryData: cq, + }) + assert.NilError(s.T, err) + test.resp(*resp) + }) + } +} + func (s *IntegrationTestSuite) TestLeverageTxs() { accAddr := sdk.MustAccAddressFromBech32(s.contractAddr) err := s.app.BankKeeper.SendCoinsFromModuleToAccount(s.ctx, minttypes.ModuleName, accAddr, sdk.NewCoins(sdk.NewCoin(appparams.BondDenom, sdk.NewInt(100000)))) @@ -278,3 +337,31 @@ func (s *IntegrationTestSuite) TestIncentiveQueries() { }) } } + +func (s *IntegrationTestSuite) TestMetokenQueries() { + tests := []struct { + Name string + CQ []byte + ResponseCheck func(data []byte) + }{ + { + Name: "metoken query params", + CQ: s.genCustomQuery(wq.UmeeQuery{ + MeTokenParameters: &metoken.QueryParams{}, + }), + ResponseCheck: func(data []byte) { + var rr metoken.QueryParamsResponse + err := json.Unmarshal(data, &rr) + assert.NilError(s.T, err) + assert.DeepEqual(s.T, rr.Params, metoken.DefaultParams()) + }, + }, + } + + for _, tc := range tests { + s.T.Run(tc.Name, func(t *testing.T) { + resp := s.queryContract(tc.CQ) + tc.ResponseCheck(resp.Data) + }) + } +} diff --git a/contrib/scripts/mockgen.sh b/contrib/scripts/mockgen.sh index d57bd3a380..224afa112d 100644 --- a/contrib/scripts/mockgen.sh +++ b/contrib/scripts/mockgen.sh @@ -2,6 +2,7 @@ mockgen_cmd="go run github.com/golang/mock/mockgen" +$mockgen_cmd -source ./x/ugov/keeper_interfaces.go -package mocks -destination ./x/ugov/mocks/keepers.go $mockgen_cmd -source ./x/uibc/expected_keepers.go -package mocks -destination ./x/uibc/mocks/keepers.go $mockgen_cmd -source ./x/metoken/expected_keepers.go -package mocks -destination ./x/metoken/mocks/keepers.go -$mockgen_cmd -source ./app/inflation/expected_keepers.go -package mocks -destination ./app/inflation/mocks/keepers.go \ No newline at end of file +$mockgen_cmd -source ./app/inflation/expected_keepers.go -package mocks -destination ./app/inflation/mocks/keepers.go diff --git a/tests/artifacts/umee_cosmwasm-aarch64.wasm b/tests/artifacts/umee_cosmwasm-aarch64.wasm index 2c0ddb094e..3a78930fee 100644 Binary files a/tests/artifacts/umee_cosmwasm-aarch64.wasm and b/tests/artifacts/umee_cosmwasm-aarch64.wasm differ diff --git a/util/coin/fixtures.go b/util/coin/fixtures.go index d1cac138a3..04a3204752 100644 --- a/util/coin/fixtures.go +++ b/util/coin/fixtures.go @@ -4,7 +4,6 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" appparams "github.com/umee-network/umee/v5/app/params" - leveragetypes "github.com/umee-network/umee/v5/x/leverage/types" ) const umee = appparams.BondDenom @@ -12,7 +11,7 @@ const umee = appparams.BondDenom // common coins used in tests var ( // the uToken denom "u/uumee" - UumeeDenom = leveragetypes.ToUTokenDenom(umee) + UumeeDenom = ToUTokenDenom(umee) // 1uumee Coin Umee1 = New(umee, 1) // 10_000uumee Coin @@ -50,15 +49,15 @@ func UmeeDec(amount string) sdk.DecCoin { // Utoken creates a uToken DecCoin. func Utoken(denom string, amount int64) sdk.Coin { - return New(leveragetypes.ToUTokenDenom(denom), amount) + return New(ToUTokenDenom(denom), amount) } // UtokenDec creates a uToken DecCoin. func UtokenDec(denom string, amount string) sdk.DecCoin { - return Dec(leveragetypes.ToUTokenDenom(denom), amount) + return Dec(ToUTokenDenom(denom), amount) } // UtokenDecF creates a uToken DecCoin. func UtokenDecF(denom string, amount float64) sdk.DecCoin { - return DecF(leveragetypes.ToUTokenDenom(denom), amount) + return DecF(ToUTokenDenom(denom), amount) } diff --git a/util/coin/utoken.go b/util/coin/utoken.go new file mode 100644 index 0000000000..7347ff0c12 --- /dev/null +++ b/util/coin/utoken.go @@ -0,0 +1,39 @@ +package coin + +import ( + "strings" +) + +const ( + // UTokenPrefix defines the uToken denomination prefix for all uToken types. + UTokenPrefix = "u/" +) + +// HasUTokenPrefix detects the uToken prefix on a denom. +func HasUTokenPrefix(denom string) bool { + return strings.HasPrefix(denom, UTokenPrefix) +} + +// ToUTokenDenom adds the uToken prefix to a denom. Returns an empty string +// instead if the prefix was already present. +func ToUTokenDenom(denom string) string { + if HasUTokenPrefix(denom) { + return "" + } + return UTokenPrefix + denom +} + +// StripUTokenDenom strips the uToken prefix from a denom, or returns an empty +// string if it was not present. Also returns an empty string if the prefix +// was repeated multiple times. +func StripUTokenDenom(denom string) string { + if !HasUTokenPrefix(denom) { + return "" + } + s := strings.TrimPrefix(denom, UTokenPrefix) + if HasUTokenPrefix(s) { + // denom started with "u/u/" + return "" + } + return s +} diff --git a/util/coin/utoken_test.go b/util/coin/utoken_test.go new file mode 100644 index 0000000000..db73aa5857 --- /dev/null +++ b/util/coin/utoken_test.go @@ -0,0 +1,37 @@ +package coin + +import ( + "testing" + + "gotest.tools/v3/assert" +) + +func TestToUTokenDenom(t *testing.T) { + // Turns base token denoms into base uTokens + assert.Equal(t, "u/uumee", ToUTokenDenom("uumee")) + assert.Equal(t, "u/ibc/abcd", ToUTokenDenom("ibc/abcd")) + + // Empty return for uTokens + assert.Equal(t, "", ToUTokenDenom("u/uumee")) + assert.Equal(t, "", ToUTokenDenom("u/ibc/abcd")) + + // Edge cases + assert.Equal(t, "u/", ToUTokenDenom("")) +} + +func TestToTokenDenom(t *testing.T) { + // Turns uToken denoms into base tokens + assert.Equal(t, "uumee", StripUTokenDenom("u/uumee")) + assert.Equal(t, "ibc/abcd", StripUTokenDenom("u/ibc/abcd")) + + // Empty return for base tokens + assert.Equal(t, "", StripUTokenDenom("uumee")) + assert.Equal(t, "", StripUTokenDenom("ibc/abcd")) + + // Empty return on repreated prefix + assert.Equal(t, "", StripUTokenDenom("u/u/abcd")) + + // Edge cases + assert.Equal(t, "", StripUTokenDenom("u/")) + assert.Equal(t, "", StripUTokenDenom("")) +} diff --git a/x/incentive/expected_keepers.go b/x/incentive/expected_keepers.go index bb310be1eb..f31203f31f 100644 --- a/x/incentive/expected_keepers.go +++ b/x/incentive/expected_keepers.go @@ -21,5 +21,5 @@ type LeverageKeeper interface { GetTokenSettings(ctx sdk.Context, denom string) (leveragetypes.Token, error) // These are used for APY queries only TotalTokenValue(ctx sdk.Context, coins sdk.Coins, mode leveragetypes.PriceMode) (sdk.Dec, error) - ExchangeUToken(ctx sdk.Context, uToken sdk.Coin) (sdk.Coin, error) + ToToken(ctx sdk.Context, uToken sdk.Coin) (sdk.Coin, error) } diff --git a/x/incentive/genesis.go b/x/incentive/genesis.go index 6f39ba5dad..2f45c83030 100644 --- a/x/incentive/genesis.go +++ b/x/incentive/genesis.go @@ -8,6 +8,7 @@ import ( "github.com/cosmos/cosmos-sdk/codec" sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/umee-network/umee/v5/util/coin" leveragetypes "github.com/umee-network/umee/v5/x/leverage/types" ) @@ -189,7 +190,7 @@ func (ip IncentiveProgram) Validate() error { if err := sdk.ValidateDenom(ip.UToken); err != nil { return err } - if !leveragetypes.HasUTokenPrefix(ip.UToken) { + if !coin.HasUTokenPrefix(ip.UToken) { // only allow uToken denoms as bonded denoms return errors.Wrap(leveragetypes.ErrNotUToken, ip.UToken) } @@ -197,7 +198,7 @@ func (ip IncentiveProgram) Validate() error { if err := ip.TotalRewards.Validate(); err != nil { return err } - if leveragetypes.HasUTokenPrefix(ip.TotalRewards.Denom) { + if coin.HasUTokenPrefix(ip.TotalRewards.Denom) { // only allow base token denoms as rewards return errors.Wrap(leveragetypes.ErrUToken, ip.TotalRewards.Denom) } @@ -264,7 +265,7 @@ func (b Bond) Validate() error { if err := b.UToken.Validate(); err != nil { return err } - if !leveragetypes.HasUTokenPrefix(b.UToken.Denom) { + if !coin.HasUTokenPrefix(b.UToken.Denom) { return leveragetypes.ErrNotUToken.Wrap(b.UToken.Denom) } return nil @@ -286,14 +287,14 @@ func (rt RewardTracker) Validate() error { if err := sdk.ValidateDenom(rt.UToken); err != nil { return err } - if !leveragetypes.HasUTokenPrefix(rt.UToken) { + if !coin.HasUTokenPrefix(rt.UToken) { return leveragetypes.ErrNotUToken.Wrap(rt.UToken) } if err := rt.Rewards.Validate(); err != nil { return err } for _, r := range rt.Rewards { - if leveragetypes.HasUTokenPrefix(r.Denom) { + if coin.HasUTokenPrefix(r.Denom) { return leveragetypes.ErrUToken.Wrap(r.Denom) } } @@ -313,14 +314,14 @@ func (ra RewardAccumulator) Validate() error { if err := sdk.ValidateDenom(ra.UToken); err != nil { return err } - if !leveragetypes.HasUTokenPrefix(ra.UToken) { + if !coin.HasUTokenPrefix(ra.UToken) { return leveragetypes.ErrNotUToken.Wrap(ra.UToken) } if err := ra.Rewards.Validate(); err != nil { return err } for _, r := range ra.Rewards { - if leveragetypes.HasUTokenPrefix(r.Denom) { + if coin.HasUTokenPrefix(r.Denom) { return leveragetypes.ErrUToken.Wrap(r.Denom) } } @@ -340,7 +341,7 @@ func (u Unbonding) Validate() error { if u.End < u.Start { return ErrInvalidUnbonding.Wrap("start time > end time") } - if !leveragetypes.HasUTokenPrefix(u.UToken.Denom) { + if !coin.HasUTokenPrefix(u.UToken.Denom) { return leveragetypes.ErrNotUToken.Wrap(u.UToken.Denom) } return u.UToken.Validate() @@ -362,7 +363,7 @@ func (au AccountUnbondings) Validate() error { if err := sdk.ValidateDenom(au.UToken); err != nil { return err } - if !leveragetypes.HasUTokenPrefix(au.UToken) { + if !coin.HasUTokenPrefix(au.UToken) { return leveragetypes.ErrNotUToken.Wrap(au.UToken) } for _, u := range au.Unbondings { diff --git a/x/incentive/keeper/grpc_query.go b/x/incentive/keeper/grpc_query.go index 49990f64b6..bc3a5ecd10 100644 --- a/x/incentive/keeper/grpc_query.go +++ b/x/incentive/keeper/grpc_query.go @@ -263,7 +263,7 @@ func (q Querier) ActualRates( } // compute oracle price ratio of rewards to reference bond amount - referenceToken, err := k.leverageKeeper.ExchangeUToken(ctx, referenceUToken) + referenceToken, err := k.leverageKeeper.ToToken(ctx, referenceUToken) if err != nil { return nil, err } diff --git a/x/incentive/keeper/mock_test.go b/x/incentive/keeper/mock_test.go index 423e1b758c..e30e531f27 100644 --- a/x/incentive/keeper/mock_test.go +++ b/x/incentive/keeper/mock_test.go @@ -218,13 +218,13 @@ func (m *mockLeverageKeeper) TotalTokenValue(_ sdk.Context, coins sdk.Coins, _ l return total, nil } -// ExchangeUToken implements the expected leverage keeper, with uToken exchange rates always equal to 1 -func (m *mockLeverageKeeper) ExchangeUToken(_ sdk.Context, uToken sdk.Coin) (sdk.Coin, error) { - if !leveragetypes.HasUTokenPrefix(uToken.Denom) { +// ToToken implements the expected leverage keeper, with uToken exchange rates always equal to 1 +func (m *mockLeverageKeeper) ToToken(_ sdk.Context, uToken sdk.Coin) (sdk.Coin, error) { + if !coin.HasUTokenPrefix(uToken.Denom) { return uToken, leveragetypes.ErrUToken } return sdk.NewCoin( - leveragetypes.ToTokenDenom(uToken.Denom), + coin.StripUTokenDenom(uToken.Denom), uToken.Amount, ), nil } diff --git a/x/incentive/keeper/msg_server.go b/x/incentive/keeper/msg_server.go index 436116bcab..36d3218cfe 100644 --- a/x/incentive/keeper/msg_server.go +++ b/x/incentive/keeper/msg_server.go @@ -5,6 +5,7 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/umee-network/umee/v5/util/coin" "github.com/umee-network/umee/v5/x/incentive" leveragetypes "github.com/umee-network/umee/v5/x/leverage/types" ) @@ -210,7 +211,7 @@ func addressUToken(account string, asset sdk.Coin) (sdk.AccAddress, string, erro if err != nil { return sdk.AccAddress{}, "", err } - if !leveragetypes.HasUTokenPrefix(asset.Denom) { + if !coin.HasUTokenPrefix(asset.Denom) { return sdk.AccAddress{}, "", leveragetypes.ErrNotUToken.Wrap(asset.Denom) } diff --git a/x/incentive/keeper/msg_server_test.go b/x/incentive/keeper/msg_server_test.go index 0a0b4fae28..96c668fb15 100644 --- a/x/incentive/keeper/msg_server_test.go +++ b/x/incentive/keeper/msg_server_test.go @@ -19,8 +19,8 @@ func TestMsgBond(t *testing.T) { const ( umee = fixtures.UmeeDenom atom = fixtures.AtomDenom - uumee = leveragetypes.UTokenPrefix + fixtures.UmeeDenom - uatom = leveragetypes.UTokenPrefix + fixtures.AtomDenom + uumee = coin.UTokenPrefix + fixtures.UmeeDenom + uatom = coin.UTokenPrefix + fixtures.AtomDenom ) // create an account which the mock leverage keeper will report as @@ -104,8 +104,8 @@ func TestMsgBeginUnbonding(t *testing.T) { const ( umee = fixtures.UmeeDenom atom = fixtures.AtomDenom - uumee = leveragetypes.UTokenPrefix + fixtures.UmeeDenom - uatom = leveragetypes.UTokenPrefix + fixtures.AtomDenom + uumee = coin.UTokenPrefix + fixtures.UmeeDenom + uatom = coin.UTokenPrefix + fixtures.AtomDenom ) // create an account which the mock leverage keeper will report as @@ -201,8 +201,8 @@ func TestMsgEmergencyUnbond(t *testing.T) { const ( umee = fixtures.UmeeDenom atom = fixtures.AtomDenom - uumee = leveragetypes.UTokenPrefix + fixtures.UmeeDenom - uatom = leveragetypes.UTokenPrefix + fixtures.AtomDenom + uumee = coin.UTokenPrefix + fixtures.UmeeDenom + uatom = coin.UTokenPrefix + fixtures.AtomDenom ) // create an account which the mock leverage keeper will report as @@ -290,7 +290,7 @@ func TestMsgSponsor(t *testing.T) { const ( umee = fixtures.UmeeDenom - uumee = leveragetypes.UTokenPrefix + fixtures.UmeeDenom + uumee = coin.UTokenPrefix + fixtures.UmeeDenom ) sponsor := k.newAccount(sdk.NewInt64Coin(umee, 15_000000)) @@ -389,7 +389,7 @@ func TestMsgGovCreatePrograms(t *testing.T) { const ( umee = fixtures.UmeeDenom - uumee = leveragetypes.UTokenPrefix + fixtures.UmeeDenom + uumee = coin.UTokenPrefix + fixtures.UmeeDenom ) // fund community fund with 15 UMEE diff --git a/x/incentive/keeper/program.go b/x/incentive/keeper/program.go index e0cd47e93a..101581e4cd 100644 --- a/x/incentive/keeper/program.go +++ b/x/incentive/keeper/program.go @@ -6,8 +6,8 @@ import ( authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" disttypes "github.com/cosmos/cosmos-sdk/x/distribution/types" + "github.com/umee-network/umee/v5/util/coin" "github.com/umee-network/umee/v5/x/incentive" - leveragetypes "github.com/umee-network/umee/v5/x/leverage/types" ) // createIncentiveProgram saves an incentive program to upcoming programs after it @@ -50,7 +50,7 @@ func (k Keeper) createIncentiveProgram( // Note that this interprets Exponent == 0 as needing initialization, but if an asset actually had exponent zero, // and had already been initialized, this would be a harmless no-op. if ra := k.getRewardAccumulator(ctx, program.UToken); ra.Exponent == 0 { - token, err := k.leverageKeeper.GetTokenSettings(ctx, leveragetypes.ToTokenDenom(program.UToken)) + token, err := k.leverageKeeper.GetTokenSettings(ctx, coin.StripUTokenDenom(program.UToken)) if err != nil { // unregistered tokens do not have uTokens, so they cannot be incentivized return err diff --git a/x/incentive/keeper/reward.go b/x/incentive/keeper/reward.go index 184b615066..f49d1efa25 100644 --- a/x/incentive/keeper/reward.go +++ b/x/incentive/keeper/reward.go @@ -3,6 +3,7 @@ package keeper import ( sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/umee-network/umee/v5/util/coin" "github.com/umee-network/umee/v5/x/incentive" leveragetypes "github.com/umee-network/umee/v5/x/leverage/types" ) @@ -13,7 +14,7 @@ var secondsPerYear = sdk.MustNewDecFromStr("31557600") // 365.25 * 3600 * 24 // of that uToken (10^exponent from the uToken's reward accumulator) and the estimated rewards that bond // would earn if they continued at the current rate computed at the time of query. func (k Keeper) calculateReferenceAPY(ctx sdk.Context, denom string) (sdk.Coin, sdk.Coins, error) { - if !leveragetypes.HasUTokenPrefix(denom) { + if !coin.HasUTokenPrefix(denom) { return sdk.Coin{}, sdk.Coins{}, leveragetypes.ErrNotUToken.Wrap(denom) } diff --git a/x/incentive/keeper/scenario_test.go b/x/incentive/keeper/scenario_test.go index 0c1cfe832a..58004a6d88 100644 --- a/x/incentive/keeper/scenario_test.go +++ b/x/incentive/keeper/scenario_test.go @@ -9,14 +9,13 @@ import ( "github.com/umee-network/umee/v5/util/coin" "github.com/umee-network/umee/v5/x/incentive" "github.com/umee-network/umee/v5/x/leverage/fixtures" - leveragetypes "github.com/umee-network/umee/v5/x/leverage/types" ) const ( umee = fixtures.UmeeDenom atom = fixtures.AtomDenom - uUmee = leveragetypes.UTokenPrefix + fixtures.UmeeDenom - uAtom = leveragetypes.UTokenPrefix + fixtures.AtomDenom + uUmee = coin.UTokenPrefix + fixtures.UmeeDenom + uAtom = coin.UTokenPrefix + fixtures.AtomDenom ) var zeroCoins = sdk.NewCoins() diff --git a/x/leverage/client/tests/tests.go b/x/leverage/client/tests/tests.go index 1aaec36437..fd015d06e3 100644 --- a/x/leverage/client/tests/tests.go +++ b/x/leverage/client/tests/tests.go @@ -2,8 +2,10 @@ package tests import ( sdk "github.com/cosmos/cosmos-sdk/types" + appparams "github.com/umee-network/umee/v5/app/params" itestsuite "github.com/umee-network/umee/v5/tests/cli" + "github.com/umee-network/umee/v5/util/coin" "github.com/umee-network/umee/v5/x/leverage/client/cli" "github.com/umee-network/umee/v5/x/leverage/fixtures" "github.com/umee-network/umee/v5/x/leverage/types" @@ -306,7 +308,7 @@ func (s *IntegrationTests) TestLeverageScenario() { sdk.NewInt64Coin(appparams.BondDenom, 1001), ), Collateral: sdk.NewCoins( - sdk.NewInt64Coin(types.ToUTokenDenom(appparams.BondDenom), 1000), + sdk.NewInt64Coin(coin.ToUTokenDenom(appparams.BondDenom), 1000), ), Borrowed: sdk.NewCoins( sdk.NewInt64Coin(appparams.BondDenom, 251), @@ -380,7 +382,7 @@ func (s *IntegrationTests) TestLeverageScenario() { sdk.NewInt64Coin(appparams.BondDenom, 201), // slightly increased uToken exchange rate ), Collateral: sdk.NewCoins( - sdk.NewInt64Coin(types.ToUTokenDenom(appparams.BondDenom), 100), + sdk.NewInt64Coin(coin.ToUTokenDenom(appparams.BondDenom), 100), ), Borrowed: sdk.NewCoins(), }, diff --git a/x/leverage/keeper/borrows.go b/x/leverage/keeper/borrows.go index dcf3419654..92e358066e 100644 --- a/x/leverage/keeper/borrows.go +++ b/x/leverage/keeper/borrows.go @@ -134,7 +134,7 @@ func (k Keeper) CalculateBorrowLimit(ctx sdk.Context, collateral sdk.Coins) (sdk for _, coin := range collateral { // convert uToken collateral to base assets - baseAsset, err := k.ExchangeUToken(ctx, coin) + baseAsset, err := k.ToToken(ctx, coin) if err != nil { return sdk.ZeroDec(), err } @@ -170,7 +170,7 @@ func (k Keeper) VisibleBorrowLimit(ctx sdk.Context, collateral sdk.Coins) (sdk.D for _, coin := range collateral { // convert uToken collateral to base assets - baseAsset, err := k.ExchangeUToken(ctx, coin) + baseAsset, err := k.ToToken(ctx, coin) if err != nil { return sdk.ZeroDec(), err } @@ -208,7 +208,7 @@ func (k Keeper) CalculateLiquidationThreshold(ctx sdk.Context, collateral sdk.Co for _, coin := range collateral { // convert uToken collateral to base assets - baseAsset, err := k.ExchangeUToken(ctx, coin) + baseAsset, err := k.ToToken(ctx, coin) if err != nil { return sdk.ZeroDec(), err } diff --git a/x/leverage/keeper/borrows_test.go b/x/leverage/keeper/borrows_test.go index 466520c4e8..a9007ecb95 100644 --- a/x/leverage/keeper/borrows_test.go +++ b/x/leverage/keeper/borrows_test.go @@ -213,7 +213,7 @@ func (s *IntegrationTestSuite) TestCalculateBorrowLimit() { require.ErrorIs(err, types.ErrNotUToken) // Create collateral uTokens (1k u/umee) - umeeCollatDenom := types.ToUTokenDenom(umeeDenom) + umeeCollatDenom := coin.ToUTokenDenom(umeeDenom) umeeCollateral := sdk.NewCoins(coin.New(umeeCollatDenom, 1000_000000)) // Manually compute borrow limit using collateral weight of 0.25 @@ -228,7 +228,7 @@ func (s *IntegrationTestSuite) TestCalculateBorrowLimit() { require.Equal(expectedUmeeLimit, borrowLimit) // Create collateral atom uTokens (1k u/uatom) - atomCollatDenom := types.ToUTokenDenom(atomDenom) + atomCollatDenom := coin.ToUTokenDenom(atomDenom) atomCollateral := sdk.NewCoins(coin.New(atomCollatDenom, 1000_000000)) // Manually compute borrow limit using collateral weight of 0.25 diff --git a/x/leverage/keeper/collateral.go b/x/leverage/keeper/collateral.go index 31786d4d99..0b80822977 100644 --- a/x/leverage/keeper/collateral.go +++ b/x/leverage/keeper/collateral.go @@ -4,6 +4,7 @@ import ( sdkmath "cosmossdk.io/math" sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/umee-network/umee/v5/util/coin" "github.com/umee-network/umee/v5/x/leverage/types" ) @@ -63,7 +64,7 @@ func (k Keeper) moveCollateral(ctx sdk.Context, fromAddr, toAddr sdk.AccAddress, // GetTotalCollateral returns an sdk.Coin representing how much of a given uToken // the x/leverage module account currently holds as collateral. Non-uTokens return zero. func (k Keeper) GetTotalCollateral(ctx sdk.Context, denom string) sdk.Coin { - if !types.HasUTokenPrefix(denom) { + if !coin.HasUTokenPrefix(denom) { // non-uTokens cannot be collateral return sdk.Coin{} } @@ -80,7 +81,7 @@ func (k Keeper) CalculateCollateralValue(ctx sdk.Context, collateral sdk.Coins, for _, coin := range collateral { // convert uToken collateral to base assets - baseAsset, err := k.ExchangeUToken(ctx, coin) + baseAsset, err := k.ToToken(ctx, coin) if err != nil { return sdk.ZeroDec(), err } @@ -107,7 +108,7 @@ func (k Keeper) VisibleCollateralValue(ctx sdk.Context, collateral sdk.Coins, mo for _, coin := range collateral { // convert uToken collateral to base assets - baseAsset, err := k.ExchangeUToken(ctx, coin) + baseAsset, err := k.ToToken(ctx, coin) if err != nil { return sdk.ZeroDec(), err } @@ -132,7 +133,7 @@ func (k Keeper) GetAllTotalCollateral(ctx sdk.Context) sdk.Coins { tokens := k.GetAllRegisteredTokens(ctx) for _, t := range tokens { - uDenom := types.ToUTokenDenom(t.BaseDenom) + uDenom := coin.ToUTokenDenom(t.BaseDenom) total = total.Add(k.GetTotalCollateral(ctx, uDenom)) } return total @@ -142,7 +143,7 @@ func (k Keeper) GetAllTotalCollateral(ctx sdk.Context) sdk.Coins { // which is defined as the token's liquidity, divided by the base token equivalent // of associated uToken's total collateral. Ranges from 0 to 1.0 func (k Keeper) CollateralLiquidity(ctx sdk.Context, denom string) sdk.Dec { - totalCollateral := k.GetTotalCollateral(ctx, types.ToUTokenDenom(denom)) + totalCollateral := k.GetTotalCollateral(ctx, coin.ToUTokenDenom(denom)) exchangeRate := k.DeriveExchangeRate(ctx, denom) liquidity := k.AvailableLiquidity(ctx, denom) @@ -204,7 +205,7 @@ func (k Keeper) checkCollateralLiquidity(ctx sdk.Context, denom string) error { // checkCollateralShare returns an error if a given uToken is above its collateral share // as calculated using only tokens whose oracle prices exist func (k *Keeper) checkCollateralShare(ctx sdk.Context, denom string) error { - token, err := k.GetTokenSettings(ctx, types.ToTokenDenom(denom)) + token, err := k.GetTokenSettings(ctx, coin.StripUTokenDenom(denom)) if err != nil { return err } @@ -230,7 +231,7 @@ func (k *Keeper) checkCollateralShare(ctx sdk.Context, denom string) error { // withdraw up to the amount in their wallet, then determines how much collateral can be withdrawn in addition to that. // The returned value is the sum of the two values. func (k Keeper) ModuleMaxWithdraw(ctx sdk.Context, spendableUTokens sdk.Coin) (sdkmath.Int, error) { - denom := types.ToTokenDenom(spendableUTokens.Denom) + denom := coin.StripUTokenDenom(spendableUTokens.Denom) // Get the module_available_liquidity moduleAvailableLiquidity, err := k.ModuleAvailableLiquidity(ctx, denom) @@ -251,7 +252,7 @@ func (k Keeper) ModuleMaxWithdraw(ctx sdk.Context, spendableUTokens sdk.Coin) (s // Get module collateral for the uDenom totalCollateral := k.GetTotalCollateral(ctx, spendableUTokens.Denom) - totalTokenCollateral, err := k.ExchangeUTokens(ctx, sdk.NewCoins(totalCollateral)) + totalTokenCollateral, err := k.ToTokens(ctx, sdk.NewCoins(totalCollateral)) if err != nil { return sdk.ZeroInt(), err } diff --git a/x/leverage/keeper/collateral_test.go b/x/leverage/keeper/collateral_test.go index ff6b6fdb65..26f271ba29 100644 --- a/x/leverage/keeper/collateral_test.go +++ b/x/leverage/keeper/collateral_test.go @@ -9,7 +9,7 @@ import ( func (s *IntegrationTestSuite) TestGetCollateralAmount() { ctx, require := s.ctx, s.Require() - uDenom := types.ToUTokenDenom(umeeDenom) + uDenom := coin.ToUTokenDenom(umeeDenom) // get u/umee collateral amount of empty account address collateral := s.tk.GetCollateral(ctx, sdk.AccAddress{}, uDenom) @@ -56,7 +56,7 @@ func (s *IntegrationTestSuite) TestGetCollateralAmount() { func (s *IntegrationTestSuite) TestSetCollateralAmount() { ctx, require := s.ctx, s.Require() - uDenom := types.ToUTokenDenom(umeeDenom) + uDenom := coin.ToUTokenDenom(umeeDenom) // set u/umee collateral amount of empty account address (error) err := s.tk.SetCollateral(ctx, sdk.AccAddress{}, coin.New(uDenom, 0)) @@ -115,7 +115,7 @@ func (s *IntegrationTestSuite) TestTotalCollateral() { require.Equal(sdk.Coin{}, collateral, "not a uToken") // Test zero collateral - uDenom := types.ToUTokenDenom(umeeDenom) + uDenom := coin.ToUTokenDenom(umeeDenom) collateral = app.LeverageKeeper.GetTotalCollateral(ctx, uDenom) require.Equal(coin.New(uDenom, 0), collateral, "zero collateral") diff --git a/x/leverage/keeper/exchange_rate.go b/x/leverage/keeper/exchange_rate.go index 8cfb9b03fe..65d0fb964f 100644 --- a/x/leverage/keeper/exchange_rate.go +++ b/x/leverage/keeper/exchange_rate.go @@ -3,35 +3,35 @@ package keeper import ( sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/umee-network/umee/v5/util/coin" "github.com/umee-network/umee/v5/x/leverage/types" ) -// ExchangeToken converts an sdk.Coin containing a base asset to its value as a -// uToken. -func (k Keeper) ExchangeToken(ctx sdk.Context, token sdk.Coin) (sdk.Coin, error) { +// ToUToken returns uToken in the amount a user would receive when supplying the token. +// Returns error if the input is not a Token. +func (k Keeper) ToUToken(ctx sdk.Context, token sdk.Coin) (sdk.Coin, error) { if err := token.Validate(); err != nil { return sdk.Coin{}, err } - uTokenDenom := types.ToUTokenDenom(token.Denom) + uTokenDenom := coin.ToUTokenDenom(token.Denom) if uTokenDenom == "" { return sdk.Coin{}, types.ErrUToken.Wrap(token.Denom) } exchangeRate := k.DeriveExchangeRate(ctx, token.Denom) - uTokenAmount := toDec(token.Amount).Quo(exchangeRate).TruncateInt() return sdk.NewCoin(uTokenDenom, uTokenAmount), nil } -// ExchangeUToken converts an sdk.Coin containing a uToken to its value in a base -// token. -func (k Keeper) ExchangeUToken(ctx sdk.Context, uToken sdk.Coin) (sdk.Coin, error) { +// ToToken returns Token in the amount a user would receive when withdrawing the uToken. +// Returns error if the input is not a uToken. +func (k Keeper) ToToken(ctx sdk.Context, uToken sdk.Coin) (sdk.Coin, error) { if err := uToken.Validate(); err != nil { return sdk.Coin{}, err } - tokenDenom := types.ToTokenDenom(uToken.Denom) + tokenDenom := coin.StripUTokenDenom(uToken.Denom) if tokenDenom == "" { return sdk.Coin{}, types.ErrNotUToken.Wrap(uToken.Denom) } @@ -42,16 +42,17 @@ func (k Keeper) ExchangeUToken(ctx sdk.Context, uToken sdk.Coin) (sdk.Coin, erro return sdk.NewCoin(tokenDenom, tokenAmount), nil } -// ExchangeUTokens converts an sdk.Coins containing uTokens to their values in base -// tokens. -func (k Keeper) ExchangeUTokens(ctx sdk.Context, uTokens sdk.Coins) (sdk.Coins, error) { +// ToTokens returns list of Tokens in the amount a user would receive when withdrawing the +// list of uTokens. +// Returns error if any of the inputs are tokens. +func (k Keeper) ToTokens(ctx sdk.Context, uTokens sdk.Coins) (sdk.Coins, error) { if err := uTokens.Validate(); err != nil { return sdk.Coins{}, err } tokens := sdk.Coins{} for _, coin := range uTokens { - token, err := k.ExchangeUToken(ctx, coin) + token, err := k.ToToken(ctx, coin) if err != nil { return sdk.Coins{}, err } @@ -71,7 +72,7 @@ func (k Keeper) DeriveExchangeRate(ctx sdk.Context, denom string) sdk.Dec { moduleBalance := toDec(k.ModuleBalance(ctx, denom).Amount) reserveAmount := toDec(k.GetReserves(ctx, denom).Amount) totalBorrowed := k.getAdjustedTotalBorrowed(ctx, denom).Mul(k.getInterestScalar(ctx, denom)) - uTokenSupply := k.GetUTokenSupply(ctx, types.ToUTokenDenom(denom)).Amount + uTokenSupply := k.GetUTokenSupply(ctx, coin.ToUTokenDenom(denom)).Amount // Derive effective token supply tokenSupply := moduleBalance.Add(totalBorrowed).Sub(reserveAmount) diff --git a/x/leverage/keeper/grpc_query.go b/x/leverage/keeper/grpc_query.go index 45cd997bde..e2055b7f16 100644 --- a/x/leverage/keeper/grpc_query.go +++ b/x/leverage/keeper/grpc_query.go @@ -7,6 +7,7 @@ import ( "google.golang.org/grpc/codes" "google.golang.org/grpc/status" + "github.com/umee-network/umee/v5/util/coin" "github.com/umee-network/umee/v5/x/leverage/types" ) @@ -112,7 +113,7 @@ func (q Querier) MarketSummary( borrowed := q.Keeper.GetTotalBorrowed(ctx, req.Denom) liquidity := q.Keeper.AvailableLiquidity(ctx, req.Denom) - uDenom := types.ToUTokenDenom(req.Denom) + uDenom := coin.ToUTokenDenom(req.Denom) uSupply := q.Keeper.GetUTokenSupply(ctx, uDenom) uCollateral := q.Keeper.GetTotalCollateral(ctx, uDenom) @@ -362,7 +363,7 @@ func (q Querier) MaxWithdraw( // On non-nil error here, max withdraw is zero. uToken, _, err := q.Keeper.userMaxWithdraw(ctx, addr, denom) if err == nil && uToken.IsPositive() { - token, err := q.Keeper.ExchangeUToken(ctx, uToken) + token, err := q.Keeper.ToToken(ctx, uToken) if err != nil { return nil, err } diff --git a/x/leverage/keeper/incentive.go b/x/leverage/keeper/incentive.go index 2266477193..c33b39bd67 100644 --- a/x/leverage/keeper/incentive.go +++ b/x/leverage/keeper/incentive.go @@ -7,7 +7,7 @@ import ( // DonateCollateral burns some collateral uTokens already present in the module, then adds their equivalent amount // in tokens reserves. Currently, this is only used as the penalty for incentive module's MsgEmergencyUnbond. func (k Keeper) DonateCollateral(ctx sdk.Context, fromAddr sdk.AccAddress, uToken sdk.Coin) error { - token, err := k.ExchangeUToken(ctx, uToken) + token, err := k.ToToken(ctx, uToken) if err != nil { return err } diff --git a/x/leverage/keeper/inspector.go b/x/leverage/keeper/inspector.go index 5a5f113f5f..d975e789bc 100644 --- a/x/leverage/keeper/inspector.go +++ b/x/leverage/keeper/inspector.go @@ -10,6 +10,7 @@ import ( "google.golang.org/grpc/codes" "google.golang.org/grpc/status" + "github.com/umee-network/umee/v5/util/coin" "github.com/umee-network/umee/v5/x/leverage/types" ) @@ -125,9 +126,9 @@ func symbolDecCoins( for _, c := range coins { exchangeRate := sdk.OneDec() - if types.HasUTokenPrefix(c.Denom) { + if coin.HasUTokenPrefix(c.Denom) { // uTokens will be converted to base tokens - c.Denom = types.ToTokenDenom(c.Denom) + c.Denom = coin.StripUTokenDenom(c.Denom) exchangeRate = tokens[c.Denom].exchangeRate } t, ok := tokens[c.Denom] diff --git a/x/leverage/keeper/invariants_test.go b/x/leverage/keeper/invariants_test.go index c1f5bcbb94..4b482d3cd4 100644 --- a/x/leverage/keeper/invariants_test.go +++ b/x/leverage/keeper/invariants_test.go @@ -4,7 +4,6 @@ import ( appparams "github.com/umee-network/umee/v5/app/params" "github.com/umee-network/umee/v5/util/coin" "github.com/umee-network/umee/v5/x/leverage/keeper" - "github.com/umee-network/umee/v5/x/leverage/types" ) func (s *IntegrationTestSuite) TestReserveAmountInvariant() { @@ -30,7 +29,7 @@ func (s *IntegrationTestSuite) TestCollateralAmountInvariant() { _, broken := keeper.InefficientCollateralAmountInvariant(app.LeverageKeeper)(ctx) require.False(broken) - uTokenDenom := types.ToUTokenDenom(appparams.BondDenom) + uTokenDenom := coin.ToUTokenDenom(appparams.BondDenom) // withdraw the supplied umee in the initBorrowScenario s.withdraw(addr, coin.New(uTokenDenom, 1000_000000)) diff --git a/x/leverage/keeper/keeper.go b/x/leverage/keeper/keeper.go index d3713b18dd..74baee23e6 100644 --- a/x/leverage/keeper/keeper.go +++ b/x/leverage/keeper/keeper.go @@ -91,7 +91,7 @@ func (k Keeper) Supply(ctx sdk.Context, supplierAddr sdk.AccAddress, coin sdk.Co } // determine uToken amount to mint - uToken, err := k.ExchangeToken(ctx, coin) + uToken, err := k.ToUToken(ctx, coin) if err != nil { return sdk.Coin{}, err } @@ -129,7 +129,7 @@ func (k Keeper) SupplyFromModule(ctx sdk.Context, fromModule string, coin sdk.Co } // determine uToken amount to mint - uToken, err := k.ExchangeToken(ctx, coin) + uToken, err := k.ToUToken(ctx, coin) if err != nil { return sdk.Coin{}, true, err } @@ -176,7 +176,7 @@ func (k Keeper) Withdraw(ctx sdk.Context, supplierAddr sdk.AccAddress, uToken sd } // calculate base asset amount to withdraw - token, err := k.ExchangeUToken(ctx, uToken) + token, err := k.ToToken(ctx, uToken) if err != nil { return sdk.Coin{}, isFromCollateral, err } @@ -256,7 +256,7 @@ func (k Keeper) WithdrawToModule(ctx sdk.Context, toModule string, uToken sdk.Co } // calculate base asset amount to withdraw - token, err := k.ExchangeUToken(ctx, uToken) + token, err := k.ToToken(ctx, uToken) if err != nil { return sdk.Coin{}, true, err } @@ -411,10 +411,10 @@ func (k Keeper) Liquidate( } // detect if the user selected a base token reward instead of a uToken - directLiquidation := !types.HasUTokenPrefix(rewardDenom) + directLiquidation := !coin.HasUTokenPrefix(rewardDenom) if !directLiquidation { // convert rewardDenom to base token - rewardDenom = types.ToTokenDenom(rewardDenom) + rewardDenom = coin.StripUTokenDenom(rewardDenom) } // ensure that base reward is a registered token if err := k.validateAcceptedDenom(ctx, rewardDenom); err != nil { @@ -481,7 +481,7 @@ func (k Keeper) LeveragedLiquidate( if rewardDenom == "" { collateral := k.GetBorrowerCollateral(ctx, borrowerAddr) if !collateral.IsZero() { - rewardDenom = types.ToTokenDenom(collateral[0].Denom) + rewardDenom = coin.StripUTokenDenom(collateral[0].Denom) } } @@ -491,7 +491,7 @@ func (k Keeper) LeveragedLiquidate( if err := k.validateAcceptedDenom(ctx, rewardDenom); err != nil { return sdk.Coin{}, sdk.Coin{}, err } - uRewardDenom := types.ToUTokenDenom(rewardDenom) + uRewardDenom := coin.ToUTokenDenom(rewardDenom) tokenRepay, uTokenReward, _, err := k.getLiquidationAmounts( ctx, diff --git a/x/leverage/keeper/limits.go b/x/leverage/keeper/limits.go index 16cb9030ba..1debc8d49d 100644 --- a/x/leverage/keeper/limits.go +++ b/x/leverage/keeper/limits.go @@ -3,6 +3,8 @@ package keeper import ( sdkmath "cosmossdk.io/math" sdk "github.com/cosmos/cosmos-sdk/types" + + "github.com/umee-network/umee/v5/util/coin" "github.com/umee-network/umee/v5/x/leverage/types" ) @@ -11,9 +13,9 @@ import ( // some of the borrower's collateral (other than the denom being withdrawn), computes the maximum safe withdraw // allowed by only the collateral whose prices are known. func (k *Keeper) userMaxWithdraw(ctx sdk.Context, addr sdk.AccAddress, denom string) (sdk.Coin, sdk.Coin, error) { - uDenom := types.ToUTokenDenom(denom) + uDenom := coin.ToUTokenDenom(denom) availableTokens := sdk.NewCoin(denom, k.AvailableLiquidity(ctx, denom)) - availableUTokens, err := k.ExchangeToken(ctx, availableTokens) + availableUTokens, err := k.ToUToken(ctx, availableTokens) if err != nil { return sdk.Coin{}, sdk.Coin{}, err } @@ -144,7 +146,7 @@ func (k *Keeper) userMaxWithdraw(ctx sdk.Context, addr sdk.AccAddress, denom str // input denom should be a base token. If oracle prices are missing for some of the borrower's // collateral, computes the maximum safe borrow allowed by only the collateral whose prices are known. func (k *Keeper) userMaxBorrow(ctx sdk.Context, addr sdk.AccAddress, denom string) (sdk.Coin, error) { - if types.HasUTokenPrefix(denom) { + if coin.HasUTokenPrefix(denom) { return sdk.Coin{}, types.ErrUToken } token, err := k.GetTokenSettings(ctx, denom) @@ -230,7 +232,7 @@ func (k *Keeper) userMaxBorrow(ctx sdk.Context, addr sdk.AccAddress, denom strin // under current market conditions. If any collateral denoms other than this are missing // oracle prices, calculates a (lower) maximum amount using the collateral with known prices. func (k *Keeper) maxCollateralFromShare(ctx sdk.Context, denom string) (sdkmath.Int, error) { - token, err := k.GetTokenSettings(ctx, types.ToTokenDenom(denom)) + token, err := k.GetTokenSettings(ctx, coin.StripUTokenDenom(denom)) if err != nil { return sdk.ZeroInt(), err } @@ -264,7 +266,7 @@ func (k *Keeper) maxCollateralFromShare(ctx sdk.Context, denom string) (sdkmath. // determine the amount of base tokens which would be required to reach maxValue, // using the higher of spot or historic prices - udenom := types.ToUTokenDenom(denom) + udenom := coin.ToUTokenDenom(denom) maxUTokens, err := k.UTokenWithValue(ctx, udenom, maxValue, types.PriceModeHigh) if err != nil { return sdk.ZeroInt(), err @@ -281,8 +283,8 @@ func (k Keeper) ModuleAvailableLiquidity(ctx sdk.Context, denom string) (sdkmath liquidity := k.AvailableLiquidity(ctx, denom) // Get module collateral for the associated uToken - totalCollateral := k.GetTotalCollateral(ctx, types.ToUTokenDenom(denom)) - totalTokenCollateral, err := k.ExchangeUTokens(ctx, sdk.NewCoins(totalCollateral)) + totalCollateral := k.GetTotalCollateral(ctx, coin.ToUTokenDenom(denom)) + totalTokenCollateral, err := k.ToTokens(ctx, sdk.NewCoins(totalCollateral)) if err != nil { return sdkmath.Int{}, err } diff --git a/x/leverage/keeper/liquidate.go b/x/leverage/keeper/liquidate.go index c346fec0e5..61721c2c70 100644 --- a/x/leverage/keeper/liquidate.go +++ b/x/leverage/keeper/liquidate.go @@ -4,6 +4,7 @@ import ( sdkmath "cosmossdk.io/math" sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/umee-network/umee/v5/util/coin" "github.com/umee-network/umee/v5/x/leverage/types" ) @@ -20,7 +21,7 @@ func (k Keeper) getLiquidationAmounts( leveragedLiquidate bool, ) (tokenRepay sdk.Coin, collateralLiquidate sdk.Coin, tokenReward sdk.Coin, err error) { repayDenom := requestedRepay.Denom - collateralDenom := types.ToUTokenDenom(rewardDenom) + collateralDenom := coin.ToUTokenDenom(rewardDenom) // get relevant liquidator, borrower, and module balances borrowerCollateral := k.GetBorrowerCollateral(ctx, targetAddr) diff --git a/x/leverage/keeper/migrations.go b/x/leverage/keeper/migrations.go index 576491804b..d645fdcf6e 100644 --- a/x/leverage/keeper/migrations.go +++ b/x/leverage/keeper/migrations.go @@ -2,6 +2,8 @@ package keeper import ( sdk "github.com/cosmos/cosmos-sdk/types" + + "github.com/umee-network/umee/v5/util/coin" "github.com/umee-network/umee/v5/x/leverage/types" ) @@ -21,7 +23,7 @@ func (m Migrator) MigrateBNB(ctx sdk.Context) (bool, error) { // Bad BNB token denom badDenom := "ibc/77BCD42E49E5B7E0FC6B269FEBF0185B15044F13F6F38CA285DF0AF883459F40" // Ensure zero supply of the token being removed from leverage registry - uSupply := m.keeper.GetUTokenSupply(ctx, types.ToUTokenDenom(badDenom)) + uSupply := m.keeper.GetUTokenSupply(ctx, coin.ToUTokenDenom(badDenom)) if !uSupply.IsZero() { ctx.Logger().Error("can't correctly migrate leverage with existing supply", "token", badDenom, "total_u_supply", uSupply) diff --git a/x/leverage/keeper/msg_server.go b/x/leverage/keeper/msg_server.go index ead00decda..26a584c9b0 100644 --- a/x/leverage/keeper/msg_server.go +++ b/x/leverage/keeper/msg_server.go @@ -104,7 +104,7 @@ func (s msgServer) MaxWithdraw( if err != nil { return nil, err } - if types.HasUTokenPrefix(msg.Denom) { + if coin.HasUTokenPrefix(msg.Denom) { return nil, types.ErrUToken } if _, err = s.keeper.GetTokenSettings(ctx, msg.Denom); err != nil { @@ -196,7 +196,7 @@ func (s msgServer) Collateralize( return nil, err } - if err := s.keeper.checkCollateralLiquidity(ctx, types.ToTokenDenom(msg.Asset.Denom)); err != nil { + if err := s.keeper.checkCollateralLiquidity(ctx, coin.StripUTokenDenom(msg.Asset.Denom)); err != nil { return nil, err } diff --git a/x/leverage/keeper/msg_server_test.go b/x/leverage/keeper/msg_server_test.go index 62931a5b46..112ca1bf08 100644 --- a/x/leverage/keeper/msg_server_test.go +++ b/x/leverage/keeper/msg_server_test.go @@ -482,7 +482,7 @@ func (s *IntegrationTestSuite) TestMsgWithdraw() { _, err := srv.Withdraw(ctx, msg) require.ErrorIs(err, tc.err, tc.msg) } else { - denom := types.ToTokenDenom(tc.uToken.Denom) + denom := coin.StripUTokenDenom(tc.uToken.Denom) // initial state iBalance := app.BankKeeper.GetAllBalances(ctx, tc.addr) @@ -951,7 +951,7 @@ func (s *IntegrationTestSuite) TestMsgCollateralize() { _, err := srv.Collateralize(ctx, msg) require.ErrorIs(err, tc.err, tc.msg) } else { - denom := types.ToTokenDenom(tc.uToken.Denom) + denom := coin.StripUTokenDenom(tc.uToken.Denom) // initial state iBalance := app.BankKeeper.GetAllBalances(ctx, tc.addr) @@ -1109,7 +1109,7 @@ func (s *IntegrationTestSuite) TestMsgDecollateralize() { _, err := srv.Decollateralize(ctx, msg) require.ErrorIs(err, tc.err, tc.msg) } else { - denom := types.ToTokenDenom(tc.uToken.Denom) + denom := coin.StripUTokenDenom(tc.uToken.Denom) // initial state iBalance := app.BankKeeper.GetAllBalances(ctx, tc.addr) @@ -2009,7 +2009,7 @@ func (s *IntegrationTestSuite) TestMsgLiquidate() { _, err := srv.Liquidate(ctx, msg) require.ErrorIs(err, tc.err, tc.msg) } else { - baseRewardDenom := types.ToTokenDenom(tc.expectedLiquidate.Denom) + baseRewardDenom := coin.StripUTokenDenom(tc.expectedLiquidate.Denom) // initial state (borrowed denom) biUTokenSupply := app.LeverageKeeper.GetAllUTokenSupply(ctx) @@ -2064,7 +2064,7 @@ func (s *IntegrationTestSuite) TestMsgLiquidate() { // verify liquidated denom uToken supply is unchanged if indirect liquidation, or reduced if direct expectedLiquidatedUTokenSupply := liUTokenSupply - if !types.HasUTokenPrefix(tc.rewardDenom) { + if !coin.HasUTokenPrefix(tc.rewardDenom) { expectedLiquidatedUTokenSupply = expectedLiquidatedUTokenSupply.Sub(tc.expectedLiquidate) } require.Equal(expectedLiquidatedUTokenSupply, lfUTokenSupply, "%s: %s", tc.msg, "uToken supply (liquidated denom") @@ -2261,7 +2261,7 @@ func (s *IntegrationTestSuite) TestMsgLeveragedLiquidate() { } if msg.RewardDenom == "" { if !biCollateral.IsZero() { - tc.rewardDenom = types.ToTokenDenom(biCollateral[0].Denom) + tc.rewardDenom = coin.StripUTokenDenom(biCollateral[0].Denom) } } diff --git a/x/leverage/keeper/oracle.go b/x/leverage/keeper/oracle.go index 7b27072b2e..4fa6d2166f 100644 --- a/x/leverage/keeper/oracle.go +++ b/x/leverage/keeper/oracle.go @@ -6,6 +6,7 @@ import ( "cosmossdk.io/errors" sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/umee-network/umee/v5/util/coin" "github.com/umee-network/umee/v5/util/sdkutil" "github.com/umee-network/umee/v5/x/leverage/types" oracletypes "github.com/umee-network/umee/v5/x/oracle/types" @@ -167,7 +168,7 @@ func (k Keeper) VisibleUTokensValue(ctx sdk.Context, uTokens sdk.Coins, mode typ tokens := sdk.NewCoins() for _, u := range uTokens { - t, err := k.ExchangeUToken(ctx, u) + t, err := k.ToToken(ctx, u) if err != nil { return sdk.ZeroDec(), err } @@ -196,7 +197,7 @@ func (k Keeper) TokenWithValue(ctx sdk.Context, denom string, value sdk.Dec, mod // Returns an error on invalid price or non-uToken denom. Rounds down, i.e. the // value of the uToken returned may be slightly less than the requested value. func (k Keeper) UTokenWithValue(ctx sdk.Context, denom string, value sdk.Dec, mode types.PriceMode) (sdk.Coin, error) { - base := types.ToTokenDenom(denom) + base := coin.StripUTokenDenom(denom) if base == "" { return sdk.Coin{}, types.ErrNotUToken.Wrap(denom) } diff --git a/x/leverage/keeper/reserves.go b/x/leverage/keeper/reserves.go index 29aaf30772..5803a03f42 100644 --- a/x/leverage/keeper/reserves.go +++ b/x/leverage/keeper/reserves.go @@ -3,6 +3,7 @@ package keeper import ( sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/umee-network/umee/v5/util/coin" "github.com/umee-network/umee/v5/util/sdkutil" "github.com/umee-network/umee/v5/x/leverage/types" ) @@ -15,15 +16,15 @@ import ( func (k Keeper) clearBlacklistedCollateral(ctx sdk.Context, borrowerAddr sdk.AccAddress) (bool, error) { collateral := k.GetBorrowerCollateral(ctx, borrowerAddr) hasCollateral := false - for _, coin := range collateral { - denom := types.ToTokenDenom(coin.Denom) + for _, c := range collateral { + denom := coin.StripUTokenDenom(c.Denom) token, err := k.GetTokenSettings(ctx, denom) if err != nil { return false, err } if token.Blacklist { // Decollateralize any blacklisted uTokens encountered - err := k.decollateralize(ctx, borrowerAddr, borrowerAddr, coin) + err := k.decollateralize(ctx, borrowerAddr, borrowerAddr, c) if err != nil { return false, err } diff --git a/x/leverage/keeper/supply.go b/x/leverage/keeper/supply.go index bb4cfc3b7d..6148830ef4 100644 --- a/x/leverage/keeper/supply.go +++ b/x/leverage/keeper/supply.go @@ -3,23 +3,24 @@ package keeper import ( sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/umee-network/umee/v5/util/coin" "github.com/umee-network/umee/v5/x/leverage/types" ) // GetSupplied returns an sdk.Coin representing how much of a given denom a // user has supplied, including interest accrued. func (k Keeper) GetSupplied(ctx sdk.Context, supplierAddr sdk.AccAddress, denom string) (sdk.Coin, error) { - if types.HasUTokenPrefix(denom) { + if coin.HasUTokenPrefix(denom) { return sdk.Coin{}, types.ErrUToken.Wrap(denom) } // sum wallet-held and collateral-enabled uTokens in the associated uToken denom - uDenom := types.ToUTokenDenom(denom) + uDenom := coin.ToUTokenDenom(denom) balance := k.bankKeeper.GetBalance(ctx, supplierAddr, uDenom) collateral := k.GetCollateral(ctx, supplierAddr, uDenom) // convert uTokens to tokens - return k.ExchangeUToken(ctx, balance.Add(collateral)) + return k.ToToken(ctx, balance.Add(collateral)) } // GetAllSupplied returns the total tokens supplied by a user, including @@ -31,26 +32,26 @@ func (k Keeper) GetAllSupplied(ctx sdk.Context, supplierAddr sdk.AccAddress) (sd // get all uTokens not set as collateral by filtering non-uTokens from supplier balance uTokens := sdk.Coins{} balance := k.bankKeeper.GetAllBalances(ctx, supplierAddr) - for _, coin := range balance { - if types.HasUTokenPrefix(coin.Denom) { - uTokens = uTokens.Add(coin) + for _, c := range balance { + if coin.HasUTokenPrefix(c.Denom) { + uTokens = uTokens.Add(c) } } // convert the sum of found uTokens to base tokens - return k.ExchangeUTokens(ctx, collateral.Add(uTokens...)) + return k.ToTokens(ctx, collateral.Add(uTokens...)) } // GetTotalSupply returns the total supplied by all suppliers in a given denom, // including any interest accrued. func (k Keeper) GetTotalSupply(ctx sdk.Context, denom string) (sdk.Coin, error) { - if types.HasUTokenPrefix(denom) { + if coin.HasUTokenPrefix(denom) { return sdk.Coin{}, types.ErrUToken.Wrap(denom) } // convert associated uToken's total supply to base tokens - uTokenDenom := types.ToUTokenDenom(denom) - return k.ExchangeUToken(ctx, k.GetUTokenSupply(ctx, uTokenDenom)) + uTokenDenom := coin.ToUTokenDenom(denom) + return k.ToToken(ctx, k.GetUTokenSupply(ctx, uTokenDenom)) } // checkMaxSupply returns the appropriate error if a token denom's diff --git a/x/leverage/keeper/token.go b/x/leverage/keeper/token.go index c04b2150cc..7d952e9dda 100644 --- a/x/leverage/keeper/token.go +++ b/x/leverage/keeper/token.go @@ -5,6 +5,7 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/umee-network/umee/v5/util/coin" "github.com/umee-network/umee/v5/util/store" "github.com/umee-network/umee/v5/x/leverage/types" ) @@ -15,7 +16,7 @@ func (k Keeper) CleanTokenRegistry(ctx sdk.Context) error { tokens := k.GetAllRegisteredTokens(ctx) for _, t := range tokens { if t.Blacklist { - uDenom := types.ToUTokenDenom(t.BaseDenom) + uDenom := coin.ToUTokenDenom(t.BaseDenom) uSupply := k.GetUTokenSupply(ctx, uDenom) if uSupply.IsZero() { err := k.deleteTokenSettings(ctx, t) diff --git a/x/leverage/keeper/validate.go b/x/leverage/keeper/validate.go index fb8bd4e0c5..ec99cb6499 100644 --- a/x/leverage/keeper/validate.go +++ b/x/leverage/keeper/validate.go @@ -3,13 +3,14 @@ package keeper import ( sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/umee-network/umee/v5/util/coin" "github.com/umee-network/umee/v5/x/leverage/types" ) // validateAcceptedDenom validates an sdk.Coin and ensures it is a registered Token // with Blacklisted == false func (k Keeper) validateAcceptedDenom(ctx sdk.Context, denom string) error { - if types.HasUTokenPrefix(denom) { + if coin.HasUTokenPrefix(denom) { return types.ErrUToken.Wrap(denom) } token, err := k.GetTokenSettings(ctx, denom) @@ -58,7 +59,7 @@ func (k Keeper) validateCollateralize(ctx sdk.Context, collateral sdk.Coin) erro if err := validateUToken(collateral); err != nil { return err } - token, err := k.GetTokenSettings(ctx, types.ToTokenDenom(collateral.Denom)) + token, err := k.GetTokenSettings(ctx, coin.StripUTokenDenom(collateral.Denom)) if err != nil { return err } @@ -69,23 +70,23 @@ func (k Keeper) validateCollateralize(ctx sdk.Context, collateral sdk.Coin) erro } // validateBaseToken validates an sdk.Coin and ensures its Denom is not a uToken. -func validateBaseToken(coin sdk.Coin) error { - if err := coin.Validate(); err != nil { +func validateBaseToken(c sdk.Coin) error { + if err := c.Validate(); err != nil { return err } - if types.HasUTokenPrefix(coin.Denom) { - return types.ErrUToken.Wrap(coin.Denom) + if coin.HasUTokenPrefix(c.Denom) { + return types.ErrUToken.Wrap(c.Denom) } return nil } // validateUToken validates an sdk.Coin and ensures its Denom is a uToken. -func validateUToken(coin sdk.Coin) error { - if err := coin.Validate(); err != nil { +func validateUToken(c sdk.Coin) error { + if err := c.Validate(); err != nil { return err } - if !types.HasUTokenPrefix(coin.Denom) { - return types.ErrNotUToken.Wrap(coin.Denom) + if !coin.HasUTokenPrefix(c.Denom) { + return types.ErrNotUToken.Wrap(c.Denom) } return nil } diff --git a/x/leverage/simulation/operations.go b/x/leverage/simulation/operations.go index 9fc6651e4b..788b846371 100644 --- a/x/leverage/simulation/operations.go +++ b/x/leverage/simulation/operations.go @@ -12,6 +12,7 @@ import ( "github.com/cosmos/cosmos-sdk/x/simulation" appparams "github.com/umee-network/umee/v5/app/params" + "github.com/umee-network/umee/v5/util/coin" umeesim "github.com/umee-network/umee/v5/util/sim" "github.com/umee-network/umee/v5/x/leverage/keeper" "github.com/umee-network/umee/v5/x/leverage/types" @@ -261,9 +262,9 @@ func randomCoin(r *rand.Rand, coins sdk.Coins) sdk.Coin { // getSpendableTokens returns all non-uTokens from an account's spendable coins. func getSpendableTokens(ctx sdk.Context, addr sdk.AccAddress, bk types.BankKeeper) sdk.Coins { tokens := sdk.NewCoins() - for _, coin := range bk.SpendableCoins(ctx, addr) { - if !types.HasUTokenPrefix(coin.Denom) { - tokens = tokens.Add(coin) + for _, c := range bk.SpendableCoins(ctx, addr) { + if !coin.HasUTokenPrefix(c.Denom) { + tokens = tokens.Add(c) } } @@ -273,9 +274,9 @@ func getSpendableTokens(ctx sdk.Context, addr sdk.AccAddress, bk types.BankKeepe // getSpendableUTokens returns all uTokens from an account's spendable coins. func getSpendableUTokens(ctx sdk.Context, addr sdk.AccAddress, bk types.BankKeeper) sdk.Coins { uTokens := sdk.NewCoins() - for _, coin := range bk.SpendableCoins(ctx, addr) { - if types.HasUTokenPrefix(coin.Denom) { - uTokens = uTokens.Add(coin) + for _, c := range bk.SpendableCoins(ctx, addr) { + if coin.HasUTokenPrefix(c.Denom) { + uTokens = uTokens.Add(c) } } @@ -418,7 +419,7 @@ func randomLiquidateFields( return liquidator, borrower, sdk.Coin{}, "", true } - rewardDenom = types.ToTokenDenom(randomCoin(r, collateral).Denom) + rewardDenom = coin.StripUTokenDenom(randomCoin(r, collateral).Denom) return liquidator, borrower, randomCoin(r, borrowed), rewardDenom, false } diff --git a/x/leverage/types/token.go b/x/leverage/types/token.go index 011d2f0207..db84796b3d 100644 --- a/x/leverage/types/token.go +++ b/x/leverage/types/token.go @@ -2,61 +2,27 @@ package types import ( "fmt" - "strings" sdk "github.com/cosmos/cosmos-sdk/types" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" appparams "github.com/umee-network/umee/v5/app/params" -) - -const ( - // UTokenPrefix defines the uToken denomination prefix for all uToken types. - UTokenPrefix = "u/" + "github.com/umee-network/umee/v5/util/coin" ) var halfDec = sdk.MustNewDecFromStr("0.5") -// HasUTokenPrefix detects the uToken prefix on a denom. -func HasUTokenPrefix(denom string) bool { - return strings.HasPrefix(denom, UTokenPrefix) -} - -// ToUTokenDenom adds the uToken prefix to a denom. Returns an empty string -// instead if the prefix was already present. -func ToUTokenDenom(denom string) string { - if HasUTokenPrefix(denom) { - return "" - } - return UTokenPrefix + denom -} - // ValidateBaseDenom validates a denom and ensures it is not a uToken. func ValidateBaseDenom(denom string) error { if err := sdk.ValidateDenom(denom); err != nil { return err } - if HasUTokenPrefix(denom) { + if coin.HasUTokenPrefix(denom) { return ErrUToken.Wrap(denom) } return nil } -// ToTokenDenom strips the uToken prefix from a denom, or returns an empty -// string if it was not present. Also returns an empty string if the prefix -// was repeated multiple times. -func ToTokenDenom(denom string) string { - if !HasUTokenPrefix(denom) { - return "" - } - s := strings.TrimPrefix(denom, UTokenPrefix) - if HasUTokenPrefix(s) { - // denom started with "u/u/" - return "" - } - return s -} - // Validate performs validation on an Token type returning an error if the Token // is invalid. func (t Token) Validate() error { diff --git a/x/leverage/types/token_test.go b/x/leverage/types/token_test.go index 40e369f9c7..0048ddad29 100644 --- a/x/leverage/types/token_test.go +++ b/x/leverage/types/token_test.go @@ -9,36 +9,6 @@ import ( "github.com/umee-network/umee/v5/x/leverage/types" ) -func TestToTokenDenom(t *testing.T) { - // Turns uToken denoms into base tokens - assert.Equal(t, "uumee", types.ToTokenDenom("u/uumee")) - assert.Equal(t, "ibc/abcd", types.ToTokenDenom("u/ibc/abcd")) - - // Empty return for base tokens - assert.Equal(t, "", types.ToTokenDenom("uumee")) - assert.Equal(t, "", types.ToTokenDenom("ibc/abcd")) - - // Empty return on repreated prefix - assert.Equal(t, "", types.ToTokenDenom("u/u/abcd")) - - // Edge cases - assert.Equal(t, "", types.ToTokenDenom("u/")) - assert.Equal(t, "", types.ToTokenDenom("")) -} - -func TestToUTokenDenom(t *testing.T) { - // Turns base token denoms into base uTokens - assert.Equal(t, "u/uumee", types.ToUTokenDenom("uumee")) - assert.Equal(t, "u/ibc/abcd", types.ToUTokenDenom("ibc/abcd")) - - // Empty return for uTokens - assert.Equal(t, "", types.ToUTokenDenom("u/uumee")) - assert.Equal(t, "", types.ToUTokenDenom("u/ibc/abcd")) - - // Edge cases - assert.Equal(t, "u/", types.ToUTokenDenom("")) -} - func validToken() types.Token { return types.Token{ BaseDenom: "uumee", diff --git a/x/metoken/expected_keepers.go b/x/metoken/expected_keepers.go index 0db126576b..1635f98af6 100644 --- a/x/metoken/expected_keepers.go +++ b/x/metoken/expected_keepers.go @@ -22,8 +22,8 @@ type BankKeeper interface { // LeverageKeeper interface for interacting with x/leverage type LeverageKeeper interface { GetTokenSettings(ctx sdk.Context, denom string) (ltypes.Token, error) - ExchangeToken(ctx sdk.Context, token sdk.Coin) (sdk.Coin, error) - ExchangeUToken(ctx sdk.Context, uToken sdk.Coin) (sdk.Coin, error) + ToUToken(ctx sdk.Context, token sdk.Coin) (sdk.Coin, error) + ToToken(ctx sdk.Context, uToken sdk.Coin) (sdk.Coin, error) SupplyFromModule(ctx sdk.Context, fromModule string, coin sdk.Coin) (sdk.Coin, bool, error) WithdrawToModule(ctx sdk.Context, toModule string, uToken sdk.Coin) (sdk.Coin, bool, error) ModuleMaxWithdraw(ctx sdk.Context, spendableUTokens sdk.Coin) (sdkmath.Int, error) diff --git a/x/metoken/keeper/intest/grpc_query_test.go b/x/metoken/keeper/intest/grpc_query_test.go index 754d5d48b1..0792ae06eb 100644 --- a/x/metoken/keeper/intest/grpc_query_test.go +++ b/x/metoken/keeper/intest/grpc_query_test.go @@ -1,4 +1,4 @@ -package keeper_test +package intest import ( "testing" diff --git a/x/metoken/keeper/intest/interest_test.go b/x/metoken/keeper/intest/interest_test.go index d0247d2ac1..fd60ea399d 100644 --- a/x/metoken/keeper/intest/interest_test.go +++ b/x/metoken/keeper/intest/interest_test.go @@ -1,4 +1,4 @@ -package keeper_test +package intest import ( "testing" @@ -75,7 +75,7 @@ func TestInterestClaiming(t *testing.T) { ) require.NoError(t, err) - uTokens, err := app.LeverageKeeper.ExchangeToken(ctx, borrowerSupply) + uTokens, err := app.LeverageKeeper.ToUToken(ctx, borrowerSupply) require.NoError(t, err) err = app.LeverageKeeper.Collateralize(ctx, borrower, uTokens) diff --git a/x/metoken/keeper/intest/keeper_test.go b/x/metoken/keeper/intest/keeper_test.go index e706e3a15c..63fba38b4d 100644 --- a/x/metoken/keeper/intest/keeper_test.go +++ b/x/metoken/keeper/intest/keeper_test.go @@ -1,10 +1,11 @@ -package keeper_test +package intest import ( "fmt" "testing" "time" + "github.com/golang/mock/gomock" "github.com/stretchr/testify/require" sdkmath "cosmossdk.io/math" @@ -42,8 +43,15 @@ func initTestSuite(t *testing.T, registry []metoken.Index, balances []metoken.In }, ).WithBlockTime(time.Now()) - oracleMock := mocks.NewMockOracleKeeper() - oracleMock.AllMedianPricesFunc.SetDefaultHook(mocks.ValidPricesFunc()) + ctrl := gomock.NewController(t) + defer ctrl.Finish() + + oracleMock := mocks.NewMockOracleKeeper(ctrl) + oracleMock. + EXPECT(). + AllMedianPrices(gomock.Any()). + Return(mocks.ValidPrices()). + AnyTimes() kb := keeper.NewKeeperBuilder( app.AppCodec(), diff --git a/x/metoken/keeper/intest/msg_server_test.go b/x/metoken/keeper/intest/msg_server_test.go index 7e62b55151..0c12a65a41 100644 --- a/x/metoken/keeper/intest/msg_server_test.go +++ b/x/metoken/keeper/intest/msg_server_test.go @@ -1,8 +1,9 @@ -package keeper_test +package intest import ( "testing" + "github.com/golang/mock/gomock" "github.com/stretchr/testify/require" "gotest.tools/v3/assert" @@ -558,40 +559,38 @@ func TestMsgServer_Swap_Depegging(t *testing.T) { } // after initial swaps IST price is dropped to 0.64 USD - oracleMock := mocks.NewMockOracleKeeper() - oracleMock.AllMedianPricesFunc.SetDefaultHook( - func(ctx sdk.Context) otypes.Prices { - prices := otypes.Prices{} - median := otypes.Price{ - ExchangeRateTuple: otypes.NewExchangeRateTuple( - mocks.USDTSymbolDenom, - mocks.USDTPrice, - ), - BlockNum: uint64(1), - } - prices = append(prices, median) - - median = otypes.Price{ - ExchangeRateTuple: otypes.NewExchangeRateTuple( - mocks.USDCSymbolDenom, - mocks.USDCPrice, - ), - BlockNum: uint64(1), - } - prices = append(prices, median) - - median = otypes.Price{ - ExchangeRateTuple: otypes.NewExchangeRateTuple( - mocks.ISTSymbolDenom, - sdk.MustNewDecFromStr("0.64"), - ), - BlockNum: uint64(1), - } - prices = append(prices, median) - - return prices + + ctrl := gomock.NewController(t) + defer ctrl.Finish() + + initialPrices := otypes.Prices{ + otypes.Price{ + ExchangeRateTuple: otypes.NewExchangeRateTuple( + mocks.USDTSymbolDenom, + mocks.USDTPrice, + ), + BlockNum: uint64(1), + }, otypes.Price{ + ExchangeRateTuple: otypes.NewExchangeRateTuple( + mocks.USDCSymbolDenom, + mocks.USDCPrice, + ), + BlockNum: uint64(1), + }, otypes.Price{ + ExchangeRateTuple: otypes.NewExchangeRateTuple( + mocks.ISTSymbolDenom, + sdk.MustNewDecFromStr("0.64"), + ), + BlockNum: uint64(1), }, - ) + } + + oracleMock := mocks.NewMockOracleKeeper(ctrl) + oracleMock. + EXPECT(). + AllMedianPrices(gomock.Any()). + Return(initialPrices). + AnyTimes() kb := keeper.NewKeeperBuilder( app.AppCodec(), @@ -683,7 +682,11 @@ func TestMsgServer_Swap_Depegging(t *testing.T) { } // after some swaps with depegged price, all is back to normal - oracleMock.AllMedianPricesFunc.SetDefaultHook(mocks.ValidPricesFunc()) + oracleMock. + EXPECT(). + AllMedianPrices(gomock.Any()). + Return(mocks.ValidPrices()). + AnyTimes() kb = keeper.NewKeeperBuilder( app.AppCodec(), @@ -1252,40 +1255,37 @@ func TestMsgServer_Redeem_Depegging(t *testing.T) { } // after initial swaps USDT price is dropped to 0.73 USD - oracleMock := mocks.NewMockOracleKeeper() - oracleMock.AllMedianPricesFunc.SetDefaultHook( - func(ctx sdk.Context) otypes.Prices { - prices := otypes.Prices{} - median := otypes.Price{ - ExchangeRateTuple: otypes.NewExchangeRateTuple( - mocks.USDTSymbolDenom, - sdk.MustNewDecFromStr("0.73"), - ), - BlockNum: uint64(1), - } - prices = append(prices, median) - - median = otypes.Price{ - ExchangeRateTuple: otypes.NewExchangeRateTuple( - mocks.USDCSymbolDenom, - mocks.USDCPrice, - ), - BlockNum: uint64(1), - } - prices = append(prices, median) - - median = otypes.Price{ - ExchangeRateTuple: otypes.NewExchangeRateTuple( - mocks.ISTSymbolDenom, - mocks.ISTPrice, - ), - BlockNum: uint64(1), - } - prices = append(prices, median) - - return prices + + initialPrices := otypes.Prices{ + otypes.Price{ + ExchangeRateTuple: otypes.NewExchangeRateTuple( + mocks.USDTSymbolDenom, + sdk.MustNewDecFromStr("0.73"), + ), + BlockNum: uint64(1), + }, otypes.Price{ + ExchangeRateTuple: otypes.NewExchangeRateTuple( + mocks.USDCSymbolDenom, + mocks.USDCPrice, + ), + BlockNum: uint64(1), + }, otypes.Price{ + ExchangeRateTuple: otypes.NewExchangeRateTuple( + mocks.ISTSymbolDenom, + mocks.ISTPrice, + ), + BlockNum: uint64(1), }, - ) + } + ctrl := gomock.NewController(t) + defer ctrl.Finish() + + oracleMock := mocks.NewMockOracleKeeper(ctrl) + oracleMock. + EXPECT(). + AllMedianPrices(gomock.Any()). + Return(initialPrices). + AnyTimes() kb := keeper.NewKeeperBuilder( app.AppCodec(), @@ -1377,7 +1377,11 @@ func TestMsgServer_Redeem_Depegging(t *testing.T) { } // after some redemptions with depegged price, all is back to normal - oracleMock.AllMedianPricesFunc.SetDefaultHook(mocks.ValidPricesFunc()) + oracleMock. + EXPECT(). + AllMedianPrices(gomock.Any()). + Return(mocks.ValidPrices()). + AnyTimes() kb = keeper.NewKeeperBuilder( app.AppCodec(), diff --git a/x/metoken/keeper/intest/reserves_test.go b/x/metoken/keeper/intest/reserves_test.go index 780623acdc..1daf4720d3 100644 --- a/x/metoken/keeper/intest/reserves_test.go +++ b/x/metoken/keeper/intest/reserves_test.go @@ -1,4 +1,4 @@ -package keeper_test +package intest import ( "testing" diff --git a/x/metoken/keeper/mocks_test.go b/x/metoken/keeper/mocks_test.go index 0d3f18fdb4..dedd940e5e 100644 --- a/x/metoken/keeper/mocks_test.go +++ b/x/metoken/keeper/mocks_test.go @@ -33,11 +33,11 @@ func (l Leverage) GetTokenSettings(_ sdk.Context, denom string) (ltypes.Token, e return ts, nil } -func (l Leverage) ExchangeToken(_ sdk.Context, _ sdk.Coin) (sdk.Coin, error) { +func (l Leverage) ToUToken(_ sdk.Context, _ sdk.Coin) (sdk.Coin, error) { panic("not implemented") } -func (l Leverage) ExchangeUToken(_ sdk.Context, _ sdk.Coin) (sdk.Coin, error) { +func (l Leverage) ToToken(_ sdk.Context, _ sdk.Coin) (sdk.Coin, error) { panic("not implemented") } diff --git a/x/metoken/keeper/redeem.go b/x/metoken/keeper/redeem.go index a56bd7ee55..c77ee8fe82 100644 --- a/x/metoken/keeper/redeem.go +++ b/x/metoken/keeper/redeem.go @@ -150,7 +150,7 @@ func (k Keeper) redeem(userAddr sdk.AccAddress, meToken sdk.Coin, assetDenom str // - tokensWithdrawn: the amount tokens withdrawn from x/leverage. // - error func (k Keeper) withdrawFromLeverage(tokensToWithdraw sdk.Coin) (sdk.Coin, error) { - uTokensFromLeverage, err := k.leverageKeeper.ExchangeToken(*k.ctx, tokensToWithdraw) + uTokensFromLeverage, err := k.leverageKeeper.ToUToken(*k.ctx, tokensToWithdraw) if err != nil { return sdk.Coin{}, errors.Wrap(err, true) } diff --git a/x/metoken/mocks/keepers.go b/x/metoken/mocks/keepers.go index 8db05124a0..08dc92019d 100644 --- a/x/metoken/mocks/keepers.go +++ b/x/metoken/mocks/keepers.go @@ -1,1744 +1,276 @@ -// Code generated by go-mockgen 1.3.7; DO NOT EDIT. +// Code generated by MockGen. DO NOT EDIT. +// Source: ./x/metoken/expected_keepers.go +// Package mocks is a generated GoMock package. package mocks import ( - "sync" + reflect "reflect" math "cosmossdk.io/math" types "github.com/cosmos/cosmos-sdk/types" - types1 "github.com/umee-network/umee/v5/x/leverage/types" - metoken "github.com/umee-network/umee/v5/x/metoken" - types2 "github.com/umee-network/umee/v5/x/oracle/types" + gomock "github.com/golang/mock/gomock" + types0 "github.com/umee-network/umee/v5/x/leverage/types" + types1 "github.com/umee-network/umee/v5/x/oracle/types" ) -// MockBankKeeper is a mock implementation of the BankKeeper interface (from -// the package github.com/umee-network/umee/v5/x/metoken) used for unit -// testing. +// MockBankKeeper is a mock of BankKeeper interface. type MockBankKeeper struct { - // BurnCoinsFunc is an instance of a mock function object controlling - // the behavior of the method BurnCoins. - BurnCoinsFunc *BankKeeperBurnCoinsFunc - // MintCoinsFunc is an instance of a mock function object controlling - // the behavior of the method MintCoins. - MintCoinsFunc *BankKeeperMintCoinsFunc - // SendCoinsFromAccountToModuleFunc is an instance of a mock function - // object controlling the behavior of the method - // SendCoinsFromAccountToModule. - SendCoinsFromAccountToModuleFunc *BankKeeperSendCoinsFromAccountToModuleFunc - // SendCoinsFromModuleToAccountFunc is an instance of a mock function - // object controlling the behavior of the method - // SendCoinsFromModuleToAccount. - SendCoinsFromModuleToAccountFunc *BankKeeperSendCoinsFromModuleToAccountFunc + ctrl *gomock.Controller + recorder *MockBankKeeperMockRecorder } -// NewMockBankKeeper creates a new mock of the BankKeeper interface. All -// methods return zero values for all results, unless overwritten. -func NewMockBankKeeper() *MockBankKeeper { - return &MockBankKeeper{ - BurnCoinsFunc: &BankKeeperBurnCoinsFunc{ - defaultHook: func(types.Context, string, types.Coins) (r0 error) { - return - }, - }, - MintCoinsFunc: &BankKeeperMintCoinsFunc{ - defaultHook: func(types.Context, string, types.Coins) (r0 error) { - return - }, - }, - SendCoinsFromAccountToModuleFunc: &BankKeeperSendCoinsFromAccountToModuleFunc{ - defaultHook: func(types.Context, types.AccAddress, string, types.Coins) (r0 error) { - return - }, - }, - SendCoinsFromModuleToAccountFunc: &BankKeeperSendCoinsFromModuleToAccountFunc{ - defaultHook: func(types.Context, string, types.AccAddress, types.Coins) (r0 error) { - return - }, - }, - } +// MockBankKeeperMockRecorder is the mock recorder for MockBankKeeper. +type MockBankKeeperMockRecorder struct { + mock *MockBankKeeper } -// NewStrictMockBankKeeper creates a new mock of the BankKeeper interface. -// All methods panic on invocation, unless overwritten. -func NewStrictMockBankKeeper() *MockBankKeeper { - return &MockBankKeeper{ - BurnCoinsFunc: &BankKeeperBurnCoinsFunc{ - defaultHook: func(types.Context, string, types.Coins) error { - panic("unexpected invocation of MockBankKeeper.BurnCoins") - }, - }, - MintCoinsFunc: &BankKeeperMintCoinsFunc{ - defaultHook: func(types.Context, string, types.Coins) error { - panic("unexpected invocation of MockBankKeeper.MintCoins") - }, - }, - SendCoinsFromAccountToModuleFunc: &BankKeeperSendCoinsFromAccountToModuleFunc{ - defaultHook: func(types.Context, types.AccAddress, string, types.Coins) error { - panic("unexpected invocation of MockBankKeeper.SendCoinsFromAccountToModule") - }, - }, - SendCoinsFromModuleToAccountFunc: &BankKeeperSendCoinsFromModuleToAccountFunc{ - defaultHook: func(types.Context, string, types.AccAddress, types.Coins) error { - panic("unexpected invocation of MockBankKeeper.SendCoinsFromModuleToAccount") - }, - }, - } +// NewMockBankKeeper creates a new mock instance. +func NewMockBankKeeper(ctrl *gomock.Controller) *MockBankKeeper { + mock := &MockBankKeeper{ctrl: ctrl} + mock.recorder = &MockBankKeeperMockRecorder{mock} + return mock } -// NewMockBankKeeperFrom creates a new mock of the MockBankKeeper interface. -// All methods delegate to the given implementation, unless overwritten. -func NewMockBankKeeperFrom(i metoken.BankKeeper) *MockBankKeeper { - return &MockBankKeeper{ - BurnCoinsFunc: &BankKeeperBurnCoinsFunc{ - defaultHook: i.BurnCoins, - }, - MintCoinsFunc: &BankKeeperMintCoinsFunc{ - defaultHook: i.MintCoins, - }, - SendCoinsFromAccountToModuleFunc: &BankKeeperSendCoinsFromAccountToModuleFunc{ - defaultHook: i.SendCoinsFromAccountToModule, - }, - SendCoinsFromModuleToAccountFunc: &BankKeeperSendCoinsFromModuleToAccountFunc{ - defaultHook: i.SendCoinsFromModuleToAccount, - }, - } +// EXPECT returns an object that allows the caller to indicate expected use. +func (m *MockBankKeeper) EXPECT() *MockBankKeeperMockRecorder { + return m.recorder } -// BankKeeperBurnCoinsFunc describes the behavior when the BurnCoins method -// of the parent MockBankKeeper instance is invoked. -type BankKeeperBurnCoinsFunc struct { - defaultHook func(types.Context, string, types.Coins) error - hooks []func(types.Context, string, types.Coins) error - history []BankKeeperBurnCoinsFuncCall - mutex sync.Mutex +// BurnCoins mocks base method. +func (m *MockBankKeeper) BurnCoins(ctx types.Context, moduleName string, amounts types.Coins) error { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "BurnCoins", ctx, moduleName, amounts) + ret0, _ := ret[0].(error) + return ret0 } -// BurnCoins delegates to the next hook function in the queue and stores the -// parameter and result values of this invocation. -func (m *MockBankKeeper) BurnCoins(v0 types.Context, v1 string, v2 types.Coins) error { - r0 := m.BurnCoinsFunc.nextHook()(v0, v1, v2) - m.BurnCoinsFunc.appendCall(BankKeeperBurnCoinsFuncCall{v0, v1, v2, r0}) - return r0 +// BurnCoins indicates an expected call of BurnCoins. +func (mr *MockBankKeeperMockRecorder) BurnCoins(ctx, moduleName, amounts interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "BurnCoins", reflect.TypeOf((*MockBankKeeper)(nil).BurnCoins), ctx, moduleName, amounts) } -// SetDefaultHook sets function that is called when the BurnCoins method of -// the parent MockBankKeeper instance is invoked and the hook queue is -// empty. -func (f *BankKeeperBurnCoinsFunc) SetDefaultHook(hook func(types.Context, string, types.Coins) error) { - f.defaultHook = hook +// MintCoins mocks base method. +func (m *MockBankKeeper) MintCoins(ctx types.Context, moduleName string, amounts types.Coins) error { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "MintCoins", ctx, moduleName, amounts) + ret0, _ := ret[0].(error) + return ret0 } -// PushHook adds a function to the end of hook queue. Each invocation of the -// BurnCoins method of the parent MockBankKeeper instance invokes the hook -// at the front of the queue and discards it. After the queue is empty, the -// default hook function is invoked for any future action. -func (f *BankKeeperBurnCoinsFunc) PushHook(hook func(types.Context, string, types.Coins) error) { - f.mutex.Lock() - f.hooks = append(f.hooks, hook) - f.mutex.Unlock() +// MintCoins indicates an expected call of MintCoins. +func (mr *MockBankKeeperMockRecorder) MintCoins(ctx, moduleName, amounts interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "MintCoins", reflect.TypeOf((*MockBankKeeper)(nil).MintCoins), ctx, moduleName, amounts) } -// SetDefaultReturn calls SetDefaultHook with a function that returns the -// given values. -func (f *BankKeeperBurnCoinsFunc) SetDefaultReturn(r0 error) { - f.SetDefaultHook(func(types.Context, string, types.Coins) error { - return r0 - }) +// SendCoinsFromAccountToModule mocks base method. +func (m *MockBankKeeper) SendCoinsFromAccountToModule(ctx types.Context, senderAddr types.AccAddress, recipientModule string, amt types.Coins) error { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "SendCoinsFromAccountToModule", ctx, senderAddr, recipientModule, amt) + ret0, _ := ret[0].(error) + return ret0 } -// PushReturn calls PushHook with a function that returns the given values. -func (f *BankKeeperBurnCoinsFunc) PushReturn(r0 error) { - f.PushHook(func(types.Context, string, types.Coins) error { - return r0 - }) +// SendCoinsFromAccountToModule indicates an expected call of SendCoinsFromAccountToModule. +func (mr *MockBankKeeperMockRecorder) SendCoinsFromAccountToModule(ctx, senderAddr, recipientModule, amt interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "SendCoinsFromAccountToModule", reflect.TypeOf((*MockBankKeeper)(nil).SendCoinsFromAccountToModule), ctx, senderAddr, recipientModule, amt) } -func (f *BankKeeperBurnCoinsFunc) nextHook() func(types.Context, string, types.Coins) error { - f.mutex.Lock() - defer f.mutex.Unlock() - - if len(f.hooks) == 0 { - return f.defaultHook - } - - hook := f.hooks[0] - f.hooks = f.hooks[1:] - return hook -} - -func (f *BankKeeperBurnCoinsFunc) appendCall(r0 BankKeeperBurnCoinsFuncCall) { - f.mutex.Lock() - f.history = append(f.history, r0) - f.mutex.Unlock() -} - -// History returns a sequence of BankKeeperBurnCoinsFuncCall objects -// describing the invocations of this function. -func (f *BankKeeperBurnCoinsFunc) History() []BankKeeperBurnCoinsFuncCall { - f.mutex.Lock() - history := make([]BankKeeperBurnCoinsFuncCall, len(f.history)) - copy(history, f.history) - f.mutex.Unlock() - - return history -} - -// BankKeeperBurnCoinsFuncCall is an object that describes an invocation of -// method BurnCoins on an instance of MockBankKeeper. -type BankKeeperBurnCoinsFuncCall struct { - // Arg0 is the value of the 1st argument passed to this method - // invocation. - Arg0 types.Context - // Arg1 is the value of the 2nd argument passed to this method - // invocation. - Arg1 string - // Arg2 is the value of the 3rd argument passed to this method - // invocation. - Arg2 types.Coins - // Result0 is the value of the 1st result returned from this method - // invocation. - Result0 error -} - -// Args returns an interface slice containing the arguments of this -// invocation. -func (c BankKeeperBurnCoinsFuncCall) Args() []interface{} { - return []interface{}{c.Arg0, c.Arg1, c.Arg2} -} - -// Results returns an interface slice containing the results of this -// invocation. -func (c BankKeeperBurnCoinsFuncCall) Results() []interface{} { - return []interface{}{c.Result0} -} - -// BankKeeperMintCoinsFunc describes the behavior when the MintCoins method -// of the parent MockBankKeeper instance is invoked. -type BankKeeperMintCoinsFunc struct { - defaultHook func(types.Context, string, types.Coins) error - hooks []func(types.Context, string, types.Coins) error - history []BankKeeperMintCoinsFuncCall - mutex sync.Mutex -} - -// MintCoins delegates to the next hook function in the queue and stores the -// parameter and result values of this invocation. -func (m *MockBankKeeper) MintCoins(v0 types.Context, v1 string, v2 types.Coins) error { - r0 := m.MintCoinsFunc.nextHook()(v0, v1, v2) - m.MintCoinsFunc.appendCall(BankKeeperMintCoinsFuncCall{v0, v1, v2, r0}) - return r0 -} - -// SetDefaultHook sets function that is called when the MintCoins method of -// the parent MockBankKeeper instance is invoked and the hook queue is -// empty. -func (f *BankKeeperMintCoinsFunc) SetDefaultHook(hook func(types.Context, string, types.Coins) error) { - f.defaultHook = hook -} - -// PushHook adds a function to the end of hook queue. Each invocation of the -// MintCoins method of the parent MockBankKeeper instance invokes the hook -// at the front of the queue and discards it. After the queue is empty, the -// default hook function is invoked for any future action. -func (f *BankKeeperMintCoinsFunc) PushHook(hook func(types.Context, string, types.Coins) error) { - f.mutex.Lock() - f.hooks = append(f.hooks, hook) - f.mutex.Unlock() -} - -// SetDefaultReturn calls SetDefaultHook with a function that returns the -// given values. -func (f *BankKeeperMintCoinsFunc) SetDefaultReturn(r0 error) { - f.SetDefaultHook(func(types.Context, string, types.Coins) error { - return r0 - }) -} - -// PushReturn calls PushHook with a function that returns the given values. -func (f *BankKeeperMintCoinsFunc) PushReturn(r0 error) { - f.PushHook(func(types.Context, string, types.Coins) error { - return r0 - }) -} - -func (f *BankKeeperMintCoinsFunc) nextHook() func(types.Context, string, types.Coins) error { - f.mutex.Lock() - defer f.mutex.Unlock() - - if len(f.hooks) == 0 { - return f.defaultHook - } - - hook := f.hooks[0] - f.hooks = f.hooks[1:] - return hook -} - -func (f *BankKeeperMintCoinsFunc) appendCall(r0 BankKeeperMintCoinsFuncCall) { - f.mutex.Lock() - f.history = append(f.history, r0) - f.mutex.Unlock() -} - -// History returns a sequence of BankKeeperMintCoinsFuncCall objects -// describing the invocations of this function. -func (f *BankKeeperMintCoinsFunc) History() []BankKeeperMintCoinsFuncCall { - f.mutex.Lock() - history := make([]BankKeeperMintCoinsFuncCall, len(f.history)) - copy(history, f.history) - f.mutex.Unlock() - - return history -} - -// BankKeeperMintCoinsFuncCall is an object that describes an invocation of -// method MintCoins on an instance of MockBankKeeper. -type BankKeeperMintCoinsFuncCall struct { - // Arg0 is the value of the 1st argument passed to this method - // invocation. - Arg0 types.Context - // Arg1 is the value of the 2nd argument passed to this method - // invocation. - Arg1 string - // Arg2 is the value of the 3rd argument passed to this method - // invocation. - Arg2 types.Coins - // Result0 is the value of the 1st result returned from this method - // invocation. - Result0 error -} - -// Args returns an interface slice containing the arguments of this -// invocation. -func (c BankKeeperMintCoinsFuncCall) Args() []interface{} { - return []interface{}{c.Arg0, c.Arg1, c.Arg2} -} - -// Results returns an interface slice containing the results of this -// invocation. -func (c BankKeeperMintCoinsFuncCall) Results() []interface{} { - return []interface{}{c.Result0} -} - -// BankKeeperSendCoinsFromAccountToModuleFunc describes the behavior when -// the SendCoinsFromAccountToModule method of the parent MockBankKeeper -// instance is invoked. -type BankKeeperSendCoinsFromAccountToModuleFunc struct { - defaultHook func(types.Context, types.AccAddress, string, types.Coins) error - hooks []func(types.Context, types.AccAddress, string, types.Coins) error - history []BankKeeperSendCoinsFromAccountToModuleFuncCall - mutex sync.Mutex -} - -// SendCoinsFromAccountToModule delegates to the next hook function in the -// queue and stores the parameter and result values of this invocation. -func (m *MockBankKeeper) SendCoinsFromAccountToModule(v0 types.Context, v1 types.AccAddress, v2 string, v3 types.Coins) error { - r0 := m.SendCoinsFromAccountToModuleFunc.nextHook()(v0, v1, v2, v3) - m.SendCoinsFromAccountToModuleFunc.appendCall(BankKeeperSendCoinsFromAccountToModuleFuncCall{v0, v1, v2, v3, r0}) - return r0 -} - -// SetDefaultHook sets function that is called when the -// SendCoinsFromAccountToModule method of the parent MockBankKeeper instance -// is invoked and the hook queue is empty. -func (f *BankKeeperSendCoinsFromAccountToModuleFunc) SetDefaultHook(hook func(types.Context, types.AccAddress, string, types.Coins) error) { - f.defaultHook = hook -} - -// PushHook adds a function to the end of hook queue. Each invocation of the -// SendCoinsFromAccountToModule method of the parent MockBankKeeper instance -// invokes the hook at the front of the queue and discards it. After the -// queue is empty, the default hook function is invoked for any future -// action. -func (f *BankKeeperSendCoinsFromAccountToModuleFunc) PushHook(hook func(types.Context, types.AccAddress, string, types.Coins) error) { - f.mutex.Lock() - f.hooks = append(f.hooks, hook) - f.mutex.Unlock() -} - -// SetDefaultReturn calls SetDefaultHook with a function that returns the -// given values. -func (f *BankKeeperSendCoinsFromAccountToModuleFunc) SetDefaultReturn(r0 error) { - f.SetDefaultHook(func(types.Context, types.AccAddress, string, types.Coins) error { - return r0 - }) -} - -// PushReturn calls PushHook with a function that returns the given values. -func (f *BankKeeperSendCoinsFromAccountToModuleFunc) PushReturn(r0 error) { - f.PushHook(func(types.Context, types.AccAddress, string, types.Coins) error { - return r0 - }) -} - -func (f *BankKeeperSendCoinsFromAccountToModuleFunc) nextHook() func(types.Context, types.AccAddress, string, types.Coins) error { - f.mutex.Lock() - defer f.mutex.Unlock() - - if len(f.hooks) == 0 { - return f.defaultHook - } - - hook := f.hooks[0] - f.hooks = f.hooks[1:] - return hook -} - -func (f *BankKeeperSendCoinsFromAccountToModuleFunc) appendCall(r0 BankKeeperSendCoinsFromAccountToModuleFuncCall) { - f.mutex.Lock() - f.history = append(f.history, r0) - f.mutex.Unlock() -} - -// History returns a sequence of -// BankKeeperSendCoinsFromAccountToModuleFuncCall objects describing the -// invocations of this function. -func (f *BankKeeperSendCoinsFromAccountToModuleFunc) History() []BankKeeperSendCoinsFromAccountToModuleFuncCall { - f.mutex.Lock() - history := make([]BankKeeperSendCoinsFromAccountToModuleFuncCall, len(f.history)) - copy(history, f.history) - f.mutex.Unlock() - - return history -} - -// BankKeeperSendCoinsFromAccountToModuleFuncCall is an object that -// describes an invocation of method SendCoinsFromAccountToModule on an -// instance of MockBankKeeper. -type BankKeeperSendCoinsFromAccountToModuleFuncCall struct { - // Arg0 is the value of the 1st argument passed to this method - // invocation. - Arg0 types.Context - // Arg1 is the value of the 2nd argument passed to this method - // invocation. - Arg1 types.AccAddress - // Arg2 is the value of the 3rd argument passed to this method - // invocation. - Arg2 string - // Arg3 is the value of the 4th argument passed to this method - // invocation. - Arg3 types.Coins - // Result0 is the value of the 1st result returned from this method - // invocation. - Result0 error -} - -// Args returns an interface slice containing the arguments of this -// invocation. -func (c BankKeeperSendCoinsFromAccountToModuleFuncCall) Args() []interface{} { - return []interface{}{c.Arg0, c.Arg1, c.Arg2, c.Arg3} -} - -// Results returns an interface slice containing the results of this -// invocation. -func (c BankKeeperSendCoinsFromAccountToModuleFuncCall) Results() []interface{} { - return []interface{}{c.Result0} -} - -// BankKeeperSendCoinsFromModuleToAccountFunc describes the behavior when -// the SendCoinsFromModuleToAccount method of the parent MockBankKeeper -// instance is invoked. -type BankKeeperSendCoinsFromModuleToAccountFunc struct { - defaultHook func(types.Context, string, types.AccAddress, types.Coins) error - hooks []func(types.Context, string, types.AccAddress, types.Coins) error - history []BankKeeperSendCoinsFromModuleToAccountFuncCall - mutex sync.Mutex -} - -// SendCoinsFromModuleToAccount delegates to the next hook function in the -// queue and stores the parameter and result values of this invocation. -func (m *MockBankKeeper) SendCoinsFromModuleToAccount(v0 types.Context, v1 string, v2 types.AccAddress, v3 types.Coins) error { - r0 := m.SendCoinsFromModuleToAccountFunc.nextHook()(v0, v1, v2, v3) - m.SendCoinsFromModuleToAccountFunc.appendCall(BankKeeperSendCoinsFromModuleToAccountFuncCall{v0, v1, v2, v3, r0}) - return r0 -} - -// SetDefaultHook sets function that is called when the -// SendCoinsFromModuleToAccount method of the parent MockBankKeeper instance -// is invoked and the hook queue is empty. -func (f *BankKeeperSendCoinsFromModuleToAccountFunc) SetDefaultHook(hook func(types.Context, string, types.AccAddress, types.Coins) error) { - f.defaultHook = hook -} - -// PushHook adds a function to the end of hook queue. Each invocation of the -// SendCoinsFromModuleToAccount method of the parent MockBankKeeper instance -// invokes the hook at the front of the queue and discards it. After the -// queue is empty, the default hook function is invoked for any future -// action. -func (f *BankKeeperSendCoinsFromModuleToAccountFunc) PushHook(hook func(types.Context, string, types.AccAddress, types.Coins) error) { - f.mutex.Lock() - f.hooks = append(f.hooks, hook) - f.mutex.Unlock() +// SendCoinsFromModuleToAccount mocks base method. +func (m *MockBankKeeper) SendCoinsFromModuleToAccount(ctx types.Context, senderModule string, recipientAddr types.AccAddress, amt types.Coins) error { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "SendCoinsFromModuleToAccount", ctx, senderModule, recipientAddr, amt) + ret0, _ := ret[0].(error) + return ret0 } -// SetDefaultReturn calls SetDefaultHook with a function that returns the -// given values. -func (f *BankKeeperSendCoinsFromModuleToAccountFunc) SetDefaultReturn(r0 error) { - f.SetDefaultHook(func(types.Context, string, types.AccAddress, types.Coins) error { - return r0 - }) +// SendCoinsFromModuleToAccount indicates an expected call of SendCoinsFromModuleToAccount. +func (mr *MockBankKeeperMockRecorder) SendCoinsFromModuleToAccount(ctx, senderModule, recipientAddr, amt interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "SendCoinsFromModuleToAccount", reflect.TypeOf((*MockBankKeeper)(nil).SendCoinsFromModuleToAccount), ctx, senderModule, recipientAddr, amt) } -// PushReturn calls PushHook with a function that returns the given values. -func (f *BankKeeperSendCoinsFromModuleToAccountFunc) PushReturn(r0 error) { - f.PushHook(func(types.Context, string, types.AccAddress, types.Coins) error { - return r0 - }) -} - -func (f *BankKeeperSendCoinsFromModuleToAccountFunc) nextHook() func(types.Context, string, types.AccAddress, types.Coins) error { - f.mutex.Lock() - defer f.mutex.Unlock() - - if len(f.hooks) == 0 { - return f.defaultHook - } - - hook := f.hooks[0] - f.hooks = f.hooks[1:] - return hook -} - -func (f *BankKeeperSendCoinsFromModuleToAccountFunc) appendCall(r0 BankKeeperSendCoinsFromModuleToAccountFuncCall) { - f.mutex.Lock() - f.history = append(f.history, r0) - f.mutex.Unlock() -} - -// History returns a sequence of -// BankKeeperSendCoinsFromModuleToAccountFuncCall objects describing the -// invocations of this function. -func (f *BankKeeperSendCoinsFromModuleToAccountFunc) History() []BankKeeperSendCoinsFromModuleToAccountFuncCall { - f.mutex.Lock() - history := make([]BankKeeperSendCoinsFromModuleToAccountFuncCall, len(f.history)) - copy(history, f.history) - f.mutex.Unlock() - - return history -} - -// BankKeeperSendCoinsFromModuleToAccountFuncCall is an object that -// describes an invocation of method SendCoinsFromModuleToAccount on an -// instance of MockBankKeeper. -type BankKeeperSendCoinsFromModuleToAccountFuncCall struct { - // Arg0 is the value of the 1st argument passed to this method - // invocation. - Arg0 types.Context - // Arg1 is the value of the 2nd argument passed to this method - // invocation. - Arg1 string - // Arg2 is the value of the 3rd argument passed to this method - // invocation. - Arg2 types.AccAddress - // Arg3 is the value of the 4th argument passed to this method - // invocation. - Arg3 types.Coins - // Result0 is the value of the 1st result returned from this method - // invocation. - Result0 error -} - -// Args returns an interface slice containing the arguments of this -// invocation. -func (c BankKeeperSendCoinsFromModuleToAccountFuncCall) Args() []interface{} { - return []interface{}{c.Arg0, c.Arg1, c.Arg2, c.Arg3} -} - -// Results returns an interface slice containing the results of this -// invocation. -func (c BankKeeperSendCoinsFromModuleToAccountFuncCall) Results() []interface{} { - return []interface{}{c.Result0} -} - -// MockLeverageKeeper is a mock implementation of the LeverageKeeper -// interface (from the package github.com/umee-network/umee/v5/x/metoken) -// used for unit testing. +// MockLeverageKeeper is a mock of LeverageKeeper interface. type MockLeverageKeeper struct { - // ExchangeTokenFunc is an instance of a mock function object - // controlling the behavior of the method ExchangeToken. - ExchangeTokenFunc *LeverageKeeperExchangeTokenFunc - // ExchangeUTokenFunc is an instance of a mock function object - // controlling the behavior of the method ExchangeUToken. - ExchangeUTokenFunc *LeverageKeeperExchangeUTokenFunc - // GetAllSuppliedFunc is an instance of a mock function object - // controlling the behavior of the method GetAllSupplied. - GetAllSuppliedFunc *LeverageKeeperGetAllSuppliedFunc - // GetTokenSettingsFunc is an instance of a mock function object - // controlling the behavior of the method GetTokenSettings. - GetTokenSettingsFunc *LeverageKeeperGetTokenSettingsFunc - // GetTotalSupplyFunc is an instance of a mock function object - // controlling the behavior of the method GetTotalSupply. - GetTotalSupplyFunc *LeverageKeeperGetTotalSupplyFunc - // ModuleMaxWithdrawFunc is an instance of a mock function object - // controlling the behavior of the method ModuleMaxWithdraw. - ModuleMaxWithdrawFunc *LeverageKeeperModuleMaxWithdrawFunc - // SupplyFromModuleFunc is an instance of a mock function object - // controlling the behavior of the method SupplyFromModule. - SupplyFromModuleFunc *LeverageKeeperSupplyFromModuleFunc - // WithdrawToModuleFunc is an instance of a mock function object - // controlling the behavior of the method WithdrawToModule. - WithdrawToModuleFunc *LeverageKeeperWithdrawToModuleFunc -} - -// NewMockLeverageKeeper creates a new mock of the LeverageKeeper interface. -// All methods return zero values for all results, unless overwritten. -func NewMockLeverageKeeper() *MockLeverageKeeper { - return &MockLeverageKeeper{ - ExchangeTokenFunc: &LeverageKeeperExchangeTokenFunc{ - defaultHook: func(types.Context, types.Coin) (r0 types.Coin, r1 error) { - return - }, - }, - ExchangeUTokenFunc: &LeverageKeeperExchangeUTokenFunc{ - defaultHook: func(types.Context, types.Coin) (r0 types.Coin, r1 error) { - return - }, - }, - GetAllSuppliedFunc: &LeverageKeeperGetAllSuppliedFunc{ - defaultHook: func(types.Context, types.AccAddress) (r0 types.Coins, r1 error) { - return - }, - }, - GetTokenSettingsFunc: &LeverageKeeperGetTokenSettingsFunc{ - defaultHook: func(types.Context, string) (r0 types1.Token, r1 error) { - return - }, - }, - GetTotalSupplyFunc: &LeverageKeeperGetTotalSupplyFunc{ - defaultHook: func(types.Context, string) (r0 types.Coin, r1 error) { - return - }, - }, - ModuleMaxWithdrawFunc: &LeverageKeeperModuleMaxWithdrawFunc{ - defaultHook: func(types.Context, types.Coin) (r0 math.Int, r1 error) { - return - }, - }, - SupplyFromModuleFunc: &LeverageKeeperSupplyFromModuleFunc{ - defaultHook: func(types.Context, string, types.Coin) (r0 types.Coin, r1 bool, r2 error) { - return - }, - }, - WithdrawToModuleFunc: &LeverageKeeperWithdrawToModuleFunc{ - defaultHook: func(types.Context, string, types.Coin) (r0 types.Coin, r1 bool, r2 error) { - return - }, - }, - } + ctrl *gomock.Controller + recorder *MockLeverageKeeperMockRecorder } -// NewStrictMockLeverageKeeper creates a new mock of the LeverageKeeper -// interface. All methods panic on invocation, unless overwritten. -func NewStrictMockLeverageKeeper() *MockLeverageKeeper { - return &MockLeverageKeeper{ - ExchangeTokenFunc: &LeverageKeeperExchangeTokenFunc{ - defaultHook: func(types.Context, types.Coin) (types.Coin, error) { - panic("unexpected invocation of MockLeverageKeeper.ExchangeToken") - }, - }, - ExchangeUTokenFunc: &LeverageKeeperExchangeUTokenFunc{ - defaultHook: func(types.Context, types.Coin) (types.Coin, error) { - panic("unexpected invocation of MockLeverageKeeper.ExchangeUToken") - }, - }, - GetAllSuppliedFunc: &LeverageKeeperGetAllSuppliedFunc{ - defaultHook: func(types.Context, types.AccAddress) (types.Coins, error) { - panic("unexpected invocation of MockLeverageKeeper.GetAllSupplied") - }, - }, - GetTokenSettingsFunc: &LeverageKeeperGetTokenSettingsFunc{ - defaultHook: func(types.Context, string) (types1.Token, error) { - panic("unexpected invocation of MockLeverageKeeper.GetTokenSettings") - }, - }, - GetTotalSupplyFunc: &LeverageKeeperGetTotalSupplyFunc{ - defaultHook: func(types.Context, string) (types.Coin, error) { - panic("unexpected invocation of MockLeverageKeeper.GetTotalSupply") - }, - }, - ModuleMaxWithdrawFunc: &LeverageKeeperModuleMaxWithdrawFunc{ - defaultHook: func(types.Context, types.Coin) (math.Int, error) { - panic("unexpected invocation of MockLeverageKeeper.ModuleMaxWithdraw") - }, - }, - SupplyFromModuleFunc: &LeverageKeeperSupplyFromModuleFunc{ - defaultHook: func(types.Context, string, types.Coin) (types.Coin, bool, error) { - panic("unexpected invocation of MockLeverageKeeper.SupplyFromModule") - }, - }, - WithdrawToModuleFunc: &LeverageKeeperWithdrawToModuleFunc{ - defaultHook: func(types.Context, string, types.Coin) (types.Coin, bool, error) { - panic("unexpected invocation of MockLeverageKeeper.WithdrawToModule") - }, - }, - } +// MockLeverageKeeperMockRecorder is the mock recorder for MockLeverageKeeper. +type MockLeverageKeeperMockRecorder struct { + mock *MockLeverageKeeper } -// NewMockLeverageKeeperFrom creates a new mock of the MockLeverageKeeper -// interface. All methods delegate to the given implementation, unless -// overwritten. -func NewMockLeverageKeeperFrom(i metoken.LeverageKeeper) *MockLeverageKeeper { - return &MockLeverageKeeper{ - ExchangeTokenFunc: &LeverageKeeperExchangeTokenFunc{ - defaultHook: i.ExchangeToken, - }, - ExchangeUTokenFunc: &LeverageKeeperExchangeUTokenFunc{ - defaultHook: i.ExchangeUToken, - }, - GetAllSuppliedFunc: &LeverageKeeperGetAllSuppliedFunc{ - defaultHook: i.GetAllSupplied, - }, - GetTokenSettingsFunc: &LeverageKeeperGetTokenSettingsFunc{ - defaultHook: i.GetTokenSettings, - }, - GetTotalSupplyFunc: &LeverageKeeperGetTotalSupplyFunc{ - defaultHook: i.GetTotalSupply, - }, - ModuleMaxWithdrawFunc: &LeverageKeeperModuleMaxWithdrawFunc{ - defaultHook: i.ModuleMaxWithdraw, - }, - SupplyFromModuleFunc: &LeverageKeeperSupplyFromModuleFunc{ - defaultHook: i.SupplyFromModule, - }, - WithdrawToModuleFunc: &LeverageKeeperWithdrawToModuleFunc{ - defaultHook: i.WithdrawToModule, - }, - } +// NewMockLeverageKeeper creates a new mock instance. +func NewMockLeverageKeeper(ctrl *gomock.Controller) *MockLeverageKeeper { + mock := &MockLeverageKeeper{ctrl: ctrl} + mock.recorder = &MockLeverageKeeperMockRecorder{mock} + return mock } -// LeverageKeeperExchangeTokenFunc describes the behavior when the -// ExchangeToken method of the parent MockLeverageKeeper instance is -// invoked. -type LeverageKeeperExchangeTokenFunc struct { - defaultHook func(types.Context, types.Coin) (types.Coin, error) - hooks []func(types.Context, types.Coin) (types.Coin, error) - history []LeverageKeeperExchangeTokenFuncCall - mutex sync.Mutex +// EXPECT returns an object that allows the caller to indicate expected use. +func (m *MockLeverageKeeper) EXPECT() *MockLeverageKeeperMockRecorder { + return m.recorder } -// ExchangeToken delegates to the next hook function in the queue and stores -// the parameter and result values of this invocation. -func (m *MockLeverageKeeper) ExchangeToken(v0 types.Context, v1 types.Coin) (types.Coin, error) { - r0, r1 := m.ExchangeTokenFunc.nextHook()(v0, v1) - m.ExchangeTokenFunc.appendCall(LeverageKeeperExchangeTokenFuncCall{v0, v1, r0, r1}) - return r0, r1 +// GetAllSupplied mocks base method. +func (m *MockLeverageKeeper) GetAllSupplied(ctx types.Context, supplierAddr types.AccAddress) (types.Coins, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "GetAllSupplied", ctx, supplierAddr) + ret0, _ := ret[0].(types.Coins) + ret1, _ := ret[1].(error) + return ret0, ret1 } -// SetDefaultHook sets function that is called when the ExchangeToken method -// of the parent MockLeverageKeeper instance is invoked and the hook queue -// is empty. -func (f *LeverageKeeperExchangeTokenFunc) SetDefaultHook(hook func(types.Context, types.Coin) (types.Coin, error)) { - f.defaultHook = hook +// GetAllSupplied indicates an expected call of GetAllSupplied. +func (mr *MockLeverageKeeperMockRecorder) GetAllSupplied(ctx, supplierAddr interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetAllSupplied", reflect.TypeOf((*MockLeverageKeeper)(nil).GetAllSupplied), ctx, supplierAddr) } -// PushHook adds a function to the end of hook queue. Each invocation of the -// ExchangeToken method of the parent MockLeverageKeeper instance invokes -// the hook at the front of the queue and discards it. After the queue is -// empty, the default hook function is invoked for any future action. -func (f *LeverageKeeperExchangeTokenFunc) PushHook(hook func(types.Context, types.Coin) (types.Coin, error)) { - f.mutex.Lock() - f.hooks = append(f.hooks, hook) - f.mutex.Unlock() +// GetTokenSettings mocks base method. +func (m *MockLeverageKeeper) GetTokenSettings(ctx types.Context, denom string) (types0.Token, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "GetTokenSettings", ctx, denom) + ret0, _ := ret[0].(types0.Token) + ret1, _ := ret[1].(error) + return ret0, ret1 } -// SetDefaultReturn calls SetDefaultHook with a function that returns the -// given values. -func (f *LeverageKeeperExchangeTokenFunc) SetDefaultReturn(r0 types.Coin, r1 error) { - f.SetDefaultHook(func(types.Context, types.Coin) (types.Coin, error) { - return r0, r1 - }) +// GetTokenSettings indicates an expected call of GetTokenSettings. +func (mr *MockLeverageKeeperMockRecorder) GetTokenSettings(ctx, denom interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetTokenSettings", reflect.TypeOf((*MockLeverageKeeper)(nil).GetTokenSettings), ctx, denom) } -// PushReturn calls PushHook with a function that returns the given values. -func (f *LeverageKeeperExchangeTokenFunc) PushReturn(r0 types.Coin, r1 error) { - f.PushHook(func(types.Context, types.Coin) (types.Coin, error) { - return r0, r1 - }) +// GetTotalSupply mocks base method. +func (m *MockLeverageKeeper) GetTotalSupply(ctx types.Context, denom string) (types.Coin, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "GetTotalSupply", ctx, denom) + ret0, _ := ret[0].(types.Coin) + ret1, _ := ret[1].(error) + return ret0, ret1 } -func (f *LeverageKeeperExchangeTokenFunc) nextHook() func(types.Context, types.Coin) (types.Coin, error) { - f.mutex.Lock() - defer f.mutex.Unlock() - - if len(f.hooks) == 0 { - return f.defaultHook - } - - hook := f.hooks[0] - f.hooks = f.hooks[1:] - return hook -} - -func (f *LeverageKeeperExchangeTokenFunc) appendCall(r0 LeverageKeeperExchangeTokenFuncCall) { - f.mutex.Lock() - f.history = append(f.history, r0) - f.mutex.Unlock() -} - -// History returns a sequence of LeverageKeeperExchangeTokenFuncCall objects -// describing the invocations of this function. -func (f *LeverageKeeperExchangeTokenFunc) History() []LeverageKeeperExchangeTokenFuncCall { - f.mutex.Lock() - history := make([]LeverageKeeperExchangeTokenFuncCall, len(f.history)) - copy(history, f.history) - f.mutex.Unlock() - - return history +// GetTotalSupply indicates an expected call of GetTotalSupply. +func (mr *MockLeverageKeeperMockRecorder) GetTotalSupply(ctx, denom interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetTotalSupply", reflect.TypeOf((*MockLeverageKeeper)(nil).GetTotalSupply), ctx, denom) } -// LeverageKeeperExchangeTokenFuncCall is an object that describes an -// invocation of method ExchangeToken on an instance of MockLeverageKeeper. -type LeverageKeeperExchangeTokenFuncCall struct { - // Arg0 is the value of the 1st argument passed to this method - // invocation. - Arg0 types.Context - // Arg1 is the value of the 2nd argument passed to this method - // invocation. - Arg1 types.Coin - // Result0 is the value of the 1st result returned from this method - // invocation. - Result0 types.Coin - // Result1 is the value of the 2nd result returned from this method - // invocation. - Result1 error +// ModuleMaxWithdraw mocks base method. +func (m *MockLeverageKeeper) ModuleMaxWithdraw(ctx types.Context, spendableUTokens types.Coin) (math.Int, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "ModuleMaxWithdraw", ctx, spendableUTokens) + ret0, _ := ret[0].(math.Int) + ret1, _ := ret[1].(error) + return ret0, ret1 } -// Args returns an interface slice containing the arguments of this -// invocation. -func (c LeverageKeeperExchangeTokenFuncCall) Args() []interface{} { - return []interface{}{c.Arg0, c.Arg1} +// ModuleMaxWithdraw indicates an expected call of ModuleMaxWithdraw. +func (mr *MockLeverageKeeperMockRecorder) ModuleMaxWithdraw(ctx, spendableUTokens interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ModuleMaxWithdraw", reflect.TypeOf((*MockLeverageKeeper)(nil).ModuleMaxWithdraw), ctx, spendableUTokens) } -// Results returns an interface slice containing the results of this -// invocation. -func (c LeverageKeeperExchangeTokenFuncCall) Results() []interface{} { - return []interface{}{c.Result0, c.Result1} +// SupplyFromModule mocks base method. +func (m *MockLeverageKeeper) SupplyFromModule(ctx types.Context, fromModule string, coin types.Coin) (types.Coin, bool, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "SupplyFromModule", ctx, fromModule, coin) + ret0, _ := ret[0].(types.Coin) + ret1, _ := ret[1].(bool) + ret2, _ := ret[2].(error) + return ret0, ret1, ret2 } -// LeverageKeeperExchangeUTokenFunc describes the behavior when the -// ExchangeUToken method of the parent MockLeverageKeeper instance is -// invoked. -type LeverageKeeperExchangeUTokenFunc struct { - defaultHook func(types.Context, types.Coin) (types.Coin, error) - hooks []func(types.Context, types.Coin) (types.Coin, error) - history []LeverageKeeperExchangeUTokenFuncCall - mutex sync.Mutex +// SupplyFromModule indicates an expected call of SupplyFromModule. +func (mr *MockLeverageKeeperMockRecorder) SupplyFromModule(ctx, fromModule, coin interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "SupplyFromModule", reflect.TypeOf((*MockLeverageKeeper)(nil).SupplyFromModule), ctx, fromModule, coin) } -// ExchangeUToken delegates to the next hook function in the queue and -// stores the parameter and result values of this invocation. -func (m *MockLeverageKeeper) ExchangeUToken(v0 types.Context, v1 types.Coin) (types.Coin, error) { - r0, r1 := m.ExchangeUTokenFunc.nextHook()(v0, v1) - m.ExchangeUTokenFunc.appendCall(LeverageKeeperExchangeUTokenFuncCall{v0, v1, r0, r1}) - return r0, r1 +// ToToken mocks base method. +func (m *MockLeverageKeeper) ToToken(ctx types.Context, uToken types.Coin) (types.Coin, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "ToToken", ctx, uToken) + ret0, _ := ret[0].(types.Coin) + ret1, _ := ret[1].(error) + return ret0, ret1 } -// SetDefaultHook sets function that is called when the ExchangeUToken -// method of the parent MockLeverageKeeper instance is invoked and the hook -// queue is empty. -func (f *LeverageKeeperExchangeUTokenFunc) SetDefaultHook(hook func(types.Context, types.Coin) (types.Coin, error)) { - f.defaultHook = hook +// ToToken indicates an expected call of ToToken. +func (mr *MockLeverageKeeperMockRecorder) ToToken(ctx, uToken interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ToToken", reflect.TypeOf((*MockLeverageKeeper)(nil).ToToken), ctx, uToken) } -// PushHook adds a function to the end of hook queue. Each invocation of the -// ExchangeUToken method of the parent MockLeverageKeeper instance invokes -// the hook at the front of the queue and discards it. After the queue is -// empty, the default hook function is invoked for any future action. -func (f *LeverageKeeperExchangeUTokenFunc) PushHook(hook func(types.Context, types.Coin) (types.Coin, error)) { - f.mutex.Lock() - f.hooks = append(f.hooks, hook) - f.mutex.Unlock() +// ToUToken mocks base method. +func (m *MockLeverageKeeper) ToUToken(ctx types.Context, token types.Coin) (types.Coin, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "ToUToken", ctx, token) + ret0, _ := ret[0].(types.Coin) + ret1, _ := ret[1].(error) + return ret0, ret1 } -// SetDefaultReturn calls SetDefaultHook with a function that returns the -// given values. -func (f *LeverageKeeperExchangeUTokenFunc) SetDefaultReturn(r0 types.Coin, r1 error) { - f.SetDefaultHook(func(types.Context, types.Coin) (types.Coin, error) { - return r0, r1 - }) +// ToUToken indicates an expected call of ToUToken. +func (mr *MockLeverageKeeperMockRecorder) ToUToken(ctx, token interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ToUToken", reflect.TypeOf((*MockLeverageKeeper)(nil).ToUToken), ctx, token) } -// PushReturn calls PushHook with a function that returns the given values. -func (f *LeverageKeeperExchangeUTokenFunc) PushReturn(r0 types.Coin, r1 error) { - f.PushHook(func(types.Context, types.Coin) (types.Coin, error) { - return r0, r1 - }) +// WithdrawToModule mocks base method. +func (m *MockLeverageKeeper) WithdrawToModule(ctx types.Context, toModule string, uToken types.Coin) (types.Coin, bool, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "WithdrawToModule", ctx, toModule, uToken) + ret0, _ := ret[0].(types.Coin) + ret1, _ := ret[1].(bool) + ret2, _ := ret[2].(error) + return ret0, ret1, ret2 } -func (f *LeverageKeeperExchangeUTokenFunc) nextHook() func(types.Context, types.Coin) (types.Coin, error) { - f.mutex.Lock() - defer f.mutex.Unlock() - - if len(f.hooks) == 0 { - return f.defaultHook - } - - hook := f.hooks[0] - f.hooks = f.hooks[1:] - return hook +// WithdrawToModule indicates an expected call of WithdrawToModule. +func (mr *MockLeverageKeeperMockRecorder) WithdrawToModule(ctx, toModule, uToken interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "WithdrawToModule", reflect.TypeOf((*MockLeverageKeeper)(nil).WithdrawToModule), ctx, toModule, uToken) } -func (f *LeverageKeeperExchangeUTokenFunc) appendCall(r0 LeverageKeeperExchangeUTokenFuncCall) { - f.mutex.Lock() - f.history = append(f.history, r0) - f.mutex.Unlock() -} - -// History returns a sequence of LeverageKeeperExchangeUTokenFuncCall -// objects describing the invocations of this function. -func (f *LeverageKeeperExchangeUTokenFunc) History() []LeverageKeeperExchangeUTokenFuncCall { - f.mutex.Lock() - history := make([]LeverageKeeperExchangeUTokenFuncCall, len(f.history)) - copy(history, f.history) - f.mutex.Unlock() - - return history -} - -// LeverageKeeperExchangeUTokenFuncCall is an object that describes an -// invocation of method ExchangeUToken on an instance of MockLeverageKeeper. -type LeverageKeeperExchangeUTokenFuncCall struct { - // Arg0 is the value of the 1st argument passed to this method - // invocation. - Arg0 types.Context - // Arg1 is the value of the 2nd argument passed to this method - // invocation. - Arg1 types.Coin - // Result0 is the value of the 1st result returned from this method - // invocation. - Result0 types.Coin - // Result1 is the value of the 2nd result returned from this method - // invocation. - Result1 error -} - -// Args returns an interface slice containing the arguments of this -// invocation. -func (c LeverageKeeperExchangeUTokenFuncCall) Args() []interface{} { - return []interface{}{c.Arg0, c.Arg1} -} - -// Results returns an interface slice containing the results of this -// invocation. -func (c LeverageKeeperExchangeUTokenFuncCall) Results() []interface{} { - return []interface{}{c.Result0, c.Result1} -} - -// LeverageKeeperGetAllSuppliedFunc describes the behavior when the -// GetAllSupplied method of the parent MockLeverageKeeper instance is -// invoked. -type LeverageKeeperGetAllSuppliedFunc struct { - defaultHook func(types.Context, types.AccAddress) (types.Coins, error) - hooks []func(types.Context, types.AccAddress) (types.Coins, error) - history []LeverageKeeperGetAllSuppliedFuncCall - mutex sync.Mutex -} - -// GetAllSupplied delegates to the next hook function in the queue and -// stores the parameter and result values of this invocation. -func (m *MockLeverageKeeper) GetAllSupplied(v0 types.Context, v1 types.AccAddress) (types.Coins, error) { - r0, r1 := m.GetAllSuppliedFunc.nextHook()(v0, v1) - m.GetAllSuppliedFunc.appendCall(LeverageKeeperGetAllSuppliedFuncCall{v0, v1, r0, r1}) - return r0, r1 -} - -// SetDefaultHook sets function that is called when the GetAllSupplied -// method of the parent MockLeverageKeeper instance is invoked and the hook -// queue is empty. -func (f *LeverageKeeperGetAllSuppliedFunc) SetDefaultHook(hook func(types.Context, types.AccAddress) (types.Coins, error)) { - f.defaultHook = hook -} - -// PushHook adds a function to the end of hook queue. Each invocation of the -// GetAllSupplied method of the parent MockLeverageKeeper instance invokes -// the hook at the front of the queue and discards it. After the queue is -// empty, the default hook function is invoked for any future action. -func (f *LeverageKeeperGetAllSuppliedFunc) PushHook(hook func(types.Context, types.AccAddress) (types.Coins, error)) { - f.mutex.Lock() - f.hooks = append(f.hooks, hook) - f.mutex.Unlock() -} - -// SetDefaultReturn calls SetDefaultHook with a function that returns the -// given values. -func (f *LeverageKeeperGetAllSuppliedFunc) SetDefaultReturn(r0 types.Coins, r1 error) { - f.SetDefaultHook(func(types.Context, types.AccAddress) (types.Coins, error) { - return r0, r1 - }) -} - -// PushReturn calls PushHook with a function that returns the given values. -func (f *LeverageKeeperGetAllSuppliedFunc) PushReturn(r0 types.Coins, r1 error) { - f.PushHook(func(types.Context, types.AccAddress) (types.Coins, error) { - return r0, r1 - }) -} - -func (f *LeverageKeeperGetAllSuppliedFunc) nextHook() func(types.Context, types.AccAddress) (types.Coins, error) { - f.mutex.Lock() - defer f.mutex.Unlock() - - if len(f.hooks) == 0 { - return f.defaultHook - } - - hook := f.hooks[0] - f.hooks = f.hooks[1:] - return hook -} - -func (f *LeverageKeeperGetAllSuppliedFunc) appendCall(r0 LeverageKeeperGetAllSuppliedFuncCall) { - f.mutex.Lock() - f.history = append(f.history, r0) - f.mutex.Unlock() -} - -// History returns a sequence of LeverageKeeperGetAllSuppliedFuncCall -// objects describing the invocations of this function. -func (f *LeverageKeeperGetAllSuppliedFunc) History() []LeverageKeeperGetAllSuppliedFuncCall { - f.mutex.Lock() - history := make([]LeverageKeeperGetAllSuppliedFuncCall, len(f.history)) - copy(history, f.history) - f.mutex.Unlock() - - return history -} - -// LeverageKeeperGetAllSuppliedFuncCall is an object that describes an -// invocation of method GetAllSupplied on an instance of MockLeverageKeeper. -type LeverageKeeperGetAllSuppliedFuncCall struct { - // Arg0 is the value of the 1st argument passed to this method - // invocation. - Arg0 types.Context - // Arg1 is the value of the 2nd argument passed to this method - // invocation. - Arg1 types.AccAddress - // Result0 is the value of the 1st result returned from this method - // invocation. - Result0 types.Coins - // Result1 is the value of the 2nd result returned from this method - // invocation. - Result1 error -} - -// Args returns an interface slice containing the arguments of this -// invocation. -func (c LeverageKeeperGetAllSuppliedFuncCall) Args() []interface{} { - return []interface{}{c.Arg0, c.Arg1} -} - -// Results returns an interface slice containing the results of this -// invocation. -func (c LeverageKeeperGetAllSuppliedFuncCall) Results() []interface{} { - return []interface{}{c.Result0, c.Result1} -} - -// LeverageKeeperGetTokenSettingsFunc describes the behavior when the -// GetTokenSettings method of the parent MockLeverageKeeper instance is -// invoked. -type LeverageKeeperGetTokenSettingsFunc struct { - defaultHook func(types.Context, string) (types1.Token, error) - hooks []func(types.Context, string) (types1.Token, error) - history []LeverageKeeperGetTokenSettingsFuncCall - mutex sync.Mutex -} - -// GetTokenSettings delegates to the next hook function in the queue and -// stores the parameter and result values of this invocation. -func (m *MockLeverageKeeper) GetTokenSettings(v0 types.Context, v1 string) (types1.Token, error) { - r0, r1 := m.GetTokenSettingsFunc.nextHook()(v0, v1) - m.GetTokenSettingsFunc.appendCall(LeverageKeeperGetTokenSettingsFuncCall{v0, v1, r0, r1}) - return r0, r1 -} - -// SetDefaultHook sets function that is called when the GetTokenSettings -// method of the parent MockLeverageKeeper instance is invoked and the hook -// queue is empty. -func (f *LeverageKeeperGetTokenSettingsFunc) SetDefaultHook(hook func(types.Context, string) (types1.Token, error)) { - f.defaultHook = hook -} - -// PushHook adds a function to the end of hook queue. Each invocation of the -// GetTokenSettings method of the parent MockLeverageKeeper instance invokes -// the hook at the front of the queue and discards it. After the queue is -// empty, the default hook function is invoked for any future action. -func (f *LeverageKeeperGetTokenSettingsFunc) PushHook(hook func(types.Context, string) (types1.Token, error)) { - f.mutex.Lock() - f.hooks = append(f.hooks, hook) - f.mutex.Unlock() -} - -// SetDefaultReturn calls SetDefaultHook with a function that returns the -// given values. -func (f *LeverageKeeperGetTokenSettingsFunc) SetDefaultReturn(r0 types1.Token, r1 error) { - f.SetDefaultHook(func(types.Context, string) (types1.Token, error) { - return r0, r1 - }) -} - -// PushReturn calls PushHook with a function that returns the given values. -func (f *LeverageKeeperGetTokenSettingsFunc) PushReturn(r0 types1.Token, r1 error) { - f.PushHook(func(types.Context, string) (types1.Token, error) { - return r0, r1 - }) -} - -func (f *LeverageKeeperGetTokenSettingsFunc) nextHook() func(types.Context, string) (types1.Token, error) { - f.mutex.Lock() - defer f.mutex.Unlock() - - if len(f.hooks) == 0 { - return f.defaultHook - } - - hook := f.hooks[0] - f.hooks = f.hooks[1:] - return hook -} - -func (f *LeverageKeeperGetTokenSettingsFunc) appendCall(r0 LeverageKeeperGetTokenSettingsFuncCall) { - f.mutex.Lock() - f.history = append(f.history, r0) - f.mutex.Unlock() -} - -// History returns a sequence of LeverageKeeperGetTokenSettingsFuncCall -// objects describing the invocations of this function. -func (f *LeverageKeeperGetTokenSettingsFunc) History() []LeverageKeeperGetTokenSettingsFuncCall { - f.mutex.Lock() - history := make([]LeverageKeeperGetTokenSettingsFuncCall, len(f.history)) - copy(history, f.history) - f.mutex.Unlock() - - return history -} - -// LeverageKeeperGetTokenSettingsFuncCall is an object that describes an -// invocation of method GetTokenSettings on an instance of -// MockLeverageKeeper. -type LeverageKeeperGetTokenSettingsFuncCall struct { - // Arg0 is the value of the 1st argument passed to this method - // invocation. - Arg0 types.Context - // Arg1 is the value of the 2nd argument passed to this method - // invocation. - Arg1 string - // Result0 is the value of the 1st result returned from this method - // invocation. - Result0 types1.Token - // Result1 is the value of the 2nd result returned from this method - // invocation. - Result1 error -} - -// Args returns an interface slice containing the arguments of this -// invocation. -func (c LeverageKeeperGetTokenSettingsFuncCall) Args() []interface{} { - return []interface{}{c.Arg0, c.Arg1} -} - -// Results returns an interface slice containing the results of this -// invocation. -func (c LeverageKeeperGetTokenSettingsFuncCall) Results() []interface{} { - return []interface{}{c.Result0, c.Result1} -} - -// LeverageKeeperGetTotalSupplyFunc describes the behavior when the -// GetTotalSupply method of the parent MockLeverageKeeper instance is -// invoked. -type LeverageKeeperGetTotalSupplyFunc struct { - defaultHook func(types.Context, string) (types.Coin, error) - hooks []func(types.Context, string) (types.Coin, error) - history []LeverageKeeperGetTotalSupplyFuncCall - mutex sync.Mutex -} - -// GetTotalSupply delegates to the next hook function in the queue and -// stores the parameter and result values of this invocation. -func (m *MockLeverageKeeper) GetTotalSupply(v0 types.Context, v1 string) (types.Coin, error) { - r0, r1 := m.GetTotalSupplyFunc.nextHook()(v0, v1) - m.GetTotalSupplyFunc.appendCall(LeverageKeeperGetTotalSupplyFuncCall{v0, v1, r0, r1}) - return r0, r1 -} - -// SetDefaultHook sets function that is called when the GetTotalSupply -// method of the parent MockLeverageKeeper instance is invoked and the hook -// queue is empty. -func (f *LeverageKeeperGetTotalSupplyFunc) SetDefaultHook(hook func(types.Context, string) (types.Coin, error)) { - f.defaultHook = hook -} - -// PushHook adds a function to the end of hook queue. Each invocation of the -// GetTotalSupply method of the parent MockLeverageKeeper instance invokes -// the hook at the front of the queue and discards it. After the queue is -// empty, the default hook function is invoked for any future action. -func (f *LeverageKeeperGetTotalSupplyFunc) PushHook(hook func(types.Context, string) (types.Coin, error)) { - f.mutex.Lock() - f.hooks = append(f.hooks, hook) - f.mutex.Unlock() -} - -// SetDefaultReturn calls SetDefaultHook with a function that returns the -// given values. -func (f *LeverageKeeperGetTotalSupplyFunc) SetDefaultReturn(r0 types.Coin, r1 error) { - f.SetDefaultHook(func(types.Context, string) (types.Coin, error) { - return r0, r1 - }) -} - -// PushReturn calls PushHook with a function that returns the given values. -func (f *LeverageKeeperGetTotalSupplyFunc) PushReturn(r0 types.Coin, r1 error) { - f.PushHook(func(types.Context, string) (types.Coin, error) { - return r0, r1 - }) -} - -func (f *LeverageKeeperGetTotalSupplyFunc) nextHook() func(types.Context, string) (types.Coin, error) { - f.mutex.Lock() - defer f.mutex.Unlock() - - if len(f.hooks) == 0 { - return f.defaultHook - } - - hook := f.hooks[0] - f.hooks = f.hooks[1:] - return hook -} - -func (f *LeverageKeeperGetTotalSupplyFunc) appendCall(r0 LeverageKeeperGetTotalSupplyFuncCall) { - f.mutex.Lock() - f.history = append(f.history, r0) - f.mutex.Unlock() -} - -// History returns a sequence of LeverageKeeperGetTotalSupplyFuncCall -// objects describing the invocations of this function. -func (f *LeverageKeeperGetTotalSupplyFunc) History() []LeverageKeeperGetTotalSupplyFuncCall { - f.mutex.Lock() - history := make([]LeverageKeeperGetTotalSupplyFuncCall, len(f.history)) - copy(history, f.history) - f.mutex.Unlock() - - return history -} - -// LeverageKeeperGetTotalSupplyFuncCall is an object that describes an -// invocation of method GetTotalSupply on an instance of MockLeverageKeeper. -type LeverageKeeperGetTotalSupplyFuncCall struct { - // Arg0 is the value of the 1st argument passed to this method - // invocation. - Arg0 types.Context - // Arg1 is the value of the 2nd argument passed to this method - // invocation. - Arg1 string - // Result0 is the value of the 1st result returned from this method - // invocation. - Result0 types.Coin - // Result1 is the value of the 2nd result returned from this method - // invocation. - Result1 error -} - -// Args returns an interface slice containing the arguments of this -// invocation. -func (c LeverageKeeperGetTotalSupplyFuncCall) Args() []interface{} { - return []interface{}{c.Arg0, c.Arg1} -} - -// Results returns an interface slice containing the results of this -// invocation. -func (c LeverageKeeperGetTotalSupplyFuncCall) Results() []interface{} { - return []interface{}{c.Result0, c.Result1} -} - -// LeverageKeeperModuleMaxWithdrawFunc describes the behavior when the -// ModuleMaxWithdraw method of the parent MockLeverageKeeper instance is -// invoked. -type LeverageKeeperModuleMaxWithdrawFunc struct { - defaultHook func(types.Context, types.Coin) (math.Int, error) - hooks []func(types.Context, types.Coin) (math.Int, error) - history []LeverageKeeperModuleMaxWithdrawFuncCall - mutex sync.Mutex -} - -// ModuleMaxWithdraw delegates to the next hook function in the queue and -// stores the parameter and result values of this invocation. -func (m *MockLeverageKeeper) ModuleMaxWithdraw(v0 types.Context, v1 types.Coin) (math.Int, error) { - r0, r1 := m.ModuleMaxWithdrawFunc.nextHook()(v0, v1) - m.ModuleMaxWithdrawFunc.appendCall(LeverageKeeperModuleMaxWithdrawFuncCall{v0, v1, r0, r1}) - return r0, r1 -} - -// SetDefaultHook sets function that is called when the ModuleMaxWithdraw -// method of the parent MockLeverageKeeper instance is invoked and the hook -// queue is empty. -func (f *LeverageKeeperModuleMaxWithdrawFunc) SetDefaultHook(hook func(types.Context, types.Coin) (math.Int, error)) { - f.defaultHook = hook -} - -// PushHook adds a function to the end of hook queue. Each invocation of the -// ModuleMaxWithdraw method of the parent MockLeverageKeeper instance -// invokes the hook at the front of the queue and discards it. After the -// queue is empty, the default hook function is invoked for any future -// action. -func (f *LeverageKeeperModuleMaxWithdrawFunc) PushHook(hook func(types.Context, types.Coin) (math.Int, error)) { - f.mutex.Lock() - f.hooks = append(f.hooks, hook) - f.mutex.Unlock() -} - -// SetDefaultReturn calls SetDefaultHook with a function that returns the -// given values. -func (f *LeverageKeeperModuleMaxWithdrawFunc) SetDefaultReturn(r0 math.Int, r1 error) { - f.SetDefaultHook(func(types.Context, types.Coin) (math.Int, error) { - return r0, r1 - }) -} - -// PushReturn calls PushHook with a function that returns the given values. -func (f *LeverageKeeperModuleMaxWithdrawFunc) PushReturn(r0 math.Int, r1 error) { - f.PushHook(func(types.Context, types.Coin) (math.Int, error) { - return r0, r1 - }) -} - -func (f *LeverageKeeperModuleMaxWithdrawFunc) nextHook() func(types.Context, types.Coin) (math.Int, error) { - f.mutex.Lock() - defer f.mutex.Unlock() - - if len(f.hooks) == 0 { - return f.defaultHook - } - - hook := f.hooks[0] - f.hooks = f.hooks[1:] - return hook -} - -func (f *LeverageKeeperModuleMaxWithdrawFunc) appendCall(r0 LeverageKeeperModuleMaxWithdrawFuncCall) { - f.mutex.Lock() - f.history = append(f.history, r0) - f.mutex.Unlock() -} - -// History returns a sequence of LeverageKeeperModuleMaxWithdrawFuncCall -// objects describing the invocations of this function. -func (f *LeverageKeeperModuleMaxWithdrawFunc) History() []LeverageKeeperModuleMaxWithdrawFuncCall { - f.mutex.Lock() - history := make([]LeverageKeeperModuleMaxWithdrawFuncCall, len(f.history)) - copy(history, f.history) - f.mutex.Unlock() - - return history -} - -// LeverageKeeperModuleMaxWithdrawFuncCall is an object that describes an -// invocation of method ModuleMaxWithdraw on an instance of -// MockLeverageKeeper. -type LeverageKeeperModuleMaxWithdrawFuncCall struct { - // Arg0 is the value of the 1st argument passed to this method - // invocation. - Arg0 types.Context - // Arg1 is the value of the 2nd argument passed to this method - // invocation. - Arg1 types.Coin - // Result0 is the value of the 1st result returned from this method - // invocation. - Result0 math.Int - // Result1 is the value of the 2nd result returned from this method - // invocation. - Result1 error -} - -// Args returns an interface slice containing the arguments of this -// invocation. -func (c LeverageKeeperModuleMaxWithdrawFuncCall) Args() []interface{} { - return []interface{}{c.Arg0, c.Arg1} -} - -// Results returns an interface slice containing the results of this -// invocation. -func (c LeverageKeeperModuleMaxWithdrawFuncCall) Results() []interface{} { - return []interface{}{c.Result0, c.Result1} -} - -// LeverageKeeperSupplyFromModuleFunc describes the behavior when the -// SupplyFromModule method of the parent MockLeverageKeeper instance is -// invoked. -type LeverageKeeperSupplyFromModuleFunc struct { - defaultHook func(types.Context, string, types.Coin) (types.Coin, bool, error) - hooks []func(types.Context, string, types.Coin) (types.Coin, bool, error) - history []LeverageKeeperSupplyFromModuleFuncCall - mutex sync.Mutex -} - -// SupplyFromModule delegates to the next hook function in the queue and -// stores the parameter and result values of this invocation. -func (m *MockLeverageKeeper) SupplyFromModule(v0 types.Context, v1 string, v2 types.Coin) (types.Coin, bool, error) { - r0, r1, r2 := m.SupplyFromModuleFunc.nextHook()(v0, v1, v2) - m.SupplyFromModuleFunc.appendCall(LeverageKeeperSupplyFromModuleFuncCall{v0, v1, v2, r0, r1, r2}) - return r0, r1, r2 -} - -// SetDefaultHook sets function that is called when the SupplyFromModule -// method of the parent MockLeverageKeeper instance is invoked and the hook -// queue is empty. -func (f *LeverageKeeperSupplyFromModuleFunc) SetDefaultHook(hook func(types.Context, string, types.Coin) (types.Coin, bool, error)) { - f.defaultHook = hook -} - -// PushHook adds a function to the end of hook queue. Each invocation of the -// SupplyFromModule method of the parent MockLeverageKeeper instance invokes -// the hook at the front of the queue and discards it. After the queue is -// empty, the default hook function is invoked for any future action. -func (f *LeverageKeeperSupplyFromModuleFunc) PushHook(hook func(types.Context, string, types.Coin) (types.Coin, bool, error)) { - f.mutex.Lock() - f.hooks = append(f.hooks, hook) - f.mutex.Unlock() -} - -// SetDefaultReturn calls SetDefaultHook with a function that returns the -// given values. -func (f *LeverageKeeperSupplyFromModuleFunc) SetDefaultReturn(r0 types.Coin, r1 bool, r2 error) { - f.SetDefaultHook(func(types.Context, string, types.Coin) (types.Coin, bool, error) { - return r0, r1, r2 - }) -} - -// PushReturn calls PushHook with a function that returns the given values. -func (f *LeverageKeeperSupplyFromModuleFunc) PushReturn(r0 types.Coin, r1 bool, r2 error) { - f.PushHook(func(types.Context, string, types.Coin) (types.Coin, bool, error) { - return r0, r1, r2 - }) -} - -func (f *LeverageKeeperSupplyFromModuleFunc) nextHook() func(types.Context, string, types.Coin) (types.Coin, bool, error) { - f.mutex.Lock() - defer f.mutex.Unlock() - - if len(f.hooks) == 0 { - return f.defaultHook - } - - hook := f.hooks[0] - f.hooks = f.hooks[1:] - return hook -} - -func (f *LeverageKeeperSupplyFromModuleFunc) appendCall(r0 LeverageKeeperSupplyFromModuleFuncCall) { - f.mutex.Lock() - f.history = append(f.history, r0) - f.mutex.Unlock() -} - -// History returns a sequence of LeverageKeeperSupplyFromModuleFuncCall -// objects describing the invocations of this function. -func (f *LeverageKeeperSupplyFromModuleFunc) History() []LeverageKeeperSupplyFromModuleFuncCall { - f.mutex.Lock() - history := make([]LeverageKeeperSupplyFromModuleFuncCall, len(f.history)) - copy(history, f.history) - f.mutex.Unlock() - - return history -} - -// LeverageKeeperSupplyFromModuleFuncCall is an object that describes an -// invocation of method SupplyFromModule on an instance of -// MockLeverageKeeper. -type LeverageKeeperSupplyFromModuleFuncCall struct { - // Arg0 is the value of the 1st argument passed to this method - // invocation. - Arg0 types.Context - // Arg1 is the value of the 2nd argument passed to this method - // invocation. - Arg1 string - // Arg2 is the value of the 3rd argument passed to this method - // invocation. - Arg2 types.Coin - // Result0 is the value of the 1st result returned from this method - // invocation. - Result0 types.Coin - // Result1 is the value of the 2nd result returned from this method - // invocation. - Result1 bool - // Result2 is the value of the 3rd result returned from this method - // invocation. - Result2 error -} - -// Args returns an interface slice containing the arguments of this -// invocation. -func (c LeverageKeeperSupplyFromModuleFuncCall) Args() []interface{} { - return []interface{}{c.Arg0, c.Arg1, c.Arg2} -} - -// Results returns an interface slice containing the results of this -// invocation. -func (c LeverageKeeperSupplyFromModuleFuncCall) Results() []interface{} { - return []interface{}{c.Result0, c.Result1, c.Result2} -} - -// LeverageKeeperWithdrawToModuleFunc describes the behavior when the -// WithdrawToModule method of the parent MockLeverageKeeper instance is -// invoked. -type LeverageKeeperWithdrawToModuleFunc struct { - defaultHook func(types.Context, string, types.Coin) (types.Coin, bool, error) - hooks []func(types.Context, string, types.Coin) (types.Coin, bool, error) - history []LeverageKeeperWithdrawToModuleFuncCall - mutex sync.Mutex -} - -// WithdrawToModule delegates to the next hook function in the queue and -// stores the parameter and result values of this invocation. -func (m *MockLeverageKeeper) WithdrawToModule(v0 types.Context, v1 string, v2 types.Coin) (types.Coin, bool, error) { - r0, r1, r2 := m.WithdrawToModuleFunc.nextHook()(v0, v1, v2) - m.WithdrawToModuleFunc.appendCall(LeverageKeeperWithdrawToModuleFuncCall{v0, v1, v2, r0, r1, r2}) - return r0, r1, r2 -} - -// SetDefaultHook sets function that is called when the WithdrawToModule -// method of the parent MockLeverageKeeper instance is invoked and the hook -// queue is empty. -func (f *LeverageKeeperWithdrawToModuleFunc) SetDefaultHook(hook func(types.Context, string, types.Coin) (types.Coin, bool, error)) { - f.defaultHook = hook -} - -// PushHook adds a function to the end of hook queue. Each invocation of the -// WithdrawToModule method of the parent MockLeverageKeeper instance invokes -// the hook at the front of the queue and discards it. After the queue is -// empty, the default hook function is invoked for any future action. -func (f *LeverageKeeperWithdrawToModuleFunc) PushHook(hook func(types.Context, string, types.Coin) (types.Coin, bool, error)) { - f.mutex.Lock() - f.hooks = append(f.hooks, hook) - f.mutex.Unlock() -} - -// SetDefaultReturn calls SetDefaultHook with a function that returns the -// given values. -func (f *LeverageKeeperWithdrawToModuleFunc) SetDefaultReturn(r0 types.Coin, r1 bool, r2 error) { - f.SetDefaultHook(func(types.Context, string, types.Coin) (types.Coin, bool, error) { - return r0, r1, r2 - }) -} - -// PushReturn calls PushHook with a function that returns the given values. -func (f *LeverageKeeperWithdrawToModuleFunc) PushReturn(r0 types.Coin, r1 bool, r2 error) { - f.PushHook(func(types.Context, string, types.Coin) (types.Coin, bool, error) { - return r0, r1, r2 - }) -} - -func (f *LeverageKeeperWithdrawToModuleFunc) nextHook() func(types.Context, string, types.Coin) (types.Coin, bool, error) { - f.mutex.Lock() - defer f.mutex.Unlock() - - if len(f.hooks) == 0 { - return f.defaultHook - } - - hook := f.hooks[0] - f.hooks = f.hooks[1:] - return hook -} - -func (f *LeverageKeeperWithdrawToModuleFunc) appendCall(r0 LeverageKeeperWithdrawToModuleFuncCall) { - f.mutex.Lock() - f.history = append(f.history, r0) - f.mutex.Unlock() -} - -// History returns a sequence of LeverageKeeperWithdrawToModuleFuncCall -// objects describing the invocations of this function. -func (f *LeverageKeeperWithdrawToModuleFunc) History() []LeverageKeeperWithdrawToModuleFuncCall { - f.mutex.Lock() - history := make([]LeverageKeeperWithdrawToModuleFuncCall, len(f.history)) - copy(history, f.history) - f.mutex.Unlock() - - return history -} - -// LeverageKeeperWithdrawToModuleFuncCall is an object that describes an -// invocation of method WithdrawToModule on an instance of -// MockLeverageKeeper. -type LeverageKeeperWithdrawToModuleFuncCall struct { - // Arg0 is the value of the 1st argument passed to this method - // invocation. - Arg0 types.Context - // Arg1 is the value of the 2nd argument passed to this method - // invocation. - Arg1 string - // Arg2 is the value of the 3rd argument passed to this method - // invocation. - Arg2 types.Coin - // Result0 is the value of the 1st result returned from this method - // invocation. - Result0 types.Coin - // Result1 is the value of the 2nd result returned from this method - // invocation. - Result1 bool - // Result2 is the value of the 3rd result returned from this method - // invocation. - Result2 error -} - -// Args returns an interface slice containing the arguments of this -// invocation. -func (c LeverageKeeperWithdrawToModuleFuncCall) Args() []interface{} { - return []interface{}{c.Arg0, c.Arg1, c.Arg2} -} - -// Results returns an interface slice containing the results of this -// invocation. -func (c LeverageKeeperWithdrawToModuleFuncCall) Results() []interface{} { - return []interface{}{c.Result0, c.Result1, c.Result2} -} - -// MockOracleKeeper is a mock implementation of the OracleKeeper interface -// (from the package github.com/umee-network/umee/v5/x/metoken) used for -// unit testing. +// MockOracleKeeper is a mock of OracleKeeper interface. type MockOracleKeeper struct { - // AllMedianPricesFunc is an instance of a mock function object - // controlling the behavior of the method AllMedianPrices. - AllMedianPricesFunc *OracleKeeperAllMedianPricesFunc + ctrl *gomock.Controller + recorder *MockOracleKeeperMockRecorder } -// NewMockOracleKeeper creates a new mock of the OracleKeeper interface. All -// methods return zero values for all results, unless overwritten. -func NewMockOracleKeeper() *MockOracleKeeper { - return &MockOracleKeeper{ - AllMedianPricesFunc: &OracleKeeperAllMedianPricesFunc{ - defaultHook: func(types.Context) (r0 types2.Prices) { - return - }, - }, - } +// MockOracleKeeperMockRecorder is the mock recorder for MockOracleKeeper. +type MockOracleKeeperMockRecorder struct { + mock *MockOracleKeeper } -// NewStrictMockOracleKeeper creates a new mock of the OracleKeeper -// interface. All methods panic on invocation, unless overwritten. -func NewStrictMockOracleKeeper() *MockOracleKeeper { - return &MockOracleKeeper{ - AllMedianPricesFunc: &OracleKeeperAllMedianPricesFunc{ - defaultHook: func(types.Context) types2.Prices { - panic("unexpected invocation of MockOracleKeeper.AllMedianPrices") - }, - }, - } -} - -// NewMockOracleKeeperFrom creates a new mock of the MockOracleKeeper -// interface. All methods delegate to the given implementation, unless -// overwritten. -func NewMockOracleKeeperFrom(i metoken.OracleKeeper) *MockOracleKeeper { - return &MockOracleKeeper{ - AllMedianPricesFunc: &OracleKeeperAllMedianPricesFunc{ - defaultHook: i.AllMedianPrices, - }, - } -} - -// OracleKeeperAllMedianPricesFunc describes the behavior when the -// AllMedianPrices method of the parent MockOracleKeeper instance is -// invoked. -type OracleKeeperAllMedianPricesFunc struct { - defaultHook func(types.Context) types2.Prices - hooks []func(types.Context) types2.Prices - history []OracleKeeperAllMedianPricesFuncCall - mutex sync.Mutex -} - -// AllMedianPrices delegates to the next hook function in the queue and -// stores the parameter and result values of this invocation. -func (m *MockOracleKeeper) AllMedianPrices(v0 types.Context) types2.Prices { - r0 := m.AllMedianPricesFunc.nextHook()(v0) - m.AllMedianPricesFunc.appendCall(OracleKeeperAllMedianPricesFuncCall{v0, r0}) - return r0 -} - -// SetDefaultHook sets function that is called when the AllMedianPrices -// method of the parent MockOracleKeeper instance is invoked and the hook -// queue is empty. -func (f *OracleKeeperAllMedianPricesFunc) SetDefaultHook(hook func(types.Context) types2.Prices) { - f.defaultHook = hook -} - -// PushHook adds a function to the end of hook queue. Each invocation of the -// AllMedianPrices method of the parent MockOracleKeeper instance invokes -// the hook at the front of the queue and discards it. After the queue is -// empty, the default hook function is invoked for any future action. -func (f *OracleKeeperAllMedianPricesFunc) PushHook(hook func(types.Context) types2.Prices) { - f.mutex.Lock() - f.hooks = append(f.hooks, hook) - f.mutex.Unlock() -} - -// SetDefaultReturn calls SetDefaultHook with a function that returns the -// given values. -func (f *OracleKeeperAllMedianPricesFunc) SetDefaultReturn(r0 types2.Prices) { - f.SetDefaultHook(func(types.Context) types2.Prices { - return r0 - }) -} - -// PushReturn calls PushHook with a function that returns the given values. -func (f *OracleKeeperAllMedianPricesFunc) PushReturn(r0 types2.Prices) { - f.PushHook(func(types.Context) types2.Prices { - return r0 - }) -} - -func (f *OracleKeeperAllMedianPricesFunc) nextHook() func(types.Context) types2.Prices { - f.mutex.Lock() - defer f.mutex.Unlock() - - if len(f.hooks) == 0 { - return f.defaultHook - } - - hook := f.hooks[0] - f.hooks = f.hooks[1:] - return hook -} - -func (f *OracleKeeperAllMedianPricesFunc) appendCall(r0 OracleKeeperAllMedianPricesFuncCall) { - f.mutex.Lock() - f.history = append(f.history, r0) - f.mutex.Unlock() -} - -// History returns a sequence of OracleKeeperAllMedianPricesFuncCall objects -// describing the invocations of this function. -func (f *OracleKeeperAllMedianPricesFunc) History() []OracleKeeperAllMedianPricesFuncCall { - f.mutex.Lock() - history := make([]OracleKeeperAllMedianPricesFuncCall, len(f.history)) - copy(history, f.history) - f.mutex.Unlock() - - return history +// NewMockOracleKeeper creates a new mock instance. +func NewMockOracleKeeper(ctrl *gomock.Controller) *MockOracleKeeper { + mock := &MockOracleKeeper{ctrl: ctrl} + mock.recorder = &MockOracleKeeperMockRecorder{mock} + return mock } -// OracleKeeperAllMedianPricesFuncCall is an object that describes an -// invocation of method AllMedianPrices on an instance of MockOracleKeeper. -type OracleKeeperAllMedianPricesFuncCall struct { - // Arg0 is the value of the 1st argument passed to this method - // invocation. - Arg0 types.Context - // Result0 is the value of the 1st result returned from this method - // invocation. - Result0 types2.Prices +// EXPECT returns an object that allows the caller to indicate expected use. +func (m *MockOracleKeeper) EXPECT() *MockOracleKeeperMockRecorder { + return m.recorder } -// Args returns an interface slice containing the arguments of this -// invocation. -func (c OracleKeeperAllMedianPricesFuncCall) Args() []interface{} { - return []interface{}{c.Arg0} +// AllMedianPrices mocks base method. +func (m *MockOracleKeeper) AllMedianPrices(ctx types.Context) types1.Prices { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "AllMedianPrices", ctx) + ret0, _ := ret[0].(types1.Prices) + return ret0 } -// Results returns an interface slice containing the results of this -// invocation. -func (c OracleKeeperAllMedianPricesFuncCall) Results() []interface{} { - return []interface{}{c.Result0} +// AllMedianPrices indicates an expected call of AllMedianPrices. +func (mr *MockOracleKeeperMockRecorder) AllMedianPrices(ctx interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "AllMedianPrices", reflect.TypeOf((*MockOracleKeeper)(nil).AllMedianPrices), ctx) } diff --git a/x/oracle/keeper/historic_price.go b/x/oracle/keeper/historic_price.go index 4b265f5b7f..bad1b1f377 100644 --- a/x/oracle/keeper/historic_price.go +++ b/x/oracle/keeper/historic_price.go @@ -34,6 +34,16 @@ func (k Keeper) CalcAndSetHistoricMedian( denom string, ) error { historicPrices := k.historicPrices(ctx, denom, k.MaximumPriceStamps(ctx)) + if len(historicPrices) == 0 { + k.Logger(ctx).Error( + "There always should be an historic price before we attempt to make any median price. "+ + "This scenario should never happen.", + "denom", denom, + "block_height", ctx.BlockHeight(), + ) + return nil + } + median, err := decmath.Median(historicPrices) if err != nil { return errors.Wrap(err, "denom: "+denom) diff --git a/x/oracle/keeper/historic_price_test.go b/x/oracle/keeper/historic_price_test.go index ec07e08b3b..7744647cd5 100644 --- a/x/oracle/keeper/historic_price_test.go +++ b/x/oracle/keeper/historic_price_test.go @@ -16,6 +16,7 @@ func (s *IntegrationTestSuite) TestSetHistoraclePricing() { // prefix to test unique prefix safety when iterating for // similar prefixes displayDenomVariation := displayDenom + "test" + nonExistingDenom := "nonexistingdenom" // add multiple historic prices to store exchangeRates := []string{"1.0", "1.2", "1.1", "1.4", "1.1", "1.15", "1.2", "1.3", "1.2"} @@ -27,6 +28,8 @@ func (s *IntegrationTestSuite) TestSetHistoraclePricing() { s.Require().NoError(err) err = app.OracleKeeper.CalcAndSetHistoricMedian(ctx, displayDenomVariation) s.Require().NoError(err) + err = app.OracleKeeper.CalcAndSetHistoricMedian(ctx, nonExistingDenom) + s.Require().NoError(err) } // update blockheight diff --git a/x/ugov/keeper/genesis.go b/x/ugov/keeper/genesis.go index 52e27dcaf9..1da5a790f1 100644 --- a/x/ugov/keeper/genesis.go +++ b/x/ugov/keeper/genesis.go @@ -5,7 +5,7 @@ import ( ) func (k Keeper) ExportGenesis() *ugov.GenesisState { - cycleEndTime := k.GetInflationCycleEnd() + cycleEndTime := k.InflationCycleEnd() return &ugov.GenesisState{ MinGasPrice: k.MinGasPrice(), InflationParams: k.InflationParams(), diff --git a/x/ugov/keeper/keeper.go b/x/ugov/keeper/keeper.go index 13fbf814ed..291ec492a6 100644 --- a/x/ugov/keeper/keeper.go +++ b/x/ugov/keeper/keeper.go @@ -4,8 +4,11 @@ import ( "github.com/cosmos/cosmos-sdk/codec" storetypes "github.com/cosmos/cosmos-sdk/store/types" sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/umee-network/umee/v5/x/ugov" ) +var _ ugov.Keeper = Keeper{} + // Builder constructs Keeper by perparing all related dependencies (notably the store). type Builder struct { storeKey storetypes.StoreKey @@ -21,13 +24,18 @@ func NewKeeperBuilder( } } -func (kb Builder) Keeper(ctx *sdk.Context) IKeeper { +func (kb Builder) Keeper(ctx *sdk.Context) ugov.Keeper { return Keeper{ store: ctx.KVStore(kb.storeKey), cdc: kb.Cdc, } } +// functions to downcast Keeper constructor into super types. + +func (kb Builder) Params(ctx *sdk.Context) ugov.ParamsKeeper { return kb.Keeper(ctx) } +func (kb Builder) EmergencyGroup(ctx *sdk.Context) ugov.WithEmergencyGroup { return kb.Keeper(ctx) } + // Keeper provides a light interface for module data access and transformation type Keeper struct { store sdk.KVStore diff --git a/x/ugov/keeper/keeper_interfaces.go b/x/ugov/keeper/keeper_interfaces.go deleted file mode 100644 index b539933041..0000000000 --- a/x/ugov/keeper/keeper_interfaces.go +++ /dev/null @@ -1,31 +0,0 @@ -package keeper - -import ( - "time" - - sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/umee-network/umee/v5/x/ugov" -) - -type BKeeperI interface { - Keeper(ctx *sdk.Context) IKeeper -} - -type IKeeper interface { - IParams - ExportGenesis() *ugov.GenesisState - InitGenesis(gs *ugov.GenesisState) error -} - -type IParams interface { - SetMinGasPrice(p sdk.DecCoin) error - MinGasPrice() sdk.DecCoin - SetEmergencyGroup(p sdk.AccAddress) - EmergencyGroup() sdk.AccAddress - SetInflationParams(lp ugov.InflationParams) error - InflationParams() ugov.InflationParams - SetInflationCycleEnd(startTime time.Time) error - GetInflationCycleEnd() time.Time -} - -var _ IKeeper = Keeper{} diff --git a/x/ugov/keeper/params.go b/x/ugov/keeper/params.go index 6c31e724f4..7d5e82f754 100644 --- a/x/ugov/keeper/params.go +++ b/x/ugov/keeper/params.go @@ -48,7 +48,7 @@ func (k Keeper) SetInflationCycleEnd(cycleEnd time.Time) error { } // Returns zero unix time if the inflation cycle was not set. -func (k Keeper) GetInflationCycleEnd() time.Time { +func (k Keeper) InflationCycleEnd() time.Time { t, _ := store.GetTimeMs(k.store, ugov.KeyInflationCycleEnd) return t } diff --git a/x/ugov/keeper/params_test.go b/x/ugov/keeper/params_test.go index 6b2b762a13..4bc15c4c8a 100644 --- a/x/ugov/keeper/params_test.go +++ b/x/ugov/keeper/params_test.go @@ -61,12 +61,12 @@ func TestInflationCycleEnd(t *testing.T) { st := time.Time{} err := k.SetInflationCycleEnd(st) require.NoError(err) - end := k.GetInflationCycleEnd() + end := k.InflationCycleEnd() require.Equal(end.IsZero(), true, "it should be default zero time") cycleEnd := time.Now() err = k.SetInflationCycleEnd(cycleEnd) require.NoError(err) - end = k.GetInflationCycleEnd() + end = k.InflationCycleEnd() require.Equal(end, cycleEnd.Truncate(time.Millisecond), "inflation cycle end time should be same") } diff --git a/x/ugov/keeper/query_server.go b/x/ugov/keeper/query_server.go index 043c730445..d8252521c9 100644 --- a/x/ugov/keeper/query_server.go +++ b/x/ugov/keeper/query_server.go @@ -41,6 +41,6 @@ func (q Querier) InflationParams(ctx context.Context, _ *ugov.QueryInflationPara func (q Querier) InflationCycleEnd(ctx context.Context, _ *ugov.QueryInflationCycleEnd) ( *ugov.QueryInflationCycleEndResponse, error) { sdkCtx := sdk.UnwrapSDKContext(ctx) - cycleEndTime := q.Keeper(&sdkCtx).GetInflationCycleEnd() + cycleEndTime := q.Keeper(&sdkCtx).InflationCycleEnd() return &ugov.QueryInflationCycleEndResponse{End: &cycleEndTime}, nil } diff --git a/x/ugov/keeper/unit_test.go b/x/ugov/keeper/unit_test.go index 5c7cd63ae0..c5bef0bafe 100644 --- a/x/ugov/keeper/unit_test.go +++ b/x/ugov/keeper/unit_test.go @@ -23,7 +23,7 @@ func initKeeper(t *testing.T) TestKeeper { } type TestKeeper struct { - IKeeper + ugov.Keeper t *testing.T ctx *sdk.Context } diff --git a/x/ugov/keeper_interfaces.go b/x/ugov/keeper_interfaces.go new file mode 100644 index 0000000000..67e65037f8 --- /dev/null +++ b/x/ugov/keeper_interfaces.go @@ -0,0 +1,33 @@ +package ugov + +import ( + "time" + + sdk "github.com/cosmos/cosmos-sdk/types" +) + +type Keeper interface { + ParamsKeeper + WithEmergencyGroup + ExportGenesis() *GenesisState + InitGenesis(gs *GenesisState) error +} + +type ParamsKeeper interface { + SetMinGasPrice(p sdk.DecCoin) error + MinGasPrice() sdk.DecCoin + SetEmergencyGroup(p sdk.AccAddress) + SetInflationParams(lp InflationParams) error + InflationParams() InflationParams + SetInflationCycleEnd(startTime time.Time) error + InflationCycleEnd() time.Time +} + +type WithEmergencyGroup interface { + EmergencyGroup() sdk.AccAddress +} + +// Builder functions + +type EmergencyGroupBuilder func(*sdk.Context) WithEmergencyGroup +type ParamsKeeperBuilder func(*sdk.Context) ParamsKeeper diff --git a/x/ugov/mocks/constructors.go b/x/ugov/mocks/constructors.go new file mode 100644 index 0000000000..091c1d538e --- /dev/null +++ b/x/ugov/mocks/constructors.go @@ -0,0 +1,13 @@ +package mocks + +import ( + sdk "github.com/cosmos/cosmos-sdk/types" + ugov "github.com/umee-network/umee/v5/x/ugov" +) + +// NewUgovParamsBuilder creates a ParamsKeeper builder function +func NewUgovParamsBuilder(pk ugov.ParamsKeeper) ugov.ParamsKeeperBuilder { + return func(_ *sdk.Context) ugov.ParamsKeeper { + return pk + } +} diff --git a/x/ugov/mocks/keepers.go b/x/ugov/mocks/keepers.go new file mode 100644 index 0000000000..22c7476fc3 --- /dev/null +++ b/x/ugov/mocks/keepers.go @@ -0,0 +1,331 @@ +// Code generated by MockGen. DO NOT EDIT. +// Source: ./x/ugov/keeper_interfaces.go + +// Package mocks is a generated GoMock package. +package mocks + +import ( + reflect "reflect" + time "time" + + types "github.com/cosmos/cosmos-sdk/types" + gomock "github.com/golang/mock/gomock" + ugov "github.com/umee-network/umee/v5/x/ugov" +) + +// MockKeeper is a mock of Keeper interface. +type MockKeeper struct { + ctrl *gomock.Controller + recorder *MockKeeperMockRecorder +} + +// MockKeeperMockRecorder is the mock recorder for MockKeeper. +type MockKeeperMockRecorder struct { + mock *MockKeeper +} + +// NewMockKeeper creates a new mock instance. +func NewMockKeeper(ctrl *gomock.Controller) *MockKeeper { + mock := &MockKeeper{ctrl: ctrl} + mock.recorder = &MockKeeperMockRecorder{mock} + return mock +} + +// EXPECT returns an object that allows the caller to indicate expected use. +func (m *MockKeeper) EXPECT() *MockKeeperMockRecorder { + return m.recorder +} + +// EmergencyGroup mocks base method. +func (m *MockKeeper) EmergencyGroup() types.AccAddress { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "EmergencyGroup") + ret0, _ := ret[0].(types.AccAddress) + return ret0 +} + +// EmergencyGroup indicates an expected call of EmergencyGroup. +func (mr *MockKeeperMockRecorder) EmergencyGroup() *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "EmergencyGroup", reflect.TypeOf((*MockKeeper)(nil).EmergencyGroup)) +} + +// ExportGenesis mocks base method. +func (m *MockKeeper) ExportGenesis() *ugov.GenesisState { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "ExportGenesis") + ret0, _ := ret[0].(*ugov.GenesisState) + return ret0 +} + +// ExportGenesis indicates an expected call of ExportGenesis. +func (mr *MockKeeperMockRecorder) ExportGenesis() *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ExportGenesis", reflect.TypeOf((*MockKeeper)(nil).ExportGenesis)) +} + +// InflationCycleEnd mocks base method. +func (m *MockKeeper) InflationCycleEnd() time.Time { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "InflationCycleEnd") + ret0, _ := ret[0].(time.Time) + return ret0 +} + +// InflationCycleEnd indicates an expected call of InflationCycleEnd. +func (mr *MockKeeperMockRecorder) InflationCycleEnd() *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "InflationCycleEnd", reflect.TypeOf((*MockKeeper)(nil).InflationCycleEnd)) +} + +// InflationParams mocks base method. +func (m *MockKeeper) InflationParams() ugov.InflationParams { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "InflationParams") + ret0, _ := ret[0].(ugov.InflationParams) + return ret0 +} + +// InflationParams indicates an expected call of InflationParams. +func (mr *MockKeeperMockRecorder) InflationParams() *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "InflationParams", reflect.TypeOf((*MockKeeper)(nil).InflationParams)) +} + +// InitGenesis mocks base method. +func (m *MockKeeper) InitGenesis(gs *ugov.GenesisState) error { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "InitGenesis", gs) + ret0, _ := ret[0].(error) + return ret0 +} + +// InitGenesis indicates an expected call of InitGenesis. +func (mr *MockKeeperMockRecorder) InitGenesis(gs interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "InitGenesis", reflect.TypeOf((*MockKeeper)(nil).InitGenesis), gs) +} + +// MinGasPrice mocks base method. +func (m *MockKeeper) MinGasPrice() types.DecCoin { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "MinGasPrice") + ret0, _ := ret[0].(types.DecCoin) + return ret0 +} + +// MinGasPrice indicates an expected call of MinGasPrice. +func (mr *MockKeeperMockRecorder) MinGasPrice() *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "MinGasPrice", reflect.TypeOf((*MockKeeper)(nil).MinGasPrice)) +} + +// SetEmergencyGroup mocks base method. +func (m *MockKeeper) SetEmergencyGroup(p types.AccAddress) { + m.ctrl.T.Helper() + m.ctrl.Call(m, "SetEmergencyGroup", p) +} + +// SetEmergencyGroup indicates an expected call of SetEmergencyGroup. +func (mr *MockKeeperMockRecorder) SetEmergencyGroup(p interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "SetEmergencyGroup", reflect.TypeOf((*MockKeeper)(nil).SetEmergencyGroup), p) +} + +// SetInflationCycleEnd mocks base method. +func (m *MockKeeper) SetInflationCycleEnd(startTime time.Time) error { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "SetInflationCycleEnd", startTime) + ret0, _ := ret[0].(error) + return ret0 +} + +// SetInflationCycleEnd indicates an expected call of SetInflationCycleEnd. +func (mr *MockKeeperMockRecorder) SetInflationCycleEnd(startTime interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "SetInflationCycleEnd", reflect.TypeOf((*MockKeeper)(nil).SetInflationCycleEnd), startTime) +} + +// SetInflationParams mocks base method. +func (m *MockKeeper) SetInflationParams(lp ugov.InflationParams) error { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "SetInflationParams", lp) + ret0, _ := ret[0].(error) + return ret0 +} + +// SetInflationParams indicates an expected call of SetInflationParams. +func (mr *MockKeeperMockRecorder) SetInflationParams(lp interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "SetInflationParams", reflect.TypeOf((*MockKeeper)(nil).SetInflationParams), lp) +} + +// SetMinGasPrice mocks base method. +func (m *MockKeeper) SetMinGasPrice(p types.DecCoin) error { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "SetMinGasPrice", p) + ret0, _ := ret[0].(error) + return ret0 +} + +// SetMinGasPrice indicates an expected call of SetMinGasPrice. +func (mr *MockKeeperMockRecorder) SetMinGasPrice(p interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "SetMinGasPrice", reflect.TypeOf((*MockKeeper)(nil).SetMinGasPrice), p) +} + +// MockParamsKeeper is a mock of ParamsKeeper interface. +type MockParamsKeeper struct { + ctrl *gomock.Controller + recorder *MockParamsKeeperMockRecorder +} + +// MockParamsKeeperMockRecorder is the mock recorder for MockParamsKeeper. +type MockParamsKeeperMockRecorder struct { + mock *MockParamsKeeper +} + +// NewMockParamsKeeper creates a new mock instance. +func NewMockParamsKeeper(ctrl *gomock.Controller) *MockParamsKeeper { + mock := &MockParamsKeeper{ctrl: ctrl} + mock.recorder = &MockParamsKeeperMockRecorder{mock} + return mock +} + +// EXPECT returns an object that allows the caller to indicate expected use. +func (m *MockParamsKeeper) EXPECT() *MockParamsKeeperMockRecorder { + return m.recorder +} + +// InflationCycleEnd mocks base method. +func (m *MockParamsKeeper) InflationCycleEnd() time.Time { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "InflationCycleEnd") + ret0, _ := ret[0].(time.Time) + return ret0 +} + +// InflationCycleEnd indicates an expected call of InflationCycleEnd. +func (mr *MockParamsKeeperMockRecorder) InflationCycleEnd() *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "InflationCycleEnd", reflect.TypeOf((*MockParamsKeeper)(nil).InflationCycleEnd)) +} + +// InflationParams mocks base method. +func (m *MockParamsKeeper) InflationParams() ugov.InflationParams { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "InflationParams") + ret0, _ := ret[0].(ugov.InflationParams) + return ret0 +} + +// InflationParams indicates an expected call of InflationParams. +func (mr *MockParamsKeeperMockRecorder) InflationParams() *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "InflationParams", reflect.TypeOf((*MockParamsKeeper)(nil).InflationParams)) +} + +// MinGasPrice mocks base method. +func (m *MockParamsKeeper) MinGasPrice() types.DecCoin { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "MinGasPrice") + ret0, _ := ret[0].(types.DecCoin) + return ret0 +} + +// MinGasPrice indicates an expected call of MinGasPrice. +func (mr *MockParamsKeeperMockRecorder) MinGasPrice() *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "MinGasPrice", reflect.TypeOf((*MockParamsKeeper)(nil).MinGasPrice)) +} + +// SetEmergencyGroup mocks base method. +func (m *MockParamsKeeper) SetEmergencyGroup(p types.AccAddress) { + m.ctrl.T.Helper() + m.ctrl.Call(m, "SetEmergencyGroup", p) +} + +// SetEmergencyGroup indicates an expected call of SetEmergencyGroup. +func (mr *MockParamsKeeperMockRecorder) SetEmergencyGroup(p interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "SetEmergencyGroup", reflect.TypeOf((*MockParamsKeeper)(nil).SetEmergencyGroup), p) +} + +// SetInflationCycleEnd mocks base method. +func (m *MockParamsKeeper) SetInflationCycleEnd(startTime time.Time) error { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "SetInflationCycleEnd", startTime) + ret0, _ := ret[0].(error) + return ret0 +} + +// SetInflationCycleEnd indicates an expected call of SetInflationCycleEnd. +func (mr *MockParamsKeeperMockRecorder) SetInflationCycleEnd(startTime interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "SetInflationCycleEnd", reflect.TypeOf((*MockParamsKeeper)(nil).SetInflationCycleEnd), startTime) +} + +// SetInflationParams mocks base method. +func (m *MockParamsKeeper) SetInflationParams(lp ugov.InflationParams) error { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "SetInflationParams", lp) + ret0, _ := ret[0].(error) + return ret0 +} + +// SetInflationParams indicates an expected call of SetInflationParams. +func (mr *MockParamsKeeperMockRecorder) SetInflationParams(lp interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "SetInflationParams", reflect.TypeOf((*MockParamsKeeper)(nil).SetInflationParams), lp) +} + +// SetMinGasPrice mocks base method. +func (m *MockParamsKeeper) SetMinGasPrice(p types.DecCoin) error { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "SetMinGasPrice", p) + ret0, _ := ret[0].(error) + return ret0 +} + +// SetMinGasPrice indicates an expected call of SetMinGasPrice. +func (mr *MockParamsKeeperMockRecorder) SetMinGasPrice(p interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "SetMinGasPrice", reflect.TypeOf((*MockParamsKeeper)(nil).SetMinGasPrice), p) +} + +// MockWithEmergencyGroup is a mock of WithEmergencyGroup interface. +type MockWithEmergencyGroup struct { + ctrl *gomock.Controller + recorder *MockWithEmergencyGroupMockRecorder +} + +// MockWithEmergencyGroupMockRecorder is the mock recorder for MockWithEmergencyGroup. +type MockWithEmergencyGroupMockRecorder struct { + mock *MockWithEmergencyGroup +} + +// NewMockWithEmergencyGroup creates a new mock instance. +func NewMockWithEmergencyGroup(ctrl *gomock.Controller) *MockWithEmergencyGroup { + mock := &MockWithEmergencyGroup{ctrl: ctrl} + mock.recorder = &MockWithEmergencyGroupMockRecorder{mock} + return mock +} + +// EXPECT returns an object that allows the caller to indicate expected use. +func (m *MockWithEmergencyGroup) EXPECT() *MockWithEmergencyGroupMockRecorder { + return m.recorder +} + +// EmergencyGroup mocks base method. +func (m *MockWithEmergencyGroup) EmergencyGroup() types.AccAddress { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "EmergencyGroup") + ret0, _ := ret[0].(types.AccAddress) + return ret0 +} + +// EmergencyGroup indicates an expected call of EmergencyGroup. +func (mr *MockWithEmergencyGroupMockRecorder) EmergencyGroup() *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "EmergencyGroup", reflect.TypeOf((*MockWithEmergencyGroup)(nil).EmergencyGroup)) +} diff --git a/x/uibc/expected_keepers.go b/x/uibc/expected_keepers.go index 2b8f61a655..6c9b3931a9 100644 --- a/x/uibc/expected_keepers.go +++ b/x/uibc/expected_keepers.go @@ -16,7 +16,7 @@ type BankKeeper interface { type Leverage interface { GetTokenSettings(ctx sdk.Context, baseDenom string) (ltypes.Token, error) - ExchangeUToken(ctx sdk.Context, uToken sdk.Coin) (sdk.Coin, error) + ToToken(ctx sdk.Context, uToken sdk.Coin) (sdk.Coin, error) DeriveExchangeRate(ctx sdk.Context, denom string) sdk.Dec } diff --git a/x/uibc/mocks/keepers.go b/x/uibc/mocks/keepers.go index cd0a9be211..0f0154c282 100644 --- a/x/uibc/mocks/keepers.go +++ b/x/uibc/mocks/keepers.go @@ -75,31 +75,31 @@ func (mr *MockBankKeeperMockRecorder) SetDenomMetaData(ctx, denomMetaData interf return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "SetDenomMetaData", reflect.TypeOf((*MockBankKeeper)(nil).SetDenomMetaData), ctx, denomMetaData) } -// MockLeverageKeeper is a mock of LeverageKeeper interface. -type MockLeverageKeeper struct { +// MockLeverage is a mock of Leverage interface. +type MockLeverage struct { ctrl *gomock.Controller - recorder *MockLeverageKeeperMockRecorder + recorder *MockLeverageMockRecorder } -// MockLeverageKeeperMockRecorder is the mock recorder for MockLeverageKeeper. -type MockLeverageKeeperMockRecorder struct { - mock *MockLeverageKeeper +// MockLeverageMockRecorder is the mock recorder for MockLeverage. +type MockLeverageMockRecorder struct { + mock *MockLeverage } -// NewMockLeverageKeeper creates a new mock instance. -func NewMockLeverageKeeper(ctrl *gomock.Controller) *MockLeverageKeeper { - mock := &MockLeverageKeeper{ctrl: ctrl} - mock.recorder = &MockLeverageKeeperMockRecorder{mock} +// NewMockLeverage creates a new mock instance. +func NewMockLeverage(ctrl *gomock.Controller) *MockLeverage { + mock := &MockLeverage{ctrl: ctrl} + mock.recorder = &MockLeverageMockRecorder{mock} return mock } // EXPECT returns an object that allows the caller to indicate expected use. -func (m *MockLeverageKeeper) EXPECT() *MockLeverageKeeperMockRecorder { +func (m *MockLeverage) EXPECT() *MockLeverageMockRecorder { return m.recorder } // DeriveExchangeRate mocks base method. -func (m *MockLeverageKeeper) DeriveExchangeRate(ctx types.Context, denom string) types.Dec { +func (m *MockLeverage) DeriveExchangeRate(ctx types.Context, denom string) types.Dec { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "DeriveExchangeRate", ctx, denom) ret0, _ := ret[0].(types.Dec) @@ -107,39 +107,39 @@ func (m *MockLeverageKeeper) DeriveExchangeRate(ctx types.Context, denom string) } // DeriveExchangeRate indicates an expected call of DeriveExchangeRate. -func (mr *MockLeverageKeeperMockRecorder) DeriveExchangeRate(ctx, denom interface{}) *gomock.Call { +func (mr *MockLeverageMockRecorder) DeriveExchangeRate(ctx, denom interface{}) *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "DeriveExchangeRate", reflect.TypeOf((*MockLeverageKeeper)(nil).DeriveExchangeRate), ctx, denom) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "DeriveExchangeRate", reflect.TypeOf((*MockLeverage)(nil).DeriveExchangeRate), ctx, denom) } -// ExchangeUToken mocks base method. -func (m *MockLeverageKeeper) ExchangeUToken(ctx types.Context, uToken types.Coin) (types.Coin, error) { +// GetTokenSettings mocks base method. +func (m *MockLeverage) GetTokenSettings(ctx types.Context, baseDenom string) (types1.Token, error) { m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "ExchangeUToken", ctx, uToken) - ret0, _ := ret[0].(types.Coin) + ret := m.ctrl.Call(m, "GetTokenSettings", ctx, baseDenom) + ret0, _ := ret[0].(types1.Token) ret1, _ := ret[1].(error) return ret0, ret1 } -// ExchangeUToken indicates an expected call of ExchangeUToken. -func (mr *MockLeverageKeeperMockRecorder) ExchangeUToken(ctx, uToken interface{}) *gomock.Call { +// GetTokenSettings indicates an expected call of GetTokenSettings. +func (mr *MockLeverageMockRecorder) GetTokenSettings(ctx, baseDenom interface{}) *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ExchangeUToken", reflect.TypeOf((*MockLeverageKeeper)(nil).ExchangeUToken), ctx, uToken) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetTokenSettings", reflect.TypeOf((*MockLeverage)(nil).GetTokenSettings), ctx, baseDenom) } -// GetTokenSettings mocks base method. -func (m *MockLeverageKeeper) GetTokenSettings(ctx types.Context, baseDenom string) (types1.Token, error) { +// ToToken mocks base method. +func (m *MockLeverage) ToToken(ctx types.Context, uToken types.Coin) (types.Coin, error) { m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "GetTokenSettings", ctx, baseDenom) - ret0, _ := ret[0].(types1.Token) + ret := m.ctrl.Call(m, "ToToken", ctx, uToken) + ret0, _ := ret[0].(types.Coin) ret1, _ := ret[1].(error) return ret0, ret1 } -// GetTokenSettings indicates an expected call of GetTokenSettings. -func (mr *MockLeverageKeeperMockRecorder) GetTokenSettings(ctx, baseDenom interface{}) *gomock.Call { +// ToToken indicates an expected call of ToToken. +func (mr *MockLeverageMockRecorder) ToToken(ctx, uToken interface{}) *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetTokenSettings", reflect.TypeOf((*MockLeverageKeeper)(nil).GetTokenSettings), ctx, baseDenom) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ToToken", reflect.TypeOf((*MockLeverage)(nil).ToToken), ctx, uToken) } // MockOracle is a mock of Oracle interface. diff --git a/x/uibc/quota/keeper/intest/genesis_test.go b/x/uibc/quota/keeper/intest/genesis_test.go index 0334899873..307650385d 100644 --- a/x/uibc/quota/keeper/intest/genesis_test.go +++ b/x/uibc/quota/keeper/intest/genesis_test.go @@ -1,4 +1,4 @@ -package keeper_test +package intest import ( "testing" diff --git a/x/uibc/quota/keeper/intest/grpc_query_test.go b/x/uibc/quota/keeper/intest/grpc_query_test.go index d72a14f772..8272c42d91 100644 --- a/x/uibc/quota/keeper/intest/grpc_query_test.go +++ b/x/uibc/quota/keeper/intest/grpc_query_test.go @@ -1,4 +1,4 @@ -package keeper_test +package intest import ( "testing" diff --git a/x/uibc/quota/keeper/intest/msg_server_test.go b/x/uibc/quota/keeper/intest/msg_server_test.go index 3fc4c3a97a..5c80ac0c50 100644 --- a/x/uibc/quota/keeper/intest/msg_server_test.go +++ b/x/uibc/quota/keeper/intest/msg_server_test.go @@ -1,4 +1,4 @@ -package keeper_test +package intest import ( "testing" diff --git a/x/uibc/quota/keeper/intest/quota_test.go b/x/uibc/quota/keeper/intest/quota_test.go index 7fb32c0d65..59409d3577 100644 --- a/x/uibc/quota/keeper/intest/quota_test.go +++ b/x/uibc/quota/keeper/intest/quota_test.go @@ -1,4 +1,4 @@ -package keeper_test +package intest import ( "testing" @@ -38,14 +38,12 @@ func TestKeeper_CheckAndUpdateQuota(t *testing.T) { umeeUToken := sdk.NewCoin("u/umee", sdkmath.NewInt(100)) atomToken := sdk.NewCoin("atom", sdkmath.NewInt(1000)) daiToken := sdk.NewCoin("dai", sdkmath.NewInt(50)) - // gomock initializations - leverageCtrl := gomock.NewController(t) - defer leverageCtrl.Finish() - leverageMock := mocks.NewMockLeverageKeeper(leverageCtrl) - oracleCtrl := gomock.NewController(t) - defer oracleCtrl.Finish() - oracleMock := mocks.NewMockOracle(oracleCtrl) + ctrl := gomock.NewController(t) + defer ctrl.Finish() + + leverageMock := mocks.NewMockLeverage(ctrl) + oracleMock := mocks.NewMockOracle(ctrl) marshaller := codec.NewProtoCodec(nil) ctx, k := initKeeper(t, marshaller, nil, leverageMock, oracleMock) @@ -53,14 +51,14 @@ func TestKeeper_CheckAndUpdateQuota(t *testing.T) { assert.NilError(t, err) // invalid token, returns error from mock leverage - leverageMock.EXPECT().ExchangeUToken(ctx, invalidToken).Return(sdk.Coin{}, ltypes.ErrNotUToken).AnyTimes() + leverageMock.EXPECT().ToToken(ctx, invalidToken).Return(sdk.Coin{}, ltypes.ErrNotUToken).AnyTimes() err = k.CheckAndUpdateQuota(invalidToken.Denom, invalidToken.Amount) assert.ErrorIs(t, err, ltypes.ErrNotUToken) // UMEE uToken, exchanges correctly, but returns ErrNotRegisteredToken when trying to get Token's settings // from leverage mock keeper - leverageMock.EXPECT().ExchangeUToken(ctx, umeeUToken).Return( + leverageMock.EXPECT().ToToken(ctx, umeeUToken).Return( sdk.NewCoin("umee", sdkmath.NewInt(100)), nil, ).AnyTimes() @@ -102,14 +100,12 @@ func TestKeeper_UndoUpdateQuota(t *testing.T) { umeeQuota := sdkmath.NewInt(10000) umeeToken := sdk.NewCoin("umee", umeeAmount) umeeExponent := 6 - // gomock initializations - leverageCtrl := gomock.NewController(t) - defer leverageCtrl.Finish() - leverageMock := mocks.NewMockLeverageKeeper(leverageCtrl) - - oracleCtrl := gomock.NewController(t) - defer oracleCtrl.Finish() - oracleMock := mocks.NewMockOracle(oracleCtrl) + + ctrl := gomock.NewController(t) + defer ctrl.Finish() + + leverageMock := mocks.NewMockLeverage(ctrl) + oracleMock := mocks.NewMockOracle(ctrl) marshaller := codec.NewProtoCodec(nil) ctx, k := initKeeper(t, marshaller, nil, leverageMock, oracleMock) diff --git a/x/uibc/quota/keeper/intest/suite_test.go b/x/uibc/quota/keeper/intest/suite_test.go index d39fd4e372..5714b798cd 100644 --- a/x/uibc/quota/keeper/intest/suite_test.go +++ b/x/uibc/quota/keeper/intest/suite_test.go @@ -1,4 +1,4 @@ -package keeper_test +package intest import ( "fmt" diff --git a/x/uibc/quota/keeper/mocks_test.go b/x/uibc/quota/keeper/mocks_test.go index 33c2df0e3c..2f51d13ac1 100644 --- a/x/uibc/quota/keeper/mocks_test.go +++ b/x/uibc/quota/keeper/mocks_test.go @@ -22,7 +22,7 @@ func (k LeverageKeeper) GetTokenSettings(_ sdk.Context, baseDenom string) (ltype return ts, nil } -func (k LeverageKeeper) ExchangeUToken(_ sdk.Context, _ sdk.Coin) (sdk.Coin, error) { +func (k LeverageKeeper) ToToken(_ sdk.Context, _ sdk.Coin) (sdk.Coin, error) { panic("not implemented") } diff --git a/x/uibc/quota/keeper/quota.go b/x/uibc/quota/keeper/quota.go index 57395916bf..f2b9d131f4 100644 --- a/x/uibc/quota/keeper/quota.go +++ b/x/uibc/quota/keeper/quota.go @@ -11,6 +11,7 @@ import ( "github.com/cosmos/ibc-go/v6/modules/core/exported" "github.com/umee-network/umee/v5/util" + "github.com/umee-network/umee/v5/util/coin" "github.com/umee-network/umee/v5/util/store" ltypes "github.com/umee-network/umee/v5/x/leverage/types" "github.com/umee-network/umee/v5/x/uibc" @@ -139,9 +140,9 @@ func (k Keeper) getExchangePrice(denom string, amount sdkmath.Int) (sdk.Dec, err ) // convert to base asset if it is `uToken` - if ltypes.HasUTokenPrefix(denom) { + if coin.HasUTokenPrefix(denom) { // NOTE: to avoid ctx, we can use similar approach: create a leverage keeper builder - transferCoin, err = k.leverage.ExchangeUToken(*k.ctx, transferCoin) + transferCoin, err = k.leverage.ToToken(*k.ctx, transferCoin) if err != nil { return sdk.Dec{}, err }