/
msg.go
295 lines (244 loc) · 8.91 KB
/
msg.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
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
package types
import (
errorsmod "cosmossdk.io/errors"
sdk "github.com/cosmos/cosmos-sdk/types"
)
var (
_ sdk.Msg = &MsgSetHotRoutes{}
_ sdk.Msg = &MsgSetDeveloperAccount{}
_ sdk.Msg = &MsgSetMaxPoolPointsPerTx{}
_ sdk.Msg = &MsgSetMaxPoolPointsPerBlock{}
_ sdk.Msg = &MsgSetInfoByPoolType{}
_ sdk.Msg = &MsgSetBaseDenoms{}
)
const (
TypeMsgSetHotRoutes = "set_hot_routes"
TypeMsgSetDeveloperAccount = "set_developer_account"
TypeMsgSetMaxPoolPointsPerTx = "set_max_pool_points_per_tx"
TypeMsgSetMaxPoolPointsPerBlock = "set_max_pool_points_per_block"
TypeMsgSetPoolTypeInfo = "set_info_by_pool_type"
TypeMsgSetBaseDenoms = "set_base_denoms"
)
// ---------------------- Interface for MsgSetHotRoutes ---------------------- //
// NewMsgSetHotRoutes creates a new MsgSetHotRoutes instance
func NewMsgSetHotRoutes(admin string, tokenPairArbRoutes []TokenPairArbRoutes) *MsgSetHotRoutes {
return &MsgSetHotRoutes{
Admin: admin,
HotRoutes: tokenPairArbRoutes,
}
}
// Route returns the name of the module
func (msg MsgSetHotRoutes) Route() string {
return RouterKey
}
// Type returns the type of the message
func (msg MsgSetHotRoutes) Type() string {
return TypeMsgSetHotRoutes
}
// ValidateBasic validates the MsgSetHotRoutes
func (msg MsgSetHotRoutes) ValidateBasic() error {
// Account must be a valid bech32 address
if _, err := sdk.AccAddressFromBech32(msg.Admin); err != nil {
return errorsmod.Wrap(err, "invalid admin address (must be bech32)")
}
// Validate the hot routes
if err := ValidateTokenPairArbRoutes(msg.HotRoutes); err != nil {
return err
}
return nil
}
// GetSignBytes encodes the message for signing
func (msg MsgSetHotRoutes) GetSignBytes() []byte {
return sdk.MustSortJSON(ModuleCdc.MustMarshalJSON(&msg))
}
// GetSigners defines whose signature is required
func (msg MsgSetHotRoutes) GetSigners() []sdk.AccAddress {
addr := sdk.MustAccAddressFromBech32(msg.Admin)
return []sdk.AccAddress{addr}
}
// ---------------------- Interface for MsgSetDeveloperAccount ---------------------- //
// NewMsgSetDeveloperAccount creates a new MsgSetDeveloperAccount instance
func NewMsgSetDeveloperAccount(admin string, developerAccount string) *MsgSetDeveloperAccount {
return &MsgSetDeveloperAccount{
Admin: admin,
DeveloperAccount: developerAccount,
}
}
// Route returns the name of the module
func (msg MsgSetDeveloperAccount) Route() string {
return RouterKey
}
// Type returns the type of the message
func (msg MsgSetDeveloperAccount) Type() string {
return TypeMsgSetDeveloperAccount
}
// ValidateBasic validates the MsgSetDeveloperAccount
func (msg MsgSetDeveloperAccount) ValidateBasic() error {
// Account must be a valid bech32 address
_, err := sdk.AccAddressFromBech32(msg.Admin)
if err != nil {
return errorsmod.Wrap(err, "invalid admin address (must be bech32)")
}
// Account must be a valid bech32 address
_, err = sdk.AccAddressFromBech32(msg.DeveloperAccount)
if err != nil {
return errorsmod.Wrap(err, "invalid developer account address (must be bech32)")
}
return nil
}
// GetSignBytes encodes the message for signing
func (msg MsgSetDeveloperAccount) GetSignBytes() []byte {
return sdk.MustSortJSON(ModuleCdc.MustMarshalJSON(&msg))
}
// GetSigners defines whose signature is required
func (msg MsgSetDeveloperAccount) GetSigners() []sdk.AccAddress {
addr := sdk.MustAccAddressFromBech32(msg.Admin)
return []sdk.AccAddress{addr}
}
// ---------------------- Interface for MsgSetMaxPoolPointsPerTx ---------------------- //
// NewMsgSetMaxPoolPointsPerTx creates a new MsgSetMaxPoolPointsPerTx instance
func NewMsgSetMaxPoolPointsPerTx(admin string, maxPoolPointsPerTx uint64) *MsgSetMaxPoolPointsPerTx {
return &MsgSetMaxPoolPointsPerTx{
Admin: admin,
MaxPoolPointsPerTx: maxPoolPointsPerTx,
}
}
// Route returns the name of the module
func (msg MsgSetMaxPoolPointsPerTx) Route() string {
return RouterKey
}
// Type returns the type of the message
func (msg MsgSetMaxPoolPointsPerTx) Type() string {
return TypeMsgSetMaxPoolPointsPerTx
}
// ValidateBasic validates the MsgSetMaxPoolPointsPerTx
func (msg MsgSetMaxPoolPointsPerTx) ValidateBasic() error {
// Account must be a valid bech32 address
if _, err := sdk.AccAddressFromBech32(msg.Admin); err != nil {
return errorsmod.Wrap(err, "invalid admin address (must be bech32)")
}
// Max pool points per tx must be in the valid range
if err := ValidateMaxPoolPointsPerTx(msg.MaxPoolPointsPerTx); err != nil {
return err
}
return nil
}
// GetSignBytes encodes the message for signing
func (msg MsgSetMaxPoolPointsPerTx) GetSignBytes() []byte {
return sdk.MustSortJSON(ModuleCdc.MustMarshalJSON(&msg))
}
// GetSigners defines whose signature is required
func (msg MsgSetMaxPoolPointsPerTx) GetSigners() []sdk.AccAddress {
addr := sdk.MustAccAddressFromBech32(msg.Admin)
return []sdk.AccAddress{addr}
}
// ---------------------- Interface for MsgSetMaxPoolPointsPerBlock ---------------------- //
// NewMsgSetMaxPoolPointsPerBlock creates a new MsgSetMaxPoolPointsPerBlock instance
func NewMsgSetMaxPoolPointsPerBlock(admin string, maxPoolPointsPerBlock uint64) *MsgSetMaxPoolPointsPerBlock {
return &MsgSetMaxPoolPointsPerBlock{
Admin: admin,
MaxPoolPointsPerBlock: maxPoolPointsPerBlock,
}
}
// Route returns the name of the module
func (msg MsgSetMaxPoolPointsPerBlock) Route() string {
return RouterKey
}
// Type returns the type of the message
func (msg MsgSetMaxPoolPointsPerBlock) Type() string {
return TypeMsgSetMaxPoolPointsPerBlock
}
// ValidateBasic validates the MsgSetMaxPoolPointsPerBlock
func (msg MsgSetMaxPoolPointsPerBlock) ValidateBasic() error {
// Account must be a valid bech32 address
if _, err := sdk.AccAddressFromBech32(msg.Admin); err != nil {
return errorsmod.Wrap(err, "invalid admin address (must be bech32)")
}
// Max pool points per block must be in the valid range
if err := ValidateMaxPoolPointsPerBlock(msg.MaxPoolPointsPerBlock); err != nil {
return err
}
return nil
}
// GetSignBytes encodes the message for signing
func (msg MsgSetMaxPoolPointsPerBlock) GetSignBytes() []byte {
return sdk.MustSortJSON(ModuleCdc.MustMarshalJSON(&msg))
}
// GetSigners defines whose signature is required
func (msg MsgSetMaxPoolPointsPerBlock) GetSigners() []sdk.AccAddress {
addr := sdk.MustAccAddressFromBech32(msg.Admin)
return []sdk.AccAddress{addr}
}
// ---------------------- Interface for MsgSetInfoByPoolType ---------------------- //
// NewMsgSetPoolTypeInfo creates a new MsgSetInfoByPoolType instance
func NewMsgSetPoolTypeInfo(admin string, infoByPoolType InfoByPoolType) *MsgSetInfoByPoolType {
return &MsgSetInfoByPoolType{
Admin: admin,
InfoByPoolType: infoByPoolType,
}
}
// Route returns the name of the module
func (msg MsgSetInfoByPoolType) Route() string {
return RouterKey
}
// Type returns the type of the message
func (msg MsgSetInfoByPoolType) Type() string {
return TypeMsgSetPoolTypeInfo
}
// ValidateBasic validates the MsgSetInfoByPoolType
func (msg MsgSetInfoByPoolType) ValidateBasic() error {
// Account must be a valid bech32 address
if _, err := sdk.AccAddressFromBech32(msg.Admin); err != nil {
return errorsmod.Wrap(err, "invalid admin address (must be bech32)")
}
if err := msg.InfoByPoolType.Validate(); err != nil {
return err
}
return nil
}
// GetSignBytes encodes the message for signing
func (msg MsgSetInfoByPoolType) GetSignBytes() []byte {
return sdk.MustSortJSON(ModuleCdc.MustMarshalJSON(&msg))
}
// GetSigners defines whose signature is required
func (msg MsgSetInfoByPoolType) GetSigners() []sdk.AccAddress {
addr := sdk.MustAccAddressFromBech32(msg.Admin)
return []sdk.AccAddress{addr}
}
// ---------------------- Interface for MsgSetBaseDenoms ---------------------- //
// NewMsgSetBaseDenoms creates a new MsgSetBaseDenoms instance
func NewMsgSetBaseDenoms(admin string, baseDenoms []BaseDenom) *MsgSetBaseDenoms {
return &MsgSetBaseDenoms{
Admin: admin,
BaseDenoms: baseDenoms,
}
}
// Route returns the name of the module
func (msg MsgSetBaseDenoms) Route() string {
return RouterKey
}
// Type returns the type of the message
func (msg MsgSetBaseDenoms) Type() string {
return TypeMsgSetBaseDenoms
}
// ValidateBasic validates the MsgSetBaseDenoms
func (msg MsgSetBaseDenoms) ValidateBasic() error {
// Account must be a valid bech32 address
if _, err := sdk.AccAddressFromBech32(msg.Admin); err != nil {
return errorsmod.Wrap(err, "invalid admin address (must be bech32)")
}
// Check that there is at least one base denom and that first denom is osmo
if err := ValidateBaseDenoms(msg.BaseDenoms); err != nil {
return err
}
return nil
}
// GetSignBytes encodes the message for signing
func (msg MsgSetBaseDenoms) GetSignBytes() []byte {
return sdk.MustSortJSON(ModuleCdc.MustMarshalJSON(&msg))
}
// GetSigners defines whose signature is required
func (msg MsgSetBaseDenoms) GetSigners() []sdk.AccAddress {
addr := sdk.MustAccAddressFromBech32(msg.Admin)
return []sdk.AccAddress{addr}
}