-
Notifications
You must be signed in to change notification settings - Fork 43
/
genesis.go
74 lines (60 loc) · 1.99 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
package simulation
// DONTCOVER
import (
"encoding/json"
"fmt"
"math/rand"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/module"
"github.com/classic-terra/core/v2/x/market/types"
)
// Simulation parameter constants
const (
basePoolKey = "base_pool"
poolRecoveryPeriodKey = "pool_recovery_period"
minStabilitySpreadKey = "min_spread"
)
// GenBasePool randomized MintBasePool
func GenBasePool(r *rand.Rand) sdk.Dec {
return sdk.NewDec(50000000000000).Add(sdk.NewDec(int64(r.Intn(10000000000))))
}
// GenPoolRecoveryPeriod randomized PoolRecoveryPeriod
func GenPoolRecoveryPeriod(r *rand.Rand) uint64 {
return uint64(100 + r.Intn(10000000000))
}
// GenMinSpread randomized MinSpread
func GenMinSpread(r *rand.Rand) sdk.Dec {
return sdk.NewDecWithPrec(1, 2).Add(sdk.NewDecWithPrec(int64(r.Intn(100)), 3))
}
// RandomizedGenState generates a random GenesisState for gov
func RandomizedGenState(simState *module.SimulationState) {
var basePool sdk.Dec
simState.AppParams.GetOrGenerate(
simState.Cdc, basePoolKey, &basePool, simState.Rand,
func(r *rand.Rand) { basePool = GenBasePool(r) },
)
var poolRecoveryPeriod uint64
simState.AppParams.GetOrGenerate(
simState.Cdc, poolRecoveryPeriodKey, &poolRecoveryPeriod, simState.Rand,
func(r *rand.Rand) { poolRecoveryPeriod = GenPoolRecoveryPeriod(r) },
)
var minStabilitySpread sdk.Dec
simState.AppParams.GetOrGenerate(
simState.Cdc, minStabilitySpreadKey, &minStabilitySpread, simState.Rand,
func(r *rand.Rand) { minStabilitySpread = GenMinSpread(r) },
)
marketGenesis := types.NewGenesisState(
sdk.ZeroDec(),
types.Params{
BasePool: basePool,
PoolRecoveryPeriod: poolRecoveryPeriod,
MinStabilitySpread: minStabilitySpread,
},
)
bz, err := json.MarshalIndent(&marketGenesis.Params, "", " ")
if err != nil {
panic(err)
}
fmt.Printf("Selected randomly generated market parameters:\n%s\n", bz)
simState.GenState[types.ModuleName] = simState.Cdc.MustMarshalJSON(marketGenesis)
}