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

Commit 02f2bb6

Browse files
AgusVelez5scnale
authored andcommitted
Refactor base fn and add disable script
1 parent eef8c43 commit 02f2bb6

File tree

10 files changed

+109
-255
lines changed

10 files changed

+109
-255
lines changed

deployment/config/config-types.ts

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,19 @@
11
import { ChainId } from "@wormhole-foundation/sdk-base";
2-
import { BytesLike } from "ethers";
3-
4-
export type RouterEndpointConfig = {
5-
wormholeChainId: ChainId;
6-
endpoint: {
7-
router: BytesLike;
8-
mintRecipient: BytesLike;
9-
},
10-
circleDomain: number;
11-
}
122

133
export type TokenRouterConfiguration = {
144
// Wormhole Chain ID of the token router configuration
155
chainId: ChainId;
166

17-
// Immutable values
18-
matchingEngineMintRecipient: string;
19-
matchingEngineChain: ChainId; // Wormhole Chain ID
20-
matchingEngineDomain: string;
21-
227
// Mutable values
238
ownerAssistant: string;
24-
routerEndpoints: RouterEndpointConfig[];
259
fastTransferParameters: {
2610
enabled: boolean;
2711
maxAmount: number;
2812
baseFee: number;
2913
initAuctionFee: number;
3014
};
3115
cctpAllowance: number;
16+
disableRouterEndpoints?: ChainId[];
3217
};
3318

3419
export type MatchingEngineConfiguration = {
@@ -45,6 +30,5 @@ export type MatchingEngineConfiguration = {
4530
// Mutable values
4631
ownerAssistant: string;
4732
feeRecipient: string;
48-
routerEndpoints: RouterEndpointConfig[];
4933
cctpAllowance: number;
5034
};

deployment/helpers/evm.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ export async function runOnEvmsSequentially(scriptName: string, cb: EvmScriptCb)
4545
}
4646

