diff --git a/src/e2e.ts b/src/e2e.ts index e4e171b..1e4909c 100644 --- a/src/e2e.ts +++ b/src/e2e.ts @@ -63,7 +63,7 @@ export const tradeE2eAsync = async ( const routingPlan = parse(res.swapResponse); // get router object by chainId - const router = universalRouterByChainId.get(chainId); + const router = universalRouterByChainId[chainId]; if (router === undefined) { throw new Error(`Router for chainId ${chainId} not found.`); } diff --git a/src/parser.ts b/src/parser.ts index 98ce434..f7d60a9 100644 --- a/src/parser.ts +++ b/src/parser.ts @@ -9,19 +9,12 @@ import { parserPluginByLiquiditySourceUname } from "./liquiditySourcePlugins/par const toSwap = (route: IRouteInfoInResponse, tokenOpsById: Map): Swap => { const plugin = parserPluginByLiquiditySourceUname[route.name]; - - let liquidityInfo: LiquidityInfo; if (plugin === undefined) { - liquidityInfo = { - source: route.name, - address: route.address, - } - // throw new Error(`Invalid route name ${route.name}!`); - } - else { - liquidityInfo = plugin.converToLiquidityInfo(route); + throw new Error(`Invalid liquidity source ${route.name}!`); } + const liquidityInfo: LiquidityInfo = plugin.converToLiquidityInfo(route); + const fromTokenOp = tokenOpsById.get(route.fromTokens[0].referenceId); if (fromTokenOp === undefined) { throw new Error(`Missing tokenOp with ID ${route.fromTokens[0]}.`); diff --git a/src/routers/universalRouter/index.ts b/src/routers/universalRouter/index.ts index ad114ed..3d009ef 100644 --- a/src/routers/universalRouter/index.ts +++ b/src/routers/universalRouter/index.ts @@ -12,6 +12,7 @@ import type { IEncodeOptions } from '../types.js'; import { deployedAddressesByChainId } from './addresses.js'; import { CommandType, CONTRACT_BALANCE, RoutePlanner, ROUTER_AS_RECIPIENT, SENDER_AS_RECIPIENT, type IPermitWithSignature } from './routerCommands.js'; import { universalRouterPluginByLiquiditySourceUname } from '../../liquiditySourcePlugins/universalRouterPlugins.js'; +import type { PartialRecord } from '../../common/typeUtils.js'; const universalRouterInterface: Interface = new Interface(universalRouterData.abi); @@ -116,9 +117,8 @@ export class UniversalRouter extends RouterBase { } } -export const universalRouterByChainId: Map = new Map(); - +export const universalRouterByChainId: PartialRecord = {}; Object.entries(deployedAddressesByChainId).map(([chainIdStr, routerAddress]) => { const chainId = parseInt(chainIdStr) as ChainId; - universalRouterByChainId.set(chainId, new UniversalRouter(chainId, routerAddress)); + Object.assign(universalRouterByChainId, { [chainId]: new UniversalRouter(chainId, routerAddress)}); }); \ No newline at end of file