-
Notifications
You must be signed in to change notification settings - Fork 3
/
proposals.go
156 lines (136 loc) · 4.98 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
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
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/cosmosquad-labs/squad/v3/app/params"
"github.com/cosmosquad-labs/squad/v3/x/marketmaker/keeper"
"github.com/cosmosquad-labs/squad/v3/x/marketmaker/types"
minttypes "github.com/cosmosquad-labs/squad/v3/x/mint/types"
)
// Simulation operation weights constants.
const (
OpWeightSimulateMarketMakerProposal = "op_weight_market_maker_proposal"
OpWeightSimulateChangeIncentivePairsProposal = "op_weight_change_incentive_pairs_proposal"
OpWeightSimulateChangeDepositAmountProposal = "op_weight_change_deposit_amount_proposal"
)
// ProposalContents defines the module weighted proposals' contents
func ProposalContents(bk types.BankKeeper, k keeper.Keeper) []simtypes.WeightedProposalContent {
return []simtypes.WeightedProposalContent{
simulation.NewWeightedProposalContent(
OpWeightSimulateMarketMakerProposal,
params.DefaultWeightMarketMakerProposal,
SimulateMarketMakerProposal(bk, k),
),
simulation.NewWeightedProposalContent(
OpWeightSimulateChangeIncentivePairsProposal,
params.DefaultWeightChangeIncentivePairs,
SimulateChangeIncentivePairs(k),
),
simulation.NewWeightedProposalContent(
OpWeightSimulateChangeDepositAmountProposal,
params.DefaultWeightChangeDepositAmount,
SimulateChangeDepositAmount(k),
),
}
}
// SimulateMarketMakerProposal generates random market maker proposal content.
func SimulateMarketMakerProposal(bk types.BankKeeper, k keeper.Keeper) simtypes.ContentSimulatorFn {
return func(r *rand.Rand, ctx sdk.Context, accs []simtypes.Account) simtypes.Content {
params := k.GetParams(ctx)
_, err := fundBalances(ctx, r, bk, params.IncentiveBudgetAcc(), []string{"stake"})
if err != nil {
panic(err)
}
spendableIncentives := bk.SpendableCoins(ctx, params.IncentiveBudgetAcc())
inclusions := []types.MarketMakerHandle{}
distributions := []types.IncentiveDistribution{}
exclusions := []types.MarketMakerHandle{}
rejections := []types.MarketMakerHandle{}
mms := k.GetAllMarketMakers(ctx)
for _, mm := range mms {
if !mm.Eligible {
// inclusion
if simtypes.RandIntBetween(r, 0, 2) == 1 {
inclusions = append(inclusions, types.MarketMakerHandle{
Address: mm.Address,
PairId: mm.PairId,
})
} else {
// rejection
rejections = append(rejections, types.MarketMakerHandle{
Address: mm.Address,
PairId: mm.PairId,
})
}
}
// distribution
if mm.Eligible && simtypes.RandIntBetween(r, 0, 3) == 1 {
incentive := sdk.NewCoins(sdk.NewCoin("stake", spendableIncentives.AmountOf("stake").QuoRaw(1000)))
distributions = append(distributions, types.IncentiveDistribution{
Address: mm.Address,
PairId: mm.PairId,
Amount: incentive,
})
spendableIncentives = spendableIncentives.Sub(incentive)
}
// exclusion
if mm.Eligible && simtypes.RandIntBetween(r, 0, 7) == 1 {
exclusions = append(exclusions, types.MarketMakerHandle{
Address: mm.Address,
PairId: mm.PairId,
})
}
}
if len(inclusions) == 0 && len(exclusions) == 0 && len(rejections) == 0 && len(distributions) == 0 {
return nil
}
proposal := types.NewMarketMakerProposal(
simtypes.RandStringOfLength(r, 10),
simtypes.RandStringOfLength(r, 100),
inclusions,
exclusions,
rejections,
distributions,
)
// force execute proposal to avoid waiting voting period
err = keeper.HandleMarketMakerProposal(ctx, k, proposal)
if err != nil {
panic(err)
}
return nil
}
}
// SimulateChangeIncentivePairs generates random incentive pairs param change proposal content.
func SimulateChangeIncentivePairs(k keeper.Keeper) simtypes.ContentSimulatorFn {
return func(r *rand.Rand, ctx sdk.Context, accs []simtypes.Account) simtypes.Content {
params := k.GetParams(ctx)
params.IncentivePairs = GenIncentivePairs(r)
k.SetParams(ctx, params)
return nil
}
}
// SimulateChangeDepositAmount generates random deposit amount param change proposal content.
func SimulateChangeDepositAmount(k keeper.Keeper) simtypes.ContentSimulatorFn {
return func(r *rand.Rand, ctx sdk.Context, accs []simtypes.Account) simtypes.Content {
params := k.GetParams(ctx)
params.DepositAmount = GenDepositAmount(r)
k.SetParams(ctx, params)
return nil
}
}
// fundBalances mints random amount of coins with the provided coin denoms and
// send them to the simulated account.
func fundBalances(ctx sdk.Context, r *rand.Rand, bk types.BankKeeper, acc sdk.AccAddress, denoms []string) (mintCoins sdk.Coins, err error) {
for _, denom := range denoms {
mintCoins = mintCoins.Add(sdk.NewInt64Coin(denom, int64(simtypes.RandIntBetween(r, 1e14, 1e15))))
}
if err := bk.MintCoins(ctx, minttypes.ModuleName, mintCoins); err != nil {
return nil, err
}
if err := bk.SendCoinsFromModuleToAccount(ctx, minttypes.ModuleName, acc, mintCoins); err != nil {
return nil, err
}
return mintCoins, nil
}