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