@lightprotocol/compressed-token 0.20.8 → 0.21.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.
@@ -1,8 +1,351 @@
1
- import { PackedMerkleContext, CompressedProof, ParsedTokenAccount, InputTokenDataWithContext as InputTokenDataWithContext$1, Rpc } from '@lightprotocol/stateless.js';
2
- import { PublicKey, AccountMeta, TransactionInstruction, Connection, Signer, ConfirmOptions, TransactionSignature, Keypair } from '@solana/web3.js';
1
+ import { Signer, PublicKey, ConfirmOptions, TransactionSignature, Commitment, Keypair, AccountMeta, TransactionInstruction, Connection } from '@solana/web3.js';
2
+ import { Rpc, StateTreeInfo, ParsedTokenAccount, PackedMerkleContext, ValidityProof, InputTokenDataWithContext as InputTokenDataWithContext$1, CompressedProof } from '@lightprotocol/stateless.js';
3
3
  import BN from 'bn.js';
4
+ import { Buffer } from 'buffer';
4
5
  import * as buffer_layout from 'buffer-layout';
5
- import { Buffer as Buffer$1 } from 'buffer';
6
+
7
+ /**
8
+ * Approve a delegate to spend tokens
9
+ *
10
+ * @param rpc Rpc to use
11
+ * @param payer Payer of the transaction fees
12
+ * @param mint Mint of the compressed token
13
+ * @param amount Number of tokens to delegate
14
+ * @param owner Owner of the compressed tokens
15
+ * @param delegate Address of the delegate
16
+ * @param confirmOptions Options for confirming the transaction
17
+ *
18
+ * @return Signature of the confirmed transaction
19
+ */
20
+ declare function approve(rpc: Rpc, payer: Signer, mint: PublicKey, amount: number | BN, owner: Signer, delegate: PublicKey, confirmOptions?: ConfirmOptions): Promise<TransactionSignature>;
21
+
22
+ /**
23
+ * Check if the token pool info is initialized and has a balance.
24
+ * @param mint The mint of the token pool
25
+ * @param tokenPoolInfo The token pool info
26
+ * @returns True if the token pool info is initialized and has a balance
27
+ */
28
+ declare function checkTokenPoolInfo(tokenPoolInfo: TokenPoolInfo, mint: PublicKey): boolean;
29
+ /**
30
+ * Get the token pool infos for a given mint.
31
+ * @param rpc The RPC client
32
+ * @param mint The mint of the token pool
33
+ * @param commitment The commitment to use
34
+ *
35
+ * @returns The token pool infos
36
+ */
37
+ declare function getTokenPoolInfos(rpc: Rpc, mint: PublicKey, commitment?: Commitment): Promise<TokenPoolInfo[]>;
38
+ type TokenPoolActivity = {
39
+ signature: string;
40
+ amount: BN;
41
+ action: Action;
42
+ };
43
+ /**
44
+ * Token pool pda info.
45
+ */
46
+ type TokenPoolInfo = {
47
+ /**
48
+ * The mint of the token pool
49
+ */
50
+ mint: PublicKey;
51
+ /**
52
+ * The token pool address
53
+ */
54
+ tokenPoolPda: PublicKey;
55
+ /**
56
+ * The token program of the token pool
57
+ */
58
+ tokenProgram: PublicKey;
59
+ /**
60
+ * count of txs and volume in the past 60 seconds.
61
+ */
62
+ activity?: {
63
+ txs: number;
64
+ amountAdded: BN;
65
+ amountRemoved: BN;
66
+ };
67
+ /**
68
+ * Whether the token pool is initialized
69
+ */
70
+ isInitialized: boolean;
71
+ /**
72
+ * The balance of the token pool
73
+ */
74
+ balance: BN;
75
+ /**
76
+ * The index of the token pool
77
+ */
78
+ poolIndex: number;
79
+ };
80
+ /**
81
+ * @internal
82
+ */
83
+ declare enum Action {
84
+ Compress = 1,
85
+ Decompress = 2,
86
+ Transfer = 3
87
+ }
88
+ /**
89
+ * Select a random token pool info from the token pool infos.
90
+ *
91
+ * @param infos The token pool infos
92
+ *
93
+ * @returns A random token pool info
94
+ */
95
+ declare function selectTokenPoolInfo(infos: TokenPoolInfo[]): TokenPoolInfo;
96
+ /**
97
+ * Select one or multiple token pool infos from the token pool infos.
98
+ *
99
+ * Use this function for `decompress`.
100
+ *
101
+ * For `compress`, `mintTo` use {@link selectTokenPoolInfo} instead.
102
+ *
103
+ * @param infos The token pool infos
104
+ * @param decompressAmount The amount of tokens to withdraw
105
+ *
106
+ * @returns Array with one or more token pool infos.
107
+ */
108
+ declare function selectTokenPoolInfosForDecompression(infos: TokenPoolInfo[], decompressAmount: number | BN): TokenPoolInfo[];
109
+
110
+ /**
111
+ * Mint compressed tokens to a solana address from an external mint authority
112
+ *
113
+ * @param rpc Rpc to use
114
+ * @param payer Payer of the transaction fees
115
+ * @param mint Mint for the account
116
+ * @param toPubkey Address of the account to mint to
117
+ * @param authority Minting authority
118
+ * @param amount Amount to mint
119
+ * @param outputStateTreeInfo State tree info
120
+ * @param tokenPoolInfo Token pool info
121
+ * @param confirmOptions Options for confirming the transaction
122
+ *
123
+ * @return Signature of the confirmed transaction
124
+ */
125
+ declare function approveAndMintTo(rpc: Rpc, payer: Signer, mint: PublicKey, toPubkey: PublicKey, authority: Signer, amount: number | BN, outputStateTreeInfo?: StateTreeInfo, tokenPoolInfo?: TokenPoolInfo, confirmOptions?: ConfirmOptions): Promise<TransactionSignature>;
126
+
127
+ /**
128
+ * Compress SPL tokens
129
+ *
130
+ * @param rpc Rpc connection to use
131
+ * @param payer Payer of the transaction fees
132
+ * @param mint Mint of the compressed token
133
+ * @param amount Number of tokens to transfer
134
+ * @param owner Owner of the compressed tokens.
135
+ * @param sourceTokenAccount Source (associated) token account
136
+ * @param toAddress Destination address of the recipient
137
+ * @param outputStateTreeInfo State tree account that the compressed tokens
138
+ * should be inserted into. Defaults to a default
139
+ * state tree account.
140
+ * @param tokenPoolInfo Token pool info
141
+ * @param confirmOptions Options for confirming the transaction
142
+ *
143
+ * @return Signature of the confirmed transaction
144
+ */
145
+ declare function compress(rpc: Rpc, payer: Signer, mint: PublicKey, amount: number | BN | number[] | BN[], owner: Signer, sourceTokenAccount: PublicKey, toAddress: PublicKey | Array<PublicKey>, outputStateTreeInfo?: StateTreeInfo, tokenPoolInfo?: TokenPoolInfo, confirmOptions?: ConfirmOptions): Promise<TransactionSignature>;
146
+
147
+ /**
148
+ * Compress SPL tokens into compressed token format
149
+ *
150
+ * @param rpc Rpc connection to use
151
+ * @param payer Payer of the transaction fees
152
+ * @param mint Mint of the token to compress
153
+ * @param owner Owner of the token account
154
+ * @param tokenAccount Token account to compress
155
+ * @param remainingAmount Optional: amount to leave in token account.
156
+ * Default: 0
157
+ * @param outputStateTreeInfo State tree to insert the compressed token
158
+ * account into
159
+ * @param tokenPoolInfo Token pool info
160
+ * @param confirmOptions Options for confirming the transaction
161
+
162
+ *
163
+ * @return Signature of the confirmed transaction
164
+ */
165
+ declare function compressSplTokenAccount(rpc: Rpc, payer: Signer, mint: PublicKey, owner: Signer, tokenAccount: PublicKey, remainingAmount?: BN, outputStateTreeInfo?: StateTreeInfo, tokenPoolInfo?: TokenPoolInfo, confirmOptions?: ConfirmOptions): Promise<TransactionSignature>;
166
+
167
+ /**
168
+ * Create and initialize a new compressed token mint
169
+ *
170
+ * @param rpc RPC to use
171
+ * @param payer Payer of the transaction and initialization fees
172
+ * @param mintAuthority Account or multisig that will control minting
173
+ * @param decimals Location of the decimal place
174
+ * @param keypair Optional keypair, defaulting to a new random one
175
+ * @param confirmOptions Options for confirming the transaction
176
+ * @param tokenProgramId Program ID for the token. Defaults to
177
+ * TOKEN_PROGRAM_ID. You can pass in a boolean to
178
+ * automatically resolve to TOKEN_2022_PROGRAM_ID if
179
+ * true, or TOKEN_PROGRAM_ID if false.
180
+ * @param freezeAuthority Account that will control freeze and thaw. Defaults
181
+ * to null.
182
+ *
183
+ * @return Address of the new mint and the transaction signature
184
+ */
185
+ declare function createMint(rpc: Rpc, payer: Signer, mintAuthority: PublicKey, decimals: number, keypair?: Keypair, confirmOptions?: ConfirmOptions, tokenProgramId?: PublicKey | boolean, freezeAuthority?: PublicKey): Promise<{
186
+ mint: PublicKey;
187
+ transactionSignature: TransactionSignature;
188
+ }>;
189
+
190
+ /**
191
+ * Register an existing mint with the CompressedToken program
192
+ *
193
+ * @param rpc RPC to use
194
+ * @param payer Payer of the transaction and initialization fees
195
+ * @param mint Address of the existing mint
196
+ * @param confirmOptions Options for confirming the transaction
197
+ * @param tokenProgramId Optional: Address of the token program. Default:
198
+ * TOKEN_PROGRAM_ID
199
+ *
200
+ * @return transaction signature
201
+ */
202
+ declare function createTokenPool(rpc: Rpc, payer: Signer, mint: PublicKey, confirmOptions?: ConfirmOptions, tokenProgramId?: PublicKey): Promise<TransactionSignature>;
203
+ /**
204
+ * Create additional token pools for an existing mint
205
+ *
206
+ * @param rpc RPC to use
207
+ * @param payer Payer of the transaction and initialization fees
208
+ * @param mint Address of the existing mint
209
+ * @param numMaxAdditionalPools Number of additional token pools to create. Max 3.
210
+ * @param confirmOptions Options for confirming the transaction
211
+ * @param tokenProgramId Optional: Address of the token program. Default:
212
+ * TOKEN_PROGRAM_ID
213
+ *
214
+ * @return transaction signature
215
+ */
216
+ declare function addTokenPools(rpc: Rpc, payer: Signer, mint: PublicKey, numMaxAdditionalPools: number, confirmOptions?: ConfirmOptions, tokenProgramId?: PublicKey): Promise<string>;
217
+
218
+ /**
219
+ * Create a lookup table for the token program's default accounts
220
+ *
221
+ * @param rpc Rpc connection to use
222
+ * @param payer Payer of the transaction fees
223
+ * @param authority Authority of the lookup table
224
+ * @param mints Optional array of mint public keys to include in
225
+ * the lookup table
226
+ * @param additionalAccounts Optional array of additional account public keys
227
+ * to include in the lookup table
228
+ *
229
+ * @return Transaction signatures and the address of the created lookup table
230
+ */
231
+ declare function createTokenProgramLookupTable(rpc: Rpc, payer: Signer, authority: Signer, mints?: PublicKey[], additionalAccounts?: PublicKey[]): Promise<{
232
+ txIds: TransactionSignature[];
233
+ address: PublicKey;
234
+ }>;
235
+
236
+ /**
237
+ * Decompress compressed tokens
238
+ *
239
+ * @param rpc Rpc to use
240
+ * @param payer Payer of the transaction fees
241
+ * @param mint Mint of the compressed token
242
+ * @param amount Number of tokens to transfer
243
+ * @param owner Owner of the compressed tokens
244
+ * @param toAddress Destination **uncompressed** (associated) token
245
+ * account address.
246
+ * @param tokenPoolInfos Token pool infos
247
+ * @param confirmOptions Options for confirming the transaction
248
+ *
249
+ * @return Signature of the confirmed transaction
250
+ */
251
+ declare function decompress(rpc: Rpc, payer: Signer, mint: PublicKey, amount: number | BN, owner: Signer, toAddress: PublicKey, tokenPoolInfos?: TokenPoolInfo[], confirmOptions?: ConfirmOptions): Promise<TransactionSignature>;
252
+
253
+ /**
254
+ * Merge multiple compressed token accounts for a given mint into a single
255
+ * account
256
+ *
257
+ * @param rpc RPC to use
258
+ * @param payer Payer of the transaction fees
259
+ * @param mint Public key of the token's mint
260
+ * @param owner Owner of the token accounts to be merged
261
+ * @param confirmOptions Options for confirming the transaction
262
+ *
263
+ * @return signature of the confirmed transaction
264
+ */
265
+ declare function mergeTokenAccounts(rpc: Rpc, payer: Signer, mint: PublicKey, owner: Signer, confirmOptions?: ConfirmOptions): Promise<TransactionSignature>;
266
+
267
+ /**
268
+ * Mint compressed tokens to a solana address
269
+ *
270
+ * @param rpc Rpc to use
271
+ * @param payer Payer of the transaction fees
272
+ * @param mint Mint for the account
273
+ * @param toPubkey Address of the account to mint to. Can be an
274
+ * array of addresses if the amount is an array of
275
+ * amounts.
276
+ * @param authority Minting authority
277
+ * @param amount Amount to mint. Can be an array of amounts if
278
+ * the toPubkey is an array of addresses.
279
+ * @param outputStateTreeInfo State tree account that the compressed tokens
280
+ * should be part of. Defaults to the default state
281
+ * tree account.
282
+ * @param tokenPoolInfo Token pool information
283
+ * @param confirmOptions Options for confirming the transaction
284
+ *
285
+ * @return Signature of the confirmed transaction
286
+ */
287
+ declare function mintTo(rpc: Rpc, payer: Signer, mint: PublicKey, toPubkey: PublicKey | PublicKey[], authority: Signer, amount: number | BN | number[] | BN[], outputStateTreeInfo?: StateTreeInfo, tokenPoolInfo?: TokenPoolInfo, confirmOptions?: ConfirmOptions): Promise<TransactionSignature>;
288
+
289
+ /**
290
+ * Revoke one or more delegated token accounts
291
+ *
292
+ * @param rpc Rpc to use
293
+ * @param payer Payer of the transaction fees
294
+ * @param accounts Delegated Compressed token accounts to revoke
295
+ * @param owner Owner of the compressed tokens
296
+ * @param confirmOptions Options for confirming the transaction
297
+ *
298
+ * @return Signature of the confirmed transaction
299
+ */
300
+ declare function revoke(rpc: Rpc, payer: Signer, accounts: ParsedTokenAccount[], owner: Signer, confirmOptions?: ConfirmOptions): Promise<TransactionSignature>;
301
+
302
+ /**
303
+ * Transfer compressed tokens from one owner to another
304
+ *
305
+ * @param rpc Rpc to use
306
+ * @param payer Payer of the transaction fees
307
+ * @param mint Mint of the compressed token
308
+ * @param amount Number of tokens to transfer
309
+ * @param owner Owner of the compressed tokens
310
+ * @param toAddress Destination address of the recipient
311
+ * @param confirmOptions Options for confirming the transaction
312
+ *
313
+ * @return Signature of the confirmed transaction
314
+ */
315
+ declare function transfer(rpc: Rpc, payer: Signer, mint: PublicKey, amount: number | BN, owner: Signer, toAddress: PublicKey, confirmOptions?: ConfirmOptions): Promise<TransactionSignature>;
316
+
317
+ /**
318
+ * Transfer delegated compressed tokens to another owner
319
+ *
320
+ * @param rpc Rpc to use
321
+ * @param payer Payer of the transaction fees
322
+ * @param mint Mint of the compressed token
323
+ * @param amount Number of tokens to transfer
324
+ * @param owner Owner of the compressed tokens
325
+ * @param toAddress Destination address of the recipient
326
+ * @param confirmOptions Options for confirming the transaction
327
+ *
328
+ * @return Signature of the confirmed transaction
329
+ */
330
+ declare function transferDelegated(rpc: Rpc, payer: Signer, mint: PublicKey, amount: number | BN, owner: Signer, toAddress: PublicKey, confirmOptions?: ConfirmOptions): Promise<TransactionSignature>;
331
+
332
+ /**
333
+ * Decompress delegated compressed tokens. Remaining compressed tokens are
334
+ * returned to the owner without delegation.
335
+ *
336
+ * @param rpc Rpc to use
337
+ * @param payer Payer of the transaction fees
338
+ * @param mint Mint of the compressed token
339
+ * @param amount Number of tokens to decompress
340
+ * @param owner Owner of the compressed tokens
341
+ * @param toAddress Destination **uncompressed** (associated) token
342
+ * account address.
343
+ * @param tokenPoolInfos Token pool infos
344
+ * @param confirmOptions Options for confirming the transaction
345
+ *
346
+ * @return Signature of the confirmed transaction
347
+ */
348
+ declare function decompressDelegated(rpc: Rpc, payer: Signer, mint: PublicKey, amount: number | BN, owner: Signer, toAddress: PublicKey, tokenPoolInfos?: TokenPoolInfo[], confirmOptions?: ConfirmOptions): Promise<TransactionSignature>;
6
349
 
