From 6a6ec2162613ba8bf7d683162698516e7c6eb7ba Mon Sep 17 00:00:00 2001 From: Cosmic Vagabond <121588426+cosmic-vagabond@users.noreply.github.com> Date: Sat, 10 Feb 2024 11:37:34 +0100 Subject: [PATCH] fix: multi hops swap with recipient (#367) --- scripts/upgrade-assure/update-genesis.go | 3 +++ x/amm/keeper/elys_routed_multihop.go | 3 +-- x/amm/keeper/route_exact_amount_in.go | 8 +++++++- 3 files changed, 11 insertions(+), 3 deletions(-) diff --git a/scripts/upgrade-assure/update-genesis.go b/scripts/upgrade-assure/update-genesis.go index 87d1fbc82..30b5d4da3 100644 --- a/scripts/upgrade-assure/update-genesis.go +++ b/scripts/upgrade-assure/update-genesis.go @@ -93,6 +93,9 @@ func updateGenesis(validatorBalance, homePath, genesisFilePath string) { // update broker address genesis.AppState.Parameter.Params.BrokerAddress = "elys1nc5tatafv6eyq7llkr2gv50ff9e22mnf70qgjlv737ktmt4eswrqau4f4q" + // update oracle price expiration + genesis.AppState.Oracle.Params.PriceExpiryTime = "604800" + outputFilePath := homePath + "/config/genesis.json" if err := writeGenesisFile(outputFilePath, genesis); err != nil { log.Fatalf(Red+"Error writing genesis file: %v", err) diff --git a/x/amm/keeper/elys_routed_multihop.go b/x/amm/keeper/elys_routed_multihop.go index 69899df6d..223d1004d 100644 --- a/x/amm/keeper/elys_routed_multihop.go +++ b/x/amm/keeper/elys_routed_multihop.go @@ -2,7 +2,6 @@ package keeper import ( sdk "github.com/cosmos/cosmos-sdk/types" - appparams "github.com/elys-network/elys/app/params" "github.com/elys-network/elys/x/amm/types" ) @@ -31,7 +30,7 @@ func (k Keeper) isElysRoutedMultihop(ctx sdk.Context, route types.MultihopRoute, return false } intemediateDenoms := route.IntermediateDenoms() - if len(intemediateDenoms) != 1 || intemediateDenoms[0] != appparams.BaseCoinUnit { + if len(intemediateDenoms) != 1 /*|| intemediateDenoms[0] != appparams.BaseCoinUnit*/ { return false } if inDenom == outDenom { diff --git a/x/amm/keeper/route_exact_amount_in.go b/x/amm/keeper/route_exact_amount_in.go index 729e937a9..41260d494 100644 --- a/x/amm/keeper/route_exact_amount_in.go +++ b/x/amm/keeper/route_exact_amount_in.go @@ -47,6 +47,12 @@ func (k Keeper) RouteExactAmountIn( totalDiscountedSwapFee = sdk.ZeroDec() for i, route := range routes { + // recipient is the same as the sender until the last pool + actualRecipient := sender + if len(routes)-1 == i { + actualRecipient = recipient + } + // To prevent the multihop swap from being interrupted prematurely, we keep // the minimum expected output at a very low number until the last pool _outMinAmount := math.NewInt(1) @@ -86,7 +92,7 @@ func (k Keeper) RouteExactAmountIn( // Calculate the total discounted swap fee totalDiscountedSwapFee = totalDiscountedSwapFee.Add(swapFee) - tokenOutAmount, err = k.SwapExactAmountIn(ctx, sender, recipient, pool, tokenIn, route.TokenOutDenom, _outMinAmount, swapFee) + tokenOutAmount, err = k.SwapExactAmountIn(ctx, sender, actualRecipient, pool, tokenIn, route.TokenOutDenom, _outMinAmount, swapFee) if err != nil { ctx.Logger().Error(err.Error()) return math.Int{}, sdk.ZeroDec(), sdk.ZeroDec(), err