Skip to content

Commit

Permalink
feat: bump to 0.50.0, add getCompressedTokenBalancesByOwnerV2 (#1353)
Browse files Browse the repository at this point in the history
* bump to 0.50.0, add getCompressedTokenBalancesByOwnerV2, extend rem. endpoints with opt. cursors

* upd name paginatedoptions

* released js

* add --no-reset flag to install.sh

* clean readme

* upd readme

* upd readme for ctoken

* capitalization

* bump js release, readme updates

---------

Co-authored-by: Swenschaeferjohann <[email protected]>
  • Loading branch information
SwenSchaeferjohann and Swenschaeferjohann authored Nov 20, 2024
1 parent bb82a7e commit 80fb05c
Show file tree
Hide file tree
Showing 12 changed files with 227 additions and 59 deletions.
6 changes: 2 additions & 4 deletions cli/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# ZK Compression CLI

CLI to interact with ZK compression.
CLI to interact with compressed accounts and compressed tokens on Solana.

## Requirements

Expand Down Expand Up @@ -179,9 +179,7 @@ FLAGS
```

#### Compress native SOL

> **Note:** Ensure the SOL omnibus account of the Light system program is already initialized by running: `light init-sol-pool`
#### Assign native SOL to a compressed account

```bash
light compress-sol --amount 1000 --to "YOUR_WALLET_ADDRESS_BASE58"
Expand Down
6 changes: 5 additions & 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.19.3",
"version": "0.20.1",
"description": "ZK Compression: Secure Scaling on Solana",
"maintainers": [
{
Expand All @@ -21,6 +21,10 @@
"./config.json",
"/npm-shrinkwrap.json",
"/oclif.manifest.json",
"!bin/proving-keys/address-append_26_1.key",
"!bin/proving-keys/address-append_26_1.vkey",
"!bin/proving-keys/address-append_26_10.key",
"!bin/proving-keys/address-append_26_10.vkey",
"!bin/proving-keys/append-with-proofs_26_10.key",
"!bin/proving-keys/append-with-proofs_26_10.vkey",
"!bin/proving-keys/append-with-subtrees_26_10.key",
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 @@ -19,7 +19,7 @@ export const SOLANA_VALIDATOR_PROCESS_NAME = "solana-test-validator";
export const LIGHT_PROVER_PROCESS_NAME = "light-prover";
export const INDEXER_PROCESS_NAME = "photon";

export const PHOTON_VERSION = "0.48.0";
export const PHOTON_VERSION = "0.50.0";

export const LIGHT_PROTOCOL_PROGRAMS_DIR_ENV = "LIGHT_PROTOCOL_PROGRAMS_DIR";
export const BASE_PATH = "../../bin/";
Expand Down
26 changes: 19 additions & 7 deletions js/compressed-token/README.md
Original file line number Diff line number Diff line change
@@ -1,24 +1,36 @@
# TS client for Interacting with the Compressed-Token Program
<p align="center">
<img src="https://github.com/ldiego08/light-protocol/raw/main/assets/logo.svg" width="90" />
</p>

<h1 align="center">@lightprotocol/compressed-token</h1>

<p align="center">
<b>This is the JavaScript SDK for interacting with the Compressed Token program on Solana.</b>
</p>

<p align="center">
<a href="https://badge.fury.io/js/@lightprotocol%2Fcompressed-token">
<img src="https://badge.fury.io/js/@lightprotocol%2Fcompressed-token.svg" alt="package npm version" height="18" />
</a>
<img src="https://img.shields.io/npm/l/%40lightprotocol%2Fcompressed-token" alt="package license" height="18">
<img src="https://img.shields.io/npm/dw/%40lightprotocol%2Fcompressed-token" alt="package weekly downloads" height="18" />
</p>

Use this to interact with the compressed-token program on Solana via the
Compression RPC API.

### Installation

**For use in Node.js or a web application**
**For use in Node.js or web**

```bash
npm install --save \
@lightprotocol/compressed-token \
@lightprotocol/stateless.js \
@solana/web3.js \
@coral-xyz/[email protected]
```

### Documentation and examples

- [Latest Source code](https://github.com/lightprotocol/lightprotocol/tree/main/js/compressed-token)
- Documentation and examples will be linked here soon!
- [Creating and sending compressed tokens](https://www.zkcompression.com/developers/typescript-client#creating-minting-and-transferring-a-compressed-token)

### Getting help

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.14.3",
"version": "0.15.1",
"description": "JS client to interact with the compressed-token program",
"sideEffects": false,
"main": "dist/cjs/node/index.cjs",
Expand Down
38 changes: 38 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 @@ -152,6 +152,44 @@ describe('rpc-interop token', () => {
});
});


it('getCompressedTokenBalancesByOwnerV2 should match', async () => {
const balances = (
await rpc.getCompressedTokenBalancesByOwnerV2(bob.publicKey, {
mint,
})
).value.items;
const balancesTest = (
await testRpc.getCompressedTokenBalancesByOwnerV2(bob.publicKey, {
mint,
})
).value.items;

assert.equal(balances.length, balancesTest.length);

balances.forEach((balance, index) => {
assert.isTrue(balance.balance.eq(balancesTest[index].balance));
});

const balancesReceiver = (
await rpc.getCompressedTokenBalancesByOwnerV2(charlie.publicKey, {
mint,
})
).value.items;
const balancesReceiverTest = (
await testRpc.getCompressedTokenBalancesByOwnerV2(charlie.publicKey, {
mint,
})
).value.items;

assert.equal(balancesReceiver.length, balancesReceiverTest.length);
balancesReceiver.forEach((balance, index) => {
assert.isTrue(
balance.balance.eq(balancesReceiverTest[index].balance),
);
});
});

it('[test-rpc missing] getSignaturesForTokenOwner should match', async () => {
const signatures = (
await rpc.getCompressionSignaturesForTokenOwner(bob.publicKey)
Expand Down
26 changes: 5 additions & 21 deletions js/stateless.js/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
<img src="https://github.com/ldiego08/light-protocol/raw/main/assets/logo.svg" width="90" />
</p>

<h1 align="center">Stateless.js</h1>
<h1 align="center">@lightprotocol/stateless.js</h1>

<p align="center">
<b>Integrate server and web applications with ZK Compression on Solana.</b>
<b>This is the JavaScript SDK for building Solana applications with ZK Compression for Node and web.</b>
</p>

<p align="center">
Expand All @@ -16,37 +16,21 @@
<img src="https://img.shields.io/npm/dw/%40lightprotocol%2Fstateless.js" alt="package weekly downloads" height="18" />
</p>

## Overview

This package provides server and web applications with clients, utilities, and types to leverage the power of [ZK Compression](https://www.zkcompression.com/) on Solana via the Compression RPC API.

> The core ZK Compression Solana programs and clients are maintained by
> [Light](https://github.com/lightprotocol) as a part of the Light Protocol. The RPC API and indexer are maintained by
> [Helius Labs](https://github.com/helius-labs).
## Usage

### Installation

Install this package in your project by running the following terminal command:

```bin
npm install --save \
@lightprotocol/stateless.js \
@solana/web3.js \
@coral-xyz/[email protected]
npm install --save @lightprotocol/stateless.js
```

### Dependencies

- [`@solana/web3.js`](https://www.npmjs.com/package/@solana/web3.js) — provides access to the Solana network via RPC.
- [`@coral-xyz/anchor`](https://www.npmjs.com/package/@coral-xyz/anchor) — a client for [Anchor](https://www.anchor-lang.com/) Solana programs.

## Documentation and Examples

For a more detailed documentation on usage, please check [the respective section at the ZK Compression documentation.](https://www.zkcompression.com/developers/typescript-client)

For example implementations, including web and server, refer to the respective repositories:
For example implementations, including web and Node, refer to the respective repositories:

- [Web application example implementation](https://github.com/Lightprotocol/example-web-client)

Expand All @@ -55,7 +39,7 @@ For example implementations, including web and server, refer to the respective r
## Troubleshooting

Have a question or a problem?
Feel free to ask in the [Light](https://discord.gg/CYvjBgzRFP) and [Helius](https://discord.gg/Uzzf6a7zKr) developer Discord servers. Please, include the following information to better be able to respond:
Feel free to ask in the [Light](https://discord.gg/CYvjBgzRFP) and [Helius](https://discord.gg/Uzzf6a7zKr) developer Discord servers. Please, include the following information:

- A detailed description or context of the issue or what you are trying to achieve.
- A code example that we can use to test and debug (if possible). Use [CodeSandbox](https://codesandbox.io/p/sandbox/vanilla-ts) or any other live environment provider.
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.14.4",
"version": "0.15.1",
"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
Expand Up @@ -130,8 +130,14 @@ export interface GetCompressedTokenAccountsByOwnerOrDelegateOptions {
cursor?: string;
limit?: BN;
}
export type TokenBalance = { balance: BN; mint: PublicKey };

export interface GetCompressedMintTokenHoldersOptions {
/**
* **Cursor** is a unique identifier for a page of results by which the next page can be fetched.
*
* **Limit** is the maximum number of results to return per page.
*/
export interface PaginatedOptions {
cursor?: string;
limit?: BN;
}
Expand Down Expand Up @@ -441,6 +447,11 @@ export const TokenBalanceListResult = pick({
cursor: nullable(string()),
});

export const TokenBalanceListResultV2 = pick({
items: array(TokenBalanceResult),
cursor: nullable(string()),
});

export const CompressedMintTokenHoldersResult = pick({
cursor: nullable(string()),
items: array(
Expand Down Expand Up @@ -546,7 +557,7 @@ export interface CompressionApiInterface {

getCompressedMintTokenHolders(
mint: PublicKey,
options?: GetCompressedMintTokenHoldersOptions,
options?: PaginatedOptions,
): Promise<WithContext<WithCursor<CompressedMintTokenHolders[]>>>;

getCompressedTokenAccountsByOwner(
Expand All @@ -564,7 +575,12 @@ export interface CompressionApiInterface {
getCompressedTokenBalancesByOwner(
publicKey: PublicKey,
options: GetCompressedTokenAccountsByOwnerOrDelegateOptions,
): Promise<WithCursor<{ balance: BN; mint: PublicKey }[]>>;
): Promise<WithCursor<TokenBalance[]>>;

getCompressedTokenBalancesByOwnerV2(
publicKey: PublicKey,
options: GetCompressedTokenAccountsByOwnerOrDelegateOptions,
): Promise<WithContext<WithCursor<TokenBalance[]>>>;

getTransactionWithCompressionInfo(
signature: string,
Expand All @@ -576,18 +592,22 @@ export interface CompressionApiInterface {

getCompressionSignaturesForAddress(
address: PublicKey,
options?: PaginatedOptions,
): Promise<WithCursor<SignatureWithMetadata[]>>;

getCompressionSignaturesForOwner(
owner: PublicKey,
options?: PaginatedOptions,
): Promise<WithCursor<SignatureWithMetadata[]>>;

getCompressionSignaturesForTokenOwner(
owner: PublicKey,
options?: PaginatedOptions,
): Promise<WithCursor<SignatureWithMetadata[]>>;

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

getLatestCompressionSignatures(
Expand Down
Loading

0 comments on commit 80fb05c

Please sign in to comment.