Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
896 changes: 425 additions & 471 deletions Cargo.lock

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,10 @@ anchor-spl = "=0.31.1"
# Anchor compatibility
borsh = "0.10.0"

# Serialization
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"

# Macro helpers
proc-macro2 = "1.0"
quote = "1.0"
Expand Down
3 changes: 0 additions & 3 deletions cli/src/commands/compress-spl/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,6 @@ class CompressSplCommand extends Command {
payer,
sourceAta,
toPublicKey,
undefined,
undefined,
undefined,
);

loader.stop(false);
Expand Down
2 changes: 1 addition & 1 deletion cli/src/commands/start-prover/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ class StartProver extends Command {

const proverPort = flags["prover-port"] || 3001;
const force = flags["force"] || false;
const redisUrl = flags["redisUrl"] || process.env.REDIS_URL;
const redisUrl = flags["redisUrl"] || process.env.REDIS_URL || undefined;
await startProver(
proverPort,
flags["run-mode"],
Expand Down
3 changes: 2 additions & 1 deletion js/compressed-token/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@
"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-validator-skip-prover": "./../../cli/test_bin/run test-validator --skip-prover",
"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 --bail=1",
"test:e2e:select-accounts": "vitest run tests/e2e/select-accounts.test.ts --reporter=verbose",
Expand All @@ -99,7 +100,7 @@
"test:e2e:rpc-token-interop": "pnpm test-validator && vitest run tests/e2e/rpc-token-interop.test.ts --reporter=verbose",
"test:e2e:rpc-multi-trees": "pnpm test-validator && vitest run tests/e2e/rpc-multi-trees.test.ts --reporter=verbose",
"test:e2e:multi-pool": "pnpm test-validator && vitest run tests/e2e/multi-pool.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/delegate.test.ts && vitest run tests/e2e/transfer-delegated.test.ts && vitest run tests/e2e/multi-pool.test.ts && vitest run tests/e2e/decompress-delegated.test.ts && pnpm test-validator &&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/rpc-multi-trees.test.ts && vitest run tests/e2e/layout.test.ts && vitest run tests/e2e/select-accounts.test.ts",
"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/delegate.test.ts && vitest run tests/e2e/transfer-delegated.test.ts && vitest run tests/e2e/multi-pool.test.ts && vitest run tests/e2e/decompress-delegated.test.ts && pnpm test-validator-skip-prover && 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/rpc-multi-trees.test.ts && vitest run tests/e2e/layout.test.ts && vitest run tests/e2e/select-accounts.test.ts",
"pull-idl": "../../scripts/push-compressed-token-idl.sh",
"build": "rimraf dist && pnpm build:bundle",
"build:bundle": "rollup -c",
Expand Down
4 changes: 2 additions & 2 deletions js/compressed-token/src/actions/approve-and-mint-to.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ import {
buildAndSignTx,
Rpc,
dedupeSigner,
StateTreeInfo,
selectStateTreeInfo,
toArray,
TreeInfo,
} from '@lightprotocol/stateless.js';
import { CompressedTokenProgram } from '../program';
import { getOrCreateAssociatedTokenAccount } from '@solana/spl-token';
Expand Down Expand Up @@ -48,7 +48,7 @@ export async function approveAndMintTo(
toPubkey: PublicKey,
authority: Signer,
amount: number | BN,
outputStateTreeInfo?: StateTreeInfo,
outputStateTreeInfo?: TreeInfo,
tokenPoolInfo?: TokenPoolInfo,
confirmOptions?: ConfirmOptions,
): Promise<TransactionSignature> {
Expand Down
6 changes: 2 additions & 4 deletions js/compressed-token/src/actions/compress-spl-token-account.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,10 @@ import {
buildAndSignTx,
Rpc,
dedupeSigner,
StateTreeInfo,
selectStateTreeInfo,
TreeInfo,
} from '@lightprotocol/stateless.js';

import BN from 'bn.js';

import {
getTokenPoolInfos,
selectTokenPoolInfo,
Expand Down Expand Up @@ -48,7 +46,7 @@ export async function compressSplTokenAccount(
owner: Signer,
tokenAccount: PublicKey,
remainingAmount?: BN,
outputStateTreeInfo?: StateTreeInfo,
outputStateTreeInfo?: TreeInfo,
tokenPoolInfo?: TokenPoolInfo,
confirmOptions?: ConfirmOptions,
): Promise<TransactionSignature> {
Expand Down
6 changes: 2 additions & 4 deletions js/compressed-token/src/actions/compress.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,11 @@ import {
buildAndSignTx,
Rpc,
dedupeSigner,
StateTreeInfo,
selectStateTreeInfo,
toArray,
TreeInfo,
} from '@lightprotocol/stateless.js';

import BN from 'bn.js';

import { CompressedTokenProgram } from '../program';
import {
getTokenPoolInfos,
Expand Down Expand Up @@ -50,7 +48,7 @@ export async function compress(
owner: Signer,
sourceTokenAccount: PublicKey,
toAddress: PublicKey | Array<PublicKey>,
outputStateTreeInfo?: StateTreeInfo,
outputStateTreeInfo?: TreeInfo,
tokenPoolInfo?: TokenPoolInfo,
confirmOptions?: ConfirmOptions,
): Promise<TransactionSignature> {
Expand Down
2 changes: 0 additions & 2 deletions js/compressed-token/src/actions/decompress-delegated.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@ import {
buildAndSignTx,
Rpc,
dedupeSigner,
selectStateTreeInfo,
StateTreeInfo,
} from '@lightprotocol/stateless.js';

import BN from 'bn.js';
Expand Down
4 changes: 2 additions & 2 deletions js/compressed-token/src/actions/mint-to.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ import {
buildAndSignTx,
Rpc,
dedupeSigner,
StateTreeInfo,
selectStateTreeInfo,
TreeInfo,
} from '@lightprotocol/stateless.js';
import { CompressedTokenProgram } from '../program';
import {
Expand Down Expand Up @@ -48,7 +48,7 @@ export async function mintTo(
toPubkey: PublicKey | PublicKey[],
authority: Signer,
amount: number | BN | number[] | BN[],
outputStateTreeInfo?: StateTreeInfo,
outputStateTreeInfo?: TreeInfo,
tokenPoolInfo?: TokenPoolInfo,
confirmOptions?: ConfirmOptions,
): Promise<TransactionSignature> {
Expand Down
2 changes: 0 additions & 2 deletions js/compressed-token/src/actions/transfer-delegated.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@ import {
buildAndSignTx,
Rpc,
dedupeSigner,
StateTreeInfo,
selectStateTreeInfo,
} from '@lightprotocol/stateless.js';
import BN from 'bn.js';
import { CompressedTokenProgram } from '../program';
Expand Down
2 changes: 0 additions & 2 deletions js/compressed-token/src/layout.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,6 @@ const PackedTokenTransferOutputDataLayout = struct([
option(vecU8(), 'tlv'),
]);

// const QueueIndexLayout = struct([u8('queueId'), u16('index')]);

const InputTokenDataWithContextLayout = struct([
u64('amount'),
option(u8(), 'delegateIndex'),
Expand Down
28 changes: 12 additions & 16 deletions js/compressed-token/src/program.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import {
validateSameOwner,
validateSufficientBalance,
defaultTestStateTreeAccounts,
StateTreeInfo,
TreeInfo,
CompressedProof,
featureFlags,
} from '@lightprotocol/stateless.js';
Expand Down Expand Up @@ -93,7 +93,7 @@ export type CompressParams = {
/**
* State tree to write to
*/
outputStateTreeInfo: StateTreeInfo;
outputStateTreeInfo: TreeInfo;
/**
* Token pool
*/
Expand Down Expand Up @@ -124,7 +124,7 @@ export type CompressSplTokenAccountParams = {
/**
* State tree to write to
*/
outputStateTreeInfo: StateTreeInfo;
outputStateTreeInfo: TreeInfo;
/**
* Token pool
*/
Expand Down Expand Up @@ -330,7 +330,7 @@ export type MintToParams = {
/**
* State tree for minted tokens
*/
outputStateTreeInfo: StateTreeInfo;
outputStateTreeInfo: TreeInfo;
/**
* Token pool
*/
Expand Down Expand Up @@ -406,7 +406,7 @@ export type ApproveAndMintToParams = {
/**
* State tree to write to
*/
outputStateTreeInfo: StateTreeInfo;
outputStateTreeInfo: TreeInfo;
/**
* Token pool
*/
Expand Down Expand Up @@ -1171,12 +1171,16 @@ export class CompressedTokenProgram {

checkTokenPoolInfo(tokenPoolInfo, mint);

if (amountArray.length !== toAddressArray.length) {
throw new Error(
'Amount and toAddress arrays must have the same length',
);
}
if (featureFlags.isV2()) {
const [index, bump] = this.findTokenPoolIndexAndBump(
tokenPoolInfo.tokenPoolPda,
mint,
);

const rawData: BatchCompressInstructionData = {
pubkeys: toAddressArray,
amounts:
Expand All @@ -1185,11 +1189,10 @@ export class CompressedTokenProgram {
: null,
lamports: null,
amount: amountArray.length === 1 ? bn(amountArray[0]) : null,
index: index,
bump: bump,
index,
bump,
};

console.log('rawData', rawData);
const data = encodeBatchCompressInstructionData(rawData);
const keys = mintToAccountsLayout({
mint,
Expand All @@ -1211,19 +1214,12 @@ export class CompressedTokenProgram {
isSigner: false,
});

console.log('keys', keys.length);

return new TransactionInstruction({
programId: this.programId,
keys,
data,
});
} else {
if (amountArray.length !== toAddressArray.length) {
throw new Error(
'Amount and toAddress arrays must have the same length',
);
}
tokenTransferOutputs = amountArray.map((amt, index) => {
const amountBN = bn(amt);
return {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ import {
getIndexOrAdd,
bn,
padOutputStateMerkleTrees,
StateTreeInfo,
TreeType,
featureFlags,
TreeInfo,
} from '@lightprotocol/stateless.js';
import { PublicKey, AccountMeta } from '@solana/web3.js';
import {
Expand All @@ -22,7 +22,7 @@ export type PackCompressedTokenAccountsParams = {
* state tree of the input state. Gets padded to the length of
* outputCompressedAccounts.
*/
outputStateTreeInfo?: StateTreeInfo;
outputStateTreeInfo?: TreeInfo;
/** Optional remaining accounts to append to */
remainingAccounts?: PublicKey[];
/**
Expand Down Expand Up @@ -102,7 +102,7 @@ export function packCompressedTokenAccounts(
);
}

let treeInfo: StateTreeInfo;
let treeInfo: TreeInfo;
if (inputCompressedTokenAccounts.length > 0) {
treeInfo = inputCompressedTokenAccounts[0].compressedAccount.treeInfo;
} else if (outputStateTreeInfo) {
Expand Down
4 changes: 2 additions & 2 deletions js/compressed-token/tests/e2e/approve-and-mint-to.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import {
sendAndConfirmTx,
getTestRpc,
defaultTestStateTreeAccounts,
StateTreeInfo,
TreeInfo,
selectStateTreeInfo,
} from '@lightprotocol/stateless.js';
import { WasmFactory } from '@lightprotocol/hasher.rs';
Expand Down Expand Up @@ -72,7 +72,7 @@ describe('approveAndMintTo', () => {
let mint: PublicKey;
let mintAuthority: Keypair;
let tokenPoolInfo: TokenPoolInfo;
let stateTreeInfo: StateTreeInfo;
let stateTreeInfo: TreeInfo;

beforeAll(async () => {
const lightWasm = await WasmFactory.getInstance();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
defaultTestStateTreeAccounts,
newAccountWithLamports,
getTestRpc,
StateTreeInfo,
TreeInfo,
selectStateTreeInfo,
} from '@lightprotocol/stateless.js';
import {
Expand Down Expand Up @@ -36,7 +36,7 @@ describe('compressSplTokenAccount', () => {
let aliceAta: PublicKey;
let mint: PublicKey;
let mintAuthority: Keypair;
let stateTreeInfo: StateTreeInfo;
let stateTreeInfo: TreeInfo;
let tokenPoolInfo: TokenPoolInfo;

beforeAll(async () => {
Expand Down
8 changes: 4 additions & 4 deletions js/compressed-token/tests/e2e/compress.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import {
buildAndSignTx,
sendAndConfirmTx,
getTestRpc,
StateTreeInfo,
TreeInfo,
selectStateTreeInfo,
} from '@lightprotocol/stateless.js';
import {
Expand Down Expand Up @@ -98,10 +98,10 @@ describe('compress', () => {
let mint: PublicKey;
let mintAuthority: Keypair;
let lut: PublicKey;
let stateTreeInfo: StateTreeInfo;
let stateTreeInfo: TreeInfo;
let tokenPoolInfo: TokenPoolInfo;

const maxBatchSize = 26;
const maxBatchSize = 15;
const recipients = Array.from(
{ length: maxBatchSize },
() => Keypair.generate().publicKey,
Expand Down Expand Up @@ -289,7 +289,7 @@ describe('compress', () => {
owner: bob.publicKey,
source: bobAta,
toAddress: recipients,
amount: bn(2),
amount: recipients.map(() => bn(2)),
mint,
outputStateTreeInfo: stateTreeInfo,
tokenPoolInfo,
Expand Down
4 changes: 2 additions & 2 deletions js/compressed-token/tests/e2e/decompress-delegated.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
bn,
newAccountWithLamports,
getTestRpc,
StateTreeInfo,
TreeInfo,
selectStateTreeInfo,
ParsedTokenAccount,
} from '@lightprotocol/stateless.js';
Expand Down Expand Up @@ -103,7 +103,7 @@ describe('decompressDelegated', () => {
let charlieAta: PublicKey;
let mint: PublicKey;
let mintAuthority: Keypair;
let stateTreeInfo: StateTreeInfo;
let stateTreeInfo: TreeInfo;
let tokenPoolInfos: TokenPoolInfo[];

beforeAll(async () => {
Expand Down
4 changes: 2 additions & 2 deletions js/compressed-token/tests/e2e/decompress.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
newAccountWithLamports,
getTestRpc,
selectStateTreeInfo,
StateTreeInfo,
TreeInfo,
} from '@lightprotocol/stateless.js';
import { WasmFactory } from '@lightprotocol/hasher.rs';
import { createMint, mintTo, decompress } from '../../src/actions';
Expand Down Expand Up @@ -73,7 +73,7 @@ describe('decompress', () => {
let charlieAta: PublicKey;
let mint: PublicKey;
let mintAuthority: Keypair;
let stateTreeInfo: StateTreeInfo;
let stateTreeInfo: TreeInfo;
let tokenPoolInfos: TokenPoolInfo[];

beforeAll(async () => {
Expand Down
Loading
Loading