mirror of
https://github.com/0glabs/0g-chain.git
synced 2024-09-20 22:57:32 +00:00
56 lines
1.8 KiB
Go
56 lines
1.8 KiB
Go
|
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 {
|
||
|
// GetName returns the name of the strategy.
|
||
|
GetName() string
|
||
|
|
||
|
// GetDescription returns the description of the strategy.
|
||
|
GetDescription() string
|
||
|
|
||
|
// GetSupportedDenoms returns a slice of supported denom for this strategy.
|
||
|
// For example, stablecoin stakers strategy supports both "busd" and "usdc".
|
||
|
GetSupportedDenoms() []string
|
||
|
|
||
|
// GetEstimatedTotalAssets returns the estimated total assets denominated in
|
||
|
// GetDenom() of this strategy. This is the value if the strategy were to
|
||
|
// liquidate all assets.
|
||
|
//
|
||
|
// **Note:** This may not reflect the true value as it may become outdated
|
||
|
// from market changes.
|
||
|
GetEstimatedTotalAssets(denom string) (sdk.Coin, error)
|
||
|
|
||
|
// Deposit the specified amount of coins into this strategy. The amount
|
||
|
// must be denominated in GetDenom().
|
||
|
Deposit(amount sdk.Coin) error
|
||
|
|
||
|
// Withdraw the specified amount of coins from this strategy. The amount
|
||
|
// must be denominated in GetDenom().
|
||
|
Withdraw(amount sdk.Coin) error
|
||
|
|
||
|
// LiquidateAll liquidates all of the entire strategy's positions, returning
|
||
|
// the amount of liquidated denominated in GetDenom(). This should be only
|
||
|
// called during use of emergency via governance.
|
||
|
LiquidateAll() (amount sdk.Coin, err error)
|
||
|
}
|
||
|
|
||
|
func (k *Keeper) GetStrategy(strategyType types.StrategyType) (Strategy, error) {
|
||
|
switch strategyType {
|
||
|
case types.STRATEGY_TYPE_STABLECOIN_STAKERS:
|
||
|
return (*StableCoinStrategy)(k), nil
|
||
|
case types.STRATEGY_TYPE_KAVA_STAKERS:
|
||
|
panic("unimplemented")
|
||
|
case types.STRATEGY_TYPE_KAVA_FOUNDATION:
|
||
|
panic("unimplemented")
|
||
|
default:
|
||
|
return nil, fmt.Errorf("unknown strategy type: %s", strategyType)
|
||
|
}
|
||
|
}
|