Skip to content

Commit

Permalink
add recipient flag on cli commands
Browse files Browse the repository at this point in the history
  • Loading branch information
jelysn committed Nov 27, 2023
1 parent ee10806 commit 79a4fb2
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 12 deletions.
1 change: 1 addition & 0 deletions x/amm/client/cli/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ var (

const (
FlagDiscount = "discount"
FlagRecipient = "recipient"
flagPacketTimeoutTimestamp = "packet-timeout-timestamp"
listSeparator = ","
)
Expand Down
13 changes: 9 additions & 4 deletions x/amm/client/cli/tx_swap_by_denom.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,17 @@ const (

func CmdSwapByDenom() *cobra.Command {
cmd := &cobra.Command{
Use: "swap-by-denom [amount] [denom-in] [denom-out] [recipient]",
Use: "swap-by-denom [amount] [denom-in] [denom-out]",
Short: "Swap an exact amount of tokens for a minimum of another token or a maximum amount of tokens for an exact amount on another token, similar to swapping a token on the trade screen GUI.",
Example: "elysd tx amm swap-by-denom 1000000000uatom uatom uusd --min-amount=1000000000uatom --max-amount=1000000000uatom --discount=0.1 --from jack --keyring-backend test",
Args: cobra.ExactArgs(4),
Args: cobra.ExactArgs(3),
RunE: func(cmd *cobra.Command, args []string) (err error) {
argAmount, err := sdk.ParseCoinNormalized(args[0])
if err != nil {
return err
}
argDenomIn := args[1]
argDenomOut := args[2]
argRecipient := args[3]

minAmountStr, err := cmd.Flags().GetString(FlagMinAmount)
if err != nil {
Expand Down Expand Up @@ -66,14 +65,19 @@ func CmdSwapByDenom() *cobra.Command {
return err
}

recipient, err := cmd.Flags().GetString(FlagRecipient)
if err != nil {
return err
}

clientCtx, err := client.GetClientTxContext(cmd)
if err != nil {
return err
}

msg := types.NewMsgSwapByDenom(
clientCtx.GetFromAddress().String(),
argRecipient,
recipient,
argAmount,
minAmount,
maxAmount,
Expand All @@ -93,6 +97,7 @@ func CmdSwapByDenom() *cobra.Command {
cmd.Flags().String(FlagMinAmount, "", "minimum amount of tokens to receive")
cmd.Flags().String(FlagMaxAmount, "", "maximum amount of tokens to send")
cmd.Flags().String(FlagDiscount, "0.0", "discount to apply to the swap fee (only smart contract broker can apply the discount)")
cmd.Flags().String(FlagRecipient, "", "optional recipient field for the tokens swapped to be sent to")

return cmd
}
12 changes: 8 additions & 4 deletions x/amm/client/cli/tx_swap_exact_amount_in.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@ var _ = strconv.Itoa(0)

func CmdSwapExactAmountIn() *cobra.Command {
cmd := &cobra.Command{
Use: "swap-exact-amount-in [token-in] [token-out-min-amount] [swap-route-pool-ids] [swap-route-denoms] [recipient]",
Use: "swap-exact-amount-in [token-in] [token-out-min-amount] [swap-route-pool-ids] [swap-route-denoms]",
Short: "Swap an exact amount of tokens for a minimum of another token, similar to swapping a token on the trade screen GUI.",
Example: `elysd tx amm swap-exact-amount-in 100000uusdc 10000 0 uatom --from=treasury --keyring-backend=test --chain-id=elystestnet-1 --yes --gas=1000000`,
Args: cobra.ExactArgs(5),
Args: cobra.ExactArgs(4),
RunE: func(cmd *cobra.Command, args []string) (err error) {
argTokenIn, err := sdk.ParseCoinNormalized(args[0])
if err != nil {
Expand Down Expand Up @@ -53,7 +53,10 @@ func CmdSwapExactAmountIn() *cobra.Command {
return err
}

argRecipient := args[4]
recipient, err := cmd.Flags().GetString(FlagRecipient)
if err != nil {
return err
}

clientCtx, err := client.GetClientTxContext(cmd)
if err != nil {
Expand All @@ -62,7 +65,7 @@ func CmdSwapExactAmountIn() *cobra.Command {

msg := types.NewMsgSwapExactAmountIn(
clientCtx.GetFromAddress().String(),
argRecipient,
recipient,
argTokenIn,
argTokenOutMinAmount,
argSwapRoutePoolIds,
Expand All @@ -79,6 +82,7 @@ func CmdSwapExactAmountIn() *cobra.Command {
flags.AddTxFlagsToCmd(cmd)

cmd.Flags().String(FlagDiscount, "0.0", "discount to apply to the swap fee (only smart contract broker can apply the discount)")
cmd.Flags().String(FlagRecipient, "", "optional recipient field for the tokens swapped to be sent to")

return cmd
}
12 changes: 8 additions & 4 deletions x/amm/client/cli/tx_swap_exact_amount_out.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@ var _ = strconv.Itoa(0)

func CmdSwapExactAmountOut() *cobra.Command {
cmd := &cobra.Command{
Use: "swap-exact-amount-out [token-out] [token-out-max-amount] [swap-route-pool-ids] [swap-route-denoms] [recipient]",
Use: "swap-exact-amount-out [token-out] [token-out-max-amount] [swap-route-pool-ids] [swap-route-denoms]",
Short: "Swap a maximum amount of tokens for an exact amount of another token, similar to swapping a token on the trade screen GUI.",
Example: `elysd tx amm swap-exact-amount-out 100000uatom 200000 0 uusdc --from=treasury --keyring-backend=test --chain-id=elystestnet-1 --yes --gas=1000000`,
Args: cobra.ExactArgs(5),
Args: cobra.ExactArgs(4),
RunE: func(cmd *cobra.Command, args []string) (err error) {
argTokenOut, err := sdk.ParseCoinNormalized(args[0])
if err != nil {
Expand Down Expand Up @@ -53,7 +53,10 @@ func CmdSwapExactAmountOut() *cobra.Command {
return err
}

argRecipient := args[4]
recipient, err := cmd.Flags().GetString(FlagRecipient)
if err != nil {
return err
}

clientCtx, err := client.GetClientTxContext(cmd)
if err != nil {
Expand All @@ -62,7 +65,7 @@ func CmdSwapExactAmountOut() *cobra.Command {

msg := types.NewMsgSwapExactAmountOut(
clientCtx.GetFromAddress().String(),
argRecipient,
recipient,
argTokenOut,
argTokenOutMaxAmount,
argSwapRoutePoolIds,
Expand All @@ -79,6 +82,7 @@ func CmdSwapExactAmountOut() *cobra.Command {
flags.AddTxFlagsToCmd(cmd)

cmd.Flags().String(FlagDiscount, "0.0", "discount to apply to the swap fee (only smart contract broker can apply the discount)")
cmd.Flags().String(FlagRecipient, "", "optional recipient field for the tokens swapped to be sent to")

return cmd
}

0 comments on commit 79a4fb2

Please sign in to comment.