@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.
@@ -4834,15 +4834,34 @@ class CompressedTokenProgram {
4834
4834
  */
4835
4835
  static async compress(params) {
4836
4836
  const { payer, owner, source, toAddress, mint, outputStateTree } = params;
4837
- const amount = stateless_js.bn(params.amount);
4838
- const tokenTransferOutputs = [
4839
- {
4840
- owner: toAddress,
4841
- amount,
4842
- lamports: stateless_js.bn(0),
4843
- tlv: null,
4844
- },
4845
- ];
4837
+ if (Array.isArray(params.amount) !== Array.isArray(params.toAddress)) {
4838
+ throw new Error('Both amount and toAddress must be arrays or both must be single values');
4839
+ }
4840
+ let tokenTransferOutputs;
4841
+ if (Array.isArray(params.amount) && Array.isArray(params.toAddress)) {
4842
+ if (params.amount.length !== params.toAddress.length) {
4843
+ throw new Error('Amount and toAddress arrays must have the same length');
4844
+ }
4845
+ tokenTransferOutputs = params.amount.map((amt, index) => {
4846
+ const amount = stateless_js.bn(amt);
4847
+ return {
4848
+ owner: params.toAddress[index],
4849
+ amount,
4850
+ lamports: stateless_js.bn(0),
4851
+ tlv: null,
4852
+ };
4853
+ });
4854
+ }
4855
+ else {
4856
+ tokenTransferOutputs = [
4857
+ {
4858
+ owner: toAddress,
4859
+ amount: stateless_js.bn(params.amount),
4860
+ lamports: stateless_js.bn(0),
4861
+ tlv: null,
4862
+ },
4863
+ ];
4864
+ }
4846
4865
  const { inputTokenDataWithContext, packedOutputTokenData, remainingAccountMetas, } = packCompressedTokenAccounts({
4847
4866
  inputCompressedTokenAccounts: [],
4848
4867
  outputStateTrees: outputStateTree,
@@ -4855,7 +4874,11 @@ class CompressedTokenProgram {
4855
4874
  delegatedTransfer: null, // TODO: implement
4856
4875
  inputTokenDataWithContext,
4857
4876
  outputCompressedAccounts: packedOutputTokenData,
4858
- compressOrDecompressAmount: amount,
4877
+ compressOrDecompressAmount: Array.isArray(params.amount)
4878
+ ? params.amount
4879
+ .map(amt => new anchor.BN(amt))
4880
+ .reduce((sum, amt) => sum.add(amt), new anchor.BN(0))
4881
+ : new anchor.BN(params.amount),
4859
4882
  isCompress: true,
4860
4883
  cpiContext: null,
4861
4884
  lamportsChangeAccountMerkleTreeIndex: null,
@@ -4992,7 +5015,6 @@ async function approveAndMintTo(rpc, payer, mint, destination, authority, amount
4992
5015
  * @return Signature of the confirmed transaction
4993
5016
  */
4994
5017
  async function compress(rpc, payer, mint, amount, owner, sourceTokenAccount, toAddress, merkleTree, confirmOptions) {
4995
- amount = stateless_js.bn(amount);
4996
5018
  const compressIx = await CompressedTokenProgram.compress({
4997
5019
  payer: payer.publicKey,
4998
5020
  owner: owner.publicKey,