Skip to content

Commit

Permalink
clean up
Browse files Browse the repository at this point in the history
  • Loading branch information
novaliu86 committed Nov 18, 2024
1 parent 0738936 commit 2252917
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 14 deletions.
2 changes: 1 addition & 1 deletion src/e2e.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.`);
}
Expand Down
13 changes: 3 additions & 10 deletions src/parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,12 @@ import { parserPluginByLiquiditySourceUname } from "./liquiditySourcePlugins/par
const toSwap = (route: IRouteInfoInResponse, tokenOpsById: Map<number, TokenOperation>): 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]}.`);
Expand Down
6 changes: 3 additions & 3 deletions src/routers/universalRouter/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -116,9 +117,8 @@ export class UniversalRouter extends RouterBase {
}
}

export const universalRouterByChainId: Map<ChainId, UniversalRouter> = new Map();

export const universalRouterByChainId: PartialRecord<ChainId, UniversalRouter> = {};
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)});
});

0 comments on commit 2252917

Please sign in to comment.