From 37f03b4319a35e939a5c498b626f86554f941b59 Mon Sep 17 00:00:00 2001 From: Roman Date: Fri, 12 Aug 2022 20:42:52 -0400 Subject: [PATCH 1/4] refactor: clean up keeper interfaces --- app/keepers/keepers.go | 1 - x/gamm/keeper/keeper.go | 6 +-- x/gamm/types/expected_keepers.go | 26 ++----------- x/incentives/keeper/keeper.go | 6 +-- x/incentives/types/expected_keepers.go | 8 +--- x/lockup/keeper/keeper.go | 6 +-- x/lockup/types/expected_keepers.go | 6 +-- x/mint/keeper/keeper.go | 42 ++++++++++----------- x/mint/types/expected_keepers.go | 4 +- x/pool-incentives/types/expected_keepers.go | 5 --- x/superfluid/keeper/epoch.go | 2 +- x/superfluid/keeper/keeper.go | 6 +-- x/superfluid/types/expected_keepers.go | 11 +----- x/tokenfactory/types/expected_keepers.go | 4 -- x/txfees/keeper/feedecorator.go | 2 +- x/txfees/keeper/keeper.go | 3 -- x/txfees/types/expected_keepers.go | 17 --------- 17 files changed, 45 insertions(+), 110 deletions(-) diff --git a/app/keepers/keepers.go b/app/keepers/keepers.go index a96c05d23fa..e3a8d0fd4dd 100644 --- a/app/keepers/keepers.go +++ b/app/keepers/keepers.go @@ -264,7 +264,6 @@ func (appKeepers *AppKeepers) InitNormalKeepers( appCodec, appKeepers.AccountKeeper, appKeepers.BankKeeper, - appKeepers.EpochsKeeper, appKeepers.keys[txfeestypes.StoreKey], appKeepers.GAMMKeeper, appKeepers.GAMMKeeper, diff --git a/x/gamm/keeper/keeper.go b/x/gamm/keeper/keeper.go index 06575aa1707..abc0371a6c8 100644 --- a/x/gamm/keeper/keeper.go +++ b/x/gamm/keeper/keeper.go @@ -31,10 +31,10 @@ type Keeper struct { // keepers accountKeeper types.AccountKeeper bankKeeper types.BankKeeper - distrKeeper types.DistrKeeper + distrKeeper types.CommunityPoolKeeper } -func NewKeeper(cdc codec.BinaryCodec, storeKey sdk.StoreKey, paramSpace paramtypes.Subspace, accountKeeper types.AccountKeeper, bankKeeper types.BankKeeper, distrKeeper types.DistrKeeper) Keeper { +func NewKeeper(cdc codec.BinaryCodec, storeKey sdk.StoreKey, paramSpace paramtypes.Subspace, accountKeeper types.AccountKeeper, bankKeeper types.BankKeeper, communityPoolKeeper types.CommunityPoolKeeper) Keeper { // Ensure that the module account are set. moduleAddr, perms := accountKeeper.GetModuleAddressAndPermissions(types.ModuleName) if moduleAddr == nil { @@ -56,7 +56,7 @@ func NewKeeper(cdc codec.BinaryCodec, storeKey sdk.StoreKey, paramSpace paramtyp // keepers accountKeeper: accountKeeper, bankKeeper: bankKeeper, - distrKeeper: distrKeeper, + distrKeeper: communityPoolKeeper, } } diff --git a/x/gamm/types/expected_keepers.go b/x/gamm/types/expected_keepers.go index e69a5da4c9f..14cfd72fdf5 100644 --- a/x/gamm/types/expected_keepers.go +++ b/x/gamm/types/expected_keepers.go @@ -10,30 +10,18 @@ import ( // creating a x/gamm keeper. type AccountKeeper interface { NewAccount(sdk.Context, authtypes.AccountI) authtypes.AccountI - NewAccountWithAddress(ctx sdk.Context, addr sdk.AccAddress) authtypes.AccountI GetAccount(ctx sdk.Context, addr sdk.AccAddress) authtypes.AccountI - GetAllAccounts(ctx sdk.Context) []authtypes.AccountI SetAccount(ctx sdk.Context, acc authtypes.AccountI) - IterateAccounts(ctx sdk.Context, process func(authtypes.AccountI) bool) - - ValidatePermissions(macc authtypes.ModuleAccountI) error - - GetModuleAddress(moduleName string) sdk.AccAddress GetModuleAddressAndPermissions(moduleName string) (addr sdk.AccAddress, permissions []string) - GetModuleAccountAndPermissions(ctx sdk.Context, moduleName string) (authtypes.ModuleAccountI, []string) - GetModuleAccount(ctx sdk.Context, moduleName string) authtypes.ModuleAccountI - SetModuleAccount(ctx sdk.Context, macc authtypes.ModuleAccountI) - - UnmarshalAccount(bz []byte) (authtypes.AccountI, error) } // BankKeeper defines the banking contract that must be fulfilled when // creating a x/gamm keeper. type BankKeeper interface { SendCoinsFromModuleToAccount(ctx sdk.Context, senderModule string, recipientAddr sdk.AccAddress, amt sdk.Coins) error - SendCoinsFromModuleToModule(ctx sdk.Context, senderPool, recipientPool string, amt sdk.Coins) error + SendCoinsFromAccountToModule(ctx sdk.Context, senderAddr sdk.AccAddress, recipientModule string, amt sdk.Coins) error SendCoins(ctx sdk.Context, fromAddr sdk.AccAddress, toAddr sdk.AccAddress, amt sdk.Coins) error @@ -47,17 +35,9 @@ type BankKeeper interface { // TODO: Look into golang syntax to make this "Everything in stakingtypes.bankkeeper + extra funcs" // I think it has to do with listing another interface as the first line here? GetAllBalances(ctx sdk.Context, addr sdk.AccAddress) sdk.Coins - GetBalance(ctx sdk.Context, addr sdk.AccAddress, denom string) sdk.Coin - // SetBalances(ctx sdk.Context, addr sdk.AccAddress, balances sdk.Coins) error - LockedCoins(ctx sdk.Context, addr sdk.AccAddress) sdk.Coins - SpendableCoins(ctx sdk.Context, addr sdk.AccAddress) sdk.Coins - GetSupply(ctx sdk.Context, denom string) sdk.Coin - UndelegateCoinsFromModuleToAccount(ctx sdk.Context, senderModule string, recipientAddr sdk.AccAddress, amt sdk.Coins) error - DelegateCoinsFromAccountToModule(ctx sdk.Context, senderAddr sdk.AccAddress, recipientModule string, amt sdk.Coins) error - IterateAllBalances(ctx sdk.Context, callback func(addr sdk.AccAddress, coin sdk.Coin) (stop bool)) } -// DistrKeeper defines the contract needed to be fulfilled for distribution keeper. -type DistrKeeper interface { +// CommunityPoolKeeper defines the contract needed to be fulfilled for distribution keeper. +type CommunityPoolKeeper interface { FundCommunityPool(ctx sdk.Context, amount sdk.Coins, sender sdk.AccAddress) error } diff --git a/x/incentives/keeper/keeper.go b/x/incentives/keeper/keeper.go index 37cbfb3397f..c97205227f2 100644 --- a/x/incentives/keeper/keeper.go +++ b/x/incentives/keeper/keeper.go @@ -22,12 +22,12 @@ type Keeper struct { bk types.BankKeeper lk types.LockupKeeper ek types.EpochKeeper - dk types.DistrKeeper + dk types.CommunityPoolKeeper tk types.TxFeesKeeper } // NewKeeper returns a new instance of the incentive module keeper struct. -func NewKeeper(cdc codec.Codec, storeKey sdk.StoreKey, paramSpace paramtypes.Subspace, bk types.BankKeeper, lk types.LockupKeeper, ek types.EpochKeeper, dk types.DistrKeeper, txfk types.TxFeesKeeper) *Keeper { +func NewKeeper(cdc codec.Codec, storeKey sdk.StoreKey, paramSpace paramtypes.Subspace, bk types.BankKeeper, lk types.LockupKeeper, ek types.EpochKeeper, ck types.CommunityPoolKeeper, txfk types.TxFeesKeeper) *Keeper { if !paramSpace.HasKeyTable() { paramSpace = paramSpace.WithKeyTable(types.ParamKeyTable()) } @@ -39,7 +39,7 @@ func NewKeeper(cdc codec.Codec, storeKey sdk.StoreKey, paramSpace paramtypes.Sub bk: bk, lk: lk, ek: ek, - dk: dk, + dk: ck, tk: txfk, } } diff --git a/x/incentives/types/expected_keepers.go b/x/incentives/types/expected_keepers.go index c0c04916feb..a64b6eba515 100644 --- a/x/incentives/types/expected_keepers.go +++ b/x/incentives/types/expected_keepers.go @@ -11,12 +11,10 @@ import ( // BankKeeper defines the expected interface needed to retrieve account balances. type BankKeeper interface { - GetAllBalances(ctx sdk.Context, addr sdk.AccAddress) sdk.Coins GetBalance(ctx sdk.Context, addr sdk.AccAddress, denom string) sdk.Coin HasSupply(ctx sdk.Context, denom string) bool - SendCoinsFromModuleToAccount(ctx sdk.Context, senderModule string, recipientAddr sdk.AccAddress, amt sdk.Coins) error SendCoinsFromModuleToManyAccounts( ctx sdk.Context, senderModule string, recipientAddrs []sdk.AccAddress, amts []sdk.Coins, ) error @@ -25,8 +23,6 @@ type BankKeeper interface { // LockupKeeper defines the expected interface needed to retrieve locks. type LockupKeeper interface { - GetSyntheticLockup(ctx sdk.Context, lockID uint64, suffix string) (*lockuptypes.SyntheticLock, error) - GetLocksPastTimeDenom(ctx sdk.Context, denom string, timestamp time.Time) []lockuptypes.PeriodLock GetLocksLongerThanDurationDenom(ctx sdk.Context, denom string, duration time.Duration) []lockuptypes.PeriodLock GetPeriodLocksAccumulation(ctx sdk.Context, query lockuptypes.QueryCondition) sdk.Int GetAccountPeriodLocks(ctx sdk.Context, addr sdk.AccAddress) []lockuptypes.PeriodLock @@ -38,8 +34,8 @@ type EpochKeeper interface { GetEpochInfo(ctx sdk.Context, identifier string) epochstypes.EpochInfo } -// DistrKeeper defines the contract needed to be fulfilled for distribution keeper. -type DistrKeeper interface { +// CommunityPoolKeeper defines the contract needed to be fulfilled for distribution keeper. +type CommunityPoolKeeper interface { FundCommunityPool(ctx sdk.Context, amount sdk.Coins, sender sdk.AccAddress) error } diff --git a/x/lockup/keeper/keeper.go b/x/lockup/keeper/keeper.go index c411ec9903a..ff1a3147293 100644 --- a/x/lockup/keeper/keeper.go +++ b/x/lockup/keeper/keeper.go @@ -19,16 +19,16 @@ type Keeper struct { ak types.AccountKeeper bk types.BankKeeper - dk types.DistrKeeper + dk types.CommunityPoolKeeper } // NewKeeper returns an instance of Keeper. -func NewKeeper(cdc codec.Codec, storeKey sdk.StoreKey, ak types.AccountKeeper, bk types.BankKeeper, dk types.DistrKeeper) *Keeper { +func NewKeeper(cdc codec.Codec, storeKey sdk.StoreKey, ak types.AccountKeeper, bk types.BankKeeper, ck types.CommunityPoolKeeper) *Keeper { return &Keeper{ storeKey: storeKey, ak: ak, bk: bk, - dk: dk, + dk: ck, } } diff --git a/x/lockup/types/expected_keepers.go b/x/lockup/types/expected_keepers.go index 4a2e7532a43..1603530ed22 100644 --- a/x/lockup/types/expected_keepers.go +++ b/x/lockup/types/expected_keepers.go @@ -14,15 +14,11 @@ type AccountKeeper interface { // BankKeeper defines the expected interface needed to retrieve account balances. type BankKeeper interface { GetAllBalances(ctx sdk.Context, addr sdk.AccAddress) sdk.Coins - GetBalance(ctx sdk.Context, addr sdk.AccAddress, denom string) sdk.Coin - LockedCoins(ctx sdk.Context, addr sdk.AccAddress) sdk.Coins - SpendableCoins(ctx sdk.Context, addr sdk.AccAddress) sdk.Coins SendCoinsFromModuleToAccount(ctx sdk.Context, senderModule string, recipientAddr sdk.AccAddress, amt sdk.Coins) error SendCoinsFromAccountToModule(ctx sdk.Context, senderAddr sdk.AccAddress, recipientModule string, amt sdk.Coins) error - BurnCoins(ctx sdk.Context, name string, amt sdk.Coins) error } -type DistrKeeper interface { +type CommunityPoolKeeper interface { FundCommunityPool(ctx sdk.Context, amount sdk.Coins, sender sdk.AccAddress) error } diff --git a/x/mint/keeper/keeper.go b/x/mint/keeper/keeper.go index c407e328341..b4d8423b0eb 100644 --- a/x/mint/keeper/keeper.go +++ b/x/mint/keeper/keeper.go @@ -17,15 +17,15 @@ import ( // Keeper of the mint store. type Keeper struct { - cdc codec.BinaryCodec - storeKey sdk.StoreKey - paramSpace paramtypes.Subspace - accountKeeper types.AccountKeeper - bankKeeper types.BankKeeper - distrKeeper types.DistrKeeper - epochKeeper types.EpochKeeper - hooks types.MintHooks - feeCollectorName string + cdc codec.BinaryCodec + storeKey sdk.StoreKey + paramSpace paramtypes.Subspace + accountKeeper types.AccountKeeper + bankKeeper types.BankKeeper + communityPoolKeeper types.CommunityPoolKeeper + epochKeeper types.EpochKeeper + hooks types.MintHooks + feeCollectorName string } type invalidRatioError struct { @@ -50,7 +50,7 @@ const emptyWeightedAddressReceiver = "" // NewKeeper creates a new mint Keeper instance. func NewKeeper( cdc codec.BinaryCodec, key sdk.StoreKey, paramSpace paramtypes.Subspace, - ak types.AccountKeeper, bk types.BankKeeper, dk types.DistrKeeper, epochKeeper types.EpochKeeper, + ak types.AccountKeeper, bk types.BankKeeper, dk types.CommunityPoolKeeper, epochKeeper types.EpochKeeper, feeCollectorName string, ) Keeper { // ensure mint module account is set @@ -64,14 +64,14 @@ func NewKeeper( } return Keeper{ - cdc: cdc, - storeKey: key, - paramSpace: paramSpace, - accountKeeper: ak, - bankKeeper: bk, - distrKeeper: dk, - epochKeeper: epochKeeper, - feeCollectorName: feeCollectorName, + cdc: cdc, + storeKey: key, + paramSpace: paramSpace, + accountKeeper: ak, + bankKeeper: bk, + communityPoolKeeper: dk, + epochKeeper: epochKeeper, + feeCollectorName: feeCollectorName, } } @@ -223,7 +223,7 @@ func (k Keeper) DistributeMintedCoin(ctx sdk.Context, mintedCoin sdk.Coin) error // subtract from original provision to ensure no coins left over after the allocations communityPoolAmount := mintedCoin.Amount.Sub(stakingIncentivesAmount).Sub(poolIncentivesAmount).Sub(devRewardAmount) - err = k.distrKeeper.FundCommunityPool(ctx, sdk.NewCoins(sdk.NewCoin(params.MintDenom, communityPoolAmount)), k.accountKeeper.GetModuleAddress(types.ModuleName)) + err = k.communityPoolKeeper.FundCommunityPool(ctx, sdk.NewCoins(sdk.NewCoin(params.MintDenom, communityPoolAmount)), k.accountKeeper.GetModuleAddress(types.ModuleName)) if err != nil { return err } @@ -287,7 +287,7 @@ func (k Keeper) distributeDeveloperRewards(ctx sdk.Context, totalMintedCoin sdk. // If no developer rewards receivers provided, fund the community pool from // the developer vesting module account. if len(developerRewardsReceivers) == 0 { - err = k.distrKeeper.FundCommunityPool(ctx, devRewardCoins, developerRewardsModuleAccountAddress) + err = k.communityPoolKeeper.FundCommunityPool(ctx, devRewardCoins, developerRewardsModuleAccountAddress) if err != nil { return sdk.Int{}, err } @@ -301,7 +301,7 @@ func (k Keeper) distributeDeveloperRewards(ctx sdk.Context, totalMintedCoin sdk. devRewardPortionCoins := sdk.NewCoins(devPortionCoin) // fund community pool when rewards address is empty. if w.Address == emptyWeightedAddressReceiver { - err := k.distrKeeper.FundCommunityPool(ctx, devRewardPortionCoins, + err := k.communityPoolKeeper.FundCommunityPool(ctx, devRewardPortionCoins, k.accountKeeper.GetModuleAddress(types.DeveloperVestingModuleAcctName)) if err != nil { return sdk.Int{}, err diff --git a/x/mint/types/expected_keepers.go b/x/mint/types/expected_keepers.go index 4db66e45456..b826a62885a 100644 --- a/x/mint/types/expected_keepers.go +++ b/x/mint/types/expected_keepers.go @@ -27,8 +27,8 @@ type BankKeeper interface { AddSupplyOffset(ctx sdk.Context, denom string, offsetAmount sdk.Int) } -// DistrKeeper defines the contract needed to be fulfilled for distribution keeper. -type DistrKeeper interface { +// CommunityPoolKeeper defines the contract needed to be fulfilled for distribution keeper. +type CommunityPoolKeeper interface { FundCommunityPool(ctx sdk.Context, amount sdk.Coins, sender sdk.AccAddress) error } diff --git a/x/pool-incentives/types/expected_keepers.go b/x/pool-incentives/types/expected_keepers.go index 23210ed201c..920f1807a76 100644 --- a/x/pool-incentives/types/expected_keepers.go +++ b/x/pool-incentives/types/expected_keepers.go @@ -14,8 +14,6 @@ import ( // AccountKeeper interface contains functions for getting accounts and the module address type AccountKeeper interface { - GetAccount(ctx sdk.Context, addr sdk.AccAddress) authtypes.AccountI - GetModuleAddress(name string) sdk.AccAddress GetModuleAccount(ctx sdk.Context, name string) authtypes.ModuleAccountI } @@ -23,8 +21,6 @@ type AccountKeeper interface { // BankKeeper sends tokens across modules and is able to get account balances. type BankKeeper interface { GetBalance(ctx sdk.Context, addr sdk.AccAddress, denom string) sdk.Coin - - SendCoinsFromModuleToModule(ctx sdk.Context, senderModule string, recipientModule string, amt sdk.Coins) error } // GAMMKeeper gets the pool interface from poolID. @@ -43,7 +39,6 @@ type IncentivesKeeper interface { // DistrKeeper handles pool-fees functionality - setting / getting fees and funding the community pool. type DistrKeeper interface { - GetFeePool(ctx sdk.Context) (feePool distrtypes.FeePool) SetFeePool(ctx sdk.Context, feePool distrtypes.FeePool) FundCommunityPool(ctx sdk.Context, amount sdk.Coins, sender sdk.AccAddress) error } diff --git a/x/superfluid/keeper/epoch.go b/x/superfluid/keeper/epoch.go index 47e7023c76f..de7bf1f33b1 100644 --- a/x/superfluid/keeper/epoch.go +++ b/x/superfluid/keeper/epoch.go @@ -62,7 +62,7 @@ func (k Keeper) MoveSuperfluidDelegationRewardToGauges(ctx sdk.Context) { // To avoid unexpected issues on WithdrawDelegationRewards and AddToGaugeRewards // we use cacheCtx and apply the changes later _ = osmoutils.ApplyFuncIfNoError(ctx, func(cacheCtx sdk.Context) error { - _, err := k.dk.WithdrawDelegationRewards(cacheCtx, addr, valAddr) + _, err := k.ck.WithdrawDelegationRewards(cacheCtx, addr, valAddr) if errors.Is(err, distributiontypes.ErrEmptyDelegationDistInfo) { ctx.Logger().Debug("no swaps occurred in this pool between last epoch and this epoch") return nil diff --git a/x/superfluid/keeper/keeper.go b/x/superfluid/keeper/keeper.go index a54027fd148..4d5e6b99955 100644 --- a/x/superfluid/keeper/keeper.go +++ b/x/superfluid/keeper/keeper.go @@ -23,7 +23,7 @@ type Keeper struct { ak authkeeper.AccountKeeper bk types.BankKeeper sk types.StakingKeeper - dk types.DistrKeeper + ck types.CommunityPoolKeeper ek types.EpochKeeper lk types.LockupKeeper gk types.GammKeeper @@ -35,7 +35,7 @@ type Keeper struct { var _ govtypes.StakingKeeper = (*Keeper)(nil) // NewKeeper returns an instance of Keeper. -func NewKeeper(cdc codec.Codec, storeKey sdk.StoreKey, paramSpace paramtypes.Subspace, ak authkeeper.AccountKeeper, bk types.BankKeeper, sk types.StakingKeeper, dk types.DistrKeeper, ek types.EpochKeeper, lk types.LockupKeeper, gk types.GammKeeper, ik types.IncentivesKeeper, lms types.LockupMsgServer) *Keeper { +func NewKeeper(cdc codec.Codec, storeKey sdk.StoreKey, paramSpace paramtypes.Subspace, ak authkeeper.AccountKeeper, bk types.BankKeeper, sk types.StakingKeeper, dk types.CommunityPoolKeeper, ek types.EpochKeeper, lk types.LockupKeeper, gk types.GammKeeper, ik types.IncentivesKeeper, lms types.LockupMsgServer) *Keeper { // set KeyTable if it has not already been set if !paramSpace.HasKeyTable() { paramSpace = paramSpace.WithKeyTable(types.ParamKeyTable()) @@ -48,7 +48,7 @@ func NewKeeper(cdc codec.Codec, storeKey sdk.StoreKey, paramSpace paramtypes.Sub ak: ak, bk: bk, sk: sk, - dk: dk, + ck: dk, ek: ek, lk: lk, gk: gk, diff --git a/x/superfluid/types/expected_keepers.go b/x/superfluid/types/expected_keepers.go index 5f919d5a295..a35aa2c9cd3 100644 --- a/x/superfluid/types/expected_keepers.go +++ b/x/superfluid/types/expected_keepers.go @@ -15,7 +15,6 @@ import ( // LockupKeeper defines the expected interface needed to retrieve locks. type LockupKeeper interface { - GetLocksPastTimeDenom(ctx sdk.Context, denom string, timestamp time.Time) []lockuptypes.PeriodLock GetLocksLongerThanDurationDenom(ctx sdk.Context, denom string, duration time.Duration) []lockuptypes.PeriodLock GetAccountLockedLongerDurationDenom(ctx sdk.Context, addr sdk.AccAddress, denom string, duration time.Duration) []lockuptypes.PeriodLock GetAccountLockedLongerDurationDenomNotUnlockingOnly(ctx sdk.Context, addr sdk.AccAddress, denom string, duration time.Duration) []lockuptypes.PeriodLock @@ -45,7 +44,6 @@ type LockupMsgServer interface { // GammKeeper defines the expected interface needed for superfluid module. type GammKeeper interface { - CalculateSpotPrice(ctx sdk.Context, poolId uint64, tokenInDenom, tokenOutDenom string) (sdk.Dec, error) GetPoolAndPoke(ctx sdk.Context, poolId uint64) (gammtypes.PoolI, error) GetPoolsAndPoke(ctx sdk.Context) (res []gammtypes.PoolI, err error) ExitPool(ctx sdk.Context, sender sdk.AccAddress, poolId uint64, shareInAmount sdk.Int, tokenOutMins sdk.Coins) (exitCoins sdk.Coins, err error) @@ -55,9 +53,7 @@ type BankKeeper interface { GetBalance(ctx sdk.Context, addr sdk.AccAddress, denom string) sdk.Coin MintCoins(ctx sdk.Context, moduleName string, amt sdk.Coins) error BurnCoins(ctx sdk.Context, moduleName string, amounts sdk.Coins) error - GetSupplyOffset(ctx sdk.Context, denom string) sdk.Int AddSupplyOffset(ctx sdk.Context, denom string, offsetAmount sdk.Int) - GetSupplyWithOffset(ctx sdk.Context, denom string) sdk.Coin SendCoinsFromAccountToModule(ctx sdk.Context, senderAddr sdk.AccAddress, recipientModule string, amt sdk.Coins) error SendCoinsFromModuleToAccount(ctx sdk.Context, senderModule string, recipientAddr sdk.AccAddress, amt sdk.Coins) error } @@ -69,11 +65,8 @@ type StakingKeeper interface { GetValidator(ctx sdk.Context, addr sdk.ValAddress) (validator stakingtypes.Validator, found bool) ValidateUnbondAmount(ctx sdk.Context, delAddr sdk.AccAddress, valAddr sdk.ValAddress, amt sdk.Int) (shares sdk.Dec, err error) Delegate(ctx sdk.Context, delAddr sdk.AccAddress, bondAmt sdk.Int, tokenSrc stakingtypes.BondStatus, validator stakingtypes.Validator, subtractAccount bool) (newShares sdk.Dec, err error) - Unbond(ctx sdk.Context, delAddr sdk.AccAddress, valAddr sdk.ValAddress, shares sdk.Dec) (amount sdk.Int, err error) - Undelegate(ctx sdk.Context, delAddr sdk.AccAddress, valAddr sdk.ValAddress, sharesAmount sdk.Dec) (time.Time, error) InstantUndelegate(ctx sdk.Context, delAddr sdk.AccAddress, valAddr sdk.ValAddress, sharesAmount sdk.Dec) (sdk.Coins, error) GetDelegation(ctx sdk.Context, delAddr sdk.AccAddress, valAddr sdk.ValAddress) (delegation stakingtypes.Delegation, found bool) - GetUnbondingDelegation(ctx sdk.Context, delAddr sdk.AccAddress, valAddr sdk.ValAddress) (ubd stakingtypes.UnbondingDelegation, found bool) UnbondingTime(ctx sdk.Context) time.Duration GetParams(ctx sdk.Context) stakingtypes.Params @@ -82,8 +75,8 @@ type StakingKeeper interface { IterateDelegations(ctx sdk.Context, delegator sdk.AccAddress, fn func(int64, stakingtypes.DelegationI) bool) } -// DistrKeeper expected distribution keeper. -type DistrKeeper interface { +// CommunityPoolKeeper expected distribution keeper. +type CommunityPoolKeeper interface { WithdrawDelegationRewards(ctx sdk.Context, delAddr sdk.AccAddress, valAddr sdk.ValAddress) (sdk.Coins, error) } diff --git a/x/tokenfactory/types/expected_keepers.go b/x/tokenfactory/types/expected_keepers.go index c76cabded5b..e1f8561b98e 100644 --- a/x/tokenfactory/types/expected_keepers.go +++ b/x/tokenfactory/types/expected_keepers.go @@ -15,8 +15,6 @@ type BankKeeper interface { SendCoinsFromModuleToAccount(ctx sdk.Context, senderModule string, recipientAddr sdk.AccAddress, amt sdk.Coins) error SendCoinsFromAccountToModule(ctx sdk.Context, senderAddr sdk.AccAddress, recipientModule string, amt sdk.Coins) error - DelegateCoinsFromAccountToModule(ctx sdk.Context, senderAddr sdk.AccAddress, recipientModule string, amt sdk.Coins) error - UndelegateCoinsFromModuleToAccount(ctx sdk.Context, senderModule string, recipientAddr sdk.AccAddress, amt sdk.Coins) error MintCoins(ctx sdk.Context, moduleName string, amt sdk.Coins) error BurnCoins(ctx sdk.Context, moduleName string, amt sdk.Coins) error @@ -24,9 +22,7 @@ type BankKeeper interface { } type AccountKeeper interface { - GetModuleAddress(name string) sdk.AccAddress SetModuleAccount(ctx sdk.Context, macc authtypes.ModuleAccountI) - GetAccount(sdk.Context, sdk.AccAddress) authtypes.AccountI } // CommunityPoolKeeper defines the contract needed to be fulfilled for community pool interactions. diff --git a/x/txfees/keeper/feedecorator.go b/x/txfees/keeper/feedecorator.go index caa93cfee9a..1c9b6d8cf38 100644 --- a/x/txfees/keeper/feedecorator.go +++ b/x/txfees/keeper/feedecorator.go @@ -210,7 +210,7 @@ func (dfd DeductFeeDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simulate bo } // DeductFees deducts fees from the given account and transfers them to the set module account. -func DeductFees(txFeesKeeper types.TxFeesKeeper, bankKeeper types.BankKeeper, ctx sdk.Context, acc authtypes.AccountI, fees sdk.Coins) error { +func DeductFees(txFeesKeeper Keeper, bankKeeper types.BankKeeper, ctx sdk.Context, acc authtypes.AccountI, fees sdk.Coins) error { // Checks the validity of the fee tokens (sorted, have positive amount, valid and unique denomination) if !fees.IsValid() { return sdkerrors.Wrapf(sdkerrors.ErrInsufficientFee, "invalid fee amount: %s", fees) diff --git a/x/txfees/keeper/keeper.go b/x/txfees/keeper/keeper.go index 54619e2d988..fc4e572d8da 100644 --- a/x/txfees/keeper/keeper.go +++ b/x/txfees/keeper/keeper.go @@ -17,7 +17,6 @@ type Keeper struct { accountKeeper types.AccountKeeper bankKeeper types.BankKeeper - epochKeeper types.EpochKeeper gammKeeper types.GammKeeper spotPriceCalculator types.SpotPriceCalculator feeCollectorName string @@ -28,7 +27,6 @@ func NewKeeper( cdc codec.Codec, accountKeeper types.AccountKeeper, bankKeeper types.BankKeeper, - epochKeeper types.EpochKeeper, storeKey sdk.StoreKey, gammKeeper types.GammKeeper, spotPriceCalculator types.SpotPriceCalculator, @@ -38,7 +36,6 @@ func NewKeeper( return Keeper{ accountKeeper: accountKeeper, bankKeeper: bankKeeper, - epochKeeper: epochKeeper, storeKey: storeKey, gammKeeper: gammKeeper, spotPriceCalculator: spotPriceCalculator, diff --git a/x/txfees/types/expected_keepers.go b/x/txfees/types/expected_keepers.go index 9e2ae585cd8..9ed89ee37dc 100644 --- a/x/txfees/types/expected_keepers.go +++ b/x/txfees/types/expected_keepers.go @@ -3,8 +3,6 @@ package types import ( sdk "github.com/cosmos/cosmos-sdk/types" authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" - - epochstypes "github.com/osmosis-labs/osmosis/v10/x/epochs/types" ) // SpotPriceCalculator defines the contract that must be fulfilled by a spot price calculator @@ -28,9 +26,7 @@ type GammKeeper interface { // AccountKeeper defines the contract needed for AccountKeeper related APIs. // Interface provides support to use non-sdk AccountKeeper for AnteHandler's decorators. type AccountKeeper interface { - GetParams(ctx sdk.Context) (params authtypes.Params) GetAccount(ctx sdk.Context, addr sdk.AccAddress) authtypes.AccountI - SetAccount(ctx sdk.Context, acc authtypes.AccountI) GetModuleAddress(moduleName string) sdk.AccAddress } @@ -42,19 +38,6 @@ type FeegrantKeeper interface { // BankKeeper defines the contract needed for supply related APIs (noalias) type BankKeeper interface { SendCoinsFromAccountToModule(ctx sdk.Context, senderAddr sdk.AccAddress, recipientModule string, amt sdk.Coins) error - GetAllBalances(ctx sdk.Context, addr sdk.AccAddress) sdk.Coins GetBalance(ctx sdk.Context, addr sdk.AccAddress, denom string) sdk.Coin SendCoinsFromModuleToModule(ctx sdk.Context, senderModule, recipientModule string, amt sdk.Coins) error } - -// TxFeesKeeper defines the expected transaction fee keeper -type TxFeesKeeper interface { - ConvertToBaseToken(ctx sdk.Context, inputFee sdk.Coin) (sdk.Coin, error) - GetBaseDenom(ctx sdk.Context) (denom string, err error) - GetFeeToken(ctx sdk.Context, denom string) (FeeToken, error) -} - -// EpochKeeper defines the contract needed to be fulfilled for epochs keeper -type EpochKeeper interface { - GetEpochInfo(ctx sdk.Context, identifier string) epochstypes.EpochInfo -} From 8a0c85bca21c013ccedf2748b2e1bc0755136767 Mon Sep 17 00:00:00 2001 From: Roman Date: Fri, 12 Aug 2022 20:48:51 -0400 Subject: [PATCH 2/4] rename community pool keeper --- x/gamm/keeper/keeper.go | 12 ++++++------ x/gamm/keeper/pool_service.go | 2 +- x/incentives/keeper/gauge.go | 2 +- x/incentives/keeper/keeper.go | 4 ++-- x/lockup/keeper/keeper.go | 4 ++-- x/lockup/keeper/lock.go | 2 +- x/mint/keeper/keeper.go | 4 ++-- 7 files changed, 15 insertions(+), 15 deletions(-) diff --git a/x/gamm/keeper/keeper.go b/x/gamm/keeper/keeper.go index abc0371a6c8..91e8df6c99e 100644 --- a/x/gamm/keeper/keeper.go +++ b/x/gamm/keeper/keeper.go @@ -29,9 +29,9 @@ type Keeper struct { hooks types.GammHooks // keepers - accountKeeper types.AccountKeeper - bankKeeper types.BankKeeper - distrKeeper types.CommunityPoolKeeper + accountKeeper types.AccountKeeper + bankKeeper types.BankKeeper + communityPoolKeeper types.CommunityPoolKeeper } func NewKeeper(cdc codec.BinaryCodec, storeKey sdk.StoreKey, paramSpace paramtypes.Subspace, accountKeeper types.AccountKeeper, bankKeeper types.BankKeeper, communityPoolKeeper types.CommunityPoolKeeper) Keeper { @@ -54,9 +54,9 @@ func NewKeeper(cdc codec.BinaryCodec, storeKey sdk.StoreKey, paramSpace paramtyp cdc: cdc, paramSpace: paramSpace, // keepers - accountKeeper: accountKeeper, - bankKeeper: bankKeeper, - distrKeeper: communityPoolKeeper, + accountKeeper: accountKeeper, + bankKeeper: bankKeeper, + communityPoolKeeper: communityPoolKeeper, } } diff --git a/x/gamm/keeper/pool_service.go b/x/gamm/keeper/pool_service.go index d0d45ffdb1a..096a6a26357 100644 --- a/x/gamm/keeper/pool_service.go +++ b/x/gamm/keeper/pool_service.go @@ -101,7 +101,7 @@ func (k Keeper) CreatePool(ctx sdk.Context, msg types.CreatePoolMsg) (uint64, er // send pool creation fee to community pool params := k.GetParams(ctx) - if err := k.distrKeeper.FundCommunityPool(ctx, params.PoolCreationFee, sender); err != nil { + if err := k.communityPoolKeeper.FundCommunityPool(ctx, params.PoolCreationFee, sender); err != nil { return 0, err } diff --git a/x/incentives/keeper/gauge.go b/x/incentives/keeper/gauge.go index 636597714d2..ea1f29dee2a 100644 --- a/x/incentives/keeper/gauge.go +++ b/x/incentives/keeper/gauge.go @@ -298,7 +298,7 @@ func (k Keeper) chargeFeeIfSufficientFeeDenomBalance(ctx sdk.Context, address sd return sdkerrors.Wrapf(sdkerrors.ErrInsufficientFunds, "account's balance of %s (%s) is less than the total cost of the message (%s)", feeDenom, accountBalance, totalCost) } - if err := k.dk.FundCommunityPool(ctx, sdk.NewCoins(sdk.NewCoin(feeDenom, fee)), address); err != nil { + if err := k.ck.FundCommunityPool(ctx, sdk.NewCoins(sdk.NewCoin(feeDenom, fee)), address); err != nil { return err } return nil diff --git a/x/incentives/keeper/keeper.go b/x/incentives/keeper/keeper.go index c97205227f2..0ca92037fa0 100644 --- a/x/incentives/keeper/keeper.go +++ b/x/incentives/keeper/keeper.go @@ -22,7 +22,7 @@ type Keeper struct { bk types.BankKeeper lk types.LockupKeeper ek types.EpochKeeper - dk types.CommunityPoolKeeper + ck types.CommunityPoolKeeper tk types.TxFeesKeeper } @@ -39,7 +39,7 @@ func NewKeeper(cdc codec.Codec, storeKey sdk.StoreKey, paramSpace paramtypes.Sub bk: bk, lk: lk, ek: ek, - dk: ck, + ck: ck, tk: txfk, } } diff --git a/x/lockup/keeper/keeper.go b/x/lockup/keeper/keeper.go index ff1a3147293..faf8a5f5fd5 100644 --- a/x/lockup/keeper/keeper.go +++ b/x/lockup/keeper/keeper.go @@ -19,7 +19,7 @@ type Keeper struct { ak types.AccountKeeper bk types.BankKeeper - dk types.CommunityPoolKeeper + ck types.CommunityPoolKeeper } // NewKeeper returns an instance of Keeper. @@ -28,7 +28,7 @@ func NewKeeper(cdc codec.Codec, storeKey sdk.StoreKey, ak types.AccountKeeper, b storeKey: storeKey, ak: ak, bk: bk, - dk: ck, + ck: ck, } } diff --git a/x/lockup/keeper/lock.go b/x/lockup/keeper/lock.go index 84e7aa6449b..cb46c73f826 100644 --- a/x/lockup/keeper/lock.go +++ b/x/lockup/keeper/lock.go @@ -569,7 +569,7 @@ func (k Keeper) SlashTokensFromLockByID(ctx sdk.Context, lockID uint64, coins sd } modAddr := k.ak.GetModuleAddress(types.ModuleName) - err = k.dk.FundCommunityPool(ctx, coins, modAddr) + err = k.ck.FundCommunityPool(ctx, coins, modAddr) if err != nil { return nil, err } diff --git a/x/mint/keeper/keeper.go b/x/mint/keeper/keeper.go index b4d8423b0eb..1f31bfea88f 100644 --- a/x/mint/keeper/keeper.go +++ b/x/mint/keeper/keeper.go @@ -50,7 +50,7 @@ const emptyWeightedAddressReceiver = "" // NewKeeper creates a new mint Keeper instance. func NewKeeper( cdc codec.BinaryCodec, key sdk.StoreKey, paramSpace paramtypes.Subspace, - ak types.AccountKeeper, bk types.BankKeeper, dk types.CommunityPoolKeeper, epochKeeper types.EpochKeeper, + ak types.AccountKeeper, bk types.BankKeeper, ck types.CommunityPoolKeeper, epochKeeper types.EpochKeeper, feeCollectorName string, ) Keeper { // ensure mint module account is set @@ -69,7 +69,7 @@ func NewKeeper( paramSpace: paramSpace, accountKeeper: ak, bankKeeper: bk, - communityPoolKeeper: dk, + communityPoolKeeper: ck, epochKeeper: epochKeeper, feeCollectorName: feeCollectorName, } From d5931d2fbc49c4f56af0573a0bf6f5463f78bcaa Mon Sep 17 00:00:00 2001 From: Roman Date: Fri, 12 Aug 2022 20:54:09 -0400 Subject: [PATCH 3/4] changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index ee50b747c3d..81edf24d6ed 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -72,6 +72,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 * [#1667](https://github.com/osmosis-labs/osmosis/pull/1673) Move wasm-bindings code out of app package into its own root level package. * [#2013](https://github.com/osmosis-labs/osmosis/pull/2013) Make `SetParams`, `SetPool`, `SetTotalLiquidity`, and `SetDenomLiquidity` GAMM APIs private * [#1857](https://github.com/osmosis-labs/osmosis/pull/1857) x/mint rename GetLastHalvenEpochNum to GetLastReductionEpochNum +* [#2394](https://github.com/osmosis-labs/osmosis/pull/2394) Remove unused interface methods from expected keepers of each module ### Features From 3641c907392b33a9db1e720db9cb3ea99bbfe86d Mon Sep 17 00:00:00 2001 From: Roman Date: Fri, 12 Aug 2022 22:03:28 -0400 Subject: [PATCH 4/4] restore TxFeesKeeper and type check --- x/txfees/keeper/feedecorator.go | 2 +- x/txfees/keeper/keeper.go | 2 ++ x/txfees/types/expected_keepers.go | 7 +++++++ 3 files changed, 10 insertions(+), 1 deletion(-) diff --git a/x/txfees/keeper/feedecorator.go b/x/txfees/keeper/feedecorator.go index 2281aa5fa76..e394bf03b8e 100644 --- a/x/txfees/keeper/feedecorator.go +++ b/x/txfees/keeper/feedecorator.go @@ -210,7 +210,7 @@ func (dfd DeductFeeDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simulate bo } // DeductFees deducts fees from the given account and transfers them to the set module account. -func DeductFees(txFeesKeeper Keeper, bankKeeper types.BankKeeper, ctx sdk.Context, acc authtypes.AccountI, fees sdk.Coins) error { +func DeductFees(txFeesKeeper types.TxFeesKeeper, bankKeeper types.BankKeeper, ctx sdk.Context, acc authtypes.AccountI, fees sdk.Coins) error { // Checks the validity of the fee tokens (sorted, have positive amount, valid and unique denomination) if !fees.IsValid() { return sdkerrors.Wrapf(sdkerrors.ErrInsufficientFee, "invalid fee amount: %s", fees) diff --git a/x/txfees/keeper/keeper.go b/x/txfees/keeper/keeper.go index 74af1138d52..3cfba9d2ac9 100644 --- a/x/txfees/keeper/keeper.go +++ b/x/txfees/keeper/keeper.go @@ -23,6 +23,8 @@ type Keeper struct { nonNativeFeeCollectorName string } +var _ types.TxFeesKeeper = (*Keeper)(nil) + func NewKeeper( cdc codec.Codec, accountKeeper types.AccountKeeper, diff --git a/x/txfees/types/expected_keepers.go b/x/txfees/types/expected_keepers.go index 9ed89ee37dc..b4f050e75cb 100644 --- a/x/txfees/types/expected_keepers.go +++ b/x/txfees/types/expected_keepers.go @@ -41,3 +41,10 @@ type BankKeeper interface { GetBalance(ctx sdk.Context, addr sdk.AccAddress, denom string) sdk.Coin SendCoinsFromModuleToModule(ctx sdk.Context, senderModule, recipientModule string, amt sdk.Coins) error } + +// TxFeesKeeper defines the expected transaction fee keeper +type TxFeesKeeper interface { + ConvertToBaseToken(ctx sdk.Context, inputFee sdk.Coin) (sdk.Coin, error) + GetBaseDenom(ctx sdk.Context) (denom string, err error) + GetFeeToken(ctx sdk.Context, denom string) (FeeToken, error) +}