@lightprotocol/compressed-token 0.9.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 +4 -4
package/dist/es/browser/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { getIndexOrAdd, bn, padOutputStateMerkleTrees, useWallet, confirmConfig, defaultStaticAccountsStruct, toArray, LightSystemProgram, defaultTestStateTreeAccounts, sumUpLamports, validateSufficientBalance, validateSameOwner, dedupeSigner, buildAndSignTx, sendAndConfirmTx } from '@lightprotocol/stateless.js';
|
|
2
|
-
import { PublicKey, SystemProgram, TransactionInstruction, Transaction, sendAndConfirmTransaction, Keypair, Connection, ComputeBudgetProgram } from '@solana/web3.js';
|
|
2
|
+
import { PublicKey, SystemProgram, TransactionInstruction, Transaction, sendAndConfirmTransaction, Keypair, Connection, AddressLookupTableProgram, ComputeBudgetProgram } from '@solana/web3.js';
|
|
3
3
|
import { AnchorProvider, setProvider, Program, BN } from '@coral-xyz/anchor';
|
|
4
4
|
|
|
5
5
|
const IDL = {
|
|
@@ -6765,6 +6765,9 @@ class CompressedTokenProgram {
|
|
|
6765
6765
|
const tokenPoolPda = this.deriveTokenPoolPda(mint);
|
|
6766
6766
|
const amounts = toArray(amount).map(amount => bn(amount));
|
|
6767
6767
|
const toPubkeys = toArray(toPubkey);
|
|
6768
|
+
if (amounts.length !== toPubkeys.length) {
|
|
6769
|
+
throw new Error('Amount and toPubkey arrays must have the same length');
|
|
6770
|
+
}
|
|
6768
6771
|
const instruction = await this.program.methods
|
|
6769
6772
|
.mintTo(toPubkeys, amounts, null)
|
|
6770
6773
|
.accounts({
|
|
@@ -6854,7 +6857,51 @@ class CompressedTokenProgram {
|
|
|
6854
6857
|
return instruction;
|
|
6855
6858
|
}
|
|
6856
6859
|
/**
|
|
6857
|
-
*
|
|
6860
|
+
* Create lookup table instructions for the token program's default accounts.
|
|
6861
|
+
*/
|
|
6862
|
+
static async createTokenProgramLookupTable(params) {
|
|
6863
|
+
const { authority, mints, recentSlot, payer, remainingAccounts } = params;
|
|
6864
|
+
const [createInstruction, lookupTableAddress] = AddressLookupTableProgram.createLookupTable({
|
|
6865
|
+
authority,
|
|
6866
|
+
payer: authority,
|
|
6867
|
+
recentSlot,
|
|
6868
|
+
});
|
|
6869
|
+
let optionalMintKeys = [];
|
|
6870
|
+
if (mints) {
|
|
6871
|
+
optionalMintKeys = [
|
|
6872
|
+
...mints,
|
|
6873
|
+
...mints.map(mint => this.deriveTokenPoolPda(mint)),
|
|
6874
|
+
];
|
|
6875
|
+
}
|
|
6876
|
+
const extendInstruction = AddressLookupTableProgram.extendLookupTable({
|
|
6877
|
+
payer,
|
|
6878
|
+
authority,
|
|
6879
|
+
lookupTable: lookupTableAddress,
|
|
6880
|
+
addresses: [
|
|
6881
|
+
this.deriveCpiAuthorityPda,
|
|
6882
|
+
LightSystemProgram.programId,
|
|
6883
|
+
defaultStaticAccountsStruct().registeredProgramPda,
|
|
6884
|
+
defaultStaticAccountsStruct().noopProgram,
|
|
6885
|
+
defaultStaticAccountsStruct().accountCompressionAuthority,
|
|
6886
|
+
defaultStaticAccountsStruct().accountCompressionProgram,
|
|
6887
|
+
defaultTestStateTreeAccounts().merkleTree,
|
|
6888
|
+
defaultTestStateTreeAccounts().nullifierQueue,
|
|
6889
|
+
defaultTestStateTreeAccounts().addressTree,
|
|
6890
|
+
defaultTestStateTreeAccounts().addressQueue,
|
|
6891
|
+
this.programId,
|
|
6892
|
+
TOKEN_PROGRAM_ID,
|
|
6893
|
+
authority,
|
|
6894
|
+
...optionalMintKeys,
|
|
6895
|
+
...(remainingAccounts ?? []),
|
|
6896
|
+
],
|
|
6897
|
+
});
|
|
6898
|
+
return {
|
|
6899
|
+
instructions: [createInstruction, extendInstruction],
|
|
6900
|
+
address: lookupTableAddress,
|
|
6901
|
+
};
|
|
6902
|
+
}
|
|
6903
|
+
/**
|
|
6904
|
+
* Create compress instruction
|
|
6858
6905
|
* @returns compressInstruction
|
|
6859
6906
|
*/
|
|
6860
6907
|
static async compress(params) {
|
|
@@ -6909,7 +6956,6 @@ class CompressedTokenProgram {
|
|
|
6909
6956
|
lamportsChangeAccountMerkleTreeIndex: null,
|
|
6910
6957
|
};
|
|
6911
6958
|
const encodedData = this.program.coder.types.encode('CompressedTokenInstructionDataTransfer', data);
|
|
6912
|
-
const { accountCompressionAuthority, noopProgram, registeredProgramPda, accountCompressionProgram, } = defaultStaticAccountsStruct();
|
|
6913
6959
|
const instruction = await this.program.methods
|
|
6914
6960
|
.transfer(encodedData)
|
|
6915
6961
|
.accounts({
|
|
@@ -6917,10 +6963,10 @@ class CompressedTokenProgram {
|
|
|
6917
6963
|
authority: owner,
|
|
6918
6964
|
cpiAuthorityPda: this.deriveCpiAuthorityPda,
|
|
6919
6965
|
lightSystemProgram: LightSystemProgram.programId,
|
|
6920
|
-
registeredProgramPda: registeredProgramPda,
|
|
6921
|
-
noopProgram: noopProgram,
|
|
6922
|
-
accountCompressionAuthority: accountCompressionAuthority,
|
|
6923
|
-
accountCompressionProgram: accountCompressionProgram,
|
|
6966
|
+
registeredProgramPda: defaultStaticAccountsStruct().registeredProgramPda,
|
|
6967
|
+
noopProgram: defaultStaticAccountsStruct().noopProgram,
|
|
6968
|
+
accountCompressionAuthority: defaultStaticAccountsStruct().accountCompressionAuthority,
|
|
6969
|
+
accountCompressionProgram: defaultStaticAccountsStruct().accountCompressionProgram,
|
|
6924
6970
|
selfProgram: this.programId,
|
|
6925
6971
|
tokenPoolPda: this.deriveTokenPoolPda(mint),
|
|
6926
6972
|
compressOrDecompressTokenAccount: source, // token
|
|
@@ -7205,9 +7251,11 @@ async function createMint(rpc, payer, mintAuthority, decimals, keypair = Keypair
|
|
|
7205
7251
|
* @param rpc Rpc to use
|
|
7206
7252
|
* @param payer Payer of the transaction fees
|
|
7207
7253
|
* @param mint Mint for the account
|
|
7208
|
-
* @param destination Address of the account to mint to
|
|
7254
|
+
* @param destination Address of the account to mint to. Can be an array of
|
|
7255
|
+
* addresses if the amount is an array of amounts.
|
|
7209
7256
|
* @param authority Minting authority
|
|
7210
|
-
* @param amount Amount to mint
|
|
7257
|
+
* @param amount Amount to mint. Can be an array of amounts if the
|
|
7258
|
+
* destination is an array of addresses.
|
|
7211
7259
|
* @param merkleTree State tree account that the compressed tokens should be
|
|
7212
7260
|
* part of. Defaults to the default state tree account.
|
|
7213
7261
|
* @param confirmOptions Options for confirming the transaction
|
|
@@ -7252,5 +7300,38 @@ async function createTokenPool(rpc, payer, mintAddress, confirmOptions) {
|
|
|
7252
7300
|
return txId;
|
|
7253
7301
|
}
|
|
7254
7302
|
|
|
7255
|
-
|
|
7303
|
+
/**
|
|
7304
|
+
* Create a lookup table for the token program's default accounts
|
|
7305
|
+
*
|
|
7306
|
+
* @param rpc Rpc connection to use
|
|
7307
|
+
* @param payer Payer of the transaction fees
|
|
7308
|
+
* @param authority Authority of the lookup table
|
|
7309
|
+
* @param mints Optional array of mint public keys to include in
|
|
7310
|
+
* the lookup table
|
|
7311
|
+
* @param additionalAccounts Optional array of additional account public keys
|
|
7312
|
+
* to include in the lookup table
|
|
7313
|
+
*
|
|
7314
|
+
* @return Transaction signatures and the address of the created lookup table
|
|
7315
|
+
*/
|
|
7316
|
+
async function createTokenProgramLookupTable(rpc, payer, authority, mints, additionalAccounts) {
|
|
7317
|
+
const recentSlot = await rpc.getSlot('finalized');
|
|
7318
|
+
const { instructions, address } = await CompressedTokenProgram.createTokenProgramLookupTable({
|
|
7319
|
+
payer: payer.publicKey,
|
|
7320
|
+
authority: authority.publicKey,
|
|
7321
|
+
mints,
|
|
7322
|
+
remainingAccounts: additionalAccounts,
|
|
7323
|
+
recentSlot,
|
|
7324
|
+
});
|
|
7325
|
+
const additionalSigners = dedupeSigner(payer, [authority]);
|
|
7326
|
+
const blockhashCtx = await rpc.getLatestBlockhash();
|
|
7327
|
+
const signedTx = buildAndSignTx([instructions[0]], payer, blockhashCtx.blockhash, additionalSigners);
|
|
7328
|
+
/// Must wait for the first instruction to be finalized.
|
|
7329
|
+
const txId = await sendAndConfirmTx(rpc, signedTx, { commitment: 'finalized' }, blockhashCtx);
|
|
7330
|
+
const blockhashCtx2 = await rpc.getLatestBlockhash();
|
|
7331
|
+
const signedTx2 = buildAndSignTx([instructions[1]], payer, blockhashCtx2.blockhash, additionalSigners);
|
|
7332
|
+
const txId2 = await sendAndConfirmTx(rpc, signedTx2, { commitment: 'finalized' }, blockhashCtx2);
|
|
7333
|
+
return { txIds: [txId, txId2], address };
|
|
7334
|
+
}
|
|
7335
|
+
|
|
7336
|
+
export { CPI_AUTHORITY_SEED, CompressedTokenProgram, IDL, POOL_SEED, SPL_TOKEN_MINT_RENT_EXEMPT_BALANCE, approveAndMintTo, compress, createDecompressOutputState, createMint, createTokenPool, createTokenProgramLookupTable, createTransferOutputState, decompress, mintTo, packCompressedTokenAccounts, parseTokenData, selectMinCompressedTokenAccountsForTransfer, sumUpTokenAmount, transfer, validateSameTokenOwner };
|
|
7256
7337
|
//# sourceMappingURL=index.js.map
|