@lightprotocol/compressed-token 0.8.0 → 0.10.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.
@@ -6857,15 +6857,34 @@ class CompressedTokenProgram {
6857
6857
  */
6858
6858
  static async compress(params) {
6859
6859
  const { payer, owner, source, toAddress, mint, outputStateTree } = params;
6860
- const amount = stateless_js.bn(params.amount);
6861
- const tokenTransferOutputs = [
6862
- {
6863
- owner: toAddress,
6864
- amount,
6865
- lamports: stateless_js.bn(0),
6866
- tlv: null,
6867
- },
6868
- ];
6860
+ if (Array.isArray(params.amount) !== Array.isArray(params.toAddress)) {
6861
+ throw new Error('Both amount and toAddress must be arrays or both must be single values');
6862
+ }
6863
+ let tokenTransferOutputs;
6864
+ if (Array.isArray(params.amount) && Array.isArray(params.toAddress)) {
6865
+ if (params.amount.length !== params.toAddress.length) {
6866
+ throw new Error('Amount and toAddress arrays must have the same length');
6867
+ }
6868
+ tokenTransferOutputs = params.amount.map((amt, index) => {
6869
+ const amount = stateless_js.bn(amt);
6870
+ return {
6871
+ owner: params.toAddress[index],
6872
+ amount,
6873
+ lamports: stateless_js.bn(0),
6874
+ tlv: null,
6875
+ };
6876
+ });
6877
+ }
6878
+ else {
6879
+ tokenTransferOutputs = [
6880
+ {
6881
+ owner: toAddress,
6882
+ amount: stateless_js.bn(params.amount),
6883
+ lamports: stateless_js.bn(0),
6884
+ tlv: null,
6885
+ },
6886
+ ];
6887
+ }
6869
6888
  const { inputTokenDataWithContext, packedOutputTokenData, remainingAccountMetas, } = packCompressedTokenAccounts({
6870
6889
  inputCompressedTokenAccounts: [],
6871
6890
  outputStateTrees: outputStateTree,
@@ -6878,7 +6897,11 @@ class CompressedTokenProgram {
6878
6897
  delegatedTransfer: null, // TODO: implement
6879
6898
  inputTokenDataWithContext,
6880
6899
  outputCompressedAccounts: packedOutputTokenData,
6881
- compressOrDecompressAmount: amount,
6900
+ compressOrDecompressAmount: Array.isArray(params.amount)
6901
+ ? params.amount
6902
+ .map(amt => new anchor.BN(amt))
6903
+ .reduce((sum, amt) => sum.add(amt), new anchor.BN(0))
6904
+ : new anchor.BN(params.amount),
6882
6905
  isCompress: true,
6883
6906
  cpiContext: null,
6884
6907
  lamportsChangeAccountMerkleTreeIndex: null,
@@ -7015,7 +7038,6 @@ async function approveAndMintTo(rpc, payer, mint, destination, authority, amount
7015
7038
  * @return Signature of the confirmed transaction
7016
7039
  */
7017
7040
  async function compress(rpc, payer, mint, amount, owner, sourceTokenAccount, toAddress, merkleTree, confirmOptions) {
7018
- amount = stateless_js.bn(amount);
7019
7041
  const compressIx = await CompressedTokenProgram.compress({
7020
7042
  payer: payer.publicKey,
7021
7043
  owner: owner.publicKey,