@lightprotocol/compressed-token 0.12.0 → 0.14.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.
@@ -3,7 +3,7 @@ import { PublicKey, SystemProgram, TransactionInstruction, Transaction, sendAndC
3
3
  import { AnchorProvider, setProvider, Program, BN } from '@coral-xyz/anchor';
4
4
 
5
5
  const IDL = {
6
- version: '1.0.0',
6
+ version: '1.2.0',
7
7
  name: 'light_compressed_token',
8
8
  instructions: [
9
9
  {
@@ -1553,128 +1553,23 @@ const IDL = {
1553
1553
  errors: [
1554
1554
  {
1555
1555
  code: 6000,
1556
- name: 'PublicKeyAmountMissmatch',
1557
- msg: 'public keys and amounts must be of same length',
1556
+ name: 'SignerCheckFailed',
1557
+ msg: 'Signer check failed',
1558
1558
  },
1559
1559
  {
1560
1560
  code: 6001,
1561
- name: 'ComputeInputSumFailed',
1562
- msg: 'ComputeInputSumFailed',
1561
+ name: 'CreateTransferInstructionFailed',
1562
+ msg: 'Create transfer instruction failed',
1563
1563
  },
1564
1564
  {
1565
1565
  code: 6002,
1566
- name: 'ComputeOutputSumFailed',
1567
- msg: 'ComputeOutputSumFailed',
1566
+ name: 'AccountNotFound',
1567
+ msg: 'Account not found',
1568
1568
  },
1569
1569
  {
1570
1570
  code: 6003,
1571
- name: 'ComputeCompressSumFailed',
1572
- msg: 'ComputeCompressSumFailed',
1573
- },
1574
- {
1575
- code: 6004,
1576
- name: 'ComputeDecompressSumFailed',
1577
- msg: 'ComputeDecompressSumFailed',
1578
- },
1579
- {
1580
- code: 6005,
1581
- name: 'SumCheckFailed',
1582
- msg: 'SumCheckFailed',
1583
- },
1584
- {
1585
- code: 6006,
1586
- name: 'DecompressRecipientUndefinedForDecompress',
1587
- msg: 'DecompressRecipientUndefinedForDecompress',
1588
- },
1589
- {
1590
- code: 6007,
1591
- name: 'CompressedPdaUndefinedForDecompress',
1592
- msg: 'CompressedPdaUndefinedForDecompress',
1593
- },
1594
- {
1595
- code: 6008,
1596
- name: 'DeCompressAmountUndefinedForDecompress',
1597
- msg: 'DeCompressAmountUndefinedForDecompress',
1598
- },
1599
- {
1600
- code: 6009,
1601
- name: 'CompressedPdaUndefinedForCompress',
1602
- msg: 'CompressedPdaUndefinedForCompress',
1603
- },
1604
- {
1605
- code: 6010,
1606
- name: 'DeCompressAmountUndefinedForCompress',
1607
- msg: 'DeCompressAmountUndefinedForCompress',
1608
- },
1609
- {
1610
- code: 6011,
1611
- name: 'DelegateSignerCheckFailed',
1612
- msg: 'DelegateSignerCheckFailed',
1613
- },
1614
- {
1615
- code: 6012,
1616
- name: 'MintTooLarge',
1617
- msg: 'Minted amount greater than u64::MAX',
1618
- },
1619
- {
1620
- code: 6013,
1621
- name: 'SplTokenSupplyMismatch',
1622
- msg: 'SplTokenSupplyMismatch',
1623
- },
1624
- {
1625
- code: 6014,
1626
- name: 'HeapMemoryCheckFailed',
1627
- msg: 'HeapMemoryCheckFailed',
1628
- },
1629
- {
1630
- code: 6015,
1631
- name: 'InstructionNotCallable',
1632
- msg: 'The instruction is not callable',
1633
- },
1634
- {
1635
- code: 6016,
1636
- name: 'ArithmeticUnderflow',
1637
- msg: 'ArithmeticUnderflow',
1638
- },
1639
- {
1640
- code: 6017,
1641
- name: 'HashToFieldError',
1642
- msg: 'HashToFieldError',
1643
- },
1644
- {
1645
- code: 6018,
1646
- name: 'InvalidAuthorityMint',
1647
- msg: 'Expected the authority to be also a mint authority',
1648
- },
1649
- {
1650
- code: 6019,
1651
- name: 'InvalidFreezeAuthority',
1652
- msg: 'Provided authority is not the freeze authority',
1653
- },
1654
- {
1655
- code: 6020,
1656
- name: 'InvalidDelegateIndex',
1657
- },
1658
- {
1659
- code: 6021,
1660
- name: 'TokenPoolPdaUndefined',
1661
- },
1662
- {
1663
- code: 6022,
1664
- name: 'IsTokenPoolPda',
1665
- msg: 'Compress or decompress recipient is the same account as the token pool pda.',
1666
- },
1667
- {
1668
- code: 6023,
1669
- name: 'InvalidTokenPoolPda',
1670
- },
1671
- {
1672
- code: 6024,
1673
- name: 'NoInputTokenAccountsProvided',
1674
- },
1675
- {
1676
- code: 6025,
1677
- name: 'NoInputsProvided',
1571
+ name: 'SerializationError',
1572
+ msg: 'Serialization error',
1678
1573
  },
1679
1574
  ],
1680
1575
  };
@@ -7058,6 +6953,22 @@ class CompressedTokenProgram {
7058
6953
  .instruction();
7059
6954
  return instruction;
7060
6955
  }
6956
+ static async mergeTokenAccounts(params) {
6957
+ const { payer, owner, inputCompressedTokenAccounts, outputStateTree, recentValidityProof, recentInputStateRootIndices, } = params;
6958
+ if (inputCompressedTokenAccounts.length > 3) {
6959
+ throw new Error('Cannot merge more than 3 token accounts at once');
6960
+ }
6961
+ const ix = await this.transfer({
6962
+ payer,
6963
+ inputCompressedTokenAccounts,
6964
+ toAddress: owner,
6965
+ amount: inputCompressedTokenAccounts.reduce((sum, account) => sum.add(account.parsed.amount), new BN(0)),
6966
+ outputStateTrees: outputStateTree,
6967
+ recentInputStateRootIndices,
6968
+ recentValidityProof,
6969
+ });
6970
+ return [ix];
6971
+ }
7061
6972
  }
7062
6973
 
7063
6974
  /**
@@ -7312,6 +7223,51 @@ async function mintTo(rpc, payer, mint, destination, authority, amount, merkleTr
7312
7223
  return txId;
7313
7224
  }
7314
7225
 
7226
+ /**
7227
+ * Merge multiple compressed token accounts for a given mint into a single
7228
+ * account
7229
+ *
7230
+ * @param rpc RPC to use
7231
+ * @param payer Payer of the transaction fees
7232
+ * @param mint Public key of the token's mint
7233
+ * @param owner Owner of the token accounts to be merged
7234
+ * @param merkleTree Optional merkle tree for compressed tokens
7235
+ * @param confirmOptions Options for confirming the transaction
7236
+ *
7237
+ * @return Array of transaction signatures
7238
+ */
7239
+ async function mergeTokenAccounts(rpc, payer, mint, owner, merkleTree, confirmOptions) {
7240
+ const compressedTokenAccounts = await rpc.getCompressedTokenAccountsByOwner(owner.publicKey, { mint });
7241
+ if (compressedTokenAccounts.items.length === 0) {
7242
+ throw new Error(`No compressed token accounts found for mint ${mint.toBase58()}`);
7243
+ }
7244
+ if (compressedTokenAccounts.items.length >= 6) {
7245
+ throw new Error(`Too many compressed token accounts used for mint ${mint.toBase58()}`);
7246
+ }
7247
+ const instructions = [
7248
+ ComputeBudgetProgram.setComputeUnitLimit({ units: 1_000_000 }),
7249
+ ];
7250
+ for (let i = 0; i < compressedTokenAccounts.items.slice(0, 6).length; i += 3) {
7251
+ const batch = compressedTokenAccounts.items.slice(i, i + 3);
7252
+ const proof = await rpc.getValidityProof(batch.map(account => bn(account.compressedAccount.hash)));
7253
+ const batchInstructions = await CompressedTokenProgram.mergeTokenAccounts({
7254
+ payer: payer.publicKey,
7255
+ owner: owner.publicKey,
7256
+ mint,
7257
+ inputCompressedTokenAccounts: batch,
7258
+ outputStateTree: merkleTree,
7259
+ recentValidityProof: proof.compressedProof,
7260
+ recentInputStateRootIndices: proof.rootIndices,
7261
+ });
7262
+ instructions.push(...batchInstructions);
7263
+ }
7264
+ const { blockhash } = await rpc.getLatestBlockhash();
7265
+ const additionalSigners = dedupeSigner(payer, [owner]);
7266
+ const signedTx = buildAndSignTx(instructions, payer, blockhash, additionalSigners);
7267
+ const txId = await sendAndConfirmTx(rpc, signedTx, confirmOptions);
7268
+ return txId;
7269
+ }
7270
+
7315
7271
  /**
7316
7272
  * Register an existing mint with the CompressedToken program
7317
7273
  *
@@ -7367,5 +7323,5 @@ async function createTokenProgramLookupTable(rpc, payer, authority, mints, addit
7367
7323
  return { txIds: [txId, txId2], address };
7368
7324
  }
7369
7325
 
7370
- export { CPI_AUTHORITY_SEED, CompressedTokenProgram, IDL, POOL_SEED, SPL_TOKEN_MINT_RENT_EXEMPT_BALANCE, approveAndMintTo, compress, createDecompressOutputState, createMint, createTokenPool, createTokenProgramLookupTable, createTransferOutputState, decompress, mintTo, packCompressedTokenAccounts, parseTokenData, selectMinCompressedTokenAccountsForTransfer, sumUpTokenAmount, transfer, validateSameTokenOwner };
7326
+ export { CPI_AUTHORITY_SEED, CompressedTokenProgram, IDL, POOL_SEED, SPL_TOKEN_MINT_RENT_EXEMPT_BALANCE, approveAndMintTo, compress, createDecompressOutputState, createMint, createTokenPool, createTokenProgramLookupTable, createTransferOutputState, decompress, mergeTokenAccounts, mintTo, packCompressedTokenAccounts, parseTokenData, selectMinCompressedTokenAccountsForTransfer, sumUpTokenAmount, transfer, validateSameTokenOwner };
7371
7327
  //# sourceMappingURL=index.js.map