feat: add max top up to compressible config#2093
Conversation
|
Important Review skippedReview was skipped due to path filters ⛔ Files ignored due to path filters (1)
CodeRabbit blocks several paths by default. You can override this behavior by explicitly including those paths in the path filters. For example, including You can disable this status message by setting the WalkthroughAdds a configurable per-operation top-up cap ( Changes
Sequence Diagram(s)sequenceDiagram
participant Client
participant InstructionParser
participant Processor
participant CompressionLayer
participant RentModule
participant SystemProgram
Client->>InstructionParser: send transfer2/mint instruction (optional max_top_up)
InstructionParser->>Processor: parse amount, max_top_up
Processor->>CompressionLayer: process_token_compression(inputs, max_top_up)
CompressionLayer->>CompressionLayer: init lamports_budget = max_top_up + 1
CompressionLayer->>CompressionLayer: iterate accounts -> compress_or_decompress_ctokens(..., lamports_budget)
CompressionLayer->>RentModule: calculate_top_up_lamports(account_state)
RentModule-->>CompressionLayer: transfer_amount (may include rent deficit)
CompressionLayer->>CompressionLayer: lamports_budget -= transfer_amount
alt budget exhausted and max_top_up != 0
CompressionLayer-->>Processor: return MaxTopUpExceeded
else budget ok
CompressionLayer->>SystemProgram: request lamports transfer (payer)
SystemProgram-->>Processor: transfer result
end
Processor-->>Client: final status
Estimated code review effort🎯 4 (Complex) | ⏱️ ~45 minutes
Possibly related PRs
Suggested labels
Suggested reviewers
Poem
Pre-merge checks and finishing touches✅ Passed checks (3 passed)
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. Comment |
018d5ce to
ab565a8
Compare
There was a problem hiding this comment.
Actionable comments posted: 1
📜 Review details
Configuration used: Path: .coderabbit.yaml
Review profile: ASSERTIVE
Plan: Pro
⛔ Files ignored due to path filters (2)
program-tests/compressed-token-test/tests/ctoken/create.rsis excluded by none and included by noneprogram-tests/compressed-token-test/tests/ctoken/create_ata.rsis excluded by none and included by none
📒 Files selected for processing (4)
program-libs/compressible/src/rent/config.rs(7 hunks)program-libs/ctoken-types/src/error.rs(2 hunks)program-libs/ctoken-types/tests/ctoken/spl_compat.rs(1 hunks)programs/compressed-token/program/src/shared/initialize_ctoken_account.rs(2 hunks)
🧰 Additional context used
📓 Path-based instructions (5)
program-libs/**/*.rs
📄 CodeRabbit inference engine (CLAUDE.md)
Unit tests in program-libs must not depend on light-test-utils; any test requiring light-test-utils must be in program-tests
Files:
program-libs/ctoken-types/src/error.rsprogram-libs/ctoken-types/tests/ctoken/spl_compat.rsprogram-libs/compressible/src/rent/config.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/shared/initialize_ctoken_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/shared/initialize_ctoken_account.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/shared/initialize_ctoken_account.rs
program-libs/compressible/**/*.rs
📄 CodeRabbit inference engine (program-libs/compressible/CLAUDE.md)
program-libs/compressible/**/*.rs: Use Anchor serialization for CompressibleConfig account structures in Rust programs
Implement state validation methods (validate_active,validate_not_inactive) for CompressibleConfig account state verification
Derive PDA addresses usingderive_pdaandderive_v1_config_pdafunctions for CToken account configuration
Use rent curve algorithms (rent_curve_per_epoch) from RentConfig for calculating compressibility thresholds
Calculate claimable rent usingclaimable_lamportsfunction before closing CToken accounts
Error types must use numeric codes in the 19xxx range for rent/config module errors
Support multiple serialization formats (Anchor, Pinocchio, Borsh) for cross-program compatibility
Usecalculate_rent_and_balancefunction to determine if a CToken account is compressible
Usecalculate_close_lamportsfunction to determine lamport distribution when closing CToken accounts
Files:
program-libs/compressible/src/rent/config.rs
🧠 Learnings (52)
📓 Common learnings
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
Learnt from: CR
Repo: Lightprotocol/light-protocol PR: 0
File: program-libs/compressible/docs/SOLANA_RENT.md:0-0
Timestamp: 2025-11-24T18:00:48.449Z
Learning: Applies to program-libs/compressible/docs/**/*.rs : Light Protocol accounts must satisfy both Solana rent exemption and Light Protocol rent requirements, plus an 11,000 lamport compression incentive during creation
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 : Return error `AccountError::AccountNotRentExempt` (error code 12011) when account balance is insufficient for rent exemption at calculated size
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-libs/compressible/src/config.rs : RentConfig struct must use fixed-size fields: base_rent (u16, 2 bytes), compression_cost (u16, 2 bytes), lamports_per_byte_per_epoch (u8, 1 byte), and _place_holder_bytes ([u8; 3], 3 bytes padding) for proper 8-byte alignment
📚 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:
program-libs/ctoken-types/src/error.rs
📚 Learning: 2025-11-24T17:59:46.693Z
Learnt from: CR
Repo: Lightprotocol/light-protocol PR: 0
File: program-libs/account-checks/docs/ERRORS.md:0-0
Timestamp: 2025-11-24T17:59:46.693Z
Learning: Applies to program-libs/account-checks/docs/program-libs/account-checks/src/error.rs : Use error code range 20000-20015 for AccountError variants
Applied to files:
program-libs/ctoken-types/src/error.rs
📚 Learning: 2025-11-24T17:59:46.693Z
Learnt from: CR
Repo: Lightprotocol/light-protocol PR: 0
File: program-libs/account-checks/docs/ERRORS.md:0-0
Timestamp: 2025-11-24T17:59:46.693Z
Learning: Applies to program-libs/account-checks/docs/program-libs/account-checks/src/error.rs : All AccountError variants must convert automatically to `ProgramError::Custom(u32)` for both solana-program and pinocchio SDKs using From trait implementations
Applied to files:
program-libs/ctoken-types/src/error.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:
program-libs/ctoken-types/src/error.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/**/*.rs : Error handling must use BatchedMerkleTreeError enum from errors.rs with u32 error codes in the 14301-14312 range
Applied to files:
program-libs/ctoken-types/src/error.rs
📚 Learning: 2025-11-24T17:59:54.233Z
Learnt from: CR
Repo: Lightprotocol/light-protocol PR: 0
File: program-libs/account-checks/docs/PACKED_ACCOUNTS.md:0-0
Timestamp: 2025-11-24T17:59:54.233Z
Learning: Applies to program-libs/account-checks/docs/program-libs/account-checks/src/**/*.rs : Provide descriptive names in ProgramPackedAccounts error messages (e.g., 'token_mint' instead of 'account')
Applied to files:
program-libs/ctoken-types/src/error.rsprograms/compressed-token/program/src/shared/initialize_ctoken_account.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 numeric error codes in the 12006-12021 range for account check errors
Applied to files:
program-libs/ctoken-types/src/error.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 : Error types must use numeric codes in the 19xxx range for rent/config module errors
Applied to files:
program-libs/ctoken-types/src/error.rsprogram-libs/ctoken-types/tests/ctoken/spl_compat.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: Error type conversions should support multiple framework targets: Solana (default) converts to `solana_program_error::ProgramError`, Anchor converts to `anchor_lang::prelude::ProgramError`, and Pinocchio converts to `pinocchio::program_error::ProgramError`. All conversions must preserve the numeric error code for consistent error tracking.
Applied to files:
program-libs/ctoken-types/src/error.rs
📚 Learning: 2025-11-24T17:59:46.693Z
Learnt from: CR
Repo: Lightprotocol/light-protocol PR: 0
File: program-libs/account-checks/docs/ERRORS.md:0-0
Timestamp: 2025-11-24T17:59:46.693Z
Learning: Applies to program-libs/account-checks/docs/program-libs/account-checks/src/error.rs : Map Pinocchio standard ProgramError variants (InvalidArgument, InvalidInstructionData, InvalidAccountData, AccountDataTooSmall, InsufficientFunds, IncorrectProgramId, MissingRequiredSignature, AccountAlreadyInitialized, UninitializedAccount, NotEnoughAccountKeys, AccountBorrowFailed) to AccountError::PinocchioProgramError with codes 1-11
Applied to files:
program-libs/ctoken-types/src/error.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/*.rs : AccountInfoTrait implementations must return `AccountError` from all fallible operations: `BorrowAccountDataFailed` (12009) for borrow failures, `InvalidSeeds` (12016) for PDA creation, and `FailedBorrowRentSysvar` (12014) for rent access
Applied to files:
program-libs/ctoken-types/src/error.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 : Return error `AccountError::AccountNotRentExempt` (error code 12011) when account balance is insufficient for rent exemption at calculated size
Applied to files:
program-libs/ctoken-types/src/error.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: HasherError conversions: Automatic conversion from `light_hasher::HasherError` (7xxx error codes) is supported. Refer to the light-hasher crate documentation for specific hasher error details.
Applied to files:
program-libs/ctoken-types/src/error.rs
📚 Learning: 2025-11-24T17:59:46.693Z
Learnt from: CR
Repo: Lightprotocol/light-protocol PR: 0
File: program-libs/account-checks/docs/ERRORS.md:0-0
Timestamp: 2025-11-24T17:59:46.693Z
Learning: Applies to program-libs/account-checks/docs/program-libs/account-checks/src/error.rs : Implement From<std::cell::BorrowError> and From<std::cell::BorrowMutError> to convert to AccountError::BorrowAccountDataFailed when using solana-program SDK
Applied to files:
program-libs/ctoken-types/src/error.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 : Return error `AccountError::InvalidAccountSize` (error code 12006) when account data length doesn't match calculated size requirements
Applied to files:
program-libs/ctoken-types/src/error.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 : Verify merkle_tree_account data length matches calculated size in `src/initialize_address_tree.rs`. Return error `AccountError::InvalidAccountSize` (error code: 12006) if account data length doesn't match calculated size requirements.
Applied to files:
program-libs/ctoken-types/src/error.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_close_lamports` function to determine lamport distribution when closing CToken accounts
Applied to files:
programs/compressed-token/program/src/shared/initialize_ctoken_account.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/shared/initialize_ctoken_account.rsprogram-libs/ctoken-types/tests/ctoken/spl_compat.rsprogram-libs/compressible/src/rent/config.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/shared/initialize_ctoken_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/{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:
programs/compressed-token/program/src/shared/initialize_ctoken_account.rsprogram-libs/ctoken-types/tests/ctoken/spl_compat.rsprogram-libs/compressible/src/rent/config.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/shared/initialize_ctoken_account.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/shared/initialize_ctoken_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 mint accounts (cmints) support only one extension: TokenMetadata
Applied to files:
programs/compressed-token/program/src/shared/initialize_ctoken_account.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/shared/initialize_ctoken_account.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:
programs/compressed-token/program/src/shared/initialize_ctoken_account.rsprogram-libs/ctoken-types/tests/ctoken/spl_compat.rsprogram-libs/compressible/src/rent/config.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:
programs/compressed-token/program/src/shared/initialize_ctoken_account.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:
programs/compressed-token/program/src/shared/initialize_ctoken_account.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:
programs/compressed-token/program/src/shared/initialize_ctoken_account.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-libs/compressible/src/config.rs : CompressibleConfig struct must use `#[repr(C)]` for proper memory layout with fixed field ordering: version (u16, 2 bytes), state (u8, 1 byte), bump (u8, 1 byte), update_authority (Pubkey, 32 bytes), withdrawal_authority (Pubkey, 32 bytes), rent_sponsor (Pubkey, 32 bytes), compression_authority (Pubkey, 32 bytes), rent_sponsor_bump (u8, 1 byte), compression_authority_bump (u8, 1 byte), rent_config (RentConfig, 8 bytes), address_space ([Pubkey; 4], 128 bytes), and _place_holder ([u8; 32], 32 bytes) for total of 256 bytes
Applied to files:
programs/compressed-token/program/src/shared/initialize_ctoken_account.rsprogram-libs/ctoken-types/tests/ctoken/spl_compat.rsprogram-libs/compressible/src/rent/config.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/shared/initialize_ctoken_account.rsprogram-libs/ctoken-types/tests/ctoken/spl_compat.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:
programs/compressed-token/program/src/shared/initialize_ctoken_account.rsprogram-libs/compressible/src/rent/config.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/shared/initialize_ctoken_account.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-libs/compressible/src/config.rs : RentConfig struct must use fixed-size fields: base_rent (u16, 2 bytes), compression_cost (u16, 2 bytes), lamports_per_byte_per_epoch (u8, 1 byte), and _place_holder_bytes ([u8; 3], 3 bytes padding) for proper 8-byte alignment
Applied to files:
programs/compressed-token/program/src/shared/initialize_ctoken_account.rsprogram-libs/ctoken-types/tests/ctoken/spl_compat.rsprogram-libs/compressible/src/rent/config.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 : Calculate claimable rent using `claimable_lamports` function before closing CToken accounts
Applied to files:
programs/compressed-token/program/src/shared/initialize_ctoken_account.rsprogram-libs/ctoken-types/tests/ctoken/spl_compat.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: Applies to program-libs/compressible/docs/**/*rent*.rs : Implement `calculate_rent_and_balance` function to determine compressibility by checking if account balance covers required rent for epochs since last claim, returning (bool, u64) tuple.
Applied to files:
programs/compressed-token/program/src/shared/initialize_ctoken_account.rsprogram-libs/compressible/src/rent/config.rs
📚 Learning: 2025-11-24T18:00:48.449Z
Learnt from: CR
Repo: Lightprotocol/light-protocol PR: 0
File: program-libs/compressible/docs/SOLANA_RENT.md:0-0
Timestamp: 2025-11-24T18:00:48.449Z
Learning: Applies to program-libs/compressible/docs/**/*.rs : Light Protocol accounts must satisfy both Solana rent exemption and Light Protocol rent requirements, plus an 11,000 lamport compression incentive during creation
Applied to files:
programs/compressed-token/program/src/shared/initialize_ctoken_account.rsprogram-libs/compressible/src/rent/config.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: Applies to program-libs/compressible/docs/**/*rent*.rs : RentConfig struct must be exactly 8 bytes and contain: base_rent (u16), compression_cost (u16), lamports_per_byte_per_epoch (u8), and 3 bytes of padding.
Applied to files:
program-libs/ctoken-types/tests/ctoken/spl_compat.rsprogram-libs/compressible/src/rent/config.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 rent curve algorithms (`rent_curve_per_epoch`) from RentConfig for calculating compressibility thresholds
Applied to files:
program-libs/ctoken-types/tests/ctoken/spl_compat.rsprogram-libs/compressible/src/rent/config.rs
📚 Learning: 2025-11-24T18:00:48.449Z
Learnt from: CR
Repo: Lightprotocol/light-protocol PR: 0
File: program-libs/compressible/docs/SOLANA_RENT.md:0-0
Timestamp: 2025-11-24T18:00:48.449Z
Learning: Applies to program-libs/compressible/docs/**/*.rs : Light Protocol rent is calculated per epoch as: 1220 minimum + (data_bytes * 10) lamports per epoch
Applied to files:
program-libs/ctoken-types/tests/ctoken/spl_compat.rsprogram-libs/compressible/src/rent/config.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 receive COMPRESSION_COST + COMPRESSION_INCENTIVE lamports (11,000 total) when created to cover future compression operations.
Applied to files:
program-libs/ctoken-types/tests/ctoken/spl_compat.rsprogram-libs/compressible/src/rent/config.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: Applies to program-libs/compressible/docs/**/*rent*.rs : Implement rent constants with values: BASE_RENT = 1,220 lamports, RENT_PER_BYTE = 10 lamports, SLOTS_PER_EPOCH = 432,000.
Applied to files:
program-libs/compressible/src/rent/config.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: Applies to program-libs/compressible/docs/**/*rent*.rs : Implement `rent_curve_per_epoch` function with formula: base_rent + (num_bytes * lamports_per_byte_per_epoch).
Applied to files:
program-libs/compressible/src/rent/config.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: Applies to program-libs/compressible/docs/**/*rent*.rs : Implement `calculate_close_lamports` function to return (u64, u64) tuple splitting lamports between rent recipient and user, with rent recipient receiving completed epochs and user receiving partial epoch remainder.
Applied to files:
program-libs/compressible/src/rent/config.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: Applies to program-libs/compressible/docs/**/*rent*.rs : Implement `get_last_funded_epoch` function to determine the last epoch number covered by rent payments.
Applied to files:
program-libs/compressible/src/rent/config.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: Applies to program-libs/compressible/docs/**/*rent*.rs : Implement `get_rent` function to calculate total rent across multiple epochs using: rent_curve_per_epoch * epochs.
Applied to files:
program-libs/compressible/src/rent/config.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: Use `rent_curve_per_epoch(base_rent, lamports_per_byte_per_epoch, num_bytes)` function for base rent calculations in all rent operations.
Applied to files:
program-libs/compressible/src/rent/config.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-libs/compressible/src/config.rs : Define CompressibleConfig constant `LEN = 256` to represent the account size in bytes for rent calculation and account creation
Applied to files:
program-libs/compressible/src/rent/config.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: Applies to program-libs/compressible/docs/**/*rent*.rs : Implement compression cost and incentive values as constants: COMPRESSION_COST = 10,000 lamports, COMPRESSION_INCENTIVE = 1,000 lamports.
Applied to files:
program-libs/compressible/src/rent/config.rs
📚 Learning: 2025-11-24T17:54:20.982Z
Learnt from: CR
Repo: Lightprotocol/light-protocol PR: 0
File: program-libs/zero-copy-derive/README.md:0-0
Timestamp: 2025-11-24T17:54:20.982Z
Learning: Applies to program-libs/zero-copy-derive/**/*.rs : Option<u64>, Option<u32>, and Option<u16> are optimized in zero-copy structs; other Option<T> types delegate to T's ZeroCopyAt implementation
Applied to files:
program-libs/compressible/src/rent/config.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 : Derive CompressibleConfig PDA using seeds `[b"compressible_config", version.to_le_bytes()]` with version parameter to support multiple config versions
Applied to files:
program-libs/compressible/src/rent/config.rs
📚 Learning: 2025-11-24T18:00:48.449Z
Learnt from: CR
Repo: Lightprotocol/light-protocol PR: 0
File: program-libs/compressible/docs/SOLANA_RENT.md:0-0
Timestamp: 2025-11-24T18:00:48.449Z
Learning: Applies to program-libs/compressible/docs/**/*.rs : Implement account compressibility states in the following order: Funded (rent for current + 1 epoch) → Compressible (lacks rent for current + 1 epoch) → Claimable (funded but past epochs unclaimed)
Applied to files:
program-libs/compressible/src/rent/config.rs
⏰ 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). (9)
- GitHub Check: system-programs (native, ["cargo-test-sbf -p sdk-native-test", "cargo-test-sbf -p sdk-v1-native-t...
- GitHub Check: system-programs (anchor & pinocchio, ["cargo-test-sbf -p sdk-anchor-test", "cargo-test-sbf -p sdk...
- 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: Test program-libs-fast
- GitHub Check: Test batched-merkle-tree-simulate
- GitHub Check: Test program-libs-slow
- GitHub Check: stateless-js-v2
🔇 Additional comments (11)
program-libs/ctoken-types/src/error.rs (2)
132-134: LGTM! New error variant is well-placed.The
WriteTopUpExceedsMaximumvariant follows the established pattern, with a clear error message that references bothwrite_top_upandmax_top_upfromRentConfig. The error code 18042 correctly continues the sequential CTokenError numbering.
181-181: Error code assignment is correct.Code 18042 properly follows the sequence after
TooManySeeds(18041). The CTokenError range (18xxx) is appropriate since this is a token-level validation error, distinct from rent/config module errors which use the 19xxx range per coding guidelines.programs/compressed-token/program/src/shared/initialize_ctoken_account.rs (1)
4-7: Import addition is appropriate.
CTokenErroris correctly imported to support the newWriteTopUpExceedsMaximumvariant usage in the validation logic.program-libs/ctoken-types/tests/ctoken/spl_compat.rs (1)
538-544: Test correctly reflects the RentConfig field change.The
max_top_up: 0value aligns with all other zeroedrent_configfields in this test, maintaining the consistency needed forPartialEqverification betweenZCTokenandCToken. Sincemax_top_up(u16) replaces the removed_paddingfield (also previously 2 bytes), the serialized layout remains compatible.program-libs/compressible/src/rent/config.rs (7)
32-34: Trait method addition is well-designed.The
max_top_up()method follows the established pattern of the other trait methods—clear documentation and consistentu64return type that allows for uniform usage across rent calculations.
78-81: Struct field maintains proper alignment and provides clear documentation.The
max_top_up: u16field correctly replaces the removed_padding: [u8; 2], preserving the 8-byte struct size required per coding guidelines. The documentation clearly explains the anti-griefing purpose—this is helpful context for future maintainers.
90-91: Default value calculation is correct.The comment documents that 12416 represents 48h rent for 260-byte ctoken accounts. Let me verify: with
SLOTS_PER_EPOCH = 13500(1.5h epochs), 48h spans 32 epochs. Per-epoch rent =base_rent + num_bytes * lamports_per_byte_per_epoch= 128 + 260 × 1 = 388 lamports. Total: 32 × 388 = 12,416 ✓This default provides reasonable protection against excessive top-ups while allowing sufficient buffer for normal operations.
115-120: Trait implementation for RentConfig is correct.The
max_top_up()accessor follows the identical pattern as other field accessors—as u64cast for the ownedRentConfigtype.
155-160: Zero-copy immutable implementation is correct.Uses
.into()for conversion from the zero-copyu16wrapper, consistent withbase_rentandcompression_costaccessors in this impl block.
183-188: Zero-copy mutable implementation is correct.Mirrors the immutable implementation exactly, as expected.
197-198: Setter correctly propagates max_top_up.The
.into()conversion is consistent with howbase_rentandcompression_costare handled in this method. This properly replaces the previous_paddingassignment.
programs/compressed-token/program/src/shared/initialize_ctoken_account.rs
Show resolved
Hide resolved
There was a problem hiding this comment.
Actionable comments posted: 3
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (4)
programs/compressed-token/program/src/transfer2/processor.rs (1)
111-143: Propagatingmax_top_upintoprocess_token_compressionlooks correct; ensure behavior is covered by testsThreading
inputs.max_top_up.get()intoprocess_token_compressionin both the “no system CPI” and “with system CPI” paths is consistent with the new instruction field and the budget/top‑up semantics described in the PR.I’d recommend adding/confirming tests that:
- Use a non‑zero
max_top_upand verify a successful transfer where total rent deficit + top‑ups ≤ cap.- Exercise the failure path where the new logic returns
CTokenError::MaxTopUpExceeded, so we know both branches are wired correctly end‑to‑end through this processor.Also applies to: 205-213
programs/registry/src/compressible/compressed_token/compress_and_close.rs (1)
124-140: Defaultingmax_top_upto 0 preserves existing CompressAndClose behaviorSetting
max_top_up: 0here keeps the registry helper’s semantics unchanged (no additional lamport budget cap applied to these compress‑and‑close flows), while making the instruction structurally compatible with the new field.If you later want registry‑level grief‑protection, this value can be threaded as a parameter, but that’s not required for this PR.
program-libs/ctoken-types/src/instructions/transfer2/instruction_data.rs (1)
9-35: Confirm that au16cap formax_top_upis intentional and documentedThe new
max_top_up: u16field and its “0 = no limit” semantics fit with the rest of the rent/top‑up configuration story and are wired through the processor correctly.Given that lamports themselves are
u64, usingu16here hard‑caps the combined rent + top‑up budget at 65,535 lamports per instruction. That’s likely fine given your existingRentConfigfield sizes, but it’s worth double‑checking:
- If you ever expect larger per‑instruction budgets (e.g., heavy rent deficits on big accounts), consider promoting this to
u32/u64.- If
u16is intentional, I’d call out the 65,535‑lamport upper bound explicitly in docs so users know the envelope.programs/compressed-token/program/src/shared/initialize_ctoken_account.rs (1)
1-7: Propagatemax_top_upto extension's rent_config for consistencyThe validation check at line 157 correctly enforces the
max_top_upcap before settinglamports_per_write. Thewrite_top_up(u32) vsmax_top_up(u16) cast is necessary and correct.However, after validation passes,
max_top_upis not copied tocompressible_extension.rent_config. The code currently copiesbase_rent,compression_cost,lamports_per_byte_per_epoch, andmax_funded_epochsfrom the config account (lines 129–141), but omitsmax_top_up. Sincerent_configfields are read from the extension at runtime (e.g., in close operations), this field should be included for consistency:compressible_extension.rent_config.max_top_up = compressible_config_account.rent_config.max_top_up;Alternatively, use the existing
ZRentConfigMut::set()method to copy all fields at once:compressible_extension.rent_config.set(&compressible_config_account.rent_config);
Changes:
CompressionConfigaccountCompressionConfiglamport_budgetparameter to instruction data ofctoken_transfer,mint_action,transfer2. If the sum of rent deficit and or top ups payable exceed thelamport_budgetthe instruction fails.Summary by CodeRabbit
New Features
Bug Fixes / Validation
✏️ Tip: You can customize this high-level summary in your review settings.