@lightprotocol/compressed-token 0.10.0 → 0.11.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,5 +1,5 @@
1
1
  import { getIndexOrAdd, bn, padOutputStateMerkleTrees, useWallet, confirmConfig, defaultStaticAccountsStruct, toArray, LightSystemProgram, defaultTestStateTreeAccounts, sumUpLamports, validateSufficientBalance, validateSameOwner, dedupeSigner, buildAndSignTx, sendAndConfirmTx } from '@lightprotocol/stateless.js';
2
- import { PublicKey, SystemProgram, TransactionInstruction, Transaction, sendAndConfirmTransaction, Keypair, Connection, ComputeBudgetProgram } from '@solana/web3.js';
2
+ import { PublicKey, SystemProgram, TransactionInstruction, Transaction, sendAndConfirmTransaction, Keypair, Connection, AddressLookupTableProgram, ComputeBudgetProgram } from '@solana/web3.js';
3
3
  import { AnchorProvider, setProvider, Program, BN } from '@coral-xyz/anchor';
4
4
 
5
5
  const IDL = {
@@ -1559,120 +1559,23 @@ const IDL = {
1559
1559
  errors: [
1560
1560
  {
1561
1561
  code: 6000,
1562
- name: 'PublicKeyAmountMissmatch',
1563
- msg: 'public keys and amounts must be of same length',
1562
+ name: 'SignerCheckFailed',
1563
+ msg: 'Signer check failed',
1564
1564
  },
1565
1565
  {
1566
1566
  code: 6001,
1567
- name: 'ComputeInputSumFailed',
1568
- msg: 'ComputeInputSumFailed',
1567
+ name: 'CreateTransferInstructionFailed',
1568
+ msg: 'Create transfer instruction failed',
1569
1569
  },
1570
1570
  {
1571
1571
  code: 6002,
1572
- name: 'ComputeOutputSumFailed',
1573
- msg: 'ComputeOutputSumFailed',
1572
+ name: 'AccountNotFound',
1573
+ msg: 'Account not found',
1574
1574
  },
1575
1575
  {
1576
1576
  code: 6003,
1577
- name: 'ComputeCompressSumFailed',
1578
- msg: 'ComputeCompressSumFailed',
1579
- },
1580
- {
1581
- code: 6004,
1582
- name: 'ComputeDecompressSumFailed',
1583
- msg: 'ComputeDecompressSumFailed',
1584
- },
1585
- {
1586
- code: 6005,
1587
- name: 'SumCheckFailed',
1588
- msg: 'SumCheckFailed',
1589
- },
1590
- {
1591
- code: 6006,
1592
- name: 'DecompressRecipientUndefinedForDecompress',
1593
- msg: 'DecompressRecipientUndefinedForDecompress',
1594
- },
1595
- {
1596
- code: 6007,
1597
- name: 'CompressedPdaUndefinedForDecompress',
1598
- msg: 'CompressedPdaUndefinedForDecompress',
1599
- },
1600
- {
1601
- code: 6008,
1602
- name: 'DeCompressAmountUndefinedForDecompress',
1603
- msg: 'DeCompressAmountUndefinedForDecompress',
1604
- },
1605
- {
1606
- code: 6009,
1607
- name: 'CompressedPdaUndefinedForCompress',
1608
- msg: 'CompressedPdaUndefinedForCompress',
1609
- },
1610
- {
1611
- code: 6010,
1612
- name: 'DeCompressAmountUndefinedForCompress',
1613
- msg: 'DeCompressAmountUndefinedForCompress',
1614
- },
1615
- {
1616
- code: 6011,
1617
- name: 'DelegateSignerCheckFailed',
1618
- msg: 'DelegateSignerCheckFailed',
1619
- },
1620
- {
1621
- code: 6012,
1622
- name: 'MintTooLarge',
1623
- msg: 'Minted amount greater than u64::MAX',
1624
- },
1625
- {
1626
- code: 6013,
1627
- name: 'SplTokenSupplyMismatch',
1628
- msg: 'SplTokenSupplyMismatch',
1629
- },
1630
- {
1631
- code: 6014,
1632
- name: 'HeapMemoryCheckFailed',
1633
- msg: 'HeapMemoryCheckFailed',
1634
- },
1635
- {
1636
- code: 6015,
1637
- name: 'InstructionNotCallable',
1638
- msg: 'The instruction is not callable',
1639
- },
1640
- {
1641
- code: 6016,
1642
- name: 'ArithmeticUnderflow',
1643
- msg: 'ArithmeticUnderflow',
1644
- },
1645
- {
1646
- code: 6017,
1647
- name: 'HashToFieldError',
1648
- msg: 'HashToFieldError',
1649
- },
1650
- {
1651
- code: 6018,
1652
- name: 'InvalidAuthorityMint',
1653
- msg: 'Expected the authority to be also a mint authority',
1654
- },
1655
- {
1656
- code: 6019,
1657
- name: 'InvalidFreezeAuthority',
1658
- msg: 'Provided authority is not the freeze authority',
1659
- },
1660
- {
1661
- code: 6020,
1662
- name: 'InvalidDelegateIndex',
1663
- },
1664
- {
1665
- code: 6021,
1666
- name: 'TokenPoolPdaUndefined',
1667
- },
1668
- {
1669
- code: 6022,
1670
- name: 'IsTokenPoolPda',
1671
- msg: 'Compress or decompress recipient is the same account as the token pool pda.',
1672
- },
1673
- {
1674
- code: 6023,
1675
- name: 'InvalidTokenPoolPda',
1577
+ name: 'SerializationError',
1578
+ msg: 'Serialization error',
1676
1579
  },
1677
1580
  ],
1678
1581
  };
@@ -6680,7 +6583,7 @@ class CompressedTokenProgram {
6680
6583
  /**
6681
6584
  * Public key that identifies the CompressedPda program
6682
6585
  */
6683
- static programId = new PublicKey('HXVfQ44ATEi9WBKLSCCwM54KokdkzqXci9xCQ7ST9SYN');
6586
+ static programId = new PublicKey('cTokenmWW8bLPjZEBAUgYy3zKxQZW6VKi7bqNFEVv3m');
6684
6587
  static _program = null;
6685
6588
  /** @internal */
6686
6589
  static get program() {
@@ -6765,6 +6668,9 @@ class CompressedTokenProgram {
6765
6668
  const tokenPoolPda = this.deriveTokenPoolPda(mint);
6766
6669
  const amounts = toArray(amount).map(amount => bn(amount));
6767
6670
  const toPubkeys = toArray(toPubkey);
6671
+ if (amounts.length !== toPubkeys.length) {
6672
+ throw new Error('Amount and toPubkey arrays must have the same length');
6673
+ }
6768
6674
  const instruction = await this.program.methods
6769
6675
  .mintTo(toPubkeys, amounts, null)
6770
6676
  .accounts({
@@ -6854,7 +6760,51 @@ class CompressedTokenProgram {
6854
6760
  return instruction;
6855
6761
  }
6856
6762
  /**
6857
- * Construct compress instruction
6763
+ * Create lookup table instructions for the token program's default accounts.
6764
+ */
6765
+ static async createTokenProgramLookupTable(params) {
6766
+ const { authority, mints, recentSlot, payer, remainingAccounts } = params;
6767
+ const [createInstruction, lookupTableAddress] = AddressLookupTableProgram.createLookupTable({
6768
+ authority,
6769
+ payer: authority,
6770
+ recentSlot,
6771
+ });
6772
+ let optionalMintKeys = [];
6773
+ if (mints) {
6774
+ optionalMintKeys = [
6775
+ ...mints,
6776
+ ...mints.map(mint => this.deriveTokenPoolPda(mint)),
6777
+ ];
6778
+ }
6779
+ const extendInstruction = AddressLookupTableProgram.extendLookupTable({
6780
+ payer,
6781
+ authority,
6782
+ lookupTable: lookupTableAddress,
6783
+ addresses: [
6784
+ this.deriveCpiAuthorityPda,
6785
+ LightSystemProgram.programId,
6786
+ defaultStaticAccountsStruct().registeredProgramPda,
6787
+ defaultStaticAccountsStruct().noopProgram,
6788
+ defaultStaticAccountsStruct().accountCompressionAuthority,
6789
+ defaultStaticAccountsStruct().accountCompressionProgram,
6790
+ defaultTestStateTreeAccounts().merkleTree,
6791
+ defaultTestStateTreeAccounts().nullifierQueue,
6792
+ defaultTestStateTreeAccounts().addressTree,
6793
+ defaultTestStateTreeAccounts().addressQueue,
6794
+ this.programId,
6795
+ TOKEN_PROGRAM_ID,
6796
+ authority,
6797
+ ...optionalMintKeys,
6798
+ ...(remainingAccounts ?? []),
6799
+ ],
6800
+ });
6801
+ return {
6802
+ instructions: [createInstruction, extendInstruction],
6803
+ address: lookupTableAddress,
6804
+ };
6805
+ }
6806
+ /**
6807
+ * Create compress instruction
6858
6808
  * @returns compressInstruction
6859
6809
  */
6860
6810
  static async compress(params) {
@@ -6909,7 +6859,6 @@ class CompressedTokenProgram {
6909
6859
  lamportsChangeAccountMerkleTreeIndex: null,
6910
6860
  };
6911
6861
  const encodedData = this.program.coder.types.encode('CompressedTokenInstructionDataTransfer', data);
6912
- const { accountCompressionAuthority, noopProgram, registeredProgramPda, accountCompressionProgram, } = defaultStaticAccountsStruct();
6913
6862
  const instruction = await this.program.methods
6914
6863
  .transfer(encodedData)
6915
6864
  .accounts({
@@ -6917,10 +6866,10 @@ class CompressedTokenProgram {
6917
6866
  authority: owner,
6918
6867
  cpiAuthorityPda: this.deriveCpiAuthorityPda,
6919
6868
  lightSystemProgram: LightSystemProgram.programId,
6920
- registeredProgramPda: registeredProgramPda,
6921
- noopProgram: noopProgram,
6922
- accountCompressionAuthority: accountCompressionAuthority,
6923
- accountCompressionProgram: accountCompressionProgram,
6869
+ registeredProgramPda: defaultStaticAccountsStruct().registeredProgramPda,
6870
+ noopProgram: defaultStaticAccountsStruct().noopProgram,
6871
+ accountCompressionAuthority: defaultStaticAccountsStruct().accountCompressionAuthority,
6872
+ accountCompressionProgram: defaultStaticAccountsStruct().accountCompressionProgram,
6924
6873
  selfProgram: this.programId,
6925
6874
  tokenPoolPda: this.deriveTokenPoolPda(mint),
6926
6875
  compressOrDecompressTokenAccount: source, // token
@@ -7205,9 +7154,11 @@ async function createMint(rpc, payer, mintAuthority, decimals, keypair = Keypair
7205
7154
  * @param rpc Rpc to use
7206
7155
  * @param payer Payer of the transaction fees
7207
7156
  * @param mint Mint for the account
7208
- * @param destination Address of the account to mint to
7157
+ * @param destination Address of the account to mint to. Can be an array of
7158
+ * addresses if the amount is an array of amounts.
7209
7159
  * @param authority Minting authority
7210
- * @param amount Amount to mint
7160
+ * @param amount Amount to mint. Can be an array of amounts if the
7161
+ * destination is an array of addresses.
7211
7162
  * @param merkleTree State tree account that the compressed tokens should be
7212
7163
  * part of. Defaults to the default state tree account.
7213
7164
  * @param confirmOptions Options for confirming the transaction
@@ -7252,5 +7203,38 @@ async function createTokenPool(rpc, payer, mintAddress, confirmOptions) {
7252
7203
  return txId;
7253
7204
  }
7254
7205
 
7255
- export { CPI_AUTHORITY_SEED, CompressedTokenProgram, IDL, POOL_SEED, SPL_TOKEN_MINT_RENT_EXEMPT_BALANCE, approveAndMintTo, compress, createDecompressOutputState, createMint, createTokenPool, createTransferOutputState, decompress, mintTo, packCompressedTokenAccounts, parseTokenData, selectMinCompressedTokenAccountsForTransfer, sumUpTokenAmount, transfer, validateSameTokenOwner };
7206
+ /**
7207
+ * Create a lookup table for the token program's default accounts
7208
+ *
7209
+ * @param rpc Rpc connection to use
7210
+ * @param payer Payer of the transaction fees
7211
+ * @param authority Authority of the lookup table
7212
+ * @param mints Optional array of mint public keys to include in
7213
+ * the lookup table
7214
+ * @param additionalAccounts Optional array of additional account public keys
7215
+ * to include in the lookup table
7216
+ *
7217
+ * @return Transaction signatures and the address of the created lookup table
7218
+ */
7219
+ async function createTokenProgramLookupTable(rpc, payer, authority, mints, additionalAccounts) {
7220
+ const recentSlot = await rpc.getSlot('finalized');
7221
+ const { instructions, address } = await CompressedTokenProgram.createTokenProgramLookupTable({
7222
+ payer: payer.publicKey,
7223
+ authority: authority.publicKey,
7224
+ mints,
7225
+ remainingAccounts: additionalAccounts,
7226
+ recentSlot,
7227
+ });
7228
+ const additionalSigners = dedupeSigner(payer, [authority]);
7229
+ const blockhashCtx = await rpc.getLatestBlockhash();
7230
+ const signedTx = buildAndSignTx([instructions[0]], payer, blockhashCtx.blockhash, additionalSigners);
7231
+ /// Must wait for the first instruction to be finalized.
7232
+ const txId = await sendAndConfirmTx(rpc, signedTx, { commitment: 'finalized' }, blockhashCtx);
7233
+ const blockhashCtx2 = await rpc.getLatestBlockhash();
7234
+ const signedTx2 = buildAndSignTx([instructions[1]], payer, blockhashCtx2.blockhash, additionalSigners);
7235
+ const txId2 = await sendAndConfirmTx(rpc, signedTx2, { commitment: 'finalized' }, blockhashCtx2);
7236
+ return { txIds: [txId, txId2], address };
7237
+ }
7238
+
7239
+ 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 };
7256
7240
  //# sourceMappingURL=index.js.map