@lightprotocol/compressed-token 0.16.0 → 0.17.1
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 +440 -706
- package/dist/cjs/browser/index.cjs.map +1 -1
- package/dist/cjs/node/index.cjs +440 -706
- package/dist/cjs/node/index.cjs.map +1 -1
- package/dist/es/browser/index.js +405 -635
- package/dist/es/browser/index.js.map +1 -1
- package/dist/types/index.d.ts +274 -279
- package/package.json +2 -2
|
@@ -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,85 +1999,70 @@ 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
|
-
* Construct createMint instruction for compressed tokens
|
|
2020
|
+
* Construct createMint instruction for compressed tokens.
|
|
2021
|
+
* @returns [createMintAccountInstruction, initializeMintInstruction, createTokenPoolInstruction]
|
|
2022
|
+
*
|
|
2023
|
+
* Note that `createTokenPoolInstruction` must be executed after `initializeMintInstruction`.
|
|
1973
2024
|
*/
|
|
1974
2025
|
static async createMint(params) {
|
|
1975
|
-
const { mint, authority, feePayer, rentExemptBalance } = params;
|
|
2026
|
+
const { mint, authority, feePayer, rentExemptBalance, tokenProgramId, freezeAuthority, mintSize, } = params;
|
|
2027
|
+
const tokenProgram = tokenProgramId !== null && tokenProgramId !== void 0 ? tokenProgramId : splToken.TOKEN_PROGRAM_ID;
|
|
1976
2028
|
/// Create and initialize SPL Mint account
|
|
1977
|
-
const createMintAccountInstruction =
|
|
1978
|
-
|
|
1979
|
-
|
|
1980
|
-
|
|
1981
|
-
|
|
1982
|
-
|
|
1983
|
-
|
|
1984
|
-
|
|
1985
|
-
const
|
|
1986
|
-
splToken.createInitializeMint2Instruction(
|
|
1987
|
-
mint,
|
|
1988
|
-
params.decimals,
|
|
1989
|
-
authority,
|
|
1990
|
-
params.freezeAuthority,
|
|
1991
|
-
splToken.TOKEN_PROGRAM_ID,
|
|
1992
|
-
);
|
|
1993
|
-
const ix = await this.createTokenPool({
|
|
2029
|
+
const createMintAccountInstruction = web3_js.SystemProgram.createAccount({
|
|
2030
|
+
fromPubkey: feePayer,
|
|
2031
|
+
lamports: rentExemptBalance,
|
|
2032
|
+
newAccountPubkey: mint,
|
|
2033
|
+
programId: tokenProgram,
|
|
2034
|
+
space: mintSize !== null && mintSize !== void 0 ? mintSize : splToken.MINT_SIZE,
|
|
2035
|
+
});
|
|
2036
|
+
const initializeMintInstruction = splToken.createInitializeMint2Instruction(mint, params.decimals, authority, freezeAuthority, tokenProgram);
|
|
2037
|
+
const createTokenPoolInstruction = await this.createTokenPool({
|
|
1994
2038
|
feePayer,
|
|
1995
2039
|
mint,
|
|
2040
|
+
tokenProgramId: tokenProgram,
|
|
1996
2041
|
});
|
|
1997
|
-
return [
|
|
2042
|
+
return [
|
|
2043
|
+
createMintAccountInstruction,
|
|
2044
|
+
initializeMintInstruction,
|
|
2045
|
+
createTokenPoolInstruction,
|
|
2046
|
+
];
|
|
1998
2047
|
}
|
|
1999
2048
|
/**
|
|
2000
2049
|
* Enable compression for an existing SPL mint, creating an omnibus account.
|
|
2001
2050
|
* For new mints, use `CompressedTokenProgram.createMint`.
|
|
2002
2051
|
*/
|
|
2003
2052
|
static async createTokenPool(params) {
|
|
2004
|
-
const { mint, feePayer } = params;
|
|
2053
|
+
const { mint, feePayer, tokenProgramId } = params;
|
|
2054
|
+
const tokenProgram = tokenProgramId !== null && tokenProgramId !== void 0 ? tokenProgramId : splToken.TOKEN_PROGRAM_ID;
|
|
2005
2055
|
const tokenPoolPda = this.deriveTokenPoolPda(mint);
|
|
2006
2056
|
const ix = await this.program.methods
|
|
2007
2057
|
.createTokenPool()
|
|
2008
2058
|
.accounts({
|
|
2009
|
-
|
|
2010
|
-
|
|
2011
|
-
|
|
2012
|
-
|
|
2013
|
-
|
|
2014
|
-
|
|
2015
|
-
|
|
2059
|
+
mint,
|
|
2060
|
+
feePayer,
|
|
2061
|
+
tokenPoolPda,
|
|
2062
|
+
systemProgram: web3_js.SystemProgram.programId,
|
|
2063
|
+
tokenProgram,
|
|
2064
|
+
cpiAuthorityPda: this.deriveCpiAuthorityPda,
|
|
2065
|
+
})
|
|
2016
2066
|
.instruction();
|
|
2017
2067
|
return ix;
|
|
2018
2068
|
}
|
|
@@ -2021,65 +2071,43 @@ class CompressedTokenProgram {
|
|
|
2021
2071
|
*/
|
|
2022
2072
|
static async mintTo(params) {
|
|
2023
2073
|
const systemKeys = stateless_js.defaultStaticAccountsStruct();
|
|
2024
|
-
const { mint, feePayer, authority, merkleTree, toPubkey, amount } =
|
|
2025
|
-
|
|
2074
|
+
const { mint, feePayer, authority, merkleTree, toPubkey, amount, tokenProgramId, } = params;
|
|
2075
|
+
const tokenProgram = tokenProgramId !== null && tokenProgramId !== void 0 ? tokenProgramId : splToken.TOKEN_PROGRAM_ID;
|
|
2026
2076
|
const tokenPoolPda = this.deriveTokenPoolPda(mint);
|
|
2027
|
-
const amounts = stateless_js
|
|
2028
|
-
.toArray(amount)
|
|
2029
|
-
.map(amount => stateless_js.bn(amount));
|
|
2077
|
+
const amounts = stateless_js.toArray(amount).map(amount => stateless_js.bn(amount));
|
|
2030
2078
|
const toPubkeys = stateless_js.toArray(toPubkey);
|
|
2031
2079
|
if (amounts.length !== toPubkeys.length) {
|
|
2032
|
-
throw new Error(
|
|
2033
|
-
'Amount and toPubkey arrays must have the same length',
|
|
2034
|
-
);
|
|
2080
|
+
throw new Error('Amount and toPubkey arrays must have the same length');
|
|
2035
2081
|
}
|
|
2036
2082
|
const instruction = await this.program.methods
|
|
2037
2083
|
.mintTo(toPubkeys, amounts, null)
|
|
2038
2084
|
.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
|
-
})
|
|
2085
|
+
feePayer,
|
|
2086
|
+
authority,
|
|
2087
|
+
cpiAuthorityPda: this.deriveCpiAuthorityPda,
|
|
2088
|
+
mint,
|
|
2089
|
+
tokenPoolPda,
|
|
2090
|
+
tokenProgram,
|
|
2091
|
+
lightSystemProgram: stateless_js.LightSystemProgram.programId,
|
|
2092
|
+
registeredProgramPda: systemKeys.registeredProgramPda,
|
|
2093
|
+
noopProgram: systemKeys.noopProgram,
|
|
2094
|
+
accountCompressionAuthority: systemKeys.accountCompressionAuthority,
|
|
2095
|
+
accountCompressionProgram: systemKeys.accountCompressionProgram,
|
|
2096
|
+
merkleTree: merkleTree !== null && merkleTree !== void 0 ? merkleTree : stateless_js.defaultTestStateTreeAccounts().merkleTree,
|
|
2097
|
+
selfProgram: this.programId,
|
|
2098
|
+
solPoolPda: null,
|
|
2099
|
+
})
|
|
2059
2100
|
.instruction();
|
|
2060
2101
|
return instruction;
|
|
2061
2102
|
}
|
|
2062
|
-
/// TODO: add compressBatch functionality for batch minting
|
|
2063
2103
|
/**
|
|
2064
|
-
* Mint tokens from
|
|
2104
|
+
* Mint tokens from registered SPL mint account to a compressed account
|
|
2065
2105
|
*/
|
|
2066
2106
|
static async approveAndMintTo(params) {
|
|
2067
|
-
const {
|
|
2068
|
-
mint,
|
|
2069
|
-
feePayer,
|
|
2070
|
-
authorityTokenAccount,
|
|
2071
|
-
authority,
|
|
2072
|
-
merkleTree,
|
|
2073
|
-
toPubkey,
|
|
2074
|
-
} = params;
|
|
2107
|
+
const { mint, feePayer, authorityTokenAccount, authority, merkleTree, toPubkey, tokenProgramId, } = params;
|
|
2075
2108
|
const amount = BigInt(params.amount.toString());
|
|
2076
2109
|
/// 1. Mint to existing ATA of mintAuthority.
|
|
2077
|
-
const splMintToInstruction = splToken.createMintToInstruction(
|
|
2078
|
-
mint,
|
|
2079
|
-
authorityTokenAccount,
|
|
2080
|
-
authority,
|
|
2081
|
-
amount,
|
|
2082
|
-
);
|
|
2110
|
+
const splMintToInstruction = splToken.createMintToInstruction(mint, authorityTokenAccount, authority, amount, [], tokenProgramId);
|
|
2083
2111
|
/// 2. Compress from mint authority ATA to recipient compressed account
|
|
2084
2112
|
const compressInstruction = await this.compress({
|
|
2085
2113
|
payer: feePayer,
|
|
@@ -2089,6 +2117,7 @@ class CompressedTokenProgram {
|
|
|
2089
2117
|
mint,
|
|
2090
2118
|
amount: params.amount,
|
|
2091
2119
|
outputStateTree: merkleTree,
|
|
2120
|
+
tokenProgramId,
|
|
2092
2121
|
});
|
|
2093
2122
|
return [splMintToInstruction, compressInstruction];
|
|
2094
2123
|
}
|
|
@@ -2096,33 +2125,15 @@ class CompressedTokenProgram {
|
|
|
2096
2125
|
* Construct transfer instruction for compressed tokens
|
|
2097
2126
|
*/
|
|
2098
2127
|
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({
|
|
2128
|
+
const { payer, inputCompressedTokenAccounts, recentInputStateRootIndices, recentValidityProof, amount, outputStateTrees, toAddress, } = params;
|
|
2129
|
+
const tokenTransferOutputs = createTransferOutputState(inputCompressedTokenAccounts, toAddress, amount);
|
|
2130
|
+
const { inputTokenDataWithContext, packedOutputTokenData, remainingAccountMetas, } = packCompressedTokenAccounts({
|
|
2118
2131
|
inputCompressedTokenAccounts,
|
|
2119
2132
|
outputStateTrees,
|
|
2120
2133
|
rootIndices: recentInputStateRootIndices,
|
|
2121
2134
|
tokenTransferOutputs,
|
|
2122
2135
|
});
|
|
2123
|
-
const { mint, currentOwner } = parseTokenData(
|
|
2124
|
-
inputCompressedTokenAccounts,
|
|
2125
|
-
);
|
|
2136
|
+
const { mint, currentOwner } = parseTokenData(inputCompressedTokenAccounts);
|
|
2126
2137
|
const data = {
|
|
2127
2138
|
proof: recentValidityProof,
|
|
2128
2139
|
mint,
|
|
@@ -2134,32 +2145,24 @@ class CompressedTokenProgram {
|
|
|
2134
2145
|
cpiContext: null,
|
|
2135
2146
|
lamportsChangeAccountMerkleTreeIndex: null,
|
|
2136
2147
|
};
|
|
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();
|
|
2148
|
+
const encodedData = this.program.coder.types.encode('CompressedTokenInstructionDataTransfer', data);
|
|
2149
|
+
const { accountCompressionAuthority, noopProgram, registeredProgramPda, accountCompressionProgram, } = stateless_js.defaultStaticAccountsStruct();
|
|
2147
2150
|
const instruction = await this.program.methods
|
|
2148
2151
|
.transfer(encodedData)
|
|
2149
2152
|
.accounts({
|
|
2150
|
-
|
|
2151
|
-
|
|
2152
|
-
|
|
2153
|
-
|
|
2154
|
-
|
|
2155
|
-
|
|
2156
|
-
|
|
2157
|
-
|
|
2158
|
-
|
|
2159
|
-
|
|
2160
|
-
|
|
2161
|
-
|
|
2162
|
-
|
|
2153
|
+
feePayer: payer,
|
|
2154
|
+
authority: currentOwner,
|
|
2155
|
+
cpiAuthorityPda: this.deriveCpiAuthorityPda,
|
|
2156
|
+
lightSystemProgram: stateless_js.LightSystemProgram.programId,
|
|
2157
|
+
registeredProgramPda: registeredProgramPda,
|
|
2158
|
+
noopProgram: noopProgram,
|
|
2159
|
+
accountCompressionAuthority: accountCompressionAuthority,
|
|
2160
|
+
accountCompressionProgram: accountCompressionProgram,
|
|
2161
|
+
selfProgram: this.programId,
|
|
2162
|
+
tokenPoolPda: null,
|
|
2163
|
+
compressOrDecompressTokenAccount: null,
|
|
2164
|
+
tokenProgram: null,
|
|
2165
|
+
})
|
|
2163
2166
|
.remainingAccounts(remainingAccountMetas)
|
|
2164
2167
|
.instruction();
|
|
2165
2168
|
return instruction;
|
|
@@ -2168,14 +2171,12 @@ class CompressedTokenProgram {
|
|
|
2168
2171
|
* Create lookup table instructions for the token program's default accounts.
|
|
2169
2172
|
*/
|
|
2170
2173
|
static async createTokenProgramLookupTable(params) {
|
|
2171
|
-
const { authority, mints, recentSlot, payer, remainingAccounts } =
|
|
2172
|
-
|
|
2173
|
-
|
|
2174
|
-
|
|
2175
|
-
|
|
2176
|
-
|
|
2177
|
-
recentSlot,
|
|
2178
|
-
});
|
|
2174
|
+
const { authority, mints, recentSlot, payer, remainingAccounts } = params;
|
|
2175
|
+
const [createInstruction, lookupTableAddress] = web3_js.AddressLookupTableProgram.createLookupTable({
|
|
2176
|
+
authority,
|
|
2177
|
+
payer: authority,
|
|
2178
|
+
recentSlot,
|
|
2179
|
+
});
|
|
2179
2180
|
let optionalMintKeys = [];
|
|
2180
2181
|
if (mints) {
|
|
2181
2182
|
optionalMintKeys = [
|
|
@@ -2183,35 +2184,29 @@ class CompressedTokenProgram {
|
|
|
2183
2184
|
...mints.map(mint => this.deriveTokenPoolPda(mint)),
|
|
2184
2185
|
];
|
|
2185
2186
|
}
|
|
2186
|
-
const extendInstruction =
|
|
2187
|
-
|
|
2188
|
-
|
|
2187
|
+
const extendInstruction = web3_js.AddressLookupTableProgram.extendLookupTable({
|
|
2188
|
+
payer,
|
|
2189
|
+
authority,
|
|
2190
|
+
lookupTable: lookupTableAddress,
|
|
2191
|
+
addresses: [
|
|
2192
|
+
this.deriveCpiAuthorityPda,
|
|
2193
|
+
stateless_js.LightSystemProgram.programId,
|
|
2194
|
+
stateless_js.defaultStaticAccountsStruct().registeredProgramPda,
|
|
2195
|
+
stateless_js.defaultStaticAccountsStruct().noopProgram,
|
|
2196
|
+
stateless_js.defaultStaticAccountsStruct().accountCompressionAuthority,
|
|
2197
|
+
stateless_js.defaultStaticAccountsStruct().accountCompressionProgram,
|
|
2198
|
+
stateless_js.defaultTestStateTreeAccounts().merkleTree,
|
|
2199
|
+
stateless_js.defaultTestStateTreeAccounts().nullifierQueue,
|
|
2200
|
+
stateless_js.defaultTestStateTreeAccounts().addressTree,
|
|
2201
|
+
stateless_js.defaultTestStateTreeAccounts().addressQueue,
|
|
2202
|
+
this.programId,
|
|
2203
|
+
splToken.TOKEN_PROGRAM_ID,
|
|
2204
|
+
splToken.TOKEN_2022_PROGRAM_ID,
|
|
2189
2205
|
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
|
-
});
|
|
2206
|
+
...optionalMintKeys,
|
|
2207
|
+
...(remainingAccounts !== null && remainingAccounts !== void 0 ? remainingAccounts : []),
|
|
2208
|
+
],
|
|
2209
|
+
});
|
|
2215
2210
|
return {
|
|
2216
2211
|
instructions: [createInstruction, extendInstruction],
|
|
2217
2212
|
address: lookupTableAddress,
|
|
@@ -2222,19 +2217,14 @@ class CompressedTokenProgram {
|
|
|
2222
2217
|
* @returns compressInstruction
|
|
2223
2218
|
*/
|
|
2224
2219
|
static async compress(params) {
|
|
2225
|
-
const { payer, owner, source, toAddress, mint, outputStateTree } =
|
|
2226
|
-
params;
|
|
2220
|
+
const { payer, owner, source, toAddress, mint, outputStateTree, tokenProgramId, } = params;
|
|
2227
2221
|
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
|
-
);
|
|
2222
|
+
throw new Error('Both amount and toAddress must be arrays or both must be single values');
|
|
2231
2223
|
}
|
|
2232
2224
|
let tokenTransferOutputs;
|
|
2233
2225
|
if (Array.isArray(params.amount) && Array.isArray(params.toAddress)) {
|
|
2234
2226
|
if (params.amount.length !== params.toAddress.length) {
|
|
2235
|
-
throw new Error(
|
|
2236
|
-
'Amount and toAddress arrays must have the same length',
|
|
2237
|
-
);
|
|
2227
|
+
throw new Error('Amount and toAddress arrays must have the same length');
|
|
2238
2228
|
}
|
|
2239
2229
|
tokenTransferOutputs = params.amount.map((amt, index) => {
|
|
2240
2230
|
const amount = stateless_js.bn(amt);
|
|
@@ -2245,7 +2235,8 @@ class CompressedTokenProgram {
|
|
|
2245
2235
|
tlv: null,
|
|
2246
2236
|
};
|
|
2247
2237
|
});
|
|
2248
|
-
}
|
|
2238
|
+
}
|
|
2239
|
+
else {
|
|
2249
2240
|
tokenTransferOutputs = [
|
|
2250
2241
|
{
|
|
2251
2242
|
owner: toAddress,
|
|
@@ -2255,11 +2246,7 @@ class CompressedTokenProgram {
|
|
|
2255
2246
|
},
|
|
2256
2247
|
];
|
|
2257
2248
|
}
|
|
2258
|
-
const {
|
|
2259
|
-
inputTokenDataWithContext,
|
|
2260
|
-
packedOutputTokenData,
|
|
2261
|
-
remainingAccountMetas,
|
|
2262
|
-
} = packCompressedTokenAccounts({
|
|
2249
|
+
const { inputTokenDataWithContext, packedOutputTokenData, remainingAccountMetas, } = packCompressedTokenAccounts({
|
|
2263
2250
|
inputCompressedTokenAccounts: [],
|
|
2264
2251
|
outputStateTrees: outputStateTree,
|
|
2265
2252
|
rootIndices: [],
|
|
@@ -2273,40 +2260,31 @@ class CompressedTokenProgram {
|
|
|
2273
2260
|
outputCompressedAccounts: packedOutputTokenData,
|
|
2274
2261
|
compressOrDecompressAmount: Array.isArray(params.amount)
|
|
2275
2262
|
? params.amount
|
|
2276
|
-
|
|
2277
|
-
|
|
2263
|
+
.map(amt => new anchor.BN(amt))
|
|
2264
|
+
.reduce((sum, amt) => sum.add(amt), new anchor.BN(0))
|
|
2278
2265
|
: new anchor.BN(params.amount),
|
|
2279
2266
|
isCompress: true,
|
|
2280
2267
|
cpiContext: null,
|
|
2281
2268
|
lamportsChangeAccountMerkleTreeIndex: null,
|
|
2282
2269
|
};
|
|
2283
|
-
const encodedData = this.program.coder.types.encode(
|
|
2284
|
-
|
|
2285
|
-
data,
|
|
2286
|
-
);
|
|
2270
|
+
const encodedData = this.program.coder.types.encode('CompressedTokenInstructionDataTransfer', data);
|
|
2271
|
+
const tokenProgram = tokenProgramId !== null && tokenProgramId !== void 0 ? tokenProgramId : splToken.TOKEN_PROGRAM_ID;
|
|
2287
2272
|
const instruction = await this.program.methods
|
|
2288
2273
|
.transfer(encodedData)
|
|
2289
2274
|
.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
|
-
})
|
|
2275
|
+
feePayer: payer,
|
|
2276
|
+
authority: owner,
|
|
2277
|
+
cpiAuthorityPda: this.deriveCpiAuthorityPda,
|
|
2278
|
+
lightSystemProgram: stateless_js.LightSystemProgram.programId,
|
|
2279
|
+
registeredProgramPda: stateless_js.defaultStaticAccountsStruct().registeredProgramPda,
|
|
2280
|
+
noopProgram: stateless_js.defaultStaticAccountsStruct().noopProgram,
|
|
2281
|
+
accountCompressionAuthority: stateless_js.defaultStaticAccountsStruct().accountCompressionAuthority,
|
|
2282
|
+
accountCompressionProgram: stateless_js.defaultStaticAccountsStruct().accountCompressionProgram,
|
|
2283
|
+
selfProgram: this.programId,
|
|
2284
|
+
tokenPoolPda: this.deriveTokenPoolPda(mint),
|
|
2285
|
+
compressOrDecompressTokenAccount: source, // token
|
|
2286
|
+
tokenProgram,
|
|
2287
|
+
})
|
|
2310
2288
|
.remainingAccounts(remainingAccountMetas)
|
|
2311
2289
|
.instruction();
|
|
2312
2290
|
return instruction;
|
|
@@ -2315,33 +2293,17 @@ class CompressedTokenProgram {
|
|
|
2315
2293
|
* Construct decompress instruction
|
|
2316
2294
|
*/
|
|
2317
2295
|
static async decompress(params) {
|
|
2318
|
-
const {
|
|
2319
|
-
payer,
|
|
2320
|
-
inputCompressedTokenAccounts,
|
|
2321
|
-
toAddress,
|
|
2322
|
-
outputStateTree,
|
|
2323
|
-
recentValidityProof,
|
|
2324
|
-
recentInputStateRootIndices,
|
|
2325
|
-
} = params;
|
|
2296
|
+
const { payer, inputCompressedTokenAccounts, toAddress, outputStateTree, recentValidityProof, recentInputStateRootIndices, tokenProgramId, } = params;
|
|
2326
2297
|
const amount = stateless_js.bn(params.amount);
|
|
2327
|
-
const tokenTransferOutputs = createDecompressOutputState(
|
|
2328
|
-
inputCompressedTokenAccounts,
|
|
2329
|
-
amount,
|
|
2330
|
-
);
|
|
2298
|
+
const tokenTransferOutputs = createDecompressOutputState(inputCompressedTokenAccounts, amount);
|
|
2331
2299
|
/// Pack
|
|
2332
|
-
const {
|
|
2333
|
-
inputTokenDataWithContext,
|
|
2334
|
-
packedOutputTokenData,
|
|
2335
|
-
remainingAccountMetas,
|
|
2336
|
-
} = packCompressedTokenAccounts({
|
|
2300
|
+
const { inputTokenDataWithContext, packedOutputTokenData, remainingAccountMetas, } = packCompressedTokenAccounts({
|
|
2337
2301
|
inputCompressedTokenAccounts,
|
|
2338
2302
|
outputStateTrees: outputStateTree,
|
|
2339
2303
|
rootIndices: recentInputStateRootIndices,
|
|
2340
2304
|
tokenTransferOutputs: tokenTransferOutputs,
|
|
2341
2305
|
});
|
|
2342
|
-
const { mint, currentOwner } = parseTokenData(
|
|
2343
|
-
inputCompressedTokenAccounts,
|
|
2344
|
-
);
|
|
2306
|
+
const { mint, currentOwner } = parseTokenData(inputCompressedTokenAccounts);
|
|
2345
2307
|
const data = {
|
|
2346
2308
|
proof: recentValidityProof,
|
|
2347
2309
|
mint,
|
|
@@ -2353,45 +2315,31 @@ class CompressedTokenProgram {
|
|
|
2353
2315
|
cpiContext: null,
|
|
2354
2316
|
lamportsChangeAccountMerkleTreeIndex: null,
|
|
2355
2317
|
};
|
|
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();
|
|
2318
|
+
const encodedData = this.program.coder.types.encode('CompressedTokenInstructionDataTransfer', data);
|
|
2319
|
+
const { accountCompressionAuthority, noopProgram, registeredProgramPda, accountCompressionProgram, } = stateless_js.defaultStaticAccountsStruct();
|
|
2320
|
+
const tokenProgram = tokenProgramId !== null && tokenProgramId !== void 0 ? tokenProgramId : splToken.TOKEN_PROGRAM_ID;
|
|
2366
2321
|
const instruction = await this.program.methods
|
|
2367
2322
|
.transfer(encodedData)
|
|
2368
2323
|
.accounts({
|
|
2369
|
-
|
|
2370
|
-
|
|
2371
|
-
|
|
2372
|
-
|
|
2373
|
-
|
|
2374
|
-
|
|
2375
|
-
|
|
2376
|
-
|
|
2377
|
-
|
|
2378
|
-
|
|
2379
|
-
|
|
2380
|
-
|
|
2381
|
-
|
|
2324
|
+
feePayer: payer,
|
|
2325
|
+
authority: currentOwner,
|
|
2326
|
+
cpiAuthorityPda: this.deriveCpiAuthorityPda,
|
|
2327
|
+
lightSystemProgram: stateless_js.LightSystemProgram.programId,
|
|
2328
|
+
registeredProgramPda: registeredProgramPda,
|
|
2329
|
+
noopProgram: noopProgram,
|
|
2330
|
+
accountCompressionAuthority: accountCompressionAuthority,
|
|
2331
|
+
accountCompressionProgram: accountCompressionProgram,
|
|
2332
|
+
selfProgram: this.programId,
|
|
2333
|
+
tokenPoolPda: this.deriveTokenPoolPda(mint),
|
|
2334
|
+
compressOrDecompressTokenAccount: toAddress,
|
|
2335
|
+
tokenProgram,
|
|
2336
|
+
})
|
|
2382
2337
|
.remainingAccounts(remainingAccountMetas)
|
|
2383
2338
|
.instruction();
|
|
2384
2339
|
return instruction;
|
|
2385
2340
|
}
|
|
2386
2341
|
static async mergeTokenAccounts(params) {
|
|
2387
|
-
const {
|
|
2388
|
-
payer,
|
|
2389
|
-
owner,
|
|
2390
|
-
inputCompressedTokenAccounts,
|
|
2391
|
-
outputStateTree,
|
|
2392
|
-
recentValidityProof,
|
|
2393
|
-
recentInputStateRootIndices,
|
|
2394
|
-
} = params;
|
|
2342
|
+
const { payer, owner, inputCompressedTokenAccounts, outputStateTree, recentValidityProof, recentInputStateRootIndices, } = params;
|
|
2395
2343
|
if (inputCompressedTokenAccounts.length > 3) {
|
|
2396
2344
|
throw new Error('Cannot merge more than 3 token accounts at once');
|
|
2397
2345
|
}
|
|
@@ -2399,10 +2347,7 @@ class CompressedTokenProgram {
|
|
|
2399
2347
|
payer,
|
|
2400
2348
|
inputCompressedTokenAccounts,
|
|
2401
2349
|
toAddress: owner,
|
|
2402
|
-
amount: inputCompressedTokenAccounts.reduce(
|
|
2403
|
-
(sum, account) => sum.add(account.parsed.amount),
|
|
2404
|
-
new anchor.BN(0),
|
|
2405
|
-
),
|
|
2350
|
+
amount: inputCompressedTokenAccounts.reduce((sum, account) => sum.add(account.parsed.amount), new anchor.BN(0)),
|
|
2406
2351
|
outputStateTrees: outputStateTree,
|
|
2407
2352
|
recentInputStateRootIndices,
|
|
2408
2353
|
recentValidityProof,
|
|
@@ -2410,14 +2355,8 @@ class CompressedTokenProgram {
|
|
|
2410
2355
|
return [ix];
|
|
2411
2356
|
}
|
|
2412
2357
|
static async compressSplTokenAccount(params) {
|
|
2413
|
-
const {
|
|
2414
|
-
|
|
2415
|
-
authority,
|
|
2416
|
-
tokenAccount,
|
|
2417
|
-
mint,
|
|
2418
|
-
remainingAmount,
|
|
2419
|
-
outputStateTree,
|
|
2420
|
-
} = params;
|
|
2358
|
+
const { feePayer, authority, tokenAccount, mint, remainingAmount, outputStateTree, tokenProgramId, } = params;
|
|
2359
|
+
const tokenProgram = tokenProgramId !== null && tokenProgramId !== void 0 ? tokenProgramId : splToken.TOKEN_PROGRAM_ID;
|
|
2421
2360
|
const remainingAccountMetas = [
|
|
2422
2361
|
{
|
|
2423
2362
|
pubkey: outputStateTree,
|
|
@@ -2426,46 +2365,35 @@ class CompressedTokenProgram {
|
|
|
2426
2365
|
},
|
|
2427
2366
|
];
|
|
2428
2367
|
const instruction = await this.program.methods
|
|
2429
|
-
.compressSplTokenAccount(
|
|
2430
|
-
authority,
|
|
2431
|
-
remainingAmount !== null && remainingAmount !== void 0
|
|
2432
|
-
? remainingAmount
|
|
2433
|
-
: null,
|
|
2434
|
-
null,
|
|
2435
|
-
)
|
|
2368
|
+
.compressSplTokenAccount(authority, remainingAmount !== null && remainingAmount !== void 0 ? remainingAmount : null, null)
|
|
2436
2369
|
.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
|
-
})
|
|
2370
|
+
feePayer,
|
|
2371
|
+
authority,
|
|
2372
|
+
cpiAuthorityPda: this.deriveCpiAuthorityPda,
|
|
2373
|
+
lightSystemProgram: stateless_js.LightSystemProgram.programId,
|
|
2374
|
+
registeredProgramPda: stateless_js.defaultStaticAccountsStruct().registeredProgramPda,
|
|
2375
|
+
noopProgram: stateless_js.defaultStaticAccountsStruct().noopProgram,
|
|
2376
|
+
accountCompressionAuthority: stateless_js.defaultStaticAccountsStruct().accountCompressionAuthority,
|
|
2377
|
+
accountCompressionProgram: stateless_js.defaultStaticAccountsStruct().accountCompressionProgram,
|
|
2378
|
+
selfProgram: this.programId,
|
|
2379
|
+
tokenPoolPda: this.deriveTokenPoolPda(mint),
|
|
2380
|
+
compressOrDecompressTokenAccount: tokenAccount,
|
|
2381
|
+
tokenProgram,
|
|
2382
|
+
systemProgram: web3_js.SystemProgram.programId,
|
|
2383
|
+
})
|
|
2458
2384
|
.remainingAccounts(remainingAccountMetas)
|
|
2459
2385
|
.instruction();
|
|
2460
2386
|
return instruction;
|
|
2461
2387
|
}
|
|
2388
|
+
static async get_mint_program_id(mint, connection) {
|
|
2389
|
+
var _a;
|
|
2390
|
+
return (_a = (await connection.getAccountInfo(mint))) === null || _a === void 0 ? void 0 : _a.owner;
|
|
2391
|
+
}
|
|
2462
2392
|
}
|
|
2463
2393
|
/**
|
|
2464
2394
|
* Public key that identifies the CompressedPda program
|
|
2465
2395
|
*/
|
|
2466
|
-
CompressedTokenProgram.programId = new web3_js.PublicKey(
|
|
2467
|
-
'cTokenmWW8bLPjZEBAUgYy3zKxQZW6VKi7bqNFEVv3m',
|
|
2468
|
-
);
|
|
2396
|
+
CompressedTokenProgram.programId = new web3_js.PublicKey('cTokenmWW8bLPjZEBAUgYy3zKxQZW6VKi7bqNFEVv3m');
|
|
2469
2397
|
CompressedTokenProgram._program = null;
|
|
2470
2398
|
|
|
2471
2399
|
/**
|
|
@@ -2483,23 +2411,11 @@ CompressedTokenProgram._program = null;
|
|
|
2483
2411
|
*
|
|
2484
2412
|
* @return Signature of the confirmed transaction
|
|
2485
2413
|
*/
|
|
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
|
-
);
|
|
2414
|
+
async function approveAndMintTo(rpc, payer, mint, destination, authority, amount, merkleTree, confirmOptions, tokenProgramId) {
|
|
2415
|
+
tokenProgramId = tokenProgramId
|
|
2416
|
+
? tokenProgramId
|
|
2417
|
+
: await CompressedTokenProgram.get_mint_program_id(mint, rpc);
|
|
2418
|
+
const authorityTokenAccount = await splToken.getOrCreateAssociatedTokenAccount(rpc, payer, mint, authority.publicKey, undefined, undefined, confirmOptions, tokenProgramId);
|
|
2503
2419
|
const ixs = await CompressedTokenProgram.approveAndMintTo({
|
|
2504
2420
|
feePayer: payer.publicKey,
|
|
2505
2421
|
mint,
|
|
@@ -2508,20 +2424,14 @@ async function approveAndMintTo(
|
|
|
2508
2424
|
amount,
|
|
2509
2425
|
toPubkey: destination,
|
|
2510
2426
|
merkleTree,
|
|
2427
|
+
tokenProgramId,
|
|
2511
2428
|
});
|
|
2512
2429
|
const { blockhash } = await rpc.getLatestBlockhash();
|
|
2513
2430
|
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
|
-
);
|
|
2431
|
+
const tx = stateless_js.buildAndSignTx([
|
|
2432
|
+
web3_js.ComputeBudgetProgram.setComputeUnitLimit({ units: 1000000 }),
|
|
2433
|
+
...ixs,
|
|
2434
|
+
], payer, blockhash, additionalSigners);
|
|
2525
2435
|
const txId = await stateless_js.sendAndConfirmTx(rpc, tx, confirmOptions);
|
|
2526
2436
|
return txId;
|
|
2527
2437
|
}
|
|
@@ -2544,17 +2454,10 @@ async function approveAndMintTo(
|
|
|
2544
2454
|
*
|
|
2545
2455
|
* @return Signature of the confirmed transaction
|
|
2546
2456
|
*/
|
|
2547
|
-
async function compress(
|
|
2548
|
-
|
|
2549
|
-
|
|
2550
|
-
|
|
2551
|
-
amount,
|
|
2552
|
-
owner,
|
|
2553
|
-
sourceTokenAccount,
|
|
2554
|
-
toAddress,
|
|
2555
|
-
merkleTree,
|
|
2556
|
-
confirmOptions,
|
|
2557
|
-
) {
|
|
2457
|
+
async function compress(rpc, payer, mint, amount, owner, sourceTokenAccount, toAddress, merkleTree, confirmOptions, tokenProgramId) {
|
|
2458
|
+
tokenProgramId = tokenProgramId
|
|
2459
|
+
? tokenProgramId
|
|
2460
|
+
: await CompressedTokenProgram.get_mint_program_id(mint, rpc);
|
|
2558
2461
|
const compressIx = await CompressedTokenProgram.compress({
|
|
2559
2462
|
payer: payer.publicKey,
|
|
2560
2463
|
owner: owner.publicKey,
|
|
@@ -2563,26 +2466,17 @@ async function compress(
|
|
|
2563
2466
|
amount,
|
|
2564
2467
|
mint,
|
|
2565
2468
|
outputStateTree: merkleTree,
|
|
2469
|
+
tokenProgramId,
|
|
2566
2470
|
});
|
|
2567
2471
|
const blockhashCtx = await rpc.getLatestBlockhash();
|
|
2568
2472
|
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
|
-
);
|
|
2473
|
+
const signedTx = stateless_js.buildAndSignTx([
|
|
2474
|
+
web3_js.ComputeBudgetProgram.setComputeUnitLimit({
|
|
2475
|
+
units: 1000000,
|
|
2476
|
+
}),
|
|
2477
|
+
compressIx,
|
|
2478
|
+
], payer, blockhashCtx.blockhash, additionalSigners);
|
|
2479
|
+
const txId = await stateless_js.sendAndConfirmTx(rpc, signedTx, confirmOptions, blockhashCtx);
|
|
2586
2480
|
return txId;
|
|
2587
2481
|
}
|
|
2588
2482
|
|
|
@@ -2603,33 +2497,15 @@ async function compress(
|
|
|
2603
2497
|
*
|
|
2604
2498
|
* @return Signature of the confirmed transaction
|
|
2605
2499
|
*/
|
|
2606
|
-
async function transfer(
|
|
2607
|
-
|
|
2608
|
-
|
|
2609
|
-
mint,
|
|
2610
|
-
amount,
|
|
2611
|
-
owner,
|
|
2612
|
-
toAddress,
|
|
2613
|
-
/// TODO: allow multiple
|
|
2614
|
-
merkleTree,
|
|
2615
|
-
confirmOptions,
|
|
2616
|
-
) {
|
|
2500
|
+
async function transfer(rpc, payer, mint, amount, owner, toAddress,
|
|
2501
|
+
/// TODO: allow multiple
|
|
2502
|
+
merkleTree, confirmOptions) {
|
|
2617
2503
|
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
|
-
);
|
|
2504
|
+
const compressedTokenAccounts = await rpc.getCompressedTokenAccountsByOwner(owner.publicKey, {
|
|
2505
|
+
mint,
|
|
2506
|
+
});
|
|
2507
|
+
const [inputAccounts] = selectMinCompressedTokenAccountsForTransfer(compressedTokenAccounts.items, amount);
|
|
2508
|
+
const proof = await rpc.getValidityProof(inputAccounts.map(account => stateless_js.bn(account.compressedAccount.hash)));
|
|
2633
2509
|
const ix = await CompressedTokenProgram.transfer({
|
|
2634
2510
|
payer: payer.publicKey,
|
|
2635
2511
|
inputCompressedTokenAccounts: inputAccounts,
|
|
@@ -2641,22 +2517,8 @@ async function transfer(
|
|
|
2641
2517
|
});
|
|
2642
2518
|
const { blockhash } = await rpc.getLatestBlockhash();
|
|
2643
2519
|
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
|
-
);
|
|
2520
|
+
const signedTx = stateless_js.buildAndSignTx([web3_js.ComputeBudgetProgram.setComputeUnitLimit({ units: 1000000 }), ix], payer, blockhash, additionalSigners);
|
|
2521
|
+
const txId = await stateless_js.sendAndConfirmTx(rpc, signedTx, confirmOptions);
|
|
2660
2522
|
return txId;
|
|
2661
2523
|
}
|
|
2662
2524
|
/**
|
|
@@ -2672,17 +2534,14 @@ function selectMinCompressedTokenAccountsForTransfer(accounts, transferAmount) {
|
|
|
2672
2534
|
const selectedAccounts = [];
|
|
2673
2535
|
accounts.sort((a, b) => b.parsed.amount.cmp(a.parsed.amount));
|
|
2674
2536
|
for (const account of accounts) {
|
|
2675
|
-
if (accumulatedAmount.gte(stateless_js.bn(transferAmount)))
|
|
2537
|
+
if (accumulatedAmount.gte(stateless_js.bn(transferAmount)))
|
|
2538
|
+
break;
|
|
2676
2539
|
accumulatedAmount = accumulatedAmount.add(account.parsed.amount);
|
|
2677
|
-
accumulatedLamports = accumulatedLamports.add(
|
|
2678
|
-
account.compressedAccount.lamports,
|
|
2679
|
-
);
|
|
2540
|
+
accumulatedLamports = accumulatedLamports.add(account.compressedAccount.lamports);
|
|
2680
2541
|
selectedAccounts.push(account);
|
|
2681
2542
|
}
|
|
2682
2543
|
if (accumulatedAmount.lt(stateless_js.bn(transferAmount))) {
|
|
2683
|
-
throw new Error(
|
|
2684
|
-
`Not enough balance for transfer. Required: ${transferAmount.toString()}, available: ${accumulatedAmount.toString()}`,
|
|
2685
|
-
);
|
|
2544
|
+
throw new Error(`Not enough balance for transfer. Required: ${transferAmount.toString()}, available: ${accumulatedAmount.toString()}`);
|
|
2686
2545
|
}
|
|
2687
2546
|
return [
|
|
2688
2547
|
selectedAccounts,
|
|
@@ -2709,34 +2568,19 @@ function selectMinCompressedTokenAccountsForTransfer(accounts, transferAmount) {
|
|
|
2709
2568
|
*
|
|
2710
2569
|
* @return Signature of the confirmed transaction
|
|
2711
2570
|
*/
|
|
2712
|
-
async function decompress(
|
|
2713
|
-
|
|
2714
|
-
|
|
2715
|
-
|
|
2716
|
-
|
|
2717
|
-
|
|
2718
|
-
toAddress,
|
|
2719
|
-
/// TODO: allow multiple
|
|
2720
|
-
merkleTree,
|
|
2721
|
-
confirmOptions,
|
|
2722
|
-
) {
|
|
2571
|
+
async function decompress(rpc, payer, mint, amount, owner, toAddress,
|
|
2572
|
+
/// TODO: allow multiple
|
|
2573
|
+
merkleTree, confirmOptions, tokenProgramId) {
|
|
2574
|
+
tokenProgramId = tokenProgramId
|
|
2575
|
+
? tokenProgramId
|
|
2576
|
+
: await CompressedTokenProgram.get_mint_program_id(mint, rpc);
|
|
2723
2577
|
amount = stateless_js.bn(amount);
|
|
2724
|
-
const compressedTokenAccounts = await rpc.getCompressedTokenAccountsByOwner(
|
|
2725
|
-
|
|
2726
|
-
|
|
2727
|
-
mint,
|
|
2728
|
-
},
|
|
2729
|
-
);
|
|
2578
|
+
const compressedTokenAccounts = await rpc.getCompressedTokenAccountsByOwner(owner.publicKey, {
|
|
2579
|
+
mint,
|
|
2580
|
+
});
|
|
2730
2581
|
/// 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
|
-
);
|
|
2582
|
+
const [inputAccounts] = selectMinCompressedTokenAccountsForTransfer(compressedTokenAccounts.items, amount);
|
|
2583
|
+
const proof = await rpc.getValidityProof(inputAccounts.map(account => stateless_js.bn(account.compressedAccount.hash)));
|
|
2740
2584
|
const ix = await CompressedTokenProgram.decompress({
|
|
2741
2585
|
payer: payer.publicKey,
|
|
2742
2586
|
inputCompressedTokenAccounts: inputAccounts,
|
|
@@ -2745,25 +2589,12 @@ async function decompress(
|
|
|
2745
2589
|
outputStateTree: merkleTree,
|
|
2746
2590
|
recentInputStateRootIndices: proof.rootIndices,
|
|
2747
2591
|
recentValidityProof: proof.compressedProof,
|
|
2592
|
+
tokenProgramId,
|
|
2748
2593
|
});
|
|
2749
2594
|
const { blockhash } = await rpc.getLatestBlockhash();
|
|
2750
2595
|
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
|
-
);
|
|
2596
|
+
const signedTx = stateless_js.buildAndSignTx([web3_js.ComputeBudgetProgram.setComputeUnitLimit({ units: 1000000 }), ix], payer, blockhash, additionalSigners);
|
|
2597
|
+
const txId = await stateless_js.sendAndConfirmTx(rpc, signedTx, confirmOptions);
|
|
2767
2598
|
return txId;
|
|
2768
2599
|
}
|
|
2769
2600
|
|
|
@@ -2776,20 +2607,13 @@ async function decompress(
|
|
|
2776
2607
|
* @param decimals Location of the decimal place
|
|
2777
2608
|
* @param keypair Optional keypair, defaulting to a new random one
|
|
2778
2609
|
* @param confirmOptions Options for confirming the transaction
|
|
2610
|
+
* @param isToken22 Whether to create a Token 2022 mint. Defaults to false.
|
|
2779
2611
|
*
|
|
2780
2612
|
* @return Address of the new mint and the transaction signature
|
|
2781
2613
|
*/
|
|
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
|
-
);
|
|
2614
|
+
async function createMint(rpc, payer, mintAuthority, decimals, keypair = web3_js.Keypair.generate(), confirmOptions, isToken22 = false) {
|
|
2615
|
+
const rentExemptBalance = await rpc.getMinimumBalanceForRentExemption(splToken.MINT_SIZE);
|
|
2616
|
+
const tokenProgramId = isToken22 ? splToken.TOKEN_2022_PROGRAM_ID : splToken.TOKEN_PROGRAM_ID;
|
|
2793
2617
|
const ixs = await CompressedTokenProgram.createMint({
|
|
2794
2618
|
feePayer: payer.publicKey,
|
|
2795
2619
|
mint: keypair.publicKey,
|
|
@@ -2797,15 +2621,11 @@ async function createMint(
|
|
|
2797
2621
|
authority: mintAuthority,
|
|
2798
2622
|
freezeAuthority: null, // TODO: add feature
|
|
2799
2623
|
rentExemptBalance,
|
|
2624
|
+
tokenProgramId,
|
|
2800
2625
|
});
|
|
2801
2626
|
const { blockhash } = await rpc.getLatestBlockhash();
|
|
2802
2627
|
const additionalSigners = stateless_js.dedupeSigner(payer, [keypair]);
|
|
2803
|
-
const tx = stateless_js.buildAndSignTx(
|
|
2804
|
-
ixs,
|
|
2805
|
-
payer,
|
|
2806
|
-
blockhash,
|
|
2807
|
-
additionalSigners,
|
|
2808
|
-
);
|
|
2628
|
+
const tx = stateless_js.buildAndSignTx(ixs, payer, blockhash, additionalSigners);
|
|
2809
2629
|
const txId = await stateless_js.sendAndConfirmTx(rpc, tx, confirmOptions);
|
|
2810
2630
|
return { mint: keypair.publicKey, transactionSignature: txId };
|
|
2811
2631
|
}
|
|
@@ -2827,16 +2647,10 @@ async function createMint(
|
|
|
2827
2647
|
*
|
|
2828
2648
|
* @return Signature of the confirmed transaction
|
|
2829
2649
|
*/
|
|
2830
|
-
async function mintTo(
|
|
2831
|
-
|
|
2832
|
-
|
|
2833
|
-
|
|
2834
|
-
destination,
|
|
2835
|
-
authority,
|
|
2836
|
-
amount,
|
|
2837
|
-
merkleTree,
|
|
2838
|
-
confirmOptions,
|
|
2839
|
-
) {
|
|
2650
|
+
async function mintTo(rpc, payer, mint, destination, authority, amount, merkleTree, confirmOptions, tokenProgramId) {
|
|
2651
|
+
tokenProgramId = tokenProgramId
|
|
2652
|
+
? tokenProgramId
|
|
2653
|
+
: await CompressedTokenProgram.get_mint_program_id(mint, rpc);
|
|
2840
2654
|
const additionalSigners = stateless_js.dedupeSigner(payer, [authority]);
|
|
2841
2655
|
const ix = await CompressedTokenProgram.mintTo({
|
|
2842
2656
|
feePayer: payer.publicKey,
|
|
@@ -2845,19 +2659,10 @@ async function mintTo(
|
|
|
2845
2659
|
amount: amount,
|
|
2846
2660
|
toPubkey: destination,
|
|
2847
2661
|
merkleTree,
|
|
2662
|
+
tokenProgramId,
|
|
2848
2663
|
});
|
|
2849
2664
|
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
|
-
);
|
|
2665
|
+
const tx = stateless_js.buildAndSignTx([web3_js.ComputeBudgetProgram.setComputeUnitLimit({ units: 1000000 }), ix], payer, blockhash, additionalSigners);
|
|
2861
2666
|
const txId = await stateless_js.sendAndConfirmTx(rpc, tx, confirmOptions);
|
|
2862
2667
|
return txId;
|
|
2863
2668
|
}
|
|
@@ -2875,67 +2680,35 @@ async function mintTo(
|
|
|
2875
2680
|
*
|
|
2876
2681
|
* @return Array of transaction signatures
|
|
2877
2682
|
*/
|
|
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
|
-
);
|
|
2683
|
+
async function mergeTokenAccounts(rpc, payer, mint, owner, merkleTree, confirmOptions) {
|
|
2684
|
+
const compressedTokenAccounts = await rpc.getCompressedTokenAccountsByOwner(owner.publicKey, { mint });
|
|
2890
2685
|
if (compressedTokenAccounts.items.length === 0) {
|
|
2891
|
-
throw new Error(
|
|
2892
|
-
`No compressed token accounts found for mint ${mint.toBase58()}`,
|
|
2893
|
-
);
|
|
2686
|
+
throw new Error(`No compressed token accounts found for mint ${mint.toBase58()}`);
|
|
2894
2687
|
}
|
|
2895
2688
|
if (compressedTokenAccounts.items.length >= 6) {
|
|
2896
|
-
throw new Error(
|
|
2897
|
-
`Too many compressed token accounts used for mint ${mint.toBase58()}`,
|
|
2898
|
-
);
|
|
2689
|
+
throw new Error(`Too many compressed token accounts used for mint ${mint.toBase58()}`);
|
|
2899
2690
|
}
|
|
2900
2691
|
const instructions = [
|
|
2901
2692
|
web3_js.ComputeBudgetProgram.setComputeUnitLimit({ units: 1000000 }),
|
|
2902
2693
|
];
|
|
2903
|
-
for (
|
|
2904
|
-
let i = 0;
|
|
2905
|
-
i < compressedTokenAccounts.items.slice(0, 6).length;
|
|
2906
|
-
i += 3
|
|
2907
|
-
) {
|
|
2694
|
+
for (let i = 0; i < compressedTokenAccounts.items.slice(0, 6).length; i += 3) {
|
|
2908
2695
|
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
|
-
});
|
|
2696
|
+
const proof = await rpc.getValidityProof(batch.map(account => stateless_js.bn(account.compressedAccount.hash)));
|
|
2697
|
+
const batchInstructions = await CompressedTokenProgram.mergeTokenAccounts({
|
|
2698
|
+
payer: payer.publicKey,
|
|
2699
|
+
owner: owner.publicKey,
|
|
2700
|
+
mint,
|
|
2701
|
+
inputCompressedTokenAccounts: batch,
|
|
2702
|
+
outputStateTree: merkleTree,
|
|
2703
|
+
recentValidityProof: proof.compressedProof,
|
|
2704
|
+
recentInputStateRootIndices: proof.rootIndices,
|
|
2705
|
+
});
|
|
2924
2706
|
instructions.push(...batchInstructions);
|
|
2925
2707
|
}
|
|
2926
2708
|
const { blockhash } = await rpc.getLatestBlockhash();
|
|
2927
2709
|
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
|
-
);
|
|
2710
|
+
const signedTx = stateless_js.buildAndSignTx(instructions, payer, blockhash, additionalSigners);
|
|
2711
|
+
const txId = await stateless_js.sendAndConfirmTx(rpc, signedTx, confirmOptions);
|
|
2939
2712
|
return txId;
|
|
2940
2713
|
}
|
|
2941
2714
|
|
|
@@ -2950,10 +2723,14 @@ async function mergeTokenAccounts(
|
|
|
2950
2723
|
*
|
|
2951
2724
|
* @return transaction signature
|
|
2952
2725
|
*/
|
|
2953
|
-
async function createTokenPool(rpc, payer,
|
|
2726
|
+
async function createTokenPool(rpc, payer, mint, confirmOptions, tokenProgramId) {
|
|
2727
|
+
tokenProgramId = tokenProgramId
|
|
2728
|
+
? tokenProgramId
|
|
2729
|
+
: await CompressedTokenProgram.get_mint_program_id(mint, rpc);
|
|
2954
2730
|
const ix = await CompressedTokenProgram.createTokenPool({
|
|
2955
2731
|
feePayer: payer.publicKey,
|
|
2956
|
-
mint
|
|
2732
|
+
mint,
|
|
2733
|
+
tokenProgramId,
|
|
2957
2734
|
});
|
|
2958
2735
|
const { blockhash } = await rpc.getLatestBlockhash();
|
|
2959
2736
|
const tx = stateless_js.buildAndSignTx([ix], payer, blockhash);
|
|
@@ -2974,50 +2751,23 @@ async function createTokenPool(rpc, payer, mintAddress, confirmOptions) {
|
|
|
2974
2751
|
*
|
|
2975
2752
|
* @return Transaction signatures and the address of the created lookup table
|
|
2976
2753
|
*/
|
|
2977
|
-
async function createTokenProgramLookupTable(
|
|
2978
|
-
rpc,
|
|
2979
|
-
payer,
|
|
2980
|
-
authority,
|
|
2981
|
-
mints,
|
|
2982
|
-
additionalAccounts,
|
|
2983
|
-
) {
|
|
2754
|
+
async function createTokenProgramLookupTable(rpc, payer, authority, mints, additionalAccounts) {
|
|
2984
2755
|
const recentSlot = await rpc.getSlot('finalized');
|
|
2985
|
-
const { instructions, address } =
|
|
2986
|
-
|
|
2987
|
-
|
|
2988
|
-
|
|
2989
|
-
|
|
2990
|
-
|
|
2991
|
-
|
|
2992
|
-
});
|
|
2756
|
+
const { instructions, address } = await CompressedTokenProgram.createTokenProgramLookupTable({
|
|
2757
|
+
payer: payer.publicKey,
|
|
2758
|
+
authority: authority.publicKey,
|
|
2759
|
+
mints,
|
|
2760
|
+
remainingAccounts: additionalAccounts,
|
|
2761
|
+
recentSlot,
|
|
2762
|
+
});
|
|
2993
2763
|
const additionalSigners = stateless_js.dedupeSigner(payer, [authority]);
|
|
2994
2764
|
const blockhashCtx = await rpc.getLatestBlockhash();
|
|
2995
|
-
const signedTx = stateless_js.buildAndSignTx(
|
|
2996
|
-
[instructions[0]],
|
|
2997
|
-
payer,
|
|
2998
|
-
blockhashCtx.blockhash,
|
|
2999
|
-
additionalSigners,
|
|
3000
|
-
);
|
|
2765
|
+
const signedTx = stateless_js.buildAndSignTx([instructions[0]], payer, blockhashCtx.blockhash, additionalSigners);
|
|
3001
2766
|
/// 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
|
-
);
|
|
2767
|
+
const txId = await stateless_js.sendAndConfirmTx(rpc, signedTx, { commitment: 'finalized' }, blockhashCtx);
|
|
3008
2768
|
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
|
-
);
|
|
2769
|
+
const signedTx2 = stateless_js.buildAndSignTx([instructions[1]], payer, blockhashCtx2.blockhash, additionalSigners);
|
|
2770
|
+
const txId2 = await stateless_js.sendAndConfirmTx(rpc, signedTx2, { commitment: 'finalized' }, blockhashCtx2);
|
|
3021
2771
|
return { txIds: [txId, txId2], address };
|
|
3022
2772
|
}
|
|
3023
2773
|
|
|
@@ -3035,16 +2785,10 @@ async function createTokenProgramLookupTable(
|
|
|
3035
2785
|
*
|
|
3036
2786
|
* @return Signature of the confirmed transaction
|
|
3037
2787
|
*/
|
|
3038
|
-
async function compressSplTokenAccount(
|
|
3039
|
-
|
|
3040
|
-
|
|
3041
|
-
|
|
3042
|
-
owner,
|
|
3043
|
-
tokenAccount,
|
|
3044
|
-
outputStateTree,
|
|
3045
|
-
remainingAmount,
|
|
3046
|
-
confirmOptions,
|
|
3047
|
-
) {
|
|
2788
|
+
async function compressSplTokenAccount(rpc, payer, mint, owner, tokenAccount, outputStateTree, remainingAmount, confirmOptions, tokenProgramId) {
|
|
2789
|
+
tokenProgramId = tokenProgramId
|
|
2790
|
+
? tokenProgramId
|
|
2791
|
+
: await CompressedTokenProgram.get_mint_program_id(mint, rpc);
|
|
3048
2792
|
const compressIx = await CompressedTokenProgram.compressSplTokenAccount({
|
|
3049
2793
|
feePayer: payer.publicKey,
|
|
3050
2794
|
authority: owner.publicKey,
|
|
@@ -3052,26 +2796,17 @@ async function compressSplTokenAccount(
|
|
|
3052
2796
|
mint,
|
|
3053
2797
|
remainingAmount,
|
|
3054
2798
|
outputStateTree,
|
|
2799
|
+
tokenProgramId,
|
|
3055
2800
|
});
|
|
3056
2801
|
const blockhashCtx = await rpc.getLatestBlockhash();
|
|
3057
2802
|
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
|
-
);
|
|
2803
|
+
const signedTx = stateless_js.buildAndSignTx([
|
|
2804
|
+
web3_js.ComputeBudgetProgram.setComputeUnitLimit({
|
|
2805
|
+
units: 1000000,
|
|
2806
|
+
}),
|
|
2807
|
+
compressIx,
|
|
2808
|
+
], payer, blockhashCtx.blockhash, additionalSigners);
|
|
2809
|
+
const txId = await stateless_js.sendAndConfirmTx(rpc, signedTx, confirmOptions, blockhashCtx);
|
|
3075
2810
|
return txId;
|
|
3076
2811
|
}
|
|
3077
2812
|
|
|
@@ -3093,8 +2828,7 @@ exports.mergeTokenAccounts = mergeTokenAccounts;
|
|
|
3093
2828
|
exports.mintTo = mintTo;
|
|
3094
2829
|
exports.packCompressedTokenAccounts = packCompressedTokenAccounts;
|
|
3095
2830
|
exports.parseTokenData = parseTokenData;
|
|
3096
|
-
exports.selectMinCompressedTokenAccountsForTransfer =
|
|
3097
|
-
selectMinCompressedTokenAccountsForTransfer;
|
|
2831
|
+
exports.selectMinCompressedTokenAccountsForTransfer = selectMinCompressedTokenAccountsForTransfer;
|
|
3098
2832
|
exports.sumUpTokenAmount = sumUpTokenAmount;
|
|
3099
2833
|
exports.transfer = transfer;
|
|
3100
2834
|
exports.validateSameTokenOwner = validateSameTokenOwner;
|