Skip to content

Conversation

@SwenSchaeferjohann
Copy link
Contributor

@SwenSchaeferjohann SwenSchaeferjohann commented Dec 3, 2025

Description

  • adds a wrapper ixn transfer2WithAta that derives the ATA and invokes transfer2 with the ata a signer via self-cpi

why

improving devex for the same reasons why solana had added atas back in the day.

alternative considered

  1. not adding. devex improvement too big to ignore for payments companies and trading apps.

  2. not doing self-cpi but call process_transfer2 and change transfer2 ownership check. saves CU cost but adds audit complexity. whereas the self-cpi approach is purely accretive.

self-cpi adds ~4400 cu extra cost for decompressing 1 ATA compared to directly invoking transfer2 with proveByIndex:true.

I think the extra cpi cost is still worth it also because:

  • creating ctoken atas with compressToPubkey=true is optional, so power users can still choose to create it the non-ata way
  • this is outside the on the cold path, so the cu cost is less critical
  • the devex improvements outweigh these drawbacks

test coverage

  • Success
    test_transfer2_with_ata_single_input_success - Decompress single ATA-owned compressed token
    test_transfer2_with_ata_multiple_inputs_success - Decompress multiple ATA-owned tokens in one call
  • Failing
    test_transfer2_with_ata_wrong_owner_signer_fails - Wrong wallet (not ATA owner) tries to sign
    test_transfer2_with_ata_wrong_mint_fails - Mint doesn't match ATA derivation
    test_transfer2_with_ata_wallet_not_signer_fails - Correct wallet key but missing signature
    test_transfer2_with_ata_wrong_ata_account_fails - Wrong ATA address passed

test_transfer2_with_ata_mixed_ownership_fails - Mix of ATA-owned and wallet-owned inputs (must all be ATA-owned)
note this is implementation detail to reduce complexity, we could remove this check safely.

test_transfer2_with_ata_wrong_bump_fails - bump must match
test_transfer2_with_ata_cu_benchmark - CU comparison vs regular Transfer2 (1 & 2 inputs)

changes to existing program code:

  • at ctoken creation, do not disable compressToPubkey for ATAs, but reuse check_seeds() to keep diff minimal:
    if let Some(compress_to_pubkey) = compressible_config_ix_data
        .compress_to_account_pubkey
        .is_some()
    {
        msg!("Associated token accounts must not compress to pubkey");
        return Err(ProgramError::InvalidInstructionData);
    }

becomes:

    if let Some(compress_to_pubkey) = compressible_config_ix_data
        .compress_to_account_pubkey
        .as_ref()
     compress_to_pubkey
            .check_seeds(associated_token_account.key())
            .map_err(|_| {
                msg!("compress_to_pubkey seeds do not match ATA derivation");
                ProgramError::InvalidInstructionData
            })?;

cu overhead comparison

1 input(s) with ata : 44363 cu
1 input(s) transfer2 : 39142 cu
1 input(s) difference : +5221 cu (+13.3%)

2 input(s) with ata : 56460 cu
2 input(s) transfer2 : 46849 cu
2 input(s) difference : +9611 cu (+20.5%)

additional changes we could consider:

  • could safely remove the check that enforces all compressed token accounts to be owned by ATA. (kept for simple audit overhead)
  • could tighten this ixn to just allow decompression flow and check that the destination key again matches the ATA (this would simplify usage but restrict transfer2WithAta unnecessarily)

Summary by CodeRabbit

Release Notes

  • New Features

    • Added support for transfers of compressed tokens owned by associated token accounts (ATAs).
    • Introduced a new Transfer2WithAta instruction type for ATA-based token operations.
    • Added utilities for decompressing ATA-owned compressed tokens with optional delegate support.
  • Improvements

    • Enhanced configuration propagation for associated token account creation.
    • Expanded multi-signer support in transaction simulation tooling.

✏️ Tip: You can customize this high-level summary in your review settings.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Dec 3, 2025

Walkthrough

This PR introduces a new Transfer2WithAta instruction type (discriminant 108) to enable compressed token transfers owned by associated token accounts. It modifies ATA creation seed validation to conditionally check compress_to_account_pubkey, adds program-level dispatch and CPI logic for ATA-based transfers, and provides SDK utilities to construct these operations with proper signer delegation and balance handling.

Changes

Cohort / File(s) Summary
Program dispatcher and ATA transfer logic
programs/compressed-token/program/src/lib.rs, programs/compressed-token/program/src/transfer2_with_ata.rs
Added new instruction type Transfer2WithAta = 108 with full deserialization and dispatch. New module transfer2_with_ata exports process_transfer2_with_ata which validates ATA derivation, resolves accounts by index, handles both delegate and non-delegate modes, constructs self-CPI to LIGHT_CPI_SIGNER with delegated signing via ATA seeds.
ATA creation seed validation
programs/compressed-token/program/src/create_associated_token_account.rs
Replaced unconditional rejection of compress_to_pubkey with conditional seed validation: when compress_to_account_pubkey is present, validates provided seeds match ATA derivation via check_seeds, returning InvalidInstructionData on mismatch.
Shared constants
sdk-libs/compressed-token-types/src/constants.rs
Added public constant TRANSFER2_WITH_ATA: u8 = 108.
SDK ATA decompression utilities
sdk-libs/compressed-token-sdk/src/ctoken/decompress_ata.rs, sdk-libs/compressed-token-sdk/src/ctoken/mod.rs
New module introduces DecompressAtaParams struct and create_decompress_ata_instruction function to transform base Transfer2 instructions into Transfer2WithAta instructions. Handles account derivation, signer marking (delegate or wallet), ATA bump resolution, and instruction data modification.
SDK ATA configuration propagation
sdk-libs/compressed-token-sdk/src/ctoken/create_ata.rs
Updated CreateAssociatedTokenAccount and CreateAssociatedTokenAccount2 builders to propagate compress_to_account_pubkey from config instead of setting to None in both instruction and params conversions.
RPC-driven token client
sdk-libs/token-client/src/instructions/transfer2_with_ata.rs, sdk-libs/token-client/src/instructions/mod.rs
New module adds DecompressAtaInput struct and create_decompress_ata_instruction_rpc async function for end-to-end ATA decompression workflow. Validates owner/ATA consistency, derives expected ATA, computes total balance, builds base Transfer2 instruction, and transforms to Transfer2WithAta using SDK utilities.
Test utilities
sdk-libs/program-test/src/utils/simulation.rs, sdk-libs/program-test/src/utils/mod.rs
Introduced simulate_cu_multi to support multi-signer simulations. Refactored simulate_cu to delegate to simulate_cu_multi with empty additional signers. Exported both functions from utils module.

Sequence Diagram

sequenceDiagram
    participant Client as Client SDK
    participant Transform as SDK Transformer
    participant Prog as Program Dispatcher
    participant Handler as Transfer2WithAta Handler
    participant CPI as LIGHT_CPI_SIGNER (CPI)

    Client->>Client: Build base Transfer2 decompress instruction
    Client->>Transform: create_decompress_ata_instruction(transfer2_ix, params)
    activate Transform
    Transform->>Transform: Derive ATA from owner_wallet + mint
    Transform->>Transform: Locate/add wallet, mint, ATA in accounts
    Transform->>Transform: Mark signer flags (delegate or wallet)
    Transform->>Transform: Append wallet_idx, mint_idx, ata_idx, bump, use_delegate to data
    Transform-->>Client: Return Transfer2WithAta instruction
    deactivate Transform
    
    Client->>Prog: Submit instruction (discriminant 108)
    activate Prog
    Prog->>Handler: InstructionType::Transfer2WithAta → process_transfer2_with_ata()
    deactivate Prog
    
    activate Handler
    Handler->>Handler: Parse data: transfer2 payload + wallet/mint/ata indices + bump
    Handler->>Handler: Resolve accounts by index
    Handler->>Handler: Derive expected ATA using seeds [owner, LIGHT_CPI_SIGNER, mint]
    Handler->>Handler: Validate derived ATA matches provided ATA
    
    alt use_delegate = true
    Handler->>Handler: Validate delegate is signer
    Handler->>Handler: Check all inputs have matching delegate
    else use_delegate = false
    Handler->>Handler: Validate wallet owner is signer
    end
    
    Handler->>CPI: slice_invoke_signed with data prefix 101 + transfer2 payload
    activate CPI
    CPI-->>Handler: Success
    deactivate CPI
    Handler-->>Client: Return result
    deactivate Handler
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

Areas requiring extra attention:

  • transfer2_with_ata.rs (program handler) — Dense validation logic with dual modes (delegate vs. non-delegate), account resolution by index, ATA derivation with seed verification, and CPI construction. Requires careful review of signer validation and CPI account meta ordering.
  • create_decompress_ata_instruction_rpc in token-client — Orchestrates RPC calls, balance computation, instruction transformation, and delegate consistency checks across multiple layers. Complex state management and error propagation paths.
  • create_decompress_ata_instruction in decompress_ata.rs — Account list mutation, index management, and instruction data serialization. Ensure bump and index consistency with program-side derivation.
  • ATA seed validation change in create_associated_token_account.rs — Verify that conditional logic correctly distinguishes when check_seeds should be invoked vs. skipped, and that error messaging aligns with on-chain behavior.

