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

Commit d3411c8

Browse files
committed
deploy: retrieves mint recipient from solana sdk
1 parent 46a7a77 commit d3411c8

File tree

5 files changed

+51
-26
lines changed

5 files changed

+51
-26
lines changed

deployment/helpers/interfaces.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ export type ChainInfo = {
1515
chainId: ChainId;
1616
rpc: string;
1717
/**
18-
* Native ChainId
18+
* Native (e.g. EIP-155) ChainId
1919
*/
2020
externalId?: string;
2121
network: Network;

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,14 @@ evm.runOnEvms("cross-registration-token-router", async (chain, _, log) => {
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);
10-
const chainName = toChain(chain.chainId);
1110

1211
for (const router of deployedTokenRouters) {
1312
const circleDomain = circle.toCircleChainId(chain.network, toChain(router.chainId));
13+
// TODO: handle Solana registrations correctly in regards to mintRecipient
14+
const routerChain = toChain(router.chainId);
1415
const endpoint = {
15-
router: toUniversal(chainName, router.address).toString(),
16-
mintRecipient: toUniversal(chainName, router.address).toString()
16+
router: toUniversal(routerChain, router.address).toString(),
17+
mintRecipient: toUniversal(routerChain, router.address).toString()
1718
};
1819

1920
if (router.chainId === 0)

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

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,23 @@
11
import { ethers } from "ethers";
2-
import { evm, LoggerFn, writeDeployedContract } from "../../../helpers";
2+
import { ecosystemChains, evm, LoggerFn, solana, writeDeployedContract } from "../../../helpers";
33
import { TokenRouterConfiguration } from "../../../config/config-types";
4-
import { deployImplementation, getTokenRouterConfiguration } from "./utils";
4+
import { deployImplementation, getMatchingEngineMintRecipientAddress, getTokenRouterConfiguration } from "./utils";
55
import { ERC1967Proxy__factory } from "../../../contract-bindings";
6+
import { toUniversal } from "@wormhole-foundation/sdk-definitions";
7+
import { Connection } from "@solana/web3.js";
68

79
evm.runOnEvms("deploy-token-router", async (chain, signer, log) => {
810
const config = await getTokenRouterConfiguration(chain);
9-
const implementation = await deployImplementation(chain, signer, config, log);
11+
12+
// TODO: write a `getChain(chainId: ChainId): ChainInfo` function to replace these lines
13+
if (ecosystemChains.solana.networks.length !== 1) {
14+
throw Error("Unexpected number of Solana networks.");
15+
}
16+
const solanaRpc = ecosystemChains.solana.networks[0].rpc;
17+
18+
const solanaConnection = new Connection(solanaRpc, solana.connectionCommitmentLevel);
19+
const matchingEngineMintRecipient = toUniversal("Solana", getMatchingEngineMintRecipientAddress(solanaConnection));
20+
const implementation = await deployImplementation(signer, config, matchingEngineMintRecipient, log);
1021
await deployProxy(signer, config, implementation, log);
1122
});
1223

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

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,35 @@
1-
import { evm, ChainInfo, getContractInstance, getContractAddress, getDependencyAddress } from "../../../helpers";
2-
import { deployImplementation, getMintRecipientAddress, getTokenRouterConfiguration, matchingEngineChain, matchingEngineDomain } from "./utils";
1+
import { evm, ChainInfo, getContractInstance, getContractAddress, getDependencyAddress, ecosystemChains, solana } from "../../../helpers";
2+
import { deployImplementation, getMatchingEngineMintRecipientAddress, getTokenRouterConfiguration, matchingEngineChain, matchingEngineDomain } from "./utils";
33
import { TokenRouter } from "../../../contract-bindings";
4-
import { toUniversal } from "@wormhole-foundation/sdk-definitions";
4+
import { UniversalAddress, toUniversal } from "@wormhole-foundation/sdk-definitions";
5+
import { Connection } from "@solana/web3.js";
56

67
evm.runOnEvms("upgrade-token-router", async (chain, signer, log) => {
78
const currentImplementationAddress = getContractAddress("TokenRouterImplementation", chain.chainId);
89
const proxyAddress = getContractAddress("TokenRouterProxy", chain.chainId);
910
const proxy = (await getContractInstance("TokenRouter", proxyAddress, chain)) as TokenRouter;
1011
const config = await getTokenRouterConfiguration(chain);
1112

13+
// TODO: write a `getChain(chainId: ChainId): ChainInfo` function to replace these lines
14+
if (ecosystemChains.solana.networks.length !== 1) {
15+
throw Error("Unexpected number of Solana networks.");
16+
}
17+
const solanaRpc = ecosystemChains.solana.networks[0].rpc;
18+
19+
const solanaConnection = new Connection(solanaRpc, solana.connectionCommitmentLevel);
20+
const matchingEngineMintRecipient = toUniversal("Solana", getMatchingEngineMintRecipientAddress(solanaConnection));
21+
1222
log(`Checking immutables for TokenRouter`);
13-
checkImmutables(proxy, chain);
23+
checkImmutables(proxy, chain, matchingEngineMintRecipient);
1424

15-
const newImplementation = await deployImplementation(chain, signer, config, log);
25+
const newImplementation = await deployImplementation(signer, config, matchingEngineMintRecipient, log);
1626

1727
log(`Upgrading TokenRouter implementation from ${currentImplementationAddress} to ${newImplementation.address}`);
18-
28+
1929
await proxy.upgradeContract(newImplementation.address);
2030
});
2131

22-
async function checkImmutables(tokenRouter: TokenRouter, chain: ChainInfo) {
32+
async function checkImmutables(tokenRouter: TokenRouter, chain: ChainInfo, matchingEngineMintRecipient: UniversalAddress) {
2333
const [
2434
token,
2535
savedMatchingEngineMintRecipient,
@@ -34,12 +44,11 @@ async function checkImmutables(tokenRouter: TokenRouter, chain: ChainInfo) {
3444
tokenRouter.matchingEngineAddress(),
3545
]);
3646

37-
const matchingEngineMintRecipient = toUniversal("Solana", getMintRecipientAddress()).toString();
3847
const localMatchingEngineAddress = getContractAddress("MatchingEngineProxy", matchingEngineChain);
3948
const matchingEngineAddress = toUniversal("Solana", localMatchingEngineAddress).toString();
4049
const tokenAddress = getDependencyAddress("token", chain.chainId);
4150

42-
if (savedMatchingEngineMintRecipient.toLowerCase() !== matchingEngineMintRecipient.toLowerCase())
51+
if (savedMatchingEngineMintRecipient.toLowerCase() !== matchingEngineMintRecipient.toString().toLowerCase())
4352
throw new Error(`MatchingEngineMintRecipient is an immutable value and cannot be changed.`);
4453

4554
if (savedMatchingEngineChain !== matchingEngineChain)

deployment/scripts/evm/TokenRouter/utils.ts

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@ import { TokenRouter, TokenRouter__factory } from "../../../contract-bindings";
44
import { ChainInfo, getChainConfig, LoggerFn, getDependencyAddress, writeDeployedContract, getContractAddress, getContractInstance, logComparison, someoneIsDifferent } from "../../../helpers";
55
import { IERC20 } from "../../../contract-bindings";
66
import { UniversalAddress, toUniversal } from "@wormhole-foundation/sdk-definitions";
7-
import { toChain } from "@wormhole-foundation/sdk-base";
7+
import { circle, toChain, toChainId } from "@wormhole-foundation/sdk-base";
8+
import { MatchingEngineProgram, ProgramId } from "@wormhole-foundation/example-liquidity-layer-solana/matchingEngine";
9+
import { Connection, PublicKey } from "@solana/web3.js";
810

911
/**
1012
* Chain ID for the Solana wormhole chain
@@ -16,35 +18,37 @@ export const matchingEngineChain = 1;
1618
*/
1719
export const matchingEngineDomain = 5;
1820

19-
// TODO
20-
export function getMintRecipientAddress() {
21-
return '6y7V8dL673XFzm9QyC5vvh3itWkp7wztahBd2yDqsyrK'
21+
export function getMatchingEngineMintRecipientAddress(connection: Connection) {
22+
const matchingEngineId = getContractAddress("MatchingEngineProxy", toChainId("Solana")) as ProgramId;
23+
24+
const env = "Mainnet";
25+
const usdcMint = new PublicKey(circle.usdcContract(env, "Solana"));
26+
const matchingEngine = new MatchingEngineProgram(connection, matchingEngineId, usdcMint);
27+
return matchingEngine.cctpMintRecipientAddress().toBytes();
2228
};
2329

2430
export function getTokenRouterConfiguration(chain: ChainInfo): Promise<TokenRouterConfiguration> {
2531
return getChainConfig<TokenRouterConfiguration>("token-router", chain.chainId);
2632
}
2733

28-
export async function deployImplementation(chain: ChainInfo, signer: ethers.Signer, config: TokenRouterConfiguration, log: LoggerFn) {
34+
export async function deployImplementation(signer: ethers.Signer, config: TokenRouterConfiguration, matchingEngineMintRecipient: UniversalAddress, log: LoggerFn) {
2935
const factory = new TokenRouter__factory(signer);
3036
const token = getDependencyAddress("token", config.chainId);
3137
const wormhole = getDependencyAddress("wormhole", config.chainId);
3238
const tokenMessenger = getDependencyAddress("tokenMessenger", config.chainId);
3339

34-
const matchingEngineMintRecipient = toUniversal("Solana", getMintRecipientAddress()).toString();
35-
let matchingEngineAddress = (getContractAddress(
40+
const matchingEngineAddress = toUniversal("Solana", (getContractAddress(
3641
"MatchingEngineProxy",
3742
matchingEngineChain
38-
));
39-
matchingEngineAddress = toUniversal("Solana", matchingEngineAddress).toString();
43+
))).toString();
4044

4145
const deployment = await factory.deploy(
4246
token,
4347
wormhole,
4448
tokenMessenger,
4549
matchingEngineChain,
4650
matchingEngineAddress,
47-
matchingEngineMintRecipient,
51+
matchingEngineMintRecipient.toString(),
4852
matchingEngineDomain,
4953
{} // overrides
5054
);

0 commit comments

Comments
 (0)