Skip to content
Open
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
6 changes: 3 additions & 3 deletions .github/workflows/js-v2.yml
Original file line number Diff line number Diff line change
Expand Up @@ -97,13 +97,13 @@ jobs:
done
echo "Tests passed on attempt $attempt"

- name: Run compressed-token ctoken tests with V2
- name: Run compressed-token lighttoken tests with V2
run: |
echo "Running compressed-token ctoken tests with retry logic (max 2 attempts)..."
echo "Running compressed-token lighttoken tests with retry logic (max 2 attempts)..."
attempt=1
max_attempts=2
cd js/compressed-token
until LIGHT_PROTOCOL_VERSION=V2 pnpm test:e2e:ctoken:all; do
until LIGHT_PROTOCOL_VERSION=V2 pnpm test:e2e:lighttoken:all; do
attempt=$((attempt + 1))
if [ $attempt -gt $max_attempts ]; then
echo "Tests failed after $max_attempts attempts"
Expand Down
8 changes: 8 additions & 0 deletions js/compressed-token/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
## [0.23.0-beta.10]

### Breaking Changes

- **`decompressInterface` removed.** Use `loadAta` (action) or `createLoadAtaInstructions` (instruction builder) instead. `decompressInterface` did not support >8 compressed inputs and has been fully removed.
- **Action (send transaction):** Replace `decompressInterface(rpc, payer, owner, mint, amount?, destinationAta?, destinationOwner?, splInterfaceInfo?, confirmOptions?)` with `loadAta(rpc, ata, owner, mint, payer?, confirmOptions?, interfaceOptions?, wrap?)`. Derive the target ATA with `getAssociatedTokenAddressInterface(mint, owner)` for c-token, or pass the SPL/T22 ATA to decompress to that program. `loadAta` loads all cold balance into the given ATA (no partial amount); it supports >8 inputs via batched transactions and creates the ATA if needed.
- **Instruction-level:** Use `createLoadAtaInstructions(rpc, ata, owner, mint, payer?, interfaceOptions?, wrap?)` to get `TransactionInstruction[][]` and send batches yourself. The single-instruction primitive is no longer exported; use the batched API only.

## [0.23.0-beta.9]

