2022-12-09 21:24:35 +00:00
|
|
|
package keeper
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
|
|
|
|
"github.com/tendermint/tendermint/libs/log"
|
|
|
|
|
|
|
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
|
|
|
"github.com/kava-labs/kava/x/community/types"
|
|
|
|
)
|
|
|
|
|
|
|
|
// Keeper of the community store
|
|
|
|
type Keeper struct {
|
|
|
|
bankKeeper types.BankKeeper
|
2023-04-20 21:13:16 +00:00
|
|
|
cdpKeeper types.CdpKeeper
|
2022-12-19 21:56:46 +00:00
|
|
|
distrKeeper types.DistributionKeeper
|
2022-12-13 00:38:27 +00:00
|
|
|
hardKeeper types.HardKeeper
|
2022-12-09 21:24:35 +00:00
|
|
|
moduleAddress sdk.AccAddress
|
2023-10-25 17:09:19 +00:00
|
|
|
mintKeeper types.MintKeeper
|
|
|
|
stakingKeeper types.StakingKeeper
|
2022-12-19 21:56:46 +00:00
|
|
|
|
|
|
|
legacyCommunityPoolAddress sdk.AccAddress
|
2022-12-09 21:24:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// NewKeeper creates a new community Keeper instance
|
2023-10-25 17:09:19 +00:00
|
|
|
func NewKeeper(
|
|
|
|
ak types.AccountKeeper,
|
|
|
|
bk types.BankKeeper,
|
|
|
|
ck types.CdpKeeper,
|
|
|
|
dk types.DistributionKeeper,
|
|
|
|
hk types.HardKeeper,
|
|
|
|
mk types.MintKeeper,
|
|
|
|
sk types.StakingKeeper,
|
|
|
|
) Keeper {
|
2022-12-09 21:24:35 +00:00
|
|
|
// 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))
|
|
|
|
}
|
2022-12-19 21:56:46 +00:00
|
|
|
legacyAddr := ak.GetModuleAddress(types.LegacyCommunityPoolModuleName)
|
|
|
|
if addr == nil {
|
|
|
|
panic("legacy community pool address not found")
|
|
|
|
}
|
2022-12-09 21:24:35 +00:00
|
|
|
|
|
|
|
return Keeper{
|
|
|
|
bankKeeper: bk,
|
2023-04-20 21:13:16 +00:00
|
|
|
cdpKeeper: ck,
|
2022-12-19 21:56:46 +00:00
|
|
|
distrKeeper: dk,
|
2022-12-13 00:38:27 +00:00
|
|
|
hardKeeper: hk,
|
2023-10-25 17:09:19 +00:00
|
|
|
mintKeeper: mk,
|
|
|
|
stakingKeeper: sk,
|
2022-12-09 21:24:35 +00:00
|
|
|
moduleAddress: addr,
|
2022-12-19 21:56:46 +00:00
|
|
|
|
|
|
|
legacyCommunityPoolAddress: legacyAddr,
|
2022-12-09 21:24:35 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// 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)
|
|
|
|
}
|