Possibly related PRs

Suggested labels

ai-review

Suggested reviewers

  • sergeytimoshin
  • ananas-block

Poem

🔐 Seeds align, ATAs derived with care,
Delegates sign, compressed tokens in the air,
From Transfer2 to Transfer2WithAta flow,
Multi-layer validation, delegated glow.

Pre-merge checks and finishing touches

✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'feat: add transfer2WithAta ixn wrapper' clearly and concisely describes the primary change: introducing a new instruction wrapper for transfer2 that operates with associated token accounts.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 70.00%.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch swen/compressed-ata

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 5

📜 Review details

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 82470c4 and cc71592.

⛔ Files ignored due to path filters (2)
  • program-tests/compressed-token-test/tests/transfer2/mod.rs is excluded by none and included by none
  • program-tests/compressed-token-test/tests/transfer2/transfer2_with_ata.rs is excluded by none and included by none
📒 Files selected for processing (11)
  • programs/compressed-token/program/src/create_associated_token_account.rs (1 hunks)
  • programs/compressed-token/program/src/lib.rs (5 hunks)
  • programs/compressed-token/program/src/transfer2_with_ata.rs (1 hunks)
  • sdk-libs/compressed-token-sdk/src/ctoken/create_ata.rs (4 hunks)
  • sdk-libs/compressed-token-sdk/src/ctoken/decompress_ata.rs (1 hunks)
  • sdk-libs/compressed-token-sdk/src/ctoken/mod.rs (2 hunks)
  • sdk-libs/compressed-token-types/src/constants.rs (1 hunks)
  • sdk-libs/program-test/src/utils/mod.rs (1 hunks)
  • sdk-libs/program-test/src/utils/simulation.rs (1 hunks)
  • sdk-libs/token-client/src/instructions/mod.rs (1 hunks)
  • sdk-libs/token-client/src/instructions/transfer2_with_ata.rs (1 hunks)
🧰 Additional context used
📓 Path-based instructions (5)
sdk-libs/**/*.rs

📄 CodeRabbit inference engine (CLAUDE.md)

Unit tests in sdk-libs must not depend on light-test-utils; any test requiring light-test-utils must be in sdk-tests

Files:

  • sdk-libs/compressed-token-sdk/src/ctoken/mod.rs
  • sdk-libs/token-client/src/instructions/mod.rs
  • sdk-libs/compressed-token-types/src/constants.rs
  • sdk-libs/compressed-token-sdk/src/ctoken/decompress_ata.rs
  • sdk-libs/token-client/src/instructions/transfer2_with_ata.rs
  • sdk-libs/compressed-token-sdk/src/ctoken/create_ata.rs
  • sdk-libs/program-test/src/utils/simulation.rs
  • sdk-libs/program-test/src/utils/mod.rs
programs/compressed-token/program/src/**/*.rs

📄 CodeRabbit inference engine (programs/compressed-token/program/CLAUDE.md)

programs/compressed-token/program/src/**/*.rs: Compressed token accounts (ctoken solana accounts) must use the same account layout as SPL tokens with a custom Compressible extension
Compressed mint accounts (cmints) support only one extension: TokenMetadata

Files:

  • programs/compressed-token/program/src/create_associated_token_account.rs
  • programs/compressed-token/program/src/lib.rs
  • programs/compressed-token/program/src/transfer2_with_ata.rs
programs/compressed-token/program/src/create_*_account*.rs

📄 CodeRabbit inference engine (programs/compressed-token/program/CLAUDE.md)

Token account creation instructions (Create CToken Account and Create Associated CToken Account) require ACTIVE config validation only

Files:

  • programs/compressed-token/program/src/create_associated_token_account.rs
**/programs/**/src/**/*.rs

📄 CodeRabbit inference engine (DOCS.md)

For accounts with associated methods, add a Methods section grouping methods by purpose (Validation, Constructors, PDA Derivation, etc.) with concise parameter names in signatures, one-line action-oriented descriptions, and concrete values where helpful (constants, defaults)

Files:

  • programs/compressed-token/program/src/create_associated_token_account.rs
  • programs/compressed-token/program/src/lib.rs
  • programs/compressed-token/program/src/transfer2_with_ata.rs
programs/**/*.rs

📄 CodeRabbit inference engine (CLAUDE.md)

Unit tests in programs must not depend on light-test-utils; any test requiring light-test-utils must be in program-tests

Files:

  • programs/compressed-token/program/src/create_associated_token_account.rs
  • programs/compressed-token/program/src/lib.rs
  • programs/compressed-token/program/src/transfer2_with_ata.rs
🧠 Learnings (77)
📓 Common learnings
Learnt from: CR
Repo: Lightprotocol/light-protocol PR: 0
File: programs/compressed-token/program/CLAUDE.md:0-0
Timestamp: 2025-11-24T18:01:42.343Z
Learning: Applies to programs/compressed-token/program/src/transfer2/**/*.rs : Transfer2 instruction must support Compress, Decompress, and CompressAndClose operations with multi-mint support and sum checks
Learnt from: CR
Repo: Lightprotocol/light-protocol PR: 0
File: programs/compressed-token/program/docs/instructions/CLAUDE.md:0-0
Timestamp: 2025-11-24T18:01:54.689Z
Learning: Applies to programs/compressed-token/program/docs/instructions/instructions/TRANSFER2.md : Transfer2 documentation must cover batch transfer instruction supporting compress/decompress/transfer operations
Learnt from: CR
Repo: Lightprotocol/light-protocol PR: 0
File: programs/compressed-token/program/docs/instructions/CLAUDE.md:0-0
Timestamp: 2025-11-24T18:01:54.689Z
Learning: Applies to programs/compressed-token/program/docs/instructions/instructions/DECOMPRESSED_TRANSFER.md : Decompressed Transfer documentation must cover SPL-compatible transfers between decompressed accounts
Learnt from: CR
Repo: Lightprotocol/light-protocol PR: 0
File: sdk-tests/sdk-ctoken-test/README.md:0-0
Timestamp: 2025-11-24T17:55:32.059Z
Learning: Implement all 8 core compressed token operations: create_cmint, mint_to_ctoken, create_token_account_invoke, create_token_account_invoke_signed, create_ata_invoke, create_ata_invoke_signed, transfer_interface_invoke, and transfer_interface_invoke_signed
Learnt from: CR
Repo: Lightprotocol/light-protocol PR: 0
File: programs/registry/CLAUDE.md:0-0
Timestamp: 2025-11-24T18:02:15.670Z
Learning: Applies to programs/registry/src/account_compression_cpi/*.rs : Create wrapper instruction module at `src/account_compression_cpi/new_operation.rs` with `NewOperationContext` struct defining required accounts
Learnt from: CR
Repo: Lightprotocol/light-protocol PR: 0
File: programs/registry/CLAUDE.md:0-0
Timestamp: 2025-11-24T18:02:15.670Z
Learning: Applies to programs/registry/src/account_compression_cpi/*.rs : Implement `process_new_operation()` function in wrapper module to handle PDA signer setup, account mapping, and CPI execution
Learnt from: CR
Repo: Lightprotocol/light-protocol PR: 0
File: programs/compressed-token/program/CLAUDE.md:0-0
Timestamp: 2025-11-24T18:01:42.343Z
Learning: Applies to programs/compressed-token/program/docs/ACCOUNTS.md : All account documentation must include: description, discriminator, state layout, serialization example, hashing (for compressed accounts only), derivation (for PDAs only), and associated instructions
Learnt from: CR
Repo: Lightprotocol/light-protocol PR: 0
File: programs/compressed-token/program/CLAUDE.md:0-0
Timestamp: 2025-11-24T18:01:42.343Z
Learning: Applies to programs/compressed-token/program/src/{claim,transfer2}/**/*.rs : Rent authority can only compress accounts when is_compressible() returns true; lamport distribution on close is: rent → rent_sponsor, unutilized → destination
Learnt from: CR
Repo: Lightprotocol/light-protocol PR: 0
File: programs/compressed-token/program/docs/instructions/CLAUDE.md:0-0
Timestamp: 2025-11-24T18:01:54.689Z
Learning: Applies to programs/compressed-token/program/docs/instructions/instructions/CREATE_TOKEN_ACCOUNT.md : Create Token Account Instructions documentation must cover creation of regular and associated ctoken accounts
Learnt from: CR
Repo: Lightprotocol/light-protocol PR: 0
File: programs/compressed-token/program/CLAUDE.md:0-0
Timestamp: 2025-11-24T18:01:42.343Z
Learning: Applies to programs/compressed-token/program/src/mint_action/**/*.rs : MintAction instruction must support 9 action types: CreateCompressedMint, MintTo, UpdateMintAuthority, UpdateFreezeAuthority, CreateSplMint, MintToCToken, UpdateMetadataField, UpdateMetadataAuthority, RemoveMetadataKey
📚 Learning: 2025-11-24T17:55:17.323Z
Learnt from: CR
Repo: Lightprotocol/light-protocol PR: 0
File: sdk-libs/macros/src/compressible/README.md:0-0
Timestamp: 2025-11-24T17:55:17.323Z
Learning: Applies to sdk-libs/macros/src/compressible/**/decompress_context.rs : Decompression trait implementation (`DecompressContext`) with account accessors, PDA/token separation logic, and token processing delegation should be in `decompress_context.rs`

