github.com/gravity-devs/liquidity@v1.5.3/x/liquidity/keeper/keeper.go (about)

     1  package keeper
     2  
     3  import (
     4  	"fmt"
     5  
     6  	"github.com/cosmos/cosmos-sdk/codec"
     7  	sdk "github.com/cosmos/cosmos-sdk/types"
     8  	paramstypes "github.com/cosmos/cosmos-sdk/x/params/types"
     9  	"github.com/tendermint/tendermint/libs/log"
    10  
    11  	"github.com/gravity-devs/liquidity/x/liquidity/types"
    12  )
    13  
    14  // Keeper of the liquidity store
    15  type Keeper struct {
    16  	cdc           codec.BinaryCodec
    17  	storeKey      sdk.StoreKey
    18  	bankKeeper    types.BankKeeper
    19  	accountKeeper types.AccountKeeper
    20  	distrKeeper   types.DistributionKeeper
    21  	paramSpace    paramstypes.Subspace
    22  }
    23  
    24  // NewKeeper returns a liquidity keeper. It handles:
    25  // - creating new ModuleAccounts for each pool ReserveAccount
    26  // - sending to and from ModuleAccounts
    27  // - minting, burning PoolCoins
    28  func NewKeeper(cdc codec.BinaryCodec, key sdk.StoreKey, paramSpace paramstypes.Subspace, bankKeeper types.BankKeeper, accountKeeper types.AccountKeeper, distrKeeper types.DistributionKeeper) Keeper {
    29  	// ensure liquidity module account is set
    30  	if addr := accountKeeper.GetModuleAddress(types.ModuleName); addr == nil {
    31  		panic(fmt.Sprintf("%s module account has not been set", types.ModuleName))
    32  	}
    33  
    34  	// set KeyTable if it has not already been set
    35  	if !paramSpace.HasKeyTable() {
    36  		paramSpace = paramSpace.WithKeyTable(types.ParamKeyTable())
    37  	}
    38  
    39  	return Keeper{
    40  		storeKey:      key,
    41  		bankKeeper:    bankKeeper,
    42  		accountKeeper: accountKeeper,
    43  		distrKeeper:   distrKeeper,
    44  		cdc:           cdc,
    45  		paramSpace:    paramSpace,
    46  	}
    47  }
    48  
    49  // Logger returns a module-specific logger.
    50  func (k Keeper) Logger(ctx sdk.Context) log.Logger {
    51  	return ctx.Logger().With("module", types.ModuleName)
    52  }
    53  
    54  // GetParams gets the parameters for the liquidity module.
    55  func (k Keeper) GetParams(ctx sdk.Context) (params types.Params) {
    56  	k.paramSpace.GetParamSet(ctx, &params)
    57  	return params
    58  }
    59  
    60  // SetParams sets the parameters for the liquidity module.
    61  func (k Keeper) SetParams(ctx sdk.Context, params types.Params) {
    62  	k.paramSpace.SetParamSet(ctx, &params)
    63  }
    64  
    65  // GetCircuitBreakerEnabled returns circuit breaker enabled param from the paramspace.
    66  func (k Keeper) GetCircuitBreakerEnabled(ctx sdk.Context) (enabled bool) {
    67  	k.paramSpace.Get(ctx, types.KeyCircuitBreakerEnabled, &enabled)
    68  	return
    69  }