@lightprotocol/compressed-token 0.10.0 → 0.10.1
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/dist/cjs/browser/index.cjs +90 -8
- package/dist/cjs/browser/index.cjs.map +1 -1
- package/dist/cjs/node/index.cjs +90 -8
- package/dist/cjs/node/index.cjs.map +1 -1
- package/dist/es/browser/index.js +91 -10
- package/dist/es/browser/index.js.map +1 -1
- package/dist/types/index.d.ts +54 -5
- package/package.json +2 -2
|
@@ -6763,6 +6763,9 @@ class CompressedTokenProgram {
|
|
|
6763
6763
|
const tokenPoolPda = this.deriveTokenPoolPda(mint);
|
|
6764
6764
|
const amounts = stateless_js.toArray(amount).map(amount => stateless_js.bn(amount));
|
|
6765
6765
|
const toPubkeys = stateless_js.toArray(toPubkey);
|
|
6766
|
+
if (amounts.length !== toPubkeys.length) {
|
|
6767
|
+
throw new Error('Amount and toPubkey arrays must have the same length');
|
|
6768
|
+
}
|
|
6766
6769
|
const instruction = await this.program.methods
|
|
6767
6770
|
.mintTo(toPubkeys, amounts, null)
|
|
6768
6771
|
.accounts({
|
|
@@ -6852,7 +6855,51 @@ class CompressedTokenProgram {
|
|
|
6852
6855
|
return instruction;
|
|
6853
6856
|
}
|
|
6854
6857
|
/**
|
|
6855
|
-
*
|
|
6858
|
+
* Create lookup table instructions for the token program's default accounts.
|
|
6859
|
+
*/
|
|
6860
|
+
static async createTokenProgramLookupTable(params) {
|
|
6861
|
+
const { authority, mints, recentSlot, payer, remainingAccounts } = params;
|
|
6862
|
+
const [createInstruction, lookupTableAddress] = web3_js.AddressLookupTableProgram.createLookupTable({
|
|
6863
|
+
authority,
|
|
6864
|
+
payer: authority,
|
|
6865
|
+
recentSlot,
|
|
6866
|
+
});
|
|
6867
|
+
let optionalMintKeys = [];
|
|
6868
|
+
if (mints) {
|
|
6869
|
+
optionalMintKeys = [
|
|
6870
|
+
...mints,
|
|
6871
|
+
...mints.map(mint => this.deriveTokenPoolPda(mint)),
|
|
6872
|
+
];
|
|
6873
|
+
}
|
|
6874
|
+
const extendInstruction = web3_js.AddressLookupTableProgram.extendLookupTable({
|
|
6875
|
+
payer,
|
|
6876
|
+
authority,
|
|
6877
|
+
lookupTable: lookupTableAddress,
|
|
6878
|
+
addresses: [
|
|
6879
|
+
this.deriveCpiAuthorityPda,
|
|
6880
|
+
stateless_js.LightSystemProgram.programId,
|
|
6881
|
+
stateless_js.defaultStaticAccountsStruct().registeredProgramPda,
|
|
6882
|
+
stateless_js.defaultStaticAccountsStruct().noopProgram,
|
|
6883
|
+
stateless_js.defaultStaticAccountsStruct().accountCompressionAuthority,
|
|
6884
|
+
stateless_js.defaultStaticAccountsStruct().accountCompressionProgram,
|
|
6885
|
+
stateless_js.defaultTestStateTreeAccounts().merkleTree,
|
|
6886
|
+
stateless_js.defaultTestStateTreeAccounts().nullifierQueue,
|
|
6887
|
+
stateless_js.defaultTestStateTreeAccounts().addressTree,
|
|
6888
|
+
stateless_js.defaultTestStateTreeAccounts().addressQueue,
|
|
6889
|
+
this.programId,
|
|
6890
|
+
TOKEN_PROGRAM_ID,
|
|
6891
|
+
authority,
|
|
6892
|
+
...optionalMintKeys,
|
|
6893
|
+
...(remainingAccounts !== null && remainingAccounts !== void 0 ? remainingAccounts : []),
|
|
6894
|
+
],
|
|
6895
|
+
});
|
|
6896
|
+
return {
|
|
6897
|
+
instructions: [createInstruction, extendInstruction],
|
|
6898
|
+
address: lookupTableAddress,
|
|
6899
|
+
};
|
|
6900
|
+
}
|
|
6901
|
+
/**
|
|
6902
|
+
* Create compress instruction
|
|
6856
6903
|
* @returns compressInstruction
|
|
6857
6904
|
*/
|
|
6858
6905
|
static async compress(params) {
|
|
@@ -6907,7 +6954,6 @@ class CompressedTokenProgram {
|
|
|
6907
6954
|
lamportsChangeAccountMerkleTreeIndex: null,
|
|
6908
6955
|
};
|
|
6909
6956
|
const encodedData = this.program.coder.types.encode('CompressedTokenInstructionDataTransfer', data);
|
|
6910
|
-
const { accountCompressionAuthority, noopProgram, registeredProgramPda, accountCompressionProgram, } = stateless_js.defaultStaticAccountsStruct();
|
|
6911
6957
|
const instruction = await this.program.methods
|
|
6912
6958
|
.transfer(encodedData)
|
|
6913
6959
|
.accounts({
|
|
@@ -6915,10 +6961,10 @@ class CompressedTokenProgram {
|
|
|
6915
6961
|
authority: owner,
|
|
6916
6962
|
cpiAuthorityPda: this.deriveCpiAuthorityPda,
|
|
6917
6963
|
lightSystemProgram: stateless_js.LightSystemProgram.programId,
|
|
6918
|
-
registeredProgramPda: registeredProgramPda,
|
|
6919
|
-
noopProgram: noopProgram,
|
|
6920
|
-
accountCompressionAuthority: accountCompressionAuthority,
|
|
6921
|
-
accountCompressionProgram: accountCompressionProgram,
|
|
6964
|
+
registeredProgramPda: stateless_js.defaultStaticAccountsStruct().registeredProgramPda,
|
|
6965
|
+
noopProgram: stateless_js.defaultStaticAccountsStruct().noopProgram,
|
|
6966
|
+
accountCompressionAuthority: stateless_js.defaultStaticAccountsStruct().accountCompressionAuthority,
|
|
6967
|
+
accountCompressionProgram: stateless_js.defaultStaticAccountsStruct().accountCompressionProgram,
|
|
6922
6968
|
selfProgram: this.programId,
|
|
6923
6969
|
tokenPoolPda: this.deriveTokenPoolPda(mint),
|
|
6924
6970
|
compressOrDecompressTokenAccount: source, // token
|
|
@@ -7208,9 +7254,11 @@ async function createMint(rpc, payer, mintAuthority, decimals, keypair = web3_js
|
|
|
7208
7254
|
* @param rpc Rpc to use
|
|
7209
7255
|
* @param payer Payer of the transaction fees
|
|
7210
7256
|
* @param mint Mint for the account
|
|
7211
|
-
* @param destination Address of the account to mint to
|
|
7257
|
+
* @param destination Address of the account to mint to. Can be an array of
|
|
7258
|
+
* addresses if the amount is an array of amounts.
|
|
7212
7259
|
* @param authority Minting authority
|
|
7213
|
-
* @param amount Amount to mint
|
|
7260
|
+
* @param amount Amount to mint. Can be an array of amounts if the
|
|
7261
|
+
* destination is an array of addresses.
|
|
7214
7262
|
* @param merkleTree State tree account that the compressed tokens should be
|
|
7215
7263
|
* part of. Defaults to the default state tree account.
|
|
7216
7264
|
* @param confirmOptions Options for confirming the transaction
|
|
@@ -7255,6 +7303,39 @@ async function createTokenPool(rpc, payer, mintAddress, confirmOptions) {
|
|
|
7255
7303
|
return txId;
|
|
7256
7304
|
}
|
|
7257
7305
|
|
|
7306
|
+
/**
|
|
7307
|
+
* Create a lookup table for the token program's default accounts
|
|
7308
|
+
*
|
|
7309
|
+
* @param rpc Rpc connection to use
|
|
7310
|
+
* @param payer Payer of the transaction fees
|
|
7311
|
+
* @param authority Authority of the lookup table
|
|
7312
|
+
* @param mints Optional array of mint public keys to include in
|
|
7313
|
+
* the lookup table
|
|
7314
|
+
* @param additionalAccounts Optional array of additional account public keys
|
|
7315
|
+
* to include in the lookup table
|
|
7316
|
+
*
|
|
7317
|
+
* @return Transaction signatures and the address of the created lookup table
|
|
7318
|
+
*/
|
|
7319
|
+
async function createTokenProgramLookupTable(rpc, payer, authority, mints, additionalAccounts) {
|
|
7320
|
+
const recentSlot = await rpc.getSlot('finalized');
|
|
7321
|
+
const { instructions, address } = await CompressedTokenProgram.createTokenProgramLookupTable({
|
|
7322
|
+
payer: payer.publicKey,
|
|
7323
|
+
authority: authority.publicKey,
|
|
7324
|
+
mints,
|
|
7325
|
+
remainingAccounts: additionalAccounts,
|
|
7326
|
+
recentSlot,
|
|
7327
|
+
});
|
|
7328
|
+
const additionalSigners = stateless_js.dedupeSigner(payer, [authority]);
|
|
7329
|
+
const blockhashCtx = await rpc.getLatestBlockhash();
|
|
7330
|
+
const signedTx = stateless_js.buildAndSignTx([instructions[0]], payer, blockhashCtx.blockhash, additionalSigners);
|
|
7331
|
+
/// Must wait for the first instruction to be finalized.
|
|
7332
|
+
const txId = await stateless_js.sendAndConfirmTx(rpc, signedTx, { commitment: 'finalized' }, blockhashCtx);
|
|
7333
|
+
const blockhashCtx2 = await rpc.getLatestBlockhash();
|
|
7334
|
+
const signedTx2 = stateless_js.buildAndSignTx([instructions[1]], payer, blockhashCtx2.blockhash, additionalSigners);
|
|
7335
|
+
const txId2 = await stateless_js.sendAndConfirmTx(rpc, signedTx2, { commitment: 'finalized' }, blockhashCtx2);
|
|
7336
|
+
return { txIds: [txId, txId2], address };
|
|
7337
|
+
}
|
|
7338
|
+
|
|
7258
7339
|
exports.CPI_AUTHORITY_SEED = CPI_AUTHORITY_SEED;
|
|
7259
7340
|
exports.CompressedTokenProgram = CompressedTokenProgram;
|
|
7260
7341
|
exports.IDL = IDL;
|
|
@@ -7265,6 +7346,7 @@ exports.compress = compress;
|
|
|
7265
7346
|
exports.createDecompressOutputState = createDecompressOutputState;
|
|
7266
7347
|
exports.createMint = createMint;
|
|
7267
7348
|
exports.createTokenPool = createTokenPool;
|
|
7349
|
+
exports.createTokenProgramLookupTable = createTokenProgramLookupTable;
|
|
7268
7350
|
exports.createTransferOutputState = createTransferOutputState;
|
|
7269
7351
|
exports.decompress = decompress;
|
|
7270
7352
|
exports.mintTo = mintTo;
|