@lightprotocol/compressed-token 0.9.0 → 0.10.1

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.
@@ -4740,6 +4740,9 @@ class CompressedTokenProgram {
4740
4740
  const tokenPoolPda = this.deriveTokenPoolPda(mint);
4741
4741
  const amounts = stateless_js.toArray(amount).map(amount => stateless_js.bn(amount));
4742
4742
  const toPubkeys = stateless_js.toArray(toPubkey);
4743
+ if (amounts.length !== toPubkeys.length) {
4744
+ throw new Error('Amount and toPubkey arrays must have the same length');
4745
+ }
4743
4746
  const instruction = await this.program.methods
4744
4747
  .mintTo(toPubkeys, amounts, null)
4745
4748
  .accounts({
@@ -4829,7 +4832,51 @@ class CompressedTokenProgram {
4829
4832
  return instruction;
4830
4833
  }
4831
4834
  /**
4832
- * Construct compress instruction
4835
+ * Create lookup table instructions for the token program's default accounts.
4836
+ */
4837
+ static async createTokenProgramLookupTable(params) {
4838
+ const { authority, mints, recentSlot, payer, remainingAccounts } = params;
4839
+ const [createInstruction, lookupTableAddress] = web3_js.AddressLookupTableProgram.createLookupTable({
4840
+ authority,
4841
+ payer: authority,
4842
+ recentSlot,
4843
+ });
4844
+ let optionalMintKeys = [];
4845
+ if (mints) {
4846
+ optionalMintKeys = [
4847
+ ...mints,
4848
+ ...mints.map(mint => this.deriveTokenPoolPda(mint)),
4849
+ ];
4850
+ }
4851
+ const extendInstruction = web3_js.AddressLookupTableProgram.extendLookupTable({
4852
+ payer,
4853
+ authority,
4854
+ lookupTable: lookupTableAddress,
4855
+ addresses: [
4856
+ this.deriveCpiAuthorityPda,
4857
+ stateless_js.LightSystemProgram.programId,
4858
+ stateless_js.defaultStaticAccountsStruct().registeredProgramPda,
4859
+ stateless_js.defaultStaticAccountsStruct().noopProgram,
4860
+ stateless_js.defaultStaticAccountsStruct().accountCompressionAuthority,
4861
+ stateless_js.defaultStaticAccountsStruct().accountCompressionProgram,
4862
+ stateless_js.defaultTestStateTreeAccounts().merkleTree,
4863
+ stateless_js.defaultTestStateTreeAccounts().nullifierQueue,
4864
+ stateless_js.defaultTestStateTreeAccounts().addressTree,
4865
+ stateless_js.defaultTestStateTreeAccounts().addressQueue,
4866
+ this.programId,
4867
+ TOKEN_PROGRAM_ID,
4868
+ authority,
4869
+ ...optionalMintKeys,
4870
+ ...(remainingAccounts !== null && remainingAccounts !== void 0 ? remainingAccounts : []),
4871
+ ],
4872
+ });
4873
+ return {
4874
+ instructions: [createInstruction, extendInstruction],
4875
+ address: lookupTableAddress,
4876
+ };
4877
+ }
4878
+ /**
4879
+ * Create compress instruction
4833
4880
  * @returns compressInstruction
4834
4881
  */
4835
4882
  static async compress(params) {
@@ -4884,7 +4931,6 @@ class CompressedTokenProgram {
4884
4931
  lamportsChangeAccountMerkleTreeIndex: null,
4885
4932
  };
4886
4933
  const encodedData = this.program.coder.types.encode('CompressedTokenInstructionDataTransfer', data);
4887
- const { accountCompressionAuthority, noopProgram, registeredProgramPda, accountCompressionProgram, } = stateless_js.defaultStaticAccountsStruct();
4888
4934
  const instruction = await this.program.methods
4889
4935
  .transfer(encodedData)
4890
4936
  .accounts({
@@ -4892,10 +4938,10 @@ class CompressedTokenProgram {
4892
4938
  authority: owner,
4893
4939
  cpiAuthorityPda: this.deriveCpiAuthorityPda,
4894
4940
  lightSystemProgram: stateless_js.LightSystemProgram.programId,
4895
- registeredProgramPda: registeredProgramPda,
4896
- noopProgram: noopProgram,
4897
- accountCompressionAuthority: accountCompressionAuthority,
4898
- accountCompressionProgram: accountCompressionProgram,
4941
+ registeredProgramPda: stateless_js.defaultStaticAccountsStruct().registeredProgramPda,
4942
+ noopProgram: stateless_js.defaultStaticAccountsStruct().noopProgram,
4943
+ accountCompressionAuthority: stateless_js.defaultStaticAccountsStruct().accountCompressionAuthority,
4944
+ accountCompressionProgram: stateless_js.defaultStaticAccountsStruct().accountCompressionProgram,
4899
4945
  selfProgram: this.programId,
4900
4946
  tokenPoolPda: this.deriveTokenPoolPda(mint),
4901
4947
  compressOrDecompressTokenAccount: source, // token
@@ -5185,9 +5231,11 @@ async function createMint(rpc, payer, mintAuthority, decimals, keypair = web3_js
5185
5231
  * @param rpc Rpc to use
5186
5232
  * @param payer Payer of the transaction fees
5187
5233
  * @param mint Mint for the account
5188
- * @param destination Address of the account to mint to
5234
+ * @param destination Address of the account to mint to. Can be an array of
5235
+ * addresses if the amount is an array of amounts.
5189
5236
  * @param authority Minting authority
5190
- * @param amount Amount to mint
5237
+ * @param amount Amount to mint. Can be an array of amounts if the
5238
+ * destination is an array of addresses.
5191
5239
  * @param merkleTree State tree account that the compressed tokens should be
5192
5240
  * part of. Defaults to the default state tree account.
5193
5241
  * @param confirmOptions Options for confirming the transaction
@@ -5232,6 +5280,39 @@ async function createTokenPool(rpc, payer, mintAddress, confirmOptions) {
5232
5280
  return txId;
5233
5281
  }
5234
5282
 
5283
+ /**
5284
+ * Create a lookup table for the token program's default accounts
5285
+ *
5286
+ * @param rpc Rpc connection to use
5287
+ * @param payer Payer of the transaction fees
5288
+ * @param authority Authority of the lookup table
5289
+ * @param mints Optional array of mint public keys to include in
5290
+ * the lookup table
5291
+ * @param additionalAccounts Optional array of additional account public keys
5292
+ * to include in the lookup table
5293
+ *
5294
+ * @return Transaction signatures and the address of the created lookup table
5295
+ */
5296
+ async function createTokenProgramLookupTable(rpc, payer, authority, mints, additionalAccounts) {
5297
+ const recentSlot = await rpc.getSlot('finalized');
5298
+ const { instructions, address } = await CompressedTokenProgram.createTokenProgramLookupTable({
5299
+ payer: payer.publicKey,
5300
+ authority: authority.publicKey,
5301
+ mints,
5302
+ remainingAccounts: additionalAccounts,
5303
+ recentSlot,
5304
+ });
5305
+ const additionalSigners = stateless_js.dedupeSigner(payer, [authority]);
5306
+ const blockhashCtx = await rpc.getLatestBlockhash();
5307
+ const signedTx = stateless_js.buildAndSignTx([instructions[0]], payer, blockhashCtx.blockhash, additionalSigners);
5308
+ /// Must wait for the first instruction to be finalized.
5309
+ const txId = await stateless_js.sendAndConfirmTx(rpc, signedTx, { commitment: 'finalized' }, blockhashCtx);
5310
+ const blockhashCtx2 = await rpc.getLatestBlockhash();
5311
+ const signedTx2 = stateless_js.buildAndSignTx([instructions[1]], payer, blockhashCtx2.blockhash, additionalSigners);
5312
+ const txId2 = await stateless_js.sendAndConfirmTx(rpc, signedTx2, { commitment: 'finalized' }, blockhashCtx2);
5313
+ return { txIds: [txId, txId2], address };
5314
+ }
5315
+
5235
5316
  exports.CPI_AUTHORITY_SEED = CPI_AUTHORITY_SEED;
5236
5317
  exports.CompressedTokenProgram = CompressedTokenProgram;
5237
5318
  exports.IDL = IDL;
@@ -5242,6 +5323,7 @@ exports.compress = compress;
5242
5323
  exports.createDecompressOutputState = createDecompressOutputState;
5243
5324
  exports.createMint = createMint;
5244
5325
  exports.createTokenPool = createTokenPool;
5326
+ exports.createTokenProgramLookupTable = createTokenProgramLookupTable;
5245
5327
  exports.createTransferOutputState = createTransferOutputState;
5246
5328
  exports.decompress = decompress;
5247
5329
  exports.mintTo = mintTo;