@lightprotocol/compressed-token 0.20.6 → 0.20.8
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/types/index.d.ts
CHANGED
|
@@ -2562,10 +2562,37 @@ declare const IDL: LightCompressedToken;
|
|
|
2562
2562
|
|
|
2563
2563
|
declare const ERROR_NO_ACCOUNTS_FOUND = "Could not find accounts to select for transfer.";
|
|
2564
2564
|
/**
|
|
2565
|
-
* Selects the
|
|
2565
|
+
* Selects the minimum number of compressed token accounts required for a transfer, up to a specified maximum.
|
|
2566
2566
|
*
|
|
2567
|
-
*
|
|
2568
|
-
*
|
|
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'
|
|
2569
2596
|
*/
|
|
2570
2597
|
declare function selectMinCompressedTokenAccountsForTransfer(accounts: ParsedTokenAccount[], transferAmount: BN, maxInputs?: number): [
|
|
2571
2598
|
selectedAccounts: ParsedTokenAccount[],
|
|
@@ -2574,12 +2601,12 @@ declare function selectMinCompressedTokenAccountsForTransfer(accounts: ParsedTok
|
|
|
2574
2601
|
maxPossibleAmount: BN
|
|
2575
2602
|
];
|
|
2576
2603
|
/**
|
|
2577
|
-
* Selects the minimal number of compressed token accounts for a transfer
|
|
2604
|
+
* Selects the minimal number of compressed token accounts for a transfer orPartially.
|
|
2578
2605
|
*
|
|
2579
2606
|
* 1. Sorts accounts by amount (descending)
|
|
2580
2607
|
* 2. Accumulates amount until it meets or exceeds transfer amount
|
|
2581
2608
|
*/
|
|
2582
|
-
declare function
|
|
2609
|
+
declare function selectMinCompressedTokenAccountsForTransferOrPartial(accounts: ParsedTokenAccount[], transferAmount: BN, maxInputs?: number): [
|
|
2583
2610
|
selectedAccounts: ParsedTokenAccount[],
|
|
2584
2611
|
total: BN,
|
|
2585
2612
|
totalLamports: BN | null,
|
|
@@ -2590,7 +2617,39 @@ declare function selectMinCompressedTokenAccountsForTransferIdempotent(accounts:
|
|
|
2590
2617
|
* if possible, up to maxInputs.
|
|
2591
2618
|
*
|
|
2592
2619
|
* 1. Sorts accounts by amount (desc)
|
|
2593
|
-
* 2. Selects accounts until transfer amount is met or
|
|
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'
|
|
2594
2653
|
*/
|
|
2595
2654
|
declare function selectSmartCompressedTokenAccountsForTransfer(accounts: ParsedTokenAccount[], transferAmount: BN, maxInputs?: number): [
|
|
2596
2655
|
selectedAccounts: ParsedTokenAccount[],
|
|
@@ -2599,18 +2658,13 @@ declare function selectSmartCompressedTokenAccountsForTransfer(accounts: ParsedT
|
|
|
2599
2658
|
maxPossibleAmount: BN
|
|
2600
2659
|
];
|
|
2601
2660
|
/**
|
|
2602
|
-
*
|
|
2603
|
-
* account than needed, up to maxInputs, with the extra being the smallest.
|
|
2604
|
-
*
|
|
2605
|
-
* 1. Sorts accounts by amount (desc)
|
|
2606
|
-
* 2. Selects accounts until transfer amount is met, then adds the smallest
|
|
2607
|
-
* extra account if possible
|
|
2661
|
+
* orPartially runs {@link selectSmartCompressedTokenAccountsForTransfer} strategy.
|
|
2608
2662
|
*/
|
|
2609
|
-
declare function
|
|
2663
|
+
declare function selectSmartCompressedTokenAccountsForTransferOrPartial(accounts: ParsedTokenAccount[], transferAmount: BN, maxInputs?: number): [
|
|
2610
2664
|
selectedAccounts: ParsedTokenAccount[],
|
|
2611
2665
|
total: BN,
|
|
2612
2666
|
totalLamports: BN | null,
|
|
2613
2667
|
maxPossibleAmount: BN
|
|
2614
2668
|
];
|
|
2615
2669
|
|
|
2616
|
-
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,
|
|
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 };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lightprotocol/compressed-token",
|
|
3
|
-
"version": "0.20.
|
|
3
|
+
"version": "0.20.8",
|
|
4
4
|
"description": "JS client to interact with the compressed-token program",
|
|
5
5
|
"sideEffects": false,
|
|
6
6
|
"main": "dist/cjs/node/index.cjs",
|
|
@@ -31,7 +31,7 @@
|
|
|
31
31
|
"peerDependencies": {
|
|
32
32
|
"@solana/spl-token": ">=0.3.9",
|
|
33
33
|
"@solana/web3.js": ">=1.73.5",
|
|
34
|
-
"@lightprotocol/stateless.js": "0.20.
|
|
34
|
+
"@lightprotocol/stateless.js": "0.20.8"
|
|
35
35
|
},
|
|
36
36
|
"dependencies": {
|
|
37
37
|
"@coral-xyz/borsh": "^0.29.0",
|