price subscriptions

This commit is contained in:
Tim Olson
2023-11-02 23:30:43 -04:00
parent 3f15985bf5
commit b483974268
10 changed files with 212 additions and 40 deletions

29
src/blockchain/route.js Normal file
View File

@@ -0,0 +1,29 @@
import {queryHelperContract} from "@/blockchain/contract.js";
import {Exchange} from "@/blockchain/orderlib.js";
import {useStore} from "@/store/store.js";
export async function findRoute(tokenA, tokenB) {
const helper = await queryHelperContract()
if (!helper)
throw Error('no helper')
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
for (let [exchange, fee, pool] of rawRoutes) {
exchange = Number(exchange)
fee = Number(fee)
if (result.fee === undefined || result.fee > fee) {
switch (exchange) {
case 0: // UniswapV2
break
case 1: // UniswapV3
const [token0, token1] = tokenA.address < tokenB.address ? [tokenA, tokenB] : [tokenB, tokenA]
result = {chainId, exchange: Exchange.UniswapV3, pool, fee, token0, token1}
break
}
}
}
return [result]
}