Skip to content

Commit

Permalink
fix: multi hops swap with recipient
Browse files Browse the repository at this point in the history
  • Loading branch information
cosmic-vagabond committed Feb 10, 2024
1 parent d36f244 commit 3fdaf14
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 3 deletions.
3 changes: 3 additions & 0 deletions scripts/upgrade-assure/update-genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
3 changes: 1 addition & 2 deletions x/amm/keeper/elys_routed_multihop.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand Down Expand Up @@ -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 {
Expand Down
8 changes: 7 additions & 1 deletion x/amm/keeper/route_exact_amount_in.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 3fdaf14

Please sign in to comment.