@@ -35,7 +35,7 @@ import { NttManager__factory } from "../evm_binding/factories/NttManager__factor
35
35
import { TransceiverStructs__factory } from "../evm_binding/factories/TransceiverStructs__factory" ;
36
36
import { TrimmedAmountLib__factory } from "../evm_binding/factories/TrimmedAmount.sol/TrimmedAmountLib__factory" ;
37
37
import { WormholeTransceiver__factory } from "../evm_binding/factories/WormholeTransceiver__factory" ;
38
- import { NTT } from "../solana_binding/ts/sdk" ;
38
+ import { NTT , NttProgramId } from "../solana_binding/ts/sdk" ;
39
39
import solanaTiltKey from "./solana-tilt.json" ; // from https://github.com/wormhole-foundation/wormhole/blob/main/solana/keys/solana-devnet.json
40
40
41
41
// NOTE: This test uses ethers-v5 as it has proven to be significantly faster than v6.
@@ -53,6 +53,7 @@ interface EVMChainDetails extends BaseDetails {
53
53
interface SolanaChainDetails extends BaseDetails {
54
54
type : "solana" ;
55
55
signer : web3 . Keypair ;
56
+ manager : NTT ;
56
57
}
57
58
interface BaseDetails {
58
59
chainId : ChainId ;
@@ -84,10 +85,6 @@ const SOL_CONNECTION = new web3.Connection(
84
85
"confirmed"
85
86
) ;
86
87
const SOL_CORE_ADDRESS = "Bridge1p5gheXUvJ6jGWGeCsgPKgnE3YgdGKRVCMY9o" ;
87
- const SOL_NTT_CONTRACT = new NTT ( SOL_CONNECTION , {
88
- nttId : "NTTManager111111111111111111111111111111111" ,
89
- wormholeId : SOL_CORE_ADDRESS ,
90
- } ) ;
91
88
const RELAYER_CONTRACT = "0x53855d4b64E9A3CF59A84bc768adA716B5536BC5" ;
92
89
93
90
// Wormhole format means that addresses are bytes32 instead of addresses when using them to support other chains.
@@ -265,8 +262,20 @@ async function deployEvm(
265
262
} ;
266
263
}
267
264
268
- async function initSolana ( mode : Mode ) : Promise < SolanaChainDetails > {
269
- console . log ( "Using public key" , SOL_PUBLIC_KEY . toString ( ) ) ;
265
+ async function initSolana (
266
+ mode : Mode ,
267
+ nttId : NttProgramId
268
+ ) : Promise < SolanaChainDetails > {
269
+ console . log (
270
+ "Using public key" ,
271
+ SOL_PUBLIC_KEY . toString ( ) ,
272
+ "and manager address" ,
273
+ nttId
274
+ ) ;
275
+ const manager = new NTT ( SOL_CONNECTION , {
276
+ nttId,
277
+ wormholeId : SOL_CORE_ADDRESS ,
278
+ } ) ;
270
279
const mint = await spl . createMint (
271
280
SOL_CONNECTION ,
272
281
SOL_PRIVATE_KEY ,
@@ -289,7 +298,7 @@ async function initSolana(mode: Mode): Promise<SolanaChainDetails> {
289
298
mint ,
290
299
tokenAccount ,
291
300
SOL_PRIVATE_KEY ,
292
- BigInt ( 10000000 )
301
+ utils . parseUnits ( "100" , 9 ) . toBigInt ( )
293
302
) ;
294
303
console . log ( "Minted 10000000 tokens" ) ;
295
304
}
@@ -299,30 +308,27 @@ async function initSolana(mode: Mode): Promise<SolanaChainDetails> {
299
308
mint ,
300
309
SOL_PRIVATE_KEY ,
301
310
0 , // mint
302
- SOL_NTT_CONTRACT . tokenAuthorityAddress ( )
311
+ manager . tokenAuthorityAddress ( )
303
312
) ;
304
313
console . log (
305
314
"Set token authority to" ,
306
- SOL_NTT_CONTRACT . tokenAuthorityAddress ( ) . toString ( )
315
+ manager . tokenAuthorityAddress ( ) . toString ( )
307
316
) ;
308
317
309
- await SOL_NTT_CONTRACT . initialize ( {
318
+ await manager . initialize ( {
310
319
payer : SOL_PRIVATE_KEY ,
311
320
owner : SOL_PRIVATE_KEY ,
312
321
chain : "solana" ,
313
322
mint,
314
323
outboundLimit : new BN ( 1000000000 ) ,
315
324
mode,
316
325
} ) ;
317
- console . log (
318
- "Initialized ntt at" ,
319
- SOL_NTT_CONTRACT . program . programId . toString ( )
320
- ) ;
326
+ console . log ( "Initialized ntt at" , manager . program . programId . toString ( ) ) ;
321
327
322
- await SOL_NTT_CONTRACT . registerTransceiver ( {
328
+ await manager . registerTransceiver ( {
323
329
payer : SOL_PRIVATE_KEY ,
324
330
owner : SOL_PRIVATE_KEY ,
325
- transceiver : SOL_NTT_CONTRACT . program . programId ,
331
+ transceiver : manager . program . programId ,
326
332
} ) ;
327
333
console . log ( "Registered transceiver with self" ) ;
328
334
@@ -331,23 +337,25 @@ async function initSolana(mode: Mode): Promise<SolanaChainDetails> {
331
337
chainId : 1 ,
332
338
chainName : "solana" ,
333
339
mode,
334
- transceiverAddress : SOL_NTT_CONTRACT . emitterAccountAddress ( ) . toString ( ) ,
335
- managerAddress : SOL_NTT_CONTRACT . program . programId . toString ( ) ,
340
+ transceiverAddress : manager . emitterAccountAddress ( ) . toString ( ) ,
341
+ managerAddress : manager . program . programId . toString ( ) ,
336
342
NTTTokenAddress : mint . toString ( ) ,
337
343
wormholeCoreAddress : SOL_CORE_ADDRESS ,
338
344
signer : SOL_PRIVATE_KEY ,
345
+ manager,
339
346
} ;
340
347
}
341
348
342
349
async function setupPeer ( targetInfo : ChainDetails , peerInfo : ChainDetails ) {
343
350
const managerAddress =
344
351
peerInfo . type === "evm"
345
352
? addressToBytes32 ( peerInfo . managerAddress )
346
- : `0x${ SOL_NTT_CONTRACT . program . programId . toBuffer ( ) . toString ( "hex" ) } ` ;
353
+ : `0x${ peerInfo . manager . program . programId . toBuffer ( ) . toString ( "hex" ) } ` ;
347
354
const transceiverEmitter =
348
355
peerInfo . type === "evm"
349
356
? addressToBytes32 ( peerInfo . transceiverAddress )
350
- : `0x${ SOL_NTT_CONTRACT . emitterAccountAddress ( )
357
+ : `0x${ peerInfo . manager
358
+ . emitterAccountAddress ( )
351
359
. toBuffer ( )
352
360
. toString ( "hex" ) } `;
353
361
const tokenDecimals = peerInfo . type === "evm" ? 18 : 9 ;
@@ -384,13 +392,13 @@ async function setupPeer(targetInfo: ChainDetails, peerInfo: ChainDetails) {
384
392
) ;
385
393
}
386
394
} else if ( targetInfo . type === "solana" ) {
387
- await SOL_NTT_CONTRACT . setWormholeTransceiverPeer ( {
395
+ await targetInfo . manager . setWormholeTransceiverPeer ( {
388
396
payer : SOL_PRIVATE_KEY ,
389
397
owner : SOL_PRIVATE_KEY ,
390
398
chain : coalesceChainName ( peerInfo . chainId ) ,
391
399
address : Buffer . from ( transceiverEmitter . substring ( 2 ) , "hex" ) ,
392
400
} ) ;
393
- await SOL_NTT_CONTRACT . setPeer ( {
401
+ await targetInfo . manager . setPeer ( {
394
402
payer : SOL_PRIVATE_KEY ,
395
403
owner : SOL_PRIVATE_KEY ,
396
404
chain : coalesceChainName ( peerInfo . chainId ) ,
@@ -449,7 +457,7 @@ async function receive(
449
457
SOL_PUBLIC_KEY ,
450
458
vaa
451
459
) ;
452
- const released = await SOL_NTT_CONTRACT . redeem ( {
460
+ const released = await chainDest . manager . redeem ( {
453
461
payer : SOL_PRIVATE_KEY ,
454
462
vaa,
455
463
} ) ;
@@ -471,12 +479,12 @@ async function getManagerAndUserBalance(
471
479
await token . balanceOf ( ETH_PUBLIC_KEY ) ,
472
480
] ;
473
481
} else if ( chain . type === "solana" ) {
474
- const mintAddress = await SOL_NTT_CONTRACT . mintAccountAddress ( ) ;
482
+ const mintAddress = await chain . manager . mintAccountAddress ( ) ;
475
483
const associatedTokenAddress = spl . getAssociatedTokenAddressSync (
476
484
mintAddress ,
477
485
SOL_PUBLIC_KEY
478
486
) ;
479
- const custodyAddress = await SOL_NTT_CONTRACT . custodyAccountAddress (
487
+ const custodyAddress = await chain . manager . custodyAccountAddress (
480
488
mintAddress
481
489
) ;
482
490
return [
@@ -545,12 +553,12 @@ async function transferWithChecks(
545
553
sourceChain . wormholeCoreAddress
546
554
) ;
547
555
} else if ( sourceChain . type === "solana" ) {
548
- const mintAddress = await SOL_NTT_CONTRACT . mintAccountAddress ( ) ;
556
+ const mintAddress = await sourceChain . manager . mintAccountAddress ( ) ;
549
557
const associatedTokenAddress = spl . getAssociatedTokenAddressSync (
550
558
mintAddress ,
551
559
SOL_PUBLIC_KEY
552
560
) ;
553
- const outboxItem = await SOL_NTT_CONTRACT . transfer ( {
561
+ const outboxItem = await sourceChain . manager . transfer ( {
554
562
payer : SOL_PRIVATE_KEY ,
555
563
from : associatedTokenAddress ,
556
564
fromAuthority : SOL_PRIVATE_KEY ,
@@ -563,7 +571,7 @@ async function transferWithChecks(
563
571
shouldQueue : false ,
564
572
} ) ;
565
573
const wormholeMessage =
566
- SOL_NTT_CONTRACT . wormholeMessageAccountAddress ( outboxItem ) ;
574
+ sourceChain . manager . wormholeMessageAccountAddress ( outboxItem ) ;
567
575
const wormholeMessageAccount = await SOL_CONNECTION . getAccountInfo (
568
576
wormholeMessage
569
577
) ;
@@ -573,7 +581,8 @@ async function transferWithChecks(
573
581
const messageData = PostedMessageData . deserialize (
574
582
wormholeMessageAccount . data
575
583
) ;
576
- emitterAddress = SOL_NTT_CONTRACT . emitterAccountAddress ( )
584
+ emitterAddress = sourceChain . manager
585
+ . emitterAccountAddress ( )
577
586
. toBuffer ( )
578
587
. toString ( "hex" ) ;
579
588
sequence = messageData . message . sequence . toString ( ) ;
@@ -634,6 +643,7 @@ async function transferWithChecks(
634
643
}
635
644
636
645
async function testEthHub ( ) {
646
+ console . log ( "\n\n\n***\nEth Hub Test\n***" ) ;
637
647
console . log ( "\nDeploying on eth-devnet" ) ;
638
648
console . log ( "===============================================" ) ;
639
649
const ethInfo = await deployEvm ( ETH_SIGNER , "ethereum" , "locking" ) ;
@@ -642,7 +652,10 @@ async function testEthHub() {
642
652
const bscInfo = await deployEvm ( BSC_SIGNER , "bsc" , "burning" ) ;
643
653
console . log ( "\nInitializing on solana-devnet" ) ;
644
654
console . log ( "===============================================" ) ;
645
- const solInfo = await initSolana ( "burning" ) ;
655
+ const solInfo = await initSolana (
656
+ "burning" ,
657
+ "NTTManager111111111111111111111111111111111"
658
+ ) ;
646
659
await link ( [ ethInfo , bscInfo , solInfo ] ) ;
647
660
console . log ( "\nStarting tests" ) ;
648
661
console . log ( "========================" ) ;
@@ -662,4 +675,32 @@ async function testEthHub() {
662
675
// TODO: corrupted or bad VAA usage
663
676
}
664
677
665
- testEthHub ( ) ;
678
+ async function testSolanaHub ( ) {
679
+ console . log ( "\n\n\n***\nSolana Hub Test\n***" ) ;
680
+ console . log ( "\nDeploying on eth-devnet" ) ;
681
+ console . log ( "===============================================" ) ;
682
+ const ethInfo = await deployEvm ( ETH_SIGNER , "ethereum" , "burning" ) ;
683
+ console . log ( "\nDeploying on eth-devnet2" ) ;
684
+ console . log ( "===============================================" ) ;
685
+ const bscInfo = await deployEvm ( BSC_SIGNER , "bsc" , "burning" ) ;
686
+ console . log ( "\nInitializing on solana-devnet" ) ;
687
+ console . log ( "===============================================" ) ;
688
+ const solInfo = await initSolana (
689
+ "locking" ,
690
+ "NTTManager222222222222222222222222222222222"
691
+ ) ;
692
+ await link ( [ ethInfo , bscInfo , solInfo ] ) ;
693
+ console . log ( "\nStarting tests" ) ;
694
+ console . log ( "========================" ) ;
695
+ console . log ( "Solana -> Eth -> BSC -> Solana" ) ;
696
+ await transferWithChecks ( solInfo , ethInfo ) ;
697
+ await transferWithChecks ( ethInfo , bscInfo ) ;
698
+ await transferWithChecks ( bscInfo , solInfo ) ;
699
+ }
700
+
701
+ async function test ( ) {
702
+ await testEthHub ( ) ;
703
+ await testSolanaHub ( ) ;
704
+ }
705
+
706
+ test ( ) ;
0 commit comments