2022-07-20 23:14:43 +00:00
|
|
|
package keeper
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
|
|
|
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
|
|
|
"github.com/kava-labs/kava/x/earn/types"
|
|
|
|
)
|
|
|
|
|
|
|
|
// Strategy is the interface that must be implemented by a strategy.
|
|
|
|
type Strategy interface {
|
2022-07-28 16:39:57 +00:00
|
|
|
// GetStrategyType returns the strategy type
|
|
|
|
GetStrategyType() types.StrategyType
|
2022-07-20 23:14:43 +00:00
|
|
|
|
2022-09-12 17:50:35 +00:00
|
|
|
// GetEstimatedTotalAssets returns the estimated total assets of the
|
|
|
|
// strategy with the specified denom. This is the value if the strategy were
|
|
|
|
// to liquidate all assets.
|
2022-07-20 23:14:43 +00:00
|
|
|
//
|
|
|
|
// **Note:** This may not reflect the true value as it may become outdated
|
|
|
|
// from market changes.
|
2022-07-28 16:39:57 +00:00
|
|
|
GetEstimatedTotalAssets(ctx sdk.Context, denom string) (sdk.Coin, error)
|
2022-07-20 23:14:43 +00:00
|
|
|
|
2022-09-12 17:50:35 +00:00
|
|
|
// Deposit the specified amount of coins into this strategy.
|
2022-07-28 16:39:57 +00:00
|
|
|
Deposit(ctx sdk.Context, amount sdk.Coin) error
|
2022-07-20 23:14:43 +00:00
|
|
|
|
2022-09-12 17:50:35 +00:00
|
|
|
// Withdraw the specified amount of coins from this strategy.
|
2022-07-28 16:39:57 +00:00
|
|
|
Withdraw(ctx sdk.Context, amount sdk.Coin) error
|
2022-07-20 23:14:43 +00:00
|
|
|
}
|
|
|
|
|
2022-07-28 16:39:57 +00:00
|
|
|
// GetStrategy returns the strategy for the given strategy type.
|
2022-07-20 23:14:43 +00:00
|
|
|
func (k *Keeper) GetStrategy(strategyType types.StrategyType) (Strategy, error) {
|
|
|
|
switch strategyType {
|
2022-07-28 16:39:57 +00:00
|
|
|
case types.STRATEGY_TYPE_HARD:
|
|
|
|
return (*HardStrategy)(k), nil
|
|
|
|
case types.STRATEGY_TYPE_SAVINGS:
|
2022-09-12 17:50:35 +00:00
|
|
|
return (*SavingsStrategy)(k), nil
|
2022-07-20 23:14:43 +00:00
|
|
|
default:
|
|
|
|
return nil, fmt.Errorf("unknown strategy type: %s", strategyType)
|
|
|
|
}
|
|
|
|
}
|