7
350
  type CompressedCpiContext = {
8
351
  setContext: boolean;
@@ -71,11 +414,12 @@ type CompressSplTokenAccountInstructionData = {
71
414
  remainingAmount: BN | null;
72
415
  cpiContext: CompressedCpiContext | null;
73
416
  };
417
+ declare function isSingleTokenPoolInfo(tokenPoolInfos: TokenPoolInfo | TokenPoolInfo[]): tokenPoolInfos is TokenPoolInfo;
74
418
  type CompressedTokenInstructionDataTransfer = {
75
419
  /**
76
420
  * Validity proof
77
421
  */
78
- proof: CompressedProof | null;
422
+ proof: ValidityProof | null;
79
423
  /**
80
424
  * The mint of the transfer
81
425
  */
@@ -138,6 +482,24 @@ type TokenData = {
138
482
  */
139
483
  tlv: Buffer | null;
140
484
  };
485
+ type CompressedTokenInstructionDataApprove = {
486
+ proof: ValidityProof;
487
+ mint: PublicKey;
488
+ inputTokenDataWithContext: InputTokenDataWithContext[];
489
+ cpiContext: CompressedCpiContext | null;
490
+ delegate: PublicKey;
491
+ delegatedAmount: BN;
492
+ delegateMerkleTreeIndex: number;
493
+ changeAccountMerkleTreeIndex: number;
494
+ delegateLamports: BN | null;
495
+ };
496
+ type CompressedTokenInstructionDataRevoke = {
497
+ proof: ValidityProof;
498
+ mint: PublicKey;
499
+ inputTokenDataWithContext: InputTokenDataWithContext[];
500
+ cpiContext: CompressedCpiContext | null;
501
+ outputAccountMerkleTreeIndex: number;
502
+ };
141
503
 
142
504
  type PackCompressedTokenAccountsParams = {
143
505
  /** Input state to be consumed */
@@ -147,7 +509,7 @@ type PackCompressedTokenAccountsParams = {
147
509
  * state tree of the input state. Gets padded to the length of
148
510
  * outputCompressedAccounts.
149
511
  */
150
- outputStateTrees?: PublicKey[] | PublicKey;
512
+ outputStateTreeInfo?: StateTreeInfo;
151
513
  /** Optional remaining accounts to append to */
152
514
  remainingAccounts?: PublicKey[];
153
515
  /**
@@ -166,659 +528,147 @@ declare function packCompressedTokenAccounts(params: PackCompressedTokenAccounts
166
528
  packedOutputTokenData: PackedTokenTransferOutputData[];
167
529
  };
168
530
 
169
- declare const POOL_SEED: Buffer;
170
- declare const CPI_AUTHORITY_SEED: Buffer;
171
- declare const SPL_TOKEN_MINT_RENT_EXEMPT_BALANCE = 1461600;
172
- declare const CREATE_TOKEN_POOL_DISCRIMINATOR: Buffer;
173
- declare const MINT_TO_DISCRIMINATOR: Buffer;
174
- declare const TRANSFER_DISCRIMINATOR: Buffer;
175
- declare const COMPRESS_SPL_TOKEN_ACCOUNT_DISCRIMINATOR: Buffer;
176
-
177
- type CompressParams = {
178
- /**
179
- * The payer of the transaction.
180
- */
181
- payer: PublicKey;
182
- /**
183
- * owner of the *uncompressed* token account.
184
- */
185
- owner: PublicKey;
186
- /**
187
- * source (associated) token account address.
188
- */
189
- source: PublicKey;
190
- /**
191
- * owner of the compressed token account.
192
- * To compress to a batch of recipients, pass an array of PublicKeys.
193
- */
194
- toAddress: PublicKey | PublicKey[];
195
- /**
196
- * Mint address of the token to compress.
197
- */
198
- mint: PublicKey;
199
- /**
200
- * amount of tokens to compress.
201
- */
202
- amount: number | BN | number[] | BN[];
203
- /**
204
- * The state tree that the tx output should be inserted into. Defaults to a
205
- * public state tree if unspecified.
206
- */
207
- outputStateTree?: PublicKey;
208
- /**
209
- * Optional: The token program ID. Default: SPL Token Program ID
210
- */
211
- tokenProgramId?: PublicKey;
212
- };
213
- type CompressSplTokenAccountParams = {
214
- /**
215
- * Tx feepayer
216
- */
217
- feePayer: PublicKey;
218
- /**
219
- * Authority that owns the token account
220
- */
221
- authority: PublicKey;
222
- /**
223
- * Token account to compress
224
- */
225
- tokenAccount: PublicKey;
226
- /**
227
- * Mint public key
228
- */
229
- mint: PublicKey;
230
- /**
231
- * Optional: remaining amount to leave in token account. Default: 0
232
- */
233
- remainingAmount?: BN;
234
- /**
235
- * The state tree that the compressed token account should be inserted into.
236
- */
237
- outputStateTree: PublicKey;
238
- /**
239
- * Optional: The token program ID. Default: SPL Token Program ID
240
- */
241
- tokenProgramId?: PublicKey;
242
- };
243
- type DecompressParams = {
244
- /**
245
- * The payer of the transaction.
246
- */
247
- payer: PublicKey;
248
- /**
249
- * input state to be consumed
250
- */
251
- inputCompressedTokenAccounts: ParsedTokenAccount[];
252
- /**
253
- * address of **uncompressed** destination token account.
254
- */
255
- toAddress: PublicKey;
256
- /**
257
- * amount of tokens to decompress.
258
- */
259
- amount: number | BN;
260
- /**
261
- * The recent state root indices of the input state. The expiry is tied to
262
- * the proof.
263
- */
264
- recentInputStateRootIndices: number[];
265
- /**
266
- * The recent validity proof for state inclusion of the input state. It
267
- * expires after n slots.
268
- */
269
- recentValidityProof: CompressedProof;
270
- /**
271
- * The state tree that the change tx output should be inserted into.
272
- * Defaults to a public state tree if unspecified.
273
- */
274
- outputStateTree?: PublicKey;
275
- /**
276
- * Optional: The token program ID. Default: SPL Token Program ID
277
- */
278
- tokenProgramId?: PublicKey;
279
- };
280
- type TransferParams = {
281
- /**
282
- * The payer of the transaction
283
- */
284
- payer: PublicKey;
285
- /**
286
- * The input state to be consumed
287
- */
288
- inputCompressedTokenAccounts: ParsedTokenAccount[];
289
- /**
290
- * Recipient address
291
- */
292
- toAddress: PublicKey;
293
- /**
294
- * Amount of tokens to transfer
295
- */
296
- amount: BN | number;
297
- /**
298
- * The recent state root indices of the input state. The expiry is tied to
299
- * the proof.
300
-
301
- */
302
- recentInputStateRootIndices: number[];
303
- /**
304
- * The recent validity proof for state inclusion of the input state. It
305
- * expires after n slots.
306
- */
307
- recentValidityProof: CompressedProof;
308
- /**
309
- * The state trees that the tx output should be inserted into. This can be a
310
- * single PublicKey or an array of PublicKey. Defaults to the 0th state tree
311
- * of input state.
312
- */
313
- outputStateTrees?: PublicKey[] | PublicKey;
314
- };
531
+ declare const ERROR_NO_ACCOUNTS_FOUND = "Could not find accounts to select for transfer.";
315
532
  /**
316
- * Create Mint account for compressed Tokens
533
+ * Selects token accounts for approval, first trying to find an exact match, then falling back to minimum selection.
534
+ *
535
+ * @param {ParsedTokenAccount[]} accounts - Token accounts to choose from.
536
+ * @param {BN} approveAmount - Amount to approve.
537
+ * @param {number} [maxInputs=4] - Max accounts to select when falling back to minimum selection.
538
+ * @returns {[
539
+ * selectedAccounts: ParsedTokenAccount[],
540
+ * total: BN,
541
+ * totalLamports: BN | null,
542
+ * maxPossibleAmount: BN
543
+ * ]} - Returns:
544
+ * - selectedAccounts: Accounts chosen for approval.
545
+ * - total: Total amount from selected accounts.
546
+ * - totalLamports: Total lamports from selected accounts.
547
+ * - maxPossibleAmount: Max approvable amount given maxInputs.
317
548
  */
318
- type CreateMintParams = {
319
- /**
320
- * Tx feepayer
321
- */
322
- feePayer: PublicKey;
323
- /**
324
- * Mint authority
325
- */
326
- authority: PublicKey;
327
- /**
328
- * Mint public key
329
- */
330
- mint: PublicKey;
331
- /**
332
- * Mint decimals
333
- */
334
- decimals: number;
335
- /**
336
- * Optional: freeze authority
337
- */
338
- freezeAuthority: PublicKey | null;
339
- /**
340
- * lamport amount for mint account rent exemption
341
- */
342
- rentExemptBalance: number;
343
- /**
344
- * Optional: The token program ID. Default: SPL Token Program ID
345
- */
346
- tokenProgramId?: PublicKey;
347
- /**
348
- * Optional: Mint size to use, defaults to MINT_SIZE
349
- */
350
- mintSize?: number;
351
- };
549
+ declare function selectTokenAccountsForApprove(accounts: ParsedTokenAccount[], approveAmount: BN, maxInputs?: number): [
550
+ selectedAccounts: ParsedTokenAccount[],
551
+ total: BN,
552
+ totalLamports: BN | null,
553
+ maxPossibleAmount: BN
554
+ ];
352
555
  /**
353
- * Parameters for merging compressed token accounts
556
+ * Selects the minimum number of compressed token accounts required for a
557
+ * decompress instruction, up to a specified maximum.
558
+ *
559
+ * @param {ParsedTokenAccount[]} accounts Token accounts to choose from.
560
+ * @param {BN} amount Amount to decompress.
561
+ * @param {number} [maxInputs=4] Max accounts to select. Default
562
+ * is 4.
563
+ *
564
+ * @returns Returns selected accounts and their totals.
354
565
  */
355
- type MergeTokenAccountsParams = {
356
- /**
357
- * Tx feepayer
358
- */
359
- payer: PublicKey;
360
- /**
361
- * Owner of the token accounts to be merged
362
- */
363
- owner: PublicKey;
364
- /**
365
- * Mint public key
366
- */
367
- mint: PublicKey;
368
- /**
369
- * Array of compressed token accounts to merge
370
- */
371
- inputCompressedTokenAccounts: ParsedTokenAccount[];
372
- /**
373
- * Optional: Public key of the state tree to merge into
374
- */
375
- outputStateTree: PublicKey;
376
- /**
377
- * Optional: Recent validity proof for state inclusion
378
- */
379
- recentValidityProof: CompressedProof;
380
- /**
381
- * Optional: Recent state root indices of the input state
382
- */
383
- recentInputStateRootIndices: number[];
566
+ declare function selectMinCompressedTokenAccountsForDecompression(accounts: ParsedTokenAccount[], amount: BN, maxInputs?: number): {
567
+ selectedAccounts: ParsedTokenAccount[];
568
+ total: BN;
569
+ totalLamports: BN | null;
570
+ maxPossibleAmount: BN;
384
571
  };
385
572
  /**
386
- * Create compressed token accounts
573
+ * Selects the minimum number of compressed token accounts required for a
574
+ * transfer or decompression instruction, up to a specified maximum.
575
+ *
576
+ * @param {ParsedTokenAccount[]} accounts Token accounts to choose from.
577
+ * @param {BN} transferAmount Amount to transfer or decompress.
578
+ * @param {number} [maxInputs=4] Max accounts to select. Default
579
+ * is 4.
580
+ *
581
+ * @returns Returns selected accounts and their totals. [
582
+ * selectedAccounts: ParsedTokenAccount[],
583
+ * total: BN,
584
+ * totalLamports: BN | null,
585
+ * maxPossibleAmount: BN
586
+ * ]
387
587
  */
388
- type MintToParams = {
389
- /**
390
- * Tx feepayer
391
- */
392
- feePayer: PublicKey;
393
- /**
394
- * Mint authority
395
- */
396
- authority: PublicKey;
397
- /**
398
- * Mint public key
399
- */
400
- mint: PublicKey;
401
- /**
402
- * The Solana Public Keys to mint to.
403
- */
404
- toPubkey: PublicKey[] | PublicKey;
405
- /**
406
- * The amount of compressed tokens to mint.
407
- */
408
- amount: BN | BN[] | number | number[];
409
- /**
410
- * Public key of the state tree to mint into. Defaults to a public state
411
- * tree if unspecified.
412
- */
413
- merkleTree?: PublicKey;
414
- /**
415
- * Optional: The token program ID. Default: SPL Token Program ID
416
- */
417
- tokenProgramId?: PublicKey;
418
- };
588
+ declare function selectMinCompressedTokenAccountsForTransfer(accounts: ParsedTokenAccount[], transferAmount: BN, maxInputs?: number): [
589
+ selectedAccounts: ParsedTokenAccount[],
590
+ total: BN,
591
+ totalLamports: BN | null,
592
+ maxPossibleAmount: BN
593
+ ];
419
594
  /**
420
- * Register an existing SPL mint account to the compressed token program
421
- * Creates an omnibus account for the mint
595
+ * Executes {@link selectMinCompressedTokenAccountsForTransfer} strategy,
596
+ * returns partial amounts if insufficient accounts are found instead of
597
+ * throwing an error.
422
598
  */
423
- type RegisterMintParams = {
424
- /** Tx feepayer */
425
- feePayer: PublicKey;
426
- /** Mint public key */
427
- mint: PublicKey;
428
- /**
429
- * Optional: The token program ID. Default: SPL Token Program ID
430
- */
431
- tokenProgramId?: PublicKey;
432
- };
599
+ declare function selectMinCompressedTokenAccountsForTransferOrPartial(accounts: ParsedTokenAccount[], transferAmount: BN, maxInputs?: number): [
600
+ selectedAccounts: ParsedTokenAccount[],
601
+ total: BN,
602
+ totalLamports: BN | null,
603
+ maxPossibleAmount: BN
604
+ ];
433
605
  /**
434
- * Mint from existing SPL mint to compressed token accounts
435
- */
436
- type ApproveAndMintToParams = {
437
- /**
438
- * Tx feepayer
439
- */
440
- feePayer: PublicKey;
441
- /**
442
- * Mint authority
443
- */
444
- authority: PublicKey;
445
- /**
446
- * Mint authority (associated) token account
447
- */
448
- authorityTokenAccount: PublicKey;
449
- /**
450
- * Mint public key
451
- */
452
- mint: PublicKey;
453
- /**
454
- * The Solana Public Key to mint to.
455
- */
456
- toPubkey: PublicKey;
457
- /**
458
- * The amount of compressed tokens to mint.
459
- */
460
- amount: BN | number;
461
- /**
462
- * Public key of the state tree to mint into. Defaults to a public state
463
- * tree if unspecified.
464
- */
465
- merkleTree?: PublicKey;
466
- /**
467
- * Optional: The token program ID. Default: SPL Token Program ID
468
- */
469
- tokenProgramId?: PublicKey;
470
- };
471
- type CreateTokenProgramLookupTableParams = {
472
- /**
473
- * The payer of the transaction.
474
- */
475
- payer: PublicKey;
476
- /**
477
- * The authority of the transaction.
478
- */
479
- authority: PublicKey;
480
- /**
481
- * Recently finalized Solana slot.
482
- */
483
- recentSlot: number;
484
- /**
485
- * Optional Mint addresses to store in the lookup table.
486
- */
487
- mints?: PublicKey[];
488
- /**
489
- * Optional additional addresses to store in the lookup table.
490
- */
491
- remainingAccounts?: PublicKey[];
492
- };
493
- /**
494
- * Sum up the token amounts of the compressed token accounts
495
- */
496
- declare const sumUpTokenAmount: (accounts: ParsedTokenAccount[]) => BN;
497
- /**
498
- * Validate that all the compressed token accounts are owned by the same owner.
499
- */
500
- declare const validateSameTokenOwner: (accounts: ParsedTokenAccount[]) => void;
501
- /**
502
- * Parse compressed token accounts to get the mint, current owner and delegate.
503
- */
504
- declare const parseTokenData: (compressedTokenAccounts: ParsedTokenAccount[]) => {
505
- mint: PublicKey;
506
- currentOwner: PublicKey;
507
- delegate: PublicKey | null;
508
- };
509
- /**
510
- * Create the output state for a transfer transaction.
511
- * @param inputCompressedTokenAccounts Input state
512
- * @param toAddress Recipient address
513
- * @param amount Amount of tokens to transfer
514
- * @returns Output token data for the transfer
515
- * instruction
516
- */
517
- declare function createTransferOutputState(inputCompressedTokenAccounts: ParsedTokenAccount[], toAddress: PublicKey, amount: number | BN): TokenTransferOutputData[];
518
- /**
519
- * Create the output state for a compress transaction.
520
- * @param inputCompressedTokenAccounts Input state
521
- * @param amount Amount of tokens to compress
522
- * @returns Output token data for the compress
523
- * instruction
524
- */
525
- declare function createDecompressOutputState(inputCompressedTokenAccounts: ParsedTokenAccount[], amount: number | BN): TokenTransferOutputData[];
526
- declare class CompressedTokenProgram {
527
- /**
528
- * @internal
529
- */
530
- constructor();
531
- /**
532
- * Public key that identifies the CompressedPda program
533
- */
534
- static programId: PublicKey;
535
- /**
536
- * Set a custom programId via PublicKey or base58 encoded string.
537
- * This method is not required for regular usage.
538
- *
539
- * Use this only if you know what you are doing.
540
- */
541
- static setProgramId(programId: PublicKey | string): void;
542
- /** @internal */
543
- static deriveTokenPoolPda(mint: PublicKey): PublicKey;
544
- /** @internal */
545
- static get deriveCpiAuthorityPda(): PublicKey;
546
- /**
547
- * Construct createMint instruction for compressed tokens.
548
- * @returns [createMintAccountInstruction, initializeMintInstruction, createTokenPoolInstruction]
549
- *
550
- * Note that `createTokenPoolInstruction` must be executed after `initializeMintInstruction`.
551
- */
552
- static createMint(params: CreateMintParams): Promise<TransactionInstruction[]>;
553
- /**
554
- * Enable compression for an existing SPL mint, creating an omnibus account.
555
- * For new mints, use `CompressedTokenProgram.createMint`.
556
- */
557
- static createTokenPool(params: RegisterMintParams): Promise<TransactionInstruction>;
558
- /**
559
- * Construct mintTo instruction for compressed tokens
560
- */
561
- static mintTo(params: MintToParams): Promise<TransactionInstruction>;
562
- /**
563
- * Mint tokens from registered SPL mint account to a compressed account
564
- */
565
- static approveAndMintTo(params: ApproveAndMintToParams): Promise<TransactionInstruction[]>;
566
- /**
567
- * Construct transfer instruction for compressed tokens
568
- */
569
- static transfer(params: TransferParams): Promise<TransactionInstruction>;
570
- /**
571
- * Create lookup table instructions for the token program's default accounts.
572
- */
573
- static createTokenProgramLookupTable(params: CreateTokenProgramLookupTableParams): Promise<{
574
- instructions: TransactionInstruction[];
575
- address: PublicKey;
576
- }>;
577
- /**
578
- * Create compress instruction
579
- * @returns compressInstruction
580
- */
581
- static compress(params: CompressParams): Promise<TransactionInstruction>;
582
- /**
583
- * Construct decompress instruction
584
- */
585
- static decompress(params: DecompressParams): Promise<TransactionInstruction>;
586
- static mergeTokenAccounts(params: MergeTokenAccountsParams): Promise<TransactionInstruction[]>;
587
- static compressSplTokenAccount(params: CompressSplTokenAccountParams): Promise<TransactionInstruction>;
588
- static get_mint_program_id(mint: PublicKey, connection: Connection): Promise<PublicKey | undefined>;
589
- }
590
-
591
- /**
592
- * Mint compressed tokens to a solana address from an external mint authority
593
- *
594
- * @param rpc Rpc to use
595
- * @param payer Payer of the transaction fees
596
- * @param mint Mint for the account
597
- * @param destination Address of the account to mint to
598
- * @param authority Minting authority
599
- * @param amount Amount to mint
600
- * @param merkleTree State tree account that the compressed tokens should be
601
- * part of. Defaults to random public state tree account.
602
- * @param confirmOptions Options for confirming the transaction
603
- *
604
- * @return Signature of the confirmed transaction
605
- */
606
- declare function approveAndMintTo(rpc: Rpc, payer: Signer, mint: PublicKey, destination: PublicKey, authority: Signer, amount: number | BN, merkleTree?: PublicKey, confirmOptions?: ConfirmOptions, tokenProgramId?: PublicKey): Promise<TransactionSignature>;
607
-
608
- /**
609
- * Compress SPL tokens
610
- *
611
- * @param rpc Rpc connection to use
612
- * @param payer Payer of the transaction fees
613
- * @param mint Mint of the compressed token
614
- * @param amount Number of tokens to transfer
615
- * @param owner Owner of the compressed tokens.
616
- * @param sourceTokenAccount Source (associated) token account
617
- * @param toAddress Destination address of the recipient
618
- * @param merkleTree State tree account that the compressed tokens
619
- * should be inserted into. Defaults to a default
620
- * state tree account.
621
- * @param confirmOptions Options for confirming the transaction
622
- *
623
- *
624
- * @return Signature of the confirmed transaction
625
- */
626
- declare function compress(rpc: Rpc, payer: Signer, mint: PublicKey, amount: number | BN | number[] | BN[], owner: Signer, sourceTokenAccount: PublicKey, toAddress: PublicKey | Array<PublicKey>, merkleTree?: PublicKey, confirmOptions?: ConfirmOptions, tokenProgramId?: PublicKey): Promise<TransactionSignature>;
627
-
628
- /**
629
- * Decompress compressed tokens
630
- *
631
- * @param rpc Rpc to use
632
- * @param payer Payer of the transaction fees
633
- * @param mint Mint of the compressed token
634
- * @param amount Number of tokens to transfer
635
- * @param owner Owner of the compressed tokens
636
- * @param toAddress Destination **uncompressed** (associated) token account
637
- * address.
638
- * @param merkleTree State tree account that any change compressed tokens should be
639
- * inserted into. Defaults to a default state tree
640
- * account.
641
- * @param confirmOptions Options for confirming the transaction
642
- *
643
- *
644
- * @return Signature of the confirmed transaction
645
- */
646
- declare function decompress(rpc: Rpc, payer: Signer, mint: PublicKey, amount: number | BN, owner: Signer, toAddress: PublicKey, merkleTree?: PublicKey, confirmOptions?: ConfirmOptions, tokenProgramId?: PublicKey): Promise<TransactionSignature>;
647
-
648
- /**
649
- * Create and initialize a new compressed token mint
650
- *
651
- * @param rpc RPC to use
652
- * @param payer Payer of the transaction and initialization fees
653
- * @param mintAuthority Account or multisig that will control minting
654
- * @param decimals Location of the decimal place
655
- * @param keypair Optional keypair, defaulting to a new random one
656
- * @param confirmOptions Options for confirming the transaction
657
- * @param tokenProgramId Program ID for the token. Defaults to
658
- * TOKEN_PROGRAM_ID. You can pass in a boolean to
659
- * automatically resolve to TOKEN_2022_PROGRAM_ID if
660
- * true, or TOKEN_PROGRAM_ID if false.
661
- * @param freezeAuthority Account that will control freeze and thaw. Defaults to null.
606
+ * Selects compressed token accounts for a transfer, ensuring one extra account
607
+ * if possible, up to maxInputs.
662
608
  *
663
- * @return Address of the new mint and the transaction signature
664
- */
665
- declare function createMint(rpc: Rpc, payer: Signer, mintAuthority: PublicKey, decimals: number, keypair?: Keypair, confirmOptions?: ConfirmOptions, tokenProgramId?: PublicKey | boolean, freezeAuthority?: PublicKey): Promise<{
666
- mint: PublicKey;
667
- transactionSignature: TransactionSignature;
668
- }>;
669
-
670
- /**
671
- * Mint compressed tokens to a solana address
609
+ * 1. Sorts accounts by amount (desc)
610
+ * 2. Selects accounts until transfer amount is met or maxInputs is reached,
611
+ * attempting to add one extra account if possible.
672
612
  *
673
- * @param rpc Rpc to use
674
- * @param payer Payer of the transaction fees
675
- * @param mint Mint for the account
676
- * @param destination Address of the account to mint to. Can be an array of
677
- * addresses if the amount is an array of amounts.
678
- * @param authority Minting authority
679
- * @param amount Amount to mint. Can be an array of amounts if the
680
- * destination is an array of addresses.
681
- * @param merkleTree State tree account that the compressed tokens should be
682
- * part of. Defaults to the default state tree account.
683
- * @param confirmOptions Options for confirming the transaction
613
+ * @param {ParsedTokenAccount[]} accounts - The list of token accounts to select from.
614
+ * @param {BN} transferAmount - The token amount to be transferred.
615
+ * @param {number} [maxInputs=4] - The maximum number of accounts to select. Default: 4.
616
+ * @returns {[
617
+ * selectedAccounts: ParsedTokenAccount[],
618
+ * total: BN,
619
+ * totalLamports: BN | null,
620
+ * maxPossibleAmount: BN
621
+ * ]} - An array containing:
622
+ * - selectedAccounts: The accounts selected for the transfer.
623
+ * - total: The total amount accumulated from the selected accounts.
624
+ * - totalLamports: The total lamports accumulated from the selected accounts.
625
+ * - maxPossibleAmount: The maximum possible amount that can be transferred considering maxInputs.
684
626
  *
685
- * @return Signature of the confirmed transaction
686
- */
687
- declare function mintTo(rpc: Rpc, payer: Signer, mint: PublicKey, destination: PublicKey | PublicKey[], authority: Signer, amount: number | BN | number[] | BN[], merkleTree?: PublicKey, confirmOptions?: ConfirmOptions, tokenProgramId?: PublicKey): Promise<TransactionSignature>;
688
-
689
- /**
690
- * Merge multiple compressed token accounts for a given mint into a single
691
- * account
627
+ * @example
628
+ * const accounts = [
629
+ * { parsed: { amount: new BN(100) }, compressedAccount: { lamports: new BN(10) } },
630
+ * { parsed: { amount: new BN(50) }, compressedAccount: { lamports: new BN(5) } },
631
+ * { parsed: { amount: new BN(25) }, compressedAccount: { lamports: new BN(2) } },
632
+ * ];
633
+ * const transferAmount = new BN(75);
634
+ * const maxInputs = 2;
692
635
  *
693
- * @param rpc RPC to use
694
- * @param payer Payer of the transaction fees
695
- * @param mint Public key of the token's mint
696
- * @param owner Owner of the token accounts to be merged
697
- * @param merkleTree Optional merkle tree for compressed tokens
698
- * @param confirmOptions Options for confirming the transaction
636
+ * const [selectedAccounts, total, totalLamports, maxPossibleAmount] =
637
+ * selectSmartCompressedTokenAccountsForTransfer(accounts, transferAmount, maxInputs);
699
638
  *
700
- * @return Array of transaction signatures
639
+ * console.log(selectedAccounts.length); // 2
640
+ * console.log(total.toString()); // '150'
641
+ * console.log(totalLamports!.toString()); // '15'
642
+ * console.log(maxPossibleAmount.toString()); // '150'
701
643
  */
702
- declare function mergeTokenAccounts(rpc: Rpc, payer: Signer, mint: PublicKey, owner: Signer, merkleTree?: PublicKey, confirmOptions?: ConfirmOptions): Promise<TransactionSignature>;
703
-
644
+ declare function selectSmartCompressedTokenAccountsForTransfer(accounts: ParsedTokenAccount[], transferAmount: BN, maxInputs?: number): [
645
+ selectedAccounts: ParsedTokenAccount[],
646
+ total: BN,
647
+ totalLamports: BN | null,
648
+ maxPossibleAmount: BN
649
+ ];
704
650
  /**
705
- * Register an existing mint with the CompressedToken program
706
- *
707
- * @param rpc RPC to use
708
- * @param payer Payer of the transaction and initialization fees
709
- * @param mintAuthority Account or multisig that will control minting. Is signer.
710
- * @param mintAddress Address of the existing mint
711
- * @param confirmOptions Options for confirming the transaction
712
- *
713
- * @return transaction signature
651
+ * Executes {@link selectMinCompressedTokenAccountsForTransfer} strategy,
652
+ * returns partial amounts if insufficient accounts are found instead of
653
+ * throwing an error.
714
654
  */
715
- declare function createTokenPool(rpc: Rpc, payer: Signer, mint: PublicKey, confirmOptions?: ConfirmOptions, tokenProgramId?: PublicKey): Promise<TransactionSignature>;
655
+ declare function selectSmartCompressedTokenAccountsForTransferOrPartial(accounts: ParsedTokenAccount[], transferAmount: BN, maxInputs?: number): [
656
+ selectedAccounts: ParsedTokenAccount[],
657
+ total: BN,
658
+ totalLamports: BN | null,
659
+ maxPossibleAmount: BN
660
+ ];
716
661
 
717
- /**
718
- * Transfer compressed tokens from one owner to another
719
- *
720
- * @param rpc Rpc to use
721
- * @param payer Payer of the transaction fees
722
- * @param mint Mint of the compressed token
723
- * @param amount Number of tokens to transfer
724
- * @param owner Owner of the compressed tokens
725
- * @param toAddress Destination address of the recipient
726
- * @param merkleTree State tree account that the compressed tokens should be
727
- * inserted into. Defaults to the default state tree
728
- * account.
729
- * @param confirmOptions Options for confirming the transaction
730
- *
731
- *
732
- * @return Signature of the confirmed transaction
733
- */
734
- declare function transfer(rpc: Rpc, payer: Signer, mint: PublicKey, amount: number | BN, owner: Signer, toAddress: PublicKey, merkleTree?: PublicKey, confirmOptions?: ConfirmOptions): Promise<TransactionSignature>;
735
-
736
- /**
737
- * Create a lookup table for the token program's default accounts
738
- *
739
- * @param rpc Rpc connection to use
740
- * @param payer Payer of the transaction fees
741
- * @param authority Authority of the lookup table
742
- * @param mints Optional array of mint public keys to include in
743
- * the lookup table
744
- * @param additionalAccounts Optional array of additional account public keys
745
- * to include in the lookup table
746
- *
747
- * @return Transaction signatures and the address of the created lookup table
748
- */
749
- declare function createTokenProgramLookupTable(rpc: Rpc, payer: Signer, authority: Signer, mints?: PublicKey[], additionalAccounts?: PublicKey[]): Promise<{
750
- txIds: TransactionSignature[];
751
- address: PublicKey;
752
- }>;
753
-
754
- /**
755
- * Compress SPL tokens into compressed token format
756
- *
757
- * @param rpc Rpc connection to use
758
- * @param payer Payer of the transaction fees
759
- * @param mint Mint of the token to compress
760
- * @param owner Owner of the token account
761
- * @param tokenAccount Token account to compress
762
- * @param outputStateTree State tree to insert the compressed token account into
763
- * @param remainingAmount Optional: amount to leave in token account. Default: 0
764
- * @param confirmOptions Options for confirming the transaction
765
- *
766
- * @return Signature of the confirmed transaction
767
- */
768
- declare function compressSplTokenAccount(rpc: Rpc, payer: Signer, mint: PublicKey, owner: Signer, tokenAccount: PublicKey, outputStateTree: PublicKey, remainingAmount?: BN, confirmOptions?: ConfirmOptions, tokenProgramId?: PublicKey): Promise<TransactionSignature>;
769
-
770
- declare const DelegatedTransferLayout: buffer_layout.Layout<unknown>;
771
- declare const CpiContextLayout: buffer_layout.Layout<unknown>;
772
- declare const CompressedTokenInstructionDataTransferLayout: buffer_layout.Layout<unknown>;
773
- declare const mintToLayout: buffer_layout.Layout<unknown>;
774
- declare const compressSplTokenAccountInstructionDataLayout: buffer_layout.Layout<unknown>;
775
- declare function encodeMintToInstructionData(data: MintToInstructionData): Buffer$1;
776
- declare function decodeMintToInstructionData(buffer: Buffer$1): MintToInstructionData;
777
- declare function encodeCompressSplTokenAccountInstructionData(data: CompressSplTokenAccountInstructionData): Buffer$1;
778
- declare function decodeCompressSplTokenAccountInstructionData(buffer: Buffer$1): CompressSplTokenAccountInstructionData;
779
- declare function encodeTransferInstructionData(data: CompressedTokenInstructionDataTransfer): Buffer$1;
780
- declare function decodeTransferInstructionData(buffer: Buffer$1): CompressedTokenInstructionDataTransfer;
781
- interface BaseAccountsLayoutParams {
782
- feePayer: PublicKey;
783
- authority: PublicKey;
784
- cpiAuthorityPda: PublicKey;
785
- lightSystemProgram: PublicKey;
786
- registeredProgramPda: PublicKey;
787
- noopProgram: PublicKey;
788
- accountCompressionAuthority: PublicKey;
789
- accountCompressionProgram: PublicKey;
790
- selfProgram: PublicKey;
791
- systemProgram: PublicKey;
792
- }
793
- type createTokenPoolAccountsLayoutParams = {
794
- feePayer: PublicKey;
795
- tokenPoolPda: PublicKey;
796
- systemProgram: PublicKey;
797
- mint: PublicKey;
798
- tokenProgram: PublicKey;
799
- cpiAuthorityPda: PublicKey;
800
- };
801
- type mintToAccountsLayoutParams = BaseAccountsLayoutParams & {
802
- mint: PublicKey;
803
- tokenPoolPda: PublicKey;
804
- tokenProgram: PublicKey;
805
- merkleTree: PublicKey;
806
- solPoolPda: PublicKey | null;
807
- };
808
- type transferAccountsLayoutParams = BaseAccountsLayoutParams & {
809
- tokenPoolPda?: PublicKey;
810
- compressOrDecompressTokenAccount?: PublicKey;
811
- tokenProgram?: PublicKey;
812
- };
813
- type approveAccountsLayoutParams = BaseAccountsLayoutParams;
814
- type revokeAccountsLayoutParams = approveAccountsLayoutParams;
815
- type freezeAccountsLayoutParams = BaseAccountsLayoutParams & {
816
- mint: PublicKey;
817
- };
818
- type thawAccountsLayoutParams = freezeAccountsLayoutParams;
819
- declare const createTokenPoolAccountsLayout: (accounts: createTokenPoolAccountsLayoutParams) => AccountMeta[];
820
- declare const mintToAccountsLayout: (accounts: mintToAccountsLayoutParams) => AccountMeta[];
821
- declare const transferAccountsLayout: (accounts: transferAccountsLayoutParams) => AccountMeta[];
662
+ declare const POOL_SEED: Buffer;
663
+ declare const CPI_AUTHORITY_SEED: Buffer;
664
+ declare const SPL_TOKEN_MINT_RENT_EXEMPT_BALANCE = 1461600;
665
+ declare const CREATE_TOKEN_POOL_DISCRIMINATOR: Buffer;
666
+ declare const MINT_TO_DISCRIMINATOR: Buffer;
667
+ declare const TRANSFER_DISCRIMINATOR: Buffer;
668
+ declare const COMPRESS_SPL_TOKEN_ACCOUNT_DISCRIMINATOR: Buffer;
669
+ declare const APPROVE_DISCRIMINATOR: Buffer;
670
+ declare const REVOKE_DISCRIMINATOR: Buffer;
671
+ declare const ADD_TOKEN_POOL_DISCRIMINATOR: Buffer;
822
672
 
823
673
  type LightCompressedToken = {
824
674
  version: '1.2.0';
@@ -1911,6 +1761,104 @@ type LightCompressedToken = {
1911
1761
  ];
1912
1762
  };
1913
1763
  },
1764
+ {
1765
+ name: 'CompressedTokenInstructionDataRevoke';
1766
+ type: {
1767
+ kind: 'struct';
1768
+ fields: [
1769
+ {
1770
+ name: 'proof';
1771
+ type: {
1772
+ option: {
1773
+ defined: 'CompressedProof';
1774
+ };
1775
+ };
1776
+ },
1777
+ {
1778
+ name: 'mint';
1779
+ type: 'publicKey';
1780
+ },
1781
+ {
1782
+ name: 'inputTokenDataWithContext';
1783
+ type: {
1784
+ vec: {
1785
+ defined: 'InputTokenDataWithContext';
1786
+ };
1787
+ };
1788
+ },
1789
+ {
1790
+ name: 'cpiContext';
1791
+ type: {
1792
+ option: {
1793
+ defined: 'CompressedCpiContext';
1794
+ };
1795
+ };
1796
+ },
1797
+ {
1798
+ name: 'outputAccountMerkleTreeIndex';
1799
+ type: 'u8';
1800
+ }
1801
+ ];
1802
+ };
1803
+ },
1804
+ {
1805
+ name: 'CompressedTokenInstructionDataApprove';
1806
+ type: {
1807
+ kind: 'struct';
1808
+ fields: [
1809
+ {
1810
+ name: 'proof';
1811
+ type: {
1812
+ option: {
1813
+ defined: 'CompressedProof';
1814
+ };
1815
+ };
1816
+ },
1817
+ {
1818
+ name: 'mint';
1819
+ type: 'publicKey';
1820
+ },
1821
+ {
1822
+ name: 'inputTokenDataWithContext';
1823
+ type: {
1824
+ vec: {
1825
+ defined: 'InputTokenDataWithContext';
1826
+ };
1827
+ };
1828
+ },
1829
+ {
1830
+ name: 'cpiContext';
1831
+ type: {
1832
+ option: {
1833
+ defined: 'CompressedCpiContext';
1834
+ };
1835
+ };
1836
+ },
1837
+ {
1838
+ name: 'delegate';
1839
+ type: 'publicKey';
1840
+ },
1841
+ {
1842
+ name: 'delegatedAmount';
1843
+ type: 'u64';
1844
+ },
1845
+ {
1846
+ name: 'delegateMerkleTreeIndex';
1847
+ type: 'u8';
1848
+ },
1849
+ {
1850
+ name: 'changeAccountMerkleTreeIndex';
1851
+ type: 'u8';
1852
+ },
1853
+ {
1854
+ name: 'delegateLamports';
1855
+ type: {
1856
+ option: 'u64';
1857
+ };
1858
+ }
1859
+ ];
1860
+ };
1861
+ },
1914
1862
  {
1915
1863
  name: 'DelegatedTransfer';
1916
1864
  docs: [
@@ -2560,111 +2508,539 @@ type LightCompressedToken = {
2560
2508
  };
2561
2509
  declare const IDL: LightCompressedToken;
2562
2510
 
2563
- declare const ERROR_NO_ACCOUNTS_FOUND = "Could not find accounts to select for transfer.";
2564
- /**
2565
- * Selects the minimum number of compressed token accounts required for a transfer, up to a specified maximum.
2566
- *
2567
- * @param {ParsedTokenAccount[]} accounts - Token accounts to choose from.
2568
- * @param {BN} transferAmount - Amount to transfer.
2569
- * @param {number} [maxInputs=4] - Max accounts to select. Default is 4.
2570
- * @returns {[
2571
- * selectedAccounts: ParsedTokenAccount[],
2572
- * total: BN,
2573
- * totalLamports: BN | null,
2574
- * maxPossibleAmount: BN
2575
- * ]} - Returns:
2576
- * - selectedAccounts: Accounts chosen for transfer.
2577
- * - total: Total amount from selected accounts.
2578
- * - totalLamports: Total lamports from selected accounts.
2579
- * - maxPossibleAmount: Max transferable amount given maxInputs.
2580
- *
2581
- * @example
2582
- * const accounts = [
2583
- * { parsed: { amount: new BN(100) }, compressedAccount: { lamports: new BN(10) } },
2584
- * { parsed: { amount: new BN(50) }, compressedAccount: { lamports: new BN(5) } },
2585
- * { parsed: { amount: new BN(25) }, compressedAccount: { lamports: new BN(2) } },
2586
- * ];
2587
- * const transferAmount = new BN(75);
2588
- * const maxInputs = 2;
2589
- *
2590
- * const [selectedAccounts, total, totalLamports, maxPossibleAmount] =
2591
- * selectMinCompressedTokenAccountsForTransfer(accounts, transferAmount, maxInputs);
2592
- *
2593
- * console.log(selectedAccounts.length); // 2
2594
- * console.log(total.toString()); // '150'
2595
- * console.log(totalLamports!.toString()); // '15'
2596
- */
2597
- declare function selectMinCompressedTokenAccountsForTransfer(accounts: ParsedTokenAccount[], transferAmount: BN, maxInputs?: number): [
2598
- selectedAccounts: ParsedTokenAccount[],
2599
- total: BN,
2600
- totalLamports: BN | null,
2601
- maxPossibleAmount: BN
2602
- ];
2603
- /**
2604
- * Selects the minimal number of compressed token accounts for a transfer orPartially.
2605
- *
2606
- * 1. Sorts accounts by amount (descending)
2607
- * 2. Accumulates amount until it meets or exceeds transfer amount
2608
- */
2609
- declare function selectMinCompressedTokenAccountsForTransferOrPartial(accounts: ParsedTokenAccount[], transferAmount: BN, maxInputs?: number): [
2610
- selectedAccounts: ParsedTokenAccount[],
2611
- total: BN,
2612
- totalLamports: BN | null,
2613
- maxPossibleAmount: BN
2614
- ];
2615
- /**
2616
- * Selects compressed token accounts for a transfer, ensuring one extra account
2617
- * if possible, up to maxInputs.
2618
- *
2619
- * 1. Sorts accounts by amount (desc)
2620
- * 2. Selects accounts until transfer amount is met or maxInputs is reached,
2621
- * attempting to add one extra account if possible.
2622
- *
2623
- * @param {ParsedTokenAccount[]} accounts - The list of token accounts to select from.
2624
- * @param {BN} transferAmount - The token amount to be transferred.
2625
- * @param {number} [maxInputs=4] - The maximum number of accounts to select. Default: 4.
2626
- * @returns {[
2627
- * selectedAccounts: ParsedTokenAccount[],
2628
- * total: BN,
2629
- * totalLamports: BN | null,
2630
- * maxPossibleAmount: BN
2631
- * ]} - An array containing:
2632
- * - selectedAccounts: The accounts selected for the transfer.
2633
- * - total: The total amount accumulated from the selected accounts.
2634
- * - totalLamports: The total lamports accumulated from the selected accounts.
2635
- * - maxPossibleAmount: The maximum possible amount that can be transferred considering maxInputs.
2636
- *
2637
- * @example
2638
- * const accounts = [
2639
- * { parsed: { amount: new BN(100) }, compressedAccount: { lamports: new BN(10) } },
2640
- * { parsed: { amount: new BN(50) }, compressedAccount: { lamports: new BN(5) } },
2641
- * { parsed: { amount: new BN(25) }, compressedAccount: { lamports: new BN(2) } },
2642
- * ];
2643
- * const transferAmount = new BN(75);
2644
- * const maxInputs = 2;
2645
- *
2646
- * const [selectedAccounts, total, totalLamports, maxPossibleAmount] =
2647
- * selectSmartCompressedTokenAccountsForTransfer(accounts, transferAmount, maxInputs);
2648
- *
2649
- * console.log(selectedAccounts.length); // 2
2650
- * console.log(total.toString()); // '150'
2651
- * console.log(totalLamports!.toString()); // '15'
2652
- * console.log(maxPossibleAmount.toString()); // '150'
2653
- */
2654
- declare function selectSmartCompressedTokenAccountsForTransfer(accounts: ParsedTokenAccount[], transferAmount: BN, maxInputs?: number): [
2655
- selectedAccounts: ParsedTokenAccount[],
2656
- total: BN,
2657
- totalLamports: BN | null,
2658
- maxPossibleAmount: BN
2659
- ];
2660
- /**
2661
- * orPartially runs {@link selectSmartCompressedTokenAccountsForTransfer} strategy.
2662
- */
2663
- declare function selectSmartCompressedTokenAccountsForTransferOrPartial(accounts: ParsedTokenAccount[], transferAmount: BN, maxInputs?: number): [
2664
- selectedAccounts: ParsedTokenAccount[],
2665
- total: BN,
2666
- totalLamports: BN | null,
2667
- maxPossibleAmount: BN
2668
- ];
2511
+ declare const DelegatedTransferLayout: buffer_layout.Layout<unknown>;
2512
+ declare const CpiContextLayout: buffer_layout.Layout<unknown>;
2513
+ declare const CompressedTokenInstructionDataTransferLayout: buffer_layout.Layout<unknown>;
2514
+ declare const mintToLayout: buffer_layout.Layout<unknown>;
2515
+ declare const compressSplTokenAccountInstructionDataLayout: buffer_layout.Layout<unknown>;
2516
+ declare function encodeMintToInstructionData(data: MintToInstructionData): Buffer;
2517
+ declare function decodeMintToInstructionData(buffer: Buffer): MintToInstructionData;
2518
+ declare function encodeCompressSplTokenAccountInstructionData(data: CompressSplTokenAccountInstructionData): Buffer;
2519
+ declare function decodeCompressSplTokenAccountInstructionData(buffer: Buffer): CompressSplTokenAccountInstructionData;
2520
+ declare function encodeTransferInstructionData(data: CompressedTokenInstructionDataTransfer): Buffer;
2521
+ declare function decodeTransferInstructionData(buffer: Buffer): CompressedTokenInstructionDataTransfer;
2522
+ interface BaseAccountsLayoutParams {
2523
+ feePayer: PublicKey;
2524
+ authority: PublicKey;
2525
+ cpiAuthorityPda: PublicKey;
2526
+ lightSystemProgram: PublicKey;
2527
+ registeredProgramPda: PublicKey;
2528
+ noopProgram: PublicKey;
2529
+ accountCompressionAuthority: PublicKey;
2530
+ accountCompressionProgram: PublicKey;
2531
+ selfProgram: PublicKey;
2532
+ systemProgram: PublicKey;
2533
+ }
2534
+ type createTokenPoolAccountsLayoutParams = {
2535
+ feePayer: PublicKey;
2536
+ tokenPoolPda: PublicKey;
2537
+ systemProgram: PublicKey;
2538
+ mint: PublicKey;
2539
+ tokenProgram: PublicKey;
2540
+ cpiAuthorityPda: PublicKey;
2541
+ };
2542
+ type addTokenPoolAccountsLayoutParams = createTokenPoolAccountsLayoutParams & {
2543
+ existingTokenPoolPda: PublicKey;
2544
+ };
2545
+ type mintToAccountsLayoutParams = BaseAccountsLayoutParams & {
2546
+ mint: PublicKey;
2547
+ tokenPoolPda: PublicKey;
2548
+ tokenProgram: PublicKey;
2549
+ merkleTree: PublicKey;
2550
+ solPoolPda: PublicKey | null;
2551
+ };
2552
+ type transferAccountsLayoutParams = BaseAccountsLayoutParams & {
2553
+ tokenPoolPda?: PublicKey;
2554
+ compressOrDecompressTokenAccount?: PublicKey;
2555
+ tokenProgram?: PublicKey;
2556
+ };
2557
+ type approveAccountsLayoutParams = BaseAccountsLayoutParams;
2558
+ type revokeAccountsLayoutParams = approveAccountsLayoutParams;
2559
+ type freezeAccountsLayoutParams = BaseAccountsLayoutParams & {
2560
+ mint: PublicKey;
2561
+ };
2562
+ type thawAccountsLayoutParams = freezeAccountsLayoutParams;
2563
+ declare const createTokenPoolAccountsLayout: (accounts: createTokenPoolAccountsLayoutParams) => AccountMeta[];
2564
+ declare const addTokenPoolAccountsLayout: (accounts: addTokenPoolAccountsLayoutParams) => AccountMeta[];
2565
+ declare const mintToAccountsLayout: (accounts: mintToAccountsLayoutParams) => AccountMeta[];
2566
+ declare const transferAccountsLayout: (accounts: transferAccountsLayoutParams) => AccountMeta[];
2567
+ declare const approveAccountsLayout: (accounts: approveAccountsLayoutParams) => AccountMeta[];
2568
+ declare const revokeAccountsLayout: (accounts: approveAccountsLayoutParams) => AccountMeta[];
2569
+ declare const freezeAccountsLayout: (accounts: freezeAccountsLayoutParams) => AccountMeta[];
2570
+ declare const thawAccountsLayout: (accounts: freezeAccountsLayoutParams) => AccountMeta[];
2571
+ declare const CompressedTokenInstructionDataApproveLayout: buffer_layout.Layout<unknown>;
2572
+ declare const CompressedTokenInstructionDataRevokeLayout: buffer_layout.Layout<unknown>;
2573
+ declare function encodeApproveInstructionData(data: CompressedTokenInstructionDataApprove): Buffer;
2574
+ declare function decodeApproveInstructionData(buffer: Buffer): CompressedTokenInstructionDataApprove;
2575
+ declare function encodeRevokeInstructionData(data: CompressedTokenInstructionDataRevoke): Buffer;
2576
+ declare function decodeRevokeInstructionData(buffer: Buffer): CompressedTokenInstructionDataRevoke;
2577
+
2578
+ type CompressParams = {
2579
+ /**
2580
+ * The payer of the transaction.
2581
+ */
2582
+ payer: PublicKey;
2583
+ /**
2584
+ * owner of the *uncompressed* token account.
2585
+ */
2586
+ owner: PublicKey;
2587
+ /**
2588
+ * source (associated) token account address.
2589
+ */
2590
+ source: PublicKey;
2591
+ /**
2592
+ * owner of the compressed token account.
2593
+ * To compress to a batch of recipients, pass an array of PublicKeys.
2594
+ */
2595
+ toAddress: PublicKey | PublicKey[];
2596
+ /**
2597
+ * Mint address of the token to compress.
2598
+ */
2599
+ mint: PublicKey;
2600
+ /**
2601
+ * amount of tokens to compress.
2602
+ */
2603
+ amount: number | BN | number[] | BN[];
2604
+ /**
2605
+ * The state tree that the tx output should be inserted into. Defaults to a
2606
+ * public state tree if unspecified.
2607
+ */
2608
+ outputStateTreeInfo: StateTreeInfo;
2609
+ /**
2610
+ * Tokenpool.
2611
+ */
2612
+ tokenPoolInfo: TokenPoolInfo;
2613
+ };
2614
+ type CompressSplTokenAccountParams = {
2615
+ /**
2616
+ * Tx feepayer
2617
+ */
2618
+ feePayer: PublicKey;
2619
+ /**
2620
+ * Authority that owns the token account
2621
+ */
2622
+ authority: PublicKey;
2623
+ /**
2624
+ * Token account to compress
2625
+ */
2626
+ tokenAccount: PublicKey;
2627
+ /**
2628
+ * Mint public key
2629
+ */
2630
+ mint: PublicKey;
2631
+ /**
2632
+ * Optional: remaining amount to leave in token account. Default: 0
2633
+ */
2634
+ remainingAmount?: BN;
2635
+ /**
2636
+ * The state tree that the compressed token account should be inserted into.
2637
+ */
2638
+ outputStateTreeInfo: StateTreeInfo;
2639
+ /**
2640
+ * The token pool info.
2641
+ */
2642
+ tokenPoolInfo: TokenPoolInfo;
2643
+ };
2644
+ type DecompressParams = {
2645
+ /**
2646
+ * The payer of the transaction.
2647
+ */
2648
+ payer: PublicKey;
2649
+ /**
2650
+ * input state to be consumed
2651
+ */
2652
+ inputCompressedTokenAccounts: ParsedTokenAccount[];
2653
+ /**
2654
+ * address of **uncompressed** destination token account.
2655
+ */
2656
+ toAddress: PublicKey;
2657
+ /**
2658
+ * amount of tokens to decompress.
2659
+ */
2660
+ amount: number | BN;
2661
+ /**
2662
+ * The recent state root indices of the input state. The expiry is tied to
2663
+ * the proof.
2664
+ */
2665
+ recentInputStateRootIndices: number[];
2666
+ /**
2667
+ * The recent validity proof for state inclusion of the input state. It
2668
+ * expires after n slots.
2669
+ */
2670
+ recentValidityProof: ValidityProof | CompressedProof;
2671
+ /**
2672
+ * Tokenpool addresses. One or more token pools can be provided.
2673
+ */
2674
+ tokenPoolInfos: TokenPoolInfo | TokenPoolInfo[];
2675
+ };
2676
+ type TransferParams = {
2677
+ /**
2678
+ * The payer of the transaction
2679
+ */
2680
+ payer: PublicKey;
2681
+ /**
2682
+ * The input state to be consumed
2683
+ */
2684
+ inputCompressedTokenAccounts: ParsedTokenAccount[];
2685
+ /**
2686
+ * Recipient address
2687
+ */
2688
+ toAddress: PublicKey;
2689
+ /**
2690
+ * Amount of tokens to transfer
2691
+ */
2692
+ amount: BN | number;
2693
+ /**
2694
+ * The recent state root indices of the input state. The expiry is tied to
2695
+ * the proof.
2696
+ */
2697
+ recentInputStateRootIndices: number[];
2698
+ /**
2699
+ * The recent validity proof for state inclusion of the input state. It
2700
+ * expires after n slots.
2701
+ */
2702
+ recentValidityProof: ValidityProof | CompressedProof;
2703
+ };
2704
+ type ApproveParams = TransferParams;
2705
+ type RevokeParams = {
2706
+ /**
2707
+ * The payer of the transaction
2708
+ */
2709
+ payer: PublicKey;
2710
+ /**
2711
+ * The input state to be consumed
2712
+ */
2713
+ inputCompressedTokenAccounts: ParsedTokenAccount[];
2714
+ /**
2715
+ * The recent state root indices of the input state. The expiry is tied to
2716
+ * the proof.
2717
+ */
2718
+ recentInputStateRootIndices: number[];
2719
+ /**
2720
+ * The recent validity proof for state inclusion of the input state. It
2721
+ * expires after n slots.
2722
+ */
2723
+ recentValidityProof: ValidityProof | CompressedProof;
2724
+ };
2725
+ /**
2726
+ * Create Mint account for compressed Tokens
2727
+ */
2728
+ type CreateMintParams = {
2729
+ /**
2730
+ * Tx feepayer
2731
+ */
2732
+ feePayer: PublicKey;
2733
+ /**
2734
+ * Mint authority
2735
+ */
2736
+ authority: PublicKey;
2737
+ /**
2738
+ * Mint public key
2739
+ */
2740
+ mint: PublicKey;
2741
+ /**
2742
+ * Mint decimals
2743
+ */
2744
+ decimals: number;
2745
+ /**
2746
+ * Optional: freeze authority
2747
+ */
2748
+ freezeAuthority: PublicKey | null;
2749
+ /**
2750
+ * lamport amount for mint account rent exemption
2751
+ */
2752
+ rentExemptBalance: number;
2753
+ /**
2754
+ * Optional: The token program ID. Default: SPL Token Program ID
2755
+ */
2756
+ tokenProgramId?: PublicKey;
2757
+ /**
2758
+ * Optional: Mint size to use, defaults to MINT_SIZE
2759
+ */
2760
+ mintSize?: number;
2761
+ };
2762
+ /**
2763
+ * Parameters for merging compressed token accounts
2764
+ */
2765
+ type MergeTokenAccountsParams = {
2766
+ /**
2767
+ * Tx feepayer
2768
+ */
2769
+ payer: PublicKey;
2770
+ /**
2771
+ * Owner of the token accounts to be merged
2772
+ */
2773
+ owner: PublicKey;
2774
+ /**
2775
+ * Mint public key
2776
+ */
2777
+ mint: PublicKey;
2778
+ /**
2779
+ * Array of compressed token accounts to merge
2780
+ */
2781
+ inputCompressedTokenAccounts: ParsedTokenAccount[];
2782
+ /**
2783
+ * Optional: Recent validity proof for state inclusion
2784
+ */
2785
+ recentValidityProof: ValidityProof;
2786
+ /**
2787
+ * Optional: Recent state root indices of the input state
2788
+ */
2789
+ recentInputStateRootIndices: number[];
2790
+ };
2791
+ /**
2792
+ * Create compressed token accounts
2793
+ */
2794
+ type MintToParams = {
2795
+ /**
2796
+ * Tx feepayer
2797
+ */
2798
+ feePayer: PublicKey;
2799
+ /**
2800
+ * Mint authority
2801
+ */
2802
+ authority: PublicKey;
2803
+ /**
2804
+ * Mint public key
2805
+ */
2806
+ mint: PublicKey;
2807
+ /**
2808
+ * The Solana Public Keys to mint to.
2809
+ */
2810
+ toPubkey: PublicKey[] | PublicKey;
2811
+ /**
2812
+ * The amount of compressed tokens to mint.
2813
+ */
2814
+ amount: BN | BN[] | number | number[];
2815
+ /**
2816
+ * The state tree to mint into.
2817
+ */
2818
+ outputStateTreeInfo: StateTreeInfo;
2819
+ /**
2820
+ * Tokenpool addresses. One or more token pools can be provided.
2821
+ */
2822
+ tokenPoolInfo: TokenPoolInfo;
2823
+ };
2824
+ /**
2825
+ * Register an existing SPL mint account to the compressed token program
2826
+ * Creates an omnibus account for the mint
2827
+ */
2828
+ type RegisterMintParams = {
2829
+ /**
2830
+ * Tx feepayer
2831
+ */
2832
+ feePayer: PublicKey;
2833
+ /**
2834
+ * Mint public key
2835
+ */
2836
+ mint: PublicKey;
2837
+ /**
2838
+ * Optional: The token program ID. Default: SPL Token Program ID
2839
+ */
2840
+ tokenProgramId?: PublicKey;
2841
+ };
2842
+ type AddTokenPoolParams = {
2843
+ /**
2844
+ * Tx feepayer
2845
+ */
2846
+ feePayer: PublicKey;
2847
+ /**
2848
+ * Mint public key
2849
+ */
2850
+ mint: PublicKey;
2851
+ /**
2852
+ * Optional: The token program ID. Default: SPL Token Program ID
2853
+ */
2854
+ tokenProgramId?: PublicKey;
2855
+ /**
2856
+ * Optional: index for the token pool. Default: 0
2857
+ */
2858
+ poolIndex: number;
2859
+ };
2860
+ /**
2861
+ * Mint from existing SPL mint to compressed token accounts
2862
+ */
2863
+ type ApproveAndMintToParams = {
2864
+ /**
2865
+ * Tx feepayer
2866
+ */
2867
+ feePayer: PublicKey;
2868
+ /**
2869
+ * Mint authority
2870
+ */
2871
+ authority: PublicKey;
2872
+ /**
2873
+ * Mint authority (associated) token account
2874
+ */
2875
+ authorityTokenAccount: PublicKey;
2876
+ /**
2877
+ * Mint public key
2878
+ */
2879
+ mint: PublicKey;
2880
+ /**
2881
+ * The Solana Public Key to mint to.
2882
+ */
2883
+ toPubkey: PublicKey;
2884
+ /**
2885
+ * The amount of compressed tokens to mint.
2886
+ */
2887
+ amount: BN | number;
2888
+ /**
2889
+ * The state tree to mint into. Defaults to a public state
2890
+ * tree if unspecified.
2891
+ */
2892
+ outputStateTreeInfo: StateTreeInfo;
2893
+ /**
2894
+ * Tokenpool addresses. One or more token pools can be provided.
2895
+ */
2896
+ tokenPoolInfo: TokenPoolInfo;
2897
+ };
2898
+ type CreateTokenProgramLookupTableParams = {
2899
+ /**
2900
+ * The payer of the transaction.
2901
+ */
2902
+ payer: PublicKey;
2903
+ /**
2904
+ * The authority of the transaction.
2905
+ */
2906
+ authority: PublicKey;
2907
+ /**
2908
+ * Recently finalized Solana slot.
2909
+ */
2910
+ recentSlot: number;
2911
+ /**
2912
+ * Optional Mint addresses to store in the lookup table.
2913
+ */
2914
+ mints?: PublicKey[];
2915
+ /**
2916
+ * Optional additional addresses to store in the lookup table.
2917
+ */
2918
+ remainingAccounts?: PublicKey[];
2919
+ };
2920
+ /**
2921
+ * Sum up the token amounts of the compressed token accounts
2922
+ */
2923
+ declare const sumUpTokenAmount: (accounts: ParsedTokenAccount[]) => BN;
2924
+ /**
2925
+ * Validate that all the compressed token accounts are owned by the same owner.
2926
+ */
2927
+ declare const validateSameTokenOwner: (accounts: ParsedTokenAccount[]) => void;
2928
+ /**
2929
+ * Parse compressed token accounts to get the mint, current owner and delegate.
2930
+ */
2931
+ declare const parseTokenData: (compressedTokenAccounts: ParsedTokenAccount[]) => {
2932
+ mint: PublicKey;
2933
+ currentOwner: PublicKey;
2934
+ delegate: PublicKey | null;
2935
+ };
2936
+ declare const parseMaybeDelegatedTransfer: (inputs: ParsedTokenAccount[], outputs: TokenTransferOutputData[]) => {
2937
+ delegatedTransfer: DelegatedTransfer | null;
2938
+ authority: PublicKey;
2939
+ };
2940
+ /**
2941
+ * Create the output state for a transfer transaction.
2942
+ * @param inputCompressedTokenAccounts Input state
2943
+ * @param toAddress Recipient address
2944
+ * @param amount Amount of tokens to transfer
2945
+ * @returns Output token data for the transfer
2946
+ * instruction
2947
+ */
2948
+ declare function createTransferOutputState(inputCompressedTokenAccounts: ParsedTokenAccount[], toAddress: PublicKey, amount: number | BN): TokenTransferOutputData[];
2949
+ /**
2950
+ * Create the output state for a compress transaction.
2951
+ * @param inputCompressedTokenAccounts Input state
2952
+ * @param amount Amount of tokens to compress
2953
+ * @returns Output token data for the compress
2954
+ * instruction
2955
+ */
2956
+ declare function createDecompressOutputState(inputCompressedTokenAccounts: ParsedTokenAccount[], amount: number | BN): TokenTransferOutputData[];
2957
+ declare class CompressedTokenProgram {
2958
+ /**
2959
+ * @internal
2960
+ */
2961
+ constructor();
2962
+ /**
2963
+ * Public key that identifies the CompressedPda program
2964
+ */
2965
+ static programId: PublicKey;
2966
+ /**
2967
+ * Set a custom programId via PublicKey or base58 encoded string.
2968
+ * This method is not required for regular usage.
2969
+ *
2970
+ * Use this only if you know what you are doing.
2971
+ */
2972
+ static setProgramId(programId: PublicKey | string): void;
2973
+ /**
2974
+ * Derive the token pool pda.
2975
+ * To derive the token pool pda with bump, use {@link deriveTokenPoolPdaWithBump}.
2976
+ *
2977
+ * @param mint The mint of the token pool
2978
+ *
2979
+ * @returns The token pool pda
2980
+ */
2981
+ static deriveTokenPoolPda(mint: PublicKey): PublicKey;
2982
+ /**
2983
+ * Derive the token pool pda with bump.
2984
+ *
2985
+ * @param mint The mint of the token pool
2986
+ * @param bump Bump. starts at 0. The Protocol supports 4 bumps aka token pools
2987
+ * per mint.
2988
+ *
2989
+ * @returns The token pool pda
2990
+ */
2991
+ static deriveTokenPoolPdaWithBump(mint: PublicKey, bump: number): PublicKey;
2992
+ /** @internal */
2993
+ static get deriveCpiAuthorityPda(): PublicKey;
2994
+ /**
2995
+ * Construct createMint instruction for compressed tokens.
2996
+ * @returns [createMintAccountInstruction, initializeMintInstruction, createTokenPoolInstruction]
2997
+ *
2998
+ * Note that `createTokenPoolInstruction` must be executed after `initializeMintInstruction`.
2999
+ */
3000
+ static createMint(params: CreateMintParams): Promise<TransactionInstruction[]>;
3001
+ /**
3002
+ * Enable compression for an existing SPL mint, creating an omnibus account.
3003
+ * For new mints, use `CompressedTokenProgram.createMint`.
3004
+ */
3005
+ static createTokenPool(params: RegisterMintParams): Promise<TransactionInstruction>;
3006
+ /**
3007
+ * Enable compression for an existing SPL mint, creating an omnibus account.
3008
+ * For new mints, use `CompressedTokenProgram.createMint`.
3009
+ */
3010
+ static addTokenPool(params: AddTokenPoolParams): Promise<TransactionInstruction>;
3011
+ /**
3012
+ * Construct mintTo instruction for compressed tokens
3013
+ */
3014
+ static mintTo(params: MintToParams): Promise<TransactionInstruction>;
3015
+ /**
3016
+ * Mint tokens from registered SPL mint account to a compressed account
3017
+ */
3018
+ static approveAndMintTo(params: ApproveAndMintToParams): Promise<TransactionInstruction[]>;
3019
+ /**
3020
+ * Construct transfer instruction for compressed tokens
3021
+ */
3022
+ static transfer(params: TransferParams): Promise<TransactionInstruction>;
3023
+ /**
3024
+ * Create lookup table instructions for the token program's default accounts.
3025
+ */
3026
+ static createTokenProgramLookupTable(params: CreateTokenProgramLookupTableParams): Promise<{
3027
+ instructions: TransactionInstruction[];
3028
+ address: PublicKey;
3029
+ }>;
3030
+ /**
3031
+ * Create compress instruction
3032
+ * @returns compressInstruction
3033
+ */
3034
+ static compress(params: CompressParams): Promise<TransactionInstruction>;
3035
+ /**
3036
+ * Construct decompress instruction
3037
+ */
3038
+ static decompress(params: DecompressParams): Promise<TransactionInstruction>;
3039
+ static mergeTokenAccounts(params: MergeTokenAccountsParams): Promise<TransactionInstruction[]>;
3040
+ static compressSplTokenAccount(params: CompressSplTokenAccountParams): Promise<TransactionInstruction>;
3041
+ static getMintProgramId(mint: PublicKey, connection: Connection): Promise<PublicKey | undefined>;
3042
+ static approve(params: TransferParams): Promise<TransactionInstruction>;
3043
+ static revoke(params: RevokeParams): Promise<TransactionInstruction>;
3044
+ }
2669
3045
 
2670
- export { type ApproveAndMintToParams, COMPRESS_SPL_TOKEN_ACCOUNT_DISCRIMINATOR, CPI_AUTHORITY_SEED, CREATE_TOKEN_POOL_DISCRIMINATOR, type CompressParams, type CompressSplTokenAccountInstructionData, type CompressSplTokenAccountParams, type CompressedCpiContext, type CompressedTokenInstructionDataTransfer, CompressedTokenInstructionDataTransferLayout, CompressedTokenProgram, CpiContextLayout, type CreateMintParams, type CreateTokenProgramLookupTableParams, type DecompressParams, type DelegatedTransfer, DelegatedTransferLayout, ERROR_NO_ACCOUNTS_FOUND, IDL, type InputTokenDataWithContext, type LightCompressedToken, MINT_TO_DISCRIMINATOR, type MergeTokenAccountsParams, type MintToInstructionData, type MintToParams, POOL_SEED, type PackCompressedTokenAccountsParams, type PackedTokenTransferOutputData, type RegisterMintParams, SPL_TOKEN_MINT_RENT_EXEMPT_BALANCE, TRANSFER_DISCRIMINATOR, type TokenData, type TokenTransferOutputData, type TransferParams, type approveAccountsLayoutParams, approveAndMintTo, compress, compressSplTokenAccount, compressSplTokenAccountInstructionDataLayout, createDecompressOutputState, createMint, createTokenPool, createTokenPoolAccountsLayout, type createTokenPoolAccountsLayoutParams, createTokenProgramLookupTable, createTransferOutputState, decodeCompressSplTokenAccountInstructionData, decodeMintToInstructionData, decodeTransferInstructionData, decompress, encodeCompressSplTokenAccountInstructionData, encodeMintToInstructionData, encodeTransferInstructionData, type freezeAccountsLayoutParams, mergeTokenAccounts, mintTo, mintToAccountsLayout, type mintToAccountsLayoutParams, mintToLayout, packCompressedTokenAccounts, parseTokenData, type revokeAccountsLayoutParams, selectMinCompressedTokenAccountsForTransfer, selectMinCompressedTokenAccountsForTransferOrPartial, selectSmartCompressedTokenAccountsForTransfer, selectSmartCompressedTokenAccountsForTransferOrPartial, sumUpTokenAmount, type thawAccountsLayoutParams, transfer, transferAccountsLayout, type transferAccountsLayoutParams, validateSameTokenOwner };
3046
+ export { ADD_TOKEN_POOL_DISCRIMINATOR, APPROVE_DISCRIMINATOR, Action, type AddTokenPoolParams, type ApproveAndMintToParams, type ApproveParams, COMPRESS_SPL_TOKEN_ACCOUNT_DISCRIMINATOR, CPI_AUTHORITY_SEED, CREATE_TOKEN_POOL_DISCRIMINATOR, type CompressParams, type CompressSplTokenAccountInstructionData, type CompressSplTokenAccountParams, type CompressedCpiContext, type CompressedTokenInstructionDataApprove, CompressedTokenInstructionDataApproveLayout, type CompressedTokenInstructionDataRevoke, CompressedTokenInstructionDataRevokeLayout, type CompressedTokenInstructionDataTransfer, CompressedTokenInstructionDataTransferLayout, CompressedTokenProgram, CpiContextLayout, type CreateMintParams, type CreateTokenProgramLookupTableParams, type DecompressParams, type DelegatedTransfer, DelegatedTransferLayout, ERROR_NO_ACCOUNTS_FOUND, IDL, type InputTokenDataWithContext, type LightCompressedToken, MINT_TO_DISCRIMINATOR, type MergeTokenAccountsParams, type MintToInstructionData, type MintToParams, POOL_SEED, type PackCompressedTokenAccountsParams, type PackedTokenTransferOutputData, REVOKE_DISCRIMINATOR, type RegisterMintParams, type RevokeParams, SPL_TOKEN_MINT_RENT_EXEMPT_BALANCE, TRANSFER_DISCRIMINATOR, type TokenData, type TokenPoolActivity, type TokenPoolInfo, type TokenTransferOutputData, type TransferParams, addTokenPoolAccountsLayout, type addTokenPoolAccountsLayoutParams, addTokenPools, approve, approveAccountsLayout, type approveAccountsLayoutParams, approveAndMintTo, checkTokenPoolInfo, compress, compressSplTokenAccount, compressSplTokenAccountInstructionDataLayout, createDecompressOutputState, createMint, createTokenPool, createTokenPoolAccountsLayout, type createTokenPoolAccountsLayoutParams, createTokenProgramLookupTable, createTransferOutputState, decodeApproveInstructionData, decodeCompressSplTokenAccountInstructionData, decodeMintToInstructionData, decodeRevokeInstructionData, decodeTransferInstructionData, decompress, decompressDelegated, encodeApproveInstructionData, encodeCompressSplTokenAccountInstructionData, encodeMintToInstructionData, encodeRevokeInstructionData, encodeTransferInstructionData, freezeAccountsLayout, type freezeAccountsLayoutParams, getTokenPoolInfos, isSingleTokenPoolInfo, mergeTokenAccounts, mintTo, mintToAccountsLayout, type mintToAccountsLayoutParams, mintToLayout, packCompressedTokenAccounts, parseMaybeDelegatedTransfer, parseTokenData, revoke, revokeAccountsLayout, type revokeAccountsLayoutParams, selectMinCompressedTokenAccountsForDecompression, selectMinCompressedTokenAccountsForTransfer, selectMinCompressedTokenAccountsForTransferOrPartial, selectSmartCompressedTokenAccountsForTransfer, selectSmartCompressedTokenAccountsForTransferOrPartial, selectTokenAccountsForApprove, selectTokenPoolInfo, selectTokenPoolInfosForDecompression, sumUpTokenAmount, thawAccountsLayout, type thawAccountsLayoutParams, transfer, transferAccountsLayout, type transferAccountsLayoutParams, transferDelegated, validateSameTokenOwner };