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

Commit e2eccbc

Browse files
AgusVelez5scnale
authored andcommitted
WIP scripts
1 parent dac3573 commit e2eccbc

File tree

6 files changed

+121
-48
lines changed

6 files changed

+121
-48
lines changed

deployment/config/config-types.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ export type TokenRouterConfiguration = {
1212
baseFee: number;
1313
initAuctionFee: number;
1414
};
15-
cctpAllowance: number;
15+
cctpAllowance: string;
1616
disableRouterEndpoints?: ChainId[];
1717
};
1818

@@ -30,5 +30,5 @@ export type MatchingEngineConfiguration = {
3030
// Mutable values
3131
ownerAssistant: string;
3232
feeRecipient: string;
33-
cctpAllowance: number;
33+
cctpAllowance: string;
3434
};

deployment/helpers/env.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import fs from "fs";
22
import { ethers, utils } from "ethers";
33
import { validateSolAddress } from "./solana";
4-
import { ChainConfig, ChainInfo, ContractsJson, Dependencies, Ecosystem } from "./interfaces";
4+
import { ChainConfig, ChainInfo, ContractsJson, Dependencies, Ecosystem, VerificationApiKeys } from "./interfaces";
55
import { getSigner } from "./evm";
66
// TODO: support different env files
77
import 'dotenv/config';
@@ -11,6 +11,7 @@ export const env = getEnv("ENV");
1111
export const contracts = loadContracts();
1212
export const dependencies = loadDependencies();
1313
export const ecosystemChains = loadEcosystem();
14+
export const verificationApiKeys = loadVerificationApiKeys();
1415

