@lightprotocol/stateless.js 0.8.0 → 0.10.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 +56 -30
- package/dist/cjs/browser/index.cjs.map +1 -1
- package/dist/cjs/node/index.cjs +56 -30
- package/dist/cjs/node/index.cjs.map +1 -1
- package/dist/es/browser/index.js +53 -27
- package/dist/es/browser/index.js.map +1 -1
- package/dist/types/index.d.ts +44 -36
- package/package.json +3 -3
package/dist/cjs/node/index.cjs
CHANGED
|
@@ -4952,15 +4952,16 @@ if (undefined) {
|
|
|
4952
4952
|
* @param instructions instructions to include
|
|
4953
4953
|
* @param payerPublicKey fee payer public key
|
|
4954
4954
|
* @param blockhash blockhash to use
|
|
4955
|
+
* @param lookupTableAccounts lookup table accounts to include
|
|
4955
4956
|
*
|
|
4956
4957
|
* @return VersionedTransaction
|
|
4957
4958
|
*/
|
|
4958
|
-
function buildTx(instructions, payerPublicKey, blockhash) {
|
|
4959
|
+
function buildTx(instructions, payerPublicKey, blockhash, lookupTableAccounts) {
|
|
4959
4960
|
const messageV0 = new web3_js.TransactionMessage({
|
|
4960
4961
|
payerKey: payerPublicKey,
|
|
4961
4962
|
recentBlockhash: blockhash,
|
|
4962
4963
|
instructions,
|
|
4963
|
-
}).compileToV0Message();
|
|
4964
|
+
}).compileToV0Message(lookupTableAccounts);
|
|
4964
4965
|
return new web3_js.VersionedTransaction(messageV0);
|
|
4965
4966
|
}
|
|
4966
4967
|
/**
|
|
@@ -5016,12 +5017,13 @@ async function confirmTx(rpc, txId, confirmOptions, blockHashCtx) {
|
|
|
5016
5017
|
* @param payer payer of the transaction
|
|
5017
5018
|
* @param blockhash recent blockhash to use in the transaction
|
|
5018
5019
|
* @param additionalSigners non-feepayer signers to include in the transaction
|
|
5020
|
+
* @param lookupTableAccounts lookup table accounts to include in the transaction
|
|
5019
5021
|
*/
|
|
5020
|
-
function buildAndSignTx(instructions, payer, blockhash, additionalSigners = []) {
|
|
5022
|
+
function buildAndSignTx(instructions, payer, blockhash, additionalSigners = [], lookupTableAccounts) {
|
|
5021
5023
|
if (additionalSigners.includes(payer))
|
|
5022
5024
|
throw new Error('payer must not be in additionalSigners');
|
|
5023
5025
|
const allSigners = [payer, ...additionalSigners];
|
|
5024
|
-
const tx = buildTx(instructions, payer.publicKey, blockhash);
|
|
5026
|
+
const tx = buildTx(instructions, payer.publicKey, blockhash, lookupTableAccounts);
|
|
5025
5027
|
tx.sign(allSigners);
|
|
5026
5028
|
return tx;
|
|
5027
5029
|
}
|
|
@@ -5443,7 +5445,7 @@ async function createAccount(rpc, payer, seed, programId, addressTree, addressQu
|
|
|
5443
5445
|
async function createAccountWithLamports(rpc, payer, seed, lamports, programId, addressTree, addressQueue, outputStateTree, confirmOptions) {
|
|
5444
5446
|
lamports = bn(lamports);
|
|
5445
5447
|
const compressedAccounts = await rpc.getCompressedAccountsByOwner(payer.publicKey);
|
|
5446
|
-
const [inputAccounts] = selectMinCompressedSolAccountsForTransfer(compressedAccounts, lamports);
|
|
5448
|
+
const [inputAccounts] = selectMinCompressedSolAccountsForTransfer(compressedAccounts.items, lamports);
|
|
5447
5449
|
const { blockhash } = await rpc.getLatestBlockhash();
|
|
5448
5450
|
addressTree = addressTree !== null && addressTree !== void 0 ? addressTree : defaultTestStateTreeAccounts().addressTree;
|
|
5449
5451
|
addressQueue = addressQueue !== null && addressQueue !== void 0 ? addressQueue : defaultTestStateTreeAccounts().addressQueue;
|
|
@@ -5490,7 +5492,7 @@ async function createAccountWithLamports(rpc, payer, seed, lamports, programId,
|
|
|
5490
5492
|
/// TODO: add support for payer != owner
|
|
5491
5493
|
async function decompress(rpc, payer, lamports, recipient, outputStateTree, confirmOptions) {
|
|
5492
5494
|
/// TODO: use dynamic state tree and nullifier queue
|
|
5493
|
-
const userCompressedAccountsWithMerkleContext = await rpc.getCompressedAccountsByOwner(payer.publicKey);
|
|
5495
|
+
const userCompressedAccountsWithMerkleContext = (await rpc.getCompressedAccountsByOwner(payer.publicKey)).items;
|
|
5494
5496
|
lamports = bn(lamports);
|
|
5495
5497
|
const inputLamports = sumUpLamports(userCompressedAccountsWithMerkleContext);
|
|
5496
5498
|
if (lamports.gt(inputLamports)) {
|
|
@@ -5540,7 +5542,7 @@ async function transfer(rpc, payer, lamports, owner, toAddress,
|
|
|
5540
5542
|
merkleTree, confirmOptions) {
|
|
5541
5543
|
lamports = bn(lamports);
|
|
5542
5544
|
const compressedAccounts = await rpc.getCompressedAccountsByOwner(owner.publicKey);
|
|
5543
|
-
const [inputAccounts] = selectMinCompressedSolAccountsForTransfer(compressedAccounts, lamports);
|
|
5545
|
+
const [inputAccounts] = selectMinCompressedSolAccountsForTransfer(compressedAccounts.items, lamports);
|
|
5544
5546
|
const proof = await rpc.getValidityProof(inputAccounts.map(account => bn(account.hash)));
|
|
5545
5547
|
const ix = await LightSystemProgram.transfer({
|
|
5546
5548
|
payer: payer.publicKey,
|
|
@@ -10375,14 +10377,14 @@ const MultipleCompressedAccountsResult = type({
|
|
|
10375
10377
|
*/
|
|
10376
10378
|
const CompressedAccountsByOwnerResult = type({
|
|
10377
10379
|
items: array(CompressedAccountResult),
|
|
10378
|
-
cursor: nullable(
|
|
10380
|
+
cursor: nullable(string()),
|
|
10379
10381
|
});
|
|
10380
10382
|
/**
|
|
10381
10383
|
* @internal
|
|
10382
10384
|
*/
|
|
10383
10385
|
const CompressedTokenAccountsByOwnerOrDelegateResult = type({
|
|
10384
10386
|
items: array(CompressedTokenAccountResult),
|
|
10385
|
-
cursor: nullable(
|
|
10387
|
+
cursor: nullable(string()),
|
|
10386
10388
|
});
|
|
10387
10389
|
/**
|
|
10388
10390
|
* @internal
|
|
@@ -10477,7 +10479,7 @@ const TokenBalanceResult = type({
|
|
|
10477
10479
|
});
|
|
10478
10480
|
const TokenBalanceListResult = type({
|
|
10479
10481
|
tokenBalances: array(TokenBalanceResult),
|
|
10480
|
-
cursor: nullable(
|
|
10482
|
+
cursor: nullable(string()),
|
|
10481
10483
|
});
|
|
10482
10484
|
const AccountProofResult = type({
|
|
10483
10485
|
hash: array(number()),
|
|
@@ -10500,7 +10502,7 @@ const SignatureListWithCursorResult = type({
|
|
|
10500
10502
|
signature: string(),
|
|
10501
10503
|
slot: number(),
|
|
10502
10504
|
})),
|
|
10503
|
-
cursor: nullable(
|
|
10505
|
+
cursor: nullable(string()),
|
|
10504
10506
|
});
|
|
10505
10507
|
const CompressedTransactionResult = type({
|
|
10506
10508
|
compressionInfo: type({
|
|
@@ -10569,7 +10571,10 @@ async function getCompressedTokenAccountsByOwnerOrDelegate(rpc, ownerOrDelegate,
|
|
|
10569
10571
|
});
|
|
10570
10572
|
});
|
|
10571
10573
|
/// TODO: consider custom or different sort. Most recent here.
|
|
10572
|
-
return
|
|
10574
|
+
return {
|
|
10575
|
+
items: accounts.sort((a, b) => b.compressedAccount.leafIndex - a.compressedAccount.leafIndex),
|
|
10576
|
+
cursor: res.result.value.cursor,
|
|
10577
|
+
};
|
|
10573
10578
|
}
|
|
10574
10579
|
/** @internal */
|
|
10575
10580
|
function buildCompressedAccountWithMaybeTokenData(accountStructWithOptionalTokenData) {
|
|
@@ -10859,14 +10864,20 @@ class Rpc extends web3_js.Connection {
|
|
|
10859
10864
|
throw new web3_js.SolanaJSONRPCError(res.error, `failed to get info for compressed accounts owned by ${owner.toBase58()}`);
|
|
10860
10865
|
}
|
|
10861
10866
|
if (res.result.value === null) {
|
|
10862
|
-
return
|
|
10867
|
+
return {
|
|
10868
|
+
items: [],
|
|
10869
|
+
cursor: null,
|
|
10870
|
+
};
|
|
10863
10871
|
}
|
|
10864
10872
|
const accounts = [];
|
|
10865
10873
|
res.result.value.items.map(item => {
|
|
10866
10874
|
const account = createCompressedAccountWithMerkleContext(createMerkleContext(item.tree, mockNullifierQueue, item.hash.toArray('be', 32), item.leafIndex), item.owner, bn(item.lamports), item.data ? parseAccountData(item.data) : undefined, item.address || undefined);
|
|
10867
10875
|
accounts.push(account);
|
|
10868
10876
|
});
|
|
10869
|
-
return
|
|
10877
|
+
return {
|
|
10878
|
+
items: accounts.sort((a, b) => b.leafIndex - a.leafIndex),
|
|
10879
|
+
cursor: res.result.value.cursor,
|
|
10880
|
+
};
|
|
10870
10881
|
}
|
|
10871
10882
|
/**
|
|
10872
10883
|
* Fetch all the compressed token accounts owned by the specified public
|
|
@@ -10923,7 +10934,10 @@ class Rpc extends web3_js.Connection {
|
|
|
10923
10934
|
const maybeFiltered = options.mint
|
|
10924
10935
|
? res.result.value.tokenBalances.filter(tokenBalance => tokenBalance.mint.toBase58() === options.mint.toBase58())
|
|
10925
10936
|
: res.result.value.tokenBalances;
|
|
10926
|
-
return
|
|
10937
|
+
return {
|
|
10938
|
+
items: maybeFiltered,
|
|
10939
|
+
cursor: res.result.value.cursor,
|
|
10940
|
+
};
|
|
10927
10941
|
}
|
|
10928
10942
|
/**
|
|
10929
10943
|
* Returns confirmed compression signatures for transactions involving the specified
|
|
@@ -11003,7 +11017,7 @@ class Rpc extends web3_js.Connection {
|
|
|
11003
11017
|
if (res.result.value === null) {
|
|
11004
11018
|
throw new Error(`failed to get signatures for address ${address.toBase58()}`);
|
|
11005
11019
|
}
|
|
11006
|
-
return res.result.value
|
|
11020
|
+
return res.result.value;
|
|
11007
11021
|
}
|
|
11008
11022
|
/**
|
|
11009
11023
|
* Returns confirmed signatures for compression transactions involving the
|
|
@@ -11021,7 +11035,7 @@ class Rpc extends web3_js.Connection {
|
|
|
11021
11035
|
if (res.result.value === null) {
|
|
11022
11036
|
throw new Error(`failed to get signatures for owner ${owner.toBase58()}`);
|
|
11023
11037
|
}
|
|
11024
|
-
return res.result.value
|
|
11038
|
+
return res.result.value;
|
|
11025
11039
|
}
|
|
11026
11040
|
/// TODO(photon): needs mint
|
|
11027
11041
|
/**
|
|
@@ -11038,7 +11052,7 @@ class Rpc extends web3_js.Connection {
|
|
|
11038
11052
|
if (res.result.value === null) {
|
|
11039
11053
|
throw new Error(`failed to get signatures for owner ${owner.toBase58()}`);
|
|
11040
11054
|
}
|
|
11041
|
-
return res.result.value
|
|
11055
|
+
return res.result.value;
|
|
11042
11056
|
}
|
|
11043
11057
|
/**
|
|
11044
11058
|
* Fetch the current indexer health status
|
|
@@ -15574,16 +15588,22 @@ async function getCompressedTokenAccountsByOwnerTest(rpc, owner, mint) {
|
|
|
15574
15588
|
const events = await getParsedEvents(rpc);
|
|
15575
15589
|
const compressedTokenAccounts = await getCompressedTokenAccounts(events);
|
|
15576
15590
|
const accounts = compressedTokenAccounts.filter(acc => acc.parsed.owner.equals(owner) && acc.parsed.mint.equals(mint));
|
|
15577
|
-
return
|
|
15591
|
+
return {
|
|
15592
|
+
items: accounts.sort((a, b) => b.compressedAccount.leafIndex - a.compressedAccount.leafIndex),
|
|
15593
|
+
cursor: null,
|
|
15594
|
+
};
|
|
15578
15595
|
}
|
|
15579
15596
|
async function getCompressedTokenAccountsByDelegateTest(rpc, delegate, mint) {
|
|
15580
15597
|
const events = await getParsedEvents(rpc);
|
|
15581
15598
|
const compressedTokenAccounts = await getCompressedTokenAccounts(events);
|
|
15582
|
-
return
|
|
15583
|
-
|
|
15584
|
-
|
|
15585
|
-
acc.parsed.
|
|
15586
|
-
|
|
15599
|
+
return {
|
|
15600
|
+
items: compressedTokenAccounts.filter(acc => {
|
|
15601
|
+
var _a;
|
|
15602
|
+
return ((_a = acc.parsed.delegate) === null || _a === void 0 ? void 0 : _a.equals(delegate)) &&
|
|
15603
|
+
acc.parsed.mint.equals(mint);
|
|
15604
|
+
}),
|
|
15605
|
+
cursor: null,
|
|
15606
|
+
};
|
|
15587
15607
|
}
|
|
15588
15608
|
async function getCompressedTokenAccountByHashTest(rpc, hash) {
|
|
15589
15609
|
const events = await getParsedEvents(rpc);
|
|
@@ -15690,7 +15710,7 @@ class TestRpc extends web3_js.Connection {
|
|
|
15690
15710
|
*/
|
|
15691
15711
|
async getCompressedBalanceByOwner(owner) {
|
|
15692
15712
|
const accounts = await this.getCompressedAccountsByOwner(owner);
|
|
15693
|
-
return accounts.reduce((acc, account) => acc.add(account.lamports), bn(0));
|
|
15713
|
+
return accounts.items.reduce((acc, account) => acc.add(account.lamports), bn(0));
|
|
15694
15714
|
}
|
|
15695
15715
|
/**
|
|
15696
15716
|
* Fetch the latest merkle proof for the specified account hash from the
|
|
@@ -15765,7 +15785,10 @@ class TestRpc extends web3_js.Connection {
|
|
|
15765
15785
|
*/
|
|
15766
15786
|
async getCompressedAccountsByOwner(owner) {
|
|
15767
15787
|
const accounts = await getCompressedAccountsByOwnerTest(this, owner);
|
|
15768
|
-
return
|
|
15788
|
+
return {
|
|
15789
|
+
items: accounts,
|
|
15790
|
+
cursor: null,
|
|
15791
|
+
};
|
|
15769
15792
|
}
|
|
15770
15793
|
/**
|
|
15771
15794
|
* Fetch the latest compression signatures on the cluster. Results are
|
|
@@ -15807,10 +15830,13 @@ class TestRpc extends web3_js.Connection {
|
|
|
15807
15830
|
*/
|
|
15808
15831
|
async getCompressedTokenBalancesByOwner(publicKey, options) {
|
|
15809
15832
|
const accounts = await getCompressedTokenAccountsByOwnerTest(this, publicKey, options.mint);
|
|
15810
|
-
return
|
|
15811
|
-
|
|
15812
|
-
|
|
15813
|
-
|
|
15833
|
+
return {
|
|
15834
|
+
items: accounts.items.map(account => ({
|
|
15835
|
+
balance: bn(account.parsed.amount),
|
|
15836
|
+
mint: account.parsed.mint,
|
|
15837
|
+
})),
|
|
15838
|
+
cursor: null,
|
|
15839
|
+
};
|
|
15814
15840
|
}
|
|
15815
15841
|
/**
|
|
15816
15842
|
* Returns confirmed signatures for transactions involving the specified
|