@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/README.md
CHANGED
|
@@ -1,24 +1,35 @@
|
|
|
1
|
-
|
|
1
|
+
<p align="center">
|
|
2
|
+
<img src="https://github.com/ldiego08/light-protocol/raw/main/assets/logo.svg" width="90" />
|
|
3
|
+
</p>
|
|
2
4
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
+
<h1 align="center">@lightprotocol/compressed-token</h1>
|
|
6
|
+
|
|
7
|
+
<p align="center">
|
|
8
|
+
<b>This is the JavaScript SDK for interacting with the Compressed Token program on Solana.</b>
|
|
9
|
+
</p>
|
|
10
|
+
|
|
11
|
+
<p align="center">
|
|
12
|
+
<a href="https://badge.fury.io/js/@lightprotocol%2Fcompressed-token">
|
|
13
|
+
<img src="https://badge.fury.io/js/@lightprotocol%2Fcompressed-token.svg" alt="package npm version" height="18" />
|
|
14
|
+
</a>
|
|
15
|
+
<img src="https://img.shields.io/npm/l/%40lightprotocol%2Fcompressed-token" alt="package license" height="18">
|
|
16
|
+
<img src="https://img.shields.io/npm/dw/%40lightprotocol%2Fcompressed-token" alt="package weekly downloads" height="18" />
|
|
17
|
+
</p>
|
|
5
18
|
|
|
6
19
|
### Installation
|
|
7
20
|
|
|
8
|
-
**For use in Node.js or
|
|
21
|
+
**For use in Node.js or web**
|
|
9
22
|
|
|
10
23
|
```bash
|
|
11
24
|
npm install --save \
|
|
12
25
|
@lightprotocol/compressed-token \
|
|
13
26
|
@lightprotocol/stateless.js \
|
|
14
|
-
@solana/web3.js \
|
|
15
|
-
@coral-xyz/anchor@0.29
|
|
16
27
|
```
|
|
17
28
|
|
|
18
29
|
### Documentation and examples
|
|
19
30
|
|
|
20
31
|
- [Latest Source code](https://github.com/lightprotocol/lightprotocol/tree/main/js/compressed-token)
|
|
21
|
-
-
|
|
32
|
+
- [Creating and sending compressed tokens](https://www.zkcompression.com/developers/typescript-client#creating-minting-and-transferring-a-compressed-token)
|
|
22
33
|
|
|
23
34
|
### Getting help
|
|
24
35
|
|
|
@@ -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: [
|
|
@@ -6967,6 +7067,54 @@ class CompressedTokenProgram {
|
|
|
6967
7067
|
});
|
|
6968
7068
|
return [ix];
|
|
6969
7069
|
}
|
|
7070
|
+
static async compressSplTokenAccount(params) {
|
|
7071
|
+
const { feePayer, authority, tokenAccount, mint, remainingAmount, outputStateTree, } = params;
|
|
7072
|
+
// const outputData: TokenTransferOutputData[] = [
|
|
7073
|
+
// {
|
|
7074
|
+
// owner: authority,
|
|
7075
|
+
// amount: remainingAmount ?? new BN(0),
|
|
7076
|
+
// lamports: bn(subremainingAmount),
|
|
7077
|
+
// tlv: null,
|
|
7078
|
+
// },
|
|
7079
|
+
// ];
|
|
7080
|
+
// const {
|
|
7081
|
+
// inputTokenDataWithContext,
|
|
7082
|
+
// packedOutputTokenData,
|
|
7083
|
+
// remainingAccountMetas,
|
|
7084
|
+
// } = packCompressedTokenAccounts({
|
|
7085
|
+
// inputCompressedTokenAccounts: [],
|
|
7086
|
+
// outputStateTrees: outputStateTree,
|
|
7087
|
+
// rootIndices: [],
|
|
7088
|
+
// tokenTransferOutputs,
|
|
7089
|
+
// });
|
|
7090
|
+
const remainingAccountMetas = [
|
|
7091
|
+
{
|
|
7092
|
+
pubkey: outputStateTree,
|
|
7093
|
+
isSigner: false,
|
|
7094
|
+
isWritable: true,
|
|
7095
|
+
},
|
|
7096
|
+
];
|
|
7097
|
+
const instruction = await this.program.methods
|
|
7098
|
+
.compressSplTokenAccount(authority, remainingAmount !== null && remainingAmount !== void 0 ? remainingAmount : null, null)
|
|
7099
|
+
.accounts({
|
|
7100
|
+
feePayer,
|
|
7101
|
+
authority,
|
|
7102
|
+
cpiAuthorityPda: this.deriveCpiAuthorityPda,
|
|
7103
|
+
lightSystemProgram: stateless_js.LightSystemProgram.programId,
|
|
7104
|
+
registeredProgramPda: stateless_js.defaultStaticAccountsStruct().registeredProgramPda,
|
|
7105
|
+
noopProgram: stateless_js.defaultStaticAccountsStruct().noopProgram,
|
|
7106
|
+
accountCompressionAuthority: stateless_js.defaultStaticAccountsStruct().accountCompressionAuthority,
|
|
7107
|
+
accountCompressionProgram: stateless_js.defaultStaticAccountsStruct().accountCompressionProgram,
|
|
7108
|
+
selfProgram: this.programId,
|
|
7109
|
+
tokenPoolPda: this.deriveTokenPoolPda(mint),
|
|
7110
|
+
compressOrDecompressTokenAccount: tokenAccount,
|
|
7111
|
+
tokenProgram: TOKEN_PROGRAM_ID,
|
|
7112
|
+
systemProgram: web3_js.SystemProgram.programId,
|
|
7113
|
+
})
|
|
7114
|
+
.remainingAccounts(remainingAccountMetas)
|
|
7115
|
+
.instruction();
|
|
7116
|
+
return instruction;
|
|
7117
|
+
}
|
|
6970
7118
|
}
|
|
6971
7119
|
/**
|
|
6972
7120
|
* Public key that identifies the CompressedPda program
|
|
@@ -7326,6 +7474,41 @@ async function createTokenProgramLookupTable(rpc, payer, authority, mints, addit
|
|
|
7326
7474
|
return { txIds: [txId, txId2], address };
|
|
7327
7475
|
}
|
|
7328
7476
|
|
|
7477
|
+
/**
|
|
7478
|
+
* Compress SPL tokens into compressed token format
|
|
7479
|
+
*
|
|
7480
|
+
* @param rpc Rpc connection to use
|
|
7481
|
+
* @param payer Payer of the transaction fees
|
|
7482
|
+
* @param mint Mint of the token to compress
|
|
7483
|
+
* @param owner Owner of the token account
|
|
7484
|
+
* @param tokenAccount Token account to compress
|
|
7485
|
+
* @param outputStateTree State tree to insert the compressed token account into
|
|
7486
|
+
* @param remainingAmount Optional: amount to leave in token account. Default: 0
|
|
7487
|
+
* @param confirmOptions Options for confirming the transaction
|
|
7488
|
+
*
|
|
7489
|
+
* @return Signature of the confirmed transaction
|
|
7490
|
+
*/
|
|
7491
|
+
async function compressSplTokenAccount(rpc, payer, mint, owner, tokenAccount, outputStateTree, remainingAmount, confirmOptions) {
|
|
7492
|
+
const compressIx = await CompressedTokenProgram.compressSplTokenAccount({
|
|
7493
|
+
feePayer: payer.publicKey,
|
|
7494
|
+
authority: owner.publicKey,
|
|
7495
|
+
tokenAccount,
|
|
7496
|
+
mint,
|
|
7497
|
+
remainingAmount,
|
|
7498
|
+
outputStateTree,
|
|
7499
|
+
});
|
|
7500
|
+
const blockhashCtx = await rpc.getLatestBlockhash();
|
|
7501
|
+
const additionalSigners = stateless_js.dedupeSigner(payer, [owner]);
|
|
7502
|
+
const signedTx = stateless_js.buildAndSignTx([
|
|
7503
|
+
web3_js.ComputeBudgetProgram.setComputeUnitLimit({
|
|
7504
|
+
units: 1000000,
|
|
7505
|
+
}),
|
|
7506
|
+
compressIx,
|
|
7507
|
+
], payer, blockhashCtx.blockhash, additionalSigners);
|
|
7508
|
+
const txId = await stateless_js.sendAndConfirmTx(rpc, signedTx, confirmOptions, blockhashCtx);
|
|
7509
|
+
return txId;
|
|
7510
|
+
}
|
|
7511
|
+
|
|
7329
7512
|
exports.CPI_AUTHORITY_SEED = CPI_AUTHORITY_SEED;
|
|
7330
7513
|
exports.CompressedTokenProgram = CompressedTokenProgram;
|
|
7331
7514
|
exports.IDL = IDL;
|
|
@@ -7333,6 +7516,7 @@ exports.POOL_SEED = POOL_SEED;
|
|
|
7333
7516
|
exports.SPL_TOKEN_MINT_RENT_EXEMPT_BALANCE = SPL_TOKEN_MINT_RENT_EXEMPT_BALANCE;
|
|
7334
7517
|
exports.approveAndMintTo = approveAndMintTo;
|
|
7335
7518
|
exports.compress = compress;
|
|
7519
|
+
exports.compressSplTokenAccount = compressSplTokenAccount;
|
|
7336
7520
|
exports.createDecompressOutputState = createDecompressOutputState;
|
|
7337
7521
|
exports.createMint = createMint;
|
|
7338
7522
|
exports.createTokenPool = createTokenPool;
|