@lightprotocol/compressed-token 0.15.1 → 0.15.3

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.
@@ -164,6 +164,106 @@ const IDL = {
164
164
  },
165
165
  ],
166
166
  },
167
+ {
168
+ name: 'compressSplTokenAccount',
169
+ accounts: [
170
+ {
171
+ name: 'feePayer',
172
+ isMut: true,
173
+ isSigner: true,
174
+ docs: ['UNCHECKED: only pays fees.'],
175
+ },
176
+ {
177
+ name: 'authority',
178
+ isMut: false,
179
+ isSigner: true,
180
+ docs: [
181
+ 'Authority is verified through proof since both owner and delegate',
182
+ 'are included in the token data hash, which is a public input to the',
183
+ 'validity proof.',
184
+ ],
185
+ },
186
+ {
187
+ name: 'cpiAuthorityPda',
188
+ isMut: false,
189
+ isSigner: false,
190
+ },
191
+ {
192
+ name: 'lightSystemProgram',
193
+ isMut: false,
194
+ isSigner: false,
195
+ },
196
+ {
197
+ name: 'registeredProgramPda',
198
+ isMut: false,
199
+ isSigner: false,
200
+ },
201
+ {
202
+ name: 'noopProgram',
203
+ isMut: false,
204
+ isSigner: false,
205
+ },
206
+ {
207
+ name: 'accountCompressionAuthority',
208
+ isMut: false,
209
+ isSigner: false,
210
+ },
211
+ {
212
+ name: 'accountCompressionProgram',
213
+ isMut: false,
214
+ isSigner: false,
215
+ },
216
+ {
217
+ name: 'selfProgram',
218
+ isMut: false,
219
+ isSigner: false,
220
+ docs: ['this program is the signer of the cpi.'],
221
+ },
222
+ {
223
+ name: 'tokenPoolPda',
224
+ isMut: true,
225
+ isSigner: false,
226
+ isOptional: true,
227
+ },
228
+ {
229
+ name: 'compressOrDecompressTokenAccount',
230
+ isMut: true,
231
+ isSigner: false,
232
+ isOptional: true,
233
+ },
234
+ {
235
+ name: 'tokenProgram',
236
+ isMut: false,
237
+ isSigner: false,
238
+ isOptional: true,
239
+ },
240
+ {
241
+ name: 'systemProgram',
242
+ isMut: false,
243
+ isSigner: false,
244
+ },
245
+ ],
246
+ args: [
247
+ {
248
+ name: 'owner',
249
+ type: 'publicKey',
250
+ },
251
+ {
252
+ name: 'remainingAmount',
253
+ type: {
254
+ option: 'u64',
255
+ },
256
+ },
257
+ {
258
+ name: 'cpiContext',
259
+ type: {
260
+ option: {
261
+ defined: 'CompressedCpiContext',
262
+ },
263
+ },
264
+ },
265
+ ],
266
+ },
167
267
  {
168
268
  name: 'transfer',
169
269
  docs: [
@@ -6610,6 +6710,20 @@ class CompressedTokenProgram {
6610
6710
  * Public key that identifies the CompressedPda program
6611
6711
  */
6612
6712
  static programId = new PublicKey('cTokenmWW8bLPjZEBAUgYy3zKxQZW6VKi7bqNFEVv3m');
6713
+ /**
6714
+ * Set a custom programId via PublicKey or base58 encoded string.
6715
+ * This method is not required for regular usage.
6716
+ *
6717
+ * Use this only if you know what you are doing.
6718
+ */
6719
+ static setProgramId(programId) {
6720
+ this.programId =
6721
+ typeof programId === 'string'
6722
+ ? new PublicKey(programId)
6723
+ : programId;
6724
+ // Reset program when programId changes
6725
+ this._program = null;
6726
+ }
6613
6727
  static _program = null;
6614
6728
  /** @internal */
6615
6729
  static get program() {
@@ -6969,6 +7083,36 @@ class CompressedTokenProgram {
6969
7083
  });
6970
7084
  return [ix];
6971
7085
  }
7086
+ static async compressSplTokenAccount(params) {
7087
+ const { feePayer, authority, tokenAccount, mint, remainingAmount, outputStateTree, } = params;
7088
+ const remainingAccountMetas = [
7089
+ {
7090
+ pubkey: outputStateTree,
7091
+ isSigner: false,
7092
+ isWritable: true,
7093
+ },
7094
+ ];
7095
+ const instruction = await this.program.methods
7096
+ .compressSplTokenAccount(authority, remainingAmount ?? null, null)
7097
+ .accounts({
7098
+ feePayer,
7099
+ authority,
7100
+ cpiAuthorityPda: this.deriveCpiAuthorityPda,
7101
+ lightSystemProgram: LightSystemProgram.programId,
7102
+ registeredProgramPda: defaultStaticAccountsStruct().registeredProgramPda,
7103
+ noopProgram: defaultStaticAccountsStruct().noopProgram,
7104
+ accountCompressionAuthority: defaultStaticAccountsStruct().accountCompressionAuthority,
7105
+ accountCompressionProgram: defaultStaticAccountsStruct().accountCompressionProgram,
7106
+ selfProgram: this.programId,
7107
+ tokenPoolPda: this.deriveTokenPoolPda(mint),
7108
+ compressOrDecompressTokenAccount: tokenAccount,
7109
+ tokenProgram: TOKEN_PROGRAM_ID,
7110
+ systemProgram: SystemProgram.programId,
7111
+ })
7112
+ .remainingAccounts(remainingAccountMetas)
7113
+ .instruction();
7114
+ return instruction;
7115
+ }
6972
7116
  }
6973
7117
 
6974
7118
  /**
@@ -7323,5 +7467,40 @@ async function createTokenProgramLookupTable(rpc, payer, authority, mints, addit
7323
7467
  return { txIds: [txId, txId2], address };
7324
7468
  }
7325
7469
 
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 };
7470
+ /**
7471
+ * Compress SPL tokens into compressed token format
7472
+ *
7473
+ * @param rpc Rpc connection to use
7474
+ * @param payer Payer of the transaction fees
7475
+ * @param mint Mint of the token to compress
7476
+ * @param owner Owner of the token account
7477
+ * @param tokenAccount Token account to compress
7478
+ * @param outputStateTree State tree to insert the compressed token account into
7479
+ * @param remainingAmount Optional: amount to leave in token account. Default: 0
7480
+ * @param confirmOptions Options for confirming the transaction
7481
+ *
7482
+ * @return Signature of the confirmed transaction
7483
+ */
7484
+ async function compressSplTokenAccount(rpc, payer, mint, owner, tokenAccount, outputStateTree, remainingAmount, confirmOptions) {
7485
+ const compressIx = await CompressedTokenProgram.compressSplTokenAccount({
7486
+ feePayer: payer.publicKey,
7487
+ authority: owner.publicKey,
7488
+ tokenAccount,
7489
+ mint,
7490
+ remainingAmount,
7491
+ outputStateTree,
7492
+ });
7493
+ const blockhashCtx = await rpc.getLatestBlockhash();
7494
+ const additionalSigners = dedupeSigner(payer, [owner]);
7495
+ const signedTx = buildAndSignTx([
7496
+ ComputeBudgetProgram.setComputeUnitLimit({
7497
+ units: 1_000_000,
7498
+ }),
7499
+ compressIx,
7500
+ ], payer, blockhashCtx.blockhash, additionalSigners);
7501
+ const txId = await sendAndConfirmTx(rpc, signedTx, confirmOptions, blockhashCtx);
7502
+ return txId;
7503
+ }
7504
+
7505
+ export { CPI_AUTHORITY_SEED, CompressedTokenProgram, IDL, POOL_SEED, SPL_TOKEN_MINT_RENT_EXEMPT_BALANCE, approveAndMintTo, compress, compressSplTokenAccount, createDecompressOutputState, createMint, createTokenPool, createTokenProgramLookupTable, createTransferOutputState, decompress, mergeTokenAccounts, mintTo, packCompressedTokenAccounts, parseTokenData, selectMinCompressedTokenAccountsForTransfer, sumUpTokenAmount, transfer, validateSameTokenOwner };
7327
7506
  //# sourceMappingURL=index.js.map