/
farm_pool.go
87 lines (76 loc) · 2.56 KB
/
farm_pool.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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
package types
import (
"fmt"
"strings"
sdk "github.com/cosmos/cosmos-sdk/types"
)
// FarmPool is the pool where an address can lock specified token to yield other tokens
type FarmPool struct {
Owner sdk.AccAddress `json:"owner"`
Name string `json:"name"`
MinLockAmount sdk.SysCoin `json:"min_lock_amount"`
DepositAmount sdk.SysCoin `json:"deposit_amount"`
// sum of LockInfo.Amount
TotalValueLocked sdk.SysCoin `json:"total_value_locked"`
YieldedTokenInfos YieldedTokenInfos `json:"yielded_token_infos"`
TotalAccumulatedRewards sdk.SysCoins `json:"total_accumulated_rewards"`
}
// NewFarmPool creates a new instance of FarmPool
func NewFarmPool(
owner sdk.AccAddress, name string, minLockAmount sdk.SysCoin, depositAmount, totalValueLocked sdk.SysCoin,
yieldedTokenInfos YieldedTokenInfos, accumulatedRewards sdk.SysCoins,
) FarmPool {
return FarmPool{
Owner: owner,
Name: name,
MinLockAmount: minLockAmount,
DepositAmount: depositAmount,
TotalValueLocked: totalValueLocked,
YieldedTokenInfos: yieldedTokenInfos,
TotalAccumulatedRewards: accumulatedRewards,
}
}
func (fp FarmPool) Finished() bool {
for _, yieldedTokenInfo := range fp.YieldedTokenInfos {
if yieldedTokenInfo.RemainingAmount.IsPositive() {
return false
}
}
return fp.TotalValueLocked.IsZero()
}
// String returns a human readable string representation of FarmPool
func (fp FarmPool) String() string {
return fmt.Sprintf(`FarmPool:
Pool Name: %s
Owner: %s
Min Lock Amount: %s
Deposit Amount: %s
Total Value Locked: %s
Yielded Token Infos: %s
Total Accumulated Rewards: %s`,
fp.Name, fp.Owner, fp.MinLockAmount.String(), fp.DepositAmount, fp.TotalValueLocked, fp.YieldedTokenInfos, fp.TotalAccumulatedRewards)
}
// FarmPools is a collection of FarmPool
type FarmPools []FarmPool
// String returns a human readable string representation of FarmPools
func (fps FarmPools) String() (out string) {
for _, fp := range fps {
out += fp.String() + "\n"
}
return strings.TrimSpace(out)
}
// PoolNum is a wrapped structure of uint to display by cli query
type PoolNum struct {
Number uint `json:"number"`
}
// NewPoolNum creates a new instance of PoolNum
func NewPoolNum(num uint) PoolNum {
return PoolNum{
Number: num,
}
}
// String returns a human readable string representation of PoolNum
func (pn PoolNum) String() string {
return fmt.Sprintf(`Number Of Pools:
Number: %d`, pn.Number)
}