@@ -436,20 +436,29 @@ export class PythSolanaReceiver {
436436 readonly receiver : Program < PythSolanaReceiverProgram > ;
437437 readonly wormhole : Program < WormholeCoreBridgeSolana > ;
438438 readonly pushOracle : Program < PythPushOracle > ;
439-
439+ readonly treasuryId ?: number ;
440440 constructor ( {
441441 connection,
442442 wallet,
443443 wormholeProgramId = DEFAULT_WORMHOLE_PROGRAM_ID ,
444444 receiverProgramId = DEFAULT_RECEIVER_PROGRAM_ID ,
445445 pushOracleProgramId = DEFAULT_PUSH_ORACLE_PROGRAM_ID ,
446+ treasuryId = undefined ,
446447 } : {
447448 connection : Connection ;
448449 wallet : Wallet ;
449450 wormholeProgramId ?: PublicKey ;
450451 receiverProgramId ?: PublicKey ;
451452 pushOracleProgramId ?: PublicKey ;
453+ // Optionally provide a treasuryId to always use a specific treasury account.
454+ // This can be useful when using an ALT to reduce tx size.
455+ // If not provided, treasury accounts will be randomly selected.
456+ treasuryId ?: number ;
452457 } ) {
458+ if ( treasuryId !== undefined && ( treasuryId < 0 || treasuryId > 255 ) ) {
459+ throw new Error ( "treasuryId must be between 0 and 255" ) ;
460+ }
461+
453462 this . connection = connection ;
454463 this . wallet = wallet ;
455464 this . provider = new AnchorProvider ( this . connection , this . wallet , {
@@ -470,16 +479,17 @@ export class PythSolanaReceiver {
470479 pushOracleProgramId ,
471480 this . provider
472481 ) ;
482+ this . treasuryId = treasuryId ;
473483 }
474484
475485 /**
476486 * Get a new transaction builder to build transactions that interact with the Pyth Solana Receiver program and consume price updates
477487 */
478488 newTransactionBuilder (
479489 config : PythTransactionBuilderConfig ,
480- address_lookup_account ?: AddressLookupTableAccount
490+ addressLookupAccount ?: AddressLookupTableAccount
481491 ) : PythTransactionBuilder {
482- return new PythTransactionBuilder ( this , config , address_lookup_account ) ;
492+ return new PythTransactionBuilder ( this , config , addressLookupAccount ) ;
483493 }
484494
485495 /**
@@ -504,7 +514,7 @@ export class PythSolanaReceiver {
504514 const priceFeedIdToPriceUpdateAccount : Record < string , PublicKey > = { } ;
505515 const closeInstructions : InstructionWithEphemeralSigners [ ] = [ ] ;
506516
507- const treasuryId = DEFAULT_TREASURY_ID ;
517+ const treasuryId = this . treasuryId ?? getRandomTreasuryId ( ) ;
508518
509519 for ( const priceUpdateData of priceUpdateDataArray ) {
510520 const accumulatorUpdateData = parseAccumulatorUpdateData (
@@ -572,7 +582,7 @@ export class PythSolanaReceiver {
572582 const priceFeedIdToPriceUpdateAccount : Record < string , PublicKey > = { } ;
573583 const closeInstructions : InstructionWithEphemeralSigners [ ] = [ ] ;
574584
575- const treasuryId = getRandomTreasuryId ( ) ;
585+ const treasuryId = this . treasuryId ?? getRandomTreasuryId ( ) ;
576586
577587 for ( const priceUpdateData of priceUpdateDataArray ) {
578588 const accumulatorUpdateData = parseAccumulatorUpdateData (
@@ -643,7 +653,7 @@ export class PythSolanaReceiver {
643653 const priceFeedIdToTwapUpdateAccount : Record < string , PublicKey > = { } ;
644654 const closeInstructions : InstructionWithEphemeralSigners [ ] = [ ] ;
645655
646- const treasuryId = getRandomTreasuryId ( ) ;
656+ const treasuryId = this . treasuryId ?? getRandomTreasuryId ( ) ;
647657
648658 if ( twapUpdateDataArray . length !== 2 ) {
649659 throw new Error (
@@ -737,7 +747,7 @@ export class PythSolanaReceiver {
737747 const priceFeedIdToPriceUpdateAccount : Record < string , PublicKey > = { } ;
738748 const closeInstructions : InstructionWithEphemeralSigners [ ] = [ ] ;
739749
740- const treasuryId = DEFAULT_TREASURY_ID ;
750+ const treasuryId = this . treasuryId ?? getRandomTreasuryId ( ) ;
741751
742752 for ( const priceUpdateData of priceUpdateDataArray ) {
743753 const accumulatorUpdateData = parseAccumulatorUpdateData (
0 commit comments