Skip to content

Commit

Permalink
add recipient on SwapByDenom
Browse files Browse the repository at this point in the history
  • Loading branch information
jelysn committed Nov 27, 2023
1 parent 7ed25d5 commit ee10806
Show file tree
Hide file tree
Showing 5 changed files with 138 additions and 82 deletions.
1 change: 1 addition & 0 deletions proto/elys/amm/tx.proto
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ message MsgSwapByDenom {
string denom_in = 5;
string denom_out = 6;
string discount = 7 [(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec", (gogoproto.nullable) = false];
string recipient = 8;
}

message MsgSwapByDenomResponse {
Expand Down
6 changes: 4 additions & 2 deletions x/amm/client/cli/tx_swap_by_denom.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,18 @@ const (

func CmdSwapByDenom() *cobra.Command {
cmd := &cobra.Command{
Use: "swap-by-denom [amount] [denom-in] [denom-out]",
Use: "swap-by-denom [amount] [denom-in] [denom-out] [recipient]",
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(3),
Args: cobra.ExactArgs(4),
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 @@ -72,6 +73,7 @@ func CmdSwapByDenom() *cobra.Command {

msg := types.NewMsgSwapByDenom(
clientCtx.GetFromAddress().String(),
argRecipient,
argAmount,
minAmount,
maxAmount,
Expand Down
5 changes: 3 additions & 2 deletions x/amm/keeper/msg_server_swap_by_denom.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,10 @@ func (k msgServer) SwapByDenom(goCtx context.Context, msg *types.MsgSwapByDenom)
}

res, err := k.SwapExactAmountIn(
ctx,
sdk.WrapSDKContext(ctx),
&types.MsgSwapExactAmountIn{
Sender: msg.Sender,
Recipient: msg.Recipient,
Routes: route,
TokenIn: msg.Amount,
TokenOutMinAmount: msg.MinAmount.Amount,
Expand Down Expand Up @@ -79,7 +80,7 @@ func (k msgServer) SwapByDenom(goCtx context.Context, msg *types.MsgSwapByDenom)
}

res, err := k.SwapExactAmountOut(
ctx,
sdk.WrapSDKContext(ctx),
&types.MsgSwapExactAmountOut{
Sender: msg.Sender,
Routes: route,
Expand Down
3 changes: 2 additions & 1 deletion x/amm/types/message_swap_by_denom.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,10 @@ const TypeMsgSwapByDenom = "swap_by_denom"

var _ sdk.Msg = &MsgSwapByDenom{}

func NewMsgSwapByDenom(sender string, amount sdk.Coin, minAmount sdk.Coin, maxAmount sdk.Coin, denomIn string, denomOut string, discount sdk.Dec) *MsgSwapByDenom {
func NewMsgSwapByDenom(sender, recipient string, amount sdk.Coin, minAmount sdk.Coin, maxAmount sdk.Coin, denomIn string, denomOut string, discount sdk.Dec) *MsgSwapByDenom {
return &MsgSwapByDenom{
Sender: sender,
Recipient: recipient,
Amount: amount,
MinAmount: minAmount,
MaxAmount: maxAmount,
Expand Down
Loading

0 comments on commit ee10806

Please sign in to comment.