@lightprotocol/compressed-token 0.20.5 → 0.20.7

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.
@@ -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 minimal number of compressed token accounts for a transfer.
2565
+ * Selects the minimum number of compressed token accounts required for a transfer, up to a specified maximum.
2566
2566
  *
2567
- * 1. Sorts accounts by amount (descending)
2568
- * 2. Accumulates amount until it meets or exceeds transfer amount
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[],
@@ -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 cap is reached
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,12 +2658,7 @@ declare function selectSmartCompressedTokenAccountsForTransfer(accounts: ParsedT
2599
2658
  maxPossibleAmount: BN
2600
2659
  ];
2601
2660
  /**
2602
- * Idempotently selects compressed token accounts for a transfer. Picks one more
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
+ * Idempotently runs {@link selectSmartCompressedTokenAccountsForTransfer} strategy.
2608
2662
  */
2609
2663
  declare function selectSmartCompressedTokenAccountsForTransferIdempotent(accounts: ParsedTokenAccount[], transferAmount: BN, maxInputs?: number): [
2610
2664
  selectedAccounts: ParsedTokenAccount[],
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lightprotocol/compressed-token",
3
- "version": "0.20.5",
3
+ "version": "0.20.7",
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.5"
34
+ "@lightprotocol/stateless.js": "0.20.7"
35
35
  },
36
36
  "dependencies": {
37
37
  "@coral-xyz/borsh": "^0.29.0",