4747
export function evmOperatingChains() {
48-
const { operatingChains } = ecosystemChains.evm;
48+
const { operatingChains } = ecosystemChains;
4949
if (Array.isArray(operatingChains) && operatingChains.length >= 1) {
5050
return ecosystemChains.evm.networks.filter((x) => {
5151
return operatingChains.includes(x.chainId);

deployment/helpers/interfaces.ts

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

55
export type EvmScriptCb = (chain: ChainInfo, signer: ethers.Signer, logFn: LoggerFn) => Promise<void>;
66
export type SolanaScriptCb = (chain: ChainInfo, signer: SolanaLedgerSigner, logFn: LoggerFn) => Promise<void>;
@@ -21,9 +21,8 @@ export type Deployment = {
2121
};
2222

2323
export type Ecosystem = {
24-
guardianSetIndex: number;
24+
operatingChains?: number[];
2525
evm: {
26-
operatingChains?: number[];
2726
networks: ChainInfo[];
2827
},
2928
solana: {
@@ -46,4 +45,22 @@ export interface Dependencies extends ChainConfig {
4645
export interface ValueDiff {
4746
onChain: any;
4847
offChain: any;
48+
}
49+
50+
export interface VerificationApiKeys extends ChainConfig {
51+
etherscan: string;
52+
blockscout?: {
53+
mainnet: string;
54+
testnet: string;
55+
};
56+
sourcify?: string;
57+
}
58+
59+
export type RouterEndpoint = {
60+
wormholeChainId: ChainId;
61+
endpoint: {
62+
router: BytesLike;
63+
mintRecipient: BytesLike;
64+
},
65+
circleDomain: number;
4966
}

deployment/helpers/utils.ts

Lines changed: 28 additions & 89 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
import chalk from 'chalk';
2-
import { LoggerFn, ValueDiff, getEnv } from '.';
3-
import { ChainId } from "@wormhole-foundation/sdk-base";
4-
import { RouterEndpointConfig } from '../config/config-types';
5-
import { UniversalAddress } from '@wormhole-foundation/sdk-definitions';
2+
import { ChainInfo, LoggerFn, ValueDiff } from '.';
63

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

@@ -13,124 +10,66 @@ export function logComparision(name: string, diffValues: any, log: LoggerFn) {
1310
return;
1411

1512
// If the on chain value is not present or it is zero value, log it as an addition
16-
if (!diffValues.onChain || Number(diffValues.onChain) === 0) {
13+
if (!diffValues.onChain || Number(diffValues.onChain) === 0)
1714
log(chalk.green(`+ ${name}: ${diffValues.offChain}`));
18-
}
1915

2016
// If the off chain value is not present or it is zero value, log it as a removal
21-
else if (!diffValues.offChain || Number(diffValues.offChain) === 0) {
17+
else if (!diffValues.offChain || Number(diffValues.offChain) === 0)
2218
log(chalk.red(`- ${name}: ${diffValues.onChain}`));
23-
}
2419

2520
// If both values are present and they are different, log it as a change
26-
else {
21+
else
2722
log(chalk.yellow(`~ ${name}: `) + chalk.red(`${diffValues.onChain}`) + ' -> ' + chalk.green(`${diffValues.offChain}`));
28-
}
2923
}
3024

3125
// Assuming that we'll only have two types of addresses: Ethereum and Solana
3226
export function getAddressType(address: string): 'hex' | 'base58' {
3327
const ETHEREUM_ADDRESS_LENGTH = 40;
3428
const addressLength = address.length - (address.startsWith("0x") ? 2 : 0);
3529

36-
// TODO: check lenght of solana addresses
3730
if (address.length < ETHEREUM_ADDRESS_LENGTH)
3831
throw new Error(`Invalid address length: ${address}`);
3932

4033
return addressLength === ETHEREUM_ADDRESS_LENGTH ? 'hex' : 'base58';
4134
}
4235

43-
// Router endpoint helpers
44-
45-
export function getRouterEndpointDifferences(onChainRouterEndpoints: RouterEndpointConfig[], offChainRouterEndpoints: RouterEndpointConfig[]) {
46-
const routerEndpointsDifferences = [];
47-
let onChainIndex = 0;
48-
let offChainIndex = 0;
49-
50-
onChainRouterEndpoints = onChainRouterEndpoints.sort((a, b) => a.wormholeChainId - b.wormholeChainId);
51-
offChainRouterEndpoints = offChainRouterEndpoints.sort((a, b) => a.wormholeChainId - b.wormholeChainId);
52-
53-
while (true) {
54-
const onChainEndpoint = onChainRouterEndpoints[onChainIndex];
55-
const offChainEndpoint = offChainRouterEndpoints[offChainIndex];
56-
57-
// If we've reached the end of both arrays, we're done
58-
if (!onChainEndpoint && !offChainEndpoint) {
59-
break;
60-
}
61-
62-
// If we've reached the end of offChainEndpoints, add the remaining onChainEndpoints
63-
// or if the onChainEndpoint is less than the offChainEndpoint, add the onChainEndpoint
64-
if (!offChainEndpoint || onChainEndpoint?.wormholeChainId < offChainEndpoint?.wormholeChainId) {
65-
routerEndpointsDifferences.push(
66-
routerEndpointConfig(onChainEndpoint.wormholeChainId, onChainEndpoint, {})
67-
);
68-
onChainIndex++;
69-
continue;
70-
}
71-
72-
// If we've reached the end of onChainEndpoints, add the remaining offChainEndpoints
73-
// or if the offChainEndpoint is less than the onChainEndpoint, add the offChainEndpoint
74-
if (!onChainEndpoint || onChainEndpoint?.wormholeChainId > offChainEndpoint?.wormholeChainId) {
75-
routerEndpointsDifferences.push(
76-
routerEndpointConfig(offChainEndpoint.wormholeChainId, {}, offChainEndpoint)
77-
);
78-
offChainIndex++;
79-
continue;
80-
}
81-
82-
routerEndpointsDifferences.push(
83-
routerEndpointConfig(onChainEndpoint.wormholeChainId, onChainEndpoint, offChainEndpoint)
84-
);
85-
86-
onChainIndex++;
87-
offChainIndex++;
36+
export function flattenObject(obj: Record<string, any>, parentKey = '', result: Record<string, any> = {}) {
37+
for (let key in obj) {
38+
if (obj.hasOwnProperty(key)) {
39+
let newKey = parentKey ? `${parentKey}-${key}` : key;
40+
41+
if (typeof obj[key] === 'object' && obj[key] !== null && !Array.isArray(obj[key])) {
42+
flattenObject(obj[key], newKey, result);
43+
} else {
44+
result[newKey] = obj[key];
45+
}
46+
}
8847
}
89-
90-
return routerEndpointsDifferences;
91-
}
92-
93-
const routerEndpointConfig = (wormholeChainId: ChainId, onChain: Partial<RouterEndpointConfig>, offChain: Partial<RouterEndpointConfig>) => ({
94-
wormholeChainId,
95-
router: {
96-
onChain: onChain?.endpoint?.router,
97-
offChain: offChain?.endpoint?.router
98-
},
99-
mintRecipient: {
100-
onChain: onChain?.endpoint?.mintRecipient,
101-
offChain: offChain?.endpoint?.mintRecipient
102-
},
103-
circleDomain: {
104-
onChain: onChain?.circleDomain,
105-
offChain: offChain?.circleDomain
106-
}
107-
});
108-
109-
export function getFormattedEndpoint(router: string, mintRecipient: string) {
110-
const routerAddresType = getAddressType(router);
111-
const mintRecipientAddressType = getAddressType(mintRecipient);
112-
113-
return {
114-
router: (new UniversalAddress(router, routerAddresType)).toString(),
115-
mintRecipient: (new UniversalAddress(mintRecipient, mintRecipientAddressType)).toString()
116-
};
48+
return result;
11749
}
11850

11951
/// Verify bytecode helper
12052

12153
export function getVerifyCommand(
54+
chain: ChainInfo,
12255
contractName: string,
12356
contractPath: string,
12457
contractAddress: string,
12558
constructorSignature: string,
12659
constructorArgs: any[],
127-
EvmChainId: number
60+
verifier: string,
61+
apiKey?: string
12862
): string {
129-
const ETHERSCAN_API_KEY = getEnv("ETHERSCAN_API_KEY");
130-
return `
63+
if (chain.externalId === undefined)
64+
throw new Error(`Chain ${chain.chainId} does not have an external ID`);
65+
66+
let command = `
13167
forge verify-contract ${contractAddress} ${contractPath}:${contractName} \
68+
--verifier ${verifier} \
13269
--watch --constructor-args $(cast abi-encode "${constructorSignature}" "${constructorArgs.join('" "')}") \
133-
--chain-id ${EvmChainId} \
134-
--etherscan-api-key ${ETHERSCAN_API_KEY} \
70+
--chain-id ${chain.externalId} \
71+
${ apiKey === undefined || apiKey === "" ? '' : `--etherscan-api-key ${apiKey}` }
13572
`;
73+
74+
return command;
13675
}

deployment/scripts/evm/MatchingEngine/config-matching-engine.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { MatchingEngine } from "../../../contract-bindings";
2-
import { runOnEvmsSequentially, ChainInfo, LoggerFn, getContractInstance, getContractAddress, getFormattedEndpoint } from "../../../helpers";
2+
import { runOnEvmsSequentially, ChainInfo, LoggerFn, getContractInstance, getContractAddress } from "../../../helpers";
33
import { ethers } from "ethers";
44
import { getConfigurationDifferences, logDiff } from "./utils";
55
import confirm from '@inquirer/confirm';

deployment/scripts/evm/MatchingEngine/utils.ts

Lines changed: 2 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { ethers } from "ethers";
22
import { MatchingEngineConfiguration } from "../../../config/config-types";
33
import { MatchingEngine, MatchingEngine__factory } from "../../../contract-bindings";
4-
import { ChainInfo, getChainConfig, LoggerFn, getDependencyAddress, writeDeployedContract, getContractAddress, getContractInstance, getRouterEndpointDifferences, logComparision, someoneIsDifferent } from "../../../helpers";
4+
import { ChainInfo, getChainConfig, LoggerFn, getDependencyAddress, writeDeployedContract, getContractAddress, getContractInstance, logComparision, someoneIsDifferent } from "../../../helpers";
55
import { ERC20 } from "../../../contract-bindings/out/ERC20";
66

77
export function getMachingEngineConfiguration(chain: ChainInfo): Promise<MatchingEngineConfiguration> {
@@ -75,25 +75,11 @@ export async function getOnChainMachingEngineConfiguration(chain: ChainInfo) {
7575
const feeRecipient = await matchingEngine.feeRecipient();
7676
const ownerAssistant = await matchingEngine.getOwnerAssistant();
7777

78-
const routerEndpoints = await Promise.all(config
79-
.routerEndpoints
80-
.map(async ({ wormholeChainId }) => {
81-
const { router, mintRecipient } = await matchingEngine.getRouterEndpoint(wormholeChainId);
82-
return {
83-
wormholeChainId,
84-
endpoint: {
85-
router,
86-
mintRecipient
87-
},
88-
circleDomain: await matchingEngine.getDomain(wormholeChainId)
89-
}
90-
}));
9178

9279
return {
9380
cctpAllowance,
9481
feeRecipient,
95-
ownerAssistant,
96-
routerEndpoints
82+
ownerAssistant
9783
};
9884
}
9985

@@ -120,43 +106,11 @@ export async function getConfigurationDifferences(chain: ChainInfo) {
120106
};
121107
}
122108

123-
differences.routerEndpoints = getRouterEndpointDifferences(onChainConfig.routerEndpoints, offChainConfig.routerEndpoints);
124-
125109
return differences;
126110
}
127111

128112
export function logDiff(differences: Record<string, any>, log: LoggerFn, valuesToShow?: Array<"new" | "update" | "delete">) {
129113
logComparision('feeRecipient', differences.feeRecipient, log);
130114
logComparision('cctpAllowance', differences.cctpAllowance, log);
131115

132-
logRoutersDiff(differences, log, valuesToShow);
133-
}
134-
135-
export function logRoutersDiff(differences: Record<string, any>, log: LoggerFn, valuesToShow?: Array<"new" | "update" | "delete">) {
136-
let routersLogged = false;
137-
for (const { wormholeChainId, router, mintRecipient, circleDomain } of differences.routerEndpoints) {
138-
// In no one is different, skip
139-
if (!someoneIsDifferent([router, mintRecipient, circleDomain]))
140-
continue;
141-
142-
// Edge case: if only mintRecipient is different and the off chain values are 0 (the endpoint is disabled), skip
143-
if (
144-
someoneIsDifferent([mintRecipient]) &&
145-
!someoneIsDifferent([router, circleDomain]) &&
146-
(Number(router.onChain) === 0 && Number(circleDomain.onChain) === 0) &&
147-
(Number(mintRecipient.offChain) === 0)
148-
) {
149-
continue;
150-
}
151-
152-
if (!routersLogged) {
153-
log('Router endpoints:');
154-
routersLogged = true;
155-
}
156-
157-
log(`WormholeChainId ${wormholeChainId}:`);
158-
logComparision('router', router, log, valuesToShow);
159-
logComparision('mintRecipient', mintRecipient, log, valuesToShow);
160-
logComparision('circleDomain', circleDomain, log, valuesToShow);
161-
}
162116
}

0 commit comments

Comments
 (0)