@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
|
@@ -6982,15 +6982,16 @@ if (undefined) {
|
|
|
6982
6982
|
* @param instructions instructions to include
|
|
6983
6983
|
* @param payerPublicKey fee payer public key
|
|
6984
6984
|
* @param blockhash blockhash to use
|
|
6985
|
+
* @param lookupTableAccounts lookup table accounts to include
|
|
6985
6986
|
*
|
|
6986
6987
|
* @return VersionedTransaction
|
|
6987
6988
|
*/
|
|
6988
|
-
function buildTx(instructions, payerPublicKey, blockhash) {
|
|
6989
|
+
function buildTx(instructions, payerPublicKey, blockhash, lookupTableAccounts) {
|
|
6989
6990
|
const messageV0 = new web3_js.TransactionMessage({
|
|
6990
6991
|
payerKey: payerPublicKey,
|
|
6991
6992
|
recentBlockhash: blockhash,
|
|
6992
6993
|
instructions,
|
|
6993
|
-
}).compileToV0Message();
|
|
6994
|
+
}).compileToV0Message(lookupTableAccounts);
|
|
6994
6995
|
return new web3_js.VersionedTransaction(messageV0);
|
|
6995
6996
|
}
|
|
6996
6997
|
/**
|
|
@@ -7046,12 +7047,13 @@ async function confirmTx(rpc, txId, confirmOptions, blockHashCtx) {
|
|
|
7046
7047
|
* @param payer payer of the transaction
|
|
7047
7048
|
* @param blockhash recent blockhash to use in the transaction
|
|
7048
7049
|
* @param additionalSigners non-feepayer signers to include in the transaction
|
|
7050
|
+
* @param lookupTableAccounts lookup table accounts to include in the transaction
|
|
7049
7051
|
*/
|
|
7050
|
-
function buildAndSignTx(instructions, payer, blockhash, additionalSigners = []) {
|
|
7052
|
+
function buildAndSignTx(instructions, payer, blockhash, additionalSigners = [], lookupTableAccounts) {
|
|
7051
7053
|
if (additionalSigners.includes(payer))
|
|
7052
7054
|
throw new Error('payer must not be in additionalSigners');
|
|
7053
7055
|
const allSigners = [payer, ...additionalSigners];
|
|
7054
|
-
const tx = buildTx(instructions, payer.publicKey, blockhash);
|
|
7056
|
+
const tx = buildTx(instructions, payer.publicKey, blockhash, lookupTableAccounts);
|
|
7055
7057
|
tx.sign(allSigners);
|
|
7056
7058
|
return tx;
|
|
7057
7059
|
}
|
|
@@ -7473,7 +7475,7 @@ async function createAccount(rpc, payer, seed, programId, addressTree, addressQu
|
|
|
7473
7475
|
async function createAccountWithLamports(rpc, payer, seed, lamports, programId, addressTree, addressQueue, outputStateTree, confirmOptions) {
|
|
7474
7476
|
lamports = bn(lamports);
|
|
7475
7477
|
const compressedAccounts = await rpc.getCompressedAccountsByOwner(payer.publicKey);
|
|
7476
|
-
const [inputAccounts] = selectMinCompressedSolAccountsForTransfer(compressedAccounts, lamports);
|
|
7478
|
+
const [inputAccounts] = selectMinCompressedSolAccountsForTransfer(compressedAccounts.items, lamports);
|
|
7477
7479
|
const { blockhash } = await rpc.getLatestBlockhash();
|
|
7478
7480
|
addressTree = addressTree !== null && addressTree !== void 0 ? addressTree : defaultTestStateTreeAccounts().addressTree;
|
|
7479
7481
|
addressQueue = addressQueue !== null && addressQueue !== void 0 ? addressQueue : defaultTestStateTreeAccounts().addressQueue;
|
|
@@ -7520,7 +7522,7 @@ async function createAccountWithLamports(rpc, payer, seed, lamports, programId,
|
|
|
7520
7522
|
/// TODO: add support for payer != owner
|
|
7521
7523
|
async function decompress(rpc, payer, lamports, recipient, outputStateTree, confirmOptions) {
|
|
7522
7524
|
/// TODO: use dynamic state tree and nullifier queue
|
|
7523
|
-
const userCompressedAccountsWithMerkleContext = await rpc.getCompressedAccountsByOwner(payer.publicKey);
|
|
7525
|
+
const userCompressedAccountsWithMerkleContext = (await rpc.getCompressedAccountsByOwner(payer.publicKey)).items;
|
|
7524
7526
|
lamports = bn(lamports);
|
|
7525
7527
|
const inputLamports = sumUpLamports(userCompressedAccountsWithMerkleContext);
|
|
7526
7528
|
if (lamports.gt(inputLamports)) {
|
|
@@ -7570,7 +7572,7 @@ async function transfer(rpc, payer, lamports, owner, toAddress,
|
|
|
7570
7572
|
merkleTree, confirmOptions) {
|
|
7571
7573
|
lamports = bn(lamports);
|
|
7572
7574
|
const compressedAccounts = await rpc.getCompressedAccountsByOwner(owner.publicKey);
|
|
7573
|
-
const [inputAccounts] = selectMinCompressedSolAccountsForTransfer(compressedAccounts, lamports);
|
|
7575
|
+
const [inputAccounts] = selectMinCompressedSolAccountsForTransfer(compressedAccounts.items, lamports);
|
|
7574
7576
|
const proof = await rpc.getValidityProof(inputAccounts.map(account => bn(account.hash)));
|
|
7575
7577
|
const ix = await LightSystemProgram.transfer({
|
|
7576
7578
|
payer: payer.publicKey,
|
|
@@ -12405,14 +12407,14 @@ const MultipleCompressedAccountsResult = type({
|
|
|
12405
12407
|
*/
|
|
12406
12408
|
const CompressedAccountsByOwnerResult = type({
|
|
12407
12409
|
items: array(CompressedAccountResult),
|
|
12408
|
-
cursor: nullable(
|
|
12410
|
+
cursor: nullable(string()),
|
|
12409
12411
|
});
|
|
12410
12412
|
/**
|
|
12411
12413
|
* @internal
|
|
12412
12414
|
*/
|
|
12413
12415
|
const CompressedTokenAccountsByOwnerOrDelegateResult = type({
|
|
12414
12416
|
items: array(CompressedTokenAccountResult),
|
|
12415
|
-
cursor: nullable(
|
|
12417
|
+
cursor: nullable(string()),
|
|
12416
12418
|
});
|
|
12417
12419
|
/**
|
|
12418
12420
|
* @internal
|
|
@@ -12507,7 +12509,7 @@ const TokenBalanceResult = type({
|
|
|
12507
12509
|
});
|
|
12508
12510
|
const TokenBalanceListResult = type({
|
|
12509
12511
|
tokenBalances: array(TokenBalanceResult),
|
|
12510
|
-
cursor: nullable(
|
|
12512
|
+
cursor: nullable(string()),
|
|
12511
12513
|
});
|
|
12512
12514
|
const AccountProofResult = type({
|
|
12513
12515
|
hash: array(number()),
|
|
@@ -12530,7 +12532,7 @@ const SignatureListWithCursorResult = type({
|
|
|
12530
12532
|
signature: string(),
|
|
12531
12533
|
slot: number(),
|
|
12532
12534
|
})),
|
|
12533
|
-
cursor: nullable(
|
|
12535
|
+
cursor: nullable(string()),
|
|
12534
12536
|
});
|
|
12535
12537
|
const CompressedTransactionResult = type({
|
|
12536
12538
|
compressionInfo: type({
|
|
@@ -12599,7 +12601,10 @@ async function getCompressedTokenAccountsByOwnerOrDelegate(rpc, ownerOrDelegate,
|
|
|
12599
12601
|
});
|
|
12600
12602
|
});
|
|
12601
12603
|
/// TODO: consider custom or different sort. Most recent here.
|
|
12602
|
-
return
|
|
12604
|
+
return {
|
|
12605
|
+
items: accounts.sort((a, b) => b.compressedAccount.leafIndex - a.compressedAccount.leafIndex),
|
|
12606
|
+
cursor: res.result.value.cursor,
|
|
12607
|
+
};
|
|
12603
12608
|
}
|
|
12604
12609
|
/** @internal */
|
|
12605
12610
|
function buildCompressedAccountWithMaybeTokenData(accountStructWithOptionalTokenData) {
|
|
@@ -12889,14 +12894,20 @@ class Rpc extends web3_js.Connection {
|
|
|
12889
12894
|
throw new web3_js.SolanaJSONRPCError(res.error, `failed to get info for compressed accounts owned by ${owner.toBase58()}`);
|
|
12890
12895
|
}
|
|
12891
12896
|
if (res.result.value === null) {
|
|
12892
|
-
return
|
|
12897
|
+
return {
|
|
12898
|
+
items: [],
|
|
12899
|
+
cursor: null,
|
|
12900
|
+
};
|
|
12893
12901
|
}
|
|
12894
12902
|
const accounts = [];
|
|
12895
12903
|
res.result.value.items.map(item => {
|
|
12896
12904
|
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);
|
|
12897
12905
|
accounts.push(account);
|
|
12898
12906
|
});
|
|
12899
|
-
return
|
|
12907
|
+
return {
|
|
12908
|
+
items: accounts.sort((a, b) => b.leafIndex - a.leafIndex),
|
|
12909
|
+
cursor: res.result.value.cursor,
|
|
12910
|
+
};
|
|
12900
12911
|
}
|
|
12901
12912
|
/**
|
|
12902
12913
|
* Fetch all the compressed token accounts owned by the specified public
|
|
@@ -12953,7 +12964,10 @@ class Rpc extends web3_js.Connection {
|
|
|
12953
12964
|
const maybeFiltered = options.mint
|
|
12954
12965
|
? res.result.value.tokenBalances.filter(tokenBalance => tokenBalance.mint.toBase58() === options.mint.toBase58())
|
|
12955
12966
|
: res.result.value.tokenBalances;
|
|
12956
|
-
return
|
|
12967
|
+
return {
|
|
12968
|
+
items: maybeFiltered,
|
|
12969
|
+
cursor: res.result.value.cursor,
|
|
12970
|
+
};
|
|
12957
12971
|
}
|
|
12958
12972
|
/**
|
|
12959
12973
|
* Returns confirmed compression signatures for transactions involving the specified
|
|
@@ -13033,7 +13047,7 @@ class Rpc extends web3_js.Connection {
|
|
|
13033
13047
|
if (res.result.value === null) {
|
|
13034
13048
|
throw new Error(`failed to get signatures for address ${address.toBase58()}`);
|
|
13035
13049
|
}
|
|
13036
|
-
return res.result.value
|
|
13050
|
+
return res.result.value;
|
|
13037
13051
|
}
|
|
13038
13052
|
/**
|
|
13039
13053
|
* Returns confirmed signatures for compression transactions involving the
|
|
@@ -13051,7 +13065,7 @@ class Rpc extends web3_js.Connection {
|
|
|
13051
13065
|
if (res.result.value === null) {
|
|
13052
13066
|
throw new Error(`failed to get signatures for owner ${owner.toBase58()}`);
|
|
13053
13067
|
}
|
|
13054
|
-
return res.result.value
|
|
13068
|
+
return res.result.value;
|
|
13055
13069
|
}
|
|
13056
13070
|
/// TODO(photon): needs mint
|
|
13057
13071
|
/**
|
|
@@ -13068,7 +13082,7 @@ class Rpc extends web3_js.Connection {
|
|
|
13068
13082
|
if (res.result.value === null) {
|
|
13069
13083
|
throw new Error(`failed to get signatures for owner ${owner.toBase58()}`);
|
|
13070
13084
|
}
|
|
13071
|
-
return res.result.value
|
|
13085
|
+
return res.result.value;
|
|
13072
13086
|
}
|
|
13073
13087
|
/**
|
|
13074
13088
|
* Fetch the current indexer health status
|
|
@@ -18707,16 +18721,22 @@ async function getCompressedTokenAccountsByOwnerTest(rpc, owner, mint) {
|
|
|
18707
18721
|
const events = await getParsedEvents(rpc);
|
|
18708
18722
|
const compressedTokenAccounts = await getCompressedTokenAccounts(events);
|
|
18709
18723
|
const accounts = compressedTokenAccounts.filter(acc => acc.parsed.owner.equals(owner) && acc.parsed.mint.equals(mint));
|
|
18710
|
-
return
|
|
18724
|
+
return {
|
|
18725
|
+
items: accounts.sort((a, b) => b.compressedAccount.leafIndex - a.compressedAccount.leafIndex),
|
|
18726
|
+
cursor: null,
|
|
18727
|
+
};
|
|
18711
18728
|
}
|
|
18712
18729
|
async function getCompressedTokenAccountsByDelegateTest(rpc, delegate, mint) {
|
|
18713
18730
|
const events = await getParsedEvents(rpc);
|
|
18714
18731
|
const compressedTokenAccounts = await getCompressedTokenAccounts(events);
|
|
18715
|
-
return
|
|
18716
|
-
|
|
18717
|
-
|
|
18718
|
-
acc.parsed.
|
|
18719
|
-
|
|
18732
|
+
return {
|
|
18733
|
+
items: compressedTokenAccounts.filter(acc => {
|
|
18734
|
+
var _a;
|
|
18735
|
+
return ((_a = acc.parsed.delegate) === null || _a === void 0 ? void 0 : _a.equals(delegate)) &&
|
|
18736
|
+
acc.parsed.mint.equals(mint);
|
|
18737
|
+
}),
|
|
18738
|
+
cursor: null,
|
|
18739
|
+
};
|
|
18720
18740
|
}
|
|
18721
18741
|
async function getCompressedTokenAccountByHashTest(rpc, hash) {
|
|
18722
18742
|
const events = await getParsedEvents(rpc);
|
|
@@ -18823,7 +18843,7 @@ class TestRpc extends web3_js.Connection {
|
|
|
18823
18843
|
*/
|
|
18824
18844
|
async getCompressedBalanceByOwner(owner) {
|
|
18825
18845
|
const accounts = await this.getCompressedAccountsByOwner(owner);
|
|
18826
|
-
return accounts.reduce((acc, account) => acc.add(account.lamports), bn(0));
|
|
18846
|
+
return accounts.items.reduce((acc, account) => acc.add(account.lamports), bn(0));
|
|
18827
18847
|
}
|
|
18828
18848
|
/**
|
|
18829
18849
|
* Fetch the latest merkle proof for the specified account hash from the
|
|
@@ -18898,7 +18918,10 @@ class TestRpc extends web3_js.Connection {
|
|
|
18898
18918
|
*/
|
|
18899
18919
|
async getCompressedAccountsByOwner(owner) {
|
|
18900
18920
|
const accounts = await getCompressedAccountsByOwnerTest(this, owner);
|
|
18901
|
-
return
|
|
18921
|
+
return {
|
|
18922
|
+
items: accounts,
|
|
18923
|
+
cursor: null,
|
|
18924
|
+
};
|
|
18902
18925
|
}
|
|
18903
18926
|
/**
|
|
18904
18927
|
* Fetch the latest compression signatures on the cluster. Results are
|
|
@@ -18940,10 +18963,13 @@ class TestRpc extends web3_js.Connection {
|
|
|
18940
18963
|
*/
|
|
18941
18964
|
async getCompressedTokenBalancesByOwner(publicKey, options) {
|
|
18942
18965
|
const accounts = await getCompressedTokenAccountsByOwnerTest(this, publicKey, options.mint);
|
|
18943
|
-
return
|
|
18944
|
-
|
|
18945
|
-
|
|
18946
|
-
|
|
18966
|
+
return {
|
|
18967
|
+
items: accounts.items.map(account => ({
|
|
18968
|
+
balance: bn(account.parsed.amount),
|
|
18969
|
+
mint: account.parsed.mint,
|
|
18970
|
+
})),
|
|
18971
|
+
cursor: null,
|
|
18972
|
+
};
|
|
18947
18973
|
}
|
|
18948
18974
|
/**
|
|
18949
18975
|
* Returns confirmed signatures for transactions involving the specified
|