@lightprotocol/compressed-token 0.10.0 → 0.11.0
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 +99 -114
- package/dist/cjs/browser/index.cjs.map +1 -1
- package/dist/cjs/node/index.cjs +99 -114
- package/dist/cjs/node/index.cjs.map +1 -1
- package/dist/es/browser/index.js +100 -116
- package/dist/es/browser/index.js.map +1 -1
- package/dist/types/index.d.ts +62 -110
- package/package.json +5 -5
|
@@ -1561,120 +1561,23 @@ const IDL = {
|
|
|
1561
1561
|
errors: [
|
|
1562
1562
|
{
|
|
1563
1563
|
code: 6000,
|
|
1564
|
-
name: '
|
|
1565
|
-
msg: '
|
|
1564
|
+
name: 'SignerCheckFailed',
|
|
1565
|
+
msg: 'Signer check failed',
|
|
1566
1566
|
},
|
|
1567
1567
|
{
|
|
1568
1568
|
code: 6001,
|
|
1569
|
-
name: '
|
|
1570
|
-
msg: '
|
|
1569
|
+
name: 'CreateTransferInstructionFailed',
|
|
1570
|
+
msg: 'Create transfer instruction failed',
|
|
1571
1571
|
},
|
|
1572
1572
|
{
|
|
1573
1573
|
code: 6002,
|
|
1574
|
-
name: '
|
|
1575
|
-
msg: '
|
|
1574
|
+
name: 'AccountNotFound',
|
|
1575
|
+
msg: 'Account not found',
|
|
1576
1576
|
},
|
|
1577
1577
|
{
|
|
1578
1578
|
code: 6003,
|
|
1579
|
-
name: '
|
|
1580
|
-
msg: '
|
|
1581
|
-
},
|
|
1582
|
-
{
|
|
1583
|
-
code: 6004,
|
|
1584
|
-
name: 'ComputeDecompressSumFailed',
|
|
1585
|
-
msg: 'ComputeDecompressSumFailed',
|
|
1586
|
-
},
|
|
1587
|
-
{
|
|
1588
|
-
code: 6005,
|
|
1589
|
-
name: 'SumCheckFailed',
|
|
1590
|
-
msg: 'SumCheckFailed',
|
|
1591
|
-
},
|
|
1592
|
-
{
|
|
1593
|
-
code: 6006,
|
|
1594
|
-
name: 'DecompressRecipientUndefinedForDecompress',
|
|
1595
|
-
msg: 'DecompressRecipientUndefinedForDecompress',
|
|
1596
|
-
},
|
|
1597
|
-
{
|
|
1598
|
-
code: 6007,
|
|
1599
|
-
name: 'CompressedPdaUndefinedForDecompress',
|
|
1600
|
-
msg: 'CompressedPdaUndefinedForDecompress',
|
|
1601
|
-
},
|
|
1602
|
-
{
|
|
1603
|
-
code: 6008,
|
|
1604
|
-
name: 'DeCompressAmountUndefinedForDecompress',
|
|
1605
|
-
msg: 'DeCompressAmountUndefinedForDecompress',
|
|
1606
|
-
},
|
|
1607
|
-
{
|
|
1608
|
-
code: 6009,
|
|
1609
|
-
name: 'CompressedPdaUndefinedForCompress',
|
|
1610
|
-
msg: 'CompressedPdaUndefinedForCompress',
|
|
1611
|
-
},
|
|
1612
|
-
{
|
|
1613
|
-
code: 6010,
|
|
1614
|
-
name: 'DeCompressAmountUndefinedForCompress',
|
|
1615
|
-
msg: 'DeCompressAmountUndefinedForCompress',
|
|
1616
|
-
},
|
|
1617
|
-
{
|
|
1618
|
-
code: 6011,
|
|
1619
|
-
name: 'DelegateSignerCheckFailed',
|
|
1620
|
-
msg: 'DelegateSignerCheckFailed',
|
|
1621
|
-
},
|
|
1622
|
-
{
|
|
1623
|
-
code: 6012,
|
|
1624
|
-
name: 'MintTooLarge',
|
|
1625
|
-
msg: 'Minted amount greater than u64::MAX',
|
|
1626
|
-
},
|
|
1627
|
-
{
|
|
1628
|
-
code: 6013,
|
|
1629
|
-
name: 'SplTokenSupplyMismatch',
|
|
1630
|
-
msg: 'SplTokenSupplyMismatch',
|
|
1631
|
-
},
|
|
1632
|
-
{
|
|
1633
|
-
code: 6014,
|
|
1634
|
-
name: 'HeapMemoryCheckFailed',
|
|
1635
|
-
msg: 'HeapMemoryCheckFailed',
|
|
1636
|
-
},
|
|
1637
|
-
{
|
|
1638
|
-
code: 6015,
|
|
1639
|
-
name: 'InstructionNotCallable',
|
|
1640
|
-
msg: 'The instruction is not callable',
|
|
1641
|
-
},
|
|
1642
|
-
{
|
|
1643
|
-
code: 6016,
|
|
1644
|
-
name: 'ArithmeticUnderflow',
|
|
1645
|
-
msg: 'ArithmeticUnderflow',
|
|
1646
|
-
},
|
|
1647
|
-
{
|
|
1648
|
-
code: 6017,
|
|
1649
|
-
name: 'HashToFieldError',
|
|
1650
|
-
msg: 'HashToFieldError',
|
|
1651
|
-
},
|
|
1652
|
-
{
|
|
1653
|
-
code: 6018,
|
|
1654
|
-
name: 'InvalidAuthorityMint',
|
|
1655
|
-
msg: 'Expected the authority to be also a mint authority',
|
|
1656
|
-
},
|
|
1657
|
-
{
|
|
1658
|
-
code: 6019,
|
|
1659
|
-
name: 'InvalidFreezeAuthority',
|
|
1660
|
-
msg: 'Provided authority is not the freeze authority',
|
|
1661
|
-
},
|
|
1662
|
-
{
|
|
1663
|
-
code: 6020,
|
|
1664
|
-
name: 'InvalidDelegateIndex',
|
|
1665
|
-
},
|
|
1666
|
-
{
|
|
1667
|
-
code: 6021,
|
|
1668
|
-
name: 'TokenPoolPdaUndefined',
|
|
1669
|
-
},
|
|
1670
|
-
{
|
|
1671
|
-
code: 6022,
|
|
1672
|
-
name: 'IsTokenPoolPda',
|
|
1673
|
-
msg: 'Compress or decompress recipient is the same account as the token pool pda.',
|
|
1674
|
-
},
|
|
1675
|
-
{
|
|
1676
|
-
code: 6023,
|
|
1677
|
-
name: 'InvalidTokenPoolPda',
|
|
1579
|
+
name: 'SerializationError',
|
|
1580
|
+
msg: 'Serialization error',
|
|
1678
1581
|
},
|
|
1679
1582
|
],
|
|
1680
1583
|
};
|
|
@@ -6763,6 +6666,9 @@ class CompressedTokenProgram {
|
|
|
6763
6666
|
const tokenPoolPda = this.deriveTokenPoolPda(mint);
|
|
6764
6667
|
const amounts = stateless_js.toArray(amount).map(amount => stateless_js.bn(amount));
|
|
6765
6668
|
const toPubkeys = stateless_js.toArray(toPubkey);
|
|
6669
|
+
if (amounts.length !== toPubkeys.length) {
|
|
6670
|
+
throw new Error('Amount and toPubkey arrays must have the same length');
|
|
6671
|
+
}
|
|
6766
6672
|
const instruction = await this.program.methods
|
|
6767
6673
|
.mintTo(toPubkeys, amounts, null)
|
|
6768
6674
|
.accounts({
|
|
@@ -6852,7 +6758,51 @@ class CompressedTokenProgram {
|
|
|
6852
6758
|
return instruction;
|
|
6853
6759
|
}
|
|
6854
6760
|
/**
|
|
6855
|
-
*
|
|
6761
|
+
* Create lookup table instructions for the token program's default accounts.
|
|
6762
|
+
*/
|
|
6763
|
+
static async createTokenProgramLookupTable(params) {
|
|
6764
|
+
const { authority, mints, recentSlot, payer, remainingAccounts } = params;
|
|
6765
|
+
const [createInstruction, lookupTableAddress] = web3_js.AddressLookupTableProgram.createLookupTable({
|
|
6766
|
+
authority,
|
|
6767
|
+
payer: authority,
|
|
6768
|
+
recentSlot,
|
|
6769
|
+
});
|
|
6770
|
+
let optionalMintKeys = [];
|
|
6771
|
+
if (mints) {
|
|
6772
|
+
optionalMintKeys = [
|
|
6773
|
+
...mints,
|
|
6774
|
+
...mints.map(mint => this.deriveTokenPoolPda(mint)),
|
|
6775
|
+
];
|
|
6776
|
+
}
|
|
6777
|
+
const extendInstruction = web3_js.AddressLookupTableProgram.extendLookupTable({
|
|
6778
|
+
payer,
|
|
6779
|
+
authority,
|
|
6780
|
+
lookupTable: lookupTableAddress,
|
|
6781
|
+
addresses: [
|
|
6782
|
+
this.deriveCpiAuthorityPda,
|
|
6783
|
+
stateless_js.LightSystemProgram.programId,
|
|
6784
|
+
stateless_js.defaultStaticAccountsStruct().registeredProgramPda,
|
|
6785
|
+
stateless_js.defaultStaticAccountsStruct().noopProgram,
|
|
6786
|
+
stateless_js.defaultStaticAccountsStruct().accountCompressionAuthority,
|
|
6787
|
+
stateless_js.defaultStaticAccountsStruct().accountCompressionProgram,
|
|
6788
|
+
stateless_js.defaultTestStateTreeAccounts().merkleTree,
|
|
6789
|
+
stateless_js.defaultTestStateTreeAccounts().nullifierQueue,
|
|
6790
|
+
stateless_js.defaultTestStateTreeAccounts().addressTree,
|
|
6791
|
+
stateless_js.defaultTestStateTreeAccounts().addressQueue,
|
|
6792
|
+
this.programId,
|
|
6793
|
+
TOKEN_PROGRAM_ID,
|
|
6794
|
+
authority,
|
|
6795
|
+
...optionalMintKeys,
|
|
6796
|
+
...(remainingAccounts !== null && remainingAccounts !== void 0 ? remainingAccounts : []),
|
|
6797
|
+
],
|
|
6798
|
+
});
|
|
6799
|
+
return {
|
|
6800
|
+
instructions: [createInstruction, extendInstruction],
|
|
6801
|
+
address: lookupTableAddress,
|
|
6802
|
+
};
|
|
6803
|
+
}
|
|
6804
|
+
/**
|
|
6805
|
+
* Create compress instruction
|
|
6856
6806
|
* @returns compressInstruction
|
|
6857
6807
|
*/
|
|
6858
6808
|
static async compress(params) {
|
|
@@ -6907,7 +6857,6 @@ class CompressedTokenProgram {
|
|
|
6907
6857
|
lamportsChangeAccountMerkleTreeIndex: null,
|
|
6908
6858
|
};
|
|
6909
6859
|
const encodedData = this.program.coder.types.encode('CompressedTokenInstructionDataTransfer', data);
|
|
6910
|
-
const { accountCompressionAuthority, noopProgram, registeredProgramPda, accountCompressionProgram, } = stateless_js.defaultStaticAccountsStruct();
|
|
6911
6860
|
const instruction = await this.program.methods
|
|
6912
6861
|
.transfer(encodedData)
|
|
6913
6862
|
.accounts({
|
|
@@ -6915,10 +6864,10 @@ class CompressedTokenProgram {
|
|
|
6915
6864
|
authority: owner,
|
|
6916
6865
|
cpiAuthorityPda: this.deriveCpiAuthorityPda,
|
|
6917
6866
|
lightSystemProgram: stateless_js.LightSystemProgram.programId,
|
|
6918
|
-
registeredProgramPda: registeredProgramPda,
|
|
6919
|
-
noopProgram: noopProgram,
|
|
6920
|
-
accountCompressionAuthority: accountCompressionAuthority,
|
|
6921
|
-
accountCompressionProgram: accountCompressionProgram,
|
|
6867
|
+
registeredProgramPda: stateless_js.defaultStaticAccountsStruct().registeredProgramPda,
|
|
6868
|
+
noopProgram: stateless_js.defaultStaticAccountsStruct().noopProgram,
|
|
6869
|
+
accountCompressionAuthority: stateless_js.defaultStaticAccountsStruct().accountCompressionAuthority,
|
|
6870
|
+
accountCompressionProgram: stateless_js.defaultStaticAccountsStruct().accountCompressionProgram,
|
|
6922
6871
|
selfProgram: this.programId,
|
|
6923
6872
|
tokenPoolPda: this.deriveTokenPoolPda(mint),
|
|
6924
6873
|
compressOrDecompressTokenAccount: source, // token
|
|
@@ -6980,7 +6929,7 @@ class CompressedTokenProgram {
|
|
|
6980
6929
|
/**
|
|
6981
6930
|
* Public key that identifies the CompressedPda program
|
|
6982
6931
|
*/
|
|
6983
|
-
CompressedTokenProgram.programId = new web3_js.PublicKey('
|
|
6932
|
+
CompressedTokenProgram.programId = new web3_js.PublicKey('cTokenmWW8bLPjZEBAUgYy3zKxQZW6VKi7bqNFEVv3m');
|
|
6984
6933
|
CompressedTokenProgram._program = null;
|
|
6985
6934
|
|
|
6986
6935
|
/**
|
|
@@ -7208,9 +7157,11 @@ async function createMint(rpc, payer, mintAuthority, decimals, keypair = web3_js
|
|
|
7208
7157
|
* @param rpc Rpc to use
|
|
7209
7158
|
* @param payer Payer of the transaction fees
|
|
7210
7159
|
* @param mint Mint for the account
|
|
7211
|
-
* @param destination Address of the account to mint to
|
|
7160
|
+
* @param destination Address of the account to mint to. Can be an array of
|
|
7161
|
+
* addresses if the amount is an array of amounts.
|
|
7212
7162
|
* @param authority Minting authority
|
|
7213
|
-
* @param amount Amount to mint
|
|
7163
|
+
* @param amount Amount to mint. Can be an array of amounts if the
|
|
7164
|
+
* destination is an array of addresses.
|
|
7214
7165
|
* @param merkleTree State tree account that the compressed tokens should be
|
|
7215
7166
|
* part of. Defaults to the default state tree account.
|
|
7216
7167
|
* @param confirmOptions Options for confirming the transaction
|
|
@@ -7255,6 +7206,39 @@ async function createTokenPool(rpc, payer, mintAddress, confirmOptions) {
|
|
|
7255
7206
|
return txId;
|
|
7256
7207
|
}
|
|
7257
7208
|
|
|
7209
|
+
/**
|
|
7210
|
+
* Create a lookup table for the token program's default accounts
|
|
7211
|
+
*
|
|
7212
|
+
* @param rpc Rpc connection to use
|
|
7213
|
+
* @param payer Payer of the transaction fees
|
|
7214
|
+
* @param authority Authority of the lookup table
|
|
7215
|
+
* @param mints Optional array of mint public keys to include in
|
|
7216
|
+
* the lookup table
|
|
7217
|
+
* @param additionalAccounts Optional array of additional account public keys
|
|
7218
|
+
* to include in the lookup table
|
|
7219
|
+
*
|
|
7220
|
+
* @return Transaction signatures and the address of the created lookup table
|
|
7221
|
+
*/
|
|
7222
|
+
async function createTokenProgramLookupTable(rpc, payer, authority, mints, additionalAccounts) {
|
|
7223
|
+
const recentSlot = await rpc.getSlot('finalized');
|
|
7224
|
+
const { instructions, address } = await CompressedTokenProgram.createTokenProgramLookupTable({
|
|
7225
|
+
payer: payer.publicKey,
|
|
7226
|
+
authority: authority.publicKey,
|
|
7227
|
+
mints,
|
|
7228
|
+
remainingAccounts: additionalAccounts,
|
|
7229
|
+
recentSlot,
|
|
7230
|
+
});
|
|
7231
|
+
const additionalSigners = stateless_js.dedupeSigner(payer, [authority]);
|
|
7232
|
+
const blockhashCtx = await rpc.getLatestBlockhash();
|
|
7233
|
+
const signedTx = stateless_js.buildAndSignTx([instructions[0]], payer, blockhashCtx.blockhash, additionalSigners);
|
|
7234
|
+
/// Must wait for the first instruction to be finalized.
|
|
7235
|
+
const txId = await stateless_js.sendAndConfirmTx(rpc, signedTx, { commitment: 'finalized' }, blockhashCtx);
|
|
7236
|
+
const blockhashCtx2 = await rpc.getLatestBlockhash();
|
|
7237
|
+
const signedTx2 = stateless_js.buildAndSignTx([instructions[1]], payer, blockhashCtx2.blockhash, additionalSigners);
|
|
7238
|
+
const txId2 = await stateless_js.sendAndConfirmTx(rpc, signedTx2, { commitment: 'finalized' }, blockhashCtx2);
|
|
7239
|
+
return { txIds: [txId, txId2], address };
|
|
7240
|
+
}
|
|
7241
|
+
|
|
7258
7242
|
exports.CPI_AUTHORITY_SEED = CPI_AUTHORITY_SEED;
|
|
7259
7243
|
exports.CompressedTokenProgram = CompressedTokenProgram;
|
|
7260
7244
|
exports.IDL = IDL;
|
|
@@ -7265,6 +7249,7 @@ exports.compress = compress;
|
|
|
7265
7249
|
exports.createDecompressOutputState = createDecompressOutputState;
|
|
7266
7250
|
exports.createMint = createMint;
|
|
7267
7251
|
exports.createTokenPool = createTokenPool;
|
|
7252
|
+
exports.createTokenProgramLookupTable = createTokenProgramLookupTable;
|
|
7268
7253
|
exports.createTransferOutputState = createTransferOutputState;
|
|
7269
7254
|
exports.decompress = decompress;
|
|
7270
7255
|
exports.mintTo = mintTo;
|