Applied to files:

  • sdk-libs/compressed-token-sdk/src/ctoken/mod.rs
  • sdk-libs/compressed-token-sdk/src/ctoken/decompress_ata.rs
  • sdk-libs/token-client/src/instructions/transfer2_with_ata.rs
  • sdk-libs/compressed-token-sdk/src/ctoken/create_ata.rs
📚 Learning: 2025-11-24T18:02:15.670Z
Learnt from: CR
Repo: Lightprotocol/light-protocol PR: 0
File: programs/registry/CLAUDE.md:0-0
Timestamp: 2025-11-24T18:02:15.670Z
Learning: Applies to programs/registry/src/account_compression_cpi/mod.rs : Export new wrapper modules in `account_compression_cpi/mod.rs` using `pub mod new_operation;` and `pub use new_operation::*;`, then import in `lib.rs`

Applied to files:

  • sdk-libs/compressed-token-sdk/src/ctoken/mod.rs
  • sdk-libs/token-client/src/instructions/mod.rs
  • programs/compressed-token/program/src/lib.rs
  • sdk-libs/token-client/src/instructions/transfer2_with_ata.rs
  • sdk-libs/program-test/src/utils/mod.rs
📚 Learning: 2025-11-24T17:55:17.323Z
Learnt from: CR
Repo: Lightprotocol/light-protocol PR: 0
File: sdk-libs/macros/src/compressible/README.md:0-0
Timestamp: 2025-11-24T17:55:17.323Z
Learning: Applies to sdk-libs/macros/src/compressible/**/instructions.rs : Compress/decompress instruction handlers and context struct generation should be implemented in `instructions.rs`, with compress using PDA-only and decompress supporting full PDA + ctoken

Applied to files:

  • sdk-libs/compressed-token-sdk/src/ctoken/mod.rs
  • programs/compressed-token/program/src/create_associated_token_account.rs
  • programs/compressed-token/program/src/lib.rs
  • programs/compressed-token/program/src/transfer2_with_ata.rs
  • sdk-libs/compressed-token-sdk/src/ctoken/decompress_ata.rs
  • sdk-libs/token-client/src/instructions/transfer2_with_ata.rs
  • sdk-libs/compressed-token-sdk/src/ctoken/create_ata.rs
📚 Learning: 2025-11-24T17:55:17.323Z
Learnt from: CR
Repo: Lightprotocol/light-protocol PR: 0
File: sdk-libs/macros/src/compressible/README.md:0-0
Timestamp: 2025-11-24T17:55:17.323Z
Learning: Applies to sdk-libs/macros/src/compressible/**/mod.rs : Module declaration should be kept in `mod.rs`

Applied to files:

  • sdk-libs/compressed-token-sdk/src/ctoken/mod.rs
  • sdk-libs/program-test/src/utils/mod.rs
📚 Learning: 2025-11-24T17:55:17.323Z
Learnt from: CR
Repo: Lightprotocol/light-protocol PR: 0
File: sdk-libs/macros/src/compressible/README.md:0-0
Timestamp: 2025-11-24T17:55:17.323Z
Learning: Applies to sdk-libs/macros/src/compressible/**/pack_unpack.rs : Pubkey compression logic and `PackedXxx` struct generation with Pack/Unpack trait implementations should be in `pack_unpack.rs`

Applied to files:

  • sdk-libs/compressed-token-sdk/src/ctoken/mod.rs
📚 Learning: 2025-11-24T18:01:14.087Z
Learnt from: CR
Repo: Lightprotocol/light-protocol PR: 0
File: program-libs/compressible/CLAUDE.md:0-0
Timestamp: 2025-11-24T18:01:14.087Z
Learning: Applies to program-libs/compressible/**/*.rs : Derive PDA addresses using `derive_pda` and `derive_v1_config_pda` functions for CToken account configuration

Applied to files:

  • sdk-libs/compressed-token-sdk/src/ctoken/mod.rs
  • programs/compressed-token/program/src/create_associated_token_account.rs
  • programs/compressed-token/program/src/transfer2_with_ata.rs
  • sdk-libs/compressed-token-sdk/src/ctoken/decompress_ata.rs
  • sdk-libs/token-client/src/instructions/transfer2_with_ata.rs
  • sdk-libs/compressed-token-sdk/src/ctoken/create_ata.rs
📚 Learning: 2025-11-24T17:55:17.323Z
Learnt from: CR
Repo: Lightprotocol/light-protocol PR: 0
File: sdk-libs/macros/src/compressible/README.md:0-0
Timestamp: 2025-11-24T17:55:17.323Z
Learning: Applies to sdk-libs/macros/src/compressible/**/traits.rs : Core trait implementations (`HasCompressionInfo`, `CompressAs`, `Compressible`) should be defined in `traits.rs`

Applied to files:

  • sdk-libs/compressed-token-sdk/src/ctoken/mod.rs
📚 Learning: 2025-11-24T17:55:32.059Z
Learnt from: CR
Repo: Lightprotocol/light-protocol PR: 0
File: sdk-tests/sdk-ctoken-test/README.md:0-0
Timestamp: 2025-11-24T17:55:32.059Z
Learning: Applies to sdk-tests/sdk-ctoken-test/**/*.rs : Use the builder pattern from `light-compressed-token-sdk::ctoken` module for CPI operations instead of manual instruction building

Applied to files:

  • sdk-libs/compressed-token-sdk/src/ctoken/mod.rs
  • sdk-libs/token-client/src/instructions/mod.rs
  • sdk-libs/token-client/src/instructions/transfer2_with_ata.rs
📚 Learning: 2025-11-24T18:02:15.670Z
Learnt from: CR
Repo: Lightprotocol/light-protocol PR: 0
File: programs/registry/CLAUDE.md:0-0
Timestamp: 2025-11-24T18:02:15.670Z
Learning: Applies to programs/registry/src/account_compression_cpi/*.rs : Create wrapper instruction module at `src/account_compression_cpi/new_operation.rs` with `NewOperationContext` struct defining required accounts

Applied to files:

  • sdk-libs/compressed-token-sdk/src/ctoken/mod.rs
  • sdk-libs/token-client/src/instructions/mod.rs
  • programs/compressed-token/program/src/lib.rs
  • programs/compressed-token/program/src/transfer2_with_ata.rs
  • sdk-libs/compressed-token-sdk/src/ctoken/decompress_ata.rs
  • sdk-libs/token-client/src/instructions/transfer2_with_ata.rs
  • sdk-libs/compressed-token-sdk/src/ctoken/create_ata.rs
📚 Learning: 2025-11-24T17:55:17.323Z
Learnt from: CR
Repo: Lightprotocol/light-protocol PR: 0
File: sdk-libs/macros/src/compressible/README.md:0-0
Timestamp: 2025-11-24T17:55:17.323Z
Learning: Applies to sdk-libs/macros/src/compressible/**/seed_providers.rs : PDA and CToken seed provider implementations with client-side seed functions should be in `seed_providers.rs`

Applied to files:

  • sdk-libs/compressed-token-sdk/src/ctoken/mod.rs
  • programs/compressed-token/program/src/create_associated_token_account.rs
📚 Learning: 2025-11-24T17:55:32.059Z
Learnt from: CR
Repo: Lightprotocol/light-protocol PR: 0
File: sdk-tests/sdk-ctoken-test/README.md:0-0
Timestamp: 2025-11-24T17:55:32.059Z
Learning: Implement all 8 core compressed token operations: create_cmint, mint_to_ctoken, create_token_account_invoke, create_token_account_invoke_signed, create_ata_invoke, create_ata_invoke_signed, transfer_interface_invoke, and transfer_interface_invoke_signed

Applied to files:

  • sdk-libs/compressed-token-sdk/src/ctoken/mod.rs
  • sdk-libs/token-client/src/instructions/mod.rs
  • programs/compressed-token/program/src/lib.rs
  • sdk-libs/compressed-token-types/src/constants.rs
  • programs/compressed-token/program/src/transfer2_with_ata.rs
  • sdk-libs/compressed-token-sdk/src/ctoken/decompress_ata.rs
  • sdk-libs/token-client/src/instructions/transfer2_with_ata.rs
