Skip to content
This repository was archived by the owner on Jun 16, 2025. It is now read-only.

Commit 00e6d4e

Browse files
AgusVelez5scnale
authored andcommitted
Finished cross registration script
1 parent 2ecd04f commit 00e6d4e

File tree

1 file changed

+7
-11
lines changed

1 file changed

+7
-11
lines changed
Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,33 @@
11
import { ChainInfo, LoggerFn, getContractInstance, getContractAddress, runOnEvms, contracts, getUniversalAddress } from "../../../helpers";
22
import { ethers } from "ethers";
33
import { TokenRouter } from "../../../contract-bindings";
4-
import { circle } from "@wormhole-foundation/sdk-base";
4+
import { circle, toChain } from "@wormhole-foundation/sdk-base";
55

66
runOnEvms("cross-registration-token-router", async (chain: ChainInfo, signer: ethers.Signer, log: LoggerFn) => {
77
const tokenRouterAddress = getContractAddress("TokenRouterProxy", chain.chainId);
88
const tokenRouter = (await getContractInstance("TokenRouter", tokenRouterAddress, chain)) as TokenRouter;
99
const deployedTokenRouters = contracts['TokenRouterProxy'].filter((router) => router.chainId !== chain.chainId);
1010

1111
for (const router of deployedTokenRouters) {
12-
const circleDomain = circle.toCircleChainId(chain.network, router.chainId);
12+
const circleDomain = circle.toCircleChainId(chain.network, toChain(router.chainId));
1313
const endpoint = {
1414
router: getUniversalAddress(router.address),
1515
mintRecipient: getUniversalAddress(router.address)
1616
};
1717

18-
19-
// check if is already registered
20-
2118
if (router.chainId === 0)
2219
throw new Error('Invalid chainId when register new router endpoint');
2320

2421
if (Number(router.address) === 0)
2522
throw new Error(`Invalid router address for chainId ${router.chainId}`);
2623

27-
const isAlreadyRegistered =
24+
const currentMintRecipient = await tokenRouter.getMintRecipient(router.chainId);
25+
if (Number(currentMintRecipient) !== 0) {
26+
log(`Router endpoint already registered for chainId ${router.chainId}`);
27+
continue;
28+
}
2829

2930
await tokenRouter.addRouterEndpoint(router.chainId, endpoint, circleDomain);
3031
log(`Router endpoint added for chainId ${router.chainId}`);
3132
}
3233
});
33-
34-
function isRouterEndpointRegistered(router: TokenRouter, chainId: number, endpoint: { router: string; mintRecipient: string }) {
35-
const mintRecipient = await tokenRouter.getMintRecipient(router.chainId, endpoint);
36-
return Number(mintRecipient) !== 0;
37-
}

0 commit comments

Comments
 (0)