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