0g-chain/x/community/keeper/keeper.go
Draco 43be3815cc
feat: disable inflation upgrade logic (#1706)
* feat: disable inflation upgrade logic

* improve disable inflation comments

* add upgrade tests

* update changelog

* split disable inflation upgrade and the upgrade check

* remove pay rewards logic

* clean up incentives test

* add abci test

* refactor upgradeTime and blockTime check

* fix abci test

* fix wrong pr in changelog

* refactor disable inflation tests, behavior, and implementation
  - Unit tests are now shared between keeper and abci begin blocker
    since behavior is 100% the same
  - ABCI is unaware of keeper initial keeper logic branch (keeper
    methods required to be called in certain order by begin blocker)
  - Behavior of zero time is changed -- this now doesn't run for the
    zero time.  This is more ideal for new chains (genesis should set
    all correct state instead of relying on inflation disable logic),
    and allows for a simpler implementation.
  - Begin blocker now panics if parameters are not in state

* remove previous tests and implementation

* remove previous block time keeper state -- not needed for inflation
disalbing

* move inflation disabling to private method and add more comments

* remove unused key

* use correct spelling for idempotence

---------

Co-authored-by: Nick DeLuca <nickdeluca08@gmail.com>
2023-10-02 13:10:22 -07:00

87 lines
2.4 KiB
Go

package keeper
import (
"fmt"
"github.com/cosmos/cosmos-sdk/codec"
storetypes "github.com/cosmos/cosmos-sdk/store/types"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/tendermint/tendermint/libs/log"
"github.com/kava-labs/kava/x/community/types"
)
// Keeper of the community store
type Keeper struct {
key storetypes.StoreKey
cdc codec.Codec
bankKeeper types.BankKeeper
cdpKeeper types.CdpKeeper
distrKeeper types.DistributionKeeper
hardKeeper types.HardKeeper
moduleAddress sdk.AccAddress
mintKeeper types.MintKeeper
kavadistKeeper types.KavadistKeeper
legacyCommunityPoolAddress sdk.AccAddress
}
// NewKeeper creates a new community Keeper instance
func NewKeeper(
cdc codec.Codec,
key storetypes.StoreKey,
ak types.AccountKeeper,
bk types.BankKeeper,
ck types.CdpKeeper,
dk types.DistributionKeeper,
hk types.HardKeeper,
mk types.MintKeeper,
kk types.KavadistKeeper,
) Keeper {
// ensure community module account is set
addr := ak.GetModuleAddress(types.ModuleAccountName)
if addr == nil {
panic(fmt.Sprintf("%s module account has not been set", types.ModuleAccountName))
}
legacyAddr := ak.GetModuleAddress(types.LegacyCommunityPoolModuleName)
if addr == nil {
panic("legacy community pool address not found")
}
return Keeper{
key: key,
cdc: cdc,
bankKeeper: bk,
cdpKeeper: ck,
distrKeeper: dk,
hardKeeper: hk,
mintKeeper: mk,
kavadistKeeper: kk,
moduleAddress: addr,
legacyCommunityPoolAddress: legacyAddr,
}
}
// Logger returns a module-specific logger.
func (k Keeper) Logger(ctx sdk.Context) log.Logger {
return ctx.Logger().With("module", "x/"+types.ModuleName)
}
// GetModuleAccountBalance returns all the coins held by the community module account
func (k Keeper) GetModuleAccountBalance(ctx sdk.Context) sdk.Coins {
return k.bankKeeper.GetAllBalances(ctx, k.moduleAddress)
}
// FundCommunityPool transfers coins from the sender to the community module account.
func (k Keeper) FundCommunityPool(ctx sdk.Context, sender sdk.AccAddress, amount sdk.Coins) error {
return k.bankKeeper.SendCoinsFromAccountToModule(ctx, sender, types.ModuleAccountName, amount)
}
// DistributeFromCommunityPool transfers coins from the community pool to recipient.
func (k Keeper) DistributeFromCommunityPool(ctx sdk.Context, recipient sdk.AccAddress, amount sdk.Coins) error {
return k.bankKeeper.SendCoinsFromModuleToAccount(ctx, types.ModuleAccountName, recipient, amount)
}