@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.
- package/README.md +0 -1
- package/dist/cjs/browser/index.cjs +180 -0
- package/dist/cjs/browser/index.cjs.map +1 -1
- package/dist/cjs/node/index.cjs +180 -0
- package/dist/cjs/node/index.cjs.map +1 -1
- package/dist/es/browser/index.js +180 -1
- package/dist/es/browser/index.js.map +1 -1
- package/dist/types/index.d.ts +151 -1
- package/package.json +7 -5
package/dist/cjs/node/index.cjs
CHANGED
|
@@ -167,6 +167,106 @@ const IDL = {
|
|
|
167
167
|
},
|
|
168
168
|
],
|
|
169
169
|
},
|
|
170
|
+
{
|
|
171
|
+
name: 'compressSplTokenAccount',
|
|
172
|
+
accounts: [
|
|
173
|
+
{
|
|
174
|
+
name: 'feePayer',
|
|
175
|
+
isMut: true,
|
|
176
|
+
isSigner: true,
|
|
177
|
+
docs: ['UNCHECKED: only pays fees.'],
|
|
178
|
+
},
|
|
179
|
+
{
|
|
180
|
+
name: 'authority',
|
|
181
|
+
isMut: false,
|
|
182
|
+
isSigner: true,
|
|
183
|
+
docs: [
|
|
184
|
+
'Authority is verified through proof since both owner and delegate',
|
|
185
|
+
'are included in the token data hash, which is a public input to the',
|
|
186
|
+
'validity proof.',
|
|
187
|
+
],
|
|
188
|
+
},
|
|
189
|
+
{
|
|
190
|
+
name: 'cpiAuthorityPda',
|
|
191
|
+
isMut: false,
|
|
192
|
+
isSigner: false,
|
|
193
|
+
},
|
|
194
|
+
{
|
|
195
|
+
name: 'lightSystemProgram',
|
|
196
|
+
isMut: false,
|
|
197
|
+
isSigner: false,
|
|
198
|
+
},
|
|
199
|
+
{
|
|
200
|
+
name: 'registeredProgramPda',
|
|
201
|
+
isMut: false,
|
|
202
|
+
isSigner: false,
|
|
203
|
+
},
|
|
204
|
+
{
|
|
205
|
+
name: 'noopProgram',
|
|
206
|
+
isMut: false,
|
|
207
|
+
isSigner: false,
|
|
208
|
+
},
|
|
209
|
+
{
|
|
210
|
+
name: 'accountCompressionAuthority',
|
|
211
|
+
isMut: false,
|
|
212
|
+
isSigner: false,
|
|
213
|
+
},
|
|
214
|
+
{
|
|
215
|
+
name: 'accountCompressionProgram',
|
|
216
|
+
isMut: false,
|
|
217
|
+
isSigner: false,
|
|
218
|
+
},
|
|
219
|
+
{
|
|
220
|
+
name: 'selfProgram',
|
|
221
|
+
isMut: false,
|
|
222
|
+
isSigner: false,
|
|
223
|
+
docs: ['this program is the signer of the cpi.'],
|
|
224
|
+
},
|
|
225
|
+
{
|
|
226
|
+
name: 'tokenPoolPda',
|
|
227
|
+
isMut: true,
|
|
228
|
+
isSigner: false,
|
|
229
|
+
isOptional: true,
|
|
230
|
+
},
|
|
231
|
+
{
|
|
232
|
+
name: 'compressOrDecompressTokenAccount',
|
|
233
|
+
isMut: true,
|
|
234
|
+
isSigner: false,
|
|
235
|
+
isOptional: true,
|
|
236
|
+
},
|
|
237
|
+
{
|
|
238
|
+
name: 'tokenProgram',
|
|
239
|
+
isMut: false,
|
|
240
|
+
isSigner: false,
|
|
241
|
+
isOptional: true,
|
|
242
|
+
},
|
|
243
|
+
{
|
|
244
|
+
name: 'systemProgram',
|
|
245
|
+
isMut: false,
|
|
246
|
+
isSigner: false,
|
|
247
|
+
},
|
|
248
|
+
],
|
|
249
|
+
args: [
|
|
250
|
+
{
|
|
251
|
+
name: 'owner',
|
|
252
|
+
type: 'publicKey',
|
|
253
|
+
},
|
|
254
|
+
{
|
|
255
|
+
name: 'remainingAmount',
|
|
256
|
+
type: {
|
|
257
|
+
option: 'u64',
|
|
258
|
+
},
|
|
259
|
+
},
|
|
260
|
+
{
|
|
261
|
+
name: 'cpiContext',
|
|
262
|
+
type: {
|
|
263
|
+
option: {
|
|
264
|
+
defined: 'CompressedCpiContext',
|
|
265
|
+
},
|
|
266
|
+
},
|
|
267
|
+
},
|
|
268
|
+
],
|
|
269
|
+
},
|
|
170
270
|
{
|
|
171
271
|
name: 'transfer',
|
|
172
272
|
docs: [
|
|
@@ -4586,6 +4686,20 @@ class CompressedTokenProgram {
|
|
|
4586
4686
|
* @internal
|
|
4587
4687
|
*/
|
|
4588
4688
|
constructor() { }
|
|
4689
|
+
/**
|
|
4690
|
+
* Set a custom programId via PublicKey or base58 encoded string.
|
|
4691
|
+
* This method is not required for regular usage.
|
|
4692
|
+
*
|
|
4693
|
+
* Use this only if you know what you are doing.
|
|
4694
|
+
*/
|
|
4695
|
+
static setProgramId(programId) {
|
|
4696
|
+
this.programId =
|
|
4697
|
+
typeof programId === 'string'
|
|
4698
|
+
? new web3_js.PublicKey(programId)
|
|
4699
|
+
: programId;
|
|
4700
|
+
// Reset program when programId changes
|
|
4701
|
+
this._program = null;
|
|
4702
|
+
}
|
|
4589
4703
|
/** @internal */
|
|
4590
4704
|
static get program() {
|
|
4591
4705
|
if (!this._program) {
|
|
@@ -4944,6 +5058,36 @@ class CompressedTokenProgram {
|
|
|
4944
5058
|
});
|
|
4945
5059
|
return [ix];
|
|
4946
5060
|
}
|
|
5061
|
+
static async compressSplTokenAccount(params) {
|
|
5062
|
+
const { feePayer, authority, tokenAccount, mint, remainingAmount, outputStateTree, } = params;
|
|
5063
|
+
const remainingAccountMetas = [
|
|
5064
|
+
{
|
|
5065
|
+
pubkey: outputStateTree,
|
|
5066
|
+
isSigner: false,
|
|
5067
|
+
isWritable: true,
|
|
5068
|
+
},
|
|
5069
|
+
];
|
|
5070
|
+
const instruction = await this.program.methods
|
|
5071
|
+
.compressSplTokenAccount(authority, remainingAmount !== null && remainingAmount !== void 0 ? remainingAmount : null, null)
|
|
5072
|
+
.accounts({
|
|
5073
|
+
feePayer,
|
|
5074
|
+
authority,
|
|
5075
|
+
cpiAuthorityPda: this.deriveCpiAuthorityPda,
|
|
5076
|
+
lightSystemProgram: stateless_js.LightSystemProgram.programId,
|
|
5077
|
+
registeredProgramPda: stateless_js.defaultStaticAccountsStruct().registeredProgramPda,
|
|
5078
|
+
noopProgram: stateless_js.defaultStaticAccountsStruct().noopProgram,
|
|
5079
|
+
accountCompressionAuthority: stateless_js.defaultStaticAccountsStruct().accountCompressionAuthority,
|
|
5080
|
+
accountCompressionProgram: stateless_js.defaultStaticAccountsStruct().accountCompressionProgram,
|
|
5081
|
+
selfProgram: this.programId,
|
|
5082
|
+
tokenPoolPda: this.deriveTokenPoolPda(mint),
|
|
5083
|
+
compressOrDecompressTokenAccount: tokenAccount,
|
|
5084
|
+
tokenProgram: TOKEN_PROGRAM_ID,
|
|
5085
|
+
systemProgram: web3_js.SystemProgram.programId,
|
|
5086
|
+
})
|
|
5087
|
+
.remainingAccounts(remainingAccountMetas)
|
|
5088
|
+
.instruction();
|
|
5089
|
+
return instruction;
|
|
5090
|
+
}
|
|
4947
5091
|
}
|
|
4948
5092
|
/**
|
|
4949
5093
|
* Public key that identifies the CompressedPda program
|
|
@@ -5303,6 +5447,41 @@ async function createTokenProgramLookupTable(rpc, payer, authority, mints, addit
|
|
|
5303
5447
|
return { txIds: [txId, txId2], address };
|
|
5304
5448
|
}
|
|
5305
5449
|
|
|
5450
|
+
/**
|
|
5451
|
+
* Compress SPL tokens into compressed token format
|
|
5452
|
+
*
|
|
5453
|
+
* @param rpc Rpc connection to use
|
|
5454
|
+
* @param payer Payer of the transaction fees
|
|
5455
|
+
* @param mint Mint of the token to compress
|
|
5456
|
+
* @param owner Owner of the token account
|
|
5457
|
+
* @param tokenAccount Token account to compress
|
|
5458
|
+
* @param outputStateTree State tree to insert the compressed token account into
|
|
5459
|
+
* @param remainingAmount Optional: amount to leave in token account. Default: 0
|
|
5460
|
+
* @param confirmOptions Options for confirming the transaction
|
|
5461
|
+
*
|
|
5462
|
+
* @return Signature of the confirmed transaction
|
|
5463
|
+
*/
|
|
5464
|
+
async function compressSplTokenAccount(rpc, payer, mint, owner, tokenAccount, outputStateTree, remainingAmount, confirmOptions) {
|
|
5465
|
+
const compressIx = await CompressedTokenProgram.compressSplTokenAccount({
|
|
5466
|
+
feePayer: payer.publicKey,
|
|
5467
|
+
authority: owner.publicKey,
|
|
5468
|
+
tokenAccount,
|
|
5469
|
+
mint,
|
|
5470
|
+
remainingAmount,
|
|
5471
|
+
outputStateTree,
|
|
5472
|
+
});
|
|
5473
|
+
const blockhashCtx = await rpc.getLatestBlockhash();
|
|
5474
|
+
const additionalSigners = stateless_js.dedupeSigner(payer, [owner]);
|
|
5475
|
+
const signedTx = stateless_js.buildAndSignTx([
|
|
5476
|
+
web3_js.ComputeBudgetProgram.setComputeUnitLimit({
|
|
5477
|
+
units: 1000000,
|
|
5478
|
+
}),
|
|
5479
|
+
compressIx,
|
|
5480
|
+
], payer, blockhashCtx.blockhash, additionalSigners);
|
|
5481
|
+
const txId = await stateless_js.sendAndConfirmTx(rpc, signedTx, confirmOptions, blockhashCtx);
|
|
5482
|
+
return txId;
|
|
5483
|
+
}
|
|
5484
|
+
|
|
5306
5485
|
exports.CPI_AUTHORITY_SEED = CPI_AUTHORITY_SEED;
|
|
5307
5486
|
exports.CompressedTokenProgram = CompressedTokenProgram;
|
|
5308
5487
|
exports.IDL = IDL;
|
|
@@ -5310,6 +5489,7 @@ exports.POOL_SEED = POOL_SEED;
|
|
|
5310
5489
|
exports.SPL_TOKEN_MINT_RENT_EXEMPT_BALANCE = SPL_TOKEN_MINT_RENT_EXEMPT_BALANCE;
|
|
5311
5490
|
exports.approveAndMintTo = approveAndMintTo;
|
|
5312
5491
|
exports.compress = compress;
|
|
5492
|
+
exports.compressSplTokenAccount = compressSplTokenAccount;
|
|
5313
5493
|
exports.createDecompressOutputState = createDecompressOutputState;
|
|
5314
5494
|
exports.createMint = createMint;
|
|
5315
5495
|
exports.createTokenPool = createTokenPool;
|