-
Notifications
You must be signed in to change notification settings - Fork 0
/
genesis.go
160 lines (143 loc) · 4.51 KB
/
genesis.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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
package types
import (
"fmt"
"time"
)
var (
DefaultUSDXClaims = USDXMintingClaims{}
DefaultHardClaims = HardLiquidityProviderClaims{}
DefaultDelegatorClaims = DelegatorClaims{}
DefaultSwapClaims = SwapClaims{}
DefaultSavingsClaims = SavingsClaims{}
DefaultGenesisRewardState = NewGenesisRewardState(
AccumulationTimes{},
MultiRewardIndexes{},
)
DefaultEarnClaims = EarnClaims{}
)
// NewGenesisState returns a new genesis state
func NewGenesisState(
params Params,
usdxState, hardSupplyState, hardBorrowState, delegatorState, swapState, savingsState, earnState GenesisRewardState,
c USDXMintingClaims, hc HardLiquidityProviderClaims, dc DelegatorClaims, sc SwapClaims, savingsc SavingsClaims,
earnc EarnClaims,
) GenesisState {
return GenesisState{
Params: params,
USDXRewardState: usdxState,
HardSupplyRewardState: hardSupplyState,
HardBorrowRewardState: hardBorrowState,
DelegatorRewardState: delegatorState,
SwapRewardState: swapState,
SavingsRewardState: savingsState,
EarnRewardState: earnState,
USDXMintingClaims: c,
HardLiquidityProviderClaims: hc,
DelegatorClaims: dc,
SwapClaims: sc,
SavingsClaims: savingsc,
EarnClaims: earnc,
}
}
// DefaultGenesisState returns a default genesis state
func DefaultGenesisState() GenesisState {
return GenesisState{
Params: DefaultParams(),
USDXRewardState: DefaultGenesisRewardState,
HardSupplyRewardState: DefaultGenesisRewardState,
HardBorrowRewardState: DefaultGenesisRewardState,
DelegatorRewardState: DefaultGenesisRewardState,
SwapRewardState: DefaultGenesisRewardState,
SavingsRewardState: DefaultGenesisRewardState,
EarnRewardState: DefaultGenesisRewardState,
USDXMintingClaims: DefaultUSDXClaims,
HardLiquidityProviderClaims: DefaultHardClaims,
DelegatorClaims: DefaultDelegatorClaims,
SwapClaims: DefaultSwapClaims,
SavingsClaims: DefaultSavingsClaims,
EarnClaims: DefaultEarnClaims,
}
}
// Validate performs basic validation of genesis data returning an
// error for any failed validation criteria.
func (gs GenesisState) Validate() error {
if err := gs.Params.Validate(); err != nil {
return err
}
if err := gs.USDXRewardState.Validate(); err != nil {
return err
}
if err := gs.HardSupplyRewardState.Validate(); err != nil {
return err
}
if err := gs.HardBorrowRewardState.Validate(); err != nil {
return err
}
if err := gs.DelegatorRewardState.Validate(); err != nil {
return err
}
if err := gs.SwapRewardState.Validate(); err != nil {
return err
}
if err := gs.SavingsRewardState.Validate(); err != nil {
return err
}
if err := gs.EarnRewardState.Validate(); err != nil {
return err
}
if err := gs.USDXMintingClaims.Validate(); err != nil {
return err
}
if err := gs.HardLiquidityProviderClaims.Validate(); err != nil {
return err
}
if err := gs.DelegatorClaims.Validate(); err != nil {
return err
}
if err := gs.SwapClaims.Validate(); err != nil {
return err
}
if err := gs.SavingsClaims.Validate(); err != nil {
return err
}
return gs.EarnClaims.Validate()
}
// NewGenesisRewardState returns a new GenesisRewardState
func NewGenesisRewardState(accumTimes AccumulationTimes, indexes MultiRewardIndexes) GenesisRewardState {
return GenesisRewardState{
AccumulationTimes: accumTimes,
MultiRewardIndexes: indexes,
}
}
// Validate performs validation of a GenesisRewardState
func (grs GenesisRewardState) Validate() error {
if err := grs.AccumulationTimes.Validate(); err != nil {
return err
}
return grs.MultiRewardIndexes.Validate()
}
// NewAccumulationTime returns a new GenesisAccumulationTime
func NewAccumulationTime(ctype string, prevTime time.Time) AccumulationTime {
return AccumulationTime{
CollateralType: ctype,
PreviousAccumulationTime: prevTime,
}
}
// Validate performs validation of GenesisAccumulationTime
func (gat AccumulationTime) Validate() error {
if len(gat.CollateralType) == 0 {
return fmt.Errorf("genesis accumulation time's collateral type must be defined")
}
return nil
}
// AccumulationTimes slice of GenesisAccumulationTime
type AccumulationTimes []AccumulationTime
// Validate performs validation of GenesisAccumulationTimes
func (gats AccumulationTimes) Validate() error {
for _, gat := range gats {
if err := gat.Validate(); err != nil {
return err
}
}
return nil
}