-
Notifications
You must be signed in to change notification settings - Fork 170
/
genesis.go
129 lines (110 loc) · 4.24 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
package simulation
import (
"encoding/json"
"fmt"
"math/rand"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/module"
"github.com/umee-network/umee/v2/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"
)
// 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))
}
// 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) },
)
oracleGenesis := types.NewGenesisState(
types.Params{
VotePeriod: votePeriod,
VoteThreshold: voteThreshold,
RewardBand: rewardBand,
RewardDistributionWindow: rewardDistributionWindow,
AcceptList: types.DenomList{
{SymbolDenom: types.UmeeSymbol, BaseDenom: types.UmeeDenom},
},
SlashFraction: slashFraction,
SlashWindow: slashWindow,
MinValidPerWindow: minValidPerWindow,
},
[]types.ExchangeRateTuple{},
[]types.FeederDelegation{},
[]types.MissCounter{},
[]types.AggregateExchangeRatePrevote{},
[]types.AggregateExchangeRateVote{},
)
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)
}