📚 Learning: 2025-11-24T18:01:42.343Z
Learnt from: CR
Repo: Lightprotocol/light-protocol PR: 0
File: programs/compressed-token/program/CLAUDE.md:0-0
Timestamp: 2025-11-24T18:01:42.343Z
Learning: Applies to programs/compressed-token/program/src/transfer2/**/*.rs : Transfer2 instruction must support Compress, Decompress, and CompressAndClose operations with multi-mint support and sum checks

Applied to files:

  • sdk-libs/compressed-token-sdk/src/ctoken/mod.rs
  • sdk-libs/token-client/src/instructions/mod.rs
  • programs/compressed-token/program/src/lib.rs
  • sdk-libs/compressed-token-types/src/constants.rs
  • programs/compressed-token/program/src/transfer2_with_ata.rs
  • sdk-libs/compressed-token-sdk/src/ctoken/decompress_ata.rs
  • sdk-libs/token-client/src/instructions/transfer2_with_ata.rs
  • sdk-libs/compressed-token-sdk/src/ctoken/create_ata.rs
📚 Learning: 2025-11-24T18:01:42.343Z
Learnt from: CR
Repo: Lightprotocol/light-protocol PR: 0
File: programs/compressed-token/program/CLAUDE.md:0-0
Timestamp: 2025-11-24T18:01:42.343Z
Learning: Applies to programs/compressed-token/program/src/mint_action/**/*.rs : MintAction instruction must support 9 action types: CreateCompressedMint, MintTo, UpdateMintAuthority, UpdateFreezeAuthority, CreateSplMint, MintToCToken, UpdateMetadataField, UpdateMetadataAuthority, RemoveMetadataKey

Applied to files:

  • sdk-libs/compressed-token-sdk/src/ctoken/mod.rs
  • sdk-libs/token-client/src/instructions/mod.rs
  • programs/compressed-token/program/src/lib.rs
  • sdk-libs/compressed-token-sdk/src/ctoken/decompress_ata.rs
📚 Learning: 2025-11-24T18:01:42.343Z
Learnt from: CR
Repo: Lightprotocol/light-protocol PR: 0
File: programs/compressed-token/program/CLAUDE.md:0-0
Timestamp: 2025-11-24T18:01:42.343Z
Learning: Applies to programs/compressed-token/program/src/**/*.rs : Compressed mint accounts (cmints) support only one extension: TokenMetadata

Applied to files:

  • sdk-libs/compressed-token-sdk/src/ctoken/mod.rs
  • sdk-libs/token-client/src/instructions/mod.rs
📚 Learning: 2025-11-24T18:01:42.343Z
Learnt from: CR
Repo: Lightprotocol/light-protocol PR: 0
File: programs/compressed-token/program/CLAUDE.md:0-0
Timestamp: 2025-11-24T18:01:42.343Z
Learning: Applies to programs/compressed-token/program/src/{claim,transfer2}/**/*.rs : Rent authority can only compress accounts when is_compressible() returns true; lamport distribution on close is: rent → rent_sponsor, unutilized → destination

Applied to files:

  • sdk-libs/compressed-token-sdk/src/ctoken/mod.rs
  • sdk-libs/token-client/src/instructions/mod.rs
  • programs/compressed-token/program/src/create_associated_token_account.rs
  • programs/compressed-token/program/src/transfer2_with_ata.rs
  • sdk-libs/compressed-token-sdk/src/ctoken/decompress_ata.rs
  • sdk-libs/token-client/src/instructions/transfer2_with_ata.rs
  • sdk-libs/compressed-token-sdk/src/ctoken/create_ata.rs
📚 Learning: 2025-11-24T17:53:40.537Z
Learnt from: CR
Repo: Lightprotocol/light-protocol PR: 0
File: cli/README.md:0-0
Timestamp: 2025-11-24T17:53:40.537Z
Learning: Implement CLI commands: create-mint, mint-to, transfer, compress-sol, and decompress-sol with their specified flags and required parameters

Applied to files:

  • sdk-libs/compressed-token-sdk/src/ctoken/mod.rs
📚 Learning: 2025-11-24T18:00:13.178Z
Learnt from: CR
Repo: Lightprotocol/light-protocol PR: 0
File: program-libs/compressible/docs/CONFIG_ACCOUNT.md:0-0
Timestamp: 2025-11-24T18:00:13.178Z
Learning: Applies to program-libs/compressible/docs/**/config.rs : Set CompressibleConfig default values for CToken V1: base_rent = 1220, compression_cost = 11000, lamports_per_byte_per_epoch = 10, and address_space[0] = `amt2kaJA14v3urZbZvnc5v2np8jqvc4Z8zDep5wbtzx`

Applied to files:

  • sdk-libs/compressed-token-sdk/src/ctoken/mod.rs
  • sdk-libs/compressed-token-sdk/src/ctoken/create_ata.rs
📚 Learning: 2025-11-24T18:02:30.871Z
Learnt from: CR
Repo: Lightprotocol/light-protocol PR: 0
File: sdk-tests/sdk-token-test/CLAUDE.md:0-0
Timestamp: 2025-11-24T18:02:30.871Z
Learning: Use light-compressed-token-sdk functions from sdk-libs/compressed-token-sdk for testing ctoken instructions

Applied to files:

  • sdk-libs/compressed-token-sdk/src/ctoken/mod.rs
  • sdk-libs/token-client/src/instructions/transfer2_with_ata.rs
📚 Learning: 2025-11-24T17:54:38.537Z
Learnt from: CR
Repo: Lightprotocol/light-protocol PR: 0
File: programs/compressed-token/program/README.md:0-0
Timestamp: 2025-11-24T17:54:38.537Z
Learning: Implement compressed token program interfaces for third-party token creation and usage on Solana using ZK Compression

Applied to files:

  • sdk-libs/compressed-token-sdk/src/ctoken/mod.rs
  • sdk-libs/token-client/src/instructions/transfer2_with_ata.rs
📚 Learning: 2025-11-24T17:56:00.229Z
Learnt from: CR
Repo: Lightprotocol/light-protocol PR: 0
File: program-libs/batched-merkle-tree/docs/CLAUDE.md:0-0
Timestamp: 2025-11-24T17:56:00.229Z
Learning: Applies to program-libs/batched-merkle-tree/docs/**/Cargo.toml : Depend on light-compressed-account crate for compressed account types and utilities

Applied to files:

  • sdk-libs/compressed-token-sdk/src/ctoken/mod.rs
  • sdk-libs/token-client/src/instructions/mod.rs
📚 Learning: 2025-11-24T18:01:42.343Z
Learnt from: CR
Repo: Lightprotocol/light-protocol PR: 0
File: programs/compressed-token/program/CLAUDE.md:0-0
Timestamp: 2025-11-24T18:01:42.343Z
Learning: Data structures (state and instruction types) must be defined in the separate 'light-ctoken-types' crate (program-libs/ctoken-types/) to allow SDKs to import types without program dependencies

Applied to files:

  • sdk-libs/token-client/src/instructions/mod.rs
📚 Learning: 2025-11-24T18:01:54.689Z
Learnt from: CR
Repo: Lightprotocol/light-protocol PR: 0
File: programs/compressed-token/program/docs/instructions/CLAUDE.md:0-0
Timestamp: 2025-11-24T18:01:54.689Z
Learning: Applies to programs/compressed-token/program/docs/instructions/instructions/TRANSFER2.md : Transfer2 documentation must cover batch transfer instruction supporting compress/decompress/transfer operations

Applied to files:

  • sdk-libs/token-client/src/instructions/mod.rs
  • programs/compressed-token/program/src/lib.rs
  • sdk-libs/compressed-token-types/src/constants.rs
  • programs/compressed-token/program/src/transfer2_with_ata.rs
  • sdk-libs/compressed-token-sdk/src/ctoken/decompress_ata.rs
  • sdk-libs/token-client/src/instructions/transfer2_with_ata.rs
📚 Learning: 2025-11-24T18:01:30.012Z
Learnt from: CR
Repo: Lightprotocol/light-protocol PR: 0
File: program-tests/CLAUDE.md:0-0
Timestamp: 2025-11-24T18:01:30.012Z
Learning: Run compressed token core tests using `cargo test-sbf -p compressed-token-test --test ctoken`, `--test v1`, `--test mint`, and `--test transfer2`

Applied to files:

  • sdk-libs/token-client/src/instructions/mod.rs
📚 Learning: 2025-11-24T18:01:54.689Z
Learnt from: CR
Repo: Lightprotocol/light-protocol PR: 0
File: programs/compressed-token/program/docs/instructions/CLAUDE.md:0-0
Timestamp: 2025-11-24T18:01:54.689Z
Learning: Applies to programs/compressed-token/program/docs/instructions/instructions/MINT_ACTION.md : MintAction documentation must cover batch instruction for compressed mint management supporting 9 actions: CreateCompressedMint, MintTo, UpdateMintAuthority, UpdateFreezeAuthority, CreateSplMint, MintToCToken, UpdateMetadataField, UpdateMetadataAuthority, RemoveMetadataKey

