-
Notifications
You must be signed in to change notification settings - Fork 337
/
strategy_savings.go
49 lines (40 loc) · 1.64 KB
/
strategy_savings.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
package keeper
import (
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/kava-labs/kava/x/earn/types"
)
// SavingsStrategy defines the strategy that deposits assets to x/savings
type SavingsStrategy Keeper
var _ Strategy = (*SavingsStrategy)(nil)
// GetStrategyType returns the strategy type
func (s *SavingsStrategy) GetStrategyType() types.StrategyType {
return types.STRATEGY_TYPE_SAVINGS
}
// GetEstimatedTotalAssets returns the current value of all assets deposited
// in savings.
func (s *SavingsStrategy) GetEstimatedTotalAssets(ctx sdk.Context, denom string) (sdk.Coin, error) {
macc := s.accountKeeper.GetModuleAccount(ctx, types.ModuleName)
deposit, found := s.savingsKeeper.GetDeposit(ctx, macc.GetAddress())
if !found {
// Return 0 if no deposit exists for module account
return sdk.NewCoin(denom, sdk.ZeroInt()), nil
}
// Only return the deposit for the vault denom.
for _, coin := range deposit.Amount {
if coin.Denom == denom {
return coin, nil
}
}
// Return 0 if no deposit exists for the vault denom
return sdk.NewCoin(denom, sdk.ZeroInt()), nil
}
// Deposit deposits the specified amount of coins into savings.
func (s *SavingsStrategy) Deposit(ctx sdk.Context, amount sdk.Coin) error {
macc := s.accountKeeper.GetModuleAccount(ctx, types.ModuleName)
return s.savingsKeeper.Deposit(ctx, macc.GetAddress(), sdk.NewCoins(amount))
}
// Withdraw withdraws the specified amount of coins from savings.
func (s *SavingsStrategy) Withdraw(ctx sdk.Context, amount sdk.Coin) error {
macc := s.accountKeeper.GetModuleAccount(ctx, types.ModuleName)
return s.savingsKeeper.Withdraw(ctx, macc.GetAddress(), sdk.NewCoins(amount))
}