@lightprotocol/compressed-token 0.15.0 → 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 +18 -7
- 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 +4 -3
package/dist/es/browser/index.js
CHANGED
|
@@ -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: [
|
|
@@ -6969,6 +7069,54 @@ class CompressedTokenProgram {
|
|
|
6969
7069
|
});
|
|
6970
7070
|
return [ix];
|
|
6971
7071
|
}
|
|
7072
|
+
static async compressSplTokenAccount(params) {
|
|
7073
|
+
const { feePayer, authority, tokenAccount, mint, remainingAmount, outputStateTree, } = params;
|
|
7074
|
+
// const outputData: TokenTransferOutputData[] = [
|
|
7075
|
+
// {
|
|
7076
|
+
// owner: authority,
|
|
7077
|
+
// amount: remainingAmount ?? new BN(0),
|
|
7078
|
+
// lamports: bn(subremainingAmount),
|
|
7079
|
+
// tlv: null,
|
|
7080
|
+
// },
|
|
7081
|
+
// ];
|
|
7082
|
+
// const {
|
|
7083
|
+
// inputTokenDataWithContext,
|
|
7084
|
+
// packedOutputTokenData,
|
|
7085
|
+
// remainingAccountMetas,
|
|
7086
|
+
// } = packCompressedTokenAccounts({
|
|
7087
|
+
// inputCompressedTokenAccounts: [],
|
|
7088
|
+
// outputStateTrees: outputStateTree,
|
|
7089
|
+
// rootIndices: [],
|
|
7090
|
+
// tokenTransferOutputs,
|
|
7091
|
+
// });
|
|
7092
|
+
const remainingAccountMetas = [
|
|
7093
|
+
{
|
|
7094
|
+
pubkey: outputStateTree,
|
|
7095
|
+
isSigner: false,
|
|
7096
|
+
isWritable: true,
|
|
7097
|
+
},
|
|
7098
|
+
];
|
|
7099
|
+
const instruction = await this.program.methods
|
|
7100
|
+
.compressSplTokenAccount(authority, remainingAmount ?? null, null)
|
|
7101
|
+
.accounts({
|
|
7102
|
+
feePayer,
|
|
7103
|
+
authority,
|
|
7104
|
+
cpiAuthorityPda: this.deriveCpiAuthorityPda,
|
|
7105
|
+
lightSystemProgram: LightSystemProgram.programId,
|
|
7106
|
+
registeredProgramPda: defaultStaticAccountsStruct().registeredProgramPda,
|
|
7107
|
+
noopProgram: defaultStaticAccountsStruct().noopProgram,
|
|
7108
|
+
accountCompressionAuthority: defaultStaticAccountsStruct().accountCompressionAuthority,
|
|
7109
|
+
accountCompressionProgram: defaultStaticAccountsStruct().accountCompressionProgram,
|
|
7110
|
+
selfProgram: this.programId,
|
|
7111
|
+
tokenPoolPda: this.deriveTokenPoolPda(mint),
|
|
7112
|
+
compressOrDecompressTokenAccount: tokenAccount,
|
|
7113
|
+
tokenProgram: TOKEN_PROGRAM_ID,
|
|
7114
|
+
systemProgram: SystemProgram.programId,
|
|
7115
|
+
})
|
|
7116
|
+
.remainingAccounts(remainingAccountMetas)
|
|
7117
|
+
.instruction();
|
|
7118
|
+
return instruction;
|
|
7119
|
+
}
|
|
6972
7120
|
}
|
|
6973
7121
|
|
|
6974
7122
|
/**
|
|
@@ -7323,5 +7471,40 @@ async function createTokenProgramLookupTable(rpc, payer, authority, mints, addit
|
|
|
7323
7471
|
return { txIds: [txId, txId2], address };
|
|
7324
7472
|
}
|
|
7325
7473
|
|
|
7326
|
-
|
|
7474
|
+
/**
|
|
7475
|
+
* Compress SPL tokens into compressed token format
|
|
7476
|
+
*
|
|
7477
|
+
* @param rpc Rpc connection to use
|
|
7478
|
+
* @param payer Payer of the transaction fees
|
|
7479
|
+
* @param mint Mint of the token to compress
|
|
7480
|
+
* @param owner Owner of the token account
|
|
7481
|
+
* @param tokenAccount Token account to compress
|
|
7482
|
+
* @param outputStateTree State tree to insert the compressed token account into
|
|
7483
|
+
* @param remainingAmount Optional: amount to leave in token account. Default: 0
|
|
7484
|
+
* @param confirmOptions Options for confirming the transaction
|
|
7485
|
+
*
|
|
7486
|
+
* @return Signature of the confirmed transaction
|
|
7487
|
+
*/
|
|
7488
|
+
async function compressSplTokenAccount(rpc, payer, mint, owner, tokenAccount, outputStateTree, remainingAmount, confirmOptions) {
|
|
7489
|
+
const compressIx = await CompressedTokenProgram.compressSplTokenAccount({
|
|
7490
|
+
feePayer: payer.publicKey,
|
|
7491
|
+
authority: owner.publicKey,
|
|
7492
|
+
tokenAccount,
|
|
7493
|
+
mint,
|
|
7494
|
+
remainingAmount,
|
|
7495
|
+
outputStateTree,
|
|
7496
|
+
});
|
|
7497
|
+
const blockhashCtx = await rpc.getLatestBlockhash();
|
|
7498
|
+
const additionalSigners = dedupeSigner(payer, [owner]);
|
|
7499
|
+
const signedTx = buildAndSignTx([
|
|
7500
|
+
ComputeBudgetProgram.setComputeUnitLimit({
|
|
7501
|
+
units: 1_000_000,
|
|
7502
|
+
}),
|
|
7503
|
+
compressIx,
|
|
7504
|
+
], payer, blockhashCtx.blockhash, additionalSigners);
|
|
7505
|
+
const txId = await sendAndConfirmTx(rpc, signedTx, confirmOptions, blockhashCtx);
|
|
7506
|
+
return txId;
|
|
7507
|
+
}
|
|
7508
|
+
|
|
7509
|
+
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
7510
|
//# sourceMappingURL=index.js.map
|