@lightprotocol/compressed-token 0.15.1 → 0.15.2
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 +184 -0
- package/dist/cjs/browser/index.cjs.map +1 -1
- package/dist/cjs/node/index.cjs +184 -0
- package/dist/cjs/node/index.cjs.map +1 -1
- package/dist/es/browser/index.js +184 -1
- package/dist/es/browser/index.js.map +1 -1
- package/dist/types/index.d.ts +144 -1
- package/package.json +3 -2
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: [
|
|
@@ -4944,6 +5044,54 @@ class CompressedTokenProgram {
|
|
|
4944
5044
|
});
|
|
4945
5045
|
return [ix];
|
|
4946
5046
|
}
|
|
5047
|
+
static async compressSplTokenAccount(params) {
|
|
5048
|
+
const { feePayer, authority, tokenAccount, mint, remainingAmount, outputStateTree, } = params;
|
|
5049
|
+
// const outputData: TokenTransferOutputData[] = [
|
|
5050
|
+
// {
|
|
5051
|
+
// owner: authority,
|
|
5052
|
+
// amount: remainingAmount ?? new BN(0),
|
|
5053
|
+
// lamports: bn(subremainingAmount),
|
|
5054
|
+
// tlv: null,
|
|
5055
|
+
// },
|
|
5056
|
+
// ];
|
|
5057
|
+
// const {
|
|
5058
|
+
// inputTokenDataWithContext,
|
|
5059
|
+
// packedOutputTokenData,
|
|
5060
|
+
// remainingAccountMetas,
|
|
5061
|
+
// } = packCompressedTokenAccounts({
|
|
5062
|
+
// inputCompressedTokenAccounts: [],
|
|
5063
|
+
// outputStateTrees: outputStateTree,
|
|
5064
|
+
// rootIndices: [],
|
|
5065
|
+
// tokenTransferOutputs,
|
|
5066
|
+
// });
|
|
5067
|
+
const remainingAccountMetas = [
|
|
5068
|
+
{
|
|
5069
|
+
pubkey: outputStateTree,
|
|
5070
|
+
isSigner: false,
|
|
5071
|
+
isWritable: true,
|
|
5072
|
+
},
|
|
5073
|
+
];
|
|
5074
|
+
const instruction = await this.program.methods
|
|
5075
|
+
.compressSplTokenAccount(authority, remainingAmount !== null && remainingAmount !== void 0 ? remainingAmount : null, null)
|
|
5076
|
+
.accounts({
|
|
5077
|
+
feePayer,
|
|
5078
|
+
authority,
|
|
5079
|
+
cpiAuthorityPda: this.deriveCpiAuthorityPda,
|
|
5080
|
+
lightSystemProgram: stateless_js.LightSystemProgram.programId,
|
|
5081
|
+
registeredProgramPda: stateless_js.defaultStaticAccountsStruct().registeredProgramPda,
|
|
5082
|
+
noopProgram: stateless_js.defaultStaticAccountsStruct().noopProgram,
|
|
5083
|
+
accountCompressionAuthority: stateless_js.defaultStaticAccountsStruct().accountCompressionAuthority,
|
|
5084
|
+
accountCompressionProgram: stateless_js.defaultStaticAccountsStruct().accountCompressionProgram,
|
|
5085
|
+
selfProgram: this.programId,
|
|
5086
|
+
tokenPoolPda: this.deriveTokenPoolPda(mint),
|
|
5087
|
+
compressOrDecompressTokenAccount: tokenAccount,
|
|
5088
|
+
tokenProgram: TOKEN_PROGRAM_ID,
|
|
5089
|
+
systemProgram: web3_js.SystemProgram.programId,
|
|
5090
|
+
})
|
|
5091
|
+
.remainingAccounts(remainingAccountMetas)
|
|
5092
|
+
.instruction();
|
|
5093
|
+
return instruction;
|
|
5094
|
+
}
|
|
4947
5095
|
}
|
|
4948
5096
|
/**
|
|
4949
5097
|
* Public key that identifies the CompressedPda program
|
|
@@ -5303,6 +5451,41 @@ async function createTokenProgramLookupTable(rpc, payer, authority, mints, addit
|
|
|
5303
5451
|
return { txIds: [txId, txId2], address };
|
|
5304
5452
|
}
|
|
5305
5453
|
|
|
5454
|
+
/**
|
|
5455
|
+
* Compress SPL tokens into compressed token format
|
|
5456
|
+
*
|
|
5457
|
+
* @param rpc Rpc connection to use
|
|
5458
|
+
* @param payer Payer of the transaction fees
|
|
5459
|
+
* @param mint Mint of the token to compress
|
|
5460
|
+
* @param owner Owner of the token account
|
|
5461
|
+
* @param tokenAccount Token account to compress
|
|
5462
|
+
* @param outputStateTree State tree to insert the compressed token account into
|
|
5463
|
+
* @param remainingAmount Optional: amount to leave in token account. Default: 0
|
|
5464
|
+
* @param confirmOptions Options for confirming the transaction
|
|
5465
|
+
*
|
|
5466
|
+
* @return Signature of the confirmed transaction
|
|
5467
|
+
*/
|
|
5468
|
+
async function compressSplTokenAccount(rpc, payer, mint, owner, tokenAccount, outputStateTree, remainingAmount, confirmOptions) {
|
|
5469
|
+
const compressIx = await CompressedTokenProgram.compressSplTokenAccount({
|
|
5470
|
+
feePayer: payer.publicKey,
|
|
5471
|
+
authority: owner.publicKey,
|
|
5472
|
+
tokenAccount,
|
|
5473
|
+
mint,
|
|
5474
|
+
remainingAmount,
|
|
5475
|
+
outputStateTree,
|
|
5476
|
+
});
|
|
5477
|
+
const blockhashCtx = await rpc.getLatestBlockhash();
|
|
5478
|
+
const additionalSigners = stateless_js.dedupeSigner(payer, [owner]);
|
|
5479
|
+
const signedTx = stateless_js.buildAndSignTx([
|
|
5480
|
+
web3_js.ComputeBudgetProgram.setComputeUnitLimit({
|
|
5481
|
+
units: 1000000,
|
|
5482
|
+
}),
|
|
5483
|
+
compressIx,
|
|
5484
|
+
], payer, blockhashCtx.blockhash, additionalSigners);
|
|
5485
|
+
const txId = await stateless_js.sendAndConfirmTx(rpc, signedTx, confirmOptions, blockhashCtx);
|
|
5486
|
+
return txId;
|
|
5487
|
+
}
|
|
5488
|
+
|
|
5306
5489
|
exports.CPI_AUTHORITY_SEED = CPI_AUTHORITY_SEED;
|
|
5307
5490
|
exports.CompressedTokenProgram = CompressedTokenProgram;
|
|
5308
5491
|
exports.IDL = IDL;
|
|
@@ -5310,6 +5493,7 @@ exports.POOL_SEED = POOL_SEED;
|
|
|
5310
5493
|
exports.SPL_TOKEN_MINT_RENT_EXEMPT_BALANCE = SPL_TOKEN_MINT_RENT_EXEMPT_BALANCE;
|
|
5311
5494
|
exports.approveAndMintTo = approveAndMintTo;
|
|
5312
5495
|
exports.compress = compress;
|
|
5496
|
+
exports.compressSplTokenAccount = compressSplTokenAccount;
|
|
5313
5497
|
exports.createDecompressOutputState = createDecompressOutputState;
|
|
5314
5498
|
exports.createMint = createMint;
|
|
5315
5499
|
exports.createTokenPool = createTokenPool;
|