@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/es/browser/index.js
CHANGED
|
@@ -6989,15 +6989,16 @@ if (import.meta.vitest) {
|
|
|
6989
6989
|
* @param instructions instructions to include
|
|
6990
6990
|
* @param payerPublicKey fee payer public key
|
|
6991
6991
|
* @param blockhash blockhash to use
|
|
6992
|
+
* @param lookupTableAccounts lookup table accounts to include
|
|
6992
6993
|
*
|
|
6993
6994
|
* @return VersionedTransaction
|
|
6994
6995
|
*/
|
|
6995
|
-
function buildTx(instructions, payerPublicKey, blockhash) {
|
|
6996
|
+
function buildTx(instructions, payerPublicKey, blockhash, lookupTableAccounts) {
|
|
6996
6997
|
const messageV0 = new TransactionMessage({
|
|
6997
6998
|
payerKey: payerPublicKey,
|
|
6998
6999
|
recentBlockhash: blockhash,
|
|
6999
7000
|
instructions,
|
|
7000
|
-
}).compileToV0Message();
|
|
7001
|
+
}).compileToV0Message(lookupTableAccounts);
|
|
7001
7002
|
return new VersionedTransaction(messageV0);
|
|
7002
7003
|
}
|
|
7003
7004
|
/**
|
|
@@ -7053,12 +7054,13 @@ async function confirmTx(rpc, txId, confirmOptions, blockHashCtx) {
|
|
|
7053
7054
|
* @param payer payer of the transaction
|
|
7054
7055
|
* @param blockhash recent blockhash to use in the transaction
|
|
7055
7056
|
* @param additionalSigners non-feepayer signers to include in the transaction
|
|
7057
|
+
* @param lookupTableAccounts lookup table accounts to include in the transaction
|
|
7056
7058
|
*/
|
|
7057
|
-
function buildAndSignTx(instructions, payer, blockhash, additionalSigners = []) {
|
|
7059
|
+
function buildAndSignTx(instructions, payer, blockhash, additionalSigners = [], lookupTableAccounts) {
|
|
7058
7060
|
if (additionalSigners.includes(payer))
|
|
7059
7061
|
throw new Error('payer must not be in additionalSigners');
|
|
7060
7062
|
const allSigners = [payer, ...additionalSigners];
|
|
7061
|
-
const tx = buildTx(instructions, payer.publicKey, blockhash);
|
|
7063
|
+
const tx = buildTx(instructions, payer.publicKey, blockhash, lookupTableAccounts);
|
|
7062
7064
|
tx.sign(allSigners);
|
|
7063
7065
|
return tx;
|
|
7064
7066
|
}
|
|
@@ -7508,7 +7510,7 @@ async function createAccount(rpc, payer, seed, programId, addressTree, addressQu
|
|
|
7508
7510
|
async function createAccountWithLamports(rpc, payer, seed, lamports, programId, addressTree, addressQueue, outputStateTree, confirmOptions) {
|
|
7509
7511
|
lamports = bn(lamports);
|
|
7510
7512
|
const compressedAccounts = await rpc.getCompressedAccountsByOwner(payer.publicKey);
|
|
7511
|
-
const [inputAccounts] = selectMinCompressedSolAccountsForTransfer(compressedAccounts, lamports);
|
|
7513
|
+
const [inputAccounts] = selectMinCompressedSolAccountsForTransfer(compressedAccounts.items, lamports);
|
|
7512
7514
|
const { blockhash } = await rpc.getLatestBlockhash();
|
|
7513
7515
|
addressTree = addressTree ?? defaultTestStateTreeAccounts().addressTree;
|
|
7514
7516
|
addressQueue = addressQueue ?? defaultTestStateTreeAccounts().addressQueue;
|
|
@@ -7555,7 +7557,7 @@ async function createAccountWithLamports(rpc, payer, seed, lamports, programId,
|
|
|
7555
7557
|
/// TODO: add support for payer != owner
|
|
7556
7558
|
async function decompress(rpc, payer, lamports, recipient, outputStateTree, confirmOptions) {
|
|
7557
7559
|
/// TODO: use dynamic state tree and nullifier queue
|
|
7558
|
-
const userCompressedAccountsWithMerkleContext = await rpc.getCompressedAccountsByOwner(payer.publicKey);
|
|
7560
|
+
const userCompressedAccountsWithMerkleContext = (await rpc.getCompressedAccountsByOwner(payer.publicKey)).items;
|
|
7559
7561
|
lamports = bn(lamports);
|
|
7560
7562
|
const inputLamports = sumUpLamports(userCompressedAccountsWithMerkleContext);
|
|
7561
7563
|
if (lamports.gt(inputLamports)) {
|
|
@@ -7605,7 +7607,7 @@ async function transfer(rpc, payer, lamports, owner, toAddress,
|
|
|
7605
7607
|
merkleTree, confirmOptions) {
|
|
7606
7608
|
lamports = bn(lamports);
|
|
7607
7609
|
const compressedAccounts = await rpc.getCompressedAccountsByOwner(owner.publicKey);
|
|
7608
|
-
const [inputAccounts] = selectMinCompressedSolAccountsForTransfer(compressedAccounts, lamports);
|
|
7610
|
+
const [inputAccounts] = selectMinCompressedSolAccountsForTransfer(compressedAccounts.items, lamports);
|
|
7609
7611
|
const proof = await rpc.getValidityProof(inputAccounts.map(account => bn(account.hash)));
|
|
7610
7612
|
const ix = await LightSystemProgram.transfer({
|
|
7611
7613
|
payer: payer.publicKey,
|
|
@@ -12446,14 +12448,14 @@ const MultipleCompressedAccountsResult = type({
|
|
|
12446
12448
|
*/
|
|
12447
12449
|
const CompressedAccountsByOwnerResult = type({
|
|
12448
12450
|
items: array(CompressedAccountResult),
|
|
12449
|
-
cursor: nullable(
|
|
12451
|
+
cursor: nullable(string()),
|
|
12450
12452
|
});
|
|
12451
12453
|
/**
|
|
12452
12454
|
* @internal
|
|
12453
12455
|
*/
|
|
12454
12456
|
const CompressedTokenAccountsByOwnerOrDelegateResult = type({
|
|
12455
12457
|
items: array(CompressedTokenAccountResult),
|
|
12456
|
-
cursor: nullable(
|
|
12458
|
+
cursor: nullable(string()),
|
|
12457
12459
|
});
|
|
12458
12460
|
/**
|
|
12459
12461
|
* @internal
|
|
@@ -12548,7 +12550,7 @@ const TokenBalanceResult = type({
|
|
|
12548
12550
|
});
|
|
12549
12551
|
const TokenBalanceListResult = type({
|
|
12550
12552
|
tokenBalances: array(TokenBalanceResult),
|
|
12551
|
-
cursor: nullable(
|
|
12553
|
+
cursor: nullable(string()),
|
|
12552
12554
|
});
|
|
12553
12555
|
const AccountProofResult = type({
|
|
12554
12556
|
hash: array(number()),
|
|
@@ -12571,7 +12573,7 @@ const SignatureListWithCursorResult = type({
|
|
|
12571
12573
|
signature: string(),
|
|
12572
12574
|
slot: number(),
|
|
12573
12575
|
})),
|
|
12574
|
-
cursor: nullable(
|
|
12576
|
+
cursor: nullable(string()),
|
|
12575
12577
|
});
|
|
12576
12578
|
const CompressedTransactionResult = type({
|
|
12577
12579
|
compressionInfo: type({
|
|
@@ -12638,7 +12640,10 @@ async function getCompressedTokenAccountsByOwnerOrDelegate(rpc, ownerOrDelegate,
|
|
|
12638
12640
|
});
|
|
12639
12641
|
});
|
|
12640
12642
|
/// TODO: consider custom or different sort. Most recent here.
|
|
12641
|
-
return
|
|
12643
|
+
return {
|
|
12644
|
+
items: accounts.sort((a, b) => b.compressedAccount.leafIndex - a.compressedAccount.leafIndex),
|
|
12645
|
+
cursor: res.result.value.cursor,
|
|
12646
|
+
};
|
|
12642
12647
|
}
|
|
12643
12648
|
/** @internal */
|
|
12644
12649
|
function buildCompressedAccountWithMaybeTokenData(accountStructWithOptionalTokenData) {
|
|
@@ -12930,14 +12935,20 @@ class Rpc extends Connection {
|
|
|
12930
12935
|
throw new SolanaJSONRPCError(res.error, `failed to get info for compressed accounts owned by ${owner.toBase58()}`);
|
|
12931
12936
|
}
|
|
12932
12937
|
if (res.result.value === null) {
|
|
12933
|
-
return
|
|
12938
|
+
return {
|
|
12939
|
+
items: [],
|
|
12940
|
+
cursor: null,
|
|
12941
|
+
};
|
|
12934
12942
|
}
|
|
12935
12943
|
const accounts = [];
|
|
12936
12944
|
res.result.value.items.map(item => {
|
|
12937
12945
|
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);
|
|
12938
12946
|
accounts.push(account);
|
|
12939
12947
|
});
|
|
12940
|
-
return
|
|
12948
|
+
return {
|
|
12949
|
+
items: accounts.sort((a, b) => b.leafIndex - a.leafIndex),
|
|
12950
|
+
cursor: res.result.value.cursor,
|
|
12951
|
+
};
|
|
12941
12952
|
}
|
|
12942
12953
|
/**
|
|
12943
12954
|
* Fetch all the compressed token accounts owned by the specified public
|
|
@@ -12993,7 +13004,10 @@ class Rpc extends Connection {
|
|
|
12993
13004
|
const maybeFiltered = options.mint
|
|
12994
13005
|
? res.result.value.tokenBalances.filter(tokenBalance => tokenBalance.mint.toBase58() === options.mint.toBase58())
|
|
12995
13006
|
: res.result.value.tokenBalances;
|
|
12996
|
-
return
|
|
13007
|
+
return {
|
|
13008
|
+
items: maybeFiltered,
|
|
13009
|
+
cursor: res.result.value.cursor,
|
|
13010
|
+
};
|
|
12997
13011
|
}
|
|
12998
13012
|
/**
|
|
12999
13013
|
* Returns confirmed compression signatures for transactions involving the specified
|
|
@@ -13073,7 +13087,7 @@ class Rpc extends Connection {
|
|
|
13073
13087
|
if (res.result.value === null) {
|
|
13074
13088
|
throw new Error(`failed to get signatures for address ${address.toBase58()}`);
|
|
13075
13089
|
}
|
|
13076
|
-
return res.result.value
|
|
13090
|
+
return res.result.value;
|
|
13077
13091
|
}
|
|
13078
13092
|
/**
|
|
13079
13093
|
* Returns confirmed signatures for compression transactions involving the
|
|
@@ -13091,7 +13105,7 @@ class Rpc extends Connection {
|
|
|
13091
13105
|
if (res.result.value === null) {
|
|
13092
13106
|
throw new Error(`failed to get signatures for owner ${owner.toBase58()}`);
|
|
13093
13107
|
}
|
|
13094
|
-
return res.result.value
|
|
13108
|
+
return res.result.value;
|
|
13095
13109
|
}
|
|
13096
13110
|
/// TODO(photon): needs mint
|
|
13097
13111
|
/**
|
|
@@ -13108,7 +13122,7 @@ class Rpc extends Connection {
|
|
|
13108
13122
|
if (res.result.value === null) {
|
|
13109
13123
|
throw new Error(`failed to get signatures for owner ${owner.toBase58()}`);
|
|
13110
13124
|
}
|
|
13111
|
-
return res.result.value
|
|
13125
|
+
return res.result.value;
|
|
13112
13126
|
}
|
|
13113
13127
|
/**
|
|
13114
13128
|
* Fetch the current indexer health status
|
|
@@ -18768,13 +18782,19 @@ async function getCompressedTokenAccountsByOwnerTest(rpc, owner, mint) {
|
|
|
18768
18782
|
const events = await getParsedEvents(rpc);
|
|
18769
18783
|
const compressedTokenAccounts = await getCompressedTokenAccounts(events);
|
|
18770
18784
|
const accounts = compressedTokenAccounts.filter(acc => acc.parsed.owner.equals(owner) && acc.parsed.mint.equals(mint));
|
|
18771
|
-
return
|
|
18785
|
+
return {
|
|
18786
|
+
items: accounts.sort((a, b) => b.compressedAccount.leafIndex - a.compressedAccount.leafIndex),
|
|
18787
|
+
cursor: null,
|
|
18788
|
+
};
|
|
18772
18789
|
}
|
|
18773
18790
|
async function getCompressedTokenAccountsByDelegateTest(rpc, delegate, mint) {
|
|
18774
18791
|
const events = await getParsedEvents(rpc);
|
|
18775
18792
|
const compressedTokenAccounts = await getCompressedTokenAccounts(events);
|
|
18776
|
-
return
|
|
18777
|
-
acc.parsed.
|
|
18793
|
+
return {
|
|
18794
|
+
items: compressedTokenAccounts.filter(acc => acc.parsed.delegate?.equals(delegate) &&
|
|
18795
|
+
acc.parsed.mint.equals(mint)),
|
|
18796
|
+
cursor: null,
|
|
18797
|
+
};
|
|
18778
18798
|
}
|
|
18779
18799
|
async function getCompressedTokenAccountByHashTest(rpc, hash) {
|
|
18780
18800
|
const events = await getParsedEvents(rpc);
|
|
@@ -18889,7 +18909,7 @@ class TestRpc extends Connection {
|
|
|
18889
18909
|
*/
|
|
18890
18910
|
async getCompressedBalanceByOwner(owner) {
|
|
18891
18911
|
const accounts = await this.getCompressedAccountsByOwner(owner);
|
|
18892
|
-
return accounts.reduce((acc, account) => acc.add(account.lamports), bn(0));
|
|
18912
|
+
return accounts.items.reduce((acc, account) => acc.add(account.lamports), bn(0));
|
|
18893
18913
|
}
|
|
18894
18914
|
/**
|
|
18895
18915
|
* Fetch the latest merkle proof for the specified account hash from the
|
|
@@ -18964,7 +18984,10 @@ class TestRpc extends Connection {
|
|
|
18964
18984
|
*/
|
|
18965
18985
|
async getCompressedAccountsByOwner(owner) {
|
|
18966
18986
|
const accounts = await getCompressedAccountsByOwnerTest(this, owner);
|
|
18967
|
-
return
|
|
18987
|
+
return {
|
|
18988
|
+
items: accounts,
|
|
18989
|
+
cursor: null,
|
|
18990
|
+
};
|
|
18968
18991
|
}
|
|
18969
18992
|
/**
|
|
18970
18993
|
* Fetch the latest compression signatures on the cluster. Results are
|
|
@@ -19006,10 +19029,13 @@ class TestRpc extends Connection {
|
|
|
19006
19029
|
*/
|
|
19007
19030
|
async getCompressedTokenBalancesByOwner(publicKey, options) {
|
|
19008
19031
|
const accounts = await getCompressedTokenAccountsByOwnerTest(this, publicKey, options.mint);
|
|
19009
|
-
return
|
|
19010
|
-
|
|
19011
|
-
|
|
19012
|
-
|
|
19032
|
+
return {
|
|
19033
|
+
items: accounts.items.map(account => ({
|
|
19034
|
+
balance: bn(account.parsed.amount),
|
|
19035
|
+
mint: account.parsed.mint,
|
|
19036
|
+
})),
|
|
19037
|
+
cursor: null,
|
|
19038
|
+
};
|
|
19013
19039
|
}
|
|
19014
19040
|
/**
|
|
19015
19041
|
* Returns confirmed signatures for transactions involving the specified
|