Skip to content

Commit

Permalink
bump 1
Browse files Browse the repository at this point in the history
bump 0.7.0
  • Loading branch information
Swen committed Aug 19, 2024
1 parent 3867c58 commit 041775d
Show file tree
Hide file tree
Showing 10 changed files with 125 additions and 13 deletions.
2 changes: 1 addition & 1 deletion cli/package.json
Original file line number Diff line number Diff line change
@@ -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": [
{
Expand Down
2 changes: 1 addition & 1 deletion cli/src/utils/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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/";
2 changes: 1 addition & 1 deletion js/compressed-token/package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
2 changes: 1 addition & 1 deletion js/stateless.js/package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
26 changes: 23 additions & 3 deletions js/stateless.js/src/rpc-interface.ts
Original file line number Diff line number Diff line change
@@ -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,
Expand Down Expand Up @@ -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: {
Expand Down Expand Up @@ -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[];
};

Expand All @@ -122,6 +132,10 @@ export type WithContext<T> = {
value: T;
};

export type WithCursor<T> = {
cursor: PublicKey | null;
value: T;
};
/**
* @internal
*/
Expand Down Expand Up @@ -477,8 +491,14 @@ export interface CompressionApiInterface {

getCompressedAccountsByOwner(
owner: PublicKey,
config?: GetCompressedAccountsByOwnerConfig,
): Promise<CompressedAccountWithMerkleContext[]>;

getCompressedAccountsByOwnerWithCursor(
owner: PublicKey,
config?: GetCompressedAccountsByOwnerConfig,
): Promise<WithCursor<CompressedAccountWithMerkleContext[]>>;

getCompressedTokenAccountsByOwner(
publicKey: PublicKey,
options: GetCompressedTokenAccountsByOwnerOrDelegateOptions,
Expand Down
44 changes: 39 additions & 5 deletions js/stateless.js/src/rpc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ import {
LatestNonVotingSignaturesResultPaginated,
LatestNonVotingSignaturesPaginated,
WithContext,
GetCompressedAccountsByOwnerConfig,
WithCursor,
} from './rpc-interface';
import {
MerkleContextWithMerkleProof,
Expand Down Expand Up @@ -657,27 +659,35 @@ 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<CompressedAccountWithMerkleContext[]> {
config?: GetCompressedAccountsByOwnerConfig,
): Promise<WithCursor<CompressedAccountWithMerkleContext[]>> {
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,
`failed to get info for compressed accounts owned by ${owner.toBase58()}`,
);
}
if (res.result.value === null) {
return [];
return { cursor: null, value: [] };
}
const accounts: CompressedAccountWithMerkleContext[] = [];

Expand All @@ -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<CompressedAccountWithMerkleContext[]> {
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;
}

/**
Expand Down
27 changes: 27 additions & 0 deletions js/stateless.js/src/test-helpers/test-rpc/test-rpc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -333,10 +335,35 @@ export class TestRpc extends Connection implements CompressionApiInterface {
*/
async getCompressedAccountsByOwner(
owner: PublicKey,
_config?: GetCompressedAccountsByOwnerConfig,
): Promise<CompressedAccountWithMerkleContext[]> {
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<WithCursor<CompressedAccountWithMerkleContext[]>> {
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
Expand Down
27 changes: 27 additions & 0 deletions js/stateless.js/tests/e2e/rpc-interop.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
4 changes: 4 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion scripts/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 041775d

Please sign in to comment.