@lightprotocol/compressed-token - v0.22.1-alpha.2
    Preparing search index...

    Function selectSmartCompressedTokenAccountsForTransfer

    • Selects compressed token accounts for a transfer, ensuring one extra account if possible, up to maxInputs.

      1. Sorts accounts by amount (desc)
      2. Selects accounts until transfer amount is met or maxInputs is reached, attempting to add one extra account if possible.

      Parameters

      • accounts: ParsedTokenAccount[]

        The list of token accounts to select from.

      • transferAmount: BN

        The token amount to be transferred.

      • OptionalmaxInputs: number = 4

        The maximum number of accounts to select. Default: 4.

      Returns [
          selectedAccounts: ParsedTokenAccount[],
          total: BN,
          totalLamports: BN
          | null,
          maxPossibleAmount: BN,
      ]

      • An array containing:
        • selectedAccounts: The accounts selected for the transfer.
        • total: The total amount accumulated from the selected accounts.
        • totalLamports: The total lamports accumulated from the selected accounts.
        • maxPossibleAmount: The maximum possible amount that can be transferred considering maxInputs.
      const accounts = [
      { parsed: { amount: new BN(100) }, compressedAccount: { lamports: new BN(10) } },
      { parsed: { amount: new BN(50) }, compressedAccount: { lamports: new BN(5) } },
      { parsed: { amount: new BN(25) }, compressedAccount: { lamports: new BN(2) } },
      ];
      const transferAmount = new BN(75);
      const maxInputs = 2;

      const [selectedAccounts, total, totalLamports, maxPossibleAmount] =
      selectSmartCompressedTokenAccountsForTransfer(accounts, transferAmount, maxInputs);

      console.log(selectedAccounts.length); // 2
      console.log(total.toString()); // '150'
      console.log(totalLamports!.toString()); // '15'
      console.log(maxPossibleAmount.toString()); // '150'