1516
function loadJson<T>(filename: string): T {
1617
const fileContent = fs.readFileSync(
@@ -32,6 +33,10 @@ function loadEcosystem(): Ecosystem {
3233
return loadJson<Ecosystem>("ecosystem");
3334
}
3435

36+
function loadVerificationApiKeys() {
37+
return loadJson<VerificationApiKeys[]>("verification-api-keys");
38+
}
39+
3540
export function getEnv(env: string): string {
3641
const v = process.env[env];
3742
if (!v) {

deployment/helpers/interfaces.ts

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { ChainId } from "@wormhole-foundation/sdk-base";
1+
import { ChainId, Network } from "@wormhole-foundation/sdk-base";
22
import { SolanaLedgerSigner } from "@xlabs-xyz/ledger-signer-solana";
33
import { BytesLike, ethers } from "ethers";
44

@@ -9,13 +9,23 @@ export type LoggerFn = (...args: any[]) => void;
99

1010
export type ChainInfo = {
1111
name: string;
12-
chainId: ChainId; // Wormhole ChainId
12+
/**
13+
* Wormhole ChainId
14+
*/
15+
chainId: ChainId;
1316
rpc: string;
14-
externalId?: string; // Native ChainId
17+
/**
18+
* Native ChainId
19+
*/
20+
externalId?: string;
21+
network: Network;
1522
};
1623

1724
export type Deployment = {
18-
chainId: number; // Wormhole ChainId
25+
/**
26+
* Wormhole ChainId
27+
*/
28+
chainId: number;
1929
address: string;
2030
constructorArgs?: any[];
2131
};
@@ -33,7 +43,10 @@ export type Ecosystem = {
3343
export type ContractsJson = Record<string, Deployment[]>;
3444

3545
export interface ChainConfig {
36-
chainId: ChainId; // Wormhole ChainId
46+
/**
47+
* Wormhole ChainId
48+
*/
49+
chainId: ChainId;
3750
}
3851

3952
export interface Dependencies extends ChainConfig {
@@ -57,7 +70,10 @@ export interface VerificationApiKeys extends ChainConfig {
5770
}
5871

5972
export type RouterEndpoint = {
60-
wormholeChainId: ChainId;
73+
/**
74+
* Wormhole ChainId
75+
*/
76+
chainId: ChainId;
6177
endpoint: {
6278
router: BytesLike;
6379
mintRecipient: BytesLike;

deployment/helpers/utils.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import chalk from 'chalk';
22
import { ChainInfo, LoggerFn, ValueDiff } from '.';
3+
import { UniversalAddress } from '@wormhole-foundation/sdk-definitions';
34

45
export const someoneIsDifferent = (values: ValueDiff[]) => values.some((value) => value.onChain.toString() !== value.offChain.toString() && Number(value.onChain) !== Number(value.offChain));
56

@@ -48,7 +49,10 @@ export function flattenObject(obj: Record<string, any>, parentKey = '', result:
4849
return result;
4950
}
5051

51-
/// Verify bytecode helper
52+
export function getUniversalAddress(address: string): string {
53+
const type = getAddressType(address);
54+
return new UniversalAddress(address, type).toString()
55+
}
5256

5357
export function getVerifyCommand(
5458
chain: ChainInfo,
Lines changed: 49 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { runOnEvms, ChainInfo, LoggerFn, getContractAddress, getDeploymentArgs, getVerifyCommand } from "../../../helpers";
1+
import { runOnEvms, ChainInfo, LoggerFn, getContractAddress, getDeploymentArgs, getVerifyCommand, verificationApiKeys, flattenObject } from "../../../helpers";
22
import { ethers } from "ethers";
33
import { execSync } from "child_process";
44
import path from "path";
@@ -8,44 +8,55 @@ runOnEvms("bytecode-verification-token-router", async (chain: ChainInfo, signer:
88
// The root path of the foundry project
99
const rootPath = path.resolve('../evm/');
1010

11-
if (chain.externalId === undefined)
12-
throw new Error(`Chain ${chain.chainId} does not have an external ID`);
1311

14-
// Implementation data
15-
const implementationName = "TokenRouter";
16-
const implementationPath = 'src/TokenRouter/TokenRouter.sol';
17-
const implementationAddress = getContractAddress("TokenRouterImplementation", chain.chainId);
18-
const implementationDeploymentArgs = getDeploymentArgs("TokenRouterImplementation", chain.chainId);
19-
const implementationConstructorSignature = "constructor(address,address,address,uint16,bytes32,bytes32,uint32)";
20-
const verifyImplementationCommand = getVerifyCommand(
21-
implementationName,
22-
implementationPath,
23-
implementationAddress,
24-
implementationConstructorSignature,
25-
implementationDeploymentArgs,
26-
parseInt(chain.externalId)
27-
);
28-
29-
// Proxy data
30-
const proxyName = "ERC1967Proxy";
31-
const proxyPath = 'lib/openzeppelin-contracts/contracts/proxy/ERC1967/ERC1967Proxy.sol';
32-
const proxyAddress = getContractAddress("TokenRouterProxy", chain.chainId);
33-
const proxyDeploymentArgs = getDeploymentArgs("TokenRouterProxy", chain.chainId);
34-
const proxyConstructorSignature = "constructor(address,bytes)";
35-
const verifyProxyCommand = getVerifyCommand(
36-
proxyName,
37-
proxyPath,
38-
proxyAddress,
39-
proxyConstructorSignature,
40-
proxyDeploymentArgs,
41-
parseInt(chain.externalId)
42-
);
12+
const verifiersData = verificationApiKeys.find((x) => x.chainId == chain.chainId);
13+
const verifiers = flattenObject(verifiersData!);
14+
delete verifiers.chainId;
4315

44-
log(chalk.green("Verifying implementation bytecode..."));
45-
execSync(verifyImplementationCommand, { stdio: "inherit", cwd: rootPath });
46-
console.log()
16+
for (let [name, apiKey] of Object.entries(verifiers)) {
17+
name = name.split("-")[0];
4718

48-
log(chalk.green("Verifying proxy bytecode..."));
49-
execSync(verifyProxyCommand, { stdio: "inherit", cwd: rootPath });
50-
console.log()
19+
// Implementation data
20+
const implementationName = "MatchingEngine";
21+
const implementationPath = 'src/MatchingEngine/MatchingEngine.sol';
22+
const implementationAddress = getContractAddress("MatchingEngineImplementation", chain.chainId);
23+
const implementationDeploymentArgs = getDeploymentArgs("MatchingEngineImplementation", chain.chainId);
24+
const implementationConstructorSignature = "constructor(address,address,address,uint24,uint24,uint8,uint8,uint8)";
25+
const verifyImplementationCommand = getVerifyCommand(
26+
chain,
27+
implementationName,
28+
implementationPath,
29+
implementationAddress,
30+
implementationConstructorSignature,
31+
implementationDeploymentArgs,
32+
name,
33+
apiKey
34+
);
35+
36+
// Proxy data
37+
const proxyName = "ERC1967Proxy";
38+
const proxyPath = 'lib/openzeppelin-contracts/contracts/proxy/ERC1967/ERC1967Proxy.sol';
39+
const proxyAddress = getContractAddress("MatchingEngineProxy", chain.chainId);
40+
const proxyDeploymentArgs = getDeploymentArgs("MatchingEngineProxy", chain.chainId);
41+
const proxyConstructorSignature = "constructor(address,bytes)";
42+
const verifyProxyCommand = getVerifyCommand(
43+
chain,
44+
proxyName,
45+
proxyPath,
46+
proxyAddress,
47+
proxyConstructorSignature,
48+
proxyDeploymentArgs,
49+
name,
50+
apiKey
51+
);
52+
53+
log(chalk.green(`Verifying bytecode on ${name}...`));
54+
log(chalk.green("Verifying implementation bytecode..."));
55+
execSync(verifyImplementationCommand, { stdio: "inherit", cwd: rootPath });
56+
console.log()
57+
58+
log(chalk.green("Verifying proxy bytecode..."));
59+
execSync(verifyProxyCommand, { stdio: "inherit", cwd: rootPath });
60+
console.log()
61+
}
5162
});
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import { ChainInfo, LoggerFn, getContractInstance, getContractAddress, runOnEvms, contracts, getUniversalAddress } from "../../../helpers";
2+
import { ethers } from "ethers";
3+
import { TokenRouter } from "../../../contract-bindings";
4+
import { circle } from "@wormhole-foundation/sdk-base";
5+
6+
runOnEvms("cross-registration-token-router", async (chain: ChainInfo, signer: ethers.Signer, log: LoggerFn) => {
7+
const tokenRouterAddress = getContractAddress("TokenRouterProxy", chain.chainId);
8+
const tokenRouter = (await getContractInstance("TokenRouter", tokenRouterAddress, chain)) as TokenRouter;
9+
const deployedTokenRouters = contracts['TokenRouterProxy'].filter((router) => router.chainId !== chain.chainId);
10+
11+
for (const router of deployedTokenRouters) {
12+
const circleDomain = circle.toCircleChainId(chain.network, router.chainId);
13+
const endpoint = {
14+
router: getUniversalAddress(router.address),
15+
mintRecipient: getUniversalAddress(router.address)
16+
};
17+
18+
19+
// check if is already registered
20+
21+
if (router.chainId === 0)
22+
throw new Error('Invalid chainId when register new router endpoint');
23+
24+
if (Number(router.address) === 0)
25+
throw new Error(`Invalid router address for chainId ${router.chainId}`);
26+
27+
const isAlreadyRegistered =
28+
29+
await tokenRouter.addRouterEndpoint(router.chainId, endpoint, circleDomain);
30+
log(`Router endpoint added for chainId ${router.chainId}`);
31+
}
32+
});
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)