Skip to content

Commit

Permalink
Use for-in and retryAsync
Browse files Browse the repository at this point in the history
  • Loading branch information
ltyu committed Oct 7, 2024
1 parent 7a924b2 commit 7598729
Showing 1 changed file with 70 additions and 33 deletions.
103 changes: 70 additions & 33 deletions typescript/cli/src/deploy/warp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,11 @@ import {
Address,
ProtocolType,
assert,
concurrentMap,
objFilter,
objKeys,
objMap,
promiseObjAll,
retryAsync,
} from '@hyperlane-xyz/utils';

import { readWarpRouteDeployConfig } from '../config/warp.js';
Expand Down Expand Up @@ -625,42 +625,79 @@ async function enrollRemoteRouters(
(_, contracts) => getRouter(contracts).address,
);
const allChains = Object.keys(deployedRouters);
await concurrentMap(1, allChains, async (chain) => {
for (const chain of allChains) {
const contracts = deployedContractsMap[chain];
const router = getRouter(contracts); // Assume deployedContract always has 1 value

// Mutate the config.remoteRouters by setting it to all other routers to update
const warpRouteReader = new EvmERC20WarpRouteReader(multiProvider, chain);
const mutatedWarpRouteConfig = await warpRouteReader.deriveWarpRouteConfig(
router.address,
);
const evmERC20WarpModule = new EvmERC20WarpModule(multiProvider, {
config: mutatedWarpRouteConfig,
chain,
addresses: { deployedTokenRoute: router.address },
});
await retryAsync(async () => {
const router = getRouter(contracts); // Assume deployedContract always has 1 value

// Mutate the config.remoteRouters by setting it to all other routers to update
const warpRouteReader = new EvmERC20WarpRouteReader(multiProvider, chain);
const mutatedWarpRouteConfig =
await warpRouteReader.deriveWarpRouteConfig(router.address);
const evmERC20WarpModule = new EvmERC20WarpModule(multiProvider, {
config: mutatedWarpRouteConfig,
chain,
addresses: { deployedTokenRoute: router.address },
});

const otherChains = multiProvider
.getRemoteChains(chain)
.filter((c) => allChains.includes(c));
const otherChains = multiProvider
.getRemoteChains(chain)
.filter((c) => allChains.includes(c));

mutatedWarpRouteConfig.remoteRouters = otherChains.reduce<RemoteRouters>(
(remoteRouters, chain) => {
remoteRouters[multiProvider.getDomainId(chain)] =
deployedRouters[chain];
return remoteRouters;
},
{},
);
const mutatedConfigTxs: AnnotatedEV5Transaction[] =
await evmERC20WarpModule.update(mutatedWarpRouteConfig);

if (mutatedConfigTxs.length == 0)
return logGreen(
`Warp config on ${chain} is the same as target. No updates needed.`,
mutatedWarpRouteConfig.remoteRouters = otherChains.reduce<RemoteRouters>(
(remoteRouters, chain) => {
remoteRouters[multiProvider.getDomainId(chain)] =
deployedRouters[chain];
return remoteRouters;
},
{},
);
await submitWarpApplyTransactions(chain, params, mutatedConfigTxs);
});
const mutatedConfigTxs: AnnotatedEV5Transaction[] =
await evmERC20WarpModule.update(mutatedWarpRouteConfig);

if (mutatedConfigTxs.length == 0)
return logGreen(
`Warp config on ${chain} is the same as target. No updates needed.`,
);
await submitWarpApplyTransactions(chain, params, mutatedConfigTxs);
});
}
// await promiseObjAll(
// objMap(deployedContractsMap, async (chain, contracts) => {
// const router = getRouter(contracts); // Assume deployedContract always has 1 value

// // Mutate the config.remoteRouters by setting it to all other routers to update
// const warpRouteReader = new EvmERC20WarpRouteReader(multiProvider, chain);
// const mutatedWarpRouteConfig =
// await warpRouteReader.deriveWarpRouteConfig(router.address);
// const evmERC20WarpModule = new EvmERC20WarpModule(multiProvider, {
// config: mutatedWarpRouteConfig,
// chain,
// addresses: { deployedTokenRoute: router.address },
// });

// const otherChains = multiProvider
// .getRemoteChains(chain)
// .filter((c) => allChains.includes(c));

// mutatedWarpRouteConfig.remoteRouters = otherChains.reduce<RemoteRouters>(
// (remoteRouters, chain) => {
// remoteRouters[multiProvider.getDomainId(chain)] =
// deployedRouters[chain];
// return remoteRouters;
// },
// {},
// );
// const mutatedConfigTxs: AnnotatedEV5Transaction[] =
// await evmERC20WarpModule.update(mutatedWarpRouteConfig);

// if (mutatedConfigTxs.length == 0)
// return logGreen(
// `Warp config on ${chain} is the same as target. No updates needed.`,
// );
// await submitWarpApplyTransactions(chain, params, mutatedConfigTxs);
// }),
// );
}

function getRouter(contracts: HyperlaneContracts<HypERC20Factories>) {
Expand Down

0 comments on commit 7598729

Please sign in to comment.