-
Notifications
You must be signed in to change notification settings - Fork 0
/
gov.go
271 lines (225 loc) · 9.63 KB
/
gov.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
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
package types
import (
"fmt"
"strings"
sdk "github.com/cosmos/cosmos-sdk/types"
govtypes "github.com/cosmos/cosmos-sdk/x/gov/types"
"github.com/osmosis-labs/osmosis/osmomath"
gammmigration "github.com/fury-labs/furya/v20/x/gamm/types/migration"
)
const (
ProposalTypeUpdateMigrationRecords = "UpdateMigrationRecords"
ProposalTypeReplaceMigrationRecords = "ReplaceMigrationRecords"
ProposalTypeCreateConcentratedLiquidityPoolAndLinktoCFMM = "CreateConcentratedLiquidityPoolAndLinktoCFMM"
ProposalTypeSetScalingFactorController = "SetScalingFactorController"
)
// Init registers proposals to update and replace migration records.
func init() {
govtypes.RegisterProposalType(ProposalTypeUpdateMigrationRecords)
govtypes.RegisterProposalTypeCodec(&UpdateMigrationRecordsProposal{}, "furya/UpdateMigrationRecordsProposal")
govtypes.RegisterProposalType(ProposalTypeReplaceMigrationRecords)
govtypes.RegisterProposalTypeCodec(&ReplaceMigrationRecordsProposal{}, "furya/ReplaceMigrationRecordsProposal")
govtypes.RegisterProposalType(ProposalTypeCreateConcentratedLiquidityPoolAndLinktoCFMM)
govtypes.RegisterProposalTypeCodec(&CreateConcentratedLiquidityPoolsAndLinktoCFMMProposal{}, "furya/CreateConcentratedLiquidityPoolsAndLinktoCFMMProposal")
govtypes.RegisterProposalType(ProposalTypeSetScalingFactorController)
govtypes.RegisterProposalTypeCodec(&SetScalingFactorControllerProposal{}, "furya/SetScalingFactorControllerProposal")
}
var (
_ govtypes.Content = &UpdateMigrationRecordsProposal{}
_ govtypes.Content = &ReplaceMigrationRecordsProposal{}
_ govtypes.Content = &CreateConcentratedLiquidityPoolsAndLinktoCFMMProposal{}
_ govtypes.Content = &SetScalingFactorControllerProposal{}
)
// NewReplacePoolIncentivesProposal returns a new instance of a replace migration record's proposal struct.
func NewReplaceMigrationRecordsProposal(title, description string, records []gammmigration.BalancerToConcentratedPoolLink) govtypes.Content {
return &ReplaceMigrationRecordsProposal{
Title: title,
Description: description,
Records: records,
}
}
// GetTitle gets the title of the proposal
func (p *ReplaceMigrationRecordsProposal) GetTitle() string { return p.Title }
// GetDescription gets the description of the proposal
func (p *ReplaceMigrationRecordsProposal) GetDescription() string { return p.Description }
// ProposalRoute returns the router key for the proposal
func (p *ReplaceMigrationRecordsProposal) ProposalRoute() string { return RouterKey }
// ProposalType returns the type of the proposal
func (p *ReplaceMigrationRecordsProposal) ProposalType() string {
return ProposalTypeReplaceMigrationRecords
}
// ValidateBasic validates a governance proposal's abstract and basic contents
func (p *ReplaceMigrationRecordsProposal) ValidateBasic() error {
err := govtypes.ValidateAbstract(p)
if err != nil {
return err
}
if len(p.Records) == 0 {
return fmt.Errorf("empty proposal records")
}
return nil
}
// String returns a string containing the migration record's proposal.
func (p ReplaceMigrationRecordsProposal) String() string {
recordsStr := ""
for _, record := range p.Records {
recordsStr = recordsStr + fmt.Sprintf("(BalancerPoolID: %d, ClPoolID: %d) ", record.BalancerPoolId, record.ClPoolId)
}
var b strings.Builder
b.WriteString(fmt.Sprintf(`Replace Migration Records Proposal:
Title: %s
Description: %s
Records: %s
`, p.Title, p.Description, recordsStr))
return b.String()
}
// NewReplacePoolIncentivesProposal returns a new instance of a replace migration record's proposal struct.
func NewUpdatePoolIncentivesProposal(title, description string, records []gammmigration.BalancerToConcentratedPoolLink) govtypes.Content {
return &UpdateMigrationRecordsProposal{
Title: title,
Description: description,
Records: records,
}
}
// GetTitle gets the title of the proposal
func (p *UpdateMigrationRecordsProposal) GetTitle() string { return p.Title }
// GetDescription gets the description of the proposal
func (p *UpdateMigrationRecordsProposal) GetDescription() string { return p.Description }
// ProposalRoute returns the router key for the proposal
func (p *UpdateMigrationRecordsProposal) ProposalRoute() string { return RouterKey }
// ProposalType returns the type of the proposal
func (p *UpdateMigrationRecordsProposal) ProposalType() string {
return ProposalTypeUpdateMigrationRecords
}
// ValidateBasic validates a governance proposal's abstract and basic contents.
func (p *UpdateMigrationRecordsProposal) ValidateBasic() error {
err := govtypes.ValidateAbstract(p)
if err != nil {
return err
}
if len(p.Records) == 0 {
return fmt.Errorf("empty proposal records")
}
return nil
}
// String returns a string containing the migration record's proposal.
func (p UpdateMigrationRecordsProposal) String() string {
// TODO: Make this prettier
recordsStr := ""
for _, record := range p.Records {
recordsStr = recordsStr + fmt.Sprintf("(BalancerPoolID: %d, ClPoolID: %d) ", record.BalancerPoolId, record.ClPoolId)
}
var b strings.Builder
b.WriteString(fmt.Sprintf(`Update Migration Records Proposal:
Title: %s
Description: %s
Records: %s
`, p.Title, p.Description, recordsStr))
return b.String()
}
func NewCreateConcentratedLiquidityPoolsAndLinktoCFMMProposal(title, description string, records []PoolRecordWithCFMMLink) govtypes.Content {
return &CreateConcentratedLiquidityPoolsAndLinktoCFMMProposal{
Title: title,
Description: description,
PoolRecordsWithCfmmLink: records,
}
}
// GetTitle gets the title of the proposal
func (p *CreateConcentratedLiquidityPoolsAndLinktoCFMMProposal) GetTitle() string { return p.Title }
// GetDescription gets the description of the proposal
func (p *CreateConcentratedLiquidityPoolsAndLinktoCFMMProposal) GetDescription() string {
return p.Description
}
// ProposalRoute returns the router key for the proposal
func (p *CreateConcentratedLiquidityPoolsAndLinktoCFMMProposal) ProposalRoute() string {
return RouterKey
}
// ProposalType returns the type of the proposal
func (p *CreateConcentratedLiquidityPoolsAndLinktoCFMMProposal) ProposalType() string {
return ProposalTypeCreateConcentratedLiquidityPoolAndLinktoCFMM
}
// ValidateBasic validates a governance proposal's abstract and basic contents.
func (p *CreateConcentratedLiquidityPoolsAndLinktoCFMMProposal) ValidateBasic() error {
err := govtypes.ValidateAbstract(p)
if err != nil {
return err
}
for _, record := range p.PoolRecordsWithCfmmLink {
if record.TickSpacing <= 0 {
return fmt.Errorf("tick spacing must be positive")
}
if record.Denom0 == record.Denom1 {
return fmt.Errorf("denom0 and denom1 must be different")
}
if sdk.ValidateDenom(record.Denom0) != nil {
return fmt.Errorf("denom0 is invalid: %s", sdk.ValidateDenom(record.Denom0))
}
if sdk.ValidateDenom(record.Denom1) != nil {
return fmt.Errorf("denom1 is invalid: %s", sdk.ValidateDenom(record.Denom1))
}
spreadFactor := record.SpreadFactor
if spreadFactor.IsNegative() || spreadFactor.GTE(osmomath.OneDec()) {
return fmt.Errorf("Invalid Spread factor")
}
if record.BalancerPoolId <= 0 {
return fmt.Errorf("Invalid Balancer Pool Id")
}
}
return nil
}
// String returns a string containing creating CL pool and linking it to an existing CFMM pool.
func (p CreateConcentratedLiquidityPoolsAndLinktoCFMMProposal) String() string {
recordsStr := ""
for _, record := range p.PoolRecordsWithCfmmLink {
recordsStr = recordsStr + fmt.Sprintf("(Denom0: %s, Denom1: %s, TickSpacing: %d, ExponentAtPriceOne: %d, SpreadFactor: %d, BalancerPoolId: %d) ", record.Denom0, record.Denom1, record.TickSpacing, record.ExponentAtPriceOne, record.SpreadFactor, record.BalancerPoolId)
}
var b strings.Builder
b.WriteString(fmt.Sprintf(`Create Concentrated Liquidity Pool Proposal:
Title: %s
Description: %s
Records: %s
`, p.Title, p.Description, recordsStr))
return b.String()
}
// NewSetScalingFactorControllerProposal returns a new instance of a replace migration record's proposal struct.
func NewSetScalingFactorControllerProposal(title, description string, poolId uint64, controllerAddress string) govtypes.Content {
return &SetScalingFactorControllerProposal{
Title: title,
Description: description,
PoolId: poolId,
ControllerAddress: controllerAddress,
}
}
// GetTitle gets the title of the proposal
func (p *SetScalingFactorControllerProposal) GetTitle() string { return p.Title }
// GetDescription gets the description of the proposal
func (p *SetScalingFactorControllerProposal) GetDescription() string { return p.Description }
// ProposalRoute returns the router key for the proposal
func (p *SetScalingFactorControllerProposal) ProposalRoute() string { return RouterKey }
// ProposalType returns the type of the proposal
func (p *SetScalingFactorControllerProposal) ProposalType() string {
return ProposalTypeReplaceMigrationRecords
}
// ValidateBasic validates a governance proposal's abstract and basic contents
func (p *SetScalingFactorControllerProposal) ValidateBasic() error {
err := govtypes.ValidateAbstract(p)
if err != nil {
return err
}
_, err = sdk.AccAddressFromBech32(p.ControllerAddress)
if err != nil {
return fmt.Errorf("Invalid controller address (%s)", err)
}
return nil
}
// String returns a string containing the migration record's proposal.
func (p SetScalingFactorControllerProposal) String() string {
var b strings.Builder
b.WriteString(fmt.Sprintf(`Set Scaling Factor Controller Address Proposal:
Title: %s
Description: %s
PoolId: %d
ControllerAddress: %s
`, p.Title, p.Description, p.PoolId, p.ControllerAddress))
return b.String()
}