-
Notifications
You must be signed in to change notification settings - Fork 74
/
module_simulation.go
169 lines (146 loc) · 5.09 KB
/
module_simulation.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
package dex
import (
"math/rand"
"github.com/cosmos/cosmos-sdk/baseapp"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/module"
simtypes "github.com/cosmos/cosmos-sdk/types/simulation"
"github.com/cosmos/cosmos-sdk/x/simulation"
"github.com/neutron-org/neutron/v2/testutil/common/sample"
dexsimulation "github.com/neutron-org/neutron/v2/x/dex/simulation"
"github.com/neutron-org/neutron/v2/x/dex/types"
)
// avoid unused import issue
var (
_ = sample.AccAddress
_ = dexsimulation.FindAccount
_ = simulation.MsgEntryKind
_ = baseapp.Paramspace
)
//nolint:gosec // false positive
const (
opWeightMsgDeposit = "op_weight_msg_deposit"
// TODO: Determine the simulation weight value
defaultWeightMsgDeposit int = 100
opWeightMsgWithdrawal = "op_weight_msg_withdrawal"
// TODO: Determine the simulation weight value
defaultWeightMsgWithdrawal int = 100
opWeightMsgPlaceLimitOrder = "op_weight_msg_place_limit_order"
// TODO: Determine the simulation weight value
defaultWeightMsgPlaceLimitOrder int = 100
opWeightMsgWithdrawFilledLimitOrder = "op_weight_msg_withdrawal_withdrawn_limit_order"
// TODO: Determine the simulation weight value
defaultWeightMsgWithdrawFilledLimitOrder int = 100
opWeightMsgCancelLimitOrder = "op_weight_msg_cancel_limit_order"
// TODO: Determine the simulation weight value
defaultWeightMsgCancelLimitOrder int = 100
opWeightMsgMultiHopSwap = "op_weight_msg_multi_hop_swap"
// TODO: Determine the simulation weight value
defaultWeightMsgMultiHopSwap int = 100
// this line is used by starport scaffolding # simapp/module/const
)
// GenerateGenesisState creates a randomized GenState of the module
func (AppModule) GenerateGenesisState(simState *module.SimulationState) {
accs := make([]string, len(simState.Accounts))
for i, acc := range simState.Accounts {
accs[i] = acc.Address.String()
}
dexGenesis := types.GenesisState{
Params: types.DefaultParams(),
// this line is used by starport scaffolding # simapp/module/genesisState
}
simState.GenState[types.ModuleName] = simState.Cdc.MustMarshalJSON(&dexGenesis)
}
// ProposalContents doesn't return any content functions for governance proposals
func (AppModule) ProposalContents(_ module.SimulationState) []simtypes.WeightedProposalMsg {
return nil
}
// RegisterStoreDecoder registers a decoder
func (am AppModule) RegisterStoreDecoder(_ sdk.StoreDecoderRegistry) {}
// WeightedOperations returns the all the gov module operations with their respective weights.
func (am AppModule) WeightedOperations(
simState module.SimulationState,
) []simtypes.WeightedOperation {
operations := make([]simtypes.WeightedOperation, 0)
var weightMsgDeposit int
simState.AppParams.GetOrGenerate(simState.Cdc, opWeightMsgDeposit, &weightMsgDeposit, nil,
func(_ *rand.Rand) {
weightMsgDeposit = defaultWeightMsgDeposit
},
)
operations = append(operations, simulation.NewWeightedOperation(
weightMsgDeposit,
dexsimulation.SimulateMsgDeposit(am.bankKeeper, am.keeper),
))
var weightMsgWithdrawal int
simState.AppParams.GetOrGenerate(simState.Cdc, opWeightMsgWithdrawal, &weightMsgWithdrawal, nil,
func(_ *rand.Rand) {
weightMsgWithdrawal = defaultWeightMsgWithdrawal
},
)
operations = append(operations, simulation.NewWeightedOperation(
weightMsgWithdrawal,
dexsimulation.SimulateMsgWithdrawal(am.bankKeeper, am.keeper),
))
var weightMsgPlaceLimitOrder int
simState.AppParams.GetOrGenerate(
simState.Cdc,
opWeightMsgPlaceLimitOrder,
&weightMsgPlaceLimitOrder,
nil,
func(_ *rand.Rand) {
weightMsgPlaceLimitOrder = defaultWeightMsgPlaceLimitOrder
},
)
operations = append(operations, simulation.NewWeightedOperation(
weightMsgPlaceLimitOrder,
dexsimulation.SimulateMsgPlaceLimitOrder(am.bankKeeper, am.keeper),
))
var weightMsgWithdrawFilledLimitOrder int
simState.AppParams.GetOrGenerate(
simState.Cdc,
opWeightMsgWithdrawFilledLimitOrder,
&weightMsgWithdrawFilledLimitOrder,
nil,
func(_ *rand.Rand) {
weightMsgWithdrawFilledLimitOrder = defaultWeightMsgWithdrawFilledLimitOrder
},
)
operations = append(operations, simulation.NewWeightedOperation(
weightMsgWithdrawFilledLimitOrder,
dexsimulation.SimulateMsgWithdrawFilledLimitOrder(
am.bankKeeper,
am.keeper,
),
))
var weightMsgCancelLimitOrder int
simState.AppParams.GetOrGenerate(
simState.Cdc,
opWeightMsgCancelLimitOrder,
&weightMsgCancelLimitOrder,
nil,
func(_ *rand.Rand) {
weightMsgCancelLimitOrder = defaultWeightMsgCancelLimitOrder
},
)
operations = append(operations, simulation.NewWeightedOperation(
weightMsgCancelLimitOrder,
dexsimulation.SimulateMsgCancelLimitOrder(am.bankKeeper, am.keeper),
))
var weightMsgMultiHopSwap int
simState.AppParams.GetOrGenerate(
simState.Cdc,
opWeightMsgMultiHopSwap,
&weightMsgMultiHopSwap,
nil,
func(_ *rand.Rand) {
weightMsgMultiHopSwap = defaultWeightMsgMultiHopSwap
},
)
operations = append(operations, simulation.NewWeightedOperation(
weightMsgMultiHopSwap,
dexsimulation.SimulateMsgMultiHopSwap(am.bankKeeper, am.keeper),
))
// this line is used by starport scaffolding # simapp/module/operation
return operations
}