/
tx.go
213 lines (178 loc) · 5.4 KB
/
tx.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
package cli
// DONTCOVER
// client is excluded from test coverage in MVP version
import (
"fmt"
"strconv"
"strings"
"github.com/spf13/cobra"
"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/client/flags"
"github.com/cosmos/cosmos-sdk/client/tx"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/version"
"github.com/cosmos/cosmos-sdk/x/gov/client/cli"
gov "github.com/cosmos/cosmos-sdk/x/gov/types"
"github.com/cosmosquad-labs/squad/v3/x/marketmaker/types"
)
// GetTxCmd returns a root CLI command handler for all x/marketmaker transaction commands.
func GetTxCmd() *cobra.Command {
marketmakerTxCmd := &cobra.Command{
Use: types.ModuleName,
Short: "MarketMaker transaction subcommands",
DisableFlagParsing: true,
SuggestionsMinimumDistance: 2,
RunE: client.ValidateCmd,
}
marketmakerTxCmd.AddCommand(
NewApplyMarketMaker(),
NewClaimIncentives(),
)
return marketmakerTxCmd
}
// NewApplyMarketMaker implements apply market maker command handler.
func NewApplyMarketMaker() *cobra.Command {
cmd := &cobra.Command{
Use: "apply [pool-ids]",
Args: cobra.ExactArgs(1),
Short: "Apply to be a market maker",
Long: strings.TrimSpace(
fmt.Sprintf(`
Apply to be a market maker for a number of pairs. The deposit amount defined in params is required to deposit, and the amount is expected to be refunded when you are either included or rejected by the community (through a governance proposal).
Example:
$ %s tx %s apply 1 --from mykey
$ %s tx %s apply 1,2 --from mykey
`,
version.AppName, types.ModuleName,
version.AppName, types.ModuleName,
),
),
RunE: func(cmd *cobra.Command, args []string) error {
clientCtx, err := client.GetClientTxContext(cmd)
if err != nil {
return err
}
farmer := clientCtx.GetFromAddress()
pairIds := []uint64{}
pairIdsStr := strings.Split(args[0], ",")
for _, i := range pairIdsStr {
pairId, err := strconv.ParseUint(i, 10, 64)
if err != nil {
return fmt.Errorf("parse pair id: %w", err)
}
pairIds = append(pairIds, pairId)
}
msg := types.NewMsgApplyMarketMaker(farmer, pairIds)
return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), msg)
},
}
flags.AddTxFlagsToCmd(cmd)
return cmd
}
// NewClaimIncentives implements the remove plan handler.
func NewClaimIncentives() *cobra.Command {
cmd := &cobra.Command{
Use: "claim",
Args: cobra.ExactArgs(0),
Short: "Claim all claimable incentives",
Long: fmt.Sprintf(`
Claim all market making incentives distributed through governance
Example:
$ %s tx %s claim --from mykey`,
version.AppName, types.ModuleName,
),
RunE: func(cmd *cobra.Command, args []string) error {
clientCtx, err := client.GetClientTxContext(cmd)
if err != nil {
return err
}
creator := clientCtx.GetFromAddress()
msg := types.NewMsgClaimIncentives(creator)
return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), msg)
},
}
flags.AddTxFlagsToCmd(cmd)
return cmd
}
// GetCmdSubmitMarketMakerProposal implements the inclusion/exclusion/rejection/distribution for market maker command handler.
func GetCmdSubmitMarketMakerProposal() *cobra.Command {
cmd := &cobra.Command{
Use: "market-maker-proposal [proposal-file] [flags]",
Args: cobra.ExactArgs(1),
Short: "Submit a market maker proposal",
Long: strings.TrimSpace(
fmt.Sprintf(`Submit a market maker proposal along with an initial deposit. You can submit this governance proposal
to include, exclude, reject, and incentivize distribution for market makers. The proposal details must be supplied via a JSON file. A JSON file to add request proposal is
provided below.
Example:
$ %s tx gov submit-proposal market-maker-proposal <path/to/proposal.json> --from=<key_or_address> --deposit=<deposit_amount>
Where proposal.json contains:
{
"title": "Market Maker Proposal",
"description": "Include, reject, and incentivize market makers",
"inclusions": [
{
"address": "cosmos1vqac3p8fl4kez7ehjz8eltugd2fm67pckpl7pn",
"pair_id": "1"
}
],
"exclusions": [],
"rejections": [
{
"address": "cosmos1vqac3p8fl4kez7ehjz8eltugd2fm67pckpl7pn",
"pair_id": "2"
}
],
"distributions": [
{
"address": "cosmos1vqac3p8fl4kez7ehjz8eltugd2fm67pckpl7pn",
"pair_id": "1",
"amount": [
{
"denom": "stake",
"amount": "100000000"
}
]
}
]
}
`,
version.AppName,
),
),
RunE: func(cmd *cobra.Command, args []string) error {
clientCtx, err := client.GetClientTxContext(cmd)
if err != nil {
return err
}
depositStr, err := cmd.Flags().GetString(cli.FlagDeposit)
if err != nil {
return err
}
deposit, err := sdk.ParseCoinsNormalized(depositStr)
if err != nil {
return err
}
proposal, err := ParseMarketMakerProposal(clientCtx.Codec, args[0])
if err != nil {
return err
}
content := types.NewMarketMakerProposal(
proposal.Title,
proposal.Description,
proposal.Inclusions,
proposal.Exclusions,
proposal.Rejections,
proposal.Distributions,
)
from := clientCtx.GetFromAddress()
msg, err := gov.NewMsgSubmitProposal(content, deposit, from)
if err != nil {
return err
}
return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), msg)
},
}
cmd.Flags().String(cli.FlagDeposit, "", "deposit of proposal")
return cmd
}