11// This script executes root bundle on HubPool that rebalances tokens to Solana Spoke Pool. Required environment:
2- // - ETHERS_PROVIDER_URL : Ethereum RPC provider URL.
3- // - ETHERS_MNEMONIC : Mnemonic of the wallet that will sign the sending transaction on Ethereum
2+ // - NODE_URL_${CHAIN_ID} : Ethereum RPC URL (must point to the Mainnet or Sepolia depending on Solana cluster) .
3+ // - MNEMONIC : Mnemonic of the wallet that will sign the sending transaction on Ethereum
44// - HUB_POOL_ADDRESS: Hub Pool address
55
66import * as anchor from "@coral-xyz/anchor" ;
77import { BN , Program , AnchorProvider } from "@coral-xyz/anchor" ;
88import { AccountMeta , PublicKey , SystemProgram } from "@solana/web3.js" ;
99import { TOKEN_PROGRAM_ID , getAssociatedTokenAddressSync } from "@solana/spl-token" ;
10+ import { getNodeUrl } from "@uma/common" ;
1011// eslint-disable-next-line camelcase
1112import { CHAIN_IDs , TOKEN_SYMBOLS_MAP } from "../../utils/constants" ;
1213import { SvmSpoke } from "../../target/types/svm_spoke" ;
@@ -26,6 +27,7 @@ import {
2627} from "./utils/constants" ;
2728import { constructSimpleRebalanceTree } from "./utils/poolRebalanceTree" ;
2829import { decodeMessageHeader , getMessages } from "../../test/svm/cctpHelpers" ;
30+ import { getSolanaChainId , isSolanaDevnet , requireEnv } from "./utils/helpers" ;
2931
3032// Set up Solana provider.
3133const provider = AnchorProvider . env ( ) ;
@@ -39,21 +41,14 @@ const messageTransmitterProgram = new Program<MessageTransmitter>(messageTransmi
3941const tokenMessengerMinterIdl = require ( "../../target/idl/token_messenger_minter.json" ) ;
4042const tokenMessengerMinterProgram = new Program < TokenMessengerMinter > ( tokenMessengerMinterIdl , provider ) ;
4143
42- // Set up Ethereum provider.
43- if ( ! process . env . ETHERS_PROVIDER_URL ) {
44- throw new Error ( "Environment variable ETHERS_PROVIDER_URL is not set" ) ;
45- }
46- const ethersProvider = new ethers . providers . JsonRpcProvider ( process . env . ETHERS_PROVIDER_URL ) ;
47- if ( ! process . env . ETHERS_MNEMONIC ) {
48- throw new Error ( "Environment variable ETHERS_MNEMONIC is not set" ) ;
49- }
50- const ethersSigner = ethers . Wallet . fromMnemonic ( process . env . ETHERS_MNEMONIC ) . connect ( ethersProvider ) ;
44+ // Set up Ethereum provider and signer.
45+ const isDevnet = isSolanaDevnet ( provider ) ;
46+ const nodeURL = isDevnet ? getNodeUrl ( "sepolia" , true ) : getNodeUrl ( "mainnet" , true ) ;
47+ const ethersProvider = new ethers . providers . JsonRpcProvider ( nodeURL ) ;
48+ const ethersSigner = ethers . Wallet . fromMnemonic ( requireEnv ( "MNEMONIC" ) ) . connect ( ethersProvider ) ;
5149
5250// Get the HubPool contract instance.
53- if ( ! process . env . HUB_POOL_ADDRESS ) {
54- throw new Error ( "Environment variable HUB_POOL_ADDRESS is not set" ) ;
55- }
56- const hubPoolAddress = ethers . utils . getAddress ( process . env . HUB_POOL_ADDRESS ) ;
51+ const hubPoolAddress = ethers . utils . getAddress ( requireEnv ( "HUB_POOL_ADDRESS" ) ) ;
5752const hubPool = HubPool__factory . connect ( hubPoolAddress , ethersProvider ) ;
5853
5954// CCTP domains.
@@ -79,16 +74,9 @@ async function executeRebalanceToSpokePool(): Promise<void> {
7974 const netSendAmount = resolvedArgv . netSendAmount ? BigNumber . from ( resolvedArgv . netSendAmount ) : BigNumber . from ( 0 ) ;
8075 const resumeRemoteTx = resolvedArgv . resumeRemoteTx ;
8176
82- // Resolve Solana cluster, EVM chain ID, Iris API URL and USDC addresses.
83- let isDevnet : boolean ;
84- const solanaRpcEndpoint = provider . connection . rpcEndpoint ;
85- if ( solanaRpcEndpoint . includes ( "devnet" ) ) isDevnet = true ;
86- else if ( solanaRpcEndpoint . includes ( "mainnet" ) ) isDevnet = false ;
87- else throw new Error ( `Unsupported solanaCluster endpoint: ${ solanaRpcEndpoint } ` ) ;
77+ // Resolve chain IDs, Iris API URL and USDC addresses.
8878 const solanaCluster = isDevnet ? "devnet" : "mainnet" ;
89- const solanaChainId = BigNumber . from (
90- BigInt ( ethers . utils . keccak256 ( ethers . utils . toUtf8Bytes ( `solana-${ solanaCluster } ` ) ) ) & BigInt ( "0xFFFFFFFFFFFFFFFF" )
91- ) ;
79+ const solanaChainId = getSolanaChainId ( solanaCluster ) ;
9280 const irisApiUrl = isDevnet ? CIRCLE_IRIS_API_URL_DEVNET : CIRCLE_IRIS_API_URL_MAINNET ;
9381 const supportedEvmChainId = isDevnet ? CHAIN_IDs . SEPOLIA : CHAIN_IDs . MAINNET ; // Sepolia is bridged to devnet, Ethereum to mainnet in CCTP.
9482 const evmChainId = ( await ethersProvider . getNetwork ( ) ) . chainId ;
0 commit comments