-
Notifications
You must be signed in to change notification settings - Fork 590
/
gov.go
168 lines (135 loc) · 4.6 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
package types
import (
"fmt"
"strings"
gammtypes "github.com/osmosis-labs/osmosis/v25/x/gamm/types"
govtypesv1 "github.com/cosmos/cosmos-sdk/x/gov/types/v1beta1"
cltypes "github.com/osmosis-labs/osmosis/v25/x/concentrated-liquidity/types"
)
const (
ProposalTypeSetSuperfluidAssets = "SetSuperfluidAssets"
ProposalTypeRemoveSuperfluidAssets = "RemoveSuperfluidAssets"
ProposalTypeUpdateUnpoolWhitelist = "UpdateUnpoolWhitelist"
)
func init() {
govtypesv1.RegisterProposalType(ProposalTypeSetSuperfluidAssets)
govtypesv1.RegisterProposalType(ProposalTypeRemoveSuperfluidAssets)
govtypesv1.RegisterProposalType(ProposalTypeUpdateUnpoolWhitelist)
}
var (
_ govtypesv1.Content = &SetSuperfluidAssetsProposal{}
_ govtypesv1.Content = &RemoveSuperfluidAssetsProposal{}
_ govtypesv1.Content = &UpdateUnpoolWhiteListProposal{}
)
func NewSetSuperfluidAssetsProposal(title, description string, assets []SuperfluidAsset) govtypesv1.Content {
return &SetSuperfluidAssetsProposal{
Title: title,
Description: description,
Assets: assets,
}
}
func (p *SetSuperfluidAssetsProposal) GetTitle() string { return p.Title }
func (p *SetSuperfluidAssetsProposal) GetDescription() string { return p.Description }
func (p *SetSuperfluidAssetsProposal) ProposalRoute() string { return RouterKey }
func (p *SetSuperfluidAssetsProposal) ProposalType() string {
return ProposalTypeSetSuperfluidAssets
}
func (p *SetSuperfluidAssetsProposal) ValidateBasic() error {
err := govtypesv1.ValidateAbstract(p)
if err != nil {
return err
}
for _, asset := range p.Assets {
switch asset.AssetType {
case SuperfluidAssetTypeLPShare:
if _, err := gammtypes.GetPoolIdFromShareDenom(asset.Denom); err != nil {
return err
}
// Denom must be from GAMM
if !strings.HasPrefix(asset.Denom, gammtypes.GAMMTokenPrefix) {
return fmt.Errorf("denom %s must be from GAMM", asset.Denom)
}
case SuperfluidAssetTypeConcentratedShare:
if _, err := cltypes.GetPoolIdFromShareDenom(asset.Denom); err != nil {
return err
}
// Denom must be from CL
if !strings.HasPrefix(asset.Denom, cltypes.ConcentratedLiquidityTokenPrefix) {
return fmt.Errorf("denom %s must be from CL", asset.Denom)
}
default:
return fmt.Errorf("unsupported superfluid asset type")
}
}
return nil
}
func (p SetSuperfluidAssetsProposal) String() string {
return fmt.Sprintf(`Set Superfluid Assets Proposal:
Title: %s
Description: %s
Assets: %+v
`, p.Title, p.Description, p.Assets)
}
func NewRemoveSuperfluidAssetsProposal(title, description string, denoms []string) govtypesv1.Content {
return &RemoveSuperfluidAssetsProposal{
Title: title,
Description: description,
SuperfluidAssetDenoms: denoms,
}
}
func (p *RemoveSuperfluidAssetsProposal) GetTitle() string { return p.Title }
func (p *RemoveSuperfluidAssetsProposal) GetDescription() string { return p.Description }
func (p *RemoveSuperfluidAssetsProposal) ProposalRoute() string { return RouterKey }
func (p *RemoveSuperfluidAssetsProposal) ProposalType() string {
return ProposalTypeRemoveSuperfluidAssets
}
func (p *RemoveSuperfluidAssetsProposal) ValidateBasic() error {
err := govtypesv1.ValidateAbstract(p)
if err != nil {
return err
}
return nil
}
func (p RemoveSuperfluidAssetsProposal) String() string {
var b strings.Builder
b.WriteString(fmt.Sprintf(`Remove Superfluid Assets Proposal:
Title: %s
Description: %s
SuperfluidAssetDenoms: %+v
`, p.Title, p.Description, p.SuperfluidAssetDenoms))
return b.String()
}
func NewUpdateUnpoolWhitelistProposal(title, description string, poolIds []uint64, isOverwrite bool) govtypesv1.Content {
return &UpdateUnpoolWhiteListProposal{
Title: title,
Description: description,
Ids: poolIds,
IsOverwrite: isOverwrite,
}
}
func (p *UpdateUnpoolWhiteListProposal) GetTitle() string { return p.Title }
func (p *UpdateUnpoolWhiteListProposal) GetDescription() string { return p.Description }
func (p *UpdateUnpoolWhiteListProposal) ProposalRoute() string { return RouterKey }
func (p *UpdateUnpoolWhiteListProposal) ProposalType() string {
return ProposalTypeUpdateUnpoolWhitelist
}
func (p *UpdateUnpoolWhiteListProposal) ValidateBasic() error {
err := govtypesv1.ValidateAbstract(p)
if err != nil {
return err
}
for _, id := range p.Ids {
if id == 0 {
return fmt.Errorf("pool id cannot be 0")
}
}
return nil
}
func (p UpdateUnpoolWhiteListProposal) String() string {
return fmt.Sprintf(`Update Unpool Whitelist Assets Proposal:
Title: %s
Description: %s
Pool Ids: %+v
IsOverwrite: %t
`, p.Title, p.Description, p.Ids, p.IsOverwrite)
}