1+ import {
2+ ComputeBudgetProgram ,
3+ Connection ,
4+ PublicKey ,
5+ } from "@solana/web3.js" ;
6+ import "dotenv/config" ;
7+ import { solana , LoggerFn , getChainConfig , getContractAddress } from "../../helpers" ;
8+ import { TokenRouterConfiguration } from "../../config/config-types" ;
9+ import { ProgramId } from "@wormhole-foundation/example-liquidity-layer-solana/tokenRouter" ;
10+ import { SolanaLedgerSigner } from "@xlabs-xyz/ledger-signer-solana" ;
11+ import { circle } from "@wormhole-foundation/sdk-base" ;
12+ import { TokenRouterProgram } from "@wormhole-foundation/example-liquidity-layer-solana/tokenRouter" ;
13+ import { ledgerSignAndSend } from "../../helpers/solana" ;
14+
15+ solana . runOnSolana ( "deploy-token-router" , async ( chain , signer , log ) => {
16+ const config = await getChainConfig < TokenRouterConfiguration > ( "token-router" , chain . chainId ) ;
17+ const tokenRouterId = getContractAddress ( "TokenRouterProgram" , chain . chainId ) as ProgramId ;
18+
19+ const env = "Mainnet" ;
20+ const usdcMint = new PublicKey ( circle . usdcContract ( env , "Solana" ) ) ;
21+ const connection = new Connection ( chain . rpc , solana . connectionCommitmentLevel ) ;
22+ const tokenRouter = new TokenRouterProgram ( connection , tokenRouterId , usdcMint ) ;
23+
24+ await initialize ( tokenRouter , signer , log , config ) ;
25+ } ) ;
26+
27+ async function initialize ( tokenRouter : TokenRouterProgram , signer : SolanaLedgerSigner , log : LoggerFn , config : TokenRouterConfiguration ) {
28+ const connection = tokenRouter . program . provider . connection ;
29+
30+ const custodian = tokenRouter . custodianAddress ( ) ;
31+ log ( "custodian" , custodian . toString ( ) ) ;
32+
33+ const exists = await connection . getAccountInfo ( custodian ) . then ( ( acct ) => acct != null ) ;
34+ if ( exists ) {
35+ log ( "already initialized" ) ;
36+ return ;
37+ }
38+
39+ const signerPubkey = new PublicKey ( await signer . getAddress ( ) ) ;
40+ const initializeIx = await tokenRouter . initializeIx ( {
41+ owner : signerPubkey ,
42+ ownerAssistant : new PublicKey ( config . ownerAssistant ) ,
43+ } ) ;
44+ const priorityFee = ComputeBudgetProgram . setComputeUnitPrice ( { microLamports : solana . priorityMicrolamports } ) ;
45+
46+ const txSig = await ledgerSignAndSend ( connection , [ initializeIx , priorityFee ] , [ ] ) ;
47+ log ( "intialize" , txSig ) ;
48+ }
0 commit comments