0g-chain/x/earn/keeper/keeper.go
Derrick Lee ded692d2f4
Add savings strategy (#1290)
* Add basic savings strategy

Supports ukava

* Use clearer error message for ErrInvalidVaultStrategy

* Add invariants

* Separate specific vault/all vaults query, update depositor inconsistencies

* Update swagger

* Use single bkava AllowedVault for all bkava variants

* Do not use allowedVault.Denom for value

* Fix vault balance query

* Update query to list bkava vaults

* Add vaults query doc

* Update grpc query test with no supply

* Add earn hooks

* Handle errors

* Update outdated doc comments, make getAllowedVault_Raw private

* Fix outdated comments, lints

* Fix comment maths

* Use AccAddressFromBech32 to validate message addresses
2022-09-12 10:50:35 -07:00

63 lines
1.4 KiB
Go

package keeper
import (
"github.com/cosmos/cosmos-sdk/codec"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/kava-labs/kava/x/earn/types"
paramtypes "github.com/cosmos/cosmos-sdk/x/params/types"
)
// Keeper keeper for the earn module
type Keeper struct {
key sdk.StoreKey
cdc codec.Codec
paramSubspace paramtypes.Subspace
hooks types.EarnHooks
accountKeeper types.AccountKeeper
bankKeeper types.BankKeeper
// Keepers used for strategies
hardKeeper types.HardKeeper
savingsKeeper types.SavingsKeeper
}
// NewKeeper creates a new keeper
func NewKeeper(
cdc codec.Codec,
key sdk.StoreKey,
paramstore paramtypes.Subspace,
accountKeeper types.AccountKeeper,
bankKeeper types.BankKeeper,
hardKeeper types.HardKeeper,
savingsKeeper types.SavingsKeeper,
) Keeper {
if !paramstore.HasKeyTable() {
paramstore = paramstore.WithKeyTable(types.ParamKeyTable())
}
return Keeper{
key: key,
cdc: cdc,
paramSubspace: paramstore,
accountKeeper: accountKeeper,
bankKeeper: bankKeeper,
hardKeeper: hardKeeper,
savingsKeeper: savingsKeeper,
}
}
// SetHooks adds hooks to the keeper.
func (k *Keeper) SetHooks(sh types.EarnHooks) *Keeper {
if k.hooks != nil {
panic("cannot set earn hooks twice")
}
k.hooks = sh
return k
}
// ClearHooks clears the hooks on the keeper
func (k *Keeper) ClearHooks() {
k.hooks = nil
}