package keeper
import (
"fmt"
"github.com/cometbft/cometbft/libs/log"
"github.com/cosmos/cosmos-sdk/codec"
storetypes "github.com/cosmos/cosmos-sdk/store/types"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cybercongress/go-cyber/v7/x/liquidity/types"
)
type Keeper struct {
cdc codec.BinaryCodec
storeKey storetypes.StoreKey
bankKeeper types.BankKeeper
accountKeeper types.AccountKeeper
distrKeeper types.DistributionKeeper
authority string
}
func NewKeeper(
cdc codec.BinaryCodec,
key storetypes.StoreKey,
bankKeeper types.BankKeeper,
accountKeeper types.AccountKeeper,
distrKeeper types.DistributionKeeper,
authority string,
) Keeper {
if addr := accountKeeper.GetModuleAddress(types.ModuleName); addr == nil {
panic(fmt.Sprintf("%s module account has not been set", types.ModuleName))
}
return Keeper{
storeKey: key,
bankKeeper: bankKeeper,
accountKeeper: accountKeeper,
distrKeeper: distrKeeper,
cdc: cdc,
authority: authority,
}
}
func (k Keeper) GetAuthority() string { return k.authority }
func (k Keeper) Logger(ctx sdk.Context) log.Logger {
return ctx.Logger().With("module", fmt.Sprintf("x/%s", types.ModuleName))
}
func (k Keeper) SetParams(ctx sdk.Context, p types.Params) error {
if err := p.Validate(); err != nil {
return err
}
store := ctx.KVStore(k.storeKey)
bz := k.cdc.MustMarshal(&p)
store.Set(types.ParamsKey, bz)
return nil
}
func (k Keeper) GetParams(ctx sdk.Context) (p types.Params) {
store := ctx.KVStore(k.storeKey)
bz := store.Get(types.ParamsKey)
if bz == nil {
return p
}
k.cdc.MustUnmarshal(bz, &p)
return p
}
func (k Keeper) GetCircuitBreakerEnabled(ctx sdk.Context) bool {
return k.GetParams(ctx).CircuitBreakerEnabled
}