@lightprotocol/compressed-token 0.16.0 → 0.17.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 +430 -703
- package/dist/cjs/browser/index.cjs.map +1 -1
- package/dist/cjs/node/index.cjs +430 -703
- package/dist/cjs/node/index.cjs.map +1 -1
- package/dist/es/browser/index.js +395 -632
- package/dist/es/browser/index.js.map +1 -1
- package/dist/types/index.d.ts +270 -278
- package/package.json +2 -2
package/dist/cjs/node/index.cjs
CHANGED
|
@@ -89,9 +89,6 @@ const IDL = {
|
|
|
89
89
|
name: 'tokenPoolPda',
|
|
90
90
|
isMut: true,
|
|
91
91
|
isSigner: false,
|
|
92
|
-
docs: [
|
|
93
|
-
'account to a token account of a different mint will fail',
|
|
94
|
-
],
|
|
95
92
|
},
|
|
96
93
|
{
|
|
97
94
|
name: 'tokenProgram',
|
|
@@ -169,6 +166,11 @@ const IDL = {
|
|
|
169
166
|
},
|
|
170
167
|
{
|
|
171
168
|
name: 'compressSplTokenAccount',
|
|
169
|
+
docs: [
|
|
170
|
+
'Compresses the balance of an spl token account sub an optional remaining',
|
|
171
|
+
'amount. This instruction does not close the spl token account. To close',
|
|
172
|
+
'the account bundle a close spl account instruction in your transaction.',
|
|
173
|
+
],
|
|
172
174
|
accounts: [
|
|
173
175
|
{
|
|
174
176
|
name: 'feePayer',
|
|
@@ -1162,8 +1164,7 @@ const IDL = {
|
|
|
1162
1164
|
name: 'inputCompressedAccountsWithMerkleContext',
|
|
1163
1165
|
type: {
|
|
1164
1166
|
vec: {
|
|
1165
|
-
defined:
|
|
1166
|
-
'PackedCompressedAccountWithMerkleContext',
|
|
1167
|
+
defined: 'PackedCompressedAccountWithMerkleContext',
|
|
1167
1168
|
},
|
|
1168
1169
|
},
|
|
1169
1170
|
},
|
|
@@ -1171,8 +1172,7 @@ const IDL = {
|
|
|
1171
1172
|
name: 'outputCompressedAccounts',
|
|
1172
1173
|
type: {
|
|
1173
1174
|
vec: {
|
|
1174
|
-
defined:
|
|
1175
|
-
'OutputCompressedAccountWithPackedContext',
|
|
1175
|
+
defined: 'OutputCompressedAccountWithPackedContext',
|
|
1176
1176
|
},
|
|
1177
1177
|
},
|
|
1178
1178
|
},
|
|
@@ -1228,8 +1228,7 @@ const IDL = {
|
|
|
1228
1228
|
name: 'inputCompressedAccountsWithMerkleContext',
|
|
1229
1229
|
type: {
|
|
1230
1230
|
vec: {
|
|
1231
|
-
defined:
|
|
1232
|
-
'PackedCompressedAccountWithMerkleContext',
|
|
1231
|
+
defined: 'PackedCompressedAccountWithMerkleContext',
|
|
1233
1232
|
},
|
|
1234
1233
|
},
|
|
1235
1234
|
},
|
|
@@ -1237,8 +1236,7 @@ const IDL = {
|
|
|
1237
1236
|
name: 'outputCompressedAccounts',
|
|
1238
1237
|
type: {
|
|
1239
1238
|
vec: {
|
|
1240
|
-
defined:
|
|
1241
|
-
'OutputCompressedAccountWithPackedContext',
|
|
1239
|
+
defined: 'OutputCompressedAccountWithPackedContext',
|
|
1242
1240
|
},
|
|
1243
1241
|
},
|
|
1244
1242
|
},
|
|
@@ -1483,8 +1481,7 @@ const IDL = {
|
|
|
1483
1481
|
name: 'outputCompressedAccounts',
|
|
1484
1482
|
type: {
|
|
1485
1483
|
vec: {
|
|
1486
|
-
defined:
|
|
1487
|
-
'OutputCompressedAccountWithPackedContext',
|
|
1484
|
+
defined: 'OutputCompressedAccountWithPackedContext',
|
|
1488
1485
|
},
|
|
1489
1486
|
},
|
|
1490
1487
|
},
|
|
@@ -1661,23 +1658,141 @@ const IDL = {
|
|
|
1661
1658
|
errors: [
|
|
1662
1659
|
{
|
|
1663
1660
|
code: 6000,
|
|
1664
|
-
name: '
|
|
1665
|
-
msg: '
|
|
1661
|
+
name: 'PublicKeyAmountMissmatch',
|
|
1662
|
+
msg: 'public keys and amounts must be of same length',
|
|
1666
1663
|
},
|
|
1667
1664
|
{
|
|
1668
1665
|
code: 6001,
|
|
1669
|
-
name: '
|
|
1670
|
-
msg: '
|
|
1666
|
+
name: 'ComputeInputSumFailed',
|
|
1667
|
+
msg: 'ComputeInputSumFailed',
|
|
1671
1668
|
},
|
|
1672
1669
|
{
|
|
1673
1670
|
code: 6002,
|
|
1674
|
-
name: '
|
|
1675
|
-
msg: '
|
|
1671
|
+
name: 'ComputeOutputSumFailed',
|
|
1672
|
+
msg: 'ComputeOutputSumFailed',
|
|
1676
1673
|
},
|
|
1677
1674
|
{
|
|
1678
1675
|
code: 6003,
|
|
1679
|
-
name: '
|
|
1680
|
-
msg: '
|
|
1676
|
+
name: 'ComputeCompressSumFailed',
|
|
1677
|
+
msg: 'ComputeCompressSumFailed',
|
|
1678
|
+
},
|
|
1679
|
+
{
|
|
1680
|
+
code: 6004,
|
|
1681
|
+
name: 'ComputeDecompressSumFailed',
|
|
1682
|
+
msg: 'ComputeDecompressSumFailed',
|
|
1683
|
+
},
|
|
1684
|
+
{
|
|
1685
|
+
code: 6005,
|
|
1686
|
+
name: 'SumCheckFailed',
|
|
1687
|
+
msg: 'SumCheckFailed',
|
|
1688
|
+
},
|
|
1689
|
+
{
|
|
1690
|
+
code: 6006,
|
|
1691
|
+
name: 'DecompressRecipientUndefinedForDecompress',
|
|
1692
|
+
msg: 'DecompressRecipientUndefinedForDecompress',
|
|
1693
|
+
},
|
|
1694
|
+
{
|
|
1695
|
+
code: 6007,
|
|
1696
|
+
name: 'CompressedPdaUndefinedForDecompress',
|
|
1697
|
+
msg: 'CompressedPdaUndefinedForDecompress',
|
|
1698
|
+
},
|
|
1699
|
+
{
|
|
1700
|
+
code: 6008,
|
|
1701
|
+
name: 'DeCompressAmountUndefinedForDecompress',
|
|
1702
|
+
msg: 'DeCompressAmountUndefinedForDecompress',
|
|
1703
|
+
},
|
|
1704
|
+
{
|
|
1705
|
+
code: 6009,
|
|
1706
|
+
name: 'CompressedPdaUndefinedForCompress',
|
|
1707
|
+
msg: 'CompressedPdaUndefinedForCompress',
|
|
1708
|
+
},
|
|
1709
|
+
{
|
|
1710
|
+
code: 6010,
|
|
1711
|
+
name: 'DeCompressAmountUndefinedForCompress',
|
|
1712
|
+
msg: 'DeCompressAmountUndefinedForCompress',
|
|
1713
|
+
},
|
|
1714
|
+
{
|
|
1715
|
+
code: 6011,
|
|
1716
|
+
name: 'DelegateSignerCheckFailed',
|
|
1717
|
+
msg: 'DelegateSignerCheckFailed',
|
|
1718
|
+
},
|
|
1719
|
+
{
|
|
1720
|
+
code: 6012,
|
|
1721
|
+
name: 'MintTooLarge',
|
|
1722
|
+
msg: 'Minted amount greater than u64::MAX',
|
|
1723
|
+
},
|
|
1724
|
+
{
|
|
1725
|
+
code: 6013,
|
|
1726
|
+
name: 'SplTokenSupplyMismatch',
|
|
1727
|
+
msg: 'SplTokenSupplyMismatch',
|
|
1728
|
+
},
|
|
1729
|
+
{
|
|
1730
|
+
code: 6014,
|
|
1731
|
+
name: 'HeapMemoryCheckFailed',
|
|
1732
|
+
msg: 'HeapMemoryCheckFailed',
|
|
1733
|
+
},
|
|
1734
|
+
{
|
|
1735
|
+
code: 6015,
|
|
1736
|
+
name: 'InstructionNotCallable',
|
|
1737
|
+
msg: 'The instruction is not callable',
|
|
1738
|
+
},
|
|
1739
|
+
{
|
|
1740
|
+
code: 6016,
|
|
1741
|
+
name: 'ArithmeticUnderflow',
|
|
1742
|
+
msg: 'ArithmeticUnderflow',
|
|
1743
|
+
},
|
|
1744
|
+
{
|
|
1745
|
+
code: 6017,
|
|
1746
|
+
name: 'HashToFieldError',
|
|
1747
|
+
msg: 'HashToFieldError',
|
|
1748
|
+
},
|
|
1749
|
+
{
|
|
1750
|
+
code: 6018,
|
|
1751
|
+
name: 'InvalidAuthorityMint',
|
|
1752
|
+
msg: 'Expected the authority to be also a mint authority',
|
|
1753
|
+
},
|
|
1754
|
+
{
|
|
1755
|
+
code: 6019,
|
|
1756
|
+
name: 'InvalidFreezeAuthority',
|
|
1757
|
+
msg: 'Provided authority is not the freeze authority',
|
|
1758
|
+
},
|
|
1759
|
+
{
|
|
1760
|
+
code: 6020,
|
|
1761
|
+
name: 'InvalidDelegateIndex',
|
|
1762
|
+
},
|
|
1763
|
+
{
|
|
1764
|
+
code: 6021,
|
|
1765
|
+
name: 'TokenPoolPdaUndefined',
|
|
1766
|
+
},
|
|
1767
|
+
{
|
|
1768
|
+
code: 6022,
|
|
1769
|
+
name: 'IsTokenPoolPda',
|
|
1770
|
+
msg: 'Compress or decompress recipient is the same account as the token pool pda.',
|
|
1771
|
+
},
|
|
1772
|
+
{
|
|
1773
|
+
code: 6023,
|
|
1774
|
+
name: 'InvalidTokenPoolPda',
|
|
1775
|
+
},
|
|
1776
|
+
{
|
|
1777
|
+
code: 6024,
|
|
1778
|
+
name: 'NoInputTokenAccountsProvided',
|
|
1779
|
+
},
|
|
1780
|
+
{
|
|
1781
|
+
code: 6025,
|
|
1782
|
+
name: 'NoInputsProvided',
|
|
1783
|
+
},
|
|
1784
|
+
{
|
|
1785
|
+
code: 6026,
|
|
1786
|
+
name: 'MintHasNoFreezeAuthority',
|
|
1787
|
+
},
|
|
1788
|
+
{
|
|
1789
|
+
code: 6027,
|
|
1790
|
+
name: 'MintWithInvalidExtension',
|
|
1791
|
+
},
|
|
1792
|
+
{
|
|
1793
|
+
code: 6028,
|
|
1794
|
+
name: 'InsufficientTokenAccountBalance',
|
|
1795
|
+
msg: 'The token account balance is less than the remaining amount.',
|
|
1681
1796
|
},
|
|
1682
1797
|
],
|
|
1683
1798
|
};
|
|
@@ -1687,37 +1802,20 @@ const IDL = {
|
|
|
1687
1802
|
* Packs Compressed Token Accounts.
|
|
1688
1803
|
*/
|
|
1689
1804
|
function packCompressedTokenAccounts(params) {
|
|
1690
|
-
const {
|
|
1691
|
-
inputCompressedTokenAccounts,
|
|
1692
|
-
outputStateTrees,
|
|
1693
|
-
remainingAccounts = [],
|
|
1694
|
-
rootIndices,
|
|
1695
|
-
tokenTransferOutputs,
|
|
1696
|
-
} = params;
|
|
1805
|
+
const { inputCompressedTokenAccounts, outputStateTrees, remainingAccounts = [], rootIndices, tokenTransferOutputs, } = params;
|
|
1697
1806
|
const _remainingAccounts = remainingAccounts.slice();
|
|
1698
1807
|
let delegateIndex = null;
|
|
1699
|
-
if (
|
|
1700
|
-
inputCompressedTokenAccounts.
|
|
1701
|
-
inputCompressedTokenAccounts[0].parsed.delegate
|
|
1702
|
-
) {
|
|
1703
|
-
delegateIndex = stateless_js.getIndexOrAdd(
|
|
1704
|
-
_remainingAccounts,
|
|
1705
|
-
inputCompressedTokenAccounts[0].parsed.delegate,
|
|
1706
|
-
);
|
|
1808
|
+
if (inputCompressedTokenAccounts.length > 0 &&
|
|
1809
|
+
inputCompressedTokenAccounts[0].parsed.delegate) {
|
|
1810
|
+
delegateIndex = stateless_js.getIndexOrAdd(_remainingAccounts, inputCompressedTokenAccounts[0].parsed.delegate);
|
|
1707
1811
|
}
|
|
1708
1812
|
/// TODO: move pubkeyArray to remainingAccounts
|
|
1709
1813
|
/// Currently just packs 'delegate' to pubkeyArray
|
|
1710
1814
|
const packedInputTokenData = [];
|
|
1711
1815
|
/// pack inputs
|
|
1712
1816
|
inputCompressedTokenAccounts.forEach((account, index) => {
|
|
1713
|
-
const merkleTreePubkeyIndex = stateless_js.getIndexOrAdd(
|
|
1714
|
-
|
|
1715
|
-
account.compressedAccount.merkleTree,
|
|
1716
|
-
);
|
|
1717
|
-
const nullifierQueuePubkeyIndex = stateless_js.getIndexOrAdd(
|
|
1718
|
-
_remainingAccounts,
|
|
1719
|
-
account.compressedAccount.nullifierQueue,
|
|
1720
|
-
);
|
|
1817
|
+
const merkleTreePubkeyIndex = stateless_js.getIndexOrAdd(_remainingAccounts, account.compressedAccount.merkleTree);
|
|
1818
|
+
const nullifierQueuePubkeyIndex = stateless_js.getIndexOrAdd(_remainingAccounts, account.compressedAccount.nullifierQueue);
|
|
1721
1819
|
packedInputTokenData.push({
|
|
1722
1820
|
amount: account.parsed.amount,
|
|
1723
1821
|
delegateIndex,
|
|
@@ -1735,27 +1833,15 @@ function packCompressedTokenAccounts(params) {
|
|
|
1735
1833
|
});
|
|
1736
1834
|
});
|
|
1737
1835
|
/// pack output state trees
|
|
1738
|
-
const paddedOutputStateMerkleTrees = stateless_js.padOutputStateMerkleTrees(
|
|
1739
|
-
outputStateTrees,
|
|
1740
|
-
tokenTransferOutputs.length,
|
|
1741
|
-
inputCompressedTokenAccounts.map(acc => acc.compressedAccount),
|
|
1742
|
-
);
|
|
1836
|
+
const paddedOutputStateMerkleTrees = stateless_js.padOutputStateMerkleTrees(outputStateTrees, tokenTransferOutputs.length, inputCompressedTokenAccounts.map(acc => acc.compressedAccount));
|
|
1743
1837
|
const packedOutputTokenData = [];
|
|
1744
1838
|
paddedOutputStateMerkleTrees.forEach((account, index) => {
|
|
1745
1839
|
var _a;
|
|
1746
|
-
const merkleTreeIndex = stateless_js.getIndexOrAdd(
|
|
1747
|
-
_remainingAccounts,
|
|
1748
|
-
account,
|
|
1749
|
-
);
|
|
1840
|
+
const merkleTreeIndex = stateless_js.getIndexOrAdd(_remainingAccounts, account);
|
|
1750
1841
|
packedOutputTokenData.push({
|
|
1751
1842
|
owner: tokenTransferOutputs[index].owner,
|
|
1752
1843
|
amount: tokenTransferOutputs[index].amount,
|
|
1753
|
-
lamports: (
|
|
1754
|
-
(_a = tokenTransferOutputs[index].lamports) === null ||
|
|
1755
|
-
_a === void 0
|
|
1756
|
-
? void 0
|
|
1757
|
-
: _a.eq(stateless_js.bn(0))
|
|
1758
|
-
)
|
|
1844
|
+
lamports: ((_a = tokenTransferOutputs[index].lamports) === null || _a === void 0 ? void 0 : _a.eq(stateless_js.bn(0)))
|
|
1759
1845
|
? null
|
|
1760
1846
|
: tokenTransferOutputs[index].lamports,
|
|
1761
1847
|
merkleTreeIndex,
|
|
@@ -1763,7 +1849,7 @@ function packCompressedTokenAccounts(params) {
|
|
|
1763
1849
|
});
|
|
1764
1850
|
});
|
|
1765
1851
|
// to meta
|
|
1766
|
-
const remainingAccountMetas = _remainingAccounts.map(account => ({
|
|
1852
|
+
const remainingAccountMetas = _remainingAccounts.map((account) => ({
|
|
1767
1853
|
pubkey: account,
|
|
1768
1854
|
isWritable: true,
|
|
1769
1855
|
isSigner: false,
|
|
@@ -1782,16 +1868,13 @@ const SPL_TOKEN_MINT_RENT_EXEMPT_BALANCE = 1461600;
|
|
|
1782
1868
|
/**
|
|
1783
1869
|
* Sum up the token amounts of the compressed token accounts
|
|
1784
1870
|
*/
|
|
1785
|
-
const sumUpTokenAmount = accounts => {
|
|
1786
|
-
return accounts.reduce(
|
|
1787
|
-
(acc, account) => acc.add(account.parsed.amount),
|
|
1788
|
-
stateless_js.bn(0),
|
|
1789
|
-
);
|
|
1871
|
+
const sumUpTokenAmount = (accounts) => {
|
|
1872
|
+
return accounts.reduce((acc, account) => acc.add(account.parsed.amount), stateless_js.bn(0));
|
|
1790
1873
|
};
|
|
1791
1874
|
/**
|
|
1792
1875
|
* Validate that all the compressed token accounts are owned by the same owner.
|
|
1793
1876
|
*/
|
|
1794
|
-
const validateSameTokenOwner = accounts => {
|
|
1877
|
+
const validateSameTokenOwner = (accounts) => {
|
|
1795
1878
|
const owner = accounts[0].parsed.owner;
|
|
1796
1879
|
accounts.forEach(acc => {
|
|
1797
1880
|
if (!acc.parsed.owner.equals(owner)) {
|
|
@@ -1802,7 +1885,7 @@ const validateSameTokenOwner = accounts => {
|
|
|
1802
1885
|
/**
|
|
1803
1886
|
* Parse compressed token accounts to get the mint, current owner and delegate.
|
|
1804
1887
|
*/
|
|
1805
|
-
const parseTokenData = compressedTokenAccounts => {
|
|
1888
|
+
const parseTokenData = (compressedTokenAccounts) => {
|
|
1806
1889
|
const mint = compressedTokenAccounts[0].parsed.mint;
|
|
1807
1890
|
const currentOwner = compressedTokenAccounts[0].parsed.owner;
|
|
1808
1891
|
const delegate = compressedTokenAccounts[0].parsed.delegate;
|
|
@@ -1816,22 +1899,13 @@ const parseTokenData = compressedTokenAccounts => {
|
|
|
1816
1899
|
* @returns Output token data for the transfer
|
|
1817
1900
|
* instruction
|
|
1818
1901
|
*/
|
|
1819
|
-
function createTransferOutputState(
|
|
1820
|
-
inputCompressedTokenAccounts,
|
|
1821
|
-
toAddress,
|
|
1822
|
-
amount,
|
|
1823
|
-
) {
|
|
1902
|
+
function createTransferOutputState(inputCompressedTokenAccounts, toAddress, amount) {
|
|
1824
1903
|
amount = stateless_js.bn(amount);
|
|
1825
1904
|
const inputAmount = sumUpTokenAmount(inputCompressedTokenAccounts);
|
|
1826
|
-
const inputLamports = stateless_js.sumUpLamports(
|
|
1827
|
-
inputCompressedTokenAccounts.map(acc => acc.compressedAccount),
|
|
1828
|
-
);
|
|
1905
|
+
const inputLamports = stateless_js.sumUpLamports(inputCompressedTokenAccounts.map(acc => acc.compressedAccount));
|
|
1829
1906
|
const changeAmount = inputAmount.sub(amount);
|
|
1830
1907
|
stateless_js.validateSufficientBalance(changeAmount);
|
|
1831
|
-
if (
|
|
1832
|
-
changeAmount.eq(stateless_js.bn(0)) &&
|
|
1833
|
-
inputLamports.eq(stateless_js.bn(0))
|
|
1834
|
-
) {
|
|
1908
|
+
if (changeAmount.eq(stateless_js.bn(0)) && inputLamports.eq(stateless_js.bn(0))) {
|
|
1835
1909
|
return [
|
|
1836
1910
|
{
|
|
1837
1911
|
owner: toAddress,
|
|
@@ -1842,9 +1916,7 @@ function createTransferOutputState(
|
|
|
1842
1916
|
];
|
|
1843
1917
|
}
|
|
1844
1918
|
/// validates token program
|
|
1845
|
-
stateless_js.validateSameOwner(
|
|
1846
|
-
inputCompressedTokenAccounts.map(acc => acc.compressedAccount),
|
|
1847
|
-
);
|
|
1919
|
+
stateless_js.validateSameOwner(inputCompressedTokenAccounts.map(acc => acc.compressedAccount));
|
|
1848
1920
|
validateSameTokenOwner(inputCompressedTokenAccounts);
|
|
1849
1921
|
const outputCompressedAccounts = [
|
|
1850
1922
|
{
|
|
@@ -1871,22 +1943,15 @@ function createTransferOutputState(
|
|
|
1871
1943
|
*/
|
|
1872
1944
|
function createDecompressOutputState(inputCompressedTokenAccounts, amount) {
|
|
1873
1945
|
amount = stateless_js.bn(amount);
|
|
1874
|
-
const inputLamports = stateless_js.sumUpLamports(
|
|
1875
|
-
inputCompressedTokenAccounts.map(acc => acc.compressedAccount),
|
|
1876
|
-
);
|
|
1946
|
+
const inputLamports = stateless_js.sumUpLamports(inputCompressedTokenAccounts.map(acc => acc.compressedAccount));
|
|
1877
1947
|
const inputAmount = sumUpTokenAmount(inputCompressedTokenAccounts);
|
|
1878
1948
|
const changeAmount = inputAmount.sub(amount);
|
|
1879
1949
|
stateless_js.validateSufficientBalance(changeAmount);
|
|
1880
1950
|
/// lamports gets decompressed
|
|
1881
|
-
if (
|
|
1882
|
-
changeAmount.eq(stateless_js.bn(0)) &&
|
|
1883
|
-
inputLamports.eq(stateless_js.bn(0))
|
|
1884
|
-
) {
|
|
1951
|
+
if (changeAmount.eq(stateless_js.bn(0)) && inputLamports.eq(stateless_js.bn(0))) {
|
|
1885
1952
|
return [];
|
|
1886
1953
|
}
|
|
1887
|
-
stateless_js.validateSameOwner(
|
|
1888
|
-
inputCompressedTokenAccounts.map(acc => acc.compressedAccount),
|
|
1889
|
-
);
|
|
1954
|
+
stateless_js.validateSameOwner(inputCompressedTokenAccounts.map(acc => acc.compressedAccount));
|
|
1890
1955
|
validateSameTokenOwner(inputCompressedTokenAccounts);
|
|
1891
1956
|
const tokenTransferOutputs = [
|
|
1892
1957
|
{
|
|
@@ -1902,7 +1967,7 @@ class CompressedTokenProgram {
|
|
|
1902
1967
|
/**
|
|
1903
1968
|
* @internal
|
|
1904
1969
|
*/
|
|
1905
|
-
constructor() {}
|
|
1970
|
+
constructor() { }
|
|
1906
1971
|
/**
|
|
1907
1972
|
* Set a custom programId via PublicKey or base58 encoded string.
|
|
1908
1973
|
* This method is not required for regular usage.
|
|
@@ -1934,65 +1999,42 @@ class CompressedTokenProgram {
|
|
|
1934
1999
|
/// program only for serde and building instructions, not for
|
|
1935
2000
|
/// interacting with the network.
|
|
1936
2001
|
const mockKeypair = web3_js.Keypair.generate();
|
|
1937
|
-
const mockConnection = new web3_js.Connection(
|
|
1938
|
-
|
|
1939
|
-
'confirmed',
|
|
1940
|
-
);
|
|
1941
|
-
const mockProvider = new anchor.AnchorProvider(
|
|
1942
|
-
mockConnection,
|
|
1943
|
-
stateless_js.useWallet(mockKeypair),
|
|
1944
|
-
stateless_js.confirmConfig,
|
|
1945
|
-
);
|
|
2002
|
+
const mockConnection = new web3_js.Connection('http://127.0.0.1:8899', 'confirmed');
|
|
2003
|
+
const mockProvider = new anchor.AnchorProvider(mockConnection, stateless_js.useWallet(mockKeypair), stateless_js.confirmConfig);
|
|
1946
2004
|
anchor.setProvider(mockProvider);
|
|
1947
|
-
this._program = new anchor.Program(
|
|
1948
|
-
IDL,
|
|
1949
|
-
this.programId,
|
|
1950
|
-
mockProvider,
|
|
1951
|
-
);
|
|
2005
|
+
this._program = new anchor.Program(IDL, this.programId, mockProvider);
|
|
1952
2006
|
}
|
|
1953
2007
|
}
|
|
1954
2008
|
/** @internal */
|
|
1955
2009
|
static deriveTokenPoolPda(mint) {
|
|
1956
2010
|
const seeds = [POOL_SEED, mint.toBuffer()];
|
|
1957
|
-
const [address, _] = web3_js.PublicKey.findProgramAddressSync(
|
|
1958
|
-
seeds,
|
|
1959
|
-
this.programId,
|
|
1960
|
-
);
|
|
2011
|
+
const [address, _] = web3_js.PublicKey.findProgramAddressSync(seeds, this.programId);
|
|
1961
2012
|
return address;
|
|
1962
2013
|
}
|
|
1963
2014
|
/** @internal */
|
|
1964
2015
|
static get deriveCpiAuthorityPda() {
|
|
1965
|
-
const [address, _] = web3_js.PublicKey.findProgramAddressSync(
|
|
1966
|
-
[CPI_AUTHORITY_SEED],
|
|
1967
|
-
this.programId,
|
|
1968
|
-
);
|
|
2016
|
+
const [address, _] = web3_js.PublicKey.findProgramAddressSync([CPI_AUTHORITY_SEED], this.programId);
|
|
1969
2017
|
return address;
|
|
1970
2018
|
}
|
|
1971
2019
|
/**
|
|
1972
2020
|
* Construct createMint instruction for compressed tokens
|
|
1973
2021
|
*/
|
|
1974
2022
|
static async createMint(params) {
|
|
1975
|
-
const { mint, authority, feePayer, rentExemptBalance } = params;
|
|
2023
|
+
const { mint, authority, feePayer, rentExemptBalance, tokenProgramId, freezeAuthority, mintSize, } = params;
|
|
2024
|
+
const tokenProgram = tokenProgramId !== null && tokenProgramId !== void 0 ? tokenProgramId : splToken.TOKEN_PROGRAM_ID;
|
|
1976
2025
|
/// Create and initialize SPL Mint account
|
|
1977
|
-
const createMintAccountInstruction =
|
|
1978
|
-
|
|
1979
|
-
|
|
1980
|
-
|
|
1981
|
-
|
|
1982
|
-
|
|
1983
|
-
|
|
1984
|
-
|
|
1985
|
-
const initializeMintInstruction =
|
|
1986
|
-
splToken.createInitializeMint2Instruction(
|
|
1987
|
-
mint,
|
|
1988
|
-
params.decimals,
|
|
1989
|
-
authority,
|
|
1990
|
-
params.freezeAuthority,
|
|
1991
|
-
splToken.TOKEN_PROGRAM_ID,
|
|
1992
|
-
);
|
|
2026
|
+
const createMintAccountInstruction = web3_js.SystemProgram.createAccount({
|
|
2027
|
+
fromPubkey: feePayer,
|
|
2028
|
+
lamports: rentExemptBalance,
|
|
2029
|
+
newAccountPubkey: mint,
|
|
2030
|
+
programId: tokenProgram,
|
|
2031
|
+
space: mintSize !== null && mintSize !== void 0 ? mintSize : splToken.MINT_SIZE,
|
|
2032
|
+
});
|
|
2033
|
+
const initializeMintInstruction = splToken.createInitializeMint2Instruction(mint, params.decimals, authority, freezeAuthority, tokenProgram);
|
|
1993
2034
|
const ix = await this.createTokenPool({
|
|
1994
2035
|
feePayer,
|
|
1995
2036
|
mint,
|
|
2037
|
+
tokenProgramId: tokenProgram,
|
|
1996
2038
|
});
|
|
1997
2039
|
return [createMintAccountInstruction, initializeMintInstruction, ix];
|
|
1998
2040
|
}
|
|
@@ -2001,18 +2043,19 @@ class CompressedTokenProgram {
|
|
|
2001
2043
|
* For new mints, use `CompressedTokenProgram.createMint`.
|
|
2002
2044
|
*/
|
|
2003
2045
|
static async createTokenPool(params) {
|
|
2004
|
-
const { mint, feePayer } = params;
|
|
2046
|
+
const { mint, feePayer, tokenProgramId } = params;
|
|
2047
|
+
const tokenProgram = tokenProgramId !== null && tokenProgramId !== void 0 ? tokenProgramId : splToken.TOKEN_PROGRAM_ID;
|
|
2005
2048
|
const tokenPoolPda = this.deriveTokenPoolPda(mint);
|
|
2006
2049
|
const ix = await this.program.methods
|
|
2007
2050
|
.createTokenPool()
|
|
2008
2051
|
.accounts({
|
|
2009
|
-
|
|
2010
|
-
|
|
2011
|
-
|
|
2012
|
-
|
|
2013
|
-
|
|
2014
|
-
|
|
2015
|
-
|
|
2052
|
+
mint,
|
|
2053
|
+
feePayer,
|
|
2054
|
+
tokenPoolPda,
|
|
2055
|
+
systemProgram: web3_js.SystemProgram.programId,
|
|
2056
|
+
tokenProgram,
|
|
2057
|
+
cpiAuthorityPda: this.deriveCpiAuthorityPda,
|
|
2058
|
+
})
|
|
2016
2059
|
.instruction();
|
|
2017
2060
|
return ix;
|
|
2018
2061
|
}
|
|
@@ -2021,65 +2064,43 @@ class CompressedTokenProgram {
|
|
|
2021
2064
|
*/
|
|
2022
2065
|
static async mintTo(params) {
|
|
2023
2066
|
const systemKeys = stateless_js.defaultStaticAccountsStruct();
|
|
2024
|
-
const { mint, feePayer, authority, merkleTree, toPubkey, amount } =
|
|
2025
|
-
|
|
2067
|
+
const { mint, feePayer, authority, merkleTree, toPubkey, amount, tokenProgramId, } = params;
|
|
2068
|
+
const tokenProgram = tokenProgramId !== null && tokenProgramId !== void 0 ? tokenProgramId : splToken.TOKEN_PROGRAM_ID;
|
|
2026
2069
|
const tokenPoolPda = this.deriveTokenPoolPda(mint);
|
|
2027
|
-
const amounts = stateless_js
|
|
2028
|
-
.toArray(amount)
|
|
2029
|
-
.map(amount => stateless_js.bn(amount));
|
|
2070
|
+
const amounts = stateless_js.toArray(amount).map(amount => stateless_js.bn(amount));
|
|
2030
2071
|
const toPubkeys = stateless_js.toArray(toPubkey);
|
|
2031
2072
|
if (amounts.length !== toPubkeys.length) {
|
|
2032
|
-
throw new Error(
|
|
2033
|
-
'Amount and toPubkey arrays must have the same length',
|
|
2034
|
-
);
|
|
2073
|
+
throw new Error('Amount and toPubkey arrays must have the same length');
|
|
2035
2074
|
}
|
|
2036
2075
|
const instruction = await this.program.methods
|
|
2037
2076
|
.mintTo(toPubkeys, amounts, null)
|
|
2038
2077
|
.accounts({
|
|
2039
|
-
|
|
2040
|
-
|
|
2041
|
-
|
|
2042
|
-
|
|
2043
|
-
|
|
2044
|
-
|
|
2045
|
-
|
|
2046
|
-
|
|
2047
|
-
|
|
2048
|
-
|
|
2049
|
-
|
|
2050
|
-
|
|
2051
|
-
|
|
2052
|
-
|
|
2053
|
-
|
|
2054
|
-
: stateless_js.defaultTestStateTreeAccounts()
|
|
2055
|
-
.merkleTree,
|
|
2056
|
-
selfProgram: this.programId,
|
|
2057
|
-
solPoolPda: null,
|
|
2058
|
-
})
|
|
2078
|
+
feePayer,
|
|
2079
|
+
authority,
|
|
2080
|
+
cpiAuthorityPda: this.deriveCpiAuthorityPda,
|
|
2081
|
+
mint,
|
|
2082
|
+
tokenPoolPda,
|
|
2083
|
+
tokenProgram,
|
|
2084
|
+
lightSystemProgram: stateless_js.LightSystemProgram.programId,
|
|
2085
|
+
registeredProgramPda: systemKeys.registeredProgramPda,
|
|
2086
|
+
noopProgram: systemKeys.noopProgram,
|
|
2087
|
+
accountCompressionAuthority: systemKeys.accountCompressionAuthority,
|
|
2088
|
+
accountCompressionProgram: systemKeys.accountCompressionProgram,
|
|
2089
|
+
merkleTree: merkleTree !== null && merkleTree !== void 0 ? merkleTree : stateless_js.defaultTestStateTreeAccounts().merkleTree,
|
|
2090
|
+
selfProgram: this.programId,
|
|
2091
|
+
solPoolPda: null,
|
|
2092
|
+
})
|
|
2059
2093
|
.instruction();
|
|
2060
2094
|
return instruction;
|
|
2061
2095
|
}
|
|
2062
|
-
/// TODO: add compressBatch functionality for batch minting
|
|
2063
2096
|
/**
|
|
2064
|
-
* Mint tokens from
|
|
2097
|
+
* Mint tokens from registered SPL mint account to a compressed account
|
|
2065
2098
|
*/
|
|
2066
2099
|
static async approveAndMintTo(params) {
|
|
2067
|
-
const {
|
|
2068
|
-
mint,
|
|
2069
|
-
feePayer,
|
|
2070
|
-
authorityTokenAccount,
|
|
2071
|
-
authority,
|
|
2072
|
-
merkleTree,
|
|
2073
|
-
toPubkey,
|
|
2074
|
-
} = params;
|
|
2100
|
+
const { mint, feePayer, authorityTokenAccount, authority, merkleTree, toPubkey, tokenProgramId, } = params;
|
|
2075
2101
|
const amount = BigInt(params.amount.toString());
|
|
2076
2102
|
/// 1. Mint to existing ATA of mintAuthority.
|
|
2077
|
-
const splMintToInstruction = splToken.createMintToInstruction(
|
|
2078
|
-
mint,
|
|
2079
|
-
authorityTokenAccount,
|
|
2080
|
-
authority,
|
|
2081
|
-
amount,
|
|
2082
|
-
);
|
|
2103
|
+
const splMintToInstruction = splToken.createMintToInstruction(mint, authorityTokenAccount, authority, amount, [], tokenProgramId);
|
|
2083
2104
|
/// 2. Compress from mint authority ATA to recipient compressed account
|
|
2084
2105
|
const compressInstruction = await this.compress({
|
|
2085
2106
|
payer: feePayer,
|
|
@@ -2089,6 +2110,7 @@ class CompressedTokenProgram {
|
|
|
2089
2110
|
mint,
|
|
2090
2111
|
amount: params.amount,
|
|
2091
2112
|
outputStateTree: merkleTree,
|
|
2113
|
+
tokenProgramId,
|
|
2092
2114
|
});
|
|
2093
2115
|
return [splMintToInstruction, compressInstruction];
|
|
2094
2116
|
}
|
|
@@ -2096,33 +2118,15 @@ class CompressedTokenProgram {
|
|
|
2096
2118
|
* Construct transfer instruction for compressed tokens
|
|
2097
2119
|
*/
|
|
2098
2120
|
static async transfer(params) {
|
|
2099
|
-
const {
|
|
2100
|
-
|
|
2101
|
-
|
|
2102
|
-
recentInputStateRootIndices,
|
|
2103
|
-
recentValidityProof,
|
|
2104
|
-
amount,
|
|
2105
|
-
outputStateTrees,
|
|
2106
|
-
toAddress,
|
|
2107
|
-
} = params;
|
|
2108
|
-
const tokenTransferOutputs = createTransferOutputState(
|
|
2109
|
-
inputCompressedTokenAccounts,
|
|
2110
|
-
toAddress,
|
|
2111
|
-
amount,
|
|
2112
|
-
);
|
|
2113
|
-
const {
|
|
2114
|
-
inputTokenDataWithContext,
|
|
2115
|
-
packedOutputTokenData,
|
|
2116
|
-
remainingAccountMetas,
|
|
2117
|
-
} = packCompressedTokenAccounts({
|
|
2121
|
+
const { payer, inputCompressedTokenAccounts, recentInputStateRootIndices, recentValidityProof, amount, outputStateTrees, toAddress, } = params;
|
|
2122
|
+
const tokenTransferOutputs = createTransferOutputState(inputCompressedTokenAccounts, toAddress, amount);
|
|
2123
|
+
const { inputTokenDataWithContext, packedOutputTokenData, remainingAccountMetas, } = packCompressedTokenAccounts({
|
|
2118
2124
|
inputCompressedTokenAccounts,
|
|
2119
2125
|
outputStateTrees,
|
|
2120
2126
|
rootIndices: recentInputStateRootIndices,
|
|
2121
2127
|
tokenTransferOutputs,
|
|
2122
2128
|
});
|
|
2123
|
-
const { mint, currentOwner } = parseTokenData(
|
|
2124
|
-
inputCompressedTokenAccounts,
|
|
2125
|
-
);
|
|
2129
|
+
const { mint, currentOwner } = parseTokenData(inputCompressedTokenAccounts);
|
|
2126
2130
|
const data = {
|
|
2127
2131
|
proof: recentValidityProof,
|
|
2128
2132
|
mint,
|
|
@@ -2134,32 +2138,24 @@ class CompressedTokenProgram {
|
|
|
2134
2138
|
cpiContext: null,
|
|
2135
2139
|
lamportsChangeAccountMerkleTreeIndex: null,
|
|
2136
2140
|
};
|
|
2137
|
-
const encodedData = this.program.coder.types.encode(
|
|
2138
|
-
|
|
2139
|
-
data,
|
|
2140
|
-
);
|
|
2141
|
-
const {
|
|
2142
|
-
accountCompressionAuthority,
|
|
2143
|
-
noopProgram,
|
|
2144
|
-
registeredProgramPda,
|
|
2145
|
-
accountCompressionProgram,
|
|
2146
|
-
} = stateless_js.defaultStaticAccountsStruct();
|
|
2141
|
+
const encodedData = this.program.coder.types.encode('CompressedTokenInstructionDataTransfer', data);
|
|
2142
|
+
const { accountCompressionAuthority, noopProgram, registeredProgramPda, accountCompressionProgram, } = stateless_js.defaultStaticAccountsStruct();
|
|
2147
2143
|
const instruction = await this.program.methods
|
|
2148
2144
|
.transfer(encodedData)
|
|
2149
2145
|
.accounts({
|
|
2150
|
-
|
|
2151
|
-
|
|
2152
|
-
|
|
2153
|
-
|
|
2154
|
-
|
|
2155
|
-
|
|
2156
|
-
|
|
2157
|
-
|
|
2158
|
-
|
|
2159
|
-
|
|
2160
|
-
|
|
2161
|
-
|
|
2162
|
-
|
|
2146
|
+
feePayer: payer,
|
|
2147
|
+
authority: currentOwner,
|
|
2148
|
+
cpiAuthorityPda: this.deriveCpiAuthorityPda,
|
|
2149
|
+
lightSystemProgram: stateless_js.LightSystemProgram.programId,
|
|
2150
|
+
registeredProgramPda: registeredProgramPda,
|
|
2151
|
+
noopProgram: noopProgram,
|
|
2152
|
+
accountCompressionAuthority: accountCompressionAuthority,
|
|
2153
|
+
accountCompressionProgram: accountCompressionProgram,
|
|
2154
|
+
selfProgram: this.programId,
|
|
2155
|
+
tokenPoolPda: null,
|
|
2156
|
+
compressOrDecompressTokenAccount: null,
|
|
2157
|
+
tokenProgram: null,
|
|
2158
|
+
})
|
|
2163
2159
|
.remainingAccounts(remainingAccountMetas)
|
|
2164
2160
|
.instruction();
|
|
2165
2161
|
return instruction;
|
|
@@ -2168,14 +2164,12 @@ class CompressedTokenProgram {
|
|
|
2168
2164
|
* Create lookup table instructions for the token program's default accounts.
|
|
2169
2165
|
*/
|
|
2170
2166
|
static async createTokenProgramLookupTable(params) {
|
|
2171
|
-
const { authority, mints, recentSlot, payer, remainingAccounts } =
|
|
2172
|
-
|
|
2173
|
-
|
|
2174
|
-
|
|
2175
|
-
|
|
2176
|
-
|
|
2177
|
-
recentSlot,
|
|
2178
|
-
});
|
|
2167
|
+
const { authority, mints, recentSlot, payer, remainingAccounts } = params;
|
|
2168
|
+
const [createInstruction, lookupTableAddress] = web3_js.AddressLookupTableProgram.createLookupTable({
|
|
2169
|
+
authority,
|
|
2170
|
+
payer: authority,
|
|
2171
|
+
recentSlot,
|
|
2172
|
+
});
|
|
2179
2173
|
let optionalMintKeys = [];
|
|
2180
2174
|
if (mints) {
|
|
2181
2175
|
optionalMintKeys = [
|
|
@@ -2183,35 +2177,29 @@ class CompressedTokenProgram {
|
|
|
2183
2177
|
...mints.map(mint => this.deriveTokenPoolPda(mint)),
|
|
2184
2178
|
];
|
|
2185
2179
|
}
|
|
2186
|
-
const extendInstruction =
|
|
2187
|
-
|
|
2188
|
-
|
|
2180
|
+
const extendInstruction = web3_js.AddressLookupTableProgram.extendLookupTable({
|
|
2181
|
+
payer,
|
|
2182
|
+
authority,
|
|
2183
|
+
lookupTable: lookupTableAddress,
|
|
2184
|
+
addresses: [
|
|
2185
|
+
this.deriveCpiAuthorityPda,
|
|
2186
|
+
stateless_js.LightSystemProgram.programId,
|
|
2187
|
+
stateless_js.defaultStaticAccountsStruct().registeredProgramPda,
|
|
2188
|
+
stateless_js.defaultStaticAccountsStruct().noopProgram,
|
|
2189
|
+
stateless_js.defaultStaticAccountsStruct().accountCompressionAuthority,
|
|
2190
|
+
stateless_js.defaultStaticAccountsStruct().accountCompressionProgram,
|
|
2191
|
+
stateless_js.defaultTestStateTreeAccounts().merkleTree,
|
|
2192
|
+
stateless_js.defaultTestStateTreeAccounts().nullifierQueue,
|
|
2193
|
+
stateless_js.defaultTestStateTreeAccounts().addressTree,
|
|
2194
|
+
stateless_js.defaultTestStateTreeAccounts().addressQueue,
|
|
2195
|
+
this.programId,
|
|
2196
|
+
splToken.TOKEN_PROGRAM_ID,
|
|
2197
|
+
splToken.TOKEN_2022_PROGRAM_ID,
|
|
2189
2198
|
authority,
|
|
2190
|
-
|
|
2191
|
-
|
|
2192
|
-
|
|
2193
|
-
|
|
2194
|
-
stateless_js.defaultStaticAccountsStruct()
|
|
2195
|
-
.registeredProgramPda,
|
|
2196
|
-
stateless_js.defaultStaticAccountsStruct().noopProgram,
|
|
2197
|
-
stateless_js.defaultStaticAccountsStruct()
|
|
2198
|
-
.accountCompressionAuthority,
|
|
2199
|
-
stateless_js.defaultStaticAccountsStruct()
|
|
2200
|
-
.accountCompressionProgram,
|
|
2201
|
-
stateless_js.defaultTestStateTreeAccounts().merkleTree,
|
|
2202
|
-
stateless_js.defaultTestStateTreeAccounts().nullifierQueue,
|
|
2203
|
-
stateless_js.defaultTestStateTreeAccounts().addressTree,
|
|
2204
|
-
stateless_js.defaultTestStateTreeAccounts().addressQueue,
|
|
2205
|
-
this.programId,
|
|
2206
|
-
splToken.TOKEN_PROGRAM_ID,
|
|
2207
|
-
authority,
|
|
2208
|
-
...optionalMintKeys,
|
|
2209
|
-
...(remainingAccounts !== null &&
|
|
2210
|
-
remainingAccounts !== void 0
|
|
2211
|
-
? remainingAccounts
|
|
2212
|
-
: []),
|
|
2213
|
-
],
|
|
2214
|
-
});
|
|
2199
|
+
...optionalMintKeys,
|
|
2200
|
+
...(remainingAccounts !== null && remainingAccounts !== void 0 ? remainingAccounts : []),
|
|
2201
|
+
],
|
|
2202
|
+
});
|
|
2215
2203
|
return {
|
|
2216
2204
|
instructions: [createInstruction, extendInstruction],
|
|
2217
2205
|
address: lookupTableAddress,
|
|
@@ -2222,19 +2210,14 @@ class CompressedTokenProgram {
|
|
|
2222
2210
|
* @returns compressInstruction
|
|
2223
2211
|
*/
|
|
2224
2212
|
static async compress(params) {
|
|
2225
|
-
const { payer, owner, source, toAddress, mint, outputStateTree } =
|
|
2226
|
-
params;
|
|
2213
|
+
const { payer, owner, source, toAddress, mint, outputStateTree, tokenProgramId, } = params;
|
|
2227
2214
|
if (Array.isArray(params.amount) !== Array.isArray(params.toAddress)) {
|
|
2228
|
-
throw new Error(
|
|
2229
|
-
'Both amount and toAddress must be arrays or both must be single values',
|
|
2230
|
-
);
|
|
2215
|
+
throw new Error('Both amount and toAddress must be arrays or both must be single values');
|
|
2231
2216
|
}
|
|
2232
2217
|
let tokenTransferOutputs;
|
|
2233
2218
|
if (Array.isArray(params.amount) && Array.isArray(params.toAddress)) {
|
|
2234
2219
|
if (params.amount.length !== params.toAddress.length) {
|
|
2235
|
-
throw new Error(
|
|
2236
|
-
'Amount and toAddress arrays must have the same length',
|
|
2237
|
-
);
|
|
2220
|
+
throw new Error('Amount and toAddress arrays must have the same length');
|
|
2238
2221
|
}
|
|
2239
2222
|
tokenTransferOutputs = params.amount.map((amt, index) => {
|
|
2240
2223
|
const amount = stateless_js.bn(amt);
|
|
@@ -2245,7 +2228,8 @@ class CompressedTokenProgram {
|
|
|
2245
2228
|
tlv: null,
|
|
2246
2229
|
};
|
|
2247
2230
|
});
|
|
2248
|
-
}
|
|
2231
|
+
}
|
|
2232
|
+
else {
|
|
2249
2233
|
tokenTransferOutputs = [
|
|
2250
2234
|
{
|
|
2251
2235
|
owner: toAddress,
|
|
@@ -2255,11 +2239,7 @@ class CompressedTokenProgram {
|
|
|
2255
2239
|
},
|
|
2256
2240
|
];
|
|
2257
2241
|
}
|
|
2258
|
-
const {
|
|
2259
|
-
inputTokenDataWithContext,
|
|
2260
|
-
packedOutputTokenData,
|
|
2261
|
-
remainingAccountMetas,
|
|
2262
|
-
} = packCompressedTokenAccounts({
|
|
2242
|
+
const { inputTokenDataWithContext, packedOutputTokenData, remainingAccountMetas, } = packCompressedTokenAccounts({
|
|
2263
2243
|
inputCompressedTokenAccounts: [],
|
|
2264
2244
|
outputStateTrees: outputStateTree,
|
|
2265
2245
|
rootIndices: [],
|
|
@@ -2273,40 +2253,31 @@ class CompressedTokenProgram {
|
|
|
2273
2253
|
outputCompressedAccounts: packedOutputTokenData,
|
|
2274
2254
|
compressOrDecompressAmount: Array.isArray(params.amount)
|
|
2275
2255
|
? params.amount
|
|
2276
|
-
|
|
2277
|
-
|
|
2256
|
+
.map(amt => new anchor.BN(amt))
|
|
2257
|
+
.reduce((sum, amt) => sum.add(amt), new anchor.BN(0))
|
|
2278
2258
|
: new anchor.BN(params.amount),
|
|
2279
2259
|
isCompress: true,
|
|
2280
2260
|
cpiContext: null,
|
|
2281
2261
|
lamportsChangeAccountMerkleTreeIndex: null,
|
|
2282
2262
|
};
|
|
2283
|
-
const encodedData = this.program.coder.types.encode(
|
|
2284
|
-
|
|
2285
|
-
data,
|
|
2286
|
-
);
|
|
2263
|
+
const encodedData = this.program.coder.types.encode('CompressedTokenInstructionDataTransfer', data);
|
|
2264
|
+
const tokenProgram = tokenProgramId !== null && tokenProgramId !== void 0 ? tokenProgramId : splToken.TOKEN_PROGRAM_ID;
|
|
2287
2265
|
const instruction = await this.program.methods
|
|
2288
2266
|
.transfer(encodedData)
|
|
2289
2267
|
.accounts({
|
|
2290
|
-
|
|
2291
|
-
|
|
2292
|
-
|
|
2293
|
-
|
|
2294
|
-
|
|
2295
|
-
|
|
2296
|
-
|
|
2297
|
-
|
|
2298
|
-
|
|
2299
|
-
|
|
2300
|
-
|
|
2301
|
-
|
|
2302
|
-
|
|
2303
|
-
stateless_js.defaultStaticAccountsStruct()
|
|
2304
|
-
.accountCompressionProgram,
|
|
2305
|
-
selfProgram: this.programId,
|
|
2306
|
-
tokenPoolPda: this.deriveTokenPoolPda(mint),
|
|
2307
|
-
compressOrDecompressTokenAccount: source, // token
|
|
2308
|
-
tokenProgram: splToken.TOKEN_PROGRAM_ID,
|
|
2309
|
-
})
|
|
2268
|
+
feePayer: payer,
|
|
2269
|
+
authority: owner,
|
|
2270
|
+
cpiAuthorityPda: this.deriveCpiAuthorityPda,
|
|
2271
|
+
lightSystemProgram: stateless_js.LightSystemProgram.programId,
|
|
2272
|
+
registeredProgramPda: stateless_js.defaultStaticAccountsStruct().registeredProgramPda,
|
|
2273
|
+
noopProgram: stateless_js.defaultStaticAccountsStruct().noopProgram,
|
|
2274
|
+
accountCompressionAuthority: stateless_js.defaultStaticAccountsStruct().accountCompressionAuthority,
|
|
2275
|
+
accountCompressionProgram: stateless_js.defaultStaticAccountsStruct().accountCompressionProgram,
|
|
2276
|
+
selfProgram: this.programId,
|
|
2277
|
+
tokenPoolPda: this.deriveTokenPoolPda(mint),
|
|
2278
|
+
compressOrDecompressTokenAccount: source, // token
|
|
2279
|
+
tokenProgram,
|
|
2280
|
+
})
|
|
2310
2281
|
.remainingAccounts(remainingAccountMetas)
|
|
2311
2282
|
.instruction();
|
|
2312
2283
|
return instruction;
|
|
@@ -2315,33 +2286,17 @@ class CompressedTokenProgram {
|
|
|
2315
2286
|
* Construct decompress instruction
|
|
2316
2287
|
*/
|
|
2317
2288
|
static async decompress(params) {
|
|
2318
|
-
const {
|
|
2319
|
-
payer,
|
|
2320
|
-
inputCompressedTokenAccounts,
|
|
2321
|
-
toAddress,
|
|
2322
|
-
outputStateTree,
|
|
2323
|
-
recentValidityProof,
|
|
2324
|
-
recentInputStateRootIndices,
|
|
2325
|
-
} = params;
|
|
2289
|
+
const { payer, inputCompressedTokenAccounts, toAddress, outputStateTree, recentValidityProof, recentInputStateRootIndices, tokenProgramId, } = params;
|
|
2326
2290
|
const amount = stateless_js.bn(params.amount);
|
|
2327
|
-
const tokenTransferOutputs = createDecompressOutputState(
|
|
2328
|
-
inputCompressedTokenAccounts,
|
|
2329
|
-
amount,
|
|
2330
|
-
);
|
|
2291
|
+
const tokenTransferOutputs = createDecompressOutputState(inputCompressedTokenAccounts, amount);
|
|
2331
2292
|
/// Pack
|
|
2332
|
-
const {
|
|
2333
|
-
inputTokenDataWithContext,
|
|
2334
|
-
packedOutputTokenData,
|
|
2335
|
-
remainingAccountMetas,
|
|
2336
|
-
} = packCompressedTokenAccounts({
|
|
2293
|
+
const { inputTokenDataWithContext, packedOutputTokenData, remainingAccountMetas, } = packCompressedTokenAccounts({
|
|
2337
2294
|
inputCompressedTokenAccounts,
|
|
2338
2295
|
outputStateTrees: outputStateTree,
|
|
2339
2296
|
rootIndices: recentInputStateRootIndices,
|
|
2340
2297
|
tokenTransferOutputs: tokenTransferOutputs,
|
|
2341
2298
|
});
|
|
2342
|
-
const { mint, currentOwner } = parseTokenData(
|
|
2343
|
-
inputCompressedTokenAccounts,
|
|
2344
|
-
);
|
|
2299
|
+
const { mint, currentOwner } = parseTokenData(inputCompressedTokenAccounts);
|
|
2345
2300
|
const data = {
|
|
2346
2301
|
proof: recentValidityProof,
|
|
2347
2302
|
mint,
|
|
@@ -2353,45 +2308,31 @@ class CompressedTokenProgram {
|
|
|
2353
2308
|
cpiContext: null,
|
|
2354
2309
|
lamportsChangeAccountMerkleTreeIndex: null,
|
|
2355
2310
|
};
|
|
2356
|
-
const encodedData = this.program.coder.types.encode(
|
|
2357
|
-
|
|
2358
|
-
|
|
2359
|
-
);
|
|
2360
|
-
const {
|
|
2361
|
-
accountCompressionAuthority,
|
|
2362
|
-
noopProgram,
|
|
2363
|
-
registeredProgramPda,
|
|
2364
|
-
accountCompressionProgram,
|
|
2365
|
-
} = stateless_js.defaultStaticAccountsStruct();
|
|
2311
|
+
const encodedData = this.program.coder.types.encode('CompressedTokenInstructionDataTransfer', data);
|
|
2312
|
+
const { accountCompressionAuthority, noopProgram, registeredProgramPda, accountCompressionProgram, } = stateless_js.defaultStaticAccountsStruct();
|
|
2313
|
+
const tokenProgram = tokenProgramId !== null && tokenProgramId !== void 0 ? tokenProgramId : splToken.TOKEN_PROGRAM_ID;
|
|
2366
2314
|
const instruction = await this.program.methods
|
|
2367
2315
|
.transfer(encodedData)
|
|
2368
2316
|
.accounts({
|
|
2369
|
-
|
|
2370
|
-
|
|
2371
|
-
|
|
2372
|
-
|
|
2373
|
-
|
|
2374
|
-
|
|
2375
|
-
|
|
2376
|
-
|
|
2377
|
-
|
|
2378
|
-
|
|
2379
|
-
|
|
2380
|
-
|
|
2381
|
-
|
|
2317
|
+
feePayer: payer,
|
|
2318
|
+
authority: currentOwner,
|
|
2319
|
+
cpiAuthorityPda: this.deriveCpiAuthorityPda,
|
|
2320
|
+
lightSystemProgram: stateless_js.LightSystemProgram.programId,
|
|
2321
|
+
registeredProgramPda: registeredProgramPda,
|
|
2322
|
+
noopProgram: noopProgram,
|
|
2323
|
+
accountCompressionAuthority: accountCompressionAuthority,
|
|
2324
|
+
accountCompressionProgram: accountCompressionProgram,
|
|
2325
|
+
selfProgram: this.programId,
|
|
2326
|
+
tokenPoolPda: this.deriveTokenPoolPda(mint),
|
|
2327
|
+
compressOrDecompressTokenAccount: toAddress,
|
|
2328
|
+
tokenProgram,
|
|
2329
|
+
})
|
|
2382
2330
|
.remainingAccounts(remainingAccountMetas)
|
|
2383
2331
|
.instruction();
|
|
2384
2332
|
return instruction;
|
|
2385
2333
|
}
|
|
2386
2334
|
static async mergeTokenAccounts(params) {
|
|
2387
|
-
const {
|
|
2388
|
-
payer,
|
|
2389
|
-
owner,
|
|
2390
|
-
inputCompressedTokenAccounts,
|
|
2391
|
-
outputStateTree,
|
|
2392
|
-
recentValidityProof,
|
|
2393
|
-
recentInputStateRootIndices,
|
|
2394
|
-
} = params;
|
|
2335
|
+
const { payer, owner, inputCompressedTokenAccounts, outputStateTree, recentValidityProof, recentInputStateRootIndices, } = params;
|
|
2395
2336
|
if (inputCompressedTokenAccounts.length > 3) {
|
|
2396
2337
|
throw new Error('Cannot merge more than 3 token accounts at once');
|
|
2397
2338
|
}
|
|
@@ -2399,10 +2340,7 @@ class CompressedTokenProgram {
|
|
|
2399
2340
|
payer,
|
|
2400
2341
|
inputCompressedTokenAccounts,
|
|
2401
2342
|
toAddress: owner,
|
|
2402
|
-
amount: inputCompressedTokenAccounts.reduce(
|
|
2403
|
-
(sum, account) => sum.add(account.parsed.amount),
|
|
2404
|
-
new anchor.BN(0),
|
|
2405
|
-
),
|
|
2343
|
+
amount: inputCompressedTokenAccounts.reduce((sum, account) => sum.add(account.parsed.amount), new anchor.BN(0)),
|
|
2406
2344
|
outputStateTrees: outputStateTree,
|
|
2407
2345
|
recentInputStateRootIndices,
|
|
2408
2346
|
recentValidityProof,
|
|
@@ -2410,14 +2348,8 @@ class CompressedTokenProgram {
|
|
|
2410
2348
|
return [ix];
|
|
2411
2349
|
}
|
|
2412
2350
|
static async compressSplTokenAccount(params) {
|
|
2413
|
-
const {
|
|
2414
|
-
|
|
2415
|
-
authority,
|
|
2416
|
-
tokenAccount,
|
|
2417
|
-
mint,
|
|
2418
|
-
remainingAmount,
|
|
2419
|
-
outputStateTree,
|
|
2420
|
-
} = params;
|
|
2351
|
+
const { feePayer, authority, tokenAccount, mint, remainingAmount, outputStateTree, tokenProgramId, } = params;
|
|
2352
|
+
const tokenProgram = tokenProgramId !== null && tokenProgramId !== void 0 ? tokenProgramId : splToken.TOKEN_PROGRAM_ID;
|
|
2421
2353
|
const remainingAccountMetas = [
|
|
2422
2354
|
{
|
|
2423
2355
|
pubkey: outputStateTree,
|
|
@@ -2426,46 +2358,35 @@ class CompressedTokenProgram {
|
|
|
2426
2358
|
},
|
|
2427
2359
|
];
|
|
2428
2360
|
const instruction = await this.program.methods
|
|
2429
|
-
.compressSplTokenAccount(
|
|
2430
|
-
authority,
|
|
2431
|
-
remainingAmount !== null && remainingAmount !== void 0
|
|
2432
|
-
? remainingAmount
|
|
2433
|
-
: null,
|
|
2434
|
-
null,
|
|
2435
|
-
)
|
|
2361
|
+
.compressSplTokenAccount(authority, remainingAmount !== null && remainingAmount !== void 0 ? remainingAmount : null, null)
|
|
2436
2362
|
.accounts({
|
|
2437
|
-
|
|
2438
|
-
|
|
2439
|
-
|
|
2440
|
-
|
|
2441
|
-
|
|
2442
|
-
|
|
2443
|
-
|
|
2444
|
-
|
|
2445
|
-
|
|
2446
|
-
|
|
2447
|
-
|
|
2448
|
-
|
|
2449
|
-
|
|
2450
|
-
|
|
2451
|
-
.accountCompressionProgram,
|
|
2452
|
-
selfProgram: this.programId,
|
|
2453
|
-
tokenPoolPda: this.deriveTokenPoolPda(mint),
|
|
2454
|
-
compressOrDecompressTokenAccount: tokenAccount,
|
|
2455
|
-
tokenProgram: splToken.TOKEN_PROGRAM_ID,
|
|
2456
|
-
systemProgram: web3_js.SystemProgram.programId,
|
|
2457
|
-
})
|
|
2363
|
+
feePayer,
|
|
2364
|
+
authority,
|
|
2365
|
+
cpiAuthorityPda: this.deriveCpiAuthorityPda,
|
|
2366
|
+
lightSystemProgram: stateless_js.LightSystemProgram.programId,
|
|
2367
|
+
registeredProgramPda: stateless_js.defaultStaticAccountsStruct().registeredProgramPda,
|
|
2368
|
+
noopProgram: stateless_js.defaultStaticAccountsStruct().noopProgram,
|
|
2369
|
+
accountCompressionAuthority: stateless_js.defaultStaticAccountsStruct().accountCompressionAuthority,
|
|
2370
|
+
accountCompressionProgram: stateless_js.defaultStaticAccountsStruct().accountCompressionProgram,
|
|
2371
|
+
selfProgram: this.programId,
|
|
2372
|
+
tokenPoolPda: this.deriveTokenPoolPda(mint),
|
|
2373
|
+
compressOrDecompressTokenAccount: tokenAccount,
|
|
2374
|
+
tokenProgram,
|
|
2375
|
+
systemProgram: web3_js.SystemProgram.programId,
|
|
2376
|
+
})
|
|
2458
2377
|
.remainingAccounts(remainingAccountMetas)
|
|
2459
2378
|
.instruction();
|
|
2460
2379
|
return instruction;
|
|
2461
2380
|
}
|
|
2381
|
+
static async get_mint_program_id(mint, connection) {
|
|
2382
|
+
var _a;
|
|
2383
|
+
return (_a = (await connection.getAccountInfo(mint))) === null || _a === void 0 ? void 0 : _a.owner;
|
|
2384
|
+
}
|
|
2462
2385
|
}
|
|
2463
2386
|
/**
|
|
2464
2387
|
* Public key that identifies the CompressedPda program
|
|
2465
2388
|
*/
|
|
2466
|
-
CompressedTokenProgram.programId = new web3_js.PublicKey(
|
|
2467
|
-
'cTokenmWW8bLPjZEBAUgYy3zKxQZW6VKi7bqNFEVv3m',
|
|
2468
|
-
);
|
|
2389
|
+
CompressedTokenProgram.programId = new web3_js.PublicKey('cTokenmWW8bLPjZEBAUgYy3zKxQZW6VKi7bqNFEVv3m');
|
|
2469
2390
|
CompressedTokenProgram._program = null;
|
|
2470
2391
|
|
|
2471
2392
|
/**
|
|
@@ -2483,23 +2404,11 @@ CompressedTokenProgram._program = null;
|
|
|
2483
2404
|
*
|
|
2484
2405
|
* @return Signature of the confirmed transaction
|
|
2485
2406
|
*/
|
|
2486
|
-
async function approveAndMintTo(
|
|
2487
|
-
|
|
2488
|
-
|
|
2489
|
-
|
|
2490
|
-
|
|
2491
|
-
authority,
|
|
2492
|
-
amount,
|
|
2493
|
-
merkleTree,
|
|
2494
|
-
confirmOptions,
|
|
2495
|
-
) {
|
|
2496
|
-
const authorityTokenAccount =
|
|
2497
|
-
await splToken.getOrCreateAssociatedTokenAccount(
|
|
2498
|
-
rpc,
|
|
2499
|
-
payer,
|
|
2500
|
-
mint,
|
|
2501
|
-
authority.publicKey,
|
|
2502
|
-
);
|
|
2407
|
+
async function approveAndMintTo(rpc, payer, mint, destination, authority, amount, merkleTree, confirmOptions, tokenProgramId) {
|
|
2408
|
+
tokenProgramId = tokenProgramId
|
|
2409
|
+
? tokenProgramId
|
|
2410
|
+
: await CompressedTokenProgram.get_mint_program_id(mint, rpc);
|
|
2411
|
+
const authorityTokenAccount = await splToken.getOrCreateAssociatedTokenAccount(rpc, payer, mint, authority.publicKey, undefined, undefined, confirmOptions, tokenProgramId);
|
|
2503
2412
|
const ixs = await CompressedTokenProgram.approveAndMintTo({
|
|
2504
2413
|
feePayer: payer.publicKey,
|
|
2505
2414
|
mint,
|
|
@@ -2508,20 +2417,14 @@ async function approveAndMintTo(
|
|
|
2508
2417
|
amount,
|
|
2509
2418
|
toPubkey: destination,
|
|
2510
2419
|
merkleTree,
|
|
2420
|
+
tokenProgramId,
|
|
2511
2421
|
});
|
|
2512
2422
|
const { blockhash } = await rpc.getLatestBlockhash();
|
|
2513
2423
|
const additionalSigners = stateless_js.dedupeSigner(payer, [authority]);
|
|
2514
|
-
const tx = stateless_js.buildAndSignTx(
|
|
2515
|
-
|
|
2516
|
-
|
|
2517
|
-
|
|
2518
|
-
}),
|
|
2519
|
-
...ixs,
|
|
2520
|
-
],
|
|
2521
|
-
payer,
|
|
2522
|
-
blockhash,
|
|
2523
|
-
additionalSigners,
|
|
2524
|
-
);
|
|
2424
|
+
const tx = stateless_js.buildAndSignTx([
|
|
2425
|
+
web3_js.ComputeBudgetProgram.setComputeUnitLimit({ units: 1000000 }),
|
|
2426
|
+
...ixs,
|
|
2427
|
+
], payer, blockhash, additionalSigners);
|
|
2525
2428
|
const txId = await stateless_js.sendAndConfirmTx(rpc, tx, confirmOptions);
|
|
2526
2429
|
return txId;
|
|
2527
2430
|
}
|
|
@@ -2544,17 +2447,10 @@ async function approveAndMintTo(
|
|
|
2544
2447
|
*
|
|
2545
2448
|
* @return Signature of the confirmed transaction
|
|
2546
2449
|
*/
|
|
2547
|
-
async function compress(
|
|
2548
|
-
|
|
2549
|
-
|
|
2550
|
-
|
|
2551
|
-
amount,
|
|
2552
|
-
owner,
|
|
2553
|
-
sourceTokenAccount,
|
|
2554
|
-
toAddress,
|
|
2555
|
-
merkleTree,
|
|
2556
|
-
confirmOptions,
|
|
2557
|
-
) {
|
|
2450
|
+
async function compress(rpc, payer, mint, amount, owner, sourceTokenAccount, toAddress, merkleTree, confirmOptions, tokenProgramId) {
|
|
2451
|
+
tokenProgramId = tokenProgramId
|
|
2452
|
+
? tokenProgramId
|
|
2453
|
+
: await CompressedTokenProgram.get_mint_program_id(mint, rpc);
|
|
2558
2454
|
const compressIx = await CompressedTokenProgram.compress({
|
|
2559
2455
|
payer: payer.publicKey,
|
|
2560
2456
|
owner: owner.publicKey,
|
|
@@ -2563,26 +2459,17 @@ async function compress(
|
|
|
2563
2459
|
amount,
|
|
2564
2460
|
mint,
|
|
2565
2461
|
outputStateTree: merkleTree,
|
|
2462
|
+
tokenProgramId,
|
|
2566
2463
|
});
|
|
2567
2464
|
const blockhashCtx = await rpc.getLatestBlockhash();
|
|
2568
2465
|
const additionalSigners = stateless_js.dedupeSigner(payer, [owner]);
|
|
2569
|
-
const signedTx = stateless_js.buildAndSignTx(
|
|
2570
|
-
|
|
2571
|
-
|
|
2572
|
-
|
|
2573
|
-
|
|
2574
|
-
|
|
2575
|
-
|
|
2576
|
-
payer,
|
|
2577
|
-
blockhashCtx.blockhash,
|
|
2578
|
-
additionalSigners,
|
|
2579
|
-
);
|
|
2580
|
-
const txId = await stateless_js.sendAndConfirmTx(
|
|
2581
|
-
rpc,
|
|
2582
|
-
signedTx,
|
|
2583
|
-
confirmOptions,
|
|
2584
|
-
blockhashCtx,
|
|
2585
|
-
);
|
|
2466
|
+
const signedTx = stateless_js.buildAndSignTx([
|
|
2467
|
+
web3_js.ComputeBudgetProgram.setComputeUnitLimit({
|
|
2468
|
+
units: 1000000,
|
|
2469
|
+
}),
|
|
2470
|
+
compressIx,
|
|
2471
|
+
], payer, blockhashCtx.blockhash, additionalSigners);
|
|
2472
|
+
const txId = await stateless_js.sendAndConfirmTx(rpc, signedTx, confirmOptions, blockhashCtx);
|
|
2586
2473
|
return txId;
|
|
2587
2474
|
}
|
|
2588
2475
|
|
|
@@ -2603,33 +2490,15 @@ async function compress(
|
|
|
2603
2490
|
*
|
|
2604
2491
|
* @return Signature of the confirmed transaction
|
|
2605
2492
|
*/
|
|
2606
|
-
async function transfer(
|
|
2607
|
-
|
|
2608
|
-
|
|
2609
|
-
mint,
|
|
2610
|
-
amount,
|
|
2611
|
-
owner,
|
|
2612
|
-
toAddress,
|
|
2613
|
-
/// TODO: allow multiple
|
|
2614
|
-
merkleTree,
|
|
2615
|
-
confirmOptions,
|
|
2616
|
-
) {
|
|
2493
|
+
async function transfer(rpc, payer, mint, amount, owner, toAddress,
|
|
2494
|
+
/// TODO: allow multiple
|
|
2495
|
+
merkleTree, confirmOptions) {
|
|
2617
2496
|
amount = stateless_js.bn(amount);
|
|
2618
|
-
const compressedTokenAccounts = await rpc.getCompressedTokenAccountsByOwner(
|
|
2619
|
-
|
|
2620
|
-
|
|
2621
|
-
|
|
2622
|
-
|
|
2623
|
-
);
|
|
2624
|
-
const [inputAccounts] = selectMinCompressedTokenAccountsForTransfer(
|
|
2625
|
-
compressedTokenAccounts.items,
|
|
2626
|
-
amount,
|
|
2627
|
-
);
|
|
2628
|
-
const proof = await rpc.getValidityProof(
|
|
2629
|
-
inputAccounts.map(account =>
|
|
2630
|
-
stateless_js.bn(account.compressedAccount.hash),
|
|
2631
|
-
),
|
|
2632
|
-
);
|
|
2497
|
+
const compressedTokenAccounts = await rpc.getCompressedTokenAccountsByOwner(owner.publicKey, {
|
|
2498
|
+
mint,
|
|
2499
|
+
});
|
|
2500
|
+
const [inputAccounts] = selectMinCompressedTokenAccountsForTransfer(compressedTokenAccounts.items, amount);
|
|
2501
|
+
const proof = await rpc.getValidityProof(inputAccounts.map(account => stateless_js.bn(account.compressedAccount.hash)));
|
|
2633
2502
|
const ix = await CompressedTokenProgram.transfer({
|
|
2634
2503
|
payer: payer.publicKey,
|
|
2635
2504
|
inputCompressedTokenAccounts: inputAccounts,
|
|
@@ -2641,22 +2510,8 @@ async function transfer(
|
|
|
2641
2510
|
});
|
|
2642
2511
|
const { blockhash } = await rpc.getLatestBlockhash();
|
|
2643
2512
|
const additionalSigners = stateless_js.dedupeSigner(payer, [owner]);
|
|
2644
|
-
const signedTx = stateless_js.buildAndSignTx(
|
|
2645
|
-
|
|
2646
|
-
web3_js.ComputeBudgetProgram.setComputeUnitLimit({
|
|
2647
|
-
units: 1000000,
|
|
2648
|
-
}),
|
|
2649
|
-
ix,
|
|
2650
|
-
],
|
|
2651
|
-
payer,
|
|
2652
|
-
blockhash,
|
|
2653
|
-
additionalSigners,
|
|
2654
|
-
);
|
|
2655
|
-
const txId = await stateless_js.sendAndConfirmTx(
|
|
2656
|
-
rpc,
|
|
2657
|
-
signedTx,
|
|
2658
|
-
confirmOptions,
|
|
2659
|
-
);
|
|
2513
|
+
const signedTx = stateless_js.buildAndSignTx([web3_js.ComputeBudgetProgram.setComputeUnitLimit({ units: 1000000 }), ix], payer, blockhash, additionalSigners);
|
|
2514
|
+
const txId = await stateless_js.sendAndConfirmTx(rpc, signedTx, confirmOptions);
|
|
2660
2515
|
return txId;
|
|
2661
2516
|
}
|
|
2662
2517
|
/**
|
|
@@ -2672,17 +2527,14 @@ function selectMinCompressedTokenAccountsForTransfer(accounts, transferAmount) {
|
|
|
2672
2527
|
const selectedAccounts = [];
|
|
2673
2528
|
accounts.sort((a, b) => b.parsed.amount.cmp(a.parsed.amount));
|
|
2674
2529
|
for (const account of accounts) {
|
|
2675
|
-
if (accumulatedAmount.gte(stateless_js.bn(transferAmount)))
|
|
2530
|
+
if (accumulatedAmount.gte(stateless_js.bn(transferAmount)))
|
|
2531
|
+
break;
|
|
2676
2532
|
accumulatedAmount = accumulatedAmount.add(account.parsed.amount);
|
|
2677
|
-
accumulatedLamports = accumulatedLamports.add(
|
|
2678
|
-
account.compressedAccount.lamports,
|
|
2679
|
-
);
|
|
2533
|
+
accumulatedLamports = accumulatedLamports.add(account.compressedAccount.lamports);
|
|
2680
2534
|
selectedAccounts.push(account);
|
|
2681
2535
|
}
|
|
2682
2536
|
if (accumulatedAmount.lt(stateless_js.bn(transferAmount))) {
|
|
2683
|
-
throw new Error(
|
|
2684
|
-
`Not enough balance for transfer. Required: ${transferAmount.toString()}, available: ${accumulatedAmount.toString()}`,
|
|
2685
|
-
);
|
|
2537
|
+
throw new Error(`Not enough balance for transfer. Required: ${transferAmount.toString()}, available: ${accumulatedAmount.toString()}`);
|
|
2686
2538
|
}
|
|
2687
2539
|
return [
|
|
2688
2540
|
selectedAccounts,
|
|
@@ -2709,34 +2561,19 @@ function selectMinCompressedTokenAccountsForTransfer(accounts, transferAmount) {
|
|
|
2709
2561
|
*
|
|
2710
2562
|
* @return Signature of the confirmed transaction
|
|
2711
2563
|
*/
|
|
2712
|
-
async function decompress(
|
|
2713
|
-
|
|
2714
|
-
|
|
2715
|
-
|
|
2716
|
-
|
|
2717
|
-
|
|
2718
|
-
toAddress,
|
|
2719
|
-
/// TODO: allow multiple
|
|
2720
|
-
merkleTree,
|
|
2721
|
-
confirmOptions,
|
|
2722
|
-
) {
|
|
2564
|
+
async function decompress(rpc, payer, mint, amount, owner, toAddress,
|
|
2565
|
+
/// TODO: allow multiple
|
|
2566
|
+
merkleTree, confirmOptions, tokenProgramId) {
|
|
2567
|
+
tokenProgramId = tokenProgramId
|
|
2568
|
+
? tokenProgramId
|
|
2569
|
+
: await CompressedTokenProgram.get_mint_program_id(mint, rpc);
|
|
2723
2570
|
amount = stateless_js.bn(amount);
|
|
2724
|
-
const compressedTokenAccounts = await rpc.getCompressedTokenAccountsByOwner(
|
|
2725
|
-
|
|
2726
|
-
|
|
2727
|
-
mint,
|
|
2728
|
-
},
|
|
2729
|
-
);
|
|
2571
|
+
const compressedTokenAccounts = await rpc.getCompressedTokenAccountsByOwner(owner.publicKey, {
|
|
2572
|
+
mint,
|
|
2573
|
+
});
|
|
2730
2574
|
/// TODO: consider using a different selection algorithm
|
|
2731
|
-
const [inputAccounts] = selectMinCompressedTokenAccountsForTransfer(
|
|
2732
|
-
|
|
2733
|
-
amount,
|
|
2734
|
-
);
|
|
2735
|
-
const proof = await rpc.getValidityProof(
|
|
2736
|
-
inputAccounts.map(account =>
|
|
2737
|
-
stateless_js.bn(account.compressedAccount.hash),
|
|
2738
|
-
),
|
|
2739
|
-
);
|
|
2575
|
+
const [inputAccounts] = selectMinCompressedTokenAccountsForTransfer(compressedTokenAccounts.items, amount);
|
|
2576
|
+
const proof = await rpc.getValidityProof(inputAccounts.map(account => stateless_js.bn(account.compressedAccount.hash)));
|
|
2740
2577
|
const ix = await CompressedTokenProgram.decompress({
|
|
2741
2578
|
payer: payer.publicKey,
|
|
2742
2579
|
inputCompressedTokenAccounts: inputAccounts,
|
|
@@ -2745,25 +2582,12 @@ async function decompress(
|
|
|
2745
2582
|
outputStateTree: merkleTree,
|
|
2746
2583
|
recentInputStateRootIndices: proof.rootIndices,
|
|
2747
2584
|
recentValidityProof: proof.compressedProof,
|
|
2585
|
+
tokenProgramId,
|
|
2748
2586
|
});
|
|
2749
2587
|
const { blockhash } = await rpc.getLatestBlockhash();
|
|
2750
2588
|
const additionalSigners = stateless_js.dedupeSigner(payer, [owner]);
|
|
2751
|
-
const signedTx = stateless_js.buildAndSignTx(
|
|
2752
|
-
|
|
2753
|
-
web3_js.ComputeBudgetProgram.setComputeUnitLimit({
|
|
2754
|
-
units: 1000000,
|
|
2755
|
-
}),
|
|
2756
|
-
ix,
|
|
2757
|
-
],
|
|
2758
|
-
payer,
|
|
2759
|
-
blockhash,
|
|
2760
|
-
additionalSigners,
|
|
2761
|
-
);
|
|
2762
|
-
const txId = await stateless_js.sendAndConfirmTx(
|
|
2763
|
-
rpc,
|
|
2764
|
-
signedTx,
|
|
2765
|
-
confirmOptions,
|
|
2766
|
-
);
|
|
2589
|
+
const signedTx = stateless_js.buildAndSignTx([web3_js.ComputeBudgetProgram.setComputeUnitLimit({ units: 1000000 }), ix], payer, blockhash, additionalSigners);
|
|
2590
|
+
const txId = await stateless_js.sendAndConfirmTx(rpc, signedTx, confirmOptions);
|
|
2767
2591
|
return txId;
|
|
2768
2592
|
}
|
|
2769
2593
|
|
|
@@ -2776,20 +2600,13 @@ async function decompress(
|
|
|
2776
2600
|
* @param decimals Location of the decimal place
|
|
2777
2601
|
* @param keypair Optional keypair, defaulting to a new random one
|
|
2778
2602
|
* @param confirmOptions Options for confirming the transaction
|
|
2603
|
+
* @param isToken22 Whether to create a Token 2022 mint. Defaults to false.
|
|
2779
2604
|
*
|
|
2780
2605
|
* @return Address of the new mint and the transaction signature
|
|
2781
2606
|
*/
|
|
2782
|
-
async function createMint(
|
|
2783
|
-
rpc
|
|
2784
|
-
|
|
2785
|
-
mintAuthority,
|
|
2786
|
-
decimals,
|
|
2787
|
-
keypair = web3_js.Keypair.generate(),
|
|
2788
|
-
confirmOptions,
|
|
2789
|
-
) {
|
|
2790
|
-
const rentExemptBalance = await rpc.getMinimumBalanceForRentExemption(
|
|
2791
|
-
splToken.MINT_SIZE,
|
|
2792
|
-
);
|
|
2607
|
+
async function createMint(rpc, payer, mintAuthority, decimals, keypair = web3_js.Keypair.generate(), confirmOptions, isToken22 = false) {
|
|
2608
|
+
const rentExemptBalance = await rpc.getMinimumBalanceForRentExemption(splToken.MINT_SIZE);
|
|
2609
|
+
const tokenProgramId = isToken22 ? splToken.TOKEN_2022_PROGRAM_ID : splToken.TOKEN_PROGRAM_ID;
|
|
2793
2610
|
const ixs = await CompressedTokenProgram.createMint({
|
|
2794
2611
|
feePayer: payer.publicKey,
|
|
2795
2612
|
mint: keypair.publicKey,
|
|
@@ -2797,15 +2614,11 @@ async function createMint(
|
|
|
2797
2614
|
authority: mintAuthority,
|
|
2798
2615
|
freezeAuthority: null, // TODO: add feature
|
|
2799
2616
|
rentExemptBalance,
|
|
2617
|
+
tokenProgramId,
|
|
2800
2618
|
});
|
|
2801
2619
|
const { blockhash } = await rpc.getLatestBlockhash();
|
|
2802
2620
|
const additionalSigners = stateless_js.dedupeSigner(payer, [keypair]);
|
|
2803
|
-
const tx = stateless_js.buildAndSignTx(
|
|
2804
|
-
ixs,
|
|
2805
|
-
payer,
|
|
2806
|
-
blockhash,
|
|
2807
|
-
additionalSigners,
|
|
2808
|
-
);
|
|
2621
|
+
const tx = stateless_js.buildAndSignTx(ixs, payer, blockhash, additionalSigners);
|
|
2809
2622
|
const txId = await stateless_js.sendAndConfirmTx(rpc, tx, confirmOptions);
|
|
2810
2623
|
return { mint: keypair.publicKey, transactionSignature: txId };
|
|
2811
2624
|
}
|
|
@@ -2827,16 +2640,10 @@ async function createMint(
|
|
|
2827
2640
|
*
|
|
2828
2641
|
* @return Signature of the confirmed transaction
|
|
2829
2642
|
*/
|
|
2830
|
-
async function mintTo(
|
|
2831
|
-
|
|
2832
|
-
|
|
2833
|
-
|
|
2834
|
-
destination,
|
|
2835
|
-
authority,
|
|
2836
|
-
amount,
|
|
2837
|
-
merkleTree,
|
|
2838
|
-
confirmOptions,
|
|
2839
|
-
) {
|
|
2643
|
+
async function mintTo(rpc, payer, mint, destination, authority, amount, merkleTree, confirmOptions, tokenProgramId) {
|
|
2644
|
+
tokenProgramId = tokenProgramId
|
|
2645
|
+
? tokenProgramId
|
|
2646
|
+
: await CompressedTokenProgram.get_mint_program_id(mint, rpc);
|
|
2840
2647
|
const additionalSigners = stateless_js.dedupeSigner(payer, [authority]);
|
|
2841
2648
|
const ix = await CompressedTokenProgram.mintTo({
|
|
2842
2649
|
feePayer: payer.publicKey,
|
|
@@ -2845,19 +2652,10 @@ async function mintTo(
|
|
|
2845
2652
|
amount: amount,
|
|
2846
2653
|
toPubkey: destination,
|
|
2847
2654
|
merkleTree,
|
|
2655
|
+
tokenProgramId,
|
|
2848
2656
|
});
|
|
2849
2657
|
const { blockhash } = await rpc.getLatestBlockhash();
|
|
2850
|
-
const tx = stateless_js.buildAndSignTx(
|
|
2851
|
-
[
|
|
2852
|
-
web3_js.ComputeBudgetProgram.setComputeUnitLimit({
|
|
2853
|
-
units: 1000000,
|
|
2854
|
-
}),
|
|
2855
|
-
ix,
|
|
2856
|
-
],
|
|
2857
|
-
payer,
|
|
2858
|
-
blockhash,
|
|
2859
|
-
additionalSigners,
|
|
2860
|
-
);
|
|
2658
|
+
const tx = stateless_js.buildAndSignTx([web3_js.ComputeBudgetProgram.setComputeUnitLimit({ units: 1000000 }), ix], payer, blockhash, additionalSigners);
|
|
2861
2659
|
const txId = await stateless_js.sendAndConfirmTx(rpc, tx, confirmOptions);
|
|
2862
2660
|
return txId;
|
|
2863
2661
|
}
|
|
@@ -2875,67 +2673,35 @@ async function mintTo(
|
|
|
2875
2673
|
*
|
|
2876
2674
|
* @return Array of transaction signatures
|
|
2877
2675
|
*/
|
|
2878
|
-
async function mergeTokenAccounts(
|
|
2879
|
-
rpc,
|
|
2880
|
-
payer,
|
|
2881
|
-
mint,
|
|
2882
|
-
owner,
|
|
2883
|
-
merkleTree,
|
|
2884
|
-
confirmOptions,
|
|
2885
|
-
) {
|
|
2886
|
-
const compressedTokenAccounts = await rpc.getCompressedTokenAccountsByOwner(
|
|
2887
|
-
owner.publicKey,
|
|
2888
|
-
{ mint },
|
|
2889
|
-
);
|
|
2676
|
+
async function mergeTokenAccounts(rpc, payer, mint, owner, merkleTree, confirmOptions) {
|
|
2677
|
+
const compressedTokenAccounts = await rpc.getCompressedTokenAccountsByOwner(owner.publicKey, { mint });
|
|
2890
2678
|
if (compressedTokenAccounts.items.length === 0) {
|
|
2891
|
-
throw new Error(
|
|
2892
|
-
`No compressed token accounts found for mint ${mint.toBase58()}`,
|
|
2893
|
-
);
|
|
2679
|
+
throw new Error(`No compressed token accounts found for mint ${mint.toBase58()}`);
|
|
2894
2680
|
}
|
|
2895
2681
|
if (compressedTokenAccounts.items.length >= 6) {
|
|
2896
|
-
throw new Error(
|
|
2897
|
-
`Too many compressed token accounts used for mint ${mint.toBase58()}`,
|
|
2898
|
-
);
|
|
2682
|
+
throw new Error(`Too many compressed token accounts used for mint ${mint.toBase58()}`);
|
|
2899
2683
|
}
|
|
2900
2684
|
const instructions = [
|
|
2901
2685
|
web3_js.ComputeBudgetProgram.setComputeUnitLimit({ units: 1000000 }),
|
|
2902
2686
|
];
|
|
2903
|
-
for (
|
|
2904
|
-
let i = 0;
|
|
2905
|
-
i < compressedTokenAccounts.items.slice(0, 6).length;
|
|
2906
|
-
i += 3
|
|
2907
|
-
) {
|
|
2687
|
+
for (let i = 0; i < compressedTokenAccounts.items.slice(0, 6).length; i += 3) {
|
|
2908
2688
|
const batch = compressedTokenAccounts.items.slice(i, i + 3);
|
|
2909
|
-
const proof = await rpc.getValidityProof(
|
|
2910
|
-
|
|
2911
|
-
|
|
2912
|
-
|
|
2913
|
-
|
|
2914
|
-
|
|
2915
|
-
|
|
2916
|
-
|
|
2917
|
-
|
|
2918
|
-
|
|
2919
|
-
inputCompressedTokenAccounts: batch,
|
|
2920
|
-
outputStateTree: merkleTree,
|
|
2921
|
-
recentValidityProof: proof.compressedProof,
|
|
2922
|
-
recentInputStateRootIndices: proof.rootIndices,
|
|
2923
|
-
});
|
|
2689
|
+
const proof = await rpc.getValidityProof(batch.map(account => stateless_js.bn(account.compressedAccount.hash)));
|
|
2690
|
+
const batchInstructions = await CompressedTokenProgram.mergeTokenAccounts({
|
|
2691
|
+
payer: payer.publicKey,
|
|
2692
|
+
owner: owner.publicKey,
|
|
2693
|
+
mint,
|
|
2694
|
+
inputCompressedTokenAccounts: batch,
|
|
2695
|
+
outputStateTree: merkleTree,
|
|
2696
|
+
recentValidityProof: proof.compressedProof,
|
|
2697
|
+
recentInputStateRootIndices: proof.rootIndices,
|
|
2698
|
+
});
|
|
2924
2699
|
instructions.push(...batchInstructions);
|
|
2925
2700
|
}
|
|
2926
2701
|
const { blockhash } = await rpc.getLatestBlockhash();
|
|
2927
2702
|
const additionalSigners = stateless_js.dedupeSigner(payer, [owner]);
|
|
2928
|
-
const signedTx = stateless_js.buildAndSignTx(
|
|
2929
|
-
|
|
2930
|
-
payer,
|
|
2931
|
-
blockhash,
|
|
2932
|
-
additionalSigners,
|
|
2933
|
-
);
|
|
2934
|
-
const txId = await stateless_js.sendAndConfirmTx(
|
|
2935
|
-
rpc,
|
|
2936
|
-
signedTx,
|
|
2937
|
-
confirmOptions,
|
|
2938
|
-
);
|
|
2703
|
+
const signedTx = stateless_js.buildAndSignTx(instructions, payer, blockhash, additionalSigners);
|
|
2704
|
+
const txId = await stateless_js.sendAndConfirmTx(rpc, signedTx, confirmOptions);
|
|
2939
2705
|
return txId;
|
|
2940
2706
|
}
|
|
2941
2707
|
|
|
@@ -2950,10 +2716,14 @@ async function mergeTokenAccounts(
|
|
|
2950
2716
|
*
|
|
2951
2717
|
* @return transaction signature
|
|
2952
2718
|
*/
|
|
2953
|
-
async function createTokenPool(rpc, payer,
|
|
2719
|
+
async function createTokenPool(rpc, payer, mint, confirmOptions, tokenProgramId) {
|
|
2720
|
+
tokenProgramId = tokenProgramId
|
|
2721
|
+
? tokenProgramId
|
|
2722
|
+
: await CompressedTokenProgram.get_mint_program_id(mint, rpc);
|
|
2954
2723
|
const ix = await CompressedTokenProgram.createTokenPool({
|
|
2955
2724
|
feePayer: payer.publicKey,
|
|
2956
|
-
mint
|
|
2725
|
+
mint,
|
|
2726
|
+
tokenProgramId,
|
|
2957
2727
|
});
|
|
2958
2728
|
const { blockhash } = await rpc.getLatestBlockhash();
|
|
2959
2729
|
const tx = stateless_js.buildAndSignTx([ix], payer, blockhash);
|
|
@@ -2974,50 +2744,23 @@ async function createTokenPool(rpc, payer, mintAddress, confirmOptions) {
|
|
|
2974
2744
|
*
|
|
2975
2745
|
* @return Transaction signatures and the address of the created lookup table
|
|
2976
2746
|
*/
|
|
2977
|
-
async function createTokenProgramLookupTable(
|
|
2978
|
-
rpc,
|
|
2979
|
-
payer,
|
|
2980
|
-
authority,
|
|
2981
|
-
mints,
|
|
2982
|
-
additionalAccounts,
|
|
2983
|
-
) {
|
|
2747
|
+
async function createTokenProgramLookupTable(rpc, payer, authority, mints, additionalAccounts) {
|
|
2984
2748
|
const recentSlot = await rpc.getSlot('finalized');
|
|
2985
|
-
const { instructions, address } =
|
|
2986
|
-
|
|
2987
|
-
|
|
2988
|
-
|
|
2989
|
-
|
|
2990
|
-
|
|
2991
|
-
|
|
2992
|
-
});
|
|
2749
|
+
const { instructions, address } = await CompressedTokenProgram.createTokenProgramLookupTable({
|
|
2750
|
+
payer: payer.publicKey,
|
|
2751
|
+
authority: authority.publicKey,
|
|
2752
|
+
mints,
|
|
2753
|
+
remainingAccounts: additionalAccounts,
|
|
2754
|
+
recentSlot,
|
|
2755
|
+
});
|
|
2993
2756
|
const additionalSigners = stateless_js.dedupeSigner(payer, [authority]);
|
|
2994
2757
|
const blockhashCtx = await rpc.getLatestBlockhash();
|
|
2995
|
-
const signedTx = stateless_js.buildAndSignTx(
|
|
2996
|
-
[instructions[0]],
|
|
2997
|
-
payer,
|
|
2998
|
-
blockhashCtx.blockhash,
|
|
2999
|
-
additionalSigners,
|
|
3000
|
-
);
|
|
2758
|
+
const signedTx = stateless_js.buildAndSignTx([instructions[0]], payer, blockhashCtx.blockhash, additionalSigners);
|
|
3001
2759
|
/// Must wait for the first instruction to be finalized.
|
|
3002
|
-
const txId = await stateless_js.sendAndConfirmTx(
|
|
3003
|
-
rpc,
|
|
3004
|
-
signedTx,
|
|
3005
|
-
{ commitment: 'finalized' },
|
|
3006
|
-
blockhashCtx,
|
|
3007
|
-
);
|
|
2760
|
+
const txId = await stateless_js.sendAndConfirmTx(rpc, signedTx, { commitment: 'finalized' }, blockhashCtx);
|
|
3008
2761
|
const blockhashCtx2 = await rpc.getLatestBlockhash();
|
|
3009
|
-
const signedTx2 = stateless_js.buildAndSignTx(
|
|
3010
|
-
|
|
3011
|
-
payer,
|
|
3012
|
-
blockhashCtx2.blockhash,
|
|
3013
|
-
additionalSigners,
|
|
3014
|
-
);
|
|
3015
|
-
const txId2 = await stateless_js.sendAndConfirmTx(
|
|
3016
|
-
rpc,
|
|
3017
|
-
signedTx2,
|
|
3018
|
-
{ commitment: 'finalized' },
|
|
3019
|
-
blockhashCtx2,
|
|
3020
|
-
);
|
|
2762
|
+
const signedTx2 = stateless_js.buildAndSignTx([instructions[1]], payer, blockhashCtx2.blockhash, additionalSigners);
|
|
2763
|
+
const txId2 = await stateless_js.sendAndConfirmTx(rpc, signedTx2, { commitment: 'finalized' }, blockhashCtx2);
|
|
3021
2764
|
return { txIds: [txId, txId2], address };
|
|
3022
2765
|
}
|
|
3023
2766
|
|
|
@@ -3035,16 +2778,10 @@ async function createTokenProgramLookupTable(
|
|
|
3035
2778
|
*
|
|
3036
2779
|
* @return Signature of the confirmed transaction
|
|
3037
2780
|
*/
|
|
3038
|
-
async function compressSplTokenAccount(
|
|
3039
|
-
|
|
3040
|
-
|
|
3041
|
-
|
|
3042
|
-
owner,
|
|
3043
|
-
tokenAccount,
|
|
3044
|
-
outputStateTree,
|
|
3045
|
-
remainingAmount,
|
|
3046
|
-
confirmOptions,
|
|
3047
|
-
) {
|
|
2781
|
+
async function compressSplTokenAccount(rpc, payer, mint, owner, tokenAccount, outputStateTree, remainingAmount, confirmOptions, tokenProgramId) {
|
|
2782
|
+
tokenProgramId = tokenProgramId
|
|
2783
|
+
? tokenProgramId
|
|
2784
|
+
: await CompressedTokenProgram.get_mint_program_id(mint, rpc);
|
|
3048
2785
|
const compressIx = await CompressedTokenProgram.compressSplTokenAccount({
|
|
3049
2786
|
feePayer: payer.publicKey,
|
|
3050
2787
|
authority: owner.publicKey,
|
|
@@ -3052,26 +2789,17 @@ async function compressSplTokenAccount(
|
|
|
3052
2789
|
mint,
|
|
3053
2790
|
remainingAmount,
|
|
3054
2791
|
outputStateTree,
|
|
2792
|
+
tokenProgramId,
|
|
3055
2793
|
});
|
|
3056
2794
|
const blockhashCtx = await rpc.getLatestBlockhash();
|
|
3057
2795
|
const additionalSigners = stateless_js.dedupeSigner(payer, [owner]);
|
|
3058
|
-
const signedTx = stateless_js.buildAndSignTx(
|
|
3059
|
-
|
|
3060
|
-
|
|
3061
|
-
|
|
3062
|
-
|
|
3063
|
-
|
|
3064
|
-
|
|
3065
|
-
payer,
|
|
3066
|
-
blockhashCtx.blockhash,
|
|
3067
|
-
additionalSigners,
|
|
3068
|
-
);
|
|
3069
|
-
const txId = await stateless_js.sendAndConfirmTx(
|
|
3070
|
-
rpc,
|
|
3071
|
-
signedTx,
|
|
3072
|
-
confirmOptions,
|
|
3073
|
-
blockhashCtx,
|
|
3074
|
-
);
|
|
2796
|
+
const signedTx = stateless_js.buildAndSignTx([
|
|
2797
|
+
web3_js.ComputeBudgetProgram.setComputeUnitLimit({
|
|
2798
|
+
units: 1000000,
|
|
2799
|
+
}),
|
|
2800
|
+
compressIx,
|
|
2801
|
+
], payer, blockhashCtx.blockhash, additionalSigners);
|
|
2802
|
+
const txId = await stateless_js.sendAndConfirmTx(rpc, signedTx, confirmOptions, blockhashCtx);
|
|
3075
2803
|
return txId;
|
|
3076
2804
|
}
|
|
3077
2805
|
|
|
@@ -3093,8 +2821,7 @@ exports.mergeTokenAccounts = mergeTokenAccounts;
|
|
|
3093
2821
|
exports.mintTo = mintTo;
|
|
3094
2822
|
exports.packCompressedTokenAccounts = packCompressedTokenAccounts;
|
|
3095
2823
|
exports.parseTokenData = parseTokenData;
|
|
3096
|
-
exports.selectMinCompressedTokenAccountsForTransfer =
|
|
3097
|
-
selectMinCompressedTokenAccountsForTransfer;
|
|
2824
|
+
exports.selectMinCompressedTokenAccountsForTransfer = selectMinCompressedTokenAccountsForTransfer;
|
|
3098
2825
|
exports.sumUpTokenAmount = sumUpTokenAmount;
|
|
3099
2826
|
exports.transfer = transfer;
|
|
3100
2827
|
exports.validateSameTokenOwner = validateSameTokenOwner;
|