price constraints working
This commit is contained in:
@@ -10,14 +10,15 @@ export async function findRoute(tokenA, tokenB) {
|
||||
const chainId = useStore().chainId
|
||||
const rawRoutes = await helper.getRoutes(tokenA.address, tokenB.address)
|
||||
// todo expose all available pools
|
||||
let result = {} // we actually only find a single pool for now
|
||||
console.log('raw routes', rawRoutes)
|
||||
let result = null // we actually only find a single pool for now
|
||||
for (let [exchange, fee, pool] of rawRoutes) {
|
||||
exchange = Number(exchange)
|
||||
fee = Number(fee)
|
||||
if (result.fee === undefined || result.fee > fee) {
|
||||
if (!result || result.fee > fee) {
|
||||
switch (exchange) {
|
||||
case 0: // UniswapV2
|
||||
break
|
||||
throw Error('Uniswap V2 not yet supported')
|
||||
case 1: // UniswapV3
|
||||
const [token0, token1] = tokenA.address < tokenB.address ? [tokenA, tokenB] : [tokenB, tokenA]
|
||||
result = {chainId, exchange: Exchange.UniswapV3, pool, fee, token0, token1}
|
||||
@@ -25,5 +26,5 @@ export async function findRoute(tokenA, tokenB) {
|
||||
}
|
||||
}
|
||||
}
|
||||
return [result]
|
||||
}
|
||||
return result ? [result] : []
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user