@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
package/dist/cjs/node/index.cjs
CHANGED
|
@@ -1562,120 +1562,23 @@ const IDL = {
|
|
|
1562
1562
|
errors: [
|
|
1563
1563
|
{
|
|
1564
1564
|
code: 6000,
|
|
1565
|
-
name: '
|
|
1566
|
-
msg: '
|
|
1565
|
+
name: 'SignerCheckFailed',
|
|
1566
|
+
msg: 'Signer check failed',
|
|
1567
1567
|
},
|
|
1568
1568
|
{
|
|
1569
1569
|
code: 6001,
|
|
1570
|
-
name: '
|
|
1571
|
-
msg: '
|
|
1570
|
+
name: 'CreateTransferInstructionFailed',
|
|
1571
|
+
msg: 'Create transfer instruction failed',
|
|
1572
1572
|
},
|
|
1573
1573
|
{
|
|
1574
1574
|
code: 6002,
|
|
1575
|
-
name: '
|
|
1576
|
-
msg: '
|
|
1575
|
+
name: 'AccountNotFound',
|
|
1576
|
+
msg: 'Account not found',
|
|
1577
1577
|
},
|
|
1578
1578
|
{
|
|
1579
1579
|
code: 6003,
|
|
1580
|
-
name: '
|
|
1581
|
-
msg: '
|
|
1582
|
-
},
|
|
1583
|
-
{
|
|
1584
|
-
code: 6004,
|
|
1585
|
-
name: 'ComputeDecompressSumFailed',
|
|
1586
|
-
msg: 'ComputeDecompressSumFailed',
|
|
1587
|
-
},
|
|
1588
|
-
{
|
|
1589
|
-
code: 6005,
|
|
1590
|
-
name: 'SumCheckFailed',
|
|
1591
|
-
msg: 'SumCheckFailed',
|
|
1592
|
-
},
|
|
1593
|
-
{
|
|
1594
|
-
code: 6006,
|
|
1595
|
-
name: 'DecompressRecipientUndefinedForDecompress',
|
|
1596
|
-
msg: 'DecompressRecipientUndefinedForDecompress',
|
|
1597
|
-
},
|
|
1598
|
-
{
|
|
1599
|
-
code: 6007,
|
|
1600
|
-
name: 'CompressedPdaUndefinedForDecompress',
|
|
1601
|
-
msg: 'CompressedPdaUndefinedForDecompress',
|
|
1602
|
-
},
|
|
1603
|
-
{
|
|
1604
|
-
code: 6008,
|
|
1605
|
-
name: 'DeCompressAmountUndefinedForDecompress',
|
|
1606
|
-
msg: 'DeCompressAmountUndefinedForDecompress',
|
|
1607
|
-
},
|
|
1608
|
-
{
|
|
1609
|
-
code: 6009,
|
|
1610
|
-
name: 'CompressedPdaUndefinedForCompress',
|
|
1611
|
-
msg: 'CompressedPdaUndefinedForCompress',
|
|
1612
|
-
},
|
|
1613
|
-
{
|
|
1614
|
-
code: 6010,
|
|
1615
|
-
name: 'DeCompressAmountUndefinedForCompress',
|
|
1616
|
-
msg: 'DeCompressAmountUndefinedForCompress',
|
|
1617
|
-
},
|
|
1618
|
-
{
|
|
1619
|
-
code: 6011,
|
|
1620
|
-
name: 'DelegateSignerCheckFailed',
|
|
1621
|
-
msg: 'DelegateSignerCheckFailed',
|
|
1622
|
-
},
|
|
1623
|
-
{
|
|
1624
|
-
code: 6012,
|
|
1625
|
-
name: 'MintTooLarge',
|
|
1626
|
-
msg: 'Minted amount greater than u64::MAX',
|
|
1627
|
-
},
|
|
1628
|
-
{
|
|
1629
|
-
code: 6013,
|
|
1630
|
-
name: 'SplTokenSupplyMismatch',
|
|
1631
|
-
msg: 'SplTokenSupplyMismatch',
|
|
1632
|
-
},
|
|
1633
|
-
{
|
|
1634
|
-
code: 6014,
|
|
1635
|
-
name: 'HeapMemoryCheckFailed',
|
|
1636
|
-
msg: 'HeapMemoryCheckFailed',
|
|
1637
|
-
},
|
|
1638
|
-
{
|
|
1639
|
-
code: 6015,
|
|
1640
|
-
name: 'InstructionNotCallable',
|
|
1641
|
-
msg: 'The instruction is not callable',
|
|
1642
|
-
},
|
|
1643
|
-
{
|
|
1644
|
-
code: 6016,
|
|
1645
|
-
name: 'ArithmeticUnderflow',
|
|
1646
|
-
msg: 'ArithmeticUnderflow',
|
|
1647
|
-
},
|
|
1648
|
-
{
|
|
1649
|
-
code: 6017,
|
|
1650
|
-
name: 'HashToFieldError',
|
|
1651
|
-
msg: 'HashToFieldError',
|
|
1652
|
-
},
|
|
1653
|
-
{
|
|
1654
|
-
code: 6018,
|
|
1655
|
-
name: 'InvalidAuthorityMint',
|
|
1656
|
-
msg: 'Expected the authority to be also a mint authority',
|
|
1657
|
-
},
|
|
1658
|
-
{
|
|
1659
|
-
code: 6019,
|
|
1660
|
-
name: 'InvalidFreezeAuthority',
|
|
1661
|
-
msg: 'Provided authority is not the freeze authority',
|
|
1662
|
-
},
|
|
1663
|
-
{
|
|
1664
|
-
code: 6020,
|
|
1665
|
-
name: 'InvalidDelegateIndex',
|
|
1666
|
-
},
|
|
1667
|
-
{
|
|
1668
|
-
code: 6021,
|
|
1669
|
-
name: 'TokenPoolPdaUndefined',
|
|
1670
|
-
},
|
|
1671
|
-
{
|
|
1672
|
-
code: 6022,
|
|
1673
|
-
name: 'IsTokenPoolPda',
|
|
1674
|
-
msg: 'Compress or decompress recipient is the same account as the token pool pda.',
|
|
1675
|
-
},
|
|
1676
|
-
{
|
|
1677
|
-
code: 6023,
|
|
1678
|
-
name: 'InvalidTokenPoolPda',
|
|
1580
|
+
name: 'SerializationError',
|
|
1581
|
+
msg: 'Serialization error',
|
|
1679
1582
|
},
|
|
1680
1583
|
],
|
|
1681
1584
|
};
|
|
@@ -4740,6 +4643,9 @@ class CompressedTokenProgram {
|
|
|
4740
4643
|
const tokenPoolPda = this.deriveTokenPoolPda(mint);
|
|
4741
4644
|
const amounts = stateless_js.toArray(amount).map(amount => stateless_js.bn(amount));
|
|
4742
4645
|
const toPubkeys = stateless_js.toArray(toPubkey);
|
|
4646
|
+
if (amounts.length !== toPubkeys.length) {
|
|
4647
|
+
throw new Error('Amount and toPubkey arrays must have the same length');
|
|
4648
|
+
}
|
|
4743
4649
|
const instruction = await this.program.methods
|
|
4744
4650
|
.mintTo(toPubkeys, amounts, null)
|
|
4745
4651
|
.accounts({
|
|
@@ -4829,7 +4735,51 @@ class CompressedTokenProgram {
|
|
|
4829
4735
|
return instruction;
|
|
4830
4736
|
}
|
|
4831
4737
|
/**
|
|
4832
|
-
*
|
|
4738
|
+
* Create lookup table instructions for the token program's default accounts.
|
|
4739
|
+
*/
|
|
4740
|
+
static async createTokenProgramLookupTable(params) {
|
|
4741
|
+
const { authority, mints, recentSlot, payer, remainingAccounts } = params;
|
|
4742
|
+
const [createInstruction, lookupTableAddress] = web3_js.AddressLookupTableProgram.createLookupTable({
|
|
4743
|
+
authority,
|
|
4744
|
+
payer: authority,
|
|
4745
|
+
recentSlot,
|
|
4746
|
+
});
|
|
4747
|
+
let optionalMintKeys = [];
|
|
4748
|
+
if (mints) {
|
|
4749
|
+
optionalMintKeys = [
|
|
4750
|
+
...mints,
|
|
4751
|
+
...mints.map(mint => this.deriveTokenPoolPda(mint)),
|
|
4752
|
+
];
|
|
4753
|
+
}
|
|
4754
|
+
const extendInstruction = web3_js.AddressLookupTableProgram.extendLookupTable({
|
|
4755
|
+
payer,
|
|
4756
|
+
authority,
|
|
4757
|
+
lookupTable: lookupTableAddress,
|
|
4758
|
+
addresses: [
|
|
4759
|
+
this.deriveCpiAuthorityPda,
|
|
4760
|
+
stateless_js.LightSystemProgram.programId,
|
|
4761
|
+
stateless_js.defaultStaticAccountsStruct().registeredProgramPda,
|
|
4762
|
+
stateless_js.defaultStaticAccountsStruct().noopProgram,
|
|
4763
|
+
stateless_js.defaultStaticAccountsStruct().accountCompressionAuthority,
|
|
4764
|
+
stateless_js.defaultStaticAccountsStruct().accountCompressionProgram,
|
|
4765
|
+
stateless_js.defaultTestStateTreeAccounts().merkleTree,
|
|
4766
|
+
stateless_js.defaultTestStateTreeAccounts().nullifierQueue,
|
|
4767
|
+
stateless_js.defaultTestStateTreeAccounts().addressTree,
|
|
4768
|
+
stateless_js.defaultTestStateTreeAccounts().addressQueue,
|
|
4769
|
+
this.programId,
|
|
4770
|
+
TOKEN_PROGRAM_ID,
|
|
4771
|
+
authority,
|
|
4772
|
+
...optionalMintKeys,
|
|
4773
|
+
...(remainingAccounts !== null && remainingAccounts !== void 0 ? remainingAccounts : []),
|
|
4774
|
+
],
|
|
4775
|
+
});
|
|
4776
|
+
return {
|
|
4777
|
+
instructions: [createInstruction, extendInstruction],
|
|
4778
|
+
address: lookupTableAddress,
|
|
4779
|
+
};
|
|
4780
|
+
}
|
|
4781
|
+
/**
|
|
4782
|
+
* Create compress instruction
|
|
4833
4783
|
* @returns compressInstruction
|
|
4834
4784
|
*/
|
|
4835
4785
|
static async compress(params) {
|
|
@@ -4884,7 +4834,6 @@ class CompressedTokenProgram {
|
|
|
4884
4834
|
lamportsChangeAccountMerkleTreeIndex: null,
|
|
4885
4835
|
};
|
|
4886
4836
|
const encodedData = this.program.coder.types.encode('CompressedTokenInstructionDataTransfer', data);
|
|
4887
|
-
const { accountCompressionAuthority, noopProgram, registeredProgramPda, accountCompressionProgram, } = stateless_js.defaultStaticAccountsStruct();
|
|
4888
4837
|
const instruction = await this.program.methods
|
|
4889
4838
|
.transfer(encodedData)
|
|
4890
4839
|
.accounts({
|
|
@@ -4892,10 +4841,10 @@ class CompressedTokenProgram {
|
|
|
4892
4841
|
authority: owner,
|
|
4893
4842
|
cpiAuthorityPda: this.deriveCpiAuthorityPda,
|
|
4894
4843
|
lightSystemProgram: stateless_js.LightSystemProgram.programId,
|
|
4895
|
-
registeredProgramPda: registeredProgramPda,
|
|
4896
|
-
noopProgram: noopProgram,
|
|
4897
|
-
accountCompressionAuthority: accountCompressionAuthority,
|
|
4898
|
-
accountCompressionProgram: accountCompressionProgram,
|
|
4844
|
+
registeredProgramPda: stateless_js.defaultStaticAccountsStruct().registeredProgramPda,
|
|
4845
|
+
noopProgram: stateless_js.defaultStaticAccountsStruct().noopProgram,
|
|
4846
|
+
accountCompressionAuthority: stateless_js.defaultStaticAccountsStruct().accountCompressionAuthority,
|
|
4847
|
+
accountCompressionProgram: stateless_js.defaultStaticAccountsStruct().accountCompressionProgram,
|
|
4899
4848
|
selfProgram: this.programId,
|
|
4900
4849
|
tokenPoolPda: this.deriveTokenPoolPda(mint),
|
|
4901
4850
|
compressOrDecompressTokenAccount: source, // token
|
|
@@ -4957,7 +4906,7 @@ class CompressedTokenProgram {
|
|
|
4957
4906
|
/**
|
|
4958
4907
|
* Public key that identifies the CompressedPda program
|
|
4959
4908
|
*/
|
|
4960
|
-
CompressedTokenProgram.programId = new web3_js.PublicKey('
|
|
4909
|
+
CompressedTokenProgram.programId = new web3_js.PublicKey('cTokenmWW8bLPjZEBAUgYy3zKxQZW6VKi7bqNFEVv3m');
|
|
4961
4910
|
CompressedTokenProgram._program = null;
|
|
4962
4911
|
|
|
4963
4912
|
/**
|
|
@@ -5185,9 +5134,11 @@ async function createMint(rpc, payer, mintAuthority, decimals, keypair = web3_js
|
|
|
5185
5134
|
* @param rpc Rpc to use
|
|
5186
5135
|
* @param payer Payer of the transaction fees
|
|
5187
5136
|
* @param mint Mint for the account
|
|
5188
|
-
* @param destination Address of the account to mint to
|
|
5137
|
+
* @param destination Address of the account to mint to. Can be an array of
|
|
5138
|
+
* addresses if the amount is an array of amounts.
|
|
5189
5139
|
* @param authority Minting authority
|
|
5190
|
-
* @param amount Amount to mint
|
|
5140
|
+
* @param amount Amount to mint. Can be an array of amounts if the
|
|
5141
|
+
* destination is an array of addresses.
|
|
5191
5142
|
* @param merkleTree State tree account that the compressed tokens should be
|
|
5192
5143
|
* part of. Defaults to the default state tree account.
|
|
5193
5144
|
* @param confirmOptions Options for confirming the transaction
|
|
@@ -5232,6 +5183,39 @@ async function createTokenPool(rpc, payer, mintAddress, confirmOptions) {
|
|
|
5232
5183
|
return txId;
|
|
5233
5184
|
}
|
|
5234
5185
|
|
|
5186
|
+
/**
|
|
5187
|
+
* Create a lookup table for the token program's default accounts
|
|
5188
|
+
*
|
|
5189
|
+
* @param rpc Rpc connection to use
|
|
5190
|
+
* @param payer Payer of the transaction fees
|
|
5191
|
+
* @param authority Authority of the lookup table
|
|
5192
|
+
* @param mints Optional array of mint public keys to include in
|
|
5193
|
+
* the lookup table
|
|
5194
|
+
* @param additionalAccounts Optional array of additional account public keys
|
|
5195
|
+
* to include in the lookup table
|
|
5196
|
+
*
|
|
5197
|
+
* @return Transaction signatures and the address of the created lookup table
|
|
5198
|
+
*/
|
|
5199
|
+
async function createTokenProgramLookupTable(rpc, payer, authority, mints, additionalAccounts) {
|
|
5200
|
+
const recentSlot = await rpc.getSlot('finalized');
|
|
5201
|
+
const { instructions, address } = await CompressedTokenProgram.createTokenProgramLookupTable({
|
|
5202
|
+
payer: payer.publicKey,
|
|
5203
|
+
authority: authority.publicKey,
|
|
5204
|
+
mints,
|
|
5205
|
+
remainingAccounts: additionalAccounts,
|
|
5206
|
+
recentSlot,
|
|
5207
|
+
});
|
|
5208
|
+
const additionalSigners = stateless_js.dedupeSigner(payer, [authority]);
|
|
5209
|
+
const blockhashCtx = await rpc.getLatestBlockhash();
|
|
5210
|
+
const signedTx = stateless_js.buildAndSignTx([instructions[0]], payer, blockhashCtx.blockhash, additionalSigners);
|
|
5211
|
+
/// Must wait for the first instruction to be finalized.
|
|
5212
|
+
const txId = await stateless_js.sendAndConfirmTx(rpc, signedTx, { commitment: 'finalized' }, blockhashCtx);
|
|
5213
|
+
const blockhashCtx2 = await rpc.getLatestBlockhash();
|
|
5214
|
+
const signedTx2 = stateless_js.buildAndSignTx([instructions[1]], payer, blockhashCtx2.blockhash, additionalSigners);
|
|
5215
|
+
const txId2 = await stateless_js.sendAndConfirmTx(rpc, signedTx2, { commitment: 'finalized' }, blockhashCtx2);
|
|
5216
|
+
return { txIds: [txId, txId2], address };
|
|
5217
|
+
}
|
|
5218
|
+
|
|
5235
5219
|
exports.CPI_AUTHORITY_SEED = CPI_AUTHORITY_SEED;
|
|
5236
5220
|
exports.CompressedTokenProgram = CompressedTokenProgram;
|
|
5237
5221
|
exports.IDL = IDL;
|
|
@@ -5242,6 +5226,7 @@ exports.compress = compress;
|
|
|
5242
5226
|
exports.createDecompressOutputState = createDecompressOutputState;
|
|
5243
5227
|
exports.createMint = createMint;
|
|
5244
5228
|
exports.createTokenPool = createTokenPool;
|
|
5229
|
+
exports.createTokenProgramLookupTable = createTokenProgramLookupTable;
|
|
5245
5230
|
exports.createTransferOutputState = createTransferOutputState;
|
|
5246
5231
|
exports.decompress = decompress;
|
|
5247
5232
|
exports.mintTo = mintTo;
|