-
Notifications
You must be signed in to change notification settings - Fork 55
/
proposals.go
51 lines (44 loc) 路 1.54 KB
/
proposals.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
package simulation
import (
"math/rand"
sdk "github.com/cosmos/cosmos-sdk/types"
simtypes "github.com/cosmos/cosmos-sdk/types/simulation"
"github.com/cosmos/cosmos-sdk/x/simulation"
"github.com/crescent-network/crescent/v5/x/exchange/keeper"
"github.com/crescent-network/crescent/v5/x/exchange/types"
)
const (
OpWeightSubmitMarketParameterChangeProposal = "op_weight_submit_market_parameter_change_proposal"
DefaultWeightMarketParameterChangeProposal = 5
)
// ProposalContents defines the module weighted proposals' contents
func ProposalContents(k keeper.Keeper) []simtypes.WeightedProposalContent {
return []simtypes.WeightedProposalContent{
simulation.NewWeightedProposalContent(
OpWeightSubmitMarketParameterChangeProposal,
DefaultWeightMarketParameterChangeProposal,
SimulateMarketParameterChangeProposal(k),
),
}
}
func SimulateMarketParameterChangeProposal(k keeper.Keeper) simtypes.ContentSimulatorFn {
return func(r *rand.Rand, ctx sdk.Context, accs []simtypes.Account) simtypes.Content {
var changes []types.MarketParameterChange
k.IterateAllMarkets(ctx, func(market types.Market) (stop bool) {
if r.Float64() <= 0.5 {
fees := GenFees(r)
changes = append(changes, types.NewMarketParameterChange(
market.Id, fees.DefaultMakerFeeRate, fees.DefaultTakerFeeRate, fees.DefaultOrderSourceFeeRatio))
}
return false
})
if len(changes) == 0 {
return nil
}
return types.NewMarketParameterChangeProposal(
simtypes.RandStringOfLength(r, 10),
simtypes.RandStringOfLength(r, 100),
changes,
)
}
}