@unclaimedsol/spl-burn-close-sdk 1.0.4 → 1.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs CHANGED
@@ -8,14 +8,15 @@ const TOKEN_PROGRAM_ID = new PublicKey("TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ
8
8
  * Build *unsigned* transactions that call the on-chain burn+close program.
9
9
  * You sign and send them yourself (frontend wallet or backend keypair).
10
10
  *
11
- * @param connection Solana RPC connection
12
- * @param programId Your deployed program ID
13
- * @param user The user whose ATAs will be burned/closed
14
- * @param pairs Array of { mint, ata } to process
15
- * @param options Chunking / blockhash / payer tweaks
16
- * @returns Array of *unsigned* Transaction objects
11
+ * @param connection Solana RPC connection
12
+ * @param programId Your deployed program ID
13
+ * @param user The user whose ATAs will be burned/closed
14
+ * @param pairs Array of { mint, ata } to process
15
+ * @param options Chunking / blockhash / payer tweaks
16
+ * @param tokenProgramId Support for multiple Token programs
17
+ * @returns Array of *unsigned* Transaction objects
17
18
  */
18
- export async function buildBurnAndCloseTransactions(connection, programId, user, pairs, options = {}) {
19
+ export async function buildBurnAndCloseTransactions(connection, programId, user, pairs, options = {}, tokenProgramId = TOKEN_PROGRAM_ID) {
19
20
  if (!pairs.length)
20
21
  return [];
21
22
  const chunkSize = Math.max(1, options.chunkSize ?? 12);
@@ -35,7 +36,7 @@ export async function buildBurnAndCloseTransactions(connection, programId, user,
35
36
  // the caller must actually sign the Transaction later.
36
37
  { pubkey: FEE_RECIPIENT, isSigner: false, isWritable: true },
37
38
  { pubkey: user, isSigner: true, isWritable: true },
38
- { pubkey: TOKEN_PROGRAM_ID, isSigner: false, isWritable: false },
39
+ { pubkey: tokenProgramId, isSigner: false, isWritable: false },
39
40
  { pubkey: SystemProgram.programId, isSigner: false, isWritable: false },
40
41
  ];
41
42
  for (const { mint, ata } of chunk) {
@@ -60,3 +61,38 @@ export async function buildBurnAndCloseTransactions(connection, programId, user,
60
61
  }
61
62
  return txs;
62
63
  }
64
+ /**
65
+ * Build a single **TransactionInstruction** that calls the on-chain
66
+ * burn+close program for a specific Token Program (either SPL Token or Token-2022).
67
+ *
68
+ * Unlike `buildBurnAndCloseTransactions`, this helper does **not**
69
+ * create or sign full transactions — it only constructs one
70
+ * instruction for a batch of (mint, ATA) pairs.
71
+ */
72
+ export async function buildBurnAndCloseInstruction(programId, user, pairs, tokenProgramId) {
73
+ if (!pairs.length) {
74
+ return null;
75
+ }
76
+ // instruction data selector: 0 = burn_and_close_token_accounts
77
+ const data = Buffer.from([0]);
78
+ // accounts order MUST match the on-chain program's expectation:
79
+ // [0] fee_payer_account (your fee recipient)
80
+ // [1] user_wallet_account (the signer)
81
+ // [2] token_program_account (SPL Token program or Token-2022 program)
82
+ // [3] system_program_account
83
+ // then repeating (mint, ata) pairs, both writable
84
+ const keys = [
85
+ { pubkey: FEE_RECIPIENT, isSigner: false, isWritable: true },
86
+ { pubkey: user, isSigner: true, isWritable: true },
87
+ { pubkey: tokenProgramId, isSigner: false, isWritable: false },
88
+ { pubkey: SystemProgram.programId, isSigner: false, isWritable: false },
89
+ ];
90
+ for (const { mint, ata } of pairs) {
91
+ keys.push({ pubkey: mint, isSigner: false, isWritable: true }, { pubkey: ata, isSigner: false, isWritable: true });
92
+ }
93
+ return new TransactionInstruction({
94
+ programId,
95
+ keys,
96
+ data,
97
+ });
98
+ }
package/dist/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { Connection, PublicKey, Transaction, Commitment } from "@solana/web3.js";
1
+ import { Connection, PublicKey, Transaction, TransactionInstruction, Commitment } from "@solana/web3.js";
2
2
  /** Exporting on-chain program ID for convenience */
3
3
  export declare const PROGRAM_ID: PublicKey;
4
4
  /** Hardcoded fee recipient on-chain expectation */
@@ -28,11 +28,21 @@ export type BuildOptions = {
28
28
  * Build *unsigned* transactions that call the on-chain burn+close program.
29
29
  * You sign and send them yourself (frontend wallet or backend keypair).
30
30
  *
31
- * @param connection Solana RPC connection
32
- * @param programId Your deployed program ID
33
- * @param user The user whose ATAs will be burned/closed
34
- * @param pairs Array of { mint, ata } to process
35
- * @param options Chunking / blockhash / payer tweaks
36
- * @returns Array of *unsigned* Transaction objects
31
+ * @param connection Solana RPC connection
32
+ * @param programId Your deployed program ID
33
+ * @param user The user whose ATAs will be burned/closed
34
+ * @param pairs Array of { mint, ata } to process
35
+ * @param options Chunking / blockhash / payer tweaks
36
+ * @param tokenProgramId Support for multiple Token programs
37
+ * @returns Array of *unsigned* Transaction objects
37
38
  */
38
- export declare function buildBurnAndCloseTransactions(connection: Connection, programId: PublicKey, user: PublicKey, pairs: Pair[], options?: BuildOptions): Promise<Transaction[]>;
39
+ export declare function buildBurnAndCloseTransactions(connection: Connection, programId: PublicKey, user: PublicKey, pairs: Pair[], options?: BuildOptions, tokenProgramId?: PublicKey): Promise<Transaction[]>;
40
+ /**
41
+ * Build a single **TransactionInstruction** that calls the on-chain
42
+ * burn+close program for a specific Token Program (either SPL Token or Token-2022).
43
+ *
44
+ * Unlike `buildBurnAndCloseTransactions`, this helper does **not**
45
+ * create or sign full transactions — it only constructs one
46
+ * instruction for a batch of (mint, ATA) pairs.
47
+ */
48
+ export declare function buildBurnAndCloseInstruction(programId: PublicKey, user: PublicKey, pairs: Pair[], tokenProgramId: PublicKey): Promise<TransactionInstruction | null>;
package/dist/index.js CHANGED
@@ -8,14 +8,15 @@ export const TOKEN_PROGRAM_ID = new PublicKey("TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9
8
8
  * Build *unsigned* transactions that call the on-chain burn+close program.
9
9
  * You sign and send them yourself (frontend wallet or backend keypair).
10
10
  *
11
- * @param connection Solana RPC connection
12
- * @param programId Your deployed program ID
13
- * @param user The user whose ATAs will be burned/closed
14
- * @param pairs Array of { mint, ata } to process
15
- * @param options Chunking / blockhash / payer tweaks
16
- * @returns Array of *unsigned* Transaction objects
11
+ * @param connection Solana RPC connection
12
+ * @param programId Your deployed program ID
13
+ * @param user The user whose ATAs will be burned/closed
14
+ * @param pairs Array of { mint, ata } to process
15
+ * @param options Chunking / blockhash / payer tweaks
16
+ * @param tokenProgramId Support for multiple Token programs
17
+ * @returns Array of *unsigned* Transaction objects
17
18
  */
18
- export async function buildBurnAndCloseTransactions(connection, programId, user, pairs, options = {}) {
19
+ export async function buildBurnAndCloseTransactions(connection, programId, user, pairs, options = {}, tokenProgramId = TOKEN_PROGRAM_ID) {
19
20
  if (!pairs.length)
20
21
  return [];
21
22
  const chunkSize = Math.max(1, options.chunkSize ?? 12);
@@ -35,7 +36,7 @@ export async function buildBurnAndCloseTransactions(connection, programId, user,
35
36
  // the caller must actually sign the Transaction later.
36
37
  { pubkey: FEE_RECIPIENT, isSigner: false, isWritable: true },
37
38
  { pubkey: user, isSigner: true, isWritable: true },
38
- { pubkey: TOKEN_PROGRAM_ID, isSigner: false, isWritable: false },
39
+ { pubkey: tokenProgramId, isSigner: false, isWritable: false },
39
40
  { pubkey: SystemProgram.programId, isSigner: false, isWritable: false },
40
41
  ];
41
42
  for (const { mint, ata } of chunk) {
@@ -60,3 +61,38 @@ export async function buildBurnAndCloseTransactions(connection, programId, user,
60
61
  }
61
62
  return txs;
62
63
  }
64
+ /**
65
+ * Build a single **TransactionInstruction** that calls the on-chain
66
+ * burn+close program for a specific Token Program (either SPL Token or Token-2022).
67
+ *
68
+ * Unlike `buildBurnAndCloseTransactions`, this helper does **not**
69
+ * create or sign full transactions — it only constructs one
70
+ * instruction for a batch of (mint, ATA) pairs.
71
+ */
72
+ export async function buildBurnAndCloseInstruction(programId, user, pairs, tokenProgramId) {
73
+ if (!pairs.length) {
74
+ return null;
75
+ }
76
+ // instruction data selector: 0 = burn_and_close_token_accounts
77
+ const data = Buffer.from([0]);
78
+ // accounts order MUST match the on-chain program's expectation:
79
+ // [0] fee_payer_account (your fee recipient)
80
+ // [1] user_wallet_account (the signer)
81
+ // [2] token_program_account (SPL Token program or Token-2022 program)
82
+ // [3] system_program_account
83
+ // then repeating (mint, ata) pairs, both writable
84
+ const keys = [
85
+ { pubkey: FEE_RECIPIENT, isSigner: false, isWritable: true },
86
+ { pubkey: user, isSigner: true, isWritable: true },
87
+ { pubkey: tokenProgramId, isSigner: false, isWritable: false },
88
+ { pubkey: SystemProgram.programId, isSigner: false, isWritable: false },
89
+ ];
90
+ for (const { mint, ata } of pairs) {
91
+ keys.push({ pubkey: mint, isSigner: false, isWritable: true }, { pubkey: ata, isSigner: false, isWritable: true });
92
+ }
93
+ return new TransactionInstruction({
94
+ programId,
95
+ keys,
96
+ data,
97
+ });
98
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@unclaimedsol/spl-burn-close-sdk",
3
- "version": "1.0.4",
3
+ "version": "1.2.0",
4
4
  "description": "SDK to burn and close SPL token accounts via the Unclaimed SOL program (with a built-in 5% fee).",
5
5
  "license": "MIT",
6
6
  "author": "Unclaimed SOL",