@lightprotocol/compressed-token 0.12.0 → 0.14.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 +71 -114
- package/dist/cjs/browser/index.cjs.map +1 -1
- package/dist/cjs/node/index.cjs +71 -114
- package/dist/cjs/node/index.cjs.map +1 -1
- package/dist/es/browser/index.js +71 -115
- package/dist/es/browser/index.js.map +1 -1
- package/dist/types/index.d.ts +59 -115
- package/package.json +5 -4
package/dist/cjs/node/index.cjs
CHANGED
|
@@ -6,7 +6,7 @@ var anchor = require('@coral-xyz/anchor');
|
|
|
6
6
|
var require$$0 = require('buffer');
|
|
7
7
|
|
|
8
8
|
const IDL = {
|
|
9
|
-
version: '1.
|
|
9
|
+
version: '1.2.0',
|
|
10
10
|
name: 'light_compressed_token',
|
|
11
11
|
instructions: [
|
|
12
12
|
{
|
|
@@ -1556,128 +1556,23 @@ const IDL = {
|
|
|
1556
1556
|
errors: [
|
|
1557
1557
|
{
|
|
1558
1558
|
code: 6000,
|
|
1559
|
-
name: '
|
|
1560
|
-
msg: '
|
|
1559
|
+
name: 'SignerCheckFailed',
|
|
1560
|
+
msg: 'Signer check failed',
|
|
1561
1561
|
},
|
|
1562
1562
|
{
|
|
1563
1563
|
code: 6001,
|
|
1564
|
-
name: '
|
|
1565
|
-
msg: '
|
|
1564
|
+
name: 'CreateTransferInstructionFailed',
|
|
1565
|
+
msg: 'Create transfer instruction failed',
|
|
1566
1566
|
},
|
|
1567
1567
|
{
|
|
1568
1568
|
code: 6002,
|
|
1569
|
-
name: '
|
|
1570
|
-
msg: '
|
|
1569
|
+
name: 'AccountNotFound',
|
|
1570
|
+
msg: 'Account not found',
|
|
1571
1571
|
},
|
|
1572
1572
|
{
|
|
1573
1573
|
code: 6003,
|
|
1574
|
-
name: '
|
|
1575
|
-
msg: '
|
|
1576
|
-
},
|
|
1577
|
-
{
|
|
1578
|
-
code: 6004,
|
|
1579
|
-
name: 'ComputeDecompressSumFailed',
|
|
1580
|
-
msg: 'ComputeDecompressSumFailed',
|
|
1581
|
-
},
|
|
1582
|
-
{
|
|
1583
|
-
code: 6005,
|
|
1584
|
-
name: 'SumCheckFailed',
|
|
1585
|
-
msg: 'SumCheckFailed',
|
|
1586
|
-
},
|
|
1587
|
-
{
|
|
1588
|
-
code: 6006,
|
|
1589
|
-
name: 'DecompressRecipientUndefinedForDecompress',
|
|
1590
|
-
msg: 'DecompressRecipientUndefinedForDecompress',
|
|
1591
|
-
},
|
|
1592
|
-
{
|
|
1593
|
-
code: 6007,
|
|
1594
|
-
name: 'CompressedPdaUndefinedForDecompress',
|
|
1595
|
-
msg: 'CompressedPdaUndefinedForDecompress',
|
|
1596
|
-
},
|
|
1597
|
-
{
|
|
1598
|
-
code: 6008,
|
|
1599
|
-
name: 'DeCompressAmountUndefinedForDecompress',
|
|
1600
|
-
msg: 'DeCompressAmountUndefinedForDecompress',
|
|
1601
|
-
},
|
|
1602
|
-
{
|
|
1603
|
-
code: 6009,
|
|
1604
|
-
name: 'CompressedPdaUndefinedForCompress',
|
|
1605
|
-
msg: 'CompressedPdaUndefinedForCompress',
|
|
1606
|
-
},
|
|
1607
|
-
{
|
|
1608
|
-
code: 6010,
|
|
1609
|
-
name: 'DeCompressAmountUndefinedForCompress',
|
|
1610
|
-
msg: 'DeCompressAmountUndefinedForCompress',
|
|
1611
|
-
},
|
|
1612
|
-
{
|
|
1613
|
-
code: 6011,
|
|
1614
|
-
name: 'DelegateSignerCheckFailed',
|
|
1615
|
-
msg: 'DelegateSignerCheckFailed',
|
|
1616
|
-
},
|
|
1617
|
-
{
|
|
1618
|
-
code: 6012,
|
|
1619
|
-
name: 'MintTooLarge',
|
|
1620
|
-
msg: 'Minted amount greater than u64::MAX',
|
|
1621
|
-
},
|
|
1622
|
-
{
|
|
1623
|
-
code: 6013,
|
|
1624
|
-
name: 'SplTokenSupplyMismatch',
|
|
1625
|
-
msg: 'SplTokenSupplyMismatch',
|
|
1626
|
-
},
|
|
1627
|
-
{
|
|
1628
|
-
code: 6014,
|
|
1629
|
-
name: 'HeapMemoryCheckFailed',
|
|
1630
|
-
msg: 'HeapMemoryCheckFailed',
|
|
1631
|
-
},
|
|
1632
|
-
{
|
|
1633
|
-
code: 6015,
|
|
1634
|
-
name: 'InstructionNotCallable',
|
|
1635
|
-
msg: 'The instruction is not callable',
|
|
1636
|
-
},
|
|
1637
|
-
{
|
|
1638
|
-
code: 6016,
|
|
1639
|
-
name: 'ArithmeticUnderflow',
|
|
1640
|
-
msg: 'ArithmeticUnderflow',
|
|
1641
|
-
},
|
|
1642
|
-
{
|
|
1643
|
-
code: 6017,
|
|
1644
|
-
name: 'HashToFieldError',
|
|
1645
|
-
msg: 'HashToFieldError',
|
|
1646
|
-
},
|
|
1647
|
-
{
|
|
1648
|
-
code: 6018,
|
|
1649
|
-
name: 'InvalidAuthorityMint',
|
|
1650
|
-
msg: 'Expected the authority to be also a mint authority',
|
|
1651
|
-
},
|
|
1652
|
-
{
|
|
1653
|
-
code: 6019,
|
|
1654
|
-
name: 'InvalidFreezeAuthority',
|
|
1655
|
-
msg: 'Provided authority is not the freeze authority',
|
|
1656
|
-
},
|
|
1657
|
-
{
|
|
1658
|
-
code: 6020,
|
|
1659
|
-
name: 'InvalidDelegateIndex',
|
|
1660
|
-
},
|
|
1661
|
-
{
|
|
1662
|
-
code: 6021,
|
|
1663
|
-
name: 'TokenPoolPdaUndefined',
|
|
1664
|
-
},
|
|
1665
|
-
{
|
|
1666
|
-
code: 6022,
|
|
1667
|
-
name: 'IsTokenPoolPda',
|
|
1668
|
-
msg: 'Compress or decompress recipient is the same account as the token pool pda.',
|
|
1669
|
-
},
|
|
1670
|
-
{
|
|
1671
|
-
code: 6023,
|
|
1672
|
-
name: 'InvalidTokenPoolPda',
|
|
1673
|
-
},
|
|
1674
|
-
{
|
|
1675
|
-
code: 6024,
|
|
1676
|
-
name: 'NoInputTokenAccountsProvided',
|
|
1677
|
-
},
|
|
1678
|
-
{
|
|
1679
|
-
code: 6025,
|
|
1680
|
-
name: 'NoInputsProvided',
|
|
1574
|
+
name: 'SerializationError',
|
|
1575
|
+
msg: 'Serialization error',
|
|
1681
1576
|
},
|
|
1682
1577
|
],
|
|
1683
1578
|
};
|
|
@@ -5033,6 +4928,22 @@ class CompressedTokenProgram {
|
|
|
5033
4928
|
.instruction();
|
|
5034
4929
|
return instruction;
|
|
5035
4930
|
}
|
|
4931
|
+
static async mergeTokenAccounts(params) {
|
|
4932
|
+
const { payer, owner, inputCompressedTokenAccounts, outputStateTree, recentValidityProof, recentInputStateRootIndices, } = params;
|
|
4933
|
+
if (inputCompressedTokenAccounts.length > 3) {
|
|
4934
|
+
throw new Error('Cannot merge more than 3 token accounts at once');
|
|
4935
|
+
}
|
|
4936
|
+
const ix = await this.transfer({
|
|
4937
|
+
payer,
|
|
4938
|
+
inputCompressedTokenAccounts,
|
|
4939
|
+
toAddress: owner,
|
|
4940
|
+
amount: inputCompressedTokenAccounts.reduce((sum, account) => sum.add(account.parsed.amount), new anchor.BN(0)),
|
|
4941
|
+
outputStateTrees: outputStateTree,
|
|
4942
|
+
recentInputStateRootIndices,
|
|
4943
|
+
recentValidityProof,
|
|
4944
|
+
});
|
|
4945
|
+
return [ix];
|
|
4946
|
+
}
|
|
5036
4947
|
}
|
|
5037
4948
|
/**
|
|
5038
4949
|
* Public key that identifies the CompressedPda program
|
|
@@ -5292,6 +5203,51 @@ async function mintTo(rpc, payer, mint, destination, authority, amount, merkleTr
|
|
|
5292
5203
|
return txId;
|
|
5293
5204
|
}
|
|
5294
5205
|
|
|
5206
|
+
/**
|
|
5207
|
+
* Merge multiple compressed token accounts for a given mint into a single
|
|
5208
|
+
* account
|
|
5209
|
+
*
|
|
5210
|
+
* @param rpc RPC to use
|
|
5211
|
+
* @param payer Payer of the transaction fees
|
|
5212
|
+
* @param mint Public key of the token's mint
|
|
5213
|
+
* @param owner Owner of the token accounts to be merged
|
|
5214
|
+
* @param merkleTree Optional merkle tree for compressed tokens
|
|
5215
|
+
* @param confirmOptions Options for confirming the transaction
|
|
5216
|
+
*
|
|
5217
|
+
* @return Array of transaction signatures
|
|
5218
|
+
*/
|
|
5219
|
+
async function mergeTokenAccounts(rpc, payer, mint, owner, merkleTree, confirmOptions) {
|
|
5220
|
+
const compressedTokenAccounts = await rpc.getCompressedTokenAccountsByOwner(owner.publicKey, { mint });
|
|
5221
|
+
if (compressedTokenAccounts.items.length === 0) {
|
|
5222
|
+
throw new Error(`No compressed token accounts found for mint ${mint.toBase58()}`);
|
|
5223
|
+
}
|
|
5224
|
+
if (compressedTokenAccounts.items.length >= 6) {
|
|
5225
|
+
throw new Error(`Too many compressed token accounts used for mint ${mint.toBase58()}`);
|
|
5226
|
+
}
|
|
5227
|
+
const instructions = [
|
|
5228
|
+
web3_js.ComputeBudgetProgram.setComputeUnitLimit({ units: 1000000 }),
|
|
5229
|
+
];
|
|
5230
|
+
for (let i = 0; i < compressedTokenAccounts.items.slice(0, 6).length; i += 3) {
|
|
5231
|
+
const batch = compressedTokenAccounts.items.slice(i, i + 3);
|
|
5232
|
+
const proof = await rpc.getValidityProof(batch.map(account => stateless_js.bn(account.compressedAccount.hash)));
|
|
5233
|
+
const batchInstructions = await CompressedTokenProgram.mergeTokenAccounts({
|
|
5234
|
+
payer: payer.publicKey,
|
|
5235
|
+
owner: owner.publicKey,
|
|
5236
|
+
mint,
|
|
5237
|
+
inputCompressedTokenAccounts: batch,
|
|
5238
|
+
outputStateTree: merkleTree,
|
|
5239
|
+
recentValidityProof: proof.compressedProof,
|
|
5240
|
+
recentInputStateRootIndices: proof.rootIndices,
|
|
5241
|
+
});
|
|
5242
|
+
instructions.push(...batchInstructions);
|
|
5243
|
+
}
|
|
5244
|
+
const { blockhash } = await rpc.getLatestBlockhash();
|
|
5245
|
+
const additionalSigners = stateless_js.dedupeSigner(payer, [owner]);
|
|
5246
|
+
const signedTx = stateless_js.buildAndSignTx(instructions, payer, blockhash, additionalSigners);
|
|
5247
|
+
const txId = await stateless_js.sendAndConfirmTx(rpc, signedTx, confirmOptions);
|
|
5248
|
+
return txId;
|
|
5249
|
+
}
|
|
5250
|
+
|
|
5295
5251
|
/**
|
|
5296
5252
|
* Register an existing mint with the CompressedToken program
|
|
5297
5253
|
*
|
|
@@ -5360,6 +5316,7 @@ exports.createTokenPool = createTokenPool;
|
|
|
5360
5316
|
exports.createTokenProgramLookupTable = createTokenProgramLookupTable;
|
|
5361
5317
|
exports.createTransferOutputState = createTransferOutputState;
|
|
5362
5318
|
exports.decompress = decompress;
|
|
5319
|
+
exports.mergeTokenAccounts = mergeTokenAccounts;
|
|
5363
5320
|
exports.mintTo = mintTo;
|
|
5364
5321
|
exports.packCompressedTokenAccounts = packCompressedTokenAccounts;
|
|
5365
5322
|
exports.parseTokenData = parseTokenData;
|