Skip to content

Commit

Permalink
chore: remove anchor dependency in js (#1415)
Browse files Browse the repository at this point in the history
* pin js sdks to use [email protected]

wip

remove anchor from stateless.js

add buffer-layout.dt.ts

add note

wip

wip

remove anchor dep in ctoken

use bs58

fmt

wip

remove custom program id test

fix dl keyss

statelessjs bundle optimization. remove idls

rm tweetnacl, minify compressed-token lib

wip. less externals

wip: try alpha

npm release script with alpha option

wip

wip

stateless.js works with web3js 1.73.5 - alpha

wip

* wip

* clean

* clean

* clean layout, add unit tests

* add unit tests for codec/layout.ts files

* add todo

* clean

* rm es bundles

* bump

* wip - debug ct

* wip

* wiop

* rm logs

* bump js releases to 0.18.0

* rm only

* add layout.test.ts to pnpm test

* layout test with real keys

* real keys for layout.test.ts in stateless.js

---------

Co-authored-by: Swenschaeferjohann <[email protected]>
  • Loading branch information
SwenSchaeferjohann and Swenschaeferjohann authored Jan 9, 2025
1 parent 9fc0542 commit 68cd27a
Show file tree
Hide file tree
Showing 71 changed files with 2,720 additions and 10,627 deletions.
2 changes: 1 addition & 1 deletion cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
"@oclif/plugin-not-found": "^3.1.2",
"@oclif/plugin-plugins": "^5.0.7",
"@solana-developers/helpers": "^1.5.1",
"@solana/web3.js": "1.95.3",
"@solana/web3.js": "1.98.0",
"axios": "^1.6.8",
"case-anything": "^2.1.13",
"cli-progress": "^3.12.0",
Expand Down
2 changes: 1 addition & 1 deletion examples/browser/nextjs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
"@solana/wallet-adapter-react": "^0.15.35",
"@solana/wallet-adapter-react-ui": "^0.9.35",
"@solana/wallet-adapter-unsafe-burner": "^0.1.7",
"@solana/web3.js": "^1.95.3",
"@solana/web3.js": "1.98.0",
"next": "15.0.4",
"react": "^19",
"react-dom": "^19"
Expand Down
2 changes: 1 addition & 1 deletion examples/node/esm/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
},
"dependencies": {
"@coral-xyz/anchor": "^0.30.0",
"@solana/web3.js": "^1.95.3",
"@solana/web3.js": "1.98.0",
"@lightprotocol/stateless.js": "workspace:*"
}
}
80 changes: 42 additions & 38 deletions 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.17.1",
"version": "0.18.0",
"description": "JS client to interact with the compressed-token program",
"sideEffects": false,
"main": "dist/cjs/node/index.cjs",
Expand All @@ -21,37 +21,6 @@
"files": [
"dist"
],
"scripts": {
"test": "pnpm test:e2e:all",
"test-all": "vitest run",
"test:unit:all": "EXCLUDE_E2E=true vitest run",
"test-all:verbose": "vitest run --reporter=verbose",
"test-validator": "./../../cli/test_bin/run test-validator --prover-run-mode rpc",
"test:e2e:create-mint": "pnpm test-validator && vitest run tests/e2e/create-mint.test.ts",
"test:e2e:create-token-pool": "pnpm test-validator && vitest run tests/e2e/create-token-pool.test.ts",
"test:e2e:mint-to": "pnpm test-validator && vitest run tests/e2e/mint-to.test.ts --reporter=verbose",
"test:e2e:approve-and-mint-to": "pnpm test-validator && vitest run tests/e2e/approve-and-mint-to.test.ts --reporter=verbose",
"test:e2e:merge-token-accounts": "pnpm test-validator && vitest run tests/e2e/merge-token-accounts.test.ts --reporter=verbose",
"test:e2e:transfer": "pnpm test-validator && vitest run tests/e2e/transfer.test.ts --reporter=verbose",
"test:e2e:compress": "pnpm test-validator && vitest run tests/e2e/compress.test.ts --reporter=verbose",
"test:e2e:compress-spl-token-account": "pnpm test-validator && vitest run tests/e2e/compress-spl-token-account.test.ts --reporter=verbose",
"test:e2e:decompress": "pnpm test-validator && vitest run tests/e2e/decompress.test.ts --reporter=verbose",
"test:e2e:rpc-token-interop": "pnpm test-validator && vitest run tests/e2e/rpc-token-interop.test.ts --reporter=verbose",
"test:e2e:custom-program-id": "vitest run tests/e2e/custom-program-id.test.ts --reporter=verbose",
"test:e2e:all": "pnpm test-validator && vitest run tests/e2e/create-mint.test.ts && vitest run tests/e2e/mint-to.test.ts && vitest run tests/e2e/transfer.test.ts && vitest run tests/e2e/compress.test.ts && vitest run tests/e2e/compress-spl-token-account.test.ts && vitest run tests/e2e/decompress.test.ts && vitest run tests/e2e/create-token-pool.test.ts && vitest run tests/e2e/approve-and-mint-to.test.ts && vitest run tests/e2e/rpc-token-interop.test.ts && vitest run tests/e2e/custom-program-id.test.ts",
"pull-idl": "../../scripts/push-compressed-token-idl.sh",
"build": "rimraf dist && pnpm pull-idl && pnpm build:bundle",
"build:bundle": "rollup -c",
"format": "prettier --write .",
"lint": "eslint ."
},
"keywords": [
"zk",
"compression",
"light",
"stateless",
"solana"
],
"maintainers": [
{
"name": "Light Protocol Maintainers",
Expand All @@ -60,16 +29,17 @@
],
"license": "Apache-2.0",
"peerDependencies": {
"@lightprotocol/stateless.js": "workspace:*"
"@lightprotocol/stateless.js": "workspace:*",
"@solana/spl-token": ">=0.3.9",
"@solana/web3.js": ">=1.73.5"
},
"dependencies": {
"@coral-xyz/anchor": "0.29.0",
"@solana/web3.js": "1.95.3",
"@solana/spl-token": "0.4.8",
"buffer": "6.0.3",
"tweetnacl": "1.0.3"
"@coral-xyz/borsh": "^0.29.0",
"bn.js": "^5.2.1",
"buffer": "6.0.3"
},
"devDependencies": {
"@coral-xyz/anchor": "^0.29.0",
"@esbuild-plugins/node-globals-polyfill": "^0.2.3",
"@lightprotocol/hasher.rs": "0.2.1",
"@lightprotocol/programs": "workspace:*",
Expand All @@ -81,6 +51,9 @@
"@rollup/plugin-replace": "^5.0.7",
"@rollup/plugin-terser": "^0.4.4",
"@rollup/plugin-typescript": "^11.1.6",
"@solana/spl-token": "0.4.8",
"@solana/web3.js": "1.98.0",
"@types/bn.js": "^5.1.5",
"@types/node": "^22.5.5",
"@typescript-eslint/eslint-plugin": "^7.13.1",
"@typescript-eslint/parser": "^7.13.1",
Expand All @@ -103,6 +76,37 @@
"typescript": "^5.6.2",
"vitest": "^2.1.1"
},
"scripts": {
"test": "pnpm test:e2e:all",
"test-all": "vitest run",
"test:unit:all": "EXCLUDE_E2E=true vitest run",
"test-all:verbose": "vitest run --reporter=verbose",
"test-validator": "./../../cli/test_bin/run test-validator --prover-run-mode rpc",
"test:e2e:create-mint": "pnpm test-validator && NODE_OPTIONS='--trace-deprecation' vitest run tests/e2e/create-mint.test.ts --reporter=verbose",
"test:e2e:layout": "vitest run tests/e2e/layout.test.ts --reporter=verbose",
"test:e2e:create-token-pool": "pnpm test-validator && vitest run tests/e2e/create-token-pool.test.ts",
"test:e2e:mint-to": "pnpm test-validator && vitest run tests/e2e/mint-to.test.ts --reporter=verbose",
"test:e2e:approve-and-mint-to": "pnpm test-validator && vitest run tests/e2e/approve-and-mint-to.test.ts --reporter=verbose",
"test:e2e:merge-token-accounts": "pnpm test-validator && vitest run tests/e2e/merge-token-accounts.test.ts --reporter=verbose",
"test:e2e:transfer": "pnpm test-validator && vitest run tests/e2e/transfer.test.ts --reporter=verbose",
"test:e2e:compress": "pnpm test-validator && vitest run tests/e2e/compress.test.ts --reporter=verbose",
"test:e2e:compress-spl-token-account": "pnpm test-validator && vitest run tests/e2e/compress-spl-token-account.test.ts --reporter=verbose",
"test:e2e:decompress": "pnpm test-validator && vitest run tests/e2e/decompress.test.ts --reporter=verbose",
"test:e2e:rpc-token-interop": "pnpm test-validator && vitest run tests/e2e/rpc-token-interop.test.ts --reporter=verbose",
"test:e2e:all": "pnpm test-validator && vitest run tests/e2e/create-mint.test.ts && vitest run tests/e2e/mint-to.test.ts && vitest run tests/e2e/transfer.test.ts && vitest run tests/e2e/compress.test.ts && vitest run tests/e2e/compress-spl-token-account.test.ts && vitest run tests/e2e/decompress.test.ts && vitest run tests/e2e/create-token-pool.test.ts && vitest run tests/e2e/approve-and-mint-to.test.ts && vitest run tests/e2e/rpc-token-interop.test.ts && vitest run tests/e2e/layout.test.ts",
"pull-idl": "../../scripts/push-compressed-token-idl.sh",
"build": "rimraf dist && pnpm build:bundle",
"build:bundle": "rollup -c",
"format": "prettier --write .",
"lint": "eslint ."
},
"keywords": [
"zk",
"compression",
"light",
"stateless",
"solana"
],
"nx": {
"targets": {
"build": {
Expand Down
25 changes: 22 additions & 3 deletions js/compressed-token/rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import resolve from '@rollup/plugin-node-resolve';
import commonjs from '@rollup/plugin-commonjs';
import alias from '@rollup/plugin-alias';
import json from '@rollup/plugin-json';
import terser from '@rollup/plugin-terser';

const rolls = (fmt, env) => ({
input: 'src/index.ts',
Expand All @@ -16,10 +17,9 @@ const rolls = (fmt, env) => ({
},
external: [
'@solana/web3.js',
'@coral-xyz/anchor',
'@solana/spl-token',
'@coral-xyz/borsh',
'@lightprotocol/stateless.js',
'tweetnacl',
],
plugins: [
json(),
Expand All @@ -45,6 +45,26 @@ const rolls = (fmt, env) => ({
],
}),
env === 'browser' ? nodePolyfills() : undefined,
terser({
compress: {
drop_console: true,
drop_debugger: true,
passes: 3,
pure_funcs: ['console.log', 'console.error', 'console.warn'],
booleans_as_integers: true,
keep_fargs: false,
keep_fnames: false,
keep_infinity: true,
reduce_funcs: true,
reduce_vars: true,
},
mangle: {
toplevel: true,
},
output: {
comments: false,
},
}),
].filter(Boolean),
onwarn(warning, warn) {
if (warning.code !== 'CIRCULAR_DEPENDENCY') {
Expand All @@ -61,7 +81,6 @@ const typesConfig = {

export default [
rolls('cjs', 'browser'),
rolls('es', 'browser'),
rolls('cjs', 'node'),
typesConfig,
];
2 changes: 1 addition & 1 deletion js/compressed-token/src/actions/approve-and-mint-to.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {
Signer,
TransactionSignature,
} from '@solana/web3.js';
import { BN } from '@coral-xyz/anchor';
import BN from 'bn.js';
import {
sendAndConfirmTx,
buildAndSignTx,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {
dedupeSigner,
} from '@lightprotocol/stateless.js';

import { BN } from '@coral-xyz/anchor';
import BN from 'bn.js';

import { CompressedTokenProgram } from '../program';

Expand Down
2 changes: 1 addition & 1 deletion js/compressed-token/src/actions/compress.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {
dedupeSigner,
} from '@lightprotocol/stateless.js';

import { BN } from '@coral-xyz/anchor';
import BN from 'bn.js';

import { CompressedTokenProgram } from '../program';

Expand Down
2 changes: 1 addition & 1 deletion js/compressed-token/src/actions/decompress.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import {
dedupeSigner,
} from '@lightprotocol/stateless.js';

import { BN } from '@coral-xyz/anchor';
import BN from 'bn.js';

import { CompressedTokenProgram } from '../program';
import { selectMinCompressedTokenAccountsForTransfer } from './transfer';
Expand Down
2 changes: 1 addition & 1 deletion js/compressed-token/src/actions/mint-to.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {
Signer,
TransactionSignature,
} from '@solana/web3.js';
import { BN } from '@coral-xyz/anchor';
import BN from 'bn.js';
import {
sendAndConfirmTx,
buildAndSignTx,
Expand Down
2 changes: 1 addition & 1 deletion js/compressed-token/src/actions/transfer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import {
dedupeSigner,
} from '@lightprotocol/stateless.js';

import { BN } from '@coral-xyz/anchor';
import BN from 'bn.js';

import { CompressedTokenProgram } from '../program';

Expand Down
13 changes: 13 additions & 0 deletions js/compressed-token/src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,16 @@ export const POOL_SEED = Buffer.from('pool');
export const CPI_AUTHORITY_SEED = Buffer.from('cpi_authority');

export const SPL_TOKEN_MINT_RENT_EXEMPT_BALANCE = 1461600;

export const CREATE_TOKEN_POOL_DISCRIMINATOR = Buffer.from([
23, 169, 27, 122, 147, 169, 209, 152,
]);
export const MINT_TO_DISCRIMINATOR = Buffer.from([
241, 34, 48, 186, 37, 179, 123, 192,
]);
export const TRANSFER_DISCRIMINATOR = Buffer.from([
163, 52, 200, 231, 140, 3, 69, 186,
]);
export const COMPRESS_SPL_TOKEN_ACCOUNT_DISCRIMINATOR = Buffer.from([
112, 230, 105, 101, 145, 202, 157, 97,
]);
File renamed without changes.
1 change: 0 additions & 1 deletion js/compressed-token/src/idl/index.ts

This file was deleted.

3 changes: 2 additions & 1 deletion js/compressed-token/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
export * from './idl';
export * from './instructions';
export * from './constants';
export * from './program';
export * from './types';
export * from './actions';
export * from './layout';
export * from './idl';
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@ import {
getIndexOrAdd,
bn,
padOutputStateMerkleTrees,
TokenTransferOutputData,
} from '@lightprotocol/stateless.js';
import { PublicKey, AccountMeta } from '@solana/web3.js';
import { PackedTokenTransferOutputData } from '../types';
import {
PackedTokenTransferOutputData,
TokenTransferOutputData,
} from '../types';

export type PackCompressedTokenAccountsParams = {
/** Input state to be consumed */
Expand Down
Loading

0 comments on commit 68cd27a

Please sign in to comment.