forked from umee-network/umee
-
Notifications
You must be signed in to change notification settings - Fork 0
/
genesis.go
175 lines (148 loc) · 6.04 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
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
package simulation
import (
"encoding/json"
"fmt"
"math/rand"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/module"
"github.com/mokitanetwork/katana/x/oracle/types"
)
// Simulation parameter constants
const (
votePeriodKey = "vote_period"
voteThresholdKey = "vote_threshold"
rewardBandKey = "reward_band"
rewardDistributionWindowKey = "reward_distribution_window"
slashFractionKey = "slash_fraction"
slashWindowKey = "slash_window"
minValidPerWindowKey = "min_valid_per_window"
historicStampPeriodKey = "historic_stamp_period"
medianStampPeriodKey = "median_stamp_period"
maximumPriceStampsKey = "maximum_price_stamps"
maximumMedianStampsKey = "maximum_median_stamps"
)
// GenVotePeriod produces a randomized VotePeriod in the range of [5, 100]
func GenVotePeriod(r *rand.Rand) uint64 {
return uint64(5 + r.Intn(100))
}
// GenVoteThreshold produces a randomized VoteThreshold in the range of [0.333, 0.666]
func GenVoteThreshold(r *rand.Rand) sdk.Dec {
return sdk.NewDecWithPrec(333, 3).Add(sdk.NewDecWithPrec(int64(r.Intn(333)), 3))
}
// GenRewardBand produces a randomized RewardBand in the range of [0.000, 0.100]
func GenRewardBand(r *rand.Rand) sdk.Dec {
return sdk.ZeroDec().Add(sdk.NewDecWithPrec(int64(r.Intn(100)), 3))
}
// GenRewardDistributionWindow produces a randomized RewardDistributionWindow in the range of [100, 100000]
func GenRewardDistributionWindow(r *rand.Rand) uint64 {
return uint64(100 + r.Intn(100000))
}
// GenSlashFraction produces a randomized SlashFraction in the range of [0.000, 0.100]
func GenSlashFraction(r *rand.Rand) sdk.Dec {
return sdk.ZeroDec().Add(sdk.NewDecWithPrec(int64(r.Intn(100)), 3))
}
// GenSlashWindow produces a randomized SlashWindow in the range of [100, 100000]
func GenSlashWindow(r *rand.Rand) uint64 {
return uint64(100 + r.Intn(100000))
}
// GenMinValidPerWindow produces a randomized MinValidPerWindow in the range of [0, 0.500]
func GenMinValidPerWindow(r *rand.Rand) sdk.Dec {
return sdk.ZeroDec().Add(sdk.NewDecWithPrec(int64(r.Intn(500)), 3))
}
// GenHistoricStampPeriod produces a randomized HistoricStampPeriod in the range of [100, 1000]
func GenHistoricStampPeriod(r *rand.Rand) uint64 {
return uint64(100 + r.Intn(1000))
}
// GenMedianStampPeriod produces a randomized MedianStampPeriod in the range of [100, 1000]
func GenMedianStampPeriod(r *rand.Rand) uint64 {
return uint64(10001 + r.Intn(100000))
}
// GenMaximumPriceStamps produces a randomized MaximumPriceStamps in the range of [10, 100]
func GenMaximumPriceStamps(r *rand.Rand) uint64 {
return uint64(11 + r.Intn(100))
}
// GenMaximumMedianStamps produces a randomized MaximumMedianStamps in the range of [10, 100]
func GenMaximumMedianStamps(r *rand.Rand) uint64 {
return uint64(11 + r.Intn(100))
}
// RandomizedGenState generates a random GenesisState for oracle
func RandomizedGenState(simState *module.SimulationState) {
var votePeriod uint64
simState.AppParams.GetOrGenerate(
simState.Cdc, votePeriodKey, &votePeriod, simState.Rand,
func(r *rand.Rand) { votePeriod = GenVotePeriod(r) },
)
var voteThreshold sdk.Dec
simState.AppParams.GetOrGenerate(
simState.Cdc, voteThresholdKey, &voteThreshold, simState.Rand,
func(r *rand.Rand) { voteThreshold = GenVoteThreshold(r) },
)
var rewardBand sdk.Dec
simState.AppParams.GetOrGenerate(
simState.Cdc, rewardBandKey, &rewardBand, simState.Rand,
func(r *rand.Rand) { rewardBand = GenRewardBand(r) },
)
var rewardDistributionWindow uint64
simState.AppParams.GetOrGenerate(
simState.Cdc, rewardDistributionWindowKey, &rewardDistributionWindow, simState.Rand,
func(r *rand.Rand) { rewardDistributionWindow = GenRewardDistributionWindow(r) },
)
var slashFraction sdk.Dec
simState.AppParams.GetOrGenerate(
simState.Cdc, slashFractionKey, &slashFraction, simState.Rand,
func(r *rand.Rand) { slashFraction = GenSlashFraction(r) },
)
var slashWindow uint64
simState.AppParams.GetOrGenerate(
simState.Cdc, slashWindowKey, &slashWindow, simState.Rand,
func(r *rand.Rand) { slashWindow = GenSlashWindow(r) },
)
var minValidPerWindow sdk.Dec
simState.AppParams.GetOrGenerate(
simState.Cdc, minValidPerWindowKey, &minValidPerWindow, simState.Rand,
func(r *rand.Rand) { minValidPerWindow = GenMinValidPerWindow(r) },
)
var historicStampPeriod uint64
simState.AppParams.GetOrGenerate(
simState.Cdc, historicStampPeriodKey, &historicStampPeriod, simState.Rand,
func(r *rand.Rand) { historicStampPeriod = GenHistoricStampPeriod(r) },
)
var medianStampPeriod uint64
simState.AppParams.GetOrGenerate(
simState.Cdc, medianStampPeriodKey, &medianStampPeriod, simState.Rand,
func(r *rand.Rand) { medianStampPeriod = GenMedianStampPeriod(r) },
)
var maximumPriceStamps uint64
simState.AppParams.GetOrGenerate(
simState.Cdc, maximumPriceStampsKey, &maximumPriceStamps, simState.Rand,
func(r *rand.Rand) { maximumPriceStamps = GenMaximumPriceStamps(r) },
)
var maximumMedianStamps uint64
simState.AppParams.GetOrGenerate(
simState.Cdc, maximumMedianStampsKey, &maximumMedianStamps, simState.Rand,
func(r *rand.Rand) { maximumMedianStamps = GenMaximumMedianStamps(r) },
)
oracleGenesis := types.DefaultGenesisState()
oracleGenesis.Params = types.Params{
VotePeriod: votePeriod,
VoteThreshold: voteThreshold,
RewardBand: rewardBand,
RewardDistributionWindow: rewardDistributionWindow,
AcceptList: types.DenomList{
{SymbolDenom: types.KatanaSymbol, BaseDenom: types.KatanaDenom},
},
SlashFraction: slashFraction,
SlashWindow: slashWindow,
MinValidPerWindow: minValidPerWindow,
HistoricStampPeriod: historicStampPeriod,
MedianStampPeriod: medianStampPeriod,
MaximumPriceStamps: historicStampPeriod,
MaximumMedianStamps: historicStampPeriod,
}
bz, err := json.MarshalIndent(&oracleGenesis.Params, "", " ")
if err != nil {
panic(err)
}
fmt.Printf("Selected randomly generated oracle parameters:\n%s\n", bz)
simState.GenState[types.ModuleName] = simState.Cdc.MustMarshalJSON(oracleGenesis)
}