price constraints working

This commit is contained in:
Tim Olson
2023-11-05 16:50:06 -04:00
parent b483974268
commit bec1b33d22
13 changed files with 195 additions and 67 deletions

View File

@@ -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] : []
}