Applied to files:

  • sdk-libs/token-client/src/instructions/mod.rs
📚 Learning: 2025-11-24T18:00:13.178Z
Learnt from: CR
Repo: Lightprotocol/light-protocol PR: 0
File: program-libs/compressible/docs/CONFIG_ACCOUNT.md:0-0
Timestamp: 2025-11-24T18:00:13.178Z
Learning: Applies to program-libs/compressible/docs/**/*instruction*.rs : Validate CompressibleConfig state using `validate_active()` method to ensure state == Active before allowing new compressed token account creation

Applied to files:

  • programs/compressed-token/program/src/create_associated_token_account.rs
  • sdk-libs/compressed-token-sdk/src/ctoken/create_ata.rs
📚 Learning: 2025-11-24T18:01:42.343Z
Learnt from: CR
Repo: Lightprotocol/light-protocol PR: 0
File: programs/compressed-token/program/CLAUDE.md:0-0
Timestamp: 2025-11-24T18:01:42.343Z
Learning: Applies to programs/compressed-token/program/src/create_*_account*.rs : Token account creation instructions (Create CToken Account and Create Associated CToken Account) require ACTIVE config validation only

Applied to files:

  • programs/compressed-token/program/src/create_associated_token_account.rs
  • sdk-libs/compressed-token-sdk/src/ctoken/create_ata.rs
📚 Learning: 2025-11-24T18:01:14.087Z
Learnt from: CR
Repo: Lightprotocol/light-protocol PR: 0
File: program-libs/compressible/CLAUDE.md:0-0
Timestamp: 2025-11-24T18:01:14.087Z
Learning: Applies to program-libs/compressible/**/*.rs : Implement state validation methods (`validate_active`, `validate_not_inactive`) for CompressibleConfig account state verification

Applied to files:

  • programs/compressed-token/program/src/create_associated_token_account.rs
📚 Learning: 2025-11-24T17:59:03.485Z
Learnt from: CR
Repo: Lightprotocol/light-protocol PR: 0
File: program-libs/account-checks/docs/ACCOUNT_INFO_TRAIT.md:0-0
Timestamp: 2025-11-24T17:59:03.485Z
Learning: Applies to program-libs/account-checks/docs/**/*.rs : PDA derivation functions should accept `&[&[u8]]` for seeds and `&[u8; 32]` for program_id when using AccountInfoTrait methods `find_program_address()` or `create_program_address()`

Applied to files:

  • programs/compressed-token/program/src/create_associated_token_account.rs
📚 Learning: 2025-11-24T17:58:50.237Z
Learnt from: CR
Repo: Lightprotocol/light-protocol PR: 0
File: program-libs/account-checks/docs/ACCOUNT_CHECKS.md:0-0
Timestamp: 2025-11-24T17:58:50.237Z
Learning: Applies to program-libs/account-checks/docs/program-libs/account-checks/src/checks.rs : Implement `check_pda_seeds` function to derive PDA using `find_program_address` and verify it matches account key, returning `InvalidSeeds` (20010) error on mismatch

Applied to files:

  • programs/compressed-token/program/src/create_associated_token_account.rs
📚 Learning: 2025-11-24T18:01:42.343Z
Learnt from: CR
Repo: Lightprotocol/light-protocol PR: 0
File: programs/compressed-token/program/CLAUDE.md:0-0
Timestamp: 2025-11-24T18:01:42.343Z
Learning: Applies to programs/compressed-token/program/src/**/*.rs : Compressed token accounts (ctoken solana accounts) must use the same account layout as SPL tokens with a custom Compressible extension

Applied to files:

  • programs/compressed-token/program/src/create_associated_token_account.rs
  • programs/compressed-token/program/src/transfer2_with_ata.rs
  • sdk-libs/compressed-token-sdk/src/ctoken/create_ata.rs
📚 Learning: 2025-11-24T18:01:42.343Z
Learnt from: CR
Repo: Lightprotocol/light-protocol PR: 0
File: programs/compressed-token/program/CLAUDE.md:0-0
Timestamp: 2025-11-24T18:01:42.343Z
Learning: Applies to programs/compressed-token/program/programs/compressed-token/anchor/src/lib.rs : Custom error codes must be defined in programs/compressed-token/anchor/src/lib.rs as the 'anchor_compressed_token::ErrorCode' enum

Applied to files:

  • programs/compressed-token/program/src/create_associated_token_account.rs
  • programs/compressed-token/program/src/lib.rs
  • sdk-libs/compressed-token-types/src/constants.rs
📚 Learning: 2025-11-24T18:00:13.178Z
Learnt from: CR
Repo: Lightprotocol/light-protocol PR: 0
File: program-libs/compressible/docs/CONFIG_ACCOUNT.md:0-0
Timestamp: 2025-11-24T18:00:13.178Z
Learning: Applies to program-libs/compressible/docs/**/programs/**/*.rs : Use Anchor's `AccountDeserialize::try_deserialize` for CompressibleConfig when Anchor feature is enabled, which includes automatic discriminator validation

Applied to files:

  • programs/compressed-token/program/src/create_associated_token_account.rs
📚 Learning: 2025-11-24T18:01:42.343Z
Learnt from: CR
Repo: Lightprotocol/light-protocol PR: 0
File: programs/compressed-token/program/CLAUDE.md:0-0
Timestamp: 2025-11-24T18:01:42.343Z
Learning: Applies to programs/compressed-token/program/src/close_token_account.rs : Close Token Account instruction must return rent exemption to rent recipient if compressible, and return remaining lamports to destination account

Applied to files:

  • programs/compressed-token/program/src/create_associated_token_account.rs
  • programs/compressed-token/program/src/transfer2_with_ata.rs
  • sdk-libs/compressed-token-sdk/src/ctoken/decompress_ata.rs
  • sdk-libs/compressed-token-sdk/src/ctoken/create_ata.rs
📚 Learning: 2025-11-24T18:01:14.087Z
Learnt from: CR
Repo: Lightprotocol/light-protocol PR: 0
File: program-libs/compressible/CLAUDE.md:0-0
Timestamp: 2025-11-24T18:01:14.087Z
Learning: Applies to program-libs/compressible/**/*.rs : Use Anchor serialization for CompressibleConfig account structures in Rust programs

Applied to files:

  • programs/compressed-token/program/src/create_associated_token_account.rs
  • programs/compressed-token/program/src/lib.rs
  • sdk-libs/compressed-token-sdk/src/ctoken/create_ata.rs
📚 Learning: 2025-11-24T18:01:14.087Z
Learnt from: CR
Repo: Lightprotocol/light-protocol PR: 0
File: program-libs/compressible/CLAUDE.md:0-0
Timestamp: 2025-11-24T18:01:14.087Z
Learning: Applies to program-libs/compressible/**/*.rs : Use `calculate_rent_and_balance` function to determine if a CToken account is compressible

Applied to files:

  • programs/compressed-token/program/src/create_associated_token_account.rs
  • sdk-libs/compressed-token-sdk/src/ctoken/create_ata.rs
📚 Learning: 2025-11-24T18:00:13.178Z
Learnt from: CR
Repo: Lightprotocol/light-protocol PR: 0
File: program-libs/compressible/docs/CONFIG_ACCOUNT.md:0-0
Timestamp: 2025-11-24T18:00:13.178Z
Learning: Applies to program-libs/compressible/docs/**/*.rs : Validate CompressibleConfig account ownership against Light Registry Program address (`Lighton6oQpVkeewmo2mcPTQQp7kYHr4fWpAgJyEmDX`) before processing

Applied to files:

  • programs/compressed-token/program/src/create_associated_token_account.rs
  • sdk-libs/compressed-token-sdk/src/ctoken/create_ata.rs
📚 Learning: 2025-11-24T18:00:21.501Z
Learnt from: CR
Repo: Lightprotocol/light-protocol PR: 0
File: program-libs/compressible/docs/ERRORS.md:0-0
Timestamp: 2025-11-24T18:00:21.501Z
Learning: Applies to program-libs/compressible/docs/program-libs/compressible/src/**/*.rs : InvalidState (Error Code 19002): For account creation, ensure CompressibleConfig state is `Active` (1). For other operations (claim, withdraw, compress & close), ensure config state is not `Inactive` (0). Validate config state using `config.validate_active()` for creation and `config.validate_not_inactive()` for other operations.

Applied to files:

  • programs/compressed-token/program/src/create_associated_token_account.rs
