forked from neutron-org/neutron
-
Notifications
You must be signed in to change notification settings - Fork 0
/
tx_deposit.go
122 lines (100 loc) · 2.97 KB
/
tx_deposit.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
package cli
import (
"log"
"strconv"
"strings"
sdkerrors "cosmossdk.io/errors"
"cosmossdk.io/math"
"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/client/flags"
"github.com/cosmos/cosmos-sdk/client/tx"
"github.com/spf13/cobra"
"github.com/MonikaCat/neutron/v2/x/dex/types"
)
func CmdDeposit() *cobra.Command {
cmd := &cobra.Command{
//nolint:lll
Use: "deposit [receiver] [token-a] [token-b] [list of amount-0] [list of amount-1] [list of tick-index] [list of fees] [disable_autoswap]",
Short: "Broadcast message deposit",
Example: "deposit alice tokenA tokenB 100,0 0,50 [-10,5] 1,1 false,false --from alice",
Args: cobra.ExactArgs(8),
RunE: func(cmd *cobra.Command, args []string) (err error) {
argReceiver := args[0]
argTokenA := args[1]
argTokenB := args[2]
argAmountsA := strings.Split(args[3], ",")
argAmountsB := strings.Split(args[4], ",")
if args[5] == "-" {
log.Printf("\"this is a test\": %v\n", "this is a test")
}
if strings.HasPrefix(args[5], "[") && strings.HasSuffix(args[5], "]") {
args[5] = strings.TrimPrefix(args[5], "[")
args[5] = strings.TrimSuffix(args[5], "]")
}
argTicksIndexes := strings.Split(args[5], ",")
argFees := strings.Split(args[6], ",")
argDepositOptions := strings.Split(args[7], ",")
var AmountsA []math.Int
var AmountsB []math.Int
var TicksIndexesInt []int64
var FeesUint []uint64
var DepositOptions []*types.DepositOptions
for _, s := range argAmountsA {
amountA, ok := math.NewIntFromString(s)
if !ok {
return sdkerrors.Wrapf(types.ErrIntOverflowTx, "Integer overflow for amountsA")
}
AmountsA = append(AmountsA, amountA)
}
for _, s := range argAmountsB {
amountB, ok := math.NewIntFromString(s)
if !ok {
return sdkerrors.Wrapf(types.ErrIntOverflowTx, "Integer overflow for amountsB")
}
AmountsB = append(AmountsB, amountB)
}
for _, s := range argTicksIndexes {
TickIndexInt, err := strconv.ParseInt(s, 10, 0)
if err != nil {
return err
}
TicksIndexesInt = append(TicksIndexesInt, TickIndexInt)
}
for _, s := range argFees {
FeeInt, err := strconv.ParseUint(s, 10, 0)
if err != nil {
return err
}
FeesUint = append(FeesUint, FeeInt)
}
for _, s := range argDepositOptions {
disableAutoswap, err := strconv.ParseBool(s)
if err != nil {
return err
}
DepositOptions = append(DepositOptions, &types.DepositOptions{DisableAutoswap: disableAutoswap})
}
clientCtx, err := client.GetClientTxContext(cmd)
if err != nil {
return err
}
msg := types.NewMsgDeposit(
clientCtx.GetFromAddress().String(),
argReceiver,
argTokenA,
argTokenB,
AmountsA,
AmountsB,
TicksIndexesInt,
FeesUint,
DepositOptions,
)
if err := msg.ValidateBasic(); err != nil {
return err
}
return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), msg)
},
}
flags.AddTxFlagsToCmd(cmd)
return cmd
}