@@ -14,7 +14,12 @@ const MIX_API_ERROR_MESSAGE =
1414
1515export class CloseAtaBuilder extends TransactionBuilder {
1616 // Unified storage for all close entries (single or bulk)
17- protected _closeAtaEntries : { accountAddress : string ; destinationAddress : string ; authorityAddress : string } [ ] = [ ] ;
17+ protected _closeAtaEntries : {
18+ accountAddress : string ;
19+ destinationAddress : string ;
20+ authorityAddress : string ;
21+ programId ?: string ;
22+ } [ ] = [ ] ;
1823
1924 // Which API has been used on this builder instance. Locks in on first call so we can
2025 // reject attempts to mix the legacy single-ATA setters with the bulk addCloseAtaInstruction().
@@ -71,6 +76,16 @@ export class CloseAtaBuilder extends TransactionBuilder {
7176 return this ;
7277 }
7378
79+ /** Sets the SPL token program used by the close instruction. */
80+ programId ( programId : string ) : this {
81+ this . _assertSingleAtaApiUsable ( ) ;
82+ validateAddress ( programId , 'programId' ) ;
83+ this . _apiMode = 'single' ;
84+ this . _ensureSingleEntry ( ) ;
85+ this . _closeAtaEntries [ 0 ] . programId = programId ;
86+ return this ;
87+ }
88+
7489 /**
7590 * Throws if the bulk-ATA API has already been used on this builder.
7691 */
@@ -93,18 +108,27 @@ export class CloseAtaBuilder extends TransactionBuilder {
93108 * Add an ATA to close in this transaction (for bulk closure).
94109 * Cannot be mixed with the single-ATA API (accountAddress/destinationAddress/authorityAddress).
95110 *
96- * @param {string } accountAddress - the ATA address to close
97- * @param {string } destinationAddress - where rent SOL goes (root wallet address)
98- * @param {string } authorityAddress - ATA owner who must sign
111+ * @param accountAddress - the ATA address to close
112+ * @param destinationAddress - where rent SOL goes (root wallet address)
113+ * @param authorityAddress - ATA owner who must sign
114+ * @param programId - SPL token program owning the ATA; omitted for legacy SPL
99115 */
100- addCloseAtaInstruction ( accountAddress : string , destinationAddress : string , authorityAddress : string ) : this {
116+ addCloseAtaInstruction (
117+ accountAddress : string ,
118+ destinationAddress : string ,
119+ authorityAddress : string ,
120+ programId ?: string
121+ ) : this {
101122 if ( this . _apiMode === 'single' ) {
102123 throw new BuildTransactionError ( MIX_API_ERROR_MESSAGE ) ;
103124 }
104125
105126 validateAddress ( accountAddress , 'accountAddress' ) ;
106127 validateAddress ( destinationAddress , 'destinationAddress' ) ;
107128 validateAddress ( authorityAddress , 'authorityAddress' ) ;
129+ if ( programId ) {
130+ validateAddress ( programId , 'programId' ) ;
131+ }
108132
109133 if ( accountAddress === destinationAddress ) {
110134 throw new BuildTransactionError ( 'Account address to close cannot be the same as the destination address' ) ;
@@ -115,7 +139,7 @@ export class CloseAtaBuilder extends TransactionBuilder {
115139 }
116140
117141 this . _apiMode = 'bulk' ;
118- this . _closeAtaEntries . push ( { accountAddress, destinationAddress, authorityAddress } ) ;
142+ this . _closeAtaEntries . push ( { accountAddress, destinationAddress, authorityAddress, programId } ) ;
119143 return this ;
120144 }
121145
@@ -129,6 +153,7 @@ export class CloseAtaBuilder extends TransactionBuilder {
129153 accountAddress : ataCloseInstruction . params . accountAddress ,
130154 destinationAddress : ataCloseInstruction . params . destinationAddress ,
131155 authorityAddress : ataCloseInstruction . params . authorityAddress ,
156+ programId : ataCloseInstruction . params . programId ,
132157 } ) ;
133158 }
134159 }
@@ -158,6 +183,7 @@ export class CloseAtaBuilder extends TransactionBuilder {
158183 accountAddress : entry . accountAddress ,
159184 destinationAddress : entry . destinationAddress ,
160185 authorityAddress : entry . authorityAddress ,
186+ ...( entry . programId ? { programId : entry . programId } : { } ) ,
161187 } ,
162188 } )
163189 ) ;
0 commit comments