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

Commit 2ba338f

Browse files
AgusVelez5scnale
authored andcommitted
Fix ts errors
1 parent 016e4b9 commit 2ba338f

File tree

8 files changed

+70
-63
lines changed

8 files changed

+70
-63
lines changed

deployment/helpers/utils.ts

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -49,11 +49,6 @@ export function flattenObject(obj: Record<string, any>, parentKey = '', result:
4949
return result;
5050
}
5151

52-
export function getUniversalAddress(address: string): string {
53-
const type = getAddressType(address);
54-
return new UniversalAddress(address, type).toString()
55-
}
56-
5752
export function getVerifyCommand(
5853
chain: ChainInfo,
5954
contractName: string,

deployment/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22
"name": "deployment",
33
"scripts": {
44
"evm-deps": "forge build --contracts ../evm/lib/openzeppelin-contracts/contracts/proxy && forge build --config-path ../evm/foundry.toml",
5-
"build-evm": "npm run evm-deps && npx typechain --target=ethers-v5 --out-dir=./contract-bindings ../evm/out/*/*.json"
5+
"build-evm": "npm run evm-deps && npx typechain --target=ethers-v5 --out-dir=./contract-bindings ../evm/out/*/*.json",
6+
"check": "npx tsc --noEmit"
67
},
78
"author": "",
89
"devDependencies": {

deployment/scripts/evm/TokenRouter/bytecode-verification-token-router.ts

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ evm.runOnEvms("bytecode-verification-token-router", async (chain, signer, log) =
77
// The root path of the foundry project
88
const rootPath = path.resolve('../evm/');
99

10-
1110
const verifiersData = verificationApiKeys.find((x) => x.chainId == chain.chainId);
1211
const verifiers = flattenObject(verifiersData!);
1312
delete verifiers.chainId;
@@ -16,11 +15,11 @@ evm.runOnEvms("bytecode-verification-token-router", async (chain, signer, log) =
1615
name = name.split("-")[0];
1716

1817
// Implementation data
19-
const implementationName = "MatchingEngine";
20-
const implementationPath = 'src/MatchingEngine/MatchingEngine.sol';
21-
const implementationAddress = getContractAddress("MatchingEngineImplementation", chain.chainId);
22-
const implementationDeploymentArgs = getDeploymentArgs("MatchingEngineImplementation", chain.chainId);
23-
const implementationConstructorSignature = "constructor(address,address,address,uint24,uint24,uint8,uint8,uint8)";
18+
const implementationName = "TokenRouter";
19+
const implementationPath = 'src/TokenRouter/TokenRouter.sol';
20+
const implementationAddress = getContractAddress("TokenRouterImplementation", chain.chainId);
21+
const implementationDeploymentArgs = getDeploymentArgs("TokenRouterImplementation", chain.chainId);
22+
const implementationConstructorSignature = "constructor(address,address,address,uint16,bytes32,bytes32,uint32)";
2423
const verifyImplementationCommand = getVerifyCommand(
2524
chain,
2625
implementationName,

deployment/scripts/evm/TokenRouter/cross-registration-token-router.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,19 @@
1-
import { evm, getContractInstance, getContractAddress, contracts, getUniversalAddress } from "../../../helpers";
1+
import { evm, getContractInstance, getContractAddress, contracts } from "../../../helpers";
22
import { TokenRouter } from "../../../contract-bindings";
33
import { circle, toChain } from "@wormhole-foundation/sdk-base";
4+
import { toUniversal } from "@wormhole-foundation/sdk-definitions";
45

5-
evm.runOnEvms("cross-registration-token-router", async (chain, signer, log) => {
6+
evm.runOnEvms("cross-registration-token-router", async (chain, _, log) => {
67
const tokenRouterAddress = getContractAddress("TokenRouterProxy", chain.chainId);
78
const tokenRouter = (await getContractInstance("TokenRouter", tokenRouterAddress, chain)) as TokenRouter;
89
const deployedTokenRouters = contracts['TokenRouterProxy'].filter((router) => router.chainId !== chain.chainId);
9-
10+
const chainName = toChain(chain.chainId);
11+
1012
for (const router of deployedTokenRouters) {
1113
const circleDomain = circle.toCircleChainId(chain.network, toChain(router.chainId));
1214
const endpoint = {
13-
router: getUniversalAddress(router.address),
14-
mintRecipient: getUniversalAddress(router.address)
15+
router: toUniversal(chainName, router.address).toString(),
16+
mintRecipient: toUniversal(chainName, router.address).toString()
1517
};
1618

1719
if (router.chainId === 0)

deployment/scripts/evm/TokenRouter/upgrade-token-router.ts

Lines changed: 16 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
1-
import { evm, ChainInfo, getContractInstance, getContractAddress, getDependencyAddress, getAddressType } from "../../../helpers";
2-
import { deployImplementation, getTokenRouterConfiguration } from "./utils";
1+
import { evm, ChainInfo, getContractInstance, getContractAddress, getDependencyAddress } from "../../../helpers";
2+
import { deployImplementation, getMintRecipientAddress, getTokenRouterConfiguration, matchingEngineChain, matchingEngineDomain } from "./utils";
33
import { TokenRouter } from "../../../contract-bindings";
4-
import { TokenRouterConfiguration } from "../../../config/config-types";
5-
import { UniversalAddress } from "@wormhole-foundation/sdk-definitions";
4+
import { toUniversal } from "@wormhole-foundation/sdk-definitions";
65

76
evm.runOnEvms("upgrade-token-router", async (chain, signer, log) => {
87
const currentImplementationAddress = getContractAddress("TokenRouterImplementation", chain.chainId);
@@ -11,7 +10,7 @@ evm.runOnEvms("upgrade-token-router", async (chain, signer, log) => {
1110
const config = await getTokenRouterConfiguration(chain);
1211

1312
log(`Checking immutables for TokenRouter`);
14-
checkImmutables(proxy, config, chain);
13+
checkImmutables(proxy, chain);
1514

1615
const newImplementation = await deployImplementation(chain, signer, config, log);
1716

@@ -20,13 +19,13 @@ evm.runOnEvms("upgrade-token-router", async (chain, signer, log) => {
2019
await proxy.upgradeContract(newImplementation.address);
2120
});
2221

23-
async function checkImmutables(tokenRouter: TokenRouter, config: TokenRouterConfiguration, chain: ChainInfo) {
22+
async function checkImmutables(tokenRouter: TokenRouter, chain: ChainInfo) {
2423
const [
2524
token,
26-
matchingEngineMintRecipient,
27-
matchingEngineChain,
28-
matchingEngineDomain,
29-
matchingEngineAddress,
25+
savedMatchingEngineMintRecipient,
26+
savedMatchingEngineChain,
27+
savedMatchingEngineDomain,
28+
savedMatchingEngineAddress,
3029
] = await Promise.all([
3130
tokenRouter.orderToken(),
3231
tokenRouter.matchingEngineMintRecipient(),
@@ -35,23 +34,21 @@ async function checkImmutables(tokenRouter: TokenRouter, config: TokenRouterConf
3534
tokenRouter.matchingEngineAddress(),
3635
]);
3736

38-
const mintRecipientAddressType = getAddressType(config.matchingEngineMintRecipient);
39-
const expectedMatchingEngineMintRecipient = (new UniversalAddress(config.matchingEngineMintRecipient, mintRecipientAddressType)).toString();
40-
const localMatchingEngineAddress = getContractAddress("MatchingEngineProxy", chain.chainId);
41-
const matchingEngineAddressType = getAddressType(localMatchingEngineAddress);
42-
const expectedMatchingEngineAddress = (new UniversalAddress(localMatchingEngineAddress, matchingEngineAddressType)).toString();
37+
const matchingEngineMintRecipient = toUniversal("Solana", getMintRecipientAddress()).toString();
38+
const localMatchingEngineAddress = getContractAddress("MatchingEngineProxy", matchingEngineChain);
39+
const matchingEngineAddress = toUniversal("Solana", localMatchingEngineAddress).toString();
4340
const tokenAddress = getDependencyAddress("token", chain.chainId);
4441

45-
if (matchingEngineMintRecipient.toLowerCase() !== expectedMatchingEngineMintRecipient.toLowerCase())
42+
if (savedMatchingEngineMintRecipient.toLowerCase() !== matchingEngineMintRecipient.toLowerCase())
4643
throw new Error(`MatchingEngineMintRecipient is an immutable value and cannot be changed.`);
4744

48-
if (matchingEngineChain !== Number(config.matchingEngineChain))
45+
if (savedMatchingEngineChain !== matchingEngineChain)
4946
throw new Error(`MatchingEngineChain is an immutable value and cannot be changed.`);
5047

51-
if (matchingEngineDomain !== Number(config.matchingEngineDomain))
48+
if (savedMatchingEngineDomain !== matchingEngineDomain)
5249
throw new Error(`MatchingEngineDomain is an immutable value and cannot be changed.`);
5350

54-
if (matchingEngineAddress.toLowerCase() !== expectedMatchingEngineAddress.toLowerCase())
51+
if (savedMatchingEngineAddress.toLowerCase() !== matchingEngineAddress.toLowerCase())
5552
throw new Error(`MatchingEngineAddress is an immutable value and cannot be changed.`);
5653

5754
if (token.toLowerCase() !== tokenAddress.toLowerCase())

deployment/scripts/evm/TokenRouter/utils.ts

Lines changed: 23 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,38 +2,47 @@ import { ethers } from "ethers";
22
import { TokenRouterConfiguration } from "../../../config/config-types";
33
import { TokenRouter, TokenRouter__factory } from "../../../contract-bindings";
44
import { ChainInfo, getChainConfig, LoggerFn, getDependencyAddress, writeDeployedContract, getContractAddress, getContractInstance, logComparison, someoneIsDifferent } from "../../../helpers";
5-
import { ERC20 } from "../../../contract-bindings/ERC20";
6-
import { UniversalAddress } from "@wormhole-foundation/sdk-definitions";
5+
import { IERC20 } from "../../../contract-bindings";
6+
import { UniversalAddress, toUniversal } from "@wormhole-foundation/sdk-definitions";
7+
import { toChain } from "@wormhole-foundation/sdk-base";
78

8-
export function getTokenRouterConfiguration(chain: ChainInfo): Promise<TokenRouterConfiguration> {
9-
return getChainConfig<TokenRouterConfiguration>("token-router", chain.chainId);
10-
}
9+
/**
10+
* Chain ID for the Solana wormhole chain
11+
*/
12+
export const matchingEngineChain = 1;
13+
14+
/**
15+
* CCTP Domain for Solana
16+
*/
17+
export const matchingEngineDomain = 5;
1118

1219
// TODO
13-
function getMintRecipientAddress() {
20+
export function getMintRecipientAddress() {
1421
return '6y7V8dL673XFzm9QyC5vvh3itWkp7wztahBd2yDqsyrK'
1522
};
1623

24+
export function getTokenRouterConfiguration(chain: ChainInfo): Promise<TokenRouterConfiguration> {
25+
return getChainConfig<TokenRouterConfiguration>("token-router", chain.chainId);
26+
}
27+
1728
export async function deployImplementation(chain: ChainInfo, signer: ethers.Signer, config: TokenRouterConfiguration, log: LoggerFn) {
1829
const factory = new TokenRouter__factory(signer);
1930
const token = getDependencyAddress("token", config.chainId);
2031
const wormhole = getDependencyAddress("wormhole", config.chainId);
2132
const tokenMessenger = getDependencyAddress("tokenMessenger", config.chainId);
2233

23-
const matchingEngineMintRecipient = (new UniversalAddress(getMintRecipientAddress(), 'base58')).toString();
24-
const matchinEngineChain = 1; // Solana wormhole chain id
25-
const matchingEngineDomain = 5; // Solana cctp domain
34+
const matchingEngineMintRecipient = toUniversal("Solana", getMintRecipientAddress()).toString();
2635
let matchingEngineAddress = (getContractAddress(
2736
"MatchingEngineProxy",
28-
matchinEngineChain
37+
matchingEngineChain
2938
));
30-
matchingEngineAddress = (new UniversalAddress(matchingEngineAddress, 'base58')).toString();
39+
matchingEngineAddress = toUniversal("Solana", matchingEngineAddress).toString();
3140

3241
const deployment = await factory.deploy(
3342
token,
3443
wormhole,
3544
tokenMessenger,
36-
matchinEngineChain,
45+
matchingEngineChain,
3746
matchingEngineAddress,
3847
matchingEngineMintRecipient,
3948
matchingEngineDomain,
@@ -48,7 +57,7 @@ export async function deployImplementation(chain: ChainInfo, signer: ethers.Sign
4857
token,
4958
wormhole,
5059
tokenMessenger,
51-
matchinEngineChain,
60+
matchingEngineChain,
5261
matchingEngineAddress,
5362
matchingEngineMintRecipient,
5463
matchingEngineDomain
@@ -66,7 +75,7 @@ export async function getOnChainTokenRouterConfiguration(chain: ChainInfo) {
6675
// Get the allowance for the token messenger
6776
const tokenMessengerAddress = getDependencyAddress("tokenMessenger", chain.chainId);
6877
const orderTokenAddress = await tokenRouter.orderToken();
69-
const orderToken = (await getContractInstance("ERC20", orderTokenAddress, chain)) as ERC20;
78+
const orderToken = (await getContractInstance("IERC20", orderTokenAddress, chain)) as IERC20;
7079
const cctpAllowance = await orderToken.allowance(tokenRouterProxyAddress, tokenMessengerAddress);
7180
const ownerAssistant = await tokenRouter.getOwnerAssistant();
7281
const { enabled, maxAmount, baseFee, initAuctionFee} = await tokenRouter.getFastTransferParameters();

deployment/scripts/solana/initializeMatchingEngine.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
import {
2-
ComputeBudgetProgram,
3-
Connection,
4-
PublicKey,
2+
AccountInfo,
3+
ComputeBudgetProgram,
4+
Connection,
5+
PublicKey,
56
} from "@solana/web3.js";
67
import "dotenv/config";
78
import { uint64ToBN } from "@wormhole-foundation/example-liquidity-layer-solana/common";
@@ -30,7 +31,7 @@ async function initialize(matchingEngine: MatchingEngineProgram, signer: SolanaL
3031
const custodian = matchingEngine.custodianAddress();
3132
log("custodian", custodian.toString());
3233

33-
const exists = await connection.getAccountInfo(custodian).then((acct) => acct != null);
34+
const exists = await connection.getAccountInfo(custodian).then((acct: null | AccountInfo<Buffer>) => acct != null);
3435
if (exists) {
3536
log("already initialized");
3637
return;

deployment/scripts/solana/registerRoutersInMatchingEngine.ts

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
import {
2-
ComputeBudgetProgram,
3-
Connection,
4-
PublicKey,
2+
AccountInfo,
3+
ComputeBudgetProgram,
4+
Connection,
5+
PublicKey,
56
} from "@solana/web3.js";
67
import "dotenv/config";
78
import { MatchingEngineProgram } from "@wormhole-foundation/example-liquidity-layer-solana/matchingEngine";
@@ -16,8 +17,10 @@ import { TokenRouterProgram } from "@wormhole-foundation/example-liquidity-layer
1617
solana.runOnSolana("register-routers-matching-engine", async (chain, signer, log) => {
1718
const matchingEngineId = getContractAddress("MatchingEngine", chain.chainId) as ProgramId;
1819

19-
const env = "Mainnet";
20-
const usdcMint = new PublicKey(circle.usdcContract(env, "Solana"));
20+
if (chain.network === "Devnet")
21+
throw new Error("Devnet is not supported by USDC. Use Mainnet or Testnet.");
22+
23+
const usdcMint = new PublicKey(circle.usdcContract(chain.network, "Solana"));
2124
const connection = new Connection(chain.rpc, solana.connectionCommitmentLevel);
2225
const matchingEngine = new MatchingEngineProgram(connection, matchingEngineId, usdcMint);
2326

@@ -60,15 +63,15 @@ async function addCctpRouterEndpoint(
6063
foreignMintRecipient: string | null,
6164
log: LoggerFn,
6265
) {
63-
await matchingEngine.fetchCustodian().catch((_) => {
66+
await matchingEngine.fetchCustodian().catch((_: unknown) => {
6467
throw new Error("no custodian found");
6568
});
6669

6770
const connection = matchingEngine.program.provider.connection;
6871

6972
const foreignChainId = toChainId(foreignChain);
7073
const endpoint = matchingEngine.routerEndpointAddress(foreignChainId);
71-
const exists = await connection.getAccountInfo(endpoint).then((acct) => acct != null);
74+
const exists = await connection.getAccountInfo(endpoint).then((acct: null | AccountInfo<Buffer>) => acct != null);
7275

7376
const endpointAddress = Array.from(toUniversal(foreignChain, foreignEmitter).unwrap());
7477
const endpointMintRecipient =
@@ -153,15 +156,15 @@ async function addSolanaCctpRouterEndpoint(
153156
tokenRouter: TokenRouterProgram,
154157
log: LoggerFn,
155158
) {
156-
await matchingEngine.fetchCustodian().catch((_) => {
159+
await matchingEngine.fetchCustodian().catch((_: unknown) => {
157160
throw new Error("no custodian found");
158161
});
159162

160163
const connection = matchingEngine.program.provider.connection;
161164

162165
const chain = toChainId("Solana");
163166
const endpoint = matchingEngine.routerEndpointAddress(chain);
164-
const exists = await connection.getAccountInfo(endpoint).then((acct) => acct != null);
167+
const exists = await connection.getAccountInfo(endpoint).then((acct: null | AccountInfo<Buffer>) => acct != null);
165168

166169
const endpointAddress = Array.from(
167170
toUniversal("Solana", tokenRouter.custodianAddress().toString()).unwrap(),

0 commit comments

Comments
 (0)