@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
|
@@ -5,7 +5,7 @@ var web3_js = require('@solana/web3.js');
|
|
|
5
5
|
var anchor = require('@coral-xyz/anchor');
|
|
6
6
|
|
|
7
7
|
const IDL = {
|
|
8
|
-
version: '1.
|
|
8
|
+
version: '1.2.0',
|
|
9
9
|
name: 'light_compressed_token',
|
|
10
10
|
instructions: [
|
|
11
11
|
{
|
|
@@ -1555,128 +1555,23 @@ const IDL = {
|
|
|
1555
1555
|
errors: [
|
|
1556
1556
|
{
|
|
1557
1557
|
code: 6000,
|
|
1558
|
-
name: '
|
|
1559
|
-
msg: '
|
|
1558
|
+
name: 'SignerCheckFailed',
|
|
1559
|
+
msg: 'Signer check failed',
|
|
1560
1560
|
},
|
|
1561
1561
|
{
|
|
1562
1562
|
code: 6001,
|
|
1563
|
-
name: '
|
|
1564
|
-
msg: '
|
|
1563
|
+
name: 'CreateTransferInstructionFailed',
|
|
1564
|
+
msg: 'Create transfer instruction failed',
|
|
1565
1565
|
},
|
|
1566
1566
|
{
|
|
1567
1567
|
code: 6002,
|
|
1568
|
-
name: '
|
|
1569
|
-
msg: '
|
|
1568
|
+
name: 'AccountNotFound',
|
|
1569
|
+
msg: 'Account not found',
|
|
1570
1570
|
},
|
|
1571
1571
|
{
|
|
1572
1572
|
code: 6003,
|
|
1573
|
-
name: '
|
|
1574
|
-
msg: '
|
|
1575
|
-
},
|
|
1576
|
-
{
|
|
1577
|
-
code: 6004,
|
|
1578
|
-
name: 'ComputeDecompressSumFailed',
|
|
1579
|
-
msg: 'ComputeDecompressSumFailed',
|
|
1580
|
-
},
|
|
1581
|
-
{
|
|
1582
|
-
code: 6005,
|
|
1583
|
-
name: 'SumCheckFailed',
|
|
1584
|
-
msg: 'SumCheckFailed',
|
|
1585
|
-
},
|
|
1586
|
-
{
|
|
1587
|
-
code: 6006,
|
|
1588
|
-
name: 'DecompressRecipientUndefinedForDecompress',
|
|
1589
|
-
msg: 'DecompressRecipientUndefinedForDecompress',
|
|
1590
|
-
},
|
|
1591
|
-
{
|
|
1592
|
-
code: 6007,
|
|
1593
|
-
name: 'CompressedPdaUndefinedForDecompress',
|
|
1594
|
-
msg: 'CompressedPdaUndefinedForDecompress',
|
|
1595
|
-
},
|
|
1596
|
-
{
|
|
1597
|
-
code: 6008,
|
|
1598
|
-
name: 'DeCompressAmountUndefinedForDecompress',
|
|
1599
|
-
msg: 'DeCompressAmountUndefinedForDecompress',
|
|
1600
|
-
},
|
|
1601
|
-
{
|
|
1602
|
-
code: 6009,
|
|
1603
|
-
name: 'CompressedPdaUndefinedForCompress',
|
|
1604
|
-
msg: 'CompressedPdaUndefinedForCompress',
|
|
1605
|
-
},
|
|
1606
|
-
{
|
|
1607
|
-
code: 6010,
|
|
1608
|
-
name: 'DeCompressAmountUndefinedForCompress',
|
|
1609
|
-
msg: 'DeCompressAmountUndefinedForCompress',
|
|
1610
|
-
},
|
|
1611
|
-
{
|
|
1612
|
-
code: 6011,
|
|
1613
|
-
name: 'DelegateSignerCheckFailed',
|
|
1614
|
-
msg: 'DelegateSignerCheckFailed',
|
|
1615
|
-
},
|
|
1616
|
-
{
|
|
1617
|
-
code: 6012,
|
|
1618
|
-
name: 'MintTooLarge',
|
|
1619
|
-
msg: 'Minted amount greater than u64::MAX',
|
|
1620
|
-
},
|
|
1621
|
-
{
|
|
1622
|
-
code: 6013,
|
|
1623
|
-
name: 'SplTokenSupplyMismatch',
|
|
1624
|
-
msg: 'SplTokenSupplyMismatch',
|
|
1625
|
-
},
|
|
1626
|
-
{
|
|
1627
|
-
code: 6014,
|
|
1628
|
-
name: 'HeapMemoryCheckFailed',
|
|
1629
|
-
msg: 'HeapMemoryCheckFailed',
|
|
1630
|
-
},
|
|
1631
|
-
{
|
|
1632
|
-
code: 6015,
|
|
1633
|
-
name: 'InstructionNotCallable',
|
|
1634
|
-
msg: 'The instruction is not callable',
|
|
1635
|
-
},
|
|
1636
|
-
{
|
|
1637
|
-
code: 6016,
|
|
1638
|
-
name: 'ArithmeticUnderflow',
|
|
1639
|
-
msg: 'ArithmeticUnderflow',
|
|
1640
|
-
},
|
|
1641
|
-
{
|
|
1642
|
-
code: 6017,
|
|
1643
|
-
name: 'HashToFieldError',
|
|
1644
|
-
msg: 'HashToFieldError',
|
|
1645
|
-
},
|
|
1646
|
-
{
|
|
1647
|
-
code: 6018,
|
|
1648
|
-
name: 'InvalidAuthorityMint',
|
|
1649
|
-
msg: 'Expected the authority to be also a mint authority',
|
|
1650
|
-
},
|
|
1651
|
-
{
|
|
1652
|
-
code: 6019,
|
|
1653
|
-
name: 'InvalidFreezeAuthority',
|
|
1654
|
-
msg: 'Provided authority is not the freeze authority',
|
|
1655
|
-
},
|
|
1656
|
-
{
|
|
1657
|
-
code: 6020,
|
|
1658
|
-
name: 'InvalidDelegateIndex',
|
|
1659
|
-
},
|
|
1660
|
-
{
|
|
1661
|
-
code: 6021,
|
|
1662
|
-
name: 'TokenPoolPdaUndefined',
|
|
1663
|
-
},
|
|
1664
|
-
{
|
|
1665
|
-
code: 6022,
|
|
1666
|
-
name: 'IsTokenPoolPda',
|
|
1667
|
-
msg: 'Compress or decompress recipient is the same account as the token pool pda.',
|
|
1668
|
-
},
|
|
1669
|
-
{
|
|
1670
|
-
code: 6023,
|
|
1671
|
-
name: 'InvalidTokenPoolPda',
|
|
1672
|
-
},
|
|
1673
|
-
{
|
|
1674
|
-
code: 6024,
|
|
1675
|
-
name: 'NoInputTokenAccountsProvided',
|
|
1676
|
-
},
|
|
1677
|
-
{
|
|
1678
|
-
code: 6025,
|
|
1679
|
-
name: 'NoInputsProvided',
|
|
1573
|
+
name: 'SerializationError',
|
|
1574
|
+
msg: 'Serialization error',
|
|
1680
1575
|
},
|
|
1681
1576
|
],
|
|
1682
1577
|
};
|
|
@@ -7056,6 +6951,22 @@ class CompressedTokenProgram {
|
|
|
7056
6951
|
.instruction();
|
|
7057
6952
|
return instruction;
|
|
7058
6953
|
}
|
|
6954
|
+
static async mergeTokenAccounts(params) {
|
|
6955
|
+
const { payer, owner, inputCompressedTokenAccounts, outputStateTree, recentValidityProof, recentInputStateRootIndices, } = params;
|
|
6956
|
+
if (inputCompressedTokenAccounts.length > 3) {
|
|
6957
|
+
throw new Error('Cannot merge more than 3 token accounts at once');
|
|
6958
|
+
}
|
|
6959
|
+
const ix = await this.transfer({
|
|
6960
|
+
payer,
|
|
6961
|
+
inputCompressedTokenAccounts,
|
|
6962
|
+
toAddress: owner,
|
|
6963
|
+
amount: inputCompressedTokenAccounts.reduce((sum, account) => sum.add(account.parsed.amount), new anchor.BN(0)),
|
|
6964
|
+
outputStateTrees: outputStateTree,
|
|
6965
|
+
recentInputStateRootIndices,
|
|
6966
|
+
recentValidityProof,
|
|
6967
|
+
});
|
|
6968
|
+
return [ix];
|
|
6969
|
+
}
|
|
7059
6970
|
}
|
|
7060
6971
|
/**
|
|
7061
6972
|
* Public key that identifies the CompressedPda program
|
|
@@ -7315,6 +7226,51 @@ async function mintTo(rpc, payer, mint, destination, authority, amount, merkleTr
|
|
|
7315
7226
|
return txId;
|
|
7316
7227
|
}
|
|
7317
7228
|
|
|
7229
|
+
/**
|
|
7230
|
+
* Merge multiple compressed token accounts for a given mint into a single
|
|
7231
|
+
* account
|
|
7232
|
+
*
|
|
7233
|
+
* @param rpc RPC to use
|
|
7234
|
+
* @param payer Payer of the transaction fees
|
|
7235
|
+
* @param mint Public key of the token's mint
|
|
7236
|
+
* @param owner Owner of the token accounts to be merged
|
|
7237
|
+
* @param merkleTree Optional merkle tree for compressed tokens
|
|
7238
|
+
* @param confirmOptions Options for confirming the transaction
|
|
7239
|
+
*
|
|
7240
|
+
* @return Array of transaction signatures
|
|
7241
|
+
*/
|
|
7242
|
+
async function mergeTokenAccounts(rpc, payer, mint, owner, merkleTree, confirmOptions) {
|
|
7243
|
+
const compressedTokenAccounts = await rpc.getCompressedTokenAccountsByOwner(owner.publicKey, { mint });
|
|
7244
|
+
if (compressedTokenAccounts.items.length === 0) {
|
|
7245
|
+
throw new Error(`No compressed token accounts found for mint ${mint.toBase58()}`);
|
|
7246
|
+
}
|
|
7247
|
+
if (compressedTokenAccounts.items.length >= 6) {
|
|
7248
|
+
throw new Error(`Too many compressed token accounts used for mint ${mint.toBase58()}`);
|
|
7249
|
+
}
|
|
7250
|
+
const instructions = [
|
|
7251
|
+
web3_js.ComputeBudgetProgram.setComputeUnitLimit({ units: 1000000 }),
|
|
7252
|
+
];
|
|
7253
|
+
for (let i = 0; i < compressedTokenAccounts.items.slice(0, 6).length; i += 3) {
|
|
7254
|
+
const batch = compressedTokenAccounts.items.slice(i, i + 3);
|
|
7255
|
+
const proof = await rpc.getValidityProof(batch.map(account => stateless_js.bn(account.compressedAccount.hash)));
|
|
7256
|
+
const batchInstructions = await CompressedTokenProgram.mergeTokenAccounts({
|
|
7257
|
+
payer: payer.publicKey,
|
|
7258
|
+
owner: owner.publicKey,
|
|
7259
|
+
mint,
|
|
7260
|
+
inputCompressedTokenAccounts: batch,
|
|
7261
|
+
outputStateTree: merkleTree,
|
|
7262
|
+
recentValidityProof: proof.compressedProof,
|
|
7263
|
+
recentInputStateRootIndices: proof.rootIndices,
|
|
7264
|
+
});
|
|
7265
|
+
instructions.push(...batchInstructions);
|
|
7266
|
+
}
|
|
7267
|
+
const { blockhash } = await rpc.getLatestBlockhash();
|
|
7268
|
+
const additionalSigners = stateless_js.dedupeSigner(payer, [owner]);
|
|
7269
|
+
const signedTx = stateless_js.buildAndSignTx(instructions, payer, blockhash, additionalSigners);
|
|
7270
|
+
const txId = await stateless_js.sendAndConfirmTx(rpc, signedTx, confirmOptions);
|
|
7271
|
+
return txId;
|
|
7272
|
+
}
|
|
7273
|
+
|
|
7318
7274
|
/**
|
|
7319
7275
|
* Register an existing mint with the CompressedToken program
|
|
7320
7276
|
*
|
|
@@ -7383,6 +7339,7 @@ exports.createTokenPool = createTokenPool;
|
|
|
7383
7339
|
exports.createTokenProgramLookupTable = createTokenProgramLookupTable;
|
|
7384
7340
|
exports.createTransferOutputState = createTransferOutputState;
|
|
7385
7341
|
exports.decompress = decompress;
|
|
7342
|
+
exports.mergeTokenAccounts = mergeTokenAccounts;
|
|
7386
7343
|
exports.mintTo = mintTo;
|
|
7387
7344
|
exports.packCompressedTokenAccounts = packCompressedTokenAccounts;
|
|
7388
7345
|
exports.parseTokenData = parseTokenData;
|