📚 Learning: 2025-11-24T18:02:15.670Z
Learnt from: CR
Repo: Lightprotocol/light-protocol PR: 0
File: programs/registry/CLAUDE.md:0-0
Timestamp: 2025-11-24T18:02:15.670Z
Learning: Applies to programs/registry/src/account_compression_cpi/*.rs : Implement `process_new_operation()` function in wrapper module to handle PDA signer setup, account mapping, and CPI execution

Applied to files:

  • programs/compressed-token/program/src/lib.rs
  • programs/compressed-token/program/src/transfer2_with_ata.rs
  • sdk-libs/program-test/src/utils/simulation.rs
📚 Learning: 2025-11-24T18:01:54.689Z
Learnt from: CR
Repo: Lightprotocol/light-protocol PR: 0
File: programs/compressed-token/program/docs/instructions/CLAUDE.md:0-0
Timestamp: 2025-11-24T18:01:54.689Z
Learning: Applies to programs/compressed-token/program/docs/instructions/instructions/DECOMPRESSED_TRANSFER.md : Decompressed Transfer documentation must cover SPL-compatible transfers between decompressed accounts

Applied to files:

  • programs/compressed-token/program/src/lib.rs
  • programs/compressed-token/program/src/transfer2_with_ata.rs
  • sdk-libs/compressed-token-sdk/src/ctoken/decompress_ata.rs
  • sdk-libs/token-client/src/instructions/transfer2_with_ata.rs
📚 Learning: 2025-11-24T18:00:13.178Z
Learnt from: CR
Repo: Lightprotocol/light-protocol PR: 0
File: program-libs/compressible/docs/CONFIG_ACCOUNT.md:0-0
Timestamp: 2025-11-24T18:00:13.178Z
Learning: Applies to program-libs/compressible/docs/**/*program*.rs : Use zero-copy deserialization with `bytemuck::pod_from_bytes` in program instruction handlers for CompressibleConfig, skipping the 8-byte discriminator

Applied to files:

  • programs/compressed-token/program/src/lib.rs
📚 Learning: 2025-11-24T17:59:23.357Z
Learnt from: CR
Repo: Lightprotocol/light-protocol PR: 0
File: program-libs/account-checks/docs/CLAUDE.md:0-0
Timestamp: 2025-11-24T17:59:23.357Z
Learning: Applies to program-libs/account-checks/docs/src/**/*.rs : Use 8-byte discriminators for account type identification and implement the Discriminator trait for account identification

Applied to files:

  • programs/compressed-token/program/src/lib.rs
📚 Learning: 2025-11-24T18:01:42.343Z
Learnt from: CR
Repo: Lightprotocol/light-protocol PR: 0
File: programs/compressed-token/program/CLAUDE.md:0-0
Timestamp: 2025-11-24T18:01:42.343Z
Learning: Applies to programs/compressed-token/program/src/{claim,withdraw_funding_pool}*.rs : Claim and Withdraw Funding Pool instructions require config validation that allows Not Inactive state (active or deprecated OK)

Applied to files:

  • programs/compressed-token/program/src/lib.rs
📚 Learning: 2025-11-24T17:53:31.428Z
Learnt from: CR
Repo: Lightprotocol/light-protocol PR: 0
File: anchor-programs/system/README.md:0-0
Timestamp: 2025-11-24T17:53:31.428Z
Learning: Maintain consistent bindings with the deployed system program in this anchor wrapper

Applied to files:

  • programs/compressed-token/program/src/lib.rs
📚 Learning: 2025-11-24T18:01:03.786Z
Learnt from: CR
Repo: Lightprotocol/light-protocol PR: 0
File: program-libs/account-checks/CLAUDE.md:0-0
Timestamp: 2025-11-24T18:01:03.786Z
Learning: Applies to program-libs/account-checks/src/account_info/*.rs : Provide PDA derivation functions (`find_program_address`, `create_program_address`) and permission checks in AccountInfoTrait

Applied to files:

  • programs/compressed-token/program/src/lib.rs
📚 Learning: 2025-11-24T17:58:50.237Z
Learnt from: CR
Repo: Lightprotocol/light-protocol PR: 0
File: program-libs/account-checks/docs/ACCOUNT_CHECKS.md:0-0
Timestamp: 2025-11-24T17:58:50.237Z
Learning: Applies to program-libs/account-checks/docs/program-libs/account-checks/src/checks.rs : Implement `check_signer` function to verify account is a transaction signer, returning `InvalidSigner` (20009) error if not

Applied to files:

  • programs/compressed-token/program/src/lib.rs
📚 Learning: 2025-11-24T17:58:50.237Z
Learnt from: CR
Repo: Lightprotocol/light-protocol PR: 0
File: program-libs/account-checks/docs/ACCOUNT_CHECKS.md:0-0
Timestamp: 2025-11-24T17:58:50.237Z
Learning: Applies to program-libs/account-checks/docs/program-libs/account-checks/src/checks.rs : Implement `set_discriminator` function to set 8-byte discriminator on uninitialized account, returning `AlreadyInitialized` (20006) if discriminator is non-zero

Applied to files:

  • programs/compressed-token/program/src/lib.rs
📚 Learning: 2025-11-24T18:01:03.786Z
Learnt from: CR
Repo: Lightprotocol/light-protocol PR: 0
File: program-libs/account-checks/CLAUDE.md:0-0
Timestamp: 2025-11-24T18:01:03.786Z
Learning: Applies to program-libs/account-checks/**/discriminator.rs : Implement Discriminator trait with constant discriminator arrays for compile-time verification and 8-byte account type prefixes

Applied to files:

  • programs/compressed-token/program/src/lib.rs
📚 Learning: 2025-11-24T17:58:50.237Z
Learnt from: CR
Repo: Lightprotocol/light-protocol PR: 0
File: program-libs/account-checks/docs/ACCOUNT_CHECKS.md:0-0
Timestamp: 2025-11-24T17:58:50.237Z
Learning: Applies to program-libs/account-checks/docs/program-libs/account-checks/src/checks.rs : Implement `account_info_init` function to initialize account with discriminator, handling `BorrowAccountDataFailed` (20003) and `AlreadyInitialized` (20006) errors

Applied to files:

  • programs/compressed-token/program/src/lib.rs
📚 Learning: 2025-11-24T17:59:36.701Z
Learnt from: CR
Repo: Lightprotocol/light-protocol PR: 0
File: program-libs/account-checks/docs/DISCRIMINATOR.md:0-0
Timestamp: 2025-11-24T17:59:36.701Z
Learning: Applies to program-libs/account-checks/docs/**/account-checks/**/*.rs : Implement the Discriminator trait for account types, providing 8-byte LIGHT_DISCRIMINATOR constant and LIGHT_DISCRIMINATOR_SLICE reference in Rust account structures

Applied to files:

  • programs/compressed-token/program/src/lib.rs
📚 Learning: 2025-11-24T18:01:03.786Z
Learnt from: CR
Repo: Lightprotocol/light-protocol PR: 0
File: program-libs/account-checks/CLAUDE.md:0-0
Timestamp: 2025-11-24T18:01:03.786Z
Learning: Applies to program-libs/account-checks/**/{checks,discriminator}.rs : Implement discriminator validation functions (`check_discriminator`, `set_discriminator`) for account type identification

Applied to files:

  • programs/compressed-token/program/src/lib.rs
📚 Learning: 2025-11-24T17:58:50.237Z
Learnt from: CR
Repo: Lightprotocol/light-protocol PR: 0
File: program-libs/account-checks/docs/ACCOUNT_CHECKS.md:0-0
Timestamp: 2025-11-24T17:58:50.237Z
Learning: Applies to program-libs/account-checks/docs/program-libs/account-checks/src/checks.rs : Implement `check_discriminator` function to verify first 8 bytes match expected discriminator for type T, returning `InvalidAccountSize` (20004) if < 8 bytes or `InvalidDiscriminator` (20000) if mismatch

Applied to files:

  • programs/compressed-token/program/src/lib.rs
📚 Learning: 2025-11-24T18:01:03.786Z
Learnt from: CR
Repo: Lightprotocol/light-protocol PR: 0
File: program-libs/account-checks/CLAUDE.md:0-0
Timestamp: 2025-11-24T18:01:03.786Z
Learning: Applies to program-libs/account-checks/**/discriminator.rs : Integrate Discriminator trait with zero-copy deserialization for account data parsing

Applied to files:

  • programs/compressed-token/program/src/lib.rs
📚 Learning: 2025-11-24T17:58:50.237Z
Learnt from: CR
Repo: Lightprotocol/light-protocol PR: 0
File: program-libs/account-checks/docs/ACCOUNT_CHECKS.md:0-0
Timestamp: 2025-11-24T17:58:50.237Z
Learning: Applies to program-libs/account-checks/docs/program-libs/account-checks/src/checks.rs : Implement `check_account_info` function to validate account ownership by program_id and verify discriminator matches type T

Applied to files:

  • programs/compressed-token/program/src/lib.rs
📚 Learning: 2025-11-24T17:59:36.701Z
Learnt from: CR
Repo: Lightprotocol/light-protocol PR: 0
File: program-libs/account-checks/docs/DISCRIMINATOR.md:0-0
Timestamp: 2025-11-24T17:59:36.701Z
Learning: Applies to program-libs/account-checks/docs/**/account-checks/**/*.rs : Call account_info_init<T> or set_discriminator<T> during account initialization to write discriminator to account data

