You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm submitting a ...
[x] bug report
[ ] feature request
[ ] question about the decisions made in the repository
[ ] question about how to use this project
Summary
When estimating route in AlphaRouter, the number of swaps specified in EXACT will be different if the swaps are split so that multiple Pools are used (truncation probably occurs for each split Swap, and the total number of swaps due to the split Swaps is less than EXACT).
Other information (e.g. detailed explanation, stack traces, related issues, suggestions how to fix, links for us to have context, eg. StackOverflow, personal fork, etc.)
Reproduced code (It can be confirmed that the value of route.trade.swap is off due to an error. Also, the byte code of route.methodParameters.calldata is off as well as route.trade.swap)
Note that the following code is an example for TradeType.EXACT_OUTPUT, but the same misalignment occurred for TradeType.EXACT_INPUT.
const provider = // provider
const recipientAddress = // recipient address
const networkId = 137 // polygon
const buyTokenAddress = "0x7ceB23fD6bC0adD59E62ac25578270cFf1b9f619" // WETH
const buyTokenDecimals = 18
const buyAmountWei = "1464983244737305125"
const sellTokenAddress = "0x0x0d500B1d8E8eF31E21C99d1Db9A6444d3ADf1270" // WMATIC
const sellTokenDecimals = 18
const router = new AlphaRouter({
chainId: networkId,
provider,
})
const route = await router.route(
CurrencyAmount.fromRawAmount(
new Token(networkId, buyTokenAddress, buyTokenDecimals),
buyAmountWei
),
new Token(networkId, sellTokenAddress, sellTokenDecimals),
TradeType.EXACT_OUTPUT,
{
recipient: recipientAddress,
slippageTolerance: new Percent(3,100),
deadline: Math.floor(Date.now() / 1000) + 60 * 15,
type: SwapType.SWAP_ROUTER_02,
},
{
minSplits:2 // NOTE: Set the split to 2 or more to reproduce the problem.
}
)
if (route == undefined) {
throw new Error("Swap route not found.")
}
let sumSellAmount = new BigNumberJS(0)
let sumBuyAmount = new BigNumberJS(0)
route.trade.swaps.forEach(it => {
const sellAmount= it.inputAmount.quotient.toString()
const buyAmount = it.outputAmount.quotient.toString()
sumSellAmount = sumSellAmount.plus(sellAmount)
sumBuyAmount = sumBuyAmount.plus(buyAmount)
})
let sellAmount = route.trade.inputAmount.quotient.toString()
let buyAmount = route.trade.outputAmount.quotient.toString()
console.log("debug quote amount", {
splits: route.trade.swaps.length,
pools: route.trade.swaps.map(swap => swap.route.pools.map(pool => pool)),
diffBuyAmount: sumBuyAmount.minus(buyAmount).toString(), // NOTE: If "splits" is greater than 1, the value specified in EXACT is often off, probably due to truncation errors caused by swapping by each pool.
requiredBuyAmount: buyAmountWei,
quoteSellAmount: sumSellAmount.toString(),
quoteBuyAmount: sumBuyAmount.toString(),
}
)
The text was updated successfully, but these errors were encountered:
I'm submitting a ...
[x] bug report
[ ] feature request
[ ] question about the decisions made in the repository
[ ] question about how to use this project
Summary
When estimating route in AlphaRouter, the number of swaps specified in EXACT will be different if the swaps are split so that multiple Pools are used (truncation probably occurs for each split Swap, and the total number of swaps due to the split Swaps is less than EXACT).
Other information (e.g. detailed explanation, stack traces, related issues, suggestions how to fix, links for us to have context, eg. StackOverflow, personal fork, etc.)
Reproduced code (It can be confirmed that the value of
route.trade.swap
is off due to an error. Also, the byte code ofroute.methodParameters.calldata
is off as well as route.trade.swap)Note that the following code is an example for
TradeType.EXACT_OUTPUT
, but the same misalignment occurred forTradeType.EXACT_INPUT
.The text was updated successfully, but these errors were encountered: