Parallelize router address fetching

pull/15/head
J M Rossy 2 years ago
parent 1c4d69b087
commit 9617d498cd
  1. 19
      src/features/tokens/routes.ts

@ -152,16 +152,15 @@ export function useTokenRoutes() {
const domains = await collateralContract.domains(); const domains = await collateralContract.domains();
logger.info(`Found ${domains.length} connected domains:`, domains); logger.info(`Found ${domains.length} connected domains:`, domains);
const hypTokens: Array<{ chainId: number; address: Address }> = []; logger.info('Getting domain router address');
// TODO parallelization here would be good, either with RPC batching or just promise.all, but const hypTokenByteAddressesP = domains.map((d) => collateralContract.routers(d));
// avoiding it for now due to limitations of public RPC providers const hypTokenByteAddresses = await Promise.all(hypTokenByteAddressesP);
for (const chainId of domains) { const hypTokenAddresses = hypTokenByteAddresses.map((b) => utils.bytes32ToAddress(b));
logger.info(`Getting domain router address for:`, chainId); logger.info(`Addresses found:`, hypTokenAddresses);
const hypTokenAddrBytes = await collateralContract.routers(chainId); const hypTokens = hypTokenAddresses.map((addr, i) => ({
const hypTokenAddr = utils.bytes32ToAddress(hypTokenAddrBytes); chainId: domains[i],
logger.info(`Address found:`, hypTokenAddr); address: normalizeAddress(addr),
hypTokens.push({ chainId, address: normalizeAddress(hypTokenAddr) }); }));
}
tokens.push({ ...token, hypTokens }); tokens.push({ ...token, hypTokens });
} }

Loading…
Cancel
Save