Applied to files:

  • programs/compressed-token/program/src/lib.rs
📚 Learning: 2025-11-24T17:55:17.323Z
Learnt from: CR
Repo: Lightprotocol/light-protocol PR: 0
File: sdk-libs/macros/src/compressible/README.md:0-0
Timestamp: 2025-11-24T17:55:17.323Z
Learning: Applies to sdk-libs/macros/src/compressible/**/variant_enum.rs : Account variant enum (`CompressedAccountVariant`) generation and `CompressedAccountData` wrapper struct should be implemented in `variant_enum.rs`

Applied to files:

  • sdk-libs/compressed-token-types/src/constants.rs
📚 Learning: 2025-11-24T17:56:20.711Z
Learnt from: CR
Repo: Lightprotocol/light-protocol PR: 0
File: program-libs/batched-merkle-tree/docs/INITIALIZE_ADDRESS_TREE.md:0-0
Timestamp: 2025-11-24T17:56:20.711Z
Learning: Applies to program-libs/batched-merkle-tree/docs/src/initialize_address_tree.rs : Set discriminator to `BatchMta` `[66, 97, 116, 99, 104, 77, 116, 97]` (8 bytes) for BatchedMerkleTreeAccount in `src/initialize_address_tree.rs`.

Applied to files:

  • sdk-libs/compressed-token-types/src/constants.rs
📚 Learning: 2025-11-24T17:57:39.230Z
Learnt from: CR
Repo: Lightprotocol/light-protocol PR: 0
File: program-libs/batched-merkle-tree/docs/QUEUE_ACCOUNT.md:0-0
Timestamp: 2025-11-24T17:57:39.230Z
Learning: Applies to program-libs/batched-merkle-tree/docs/src/queue.rs : Validate account ownership by Light account compression program using `check_owner` from `light-account-checks` when deserializing `BatchedQueueAccount` with `output_from_account_info`

Applied to files:

  • programs/compressed-token/program/src/transfer2_with_ata.rs
📚 Learning: 2025-11-24T17:55:32.059Z
Learnt from: CR
Repo: Lightprotocol/light-protocol PR: 0
File: sdk-tests/sdk-ctoken-test/README.md:0-0
Timestamp: 2025-11-24T17:55:32.059Z
Learning: Applies to sdk-tests/sdk-ctoken-test/**/*.rs : Use `invoke()` method for CPI calls where the program acts as authority without PDA signing

Applied to files:

  • programs/compressed-token/program/src/transfer2_with_ata.rs
  • sdk-libs/program-test/src/utils/simulation.rs
📚 Learning: 2025-11-24T18:01:03.786Z
Learnt from: CR
Repo: Lightprotocol/light-protocol PR: 0
File: program-libs/account-checks/CLAUDE.md:0-0
Timestamp: 2025-11-24T18:01:03.786Z
Learning: Applies to program-libs/account-checks/**/error.rs : Map AccountError variants (codes 12006-12021) to automatic ProgramError conversion for both Solana and Pinocchio SDKs

Applied to files:

  • programs/compressed-token/program/src/transfer2_with_ata.rs
📚 Learning: 2025-11-24T17:54:33.614Z
Learnt from: CR
Repo: Lightprotocol/light-protocol PR: 0
File: programs/compressed-token/anchor/README.md:0-0
Timestamp: 2025-11-24T17:54:33.614Z
Learning: Implement the Compressed Token Program interface for creating and using compressed tokens on Solana with ZK Compression

Applied to files:

  • sdk-libs/compressed-token-sdk/src/ctoken/decompress_ata.rs
  • sdk-libs/token-client/src/instructions/transfer2_with_ata.rs
📚 Learning: 2025-11-24T18:01:54.689Z
Learnt from: CR
Repo: Lightprotocol/light-protocol PR: 0
File: programs/compressed-token/program/docs/instructions/CLAUDE.md:0-0
Timestamp: 2025-11-24T18:01:54.689Z
Learning: Applies to programs/compressed-token/program/docs/instructions/instructions/CREATE_TOKEN_ACCOUNT.md : Create Token Account Instructions documentation must cover creation of regular and associated ctoken accounts

Applied to files:

  • sdk-libs/compressed-token-sdk/src/ctoken/create_ata.rs
📚 Learning: 2025-11-24T17:56:20.711Z
Learnt from: CR
Repo: Lightprotocol/light-protocol PR: 0
File: program-libs/batched-merkle-tree/docs/INITIALIZE_ADDRESS_TREE.md:0-0
Timestamp: 2025-11-24T17:56:20.711Z
Learning: Applies to program-libs/batched-merkle-tree/docs/src/initialize_address_tree.rs : `InitAddressTreeAccountsInstructionData` struct in `src/initialize_address_tree.rs` must include: height (u32, default 40), index (u64), root_history_capacity (u32, default 200), input_queue_batch_size (u64, default 15,000), input_queue_zkp_batch_size (u64, default 250), bloom_filter_capacity (u64, default batch_size * 8), bloom_filter_num_iters (u64, default 3 for test/10 for production), program_owner (Option<Pubkey>), forester (Option<Pubkey>), rollover_threshold (Option<u64>, default 95%), network_fee (Option<u64>, default 10,000 lamports), and close_threshold (Option<u64>).

Applied to files:

  • sdk-libs/compressed-token-sdk/src/ctoken/create_ata.rs
📚 Learning: 2025-11-24T18:01:42.343Z
Learnt from: CR
Repo: Lightprotocol/light-protocol PR: 0
File: programs/compressed-token/program/CLAUDE.md:0-0
Timestamp: 2025-11-24T18:01:42.343Z
Learning: Applies to programs/compressed-token/program/docs/ACCOUNTS.md : All account documentation must include: description, discriminator, state layout, serialization example, hashing (for compressed accounts only), derivation (for PDAs only), and associated instructions

Applied to files:

  • sdk-libs/compressed-token-sdk/src/ctoken/create_ata.rs
📚 Learning: 2025-11-24T18:01:14.087Z
Learnt from: CR
Repo: Lightprotocol/light-protocol PR: 0
File: program-libs/compressible/CLAUDE.md:0-0
Timestamp: 2025-11-24T18:01:14.087Z
Learning: CompressibleConfig module provides account configuration and rent management for the Light Registry program

Applied to files:

  • sdk-libs/compressed-token-sdk/src/ctoken/create_ata.rs
📚 Learning: 2025-11-24T18:00:36.663Z
Learnt from: CR
Repo: Lightprotocol/light-protocol PR: 0
File: program-libs/compressible/docs/RENT.md:0-0
Timestamp: 2025-11-24T18:00:36.663Z
Learning: Accounts become compressible when they lack rent for the current epoch plus the next epoch (compressibility window).

Applied to files:

  • sdk-libs/compressed-token-sdk/src/ctoken/create_ata.rs
📚 Learning: 2025-11-24T18:01:42.343Z
Learnt from: CR
Repo: Lightprotocol/light-protocol PR: 0
File: programs/compressed-token/program/CLAUDE.md:0-0
Timestamp: 2025-11-24T18:01:42.343Z
Learning: When working with ctoken accounts having the compressible extension, you must read program-libs/compressible/docs/ documentation including RENT.md, CONFIG_ACCOUNT.md, and SOLANA_RENT.md for rent system understanding

Applied to files:

  • sdk-libs/compressed-token-sdk/src/ctoken/create_ata.rs
📚 Learning: 2025-11-24T17:55:32.059Z
Learnt from: CR
Repo: Lightprotocol/light-protocol PR: 0
File: sdk-tests/sdk-ctoken-test/README.md:0-0
Timestamp: 2025-11-24T17:55:32.059Z
Learning: Applies to sdk-tests/sdk-ctoken-test/**/*.rs : Derive PDAs using `Pubkey::find_program_address()` before using in `invoke_signed()` calls, passing the bump as part of `signer_seeds`

Applied to files:

  • sdk-libs/program-test/src/utils/simulation.rs
📚 Learning: 2025-11-24T17:55:32.059Z
Learnt from: CR
Repo: Lightprotocol/light-protocol PR: 0
File: sdk-tests/sdk-ctoken-test/README.md:0-0
Timestamp: 2025-11-24T17:55:32.059Z
Learning: Applies to sdk-tests/sdk-ctoken-test/**/*.rs : Use `invoke_signed()` method for PPI calls where a PDA is the authority/owner and needs to sign transactions

Applied to files:

  • sdk-libs/program-test/src/utils/simulation.rs
📚 Learning: 2025-11-24T17:59:13.714Z
Learnt from: CR
Repo: Lightprotocol/light-protocol PR: 0
File: program-libs/account-checks/docs/ACCOUNT_ITERATOR.md:0-0
Timestamp: 2025-11-24T17:59:13.714Z
Learning: Applies to program-libs/account-checks/docs/**/*.rs : Use specialized AccountIterator methods (`next_signer`, `next_mut`, `next_signer_mut`, etc.) instead of manually calling `next_account()` followed by separate validation functions

