Anchor Framework

website·Indexed 35 days ago

https://www.anchor-lang.com/

A framework for building Solana programs, providing tools for program structure, account constraints, and IDL generation. It includes the Anchor Version Manager (AVM) and supports features like zero-copy deserialization, Cross Program Invocations (CPIs), and integration with Solana's Token Programs. Documentation covers versions from 0.29.0 through 1.2.0.

Tokens
46K
Snippets
308
Records
405
Agent score
67%

What's inside Anchor

  1. Overview of LiteSVM

    LiteSVM is a lightweight, in-process Solana VM designed for program developers to run and compile tests significantly faster than solana-program-test or solana-test-validator. It is available for Rust, TypeScript/JavaScript, and Python (via the solders library).
  2. Overview of Solana Token Extensions (Token 2022)

    The Token Extensions Program (Token 2022) allows developers to add optional features to token mints and token accounts via extensions. Most extensions must be enabled during the initial account creation and cannot be added later. However, the following extensions are exceptions and can be added after initialization:

    • cpi-guard
    • memo-transfer
    • token-group
    • token-member
    • token-metadata

    Note that some extensions are mutually exclusive; for example, NonTransferable and TransferFeeConfig cannot be used on the same mint or account due to conflicting behaviors.

  3. Overview of Solana program fuzzing with anchor fuzz

    anchor fuzz provides coverage-guided fuzzing for Solana programs via Crucible. It generates random action sequences against a program and checks invariants after each action to identify bugs that standard unit tests might miss. Key features include stateful invariant testing, multi-core parallel fuzzing, crash minimization, and LCOV coverage output.
  4. Overview of Mollusk testing harness

    Mollusk is a lightweight test harness for Solana programs that allows developers to write tests in Rust. It provides a minified Solana Virtual Machine (SVM) environment by provisioning a program execution pipeline directly from lower-level SVM components, bypassing heavy components like AccountsDB or Bank. Because it does not have a built-in account database, users must provide an explicit list of accounts for each test. The environment can be configured by adjusting the compute budget, feature set, or sysvars via the Mollusk struct.
  5. Overview of Zero-Copy Deserialization in Anchor

    Zero-copy deserialization allows Solana programs to read and write account data directly from memory without copying it into a heap-allocated struct. This is critical for accounts larger than 1KB or high-frequency operations where compute units (CU) are limited. While traditional Account<T> is suitable for small accounts (< 1KB) and dynamic structures (Vec, String), AccountLoader<T> is required for large accounts (up to 10MB) and provides approximately a 90% reduction in CU usage for large data sets.
  6. Overview of the Anchor Framework for Solana

    Anchor is a development framework designed for building secure Solana programs (smart contracts). It simplifies the entire lifecycle of Solana development, including writing, testing, deploying, and interacting with programs. The framework is designed to help developers create production-ready applications more quickly while mitigating vulnerabilities through integrated security features.
  7. Understand Solana Token Mint Accounts

    A mint account is a specialized account in Solana's Token and Token Extension Programs that uniquely represents a token on the network. The address of the mint account serves as the token's unique identifier (e.g., the USDC mint address). It stores global metadata including the total supply, decimal precision, and the authorities permitted to mint new tokens or freeze accounts.
  8. Understand Associated Token Accounts (ATAs)

    An Associated Token Account (ATA) is a token account with a deterministic address derived as a PDA using the Associated Token Program. This allows any user's token account for a specific mint to be found without needing to store the address separately.

    The derivation uses the wallet address, the token program ID, and the mint address. The Associated Token Program acts as a helper that CPIs into the Token or Token Extension Program to create the actual account.

    pub fn get_associated_token_address_and_bump_seed_internal(
        wallet_address: &Pubkey,
        token_mint_address: &Pubkey,
        program_id: &Pubkey,
        token_program_id: &Pubkey,
    ) -> (Pubkey, u8) {
        Pubkey::find_program_address(
            &[
                &wallet_address.to_bytes(),
                &token_program_id.to_bytes(),
                &token_mint_address.to_bytes(),
            ],
            program_id,
        )
    }
  9. Interact with Anchor programs using the Rust client library

    The anchor-client crate is the official Rust library for interacting with Anchor programs. It allows developers to build program instructions, send transactions, and fetch program accounts. A key feature is the declare_program! macro, which automatically generates dependency-free modules for a program's instructions and accounts based on its IDL (Interface Definition Language) file.
    [dependencies]
    anchor-client = { version = "1.2.0", features = ["async"] }
    anchor-lang = "1.2.0"
  10. Interact with programs using the declare_program! macro

    The declare_program!() macro allows developers to interact with Anchor programs without adding them as Rust dependencies. It generates a set of Rust modules based on the target program's IDL file, which can be used for both on-chain Cross-Program Invocations (CPI) and off-chain client transactions.
  11. Understand Solana Token Program options

    Solana provides two primary token programs for managing assets:

    1. Token Program (Original): Provides basic token functionality such as minting and transferring. It is immutable and widely used.
    2. Token Extension Program (Token 2022): Includes all features of the original Token Program but adds additional functionality via 'extensions'. This is the recommended choice for new tokens.
  12. Specify SBPF architecture and platform-tools version during build

    Starting with Anchor v1.2.0, you can use the --arch and --tools-version flags with the anchor build command to select a specific SBPF architecture and platform-tools version.
    anchor build --arch <architecture> --tools-version <version>