### Fixed
Expand Down
17 changes: 10 additions & 7 deletions js/compressed-token/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -89,22 +89,23 @@
"vitest": "^2.1.1"
},
"scripts": {
"test": "vitest run tests/unit && if [ \"$LIGHT_PROTOCOL_VERSION\" = \"V1\" ]; then pnpm test:e2e:legacy:all; else pnpm test:e2e:ctoken:all; fi",
"test": "vitest run tests/unit && if [ \"$LIGHT_PROTOCOL_VERSION\" = \"V1\" ]; then pnpm test:e2e:legacy:all; else pnpm test:e2e:lighttoken:all; fi",
"test-ci": "pnpm test:v1 && pnpm test:v2",
"test:v1": "pnpm build:v1 && LIGHT_PROTOCOL_VERSION=V1 vitest run tests/unit && LIGHT_PROTOCOL_VERSION=V1 pnpm test:e2e:legacy:all",
"test:v2": "pnpm build:v2 && LIGHT_PROTOCOL_VERSION=V2 vitest run tests/unit && LIGHT_PROTOCOL_VERSION=V2 LIGHT_PROTOCOL_BETA=true pnpm test:e2e:ctoken:all",
"test:v2:ctoken": "pnpm build:v2 && LIGHT_PROTOCOL_VERSION=V2 LIGHT_PROTOCOL_BETA=true pnpm test:e2e:ctoken:all",
"test:v2": "pnpm build:v2 && LIGHT_PROTOCOL_VERSION=V2 vitest run tests/unit && LIGHT_PROTOCOL_VERSION=V2 LIGHT_PROTOCOL_BETA=true pnpm test:e2e:lighttoken:all",
"test:v2:lighttoken": "pnpm build:v2 && LIGHT_PROTOCOL_VERSION=V2 LIGHT_PROTOCOL_BETA=true pnpm test:e2e:lighttoken:all",
"test-all": "vitest run",
"test:unit:all": "EXCLUDE_E2E=true vitest run",
"test:unit:all:v1": "LIGHT_PROTOCOL_VERSION=V1 vitest run tests/unit --reporter=verbose",
"test:unit:all:v2": "LIGHT_PROTOCOL_VERSION=V2 vitest run tests/unit --reporter=verbose",
"test:unit:delegate-merge-semantics": "vitest run tests/unit/delegate-merge-semantics.test.ts --reporter=verbose",
"test-all:verbose": "vitest run --reporter=verbose",
"test-validator": "./../../cli/test_bin/run test-validator",
"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:create-compressed-mint": "pnpm test-validator && vitest run tests/e2e/create-compressed-mint.test.ts --reporter=verbose --bail=1",
"test:e2e:create-associated-ctoken": "pnpm test-validator && vitest run tests/e2e/create-associated-ctoken.test.ts --reporter=verbose",
"test:e2e:mint-to-ctoken": "pnpm test-validator && vitest run tests/e2e/mint-to-ctoken.test.ts --reporter=verbose",
"test:e2e:create-associated-light-token": "pnpm test-validator && vitest run tests/e2e/create-associated-light-token.test.ts --reporter=verbose",
"test:e2e:mint-to-light-token": "pnpm test-validator && vitest run tests/e2e/mint-to-light-token.test.ts --reporter=verbose",
"test:e2e:mint-to-compressed": "pnpm test-validator && vitest run tests/e2e/mint-to-compressed.test.ts --reporter=verbose",
"test:e2e:mint-to-interface": "pnpm test-validator && LIGHT_PROTOCOL_BETA=true vitest run tests/e2e/mint-to-interface.test.ts --reporter=verbose",
"test:e2e:mint-workflow": "pnpm test-validator && vitest run tests/e2e/mint-workflow.test.ts --reporter=verbose",
Expand Down Expand Up @@ -138,9 +139,11 @@
"test:e2e:load-ata-unified": "pnpm test-validator && LIGHT_PROTOCOL_BETA=true vitest run tests/e2e/load-ata-unified.test.ts --reporter=verbose",
"test:e2e:load-ata-combined": "pnpm test-validator && LIGHT_PROTOCOL_BETA=true vitest run tests/e2e/load-ata-combined.test.ts --reporter=verbose",
"test:e2e:load-ata-spl-t22": "pnpm test-validator && LIGHT_PROTOCOL_BETA=true vitest run tests/e2e/load-ata-spl-t22.test.ts --reporter=verbose",
"test:e2e:multi-cold-inputs-batching": "pnpm test-validator && LIGHT_PROTOCOL_VERSION=V2 LIGHT_PROTOCOL_BETA=true vitest run tests/e2e/multi-cold-inputs-batching.test.ts -t \"instruction-level|hash uniqueness|ensureRecipientAta\" --reporter=verbose && pnpm test-validator && LIGHT_PROTOCOL_VERSION=V2 LIGHT_PROTOCOL_BETA=true vitest run tests/e2e/multi-cold-inputs-batching.test.ts -t \"parallel multi-tx\" --reporter=verbose",
"test:e2e:load-ata:all": "pnpm test-validator && LIGHT_PROTOCOL_BETA=true vitest run tests/e2e/load-ata-standard.test.ts --bail=1 && pnpm test-validator && LIGHT_PROTOCOL_BETA=true vitest run tests/e2e/load-ata-unified.test.ts --bail=1 && pnpm test-validator && LIGHT_PROTOCOL_BETA=true vitest run tests/e2e/load-ata-combined.test.ts --bail=1 && pnpm test-validator && LIGHT_PROTOCOL_BETA=true vitest run tests/e2e/load-ata-spl-t22.test.ts --bail=1",
"test:e2e:ctoken:all": "pnpm test-validator && LIGHT_PROTOCOL_BETA=true vitest run tests/e2e/create-compressed-mint.test.ts --bail=1 && LIGHT_PROTOCOL_BETA=true vitest run tests/e2e/create-associated-ctoken.test.ts --bail=1 && LIGHT_PROTOCOL_BETA=true vitest run tests/e2e/mint-to-ctoken.test.ts --bail=1 && pnpm test-validator && LIGHT_PROTOCOL_BETA=true vitest run tests/e2e/mint-to-compressed.test.ts --bail=1 && LIGHT_PROTOCOL_BETA=true vitest run tests/e2e/mint-to-interface.test.ts --bail=1 && LIGHT_PROTOCOL_BETA=true vitest run tests/e2e/mint-workflow.test.ts --bail=1 && pnpm test-validator && LIGHT_PROTOCOL_BETA=true vitest run tests/e2e/update-mint.test.ts --bail=1 && LIGHT_PROTOCOL_BETA=true vitest run tests/e2e/update-metadata.test.ts --bail=1 && LIGHT_PROTOCOL_BETA=true vitest run tests/e2e/compressible-load.test.ts --bail=1 && pnpm test-validator && LIGHT_PROTOCOL_BETA=true vitest run tests/e2e/wrap.test.ts --bail=1 && LIGHT_PROTOCOL_BETA=true vitest run tests/e2e/get-mint-interface.test.ts --bail=1 && LIGHT_PROTOCOL_BETA=true vitest run tests/e2e/get-account-interface.test.ts --bail=1 && pnpm test-validator && LIGHT_PROTOCOL_BETA=true vitest run tests/e2e/create-mint-interface.test.ts --bail=1 && LIGHT_PROTOCOL_BETA=true vitest run tests/e2e/create-ata-interface.test.ts --bail=1 && pnpm test-validator && LIGHT_PROTOCOL_BETA=true vitest run tests/e2e/get-or-create-ata-interface.test.ts --bail=1 && LIGHT_PROTOCOL_BETA=true vitest run tests/e2e/transfer-interface.test.ts --bail=1 && pnpm test-validator && LIGHT_PROTOCOL_BETA=true vitest run tests/e2e/unwrap.test.ts --bail=1 && LIGHT_PROTOCOL_BETA=true vitest run tests/e2e/decompress2.test.ts --bail=1 && LIGHT_PROTOCOL_BETA=true vitest run tests/e2e/payment-flows.test.ts --bail=1 && pnpm test-validator && vitest run tests/e2e/v1-v2-migration.test.ts --bail=1 && pnpm test-validator && LIGHT_PROTOCOL_BETA=true vitest run tests/e2e/load-ata-standard.test.ts --bail=1 && pnpm test-validator && LIGHT_PROTOCOL_BETA=true vitest run tests/e2e/load-ata-unified.test.ts --bail=1 && pnpm test-validator && LIGHT_PROTOCOL_BETA=true vitest run tests/e2e/load-ata-combined.test.ts --bail=1 && pnpm test-validator && LIGHT_PROTOCOL_BETA=true vitest run tests/e2e/load-ata-spl-t22.test.ts --bail=1",
"test:e2e:all": "pnpm test:e2e:legacy:all && pnpm test:e2e:ctoken:all",
"test:e2e:load-ata-freeze": "pnpm test-validator && LIGHT_PROTOCOL_BETA=true vitest run tests/e2e/load-ata-freeze.test.ts --reporter=verbose",
"test:e2e:lighttoken:all": "pnpm test-validator && LIGHT_PROTOCOL_BETA=true vitest run tests/e2e/create-compressed-mint.test.ts --bail=1 && LIGHT_PROTOCOL_BETA=true vitest run tests/e2e/create-associated-light-token.test.ts --bail=1 && LIGHT_PROTOCOL_BETA=true vitest run tests/e2e/mint-to-light-token.test.ts --bail=1 && pnpm test-validator && LIGHT_PROTOCOL_BETA=true vitest run tests/e2e/mint-to-compressed.test.ts --bail=1 && LIGHT_PROTOCOL_BETA=true vitest run tests/e2e/mint-to-interface.test.ts --bail=1 && LIGHT_PROTOCOL_BETA=true vitest run tests/e2e/mint-workflow.test.ts --bail=1 && pnpm test-validator && LIGHT_PROTOCOL_BETA=true vitest run tests/e2e/update-mint.test.ts --bail=1 && LIGHT_PROTOCOL_BETA=true vitest run tests/e2e/update-metadata.test.ts --bail=1 && LIGHT_PROTOCOL_BETA=true vitest run tests/e2e/compressible-load.test.ts --bail=1 && pnpm test-validator && LIGHT_PROTOCOL_BETA=true vitest run tests/e2e/wrap.test.ts --bail=1 && LIGHT_PROTOCOL_BETA=true vitest run tests/e2e/get-mint-interface.test.ts --bail=1 && LIGHT_PROTOCOL_BETA=true vitest run tests/e2e/get-account-interface.test.ts --bail=1 && pnpm test-validator && LIGHT_PROTOCOL_BETA=true vitest run tests/e2e/create-mint-interface.test.ts --bail=1 && LIGHT_PROTOCOL_BETA=true vitest run tests/e2e/create-ata-interface.test.ts --bail=1 && pnpm test-validator && LIGHT_PROTOCOL_BETA=true vitest run tests/e2e/get-or-create-ata-interface.test.ts --bail=1 && LIGHT_PROTOCOL_BETA=true vitest run tests/e2e/transfer-interface.test.ts --bail=1 && pnpm test-validator && LIGHT_PROTOCOL_BETA=true vitest run tests/e2e/unwrap.test.ts --bail=1 && LIGHT_PROTOCOL_BETA=true vitest run tests/e2e/decompress2.test.ts --bail=1 && LIGHT_PROTOCOL_BETA=true vitest run tests/e2e/payment-flows.test.ts --bail=1 && pnpm test-validator && vitest run tests/e2e/v1-v2-migration.test.ts --bail=1 && pnpm test-validator && LIGHT_PROTOCOL_BETA=true vitest run tests/e2e/load-ata-standard.test.ts --bail=1 && pnpm test-validator && LIGHT_PROTOCOL_BETA=true vitest run tests/e2e/load-ata-unified.test.ts --bail=1 && pnpm test-validator && LIGHT_PROTOCOL_BETA=true vitest run tests/e2e/load-ata-combined.test.ts --bail=1 && pnpm test-validator && LIGHT_PROTOCOL_BETA=true vitest run tests/e2e/load-ata-freeze.test.ts --bail=1 && pnpm test-validator && LIGHT_PROTOCOL_BETA=true vitest run tests/e2e/load-ata-spl-t22.test.ts --bail=1 && pnpm test-validator && LIGHT_PROTOCOL_VERSION=V2 LIGHT_PROTOCOL_BETA=true vitest run tests/e2e/multi-cold-inputs-batching.test.ts -t \"instruction-level|hash uniqueness|ensureRecipientAta\" --bail=1 && pnpm test-validator && LIGHT_PROTOCOL_VERSION=V2 LIGHT_PROTOCOL_BETA=true vitest run tests/e2e/multi-cold-inputs-batching.test.ts -t \"parallel multi-tx\" --bail=1",
"test:e2e:all": "pnpm test:e2e:legacy:all && pnpm test:e2e:lighttoken:all",
"pull-idl": "../../scripts/push-compressed-token-idl.sh",
"build": "if [ \"$LIGHT_PROTOCOL_VERSION\" = \"V2\" ]; then LIGHT_PROTOCOL_VERSION=V2 pnpm build:bundle; else LIGHT_PROTOCOL_VERSION=V1 pnpm build:bundle; fi",
"build:bundle": "rimraf dist && rollup -c",
Expand Down
16 changes: 7 additions & 9 deletions js/compressed-token/src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,6 @@ export const ADD_TOKEN_POOL_DISCRIMINATOR = Buffer.from([
114, 143, 210, 73, 96, 115, 1, 228,
]);

export const DECOMPRESS_ACCOUNTS_IDEMPOTENT_DISCRIMINATOR = Buffer.from([107]);

/**
* Maximum lamports for rent top-up in a single instruction.
* u16::MAX = no limit; 0 = no top-ups allowed.
Expand All @@ -66,7 +64,7 @@ export const DECOMPRESS_ACCOUNTS_IDEMPOTENT_DISCRIMINATOR = Buffer.from([107]);
export const MAX_TOP_UP = 65535;

/**
* Rent configuration constants for compressible ctoken accounts.
* Rent configuration constants for compressible light token accounts.
* These match the Rust SDK defaults in program-libs/compressible/src/rent/config.rs
*/

Expand All @@ -89,11 +87,11 @@ export const COMPRESSION_INCENTIVE = 1000;
export const TOTAL_COMPRESSION_COST = COMPRESSION_COST + COMPRESSION_INCENTIVE;

/**
* Compressible ctoken account size in bytes.
* Compressible light token account size in bytes.
* = 165 (base SPL token) + 1 (account_type) + 1 (Option) + 4 (Vec len) + 1 (ext disc) + 4 (ext header) + 96 (CompressionInfo) = 272
* Source: program-libs/token-interface/src/state/token/top_up.rs MIN_SIZE_WITH_COMPRESSIBLE
*/
export const COMPRESSIBLE_CTOKEN_ACCOUNT_SIZE = 272;
export const COMPRESSIBLE_LIGHT_TOKEN_ACCOUNT_SIZE = 272;

/**
* Calculate rent per epoch for a given account size.
Expand All @@ -104,11 +102,11 @@ export function rentPerEpoch(bytes: number): number {
}

/**
* Default rent per epoch for a compressible ctoken account (272 bytes).
* Default rent per epoch for a compressible light token account (272 bytes).
* = 128 + 272 = 400 lamports
*/
export const COMPRESSIBLE_CTOKEN_RENT_PER_EPOCH = rentPerEpoch(
COMPRESSIBLE_CTOKEN_ACCOUNT_SIZE,
export const COMPRESSIBLE_LIGHT_TOKEN_RENT_PER_EPOCH = rentPerEpoch(
COMPRESSIBLE_LIGHT_TOKEN_ACCOUNT_SIZE,
);

/** Default prepaid epochs (24 hours = 16 epochs * 1.5h) */
Expand All @@ -123,7 +121,7 @@ export const DEFAULT_WRITE_TOP_UP = 766;
*/
export function calculateFeePayerCostAtCreation(
prepayEpochs: number = DEFAULT_PREPAY_EPOCHS,
accountBytes: number = COMPRESSIBLE_CTOKEN_ACCOUNT_SIZE,
accountBytes: number = COMPRESSIBLE_LIGHT_TOKEN_ACCOUNT_SIZE,
): number {
return TOTAL_COMPRESSION_COST + prepayEpochs * rentPerEpoch(accountBytes);
}
40 changes: 11 additions & 29 deletions js/compressed-token/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,30 +22,12 @@ export * from './program';
export { CompressedTokenProgram as LightTokenProgram } from './program';
export * from './types';
import {
createLoadAccountsParams,
createLoadAtaInstructionsFromInterface,
createLoadAtaInstructions as _createLoadAtaInstructions,
loadAta as _loadAta,
calculateCompressibleLoadComputeUnits,
selectInputsForAmount,
CompressibleAccountInput,
ParsedAccountInfoInterface,
CompressibleLoadParams,
PackedCompressedAccount,
LoadResult,
} from './v3/actions/load-ata';

export {
createLoadAccountsParams,
createLoadAtaInstructionsFromInterface,
calculateCompressibleLoadComputeUnits,
selectInputsForAmount,
CompressibleAccountInput,
ParsedAccountInfoInterface,
CompressibleLoadParams,
PackedCompressedAccount,
LoadResult,
};
export { selectInputsForAmount };

export {
estimateTransactionSize,
Expand All @@ -59,8 +41,8 @@ export {
// Instructions
createMintInstruction,
createTokenMetadata,
createAssociatedCTokenAccountInstruction,
createAssociatedCTokenAccountIdempotentInstruction,
createAssociatedLightTokenAccountInstruction,
createAssociatedLightTokenAccountIdempotentInstruction,
createAssociatedTokenAccountInterfaceInstruction,
createAssociatedTokenAccountInterfaceIdempotentInstruction,
createAtaInterfaceIdempotentInstruction,
Expand All @@ -75,13 +57,14 @@ export {
createWrapInstruction,
createUnwrapInstruction,
createUnwrapInstructions,
createDecompressInterfaceInstruction,
createLightTokenFreezeAccountInstruction,
createLightTokenThawAccountInstruction,
createLightTokenTransferInstruction,
// Types
TokenMetadataInstructionData,
CompressibleConfig,
CTokenConfig,
CreateAssociatedCTokenAccountParams,
LightTokenConfig,
CreateAssociatedLightTokenAccountParams,
// Constants for rent sponsor
DEFAULT_COMPRESSIBLE_CONFIG,
// Actions
Expand All @@ -93,9 +76,8 @@ export {
transferInterface,
createTransferInterfaceInstructions,
sliceLast,
decompressInterface,
wrap,
mintTo as mintToCToken,
mintTo as mintToLightToken,
mintToCompressed,
mintToInterface,
updateMintAuthority,
Expand All @@ -114,8 +96,8 @@ export {
Account,
AccountState,
ParsedTokenAccount as ParsedTokenAccountInterface,
parseCTokenHot,
parseCTokenCold,
parseLightTokenHot,
parseLightTokenCold,
toAccountInfo,
convertTokenDataToAccount,
// Types
Expand Down Expand Up @@ -193,7 +175,7 @@ export async function createLoadAtaInstructions(
}

/**
* Load token balances into a c-token ATA.
* Load token balances into a light-token ATA.
*
* @param rpc RPC connection
* @param ata Associated token address
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ import {
assertBetaEnabled,
} from '@lightprotocol/stateless.js';
import {
createAssociatedCTokenAccountInstruction,
createAssociatedCTokenAccountIdempotentInstruction,
createAssociatedLightTokenAccountInstruction,
createAssociatedLightTokenAccountIdempotentInstruction,
CompressibleConfig,
} from '../instructions/create-associated-ctoken';
import { getAssociatedCTokenAddress } from '../derivation';
} from '../instructions/create-associated-light-token';
import { getAssociatedLightTokenAddress } from '../derivation';

/**
* Create an associated light-token account.
Expand All @@ -29,8 +29,9 @@ import { getAssociatedCTokenAddress } from '../derivation';
* @param rentPayerPda Optional rent payer PDA
* @param confirmOptions Optional confirm options
* @returns Address of the new associated token account
* @internal
*/
export async function createAssociatedCTokenAccount(
export async function createAssociatedLightTokenAccount(
rpc: Rpc,
payer: Signer,
owner: PublicKey,
Expand All @@ -42,7 +43,7 @@ export async function createAssociatedCTokenAccount(
): Promise<PublicKey> {
assertBetaEnabled();

const ix = createAssociatedCTokenAccountInstruction(
const ix = createAssociatedLightTokenAccountInstruction(
payer.publicKey,
owner,
mint,
Expand All @@ -61,7 +62,7 @@ export async function createAssociatedCTokenAccount(

await sendAndConfirmTx(rpc, tx, confirmOptions);

return getAssociatedCTokenAddress(owner, mint);
return getAssociatedLightTokenAddress(owner, mint);
}

/**
Expand All @@ -76,8 +77,9 @@ export async function createAssociatedCTokenAccount(
* @param rentPayerPda Optional rent payer PDA
* @param confirmOptions Optional confirm options
* @returns Address of the associated token account
* @internal
*/
export async function createAssociatedCTokenAccountIdempotent(
export async function createAssociatedLightTokenAccountIdempotent(
rpc: Rpc,
payer: Signer,
owner: PublicKey,
Expand All @@ -89,7 +91,7 @@ export async function createAssociatedCTokenAccountIdempotent(
): Promise<PublicKey> {
assertBetaEnabled();

const ix = createAssociatedCTokenAccountIdempotentInstruction(
const ix = createAssociatedLightTokenAccountIdempotentInstruction(
payer.publicKey,
owner,
mint,
Expand All @@ -108,5 +110,5 @@ export async function createAssociatedCTokenAccountIdempotent(

await sendAndConfirmTx(rpc, tx, confirmOptions);

return getAssociatedCTokenAddress(owner, mint);
return getAssociatedLightTokenAddress(owner, mint);
}
Loading