-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathgetTestnetInfo.ts
109 lines (94 loc) · 3.85 KB
/
getTestnetInfo.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
import { Connection, PublicKey } from "@solana/web3.js";
import { Chain, toChainId } from "@wormhole-foundation/sdk-base";
import { toUniversal } from "@wormhole-foundation/sdk-definitions";
import * as matchingEngineSdk from "../src/matchingEngine";
import * as tokenRouterSdk from "../src/tokenRouter";
const USDC_MINT = new PublicKey("4zMMC9srt5Ri5X14GAgXhaHii3GnPAEERYPJgZJDncDU");
export const CHAINS: Chain[] = [
"Sepolia",
"Avalanche",
"OptimismSepolia",
"ArbitrumSepolia",
"BaseSepolia",
"PolygonSepolia",
];
// Here we go.
main();
// impl
async function main() {
const connection = new Connection("https://api.devnet.solana.com", "confirmed");
console.log("Collecting Solana Matching Engine and Token Router Info...");
console.log();
{
const matchingEngine = new matchingEngineSdk.MatchingEngineProgram(
connection,
matchingEngineSdk.testnet(),
USDC_MINT,
);
const custodian = matchingEngine.custodianAddress();
console.log("Matching Engine");
console.log(" Custodian (NOTE: The Custodian's address is the program's emitter):");
console.log(` Native: ${custodian.toString()}`);
console.log(` Universal: ${custodian.toBuffer().toString("hex")}`);
console.log();
const cctpMintRecipient = matchingEngine.cctpMintRecipientAddress();
console.log(" Mint Recipient:");
console.log(` Native: ${cctpMintRecipient.toString()}`);
console.log(` Universal: ${cctpMintRecipient.toBuffer().toString("hex")}`);
console.log();
const custodianData = await matchingEngine.fetchCustodian();
console.log("Custodian Data");
console.log(JSON.stringify(custodianData, null, 2));
console.log();
const auctionConfig = await matchingEngine.fetchAuctionConfig(
custodianData.auctionConfigId,
);
console.log("Auction Config Data");
console.log(JSON.stringify(auctionConfig, null, 2));
console.log();
for (const chainName of CHAINS) {
await matchingEngine
.fetchRouterEndpointInfo(toChainId(chainName))
.then((endpointData) => {
console.log(
`Registered Endpoint (${chainName}): ${stringifyEndpoint(
chainName,
endpointData,
)}`,
);
})
.catch((err) => {
console.log(`Not Registered: ${chainName}`);
});
console.log();
}
}
{
const tokenRouter = new tokenRouterSdk.TokenRouterProgram(
connection,
tokenRouterSdk.testnet(),
USDC_MINT,
);
const custodian = tokenRouter.custodianAddress();
console.log(`Token Router`);
console.log(" Custodian (NOTE: The Custodian's address is the program's emitter):");
console.log(` Native: ${custodian.toString()}`);
console.log(` Universal: ${custodian.toBuffer().toString("hex")}`);
console.log();
const cctpMintRecipient = tokenRouter.cctpMintRecipientAddress();
console.log(" Mint Recipient:");
console.log(` Native: ${cctpMintRecipient.toString()}`);
console.log(` Universal: ${cctpMintRecipient.toBuffer().toString("hex")}`);
console.log();
}
}
function stringifyEndpoint(chain: Chain, endpoint: matchingEngineSdk.EndpointInfo) {
const out = {
address: toUniversal(chain, Uint8Array.from(endpoint.address)).toNative(chain).toString(),
mintRecipient: toUniversal(chain, Uint8Array.from(endpoint.mintRecipient))
.toNative(chain)
.toString(),
protocol: endpoint.protocol,
};
return JSON.stringify(out, null, 2);
}