@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.
@@ -1,6 +1,6 @@
1
1
  import { getIndexOrAdd, bn, padOutputStateMerkleTrees, useWallet, confirmConfig, defaultStaticAccountsStruct, toArray, LightSystemProgram, defaultTestStateTreeAccounts, sumUpLamports, validateSufficientBalance, validateSameOwner, dedupeSigner, buildAndSignTx, sendAndConfirmTx } from '@lightprotocol/stateless.js';
2
2
  import { PublicKey, SystemProgram, TransactionInstruction, Transaction, sendAndConfirmTransaction, Keypair, Connection, ComputeBudgetProgram } from '@solana/web3.js';
3
- import { AnchorProvider, setProvider, Program } from '@coral-xyz/anchor';
3
+ import { AnchorProvider, setProvider, Program, BN } from '@coral-xyz/anchor';
4
4
 
5
5
  const IDL = {
6
6
  version: '0.5.0',
@@ -6859,15 +6859,34 @@ class CompressedTokenProgram {
6859
6859
  */
6860
6860
  static async compress(params) {
6861
6861
  const { payer, owner, source, toAddress, mint, outputStateTree } = params;
6862
- const amount = bn(params.amount);
6863
- const tokenTransferOutputs = [
6864
- {
6865
- owner: toAddress,
6866
- amount,
6867
- lamports: bn(0),
6868
- tlv: null,
6869
- },
6870
- ];
6862
+ if (Array.isArray(params.amount) !== Array.isArray(params.toAddress)) {
6863
+ throw new Error('Both amount and toAddress must be arrays or both must be single values');
6864
+ }
6865
+ let tokenTransferOutputs;
6866
+ if (Array.isArray(params.amount) && Array.isArray(params.toAddress)) {
6867
+ if (params.amount.length !== params.toAddress.length) {
6868
+ throw new Error('Amount and toAddress arrays must have the same length');
6869
+ }
6870
+ tokenTransferOutputs = params.amount.map((amt, index) => {
6871
+ const amount = bn(amt);
6872
+ return {
6873
+ owner: params.toAddress[index],
6874
+ amount,
6875
+ lamports: bn(0),
6876
+ tlv: null,
6877
+ };
6878
+ });
6879
+ }
6880
+ else {
6881
+ tokenTransferOutputs = [
6882
+ {
6883
+ owner: toAddress,
6884
+ amount: bn(params.amount),
6885
+ lamports: bn(0),
6886
+ tlv: null,
6887
+ },
6888
+ ];
6889
+ }
6871
6890
  const { inputTokenDataWithContext, packedOutputTokenData, remainingAccountMetas, } = packCompressedTokenAccounts({
6872
6891
  inputCompressedTokenAccounts: [],
6873
6892
  outputStateTrees: outputStateTree,
@@ -6880,7 +6899,11 @@ class CompressedTokenProgram {
6880
6899
  delegatedTransfer: null, // TODO: implement
6881
6900
  inputTokenDataWithContext,
6882
6901
  outputCompressedAccounts: packedOutputTokenData,
6883
- compressOrDecompressAmount: amount,
6902
+ compressOrDecompressAmount: Array.isArray(params.amount)
6903
+ ? params.amount
6904
+ .map(amt => new BN(amt))
6905
+ .reduce((sum, amt) => sum.add(amt), new BN(0))
6906
+ : new BN(params.amount),
6884
6907
  isCompress: true,
6885
6908
  cpiContext: null,
6886
6909
  lamportsChangeAccountMerkleTreeIndex: null,
@@ -7012,7 +7035,6 @@ async function approveAndMintTo(rpc, payer, mint, destination, authority, amount
7012
7035
  * @return Signature of the confirmed transaction
7013
7036
  */
7014
7037
  async function compress(rpc, payer, mint, amount, owner, sourceTokenAccount, toAddress, merkleTree, confirmOptions) {
7015
- amount = bn(amount);
7016
7038
  const compressIx = await CompressedTokenProgram.compress({
7017
7039
  payer: payer.publicKey,
7018
7040
  owner: owner.publicKey,