Skip to content

Commit

Permalink
chore: js rpc update (JS 0.4.1) (#870)
Browse files Browse the repository at this point in the history
* add getLatestNonVotingSignatures, no testcov for cursor

* add limit, cursor, opt mint to token endpoints

* remove cursor

* add test: getCompressedTokenAccountsByOwner without mint filter

* getCompressionSignaturesForAddress skip

* mark fn deprecated

* sync name getCompressionSignaturesForAccount

* getLatestCompressionSignatures

* moved interfaces

* cleanup

* linted

* fix

* doc

* released, bump

* make options optional

---------

Co-authored-by: Swen <[email protected]>
  • Loading branch information
SwenSchaeferjohann and Swen authored Jun 26, 2024
1 parent 3bfbcaf commit f576164
Show file tree
Hide file tree
Showing 9 changed files with 379 additions and 76 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.4.2",
"version": "0.4.3",
"description": "ZK Compression: Secure Scaling on Solana",
"maintainers": [
{
Expand Down
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.3.0",
"version": "0.3.1",
"description": "JS client to interact with the compressed-token program",
"sideEffects": false,
"type": "module",
Expand Down
30 changes: 30 additions & 0 deletions js/compressed-token/tests/e2e/rpc-token-interop.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -168,4 +168,34 @@ describe('rpc-interop token', () => {

assert.equal(accs.length, 0);
});

it('[rpc] getCompressedTokenAccountsByOwner with 2 mints should return both mints', async () => {
// additional mint
const mint2 = (
await createMint(
rpc,
payer,
mintAuthority.publicKey,
TEST_TOKEN_DECIMALS,
)
).mint;

await mintTo(rpc, payer, mint2, bob.publicKey, mintAuthority, bn(1000));

const senderAccounts = await rpc.getCompressedTokenAccountsByOwner(
bob.publicKey,
);

// check that mint and mint2 exist in list of senderaccounts at least once
assert.isTrue(
senderAccounts.some(
account => account.parsed.mint.toBase58() === mint.toBase58(),
),
);
assert.isTrue(
senderAccounts.some(
account => account.parsed.mint.toBase58() === mint2.toBase58(),
),
);
});
});
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.4.0",
"version": "0.4.1",
"description": "JavaScript API for Light and ZK Compression",
"sideEffects": false,
"main": "dist/cjs/node/index.cjs",
Expand Down
76 changes: 64 additions & 12 deletions js/stateless.js/src/rpc-interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,21 @@ import {
} from './state';
import { BN } from '@coral-xyz/anchor';

export interface LatestNonVotingSignatures {
context: { slot: number };
value: {
items: { signature: string; slot: number; blockTime: number }[];
};
}

export interface LatestNonVotingSignaturesPaginated {
context: { slot: number };
value: {
items: { signature: string; slot: number; blockTime: number }[];
cursor: string | null;
};
}

export interface SignatureWithMetadata {
blockTime: number;
signature: string;
Expand Down Expand Up @@ -68,7 +83,7 @@ export type CompressedProofWithContext = {
};

export interface GetCompressedTokenAccountsByOwnerOrDelegateOptions {
mint: PublicKey;
mint?: PublicKey;
cursor?: string;
limit?: BN;
}
Expand Down Expand Up @@ -259,6 +274,33 @@ export const SlotResult = number();
*/
export const HealthResult = string();

/**
* @internal
*/
export const LatestNonVotingSignaturesResult = pick({
items: array(
pick({
signature: string(),
slot: number(),
blockTime: number(),
}),
),
});

/**
* @internal
*/
export const LatestNonVotingSignaturesResultPaginated = pick({
items: array(
pick({
signature: string(),
slot: number(),
blockTime: number(),
}),
),
cursor: nullable(string()),
});

/**
* @internal
*/
Expand Down Expand Up @@ -386,10 +428,11 @@ export const CompressedTransactionResult = pick({

export interface CompressionApiInterface {
getCompressedAccount(
hash: BN254,
address?: BN254,
hash?: BN254,
): Promise<CompressedAccountWithMerkleContext | null>;

getCompressedBalance(hash: BN254): Promise<BN | null>;
getCompressedBalance(address?: BN254, hash?: BN254): Promise<BN | null>;

getCompressedBalanceByOwner(owner: PublicKey): Promise<BN>;

Expand All @@ -405,6 +448,11 @@ export interface CompressionApiInterface {
hashes: BN254[],
): Promise<MerkleContextWithMerkleProof[]>;

getValidityProof(
hashes: BN254[],
newAddresses: BN254[],
): Promise<CompressedProofWithContext>;

getCompressedAccountsByOwner(
owner: PublicKey,
): Promise<CompressedAccountWithMerkleContext[]>;
Expand All @@ -426,14 +474,14 @@ export interface CompressionApiInterface {
options: GetCompressedTokenAccountsByOwnerOrDelegateOptions,
): Promise<{ balance: BN; mint: PublicKey }[]>;

getSignaturesForCompressedAccount(
hash: BN254,
): Promise<SignatureWithMetadata[]>;

getTransactionWithCompressionInfo(
signature: string,
): Promise<CompressedTransaction | null>;

getCompressionSignaturesForAccount(
hash: BN254,
): Promise<SignatureWithMetadata[]>;

getCompressionSignaturesForAddress(
address: PublicKey,
): Promise<SignatureWithMetadata[]>;
Expand All @@ -446,12 +494,16 @@ export interface CompressionApiInterface {
owner: PublicKey,
): Promise<SignatureWithMetadata[]>;

getLatestNonVotingSignatures(
limit?: number,
): Promise<LatestNonVotingSignatures>;

getLatestCompressionSignatures(
cursor?: string,
limit?: number,
): Promise<LatestNonVotingSignaturesPaginated>;

getIndexerHealth(): Promise<string>;

getIndexerSlot(): Promise<number>;

getValidityProof(
hashes: BN254[],
newAddresses: BN254[],
): Promise<CompressedProofWithContext>;
}
Loading

0 comments on commit f576164

Please sign in to comment.