From 041775d087bdb815b75244a166420702c051121f Mon Sep 17 00:00:00 2001 From: Swen Date: Tue, 30 Jul 2024 05:53:22 +0100 Subject: [PATCH] bump 1 bump 0.7.0 --- cli/package.json | 2 +- cli/src/utils/constants.ts | 2 +- js/compressed-token/package.json | 2 +- js/stateless.js/package.json | 2 +- js/stateless.js/src/rpc-interface.ts | 26 +++++++++-- js/stateless.js/src/rpc.ts | 44 ++++++++++++++++--- .../src/test-helpers/test-rpc/test-rpc.ts | 27 ++++++++++++ js/stateless.js/tests/e2e/rpc-interop.test.ts | 27 ++++++++++++ pnpm-lock.yaml | 4 ++ scripts/install.sh | 2 +- 10 files changed, 125 insertions(+), 13 deletions(-) diff --git a/cli/package.json b/cli/package.json index afc7ce15c9..dd7cf6367e 100644 --- a/cli/package.json +++ b/cli/package.json @@ -1,6 +1,6 @@ { "name": "@lightprotocol/zk-compression-cli", - "version": "0.5.1", + "version": "0.7.0", "description": "ZK Compression: Secure Scaling on Solana", "maintainers": [ { diff --git a/cli/src/utils/constants.ts b/cli/src/utils/constants.ts index 369feeffef..c35baab223 100644 --- a/cli/src/utils/constants.ts +++ b/cli/src/utils/constants.ts @@ -21,7 +21,7 @@ export const LIGHT_PROVER_PROCESS_NAME = "light-prover"; export const INDEXER_PROCESS_NAME = "photon"; export const FORESTER_PROCESS_NAME = "forester"; -export const PHOTON_VERSION = "0.38.0"; +export const PHOTON_VERSION = "0.39.0"; export const LIGHT_PROTOCOL_PROGRAMS_DIR_ENV = "LIGHT_PROTOCOL_PROGRAMS_DIR"; export const BASE_PATH = "../../bin/"; diff --git a/js/compressed-token/package.json b/js/compressed-token/package.json index ddd70c4fe6..43922d828a 100644 --- a/js/compressed-token/package.json +++ b/js/compressed-token/package.json @@ -1,6 +1,6 @@ { "name": "@lightprotocol/compressed-token", - "version": "0.4.1", + "version": "0.6.0", "description": "JS client to interact with the compressed-token program", "sideEffects": false, "type": "module", diff --git a/js/stateless.js/package.json b/js/stateless.js/package.json index d2c9239a62..1caa353be3 100644 --- a/js/stateless.js/package.json +++ b/js/stateless.js/package.json @@ -1,6 +1,6 @@ { "name": "@lightprotocol/stateless.js", - "version": "0.5.1", + "version": "0.7.0", "description": "JavaScript API for Light and ZK Compression", "sideEffects": false, "main": "dist/cjs/node/index.cjs", diff --git a/js/stateless.js/src/rpc-interface.ts b/js/stateless.js/src/rpc-interface.ts index 8d5946757c..91ffe63c3a 100644 --- a/js/stateless.js/src/rpc-interface.ts +++ b/js/stateless.js/src/rpc-interface.ts @@ -1,4 +1,4 @@ -import { PublicKey, DataSizeFilter, MemcmpFilter } from '@solana/web3.js'; +import { PublicKey, MemcmpFilter, DataSlice } from '@solana/web3.js'; import { type as pick, number, @@ -37,6 +37,13 @@ export interface LatestNonVotingSignatures { }; } +export interface GetCompressedAccountsByOwnerConfig { + filters?: GetCompressedAccountsFilter[]; + dataSlice?: DataSlice; + cursor?: string; + limit?: BN; +} + export interface LatestNonVotingSignaturesPaginated { context: { slot: number }; value: { @@ -97,14 +104,17 @@ export interface GetCompressedTokenAccountsByOwnerOrDelegateOptions { limit?: BN; } -export type GetCompressedAccountsFilter = MemcmpFilter | DataSizeFilter; +/** + * Note, DataSizeFilter is currently not available. + */ +export type GetCompressedAccountsFilter = MemcmpFilter; // | DataSizeFilter; export type GetCompressedAccountConfig = { encoding?: string; }; export type GetCompressedAccountsConfig = { - encoding?: string; + dataSlice: DataSlice; filters?: GetCompressedAccountsFilter[]; }; @@ -122,6 +132,10 @@ export type WithContext = { value: T; }; +export type WithCursor = { + cursor: PublicKey | null; + value: T; +}; /** * @internal */ @@ -477,8 +491,14 @@ export interface CompressionApiInterface { getCompressedAccountsByOwner( owner: PublicKey, + config?: GetCompressedAccountsByOwnerConfig, ): Promise; + getCompressedAccountsByOwnerWithCursor( + owner: PublicKey, + config?: GetCompressedAccountsByOwnerConfig, + ): Promise>; + getCompressedTokenAccountsByOwner( publicKey: PublicKey, options: GetCompressedTokenAccountsByOwnerOrDelegateOptions, diff --git a/js/stateless.js/src/rpc.ts b/js/stateless.js/src/rpc.ts index 3019e6203f..d5b8601347 100644 --- a/js/stateless.js/src/rpc.ts +++ b/js/stateless.js/src/rpc.ts @@ -35,6 +35,8 @@ import { LatestNonVotingSignaturesResultPaginated, LatestNonVotingSignaturesPaginated, WithContext, + GetCompressedAccountsByOwnerConfig, + WithCursor, } from './rpc-interface'; import { MerkleContextWithMerkleProof, @@ -657,19 +659,27 @@ export class Rpc extends Connection implements CompressionApiInterface { * Fetch all the compressed accounts owned by the specified public key. * Owner can be a program or user account */ - async getCompressedAccountsByOwner( + async getCompressedAccountsByOwnerWithCursor( owner: PublicKey, - ): Promise { + config?: GetCompressedAccountsByOwnerConfig, + ): Promise> { const unsafeRes = await rpcRequest( this.compressionApiEndpoint, 'getCompressedAccountsByOwner', - { owner: owner.toBase58() }, + { + owner: owner.toBase58(), + filters: config?.filters || [], + dataSlice: config?.dataSlice, + cursor: config?.cursor, + limit: config?.limit?.toNumber(), + }, ); const res = create( unsafeRes, jsonRpcResultAndContext(CompressedAccountsByOwnerResult), ); + if ('error' in res) { throw new SolanaJSONRPCError( res.error, @@ -677,7 +687,7 @@ export class Rpc extends Connection implements CompressionApiInterface { ); } if (res.result.value === null) { - return []; + return { cursor: null, value: [] }; } const accounts: CompressedAccountWithMerkleContext[] = []; @@ -698,7 +708,31 @@ export class Rpc extends Connection implements CompressionApiInterface { accounts.push(account); }); - return accounts.sort((a, b) => b.leafIndex - a.leafIndex); + return { + value: accounts.sort((a, b) => b.leafIndex - a.leafIndex), + cursor: res.result.value.cursor, + }; + } + /** + * Fetch all the compressed accounts owned by the specified public key. + * Owner can be a program or user account + * + * To use `config.limit` or `config.cursor`, please use {@link getCompressedAccountsByOwnerWithCursor} instead. + */ + async getCompressedAccountsByOwner( + owner: PublicKey, + config?: GetCompressedAccountsByOwnerConfig, + ): Promise { + if (config?.cursor || config?.limit) { + throw new Error( + 'To use `limit` and `cursor`, please use getCompressedAccountsByOwnerWithCursor instead.', + ); + } + const res = await this.getCompressedAccountsByOwnerWithCursor( + owner, + config, + ); + return res.value; } /** diff --git a/js/stateless.js/src/test-helpers/test-rpc/test-rpc.ts b/js/stateless.js/src/test-helpers/test-rpc/test-rpc.ts index 33ce7fb915..849b999a38 100644 --- a/js/stateless.js/src/test-helpers/test-rpc/test-rpc.ts +++ b/js/stateless.js/src/test-helpers/test-rpc/test-rpc.ts @@ -16,10 +16,12 @@ import { getParsedEvents } from './get-parsed-events'; import { defaultTestStateTreeAccounts } from '../../constants'; import { CompressedTransaction, + GetCompressedAccountsByOwnerConfig, LatestNonVotingSignatures, LatestNonVotingSignaturesPaginated, SignatureWithMetadata, WithContext, + WithCursor, } from '../../rpc-interface'; import { CompressedProofWithContext, @@ -333,10 +335,35 @@ export class TestRpc extends Connection implements CompressionApiInterface { */ async getCompressedAccountsByOwner( owner: PublicKey, + _config?: GetCompressedAccountsByOwnerConfig, ): Promise { + if (_config) { + throw new Error( + 'dataSlice or filters are not supported in test-rpc. Please use rpc.ts instead.', + ); + } + const accounts = await getCompressedAccountsByOwnerTest(this, owner); return accounts; } + /** + * Fetch all the compressed accounts owned by the specified public key. + * Owner can be a program or user account + * Returns with cursor + */ + async getCompressedAccountsByOwnerWithCursor( + owner: PublicKey, + _config?: GetCompressedAccountsByOwnerConfig, + ): Promise> { + if (_config) { + throw new Error( + 'dataSlice or filters are not supported in test-rpc. Please use rpc.ts instead.', + ); + } + + const accounts = await getCompressedAccountsByOwnerTest(this, owner); + return { cursor: null, value: accounts }; + } /** * Fetch the latest compression signatures on the cluster. Results are diff --git a/js/stateless.js/tests/e2e/rpc-interop.test.ts b/js/stateless.js/tests/e2e/rpc-interop.test.ts index 4f534a4b19..845458526e 100644 --- a/js/stateless.js/tests/e2e/rpc-interop.test.ts +++ b/js/stateless.js/tests/e2e/rpc-interop.test.ts @@ -40,6 +40,33 @@ describe('rpc-interop', () => { const transferAmount = 1e4; const numberOfTransfers = 15; + it('getCompressedAccountsByOnwer [noforester] filter should work', async () => { + let accs = await rpc.getCompressedAccountsByOwner(payer.publicKey, { + filters: [ + { + memcmp: { + offset: 1, + bytes: '5Vf', + }, + }, + ], + }); + assert.equal(accs.length, 0); + + accs = await rpc.getCompressedAccountsByOwner(payer.publicKey, { + dataSlice: { offset: 1, length: 2 }, + }); + /// TODO: DataSlice filter does not work in photon. Adapt once photon is fixed. + assert.equal(accs.length, 1); + + accs = ( + await rpc.getCompressedAccountsByOwnerWithCursor(payer.publicKey, { + dataSlice: { offset: 1, length: 2 }, + limit: bn(1), + }) + ).value; + assert.equal(accs.length, 1); + }); it('getValidityProof [noforester] (inclusion) should match', async () => { const senderAccounts = await rpc.getCompressedAccountsByOwner( payer.publicKey, diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 79c1560b41..58f8bd0153 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -382,6 +382,10 @@ importers: specifier: ^1.6.0 version: 1.6.0(@types/node@20.12.11)(@vitest/browser@1.6.0)(terser@5.31.0) + hasher.rs/src/main/wasm: {} + + hasher.rs/src/main/wasm-simd: {} + js/compressed-token: dependencies: '@coral-xyz/anchor': diff --git a/scripts/install.sh b/scripts/install.sh index cfdefd6aa7..9fa05af002 100755 --- a/scripts/install.sh +++ b/scripts/install.sh @@ -114,7 +114,7 @@ PNPM_VERSION="9.5.0" SOLANA_VERSION="1.18.11" ANCHOR_VERSION="anchor-v0.29.0" JQ_VERSION="jq-1.7.1" -PHOTON_VERSION="0.38.0" +PHOTON_VERSION="0.39.0" PHOTON_BRANCH="" case "${OS}" in