Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: multi hops swap with recipient #367

Merged
merged 1 commit into from
Feb 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading