From 3f1478dc9a3e430b01f6b36952b4473dea8c0b7e Mon Sep 17 00:00:00 2001 From: Amit Yadav Date: Mon, 18 Nov 2024 19:28:06 +0530 Subject: [PATCH] Discount changes (#957) * change discount values * more changes * get discount in amm: * ifx tests * fix tests * fix * tradeshield fix * use tier structure * update tests * fixing tier keeper pointers (#958) * fixing tier keeper pointers * fixing tier keeper pointers * fixing tier keeper pointers * fix * fix * add discoumt to perpetual * fix tests * review changes --------- Co-authored-by: Abhinav Kumar <57705190+avkr003@users.noreply.github.com> --- app/keepers/keepers.go | 10 +- app/modules.go | 4 +- proto/elys/tier/query.proto | 5 +- proto/elys/tier/userdata.proto | 22 ++ testutil/keeper/amm.go | 4 +- testutil/keeper/tradeshield.go | 4 +- x/accountedpool/types/mocks/amm_keeper.go | 2 +- x/accountedpool/types/mocks/bank_keeper.go | 88 ++--- .../types/mocks/perpetual_keeper.go | 2 +- x/accountedpool/types/query.pb.go | 1 - x/accountedpool/types/tx.pb.go | 1 - x/amm/keeper/keeper.go | 15 +- x/amm/keeper/route_exact_amount_in.go | 11 +- x/amm/keeper/route_exact_amount_out.go | 11 +- x/amm/types/expected_keepers.go | 7 + x/amm/types/mocks/accounted_pool_keeper.go | 16 +- x/amm/types/mocks/oracle_keeper.go | 2 +- x/amm/types/query.pb.go | 1 - x/amm/types/tx.pb.go | 1 - x/assetprofile/types/query.pb.go | 1 - x/assetprofile/types/tx.pb.go | 1 - x/burner/types/mocks/bank_keeper.go | 2 +- x/burner/types/query.pb.go | 1 - x/burner/types/tx.pb.go | 1 - x/commitment/types/query.pb.go | 1 - x/commitment/types/tx.pb.go | 1 - x/epochs/types/query.pb.go | 1 - x/estaking/types/query.pb.go | 1 - x/estaking/types/tx.pb.go | 1 - x/leveragelp/types/mocks/bank_keeper.go | 183 +++++----- x/leveragelp/types/query.pb.go | 1 - x/leveragelp/types/tx.pb.go | 1 - x/masterchef/types/query.pb.go | 1 - x/masterchef/types/tx.pb.go | 1 - x/oracle/types/query.pb.go | 1 - x/oracle/types/tx.pb.go | 1 - x/parameter/types/query.pb.go | 1 - x/parameter/types/tx.pb.go | 1 - x/perpetual/keeper/estimate_and_repay.go | 7 +- x/perpetual/keeper/estimate_swap.go | 23 +- x/perpetual/keeper/keeper.go | 19 +- x/perpetual/keeper/mtp_health.go | 4 +- x/perpetual/keeper/process_open.go | 4 +- x/perpetual/keeper/query_open_estimation.go | 7 +- x/perpetual/keeper/query_pool_test.go | 5 +- x/perpetual/types/query.pb.go | 1 - x/perpetual/types/tx.pb.go | 1 - x/stablestake/types/query.pb.go | 1 - x/stablestake/types/tx.pb.go | 1 - x/tier/keeper/portfolio.go | 12 +- x/tier/keeper/portfolio_test.go | 9 +- x/tier/keeper/query_calculate_discount.go | 8 +- x/tier/types/query.pb.go | 264 ++++++-------- x/tier/types/tx.pb.go | 1 - x/tier/types/types.go | 23 ++ x/tier/types/userdata.pb.go | 331 ++++++++++++++++-- x/tokenomics/types/query.pb.go | 1 - x/tokenomics/types/tx.pb.go | 1 - x/tradeshield/keeper/keeper.go | 13 +- .../keeper/pending_spot_order_test.go | 10 +- x/tradeshield/types/expected_keepers.go | 4 +- x/tradeshield/types/mocks/amm_keeper.go | 2 +- x/tradeshield/types/mocks/perpetual_keeper.go | 2 +- x/tradeshield/types/mocks/tier_keeper.go | 28 +- x/tradeshield/types/query.pb.go | 1 - x/tradeshield/types/tx.pb.go | 1 - x/transferhook/keeper/keeper.go | 4 +- x/transferhook/keeper/swap.go | 2 +- x/transferhook/keeper/swap_test.go | 4 +- x/transferhook/types/query.pb.go | 1 - 70 files changed, 754 insertions(+), 450 deletions(-) diff --git a/app/keepers/keepers.go b/app/keepers/keepers.go index 7b123aa97..8c75d4ebe 100644 --- a/app/keepers/keepers.go +++ b/app/keepers/keepers.go @@ -164,7 +164,7 @@ type AppKeepers struct { LeveragelpKeeper *leveragelpmodulekeeper.Keeper MasterchefKeeper masterchefmodulekeeper.Keeper EstakingKeeper *estakingmodulekeeper.Keeper - TierKeeper tiermodulekeeper.Keeper + TierKeeper *tiermodulekeeper.Keeper TradeshieldKeeper tradeshieldmodulekeeper.Keeper // FIXME: disabled to avoid dependency with wasm @@ -478,6 +478,7 @@ func NewAppKeeper( app.CommitmentKeeper, app.AssetprofileKeeper, app.AccountedPoolKeeper, + app.TierKeeper, ) app.StablestakeKeeper = stablestakekeeper.NewKeeper( @@ -514,6 +515,7 @@ func NewAppKeeper( app.OracleKeeper, app.AssetprofileKeeper, &app.ParameterKeeper, + app.TierKeeper, ) app.MasterchefKeeper = *masterchefmodulekeeper.NewKeeper( @@ -544,7 +546,7 @@ func NewAppKeeper( app.TransferhookKeeper = *transferhookkeeper.NewKeeper( appCodec, runtime.NewKVStoreService(app.keys[transferhooktypes.StoreKey]), - *app.AmmKeeper) + app.AmmKeeper) //app.ConsumerKeeper = ccvconsumerkeeper.NewKeeper( // appCodec, @@ -621,7 +623,7 @@ func NewAppKeeper( app.AccountedPoolKeeper, ) - app.TierKeeper = *tiermodulekeeper.NewKeeper( + app.TierKeeper = tiermodulekeeper.NewKeeper( appCodec, runtime.NewKVStoreService(app.keys[tiermoduletypes.StoreKey]), app.BankKeeper, @@ -636,6 +638,8 @@ func NewAppKeeper( app.LeveragelpKeeper, app.StablestakeKeeper, ) + app.AmmKeeper.SetTierKeeper(app.TierKeeper) + app.PerpetualKeeper.SetTierKeeper(app.TierKeeper) app.TradeshieldKeeper = *tradeshieldmodulekeeper.NewKeeper( appCodec, diff --git a/app/modules.go b/app/modules.go index 1f257a172..8eea5ef7d 100644 --- a/app/modules.go +++ b/app/modules.go @@ -160,7 +160,7 @@ func appModules( masterchefmodule.NewAppModule(appCodec, app.MasterchefKeeper, app.AccountKeeper, app.BankKeeper), estakingmodule.NewAppModule(appCodec, *app.EstakingKeeper, app.AccountKeeper, app.BankKeeper), perpetualmodule.NewAppModule(appCodec, app.PerpetualKeeper, app.AccountKeeper, app.BankKeeper), - tiermodule.NewAppModule(appCodec, app.TierKeeper, app.AccountKeeper, app.BankKeeper), + tiermodule.NewAppModule(appCodec, *app.TierKeeper, app.AccountKeeper, app.BankKeeper), tradeshieldmodule.NewAppModule(appCodec, app.TradeshieldKeeper, app.AccountKeeper, app.BankKeeper), } } @@ -220,7 +220,7 @@ func simulationModules( masterchefmodule.NewAppModule(appCodec, app.MasterchefKeeper, app.AccountKeeper, app.BankKeeper), estakingmodule.NewAppModule(appCodec, *app.EstakingKeeper, app.AccountKeeper, app.BankKeeper), perpetualmodule.NewAppModule(appCodec, app.PerpetualKeeper, app.AccountKeeper, app.BankKeeper), - tiermodule.NewAppModule(appCodec, app.TierKeeper, app.AccountKeeper, app.BankKeeper), + tiermodule.NewAppModule(appCodec, *app.TierKeeper, app.AccountKeeper, app.BankKeeper), tradeshieldmodule.NewAppModule(appCodec, app.TradeshieldKeeper, app.AccountKeeper, app.BankKeeper), } } diff --git a/proto/elys/tier/query.proto b/proto/elys/tier/query.proto index e34a4d875..1ef01ee4b 100644 --- a/proto/elys/tier/query.proto +++ b/proto/elys/tier/query.proto @@ -118,9 +118,8 @@ message QueryAllPortfolioResponse { message QueryCalculateDiscountRequest { string user = 1; } message QueryCalculateDiscountResponse { - string discount = 1; - string tier = 2; - string portfolio = 3; + MembershipTier membership_tier = 1; + string portfolio = 2; } message QueryLeverageLpTotalRequest { string user = 1; } diff --git a/proto/elys/tier/userdata.proto b/proto/elys/tier/userdata.proto index 6fc8d3d16..8a1dc3b0f 100644 --- a/proto/elys/tier/userdata.proto +++ b/proto/elys/tier/userdata.proto @@ -2,6 +2,7 @@ syntax = "proto3"; package elys.tier; import "gogoproto/gogo.proto"; +import "cosmos_proto/cosmos.proto"; option go_package = "github.com/elys-network/elys/x/tier/types"; @@ -18,4 +19,25 @@ message Pool { (gogoproto.customtype) = "cosmossdk.io/math.Int", (gogoproto.nullable) = false ]; +} + +enum MembershipTierType { + BRONZE = 0; + SILVER = 1; + GOLD = 2; + PLATINUM = 3; +} + +message MembershipTier { + string minimum_portfolio = 1 [ + (cosmos_proto.scalar) = "cosmos.Dec", + (gogoproto.customtype) = "cosmossdk.io/math.LegacyDec", + (gogoproto.nullable) = false + ]; + MembershipTierType membership = 2; + string discount = 3 [ + (cosmos_proto.scalar) = "cosmos.Dec", + (gogoproto.customtype) = "cosmossdk.io/math.LegacyDec", + (gogoproto.nullable) = false + ]; } \ No newline at end of file diff --git a/testutil/keeper/amm.go b/testutil/keeper/amm.go index 380dffc6a..f4951e64a 100644 --- a/testutil/keeper/amm.go +++ b/testutil/keeper/amm.go @@ -1,9 +1,10 @@ package keeper import ( + "testing" + "cosmossdk.io/store/metrics" "github.com/cosmos/cosmos-sdk/runtime" - "testing" "cosmossdk.io/log" "cosmossdk.io/store" @@ -50,6 +51,7 @@ func AmmKeeper(t testing.TB) (*keeper.Keeper, sdk.Context, *mocks.AccountedPoolK nil, nil, accountedPoolKeeper, + nil, ) ctx := sdk.NewContext(stateStore, tmproto.Header{}, false, log.NewNopLogger()) diff --git a/testutil/keeper/tradeshield.go b/testutil/keeper/tradeshield.go index ade2808b1..7984b2656 100644 --- a/testutil/keeper/tradeshield.go +++ b/testutil/keeper/tradeshield.go @@ -1,9 +1,10 @@ package keeper import ( + "testing" + "cosmossdk.io/store/metrics" "github.com/cosmos/cosmos-sdk/runtime" - "testing" "cosmossdk.io/log" "cosmossdk.io/store" @@ -36,7 +37,6 @@ func TradeshieldKeeper(t testing.TB) (*keeper.Keeper, sdk.Context, *mocks.AmmKee ammKeeper := mocks.NewAmmKeeper(t) tierKeeper := mocks.NewTierKeeper(t) perpetualKeeper := mocks.NewPerpetualKeeper(t) - k := keeper.NewKeeper( cdc, storeService, diff --git a/x/accountedpool/types/mocks/amm_keeper.go b/x/accountedpool/types/mocks/amm_keeper.go index 5aff82e70..e2bb3bea8 100644 --- a/x/accountedpool/types/mocks/amm_keeper.go +++ b/x/accountedpool/types/mocks/amm_keeper.go @@ -1,4 +1,4 @@ -// Code generated by mockery v2.46.3. DO NOT EDIT. +// Code generated by mockery v2.47.0. DO NOT EDIT. package mocks diff --git a/x/accountedpool/types/mocks/bank_keeper.go b/x/accountedpool/types/mocks/bank_keeper.go index de48f2cfe..53bcf0a4d 100644 --- a/x/accountedpool/types/mocks/bank_keeper.go +++ b/x/accountedpool/types/mocks/bank_keeper.go @@ -1,8 +1,10 @@ -// Code generated by mockery v2.46.3. DO NOT EDIT. +// Code generated by mockery v2.47.0. DO NOT EDIT. package mocks import ( + context "context" + types "github.com/cosmos/cosmos-sdk/types" mock "github.com/stretchr/testify/mock" ) @@ -67,7 +69,7 @@ func (_c *BankKeeper_BlockedAddr_Call) RunAndReturn(run func(types.AccAddress) b } // GetAllBalances provides a mock function with given fields: ctx, addr -func (_m *BankKeeper) GetAllBalances(ctx types.Context, addr types.AccAddress) types.Coins { +func (_m *BankKeeper) GetAllBalances(ctx context.Context, addr types.AccAddress) types.Coins { ret := _m.Called(ctx, addr) if len(ret) == 0 { @@ -75,7 +77,7 @@ func (_m *BankKeeper) GetAllBalances(ctx types.Context, addr types.AccAddress) t } var r0 types.Coins - if rf, ok := ret.Get(0).(func(types.Context, types.AccAddress) types.Coins); ok { + if rf, ok := ret.Get(0).(func(context.Context, types.AccAddress) types.Coins); ok { r0 = rf(ctx, addr) } else { if ret.Get(0) != nil { @@ -92,15 +94,15 @@ type BankKeeper_GetAllBalances_Call struct { } // GetAllBalances is a helper method to define mock.On call -// - ctx types.Context +// - ctx context.Context // - addr types.AccAddress func (_e *BankKeeper_Expecter) GetAllBalances(ctx interface{}, addr interface{}) *BankKeeper_GetAllBalances_Call { return &BankKeeper_GetAllBalances_Call{Call: _e.mock.On("GetAllBalances", ctx, addr)} } -func (_c *BankKeeper_GetAllBalances_Call) Run(run func(ctx types.Context, addr types.AccAddress)) *BankKeeper_GetAllBalances_Call { +func (_c *BankKeeper_GetAllBalances_Call) Run(run func(ctx context.Context, addr types.AccAddress)) *BankKeeper_GetAllBalances_Call { _c.Call.Run(func(args mock.Arguments) { - run(args[0].(types.Context), args[1].(types.AccAddress)) + run(args[0].(context.Context), args[1].(types.AccAddress)) }) return _c } @@ -110,13 +112,13 @@ func (_c *BankKeeper_GetAllBalances_Call) Return(_a0 types.Coins) *BankKeeper_Ge return _c } -func (_c *BankKeeper_GetAllBalances_Call) RunAndReturn(run func(types.Context, types.AccAddress) types.Coins) *BankKeeper_GetAllBalances_Call { +func (_c *BankKeeper_GetAllBalances_Call) RunAndReturn(run func(context.Context, types.AccAddress) types.Coins) *BankKeeper_GetAllBalances_Call { _c.Call.Return(run) return _c } // GetBalance provides a mock function with given fields: ctx, addr, denom -func (_m *BankKeeper) GetBalance(ctx types.Context, addr types.AccAddress, denom string) types.Coin { +func (_m *BankKeeper) GetBalance(ctx context.Context, addr types.AccAddress, denom string) types.Coin { ret := _m.Called(ctx, addr, denom) if len(ret) == 0 { @@ -124,7 +126,7 @@ func (_m *BankKeeper) GetBalance(ctx types.Context, addr types.AccAddress, denom } var r0 types.Coin - if rf, ok := ret.Get(0).(func(types.Context, types.AccAddress, string) types.Coin); ok { + if rf, ok := ret.Get(0).(func(context.Context, types.AccAddress, string) types.Coin); ok { r0 = rf(ctx, addr, denom) } else { r0 = ret.Get(0).(types.Coin) @@ -139,16 +141,16 @@ type BankKeeper_GetBalance_Call struct { } // GetBalance is a helper method to define mock.On call -// - ctx types.Context +// - ctx context.Context // - addr types.AccAddress // - denom string func (_e *BankKeeper_Expecter) GetBalance(ctx interface{}, addr interface{}, denom interface{}) *BankKeeper_GetBalance_Call { return &BankKeeper_GetBalance_Call{Call: _e.mock.On("GetBalance", ctx, addr, denom)} } -func (_c *BankKeeper_GetBalance_Call) Run(run func(ctx types.Context, addr types.AccAddress, denom string)) *BankKeeper_GetBalance_Call { +func (_c *BankKeeper_GetBalance_Call) Run(run func(ctx context.Context, addr types.AccAddress, denom string)) *BankKeeper_GetBalance_Call { _c.Call.Run(func(args mock.Arguments) { - run(args[0].(types.Context), args[1].(types.AccAddress), args[2].(string)) + run(args[0].(context.Context), args[1].(types.AccAddress), args[2].(string)) }) return _c } @@ -158,13 +160,13 @@ func (_c *BankKeeper_GetBalance_Call) Return(_a0 types.Coin) *BankKeeper_GetBala return _c } -func (_c *BankKeeper_GetBalance_Call) RunAndReturn(run func(types.Context, types.AccAddress, string) types.Coin) *BankKeeper_GetBalance_Call { +func (_c *BankKeeper_GetBalance_Call) RunAndReturn(run func(context.Context, types.AccAddress, string) types.Coin) *BankKeeper_GetBalance_Call { _c.Call.Return(run) return _c } // HasBalance provides a mock function with given fields: ctx, addr, amt -func (_m *BankKeeper) HasBalance(ctx types.Context, addr types.AccAddress, amt types.Coin) bool { +func (_m *BankKeeper) HasBalance(ctx context.Context, addr types.AccAddress, amt types.Coin) bool { ret := _m.Called(ctx, addr, amt) if len(ret) == 0 { @@ -172,7 +174,7 @@ func (_m *BankKeeper) HasBalance(ctx types.Context, addr types.AccAddress, amt t } var r0 bool - if rf, ok := ret.Get(0).(func(types.Context, types.AccAddress, types.Coin) bool); ok { + if rf, ok := ret.Get(0).(func(context.Context, types.AccAddress, types.Coin) bool); ok { r0 = rf(ctx, addr, amt) } else { r0 = ret.Get(0).(bool) @@ -187,16 +189,16 @@ type BankKeeper_HasBalance_Call struct { } // HasBalance is a helper method to define mock.On call -// - ctx types.Context +// - ctx context.Context // - addr types.AccAddress // - amt types.Coin func (_e *BankKeeper_Expecter) HasBalance(ctx interface{}, addr interface{}, amt interface{}) *BankKeeper_HasBalance_Call { return &BankKeeper_HasBalance_Call{Call: _e.mock.On("HasBalance", ctx, addr, amt)} } -func (_c *BankKeeper_HasBalance_Call) Run(run func(ctx types.Context, addr types.AccAddress, amt types.Coin)) *BankKeeper_HasBalance_Call { +func (_c *BankKeeper_HasBalance_Call) Run(run func(ctx context.Context, addr types.AccAddress, amt types.Coin)) *BankKeeper_HasBalance_Call { _c.Call.Run(func(args mock.Arguments) { - run(args[0].(types.Context), args[1].(types.AccAddress), args[2].(types.Coin)) + run(args[0].(context.Context), args[1].(types.AccAddress), args[2].(types.Coin)) }) return _c } @@ -206,13 +208,13 @@ func (_c *BankKeeper_HasBalance_Call) Return(_a0 bool) *BankKeeper_HasBalance_Ca return _c } -func (_c *BankKeeper_HasBalance_Call) RunAndReturn(run func(types.Context, types.AccAddress, types.Coin) bool) *BankKeeper_HasBalance_Call { +func (_c *BankKeeper_HasBalance_Call) RunAndReturn(run func(context.Context, types.AccAddress, types.Coin) bool) *BankKeeper_HasBalance_Call { _c.Call.Return(run) return _c } // SendCoinsFromAccountToModule provides a mock function with given fields: ctx, senderAddr, recipientModule, amt -func (_m *BankKeeper) SendCoinsFromAccountToModule(ctx types.Context, senderAddr types.AccAddress, recipientModule string, amt types.Coins) error { +func (_m *BankKeeper) SendCoinsFromAccountToModule(ctx context.Context, senderAddr types.AccAddress, recipientModule string, amt types.Coins) error { ret := _m.Called(ctx, senderAddr, recipientModule, amt) if len(ret) == 0 { @@ -220,7 +222,7 @@ func (_m *BankKeeper) SendCoinsFromAccountToModule(ctx types.Context, senderAddr } var r0 error - if rf, ok := ret.Get(0).(func(types.Context, types.AccAddress, string, types.Coins) error); ok { + if rf, ok := ret.Get(0).(func(context.Context, types.AccAddress, string, types.Coins) error); ok { r0 = rf(ctx, senderAddr, recipientModule, amt) } else { r0 = ret.Error(0) @@ -235,7 +237,7 @@ type BankKeeper_SendCoinsFromAccountToModule_Call struct { } // SendCoinsFromAccountToModule is a helper method to define mock.On call -// - ctx types.Context +// - ctx context.Context // - senderAddr types.AccAddress // - recipientModule string // - amt types.Coins @@ -243,9 +245,9 @@ func (_e *BankKeeper_Expecter) SendCoinsFromAccountToModule(ctx interface{}, sen return &BankKeeper_SendCoinsFromAccountToModule_Call{Call: _e.mock.On("SendCoinsFromAccountToModule", ctx, senderAddr, recipientModule, amt)} } -func (_c *BankKeeper_SendCoinsFromAccountToModule_Call) Run(run func(ctx types.Context, senderAddr types.AccAddress, recipientModule string, amt types.Coins)) *BankKeeper_SendCoinsFromAccountToModule_Call { +func (_c *BankKeeper_SendCoinsFromAccountToModule_Call) Run(run func(ctx context.Context, senderAddr types.AccAddress, recipientModule string, amt types.Coins)) *BankKeeper_SendCoinsFromAccountToModule_Call { _c.Call.Run(func(args mock.Arguments) { - run(args[0].(types.Context), args[1].(types.AccAddress), args[2].(string), args[3].(types.Coins)) + run(args[0].(context.Context), args[1].(types.AccAddress), args[2].(string), args[3].(types.Coins)) }) return _c } @@ -255,13 +257,13 @@ func (_c *BankKeeper_SendCoinsFromAccountToModule_Call) Return(_a0 error) *BankK return _c } -func (_c *BankKeeper_SendCoinsFromAccountToModule_Call) RunAndReturn(run func(types.Context, types.AccAddress, string, types.Coins) error) *BankKeeper_SendCoinsFromAccountToModule_Call { +func (_c *BankKeeper_SendCoinsFromAccountToModule_Call) RunAndReturn(run func(context.Context, types.AccAddress, string, types.Coins) error) *BankKeeper_SendCoinsFromAccountToModule_Call { _c.Call.Return(run) return _c } // SendCoinsFromModuleToAccount provides a mock function with given fields: ctx, senderModule, recipientAddr, amt -func (_m *BankKeeper) SendCoinsFromModuleToAccount(ctx types.Context, senderModule string, recipientAddr types.AccAddress, amt types.Coins) error { +func (_m *BankKeeper) SendCoinsFromModuleToAccount(ctx context.Context, senderModule string, recipientAddr types.AccAddress, amt types.Coins) error { ret := _m.Called(ctx, senderModule, recipientAddr, amt) if len(ret) == 0 { @@ -269,7 +271,7 @@ func (_m *BankKeeper) SendCoinsFromModuleToAccount(ctx types.Context, senderModu } var r0 error - if rf, ok := ret.Get(0).(func(types.Context, string, types.AccAddress, types.Coins) error); ok { + if rf, ok := ret.Get(0).(func(context.Context, string, types.AccAddress, types.Coins) error); ok { r0 = rf(ctx, senderModule, recipientAddr, amt) } else { r0 = ret.Error(0) @@ -284,7 +286,7 @@ type BankKeeper_SendCoinsFromModuleToAccount_Call struct { } // SendCoinsFromModuleToAccount is a helper method to define mock.On call -// - ctx types.Context +// - ctx context.Context // - senderModule string // - recipientAddr types.AccAddress // - amt types.Coins @@ -292,9 +294,9 @@ func (_e *BankKeeper_Expecter) SendCoinsFromModuleToAccount(ctx interface{}, sen return &BankKeeper_SendCoinsFromModuleToAccount_Call{Call: _e.mock.On("SendCoinsFromModuleToAccount", ctx, senderModule, recipientAddr, amt)} } -func (_c *BankKeeper_SendCoinsFromModuleToAccount_Call) Run(run func(ctx types.Context, senderModule string, recipientAddr types.AccAddress, amt types.Coins)) *BankKeeper_SendCoinsFromModuleToAccount_Call { +func (_c *BankKeeper_SendCoinsFromModuleToAccount_Call) Run(run func(ctx context.Context, senderModule string, recipientAddr types.AccAddress, amt types.Coins)) *BankKeeper_SendCoinsFromModuleToAccount_Call { _c.Call.Run(func(args mock.Arguments) { - run(args[0].(types.Context), args[1].(string), args[2].(types.AccAddress), args[3].(types.Coins)) + run(args[0].(context.Context), args[1].(string), args[2].(types.AccAddress), args[3].(types.Coins)) }) return _c } @@ -304,13 +306,13 @@ func (_c *BankKeeper_SendCoinsFromModuleToAccount_Call) Return(_a0 error) *BankK return _c } -func (_c *BankKeeper_SendCoinsFromModuleToAccount_Call) RunAndReturn(run func(types.Context, string, types.AccAddress, types.Coins) error) *BankKeeper_SendCoinsFromModuleToAccount_Call { +func (_c *BankKeeper_SendCoinsFromModuleToAccount_Call) RunAndReturn(run func(context.Context, string, types.AccAddress, types.Coins) error) *BankKeeper_SendCoinsFromModuleToAccount_Call { _c.Call.Return(run) return _c } // SendCoinsFromModuleToModule provides a mock function with given fields: ctx, senderModule, recipientModule, amt -func (_m *BankKeeper) SendCoinsFromModuleToModule(ctx types.Context, senderModule string, recipientModule string, amt types.Coins) error { +func (_m *BankKeeper) SendCoinsFromModuleToModule(ctx context.Context, senderModule string, recipientModule string, amt types.Coins) error { ret := _m.Called(ctx, senderModule, recipientModule, amt) if len(ret) == 0 { @@ -318,7 +320,7 @@ func (_m *BankKeeper) SendCoinsFromModuleToModule(ctx types.Context, senderModul } var r0 error - if rf, ok := ret.Get(0).(func(types.Context, string, string, types.Coins) error); ok { + if rf, ok := ret.Get(0).(func(context.Context, string, string, types.Coins) error); ok { r0 = rf(ctx, senderModule, recipientModule, amt) } else { r0 = ret.Error(0) @@ -333,7 +335,7 @@ type BankKeeper_SendCoinsFromModuleToModule_Call struct { } // SendCoinsFromModuleToModule is a helper method to define mock.On call -// - ctx types.Context +// - ctx context.Context // - senderModule string // - recipientModule string // - amt types.Coins @@ -341,9 +343,9 @@ func (_e *BankKeeper_Expecter) SendCoinsFromModuleToModule(ctx interface{}, send return &BankKeeper_SendCoinsFromModuleToModule_Call{Call: _e.mock.On("SendCoinsFromModuleToModule", ctx, senderModule, recipientModule, amt)} } -func (_c *BankKeeper_SendCoinsFromModuleToModule_Call) Run(run func(ctx types.Context, senderModule string, recipientModule string, amt types.Coins)) *BankKeeper_SendCoinsFromModuleToModule_Call { +func (_c *BankKeeper_SendCoinsFromModuleToModule_Call) Run(run func(ctx context.Context, senderModule string, recipientModule string, amt types.Coins)) *BankKeeper_SendCoinsFromModuleToModule_Call { _c.Call.Run(func(args mock.Arguments) { - run(args[0].(types.Context), args[1].(string), args[2].(string), args[3].(types.Coins)) + run(args[0].(context.Context), args[1].(string), args[2].(string), args[3].(types.Coins)) }) return _c } @@ -353,13 +355,13 @@ func (_c *BankKeeper_SendCoinsFromModuleToModule_Call) Return(_a0 error) *BankKe return _c } -func (_c *BankKeeper_SendCoinsFromModuleToModule_Call) RunAndReturn(run func(types.Context, string, string, types.Coins) error) *BankKeeper_SendCoinsFromModuleToModule_Call { +func (_c *BankKeeper_SendCoinsFromModuleToModule_Call) RunAndReturn(run func(context.Context, string, string, types.Coins) error) *BankKeeper_SendCoinsFromModuleToModule_Call { _c.Call.Return(run) return _c } // SpendableCoins provides a mock function with given fields: ctx, addr -func (_m *BankKeeper) SpendableCoins(ctx types.Context, addr types.AccAddress) types.Coins { +func (_m *BankKeeper) SpendableCoins(ctx context.Context, addr types.AccAddress) types.Coins { ret := _m.Called(ctx, addr) if len(ret) == 0 { @@ -367,7 +369,7 @@ func (_m *BankKeeper) SpendableCoins(ctx types.Context, addr types.AccAddress) t } var r0 types.Coins - if rf, ok := ret.Get(0).(func(types.Context, types.AccAddress) types.Coins); ok { + if rf, ok := ret.Get(0).(func(context.Context, types.AccAddress) types.Coins); ok { r0 = rf(ctx, addr) } else { if ret.Get(0) != nil { @@ -384,15 +386,15 @@ type BankKeeper_SpendableCoins_Call struct { } // SpendableCoins is a helper method to define mock.On call -// - ctx types.Context +// - ctx context.Context // - addr types.AccAddress func (_e *BankKeeper_Expecter) SpendableCoins(ctx interface{}, addr interface{}) *BankKeeper_SpendableCoins_Call { return &BankKeeper_SpendableCoins_Call{Call: _e.mock.On("SpendableCoins", ctx, addr)} } -func (_c *BankKeeper_SpendableCoins_Call) Run(run func(ctx types.Context, addr types.AccAddress)) *BankKeeper_SpendableCoins_Call { +func (_c *BankKeeper_SpendableCoins_Call) Run(run func(ctx context.Context, addr types.AccAddress)) *BankKeeper_SpendableCoins_Call { _c.Call.Run(func(args mock.Arguments) { - run(args[0].(types.Context), args[1].(types.AccAddress)) + run(args[0].(context.Context), args[1].(types.AccAddress)) }) return _c } @@ -402,7 +404,7 @@ func (_c *BankKeeper_SpendableCoins_Call) Return(_a0 types.Coins) *BankKeeper_Sp return _c } -func (_c *BankKeeper_SpendableCoins_Call) RunAndReturn(run func(types.Context, types.AccAddress) types.Coins) *BankKeeper_SpendableCoins_Call { +func (_c *BankKeeper_SpendableCoins_Call) RunAndReturn(run func(context.Context, types.AccAddress) types.Coins) *BankKeeper_SpendableCoins_Call { _c.Call.Return(run) return _c } diff --git a/x/accountedpool/types/mocks/perpetual_keeper.go b/x/accountedpool/types/mocks/perpetual_keeper.go index c3015f04b..0ad31cd42 100644 --- a/x/accountedpool/types/mocks/perpetual_keeper.go +++ b/x/accountedpool/types/mocks/perpetual_keeper.go @@ -1,4 +1,4 @@ -// Code generated by mockery v2.46.3. DO NOT EDIT. +// Code generated by mockery v2.47.0. DO NOT EDIT. package mocks diff --git a/x/accountedpool/types/query.pb.go b/x/accountedpool/types/query.pb.go index 8baceeffa..80e07df7e 100644 --- a/x/accountedpool/types/query.pb.go +++ b/x/accountedpool/types/query.pb.go @@ -356,7 +356,6 @@ func _Query_AccountedPoolAll_Handler(srv interface{}, ctx context.Context, dec f return interceptor(ctx, in, info, handler) } -var Query_serviceDesc = _Query_serviceDesc var _Query_serviceDesc = grpc.ServiceDesc{ ServiceName: "elys.accountedpool.Query", HandlerType: (*QueryServer)(nil), diff --git a/x/accountedpool/types/tx.pb.go b/x/accountedpool/types/tx.pb.go index 41a8b321c..154953843 100644 --- a/x/accountedpool/types/tx.pb.go +++ b/x/accountedpool/types/tx.pb.go @@ -78,7 +78,6 @@ func RegisterMsgServer(s grpc1.Server, srv MsgServer) { s.RegisterService(&_Msg_serviceDesc, srv) } -var Msg_serviceDesc = _Msg_serviceDesc var _Msg_serviceDesc = grpc.ServiceDesc{ ServiceName: "elys.accountedpool.Msg", HandlerType: (*MsgServer)(nil), diff --git a/x/amm/keeper/keeper.go b/x/amm/keeper/keeper.go index 18239253f..c14ed5d10 100644 --- a/x/amm/keeper/keeper.go +++ b/x/amm/keeper/keeper.go @@ -1,9 +1,10 @@ package keeper import ( - "cosmossdk.io/core/store" "fmt" + "cosmossdk.io/core/store" + "cosmossdk.io/log" storetypes "cosmossdk.io/store/types" "github.com/cosmos/cosmos-sdk/codec" @@ -12,6 +13,7 @@ import ( "github.com/elys-network/elys/x/amm/types" commitmentkeeper "github.com/elys-network/elys/x/commitment/keeper" pkeeper "github.com/elys-network/elys/x/parameter/keeper" + tierkeeper "github.com/elys-network/elys/x/tier/keeper" ) type ( @@ -29,6 +31,7 @@ type ( commitmentKeeper *commitmentkeeper.Keeper assetProfileKeeper types.AssetProfileKeeper accountedPoolKeeper types.AccountedPoolKeeper + tierKeeper *tierkeeper.Keeper } ) @@ -45,6 +48,7 @@ func NewKeeper( commitmentKeeper *commitmentkeeper.Keeper, assetProfileKeeper types.AssetProfileKeeper, accountedPoolKeeper types.AccountedPoolKeeper, + tierKeeper *tierkeeper.Keeper, ) *Keeper { return &Keeper{ @@ -60,6 +64,7 @@ func NewKeeper( commitmentKeeper: commitmentKeeper, assetProfileKeeper: assetProfileKeeper, accountedPoolKeeper: accountedPoolKeeper, + tierKeeper: tierKeeper, } } @@ -77,3 +82,11 @@ func (k *Keeper) SetHooks(gh types.AmmHooks) *Keeper { return k } + +func (k *Keeper) SetTierKeeper(tk *tierkeeper.Keeper) { + k.tierKeeper = tk +} + +func (k *Keeper) GetTierKeeper() *tierkeeper.Keeper { + return k.tierKeeper +} diff --git a/x/amm/keeper/route_exact_amount_in.go b/x/amm/keeper/route_exact_amount_in.go index ce32fcfcd..f90ef34f0 100644 --- a/x/amm/keeper/route_exact_amount_in.go +++ b/x/amm/keeper/route_exact_amount_in.go @@ -1,7 +1,6 @@ package keeper import ( - errorsmod "cosmossdk.io/errors" "cosmossdk.io/math" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/elys-network/elys/x/amm/types" @@ -80,14 +79,8 @@ func (k Keeper) RouteExactAmountIn( } // Apply discount to swap fee if applicable - brokerAddress := k.parameterKeeper.GetParams(ctx).BrokerAddress - if discount.IsNil() { - discount = math.LegacyZeroDec() - } - if discount.IsPositive() && sender.String() != brokerAddress { - return math.Int{}, math.LegacyZeroDec(), math.LegacyZeroDec(), errorsmod.Wrapf(types.ErrInvalidDiscount, "discount %s is positive and signer address %s is not broker address %s", discount, sender, brokerAddress) - } - swapFee = types.ApplyDiscount(swapFee, discount) + _, tier := k.tierKeeper.GetMembershipTier(ctx, sender) + swapFee = types.ApplyDiscount(swapFee, tier.Discount) // Calculate the total discounted swap fee totalDiscountedSwapFee = totalDiscountedSwapFee.Add(swapFee) diff --git a/x/amm/keeper/route_exact_amount_out.go b/x/amm/keeper/route_exact_amount_out.go index 9c18a8002..7c155de6f 100644 --- a/x/amm/keeper/route_exact_amount_out.go +++ b/x/amm/keeper/route_exact_amount_out.go @@ -3,7 +3,6 @@ package keeper import ( "fmt" - errorsmod "cosmossdk.io/errors" "cosmossdk.io/math" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/elys-network/elys/x/amm/types" @@ -100,14 +99,8 @@ func (k Keeper) RouteExactAmountOut(ctx sdk.Context, } // Apply discount to swap fee if applicable - brokerAddress := k.parameterKeeper.GetParams(ctx).BrokerAddress - if discount.IsNil() { - discount = math.LegacyZeroDec() - } - if discount.IsPositive() && sender.String() != brokerAddress { - return math.Int{}, math.LegacyZeroDec(), math.LegacyZeroDec(), errorsmod.Wrapf(types.ErrInvalidDiscount, "discount %s is positive and signer address %s is not broker address %s", discount, sender, brokerAddress) - } - swapFee = types.ApplyDiscount(swapFee, discount) + _, tier := k.tierKeeper.GetMembershipTier(ctx, sender) + swapFee = types.ApplyDiscount(swapFee, tier.Discount) // Calculate the total discounted swap fee totalDiscountedSwapFee = totalDiscountedSwapFee.Add(swapFee) diff --git a/x/amm/types/expected_keepers.go b/x/amm/types/expected_keepers.go index e27fba253..86e3b00ed 100644 --- a/x/amm/types/expected_keepers.go +++ b/x/amm/types/expected_keepers.go @@ -2,6 +2,7 @@ package types import ( "context" + sdkmath "cosmossdk.io/math" sdk "github.com/cosmos/cosmos-sdk/types" banktypes "github.com/cosmos/cosmos-sdk/x/bank/types" @@ -57,3 +58,9 @@ type AssetProfileKeeper interface { type AccountedPoolKeeper interface { GetAccountedBalance(sdk.Context, uint64, string) sdkmath.Int } + +type TierKeeper interface { + GetMembershipTier(ctx sdk.Context, user sdk.AccAddress) (total_portfolio sdkmath.LegacyDec, tier string, discount sdkmath.LegacyDec) + + CalculateUSDValue(ctx sdk.Context, denom string, amount sdkmath.Int) sdkmath.LegacyDec +} diff --git a/x/amm/types/mocks/accounted_pool_keeper.go b/x/amm/types/mocks/accounted_pool_keeper.go index 07fc3c20e..4084e3334 100644 --- a/x/amm/types/mocks/accounted_pool_keeper.go +++ b/x/amm/types/mocks/accounted_pool_keeper.go @@ -1,9 +1,9 @@ -// Code generated by mockery v2.46.3. DO NOT EDIT. +// Code generated by mockery v2.47.0. DO NOT EDIT. package mocks import ( - sdkmath "cosmossdk.io/math" + math "cosmossdk.io/math" types "github.com/cosmos/cosmos-sdk/types" mock "github.com/stretchr/testify/mock" ) @@ -22,18 +22,18 @@ func (_m *AccountedPoolKeeper) EXPECT() *AccountedPoolKeeper_Expecter { } // GetAccountedBalance provides a mock function with given fields: _a0, _a1, _a2 -func (_m *AccountedPoolKeeper) GetAccountedBalance(_a0 types.Context, _a1 uint64, _a2 string) sdkmath.Int { +func (_m *AccountedPoolKeeper) GetAccountedBalance(_a0 types.Context, _a1 uint64, _a2 string) math.Int { ret := _m.Called(_a0, _a1, _a2) if len(ret) == 0 { panic("no return value specified for GetAccountedBalance") } - var r0 sdkmath.Int - if rf, ok := ret.Get(0).(func(types.Context, uint64, string) sdkmath.Int); ok { + var r0 math.Int + if rf, ok := ret.Get(0).(func(types.Context, uint64, string) math.Int); ok { r0 = rf(_a0, _a1, _a2) } else { - r0 = ret.Get(0).(sdkmath.Int) + r0 = ret.Get(0).(math.Int) } return r0 @@ -59,12 +59,12 @@ func (_c *AccountedPoolKeeper_GetAccountedBalance_Call) Run(run func(_a0 types.C return _c } -func (_c *AccountedPoolKeeper_GetAccountedBalance_Call) Return(_a0 sdkmath.Int) *AccountedPoolKeeper_GetAccountedBalance_Call { +func (_c *AccountedPoolKeeper_GetAccountedBalance_Call) Return(_a0 math.Int) *AccountedPoolKeeper_GetAccountedBalance_Call { _c.Call.Return(_a0) return _c } -func (_c *AccountedPoolKeeper_GetAccountedBalance_Call) RunAndReturn(run func(types.Context, uint64, string) sdkmath.Int) *AccountedPoolKeeper_GetAccountedBalance_Call { +func (_c *AccountedPoolKeeper_GetAccountedBalance_Call) RunAndReturn(run func(types.Context, uint64, string) math.Int) *AccountedPoolKeeper_GetAccountedBalance_Call { _c.Call.Return(run) return _c } diff --git a/x/amm/types/mocks/oracle_keeper.go b/x/amm/types/mocks/oracle_keeper.go index 4e4efc87b..ccbfbc2e8 100644 --- a/x/amm/types/mocks/oracle_keeper.go +++ b/x/amm/types/mocks/oracle_keeper.go @@ -1,4 +1,4 @@ -// Code generated by mockery v2.46.3. DO NOT EDIT. +// Code generated by mockery v2.47.0. DO NOT EDIT. package mocks diff --git a/x/amm/types/query.pb.go b/x/amm/types/query.pb.go index 552485124..45770b7a3 100644 --- a/x/amm/types/query.pb.go +++ b/x/amm/types/query.pb.go @@ -2104,7 +2104,6 @@ func _Query_SwapEstimationByDenom_Handler(srv interface{}, ctx context.Context, return interceptor(ctx, in, info, handler) } -var Query_serviceDesc = _Query_serviceDesc var _Query_serviceDesc = grpc.ServiceDesc{ ServiceName: "elys.amm.Query", HandlerType: (*QueryServer)(nil), diff --git a/x/amm/types/tx.pb.go b/x/amm/types/tx.pb.go index 1e68ef3af..eda3d6ecd 100644 --- a/x/amm/types/tx.pb.go +++ b/x/amm/types/tx.pb.go @@ -1590,7 +1590,6 @@ func _Msg_UpdateParams_Handler(srv interface{}, ctx context.Context, dec func(in return interceptor(ctx, in, info, handler) } -var Msg_serviceDesc = _Msg_serviceDesc var _Msg_serviceDesc = grpc.ServiceDesc{ ServiceName: "elys.amm.Msg", HandlerType: (*MsgServer)(nil), diff --git a/x/assetprofile/types/query.pb.go b/x/assetprofile/types/query.pb.go index 436ed1def..53139cbc3 100644 --- a/x/assetprofile/types/query.pb.go +++ b/x/assetprofile/types/query.pb.go @@ -604,7 +604,6 @@ func _Query_EntryAll_Handler(srv interface{}, ctx context.Context, dec func(inte return interceptor(ctx, in, info, handler) } -var Query_serviceDesc = _Query_serviceDesc var _Query_serviceDesc = grpc.ServiceDesc{ ServiceName: "elys.assetprofile.Query", HandlerType: (*QueryServer)(nil), diff --git a/x/assetprofile/types/tx.pb.go b/x/assetprofile/types/tx.pb.go index 39985877f..43afdc982 100644 --- a/x/assetprofile/types/tx.pb.go +++ b/x/assetprofile/types/tx.pb.go @@ -764,7 +764,6 @@ func _Msg_AddEntry_Handler(srv interface{}, ctx context.Context, dec func(interf return interceptor(ctx, in, info, handler) } -var Msg_serviceDesc = _Msg_serviceDesc var _Msg_serviceDesc = grpc.ServiceDesc{ ServiceName: "elys.assetprofile.Msg", HandlerType: (*MsgServer)(nil), diff --git a/x/burner/types/mocks/bank_keeper.go b/x/burner/types/mocks/bank_keeper.go index f2163b188..9c095f3b3 100644 --- a/x/burner/types/mocks/bank_keeper.go +++ b/x/burner/types/mocks/bank_keeper.go @@ -1,4 +1,4 @@ -// Code generated by mockery v2.46.3. DO NOT EDIT. +// Code generated by mockery v2.47.0. DO NOT EDIT. package mocks diff --git a/x/burner/types/query.pb.go b/x/burner/types/query.pb.go index 6cbaf0b42..3bd23c387 100644 --- a/x/burner/types/query.pb.go +++ b/x/burner/types/query.pb.go @@ -487,7 +487,6 @@ func _Query_HistoryAll_Handler(srv interface{}, ctx context.Context, dec func(in return interceptor(ctx, in, info, handler) } -var Query_serviceDesc = _Query_serviceDesc var _Query_serviceDesc = grpc.ServiceDesc{ ServiceName: "elys.burner.Query", HandlerType: (*QueryServer)(nil), diff --git a/x/burner/types/tx.pb.go b/x/burner/types/tx.pb.go index 616da1740..e6510aada 100644 --- a/x/burner/types/tx.pb.go +++ b/x/burner/types/tx.pb.go @@ -216,7 +216,6 @@ func _Msg_UpdateParams_Handler(srv interface{}, ctx context.Context, dec func(in return interceptor(ctx, in, info, handler) } -var Msg_serviceDesc = _Msg_serviceDesc var _Msg_serviceDesc = grpc.ServiceDesc{ ServiceName: "elys.burner.Msg", HandlerType: (*MsgServer)(nil), diff --git a/x/commitment/types/query.pb.go b/x/commitment/types/query.pb.go index d16220858..8d33b49d7 100644 --- a/x/commitment/types/query.pb.go +++ b/x/commitment/types/query.pb.go @@ -817,7 +817,6 @@ func _Query_CommitmentVestingInfo_Handler(srv interface{}, ctx context.Context, return interceptor(ctx, in, info, handler) } -var Query_serviceDesc = _Query_serviceDesc var _Query_serviceDesc = grpc.ServiceDesc{ ServiceName: "elys.commitment.Query", HandlerType: (*QueryServer)(nil), diff --git a/x/commitment/types/tx.pb.go b/x/commitment/types/tx.pb.go index f5609648d..6fb09d353 100644 --- a/x/commitment/types/tx.pb.go +++ b/x/commitment/types/tx.pb.go @@ -1467,7 +1467,6 @@ func _Msg_Unstake_Handler(srv interface{}, ctx context.Context, dec func(interfa return interceptor(ctx, in, info, handler) } -var Msg_serviceDesc = _Msg_serviceDesc var _Msg_serviceDesc = grpc.ServiceDesc{ ServiceName: "elys.commitment.Msg", HandlerType: (*MsgServer)(nil), diff --git a/x/epochs/types/query.pb.go b/x/epochs/types/query.pb.go index 45a4d5bbd..85ca8b0b0 100644 --- a/x/epochs/types/query.pb.go +++ b/x/epochs/types/query.pb.go @@ -372,7 +372,6 @@ func _Query_CurrentEpoch_Handler(srv interface{}, ctx context.Context, dec func( return interceptor(ctx, in, info, handler) } -var Query_serviceDesc = _Query_serviceDesc var _Query_serviceDesc = grpc.ServiceDesc{ ServiceName: "elys.epochs.v1.Query", HandlerType: (*QueryServer)(nil), diff --git a/x/estaking/types/query.pb.go b/x/estaking/types/query.pb.go index c837e931d..ebf6e6393 100644 --- a/x/estaking/types/query.pb.go +++ b/x/estaking/types/query.pb.go @@ -533,7 +533,6 @@ func _Query_Invariant_Handler(srv interface{}, ctx context.Context, dec func(int return interceptor(ctx, in, info, handler) } -var Query_serviceDesc = _Query_serviceDesc var _Query_serviceDesc = grpc.ServiceDesc{ ServiceName: "elys.estaking.Query", HandlerType: (*QueryServer)(nil), diff --git a/x/estaking/types/tx.pb.go b/x/estaking/types/tx.pb.go index 2187e633f..a9d5a880a 100644 --- a/x/estaking/types/tx.pb.go +++ b/x/estaking/types/tx.pb.go @@ -645,7 +645,6 @@ func _Msg_WithdrawAllRewards_Handler(srv interface{}, ctx context.Context, dec f return interceptor(ctx, in, info, handler) } -var Msg_serviceDesc = _Msg_serviceDesc var _Msg_serviceDesc = grpc.ServiceDesc{ ServiceName: "elys.estaking.Msg", HandlerType: (*MsgServer)(nil), diff --git a/x/leveragelp/types/mocks/bank_keeper.go b/x/leveragelp/types/mocks/bank_keeper.go index 9f16ede56..7efabdbbe 100644 --- a/x/leveragelp/types/mocks/bank_keeper.go +++ b/x/leveragelp/types/mocks/bank_keeper.go @@ -1,10 +1,13 @@ -// Code generated by mockery v2.46.3. DO NOT EDIT. +// Code generated by mockery v2.47.0. DO NOT EDIT. package mocks import ( - types "github.com/cosmos/cosmos-sdk/types" + context "context" + mock "github.com/stretchr/testify/mock" + + types "github.com/cosmos/cosmos-sdk/types" ) // BankKeeper is an autogenerated mock type for the BankKeeper type @@ -66,17 +69,17 @@ func (_c *BankKeeper_BlockedAddr_Call) RunAndReturn(run func(types.AccAddress) b return _c } -// GetAllBalances provides a mock function with given fields: ctx, addr -func (_m *BankKeeper) GetAllBalances(ctx types.Context, addr types.AccAddress) types.Coins { - ret := _m.Called(ctx, addr) +// GetAllBalances provides a mock function with given fields: goCtx, addr +func (_m *BankKeeper) GetAllBalances(goCtx context.Context, addr types.AccAddress) types.Coins { + ret := _m.Called(goCtx, addr) if len(ret) == 0 { panic("no return value specified for GetAllBalances") } var r0 types.Coins - if rf, ok := ret.Get(0).(func(types.Context, types.AccAddress) types.Coins); ok { - r0 = rf(ctx, addr) + if rf, ok := ret.Get(0).(func(context.Context, types.AccAddress) types.Coins); ok { + r0 = rf(goCtx, addr) } else { if ret.Get(0) != nil { r0 = ret.Get(0).(types.Coins) @@ -92,15 +95,15 @@ type BankKeeper_GetAllBalances_Call struct { } // GetAllBalances is a helper method to define mock.On call -// - ctx types.Context +// - goCtx context.Context // - addr types.AccAddress -func (_e *BankKeeper_Expecter) GetAllBalances(ctx interface{}, addr interface{}) *BankKeeper_GetAllBalances_Call { - return &BankKeeper_GetAllBalances_Call{Call: _e.mock.On("GetAllBalances", ctx, addr)} +func (_e *BankKeeper_Expecter) GetAllBalances(goCtx interface{}, addr interface{}) *BankKeeper_GetAllBalances_Call { + return &BankKeeper_GetAllBalances_Call{Call: _e.mock.On("GetAllBalances", goCtx, addr)} } -func (_c *BankKeeper_GetAllBalances_Call) Run(run func(ctx types.Context, addr types.AccAddress)) *BankKeeper_GetAllBalances_Call { +func (_c *BankKeeper_GetAllBalances_Call) Run(run func(goCtx context.Context, addr types.AccAddress)) *BankKeeper_GetAllBalances_Call { _c.Call.Run(func(args mock.Arguments) { - run(args[0].(types.Context), args[1].(types.AccAddress)) + run(args[0].(context.Context), args[1].(types.AccAddress)) }) return _c } @@ -110,22 +113,22 @@ func (_c *BankKeeper_GetAllBalances_Call) Return(_a0 types.Coins) *BankKeeper_Ge return _c } -func (_c *BankKeeper_GetAllBalances_Call) RunAndReturn(run func(types.Context, types.AccAddress) types.Coins) *BankKeeper_GetAllBalances_Call { +func (_c *BankKeeper_GetAllBalances_Call) RunAndReturn(run func(context.Context, types.AccAddress) types.Coins) *BankKeeper_GetAllBalances_Call { _c.Call.Return(run) return _c } -// GetBalance provides a mock function with given fields: ctx, addr, denom -func (_m *BankKeeper) GetBalance(ctx types.Context, addr types.AccAddress, denom string) types.Coin { - ret := _m.Called(ctx, addr, denom) +// GetBalance provides a mock function with given fields: goCtx, addr, denom +func (_m *BankKeeper) GetBalance(goCtx context.Context, addr types.AccAddress, denom string) types.Coin { + ret := _m.Called(goCtx, addr, denom) if len(ret) == 0 { panic("no return value specified for GetBalance") } var r0 types.Coin - if rf, ok := ret.Get(0).(func(types.Context, types.AccAddress, string) types.Coin); ok { - r0 = rf(ctx, addr, denom) + if rf, ok := ret.Get(0).(func(context.Context, types.AccAddress, string) types.Coin); ok { + r0 = rf(goCtx, addr, denom) } else { r0 = ret.Get(0).(types.Coin) } @@ -139,16 +142,16 @@ type BankKeeper_GetBalance_Call struct { } // GetBalance is a helper method to define mock.On call -// - ctx types.Context +// - goCtx context.Context // - addr types.AccAddress // - denom string -func (_e *BankKeeper_Expecter) GetBalance(ctx interface{}, addr interface{}, denom interface{}) *BankKeeper_GetBalance_Call { - return &BankKeeper_GetBalance_Call{Call: _e.mock.On("GetBalance", ctx, addr, denom)} +func (_e *BankKeeper_Expecter) GetBalance(goCtx interface{}, addr interface{}, denom interface{}) *BankKeeper_GetBalance_Call { + return &BankKeeper_GetBalance_Call{Call: _e.mock.On("GetBalance", goCtx, addr, denom)} } -func (_c *BankKeeper_GetBalance_Call) Run(run func(ctx types.Context, addr types.AccAddress, denom string)) *BankKeeper_GetBalance_Call { +func (_c *BankKeeper_GetBalance_Call) Run(run func(goCtx context.Context, addr types.AccAddress, denom string)) *BankKeeper_GetBalance_Call { _c.Call.Run(func(args mock.Arguments) { - run(args[0].(types.Context), args[1].(types.AccAddress), args[2].(string)) + run(args[0].(context.Context), args[1].(types.AccAddress), args[2].(string)) }) return _c } @@ -158,22 +161,22 @@ func (_c *BankKeeper_GetBalance_Call) Return(_a0 types.Coin) *BankKeeper_GetBala return _c } -func (_c *BankKeeper_GetBalance_Call) RunAndReturn(run func(types.Context, types.AccAddress, string) types.Coin) *BankKeeper_GetBalance_Call { +func (_c *BankKeeper_GetBalance_Call) RunAndReturn(run func(context.Context, types.AccAddress, string) types.Coin) *BankKeeper_GetBalance_Call { _c.Call.Return(run) return _c } -// HasBalance provides a mock function with given fields: ctx, addr, amt -func (_m *BankKeeper) HasBalance(ctx types.Context, addr types.AccAddress, amt types.Coin) bool { - ret := _m.Called(ctx, addr, amt) +// HasBalance provides a mock function with given fields: goCtx, addr, amt +func (_m *BankKeeper) HasBalance(goCtx context.Context, addr types.AccAddress, amt types.Coin) bool { + ret := _m.Called(goCtx, addr, amt) if len(ret) == 0 { panic("no return value specified for HasBalance") } var r0 bool - if rf, ok := ret.Get(0).(func(types.Context, types.AccAddress, types.Coin) bool); ok { - r0 = rf(ctx, addr, amt) + if rf, ok := ret.Get(0).(func(context.Context, types.AccAddress, types.Coin) bool); ok { + r0 = rf(goCtx, addr, amt) } else { r0 = ret.Get(0).(bool) } @@ -187,16 +190,16 @@ type BankKeeper_HasBalance_Call struct { } // HasBalance is a helper method to define mock.On call -// - ctx types.Context +// - goCtx context.Context // - addr types.AccAddress // - amt types.Coin -func (_e *BankKeeper_Expecter) HasBalance(ctx interface{}, addr interface{}, amt interface{}) *BankKeeper_HasBalance_Call { - return &BankKeeper_HasBalance_Call{Call: _e.mock.On("HasBalance", ctx, addr, amt)} +func (_e *BankKeeper_Expecter) HasBalance(goCtx interface{}, addr interface{}, amt interface{}) *BankKeeper_HasBalance_Call { + return &BankKeeper_HasBalance_Call{Call: _e.mock.On("HasBalance", goCtx, addr, amt)} } -func (_c *BankKeeper_HasBalance_Call) Run(run func(ctx types.Context, addr types.AccAddress, amt types.Coin)) *BankKeeper_HasBalance_Call { +func (_c *BankKeeper_HasBalance_Call) Run(run func(goCtx context.Context, addr types.AccAddress, amt types.Coin)) *BankKeeper_HasBalance_Call { _c.Call.Run(func(args mock.Arguments) { - run(args[0].(types.Context), args[1].(types.AccAddress), args[2].(types.Coin)) + run(args[0].(context.Context), args[1].(types.AccAddress), args[2].(types.Coin)) }) return _c } @@ -206,22 +209,22 @@ func (_c *BankKeeper_HasBalance_Call) Return(_a0 bool) *BankKeeper_HasBalance_Ca return _c } -func (_c *BankKeeper_HasBalance_Call) RunAndReturn(run func(types.Context, types.AccAddress, types.Coin) bool) *BankKeeper_HasBalance_Call { +func (_c *BankKeeper_HasBalance_Call) RunAndReturn(run func(context.Context, types.AccAddress, types.Coin) bool) *BankKeeper_HasBalance_Call { _c.Call.Return(run) return _c } -// SendCoins provides a mock function with given fields: ctx, fromAddr, toAddr, amt -func (_m *BankKeeper) SendCoins(ctx types.Context, fromAddr types.AccAddress, toAddr types.AccAddress, amt types.Coins) error { - ret := _m.Called(ctx, fromAddr, toAddr, amt) +// SendCoins provides a mock function with given fields: goCtx, fromAddr, toAddr, amt +func (_m *BankKeeper) SendCoins(goCtx context.Context, fromAddr types.AccAddress, toAddr types.AccAddress, amt types.Coins) error { + ret := _m.Called(goCtx, fromAddr, toAddr, amt) if len(ret) == 0 { panic("no return value specified for SendCoins") } var r0 error - if rf, ok := ret.Get(0).(func(types.Context, types.AccAddress, types.AccAddress, types.Coins) error); ok { - r0 = rf(ctx, fromAddr, toAddr, amt) + if rf, ok := ret.Get(0).(func(context.Context, types.AccAddress, types.AccAddress, types.Coins) error); ok { + r0 = rf(goCtx, fromAddr, toAddr, amt) } else { r0 = ret.Error(0) } @@ -235,17 +238,17 @@ type BankKeeper_SendCoins_Call struct { } // SendCoins is a helper method to define mock.On call -// - ctx types.Context +// - goCtx context.Context // - fromAddr types.AccAddress // - toAddr types.AccAddress // - amt types.Coins -func (_e *BankKeeper_Expecter) SendCoins(ctx interface{}, fromAddr interface{}, toAddr interface{}, amt interface{}) *BankKeeper_SendCoins_Call { - return &BankKeeper_SendCoins_Call{Call: _e.mock.On("SendCoins", ctx, fromAddr, toAddr, amt)} +func (_e *BankKeeper_Expecter) SendCoins(goCtx interface{}, fromAddr interface{}, toAddr interface{}, amt interface{}) *BankKeeper_SendCoins_Call { + return &BankKeeper_SendCoins_Call{Call: _e.mock.On("SendCoins", goCtx, fromAddr, toAddr, amt)} } -func (_c *BankKeeper_SendCoins_Call) Run(run func(ctx types.Context, fromAddr types.AccAddress, toAddr types.AccAddress, amt types.Coins)) *BankKeeper_SendCoins_Call { +func (_c *BankKeeper_SendCoins_Call) Run(run func(goCtx context.Context, fromAddr types.AccAddress, toAddr types.AccAddress, amt types.Coins)) *BankKeeper_SendCoins_Call { _c.Call.Run(func(args mock.Arguments) { - run(args[0].(types.Context), args[1].(types.AccAddress), args[2].(types.AccAddress), args[3].(types.Coins)) + run(args[0].(context.Context), args[1].(types.AccAddress), args[2].(types.AccAddress), args[3].(types.Coins)) }) return _c } @@ -255,22 +258,22 @@ func (_c *BankKeeper_SendCoins_Call) Return(_a0 error) *BankKeeper_SendCoins_Cal return _c } -func (_c *BankKeeper_SendCoins_Call) RunAndReturn(run func(types.Context, types.AccAddress, types.AccAddress, types.Coins) error) *BankKeeper_SendCoins_Call { +func (_c *BankKeeper_SendCoins_Call) RunAndReturn(run func(context.Context, types.AccAddress, types.AccAddress, types.Coins) error) *BankKeeper_SendCoins_Call { _c.Call.Return(run) return _c } -// SendCoinsFromAccountToModule provides a mock function with given fields: ctx, senderAddr, recipientModule, amt -func (_m *BankKeeper) SendCoinsFromAccountToModule(ctx types.Context, senderAddr types.AccAddress, recipientModule string, amt types.Coins) error { - ret := _m.Called(ctx, senderAddr, recipientModule, amt) +// SendCoinsFromAccountToModule provides a mock function with given fields: goCtx, senderAddr, recipientModule, amt +func (_m *BankKeeper) SendCoinsFromAccountToModule(goCtx context.Context, senderAddr types.AccAddress, recipientModule string, amt types.Coins) error { + ret := _m.Called(goCtx, senderAddr, recipientModule, amt) if len(ret) == 0 { panic("no return value specified for SendCoinsFromAccountToModule") } var r0 error - if rf, ok := ret.Get(0).(func(types.Context, types.AccAddress, string, types.Coins) error); ok { - r0 = rf(ctx, senderAddr, recipientModule, amt) + if rf, ok := ret.Get(0).(func(context.Context, types.AccAddress, string, types.Coins) error); ok { + r0 = rf(goCtx, senderAddr, recipientModule, amt) } else { r0 = ret.Error(0) } @@ -284,17 +287,17 @@ type BankKeeper_SendCoinsFromAccountToModule_Call struct { } // SendCoinsFromAccountToModule is a helper method to define mock.On call -// - ctx types.Context +// - goCtx context.Context // - senderAddr types.AccAddress // - recipientModule string // - amt types.Coins -func (_e *BankKeeper_Expecter) SendCoinsFromAccountToModule(ctx interface{}, senderAddr interface{}, recipientModule interface{}, amt interface{}) *BankKeeper_SendCoinsFromAccountToModule_Call { - return &BankKeeper_SendCoinsFromAccountToModule_Call{Call: _e.mock.On("SendCoinsFromAccountToModule", ctx, senderAddr, recipientModule, amt)} +func (_e *BankKeeper_Expecter) SendCoinsFromAccountToModule(goCtx interface{}, senderAddr interface{}, recipientModule interface{}, amt interface{}) *BankKeeper_SendCoinsFromAccountToModule_Call { + return &BankKeeper_SendCoinsFromAccountToModule_Call{Call: _e.mock.On("SendCoinsFromAccountToModule", goCtx, senderAddr, recipientModule, amt)} } -func (_c *BankKeeper_SendCoinsFromAccountToModule_Call) Run(run func(ctx types.Context, senderAddr types.AccAddress, recipientModule string, amt types.Coins)) *BankKeeper_SendCoinsFromAccountToModule_Call { +func (_c *BankKeeper_SendCoinsFromAccountToModule_Call) Run(run func(goCtx context.Context, senderAddr types.AccAddress, recipientModule string, amt types.Coins)) *BankKeeper_SendCoinsFromAccountToModule_Call { _c.Call.Run(func(args mock.Arguments) { - run(args[0].(types.Context), args[1].(types.AccAddress), args[2].(string), args[3].(types.Coins)) + run(args[0].(context.Context), args[1].(types.AccAddress), args[2].(string), args[3].(types.Coins)) }) return _c } @@ -304,22 +307,22 @@ func (_c *BankKeeper_SendCoinsFromAccountToModule_Call) Return(_a0 error) *BankK return _c } -func (_c *BankKeeper_SendCoinsFromAccountToModule_Call) RunAndReturn(run func(types.Context, types.AccAddress, string, types.Coins) error) *BankKeeper_SendCoinsFromAccountToModule_Call { +func (_c *BankKeeper_SendCoinsFromAccountToModule_Call) RunAndReturn(run func(context.Context, types.AccAddress, string, types.Coins) error) *BankKeeper_SendCoinsFromAccountToModule_Call { _c.Call.Return(run) return _c } -// SendCoinsFromModuleToAccount provides a mock function with given fields: ctx, senderModule, recipientAddr, amt -func (_m *BankKeeper) SendCoinsFromModuleToAccount(ctx types.Context, senderModule string, recipientAddr types.AccAddress, amt types.Coins) error { - ret := _m.Called(ctx, senderModule, recipientAddr, amt) +// SendCoinsFromModuleToAccount provides a mock function with given fields: goCtx, senderModule, recipientAddr, amt +func (_m *BankKeeper) SendCoinsFromModuleToAccount(goCtx context.Context, senderModule string, recipientAddr types.AccAddress, amt types.Coins) error { + ret := _m.Called(goCtx, senderModule, recipientAddr, amt) if len(ret) == 0 { panic("no return value specified for SendCoinsFromModuleToAccount") } var r0 error - if rf, ok := ret.Get(0).(func(types.Context, string, types.AccAddress, types.Coins) error); ok { - r0 = rf(ctx, senderModule, recipientAddr, amt) + if rf, ok := ret.Get(0).(func(context.Context, string, types.AccAddress, types.Coins) error); ok { + r0 = rf(goCtx, senderModule, recipientAddr, amt) } else { r0 = ret.Error(0) } @@ -333,17 +336,17 @@ type BankKeeper_SendCoinsFromModuleToAccount_Call struct { } // SendCoinsFromModuleToAccount is a helper method to define mock.On call -// - ctx types.Context +// - goCtx context.Context // - senderModule string // - recipientAddr types.AccAddress // - amt types.Coins -func (_e *BankKeeper_Expecter) SendCoinsFromModuleToAccount(ctx interface{}, senderModule interface{}, recipientAddr interface{}, amt interface{}) *BankKeeper_SendCoinsFromModuleToAccount_Call { - return &BankKeeper_SendCoinsFromModuleToAccount_Call{Call: _e.mock.On("SendCoinsFromModuleToAccount", ctx, senderModule, recipientAddr, amt)} +func (_e *BankKeeper_Expecter) SendCoinsFromModuleToAccount(goCtx interface{}, senderModule interface{}, recipientAddr interface{}, amt interface{}) *BankKeeper_SendCoinsFromModuleToAccount_Call { + return &BankKeeper_SendCoinsFromModuleToAccount_Call{Call: _e.mock.On("SendCoinsFromModuleToAccount", goCtx, senderModule, recipientAddr, amt)} } -func (_c *BankKeeper_SendCoinsFromModuleToAccount_Call) Run(run func(ctx types.Context, senderModule string, recipientAddr types.AccAddress, amt types.Coins)) *BankKeeper_SendCoinsFromModuleToAccount_Call { +func (_c *BankKeeper_SendCoinsFromModuleToAccount_Call) Run(run func(goCtx context.Context, senderModule string, recipientAddr types.AccAddress, amt types.Coins)) *BankKeeper_SendCoinsFromModuleToAccount_Call { _c.Call.Run(func(args mock.Arguments) { - run(args[0].(types.Context), args[1].(string), args[2].(types.AccAddress), args[3].(types.Coins)) + run(args[0].(context.Context), args[1].(string), args[2].(types.AccAddress), args[3].(types.Coins)) }) return _c } @@ -353,22 +356,22 @@ func (_c *BankKeeper_SendCoinsFromModuleToAccount_Call) Return(_a0 error) *BankK return _c } -func (_c *BankKeeper_SendCoinsFromModuleToAccount_Call) RunAndReturn(run func(types.Context, string, types.AccAddress, types.Coins) error) *BankKeeper_SendCoinsFromModuleToAccount_Call { +func (_c *BankKeeper_SendCoinsFromModuleToAccount_Call) RunAndReturn(run func(context.Context, string, types.AccAddress, types.Coins) error) *BankKeeper_SendCoinsFromModuleToAccount_Call { _c.Call.Return(run) return _c } -// SendCoinsFromModuleToModule provides a mock function with given fields: ctx, senderModule, recipientModule, amt -func (_m *BankKeeper) SendCoinsFromModuleToModule(ctx types.Context, senderModule string, recipientModule string, amt types.Coins) error { - ret := _m.Called(ctx, senderModule, recipientModule, amt) +// SendCoinsFromModuleToModule provides a mock function with given fields: goCtx, senderModule, recipientModule, amt +func (_m *BankKeeper) SendCoinsFromModuleToModule(goCtx context.Context, senderModule string, recipientModule string, amt types.Coins) error { + ret := _m.Called(goCtx, senderModule, recipientModule, amt) if len(ret) == 0 { panic("no return value specified for SendCoinsFromModuleToModule") } var r0 error - if rf, ok := ret.Get(0).(func(types.Context, string, string, types.Coins) error); ok { - r0 = rf(ctx, senderModule, recipientModule, amt) + if rf, ok := ret.Get(0).(func(context.Context, string, string, types.Coins) error); ok { + r0 = rf(goCtx, senderModule, recipientModule, amt) } else { r0 = ret.Error(0) } @@ -382,17 +385,17 @@ type BankKeeper_SendCoinsFromModuleToModule_Call struct { } // SendCoinsFromModuleToModule is a helper method to define mock.On call -// - ctx types.Context +// - goCtx context.Context // - senderModule string // - recipientModule string // - amt types.Coins -func (_e *BankKeeper_Expecter) SendCoinsFromModuleToModule(ctx interface{}, senderModule interface{}, recipientModule interface{}, amt interface{}) *BankKeeper_SendCoinsFromModuleToModule_Call { - return &BankKeeper_SendCoinsFromModuleToModule_Call{Call: _e.mock.On("SendCoinsFromModuleToModule", ctx, senderModule, recipientModule, amt)} +func (_e *BankKeeper_Expecter) SendCoinsFromModuleToModule(goCtx interface{}, senderModule interface{}, recipientModule interface{}, amt interface{}) *BankKeeper_SendCoinsFromModuleToModule_Call { + return &BankKeeper_SendCoinsFromModuleToModule_Call{Call: _e.mock.On("SendCoinsFromModuleToModule", goCtx, senderModule, recipientModule, amt)} } -func (_c *BankKeeper_SendCoinsFromModuleToModule_Call) Run(run func(ctx types.Context, senderModule string, recipientModule string, amt types.Coins)) *BankKeeper_SendCoinsFromModuleToModule_Call { +func (_c *BankKeeper_SendCoinsFromModuleToModule_Call) Run(run func(goCtx context.Context, senderModule string, recipientModule string, amt types.Coins)) *BankKeeper_SendCoinsFromModuleToModule_Call { _c.Call.Run(func(args mock.Arguments) { - run(args[0].(types.Context), args[1].(string), args[2].(string), args[3].(types.Coins)) + run(args[0].(context.Context), args[1].(string), args[2].(string), args[3].(types.Coins)) }) return _c } @@ -402,22 +405,22 @@ func (_c *BankKeeper_SendCoinsFromModuleToModule_Call) Return(_a0 error) *BankKe return _c } -func (_c *BankKeeper_SendCoinsFromModuleToModule_Call) RunAndReturn(run func(types.Context, string, string, types.Coins) error) *BankKeeper_SendCoinsFromModuleToModule_Call { +func (_c *BankKeeper_SendCoinsFromModuleToModule_Call) RunAndReturn(run func(context.Context, string, string, types.Coins) error) *BankKeeper_SendCoinsFromModuleToModule_Call { _c.Call.Return(run) return _c } -// SpendableCoins provides a mock function with given fields: ctx, addr -func (_m *BankKeeper) SpendableCoins(ctx types.Context, addr types.AccAddress) types.Coins { - ret := _m.Called(ctx, addr) +// SpendableCoins provides a mock function with given fields: goCtx, addr +func (_m *BankKeeper) SpendableCoins(goCtx context.Context, addr types.AccAddress) types.Coins { + ret := _m.Called(goCtx, addr) if len(ret) == 0 { panic("no return value specified for SpendableCoins") } var r0 types.Coins - if rf, ok := ret.Get(0).(func(types.Context, types.AccAddress) types.Coins); ok { - r0 = rf(ctx, addr) + if rf, ok := ret.Get(0).(func(context.Context, types.AccAddress) types.Coins); ok { + r0 = rf(goCtx, addr) } else { if ret.Get(0) != nil { r0 = ret.Get(0).(types.Coins) @@ -433,15 +436,15 @@ type BankKeeper_SpendableCoins_Call struct { } // SpendableCoins is a helper method to define mock.On call -// - ctx types.Context +// - goCtx context.Context // - addr types.AccAddress -func (_e *BankKeeper_Expecter) SpendableCoins(ctx interface{}, addr interface{}) *BankKeeper_SpendableCoins_Call { - return &BankKeeper_SpendableCoins_Call{Call: _e.mock.On("SpendableCoins", ctx, addr)} +func (_e *BankKeeper_Expecter) SpendableCoins(goCtx interface{}, addr interface{}) *BankKeeper_SpendableCoins_Call { + return &BankKeeper_SpendableCoins_Call{Call: _e.mock.On("SpendableCoins", goCtx, addr)} } -func (_c *BankKeeper_SpendableCoins_Call) Run(run func(ctx types.Context, addr types.AccAddress)) *BankKeeper_SpendableCoins_Call { +func (_c *BankKeeper_SpendableCoins_Call) Run(run func(goCtx context.Context, addr types.AccAddress)) *BankKeeper_SpendableCoins_Call { _c.Call.Run(func(args mock.Arguments) { - run(args[0].(types.Context), args[1].(types.AccAddress)) + run(args[0].(context.Context), args[1].(types.AccAddress)) }) return _c } @@ -451,7 +454,7 @@ func (_c *BankKeeper_SpendableCoins_Call) Return(_a0 types.Coins) *BankKeeper_Sp return _c } -func (_c *BankKeeper_SpendableCoins_Call) RunAndReturn(run func(types.Context, types.AccAddress) types.Coins) *BankKeeper_SpendableCoins_Call { +func (_c *BankKeeper_SpendableCoins_Call) RunAndReturn(run func(context.Context, types.AccAddress) types.Coins) *BankKeeper_SpendableCoins_Call { _c.Call.Return(run) return _c } diff --git a/x/leveragelp/types/query.pb.go b/x/leveragelp/types/query.pb.go index f4327647a..d0459ec30 100644 --- a/x/leveragelp/types/query.pb.go +++ b/x/leveragelp/types/query.pb.go @@ -2155,7 +2155,6 @@ func _Query_CommittedTokensLocked_Handler(srv interface{}, ctx context.Context, return interceptor(ctx, in, info, handler) } -var Query_serviceDesc = _Query_serviceDesc var _Query_serviceDesc = grpc.ServiceDesc{ ServiceName: "elys.leveragelp.Query", HandlerType: (*QueryServer)(nil), diff --git a/x/leveragelp/types/tx.pb.go b/x/leveragelp/types/tx.pb.go index f88920aab..589a1145f 100644 --- a/x/leveragelp/types/tx.pb.go +++ b/x/leveragelp/types/tx.pb.go @@ -1436,7 +1436,6 @@ func _Msg_ClosePositions_Handler(srv interface{}, ctx context.Context, dec func( return interceptor(ctx, in, info, handler) } -var Msg_serviceDesc = _Msg_serviceDesc var _Msg_serviceDesc = grpc.ServiceDesc{ ServiceName: "elys.leveragelp.Msg", HandlerType: (*MsgServer)(nil), diff --git a/x/masterchef/types/query.pb.go b/x/masterchef/types/query.pb.go index 2316b5ec2..5aa2991d3 100644 --- a/x/masterchef/types/query.pb.go +++ b/x/masterchef/types/query.pb.go @@ -1954,7 +1954,6 @@ func _Query_PoolRewards_Handler(srv interface{}, ctx context.Context, dec func(i return interceptor(ctx, in, info, handler) } -var Query_serviceDesc = _Query_serviceDesc var _Query_serviceDesc = grpc.ServiceDesc{ ServiceName: "elys.masterchef.Query", HandlerType: (*QueryServer)(nil), diff --git a/x/masterchef/types/tx.pb.go b/x/masterchef/types/tx.pb.go index 0aeefc073..ff4e1b20a 100644 --- a/x/masterchef/types/tx.pb.go +++ b/x/masterchef/types/tx.pb.go @@ -951,7 +951,6 @@ func _Msg_TogglePoolEdenRewards_Handler(srv interface{}, ctx context.Context, de return interceptor(ctx, in, info, handler) } -var Msg_serviceDesc = _Msg_serviceDesc var _Msg_serviceDesc = grpc.ServiceDesc{ ServiceName: "elys.masterchef.Msg", HandlerType: (*MsgServer)(nil), diff --git a/x/oracle/types/query.pb.go b/x/oracle/types/query.pb.go index 8b2c2f4fd..38e20e060 100644 --- a/x/oracle/types/query.pb.go +++ b/x/oracle/types/query.pb.go @@ -1280,7 +1280,6 @@ func _Query_PriceFeederAll_Handler(srv interface{}, ctx context.Context, dec fun return interceptor(ctx, in, info, handler) } -var Query_serviceDesc = _Query_serviceDesc var _Query_serviceDesc = grpc.ServiceDesc{ ServiceName: "elys.oracle.Query", HandlerType: (*QueryServer)(nil), diff --git a/x/oracle/types/tx.pb.go b/x/oracle/types/tx.pb.go index 9a2e2ac05..cadd3c47b 100644 --- a/x/oracle/types/tx.pb.go +++ b/x/oracle/types/tx.pb.go @@ -1276,7 +1276,6 @@ func _Msg_CreateAssetInfo_Handler(srv interface{}, ctx context.Context, dec func return interceptor(ctx, in, info, handler) } -var Msg_serviceDesc = _Msg_serviceDesc var _Msg_serviceDesc = grpc.ServiceDesc{ ServiceName: "elys.oracle.Msg", HandlerType: (*MsgServer)(nil), diff --git a/x/parameter/types/query.pb.go b/x/parameter/types/query.pb.go index 5e460ad8c..1cfe0187a 100644 --- a/x/parameter/types/query.pb.go +++ b/x/parameter/types/query.pb.go @@ -209,7 +209,6 @@ func _Query_Params_Handler(srv interface{}, ctx context.Context, dec func(interf return interceptor(ctx, in, info, handler) } -var Query_serviceDesc = _Query_serviceDesc var _Query_serviceDesc = grpc.ServiceDesc{ ServiceName: "elys.parameter.Query", HandlerType: (*QueryServer)(nil), diff --git a/x/parameter/types/tx.pb.go b/x/parameter/types/tx.pb.go index a0e8231ef..5e02d5a98 100644 --- a/x/parameter/types/tx.pb.go +++ b/x/parameter/types/tx.pb.go @@ -849,7 +849,6 @@ func _Msg_UpdateRewardsDataLifetime_Handler(srv interface{}, ctx context.Context return interceptor(ctx, in, info, handler) } -var Msg_serviceDesc = _Msg_serviceDesc var _Msg_serviceDesc = grpc.ServiceDesc{ ServiceName: "elys.parameter.Msg", HandlerType: (*MsgServer)(nil), diff --git a/x/perpetual/keeper/estimate_and_repay.go b/x/perpetual/keeper/estimate_and_repay.go index 0f6f2e922..01696114f 100644 --- a/x/perpetual/keeper/estimate_and_repay.go +++ b/x/perpetual/keeper/estimate_and_repay.go @@ -1,8 +1,9 @@ package keeper import ( - "cosmossdk.io/math" "fmt" + + "cosmossdk.io/math" sdk "github.com/cosmos/cosmos-sdk/types" ammtypes "github.com/elys-network/elys/x/amm/types" "github.com/elys-network/elys/x/perpetual/types" @@ -47,7 +48,7 @@ func (k Keeper) CalcRepayAmount(ctx sdk.Context, mtp *types.MTP, ammPool *ammtyp if mtp.Position == types.Position_LONG { liabilitiesWithClosingRatio := sdk.NewCoin(mtp.LiabilitiesAsset, payingLiabilities) - repayAmount, slippage, weightBreakingFee, err = k.EstimateSwapGivenOut(ctx, liabilitiesWithClosingRatio, mtp.CustodyAsset, *ammPool) + repayAmount, slippage, weightBreakingFee, err = k.EstimateSwapGivenOut(ctx, liabilitiesWithClosingRatio, mtp.CustodyAsset, *ammPool, mtp.Address) if err != nil { return math.ZeroInt(), math.ZeroInt(), math.LegacyZeroDec(), math.LegacyZeroDec(), err } @@ -55,7 +56,7 @@ func (k Keeper) CalcRepayAmount(ctx sdk.Context, mtp *types.MTP, ammPool *ammtyp if mtp.Position == types.Position_SHORT { // if position is short, repay in custody asset which is base currency liabilitiesWithClosingRatio := sdk.NewCoin(mtp.LiabilitiesAsset, payingLiabilities) - repayAmount, slippage, weightBreakingFee, err = k.EstimateSwapGivenOut(ctx, liabilitiesWithClosingRatio, mtp.CustodyAsset, *ammPool) + repayAmount, slippage, weightBreakingFee, err = k.EstimateSwapGivenOut(ctx, liabilitiesWithClosingRatio, mtp.CustodyAsset, *ammPool, mtp.Address) if err != nil { return math.ZeroInt(), math.ZeroInt(), math.LegacyZeroDec(), math.LegacyZeroDec(), err } diff --git a/x/perpetual/keeper/estimate_swap.go b/x/perpetual/keeper/estimate_swap.go index 55b5651ca..60c54a5c8 100644 --- a/x/perpetual/keeper/estimate_swap.go +++ b/x/perpetual/keeper/estimate_swap.go @@ -22,15 +22,22 @@ func getWeightBreakingFee(weightBalanceBonus math.LegacyDec) math.LegacyDec { } // Swap estimation using amm CalcOutAmtGivenIn function -func (k Keeper) EstimateSwapGivenIn(ctx sdk.Context, tokenInAmount sdk.Coin, tokenOutDenom string, ammPool ammtypes.Pool) (math.Int, math.LegacyDec, math.LegacyDec, error) { +func (k Keeper) EstimateSwapGivenIn(ctx sdk.Context, tokenInAmount sdk.Coin, tokenOutDenom string, ammPool ammtypes.Pool, owner string) (math.Int, math.LegacyDec, math.LegacyDec, error) { if tokenInAmount.IsZero() { return math.Int{}, math.LegacyDec{}, math.LegacyDec{}, fmt.Errorf("tokenInAmount is zero for EstimateSwapGivenIn") } params := k.GetParams(ctx) + + addr, err := sdk.AccAddressFromBech32(owner) + if err != nil { + addr = sdk.AccAddress{} + } + _, tier := k.tierKeeper.GetMembershipTier(ctx, addr) + perpetualFees := ammtypes.ApplyDiscount(params.PerpetualSwapFee, tier.Discount) // Estimate swap snapshot := k.amm.GetAccountedPoolSnapshotOrSet(ctx, ammPool) tokensIn := sdk.Coins{tokenInAmount} - tokenOut, slippage, _, weightBalanceBonus, err := k.amm.SwapOutAmtGivenIn(ctx, ammPool.PoolId, k.oracleKeeper, &snapshot, tokensIn, tokenOutDenom, params.PerpetualSwapFee, params.WeightBreakingFeeFactor) + tokenOut, slippage, _, weightBalanceBonus, err := k.amm.SwapOutAmtGivenIn(ctx, ammPool.PoolId, k.oracleKeeper, &snapshot, tokensIn, tokenOutDenom, perpetualFees, params.WeightBreakingFeeFactor) if err != nil { return math.ZeroInt(), math.LegacyZeroDec(), math.LegacyZeroDec(), errorsmod.Wrapf(err, "unable to swap (EstimateSwapGivenIn) for in %s and out denom %s", tokenInAmount.String(), tokenOutDenom) } @@ -42,15 +49,23 @@ func (k Keeper) EstimateSwapGivenIn(ctx sdk.Context, tokenInAmount sdk.Coin, tok } // Swap estimation using amm CalcInAmtGivenOut function -func (k Keeper) EstimateSwapGivenOut(ctx sdk.Context, tokenOutAmount sdk.Coin, tokenInDenom string, ammPool ammtypes.Pool) (math.Int, math.LegacyDec, math.LegacyDec, error) { +func (k Keeper) EstimateSwapGivenOut(ctx sdk.Context, tokenOutAmount sdk.Coin, tokenInDenom string, ammPool ammtypes.Pool, owner string) (math.Int, math.LegacyDec, math.LegacyDec, error) { if tokenOutAmount.IsZero() { return math.Int{}, math.LegacyDec{}, math.LegacyDec{}, fmt.Errorf("tokenOutAmount is zero for EstimateSwapGivenOut") } params := k.GetParams(ctx) tokensOut := sdk.Coins{tokenOutAmount} + + addr, err := sdk.AccAddressFromBech32(owner) + if err != nil { + addr = sdk.AccAddress{} + } + _, tier := k.tierKeeper.GetMembershipTier(ctx, addr) + perpetualFees := ammtypes.ApplyDiscount(params.PerpetualSwapFee, tier.Discount) + // Estimate swap snapshot := k.amm.GetAccountedPoolSnapshotOrSet(ctx, ammPool) - tokenIn, slippage, _, weightBalanceBonus, err := k.amm.SwapInAmtGivenOut(ctx, ammPool.PoolId, k.oracleKeeper, &snapshot, tokensOut, tokenInDenom, params.PerpetualSwapFee, params.WeightBreakingFeeFactor) + tokenIn, slippage, _, weightBalanceBonus, err := k.amm.SwapInAmtGivenOut(ctx, ammPool.PoolId, k.oracleKeeper, &snapshot, tokensOut, tokenInDenom, perpetualFees, params.WeightBreakingFeeFactor) if err != nil { return math.ZeroInt(), math.LegacyZeroDec(), math.LegacyZeroDec(), errorsmod.Wrapf(err, "unable to swap (EstimateSwapGivenOut) for out %s and in denom %s", tokenOutAmount.String(), tokenInDenom) } diff --git a/x/perpetual/keeper/keeper.go b/x/perpetual/keeper/keeper.go index df7db7201..1231fc79e 100644 --- a/x/perpetual/keeper/keeper.go +++ b/x/perpetual/keeper/keeper.go @@ -1,9 +1,10 @@ package keeper import ( + "fmt" + "cosmossdk.io/core/store" "cosmossdk.io/log" - "fmt" "github.com/cosmos/cosmos-sdk/codec" sdk "github.com/cosmos/cosmos-sdk/types" @@ -12,6 +13,7 @@ import ( ammtypes "github.com/elys-network/elys/x/amm/types" pkeeper "github.com/elys-network/elys/x/parameter/keeper" "github.com/elys-network/elys/x/perpetual/types" + tierkeeper "github.com/elys-network/elys/x/tier/keeper" ) type ( @@ -24,6 +26,7 @@ type ( bankKeeper types.BankKeeper oracleKeeper types.OracleKeeper assetProfileKeeper types.AssetProfileKeeper + tierKeeper *tierkeeper.Keeper hooks types.PerpetualHooks } @@ -38,6 +41,7 @@ func NewKeeper( oracleKeeper types.OracleKeeper, assetProfileKeeper types.AssetProfileKeeper, parameterKeeper *pkeeper.Keeper, + tierKeeper *tierkeeper.Keeper, ) *Keeper { // ensure that authority is a valid AccAddress if _, err := sdk.AccAddressFromBech32(authority); err != nil { @@ -53,6 +57,7 @@ func NewKeeper( oracleKeeper: oracleKeeper, assetProfileKeeper: assetProfileKeeper, parameterKeeper: parameterKeeper, + tierKeeper: tierKeeper, } return keeper @@ -62,6 +67,14 @@ func (k Keeper) Logger(ctx sdk.Context) log.Logger { return ctx.Logger().With("module", fmt.Sprintf("x/%s", types.ModuleName)) } +func (k *Keeper) SetTierKeeper(tk *tierkeeper.Keeper) { + k.tierKeeper = tk +} + +func (k *Keeper) GetTierKeeper() *tierkeeper.Keeper { + return k.tierKeeper +} + func (k Keeper) Borrow(ctx sdk.Context, collateralAmount math.Int, custodyAmount math.Int, mtp *types.MTP, ammPool *ammtypes.Pool, pool *types.Pool, proxyLeverage math.LegacyDec, baseCurrency string, isBroker bool) error { senderAddress, err := sdk.AccAddressFromBech32(mtp.Address) if err != nil { @@ -93,7 +106,7 @@ func (k Keeper) Borrow(ctx sdk.Context, collateralAmount math.Int, custodyAmount if !liabilities.IsZero() { liabilitiesInCollateralTokenOut := sdk.NewCoin(mtp.CollateralAsset, liabilitiesInCollateral) // Calculate base currency amount given atom out amount and we use it liabilty amount in base currency - liabilities, _, _, err = k.EstimateSwapGivenOut(ctx, liabilitiesInCollateralTokenOut, baseCurrency, *ammPool) + liabilities, _, _, err = k.EstimateSwapGivenOut(ctx, liabilitiesInCollateralTokenOut, baseCurrency, *ammPool, mtp.Address) if err != nil { return err } @@ -105,7 +118,7 @@ func (k Keeper) Borrow(ctx sdk.Context, collateralAmount math.Int, custodyAmount // liabilities.IsZero() happens when we are consolidating with leverage 1 as eta = 0 if !liabilities.IsZero() { liabilitiesInCollateralTokenIn := sdk.NewCoin(baseCurrency, liabilities) - liabilities, _, _, err = k.EstimateSwapGivenOut(ctx, liabilitiesInCollateralTokenIn, mtp.LiabilitiesAsset, *ammPool) + liabilities, _, _, err = k.EstimateSwapGivenOut(ctx, liabilitiesInCollateralTokenIn, mtp.LiabilitiesAsset, *ammPool, mtp.Address) if err != nil { return err } diff --git a/x/perpetual/keeper/mtp_health.go b/x/perpetual/keeper/mtp_health.go index 5872ec770..93f9cf8dc 100644 --- a/x/perpetual/keeper/mtp_health.go +++ b/x/perpetual/keeper/mtp_health.go @@ -21,7 +21,7 @@ func (k Keeper) GetMTPHealth(ctx sdk.Context, mtp types.MTP, ammPool ammtypes.Po if mtp.Position == types.Position_SHORT { liabilitiesTokenOut := sdk.NewCoin(mtp.LiabilitiesAsset, totalLiabilities) var err error - totalLiabilities, _, _, err = k.EstimateSwapGivenOut(ctx, liabilitiesTokenOut, baseCurrency, ammPool) + totalLiabilities, _, _, err = k.EstimateSwapGivenOut(ctx, liabilitiesTokenOut, baseCurrency, ammPool, mtp.Address) if err != nil { return math.LegacyZeroDec(), err } @@ -43,7 +43,7 @@ func (k Keeper) GetMTPHealth(ctx sdk.Context, mtp types.MTP, ammPool ammtypes.Po if mtp.Position == types.Position_LONG { custodyAmtTokenOut := sdk.NewCoin(mtp.CustodyAsset, custodyAmtInBaseCurrency) var err error - custodyAmtInBaseCurrency, _, _, err = k.EstimateSwapGivenOut(ctx, custodyAmtTokenOut, baseCurrency, ammPool) + custodyAmtInBaseCurrency, _, _, err = k.EstimateSwapGivenOut(ctx, custodyAmtTokenOut, baseCurrency, ammPool, mtp.Address) if err != nil { return math.LegacyZeroDec(), err } diff --git a/x/perpetual/keeper/process_open.go b/x/perpetual/keeper/process_open.go index 8fc90b322..ccdf4be12 100644 --- a/x/perpetual/keeper/process_open.go +++ b/x/perpetual/keeper/process_open.go @@ -33,7 +33,7 @@ func (k Keeper) ProcessOpen(ctx sdk.Context, mtp *types.MTP, proxyLeverage sdkma // If collateral is not base currency, calculate the borrowing amount in base currency and check the balance if mtp.CollateralAsset != baseCurrency { custodyAmtToken := sdk.NewCoin(mtp.CollateralAsset, leveragedAmount) - borrowingAmount, _, _, err := k.EstimateSwapGivenOut(ctx, custodyAmtToken, baseCurrency, ammPool) + borrowingAmount, _, _, err := k.EstimateSwapGivenOut(ctx, custodyAmtToken, baseCurrency, ammPool, mtp.Address) if err != nil { return nil, err } @@ -49,7 +49,7 @@ func (k Keeper) ProcessOpen(ctx sdk.Context, mtp *types.MTP, proxyLeverage sdkma // If position is long, calculate custody amount in custody asset if mtp.CollateralAsset == baseCurrency { leveragedAmtTokenIn := sdk.NewCoin(mtp.CollateralAsset, leveragedAmount) - custodyAmount, _, _, err = k.EstimateSwapGivenIn(ctx, leveragedAmtTokenIn, mtp.CustodyAsset, ammPool) + custodyAmount, _, _, err = k.EstimateSwapGivenIn(ctx, leveragedAmtTokenIn, mtp.CustodyAsset, ammPool, mtp.Address) if err != nil { return nil, err } diff --git a/x/perpetual/keeper/query_open_estimation.go b/x/perpetual/keeper/query_open_estimation.go index c11a4b15b..3cf5081dd 100644 --- a/x/perpetual/keeper/query_open_estimation.go +++ b/x/perpetual/keeper/query_open_estimation.go @@ -2,6 +2,7 @@ package keeper import ( "context" + errorsmod "cosmossdk.io/errors" "cosmossdk.io/math" sdk "github.com/cosmos/cosmos-sdk/types" @@ -105,7 +106,7 @@ func (k Keeper) HandleOpenEstimation(ctx sdk.Context, req *types.QueryOpenEstima //getting custody if mtp.CollateralAsset == baseCurrency { leveragedAmtTokenIn := sdk.NewCoin(mtp.CollateralAsset, leveragedAmount) - custodyAmount, slippage, weightBreakingFee, err = k.EstimateSwapGivenIn(ctx, leveragedAmtTokenIn, mtp.CustodyAsset, ammPool) + custodyAmount, slippage, weightBreakingFee, err = k.EstimateSwapGivenIn(ctx, leveragedAmtTokenIn, mtp.CustodyAsset, ammPool, mtp.Address) if err != nil { return nil, err } @@ -118,7 +119,7 @@ func (k Keeper) HandleOpenEstimation(ctx sdk.Context, req *types.QueryOpenEstima //getting Liabilities if mtp.CollateralAsset != baseCurrency { amountIn := req.Collateral.Amount.ToLegacyDec().Mul(eta).TruncateInt() - liabilities, slippage, weightBreakingFee, err = k.EstimateSwapGivenOut(ctx, sdk.NewCoin(req.Collateral.Denom, amountIn), baseCurrency, ammPool) + liabilities, slippage, weightBreakingFee, err = k.EstimateSwapGivenOut(ctx, sdk.NewCoin(req.Collateral.Denom, amountIn), baseCurrency, ammPool, mtp.Address) if err != nil { return nil, err } @@ -134,7 +135,7 @@ func (k Keeper) HandleOpenEstimation(ctx sdk.Context, req *types.QueryOpenEstima // Collateral will be in base currency amountOut := req.Collateral.Amount.ToLegacyDec().Mul(eta).TruncateInt() tokenOut := sdk.NewCoin(baseCurrency, amountOut) - liabilities, slippage, weightBreakingFee, err = k.EstimateSwapGivenOut(ctx, tokenOut, mtp.LiabilitiesAsset, ammPool) + liabilities, slippage, weightBreakingFee, err = k.EstimateSwapGivenOut(ctx, tokenOut, mtp.LiabilitiesAsset, ammPool, mtp.Address) if err != nil { return nil, err } diff --git a/x/perpetual/keeper/query_pool_test.go b/x/perpetual/keeper/query_pool_test.go index b30d47d76..0b8bfd030 100644 --- a/x/perpetual/keeper/query_pool_test.go +++ b/x/perpetual/keeper/query_pool_test.go @@ -1,9 +1,10 @@ package keeper_test import ( - ptypes "github.com/elys-network/elys/x/parameter/types" "testing" + ptypes "github.com/elys-network/elys/x/parameter/types" + sdk "github.com/cosmos/cosmos-sdk/types" "github.com/stretchr/testify/assert" "google.golang.org/grpc/codes" @@ -16,7 +17,7 @@ import ( ) func TestPools_InvalidRequest(t *testing.T) { - k := keeper.NewKeeper(nil, nil, "cosmos1ysxv266l8w76lq0vy44ktzajdr9u9yhlxzlvga", nil, nil, nil, nil, nil) + k := keeper.NewKeeper(nil, nil, "cosmos1ysxv266l8w76lq0vy44ktzajdr9u9yhlxzlvga", nil, nil, nil, nil, nil, nil) ctx := sdk.Context{} _, err := k.Pools(ctx, nil) diff --git a/x/perpetual/types/query.pb.go b/x/perpetual/types/query.pb.go index 7d4d5475e..f2fab00a9 100644 --- a/x/perpetual/types/query.pb.go +++ b/x/perpetual/types/query.pb.go @@ -2253,7 +2253,6 @@ func _Query_CloseEstimation_Handler(srv interface{}, ctx context.Context, dec fu return interceptor(ctx, in, info, handler) } -var Query_serviceDesc = _Query_serviceDesc var _Query_serviceDesc = grpc.ServiceDesc{ ServiceName: "elys.perpetual.Query", HandlerType: (*QueryServer)(nil), diff --git a/x/perpetual/types/tx.pb.go b/x/perpetual/types/tx.pb.go index bb8b9a89f..79f00d4ac 100644 --- a/x/perpetual/types/tx.pb.go +++ b/x/perpetual/types/tx.pb.go @@ -1404,7 +1404,6 @@ func _Msg_UpdateTakeProfitPrice_Handler(srv interface{}, ctx context.Context, de return interceptor(ctx, in, info, handler) } -var Msg_serviceDesc = _Msg_serviceDesc var _Msg_serviceDesc = grpc.ServiceDesc{ ServiceName: "elys.perpetual.Msg", HandlerType: (*MsgServer)(nil), diff --git a/x/stablestake/types/query.pb.go b/x/stablestake/types/query.pb.go index 9130177ec..36617f22e 100644 --- a/x/stablestake/types/query.pb.go +++ b/x/stablestake/types/query.pb.go @@ -337,7 +337,6 @@ func _Query_BorrowRatio_Handler(srv interface{}, ctx context.Context, dec func(i return interceptor(ctx, in, info, handler) } -var Query_serviceDesc = _Query_serviceDesc var _Query_serviceDesc = grpc.ServiceDesc{ ServiceName: "elys.stablestake.Query", HandlerType: (*QueryServer)(nil), diff --git a/x/stablestake/types/tx.pb.go b/x/stablestake/types/tx.pb.go index b9af122a7..3ec2d38fb 100644 --- a/x/stablestake/types/tx.pb.go +++ b/x/stablestake/types/tx.pb.go @@ -462,7 +462,6 @@ func _Msg_UpdateParams_Handler(srv interface{}, ctx context.Context, dec func(in return interceptor(ctx, in, info, handler) } -var Msg_serviceDesc = _Msg_serviceDesc var _Msg_serviceDesc = grpc.ServiceDesc{ ServiceName: "elys.stablestake.Msg", HandlerType: (*MsgServer)(nil), diff --git a/x/tier/keeper/portfolio.go b/x/tier/keeper/portfolio.go index 7469091cb..6ffb3a022 100644 --- a/x/tier/keeper/portfolio.go +++ b/x/tier/keeper/portfolio.go @@ -370,7 +370,7 @@ func (k Keeper) GetPortfolio(ctx sdk.Context, user sdk.AccAddress, date string) return val.Portfolio, true } -func (k Keeper) GetMembershipTier(ctx sdk.Context, user sdk.AccAddress) (total_portfolio sdkmath.LegacyDec, tier string, discount uint64) { +func (k Keeper) GetMembershipTier(ctx sdk.Context, user sdk.AccAddress) (total_portfolio sdkmath.LegacyDec, membership_tier types.MembershipTier) { year, month, day := ctx.BlockTime().Date() dateToday := time.Date(year, month, day, 0, 0, 0, 0, ctx.BlockTime().Location()) startDate := dateToday.AddDate(0, 0, -7) @@ -384,23 +384,23 @@ func (k Keeper) GetMembershipTier(ctx sdk.Context, user sdk.AccAddress) (total_p } if minTotal.Equal(sdkmath.LegacyNewDec(math.MaxInt64)) { - return sdkmath.LegacyNewDec(0), "bronze", 0 + return sdkmath.LegacyNewDec(0), types.Bronze } // TODO: Make tier discount and minimum balance configurable if minTotal.GTE(sdkmath.LegacyNewDec(500000)) { - return minTotal, "platinum", 30 + return minTotal, types.Platinum } if minTotal.GTE(sdkmath.LegacyNewDec(250000)) { - return minTotal, "gold", 20 + return minTotal, types.Gold } if minTotal.GTE(sdkmath.LegacyNewDec(50000)) { - return minTotal, "silver", 10 + return minTotal, types.Silver } - return minTotal, "bronze", 0 + return minTotal, types.Bronze } // RemovePortfolioLast removes a portfolio from the store with a specific date diff --git a/x/tier/keeper/portfolio_test.go b/x/tier/keeper/portfolio_test.go index e060748a0..68122f794 100644 --- a/x/tier/keeper/portfolio_test.go +++ b/x/tier/keeper/portfolio_test.go @@ -5,6 +5,7 @@ import ( "testing" "cosmossdk.io/math" + sdkmath "cosmossdk.io/math" "github.com/cometbft/cometbft/crypto/ed25519" sdk "github.com/cosmos/cosmos-sdk/types" @@ -209,11 +210,11 @@ func TestPortfolioGetDiscount(t *testing.T) { keeper.SetPortfolio(ctx, items[9]) - _, _, discount := keeper.GetMembershipTier(ctx, sdk.MustAccAddressFromBech32(items[0].Creator)) - require.Equal(t, discount, uint64(20)) + _, tier := keeper.GetMembershipTier(ctx, sdk.MustAccAddressFromBech32(items[0].Creator)) + require.Equal(t, tier.Discount, sdkmath.LegacyMustNewDecFromStr("0.2")) - _, _, discount = keeper.GetMembershipTier(ctx, sdk.MustAccAddressFromBech32(items[9].Creator)) - require.Equal(t, discount, uint64(0)) + _, tier = keeper.GetMembershipTier(ctx, sdk.MustAccAddressFromBech32(items[9].Creator)) + require.Equal(t, tier.Discount, sdkmath.LegacyZeroDec()) } func TestGetPortfolioPerpetual(t *testing.T) { diff --git a/x/tier/keeper/query_calculate_discount.go b/x/tier/keeper/query_calculate_discount.go index d4a0d4855..b14e87b67 100644 --- a/x/tier/keeper/query_calculate_discount.go +++ b/x/tier/keeper/query_calculate_discount.go @@ -2,7 +2,6 @@ package keeper import ( "context" - "strconv" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/elys-network/elys/x/tier/types" @@ -22,11 +21,10 @@ func (k Keeper) CalculateDiscount(goCtx context.Context, req *types.QueryCalcula return nil, status.Error(codes.InvalidArgument, err.Error()) } - portfolio, tier, discount := k.GetMembershipTier(ctx, user) + portfolio, tier := k.GetMembershipTier(ctx, user) return &types.QueryCalculateDiscountResponse{ - Discount: strconv.FormatUint(discount, 10), - Portfolio: portfolio.String(), - Tier: tier, + Portfolio: portfolio.String(), + MembershipTier: &tier, }, nil } diff --git a/x/tier/types/query.pb.go b/x/tier/types/query.pb.go index 2f6ff2352..d29f3f4d8 100644 --- a/x/tier/types/query.pb.go +++ b/x/tier/types/query.pb.go @@ -343,9 +343,8 @@ func (m *QueryCalculateDiscountRequest) GetUser() string { } type QueryCalculateDiscountResponse struct { - Discount string `protobuf:"bytes,1,opt,name=discount,proto3" json:"discount,omitempty"` - Tier string `protobuf:"bytes,2,opt,name=tier,proto3" json:"tier,omitempty"` - Portfolio string `protobuf:"bytes,3,opt,name=portfolio,proto3" json:"portfolio,omitempty"` + MembershipTier *MembershipTier `protobuf:"bytes,1,opt,name=membership_tier,json=membershipTier,proto3" json:"membership_tier,omitempty"` + Portfolio string `protobuf:"bytes,2,opt,name=portfolio,proto3" json:"portfolio,omitempty"` } func (m *QueryCalculateDiscountResponse) Reset() { *m = QueryCalculateDiscountResponse{} } @@ -381,18 +380,11 @@ func (m *QueryCalculateDiscountResponse) XXX_DiscardUnknown() { var xxx_messageInfo_QueryCalculateDiscountResponse proto.InternalMessageInfo -func (m *QueryCalculateDiscountResponse) GetDiscount() string { +func (m *QueryCalculateDiscountResponse) GetMembershipTier() *MembershipTier { if m != nil { - return m.Discount + return m.MembershipTier } - return "" -} - -func (m *QueryCalculateDiscountResponse) GetTier() string { - if m != nil { - return m.Tier - } - return "" + return nil } func (m *QueryCalculateDiscountResponse) GetPortfolio() string { @@ -1193,91 +1185,92 @@ func init() { func init() { proto.RegisterFile("elys/tier/query.proto", fileDescriptor_461504ebf74c9a97) } var fileDescriptor_461504ebf74c9a97 = []byte{ - // 1338 bytes of a gzipped FileDescriptorProto + // 1345 bytes of a gzipped FileDescriptorProto 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xcc, 0x98, 0x4f, 0x6f, 0xd4, 0xc6, - 0x1b, 0xc7, 0x63, 0x20, 0xf9, 0xb1, 0xcf, 0xe6, 0xc7, 0x9f, 0x21, 0xd0, 0x60, 0x60, 0x01, 0xa7, - 0x25, 0x0b, 0x24, 0x36, 0x2c, 0xa8, 0x0d, 0xad, 0xfa, 0x87, 0x64, 0x4b, 0x5a, 0x29, 0x95, 0xd2, - 0x2d, 0x70, 0xe8, 0x65, 0x35, 0x6b, 0x0f, 0xc6, 0xc2, 0xf6, 0x18, 0x7b, 0x36, 0x34, 0x42, 0x5c, - 0xb8, 0x54, 0x55, 0xa5, 0xb6, 0x2a, 0x87, 0x4a, 0x55, 0xd5, 0x73, 0x2f, 0xad, 0xda, 0x77, 0xc1, - 0x11, 0xa9, 0x97, 0xaa, 0x07, 0x54, 0x91, 0xbe, 0x8c, 0x1e, 0x2a, 0xcf, 0x8c, 0x77, 0xed, 0xb5, - 0xd7, 0xbb, 0xab, 0x70, 0xe8, 0x29, 0xeb, 0xf1, 0xf3, 0x7d, 0x9e, 0xcf, 0x3c, 0x33, 0x9e, 0xf9, - 0x2a, 0x70, 0x94, 0xb8, 0xdb, 0x91, 0xc1, 0x1c, 0x12, 0x1a, 0xf7, 0xbb, 0x24, 0xdc, 0xd6, 0x83, - 0x90, 0x32, 0x8a, 0x2a, 0xf1, 0xb0, 0x1e, 0x0f, 0xab, 0x73, 0x36, 0xb5, 0x29, 0x1f, 0x35, 0xe2, - 0x5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0, 0xdf, 0x14, 0x58, 0x2c, 0xf2, 0x45, 0xe8, 0x5c, + 0x41, 0xf9, 0x61, 0xc6, 0x4b, 0x5d, 0x19, 0x2f, 0x58, 0x42, 0xbf, 0xcb, 0xa1, 0xd7, 0xd0, 0x1b, + 0x65, 0xd0, 0x66, 0x4a, 0x9e, 0xa5, 0x47, 0x3b, 0x30, 0x2b, 0xb6, 0x6a, 0xfe, 0xb2, 0xc9, 0x98, + 0x9c, 0xfc, 0x65, 0x93, 0x35, 0x36, 0xda, 0x2a, 0x07, 0x59, 0x46, 0xaf, 0x97, 0xef, 0xee, 0x64, + 0x15, 0xbf, 0x57, 0x60, 0xff, 0xe0, 0xfd, 0x8b, 0x96, 0x0b, 0xa6, 0x5e, 0x64, 0x05, 0xd4, 0xfa, + 0xe8, 0xc0, 0x71, 0xb7, 0x58, 0xdc, 0x1f, 0x7e, 0x95, 0xf3, 0x73, 0xd7, 0xb6, 0x30, 0xc3, 0xeb, + 0x1b, 0x8f, 0x9f, 0xd5, 0x94, 0x27, 0xcf, 0x6a, 0xca, 0x5f, 0xcf, 0x6a, 0xca, 0x37, 0xcf, 0x6b, + 0x53, 0x4f, 0x9e, 0xd7, 0xa6, 0xfe, 0x78, 0x5e, 0x9b, 0xfa, 0xf4, 0x8c, 0xed, 0xb0, 0xdb, 0xdd, + 0x8e, 0x6e, 0x52, 0xaf, 0x20, 0xe1, 0x67, 0x22, 0x25, 0xdb, 0x0d, 0x48, 0xd4, 0x99, 0xe5, 0xff, + 0xee, 0xb9, 0xf8, 0x6f, 0x00, 0x00, 0x00, 0xff, 0xff, 0x7c, 0xa5, 0x03, 0x11, 0xbf, 0x12, 0x00, + 0x00, } // Reference imports to suppress errors if they are not otherwise used. @@ -1755,7 +1748,6 @@ func _Query_GetUsersPoolData_Handler(srv interface{}, ctx context.Context, dec f return interceptor(ctx, in, info, handler) } -var Query_serviceDesc = _Query_serviceDesc var _Query_serviceDesc = grpc.ServiceDesc{ ServiceName: "elys.tier.Query", HandlerType: (*QueryServer)(nil), @@ -2072,19 +2064,17 @@ func (m *QueryCalculateDiscountResponse) MarshalToSizedBuffer(dAtA []byte) (int, copy(dAtA[i:], m.Portfolio) i = encodeVarintQuery(dAtA, i, uint64(len(m.Portfolio))) i-- - dAtA[i] = 0x1a - } - if len(m.Tier) > 0 { - i -= len(m.Tier) - copy(dAtA[i:], m.Tier) - i = encodeVarintQuery(dAtA, i, uint64(len(m.Tier))) - i-- dAtA[i] = 0x12 } - if len(m.Discount) > 0 { - i -= len(m.Discount) - copy(dAtA[i:], m.Discount) - i = encodeVarintQuery(dAtA, i, uint64(len(m.Discount))) + if m.MembershipTier != nil { + { + size, err := m.MembershipTier.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintQuery(dAtA, i, uint64(size)) + } i-- dAtA[i] = 0xa } @@ -2862,12 +2852,8 @@ func (m *QueryCalculateDiscountResponse) Size() (n int) { } var l int _ = l - l = len(m.Discount) - if l > 0 { - n += 1 + l + sovQuery(uint64(l)) - } - l = len(m.Tier) - if l > 0 { + if m.MembershipTier != nil { + l = m.MembershipTier.Size() n += 1 + l + sovQuery(uint64(l)) } l = len(m.Portfolio) @@ -3740,9 +3726,9 @@ func (m *QueryCalculateDiscountResponse) Unmarshal(dAtA []byte) error { switch fieldNum { case 1: if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Discount", wireType) + return fmt.Errorf("proto: wrong wireType = %d for field MembershipTier", wireType) } - var stringLen uint64 + var msglen int for shift := uint(0); ; shift += 7 { if shift >= 64 { return ErrIntOverflowQuery @@ -3752,57 +3738,29 @@ func (m *QueryCalculateDiscountResponse) Unmarshal(dAtA []byte) error { } b := dAtA[iNdEx] iNdEx++ - stringLen |= uint64(b&0x7F) << shift + msglen |= int(b&0x7F) << shift if b < 0x80 { break } } - intStringLen := int(stringLen) - if intStringLen < 0 { + if msglen < 0 { return ErrInvalidLengthQuery } - postIndex := iNdEx + intStringLen + postIndex := iNdEx + msglen if postIndex < 0 { return ErrInvalidLengthQuery } if postIndex > l { return io.ErrUnexpectedEOF } - m.Discount = string(dAtA[iNdEx:postIndex]) - iNdEx = postIndex - case 2: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Tier", wireType) - } - var stringLen uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowQuery - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - stringLen |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - intStringLen := int(stringLen) - if intStringLen < 0 { - return ErrInvalidLengthQuery + if m.MembershipTier == nil { + m.MembershipTier = &MembershipTier{} } - postIndex := iNdEx + intStringLen - if postIndex < 0 { - return ErrInvalidLengthQuery - } - if postIndex > l { - return io.ErrUnexpectedEOF + if err := m.MembershipTier.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err } - m.Tier = string(dAtA[iNdEx:postIndex]) iNdEx = postIndex - case 3: + case 2: if wireType != 2 { return fmt.Errorf("proto: wrong wireType = %d for field Portfolio", wireType) } diff --git a/x/tier/types/tx.pb.go b/x/tier/types/tx.pb.go index 3f8f67e92..36df4574e 100644 --- a/x/tier/types/tx.pb.go +++ b/x/tier/types/tx.pb.go @@ -216,7 +216,6 @@ func _Msg_SetPortfolio_Handler(srv interface{}, ctx context.Context, dec func(in return interceptor(ctx, in, info, handler) } -var Msg_serviceDesc = _Msg_serviceDesc var _Msg_serviceDesc = grpc.ServiceDesc{ ServiceName: "elys.tier.Msg", HandlerType: (*MsgServer)(nil), diff --git a/x/tier/types/types.go b/x/tier/types/types.go index 9547b760c..604bfbcaa 100644 --- a/x/tier/types/types.go +++ b/x/tier/types/types.go @@ -18,3 +18,26 @@ func NewPortfolioWithContextDate(date string, creator sdk.AccAddress, value sdkm Portfolio: value, } } + +var ( + Bronze = MembershipTier{ + Discount: sdkmath.LegacyZeroDec(), + Membership: MembershipTierType_BRONZE, + MinimumPortfolio: sdkmath.LegacyZeroDec(), + } + Silver = MembershipTier{ + Discount: sdkmath.LegacyMustNewDecFromStr("0.1"), + Membership: MembershipTierType_SILVER, + MinimumPortfolio: sdkmath.LegacyMustNewDecFromStr("50000"), + } + Gold = MembershipTier{ + Discount: sdkmath.LegacyMustNewDecFromStr("0.2"), + Membership: MembershipTierType_GOLD, + MinimumPortfolio: sdkmath.LegacyMustNewDecFromStr("250000"), + } + Platinum = MembershipTier{ + Discount: sdkmath.LegacyMustNewDecFromStr("0.3"), + Membership: MembershipTierType_PLATINUM, + MinimumPortfolio: sdkmath.LegacyMustNewDecFromStr("500000"), + } +) diff --git a/x/tier/types/userdata.pb.go b/x/tier/types/userdata.pb.go index c4cedb553..f05020aac 100644 --- a/x/tier/types/userdata.pb.go +++ b/x/tier/types/userdata.pb.go @@ -6,6 +6,7 @@ package types import ( cosmossdk_io_math "cosmossdk.io/math" fmt "fmt" + _ "github.com/cosmos/cosmos-proto" _ "github.com/cosmos/gogoproto/gogoproto" proto "github.com/cosmos/gogoproto/proto" io "io" @@ -24,6 +25,37 @@ var _ = math.Inf // proto package needs to be updated. const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package +type MembershipTierType int32 + +const ( + MembershipTierType_BRONZE MembershipTierType = 0 + MembershipTierType_SILVER MembershipTierType = 1 + MembershipTierType_GOLD MembershipTierType = 2 + MembershipTierType_PLATINUM MembershipTierType = 3 +) + +var MembershipTierType_name = map[int32]string{ + 0: "BRONZE", + 1: "SILVER", + 2: "GOLD", + 3: "PLATINUM", +} + +var MembershipTierType_value = map[string]int32{ + "BRONZE": 0, + "SILVER": 1, + "GOLD": 2, + "PLATINUM": 3, +} + +func (x MembershipTierType) String() string { + return proto.EnumName(MembershipTierType_name, int32(x)) +} + +func (MembershipTierType) EnumDescriptor() ([]byte, []int) { + return fileDescriptor_604a2627f200671e, []int{0} +} + type UserData struct { User string `protobuf:"bytes,1,opt,name=user,proto3" json:"user,omitempty"` Pools []*Pool `protobuf:"bytes,2,rep,name=pools,proto3" json:"pools,omitempty"` @@ -137,34 +169,92 @@ func (m *Pool) GetFiatValue() string { return "" } +type MembershipTier struct { + MinimumPortfolio cosmossdk_io_math.LegacyDec `protobuf:"bytes,1,opt,name=minimum_portfolio,json=minimumPortfolio,proto3,customtype=cosmossdk.io/math.LegacyDec" json:"minimum_portfolio"` + Membership MembershipTierType `protobuf:"varint,2,opt,name=membership,proto3,enum=elys.tier.MembershipTierType" json:"membership,omitempty"` + Discount cosmossdk_io_math.LegacyDec `protobuf:"bytes,3,opt,name=discount,proto3,customtype=cosmossdk.io/math.LegacyDec" json:"discount"` +} + +func (m *MembershipTier) Reset() { *m = MembershipTier{} } +func (m *MembershipTier) String() string { return proto.CompactTextString(m) } +func (*MembershipTier) ProtoMessage() {} +func (*MembershipTier) Descriptor() ([]byte, []int) { + return fileDescriptor_604a2627f200671e, []int{2} +} +func (m *MembershipTier) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *MembershipTier) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_MembershipTier.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *MembershipTier) XXX_Merge(src proto.Message) { + xxx_messageInfo_MembershipTier.Merge(m, src) +} +func (m *MembershipTier) XXX_Size() int { + return m.Size() +} +func (m *MembershipTier) XXX_DiscardUnknown() { + xxx_messageInfo_MembershipTier.DiscardUnknown(m) +} + +var xxx_messageInfo_MembershipTier proto.InternalMessageInfo + +func (m *MembershipTier) GetMembership() MembershipTierType { + if m != nil { + return m.Membership + } + return MembershipTierType_BRONZE +} + func init() { + proto.RegisterEnum("elys.tier.MembershipTierType", MembershipTierType_name, MembershipTierType_value) proto.RegisterType((*UserData)(nil), "elys.tier.UserData") proto.RegisterType((*Pool)(nil), "elys.tier.Pool") + proto.RegisterType((*MembershipTier)(nil), "elys.tier.MembershipTier") } func init() { proto.RegisterFile("elys/tier/userdata.proto", fileDescriptor_604a2627f200671e) } var fileDescriptor_604a2627f200671e = []byte{ - // 292 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x3c, 0x90, 0xc1, 0x4a, 0xf3, 0x40, - 0x14, 0x85, 0x33, 0x6d, 0xff, 0xfe, 0x76, 0x5c, 0x08, 0x83, 0xe2, 0x20, 0x74, 0x5a, 0x0a, 0x42, - 0x5d, 0x38, 0x03, 0x8a, 0x2f, 0x50, 0x75, 0xd1, 0x9d, 0x04, 0x74, 0xe1, 0xa6, 0x4c, 0x9b, 0x31, - 0x0d, 0x4d, 0x72, 0x43, 0x66, 0xa2, 0xf6, 0x11, 0xdc, 0xf9, 0x58, 0x5d, 0x76, 0x29, 0x2e, 0x8a, - 0x24, 0x2f, 0x22, 0x37, 0x29, 0xee, 0xce, 0x39, 0xdf, 0x9d, 0x03, 0x73, 0x28, 0x37, 0xf1, 0xda, - 0x2a, 0x17, 0x99, 0x5c, 0x15, 0xd6, 0xe4, 0x81, 0x76, 0x5a, 0x66, 0x39, 0x38, 0x60, 0x3d, 0x24, - 0x12, 0xc9, 0xd9, 0x71, 0x08, 0x21, 0xd4, 0xa9, 0x42, 0xd5, 0x1c, 0x8c, 0xee, 0xe9, 0xc1, 0xa3, - 0x35, 0xf9, 0x9d, 0x76, 0x9a, 0x31, 0xda, 0xc1, 0xe7, 0x9c, 0x0c, 0xc9, 0xb8, 0xe7, 0xd7, 0x9a, - 0x9d, 0xd3, 0x7f, 0x19, 0x40, 0x6c, 0x79, 0x6b, 0xd8, 0x1e, 0x1f, 0x5e, 0x1d, 0xc9, 0xbf, 0x42, - 0xf9, 0x00, 0x10, 0xfb, 0x0d, 0x1d, 0x7d, 0x10, 0xda, 0x41, 0xcf, 0x4e, 0xe9, 0x7f, 0x4c, 0x66, - 0x51, 0xb0, 0xaf, 0xe9, 0xa2, 0x9d, 0x06, 0x58, 0x8e, 0x8a, 0xb7, 0x9a, 0x72, 0xd4, 0xac, 0x4f, - 0xe9, 0x4b, 0xa4, 0xdd, 0xec, 0x55, 0xc7, 0x85, 0xe1, 0xed, 0x9a, 0xf4, 0x30, 0x79, 0xc2, 0x80, - 0xdd, 0xd0, 0xae, 0x4e, 0xa0, 0x48, 0x1d, 0xef, 0x20, 0x9a, 0xf4, 0x37, 0xbb, 0x81, 0xf7, 0xbd, - 0x1b, 0x9c, 0x2c, 0xc0, 0x26, 0x60, 0x6d, 0xb0, 0x92, 0x11, 0xa8, 0x44, 0xbb, 0xa5, 0x9c, 0xa6, - 0xce, 0xdf, 0x1f, 0x4f, 0x6e, 0x37, 0xa5, 0x20, 0xdb, 0x52, 0x90, 0x9f, 0x52, 0x90, 0xcf, 0x4a, - 0x78, 0xdb, 0x4a, 0x78, 0x5f, 0x95, 0xf0, 0x9e, 0x2f, 0xc2, 0xc8, 0x2d, 0x8b, 0xb9, 0x5c, 0x40, - 0xa2, 0xf0, 0x1f, 0x97, 0xa9, 0x71, 0x6f, 0x90, 0xaf, 0x6a, 0xa3, 0xde, 0x9b, 0x05, 0xdd, 0x3a, - 0x33, 0x76, 0xde, 0xad, 0xe7, 0xb9, 0xfe, 0x0d, 0x00, 0x00, 0xff, 0xff, 0xd0, 0x47, 0xf8, 0xba, - 0x5b, 0x01, 0x00, 0x00, + // 460 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x9c, 0x92, 0x41, 0x6b, 0x13, 0x41, + 0x14, 0xc7, 0xb3, 0x49, 0x8c, 0xc9, 0x53, 0xea, 0x3a, 0x28, 0xae, 0x95, 0x6c, 0x4b, 0x40, 0xa8, + 0x42, 0x77, 0xb1, 0xe2, 0xd1, 0x83, 0x71, 0x83, 0x04, 0x92, 0x36, 0xac, 0x69, 0x0f, 0x3d, 0x18, + 0x26, 0xbb, 0xd3, 0x64, 0xe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xb8, 0x9a, 0xe7, 0x53, 0x2f, 0x42, 0xe1, 0xeb, 0x8c, 0xfb, 0x0b, 0xa6, 0x3e, 0x61, 0x76, 0x5e, + 0x14, 0xfe, 0x67, 0xf3, 0x47, 0xd5, 0x32, 0x65, 0x72, 0xda, 0x28, 0x7e, 0xd9, 0xcb, 0x3f, 0x01, + 0x00, 0x00, 0xff, 0xff, 0x13, 0x8f, 0xcb, 0x5d, 0xbd, 0x02, 0x00, 0x00, } func (m *UserData) Marshal() (dAtA []byte, err error) { @@ -265,6 +355,54 @@ func (m *Pool) MarshalToSizedBuffer(dAtA []byte) (int, error) { return len(dAtA) - i, nil } +func (m *MembershipTier) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *MembershipTier) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *MembershipTier) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + { + size := m.Discount.Size() + i -= size + if _, err := m.Discount.MarshalTo(dAtA[i:]); err != nil { + return 0, err + } + i = encodeVarintUserdata(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x1a + if m.Membership != 0 { + i = encodeVarintUserdata(dAtA, i, uint64(m.Membership)) + i-- + dAtA[i] = 0x10 + } + { + size := m.MinimumPortfolio.Size() + i -= size + if _, err := m.MinimumPortfolio.MarshalTo(dAtA[i:]); err != nil { + return 0, err + } + i = encodeVarintUserdata(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0xa + return len(dAtA) - i, nil +} + func encodeVarintUserdata(dAtA []byte, offset int, v uint64) int { offset -= sovUserdata(v) base := offset @@ -318,6 +456,22 @@ func (m *Pool) Size() (n int) { return n } +func (m *MembershipTier) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = m.MinimumPortfolio.Size() + n += 1 + l + sovUserdata(uint64(l)) + if m.Membership != 0 { + n += 1 + sovUserdata(uint64(m.Membership)) + } + l = m.Discount.Size() + n += 1 + l + sovUserdata(uint64(l)) + return n +} + func sovUserdata(x uint64) (n int) { return (math_bits.Len64(x|1) + 6) / 7 } @@ -620,6 +774,143 @@ func (m *Pool) Unmarshal(dAtA []byte) error { } return nil } +func (m *MembershipTier) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowUserdata + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: MembershipTier: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: MembershipTier: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field MinimumPortfolio", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowUserdata + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthUserdata + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthUserdata + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if err := m.MinimumPortfolio.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 2: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field Membership", wireType) + } + m.Membership = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowUserdata + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.Membership |= MembershipTierType(b&0x7F) << shift + if b < 0x80 { + break + } + } + case 3: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Discount", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowUserdata + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthUserdata + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthUserdata + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if err := m.Discount.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipUserdata(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthUserdata + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} func skipUserdata(dAtA []byte) (n int, err error) { l := len(dAtA) iNdEx := 0 diff --git a/x/tokenomics/types/query.pb.go b/x/tokenomics/types/query.pb.go index 90d2fe161..0c048722d 100644 --- a/x/tokenomics/types/query.pb.go +++ b/x/tokenomics/types/query.pb.go @@ -874,7 +874,6 @@ func _Query_TimeBasedInflationAll_Handler(srv interface{}, ctx context.Context, return interceptor(ctx, in, info, handler) } -var Query_serviceDesc = _Query_serviceDesc var _Query_serviceDesc = grpc.ServiceDesc{ ServiceName: "elys.tokenomics.Query", HandlerType: (*QueryServer)(nil), diff --git a/x/tokenomics/types/tx.pb.go b/x/tokenomics/types/tx.pb.go index 441b60fa1..0667a4462 100644 --- a/x/tokenomics/types/tx.pb.go +++ b/x/tokenomics/types/tx.pb.go @@ -1198,7 +1198,6 @@ func _Msg_DeleteTimeBasedInflation_Handler(srv interface{}, ctx context.Context, return interceptor(ctx, in, info, handler) } -var Msg_serviceDesc = _Msg_serviceDesc var _Msg_serviceDesc = grpc.ServiceDesc{ ServiceName: "elys.tokenomics.Msg", HandlerType: (*MsgServer)(nil), diff --git a/x/tradeshield/keeper/keeper.go b/x/tradeshield/keeper/keeper.go index c8f230550..6b944a94e 100644 --- a/x/tradeshield/keeper/keeper.go +++ b/x/tradeshield/keeper/keeper.go @@ -1,9 +1,10 @@ package keeper import ( - "cosmossdk.io/core/store" "fmt" + "cosmossdk.io/core/store" + "cosmossdk.io/log" sdkmath "cosmossdk.io/math" "github.com/cosmos/cosmos-sdk/codec" @@ -53,16 +54,10 @@ func (k Keeper) GetUserDiscount(ctx sdk.Context, address string) (sdkmath.Legacy } // Get discount tier (range from 0 to 100) - _, _, discount := k.tier.GetMembershipTier(ctx, user) - - // Convert uint64 discount to math.LegacyDec - discountDec := sdkmath.LegacyNewDec(int64(discount)) - - // Normalize the discount to be between 0 and 1 - discountDec = discountDec.Quo(sdkmath.LegacyNewDec(100)) + _, tier := k.tier.GetMembershipTier(ctx, user) // Return the discount - return discountDec, nil + return tier.Discount, nil } // GetAssetPriceFromDenomInToDenomOut returns the price of an asset from a denom to another denom diff --git a/x/tradeshield/keeper/pending_spot_order_test.go b/x/tradeshield/keeper/pending_spot_order_test.go index 7cf5b5ef0..1a0036f93 100644 --- a/x/tradeshield/keeper/pending_spot_order_test.go +++ b/x/tradeshield/keeper/pending_spot_order_test.go @@ -14,6 +14,8 @@ import ( "github.com/elys-network/elys/x/tradeshield/types" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" + + tiertypes "github.com/elys-network/elys/x/tier/types" ) func createNPendingSpotOrder(keeper *keeper.Keeper, ctx sdk.Context, n int) []types.SpotOrder { @@ -71,7 +73,7 @@ func TestExecuteStopLossOrder(t *testing.T) { tierKeeper.On("CalculateUSDValue", ctx, "base", sdkmath.NewInt(1)).Return(sdkmath.LegacyNewDec(1)) tierKeeper.On("CalculateUSDValue", ctx, "quote", sdkmath.NewInt(1)).Return(sdkmath.LegacyNewDec(1)) - tierKeeper.On("GetMembershipTier", ctx, address).Return(sdkmath.LegacyNewDec(10), "tier", uint64(10)) + tierKeeper.On("GetMembershipTier", ctx, address).Return(sdkmath.LegacyNewDec(10), tiertypes.Silver) ammKeeper.On("SwapByDenom", ctx, &ammtypes.MsgSwapByDenom{ Sender: address.String(), Amount: sdk.NewCoin("base", sdkmath.NewInt(1)), @@ -118,7 +120,7 @@ func TestExecuteLimitSellOrder(t *testing.T) { tierKeeper.On("CalculateUSDValue", ctx, "base", sdkmath.NewInt(1)).Return(sdkmath.LegacyNewDec(1)) tierKeeper.On("CalculateUSDValue", ctx, "quote", sdkmath.NewInt(1)).Return(sdkmath.LegacyNewDec(1)) - tierKeeper.On("GetMembershipTier", ctx, address).Return(sdkmath.LegacyNewDec(10), "tier", uint64(10)) + tierKeeper.On("GetMembershipTier", ctx, address).Return(sdkmath.LegacyNewDec(10), tiertypes.Silver) ammKeeper.On("SwapByDenom", ctx, &ammtypes.MsgSwapByDenom{ Sender: address.String(), Amount: sdk.NewCoin("base", sdkmath.NewInt(1)), @@ -165,7 +167,7 @@ func TestExecuteLimitBuyOrder(t *testing.T) { tierKeeper.On("CalculateUSDValue", ctx, "base", sdkmath.NewInt(1)).Return(sdkmath.LegacyNewDec(1)) tierKeeper.On("CalculateUSDValue", ctx, "quote", sdkmath.NewInt(1)).Return(sdkmath.LegacyNewDec(1)) - tierKeeper.On("GetMembershipTier", ctx, address).Return(sdkmath.LegacyNewDec(10), "tier", uint64(10)) + tierKeeper.On("GetMembershipTier", ctx, address).Return(sdkmath.LegacyNewDec(10), tiertypes.Silver) ammKeeper.On("SwapByDenom", ctx, &ammtypes.MsgSwapByDenom{ Sender: address.String(), Amount: sdk.NewCoin("base", sdkmath.NewInt(1)), @@ -210,7 +212,7 @@ func TestExecuteMarketBuyOrder(t *testing.T) { address := sdk.AccAddress([]byte("address")) - tierKeeper.On("GetMembershipTier", ctx, address).Return(sdkmath.LegacyNewDec(10), "tier", uint64(10)) + tierKeeper.On("GetMembershipTier", ctx, address).Return(sdkmath.LegacyNewDec(10), tiertypes.Silver) ammKeeper.On("SwapByDenom", ctx, &ammtypes.MsgSwapByDenom{ Sender: address.String(), Amount: sdk.NewCoin("base", sdkmath.NewInt(1)), diff --git a/x/tradeshield/types/expected_keepers.go b/x/tradeshield/types/expected_keepers.go index c29306b74..3f8028a53 100644 --- a/x/tradeshield/types/expected_keepers.go +++ b/x/tradeshield/types/expected_keepers.go @@ -2,11 +2,13 @@ package types import ( "context" + sdkmath "cosmossdk.io/math" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/query" ammtypes "github.com/elys-network/elys/x/amm/types" perpetualtypes "github.com/elys-network/elys/x/perpetual/types" + tiertypes "github.com/elys-network/elys/x/tier/types" ) // AccountKeeper defines the expected account keeper used for simulations (noalias) @@ -32,7 +34,7 @@ type AmmKeeper interface { // //go:generate mockery --srcpkg . --name TierKeeper --structname TierKeeper --filename tier_keeper.go --with-expecter type TierKeeper interface { - GetMembershipTier(ctx sdk.Context, user sdk.AccAddress) (total_portfolio sdkmath.LegacyDec, tier string, discount uint64) + GetMembershipTier(ctx sdk.Context, user sdk.AccAddress) (total_portfolio sdkmath.LegacyDec, tier tiertypes.MembershipTier) CalculateUSDValue(ctx sdk.Context, denom string, amount sdkmath.Int) sdkmath.LegacyDec } diff --git a/x/tradeshield/types/mocks/amm_keeper.go b/x/tradeshield/types/mocks/amm_keeper.go index 46c4e9ca5..c70f299f4 100644 --- a/x/tradeshield/types/mocks/amm_keeper.go +++ b/x/tradeshield/types/mocks/amm_keeper.go @@ -1,4 +1,4 @@ -// Code generated by mockery v2.46.3. DO NOT EDIT. +// Code generated by mockery v2.47.0. DO NOT EDIT. package mocks diff --git a/x/tradeshield/types/mocks/perpetual_keeper.go b/x/tradeshield/types/mocks/perpetual_keeper.go index 0f15e6b8b..01dea78bb 100644 --- a/x/tradeshield/types/mocks/perpetual_keeper.go +++ b/x/tradeshield/types/mocks/perpetual_keeper.go @@ -1,4 +1,4 @@ -// Code generated by mockery v2.46.3. DO NOT EDIT. +// Code generated by mockery v2.47.0. DO NOT EDIT. package mocks diff --git a/x/tradeshield/types/mocks/tier_keeper.go b/x/tradeshield/types/mocks/tier_keeper.go index 45ffa1f2d..96ffb7bce 100644 --- a/x/tradeshield/types/mocks/tier_keeper.go +++ b/x/tradeshield/types/mocks/tier_keeper.go @@ -1,9 +1,10 @@ -// Code generated by mockery v2.46.3. DO NOT EDIT. +// Code generated by mockery v2.47.0. DO NOT EDIT. package mocks import ( math "cosmossdk.io/math" + tiertypes "github.com/elys-network/elys/x/tier/types" mock "github.com/stretchr/testify/mock" types "github.com/cosmos/cosmos-sdk/types" @@ -71,7 +72,7 @@ func (_c *TierKeeper_CalculateUSDValue_Call) RunAndReturn(run func(types.Context } // GetMembershipTier provides a mock function with given fields: ctx, user -func (_m *TierKeeper) GetMembershipTier(ctx types.Context, user types.AccAddress) (math.LegacyDec, string, uint64) { +func (_m *TierKeeper) GetMembershipTier(ctx types.Context, user types.AccAddress) (math.LegacyDec, tiertypes.MembershipTier) { ret := _m.Called(ctx, user) if len(ret) == 0 { @@ -79,9 +80,8 @@ func (_m *TierKeeper) GetMembershipTier(ctx types.Context, user types.AccAddress } var r0 math.LegacyDec - var r1 string - var r2 uint64 - if rf, ok := ret.Get(0).(func(types.Context, types.AccAddress) (math.LegacyDec, string, uint64)); ok { + var r1 tiertypes.MembershipTier + if rf, ok := ret.Get(0).(func(types.Context, types.AccAddress) (math.LegacyDec, tiertypes.MembershipTier)); ok { return rf(ctx, user) } if rf, ok := ret.Get(0).(func(types.Context, types.AccAddress) math.LegacyDec); ok { @@ -90,19 +90,13 @@ func (_m *TierKeeper) GetMembershipTier(ctx types.Context, user types.AccAddress r0 = ret.Get(0).(math.LegacyDec) } - if rf, ok := ret.Get(1).(func(types.Context, types.AccAddress) string); ok { + if rf, ok := ret.Get(1).(func(types.Context, types.AccAddress) tiertypes.MembershipTier); ok { r1 = rf(ctx, user) } else { - r1 = ret.Get(1).(string) + r1 = ret.Get(1).(tiertypes.MembershipTier) } - if rf, ok := ret.Get(2).(func(types.Context, types.AccAddress) uint64); ok { - r2 = rf(ctx, user) - } else { - r2 = ret.Get(2).(uint64) - } - - return r0, r1, r2 + return r0, r1 } // TierKeeper_GetMembershipTier_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'GetMembershipTier' @@ -124,12 +118,12 @@ func (_c *TierKeeper_GetMembershipTier_Call) Run(run func(ctx types.Context, use return _c } -func (_c *TierKeeper_GetMembershipTier_Call) Return(total_portfolio math.LegacyDec, tier string, discount uint64) *TierKeeper_GetMembershipTier_Call { - _c.Call.Return(total_portfolio, tier, discount) +func (_c *TierKeeper_GetMembershipTier_Call) Return(total_portfolio math.LegacyDec, tier tiertypes.MembershipTier) *TierKeeper_GetMembershipTier_Call { + _c.Call.Return(total_portfolio, tier) return _c } -func (_c *TierKeeper_GetMembershipTier_Call) RunAndReturn(run func(types.Context, types.AccAddress) (math.LegacyDec, string, uint64)) *TierKeeper_GetMembershipTier_Call { +func (_c *TierKeeper_GetMembershipTier_Call) RunAndReturn(run func(types.Context, types.AccAddress) (math.LegacyDec, tiertypes.MembershipTier)) *TierKeeper_GetMembershipTier_Call { _c.Call.Return(run) return _c } diff --git a/x/tradeshield/types/query.pb.go b/x/tradeshield/types/query.pb.go index 9ee0bd345..3483d627f 100644 --- a/x/tradeshield/types/query.pb.go +++ b/x/tradeshield/types/query.pb.go @@ -1029,7 +1029,6 @@ func _Query_PendingSpotOrderForAddress_Handler(srv interface{}, ctx context.Cont return interceptor(ctx, in, info, handler) } -var Query_serviceDesc = _Query_serviceDesc var _Query_serviceDesc = grpc.ServiceDesc{ ServiceName: "elys.tradeshield.Query", HandlerType: (*QueryServer)(nil), diff --git a/x/tradeshield/types/tx.pb.go b/x/tradeshield/types/tx.pb.go index 6923b7c76..7f87edf72 100644 --- a/x/tradeshield/types/tx.pb.go +++ b/x/tradeshield/types/tx.pb.go @@ -1632,7 +1632,6 @@ func _Msg_ExecuteOrders_Handler(srv interface{}, ctx context.Context, dec func(i return interceptor(ctx, in, info, handler) } -var Msg_serviceDesc = _Msg_serviceDesc var _Msg_serviceDesc = grpc.ServiceDesc{ ServiceName: "elys.tradeshield.Msg", HandlerType: (*MsgServer)(nil), diff --git a/x/transferhook/keeper/keeper.go b/x/transferhook/keeper/keeper.go index 73940c3b1..1d365727d 100644 --- a/x/transferhook/keeper/keeper.go +++ b/x/transferhook/keeper/keeper.go @@ -15,14 +15,14 @@ type ( Keeper struct { Cdc codec.BinaryCodec storeService store.KVStoreService - ammKeeper ammkeeper.Keeper + ammKeeper *ammkeeper.Keeper } ) func NewKeeper( Cdc codec.BinaryCodec, storeService store.KVStoreService, - ammKeeper ammkeeper.Keeper, + ammKeeper *ammkeeper.Keeper, ) *Keeper { return &Keeper{ diff --git a/x/transferhook/keeper/swap.go b/x/transferhook/keeper/swap.go index ec6071ae8..f814018d0 100644 --- a/x/transferhook/keeper/swap.go +++ b/x/transferhook/keeper/swap.go @@ -64,7 +64,7 @@ func (k Keeper) SwapExactAmountIn(ctx sdk.Context, addr sdk.AccAddress, tokenIn return err } - msgServer := ammkeeper.NewMsgServerImpl(k.ammKeeper) + msgServer := ammkeeper.NewMsgServerImpl(*k.ammKeeper) _, err := msgServer.SwapExactAmountIn(ctx, msg) if err != nil { return errorsmod.Wrapf(sdkerrors.ErrInsufficientFunds, err.Error()) diff --git a/x/transferhook/keeper/swap_test.go b/x/transferhook/keeper/swap_test.go index 33c82c919..b6d09170b 100644 --- a/x/transferhook/keeper/swap_test.go +++ b/x/transferhook/keeper/swap_test.go @@ -1,10 +1,11 @@ package keeper_test import ( - "cosmossdk.io/math" "encoding/json" "fmt" + "cosmossdk.io/math" + "github.com/cometbft/cometbft/crypto/ed25519" "github.com/cosmos/ibc-go/v8/modules/apps/transfer" transfertypes "github.com/cosmos/ibc-go/v8/modules/apps/transfer/types" @@ -199,6 +200,7 @@ func (suite *KeeperTestSuite) TestSwapOnRecvPacket() { suite.app.TransferhookKeeper.SetParams(suite.ctx, types.Params{ AmmActive: tc.forwardingActive, }) + // bootstrap accounts poolAddr := ammtypes.NewPoolAddress(uint64(1)) treasuryAddr := sdk.AccAddress(ed25519.GenPrivKey().PubKey().Address()) diff --git a/x/transferhook/types/query.pb.go b/x/transferhook/types/query.pb.go index f15e496a5..38afb9ad9 100644 --- a/x/transferhook/types/query.pb.go +++ b/x/transferhook/types/query.pb.go @@ -210,7 +210,6 @@ func _Query_Params_Handler(srv interface{}, ctx context.Context, dec func(interf return interceptor(ctx, in, info, handler) } -var Query_serviceDesc = _Query_serviceDesc var _Query_serviceDesc = grpc.ServiceDesc{ ServiceName: "elys.transferhook.Query", HandlerType: (*QueryServer)(nil),