Applied to files:

  • sdk-libs/program-test/src/utils/simulation.rs
📚 Learning: 2025-11-24T18:01:03.786Z
Learnt from: CR
Repo: Lightprotocol/light-protocol PR: 0
File: program-libs/account-checks/CLAUDE.md:0-0
Timestamp: 2025-11-24T18:01:03.786Z
Learning: Applies to program-libs/account-checks/**/account_iterator.rs : Implement convenience methods (`next_signer`, `next_mut`, `next_non_mut`) and optional account handling (`next_option`, `next_option_mut`) in AccountIterator

Applied to files:

  • sdk-libs/program-test/src/utils/simulation.rs
📚 Learning: 2025-11-24T18:01:30.012Z
Learnt from: CR
Repo: Lightprotocol/light-protocol PR: 0
File: program-tests/CLAUDE.md:0-0
Timestamp: 2025-11-24T18:01:30.012Z
Learning: Run batched merkle tree simulation tests using `RUST_LOG=light_prover_client=debug cargo test -p batched-merkle-tree-test -- --test test_simulate_transactions` to enable logging

Applied to files:

  • sdk-libs/program-test/src/utils/simulation.rs
  • sdk-libs/program-test/src/utils/mod.rs
📚 Learning: 2025-11-24T17:55:32.059Z
Learnt from: CR
Repo: Lightprotocol/light-protocol PR: 0
File: sdk-tests/sdk-ctoken-test/README.md:0-0
Timestamp: 2025-11-24T17:55:32.059Z
Learning: Applies to sdk-tests/sdk-ctoken-test/**/Cargo.toml : Use path references in Cargo.toml dependencies pointing to local SDK libraries instead of published crates for development

Applied to files:

  • sdk-libs/program-test/src/utils/mod.rs
📚 Learning: 2025-11-24T18:03:13.950Z
Learnt from: CR
Repo: Lightprotocol/light-protocol PR: 0
File: CLAUDE.md:0-0
Timestamp: 2025-11-24T18:03:13.950Z
Learning: Applies to program-libs/**/*.rs : Unit tests in program-libs must not depend on light-test-utils; any test requiring light-test-utils must be in program-tests

Applied to files:

  • sdk-libs/program-test/src/utils/mod.rs
📚 Learning: 2025-11-24T17:59:03.485Z
Learnt from: CR
Repo: Lightprotocol/light-protocol PR: 0
File: program-libs/account-checks/docs/ACCOUNT_INFO_TRAIT.md:0-0
Timestamp: 2025-11-24T17:59:03.485Z
Learning: Applies to program-libs/account-checks/docs/program-libs/account-checks/src/account_info/test_account_info.rs : Create a test-only AccountInfo mock implementation without external dependencies for unit testing AccountInfoTrait implementations

Applied to files:

  • sdk-libs/program-test/src/utils/mod.rs
📚 Learning: 2025-11-24T18:01:03.786Z
Learnt from: CR
Repo: Lightprotocol/light-protocol PR: 0
File: program-libs/account-checks/CLAUDE.md:0-0
Timestamp: 2025-11-24T18:01:03.786Z
Learning: Applies to program-libs/account-checks/src/account_info/*.rs : Implement AccountInfoTrait for runtime-agnostic account handling with unified data access interface (`try_borrow_data`, `try_borrow_mut_data`)

Applied to files:

  • sdk-libs/program-test/src/utils/mod.rs
📚 Learning: 2025-11-24T17:56:50.011Z
Learnt from: CR
Repo: Lightprotocol/light-protocol PR: 0
File: program-libs/batched-merkle-tree/docs/INITIALIZE_STATE_TREE.md:0-0
Timestamp: 2025-11-24T17:56:50.011Z
Learning: Applies to program-libs/batched-merkle-tree/docs/src/initialize_state_tree.rs : Use `check_account_balance_is_rent_exempt` function from `light-account-checks` to verify rent exemption for both queue_account and merkle_tree_account during initialization

Applied to files:

  • sdk-libs/program-test/src/utils/mod.rs
🧬 Code graph analysis (7)
sdk-libs/compressed-token-sdk/src/ctoken/mod.rs (1)
sdk-libs/compressed-token-sdk/src/ctoken/decompress_ata.rs (1)
  • create_decompress_ata_instruction (43-117)
programs/compressed-token/program/src/create_associated_token_account.rs (1)
sdk-libs/compressed-token-sdk/src/ctoken/compressible.rs (1)
  • compress_to_pubkey (42-45)
programs/compressed-token/program/src/lib.rs (1)
programs/compressed-token/program/src/transfer2_with_ata.rs (1)
  • process_transfer2_with_ata (18-143)
programs/compressed-token/program/src/transfer2_with_ata.rs (2)
program-libs/account-checks/src/checks.rs (1)
  • check_signer (121-126)
programs/compressed-token/program/src/lib.rs (1)
  • from (91-107)
sdk-libs/compressed-token-sdk/src/ctoken/decompress_ata.rs (1)
sdk-libs/compressed-token-sdk/src/ctoken/create_ata.rs (1)
  • derive_ctoken_ata (20-29)
sdk-libs/token-client/src/instructions/transfer2_with_ata.rs (3)
sdk-libs/compressed-token-sdk/src/ctoken/decompress_ata.rs (1)
  • create_decompress_ata_instruction (43-117)
sdk-libs/compressed-token-sdk/src/ctoken/create_ata.rs (1)
  • derive_ctoken_ata (20-29)
sdk-libs/token-client/src/instructions/transfer2.rs (1)
  • create_generic_transfer2_instruction (147-640)
sdk-libs/program-test/src/utils/mod.rs (1)
sdk-libs/program-test/src/utils/simulation.rs (2)
  • simulate_cu (12-18)
  • simulate_cu_multi (24-53)
⏰ Context from checks skipped due to timeout of 900000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (7)
  • GitHub Check: programs (compressed-token-and-e2e, ["cargo-test-sbf -p compressed-token-test --test v1", "cargo-...
  • GitHub Check: programs (system-cpi-test, ["cargo-test-sbf -p system-cpi-test", "cargo test -p light-system-prog...
  • GitHub Check: programs (system-cpi-test-v2-functional-read-only, ["cargo-test-sbf -p system-cpi-v2-test -- func...
  • GitHub Check: programs (system-cpi-test-v2-functional-account-infos, ["cargo-test-sbf -p system-cpi-v2-test -- ...
  • GitHub Check: programs (light-system-program-address, ["cargo-test-sbf -p system-test -- test_with_address", "c...
  • GitHub Check: programs (account-compression-and-registry, ["cargo-test-sbf -p account-compression-test", "cargo...
  • GitHub Check: Forester e2e test

Comment on lines +82 to +88
// Calculate decompress amount
let total_balance: u64 = input
.compressed_token_accounts
.iter()
.map(|acc| acc.token.amount)
.sum();
let decompress_amount = input.decompress_amount.unwrap_or(total_balance);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick | 🔵 Trivial

Consider checked arithmetic for the balance sum.

The .sum() on u64 will panic in debug builds or silently wrap in release builds if overflow occurs. While unlikely with realistic token amounts, defensive code would use checked arithmetic:

     // Calculate decompress amount
-    let total_balance: u64 = input
-        .compressed_token_accounts
-        .iter()
-        .map(|acc| acc.token.amount)
-        .sum();
+    let total_balance: u64 = input
+        .compressed_token_accounts
+        .iter()
+        .try_fold(0u64, |acc, x| acc.checked_add(x.token.amount))
+        .ok_or(TokenSdkError::InvalidAccountData)?;
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
// Calculate decompress amount
let total_balance: u64 = input
.compressed_token_accounts
.iter()
.map(|acc| acc.token.amount)
.sum();
let decompress_amount = input.decompress_amount.unwrap_or(total_balance);
// Calculate decompress amount
let total_balance: u64 = input
.compressed_token_accounts
.iter()
.try_fold(0u64, |acc, x| acc.checked_add(x.token.amount))
.ok_or(TokenSdkError::InvalidAccountData)?;
let decompress_amount = input.decompress_amount.unwrap_or(total_balance);
🤖 Prompt for AI Agents
In sdk-libs/token-client/src/instructions/transfer2_with_ata.rs around lines 82
to 88, replace the direct .sum() over u64 (which can overflow) with a checked
accumulation (e.g., use try_fold or fold with checked_add) that returns an Err
if checked_add returns None; propagate a clear error (custom overflow error or
appropriate ProgramError) instead of allowing panic/wrap. Ensure
decompress_amount logic continues to use
input.decompress_amount.unwrap_or(total_balance) but with total_balance coming
from the checked accumulation.

Copy link
Contributor

@ananas-block ananas-block left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Interesting solution, let's hold off on merging this until we have all audit fixes for the current state merged so that we can split a clean release branch.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants