@@ -21,6 +21,7 @@ import {
21
21
SolanaChains ,
22
22
SolanaPlatform ,
23
23
SolanaPlatformType ,
24
+ SolanaTransaction ,
24
25
SolanaUnsignedTransaction ,
25
26
} from '@wormhole-foundation/connect-sdk-solana' ;
26
27
import {
@@ -211,7 +212,6 @@ export class SolanaTokenBridge<N extends Network, C extends SolanaChains>
211
212
) : AsyncGenerator < SolanaUnsignedTransaction < N , C > > {
212
213
if ( ! payer ) throw new Error ( 'Payer required to create attestation' ) ;
213
214
214
- const { blockhash } = await SolanaPlatform . latestBlock ( this . connection ) ;
215
215
const senderAddress = new SolanaAddress ( payer ) . unwrap ( ) ;
216
216
// TODO: createNonce().readUInt32LE(0);
217
217
const nonce = 0 ;
@@ -235,11 +235,11 @@ export class SolanaTokenBridge<N extends Network, C extends SolanaChains>
235
235
) ;
236
236
237
237
const transaction = new Transaction ( ) . add ( transferIx , attestIx ) ;
238
- transaction . recentBlockhash = blockhash ;
239
238
transaction . feePayer = senderAddress ;
240
- transaction . partialSign ( messageKey ) ;
241
-
242
- yield this . createUnsignedTx ( transaction , 'Solana.AttestToken' ) ;
239
+ yield this . createUnsignedTx (
240
+ { transaction, signers : [ messageKey ] } ,
241
+ 'Solana.AttestToken' ,
242
+ ) ;
243
243
}
244
244
245
245
async * submitAttestation (
@@ -248,11 +248,10 @@ export class SolanaTokenBridge<N extends Network, C extends SolanaChains>
248
248
) : AsyncGenerator < SolanaUnsignedTransaction < N , C > > {
249
249
if ( ! payer ) throw new Error ( 'Payer required to create attestation' ) ;
250
250
251
- const { blockhash } = await SolanaPlatform . latestBlock ( this . connection ) ;
252
251
const senderAddress = new SolanaAddress ( payer ) . unwrap ( ) ;
253
252
254
253
// Yield transactions to verify sigs and post the VAA
255
- yield * this . coreBridge . postVaa ( senderAddress , vaa , blockhash ) ;
254
+ yield * this . coreBridge . postVaa ( senderAddress , vaa ) ;
256
255
257
256
// Now yield the transaction to actually create the token
258
257
const transaction = new Transaction ( ) . add (
@@ -264,10 +263,9 @@ export class SolanaTokenBridge<N extends Network, C extends SolanaChains>
264
263
vaa ,
265
264
) ,
266
265
) ;
267
- transaction . recentBlockhash = blockhash ;
268
266
transaction . feePayer = senderAddress ;
269
267
270
- yield this . createUnsignedTx ( transaction , 'Solana.CreateWrapped' ) ;
268
+ yield this . createUnsignedTx ( { transaction } , 'Solana.CreateWrapped' ) ;
271
269
}
272
270
273
271
private async transferSol (
@@ -278,7 +276,6 @@ export class SolanaTokenBridge<N extends Network, C extends SolanaChains>
278
276
) : Promise < SolanaUnsignedTransaction < N , C > > {
279
277
// https://github.com/wormhole-foundation/wormhole-connect/blob/development/sdk/src/contexts/solana/context.ts#L245
280
278
281
- const { blockhash } = await SolanaPlatform . latestBlock ( this . connection ) ;
282
279
const senderAddress = new SolanaAddress ( sender ) . unwrap ( ) ;
283
280
284
281
// TODO: the payer can actually be different from the sender. We need to allow the user to pass in an optional payer
@@ -368,7 +365,6 @@ export class SolanaTokenBridge<N extends Network, C extends SolanaChains>
368
365
) ;
369
366
370
367
const transaction = new Transaction ( ) ;
371
- transaction . recentBlockhash = blockhash ;
372
368
transaction . feePayer = payerPublicKey ;
373
369
transaction . add (
374
370
createAncillaryAccountIx ,
@@ -378,9 +374,10 @@ export class SolanaTokenBridge<N extends Network, C extends SolanaChains>
378
374
tokenBridgeTransferIx ,
379
375
closeAccountIx ,
380
376
) ;
381
- transaction . partialSign ( message , ancillaryKeypair ) ;
382
-
383
- return this . createUnsignedTx ( transaction , 'TokenBridge.TransferNative' ) ;
377
+ return this . createUnsignedTx (
378
+ { transaction, signers : [ message , ancillaryKeypair ] } ,
379
+ 'TokenBridge.TransferNative' ,
380
+ ) ;
384
381
}
385
382
386
383
async * transfer (
@@ -397,7 +394,6 @@ export class SolanaTokenBridge<N extends Network, C extends SolanaChains>
397
394
return ;
398
395
}
399
396
400
- const { blockhash } = await SolanaPlatform . latestBlock ( this . connection ) ;
401
397
const tokenAddress = new SolanaAddress ( token ) . unwrap ( ) ;
402
398
const senderAddress = new SolanaAddress ( sender ) . unwrap ( ) ;
403
399
const senderTokenAddress = await getAssociatedTokenAddress (
@@ -497,17 +493,16 @@ export class SolanaTokenBridge<N extends Network, C extends SolanaChains>
497
493
tokenBridgeTransferIx ,
498
494
) ;
499
495
500
- transaction . recentBlockhash = blockhash ;
501
496
transaction . feePayer = senderAddress ;
502
- transaction . partialSign ( message ) ;
503
-
504
- yield this . createUnsignedTx ( transaction , 'TokenBridge.TransferTokens' ) ;
497
+ yield this . createUnsignedTx (
498
+ { transaction, signers : [ message ] } ,
499
+ 'TokenBridge.TransferTokens' ,
500
+ ) ;
505
501
}
506
502
507
503
private async * redeemAndUnwrap (
508
504
sender : AnySolanaAddress ,
509
505
vaa : TokenBridge . TransferVAA ,
510
- blockhash : string ,
511
506
) {
512
507
// sender, fee payer
513
508
const payerPublicKey = new SolanaAddress ( sender ) . unwrap ( ) ;
@@ -566,7 +561,6 @@ export class SolanaTokenBridge<N extends Network, C extends SolanaChains>
566
561
) ;
567
562
568
563
const transaction = new Transaction ( ) ;
569
- transaction . recentBlockhash = blockhash ;
570
564
transaction . feePayer = payerPublicKey ;
571
565
transaction . add (
572
566
completeTransferIx ,
@@ -575,15 +569,13 @@ export class SolanaTokenBridge<N extends Network, C extends SolanaChains>
575
569
balanceTransferIx ,
576
570
closeAccountIx ,
577
571
) ;
578
- transaction . partialSign ( ancillaryKeypair ) ;
579
- yield this . createUnsignedTx ( transaction , 'TokenBridge.RedeemAndUnwrap' ) ;
572
+ yield this . createUnsignedTx (
573
+ { transaction, signers : [ ancillaryKeypair ] } ,
574
+ 'TokenBridge.RedeemAndUnwrap' ,
575
+ ) ;
580
576
}
581
577
582
- private async * createAta (
583
- sender : AnySolanaAddress ,
584
- token : AnySolanaAddress ,
585
- blockhash : string ,
586
- ) {
578
+ private async * createAta ( sender : AnySolanaAddress , token : AnySolanaAddress ) {
587
579
const senderAddress = new SolanaAddress ( sender ) . unwrap ( ) ;
588
580
const tokenAddress = new SolanaAddress ( token ) . unwrap ( ) ;
589
581
@@ -592,17 +584,16 @@ export class SolanaTokenBridge<N extends Network, C extends SolanaChains>
592
584
// If the ata doesn't exist yet, create it
593
585
const acctInfo = await this . connection . getAccountInfo ( ata ) ;
594
586
if ( acctInfo === null ) {
595
- const ataCreationTx = new Transaction ( ) . add (
587
+ const transaction = new Transaction ( ) . add (
596
588
createAssociatedTokenAccountInstruction (
597
589
senderAddress ,
598
590
ata ,
599
591
senderAddress ,
600
592
tokenAddress ,
601
593
) ,
602
594
) ;
603
- ataCreationTx . feePayer = senderAddress ;
604
- ataCreationTx . recentBlockhash = blockhash ;
605
- yield this . createUnsignedTx ( ataCreationTx , 'Redeem.CreateATA' ) ;
595
+ transaction . feePayer = senderAddress ;
596
+ yield this . createUnsignedTx ( { transaction } , 'Redeem.CreateATA' ) ;
606
597
}
607
598
}
608
599
@@ -611,19 +602,17 @@ export class SolanaTokenBridge<N extends Network, C extends SolanaChains>
611
602
vaa : TokenBridge . TransferVAA ,
612
603
unwrapNative : boolean = true ,
613
604
) {
614
- const { blockhash } = await SolanaPlatform . latestBlock ( this . connection ) ;
615
-
616
605
// Find the token address local to this chain
617
606
const nativeAddress =
618
607
vaa . payload . token . chain === this . chain
619
608
? vaa . payload . token . address
620
609
: ( await this . getWrappedAsset ( vaa . payload . token ) ) . toUniversalAddress ( ) ;
621
610
622
611
// Create an ATA if necessary
623
- yield * this . createAta ( sender , nativeAddress , blockhash ) ;
612
+ yield * this . createAta ( sender , nativeAddress ) ;
624
613
625
614
// Post the VAA if necessary
626
- yield * this . coreBridge . postVaa ( sender , vaa , blockhash ) ;
615
+ yield * this . coreBridge . postVaa ( sender , vaa ) ;
627
616
628
617
// redeem vaa and unwrap to native sol from wrapped sol
629
618
if ( unwrapNative ) {
@@ -635,7 +624,7 @@ export class SolanaTokenBridge<N extends Network, C extends SolanaChains>
635
624
wrappedNative . toUint8Array ( ) ,
636
625
)
637
626
) {
638
- yield * this . redeemAndUnwrap ( sender , vaa , blockhash ) ;
627
+ yield * this . redeemAndUnwrap ( sender , vaa ) ;
639
628
return ;
640
629
}
641
630
}
@@ -656,14 +645,12 @@ export class SolanaTokenBridge<N extends Network, C extends SolanaChains>
656
645
vaa ,
657
646
) ,
658
647
) ;
659
-
660
- transaction . recentBlockhash = blockhash ;
661
648
transaction . feePayer = senderAddress ;
662
- yield this . createUnsignedTx ( transaction , 'Solana.RedeemTransfer' ) ;
649
+ yield this . createUnsignedTx ( { transaction } , 'Solana.RedeemTransfer' ) ;
663
650
}
664
651
665
652
private createUnsignedTx (
666
- txReq : Transaction ,
653
+ txReq : SolanaTransaction ,
667
654
description : string ,
668
655
parallelizable : boolean = false ,
669
656
) : SolanaUnsignedTransaction < N , C > {
0 commit comments