From b4f661f4d3f46c5cb7283a906c93bb293f885b89 Mon Sep 17 00:00:00 2001 From: tilo-14 Date: Thu, 29 Jan 2026 23:07:46 +0000 Subject: [PATCH 01/10] Add escrow, fundraiser, AMM, and minter with SPL/T22/Light interop - Escrow: peer-to-peer token swap (make_offer, take_offer) - Fundraiser: time-gated fundraising with refunds - Token-swap: constant-product AMM with liquidity pools - Light-token-minter: create light-mints with metadata - All programs tested across 5 token configs (SPL, T22, Light, LightSpl, LightT22) - CI aligned with upstream Photon indexer rev --- .github/actions/setup/action.yml | 49 +- .github/workflows/rust-tests.yml | 44 + .github/workflows/typescript-tests.yml | 48 +- .gitignore | 22 +- README.md | 2 +- programs/anchor/Anchor.toml | 30 + programs/anchor/Cargo.lock | 9056 +++++++++++++++++ programs/anchor/Cargo.toml | 70 + programs/anchor/README.md | 60 + programs/anchor/escrow/Cargo.toml | 54 + programs/anchor/escrow/src/constants.rs | 4 + .../escrow/src/instructions/make_offer.rs | 148 + .../anchor/escrow/src/instructions/mod.rs | 7 + .../anchor/escrow/src/instructions/shared.rs | 86 + .../escrow/src/instructions/take_offer.rs | 178 + programs/anchor/escrow/src/lib.rs | 37 + programs/anchor/escrow/src/state/mod.rs | 3 + programs/anchor/escrow/src/state/offer.rs | 15 + programs/anchor/escrow/tests/common/mod.rs | 658 ++ programs/anchor/escrow/tests/escrow_light.rs | 17 + programs/anchor/escrow/tests/escrow_spl.rs | 17 + .../anchor/escrow/tests/escrow_spl_light.rs | 19 + programs/anchor/escrow/tests/escrow_t22.rs | 17 + .../anchor/escrow/tests/escrow_t22_light.rs | 19 + programs/anchor/fundraiser/Cargo.toml | 52 + programs/anchor/fundraiser/Xargo.toml | 2 + programs/anchor/fundraiser/src/constants.rs | 6 + programs/anchor/fundraiser/src/error.rs | 21 + .../fundraiser/src/instructions/checker.rs | 108 + .../fundraiser/src/instructions/contribute.rs | 124 + .../fundraiser/src/instructions/initialize.rs | 89 + .../anchor/fundraiser/src/instructions/mod.rs | 11 + .../fundraiser/src/instructions/refund.rs | 124 + .../fundraiser/src/instructions/shared.rs | 86 + programs/anchor/fundraiser/src/lib.rs | 43 + .../fundraiser/src/state/contributor.rs | 7 + .../anchor/fundraiser/src/state/fundraiser.rs | 13 + programs/anchor/fundraiser/src/state/mod.rs | 5 + .../anchor/fundraiser/tests/common/mod.rs | 634 ++ .../anchor/fundraiser/tests/user_light.rs | 48 + programs/anchor/fundraiser/tests/user_spl.rs | 46 + .../anchor/fundraiser/tests/user_spl_light.rs | 24 + programs/anchor/fundraiser/tests/user_t22.rs | 46 + .../anchor/fundraiser/tests/user_t22_light.rs | 24 + programs/anchor/light-token-minter/Cargo.toml | 52 + .../src/instructions/create.rs | 79 + .../src/instructions/mint.rs | 78 + .../src/instructions/mod.rs | 5 + programs/anchor/light-token-minter/src/lib.rs | 35 + .../light-token-minter/tests/minter_test.rs | 386 + programs/anchor/rust-toolchain.toml | 3 + programs/anchor/shared-test-utils/Cargo.toml | 44 + programs/anchor/shared-test-utils/src/lib.rs | 815 ++ programs/anchor/token-swap/Cargo.toml | 55 + programs/anchor/token-swap/Xargo.toml | 2 + programs/anchor/token-swap/src/constants.rs | 19 + programs/anchor/token-swap/src/errors.rs | 25 + .../token-swap/src/instructions/create_amm.rs | 36 + .../src/instructions/create_pool.rs | 135 + .../src/instructions/create_pool_light_lp.rs | 179 + .../src/instructions/deposit_liquidity.rs | 278 + .../anchor/token-swap/src/instructions/mod.rs | 15 + .../token-swap/src/instructions/shared.rs | 81 + .../swap_exact_tokens_for_tokens.rs | 285 + .../src/instructions/withdraw_liquidity.rs | 241 + programs/anchor/token-swap/src/lib.rs | 64 + programs/anchor/token-swap/src/state.rs | 28 + .../anchor/token-swap/tests/common/mod.rs | 1157 +++ .../anchor/token-swap/tests/user_light.rs | 31 + .../token-swap/tests/user_light_full.rs | 33 + programs/anchor/token-swap/tests/user_spl.rs | 31 + .../anchor/token-swap/tests/user_spl_light.rs | 25 + programs/anchor/token-swap/tests/user_t22.rs | 31 + .../anchor/token-swap/tests/user_t22_light.rs | 25 + toolkits/payments-and-wallets/README.md | 2 +- toolkits/streaming-tokens/README.mdx | 2 +- typescript-client/README.md | 2 +- 77 files changed, 16394 insertions(+), 58 deletions(-) create mode 100644 .github/workflows/rust-tests.yml create mode 100644 programs/anchor/Anchor.toml create mode 100644 programs/anchor/Cargo.lock create mode 100644 programs/anchor/Cargo.toml create mode 100644 programs/anchor/README.md create mode 100644 programs/anchor/escrow/Cargo.toml create mode 100644 programs/anchor/escrow/src/constants.rs create mode 100644 programs/anchor/escrow/src/instructions/make_offer.rs create mode 100644 programs/anchor/escrow/src/instructions/mod.rs create mode 100644 programs/anchor/escrow/src/instructions/shared.rs create mode 100644 programs/anchor/escrow/src/instructions/take_offer.rs create mode 100644 programs/anchor/escrow/src/lib.rs create mode 100644 programs/anchor/escrow/src/state/mod.rs create mode 100644 programs/anchor/escrow/src/state/offer.rs create mode 100644 programs/anchor/escrow/tests/common/mod.rs create mode 100644 programs/anchor/escrow/tests/escrow_light.rs create mode 100644 programs/anchor/escrow/tests/escrow_spl.rs create mode 100644 programs/anchor/escrow/tests/escrow_spl_light.rs create mode 100644 programs/anchor/escrow/tests/escrow_t22.rs create mode 100644 programs/anchor/escrow/tests/escrow_t22_light.rs create mode 100644 programs/anchor/fundraiser/Cargo.toml create mode 100644 programs/anchor/fundraiser/Xargo.toml create mode 100644 programs/anchor/fundraiser/src/constants.rs create mode 100644 programs/anchor/fundraiser/src/error.rs create mode 100644 programs/anchor/fundraiser/src/instructions/checker.rs create mode 100644 programs/anchor/fundraiser/src/instructions/contribute.rs create mode 100644 programs/anchor/fundraiser/src/instructions/initialize.rs create mode 100644 programs/anchor/fundraiser/src/instructions/mod.rs create mode 100644 programs/anchor/fundraiser/src/instructions/refund.rs create mode 100644 programs/anchor/fundraiser/src/instructions/shared.rs create mode 100644 programs/anchor/fundraiser/src/lib.rs create mode 100644 programs/anchor/fundraiser/src/state/contributor.rs create mode 100644 programs/anchor/fundraiser/src/state/fundraiser.rs create mode 100644 programs/anchor/fundraiser/src/state/mod.rs create mode 100644 programs/anchor/fundraiser/tests/common/mod.rs create mode 100644 programs/anchor/fundraiser/tests/user_light.rs create mode 100644 programs/anchor/fundraiser/tests/user_spl.rs create mode 100644 programs/anchor/fundraiser/tests/user_spl_light.rs create mode 100644 programs/anchor/fundraiser/tests/user_t22.rs create mode 100644 programs/anchor/fundraiser/tests/user_t22_light.rs create mode 100644 programs/anchor/light-token-minter/Cargo.toml create mode 100644 programs/anchor/light-token-minter/src/instructions/create.rs create mode 100644 programs/anchor/light-token-minter/src/instructions/mint.rs create mode 100644 programs/anchor/light-token-minter/src/instructions/mod.rs create mode 100644 programs/anchor/light-token-minter/src/lib.rs create mode 100644 programs/anchor/light-token-minter/tests/minter_test.rs create mode 100644 programs/anchor/rust-toolchain.toml create mode 100644 programs/anchor/shared-test-utils/Cargo.toml create mode 100644 programs/anchor/shared-test-utils/src/lib.rs create mode 100644 programs/anchor/token-swap/Cargo.toml create mode 100644 programs/anchor/token-swap/Xargo.toml create mode 100644 programs/anchor/token-swap/src/constants.rs create mode 100644 programs/anchor/token-swap/src/errors.rs create mode 100644 programs/anchor/token-swap/src/instructions/create_amm.rs create mode 100644 programs/anchor/token-swap/src/instructions/create_pool.rs create mode 100644 programs/anchor/token-swap/src/instructions/create_pool_light_lp.rs create mode 100644 programs/anchor/token-swap/src/instructions/deposit_liquidity.rs create mode 100644 programs/anchor/token-swap/src/instructions/mod.rs create mode 100644 programs/anchor/token-swap/src/instructions/shared.rs create mode 100644 programs/anchor/token-swap/src/instructions/swap_exact_tokens_for_tokens.rs create mode 100644 programs/anchor/token-swap/src/instructions/withdraw_liquidity.rs create mode 100644 programs/anchor/token-swap/src/lib.rs create mode 100644 programs/anchor/token-swap/src/state.rs create mode 100644 programs/anchor/token-swap/tests/common/mod.rs create mode 100644 programs/anchor/token-swap/tests/user_light.rs create mode 100644 programs/anchor/token-swap/tests/user_light_full.rs create mode 100644 programs/anchor/token-swap/tests/user_spl.rs create mode 100644 programs/anchor/token-swap/tests/user_spl_light.rs create mode 100644 programs/anchor/token-swap/tests/user_t22.rs create mode 100644 programs/anchor/token-swap/tests/user_t22_light.rs diff --git a/.github/actions/setup/action.yml b/.github/actions/setup/action.yml index 8137d8c..47e4c5d 100644 --- a/.github/actions/setup/action.yml +++ b/.github/actions/setup/action.yml @@ -1,19 +1,31 @@ name: Setup Environment -description: Setup Rust, Solana CLI, and Light CLI for testing +description: Setup Rust, Solana CLI, and optionally Node.js for testing inputs: + example: + description: "Example directory path (used for Rust workspace caching)" + required: false + default: "" + node-version: + description: "Node.js version to install (optional, empty = minimal Node for Light CLI only)" + required: false + default: "" solana-cli-version: description: "Solana CLI version" required: false - default: "2.1.21" + default: "2.3.11" rust-toolchain: description: "Rust toolchain version" required: false - default: "1.85.0" + default: "1.90.0" light-cli-version: description: "Light CLI version" required: false default: "alpha" + photon-indexer: + description: "Install Photon indexer (required for TypeScript tests)" + required: false + default: "false" runs: using: composite @@ -22,18 +34,19 @@ runs: uses: actions-rust-lang/setup-rust-toolchain@v1 with: toolchain: ${{ inputs.rust-toolchain }} - cache: false + cache-workspaces: ${{ inputs.example || '.' }} - - name: Setup Node.js (for Light CLI) + - name: Setup Node.js + if: inputs.node-version != '' uses: actions/setup-node@v4 with: - node-version: "22" + node-version: ${{ inputs.node-version }} - - name: Cache npm global packages - uses: actions/cache@v4 + - name: Setup Node.js (for Light CLI) + if: inputs.node-version == '' + uses: actions/setup-node@v4 with: - path: ~/.npm - key: npm-${{ runner.os }}-light-cli-${{ inputs.light-cli-version }} + node-version: "22" - name: Cache Solana CLI tools uses: actions/cache@v4 @@ -53,6 +66,21 @@ runs: shell: bash run: npm install -g @lightprotocol/zk-compression-cli@${{ inputs.light-cli-version }} + - name: Cache Photon indexer + if: inputs.photon-indexer == 'true' + id: cache-photon + uses: actions/cache@v4 + with: + path: ~/.cargo/bin/photon + key: photon-${{ runner.os }}-ac7df6c388db847b7693a7a1cb766a7c9d7809b5 + + - name: Install Photon indexer + if: inputs.photon-indexer == 'true' && steps.cache-photon.outputs.cache-hit != 'true' + shell: bash + env: + RUSTFLAGS: "-A dead-code" + run: cargo install --git https://github.com/lightprotocol/photon.git --rev ac7df6c388db847b7693a7a1cb766a7c9d7809b5 --locked --force + - name: Generate keypair shell: bash run: solana-keygen new --no-bip39-passphrase @@ -64,4 +92,3 @@ runs: cargo --version solana --version light --version - diff --git a/.github/workflows/rust-tests.yml b/.github/workflows/rust-tests.yml new file mode 100644 index 0000000..11f4b24 --- /dev/null +++ b/.github/workflows/rust-tests.yml @@ -0,0 +1,44 @@ +name: Rust + +on: + push: + branches: + - main + pull_request: + types: [opened, synchronize, reopened] + branches: + - main + +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: true + +env: + SOLANA_CLI_VERSION: "2.3.11" + RUST_TOOLCHAIN: "1.90.0" + +jobs: + test-rust: + name: ${{ matrix.package }} + runs-on: ubuntu-latest + strategy: + fail-fast: false + matrix: + package: + - escrow + - fundraiser + - light-token-minter + - swap_example + steps: + - uses: actions/checkout@v4 + + - name: Setup environment + uses: ./.github/actions/setup + with: + example: programs/anchor + solana-cli-version: ${{ env.SOLANA_CLI_VERSION }} + rust-toolchain: ${{ env.RUST_TOOLCHAIN }} + + - name: Test + working-directory: programs/anchor + run: cargo test-sbf -p ${{ matrix.package }} diff --git a/.github/workflows/typescript-tests.yml b/.github/workflows/typescript-tests.yml index 1b48743..70e0979 100644 --- a/.github/workflows/typescript-tests.yml +++ b/.github/workflows/typescript-tests.yml @@ -14,7 +14,8 @@ concurrency: cancel-in-progress: true env: - SOLANA_CLI_VERSION: "2.1.21" + SOLANA_CLI_VERSION: "2.3.11" + RUST_TOOLCHAIN: "1.90.0" NODE_VERSION: "22" jobs: @@ -24,48 +25,13 @@ jobs: steps: - uses: actions/checkout@v4 - - name: Setup Node.js - uses: actions/setup-node@v4 + - name: Setup environment + uses: ./.github/actions/setup with: node-version: ${{ env.NODE_VERSION }} - - - name: Cache Solana CLI tools - uses: actions/cache@v4 - with: - path: | - ~/.cache/solana/ - ~/.local/share/solana/ - key: solana-cli-${{ runner.os }}-${{ env.SOLANA_CLI_VERSION }} - - - name: Install Solana CLI tools - run: | - sh -c "$(curl -sSfL https://release.anza.xyz/v${{ env.SOLANA_CLI_VERSION }}/install)" - echo "/home/runner/.local/share/solana/install/active_release/bin" >> $GITHUB_PATH - - - name: Install Light CLI - run: npm install -g @lightprotocol/zk-compression-cli@alpha - - - name: Install Rust (for Photon) - uses: actions-rust-lang/setup-rust-toolchain@v1 - with: - toolchain: stable - cache: false - - - name: Cache Photon indexer - id: cache-photon - uses: actions/cache@v4 - with: - path: ~/.cargo/bin/photon - key: photon-${{ runner.os }}-1a785036de52896b68d06413e3b0231122d6aa4a - - - name: Install Photon indexer - if: steps.cache-photon.outputs.cache-hit != 'true' - run: cargo install --git https://github.com/lightprotocol/photon.git --rev 1a785036de52896b68d06413e3b0231122d6aa4a --locked - env: - RUSTFLAGS: "-A dead-code" - - - name: Generate keypair - run: solana-keygen new --no-bip39-passphrase + solana-cli-version: ${{ env.SOLANA_CLI_VERSION }} + rust-toolchain: ${{ env.RUST_TOOLCHAIN }} + photon-indexer: "true" - name: Install dependencies working-directory: typescript-client diff --git a/.gitignore b/.gitignore index 1803e1d..ea6b209 100644 --- a/.gitignore +++ b/.gitignore @@ -1,9 +1,27 @@ +# Dependencies **/node_modules/ **/dist/ + +# Environment and secrets **/.env +**/.env.* +**/*-keypair.json +**/id.json + +# Build artifacts +**/target +**/.anchor + +# Test artifacts +**/test-ledger + +# Lock files **/pnpm-lock.yaml **/package-lock.json + +# Backups **/*.json.bak -**/test-ledger -**/target + +# Project-specific cli/accounts/ +bugs.md diff --git a/README.md b/README.md index 8e2372a..81062b2 100644 --- a/README.md +++ b/README.md @@ -36,4 +36,4 @@ TypeScript examples for light-token-sdk. ## Documentation -Learn more [about to Light-Token here](https://www.zkcompression.com/light-token/welcome). +Learn more [about Light-Token here](https://www.zkcompression.com/light-token/welcome). diff --git a/programs/anchor/Anchor.toml b/programs/anchor/Anchor.toml new file mode 100644 index 0000000..651ef42 --- /dev/null +++ b/programs/anchor/Anchor.toml @@ -0,0 +1,30 @@ +[toolchain] + +[features] +resolution = true +skip-lint = false + +[workspace] +members = [ + "escrow", + "fundraiser", + "light-token-minter", + "token-swap", +] + +[programs.localnet] +escrow = "FKJs6rp6TXJtxzLiPtdYhqa9ExRuBXG2zwh4fda6WATN" +fundraiser = "Eoiuq1dXvHxh6dLx3wh9gj8kSAUpga11krTrbfF5XYsC" +light_token_minter = "3EPJBoxM8Evtv3Wk7R2mSWsrSzUD7WSKAaYugLgpCitV" +swap_example = "AsGVFxWqEn8icRBFQApxJe68x3r9zvfSbmiEzYFATGYn" +counter = "PDAm7XVHEkBvzBYDh8qF3z8NxnYQzPjGQJKcHVmMZpT" + +[registry] +url = "https://api.apr.dev" + +[provider] +cluster = "localnet" +wallet = "~/.config/solana/id.json" + +[scripts] +test = "yarn run ts-mocha -p ./tsconfig.json -t 1000000 tests/**/*.ts" diff --git a/programs/anchor/Cargo.lock b/programs/anchor/Cargo.lock new file mode 100644 index 0000000..70a9b29 --- /dev/null +++ b/programs/anchor/Cargo.lock @@ -0,0 +1,9056 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 4 + +[[package]] +name = "Inflector" +version = "0.11.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fe438c63458706e03479442743baae6c88256498e6431708f6dfc520a26515d3" +dependencies = [ + "lazy_static", + "regex", +] + +[[package]] +name = "adler2" +version = "2.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "320119579fcad9c21884f5c4861d16174d0e06250625266f50fe6898340abefa" + +[[package]] +name = "aead" +version = "0.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d122413f284cf2d62fb1b7db97e02edb8cda96d769b16e443a4f6195e35662b0" +dependencies = [ + "crypto-common", + "generic-array", +] + +[[package]] +name = "aes" +version = "0.8.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b169f7a6d4742236a0a00c541b845991d0ac43e546831af1249753ab4c3aa3a0" +dependencies = [ + "cfg-if", + "cipher", + "cpufeatures", +] + +[[package]] +name = "aes-gcm-siv" +version = "0.11.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ae0784134ba9375416d469ec31e7c5f9fa94405049cf08c5ce5b4698be673e0d" +dependencies = [ + "aead", + "aes", + "cipher", + "ctr", + "polyval", + "subtle", + "zeroize", +] + +[[package]] +name = "agave-feature-set" +version = "2.3.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d52a2c365c0245cbb8959de725fc2b44c754b673fdf34c9a7f9d4a25c35a7bf1" +dependencies = [ + "ahash", + "solana-epoch-schedule", + "solana-hash", + "solana-pubkey", + "solana-sha256-hasher", + "solana-svm-feature-set", +] + +[[package]] +name = "agave-precompiles" +version = "2.3.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d60d73657792af7f2464e9181d13c3979e94bb09841d9ffa014eef4ef0492b77" +dependencies = [ + "agave-feature-set", + "bincode", + "digest 0.10.7", + "ed25519-dalek", + "libsecp256k1", + "openssl", + "sha3", + "solana-ed25519-program", + "solana-message", + "solana-precompile-error", + "solana-pubkey", + "solana-sdk-ids", + "solana-secp256k1-program", + "solana-secp256r1-program", +] + +[[package]] +name = "agave-reserved-account-keys" +version = "2.3.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8289c8a8a2ef5aa10ce49a070f360f4e035ee3410b8d8f3580fb39d8cf042581" +dependencies = [ + "agave-feature-set", + "solana-pubkey", + "solana-sdk-ids", +] + +[[package]] +name = "ahash" +version = "0.8.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5a15f179cd60c4584b8a8c596927aadc462e27f2ca70c04e0071964a73ba7a75" +dependencies = [ + "cfg-if", + "getrandom 0.3.4", + "once_cell", + "version_check", + "zerocopy", +] + +[[package]] +name = "aho-corasick" +version = "1.1.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ddd31a130427c27518df266943a5308ed92d4b226cc639f5a8f1002816174301" +dependencies = [ + "memchr", +] + +[[package]] +name = "aligned-sized" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "48a526ec4434d531d488af59fe866f36b310fe8906691c75dffa664450a3800a" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.114", +] + +[[package]] +name = "alloc-no-stdlib" +version = "2.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cc7bb162ec39d46ab1ca8c77bf72e890535becd1751bb45f64c597edb4c8c6b3" + +[[package]] +name = "alloc-stdlib" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "94fb8275041c72129eb51b7d0322c29b8387a0386127718b096429201a5d6ece" +dependencies = [ + "alloc-no-stdlib", +] + +[[package]] +name = "allocator-api2" +version = "0.2.21" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "683d7910e743518b0e34f1186f92494becacb047c7b6bf616c96772180fef923" + +[[package]] +name = "anchor-attribute-access-control" +version = "0.31.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3f70fd141a4d18adf11253026b32504f885447048c7494faf5fa83b01af9c0cf" +dependencies = [ + "anchor-syn", + "proc-macro2", + "quote", + "syn 1.0.109", +] + +[[package]] +name = "anchor-attribute-account" +version = "0.31.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "715a261c57c7679581e06f07a74fa2af874ac30f86bd8ea07cca4a7e5388a064" +dependencies = [ + "anchor-syn", + "bs58", + "proc-macro2", + "quote", + "syn 1.0.109", +] + +[[package]] +name = "anchor-attribute-constant" +version = "0.31.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "730d6df8ae120321c5c25e0779e61789e4b70dc8297102248902022f286102e4" +dependencies = [ + "anchor-syn", + "quote", + "syn 1.0.109", +] + +[[package]] +name = "anchor-attribute-error" +version = "0.31.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "27e6e449cc3a37b2880b74dcafb8e5a17b954c0e58e376432d7adc646fb333ef" +dependencies = [ + "anchor-syn", + "quote", + "syn 1.0.109", +] + +[[package]] +name = "anchor-attribute-event" +version = "0.31.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d7710e4c54adf485affcd9be9adec5ef8846d9c71d7f31e16ba86ff9fc1dd49f" +dependencies = [ + "anchor-syn", + "proc-macro2", + "quote", + "syn 1.0.109", +] + +[[package]] +name = "anchor-attribute-program" +version = "0.31.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "05ecfd49b2aeadeb32f35262230db402abed76ce87e27562b34f61318b2ec83c" +dependencies = [ + "anchor-lang-idl", + "anchor-syn", + "anyhow", + "bs58", + "heck 0.3.3", + "proc-macro2", + "quote", + "serde_json", + "syn 1.0.109", +] + +[[package]] +name = "anchor-derive-accounts" +version = "0.31.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "be89d160793a88495af462a7010b3978e48e30a630c91de47ce2c1d3cb7a6149" +dependencies = [ + "anchor-syn", + "quote", + "syn 1.0.109", +] + +[[package]] +name = "anchor-derive-serde" +version = "0.31.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "abc6ee78acb7bfe0c2dd2abc677aaa4789c0281a0c0ef01dbf6fe85e0fd9e6e4" +dependencies = [ + "anchor-syn", + "borsh-derive-internal", + "proc-macro2", + "quote", + "syn 1.0.109", +] + +[[package]] +name = "anchor-derive-space" +version = "0.31.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "134a01c0703f6fd355a0e472c033f6f3e41fac1ef6e370b20c50f4c8d022cea7" +dependencies = [ + "proc-macro2", + "quote", + "syn 1.0.109", +] + +[[package]] +name = "anchor-lang" +version = "0.31.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e6bab117055905e930f762c196e08f861f8dfe7241b92cee46677a3b15561a0a" +dependencies = [ + "anchor-attribute-access-control", + "anchor-attribute-account", + "anchor-attribute-constant", + "anchor-attribute-error", + "anchor-attribute-event", + "anchor-attribute-program", + "anchor-derive-accounts", + "anchor-derive-serde", + "anchor-derive-space", + "anchor-lang-idl", + "base64 0.21.7", + "bincode", + "borsh 0.10.4", + "bytemuck", + "solana-program", + "thiserror 1.0.69", +] + +[[package]] +name = "anchor-lang-idl" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "32e8599d21995f68e296265aa5ab0c3cef582fd58afec014d01bd0bce18a4418" +dependencies = [ + "anchor-lang-idl-spec", + "anyhow", + "heck 0.3.3", + "regex", + "serde", + "serde_json", + "sha2 0.10.9", +] + +[[package]] +name = "anchor-lang-idl-spec" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2bdf143115440fe621bdac3a29a1f7472e09f6cd82b2aa569429a0c13f103838" +dependencies = [ + "anyhow", + "serde", +] + +[[package]] +name = "anchor-spl" +version = "0.31.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3c08cb5d762c0694f74bd02c9a5b04ea53cefc496e2c27b3234acffca5cd076b" +dependencies = [ + "anchor-lang", + "mpl-token-metadata", + "spl-associated-token-account 6.0.0", + "spl-pod", + "spl-token 7.0.0", + "spl-token-2022 6.0.0", + "spl-token-group-interface 0.5.0", + "spl-token-metadata-interface 0.6.0", +] + +[[package]] +name = "anchor-syn" +version = "0.31.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5dc7a6d90cc643df0ed2744862cdf180587d1e5d28936538c18fc8908489ed67" +dependencies = [ + "anyhow", + "bs58", + "cargo_toml", + "heck 0.3.3", + "proc-macro2", + "quote", + "serde", + "serde_json", + "sha2 0.10.9", + "syn 1.0.109", + "thiserror 1.0.69", +] + +[[package]] +name = "android_system_properties" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "819e7219dbd41043ac279b19830f2efc897156490d7fd6ea916720117ee66311" +dependencies = [ + "libc", +] + +[[package]] +name = "ansi_term" +version = "0.12.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d52a9bb7ec0cf484c551830a7ce27bd20d67eac647e1befb56b0be4ee39a55d2" +dependencies = [ + "winapi", +] + +[[package]] +name = "anyhow" +version = "1.0.100" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a23eb6b1614318a8071c9b2521f36b424b2c83db5eb3a0fead4a6c0809af6e61" + +[[package]] +name = "ark-bn254" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a22f4561524cd949590d78d7d4c5df8f592430d221f7f3c9497bbafd8972120f" +dependencies = [ + "ark-ec 0.4.2", + "ark-ff 0.4.2", + "ark-std 0.4.0", +] + +[[package]] +name = "ark-bn254" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d69eab57e8d2663efa5c63135b2af4f396d66424f88954c21104125ab6b3e6bc" +dependencies = [ + "ark-ec 0.5.0", + "ark-ff 0.5.0", + "ark-std 0.5.0", +] + +[[package]] +name = "ark-ec" +version = "0.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "defd9a439d56ac24968cca0571f598a61bc8c55f71d50a89cda591cb750670ba" +dependencies = [ + "ark-ff 0.4.2", + "ark-poly 0.4.2", + "ark-serialize 0.4.2", + "ark-std 0.4.0", + "derivative", + "hashbrown 0.13.2", + "itertools 0.10.5", + "num-traits", + "zeroize", +] + +[[package]] +name = "ark-ec" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "43d68f2d516162846c1238e755a7c4d131b892b70cc70c471a8e3ca3ed818fce" +dependencies = [ + "ahash", + "ark-ff 0.5.0", + "ark-poly 0.5.0", + "ark-serialize 0.5.0", + "ark-std 0.5.0", + "educe 0.6.0", + "fnv", + "hashbrown 0.15.2", + "itertools 0.13.0", + "num-bigint 0.4.6", + "num-integer", + "num-traits", + "zeroize", +] + +[[package]] +name = "ark-ff" +version = "0.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ec847af850f44ad29048935519032c33da8aa03340876d351dfab5660d2966ba" +dependencies = [ + "ark-ff-asm 0.4.2", + "ark-ff-macros 0.4.2", + "ark-serialize 0.4.2", + "ark-std 0.4.0", + "derivative", + "digest 0.10.7", + "itertools 0.10.5", + "num-bigint 0.4.6", + "num-traits", + "paste", + "rustc_version", + "zeroize", +] + +[[package]] +name = "ark-ff" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a177aba0ed1e0fbb62aa9f6d0502e9b46dad8c2eab04c14258a1212d2557ea70" +dependencies = [ + "ark-ff-asm 0.5.0", + "ark-ff-macros 0.5.0", + "ark-serialize 0.5.0", + "ark-std 0.5.0", + "arrayvec", + "digest 0.10.7", + "educe 0.6.0", + "itertools 0.13.0", + "num-bigint 0.4.6", + "num-traits", + "paste", + "zeroize", +] + +[[package]] +name = "ark-ff-asm" +version = "0.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3ed4aa4fe255d0bc6d79373f7e31d2ea147bcf486cba1be5ba7ea85abdb92348" +dependencies = [ + "quote", + "syn 1.0.109", +] + +[[package]] +name = "ark-ff-asm" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "62945a2f7e6de02a31fe400aa489f0e0f5b2502e69f95f853adb82a96c7a6b60" +dependencies = [ + "quote", + "syn 2.0.114", +] + +[[package]] +name = "ark-ff-macros" +version = "0.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7abe79b0e4288889c4574159ab790824d0033b9fdcb2a112a3182fac2e514565" +dependencies = [ + "num-bigint 0.4.6", + "num-traits", + "proc-macro2", + "quote", + "syn 1.0.109", +] + +[[package]] +name = "ark-ff-macros" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "09be120733ee33f7693ceaa202ca41accd5653b779563608f1234f78ae07c4b3" +dependencies = [ + "num-bigint 0.4.6", + "num-traits", + "proc-macro2", + "quote", + "syn 2.0.114", +] + +[[package]] +name = "ark-poly" +version = "0.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d320bfc44ee185d899ccbadfa8bc31aab923ce1558716e1997a1e74057fe86bf" +dependencies = [ + "ark-ff 0.4.2", + "ark-serialize 0.4.2", + "ark-std 0.4.0", + "derivative", + "hashbrown 0.13.2", +] + +[[package]] +name = "ark-poly" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "579305839da207f02b89cd1679e50e67b4331e2f9294a57693e5051b7703fe27" +dependencies = [ + "ahash", + "ark-ff 0.5.0", + "ark-serialize 0.5.0", + "ark-std 0.5.0", + "educe 0.6.0", + "fnv", + "hashbrown 0.15.2", +] + +[[package]] +name = "ark-serialize" +version = "0.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "adb7b85a02b83d2f22f89bd5cac66c9c89474240cb6207cb1efc16d098e822a5" +dependencies = [ + "ark-serialize-derive 0.4.2", + "ark-std 0.4.0", + "digest 0.10.7", + "num-bigint 0.4.6", +] + +[[package]] +name = "ark-serialize" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3f4d068aaf107ebcd7dfb52bc748f8030e0fc930ac8e360146ca54c1203088f7" +dependencies = [ + "ark-serialize-derive 0.5.0", + "ark-std 0.5.0", + "arrayvec", + "digest 0.10.7", + "num-bigint 0.4.6", +] + +[[package]] +name = "ark-serialize-derive" +version = "0.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ae3281bc6d0fd7e549af32b52511e1302185bd688fd3359fa36423346ff682ea" +dependencies = [ + "proc-macro2", + "quote", + "syn 1.0.109", +] + +[[package]] +name = "ark-serialize-derive" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "213888f660fddcca0d257e88e54ac05bca01885f258ccdf695bafd77031bb69d" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.114", +] + +[[package]] +name = "ark-std" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "94893f1e0c6eeab764ade8dc4c0db24caf4fe7cbbaafc0eba0a9030f447b5185" +dependencies = [ + "num-traits", + "rand 0.8.5", +] + +[[package]] +name = "ark-std" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "246a225cc6131e9ee4f24619af0f19d67761fff15d7ccc22e42b80846e69449a" +dependencies = [ + "num-traits", + "rand 0.8.5", + "rayon", +] + +[[package]] +name = "arrayref" +version = "0.3.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "76a2e8124351fda1ef8aaaa3bbd7ebbcb486bbcd4225aca0aa0d84bb2db8fecb" + +[[package]] +name = "arrayvec" +version = "0.7.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7c02d123df017efcdfbd739ef81735b36c5ba83ec3c59c80a9d7ecc718f92e50" + +[[package]] +name = "ascii" +version = "0.9.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "eab1c04a571841102f5345a8fc0f6bb3d31c315dec879b5c6e42e40ce7ffa34e" + +[[package]] +name = "async-compression" +version = "0.4.37" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d10e4f991a553474232bc0a31799f6d24b034a84c0971d80d2e2f78b2e576e40" +dependencies = [ + "compression-codecs", + "compression-core", + "pin-project-lite", + "tokio", +] + +[[package]] +name = "async-trait" +version = "0.1.89" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9035ad2d096bed7955a320ee7e2230574d28fd3c3a0f186cbea1ff3c7eed5dbb" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.114", +] + +[[package]] +name = "atomic-waker" +version = "1.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1505bd5d3d116872e7271a6d4e16d81d0c8570876c8de68093a09ac269d8aac0" + +[[package]] +name = "atty" +version = "0.2.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d9b39be18770d11421cdb1b9947a45dd3f37e93092cbf377614828a319d5fee8" +dependencies = [ + "hermit-abi", + "libc", + "winapi", +] + +[[package]] +name = "autocfg" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c08606f8c3cbf4ce6ec8e28fb0014a2c086708fe954eaa885384a6165172e7e8" + +[[package]] +name = "az" +version = "1.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7b7e4c2464d97fe331d41de9d5db0def0a96f4d823b8b32a2efd503578988973" + +[[package]] +name = "base64" +version = "0.12.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3441f0f7b02788e948e47f457ca01f1d7e6d92c693bc132c22b087d3141c03ff" + +[[package]] +name = "base64" +version = "0.13.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9e1b586273c5702936fe7b7d6896644d8be71e6314cfe09d3167c95f712589e8" + +[[package]] +name = "base64" +version = "0.21.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9d297deb1925b89f2ccc13d7635fa0714f12c87adce1c75356b39ca9b7178567" + +[[package]] +name = "base64" +version = "0.22.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "72b3254f16251a8381aa12e40e3c4d2f0199f8c6508fbecb9d91f575e0fbb8c6" + +[[package]] +name = "bincode" +version = "1.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b1f45e9417d87227c7a56d22e471c6206462cba514c7590c09aff4cf6d1ddcad" +dependencies = [ + "serde", +] + +[[package]] +name = "bitflags" +version = "1.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" + +[[package]] +name = "bitflags" +version = "2.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "812e12b5285cc515a9c72a5c1d3b6d46a19dac5acfef5265968c166106e31dd3" +dependencies = [ + "serde_core", +] + +[[package]] +name = "bitvec" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1bc2832c24239b0141d5674bb9174f9d68a8b5b3f2753311927c172ca46f7e9c" +dependencies = [ + "funty", + "radium", + "tap", + "wyz", +] + +[[package]] +name = "blake3" +version = "1.5.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b8ee0c1824c4dea5b5f81736aff91bae041d2c07ee1192bec91054e10e3e601e" +dependencies = [ + "arrayref", + "arrayvec", + "cc", + "cfg-if", + "constant_time_eq", + "digest 0.10.7", +] + +[[package]] +name = "block-buffer" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4152116fd6e9dadb291ae18fc1ec3575ed6d84c29642d97890f4b4a3417297e4" +dependencies = [ + "generic-array", +] + +[[package]] +name = "block-buffer" +version = "0.10.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3078c7629b62d3f0439517fa394996acacc5cbc91c5a20d8c658e77abd503a71" +dependencies = [ + "generic-array", +] + +[[package]] +name = "borsh" +version = "0.10.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "115e54d64eb62cdebad391c19efc9dce4981c690c85a33a12199d99bb9546fee" +dependencies = [ + "borsh-derive 0.10.4", + "hashbrown 0.13.2", +] + +[[package]] +name = "borsh" +version = "1.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d1da5ab77c1437701eeff7c88d968729e7766172279eab0676857b3d63af7a6f" +dependencies = [ + "borsh-derive 1.6.0", + "cfg_aliases", +] + +[[package]] +name = "borsh-derive" +version = "0.10.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "831213f80d9423998dd696e2c5345aba6be7a0bd8cd19e31c5243e13df1cef89" +dependencies = [ + "borsh-derive-internal", + "borsh-schema-derive-internal", + "proc-macro-crate 0.1.5", + "proc-macro2", + "syn 1.0.109", +] + +[[package]] +name = "borsh-derive" +version = "1.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0686c856aa6aac0c4498f936d7d6a02df690f614c03e4d906d1018062b5c5e2c" +dependencies = [ + "once_cell", + "proc-macro-crate 3.4.0", + "proc-macro2", + "quote", + "syn 2.0.114", +] + +[[package]] +name = "borsh-derive-internal" +version = "0.10.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "65d6ba50644c98714aa2a70d13d7df3cd75cd2b523a2b452bf010443800976b3" +dependencies = [ + "proc-macro2", + "quote", + "syn 1.0.109", +] + +[[package]] +name = "borsh-schema-derive-internal" +version = "0.10.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "276691d96f063427be83e6692b86148e488ebba9f48f77788724ca027ba3b6d4" +dependencies = [ + "proc-macro2", + "quote", + "syn 1.0.109", +] + +[[package]] +name = "brotli" +version = "8.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4bd8b9603c7aa97359dbd97ecf258968c95f3adddd6db2f7e7a5bef101c84560" +dependencies = [ + "alloc-no-stdlib", + "alloc-stdlib", + "brotli-decompressor", +] + +[[package]] +name = "brotli-decompressor" +version = "5.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "874bb8112abecc98cbd6d81ea4fa7e94fb9449648c93cc89aa40c81c24d7de03" +dependencies = [ + "alloc-no-stdlib", + "alloc-stdlib", +] + +[[package]] +name = "bs58" +version = "0.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bf88ba1141d185c399bee5288d850d63b8369520c1eafc32a0430b5b6c287bf4" +dependencies = [ + "tinyvec", +] + +[[package]] +name = "bumpalo" +version = "3.19.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5dd9dc738b7a8311c7ade152424974d8115f2cdad61e8dab8dac9f2362298510" + +[[package]] +name = "bv" +version = "0.11.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8834bb1d8ee5dc048ee3124f2c7c1afcc6bc9aed03f11e9dfd8c69470a5db340" +dependencies = [ + "feature-probe", + "serde", +] + +[[package]] +name = "bytecount" +version = "0.6.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "175812e0be2bccb6abe50bb8d566126198344f707e304f45c648fd8f2cc0365e" + +[[package]] +name = "bytemuck" +version = "1.24.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1fbdf580320f38b612e485521afda1ee26d10cc9884efaaa750d383e13e3c5f4" +dependencies = [ + "bytemuck_derive", +] + +[[package]] +name = "bytemuck_derive" +version = "1.10.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f9abbd1bc6865053c427f7198e6af43bfdedc55ab791faed4fbd361d789575ff" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.114", +] + +[[package]] +name = "byteorder" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1fd0f2584146f6f2ef48085050886acf353beff7305ebd1ae69500e27c67f64b" + +[[package]] +name = "bytes" +version = "1.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b35204fbdc0b3f4446b89fc1ac2cf84a8a68971995d0bf2e925ec7cd960f9cb3" + +[[package]] +name = "cargo_toml" +version = "0.19.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a98356df42a2eb1bd8f1793ae4ee4de48e384dd974ce5eac8eee802edb7492be" +dependencies = [ + "serde", + "toml 0.8.23", +] + +[[package]] +name = "cc" +version = "1.2.54" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6354c81bbfd62d9cfa9cb3c773c2b7b2a3a482d569de977fd0e961f6e7c00583" +dependencies = [ + "find-msvc-tools", + "jobserver", + "libc", + "shlex", +] + +[[package]] +name = "cfg-if" +version = "1.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9330f8b2ff13f34540b44e946ef35111825727b38d33286ef986142615121801" + +[[package]] +name = "cfg_aliases" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "613afe47fcd5fac7ccf1db93babcb082c5994d996f20b8b159f2ad1658eb5724" + +[[package]] +name = "cfg_eval" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "45565fc9416b9896014f5732ac776f810ee53a66730c17e4020c3ec064a8f88f" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.114", +] + +[[package]] +name = "chrono" +version = "0.4.43" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fac4744fb15ae8337dc853fee7fb3f4e48c0fbaa23d0afe49c447b4fab126118" +dependencies = [ + "iana-time-zone", + "js-sys", + "num-traits", + "serde", + "wasm-bindgen", + "windows-link", +] + +[[package]] +name = "cipher" +version = "0.4.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "773f3b9af64447d2ce9850330c473515014aa235e6a783b02db81ff39e4a3dad" +dependencies = [ + "crypto-common", + "inout", +] + +[[package]] +name = "combine" +version = "3.8.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "da3da6baa321ec19e1cc41d31bf599f00c783d0517095cdaf0332e3fe8d20680" +dependencies = [ + "ascii", + "byteorder", + "either", + "memchr", + "unreachable", +] + +[[package]] +name = "compression-codecs" +version = "0.4.36" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "00828ba6fd27b45a448e57dbfe84f1029d4c9f26b368157e9a448a5f49a2ec2a" +dependencies = [ + "brotli", + "compression-core", + "flate2", + "memchr", +] + +[[package]] +name = "compression-core" +version = "0.4.31" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "75984efb6ed102a0d42db99afb6c1948f0380d1d91808d5529916e6c08b49d8d" + +[[package]] +name = "console" +version = "0.15.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "054ccb5b10f9f2cbf51eb355ca1d05c2d279ce1804688d0db74b4733a5aeafd8" +dependencies = [ + "encode_unicode", + "libc", + "once_cell", + "unicode-width", + "windows-sys 0.59.0", +] + +[[package]] +name = "console_error_panic_hook" +version = "0.1.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a06aeb73f470f66dcdbf7223caeebb85984942f22f1adb2a088cf9668146bbbc" +dependencies = [ + "cfg-if", + "wasm-bindgen", +] + +[[package]] +name = "console_log" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e89f72f65e8501878b8a004d5a1afb780987e2ce2b4532c562e367a72c57499f" +dependencies = [ + "log", + "web-sys", +] + +[[package]] +name = "constant_time_eq" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7c74b8349d32d297c9134b8c88677813a227df8f779daa29bfc29c183fe3dca6" + +[[package]] +name = "core-foundation" +version = "0.9.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "91e195e091a93c46f7102ec7818a2aa394e1e1771c3ab4825963fa03e45afb8f" +dependencies = [ + "core-foundation-sys", + "libc", +] + +[[package]] +name = "core-foundation-sys" +version = "0.8.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "773648b94d0e5d620f64f280777445740e61fe701025087ec8b57f45c791888b" + +[[package]] +name = "cpufeatures" +version = "0.2.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "59ed5838eebb26a2bb2e58f6d5b5316989ae9d08bab10e0e6d103e656d1b0280" +dependencies = [ + "libc", +] + +[[package]] +name = "crc32fast" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9481c1c90cbf2ac953f07c8d4a58aa3945c425b7185c9154d67a65e4230da511" +dependencies = [ + "cfg-if", +] + +[[package]] +name = "crossbeam-channel" +version = "0.5.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "82b8f8f868b36967f9606790d1903570de9ceaf870a7bf9fbbd3016d636a2cb2" +dependencies = [ + "crossbeam-utils", +] + +[[package]] +name = "crossbeam-deque" +version = "0.8.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9dd111b7b7f7d55b72c0a6ae361660ee5853c9af73f70c3c2ef6858b950e2e51" +dependencies = [ + "crossbeam-epoch", + "crossbeam-utils", +] + +[[package]] +name = "crossbeam-epoch" +version = "0.9.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5b82ac4a3c2ca9c3460964f020e1402edd5753411d7737aa39c3714ad1b5420e" +dependencies = [ + "crossbeam-utils", +] + +[[package]] +name = "crossbeam-utils" +version = "0.8.21" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d0a5c400df2834b80a4c3327b3aad3a4c4cd4de0629063962b03235697506a28" + +[[package]] +name = "crunchy" +version = "0.2.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "460fbee9c2c2f33933d720630a6a0bac33ba7053db5344fac858d4b8952d77d5" + +[[package]] +name = "crypto-common" +version = "0.1.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "78c8292055d1c1df0cce5d180393dc8cce0abec0a7102adb6c7b1eef6016d60a" +dependencies = [ + "generic-array", + "rand_core 0.6.4", + "typenum", +] + +[[package]] +name = "crypto-mac" +version = "0.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b584a330336237c1eecd3e94266efb216c56ed91225d634cb2991c5f3fd1aeab" +dependencies = [ + "generic-array", + "subtle", +] + +[[package]] +name = "ctr" +version = "0.9.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0369ee1ad671834580515889b80f2ea915f23b8be8d0daa4bbaf2ac5c7590835" +dependencies = [ + "cipher", +] + +[[package]] +name = "curve25519-dalek" +version = "3.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0b9fdf9972b2bd6af2d913799d9ebc165ea4d2e65878e329d9c6b372c4491b61" +dependencies = [ + "byteorder", + "digest 0.9.0", + "rand_core 0.5.1", + "subtle", + "zeroize", +] + +[[package]] +name = "curve25519-dalek" +version = "4.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "97fb8b7c4503de7d6ae7b42ab72a5a59857b4c937ec27a3d4539dba95b5ab2be" +dependencies = [ + "cfg-if", + "cpufeatures", + "curve25519-dalek-derive", + "digest 0.10.7", + "fiat-crypto", + "rand_core 0.6.4", + "rustc_version", + "serde", + "subtle", + "zeroize", +] + +[[package]] +name = "curve25519-dalek-derive" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f46882e17999c6cc590af592290432be3bce0428cb0d5f8b6715e4dc7b383eb3" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.114", +] + +[[package]] +name = "darling" +version = "0.21.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9cdf337090841a411e2a7f3deb9187445851f91b309c0c0a29e05f74a00a48c0" +dependencies = [ + "darling_core", + "darling_macro", +] + +[[package]] +name = "darling_core" +version = "0.21.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1247195ecd7e3c85f83c8d2a366e4210d588e802133e1e355180a9870b517ea4" +dependencies = [ + "fnv", + "ident_case", + "proc-macro2", + "quote", + "strsim", + "syn 2.0.114", +] + +[[package]] +name = "darling_macro" +version = "0.21.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d38308df82d1080de0afee5d069fa14b0326a88c14f15c5ccda35b4a6c414c81" +dependencies = [ + "darling_core", + "quote", + "syn 2.0.114", +] + +[[package]] +name = "deranged" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9c9e6a11ca8224451684bc0d7d5a7adbf8f2fd6887261a1cfc3c0432f9d4068e" +dependencies = [ + "powerfmt", + "serde", +] + +[[package]] +name = "derivation-path" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6e5c37193a1db1d8ed868c03ec7b152175f26160a5b740e5e484143877e0adf0" + +[[package]] +name = "derivative" +version = "2.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fcc3dd5e9e9c0b295d6e1e4d811fb6f157d5ffd784b8d202fc62eac8035a770b" +dependencies = [ + "proc-macro2", + "quote", + "syn 1.0.109", +] + +[[package]] +name = "digest" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d3dd60d1080a57a05ab032377049e0591415d2b31afd7028356dbf3cc6dcb066" +dependencies = [ + "generic-array", +] + +[[package]] +name = "digest" +version = "0.10.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9ed9a281f7bc9b7576e61468ba615a66a5c8cfdff42420a70aa82701a3b1e292" +dependencies = [ + "block-buffer 0.10.4", + "crypto-common", + "subtle", +] + +[[package]] +name = "displaydoc" +version = "0.2.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "97369cbbc041bc366949bc74d34658d6cda5621039731c6310521892a3a20ae0" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.114", +] + +[[package]] +name = "dyn-clone" +version = "1.0.20" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d0881ea181b1df73ff77ffaaf9c7544ecc11e82fba9b5f27b262a3c73a332555" + +[[package]] +name = "eager" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "abe71d579d1812060163dff96056261deb5bf6729b100fa2e36a68b9649ba3d3" + +[[package]] +name = "ed25519" +version = "1.5.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "91cff35c70bba8a626e3185d8cd48cc11b5437e1a5bcd15b9b5fa3c64b6dfee7" +dependencies = [ + "signature", +] + +[[package]] +name = "ed25519-dalek" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c762bae6dcaf24c4c84667b8579785430908723d5c889f469d76a41d59cc7a9d" +dependencies = [ + "curve25519-dalek 3.2.0", + "ed25519", + "rand 0.7.3", + "serde", + "sha2 0.9.9", + "zeroize", +] + +[[package]] +name = "ed25519-dalek-bip32" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9d2be62a4061b872c8c0873ee4fc6f101ce7b889d039f019c5fa2af471a59908" +dependencies = [ + "derivation-path", + "ed25519-dalek", + "hmac 0.12.1", + "sha2 0.10.9", +] + +[[package]] +name = "educe" +version = "0.4.23" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0f0042ff8246a363dbe77d2ceedb073339e85a804b9a47636c6e016a9a32c05f" +dependencies = [ + "enum-ordinalize 3.1.15", + "proc-macro2", + "quote", + "syn 1.0.109", +] + +[[package]] +name = "educe" +version = "0.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1d7bc049e1bd8cdeb31b68bbd586a9464ecf9f3944af3958a7a9d0f8b9799417" +dependencies = [ + "enum-ordinalize 4.3.2", + "proc-macro2", + "quote", + "syn 2.0.114", +] + +[[package]] +name = "either" +version = "1.15.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "48c757948c5ede0e46177b7add2e67155f70e33c07fea8284df6576da70b3719" + +[[package]] +name = "encode_unicode" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "34aa73646ffb006b8f5147f3dc182bd4bcb190227ce861fc4a4844bf8e3cb2c0" + +[[package]] +name = "encoding_rs" +version = "0.8.35" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "75030f3c4f45dafd7586dd6780965a8c7e8e285a5ecb86713e63a79c5b2766f3" +dependencies = [ + "cfg-if", +] + +[[package]] +name = "enum-iterator" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9fd242f399be1da0a5354aa462d57b4ab2b4ee0683cc552f7c007d2d12d36e94" +dependencies = [ + "enum-iterator-derive", +] + +[[package]] +name = "enum-iterator-derive" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "685adfa4d6f3d765a26bc5dbc936577de9abf756c1feeb3089b01dd395034842" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.114", +] + +[[package]] +name = "enum-ordinalize" +version = "3.1.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1bf1fa3f06bbff1ea5b1a9c7b14aa992a39657db60a2759457328d7e058f49ee" +dependencies = [ + "num-bigint 0.4.6", + "num-traits", + "proc-macro2", + "quote", + "syn 2.0.114", +] + +[[package]] +name = "enum-ordinalize" +version = "4.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4a1091a7bb1f8f2c4b28f1fe2cef4980ca2d410a3d727d67ecc3178c9b0800f0" +dependencies = [ + "enum-ordinalize-derive", +] + +[[package]] +name = "enum-ordinalize-derive" +version = "4.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8ca9601fb2d62598ee17836250842873a413586e5d7ed88b356e38ddbb0ec631" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.114", +] + +[[package]] +name = "env_logger" +version = "0.9.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a12e6657c4c97ebab115a42dcee77225f7f482cdd841cf7088c657a42e9e00e7" +dependencies = [ + "atty", + "humantime", + "log", + "regex", + "termcolor", +] + +[[package]] +name = "equivalent" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "877a4ace8713b0bcf2a4e7eec82529c029f1d0619886d18145fea96c3ffe5c0f" + +[[package]] +name = "errno" +version = "0.3.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "39cab71617ae0d63f51a36d69f866391735b51691dbda63cf6f96d042b63efeb" +dependencies = [ + "libc", + "windows-sys 0.61.2", +] + +[[package]] +name = "escrow" +version = "0.1.0" +dependencies = [ + "anchor-lang", + "anchor-spl", + "blake3", + "light-anchor-spl", + "light-client", + "light-hasher", + "light-program-test", + "light-sdk", + "light-token", + "light-token-minter", + "shared-test-utils", + "solana-account-info", + "solana-instruction", + "solana-keypair", + "solana-msg", + "solana-program", + "solana-program-error", + "solana-pubkey", + "solana-sdk", + "solana-signer", + "spl-pod", + "spl-token-2022 7.0.0", + "tokio", +] + +[[package]] +name = "fastrand" +version = "2.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "37909eebbb50d72f9059c3b6d82c0463f2ff062c9e95845c43a6c9c0355411be" + +[[package]] +name = "feature-probe" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "835a3dc7d1ec9e75e2b5fb4ba75396837112d2060b03f7d43bc1897c7f7211da" + +[[package]] +name = "fiat-crypto" +version = "0.2.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "28dea519a9695b9977216879a3ebfddf92f1c08c05d984f8996aecd6ecdc811d" + +[[package]] +name = "find-msvc-tools" +version = "0.1.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8591b0bcc8a98a64310a2fae1bb3e9b8564dd10e381e6e28010fde8e8e8568db" + +[[package]] +name = "five8" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a75b8549488b4715defcb0d8a8a1c1c76a80661b5fa106b4ca0e7fce59d7d875" +dependencies = [ + "five8_core", +] + +[[package]] +name = "five8_const" +version = "0.1.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "26dec3da8bc3ef08f2c04f61eab298c3ab334523e55f076354d6d6f613799a7b" +dependencies = [ + "five8_core", +] + +[[package]] +name = "five8_core" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2551bf44bc5f776c15044b9b94153a00198be06743e262afaaa61f11ac7523a5" + +[[package]] +name = "fixed" +version = "1.27.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2fc715d38bea7b5bf487fcd79bcf8c209f0b58014f3018a7a19c2b855f472048" +dependencies = [ + "az", + "bytemuck", + "half", + "typenum", +] + +[[package]] +name = "flate2" +version = "1.1.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b375d6465b98090a5f25b1c7703f3859783755aa9a80433b36e0379a3ec2f369" +dependencies = [ + "crc32fast", + "miniz_oxide", +] + +[[package]] +name = "fnv" +version = "1.0.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" + +[[package]] +name = "foldhash" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d9c4f5dac5e15c24eb999c26181a6ca40b39fe946cbe4c263c7209467bc83af2" + +[[package]] +name = "foreign-types" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f6f339eb8adc052cd2ca78910fda869aefa38d22d5cb648e6485e4d3fc06f3b1" +dependencies = [ + "foreign-types-shared", +] + +[[package]] +name = "foreign-types-shared" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "00b0228411908ca8685dba7fc2cdd70ec9990a6e753e89b6ac91a84c40fbaf4b" + +[[package]] +name = "form_urlencoded" +version = "1.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cb4cb245038516f5f85277875cdaa4f7d2c9a0fa0468de06ed190163b1581fcf" +dependencies = [ + "percent-encoding", +] + +[[package]] +name = "fundraiser" +version = "0.1.0" +dependencies = [ + "anchor-lang", + "anchor-spl", + "blake3", + "light-anchor-spl", + "light-client", + "light-hasher", + "light-program-test", + "light-sdk", + "light-token", + "shared-test-utils", + "solana-account-info", + "solana-instruction", + "solana-keypair", + "solana-msg", + "solana-program", + "solana-program-error", + "solana-pubkey", + "solana-sdk", + "solana-signer", + "spl-pod", + "spl-token-2022 7.0.0", + "tokio", +] + +[[package]] +name = "funty" +version = "2.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e6d5a32815ae3f33302d95fdcb2ce17862f8c65363dcfd29360480ba1001fc9c" + +[[package]] +name = "futures" +version = "0.3.31" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "65bc07b1a8bc7c85c5f2e110c476c7389b4554ba72af57d8445ea63a576b0876" +dependencies = [ + "futures-channel", + "futures-core", + "futures-executor", + "futures-io", + "futures-sink", + "futures-task", + "futures-util", +] + +[[package]] +name = "futures-channel" +version = "0.3.31" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2dff15bf788c671c1934e366d07e30c1814a8ef514e1af724a602e8a2fbe1b10" +dependencies = [ + "futures-core", + "futures-sink", +] + +[[package]] +name = "futures-core" +version = "0.3.31" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "05f29059c0c2090612e8d742178b0580d2dc940c837851ad723096f87af6663e" + +[[package]] +name = "futures-executor" +version = "0.3.31" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e28d1d997f585e54aebc3f97d39e72338912123a67330d723fdbb564d646c9f" +dependencies = [ + "futures-core", + "futures-task", + "futures-util", +] + +[[package]] +name = "futures-io" +version = "0.3.31" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9e5c1b78ca4aae1ac06c48a526a655760685149f0d465d21f37abfe57ce075c6" + +[[package]] +name = "futures-macro" +version = "0.3.31" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "162ee34ebcb7c64a8abebc059ce0fee27c2262618d7b60ed8faf72fef13c3650" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.114", +] + +[[package]] +name = "futures-sink" +version = "0.3.31" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e575fab7d1e0dcb8d0c7bcf9a63ee213816ab51902e6d244a95819acacf1d4f7" + +[[package]] +name = "futures-task" +version = "0.3.31" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f90f7dce0722e95104fcb095585910c0977252f286e354b5e3bd38902cd99988" + +[[package]] +name = "futures-util" +version = "0.3.31" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9fa08315bb612088cc391249efdc3bc77536f16c91f6cf495e6fbe85b20a4a81" +dependencies = [ + "futures-channel", + "futures-core", + "futures-io", + "futures-macro", + "futures-sink", + "futures-task", + "memchr", + "pin-project-lite", + "pin-utils", + "slab", +] + +[[package]] +name = "generic-array" +version = "0.14.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "85649ca51fd72272d7821adaf274ad91c288277713d9c18820d8499a7ff69e9a" +dependencies = [ + "typenum", + "version_check", +] + +[[package]] +name = "gethostname" +version = "0.2.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c1ebd34e35c46e00bb73e81363248d627782724609fe1b6396f553f68fe3862e" +dependencies = [ + "libc", + "winapi", +] + +[[package]] +name = "getrandom" +version = "0.1.16" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8fc3cb4d91f53b50155bdcfd23f6a4c39ae1969c2ae85982b135750cccaf5fce" +dependencies = [ + "cfg-if", + "js-sys", + "libc", + "wasi 0.9.0+wasi-snapshot-preview1", + "wasm-bindgen", +] + +[[package]] +name = "getrandom" +version = "0.2.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ff2abc00be7fca6ebc474524697ae276ad847ad0a6b3faa4bcb027e9a4614ad0" +dependencies = [ + "cfg-if", + "js-sys", + "libc", + "wasi 0.11.1+wasi-snapshot-preview1", + "wasm-bindgen", +] + +[[package]] +name = "getrandom" +version = "0.3.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "899def5c37c4fd7b2664648c28120ecec138e4d395b459e5ca34f9cce2dd77fd" +dependencies = [ + "cfg-if", + "js-sys", + "libc", + "r-efi", + "wasip2", + "wasm-bindgen", +] + +[[package]] +name = "groth16-solana" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3a6d1ffb18dbf5cfc60b11bd7da88474c672870247c1e5b498619bcb6ba3d8f5" +dependencies = [ + "ark-bn254 0.5.0", + "ark-ec 0.5.0", + "ark-ff 0.5.0", + "ark-serialize 0.5.0", + "num-bigint 0.4.6", + "solana-bn254", + "thiserror 1.0.69", +] + +[[package]] +name = "h2" +version = "0.3.27" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0beca50380b1fc32983fc1cb4587bfa4bb9e78fc259aad4a0032d2080309222d" +dependencies = [ + "bytes", + "fnv", + "futures-core", + "futures-sink", + "futures-util", + "http 0.2.12", + "indexmap 2.13.0", + "slab", + "tokio", + "tokio-util 0.7.18", + "tracing", +] + +[[package]] +name = "h2" +version = "0.4.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2f44da3a8150a6703ed5d34e164b875fd14c2cdab9af1252a9a1020bde2bdc54" +dependencies = [ + "atomic-waker", + "bytes", + "fnv", + "futures-core", + "futures-sink", + "http 1.4.0", + "indexmap 2.13.0", + "slab", + "tokio", + "tokio-util 0.7.18", + "tracing", +] + +[[package]] +name = "half" +version = "2.7.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6ea2d84b969582b4b1864a92dc5d27cd2b77b622a8d79306834f1be5ba20d84b" +dependencies = [ + "cfg-if", + "crunchy", + "zerocopy", +] + +[[package]] +name = "hash32" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "47d60b12902ba28e2730cd37e95b8c9223af2808df9e902d4df49588d1470606" +dependencies = [ + "byteorder", +] + +[[package]] +name = "hashbrown" +version = "0.12.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8a9ee70c43aaf417c914396645a0fa852624801b24ebb7ae78fe8272889ac888" + +[[package]] +name = "hashbrown" +version = "0.13.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "43a3c133739dddd0d2990f9a4bdf8eb4b21ef50e4851ca85ab661199821d510e" +dependencies = [ + "ahash", +] + +[[package]] +name = "hashbrown" +version = "0.15.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bf151400ff0baff5465007dd2f3e717f3fe502074ca563069ce3a6629d07b289" +dependencies = [ + "allocator-api2", + "equivalent", + "foldhash", +] + +[[package]] +name = "hashbrown" +version = "0.16.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "841d1cc9bed7f9236f321df977030373f4a4163ae1a7dbfe1a51a2c1a51d9100" + +[[package]] +name = "heck" +version = "0.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6d621efb26863f0e9924c6ac577e8275e5e6b77455db64ffa6c65c904e9e132c" +dependencies = [ + "unicode-segmentation", +] + +[[package]] +name = "heck" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2304e00983f87ffb38b55b444b5e3b60a884b5d30c0fca7d82fe33449bbe55ea" + +[[package]] +name = "hermit-abi" +version = "0.1.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "62b467343b94ba476dcb2500d242dadbb39557df889310ac77c5d99100aaac33" +dependencies = [ + "libc", +] + +[[package]] +name = "hex" +version = "0.4.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7f24254aa9a54b5c858eaee2f5bccdb46aaf0e486a595ed5fd8f86ba55232a70" + +[[package]] +name = "hmac" +version = "0.8.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "126888268dcc288495a26bf004b38c5fdbb31682f992c84ceb046a1f0fe38840" +dependencies = [ + "crypto-mac", + "digest 0.9.0", +] + +[[package]] +name = "hmac" +version = "0.12.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6c49c37c09c17a53d937dfbb742eb3a961d65a994e6bcdcf37e7399d0cc8ab5e" +dependencies = [ + "digest 0.10.7", +] + +[[package]] +name = "hmac-drbg" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "17ea0a1394df5b6574da6e0c1ade9e78868c9fb0a4e5ef4428e32da4676b85b1" +dependencies = [ + "digest 0.9.0", + "generic-array", + "hmac 0.8.1", +] + +[[package]] +name = "http" +version = "0.2.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "601cbb57e577e2f5ef5be8e7b83f0f63994f25aa94d673e54a92d5c516d101f1" +dependencies = [ + "bytes", + "fnv", + "itoa", +] + +[[package]] +name = "http" +version = "1.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e3ba2a386d7f85a81f119ad7498ebe444d2e22c2af0b86b069416ace48b3311a" +dependencies = [ + "bytes", + "itoa", +] + +[[package]] +name = "http-body" +version = "0.4.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7ceab25649e9960c0311ea418d17bee82c0dcec1bd053b5f9a66e265a693bed2" +dependencies = [ + "bytes", + "http 0.2.12", + "pin-project-lite", +] + +[[package]] +name = "http-body" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1efedce1fb8e6913f23e0c92de8e62cd5b772a67e7b3946df930a62566c93184" +dependencies = [ + "bytes", + "http 1.4.0", +] + +[[package]] +name = "http-body-util" +version = "0.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b021d93e26becf5dc7e1b75b1bed1fd93124b374ceb73f43d4d4eafec896a64a" +dependencies = [ + "bytes", + "futures-core", + "http 1.4.0", + "http-body 1.0.1", + "pin-project-lite", +] + +[[package]] +name = "httparse" +version = "1.10.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6dbf3de79e51f3d586ab4cb9d5c3e2c14aa28ed23d180cf89b4df0454a69cc87" + +[[package]] +name = "httpdate" +version = "1.0.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "df3b46402a9d5adb4c86a0cf463f42e19994e3ee891101b1841f30a545cb49a9" + +[[package]] +name = "humantime" +version = "2.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "135b12329e5e3ce057a9f972339ea52bc954fe1e9358ef27f95e89716fbc5424" + +[[package]] +name = "hyper" +version = "0.14.32" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "41dfc780fdec9373c01bae43289ea34c972e40ee3c9f6b3c8801a35f35586ce7" +dependencies = [ + "bytes", + "futures-channel", + "futures-core", + "futures-util", + "h2 0.3.27", + "http 0.2.12", + "http-body 0.4.6", + "httparse", + "httpdate", + "itoa", + "pin-project-lite", + "socket2 0.5.10", + "tokio", + "tower-service", + "tracing", + "want", +] + +[[package]] +name = "hyper" +version = "1.8.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2ab2d4f250c3d7b1c9fcdff1cece94ea4e2dfbec68614f7b87cb205f24ca9d11" +dependencies = [ + "atomic-waker", + "bytes", + "futures-channel", + "futures-core", + "h2 0.4.13", + "http 1.4.0", + "http-body 1.0.1", + "httparse", + "itoa", + "pin-project-lite", + "pin-utils", + "smallvec", + "tokio", + "want", +] + +[[package]] +name = "hyper-rustls" +version = "0.24.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ec3efd23720e2049821a693cbc7e65ea87c72f1c58ff2f9522ff332b1491e590" +dependencies = [ + "futures-util", + "http 0.2.12", + "hyper 0.14.32", + "rustls 0.21.12", + "tokio", + "tokio-rustls 0.24.1", +] + +[[package]] +name = "hyper-rustls" +version = "0.27.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e3c93eb611681b207e1fe55d5a71ecf91572ec8a6705cdb6857f7d8d5242cf58" +dependencies = [ + "http 1.4.0", + "hyper 1.8.1", + "hyper-util", + "rustls 0.23.36", + "rustls-pki-types", + "tokio", + "tokio-rustls 0.26.4", + "tower-service", + "webpki-roots 1.0.5", +] + +[[package]] +name = "hyper-tls" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d6183ddfa99b85da61a140bea0efc93fdf56ceaa041b37d553518030827f9905" +dependencies = [ + "bytes", + "hyper 0.14.32", + "native-tls", + "tokio", + "tokio-native-tls", +] + +[[package]] +name = "hyper-tls" +version = "0.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "70206fc6890eaca9fde8a0bf71caa2ddfc9fe045ac9e5c70df101a7dbde866e0" +dependencies = [ + "bytes", + "http-body-util", + "hyper 1.8.1", + "hyper-util", + "native-tls", + "tokio", + "tokio-native-tls", + "tower-service", +] + +[[package]] +name = "hyper-util" +version = "0.1.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "727805d60e7938b76b826a6ef209eb70eaa1812794f9424d4a4e2d740662df5f" +dependencies = [ + "base64 0.22.1", + "bytes", + "futures-channel", + "futures-core", + "futures-util", + "http 1.4.0", + "http-body 1.0.1", + "hyper 1.8.1", + "ipnet", + "libc", + "percent-encoding", + "pin-project-lite", + "socket2 0.6.2", + "system-configuration 0.6.1", + "tokio", + "tower-service", + "tracing", + "windows-registry", +] + +[[package]] +name = "iana-time-zone" +version = "0.1.65" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e31bc9ad994ba00e440a8aa5c9ef0ec67d5cb5e5cb0cc7f8b744a35b389cc470" +dependencies = [ + "android_system_properties", + "core-foundation-sys", + "iana-time-zone-haiku", + "js-sys", + "log", + "wasm-bindgen", + "windows-core", +] + +[[package]] +name = "iana-time-zone-haiku" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f31827a206f56af32e590ba56d5d2d085f558508192593743f16b2306495269f" +dependencies = [ + "cc", +] + +[[package]] +name = "icu_collections" +version = "2.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4c6b649701667bbe825c3b7e6388cb521c23d88644678e83c0c4d0a621a34b43" +dependencies = [ + "displaydoc", + "potential_utf", + "yoke", + "zerofrom", + "zerovec", +] + +[[package]] +name = "icu_locale_core" +version = "2.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "edba7861004dd3714265b4db54a3c390e880ab658fec5f7db895fae2046b5bb6" +dependencies = [ + "displaydoc", + "litemap", + "tinystr", + "writeable", + "zerovec", +] + +[[package]] +name = "icu_normalizer" +version = "2.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5f6c8828b67bf8908d82127b2054ea1b4427ff0230ee9141c54251934ab1b599" +dependencies = [ + "icu_collections", + "icu_normalizer_data", + "icu_properties", + "icu_provider", + "smallvec", + "zerovec", +] + +[[package]] +name = "icu_normalizer_data" +version = "2.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7aedcccd01fc5fe81e6b489c15b247b8b0690feb23304303a9e560f37efc560a" + +[[package]] +name = "icu_properties" +version = "2.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "020bfc02fe870ec3a66d93e677ccca0562506e5872c650f893269e08615d74ec" +dependencies = [ + "icu_collections", + "icu_locale_core", + "icu_properties_data", + "icu_provider", + "zerotrie", + "zerovec", +] + +[[package]] +name = "icu_properties_data" +version = "2.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "616c294cf8d725c6afcd8f55abc17c56464ef6211f9ed59cccffe534129c77af" + +[[package]] +name = "icu_provider" +version = "2.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "85962cf0ce02e1e0a629cc34e7ca3e373ce20dda4c4d7294bbd0bf1fdb59e614" +dependencies = [ + "displaydoc", + "icu_locale_core", + "writeable", + "yoke", + "zerofrom", + "zerotrie", + "zerovec", +] + +[[package]] +name = "ident_case" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b9e0384b61958566e926dc50660321d12159025e767c18e043daf26b70104c39" + +[[package]] +name = "idna" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3b0875f23caa03898994f6ddc501886a45c7d3d62d04d2d90788d47be1b1e4de" +dependencies = [ + "idna_adapter", + "smallvec", + "utf8_iter", +] + +[[package]] +name = "idna_adapter" +version = "1.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3acae9609540aa318d1bc588455225fb2085b9ed0c4f6bd0d9d5bcd86f1a0344" +dependencies = [ + "icu_normalizer", + "icu_properties", +] + +[[package]] +name = "indexmap" +version = "1.9.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bd070e393353796e801d209ad339e89596eb4c8d430d18ede6a1cced8fafbd99" +dependencies = [ + "autocfg", + "hashbrown 0.12.3", + "serde", +] + +[[package]] +name = "indexmap" +version = "2.13.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7714e70437a7dc3ac8eb7e6f8df75fd8eb422675fc7678aff7364301092b1017" +dependencies = [ + "equivalent", + "hashbrown 0.16.1", + "serde", + "serde_core", +] + +[[package]] +name = "indicatif" +version = "0.17.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "183b3088984b400f4cfac3620d5e076c84da5364016b4f49473de574b2586235" +dependencies = [ + "console", + "number_prefix", + "portable-atomic", + "unicode-width", + "web-time", +] + +[[package]] +name = "inout" +version = "0.1.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "879f10e63c20629ecabbb64a8010319738c66a5cd0c29b02d63d272b03751d01" +dependencies = [ + "generic-array", +] + +[[package]] +name = "ipnet" +version = "2.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "469fb0b9cefa57e3ef31275ee7cacb78f2fdca44e4765491884a2b119d4eb130" + +[[package]] +name = "iri-string" +version = "0.7.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c91338f0783edbd6195decb37bae672fd3b165faffb89bf7b9e6942f8b1a731a" +dependencies = [ + "memchr", + "serde", +] + +[[package]] +name = "itertools" +version = "0.10.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b0fd2260e829bddf4cb6ea802289de2f86d6a7a690192fbe91b3f46e0f2c8473" +dependencies = [ + "either", +] + +[[package]] +name = "itertools" +version = "0.12.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ba291022dbbd398a455acf126c1e341954079855bc60dfdda641363bd6922569" +dependencies = [ + "either", +] + +[[package]] +name = "itertools" +version = "0.13.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "413ee7dfc52ee1a4949ceeb7dbc8a33f2d6c088194d9f922fb8318faf1f01186" +dependencies = [ + "either", +] + +[[package]] +name = "itertools" +version = "0.14.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2b192c782037fadd9cfa75548310488aabdbf3d2da73885b31bd0abd03351285" +dependencies = [ + "either", +] + +[[package]] +name = "itoa" +version = "1.0.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "92ecc6618181def0457392ccd0ee51198e065e016d1d527a7ac1b6dc7c1f09d2" + +[[package]] +name = "jobserver" +version = "0.1.34" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9afb3de4395d6b3e67a780b6de64b51c978ecf11cb9a462c66be7d4ca9039d33" +dependencies = [ + "getrandom 0.3.4", + "libc", +] + +[[package]] +name = "js-sys" +version = "0.3.85" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8c942ebf8e95485ca0d52d97da7c5a2c387d0e7f0ba4c35e93bfcaee045955b3" +dependencies = [ + "once_cell", + "wasm-bindgen", +] + +[[package]] +name = "jsonrpc-core" +version = "18.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "14f7f76aef2d054868398427f6c54943cf3d1caa9a7ec7d0c38d69df97a965eb" +dependencies = [ + "futures", + "futures-executor", + "futures-util", + "log", + "serde", + "serde_derive", + "serde_json", +] + +[[package]] +name = "kaigan" +version = "0.2.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2ba15de5aeb137f0f65aa3bf82187647f1285abfe5b20c80c2c37f7007ad519a" +dependencies = [ + "borsh 0.10.4", + "serde", +] + +[[package]] +name = "keccak" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ecc2af9a1119c51f12a14607e783cb977bde58bc069ff0c3da1095e635d70654" +dependencies = [ + "cpufeatures", +] + +[[package]] +name = "lazy_static" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bbd2bcb4c963f2ddae06a2efc7e9f3591312473c50c6685e1f298068316e66fe" + +[[package]] +name = "libc" +version = "0.2.180" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bcc35a38544a891a5f7c865aca548a982ccb3b8650a5b06d0fd33a10283c56fc" + +[[package]] +name = "libsecp256k1" +version = "0.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c9d220bc1feda2ac231cb78c3d26f27676b8cf82c96971f7aeef3d0cf2797c73" +dependencies = [ + "arrayref", + "base64 0.12.3", + "digest 0.9.0", + "hmac-drbg", + "libsecp256k1-core", + "libsecp256k1-gen-ecmult", + "libsecp256k1-gen-genmult", + "rand 0.7.3", + "serde", + "sha2 0.9.9", + "typenum", +] + +[[package]] +name = "libsecp256k1-core" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d0f6ab710cec28cef759c5f18671a27dae2a5f952cdaaee1d8e2908cb2478a80" +dependencies = [ + "crunchy", + "digest 0.9.0", + "subtle", +] + +[[package]] +name = "libsecp256k1-gen-ecmult" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ccab96b584d38fac86a83f07e659f0deafd0253dc096dab5a36d53efe653c5c3" +dependencies = [ + "libsecp256k1-core", +] + +[[package]] +name = "libsecp256k1-gen-genmult" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "67abfe149395e3aa1c48a2beb32b068e2334402df8181f818d3aee2b304c4f5d" +dependencies = [ + "libsecp256k1-core", +] + +[[package]] +name = "light-account-checks" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f20b8640212dd450e18d452a247e28d8ba6fdce3c713fd8b69f1e95874d1b7ab" +dependencies = [ + "solana-account-info", + "solana-msg", + "solana-program-error", + "solana-pubkey", + "solana-sysvar", + "thiserror 2.0.18", +] + +[[package]] +name = "light-anchor-spl" +version = "0.31.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9e1c802e3de6de4bb03bc9e9bacbba8aa94823a083046aaf0ef275b1321984e3" +dependencies = [ + "anchor-lang", + "spl-associated-token-account 6.0.0", + "spl-pod", + "spl-token 7.0.0", + "spl-token-2022 6.0.0", + "spl-token-group-interface 0.5.0", + "spl-token-metadata-interface 0.6.0", +] + +[[package]] +name = "light-array-map" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9bdd13b18028ac9d80d0a987551c0dad7fe81be8140e87cc9d568b80f3728203" +dependencies = [ + "tinyvec", +] + +[[package]] +name = "light-batched-merkle-tree" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "01e838c523b49371097f948cd5662bd9a89d9dca037fb61fd38001e99f485702" +dependencies = [ + "aligned-sized", + "borsh 0.10.4", + "light-account-checks", + "light-bloom-filter", + "light-compressed-account", + "light-hasher", + "light-macros", + "light-merkle-tree-metadata", + "light-verifier", + "light-zero-copy", + "solana-account-info", + "solana-msg", + "solana-program-error", + "solana-pubkey", + "solana-sysvar", + "thiserror 2.0.18", + "zerocopy", +] + +[[package]] +name = "light-bloom-filter" +version = "0.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "380b8cf734ccf5fbc1f5fed8e5308b57ebde6774d9304c167bcb0de2854412d8" +dependencies = [ + "bitvec", + "num-bigint 0.4.6", + "solana-nostd-keccak", + "solana-program-error", + "thiserror 2.0.18", +] + +[[package]] +name = "light-bounded-vec" +version = "2.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "58cfa375d028164719e3ffef93d2e5c27855cc8a5bb5bf257b868d17c12a3e66" +dependencies = [ + "bytemuck", + "memoffset", + "solana-program-error", + "thiserror 1.0.69", +] + +[[package]] +name = "light-client" +version = "0.19.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "33203f596d48d28d1cb67dee5762b151e0073207a5e828c63ec68f9efb9a5ee8" +dependencies = [ + "anchor-lang", + "async-trait", + "base64 0.13.1", + "borsh 0.10.4", + "bs58", + "futures", + "lazy_static", + "light-compressed-account", + "light-compressible", + "light-concurrent-merkle-tree", + "light-event", + "light-hasher", + "light-indexed-merkle-tree", + "light-merkle-tree-metadata", + "light-prover-client", + "light-sdk", + "light-token", + "light-token-interface", + "litesvm", + "num-bigint 0.4.6", + "photon-api", + "rand 0.8.5", + "smallvec", + "solana-account", + "solana-account-decoder-client-types", + "solana-address-lookup-table-interface", + "solana-banks-client", + "solana-clock", + "solana-commitment-config", + "solana-compute-budget-interface", + "solana-hash", + "solana-instruction", + "solana-keypair", + "solana-message", + "solana-program-error", + "solana-pubkey", + "solana-rpc-client", + "solana-rpc-client-api", + "solana-signature", + "solana-transaction", + "solana-transaction-error", + "solana-transaction-status-client-types", + "spl-pod", + "spl-token-2022-interface", + "thiserror 2.0.18", + "tokio", + "tracing", +] + +[[package]] +name = "light-compressed-account" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a9c3537bbad9df133ca97fc191b164bba93dba1de4da01a92d979ef63f8ce106" +dependencies = [ + "anchor-lang", + "borsh 0.10.4", + "bytemuck", + "light-hasher", + "light-macros", + "light-poseidon 0.3.0", + "light-program-profiler", + "light-zero-copy", + "solana-msg", + "solana-program-error", + "solana-pubkey", + "thiserror 2.0.18", + "tinyvec", + "zerocopy", +] + +[[package]] +name = "light-compressible" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "00d1dc14271907009f4ca23ae99c49279f7d2acc5a83f0f8d7362834b37e2e16" +dependencies = [ + "aligned-sized", + "anchor-lang", + "borsh 0.10.4", + "bytemuck", + "light-account-checks", + "light-compressed-account", + "light-hasher", + "light-macros", + "light-program-profiler", + "light-zero-copy", + "pinocchio-pubkey", + "solana-pubkey", + "solana-rent", + "thiserror 2.0.18", + "zerocopy", +] + +[[package]] +name = "light-concurrent-merkle-tree" +version = "5.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "db96f47253a0907aaa46dac15cecb27b5510130e48da0b36690dcd2e99a6d558" +dependencies = [ + "borsh 0.10.4", + "light-bounded-vec", + "light-hasher", + "memoffset", + "solana-program-error", + "thiserror 2.0.18", +] + +[[package]] +name = "light-event" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a4bae725ee1d4d944d442ac0bfdf2031b1b2379c04c7e39c475277aaaea08fb1" +dependencies = [ + "borsh 0.10.4", + "light-compressed-account", + "light-hasher", + "light-zero-copy", + "thiserror 2.0.18", +] + +[[package]] +name = "light-hasher" +version = "5.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c822662e6e109bac0e132a43fd52a4ef684811245a794e048cf9cda001e934c8" +dependencies = [ + "ark-bn254 0.5.0", + "ark-ff 0.5.0", + "borsh 0.10.4", + "light-poseidon 0.3.0", + "num-bigint 0.4.6", + "sha2 0.10.9", + "sha3", + "solana-program-error", + "thiserror 2.0.18", + "tinyvec", +] + +[[package]] +name = "light-indexed-array" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0f14f984030d86b6f07bd8f5ae04e2c40fcd0c3bdfcc7a291fff1ed59c9e6554" +dependencies = [ + "light-hasher", + "num-bigint 0.4.6", + "num-traits", + "thiserror 2.0.18", +] + +[[package]] +name = "light-indexed-merkle-tree" +version = "5.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0824755289075f28de2820fc7d4ec4e6b9e99d404e033c07338b91cce8c71fb8" +dependencies = [ + "light-bounded-vec", + "light-concurrent-merkle-tree", + "light-hasher", + "light-merkle-tree-reference", + "num-bigint 0.4.6", + "num-traits", + "solana-program-error", + "thiserror 2.0.18", +] + +[[package]] +name = "light-instruction-decoder" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b7f4bd98e842f21b754ec28020a56de37cb0b1089952ef24340d21c2d5afd5c5" +dependencies = [ + "borsh 0.10.4", + "bs58", + "light-compressed-account", + "light-instruction-decoder-derive", + "light-sdk-types", + "light-token-interface", + "serde", + "solana-instruction", + "solana-pubkey", + "solana-signature", + "tabled", +] + +[[package]] +name = "light-instruction-decoder-derive" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2035d04a0a1590da05634efcac149a2ac852565e28c9a55bd07a6620c0e90bff" +dependencies = [ + "bs58", + "darling", + "heck 0.5.0", + "proc-macro2", + "quote", + "sha2 0.10.9", + "syn 2.0.114", +] + +[[package]] +name = "light-macros" +version = "2.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "179ac51cadc1d0ca047b4d6265a7cc245ca3affc16a20a2749585aa6464d39c2" +dependencies = [ + "bs58", + "proc-macro2", + "quote", + "solana-pubkey", + "syn 2.0.114", +] + +[[package]] +name = "light-merkle-tree-metadata" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "15c2e63e8345dcfb80efac69136fdcc6c36a12354675aca6e3daf13ec40422d1" +dependencies = [ + "anchor-lang", + "borsh 0.10.4", + "bytemuck", + "light-compressed-account", + "solana-msg", + "solana-program-error", + "solana-sysvar", + "thiserror 2.0.18", + "zerocopy", +] + +[[package]] +name = "light-merkle-tree-reference" +version = "4.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d8d480f62ca32b38a6231bbc5310d693f91d6b5bdcc18bb13c2d9aab7a1c90e8" +dependencies = [ + "light-hasher", + "light-indexed-array", + "num-bigint 0.4.6", + "num-traits", + "thiserror 2.0.18", +] + +[[package]] +name = "light-poseidon" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3c9a85a9752c549ceb7578064b4ed891179d20acd85f27318573b64d2d7ee7ee" +dependencies = [ + "ark-bn254 0.4.0", + "ark-ff 0.4.2", + "num-bigint 0.4.6", + "thiserror 1.0.69", +] + +[[package]] +name = "light-poseidon" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "39e3d87542063daaccbfecd78b60f988079b6ec4e089249658b9455075c78d42" +dependencies = [ + "ark-bn254 0.5.0", + "ark-ff 0.5.0", + "num-bigint 0.4.6", + "thiserror 1.0.69", +] + +[[package]] +name = "light-profiler-macro" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0a8be18fe4de58a6f754caa74a3fbc6d8a758a26f1f3c24d5b0f5b55df5f5408" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.114", +] + +[[package]] +name = "light-program-profiler" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d1d345871581aebd8825868a3f08410290aa1cdddcb189ca7f7e588f61d79fcf" +dependencies = [ + "light-profiler-macro", +] + +[[package]] +name = "light-program-test" +version = "0.19.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e85916a9da34a44971e1a30badaf04cb75213fbfa9f61a139ea6ebd0f021bdde" +dependencies = [ + "anchor-lang", + "async-trait", + "base64 0.13.1", + "borsh 0.10.4", + "bs58", + "bytemuck", + "chrono", + "light-client", + "light-compressed-account", + "light-compressible", + "light-event", + "light-hasher", + "light-indexed-array", + "light-indexed-merkle-tree", + "light-instruction-decoder", + "light-merkle-tree-metadata", + "light-merkle-tree-reference", + "light-prover-client", + "light-sdk", + "light-sdk-types", + "light-token", + "light-token-interface", + "light-zero-copy", + "litesvm", + "log", + "num-bigint 0.4.6", + "num-traits", + "photon-api", + "rand 0.8.5", + "reqwest 0.12.28", + "serde", + "serde_json", + "solana-account", + "solana-banks-client", + "solana-compute-budget", + "solana-instruction", + "solana-pubkey", + "solana-rpc-client-api", + "solana-sdk", + "solana-transaction", + "solana-transaction-status", + "solana-transaction-status-client-types", + "spl-token-2022 7.0.0", + "tabled", + "tokio", +] + +[[package]] +name = "light-prover-client" +version = "6.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cd2195f4573628a8aaca37504cde1b1903b8ed20e2706acbad875b7d41acbeab" +dependencies = [ + "ark-bn254 0.5.0", + "ark-serialize 0.5.0", + "ark-std 0.5.0", + "light-compressed-account", + "light-hasher", + "light-indexed-array", + "light-sparse-merkle-tree", + "num-bigint 0.4.6", + "num-traits", + "reqwest 0.11.27", + "serde", + "serde_json", + "solana-bn254", + "thiserror 2.0.18", + "tokio", + "tracing", +] + +[[package]] +name = "light-sdk" +version = "0.19.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c7f523c64a6fcdafe6df81d647560770529896f2707be8ffcf048d909b7e2b30" +dependencies = [ + "anchor-lang", + "bincode", + "borsh 0.10.4", + "light-account-checks", + "light-compressed-account", + "light-compressible", + "light-hasher", + "light-macros", + "light-sdk-macros", + "light-sdk-types", + "light-zero-copy", + "num-bigint 0.4.6", + "solana-account-info", + "solana-clock", + "solana-cpi", + "solana-instruction", + "solana-loader-v3-interface", + "solana-msg", + "solana-program", + "solana-program-error", + "solana-pubkey", + "solana-system-interface", + "solana-sysvar", + "thiserror 2.0.18", +] + +[[package]] +name = "light-sdk-macros" +version = "0.19.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d3d12bb13b84df21a4871dc0837aafc0b48464d3e9b17e2773c0719b6cc724c5" +dependencies = [ + "darling", + "light-hasher", + "light-sdk-types", + "proc-macro2", + "quote", + "solana-pubkey", + "syn 2.0.114", +] + +[[package]] +name = "light-sdk-types" +version = "0.19.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1d8153b27d057ded7b2b6bbd78c643e3f20bd9a9718ca1a8d4183169ccd812c3" +dependencies = [ + "anchor-lang", + "borsh 0.10.4", + "light-account-checks", + "light-compressed-account", + "light-hasher", + "light-macros", + "solana-msg", + "thiserror 2.0.18", +] + +[[package]] +name = "light-sparse-merkle-tree" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4251e79b6c63f4946572dcfd7623680ad0f9e0efe1a761a944733333c5645063" +dependencies = [ + "light-hasher", + "light-indexed-array", + "num-bigint 0.4.6", + "num-traits", + "thiserror 2.0.18", +] + +[[package]] +name = "light-token" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "71fd2e8ca6d7d70c77658010e1ae6ed6d4fe23e29054964b053f51e5c4676e49" +dependencies = [ + "anchor-lang", + "arrayvec", + "borsh 0.10.4", + "light-account-checks", + "light-batched-merkle-tree", + "light-compressed-account", + "light-compressible", + "light-macros", + "light-program-profiler", + "light-sdk", + "light-sdk-macros", + "light-sdk-types", + "light-token-interface", + "light-token-types", + "light-zero-copy", + "solana-account-info", + "solana-cpi", + "solana-instruction", + "solana-msg", + "solana-program-error", + "solana-pubkey", + "spl-pod", + "thiserror 2.0.18", +] + +[[package]] +name = "light-token-interface" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f46decebc2a13ec984e2ba7f1e691c0d46b9061875c6bdd12636b7c100a60e6c" +dependencies = [ + "aligned-sized", + "anchor-lang", + "borsh 0.10.4", + "bytemuck", + "light-array-map", + "light-compressed-account", + "light-compressible", + "light-hasher", + "light-macros", + "light-program-profiler", + "light-zero-copy", + "pinocchio", + "pinocchio-pubkey", + "solana-account-info", + "solana-pubkey", + "spl-pod", + "spl-token-2022 7.0.0", + "thiserror 2.0.18", + "tinyvec", + "zerocopy", +] + +[[package]] +name = "light-token-minter" +version = "0.1.0" +dependencies = [ + "anchor-lang", + "blake3", + "light-anchor-spl", + "light-client", + "light-hasher", + "light-program-test", + "light-sdk", + "light-token", + "solana-account-info", + "solana-instruction", + "solana-keypair", + "solana-msg", + "solana-program", + "solana-program-error", + "solana-pubkey", + "solana-sdk", + "solana-signer", + "spl-pod", + "spl-token 7.0.0", + "spl-token-2022 7.0.0", + "tokio", +] + +[[package]] +name = "light-token-types" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "411481fe2e04b1241235c2572480c153c5669507e227f5e3327057b0d2ba5734" +dependencies = [ + "anchor-lang", + "borsh 0.10.4", + "light-account-checks", + "light-compressed-account", + "light-macros", + "light-sdk-types", + "solana-msg", + "thiserror 2.0.18", +] + +[[package]] +name = "light-verifier" +version = "8.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ecba4c14ac08b078a9d84033d628b12bb2577141f405140d506bacd392a830bc" +dependencies = [ + "groth16-solana", + "light-compressed-account", + "thiserror 2.0.18", +] + +[[package]] +name = "light-zero-copy" +version = "0.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a5621fb515e14af46148699c0b65334aabe230a1d2cbd06736ccc7a408c8a4af" +dependencies = [ + "light-zero-copy-derive", + "solana-program-error", + "zerocopy", +] + +[[package]] +name = "light-zero-copy-derive" +version = "0.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "41c46425e5c7ab5203ff5c86ae2615b169cca55f9283f5f60f5dd74143be6934" +dependencies = [ + "lazy_static", + "proc-macro2", + "quote", + "syn 2.0.114", +] + +[[package]] +name = "linux-raw-sys" +version = "0.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "df1d3c3b53da64cf5760482273a98e575c651a67eec7f77df96b5b642de8f039" + +[[package]] +name = "litemap" +version = "0.8.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6373607a59f0be73a39b6fe456b8192fcc3585f602af20751600e974dd455e77" + +[[package]] +name = "litesvm" +version = "0.7.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "23bca37ac374948b348e29c74b324dc36f18bbbd1ccf80e2046d967521cbd143" +dependencies = [ + "agave-feature-set", + "agave-precompiles", + "agave-reserved-account-keys", + "ansi_term", + "bincode", + "indexmap 2.13.0", + "itertools 0.14.0", + "log", + "solana-account", + "solana-address-lookup-table-interface", + "solana-bpf-loader-program", + "solana-builtins", + "solana-clock", + "solana-compute-budget", + "solana-compute-budget-instruction", + "solana-epoch-rewards", + "solana-epoch-schedule", + "solana-fee", + "solana-fee-structure", + "solana-hash", + "solana-instruction", + "solana-instructions-sysvar", + "solana-keypair", + "solana-last-restart-slot", + "solana-loader-v3-interface", + "solana-loader-v4-interface", + "solana-log-collector", + "solana-message", + "solana-native-token 3.0.0", + "solana-nonce", + "solana-nonce-account", + "solana-precompile-error", + "solana-program-error", + "solana-program-runtime", + "solana-pubkey", + "solana-rent", + "solana-sdk-ids", + "solana-sha256-hasher", + "solana-signature", + "solana-signer", + "solana-slot-hashes", + "solana-slot-history", + "solana-stake-interface", + "solana-svm-callback", + "solana-svm-transaction", + "solana-system-interface", + "solana-system-program", + "solana-sysvar", + "solana-sysvar-id", + "solana-timings", + "solana-transaction", + "solana-transaction-context", + "solana-transaction-error", + "solana-vote-program", + "thiserror 2.0.18", +] + +[[package]] +name = "lock_api" +version = "0.4.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "224399e74b87b5f3557511d98dff8b14089b3dadafcab6bb93eab67d3aace965" +dependencies = [ + "scopeguard", +] + +[[package]] +name = "log" +version = "0.4.29" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5e5032e24019045c762d3c0f28f5b6b8bbf38563a65908389bf7978758920897" + +[[package]] +name = "lru-slab" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "112b39cec0b298b6c1999fee3e31427f74f676e4cb9879ed1a121b43661a4154" + +[[package]] +name = "memchr" +version = "2.7.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f52b00d39961fc5b2736ea853c9cc86238e165017a493d1d5c8eac6bdc4cc273" + +[[package]] +name = "memmap2" +version = "0.5.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "83faa42c0a078c393f6b29d5db232d8be22776a891f8f56e5284faee4a20b327" +dependencies = [ + "libc", +] + +[[package]] +name = "memoffset" +version = "0.9.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "488016bfae457b036d996092f6cb448677611ce4449e970ceaf42695203f218a" +dependencies = [ + "autocfg", +] + +[[package]] +name = "merlin" +version = "3.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "58c38e2799fc0978b65dfff8023ec7843e2330bb462f19198840b34b6582397d" +dependencies = [ + "byteorder", + "keccak", + "rand_core 0.6.4", + "zeroize", +] + +[[package]] +name = "mime" +version = "0.3.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6877bb514081ee2a7ff5ef9de3281f14a4dd4bceac4c09388074a6b5df8a139a" + +[[package]] +name = "mime_guess" +version = "2.0.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f7c44f8e672c00fe5308fa235f821cb4198414e1c77935c1ab6948d3fd78550e" +dependencies = [ + "mime", + "unicase", +] + +[[package]] +name = "miniz_oxide" +version = "0.8.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1fa76a2c86f704bdb222d66965fb3d63269ce38518b83cb0575fca855ebb6316" +dependencies = [ + "adler2", + "simd-adler32", +] + +[[package]] +name = "mio" +version = "1.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a69bcab0ad47271a0234d9422b131806bf3968021e5dc9328caf2d4cd58557fc" +dependencies = [ + "libc", + "wasi 0.11.1+wasi-snapshot-preview1", + "windows-sys 0.61.2", +] + +[[package]] +name = "mpl-token-metadata" +version = "5.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "046f0779684ec348e2759661361c8798d79021707b1392cb49f3b5eb911340ff" +dependencies = [ + "borsh 0.10.4", + "num-derive 0.3.3", + "num-traits", + "solana-program", + "thiserror 1.0.69", +] + +[[package]] +name = "native-tls" +version = "0.2.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "87de3442987e9dbec73158d5c715e7ad9072fda936bb03d19d7fa10e00520f0e" +dependencies = [ + "libc", + "log", + "openssl", + "openssl-probe", + "openssl-sys", + "schannel", + "security-framework", + "security-framework-sys", + "tempfile", +] + +[[package]] +name = "num" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b8536030f9fea7127f841b45bb6243b27255787fb4eb83958aa1ef9d2fdc0c36" +dependencies = [ + "num-bigint 0.2.6", + "num-complex", + "num-integer", + "num-iter", + "num-rational", + "num-traits", +] + +[[package]] +name = "num-bigint" +version = "0.2.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "090c7f9998ee0ff65aa5b723e4009f7b217707f1fb5ea551329cc4d6231fb304" +dependencies = [ + "autocfg", + "num-integer", + "num-traits", +] + +[[package]] +name = "num-bigint" +version = "0.4.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a5e44f723f1133c9deac646763579fdb3ac745e418f2a7af9cd0c431da1f20b9" +dependencies = [ + "num-integer", + "num-traits", + "serde", +] + +[[package]] +name = "num-complex" +version = "0.2.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b6b19411a9719e753aff12e5187b74d60d3dc449ec3f4dc21e3989c3f554bc95" +dependencies = [ + "autocfg", + "num-traits", +] + +[[package]] +name = "num-conv" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "51d515d32fb182ee37cda2ccdcb92950d6a3c2893aa280e540671c2cd0f3b1d9" + +[[package]] +name = "num-derive" +version = "0.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "876a53fff98e03a936a674b29568b0e605f06b29372c2489ff4de23f1949743d" +dependencies = [ + "proc-macro2", + "quote", + "syn 1.0.109", +] + +[[package]] +name = "num-derive" +version = "0.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ed3955f1a9c7c0c15e092f9c887db08b1fc683305fdf6eb6684f22555355e202" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.114", +] + +[[package]] +name = "num-integer" +version = "0.1.46" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7969661fd2958a5cb096e56c8e1ad0444ac2bbcd0061bd28660485a44879858f" +dependencies = [ + "num-traits", +] + +[[package]] +name = "num-iter" +version = "0.1.45" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1429034a0490724d0075ebb2bc9e875d6503c3cf69e235a8941aa757d83ef5bf" +dependencies = [ + "autocfg", + "num-integer", + "num-traits", +] + +[[package]] +name = "num-rational" +version = "0.2.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5c000134b5dbf44adc5cb772486d335293351644b801551abe8f75c84cfa4aef" +dependencies = [ + "autocfg", + "num-bigint 0.2.6", + "num-integer", + "num-traits", +] + +[[package]] +name = "num-traits" +version = "0.2.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "071dfc062690e90b734c0b2273ce72ad0ffa95f0c74596bc250dcfd960262841" +dependencies = [ + "autocfg", +] + +[[package]] +name = "num_enum" +version = "0.7.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b1207a7e20ad57b847bbddc6776b968420d38292bbfe2089accff5e19e82454c" +dependencies = [ + "num_enum_derive", + "rustversion", +] + +[[package]] +name = "num_enum_derive" +version = "0.7.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ff32365de1b6743cb203b710788263c44a03de03802daf96092f2da4fe6ba4d7" +dependencies = [ + "proc-macro-crate 3.4.0", + "proc-macro2", + "quote", + "syn 2.0.114", +] + +[[package]] +name = "number_prefix" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "830b246a0e5f20af87141b25c173cd1b609bd7779a4617d6ec582abaf90870f3" + +[[package]] +name = "once_cell" +version = "1.21.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "42f5e15c9953c5e4ccceeb2e7382a716482c34515315f7b03532b8b4e8393d2d" + +[[package]] +name = "opaque-debug" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c08d65885ee38876c4f86fa503fb49d7b507c2b62552df7c70b2fce627e06381" + +[[package]] +name = "openssl" +version = "0.10.75" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "08838db121398ad17ab8531ce9de97b244589089e290a384c900cb9ff7434328" +dependencies = [ + "bitflags 2.10.0", + "cfg-if", + "foreign-types", + "libc", + "once_cell", + "openssl-macros", + "openssl-sys", +] + +[[package]] +name = "openssl-macros" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a948666b637a0f465e8564c73e89d4dde00d72d4d473cc972f390fc3dcee7d9c" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.114", +] + +[[package]] +name = "openssl-probe" +version = "0.1.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d05e27ee213611ffe7d6348b942e8f942b37114c00cc03cec254295a4a17852e" + +[[package]] +name = "openssl-src" +version = "300.5.5+3.5.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3f1787d533e03597a7934fd0a765f0d28e94ecc5fb7789f8053b1e699a56f709" +dependencies = [ + "cc", +] + +[[package]] +name = "openssl-sys" +version = "0.9.111" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "82cab2d520aa75e3c58898289429321eb788c3106963d0dc886ec7a5f4adc321" +dependencies = [ + "cc", + "libc", + "openssl-src", + "pkg-config", + "vcpkg", +] + +[[package]] +name = "opentelemetry" +version = "0.17.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6105e89802af13fdf48c49d7646d3b533a70e536d818aae7e78ba0433d01acb8" +dependencies = [ + "async-trait", + "crossbeam-channel", + "futures-channel", + "futures-executor", + "futures-util", + "js-sys", + "lazy_static", + "percent-encoding", + "pin-project", + "rand 0.8.5", + "thiserror 1.0.69", +] + +[[package]] +name = "papergrid" +version = "0.17.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6978128c8b51d8f4080631ceb2302ab51e32cc6e8615f735ee2f83fd269ae3f1" +dependencies = [ + "bytecount", + "fnv", + "unicode-width", +] + +[[package]] +name = "parking_lot" +version = "0.12.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "93857453250e3077bd71ff98b6a65ea6621a19bb0f559a85248955ac12c45a1a" +dependencies = [ + "lock_api", + "parking_lot_core", +] + +[[package]] +name = "parking_lot_core" +version = "0.9.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2621685985a2ebf1c516881c026032ac7deafcda1a2c9b7850dc81e3dfcb64c1" +dependencies = [ + "cfg-if", + "libc", + "redox_syscall", + "smallvec", + "windows-link", +] + +[[package]] +name = "paste" +version = "1.0.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "57c0d7b74b563b49d38dae00a0c37d4d6de9b432382b2892f0574ddcae73fd0a" + +[[package]] +name = "pbkdf2" +version = "0.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "83a0692ec44e4cf1ef28ca317f14f8f07da2d95ec3fa01f86e4467b725e60917" +dependencies = [ + "digest 0.10.7", +] + +[[package]] +name = "percent-encoding" +version = "2.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9b4f627cb1b25917193a259e49bdad08f671f8d9708acfd5fe0a8c1455d87220" + +[[package]] +name = "percentage" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2fd23b938276f14057220b707937bcb42fa76dda7560e57a2da30cb52d557937" +dependencies = [ + "num", +] + +[[package]] +name = "photon-api" +version = "0.54.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e572dba0c255f5b8176f15b9e849330d915a8927804f7f9702d5bbbc70e4a1ad" +dependencies = [ + "reqwest 0.12.28", + "serde", + "serde_derive", + "serde_json", + "serde_with", + "url", + "uuid", +] + +[[package]] +name = "pin-project" +version = "1.1.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "677f1add503faace112b9f1373e43e9e054bfdd22ff1a63c1bc485eaec6a6a8a" +dependencies = [ + "pin-project-internal", +] + +[[package]] +name = "pin-project-internal" +version = "1.1.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6e918e4ff8c4549eb882f14b3a4bc8c8bc93de829416eacf579f1207a8fbf861" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.114", +] + +[[package]] +name = "pin-project-lite" +version = "0.2.16" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3b3cff922bd51709b605d9ead9aa71031d81447142d828eb4a6eba76fe619f9b" + +[[package]] +name = "pin-utils" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" + +[[package]] +name = "pinocchio" +version = "0.9.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5b971851087bc3699b001954ad02389d50c41405ece3548cbcafc88b3e20017a" + +[[package]] +name = "pinocchio-pubkey" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cb0225638cadcbebae8932cb7f49cb5da7c15c21beb19f048f05a5ca7d93f065" +dependencies = [ + "five8_const", + "pinocchio", + "sha2-const-stable", +] + +[[package]] +name = "pkg-config" +version = "0.3.32" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7edddbd0b52d732b21ad9a5fab5c704c14cd949e5e9a1ec5929a24fded1b904c" + +[[package]] +name = "polyval" +version = "0.6.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9d1fe60d06143b2430aa532c94cfe9e29783047f06c0d7fd359a9a51b729fa25" +dependencies = [ + "cfg-if", + "cpufeatures", + "opaque-debug", + "universal-hash", +] + +[[package]] +name = "portable-atomic" +version = "1.13.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f89776e4d69bb58bc6993e99ffa1d11f228b839984854c7daeb5d37f87cbe950" + +[[package]] +name = "potential_utf" +version = "0.1.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b73949432f5e2a09657003c25bca5e19a0e9c84f8058ca374f49e0ebe605af77" +dependencies = [ + "zerovec", +] + +[[package]] +name = "powerfmt" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "439ee305def115ba05938db6eb1644ff94165c5ab5e9420d1c1bcedbba909391" + +[[package]] +name = "ppv-lite86" +version = "0.2.21" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "85eae3c4ed2f50dcfe72643da4befc30deadb458a9b590d720cde2f2b1e97da9" +dependencies = [ + "zerocopy", +] + +[[package]] +name = "proc-macro-crate" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1d6ea3c4595b96363c13943497db34af4460fb474a95c43f4446ad341b8c9785" +dependencies = [ + "toml 0.5.11", +] + +[[package]] +name = "proc-macro-crate" +version = "3.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "219cb19e96be00ab2e37d6e299658a0cfa83e52429179969b0f0121b4ac46983" +dependencies = [ + "toml_edit 0.23.10+spec-1.0.0", +] + +[[package]] +name = "proc-macro-error-attr2" +version = "2.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "96de42df36bb9bba5542fe9f1a054b8cc87e172759a1868aa05c1f3acc89dfc5" +dependencies = [ + "proc-macro2", + "quote", +] + +[[package]] +name = "proc-macro-error2" +version = "2.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "11ec05c52be0a07b08061f7dd003e7d7092e0472bc731b4af7bb1ef876109802" +dependencies = [ + "proc-macro-error-attr2", + "proc-macro2", + "quote", + "syn 2.0.114", +] + +[[package]] +name = "proc-macro2" +version = "1.0.106" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8fd00f0bb2e90d81d1044c2b32617f68fcb9fa3bb7640c23e9c748e53fb30934" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "qstring" +version = "0.7.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d464fae65fff2680baf48019211ce37aaec0c78e9264c84a3e484717f965104e" +dependencies = [ + "percent-encoding", +] + +[[package]] +name = "qualifier_attr" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9e2e25ee72f5b24d773cae88422baddefff7714f97aab68d96fe2b6fc4a28fb2" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.114", +] + +[[package]] +name = "quinn" +version = "0.11.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b9e20a958963c291dc322d98411f541009df2ced7b5a4f2bd52337638cfccf20" +dependencies = [ + "bytes", + "cfg_aliases", + "pin-project-lite", + "quinn-proto", + "quinn-udp", + "rustc-hash", + "rustls 0.23.36", + "socket2 0.6.2", + "thiserror 2.0.18", + "tokio", + "tracing", + "web-time", +] + +[[package]] +name = "quinn-proto" +version = "0.11.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f1906b49b0c3bc04b5fe5d86a77925ae6524a19b816ae38ce1e426255f1d8a31" +dependencies = [ + "bytes", + "getrandom 0.3.4", + "lru-slab", + "rand 0.9.2", + "ring", + "rustc-hash", + "rustls 0.23.36", + "rustls-pki-types", + "slab", + "thiserror 2.0.18", + "tinyvec", + "tracing", + "web-time", +] + +[[package]] +name = "quinn-udp" +version = "0.5.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "addec6a0dcad8a8d96a771f815f0eaf55f9d1805756410b39f5fa81332574cbd" +dependencies = [ + "cfg_aliases", + "libc", + "once_cell", + "socket2 0.6.2", + "tracing", + "windows-sys 0.60.2", +] + +[[package]] +name = "quote" +version = "1.0.44" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "21b2ebcf727b7760c461f091f9f0f539b77b8e87f2fd88131e7f1b433b3cece4" +dependencies = [ + "proc-macro2", +] + +[[package]] +name = "r-efi" +version = "5.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "69cdb34c158ceb288df11e18b4bd39de994f6657d83847bdffdbd7f346754b0f" + +[[package]] +name = "radium" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dc33ff2d4973d518d823d61aa239014831e521c75da58e3df4840d3f47749d09" + +[[package]] +name = "rand" +version = "0.7.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6a6b1679d49b24bbfe0c803429aa1874472f50d9b363131f0e89fc356b544d03" +dependencies = [ + "getrandom 0.1.16", + "libc", + "rand_chacha 0.2.2", + "rand_core 0.5.1", + "rand_hc", +] + +[[package]] +name = "rand" +version = "0.8.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "34af8d1a0e25924bc5b7c43c079c942339d8f0a8b57c39049bef581b46327404" +dependencies = [ + "libc", + "rand_chacha 0.3.1", + "rand_core 0.6.4", +] + +[[package]] +name = "rand" +version = "0.9.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6db2770f06117d490610c7488547d543617b21bfa07796d7a12f6f1bd53850d1" +dependencies = [ + "rand_chacha 0.9.0", + "rand_core 0.9.5", +] + +[[package]] +name = "rand_chacha" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f4c8ed856279c9737206bf725bf36935d8666ead7aa69b52be55af369d193402" +dependencies = [ + "ppv-lite86", + "rand_core 0.5.1", +] + +[[package]] +name = "rand_chacha" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e6c10a63a0fa32252be49d21e7709d4d4baf8d231c2dbce1eaa8141b9b127d88" +dependencies = [ + "ppv-lite86", + "rand_core 0.6.4", +] + +[[package]] +name = "rand_chacha" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d3022b5f1df60f26e1ffddd6c66e8aa15de382ae63b3a0c1bfc0e4d3e3f325cb" +dependencies = [ + "ppv-lite86", + "rand_core 0.9.5", +] + +[[package]] +name = "rand_core" +version = "0.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "90bde5296fc891b0cef12a6d03ddccc162ce7b2aff54160af9338f8d40df6d19" +dependencies = [ + "getrandom 0.1.16", +] + +[[package]] +name = "rand_core" +version = "0.6.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c" +dependencies = [ + "getrandom 0.2.17", +] + +[[package]] +name = "rand_core" +version = "0.9.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "76afc826de14238e6e8c374ddcc1fa19e374fd8dd986b0d2af0d02377261d83c" +dependencies = [ + "getrandom 0.3.4", +] + +[[package]] +name = "rand_hc" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ca3129af7b92a17112d59ad498c6f81eaf463253766b90396d39ea7a39d6613c" +dependencies = [ + "rand_core 0.5.1", +] + +[[package]] +name = "rayon" +version = "1.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "368f01d005bf8fd9b1206fb6fa653e6c4a81ceb1466406b81792d87c5677a58f" +dependencies = [ + "either", + "rayon-core", +] + +[[package]] +name = "rayon-core" +version = "1.13.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "22e18b0f0062d30d4230b2e85ff77fdfe4326feb054b9783a3460d8435c8ab91" +dependencies = [ + "crossbeam-deque", + "crossbeam-utils", +] + +[[package]] +name = "redox_syscall" +version = "0.5.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ed2bf2547551a7053d6fdfafda3f938979645c44812fbfcda098faae3f1a362d" +dependencies = [ + "bitflags 2.10.0", +] + +[[package]] +name = "ref-cast" +version = "1.0.25" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f354300ae66f76f1c85c5f84693f0ce81d747e2c3f21a45fef496d89c960bf7d" +dependencies = [ + "ref-cast-impl", +] + +[[package]] +name = "ref-cast-impl" +version = "1.0.25" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b7186006dcb21920990093f30e3dea63b7d6e977bf1256be20c3563a5db070da" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.114", +] + +[[package]] +name = "regex" +version = "1.12.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "843bc0191f75f3e22651ae5f1e72939ab2f72a4bc30fa80a066bd66edefc24d4" +dependencies = [ + "aho-corasick", + "memchr", + "regex-automata", + "regex-syntax", +] + +[[package]] +name = "regex-automata" +version = "0.4.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5276caf25ac86c8d810222b3dbb938e512c55c6831a10f3e6ed1c93b84041f1c" +dependencies = [ + "aho-corasick", + "memchr", + "regex-syntax", +] + +[[package]] +name = "regex-syntax" +version = "0.8.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7a2d987857b319362043e95f5353c0535c1f58eec5336fdfcf626430af7def58" + +[[package]] +name = "reqwest" +version = "0.11.27" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dd67538700a17451e7cba03ac727fb961abb7607553461627b97de0b89cf4a62" +dependencies = [ + "base64 0.21.7", + "bytes", + "encoding_rs", + "futures-core", + "futures-util", + "h2 0.3.27", + "http 0.2.12", + "http-body 0.4.6", + "hyper 0.14.32", + "hyper-rustls 0.24.2", + "hyper-tls 0.5.0", + "ipnet", + "js-sys", + "log", + "mime", + "native-tls", + "once_cell", + "percent-encoding", + "pin-project-lite", + "rustls 0.21.12", + "rustls-pemfile", + "serde", + "serde_json", + "serde_urlencoded", + "sync_wrapper 0.1.2", + "system-configuration 0.5.1", + "tokio", + "tokio-native-tls", + "tokio-rustls 0.24.1", + "tower-service", + "url", + "wasm-bindgen", + "wasm-bindgen-futures", + "web-sys", + "webpki-roots 0.25.4", + "winreg", +] + +[[package]] +name = "reqwest" +version = "0.12.28" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "eddd3ca559203180a307f12d114c268abf583f59b03cb906fd0b3ff8646c1147" +dependencies = [ + "base64 0.22.1", + "bytes", + "encoding_rs", + "futures-channel", + "futures-core", + "futures-util", + "h2 0.4.13", + "http 1.4.0", + "http-body 1.0.1", + "http-body-util", + "hyper 1.8.1", + "hyper-rustls 0.27.7", + "hyper-tls 0.6.0", + "hyper-util", + "js-sys", + "log", + "mime", + "mime_guess", + "native-tls", + "percent-encoding", + "pin-project-lite", + "quinn", + "rustls 0.23.36", + "rustls-pki-types", + "serde", + "serde_json", + "serde_urlencoded", + "sync_wrapper 1.0.2", + "tokio", + "tokio-native-tls", + "tokio-rustls 0.26.4", + "tower", + "tower-http", + "tower-service", + "url", + "wasm-bindgen", + "wasm-bindgen-futures", + "web-sys", + "webpki-roots 1.0.5", +] + +[[package]] +name = "reqwest-middleware" +version = "0.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "57f17d28a6e6acfe1733fe24bcd30774d13bffa4b8a22535b4c8c98423088d4e" +dependencies = [ + "anyhow", + "async-trait", + "http 1.4.0", + "reqwest 0.12.28", + "serde", + "thiserror 1.0.69", + "tower-service", +] + +[[package]] +name = "ring" +version = "0.17.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a4689e6c2294d81e88dc6261c768b63bc4fcdb852be6d1352498b114f61383b7" +dependencies = [ + "cc", + "cfg-if", + "getrandom 0.2.17", + "libc", + "untrusted", + "windows-sys 0.52.0", +] + +[[package]] +name = "rustc-demangle" +version = "0.1.27" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b50b8869d9fc858ce7266cce0194bd74df58b9d0e3f6df3a9fc8eb470d95c09d" + +[[package]] +name = "rustc-hash" +version = "2.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "357703d41365b4b27c590e3ed91eabb1b663f07c4c084095e60cbed4362dff0d" + +[[package]] +name = "rustc_version" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cfcb3a22ef46e85b45de6ee7e79d063319ebb6594faafcf1c225ea92ab6e9b92" +dependencies = [ + "semver", +] + +[[package]] +name = "rustix" +version = "1.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "146c9e247ccc180c1f61615433868c99f3de3ae256a30a43b49f67c2d9171f34" +dependencies = [ + "bitflags 2.10.0", + "errno", + "libc", + "linux-raw-sys", + "windows-sys 0.61.2", +] + +[[package]] +name = "rustls" +version = "0.21.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3f56a14d1f48b391359b22f731fd4bd7e43c97f3c50eee276f3aa09c94784d3e" +dependencies = [ + "log", + "ring", + "rustls-webpki 0.101.7", + "sct", +] + +[[package]] +name = "rustls" +version = "0.23.36" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c665f33d38cea657d9614f766881e4d510e0eda4239891eea56b4cadcf01801b" +dependencies = [ + "once_cell", + "ring", + "rustls-pki-types", + "rustls-webpki 0.103.9", + "subtle", + "zeroize", +] + +[[package]] +name = "rustls-pemfile" +version = "1.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1c74cae0a4cf6ccbbf5f359f08efdf8ee7e1dc532573bf0db71968cb56b1448c" +dependencies = [ + "base64 0.21.7", +] + +[[package]] +name = "rustls-pki-types" +version = "1.14.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "be040f8b0a225e40375822a563fa9524378b9d63112f53e19ffff34df5d33fdd" +dependencies = [ + "web-time", + "zeroize", +] + +[[package]] +name = "rustls-webpki" +version = "0.101.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8b6275d1ee7a1cd780b64aca7726599a1dbc893b1e64144529e55c3c2f745765" +dependencies = [ + "ring", + "untrusted", +] + +[[package]] +name = "rustls-webpki" +version = "0.103.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d7df23109aa6c1567d1c575b9952556388da57401e4ace1d15f79eedad0d8f53" +dependencies = [ + "ring", + "rustls-pki-types", + "untrusted", +] + +[[package]] +name = "rustversion" +version = "1.0.22" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b39cdef0fa800fc44525c84ccb54a029961a8215f9619753635a9c0d2538d46d" + +[[package]] +name = "ryu" +version = "1.0.22" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a50f4cf475b65d88e057964e0e9bb1f0aa9bbb2036dc65c64596b42932536984" + +[[package]] +name = "schannel" +version = "0.1.28" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "891d81b926048e76efe18581bf793546b4c0eaf8448d72be8de2bbee5fd166e1" +dependencies = [ + "windows-sys 0.61.2", +] + +[[package]] +name = "schemars" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4cd191f9397d57d581cddd31014772520aa448f65ef991055d7f61582c65165f" +dependencies = [ + "dyn-clone", + "ref-cast", + "serde", + "serde_json", +] + +[[package]] +name = "schemars" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "54e910108742c57a770f492731f99be216a52fadd361b06c8fb59d74ccc267d2" +dependencies = [ + "dyn-clone", + "ref-cast", + "serde", + "serde_json", +] + +[[package]] +name = "scopeguard" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49" + +[[package]] +name = "sct" +version = "0.7.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "da046153aa2352493d6cb7da4b6e5c0c057d8a1d0a9aa8560baffdd945acd414" +dependencies = [ + "ring", + "untrusted", +] + +[[package]] +name = "security-framework" +version = "2.11.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "897b2245f0b511c87893af39b033e5ca9cce68824c4d7e7630b5a1d339658d02" +dependencies = [ + "bitflags 2.10.0", + "core-foundation", + "core-foundation-sys", + "libc", + "security-framework-sys", +] + +[[package]] +name = "security-framework-sys" +version = "2.15.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cc1f0cbffaac4852523ce30d8bd3c5cdc873501d96ff467ca09b6767bb8cd5c0" +dependencies = [ + "core-foundation-sys", + "libc", +] + +[[package]] +name = "semver" +version = "1.0.27" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d767eb0aabc880b29956c35734170f26ed551a859dbd361d140cdbeca61ab1e2" + +[[package]] +name = "serde" +version = "1.0.228" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9a8e94ea7f378bd32cbbd37198a4a91436180c5bb472411e48b5ec2e2124ae9e" +dependencies = [ + "serde_core", + "serde_derive", +] + +[[package]] +name = "serde-big-array" +version = "0.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "11fc7cc2c76d73e0f27ee52abbd64eec84d46f370c88371120433196934e4b7f" +dependencies = [ + "serde", +] + +[[package]] +name = "serde_bytes" +version = "0.11.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a5d440709e79d88e51ac01c4b72fc6cb7314017bb7da9eeff678aa94c10e3ea8" +dependencies = [ + "serde", + "serde_core", +] + +[[package]] +name = "serde_core" +version = "1.0.228" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "41d385c7d4ca58e59fc732af25c3983b67ac852c1a25000afe1175de458b67ad" +dependencies = [ + "serde_derive", +] + +[[package]] +name = "serde_derive" +version = "1.0.228" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d540f220d3187173da220f885ab66608367b6574e925011a9353e4badda91d79" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.114", +] + +[[package]] +name = "serde_json" +version = "1.0.149" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "83fc039473c5595ace860d8c4fafa220ff474b3fc6bfdb4293327f1a37e94d86" +dependencies = [ + "itoa", + "memchr", + "serde", + "serde_core", + "zmij", +] + +[[package]] +name = "serde_spanned" +version = "0.6.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bf41e0cfaf7226dca15e8197172c295a782857fcb97fad1808a166870dee75a3" +dependencies = [ + "serde", +] + +[[package]] +name = "serde_urlencoded" +version = "0.7.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d3491c14715ca2294c4d6a88f15e84739788c1d030eed8c110436aafdaa2f3fd" +dependencies = [ + "form_urlencoded", + "itoa", + "ryu", + "serde", +] + +[[package]] +name = "serde_with" +version = "3.16.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4fa237f2807440d238e0364a218270b98f767a00d3dada77b1c53ae88940e2e7" +dependencies = [ + "base64 0.22.1", + "chrono", + "hex", + "indexmap 1.9.3", + "indexmap 2.13.0", + "schemars 0.9.0", + "schemars 1.2.0", + "serde_core", + "serde_json", + "serde_with_macros", + "time", +] + +[[package]] +name = "serde_with_macros" +version = "3.16.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "52a8e3ca0ca629121f70ab50f95249e5a6f925cc0f6ffe8256c45b728875706c" +dependencies = [ + "darling", + "proc-macro2", + "quote", + "syn 2.0.114", +] + +[[package]] +name = "sha2" +version = "0.9.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4d58a1e1bf39749807d89cf2d98ac2dfa0ff1cb3faa38fbb64dd88ac8013d800" +dependencies = [ + "block-buffer 0.9.0", + "cfg-if", + "cpufeatures", + "digest 0.9.0", + "opaque-debug", +] + +[[package]] +name = "sha2" +version = "0.10.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a7507d819769d01a365ab707794a4084392c824f54a7a6a7862f8c3d0892b283" +dependencies = [ + "cfg-if", + "cpufeatures", + "digest 0.10.7", +] + +[[package]] +name = "sha2-const-stable" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5f179d4e11094a893b82fff208f74d448a7512f99f5a0acbd5c679b705f83ed9" + +[[package]] +name = "sha3" +version = "0.10.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "75872d278a8f37ef87fa0ddbda7802605cb18344497949862c0d4dcb291eba60" +dependencies = [ + "digest 0.10.7", + "keccak", +] + +[[package]] +name = "sharded-slab" +version = "0.1.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f40ca3c46823713e0d4209592e8d6e826aa57e928f09752619fc696c499637f6" +dependencies = [ + "lazy_static", +] + +[[package]] +name = "shared-test-utils" +version = "0.1.0" +dependencies = [ + "anchor-lang", + "anchor-spl", + "light-client", + "light-hasher", + "light-program-test", + "light-sdk", + "light-token", + "light-token-minter", + "solana-instruction", + "solana-keypair", + "solana-pubkey", + "solana-sdk", + "solana-signer", + "spl-pod", + "spl-token-2022 7.0.0", + "tokio", +] + +[[package]] +name = "shlex" +version = "1.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0fda2ff0d084019ba4d7c6f371c95d8fd75ce3524c3cb8fb653a3023f6323e64" + +[[package]] +name = "signal-hook" +version = "0.3.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d881a16cf4426aa584979d30bd82cb33429027e42122b169753d6ef1085ed6e2" +dependencies = [ + "libc", + "signal-hook-registry", +] + +[[package]] +name = "signal-hook-registry" +version = "1.4.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c4db69cba1110affc0e9f7bcd48bbf87b3f4fc7c61fc9155afd4c469eb3d6c1b" +dependencies = [ + "errno", + "libc", +] + +[[package]] +name = "signature" +version = "1.6.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "74233d3b3b2f6d4b006dc19dee745e73e2a6bfb6f93607cd3b02bd5b00797d7c" + +[[package]] +name = "simd-adler32" +version = "0.3.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e320a6c5ad31d271ad523dcf3ad13e2767ad8b1cb8f047f75a8aeaf8da139da2" + +[[package]] +name = "siphasher" +version = "0.3.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "38b58827f4464d87d377d175e90bf58eb00fd8716ff0a62f80356b5e61555d0d" + +[[package]] +name = "slab" +version = "0.4.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7a2ae44ef20feb57a68b23d846850f861394c2e02dc425a50098ae8c90267589" + +[[package]] +name = "smallvec" +version = "1.15.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "67b1b7a3b5fe4f1376887184045fcf45c69e92af734b7aaddc05fb777b6fbd03" + +[[package]] +name = "socket2" +version = "0.5.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e22376abed350d73dd1cd119b57ffccad95b4e585a7cda43e286245ce23c0678" +dependencies = [ + "libc", + "windows-sys 0.52.0", +] + +[[package]] +name = "socket2" +version = "0.6.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "86f4aa3ad99f2088c990dfa82d367e19cb29268ed67c574d10d0a4bfe71f07e0" +dependencies = [ + "libc", + "windows-sys 0.60.2", +] + +[[package]] +name = "solana-account" +version = "2.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0f949fe4edaeaea78c844023bfc1c898e0b1f5a100f8a8d2d0f85d0a7b090258" +dependencies = [ + "bincode", + "serde", + "serde_bytes", + "serde_derive", + "solana-account-info", + "solana-clock", + "solana-instruction", + "solana-pubkey", + "solana-sdk-ids", + "solana-sysvar", +] + +[[package]] +name = "solana-account-decoder" +version = "2.3.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ba71c97fa4d85ce4a1e0e79044ad0406c419382be598c800202903a7688ce71a" +dependencies = [ + "Inflector", + "base64 0.22.1", + "bincode", + "bs58", + "bv", + "serde", + "serde_derive", + "serde_json", + "solana-account", + "solana-account-decoder-client-types", + "solana-address-lookup-table-interface", + "solana-clock", + "solana-config-program-client", + "solana-epoch-schedule", + "solana-fee-calculator", + "solana-instruction", + "solana-loader-v3-interface", + "solana-nonce", + "solana-program-option", + "solana-program-pack", + "solana-pubkey", + "solana-rent", + "solana-sdk-ids", + "solana-slot-hashes", + "solana-slot-history", + "solana-stake-interface", + "solana-sysvar", + "solana-vote-interface", + "spl-generic-token", + "spl-token 8.0.0", + "spl-token-2022 8.0.1", + "spl-token-group-interface 0.6.0", + "spl-token-metadata-interface 0.7.0", + "thiserror 2.0.18", + "zstd", +] + +[[package]] +name = "solana-account-decoder-client-types" +version = "2.3.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5519e8343325b707f17fbed54fcefb325131b692506d0af9e08a539d15e4f8cf" +dependencies = [ + "base64 0.22.1", + "bs58", + "serde", + "serde_derive", + "serde_json", + "solana-account", + "solana-pubkey", + "zstd", +] + +[[package]] +name = "solana-account-info" +version = "2.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c8f5152a288ef1912300fc6efa6c2d1f9bb55d9398eb6c72326360b8063987da" +dependencies = [ + "bincode", + "serde", + "solana-program-error", + "solana-program-memory", + "solana-pubkey", +] + +[[package]] +name = "solana-address-lookup-table-interface" +version = "2.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d1673f67efe870b64a65cb39e6194be5b26527691ce5922909939961a6e6b395" +dependencies = [ + "bincode", + "bytemuck", + "serde", + "serde_derive", + "solana-clock", + "solana-instruction", + "solana-pubkey", + "solana-sdk-ids", + "solana-slot-hashes", +] + +[[package]] +name = "solana-atomic-u64" +version = "2.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d52e52720efe60465b052b9e7445a01c17550666beec855cce66f44766697bc2" +dependencies = [ + "parking_lot", +] + +[[package]] +name = "solana-banks-client" +version = "2.3.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "68548570c38a021c724b5aa0112f45a54bdf7ff1b041a042848e034a95a96994" +dependencies = [ + "borsh 1.6.0", + "futures", + "solana-account", + "solana-banks-interface", + "solana-clock", + "solana-commitment-config", + "solana-hash", + "solana-message", + "solana-program-pack", + "solana-pubkey", + "solana-rent", + "solana-signature", + "solana-sysvar", + "solana-transaction", + "solana-transaction-context", + "solana-transaction-error", + "tarpc", + "thiserror 2.0.18", + "tokio", + "tokio-serde", +] + +[[package]] +name = "solana-banks-interface" +version = "2.3.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a6d90edc435bf488ef7abed4dcb1f94fa1970102cbabb25688f58417fd948286" +dependencies = [ + "serde", + "serde_derive", + "solana-account", + "solana-clock", + "solana-commitment-config", + "solana-hash", + "solana-message", + "solana-pubkey", + "solana-signature", + "solana-transaction", + "solana-transaction-context", + "solana-transaction-error", + "tarpc", +] + +[[package]] +name = "solana-big-mod-exp" +version = "2.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "75db7f2bbac3e62cfd139065d15bcda9e2428883ba61fc8d27ccb251081e7567" +dependencies = [ + "num-bigint 0.4.6", + "num-traits", + "solana-define-syscall", +] + +[[package]] +name = "solana-bincode" +version = "2.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "19a3787b8cf9c9fe3dd360800e8b70982b9e5a8af9e11c354b6665dd4a003adc" +dependencies = [ + "bincode", + "serde", + "solana-instruction", +] + +[[package]] +name = "solana-blake3-hasher" +version = "2.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a1a0801e25a1b31a14494fc80882a036be0ffd290efc4c2d640bfcca120a4672" +dependencies = [ + "blake3", + "solana-define-syscall", + "solana-hash", + "solana-sanitize", +] + +[[package]] +name = "solana-bn254" +version = "2.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4420f125118732833f36facf96a27e7b78314b2d642ba07fa9ffdacd8d79e243" +dependencies = [ + "ark-bn254 0.4.0", + "ark-ec 0.4.2", + "ark-ff 0.4.2", + "ark-serialize 0.4.2", + "bytemuck", + "solana-define-syscall", + "thiserror 2.0.18", +] + +[[package]] +name = "solana-borsh" +version = "2.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "718333bcd0a1a7aed6655aa66bef8d7fb047944922b2d3a18f49cbc13e73d004" +dependencies = [ + "borsh 0.10.4", + "borsh 1.6.0", +] + +[[package]] +name = "solana-bpf-loader-program" +version = "2.3.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b5aec57dcd80d0f6879956cad28854a6eebaed6b346ce56908ea01a9f36ab259" +dependencies = [ + "bincode", + "libsecp256k1", + "num-traits", + "qualifier_attr", + "scopeguard", + "solana-account", + "solana-account-info", + "solana-big-mod-exp", + "solana-bincode", + "solana-blake3-hasher", + "solana-bn254", + "solana-clock", + "solana-cpi", + "solana-curve25519", + "solana-hash", + "solana-instruction", + "solana-keccak-hasher", + "solana-loader-v3-interface", + "solana-loader-v4-interface", + "solana-log-collector", + "solana-measure", + "solana-packet", + "solana-poseidon", + "solana-program-entrypoint", + "solana-program-runtime", + "solana-pubkey", + "solana-sbpf", + "solana-sdk-ids", + "solana-secp256k1-recover", + "solana-sha256-hasher", + "solana-stable-layout", + "solana-svm-feature-set", + "solana-system-interface", + "solana-sysvar", + "solana-sysvar-id", + "solana-timings", + "solana-transaction-context", + "solana-type-overrides", + "thiserror 2.0.18", +] + +[[package]] +name = "solana-builtins" +version = "2.3.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6d61a31b63b52b0d268cbcd56c76f50314867d7f8e07a0f2c62ee7c9886e07b2" +dependencies = [ + "agave-feature-set", + "solana-bpf-loader-program", + "solana-compute-budget-program", + "solana-hash", + "solana-loader-v4-program", + "solana-program-runtime", + "solana-pubkey", + "solana-sdk-ids", + "solana-stake-program", + "solana-system-program", + "solana-vote-program", + "solana-zk-elgamal-proof-program", + "solana-zk-token-proof-program", +] + +[[package]] +name = "solana-builtins-default-costs" +version = "2.3.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2ca69a299a6c969b18ea381a02b40c9e4dda04b2af0d15a007c1184c82163bbb" +dependencies = [ + "agave-feature-set", + "ahash", + "log", + "solana-bpf-loader-program", + "solana-compute-budget-program", + "solana-loader-v4-program", + "solana-pubkey", + "solana-sdk-ids", + "solana-stake-program", + "solana-system-program", + "solana-vote-program", +] + +[[package]] +name = "solana-client-traits" +version = "2.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "83f0071874e629f29e0eb3dab8a863e98502ac7aba55b7e0df1803fc5cac72a7" +dependencies = [ + "solana-account", + "solana-commitment-config", + "solana-epoch-info", + "solana-hash", + "solana-instruction", + "solana-keypair", + "solana-message", + "solana-pubkey", + "solana-signature", + "solana-signer", + "solana-system-interface", + "solana-transaction", + "solana-transaction-error", +] + +[[package]] +name = "solana-clock" +version = "2.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1bb482ab70fced82ad3d7d3d87be33d466a3498eb8aa856434ff3c0dfc2e2e31" +dependencies = [ + "serde", + "serde_derive", + "solana-sdk-ids", + "solana-sdk-macro", + "solana-sysvar-id", +] + +[[package]] +name = "solana-cluster-type" +version = "2.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7ace9fea2daa28354d107ea879cff107181d85cd4e0f78a2bedb10e1a428c97e" +dependencies = [ + "serde", + "serde_derive", + "solana-hash", +] + +[[package]] +name = "solana-commitment-config" +version = "2.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ac49c4dde3edfa832de1697e9bcdb7c3b3f7cb7a1981b7c62526c8bb6700fb73" +dependencies = [ + "serde", + "serde_derive", +] + +[[package]] +name = "solana-compute-budget" +version = "2.3.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9f4fc63bc2276a1618ca0bfc609da7448534ecb43a1cb387cdf9eaa2dc7bc272" +dependencies = [ + "solana-fee-structure", + "solana-program-runtime", +] + +[[package]] +name = "solana-compute-budget-instruction" +version = "2.3.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "503d94430f6d3c5ac1e1fa6a342c1c714d5b03c800999e7b6cf235298f0b5341" +dependencies = [ + "agave-feature-set", + "log", + "solana-borsh", + "solana-builtins-default-costs", + "solana-compute-budget", + "solana-compute-budget-interface", + "solana-instruction", + "solana-packet", + "solana-pubkey", + "solana-sdk-ids", + "solana-svm-transaction", + "solana-transaction-error", + "thiserror 2.0.18", +] + +[[package]] +name = "solana-compute-budget-interface" +version = "2.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8432d2c4c22d0499aa06d62e4f7e333f81777b3d7c96050ae9e5cb71a8c3aee4" +dependencies = [ + "borsh 1.6.0", + "serde", + "serde_derive", + "solana-instruction", + "solana-sdk-ids", +] + +[[package]] +name = "solana-compute-budget-program" +version = "2.3.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "072b02beed1862c6b7b7a8a699379594c4470a9371c711856a0a3c266dcf57e5" +dependencies = [ + "solana-program-runtime", +] + +[[package]] +name = "solana-config-program-client" +version = "0.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "53aceac36f105fd4922e29b4f0c1f785b69d7b3e7e387e384b8985c8e0c3595e" +dependencies = [ + "bincode", + "borsh 0.10.4", + "kaigan", + "serde", + "solana-program", +] + +[[package]] +name = "solana-cpi" +version = "2.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8dc71126edddc2ba014622fc32d0f5e2e78ec6c5a1e0eb511b85618c09e9ea11" +dependencies = [ + "solana-account-info", + "solana-define-syscall", + "solana-instruction", + "solana-program-error", + "solana-pubkey", + "solana-stable-layout", +] + +[[package]] +name = "solana-curve25519" +version = "2.3.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "eae4261b9a8613d10e77ac831a8fa60b6fa52b9b103df46d641deff9f9812a23" +dependencies = [ + "bytemuck", + "bytemuck_derive", + "curve25519-dalek 4.1.3", + "solana-define-syscall", + "subtle", + "thiserror 2.0.18", +] + +[[package]] +name = "solana-decode-error" +version = "2.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8c781686a18db2f942e70913f7ca15dc120ec38dcab42ff7557db2c70c625a35" +dependencies = [ + "num-traits", +] + +[[package]] +name = "solana-define-syscall" +version = "2.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2ae3e2abcf541c8122eafe9a625d4d194b4023c20adde1e251f94e056bb1aee2" + +[[package]] +name = "solana-derivation-path" +version = "2.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "939756d798b25c5ec3cca10e06212bdca3b1443cb9bb740a38124f58b258737b" +dependencies = [ + "derivation-path", + "qstring", + "uriparse", +] + +[[package]] +name = "solana-ed25519-program" +version = "2.2.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a1feafa1691ea3ae588f99056f4bdd1293212c7ece28243d7da257c443e84753" +dependencies = [ + "bytemuck", + "bytemuck_derive", + "ed25519-dalek", + "solana-feature-set", + "solana-instruction", + "solana-precompile-error", + "solana-sdk-ids", +] + +[[package]] +name = "solana-epoch-info" +version = "2.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "90ef6f0b449290b0b9f32973eefd95af35b01c5c0c34c569f936c34c5b20d77b" +dependencies = [ + "serde", + "serde_derive", +] + +[[package]] +name = "solana-epoch-rewards" +version = "2.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "86b575d3dd323b9ea10bb6fe89bf6bf93e249b215ba8ed7f68f1a3633f384db7" +dependencies = [ + "serde", + "serde_derive", + "solana-hash", + "solana-sdk-ids", + "solana-sdk-macro", + "solana-sysvar-id", +] + +[[package]] +name = "solana-epoch-rewards-hasher" +version = "2.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "96c5fd2662ae7574810904585fd443545ed2b568dbd304b25a31e79ccc76e81b" +dependencies = [ + "siphasher", + "solana-hash", + "solana-pubkey", +] + +[[package]] +name = "solana-epoch-schedule" +version = "2.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3fce071fbddecc55d727b1d7ed16a629afe4f6e4c217bc8d00af3b785f6f67ed" +dependencies = [ + "serde", + "serde_derive", + "solana-sdk-ids", + "solana-sdk-macro", + "solana-sysvar-id", +] + +[[package]] +name = "solana-example-mocks" +version = "2.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "84461d56cbb8bb8d539347151e0525b53910102e4bced875d49d5139708e39d3" +dependencies = [ + "serde", + "serde_derive", + "solana-address-lookup-table-interface", + "solana-clock", + "solana-hash", + "solana-instruction", + "solana-keccak-hasher", + "solana-message", + "solana-nonce", + "solana-pubkey", + "solana-sdk-ids", + "solana-system-interface", + "thiserror 2.0.18", +] + +[[package]] +name = "solana-feature-gate-interface" +version = "2.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "43f5c5382b449e8e4e3016fb05e418c53d57782d8b5c30aa372fc265654b956d" +dependencies = [ + "bincode", + "serde", + "serde_derive", + "solana-account", + "solana-account-info", + "solana-instruction", + "solana-program-error", + "solana-pubkey", + "solana-rent", + "solana-sdk-ids", + "solana-system-interface", +] + +[[package]] +name = "solana-feature-set" +version = "2.2.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "93b93971e289d6425f88e6e3cb6668c4b05df78b3c518c249be55ced8efd6b6d" +dependencies = [ + "ahash", + "lazy_static", + "solana-epoch-schedule", + "solana-hash", + "solana-pubkey", + "solana-sha256-hasher", +] + +[[package]] +name = "solana-fee" +version = "2.3.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "16beda37597046b1edd1cea6fa7caaed033c091f99ec783fe59c82828bc2adb8" +dependencies = [ + "agave-feature-set", + "solana-fee-structure", + "solana-svm-transaction", +] + +[[package]] +name = "solana-fee-calculator" +version = "2.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d89bc408da0fb3812bc3008189d148b4d3e08252c79ad810b245482a3f70cd8d" +dependencies = [ + "log", + "serde", + "serde_derive", +] + +[[package]] +name = "solana-fee-structure" +version = "2.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "33adf673581c38e810bf618f745bf31b683a0a4a4377682e6aaac5d9a058dd4e" +dependencies = [ + "serde", + "serde_derive", + "solana-message", + "solana-native-token 2.3.0", +] + +[[package]] +name = "solana-genesis-config" +version = "2.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b3725085d47b96d37fef07a29d78d2787fc89a0b9004c66eed7753d1e554989f" +dependencies = [ + "bincode", + "chrono", + "memmap2", + "serde", + "serde_derive", + "solana-account", + "solana-clock", + "solana-cluster-type", + "solana-epoch-schedule", + "solana-fee-calculator", + "solana-hash", + "solana-inflation", + "solana-keypair", + "solana-logger", + "solana-poh-config", + "solana-pubkey", + "solana-rent", + "solana-sdk-ids", + "solana-sha256-hasher", + "solana-shred-version", + "solana-signer", + "solana-time-utils", +] + +[[package]] +name = "solana-hard-forks" +version = "2.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b6c28371f878e2ead55611d8ba1b5fb879847156d04edea13693700ad1a28baf" +dependencies = [ + "serde", + "serde_derive", +] + +[[package]] +name = "solana-hash" +version = "2.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b5b96e9f0300fa287b545613f007dfe20043d7812bee255f418c1eb649c93b63" +dependencies = [ + "borsh 1.6.0", + "bytemuck", + "bytemuck_derive", + "five8", + "js-sys", + "serde", + "serde_derive", + "solana-atomic-u64", + "solana-sanitize", + "wasm-bindgen", +] + +[[package]] +name = "solana-inflation" +version = "2.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "23eef6a09eb8e568ce6839573e4966850e85e9ce71e6ae1a6c930c1c43947de3" +dependencies = [ + "serde", + "serde_derive", +] + +[[package]] +name = "solana-instruction" +version = "2.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bab5682934bd1f65f8d2c16f21cb532526fcc1a09f796e2cacdb091eee5774ad" +dependencies = [ + "bincode", + "borsh 1.6.0", + "getrandom 0.2.17", + "js-sys", + "num-traits", + "serde", + "serde_derive", + "serde_json", + "solana-define-syscall", + "solana-pubkey", + "wasm-bindgen", +] + +[[package]] +name = "solana-instructions-sysvar" +version = "2.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e0e85a6fad5c2d0c4f5b91d34b8ca47118fc593af706e523cdbedf846a954f57" +dependencies = [ + "bitflags 2.10.0", + "solana-account-info", + "solana-instruction", + "solana-program-error", + "solana-pubkey", + "solana-sanitize", + "solana-sdk-ids", + "solana-serialize-utils", + "solana-sysvar-id", +] + +[[package]] +name = "solana-keccak-hasher" +version = "2.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c7aeb957fbd42a451b99235df4942d96db7ef678e8d5061ef34c9b34cae12f79" +dependencies = [ + "sha3", + "solana-define-syscall", + "solana-hash", + "solana-sanitize", +] + +[[package]] +name = "solana-keypair" +version = "2.2.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bd3f04aa1a05c535e93e121a95f66e7dcccf57e007282e8255535d24bf1e98bb" +dependencies = [ + "ed25519-dalek", + "ed25519-dalek-bip32", + "five8", + "rand 0.7.3", + "solana-derivation-path", + "solana-pubkey", + "solana-seed-derivable", + "solana-seed-phrase", + "solana-signature", + "solana-signer", + "wasm-bindgen", +] + +[[package]] +name = "solana-last-restart-slot" +version = "2.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4a6360ac2fdc72e7463565cd256eedcf10d7ef0c28a1249d261ec168c1b55cdd" +dependencies = [ + "serde", + "serde_derive", + "solana-sdk-ids", + "solana-sdk-macro", + "solana-sysvar-id", +] + +[[package]] +name = "solana-loader-v2-interface" +version = "2.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d8ab08006dad78ae7cd30df8eea0539e207d08d91eaefb3e1d49a446e1c49654" +dependencies = [ + "serde", + "serde_bytes", + "serde_derive", + "solana-instruction", + "solana-pubkey", + "solana-sdk-ids", +] + +[[package]] +name = "solana-loader-v3-interface" +version = "5.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6f7162a05b8b0773156b443bccd674ea78bb9aa406325b467ea78c06c99a63a2" +dependencies = [ + "serde", + "serde_bytes", + "serde_derive", + "solana-instruction", + "solana-pubkey", + "solana-sdk-ids", + "solana-system-interface", +] + +[[package]] +name = "solana-loader-v4-interface" +version = "2.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "706a777242f1f39a83e2a96a2a6cb034cb41169c6ecbee2cf09cb873d9659e7e" +dependencies = [ + "serde", + "serde_bytes", + "serde_derive", + "solana-instruction", + "solana-pubkey", + "solana-sdk-ids", + "solana-system-interface", +] + +[[package]] +name = "solana-loader-v4-program" +version = "2.3.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a6ab01855d851fa2fb6034b0d48de33d77d5c5f5fb4b0353d8e4a934cc03d48a" +dependencies = [ + "log", + "qualifier_attr", + "solana-account", + "solana-bincode", + "solana-bpf-loader-program", + "solana-instruction", + "solana-loader-v3-interface", + "solana-loader-v4-interface", + "solana-log-collector", + "solana-measure", + "solana-packet", + "solana-program-runtime", + "solana-pubkey", + "solana-sbpf", + "solana-sdk-ids", + "solana-transaction-context", + "solana-type-overrides", +] + +[[package]] +name = "solana-log-collector" +version = "2.3.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9d945b1cf5bf7cbd6f5b78795beda7376370c827640df43bb2a1c17b492dc106" +dependencies = [ + "log", +] + +[[package]] +name = "solana-logger" +version = "2.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "db8e777ec1afd733939b532a42492d888ec7c88d8b4127a5d867eb45c6eb5cd5" +dependencies = [ + "env_logger", + "lazy_static", + "libc", + "log", + "signal-hook", +] + +[[package]] +name = "solana-measure" +version = "2.3.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "11dcd67cd2ae6065e494b64e861e0498d046d95a61cbbf1ae3d58be1ea0f42ed" + +[[package]] +name = "solana-message" +version = "2.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1796aabce376ff74bf89b78d268fa5e683d7d7a96a0a4e4813ec34de49d5314b" +dependencies = [ + "bincode", + "blake3", + "lazy_static", + "serde", + "serde_derive", + "solana-bincode", + "solana-hash", + "solana-instruction", + "solana-pubkey", + "solana-sanitize", + "solana-sdk-ids", + "solana-short-vec", + "solana-system-interface", + "solana-transaction-error", + "wasm-bindgen", +] + +[[package]] +name = "solana-metrics" +version = "2.3.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0375159d8460f423d39e5103dcff6e07796a5ec1850ee1fcfacfd2482a8f34b5" +dependencies = [ + "crossbeam-channel", + "gethostname", + "log", + "reqwest 0.12.28", + "solana-cluster-type", + "solana-sha256-hasher", + "solana-time-utils", + "thiserror 2.0.18", +] + +[[package]] +name = "solana-msg" +version = "2.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f36a1a14399afaabc2781a1db09cb14ee4cc4ee5c7a5a3cfcc601811379a8092" +dependencies = [ + "solana-define-syscall", +] + +[[package]] +name = "solana-native-token" +version = "2.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "61515b880c36974053dd499c0510066783f0cc6ac17def0c7ef2a244874cf4a9" + +[[package]] +name = "solana-native-token" +version = "3.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ae8dd4c280dca9d046139eb5b7a5ac9ad10403fbd64964c7d7571214950d758f" + +[[package]] +name = "solana-nonce" +version = "2.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "703e22eb185537e06204a5bd9d509b948f0066f2d1d814a6f475dafb3ddf1325" +dependencies = [ + "serde", + "serde_derive", + "solana-fee-calculator", + "solana-hash", + "solana-pubkey", + "solana-sha256-hasher", +] + +[[package]] +name = "solana-nonce-account" +version = "2.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cde971a20b8dbf60144d6a84439dda86b5466e00e2843091fe731083cda614da" +dependencies = [ + "solana-account", + "solana-hash", + "solana-nonce", + "solana-sdk-ids", +] + +[[package]] +name = "solana-nostd-keccak" +version = "0.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d8ced70920435b1baa58f76e6f84bbc1110ddd1d6161ec76b6d731ae8431e9c4" +dependencies = [ + "sha3", +] + +[[package]] +name = "solana-offchain-message" +version = "2.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b526398ade5dea37f1f147ce55dae49aa017a5d7326606359b0445ca8d946581" +dependencies = [ + "num_enum", + "solana-hash", + "solana-packet", + "solana-pubkey", + "solana-sanitize", + "solana-sha256-hasher", + "solana-signature", + "solana-signer", +] + +[[package]] +name = "solana-packet" +version = "2.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "004f2d2daf407b3ec1a1ca5ec34b3ccdfd6866dd2d3c7d0715004a96e4b6d127" +dependencies = [ + "bincode", + "bitflags 2.10.0", + "cfg_eval", + "serde", + "serde_derive", + "serde_with", +] + +[[package]] +name = "solana-poh-config" +version = "2.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d650c3b4b9060082ac6b0efbbb66865089c58405bfb45de449f3f2b91eccee75" +dependencies = [ + "serde", + "serde_derive", +] + +[[package]] +name = "solana-poseidon" +version = "2.3.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cbac4eb90016eeb1d37fa36e592d3a64421510c49666f81020736611c319faff" +dependencies = [ + "ark-bn254 0.4.0", + "light-poseidon 0.2.0", + "solana-define-syscall", + "thiserror 2.0.18", +] + +[[package]] +name = "solana-precompile-error" +version = "2.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4d87b2c1f5de77dfe2b175ee8dd318d196aaca4d0f66f02842f80c852811f9f8" +dependencies = [ + "num-traits", + "solana-decode-error", +] + +[[package]] +name = "solana-precompiles" +version = "2.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "36e92768a57c652edb0f5d1b30a7d0bc64192139c517967c18600debe9ae3832" +dependencies = [ + "lazy_static", + "solana-ed25519-program", + "solana-feature-set", + "solana-message", + "solana-precompile-error", + "solana-pubkey", + "solana-sdk-ids", + "solana-secp256k1-program", + "solana-secp256r1-program", +] + +[[package]] +name = "solana-presigner" +version = "2.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "81a57a24e6a4125fc69510b6774cd93402b943191b6cddad05de7281491c90fe" +dependencies = [ + "solana-pubkey", + "solana-signature", + "solana-signer", +] + +[[package]] +name = "solana-program" +version = "2.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "98eca145bd3545e2fbb07166e895370576e47a00a7d824e325390d33bf467210" +dependencies = [ + "bincode", + "blake3", + "borsh 0.10.4", + "borsh 1.6.0", + "bs58", + "bytemuck", + "console_error_panic_hook", + "console_log", + "getrandom 0.2.17", + "lazy_static", + "log", + "memoffset", + "num-bigint 0.4.6", + "num-derive 0.4.2", + "num-traits", + "rand 0.8.5", + "serde", + "serde_bytes", + "serde_derive", + "solana-account-info", + "solana-address-lookup-table-interface", + "solana-atomic-u64", + "solana-big-mod-exp", + "solana-bincode", + "solana-blake3-hasher", + "solana-borsh", + "solana-clock", + "solana-cpi", + "solana-decode-error", + "solana-define-syscall", + "solana-epoch-rewards", + "solana-epoch-schedule", + "solana-example-mocks", + "solana-feature-gate-interface", + "solana-fee-calculator", + "solana-hash", + "solana-instruction", + "solana-instructions-sysvar", + "solana-keccak-hasher", + "solana-last-restart-slot", + "solana-loader-v2-interface", + "solana-loader-v3-interface", + "solana-loader-v4-interface", + "solana-message", + "solana-msg", + "solana-native-token 2.3.0", + "solana-nonce", + "solana-program-entrypoint", + "solana-program-error", + "solana-program-memory", + "solana-program-option", + "solana-program-pack", + "solana-pubkey", + "solana-rent", + "solana-sanitize", + "solana-sdk-ids", + "solana-sdk-macro", + "solana-secp256k1-recover", + "solana-serde-varint", + "solana-serialize-utils", + "solana-sha256-hasher", + "solana-short-vec", + "solana-slot-hashes", + "solana-slot-history", + "solana-stable-layout", + "solana-stake-interface", + "solana-system-interface", + "solana-sysvar", + "solana-sysvar-id", + "solana-vote-interface", + "thiserror 2.0.18", + "wasm-bindgen", +] + +[[package]] +name = "solana-program-entrypoint" +version = "2.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "32ce041b1a0ed275290a5008ee1a4a6c48f5054c8a3d78d313c08958a06aedbd" +dependencies = [ + "solana-account-info", + "solana-msg", + "solana-program-error", + "solana-pubkey", +] + +[[package]] +name = "solana-program-error" +version = "2.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9ee2e0217d642e2ea4bee237f37bd61bb02aec60da3647c48ff88f6556ade775" +dependencies = [ + "borsh 1.6.0", + "num-traits", + "serde", + "serde_derive", + "solana-decode-error", + "solana-instruction", + "solana-msg", + "solana-pubkey", +] + +[[package]] +name = "solana-program-memory" +version = "2.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3a5426090c6f3fd6cfdc10685322fede9ca8e5af43cd6a59e98bfe4e91671712" +dependencies = [ + "solana-define-syscall", +] + +[[package]] +name = "solana-program-option" +version = "2.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dc677a2e9bc616eda6dbdab834d463372b92848b2bfe4a1ed4e4b4adba3397d0" + +[[package]] +name = "solana-program-pack" +version = "2.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "319f0ef15e6e12dc37c597faccb7d62525a509fec5f6975ecb9419efddeb277b" +dependencies = [ + "solana-program-error", +] + +[[package]] +name = "solana-program-runtime" +version = "2.3.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5653001e07b657c9de6f0417cf9add1cf4325903732c480d415655e10cc86704" +dependencies = [ + "base64 0.22.1", + "bincode", + "enum-iterator", + "itertools 0.12.1", + "log", + "percentage", + "rand 0.8.5", + "serde", + "solana-account", + "solana-clock", + "solana-epoch-rewards", + "solana-epoch-schedule", + "solana-fee-structure", + "solana-hash", + "solana-instruction", + "solana-last-restart-slot", + "solana-log-collector", + "solana-measure", + "solana-metrics", + "solana-program-entrypoint", + "solana-pubkey", + "solana-rent", + "solana-sbpf", + "solana-sdk-ids", + "solana-slot-hashes", + "solana-stable-layout", + "solana-svm-callback", + "solana-svm-feature-set", + "solana-system-interface", + "solana-sysvar", + "solana-sysvar-id", + "solana-timings", + "solana-transaction-context", + "solana-type-overrides", + "thiserror 2.0.18", +] + +[[package]] +name = "solana-pubkey" +version = "2.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9b62adb9c3261a052ca1f999398c388f1daf558a1b492f60a6d9e64857db4ff1" +dependencies = [ + "borsh 0.10.4", + "borsh 1.6.0", + "bytemuck", + "bytemuck_derive", + "curve25519-dalek 4.1.3", + "five8", + "five8_const", + "getrandom 0.2.17", + "js-sys", + "num-traits", + "rand 0.8.5", + "serde", + "serde_derive", + "solana-atomic-u64", + "solana-decode-error", + "solana-define-syscall", + "solana-sanitize", + "solana-sha256-hasher", + "wasm-bindgen", +] + +[[package]] +name = "solana-quic-definitions" +version = "2.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fbf0d4d5b049eb1d0c35f7b18f305a27c8986fc5c0c9b383e97adaa35334379e" +dependencies = [ + "solana-keypair", +] + +[[package]] +name = "solana-rent" +version = "2.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d1aea8fdea9de98ca6e8c2da5827707fb3842833521b528a713810ca685d2480" +dependencies = [ + "serde", + "serde_derive", + "solana-sdk-ids", + "solana-sdk-macro", + "solana-sysvar-id", +] + +[[package]] +name = "solana-rent-collector" +version = "2.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "127e6dfa51e8c8ae3aa646d8b2672bc4ac901972a338a9e1cd249e030564fb9d" +dependencies = [ + "serde", + "serde_derive", + "solana-account", + "solana-clock", + "solana-epoch-schedule", + "solana-genesis-config", + "solana-pubkey", + "solana-rent", + "solana-sdk-ids", +] + +[[package]] +name = "solana-rent-debits" +version = "2.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4f6f9113c6003492e74438d1288e30cffa8ccfdc2ef7b49b9e816d8034da18cd" +dependencies = [ + "solana-pubkey", + "solana-reward-info", +] + +[[package]] +name = "solana-reserved-account-keys" +version = "2.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e4b22ea19ca2a3f28af7cd047c914abf833486bf7a7c4a10fc652fff09b385b1" +dependencies = [ + "lazy_static", + "solana-feature-set", + "solana-pubkey", + "solana-sdk-ids", +] + +[[package]] +name = "solana-reward-info" +version = "2.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "18205b69139b1ae0ab8f6e11cdcb627328c0814422ad2482000fa2ca54ae4a2f" +dependencies = [ + "serde", + "serde_derive", +] + +[[package]] +name = "solana-rpc-client" +version = "2.3.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b8d3161ac0918178e674c1f7f1bfac40de3e7ed0383bd65747d63113c156eaeb" +dependencies = [ + "async-trait", + "base64 0.22.1", + "bincode", + "bs58", + "futures", + "indicatif", + "log", + "reqwest 0.12.28", + "reqwest-middleware", + "semver", + "serde", + "serde_derive", + "serde_json", + "solana-account", + "solana-account-decoder-client-types", + "solana-clock", + "solana-commitment-config", + "solana-epoch-info", + "solana-epoch-schedule", + "solana-feature-gate-interface", + "solana-hash", + "solana-instruction", + "solana-message", + "solana-pubkey", + "solana-rpc-client-api", + "solana-signature", + "solana-transaction", + "solana-transaction-error", + "solana-transaction-status-client-types", + "solana-version", + "solana-vote-interface", + "tokio", +] + +[[package]] +name = "solana-rpc-client-api" +version = "2.3.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2dbc138685c79d88a766a8fd825057a74ea7a21e1dd7f8de275ada899540fff7" +dependencies = [ + "anyhow", + "jsonrpc-core", + "reqwest 0.12.28", + "reqwest-middleware", + "serde", + "serde_derive", + "serde_json", + "solana-account-decoder-client-types", + "solana-clock", + "solana-rpc-client-types", + "solana-signer", + "solana-transaction-error", + "solana-transaction-status-client-types", + "thiserror 2.0.18", +] + +[[package]] +name = "solana-rpc-client-types" +version = "2.3.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8ea428a81729255d895ea47fba9b30fd4dacbfe571a080448121bd0592751676" +dependencies = [ + "base64 0.22.1", + "bs58", + "semver", + "serde", + "serde_derive", + "serde_json", + "solana-account", + "solana-account-decoder-client-types", + "solana-clock", + "solana-commitment-config", + "solana-fee-calculator", + "solana-inflation", + "solana-pubkey", + "solana-transaction-error", + "solana-transaction-status-client-types", + "solana-version", + "spl-generic-token", + "thiserror 2.0.18", +] + +[[package]] +name = "solana-sanitize" +version = "2.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "61f1bc1357b8188d9c4a3af3fc55276e56987265eb7ad073ae6f8180ee54cecf" + +[[package]] +name = "solana-sbpf" +version = "0.11.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "474a2d95dc819898ded08d24f29642d02189d3e1497bbb442a92a3997b7eb55f" +dependencies = [ + "byteorder", + "combine", + "hash32", + "libc", + "log", + "rand 0.8.5", + "rustc-demangle", + "thiserror 2.0.18", + "winapi", +] + +[[package]] +name = "solana-sdk" +version = "2.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8cc0e4a7635b902791c44b6581bfb82f3ada32c5bc0929a64f39fe4bb384c86a" +dependencies = [ + "bincode", + "bs58", + "getrandom 0.1.16", + "js-sys", + "serde", + "serde_json", + "solana-account", + "solana-bn254", + "solana-client-traits", + "solana-cluster-type", + "solana-commitment-config", + "solana-compute-budget-interface", + "solana-decode-error", + "solana-derivation-path", + "solana-ed25519-program", + "solana-epoch-info", + "solana-epoch-rewards-hasher", + "solana-feature-set", + "solana-fee-structure", + "solana-genesis-config", + "solana-hard-forks", + "solana-inflation", + "solana-instruction", + "solana-keypair", + "solana-message", + "solana-native-token 2.3.0", + "solana-nonce-account", + "solana-offchain-message", + "solana-packet", + "solana-poh-config", + "solana-precompile-error", + "solana-precompiles", + "solana-presigner", + "solana-program", + "solana-program-memory", + "solana-pubkey", + "solana-quic-definitions", + "solana-rent-collector", + "solana-rent-debits", + "solana-reserved-account-keys", + "solana-reward-info", + "solana-sanitize", + "solana-sdk-ids", + "solana-sdk-macro", + "solana-secp256k1-program", + "solana-secp256k1-recover", + "solana-secp256r1-program", + "solana-seed-derivable", + "solana-seed-phrase", + "solana-serde", + "solana-serde-varint", + "solana-short-vec", + "solana-shred-version", + "solana-signature", + "solana-signer", + "solana-system-transaction", + "solana-time-utils", + "solana-transaction", + "solana-transaction-context", + "solana-transaction-error", + "solana-validator-exit", + "thiserror 2.0.18", + "wasm-bindgen", +] + +[[package]] +name = "solana-sdk-ids" +version = "2.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5c5d8b9cc68d5c88b062a33e23a6466722467dde0035152d8fb1afbcdf350a5f" +dependencies = [ + "solana-pubkey", +] + +[[package]] +name = "solana-sdk-macro" +version = "2.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "86280da8b99d03560f6ab5aca9de2e38805681df34e0bb8f238e69b29433b9df" +dependencies = [ + "bs58", + "proc-macro2", + "quote", + "syn 2.0.114", +] + +[[package]] +name = "solana-secp256k1-program" +version = "2.2.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f19833e4bc21558fe9ec61f239553abe7d05224347b57d65c2218aeeb82d6149" +dependencies = [ + "bincode", + "digest 0.10.7", + "libsecp256k1", + "serde", + "serde_derive", + "sha3", + "solana-feature-set", + "solana-instruction", + "solana-precompile-error", + "solana-sdk-ids", + "solana-signature", +] + +[[package]] +name = "solana-secp256k1-recover" +version = "2.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "baa3120b6cdaa270f39444f5093a90a7b03d296d362878f7a6991d6de3bbe496" +dependencies = [ + "borsh 1.6.0", + "libsecp256k1", + "solana-define-syscall", + "thiserror 2.0.18", +] + +[[package]] +name = "solana-secp256r1-program" +version = "2.2.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ce0ae46da3071a900f02d367d99b2f3058fe2e90c5062ac50c4f20cfedad8f0f" +dependencies = [ + "bytemuck", + "openssl", + "solana-feature-set", + "solana-instruction", + "solana-precompile-error", + "solana-sdk-ids", +] + +[[package]] +name = "solana-security-txt" +version = "1.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "156bb61a96c605fa124e052d630dba2f6fb57e08c7d15b757e1e958b3ed7b3fe" +dependencies = [ + "hashbrown 0.15.2", +] + +[[package]] +name = "solana-seed-derivable" +version = "2.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3beb82b5adb266c6ea90e5cf3967235644848eac476c5a1f2f9283a143b7c97f" +dependencies = [ + "solana-derivation-path", +] + +[[package]] +name = "solana-seed-phrase" +version = "2.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "36187af2324f079f65a675ec22b31c24919cb4ac22c79472e85d819db9bbbc15" +dependencies = [ + "hmac 0.12.1", + "pbkdf2", + "sha2 0.10.9", +] + +[[package]] +name = "solana-serde" +version = "2.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1931484a408af466e14171556a47adaa215953c7f48b24e5f6b0282763818b04" +dependencies = [ + "serde", +] + +[[package]] +name = "solana-serde-varint" +version = "2.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2a7e155eba458ecfb0107b98236088c3764a09ddf0201ec29e52a0be40857113" +dependencies = [ + "serde", +] + +[[package]] +name = "solana-serialize-utils" +version = "2.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "817a284b63197d2b27afdba829c5ab34231da4a9b4e763466a003c40ca4f535e" +dependencies = [ + "solana-instruction", + "solana-pubkey", + "solana-sanitize", +] + +[[package]] +name = "solana-sha256-hasher" +version = "2.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5aa3feb32c28765f6aa1ce8f3feac30936f16c5c3f7eb73d63a5b8f6f8ecdc44" +dependencies = [ + "sha2 0.10.9", + "solana-define-syscall", + "solana-hash", +] + +[[package]] +name = "solana-short-vec" +version = "2.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5c54c66f19b9766a56fa0057d060de8378676cb64987533fa088861858fc5a69" +dependencies = [ + "serde", +] + +[[package]] +name = "solana-shred-version" +version = "2.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "afd3db0461089d1ad1a78d9ba3f15b563899ca2386351d38428faa5350c60a98" +dependencies = [ + "solana-hard-forks", + "solana-hash", + "solana-sha256-hasher", +] + +[[package]] +name = "solana-signature" +version = "2.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "64c8ec8e657aecfc187522fc67495142c12f35e55ddeca8698edbb738b8dbd8c" +dependencies = [ + "ed25519-dalek", + "five8", + "rand 0.8.5", + "serde", + "serde-big-array", + "serde_derive", + "solana-sanitize", +] + +[[package]] +name = "solana-signer" +version = "2.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7c41991508a4b02f021c1342ba00bcfa098630b213726ceadc7cb032e051975b" +dependencies = [ + "solana-pubkey", + "solana-signature", + "solana-transaction-error", +] + +[[package]] +name = "solana-slot-hashes" +version = "2.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0c8691982114513763e88d04094c9caa0376b867a29577939011331134c301ce" +dependencies = [ + "serde", + "serde_derive", + "solana-hash", + "solana-sdk-ids", + "solana-sysvar-id", +] + +[[package]] +name = "solana-slot-history" +version = "2.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "97ccc1b2067ca22754d5283afb2b0126d61eae734fc616d23871b0943b0d935e" +dependencies = [ + "bv", + "serde", + "serde_derive", + "solana-sdk-ids", + "solana-sysvar-id", +] + +[[package]] +name = "solana-stable-layout" +version = "2.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9f14f7d02af8f2bc1b5efeeae71bc1c2b7f0f65cd75bcc7d8180f2c762a57f54" +dependencies = [ + "solana-instruction", + "solana-pubkey", +] + +[[package]] +name = "solana-stake-interface" +version = "1.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5269e89fde216b4d7e1d1739cf5303f8398a1ff372a81232abbee80e554a838c" +dependencies = [ + "borsh 0.10.4", + "borsh 1.6.0", + "num-traits", + "serde", + "serde_derive", + "solana-clock", + "solana-cpi", + "solana-decode-error", + "solana-instruction", + "solana-program-error", + "solana-pubkey", + "solana-system-interface", + "solana-sysvar-id", +] + +[[package]] +name = "solana-stake-program" +version = "2.3.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "500e9b9d11573f12de91e94f9c4459882cd5ffc692776af49b610d6fcc0b167f" +dependencies = [ + "agave-feature-set", + "bincode", + "log", + "solana-account", + "solana-bincode", + "solana-clock", + "solana-config-program-client", + "solana-genesis-config", + "solana-instruction", + "solana-log-collector", + "solana-native-token 2.3.0", + "solana-packet", + "solana-program-runtime", + "solana-pubkey", + "solana-rent", + "solana-sdk-ids", + "solana-stake-interface", + "solana-sysvar", + "solana-transaction-context", + "solana-type-overrides", + "solana-vote-interface", +] + +[[package]] +name = "solana-svm-callback" +version = "2.3.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7cef9f7d5cfb5d375081a6c8ad712a6f0e055a15890081f845acf55d8254a7a2" +dependencies = [ + "solana-account", + "solana-precompile-error", + "solana-pubkey", +] + +[[package]] +name = "solana-svm-feature-set" +version = "2.3.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3f24b836eb4d74ec255217bdbe0f24f64a07adeac31aca61f334f91cd4a3b1d5" + +[[package]] +name = "solana-svm-transaction" +version = "2.3.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ab717b9539375ebb088872c6c87d1d8832d19f30f154ecc530154d23f60a6f0c" +dependencies = [ + "solana-hash", + "solana-message", + "solana-pubkey", + "solana-sdk-ids", + "solana-signature", + "solana-transaction", +] + +[[package]] +name = "solana-system-interface" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "94d7c18cb1a91c6be5f5a8ac9276a1d7c737e39a21beba9ea710ab4b9c63bc90" +dependencies = [ + "js-sys", + "num-traits", + "serde", + "serde_derive", + "solana-decode-error", + "solana-instruction", + "solana-pubkey", + "wasm-bindgen", +] + +[[package]] +name = "solana-system-program" +version = "2.3.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "23ca36cef39aea7761be58d4108a56a2e27042fb1e913355fdb142a05fc7eab7" +dependencies = [ + "bincode", + "log", + "serde", + "serde_derive", + "solana-account", + "solana-bincode", + "solana-fee-calculator", + "solana-instruction", + "solana-log-collector", + "solana-nonce", + "solana-nonce-account", + "solana-packet", + "solana-program-runtime", + "solana-pubkey", + "solana-sdk-ids", + "solana-system-interface", + "solana-sysvar", + "solana-transaction-context", + "solana-type-overrides", +] + +[[package]] +name = "solana-system-transaction" +version = "2.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5bd98a25e5bcba8b6be8bcbb7b84b24c2a6a8178d7fb0e3077a916855ceba91a" +dependencies = [ + "solana-hash", + "solana-keypair", + "solana-message", + "solana-pubkey", + "solana-signer", + "solana-system-interface", + "solana-transaction", +] + +[[package]] +name = "solana-sysvar" +version = "2.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b8c3595f95069f3d90f275bb9bd235a1973c4d059028b0a7f81baca2703815db" +dependencies = [ + "base64 0.22.1", + "bincode", + "bytemuck", + "bytemuck_derive", + "lazy_static", + "serde", + "serde_derive", + "solana-account-info", + "solana-clock", + "solana-define-syscall", + "solana-epoch-rewards", + "solana-epoch-schedule", + "solana-fee-calculator", + "solana-hash", + "solana-instruction", + "solana-instructions-sysvar", + "solana-last-restart-slot", + "solana-program-entrypoint", + "solana-program-error", + "solana-program-memory", + "solana-pubkey", + "solana-rent", + "solana-sanitize", + "solana-sdk-ids", + "solana-sdk-macro", + "solana-slot-hashes", + "solana-slot-history", + "solana-stake-interface", + "solana-sysvar-id", +] + +[[package]] +name = "solana-sysvar-id" +version = "2.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5762b273d3325b047cfda250787f8d796d781746860d5d0a746ee29f3e8812c1" +dependencies = [ + "solana-pubkey", + "solana-sdk-ids", +] + +[[package]] +name = "solana-time-utils" +version = "2.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6af261afb0e8c39252a04d026e3ea9c405342b08c871a2ad8aa5448e068c784c" + +[[package]] +name = "solana-timings" +version = "2.3.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7c49b842dfc53c1bf9007eaa6730296dea93b4fce73f457ce1080af43375c0d6" +dependencies = [ + "eager", + "enum-iterator", + "solana-pubkey", +] + +[[package]] +name = "solana-transaction" +version = "2.2.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "80657d6088f721148f5d889c828ca60c7daeedac9a8679f9ec215e0c42bcbf41" +dependencies = [ + "bincode", + "serde", + "serde_derive", + "solana-bincode", + "solana-feature-set", + "solana-hash", + "solana-instruction", + "solana-keypair", + "solana-message", + "solana-precompiles", + "solana-pubkey", + "solana-sanitize", + "solana-sdk-ids", + "solana-short-vec", + "solana-signature", + "solana-signer", + "solana-system-interface", + "solana-transaction-error", + "wasm-bindgen", +] + +[[package]] +name = "solana-transaction-context" +version = "2.3.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "54a312304361987a85b2ef2293920558e6612876a639dd1309daf6d0d59ef2fe" +dependencies = [ + "bincode", + "serde", + "serde_derive", + "solana-account", + "solana-instruction", + "solana-instructions-sysvar", + "solana-pubkey", + "solana-rent", + "solana-sdk-ids", +] + +[[package]] +name = "solana-transaction-error" +version = "2.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "222a9dc8fdb61c6088baab34fc3a8b8473a03a7a5fd404ed8dd502fa79b67cb1" +dependencies = [ + "serde", + "serde_derive", + "solana-instruction", + "solana-sanitize", +] + +[[package]] +name = "solana-transaction-status" +version = "2.3.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "135f92f4192cc68900c665becf97fc0a6500ae5a67ff347bf2cbc20ecfefa821" +dependencies = [ + "Inflector", + "agave-reserved-account-keys", + "base64 0.22.1", + "bincode", + "borsh 1.6.0", + "bs58", + "log", + "serde", + "serde_derive", + "serde_json", + "solana-account-decoder", + "solana-address-lookup-table-interface", + "solana-clock", + "solana-hash", + "solana-instruction", + "solana-loader-v2-interface", + "solana-loader-v3-interface", + "solana-message", + "solana-program-option", + "solana-pubkey", + "solana-reward-info", + "solana-sdk-ids", + "solana-signature", + "solana-stake-interface", + "solana-system-interface", + "solana-transaction", + "solana-transaction-error", + "solana-transaction-status-client-types", + "solana-vote-interface", + "spl-associated-token-account 7.0.0", + "spl-memo", + "spl-token 8.0.0", + "spl-token-2022 8.0.1", + "spl-token-group-interface 0.6.0", + "spl-token-metadata-interface 0.7.0", + "thiserror 2.0.18", +] + +[[package]] +name = "solana-transaction-status-client-types" +version = "2.3.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "51f1d7c2387c35850848212244d2b225847666cb52d3bd59a5c409d2c300303d" +dependencies = [ + "base64 0.22.1", + "bincode", + "bs58", + "serde", + "serde_derive", + "serde_json", + "solana-account-decoder-client-types", + "solana-commitment-config", + "solana-message", + "solana-reward-info", + "solana-signature", + "solana-transaction", + "solana-transaction-context", + "solana-transaction-error", + "thiserror 2.0.18", +] + +[[package]] +name = "solana-type-overrides" +version = "2.3.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "41d80c44761eb398a157d809a04840865c347e1831ae3859b6100c0ee457bc1a" +dependencies = [ + "rand 0.8.5", +] + +[[package]] +name = "solana-validator-exit" +version = "2.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7bbf6d7a3c0b28dd5335c52c0e9eae49d0ae489a8f324917faf0ded65a812c1d" + +[[package]] +name = "solana-version" +version = "2.3.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3324d46c7f7b7f5d34bf7dc71a2883bdc072c7b28ca81d0b2167ecec4cf8da9f" +dependencies = [ + "agave-feature-set", + "rand 0.8.5", + "semver", + "serde", + "serde_derive", + "solana-sanitize", + "solana-serde-varint", +] + +[[package]] +name = "solana-vote-interface" +version = "2.2.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b80d57478d6599d30acc31cc5ae7f93ec2361a06aefe8ea79bc81739a08af4c3" +dependencies = [ + "bincode", + "num-derive 0.4.2", + "num-traits", + "serde", + "serde_derive", + "solana-clock", + "solana-decode-error", + "solana-hash", + "solana-instruction", + "solana-pubkey", + "solana-rent", + "solana-sdk-ids", + "solana-serde-varint", + "solana-serialize-utils", + "solana-short-vec", + "solana-system-interface", +] + +[[package]] +name = "solana-vote-program" +version = "2.3.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "908d0e72c8b83e48762eb3e8c9114497cf4b1d66e506e360c46aba9308e71299" +dependencies = [ + "agave-feature-set", + "bincode", + "log", + "num-derive 0.4.2", + "num-traits", + "serde", + "serde_derive", + "solana-account", + "solana-bincode", + "solana-clock", + "solana-epoch-schedule", + "solana-hash", + "solana-instruction", + "solana-keypair", + "solana-metrics", + "solana-packet", + "solana-program-runtime", + "solana-pubkey", + "solana-rent", + "solana-sdk-ids", + "solana-signer", + "solana-slot-hashes", + "solana-transaction", + "solana-transaction-context", + "solana-vote-interface", + "thiserror 2.0.18", +] + +[[package]] +name = "solana-zk-elgamal-proof-program" +version = "2.3.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "70cea14481d8efede6b115a2581f27bc7c6fdfba0752c20398456c3ac1245fc4" +dependencies = [ + "agave-feature-set", + "bytemuck", + "num-derive 0.4.2", + "num-traits", + "solana-instruction", + "solana-log-collector", + "solana-program-runtime", + "solana-sdk-ids", + "solana-zk-sdk", +] + +[[package]] +name = "solana-zk-sdk" +version = "2.3.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "97b9fc6ec37d16d0dccff708ed1dd6ea9ba61796700c3bb7c3b401973f10f63b" +dependencies = [ + "aes-gcm-siv", + "base64 0.22.1", + "bincode", + "bytemuck", + "bytemuck_derive", + "curve25519-dalek 4.1.3", + "itertools 0.12.1", + "js-sys", + "merlin", + "num-derive 0.4.2", + "num-traits", + "rand 0.8.5", + "serde", + "serde_derive", + "serde_json", + "sha3", + "solana-derivation-path", + "solana-instruction", + "solana-pubkey", + "solana-sdk-ids", + "solana-seed-derivable", + "solana-seed-phrase", + "solana-signature", + "solana-signer", + "subtle", + "thiserror 2.0.18", + "wasm-bindgen", + "zeroize", +] + +[[package]] +name = "solana-zk-token-proof-program" +version = "2.3.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "579752ad6ea2a671995f13c763bf28288c3c895cb857a518cc4ebab93c9a8dde" +dependencies = [ + "agave-feature-set", + "bytemuck", + "num-derive 0.4.2", + "num-traits", + "solana-instruction", + "solana-log-collector", + "solana-program-runtime", + "solana-sdk-ids", + "solana-zk-token-sdk", +] + +[[package]] +name = "solana-zk-token-sdk" +version = "2.3.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5055e5df94abd5badf4f947681c893375bdb6f8f543c05d2a7ab9647a6a9d205" +dependencies = [ + "aes-gcm-siv", + "base64 0.22.1", + "bincode", + "bytemuck", + "bytemuck_derive", + "curve25519-dalek 4.1.3", + "itertools 0.12.1", + "merlin", + "num-derive 0.4.2", + "num-traits", + "rand 0.8.5", + "serde", + "serde_derive", + "serde_json", + "sha3", + "solana-curve25519", + "solana-derivation-path", + "solana-instruction", + "solana-pubkey", + "solana-sdk-ids", + "solana-seed-derivable", + "solana-seed-phrase", + "solana-signature", + "solana-signer", + "subtle", + "thiserror 2.0.18", + "zeroize", +] + +[[package]] +name = "spl-associated-token-account" +version = "6.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "76fee7d65013667032d499adc3c895e286197a35a0d3a4643c80e7fd3e9969e3" +dependencies = [ + "borsh 1.6.0", + "num-derive 0.4.2", + "num-traits", + "solana-program", + "spl-associated-token-account-client", + "spl-token 7.0.0", + "spl-token-2022 6.0.0", + "thiserror 1.0.69", +] + +[[package]] +name = "spl-associated-token-account" +version = "7.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ae179d4a26b3c7a20c839898e6aed84cb4477adf108a366c95532f058aea041b" +dependencies = [ + "borsh 1.6.0", + "num-derive 0.4.2", + "num-traits", + "solana-program", + "spl-associated-token-account-client", + "spl-token 8.0.0", + "spl-token-2022 8.0.1", + "thiserror 2.0.18", +] + +[[package]] +name = "spl-associated-token-account-client" +version = "2.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d6f8349dbcbe575f354f9a533a21f272f3eb3808a49e2fdc1c34393b88ba76cb" +dependencies = [ + "solana-instruction", + "solana-pubkey", +] + +[[package]] +name = "spl-discriminator" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a7398da23554a31660f17718164e31d31900956054f54f52d5ec1be51cb4f4b3" +dependencies = [ + "bytemuck", + "solana-program-error", + "solana-sha256-hasher", + "spl-discriminator-derive", +] + +[[package]] +name = "spl-discriminator-derive" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d9e8418ea6269dcfb01c712f0444d2c75542c04448b480e87de59d2865edc750" +dependencies = [ + "quote", + "spl-discriminator-syn", + "syn 2.0.114", +] + +[[package]] +name = "spl-discriminator-syn" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5d1dbc82ab91422345b6df40a79e2b78c7bce1ebb366da323572dd60b7076b67" +dependencies = [ + "proc-macro2", + "quote", + "sha2 0.10.9", + "syn 2.0.114", + "thiserror 1.0.69", +] + +[[package]] +name = "spl-elgamal-registry" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ce0f668975d2b0536e8a8fd60e56a05c467f06021dae037f1d0cfed0de2e231d" +dependencies = [ + "bytemuck", + "solana-program", + "solana-zk-sdk", + "spl-pod", + "spl-token-confidential-transfer-proof-extraction 0.2.1", +] + +[[package]] +name = "spl-elgamal-registry" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "65edfeed09cd4231e595616aa96022214f9c9d2be02dea62c2b30d5695a6833a" +dependencies = [ + "bytemuck", + "solana-account-info", + "solana-cpi", + "solana-instruction", + "solana-msg", + "solana-program-entrypoint", + "solana-program-error", + "solana-pubkey", + "solana-rent", + "solana-sdk-ids", + "solana-system-interface", + "solana-sysvar", + "solana-zk-sdk", + "spl-pod", + "spl-token-confidential-transfer-proof-extraction 0.3.0", +] + +[[package]] +name = "spl-generic-token" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "741a62a566d97c58d33f9ed32337ceedd4e35109a686e31b1866c5dfa56abddc" +dependencies = [ + "bytemuck", + "solana-pubkey", +] + +[[package]] +name = "spl-memo" +version = "6.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9f09647c0974e33366efeb83b8e2daebb329f0420149e74d3a4bd2c08cf9f7cb" +dependencies = [ + "solana-account-info", + "solana-instruction", + "solana-msg", + "solana-program-entrypoint", + "solana-program-error", + "solana-pubkey", +] + +[[package]] +name = "spl-pod" +version = "0.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d994afaf86b779104b4a95ba9ca75b8ced3fdb17ee934e38cb69e72afbe17799" +dependencies = [ + "borsh 1.6.0", + "bytemuck", + "bytemuck_derive", + "num-derive 0.4.2", + "num-traits", + "solana-decode-error", + "solana-msg", + "solana-program-error", + "solana-program-option", + "solana-pubkey", + "solana-zk-sdk", + "thiserror 2.0.18", +] + +[[package]] +name = "spl-program-error" +version = "0.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9d39b5186f42b2b50168029d81e58e800b690877ef0b30580d107659250da1d1" +dependencies = [ + "num-derive 0.4.2", + "num-traits", + "solana-program", + "spl-program-error-derive 0.4.1", + "thiserror 1.0.69", +] + +[[package]] +name = "spl-program-error" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9cdebc8b42553070b75aa5106f071fef2eb798c64a7ec63375da4b1f058688c6" +dependencies = [ + "num-derive 0.4.2", + "num-traits", + "solana-decode-error", + "solana-msg", + "solana-program-error", + "spl-program-error-derive 0.5.0", + "thiserror 2.0.18", +] + +[[package]] +name = "spl-program-error-derive" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e6d375dd76c517836353e093c2dbb490938ff72821ab568b545fd30ab3256b3e" +dependencies = [ + "proc-macro2", + "quote", + "sha2 0.10.9", + "syn 2.0.114", +] + +[[package]] +name = "spl-program-error-derive" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2a2539e259c66910d78593475540e8072f0b10f0f61d7607bbf7593899ed52d0" +dependencies = [ + "proc-macro2", + "quote", + "sha2 0.10.9", + "syn 2.0.114", +] + +[[package]] +name = "spl-tlv-account-resolution" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cd99ff1e9ed2ab86e3fd582850d47a739fec1be9f4661cba1782d3a0f26805f3" +dependencies = [ + "bytemuck", + "num-derive 0.4.2", + "num-traits", + "solana-account-info", + "solana-decode-error", + "solana-instruction", + "solana-msg", + "solana-program-error", + "solana-pubkey", + "spl-discriminator", + "spl-pod", + "spl-program-error 0.6.0", + "spl-type-length-value 0.7.0", + "thiserror 1.0.69", +] + +[[package]] +name = "spl-tlv-account-resolution" +version = "0.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1408e961215688715d5a1063cbdcf982de225c45f99c82b4f7d7e1dd22b998d7" +dependencies = [ + "bytemuck", + "num-derive 0.4.2", + "num-traits", + "solana-account-info", + "solana-decode-error", + "solana-instruction", + "solana-msg", + "solana-program-error", + "solana-pubkey", + "spl-discriminator", + "spl-pod", + "spl-program-error 0.7.0", + "spl-type-length-value 0.8.0", + "thiserror 2.0.18", +] + +[[package]] +name = "spl-token" +version = "7.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ed320a6c934128d4f7e54fe00e16b8aeaecf215799d060ae14f93378da6dc834" +dependencies = [ + "arrayref", + "bytemuck", + "num-derive 0.4.2", + "num-traits", + "num_enum", + "solana-program", + "thiserror 1.0.69", +] + +[[package]] +name = "spl-token" +version = "8.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "053067c6a82c705004f91dae058b11b4780407e9ccd6799dc9e7d0fab5f242da" +dependencies = [ + "arrayref", + "bytemuck", + "num-derive 0.4.2", + "num-traits", + "num_enum", + "solana-account-info", + "solana-cpi", + "solana-decode-error", + "solana-instruction", + "solana-msg", + "solana-program-entrypoint", + "solana-program-error", + "solana-program-memory", + "solana-program-option", + "solana-program-pack", + "solana-pubkey", + "solana-rent", + "solana-sdk-ids", + "solana-sysvar", + "thiserror 2.0.18", +] + +[[package]] +name = "spl-token-2022" +version = "6.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5b27f7405010ef816587c944536b0eafbcc35206ab6ba0f2ca79f1d28e488f4f" +dependencies = [ + "arrayref", + "bytemuck", + "num-derive 0.4.2", + "num-traits", + "num_enum", + "solana-program", + "solana-security-txt", + "solana-zk-sdk", + "spl-elgamal-registry 0.1.1", + "spl-memo", + "spl-pod", + "spl-token 7.0.0", + "spl-token-confidential-transfer-ciphertext-arithmetic 0.2.1", + "spl-token-confidential-transfer-proof-extraction 0.2.1", + "spl-token-confidential-transfer-proof-generation 0.2.0", + "spl-token-group-interface 0.5.0", + "spl-token-metadata-interface 0.6.0", + "spl-transfer-hook-interface 0.9.0", + "spl-type-length-value 0.7.0", + "thiserror 1.0.69", +] + +[[package]] +name = "spl-token-2022" +version = "7.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9048b26b0df0290f929ff91317c83db28b3ef99af2b3493dd35baa146774924c" +dependencies = [ + "arrayref", + "bytemuck", + "num-derive 0.4.2", + "num-traits", + "num_enum", + "solana-program", + "solana-security-txt", + "solana-zk-sdk", + "spl-elgamal-registry 0.1.1", + "spl-memo", + "spl-pod", + "spl-token 7.0.0", + "spl-token-confidential-transfer-ciphertext-arithmetic 0.2.1", + "spl-token-confidential-transfer-proof-extraction 0.2.1", + "spl-token-confidential-transfer-proof-generation 0.3.0", + "spl-token-group-interface 0.5.0", + "spl-token-metadata-interface 0.6.0", + "spl-transfer-hook-interface 0.9.0", + "spl-type-length-value 0.7.0", + "thiserror 2.0.18", +] + +[[package]] +name = "spl-token-2022" +version = "8.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "31f0dfbb079eebaee55e793e92ca5f433744f4b71ee04880bfd6beefba5973e5" +dependencies = [ + "arrayref", + "bytemuck", + "num-derive 0.4.2", + "num-traits", + "num_enum", + "solana-account-info", + "solana-clock", + "solana-cpi", + "solana-decode-error", + "solana-instruction", + "solana-msg", + "solana-native-token 2.3.0", + "solana-program-entrypoint", + "solana-program-error", + "solana-program-memory", + "solana-program-option", + "solana-program-pack", + "solana-pubkey", + "solana-rent", + "solana-sdk-ids", + "solana-security-txt", + "solana-system-interface", + "solana-sysvar", + "solana-zk-sdk", + "spl-elgamal-registry 0.2.0", + "spl-memo", + "spl-pod", + "spl-token 8.0.0", + "spl-token-confidential-transfer-ciphertext-arithmetic 0.3.1", + "spl-token-confidential-transfer-proof-extraction 0.3.0", + "spl-token-confidential-transfer-proof-generation 0.4.1", + "spl-token-group-interface 0.6.0", + "spl-token-metadata-interface 0.7.0", + "spl-transfer-hook-interface 0.10.0", + "spl-type-length-value 0.8.0", + "thiserror 2.0.18", +] + +[[package]] +name = "spl-token-2022-interface" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "62d7ae2ee6b856f8ddcbdc3b3a9f4d2141582bbe150f93e5298ee97e0251fa04" +dependencies = [ + "arrayref", + "bytemuck", + "num-derive 0.4.2", + "num-traits", + "num_enum", + "solana-account-info", + "solana-decode-error", + "solana-instruction", + "solana-msg", + "solana-program-error", + "solana-program-option", + "solana-program-pack", + "solana-pubkey", + "solana-sdk-ids", + "solana-zk-sdk", + "spl-pod", + "spl-token-confidential-transfer-proof-extraction 0.4.1", + "spl-token-confidential-transfer-proof-generation 0.4.1", + "spl-token-group-interface 0.6.0", + "spl-token-metadata-interface 0.7.0", + "spl-type-length-value 0.8.0", + "thiserror 2.0.18", +] + +[[package]] +name = "spl-token-confidential-transfer-ciphertext-arithmetic" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "170378693c5516090f6d37ae9bad2b9b6125069be68d9acd4865bbe9fc8499fd" +dependencies = [ + "base64 0.22.1", + "bytemuck", + "solana-curve25519", + "solana-zk-sdk", +] + +[[package]] +name = "spl-token-confidential-transfer-ciphertext-arithmetic" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cddd52bfc0f1c677b41493dafa3f2dbbb4b47cf0990f08905429e19dc8289b35" +dependencies = [ + "base64 0.22.1", + "bytemuck", + "solana-curve25519", + "solana-zk-sdk", +] + +[[package]] +name = "spl-token-confidential-transfer-proof-extraction" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "eff2d6a445a147c9d6dd77b8301b1e116c8299601794b558eafa409b342faf96" +dependencies = [ + "bytemuck", + "solana-curve25519", + "solana-program", + "solana-zk-sdk", + "spl-pod", + "thiserror 2.0.18", +] + +[[package]] +name = "spl-token-confidential-transfer-proof-extraction" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fe2629860ff04c17bafa9ba4bed8850a404ecac81074113e1f840dbd0ebb7bd6" +dependencies = [ + "bytemuck", + "solana-account-info", + "solana-curve25519", + "solana-instruction", + "solana-instructions-sysvar", + "solana-msg", + "solana-program-error", + "solana-pubkey", + "solana-sdk-ids", + "solana-zk-sdk", + "spl-pod", + "thiserror 2.0.18", +] + +[[package]] +name = "spl-token-confidential-transfer-proof-extraction" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "512c85bdbbb4cbcc2038849a9e164c958b16541f252b53ea1a3933191c0a4a1a" +dependencies = [ + "bytemuck", + "solana-account-info", + "solana-curve25519", + "solana-instruction", + "solana-instructions-sysvar", + "solana-msg", + "solana-program-error", + "solana-pubkey", + "solana-sdk-ids", + "solana-zk-sdk", + "spl-pod", + "thiserror 2.0.18", +] + +[[package]] +name = "spl-token-confidential-transfer-proof-generation" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8627184782eec1894de8ea26129c61303f1f0adeed65c20e0b10bc584f09356d" +dependencies = [ + "curve25519-dalek 4.1.3", + "solana-zk-sdk", + "thiserror 1.0.69", +] + +[[package]] +name = "spl-token-confidential-transfer-proof-generation" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0e3597628b0d2fe94e7900fd17cdb4cfbb31ee35c66f82809d27d86e44b2848b" +dependencies = [ + "curve25519-dalek 4.1.3", + "solana-zk-sdk", + "thiserror 2.0.18", +] + +[[package]] +name = "spl-token-confidential-transfer-proof-generation" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fa27b9174bea869a7ebf31e0be6890bce90b1a4288bc2bbf24bd413f80ae3fde" +dependencies = [ + "curve25519-dalek 4.1.3", + "solana-zk-sdk", + "thiserror 2.0.18", +] + +[[package]] +name = "spl-token-group-interface" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d595667ed72dbfed8c251708f406d7c2814a3fa6879893b323d56a10bedfc799" +dependencies = [ + "bytemuck", + "num-derive 0.4.2", + "num-traits", + "solana-decode-error", + "solana-instruction", + "solana-msg", + "solana-program-error", + "solana-pubkey", + "spl-discriminator", + "spl-pod", + "thiserror 1.0.69", +] + +[[package]] +name = "spl-token-group-interface" +version = "0.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5597b4cd76f85ce7cd206045b7dc22da8c25516573d42d267c8d1fd128db5129" +dependencies = [ + "bytemuck", + "num-derive 0.4.2", + "num-traits", + "solana-decode-error", + "solana-instruction", + "solana-msg", + "solana-program-error", + "solana-pubkey", + "spl-discriminator", + "spl-pod", + "thiserror 2.0.18", +] + +[[package]] +name = "spl-token-metadata-interface" +version = "0.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dfb9c89dbc877abd735f05547dcf9e6e12c00c11d6d74d8817506cab4c99fdbb" +dependencies = [ + "borsh 1.6.0", + "num-derive 0.4.2", + "num-traits", + "solana-borsh", + "solana-decode-error", + "solana-instruction", + "solana-msg", + "solana-program-error", + "solana-pubkey", + "spl-discriminator", + "spl-pod", + "spl-type-length-value 0.7.0", + "thiserror 1.0.69", +] + +[[package]] +name = "spl-token-metadata-interface" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "304d6e06f0de0c13a621464b1fd5d4b1bebf60d15ca71a44d3839958e0da16ee" +dependencies = [ + "borsh 1.6.0", + "num-derive 0.4.2", + "num-traits", + "solana-borsh", + "solana-decode-error", + "solana-instruction", + "solana-msg", + "solana-program-error", + "solana-pubkey", + "spl-discriminator", + "spl-pod", + "spl-type-length-value 0.8.0", + "thiserror 2.0.18", +] + +[[package]] +name = "spl-transfer-hook-interface" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4aa7503d52107c33c88e845e1351565050362c2314036ddf19a36cd25137c043" +dependencies = [ + "arrayref", + "bytemuck", + "num-derive 0.4.2", + "num-traits", + "solana-account-info", + "solana-cpi", + "solana-decode-error", + "solana-instruction", + "solana-msg", + "solana-program-error", + "solana-pubkey", + "spl-discriminator", + "spl-pod", + "spl-program-error 0.6.0", + "spl-tlv-account-resolution 0.9.0", + "spl-type-length-value 0.7.0", + "thiserror 1.0.69", +] + +[[package]] +name = "spl-transfer-hook-interface" +version = "0.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a7e905b849b6aba63bde8c4badac944ebb6c8e6e14817029cbe1bc16829133bd" +dependencies = [ + "arrayref", + "bytemuck", + "num-derive 0.4.2", + "num-traits", + "solana-account-info", + "solana-cpi", + "solana-decode-error", + "solana-instruction", + "solana-msg", + "solana-program-error", + "solana-pubkey", + "spl-discriminator", + "spl-pod", + "spl-program-error 0.7.0", + "spl-tlv-account-resolution 0.10.0", + "spl-type-length-value 0.8.0", + "thiserror 2.0.18", +] + +[[package]] +name = "spl-type-length-value" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ba70ef09b13af616a4c987797870122863cba03acc4284f226a4473b043923f9" +dependencies = [ + "bytemuck", + "num-derive 0.4.2", + "num-traits", + "solana-account-info", + "solana-decode-error", + "solana-msg", + "solana-program-error", + "spl-discriminator", + "spl-pod", + "thiserror 1.0.69", +] + +[[package]] +name = "spl-type-length-value" +version = "0.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d417eb548214fa822d93f84444024b4e57c13ed6719d4dcc68eec24fb481e9f5" +dependencies = [ + "bytemuck", + "num-derive 0.4.2", + "num-traits", + "solana-account-info", + "solana-decode-error", + "solana-msg", + "solana-program-error", + "spl-discriminator", + "spl-pod", + "thiserror 2.0.18", +] + +[[package]] +name = "stable_deref_trait" +version = "1.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6ce2be8dc25455e1f91df71bfa12ad37d7af1092ae736f3a6cd0e37bc7810596" + +[[package]] +name = "static_assertions" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a2eb9349b6444b326872e140eb1cf5e7c522154d69e7a0ffb0fb81c06b37543f" + +[[package]] +name = "strsim" +version = "0.11.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7da8b5736845d9f2fcb837ea5d9e2628564b3b043a70948a3f0b778838c5fb4f" + +[[package]] +name = "subtle" +version = "2.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "13c2bddecc57b384dee18652358fb23172facb8a2c51ccc10d74c157bdea3292" + +[[package]] +name = "swap_example" +version = "0.1.0" +dependencies = [ + "anchor-lang", + "anchor-spl", + "az", + "blake3", + "fixed", + "light-anchor-spl", + "light-client", + "light-hasher", + "light-program-test", + "light-sdk", + "light-token", + "shared-test-utils", + "solana-account-info", + "solana-instruction", + "solana-keypair", + "solana-msg", + "solana-program", + "solana-program-error", + "solana-pubkey", + "solana-sdk", + "solana-signer", + "spl-pod", + "spl-token-2022 7.0.0", + "tokio", +] + +[[package]] +name = "syn" +version = "1.0.109" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "72b64191b275b66ffe2469e8af2c1cfe3bafa67b529ead792a6d0160888b4237" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "syn" +version = "2.0.114" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d4d107df263a3013ef9b1879b0df87d706ff80f65a86ea879bd9c31f9b307c2a" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "sync_wrapper" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2047c6ded9c721764247e62cd3b03c09ffc529b2ba5b10ec482ae507a4a70160" + +[[package]] +name = "sync_wrapper" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0bf256ce5efdfa370213c1dabab5935a12e49f2c58d15e9eac2870d3b4f27263" +dependencies = [ + "futures-core", +] + +[[package]] +name = "synstructure" +version = "0.13.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "728a70f3dbaf5bab7f0c4b1ac8d7ae5ea60a4b5549c8a5914361c99147a709d2" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.114", +] + +[[package]] +name = "system-configuration" +version = "0.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ba3a3adc5c275d719af8cb4272ea1c4a6d668a777f37e115f6d11ddbc1c8e0e7" +dependencies = [ + "bitflags 1.3.2", + "core-foundation", + "system-configuration-sys 0.5.0", +] + +[[package]] +name = "system-configuration" +version = "0.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3c879d448e9d986b661742763247d3693ed13609438cf3d006f51f5368a5ba6b" +dependencies = [ + "bitflags 2.10.0", + "core-foundation", + "system-configuration-sys 0.6.0", +] + +[[package]] +name = "system-configuration-sys" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a75fb188eb626b924683e3b95e3a48e63551fcfb51949de2f06a9d91dbee93c9" +dependencies = [ + "core-foundation-sys", + "libc", +] + +[[package]] +name = "system-configuration-sys" +version = "0.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8e1d1b10ced5ca923a1fcb8d03e96b8d3268065d724548c0211415ff6ac6bac4" +dependencies = [ + "core-foundation-sys", + "libc", +] + +[[package]] +name = "tabled" +version = "0.20.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e39a2ee1fbcd360805a771e1b300f78cc88fec7b8d3e2f71cd37bbf23e725c7d" +dependencies = [ + "papergrid", + "tabled_derive", + "testing_table", +] + +[[package]] +name = "tabled_derive" +version = "0.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0ea5d1b13ca6cff1f9231ffd62f15eefd72543dab5e468735f1a456728a02846" +dependencies = [ + "heck 0.5.0", + "proc-macro-error2", + "proc-macro2", + "quote", + "syn 2.0.114", +] + +[[package]] +name = "tap" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "55937e1799185b12863d447f42597ed69d9928686b8d88a1df17376a097d8369" + +[[package]] +name = "tarpc" +version = "0.29.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1c38a012bed6fb9681d3bf71ffaa4f88f3b4b9ed3198cda6e4c8462d24d4bb80" +dependencies = [ + "anyhow", + "fnv", + "futures", + "humantime", + "opentelemetry", + "pin-project", + "rand 0.8.5", + "serde", + "static_assertions", + "tarpc-plugins", + "thiserror 1.0.69", + "tokio", + "tokio-serde", + "tokio-util 0.6.10", + "tracing", + "tracing-opentelemetry", +] + +[[package]] +name = "tarpc-plugins" +version = "0.12.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0ee42b4e559f17bce0385ebf511a7beb67d5cc33c12c96b7f4e9789919d9c10f" +dependencies = [ + "proc-macro2", + "quote", + "syn 1.0.109", +] + +[[package]] +name = "tempfile" +version = "3.24.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "655da9c7eb6305c55742045d5a8d2037996d61d8de95806335c7c86ce0f82e9c" +dependencies = [ + "fastrand", + "getrandom 0.3.4", + "once_cell", + "rustix", + "windows-sys 0.61.2", +] + +[[package]] +name = "termcolor" +version = "1.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "06794f8f6c5c898b3275aebefa6b8a1cb24cd2c6c79397ab15774837a0bc5755" +dependencies = [ + "winapi-util", +] + +[[package]] +name = "testing_table" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0f8daae29995a24f65619e19d8d31dea5b389f3d853d8bf297bbf607cd0014cc" +dependencies = [ + "unicode-width", +] + +[[package]] +name = "thiserror" +version = "1.0.69" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b6aaf5339b578ea85b50e080feb250a3e8ae8cfcdff9a461c9ec2904bc923f52" +dependencies = [ + "thiserror-impl 1.0.69", +] + +[[package]] +name = "thiserror" +version = "2.0.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4288b5bcbc7920c07a1149a35cf9590a2aa808e0bc1eafaade0b80947865fbc4" +dependencies = [ + "thiserror-impl 2.0.18", +] + +[[package]] +name = "thiserror-impl" +version = "1.0.69" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4fee6c4efc90059e10f81e6d42c60a18f76588c3d74cb83a0b242a2b6c7504c1" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.114", +] + +[[package]] +name = "thiserror-impl" +version = "2.0.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ebc4ee7f67670e9b64d05fa4253e753e016c6c95ff35b89b7941d6b856dec1d5" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.114", +] + +[[package]] +name = "thread_local" +version = "1.1.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f60246a4944f24f6e018aa17cdeffb7818b76356965d03b07d6a9886e8962185" +dependencies = [ + "cfg-if", +] + +[[package]] +name = "time" +version = "0.3.41" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8a7619e19bc266e0f9c5e6686659d394bc57973859340060a69221e57dbc0c40" +dependencies = [ + "deranged", + "itoa", + "num-conv", + "powerfmt", + "serde", + "time-core", + "time-macros", +] + +[[package]] +name = "time-core" +version = "0.1.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c9e9a38711f559d9e3ce1cdb06dd7c5b8ea546bc90052da6d06bb76da74bb07c" + +[[package]] +name = "time-macros" +version = "0.2.22" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3526739392ec93fd8b359c8e98514cb3e8e021beb4e5f597b00a0221f8ed8a49" +dependencies = [ + "num-conv", + "time-core", +] + +[[package]] +name = "tinystr" +version = "0.8.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "42d3e9c45c09de15d06dd8acf5f4e0e399e85927b7f00711024eb7ae10fa4869" +dependencies = [ + "displaydoc", + "zerovec", +] + +[[package]] +name = "tinyvec" +version = "1.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bfa5fdc3bce6191a1dbc8c02d5c8bffcf557bafa17c124c5264a458f1b0613fa" +dependencies = [ + "tinyvec_macros", +] + +[[package]] +name = "tinyvec_macros" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1f3ccbac311fea05f86f61904b462b55fb3df8837a366dfc601a0161d0532f20" + +[[package]] +name = "tokio" +version = "1.49.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "72a2903cd7736441aac9df9d7688bd0ce48edccaadf181c3b90be801e81d3d86" +dependencies = [ + "bytes", + "libc", + "mio", + "parking_lot", + "pin-project-lite", + "signal-hook-registry", + "socket2 0.6.2", + "tokio-macros", + "windows-sys 0.61.2", +] + +[[package]] +name = "tokio-macros" +version = "2.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "af407857209536a95c8e56f8231ef2c2e2aff839b22e07a1ffcbc617e9db9fa5" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.114", +] + +[[package]] +name = "tokio-native-tls" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bbae76ab933c85776efabc971569dd6119c580d8f5d448769dec1764bf796ef2" +dependencies = [ + "native-tls", + "tokio", +] + +[[package]] +name = "tokio-rustls" +version = "0.24.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c28327cf380ac148141087fbfb9de9d7bd4e84ab5d2c28fbc911d753de8a7081" +dependencies = [ + "rustls 0.21.12", + "tokio", +] + +[[package]] +name = "tokio-rustls" +version = "0.26.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1729aa945f29d91ba541258c8df89027d5792d85a8841fb65e8bf0f4ede4ef61" +dependencies = [ + "rustls 0.23.36", + "tokio", +] + +[[package]] +name = "tokio-serde" +version = "0.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "911a61637386b789af998ee23f50aa30d5fd7edcec8d6d3dedae5e5815205466" +dependencies = [ + "bincode", + "bytes", + "educe 0.4.23", + "futures-core", + "futures-sink", + "pin-project", + "serde", + "serde_json", +] + +[[package]] +name = "tokio-util" +version = "0.6.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "36943ee01a6d67977dd3f84a5a1d2efeb4ada3a1ae771cadfaa535d9d9fc6507" +dependencies = [ + "bytes", + "futures-core", + "futures-sink", + "log", + "pin-project-lite", + "slab", + "tokio", +] + +[[package]] +name = "tokio-util" +version = "0.7.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9ae9cec805b01e8fc3fd2fe289f89149a9b66dd16786abd8b19cfa7b48cb0098" +dependencies = [ + "bytes", + "futures-core", + "futures-sink", + "pin-project-lite", + "tokio", +] + +[[package]] +name = "toml" +version = "0.5.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f4f7f0dd8d50a853a531c426359045b1998f04219d88799810762cd4ad314234" +dependencies = [ + "serde", +] + +[[package]] +name = "toml" +version = "0.8.23" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dc1beb996b9d83529a9e75c17a1686767d148d70663143c7854d8b4a09ced362" +dependencies = [ + "serde", + "serde_spanned", + "toml_datetime 0.6.11", + "toml_edit 0.22.27", +] + +[[package]] +name = "toml_datetime" +version = "0.6.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "22cddaf88f4fbc13c51aebbf5f8eceb5c7c5a9da2ac40a13519eb5b0a0e8f11c" +dependencies = [ + "serde", +] + +[[package]] +name = "toml_datetime" +version = "0.7.5+spec-1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "92e1cfed4a3038bc5a127e35a2d360f145e1f4b971b551a2ba5fd7aedf7e1347" +dependencies = [ + "serde_core", +] + +[[package]] +name = "toml_edit" +version = "0.22.27" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "41fe8c660ae4257887cf66394862d21dbca4a6ddd26f04a3560410406a2f819a" +dependencies = [ + "indexmap 2.13.0", + "serde", + "serde_spanned", + "toml_datetime 0.6.11", + "toml_write", + "winnow", +] + +[[package]] +name = "toml_edit" +version = "0.23.10+spec-1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "84c8b9f757e028cee9fa244aea147aab2a9ec09d5325a9b01e0a49730c2b5269" +dependencies = [ + "indexmap 2.13.0", + "toml_datetime 0.7.5+spec-1.1.0", + "toml_parser", + "winnow", +] + +[[package]] +name = "toml_parser" +version = "1.0.6+spec-1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a3198b4b0a8e11f09dd03e133c0280504d0801269e9afa46362ffde1cbeebf44" +dependencies = [ + "winnow", +] + +[[package]] +name = "toml_write" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5d99f8c9a7727884afe522e9bd5edbfc91a3312b36a77b5fb8926e4c31a41801" + +[[package]] +name = "tower" +version = "0.5.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ebe5ef63511595f1344e2d5cfa636d973292adc0eec1f0ad45fae9f0851ab1d4" +dependencies = [ + "futures-core", + "futures-util", + "pin-project-lite", + "sync_wrapper 1.0.2", + "tokio", + "tower-layer", + "tower-service", +] + +[[package]] +name = "tower-http" +version = "0.6.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d4e6559d53cc268e5031cd8429d05415bc4cb4aefc4aa5d6cc35fbf5b924a1f8" +dependencies = [ + "async-compression", + "bitflags 2.10.0", + "bytes", + "futures-core", + "futures-util", + "http 1.4.0", + "http-body 1.0.1", + "http-body-util", + "iri-string", + "pin-project-lite", + "tokio", + "tokio-util 0.7.18", + "tower", + "tower-layer", + "tower-service", +] + +[[package]] +name = "tower-layer" +version = "0.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "121c2a6cda46980bb0fcd1647ffaf6cd3fc79a013de288782836f6df9c48780e" + +[[package]] +name = "tower-service" +version = "0.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8df9b6e13f2d32c91b9bd719c00d1958837bc7dec474d94952798cc8e69eeec3" + +[[package]] +name = "tracing" +version = "0.1.44" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "63e71662fa4b2a2c3a26f570f037eb95bb1f85397f3cd8076caed2f026a6d100" +dependencies = [ + "log", + "pin-project-lite", + "tracing-attributes", + "tracing-core", +] + +[[package]] +name = "tracing-attributes" +version = "0.1.31" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7490cfa5ec963746568740651ac6781f701c9c5ea257c58e057f3ba8cf69e8da" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.114", +] + +[[package]] +name = "tracing-core" +version = "0.1.36" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "db97caf9d906fbde555dd62fa95ddba9eecfd14cb388e4f491a66d74cd5fb79a" +dependencies = [ + "once_cell", + "valuable", +] + +[[package]] +name = "tracing-opentelemetry" +version = "0.17.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fbbe89715c1dbbb790059e2565353978564924ee85017b5fff365c872ff6721f" +dependencies = [ + "once_cell", + "opentelemetry", + "tracing", + "tracing-core", + "tracing-subscriber", +] + +[[package]] +name = "tracing-subscriber" +version = "0.3.22" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2f30143827ddab0d256fd843b7a66d164e9f271cfa0dde49142c5ca0ca291f1e" +dependencies = [ + "sharded-slab", + "thread_local", + "tracing-core", +] + +[[package]] +name = "try-lock" +version = "0.2.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e421abadd41a4225275504ea4d6566923418b7f05506fbc9c0fe86ba7396114b" + +[[package]] +name = "typenum" +version = "1.19.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "562d481066bde0658276a35467c4af00bdc6ee726305698a55b86e61d7ad82bb" + +[[package]] +name = "unicase" +version = "2.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dbc4bc3a9f746d862c45cb89d705aa10f187bb96c76001afab07a0d35ce60142" + +[[package]] +name = "unicode-ident" +version = "1.0.22" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9312f7c4f6ff9069b165498234ce8be658059c6728633667c526e27dc2cf1df5" + +[[package]] +name = "unicode-segmentation" +version = "1.12.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f6ccf251212114b54433ec949fd6a7841275f9ada20dddd2f29e9ceea4501493" + +[[package]] +name = "unicode-width" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b4ac048d71ede7ee76d585517add45da530660ef4390e49b098733c6e897f254" + +[[package]] +name = "universal-hash" +version = "0.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fc1de2c688dc15305988b563c3854064043356019f97a4b46276fe734c4f07ea" +dependencies = [ + "crypto-common", + "subtle", +] + +[[package]] +name = "unreachable" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "382810877fe448991dfc7f0dd6e3ae5d58088fd0ea5e35189655f84e6814fa56" +dependencies = [ + "void", +] + +[[package]] +name = "untrusted" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8ecb6da28b8a351d773b68d5825ac39017e680750f980f3a1a85cd8dd28a47c1" + +[[package]] +name = "uriparse" +version = "0.6.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0200d0fc04d809396c2ad43f3c95da3582a2556eba8d453c1087f4120ee352ff" +dependencies = [ + "fnv", + "lazy_static", +] + +[[package]] +name = "url" +version = "2.5.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ff67a8a4397373c3ef660812acab3268222035010ab8680ec4215f38ba3d0eed" +dependencies = [ + "form_urlencoded", + "idna", + "percent-encoding", + "serde", +] + +[[package]] +name = "utf8_iter" +version = "1.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b6c140620e7ffbb22c2dee59cafe6084a59b5ffc27a8859a5f0d494b5d52b6be" + +[[package]] +name = "uuid" +version = "1.20.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ee48d38b119b0cd71fe4141b30f5ba9c7c5d9f4e7a3a8b4a674e4b6ef789976f" +dependencies = [ + "getrandom 0.3.4", + "js-sys", + "serde_core", + "wasm-bindgen", +] + +[[package]] +name = "valuable" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ba73ea9cf16a25df0c8caa16c51acb937d5712a8429db78a3ee29d5dcacd3a65" + +[[package]] +name = "vcpkg" +version = "0.2.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "accd4ea62f7bb7a82fe23066fb0957d48ef677f6eeb8215f372f52e48bb32426" + +[[package]] +name = "version_check" +version = "0.9.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0b928f33d975fc6ad9f86c8f283853ad26bdd5b10b7f1542aa2fa15e2289105a" + +[[package]] +name = "void" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6a02e4885ed3bc0f2de90ea6dd45ebcbb66dacffe03547fadbb0eeae2770887d" + +[[package]] +name = "want" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bfa7760aed19e106de2c7c0b581b509f2f25d3dacaf737cb82ac61bc6d760b0e" +dependencies = [ + "try-lock", +] + +[[package]] +name = "wasi" +version = "0.9.0+wasi-snapshot-preview1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cccddf32554fecc6acb585f82a32a72e28b48f8c4c1883ddfeeeaa96f7d8e519" + +[[package]] +name = "wasi" +version = "0.11.1+wasi-snapshot-preview1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ccf3ec651a847eb01de73ccad15eb7d99f80485de043efb2f370cd654f4ea44b" + +[[package]] +name = "wasip2" +version = "1.0.2+wasi-0.2.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9517f9239f02c069db75e65f174b3da828fe5f5b945c4dd26bd25d89c03ebcf5" +dependencies = [ + "wit-bindgen", +] + +[[package]] +name = "wasm-bindgen" +version = "0.2.108" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "64024a30ec1e37399cf85a7ffefebdb72205ca1c972291c51512360d90bd8566" +dependencies = [ + "cfg-if", + "once_cell", + "rustversion", + "wasm-bindgen-macro", + "wasm-bindgen-shared", +] + +[[package]] +name = "wasm-bindgen-futures" +version = "0.4.58" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "70a6e77fd0ae8029c9ea0063f87c46fde723e7d887703d74ad2616d792e51e6f" +dependencies = [ + "cfg-if", + "futures-util", + "js-sys", + "once_cell", + "wasm-bindgen", + "web-sys", +] + +[[package]] +name = "wasm-bindgen-macro" +version = "0.2.108" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "008b239d9c740232e71bd39e8ef6429d27097518b6b30bdf9086833bd5b6d608" +dependencies = [ + "quote", + "wasm-bindgen-macro-support", +] + +[[package]] +name = "wasm-bindgen-macro-support" +version = "0.2.108" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5256bae2d58f54820e6490f9839c49780dff84c65aeab9e772f15d5f0e913a55" +dependencies = [ + "bumpalo", + "proc-macro2", + "quote", + "syn 2.0.114", + "wasm-bindgen-shared", +] + +[[package]] +name = "wasm-bindgen-shared" +version = "0.2.108" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1f01b580c9ac74c8d8f0c0e4afb04eeef2acf145458e52c03845ee9cd23e3d12" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "web-sys" +version = "0.3.85" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "312e32e551d92129218ea9a2452120f4aabc03529ef03e4d0d82fb2780608598" +dependencies = [ + "js-sys", + "wasm-bindgen", +] + +[[package]] +name = "web-time" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5a6580f308b1fad9207618087a65c04e7a10bc77e02c8e84e9b00dd4b12fa0bb" +dependencies = [ + "js-sys", + "wasm-bindgen", +] + +[[package]] +name = "webpki-roots" +version = "0.25.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5f20c57d8d7db6d3b86154206ae5d8fba62dd39573114de97c2cb0578251f8e1" + +[[package]] +name = "webpki-roots" +version = "1.0.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "12bed680863276c63889429bfd6cab3b99943659923822de1c8a39c49e4d722c" +dependencies = [ + "rustls-pki-types", +] + +[[package]] +name = "winapi" +version = "0.3.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419" +dependencies = [ + "winapi-i686-pc-windows-gnu", + "winapi-x86_64-pc-windows-gnu", +] + +[[package]] +name = "winapi-i686-pc-windows-gnu" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" + +[[package]] +name = "winapi-util" +version = "0.1.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c2a7b1c03c876122aa43f3020e6c3c3ee5c05081c9a00739faf7503aeba10d22" +dependencies = [ + "windows-sys 0.61.2", +] + +[[package]] +name = "winapi-x86_64-pc-windows-gnu" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" + +[[package]] +name = "windows-core" +version = "0.62.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b8e83a14d34d0623b51dce9581199302a221863196a1dde71a7663a4c2be9deb" +dependencies = [ + "windows-implement", + "windows-interface", + "windows-link", + "windows-result", + "windows-strings", +] + +[[package]] +name = "windows-implement" +version = "0.60.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "053e2e040ab57b9dc951b72c264860db7eb3b0200ba345b4e4c3b14f67855ddf" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.114", +] + +[[package]] +name = "windows-interface" +version = "0.59.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3f316c4a2570ba26bbec722032c4099d8c8bc095efccdc15688708623367e358" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.114", +] + +[[package]] +name = "windows-link" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f0805222e57f7521d6a62e36fa9163bc891acd422f971defe97d64e70d0a4fe5" + +[[package]] +name = "windows-registry" +version = "0.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "02752bf7fbdcce7f2a27a742f798510f3e5ad88dbe84871e5168e2120c3d5720" +dependencies = [ + "windows-link", + "windows-result", + "windows-strings", +] + +[[package]] +name = "windows-result" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7781fa89eaf60850ac3d2da7af8e5242a5ea78d1a11c49bf2910bb5a73853eb5" +dependencies = [ + "windows-link", +] + +[[package]] +name = "windows-strings" +version = "0.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7837d08f69c77cf6b07689544538e017c1bfcf57e34b4c0ff58e6c2cd3b37091" +dependencies = [ + "windows-link", +] + +[[package]] +name = "windows-sys" +version = "0.48.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "677d2418bec65e3338edb076e806bc1ec15693c5d0104683f2efe857f61056a9" +dependencies = [ + "windows-targets 0.48.5", +] + +[[package]] +name = "windows-sys" +version = "0.52.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d" +dependencies = [ + "windows-targets 0.52.6", +] + +[[package]] +name = "windows-sys" +version = "0.59.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e38bc4d79ed67fd075bcc251a1c39b32a1776bbe92e5bef1f0bf1f8c531853b" +dependencies = [ + "windows-targets 0.52.6", +] + +[[package]] +name = "windows-sys" +version = "0.60.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f2f500e4d28234f72040990ec9d39e3a6b950f9f22d3dba18416c35882612bcb" +dependencies = [ + "windows-targets 0.53.5", +] + +[[package]] +name = "windows-sys" +version = "0.61.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ae137229bcbd6cdf0f7b80a31df61766145077ddf49416a728b02cb3921ff3fc" +dependencies = [ + "windows-link", +] + +[[package]] +name = "windows-targets" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9a2fa6e2155d7247be68c096456083145c183cbbbc2764150dda45a87197940c" +dependencies = [ + "windows_aarch64_gnullvm 0.48.5", + "windows_aarch64_msvc 0.48.5", + "windows_i686_gnu 0.48.5", + "windows_i686_msvc 0.48.5", + "windows_x86_64_gnu 0.48.5", + "windows_x86_64_gnullvm 0.48.5", + "windows_x86_64_msvc 0.48.5", +] + +[[package]] +name = "windows-targets" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9b724f72796e036ab90c1021d4780d4d3d648aca59e491e6b98e725b84e99973" +dependencies = [ + "windows_aarch64_gnullvm 0.52.6", + "windows_aarch64_msvc 0.52.6", + "windows_i686_gnu 0.52.6", + "windows_i686_gnullvm 0.52.6", + "windows_i686_msvc 0.52.6", + "windows_x86_64_gnu 0.52.6", + "windows_x86_64_gnullvm 0.52.6", + "windows_x86_64_msvc 0.52.6", +] + +[[package]] +name = "windows-targets" +version = "0.53.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4945f9f551b88e0d65f3db0bc25c33b8acea4d9e41163edf90dcd0b19f9069f3" +dependencies = [ + "windows-link", + "windows_aarch64_gnullvm 0.53.1", + "windows_aarch64_msvc 0.53.1", + "windows_i686_gnu 0.53.1", + "windows_i686_gnullvm 0.53.1", + "windows_i686_msvc 0.53.1", + "windows_x86_64_gnu 0.53.1", + "windows_x86_64_gnullvm 0.53.1", + "windows_x86_64_msvc 0.53.1", +] + +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2b38e32f0abccf9987a4e3079dfb67dcd799fb61361e53e2882c3cbaf0d905d8" + +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "32a4622180e7a0ec044bb555404c800bc9fd9ec262ec147edd5989ccd0c02cd3" + +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.53.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a9d8416fa8b42f5c947f8482c43e7d89e73a173cead56d044f6a56104a6d1b53" + +[[package]] +name = "windows_aarch64_msvc" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dc35310971f3b2dbbf3f0690a219f40e2d9afcf64f9ab7cc1be722937c26b4bc" + +[[package]] +name = "windows_aarch64_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "09ec2a7bb152e2252b53fa7803150007879548bc709c039df7627cabbd05d469" + +[[package]] +name = "windows_aarch64_msvc" +version = "0.53.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b9d782e804c2f632e395708e99a94275910eb9100b2114651e04744e9b125006" + +[[package]] +name = "windows_i686_gnu" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a75915e7def60c94dcef72200b9a8e58e5091744960da64ec734a6c6e9b3743e" + +[[package]] +name = "windows_i686_gnu" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8e9b5ad5ab802e97eb8e295ac6720e509ee4c243f69d781394014ebfe8bbfa0b" + +[[package]] +name = "windows_i686_gnu" +version = "0.53.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "960e6da069d81e09becb0ca57a65220ddff016ff2d6af6a223cf372a506593a3" + +[[package]] +name = "windows_i686_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0eee52d38c090b3caa76c563b86c3a4bd71ef1a819287c19d586d7334ae8ed66" + +[[package]] +name = "windows_i686_gnullvm" +version = "0.53.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fa7359d10048f68ab8b09fa71c3daccfb0e9b559aed648a8f95469c27057180c" + +[[package]] +name = "windows_i686_msvc" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8f55c233f70c4b27f66c523580f78f1004e8b5a8b659e05a4eb49d4166cca406" + +[[package]] +name = "windows_i686_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "240948bc05c5e7c6dabba28bf89d89ffce3e303022809e73deaefe4f6ec56c66" + +[[package]] +name = "windows_i686_msvc" +version = "0.53.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e7ac75179f18232fe9c285163565a57ef8d3c89254a30685b57d83a38d326c2" + +[[package]] +name = "windows_x86_64_gnu" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "53d40abd2583d23e4718fddf1ebec84dbff8381c07cae67ff7768bbf19c6718e" + +[[package]] +name = "windows_x86_64_gnu" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "147a5c80aabfbf0c7d901cb5895d1de30ef2907eb21fbbab29ca94c5b08b1a78" + +[[package]] +name = "windows_x86_64_gnu" +version = "0.53.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9c3842cdd74a865a8066ab39c8a7a473c0778a3f29370b5fd6b4b9aa7df4a499" + +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0b7b52767868a23d5bab768e390dc5f5c55825b6d30b86c844ff2dc7414044cc" + +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "24d5b23dc417412679681396f2b49f3de8c1473deb516bd34410872eff51ed0d" + +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.53.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0ffa179e2d07eee8ad8f57493436566c7cc30ac536a3379fdf008f47f6bb7ae1" + +[[package]] +name = "windows_x86_64_msvc" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ed94fce61571a4006852b7389a063ab983c02eb1bb37b47f8272ce92d06d9538" + +[[package]] +name = "windows_x86_64_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec" + +[[package]] +name = "windows_x86_64_msvc" +version = "0.53.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d6bbff5f0aada427a1e5a6da5f1f98158182f26556f345ac9e04d36d0ebed650" + +[[package]] +name = "winnow" +version = "0.7.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5a5364e9d77fcdeeaa6062ced926ee3381faa2ee02d3eb83a5c27a8825540829" +dependencies = [ + "memchr", +] + +[[package]] +name = "winreg" +version = "0.50.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "524e57b2c537c0f9b1e69f1965311ec12182b4122e45035b1508cd24d2adadb1" +dependencies = [ + "cfg-if", + "windows-sys 0.48.0", +] + +[[package]] +name = "wit-bindgen" +version = "0.51.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d7249219f66ced02969388cf2bb044a09756a083d0fab1e566056b04d9fbcaa5" + +[[package]] +name = "writeable" +version = "0.6.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9edde0db4769d2dc68579893f2306b26c6ecfbe0ef499b013d731b7b9247e0b9" + +[[package]] +name = "wyz" +version = "0.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "05f360fc0b24296329c78fda852a1e9ae82de9cf7b27dae4b7f62f118f77b9ed" +dependencies = [ + "tap", +] + +[[package]] +name = "yoke" +version = "0.8.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "72d6e5c6afb84d73944e5cedb052c4680d5657337201555f9f2a16b7406d4954" +dependencies = [ + "stable_deref_trait", + "yoke-derive", + "zerofrom", +] + +[[package]] +name = "yoke-derive" +version = "0.8.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b659052874eb698efe5b9e8cf382204678a0086ebf46982b79d6ca3182927e5d" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.114", + "synstructure", +] + +[[package]] +name = "zerocopy" +version = "0.8.35" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fdea86ddd5568519879b8187e1cf04e24fce28f7fe046ceecbce472ff19a2572" +dependencies = [ + "zerocopy-derive", +] + +[[package]] +name = "zerocopy-derive" +version = "0.8.35" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0c15e1b46eff7c6c91195752e0eeed8ef040e391cdece7c25376957d5f15df22" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.114", +] + +[[package]] +name = "zerofrom" +version = "0.1.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "50cc42e0333e05660c3587f3bf9d0478688e15d870fab3346451ce7f8c9fbea5" +dependencies = [ + "zerofrom-derive", +] + +[[package]] +name = "zerofrom-derive" +version = "0.1.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d71e5d6e06ab090c67b5e44993ec16b72dcbaabc526db883a360057678b48502" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.114", + "synstructure", +] + +[[package]] +name = "zeroize" +version = "1.8.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b97154e67e32c85465826e8bcc1c59429aaaf107c1e4a9e53c8d8ccd5eff88d0" +dependencies = [ + "zeroize_derive", +] + +[[package]] +name = "zeroize_derive" +version = "1.4.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "85a5b4158499876c763cb03bc4e49185d3cccbabb15b33c627f7884f43db852e" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.114", +] + +[[package]] +name = "zerotrie" +version = "0.2.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2a59c17a5562d507e4b54960e8569ebee33bee890c70aa3fe7b97e85a9fd7851" +dependencies = [ + "displaydoc", + "yoke", + "zerofrom", +] + +[[package]] +name = "zerovec" +version = "0.11.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6c28719294829477f525be0186d13efa9a3c602f7ec202ca9e353d310fb9a002" +dependencies = [ + "yoke", + "zerofrom", + "zerovec-derive", +] + +[[package]] +name = "zerovec-derive" +version = "0.11.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "eadce39539ca5cb3985590102671f2567e659fca9666581ad3411d59207951f3" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.114", +] + +[[package]] +name = "zmij" +version = "1.0.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "02aae0f83f69aafc94776e879363e9771d7ecbffe2c7fbb6c14c5e00dfe88439" + +[[package]] +name = "zstd" +version = "0.13.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e91ee311a569c327171651566e07972200e76fcfe2242a4fa446149a3881c08a" +dependencies = [ + "zstd-safe", +] + +[[package]] +name = "zstd-safe" +version = "7.2.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8f49c4d5f0abb602a93fb8736af2a4f4dd9512e36f7f570d66e65ff867ed3b9d" +dependencies = [ + "zstd-sys", +] + +[[package]] +name = "zstd-sys" +version = "2.0.16+zstd.1.5.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "91e19ebc2adc8f83e43039e79776e3fda8ca919132d68a1fed6a5faca2683748" +dependencies = [ + "cc", + "pkg-config", +] diff --git a/programs/anchor/Cargo.toml b/programs/anchor/Cargo.toml new file mode 100644 index 0000000..4a2efb3 --- /dev/null +++ b/programs/anchor/Cargo.toml @@ -0,0 +1,70 @@ +[workspace] +resolver = "2" +members = [ + "escrow", + "fundraiser", + "light-token-minter", + "token-swap", + "shared-test-utils", +] + +[profile.release] +lto = "fat" +codegen-units = 1 +panic = "abort" +overflow-checks = true + +[profile.release.build-override] +opt-level = 3 +incremental = false +codegen-units = 1 + +[workspace.dependencies] +# Pin blake3 version for solana-program compatibility +blake3 = { version = "=1.5.5", default-features = false } + +# Anchor +anchor-lang = "0.31.1" +anchor-spl = "0.31.1" + +# Solana +solana-sdk = "2" +solana-program = "2" +solana-pubkey = "2" +solana-msg = "2" +solana-account-info = "2" +solana-program-error = "2" +solana-instruction = "2" +solana-keypair = "2" +solana-signer = "2" + +# SPL +spl-token = "7" +spl-token-2022 = "7" +spl-pod = "0.5" + +# Light Protocol +light-sdk = { version = "0.19.0", features = ["anchor", "idl-build", "v2", "anchor-discriminator", "cpi-context"] } +light-sdk-macros = "0.19.0" +light-sdk-types = { version = "0.19.0", features = ["v2", "cpi-context"] } +light-compressible = { version = "0.4.0", features = ["anchor"] } +light-hasher = { version = "5.0.0", features = ["solana"] } +light-macros = "2.2.0" +light-compressed-account = "0.9.0" +light-token = { version = "0.4.0", features = ["anchor"] } +light-token-types = { version = "0.4.0", features = ["anchor"] } +light-token-interface = "0.3.0" +light-program-test = "0.19.0" +light-client = { version = "0.19.0", features = ["v2", "anchor"] } +light-anchor-spl = { version = "0.31.1", features = ["idl-build"] } + +# Testing +tokio = "1.43.0" +borsh = "0.10.4" + +# Pin time to avoid time-macros 0.2.26 which requires edition2024 +# (cargo build-sbf bundles Cargo 1.84.0 which doesn't support it) +time = "=0.3.41" + +# Internal +shared-test-utils = { path = "shared-test-utils" } diff --git a/programs/anchor/README.md b/programs/anchor/README.md new file mode 100644 index 0000000..1633349 --- /dev/null +++ b/programs/anchor/README.md @@ -0,0 +1,60 @@ +# Light Token Anchor Solana Programs + +- **[escrow](escrow/src/lib.rs)** - Peer-to-peer light-token swap with offer/accept flow +- **[fundraiser](fundraiser/src/lib.rs)** - Token Fundraiser with target, deadline, and refunds +- **[light-token-minter](light-token-minter/src/lib.rs)** - Create light-mints with metadata, mint tokens +- **[token-swap](token-swap/src/lib.rs)** - AMM with liquidity pools and swaps + +## Basic Macros + +- [**counter**](basic-macros/counter/src/lib.rs) - Minimal Light-PDA example +- [**create-mint**](basic-macros/create-mint/src/lib.rs) - Create a light-token mint +- [**create-ata**](basic-macros/create-ata/src/lib.rs) - Create an associated light-token account +- [**create-token-account**](basic-macros/create-token-account/src/lib.rs) - Create a light-token account + +## Basic Instructions + +- [**create-mint**](basic-instructions/create-mint/src/lib.rs) - Create a light-token mint via CPI +- [**create-ata**](basic-instructions/create-ata/src/lib.rs) - Create an associated light-token account via CPI +- [**create-token-account**](basic-instructions/create-token-account/src/lib.rs) - Create a light-token account via CPI +- [**mint-to**](basic-instructions/mint-to/src/lib.rs) - Mint tokens via CPI +- [**mint-to-checked**](basic-instructions/mint-to-checked/src/lib.rs) - Mint tokens with decimal validation via CPI +- [**transfer-interface**](basic-instructions/transfer-interface/src/lib.rs) - Transfer between light-token, T22, and SPL accounts via CPI +- [**transfer-checked**](basic-instructions/transfer-checked/src/lib.rs) - Transfer with decimal validation against mint via CPI +- [**approve**](basic-instructions/approve/src/lib.rs) - Approve delegate via CPI +- [**revoke**](basic-instructions/revoke/src/lib.rs) - Revoke delegate via CPI +- [**burn**](basic-instructions/burn/src/lib.rs) - Burn tokens via CPI +- [**freeze**](basic-instructions/freeze/src/lib.rs) - Freeze token account via CPI +- [**thaw**](basic-instructions/thaw/src/lib.rs) - Thaw token account via CPI +- [**close**](basic-instructions/close/src/lib.rs) - Close token account via CPI + +## Test + +### Requirements + +- light cli (install via `npm i -g @lightprotocol/zk-compression-cli@beta`) +- Solana CLI 2.2.15+ +- Anchor 0.31.1+ +- Rust 1.90.0+ + +### Build + +```bash +anchor build +``` + +### Run tests + +```bash +cargo test-sbf -p escrow +cargo test-sbf -p fundraiser +cargo test-sbf -p light-token-minter +cargo test-sbf -p swap_example +``` + +## Documentation + +Learn more [about Light-Token here](https://www.zkcompression.com/light-token/welcome). + +API is in Beta and subject to change. +Questions or need hands-on support? Join the Developer [Discord](https://discord.com/invite/7cJ8BhAXhu). \ No newline at end of file diff --git a/programs/anchor/escrow/Cargo.toml b/programs/anchor/escrow/Cargo.toml new file mode 100644 index 0000000..a870cac --- /dev/null +++ b/programs/anchor/escrow/Cargo.toml @@ -0,0 +1,54 @@ +[package] +name = "escrow" +version = "0.1.0" +edition = "2021" + +[lib] +crate-type = ["cdylib", "lib"] +name = "escrow" + +[features] +no-entrypoint = [] +no-log-ix-name = [] +no-idl = [] +cpi = ["no-entrypoint"] +default = [] +idl-build = ["anchor-lang/idl-build", "light-sdk/idl-build"] +test-sbf = [] + +[dependencies] +anchor-lang = { version = "=0.31.1", features = ["idl-build"] } +# Pin blake3 version for solana-program compatibility +blake3 = { workspace = true } + +light-sdk = { workspace = true, features = ["anchor", "anchor-discriminator", "idl-build", "cpi-context", "v2"] } +light-token = { workspace = true, features = ["anchor"] } +# Required by LightAccount derive macro +light-hasher = { workspace = true, features = ["solana"] } +light-anchor-spl = { workspace = true, features = ["idl-build"] } +solana-program = { workspace = true } +solana-pubkey = { workspace = true } +solana-account-info = { workspace = true } +solana-program-error = { workspace = true } +solana-msg = { workspace = true } + +[dev-dependencies] +light-program-test = { workspace = true } +light-client = { workspace = true, features = ["v2", "anchor"] } +anchor-spl = { workspace = true } +tokio = { workspace = true, features = ["full"] } +solana-keypair = { workspace = true } +solana-signer = { workspace = true } +solana-instruction = { workspace = true } +solana-sdk = { workspace = true } +spl-token-2022 = { workspace = true } +spl-pod = { workspace = true } +shared-test-utils = { workspace = true } +light-token-minter = { path = "../light-token-minter", features = ["no-entrypoint"] } + +[lints.rust.unexpected_cfgs] +level = "allow" +check-cfg = [ + 'cfg(target_os, values("solana"))', + 'cfg(feature, values("frozen-abi", "no-entrypoint"))', +] diff --git a/programs/anchor/escrow/src/constants.rs b/programs/anchor/escrow/src/constants.rs new file mode 100644 index 0000000..41af5c3 --- /dev/null +++ b/programs/anchor/escrow/src/constants.rs @@ -0,0 +1,4 @@ +pub const OFFER_SEED: &[u8] = b"offer"; +pub const VAULT_SEED: &[u8] = b"vault"; +pub const AUTH_SEED: &[u8] = b"authority"; +pub const ANCHOR_DISCRIMINATOR: usize = 8; diff --git a/programs/anchor/escrow/src/instructions/make_offer.rs b/programs/anchor/escrow/src/instructions/make_offer.rs new file mode 100644 index 0000000..f12b4be --- /dev/null +++ b/programs/anchor/escrow/src/instructions/make_offer.rs @@ -0,0 +1,148 @@ +use anchor_lang::prelude::*; +use light_anchor_spl::token_interface::{Mint, TokenAccount, TokenInterface}; +use light_sdk::interface::CreateAccountsProof; +use light_token::anchor::LightAccounts; +use light_token::instruction::{COMPRESSIBLE_CONFIG_V1, RENT_SPONSOR}; + +use light_token::spl_interface::find_spl_interface_pda; + +use crate::constants::{ANCHOR_DISCRIMINATOR, AUTH_SEED, OFFER_SEED, VAULT_SEED}; +use crate::instructions::{transfer_tokens, SplInterfaceConfig}; +use crate::state::Offer; + +#[derive(AnchorSerialize, AnchorDeserialize, Clone)] +pub struct MakeOfferParams { + pub create_accounts_proof: CreateAccountsProof, + pub id: u64, + pub token_a_offered_amount: u64, + pub token_b_wanted_amount: u64, + pub vault_bump: u8, +} + +#[derive(Accounts, LightAccounts)] +#[instruction(params: MakeOfferParams)] +pub struct MakeOffer<'info> { + #[account(mut)] + pub fee_payer: Signer<'info>, + + /// CHECK: Authority PDA for the vault + #[account( + seeds = [AUTH_SEED], + bump, + )] + pub authority: UncheckedAccount<'info>, + + /// CHECK: Config for light mint creation + pub compression_config: AccountInfo<'info>, + + #[account(mint::token_program = token_program)] + pub token_mint_a: InterfaceAccount<'info, Mint>, + + #[account(mint::token_program = token_program)] + pub token_mint_b: InterfaceAccount<'info, Mint>, + + #[account( + mut, + token::mint = token_mint_a, + token::authority = fee_payer, + )] + pub maker_token_account_a: InterfaceAccount<'info, TokenAccount>, + + #[account( + init, + payer = fee_payer, + space = ANCHOR_DISCRIMINATOR + Offer::INIT_SPACE, + seeds = [OFFER_SEED, fee_payer.key().as_ref(), params.id.to_le_bytes().as_ref()], + bump, + )] + #[light_account(init)] + pub offer: Account<'info, Offer>, + + /// CHECK: Vault PDA - initialized by light_account macro + #[account( + mut, + seeds = [VAULT_SEED, offer.key().as_ref()], + bump, + )] + #[light_account(init, + token::authority = [VAULT_SEED, self.offer.key()], + token::mint = token_mint_a, + token::owner = authority, + token::bump = params.vault_bump + )] + pub vault: UncheckedAccount<'info>, + + pub token_program: Interface<'info, TokenInterface>, + pub system_program: Program<'info, System>, + + /// Light token program for CPI calls + pub light_token_program: Interface<'info, TokenInterface>, + + /// CHECK: Light token compressible config - validated by address constraint + #[account(address = COMPRESSIBLE_CONFIG_V1)] + pub light_token_compressible_config: AccountInfo<'info>, + + /// CHECK: Light token rent sponsor - validated by address constraint + #[account(mut, address = RENT_SPONSOR)] + pub light_token_rent_sponsor: AccountInfo<'info>, + + /// CHECK: light-token CPI authority - must be writable for Light token CPI + #[account(mut)] + pub light_token_cpi_authority: AccountInfo<'info>, + + /// CHECK: SPL interface PDA for mint A + #[account(mut)] + pub spl_interface_pda_a: UncheckedAccount<'info>, +} + +pub fn send_offered_tokens_to_vault<'info>( + ctx: &Context<'_, '_, '_, 'info, MakeOffer<'info>>, + params: &MakeOfferParams, +) -> Result<()> { + let decimals = ctx.accounts.token_mint_a.decimals; + let (_, spl_interface_bump_a) = + find_spl_interface_pda(&ctx.accounts.token_mint_a.key(), false); + + let spl_interface = SplInterfaceConfig { + mint: ctx.accounts.token_mint_a.to_account_info(), + spl_token_program: ctx.accounts.token_program.to_account_info(), + spl_interface_pda: ctx.accounts.spl_interface_pda_a.to_account_info(), + spl_interface_pda_bump: spl_interface_bump_a, + }; + + transfer_tokens( + params.token_a_offered_amount, + decimals, + ctx.accounts.maker_token_account_a.to_account_info(), + ctx.accounts.vault.to_account_info(), + ctx.accounts.token_mint_a.to_account_info(), + ctx.accounts.fee_payer.to_account_info(), + ctx.accounts.fee_payer.to_account_info(), + ctx.accounts.light_token_cpi_authority.to_account_info(), + ctx.accounts.system_program.to_account_info(), + None, + Some(spl_interface), + ) +} + +pub fn save_offer<'info>( + ctx: &mut Context<'_, '_, '_, 'info, MakeOffer<'info>>, + params: &MakeOfferParams, +) -> Result<()> { + let offer = &mut ctx.accounts.offer; + offer.id = params.id; + offer.maker = ctx.accounts.fee_payer.key(); + offer.token_mint_a = ctx.accounts.token_mint_a.key(); + offer.token_mint_b = ctx.accounts.token_mint_b.key(); + offer.token_b_wanted_amount = params.token_b_wanted_amount; + offer.auth_bump = ctx.bumps.authority; + + msg!( + "Offer created: id={}, maker={}, offered={} token_a, wants={} token_b", + params.id, + ctx.accounts.fee_payer.key(), + params.token_a_offered_amount, + params.token_b_wanted_amount + ); + Ok(()) +} diff --git a/programs/anchor/escrow/src/instructions/mod.rs b/programs/anchor/escrow/src/instructions/mod.rs new file mode 100644 index 0000000..fa298ca --- /dev/null +++ b/programs/anchor/escrow/src/instructions/mod.rs @@ -0,0 +1,7 @@ +pub mod make_offer; +pub mod shared; +pub mod take_offer; + +pub use make_offer::*; +pub use shared::*; +pub use take_offer::*; diff --git a/programs/anchor/escrow/src/instructions/shared.rs b/programs/anchor/escrow/src/instructions/shared.rs new file mode 100644 index 0000000..4a25358 --- /dev/null +++ b/programs/anchor/escrow/src/instructions/shared.rs @@ -0,0 +1,86 @@ +use anchor_lang::prelude::*; +use light_sdk::constants::LIGHT_TOKEN_PROGRAM_ID; +use light_token::instruction::{TransferCheckedCpi, TransferInterfaceCpi}; + +/// Configuration for SPL interface (required for SPL<->Light transfers) +pub struct SplInterfaceConfig<'info> { + pub mint: AccountInfo<'info>, + pub spl_token_program: AccountInfo<'info>, + pub spl_interface_pda: AccountInfo<'info>, + pub spl_interface_pda_bump: u8, +} + +/// Check if an account is a Light token account (owned by Light token program) +fn is_light_account(account: &AccountInfo) -> bool { + account.owner == &Pubkey::new_from_array(LIGHT_TOKEN_PROGRAM_ID) +} + +/// Transfer tokens between token accounts. +/// For Light-to-Light transfers, uses TransferCheckedCpi with mint validation. +/// For SPL<->Light transfers, uses TransferInterfaceCpi with spl_interface config. +pub fn transfer_tokens<'info>( + amount: u64, + decimals: u8, + from: AccountInfo<'info>, + to: AccountInfo<'info>, + mint: AccountInfo<'info>, + authority: AccountInfo<'info>, + payer: AccountInfo<'info>, + light_token_cpi_authority: AccountInfo<'info>, + system_program: AccountInfo<'info>, + signer_seeds: Option<&[&[u8]]>, + spl_interface: Option>, +) -> Result<()> { + let is_light_to_light = is_light_account(&from) && is_light_account(&to); + + if is_light_to_light { + // fee_payer: Some ensures authority is readonly (required for PDA with account data) + let cpi = TransferCheckedCpi { + source: from, + mint, + destination: to, + amount, + decimals, + authority, + system_program, + max_top_up: Some(0), + fee_payer: Some(payer), + }; + + if let Some(seeds) = signer_seeds { + cpi.invoke_signed(&[seeds]) + } else { + cpi.invoke() + } + .map_err(|e| anchor_lang::prelude::ProgramError::from(e).into()) + } else { + let mut cpi = TransferInterfaceCpi::new( + amount, + decimals, + from, + to, + authority, + payer, + light_token_cpi_authority, + system_program, + ); + + if let Some(spl) = spl_interface { + cpi = cpi + .with_spl_interface( + Some(spl.mint), + Some(spl.spl_token_program), + Some(spl.spl_interface_pda), + Some(spl.spl_interface_pda_bump), + ) + .map_err(|e| anchor_lang::prelude::ProgramError::from(e))?; + } + + if let Some(seeds) = signer_seeds { + cpi.invoke_signed(&[seeds]) + } else { + cpi.invoke() + } + .map_err(|e| anchor_lang::prelude::ProgramError::from(e).into()) + } +} diff --git a/programs/anchor/escrow/src/instructions/take_offer.rs b/programs/anchor/escrow/src/instructions/take_offer.rs new file mode 100644 index 0000000..480b6ce --- /dev/null +++ b/programs/anchor/escrow/src/instructions/take_offer.rs @@ -0,0 +1,178 @@ +use anchor_lang::prelude::*; +use light_anchor_spl::token_interface::{Mint, TokenAccount, TokenInterface}; +use light_token::instruction::{CloseAccountCpi, RENT_SPONSOR}; +use light_token::utils::get_token_account_balance; + +use light_token::spl_interface::find_spl_interface_pda; + +use crate::constants::{AUTH_SEED, OFFER_SEED, VAULT_SEED}; +use crate::instructions::{transfer_tokens, SplInterfaceConfig}; +use crate::state::Offer; + +#[derive(Accounts)] +pub struct TakeOffer<'info> { + #[account(mut)] + pub taker: Signer<'info>, + + #[account(mut)] + pub maker: SystemAccount<'info>, + + /// CHECK: Authority PDA for the vault (mutable for close_vault write_top_up) + #[account( + mut, + seeds = [AUTH_SEED], + bump, + )] + pub authority: UncheckedAccount<'info>, + + pub token_mint_a: InterfaceAccount<'info, Mint>, + + pub token_mint_b: InterfaceAccount<'info, Mint>, + + #[account( + mut, + token::mint = token_mint_a, + token::authority = taker, + )] + pub taker_token_account_a: InterfaceAccount<'info, TokenAccount>, + + #[account( + mut, + token::mint = token_mint_b, + token::authority = taker, + )] + pub taker_token_account_b: InterfaceAccount<'info, TokenAccount>, + + #[account( + mut, + token::mint = token_mint_b, + token::authority = maker, + )] + pub maker_token_account_b: InterfaceAccount<'info, TokenAccount>, + + #[account( + mut, + close = maker, + has_one = maker, + has_one = token_mint_a, + has_one = token_mint_b, + seeds = [OFFER_SEED, maker.key().as_ref(), offer.id.to_le_bytes().as_ref()], + bump, + )] + pub offer: Account<'info, Offer>, + + #[account( + mut, + seeds = [VAULT_SEED, offer.key().as_ref()], + bump, + )] + pub vault: InterfaceAccount<'info, TokenAccount>, + + pub token_program: Interface<'info, TokenInterface>, + pub system_program: Program<'info, System>, + + /// Light token program for CPI calls + pub light_token_program: Interface<'info, TokenInterface>, + + /// CHECK: light-token CPI authority - must be writable for Light token CPI + #[account(mut)] + pub light_token_cpi_authority: AccountInfo<'info>, + + /// CHECK: Light token rent sponsor for closing vault + #[account(mut, address = RENT_SPONSOR)] + pub light_token_rent_sponsor: AccountInfo<'info>, + + /// CHECK: SPL interface PDA for mint A (vault→taker transfer) + #[account(mut)] + pub spl_interface_pda_a: UncheckedAccount<'info>, + + /// CHECK: SPL interface PDA for mint B (taker→maker transfer) + #[account(mut)] + pub spl_interface_pda_b: UncheckedAccount<'info>, +} + +pub fn send_wanted_tokens_to_maker(ctx: &Context) -> Result<()> { + let decimals_b = ctx.accounts.token_mint_b.decimals; + let token_b_wanted_amount = ctx.accounts.offer.token_b_wanted_amount; + let (_, spl_interface_bump_b) = + find_spl_interface_pda(&ctx.accounts.token_mint_b.key(), false); + + let spl_interface = SplInterfaceConfig { + mint: ctx.accounts.token_mint_b.to_account_info(), + spl_token_program: ctx.accounts.token_program.to_account_info(), + spl_interface_pda: ctx.accounts.spl_interface_pda_b.to_account_info(), + spl_interface_pda_bump: spl_interface_bump_b, + }; + + transfer_tokens( + token_b_wanted_amount, + decimals_b, + ctx.accounts.taker_token_account_b.to_account_info(), + ctx.accounts.maker_token_account_b.to_account_info(), + ctx.accounts.token_mint_b.to_account_info(), + ctx.accounts.taker.to_account_info(), + ctx.accounts.taker.to_account_info(), + ctx.accounts.light_token_cpi_authority.to_account_info(), + ctx.accounts.system_program.to_account_info(), + None, + Some(spl_interface), + ) +} + +pub fn withdraw_from_vault(ctx: &Context) -> Result<()> { + let offer = &ctx.accounts.offer; + let authority_seeds = &[AUTH_SEED, &[offer.auth_bump]]; + + let vault_balance = get_token_account_balance(&ctx.accounts.vault.to_account_info()) + .map_err(|_| anchor_lang::prelude::ProgramError::InvalidAccountData)?; + + let decimals_a = ctx.accounts.token_mint_a.decimals; + let (_, spl_interface_bump_a) = + find_spl_interface_pda(&ctx.accounts.token_mint_a.key(), false); + + let spl_interface = SplInterfaceConfig { + mint: ctx.accounts.token_mint_a.to_account_info(), + spl_token_program: ctx.accounts.token_program.to_account_info(), + spl_interface_pda: ctx.accounts.spl_interface_pda_a.to_account_info(), + spl_interface_pda_bump: spl_interface_bump_a, + }; + + transfer_tokens( + vault_balance, + decimals_a, + ctx.accounts.vault.to_account_info(), + ctx.accounts.taker_token_account_a.to_account_info(), + ctx.accounts.token_mint_a.to_account_info(), + ctx.accounts.authority.to_account_info(), + ctx.accounts.taker.to_account_info(), + ctx.accounts.light_token_cpi_authority.to_account_info(), + ctx.accounts.system_program.to_account_info(), + Some(authority_seeds), + Some(spl_interface), + )?; + + msg!( + "Offer taken: id={}, taker={}, transferred {} token_b to maker, received {} token_a", + offer.id, + ctx.accounts.taker.key(), + offer.token_b_wanted_amount, + vault_balance + ); + + Ok(()) +} + +pub fn close_vault(ctx: &Context) -> Result<()> { + let auth_bump = ctx.accounts.offer.auth_bump; + let authority_seeds: &[&[u8]] = &[AUTH_SEED, &[auth_bump]]; + + CloseAccountCpi { + token_program: ctx.accounts.light_token_program.to_account_info(), + account: ctx.accounts.vault.to_account_info(), + destination: ctx.accounts.taker.to_account_info(), + owner: ctx.accounts.authority.to_account_info(), + rent_sponsor: ctx.accounts.light_token_rent_sponsor.to_account_info(), + } + .invoke_signed(&[authority_seeds]) + .map_err(|e| anchor_lang::prelude::ProgramError::from(e).into()) +} diff --git a/programs/anchor/escrow/src/lib.rs b/programs/anchor/escrow/src/lib.rs new file mode 100644 index 0000000..64e5e61 --- /dev/null +++ b/programs/anchor/escrow/src/lib.rs @@ -0,0 +1,37 @@ +pub mod constants; +pub mod instructions; +pub mod state; + +use anchor_lang::prelude::*; +use light_token::anchor::{derive_light_cpi_signer, light_program, CpiSigner}; + +pub use constants::*; +pub use instructions::*; +pub use state::*; + +declare_id!("FKJs6rp6TXJtxzLiPtdYhqa9ExRuBXG2zwh4fda6WATN"); + +pub const LIGHT_CPI_SIGNER: CpiSigner = + derive_light_cpi_signer!("FKJs6rp6TXJtxzLiPtdYhqa9ExRuBXG2zwh4fda6WATN"); + +#[light_program] +// Anchor's #[program] macro uses deprecated AccountInfo::realloc internally +#[allow(deprecated)] +#[program] +pub mod escrow { + use super::*; + + pub fn make_offer<'info>( + mut ctx: Context<'_, '_, '_, 'info, MakeOffer<'info>>, + params: MakeOfferParams, + ) -> Result<()> { + instructions::make_offer::send_offered_tokens_to_vault(&ctx, ¶ms)?; + instructions::make_offer::save_offer(&mut ctx, ¶ms) + } + + pub fn take_offer(ctx: Context) -> Result<()> { + instructions::take_offer::send_wanted_tokens_to_maker(&ctx)?; + instructions::take_offer::withdraw_from_vault(&ctx)?; + instructions::take_offer::close_vault(&ctx) + } +} diff --git a/programs/anchor/escrow/src/state/mod.rs b/programs/anchor/escrow/src/state/mod.rs new file mode 100644 index 0000000..cfaa08e --- /dev/null +++ b/programs/anchor/escrow/src/state/mod.rs @@ -0,0 +1,3 @@ +pub mod offer; + +pub use offer::*; diff --git a/programs/anchor/escrow/src/state/offer.rs b/programs/anchor/escrow/src/state/offer.rs new file mode 100644 index 0000000..33cf09f --- /dev/null +++ b/programs/anchor/escrow/src/state/offer.rs @@ -0,0 +1,15 @@ +use anchor_lang::prelude::*; +use light_sdk::LightDiscriminator; +use light_token::anchor::{CompressionInfo, LightAccount}; + +#[derive(Default, Debug, InitSpace, LightAccount)] +#[account] +pub struct Offer { + pub compression_info: Option, + pub id: u64, + pub maker: Pubkey, + pub token_mint_a: Pubkey, + pub token_mint_b: Pubkey, + pub token_b_wanted_amount: u64, + pub auth_bump: u8, +} diff --git a/programs/anchor/escrow/tests/common/mod.rs b/programs/anchor/escrow/tests/common/mod.rs new file mode 100644 index 0000000..07ebe02 --- /dev/null +++ b/programs/anchor/escrow/tests/common/mod.rs @@ -0,0 +1,658 @@ +//! Common test utilities for escrow tests. +//! +//! This module provides shared test helpers for different token type combinations: +//! - SPL mint + SPL ATAs +//! - T22 mint + T22 ATAs +//! - SPL mint + Light user accounts +//! - T22 mint + Light user accounts +//! - Light mint + Light user accounts + +use anchor_lang::{InstructionData, ToAccountMetas}; +use anchor_spl::token; +use shared_test_utils::{ + helpers::verify_light_token_balance, + light_tokens::{create_light_ata, create_light_mint, mint_light_tokens}, + setup::initialize_rent_free_config, + spl_interface::{create_spl_interface_pda, transfer_spl_to_light}, + spl_tokens::{create_spl_ata, create_spl_mint, mint_spl_tokens}, + t22_tokens::{create_t22_ata, create_t22_mint, mint_t22_tokens}, + Indexer, LightProgramTest, MintType, ProgramTestConfig, Rpc, + SplInterfaceResult, TestRpc, COMPRESSIBLE_CONFIG_V1, CPI_AUTHORITY_PDA, + LIGHT_TOKEN_MINTER_PROGRAM_ID, LIGHT_TOKEN_PROGRAM_ID, RENT_SPONSOR, +}; +use light_client::interface::{get_create_accounts_proof, CreateAccountsProofInput}; +use solana_instruction::Instruction; +use solana_keypair::Keypair; +use solana_pubkey::Pubkey; +use solana_signer::Signer; + +/// Token configuration for parameterized tests +#[allow(dead_code)] +#[derive(Clone, Copy, Debug)] +pub enum TokenConfig { + /// SPL mint + SPL ATAs + Spl, + /// T22 mint + T22 ATAs + Token2022, + /// SPL mint + Light user accounts (offchain SPL->Light conversion) + LightSpl, + /// T22 mint + Light user accounts (offchain T22->Light conversion) + LightT22, + /// Light mint + Light user accounts (pure Light-to-Light) + Light, +} + +impl TokenConfig { + pub fn mint_type(&self) -> MintType { + match self { + TokenConfig::Spl | TokenConfig::LightSpl => MintType::Spl, + TokenConfig::Token2022 | TokenConfig::LightT22 => MintType::Token2022, + TokenConfig::Light => MintType::Spl, // Light mints use SPL-compatible layout + } + } + + pub fn token_program_id(&self) -> Pubkey { + match self { + TokenConfig::Spl | TokenConfig::LightSpl => token::ID, + TokenConfig::Token2022 | TokenConfig::LightT22 => spl_token_2022::ID, + TokenConfig::Light => Pubkey::new_from_array(LIGHT_TOKEN_PROGRAM_ID), + } + } + + /// Returns true if mints are Light Protocol mints (not SPL/T22) + pub fn uses_light_mints(&self) -> bool { + matches!(self, TokenConfig::Light) + } + + /// Returns true if user accounts are Light token accounts + pub fn uses_light_accounts(&self) -> bool { + matches!( + self, + TokenConfig::Light | TokenConfig::LightSpl | TokenConfig::LightT22 + ) + } +} + +/// Context for escrow tests containing all necessary accounts +#[allow(dead_code)] +pub struct EscrowTestContext { + pub program_id: Pubkey, + pub payer: Keypair, + pub token_config: TokenConfig, + pub compression_config: Pubkey, + + // Mint A + pub mint_a_pubkey: Pubkey, + pub light_mint_a_authority: Option, + pub spl_interface_a: Option, + + // Mint B + pub mint_b_pubkey: Pubkey, + pub light_mint_b_authority: Option, + pub spl_interface_b: Option, + + // Participants + pub maker: Keypair, + pub taker: Keypair, + + // PDAs + pub authority_pda: Pubkey, +} + +/// Create a new LightProgramTest instance for escrow tests +pub async fn create_test_rpc() -> LightProgramTest { + let program_id = escrow::ID; + let mut config = ProgramTestConfig::new_v2( + true, + Some(vec![ + ("escrow", program_id), + ("light_token_minter", LIGHT_TOKEN_MINTER_PROGRAM_ID), + ]), + ); + config = config.with_light_protocol_events(); + LightProgramTest::new(config).await.unwrap() +} + +/// Setup the escrow test environment based on token config +pub async fn setup_escrow_test( + rpc: &mut R, + config: TokenConfig, +) -> EscrowTestContext { + let program_id = escrow::ID; + let payer = rpc.get_payer().insecure_clone(); + + // Initialize rent-free config + let compression_config = initialize_rent_free_config(rpc, &payer, &program_id).await; + + // Create maker and taker + let maker = Keypair::new(); + let taker = Keypair::new(); + rpc.airdrop_lamports(&maker.pubkey(), 10_000_000_000) + .await + .unwrap(); + rpc.airdrop_lamports(&taker.pubkey(), 10_000_000_000) + .await + .unwrap(); + + // Derive authority PDA + let (authority_pda, _) = + Pubkey::find_program_address(&[escrow::AUTH_SEED], &program_id); + + if config.uses_light_mints() { + // ========== LIGHT MINT SETUP ========== + println!("\n=== Setting up Light mints ==="); + + let light_mint_a = create_light_mint( + rpc, + &payer, + 9, + "Escrow Token A", + "ETKA", + &compression_config, + ) + .await; + + let light_mint_b = create_light_mint( + rpc, + &payer, + 9, + "Escrow Token B", + "ETKB", + &compression_config, + ) + .await; + + return EscrowTestContext { + program_id, + payer, + token_config: config, + compression_config, + mint_a_pubkey: light_mint_a.mint, + light_mint_a_authority: Some(light_mint_a.authority), + spl_interface_a: None, + mint_b_pubkey: light_mint_b.mint, + light_mint_b_authority: Some(light_mint_b.authority), + spl_interface_b: None, + maker, + taker, + authority_pda, + }; + } + + // ========== SPL/T22 MINT SETUP ========== + let (mint_a, mint_b) = match config { + TokenConfig::Spl | TokenConfig::LightSpl => { + let a = create_spl_mint(rpc, &payer, &payer.pubkey(), 9).await; + let b = create_spl_mint(rpc, &payer, &payer.pubkey(), 9).await; + (a, b) + } + TokenConfig::Token2022 | TokenConfig::LightT22 => { + let a = create_t22_mint(rpc, &payer, &payer.pubkey(), 9).await; + let b = create_t22_mint(rpc, &payer, &payer.pubkey(), 9).await; + (a, b) + } + TokenConfig::Light => unreachable!("Light config handled above"), + }; + + let mint_a_pubkey = mint_a.pubkey(); + let mint_b_pubkey = mint_b.pubkey(); + + // Create SPL interface PDAs for all SPL/T22 configs (needed for TransferInterfaceCpi) + let iface_a = create_spl_interface_pda( + rpc, + &payer, + &mint_a_pubkey, + config.mint_type(), + false, + ) + .await; + let iface_b = create_spl_interface_pda( + rpc, + &payer, + &mint_b_pubkey, + config.mint_type(), + false, + ) + .await; + let (spl_interface_a, spl_interface_b) = (Some(iface_a), Some(iface_b)); + + EscrowTestContext { + program_id, + payer, + token_config: config, + compression_config, + mint_a_pubkey, + light_mint_a_authority: None, + spl_interface_a, + mint_b_pubkey, + light_mint_b_authority: None, + spl_interface_b, + maker, + taker, + authority_pda, + } +} + +/// Create a token account for a participant for a specific mint. +/// +/// When `funding_amount > 0`, mints tokens to the account. +/// When `funding_amount == 0`, creates the account without funding. +/// +/// For LightSpl/LightT22: creates a temp SPL/T22 ATA, mints, creates Light ATA, +/// and transfers (compresses) when funded. When unfunded, just creates Light ATA. +pub async fn create_token_account( + rpc: &mut R, + ctx: &EscrowTestContext, + owner: &Keypair, + mint_pubkey: &Pubkey, + light_mint_authority: Option<&Keypair>, + spl_interface: Option<&SplInterfaceResult>, + funding_amount: u64, +) -> Pubkey { + match ctx.token_config { + TokenConfig::Spl => { + let ata = create_spl_ata(rpc, &ctx.payer, mint_pubkey, &owner.pubkey()).await; + if funding_amount > 0 { + mint_spl_tokens(rpc, &ctx.payer, mint_pubkey, &ata, &ctx.payer, funding_amount) + .await; + } + ata + } + TokenConfig::Token2022 => { + let ata = create_t22_ata(rpc, &ctx.payer, mint_pubkey, &owner.pubkey()).await; + if funding_amount > 0 { + mint_t22_tokens(rpc, &ctx.payer, mint_pubkey, &ata, &ctx.payer, funding_amount) + .await; + } + ata + } + TokenConfig::LightSpl => { + if funding_amount > 0 { + // Create temp SPL ATA, mint, create Light ATA, transfer + let temp_ata = + create_spl_ata(rpc, &ctx.payer, mint_pubkey, &owner.pubkey()).await; + mint_spl_tokens( + rpc, + &ctx.payer, + mint_pubkey, + &temp_ata, + &ctx.payer, + funding_amount, + ) + .await; + + let light_ata = + create_light_ata(rpc, &ctx.payer, mint_pubkey, &owner.pubkey()).await; + + let iface = spl_interface.expect("LightSpl requires SPL interface PDA"); + transfer_spl_to_light( + rpc, + &ctx.payer, + owner, + mint_pubkey, + 9, + &temp_ata, + &light_ata, + &iface.pda, + iface.bump, + funding_amount, + MintType::Spl, + ) + .await; + + light_ata + } else { + create_light_ata(rpc, &ctx.payer, mint_pubkey, &owner.pubkey()).await + } + } + TokenConfig::LightT22 => { + if funding_amount > 0 { + let temp_ata = + create_t22_ata(rpc, &ctx.payer, mint_pubkey, &owner.pubkey()).await; + mint_t22_tokens( + rpc, + &ctx.payer, + mint_pubkey, + &temp_ata, + &ctx.payer, + funding_amount, + ) + .await; + + let light_ata = + create_light_ata(rpc, &ctx.payer, mint_pubkey, &owner.pubkey()).await; + + let iface = spl_interface.expect("LightT22 requires SPL interface PDA"); + transfer_spl_to_light( + rpc, + &ctx.payer, + owner, + mint_pubkey, + 9, + &temp_ata, + &light_ata, + &iface.pda, + iface.bump, + funding_amount, + MintType::Token2022, + ) + .await; + + light_ata + } else { + create_light_ata(rpc, &ctx.payer, mint_pubkey, &owner.pubkey()).await + } + } + TokenConfig::Light => { + let mint_authority = + light_mint_authority.expect("Light config requires mint authority"); + if funding_amount > 0 { + // mint_light_tokens creates ATA and mints in one call + mint_light_tokens( + rpc, + &ctx.payer, + mint_authority, + mint_pubkey, + &owner.pubkey(), + funding_amount, + ) + .await + } else { + create_light_ata(rpc, &ctx.payer, mint_pubkey, &owner.pubkey()).await + } + } + } +} + +/// Execute make_offer instruction. Returns (offer_pda, vault_pda, vault_bump). +pub async fn execute_make_offer( + rpc: &mut R, + ctx: &EscrowTestContext, + offer_id: u64, + maker_ata_a: Pubkey, + token_a_offered_amount: u64, + token_b_wanted_amount: u64, +) -> (Pubkey, Pubkey, u8) { + let (offer_pda, _) = Pubkey::find_program_address( + &[ + escrow::OFFER_SEED, + ctx.maker.pubkey().as_ref(), + offer_id.to_le_bytes().as_ref(), + ], + &ctx.program_id, + ); + + let (vault_pda, vault_bump) = + Pubkey::find_program_address(&[escrow::VAULT_SEED, offer_pda.as_ref()], &ctx.program_id); + + // Get proof for creating the offer account + let proof_result = get_create_accounts_proof( + rpc, + &ctx.program_id, + vec![CreateAccountsProofInput::pda(offer_pda)], + ) + .await + .unwrap(); + + let accounts = escrow::accounts::MakeOffer { + fee_payer: ctx.maker.pubkey(), + authority: ctx.authority_pda, + compression_config: ctx.compression_config, + token_mint_a: ctx.mint_a_pubkey, + token_mint_b: ctx.mint_b_pubkey, + maker_token_account_a: maker_ata_a, + offer: offer_pda, + vault: vault_pda, + token_program: ctx.token_config.token_program_id(), + system_program: solana_sdk::system_program::ID, + light_token_program: Pubkey::new_from_array(LIGHT_TOKEN_PROGRAM_ID), + light_token_compressible_config: COMPRESSIBLE_CONFIG_V1, + light_token_rent_sponsor: RENT_SPONSOR, + light_token_cpi_authority: CPI_AUTHORITY_PDA, + spl_interface_pda_a: ctx + .spl_interface_a + .as_ref() + .map(|i| i.pda) + .unwrap_or_default(), + }; + + let data = escrow::instruction::MakeOffer { + params: escrow::MakeOfferParams { + create_accounts_proof: proof_result.create_accounts_proof, + id: offer_id, + token_a_offered_amount, + token_b_wanted_amount, + vault_bump, + }, + }; + + let ix = Instruction { + program_id: ctx.program_id, + accounts: [ + accounts.to_account_metas(None), + proof_result.remaining_accounts, + ] + .concat(), + data: data.data(), + }; + + rpc.create_and_send_transaction(&[ix], &ctx.maker.pubkey(), &[&ctx.maker]) + .await + .expect("make_offer should succeed"); + + println!("make_offer executed: offer={:?}, vault={:?}", offer_pda, vault_pda); + + (offer_pda, vault_pda, vault_bump) +} + +/// Execute take_offer instruction. +pub async fn execute_take_offer( + rpc: &mut R, + ctx: &EscrowTestContext, + offer_pda: Pubkey, + vault_pda: Pubkey, + taker_ata_a: Pubkey, + taker_ata_b: Pubkey, + maker_ata_b: Pubkey, +) { + let accounts = escrow::accounts::TakeOffer { + taker: ctx.taker.pubkey(), + maker: ctx.maker.pubkey(), + authority: ctx.authority_pda, + token_mint_a: ctx.mint_a_pubkey, + token_mint_b: ctx.mint_b_pubkey, + taker_token_account_a: taker_ata_a, + taker_token_account_b: taker_ata_b, + maker_token_account_b: maker_ata_b, + offer: offer_pda, + vault: vault_pda, + token_program: ctx.token_config.token_program_id(), + system_program: solana_sdk::system_program::ID, + light_token_program: Pubkey::new_from_array(LIGHT_TOKEN_PROGRAM_ID), + light_token_cpi_authority: CPI_AUTHORITY_PDA, + light_token_rent_sponsor: RENT_SPONSOR, + spl_interface_pda_a: ctx + .spl_interface_a + .as_ref() + .map(|i| i.pda) + .unwrap_or_default(), + spl_interface_pda_b: ctx + .spl_interface_b + .as_ref() + .map(|i| i.pda) + .unwrap_or_default(), + }; + + let data = escrow::instruction::TakeOffer {}; + + let ix = Instruction { + program_id: ctx.program_id, + accounts: accounts.to_account_metas(None), + data: data.data(), + }; + + rpc.create_and_send_transaction(&[ix], &ctx.taker.pubkey(), &[&ctx.taker]) + .await + .expect("take_offer should succeed"); + + println!("take_offer executed"); +} + +/// Run the full escrow flow: setup accounts, make_offer, take_offer, verify balances. +pub async fn run_escrow_full_flow( + rpc: &mut R, + ctx: &EscrowTestContext, +) { + let token_a_amount = 1_000_000_000u64; // 1 token with 9 decimals + let token_b_amount = 500_000_000u64; // 0.5 tokens + + // Create token accounts for maker and taker + println!("\n=== Creating token accounts ==="); + + // Maker's token A account (funded) + let maker_ata_a = create_token_account( + rpc, + ctx, + &ctx.maker, + &ctx.mint_a_pubkey, + ctx.light_mint_a_authority.as_ref(), + ctx.spl_interface_a.as_ref(), + token_a_amount, + ) + .await; + + // Maker's token B account (unfunded, receives from taker) + let maker_ata_b = create_token_account( + rpc, + ctx, + &ctx.maker, + &ctx.mint_b_pubkey, + ctx.light_mint_b_authority.as_ref(), + ctx.spl_interface_b.as_ref(), + 0, + ) + .await; + + // Taker's token A account (unfunded, receives from vault) + let taker_ata_a = create_token_account( + rpc, + ctx, + &ctx.taker, + &ctx.mint_a_pubkey, + ctx.light_mint_a_authority.as_ref(), + ctx.spl_interface_a.as_ref(), + 0, + ) + .await; + + // Taker's token B account (funded) + let taker_ata_b = create_token_account( + rpc, + ctx, + &ctx.taker, + &ctx.mint_b_pubkey, + ctx.light_mint_b_authority.as_ref(), + ctx.spl_interface_b.as_ref(), + token_b_amount, + ) + .await; + + // Verify initial balances + println!("\n=== Verifying initial balances ==="); + verify_light_token_balance(rpc, maker_ata_a, token_a_amount, "maker_ata_a").await; + verify_light_token_balance(rpc, maker_ata_b, 0, "maker_ata_b").await; + verify_light_token_balance(rpc, taker_ata_a, 0, "taker_ata_a").await; + verify_light_token_balance(rpc, taker_ata_b, token_b_amount, "taker_ata_b").await; + + // === MAKE OFFER === + println!("\n=== Executing make_offer ==="); + let (offer_pda, vault_pda, _) = execute_make_offer( + rpc, + ctx, + 1, // offer_id + maker_ata_a, + token_a_amount, + token_b_amount, + ) + .await; + + // Verify vault was created and funded + verify_light_token_balance(rpc, vault_pda, token_a_amount, "vault (after make_offer)").await; + verify_light_token_balance(rpc, maker_ata_a, 0, "maker_ata_a (after make_offer)").await; + + // Verify offer account was created + let offer_account = rpc + .get_account(offer_pda) + .await + .unwrap() + .expect("Offer account should exist"); + assert!(!offer_account.data.is_empty(), "Offer account should have data"); + + // === TAKE OFFER === + println!("\n=== Executing take_offer ==="); + execute_take_offer(rpc, ctx, offer_pda, vault_pda, taker_ata_a, taker_ata_b, maker_ata_b) + .await; + + // === VERIFY FINAL BALANCES === + println!("\n=== Verifying final balances ==="); + verify_light_token_balance(rpc, maker_ata_a, 0, "maker_ata_a (final)").await; + verify_light_token_balance(rpc, maker_ata_b, token_b_amount, "maker_ata_b (final)").await; + verify_light_token_balance(rpc, taker_ata_a, token_a_amount, "taker_ata_a (final)").await; + verify_light_token_balance(rpc, taker_ata_b, 0, "taker_ata_b (final)").await; + + // Verify offer account was closed + let offer_after = rpc.get_account(offer_pda).await.unwrap(); + assert!( + offer_after.is_none(), + "Offer account should be closed after take_offer" + ); + println!("Offer account closed"); + + println!("\n=== Escrow full flow completed ==="); +} + +/// Run make_offer only (for setup verification tests). +pub async fn run_escrow_make_offer( + rpc: &mut R, + ctx: &EscrowTestContext, +) { + let token_a_amount = 1_000_000_000u64; + let token_b_amount = 500_000_000u64; + + // Create maker's token A account (funded) + let maker_ata_a = create_token_account( + rpc, + ctx, + &ctx.maker, + &ctx.mint_a_pubkey, + ctx.light_mint_a_authority.as_ref(), + ctx.spl_interface_a.as_ref(), + token_a_amount, + ) + .await; + + // Execute make_offer + let (offer_pda, vault_pda, _) = execute_make_offer( + rpc, + ctx, + 1, + maker_ata_a, + token_a_amount, + token_b_amount, + ) + .await; + + // Verify vault was created and funded + verify_light_token_balance(rpc, vault_pda, token_a_amount, "vault (after make_offer)").await; + verify_light_token_balance(rpc, maker_ata_a, 0, "maker_ata_a (after make_offer)").await; + + // Verify offer account was created + let offer_account = rpc + .get_account(offer_pda) + .await + .unwrap() + .expect("Offer account should exist"); + assert!(!offer_account.data.is_empty(), "Offer account should have data"); + + println!("make_offer verified"); +} diff --git a/programs/anchor/escrow/tests/escrow_light.rs b/programs/anchor/escrow/tests/escrow_light.rs new file mode 100644 index 0000000..1e32937 --- /dev/null +++ b/programs/anchor/escrow/tests/escrow_light.rs @@ -0,0 +1,17 @@ +mod common; + +use common::{create_test_rpc, run_escrow_full_flow, run_escrow_make_offer, setup_escrow_test, TokenConfig}; + +#[tokio::test] +async fn test_escrow_full_flow_light() { + let mut rpc = create_test_rpc().await; + let ctx = setup_escrow_test(&mut rpc, TokenConfig::Light).await; + run_escrow_full_flow(&mut rpc, &ctx).await; +} + +#[tokio::test] +async fn test_escrow_make_offer_light() { + let mut rpc = create_test_rpc().await; + let ctx = setup_escrow_test(&mut rpc, TokenConfig::Light).await; + run_escrow_make_offer(&mut rpc, &ctx).await; +} diff --git a/programs/anchor/escrow/tests/escrow_spl.rs b/programs/anchor/escrow/tests/escrow_spl.rs new file mode 100644 index 0000000..e51937f --- /dev/null +++ b/programs/anchor/escrow/tests/escrow_spl.rs @@ -0,0 +1,17 @@ +mod common; + +use common::{create_test_rpc, run_escrow_full_flow, run_escrow_make_offer, setup_escrow_test, TokenConfig}; + +#[tokio::test] +async fn test_escrow_full_flow_spl() { + let mut rpc = create_test_rpc().await; + let ctx = setup_escrow_test(&mut rpc, TokenConfig::Spl).await; + run_escrow_full_flow(&mut rpc, &ctx).await; +} + +#[tokio::test] +async fn test_escrow_make_offer_spl() { + let mut rpc = create_test_rpc().await; + let ctx = setup_escrow_test(&mut rpc, TokenConfig::Spl).await; + run_escrow_make_offer(&mut rpc, &ctx).await; +} diff --git a/programs/anchor/escrow/tests/escrow_spl_light.rs b/programs/anchor/escrow/tests/escrow_spl_light.rs new file mode 100644 index 0000000..25fff28 --- /dev/null +++ b/programs/anchor/escrow/tests/escrow_spl_light.rs @@ -0,0 +1,19 @@ +mod common; + +use common::{ + create_test_rpc, run_escrow_full_flow, run_escrow_make_offer, setup_escrow_test, TokenConfig, +}; + +#[tokio::test] +async fn test_escrow_full_flow_spl_light() { + let mut rpc = create_test_rpc().await; + let ctx = setup_escrow_test(&mut rpc, TokenConfig::LightSpl).await; + run_escrow_full_flow(&mut rpc, &ctx).await; +} + +#[tokio::test] +async fn test_escrow_make_offer_spl_light() { + let mut rpc = create_test_rpc().await; + let ctx = setup_escrow_test(&mut rpc, TokenConfig::LightSpl).await; + run_escrow_make_offer(&mut rpc, &ctx).await; +} diff --git a/programs/anchor/escrow/tests/escrow_t22.rs b/programs/anchor/escrow/tests/escrow_t22.rs new file mode 100644 index 0000000..d854b20 --- /dev/null +++ b/programs/anchor/escrow/tests/escrow_t22.rs @@ -0,0 +1,17 @@ +mod common; + +use common::{create_test_rpc, run_escrow_full_flow, run_escrow_make_offer, setup_escrow_test, TokenConfig}; + +#[tokio::test] +async fn test_escrow_full_flow_t22() { + let mut rpc = create_test_rpc().await; + let ctx = setup_escrow_test(&mut rpc, TokenConfig::Token2022).await; + run_escrow_full_flow(&mut rpc, &ctx).await; +} + +#[tokio::test] +async fn test_escrow_make_offer_t22() { + let mut rpc = create_test_rpc().await; + let ctx = setup_escrow_test(&mut rpc, TokenConfig::Token2022).await; + run_escrow_make_offer(&mut rpc, &ctx).await; +} diff --git a/programs/anchor/escrow/tests/escrow_t22_light.rs b/programs/anchor/escrow/tests/escrow_t22_light.rs new file mode 100644 index 0000000..e15757c --- /dev/null +++ b/programs/anchor/escrow/tests/escrow_t22_light.rs @@ -0,0 +1,19 @@ +mod common; + +use common::{ + create_test_rpc, run_escrow_full_flow, run_escrow_make_offer, setup_escrow_test, TokenConfig, +}; + +#[tokio::test] +async fn test_escrow_full_flow_t22_light() { + let mut rpc = create_test_rpc().await; + let ctx = setup_escrow_test(&mut rpc, TokenConfig::LightT22).await; + run_escrow_full_flow(&mut rpc, &ctx).await; +} + +#[tokio::test] +async fn test_escrow_make_offer_t22_light() { + let mut rpc = create_test_rpc().await; + let ctx = setup_escrow_test(&mut rpc, TokenConfig::LightT22).await; + run_escrow_make_offer(&mut rpc, &ctx).await; +} diff --git a/programs/anchor/fundraiser/Cargo.toml b/programs/anchor/fundraiser/Cargo.toml new file mode 100644 index 0000000..8f3287a --- /dev/null +++ b/programs/anchor/fundraiser/Cargo.toml @@ -0,0 +1,52 @@ +[package] +name = "fundraiser" +version = "0.1.0" +description = "Created with Anchor" +edition = "2021" + +[lib] +crate-type = ["cdylib", "lib"] +name = "fundraiser" + +[features] +default = [] +cpi = ["no-entrypoint"] +no-entrypoint = [] +no-idl = [] +no-log-ix-name = [] +idl-build = ["anchor-lang/idl-build", "light-sdk/idl-build"] +test-sbf = [] + +[dependencies] +anchor-lang = { version = "=0.31.1", features = ["init-if-needed", "idl-build"] } +blake3 = { workspace = true } + +light-sdk = { workspace = true, features = ["anchor", "anchor-discriminator", "idl-build", "cpi-context", "v2"] } +light-token = { workspace = true, features = ["anchor"] } +light-hasher = { workspace = true, features = ["solana"] } +light-anchor-spl = { workspace = true, features = ["idl-build"] } +solana-program = { workspace = true } +solana-pubkey = { workspace = true } +solana-account-info = { workspace = true } +solana-program-error = { workspace = true } +solana-msg = { workspace = true } + +[dev-dependencies] +light-program-test = { workspace = true } +light-client = { workspace = true, features = ["v2", "anchor"] } +anchor-spl = { workspace = true } +tokio = { workspace = true, features = ["full"] } +solana-keypair = { workspace = true } +solana-signer = { workspace = true } +solana-instruction = { workspace = true } +solana-sdk = { workspace = true } +spl-token-2022 = { workspace = true } +spl-pod = { workspace = true } +shared-test-utils = { workspace = true } + +[lints.rust.unexpected_cfgs] +level = "allow" +check-cfg = [ + 'cfg(target_os, values("solana"))', + 'cfg(feature, values("frozen-abi", "no-entrypoint"))', +] diff --git a/programs/anchor/fundraiser/Xargo.toml b/programs/anchor/fundraiser/Xargo.toml new file mode 100644 index 0000000..475fb71 --- /dev/null +++ b/programs/anchor/fundraiser/Xargo.toml @@ -0,0 +1,2 @@ +[target.bpfel-unknown-unknown.dependencies.std] +features = [] diff --git a/programs/anchor/fundraiser/src/constants.rs b/programs/anchor/fundraiser/src/constants.rs new file mode 100644 index 0000000..678e5f4 --- /dev/null +++ b/programs/anchor/fundraiser/src/constants.rs @@ -0,0 +1,6 @@ +pub const ANCHOR_DISCRIMINATOR: usize = 8; +pub const MIN_AMOUNT_TO_RAISE: u64 = 3; +pub const SECONDS_TO_DAYS: i64 = 86400; +pub const MAX_CONTRIBUTION_PERCENTAGE: u64 = 10; +pub const PERCENTAGE_SCALER: u64 = 100; +pub const VAULT_SEED: &[u8] = b"vault"; diff --git a/programs/anchor/fundraiser/src/error.rs b/programs/anchor/fundraiser/src/error.rs new file mode 100644 index 0000000..a7dd6fd --- /dev/null +++ b/programs/anchor/fundraiser/src/error.rs @@ -0,0 +1,21 @@ +use anchor_lang::error_code; + +#[error_code] +pub enum FundraiserError { + #[msg("The amount to raise has not been met")] + TargetNotMet, + #[msg("The amount to raise has been achieved")] + TargetMet, + #[msg("The contribution is too big")] + ContributionTooBig, + #[msg("The contribution is too small")] + ContributionTooSmall, + #[msg("The maximum amount to contribute has been reached")] + MaximumContributionsReached, + #[msg("The fundraiser has not ended yet")] + FundraiserNotEnded, + #[msg("The fundraiser has ended")] + FundraiserEnded, + #[msg("Invalid total amount. i should be bigger than 3")] + InvalidAmount, +} diff --git a/programs/anchor/fundraiser/src/instructions/checker.rs b/programs/anchor/fundraiser/src/instructions/checker.rs new file mode 100644 index 0000000..1132cdf --- /dev/null +++ b/programs/anchor/fundraiser/src/instructions/checker.rs @@ -0,0 +1,108 @@ +use anchor_lang::prelude::*; +use light_anchor_spl::token_interface::{Mint, TokenAccount, TokenInterface}; +use light_token::instruction::RENT_SPONSOR; +use light_token::spl_interface::find_spl_interface_pda; +use light_token::utils::get_token_account_balance; + +use crate::constants::VAULT_SEED; +use crate::instructions::{transfer_tokens, SplInterfaceConfig}; +use crate::state::Fundraiser; +use crate::FundraiserError; + +#[derive(Accounts)] +pub struct CheckContributions<'info> { + /// The maker who checks and claims the fundraiser (also the fee payer for Light Protocol) + #[account(mut)] + pub fee_payer: Signer<'info>, + + #[account(mint::token_program = token_program)] + pub mint_to_raise: InterfaceAccount<'info, Mint>, + + #[account( + mut, + has_one = mint_to_raise, + seeds = [b"fundraiser".as_ref(), fee_payer.key().as_ref()], + bump = fundraiser.bump, + close = fee_payer, + )] + pub fundraiser: Account<'info, Fundraiser>, + + /// CHECK: Vault token account (Light token account) + #[account( + mut, + seeds = [VAULT_SEED, fundraiser.key().as_ref()], + bump, + )] + pub vault: UncheckedAccount<'info>, + + /// Maker's SPL ATA - must be pre-created before calling this instruction + /// Receives funds from the Light vault via SPL interface + #[account( + mut, + token::mint = mint_to_raise, + token::authority = fee_payer, + )] + pub maker_ata: InterfaceAccount<'info, TokenAccount>, + + pub token_program: Interface<'info, TokenInterface>, + pub system_program: Program<'info, System>, + + /// Light token program for CPI calls + pub light_token_program: Interface<'info, TokenInterface>, + + /// CHECK: Light token rent sponsor - validated by address constraint + #[account(mut, address = RENT_SPONSOR)] + pub light_token_rent_sponsor: AccountInfo<'info>, + + /// CHECK: light-token CPI authority - must be writable for Light token CPI + #[account(mut)] + pub light_token_cpi_authority: AccountInfo<'info>, + + /// CHECK: SPL interface PDA for mint (token pool holding SPL tokens) + /// Derived by light-token program: ["pool", mint] + #[account(mut)] + pub spl_interface_pda: UncheckedAccount<'info>, +} + +impl<'info> CheckContributions<'info> { + pub fn check_contributions(&self, _bumps: &CheckContributionsBumps) -> Result<()> { + let vault_balance = get_token_account_balance(&self.vault.to_account_info()) + .map_err(|_| anchor_lang::prelude::ProgramError::InvalidAccountData)?; + require!( + vault_balance >= self.fundraiser.amount_to_raise, + FundraiserError::TargetNotMet + ); + + let fundraiser_seeds: &[&[u8]] = &[ + b"fundraiser".as_ref(), + self.fee_payer.to_account_info().key.as_ref(), + &[self.fundraiser.bump], + ]; + + let (_, spl_interface_bump) = find_spl_interface_pda(&self.mint_to_raise.key(), false); + let decimals = self.mint_to_raise.decimals; + + let spl_interface = SplInterfaceConfig { + mint: self.mint_to_raise.to_account_info(), + spl_token_program: self.token_program.to_account_info(), + spl_interface_pda: self.spl_interface_pda.to_account_info(), + spl_interface_pda_bump: spl_interface_bump, + }; + + transfer_tokens( + vault_balance, + decimals, + self.vault.to_account_info(), + self.maker_ata.to_account_info(), + self.mint_to_raise.to_account_info(), + self.fundraiser.to_account_info(), + self.fee_payer.to_account_info(), + self.light_token_cpi_authority.to_account_info(), + self.system_program.to_account_info(), + Some(fundraiser_seeds), + Some(spl_interface), + )?; + + Ok(()) + } +} diff --git a/programs/anchor/fundraiser/src/instructions/contribute.rs b/programs/anchor/fundraiser/src/instructions/contribute.rs new file mode 100644 index 0000000..a3ed0a9 --- /dev/null +++ b/programs/anchor/fundraiser/src/instructions/contribute.rs @@ -0,0 +1,124 @@ +use anchor_lang::prelude::*; +use light_anchor_spl::token_interface::{Mint, TokenAccount, TokenInterface}; +use light_token::instruction::RENT_SPONSOR; +use light_token::spl_interface::find_spl_interface_pda; + +use crate::constants::{ANCHOR_DISCRIMINATOR, VAULT_SEED}; +use crate::instructions::{transfer_tokens, SplInterfaceConfig}; +use crate::state::{Contributor, Fundraiser}; +use crate::{FundraiserError, MAX_CONTRIBUTION_PERCENTAGE, PERCENTAGE_SCALER, SECONDS_TO_DAYS}; + +#[derive(Accounts)] +pub struct Contribute<'info> { + #[account(mut)] + pub contributor: Signer<'info>, + + #[account(mint::token_program = token_program)] + pub mint_to_raise: InterfaceAccount<'info, Mint>, + + #[account( + mut, + has_one = mint_to_raise, + seeds = [b"fundraiser".as_ref(), fundraiser.maker.as_ref()], + bump = fundraiser.bump, + )] + pub fundraiser: Account<'info, Fundraiser>, + + #[account( + init_if_needed, + payer = contributor, + seeds = [b"contributor", fundraiser.key().as_ref(), contributor.key().as_ref()], + bump, + space = ANCHOR_DISCRIMINATOR + Contributor::INIT_SPACE, + )] + pub contributor_account: Account<'info, Contributor>, + + #[account( + mut, + token::mint = mint_to_raise, + token::authority = contributor + )] + pub contributor_ata: InterfaceAccount<'info, TokenAccount>, + + /// CHECK: Vault token account + #[account( + mut, + seeds = [VAULT_SEED, fundraiser.key().as_ref()], + bump, + )] + pub vault: UncheckedAccount<'info>, + + pub token_program: Interface<'info, TokenInterface>, + pub system_program: Program<'info, System>, + + /// Light token program for CPI calls + pub light_token_program: Interface<'info, TokenInterface>, + + /// CHECK: Light token rent sponsor + #[account(mut, address = RENT_SPONSOR)] + pub light_token_rent_sponsor: AccountInfo<'info>, + + /// CHECK: light-token CPI authority - must be writable for Light token CPI + #[account(mut)] + pub light_token_cpi_authority: AccountInfo<'info>, + + /// CHECK: SPL interface PDA for mint (token pool holding SPL tokens) + /// Derived by light-token program: ["pool", mint] + #[account(mut)] + pub spl_interface_pda: UncheckedAccount<'info>, +} + +impl<'info> Contribute<'info> { + pub fn contribute(&mut self, amount: u64) -> Result<()> { + require!( + amount >= 10_u64.pow(self.mint_to_raise.decimals as u32), + FundraiserError::ContributionTooSmall + ); + + let max_contribution = + (self.fundraiser.amount_to_raise * MAX_CONTRIBUTION_PERCENTAGE) / PERCENTAGE_SCALER; + require!(amount <= max_contribution, FundraiserError::ContributionTooBig); + + let current_time = Clock::get()?.unix_timestamp; + let elapsed_days = ((current_time - self.fundraiser.time_started) / SECONDS_TO_DAYS) as u16; + require!( + elapsed_days < self.fundraiser.duration, + FundraiserError::FundraiserEnded + ); + + require!( + self.contributor_account.amount <= max_contribution + && self.contributor_account.amount + amount <= max_contribution, + FundraiserError::MaximumContributionsReached + ); + + let (_, spl_interface_bump) = find_spl_interface_pda(&self.mint_to_raise.key(), false); + let decimals = self.mint_to_raise.decimals; + + let spl_interface = SplInterfaceConfig { + mint: self.mint_to_raise.to_account_info(), + spl_token_program: self.token_program.to_account_info(), + spl_interface_pda: self.spl_interface_pda.to_account_info(), + spl_interface_pda_bump: spl_interface_bump, + }; + + transfer_tokens( + amount, + decimals, + self.contributor_ata.to_account_info(), + self.vault.to_account_info(), + self.mint_to_raise.to_account_info(), + self.contributor.to_account_info(), + self.contributor.to_account_info(), + self.light_token_cpi_authority.to_account_info(), + self.system_program.to_account_info(), + None, + Some(spl_interface), + )?; + + self.fundraiser.current_amount += amount; + self.contributor_account.amount += amount; + + Ok(()) + } +} diff --git a/programs/anchor/fundraiser/src/instructions/initialize.rs b/programs/anchor/fundraiser/src/instructions/initialize.rs new file mode 100644 index 0000000..2f6b78c --- /dev/null +++ b/programs/anchor/fundraiser/src/instructions/initialize.rs @@ -0,0 +1,89 @@ +use anchor_lang::prelude::*; +use light_anchor_spl::token_interface::{Mint, TokenInterface}; +use light_sdk::interface::CreateAccountsProof; +use light_token::anchor::LightAccounts; +use light_token::instruction::{COMPRESSIBLE_CONFIG_V1, RENT_SPONSOR}; + +use crate::constants::{ANCHOR_DISCRIMINATOR, VAULT_SEED}; +use crate::state::Fundraiser; +use crate::{FundraiserError, MIN_AMOUNT_TO_RAISE}; + +#[derive(AnchorSerialize, AnchorDeserialize, Clone)] +pub struct InitializeParams { + pub create_accounts_proof: CreateAccountsProof, + pub amount: u64, + pub duration: u16, + pub vault_bump: u8, +} + +#[derive(Accounts, LightAccounts)] +#[instruction(params: InitializeParams)] +pub struct Initialize<'info> { + /// The maker who creates the fundraiser (also the fee payer for Light Protocol) + #[account(mut)] + pub fee_payer: Signer<'info>, + + #[account(mint::token_program = token_program)] + pub mint_to_raise: InterfaceAccount<'info, Mint>, + + #[account( + init, + payer = fee_payer, + space = ANCHOR_DISCRIMINATOR + Fundraiser::INIT_SPACE, + seeds = [b"fundraiser", fee_payer.key().as_ref()], + bump, + )] + pub fundraiser: Account<'info, Fundraiser>, + + /// CHECK: Vault token account - initialized via light_account macro + #[account( + mut, + seeds = [VAULT_SEED, fundraiser.key().as_ref()], + bump, + )] + #[light_account(init, + token::authority = [VAULT_SEED, self.fundraiser.key()], + token::mint = mint_to_raise, + token::owner = fundraiser, + token::bump = params.vault_bump + )] + pub vault: UncheckedAccount<'info>, + + pub token_program: Interface<'info, TokenInterface>, + pub system_program: Program<'info, System>, + + /// Light token program for CPI calls + pub light_token_program: Interface<'info, TokenInterface>, + + /// CHECK: Light token compressible config - validated by address constraint + #[account(address = COMPRESSIBLE_CONFIG_V1)] + pub light_token_compressible_config: AccountInfo<'info>, + + /// CHECK: Light token rent sponsor - validated by address constraint + #[account(mut, address = RENT_SPONSOR)] + pub light_token_rent_sponsor: AccountInfo<'info>, + + /// CHECK: light-token CPI authority + pub light_token_cpi_authority: AccountInfo<'info>, +} + +impl<'info> Initialize<'info> { + pub fn initialize(&mut self, params: &InitializeParams, bumps: &InitializeBumps) -> Result<()> { + require!( + params.amount >= MIN_AMOUNT_TO_RAISE.checked_mul(10_u64.pow(self.mint_to_raise.decimals as u32)).ok_or(FundraiserError::InvalidAmount)?, + FundraiserError::InvalidAmount + ); + + self.fundraiser.set_inner(Fundraiser { + maker: self.fee_payer.key(), + mint_to_raise: self.mint_to_raise.key(), + amount_to_raise: params.amount, + current_amount: 0, + time_started: Clock::get()?.unix_timestamp, + duration: params.duration, + bump: bumps.fundraiser, + }); + + Ok(()) + } +} diff --git a/programs/anchor/fundraiser/src/instructions/mod.rs b/programs/anchor/fundraiser/src/instructions/mod.rs new file mode 100644 index 0000000..535fdbb --- /dev/null +++ b/programs/anchor/fundraiser/src/instructions/mod.rs @@ -0,0 +1,11 @@ +pub mod checker; +pub mod contribute; +pub mod initialize; +pub mod refund; +pub mod shared; + +pub use checker::*; +pub use contribute::*; +pub use initialize::*; +pub use refund::*; +pub use shared::*; diff --git a/programs/anchor/fundraiser/src/instructions/refund.rs b/programs/anchor/fundraiser/src/instructions/refund.rs new file mode 100644 index 0000000..ff602f5 --- /dev/null +++ b/programs/anchor/fundraiser/src/instructions/refund.rs @@ -0,0 +1,124 @@ +use anchor_lang::prelude::*; +use light_anchor_spl::token_interface::{Mint, TokenAccount, TokenInterface}; +use light_token::instruction::RENT_SPONSOR; +use light_token::spl_interface::find_spl_interface_pda; +use light_token::utils::get_token_account_balance; + +use crate::constants::VAULT_SEED; +use crate::instructions::{transfer_tokens, SplInterfaceConfig}; +use crate::state::{Contributor, Fundraiser}; +use crate::{FundraiserError, SECONDS_TO_DAYS}; + +#[derive(Accounts)] +pub struct Refund<'info> { + #[account(mut)] + pub contributor: Signer<'info>, + + pub maker: SystemAccount<'info>, + + #[account(mint::token_program = token_program)] + pub mint_to_raise: InterfaceAccount<'info, Mint>, + + #[account( + mut, + has_one = mint_to_raise, + seeds = [b"fundraiser", maker.key().as_ref()], + bump = fundraiser.bump, + )] + pub fundraiser: Account<'info, Fundraiser>, + + #[account( + mut, + seeds = [b"contributor", fundraiser.key().as_ref(), contributor.key().as_ref()], + bump, + close = contributor, + )] + pub contributor_account: Account<'info, Contributor>, + + #[account( + mut, + token::mint = mint_to_raise, + token::authority = contributor + )] + pub contributor_ata: InterfaceAccount<'info, TokenAccount>, + + /// CHECK: Vault token account + #[account( + mut, + seeds = [VAULT_SEED, fundraiser.key().as_ref()], + bump, + )] + pub vault: UncheckedAccount<'info>, + + pub token_program: Interface<'info, TokenInterface>, + pub system_program: Program<'info, System>, + + /// Light token program for CPI calls + pub light_token_program: Interface<'info, TokenInterface>, + + /// CHECK: Light token rent sponsor + #[account(mut, address = RENT_SPONSOR)] + pub light_token_rent_sponsor: AccountInfo<'info>, + + /// CHECK: light-token CPI authority - must be writable for Light token CPI + #[account(mut)] + pub light_token_cpi_authority: AccountInfo<'info>, + + /// CHECK: SPL interface PDA for mint (token pool holding SPL tokens) + /// Derived by light-token program: ["pool", mint] + #[account(mut)] + pub spl_interface_pda: UncheckedAccount<'info>, +} + +impl<'info> Refund<'info> { + pub fn refund(&mut self, _bumps: &RefundBumps) -> Result<()> { + let current_time = Clock::get()?.unix_timestamp; + require!( + self.fundraiser.duration + < ((current_time - self.fundraiser.time_started) / SECONDS_TO_DAYS) as u16, + FundraiserError::FundraiserNotEnded + ); + + let vault_balance = get_token_account_balance(&self.vault.to_account_info()) + .map_err(|_| anchor_lang::prelude::ProgramError::InvalidAccountData)?; + require!( + vault_balance < self.fundraiser.amount_to_raise, + FundraiserError::TargetMet + ); + + let fundraiser_seeds: &[&[u8]] = &[ + b"fundraiser".as_ref(), + self.maker.to_account_info().key.as_ref(), + &[self.fundraiser.bump], + ]; + + let (_, spl_interface_bump) = find_spl_interface_pda(&self.mint_to_raise.key(), false); + let decimals = self.mint_to_raise.decimals; + let refund_amount = self.contributor_account.amount; + + let spl_interface = SplInterfaceConfig { + mint: self.mint_to_raise.to_account_info(), + spl_token_program: self.token_program.to_account_info(), + spl_interface_pda: self.spl_interface_pda.to_account_info(), + spl_interface_pda_bump: spl_interface_bump, + }; + + transfer_tokens( + refund_amount, + decimals, + self.vault.to_account_info(), + self.contributor_ata.to_account_info(), + self.mint_to_raise.to_account_info(), + self.fundraiser.to_account_info(), + self.contributor.to_account_info(), + self.light_token_cpi_authority.to_account_info(), + self.system_program.to_account_info(), + Some(fundraiser_seeds), + Some(spl_interface), + )?; + + self.fundraiser.current_amount -= refund_amount; + + Ok(()) + } +} diff --git a/programs/anchor/fundraiser/src/instructions/shared.rs b/programs/anchor/fundraiser/src/instructions/shared.rs new file mode 100644 index 0000000..9cc609e --- /dev/null +++ b/programs/anchor/fundraiser/src/instructions/shared.rs @@ -0,0 +1,86 @@ +use anchor_lang::prelude::*; +use light_sdk::constants::LIGHT_TOKEN_PROGRAM_ID; +use light_token::instruction::{TransferCheckedCpi, TransferInterfaceCpi}; + +/// Configuration for SPL interface (required for SPL<->Light transfers) +pub struct SplInterfaceConfig<'info> { + pub mint: AccountInfo<'info>, + pub spl_token_program: AccountInfo<'info>, + pub spl_interface_pda: AccountInfo<'info>, + pub spl_interface_pda_bump: u8, +} + +/// Check if an account is a Light token account (owned by Light token program) +fn is_light_account(account: &AccountInfo) -> bool { + account.owner == &Pubkey::new_from_array(LIGHT_TOKEN_PROGRAM_ID) +} + +/// Transfer tokens between token accounts. +/// For Light-to-Light transfers, uses TransferCheckedCpi with mint validation. +/// For SPL<->Light transfers, uses TransferInterfaceCpi with spl_interface config. +pub fn transfer_tokens<'info>( + amount: u64, + decimals: u8, + from: AccountInfo<'info>, + to: AccountInfo<'info>, + mint: AccountInfo<'info>, + authority: AccountInfo<'info>, + payer: AccountInfo<'info>, + light_token_cpi_authority: AccountInfo<'info>, + system_program: AccountInfo<'info>, + signer_seeds: Option<&[&[u8]]>, + spl_interface: Option>, +) -> Result<()> { + let is_light_to_light = is_light_account(&from) && is_light_account(&to); + + if is_light_to_light { + // fee_payer: Some ensures authority is readonly (required for PDA with account data) + let cpi = TransferCheckedCpi { + source: from, + mint, + destination: to, + amount, + decimals, + authority, + system_program, + max_top_up: Some(0), // Allow top-ups but with 0 limit + fee_payer: Some(payer), // Payer handles any rent, makes authority readonly + }; + + if let Some(seeds) = signer_seeds { + cpi.invoke_signed(&[seeds]) + } else { + cpi.invoke() + } + .map_err(|e| anchor_lang::prelude::ProgramError::from(e).into()) + } else { + let mut cpi = TransferInterfaceCpi::new( + amount, + decimals, + from, + to, + authority, + payer, + light_token_cpi_authority, + system_program, + ); + + if let Some(spl) = spl_interface { + cpi = cpi + .with_spl_interface( + Some(spl.mint), + Some(spl.spl_token_program), + Some(spl.spl_interface_pda), + Some(spl.spl_interface_pda_bump), + ) + .map_err(|e| anchor_lang::prelude::ProgramError::from(e))?; + } + + if let Some(seeds) = signer_seeds { + cpi.invoke_signed(&[seeds]) + } else { + cpi.invoke() + } + .map_err(|e| anchor_lang::prelude::ProgramError::from(e).into()) + } +} diff --git a/programs/anchor/fundraiser/src/lib.rs b/programs/anchor/fundraiser/src/lib.rs new file mode 100644 index 0000000..aec2c87 --- /dev/null +++ b/programs/anchor/fundraiser/src/lib.rs @@ -0,0 +1,43 @@ +use anchor_lang::prelude::*; +use light_token::anchor::{derive_light_cpi_signer, light_program, CpiSigner}; + +declare_id!("Eoiuq1dXvHxh6dLx3wh9gj8kSAUpga11krTrbfF5XYsC"); + +pub const LIGHT_CPI_SIGNER: CpiSigner = + derive_light_cpi_signer!("Eoiuq1dXvHxh6dLx3wh9gj8kSAUpga11krTrbfF5XYsC"); + +mod constants; +mod error; +pub mod instructions; +mod state; + +pub use constants::*; +use error::*; +pub use instructions::*; + +#[light_program] +// Anchor's #[program] macro uses deprecated AccountInfo::realloc internally +#[allow(deprecated)] +#[program] +pub mod fundraiser { + use super::*; + + pub fn initialize<'info>( + ctx: Context<'_, '_, '_, 'info, Initialize<'info>>, + params: InitializeParams, + ) -> Result<()> { + ctx.accounts.initialize(¶ms, &ctx.bumps) + } + + pub fn contribute(ctx: Context, amount: u64) -> Result<()> { + ctx.accounts.contribute(amount) + } + + pub fn check_contributions(ctx: Context) -> Result<()> { + ctx.accounts.check_contributions(&ctx.bumps) + } + + pub fn refund(ctx: Context) -> Result<()> { + ctx.accounts.refund(&ctx.bumps) + } +} diff --git a/programs/anchor/fundraiser/src/state/contributor.rs b/programs/anchor/fundraiser/src/state/contributor.rs new file mode 100644 index 0000000..ff83b0f --- /dev/null +++ b/programs/anchor/fundraiser/src/state/contributor.rs @@ -0,0 +1,7 @@ +use anchor_lang::prelude::*; + +#[account] +#[derive(InitSpace)] +pub struct Contributor { + pub amount: u64, +} diff --git a/programs/anchor/fundraiser/src/state/fundraiser.rs b/programs/anchor/fundraiser/src/state/fundraiser.rs new file mode 100644 index 0000000..ceaf9c2 --- /dev/null +++ b/programs/anchor/fundraiser/src/state/fundraiser.rs @@ -0,0 +1,13 @@ +use anchor_lang::prelude::*; + +#[account] +#[derive(InitSpace)] +pub struct Fundraiser { + pub maker: Pubkey, + pub mint_to_raise: Pubkey, + pub amount_to_raise: u64, + pub current_amount: u64, + pub time_started: i64, + pub duration: u16, + pub bump: u8, +} diff --git a/programs/anchor/fundraiser/src/state/mod.rs b/programs/anchor/fundraiser/src/state/mod.rs new file mode 100644 index 0000000..d4c1b82 --- /dev/null +++ b/programs/anchor/fundraiser/src/state/mod.rs @@ -0,0 +1,5 @@ +pub mod contributor; +pub mod fundraiser; + +pub use contributor::*; +pub use fundraiser::*; diff --git a/programs/anchor/fundraiser/tests/common/mod.rs b/programs/anchor/fundraiser/tests/common/mod.rs new file mode 100644 index 0000000..47a33ca --- /dev/null +++ b/programs/anchor/fundraiser/tests/common/mod.rs @@ -0,0 +1,634 @@ +//! Common test utilities for fundraiser tests. +//! +//! This module provides shared test helpers for different token type combinations: +//! - SPL mint + SPL ATAs +//! - T22 mint + T22 ATAs +//! - SPL mint + Light user accounts +//! - T22 mint + Light user accounts +//! - Light mint + Light user accounts + +use anchor_lang::{InstructionData, ToAccountMetas}; +use anchor_spl::token; +use shared_test_utils::{ + helpers::verify_light_token_balance, + light_tokens::{create_light_ata, create_light_mint, mint_light_tokens}, + setup::initialize_rent_free_config, + spl_interface::{create_spl_interface_pda, transfer_spl_to_light}, + spl_tokens::{create_spl_ata, create_spl_mint, mint_spl_tokens}, + t22_tokens::{create_t22_ata, create_t22_mint, mint_t22_tokens}, + CreateAccountsProofResult, Indexer, LightProgramTest, MintType, ProgramTestConfig, Rpc, + TestRpc, COMPRESSIBLE_CONFIG_V1, CPI_AUTHORITY_PDA, LIGHT_TOKEN_MINTER_PROGRAM_ID, + LIGHT_TOKEN_PROGRAM_ID, RENT_SPONSOR, +}; +use solana_instruction::Instruction; +use solana_keypair::Keypair; +use solana_pubkey::Pubkey; +use solana_signer::Signer; +use spl_token_2022::pod::PodAccount; + +/// Token configuration for parameterized tests +#[allow(dead_code)] +#[derive(Clone, Copy, Debug)] +pub enum TokenConfig { + /// SPL mint + SPL ATAs + Spl, + /// T22 mint + T22 ATAs + Token2022, + /// SPL mint + Light user accounts (offchain SPL->Light conversion) + LightSpl, + /// T22 mint + Light user accounts (offchain T22->Light conversion) + LightT22, + /// Light mint + Light user accounts (pure Light-to-Light) + Light, +} + +impl TokenConfig { + pub fn mint_type(&self) -> MintType { + match self { + TokenConfig::Spl | TokenConfig::LightSpl => MintType::Spl, + TokenConfig::Token2022 | TokenConfig::LightT22 => MintType::Token2022, + TokenConfig::Light => MintType::Spl, // Light mints use SPL-compatible layout + } + } + + pub fn token_program_id(&self) -> Pubkey { + match self { + TokenConfig::Spl | TokenConfig::LightSpl => token::ID, + TokenConfig::Token2022 | TokenConfig::LightT22 => spl_token_2022::ID, + TokenConfig::Light => Pubkey::new_from_array(LIGHT_TOKEN_PROGRAM_ID), + } + } + + /// Returns true if mints are Light Protocol mints (not SPL/T22) + pub fn uses_light_mints(&self) -> bool { + matches!(self, TokenConfig::Light) + } +} + +/// Context for fundraiser tests containing all necessary accounts +#[allow(dead_code)] +pub struct FundraiserTestContext { + pub program_id: Pubkey, + pub payer: Keypair, + pub mint: Keypair, + /// For Light mints, stores the mint PDA + pub mint_pubkey: Pubkey, + pub maker: Keypair, + pub fundraiser_pda: Pubkey, + pub vault_pda: Pubkey, + pub vault_bump: u8, + pub spl_interface_pda: Pubkey, + pub spl_interface_bump: u8, + pub token_config: TokenConfig, + pub amount_to_raise: u64, + pub duration: u16, + /// Config PDA for light mint creation + pub compression_config: Option, + /// Authority keypair for Light mint (if Light config) + pub light_mint_authority: Option, +} + +/// Create a new LightProgramTest instance for fundraiser tests +pub async fn create_test_rpc() -> LightProgramTest { + let program_id = fundraiser::ID; + let mut config = ProgramTestConfig::new_v2( + true, + Some(vec![ + ("fundraiser", program_id), + ("light_token_minter", LIGHT_TOKEN_MINTER_PROGRAM_ID), + ]), + ); + config = config.with_light_protocol_events(); + LightProgramTest::new(config).await.unwrap() +} + +/// Setup the fundraiser test environment based on token config +pub async fn setup_fundraiser_test( + rpc: &mut R, + config: TokenConfig, +) -> FundraiserTestContext { + let program_id = fundraiser::ID; + let payer = rpc.get_payer().insecure_clone(); + + // Initialize rent-free config (returns the config PDA) + let compression_config = initialize_rent_free_config(rpc, &payer, &program_id).await; + + // Create maker + let maker = Keypair::new(); + rpc.airdrop_lamports(&maker.pubkey(), 10_000_000_000) + .await + .unwrap(); + + // Amount to raise: 1000 tokens (with 9 decimals) + let amount_to_raise = 1_000_000_000_000u64; + let duration = 7u16; // 7 days + + // For Light mints, handle separately + if config.uses_light_mints() { + // ========== LIGHT MINT SETUP ========== + println!("\n=== Setting up Light mint ==="); + + // Create Light mint + let light_mint = create_light_mint( + rpc, + &payer, + 9, + "Fundraiser Token", + "FUND", + &compression_config, + ) + .await; + + let mint_pubkey = light_mint.mint; + println!("Light Mint: {:?}", mint_pubkey); + + // For pure Light-to-Light, we don't need SPL interface PDA + let spl_interface_pda = Pubkey::default(); + + // Derive fundraiser and vault PDAs + let (fundraiser_pda, _) = + Pubkey::find_program_address(&[b"fundraiser", maker.pubkey().as_ref()], &program_id); + + let (vault_pda, vault_bump) = Pubkey::find_program_address( + &[fundraiser::VAULT_SEED, fundraiser_pda.as_ref()], + &program_id, + ); + + println!("Fundraiser PDA: {:?}", fundraiser_pda); + println!("Vault PDA: {:?}", vault_pda); + + // Create dummy keypair for mint (not used for Light mints) + let dummy_keypair = Keypair::new(); + + return FundraiserTestContext { + program_id, + payer, + mint: dummy_keypair, + mint_pubkey, + maker, + fundraiser_pda, + vault_pda, + vault_bump, + spl_interface_pda, + spl_interface_bump: 0, + token_config: config, + amount_to_raise, + duration, + compression_config: Some(compression_config), + light_mint_authority: Some(light_mint.authority), + }; + } + + // ========== SPL/T22 MINT SETUP ========== + // Create mint based on config (SPL or T22 - Light user accounts still use SPL/T22 mints) + let mint = match config { + TokenConfig::Spl | TokenConfig::LightSpl => { + create_spl_mint(rpc, &payer, &payer.pubkey(), 9).await + } + TokenConfig::Token2022 | TokenConfig::LightT22 => { + create_t22_mint(rpc, &payer, &payer.pubkey(), 9).await + } + TokenConfig::Light => unreachable!("Light config handled above"), + }; + + let mint_pubkey = mint.pubkey(); + println!("Mint created: {:?}", mint_pubkey); + + // Create SPL interface PDA + println!("\n=== Creating SPL interface PDA ==="); + let spl_interface_result = + create_spl_interface_pda(rpc, &payer, &mint_pubkey, config.mint_type(), false).await; + + // Derive fundraiser and vault PDAs + let (fundraiser_pda, _) = + Pubkey::find_program_address(&[b"fundraiser", maker.pubkey().as_ref()], &program_id); + + let (vault_pda, vault_bump) = Pubkey::find_program_address( + &[fundraiser::VAULT_SEED, fundraiser_pda.as_ref()], + &program_id, + ); + + println!("Fundraiser PDA: {:?}", fundraiser_pda); + println!("Vault PDA: {:?}", vault_pda); + + FundraiserTestContext { + program_id, + payer, + mint, + mint_pubkey, + maker, + fundraiser_pda, + vault_pda, + vault_bump, + spl_interface_pda: spl_interface_result.pda, + spl_interface_bump: spl_interface_result.bump, + token_config: config, + amount_to_raise, + duration, + compression_config: Some(compression_config), + light_mint_authority: None, + } +} + +/// Initialize fundraiser +pub async fn initialize_fundraiser( + rpc: &mut R, + ctx: &FundraiserTestContext, + proof_result: CreateAccountsProofResult, +) { + println!("\n=== Initializing Fundraiser ==="); + + let token_program = ctx.token_config.token_program_id(); + + let initialize_accounts = fundraiser::accounts::Initialize { + fee_payer: ctx.maker.pubkey(), + mint_to_raise: ctx.mint_pubkey, + fundraiser: ctx.fundraiser_pda, + vault: ctx.vault_pda, + token_program, + system_program: solana_sdk::system_program::ID, + light_token_program: Pubkey::new_from_array(LIGHT_TOKEN_PROGRAM_ID), + light_token_compressible_config: COMPRESSIBLE_CONFIG_V1, + light_token_rent_sponsor: RENT_SPONSOR, + light_token_cpi_authority: CPI_AUTHORITY_PDA, + }; + + let initialize_data = fundraiser::instruction::Initialize { + params: fundraiser::instructions::InitializeParams { + create_accounts_proof: proof_result.create_accounts_proof, + amount: ctx.amount_to_raise, + duration: ctx.duration, + vault_bump: ctx.vault_bump, + }, + }; + + let initialize_ix = Instruction { + program_id: ctx.program_id, + accounts: [ + initialize_accounts.to_account_metas(None), + proof_result.remaining_accounts, + ] + .concat(), + data: initialize_data.data(), + }; + + rpc.create_and_send_transaction( + &[initialize_ix], + &ctx.payer.pubkey(), + &[&ctx.payer, &ctx.maker], + ) + .await + .expect("initialize should succeed"); + + println!("Fundraiser initialized!"); + println!( + " Amount to raise: {} tokens", + ctx.amount_to_raise / 1_000_000_000 + ); + println!(" Duration: {} days", ctx.duration); +} + +/// Create a contributor with ATA and funded tokens +pub async fn create_contributor( + rpc: &mut R, + ctx: &FundraiserTestContext, + funding_amount: u64, +) -> (Keypair, Pubkey) { + let contributor = Keypair::new(); + rpc.airdrop_lamports(&contributor.pubkey(), 5_000_000_000) + .await + .unwrap(); + + let contributor_ata = match ctx.token_config { + TokenConfig::Spl => { + let ata = + create_spl_ata(rpc, &ctx.payer, &ctx.mint_pubkey, &contributor.pubkey()).await; + mint_spl_tokens( + rpc, + &ctx.payer, + &ctx.mint_pubkey, + &ata, + &ctx.payer, + funding_amount, + ) + .await; + ata + } + TokenConfig::Token2022 => { + let ata = + create_t22_ata(rpc, &ctx.payer, &ctx.mint_pubkey, &contributor.pubkey()).await; + mint_t22_tokens( + rpc, + &ctx.payer, + &ctx.mint_pubkey, + &ata, + &ctx.payer, + funding_amount, + ) + .await; + ata + } + TokenConfig::LightSpl => { + // For Light user accounts with SPL mint: + // 1. Create temp SPL ATA, mint tokens + // 2. Create Light ATA + // 3. Transfer from SPL to Light (compress) + println!("Creating Light contributor account (SPL mint)"); + + let temp_ata = + create_spl_ata(rpc, &ctx.payer, &ctx.mint_pubkey, &contributor.pubkey()).await; + mint_spl_tokens( + rpc, + &ctx.payer, + &ctx.mint_pubkey, + &temp_ata, + &ctx.payer, + funding_amount, + ) + .await; + + // Create Light ATA + let light_ata = + create_light_ata(rpc, &ctx.payer, &ctx.mint_pubkey, &contributor.pubkey()).await; + + // Transfer from SPL to Light (compress) + transfer_spl_to_light( + rpc, + &ctx.payer, + &contributor, + &ctx.mint_pubkey, + 9, + &temp_ata, + &light_ata, + &ctx.spl_interface_pda, + ctx.spl_interface_bump, + funding_amount, + MintType::Spl, + ) + .await; + + light_ata + } + TokenConfig::LightT22 => { + // For Light user accounts with T22 mint: + println!("Creating Light contributor account (T22 mint)"); + + let temp_ata = + create_t22_ata(rpc, &ctx.payer, &ctx.mint_pubkey, &contributor.pubkey()).await; + mint_t22_tokens( + rpc, + &ctx.payer, + &ctx.mint_pubkey, + &temp_ata, + &ctx.payer, + funding_amount, + ) + .await; + + // Create Light ATA + let light_ata = + create_light_ata(rpc, &ctx.payer, &ctx.mint_pubkey, &contributor.pubkey()).await; + + // Transfer from T22 to Light (compress) + transfer_spl_to_light( + rpc, + &ctx.payer, + &contributor, + &ctx.mint_pubkey, + 9, + &temp_ata, + &light_ata, + &ctx.spl_interface_pda, + ctx.spl_interface_bump, + funding_amount, + MintType::Token2022, + ) + .await; + + light_ata + } + TokenConfig::Light => { + // For pure Light mints: + // Mint directly to contributor's Light ATA + println!("Creating Light contributor account (Light mint)"); + + let mint_authority = ctx + .light_mint_authority + .as_ref() + .expect("Light config should have mint authority"); + + // Mint tokens directly to contributor's Light ATA + let light_ata = mint_light_tokens( + rpc, + &ctx.payer, + mint_authority, + &ctx.mint_pubkey, + &contributor.pubkey(), + funding_amount, + ) + .await; + + light_ata + } + }; + + (contributor, contributor_ata) +} + +/// Contribute to fundraiser +pub async fn contribute( + rpc: &mut R, + ctx: &FundraiserTestContext, + contributor: &Keypair, + contributor_ata: Pubkey, + amount: u64, +) { + println!("\n=== Contributing ==="); + + let token_program = ctx.token_config.token_program_id(); + + // Derive contributor account PDA + let (contributor_account_pda, _) = Pubkey::find_program_address( + &[ + b"contributor", + ctx.fundraiser_pda.as_ref(), + contributor.pubkey().as_ref(), + ], + &ctx.program_id, + ); + + let contribute_accounts = fundraiser::accounts::Contribute { + contributor: contributor.pubkey(), + mint_to_raise: ctx.mint_pubkey, + fundraiser: ctx.fundraiser_pda, + contributor_account: contributor_account_pda, + contributor_ata, + vault: ctx.vault_pda, + token_program, + system_program: solana_sdk::system_program::ID, + light_token_program: Pubkey::new_from_array(LIGHT_TOKEN_PROGRAM_ID), + light_token_rent_sponsor: RENT_SPONSOR, + light_token_cpi_authority: CPI_AUTHORITY_PDA, + spl_interface_pda: ctx.spl_interface_pda, + }; + + let contribute_data = fundraiser::instruction::Contribute { amount }; + + let contribute_ix = Instruction { + program_id: ctx.program_id, + accounts: contribute_accounts.to_account_metas(None), + data: contribute_data.data(), + }; + + rpc.create_and_send_transaction( + &[contribute_ix], + &ctx.payer.pubkey(), + &[&ctx.payer, contributor], + ) + .await + .expect("contribute should succeed"); + + println!("Contributed {} tokens", amount / 1_000_000_000); +} + +/// Check contributions and claim funds (maker claims) +pub async fn check_contributions(rpc: &mut R, ctx: &FundraiserTestContext) -> Pubkey { + println!("\n=== Maker Claims Funds ==="); + + let token_program = ctx.token_config.token_program_id(); + + // Create maker's ATA (SPL/T22 receives from Light vault via SPL interface, Light receives directly) + let maker_ata = match ctx.token_config { + TokenConfig::Spl | TokenConfig::LightSpl => { + create_spl_ata(rpc, &ctx.payer, &ctx.mint_pubkey, &ctx.maker.pubkey()).await + } + TokenConfig::Token2022 | TokenConfig::LightT22 => { + create_t22_ata(rpc, &ctx.payer, &ctx.mint_pubkey, &ctx.maker.pubkey()).await + } + TokenConfig::Light => { + // For pure Light mints, maker receives to Light ATA + create_light_ata(rpc, &ctx.payer, &ctx.mint_pubkey, &ctx.maker.pubkey()).await + } + }; + + let check_contributions_accounts = fundraiser::accounts::CheckContributions { + fee_payer: ctx.maker.pubkey(), + mint_to_raise: ctx.mint_pubkey, + fundraiser: ctx.fundraiser_pda, + vault: ctx.vault_pda, + maker_ata, + token_program, + system_program: solana_sdk::system_program::ID, + light_token_program: Pubkey::new_from_array(LIGHT_TOKEN_PROGRAM_ID), + light_token_rent_sponsor: RENT_SPONSOR, + light_token_cpi_authority: CPI_AUTHORITY_PDA, + spl_interface_pda: ctx.spl_interface_pda, + }; + + let check_contributions_data = fundraiser::instruction::CheckContributions {}; + + let check_contributions_ix = Instruction { + program_id: ctx.program_id, + accounts: check_contributions_accounts.to_account_metas(None), + data: check_contributions_data.data(), + }; + + rpc.create_and_send_transaction( + &[check_contributions_ix], + &ctx.payer.pubkey(), + &[&ctx.payer, &ctx.maker], + ) + .await + .expect("check_contributions should succeed"); + + println!("Maker claimed funds!"); + maker_ata +} + +/// Get token balance from SPL/T22 account +pub async fn get_token_balance(rpc: &mut R, account: Pubkey) -> u64 { + let account_data = rpc + .get_account(account) + .await + .unwrap() + .expect("Token account should exist"); + + let token_state = + spl_pod::bytemuck::pod_from_bytes::(&account_data.data[..165]).unwrap(); + u64::from(token_state.amount) +} + +/// Run the full fundraiser flow test +pub async fn run_fundraiser_full_flow(rpc: &mut R, ctx: &FundraiserTestContext) { + use light_client::interface::{get_create_accounts_proof, CreateAccountsProofInput}; + + // Get proof for creating vault Light token account + let proof_result = get_create_accounts_proof( + rpc, + &ctx.program_id, + vec![CreateAccountsProofInput::pda(ctx.vault_pda)], + ) + .await + .unwrap(); + + // Initialize fundraiser + initialize_fundraiser(rpc, ctx, proof_result).await; + + // Verify vault was created with 0 balance + verify_light_token_balance(rpc, ctx.vault_pda, 0, "vault (initial)").await; + + // Contribution amount is 10% of target (max allowed per contributor) + let contribution_amount = ctx.amount_to_raise * 10 / 100; + + // We need 10 contributors to reach target (each contributes 10%) + let num_contributors = 10; + let contributor_funding = contribution_amount * 2; // Give them extra to be safe + + println!( + "\n=== Creating {} contributors (each contributing {} tokens) ===", + num_contributors, + contribution_amount / 1_000_000_000 + ); + + let mut total_contributed = 0u64; + for i in 0..num_contributors { + let (contributor, contributor_ata) = + create_contributor(rpc, ctx, contributor_funding).await; + contribute(rpc, ctx, &contributor, contributor_ata, contribution_amount).await; + total_contributed += contribution_amount; + println!( + "Contributor {} contributed, total: {} tokens", + i + 1, + total_contributed / 1_000_000_000 + ); + } + + // Verify vault has reached target + verify_light_token_balance( + rpc, + ctx.vault_pda, + ctx.amount_to_raise, + "vault (target reached)", + ) + .await; + + // Maker claims funds + let maker_ata = check_contributions(rpc, ctx).await; + + // Verify vault is empty + verify_light_token_balance(rpc, ctx.vault_pda, 0, "vault (after claim)").await; + + // Verify maker received funds + let maker_balance = get_token_balance(rpc, maker_ata).await; + assert_eq!( + maker_balance, ctx.amount_to_raise, + "Maker should have received all raised funds" + ); + println!("Maker received {} tokens", maker_balance / 1_000_000_000); + + // Verify fundraiser account was closed + let fundraiser_account = rpc.get_account(ctx.fundraiser_pda).await.unwrap(); + assert!(fundraiser_account.is_none(), "Fundraiser should be closed"); + + println!("\n=== Fundraiser full flow test completed successfully! ==="); +} diff --git a/programs/anchor/fundraiser/tests/user_light.rs b/programs/anchor/fundraiser/tests/user_light.rs new file mode 100644 index 0000000..f01194a --- /dev/null +++ b/programs/anchor/fundraiser/tests/user_light.rs @@ -0,0 +1,48 @@ +//! Integration tests for the fundraiser program with Light mints and Light ATAs. +//! +//! Token Configuration: +//! - Mint Type: Light (via CreateMint instruction) +//! - User Accounts: Light token accounts (contributors) +//! - Vault Account: Light Protocol token account +//! +//! This is the pure Light-to-Light test where everything uses light tokens. + +mod common; + +use common::{create_test_rpc, run_fundraiser_full_flow, setup_fundraiser_test, TokenConfig}; + +/// Test the full fundraiser flow with Light tokens +#[tokio::test] +async fn test_fundraiser_full_flow_light() { + let mut rpc = create_test_rpc().await; + let ctx = setup_fundraiser_test(&mut rpc, TokenConfig::Light).await; + run_fundraiser_full_flow(&mut rpc, &ctx).await; +} + +/// Test fundraiser initialization with Light tokens +#[tokio::test] +async fn test_initialize_fundraiser_light() { + use common::initialize_fundraiser; + use light_client::interface::{get_create_accounts_proof, CreateAccountsProofInput}; + use shared_test_utils::helpers::verify_light_token_balance; + + let mut rpc = create_test_rpc().await; + let ctx = setup_fundraiser_test(&mut rpc, TokenConfig::Light).await; + + // Get proof for creating vault + let proof_result = get_create_accounts_proof( + &rpc, + &ctx.program_id, + vec![CreateAccountsProofInput::pda(ctx.vault_pda)], + ) + .await + .unwrap(); + + // Initialize fundraiser + initialize_fundraiser(&mut rpc, &ctx, proof_result).await; + + // Verify vault was created + verify_light_token_balance(&mut rpc, ctx.vault_pda, 0, "vault").await; + + println!("=== Initialize fundraiser test completed successfully! ==="); +} diff --git a/programs/anchor/fundraiser/tests/user_spl.rs b/programs/anchor/fundraiser/tests/user_spl.rs new file mode 100644 index 0000000..e590e5d --- /dev/null +++ b/programs/anchor/fundraiser/tests/user_spl.rs @@ -0,0 +1,46 @@ +//! Integration tests for the fundraiser program with SPL mints and SPL ATAs. +//! +//! Token Configuration: +//! - Mint Type: SPL (token::ID) +//! - User Accounts: SPL ATAs (contributors) +//! - Vault Account: Light Protocol token account + +mod common; + +use common::{create_test_rpc, run_fundraiser_full_flow, setup_fundraiser_test, TokenConfig}; + +/// Test the full fundraiser flow with SPL tokens +#[tokio::test] +async fn test_fundraiser_full_flow_spl() { + let mut rpc = create_test_rpc().await; + let ctx = setup_fundraiser_test(&mut rpc, TokenConfig::Spl).await; + run_fundraiser_full_flow(&mut rpc, &ctx).await; +} + +/// Test fundraiser initialization with SPL tokens +#[tokio::test] +async fn test_initialize_fundraiser_spl() { + use common::{initialize_fundraiser, setup_fundraiser_test}; + use light_client::interface::{get_create_accounts_proof, CreateAccountsProofInput}; + use shared_test_utils::helpers::verify_light_token_balance; + + let mut rpc = create_test_rpc().await; + let ctx = setup_fundraiser_test(&mut rpc, TokenConfig::Spl).await; + + // Get proof for creating vault + let proof_result = get_create_accounts_proof( + &rpc, + &ctx.program_id, + vec![CreateAccountsProofInput::pda(ctx.vault_pda)], + ) + .await + .unwrap(); + + // Initialize fundraiser + initialize_fundraiser(&mut rpc, &ctx, proof_result).await; + + // Verify vault was created + verify_light_token_balance(&mut rpc, ctx.vault_pda, 0, "vault").await; + + println!("=== Initialize fundraiser test completed successfully! ==="); +} diff --git a/programs/anchor/fundraiser/tests/user_spl_light.rs b/programs/anchor/fundraiser/tests/user_spl_light.rs new file mode 100644 index 0000000..cc05fd9 --- /dev/null +++ b/programs/anchor/fundraiser/tests/user_spl_light.rs @@ -0,0 +1,24 @@ +//! Integration tests for the fundraiser program with SPL mints and Light user accounts. +//! +//! Token Configuration: +//! - Mint Type: SPL (token::ID) +//! - User Accounts: Light token accounts (contributors with offchain SPL->Light conversion) +//! - Vault Account: Light Protocol token account +//! +//! ## Test Flow: +//! 1. Create SPL mint and temporary SPL ATA +//! 2. Mint tokens to temporary ATA +//! 3. Create Light token account for contributor +//! 4. Create SPL interface PDA +//! 5. Transfer from SPL ATA to Light account (offchain conversion using `transfer_spl_to_light`) +//! 6. Contributor has Light account with tokens - contribute using Light-to-Light + +mod common; +use common::{create_test_rpc, run_fundraiser_full_flow, setup_fundraiser_test, TokenConfig}; + +#[tokio::test] +async fn test_fundraiser_full_flow_light_spl() { + let mut rpc = create_test_rpc().await; + let ctx = setup_fundraiser_test(&mut rpc, TokenConfig::LightSpl).await; + run_fundraiser_full_flow(&mut rpc, &ctx).await; +} diff --git a/programs/anchor/fundraiser/tests/user_t22.rs b/programs/anchor/fundraiser/tests/user_t22.rs new file mode 100644 index 0000000..540680a --- /dev/null +++ b/programs/anchor/fundraiser/tests/user_t22.rs @@ -0,0 +1,46 @@ +//! Integration tests for the fundraiser program with Token-2022 mints and T22 ATAs. +//! +//! Token Configuration: +//! - Mint Type: Token-2022 (spl_token_2022::ID) +//! - User Accounts: Token-2022 ATAs (contributors) +//! - Vault Account: Light Protocol token account + +mod common; + +use common::{create_test_rpc, run_fundraiser_full_flow, setup_fundraiser_test, TokenConfig}; + +/// Test the full fundraiser flow with Token-2022 tokens +#[tokio::test] +async fn test_fundraiser_full_flow_t22() { + let mut rpc = create_test_rpc().await; + let ctx = setup_fundraiser_test(&mut rpc, TokenConfig::Token2022).await; + run_fundraiser_full_flow(&mut rpc, &ctx).await; +} + +/// Test fundraiser initialization with Token-2022 tokens +#[tokio::test] +async fn test_initialize_fundraiser_t22() { + use common::{initialize_fundraiser, setup_fundraiser_test}; + use light_client::interface::{get_create_accounts_proof, CreateAccountsProofInput}; + use shared_test_utils::helpers::verify_light_token_balance; + + let mut rpc = create_test_rpc().await; + let ctx = setup_fundraiser_test(&mut rpc, TokenConfig::Token2022).await; + + // Get proof for creating vault + let proof_result = get_create_accounts_proof( + &rpc, + &ctx.program_id, + vec![CreateAccountsProofInput::pda(ctx.vault_pda)], + ) + .await + .unwrap(); + + // Initialize fundraiser + initialize_fundraiser(&mut rpc, &ctx, proof_result).await; + + // Verify vault was created + verify_light_token_balance(&mut rpc, ctx.vault_pda, 0, "vault").await; + + println!("=== Initialize fundraiser test completed successfully! ==="); +} diff --git a/programs/anchor/fundraiser/tests/user_t22_light.rs b/programs/anchor/fundraiser/tests/user_t22_light.rs new file mode 100644 index 0000000..03e378a --- /dev/null +++ b/programs/anchor/fundraiser/tests/user_t22_light.rs @@ -0,0 +1,24 @@ +//! Integration tests for the fundraiser program with T22 mints and Light user accounts. +//! +//! Token Configuration: +//! - Mint Type: Token-2022 (spl_token_2022::ID) +//! - User Accounts: Light token accounts (contributors with offchain T22->Light conversion) +//! - Vault Account: Light Protocol token account +//! +//! ## Test Flow: +//! 1. Create T22 mint and temporary T22 ATA +//! 2. Mint tokens to temporary ATA +//! 3. Create Light token account for contributor +//! 4. Create SPL interface PDA +//! 5. Transfer from T22 ATA to Light account (offchain conversion using `transfer_spl_to_light`) +//! 6. Contributor has Light account with tokens - contribute using Light-to-Light + +mod common; +use common::{create_test_rpc, run_fundraiser_full_flow, setup_fundraiser_test, TokenConfig}; + +#[tokio::test] +async fn test_fundraiser_full_flow_light_t22() { + let mut rpc = create_test_rpc().await; + let ctx = setup_fundraiser_test(&mut rpc, TokenConfig::LightT22).await; + run_fundraiser_full_flow(&mut rpc, &ctx).await; +} diff --git a/programs/anchor/light-token-minter/Cargo.toml b/programs/anchor/light-token-minter/Cargo.toml new file mode 100644 index 0000000..5cf38db --- /dev/null +++ b/programs/anchor/light-token-minter/Cargo.toml @@ -0,0 +1,52 @@ +[package] +name = "light-token-minter" +version = "0.1.0" +edition = "2021" + +[lib] +crate-type = ["cdylib", "lib"] +name = "light_token_minter" + +[features] +no-entrypoint = [] +no-log-ix-name = [] +no-idl = [] +cpi = ["no-entrypoint"] +default = [] +idl-build = ["anchor-lang/idl-build", "light-sdk/idl-build", "light-token/idl-build", "light-anchor-spl/idl-build"] +test-sbf = [] + +[dependencies] +anchor-lang = { version = "=0.31.1", features = ["init-if-needed", "idl-build"] } +# Pin blake3 version for solana-program compatibility +blake3 = { workspace = true } + +light-sdk = { workspace = true, features = ["anchor", "anchor-discriminator", "idl-build", "cpi-context", "v2"] } +light-token = { workspace = true, features = ["anchor", "idl-build"] } +# Required by LightAccount derive macro +light-hasher = { workspace = true, features = ["solana"] } +light-anchor-spl = { workspace = true, features = ["idl-build"] } +solana-program = { workspace = true } +solana-pubkey = { workspace = true } +solana-account-info = { workspace = true } +solana-program-error = { workspace = true } +solana-msg = { workspace = true } + +[dev-dependencies] +light-program-test = { workspace = true } +light-client = { workspace = true, features = ["v2", "anchor"] } +tokio = { workspace = true, features = ["full"] } +spl-token = { workspace = true } +solana-keypair = { workspace = true } +solana-signer = { workspace = true } +solana-instruction = { workspace = true } +solana-sdk = { workspace = true } +spl-token-2022 = { workspace = true } +spl-pod = { workspace = true } + +[lints.rust.unexpected_cfgs] +level = "allow" +check-cfg = [ + 'cfg(target_os, values("solana"))', + 'cfg(feature, values("frozen-abi", "no-entrypoint"))', +] diff --git a/programs/anchor/light-token-minter/src/instructions/create.rs b/programs/anchor/light-token-minter/src/instructions/create.rs new file mode 100644 index 0000000..ac131a1 --- /dev/null +++ b/programs/anchor/light-token-minter/src/instructions/create.rs @@ -0,0 +1,79 @@ +use anchor_lang::prelude::*; +use light_sdk::interface::CreateAccountsProof; +use light_token::anchor::LightAccounts; +use light_token::instruction::{COMPRESSIBLE_CONFIG_V1, RENT_SPONSOR}; + +use crate::MINT_SIGNER_SEED; + +#[derive(AnchorSerialize, AnchorDeserialize, Clone)] +pub struct CreateMintParams { + pub create_accounts_proof: CreateAccountsProof, + pub decimals: u8, + pub mint_signer_bump: u8, + pub token_name: String, + pub token_symbol: String, + pub token_uri: String, +} + +#[derive(Accounts, LightAccounts)] +#[instruction(params: CreateMintParams)] +pub struct CreateMint<'info> { + #[account(mut)] + pub fee_payer: Signer<'info>, + + pub authority: Signer<'info>, + + /// CHECK: PDA derived from authority, used as mint signer seed. + #[account( + seeds = [MINT_SIGNER_SEED, authority.key().as_ref()], + bump, + )] + pub mint_signer: UncheckedAccount<'info>, + + /// CHECK: Initialized by light_account macro. + #[account(mut)] + #[light_account(init, + mint::signer = mint_signer, + mint::authority = authority, + mint::decimals = params.decimals, + mint::seeds = &[MINT_SIGNER_SEED, self.authority.to_account_info().key.as_ref()], + mint::bump = params.mint_signer_bump, + mint::name = params.token_name.clone().into_bytes(), + mint::symbol = params.token_symbol.clone().into_bytes(), + mint::uri = params.token_uri.clone().into_bytes(), + mint::update_authority = authority + )] + pub light_mint: UncheckedAccount<'info>, + + /// CHECK: Config for light mint creation. + pub compression_config: AccountInfo<'info>, + + /// CHECK: Light token compressible config. + #[account(address = COMPRESSIBLE_CONFIG_V1)] + pub light_token_compressible_config: AccountInfo<'info>, + + /// CHECK: Light token rent sponsor. + #[account(mut, address = RENT_SPONSOR)] + pub rent_sponsor: AccountInfo<'info>, + + /// CHECK: Light token program. + pub light_token_program: AccountInfo<'info>, + + /// CHECK: Light token CPI authority. + pub light_token_cpi_authority: AccountInfo<'info>, + + pub system_program: Program<'info, System>, +} + +pub fn create_token<'info>( + ctx: &Context<'_, '_, '_, 'info, CreateMint<'info>>, + params: &CreateMintParams, +) -> Result<()> { + msg!("Light mint created with metadata"); + msg!("Name: {}", params.token_name); + msg!("Symbol: {}", params.token_symbol); + msg!("URI: {}", params.token_uri); + msg!("Mint signer: {}", ctx.accounts.mint_signer.key()); + msg!("Mint authority: {}", ctx.accounts.authority.key()); + Ok(()) +} diff --git a/programs/anchor/light-token-minter/src/instructions/mint.rs b/programs/anchor/light-token-minter/src/instructions/mint.rs new file mode 100644 index 0000000..690cf5f --- /dev/null +++ b/programs/anchor/light-token-minter/src/instructions/mint.rs @@ -0,0 +1,78 @@ +use anchor_lang::prelude::*; +use light_sdk::interface::CreateAccountsProof; +use light_token::anchor::LightAccounts; +use light_token::instruction::{MintToCpi, COMPRESSIBLE_CONFIG_V1, RENT_SPONSOR}; + +#[derive(AnchorSerialize, AnchorDeserialize, Clone)] +pub struct MintTokenParams { + pub amount: u64, + pub create_accounts_proof: CreateAccountsProof, + pub ata_bump: u8, +} + +#[derive(Accounts, LightAccounts)] +#[instruction(params: MintTokenParams)] +pub struct MintTo<'info> { + #[account(mut)] + pub fee_payer: Signer<'info>, + + /// Must be writable because light-token MintTo marks authority as writable in CPI. + #[account(mut)] + pub mint_authority: Signer<'info>, + + /// CHECK: Light mint account. + #[account(mut)] + pub mint: AccountInfo<'info>, + + /// CHECK: Recipient and owner of the destination token account. + pub recipient: AccountInfo<'info>, + + /// CHECK: Destination ATA, created by light_account macro if needed. + #[account(mut)] + #[light_account(init, + associated_token::authority = recipient, + associated_token::mint = mint, + associated_token::bump = params.ata_bump + )] + pub destination: UncheckedAccount<'info>, + + /// CHECK: Light token program. + pub light_token_program: AccountInfo<'info>, + + pub system_program: Program<'info, System>, + + /// CHECK: Light token compressible config. + #[account(address = COMPRESSIBLE_CONFIG_V1)] + pub light_token_compressible_config: AccountInfo<'info>, + + /// CHECK: Light token rent sponsor. + #[account(mut, address = RENT_SPONSOR)] + pub light_token_rent_sponsor: AccountInfo<'info>, + + /// CHECK: Light token CPI authority. + pub light_token_cpi_authority: AccountInfo<'info>, +} + +pub fn mint_token<'info>( + ctx: &Context<'_, '_, '_, 'info, MintTo<'info>>, + params: &MintTokenParams, +) -> Result<()> { + MintToCpi { + mint: ctx.accounts.mint.to_account_info(), + destination: ctx.accounts.destination.to_account_info(), + amount: params.amount, + authority: ctx.accounts.mint_authority.to_account_info(), + system_program: ctx.accounts.system_program.to_account_info(), + max_top_up: None, + fee_payer: Some(ctx.accounts.fee_payer.to_account_info()), + } + .invoke()?; + + msg!( + "Minted {} tokens to {} (owner: {})", + params.amount, + ctx.accounts.destination.key(), + ctx.accounts.recipient.key() + ); + Ok(()) +} diff --git a/programs/anchor/light-token-minter/src/instructions/mod.rs b/programs/anchor/light-token-minter/src/instructions/mod.rs new file mode 100644 index 0000000..b5fc428 --- /dev/null +++ b/programs/anchor/light-token-minter/src/instructions/mod.rs @@ -0,0 +1,5 @@ +pub mod create; +pub mod mint; + +pub use create::*; +pub use mint::*; diff --git a/programs/anchor/light-token-minter/src/lib.rs b/programs/anchor/light-token-minter/src/lib.rs new file mode 100644 index 0000000..590f2dd --- /dev/null +++ b/programs/anchor/light-token-minter/src/lib.rs @@ -0,0 +1,35 @@ +pub mod instructions; + +use anchor_lang::prelude::*; +use light_token::anchor::{derive_light_cpi_signer, light_program, CpiSigner}; + +pub use instructions::*; + +declare_id!("3EPJBoxM8Evtv3Wk7R2mSWsrSzUD7WSKAaYugLgpCitV"); + +pub const LIGHT_CPI_SIGNER: CpiSigner = + derive_light_cpi_signer!("3EPJBoxM8Evtv3Wk7R2mSWsrSzUD7WSKAaYugLgpCitV"); + +pub const MINT_SIGNER_SEED: &[u8] = b"mint_signer"; + +#[light_program] +// Anchor's #[program] macro uses deprecated AccountInfo::realloc internally +#[allow(deprecated)] +#[program] +pub mod light_token_minter { + use super::*; + + pub fn create_mint<'info>( + ctx: Context<'_, '_, '_, 'info, CreateMint<'info>>, + params: CreateMintParams, + ) -> Result<()> { + instructions::create::create_token(&ctx, ¶ms) + } + + pub fn mint_to<'info>( + ctx: Context<'_, '_, '_, 'info, MintTo<'info>>, + params: MintTokenParams, + ) -> Result<()> { + instructions::mint::mint_token(&ctx, ¶ms) + } +} diff --git a/programs/anchor/light-token-minter/tests/minter_test.rs b/programs/anchor/light-token-minter/tests/minter_test.rs new file mode 100644 index 0000000..330e59c --- /dev/null +++ b/programs/anchor/light-token-minter/tests/minter_test.rs @@ -0,0 +1,386 @@ +//! Integration tests for Light mint creation using #[light_account(init, mint)] macro. + +use anchor_lang::{InstructionData, ToAccountMetas}; +use light_client::interface::{ + get_create_accounts_proof, CreateAccountsProofInput, InitializeRentFreeConfig, +}; +use light_program_test::{ + program_test::{setup_mock_program_data, LightProgramTest}, + ProgramTestConfig, Rpc, +}; +use light_sdk::constants::LIGHT_TOKEN_PROGRAM_ID; +use light_token::instruction::{ + derive_token_ata, find_mint_address, COMPRESSIBLE_CONFIG_V1, RENT_SPONSOR, +}; +use solana_instruction::Instruction; +use solana_keypair::Keypair; +use solana_pubkey::Pubkey; +use solana_signer::Signer; + +/// Test creating a Light mint using the #[light_account(init, mint)] macro. +#[tokio::test] +async fn test_create_light_mint() { + let program_id = light_token_minter::ID; + let mut config = + ProgramTestConfig::new_v2(true, Some(vec![("light_token_minter", program_id)])); + config = config.with_light_protocol_events(); + + let mut rpc = LightProgramTest::new(config).await.unwrap(); + let payer = rpc.get_payer().insecure_clone(); + + // Setup program data for rent-free config + let program_data_pda = setup_mock_program_data(&mut rpc, &payer, &program_id); + + // Initialize rent-free config + let (init_config_ix, config_pda) = InitializeRentFreeConfig::new( + &program_id, + &payer.pubkey(), + &program_data_pda, + RENT_SPONSOR, + payer.pubkey(), + ) + .build(); + + rpc.create_and_send_transaction(&[init_config_ix], &payer.pubkey(), &[&payer]) + .await + .expect("Initialize config should succeed"); + + // Authority keypair (mint authority) + let authority = Keypair::new(); + + // Derive mint signer PDA + let (mint_signer_pda, mint_signer_bump) = Pubkey::find_program_address( + &[ + light_token_minter::MINT_SIGNER_SEED, + authority.pubkey().as_ref(), + ], + &program_id, + ); + + // Derive mint PDA from mint signer + let (light_mint_pda, _) = find_mint_address(&mint_signer_pda); + + // Get proof for the mint + let proof_result = get_create_accounts_proof( + &rpc, + &program_id, + vec![CreateAccountsProofInput::mint(mint_signer_pda)], + ) + .await + .unwrap(); + + println!("Light Mint test setup completed"); + println!("Program ID: {:?}", program_id); + println!( + "Mint Signer PDA: {:?} (bump: {})", + mint_signer_pda, mint_signer_bump + ); + println!("Light Mint PDA: {:?}", light_mint_pda); + + // Build create_mint instruction + let accounts = light_token_minter::accounts::CreateMint { + fee_payer: payer.pubkey(), + authority: authority.pubkey(), + mint_signer: mint_signer_pda, + light_mint: light_mint_pda, + compression_config: config_pda, + light_token_compressible_config: COMPRESSIBLE_CONFIG_V1, + rent_sponsor: RENT_SPONSOR, + light_token_program: LIGHT_TOKEN_PROGRAM_ID.into(), + light_token_cpi_authority: light_token::constants::CPI_AUTHORITY_PDA.into(), + system_program: solana_sdk::system_program::ID, + }; + + let instruction_data = light_token_minter::instruction::CreateMint { + params: light_token_minter::CreateMintParams { + create_accounts_proof: proof_result.create_accounts_proof, + decimals: 9, + mint_signer_bump, + token_name: "Test Token".to_string(), + token_symbol: "TEST".to_string(), + token_uri: "https://example.com/metadata.json".to_string(), + }, + }; + + let instruction = Instruction { + program_id, + accounts: [ + accounts.to_account_metas(None), + proof_result.remaining_accounts, + ] + .concat(), + data: instruction_data.data(), + }; + + rpc.create_and_send_transaction(&[instruction], &payer.pubkey(), &[&payer, &authority]) + .await + .expect("CreateMint should succeed"); + + // Verify mint exists on-chain + let light_mint_account = rpc + .get_account(light_mint_pda) + .await + .unwrap() + .expect("Mint should exist on-chain"); + + // Verify the account has data (mint was created successfully) + assert!( + !light_mint_account.data.is_empty(), + "Mint account should have data" + ); + + // The account should have significant size for a Light mint + assert!( + light_mint_account.data.len() > 50, + "Mint account should have sufficient data for a Light mint" + ); + + println!("Light Mint created and verified successfully!"); + println!("Mint account size: {} bytes", light_mint_account.data.len()); + println!("Mint PDA: {}", light_mint_pda); +} + +/// Test basic mint signer PDA derivation without creating the mint. +#[tokio::test] +async fn test_mint_signer_derivation() { + let program_id = light_token_minter::ID; + let mut config = + ProgramTestConfig::new_v2(true, Some(vec![("light_token_minter", program_id)])); + config = config.with_light_protocol_events(); + + let rpc = LightProgramTest::new(config).await.unwrap(); + let payer = rpc.get_payer().insecure_clone(); + + // Derive mint signer PDA + let (mint_signer_pda, bump) = Pubkey::find_program_address( + &[ + light_token_minter::MINT_SIGNER_SEED, + payer.pubkey().as_ref(), + ], + &program_id, + ); + + // Derive mint PDA from mint signer + let (mint_pda, _) = find_mint_address(&mint_signer_pda); + + println!("Light Token Minter test setup completed"); + println!("Program ID: {:?}", program_id); + println!("Mint Signer PDA: {:?} (bump: {})", mint_signer_pda, bump); + println!("Light Mint PDA: {:?}", mint_pda); + println!("Payer: {:?}", payer.pubkey()); + + // Verify the PDA derivations are deterministic + let (verify_signer, verify_bump) = Pubkey::find_program_address( + &[ + light_token_minter::MINT_SIGNER_SEED, + payer.pubkey().as_ref(), + ], + &program_id, + ); + assert_eq!(mint_signer_pda, verify_signer); + assert_eq!(bump, verify_bump); +} + +/// Test the full flow: create Light mint, create token account, mint tokens. +#[tokio::test] +async fn test_mint_to() { + let program_id = light_token_minter::ID; + let mut config = + ProgramTestConfig::new_v2(true, Some(vec![("light_token_minter", program_id)])); + config = config.with_light_protocol_events(); + + let mut rpc = LightProgramTest::new(config).await.unwrap(); + let payer = rpc.get_payer().insecure_clone(); + + // Setup program data for rent-free config + let program_data_pda = setup_mock_program_data(&mut rpc, &payer, &program_id); + + // Initialize rent-free config + let (init_config_ix, config_pda) = InitializeRentFreeConfig::new( + &program_id, + &payer.pubkey(), + &program_data_pda, + RENT_SPONSOR, + payer.pubkey(), + ) + .build(); + + rpc.create_and_send_transaction(&[init_config_ix], &payer.pubkey(), &[&payer]) + .await + .expect("Initialize config should succeed"); + + println!("Rent-free config initialized at: {:?}", config_pda); + + // Authority keypair (mint authority) + let authority = Keypair::new(); + rpc.airdrop_lamports(&authority.pubkey(), 1_000_000_000) + .await + .unwrap(); + + // Derive mint signer PDA + let (mint_signer_pda, mint_signer_bump) = Pubkey::find_program_address( + &[ + light_token_minter::MINT_SIGNER_SEED, + authority.pubkey().as_ref(), + ], + &program_id, + ); + + // Derive mint PDA from mint signer + let (light_mint_pda, _) = find_mint_address(&mint_signer_pda); + + println!("Mint Signer PDA: {:?}", mint_signer_pda); + println!("Light Mint PDA: {:?}", light_mint_pda); + + // Get proof for the mint + let proof_result = get_create_accounts_proof( + &rpc, + &program_id, + vec![CreateAccountsProofInput::mint(mint_signer_pda)], + ) + .await + .unwrap(); + + // Build create_mint instruction + let create_mint_accounts = light_token_minter::accounts::CreateMint { + fee_payer: payer.pubkey(), + authority: authority.pubkey(), + mint_signer: mint_signer_pda, + light_mint: light_mint_pda, + compression_config: config_pda, + light_token_compressible_config: COMPRESSIBLE_CONFIG_V1, + rent_sponsor: RENT_SPONSOR, + light_token_program: LIGHT_TOKEN_PROGRAM_ID.into(), + light_token_cpi_authority: light_token::constants::CPI_AUTHORITY_PDA.into(), + system_program: solana_sdk::system_program::ID, + }; + + let create_mint_data = light_token_minter::instruction::CreateMint { + params: light_token_minter::CreateMintParams { + create_accounts_proof: proof_result.create_accounts_proof, + decimals: 9, + mint_signer_bump, + token_name: "Test Token".to_string(), + token_symbol: "TEST".to_string(), + token_uri: "https://example.com/metadata.json".to_string(), + }, + }; + + let create_mint_ix = Instruction { + program_id, + accounts: [ + create_mint_accounts.to_account_metas(None), + proof_result.remaining_accounts, + ] + .concat(), + data: create_mint_data.data(), + }; + + rpc.create_and_send_transaction(&[create_mint_ix], &payer.pubkey(), &[&payer, &authority]) + .await + .expect("CreateMint should succeed"); + + println!("Light mint created successfully!"); + + // Verify mint exists on-chain + let light_mint_account = rpc + .get_account(light_mint_pda) + .await + .unwrap() + .expect("Mint should exist on-chain"); + assert!( + !light_mint_account.data.is_empty(), + "Mint account should have data" + ); + println!("Mint verified, size: {} bytes", light_mint_account.data.len()); + + // Create a recipient + let recipient = Keypair::new(); + rpc.airdrop_lamports(&recipient.pubkey(), 1_000_000_000) + .await + .unwrap(); + + // Derive the ATA address (will be created by mint_to via the #[light_account(init, associated_token)] macro) + let (recipient_ata, ata_bump) = derive_token_ata(&recipient.pubkey(), &light_mint_pda); + println!( + "Recipient ATA (to be created by mint_to): {:?}", + recipient_ata + ); + + // Get proof for creating the ATA + let mint_to_proof_result = get_create_accounts_proof( + &rpc, + &program_id, + vec![], // ATA creation via macro doesn't need special proof input + ) + .await + .unwrap(); + + // Mint tokens using the mint_to instruction (which creates the ATA via macro) + let mint_amount = 1_000_000_000u64; // 1 token with 9 decimals + + let mint_to_accounts = light_token_minter::accounts::MintTo { + fee_payer: payer.pubkey(), + mint_authority: authority.pubkey(), + mint: light_mint_pda, + recipient: recipient.pubkey(), + destination: recipient_ata, + light_token_program: LIGHT_TOKEN_PROGRAM_ID.into(), + system_program: solana_sdk::system_program::ID, + light_token_compressible_config: COMPRESSIBLE_CONFIG_V1, + light_token_rent_sponsor: RENT_SPONSOR, + light_token_cpi_authority: light_token::constants::CPI_AUTHORITY_PDA.into(), + }; + + let mint_to_data = light_token_minter::instruction::MintTo { + params: light_token_minter::MintTokenParams { + amount: mint_amount, + create_accounts_proof: mint_to_proof_result.create_accounts_proof, + ata_bump, + }, + }; + + let mint_to_ix = Instruction { + program_id, + accounts: [ + mint_to_accounts.to_account_metas(None), + mint_to_proof_result.remaining_accounts, + ] + .concat(), + data: mint_to_data.data(), + }; + + rpc.create_and_send_transaction(&[mint_to_ix], &payer.pubkey(), &[&payer, &authority]) + .await + .expect("MintTo should succeed"); + + println!("Minted {} tokens to recipient", mint_amount); + + // Verify token balance + let ata_account_after = rpc + .get_account(recipient_ata) + .await + .unwrap() + .expect("ATA should still exist"); + + // Light Token accounts have SPL-compatible data in first 165 bytes + use spl_token_2022::pod::PodAccount; + if ata_account_after.data.len() >= 165 { + let token_state = + spl_pod::bytemuck::pod_from_bytes::(&ata_account_after.data[..165]) + .unwrap(); + let balance = u64::from(token_state.amount); + println!("Final balance: {} (expected {})", balance, mint_amount); + assert_eq!( + balance, mint_amount, + "Token balance should match minted amount" + ); + } else { + panic!( + "ATA data too short: {} bytes (expected >= 165)", + ata_account_after.data.len() + ); + } + + println!("\n=== mint_to test completed successfully! ==="); +} diff --git a/programs/anchor/rust-toolchain.toml b/programs/anchor/rust-toolchain.toml new file mode 100644 index 0000000..43e5784 --- /dev/null +++ b/programs/anchor/rust-toolchain.toml @@ -0,0 +1,3 @@ +[toolchain] +channel = "1.90.0" +components = ["rustfmt", "clippy"] diff --git a/programs/anchor/shared-test-utils/Cargo.toml b/programs/anchor/shared-test-utils/Cargo.toml new file mode 100644 index 0000000..d98917f --- /dev/null +++ b/programs/anchor/shared-test-utils/Cargo.toml @@ -0,0 +1,44 @@ +[package] +name = "shared-test-utils" +version = "0.1.0" +description = "Shared test utilities for Light Protocol example programs" +edition = "2021" + +[lib] +name = "shared_test_utils" + +[dependencies] +# Light Protocol dependencies (from workspace) +light-program-test.workspace = true +light-client = { workspace = true, features = ["v2", "anchor"] } +light-sdk.workspace = true +light-token = { workspace = true, features = ["anchor"] } +light-hasher = { workspace = true, features = ["solana"] } + +# Example program dependencies (for calling Light mint creation instructions) +light-token-minter = { path = "../light-token-minter", features = ["no-entrypoint"] } + +# Anchor dependencies +anchor-lang = { workspace = true } +anchor-spl = { workspace = true } + +# Solana dependencies +solana-keypair = { workspace = true } +solana-signer = { workspace = true } +solana-instruction = { workspace = true } +solana-sdk = { workspace = true } +solana-pubkey = { workspace = true } + +# SPL Token dependencies +spl-token-2022 = { workspace = true } +spl-pod = { workspace = true } + +# Async +tokio = { workspace = true, features = ["full"] } + +[lints.rust.unexpected_cfgs] +level = "allow" +check-cfg = [ + 'cfg(target_os, values("solana"))', + 'cfg(feature, values("frozen-abi", "no-entrypoint"))', +] diff --git a/programs/anchor/shared-test-utils/src/lib.rs b/programs/anchor/shared-test-utils/src/lib.rs new file mode 100644 index 0000000..ab40b73 --- /dev/null +++ b/programs/anchor/shared-test-utils/src/lib.rs @@ -0,0 +1,815 @@ +//! Shared test utilities for Light Protocol example programs. +//! +//! This crate provides helper functions for creating and managing: +//! - SPL mints and token accounts +//! - Token-2022 mints and token accounts +//! - Light Protocol token accounts +//! - SPL interface PDAs for SPL<->Light transfers +//! - Balance verification utilities + +use anchor_spl::token; +use light_token::spl_interface::{find_spl_interface_pda, CreateSplInterfacePda}; +use solana_keypair::Keypair; +use solana_pubkey::Pubkey; +use solana_signer::Signer; +use spl_token_2022::pod::PodAccount; + +// Re-exports for convenience +pub use light_client::interface::{ + get_create_accounts_proof, CreateAccountsProofInput, CreateAccountsProofResult, + InitializeRentFreeConfig, +}; +pub use light_program_test::{ + program_test::{setup_mock_program_data, LightProgramTest, TestRpc}, + Indexer, ProgramTestConfig, Rpc, +}; +pub use light_sdk::constants::LIGHT_TOKEN_PROGRAM_ID; +pub use light_token::constants::CPI_AUTHORITY_PDA; +pub use light_token::instruction::{COMPRESSIBLE_CONFIG_V1, RENT_SPONSOR}; + +// Re-export light-token-minter program ID for tests that need to create Light mints +pub use light_token_minter::ID as LIGHT_TOKEN_MINTER_PROGRAM_ID; + +/// Token type for mint creation +#[derive(Clone, Copy, Debug, PartialEq, Eq)] +pub enum MintType { + /// Standard SPL Token (token::ID) + Spl, + /// Token-2022 (spl_token_2022::ID) + Token2022, +} + +impl MintType { + pub fn program_id(&self) -> Pubkey { + match self { + MintType::Spl => token::ID, + MintType::Token2022 => spl_token_2022::ID, + } + } +} + +/// Result of creating an SPL interface PDA +pub struct SplInterfaceResult { + pub pda: Pubkey, + pub bump: u8, +} + +// ============================================================================ +// Setup Module +// ============================================================================ + +pub mod setup { + use super::*; + + /// Initialize rent-free config for a program + pub async fn initialize_rent_free_config( + rpc: &mut R, + payer: &Keypair, + program_id: &Pubkey, + ) -> Pubkey { + // Setup program data for rent-free config + let program_data_pda = setup_mock_program_data(rpc, payer, program_id); + + // Initialize rent-free config + let (init_config_ix, config_pda) = InitializeRentFreeConfig::new( + program_id, + &payer.pubkey(), + &program_data_pda, + RENT_SPONSOR, + payer.pubkey(), + ) + .build(); + + rpc.create_and_send_transaction(&[init_config_ix], &payer.pubkey(), &[payer]) + .await + .expect("Initialize rent-free config should succeed"); + + println!("Rent-free config initialized at: {:?}", config_pda); + config_pda + } + + /// Create a new LightProgramTest instance with the given program + pub async fn create_program_test( + program_name: &'static str, + program_id: Pubkey, + ) -> (LightProgramTest, Keypair) { + let mut config = ProgramTestConfig::new_v2(true, Some(vec![(program_name, program_id)])); + config = config.with_light_protocol_events(); + + let rpc = LightProgramTest::new(config).await.unwrap(); + let payer = rpc.get_payer().insecure_clone(); + (rpc, payer) + } +} + +// ============================================================================ +// SPL Tokens Module +// ============================================================================ + +pub mod spl_tokens { + use super::*; + + /// Create an SPL mint with the given decimals + pub async fn create_spl_mint( + rpc: &mut R, + payer: &Keypair, + mint_authority: &Pubkey, + decimals: u8, + ) -> Keypair { + create_mint_internal(rpc, payer, mint_authority, decimals, MintType::Spl).await + } + + /// Create an SPL ATA for the given owner and mint + pub async fn create_spl_ata( + rpc: &mut R, + payer: &Keypair, + mint: &Pubkey, + owner: &Pubkey, + ) -> Pubkey { + create_ata_internal(rpc, payer, mint, owner, MintType::Spl).await + } + + /// Mint SPL tokens to an account + pub async fn mint_spl_tokens( + rpc: &mut R, + payer: &Keypair, + mint: &Pubkey, + destination: &Pubkey, + mint_authority: &Keypair, + amount: u64, + ) { + mint_tokens_internal( + rpc, + payer, + mint, + destination, + mint_authority, + amount, + MintType::Spl, + ) + .await + } +} + +// ============================================================================ +// Token-2022 Module +// ============================================================================ + +pub mod t22_tokens { + use super::*; + + /// Create a Token-2022 mint with the given decimals (no extensions) + pub async fn create_t22_mint( + rpc: &mut R, + payer: &Keypair, + mint_authority: &Pubkey, + decimals: u8, + ) -> Keypair { + create_mint_internal(rpc, payer, mint_authority, decimals, MintType::Token2022).await + } + + /// Create a Token-2022 ATA for the given owner and mint + pub async fn create_t22_ata( + rpc: &mut R, + payer: &Keypair, + mint: &Pubkey, + owner: &Pubkey, + ) -> Pubkey { + create_ata_internal(rpc, payer, mint, owner, MintType::Token2022).await + } + + /// Mint Token-2022 tokens to an account + pub async fn mint_t22_tokens( + rpc: &mut R, + payer: &Keypair, + mint: &Pubkey, + destination: &Pubkey, + mint_authority: &Keypair, + amount: u64, + ) { + mint_tokens_internal( + rpc, + payer, + mint, + destination, + mint_authority, + amount, + MintType::Token2022, + ) + .await + } +} + +// ============================================================================ +// Light Tokens Module +// ============================================================================ + +pub mod light_tokens { + use super::*; + use anchor_lang::{InstructionData, ToAccountMetas}; + use light_token::instruction::{ + derive_token_ata, find_mint_address, CompressibleParams, CreateAssociatedTokenAccount, + TokenDataVersion, + }; + use solana_instruction::Instruction; + + /// Result of creating a Light mint + pub struct LightMintResult { + /// The mint PDA + pub mint: Pubkey, + /// The mint signer PDA (derived from authority) + pub mint_signer: Pubkey, + /// The bump for the mint signer PDA + pub mint_signer_bump: u8, + /// The authority keypair (used as mint authority) + pub authority: Keypair, + } + + /// Create a Light mint using the light-token-minter program. + /// + /// This creates a new light mint with metadata. + /// Returns information about the created mint including the mint PDA, + /// mint signer PDA, and authority keypair. + /// + /// # Arguments + /// * `rpc` - RPC client (must implement Rpc + Indexer) + /// * `payer` - Transaction fee payer + /// * `decimals` - Token decimals + /// * `token_name` - Token name for metadata + /// * `token_symbol` - Token symbol for metadata + /// * `compression_config` - The config PDA (from initialize_rent_free_config) + /// + /// # Returns + /// * `LightMintResult` - Contains mint PDA, mint_signer PDA, bump, and authority keypair + pub async fn create_light_mint( + rpc: &mut R, + payer: &Keypair, + decimals: u8, + token_name: &str, + token_symbol: &str, + compression_config: &Pubkey, + ) -> LightMintResult { + let program_id = light_token_minter::ID; + + // Create a new authority keypair for this mint + let authority = Keypair::new(); + + // Derive mint signer PDA from authority + let (mint_signer_pda, mint_signer_bump) = Pubkey::find_program_address( + &[ + light_token_minter::MINT_SIGNER_SEED, + authority.pubkey().as_ref(), + ], + &program_id, + ); + + // Derive mint PDA from mint signer + let (mint_pda, _) = find_mint_address(&mint_signer_pda); + + // Get proof for creating the mint + let proof_result = get_create_accounts_proof( + rpc, + &program_id, + vec![CreateAccountsProofInput::mint(mint_signer_pda)], + ) + .await + .expect("Get create accounts proof should succeed"); + + // Build create_mint instruction + let accounts = light_token_minter::accounts::CreateMint { + fee_payer: payer.pubkey(), + authority: authority.pubkey(), + mint_signer: mint_signer_pda, + light_mint: mint_pda, + compression_config: *compression_config, + light_token_compressible_config: COMPRESSIBLE_CONFIG_V1, + rent_sponsor: RENT_SPONSOR, + light_token_program: Pubkey::new_from_array(LIGHT_TOKEN_PROGRAM_ID), + light_token_cpi_authority: CPI_AUTHORITY_PDA, + system_program: solana_sdk::system_program::ID, + }; + + let instruction_data = light_token_minter::instruction::CreateMint { + params: light_token_minter::CreateMintParams { + create_accounts_proof: proof_result.create_accounts_proof, + decimals, + mint_signer_bump, + token_name: token_name.to_string(), + token_symbol: token_symbol.to_string(), + token_uri: format!("https://example.com/{}.json", token_symbol.to_lowercase()), + }, + }; + + let instruction = Instruction { + program_id, + accounts: [ + accounts.to_account_metas(None), + proof_result.remaining_accounts, + ] + .concat(), + data: instruction_data.data(), + }; + + rpc.create_and_send_transaction(&[instruction], &payer.pubkey(), &[payer, &authority]) + .await + .expect("Create Light mint should succeed"); + + println!("Light mint created: {:?}", mint_pda); + println!(" Mint signer: {:?}", mint_signer_pda); + println!(" Authority: {:?}", authority.pubkey()); + println!(" Decimals: {}", decimals); + + LightMintResult { + mint: mint_pda, + mint_signer: mint_signer_pda, + mint_signer_bump, + authority, + } + } + + /// Mint Light tokens to a Light ATA, creating the ATA if needed. + /// + /// This mints tokens from a Light mint to a destination owner's Light ATA. + /// The ATA is created automatically if it doesn't exist. + /// + /// # Arguments + /// * `rpc` - RPC client (must implement Rpc + Indexer) + /// * `payer` - Transaction fee payer + /// * `mint_authority` - Keypair that is the mint authority + /// * `mint` - The Light mint PDA + /// * `destination_owner` - Owner of the destination ATA + /// * `amount` - Amount of tokens to mint + /// + /// # Returns + /// * `Pubkey` - The destination ATA address + pub async fn mint_light_tokens( + rpc: &mut R, + payer: &Keypair, + mint_authority: &Keypair, + mint: &Pubkey, + destination_owner: &Pubkey, + amount: u64, + ) -> Pubkey { + let program_id = light_token_minter::ID; + + // Derive the ATA address + let (destination_ata, ata_bump) = derive_token_ata(destination_owner, mint); + + // Get proof for creating the ATA (empty vec - ATA creation via macro) + let proof_result = get_create_accounts_proof(rpc, &program_id, vec![]) + .await + .expect("Get create accounts proof should succeed"); + + // Build mint_to instruction + let accounts = light_token_minter::accounts::MintTo { + fee_payer: payer.pubkey(), + mint_authority: mint_authority.pubkey(), + mint: *mint, + recipient: *destination_owner, + destination: destination_ata, + light_token_program: Pubkey::new_from_array(LIGHT_TOKEN_PROGRAM_ID), + system_program: solana_sdk::system_program::ID, + light_token_compressible_config: COMPRESSIBLE_CONFIG_V1, + light_token_rent_sponsor: RENT_SPONSOR, + light_token_cpi_authority: CPI_AUTHORITY_PDA, + }; + + let instruction_data = light_token_minter::instruction::MintTo { + params: light_token_minter::MintTokenParams { + amount, + create_accounts_proof: proof_result.create_accounts_proof, + ata_bump, + }, + }; + + let instruction = Instruction { + program_id, + accounts: [ + accounts.to_account_metas(None), + proof_result.remaining_accounts, + ] + .concat(), + data: instruction_data.data(), + }; + + // Sign with both payer and mint_authority + let signers: Vec<&Keypair> = if payer.pubkey() == mint_authority.pubkey() { + vec![payer] + } else { + vec![payer, mint_authority] + }; + + rpc.create_and_send_transaction(&[instruction], &payer.pubkey(), &signers) + .await + .expect("Mint Light tokens should succeed"); + + println!( + "Minted {} Light tokens to {:?} (owner: {:?})", + amount, destination_ata, destination_owner + ); + + destination_ata + } + + /// Create a Light token account (ATA) for the given owner and mint + /// + /// This creates a light token account for the given owner. + pub async fn create_light_ata( + rpc: &mut R, + payer: &Keypair, + mint: &Pubkey, + owner: &Pubkey, + ) -> Pubkey { + let compressible_params = CompressibleParams { + compressible_config: COMPRESSIBLE_CONFIG_V1, + rent_sponsor: RENT_SPONSOR, + pre_pay_num_epochs: 2, + lamports_per_write: Some(1000), + compress_to_account_pubkey: None, + token_account_version: TokenDataVersion::ShaFlat, + compression_only: true, + }; + + let create_ata_ix = CreateAssociatedTokenAccount::new(payer.pubkey(), *owner, *mint) + .with_compressible(compressible_params) + .idempotent() + .instruction() + .expect("Create Light ATA instruction should succeed"); + + rpc.create_and_send_transaction(&[create_ata_ix], &payer.pubkey(), &[payer]) + .await + .expect("Create Light ATA should succeed"); + + let (ata, _) = derive_token_ata(owner, mint); + println!("Light ATA created: {:?} for owner {:?}", ata, owner); + ata + } + + /// Derive the Light token ATA address for an owner and mint + pub fn derive_light_token_ata(owner: &Pubkey, mint: &Pubkey) -> (Pubkey, u8) { + derive_token_ata(owner, mint) + } +} + +// ============================================================================ +// SPL Interface Module +// ============================================================================ + +pub mod spl_interface { + use super::*; + use light_token::instruction::TransferFromSpl; + + /// Create an SPL interface PDA for the given mint + /// + /// # Arguments + /// * `rpc` - RPC client + /// * `payer` - Transaction fee payer + /// * `mint` - The mint public key + /// * `mint_type` - Whether this is SPL or Token-2022 + /// * `restricted` - Whether the mint has restricted T22 extensions + pub async fn create_spl_interface_pda( + rpc: &mut R, + payer: &Keypair, + mint: &Pubkey, + mint_type: MintType, + restricted: bool, + ) -> SplInterfaceResult { + let (pda, bump) = find_spl_interface_pda(mint, restricted); + + let create_ix = + CreateSplInterfacePda::new(payer.pubkey(), *mint, mint_type.program_id(), restricted) + .instruction(); + + rpc.create_and_send_transaction(&[create_ix], &payer.pubkey(), &[payer]) + .await + .expect("Create SPL interface PDA should succeed"); + + println!( + "SPL interface PDA created: {:?} (restricted={})", + pda, restricted + ); + SplInterfaceResult { pda, bump } + } + + /// Get the SPL interface PDA address without creating it + pub fn get_spl_interface_pda(mint: &Pubkey, restricted: bool) -> SplInterfaceResult { + let (pda, bump) = find_spl_interface_pda(mint, restricted); + SplInterfaceResult { pda, bump } + } + + /// Transfer tokens from an SPL/T22 token account to a Light token account + /// + /// This transfers SPL tokens from a standard SPL/T22 ATA to a light token account. + /// + /// # Arguments + /// * `rpc` - RPC client + /// * `payer` - Transaction fee payer + /// * `authority` - Authority for the source SPL account (must be signer) + /// * `mint` - The mint public key + /// * `decimals` - Token decimals + /// * `source_spl_ata` - Source SPL/T22 token account + /// * `destination_light_ata` - Destination Light token account + /// * `spl_interface_pda` - SPL interface PDA (created via create_spl_interface_pda) + /// * `spl_interface_bump` - Bump seed for the SPL interface PDA + /// * `amount` - Amount of tokens to transfer + /// * `mint_type` - Whether this is SPL or Token-2022 + pub async fn transfer_spl_to_light( + rpc: &mut R, + payer: &Keypair, + authority: &Keypair, + mint: &Pubkey, + decimals: u8, + source_spl_ata: &Pubkey, + destination_light_ata: &Pubkey, + spl_interface_pda: &Pubkey, + spl_interface_bump: u8, + amount: u64, + mint_type: MintType, + ) { + let transfer_ix = TransferFromSpl { + amount, + spl_interface_pda_bump: spl_interface_bump, + decimals, + source_spl_token_account: *source_spl_ata, + destination: *destination_light_ata, + authority: authority.pubkey(), + mint: *mint, + payer: payer.pubkey(), + spl_interface_pda: *spl_interface_pda, + spl_token_program: mint_type.program_id(), + } + .instruction() + .expect("TransferFromSpl instruction should succeed"); + + // Sign with both payer and authority if they're different + let signers: Vec<&Keypair> = if payer.pubkey() == authority.pubkey() { + vec![payer] + } else { + vec![payer, authority] + }; + + rpc.create_and_send_transaction(&[transfer_ix], &payer.pubkey(), &signers) + .await + .expect("Transfer SPL to Light should succeed"); + + println!( + "Transferred {} tokens from SPL {:?} to Light {:?}", + amount, source_spl_ata, destination_light_ata + ); + } +} + +// ============================================================================ +// Helpers Module +// ============================================================================ + +pub mod helpers { + use super::*; + + /// Verify Light Token account balance + pub async fn verify_light_token_balance( + rpc: &mut R, + account: Pubkey, + expected: u64, + name: &str, + ) { + let account_data = rpc.get_account(account).await.unwrap(); + + if let Some(data) = account_data { + // Light Token accounts have first 165 bytes as SPL-compatible token account data + if data.data.len() >= 165 { + let token_state = + spl_pod::bytemuck::pod_from_bytes::(&data.data[..165]).unwrap(); + let actual = u64::from(token_state.amount); + println!("{}: balance = {} (expected {})", name, actual, expected); + assert_eq!( + actual, expected, + "{} balance mismatch: expected {}, got {}", + name, expected, actual + ); + } else { + panic!( + "{}: account data too short: {} bytes", + name, + data.data.len() + ); + } + } else if expected == 0 { + println!("{}: account not found (expected 0 balance)", name); + } else { + panic!( + "{}: account not found but expected balance {}", + name, expected + ); + } + } + + /// Verify SPL/T22 token account balance + pub async fn verify_spl_token_balance( + rpc: &mut R, + account: Pubkey, + expected: u64, + name: &str, + ) { + let account_data = rpc + .get_account(account) + .await + .unwrap() + .unwrap_or_else(|| panic!("{} should exist", name)); + + let token_state = + spl_pod::bytemuck::pod_from_bytes::(&account_data.data[..165]).unwrap(); + let actual = u64::from(token_state.amount); + println!("{}: balance = {} (expected {})", name, actual, expected); + assert_eq!( + actual, expected, + "{} balance mismatch: expected {}, got {}", + name, expected, actual + ); + } + + /// Get proof for creating Light token accounts (PDAs) + pub async fn get_creation_proof( + rpc: &R, + program_id: &Pubkey, + accounts: Vec, + ) -> CreateAccountsProofResult { + let inputs: Vec = accounts + .into_iter() + .map(CreateAccountsProofInput::pda) + .collect(); + + get_create_accounts_proof(rpc, program_id, inputs) + .await + .expect("Get creation proof should succeed") + } + + /// Airdrop lamports to an account + pub async fn airdrop(rpc: &mut R, pubkey: &Pubkey, lamports: u64) { + rpc.airdrop_lamports(pubkey, lamports) + .await + .expect("Airdrop should succeed"); + } +} + +// ============================================================================ +// Internal Helper Functions +// ============================================================================ + +/// SPL mint account size (fixed at 82 bytes) +const SPL_MINT_SIZE: usize = 82; + +/// Token-2022 mint account size (base size without extensions) +const T22_MINT_SIZE: usize = 82; + +async fn create_mint_internal( + rpc: &mut R, + payer: &Keypair, + mint_authority: &Pubkey, + decimals: u8, + mint_type: MintType, +) -> Keypair { + let mint = Keypair::new(); + let program_id = mint_type.program_id(); + + // Get the mint account size based on token program + let mint_size = match mint_type { + MintType::Spl => SPL_MINT_SIZE, + MintType::Token2022 => T22_MINT_SIZE, + }; + + let rent = rpc + .get_minimum_balance_for_rent_exemption(mint_size) + .await + .unwrap(); + + let create_account_ix = solana_sdk::system_instruction::create_account( + &payer.pubkey(), + &mint.pubkey(), + rent, + mint_size as u64, + &program_id, + ); + + let init_mint_ix = match mint_type { + MintType::Spl => token::spl_token::instruction::initialize_mint( + &program_id, + &mint.pubkey(), + mint_authority, + None, + decimals, + ) + .unwrap(), + MintType::Token2022 => spl_token_2022::instruction::initialize_mint( + &program_id, + &mint.pubkey(), + mint_authority, + None, + decimals, + ) + .unwrap(), + }; + + rpc.create_and_send_transaction( + &[create_account_ix, init_mint_ix], + &payer.pubkey(), + &[payer, &mint], + ) + .await + .expect("Create mint should succeed"); + + println!("{:?} mint created: {:?}", mint_type, mint.pubkey()); + mint +} + +async fn create_ata_internal( + rpc: &mut R, + payer: &Keypair, + mint: &Pubkey, + owner: &Pubkey, + mint_type: MintType, +) -> Pubkey { + let program_id = mint_type.program_id(); + + let ata = anchor_spl::associated_token::spl_associated_token_account::get_associated_token_address_with_program_id( + owner, + mint, + &program_id, + ); + + let create_ata_ix = + anchor_spl::associated_token::spl_associated_token_account::instruction::create_associated_token_account( + &payer.pubkey(), + owner, + mint, + &program_id, + ); + + rpc.create_and_send_transaction(&[create_ata_ix], &payer.pubkey(), &[payer]) + .await + .expect("Create ATA should succeed"); + + println!( + "{:?} ATA created: {:?} for owner {:?}", + mint_type, ata, owner + ); + ata +} + +async fn mint_tokens_internal( + rpc: &mut R, + payer: &Keypair, + mint: &Pubkey, + destination: &Pubkey, + mint_authority: &Keypair, + amount: u64, + mint_type: MintType, +) { + let program_id = mint_type.program_id(); + + let mint_to_ix = match mint_type { + MintType::Spl => token::spl_token::instruction::mint_to( + &program_id, + mint, + destination, + &mint_authority.pubkey(), + &[], + amount, + ) + .unwrap(), + MintType::Token2022 => spl_token_2022::instruction::mint_to( + &program_id, + mint, + destination, + &mint_authority.pubkey(), + &[], + amount, + ) + .unwrap(), + }; + + // If payer is the same as mint_authority, only sign once + let signers: Vec<&Keypair> = if payer.pubkey() == mint_authority.pubkey() { + vec![payer] + } else { + vec![payer, mint_authority] + }; + + rpc.create_and_send_transaction(&[mint_to_ix], &payer.pubkey(), &signers) + .await + .expect("Mint tokens should succeed"); + + println!("Minted {} tokens to {:?}", amount, destination); +} + +/// Common test constants +pub mod constants { + /// Default decimals for test tokens + pub const DEFAULT_DECIMALS: u8 = 9; + + /// Default token amount (1000 tokens with 9 decimals) + pub const DEFAULT_TOKEN_AMOUNT: u64 = 1_000_000_000_000; + + /// Default airdrop amount (10 SOL) + pub const DEFAULT_AIRDROP: u64 = 10_000_000_000; +} diff --git a/programs/anchor/token-swap/Cargo.toml b/programs/anchor/token-swap/Cargo.toml new file mode 100644 index 0000000..5b076d3 --- /dev/null +++ b/programs/anchor/token-swap/Cargo.toml @@ -0,0 +1,55 @@ +[package] +name = "swap_example" +version = "0.1.0" +description = "Created with Anchor" +edition = "2021" + +[lib] +crate-type = ["cdylib", "lib"] +name = "swap_example" + +[features] +default = [] +cpi = ["no-entrypoint"] +no-entrypoint = [] +no-idl = [] +no-log-ix-name = [] +idl-build = ["anchor-lang/idl-build", "anchor-spl/idl-build", "light-sdk/idl-build", "light-anchor-spl/idl-build"] +test-sbf = [] + +[dependencies] +anchor-lang = { version = "=0.31.1", features = ["init-if-needed"] } +anchor-spl = { version = "0.31.1", features = ["metadata", "idl-build"] } +blake3 = { workspace = true } +fixed = "=1.27.0" +az = "=1.2.1" + +light-sdk = { workspace = true, features = ["anchor", "anchor-discriminator", "cpi-context", "v2"] } +light-token = { workspace = true, features = ["anchor"] } +light-hasher = { workspace = true, features = ["solana"] } +light-anchor-spl = { workspace = true } +solana-program = { workspace = true } +solana-pubkey = { workspace = true } +solana-account-info = { workspace = true } +solana-program-error = { workspace = true } +solana-msg = { workspace = true } + +[dev-dependencies] +light-program-test = { workspace = true } +light-client = { workspace = true, features = ["v2", "anchor"] } +anchor-spl = { workspace = true } +tokio = { workspace = true, features = ["full"] } +solana-keypair = { workspace = true } +solana-signer = { workspace = true } +solana-instruction = { workspace = true } +solana-sdk = { workspace = true } +spl-token-2022 = { workspace = true } +spl-pod = { workspace = true } +shared-test-utils = { workspace = true } + +[lints.rust.unexpected_cfgs] +level = "allow" +check-cfg = [ + 'cfg(target_os, values("solana"))', + 'cfg(feature, values("frozen-abi", "no-entrypoint"))', +] diff --git a/programs/anchor/token-swap/Xargo.toml b/programs/anchor/token-swap/Xargo.toml new file mode 100644 index 0000000..475fb71 --- /dev/null +++ b/programs/anchor/token-swap/Xargo.toml @@ -0,0 +1,2 @@ +[target.bpfel-unknown-unknown.dependencies.std] +features = [] diff --git a/programs/anchor/token-swap/src/constants.rs b/programs/anchor/token-swap/src/constants.rs new file mode 100644 index 0000000..28ef13c --- /dev/null +++ b/programs/anchor/token-swap/src/constants.rs @@ -0,0 +1,19 @@ +use anchor_lang::prelude::*; + +#[constant] +pub const MINIMUM_LIQUIDITY: u64 = 100; + +#[constant] +pub const AUTHORITY_SEED: &[u8] = b"authority"; + +#[constant] +pub const LIQUIDITY_SEED: &[u8] = b"liquidity"; + +#[constant] +pub const POOL_ACCOUNT_A_SEED: &[u8] = b"pool_a"; + +#[constant] +pub const POOL_ACCOUNT_B_SEED: &[u8] = b"pool_b"; + +#[constant] +pub const LP_MINT_SIGNER_SEED: &[u8] = b"lp_mint_signer"; diff --git a/programs/anchor/token-swap/src/errors.rs b/programs/anchor/token-swap/src/errors.rs new file mode 100644 index 0000000..ae97d61 --- /dev/null +++ b/programs/anchor/token-swap/src/errors.rs @@ -0,0 +1,25 @@ +use anchor_lang::prelude::*; + +#[error_code] +pub enum SwapError { + #[msg("Invalid fee value")] + InvalidFee, + + #[msg("Invalid mint for the pool")] + InvalidMint, + + #[msg("Depositing too little liquidity")] + DepositTooSmall, + + #[msg("Output is below the minimum expected")] + OutputTooSmall, + + #[msg("Invariant does not hold")] + InvariantViolated, + + #[msg("Arithmetic overflow")] + Overflow, + + #[msg("Arithmetic underflow")] + Underflow, +} diff --git a/programs/anchor/token-swap/src/instructions/create_amm.rs b/programs/anchor/token-swap/src/instructions/create_amm.rs new file mode 100644 index 0000000..cb804f7 --- /dev/null +++ b/programs/anchor/token-swap/src/instructions/create_amm.rs @@ -0,0 +1,36 @@ +use anchor_lang::prelude::*; + +use crate::{errors::*, state::Amm}; + +pub fn create_amm(ctx: Context, id: Pubkey, fee: u16) -> Result<()> { + let amm = &mut ctx.accounts.amm; + amm.id = id; + amm.admin = ctx.accounts.admin.key(); + amm.fee = fee; + + Ok(()) +} + +#[derive(Accounts)] +#[instruction(id: Pubkey, fee: u16)] +pub struct CreateAmm<'info> { + #[account( + init, + payer = payer, + space = Amm::LEN, + seeds = [ + id.as_ref() + ], + bump, + constraint = fee < 10000 @ SwapError::InvalidFee, + )] + pub amm: Account<'info, Amm>, + + /// CHECK: Read only, delegatable creation + pub admin: AccountInfo<'info>, + + #[account(mut)] + pub payer: Signer<'info>, + + pub system_program: Program<'info, System>, +} diff --git a/programs/anchor/token-swap/src/instructions/create_pool.rs b/programs/anchor/token-swap/src/instructions/create_pool.rs new file mode 100644 index 0000000..563ec1b --- /dev/null +++ b/programs/anchor/token-swap/src/instructions/create_pool.rs @@ -0,0 +1,135 @@ +use anchor_lang::prelude::*; +use light_anchor_spl::token_interface::{Mint, TokenInterface}; +use light_sdk::interface::CreateAccountsProof; +use light_token::anchor::LightAccounts; +use light_token::instruction::{COMPRESSIBLE_CONFIG_V1, RENT_SPONSOR}; + +use crate::{ + constants::{AUTHORITY_SEED, LIQUIDITY_SEED, POOL_ACCOUNT_A_SEED, POOL_ACCOUNT_B_SEED}, + state::{Amm, Pool}, +}; + +#[derive(AnchorSerialize, AnchorDeserialize, Clone)] +pub struct CreatePoolParams { + pub create_accounts_proof: CreateAccountsProof, + pub pool_account_a_bump: u8, + pub pool_account_b_bump: u8, +} + +pub fn create_pool(ctx: Context, _params: CreatePoolParams) -> Result<()> { + let pool = &mut ctx.accounts.pool; + pool.amm = ctx.accounts.amm.key(); + pool.mint_a = ctx.accounts.mint_a.key(); + pool.mint_b = ctx.accounts.mint_b.key(); + pool.lp_supply = 0; + + Ok(()) +} + +#[derive(Accounts, LightAccounts)] +#[instruction(params: CreatePoolParams)] +pub struct CreatePool<'info> { + #[account( + seeds = [ + amm.id.as_ref() + ], + bump, + )] + pub amm: Box>, + + #[account( + init, + payer = fee_payer, + space = Pool::LEN, + seeds = [ + amm.key().as_ref(), + mint_a.key().as_ref(), + mint_b.key().as_ref(), + ], + bump, + )] + pub pool: Box>, + + /// CHECK: PDA verified by seeds constraint + #[account( + seeds = [ + amm.key().as_ref(), + mint_a.key().as_ref(), + mint_b.key().as_ref(), + AUTHORITY_SEED, + ], + bump, + )] + pub pool_authority: AccountInfo<'info>, + + #[account( + init, + payer = fee_payer, + seeds = [ + amm.key().as_ref(), + mint_a.key().as_ref(), + mint_b.key().as_ref(), + LIQUIDITY_SEED, + ], + bump, + mint::decimals = 6, + mint::authority = pool_authority, + mint::token_program = liquidity_token_program, + )] + pub mint_liquidity: Box>, + + #[account(mint::token_program = token_program)] + pub mint_a: Box>, + + #[account(mint::token_program = token_program)] + pub mint_b: Box>, + + /// CHECK: PDA verified by seeds constraint + #[account( + mut, + seeds = [POOL_ACCOUNT_A_SEED, pool.key().as_ref()], + bump, + )] + #[light_account(init, + token::authority = [POOL_ACCOUNT_A_SEED, self.pool.key()], + token::mint = mint_a, + token::owner = pool_authority, + token::bump = params.pool_account_a_bump + )] + pub pool_account_a: UncheckedAccount<'info>, + + /// CHECK: PDA verified by seeds constraint + #[account( + mut, + seeds = [POOL_ACCOUNT_B_SEED, pool.key().as_ref()], + bump, + )] + #[light_account(init, + token::authority = [POOL_ACCOUNT_B_SEED, self.pool.key()], + token::mint = mint_b, + token::owner = pool_authority, + token::bump = params.pool_account_b_bump + )] + pub pool_account_b: UncheckedAccount<'info>, + + #[account(mut)] + pub fee_payer: Signer<'info>, + + /// Token program for mint_a and mint_b (SPL, T22, or Light). + pub token_program: Interface<'info, TokenInterface>, + /// Token program for LP mint (may differ from token_program). + pub liquidity_token_program: Interface<'info, TokenInterface>, + pub light_token_program: Interface<'info, TokenInterface>, + pub system_program: Program<'info, System>, + + /// CHECK: Validated by address constraint + #[account(address = COMPRESSIBLE_CONFIG_V1)] + pub light_token_compressible_config: AccountInfo<'info>, + + /// CHECK: Validated by address constraint + #[account(mut, address = RENT_SPONSOR)] + pub light_token_rent_sponsor: AccountInfo<'info>, + + /// CHECK: Light token CPI authority + pub light_token_cpi_authority: AccountInfo<'info>, +} diff --git a/programs/anchor/token-swap/src/instructions/create_pool_light_lp.rs b/programs/anchor/token-swap/src/instructions/create_pool_light_lp.rs new file mode 100644 index 0000000..8faaa7a --- /dev/null +++ b/programs/anchor/token-swap/src/instructions/create_pool_light_lp.rs @@ -0,0 +1,179 @@ +use anchor_lang::prelude::*; +use light_anchor_spl::token_interface::TokenInterface; +use light_sdk::interface::CreateAccountsProof; +use light_token::anchor::LightAccounts; +use light_token::instruction::{CreateTokenAccountCpi, COMPRESSIBLE_CONFIG_V1, RENT_SPONSOR}; + +use crate::{ + constants::{AUTHORITY_SEED, LP_MINT_SIGNER_SEED, POOL_ACCOUNT_A_SEED, POOL_ACCOUNT_B_SEED}, + state::{Amm, Pool}, +}; + +#[derive(AnchorSerialize, AnchorDeserialize, Clone)] +pub struct CreatePoolLightLpParams { + pub create_accounts_proof: CreateAccountsProof, + pub pool_account_a_bump: u8, + pub pool_account_b_bump: u8, + pub lp_mint_signer_bump: u8, + pub pool_authority_bump: u8, +} + +pub fn create_pool_light_lp( + ctx: Context, + params: CreatePoolLightLpParams, +) -> Result<()> { + let pool = &mut ctx.accounts.pool; + pool.amm = ctx.accounts.amm.key(); + pool.mint_a = ctx.accounts.mint_a.key(); + pool.mint_b = ctx.accounts.mint_b.key(); + pool.lp_supply = 0; + + let pool_key = ctx.accounts.pool.key(); + + CreateTokenAccountCpi { + payer: ctx.accounts.fee_payer.to_account_info(), + account: ctx.accounts.pool_vault_a.to_account_info(), + mint: ctx.accounts.mint_a.to_account_info(), + owner: ctx.accounts.pool_authority.key(), + } + .rent_free( + ctx.accounts.light_token_compressible_config.to_account_info(), + ctx.accounts.light_token_rent_sponsor.to_account_info(), + ctx.accounts.system_program.to_account_info(), + &crate::ID, + ) + .invoke_signed(&[ + POOL_ACCOUNT_A_SEED, + pool_key.as_ref(), + &[params.pool_account_a_bump], + ])?; + + CreateTokenAccountCpi { + payer: ctx.accounts.fee_payer.to_account_info(), + account: ctx.accounts.pool_vault_b.to_account_info(), + mint: ctx.accounts.mint_b.to_account_info(), + owner: ctx.accounts.pool_authority.key(), + } + .rent_free( + ctx.accounts.light_token_compressible_config.to_account_info(), + ctx.accounts.light_token_rent_sponsor.to_account_info(), + ctx.accounts.system_program.to_account_info(), + &crate::ID, + ) + .invoke_signed(&[ + POOL_ACCOUNT_B_SEED, + pool_key.as_ref(), + &[params.pool_account_b_bump], + ])?; + + Ok(()) +} + +#[derive(Accounts, LightAccounts)] +#[instruction(params: CreatePoolLightLpParams)] +pub struct CreatePoolLightLp<'info> { + #[account( + seeds = [ + amm.id.as_ref() + ], + bump, + )] + pub amm: Box>, + + #[account( + init, + payer = fee_payer, + space = Pool::LEN, + seeds = [ + amm.key().as_ref(), + mint_a.key().as_ref(), + mint_b.key().as_ref(), + ], + bump, + )] + pub pool: Box>, + + /// CHECK: PDA verified by seeds constraint + #[account( + seeds = [ + amm.key().as_ref(), + mint_a.key().as_ref(), + mint_b.key().as_ref(), + AUTHORITY_SEED, + ], + bump, + )] + pub pool_authority: AccountInfo<'info>, + + /// CHECK: PDA verified by seeds constraint + #[account( + seeds = [LP_MINT_SIGNER_SEED, pool.key().as_ref()], + bump, + )] + pub lp_mint_signer: UncheckedAccount<'info>, + + /// CHECK: Initialized by light_account macro + #[account(mut)] + #[light_account(init, + mint::signer = lp_mint_signer, + mint::authority = pool_authority, + mint::decimals = 6, + mint::seeds = &[LP_MINT_SIGNER_SEED, self.pool.to_account_info().key.as_ref()], + mint::bump = params.lp_mint_signer_bump, + mint::name = b"LP Token".to_vec(), + mint::symbol = b"LP".to_vec(), + mint::uri = b"".to_vec(), + mint::update_authority = pool_authority, + mint::authority_seeds = &[self.amm.to_account_info().key.as_ref(), self.mint_a.to_account_info().key.as_ref(), self.mint_b.to_account_info().key.as_ref(), AUTHORITY_SEED], + mint::authority_bump = params.pool_authority_bump + )] + pub mint_liquidity: UncheckedAccount<'info>, + + /// CHECK: Validated by pool_vault_a light_account constraint + pub mint_a: AccountInfo<'info>, + + /// CHECK: Validated by pool_vault_b light_account constraint + pub mint_b: AccountInfo<'info>, + + /// CHECK: Created via CreateTokenAccountCpi in handler + #[account( + mut, + seeds = [POOL_ACCOUNT_A_SEED, pool.key().as_ref()], + bump, + )] + #[light_account(token::authority = [POOL_ACCOUNT_A_SEED, self.pool.key()])] + pub pool_vault_a: UncheckedAccount<'info>, + + /// CHECK: Created via CreateTokenAccountCpi in handler + #[account( + mut, + seeds = [POOL_ACCOUNT_B_SEED, pool.key().as_ref()], + bump, + )] + #[light_account(token::authority = [POOL_ACCOUNT_B_SEED, self.pool.key()])] + pub pool_vault_b: UncheckedAccount<'info>, + + #[account(mut)] + pub fee_payer: Signer<'info>, + + /// Token program for mint_a and mint_b (SPL, T22, or Light). + pub token_program: Interface<'info, TokenInterface>, + + /// CHECK: Program-specific config for light mint creation + pub compression_config: AccountInfo<'info>, + + /// CHECK: Validated by address constraint + #[account(address = COMPRESSIBLE_CONFIG_V1)] + pub light_token_compressible_config: AccountInfo<'info>, + + /// CHECK: Validated by address constraint + #[account(mut, address = RENT_SPONSOR)] + pub light_token_rent_sponsor: AccountInfo<'info>, + + pub light_token_program: Interface<'info, TokenInterface>, + + /// CHECK: Light token CPI authority + pub light_token_cpi_authority: AccountInfo<'info>, + + pub system_program: Program<'info, System>, +} diff --git a/programs/anchor/token-swap/src/instructions/deposit_liquidity.rs b/programs/anchor/token-swap/src/instructions/deposit_liquidity.rs new file mode 100644 index 0000000..859ca29 --- /dev/null +++ b/programs/anchor/token-swap/src/instructions/deposit_liquidity.rs @@ -0,0 +1,278 @@ +use anchor_lang::prelude::*; +use fixed::types::I64F64; +use light_anchor_spl::token_interface::{Mint, MintTo, TokenAccount, TokenInterface}; +use light_token::instruction::{MintToCpi, RENT_SPONSOR}; +use light_token::spl_interface::find_spl_interface_pda; +use light_token::utils::get_token_account_balance; +use light_sdk::constants::LIGHT_TOKEN_PROGRAM_ID; + +use crate::{ + constants::{ + AUTHORITY_SEED, MINIMUM_LIQUIDITY, POOL_ACCOUNT_A_SEED, POOL_ACCOUNT_B_SEED, + }, + errors::SwapError, + instructions::{transfer_tokens, SplInterfaceConfig}, + state::Pool, +}; + +pub fn deposit_liquidity( + ctx: Context, + amount_a: u64, + amount_b: u64, +) -> Result<()> { + let pool_a_balance = get_token_account_balance(&ctx.accounts.pool_account_a.to_account_info()) + .map_err(|_| anchor_lang::prelude::ProgramError::InvalidAccountData)?; + let pool_b_balance = get_token_account_balance(&ctx.accounts.pool_account_b.to_account_info()) + .map_err(|_| anchor_lang::prelude::ProgramError::InvalidAccountData)?; + + let mut amount_a = if amount_a > ctx.accounts.depositor_account_a.amount { + ctx.accounts.depositor_account_a.amount + } else { + amount_a + }; + let mut amount_b = if amount_b > ctx.accounts.depositor_account_b.amount { + ctx.accounts.depositor_account_b.amount + } else { + amount_b + }; + + // Frontrun risk: attackers can frontrun pool creation with bad ratios + let pool_creation = pool_a_balance == 0 && pool_b_balance == 0; + (amount_a, amount_b) = if pool_creation { + (amount_a, amount_b) + } else { + let ratio = I64F64::from_num(pool_a_balance) + .checked_div(I64F64::from_num(pool_b_balance)) + .ok_or(SwapError::Underflow)?; + if pool_a_balance > pool_b_balance { + ( + I64F64::from_num(amount_b) + .checked_mul(ratio) + .ok_or(SwapError::Overflow)? + .to_num::(), + amount_b, + ) + } else { + ( + amount_a, + I64F64::from_num(amount_a) + .checked_div(ratio) + .ok_or(SwapError::Underflow)? + .to_num::(), + ) + } + }; + + let mut liquidity = I64F64::from_num(amount_a) + .checked_mul(I64F64::from_num(amount_b)) + .ok_or(SwapError::Overflow)? + .sqrt() + .to_num::(); + + if pool_creation { + if liquidity < MINIMUM_LIQUIDITY { + return err!(SwapError::DepositTooSmall); + } + + liquidity -= MINIMUM_LIQUIDITY; + } + + let decimals_a = ctx.accounts.mint_a.decimals; + let decimals_b = ctx.accounts.mint_b.decimals; + + let (_, spl_interface_bump_a) = find_spl_interface_pda(&ctx.accounts.mint_a.key(), false); + let (_, spl_interface_bump_b) = find_spl_interface_pda(&ctx.accounts.mint_b.key(), false); + + let spl_interface_a = SplInterfaceConfig { + mint: ctx.accounts.mint_a.to_account_info(), + spl_token_program: ctx.accounts.token_program.to_account_info(), + spl_interface_pda: ctx.accounts.spl_interface_pda_a.to_account_info(), + spl_interface_pda_bump: spl_interface_bump_a, + }; + + transfer_tokens( + amount_a, + decimals_a, + ctx.accounts.depositor_account_a.to_account_info(), + ctx.accounts.pool_account_a.to_account_info(), + ctx.accounts.mint_a.to_account_info(), + ctx.accounts.depositor.to_account_info(), + ctx.accounts.payer.to_account_info(), + ctx.accounts.light_token_cpi_authority.to_account_info(), + ctx.accounts.system_program.to_account_info(), + None, + Some(spl_interface_a), + )?; + + let spl_interface_b = SplInterfaceConfig { + mint: ctx.accounts.mint_b.to_account_info(), + spl_token_program: ctx.accounts.token_program.to_account_info(), + spl_interface_pda: ctx.accounts.spl_interface_pda_b.to_account_info(), + spl_interface_pda_bump: spl_interface_bump_b, + }; + + transfer_tokens( + amount_b, + decimals_b, + ctx.accounts.depositor_account_b.to_account_info(), + ctx.accounts.pool_account_b.to_account_info(), + ctx.accounts.mint_b.to_account_info(), + ctx.accounts.depositor.to_account_info(), + ctx.accounts.payer.to_account_info(), + ctx.accounts.light_token_cpi_authority.to_account_info(), + ctx.accounts.system_program.to_account_info(), + None, + Some(spl_interface_b), + )?; + + let authority_bump = ctx.bumps.pool_authority; + let amm_key = ctx.accounts.pool.amm; + let mint_a_key = ctx.accounts.mint_a.key(); + let mint_b_key = ctx.accounts.mint_b.key(); + let authority_seeds: &[&[u8]] = &[ + amm_key.as_ref(), + mint_a_key.as_ref(), + mint_b_key.as_ref(), + AUTHORITY_SEED, + &[authority_bump], + ]; + + let is_light_lp = ctx.accounts.liquidity_token_program.key().to_bytes() == LIGHT_TOKEN_PROGRAM_ID; + + if is_light_lp { + MintToCpi { + mint: ctx.accounts.mint_liquidity.to_account_info(), + destination: ctx.accounts.depositor_account_liquidity.to_account_info(), + amount: liquidity, + authority: ctx.accounts.pool_authority.to_account_info(), + system_program: ctx.accounts.system_program.to_account_info(), + max_top_up: None, + fee_payer: Some(ctx.accounts.payer.to_account_info()), + } + .invoke_signed(&[authority_seeds])?; + } else { + let signer_seeds = &[authority_seeds]; + light_anchor_spl::token_interface::mint_to( + CpiContext::new_with_signer( + ctx.accounts.liquidity_token_program.to_account_info(), + MintTo { + mint: ctx.accounts.mint_liquidity.to_account_info(), + to: ctx.accounts.depositor_account_liquidity.to_account_info(), + authority: ctx.accounts.pool_authority.to_account_info(), + }, + signer_seeds, + ), + liquidity, + )?; + } + + ctx.accounts.pool.lp_supply = ctx + .accounts + .pool + .lp_supply + .checked_add(liquidity) + .ok_or(SwapError::Overflow)?; + + Ok(()) +} + +#[derive(Accounts)] +pub struct DepositLiquidity<'info> { + #[account( + mut, + seeds = [ + pool.amm.as_ref(), + pool.mint_a.key().as_ref(), + pool.mint_b.key().as_ref(), + ], + bump, + has_one = mint_a, + has_one = mint_b, + )] + pub pool: Box>, + + /// CHECK: PDA verified by seeds constraint + #[account( + seeds = [ + pool.amm.as_ref(), + mint_a.key().as_ref(), + mint_b.key().as_ref(), + AUTHORITY_SEED, + ], + bump, + )] + pub pool_authority: AccountInfo<'info>, + + #[account(mut)] + pub depositor: Signer<'info>, + + /// CHECK: Can be SPL, T22, or Light + #[account(mut)] + pub mint_liquidity: UncheckedAccount<'info>, + + #[account(mint::token_program = token_program)] + pub mint_a: Box>, + + #[account(mint::token_program = token_program)] + pub mint_b: Box>, + + /// CHECK: PDA verified by seeds constraint + #[account( + mut, + seeds = [POOL_ACCOUNT_A_SEED, pool.key().as_ref()], + bump, + )] + pub pool_account_a: UncheckedAccount<'info>, + + /// CHECK: PDA verified by seeds constraint + #[account( + mut, + seeds = [POOL_ACCOUNT_B_SEED, pool.key().as_ref()], + bump, + )] + pub pool_account_b: UncheckedAccount<'info>, + + /// CHECK: Can be SPL, T22, or Light + #[account(mut)] + pub depositor_account_liquidity: UncheckedAccount<'info>, + + #[account( + mut, + token::mint = mint_a, + token::authority = depositor, + )] + pub depositor_account_a: Box>, + + #[account( + mut, + token::mint = mint_b, + token::authority = depositor, + )] + pub depositor_account_b: Box>, + + #[account(mut)] + pub payer: Signer<'info>, + + /// Token program for mint_a and mint_b (SPL, T22, or Light). + pub token_program: Interface<'info, TokenInterface>, + /// Token program for LP mint (may differ from token_program). + pub liquidity_token_program: Interface<'info, TokenInterface>, + pub system_program: Program<'info, System>, + pub light_token_program: Interface<'info, TokenInterface>, + + /// CHECK: Validated by address constraint + #[account(mut, address = RENT_SPONSOR)] + pub light_token_rent_sponsor: AccountInfo<'info>, + + /// CHECK: Light token CPI authority + #[account(mut)] + pub light_token_cpi_authority: AccountInfo<'info>, + + /// CHECK: SPL interface PDA derived by light-token: ["pool", mint_a] + #[account(mut)] + pub spl_interface_pda_a: UncheckedAccount<'info>, + + /// CHECK: SPL interface PDA derived by light-token: ["pool", mint_b] + #[account(mut)] + pub spl_interface_pda_b: UncheckedAccount<'info>, +} diff --git a/programs/anchor/token-swap/src/instructions/mod.rs b/programs/anchor/token-swap/src/instructions/mod.rs new file mode 100644 index 0000000..5b0ac9a --- /dev/null +++ b/programs/anchor/token-swap/src/instructions/mod.rs @@ -0,0 +1,15 @@ +mod create_amm; +mod create_pool; +mod create_pool_light_lp; +mod deposit_liquidity; +mod shared; +mod swap_exact_tokens_for_tokens; +mod withdraw_liquidity; + +pub use create_amm::*; +pub use create_pool::*; +pub use create_pool_light_lp::*; +pub use deposit_liquidity::*; +pub use shared::*; +pub use swap_exact_tokens_for_tokens::*; +pub use withdraw_liquidity::*; diff --git a/programs/anchor/token-swap/src/instructions/shared.rs b/programs/anchor/token-swap/src/instructions/shared.rs new file mode 100644 index 0000000..b264ca9 --- /dev/null +++ b/programs/anchor/token-swap/src/instructions/shared.rs @@ -0,0 +1,81 @@ +use anchor_lang::prelude::*; +use light_sdk::constants::LIGHT_TOKEN_PROGRAM_ID; +use light_token::instruction::{TransferCheckedCpi, TransferInterfaceCpi}; + +pub struct SplInterfaceConfig<'info> { + pub mint: AccountInfo<'info>, + pub spl_token_program: AccountInfo<'info>, + pub spl_interface_pda: AccountInfo<'info>, + pub spl_interface_pda_bump: u8, +} + +fn is_light_account(account: &AccountInfo) -> bool { + account.owner == &Pubkey::new_from_array(LIGHT_TOKEN_PROGRAM_ID) +} + +pub fn transfer_tokens<'info>( + amount: u64, + decimals: u8, + from: AccountInfo<'info>, + to: AccountInfo<'info>, + mint: AccountInfo<'info>, + authority: AccountInfo<'info>, + payer: AccountInfo<'info>, + light_token_cpi_authority: AccountInfo<'info>, + system_program: AccountInfo<'info>, + signer_seeds: Option<&[&[u8]]>, + spl_interface: Option>, +) -> Result<()> { + let is_light_to_light = is_light_account(&from) && is_light_account(&to); + + if is_light_to_light { + // fee_payer: Some ensures authority is readonly (required for PDA with account data) + let cpi = TransferCheckedCpi { + source: from, + mint, + destination: to, + amount, + decimals, + authority, + system_program, + max_top_up: Some(0), + fee_payer: Some(payer), + }; + + if let Some(seeds) = signer_seeds { + cpi.invoke_signed(&[seeds]) + } else { + cpi.invoke() + } + .map_err(|e| anchor_lang::prelude::ProgramError::from(e).into()) + } else { + let mut cpi = TransferInterfaceCpi::new( + amount, + decimals, + from, + to, + authority, + payer, + light_token_cpi_authority, + system_program, + ); + + if let Some(spl) = spl_interface { + cpi = cpi + .with_spl_interface( + Some(spl.mint), + Some(spl.spl_token_program), + Some(spl.spl_interface_pda), + Some(spl.spl_interface_pda_bump), + ) + .map_err(|e| anchor_lang::prelude::ProgramError::from(e))?; + } + + if let Some(seeds) = signer_seeds { + cpi.invoke_signed(&[seeds]) + } else { + cpi.invoke() + } + .map_err(|e| anchor_lang::prelude::ProgramError::from(e).into()) + } +} diff --git a/programs/anchor/token-swap/src/instructions/swap_exact_tokens_for_tokens.rs b/programs/anchor/token-swap/src/instructions/swap_exact_tokens_for_tokens.rs new file mode 100644 index 0000000..0ad6bcb --- /dev/null +++ b/programs/anchor/token-swap/src/instructions/swap_exact_tokens_for_tokens.rs @@ -0,0 +1,285 @@ +use anchor_lang::prelude::*; +use fixed::types::I64F64; +use light_anchor_spl::token_interface::{Mint, TokenAccount, TokenInterface}; +use light_token::instruction::RENT_SPONSOR; +use light_token::spl_interface::find_spl_interface_pda; +use light_token::utils::get_token_account_balance; + +use crate::{ + constants::{AUTHORITY_SEED, POOL_ACCOUNT_A_SEED, POOL_ACCOUNT_B_SEED}, + errors::*, + instructions::{transfer_tokens, SplInterfaceConfig}, + state::{Amm, Pool}, +}; + +pub fn swap_exact_tokens_for_tokens( + ctx: Context, + swap_a: bool, + input_amount: u64, + min_output_amount: u64, +) -> Result<()> { + let input = if swap_a && input_amount > ctx.accounts.trader_account_a.amount { + ctx.accounts.trader_account_a.amount + } else if !swap_a && input_amount > ctx.accounts.trader_account_b.amount { + ctx.accounts.trader_account_b.amount + } else { + input_amount + }; + + let pool_a_balance = get_token_account_balance(&ctx.accounts.pool_account_a.to_account_info()) + .map_err(|_| anchor_lang::prelude::ProgramError::InvalidAccountData)?; + let pool_b_balance = get_token_account_balance(&ctx.accounts.pool_account_b.to_account_info()) + .map_err(|_| anchor_lang::prelude::ProgramError::InvalidAccountData)?; + + let amm = &ctx.accounts.amm; + let fee_amount = (input as u128 * amm.fee as u128 / 10000) as u64; + let taxed_input = input - fee_amount; + + let output = if swap_a { + I64F64::from_num(taxed_input) + .checked_mul(I64F64::from_num(pool_b_balance)) + .ok_or(SwapError::Overflow)? + .checked_div( + I64F64::from_num(pool_a_balance) + .checked_add(I64F64::from_num(taxed_input)) + .ok_or(SwapError::Overflow)?, + ) + .ok_or(SwapError::Underflow)? + } else { + I64F64::from_num(taxed_input) + .checked_mul(I64F64::from_num(pool_a_balance)) + .ok_or(SwapError::Overflow)? + .checked_div( + I64F64::from_num(pool_b_balance) + .checked_add(I64F64::from_num(taxed_input)) + .ok_or(SwapError::Overflow)?, + ) + .ok_or(SwapError::Underflow)? + } + .to_num::(); + + if output < min_output_amount { + return err!(SwapError::OutputTooSmall); + } + + let invariant = (pool_a_balance as u128) * (pool_b_balance as u128); + + let authority_bump = ctx.bumps.pool_authority; + let mint_a_key = ctx.accounts.mint_a.key(); + let mint_b_key = ctx.accounts.mint_b.key(); + let authority_seeds: &[&[u8]] = &[ + ctx.accounts.pool.amm.as_ref(), + mint_a_key.as_ref(), + mint_b_key.as_ref(), + AUTHORITY_SEED, + &[authority_bump], + ]; + + let decimals_a = ctx.accounts.mint_a.decimals; + let decimals_b = ctx.accounts.mint_b.decimals; + + let (_, spl_interface_bump_a) = find_spl_interface_pda(&ctx.accounts.mint_a.key(), false); + let (_, spl_interface_bump_b) = find_spl_interface_pda(&ctx.accounts.mint_b.key(), false); + + if swap_a { + let spl_interface_a = SplInterfaceConfig { + mint: ctx.accounts.mint_a.to_account_info(), + spl_token_program: ctx.accounts.token_program.to_account_info(), + spl_interface_pda: ctx.accounts.spl_interface_pda_a.to_account_info(), + spl_interface_pda_bump: spl_interface_bump_a, + }; + transfer_tokens( + input, + decimals_a, + ctx.accounts.trader_account_a.to_account_info(), + ctx.accounts.pool_account_a.to_account_info(), + ctx.accounts.mint_a.to_account_info(), + ctx.accounts.trader.to_account_info(), + ctx.accounts.payer.to_account_info(), + ctx.accounts.light_token_cpi_authority.to_account_info(), + ctx.accounts.system_program.to_account_info(), + None, + Some(spl_interface_a), + )?; + + let spl_interface_b = SplInterfaceConfig { + mint: ctx.accounts.mint_b.to_account_info(), + spl_token_program: ctx.accounts.token_program.to_account_info(), + spl_interface_pda: ctx.accounts.spl_interface_pda_b.to_account_info(), + spl_interface_pda_bump: spl_interface_bump_b, + }; + transfer_tokens( + output, + decimals_b, + ctx.accounts.pool_account_b.to_account_info(), + ctx.accounts.trader_account_b.to_account_info(), + ctx.accounts.mint_b.to_account_info(), + ctx.accounts.pool_authority.to_account_info(), + ctx.accounts.payer.to_account_info(), + ctx.accounts.light_token_cpi_authority.to_account_info(), + ctx.accounts.system_program.to_account_info(), + Some(authority_seeds), + Some(spl_interface_b), + )?; + } else { + let spl_interface_b = SplInterfaceConfig { + mint: ctx.accounts.mint_b.to_account_info(), + spl_token_program: ctx.accounts.token_program.to_account_info(), + spl_interface_pda: ctx.accounts.spl_interface_pda_b.to_account_info(), + spl_interface_pda_bump: spl_interface_bump_b, + }; + transfer_tokens( + input, + decimals_b, + ctx.accounts.trader_account_b.to_account_info(), + ctx.accounts.pool_account_b.to_account_info(), + ctx.accounts.mint_b.to_account_info(), + ctx.accounts.trader.to_account_info(), + ctx.accounts.payer.to_account_info(), + ctx.accounts.light_token_cpi_authority.to_account_info(), + ctx.accounts.system_program.to_account_info(), + None, + Some(spl_interface_b), + )?; + + let spl_interface_a = SplInterfaceConfig { + mint: ctx.accounts.mint_a.to_account_info(), + spl_token_program: ctx.accounts.token_program.to_account_info(), + spl_interface_pda: ctx.accounts.spl_interface_pda_a.to_account_info(), + spl_interface_pda_bump: spl_interface_bump_a, + }; + transfer_tokens( + output, + decimals_a, + ctx.accounts.pool_account_a.to_account_info(), + ctx.accounts.trader_account_a.to_account_info(), + ctx.accounts.mint_a.to_account_info(), + ctx.accounts.pool_authority.to_account_info(), + ctx.accounts.payer.to_account_info(), + ctx.accounts.light_token_cpi_authority.to_account_info(), + ctx.accounts.system_program.to_account_info(), + Some(authority_seeds), + Some(spl_interface_a), + )?; + } + + msg!( + "Traded {} tokens ({} after fees) for {}", + input, + taxed_input, + output + ); + + // Higher invariant OK - rounding benefits LPs + let new_pool_a_balance = + get_token_account_balance(&ctx.accounts.pool_account_a.to_account_info()) + .map_err(|_| anchor_lang::prelude::ProgramError::InvalidAccountData)?; + let new_pool_b_balance = + get_token_account_balance(&ctx.accounts.pool_account_b.to_account_info()) + .map_err(|_| anchor_lang::prelude::ProgramError::InvalidAccountData)?; + + if invariant > (new_pool_a_balance as u128) * (new_pool_b_balance as u128) { + return err!(SwapError::InvariantViolated); + } + + Ok(()) +} + +#[derive(Accounts)] +pub struct SwapExactTokensForTokens<'info> { + #[account( + seeds = [ + amm.id.as_ref() + ], + bump, + )] + pub amm: Account<'info, Amm>, + + #[account( + seeds = [ + pool.amm.as_ref(), + pool.mint_a.key().as_ref(), + pool.mint_b.key().as_ref(), + ], + bump, + has_one = amm, + has_one = mint_a, + has_one = mint_b, + )] + pub pool: Account<'info, Pool>, + + /// CHECK: PDA verified by seeds constraint + #[account( + seeds = [ + pool.amm.as_ref(), + mint_a.key().as_ref(), + mint_b.key().as_ref(), + AUTHORITY_SEED, + ], + bump, + )] + pub pool_authority: AccountInfo<'info>, + + #[account(mut)] + pub trader: Signer<'info>, + + #[account(mint::token_program = token_program)] + pub mint_a: Box>, + + #[account(mint::token_program = token_program)] + pub mint_b: Box>, + + /// CHECK: PDA verified by seeds constraint + #[account( + mut, + seeds = [POOL_ACCOUNT_A_SEED, pool.key().as_ref()], + bump, + )] + pub pool_account_a: UncheckedAccount<'info>, + + /// CHECK: PDA verified by seeds constraint + #[account( + mut, + seeds = [POOL_ACCOUNT_B_SEED, pool.key().as_ref()], + bump, + )] + pub pool_account_b: UncheckedAccount<'info>, + + #[account( + mut, + token::mint = mint_a, + token::authority = trader, + )] + pub trader_account_a: Box>, + + #[account( + mut, + token::mint = mint_b, + token::authority = trader, + )] + pub trader_account_b: Box>, + + #[account(mut)] + pub payer: Signer<'info>, + + /// Token program for mint_a and mint_b (SPL, T22, or Light). + pub token_program: Interface<'info, TokenInterface>, + pub system_program: Program<'info, System>, + pub light_token_program: Interface<'info, TokenInterface>, + + /// CHECK: Validated by address constraint + #[account(mut, address = RENT_SPONSOR)] + pub light_token_rent_sponsor: AccountInfo<'info>, + + /// CHECK: Light token CPI authority + #[account(mut)] + pub light_token_cpi_authority: AccountInfo<'info>, + + /// CHECK: SPL interface PDA derived by light-token: ["pool", mint_a] + #[account(mut)] + pub spl_interface_pda_a: UncheckedAccount<'info>, + + /// CHECK: SPL interface PDA derived by light-token: ["pool", mint_b] + #[account(mut)] + pub spl_interface_pda_b: UncheckedAccount<'info>, +} diff --git a/programs/anchor/token-swap/src/instructions/withdraw_liquidity.rs b/programs/anchor/token-swap/src/instructions/withdraw_liquidity.rs new file mode 100644 index 0000000..a9a1e3c --- /dev/null +++ b/programs/anchor/token-swap/src/instructions/withdraw_liquidity.rs @@ -0,0 +1,241 @@ +use anchor_lang::prelude::*; +use fixed::types::I64F64; +use light_anchor_spl::token_interface::{self, Burn, Mint, TokenAccount, TokenInterface}; +use light_sdk::constants::LIGHT_TOKEN_PROGRAM_ID; +use light_token::instruction::{BurnCpi, RENT_SPONSOR}; +use light_token::spl_interface::find_spl_interface_pda; +use light_token::utils::get_token_account_balance; + +use crate::{ + constants::{AUTHORITY_SEED, MINIMUM_LIQUIDITY, POOL_ACCOUNT_A_SEED, POOL_ACCOUNT_B_SEED}, + errors::SwapError, + instructions::{transfer_tokens, SplInterfaceConfig}, + state::{Amm, Pool}, +}; + +pub fn withdraw_liquidity(ctx: Context, amount: u64) -> Result<()> { + let authority_bump = ctx.bumps.pool_authority; + let amm_key = ctx.accounts.pool.amm; + let mint_a_key = ctx.accounts.mint_a.key(); + let mint_b_key = ctx.accounts.mint_b.key(); + let authority_seeds: &[&[u8]] = &[ + amm_key.as_ref(), + mint_a_key.as_ref(), + mint_b_key.as_ref(), + AUTHORITY_SEED, + &[authority_bump], + ]; + + let is_light_lp = + ctx.accounts.liquidity_token_program.key().to_bytes() == LIGHT_TOKEN_PROGRAM_ID; + + let lp_supply = ctx.accounts.pool.lp_supply; + + let pool_a_balance = get_token_account_balance(&ctx.accounts.pool_account_a.to_account_info()) + .map_err(|_| anchor_lang::prelude::ProgramError::InvalidAccountData)?; + let pool_b_balance = get_token_account_balance(&ctx.accounts.pool_account_b.to_account_info()) + .map_err(|_| anchor_lang::prelude::ProgramError::InvalidAccountData)?; + + let amount_a = I64F64::from_num(amount) + .checked_mul(I64F64::from_num(pool_a_balance)) + .ok_or(SwapError::Overflow)? + .checked_div(I64F64::from_num(lp_supply + MINIMUM_LIQUIDITY)) + .ok_or(SwapError::Underflow)? + .floor() + .to_num::(); + + let (_, spl_interface_bump_a) = find_spl_interface_pda(&ctx.accounts.mint_a.key(), false); + let (_, spl_interface_bump_b) = find_spl_interface_pda(&ctx.accounts.mint_b.key(), false); + + let decimals_a = ctx.accounts.mint_a.decimals; + let spl_interface_a = SplInterfaceConfig { + mint: ctx.accounts.mint_a.to_account_info(), + spl_token_program: ctx.accounts.token_program.to_account_info(), + spl_interface_pda: ctx.accounts.spl_interface_pda_a.to_account_info(), + spl_interface_pda_bump: spl_interface_bump_a, + }; + transfer_tokens( + amount_a, + decimals_a, + ctx.accounts.pool_account_a.to_account_info(), + ctx.accounts.depositor_account_a.to_account_info(), + ctx.accounts.mint_a.to_account_info(), + ctx.accounts.pool_authority.to_account_info(), + ctx.accounts.payer.to_account_info(), + ctx.accounts.light_token_cpi_authority.to_account_info(), + ctx.accounts.system_program.to_account_info(), + Some(authority_seeds), + Some(spl_interface_a), + )?; + + let amount_b = I64F64::from_num(amount) + .checked_mul(I64F64::from_num(pool_b_balance)) + .ok_or(SwapError::Overflow)? + .checked_div(I64F64::from_num(lp_supply + MINIMUM_LIQUIDITY)) + .ok_or(SwapError::Underflow)? + .floor() + .to_num::(); + + let decimals_b = ctx.accounts.mint_b.decimals; + let spl_interface_b = SplInterfaceConfig { + mint: ctx.accounts.mint_b.to_account_info(), + spl_token_program: ctx.accounts.token_program.to_account_info(), + spl_interface_pda: ctx.accounts.spl_interface_pda_b.to_account_info(), + spl_interface_pda_bump: spl_interface_bump_b, + }; + transfer_tokens( + amount_b, + decimals_b, + ctx.accounts.pool_account_b.to_account_info(), + ctx.accounts.depositor_account_b.to_account_info(), + ctx.accounts.mint_b.to_account_info(), + ctx.accounts.pool_authority.to_account_info(), + ctx.accounts.payer.to_account_info(), + ctx.accounts.light_token_cpi_authority.to_account_info(), + ctx.accounts.system_program.to_account_info(), + Some(authority_seeds), + Some(spl_interface_b), + )?; + + if is_light_lp { + BurnCpi { + source: ctx.accounts.depositor_account_liquidity.to_account_info(), + mint: ctx.accounts.mint_liquidity.to_account_info(), + amount, + authority: ctx.accounts.depositor.to_account_info(), + system_program: ctx.accounts.system_program.to_account_info(), + max_top_up: None, + fee_payer: None, + } + .invoke()?; + } else { + token_interface::burn( + CpiContext::new( + ctx.accounts.liquidity_token_program.to_account_info(), + Burn { + mint: ctx.accounts.mint_liquidity.to_account_info(), + from: ctx.accounts.depositor_account_liquidity.to_account_info(), + authority: ctx.accounts.depositor.to_account_info(), + }, + ), + amount, + )?; + } + + ctx.accounts.pool.lp_supply = ctx + .accounts + .pool + .lp_supply + .checked_sub(amount) + .ok_or(SwapError::Underflow)?; + + Ok(()) +} + +#[derive(Accounts)] +pub struct WithdrawLiquidity<'info> { + #[account( + seeds = [ + amm.id.as_ref() + ], + bump, + )] + pub amm: Account<'info, Amm>, + + #[account( + mut, + seeds = [ + pool.amm.as_ref(), + pool.mint_a.key().as_ref(), + pool.mint_b.key().as_ref(), + ], + bump, + has_one = mint_a, + has_one = mint_b, + )] + pub pool: Account<'info, Pool>, + + /// CHECK: PDA verified by seeds constraint + #[account( + seeds = [ + pool.amm.as_ref(), + mint_a.key().as_ref(), + mint_b.key().as_ref(), + AUTHORITY_SEED, + ], + bump, + )] + pub pool_authority: AccountInfo<'info>, + + pub depositor: Signer<'info>, + + /// CHECK: Can be SPL, T22, or Light + #[account(mut)] + pub mint_liquidity: UncheckedAccount<'info>, + + #[account(mut, mint::token_program = token_program)] + pub mint_a: Box>, + + #[account(mut, mint::token_program = token_program)] + pub mint_b: Box>, + + /// CHECK: PDA verified by seeds constraint + #[account( + mut, + seeds = [POOL_ACCOUNT_A_SEED, pool.key().as_ref()], + bump, + )] + pub pool_account_a: UncheckedAccount<'info>, + + /// CHECK: PDA verified by seeds constraint + #[account( + mut, + seeds = [POOL_ACCOUNT_B_SEED, pool.key().as_ref()], + bump, + )] + pub pool_account_b: UncheckedAccount<'info>, + + /// CHECK: Can be SPL, T22, or Light + #[account(mut)] + pub depositor_account_liquidity: UncheckedAccount<'info>, + + #[account( + mut, + token::mint = mint_a, + token::authority = depositor, + )] + pub depositor_account_a: Box>, + + #[account( + mut, + token::mint = mint_b, + token::authority = depositor, + )] + pub depositor_account_b: Box>, + + #[account(mut)] + pub payer: Signer<'info>, + + /// Token program for mint_a and mint_b (SPL, T22, or Light). + pub token_program: Interface<'info, TokenInterface>, + /// Token program for LP mint (may differ from token_program). + pub liquidity_token_program: Interface<'info, TokenInterface>, + pub system_program: Program<'info, System>, + pub light_token_program: Interface<'info, TokenInterface>, + + /// CHECK: Validated by address constraint + #[account(mut, address = RENT_SPONSOR)] + pub light_token_rent_sponsor: AccountInfo<'info>, + + /// CHECK: Light token CPI authority + #[account(mut)] + pub light_token_cpi_authority: AccountInfo<'info>, + + /// CHECK: SPL interface PDA derived by light-token: ["pool", mint_a] + #[account(mut)] + pub spl_interface_pda_a: UncheckedAccount<'info>, + + /// CHECK: SPL interface PDA derived by light-token: ["pool", mint_b] + #[account(mut)] + pub spl_interface_pda_b: UncheckedAccount<'info>, +} diff --git a/programs/anchor/token-swap/src/lib.rs b/programs/anchor/token-swap/src/lib.rs new file mode 100644 index 0000000..9cddac6 --- /dev/null +++ b/programs/anchor/token-swap/src/lib.rs @@ -0,0 +1,64 @@ +#![allow(clippy::result_large_err)] + +use anchor_lang::prelude::*; +use light_token::anchor::{derive_light_cpi_signer, light_program, CpiSigner}; + +mod constants; +mod errors; +mod instructions; +mod state; + +pub use constants::{LP_MINT_SIGNER_SEED, POOL_ACCOUNT_A_SEED, POOL_ACCOUNT_B_SEED}; +pub use instructions::{CreatePoolLightLpParams, CreatePoolParams}; + +declare_id!("AsGVFxWqEn8icRBFQApxJe68x3r9zvfSbmiEzYFATGYn"); + +pub const LIGHT_CPI_SIGNER: CpiSigner = + derive_light_cpi_signer!("AsGVFxWqEn8icRBFQApxJe68x3r9zvfSbmiEzYFATGYn"); + +#[light_program] +#[allow(deprecated)] // Anchor's #[program] uses deprecated AccountInfo::realloc +#[program] +pub mod swap_example { + pub use super::instructions::*; + use super::*; + + pub fn create_amm(ctx: Context, id: Pubkey, fee: u16) -> Result<()> { + instructions::create_amm(ctx, id, fee) + } + + pub fn create_pool<'info>( + ctx: Context<'_, '_, '_, 'info, CreatePool<'info>>, + params: CreatePoolParams, + ) -> Result<()> { + instructions::create_pool(ctx, params) + } + + pub fn deposit_liquidity( + ctx: Context, + amount_a: u64, + amount_b: u64, + ) -> Result<()> { + instructions::deposit_liquidity(ctx, amount_a, amount_b) + } + + pub fn withdraw_liquidity(ctx: Context, amount: u64) -> Result<()> { + instructions::withdraw_liquidity(ctx, amount) + } + + pub fn swap_exact_tokens_for_tokens( + ctx: Context, + swap_a: bool, + input_amount: u64, + min_output_amount: u64, + ) -> Result<()> { + instructions::swap_exact_tokens_for_tokens(ctx, swap_a, input_amount, min_output_amount) + } + + pub fn create_pool_light_lp<'info>( + ctx: Context<'_, '_, '_, 'info, CreatePoolLightLp<'info>>, + params: CreatePoolLightLpParams, + ) -> Result<()> { + instructions::create_pool_light_lp(ctx, params) + } +} diff --git a/programs/anchor/token-swap/src/state.rs b/programs/anchor/token-swap/src/state.rs new file mode 100644 index 0000000..80f21b0 --- /dev/null +++ b/programs/anchor/token-swap/src/state.rs @@ -0,0 +1,28 @@ +use anchor_lang::prelude::*; + +#[account] +#[derive(Default)] +pub struct Amm { + pub id: Pubkey, + pub admin: Pubkey, + /// LP fee in basis points + pub fee: u16, +} + +impl Amm { + pub const LEN: usize = 8 + 32 + 32 + 2; +} + +#[account] +#[derive(Default)] +pub struct Pool { + pub amm: Pubkey, + pub mint_a: Pubkey, + pub mint_b: Pubkey, + /// Tracked on-chain for Light LP mint compatibility + pub lp_supply: u64, +} + +impl Pool { + pub const LEN: usize = 8 + 32 + 32 + 32 + 8; +} diff --git a/programs/anchor/token-swap/tests/common/mod.rs b/programs/anchor/token-swap/tests/common/mod.rs new file mode 100644 index 0000000..1e8b4b8 --- /dev/null +++ b/programs/anchor/token-swap/tests/common/mod.rs @@ -0,0 +1,1157 @@ +//! Common test utilities for token-swap AMM tests. +//! +//! This module provides shared test helpers for different token type combinations: +//! - SPL mint + SPL ATAs +//! - T22 mint + T22 ATAs +//! - SPL mint + Light user accounts +//! - T22 mint + Light user accounts +//! +//! Light mint + Light ATAs is not yet supported (requires Light mint creation). + +use anchor_lang::{InstructionData, ToAccountMetas}; +use anchor_spl::token; +use light_client::interface::{get_create_accounts_proof, CreateAccountsProofInput}; +use light_token::instruction::find_mint_address; +use shared_test_utils::{ + helpers::verify_light_token_balance, + light_tokens::{create_light_ata, create_light_mint, mint_light_tokens}, + setup::initialize_rent_free_config, + spl_interface::{create_spl_interface_pda, transfer_spl_to_light}, + spl_tokens::{create_spl_ata, create_spl_mint, mint_spl_tokens}, + t22_tokens::{create_t22_ata, create_t22_mint, mint_t22_tokens}, + CreateAccountsProofResult, Indexer, LightProgramTest, MintType, ProgramTestConfig, Rpc, + TestRpc, COMPRESSIBLE_CONFIG_V1, CPI_AUTHORITY_PDA, LIGHT_TOKEN_MINTER_PROGRAM_ID, + LIGHT_TOKEN_PROGRAM_ID, RENT_SPONSOR, +}; +use solana_instruction::Instruction; +use solana_keypair::Keypair; +use solana_pubkey::Pubkey; +use solana_signer::Signer; +use spl_token_2022::pod::PodAccount; + +/// Token configuration for parameterized tests. +/// +/// Some variants are used only in specific test files, so rustc warns about dead code. +/// The allow attribute suppresses these warnings across the shared test module. +#[allow(dead_code)] +#[derive(Clone, Copy, Debug)] +pub enum TokenConfig { + /// SPL mint + SPL ATAs + Spl, + /// T22 mint + T22 ATAs + Token2022, + /// SPL mint + Light user accounts (offchain SPL->Light conversion) + LightSpl, + /// T22 mint + Light user accounts (offchain T22->Light conversion) + LightT22, + /// Light mint + Light user accounts (pure Light-to-Light, SPL LP mint) + Light, + /// Full Light: Light mints + Light user accounts + Light LP mint + FullLight, +} + +impl TokenConfig { + pub fn mint_type(&self) -> MintType { + match self { + TokenConfig::Spl | TokenConfig::LightSpl => MintType::Spl, + TokenConfig::Token2022 | TokenConfig::LightT22 => MintType::Token2022, + // Light mints use SPL-compatible layout + TokenConfig::Light | TokenConfig::FullLight => MintType::Spl, + } + } + + pub fn token_program_id(&self) -> Pubkey { + match self { + TokenConfig::Spl | TokenConfig::LightSpl => token::ID, + TokenConfig::Token2022 | TokenConfig::LightT22 => spl_token_2022::ID, + TokenConfig::Light | TokenConfig::FullLight => { + Pubkey::new_from_array(LIGHT_TOKEN_PROGRAM_ID) + } + } + } + + /// Returns true if user accounts are Light token accounts + pub fn uses_light_user_accounts(&self) -> bool { + matches!( + self, + TokenConfig::LightSpl + | TokenConfig::LightT22 + | TokenConfig::Light + | TokenConfig::FullLight + ) + } + + /// Returns true if mints are Light Protocol mints (not SPL/T22) + pub fn uses_light_mints(&self) -> bool { + matches!(self, TokenConfig::Light | TokenConfig::FullLight) + } + + /// Returns true if LP mint is a Light Protocol mint + pub fn uses_light_lp_mint(&self) -> bool { + matches!(self, TokenConfig::FullLight) + } +} + +/// Context for AMM tests containing all necessary accounts +pub struct AmmTestContext { + pub program_id: Pubkey, + pub payer: Keypair, + pub mint_a_pubkey: Pubkey, + pub mint_b_pubkey: Pubkey, + pub amm_pda: Pubkey, + pub amm_id: Pubkey, + pub pool_pda: Pubkey, + pub pool_authority: Pubkey, + pub pool_authority_bump: u8, + pub mint_liquidity: Pubkey, + pub pool_account_a: Pubkey, + pub pool_account_b: Pubkey, + pub pool_a_bump: u8, + pub pool_b_bump: u8, + pub spl_interface_pda_a: Pubkey, + pub spl_interface_pda_b: Pubkey, + pub spl_interface_bump_a: u8, + pub depositor: Keypair, + pub depositor_ata_a: Pubkey, + pub depositor_ata_b: Pubkey, + pub token_config: TokenConfig, + /// Authority keypair for Light mint A (if Light config) + pub light_mint_authority_a: Option, + /// LP mint signer PDA (for FullLight config) + pub lp_mint_signer: Option, + pub lp_mint_signer_bump: u8, + /// Config PDA for rent-free light mint creation + pub compression_config: Pubkey, +} + +/// Create a new LightProgramTest instance for token-swap tests +pub async fn create_test_rpc() -> LightProgramTest { + let program_id = swap_example::ID; + let mut config = ProgramTestConfig::new_v2( + true, + Some(vec![ + ("swap_example", program_id), + ("light_token_minter", LIGHT_TOKEN_MINTER_PROGRAM_ID), + ]), + ); + config = config.with_light_protocol_events(); + LightProgramTest::new(config).await.unwrap() +} + +/// Setup the AMM test environment based on token config +pub async fn setup_amm_test( + rpc: &mut R, + config: TokenConfig, +) -> AmmTestContext { + let program_id = swap_example::ID; + let payer = rpc.get_payer().insecure_clone(); + + // Initialize rent-free config (returns the config PDA) + let compression_config = initialize_rent_free_config(rpc, &payer, &program_id).await; + + // Create depositor + let depositor = Keypair::new(); + rpc.airdrop_lamports(&depositor.pubkey(), 10_000_000_000) + .await + .unwrap(); + + // Token amount for depositor + let amount = 10_000_000_000_000u64; // 10,000 tokens with 9 decimals + + // For Light mints, we need to handle things differently + if config.uses_light_mints() { + // ========== LIGHT MINT SETUP ========== + println!("\n=== Setting up Light mints ==="); + + // Create Light mints + let light_mint_a = + create_light_mint(rpc, &payer, 9, "Token A", "TOKA", &compression_config).await; + let light_mint_b = + create_light_mint(rpc, &payer, 9, "Token B", "TOKB", &compression_config).await; + + let mint_a_pubkey = light_mint_a.mint; + let mint_b_pubkey = light_mint_b.mint; + + println!("Light Mint A: {:?}", mint_a_pubkey); + println!("Light Mint B: {:?}", mint_b_pubkey); + + // For pure Light-to-Light, we don't need SPL interface PDAs + // Use dummy pubkeys (these won't be used) + let spl_interface_pda_a = Pubkey::default(); + let spl_interface_pda_b = Pubkey::default(); + + // Mint Light tokens directly to depositor + println!("\n=== Minting Light tokens to depositor ==="); + let depositor_ata_a = mint_light_tokens( + rpc, + &payer, + &light_mint_a.authority, + &mint_a_pubkey, + &depositor.pubkey(), + amount, + ) + .await; + let depositor_ata_b = mint_light_tokens( + rpc, + &payer, + &light_mint_b.authority, + &mint_b_pubkey, + &depositor.pubkey(), + amount, + ) + .await; + + // Derive AMM PDA + let amm_id = Pubkey::new_unique(); + let (amm_pda, _) = Pubkey::find_program_address(&[amm_id.as_ref()], &program_id); + + // Derive pool PDAs using Light mint pubkeys + let (pool_pda, _) = Pubkey::find_program_address( + &[ + amm_pda.as_ref(), + mint_a_pubkey.as_ref(), + mint_b_pubkey.as_ref(), + ], + &program_id, + ); + + let (pool_authority, pool_authority_bump) = Pubkey::find_program_address( + &[ + amm_pda.as_ref(), + mint_a_pubkey.as_ref(), + mint_b_pubkey.as_ref(), + b"authority", + ], + &program_id, + ); + + let (pool_account_a, pool_a_bump) = + Pubkey::find_program_address(&[b"pool_a", pool_pda.as_ref()], &program_id); + let (pool_account_b, pool_b_bump) = + Pubkey::find_program_address(&[b"pool_b", pool_pda.as_ref()], &program_id); + + // For Light config: SPL LP mint derived normally + // For FullLight config: Light LP mint derived from lp_mint_signer + let (mint_liquidity, lp_mint_signer, lp_mint_signer_bump) = if config.uses_light_lp_mint() { + // FullLight: derive LP mint signer and Light LP mint + let (lp_mint_signer, lp_mint_signer_bump) = + Pubkey::find_program_address(&[b"lp_mint_signer", pool_pda.as_ref()], &program_id); + let (light_lp_mint, _) = find_mint_address(&lp_mint_signer); + (light_lp_mint, Some(lp_mint_signer), lp_mint_signer_bump) + } else { + // Light (non-FullLight): SPL LP mint + let (mint_liquidity, _) = Pubkey::find_program_address( + &[ + amm_pda.as_ref(), + mint_a_pubkey.as_ref(), + mint_b_pubkey.as_ref(), + b"liquidity", + ], + &program_id, + ); + (mint_liquidity, None, 0) + }; + + return AmmTestContext { + program_id, + payer, + mint_a_pubkey, + mint_b_pubkey, + amm_pda, + amm_id, + pool_pda, + pool_authority, + pool_authority_bump, + mint_liquidity, + pool_account_a, + pool_account_b, + pool_a_bump, + pool_b_bump, + spl_interface_pda_a, + spl_interface_pda_b, + spl_interface_bump_a: 0, + depositor, + depositor_ata_a, + depositor_ata_b, + token_config: config, + light_mint_authority_a: Some(light_mint_a.authority), + lp_mint_signer, + lp_mint_signer_bump, + compression_config, + }; + } + + // ========== SPL/T22 MINT SETUP ========== + // Create mints based on config (SPL or T22 - Light user accounts still use SPL/T22 mints) + let (mint_a, mint_b) = match config { + TokenConfig::Spl | TokenConfig::LightSpl => { + let mint_a = create_spl_mint(rpc, &payer, &payer.pubkey(), 9).await; + let mint_b = create_spl_mint(rpc, &payer, &payer.pubkey(), 9).await; + (mint_a, mint_b) + } + TokenConfig::Token2022 | TokenConfig::LightT22 => { + let mint_a = create_t22_mint(rpc, &payer, &payer.pubkey(), 9).await; + let mint_b = create_t22_mint(rpc, &payer, &payer.pubkey(), 9).await; + (mint_a, mint_b) + } + TokenConfig::Light | TokenConfig::FullLight => { + unreachable!("Light/FullLight config handled above") + } + }; + + let mint_a_pubkey = mint_a.pubkey(); + let mint_b_pubkey = mint_b.pubkey(); + + println!("Mint A: {:?}", mint_a_pubkey); + println!("Mint B: {:?}", mint_b_pubkey); + + // Create SPL interface PDAs for both mints + println!("\n=== Creating SPL interface PDAs ==="); + let spl_interface_result_a = + create_spl_interface_pda(rpc, &payer, &mint_a_pubkey, config.mint_type(), false).await; + let spl_interface_result_b = + create_spl_interface_pda(rpc, &payer, &mint_b_pubkey, config.mint_type(), false).await; + + // Create depositor ATAs and mint tokens based on config + let (depositor_ata_a, depositor_ata_b) = match config { + TokenConfig::Spl => { + let ata_a = create_spl_ata(rpc, &payer, &mint_a_pubkey, &depositor.pubkey()).await; + let ata_b = create_spl_ata(rpc, &payer, &mint_b_pubkey, &depositor.pubkey()).await; + mint_spl_tokens(rpc, &payer, &mint_a_pubkey, &ata_a, &payer, amount).await; + mint_spl_tokens(rpc, &payer, &mint_b_pubkey, &ata_b, &payer, amount).await; + (ata_a, ata_b) + } + TokenConfig::Token2022 => { + let ata_a = create_t22_ata(rpc, &payer, &mint_a_pubkey, &depositor.pubkey()).await; + let ata_b = create_t22_ata(rpc, &payer, &mint_b_pubkey, &depositor.pubkey()).await; + mint_t22_tokens(rpc, &payer, &mint_a_pubkey, &ata_a, &payer, amount).await; + mint_t22_tokens(rpc, &payer, &mint_b_pubkey, &ata_b, &payer, amount).await; + (ata_a, ata_b) + } + TokenConfig::LightSpl => { + // For Light user accounts with SPL mint: + // 1. Create temporary SPL ATAs + // 2. Mint tokens to temp ATAs + // 3. Create Light ATAs + // 4. Transfer from SPL to Light (compress) + println!("\n=== Setting up Light user accounts (SPL mint) ==="); + + let temp_ata_a = create_spl_ata(rpc, &payer, &mint_a_pubkey, &depositor.pubkey()).await; + let temp_ata_b = create_spl_ata(rpc, &payer, &mint_b_pubkey, &depositor.pubkey()).await; + mint_spl_tokens(rpc, &payer, &mint_a_pubkey, &temp_ata_a, &payer, amount).await; + mint_spl_tokens(rpc, &payer, &mint_b_pubkey, &temp_ata_b, &payer, amount).await; + + // Create Light ATAs + let light_ata_a = + create_light_ata(rpc, &payer, &mint_a_pubkey, &depositor.pubkey()).await; + let light_ata_b = + create_light_ata(rpc, &payer, &mint_b_pubkey, &depositor.pubkey()).await; + + // Transfer from SPL to Light (compress) + transfer_spl_to_light( + rpc, + &payer, + &depositor, + &mint_a_pubkey, + 9, + &temp_ata_a, + &light_ata_a, + &spl_interface_result_a.pda, + spl_interface_result_a.bump, + amount, + MintType::Spl, + ) + .await; + transfer_spl_to_light( + rpc, + &payer, + &depositor, + &mint_b_pubkey, + 9, + &temp_ata_b, + &light_ata_b, + &spl_interface_result_b.pda, + spl_interface_result_b.bump, + amount, + MintType::Spl, + ) + .await; + + (light_ata_a, light_ata_b) + } + TokenConfig::LightT22 => { + // For Light user accounts with T22 mint: + println!("\n=== Setting up Light user accounts (T22 mint) ==="); + + let temp_ata_a = create_t22_ata(rpc, &payer, &mint_a_pubkey, &depositor.pubkey()).await; + let temp_ata_b = create_t22_ata(rpc, &payer, &mint_b_pubkey, &depositor.pubkey()).await; + mint_t22_tokens(rpc, &payer, &mint_a_pubkey, &temp_ata_a, &payer, amount).await; + mint_t22_tokens(rpc, &payer, &mint_b_pubkey, &temp_ata_b, &payer, amount).await; + + // Create Light ATAs + let light_ata_a = + create_light_ata(rpc, &payer, &mint_a_pubkey, &depositor.pubkey()).await; + let light_ata_b = + create_light_ata(rpc, &payer, &mint_b_pubkey, &depositor.pubkey()).await; + + // Transfer from T22 to Light (compress) + transfer_spl_to_light( + rpc, + &payer, + &depositor, + &mint_a_pubkey, + 9, + &temp_ata_a, + &light_ata_a, + &spl_interface_result_a.pda, + spl_interface_result_a.bump, + amount, + MintType::Token2022, + ) + .await; + transfer_spl_to_light( + rpc, + &payer, + &depositor, + &mint_b_pubkey, + 9, + &temp_ata_b, + &light_ata_b, + &spl_interface_result_b.pda, + spl_interface_result_b.bump, + amount, + MintType::Token2022, + ) + .await; + + (light_ata_a, light_ata_b) + } + TokenConfig::Light | TokenConfig::FullLight => { + unreachable!("Light/FullLight config handled above") + } + }; + + // Derive AMM PDA + let amm_id = Pubkey::new_unique(); + let (amm_pda, _) = Pubkey::find_program_address(&[amm_id.as_ref()], &program_id); + + // Derive pool PDAs + let (pool_pda, _) = Pubkey::find_program_address( + &[ + amm_pda.as_ref(), + mint_a_pubkey.as_ref(), + mint_b_pubkey.as_ref(), + ], + &program_id, + ); + + let (pool_authority, pool_authority_bump) = Pubkey::find_program_address( + &[ + amm_pda.as_ref(), + mint_a_pubkey.as_ref(), + mint_b_pubkey.as_ref(), + b"authority", + ], + &program_id, + ); + + let (mint_liquidity, _) = Pubkey::find_program_address( + &[ + amm_pda.as_ref(), + mint_a_pubkey.as_ref(), + mint_b_pubkey.as_ref(), + b"liquidity", + ], + &program_id, + ); + + let (pool_account_a, pool_a_bump) = + Pubkey::find_program_address(&[b"pool_a", pool_pda.as_ref()], &program_id); + let (pool_account_b, pool_b_bump) = + Pubkey::find_program_address(&[b"pool_b", pool_pda.as_ref()], &program_id); + + AmmTestContext { + program_id, + payer, + mint_a_pubkey, + mint_b_pubkey, + amm_pda, + amm_id, + pool_pda, + pool_authority, + pool_authority_bump, + mint_liquidity, + pool_account_a, + pool_account_b, + pool_a_bump, + pool_b_bump, + spl_interface_pda_a: spl_interface_result_a.pda, + spl_interface_pda_b: spl_interface_result_b.pda, + spl_interface_bump_a: spl_interface_result_a.bump, + depositor, + depositor_ata_a, + depositor_ata_b, + token_config: config, + light_mint_authority_a: None, + lp_mint_signer: None, + lp_mint_signer_bump: 0, + compression_config, + } +} + +/// Create AMM +pub async fn create_amm(rpc: &mut R, ctx: &AmmTestContext, fee: u16) { + println!("\n=== Creating AMM ==="); + + let create_amm_accounts = swap_example::accounts::CreateAmm { + amm: ctx.amm_pda, + admin: ctx.payer.pubkey(), + payer: ctx.payer.pubkey(), + system_program: solana_sdk::system_program::ID, + }; + + let create_amm_data = swap_example::instruction::CreateAmm { + id: ctx.amm_id, + fee, + }; + + let create_amm_ix = Instruction { + program_id: ctx.program_id, + accounts: create_amm_accounts.to_account_metas(None), + data: create_amm_data.data(), + }; + + rpc.create_and_send_transaction(&[create_amm_ix], &ctx.payer.pubkey(), &[&ctx.payer]) + .await + .expect("create_amm should succeed"); + + println!("AMM created at: {:?}", ctx.amm_pda); + println!("AMM Fee: {} basis points", fee); +} + +/// Create Pool with Light token accounts +pub async fn create_pool( + rpc: &mut R, + ctx: &AmmTestContext, + proof_result: CreateAccountsProofResult, +) { + println!("\n=== Creating Pool ==="); + + // For liquidity mint, use SPL for Light pools (can't init Light mints via Anchor) + // For SPL/T22 pools, use the same token program as the mints + // FullLight uses create_pool_light_lp instruction instead + let liquidity_token_program = match ctx.token_config { + TokenConfig::Light | TokenConfig::LightSpl => token::ID, + TokenConfig::Token2022 | TokenConfig::LightT22 => spl_token_2022::ID, + TokenConfig::Spl => token::ID, + TokenConfig::FullLight => Pubkey::new_from_array(LIGHT_TOKEN_PROGRAM_ID), + }; + + let create_pool_accounts = swap_example::accounts::CreatePool { + amm: ctx.amm_pda, + pool: ctx.pool_pda, + pool_authority: ctx.pool_authority, + mint_liquidity: ctx.mint_liquidity, + mint_a: ctx.mint_a_pubkey, + mint_b: ctx.mint_b_pubkey, + pool_account_a: ctx.pool_account_a, + pool_account_b: ctx.pool_account_b, + fee_payer: ctx.payer.pubkey(), + token_program: ctx.token_config.token_program_id(), + liquidity_token_program, + light_token_program: Pubkey::new_from_array(LIGHT_TOKEN_PROGRAM_ID), + system_program: solana_sdk::system_program::ID, + light_token_compressible_config: COMPRESSIBLE_CONFIG_V1, + light_token_rent_sponsor: RENT_SPONSOR, + light_token_cpi_authority: CPI_AUTHORITY_PDA, + }; + + let create_pool_data = swap_example::instruction::CreatePool { + params: swap_example::CreatePoolParams { + create_accounts_proof: proof_result.create_accounts_proof, + pool_account_a_bump: ctx.pool_a_bump, + pool_account_b_bump: ctx.pool_b_bump, + }, + }; + + let create_pool_ix = Instruction { + program_id: ctx.program_id, + accounts: [ + create_pool_accounts.to_account_metas(None), + proof_result.remaining_accounts, + ] + .concat(), + data: create_pool_data.data(), + }; + + rpc.create_and_send_transaction(&[create_pool_ix], &ctx.payer.pubkey(), &[&ctx.payer]) + .await + .expect("create_pool should succeed"); + + println!("Pool created successfully!"); +} + +/// Create Pool with Light LP mint (for FullLight config) +pub async fn create_pool_light_lp( + rpc: &mut R, + ctx: &AmmTestContext, + proof_result: CreateAccountsProofResult, +) { + println!("\n=== Creating Pool with Light LP mint ==="); + + let lp_mint_signer = ctx + .lp_mint_signer + .expect("FullLight config should have lp_mint_signer"); + + let create_pool_accounts = swap_example::accounts::CreatePoolLightLp { + amm: ctx.amm_pda, + pool: ctx.pool_pda, + pool_authority: ctx.pool_authority, + lp_mint_signer, + mint_liquidity: ctx.mint_liquidity, + mint_a: ctx.mint_a_pubkey, + mint_b: ctx.mint_b_pubkey, + pool_vault_a: ctx.pool_account_a, + pool_vault_b: ctx.pool_account_b, + fee_payer: ctx.payer.pubkey(), + token_program: ctx.token_config.token_program_id(), + compression_config: ctx.compression_config, + light_token_compressible_config: COMPRESSIBLE_CONFIG_V1, + light_token_rent_sponsor: RENT_SPONSOR, + light_token_program: Pubkey::new_from_array(LIGHT_TOKEN_PROGRAM_ID), + light_token_cpi_authority: CPI_AUTHORITY_PDA, + system_program: solana_sdk::system_program::ID, + }; + + let create_pool_data = swap_example::instruction::CreatePoolLightLp { + params: swap_example::CreatePoolLightLpParams { + create_accounts_proof: proof_result.create_accounts_proof, + pool_account_a_bump: ctx.pool_a_bump, + pool_account_b_bump: ctx.pool_b_bump, + lp_mint_signer_bump: ctx.lp_mint_signer_bump, + pool_authority_bump: ctx.pool_authority_bump, + }, + }; + + let create_pool_ix = Instruction { + program_id: ctx.program_id, + accounts: [ + create_pool_accounts.to_account_metas(None), + proof_result.remaining_accounts, + ] + .concat(), + data: create_pool_data.data(), + }; + + rpc.create_and_send_transaction(&[create_pool_ix], &ctx.payer.pubkey(), &[&ctx.payer]) + .await + .expect("create_pool_light_lp should succeed"); + + println!("Pool with Light LP mint created successfully!"); +} + +/// Deposit liquidity +pub async fn deposit_liquidity( + rpc: &mut R, + ctx: &AmmTestContext, + amount_a: u64, + amount_b: u64, +) -> Pubkey { + println!("\n=== Depositing Liquidity ==="); + + let token_program = ctx.token_config.token_program_id(); + + // Liquidity mint is SPL for Light/LightSpl pools, T22 for T22/LightT22 pools, SPL for Spl pools + // FullLight uses Light token program for LP mint + let liquidity_token_program = match ctx.token_config { + TokenConfig::Light | TokenConfig::LightSpl | TokenConfig::Spl => token::ID, + TokenConfig::Token2022 | TokenConfig::LightT22 => spl_token_2022::ID, + TokenConfig::FullLight => Pubkey::new_from_array(LIGHT_TOKEN_PROGRAM_ID), + }; + + // Create the liquidity ATA first (since program no longer does init_if_needed) + // For FullLight, LP mint is a Light mint created via create_pool_light_lp + let depositor_liquidity_ata = match ctx.token_config { + TokenConfig::Spl | TokenConfig::LightSpl | TokenConfig::Light => { + // SPL liquidity mint + create_spl_ata( + rpc, + &ctx.payer, + &ctx.mint_liquidity, + &ctx.depositor.pubkey(), + ) + .await + } + TokenConfig::Token2022 | TokenConfig::LightT22 => { + // T22 liquidity mint + create_t22_ata( + rpc, + &ctx.payer, + &ctx.mint_liquidity, + &ctx.depositor.pubkey(), + ) + .await + } + TokenConfig::FullLight => { + // Light LP mint - create Light ATA + create_light_ata( + rpc, + &ctx.payer, + &ctx.mint_liquidity, + &ctx.depositor.pubkey(), + ) + .await + } + }; + + let deposit_accounts = swap_example::accounts::DepositLiquidity { + pool: ctx.pool_pda, + pool_authority: ctx.pool_authority, + depositor: ctx.depositor.pubkey(), + mint_liquidity: ctx.mint_liquidity, + mint_a: ctx.mint_a_pubkey, + mint_b: ctx.mint_b_pubkey, + pool_account_a: ctx.pool_account_a, + pool_account_b: ctx.pool_account_b, + depositor_account_liquidity: depositor_liquidity_ata, + depositor_account_a: ctx.depositor_ata_a, + depositor_account_b: ctx.depositor_ata_b, + payer: ctx.payer.pubkey(), + token_program, + liquidity_token_program, + system_program: solana_sdk::system_program::ID, + light_token_program: Pubkey::new_from_array(LIGHT_TOKEN_PROGRAM_ID), + light_token_rent_sponsor: RENT_SPONSOR, + light_token_cpi_authority: CPI_AUTHORITY_PDA, + spl_interface_pda_a: ctx.spl_interface_pda_a, + spl_interface_pda_b: ctx.spl_interface_pda_b, + }; + + let deposit_data = swap_example::instruction::DepositLiquidity { amount_a, amount_b }; + + let deposit_ix = Instruction { + program_id: ctx.program_id, + accounts: deposit_accounts.to_account_metas(None), + data: deposit_data.data(), + }; + + rpc.create_and_send_transaction( + &[deposit_ix], + &ctx.payer.pubkey(), + &[&ctx.payer, &ctx.depositor], + ) + .await + .expect("deposit_liquidity should succeed"); + + println!("Deposited {} token A and {} token B", amount_a, amount_b); + + depositor_liquidity_ata +} + +/// Perform swap A->B or B->A +pub async fn swap( + rpc: &mut R, + ctx: &AmmTestContext, + trader: &Keypair, + trader_ata_a: Pubkey, + trader_ata_b: Pubkey, + swap_a: bool, + input_amount: u64, + min_output: u64, +) { + let direction = if swap_a { "A->B" } else { "B->A" }; + println!("\n=== Swapping {} ===", direction); + + let token_program = ctx.token_config.token_program_id(); + + let swap_accounts = swap_example::accounts::SwapExactTokensForTokens { + amm: ctx.amm_pda, + pool: ctx.pool_pda, + pool_authority: ctx.pool_authority, + trader: trader.pubkey(), + mint_a: ctx.mint_a_pubkey, + mint_b: ctx.mint_b_pubkey, + pool_account_a: ctx.pool_account_a, + pool_account_b: ctx.pool_account_b, + trader_account_a: trader_ata_a, + trader_account_b: trader_ata_b, + payer: ctx.payer.pubkey(), + token_program, + system_program: solana_sdk::system_program::ID, + light_token_program: Pubkey::new_from_array(LIGHT_TOKEN_PROGRAM_ID), + light_token_rent_sponsor: RENT_SPONSOR, + light_token_cpi_authority: CPI_AUTHORITY_PDA, + spl_interface_pda_a: ctx.spl_interface_pda_a, + spl_interface_pda_b: ctx.spl_interface_pda_b, + }; + + let swap_data = swap_example::instruction::SwapExactTokensForTokens { + swap_a, + input_amount, + min_output_amount: min_output, + }; + + let swap_ix = Instruction { + program_id: ctx.program_id, + accounts: swap_accounts.to_account_metas(None), + data: swap_data.data(), + }; + + rpc.create_and_send_transaction(&[swap_ix], &ctx.payer.pubkey(), &[&ctx.payer, trader]) + .await + .expect(&format!("swap {} should succeed", direction)); + + println!("Swapped {} of input token", input_amount); +} + +/// Withdraw liquidity +pub async fn withdraw_liquidity( + rpc: &mut R, + ctx: &AmmTestContext, + depositor_liquidity_ata: Pubkey, + amount: u64, +) { + println!("\n=== Withdrawing Liquidity ==="); + + let token_program = ctx.token_config.token_program_id(); + + // Liquidity mint is SPL for Light/LightSpl pools, T22 for T22/LightT22 pools, SPL for Spl pools + // FullLight uses Light token program for LP mint + let liquidity_token_program = match ctx.token_config { + TokenConfig::Light | TokenConfig::LightSpl | TokenConfig::Spl => token::ID, + TokenConfig::Token2022 | TokenConfig::LightT22 => spl_token_2022::ID, + TokenConfig::FullLight => Pubkey::new_from_array(LIGHT_TOKEN_PROGRAM_ID), + }; + + let withdraw_accounts = swap_example::accounts::WithdrawLiquidity { + amm: ctx.amm_pda, + pool: ctx.pool_pda, + pool_authority: ctx.pool_authority, + depositor: ctx.depositor.pubkey(), + mint_liquidity: ctx.mint_liquidity, + mint_a: ctx.mint_a_pubkey, + mint_b: ctx.mint_b_pubkey, + pool_account_a: ctx.pool_account_a, + pool_account_b: ctx.pool_account_b, + depositor_account_liquidity: depositor_liquidity_ata, + depositor_account_a: ctx.depositor_ata_a, + depositor_account_b: ctx.depositor_ata_b, + payer: ctx.payer.pubkey(), + token_program, + liquidity_token_program, + system_program: solana_sdk::system_program::ID, + light_token_program: Pubkey::new_from_array(LIGHT_TOKEN_PROGRAM_ID), + light_token_rent_sponsor: RENT_SPONSOR, + light_token_cpi_authority: CPI_AUTHORITY_PDA, + spl_interface_pda_a: ctx.spl_interface_pda_a, + spl_interface_pda_b: ctx.spl_interface_pda_b, + }; + + let withdraw_data = swap_example::instruction::WithdrawLiquidity { amount }; + + let withdraw_ix = Instruction { + program_id: ctx.program_id, + accounts: withdraw_accounts.to_account_metas(None), + data: withdraw_data.data(), + }; + + rpc.create_and_send_transaction( + &[withdraw_ix], + &ctx.payer.pubkey(), + &[&ctx.payer, &ctx.depositor], + ) + .await + .expect("withdraw_liquidity should succeed"); + + println!("Withdrew {} LP tokens", amount); +} + +/// Create a trader with token accounts and funded tokens +pub async fn create_trader( + rpc: &mut R, + ctx: &AmmTestContext, + initial_a: u64, +) -> (Keypair, Pubkey, Pubkey) { + let trader = Keypair::new(); + rpc.airdrop_lamports(&trader.pubkey(), 5_000_000_000) + .await + .unwrap(); + + let (trader_ata_a, trader_ata_b) = match ctx.token_config { + TokenConfig::Spl => { + let ata_a = create_spl_ata(rpc, &ctx.payer, &ctx.mint_a_pubkey, &trader.pubkey()).await; + let ata_b = create_spl_ata(rpc, &ctx.payer, &ctx.mint_b_pubkey, &trader.pubkey()).await; + // Mint initial token A to trader + mint_spl_tokens( + rpc, + &ctx.payer, + &ctx.mint_a_pubkey, + &ata_a, + &ctx.payer, + initial_a, + ) + .await; + (ata_a, ata_b) + } + TokenConfig::Token2022 => { + let ata_a = create_t22_ata(rpc, &ctx.payer, &ctx.mint_a_pubkey, &trader.pubkey()).await; + let ata_b = create_t22_ata(rpc, &ctx.payer, &ctx.mint_b_pubkey, &trader.pubkey()).await; + // Mint initial token A to trader + mint_t22_tokens( + rpc, + &ctx.payer, + &ctx.mint_a_pubkey, + &ata_a, + &ctx.payer, + initial_a, + ) + .await; + (ata_a, ata_b) + } + TokenConfig::LightSpl => { + // For Light user accounts with SPL mint: + // 1. Create temp SPL ATAs, mint, then transfer to Light ATAs + let temp_ata_a = + create_spl_ata(rpc, &ctx.payer, &ctx.mint_a_pubkey, &trader.pubkey()).await; + let _temp_ata_b = + create_spl_ata(rpc, &ctx.payer, &ctx.mint_b_pubkey, &trader.pubkey()).await; + + // Mint initial token A to trader temp ATA + mint_spl_tokens( + rpc, + &ctx.payer, + &ctx.mint_a_pubkey, + &temp_ata_a, + &ctx.payer, + initial_a, + ) + .await; + + // Create Light ATAs + let light_ata_a = + create_light_ata(rpc, &ctx.payer, &ctx.mint_a_pubkey, &trader.pubkey()).await; + let light_ata_b = + create_light_ata(rpc, &ctx.payer, &ctx.mint_b_pubkey, &trader.pubkey()).await; + + // Transfer from SPL to Light (compress) + transfer_spl_to_light( + rpc, + &ctx.payer, + &trader, + &ctx.mint_a_pubkey, + 9, + &temp_ata_a, + &light_ata_a, + &ctx.spl_interface_pda_a, + ctx.spl_interface_bump_a, + initial_a, + MintType::Spl, + ) + .await; + + (light_ata_a, light_ata_b) + } + TokenConfig::LightT22 => { + // For Light user accounts with T22 mint: + let temp_ata_a = + create_t22_ata(rpc, &ctx.payer, &ctx.mint_a_pubkey, &trader.pubkey()).await; + let _temp_ata_b = + create_t22_ata(rpc, &ctx.payer, &ctx.mint_b_pubkey, &trader.pubkey()).await; + + // Mint initial token A to trader temp ATA + mint_t22_tokens( + rpc, + &ctx.payer, + &ctx.mint_a_pubkey, + &temp_ata_a, + &ctx.payer, + initial_a, + ) + .await; + + // Create Light ATAs + let light_ata_a = + create_light_ata(rpc, &ctx.payer, &ctx.mint_a_pubkey, &trader.pubkey()).await; + let light_ata_b = + create_light_ata(rpc, &ctx.payer, &ctx.mint_b_pubkey, &trader.pubkey()).await; + + // Transfer from T22 to Light (compress) + transfer_spl_to_light( + rpc, + &ctx.payer, + &trader, + &ctx.mint_a_pubkey, + 9, + &temp_ata_a, + &light_ata_a, + &ctx.spl_interface_pda_a, + ctx.spl_interface_bump_a, + initial_a, + MintType::Token2022, + ) + .await; + + (light_ata_a, light_ata_b) + } + TokenConfig::Light | TokenConfig::FullLight => { + // For pure Light mints (Light and FullLight): + // Mint directly to trader's Light ATAs using the Light mint authority + let mint_authority_a = ctx + .light_mint_authority_a + .as_ref() + .expect("Light/FullLight config should have mint authority A"); + + // Mint token A to trader + let light_ata_a = mint_light_tokens( + rpc, + &ctx.payer, + mint_authority_a, + &ctx.mint_a_pubkey, + &trader.pubkey(), + initial_a, + ) + .await; + + // Create Light ATA for token B (no minting needed initially) + let light_ata_b = + create_light_ata(rpc, &ctx.payer, &ctx.mint_b_pubkey, &trader.pubkey()).await; + + (light_ata_a, light_ata_b) + } + }; + + (trader, trader_ata_a, trader_ata_b) +} + +/// Get token balance from SPL/T22 account +pub async fn get_token_balance(rpc: &mut R, account: Pubkey) -> u64 { + let account_data = rpc + .get_account(account) + .await + .unwrap() + .expect("Token account should exist"); + + let token_state = + spl_pod::bytemuck::pod_from_bytes::(&account_data.data[..165]).unwrap(); + u64::from(token_state.amount) +} + +/// Run the full AMM flow test +pub async fn run_amm_full_flow(rpc: &mut R, ctx: &AmmTestContext) { + // Create AMM + create_amm(rpc, ctx, 250).await; // 2.5% fee + + // Get proof inputs - order must match #[light_account(init, ...)] order in instruction struct + // For FullLight: only mint_liquidity (token accounts created via explicit CPI) + // For others: pool_account_a, pool_account_b (created via macro) + let proof_inputs = if ctx.token_config.uses_light_lp_mint() { + let lp_mint_signer = ctx + .lp_mint_signer + .expect("FullLight config should have lp_mint_signer"); + vec![ + CreateAccountsProofInput::mint(lp_mint_signer), // mint_liquidity only + ] + } else { + vec![ + CreateAccountsProofInput::pda(ctx.pool_account_a), + CreateAccountsProofInput::pda(ctx.pool_account_b), + ] + }; + + let proof_result = get_create_accounts_proof(rpc, &ctx.program_id, proof_inputs) + .await + .unwrap(); + + // Create Pool - use create_pool_light_lp for FullLight config + if ctx.token_config.uses_light_lp_mint() { + create_pool_light_lp(rpc, ctx, proof_result).await; + } else { + create_pool(rpc, ctx, proof_result).await; + } + + // Fund pool_authority for Light-to-Light transfers (rent top-ups) + // The pool_authority needs lamports to pay for rent top-ups when transferring + // from pool accounts to user accounts during swap/withdraw operations + if ctx.token_config.uses_light_user_accounts() { + rpc.airdrop_lamports(&ctx.pool_authority, 1_000_000_000) + .await + .expect("Fund pool_authority for rent top-ups"); + println!("Funded pool_authority with 1 SOL for rent top-ups"); + } + + // Verify initial pool balances + verify_light_token_balance(rpc, ctx.pool_account_a, 0, "pool_account_a (initial)").await; + verify_light_token_balance(rpc, ctx.pool_account_b, 0, "pool_account_b (initial)").await; + + // Deposit initial liquidity + let deposit_amount = 1_000_000_000u64; // 1 token + let depositor_liquidity_ata = deposit_liquidity(rpc, ctx, deposit_amount, deposit_amount).await; + + // Verify pool balances after deposit + verify_light_token_balance( + rpc, + ctx.pool_account_a, + deposit_amount, + "pool_account_a (after deposit)", + ) + .await; + verify_light_token_balance( + rpc, + ctx.pool_account_b, + deposit_amount, + "pool_account_b (after deposit)", + ) + .await; + + // Create trader and perform swaps + let trader_initial_a = 100_000_000u64; // 0.1 tokens + let (trader, trader_ata_a, trader_ata_b) = create_trader(rpc, ctx, trader_initial_a).await; + + // Swap A -> B + let swap_input = 10_000_000u64; // 0.01 tokens + swap( + rpc, + ctx, + &trader, + trader_ata_a, + trader_ata_b, + true, + swap_input, + 1, + ) + .await; + + // Verify trader got some token B + let trader_b_balance = get_token_balance(rpc, trader_ata_b).await; + assert!(trader_b_balance > 0, "Trader should have received token B"); + println!("Trader token B after swap: {}", trader_b_balance); + + // Swap B -> A (swap half back) + let swap_b_input = trader_b_balance / 2; + swap( + rpc, + ctx, + &trader, + trader_ata_a, + trader_ata_b, + false, + swap_b_input, + 1, + ) + .await; + + // Withdraw half of LP tokens + let lp_balance = get_token_balance(rpc, depositor_liquidity_ata).await; + let withdraw_amount = lp_balance / 2; + withdraw_liquidity(rpc, ctx, depositor_liquidity_ata, withdraw_amount).await; + + // Verify LP tokens were burned + let lp_balance_after = get_token_balance(rpc, depositor_liquidity_ata).await; + assert_eq!( + lp_balance_after, + lp_balance - withdraw_amount, + "LP tokens should be burned" + ); + + println!("\n=== AMM full flow test completed successfully! ==="); +} diff --git a/programs/anchor/token-swap/tests/user_light.rs b/programs/anchor/token-swap/tests/user_light.rs new file mode 100644 index 0000000..5f34a65 --- /dev/null +++ b/programs/anchor/token-swap/tests/user_light.rs @@ -0,0 +1,31 @@ +//! Integration tests for the token-swap AMM program with Light mints and Light ATAs. +//! +//! Token Configuration: +//! - Mint Type: Light (via CreateMint instruction) +//! - User Accounts: Light token accounts +//! - Pool Accounts: Light Protocol token accounts +//! +//! This is the pure Light-to-Light test where everything uses light tokens. + +mod common; + +use common::{create_amm, create_test_rpc, run_amm_full_flow, setup_amm_test, TokenConfig}; + +#[tokio::test] +async fn test_amm_full_flow_light() { + let mut rpc = create_test_rpc().await; + let ctx = setup_amm_test(&mut rpc, TokenConfig::Light).await; + run_amm_full_flow(&mut rpc, &ctx).await; +} + +#[tokio::test] +async fn test_create_amm_light() { + let mut rpc = create_test_rpc().await; + let ctx = setup_amm_test(&mut rpc, TokenConfig::Light).await; + + // Create AMM with 0% fee + create_amm(&mut rpc, &ctx, 0).await; + + println!("AMM with 0% fee created successfully"); + println!("=== Initialize AMM test completed successfully! ==="); +} diff --git a/programs/anchor/token-swap/tests/user_light_full.rs b/programs/anchor/token-swap/tests/user_light_full.rs new file mode 100644 index 0000000..ddaa901 --- /dev/null +++ b/programs/anchor/token-swap/tests/user_light_full.rs @@ -0,0 +1,33 @@ +//! Integration tests for the token-swap AMM program with full Light configuration. +//! +//! Token Configuration: +//! - Mint Type: Light (via CreateMint instruction) +//! - User Accounts: Light token accounts +//! - Pool Accounts: Light Protocol token accounts +//! - LP Mint: Light (via create_pool_light_lp instruction) +//! +//! This is the complete Light-to-Light test where everything including the LP mint +//! uses light tokens. + +mod common; + +use common::{create_amm, create_test_rpc, run_amm_full_flow, setup_amm_test, TokenConfig}; + +#[tokio::test] +async fn test_amm_full_flow_full_light() { + let mut rpc = create_test_rpc().await; + let ctx = setup_amm_test(&mut rpc, TokenConfig::FullLight).await; + run_amm_full_flow(&mut rpc, &ctx).await; +} + +#[tokio::test] +async fn test_create_amm_full_light() { + let mut rpc = create_test_rpc().await; + let ctx = setup_amm_test(&mut rpc, TokenConfig::FullLight).await; + + // Create AMM with 0% fee + create_amm(&mut rpc, &ctx, 0).await; + + println!("AMM with 0% fee created successfully"); + println!("=== Initialize AMM (FullLight) test completed successfully! ==="); +} diff --git a/programs/anchor/token-swap/tests/user_spl.rs b/programs/anchor/token-swap/tests/user_spl.rs new file mode 100644 index 0000000..7e5cdb3 --- /dev/null +++ b/programs/anchor/token-swap/tests/user_spl.rs @@ -0,0 +1,31 @@ +//! Integration tests for the token-swap AMM program with SPL mints and SPL ATAs. +//! +//! Token Configuration: +//! - Mint Type: SPL (token::ID) +//! - User Accounts: SPL ATAs +//! - Pool Accounts: Light Protocol token accounts + +mod common; + +use common::{create_test_rpc, run_amm_full_flow, setup_amm_test, TokenConfig}; + +/// Test the full AMM flow with SPL tokens +#[tokio::test] +async fn test_amm_full_flow_spl() { + let mut rpc = create_test_rpc().await; + let ctx = setup_amm_test(&mut rpc, TokenConfig::Spl).await; + run_amm_full_flow(&mut rpc, &ctx).await; +} + +/// Test AMM creation with various fee values using SPL tokens +#[tokio::test] +async fn test_create_amm_spl() { + use common::{create_amm, setup_amm_test}; + + let mut rpc = create_test_rpc().await; + let ctx = setup_amm_test(&mut rpc, TokenConfig::Spl).await; + + // Create AMM with 0% fee + create_amm(&mut rpc, &ctx, 0).await; + println!("AMM with 0% fee created successfully"); +} diff --git a/programs/anchor/token-swap/tests/user_spl_light.rs b/programs/anchor/token-swap/tests/user_spl_light.rs new file mode 100644 index 0000000..ecf6990 --- /dev/null +++ b/programs/anchor/token-swap/tests/user_spl_light.rs @@ -0,0 +1,25 @@ +//! Integration tests for the token-swap AMM program with SPL mints and Light user accounts. +//! +//! Token Configuration: +//! - Mint Type: SPL (token::ID) +//! - User Accounts: Light token accounts (offchain SPL->Light conversion before program interaction) +//! - Pool Accounts: Light Protocol token accounts +//! +//! Test Flow: +//! 1. Create SPL mint and temporary SPL ATA +//! 2. Mint tokens to temporary ATA +//! 3. Create Light token account for user +//! 4. Create SPL interface PDA +//! 5. Transfer from SPL ATA to Light account (offchain conversion using `transfer_spl_to_light`) +//! 6. User has Light account with tokens - interact with program using Light-to-Light + +mod common; + +use common::{create_test_rpc, run_amm_full_flow, setup_amm_test, TokenConfig}; + +#[tokio::test] +async fn test_amm_full_flow_light_spl() { + let mut rpc = create_test_rpc().await; + let ctx = setup_amm_test(&mut rpc, TokenConfig::LightSpl).await; + run_amm_full_flow(&mut rpc, &ctx).await; +} diff --git a/programs/anchor/token-swap/tests/user_t22.rs b/programs/anchor/token-swap/tests/user_t22.rs new file mode 100644 index 0000000..5b4448b --- /dev/null +++ b/programs/anchor/token-swap/tests/user_t22.rs @@ -0,0 +1,31 @@ +//! Integration tests for the token-swap AMM program with Token-2022 mints and T22 ATAs. +//! +//! Token Configuration: +//! - Mint Type: Token-2022 (spl_token_2022::ID) +//! - User Accounts: Token-2022 ATAs +//! - Pool Accounts: Light Protocol token accounts + +mod common; + +use common::{create_test_rpc, run_amm_full_flow, setup_amm_test, TokenConfig}; + +/// Test the full AMM flow with Token-2022 tokens +#[tokio::test] +async fn test_amm_full_flow_t22() { + let mut rpc = create_test_rpc().await; + let ctx = setup_amm_test(&mut rpc, TokenConfig::Token2022).await; + run_amm_full_flow(&mut rpc, &ctx).await; +} + +/// Test AMM creation with various fee values using Token-2022 tokens +#[tokio::test] +async fn test_create_amm_t22() { + use common::{create_amm, setup_amm_test}; + + let mut rpc = create_test_rpc().await; + let ctx = setup_amm_test(&mut rpc, TokenConfig::Token2022).await; + + // Create AMM with 2.5% fee + create_amm(&mut rpc, &ctx, 250).await; + println!("AMM with 2.5% fee created successfully"); +} diff --git a/programs/anchor/token-swap/tests/user_t22_light.rs b/programs/anchor/token-swap/tests/user_t22_light.rs new file mode 100644 index 0000000..ed13969 --- /dev/null +++ b/programs/anchor/token-swap/tests/user_t22_light.rs @@ -0,0 +1,25 @@ +//! Integration tests for the token-swap AMM program with T22 mints and Light user accounts. +//! +//! Token Configuration: +//! - Mint Type: Token-2022 (spl_token_2022::ID) +//! - User Accounts: Light token accounts (offchain T22->Light conversion before program interaction) +//! - Pool Accounts: Light Protocol token accounts +//! +//! Test Flow: +//! 1. Create T22 mint and temporary T22 ATA +//! 2. Mint tokens to temporary ATA +//! 3. Create Light token account for user +//! 4. Create SPL interface PDA (works with T22) +//! 5. Transfer from T22 ATA to Light account (offchain conversion using `transfer_spl_to_light`) +//! 6. User has Light account with tokens - interact with program using Light-to-Light + +mod common; + +use common::{create_test_rpc, run_amm_full_flow, setup_amm_test, TokenConfig}; + +#[tokio::test] +async fn test_amm_full_flow_light_t22() { + let mut rpc = create_test_rpc().await; + let ctx = setup_amm_test(&mut rpc, TokenConfig::LightT22).await; + run_amm_full_flow(&mut rpc, &ctx).await; +} diff --git a/toolkits/payments-and-wallets/README.md b/toolkits/payments-and-wallets/README.md index db6cc1b..5738e4b 100644 --- a/toolkits/payments-and-wallets/README.md +++ b/toolkits/payments-and-wallets/README.md @@ -56,5 +56,5 @@ pnpm run unwrap ## Documentation -Learn more [about to Light-Token here](https://www.zkcompression.com/light-token/welcome). +Learn more [about Light-Token here](https://www.zkcompression.com/light-token/welcome). diff --git a/toolkits/streaming-tokens/README.mdx b/toolkits/streaming-tokens/README.mdx index a71b1a3..a7c2f38 100644 --- a/toolkits/streaming-tokens/README.mdx +++ b/toolkits/streaming-tokens/README.mdx @@ -385,7 +385,7 @@ impl BorshDeserialize for BaseMint { # Indexing Markets -cToken accounts follow the same layout as SPL-token accounts, so you can reuse your existing parsers. +Light token accounts follow the same layout as SPL-token accounts, so you can reuse your existing parsers. They include an extra compressible extension, which can be safely ignored. diff --git a/typescript-client/README.md b/typescript-client/README.md index 782bde4..6391d66 100644 --- a/typescript-client/README.md +++ b/typescript-client/README.md @@ -56,4 +56,4 @@ npm run load-ata:instruction ## Documentation -Learn more [about to Light-Token here](https://www.zkcompression.com/light-token/welcome). +Learn more [about Light-Token here](https://www.zkcompression.com/light-token/welcome). From edfb6f75d1c0289db3a349cc0016b302ef76f399 Mon Sep 17 00:00:00 2001 From: tilo-14 Date: Fri, 6 Feb 2026 21:30:40 +0000 Subject: [PATCH 02/10] add clarification --- CLAUDE.md | 149 ++++++++++++++++ programs/anchor/escrow/tests/common/mod.rs | 159 +++++++++++++----- .../anchor/token-swap/tests/common/mod.rs | 104 +++++++++--- 3 files changed, 355 insertions(+), 57 deletions(-) create mode 100644 CLAUDE.md diff --git a/CLAUDE.md b/CLAUDE.md new file mode 100644 index 0000000..1b3cec6 --- /dev/null +++ b/CLAUDE.md @@ -0,0 +1,149 @@ +# CLAUDE.md + +This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository. + +## Overview + +Light Token examples repository demonstrating rent-free token accounts on Solana. Light Token reduces mint and token account costs by 200x by having the Light Token program sponsor rent-exemption. Light accounts can hold balances from Light, SPL, and Token-2022 mints. + +## Build and Test Commands + +### Anchor Programs (from `programs/anchor/`) + +```bash +# Build all programs +anchor build + +# Test individual programs +cargo test-sbf -p escrow +cargo test-sbf -p fundraiser +cargo test-sbf -p light-token-minter +cargo test-sbf -p swap_example + +# Run a single test function +cargo test-sbf -p escrow -- test_escrow_light_full_flow +``` + +### TypeScript Client (from `typescript-client/`) + +```bash +npm install + +# Run all tests (requires light test-validator) +npm run test:all + +# Run specific categories +npm run test:actions +npm run test:instructions + +# Run individual examples +npm run create-mint:action +npm run mint-to:instruction +# See package.json for all scripts +``` + +### Local Test Validator + +```bash +# Start Light test validator (blocks terminal) +light test-validator + +# TypeScript tests require validator running with Photon indexer +``` + +## Requirements + +- Rust 1.90.0 (pinned in `programs/anchor/rust-toolchain.toml`) +- Solana CLI 2.3.11+ +- Anchor 0.31.1 +- Node 22 +- Light CLI: `npm i -g @lightprotocol/zk-compression-cli@alpha` + +## Repository Structure + +``` +programs/anchor/ # Anchor Solana programs +├── escrow/ # Peer-to-peer Light Token swap (make/take offer) +├── fundraiser/ # Token fundraiser with target, deadline, refunds +├── light-token-minter/ # Create light-mints with metadata +├── token-swap/ # AMM with liquidity pools +└── shared-test-utils/ # Common test infrastructure (all programs depend on this) + +typescript-client/ # TypeScript SDK examples +├── actions/ # High-level convenience functions +└── instructions/ # Low-level instruction builders +``` + +## Program Architecture + +Programs use Light Protocol's compressed account model: + +- `#[light_program]` macro enables Light account support +- `derive_light_cpi_signer!` generates CPI signer for Light operations +- `get_create_accounts_proof()` fetches ZK proofs for account creation + +### Light Protocol Integration Pattern + +```rust +// 1. Derive CPI signer from program ID +pub const LIGHT_CPI_SIGNER: CpiSigner = derive_light_cpi_signer!("ProgramId..."); + +// 2. Use #[light_program] before #[program] +#[light_program] +#[program] +pub mod my_program { ... } + +// 3. Initialize rent-free config in tests +let config = initialize_rent_free_config(rpc, &payer, &program_id).await; +``` + +## Test Architecture + +### Test File Naming Convention + +Each program tests five token type combinations: + +| File suffix | Mint type | User accounts | Description | +| ----------------- | ---------- | ------------- | -------------------------- | +| `*_spl.rs` | SPL | SPL ATAs | Standard SPL tokens | +| `*_t22.rs` | Token-2022 | T22 ATAs | Token-2022 tokens | +| `*_light.rs` | Light mint | Light ATAs | Pure Light-to-Light | +| `*_spl_light.rs` | SPL | Light ATAs | SPL mint → Light accounts | +| `*_t22_light.rs` | Token-2022 | Light ATAs | T22 mint → Light accounts | + +### TokenConfig Enum + +Tests use `TokenConfig` to parameterize behavior: + +```rust +pub enum TokenConfig { + Spl, // SPL mint + SPL ATAs + Token2022, // T22 mint + T22 ATAs + Light, // Light mint + Light ATAs + LightSpl, // SPL mint + Light ATAs (requires SPL interface PDA) + LightT22, // T22 mint + Light ATAs (requires SPL interface PDA) +} +``` + +### Shared Test Utilities + +`shared-test-utils` provides reusable helpers organized by token type: + +- `spl_tokens::` - Create SPL mints, ATAs, mint tokens +- `t22_tokens::` - Create Token-2022 mints, ATAs, mint tokens +- `light_tokens::` - Create Light mints, ATAs, mint tokens +- `spl_interface::` - SPL interface PDAs for cross-standard transfers +- `helpers::` - Balance verification, proof helpers + +Each program's `tests/common/mod.rs` builds on these utilities for program-specific test context. + +## TypeScript Pattern + +- **Actions**: Complete operations with connection handling (`actions/*.ts`) +- **Instructions**: Instruction builders for custom transaction composition (`instructions/*.ts`) + +Both patterns support Light Token, SPL, and Token-2022 interoperability. + +## Environment + +For devnet testing, copy `.env.example` to `.env` and set `API_KEY`. diff --git a/programs/anchor/escrow/tests/common/mod.rs b/programs/anchor/escrow/tests/common/mod.rs index 07ebe02..65f43be 100644 --- a/programs/anchor/escrow/tests/common/mod.rs +++ b/programs/anchor/escrow/tests/common/mod.rs @@ -7,6 +7,10 @@ //! - T22 mint + Light user accounts //! - Light mint + Light user accounts +// ============================================================================ +// Imports +// ============================================================================ + use anchor_lang::{InstructionData, ToAccountMetas}; use anchor_spl::token; use shared_test_utils::{ @@ -26,6 +30,10 @@ use solana_keypair::Keypair; use solana_pubkey::Pubkey; use solana_signer::Signer; +// ============================================================================ +// Token Configuration +// ============================================================================ + /// Token configuration for parameterized tests #[allow(dead_code)] #[derive(Clone, Copy, Debug)] @@ -73,6 +81,10 @@ impl TokenConfig { } } +// ============================================================================ +// Test Context +// ============================================================================ + /// Context for escrow tests containing all necessary accounts #[allow(dead_code)] pub struct EscrowTestContext { @@ -99,6 +111,10 @@ pub struct EscrowTestContext { pub authority_pda: Pubkey, } +// ============================================================================ +// Setup Functions +// ============================================================================ + /// Create a new LightProgramTest instance for escrow tests pub async fn create_test_rpc() -> LightProgramTest { let program_id = escrow::ID; @@ -233,6 +249,10 @@ pub async fn setup_escrow_test( } } +// ============================================================================ +// Token Account Creation +// ============================================================================ + /// Create a token account for a participant for a specific mint. /// /// When `funding_amount > 0`, mints tokens to the account. @@ -364,6 +384,10 @@ pub async fn create_token_account( } } +// ============================================================================ +// Instruction Execution +// ============================================================================ + /// Execute make_offer instruction. Returns (offer_pda, vault_pda, vault_bump). pub async fn execute_make_offer( rpc: &mut R, @@ -373,6 +397,7 @@ pub async fn execute_make_offer( token_a_offered_amount: u64, token_b_wanted_amount: u64, ) -> (Pubkey, Pubkey, u8) { + // Step 1: Derive offer PDA from maker + offer_id let (offer_pda, _) = Pubkey::find_program_address( &[ escrow::OFFER_SEED, @@ -382,10 +407,11 @@ pub async fn execute_make_offer( &ctx.program_id, ); + // Step 2: Derive vault PDA from offer PDA let (vault_pda, vault_bump) = Pubkey::find_program_address(&[escrow::VAULT_SEED, offer_pda.as_ref()], &ctx.program_id); - // Get proof for creating the offer account + // Step 3: Get proof for creating the offer account (light-PDA) let proof_result = get_create_accounts_proof( rpc, &ctx.program_id, @@ -394,6 +420,9 @@ pub async fn execute_make_offer( .await .unwrap(); + // Step 4: Build make_offer instruction + // - Transfers token_a from maker to vault + // - Creates offer account with escrow terms let accounts = escrow::accounts::MakeOffer { fee_payer: ctx.maker.pubkey(), authority: ctx.authority_pda, @@ -446,6 +475,11 @@ pub async fn execute_make_offer( } /// Execute take_offer instruction. +/// +/// The program performs these steps: +/// 1. Send wanted tokens from taker to maker (send_wanted_tokens_to_maker) +/// 2. Withdraw offered tokens from vault to taker (withdraw_from_vault) +/// 3. Close vault account (close_vault) pub async fn execute_take_offer( rpc: &mut R, ctx: &EscrowTestContext, @@ -455,6 +489,7 @@ pub async fn execute_take_offer( taker_ata_b: Pubkey, maker_ata_b: Pubkey, ) { + // Build take_offer instruction let accounts = escrow::accounts::TakeOffer { taker: ctx.taker.pubkey(), maker: ctx.maker.pubkey(), @@ -498,31 +533,40 @@ pub async fn execute_take_offer( println!("take_offer executed"); } +// ============================================================================ +// Full Flow Tests +// ============================================================================ + /// Run the full escrow flow: setup accounts, make_offer, take_offer, verify balances. pub async fn run_escrow_full_flow( rpc: &mut R, ctx: &EscrowTestContext, ) { - let token_a_amount = 1_000_000_000u64; // 1 token with 9 decimals - let token_b_amount = 500_000_000u64; // 0.5 tokens - - // Create token accounts for maker and taker + // ==================== PHASE 1: Define Escrow Terms ==================== + // Maker offers 1 token A, wants 0.5 token B in return + let token_a_offered = 1_000_000_000u64; // 1 token (9 decimals) + let token_b_wanted = 500_000_000u64; // 0.5 tokens + let offer_id = 1u64; + + // ==================== PHASE 2: Create Token Accounts ==================== + // Maker needs: funded token A account, empty token B account (receives payment) + // Taker needs: empty token A account (receives offered tokens), funded token B account println!("\n=== Creating token accounts ==="); - // Maker's token A account (funded) - let maker_ata_a = create_token_account( + // Maker's token A account (funded with tokens to offer) + let maker_token_a = create_token_account( rpc, ctx, &ctx.maker, &ctx.mint_a_pubkey, ctx.light_mint_a_authority.as_ref(), ctx.spl_interface_a.as_ref(), - token_a_amount, + token_a_offered, ) .await; - // Maker's token B account (unfunded, receives from taker) - let maker_ata_b = create_token_account( + // Maker's token B account (empty, will receive payment from taker) + let maker_token_b = create_token_account( rpc, ctx, &ctx.maker, @@ -533,8 +577,8 @@ pub async fn run_escrow_full_flow( ) .await; - // Taker's token A account (unfunded, receives from vault) - let taker_ata_a = create_token_account( + // Taker's token A account (empty, will receive offered tokens from vault) + let taker_token_a = create_token_account( rpc, ctx, &ctx.taker, @@ -545,40 +589,54 @@ pub async fn run_escrow_full_flow( ) .await; - // Taker's token B account (funded) - let taker_ata_b = create_token_account( + // Taker's token B account (funded with tokens to pay maker) + let taker_token_b = create_token_account( rpc, ctx, &ctx.taker, &ctx.mint_b_pubkey, ctx.light_mint_b_authority.as_ref(), ctx.spl_interface_b.as_ref(), - token_b_amount, + token_b_wanted, ) .await; - // Verify initial balances + // ==================== PHASE 3: Verify Initial State ==================== + let maker_a_before = token_a_offered; + let maker_b_before = 0u64; + let taker_a_before = 0u64; + let taker_b_before = token_b_wanted; + println!("\n=== Verifying initial balances ==="); - verify_light_token_balance(rpc, maker_ata_a, token_a_amount, "maker_ata_a").await; - verify_light_token_balance(rpc, maker_ata_b, 0, "maker_ata_b").await; - verify_light_token_balance(rpc, taker_ata_a, 0, "taker_ata_a").await; - verify_light_token_balance(rpc, taker_ata_b, token_b_amount, "taker_ata_b").await; + verify_light_token_balance(rpc, maker_token_a, maker_a_before, "maker_token_a (initial)") + .await; + verify_light_token_balance(rpc, maker_token_b, maker_b_before, "maker_token_b (initial)") + .await; + verify_light_token_balance(rpc, taker_token_a, taker_a_before, "taker_token_a (initial)") + .await; + verify_light_token_balance(rpc, taker_token_b, taker_b_before, "taker_token_b (initial)") + .await; - // === MAKE OFFER === + // ==================== PHASE 4: Make Offer ==================== + // Step 4a: Derive PDAs for offer and vault + // Step 4b: Get proof for creating compressed offer account + // Step 4c: Transfer offered tokens from maker to vault + // Step 4d: Save offer details to offer account println!("\n=== Executing make_offer ==="); let (offer_pda, vault_pda, _) = execute_make_offer( rpc, ctx, - 1, // offer_id - maker_ata_a, - token_a_amount, - token_b_amount, + offer_id, + maker_token_a, + token_a_offered, + token_b_wanted, ) .await; - // Verify vault was created and funded - verify_light_token_balance(rpc, vault_pda, token_a_amount, "vault (after make_offer)").await; - verify_light_token_balance(rpc, maker_ata_a, 0, "maker_ata_a (after make_offer)").await; + // ==================== PHASE 5: Verify Offer State ==================== + // Vault should hold offered tokens, maker's account should be empty + verify_light_token_balance(rpc, vault_pda, token_a_offered, "vault (after make_offer)").await; + verify_light_token_balance(rpc, maker_token_a, 0, "maker_token_a (after make_offer)").await; // Verify offer account was created let offer_account = rpc @@ -586,19 +644,41 @@ pub async fn run_escrow_full_flow( .await .unwrap() .expect("Offer account should exist"); - assert!(!offer_account.data.is_empty(), "Offer account should have data"); + assert!( + !offer_account.data.is_empty(), + "Offer account should have data" + ); - // === TAKE OFFER === + // ==================== PHASE 6: Take Offer ==================== + // Step 6a: Taker sends wanted tokens (B) to maker + // Step 6b: Vault releases offered tokens (A) to taker + // Step 6c: Close vault and offer accounts println!("\n=== Executing take_offer ==="); - execute_take_offer(rpc, ctx, offer_pda, vault_pda, taker_ata_a, taker_ata_b, maker_ata_b) - .await; + execute_take_offer( + rpc, + ctx, + offer_pda, + vault_pda, + taker_token_a, + taker_token_b, + maker_token_b, + ) + .await; - // === VERIFY FINAL BALANCES === + // ==================== PHASE 7: Verify Final State ==================== + // Maker: gave token A, received token B + // Taker: gave token B, received token A println!("\n=== Verifying final balances ==="); - verify_light_token_balance(rpc, maker_ata_a, 0, "maker_ata_a (final)").await; - verify_light_token_balance(rpc, maker_ata_b, token_b_amount, "maker_ata_b (final)").await; - verify_light_token_balance(rpc, taker_ata_a, token_a_amount, "taker_ata_a (final)").await; - verify_light_token_balance(rpc, taker_ata_b, 0, "taker_ata_b (final)").await; + + let maker_a_after = 0u64; + let maker_b_after = token_b_wanted; + let taker_a_after = token_a_offered; + let taker_b_after = 0u64; + + verify_light_token_balance(rpc, maker_token_a, maker_a_after, "maker_token_a (final)").await; + verify_light_token_balance(rpc, maker_token_b, maker_b_after, "maker_token_b (final)").await; + verify_light_token_balance(rpc, taker_token_a, taker_a_after, "taker_token_a (final)").await; + verify_light_token_balance(rpc, taker_token_b, taker_b_after, "taker_token_b (final)").await; // Verify offer account was closed let offer_after = rpc.get_account(offer_pda).await.unwrap(); @@ -608,7 +688,10 @@ pub async fn run_escrow_full_flow( ); println!("Offer account closed"); - println!("\n=== Escrow full flow completed ==="); + println!( + "\n=== Escrow completed: Maker exchanged {} token_a for {} token_b ===", + token_a_offered, token_b_wanted + ); } /// Run make_offer only (for setup verification tests). diff --git a/programs/anchor/token-swap/tests/common/mod.rs b/programs/anchor/token-swap/tests/common/mod.rs index 1e8b4b8..dfe8620 100644 --- a/programs/anchor/token-swap/tests/common/mod.rs +++ b/programs/anchor/token-swap/tests/common/mod.rs @@ -8,6 +8,10 @@ //! //! Light mint + Light ATAs is not yet supported (requires Light mint creation). +// ============================================================================ +// Imports +// ============================================================================ + use anchor_lang::{InstructionData, ToAccountMetas}; use anchor_spl::token; use light_client::interface::{get_create_accounts_proof, CreateAccountsProofInput}; @@ -29,6 +33,10 @@ use solana_pubkey::Pubkey; use solana_signer::Signer; use spl_token_2022::pod::PodAccount; +// ============================================================================ +// Token Configuration +// ============================================================================ + /// Token configuration for parameterized tests. /// /// Some variants are used only in specific test files, so rustc warns about dead code. @@ -92,6 +100,10 @@ impl TokenConfig { } } +// ============================================================================ +// Test Context +// ============================================================================ + /// Context for AMM tests containing all necessary accounts pub struct AmmTestContext { pub program_id: Pubkey, @@ -124,6 +136,10 @@ pub struct AmmTestContext { pub compression_config: Pubkey, } +// ============================================================================ +// Setup Functions +// ============================================================================ + /// Create a new LightProgramTest instance for token-swap tests pub async fn create_test_rpc() -> LightProgramTest { let program_id = swap_example::ID; @@ -163,7 +179,8 @@ pub async fn setup_amm_test( // ========== LIGHT MINT SETUP ========== println!("\n=== Setting up Light mints ==="); - // Create Light mints + // Step 1: Create Light mints with metadata + // Light mints are rent-free and include on-chain metadata let light_mint_a = create_light_mint(rpc, &payer, 9, "Token A", "TOKA", &compression_config).await; let light_mint_b = @@ -175,12 +192,13 @@ pub async fn setup_amm_test( println!("Light Mint A: {:?}", mint_a_pubkey); println!("Light Mint B: {:?}", mint_b_pubkey); - // For pure Light-to-Light, we don't need SPL interface PDAs - // Use dummy pubkeys (these won't be used) + // Step 2: Skip SPL interface PDAs for pure Light-to-Light + // These are only needed for wrapping SPL/T22 tokens let spl_interface_pda_a = Pubkey::default(); let spl_interface_pda_b = Pubkey::default(); - // Mint Light tokens directly to depositor + // Step 3: Mint Light tokens directly to depositor + // Creates Light ATA and mints in one operation println!("\n=== Minting Light tokens to depositor ==="); let depositor_ata_a = mint_light_tokens( rpc, @@ -201,11 +219,11 @@ pub async fn setup_amm_test( ) .await; - // Derive AMM PDA + // Step 4: Derive AMM PDA let amm_id = Pubkey::new_unique(); let (amm_pda, _) = Pubkey::find_program_address(&[amm_id.as_ref()], &program_id); - // Derive pool PDAs using Light mint pubkeys + // Step 5: Derive pool PDAs using Light mint pubkeys let (pool_pda, _) = Pubkey::find_program_address( &[ amm_pda.as_ref(), @@ -230,8 +248,9 @@ pub async fn setup_amm_test( let (pool_account_b, pool_b_bump) = Pubkey::find_program_address(&[b"pool_b", pool_pda.as_ref()], &program_id); - // For Light config: SPL LP mint derived normally - // For FullLight config: Light LP mint derived from lp_mint_signer + // Step 6: Derive LP mint address + // Light config: SPL LP mint derived normally + // FullLight config: Light LP mint derived from lp_mint_signer PDA let (mint_liquidity, lp_mint_signer, lp_mint_signer_bump) = if config.uses_light_lp_mint() { // FullLight: derive LP mint signer and Light LP mint let (lp_mint_signer, lp_mint_signer_bump) = @@ -499,10 +518,18 @@ pub async fn setup_amm_test( } } -/// Create AMM +// ============================================================================ +// Instruction Execution +// ============================================================================ + +/// Create AMM with specified fee structure. +/// +/// The AMM (Automated Market Maker) is the parent entity that defines +/// fee parameters for all pools created under it. pub async fn create_amm(rpc: &mut R, ctx: &AmmTestContext, fee: u16) { println!("\n=== Creating AMM ==="); + // Step 1: Build create_amm instruction let create_amm_accounts = swap_example::accounts::CreateAmm { amm: ctx.amm_pda, admin: ctx.payer.pubkey(), @@ -529,7 +556,10 @@ pub async fn create_amm(rpc: &mut R, ctx: &AmmTestContext, fee: u16) { println!("AMM Fee: {} basis points", fee); } -/// Create Pool with Light token accounts +/// Create Pool with Light token accounts. +/// +/// Creates a liquidity pool for token pair A/B under the AMM. +/// Pool vaults (pool_account_a, pool_account_b) are Light token accounts. pub async fn create_pool( rpc: &mut R, ctx: &AmmTestContext, @@ -537,6 +567,7 @@ pub async fn create_pool( ) { println!("\n=== Creating Pool ==="); + // Step 1: Determine LP mint token program // For liquidity mint, use SPL for Light pools (can't init Light mints via Anchor) // For SPL/T22 pools, use the same token program as the mints // FullLight uses create_pool_light_lp instruction instead @@ -591,7 +622,10 @@ pub async fn create_pool( println!("Pool created successfully!"); } -/// Create Pool with Light LP mint (for FullLight config) +/// Create Pool with Light LP mint (for FullLight config). +/// +/// Similar to create_pool but creates the LP mint as a Light mint +/// instead of SPL/T22 mint, enabling fully rent-free pool operations. pub async fn create_pool_light_lp( rpc: &mut R, ctx: &AmmTestContext, @@ -599,6 +633,7 @@ pub async fn create_pool_light_lp( ) { println!("\n=== Creating Pool with Light LP mint ==="); + // Step 1: Get LP mint signer PDA (used to derive Light LP mint address) let lp_mint_signer = ctx .lp_mint_signer .expect("FullLight config should have lp_mint_signer"); @@ -650,7 +685,10 @@ pub async fn create_pool_light_lp( println!("Pool with Light LP mint created successfully!"); } -/// Deposit liquidity +/// Deposit liquidity to pool. +/// +/// Transfers token A and B from depositor to pool vaults. +/// Mints LP tokens to depositor proportional to deposit amount. pub async fn deposit_liquidity( rpc: &mut R, ctx: &AmmTestContext, @@ -659,6 +697,7 @@ pub async fn deposit_liquidity( ) -> Pubkey { println!("\n=== Depositing Liquidity ==="); + // Step 1: Determine token programs for underlying and LP tokens let token_program = ctx.token_config.token_program_id(); // Liquidity mint is SPL for Light/LightSpl pools, T22 for T22/LightT22 pools, SPL for Spl pools @@ -748,7 +787,10 @@ pub async fn deposit_liquidity( depositor_liquidity_ata } -/// Perform swap A->B or B->A +/// Perform swap A->B or B->A. +/// +/// Swaps input tokens for output tokens using constant-product formula. +/// Fee is deducted from output amount based on AMM fee setting. pub async fn swap( rpc: &mut R, ctx: &AmmTestContext, @@ -759,9 +801,11 @@ pub async fn swap( input_amount: u64, min_output: u64, ) { + // Step 1: Determine swap direction let direction = if swap_a { "A->B" } else { "B->A" }; println!("\n=== Swapping {} ===", direction); + // Step 2: Build swap instruction let token_program = ctx.token_config.token_program_id(); let swap_accounts = swap_example::accounts::SwapExactTokensForTokens { @@ -804,7 +848,10 @@ pub async fn swap( println!("Swapped {} of input token", input_amount); } -/// Withdraw liquidity +/// Withdraw liquidity from pool. +/// +/// Burns LP tokens from depositor and returns proportional share +/// of token A and B from pool vaults. pub async fn withdraw_liquidity( rpc: &mut R, ctx: &AmmTestContext, @@ -813,6 +860,7 @@ pub async fn withdraw_liquidity( ) { println!("\n=== Withdrawing Liquidity ==="); + // Step 1: Determine token programs for underlying and LP tokens let token_program = ctx.token_config.token_program_id(); // Liquidity mint is SPL for Light/LightSpl pools, T22 for T22/LightT22 pools, SPL for Spl pools @@ -866,6 +914,10 @@ pub async fn withdraw_liquidity( println!("Withdrew {} LP tokens", amount); } +// ============================================================================ +// Helper Functions +// ============================================================================ + /// Create a trader with token accounts and funded tokens pub async fn create_trader( rpc: &mut R, @@ -1036,11 +1088,18 @@ pub async fn get_token_balance(rpc: &mut R, account: Pubkey) -> u64 { u64::from(token_state.amount) } +// ============================================================================ +// Full Flow Tests +// ============================================================================ + /// Run the full AMM flow test pub async fn run_amm_full_flow(rpc: &mut R, ctx: &AmmTestContext) { - // Create AMM + // ==================== PHASE 1: Create AMM ==================== + // AMM defines fee structure for all pools create_amm(rpc, ctx, 250).await; // 2.5% fee + // ==================== PHASE 2: Create Pool ==================== + // Pool holds liquidity for token pair A/B // Get proof inputs - order must match #[light_account(init, ...)] order in instruction struct // For FullLight: only mint_liquidity (token accounts created via explicit CPI) // For others: pool_account_a, pool_account_b (created via macro) @@ -1083,7 +1142,8 @@ pub async fn run_amm_full_flow(rpc: &mut R, ctx: &AmmTestConte verify_light_token_balance(rpc, ctx.pool_account_a, 0, "pool_account_a (initial)").await; verify_light_token_balance(rpc, ctx.pool_account_b, 0, "pool_account_b (initial)").await; - // Deposit initial liquidity + // ==================== PHASE 3: Initial Liquidity Deposit ==================== + // Depositor provides equal amounts of token A and B, receives LP tokens let deposit_amount = 1_000_000_000u64; // 1 token let depositor_liquidity_ata = deposit_liquidity(rpc, ctx, deposit_amount, deposit_amount).await; @@ -1103,10 +1163,14 @@ pub async fn run_amm_full_flow(rpc: &mut R, ctx: &AmmTestConte ) .await; - // Create trader and perform swaps + // ==================== PHASE 4: Create Trader ==================== + // Trader gets funded accounts for swapping let trader_initial_a = 100_000_000u64; // 0.1 tokens let (trader, trader_ata_a, trader_ata_b) = create_trader(rpc, ctx, trader_initial_a).await; + // ==================== PHASE 5: Execute Swaps ==================== + // Trader swaps A→B, then B→A + // Swap A -> B let swap_input = 10_000_000u64; // 0.01 tokens swap( @@ -1140,12 +1204,14 @@ pub async fn run_amm_full_flow(rpc: &mut R, ctx: &AmmTestConte ) .await; - // Withdraw half of LP tokens + // ==================== PHASE 6: Withdraw Liquidity ==================== + // Depositor redeems LP tokens for underlying token A and B let lp_balance = get_token_balance(rpc, depositor_liquidity_ata).await; let withdraw_amount = lp_balance / 2; withdraw_liquidity(rpc, ctx, depositor_liquidity_ata, withdraw_amount).await; - // Verify LP tokens were burned + // ==================== PHASE 7: Verify Final State ==================== + // LP tokens were burned let lp_balance_after = get_token_balance(rpc, depositor_liquidity_ata).await; assert_eq!( lp_balance_after, From bedc6c1b1916991525ddf843d34ab299fa792735 Mon Sep 17 00:00:00 2001 From: tilo-14 Date: Tue, 10 Feb 2026 12:54:04 +0000 Subject: [PATCH 03/10] make more educational --- programs/anchor/escrow/SPL_COMPARISON.md | 822 ++++++++++++++++++ programs/anchor/escrow/tests/common/mod.rs | 432 ++------- programs/anchor/escrow/tests/escrow.rs | 355 ++++++++ programs/anchor/escrow/tests/escrow_light.rs | 17 - programs/anchor/escrow/tests/escrow_spl.rs | 17 - .../anchor/escrow/tests/escrow_spl_light.rs | 19 - programs/anchor/escrow/tests/escrow_t22.rs | 17 - .../anchor/escrow/tests/escrow_t22_light.rs | 19 - 8 files changed, 1227 insertions(+), 471 deletions(-) create mode 100644 programs/anchor/escrow/SPL_COMPARISON.md create mode 100644 programs/anchor/escrow/tests/escrow.rs delete mode 100644 programs/anchor/escrow/tests/escrow_light.rs delete mode 100644 programs/anchor/escrow/tests/escrow_spl.rs delete mode 100644 programs/anchor/escrow/tests/escrow_spl_light.rs delete mode 100644 programs/anchor/escrow/tests/escrow_t22.rs delete mode 100644 programs/anchor/escrow/tests/escrow_t22_light.rs diff --git a/programs/anchor/escrow/SPL_COMPARISON.md b/programs/anchor/escrow/SPL_COMPARISON.md new file mode 100644 index 0000000..12b50e3 --- /dev/null +++ b/programs/anchor/escrow/SPL_COMPARISON.md @@ -0,0 +1,822 @@ +# Repository Comparison: solana-program-examples vs light-token-escrow-fixes + +This document details code differences between the standard Solana Program Examples (SPL) escrow and the Light Token implementation, organized section by section with inline annotations. + +--- + +## 1. Program Entry Point + +### SPL (solana-program-examples) + +```rust +// tokens/escrow/anchor/programs/escrow/src/lib.rs +use anchor_lang::prelude::*; + +declare_id!("2fcXpaTSQR4gGcFBgLpU3mZAX38bQQhKDJmXgSYdXj9d"); + +#[program] +pub mod escrow { + use super::*; + + pub fn make_offer( + context: Context, + id: u64, + token_a_offered_amount: u64, + token_b_wanted_amount: u64, + ) -> Result<()> { + instructions::make_offer::send_offered_tokens_to_vault(&context, token_a_offered_amount)?; + instructions::make_offer::save_offer(context, id, token_b_wanted_amount) + } + + pub fn take_offer(context: Context) -> Result<()> { + instructions::take_offer::send_wanted_tokens_to_maker(&context)?; + instructions::take_offer::withdraw_and_close_vault(context) + } +} +``` + +### Light (light-token-escrow-fixes) + +```rust +// programs/anchor/escrow/src/lib.rs +use anchor_lang::prelude::*; +use light_token::anchor::{derive_light_cpi_signer, light_program, CpiSigner}; + +declare_id!("FKJs6rp6TXJtxzLiPtdYhqa9ExRuBXG2zwh4fda6WATN"); + +// NEW: CPI signer for Light Protocol operations +pub const LIGHT_CPI_SIGNER: CpiSigner = + derive_light_cpi_signer!("FKJs6rp6TXJtxzLiPtdYhqa9ExRuBXG2zwh4fda6WATN"); + +#[light_program] // NEW: Light Protocol macro +#[allow(deprecated)] +#[program] +pub mod escrow { + use super::*; + + // Parameters wrapped in struct for proof data + pub fn make_offer<'info>( + mut ctx: Context<'_, '_, '_, 'info, MakeOffer<'info>>, + params: MakeOfferParams, + ) -> Result<()> { + instructions::make_offer::send_offered_tokens_to_vault(&ctx, ¶ms)?; + instructions::make_offer::save_offer(&mut ctx, ¶ms) + } + + pub fn take_offer(ctx: Context) -> Result<()> { + instructions::take_offer::send_wanted_tokens_to_maker(&ctx)?; + instructions::take_offer::withdraw_from_vault(&ctx)?; + instructions::take_offer::close_vault(&ctx) // Separate vault closure + } +} +``` + +**Key Differences:** + +| Aspect | SPL | Light | +| ------ | --- | ----- | +| Macro | `#[program]` | `#[light_program]` + `#[program]` | +| CPI Signer | None | `derive_light_cpi_signer!` constant | +| Parameters | Flat args | Wrapped in `MakeOfferParams` struct | +| Vault closure | Combined with withdrawal | Separate `close_vault` step | + +--- + +## 2. Instruction Parameters + +### SPL (solana-program-examples) + +```rust +// tokens/escrow/anchor/programs/escrow/src/lib.rs:18-26 +// Parameters passed directly to instruction +pub fn make_offer( + context: Context, + id: u64, + token_a_offered_amount: u64, + token_b_wanted_amount: u64, +) -> Result<()> +``` + +### Light (light-token-escrow-fixes) + +```rust +// programs/anchor/escrow/src/instructions/make_offer.rs:13-20 +#[derive(AnchorSerialize, AnchorDeserialize, Clone)] +pub struct MakeOfferParams { + pub create_accounts_proof: CreateAccountsProof, // ZK proof for account creation + pub id: u64, + pub token_a_offered_amount: u64, + pub token_b_wanted_amount: u64, + pub vault_bump: u8, // Pre-computed bump for vault PDA +} + +// Used in instruction signature +pub fn make_offer<'info>( + mut ctx: Context<'_, '_, '_, 'info, MakeOffer<'info>>, + params: MakeOfferParams, +) -> Result<()> +``` + +**Key Differences:** + +- Light uses `CreateAccountsProof` to prove the compressed account's address does not exist in the address tree +- Light pre-computes `vault_bump` client-side +- Parameters bundled in struct for cleaner handling + +--- + +## 3. State Account Definition + +### SPL (solana-program-examples) + +```rust +// tokens/escrow/anchor/programs/escrow/src/state/offer.rs +use anchor_lang::prelude::*; + +#[account] +#[derive(InitSpace)] +pub struct Offer { + pub id: u64, + pub maker: Pubkey, + pub token_mint_a: Pubkey, + pub token_mint_b: Pubkey, + pub token_b_wanted_amount: u64, + pub bump: u8, +} +``` + +### Light (light-token-escrow-fixes) + +```rust +// programs/anchor/escrow/src/state/offer.rs +use anchor_lang::prelude::*; +use light_sdk::LightDiscriminator; +use light_sdk_macros::LightAccount; +use light_token::anchor::CompressionInfo; + +#[derive(Default, Debug, InitSpace, LightAccount)] // NEW: LightAccount derive +#[account] +pub struct Offer { + pub compression_info: Option, // NEW: Compression metadata + pub id: u64, + pub maker: Pubkey, + pub token_mint_a: Pubkey, + pub token_mint_b: Pubkey, + pub token_b_wanted_amount: u64, + pub auth_bump: u8, // Renamed: authority bump, not offer bump +} +``` + +**Key Differences:** + +| Aspect | SPL | Light | +| ------ | --- | ----- | +| Derive | `#[account]` only | `#[account]` + `LightAccount` | +| Compression | None | `compression_info: Option` | +| Bump field | `bump` (offer PDA) | `auth_bump` (authority PDA) | +| Imports | anchor_lang only | + light_sdk, light_sdk_macros, light_token | + +--- + +## 4. MakeOffer Account Constraints + +### SPL (solana-program-examples) + +```rust +// tokens/escrow/anchor/programs/escrow/src/instructions/make_offer.rs:13-54 +#[derive(Accounts)] +#[instruction(id: u64)] +pub struct MakeOffer<'info> { + #[account(mut)] + pub maker: Signer<'info>, + + #[account(mint::token_program = token_program)] + pub token_mint_a: InterfaceAccount<'info, Mint>, + + #[account(mint::token_program = token_program)] + pub token_mint_b: InterfaceAccount<'info, Mint>, + + #[account( + mut, + associated_token::mint = token_mint_a, + associated_token::authority = maker, + associated_token::token_program = token_program + )] + pub maker_token_account_a: InterfaceAccount<'info, TokenAccount>, + + #[account( + init, + payer = maker, + space = ANCHOR_DISCRIMINATOR + Offer::INIT_SPACE, + seeds = [b"offer", maker.key().as_ref(), id.to_le_bytes().as_ref()], + bump + )] + pub offer: Account<'info, Offer>, + + #[account( + init, + payer = maker, + associated_token::mint = token_mint_a, + associated_token::authority = offer, + associated_token::token_program = token_program + )] + pub vault: InterfaceAccount<'info, TokenAccount>, + + pub associated_token_program: Program<'info, AssociatedToken>, + pub token_program: Interface<'info, TokenInterface>, + pub system_program: Program<'info, System>, +} +``` + +### Light (light-token-escrow-fixes) + +```rust +// programs/anchor/escrow/src/instructions/make_offer.rs:22-96 +#[derive(Accounts, LightAccounts)] // NEW: LightAccounts derive +#[instruction(params: MakeOfferParams)] +pub struct MakeOffer<'info> { + #[account(mut)] + pub fee_payer: Signer<'info>, + + /// CHECK: Authority PDA for vault operations + #[account(seeds = [AUTH_SEED], bump)] + pub authority: UncheckedAccount<'info>, + + /// CHECK: Rent-free config for this program + #[account(mut)] + pub compression_config: UncheckedAccount<'info>, + + #[account(mint::token_program = token_program)] + pub token_mint_a: InterfaceAccount<'info, Mint>, + + #[account(mint::token_program = token_program)] + pub token_mint_b: InterfaceAccount<'info, Mint>, + + /// User's source token account (Light or SPL) + /// CHECK: Verified by Light token program + #[account(mut)] + pub maker_token_account_a: UncheckedAccount<'info>, + + #[account( + init, + payer = fee_payer, + space = ANCHOR_DISCRIMINATOR + Offer::INIT_SPACE, + seeds = [OFFER_SEED, fee_payer.key().as_ref(), params.id.to_le_bytes().as_ref()], + bump, + )] + #[light_account(init)] // NEW: Light account initialization + pub offer: Account<'info, Offer>, + + /// CHECK: Light token vault account + #[account( + mut, + seeds = [VAULT_SEED, offer.key().as_ref()], + bump = params.vault_bump, + )] + #[light_account(init, + token::authority = [VAULT_SEED, self.offer.key()], + token::mint = token_mint_a, + token::owner = authority, + token::bump = params.vault_bump + )] + pub vault: UncheckedAccount<'info>, + + pub token_program: Interface<'info, TokenInterface>, + pub system_program: Program<'info, System>, + + // ========== Light Protocol Accounts ========== + pub light_token_program: Interface<'info, TokenInterface>, + + /// CHECK: Light token compressible config (constant address) + #[account(address = COMPRESSIBLE_CONFIG_V1)] + pub light_token_compressible_config: AccountInfo<'info>, + + /// CHECK: Rent sponsor account (constant address) + #[account(mut, address = RENT_SPONSOR)] + pub light_token_rent_sponsor: AccountInfo<'info>, + + /// CHECK: CPI authority for Light operations + #[account(mut)] + pub light_token_cpi_authority: AccountInfo<'info>, + + /// CHECK: SPL interface PDA for cross-protocol transfers + pub spl_interface_pda_a: UncheckedAccount<'info>, +} +``` + +**Key Differences:** + +| Aspect | SPL | Light | +| ------ | --- | ----- | +| Derive | `Accounts` | `Accounts` + `LightAccounts` | +| Vault type | `InterfaceAccount` | `UncheckedAccount` with `#[light_account]` | +| Token accounts | Typed `InterfaceAccount` | `UncheckedAccount` (Light Token program validates account state during CPI) | +| Authority | Offer account itself | Separate `authority` PDA | +| Extra accounts | 3 (system, token, ata) | 7+ (+ Light protocol accounts) | + +--- + +## 5. Token Transfer Logic + +### SPL (solana-program-examples) + +```rust +// tokens/escrow/anchor/programs/escrow/src/instructions/shared.rs +use anchor_lang::prelude::*; +use anchor_spl::token_interface::{transfer_checked, Mint, TokenAccount, TokenInterface, TransferChecked}; + +pub fn transfer_tokens<'info>( + from: &InterfaceAccount<'info, TokenAccount>, + to: &InterfaceAccount<'info, TokenAccount>, + amount: &u64, + mint: &InterfaceAccount<'info, Mint>, + authority: &Signer<'info>, + token_program: &Interface<'info, TokenInterface>, +) -> Result<()> { + let transfer_accounts = TransferChecked { + from: from.to_account_info(), + mint: mint.to_account_info(), + to: to.to_account_info(), + authority: authority.to_account_info(), + }; + + let cpi_context = CpiContext::new(token_program.to_account_info(), transfer_accounts); + + transfer_checked(cpi_context, *amount, mint.decimals) +} +``` + +### Light (light-token-escrow-fixes) + +```rust +// programs/anchor/escrow/src/instructions/shared.rs +use anchor_lang::prelude::*; +use light_token::anchor::{TransferCheckedCpi, TransferInterfaceCpi}; +use solana_program::account_info::AccountInfo; + +/// Configuration for SPL<->Light interface transfers +pub struct SplInterfaceConfig<'info> { + pub pda: AccountInfo<'info>, + pub bump: u8, + pub restricted: bool, +} + +/// Check if an account is a Light token account (>165 bytes indicates presence of CompressionInfo metadata) +fn is_light_account(account: &AccountInfo) -> bool { + account.data_len() > 165 +} + +pub fn transfer_tokens<'info>( + amount: u64, + decimals: u8, + from: AccountInfo<'info>, + to: AccountInfo<'info>, + mint: AccountInfo<'info>, + authority: AccountInfo<'info>, + payer: AccountInfo<'info>, + light_token_cpi_authority: AccountInfo<'info>, + system_program: AccountInfo<'info>, + signer_seeds: Option<&[&[u8]]>, + spl_interface: Option>, +) -> Result<()> { + // Call is_light_account() on source and destination to select transfer path + let is_light_to_light = is_light_account(&from) && is_light_account(&to); + + if is_light_to_light { + // Pure Light-to-Light transfer + let cpi = TransferCheckedCpi { + token_program: light_token_cpi_authority.clone(), + from, + to, + owner: authority.clone(), + mint, + payer, + system_program, + amount, + decimals, + }; + + if let Some(seeds) = signer_seeds { + cpi.invoke_signed(&[seeds]) + } else { + cpi.invoke() + } + .map_err(|e| anchor_lang::prelude::ProgramError::from(e).into()) + } else { + // SPL<->Light transfer via interface + let mut cpi = TransferInterfaceCpi::new( + light_token_cpi_authority.clone(), + from, + to, + authority.clone(), + mint, + payer, + system_program, + amount, + decimals, + ); + + // Add SPL interface configuration if provided + if let Some(spl) = spl_interface { + cpi = cpi.with_spl_interface(spl.pda, spl.bump, spl.restricted)?; + } + + if let Some(seeds) = signer_seeds { + cpi.invoke_signed(&[seeds]) + } else { + cpi.invoke() + } + .map_err(|e| anchor_lang::prelude::ProgramError::from(e).into()) + } +} +``` + +**Key Differences:** + +| Aspect | SPL | Light | +| ------ | --- | ----- | +| Function params | 6 typed params | 11 params including Light infra | +| Transfer type | Single `transfer_checked` | Conditional: `TransferCheckedCpi` or `TransferInterfaceCpi` | +| Account detection | N/A | `is_light_account()` checks data length | +| Cross-protocol | Not supported | `SplInterfaceConfig` for SPL<->Light | +| CPI pattern | `CpiContext::new()` | `TransferCheckedCpi`/`TransferInterfaceCpi` struct + `invoke()` | + +--- + +## 6. Vault Closure + +### SPL (solana-program-examples) + +```rust +// tokens/escrow/anchor/programs/escrow/src/instructions/take_offer.rs:88-129 +// Combined withdrawal and closure in single function +pub fn withdraw_and_close_vault(ctx: Context) -> Result<()> { + let seeds = &[ + b"offer", + ctx.accounts.maker.to_account_info().key.as_ref(), + &ctx.accounts.offer.id.to_le_bytes()[..], + &[ctx.accounts.offer.bump], + ]; + let signer_seeds = &[&seeds[..]]; + + // Transfer tokens from vault to taker + let accounts = TransferChecked { + from: ctx.accounts.vault.to_account_info(), + mint: ctx.accounts.token_mint_a.to_account_info(), + to: ctx.accounts.taker_token_account_a.to_account_info(), + authority: ctx.accounts.offer.to_account_info(), + }; + let cpi_context = CpiContext::new_with_signer( + ctx.accounts.token_program.to_account_info(), + accounts, + signer_seeds, + ); + transfer_checked( + cpi_context, + ctx.accounts.vault.amount, + ctx.accounts.token_mint_a.decimals, + )?; + + // Close vault account (returns rent to maker) + let accounts = CloseAccount { + account: ctx.accounts.vault.to_account_info(), + destination: ctx.accounts.maker.to_account_info(), + authority: ctx.accounts.offer.to_account_info(), + }; + let cpi_context = CpiContext::new_with_signer( + ctx.accounts.token_program.to_account_info(), + accounts, + signer_seeds, + ); + close_account(cpi_context) +} +``` + +### Light (light-token-escrow-fixes) + +```rust +// programs/anchor/escrow/src/instructions/take_offer.rs:140-178 +// Separate withdrawal function +pub fn withdraw_from_vault(ctx: &Context) -> Result<()> { + let auth_bump = ctx.accounts.offer.auth_bump; + let authority_seeds: &[&[u8]] = &[AUTH_SEED, &[auth_bump]]; + + // Get vault balance + let vault_data = ctx.accounts.vault.try_borrow_data()?; + let vault_amount = if vault_data.len() >= 72 { + u64::from_le_bytes(vault_data[64..72].try_into().unwrap()) + } else { + return Err(ErrorCode::InvalidVaultData.into()); + }; + drop(vault_data); + + // Determine if SPL interface needed + let spl_interface = get_spl_interface_config( + &ctx.accounts.spl_interface_pda_a, + &ctx.accounts.token_mint_a, + ); + + transfer_tokens( + vault_amount, + ctx.accounts.token_mint_a.decimals, + ctx.accounts.vault.to_account_info(), + ctx.accounts.taker_token_account_a.to_account_info(), + ctx.accounts.token_mint_a.to_account_info(), + ctx.accounts.authority.to_account_info(), + ctx.accounts.taker.to_account_info(), + ctx.accounts.light_token_cpi_authority.to_account_info(), + ctx.accounts.system_program.to_account_info(), + Some(authority_seeds), + spl_interface, + ) +} + +// Separate vault closure function +pub fn close_vault(ctx: &Context) -> Result<()> { + let auth_bump = ctx.accounts.offer.auth_bump; + let authority_seeds: &[&[u8]] = &[AUTH_SEED, &[auth_bump]]; + + CloseAccountCpi { + token_program: ctx.accounts.light_token_program.to_account_info(), + account: ctx.accounts.vault.to_account_info(), + destination: ctx.accounts.taker.to_account_info(), + owner: ctx.accounts.authority.to_account_info(), + rent_sponsor: ctx.accounts.light_token_rent_sponsor.to_account_info(), + } + .invoke_signed(&[authority_seeds]) + .map_err(|e| anchor_lang::prelude::ProgramError::from(e).into()) +} +``` + +**Key Differences:** + +| Aspect | SPL | Light | +| ------ | --- | ----- | +| Functions | 1 combined | 2 separate (`withdraw_from_vault` + `close_vault`) | +| Authority | Offer account | Separate authority PDA | +| Balance read | `ctx.accounts.vault.amount` | Manual byte parsing from account data | +| Close CPI | `close_account()` from anchor_spl | `CloseAccountCpi` from light_token | +| Rent return | To maker | To taker (rent sponsor refund) | + +--- + +## 7. Dependencies (Cargo.toml) + +### SPL (solana-program-examples) + +```toml +# tokens/escrow/anchor/programs/escrow/Cargo.toml +[dependencies] +anchor-lang = "0.32.1" +anchor-spl = "0.32.1" + +[dev-dependencies] +# None - tests are in TypeScript +``` + +### Light (light-token-escrow-fixes) + +```toml +# programs/anchor/escrow/Cargo.toml +[dependencies] +anchor-lang.workspace = true # 0.31.1 + +# Light Protocol core +light-sdk = { workspace = true, features = [ + "anchor", "anchor-discriminator", "idl-build", "cpi-context", "v2" +] } # 0.19.0 +light-token = { workspace = true, features = ["anchor"] } # 0.4.0 +light-hasher = { workspace = true, features = ["solana"] } # 5.0.0 +light-anchor-spl = { workspace = true, features = ["idl-build"] } # 0.31.1 + +# Solana (modular imports) +solana-program.workspace = true # 2.x +solana-pubkey.workspace = true +solana-account-info.workspace = true +solana-program-error.workspace = true +solana-msg.workspace = true + +[dev-dependencies] +light-program-test.workspace = true # 0.19.0 +light-client = { workspace = true, features = ["v2", "anchor"] } # 0.19.0 +spl-token-2022.workspace = true # 7.x +shared-test-utils.workspace = true # Local test utilities +tokio.workspace = true # 1.43.0 +``` + +**Key Differences:** + +- SPL: 2 dependencies (anchor-lang, anchor-spl) +- Light: 10+ dependencies (light-sdk, light-token, light-hasher, light-anchor-spl, light-program-test, light-client) +- Light uses workspace dependencies for version consistency +- Light has extensive dev-dependencies for Rust-based testing + +--- + +## 8. Test Structure + +### SPL (solana-program-examples) + +``` +tokens/escrow/anchor/ +└── tests/ + └── escrow.test.ts # Single TypeScript test file +``` + +```typescript +// escrow.test.ts (simplified) +import * as anchor from '@coral-xyz/anchor'; +import { createAccountsMintsAndTokenAccounts } from '@solana-developers/helpers'; + +describe('Escrow', () => { + const provider = anchor.AnchorProvider.env(); + const program = anchor.workspace.Escrow; + + let alice, bob, tokenMintA, tokenMintB; + + before(async () => { + // Setup accounts and mints + const result = await createAccountsMintsAndTokenAccounts(...); + alice = result.users[0]; + bob = result.users[1]; + }); + + it('creates an offer', async () => { + await program.methods + .makeOffer(offerId, offerAmount, wantedAmount) + .accounts({ maker: alice.publicKey, ... }) + .signers([alice]) + .rpc(); + }); + + it('takes an offer', async () => { + await program.methods + .takeOffer() + .accounts({ taker: bob.publicKey, ... }) + .signers([bob]) + .rpc(); + }); +}); +``` + +### Light (light-token-escrow-fixes) + +``` +programs/anchor/escrow/ +└── tests/ + ├── common/ + │ └── mod.rs # Shared test utilities + ├── escrow_spl.rs # SPL-only tests + ├── escrow_t22.rs # Token-2022 tests + ├── escrow_light.rs # Light-to-Light tests + ├── escrow_spl_light.rs # SPL mint + Light accounts + └── escrow_t22_light.rs # T22 mint + Light accounts +``` + +```rust +// tests/common/mod.rs (key abstractions) +pub enum TokenConfig { + Spl, // SPL mint + SPL ATAs + Token2022, // T22 mint + T22 ATAs + Light, // Light mint + Light ATAs + LightSpl, // SPL mint + Light ATAs + LightT22, // T22 mint + Light ATAs +} + +pub struct EscrowTestContext { + pub program_id: Pubkey, + pub payer: Keypair, + pub token_config: TokenConfig, + pub compression_config: Pubkey, + pub mint_a_pubkey: Pubkey, + pub light_mint_a_authority: Option, + pub spl_interface_a: Option, + // ... more fields +} + +pub async fn setup_escrow_test( + rpc: &mut R, + config: TokenConfig, +) -> EscrowTestContext { ... } + +pub async fn run_escrow_full_flow( + rpc: &mut R, + ctx: &EscrowTestContext, +) { ... } +``` + +```rust +// tests/escrow_light.rs +#[tokio::test] +async fn test_escrow_full_flow_light() { + let mut rpc = create_test_rpc().await; + let ctx = setup_escrow_test(&mut rpc, TokenConfig::Light).await; + run_escrow_full_flow(&mut rpc, &ctx).await; +} +``` + +**Key Differences:** + +| Aspect | SPL | Light | +| ------ | --- | ----- | +| Language | TypeScript | Rust | +| Framework | Mocha + Chai | tokio + cargo test-sbf | +| Test files | 1 | 5 (per token combination) | +| Setup | `@solana-developers/helpers` | `shared-test-utils` crate | +| Parametric | No | Yes (`TokenConfig` enum) | + +--- + +## 9. Additional Light Protocol Infrastructure + +These components exist only in the Light version: + +### Rent-Free Configuration + +```rust +// Initialized once per program +pub async fn initialize_rent_free_config( + rpc: &mut R, + payer: &Keypair, + program_id: &Pubkey, +) -> Pubkey { + let program_data_pda = setup_mock_program_data(rpc, payer, program_id); + + let (init_config_ix, config_pda) = InitializeRentFreeConfig::new( + program_id, + &payer.pubkey(), + &program_data_pda, + RENT_SPONSOR, + payer.pubkey(), + ).build(); + + rpc.create_and_send_transaction(&[init_config_ix], &payer.pubkey(), &[payer]) + .await + .expect("Initialize rent-free config should succeed"); + + config_pda +} +``` + +### SPL Interface PDA + +```rust +// Required for SPL<->Light transfers +pub async fn create_spl_interface_pda( + rpc: &mut R, + payer: &Keypair, + mint: &Pubkey, + mint_type: MintType, + restricted: bool, +) -> SplInterfaceResult { + let (pda, bump) = find_spl_interface_pda(mint, restricted); + + let create_ix = CreateSplInterfacePda::new( + payer.pubkey(), + *mint, + mint_type.program_id(), + restricted, + ).instruction(); + + rpc.create_and_send_transaction(&[create_ix], &payer.pubkey(), &[payer]) + .await + .expect("Create SPL interface PDA should succeed"); + + SplInterfaceResult { pda, bump } +} +``` + +### Light Token Account Creation + +```rust +// Creating a Light token account (ATA equivalent) +pub async fn create_light_ata( + rpc: &mut R, + payer: &Keypair, + mint: &Pubkey, + owner: &Pubkey, +) -> Pubkey { + let compressible_params = CompressibleParams { + compressible_config: COMPRESSIBLE_CONFIG_V1, + rent_sponsor: RENT_SPONSOR, + pre_pay_num_epochs: 2, + lamports_per_write: Some(1000), + compress_to_account_pubkey: None, + token_account_version: TokenDataVersion::ShaFlat, + compression_only: true, + }; + + let create_ata_ix = CreateAssociatedTokenAccount::new(payer.pubkey(), *owner, *mint) + .with_compressible(compressible_params) + .idempotent() + .instruction() + .expect("Create Light ATA instruction should succeed"); + + rpc.create_and_send_transaction(&[create_ata_ix], &payer.pubkey(), &[payer]) + .await + .expect("Create Light ATA should succeed"); + + let (ata, _) = derive_token_ata(owner, mint); + ata +} +``` diff --git a/programs/anchor/escrow/tests/common/mod.rs b/programs/anchor/escrow/tests/common/mod.rs index 65f43be..86d15b7 100644 --- a/programs/anchor/escrow/tests/common/mod.rs +++ b/programs/anchor/escrow/tests/common/mod.rs @@ -1,31 +1,35 @@ -//! Common test utilities for escrow tests. +//! Escrow test setup for 5 token standard combinations: SPL, T22, Light. //! -//! This module provides shared test helpers for different token type combinations: -//! - SPL mint + SPL ATAs -//! - T22 mint + T22 ATAs -//! - SPL mint + Light user accounts -//! - T22 mint + Light user accounts -//! - Light mint + Light user accounts +//! Each combination varies the mint type and associated token account type while the vault +//! is always a Light token account: +//! +//! - `Spl` / `Token2022`: standard associated token accounts, cross-standard transfers to Light vault +//! - `Light`: native Light token accounts, direct transfers (lowest cost) +//! - `LightSpl` / `LightT22`: SPL/T22 mints converted into Light token accounts before +//! the escrow starts (tokens are minted to a temp associated token account, then +//! transferred to a Light associated token account via `transfer_spl_to_light`) +//! +//! ## Setup flow +//! +//! 1. `create_test_rpc()` — start test validator with escrow + minter programs +//! 2. `setup_escrow_test(config)` — create mints, interface PDAs, maker/taker +//! 3. `create_token_account()` — create funded/unfunded accounts per config // ============================================================================ // Imports // ============================================================================ -use anchor_lang::{InstructionData, ToAccountMetas}; use anchor_spl::token; use shared_test_utils::{ - helpers::verify_light_token_balance, light_tokens::{create_light_ata, create_light_mint, mint_light_tokens}, setup::initialize_rent_free_config, spl_interface::{create_spl_interface_pda, transfer_spl_to_light}, spl_tokens::{create_spl_ata, create_spl_mint, mint_spl_tokens}, t22_tokens::{create_t22_ata, create_t22_mint, mint_t22_tokens}, Indexer, LightProgramTest, MintType, ProgramTestConfig, Rpc, - SplInterfaceResult, TestRpc, COMPRESSIBLE_CONFIG_V1, CPI_AUTHORITY_PDA, - LIGHT_TOKEN_MINTER_PROGRAM_ID, LIGHT_TOKEN_PROGRAM_ID, RENT_SPONSOR, + SplInterfaceResult, TestRpc, + LIGHT_TOKEN_MINTER_PROGRAM_ID, LIGHT_TOKEN_PROGRAM_ID, }; -use light_client::interface::{get_create_accounts_proof, CreateAccountsProofInput}; -use solana_instruction::Instruction; use solana_keypair::Keypair; use solana_pubkey::Pubkey; use solana_signer::Signer; @@ -34,23 +38,34 @@ use solana_signer::Signer; // Token Configuration // ============================================================================ -/// Token configuration for parameterized tests +/// Token configuration for parameterized escrow tests. +/// +/// Each variant determines the mint type and user account type. The vault is +/// always a Light token account (rent-free). The user account type controls +/// which CPI path `transfer_tokens()` selects at runtime: +/// +/// - SPL/T22 user accounts → `TransferInterfaceCpi` (cross-standard, needs interface PDA) +/// - Light user accounts → `TransferCheckedCpi` (direct, no interface PDA) #[allow(dead_code)] #[derive(Clone, Copy, Debug)] pub enum TokenConfig { - /// SPL mint + SPL ATAs + /// SPL mint + SPL associated token accounts. Transfers cross standards (SPL ↔ Light vault). Spl, - /// T22 mint + T22 ATAs + /// T22 mint + T22 associated token accounts. Transfers cross standards (T22 ↔ Light vault). Token2022, - /// SPL mint + Light user accounts (offchain SPL->Light conversion) + /// SPL mint + Light associated token accounts. Tokens converted from SPL associated token accounts in setup. + /// During escrow, all transfers are Light-to-Light. LightSpl, - /// T22 mint + Light user accounts (offchain T22->Light conversion) + /// T22 mint + Light associated token accounts. Tokens converted from T22 associated token accounts in setup. + /// During escrow, all transfers are Light-to-Light. LightT22, - /// Light mint + Light user accounts (pure Light-to-Light) + /// Light mint + Light associated token accounts. Pure Light — lowest cost, no bridging. Light, } impl TokenConfig { + /// Returns the underlying mint program type. + /// Light mints use SPL-compatible layout, so this returns `MintType::Spl`. pub fn mint_type(&self) -> MintType { match self { TokenConfig::Spl | TokenConfig::LightSpl => MintType::Spl, @@ -59,6 +74,7 @@ impl TokenConfig { } } + /// Returns the token program ID passed as `token_program` in instructions. pub fn token_program_id(&self) -> Pubkey { match self { TokenConfig::Spl | TokenConfig::LightSpl => token::ID, @@ -129,7 +145,14 @@ pub async fn create_test_rpc() -> LightProgramTest { LightProgramTest::new(config).await.unwrap() } -/// Setup the escrow test environment based on token config +/// Initialize mints, interface PDAs, and participants for a given token config. +/// +/// SPL interface PDAs are created for all SPL/T22 configs (including `Spl` and +/// `Token2022`, not just `LightSpl`/`LightT22`) because the vault is always a +/// Light token account — any transfer involving an SPL/T22 account and the Light +/// vault crosses standards and requires an interface PDA. +/// +/// For `Light` config, no interface PDAs are created (early return). pub async fn setup_escrow_test( rpc: &mut R, config: TokenConfig, @@ -253,13 +276,14 @@ pub async fn setup_escrow_test( // Token Account Creation // ============================================================================ -/// Create a token account for a participant for a specific mint. +/// Create a token account for a participant, optionally funded. /// -/// When `funding_amount > 0`, mints tokens to the account. -/// When `funding_amount == 0`, creates the account without funding. -/// -/// For LightSpl/LightT22: creates a temp SPL/T22 ATA, mints, creates Light ATA, -/// and transfers (compresses) when funded. When unfunded, just creates Light ATA. +/// Account creation varies by config: +/// - `Spl` / `Token2022`: create standard associated token account, mint directly +/// - `Light`: create Light associated token account via `mint_light_tokens` (creates + mints in one call) +/// - `LightSpl` / `LightT22`: create temp SPL/T22 associated token account → mint → +/// create Light associated token account → convert via `transfer_spl_to_light`. +/// If unfunded, just creates the Light associated token account. pub async fn create_token_account( rpc: &mut R, ctx: &EscrowTestContext, @@ -383,359 +407,3 @@ pub async fn create_token_account( } } } - -// ============================================================================ -// Instruction Execution -// ============================================================================ - -/// Execute make_offer instruction. Returns (offer_pda, vault_pda, vault_bump). -pub async fn execute_make_offer( - rpc: &mut R, - ctx: &EscrowTestContext, - offer_id: u64, - maker_ata_a: Pubkey, - token_a_offered_amount: u64, - token_b_wanted_amount: u64, -) -> (Pubkey, Pubkey, u8) { - // Step 1: Derive offer PDA from maker + offer_id - let (offer_pda, _) = Pubkey::find_program_address( - &[ - escrow::OFFER_SEED, - ctx.maker.pubkey().as_ref(), - offer_id.to_le_bytes().as_ref(), - ], - &ctx.program_id, - ); - - // Step 2: Derive vault PDA from offer PDA - let (vault_pda, vault_bump) = - Pubkey::find_program_address(&[escrow::VAULT_SEED, offer_pda.as_ref()], &ctx.program_id); - - // Step 3: Get proof for creating the offer account (light-PDA) - let proof_result = get_create_accounts_proof( - rpc, - &ctx.program_id, - vec![CreateAccountsProofInput::pda(offer_pda)], - ) - .await - .unwrap(); - - // Step 4: Build make_offer instruction - // - Transfers token_a from maker to vault - // - Creates offer account with escrow terms - let accounts = escrow::accounts::MakeOffer { - fee_payer: ctx.maker.pubkey(), - authority: ctx.authority_pda, - compression_config: ctx.compression_config, - token_mint_a: ctx.mint_a_pubkey, - token_mint_b: ctx.mint_b_pubkey, - maker_token_account_a: maker_ata_a, - offer: offer_pda, - vault: vault_pda, - token_program: ctx.token_config.token_program_id(), - system_program: solana_sdk::system_program::ID, - light_token_program: Pubkey::new_from_array(LIGHT_TOKEN_PROGRAM_ID), - light_token_compressible_config: COMPRESSIBLE_CONFIG_V1, - light_token_rent_sponsor: RENT_SPONSOR, - light_token_cpi_authority: CPI_AUTHORITY_PDA, - spl_interface_pda_a: ctx - .spl_interface_a - .as_ref() - .map(|i| i.pda) - .unwrap_or_default(), - }; - - let data = escrow::instruction::MakeOffer { - params: escrow::MakeOfferParams { - create_accounts_proof: proof_result.create_accounts_proof, - id: offer_id, - token_a_offered_amount, - token_b_wanted_amount, - vault_bump, - }, - }; - - let ix = Instruction { - program_id: ctx.program_id, - accounts: [ - accounts.to_account_metas(None), - proof_result.remaining_accounts, - ] - .concat(), - data: data.data(), - }; - - rpc.create_and_send_transaction(&[ix], &ctx.maker.pubkey(), &[&ctx.maker]) - .await - .expect("make_offer should succeed"); - - println!("make_offer executed: offer={:?}, vault={:?}", offer_pda, vault_pda); - - (offer_pda, vault_pda, vault_bump) -} - -/// Execute take_offer instruction. -/// -/// The program performs these steps: -/// 1. Send wanted tokens from taker to maker (send_wanted_tokens_to_maker) -/// 2. Withdraw offered tokens from vault to taker (withdraw_from_vault) -/// 3. Close vault account (close_vault) -pub async fn execute_take_offer( - rpc: &mut R, - ctx: &EscrowTestContext, - offer_pda: Pubkey, - vault_pda: Pubkey, - taker_ata_a: Pubkey, - taker_ata_b: Pubkey, - maker_ata_b: Pubkey, -) { - // Build take_offer instruction - let accounts = escrow::accounts::TakeOffer { - taker: ctx.taker.pubkey(), - maker: ctx.maker.pubkey(), - authority: ctx.authority_pda, - token_mint_a: ctx.mint_a_pubkey, - token_mint_b: ctx.mint_b_pubkey, - taker_token_account_a: taker_ata_a, - taker_token_account_b: taker_ata_b, - maker_token_account_b: maker_ata_b, - offer: offer_pda, - vault: vault_pda, - token_program: ctx.token_config.token_program_id(), - system_program: solana_sdk::system_program::ID, - light_token_program: Pubkey::new_from_array(LIGHT_TOKEN_PROGRAM_ID), - light_token_cpi_authority: CPI_AUTHORITY_PDA, - light_token_rent_sponsor: RENT_SPONSOR, - spl_interface_pda_a: ctx - .spl_interface_a - .as_ref() - .map(|i| i.pda) - .unwrap_or_default(), - spl_interface_pda_b: ctx - .spl_interface_b - .as_ref() - .map(|i| i.pda) - .unwrap_or_default(), - }; - - let data = escrow::instruction::TakeOffer {}; - - let ix = Instruction { - program_id: ctx.program_id, - accounts: accounts.to_account_metas(None), - data: data.data(), - }; - - rpc.create_and_send_transaction(&[ix], &ctx.taker.pubkey(), &[&ctx.taker]) - .await - .expect("take_offer should succeed"); - - println!("take_offer executed"); -} - -// ============================================================================ -// Full Flow Tests -// ============================================================================ - -/// Run the full escrow flow: setup accounts, make_offer, take_offer, verify balances. -pub async fn run_escrow_full_flow( - rpc: &mut R, - ctx: &EscrowTestContext, -) { - // ==================== PHASE 1: Define Escrow Terms ==================== - // Maker offers 1 token A, wants 0.5 token B in return - let token_a_offered = 1_000_000_000u64; // 1 token (9 decimals) - let token_b_wanted = 500_000_000u64; // 0.5 tokens - let offer_id = 1u64; - - // ==================== PHASE 2: Create Token Accounts ==================== - // Maker needs: funded token A account, empty token B account (receives payment) - // Taker needs: empty token A account (receives offered tokens), funded token B account - println!("\n=== Creating token accounts ==="); - - // Maker's token A account (funded with tokens to offer) - let maker_token_a = create_token_account( - rpc, - ctx, - &ctx.maker, - &ctx.mint_a_pubkey, - ctx.light_mint_a_authority.as_ref(), - ctx.spl_interface_a.as_ref(), - token_a_offered, - ) - .await; - - // Maker's token B account (empty, will receive payment from taker) - let maker_token_b = create_token_account( - rpc, - ctx, - &ctx.maker, - &ctx.mint_b_pubkey, - ctx.light_mint_b_authority.as_ref(), - ctx.spl_interface_b.as_ref(), - 0, - ) - .await; - - // Taker's token A account (empty, will receive offered tokens from vault) - let taker_token_a = create_token_account( - rpc, - ctx, - &ctx.taker, - &ctx.mint_a_pubkey, - ctx.light_mint_a_authority.as_ref(), - ctx.spl_interface_a.as_ref(), - 0, - ) - .await; - - // Taker's token B account (funded with tokens to pay maker) - let taker_token_b = create_token_account( - rpc, - ctx, - &ctx.taker, - &ctx.mint_b_pubkey, - ctx.light_mint_b_authority.as_ref(), - ctx.spl_interface_b.as_ref(), - token_b_wanted, - ) - .await; - - // ==================== PHASE 3: Verify Initial State ==================== - let maker_a_before = token_a_offered; - let maker_b_before = 0u64; - let taker_a_before = 0u64; - let taker_b_before = token_b_wanted; - - println!("\n=== Verifying initial balances ==="); - verify_light_token_balance(rpc, maker_token_a, maker_a_before, "maker_token_a (initial)") - .await; - verify_light_token_balance(rpc, maker_token_b, maker_b_before, "maker_token_b (initial)") - .await; - verify_light_token_balance(rpc, taker_token_a, taker_a_before, "taker_token_a (initial)") - .await; - verify_light_token_balance(rpc, taker_token_b, taker_b_before, "taker_token_b (initial)") - .await; - - // ==================== PHASE 4: Make Offer ==================== - // Step 4a: Derive PDAs for offer and vault - // Step 4b: Get proof for creating compressed offer account - // Step 4c: Transfer offered tokens from maker to vault - // Step 4d: Save offer details to offer account - println!("\n=== Executing make_offer ==="); - let (offer_pda, vault_pda, _) = execute_make_offer( - rpc, - ctx, - offer_id, - maker_token_a, - token_a_offered, - token_b_wanted, - ) - .await; - - // ==================== PHASE 5: Verify Offer State ==================== - // Vault should hold offered tokens, maker's account should be empty - verify_light_token_balance(rpc, vault_pda, token_a_offered, "vault (after make_offer)").await; - verify_light_token_balance(rpc, maker_token_a, 0, "maker_token_a (after make_offer)").await; - - // Verify offer account was created - let offer_account = rpc - .get_account(offer_pda) - .await - .unwrap() - .expect("Offer account should exist"); - assert!( - !offer_account.data.is_empty(), - "Offer account should have data" - ); - - // ==================== PHASE 6: Take Offer ==================== - // Step 6a: Taker sends wanted tokens (B) to maker - // Step 6b: Vault releases offered tokens (A) to taker - // Step 6c: Close vault and offer accounts - println!("\n=== Executing take_offer ==="); - execute_take_offer( - rpc, - ctx, - offer_pda, - vault_pda, - taker_token_a, - taker_token_b, - maker_token_b, - ) - .await; - - // ==================== PHASE 7: Verify Final State ==================== - // Maker: gave token A, received token B - // Taker: gave token B, received token A - println!("\n=== Verifying final balances ==="); - - let maker_a_after = 0u64; - let maker_b_after = token_b_wanted; - let taker_a_after = token_a_offered; - let taker_b_after = 0u64; - - verify_light_token_balance(rpc, maker_token_a, maker_a_after, "maker_token_a (final)").await; - verify_light_token_balance(rpc, maker_token_b, maker_b_after, "maker_token_b (final)").await; - verify_light_token_balance(rpc, taker_token_a, taker_a_after, "taker_token_a (final)").await; - verify_light_token_balance(rpc, taker_token_b, taker_b_after, "taker_token_b (final)").await; - - // Verify offer account was closed - let offer_after = rpc.get_account(offer_pda).await.unwrap(); - assert!( - offer_after.is_none(), - "Offer account should be closed after take_offer" - ); - println!("Offer account closed"); - - println!( - "\n=== Escrow completed: Maker exchanged {} token_a for {} token_b ===", - token_a_offered, token_b_wanted - ); -} - -/// Run make_offer only (for setup verification tests). -pub async fn run_escrow_make_offer( - rpc: &mut R, - ctx: &EscrowTestContext, -) { - let token_a_amount = 1_000_000_000u64; - let token_b_amount = 500_000_000u64; - - // Create maker's token A account (funded) - let maker_ata_a = create_token_account( - rpc, - ctx, - &ctx.maker, - &ctx.mint_a_pubkey, - ctx.light_mint_a_authority.as_ref(), - ctx.spl_interface_a.as_ref(), - token_a_amount, - ) - .await; - - // Execute make_offer - let (offer_pda, vault_pda, _) = execute_make_offer( - rpc, - ctx, - 1, - maker_ata_a, - token_a_amount, - token_b_amount, - ) - .await; - - // Verify vault was created and funded - verify_light_token_balance(rpc, vault_pda, token_a_amount, "vault (after make_offer)").await; - verify_light_token_balance(rpc, maker_ata_a, 0, "maker_ata_a (after make_offer)").await; - - // Verify offer account was created - let offer_account = rpc - .get_account(offer_pda) - .await - .unwrap() - .expect("Offer account should exist"); - assert!(!offer_account.data.is_empty(), "Offer account should have data"); - - println!("make_offer verified"); -} diff --git a/programs/anchor/escrow/tests/escrow.rs b/programs/anchor/escrow/tests/escrow.rs new file mode 100644 index 0000000..c195fcb --- /dev/null +++ b/programs/anchor/escrow/tests/escrow.rs @@ -0,0 +1,355 @@ +//! Light Token escrow: peer-to-peer token swap with rent-free vault. +//! +//! This test shows the same make/take escrow pattern as the +//! [solana-program-examples SPL escrow](https://github.com/solana-developers/program-examples/tree/main/tokens/escrow/anchor), +//! adapted for Light Token. Three architectural differences: +//! +//! 1. **Authority PDA owns the vault** — not the offer account. This lets +//! the authority sign vault withdrawals without needing account data +//! (see `make_offer.rs` `#[light_account(init, token::owner = authority)]`). +//! +//! 2. **Vault is rent-free** — it's a Light token account sponsored by +//! `RENT_SPONSOR`, eliminating the ~0.002 SOL rent per escrow. +//! +//! 3. **Validity proof for account creation** — `get_create_accounts_proof()` +//! fetches a validity proof that the offer PDA's derived address does not +//! yet exist in Light's address tree. Only needed in `make_offer` (creating +//! new state); `take_offer` reads existing accounts and needs no proof. +//! +//! ## Token scenarios +//! +//! The vault is always a Light Token account. The user's account type determines +//! which CPI path `transfer_tokens()` in `shared.rs` selects: +//! +//! | Test | Mint | User accounts | Transfer path | Purpose | +//! |------|------|---------------|---------------|---------| +//! | `test_escrow_spl` | SPL | SPL associated token accounts | `TransferInterfaceCpi` | SPL mints work with Light vault | +//! | `test_escrow_t22` | T22 | T22 associated token accounts | `TransferInterfaceCpi` | T22 mints work with Light vault | +//! | `test_escrow_light` | Light | Light associated token accounts | `TransferCheckedCpi` | Pure Light — lowest cost path | +//! | `test_escrow_spl_light` | SPL | Light associated token accounts | `TransferCheckedCpi` | SPL mint, converted user accounts | +//! | `test_escrow_t22_light` | T22 | Light associated token accounts | `TransferCheckedCpi` | T22 mint, converted user accounts | +//! +//! For `Spl`/`Token2022`: user accounts are SPL/T22, vault is Light → cross-standard +//! (`TransferInterfaceCpi` with SPL interface PDA). +//! +//! For `Light`/`LightSpl`/`LightT22`: all accounts are Light → direct +//! (`TransferCheckedCpi`, no interface PDA needed during escrow). +//! +//! `LightSpl`/`LightT22` convert tokens from SPL/T22 associated token accounts +//! into Light token accounts *before* the escrow starts (in `create_token_account`). +//! The escrow itself only sees Light token accounts. + +mod common; + +use anchor_lang::{InstructionData, ToAccountMetas}; +use common::{ + create_test_rpc, create_token_account, setup_escrow_test, EscrowTestContext, TokenConfig, +}; +use light_client::interface::{get_create_accounts_proof, CreateAccountsProofInput}; +use shared_test_utils::{ + helpers::verify_light_token_balance, Indexer, Rpc, TestRpc, COMPRESSIBLE_CONFIG_V1, + CPI_AUTHORITY_PDA, LIGHT_TOKEN_PROGRAM_ID, RENT_SPONSOR, +}; +use solana_instruction::Instruction; +use solana_pubkey::Pubkey; +use solana_signer::Signer; + +// ============================================================================ +// Full Flow +// ============================================================================ + +/// Run the full escrow flow for any token configuration: SPL, T22, Light. +/// +/// 1. Create token accounts (SPL, T22 or Light depends on `TokenConfig` — see `create_token_account`) +/// 2. Make offer: deposit token A into vault, record escrow terms +/// 3. Take offer: taker sends token B to maker, vault releases token A to taker +/// 4. Verify balances and account closure +async fn run_escrow_full_flow( + rpc: &mut R, + ctx: &EscrowTestContext, +) { + // ==================== PHASE 1: Define Escrow Terms ==================== + // Maker offers 1 token A, wants 0.5 token B in return + let token_a_offered = 1_000_000_000u64; // 1 token (9 decimals) + let token_b_wanted = 500_000_000u64; // 0.5 tokens + let offer_id = 1u64; + + // ==================== PHASE 2: Create Token Accounts ==================== + // Maker needs: funded token A account, empty token B account (receives payment) + // Taker needs: empty token A account (receives offered tokens), funded token B account + + let maker_token_a = create_token_account( + rpc, + ctx, + &ctx.maker, + &ctx.mint_a_pubkey, + ctx.light_mint_a_authority.as_ref(), + ctx.spl_interface_a.as_ref(), + token_a_offered, + ) + .await; + + let maker_token_b = create_token_account( + rpc, + ctx, + &ctx.maker, + &ctx.mint_b_pubkey, + ctx.light_mint_b_authority.as_ref(), + ctx.spl_interface_b.as_ref(), + 0, + ) + .await; + + let taker_token_a = create_token_account( + rpc, + ctx, + &ctx.taker, + &ctx.mint_a_pubkey, + ctx.light_mint_a_authority.as_ref(), + ctx.spl_interface_a.as_ref(), + 0, + ) + .await; + + let taker_token_b = create_token_account( + rpc, + ctx, + &ctx.taker, + &ctx.mint_b_pubkey, + ctx.light_mint_b_authority.as_ref(), + ctx.spl_interface_b.as_ref(), + token_b_wanted, + ) + .await; + + // ==================== PHASE 3: Verify Initial State ==================== + verify_light_token_balance(rpc, maker_token_a, token_a_offered, "maker_token_a (initial)") + .await; + verify_light_token_balance(rpc, maker_token_b, 0, "maker_token_b (initial)").await; + verify_light_token_balance(rpc, taker_token_a, 0, "taker_token_a (initial)").await; + verify_light_token_balance(rpc, taker_token_b, token_b_wanted, "taker_token_b (initial)") + .await; + + // ==================== PHASE 4: Make Offer ==================== + // Transfers token A from maker to vault, creates offer account with escrow terms + + let (offer_pda, vault_pda, _) = { + let (offer_pda, _) = Pubkey::find_program_address( + &[ + escrow::OFFER_SEED, + ctx.maker.pubkey().as_ref(), + offer_id.to_le_bytes().as_ref(), + ], + &ctx.program_id, + ); + + let (vault_pda, vault_bump) = Pubkey::find_program_address( + &[escrow::VAULT_SEED, offer_pda.as_ref()], + &ctx.program_id, + ); + + // Validity proof: verifies that the offer PDA's derived address does not + // yet exist in Light's address tree. Required for any new Light Token mint. + let proof_result = get_create_accounts_proof( + rpc, + &ctx.program_id, + vec![CreateAccountsProofInput::pda(offer_pda)], + ) + .await + .unwrap(); + + let accounts = escrow::accounts::MakeOffer { + fee_payer: ctx.maker.pubkey(), + authority: ctx.authority_pda, + compression_config: ctx.compression_config, + token_mint_a: ctx.mint_a_pubkey, + token_mint_b: ctx.mint_b_pubkey, + maker_token_account_a: maker_token_a, + offer: offer_pda, + vault: vault_pda, + token_program: ctx.token_config.token_program_id(), + system_program: solana_sdk::system_program::ID, + light_token_program: Pubkey::new_from_array(LIGHT_TOKEN_PROGRAM_ID), + light_token_compressible_config: COMPRESSIBLE_CONFIG_V1, + light_token_rent_sponsor: RENT_SPONSOR, + light_token_cpi_authority: CPI_AUTHORITY_PDA, + spl_interface_pda_a: ctx + .spl_interface_a + .as_ref() + .map(|i| i.pda) + .unwrap_or_default(), + }; + + let data = escrow::instruction::MakeOffer { + params: escrow::MakeOfferParams { + create_accounts_proof: proof_result.create_accounts_proof, + id: offer_id, + token_a_offered_amount: token_a_offered, + token_b_wanted_amount: token_b_wanted, + vault_bump, + }, + }; + + // Light system accounts (registered program PDA, noop, account compression + // authority, output state tree queue, address tree) are appended as + // remaining_accounts. The Light system program reads these during CPI + // to verify the proof and insert the new address. + let ix = Instruction { + program_id: ctx.program_id, + accounts: [ + accounts.to_account_metas(None), + proof_result.remaining_accounts, + ] + .concat(), + data: data.data(), + }; + + rpc.create_and_send_transaction(&[ix], &ctx.maker.pubkey(), &[&ctx.maker]) + .await + .expect("make_offer should succeed"); + + (offer_pda, vault_pda, vault_bump) + }; + + // ==================== PHASE 5: Verify Offer State ==================== + // Vault should hold offered tokens, maker's account should be empty + verify_light_token_balance(rpc, vault_pda, token_a_offered, "vault (after make_offer)").await; + verify_light_token_balance(rpc, maker_token_a, 0, "maker_token_a (after make_offer)").await; + + let offer_account = rpc + .get_account(offer_pda) + .await + .unwrap() + .expect("Offer account should exist"); + assert!( + !offer_account.data.is_empty(), + "Offer account should have data" + ); + + // ==================== PHASE 6: Take Offer ==================== + // Taker sends wanted tokens (B) to maker, vault releases offered tokens (A) to taker, + // then vault and offer accounts are closed + + { + let accounts = escrow::accounts::TakeOffer { + taker: ctx.taker.pubkey(), + maker: ctx.maker.pubkey(), + authority: ctx.authority_pda, + token_mint_a: ctx.mint_a_pubkey, + token_mint_b: ctx.mint_b_pubkey, + taker_token_account_a: taker_token_a, + taker_token_account_b: taker_token_b, + maker_token_account_b: maker_token_b, + offer: offer_pda, + vault: vault_pda, + token_program: ctx.token_config.token_program_id(), + system_program: solana_sdk::system_program::ID, + light_token_program: Pubkey::new_from_array(LIGHT_TOKEN_PROGRAM_ID), + light_token_cpi_authority: CPI_AUTHORITY_PDA, + light_token_rent_sponsor: RENT_SPONSOR, + spl_interface_pda_a: ctx + .spl_interface_a + .as_ref() + .map(|i| i.pda) + .unwrap_or_default(), + spl_interface_pda_b: ctx + .spl_interface_b + .as_ref() + .map(|i| i.pda) + .unwrap_or_default(), + }; + + let data = escrow::instruction::TakeOffer {}; + + let ix = Instruction { + program_id: ctx.program_id, + accounts: accounts.to_account_metas(None), + data: data.data(), + }; + + rpc.create_and_send_transaction(&[ix], &ctx.taker.pubkey(), &[&ctx.taker]) + .await + .expect("take_offer should succeed"); + } + + // ==================== PHASE 7: Verify Final State ==================== + // Maker: gave token A, received token B + // Taker: gave token B, received token A + + verify_light_token_balance(rpc, maker_token_a, 0, "maker_token_a (final)").await; + verify_light_token_balance(rpc, maker_token_b, token_b_wanted, "maker_token_b (final)").await; + verify_light_token_balance(rpc, taker_token_a, token_a_offered, "taker_token_a (final)") + .await; + verify_light_token_balance(rpc, taker_token_b, 0, "taker_token_b (final)").await; + + // Verify offer account was closed + let offer_after = rpc.get_account(offer_pda).await.unwrap(); + assert!( + offer_after.is_none(), + "Offer account should be closed after take_offer" + ); +} + +// ============================================================================ +// Tests — one per token configuration: SPL, T22, Light. +// ============================================================================ + +/// SPL mint with SPL associated token accounts → Light token vault. +/// +/// Every transfer crosses standards (SPL ↔ Light) via `TransferInterfaceCpi` +/// with SPL interface PDAs. This is the baseline: same mint type as standard +/// SPL escrow, but the vault is a rent-free Light token account. +#[tokio::test] +async fn test_escrow_spl() { + let mut rpc = create_test_rpc().await; + let ctx = setup_escrow_test(&mut rpc, TokenConfig::Spl).await; + run_escrow_full_flow(&mut rpc, &ctx).await; +} + +/// Token-2022 mint with T22 associated token accounts → Light token vault. +/// +/// Every transfer crosses standards (T22 ↔ Light) via `TransferInterfaceCpi` +/// with SPL interface PDAs. Same pattern as `test_escrow_spl` but exercises +/// the Token-2022 program path. +#[tokio::test] +async fn test_escrow_t22() { + let mut rpc = create_test_rpc().await; + let ctx = setup_escrow_test(&mut rpc, TokenConfig::Token2022).await; + run_escrow_full_flow(&mut rpc, &ctx).await; +} + +/// Light mint + Light user accounts (rent-free path). +/// +/// All accounts are Light — transfers use `TransferCheckedCpi`. +#[tokio::test] +async fn test_escrow_light() { + let mut rpc = create_test_rpc().await; + let ctx = setup_escrow_test(&mut rpc, TokenConfig::Light).await; + run_escrow_full_flow(&mut rpc, &ctx).await; +} + +/// SPL mint + Light user accounts (interop). +/// +/// Tokens start in SPL associated token accounts, get converted into Light +/// token accounts during setup via `transfer_spl_to_light`. Once in Light +/// token accounts, all escrow transfers are Light-to-Light (`TransferCheckedCpi`). +/// Shows that Light token accounts can hold any SPL mint. +#[tokio::test] +async fn test_escrow_spl_light() { + let mut rpc = create_test_rpc().await; + let ctx = setup_escrow_test(&mut rpc, TokenConfig::LightSpl).await; + run_escrow_full_flow(&mut rpc, &ctx).await; +} + +/// Token-2022 mint + Light user accounts (interop). +/// +/// Tokens start in T22 associated token accounts, get converted into Light +/// token accounts during setup via `transfer_spl_to_light`. Once in Light +/// token accounts, all escrow transfers are Light-to-Light (`TransferCheckedCpi`). +/// Shows that Light token accounts can hold any T22 mint. +#[tokio::test] +async fn test_escrow_t22_light() { + let mut rpc = create_test_rpc().await; + let ctx = setup_escrow_test(&mut rpc, TokenConfig::LightT22).await; + run_escrow_full_flow(&mut rpc, &ctx).await; +} diff --git a/programs/anchor/escrow/tests/escrow_light.rs b/programs/anchor/escrow/tests/escrow_light.rs deleted file mode 100644 index 1e32937..0000000 --- a/programs/anchor/escrow/tests/escrow_light.rs +++ /dev/null @@ -1,17 +0,0 @@ -mod common; - -use common::{create_test_rpc, run_escrow_full_flow, run_escrow_make_offer, setup_escrow_test, TokenConfig}; - -#[tokio::test] -async fn test_escrow_full_flow_light() { - let mut rpc = create_test_rpc().await; - let ctx = setup_escrow_test(&mut rpc, TokenConfig::Light).await; - run_escrow_full_flow(&mut rpc, &ctx).await; -} - -#[tokio::test] -async fn test_escrow_make_offer_light() { - let mut rpc = create_test_rpc().await; - let ctx = setup_escrow_test(&mut rpc, TokenConfig::Light).await; - run_escrow_make_offer(&mut rpc, &ctx).await; -} diff --git a/programs/anchor/escrow/tests/escrow_spl.rs b/programs/anchor/escrow/tests/escrow_spl.rs deleted file mode 100644 index e51937f..0000000 --- a/programs/anchor/escrow/tests/escrow_spl.rs +++ /dev/null @@ -1,17 +0,0 @@ -mod common; - -use common::{create_test_rpc, run_escrow_full_flow, run_escrow_make_offer, setup_escrow_test, TokenConfig}; - -#[tokio::test] -async fn test_escrow_full_flow_spl() { - let mut rpc = create_test_rpc().await; - let ctx = setup_escrow_test(&mut rpc, TokenConfig::Spl).await; - run_escrow_full_flow(&mut rpc, &ctx).await; -} - -#[tokio::test] -async fn test_escrow_make_offer_spl() { - let mut rpc = create_test_rpc().await; - let ctx = setup_escrow_test(&mut rpc, TokenConfig::Spl).await; - run_escrow_make_offer(&mut rpc, &ctx).await; -} diff --git a/programs/anchor/escrow/tests/escrow_spl_light.rs b/programs/anchor/escrow/tests/escrow_spl_light.rs deleted file mode 100644 index 25fff28..0000000 --- a/programs/anchor/escrow/tests/escrow_spl_light.rs +++ /dev/null @@ -1,19 +0,0 @@ -mod common; - -use common::{ - create_test_rpc, run_escrow_full_flow, run_escrow_make_offer, setup_escrow_test, TokenConfig, -}; - -#[tokio::test] -async fn test_escrow_full_flow_spl_light() { - let mut rpc = create_test_rpc().await; - let ctx = setup_escrow_test(&mut rpc, TokenConfig::LightSpl).await; - run_escrow_full_flow(&mut rpc, &ctx).await; -} - -#[tokio::test] -async fn test_escrow_make_offer_spl_light() { - let mut rpc = create_test_rpc().await; - let ctx = setup_escrow_test(&mut rpc, TokenConfig::LightSpl).await; - run_escrow_make_offer(&mut rpc, &ctx).await; -} diff --git a/programs/anchor/escrow/tests/escrow_t22.rs b/programs/anchor/escrow/tests/escrow_t22.rs deleted file mode 100644 index d854b20..0000000 --- a/programs/anchor/escrow/tests/escrow_t22.rs +++ /dev/null @@ -1,17 +0,0 @@ -mod common; - -use common::{create_test_rpc, run_escrow_full_flow, run_escrow_make_offer, setup_escrow_test, TokenConfig}; - -#[tokio::test] -async fn test_escrow_full_flow_t22() { - let mut rpc = create_test_rpc().await; - let ctx = setup_escrow_test(&mut rpc, TokenConfig::Token2022).await; - run_escrow_full_flow(&mut rpc, &ctx).await; -} - -#[tokio::test] -async fn test_escrow_make_offer_t22() { - let mut rpc = create_test_rpc().await; - let ctx = setup_escrow_test(&mut rpc, TokenConfig::Token2022).await; - run_escrow_make_offer(&mut rpc, &ctx).await; -} diff --git a/programs/anchor/escrow/tests/escrow_t22_light.rs b/programs/anchor/escrow/tests/escrow_t22_light.rs deleted file mode 100644 index e15757c..0000000 --- a/programs/anchor/escrow/tests/escrow_t22_light.rs +++ /dev/null @@ -1,19 +0,0 @@ -mod common; - -use common::{ - create_test_rpc, run_escrow_full_flow, run_escrow_make_offer, setup_escrow_test, TokenConfig, -}; - -#[tokio::test] -async fn test_escrow_full_flow_t22_light() { - let mut rpc = create_test_rpc().await; - let ctx = setup_escrow_test(&mut rpc, TokenConfig::LightT22).await; - run_escrow_full_flow(&mut rpc, &ctx).await; -} - -#[tokio::test] -async fn test_escrow_make_offer_t22_light() { - let mut rpc = create_test_rpc().await; - let ctx = setup_escrow_test(&mut rpc, TokenConfig::LightT22).await; - run_escrow_make_offer(&mut rpc, &ctx).await; -} From 3adc0733792d567e3ffdc27a2e84224ccbd6d588 Mon Sep 17 00:00:00 2001 From: tilo-14 Date: Tue, 10 Feb 2026 13:15:50 +0000 Subject: [PATCH 04/10] Fix SPL_COMPARISON.md code blocks and update CLAUDE.md SPL_COMPARISON.md: align all Light code blocks with actual source. Sections 4-6 had wrong struct fields, function signatures, and implementations. Section 8 showed outdated 5-file test structure. Terminology normalized (associated token accounts, cross-standard). CLAUDE.md: update test architecture section to match consolidated test structure and terminology. --- CLAUDE.md | 130 ++++++++++++++----- programs/anchor/escrow/SPL_COMPARISON.md | 152 +++++++++++------------ 2 files changed, 176 insertions(+), 106 deletions(-) diff --git a/CLAUDE.md b/CLAUDE.md index 1b3cec6..9e777df 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -21,7 +21,7 @@ cargo test-sbf -p light-token-minter cargo test-sbf -p swap_example # Run a single test function -cargo test-sbf -p escrow -- test_escrow_light_full_flow +cargo test-sbf -p escrow -- test_escrow_light ``` ### TypeScript Client (from `typescript-client/`) @@ -29,7 +29,7 @@ cargo test-sbf -p escrow -- test_escrow_light_full_flow ```bash npm install -# Run all tests (requires light test-validator) +# Run all tests npm run test:all # Run specific categories @@ -45,10 +45,7 @@ npm run mint-to:instruction ### Local Test Validator ```bash -# Start Light test validator (blocks terminal) light test-validator - -# TypeScript tests require validator running with Photon indexer ``` ## Requirements @@ -59,6 +56,8 @@ light test-validator - Node 22 - Light CLI: `npm i -g @lightprotocol/zk-compression-cli@alpha` +**Dependency pins**: The workspace pins `blake3 = "=1.5.5"` for solana-program compatibility and `time = "=0.3.41"` to avoid edition2024 requirements from cargo build-sbf. + ## Repository Structure ``` @@ -72,6 +71,10 @@ programs/anchor/ # Anchor Solana programs typescript-client/ # TypeScript SDK examples ├── actions/ # High-level convenience functions └── instructions/ # Low-level instruction builders + +toolkits/ # Integration examples +├── payments-and-wallets/ # Wallet integration patterns (TypeScript) +└── streaming-tokens/ # Laserstream mint event streaming (Rust) ``` ## Program Architecture @@ -81,6 +84,7 @@ Programs use Light Protocol's compressed account model: - `#[light_program]` macro enables Light account support - `derive_light_cpi_signer!` generates CPI signer for Light operations - `get_create_accounts_proof()` fetches ZK proofs for account creation +- `TransferInterfaceCpi` transfers between Light/SPL/T22 accounts ### Light Protocol Integration Pattern @@ -97,45 +101,115 @@ pub mod my_program { ... } let config = initialize_rent_free_config(rpc, &payer, &program_id).await; ``` +### SPL Interface PDAs + +For transfers between SPL/T22 and Light accounts, create an SPL interface PDA: + +```rust +// Required for LightSpl/LightT22 token configs +let iface = create_spl_interface_pda(rpc, &payer, &mint, MintType::Spl, false).await; +``` + +## Escrow Program Architecture + +The escrow (`programs/anchor/escrow/`) implements a peer-to-peer token swap using make/take pattern. It differs from a standard SPL escrow in three key ways: a separate authority PDA signs for the vault, the vault is a Light token account (rent-free), and transfers route through a dual-path function that picks Light-to-Light or cross-standard CPI based on account ownership. + +### Escrow Flow + +**`make_offer`**: Maker deposits token A into a vault and records offer terms. + +1. Client calls `get_create_accounts_proof(rpc, &program_id, vec![pda(offer_pda)])` to obtain a ZK proof that the offer account address does not yet exist in the address tree +2. Program transfers token A from maker to vault via `transfer_tokens()` +3. Program writes offer state (maker, mints, wanted amount, auth_bump) + +**`take_offer`**: Taker completes the swap and closes the vault. + +1. Transfer token B from taker to maker via `transfer_tokens()` +2. Withdraw token A from vault to taker via `transfer_tokens()` (signed by authority PDA) +3. Close vault via `CloseAccountCpi`, returning rent sponsor lamports to `RENT_SPONSOR` + +### PDA Derivation Chain + +PDAs derive in sequence -- vault depends on offer: + +``` +authority_pda = PDA([b"authority"], program_id) -- signs vault operations +offer_pda = PDA([b"offer", maker, id_le_bytes], program_id) -- stores offer terms +vault_pda = PDA([b"vault", offer_pda], program_id) -- holds escrowed token A +``` + +The authority PDA (not the offer account) is the vault's token owner. This differs from standard SPL escrow where the offer account itself owns the vault. + +### Dual Transfer Path (`shared.rs`) + +`transfer_tokens()` in `instructions/shared.rs` selects the CPI path at runtime based on `is_light_account()`, which checks whether an account is owned by `LIGHT_TOKEN_PROGRAM_ID`: + +- **Light-to-Light** (`is_light_account(from) && is_light_account(to)`): Uses `TransferCheckedCpi` with `fee_payer: Some(payer)` to keep the authority account readonly (required when authority is a PDA with account data). +- **Cross-standard** (any other combination): Uses `TransferInterfaceCpi` with `SplInterfaceConfig` containing the mint `AccountInfo`, SPL token program `AccountInfo`, interface PDA `AccountInfo`, and bump. The caller always passes `SplInterfaceConfig` -- for Light-to-Light it's ignored, for cross-standard it's required. + +### Light Protocol Accounts on Instructions + +Beyond standard Anchor accounts, Light instructions require: + +- `light_token_program` — Light token program for CPI (readonly) +- `light_token_compressible_config` — global config at `COMPRESSIBLE_CONFIG_V1` (readonly) +- `light_token_rent_sponsor` — pays rent exemption at `RENT_SPONSOR` (mut) +- `light_token_cpi_authority` — CPI authority PDA for Light operations (mut) +- `spl_interface_pda_*` — per-mint interface PDA for SPL<->Light transfers (mut) +- `compression_config` — per-program rent-free config, make_offer only (readonly) + +### Offer State + +`Offer` (`state/offer.rs`) derives both `#[account]` and `LightAccount`: + +```rust +pub struct Offer { + pub compression_info: Option, // Light Protocol metadata + pub id: u64, + pub maker: Pubkey, + pub token_mint_a: Pubkey, + pub token_mint_b: Pubkey, + pub token_b_wanted_amount: u64, + pub auth_bump: u8, // authority PDA bump (not offer bump) +} +``` + +The `#[light_account(init)]` attribute on the offer account in `MakeOffer` triggers Light Protocol's compressed account initialization. The vault uses `#[light_account(init, token::...)]` to create a Light token account with the authority PDA as owner. + ## Test Architecture -### Test File Naming Convention +### Escrow Tests -Each program tests five token type combinations: +All five token configurations live in a single file (`tests/escrow.rs`) with a module-level doc that explains the three architectural differences from standard SPL escrow and a scenario table mapping each test to its mint type, user account type, and transfer path. Each test function has a doc comment describing the specific token flow it exercises. -| File suffix | Mint type | User accounts | Description | -| ----------------- | ---------- | ------------- | -------------------------- | -| `*_spl.rs` | SPL | SPL ATAs | Standard SPL tokens | -| `*_t22.rs` | Token-2022 | T22 ATAs | Token-2022 tokens | -| `*_light.rs` | Light mint | Light ATAs | Pure Light-to-Light | -| `*_spl_light.rs` | SPL | Light ATAs | SPL mint → Light accounts | -| `*_t22_light.rs` | Token-2022 | Light ATAs | T22 mint → Light accounts | +`run_escrow_full_flow` builds and sends `make_offer` / `take_offer` instructions inline (no helper wrappers — the full instruction construction is visible in context). `tests/common/mod.rs` contains only setup: `TokenConfig` enum, `EscrowTestContext` struct, `create_test_rpc`, `setup_escrow_test`, and `create_token_account`. ### TokenConfig Enum -Tests use `TokenConfig` to parameterize behavior: - ```rust pub enum TokenConfig { - Spl, // SPL mint + SPL ATAs - Token2022, // T22 mint + T22 ATAs - Light, // Light mint + Light ATAs - LightSpl, // SPL mint + Light ATAs (requires SPL interface PDA) - LightT22, // T22 mint + Light ATAs (requires SPL interface PDA) + Spl, // SPL mint + SPL associated token accounts + Token2022, // T22 mint + T22 associated token accounts + Light, // Light mint + Light associated token accounts + LightSpl, // SPL mint + Light associated token accounts + LightT22, // T22 mint + Light associated token accounts } ``` +`setup_escrow_test` creates SPL interface PDAs for all SPL/T22 configs (Spl, Token2022, LightSpl, LightT22) because the vault is always a Light token account — any transfer involving an SPL/T22 account and the Light vault crosses standards and requires an interface PDA. + ### Shared Test Utilities -`shared-test-utils` provides reusable helpers organized by token type: +`shared-test-utils` (`programs/anchor/shared-test-utils/src/lib.rs`) provides reusable helpers: -- `spl_tokens::` - Create SPL mints, ATAs, mint tokens -- `t22_tokens::` - Create Token-2022 mints, ATAs, mint tokens -- `light_tokens::` - Create Light mints, ATAs, mint tokens -- `spl_interface::` - SPL interface PDAs for cross-standard transfers -- `helpers::` - Balance verification, proof helpers +- `setup::` - `initialize_rent_free_config`, `create_program_test` +- `spl_tokens::` - `create_spl_mint`, `create_spl_ata`, `mint_spl_tokens` +- `t22_tokens::` - `create_t22_mint`, `create_t22_ata`, `mint_t22_tokens` +- `light_tokens::` - `create_light_mint`, `create_light_ata`, `mint_light_tokens` +- `spl_interface::` - `create_spl_interface_pda`, `transfer_spl_to_light` +- `helpers::` - `verify_light_token_balance`, `verify_spl_token_balance`, `get_creation_proof`, `airdrop` -Each program's `tests/common/mod.rs` builds on these utilities for program-specific test context. +Each program's `tests/common/mod.rs` builds on these for program-specific context (e.g., `EscrowTestContext`). ## TypeScript Pattern diff --git a/programs/anchor/escrow/SPL_COMPARISON.md b/programs/anchor/escrow/SPL_COMPARISON.md index 12b50e3..4727837 100644 --- a/programs/anchor/escrow/SPL_COMPARISON.md +++ b/programs/anchor/escrow/SPL_COMPARISON.md @@ -242,9 +242,8 @@ pub struct MakeOffer<'info> { #[account(seeds = [AUTH_SEED], bump)] pub authority: UncheckedAccount<'info>, - /// CHECK: Rent-free config for this program - #[account(mut)] - pub compression_config: UncheckedAccount<'info>, + /// CHECK: Config for light mint creation + pub compression_config: AccountInfo<'info>, #[account(mint::token_program = token_program)] pub token_mint_a: InterfaceAccount<'info, Mint>, @@ -252,10 +251,12 @@ pub struct MakeOffer<'info> { #[account(mint::token_program = token_program)] pub token_mint_b: InterfaceAccount<'info, Mint>, - /// User's source token account (Light or SPL) - /// CHECK: Verified by Light token program - #[account(mut)] - pub maker_token_account_a: UncheckedAccount<'info>, + #[account( + mut, + token::mint = token_mint_a, + token::authority = fee_payer, + )] + pub maker_token_account_a: InterfaceAccount<'info, TokenAccount>, #[account( init, @@ -271,7 +272,7 @@ pub struct MakeOffer<'info> { #[account( mut, seeds = [VAULT_SEED, offer.key().as_ref()], - bump = params.vault_bump, + bump, )] #[light_account(init, token::authority = [VAULT_SEED, self.offer.key()], @@ -299,7 +300,8 @@ pub struct MakeOffer<'info> { #[account(mut)] pub light_token_cpi_authority: AccountInfo<'info>, - /// CHECK: SPL interface PDA for cross-protocol transfers + /// CHECK: SPL interface PDA for mint A + #[account(mut)] pub spl_interface_pda_a: UncheckedAccount<'info>, } ``` @@ -310,7 +312,7 @@ pub struct MakeOffer<'info> { | ------ | --- | ----- | | Derive | `Accounts` | `Accounts` + `LightAccounts` | | Vault type | `InterfaceAccount` | `UncheckedAccount` with `#[light_account]` | -| Token accounts | Typed `InterfaceAccount` | `UncheckedAccount` (Light Token program validates account state during CPI) | +| Token accounts | Typed `InterfaceAccount` | `InterfaceAccount` with token constraints | | Authority | Offer account itself | Separate `authority` PDA | | Extra accounts | 3 (system, token, ata) | 7+ (+ Light protocol accounts) | @@ -351,19 +353,20 @@ pub fn transfer_tokens<'info>( ```rust // programs/anchor/escrow/src/instructions/shared.rs use anchor_lang::prelude::*; -use light_token::anchor::{TransferCheckedCpi, TransferInterfaceCpi}; -use solana_program::account_info::AccountInfo; +use light_sdk::constants::LIGHT_TOKEN_PROGRAM_ID; +use light_token::instruction::{TransferCheckedCpi, TransferInterfaceCpi}; -/// Configuration for SPL<->Light interface transfers +/// Configuration for SPL interface (required for SPL<->Light transfers) pub struct SplInterfaceConfig<'info> { - pub pda: AccountInfo<'info>, - pub bump: u8, - pub restricted: bool, + pub mint: AccountInfo<'info>, + pub spl_token_program: AccountInfo<'info>, + pub spl_interface_pda: AccountInfo<'info>, + pub spl_interface_pda_bump: u8, } -/// Check if an account is a Light token account (>165 bytes indicates presence of CompressionInfo metadata) +/// Check if an account is a Light token account (owned by Light token program) fn is_light_account(account: &AccountInfo) -> bool { - account.data_len() > 165 + account.owner == &Pubkey::new_from_array(LIGHT_TOKEN_PROGRAM_ID) } pub fn transfer_tokens<'info>( @@ -379,21 +382,20 @@ pub fn transfer_tokens<'info>( signer_seeds: Option<&[&[u8]]>, spl_interface: Option>, ) -> Result<()> { - // Call is_light_account() on source and destination to select transfer path let is_light_to_light = is_light_account(&from) && is_light_account(&to); if is_light_to_light { - // Pure Light-to-Light transfer + // fee_payer: Some ensures authority is readonly (required for PDA with account data) let cpi = TransferCheckedCpi { - token_program: light_token_cpi_authority.clone(), - from, - to, - owner: authority.clone(), + source: from, mint, - payer, - system_program, + destination: to, amount, decimals, + authority, + system_program, + max_top_up: Some(0), + fee_payer: Some(payer), }; if let Some(seeds) = signer_seeds { @@ -403,22 +405,26 @@ pub fn transfer_tokens<'info>( } .map_err(|e| anchor_lang::prelude::ProgramError::from(e).into()) } else { - // SPL<->Light transfer via interface let mut cpi = TransferInterfaceCpi::new( - light_token_cpi_authority.clone(), + amount, + decimals, from, to, - authority.clone(), - mint, + authority, payer, + light_token_cpi_authority, system_program, - amount, - decimals, ); - // Add SPL interface configuration if provided if let Some(spl) = spl_interface { - cpi = cpi.with_spl_interface(spl.pda, spl.bump, spl.restricted)?; + cpi = cpi + .with_spl_interface( + Some(spl.mint), + Some(spl.spl_token_program), + Some(spl.spl_interface_pda), + Some(spl.spl_interface_pda_bump), + ) + .map_err(|e| anchor_lang::prelude::ProgramError::from(e))?; } if let Some(seeds) = signer_seeds { @@ -437,8 +443,8 @@ pub fn transfer_tokens<'info>( | ------ | --- | ----- | | Function params | 6 typed params | 11 params including Light infra | | Transfer type | Single `transfer_checked` | Conditional: `TransferCheckedCpi` or `TransferInterfaceCpi` | -| Account detection | N/A | `is_light_account()` checks data length | -| Cross-protocol | Not supported | `SplInterfaceConfig` for SPL<->Light | +| Account detection | N/A | `is_light_account()` checks account owner (`LIGHT_TOKEN_PROGRAM_ID`) | +| Cross-standard | Not supported | `SplInterfaceConfig` for SPL<->Light | | CPI pattern | `CpiContext::new()` | `TransferCheckedCpi`/`TransferInterfaceCpi` struct + `invoke()` | --- @@ -495,30 +501,29 @@ pub fn withdraw_and_close_vault(ctx: Context) -> Result<()> { ### Light (light-token-escrow-fixes) ```rust -// programs/anchor/escrow/src/instructions/take_offer.rs:140-178 +// programs/anchor/escrow/src/instructions/take_offer.rs:122-178 // Separate withdrawal function pub fn withdraw_from_vault(ctx: &Context) -> Result<()> { - let auth_bump = ctx.accounts.offer.auth_bump; - let authority_seeds: &[&[u8]] = &[AUTH_SEED, &[auth_bump]]; + let offer = &ctx.accounts.offer; + let authority_seeds = &[AUTH_SEED, &[offer.auth_bump]]; - // Get vault balance - let vault_data = ctx.accounts.vault.try_borrow_data()?; - let vault_amount = if vault_data.len() >= 72 { - u64::from_le_bytes(vault_data[64..72].try_into().unwrap()) - } else { - return Err(ErrorCode::InvalidVaultData.into()); - }; - drop(vault_data); + let vault_balance = get_token_account_balance(&ctx.accounts.vault.to_account_info()) + .map_err(|_| anchor_lang::prelude::ProgramError::InvalidAccountData)?; - // Determine if SPL interface needed - let spl_interface = get_spl_interface_config( - &ctx.accounts.spl_interface_pda_a, - &ctx.accounts.token_mint_a, - ); + let decimals_a = ctx.accounts.token_mint_a.decimals; + let (_, spl_interface_bump_a) = + find_spl_interface_pda(&ctx.accounts.token_mint_a.key(), false); + + let spl_interface = SplInterfaceConfig { + mint: ctx.accounts.token_mint_a.to_account_info(), + spl_token_program: ctx.accounts.token_program.to_account_info(), + spl_interface_pda: ctx.accounts.spl_interface_pda_a.to_account_info(), + spl_interface_pda_bump: spl_interface_bump_a, + }; transfer_tokens( - vault_amount, - ctx.accounts.token_mint_a.decimals, + vault_balance, + decimals_a, ctx.accounts.vault.to_account_info(), ctx.accounts.taker_token_account_a.to_account_info(), ctx.accounts.token_mint_a.to_account_info(), @@ -527,7 +532,7 @@ pub fn withdraw_from_vault(ctx: &Context) -> Result<()> { ctx.accounts.light_token_cpi_authority.to_account_info(), ctx.accounts.system_program.to_account_info(), Some(authority_seeds), - spl_interface, + Some(spl_interface), ) } @@ -554,7 +559,7 @@ pub fn close_vault(ctx: &Context) -> Result<()> { | ------ | --- | ----- | | Functions | 1 combined | 2 separate (`withdraw_from_vault` + `close_vault`) | | Authority | Offer account | Separate authority PDA | -| Balance read | `ctx.accounts.vault.amount` | Manual byte parsing from account data | +| Balance read | `ctx.accounts.vault.amount` | `get_token_account_balance()` utility | | Close CPI | `close_account()` from anchor_spl | `CloseAccountCpi` from light_token | | Rent return | To maker | To taker (rent sponsor refund) | @@ -665,22 +670,18 @@ describe('Escrow', () => { programs/anchor/escrow/ └── tests/ ├── common/ - │ └── mod.rs # Shared test utilities - ├── escrow_spl.rs # SPL-only tests - ├── escrow_t22.rs # Token-2022 tests - ├── escrow_light.rs # Light-to-Light tests - ├── escrow_spl_light.rs # SPL mint + Light accounts - └── escrow_t22_light.rs # T22 mint + Light accounts + │ └── mod.rs # Shared setup: TokenConfig, EscrowTestContext, create_token_account + └── escrow.rs # 5 test functions (one per token configuration) ``` ```rust // tests/common/mod.rs (key abstractions) pub enum TokenConfig { - Spl, // SPL mint + SPL ATAs - Token2022, // T22 mint + T22 ATAs - Light, // Light mint + Light ATAs - LightSpl, // SPL mint + Light ATAs - LightT22, // T22 mint + Light ATAs + Spl, // SPL mint + SPL associated token accounts + Token2022, // T22 mint + T22 associated token accounts + Light, // Light mint + Light associated token accounts + LightSpl, // SPL mint + Light associated token accounts + LightT22, // T22 mint + Light associated token accounts } pub struct EscrowTestContext { @@ -698,17 +699,12 @@ pub async fn setup_escrow_test( rpc: &mut R, config: TokenConfig, ) -> EscrowTestContext { ... } - -pub async fn run_escrow_full_flow( - rpc: &mut R, - ctx: &EscrowTestContext, -) { ... } ``` ```rust -// tests/escrow_light.rs +// tests/escrow.rs — run_escrow_full_flow lives here, called by each test #[tokio::test] -async fn test_escrow_full_flow_light() { +async fn test_escrow_light() { let mut rpc = create_test_rpc().await; let ctx = setup_escrow_test(&mut rpc, TokenConfig::Light).await; run_escrow_full_flow(&mut rpc, &ctx).await; @@ -721,7 +717,7 @@ async fn test_escrow_full_flow_light() { | ------ | --- | ----- | | Language | TypeScript | Rust | | Framework | Mocha + Chai | tokio + cargo test-sbf | -| Test files | 1 | 5 (per token combination) | +| Test files | 1 | 1 (5 test functions) | | Setup | `@solana-developers/helpers` | `shared-test-utils` crate | | Parametric | No | Yes (`TokenConfig` enum) | @@ -789,7 +785,7 @@ pub async fn create_spl_interface_pda( ### Light Token Account Creation ```rust -// Creating a Light token account (ATA equivalent) +// Creating a Light associated token account pub async fn create_light_ata( rpc: &mut R, payer: &Keypair, @@ -810,11 +806,11 @@ pub async fn create_light_ata( .with_compressible(compressible_params) .idempotent() .instruction() - .expect("Create Light ATA instruction should succeed"); + .expect("Create Light associated token account instruction should succeed"); rpc.create_and_send_transaction(&[create_ata_ix], &payer.pubkey(), &[payer]) .await - .expect("Create Light ATA should succeed"); + .expect("Create Light associated token account should succeed"); let (ata, _) = derive_token_ata(owner, mint); ata From 4af2df28cb73d9d611c413d92ea863c1987fbf8d Mon Sep 17 00:00:00 2001 From: tilo-14 Date: Wed, 11 Feb 2026 16:12:23 +0000 Subject: [PATCH 05/10] after bump --- programs/anchor/Cargo.lock | 673 +++++++----- programs/anchor/Cargo.toml | 40 +- programs/anchor/escrow/Cargo.toml | 10 +- .../escrow/src/instructions/make_offer.rs | 21 +- .../escrow/src/instructions/take_offer.rs | 4 +- programs/anchor/escrow/src/lib.rs | 2 +- programs/anchor/escrow/src/state/offer.rs | 4 +- programs/anchor/escrow/tests/common/mod.rs | 8 +- programs/anchor/escrow/tests/escrow.rs | 418 ++++++-- programs/anchor/fundraiser/Cargo.toml | 10 +- programs/anchor/fundraiser/src/constants.rs | 1 + programs/anchor/fundraiser/src/error.rs | 2 + .../fundraiser/src/instructions/checker.rs | 21 +- .../fundraiser/src/instructions/contribute.rs | 21 +- .../fundraiser/src/instructions/initialize.rs | 24 +- .../fundraiser/src/instructions/refund.rs | 25 +- programs/anchor/fundraiser/src/lib.rs | 2 +- .../anchor/fundraiser/src/state/fundraiser.rs | 1 + .../anchor/fundraiser/tests/common/mod.rs | 14 +- programs/anchor/light-token-minter/Cargo.toml | 10 +- .../src/instructions/create.rs | 14 +- .../src/instructions/mint.rs | 12 +- programs/anchor/light-token-minter/src/lib.rs | 2 +- .../light-token-minter/tests/minter_test.rs | 30 +- programs/anchor/shared-test-utils/Cargo.toml | 1 + programs/anchor/shared-test-utils/src/lib.rs | 31 +- programs/anchor/token-swap/Cargo.toml | 6 +- programs/anchor/token-swap/SPL_COMPARISON.md | 968 ++++++++++++++++++ .../src/instructions/create_pool.rs | 25 +- .../src/instructions/create_pool_light_lp.rs | 29 +- .../src/instructions/deposit_liquidity.rs | 17 +- .../swap_exact_tokens_for_tokens.rs | 16 +- .../src/instructions/withdraw_liquidity.rs | 17 +- programs/anchor/token-swap/src/lib.rs | 4 +- .../anchor/token-swap/tests/common/mod.rs | 30 +- 35 files changed, 1975 insertions(+), 538 deletions(-) create mode 100644 programs/anchor/token-swap/SPL_COMPARISON.md diff --git a/programs/anchor/Cargo.lock b/programs/anchor/Cargo.lock index 70a9b29..ad44797 100644 --- a/programs/anchor/Cargo.lock +++ b/programs/anchor/Cargo.lock @@ -126,8 +126,6 @@ dependencies = [ [[package]] name = "aligned-sized" version = "1.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "48a526ec4434d531d488af59fe866f36b310fe8906691c75dffa664450a3800a" dependencies = [ "proc-macro2", "quote", @@ -680,6 +678,28 @@ version = "1.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c08606f8c3cbf4ce6ec8e28fb0014a2c086708fe954eaa885384a6165172e7e8" +[[package]] +name = "aws-lc-rs" +version = "1.15.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7b7b6141e96a8c160799cc2d5adecd5cbbe5054cb8c7c4af53da0f83bb7ad256" +dependencies = [ + "aws-lc-sys", + "zeroize", +] + +[[package]] +name = "aws-lc-sys" +version = "0.37.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5c34dda4df7017c8db52132f0f8a2e0f8161649d15723ed63fc00c82d0f2081a" +dependencies = [ + "cc", + "cmake", + "dunce", + "fs_extra", +] + [[package]] name = "az" version = "1.2.1" @@ -952,6 +972,12 @@ dependencies = [ "shlex", ] +[[package]] +name = "cesu8" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6d43a04d8753f35258c91f8ec639f792891f748a1edbd759cf1dcea3382ad83c" + [[package]] name = "cfg-if" version = "1.0.4" @@ -984,7 +1010,6 @@ dependencies = [ "iana-time-zone", "js-sys", "num-traits", - "serde", "wasm-bindgen", "windows-link", ] @@ -999,6 +1024,15 @@ dependencies = [ "inout", ] +[[package]] +name = "cmake" +version = "0.1.57" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "75443c44cd6b379beb8c5b45d85d0773baf31cce901fe7bb252f4eff3008ef7d" +dependencies = [ + "cc", +] + [[package]] name = "combine" version = "3.8.1" @@ -1012,6 +1046,16 @@ dependencies = [ "unreachable", ] +[[package]] +name = "combine" +version = "4.6.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ba5a308b75df32fe02788e748662718f03fde005016435c444eea572398219fd" +dependencies = [ + "bytes", + "memchr", +] + [[package]] name = "compression-codecs" version = "0.4.36" @@ -1079,6 +1123,16 @@ dependencies = [ "libc", ] +[[package]] +name = "core-foundation" +version = "0.10.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b2a6cd9ae233e7f62ba4e9353e81a88df7fc8a5987b8d445b4d90c879bd156f6" +dependencies = [ + "core-foundation-sys", + "libc", +] + [[package]] name = "core-foundation-sys" version = "0.8.7" @@ -1250,16 +1304,6 @@ dependencies = [ "syn 2.0.114", ] -[[package]] -name = "deranged" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9c9e6a11ca8224451684bc0d7d5a7adbf8f2fd6887261a1cfc3c0432f9d4068e" -dependencies = [ - "powerfmt", - "serde", -] - [[package]] name = "derivation-path" version = "0.2.0" @@ -1309,10 +1353,10 @@ dependencies = [ ] [[package]] -name = "dyn-clone" -version = "1.0.20" +name = "dunce" +version = "1.0.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d0881ea181b1df73ff77ffaaf9c7544ecc11e82fba9b5f27b262a3c73a332555" +checksum = "92773504d58c093f6de2459af4af33faa518c13451eb8f2b5698ed3d36e7c813" [[package]] name = "eager" @@ -1489,8 +1533,10 @@ dependencies = [ "anchor-lang", "anchor-spl", "blake3", + "light-account", "light-anchor-spl", "light-client", + "light-compressed-account", "light-hasher", "light-program-test", "light-sdk", @@ -1617,6 +1663,12 @@ dependencies = [ "percent-encoding", ] +[[package]] +name = "fs_extra" +version = "1.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "42703706b716c37f96a77aea830392ad231f44c9e9a67872fa5548707e11b11c" + [[package]] name = "fundraiser" version = "0.1.0" @@ -1624,8 +1676,10 @@ dependencies = [ "anchor-lang", "anchor-spl", "blake3", + "light-account", "light-anchor-spl", "light-client", + "light-compressed-account", "light-hasher", "light-program-test", "light-sdk", @@ -1827,7 +1881,7 @@ dependencies = [ "futures-sink", "futures-util", "http 0.2.12", - "indexmap 2.13.0", + "indexmap", "slab", "tokio", "tokio-util 0.7.18", @@ -1846,7 +1900,7 @@ dependencies = [ "futures-core", "futures-sink", "http 1.4.0", - "indexmap 2.13.0", + "indexmap", "slab", "tokio", "tokio-util 0.7.18", @@ -1873,12 +1927,6 @@ dependencies = [ "byteorder", ] -[[package]] -name = "hashbrown" -version = "0.12.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8a9ee70c43aaf417c914396645a0fa852624801b24ebb7ae78fe8272889ac888" - [[package]] name = "hashbrown" version = "0.13.2" @@ -1929,12 +1977,6 @@ dependencies = [ "libc", ] -[[package]] -name = "hex" -version = "0.4.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7f24254aa9a54b5c858eaee2f5bccdb46aaf0e486a595ed5fd8f86ba55232a70" - [[package]] name = "hmac" version = "0.8.1" @@ -2302,17 +2344,6 @@ dependencies = [ "icu_properties", ] -[[package]] -name = "indexmap" -version = "1.9.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bd070e393353796e801d209ad339e89596eb4c8d430d18ede6a1cced8fafbd99" -dependencies = [ - "autocfg", - "hashbrown 0.12.3", - "serde", -] - [[package]] name = "indexmap" version = "2.13.0" @@ -2321,8 +2352,6 @@ checksum = "7714e70437a7dc3ac8eb7e6f8df75fd8eb422675fc7678aff7364301092b1017" dependencies = [ "equivalent", "hashbrown 0.16.1", - "serde", - "serde_core", ] [[package]] @@ -2405,6 +2434,28 @@ version = "1.0.17" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "92ecc6618181def0457392ccd0ee51198e065e016d1d527a7ac1b6dc7c1f09d2" +[[package]] +name = "jni" +version = "0.21.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1a87aa2bb7d2af34197c04845522473242e1aa17c12f4935d5856491a7fb8c97" +dependencies = [ + "cesu8", + "cfg-if", + "combine 4.6.7", + "jni-sys", + "log", + "thiserror 1.0.69", + "walkdir", + "windows-sys 0.45.0", +] + +[[package]] +name = "jni-sys" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8eaf4bc02d17cbdd7ff4c7438cafcdf7fb9a4613313ad11b4f8fefe7d3fa0130" + [[package]] name = "jobserver" version = "0.1.34" @@ -2519,16 +2570,35 @@ dependencies = [ "libsecp256k1-core", ] +[[package]] +name = "light-account" +version = "0.20.0" +dependencies = [ + "anchor-lang", + "light-account-checks", + "light-compressed-account", + "light-compressible", + "light-hasher", + "light-macros", + "light-sdk-macros", + "light-sdk-types", + "light-token-interface", + "solana-account-info", + "solana-instruction", + "solana-pubkey", +] + [[package]] name = "light-account-checks" -version = "0.7.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f20b8640212dd450e18d452a247e28d8ba6fdce3c713fd8b69f1e95874d1b7ab" +version = "0.8.0" dependencies = [ "solana-account-info", + "solana-cpi", + "solana-instruction", "solana-msg", "solana-program-error", "solana-pubkey", + "solana-system-interface", "solana-sysvar", "thiserror 2.0.18", ] @@ -2551,17 +2621,13 @@ dependencies = [ [[package]] name = "light-array-map" version = "0.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9bdd13b18028ac9d80d0a987551c0dad7fe81be8140e87cc9d568b80f3728203" dependencies = [ "tinyvec", ] [[package]] name = "light-batched-merkle-tree" -version = "0.9.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "01e838c523b49371097f948cd5662bd9a89d9dca037fb61fd38001e99f485702" +version = "0.10.0" dependencies = [ "aligned-sized", "borsh 0.10.4", @@ -2585,8 +2651,6 @@ dependencies = [ [[package]] name = "light-bloom-filter" version = "0.6.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "380b8cf734ccf5fbc1f5fed8e5308b57ebde6774d9304c167bcb0de2854412d8" dependencies = [ "bitvec", "num-bigint 0.4.6", @@ -2609,9 +2673,7 @@ dependencies = [ [[package]] name = "light-client" -version = "0.19.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "33203f596d48d28d1cb67dee5762b151e0073207a5e828c63ec68f9efb9a5ee8" +version = "0.21.0" dependencies = [ "anchor-lang", "async-trait", @@ -2620,7 +2682,9 @@ dependencies = [ "bs58", "futures", "lazy_static", + "light-account", "light-compressed-account", + "light-compressed-token-sdk", "light-compressible", "light-concurrent-merkle-tree", "light-event", @@ -2629,12 +2693,15 @@ dependencies = [ "light-merkle-tree-metadata", "light-prover-client", "light-sdk", + "light-sdk-types", "light-token", "light-token-interface", "litesvm", "num-bigint 0.4.6", "photon-api", "rand 0.8.5", + "reqwest 0.12.28", + "serde_json", "smallvec", "solana-account", "solana-account-decoder-client-types", @@ -2664,9 +2731,7 @@ dependencies = [ [[package]] name = "light-compressed-account" -version = "0.9.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a9c3537bbad9df133ca97fc191b164bba93dba1de4da01a92d979ef63f8ce106" +version = "0.10.1" dependencies = [ "anchor-lang", "borsh 0.10.4", @@ -2684,11 +2749,34 @@ dependencies = [ "zerocopy", ] +[[package]] +name = "light-compressed-token-sdk" +version = "0.20.0" +dependencies = [ + "anchor-lang", + "arrayvec", + "borsh 0.10.4", + "light-account", + "light-account-checks", + "light-compressed-account", + "light-program-profiler", + "light-sdk", + "light-sdk-types", + "light-token-interface", + "light-token-types", + "light-zero-copy", + "solana-account-info", + "solana-cpi", + "solana-instruction", + "solana-msg", + "solana-program-error", + "solana-pubkey", + "thiserror 2.0.18", +] + [[package]] name = "light-compressible" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "00d1dc14271907009f4ca23ae99c49279f7d2acc5a83f0f8d7362834b37e2e16" +version = "0.5.0" dependencies = [ "aligned-sized", "anchor-lang", @@ -2710,8 +2798,6 @@ dependencies = [ [[package]] name = "light-concurrent-merkle-tree" version = "5.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "db96f47253a0907aaa46dac15cecb27b5510130e48da0b36690dcd2e99a6d558" dependencies = [ "borsh 0.10.4", "light-bounded-vec", @@ -2723,13 +2809,12 @@ dependencies = [ [[package]] name = "light-event" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a4bae725ee1d4d944d442ac0bfdf2031b1b2379c04c7e39c475277aaaea08fb1" +version = "0.21.0" dependencies = [ "borsh 0.10.4", "light-compressed-account", "light-hasher", + "light-token-interface", "light-zero-copy", "thiserror 2.0.18", ] @@ -2737,8 +2822,6 @@ dependencies = [ [[package]] name = "light-hasher" version = "5.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c822662e6e109bac0e132a43fd52a4ef684811245a794e048cf9cda001e934c8" dependencies = [ "ark-bn254 0.5.0", "ark-ff 0.5.0", @@ -2755,8 +2838,6 @@ dependencies = [ [[package]] name = "light-indexed-array" version = "0.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0f14f984030d86b6f07bd8f5ae04e2c40fcd0c3bdfcc7a291fff1ed59c9e6554" dependencies = [ "light-hasher", "num-bigint 0.4.6", @@ -2767,8 +2848,6 @@ dependencies = [ [[package]] name = "light-indexed-merkle-tree" version = "5.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0824755289075f28de2820fc7d4ec4e6b9e99d404e033c07338b91cce8c71fb8" dependencies = [ "light-bounded-vec", "light-concurrent-merkle-tree", @@ -2782,9 +2861,7 @@ dependencies = [ [[package]] name = "light-instruction-decoder" -version = "0.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b7f4bd98e842f21b754ec28020a56de37cb0b1089952ef24340d21c2d5afd5c5" +version = "0.20.0" dependencies = [ "borsh 0.10.4", "bs58", @@ -2802,8 +2879,6 @@ dependencies = [ [[package]] name = "light-instruction-decoder-derive" version = "0.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2035d04a0a1590da05634efcac149a2ac852565e28c9a55bd07a6620c0e90bff" dependencies = [ "bs58", "darling", @@ -2817,8 +2892,6 @@ dependencies = [ [[package]] name = "light-macros" version = "2.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "179ac51cadc1d0ca047b4d6265a7cc245ca3affc16a20a2749585aa6464d39c2" dependencies = [ "bs58", "proc-macro2", @@ -2829,9 +2902,7 @@ dependencies = [ [[package]] name = "light-merkle-tree-metadata" -version = "0.9.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "15c2e63e8345dcfb80efac69136fdcc6c36a12354675aca6e3daf13ec40422d1" +version = "0.10.0" dependencies = [ "anchor-lang", "borsh 0.10.4", @@ -2847,8 +2918,6 @@ dependencies = [ [[package]] name = "light-merkle-tree-reference" version = "4.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d8d480f62ca32b38a6231bbc5310d693f91d6b5bdcc18bb13c2d9aab7a1c90e8" dependencies = [ "light-hasher", "light-indexed-array", @@ -2903,9 +2972,7 @@ dependencies = [ [[package]] name = "light-program-test" -version = "0.19.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e85916a9da34a44971e1a30badaf04cb75213fbfa9f61a139ea6ebd0f021bdde" +version = "0.21.0" dependencies = [ "anchor-lang", "async-trait", @@ -2914,8 +2981,11 @@ dependencies = [ "bs58", "bytemuck", "chrono", + "light-account", + "light-account-checks", "light-client", "light-compressed-account", + "light-compressed-token-sdk", "light-compressible", "light-event", "light-hasher", @@ -2956,9 +3026,7 @@ dependencies = [ [[package]] name = "light-prover-client" -version = "6.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cd2195f4573628a8aaca37504cde1b1903b8ed20e2706acbad875b7d41acbeab" +version = "7.0.0" dependencies = [ "ark-bn254 0.5.0", "ark-serialize 0.5.0", @@ -2980,20 +3048,20 @@ dependencies = [ [[package]] name = "light-sdk" -version = "0.19.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c7f523c64a6fcdafe6df81d647560770529896f2707be8ffcf048d909b7e2b30" +version = "0.20.0" dependencies = [ "anchor-lang", "bincode", "borsh 0.10.4", + "bytemuck", "light-account-checks", "light-compressed-account", - "light-compressible", "light-hasher", "light-macros", + "light-program-profiler", "light-sdk-macros", "light-sdk-types", + "light-token-interface", "light-zero-copy", "num-bigint 0.4.6", "solana-account-info", @@ -3012,9 +3080,7 @@ dependencies = [ [[package]] name = "light-sdk-macros" -version = "0.19.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d3d12bb13b84df21a4871dc0837aafc0b48464d3e9b17e2773c0719b6cc724c5" +version = "0.20.0" dependencies = [ "darling", "light-hasher", @@ -3027,25 +3093,25 @@ dependencies = [ [[package]] name = "light-sdk-types" -version = "0.19.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1d8153b27d057ded7b2b6bbd78c643e3f20bd9a9718ca1a8d4183169ccd812c3" +version = "0.20.0" dependencies = [ "anchor-lang", "borsh 0.10.4", + "bytemuck", "light-account-checks", "light-compressed-account", + "light-compressible", "light-hasher", "light-macros", + "light-token-interface", "solana-msg", + "solana-program-error", "thiserror 2.0.18", ] [[package]] name = "light-sparse-merkle-tree" version = "0.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4251e79b6c63f4946572dcfd7623680ad0f9e0efe1a761a944733333c5645063" dependencies = [ "light-hasher", "light-indexed-array", @@ -3056,16 +3122,16 @@ dependencies = [ [[package]] name = "light-token" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "71fd2e8ca6d7d70c77658010e1ae6ed6d4fe23e29054964b053f51e5c4676e49" +version = "0.20.0" dependencies = [ "anchor-lang", "arrayvec", "borsh 0.10.4", + "light-account", "light-account-checks", "light-batched-merkle-tree", "light-compressed-account", + "light-compressed-token-sdk", "light-compressible", "light-macros", "light-program-profiler", @@ -3087,9 +3153,7 @@ dependencies = [ [[package]] name = "light-token-interface" -version = "0.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f46decebc2a13ec984e2ba7f1e691c0d46b9061875c6bdd12636b7c100a60e6c" +version = "0.4.0" dependencies = [ "aligned-sized", "anchor-lang", @@ -3119,8 +3183,10 @@ version = "0.1.0" dependencies = [ "anchor-lang", "blake3", + "light-account", "light-anchor-spl", "light-client", + "light-compressed-account", "light-hasher", "light-program-test", "light-sdk", @@ -3142,9 +3208,7 @@ dependencies = [ [[package]] name = "light-token-types" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "411481fe2e04b1241235c2572480c153c5669507e227f5e3327057b0d2ba5734" +version = "0.20.0" dependencies = [ "anchor-lang", "borsh 0.10.4", @@ -3158,9 +3222,7 @@ dependencies = [ [[package]] name = "light-verifier" -version = "8.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ecba4c14ac08b078a9d84033d628b12bb2577141f405140d506bacd392a830bc" +version = "9.0.0" dependencies = [ "groth16-solana", "light-compressed-account", @@ -3170,8 +3232,6 @@ dependencies = [ [[package]] name = "light-zero-copy" version = "0.6.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a5621fb515e14af46148699c0b65334aabe230a1d2cbd06736ccc7a408c8a4af" dependencies = [ "light-zero-copy-derive", "solana-program-error", @@ -3181,8 +3241,6 @@ dependencies = [ [[package]] name = "light-zero-copy-derive" version = "0.6.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "41c46425e5c7ab5203ff5c86ae2615b169cca55f9283f5f60f5dd74143be6934" dependencies = [ "lazy_static", "proc-macro2", @@ -3213,7 +3271,7 @@ dependencies = [ "agave-reserved-account-keys", "ansi_term", "bincode", - "indexmap 2.13.0", + "indexmap", "itertools 0.14.0", "log", "solana-account", @@ -3328,16 +3386,6 @@ version = "0.3.17" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6877bb514081ee2a7ff5ef9de3281f14a4dd4bceac4c09388074a6b5df8a139a" -[[package]] -name = "mime_guess" -version = "2.0.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f7c44f8e672c00fe5308fa235f821cb4198414e1c77935c1ab6948d3fd78550e" -dependencies = [ - "mime", - "unicase", -] - [[package]] name = "miniz_oxide" version = "0.8.9" @@ -3381,10 +3429,10 @@ dependencies = [ "libc", "log", "openssl", - "openssl-probe", + "openssl-probe 0.1.6", "openssl-sys", "schannel", - "security-framework", + "security-framework 2.11.1", "security-framework-sys", "tempfile", ] @@ -3435,12 +3483,6 @@ dependencies = [ "num-traits", ] -[[package]] -name = "num-conv" -version = "0.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "51d515d32fb182ee37cda2ccdcb92950d6a3c2893aa280e540671c2cd0f3b1d9" - [[package]] name = "num-derive" version = "0.3.3" @@ -3576,6 +3618,12 @@ version = "0.1.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d05e27ee213611ffe7d6348b942e8f942b37114c00cc03cec254295a4a17852e" +[[package]] +name = "openssl-probe" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7c87def4c32ab89d880effc9e097653c8da5d6ef28e6b539d313baaacfbafcbe" + [[package]] name = "openssl-src" version = "300.5.5+3.5.5" @@ -3684,16 +3732,11 @@ dependencies = [ [[package]] name = "photon-api" version = "0.54.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e572dba0c255f5b8176f15b9e849330d915a8927804f7f9702d5bbbc70e4a1ad" dependencies = [ - "reqwest 0.12.28", + "progenitor-client", + "reqwest 0.13.2", "serde", - "serde_derive", "serde_json", - "serde_with", - "url", - "uuid", ] [[package]] @@ -3778,12 +3821,6 @@ dependencies = [ "zerovec", ] -[[package]] -name = "powerfmt" -version = "0.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "439ee305def115ba05938db6eb1644ff94165c5ab5e9420d1c1bcedbba909391" - [[package]] name = "ppv-lite86" version = "0.2.21" @@ -3842,6 +3879,21 @@ dependencies = [ "unicode-ident", ] +[[package]] +name = "progenitor-client" +version = "0.12.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ffab7b358944dba033a7b324e7558e66e6bcb1fb4705cf57f26fd5092bcae630" +dependencies = [ + "bytes", + "futures-core", + "percent-encoding", + "reqwest 0.13.2", + "serde", + "serde_json", + "serde_urlencoded", +] + [[package]] name = "qstring" version = "0.7.2" @@ -3888,6 +3940,7 @@ version = "0.11.13" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f1906b49b0c3bc04b5fe5d86a77925ae6524a19b816ae38ce1e426255f1d8a31" dependencies = [ + "aws-lc-rs", "bytes", "getrandom 0.3.4", "lru-slab", @@ -4067,26 +4120,6 @@ dependencies = [ "bitflags 2.10.0", ] -[[package]] -name = "ref-cast" -version = "1.0.25" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f354300ae66f76f1c85c5f84693f0ce81d747e2c3f21a45fef496d89c960bf7d" -dependencies = [ - "ref-cast-impl", -] - -[[package]] -name = "ref-cast-impl" -version = "1.0.25" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b7186006dcb21920990093f30e3dea63b7d6e977bf1256be20c3563a5db070da" -dependencies = [ - "proc-macro2", - "quote", - "syn 2.0.114", -] - [[package]] name = "regex" version = "1.12.2" @@ -4183,7 +4216,6 @@ dependencies = [ "js-sys", "log", "mime", - "mime_guess", "native-tls", "percent-encoding", "pin-project-lite", @@ -4207,6 +4239,47 @@ dependencies = [ "webpki-roots 1.0.5", ] +[[package]] +name = "reqwest" +version = "0.13.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ab3f43e3283ab1488b624b44b0e988d0acea0b3214e694730a055cb6b2efa801" +dependencies = [ + "base64 0.22.1", + "bytes", + "futures-core", + "futures-util", + "http 1.4.0", + "http-body 1.0.1", + "http-body-util", + "hyper 1.8.1", + "hyper-rustls 0.27.7", + "hyper-util", + "js-sys", + "log", + "percent-encoding", + "pin-project-lite", + "quinn", + "rustls 0.23.36", + "rustls-pki-types", + "rustls-platform-verifier", + "serde", + "serde_json", + "serde_urlencoded", + "sync_wrapper 1.0.2", + "tokio", + "tokio-rustls 0.26.4", + "tokio-util 0.7.18", + "tower", + "tower-http", + "tower-service", + "url", + "wasm-bindgen", + "wasm-bindgen-futures", + "wasm-streams", + "web-sys", +] + [[package]] name = "reqwest-middleware" version = "0.4.2" @@ -4288,6 +4361,7 @@ version = "0.23.36" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c665f33d38cea657d9614f766881e4d510e0eda4239891eea56b4cadcf01801b" dependencies = [ + "aws-lc-rs", "once_cell", "ring", "rustls-pki-types", @@ -4296,6 +4370,18 @@ dependencies = [ "zeroize", ] +[[package]] +name = "rustls-native-certs" +version = "0.8.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "612460d5f7bea540c490b2b6395d8e34a953e52b491accd6c86c8164c5932a63" +dependencies = [ + "openssl-probe 0.2.1", + "rustls-pki-types", + "schannel", + "security-framework 3.5.1", +] + [[package]] name = "rustls-pemfile" version = "1.0.4" @@ -4315,6 +4401,33 @@ dependencies = [ "zeroize", ] +[[package]] +name = "rustls-platform-verifier" +version = "0.6.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1d99feebc72bae7ab76ba994bb5e121b8d83d910ca40b36e0921f53becc41784" +dependencies = [ + "core-foundation 0.10.1", + "core-foundation-sys", + "jni", + "log", + "once_cell", + "rustls 0.23.36", + "rustls-native-certs", + "rustls-platform-verifier-android", + "rustls-webpki 0.103.9", + "security-framework 3.5.1", + "security-framework-sys", + "webpki-root-certs", + "windows-sys 0.61.2", +] + +[[package]] +name = "rustls-platform-verifier-android" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f87165f0995f63a9fbeea62b64d10b4d9d8e78ec6d7d51fb2125fda7bb36788f" + [[package]] name = "rustls-webpki" version = "0.101.7" @@ -4331,6 +4444,7 @@ version = "0.103.9" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d7df23109aa6c1567d1c575b9952556388da57401e4ace1d15f79eedad0d8f53" dependencies = [ + "aws-lc-rs", "ring", "rustls-pki-types", "untrusted", @@ -4349,36 +4463,21 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a50f4cf475b65d88e057964e0e9bb1f0aa9bbb2036dc65c64596b42932536984" [[package]] -name = "schannel" -version = "0.1.28" +name = "same-file" +version = "1.0.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "891d81b926048e76efe18581bf793546b4c0eaf8448d72be8de2bbee5fd166e1" +checksum = "93fc1dc3aaa9bfed95e02e6eadabb4baf7e3078b0bd1b4d7b6b0b68378900502" dependencies = [ - "windows-sys 0.61.2", -] - -[[package]] -name = "schemars" -version = "0.9.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4cd191f9397d57d581cddd31014772520aa448f65ef991055d7f61582c65165f" -dependencies = [ - "dyn-clone", - "ref-cast", - "serde", - "serde_json", + "winapi-util", ] [[package]] -name = "schemars" -version = "1.2.0" +name = "schannel" +version = "0.1.28" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "54e910108742c57a770f492731f99be216a52fadd361b06c8fb59d74ccc267d2" +checksum = "891d81b926048e76efe18581bf793546b4c0eaf8448d72be8de2bbee5fd166e1" dependencies = [ - "dyn-clone", - "ref-cast", - "serde", - "serde_json", + "windows-sys 0.61.2", ] [[package]] @@ -4404,7 +4503,20 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "897b2245f0b511c87893af39b033e5ca9cce68824c4d7e7630b5a1d339658d02" dependencies = [ "bitflags 2.10.0", - "core-foundation", + "core-foundation 0.9.4", + "core-foundation-sys", + "libc", + "security-framework-sys", +] + +[[package]] +name = "security-framework" +version = "3.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b3297343eaf830f66ede390ea39da1d462b6b0c1b000f420d0a83f898bbbe6ef" +dependencies = [ + "bitflags 2.10.0", + "core-foundation 0.10.1", "core-foundation-sys", "libc", "security-framework-sys", @@ -4515,17 +4627,8 @@ version = "3.16.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4fa237f2807440d238e0364a218270b98f767a00d3dada77b1c53ae88940e2e7" dependencies = [ - "base64 0.22.1", - "chrono", - "hex", - "indexmap 1.9.3", - "indexmap 2.13.0", - "schemars 0.9.0", - "schemars 1.2.0", "serde_core", - "serde_json", "serde_with_macros", - "time", ] [[package]] @@ -4595,6 +4698,7 @@ version = "0.1.0" dependencies = [ "anchor-lang", "anchor-spl", + "light-account", "light-client", "light-hasher", "light-program-test", @@ -6128,7 +6232,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "474a2d95dc819898ded08d24f29642d02189d3e1497bbb442a92a3997b7eb55f" dependencies = [ "byteorder", - "combine", + "combine 3.8.1", "hash32", "libc", "log", @@ -7682,8 +7786,10 @@ dependencies = [ "az", "blake3", "fixed", + "light-account", "light-anchor-spl", "light-client", + "light-compressed-account", "light-hasher", "light-program-test", "light-sdk", @@ -7758,7 +7864,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ba3a3adc5c275d719af8cb4272ea1c4a6d668a777f37e115f6d11ddbc1c8e0e7" dependencies = [ "bitflags 1.3.2", - "core-foundation", + "core-foundation 0.9.4", "system-configuration-sys 0.5.0", ] @@ -7769,7 +7875,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3c879d448e9d986b661742763247d3693ed13609438cf3d006f51f5368a5ba6b" dependencies = [ "bitflags 2.10.0", - "core-foundation", + "core-foundation 0.9.4", "system-configuration-sys 0.6.0", ] @@ -7938,37 +8044,6 @@ dependencies = [ "cfg-if", ] -[[package]] -name = "time" -version = "0.3.41" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8a7619e19bc266e0f9c5e6686659d394bc57973859340060a69221e57dbc0c40" -dependencies = [ - "deranged", - "itoa", - "num-conv", - "powerfmt", - "serde", - "time-core", - "time-macros", -] - -[[package]] -name = "time-core" -version = "0.1.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c9e9a38711f559d9e3ce1cdb06dd7c5b8ea546bc90052da6d06bb76da74bb07c" - -[[package]] -name = "time-macros" -version = "0.2.22" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3526739392ec93fd8b359c8e98514cb3e8e021beb4e5f597b00a0221f8ed8a49" -dependencies = [ - "num-conv", - "time-core", -] - [[package]] name = "tinystr" version = "0.8.2" @@ -8141,7 +8216,7 @@ version = "0.22.27" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "41fe8c660ae4257887cf66394862d21dbca4a6ddd26f04a3560410406a2f819a" dependencies = [ - "indexmap 2.13.0", + "indexmap", "serde", "serde_spanned", "toml_datetime 0.6.11", @@ -8155,7 +8230,7 @@ version = "0.23.10+spec-1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "84c8b9f757e028cee9fa244aea147aab2a9ec09d5325a9b01e0a49730c2b5269" dependencies = [ - "indexmap 2.13.0", + "indexmap", "toml_datetime 0.7.5+spec-1.1.0", "toml_parser", "winnow", @@ -8295,12 +8370,6 @@ version = "1.19.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "562d481066bde0658276a35467c4af00bdc6ee726305698a55b86e61d7ad82bb" -[[package]] -name = "unicase" -version = "2.9.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dbc4bc3a9f746d862c45cb89d705aa10f187bb96c76001afab07a0d35ce60142" - [[package]] name = "unicode-ident" version = "1.0.22" @@ -8372,18 +8441,6 @@ version = "1.0.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b6c140620e7ffbb22c2dee59cafe6084a59b5ffc27a8859a5f0d494b5d52b6be" -[[package]] -name = "uuid" -version = "1.20.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ee48d38b119b0cd71fe4141b30f5ba9c7c5d9f4e7a3a8b4a674e4b6ef789976f" -dependencies = [ - "getrandom 0.3.4", - "js-sys", - "serde_core", - "wasm-bindgen", -] - [[package]] name = "valuable" version = "0.1.1" @@ -8408,6 +8465,16 @@ version = "1.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6a02e4885ed3bc0f2de90ea6dd45ebcbb66dacffe03547fadbb0eeae2770887d" +[[package]] +name = "walkdir" +version = "2.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "29790946404f91d9c5d06f9874efddea1dc06c5efe94541a7d6863108e3a5e4b" +dependencies = [ + "same-file", + "winapi-util", +] + [[package]] name = "want" version = "0.3.1" @@ -8497,6 +8564,19 @@ dependencies = [ "unicode-ident", ] +[[package]] +name = "wasm-streams" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9d1ec4f6517c9e11ae630e200b2b65d193279042e28edd4a2cda233e46670bbb" +dependencies = [ + "futures-util", + "js-sys", + "wasm-bindgen", + "wasm-bindgen-futures", + "web-sys", +] + [[package]] name = "web-sys" version = "0.3.85" @@ -8517,6 +8597,15 @@ dependencies = [ "wasm-bindgen", ] +[[package]] +name = "webpki-root-certs" +version = "1.0.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "804f18a4ac2676ffb4e8b5b5fa9ae38af06df08162314f96a68d2a363e21a8ca" +dependencies = [ + "rustls-pki-types", +] + [[package]] name = "webpki-roots" version = "0.25.4" @@ -8633,6 +8722,15 @@ dependencies = [ "windows-link", ] +[[package]] +name = "windows-sys" +version = "0.45.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "75283be5efb2831d37ea142365f009c02ec203cd29a3ebecbc093d52315b66d0" +dependencies = [ + "windows-targets 0.42.2", +] + [[package]] name = "windows-sys" version = "0.48.0" @@ -8678,6 +8776,21 @@ dependencies = [ "windows-link", ] +[[package]] +name = "windows-targets" +version = "0.42.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8e5180c00cd44c9b1c88adb3693291f1cd93605ded80c250a75d472756b4d071" +dependencies = [ + "windows_aarch64_gnullvm 0.42.2", + "windows_aarch64_msvc 0.42.2", + "windows_i686_gnu 0.42.2", + "windows_i686_msvc 0.42.2", + "windows_x86_64_gnu 0.42.2", + "windows_x86_64_gnullvm 0.42.2", + "windows_x86_64_msvc 0.42.2", +] + [[package]] name = "windows-targets" version = "0.48.5" @@ -8726,6 +8839,12 @@ dependencies = [ "windows_x86_64_msvc 0.53.1", ] +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.42.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "597a5118570b68bc08d8d59125332c54f1ba9d9adeedeef5b99b02ba2b0698f8" + [[package]] name = "windows_aarch64_gnullvm" version = "0.48.5" @@ -8744,6 +8863,12 @@ version = "0.53.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a9d8416fa8b42f5c947f8482c43e7d89e73a173cead56d044f6a56104a6d1b53" +[[package]] +name = "windows_aarch64_msvc" +version = "0.42.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e08e8864a60f06ef0d0ff4ba04124db8b0fb3be5776a5cd47641e942e58c4d43" + [[package]] name = "windows_aarch64_msvc" version = "0.48.5" @@ -8762,6 +8887,12 @@ version = "0.53.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b9d782e804c2f632e395708e99a94275910eb9100b2114651e04744e9b125006" +[[package]] +name = "windows_i686_gnu" +version = "0.42.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c61d927d8da41da96a81f029489353e68739737d3beca43145c8afec9a31a84f" + [[package]] name = "windows_i686_gnu" version = "0.48.5" @@ -8792,6 +8923,12 @@ version = "0.53.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "fa7359d10048f68ab8b09fa71c3daccfb0e9b559aed648a8f95469c27057180c" +[[package]] +name = "windows_i686_msvc" +version = "0.42.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "44d840b6ec649f480a41c8d80f9c65108b92d89345dd94027bfe06ac444d1060" + [[package]] name = "windows_i686_msvc" version = "0.48.5" @@ -8810,6 +8947,12 @@ version = "0.53.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1e7ac75179f18232fe9c285163565a57ef8d3c89254a30685b57d83a38d326c2" +[[package]] +name = "windows_x86_64_gnu" +version = "0.42.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8de912b8b8feb55c064867cf047dda097f92d51efad5b491dfb98f6bbb70cb36" + [[package]] name = "windows_x86_64_gnu" version = "0.48.5" @@ -8828,6 +8971,12 @@ version = "0.53.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9c3842cdd74a865a8066ab39c8a7a473c0778a3f29370b5fd6b4b9aa7df4a499" +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.42.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "26d41b46a36d453748aedef1486d5c7a85db22e56aff34643984ea85514e94a3" + [[package]] name = "windows_x86_64_gnullvm" version = "0.48.5" @@ -8846,6 +8995,12 @@ version = "0.53.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0ffa179e2d07eee8ad8f57493436566c7cc30ac536a3379fdf008f47f6bb7ae1" +[[package]] +name = "windows_x86_64_msvc" +version = "0.42.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9aec5da331524158c6d1a4ac0ab1541149c0b9505fde06423b02f5ef0106b9f0" + [[package]] name = "windows_x86_64_msvc" version = "0.48.5" diff --git a/programs/anchor/Cargo.toml b/programs/anchor/Cargo.toml index 4a2efb3..70d48dc 100644 --- a/programs/anchor/Cargo.toml +++ b/programs/anchor/Cargo.toml @@ -44,19 +44,20 @@ spl-token-2022 = "7" spl-pod = "0.5" # Light Protocol -light-sdk = { version = "0.19.0", features = ["anchor", "idl-build", "v2", "anchor-discriminator", "cpi-context"] } -light-sdk-macros = "0.19.0" -light-sdk-types = { version = "0.19.0", features = ["v2", "cpi-context"] } -light-compressible = { version = "0.4.0", features = ["anchor"] } +light-sdk = { version = "0.20.0", features = ["anchor", "v2", "cpi-context"] } +light-sdk-macros = "0.20.0" +light-sdk-types = { version = "0.20.0", features = ["v2", "cpi-context"] } +light-account = { version = "0.20.0", features = ["anchor", "token"] } +light-compressible = { version = "0.5.0", features = ["anchor"] } light-hasher = { version = "5.0.0", features = ["solana"] } light-macros = "2.2.0" -light-compressed-account = "0.9.0" -light-token = { version = "0.4.0", features = ["anchor"] } -light-token-types = { version = "0.4.0", features = ["anchor"] } -light-token-interface = "0.3.0" -light-program-test = "0.19.0" -light-client = { version = "0.19.0", features = ["v2", "anchor"] } -light-anchor-spl = { version = "0.31.1", features = ["idl-build"] } +light-compressed-account = "0.10.1" +light-token = { version = "0.20.0", features = ["anchor"] } +light-token-types = { version = "0.20.0", features = ["anchor"] } +light-token-interface = "0.4.0" +light-program-test = { path = "/home/tilo/Workspace/light-protocol/sdk-libs/program-test" } +light-client = { path = "/home/tilo/Workspace/light-protocol/sdk-libs/client", features = ["v2", "anchor"] } +light-anchor-spl = "0.31.1" # Testing tokio = "1.43.0" @@ -68,3 +69,20 @@ time = "=0.3.41" # Internal shared-test-utils = { path = "shared-test-utils" } + +# Patch crates.io light-* deps to use local monorepo paths. +# This avoids "two different versions of the same crate" errors +# when light-client/light-program-test (path deps) pull in local +# copies of crates that our programs also reference from crates.io. +[patch.crates-io] +light-sdk = { path = "/home/tilo/Workspace/light-protocol/sdk-libs/sdk" } +light-sdk-macros = { path = "/home/tilo/Workspace/light-protocol/sdk-libs/macros" } +light-sdk-types = { path = "/home/tilo/Workspace/light-protocol/sdk-libs/sdk-types" } +light-account = { path = "/home/tilo/Workspace/light-protocol/sdk-libs/account" } +light-compressible = { path = "/home/tilo/Workspace/light-protocol/program-libs/compressible" } +light-hasher = { path = "/home/tilo/Workspace/light-protocol/program-libs/hasher" } +light-macros = { path = "/home/tilo/Workspace/light-protocol/program-libs/macros" } +light-compressed-account = { path = "/home/tilo/Workspace/light-protocol/program-libs/compressed-account" } +light-token = { path = "/home/tilo/Workspace/light-protocol/sdk-libs/token-sdk" } +light-token-types = { path = "/home/tilo/Workspace/light-protocol/sdk-libs/token-types" } +light-token-interface = { path = "/home/tilo/Workspace/light-protocol/program-libs/token-interface" } diff --git a/programs/anchor/escrow/Cargo.toml b/programs/anchor/escrow/Cargo.toml index a870cac..e1a6a96 100644 --- a/programs/anchor/escrow/Cargo.toml +++ b/programs/anchor/escrow/Cargo.toml @@ -13,19 +13,21 @@ no-log-ix-name = [] no-idl = [] cpi = ["no-entrypoint"] default = [] -idl-build = ["anchor-lang/idl-build", "light-sdk/idl-build"] +idl-build = ["anchor-lang/idl-build", "light-sdk/idl-build", "light-anchor-spl/idl-build"] test-sbf = [] [dependencies] -anchor-lang = { version = "=0.31.1", features = ["idl-build"] } +anchor-lang = { version = "=0.31.1" } # Pin blake3 version for solana-program compatibility blake3 = { workspace = true } -light-sdk = { workspace = true, features = ["anchor", "anchor-discriminator", "idl-build", "cpi-context", "v2"] } +light-sdk = { workspace = true, features = ["anchor", "cpi-context", "v2"] } light-token = { workspace = true, features = ["anchor"] } +light-account = { workspace = true } +light-compressed-account = { workspace = true } # Required by LightAccount derive macro light-hasher = { workspace = true, features = ["solana"] } -light-anchor-spl = { workspace = true, features = ["idl-build"] } +light-anchor-spl = { workspace = true } solana-program = { workspace = true } solana-pubkey = { workspace = true } solana-account-info = { workspace = true } diff --git a/programs/anchor/escrow/src/instructions/make_offer.rs b/programs/anchor/escrow/src/instructions/make_offer.rs index f12b4be..41a4ae9 100644 --- a/programs/anchor/escrow/src/instructions/make_offer.rs +++ b/programs/anchor/escrow/src/instructions/make_offer.rs @@ -1,8 +1,8 @@ use anchor_lang::prelude::*; use light_anchor_spl::token_interface::{Mint, TokenAccount, TokenInterface}; -use light_sdk::interface::CreateAccountsProof; -use light_token::anchor::LightAccounts; -use light_token::instruction::{COMPRESSIBLE_CONFIG_V1, RENT_SPONSOR}; +use light_account::CreateAccountsProof; +use light_account::LightAccounts; +use light_token::instruction::{LIGHT_TOKEN_CONFIG, LIGHT_TOKEN_RENT_SPONSOR}; use light_token::spl_interface::find_spl_interface_pda; @@ -35,6 +35,10 @@ pub struct MakeOffer<'info> { /// CHECK: Config for light mint creation pub compression_config: AccountInfo<'info>, + /// CHECK: PDA rent sponsor for rent reimbursement + #[account(mut)] + pub pda_rent_sponsor: AccountInfo<'info>, + #[account(mint::token_program = token_program)] pub token_mint_a: InterfaceAccount<'info, Mint>, @@ -65,9 +69,10 @@ pub struct MakeOffer<'info> { bump, )] #[light_account(init, - token::authority = [VAULT_SEED, self.offer.key()], + token::seeds = [VAULT_SEED, self.offer.key()], token::mint = token_mint_a, token::owner = authority, + token::owner_seeds = [AUTH_SEED], token::bump = params.vault_bump )] pub vault: UncheckedAccount<'info>, @@ -78,12 +83,12 @@ pub struct MakeOffer<'info> { /// Light token program for CPI calls pub light_token_program: Interface<'info, TokenInterface>, - /// CHECK: Light token compressible config - validated by address constraint - #[account(address = COMPRESSIBLE_CONFIG_V1)] - pub light_token_compressible_config: AccountInfo<'info>, + /// CHECK: Light token config - validated by address constraint + #[account(address = LIGHT_TOKEN_CONFIG)] + pub light_token_config: AccountInfo<'info>, /// CHECK: Light token rent sponsor - validated by address constraint - #[account(mut, address = RENT_SPONSOR)] + #[account(mut, address = LIGHT_TOKEN_RENT_SPONSOR)] pub light_token_rent_sponsor: AccountInfo<'info>, /// CHECK: light-token CPI authority - must be writable for Light token CPI diff --git a/programs/anchor/escrow/src/instructions/take_offer.rs b/programs/anchor/escrow/src/instructions/take_offer.rs index 480b6ce..4f78dd8 100644 --- a/programs/anchor/escrow/src/instructions/take_offer.rs +++ b/programs/anchor/escrow/src/instructions/take_offer.rs @@ -1,6 +1,6 @@ use anchor_lang::prelude::*; use light_anchor_spl::token_interface::{Mint, TokenAccount, TokenInterface}; -use light_token::instruction::{CloseAccountCpi, RENT_SPONSOR}; +use light_token::instruction::{CloseAccountCpi, LIGHT_TOKEN_RENT_SPONSOR}; use light_token::utils::get_token_account_balance; use light_token::spl_interface::find_spl_interface_pda; @@ -79,7 +79,7 @@ pub struct TakeOffer<'info> { pub light_token_cpi_authority: AccountInfo<'info>, /// CHECK: Light token rent sponsor for closing vault - #[account(mut, address = RENT_SPONSOR)] + #[account(mut, address = LIGHT_TOKEN_RENT_SPONSOR)] pub light_token_rent_sponsor: AccountInfo<'info>, /// CHECK: SPL interface PDA for mint A (vault→taker transfer) diff --git a/programs/anchor/escrow/src/lib.rs b/programs/anchor/escrow/src/lib.rs index 64e5e61..c34f03e 100644 --- a/programs/anchor/escrow/src/lib.rs +++ b/programs/anchor/escrow/src/lib.rs @@ -3,7 +3,7 @@ pub mod instructions; pub mod state; use anchor_lang::prelude::*; -use light_token::anchor::{derive_light_cpi_signer, light_program, CpiSigner}; +use light_account::{derive_light_cpi_signer, light_program, CpiSigner}; pub use constants::*; pub use instructions::*; diff --git a/programs/anchor/escrow/src/state/offer.rs b/programs/anchor/escrow/src/state/offer.rs index 33cf09f..b37104f 100644 --- a/programs/anchor/escrow/src/state/offer.rs +++ b/programs/anchor/escrow/src/state/offer.rs @@ -1,11 +1,11 @@ use anchor_lang::prelude::*; use light_sdk::LightDiscriminator; -use light_token::anchor::{CompressionInfo, LightAccount}; +use light_account::{CompressionInfo, LightAccount}; #[derive(Default, Debug, InitSpace, LightAccount)] #[account] pub struct Offer { - pub compression_info: Option, + pub compression_info: CompressionInfo, pub id: u64, pub maker: Pubkey, pub token_mint_a: Pubkey, diff --git a/programs/anchor/escrow/tests/common/mod.rs b/programs/anchor/escrow/tests/common/mod.rs index 86d15b7..b3a8875 100644 --- a/programs/anchor/escrow/tests/common/mod.rs +++ b/programs/anchor/escrow/tests/common/mod.rs @@ -108,6 +108,8 @@ pub struct EscrowTestContext { pub payer: Keypair, pub token_config: TokenConfig, pub compression_config: Pubkey, + /// Per-program rent sponsor PDA (derived from program_id) + pub rent_sponsor: Pubkey, // Mint A pub mint_a_pubkey: Pubkey, @@ -160,8 +162,8 @@ pub async fn setup_escrow_test( let program_id = escrow::ID; let payer = rpc.get_payer().insecure_clone(); - // Initialize rent-free config - let compression_config = initialize_rent_free_config(rpc, &payer, &program_id).await; + // Initialize rent-free config (returns config PDA + per-program rent sponsor PDA) + let (compression_config, rent_sponsor) = initialize_rent_free_config(rpc, &payer, &program_id).await; // Create maker and taker let maker = Keypair::new(); @@ -206,6 +208,7 @@ pub async fn setup_escrow_test( payer, token_config: config, compression_config, + rent_sponsor, mint_a_pubkey: light_mint_a.mint, light_mint_a_authority: Some(light_mint_a.authority), spl_interface_a: None, @@ -260,6 +263,7 @@ pub async fn setup_escrow_test( payer, token_config: config, compression_config, + rent_sponsor, mint_a_pubkey, light_mint_a_authority: None, spl_interface_a, diff --git a/programs/anchor/escrow/tests/escrow.rs b/programs/anchor/escrow/tests/escrow.rs index c195fcb..42c9216 100644 --- a/programs/anchor/escrow/tests/escrow.rs +++ b/programs/anchor/escrow/tests/escrow.rs @@ -1,8 +1,6 @@ //! Light Token escrow: peer-to-peer token swap with rent-free vault. //! -//! This test shows the same make/take escrow pattern as the -//! [solana-program-examples SPL escrow](https://github.com/solana-developers/program-examples/tree/main/tokens/escrow/anchor), -//! adapted for Light Token. Three architectural differences: +//! This test shows make/take escrow patterns adapted for Light Token. //! //! 1. **Authority PDA owns the vault** — not the offer account. This lets //! the authority sign vault withdrawals without needing account data @@ -38,22 +36,307 @@ //! `LightSpl`/`LightT22` convert tokens from SPL/T22 associated token accounts //! into Light token accounts *before* the escrow starts (in `create_token_account`). //! The escrow itself only sees Light token accounts. +//! +//! ## Cold/hot lifecycle +//! +//! Light Token accounts auto-compress when sponsored rent expires. Before each +//! transaction, the test loads cold accounts back on-chain via +//! `load_light_accounts`. After account creation, `warp_to_compress` advances +//! slots to trigger compression, demonstrating the full lifecycle: +//! create → compress → load → transact. mod common; -use anchor_lang::{InstructionData, ToAccountMetas}; +use anchor_lang::{AnchorDeserialize, InstructionData, ToAccountMetas}; use common::{ create_test_rpc, create_token_account, setup_escrow_test, EscrowTestContext, TokenConfig, }; -use light_client::interface::{get_create_accounts_proof, CreateAccountsProofInput}; +use escrow::escrow::{LightAccountVariant, OfferSeeds, VaultSeeds}; +use light_account::token::{Token as LightToken, TokenDataWithSeeds}; +use light_account::IntoVariant; +use light_client::interface::{ + create_load_instructions, get_create_accounts_proof, AccountInterface, AccountSpec, ColdContext, + CreateAccountsProofInput, PdaSpec, +}; use shared_test_utils::{ helpers::verify_light_token_balance, Indexer, Rpc, TestRpc, COMPRESSIBLE_CONFIG_V1, CPI_AUTHORITY_PDA, LIGHT_TOKEN_PROGRAM_ID, RENT_SPONSOR, }; use solana_instruction::Instruction; +use solana_keypair::Keypair; use solana_pubkey::Pubkey; use solana_signer::Signer; +// ============================================================================ +// Tests — one per token configuration: SPL, T22, Light. +// ============================================================================ + +/// SPL mint with SPL associated token accounts → Light token vault. +/// +/// Every transfer crosses standards (SPL ↔ Light) via `TransferInterfaceCpi` +/// with SPL interface PDAs. This is the baseline: same mint type as standard +/// SPL escrow, but the vault is a rent-free Light token account. +#[tokio::test] +async fn test_escrow_spl() { + let mut rpc = create_test_rpc().await; + let ctx = setup_escrow_test(&mut rpc, TokenConfig::Spl).await; + run_escrow_full_flow(&mut rpc, &ctx).await; +} + +/// Token-2022 mint with T22 associated token accounts → Light token vault. +/// +/// Every transfer crosses standards (T22 ↔ Light) via `TransferInterfaceCpi` +/// with SPL interface PDAs. Same pattern as `test_escrow_spl` but exercises +/// the Token-2022 program path. +#[tokio::test] +async fn test_escrow_t22() { + let mut rpc = create_test_rpc().await; + let ctx = setup_escrow_test(&mut rpc, TokenConfig::Token2022).await; + run_escrow_full_flow(&mut rpc, &ctx).await; +} + +/// Light mint + Light user accounts (rent-free path). +/// +/// All accounts are Light — transfers use `TransferCheckedCpi`. +#[tokio::test] +async fn test_escrow_light() { + let mut rpc = create_test_rpc().await; + let ctx = setup_escrow_test(&mut rpc, TokenConfig::Light).await; + run_escrow_full_flow(&mut rpc, &ctx).await; +} + +/// SPL mint + Light user accounts (interop). +/// +/// Tokens start in SPL associated token accounts, get converted into Light +/// token accounts during setup via `transfer_spl_to_light`. Once in Light +/// token accounts, all escrow transfers are Light-to-Light (`TransferCheckedCpi`). +/// Shows that Light token accounts can hold any SPL mint. +#[tokio::test] +async fn test_escrow_spl_light() { + let mut rpc = create_test_rpc().await; + let ctx = setup_escrow_test(&mut rpc, TokenConfig::LightSpl).await; + run_escrow_full_flow(&mut rpc, &ctx).await; +} + +/// Token-2022 mint + Light user accounts (interop). +/// +/// Tokens start in T22 associated token accounts, get converted into Light +/// token accounts during setup via `transfer_spl_to_light`. Once in Light +/// token accounts, all escrow transfers are Light-to-Light (`TransferCheckedCpi`). +/// Shows that Light token accounts can hold any T22 mint. +#[tokio::test] +async fn test_escrow_t22_light() { + let mut rpc = create_test_rpc().await; + let ctx = setup_escrow_test(&mut rpc, TokenConfig::LightT22).await; + run_escrow_full_flow(&mut rpc, &ctx).await; +} + +// ============================================================================ +// Cold/Hot Lifecycle Helpers +// ============================================================================ + +/// Advance slots past sponsored rent to trigger Light Token account compression. +/// +/// After this call, Light token accounts with expired rent are cold (compressed). +/// Standard SPL/T22 accounts are unaffected. +async fn warp_to_compress(rpc: &mut R) { + rpc.warp_epoch_forward(30) + .await + .expect("warp_epoch_forward should succeed"); +} + +/// Load cold (compressed) Light mints back on-chain before transacting. +/// +/// Uses `get_mint_interface` to check hot/cold state, then `decompress_mint` +/// to build decompression instructions. Permissionless — any signer works. +/// No-op for mints that are already hot or non-Light (SPL/T22). +async fn load_light_mints( + rpc: &mut R, + payer: &Keypair, + mints: &[Pubkey], +) { + use light_client::interface::decompress_mint::decompress_mint; + + for mint_address in mints { + let mint_iface = match rpc.get_mint_interface(mint_address, None).await { + Ok(response) => match response.value { + Some(m) => m, + None => continue, + }, + Err(_) => continue, // not a Light mint or not found + }; + + if !mint_iface.is_cold() { + continue; // already hot + } + + let ixs = decompress_mint(&mint_iface, payer.pubkey(), &*rpc) + .await + .expect("decompress_mint should succeed for cold Light mint"); + + if !ixs.is_empty() { + rpc.create_and_send_transaction(&ixs, &payer.pubkey(), &[payer]) + .await + .expect("decompress mint transaction should succeed"); + } + } +} + +/// Load cold (compressed) Light token accounts before next transaction. +/// +/// Accepts the wallet `owner` keypair and a list of mints. For each mint, +/// `get_ata_interface(owner, mint)` resolves the ATA and checks if it's cold. +/// Cold accounts are loaded via `create_load_instructions` which builds +/// `CreateAssociatedTokenAccount` + `Transfer2` instructions to decompress. +/// +/// The owner keypair signs the load transaction — `Transfer2` requires the +/// wallet owner to authorize decompression of their token accounts. +/// +/// No-op for accounts that are already hot or non-Light (SPL/T22). +async fn load_light_accounts( + rpc: &mut R, + payer: &Keypair, + owner: &Keypair, + mints: &[Pubkey], +) { + let mut specs: Vec> = Vec::new(); + let owner_pubkey = owner.pubkey(); + + for mint in mints { + match rpc.get_associated_token_account_interface(&owner_pubkey, mint, None).await { + Ok(response) => { + if let Some(iface) = response.value { + if iface.is_cold() { + specs.push(AccountSpec::Ata(iface)); + } + } + } + _ => {} // hot, not found, or non-Light account → skip + } + } + + if specs.is_empty() { + return; + } + + let ixs = create_load_instructions::( + &specs, + payer.pubkey(), + COMPRESSIBLE_CONFIG_V1, + &*rpc, + ) + .await + .expect("create_load_instructions should succeed"); + + if !ixs.is_empty() { + rpc.create_and_send_transaction(&ixs, &payer.pubkey(), &[payer, owner]) + .await + .expect("load transaction should succeed"); + } +} + +/// Load cold (compressed) program-owned Light accounts (offer + vault) back on-chain. +/// +/// The offer PDA uses `get_account_interface` to fetch cold state, deserializes +/// `Offer` from account data, and wraps it in `LightAccountVariant::Offer`. +/// +/// The vault uses `get_token_account_interface` to fetch cold state, deserializes +/// `Token` from account data, and wraps it in `LightAccountVariant::Vault`. +/// The vault's `ColdContext::Token` is converted to `ColdContext::Account` for `PdaSpec`. +/// +/// The maker must sign because the offer's `Pack` includes `fee_payer` (= maker) +/// as a signer account. No-op if both accounts are already hot. +async fn load_light_pdas( + rpc: &mut R, + payer: &Keypair, + maker: &Keypair, + program_id: &Pubkey, + compression_config: Pubkey, + offer_pda: Pubkey, + vault_pda: Pubkey, +) { + let mut specs: Vec> = Vec::new(); + + // Offer PDA: custom state account + match rpc.get_account_interface(&offer_pda, None).await { + Ok(response) => { + if let Some(iface) = response.value { + if iface.is_cold() { + let data = iface.data(); + let offer: escrow::Offer = + AnchorDeserialize::deserialize(&mut &data[8..]) + .expect("deserialize Offer from cold data"); + + // fee_payer must match the original make_offer signer (the maker), + // because the offer PDA seeds include fee_payer.key(). + let maker_pubkey = offer.maker; + let variant = OfferSeeds { + fee_payer: maker_pubkey, + id: offer.id, + } + .into_variant(&iface.data()[8..]) + .expect("seed verification should pass"); + specs.push(AccountSpec::Pda(PdaSpec::new(iface, variant, *program_id))); + } + } + } + _ => {} + } + + // Vault: Light token account (PDA-owned by authority) + match rpc.get_token_account_interface(&vault_pda, None).await { + Ok(response) => { + if let Some(iface) = response.value { + if iface.is_cold() { + let token_data: LightToken = + AnchorDeserialize::deserialize(&mut &iface.account.data[..]) + .expect("deserialize Token from cold vault data"); + let vault_variant = + LightAccountVariant::Vault(TokenDataWithSeeds { + seeds: VaultSeeds { offer: offer_pda }, + token_data, + }); + let vault_compressed = iface + .compressed() + .expect("cold vault must have compressed data"); + let vault_interface = AccountInterface { + key: iface.key, + account: iface.account.clone(), + cold: Some(ColdContext::Account( + vault_compressed.account.clone(), + )), + }; + specs.push(AccountSpec::Pda(PdaSpec::new( + vault_interface, + vault_variant, + *program_id, + ))); + } + } + } + _ => {} + } + + if specs.is_empty() { + return; + } + + let ixs = create_load_instructions::( + &specs, + maker.pubkey(), + compression_config, + &*rpc, + ) + .await + .expect("create_load_instructions for PDAs should succeed"); + + if !ixs.is_empty() { + rpc.create_and_send_transaction(&ixs, &maker.pubkey(), &[maker]) + .await + .expect("PDA decompression transaction should succeed"); + } +} + // ============================================================================ // Full Flow // ============================================================================ @@ -130,6 +413,34 @@ async fn run_escrow_full_flow( verify_light_token_balance(rpc, taker_token_b, token_b_wanted, "taker_token_b (initial)") .await; + // ==================== PHASE 3.5: Compress → Load ==================== + // Advance slots past sponsored rent to trigger compression. + // Light token accounts become cold (compressed). Standard SPL/T22 accounts + // are unaffected (warp + load is a no-op for non-Light configs). + warp_to_compress(rpc).await; + + // Load cold mints back on-chain (Light config only — SPL/T22 mints don't compress). + load_light_mints(rpc, &ctx.payer, &[ctx.mint_a_pubkey, ctx.mint_b_pubkey]).await; + + // Load cold token accounts back on-chain before make_offer. + // For Light configs: decompresses maker_token_a (has balance to deposit). + // For SPL/T22 configs: no-op (standard ATAs don't compress). + // Loads are per-owner because Transfer2 requires the wallet owner to sign. + load_light_accounts( + rpc, + &ctx.payer, + &ctx.maker, + &[ctx.mint_a_pubkey, ctx.mint_b_pubkey], + ) + .await; + load_light_accounts( + rpc, + &ctx.payer, + &ctx.taker, + &[ctx.mint_a_pubkey, ctx.mint_b_pubkey], + ) + .await; + // ==================== PHASE 4: Make Offer ==================== // Transfers token A from maker to vault, creates offer account with escrow terms @@ -170,7 +481,8 @@ async fn run_escrow_full_flow( token_program: ctx.token_config.token_program_id(), system_program: solana_sdk::system_program::ID, light_token_program: Pubkey::new_from_array(LIGHT_TOKEN_PROGRAM_ID), - light_token_compressible_config: COMPRESSIBLE_CONFIG_V1, + light_token_config: COMPRESSIBLE_CONFIG_V1, + pda_rent_sponsor: ctx.rent_sponsor, light_token_rent_sponsor: RENT_SPONSOR, light_token_cpi_authority: CPI_AUTHORITY_PDA, spl_interface_pda_a: ctx @@ -226,6 +538,36 @@ async fn run_escrow_full_flow( "Offer account should have data" ); + // ==================== PHASE 5.5: Compress → Load Before Take ==================== + // Advance slots to trigger compression, then load accounts before take_offer. + // Vault and offer are program-owned (not ATAs), loaded separately below. + warp_to_compress(rpc).await; + load_light_mints(rpc, &ctx.payer, &[ctx.mint_a_pubkey, ctx.mint_b_pubkey]).await; + load_light_pdas( + rpc, + &ctx.payer, + &ctx.maker, + &ctx.program_id, + ctx.compression_config, + offer_pda, + vault_pda, + ) + .await; + load_light_accounts( + rpc, + &ctx.payer, + &ctx.taker, + &[ctx.mint_a_pubkey, ctx.mint_b_pubkey], + ) + .await; + load_light_accounts( + rpc, + &ctx.payer, + &ctx.maker, + &[ctx.mint_b_pubkey], + ) + .await; + // ==================== PHASE 6: Take Offer ==================== // Taker sends wanted tokens (B) to maker, vault releases offered tokens (A) to taker, // then vault and offer accounts are closed @@ -289,67 +631,3 @@ async fn run_escrow_full_flow( "Offer account should be closed after take_offer" ); } - -// ============================================================================ -// Tests — one per token configuration: SPL, T22, Light. -// ============================================================================ - -/// SPL mint with SPL associated token accounts → Light token vault. -/// -/// Every transfer crosses standards (SPL ↔ Light) via `TransferInterfaceCpi` -/// with SPL interface PDAs. This is the baseline: same mint type as standard -/// SPL escrow, but the vault is a rent-free Light token account. -#[tokio::test] -async fn test_escrow_spl() { - let mut rpc = create_test_rpc().await; - let ctx = setup_escrow_test(&mut rpc, TokenConfig::Spl).await; - run_escrow_full_flow(&mut rpc, &ctx).await; -} - -/// Token-2022 mint with T22 associated token accounts → Light token vault. -/// -/// Every transfer crosses standards (T22 ↔ Light) via `TransferInterfaceCpi` -/// with SPL interface PDAs. Same pattern as `test_escrow_spl` but exercises -/// the Token-2022 program path. -#[tokio::test] -async fn test_escrow_t22() { - let mut rpc = create_test_rpc().await; - let ctx = setup_escrow_test(&mut rpc, TokenConfig::Token2022).await; - run_escrow_full_flow(&mut rpc, &ctx).await; -} - -/// Light mint + Light user accounts (rent-free path). -/// -/// All accounts are Light — transfers use `TransferCheckedCpi`. -#[tokio::test] -async fn test_escrow_light() { - let mut rpc = create_test_rpc().await; - let ctx = setup_escrow_test(&mut rpc, TokenConfig::Light).await; - run_escrow_full_flow(&mut rpc, &ctx).await; -} - -/// SPL mint + Light user accounts (interop). -/// -/// Tokens start in SPL associated token accounts, get converted into Light -/// token accounts during setup via `transfer_spl_to_light`. Once in Light -/// token accounts, all escrow transfers are Light-to-Light (`TransferCheckedCpi`). -/// Shows that Light token accounts can hold any SPL mint. -#[tokio::test] -async fn test_escrow_spl_light() { - let mut rpc = create_test_rpc().await; - let ctx = setup_escrow_test(&mut rpc, TokenConfig::LightSpl).await; - run_escrow_full_flow(&mut rpc, &ctx).await; -} - -/// Token-2022 mint + Light user accounts (interop). -/// -/// Tokens start in T22 associated token accounts, get converted into Light -/// token accounts during setup via `transfer_spl_to_light`. Once in Light -/// token accounts, all escrow transfers are Light-to-Light (`TransferCheckedCpi`). -/// Shows that Light token accounts can hold any T22 mint. -#[tokio::test] -async fn test_escrow_t22_light() { - let mut rpc = create_test_rpc().await; - let ctx = setup_escrow_test(&mut rpc, TokenConfig::LightT22).await; - run_escrow_full_flow(&mut rpc, &ctx).await; -} diff --git a/programs/anchor/fundraiser/Cargo.toml b/programs/anchor/fundraiser/Cargo.toml index 8f3287a..6bc6092 100644 --- a/programs/anchor/fundraiser/Cargo.toml +++ b/programs/anchor/fundraiser/Cargo.toml @@ -14,17 +14,19 @@ cpi = ["no-entrypoint"] no-entrypoint = [] no-idl = [] no-log-ix-name = [] -idl-build = ["anchor-lang/idl-build", "light-sdk/idl-build"] +idl-build = ["anchor-lang/idl-build", "light-sdk/idl-build", "light-anchor-spl/idl-build"] test-sbf = [] [dependencies] -anchor-lang = { version = "=0.31.1", features = ["init-if-needed", "idl-build"] } +anchor-lang = { version = "=0.31.1", features = ["init-if-needed"] } blake3 = { workspace = true } -light-sdk = { workspace = true, features = ["anchor", "anchor-discriminator", "idl-build", "cpi-context", "v2"] } +light-sdk = { workspace = true, features = ["anchor", "cpi-context", "v2"] } light-token = { workspace = true, features = ["anchor"] } +light-account = { workspace = true } +light-compressed-account = { workspace = true } light-hasher = { workspace = true, features = ["solana"] } -light-anchor-spl = { workspace = true, features = ["idl-build"] } +light-anchor-spl = { workspace = true } solana-program = { workspace = true } solana-pubkey = { workspace = true } solana-account-info = { workspace = true } diff --git a/programs/anchor/fundraiser/src/constants.rs b/programs/anchor/fundraiser/src/constants.rs index 678e5f4..8c1fe69 100644 --- a/programs/anchor/fundraiser/src/constants.rs +++ b/programs/anchor/fundraiser/src/constants.rs @@ -3,4 +3,5 @@ pub const MIN_AMOUNT_TO_RAISE: u64 = 3; pub const SECONDS_TO_DAYS: i64 = 86400; pub const MAX_CONTRIBUTION_PERCENTAGE: u64 = 10; pub const PERCENTAGE_SCALER: u64 = 100; +pub const AUTH_SEED: &[u8] = b"authority"; pub const VAULT_SEED: &[u8] = b"vault"; diff --git a/programs/anchor/fundraiser/src/error.rs b/programs/anchor/fundraiser/src/error.rs index a7dd6fd..d66583b 100644 --- a/programs/anchor/fundraiser/src/error.rs +++ b/programs/anchor/fundraiser/src/error.rs @@ -18,4 +18,6 @@ pub enum FundraiserError { FundraiserEnded, #[msg("Invalid total amount. i should be bigger than 3")] InvalidAmount, + #[msg("Arithmetic overflow in calculation")] + CalculationOverflow, } diff --git a/programs/anchor/fundraiser/src/instructions/checker.rs b/programs/anchor/fundraiser/src/instructions/checker.rs index 1132cdf..9e278f9 100644 --- a/programs/anchor/fundraiser/src/instructions/checker.rs +++ b/programs/anchor/fundraiser/src/instructions/checker.rs @@ -1,10 +1,10 @@ use anchor_lang::prelude::*; use light_anchor_spl::token_interface::{Mint, TokenAccount, TokenInterface}; -use light_token::instruction::RENT_SPONSOR; +use light_token::instruction::LIGHT_TOKEN_RENT_SPONSOR; use light_token::spl_interface::find_spl_interface_pda; use light_token::utils::get_token_account_balance; -use crate::constants::VAULT_SEED; +use crate::constants::{AUTH_SEED, VAULT_SEED}; use crate::instructions::{transfer_tokens, SplInterfaceConfig}; use crate::state::Fundraiser; use crate::FundraiserError; @@ -15,6 +15,10 @@ pub struct CheckContributions<'info> { #[account(mut)] pub fee_payer: Signer<'info>, + /// CHECK: Authority PDA — signs vault operations + #[account(seeds = [AUTH_SEED], bump)] + pub authority: UncheckedAccount<'info>, + #[account(mint::token_program = token_program)] pub mint_to_raise: InterfaceAccount<'info, Mint>, @@ -51,7 +55,7 @@ pub struct CheckContributions<'info> { pub light_token_program: Interface<'info, TokenInterface>, /// CHECK: Light token rent sponsor - validated by address constraint - #[account(mut, address = RENT_SPONSOR)] + #[account(mut, address = LIGHT_TOKEN_RENT_SPONSOR)] pub light_token_rent_sponsor: AccountInfo<'info>, /// CHECK: light-token CPI authority - must be writable for Light token CPI @@ -73,10 +77,9 @@ impl<'info> CheckContributions<'info> { FundraiserError::TargetNotMet ); - let fundraiser_seeds: &[&[u8]] = &[ - b"fundraiser".as_ref(), - self.fee_payer.to_account_info().key.as_ref(), - &[self.fundraiser.bump], + let authority_seeds: &[&[u8]] = &[ + AUTH_SEED, + &[self.fundraiser.auth_bump], ]; let (_, spl_interface_bump) = find_spl_interface_pda(&self.mint_to_raise.key(), false); @@ -95,11 +98,11 @@ impl<'info> CheckContributions<'info> { self.vault.to_account_info(), self.maker_ata.to_account_info(), self.mint_to_raise.to_account_info(), - self.fundraiser.to_account_info(), + self.authority.to_account_info(), self.fee_payer.to_account_info(), self.light_token_cpi_authority.to_account_info(), self.system_program.to_account_info(), - Some(fundraiser_seeds), + Some(authority_seeds), Some(spl_interface), )?; diff --git a/programs/anchor/fundraiser/src/instructions/contribute.rs b/programs/anchor/fundraiser/src/instructions/contribute.rs index a3ed0a9..cce6dc5 100644 --- a/programs/anchor/fundraiser/src/instructions/contribute.rs +++ b/programs/anchor/fundraiser/src/instructions/contribute.rs @@ -1,6 +1,6 @@ use anchor_lang::prelude::*; use light_anchor_spl::token_interface::{Mint, TokenAccount, TokenInterface}; -use light_token::instruction::RENT_SPONSOR; +use light_token::instruction::LIGHT_TOKEN_RENT_SPONSOR; use light_token::spl_interface::find_spl_interface_pda; use crate::constants::{ANCHOR_DISCRIMINATOR, VAULT_SEED}; @@ -55,7 +55,7 @@ pub struct Contribute<'info> { pub light_token_program: Interface<'info, TokenInterface>, /// CHECK: Light token rent sponsor - #[account(mut, address = RENT_SPONSOR)] + #[account(mut, address = LIGHT_TOKEN_RENT_SPONSOR)] pub light_token_rent_sponsor: AccountInfo<'info>, /// CHECK: light-token CPI authority - must be writable for Light token CPI @@ -75,8 +75,10 @@ impl<'info> Contribute<'info> { FundraiserError::ContributionTooSmall ); - let max_contribution = - (self.fundraiser.amount_to_raise * MAX_CONTRIBUTION_PERCENTAGE) / PERCENTAGE_SCALER; + let max_contribution = self.fundraiser.amount_to_raise + .checked_mul(MAX_CONTRIBUTION_PERCENTAGE) + .and_then(|v| v.checked_div(PERCENTAGE_SCALER)) + .ok_or(FundraiserError::CalculationOverflow)?; require!(amount <= max_contribution, FundraiserError::ContributionTooBig); let current_time = Clock::get()?.unix_timestamp; @@ -88,7 +90,8 @@ impl<'info> Contribute<'info> { require!( self.contributor_account.amount <= max_contribution - && self.contributor_account.amount + amount <= max_contribution, + && self.contributor_account.amount.checked_add(amount) + .map_or(false, |total| total <= max_contribution), FundraiserError::MaximumContributionsReached ); @@ -116,8 +119,12 @@ impl<'info> Contribute<'info> { Some(spl_interface), )?; - self.fundraiser.current_amount += amount; - self.contributor_account.amount += amount; + self.fundraiser.current_amount = self.fundraiser.current_amount + .checked_add(amount) + .ok_or(FundraiserError::CalculationOverflow)?; + self.contributor_account.amount = self.contributor_account.amount + .checked_add(amount) + .ok_or(FundraiserError::CalculationOverflow)?; Ok(()) } diff --git a/programs/anchor/fundraiser/src/instructions/initialize.rs b/programs/anchor/fundraiser/src/instructions/initialize.rs index 2f6b78c..e0063c2 100644 --- a/programs/anchor/fundraiser/src/instructions/initialize.rs +++ b/programs/anchor/fundraiser/src/instructions/initialize.rs @@ -1,10 +1,10 @@ use anchor_lang::prelude::*; use light_anchor_spl::token_interface::{Mint, TokenInterface}; -use light_sdk::interface::CreateAccountsProof; -use light_token::anchor::LightAccounts; -use light_token::instruction::{COMPRESSIBLE_CONFIG_V1, RENT_SPONSOR}; +use light_account::CreateAccountsProof; +use light_account::LightAccounts; +use light_token::instruction::{LIGHT_TOKEN_CONFIG, LIGHT_TOKEN_RENT_SPONSOR}; -use crate::constants::{ANCHOR_DISCRIMINATOR, VAULT_SEED}; +use crate::constants::{ANCHOR_DISCRIMINATOR, AUTH_SEED, VAULT_SEED}; use crate::state::Fundraiser; use crate::{FundraiserError, MIN_AMOUNT_TO_RAISE}; @@ -23,6 +23,10 @@ pub struct Initialize<'info> { #[account(mut)] pub fee_payer: Signer<'info>, + /// CHECK: Authority PDA for vault operations + #[account(seeds = [AUTH_SEED], bump)] + pub authority: UncheckedAccount<'info>, + #[account(mint::token_program = token_program)] pub mint_to_raise: InterfaceAccount<'info, Mint>, @@ -42,9 +46,10 @@ pub struct Initialize<'info> { bump, )] #[light_account(init, - token::authority = [VAULT_SEED, self.fundraiser.key()], + token::seeds = [VAULT_SEED, self.fundraiser.key()], token::mint = mint_to_raise, - token::owner = fundraiser, + token::owner = authority, + token::owner_seeds = [AUTH_SEED], token::bump = params.vault_bump )] pub vault: UncheckedAccount<'info>, @@ -56,11 +61,11 @@ pub struct Initialize<'info> { pub light_token_program: Interface<'info, TokenInterface>, /// CHECK: Light token compressible config - validated by address constraint - #[account(address = COMPRESSIBLE_CONFIG_V1)] - pub light_token_compressible_config: AccountInfo<'info>, + #[account(address = LIGHT_TOKEN_CONFIG)] + pub light_token_config: AccountInfo<'info>, /// CHECK: Light token rent sponsor - validated by address constraint - #[account(mut, address = RENT_SPONSOR)] + #[account(mut, address = LIGHT_TOKEN_RENT_SPONSOR)] pub light_token_rent_sponsor: AccountInfo<'info>, /// CHECK: light-token CPI authority @@ -82,6 +87,7 @@ impl<'info> Initialize<'info> { time_started: Clock::get()?.unix_timestamp, duration: params.duration, bump: bumps.fundraiser, + auth_bump: bumps.authority, }); Ok(()) diff --git a/programs/anchor/fundraiser/src/instructions/refund.rs b/programs/anchor/fundraiser/src/instructions/refund.rs index ff602f5..4915733 100644 --- a/programs/anchor/fundraiser/src/instructions/refund.rs +++ b/programs/anchor/fundraiser/src/instructions/refund.rs @@ -1,10 +1,10 @@ use anchor_lang::prelude::*; use light_anchor_spl::token_interface::{Mint, TokenAccount, TokenInterface}; -use light_token::instruction::RENT_SPONSOR; +use light_token::instruction::LIGHT_TOKEN_RENT_SPONSOR; use light_token::spl_interface::find_spl_interface_pda; use light_token::utils::get_token_account_balance; -use crate::constants::VAULT_SEED; +use crate::constants::{AUTH_SEED, VAULT_SEED}; use crate::instructions::{transfer_tokens, SplInterfaceConfig}; use crate::state::{Contributor, Fundraiser}; use crate::{FundraiserError, SECONDS_TO_DAYS}; @@ -16,6 +16,10 @@ pub struct Refund<'info> { pub maker: SystemAccount<'info>, + /// CHECK: Authority PDA — signs vault operations + #[account(seeds = [AUTH_SEED], bump)] + pub authority: UncheckedAccount<'info>, + #[account(mint::token_program = token_program)] pub mint_to_raise: InterfaceAccount<'info, Mint>, @@ -57,7 +61,7 @@ pub struct Refund<'info> { pub light_token_program: Interface<'info, TokenInterface>, /// CHECK: Light token rent sponsor - #[account(mut, address = RENT_SPONSOR)] + #[account(mut, address = LIGHT_TOKEN_RENT_SPONSOR)] pub light_token_rent_sponsor: AccountInfo<'info>, /// CHECK: light-token CPI authority - must be writable for Light token CPI @@ -86,10 +90,9 @@ impl<'info> Refund<'info> { FundraiserError::TargetMet ); - let fundraiser_seeds: &[&[u8]] = &[ - b"fundraiser".as_ref(), - self.maker.to_account_info().key.as_ref(), - &[self.fundraiser.bump], + let authority_seeds: &[&[u8]] = &[ + AUTH_SEED, + &[self.fundraiser.auth_bump], ]; let (_, spl_interface_bump) = find_spl_interface_pda(&self.mint_to_raise.key(), false); @@ -109,15 +112,17 @@ impl<'info> Refund<'info> { self.vault.to_account_info(), self.contributor_ata.to_account_info(), self.mint_to_raise.to_account_info(), - self.fundraiser.to_account_info(), + self.authority.to_account_info(), self.contributor.to_account_info(), self.light_token_cpi_authority.to_account_info(), self.system_program.to_account_info(), - Some(fundraiser_seeds), + Some(authority_seeds), Some(spl_interface), )?; - self.fundraiser.current_amount -= refund_amount; + self.fundraiser.current_amount = self.fundraiser.current_amount + .checked_sub(refund_amount) + .ok_or(FundraiserError::CalculationOverflow)?; Ok(()) } diff --git a/programs/anchor/fundraiser/src/lib.rs b/programs/anchor/fundraiser/src/lib.rs index aec2c87..2477649 100644 --- a/programs/anchor/fundraiser/src/lib.rs +++ b/programs/anchor/fundraiser/src/lib.rs @@ -1,5 +1,5 @@ use anchor_lang::prelude::*; -use light_token::anchor::{derive_light_cpi_signer, light_program, CpiSigner}; +use light_account::{derive_light_cpi_signer, light_program, CpiSigner}; declare_id!("Eoiuq1dXvHxh6dLx3wh9gj8kSAUpga11krTrbfF5XYsC"); diff --git a/programs/anchor/fundraiser/src/state/fundraiser.rs b/programs/anchor/fundraiser/src/state/fundraiser.rs index ceaf9c2..0b6c929 100644 --- a/programs/anchor/fundraiser/src/state/fundraiser.rs +++ b/programs/anchor/fundraiser/src/state/fundraiser.rs @@ -10,4 +10,5 @@ pub struct Fundraiser { pub time_started: i64, pub duration: u16, pub bump: u8, + pub auth_bump: u8, } diff --git a/programs/anchor/fundraiser/tests/common/mod.rs b/programs/anchor/fundraiser/tests/common/mod.rs index 47a33ca..09b614b 100644 --- a/programs/anchor/fundraiser/tests/common/mod.rs +++ b/programs/anchor/fundraiser/tests/common/mod.rs @@ -77,6 +77,7 @@ pub struct FundraiserTestContext { pub fundraiser_pda: Pubkey, pub vault_pda: Pubkey, pub vault_bump: u8, + pub authority_pda: Pubkey, pub spl_interface_pda: Pubkey, pub spl_interface_bump: u8, pub token_config: TokenConfig, @@ -110,8 +111,8 @@ pub async fn setup_fundraiser_test( let program_id = fundraiser::ID; let payer = rpc.get_payer().insecure_clone(); - // Initialize rent-free config (returns the config PDA) - let compression_config = initialize_rent_free_config(rpc, &payer, &program_id).await; + // Initialize rent-free config (returns config PDA + per-program rent sponsor PDA) + let (compression_config, _rent_sponsor) = initialize_rent_free_config(rpc, &payer, &program_id).await; // Create maker let maker = Keypair::new(); @@ -123,6 +124,9 @@ pub async fn setup_fundraiser_test( let amount_to_raise = 1_000_000_000_000u64; let duration = 7u16; // 7 days + // Derive authority PDA (used by vault operations) + let (authority_pda, _) = Pubkey::find_program_address(&[b"authority"], &program_id); + // For Light mints, handle separately if config.uses_light_mints() { // ========== LIGHT MINT SETUP ========== @@ -169,6 +173,7 @@ pub async fn setup_fundraiser_test( fundraiser_pda, vault_pda, vault_bump, + authority_pda, spl_interface_pda, spl_interface_bump: 0, token_config: config, @@ -220,6 +225,7 @@ pub async fn setup_fundraiser_test( fundraiser_pda, vault_pda, vault_bump, + authority_pda, spl_interface_pda: spl_interface_result.pda, spl_interface_bump: spl_interface_result.bump, token_config: config, @@ -242,13 +248,14 @@ pub async fn initialize_fundraiser( let initialize_accounts = fundraiser::accounts::Initialize { fee_payer: ctx.maker.pubkey(), + authority: ctx.authority_pda, mint_to_raise: ctx.mint_pubkey, fundraiser: ctx.fundraiser_pda, vault: ctx.vault_pda, token_program, system_program: solana_sdk::system_program::ID, light_token_program: Pubkey::new_from_array(LIGHT_TOKEN_PROGRAM_ID), - light_token_compressible_config: COMPRESSIBLE_CONFIG_V1, + light_token_config: COMPRESSIBLE_CONFIG_V1, light_token_rent_sponsor: RENT_SPONSOR, light_token_cpi_authority: CPI_AUTHORITY_PDA, }; @@ -513,6 +520,7 @@ pub async fn check_contributions(rpc: &mut R, ctx: &FundraiserTestContex let check_contributions_accounts = fundraiser::accounts::CheckContributions { fee_payer: ctx.maker.pubkey(), + authority: ctx.authority_pda, mint_to_raise: ctx.mint_pubkey, fundraiser: ctx.fundraiser_pda, vault: ctx.vault_pda, diff --git a/programs/anchor/light-token-minter/Cargo.toml b/programs/anchor/light-token-minter/Cargo.toml index 5cf38db..2a477ff 100644 --- a/programs/anchor/light-token-minter/Cargo.toml +++ b/programs/anchor/light-token-minter/Cargo.toml @@ -17,15 +17,17 @@ idl-build = ["anchor-lang/idl-build", "light-sdk/idl-build", "light-token/idl-bu test-sbf = [] [dependencies] -anchor-lang = { version = "=0.31.1", features = ["init-if-needed", "idl-build"] } +anchor-lang = { version = "=0.31.1", features = ["init-if-needed"] } # Pin blake3 version for solana-program compatibility blake3 = { workspace = true } -light-sdk = { workspace = true, features = ["anchor", "anchor-discriminator", "idl-build", "cpi-context", "v2"] } -light-token = { workspace = true, features = ["anchor", "idl-build"] } +light-sdk = { workspace = true, features = ["anchor", "cpi-context", "v2"] } +light-token = { workspace = true, features = ["anchor"] } +light-account = { workspace = true } +light-compressed-account = { workspace = true } # Required by LightAccount derive macro light-hasher = { workspace = true, features = ["solana"] } -light-anchor-spl = { workspace = true, features = ["idl-build"] } +light-anchor-spl = { workspace = true } solana-program = { workspace = true } solana-pubkey = { workspace = true } solana-account-info = { workspace = true } diff --git a/programs/anchor/light-token-minter/src/instructions/create.rs b/programs/anchor/light-token-minter/src/instructions/create.rs index ac131a1..eb4466d 100644 --- a/programs/anchor/light-token-minter/src/instructions/create.rs +++ b/programs/anchor/light-token-minter/src/instructions/create.rs @@ -1,7 +1,7 @@ use anchor_lang::prelude::*; -use light_sdk::interface::CreateAccountsProof; -use light_token::anchor::LightAccounts; -use light_token::instruction::{COMPRESSIBLE_CONFIG_V1, RENT_SPONSOR}; +use light_account::CreateAccountsProof; +use light_account::LightAccounts; +use light_token::instruction::{LIGHT_TOKEN_CONFIG, LIGHT_TOKEN_RENT_SPONSOR}; use crate::MINT_SIGNER_SEED; @@ -49,12 +49,12 @@ pub struct CreateMint<'info> { pub compression_config: AccountInfo<'info>, /// CHECK: Light token compressible config. - #[account(address = COMPRESSIBLE_CONFIG_V1)] - pub light_token_compressible_config: AccountInfo<'info>, + #[account(address = LIGHT_TOKEN_CONFIG)] + pub light_token_config: AccountInfo<'info>, /// CHECK: Light token rent sponsor. - #[account(mut, address = RENT_SPONSOR)] - pub rent_sponsor: AccountInfo<'info>, + #[account(mut, address = LIGHT_TOKEN_RENT_SPONSOR)] + pub light_token_rent_sponsor: AccountInfo<'info>, /// CHECK: Light token program. pub light_token_program: AccountInfo<'info>, diff --git a/programs/anchor/light-token-minter/src/instructions/mint.rs b/programs/anchor/light-token-minter/src/instructions/mint.rs index 690cf5f..c1897db 100644 --- a/programs/anchor/light-token-minter/src/instructions/mint.rs +++ b/programs/anchor/light-token-minter/src/instructions/mint.rs @@ -1,7 +1,7 @@ use anchor_lang::prelude::*; -use light_sdk::interface::CreateAccountsProof; -use light_token::anchor::LightAccounts; -use light_token::instruction::{MintToCpi, COMPRESSIBLE_CONFIG_V1, RENT_SPONSOR}; +use light_account::CreateAccountsProof; +use light_account::LightAccounts; +use light_token::instruction::{MintToCpi, LIGHT_TOKEN_CONFIG, LIGHT_TOKEN_RENT_SPONSOR}; #[derive(AnchorSerialize, AnchorDeserialize, Clone)] pub struct MintTokenParams { @@ -42,11 +42,11 @@ pub struct MintTo<'info> { pub system_program: Program<'info, System>, /// CHECK: Light token compressible config. - #[account(address = COMPRESSIBLE_CONFIG_V1)] - pub light_token_compressible_config: AccountInfo<'info>, + #[account(address = LIGHT_TOKEN_CONFIG)] + pub light_token_config: AccountInfo<'info>, /// CHECK: Light token rent sponsor. - #[account(mut, address = RENT_SPONSOR)] + #[account(mut, address = LIGHT_TOKEN_RENT_SPONSOR)] pub light_token_rent_sponsor: AccountInfo<'info>, /// CHECK: Light token CPI authority. diff --git a/programs/anchor/light-token-minter/src/lib.rs b/programs/anchor/light-token-minter/src/lib.rs index 590f2dd..b53cf64 100644 --- a/programs/anchor/light-token-minter/src/lib.rs +++ b/programs/anchor/light-token-minter/src/lib.rs @@ -1,7 +1,7 @@ pub mod instructions; use anchor_lang::prelude::*; -use light_token::anchor::{derive_light_cpi_signer, light_program, CpiSigner}; +use light_account::{derive_light_cpi_signer, light_program, CpiSigner}; pub use instructions::*; diff --git a/programs/anchor/light-token-minter/tests/minter_test.rs b/programs/anchor/light-token-minter/tests/minter_test.rs index 330e59c..0d772bb 100644 --- a/programs/anchor/light-token-minter/tests/minter_test.rs +++ b/programs/anchor/light-token-minter/tests/minter_test.rs @@ -1,6 +1,7 @@ //! Integration tests for Light mint creation using #[light_account(init, mint)] macro. use anchor_lang::{InstructionData, ToAccountMetas}; +use light_account::derive_rent_sponsor_pda; use light_client::interface::{ get_create_accounts_proof, CreateAccountsProofInput, InitializeRentFreeConfig, }; @@ -10,7 +11,8 @@ use light_program_test::{ }; use light_sdk::constants::LIGHT_TOKEN_PROGRAM_ID; use light_token::instruction::{ - derive_token_ata, find_mint_address, COMPRESSIBLE_CONFIG_V1, RENT_SPONSOR, + derive_token_ata, find_mint_address, LIGHT_TOKEN_CONFIG as COMPRESSIBLE_CONFIG_V1, + LIGHT_TOKEN_RENT_SPONSOR as RENT_SPONSOR, }; use solana_instruction::Instruction; use solana_keypair::Keypair; @@ -31,12 +33,15 @@ async fn test_create_light_mint() { // Setup program data for rent-free config let program_data_pda = setup_mock_program_data(&mut rpc, &payer, &program_id); + // Derive per-program rent sponsor PDA + let (rent_sponsor, _) = derive_rent_sponsor_pda(&program_id); + // Initialize rent-free config let (init_config_ix, config_pda) = InitializeRentFreeConfig::new( &program_id, &payer.pubkey(), &program_data_pda, - RENT_SPONSOR, + rent_sponsor, payer.pubkey(), ) .build(); @@ -84,10 +89,10 @@ async fn test_create_light_mint() { mint_signer: mint_signer_pda, light_mint: light_mint_pda, compression_config: config_pda, - light_token_compressible_config: COMPRESSIBLE_CONFIG_V1, - rent_sponsor: RENT_SPONSOR, + light_token_config: COMPRESSIBLE_CONFIG_V1, + light_token_rent_sponsor: RENT_SPONSOR, light_token_program: LIGHT_TOKEN_PROGRAM_ID.into(), - light_token_cpi_authority: light_token::constants::CPI_AUTHORITY_PDA.into(), + light_token_cpi_authority: light_token::constants::LIGHT_TOKEN_CPI_AUTHORITY.into(), system_program: solana_sdk::system_program::ID, }; @@ -195,12 +200,15 @@ async fn test_mint_to() { // Setup program data for rent-free config let program_data_pda = setup_mock_program_data(&mut rpc, &payer, &program_id); + // Derive per-program rent sponsor PDA + let (rent_sponsor, _) = derive_rent_sponsor_pda(&program_id); + // Initialize rent-free config let (init_config_ix, config_pda) = InitializeRentFreeConfig::new( &program_id, &payer.pubkey(), &program_data_pda, - RENT_SPONSOR, + rent_sponsor, payer.pubkey(), ) .build(); @@ -248,10 +256,10 @@ async fn test_mint_to() { mint_signer: mint_signer_pda, light_mint: light_mint_pda, compression_config: config_pda, - light_token_compressible_config: COMPRESSIBLE_CONFIG_V1, - rent_sponsor: RENT_SPONSOR, + light_token_config: COMPRESSIBLE_CONFIG_V1, + light_token_rent_sponsor: RENT_SPONSOR, light_token_program: LIGHT_TOKEN_PROGRAM_ID.into(), - light_token_cpi_authority: light_token::constants::CPI_AUTHORITY_PDA.into(), + light_token_cpi_authority: light_token::constants::LIGHT_TOKEN_CPI_AUTHORITY.into(), system_program: solana_sdk::system_program::ID, }; @@ -327,9 +335,9 @@ async fn test_mint_to() { destination: recipient_ata, light_token_program: LIGHT_TOKEN_PROGRAM_ID.into(), system_program: solana_sdk::system_program::ID, - light_token_compressible_config: COMPRESSIBLE_CONFIG_V1, + light_token_config: COMPRESSIBLE_CONFIG_V1, light_token_rent_sponsor: RENT_SPONSOR, - light_token_cpi_authority: light_token::constants::CPI_AUTHORITY_PDA.into(), + light_token_cpi_authority: light_token::constants::LIGHT_TOKEN_CPI_AUTHORITY.into(), }; let mint_to_data = light_token_minter::instruction::MintTo { diff --git a/programs/anchor/shared-test-utils/Cargo.toml b/programs/anchor/shared-test-utils/Cargo.toml index d98917f..b441145 100644 --- a/programs/anchor/shared-test-utils/Cargo.toml +++ b/programs/anchor/shared-test-utils/Cargo.toml @@ -13,6 +13,7 @@ light-program-test.workspace = true light-client = { workspace = true, features = ["v2", "anchor"] } light-sdk.workspace = true light-token = { workspace = true, features = ["anchor"] } +light-account = { workspace = true } light-hasher = { workspace = true, features = ["solana"] } # Example program dependencies (for calling Light mint creation instructions) diff --git a/programs/anchor/shared-test-utils/src/lib.rs b/programs/anchor/shared-test-utils/src/lib.rs index ab40b73..07f2c7d 100644 --- a/programs/anchor/shared-test-utils/src/lib.rs +++ b/programs/anchor/shared-test-utils/src/lib.rs @@ -15,6 +15,7 @@ use solana_signer::Signer; use spl_token_2022::pod::PodAccount; // Re-exports for convenience +pub use light_account::derive_rent_sponsor_pda; pub use light_client::interface::{ get_create_accounts_proof, CreateAccountsProofInput, CreateAccountsProofResult, InitializeRentFreeConfig, @@ -24,8 +25,8 @@ pub use light_program_test::{ Indexer, ProgramTestConfig, Rpc, }; pub use light_sdk::constants::LIGHT_TOKEN_PROGRAM_ID; -pub use light_token::constants::CPI_AUTHORITY_PDA; -pub use light_token::instruction::{COMPRESSIBLE_CONFIG_V1, RENT_SPONSOR}; +pub use light_token::constants::LIGHT_TOKEN_CPI_AUTHORITY as CPI_AUTHORITY_PDA; +pub use light_token::instruction::{LIGHT_TOKEN_CONFIG as COMPRESSIBLE_CONFIG_V1, LIGHT_TOKEN_RENT_SPONSOR as RENT_SPONSOR}; // Re-export light-token-minter program ID for tests that need to create Light mints pub use light_token_minter::ID as LIGHT_TOKEN_MINTER_PROGRAM_ID; @@ -61,21 +62,27 @@ pub struct SplInterfaceResult { pub mod setup { use super::*; - /// Initialize rent-free config for a program + /// Initialize rent-free config for a program. + /// + /// Derives a per-program rent sponsor PDA from `[RENT_SPONSOR_SEED]` + `program_id`. + /// Returns `(config_pda, rent_sponsor_pda)`. pub async fn initialize_rent_free_config( rpc: &mut R, payer: &Keypair, program_id: &Pubkey, - ) -> Pubkey { + ) -> (Pubkey, Pubkey) { // Setup program data for rent-free config let program_data_pda = setup_mock_program_data(rpc, payer, program_id); + // Derive per-program rent sponsor PDA + let (rent_sponsor, _) = derive_rent_sponsor_pda(program_id); + // Initialize rent-free config let (init_config_ix, config_pda) = InitializeRentFreeConfig::new( program_id, &payer.pubkey(), &program_data_pda, - RENT_SPONSOR, + rent_sponsor, payer.pubkey(), ) .build(); @@ -84,8 +91,14 @@ pub mod setup { .await .expect("Initialize rent-free config should succeed"); + // Fund the per-program rent sponsor PDA so it can pay for PDA rent + rpc.airdrop_lamports(&rent_sponsor, 100_000_000_000) + .await + .expect("Fund rent sponsor PDA should succeed"); + println!("Rent-free config initialized at: {:?}", config_pda); - config_pda + println!(" Rent sponsor PDA: {:?} (funded)", rent_sponsor); + (config_pda, rent_sponsor) } /// Create a new LightProgramTest instance with the given program @@ -282,8 +295,8 @@ pub mod light_tokens { mint_signer: mint_signer_pda, light_mint: mint_pda, compression_config: *compression_config, - light_token_compressible_config: COMPRESSIBLE_CONFIG_V1, - rent_sponsor: RENT_SPONSOR, + light_token_config: COMPRESSIBLE_CONFIG_V1, + light_token_rent_sponsor: RENT_SPONSOR, light_token_program: Pubkey::new_from_array(LIGHT_TOKEN_PROGRAM_ID), light_token_cpi_authority: CPI_AUTHORITY_PDA, system_program: solana_sdk::system_program::ID, @@ -369,7 +382,7 @@ pub mod light_tokens { destination: destination_ata, light_token_program: Pubkey::new_from_array(LIGHT_TOKEN_PROGRAM_ID), system_program: solana_sdk::system_program::ID, - light_token_compressible_config: COMPRESSIBLE_CONFIG_V1, + light_token_config: COMPRESSIBLE_CONFIG_V1, light_token_rent_sponsor: RENT_SPONSOR, light_token_cpi_authority: CPI_AUTHORITY_PDA, }; diff --git a/programs/anchor/token-swap/Cargo.toml b/programs/anchor/token-swap/Cargo.toml index 5b076d3..ac4605c 100644 --- a/programs/anchor/token-swap/Cargo.toml +++ b/programs/anchor/token-swap/Cargo.toml @@ -19,13 +19,15 @@ test-sbf = [] [dependencies] anchor-lang = { version = "=0.31.1", features = ["init-if-needed"] } -anchor-spl = { version = "0.31.1", features = ["metadata", "idl-build"] } +anchor-spl = { version = "0.31.1", features = ["metadata"] } blake3 = { workspace = true } fixed = "=1.27.0" az = "=1.2.1" -light-sdk = { workspace = true, features = ["anchor", "anchor-discriminator", "cpi-context", "v2"] } +light-sdk = { workspace = true, features = ["anchor", "cpi-context", "v2"] } light-token = { workspace = true, features = ["anchor"] } +light-account = { workspace = true } +light-compressed-account = { workspace = true } light-hasher = { workspace = true, features = ["solana"] } light-anchor-spl = { workspace = true } solana-program = { workspace = true } diff --git a/programs/anchor/token-swap/SPL_COMPARISON.md b/programs/anchor/token-swap/SPL_COMPARISON.md new file mode 100644 index 0000000..9dd13c3 --- /dev/null +++ b/programs/anchor/token-swap/SPL_COMPARISON.md @@ -0,0 +1,968 @@ +# Repository Comparison: solana-program-examples vs light-token-escrow-fixes + +This document compares the standard Solana Program Examples (SPL) AMM token-swap with the Light Token implementation, showing exact code differences section by section. + +--- + +## 1. Program Entry Point + +### SPL (solana-program-examples) + +```rust +// tokens/token-swap/anchor/programs/token-swap/src/lib.rs +use anchor_lang::prelude::*; + +declare_id!("AsGVFxWqEn8icRBFQApxJe68x3r9zvfSbmiEzYFATGYn"); + +#[program] +pub mod swap_example { + pub use super::instructions::*; + use super::*; + + pub fn create_amm(ctx: Context, id: Pubkey, fee: u16) -> Result<()> { + instructions::create_amm(ctx, id, fee) + } + + pub fn create_pool(ctx: Context) -> Result<()> { + instructions::create_pool(ctx) + } + + pub fn deposit_liquidity( + ctx: Context, + amount_a: u64, + amount_b: u64, + ) -> Result<()> { + instructions::deposit_liquidity(ctx, amount_a, amount_b) + } + + pub fn withdraw_liquidity(ctx: Context, amount: u64) -> Result<()> { + instructions::withdraw_liquidity(ctx, amount) + } + + pub fn swap_exact_tokens_for_tokens( + ctx: Context, + swap_a: bool, + input_amount: u64, + min_output_amount: u64, + ) -> Result<()> { + instructions::swap_exact_tokens_for_tokens(ctx, swap_a, input_amount, min_output_amount) + } +} +``` + +### Light (light-token-escrow-fixes) + +```rust +// programs/anchor/token-swap/src/lib.rs +use anchor_lang::prelude::*; +use light_token::anchor::{derive_light_cpi_signer, light_program, CpiSigner}; + +declare_id!("AsGVFxWqEn8icRBFQApxJe68x3r9zvfSbmiEzYFATGYn"); + +// NEW: CPI signer for Light Protocol operations +pub const LIGHT_CPI_SIGNER: CpiSigner = + derive_light_cpi_signer!("AsGVFxWqEn8icRBFQApxJe68x3r9zvfSbmiEzYFATGYn"); + +#[light_program] // NEW: Light Protocol macro +#[allow(deprecated)] +#[program] +pub mod swap_example { + pub use super::instructions::*; + use super::*; + + pub fn create_amm(ctx: Context, id: Pubkey, fee: u16) -> Result<()> { + instructions::create_amm(ctx, id, fee) + } + + // Parameters wrapped in struct for proof data + pub fn create_pool<'info>( + ctx: Context<'_, '_, '_, 'info, CreatePool<'info>>, + params: CreatePoolParams, + ) -> Result<()> { + instructions::create_pool(ctx, params) + } + + pub fn deposit_liquidity( + ctx: Context, + amount_a: u64, + amount_b: u64, + ) -> Result<()> { + instructions::deposit_liquidity(ctx, amount_a, amount_b) + } + + pub fn withdraw_liquidity(ctx: Context, amount: u64) -> Result<()> { + instructions::withdraw_liquidity(ctx, amount) + } + + pub fn swap_exact_tokens_for_tokens( + ctx: Context, + swap_a: bool, + input_amount: u64, + min_output_amount: u64, + ) -> Result<()> { + instructions::swap_exact_tokens_for_tokens(ctx, swap_a, input_amount, min_output_amount) + } + + // NEW: Create pool with Light LP mint for fully rent-free operations + pub fn create_pool_light_lp<'info>( + ctx: Context<'_, '_, '_, 'info, CreatePoolLightLp<'info>>, + params: CreatePoolLightLpParams, + ) -> Result<()> { + instructions::create_pool_light_lp(ctx, params) + } +} +``` + +**Key Differences:** + +| Aspect | SPL | Light | +| ------ | --- | ----- | +| Macro | `#[program]` | `#[light_program]` + `#[program]` | +| CPI Signer | None | `derive_light_cpi_signer!` constant | +| create_pool params | None | `CreatePoolParams` with proof data | +| Instructions | 5 | 6 (adds `create_pool_light_lp`) | + +--- + +## 2. Instruction Parameters + +### SPL (solana-program-examples) + +```rust +// tokens/token-swap/anchor/programs/token-swap/src/lib.rs:20-22 +// No parameters for create_pool +pub fn create_pool(ctx: Context) -> Result<()> { + instructions::create_pool(ctx) +} +``` + +### Light (light-token-escrow-fixes) + +```rust +// programs/anchor/token-swap/src/instructions/create_pool.rs:12-17 +#[derive(AnchorSerialize, AnchorDeserialize, Clone)] +pub struct CreatePoolParams { + pub create_accounts_proof: CreateAccountsProof, // ZK proof for account creation + pub pool_account_a_bump: u8, // Pre-computed bump for vault A + pub pool_account_b_bump: u8, // Pre-computed bump for vault B +} + +// programs/anchor/token-swap/src/instructions/create_pool_light_lp.rs:14-21 +#[derive(AnchorSerialize, AnchorDeserialize, Clone)] +pub struct CreatePoolLightLpParams { + pub create_accounts_proof: CreateAccountsProof, + pub pool_account_a_bump: u8, + pub pool_account_b_bump: u8, + pub lp_mint_signer_bump: u8, // For Light LP mint derivation + pub pool_authority_bump: u8, // For pool authority PDA +} +``` + +**Key Differences:** + +- Light requires `CreateAccountsProof` for compressed account creation +- Light pre-computes bump seeds client-side +- `CreatePoolLightLpParams` adds bumps for Light LP mint operations + +--- + +## 3. State Account Definition + +### SPL (solana-program-examples) + +```rust +// tokens/token-swap/anchor/programs/token-swap/src/state.rs +use anchor_lang::prelude::*; + +#[account] +#[derive(Default)] +pub struct Amm { + pub id: Pubkey, + pub admin: Pubkey, + pub fee: u16, +} + +impl Amm { + pub const LEN: usize = 8 + 32 + 32 + 2; +} + +#[account] +#[derive(Default)] +pub struct Pool { + pub amm: Pubkey, + pub mint_a: Pubkey, + pub mint_b: Pubkey, +} + +impl Pool { + pub const LEN: usize = 8 + 32 + 32 + 32; +} +``` + +### Light (light-token-escrow-fixes) + +```rust +// programs/anchor/token-swap/src/state.rs +use anchor_lang::prelude::*; + +#[account] +#[derive(Default)] +pub struct Amm { + pub id: Pubkey, + pub admin: Pubkey, + pub fee: u16, +} + +impl Amm { + pub const LEN: usize = 8 + 32 + 32 + 2; +} + +#[account] +#[derive(Default)] +pub struct Pool { + pub amm: Pubkey, + pub mint_a: Pubkey, + pub mint_b: Pubkey, + pub lp_supply: u64, // NEW: Tracked on-chain for Light LP mint compatibility +} + +impl Pool { + pub const LEN: usize = 8 + 32 + 32 + 32 + 8; +} +``` + +**Key Differences:** + +| Aspect | SPL | Light | +| ------ | --- | ----- | +| Pool size | 104 bytes | 112 bytes (+8) | +| LP supply tracking | Via mint.supply | `lp_supply` field for Light mints | + +The `lp_supply` field is needed because Light mints don't store supply on-chain like SPL mints. + +--- + +## 4. CreatePool Account Constraints + +### SPL (solana-program-examples) + +```rust +// tokens/token-swap/anchor/programs/token-swap/src/instructions/create_pool.rs:21-99 +#[derive(Accounts)] +pub struct CreatePool<'info> { + #[account(seeds = [amm.id.as_ref()], bump)] + pub amm: Box>, + + #[account( + init, + payer = payer, + space = Pool::LEN, + seeds = [amm.key().as_ref(), mint_a.key().as_ref(), mint_b.key().as_ref()], + bump, + )] + pub pool: Box>, + + /// CHECK: Read only authority + #[account( + seeds = [amm.key().as_ref(), mint_a.key().as_ref(), mint_b.key().as_ref(), AUTHORITY_SEED], + bump, + )] + pub pool_authority: AccountInfo<'info>, + + #[account( + init, + payer = payer, + seeds = [amm.key().as_ref(), mint_a.key().as_ref(), mint_b.key().as_ref(), LIQUIDITY_SEED], + bump, + mint::decimals = 6, + mint::authority = pool_authority, + )] + pub mint_liquidity: Box>, + + pub mint_a: Box>, + pub mint_b: Box>, + + #[account( + init, + payer = payer, + associated_token::mint = mint_a, + associated_token::authority = pool_authority, + )] + pub pool_account_a: Box>, + + #[account( + init, + payer = payer, + associated_token::mint = mint_b, + associated_token::authority = pool_authority, + )] + pub pool_account_b: Box>, + + #[account(mut)] + pub payer: Signer<'info>, + + pub token_program: Program<'info, Token>, + pub associated_token_program: Program<'info, AssociatedToken>, + pub system_program: Program<'info, System>, +} +``` + +### Light (light-token-escrow-fixes) + +```rust +// programs/anchor/token-swap/src/instructions/create_pool.rs:29-135 +#[derive(Accounts, LightAccounts)] // NEW: LightAccounts derive +#[instruction(params: CreatePoolParams)] +pub struct CreatePool<'info> { + #[account(seeds = [amm.id.as_ref()], bump)] + pub amm: Box>, + + #[account( + init, + payer = fee_payer, + space = Pool::LEN, + seeds = [amm.key().as_ref(), mint_a.key().as_ref(), mint_b.key().as_ref()], + bump, + )] + pub pool: Box>, + + /// CHECK: PDA verified by seeds constraint + #[account( + seeds = [amm.key().as_ref(), mint_a.key().as_ref(), mint_b.key().as_ref(), AUTHORITY_SEED], + bump, + )] + pub pool_authority: AccountInfo<'info>, + + #[account( + init, + payer = fee_payer, + seeds = [amm.key().as_ref(), mint_a.key().as_ref(), mint_b.key().as_ref(), LIQUIDITY_SEED], + bump, + mint::decimals = 6, + mint::authority = pool_authority, + mint::token_program = liquidity_token_program, + )] + pub mint_liquidity: Box>, + + #[account(mint::token_program = token_program)] + pub mint_a: Box>, + + #[account(mint::token_program = token_program)] + pub mint_b: Box>, + + /// CHECK: PDA verified by seeds constraint + #[account(mut, seeds = [POOL_ACCOUNT_A_SEED, pool.key().as_ref()], bump)] + #[light_account(init, + token::authority = [POOL_ACCOUNT_A_SEED, self.pool.key()], + token::mint = mint_a, + token::owner = pool_authority, + token::bump = params.pool_account_a_bump + )] + pub pool_account_a: UncheckedAccount<'info>, + + /// CHECK: PDA verified by seeds constraint + #[account(mut, seeds = [POOL_ACCOUNT_B_SEED, pool.key().as_ref()], bump)] + #[light_account(init, + token::authority = [POOL_ACCOUNT_B_SEED, self.pool.key()], + token::mint = mint_b, + token::owner = pool_authority, + token::bump = params.pool_account_b_bump + )] + pub pool_account_b: UncheckedAccount<'info>, + + #[account(mut)] + pub fee_payer: Signer<'info>, + + pub token_program: Interface<'info, TokenInterface>, + pub liquidity_token_program: Interface<'info, TokenInterface>, + pub light_token_program: Interface<'info, TokenInterface>, + pub system_program: Program<'info, System>, + + // ========== Light Protocol Accounts ========== + /// CHECK: Validated by address constraint + #[account(address = COMPRESSIBLE_CONFIG_V1)] + pub light_token_compressible_config: AccountInfo<'info>, + + /// CHECK: Validated by address constraint + #[account(mut, address = RENT_SPONSOR)] + pub light_token_rent_sponsor: AccountInfo<'info>, + + /// CHECK: Light token CPI authority + pub light_token_cpi_authority: AccountInfo<'info>, +} +``` + +**Key Differences:** + +| Aspect | SPL | Light | +| ------ | --- | ----- | +| Derive | `Accounts` | `Accounts` + `LightAccounts` | +| Vault type | `Account` | `UncheckedAccount` with `#[light_account]` | +| Vault seeds | ATA derivation | Custom `POOL_ACCOUNT_A_SEED`, `POOL_ACCOUNT_B_SEED` | +| Token program | Single `Token` | Three: `token_program`, `liquidity_token_program`, `light_token_program` | +| Extra accounts | 3 (system, token, ata) | 6+ (+ Light protocol accounts) | + +--- + +## 5. Token Transfer Logic + +### SPL (solana-program-examples) + +```rust +// tokens/token-swap/anchor/programs/token-swap/src/instructions/deposit_liquidity.rs:78-100 +// Transfer tokens to the pool +token::transfer( + CpiContext::new( + ctx.accounts.token_program.to_account_info(), + Transfer { + from: ctx.accounts.depositor_account_a.to_account_info(), + to: ctx.accounts.pool_account_a.to_account_info(), + authority: ctx.accounts.depositor.to_account_info(), + }, + ), + amount_a, +)?; +token::transfer( + CpiContext::new( + ctx.accounts.token_program.to_account_info(), + Transfer { + from: ctx.accounts.depositor_account_b.to_account_info(), + to: ctx.accounts.pool_account_b.to_account_info(), + authority: ctx.accounts.depositor.to_account_info(), + }, + ), + amount_b, +)?; +``` + +### Light (light-token-escrow-fixes) + +```rust +// programs/anchor/token-swap/src/instructions/shared.rs:5-81 +pub struct SplInterfaceConfig<'info> { + pub mint: AccountInfo<'info>, + pub spl_token_program: AccountInfo<'info>, + pub spl_interface_pda: AccountInfo<'info>, + pub spl_interface_pda_bump: u8, +} + +fn is_light_account(account: &AccountInfo) -> bool { + account.owner == &Pubkey::new_from_array(LIGHT_TOKEN_PROGRAM_ID) +} + +pub fn transfer_tokens<'info>( + amount: u64, + decimals: u8, + from: AccountInfo<'info>, + to: AccountInfo<'info>, + mint: AccountInfo<'info>, + authority: AccountInfo<'info>, + payer: AccountInfo<'info>, + light_token_cpi_authority: AccountInfo<'info>, + system_program: AccountInfo<'info>, + signer_seeds: Option<&[&[u8]]>, + spl_interface: Option>, +) -> Result<()> { + let is_light_to_light = is_light_account(&from) && is_light_account(&to); + + if is_light_to_light { + // Pure Light-to-Light transfer + let cpi = TransferCheckedCpi { + source: from, + mint, + destination: to, + amount, + decimals, + authority, + system_program, + max_top_up: Some(0), + fee_payer: Some(payer), + }; + + if let Some(seeds) = signer_seeds { + cpi.invoke_signed(&[seeds]) + } else { + cpi.invoke() + } + .map_err(|e| anchor_lang::prelude::ProgramError::from(e).into()) + } else { + // SPL<->Light transfer via interface + let mut cpi = TransferInterfaceCpi::new( + amount, + decimals, + from, + to, + authority, + payer, + light_token_cpi_authority, + system_program, + ); + + if let Some(spl) = spl_interface { + cpi = cpi + .with_spl_interface( + Some(spl.mint), + Some(spl.spl_token_program), + Some(spl.spl_interface_pda), + Some(spl.spl_interface_pda_bump), + ) + .map_err(|e| anchor_lang::prelude::ProgramError::from(e))?; + } + + if let Some(seeds) = signer_seeds { + cpi.invoke_signed(&[seeds]) + } else { + cpi.invoke() + } + .map_err(|e| anchor_lang::prelude::ProgramError::from(e).into()) + } +} +``` + +**Key Differences:** + +| Aspect | SPL | Light | +| ------ | --- | ----- | +| Function params | 4 typed params | 11 params including Light infra | +| Transfer type | Single `token::transfer` | Conditional: `TransferCheckedCpi` or `TransferInterfaceCpi` | +| Account detection | N/A | `is_light_account()` checks owner | +| Cross-protocol | Not supported | `SplInterfaceConfig` for SPL<->Light | +| CPI pattern | `CpiContext::new()` | Direct struct construction + `invoke()` | + +--- + +## 6. LP Token Minting/Burning + +### SPL (solana-program-examples) + +```rust +// tokens/token-swap/anchor/programs/token-swap/src/instructions/deposit_liquidity.rs:102-123 +// Mint the liquidity to user +let authority_bump = ctx.bumps.pool_authority; +let authority_seeds = &[ + &ctx.accounts.pool.amm.to_bytes(), + &ctx.accounts.mint_a.key().to_bytes(), + &ctx.accounts.mint_b.key().to_bytes(), + AUTHORITY_SEED, + &[authority_bump], +]; +let signer_seeds = &[&authority_seeds[..]]; +token::mint_to( + CpiContext::new_with_signer( + ctx.accounts.token_program.to_account_info(), + MintTo { + mint: ctx.accounts.mint_liquidity.to_account_info(), + to: ctx.accounts.depositor_account_liquidity.to_account_info(), + authority: ctx.accounts.pool_authority.to_account_info(), + }, + signer_seeds, + ), + liquidity, +)?; + +// tokens/token-swap/anchor/programs/token-swap/src/instructions/withdraw_liquidity.rs:69-81 +// Burn the liquidity tokens +token::burn( + CpiContext::new( + ctx.accounts.token_program.to_account_info(), + Burn { + mint: ctx.accounts.mint_liquidity.to_account_info(), + from: ctx.accounts.depositor_account_liquidity.to_account_info(), + authority: ctx.accounts.depositor.to_account_info(), + }, + ), + amount, +)?; +``` + +### Light (light-token-escrow-fixes) + +```rust +// programs/anchor/token-swap/src/instructions/deposit_liquidity.rs:140-167 +let is_light_lp = ctx.accounts.liquidity_token_program.key().to_bytes() == LIGHT_TOKEN_PROGRAM_ID; + +if is_light_lp { + // Light LP mint + MintToCpi { + mint: ctx.accounts.mint_liquidity.to_account_info(), + destination: ctx.accounts.depositor_account_liquidity.to_account_info(), + amount: liquidity, + authority: ctx.accounts.pool_authority.to_account_info(), + system_program: ctx.accounts.system_program.to_account_info(), + max_top_up: None, + fee_payer: Some(ctx.accounts.payer.to_account_info()), + } + .invoke_signed(&[authority_seeds])?; +} else { + // SPL/T22 LP mint + let signer_seeds = &[authority_seeds]; + light_anchor_spl::token_interface::mint_to( + CpiContext::new_with_signer( + ctx.accounts.liquidity_token_program.to_account_info(), + MintTo { + mint: ctx.accounts.mint_liquidity.to_account_info(), + to: ctx.accounts.depositor_account_liquidity.to_account_info(), + authority: ctx.accounts.pool_authority.to_account_info(), + }, + signer_seeds, + ), + liquidity, + )?; +} + +// programs/anchor/token-swap/src/instructions/withdraw_liquidity.rs:100-123 +if is_light_lp { + BurnCpi { + source: ctx.accounts.depositor_account_liquidity.to_account_info(), + mint: ctx.accounts.mint_liquidity.to_account_info(), + amount, + authority: ctx.accounts.depositor.to_account_info(), + system_program: ctx.accounts.system_program.to_account_info(), + max_top_up: None, + fee_payer: None, + } + .invoke()?; +} else { + token_interface::burn( + CpiContext::new( + ctx.accounts.liquidity_token_program.to_account_info(), + Burn { + mint: ctx.accounts.mint_liquidity.to_account_info(), + from: ctx.accounts.depositor_account_liquidity.to_account_info(), + authority: ctx.accounts.depositor.to_account_info(), + }, + ), + amount, + )?; +} +``` + +**Key Differences:** + +| Aspect | SPL | Light | +| ------ | --- | ----- | +| Mint CPI | Single `token::mint_to` | Conditional: `MintToCpi` (Light) or `mint_to` (SPL/T22) | +| Burn CPI | Single `token::burn` | Conditional: `BurnCpi` (Light) or `burn` (SPL/T22) | +| LP type detection | N/A | Check `liquidity_token_program` against `LIGHT_TOKEN_PROGRAM_ID` | +| LP supply tracking | Via mint.supply | Manual `pool.lp_supply` field updates | + +--- + +## 7. Balance Reading + +### SPL (solana-program-examples) + +```rust +// tokens/token-swap/anchor/programs/token-swap/src/instructions/deposit_liquidity.rs:32-35 +let pool_a = &ctx.accounts.pool_account_a; +let pool_b = &ctx.accounts.pool_account_b; +let pool_creation = pool_a.amount == 0 && pool_b.amount == 0; + +// tokens/token-swap/anchor/programs/token-swap/src/instructions/swap_exact_tokens_for_tokens.rs:135-136 +// Reload accounts because of the CPIs +ctx.accounts.pool_account_a.reload()?; +ctx.accounts.pool_account_b.reload()?; +``` + +### Light (light-token-escrow-fixes) + +```rust +// programs/anchor/token-swap/src/instructions/deposit_liquidity.rs:23-26 +let pool_a_balance = get_token_account_balance(&ctx.accounts.pool_account_a.to_account_info()) + .map_err(|_| anchor_lang::prelude::ProgramError::InvalidAccountData)?; +let pool_b_balance = get_token_account_balance(&ctx.accounts.pool_account_b.to_account_info()) + .map_err(|_| anchor_lang::prelude::ProgramError::InvalidAccountData)?; + +// programs/anchor/token-swap/src/instructions/swap_exact_tokens_for_tokens.rs:174-179 +let new_pool_a_balance = + get_token_account_balance(&ctx.accounts.pool_account_a.to_account_info()) + .map_err(|_| anchor_lang::prelude::ProgramError::InvalidAccountData)?; +let new_pool_b_balance = + get_token_account_balance(&ctx.accounts.pool_account_b.to_account_info()) + .map_err(|_| anchor_lang::prelude::ProgramError::InvalidAccountData)?; +``` + +**Key Differences:** + +| Aspect | SPL | Light | +| ------ | --- | ----- | +| Balance access | Direct `.amount` field | `get_token_account_balance()` helper | +| Account type | Typed `InterfaceAccount` | `UncheckedAccount` (Light-aware parsing) | +| Refresh method | `.reload()` | Re-call `get_token_account_balance()` | + +--- + +## 8. Constants + +### SPL (solana-program-examples) + +```rust +// tokens/token-swap/anchor/programs/token-swap/src/constants.rs +use anchor_lang::prelude::*; + +#[constant] +pub const MINIMUM_LIQUIDITY: u64 = 100; + +#[constant] +pub const AUTHORITY_SEED: &[u8] = b"authority"; + +#[constant] +pub const LIQUIDITY_SEED: &[u8] = b"liquidity"; +``` + +### Light (light-token-escrow-fixes) + +```rust +// programs/anchor/token-swap/src/constants.rs +use anchor_lang::prelude::*; + +#[constant] +pub const MINIMUM_LIQUIDITY: u64 = 100; + +#[constant] +pub const AUTHORITY_SEED: &[u8] = b"authority"; + +#[constant] +pub const LIQUIDITY_SEED: &[u8] = b"liquidity"; + +// NEW: Pool vault seeds (Light token accounts use custom PDAs, not ATAs) +#[constant] +pub const POOL_ACCOUNT_A_SEED: &[u8] = b"pool_a"; + +#[constant] +pub const POOL_ACCOUNT_B_SEED: &[u8] = b"pool_b"; + +// NEW: LP mint signer seed for FullLight config +#[constant] +pub const LP_MINT_SIGNER_SEED: &[u8] = b"lp_mint_signer"; +``` + +**Key Differences:** + +- SPL: 3 constants +- Light: 6 constants (adds `POOL_ACCOUNT_A_SEED`, `POOL_ACCOUNT_B_SEED`, `LP_MINT_SIGNER_SEED`) +- Light vaults use custom PDA derivation instead of standard ATAs + +--- + +## 9. Dependencies (Cargo.toml) + +### SPL (solana-program-examples) + +```toml +# tokens/token-swap/anchor/programs/token-swap/Cargo.toml +[dependencies] +anchor-lang = "0.32.1" +anchor-spl = "0.32.1" +fixed = "1.20.0" + +[dev-dependencies] +# None - tests are in TypeScript +``` + +### Light (light-token-escrow-fixes) + +```toml +# programs/anchor/token-swap/Cargo.toml +[dependencies] +anchor-lang.workspace = true # 0.31.1 + +# Light Protocol core +light-sdk = { workspace = true, features = [ + "anchor", "anchor-discriminator", "idl-build", "cpi-context", "v2" +] } # 0.19.0 +light-token = { workspace = true, features = ["anchor"] } # 0.4.0 +light-anchor-spl = { workspace = true, features = ["idl-build"] } # 0.31.1 + +# Math +fixed.workspace = true # 1.20.0 + +# Solana (modular imports) +solana-program.workspace = true # 2.x +solana-pubkey.workspace = true +solana-account-info.workspace = true +solana-program-error.workspace = true +solana-msg.workspace = true + +[dev-dependencies] +light-program-test.workspace = true # 0.19.0 +light-client = { workspace = true, features = ["v2", "anchor"] } # 0.19.0 +spl-token-2022.workspace = true # 7.x +shared-test-utils.workspace = true # Local test utilities +tokio.workspace = true # 1.43.0 +anchor-spl.workspace = true # 0.31.1 +spl-pod.workspace = true # 0.6.0 +``` + +**Key Differences:** + +- SPL: 3 dependencies (anchor-lang, anchor-spl, fixed) +- Light: 10+ dependencies including Light Protocol SDK, token, and test infrastructure +- Light uses workspace dependencies for version consistency +- Light has extensive dev-dependencies for Rust-based testing + +--- + +## 10. Test Structure + +### SPL (solana-program-examples) + +``` +tokens/token-swap/anchor/ +└── tests/ + └── swap.test.ts # Single TypeScript test file +``` + +### Light (light-token-escrow-fixes) + +``` +programs/anchor/token-swap/ +└── tests/ + ├── common/ + │ └── mod.rs # Shared test utilities + ├── user_spl.rs # SPL mint + SPL ATAs + ├── user_t22.rs # T22 mint + T22 ATAs + ├── user_spl_light.rs # SPL mint + Light ATAs + ├── user_t22_light.rs # T22 mint + Light ATAs + ├── user_light.rs # Light mint + Light ATAs (SPL LP) + └── user_light_full.rs # Light mint + Light ATAs + Light LP +``` + +### TokenConfig Enum + +```rust +// tests/common/mod.rs:46-59 +#[derive(Clone, Copy, Debug)] +pub enum TokenConfig { + Spl, // SPL mint + SPL ATAs + Token2022, // T22 mint + T22 ATAs + LightSpl, // SPL mint + Light ATAs (offchain compress) + LightT22, // T22 mint + Light ATAs (offchain compress) + Light, // Light mint + Light ATAs (SPL LP mint) + FullLight, // Light mint + Light ATAs + Light LP mint +} +``` + +### Test Context + +```rust +// tests/common/mod.rs:108-137 +pub struct AmmTestContext { + pub program_id: Pubkey, + pub payer: Keypair, + pub mint_a_pubkey: Pubkey, + pub mint_b_pubkey: Pubkey, + pub amm_pda: Pubkey, + pub amm_id: Pubkey, + pub pool_pda: Pubkey, + pub pool_authority: Pubkey, + pub pool_authority_bump: u8, + pub mint_liquidity: Pubkey, + pub pool_account_a: Pubkey, + pub pool_account_b: Pubkey, + pub pool_a_bump: u8, + pub pool_b_bump: u8, + pub spl_interface_pda_a: Pubkey, + pub spl_interface_pda_b: Pubkey, + pub spl_interface_bump_a: u8, + pub depositor: Keypair, + pub depositor_ata_a: Pubkey, + pub depositor_ata_b: Pubkey, + pub token_config: TokenConfig, + pub light_mint_authority_a: Option, + pub lp_mint_signer: Option, + pub lp_mint_signer_bump: u8, + pub compression_config: Pubkey, +} +``` + +**Key Differences:** + +| Aspect | SPL | Light | +| ------ | --- | ----- | +| Language | TypeScript | Rust | +| Framework | Mocha + Chai | tokio + cargo test-sbf | +| Test files | 1 | 6 (per token combination) | +| Setup | Manual or helpers | `shared-test-utils` crate | +| Parametric | No | Yes (`TokenConfig` enum) | + +--- + +## 11. Additional Light Protocol Infrastructure + +These components exist only in the Light version: + +### Rent-Free Configuration + +```rust +// tests/common/mod.rs:166 +// Initialize rent-free config (returns the config PDA) +let compression_config = initialize_rent_free_config(rpc, &payer, &program_id).await; +``` + +### SPL Interface PDAs + +```rust +// tests/common/mod.rs:329-332 +// Create SPL interface PDAs for both mints +let spl_interface_result_a = + create_spl_interface_pda(rpc, &payer, &mint_a_pubkey, config.mint_type(), false).await; +let spl_interface_result_b = + create_spl_interface_pda(rpc, &payer, &mint_b_pubkey, config.mint_type(), false).await; +``` + +### Create Pool with Light LP Mint + +```rust +// programs/anchor/token-swap/src/instructions/create_pool_light_lp.rs +// Instruction for fully rent-free pool operations +pub fn create_pool_light_lp<'info>( + ctx: Context<'_, '_, '_, 'info, CreatePoolLightLp<'info>>, + params: CreatePoolLightLpParams, +) -> Result<()> { + // 1. Create pool vaults via explicit CPI (not macro) + CreateTokenAccountCpi::rent_free(/* ... */).invoke()?; + + // 2. Initialize pool state + let pool = &mut ctx.accounts.pool; + pool.amm = ctx.accounts.amm.key(); + pool.mint_a = ctx.accounts.mint_a.key(); + pool.mint_b = ctx.accounts.mint_b.key(); + pool.lp_supply = 0; + + // LP mint created via #[light_account(init, ...)] macro + Ok(()) +} +``` + +### Pool Authority Funding + +```rust +// tests/common/mod.rs:1134-1138 +// Fund pool_authority for Light-to-Light transfers (rent top-ups) +if ctx.token_config.uses_light_user_accounts() { + rpc.airdrop_lamports(&ctx.pool_authority, 1_000_000_000) + .await + .expect("Fund pool_authority for rent top-ups"); +} +``` + +--- + +## Summary + +| Category | SPL (solana-program-examples) | Light (light-token-escrow-fixes) | +| -------- | ----------------------------- | -------------------------------- | +| **Purpose** | Educational examples | Production Light Protocol AMM | +| **Account model** | Standard Anchor | Compressed (Light accounts) | +| **Rent** | User pays rent-exempt | Sponsor-based (rent-free) | +| **Token support** | SPL only | SPL + Token-2022 + Light native | +| **Cross-protocol** | No | Yes (SPL<->Light via interface) | +| **LP mint options** | SPL only | SPL, Token-2022, or Light | +| **Pool vaults** | ATAs | Light token PDAs | +| **Dependencies** | 3 crates | 10+ crates | +| **Test language** | TypeScript | Rust | +| **Test coverage** | Single flow | 6 token combinations | +| **Instructions** | 5 | 6 (adds `create_pool_light_lp`) | +| **Complexity** | Lower | Higher (more infrastructure) | +| **Use case** | Learning Solana AMM | Building rent-free DeFi | diff --git a/programs/anchor/token-swap/src/instructions/create_pool.rs b/programs/anchor/token-swap/src/instructions/create_pool.rs index 563ec1b..c49c60e 100644 --- a/programs/anchor/token-swap/src/instructions/create_pool.rs +++ b/programs/anchor/token-swap/src/instructions/create_pool.rs @@ -1,8 +1,8 @@ use anchor_lang::prelude::*; use light_anchor_spl::token_interface::{Mint, TokenInterface}; -use light_sdk::interface::CreateAccountsProof; -use light_token::anchor::LightAccounts; -use light_token::instruction::{COMPRESSIBLE_CONFIG_V1, RENT_SPONSOR}; +use light_account::CreateAccountsProof; +use light_account::LightAccounts; +use light_token::instruction::{LIGHT_TOKEN_CONFIG, LIGHT_TOKEN_RENT_SPONSOR}; use crate::{ constants::{AUTHORITY_SEED, LIQUIDITY_SEED, POOL_ACCOUNT_A_SEED, POOL_ACCOUNT_B_SEED}, @@ -52,12 +52,7 @@ pub struct CreatePool<'info> { /// CHECK: PDA verified by seeds constraint #[account( - seeds = [ - amm.key().as_ref(), - mint_a.key().as_ref(), - mint_b.key().as_ref(), - AUTHORITY_SEED, - ], + seeds = [AUTHORITY_SEED], bump, )] pub pool_authority: AccountInfo<'info>, @@ -91,9 +86,10 @@ pub struct CreatePool<'info> { bump, )] #[light_account(init, - token::authority = [POOL_ACCOUNT_A_SEED, self.pool.key()], + token::seeds = [POOL_ACCOUNT_A_SEED, self.pool.key()], token::mint = mint_a, token::owner = pool_authority, + token::owner_seeds = [AUTHORITY_SEED], token::bump = params.pool_account_a_bump )] pub pool_account_a: UncheckedAccount<'info>, @@ -105,9 +101,10 @@ pub struct CreatePool<'info> { bump, )] #[light_account(init, - token::authority = [POOL_ACCOUNT_B_SEED, self.pool.key()], + token::seeds = [POOL_ACCOUNT_B_SEED, self.pool.key()], token::mint = mint_b, token::owner = pool_authority, + token::owner_seeds = [AUTHORITY_SEED], token::bump = params.pool_account_b_bump )] pub pool_account_b: UncheckedAccount<'info>, @@ -123,11 +120,11 @@ pub struct CreatePool<'info> { pub system_program: Program<'info, System>, /// CHECK: Validated by address constraint - #[account(address = COMPRESSIBLE_CONFIG_V1)] - pub light_token_compressible_config: AccountInfo<'info>, + #[account(address = LIGHT_TOKEN_CONFIG)] + pub light_token_config: AccountInfo<'info>, /// CHECK: Validated by address constraint - #[account(mut, address = RENT_SPONSOR)] + #[account(mut, address = LIGHT_TOKEN_RENT_SPONSOR)] pub light_token_rent_sponsor: AccountInfo<'info>, /// CHECK: Light token CPI authority diff --git a/programs/anchor/token-swap/src/instructions/create_pool_light_lp.rs b/programs/anchor/token-swap/src/instructions/create_pool_light_lp.rs index 8faaa7a..3a2afeb 100644 --- a/programs/anchor/token-swap/src/instructions/create_pool_light_lp.rs +++ b/programs/anchor/token-swap/src/instructions/create_pool_light_lp.rs @@ -1,8 +1,8 @@ use anchor_lang::prelude::*; use light_anchor_spl::token_interface::TokenInterface; -use light_sdk::interface::CreateAccountsProof; -use light_token::anchor::LightAccounts; -use light_token::instruction::{CreateTokenAccountCpi, COMPRESSIBLE_CONFIG_V1, RENT_SPONSOR}; +use light_account::CreateAccountsProof; +use light_account::LightAccounts; +use light_token::instruction::{CreateTokenAccountCpi, LIGHT_TOKEN_CONFIG, LIGHT_TOKEN_RENT_SPONSOR}; use crate::{ constants::{AUTHORITY_SEED, LP_MINT_SIGNER_SEED, POOL_ACCOUNT_A_SEED, POOL_ACCOUNT_B_SEED}, @@ -37,7 +37,7 @@ pub fn create_pool_light_lp( owner: ctx.accounts.pool_authority.key(), } .rent_free( - ctx.accounts.light_token_compressible_config.to_account_info(), + ctx.accounts.light_token_config.to_account_info(), ctx.accounts.light_token_rent_sponsor.to_account_info(), ctx.accounts.system_program.to_account_info(), &crate::ID, @@ -55,7 +55,7 @@ pub fn create_pool_light_lp( owner: ctx.accounts.pool_authority.key(), } .rent_free( - ctx.accounts.light_token_compressible_config.to_account_info(), + ctx.accounts.light_token_config.to_account_info(), ctx.accounts.light_token_rent_sponsor.to_account_info(), ctx.accounts.system_program.to_account_info(), &crate::ID, @@ -95,12 +95,7 @@ pub struct CreatePoolLightLp<'info> { /// CHECK: PDA verified by seeds constraint #[account( - seeds = [ - amm.key().as_ref(), - mint_a.key().as_ref(), - mint_b.key().as_ref(), - AUTHORITY_SEED, - ], + seeds = [AUTHORITY_SEED], bump, )] pub pool_authority: AccountInfo<'info>, @@ -124,7 +119,7 @@ pub struct CreatePoolLightLp<'info> { mint::symbol = b"LP".to_vec(), mint::uri = b"".to_vec(), mint::update_authority = pool_authority, - mint::authority_seeds = &[self.amm.to_account_info().key.as_ref(), self.mint_a.to_account_info().key.as_ref(), self.mint_b.to_account_info().key.as_ref(), AUTHORITY_SEED], + mint::authority_seeds = &[AUTHORITY_SEED], mint::authority_bump = params.pool_authority_bump )] pub mint_liquidity: UncheckedAccount<'info>, @@ -141,7 +136,7 @@ pub struct CreatePoolLightLp<'info> { seeds = [POOL_ACCOUNT_A_SEED, pool.key().as_ref()], bump, )] - #[light_account(token::authority = [POOL_ACCOUNT_A_SEED, self.pool.key()])] + #[light_account(token::seeds = [POOL_ACCOUNT_A_SEED, self.pool.key()], token::owner_seeds = [AUTHORITY_SEED])] pub pool_vault_a: UncheckedAccount<'info>, /// CHECK: Created via CreateTokenAccountCpi in handler @@ -150,7 +145,7 @@ pub struct CreatePoolLightLp<'info> { seeds = [POOL_ACCOUNT_B_SEED, pool.key().as_ref()], bump, )] - #[light_account(token::authority = [POOL_ACCOUNT_B_SEED, self.pool.key()])] + #[light_account(token::seeds = [POOL_ACCOUNT_B_SEED, self.pool.key()], token::owner_seeds = [AUTHORITY_SEED])] pub pool_vault_b: UncheckedAccount<'info>, #[account(mut)] @@ -163,11 +158,11 @@ pub struct CreatePoolLightLp<'info> { pub compression_config: AccountInfo<'info>, /// CHECK: Validated by address constraint - #[account(address = COMPRESSIBLE_CONFIG_V1)] - pub light_token_compressible_config: AccountInfo<'info>, + #[account(address = LIGHT_TOKEN_CONFIG)] + pub light_token_config: AccountInfo<'info>, /// CHECK: Validated by address constraint - #[account(mut, address = RENT_SPONSOR)] + #[account(mut, address = LIGHT_TOKEN_RENT_SPONSOR)] pub light_token_rent_sponsor: AccountInfo<'info>, pub light_token_program: Interface<'info, TokenInterface>, diff --git a/programs/anchor/token-swap/src/instructions/deposit_liquidity.rs b/programs/anchor/token-swap/src/instructions/deposit_liquidity.rs index 859ca29..abf3f32 100644 --- a/programs/anchor/token-swap/src/instructions/deposit_liquidity.rs +++ b/programs/anchor/token-swap/src/instructions/deposit_liquidity.rs @@ -1,7 +1,7 @@ use anchor_lang::prelude::*; use fixed::types::I64F64; use light_anchor_spl::token_interface::{Mint, MintTo, TokenAccount, TokenInterface}; -use light_token::instruction::{MintToCpi, RENT_SPONSOR}; +use light_token::instruction::{MintToCpi, LIGHT_TOKEN_RENT_SPONSOR}; use light_token::spl_interface::find_spl_interface_pda; use light_token::utils::get_token_account_balance; use light_sdk::constants::LIGHT_TOKEN_PROGRAM_ID; @@ -126,13 +126,7 @@ pub fn deposit_liquidity( )?; let authority_bump = ctx.bumps.pool_authority; - let amm_key = ctx.accounts.pool.amm; - let mint_a_key = ctx.accounts.mint_a.key(); - let mint_b_key = ctx.accounts.mint_b.key(); let authority_seeds: &[&[u8]] = &[ - amm_key.as_ref(), - mint_a_key.as_ref(), - mint_b_key.as_ref(), AUTHORITY_SEED, &[authority_bump], ]; @@ -193,12 +187,7 @@ pub struct DepositLiquidity<'info> { /// CHECK: PDA verified by seeds constraint #[account( - seeds = [ - pool.amm.as_ref(), - mint_a.key().as_ref(), - mint_b.key().as_ref(), - AUTHORITY_SEED, - ], + seeds = [AUTHORITY_SEED], bump, )] pub pool_authority: AccountInfo<'info>, @@ -261,7 +250,7 @@ pub struct DepositLiquidity<'info> { pub light_token_program: Interface<'info, TokenInterface>, /// CHECK: Validated by address constraint - #[account(mut, address = RENT_SPONSOR)] + #[account(mut, address = LIGHT_TOKEN_RENT_SPONSOR)] pub light_token_rent_sponsor: AccountInfo<'info>, /// CHECK: Light token CPI authority diff --git a/programs/anchor/token-swap/src/instructions/swap_exact_tokens_for_tokens.rs b/programs/anchor/token-swap/src/instructions/swap_exact_tokens_for_tokens.rs index 0ad6bcb..10a8037 100644 --- a/programs/anchor/token-swap/src/instructions/swap_exact_tokens_for_tokens.rs +++ b/programs/anchor/token-swap/src/instructions/swap_exact_tokens_for_tokens.rs @@ -1,7 +1,7 @@ use anchor_lang::prelude::*; use fixed::types::I64F64; use light_anchor_spl::token_interface::{Mint, TokenAccount, TokenInterface}; -use light_token::instruction::RENT_SPONSOR; +use light_token::instruction::LIGHT_TOKEN_RENT_SPONSOR; use light_token::spl_interface::find_spl_interface_pda; use light_token::utils::get_token_account_balance; @@ -65,12 +65,7 @@ pub fn swap_exact_tokens_for_tokens( let invariant = (pool_a_balance as u128) * (pool_b_balance as u128); let authority_bump = ctx.bumps.pool_authority; - let mint_a_key = ctx.accounts.mint_a.key(); - let mint_b_key = ctx.accounts.mint_b.key(); let authority_seeds: &[&[u8]] = &[ - ctx.accounts.pool.amm.as_ref(), - mint_a_key.as_ref(), - mint_b_key.as_ref(), AUTHORITY_SEED, &[authority_bump], ]; @@ -210,12 +205,7 @@ pub struct SwapExactTokensForTokens<'info> { /// CHECK: PDA verified by seeds constraint #[account( - seeds = [ - pool.amm.as_ref(), - mint_a.key().as_ref(), - mint_b.key().as_ref(), - AUTHORITY_SEED, - ], + seeds = [AUTHORITY_SEED], bump, )] pub pool_authority: AccountInfo<'info>, @@ -268,7 +258,7 @@ pub struct SwapExactTokensForTokens<'info> { pub light_token_program: Interface<'info, TokenInterface>, /// CHECK: Validated by address constraint - #[account(mut, address = RENT_SPONSOR)] + #[account(mut, address = LIGHT_TOKEN_RENT_SPONSOR)] pub light_token_rent_sponsor: AccountInfo<'info>, /// CHECK: Light token CPI authority diff --git a/programs/anchor/token-swap/src/instructions/withdraw_liquidity.rs b/programs/anchor/token-swap/src/instructions/withdraw_liquidity.rs index a9a1e3c..393e813 100644 --- a/programs/anchor/token-swap/src/instructions/withdraw_liquidity.rs +++ b/programs/anchor/token-swap/src/instructions/withdraw_liquidity.rs @@ -2,7 +2,7 @@ use anchor_lang::prelude::*; use fixed::types::I64F64; use light_anchor_spl::token_interface::{self, Burn, Mint, TokenAccount, TokenInterface}; use light_sdk::constants::LIGHT_TOKEN_PROGRAM_ID; -use light_token::instruction::{BurnCpi, RENT_SPONSOR}; +use light_token::instruction::{BurnCpi, LIGHT_TOKEN_RENT_SPONSOR}; use light_token::spl_interface::find_spl_interface_pda; use light_token::utils::get_token_account_balance; @@ -15,13 +15,7 @@ use crate::{ pub fn withdraw_liquidity(ctx: Context, amount: u64) -> Result<()> { let authority_bump = ctx.bumps.pool_authority; - let amm_key = ctx.accounts.pool.amm; - let mint_a_key = ctx.accounts.mint_a.key(); - let mint_b_key = ctx.accounts.mint_b.key(); let authority_seeds: &[&[u8]] = &[ - amm_key.as_ref(), - mint_a_key.as_ref(), - mint_b_key.as_ref(), AUTHORITY_SEED, &[authority_bump], ]; @@ -157,12 +151,7 @@ pub struct WithdrawLiquidity<'info> { /// CHECK: PDA verified by seeds constraint #[account( - seeds = [ - pool.amm.as_ref(), - mint_a.key().as_ref(), - mint_b.key().as_ref(), - AUTHORITY_SEED, - ], + seeds = [AUTHORITY_SEED], bump, )] pub pool_authority: AccountInfo<'info>, @@ -224,7 +213,7 @@ pub struct WithdrawLiquidity<'info> { pub light_token_program: Interface<'info, TokenInterface>, /// CHECK: Validated by address constraint - #[account(mut, address = RENT_SPONSOR)] + #[account(mut, address = LIGHT_TOKEN_RENT_SPONSOR)] pub light_token_rent_sponsor: AccountInfo<'info>, /// CHECK: Light token CPI authority diff --git a/programs/anchor/token-swap/src/lib.rs b/programs/anchor/token-swap/src/lib.rs index 9cddac6..c605f58 100644 --- a/programs/anchor/token-swap/src/lib.rs +++ b/programs/anchor/token-swap/src/lib.rs @@ -1,14 +1,14 @@ #![allow(clippy::result_large_err)] use anchor_lang::prelude::*; -use light_token::anchor::{derive_light_cpi_signer, light_program, CpiSigner}; +use light_account::{derive_light_cpi_signer, light_program, CpiSigner}; mod constants; mod errors; mod instructions; mod state; -pub use constants::{LP_MINT_SIGNER_SEED, POOL_ACCOUNT_A_SEED, POOL_ACCOUNT_B_SEED}; +pub use constants::{AUTHORITY_SEED, LP_MINT_SIGNER_SEED, POOL_ACCOUNT_A_SEED, POOL_ACCOUNT_B_SEED}; pub use instructions::{CreatePoolLightLpParams, CreatePoolParams}; declare_id!("AsGVFxWqEn8icRBFQApxJe68x3r9zvfSbmiEzYFATGYn"); diff --git a/programs/anchor/token-swap/tests/common/mod.rs b/programs/anchor/token-swap/tests/common/mod.rs index dfe8620..c08f7d9 100644 --- a/programs/anchor/token-swap/tests/common/mod.rs +++ b/programs/anchor/token-swap/tests/common/mod.rs @@ -162,8 +162,8 @@ pub async fn setup_amm_test( let program_id = swap_example::ID; let payer = rpc.get_payer().insecure_clone(); - // Initialize rent-free config (returns the config PDA) - let compression_config = initialize_rent_free_config(rpc, &payer, &program_id).await; + // Initialize rent-free config (returns config PDA + per-program rent sponsor PDA) + let (compression_config, _rent_sponsor) = initialize_rent_free_config(rpc, &payer, &program_id).await; // Create depositor let depositor = Keypair::new(); @@ -233,15 +233,8 @@ pub async fn setup_amm_test( &program_id, ); - let (pool_authority, pool_authority_bump) = Pubkey::find_program_address( - &[ - amm_pda.as_ref(), - mint_a_pubkey.as_ref(), - mint_b_pubkey.as_ref(), - b"authority", - ], - &program_id, - ); + let (pool_authority, pool_authority_bump) = + Pubkey::find_program_address(&[b"authority"], &program_id); let (pool_account_a, pool_a_bump) = Pubkey::find_program_address(&[b"pool_a", pool_pda.as_ref()], &program_id); @@ -464,15 +457,8 @@ pub async fn setup_amm_test( &program_id, ); - let (pool_authority, pool_authority_bump) = Pubkey::find_program_address( - &[ - amm_pda.as_ref(), - mint_a_pubkey.as_ref(), - mint_b_pubkey.as_ref(), - b"authority", - ], - &program_id, - ); + let (pool_authority, pool_authority_bump) = + Pubkey::find_program_address(&[b"authority"], &program_id); let (mint_liquidity, _) = Pubkey::find_program_address( &[ @@ -592,7 +578,7 @@ pub async fn create_pool( liquidity_token_program, light_token_program: Pubkey::new_from_array(LIGHT_TOKEN_PROGRAM_ID), system_program: solana_sdk::system_program::ID, - light_token_compressible_config: COMPRESSIBLE_CONFIG_V1, + light_token_config: COMPRESSIBLE_CONFIG_V1, light_token_rent_sponsor: RENT_SPONSOR, light_token_cpi_authority: CPI_AUTHORITY_PDA, }; @@ -651,7 +637,7 @@ pub async fn create_pool_light_lp( fee_payer: ctx.payer.pubkey(), token_program: ctx.token_config.token_program_id(), compression_config: ctx.compression_config, - light_token_compressible_config: COMPRESSIBLE_CONFIG_V1, + light_token_config: COMPRESSIBLE_CONFIG_V1, light_token_rent_sponsor: RENT_SPONSOR, light_token_program: Pubkey::new_from_array(LIGHT_TOKEN_PROGRAM_ID), light_token_cpi_authority: CPI_AUTHORITY_PDA, From b247ef0649d90e46bb17cff7ea7fed6a6a8a1f1a Mon Sep 17 00:00:00 2001 From: tilo-14 Date: Wed, 11 Feb 2026 18:14:00 +0000 Subject: [PATCH 06/10] align educational tests --- CLAUDE.md | 49 ++ programs/anchor/escrow/tests/escrow.rs | 16 +- .../anchor/fundraiser/tests/common/mod.rs | 509 +++--------- .../anchor/fundraiser/tests/fundraiser.rs | 589 ++++++++++++++ .../anchor/fundraiser/tests/user_light.rs | 48 -- programs/anchor/fundraiser/tests/user_spl.rs | 46 -- .../anchor/fundraiser/tests/user_spl_light.rs | 24 - programs/anchor/fundraiser/tests/user_t22.rs | 46 -- .../anchor/fundraiser/tests/user_t22_light.rs | 24 - .../anchor/token-swap/tests/common/mod.rs | 761 +++--------------- programs/anchor/token-swap/tests/swap.rs | 612 ++++++++++++++ .../anchor/token-swap/tests/user_light.rs | 31 - .../token-swap/tests/user_light_full.rs | 33 - programs/anchor/token-swap/tests/user_spl.rs | 31 - .../anchor/token-swap/tests/user_spl_light.rs | 25 - programs/anchor/token-swap/tests/user_t22.rs | 31 - .../anchor/token-swap/tests/user_t22_light.rs | 25 - 17 files changed, 1507 insertions(+), 1393 deletions(-) create mode 100644 programs/anchor/fundraiser/tests/fundraiser.rs delete mode 100644 programs/anchor/fundraiser/tests/user_light.rs delete mode 100644 programs/anchor/fundraiser/tests/user_spl.rs delete mode 100644 programs/anchor/fundraiser/tests/user_spl_light.rs delete mode 100644 programs/anchor/fundraiser/tests/user_t22.rs delete mode 100644 programs/anchor/fundraiser/tests/user_t22_light.rs create mode 100644 programs/anchor/token-swap/tests/swap.rs delete mode 100644 programs/anchor/token-swap/tests/user_light.rs delete mode 100644 programs/anchor/token-swap/tests/user_light_full.rs delete mode 100644 programs/anchor/token-swap/tests/user_spl.rs delete mode 100644 programs/anchor/token-swap/tests/user_spl_light.rs delete mode 100644 programs/anchor/token-swap/tests/user_t22.rs delete mode 100644 programs/anchor/token-swap/tests/user_t22_light.rs diff --git a/CLAUDE.md b/CLAUDE.md index 9e777df..a5d7871 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -198,6 +198,55 @@ pub enum TokenConfig { `setup_escrow_test` creates SPL interface PDAs for all SPL/T22 configs (Spl, Token2022, LightSpl, LightT22) because the vault is always a Light token account — any transfer involving an SPL/T22 account and the Light vault crosses standards and requires an interface PDA. +### Test Flow Phases (`run_escrow_full_flow`) + +The test exercises the full lifecycle in 7 phases, with two compress→load cycles that simulate accounts going cold between transactions: + +1. **Define terms** — offer_id, amounts, PDA derivation +2. **Create accounts** — maker/taker token accounts via `create_token_account` (varies by `TokenConfig`) +3. **Verify initial state** — `verify_light_token_balance` for all four accounts +4. **Compress → Load (pre-make)** — `warp_to_compress` + `load_light_mints` + `load_light_accounts` per owner +5. **Make offer** — `get_create_accounts_proof` for offer PDA, build `MakeOffer` instruction with `remaining_accounts` from proof +6. **Compress → Load (pre-take)** — second compress→load cycle, includes `load_light_pdas` for offer + vault +7. **Take offer + verify** — build `TakeOffer` instruction, verify final balances and account closure + +### Cold/Hot Lifecycle Helpers + +Light Token accounts auto-compress when sponsored rent expires. The test simulates this with `warp_to_compress` → load helpers → transact. All load helpers are no-ops for non-Light (SPL/T22) accounts, so the same flow works for all five configs. + +Four helpers live in `escrow.rs` (not `common/mod.rs`) because they depend on program-specific types: + +**`warp_to_compress(rpc)`** — calls `rpc.warp_epoch_forward(30)` to advance slots past sponsored rent, triggering compression of all Light accounts (mints, ATAs, PDAs). + +**`load_light_mints(rpc, payer, mints)`** — for each mint, calls `rpc.get_mint_interface(address, None)` to check hot/cold state, then `decompress_mint(&mint_iface, payer, rpc)` to build decompression instructions. Permissionless — any signer works. + +**`load_light_accounts(rpc, payer, owner, mints)`** — for each mint, calls `rpc.get_associated_token_account_interface(owner, mint, None)` to resolve the ATA and check cold state. Cold ATAs become `AccountSpec::Ata(iface)`, then `create_load_instructions::(&specs, ...)` builds the decompression transaction. The owner keypair must sign because `Transfer2` requires wallet owner authorization. + +**`load_light_pdas(rpc, payer, maker, program_id, compression_config, offer_pda, vault_pda)`** — loads program-owned accounts (offer + vault) back on-chain: + +- **Offer**: `rpc.get_account_interface(&offer_pda, None)` → deserialize `Offer` from `data[8..]` (skip Anchor discriminator) → `OfferSeeds { fee_payer, id }.into_variant(&data[8..])` → `AccountSpec::Pda(PdaSpec::new(iface, variant, program_id))` +- **Vault**: `rpc.get_token_account_interface(&vault_pda, None)` → deserialize `Token` from `data[..]` (no discriminator offset) → `LightAccountVariant::Vault(TokenDataWithSeeds { seeds: VaultSeeds { offer }, token_data })` → convert `ColdContext::Token` to `ColdContext::Account` via `iface.compressed().unwrap().account.clone()` → `AccountSpec::Pda(PdaSpec::new(...))` +- The maker must sign because the offer's `Pack` includes `fee_payer` (= maker) as a signer + +### LightAccountVariant and Seeds + +`#[light_program]` macro generates `LightAccountVariant`, `OfferSeeds`, and `VaultSeeds` in the `escrow::escrow` module. These types reconstruct account state for cold→hot loading: + +```rust +use escrow::escrow::{LightAccountVariant, OfferSeeds, VaultSeeds}; +use light_account::token::{Token as LightToken, TokenDataWithSeeds}; +use light_account::IntoVariant; +``` + +`OfferSeeds` implements `IntoVariant` — call `.into_variant(&data)` to verify seeds against account data and produce a `LightAccountVariant`. `VaultSeeds` wraps in `TokenDataWithSeeds` and constructs `LightAccountVariant::Vault(...)` directly. + +### Per-Program Rent Sponsor Setup + +`initialize_rent_free_config` (in `shared-test-utils/setup`) derives a per-program rent sponsor PDA via `derive_rent_sponsor_pda(&program_id)`, initializes the rent-free config, and funds the PDA. This is separate from the global `LIGHT_TOKEN_RENT_SPONSOR` — programs need both: + +- `pda_rent_sponsor`: per-program PDA that pays for `#[light_account(init)]` rent +- `light_token_rent_sponsor`: global account used in Light Token CPI operations + ### Shared Test Utilities `shared-test-utils` (`programs/anchor/shared-test-utils/src/lib.rs`) provides reusable helpers: diff --git a/programs/anchor/escrow/tests/escrow.rs b/programs/anchor/escrow/tests/escrow.rs index 42c9216..1c2fcb4 100644 --- a/programs/anchor/escrow/tests/escrow.rs +++ b/programs/anchor/escrow/tests/escrow.rs @@ -23,7 +23,7 @@ //! |------|------|---------------|---------------|---------| //! | `test_escrow_spl` | SPL | SPL associated token accounts | `TransferInterfaceCpi` | SPL mints work with Light vault | //! | `test_escrow_t22` | T22 | T22 associated token accounts | `TransferInterfaceCpi` | T22 mints work with Light vault | -//! | `test_escrow_light` | Light | Light associated token accounts | `TransferCheckedCpi` | Pure Light — lowest cost path | +//! | `test_escrow_light` | Light | Light associated token accounts | `TransferCheckedCpi` | Rent-free path | //! | `test_escrow_spl_light` | SPL | Light associated token accounts | `TransferCheckedCpi` | SPL mint, converted user accounts | //! | `test_escrow_t22_light` | T22 | Light associated token accounts | `TransferCheckedCpi` | T22 mint, converted user accounts | //! @@ -31,7 +31,7 @@ //! (`TransferInterfaceCpi` with SPL interface PDA). //! //! For `Light`/`LightSpl`/`LightT22`: all accounts are Light → direct -//! (`TransferCheckedCpi`, no interface PDA needed during escrow). +//! (`TransferCheckedCpi`, no interface PDA needed ). //! //! `LightSpl`/`LightT22` convert tokens from SPL/T22 associated token accounts //! into Light token accounts *before* the escrow starts (in `create_token_account`). @@ -42,7 +42,7 @@ //! Light Token accounts auto-compress when sponsored rent expires. Before each //! transaction, the test loads cold accounts back on-chain via //! `load_light_accounts`. After account creation, `warp_to_compress` advances -//! slots to trigger compression, demonstrating the full lifecycle: +//! slots to trigger compression to simulate the full lifecycle, where the account might turn cold: //! create → compress → load → transact. mod common; @@ -71,7 +71,7 @@ use solana_signer::Signer; // Tests — one per token configuration: SPL, T22, Light. // ============================================================================ -/// SPL mint with SPL associated token accounts → Light token vault. +/// SPL mint with SPL associated token accounts and Light token vault. /// /// Every transfer crosses standards (SPL ↔ Light) via `TransferInterfaceCpi` /// with SPL interface PDAs. This is the baseline: same mint type as standard @@ -83,11 +83,11 @@ async fn test_escrow_spl() { run_escrow_full_flow(&mut rpc, &ctx).await; } -/// Token-2022 mint with T22 associated token accounts → Light token vault. +/// Token-2022 mint with T22 associated token accounts and Light token vault. /// /// Every transfer crosses standards (T22 ↔ Light) via `TransferInterfaceCpi` -/// with SPL interface PDAs. Same pattern as `test_escrow_spl` but exercises -/// the Token-2022 program path. +/// with SPL interface PDAs. This is the baseline: same mint type as standard +/// SPL escrow, but the vault is a rent-free Light token account. #[tokio::test] async fn test_escrow_t22() { let mut rpc = create_test_rpc().await; @@ -95,7 +95,7 @@ async fn test_escrow_t22() { run_escrow_full_flow(&mut rpc, &ctx).await; } -/// Light mint + Light user accounts (rent-free path). +/// Light mint + Light user accounts and a rent-free Light token vault. /// /// All accounts are Light — transfers use `TransferCheckedCpi`. #[tokio::test] diff --git a/programs/anchor/fundraiser/tests/common/mod.rs b/programs/anchor/fundraiser/tests/common/mod.rs index 09b614b..50ad681 100644 --- a/programs/anchor/fundraiser/tests/common/mod.rs +++ b/programs/anchor/fundraiser/tests/common/mod.rs @@ -1,48 +1,71 @@ -//! Common test utilities for fundraiser tests. +//! Fundraiser test setup for 5 token standard combinations: SPL, T22, Light. //! -//! This module provides shared test helpers for different token type combinations: -//! - SPL mint + SPL ATAs -//! - T22 mint + T22 ATAs -//! - SPL mint + Light user accounts -//! - T22 mint + Light user accounts -//! - Light mint + Light user accounts - -use anchor_lang::{InstructionData, ToAccountMetas}; +//! Each combination varies the mint type and contributor account type while the vault +//! is always a Light token account: +//! +//! - `Spl` / `Token2022`: standard associated token accounts, cross-standard transfers to Light vault +//! - `Light`: native Light token accounts, direct transfers (lowest cost) +//! - `LightSpl` / `LightT22`: SPL/T22 mints converted into Light token accounts before +//! the fundraiser starts (tokens are minted to a temp associated token account, then +//! transferred to a Light associated token account via `transfer_spl_to_light`) +//! +//! ## Setup flow +//! +//! 1. `create_test_rpc()` — start test validator with fundraiser + minter programs +//! 2. `setup_fundraiser_test(config)` — create mint, interface PDAs, maker, derive PDAs +//! 3. `create_contributor()` — create funded contributor accounts per config + +// ============================================================================ +// Imports +// ============================================================================ + use anchor_spl::token; use shared_test_utils::{ - helpers::verify_light_token_balance, light_tokens::{create_light_ata, create_light_mint, mint_light_tokens}, setup::initialize_rent_free_config, spl_interface::{create_spl_interface_pda, transfer_spl_to_light}, spl_tokens::{create_spl_ata, create_spl_mint, mint_spl_tokens}, t22_tokens::{create_t22_ata, create_t22_mint, mint_t22_tokens}, - CreateAccountsProofResult, Indexer, LightProgramTest, MintType, ProgramTestConfig, Rpc, - TestRpc, COMPRESSIBLE_CONFIG_V1, CPI_AUTHORITY_PDA, LIGHT_TOKEN_MINTER_PROGRAM_ID, - LIGHT_TOKEN_PROGRAM_ID, RENT_SPONSOR, + Indexer, LightProgramTest, MintType, ProgramTestConfig, Rpc, + SplInterfaceResult, TestRpc, + LIGHT_TOKEN_MINTER_PROGRAM_ID, LIGHT_TOKEN_PROGRAM_ID, }; -use solana_instruction::Instruction; use solana_keypair::Keypair; use solana_pubkey::Pubkey; use solana_signer::Signer; -use spl_token_2022::pod::PodAccount; -/// Token configuration for parameterized tests +// ============================================================================ +// Token Configuration +// ============================================================================ + +/// Token configuration for parameterized fundraiser tests. +/// +/// Each variant determines the mint type and contributor account type. The vault is +/// always a Light token account (rent-free). The contributor account type controls +/// which CPI path `transfer_tokens()` selects at runtime: +/// +/// - SPL/T22 contributor accounts → `TransferInterfaceCpi` (cross-standard, needs interface PDA) +/// - Light contributor accounts → `TransferCheckedCpi` (direct, no interface PDA) #[allow(dead_code)] #[derive(Clone, Copy, Debug)] pub enum TokenConfig { - /// SPL mint + SPL ATAs + /// SPL mint + SPL associated token accounts. Transfers cross standards (SPL ↔ Light vault). Spl, - /// T22 mint + T22 ATAs + /// T22 mint + T22 associated token accounts. Transfers cross standards (T22 ↔ Light vault). Token2022, - /// SPL mint + Light user accounts (offchain SPL->Light conversion) + /// SPL mint + Light associated token accounts. Tokens converted from SPL associated token accounts in setup. + /// During fundraiser, all transfers are Light-to-Light. LightSpl, - /// T22 mint + Light user accounts (offchain T22->Light conversion) + /// T22 mint + Light associated token accounts. Tokens converted from T22 associated token accounts in setup. + /// During fundraiser, all transfers are Light-to-Light. LightT22, - /// Light mint + Light user accounts (pure Light-to-Light) + /// Light mint + Light associated token accounts. Pure Light — lowest cost, no bridging. Light, } impl TokenConfig { + /// Returns the underlying mint program type. + /// Light mints use SPL-compatible layout, so this returns `MintType::Spl`. pub fn mint_type(&self) -> MintType { match self { TokenConfig::Spl | TokenConfig::LightSpl => MintType::Spl, @@ -51,6 +74,7 @@ impl TokenConfig { } } + /// Returns the token program ID passed as `token_program` in instructions. pub fn token_program_id(&self) -> Pubkey { match self { TokenConfig::Spl | TokenConfig::LightSpl => token::ID, @@ -63,32 +87,46 @@ impl TokenConfig { pub fn uses_light_mints(&self) -> bool { matches!(self, TokenConfig::Light) } + } +// ============================================================================ +// Test Context +// ============================================================================ + /// Context for fundraiser tests containing all necessary accounts #[allow(dead_code)] pub struct FundraiserTestContext { pub program_id: Pubkey, pub payer: Keypair, - pub mint: Keypair, - /// For Light mints, stores the mint PDA + pub token_config: TokenConfig, + pub compression_config: Pubkey, + /// Per-program rent sponsor PDA (derived from program_id) + pub rent_sponsor: Pubkey, + + // Mint pub mint_pubkey: Pubkey, + pub light_mint_authority: Option, + pub spl_interface: Option, + + // Participants pub maker: Keypair, + + // PDAs pub fundraiser_pda: Pubkey, pub vault_pda: Pubkey, pub vault_bump: u8, pub authority_pda: Pubkey, - pub spl_interface_pda: Pubkey, - pub spl_interface_bump: u8, - pub token_config: TokenConfig, + + // Fundraiser terms pub amount_to_raise: u64, pub duration: u16, - /// Config PDA for light mint creation - pub compression_config: Option, - /// Authority keypair for Light mint (if Light config) - pub light_mint_authority: Option, } +// ============================================================================ +// Setup Functions +// ============================================================================ + /// Create a new LightProgramTest instance for fundraiser tests pub async fn create_test_rpc() -> LightProgramTest { let program_id = fundraiser::ID; @@ -103,16 +141,28 @@ pub async fn create_test_rpc() -> LightProgramTest { LightProgramTest::new(config).await.unwrap() } -/// Setup the fundraiser test environment based on token config +/// Initialize mint, interface PDAs, and participants for a given token config. +/// +/// SPL interface PDAs are created for all SPL/T22 configs (including `Spl` and +/// `Token2022`, not just `LightSpl`/`LightT22`) because the vault is always a +/// Light token account — any transfer involving an SPL/T22 account and the Light +/// vault crosses standards and requires an interface PDA. +/// +/// For `Light` config, no interface PDA is created (early return). +/// +/// Pass `duration_override` to set a custom fundraiser duration (in days). +/// Defaults to 7 days. Use `Some(1)` for refund tests to minimize warp time. pub async fn setup_fundraiser_test( rpc: &mut R, config: TokenConfig, + duration_override: Option, ) -> FundraiserTestContext { let program_id = fundraiser::ID; let payer = rpc.get_payer().insecure_clone(); // Initialize rent-free config (returns config PDA + per-program rent sponsor PDA) - let (compression_config, _rent_sponsor) = initialize_rent_free_config(rpc, &payer, &program_id).await; + let (compression_config, rent_sponsor) = + initialize_rent_free_config(rpc, &payer, &program_id).await; // Create maker let maker = Keypair::new(); @@ -120,19 +170,24 @@ pub async fn setup_fundraiser_test( .await .unwrap(); - // Amount to raise: 1000 tokens (with 9 decimals) - let amount_to_raise = 1_000_000_000_000u64; - let duration = 7u16; // 7 days + // Fundraiser terms + let amount_to_raise = 1_000_000_000_000u64; // 1000 tokens (9 decimals) + let duration = duration_override.unwrap_or(7u16); // Derive authority PDA (used by vault operations) let (authority_pda, _) = Pubkey::find_program_address(&[b"authority"], &program_id); - // For Light mints, handle separately + // Derive fundraiser and vault PDAs + let (fundraiser_pda, _) = + Pubkey::find_program_address(&[b"fundraiser", maker.pubkey().as_ref()], &program_id); + + let (vault_pda, vault_bump) = Pubkey::find_program_address( + &[fundraiser::VAULT_SEED, fundraiser_pda.as_ref()], + &program_id, + ); + if config.uses_light_mints() { // ========== LIGHT MINT SETUP ========== - println!("\n=== Setting up Light mint ==="); - - // Create Light mint let light_mint = create_light_mint( rpc, &payer, @@ -143,49 +198,26 @@ pub async fn setup_fundraiser_test( ) .await; - let mint_pubkey = light_mint.mint; - println!("Light Mint: {:?}", mint_pubkey); - - // For pure Light-to-Light, we don't need SPL interface PDA - let spl_interface_pda = Pubkey::default(); - - // Derive fundraiser and vault PDAs - let (fundraiser_pda, _) = - Pubkey::find_program_address(&[b"fundraiser", maker.pubkey().as_ref()], &program_id); - - let (vault_pda, vault_bump) = Pubkey::find_program_address( - &[fundraiser::VAULT_SEED, fundraiser_pda.as_ref()], - &program_id, - ); - - println!("Fundraiser PDA: {:?}", fundraiser_pda); - println!("Vault PDA: {:?}", vault_pda); - - // Create dummy keypair for mint (not used for Light mints) - let dummy_keypair = Keypair::new(); - return FundraiserTestContext { program_id, payer, - mint: dummy_keypair, - mint_pubkey, + token_config: config, + compression_config, + rent_sponsor, + mint_pubkey: light_mint.mint, + light_mint_authority: Some(light_mint.authority), + spl_interface: None, maker, fundraiser_pda, vault_pda, vault_bump, authority_pda, - spl_interface_pda, - spl_interface_bump: 0, - token_config: config, amount_to_raise, duration, - compression_config: Some(compression_config), - light_mint_authority: Some(light_mint.authority), }; } // ========== SPL/T22 MINT SETUP ========== - // Create mint based on config (SPL or T22 - Light user accounts still use SPL/T22 mints) let mint = match config { TokenConfig::Spl | TokenConfig::LightSpl => { create_spl_mint(rpc, &payer, &payer.pubkey(), 9).await @@ -197,105 +229,41 @@ pub async fn setup_fundraiser_test( }; let mint_pubkey = mint.pubkey(); - println!("Mint created: {:?}", mint_pubkey); - // Create SPL interface PDA - println!("\n=== Creating SPL interface PDA ==="); - let spl_interface_result = + // Create SPL interface PDA (needed for cross-standard transfers to Light vault) + let iface = create_spl_interface_pda(rpc, &payer, &mint_pubkey, config.mint_type(), false).await; - // Derive fundraiser and vault PDAs - let (fundraiser_pda, _) = - Pubkey::find_program_address(&[b"fundraiser", maker.pubkey().as_ref()], &program_id); - - let (vault_pda, vault_bump) = Pubkey::find_program_address( - &[fundraiser::VAULT_SEED, fundraiser_pda.as_ref()], - &program_id, - ); - - println!("Fundraiser PDA: {:?}", fundraiser_pda); - println!("Vault PDA: {:?}", vault_pda); - FundraiserTestContext { program_id, payer, - mint, + token_config: config, + compression_config, + rent_sponsor, mint_pubkey, + light_mint_authority: None, + spl_interface: Some(iface), maker, fundraiser_pda, vault_pda, vault_bump, authority_pda, - spl_interface_pda: spl_interface_result.pda, - spl_interface_bump: spl_interface_result.bump, - token_config: config, amount_to_raise, duration, - compression_config: Some(compression_config), - light_mint_authority: None, } } -/// Initialize fundraiser -pub async fn initialize_fundraiser( - rpc: &mut R, - ctx: &FundraiserTestContext, - proof_result: CreateAccountsProofResult, -) { - println!("\n=== Initializing Fundraiser ==="); - - let token_program = ctx.token_config.token_program_id(); - - let initialize_accounts = fundraiser::accounts::Initialize { - fee_payer: ctx.maker.pubkey(), - authority: ctx.authority_pda, - mint_to_raise: ctx.mint_pubkey, - fundraiser: ctx.fundraiser_pda, - vault: ctx.vault_pda, - token_program, - system_program: solana_sdk::system_program::ID, - light_token_program: Pubkey::new_from_array(LIGHT_TOKEN_PROGRAM_ID), - light_token_config: COMPRESSIBLE_CONFIG_V1, - light_token_rent_sponsor: RENT_SPONSOR, - light_token_cpi_authority: CPI_AUTHORITY_PDA, - }; - - let initialize_data = fundraiser::instruction::Initialize { - params: fundraiser::instructions::InitializeParams { - create_accounts_proof: proof_result.create_accounts_proof, - amount: ctx.amount_to_raise, - duration: ctx.duration, - vault_bump: ctx.vault_bump, - }, - }; - - let initialize_ix = Instruction { - program_id: ctx.program_id, - accounts: [ - initialize_accounts.to_account_metas(None), - proof_result.remaining_accounts, - ] - .concat(), - data: initialize_data.data(), - }; - - rpc.create_and_send_transaction( - &[initialize_ix], - &ctx.payer.pubkey(), - &[&ctx.payer, &ctx.maker], - ) - .await - .expect("initialize should succeed"); - - println!("Fundraiser initialized!"); - println!( - " Amount to raise: {} tokens", - ctx.amount_to_raise / 1_000_000_000 - ); - println!(" Duration: {} days", ctx.duration); -} - -/// Create a contributor with ATA and funded tokens +// ============================================================================ +// Contributor Account Creation +// ============================================================================ + +/// Create a contributor with a funded token account. +/// +/// Account creation varies by config: +/// - `Spl` / `Token2022`: create standard associated token account, mint directly +/// - `Light`: create Light associated token account via `mint_light_tokens` (creates + mints in one call) +/// - `LightSpl` / `LightT22`: create temp SPL/T22 associated token account → mint → +/// create Light associated token account → convert via `transfer_spl_to_light`. pub async fn create_contributor( rpc: &mut R, ctx: &FundraiserTestContext, @@ -336,12 +304,6 @@ pub async fn create_contributor( ata } TokenConfig::LightSpl => { - // For Light user accounts with SPL mint: - // 1. Create temp SPL ATA, mint tokens - // 2. Create Light ATA - // 3. Transfer from SPL to Light (compress) - println!("Creating Light contributor account (SPL mint)"); - let temp_ata = create_spl_ata(rpc, &ctx.payer, &ctx.mint_pubkey, &contributor.pubkey()).await; mint_spl_tokens( @@ -354,11 +316,13 @@ pub async fn create_contributor( ) .await; - // Create Light ATA let light_ata = create_light_ata(rpc, &ctx.payer, &ctx.mint_pubkey, &contributor.pubkey()).await; - // Transfer from SPL to Light (compress) + let iface = ctx + .spl_interface + .as_ref() + .expect("LightSpl requires SPL interface PDA"); transfer_spl_to_light( rpc, &ctx.payer, @@ -367,8 +331,8 @@ pub async fn create_contributor( 9, &temp_ata, &light_ata, - &ctx.spl_interface_pda, - ctx.spl_interface_bump, + &iface.pda, + iface.bump, funding_amount, MintType::Spl, ) @@ -377,9 +341,6 @@ pub async fn create_contributor( light_ata } TokenConfig::LightT22 => { - // For Light user accounts with T22 mint: - println!("Creating Light contributor account (T22 mint)"); - let temp_ata = create_t22_ata(rpc, &ctx.payer, &ctx.mint_pubkey, &contributor.pubkey()).await; mint_t22_tokens( @@ -392,11 +353,13 @@ pub async fn create_contributor( ) .await; - // Create Light ATA let light_ata = create_light_ata(rpc, &ctx.payer, &ctx.mint_pubkey, &contributor.pubkey()).await; - // Transfer from T22 to Light (compress) + let iface = ctx + .spl_interface + .as_ref() + .expect("LightT22 requires SPL interface PDA"); transfer_spl_to_light( rpc, &ctx.payer, @@ -405,8 +368,8 @@ pub async fn create_contributor( 9, &temp_ata, &light_ata, - &ctx.spl_interface_pda, - ctx.spl_interface_bump, + &iface.pda, + iface.bump, funding_amount, MintType::Token2022, ) @@ -415,17 +378,12 @@ pub async fn create_contributor( light_ata } TokenConfig::Light => { - // For pure Light mints: - // Mint directly to contributor's Light ATA - println!("Creating Light contributor account (Light mint)"); - let mint_authority = ctx .light_mint_authority .as_ref() - .expect("Light config should have mint authority"); + .expect("Light config requires mint authority"); - // Mint tokens directly to contributor's Light ATA - let light_ata = mint_light_tokens( + mint_light_tokens( rpc, &ctx.payer, mint_authority, @@ -433,210 +391,9 @@ pub async fn create_contributor( &contributor.pubkey(), funding_amount, ) - .await; - - light_ata + .await } }; (contributor, contributor_ata) } - -/// Contribute to fundraiser -pub async fn contribute( - rpc: &mut R, - ctx: &FundraiserTestContext, - contributor: &Keypair, - contributor_ata: Pubkey, - amount: u64, -) { - println!("\n=== Contributing ==="); - - let token_program = ctx.token_config.token_program_id(); - - // Derive contributor account PDA - let (contributor_account_pda, _) = Pubkey::find_program_address( - &[ - b"contributor", - ctx.fundraiser_pda.as_ref(), - contributor.pubkey().as_ref(), - ], - &ctx.program_id, - ); - - let contribute_accounts = fundraiser::accounts::Contribute { - contributor: contributor.pubkey(), - mint_to_raise: ctx.mint_pubkey, - fundraiser: ctx.fundraiser_pda, - contributor_account: contributor_account_pda, - contributor_ata, - vault: ctx.vault_pda, - token_program, - system_program: solana_sdk::system_program::ID, - light_token_program: Pubkey::new_from_array(LIGHT_TOKEN_PROGRAM_ID), - light_token_rent_sponsor: RENT_SPONSOR, - light_token_cpi_authority: CPI_AUTHORITY_PDA, - spl_interface_pda: ctx.spl_interface_pda, - }; - - let contribute_data = fundraiser::instruction::Contribute { amount }; - - let contribute_ix = Instruction { - program_id: ctx.program_id, - accounts: contribute_accounts.to_account_metas(None), - data: contribute_data.data(), - }; - - rpc.create_and_send_transaction( - &[contribute_ix], - &ctx.payer.pubkey(), - &[&ctx.payer, contributor], - ) - .await - .expect("contribute should succeed"); - - println!("Contributed {} tokens", amount / 1_000_000_000); -} - -/// Check contributions and claim funds (maker claims) -pub async fn check_contributions(rpc: &mut R, ctx: &FundraiserTestContext) -> Pubkey { - println!("\n=== Maker Claims Funds ==="); - - let token_program = ctx.token_config.token_program_id(); - - // Create maker's ATA (SPL/T22 receives from Light vault via SPL interface, Light receives directly) - let maker_ata = match ctx.token_config { - TokenConfig::Spl | TokenConfig::LightSpl => { - create_spl_ata(rpc, &ctx.payer, &ctx.mint_pubkey, &ctx.maker.pubkey()).await - } - TokenConfig::Token2022 | TokenConfig::LightT22 => { - create_t22_ata(rpc, &ctx.payer, &ctx.mint_pubkey, &ctx.maker.pubkey()).await - } - TokenConfig::Light => { - // For pure Light mints, maker receives to Light ATA - create_light_ata(rpc, &ctx.payer, &ctx.mint_pubkey, &ctx.maker.pubkey()).await - } - }; - - let check_contributions_accounts = fundraiser::accounts::CheckContributions { - fee_payer: ctx.maker.pubkey(), - authority: ctx.authority_pda, - mint_to_raise: ctx.mint_pubkey, - fundraiser: ctx.fundraiser_pda, - vault: ctx.vault_pda, - maker_ata, - token_program, - system_program: solana_sdk::system_program::ID, - light_token_program: Pubkey::new_from_array(LIGHT_TOKEN_PROGRAM_ID), - light_token_rent_sponsor: RENT_SPONSOR, - light_token_cpi_authority: CPI_AUTHORITY_PDA, - spl_interface_pda: ctx.spl_interface_pda, - }; - - let check_contributions_data = fundraiser::instruction::CheckContributions {}; - - let check_contributions_ix = Instruction { - program_id: ctx.program_id, - accounts: check_contributions_accounts.to_account_metas(None), - data: check_contributions_data.data(), - }; - - rpc.create_and_send_transaction( - &[check_contributions_ix], - &ctx.payer.pubkey(), - &[&ctx.payer, &ctx.maker], - ) - .await - .expect("check_contributions should succeed"); - - println!("Maker claimed funds!"); - maker_ata -} - -/// Get token balance from SPL/T22 account -pub async fn get_token_balance(rpc: &mut R, account: Pubkey) -> u64 { - let account_data = rpc - .get_account(account) - .await - .unwrap() - .expect("Token account should exist"); - - let token_state = - spl_pod::bytemuck::pod_from_bytes::(&account_data.data[..165]).unwrap(); - u64::from(token_state.amount) -} - -/// Run the full fundraiser flow test -pub async fn run_fundraiser_full_flow(rpc: &mut R, ctx: &FundraiserTestContext) { - use light_client::interface::{get_create_accounts_proof, CreateAccountsProofInput}; - - // Get proof for creating vault Light token account - let proof_result = get_create_accounts_proof( - rpc, - &ctx.program_id, - vec![CreateAccountsProofInput::pda(ctx.vault_pda)], - ) - .await - .unwrap(); - - // Initialize fundraiser - initialize_fundraiser(rpc, ctx, proof_result).await; - - // Verify vault was created with 0 balance - verify_light_token_balance(rpc, ctx.vault_pda, 0, "vault (initial)").await; - - // Contribution amount is 10% of target (max allowed per contributor) - let contribution_amount = ctx.amount_to_raise * 10 / 100; - - // We need 10 contributors to reach target (each contributes 10%) - let num_contributors = 10; - let contributor_funding = contribution_amount * 2; // Give them extra to be safe - - println!( - "\n=== Creating {} contributors (each contributing {} tokens) ===", - num_contributors, - contribution_amount / 1_000_000_000 - ); - - let mut total_contributed = 0u64; - for i in 0..num_contributors { - let (contributor, contributor_ata) = - create_contributor(rpc, ctx, contributor_funding).await; - contribute(rpc, ctx, &contributor, contributor_ata, contribution_amount).await; - total_contributed += contribution_amount; - println!( - "Contributor {} contributed, total: {} tokens", - i + 1, - total_contributed / 1_000_000_000 - ); - } - - // Verify vault has reached target - verify_light_token_balance( - rpc, - ctx.vault_pda, - ctx.amount_to_raise, - "vault (target reached)", - ) - .await; - - // Maker claims funds - let maker_ata = check_contributions(rpc, ctx).await; - - // Verify vault is empty - verify_light_token_balance(rpc, ctx.vault_pda, 0, "vault (after claim)").await; - - // Verify maker received funds - let maker_balance = get_token_balance(rpc, maker_ata).await; - assert_eq!( - maker_balance, ctx.amount_to_raise, - "Maker should have received all raised funds" - ); - println!("Maker received {} tokens", maker_balance / 1_000_000_000); - - // Verify fundraiser account was closed - let fundraiser_account = rpc.get_account(ctx.fundraiser_pda).await.unwrap(); - assert!(fundraiser_account.is_none(), "Fundraiser should be closed"); - - println!("\n=== Fundraiser full flow test completed successfully! ==="); -} diff --git a/programs/anchor/fundraiser/tests/fundraiser.rs b/programs/anchor/fundraiser/tests/fundraiser.rs new file mode 100644 index 0000000..ceb18d3 --- /dev/null +++ b/programs/anchor/fundraiser/tests/fundraiser.rs @@ -0,0 +1,589 @@ +//! Light Token fundraiser: crowdfunding with rent-free vault. +//! +//! This test shows fundraiser patterns adapted for Light Token. +//! +//! 1. **Authority PDA owns the vault** — not the fundraiser account. This lets +//! the authority sign vault withdrawals without needing account data +//! (see `initialize.rs` `#[light_account(init, token::owner = authority)]`). +//! +//! 2. **Vault is rent-free** — it's a Light token account sponsored by +//! `RENT_SPONSOR`, eliminating the ~0.002 SOL rent per fundraiser. +//! +//! 3. **Validity proof for account creation** — `get_create_accounts_proof()` +//! fetches a validity proof that the vault PDA's derived address does not +//! yet exist in Light's address tree. Only needed in `initialize` (creating +//! new state); `contribute`, `check_contributions`, and `refund` read +//! existing accounts and need no proof. +//! +//! ## Token scenarios +//! +//! The vault is always a Light Token account. The contributor's account type +//! determines which CPI path `transfer_tokens()` in `shared.rs` selects: +//! +//! | Test | Mint | Contributor accounts | Transfer path | Purpose | +//! |------|------|---------------------|---------------|---------| +//! | `test_fundraiser_spl` | SPL | SPL associated token accounts | `TransferInterfaceCpi` | SPL mints work with Light vault | +//! | `test_fundraiser_t22` | T22 | T22 associated token accounts | `TransferInterfaceCpi` | T22 mints work with Light vault | +//! | `test_fundraiser_light` | Light | Light associated token accounts | `TransferCheckedCpi` | Rent-free path | +//! | `test_fundraiser_spl_light` | SPL | Light associated token accounts | `TransferCheckedCpi` | SPL mint, converted contributor accounts | +//! | `test_fundraiser_t22_light` | T22 | Light associated token accounts | `TransferCheckedCpi` | T22 mint, converted contributor accounts | +//! +//! For `Spl`/`Token2022`: contributor accounts are SPL/T22, vault is Light → cross-standard +//! (`TransferInterfaceCpi` with SPL interface PDA). +//! +//! For `Light`/`LightSpl`/`LightT22`: all accounts are Light → direct +//! (`TransferCheckedCpi`, no interface PDA needed). +//! +//! `LightSpl`/`LightT22` convert tokens from SPL/T22 associated token accounts +//! into Light token accounts *before* the fundraiser starts (in `create_contributor`). +//! The fundraiser itself only sees Light token accounts. +//! +//! ## Cold/hot lifecycle +//! +//! The vault is a PDA-owned Light token account that auto-compresses when +//! sponsored rent expires. Loading a compressed vault from cold requires +//! `VaultSeeds` / `LightAccountVariant::Vault` (generated by `#[light_program]` +//! when state derives `LightAccount`). Since `Fundraiser` uses standard +//! `#[account]`, these types aren't generated, so the test doesn't exercise +//! cold/hot lifecycle. See the escrow tests for full cold/hot coverage. + +mod common; + +use anchor_lang::{InstructionData, ToAccountMetas}; +use common::{ + create_contributor, create_test_rpc, setup_fundraiser_test, FundraiserTestContext, TokenConfig, +}; +use light_client::interface::{get_create_accounts_proof, CreateAccountsProofInput}; +use shared_test_utils::{ + helpers::verify_light_token_balance, + light_tokens::create_light_ata, + spl_tokens::create_spl_ata, + t22_tokens::create_t22_ata, + Indexer, LightProgramTest, Rpc, TestRpc, COMPRESSIBLE_CONFIG_V1, CPI_AUTHORITY_PDA, + LIGHT_TOKEN_PROGRAM_ID, RENT_SPONSOR, +}; +use solana_instruction::Instruction; +use solana_keypair::Keypair; +use solana_pubkey::Pubkey; +use solana_signer::Signer; + +// ============================================================================ +// Tests — one per token configuration: SPL, T22, Light + 1 refund test. +// ============================================================================ + +/// SPL mint with SPL associated token accounts and Light token vault. +/// +/// Every transfer crosses standards (SPL ↔ Light) via `TransferInterfaceCpi` +/// with SPL interface PDAs. This is the baseline: same mint type as standard +/// SPL fundraiser, but the vault is a rent-free Light token account. +#[tokio::test] +async fn test_fundraiser_spl() { + let mut rpc = create_test_rpc().await; + let ctx = setup_fundraiser_test(&mut rpc, TokenConfig::Spl, None).await; + run_fundraiser_full_flow(&mut rpc, &ctx).await; +} + +/// Token-2022 mint with T22 associated token accounts and Light token vault. +/// +/// Every transfer crosses standards (T22 ↔ Light) via `TransferInterfaceCpi` +/// with SPL interface PDAs. +#[tokio::test] +async fn test_fundraiser_t22() { + let mut rpc = create_test_rpc().await; + let ctx = setup_fundraiser_test(&mut rpc, TokenConfig::Token2022, None).await; + run_fundraiser_full_flow(&mut rpc, &ctx).await; +} + +/// Light mint + Light contributor accounts and a rent-free Light token vault. +/// +/// All accounts are Light — transfers use `TransferCheckedCpi`. +#[tokio::test] +async fn test_fundraiser_light() { + let mut rpc = create_test_rpc().await; + let ctx = setup_fundraiser_test(&mut rpc, TokenConfig::Light, None).await; + run_fundraiser_full_flow(&mut rpc, &ctx).await; +} + +/// SPL mint + Light contributor accounts (interop). +/// +/// Tokens start in SPL associated token accounts, get converted into Light +/// token accounts during setup via `transfer_spl_to_light`. Once in Light +/// token accounts, all fundraiser transfers are Light-to-Light (`TransferCheckedCpi`). +/// Shows that Light token accounts can hold any SPL mint. +#[tokio::test] +async fn test_fundraiser_spl_light() { + let mut rpc = create_test_rpc().await; + let ctx = setup_fundraiser_test(&mut rpc, TokenConfig::LightSpl, None).await; + run_fundraiser_full_flow(&mut rpc, &ctx).await; +} + +/// Token-2022 mint + Light contributor accounts (interop). +/// +/// Tokens start in T22 associated token accounts, get converted into Light +/// token accounts during setup via `transfer_spl_to_light`. Once in Light +/// token accounts, all fundraiser transfers are Light-to-Light (`TransferCheckedCpi`). +/// Shows that Light token accounts can hold any T22 mint. +#[tokio::test] +async fn test_fundraiser_t22_light() { + let mut rpc = create_test_rpc().await; + let ctx = setup_fundraiser_test(&mut rpc, TokenConfig::LightT22, None).await; + run_fundraiser_full_flow(&mut rpc, &ctx).await; +} + +/// Light mint refund flow: deadline passes, target not met, contributors refund. +/// +/// Uses `duration: 1` (1 day) to minimize warp time. Only 3 contributors +/// contribute (30% of target), so the target is not met. After advancing +/// past the deadline, each contributor calls `refund` to reclaim tokens. +#[tokio::test] +async fn test_fundraiser_refund() { + let mut rpc = create_test_rpc().await; + let ctx = setup_fundraiser_test(&mut rpc, TokenConfig::Light, Some(1)).await; + run_fundraiser_refund_flow(&mut rpc, &ctx).await; +} + +// ============================================================================ +// Full Flow — Claim +// ============================================================================ + +/// Run the full fundraiser claim flow for any token configuration: SPL, T22, Light. +/// +/// 1. Initialize fundraiser: create vault, record terms +/// 2. Verify vault has 0 balance +/// 3. 10 contributors each contribute 10% of target +/// 4. Verify vault reached target +/// 5. Maker claims funds via check_contributions +/// 6. Verify final balances and account closure +async fn run_fundraiser_full_flow( + rpc: &mut R, + ctx: &FundraiserTestContext, +) { + // ==================== PHASE 1: Initialize Fundraiser ==================== + // Create vault, record fundraiser terms (amount, duration, maker) + { + // Validity proof: verifies that the vault PDA's derived address does not + // yet exist in Light's address tree. + let proof_result = get_create_accounts_proof( + rpc, + &ctx.program_id, + vec![CreateAccountsProofInput::pda(ctx.vault_pda)], + ) + .await + .unwrap(); + + let accounts = fundraiser::accounts::Initialize { + fee_payer: ctx.maker.pubkey(), + authority: ctx.authority_pda, + mint_to_raise: ctx.mint_pubkey, + fundraiser: ctx.fundraiser_pda, + vault: ctx.vault_pda, + token_program: ctx.token_config.token_program_id(), + system_program: solana_sdk::system_program::ID, + light_token_program: Pubkey::new_from_array(LIGHT_TOKEN_PROGRAM_ID), + light_token_config: COMPRESSIBLE_CONFIG_V1, + light_token_rent_sponsor: RENT_SPONSOR, + light_token_cpi_authority: CPI_AUTHORITY_PDA, + }; + + let data = fundraiser::instruction::Initialize { + params: fundraiser::instructions::InitializeParams { + create_accounts_proof: proof_result.create_accounts_proof, + amount: ctx.amount_to_raise, + duration: ctx.duration, + vault_bump: ctx.vault_bump, + }, + }; + + // Light system accounts (registered program PDA, noop, account compression + // authority, output state tree queue, address tree) are appended as + // remaining_accounts. The Light system program reads these during CPI + // to verify the proof and insert the new address. + let ix = Instruction { + program_id: ctx.program_id, + accounts: [ + accounts.to_account_metas(None), + proof_result.remaining_accounts, + ] + .concat(), + data: data.data(), + }; + + rpc.create_and_send_transaction( + &[ix], + &ctx.payer.pubkey(), + &[&ctx.payer, &ctx.maker], + ) + .await + .expect("initialize should succeed"); + } + + // ==================== PHASE 2: Verify Initial State ==================== + verify_light_token_balance(rpc, ctx.vault_pda, 0, "vault (initial)").await; + + // ==================== PHASE 3: Contribute (10x) ==================== + // 10 contributors each contribute 10% of target = 100% total + let contribution_amount = ctx.amount_to_raise * 10 / 100; + let contributor_funding = contribution_amount * 2; // extra for fees + + for _i in 0..10 { + let (contributor, contributor_ata) = + create_contributor(rpc, ctx, contributor_funding).await; + + // Derive contributor account PDA + let (contributor_account_pda, _) = Pubkey::find_program_address( + &[ + b"contributor", + ctx.fundraiser_pda.as_ref(), + contributor.pubkey().as_ref(), + ], + &ctx.program_id, + ); + + let accounts = fundraiser::accounts::Contribute { + contributor: contributor.pubkey(), + mint_to_raise: ctx.mint_pubkey, + fundraiser: ctx.fundraiser_pda, + contributor_account: contributor_account_pda, + contributor_ata, + vault: ctx.vault_pda, + token_program: ctx.token_config.token_program_id(), + system_program: solana_sdk::system_program::ID, + light_token_program: Pubkey::new_from_array(LIGHT_TOKEN_PROGRAM_ID), + light_token_rent_sponsor: RENT_SPONSOR, + light_token_cpi_authority: CPI_AUTHORITY_PDA, + spl_interface_pda: ctx + .spl_interface + .as_ref() + .map(|i| i.pda) + .unwrap_or_default(), + }; + + let data = fundraiser::instruction::Contribute { + amount: contribution_amount, + }; + + let ix = Instruction { + program_id: ctx.program_id, + accounts: accounts.to_account_metas(None), + data: data.data(), + }; + + rpc.create_and_send_transaction( + &[ix], + &ctx.payer.pubkey(), + &[&ctx.payer, &contributor], + ) + .await + .expect("contribute should succeed"); + } + + // ==================== PHASE 4: Verify Target Reached ==================== + verify_light_token_balance( + rpc, + ctx.vault_pda, + ctx.amount_to_raise, + "vault (target reached)", + ) + .await; + + // ==================== PHASE 5: Check Contributions (Maker Claims) ==================== + let maker_ata = { + let ata = match ctx.token_config { + TokenConfig::Spl | TokenConfig::LightSpl => { + create_spl_ata(rpc, &ctx.payer, &ctx.mint_pubkey, &ctx.maker.pubkey()).await + } + TokenConfig::Token2022 | TokenConfig::LightT22 => { + create_t22_ata(rpc, &ctx.payer, &ctx.mint_pubkey, &ctx.maker.pubkey()).await + } + TokenConfig::Light => { + create_light_ata(rpc, &ctx.payer, &ctx.mint_pubkey, &ctx.maker.pubkey()).await + } + }; + + let accounts = fundraiser::accounts::CheckContributions { + fee_payer: ctx.maker.pubkey(), + authority: ctx.authority_pda, + mint_to_raise: ctx.mint_pubkey, + fundraiser: ctx.fundraiser_pda, + vault: ctx.vault_pda, + maker_ata: ata, + token_program: ctx.token_config.token_program_id(), + system_program: solana_sdk::system_program::ID, + light_token_program: Pubkey::new_from_array(LIGHT_TOKEN_PROGRAM_ID), + light_token_rent_sponsor: RENT_SPONSOR, + light_token_cpi_authority: CPI_AUTHORITY_PDA, + spl_interface_pda: ctx + .spl_interface + .as_ref() + .map(|i| i.pda) + .unwrap_or_default(), + }; + + let data = fundraiser::instruction::CheckContributions {}; + + let ix = Instruction { + program_id: ctx.program_id, + accounts: accounts.to_account_metas(None), + data: data.data(), + }; + + rpc.create_and_send_transaction( + &[ix], + &ctx.payer.pubkey(), + &[&ctx.payer, &ctx.maker], + ) + .await + .expect("check_contributions should succeed"); + + ata + }; + + // ==================== PHASE 6: Verify Final State ==================== + // Vault should be empty + verify_light_token_balance(rpc, ctx.vault_pda, 0, "vault (after claim)").await; + + // Maker should have received all raised funds + verify_light_token_balance( + rpc, + maker_ata, + ctx.amount_to_raise, + "maker_ata (after claim)", + ) + .await; + + // Fundraiser account should be closed + let fundraiser_account = rpc.get_account(ctx.fundraiser_pda).await.unwrap(); + assert!( + fundraiser_account.is_none(), + "Fundraiser account should be closed after check_contributions" + ); +} + +// ============================================================================ +// Refund Flow +// ============================================================================ + +/// Run the fundraiser refund flow: deadline passes, target not met, contributors reclaim. +/// +/// 1. Initialize fundraiser with short duration (1 day) +/// 2. 3 contributors each contribute 10% (30% total — target not met) +/// 3. Advance clock past deadline (set unix_timestamp directly — no slot warp) +/// 4. Each contributor calls refund to reclaim tokens +/// 5. Verify vault empty, contributor balances restored, fundraiser still exists +async fn run_fundraiser_refund_flow( + rpc: &mut LightProgramTest, + ctx: &FundraiserTestContext, +) { + // ==================== PHASE 1: Initialize Fundraiser ==================== + { + let proof_result = get_create_accounts_proof( + rpc, + &ctx.program_id, + vec![CreateAccountsProofInput::pda(ctx.vault_pda)], + ) + .await + .unwrap(); + + let accounts = fundraiser::accounts::Initialize { + fee_payer: ctx.maker.pubkey(), + authority: ctx.authority_pda, + mint_to_raise: ctx.mint_pubkey, + fundraiser: ctx.fundraiser_pda, + vault: ctx.vault_pda, + token_program: ctx.token_config.token_program_id(), + system_program: solana_sdk::system_program::ID, + light_token_program: Pubkey::new_from_array(LIGHT_TOKEN_PROGRAM_ID), + light_token_config: COMPRESSIBLE_CONFIG_V1, + light_token_rent_sponsor: RENT_SPONSOR, + light_token_cpi_authority: CPI_AUTHORITY_PDA, + }; + + let data = fundraiser::instruction::Initialize { + params: fundraiser::instructions::InitializeParams { + create_accounts_proof: proof_result.create_accounts_proof, + amount: ctx.amount_to_raise, + duration: ctx.duration, + vault_bump: ctx.vault_bump, + }, + }; + + let ix = Instruction { + program_id: ctx.program_id, + accounts: [ + accounts.to_account_metas(None), + proof_result.remaining_accounts, + ] + .concat(), + data: data.data(), + }; + + rpc.create_and_send_transaction( + &[ix], + &ctx.payer.pubkey(), + &[&ctx.payer, &ctx.maker], + ) + .await + .expect("initialize should succeed"); + } + + verify_light_token_balance(rpc, ctx.vault_pda, 0, "vault (initial)").await; + + // ==================== PHASE 2: Partial Contributions (30%) ==================== + // 3 contributors at 10% each — target will not be met + let contribution_amount = ctx.amount_to_raise * 10 / 100; + let contributor_funding = contribution_amount * 2; + let num_contributors = 3; + + let mut contributors: Vec<(Keypair, Pubkey)> = Vec::new(); + for _i in 0..num_contributors { + let (contributor, contributor_ata) = + create_contributor(rpc, ctx, contributor_funding).await; + + let (contributor_account_pda, _) = Pubkey::find_program_address( + &[ + b"contributor", + ctx.fundraiser_pda.as_ref(), + contributor.pubkey().as_ref(), + ], + &ctx.program_id, + ); + + let accounts = fundraiser::accounts::Contribute { + contributor: contributor.pubkey(), + mint_to_raise: ctx.mint_pubkey, + fundraiser: ctx.fundraiser_pda, + contributor_account: contributor_account_pda, + contributor_ata, + vault: ctx.vault_pda, + token_program: ctx.token_config.token_program_id(), + system_program: solana_sdk::system_program::ID, + light_token_program: Pubkey::new_from_array(LIGHT_TOKEN_PROGRAM_ID), + light_token_rent_sponsor: RENT_SPONSOR, + light_token_cpi_authority: CPI_AUTHORITY_PDA, + spl_interface_pda: ctx + .spl_interface + .as_ref() + .map(|i| i.pda) + .unwrap_or_default(), + }; + + let data = fundraiser::instruction::Contribute { + amount: contribution_amount, + }; + + let ix = Instruction { + program_id: ctx.program_id, + accounts: accounts.to_account_metas(None), + data: data.data(), + }; + + rpc.create_and_send_transaction( + &[ix], + &ctx.payer.pubkey(), + &[&ctx.payer, &contributor], + ) + .await + .expect("contribute should succeed"); + + contributors.push((contributor, contributor_ata)); + } + + let total_contributed = contribution_amount * num_contributors as u64; + verify_light_token_balance(rpc, ctx.vault_pda, total_contributed, "vault (partial)").await; + + // ==================== PHASE 3: Advance Past Deadline ==================== + // Advance the Clock sysvar's unix_timestamp directly — `warp_epoch_forward` + // only updates the slot, not unix_timestamp, in LiteSVM. + // + // We don't warp slots here because `warp_epoch_forward` compresses all Light + // accounts (vault, mints, contributor ATAs), and the fundraiser can't load + // the vault from cold: `Fundraiser` doesn't derive `LightAccount`, so + // `#[light_program]` doesn't generate `VaultSeeds` / `LightAccountVariant::Vault` + // needed by `create_load_instructions`. + // + // Duration is 1 day. Refund requires `duration < elapsed_days`, so we need + // the elapsed time to exceed 1 full day (86,400 seconds). Use 2 days. + { + use solana_sdk::clock::Clock; + let mut clock = rpc.context.get_sysvar::(); + clock.unix_timestamp += 2 * 86_400; // advance 2 days + rpc.context.set_sysvar(&clock); + } + + // ==================== PHASE 4: Refund Each Contributor ==================== + for (contributor, contributor_ata) in &contributors { + let (contributor_account_pda, _) = Pubkey::find_program_address( + &[ + b"contributor", + ctx.fundraiser_pda.as_ref(), + contributor.pubkey().as_ref(), + ], + &ctx.program_id, + ); + + let accounts = fundraiser::accounts::Refund { + contributor: contributor.pubkey(), + maker: ctx.maker.pubkey(), + authority: ctx.authority_pda, + mint_to_raise: ctx.mint_pubkey, + fundraiser: ctx.fundraiser_pda, + contributor_account: contributor_account_pda, + contributor_ata: *contributor_ata, + vault: ctx.vault_pda, + token_program: ctx.token_config.token_program_id(), + system_program: solana_sdk::system_program::ID, + light_token_program: Pubkey::new_from_array(LIGHT_TOKEN_PROGRAM_ID), + light_token_rent_sponsor: RENT_SPONSOR, + light_token_cpi_authority: CPI_AUTHORITY_PDA, + spl_interface_pda: ctx + .spl_interface + .as_ref() + .map(|i| i.pda) + .unwrap_or_default(), + }; + + let data = fundraiser::instruction::Refund {}; + + let ix = Instruction { + program_id: ctx.program_id, + accounts: accounts.to_account_metas(None), + data: data.data(), + }; + + rpc.create_and_send_transaction( + &[ix], + &ctx.payer.pubkey(), + &[&ctx.payer, contributor], + ) + .await + .expect("refund should succeed"); + + // Verify contributor received tokens back (started with contributor_funding, + // contributed contribution_amount, got it back → net = contributor_funding) + verify_light_token_balance( + rpc, + *contributor_ata, + contributor_funding, + "contributor_ata (after refund)", + ) + .await; + + // Verify contributor_account PDA was closed + let contributor_acct = rpc.get_account(contributor_account_pda).await.unwrap(); + assert!( + contributor_acct.is_none(), + "Contributor account should be closed after refund" + ); + } + + // ==================== PHASE 5: Verify Final State ==================== + // Vault should be empty + verify_light_token_balance(rpc, ctx.vault_pda, 0, "vault (after all refunds)").await; + + // Fundraiser account should still exist (not closed by refund) + let fundraiser_account = rpc.get_account(ctx.fundraiser_pda).await.unwrap(); + assert!( + fundraiser_account.is_some(), + "Fundraiser account should still exist after refunds (only closed by check_contributions)" + ); +} diff --git a/programs/anchor/fundraiser/tests/user_light.rs b/programs/anchor/fundraiser/tests/user_light.rs deleted file mode 100644 index f01194a..0000000 --- a/programs/anchor/fundraiser/tests/user_light.rs +++ /dev/null @@ -1,48 +0,0 @@ -//! Integration tests for the fundraiser program with Light mints and Light ATAs. -//! -//! Token Configuration: -//! - Mint Type: Light (via CreateMint instruction) -//! - User Accounts: Light token accounts (contributors) -//! - Vault Account: Light Protocol token account -//! -//! This is the pure Light-to-Light test where everything uses light tokens. - -mod common; - -use common::{create_test_rpc, run_fundraiser_full_flow, setup_fundraiser_test, TokenConfig}; - -/// Test the full fundraiser flow with Light tokens -#[tokio::test] -async fn test_fundraiser_full_flow_light() { - let mut rpc = create_test_rpc().await; - let ctx = setup_fundraiser_test(&mut rpc, TokenConfig::Light).await; - run_fundraiser_full_flow(&mut rpc, &ctx).await; -} - -/// Test fundraiser initialization with Light tokens -#[tokio::test] -async fn test_initialize_fundraiser_light() { - use common::initialize_fundraiser; - use light_client::interface::{get_create_accounts_proof, CreateAccountsProofInput}; - use shared_test_utils::helpers::verify_light_token_balance; - - let mut rpc = create_test_rpc().await; - let ctx = setup_fundraiser_test(&mut rpc, TokenConfig::Light).await; - - // Get proof for creating vault - let proof_result = get_create_accounts_proof( - &rpc, - &ctx.program_id, - vec![CreateAccountsProofInput::pda(ctx.vault_pda)], - ) - .await - .unwrap(); - - // Initialize fundraiser - initialize_fundraiser(&mut rpc, &ctx, proof_result).await; - - // Verify vault was created - verify_light_token_balance(&mut rpc, ctx.vault_pda, 0, "vault").await; - - println!("=== Initialize fundraiser test completed successfully! ==="); -} diff --git a/programs/anchor/fundraiser/tests/user_spl.rs b/programs/anchor/fundraiser/tests/user_spl.rs deleted file mode 100644 index e590e5d..0000000 --- a/programs/anchor/fundraiser/tests/user_spl.rs +++ /dev/null @@ -1,46 +0,0 @@ -//! Integration tests for the fundraiser program with SPL mints and SPL ATAs. -//! -//! Token Configuration: -//! - Mint Type: SPL (token::ID) -//! - User Accounts: SPL ATAs (contributors) -//! - Vault Account: Light Protocol token account - -mod common; - -use common::{create_test_rpc, run_fundraiser_full_flow, setup_fundraiser_test, TokenConfig}; - -/// Test the full fundraiser flow with SPL tokens -#[tokio::test] -async fn test_fundraiser_full_flow_spl() { - let mut rpc = create_test_rpc().await; - let ctx = setup_fundraiser_test(&mut rpc, TokenConfig::Spl).await; - run_fundraiser_full_flow(&mut rpc, &ctx).await; -} - -/// Test fundraiser initialization with SPL tokens -#[tokio::test] -async fn test_initialize_fundraiser_spl() { - use common::{initialize_fundraiser, setup_fundraiser_test}; - use light_client::interface::{get_create_accounts_proof, CreateAccountsProofInput}; - use shared_test_utils::helpers::verify_light_token_balance; - - let mut rpc = create_test_rpc().await; - let ctx = setup_fundraiser_test(&mut rpc, TokenConfig::Spl).await; - - // Get proof for creating vault - let proof_result = get_create_accounts_proof( - &rpc, - &ctx.program_id, - vec![CreateAccountsProofInput::pda(ctx.vault_pda)], - ) - .await - .unwrap(); - - // Initialize fundraiser - initialize_fundraiser(&mut rpc, &ctx, proof_result).await; - - // Verify vault was created - verify_light_token_balance(&mut rpc, ctx.vault_pda, 0, "vault").await; - - println!("=== Initialize fundraiser test completed successfully! ==="); -} diff --git a/programs/anchor/fundraiser/tests/user_spl_light.rs b/programs/anchor/fundraiser/tests/user_spl_light.rs deleted file mode 100644 index cc05fd9..0000000 --- a/programs/anchor/fundraiser/tests/user_spl_light.rs +++ /dev/null @@ -1,24 +0,0 @@ -//! Integration tests for the fundraiser program with SPL mints and Light user accounts. -//! -//! Token Configuration: -//! - Mint Type: SPL (token::ID) -//! - User Accounts: Light token accounts (contributors with offchain SPL->Light conversion) -//! - Vault Account: Light Protocol token account -//! -//! ## Test Flow: -//! 1. Create SPL mint and temporary SPL ATA -//! 2. Mint tokens to temporary ATA -//! 3. Create Light token account for contributor -//! 4. Create SPL interface PDA -//! 5. Transfer from SPL ATA to Light account (offchain conversion using `transfer_spl_to_light`) -//! 6. Contributor has Light account with tokens - contribute using Light-to-Light - -mod common; -use common::{create_test_rpc, run_fundraiser_full_flow, setup_fundraiser_test, TokenConfig}; - -#[tokio::test] -async fn test_fundraiser_full_flow_light_spl() { - let mut rpc = create_test_rpc().await; - let ctx = setup_fundraiser_test(&mut rpc, TokenConfig::LightSpl).await; - run_fundraiser_full_flow(&mut rpc, &ctx).await; -} diff --git a/programs/anchor/fundraiser/tests/user_t22.rs b/programs/anchor/fundraiser/tests/user_t22.rs deleted file mode 100644 index 540680a..0000000 --- a/programs/anchor/fundraiser/tests/user_t22.rs +++ /dev/null @@ -1,46 +0,0 @@ -//! Integration tests for the fundraiser program with Token-2022 mints and T22 ATAs. -//! -//! Token Configuration: -//! - Mint Type: Token-2022 (spl_token_2022::ID) -//! - User Accounts: Token-2022 ATAs (contributors) -//! - Vault Account: Light Protocol token account - -mod common; - -use common::{create_test_rpc, run_fundraiser_full_flow, setup_fundraiser_test, TokenConfig}; - -/// Test the full fundraiser flow with Token-2022 tokens -#[tokio::test] -async fn test_fundraiser_full_flow_t22() { - let mut rpc = create_test_rpc().await; - let ctx = setup_fundraiser_test(&mut rpc, TokenConfig::Token2022).await; - run_fundraiser_full_flow(&mut rpc, &ctx).await; -} - -/// Test fundraiser initialization with Token-2022 tokens -#[tokio::test] -async fn test_initialize_fundraiser_t22() { - use common::{initialize_fundraiser, setup_fundraiser_test}; - use light_client::interface::{get_create_accounts_proof, CreateAccountsProofInput}; - use shared_test_utils::helpers::verify_light_token_balance; - - let mut rpc = create_test_rpc().await; - let ctx = setup_fundraiser_test(&mut rpc, TokenConfig::Token2022).await; - - // Get proof for creating vault - let proof_result = get_create_accounts_proof( - &rpc, - &ctx.program_id, - vec![CreateAccountsProofInput::pda(ctx.vault_pda)], - ) - .await - .unwrap(); - - // Initialize fundraiser - initialize_fundraiser(&mut rpc, &ctx, proof_result).await; - - // Verify vault was created - verify_light_token_balance(&mut rpc, ctx.vault_pda, 0, "vault").await; - - println!("=== Initialize fundraiser test completed successfully! ==="); -} diff --git a/programs/anchor/fundraiser/tests/user_t22_light.rs b/programs/anchor/fundraiser/tests/user_t22_light.rs deleted file mode 100644 index 03e378a..0000000 --- a/programs/anchor/fundraiser/tests/user_t22_light.rs +++ /dev/null @@ -1,24 +0,0 @@ -//! Integration tests for the fundraiser program with T22 mints and Light user accounts. -//! -//! Token Configuration: -//! - Mint Type: Token-2022 (spl_token_2022::ID) -//! - User Accounts: Light token accounts (contributors with offchain T22->Light conversion) -//! - Vault Account: Light Protocol token account -//! -//! ## Test Flow: -//! 1. Create T22 mint and temporary T22 ATA -//! 2. Mint tokens to temporary ATA -//! 3. Create Light token account for contributor -//! 4. Create SPL interface PDA -//! 5. Transfer from T22 ATA to Light account (offchain conversion using `transfer_spl_to_light`) -//! 6. Contributor has Light account with tokens - contribute using Light-to-Light - -mod common; -use common::{create_test_rpc, run_fundraiser_full_flow, setup_fundraiser_test, TokenConfig}; - -#[tokio::test] -async fn test_fundraiser_full_flow_light_t22() { - let mut rpc = create_test_rpc().await; - let ctx = setup_fundraiser_test(&mut rpc, TokenConfig::LightT22).await; - run_fundraiser_full_flow(&mut rpc, &ctx).await; -} diff --git a/programs/anchor/token-swap/tests/common/mod.rs b/programs/anchor/token-swap/tests/common/mod.rs index c08f7d9..c49c69d 100644 --- a/programs/anchor/token-swap/tests/common/mod.rs +++ b/programs/anchor/token-swap/tests/common/mod.rs @@ -1,33 +1,38 @@ -//! Common test utilities for token-swap AMM tests. +//! AMM test setup for 6 token standard combinations: SPL, T22, Light. //! -//! This module provides shared test helpers for different token type combinations: -//! - SPL mint + SPL ATAs -//! - T22 mint + T22 ATAs -//! - SPL mint + Light user accounts -//! - T22 mint + Light user accounts +//! Each combination varies the mint type and user account type while the pool +//! vaults are always Light token accounts: //! -//! Light mint + Light ATAs is not yet supported (requires Light mint creation). +//! - `Spl` / `Token2022`: standard associated token accounts, cross-standard transfers to Light vault +//! - `Light` / `FullLight`: native Light token accounts, direct transfers (lowest cost) +//! - `LightSpl` / `LightT22`: SPL/T22 mints converted into Light token accounts before +//! the AMM starts (tokens are minted to a temp associated token account, then +//! transferred to a Light associated token account via `transfer_spl_to_light`) +//! +//! `FullLight` additionally creates the LP mint as a Light mint via `create_pool_light_lp`, +//! making the entire pool rent-free. +//! +//! ## Setup flow +//! +//! 1. `create_test_rpc()` — start test validator with swap_example + minter programs +//! 2. `setup_amm_test(config)` — create mints, interface PDAs, depositor, derive PDAs +//! 3. `create_trader()` — create funded trader accounts per config // ============================================================================ // Imports // ============================================================================ -use anchor_lang::{InstructionData, ToAccountMetas}; use anchor_spl::token; -use light_client::interface::{get_create_accounts_proof, CreateAccountsProofInput}; use light_token::instruction::find_mint_address; use shared_test_utils::{ - helpers::verify_light_token_balance, light_tokens::{create_light_ata, create_light_mint, mint_light_tokens}, setup::initialize_rent_free_config, spl_interface::{create_spl_interface_pda, transfer_spl_to_light}, spl_tokens::{create_spl_ata, create_spl_mint, mint_spl_tokens}, t22_tokens::{create_t22_ata, create_t22_mint, mint_t22_tokens}, - CreateAccountsProofResult, Indexer, LightProgramTest, MintType, ProgramTestConfig, Rpc, - TestRpc, COMPRESSIBLE_CONFIG_V1, CPI_AUTHORITY_PDA, LIGHT_TOKEN_MINTER_PROGRAM_ID, - LIGHT_TOKEN_PROGRAM_ID, RENT_SPONSOR, + Indexer, LightProgramTest, MintType, ProgramTestConfig, Rpc, TestRpc, + LIGHT_TOKEN_MINTER_PROGRAM_ID, LIGHT_TOKEN_PROGRAM_ID, }; -use solana_instruction::Instruction; use solana_keypair::Keypair; use solana_pubkey::Pubkey; use solana_signer::Signer; @@ -37,37 +42,45 @@ use spl_token_2022::pod::PodAccount; // Token Configuration // ============================================================================ -/// Token configuration for parameterized tests. +/// Token configuration for parameterized AMM tests. /// -/// Some variants are used only in specific test files, so rustc warns about dead code. -/// The allow attribute suppresses these warnings across the shared test module. +/// Each variant determines the mint type and user account type. The pool vaults +/// are always Light token accounts (rent-free). The user account type controls +/// which CPI path `transfer_tokens()` selects at runtime: +/// +/// - SPL/T22 user accounts → `TransferInterfaceCpi` (cross-standard, needs interface PDA) +/// - Light user accounts → `TransferCheckedCpi` (direct, no interface PDA) #[allow(dead_code)] #[derive(Clone, Copy, Debug)] pub enum TokenConfig { - /// SPL mint + SPL ATAs + /// SPL mint + SPL ATAs. Transfers cross standards (SPL ↔ Light vault). Spl, - /// T22 mint + T22 ATAs + /// T22 mint + T22 ATAs. Transfers cross standards (T22 ↔ Light vault). Token2022, - /// SPL mint + Light user accounts (offchain SPL->Light conversion) + /// SPL mint + Light ATAs. Tokens converted from SPL ATAs in setup. + /// During AMM operations, all transfers are Light-to-Light. LightSpl, - /// T22 mint + Light user accounts (offchain T22->Light conversion) + /// T22 mint + Light ATAs. Tokens converted from T22 ATAs in setup. + /// During AMM operations, all transfers are Light-to-Light. LightT22, - /// Light mint + Light user accounts (pure Light-to-Light, SPL LP mint) + /// Light mint + Light ATAs + SPL LP mint. Pure Light — lowest cost, no bridging. Light, - /// Full Light: Light mints + Light user accounts + Light LP mint + /// Full Light: Light mints + Light ATAs + Light LP mint. Entire pool is rent-free. FullLight, } impl TokenConfig { + /// Returns the underlying mint program type. + /// Light mints use SPL-compatible layout, so this returns `MintType::Spl`. pub fn mint_type(&self) -> MintType { match self { TokenConfig::Spl | TokenConfig::LightSpl => MintType::Spl, TokenConfig::Token2022 | TokenConfig::LightT22 => MintType::Token2022, - // Light mints use SPL-compatible layout TokenConfig::Light | TokenConfig::FullLight => MintType::Spl, } } + /// Returns the token program ID passed as `token_program` in instructions. pub fn token_program_id(&self) -> Pubkey { match self { TokenConfig::Spl | TokenConfig::LightSpl => token::ID, @@ -78,7 +91,7 @@ impl TokenConfig { } } - /// Returns true if user accounts are Light token accounts + /// Returns true if user accounts are Light token accounts. pub fn uses_light_user_accounts(&self) -> bool { matches!( self, @@ -89,12 +102,12 @@ impl TokenConfig { ) } - /// Returns true if mints are Light Protocol mints (not SPL/T22) + /// Returns true if mints are Light Protocol mints (not SPL/T22). pub fn uses_light_mints(&self) -> bool { matches!(self, TokenConfig::Light | TokenConfig::FullLight) } - /// Returns true if LP mint is a Light Protocol mint + /// Returns true if LP mint is a Light Protocol mint. pub fn uses_light_lp_mint(&self) -> bool { matches!(self, TokenConfig::FullLight) } @@ -104,7 +117,7 @@ impl TokenConfig { // Test Context // ============================================================================ -/// Context for AMM tests containing all necessary accounts +/// Context for AMM tests containing all necessary accounts. pub struct AmmTestContext { pub program_id: Pubkey, pub payer: Keypair, @@ -127,12 +140,12 @@ pub struct AmmTestContext { pub depositor_ata_a: Pubkey, pub depositor_ata_b: Pubkey, pub token_config: TokenConfig, - /// Authority keypair for Light mint A (if Light config) + /// Authority keypair for Light mint A (if Light config). pub light_mint_authority_a: Option, - /// LP mint signer PDA (for FullLight config) + /// LP mint signer PDA (for FullLight config). pub lp_mint_signer: Option, pub lp_mint_signer_bump: u8, - /// Config PDA for rent-free light mint creation + /// Config PDA for rent-free light mint creation. pub compression_config: Pubkey, } @@ -140,7 +153,7 @@ pub struct AmmTestContext { // Setup Functions // ============================================================================ -/// Create a new LightProgramTest instance for token-swap tests +/// Create a new LightProgramTest instance for token-swap tests. pub async fn create_test_rpc() -> LightProgramTest { let program_id = swap_example::ID; let mut config = ProgramTestConfig::new_v2( @@ -154,7 +167,14 @@ pub async fn create_test_rpc() -> LightProgramTest { LightProgramTest::new(config).await.unwrap() } -/// Setup the AMM test environment based on token config +/// Initialize mints, interface PDAs, depositor, and derive PDAs for a given token config. +/// +/// SPL interface PDAs are created for all SPL/T22 configs (including `Spl` and +/// `Token2022`, not just `LightSpl`/`LightT22`) because the pool vaults are always +/// Light token accounts — any transfer involving an SPL/T22 account and the Light +/// vault crosses standards and requires an interface PDA. +/// +/// For `Light`/`FullLight` configs, no interface PDA is created (early return). pub async fn setup_amm_test( rpc: &mut R, config: TokenConfig, @@ -163,7 +183,8 @@ pub async fn setup_amm_test( let payer = rpc.get_payer().insecure_clone(); // Initialize rent-free config (returns config PDA + per-program rent sponsor PDA) - let (compression_config, _rent_sponsor) = initialize_rent_free_config(rpc, &payer, &program_id).await; + let (compression_config, _rent_sponsor) = + initialize_rent_free_config(rpc, &payer, &program_id).await; // Create depositor let depositor = Keypair::new(); @@ -174,13 +195,8 @@ pub async fn setup_amm_test( // Token amount for depositor let amount = 10_000_000_000_000u64; // 10,000 tokens with 9 decimals - // For Light mints, we need to handle things differently if config.uses_light_mints() { // ========== LIGHT MINT SETUP ========== - println!("\n=== Setting up Light mints ==="); - - // Step 1: Create Light mints with metadata - // Light mints are rent-free and include on-chain metadata let light_mint_a = create_light_mint(rpc, &payer, 9, "Token A", "TOKA", &compression_config).await; let light_mint_b = @@ -189,17 +205,11 @@ pub async fn setup_amm_test( let mint_a_pubkey = light_mint_a.mint; let mint_b_pubkey = light_mint_b.mint; - println!("Light Mint A: {:?}", mint_a_pubkey); - println!("Light Mint B: {:?}", mint_b_pubkey); - - // Step 2: Skip SPL interface PDAs for pure Light-to-Light - // These are only needed for wrapping SPL/T22 tokens + // No SPL interface PDAs for pure Light-to-Light let spl_interface_pda_a = Pubkey::default(); let spl_interface_pda_b = Pubkey::default(); - // Step 3: Mint Light tokens directly to depositor - // Creates Light ATA and mints in one operation - println!("\n=== Minting Light tokens to depositor ==="); + // Mint Light tokens directly to depositor (creates ATA + mints in one call) let depositor_ata_a = mint_light_tokens( rpc, &payer, @@ -219,11 +229,11 @@ pub async fn setup_amm_test( ) .await; - // Step 4: Derive AMM PDA + // Derive AMM PDA let amm_id = Pubkey::new_unique(); let (amm_pda, _) = Pubkey::find_program_address(&[amm_id.as_ref()], &program_id); - // Step 5: Derive pool PDAs using Light mint pubkeys + // Derive pool PDAs let (pool_pda, _) = Pubkey::find_program_address( &[ amm_pda.as_ref(), @@ -241,28 +251,29 @@ pub async fn setup_amm_test( let (pool_account_b, pool_b_bump) = Pubkey::find_program_address(&[b"pool_b", pool_pda.as_ref()], &program_id); - // Step 6: Derive LP mint address - // Light config: SPL LP mint derived normally - // FullLight config: Light LP mint derived from lp_mint_signer PDA - let (mint_liquidity, lp_mint_signer, lp_mint_signer_bump) = if config.uses_light_lp_mint() { - // FullLight: derive LP mint signer and Light LP mint - let (lp_mint_signer, lp_mint_signer_bump) = - Pubkey::find_program_address(&[b"lp_mint_signer", pool_pda.as_ref()], &program_id); - let (light_lp_mint, _) = find_mint_address(&lp_mint_signer); - (light_lp_mint, Some(lp_mint_signer), lp_mint_signer_bump) - } else { - // Light (non-FullLight): SPL LP mint - let (mint_liquidity, _) = Pubkey::find_program_address( - &[ - amm_pda.as_ref(), - mint_a_pubkey.as_ref(), - mint_b_pubkey.as_ref(), - b"liquidity", - ], - &program_id, - ); - (mint_liquidity, None, 0) - }; + // Derive LP mint address: + // Light config → SPL LP mint derived normally + // FullLight config → Light LP mint derived from lp_mint_signer PDA + let (mint_liquidity, lp_mint_signer, lp_mint_signer_bump) = + if config.uses_light_lp_mint() { + let (lp_mint_signer, lp_mint_signer_bump) = Pubkey::find_program_address( + &[b"lp_mint_signer", pool_pda.as_ref()], + &program_id, + ); + let (light_lp_mint, _) = find_mint_address(&lp_mint_signer); + (light_lp_mint, Some(lp_mint_signer), lp_mint_signer_bump) + } else { + let (mint_liquidity, _) = Pubkey::find_program_address( + &[ + amm_pda.as_ref(), + mint_a_pubkey.as_ref(), + mint_b_pubkey.as_ref(), + b"liquidity", + ], + &program_id, + ); + (mint_liquidity, None, 0) + }; return AmmTestContext { program_id, @@ -294,7 +305,6 @@ pub async fn setup_amm_test( } // ========== SPL/T22 MINT SETUP ========== - // Create mints based on config (SPL or T22 - Light user accounts still use SPL/T22 mints) let (mint_a, mint_b) = match config { TokenConfig::Spl | TokenConfig::LightSpl => { let mint_a = create_spl_mint(rpc, &payer, &payer.pubkey(), 9).await; @@ -314,11 +324,7 @@ pub async fn setup_amm_test( let mint_a_pubkey = mint_a.pubkey(); let mint_b_pubkey = mint_b.pubkey(); - println!("Mint A: {:?}", mint_a_pubkey); - println!("Mint B: {:?}", mint_b_pubkey); - - // Create SPL interface PDAs for both mints - println!("\n=== Creating SPL interface PDAs ==="); + // Create SPL interface PDAs for both mints (needed for cross-standard transfers) let spl_interface_result_a = create_spl_interface_pda(rpc, &payer, &mint_a_pubkey, config.mint_type(), false).await; let spl_interface_result_b = @@ -341,25 +347,19 @@ pub async fn setup_amm_test( (ata_a, ata_b) } TokenConfig::LightSpl => { - // For Light user accounts with SPL mint: - // 1. Create temporary SPL ATAs - // 2. Mint tokens to temp ATAs - // 3. Create Light ATAs - // 4. Transfer from SPL to Light (compress) - println!("\n=== Setting up Light user accounts (SPL mint) ==="); - - let temp_ata_a = create_spl_ata(rpc, &payer, &mint_a_pubkey, &depositor.pubkey()).await; - let temp_ata_b = create_spl_ata(rpc, &payer, &mint_b_pubkey, &depositor.pubkey()).await; + // Create temp SPL ATAs → mint → create Light ATAs → transfer (compress) + let temp_ata_a = + create_spl_ata(rpc, &payer, &mint_a_pubkey, &depositor.pubkey()).await; + let temp_ata_b = + create_spl_ata(rpc, &payer, &mint_b_pubkey, &depositor.pubkey()).await; mint_spl_tokens(rpc, &payer, &mint_a_pubkey, &temp_ata_a, &payer, amount).await; mint_spl_tokens(rpc, &payer, &mint_b_pubkey, &temp_ata_b, &payer, amount).await; - // Create Light ATAs let light_ata_a = create_light_ata(rpc, &payer, &mint_a_pubkey, &depositor.pubkey()).await; let light_ata_b = create_light_ata(rpc, &payer, &mint_b_pubkey, &depositor.pubkey()).await; - // Transfer from SPL to Light (compress) transfer_spl_to_light( rpc, &payer, @@ -392,21 +392,19 @@ pub async fn setup_amm_test( (light_ata_a, light_ata_b) } TokenConfig::LightT22 => { - // For Light user accounts with T22 mint: - println!("\n=== Setting up Light user accounts (T22 mint) ==="); - - let temp_ata_a = create_t22_ata(rpc, &payer, &mint_a_pubkey, &depositor.pubkey()).await; - let temp_ata_b = create_t22_ata(rpc, &payer, &mint_b_pubkey, &depositor.pubkey()).await; + // Create temp T22 ATAs → mint → create Light ATAs → transfer (compress) + let temp_ata_a = + create_t22_ata(rpc, &payer, &mint_a_pubkey, &depositor.pubkey()).await; + let temp_ata_b = + create_t22_ata(rpc, &payer, &mint_b_pubkey, &depositor.pubkey()).await; mint_t22_tokens(rpc, &payer, &mint_a_pubkey, &temp_ata_a, &payer, amount).await; mint_t22_tokens(rpc, &payer, &mint_b_pubkey, &temp_ata_b, &payer, amount).await; - // Create Light ATAs let light_ata_a = create_light_ata(rpc, &payer, &mint_a_pubkey, &depositor.pubkey()).await; let light_ata_b = create_light_ata(rpc, &payer, &mint_b_pubkey, &depositor.pubkey()).await; - // Transfer from T22 to Light (compress) transfer_spl_to_light( rpc, &payer, @@ -505,406 +503,16 @@ pub async fn setup_amm_test( } // ============================================================================ -// Instruction Execution +// Account Creation // ============================================================================ -/// Create AMM with specified fee structure. -/// -/// The AMM (Automated Market Maker) is the parent entity that defines -/// fee parameters for all pools created under it. -pub async fn create_amm(rpc: &mut R, ctx: &AmmTestContext, fee: u16) { - println!("\n=== Creating AMM ==="); - - // Step 1: Build create_amm instruction - let create_amm_accounts = swap_example::accounts::CreateAmm { - amm: ctx.amm_pda, - admin: ctx.payer.pubkey(), - payer: ctx.payer.pubkey(), - system_program: solana_sdk::system_program::ID, - }; - - let create_amm_data = swap_example::instruction::CreateAmm { - id: ctx.amm_id, - fee, - }; - - let create_amm_ix = Instruction { - program_id: ctx.program_id, - accounts: create_amm_accounts.to_account_metas(None), - data: create_amm_data.data(), - }; - - rpc.create_and_send_transaction(&[create_amm_ix], &ctx.payer.pubkey(), &[&ctx.payer]) - .await - .expect("create_amm should succeed"); - - println!("AMM created at: {:?}", ctx.amm_pda); - println!("AMM Fee: {} basis points", fee); -} - -/// Create Pool with Light token accounts. -/// -/// Creates a liquidity pool for token pair A/B under the AMM. -/// Pool vaults (pool_account_a, pool_account_b) are Light token accounts. -pub async fn create_pool( - rpc: &mut R, - ctx: &AmmTestContext, - proof_result: CreateAccountsProofResult, -) { - println!("\n=== Creating Pool ==="); - - // Step 1: Determine LP mint token program - // For liquidity mint, use SPL for Light pools (can't init Light mints via Anchor) - // For SPL/T22 pools, use the same token program as the mints - // FullLight uses create_pool_light_lp instruction instead - let liquidity_token_program = match ctx.token_config { - TokenConfig::Light | TokenConfig::LightSpl => token::ID, - TokenConfig::Token2022 | TokenConfig::LightT22 => spl_token_2022::ID, - TokenConfig::Spl => token::ID, - TokenConfig::FullLight => Pubkey::new_from_array(LIGHT_TOKEN_PROGRAM_ID), - }; - - let create_pool_accounts = swap_example::accounts::CreatePool { - amm: ctx.amm_pda, - pool: ctx.pool_pda, - pool_authority: ctx.pool_authority, - mint_liquidity: ctx.mint_liquidity, - mint_a: ctx.mint_a_pubkey, - mint_b: ctx.mint_b_pubkey, - pool_account_a: ctx.pool_account_a, - pool_account_b: ctx.pool_account_b, - fee_payer: ctx.payer.pubkey(), - token_program: ctx.token_config.token_program_id(), - liquidity_token_program, - light_token_program: Pubkey::new_from_array(LIGHT_TOKEN_PROGRAM_ID), - system_program: solana_sdk::system_program::ID, - light_token_config: COMPRESSIBLE_CONFIG_V1, - light_token_rent_sponsor: RENT_SPONSOR, - light_token_cpi_authority: CPI_AUTHORITY_PDA, - }; - - let create_pool_data = swap_example::instruction::CreatePool { - params: swap_example::CreatePoolParams { - create_accounts_proof: proof_result.create_accounts_proof, - pool_account_a_bump: ctx.pool_a_bump, - pool_account_b_bump: ctx.pool_b_bump, - }, - }; - - let create_pool_ix = Instruction { - program_id: ctx.program_id, - accounts: [ - create_pool_accounts.to_account_metas(None), - proof_result.remaining_accounts, - ] - .concat(), - data: create_pool_data.data(), - }; - - rpc.create_and_send_transaction(&[create_pool_ix], &ctx.payer.pubkey(), &[&ctx.payer]) - .await - .expect("create_pool should succeed"); - - println!("Pool created successfully!"); -} - -/// Create Pool with Light LP mint (for FullLight config). -/// -/// Similar to create_pool but creates the LP mint as a Light mint -/// instead of SPL/T22 mint, enabling fully rent-free pool operations. -pub async fn create_pool_light_lp( - rpc: &mut R, - ctx: &AmmTestContext, - proof_result: CreateAccountsProofResult, -) { - println!("\n=== Creating Pool with Light LP mint ==="); - - // Step 1: Get LP mint signer PDA (used to derive Light LP mint address) - let lp_mint_signer = ctx - .lp_mint_signer - .expect("FullLight config should have lp_mint_signer"); - - let create_pool_accounts = swap_example::accounts::CreatePoolLightLp { - amm: ctx.amm_pda, - pool: ctx.pool_pda, - pool_authority: ctx.pool_authority, - lp_mint_signer, - mint_liquidity: ctx.mint_liquidity, - mint_a: ctx.mint_a_pubkey, - mint_b: ctx.mint_b_pubkey, - pool_vault_a: ctx.pool_account_a, - pool_vault_b: ctx.pool_account_b, - fee_payer: ctx.payer.pubkey(), - token_program: ctx.token_config.token_program_id(), - compression_config: ctx.compression_config, - light_token_config: COMPRESSIBLE_CONFIG_V1, - light_token_rent_sponsor: RENT_SPONSOR, - light_token_program: Pubkey::new_from_array(LIGHT_TOKEN_PROGRAM_ID), - light_token_cpi_authority: CPI_AUTHORITY_PDA, - system_program: solana_sdk::system_program::ID, - }; - - let create_pool_data = swap_example::instruction::CreatePoolLightLp { - params: swap_example::CreatePoolLightLpParams { - create_accounts_proof: proof_result.create_accounts_proof, - pool_account_a_bump: ctx.pool_a_bump, - pool_account_b_bump: ctx.pool_b_bump, - lp_mint_signer_bump: ctx.lp_mint_signer_bump, - pool_authority_bump: ctx.pool_authority_bump, - }, - }; - - let create_pool_ix = Instruction { - program_id: ctx.program_id, - accounts: [ - create_pool_accounts.to_account_metas(None), - proof_result.remaining_accounts, - ] - .concat(), - data: create_pool_data.data(), - }; - - rpc.create_and_send_transaction(&[create_pool_ix], &ctx.payer.pubkey(), &[&ctx.payer]) - .await - .expect("create_pool_light_lp should succeed"); - - println!("Pool with Light LP mint created successfully!"); -} - -/// Deposit liquidity to pool. -/// -/// Transfers token A and B from depositor to pool vaults. -/// Mints LP tokens to depositor proportional to deposit amount. -pub async fn deposit_liquidity( - rpc: &mut R, - ctx: &AmmTestContext, - amount_a: u64, - amount_b: u64, -) -> Pubkey { - println!("\n=== Depositing Liquidity ==="); - - // Step 1: Determine token programs for underlying and LP tokens - let token_program = ctx.token_config.token_program_id(); - - // Liquidity mint is SPL for Light/LightSpl pools, T22 for T22/LightT22 pools, SPL for Spl pools - // FullLight uses Light token program for LP mint - let liquidity_token_program = match ctx.token_config { - TokenConfig::Light | TokenConfig::LightSpl | TokenConfig::Spl => token::ID, - TokenConfig::Token2022 | TokenConfig::LightT22 => spl_token_2022::ID, - TokenConfig::FullLight => Pubkey::new_from_array(LIGHT_TOKEN_PROGRAM_ID), - }; - - // Create the liquidity ATA first (since program no longer does init_if_needed) - // For FullLight, LP mint is a Light mint created via create_pool_light_lp - let depositor_liquidity_ata = match ctx.token_config { - TokenConfig::Spl | TokenConfig::LightSpl | TokenConfig::Light => { - // SPL liquidity mint - create_spl_ata( - rpc, - &ctx.payer, - &ctx.mint_liquidity, - &ctx.depositor.pubkey(), - ) - .await - } - TokenConfig::Token2022 | TokenConfig::LightT22 => { - // T22 liquidity mint - create_t22_ata( - rpc, - &ctx.payer, - &ctx.mint_liquidity, - &ctx.depositor.pubkey(), - ) - .await - } - TokenConfig::FullLight => { - // Light LP mint - create Light ATA - create_light_ata( - rpc, - &ctx.payer, - &ctx.mint_liquidity, - &ctx.depositor.pubkey(), - ) - .await - } - }; - - let deposit_accounts = swap_example::accounts::DepositLiquidity { - pool: ctx.pool_pda, - pool_authority: ctx.pool_authority, - depositor: ctx.depositor.pubkey(), - mint_liquidity: ctx.mint_liquidity, - mint_a: ctx.mint_a_pubkey, - mint_b: ctx.mint_b_pubkey, - pool_account_a: ctx.pool_account_a, - pool_account_b: ctx.pool_account_b, - depositor_account_liquidity: depositor_liquidity_ata, - depositor_account_a: ctx.depositor_ata_a, - depositor_account_b: ctx.depositor_ata_b, - payer: ctx.payer.pubkey(), - token_program, - liquidity_token_program, - system_program: solana_sdk::system_program::ID, - light_token_program: Pubkey::new_from_array(LIGHT_TOKEN_PROGRAM_ID), - light_token_rent_sponsor: RENT_SPONSOR, - light_token_cpi_authority: CPI_AUTHORITY_PDA, - spl_interface_pda_a: ctx.spl_interface_pda_a, - spl_interface_pda_b: ctx.spl_interface_pda_b, - }; - - let deposit_data = swap_example::instruction::DepositLiquidity { amount_a, amount_b }; - - let deposit_ix = Instruction { - program_id: ctx.program_id, - accounts: deposit_accounts.to_account_metas(None), - data: deposit_data.data(), - }; - - rpc.create_and_send_transaction( - &[deposit_ix], - &ctx.payer.pubkey(), - &[&ctx.payer, &ctx.depositor], - ) - .await - .expect("deposit_liquidity should succeed"); - - println!("Deposited {} token A and {} token B", amount_a, amount_b); - - depositor_liquidity_ata -} - -/// Perform swap A->B or B->A. +/// Create a trader with funded token accounts. /// -/// Swaps input tokens for output tokens using constant-product formula. -/// Fee is deducted from output amount based on AMM fee setting. -pub async fn swap( - rpc: &mut R, - ctx: &AmmTestContext, - trader: &Keypair, - trader_ata_a: Pubkey, - trader_ata_b: Pubkey, - swap_a: bool, - input_amount: u64, - min_output: u64, -) { - // Step 1: Determine swap direction - let direction = if swap_a { "A->B" } else { "B->A" }; - println!("\n=== Swapping {} ===", direction); - - // Step 2: Build swap instruction - let token_program = ctx.token_config.token_program_id(); - - let swap_accounts = swap_example::accounts::SwapExactTokensForTokens { - amm: ctx.amm_pda, - pool: ctx.pool_pda, - pool_authority: ctx.pool_authority, - trader: trader.pubkey(), - mint_a: ctx.mint_a_pubkey, - mint_b: ctx.mint_b_pubkey, - pool_account_a: ctx.pool_account_a, - pool_account_b: ctx.pool_account_b, - trader_account_a: trader_ata_a, - trader_account_b: trader_ata_b, - payer: ctx.payer.pubkey(), - token_program, - system_program: solana_sdk::system_program::ID, - light_token_program: Pubkey::new_from_array(LIGHT_TOKEN_PROGRAM_ID), - light_token_rent_sponsor: RENT_SPONSOR, - light_token_cpi_authority: CPI_AUTHORITY_PDA, - spl_interface_pda_a: ctx.spl_interface_pda_a, - spl_interface_pda_b: ctx.spl_interface_pda_b, - }; - - let swap_data = swap_example::instruction::SwapExactTokensForTokens { - swap_a, - input_amount, - min_output_amount: min_output, - }; - - let swap_ix = Instruction { - program_id: ctx.program_id, - accounts: swap_accounts.to_account_metas(None), - data: swap_data.data(), - }; - - rpc.create_and_send_transaction(&[swap_ix], &ctx.payer.pubkey(), &[&ctx.payer, trader]) - .await - .expect(&format!("swap {} should succeed", direction)); - - println!("Swapped {} of input token", input_amount); -} - -/// Withdraw liquidity from pool. -/// -/// Burns LP tokens from depositor and returns proportional share -/// of token A and B from pool vaults. -pub async fn withdraw_liquidity( - rpc: &mut R, - ctx: &AmmTestContext, - depositor_liquidity_ata: Pubkey, - amount: u64, -) { - println!("\n=== Withdrawing Liquidity ==="); - - // Step 1: Determine token programs for underlying and LP tokens - let token_program = ctx.token_config.token_program_id(); - - // Liquidity mint is SPL for Light/LightSpl pools, T22 for T22/LightT22 pools, SPL for Spl pools - // FullLight uses Light token program for LP mint - let liquidity_token_program = match ctx.token_config { - TokenConfig::Light | TokenConfig::LightSpl | TokenConfig::Spl => token::ID, - TokenConfig::Token2022 | TokenConfig::LightT22 => spl_token_2022::ID, - TokenConfig::FullLight => Pubkey::new_from_array(LIGHT_TOKEN_PROGRAM_ID), - }; - - let withdraw_accounts = swap_example::accounts::WithdrawLiquidity { - amm: ctx.amm_pda, - pool: ctx.pool_pda, - pool_authority: ctx.pool_authority, - depositor: ctx.depositor.pubkey(), - mint_liquidity: ctx.mint_liquidity, - mint_a: ctx.mint_a_pubkey, - mint_b: ctx.mint_b_pubkey, - pool_account_a: ctx.pool_account_a, - pool_account_b: ctx.pool_account_b, - depositor_account_liquidity: depositor_liquidity_ata, - depositor_account_a: ctx.depositor_ata_a, - depositor_account_b: ctx.depositor_ata_b, - payer: ctx.payer.pubkey(), - token_program, - liquidity_token_program, - system_program: solana_sdk::system_program::ID, - light_token_program: Pubkey::new_from_array(LIGHT_TOKEN_PROGRAM_ID), - light_token_rent_sponsor: RENT_SPONSOR, - light_token_cpi_authority: CPI_AUTHORITY_PDA, - spl_interface_pda_a: ctx.spl_interface_pda_a, - spl_interface_pda_b: ctx.spl_interface_pda_b, - }; - - let withdraw_data = swap_example::instruction::WithdrawLiquidity { amount }; - - let withdraw_ix = Instruction { - program_id: ctx.program_id, - accounts: withdraw_accounts.to_account_metas(None), - data: withdraw_data.data(), - }; - - rpc.create_and_send_transaction( - &[withdraw_ix], - &ctx.payer.pubkey(), - &[&ctx.payer, &ctx.depositor], - ) - .await - .expect("withdraw_liquidity should succeed"); - - println!("Withdrew {} LP tokens", amount); -} - -// ============================================================================ -// Helper Functions -// ============================================================================ - -/// Create a trader with token accounts and funded tokens +/// Account creation varies by config: +/// - `Spl` / `Token2022`: create standard ATAs, mint directly +/// - `Light` / `FullLight`: create Light ATAs via `mint_light_tokens` (creates + mints in one call) +/// - `LightSpl` / `LightT22`: create temp SPL/T22 ATAs → mint → +/// create Light ATAs → convert via `transfer_spl_to_light` pub async fn create_trader( rpc: &mut R, ctx: &AmmTestContext, @@ -917,9 +525,10 @@ pub async fn create_trader( let (trader_ata_a, trader_ata_b) = match ctx.token_config { TokenConfig::Spl => { - let ata_a = create_spl_ata(rpc, &ctx.payer, &ctx.mint_a_pubkey, &trader.pubkey()).await; - let ata_b = create_spl_ata(rpc, &ctx.payer, &ctx.mint_b_pubkey, &trader.pubkey()).await; - // Mint initial token A to trader + let ata_a = + create_spl_ata(rpc, &ctx.payer, &ctx.mint_a_pubkey, &trader.pubkey()).await; + let ata_b = + create_spl_ata(rpc, &ctx.payer, &ctx.mint_b_pubkey, &trader.pubkey()).await; mint_spl_tokens( rpc, &ctx.payer, @@ -932,9 +541,10 @@ pub async fn create_trader( (ata_a, ata_b) } TokenConfig::Token2022 => { - let ata_a = create_t22_ata(rpc, &ctx.payer, &ctx.mint_a_pubkey, &trader.pubkey()).await; - let ata_b = create_t22_ata(rpc, &ctx.payer, &ctx.mint_b_pubkey, &trader.pubkey()).await; - // Mint initial token A to trader + let ata_a = + create_t22_ata(rpc, &ctx.payer, &ctx.mint_a_pubkey, &trader.pubkey()).await; + let ata_b = + create_t22_ata(rpc, &ctx.payer, &ctx.mint_b_pubkey, &trader.pubkey()).await; mint_t22_tokens( rpc, &ctx.payer, @@ -947,14 +557,12 @@ pub async fn create_trader( (ata_a, ata_b) } TokenConfig::LightSpl => { - // For Light user accounts with SPL mint: - // 1. Create temp SPL ATAs, mint, then transfer to Light ATAs + // Create temp SPL ATAs, mint, then transfer to Light ATAs let temp_ata_a = create_spl_ata(rpc, &ctx.payer, &ctx.mint_a_pubkey, &trader.pubkey()).await; let _temp_ata_b = create_spl_ata(rpc, &ctx.payer, &ctx.mint_b_pubkey, &trader.pubkey()).await; - // Mint initial token A to trader temp ATA mint_spl_tokens( rpc, &ctx.payer, @@ -965,13 +573,11 @@ pub async fn create_trader( ) .await; - // Create Light ATAs let light_ata_a = create_light_ata(rpc, &ctx.payer, &ctx.mint_a_pubkey, &trader.pubkey()).await; let light_ata_b = create_light_ata(rpc, &ctx.payer, &ctx.mint_b_pubkey, &trader.pubkey()).await; - // Transfer from SPL to Light (compress) transfer_spl_to_light( rpc, &ctx.payer, @@ -990,13 +596,12 @@ pub async fn create_trader( (light_ata_a, light_ata_b) } TokenConfig::LightT22 => { - // For Light user accounts with T22 mint: + // Create temp T22 ATAs, mint, then transfer to Light ATAs let temp_ata_a = create_t22_ata(rpc, &ctx.payer, &ctx.mint_a_pubkey, &trader.pubkey()).await; let _temp_ata_b = create_t22_ata(rpc, &ctx.payer, &ctx.mint_b_pubkey, &trader.pubkey()).await; - // Mint initial token A to trader temp ATA mint_t22_tokens( rpc, &ctx.payer, @@ -1007,13 +612,11 @@ pub async fn create_trader( ) .await; - // Create Light ATAs let light_ata_a = create_light_ata(rpc, &ctx.payer, &ctx.mint_a_pubkey, &trader.pubkey()).await; let light_ata_b = create_light_ata(rpc, &ctx.payer, &ctx.mint_b_pubkey, &trader.pubkey()).await; - // Transfer from T22 to Light (compress) transfer_spl_to_light( rpc, &ctx.payer, @@ -1032,14 +635,12 @@ pub async fn create_trader( (light_ata_a, light_ata_b) } TokenConfig::Light | TokenConfig::FullLight => { - // For pure Light mints (Light and FullLight): - // Mint directly to trader's Light ATAs using the Light mint authority + // Mint directly to trader's Light ATAs using the mint authority let mint_authority_a = ctx .light_mint_authority_a .as_ref() .expect("Light/FullLight config should have mint authority A"); - // Mint token A to trader let light_ata_a = mint_light_tokens( rpc, &ctx.payer, @@ -1061,7 +662,11 @@ pub async fn create_trader( (trader, trader_ata_a, trader_ata_b) } -/// Get token balance from SPL/T22 account +// ============================================================================ +// Helpers +// ============================================================================ + +/// Get token balance from an on-chain token account (SPL/T22/Light when hot). pub async fn get_token_balance(rpc: &mut R, account: Pubkey) -> u64 { let account_data = rpc .get_account(account) @@ -1073,137 +678,3 @@ pub async fn get_token_balance(rpc: &mut R, account: Pubkey) -> u64 { spl_pod::bytemuck::pod_from_bytes::(&account_data.data[..165]).unwrap(); u64::from(token_state.amount) } - -// ============================================================================ -// Full Flow Tests -// ============================================================================ - -/// Run the full AMM flow test -pub async fn run_amm_full_flow(rpc: &mut R, ctx: &AmmTestContext) { - // ==================== PHASE 1: Create AMM ==================== - // AMM defines fee structure for all pools - create_amm(rpc, ctx, 250).await; // 2.5% fee - - // ==================== PHASE 2: Create Pool ==================== - // Pool holds liquidity for token pair A/B - // Get proof inputs - order must match #[light_account(init, ...)] order in instruction struct - // For FullLight: only mint_liquidity (token accounts created via explicit CPI) - // For others: pool_account_a, pool_account_b (created via macro) - let proof_inputs = if ctx.token_config.uses_light_lp_mint() { - let lp_mint_signer = ctx - .lp_mint_signer - .expect("FullLight config should have lp_mint_signer"); - vec![ - CreateAccountsProofInput::mint(lp_mint_signer), // mint_liquidity only - ] - } else { - vec![ - CreateAccountsProofInput::pda(ctx.pool_account_a), - CreateAccountsProofInput::pda(ctx.pool_account_b), - ] - }; - - let proof_result = get_create_accounts_proof(rpc, &ctx.program_id, proof_inputs) - .await - .unwrap(); - - // Create Pool - use create_pool_light_lp for FullLight config - if ctx.token_config.uses_light_lp_mint() { - create_pool_light_lp(rpc, ctx, proof_result).await; - } else { - create_pool(rpc, ctx, proof_result).await; - } - - // Fund pool_authority for Light-to-Light transfers (rent top-ups) - // The pool_authority needs lamports to pay for rent top-ups when transferring - // from pool accounts to user accounts during swap/withdraw operations - if ctx.token_config.uses_light_user_accounts() { - rpc.airdrop_lamports(&ctx.pool_authority, 1_000_000_000) - .await - .expect("Fund pool_authority for rent top-ups"); - println!("Funded pool_authority with 1 SOL for rent top-ups"); - } - - // Verify initial pool balances - verify_light_token_balance(rpc, ctx.pool_account_a, 0, "pool_account_a (initial)").await; - verify_light_token_balance(rpc, ctx.pool_account_b, 0, "pool_account_b (initial)").await; - - // ==================== PHASE 3: Initial Liquidity Deposit ==================== - // Depositor provides equal amounts of token A and B, receives LP tokens - let deposit_amount = 1_000_000_000u64; // 1 token - let depositor_liquidity_ata = deposit_liquidity(rpc, ctx, deposit_amount, deposit_amount).await; - - // Verify pool balances after deposit - verify_light_token_balance( - rpc, - ctx.pool_account_a, - deposit_amount, - "pool_account_a (after deposit)", - ) - .await; - verify_light_token_balance( - rpc, - ctx.pool_account_b, - deposit_amount, - "pool_account_b (after deposit)", - ) - .await; - - // ==================== PHASE 4: Create Trader ==================== - // Trader gets funded accounts for swapping - let trader_initial_a = 100_000_000u64; // 0.1 tokens - let (trader, trader_ata_a, trader_ata_b) = create_trader(rpc, ctx, trader_initial_a).await; - - // ==================== PHASE 5: Execute Swaps ==================== - // Trader swaps A→B, then B→A - - // Swap A -> B - let swap_input = 10_000_000u64; // 0.01 tokens - swap( - rpc, - ctx, - &trader, - trader_ata_a, - trader_ata_b, - true, - swap_input, - 1, - ) - .await; - - // Verify trader got some token B - let trader_b_balance = get_token_balance(rpc, trader_ata_b).await; - assert!(trader_b_balance > 0, "Trader should have received token B"); - println!("Trader token B after swap: {}", trader_b_balance); - - // Swap B -> A (swap half back) - let swap_b_input = trader_b_balance / 2; - swap( - rpc, - ctx, - &trader, - trader_ata_a, - trader_ata_b, - false, - swap_b_input, - 1, - ) - .await; - - // ==================== PHASE 6: Withdraw Liquidity ==================== - // Depositor redeems LP tokens for underlying token A and B - let lp_balance = get_token_balance(rpc, depositor_liquidity_ata).await; - let withdraw_amount = lp_balance / 2; - withdraw_liquidity(rpc, ctx, depositor_liquidity_ata, withdraw_amount).await; - - // ==================== PHASE 7: Verify Final State ==================== - // LP tokens were burned - let lp_balance_after = get_token_balance(rpc, depositor_liquidity_ata).await; - assert_eq!( - lp_balance_after, - lp_balance - withdraw_amount, - "LP tokens should be burned" - ); - - println!("\n=== AMM full flow test completed successfully! ==="); -} diff --git a/programs/anchor/token-swap/tests/swap.rs b/programs/anchor/token-swap/tests/swap.rs new file mode 100644 index 0000000..a0f9ea1 --- /dev/null +++ b/programs/anchor/token-swap/tests/swap.rs @@ -0,0 +1,612 @@ +//! Light Token AMM: automated market maker with rent-free pool vaults. +//! +//! This test shows constant-product AMM patterns adapted for Light Token. +//! +//! 1. **Authority PDA owns the pool vaults** — not the pool account. This lets +//! the authority sign vault operations (deposit, swap, withdraw) without +//! needing account data (see `create_pool.rs` +//! `#[light_account(init, token::owner = pool_authority)]`). +//! +//! 2. **Pool vaults are rent-free** — they're Light token accounts sponsored by +//! `RENT_SPONSOR`, eliminating ~0.002 SOL rent per pool vault. +//! +//! 3. **Validity proof for pool creation** — `get_create_accounts_proof()` +//! fetches a validity proof that the vault PDAs' derived addresses do not +//! yet exist in Light's address tree. Only needed in `create_pool` / +//! `create_pool_light_lp` (creating new state); deposit, swap, and withdraw +//! read existing accounts and need no proof. +//! +//! ## Token scenarios +//! +//! The pool vaults are always Light Token accounts. The user's account type +//! determines which CPI path `transfer_tokens()` in `shared.rs` selects: +//! +//! | Test | Mint | User accounts | LP mint | Transfer path | Purpose | +//! |------|------|---------------|---------|---------------|---------| +//! | `test_swap_spl` | SPL | SPL ATAs | SPL | `TransferInterfaceCpi` | SPL mints work with Light vault | +//! | `test_swap_t22` | T22 | T22 ATAs | T22 | `TransferInterfaceCpi` | T22 mints work with Light vault | +//! | `test_swap_light` | Light | Light ATAs | SPL | `TransferCheckedCpi` | Light mints, SPL LP mint | +//! | `test_swap_spl_light` | SPL | Light ATAs | SPL | `TransferCheckedCpi` | SPL mint, converted user accounts | +//! | `test_swap_t22_light` | T22 | Light ATAs | T22 | `TransferCheckedCpi` | T22 mint, converted user accounts | +//! | `test_swap_full_light` | Light | Light ATAs | Light | `TransferCheckedCpi` | Fully rent-free (Light LP mint) | +//! +//! For `Spl`/`Token2022`: user accounts are SPL/T22, vaults are Light → cross-standard +//! (`TransferInterfaceCpi` with SPL interface PDA). +//! +//! For `Light`/`FullLight`/`LightSpl`/`LightT22`: all accounts are Light → direct +//! (`TransferCheckedCpi`, no interface PDA needed). +//! +//! `LightSpl`/`LightT22` convert tokens from SPL/T22 associated token accounts +//! into Light token accounts *before* the AMM interactions start (in +//! `create_trader` / setup). The AMM itself only sees Light token accounts. +//! +//! ## Pool creation modes +//! +//! `FullLight` uses `create_pool_light_lp` which creates pool vaults via +//! explicit `CreateTokenAccountCpi` and the LP mint as a Light mint. +//! All other configs use `create_pool` with macro-initialized vaults and +//! an SPL/T22 LP mint. +//! +//! ## Cold/hot lifecycle +//! +//! `Pool` and `Amm` use standard `#[account]` (no `LightAccount` derive), so +//! `#[light_program]` does not generate `VaultSeeds` / `LightAccountVariant` +//! needed by `create_load_instructions`. The test does not exercise cold/hot +//! lifecycle. See the escrow tests for full cold/hot coverage. + +mod common; + +use anchor_lang::{InstructionData, ToAccountMetas}; +use anchor_spl::token; +use common::{ + create_test_rpc, create_trader, get_token_balance, setup_amm_test, AmmTestContext, TokenConfig, +}; +use light_client::interface::{get_create_accounts_proof, CreateAccountsProofInput}; +use shared_test_utils::{ + helpers::verify_light_token_balance, + light_tokens::create_light_ata, + spl_tokens::create_spl_ata, + t22_tokens::create_t22_ata, + Indexer, Rpc, TestRpc, COMPRESSIBLE_CONFIG_V1, CPI_AUTHORITY_PDA, LIGHT_TOKEN_PROGRAM_ID, + RENT_SPONSOR, +}; +use solana_instruction::Instruction; +use solana_pubkey::Pubkey; +use solana_signer::Signer; + +// ============================================================================ +// Tests — one per token configuration, plus a standalone AMM creation test. +// ============================================================================ + +/// SPL mint with SPL ATAs, SPL LP mint, and Light pool vaults. +/// +/// Every transfer crosses standards (SPL ↔ Light) via `TransferInterfaceCpi` +/// with SPL interface PDAs. This is the baseline: same mint type as standard +/// SPL AMM, but pool vaults are rent-free Light token accounts. +#[tokio::test] +async fn test_swap_spl() { + let mut rpc = create_test_rpc().await; + let ctx = setup_amm_test(&mut rpc, TokenConfig::Spl).await; + run_amm_full_flow(&mut rpc, &ctx).await; +} + +/// Token-2022 mint with T22 ATAs, T22 LP mint, and Light pool vaults. +/// +/// Every transfer crosses standards (T22 ↔ Light) via `TransferInterfaceCpi` +/// with SPL interface PDAs. +#[tokio::test] +async fn test_swap_t22() { + let mut rpc = create_test_rpc().await; + let ctx = setup_amm_test(&mut rpc, TokenConfig::Token2022).await; + run_amm_full_flow(&mut rpc, &ctx).await; +} + +/// Light mint + Light user accounts, SPL LP mint, and Light pool vaults. +/// +/// All token A/B transfers are Light-to-Light (`TransferCheckedCpi`). +/// LP mint is SPL because `create_pool` uses Anchor's `init` macro +/// which only supports SPL/T22 mints. +#[tokio::test] +async fn test_swap_light() { + let mut rpc = create_test_rpc().await; + let ctx = setup_amm_test(&mut rpc, TokenConfig::Light).await; + run_amm_full_flow(&mut rpc, &ctx).await; +} + +/// SPL mint + Light user accounts (interop), SPL LP mint. +/// +/// Tokens start in SPL ATAs, get converted into Light token accounts during +/// setup via `transfer_spl_to_light`. Once in Light token accounts, all AMM +/// transfers are Light-to-Light (`TransferCheckedCpi`). +/// Shows that Light token accounts can hold any SPL mint. +#[tokio::test] +async fn test_swap_spl_light() { + let mut rpc = create_test_rpc().await; + let ctx = setup_amm_test(&mut rpc, TokenConfig::LightSpl).await; + run_amm_full_flow(&mut rpc, &ctx).await; +} + +/// Token-2022 mint + Light user accounts (interop), T22 LP mint. +/// +/// Tokens start in T22 ATAs, get converted into Light token accounts during +/// setup via `transfer_spl_to_light`. Once in Light token accounts, all AMM +/// transfers are Light-to-Light (`TransferCheckedCpi`). +/// Shows that Light token accounts can hold any T22 mint. +#[tokio::test] +async fn test_swap_t22_light() { + let mut rpc = create_test_rpc().await; + let ctx = setup_amm_test(&mut rpc, TokenConfig::LightT22).await; + run_amm_full_flow(&mut rpc, &ctx).await; +} + +/// Fully rent-free: Light mints + Light user accounts + Light LP mint. +/// +/// Uses `create_pool_light_lp` to create the LP mint as a Light mint via CPI. +/// All token operations use `TransferCheckedCpi` — the entire pool is +/// rent-free. +#[tokio::test] +async fn test_swap_full_light() { + let mut rpc = create_test_rpc().await; + let ctx = setup_amm_test(&mut rpc, TokenConfig::FullLight).await; + run_amm_full_flow(&mut rpc, &ctx).await; +} + +/// AMM creation is config-independent (fee + admin only). Verifies that +/// `create_amm` works in isolation without pool creation. +#[tokio::test] +async fn test_create_amm() { + let mut rpc = create_test_rpc().await; + let ctx = setup_amm_test(&mut rpc, TokenConfig::Spl).await; + + let accounts = swap_example::accounts::CreateAmm { + amm: ctx.amm_pda, + admin: ctx.payer.pubkey(), + payer: ctx.payer.pubkey(), + system_program: solana_sdk::system_program::ID, + }; + + let data = swap_example::instruction::CreateAmm { + id: ctx.amm_id, + fee: 0, + }; + + let ix = Instruction { + program_id: ctx.program_id, + accounts: accounts.to_account_metas(None), + data: data.data(), + }; + + rpc.create_and_send_transaction(&[ix], &ctx.payer.pubkey(), &[&ctx.payer]) + .await + .expect("create_amm with 0% fee should succeed"); +} + +// ============================================================================ +// Full Flow +// ============================================================================ + +/// Run the full AMM flow for any token configuration: SPL, T22, Light. +/// +/// 1. Create AMM with 2.5% fee +/// 2. Create pool with Light token vaults (standard or FullLight path) +/// 3. Deposit initial liquidity, receive LP tokens +/// 4. Create trader with funded accounts +/// 5. Swap A→B +/// 6. Swap B→A (half of received B) +/// 7. Withdraw half of LP tokens +/// 8. Verify final LP balance +async fn run_amm_full_flow( + rpc: &mut R, + ctx: &AmmTestContext, +) { + // Token program IDs used across multiple phases + let token_program = ctx.token_config.token_program_id(); + let liquidity_token_program = match ctx.token_config { + TokenConfig::Light | TokenConfig::LightSpl | TokenConfig::Spl => token::ID, + TokenConfig::Token2022 | TokenConfig::LightT22 => spl_token_2022::ID, + TokenConfig::FullLight => Pubkey::new_from_array(LIGHT_TOKEN_PROGRAM_ID), + }; + + // ==================== PHASE 1: Create AMM ==================== + // AMM defines fee structure for all pools under it. + { + let accounts = swap_example::accounts::CreateAmm { + amm: ctx.amm_pda, + admin: ctx.payer.pubkey(), + payer: ctx.payer.pubkey(), + system_program: solana_sdk::system_program::ID, + }; + + let data = swap_example::instruction::CreateAmm { + id: ctx.amm_id, + fee: 250, // 2.5% + }; + + let ix = Instruction { + program_id: ctx.program_id, + accounts: accounts.to_account_metas(None), + data: data.data(), + }; + + rpc.create_and_send_transaction(&[ix], &ctx.payer.pubkey(), &[&ctx.payer]) + .await + .expect("create_amm should succeed"); + } + + // ==================== PHASE 2: Create Pool ==================== + // Pool holds liquidity for token pair A/B. Pool vaults are Light token + // accounts. FullLight uses `create_pool_light_lp` (CPI-initialized vaults + // + Light LP mint). All others use `create_pool` (macro-initialized vaults + // + SPL/T22 LP mint). + { + // Proof inputs differ by pool creation mode: + // FullLight: proves LP mint signer (vaults created via explicit CPI) + // Standard: proves pool vault PDAs (vaults created via macro) + let proof_inputs = if ctx.token_config.uses_light_lp_mint() { + vec![CreateAccountsProofInput::mint( + ctx.lp_mint_signer + .expect("FullLight config should have lp_mint_signer"), + )] + } else { + vec![ + CreateAccountsProofInput::pda(ctx.pool_account_a), + CreateAccountsProofInput::pda(ctx.pool_account_b), + ] + }; + + let proof_result = get_create_accounts_proof(rpc, &ctx.program_id, proof_inputs) + .await + .unwrap(); + + if ctx.token_config.uses_light_lp_mint() { + // FullLight: create_pool_light_lp — CPI-initialized vaults + Light LP mint + let lp_mint_signer = ctx + .lp_mint_signer + .expect("FullLight config should have lp_mint_signer"); + + let accounts = swap_example::accounts::CreatePoolLightLp { + amm: ctx.amm_pda, + pool: ctx.pool_pda, + pool_authority: ctx.pool_authority, + lp_mint_signer, + mint_liquidity: ctx.mint_liquidity, + mint_a: ctx.mint_a_pubkey, + mint_b: ctx.mint_b_pubkey, + pool_vault_a: ctx.pool_account_a, + pool_vault_b: ctx.pool_account_b, + fee_payer: ctx.payer.pubkey(), + token_program, + compression_config: ctx.compression_config, + light_token_config: COMPRESSIBLE_CONFIG_V1, + light_token_rent_sponsor: RENT_SPONSOR, + light_token_program: Pubkey::new_from_array(LIGHT_TOKEN_PROGRAM_ID), + light_token_cpi_authority: CPI_AUTHORITY_PDA, + system_program: solana_sdk::system_program::ID, + }; + + let data = swap_example::instruction::CreatePoolLightLp { + params: swap_example::CreatePoolLightLpParams { + create_accounts_proof: proof_result.create_accounts_proof, + pool_account_a_bump: ctx.pool_a_bump, + pool_account_b_bump: ctx.pool_b_bump, + lp_mint_signer_bump: ctx.lp_mint_signer_bump, + pool_authority_bump: ctx.pool_authority_bump, + }, + }; + + let ix = Instruction { + program_id: ctx.program_id, + accounts: [ + accounts.to_account_metas(None), + proof_result.remaining_accounts, + ] + .concat(), + data: data.data(), + }; + + rpc.create_and_send_transaction(&[ix], &ctx.payer.pubkey(), &[&ctx.payer]) + .await + .expect("create_pool_light_lp should succeed"); + } else { + // Standard: create_pool — macro-initialized vaults + SPL/T22 LP mint + let accounts = swap_example::accounts::CreatePool { + amm: ctx.amm_pda, + pool: ctx.pool_pda, + pool_authority: ctx.pool_authority, + mint_liquidity: ctx.mint_liquidity, + mint_a: ctx.mint_a_pubkey, + mint_b: ctx.mint_b_pubkey, + pool_account_a: ctx.pool_account_a, + pool_account_b: ctx.pool_account_b, + fee_payer: ctx.payer.pubkey(), + token_program, + liquidity_token_program, + light_token_program: Pubkey::new_from_array(LIGHT_TOKEN_PROGRAM_ID), + system_program: solana_sdk::system_program::ID, + light_token_config: COMPRESSIBLE_CONFIG_V1, + light_token_rent_sponsor: RENT_SPONSOR, + light_token_cpi_authority: CPI_AUTHORITY_PDA, + }; + + let data = swap_example::instruction::CreatePool { + params: swap_example::CreatePoolParams { + create_accounts_proof: proof_result.create_accounts_proof, + pool_account_a_bump: ctx.pool_a_bump, + pool_account_b_bump: ctx.pool_b_bump, + }, + }; + + let ix = Instruction { + program_id: ctx.program_id, + accounts: [ + accounts.to_account_metas(None), + proof_result.remaining_accounts, + ] + .concat(), + data: data.data(), + }; + + rpc.create_and_send_transaction(&[ix], &ctx.payer.pubkey(), &[&ctx.payer]) + .await + .expect("create_pool should succeed"); + } + + // Fund pool_authority for Light-to-Light transfers (rent top-ups). + // The pool_authority needs lamports to pay for rent top-ups when + // transferring from pool accounts to user accounts. + if ctx.token_config.uses_light_user_accounts() { + rpc.airdrop_lamports(&ctx.pool_authority, 1_000_000_000) + .await + .expect("Fund pool_authority for rent top-ups"); + } + } + + // Verify initial pool balances + verify_light_token_balance(rpc, ctx.pool_account_a, 0, "pool_account_a (initial)").await; + verify_light_token_balance(rpc, ctx.pool_account_b, 0, "pool_account_b (initial)").await; + + // ==================== PHASE 3: Deposit Liquidity ==================== + // Depositor provides equal amounts of token A and B, receives LP tokens. + let deposit_amount = 1_000_000_000u64; // 1 token + let depositor_liquidity_ata = { + // Create LP ATA for depositor (varies by LP mint type) + let depositor_liquidity_ata = match ctx.token_config { + TokenConfig::Spl | TokenConfig::LightSpl | TokenConfig::Light => { + create_spl_ata( + rpc, + &ctx.payer, + &ctx.mint_liquidity, + &ctx.depositor.pubkey(), + ) + .await + } + TokenConfig::Token2022 | TokenConfig::LightT22 => { + create_t22_ata( + rpc, + &ctx.payer, + &ctx.mint_liquidity, + &ctx.depositor.pubkey(), + ) + .await + } + TokenConfig::FullLight => { + create_light_ata( + rpc, + &ctx.payer, + &ctx.mint_liquidity, + &ctx.depositor.pubkey(), + ) + .await + } + }; + + let accounts = swap_example::accounts::DepositLiquidity { + pool: ctx.pool_pda, + pool_authority: ctx.pool_authority, + depositor: ctx.depositor.pubkey(), + mint_liquidity: ctx.mint_liquidity, + mint_a: ctx.mint_a_pubkey, + mint_b: ctx.mint_b_pubkey, + pool_account_a: ctx.pool_account_a, + pool_account_b: ctx.pool_account_b, + depositor_account_liquidity: depositor_liquidity_ata, + depositor_account_a: ctx.depositor_ata_a, + depositor_account_b: ctx.depositor_ata_b, + payer: ctx.payer.pubkey(), + token_program, + liquidity_token_program, + system_program: solana_sdk::system_program::ID, + light_token_program: Pubkey::new_from_array(LIGHT_TOKEN_PROGRAM_ID), + light_token_rent_sponsor: RENT_SPONSOR, + light_token_cpi_authority: CPI_AUTHORITY_PDA, + spl_interface_pda_a: ctx.spl_interface_pda_a, + spl_interface_pda_b: ctx.spl_interface_pda_b, + }; + + let data = swap_example::instruction::DepositLiquidity { + amount_a: deposit_amount, + amount_b: deposit_amount, + }; + + let ix = Instruction { + program_id: ctx.program_id, + accounts: accounts.to_account_metas(None), + data: data.data(), + }; + + rpc.create_and_send_transaction( + &[ix], + &ctx.payer.pubkey(), + &[&ctx.payer, &ctx.depositor], + ) + .await + .expect("deposit_liquidity should succeed"); + + depositor_liquidity_ata + }; + + // Verify pool balances after deposit + verify_light_token_balance( + rpc, + ctx.pool_account_a, + deposit_amount, + "pool_account_a (after deposit)", + ) + .await; + verify_light_token_balance( + rpc, + ctx.pool_account_b, + deposit_amount, + "pool_account_b (after deposit)", + ) + .await; + + // ==================== PHASE 4: Create Trader ==================== + // Trader gets funded accounts for swapping. + let trader_initial_a = 100_000_000u64; // 0.1 tokens + let (trader, trader_ata_a, trader_ata_b) = create_trader(rpc, ctx, trader_initial_a).await; + + // ==================== PHASE 5: Swap A → B ==================== + let swap_input = 10_000_000u64; // 0.01 tokens + { + let accounts = swap_example::accounts::SwapExactTokensForTokens { + amm: ctx.amm_pda, + pool: ctx.pool_pda, + pool_authority: ctx.pool_authority, + trader: trader.pubkey(), + mint_a: ctx.mint_a_pubkey, + mint_b: ctx.mint_b_pubkey, + pool_account_a: ctx.pool_account_a, + pool_account_b: ctx.pool_account_b, + trader_account_a: trader_ata_a, + trader_account_b: trader_ata_b, + payer: ctx.payer.pubkey(), + token_program, + system_program: solana_sdk::system_program::ID, + light_token_program: Pubkey::new_from_array(LIGHT_TOKEN_PROGRAM_ID), + light_token_rent_sponsor: RENT_SPONSOR, + light_token_cpi_authority: CPI_AUTHORITY_PDA, + spl_interface_pda_a: ctx.spl_interface_pda_a, + spl_interface_pda_b: ctx.spl_interface_pda_b, + }; + + let data = swap_example::instruction::SwapExactTokensForTokens { + swap_a: true, + input_amount: swap_input, + min_output_amount: 1, + }; + + let ix = Instruction { + program_id: ctx.program_id, + accounts: accounts.to_account_metas(None), + data: data.data(), + }; + + rpc.create_and_send_transaction(&[ix], &ctx.payer.pubkey(), &[&ctx.payer, &trader]) + .await + .expect("swap A->B should succeed"); + } + + // Verify trader received token B + let trader_b_balance = get_token_balance(rpc, trader_ata_b).await; + assert!(trader_b_balance > 0, "Trader should have received token B"); + + // ==================== PHASE 6: Swap B → A ==================== + // Swap half of received B back to A. + let swap_b_input = trader_b_balance / 2; + { + let accounts = swap_example::accounts::SwapExactTokensForTokens { + amm: ctx.amm_pda, + pool: ctx.pool_pda, + pool_authority: ctx.pool_authority, + trader: trader.pubkey(), + mint_a: ctx.mint_a_pubkey, + mint_b: ctx.mint_b_pubkey, + pool_account_a: ctx.pool_account_a, + pool_account_b: ctx.pool_account_b, + trader_account_a: trader_ata_a, + trader_account_b: trader_ata_b, + payer: ctx.payer.pubkey(), + token_program, + system_program: solana_sdk::system_program::ID, + light_token_program: Pubkey::new_from_array(LIGHT_TOKEN_PROGRAM_ID), + light_token_rent_sponsor: RENT_SPONSOR, + light_token_cpi_authority: CPI_AUTHORITY_PDA, + spl_interface_pda_a: ctx.spl_interface_pda_a, + spl_interface_pda_b: ctx.spl_interface_pda_b, + }; + + let data = swap_example::instruction::SwapExactTokensForTokens { + swap_a: false, + input_amount: swap_b_input, + min_output_amount: 1, + }; + + let ix = Instruction { + program_id: ctx.program_id, + accounts: accounts.to_account_metas(None), + data: data.data(), + }; + + rpc.create_and_send_transaction(&[ix], &ctx.payer.pubkey(), &[&ctx.payer, &trader]) + .await + .expect("swap B->A should succeed"); + } + + // ==================== PHASE 7: Withdraw Liquidity ==================== + // Depositor redeems half of LP tokens for underlying token A and B. + let lp_balance = get_token_balance(rpc, depositor_liquidity_ata).await; + let withdraw_amount = lp_balance / 2; + { + let accounts = swap_example::accounts::WithdrawLiquidity { + amm: ctx.amm_pda, + pool: ctx.pool_pda, + pool_authority: ctx.pool_authority, + depositor: ctx.depositor.pubkey(), + mint_liquidity: ctx.mint_liquidity, + mint_a: ctx.mint_a_pubkey, + mint_b: ctx.mint_b_pubkey, + pool_account_a: ctx.pool_account_a, + pool_account_b: ctx.pool_account_b, + depositor_account_liquidity: depositor_liquidity_ata, + depositor_account_a: ctx.depositor_ata_a, + depositor_account_b: ctx.depositor_ata_b, + payer: ctx.payer.pubkey(), + token_program, + liquidity_token_program, + system_program: solana_sdk::system_program::ID, + light_token_program: Pubkey::new_from_array(LIGHT_TOKEN_PROGRAM_ID), + light_token_rent_sponsor: RENT_SPONSOR, + light_token_cpi_authority: CPI_AUTHORITY_PDA, + spl_interface_pda_a: ctx.spl_interface_pda_a, + spl_interface_pda_b: ctx.spl_interface_pda_b, + }; + + let data = swap_example::instruction::WithdrawLiquidity { + amount: withdraw_amount, + }; + + let ix = Instruction { + program_id: ctx.program_id, + accounts: accounts.to_account_metas(None), + data: data.data(), + }; + + rpc.create_and_send_transaction( + &[ix], + &ctx.payer.pubkey(), + &[&ctx.payer, &ctx.depositor], + ) + .await + .expect("withdraw_liquidity should succeed"); + } + + // ==================== PHASE 8: Verify Final State ==================== + // LP tokens were burned + let lp_balance_after = get_token_balance(rpc, depositor_liquidity_ata).await; + assert_eq!( + lp_balance_after, + lp_balance - withdraw_amount, + "LP tokens should be burned" + ); +} diff --git a/programs/anchor/token-swap/tests/user_light.rs b/programs/anchor/token-swap/tests/user_light.rs deleted file mode 100644 index 5f34a65..0000000 --- a/programs/anchor/token-swap/tests/user_light.rs +++ /dev/null @@ -1,31 +0,0 @@ -//! Integration tests for the token-swap AMM program with Light mints and Light ATAs. -//! -//! Token Configuration: -//! - Mint Type: Light (via CreateMint instruction) -//! - User Accounts: Light token accounts -//! - Pool Accounts: Light Protocol token accounts -//! -//! This is the pure Light-to-Light test where everything uses light tokens. - -mod common; - -use common::{create_amm, create_test_rpc, run_amm_full_flow, setup_amm_test, TokenConfig}; - -#[tokio::test] -async fn test_amm_full_flow_light() { - let mut rpc = create_test_rpc().await; - let ctx = setup_amm_test(&mut rpc, TokenConfig::Light).await; - run_amm_full_flow(&mut rpc, &ctx).await; -} - -#[tokio::test] -async fn test_create_amm_light() { - let mut rpc = create_test_rpc().await; - let ctx = setup_amm_test(&mut rpc, TokenConfig::Light).await; - - // Create AMM with 0% fee - create_amm(&mut rpc, &ctx, 0).await; - - println!("AMM with 0% fee created successfully"); - println!("=== Initialize AMM test completed successfully! ==="); -} diff --git a/programs/anchor/token-swap/tests/user_light_full.rs b/programs/anchor/token-swap/tests/user_light_full.rs deleted file mode 100644 index ddaa901..0000000 --- a/programs/anchor/token-swap/tests/user_light_full.rs +++ /dev/null @@ -1,33 +0,0 @@ -//! Integration tests for the token-swap AMM program with full Light configuration. -//! -//! Token Configuration: -//! - Mint Type: Light (via CreateMint instruction) -//! - User Accounts: Light token accounts -//! - Pool Accounts: Light Protocol token accounts -//! - LP Mint: Light (via create_pool_light_lp instruction) -//! -//! This is the complete Light-to-Light test where everything including the LP mint -//! uses light tokens. - -mod common; - -use common::{create_amm, create_test_rpc, run_amm_full_flow, setup_amm_test, TokenConfig}; - -#[tokio::test] -async fn test_amm_full_flow_full_light() { - let mut rpc = create_test_rpc().await; - let ctx = setup_amm_test(&mut rpc, TokenConfig::FullLight).await; - run_amm_full_flow(&mut rpc, &ctx).await; -} - -#[tokio::test] -async fn test_create_amm_full_light() { - let mut rpc = create_test_rpc().await; - let ctx = setup_amm_test(&mut rpc, TokenConfig::FullLight).await; - - // Create AMM with 0% fee - create_amm(&mut rpc, &ctx, 0).await; - - println!("AMM with 0% fee created successfully"); - println!("=== Initialize AMM (FullLight) test completed successfully! ==="); -} diff --git a/programs/anchor/token-swap/tests/user_spl.rs b/programs/anchor/token-swap/tests/user_spl.rs deleted file mode 100644 index 7e5cdb3..0000000 --- a/programs/anchor/token-swap/tests/user_spl.rs +++ /dev/null @@ -1,31 +0,0 @@ -//! Integration tests for the token-swap AMM program with SPL mints and SPL ATAs. -//! -//! Token Configuration: -//! - Mint Type: SPL (token::ID) -//! - User Accounts: SPL ATAs -//! - Pool Accounts: Light Protocol token accounts - -mod common; - -use common::{create_test_rpc, run_amm_full_flow, setup_amm_test, TokenConfig}; - -/// Test the full AMM flow with SPL tokens -#[tokio::test] -async fn test_amm_full_flow_spl() { - let mut rpc = create_test_rpc().await; - let ctx = setup_amm_test(&mut rpc, TokenConfig::Spl).await; - run_amm_full_flow(&mut rpc, &ctx).await; -} - -/// Test AMM creation with various fee values using SPL tokens -#[tokio::test] -async fn test_create_amm_spl() { - use common::{create_amm, setup_amm_test}; - - let mut rpc = create_test_rpc().await; - let ctx = setup_amm_test(&mut rpc, TokenConfig::Spl).await; - - // Create AMM with 0% fee - create_amm(&mut rpc, &ctx, 0).await; - println!("AMM with 0% fee created successfully"); -} diff --git a/programs/anchor/token-swap/tests/user_spl_light.rs b/programs/anchor/token-swap/tests/user_spl_light.rs deleted file mode 100644 index ecf6990..0000000 --- a/programs/anchor/token-swap/tests/user_spl_light.rs +++ /dev/null @@ -1,25 +0,0 @@ -//! Integration tests for the token-swap AMM program with SPL mints and Light user accounts. -//! -//! Token Configuration: -//! - Mint Type: SPL (token::ID) -//! - User Accounts: Light token accounts (offchain SPL->Light conversion before program interaction) -//! - Pool Accounts: Light Protocol token accounts -//! -//! Test Flow: -//! 1. Create SPL mint and temporary SPL ATA -//! 2. Mint tokens to temporary ATA -//! 3. Create Light token account for user -//! 4. Create SPL interface PDA -//! 5. Transfer from SPL ATA to Light account (offchain conversion using `transfer_spl_to_light`) -//! 6. User has Light account with tokens - interact with program using Light-to-Light - -mod common; - -use common::{create_test_rpc, run_amm_full_flow, setup_amm_test, TokenConfig}; - -#[tokio::test] -async fn test_amm_full_flow_light_spl() { - let mut rpc = create_test_rpc().await; - let ctx = setup_amm_test(&mut rpc, TokenConfig::LightSpl).await; - run_amm_full_flow(&mut rpc, &ctx).await; -} diff --git a/programs/anchor/token-swap/tests/user_t22.rs b/programs/anchor/token-swap/tests/user_t22.rs deleted file mode 100644 index 5b4448b..0000000 --- a/programs/anchor/token-swap/tests/user_t22.rs +++ /dev/null @@ -1,31 +0,0 @@ -//! Integration tests for the token-swap AMM program with Token-2022 mints and T22 ATAs. -//! -//! Token Configuration: -//! - Mint Type: Token-2022 (spl_token_2022::ID) -//! - User Accounts: Token-2022 ATAs -//! - Pool Accounts: Light Protocol token accounts - -mod common; - -use common::{create_test_rpc, run_amm_full_flow, setup_amm_test, TokenConfig}; - -/// Test the full AMM flow with Token-2022 tokens -#[tokio::test] -async fn test_amm_full_flow_t22() { - let mut rpc = create_test_rpc().await; - let ctx = setup_amm_test(&mut rpc, TokenConfig::Token2022).await; - run_amm_full_flow(&mut rpc, &ctx).await; -} - -/// Test AMM creation with various fee values using Token-2022 tokens -#[tokio::test] -async fn test_create_amm_t22() { - use common::{create_amm, setup_amm_test}; - - let mut rpc = create_test_rpc().await; - let ctx = setup_amm_test(&mut rpc, TokenConfig::Token2022).await; - - // Create AMM with 2.5% fee - create_amm(&mut rpc, &ctx, 250).await; - println!("AMM with 2.5% fee created successfully"); -} diff --git a/programs/anchor/token-swap/tests/user_t22_light.rs b/programs/anchor/token-swap/tests/user_t22_light.rs deleted file mode 100644 index ed13969..0000000 --- a/programs/anchor/token-swap/tests/user_t22_light.rs +++ /dev/null @@ -1,25 +0,0 @@ -//! Integration tests for the token-swap AMM program with T22 mints and Light user accounts. -//! -//! Token Configuration: -//! - Mint Type: Token-2022 (spl_token_2022::ID) -//! - User Accounts: Light token accounts (offchain T22->Light conversion before program interaction) -//! - Pool Accounts: Light Protocol token accounts -//! -//! Test Flow: -//! 1. Create T22 mint and temporary T22 ATA -//! 2. Mint tokens to temporary ATA -//! 3. Create Light token account for user -//! 4. Create SPL interface PDA (works with T22) -//! 5. Transfer from T22 ATA to Light account (offchain conversion using `transfer_spl_to_light`) -//! 6. User has Light account with tokens - interact with program using Light-to-Light - -mod common; - -use common::{create_test_rpc, run_amm_full_flow, setup_amm_test, TokenConfig}; - -#[tokio::test] -async fn test_amm_full_flow_light_t22() { - let mut rpc = create_test_rpc().await; - let ctx = setup_amm_test(&mut rpc, TokenConfig::LightT22).await; - run_amm_full_flow(&mut rpc, &ctx).await; -} From 4ee184776c8f1e581928c5b14961c80e2cdbb09f Mon Sep 17 00:00:00 2001 From: tilo-14 Date: Thu, 12 Feb 2026 20:11:15 +0000 Subject: [PATCH 07/10] add claude md --- CLAUDE.md | 289 +++++++++--------------------------------------------- 1 file changed, 47 insertions(+), 242 deletions(-) diff --git a/CLAUDE.md b/CLAUDE.md index a5d7871..6c8af07 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -2,271 +2,76 @@ This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository. -## Overview +## What this repo is -Light Token examples repository demonstrating rent-free token accounts on Solana. Light Token reduces mint and token account costs by 200x by having the Light Token program sponsor rent-exemption. Light accounts can hold balances from Light, SPL, and Token-2022 mints. +Light Token example programs demonstrating rent-free token vaults using Light Protocol on Solana. Contains Anchor programs (escrow, fundraiser, token-swap, light-token-minter), a shared test utilities crate, TypeScript client examples, and toolkits (payments, streaming). -## Build and Test Commands +## Build and test -### Anchor Programs (from `programs/anchor/`) +All Anchor programs live in `programs/anchor/` as a Cargo workspace. Build and test from that directory: ```bash -# Build all programs -anchor build +# Build a single program +cd programs/anchor && cargo build-sbf -p escrow -# Test individual programs -cargo test-sbf -p escrow -cargo test-sbf -p fundraiser -cargo test-sbf -p light-token-minter -cargo test-sbf -p swap_example +# Test a single program (runs LiteSVM-based tests, no validator needed) +cd programs/anchor && cargo test-sbf -p escrow +cd programs/anchor && cargo test-sbf -p fundraiser +cd programs/anchor && cargo test-sbf -p light-token-minter +cd programs/anchor && cargo test-sbf -p swap_example -# Run a single test function -cargo test-sbf -p escrow -- test_escrow_light -``` - -### TypeScript Client (from `typescript-client/`) - -```bash -npm install - -# Run all tests -npm run test:all - -# Run specific categories -npm run test:actions -npm run test:instructions - -# Run individual examples -npm run create-mint:action -npm run mint-to:instruction -# See package.json for all scripts -``` - -### Local Test Validator - -```bash -light test-validator -``` - -## Requirements - -- Rust 1.90.0 (pinned in `programs/anchor/rust-toolchain.toml`) -- Solana CLI 2.3.11+ -- Anchor 0.31.1 -- Node 22 -- Light CLI: `npm i -g @lightprotocol/zk-compression-cli@alpha` - -**Dependency pins**: The workspace pins `blake3 = "=1.5.5"` for solana-program compatibility and `time = "=0.3.41"` to avoid edition2024 requirements from cargo build-sbf. - -## Repository Structure - -``` -programs/anchor/ # Anchor Solana programs -├── escrow/ # Peer-to-peer Light Token swap (make/take offer) -├── fundraiser/ # Token fundraiser with target, deadline, refunds -├── light-token-minter/ # Create light-mints with metadata -├── token-swap/ # AMM with liquidity pools -└── shared-test-utils/ # Common test infrastructure (all programs depend on this) - -typescript-client/ # TypeScript SDK examples -├── actions/ # High-level convenience functions -└── instructions/ # Low-level instruction builders - -toolkits/ # Integration examples -├── payments-and-wallets/ # Wallet integration patterns (TypeScript) -└── streaming-tokens/ # Laserstream mint event streaming (Rust) -``` - -## Program Architecture - -Programs use Light Protocol's compressed account model: - -- `#[light_program]` macro enables Light account support -- `derive_light_cpi_signer!` generates CPI signer for Light operations -- `get_create_accounts_proof()` fetches ZK proofs for account creation -- `TransferInterfaceCpi` transfers between Light/SPL/T22 accounts - -### Light Protocol Integration Pattern - -```rust -// 1. Derive CPI signer from program ID -pub const LIGHT_CPI_SIGNER: CpiSigner = derive_light_cpi_signer!("ProgramId..."); - -// 2. Use #[light_program] before #[program] -#[light_program] -#[program] -pub mod my_program { ... } - -// 3. Initialize rent-free config in tests -let config = initialize_rent_free_config(rpc, &payer, &program_id).await; -``` - -### SPL Interface PDAs - -For transfers between SPL/T22 and Light accounts, create an SPL interface PDA: - -```rust -// Required for LightSpl/LightT22 token configs -let iface = create_spl_interface_pda(rpc, &payer, &mint, MintType::Spl, false).await; -``` - -## Escrow Program Architecture - -The escrow (`programs/anchor/escrow/`) implements a peer-to-peer token swap using make/take pattern. It differs from a standard SPL escrow in three key ways: a separate authority PDA signs for the vault, the vault is a Light token account (rent-free), and transfers route through a dual-path function that picks Light-to-Light or cross-standard CPI based on account ownership. - -### Escrow Flow - -**`make_offer`**: Maker deposits token A into a vault and records offer terms. - -1. Client calls `get_create_accounts_proof(rpc, &program_id, vec![pda(offer_pda)])` to obtain a ZK proof that the offer account address does not yet exist in the address tree -2. Program transfers token A from maker to vault via `transfer_tokens()` -3. Program writes offer state (maker, mints, wanted amount, auth_bump) - -**`take_offer`**: Taker completes the swap and closes the vault. - -1. Transfer token B from taker to maker via `transfer_tokens()` -2. Withdraw token A from vault to taker via `transfer_tokens()` (signed by authority PDA) -3. Close vault via `CloseAccountCpi`, returning rent sponsor lamports to `RENT_SPONSOR` - -### PDA Derivation Chain - -PDAs derive in sequence -- vault depends on offer: +# Run a single test by name +cd programs/anchor && cargo test-sbf -p escrow -- test_escrow_spl +# TypeScript client examples +cd typescript-client && npm install && npm run create-mint:action ``` -authority_pda = PDA([b"authority"], program_id) -- signs vault operations -offer_pda = PDA([b"offer", maker, id_le_bytes], program_id) -- stores offer terms -vault_pda = PDA([b"vault", offer_pda], program_id) -- holds escrowed token A -``` - -The authority PDA (not the offer account) is the vault's token owner. This differs from standard SPL escrow where the offer account itself owns the vault. - -### Dual Transfer Path (`shared.rs`) - -`transfer_tokens()` in `instructions/shared.rs` selects the CPI path at runtime based on `is_light_account()`, which checks whether an account is owned by `LIGHT_TOKEN_PROGRAM_ID`: - -- **Light-to-Light** (`is_light_account(from) && is_light_account(to)`): Uses `TransferCheckedCpi` with `fee_payer: Some(payer)` to keep the authority account readonly (required when authority is a PDA with account data). -- **Cross-standard** (any other combination): Uses `TransferInterfaceCpi` with `SplInterfaceConfig` containing the mint `AccountInfo`, SPL token program `AccountInfo`, interface PDA `AccountInfo`, and bump. The caller always passes `SplInterfaceConfig` -- for Light-to-Light it's ignored, for cross-standard it's required. - -### Light Protocol Accounts on Instructions - -Beyond standard Anchor accounts, Light instructions require: - -- `light_token_program` — Light token program for CPI (readonly) -- `light_token_compressible_config` — global config at `COMPRESSIBLE_CONFIG_V1` (readonly) -- `light_token_rent_sponsor` — pays rent exemption at `RENT_SPONSOR` (mut) -- `light_token_cpi_authority` — CPI authority PDA for Light operations (mut) -- `spl_interface_pda_*` — per-mint interface PDA for SPL<->Light transfers (mut) -- `compression_config` — per-program rent-free config, make_offer only (readonly) - -### Offer State - -`Offer` (`state/offer.rs`) derives both `#[account]` and `LightAccount`: - -```rust -pub struct Offer { - pub compression_info: Option, // Light Protocol metadata - pub id: u64, - pub maker: Pubkey, - pub token_mint_a: Pubkey, - pub token_mint_b: Pubkey, - pub token_b_wanted_amount: u64, - pub auth_bump: u8, // authority PDA bump (not offer bump) -} -``` - -The `#[light_account(init)]` attribute on the offer account in `MakeOffer` triggers Light Protocol's compressed account initialization. The vault uses `#[light_account(init, token::...)]` to create a Light token account with the authority PDA as owner. - -## Test Architecture -### Escrow Tests +CI runs `cargo test-sbf -p ` for each program (see `.github/workflows/rust-tests.yml`). Solana CLI 2.3.11, Rust 1.90.0. -All five token configurations live in a single file (`tests/escrow.rs`) with a module-level doc that explains the three architectural differences from standard SPL escrow and a scenario table mapping each test to its mint type, user account type, and transfer path. Each test function has a doc comment describing the specific token flow it exercises. +## Architecture -`run_escrow_full_flow` builds and sends `make_offer` / `take_offer` instructions inline (no helper wrappers — the full instruction construction is visible in context). `tests/common/mod.rs` contains only setup: `TokenConfig` enum, `EscrowTestContext` struct, `create_test_rpc`, `setup_escrow_test`, and `create_token_account`. +### Programs (`programs/anchor/`) -### TokenConfig Enum - -```rust -pub enum TokenConfig { - Spl, // SPL mint + SPL associated token accounts - Token2022, // T22 mint + T22 associated token accounts - Light, // Light mint + Light associated token accounts - LightSpl, // SPL mint + Light associated token accounts - LightT22, // T22 mint + Light associated token accounts -} -``` - -`setup_escrow_test` creates SPL interface PDAs for all SPL/T22 configs (Spl, Token2022, LightSpl, LightT22) because the vault is always a Light token account — any transfer involving an SPL/T22 account and the Light vault crosses standards and requires an interface PDA. - -### Test Flow Phases (`run_escrow_full_flow`) - -The test exercises the full lifecycle in 7 phases, with two compress→load cycles that simulate accounts going cold between transactions: - -1. **Define terms** — offer_id, amounts, PDA derivation -2. **Create accounts** — maker/taker token accounts via `create_token_account` (varies by `TokenConfig`) -3. **Verify initial state** — `verify_light_token_balance` for all four accounts -4. **Compress → Load (pre-make)** — `warp_to_compress` + `load_light_mints` + `load_light_accounts` per owner -5. **Make offer** — `get_create_accounts_proof` for offer PDA, build `MakeOffer` instruction with `remaining_accounts` from proof -6. **Compress → Load (pre-take)** — second compress→load cycle, includes `load_light_pdas` for offer + vault -7. **Take offer + verify** — build `TakeOffer` instruction, verify final balances and account closure - -### Cold/Hot Lifecycle Helpers - -Light Token accounts auto-compress when sponsored rent expires. The test simulates this with `warp_to_compress` → load helpers → transact. All load helpers are no-ops for non-Light (SPL/T22) accounts, so the same flow works for all five configs. - -Four helpers live in `escrow.rs` (not `common/mod.rs`) because they depend on program-specific types: - -**`warp_to_compress(rpc)`** — calls `rpc.warp_epoch_forward(30)` to advance slots past sponsored rent, triggering compression of all Light accounts (mints, ATAs, PDAs). - -**`load_light_mints(rpc, payer, mints)`** — for each mint, calls `rpc.get_mint_interface(address, None)` to check hot/cold state, then `decompress_mint(&mint_iface, payer, rpc)` to build decompression instructions. Permissionless — any signer works. - -**`load_light_accounts(rpc, payer, owner, mints)`** — for each mint, calls `rpc.get_associated_token_account_interface(owner, mint, None)` to resolve the ATA and check cold state. Cold ATAs become `AccountSpec::Ata(iface)`, then `create_load_instructions::(&specs, ...)` builds the decompression transaction. The owner keypair must sign because `Transfer2` requires wallet owner authorization. - -**`load_light_pdas(rpc, payer, maker, program_id, compression_config, offer_pda, vault_pda)`** — loads program-owned accounts (offer + vault) back on-chain: - -- **Offer**: `rpc.get_account_interface(&offer_pda, None)` → deserialize `Offer` from `data[8..]` (skip Anchor discriminator) → `OfferSeeds { fee_payer, id }.into_variant(&data[8..])` → `AccountSpec::Pda(PdaSpec::new(iface, variant, program_id))` -- **Vault**: `rpc.get_token_account_interface(&vault_pda, None)` → deserialize `Token` from `data[..]` (no discriminator offset) → `LightAccountVariant::Vault(TokenDataWithSeeds { seeds: VaultSeeds { offer }, token_data })` → convert `ColdContext::Token` to `ColdContext::Account` via `iface.compressed().unwrap().account.clone()` → `AccountSpec::Pda(PdaSpec::new(...))` -- The maker must sign because the offer's `Pack` includes `fee_payer` (= maker) as a signer - -### LightAccountVariant and Seeds - -`#[light_program]` macro generates `LightAccountVariant`, `OfferSeeds`, and `VaultSeeds` in the `escrow::escrow` module. These types reconstruct account state for cold→hot loading: - -```rust -use escrow::escrow::{LightAccountVariant, OfferSeeds, VaultSeeds}; -use light_account::token::{Token as LightToken, TokenDataWithSeeds}; -use light_account::IntoVariant; -``` +All programs use `#[light_program]` + `#[program]` dual macros from Light Protocol. The `#[light_program]` macro generates `LightAccountVariant`, vault seed structs, and CPI signer boilerplate. -`OfferSeeds` implements `IntoVariant` — call `.into_variant(&data)` to verify seeds against account data and produce a `LightAccountVariant`. `VaultSeeds` wraps in `TokenDataWithSeeds` and constructs `LightAccountVariant::Vault(...)` directly. +- **escrow** — Peer-to-peer token swap. `make_offer` creates an Offer account + rent-free Light vault; `take_offer` completes the swap and closes the vault. `Offer` derives `LightAccount` → generates `LightAccountVariant::Vault`, `VaultSeeds`, `OfferSeeds`. +- **fundraiser** — Crowdfunding. `initialize` creates a Fundraiser + vault; `contribute`, `check_contributions`, `refund`. `Fundraiser` uses `#[account]` only (no `LightAccount` derive) → no cold/hot vault loading possible. +- **token-swap** — AMM with `create_amm`, `create_pool`, `deposit_liquidity`, `withdraw_liquidity`, `swap_exact_tokens_for_tokens`, `create_pool_light_lp`. +- **light-token-minter** — Helper program to create Light mints with metadata and mint tokens. +- **shared-test-utils** — Reusable test helpers for SPL/T22/Light mint creation, ATA creation, SPL interface PDAs, balance verification. All programs depend on this for tests. -### Per-Program Rent Sponsor Setup +### Transfer routing (`shared.rs` in escrow/fundraiser) -`initialize_rent_free_config` (in `shared-test-utils/setup`) derives a per-program rent sponsor PDA via `derive_rent_sponsor_pda(&program_id)`, initializes the rent-free config, and funds the PDA. This is separate from the global `LIGHT_TOKEN_RENT_SPONSOR` — programs need both: +Each program's `shared.rs` contains `transfer_tokens()` which picks the CPI path at runtime: +- Both accounts Light → `TransferCheckedCpi` (direct, no interface PDA) +- One SPL/T22 + one Light → `TransferInterfaceCpi` (cross-standard, requires SPL interface PDA) -- `pda_rent_sponsor`: per-program PDA that pays for `#[light_account(init)]` rent -- `light_token_rent_sponsor`: global account used in Light Token CPI operations +### Token configurations tested -### Shared Test Utilities +Each program tests 5 token standard combinations via `TokenConfig` enum: +- `Spl` — SPL mint + SPL ATAs + Light vault +- `Token2022` — T22 mint + T22 ATAs + Light vault +- `Light` — Light mint + Light ATAs + Light vault +- `LightSpl` — SPL mint, but user accounts converted to Light ATAs before escrow +- `LightT22` — T22 mint, but user accounts converted to Light ATAs before escrow -`shared-test-utils` (`programs/anchor/shared-test-utils/src/lib.rs`) provides reusable helpers: +### Test setup pattern -- `setup::` - `initialize_rent_free_config`, `create_program_test` -- `spl_tokens::` - `create_spl_mint`, `create_spl_ata`, `mint_spl_tokens` -- `t22_tokens::` - `create_t22_mint`, `create_t22_ata`, `mint_t22_tokens` -- `light_tokens::` - `create_light_mint`, `create_light_ata`, `mint_light_tokens` -- `spl_interface::` - `create_spl_interface_pda`, `transfer_spl_to_light` -- `helpers::` - `verify_light_token_balance`, `verify_spl_token_balance`, `get_creation_proof`, `airdrop` +Tests follow: `create_test_rpc()` → `setup_*_test(config)` → `create_token_account()`/`create_contributor()` → `run_*_full_flow()`. Common modules in `tests/common/mod.rs`. -Each program's `tests/common/mod.rs` builds on these for program-specific context (e.g., `EscrowTestContext`). +### Cold/hot lifecycle (escrow only) -## TypeScript Pattern +Light accounts auto-compress after rent expires. Escrow tests exercise the full cycle: create → `warp_to_compress` (calls `rpc.warp_epoch_forward(30)`) → `load_light_accounts` → transact. Fundraiser skips this because `Fundraiser` state lacks `LightAccount` derive. -- **Actions**: Complete operations with connection handling (`actions/*.ts`) -- **Instructions**: Instruction builders for custom transaction composition (`instructions/*.ts`) +### Local path dependencies -Both patterns support Light Token, SPL, and Token-2022 interoperability. +`light-client` and `light-program-test` use local path deps pointing to `~/Workspace/light-protocol/`. The workspace `Cargo.toml` also patches all `light-*` crates to local paths to avoid version conflicts. -## Environment +## Key SDK patterns -For devnet testing, copy `.env.example` to `.env` and set `API_KEY`. +- `CpiSigner` + `derive_light_cpi_signer!` at crate root for each program +- Constants used in `token::owner_seeds` must be `pub use`-exported from `lib.rs` +- Per-program rent sponsor PDA: `derive_rent_sponsor_pda(&program_id)` — separate from global `LIGHT_TOKEN_RENT_SPONSOR` +- `get_create_accounts_proof()` fetches validity proofs for account creation (needed for `init` instructions, not reads) +- `InitializeRentFreeConfig` sets up per-program compression config before any `#[light_account(init)]` \ No newline at end of file From 9bfff91888c50a40d8da5ea95d5f56f59bba94b0 Mon Sep 17 00:00:00 2001 From: tilo-14 Date: Mon, 16 Feb 2026 16:45:41 +0000 Subject: [PATCH 08/10] till l80 --- .../escrow/src/instructions/make_offer.rs | 14 +- .../anchor/escrow/src/instructions/shared.rs | 9 +- .../escrow/src/instructions/take_offer.rs | 8 +- programs/anchor/escrow/tests/escrow.rs | 139 ++++++++---------- 4 files changed, 76 insertions(+), 94 deletions(-) diff --git a/programs/anchor/escrow/src/instructions/make_offer.rs b/programs/anchor/escrow/src/instructions/make_offer.rs index 41a4ae9..90ad20a 100644 --- a/programs/anchor/escrow/src/instructions/make_offer.rs +++ b/programs/anchor/escrow/src/instructions/make_offer.rs @@ -32,10 +32,10 @@ pub struct MakeOffer<'info> { )] pub authority: UncheckedAccount<'info>, - /// CHECK: Config for light mint creation + /// CHECK: Compression config pub compression_config: AccountInfo<'info>, - /// CHECK: PDA rent sponsor for rent reimbursement + /// CHECK: Per-program rent sponsor #[account(mut)] pub pda_rent_sponsor: AccountInfo<'info>, @@ -62,7 +62,7 @@ pub struct MakeOffer<'info> { #[light_account(init)] pub offer: Account<'info, Offer>, - /// CHECK: Vault PDA - initialized by light_account macro + /// CHECK: Vault PDA #[account( mut, seeds = [VAULT_SEED, offer.key().as_ref()], @@ -80,18 +80,18 @@ pub struct MakeOffer<'info> { pub token_program: Interface<'info, TokenInterface>, pub system_program: Program<'info, System>, - /// Light token program for CPI calls + /// Light Token Program pub light_token_program: Interface<'info, TokenInterface>, - /// CHECK: Light token config - validated by address constraint + /// CHECK: Light Token config #[account(address = LIGHT_TOKEN_CONFIG)] pub light_token_config: AccountInfo<'info>, - /// CHECK: Light token rent sponsor - validated by address constraint + /// CHECK: Light Token rent sponsor #[account(mut, address = LIGHT_TOKEN_RENT_SPONSOR)] pub light_token_rent_sponsor: AccountInfo<'info>, - /// CHECK: light-token CPI authority - must be writable for Light token CPI + /// CHECK: Light Token CPI authority #[account(mut)] pub light_token_cpi_authority: AccountInfo<'info>, diff --git a/programs/anchor/escrow/src/instructions/shared.rs b/programs/anchor/escrow/src/instructions/shared.rs index 4a25358..c2b0b1b 100644 --- a/programs/anchor/escrow/src/instructions/shared.rs +++ b/programs/anchor/escrow/src/instructions/shared.rs @@ -2,7 +2,7 @@ use anchor_lang::prelude::*; use light_sdk::constants::LIGHT_TOKEN_PROGRAM_ID; use light_token::instruction::{TransferCheckedCpi, TransferInterfaceCpi}; -/// Configuration for SPL interface (required for SPL<->Light transfers) +/// SPL interface config for cross-standard transfers (SPL/Token 2022 to Light Token). pub struct SplInterfaceConfig<'info> { pub mint: AccountInfo<'info>, pub spl_token_program: AccountInfo<'info>, @@ -10,14 +10,13 @@ pub struct SplInterfaceConfig<'info> { pub spl_interface_pda_bump: u8, } -/// Check if an account is a Light token account (owned by Light token program) +/// True if owned by Light Token Program. fn is_light_account(account: &AccountInfo) -> bool { account.owner == &Pubkey::new_from_array(LIGHT_TOKEN_PROGRAM_ID) } -/// Transfer tokens between token accounts. -/// For Light-to-Light transfers, uses TransferCheckedCpi with mint validation. -/// For SPL<->Light transfers, uses TransferInterfaceCpi with spl_interface config. +/// Route a token transfer. Both Light Token: `TransferCheckedCpi`. +/// Cross-standard (SPL/Token 2022 to Light Token): `TransferInterfaceCpi`. pub fn transfer_tokens<'info>( amount: u64, decimals: u8, diff --git a/programs/anchor/escrow/src/instructions/take_offer.rs b/programs/anchor/escrow/src/instructions/take_offer.rs index 4f78dd8..60c85a5 100644 --- a/programs/anchor/escrow/src/instructions/take_offer.rs +++ b/programs/anchor/escrow/src/instructions/take_offer.rs @@ -17,7 +17,7 @@ pub struct TakeOffer<'info> { #[account(mut)] pub maker: SystemAccount<'info>, - /// CHECK: Authority PDA for the vault (mutable for close_vault write_top_up) + /// CHECK: Authority PDA (writable for vault close) #[account( mut, seeds = [AUTH_SEED], @@ -71,14 +71,14 @@ pub struct TakeOffer<'info> { pub token_program: Interface<'info, TokenInterface>, pub system_program: Program<'info, System>, - /// Light token program for CPI calls + /// Light Token Program pub light_token_program: Interface<'info, TokenInterface>, - /// CHECK: light-token CPI authority - must be writable for Light token CPI + /// CHECK: Light Token CPI authority #[account(mut)] pub light_token_cpi_authority: AccountInfo<'info>, - /// CHECK: Light token rent sponsor for closing vault + /// CHECK: Light Token rent sponsor #[account(mut, address = LIGHT_TOKEN_RENT_SPONSOR)] pub light_token_rent_sponsor: AccountInfo<'info>, diff --git a/programs/anchor/escrow/tests/escrow.rs b/programs/anchor/escrow/tests/escrow.rs index 1c2fcb4..8c78364 100644 --- a/programs/anchor/escrow/tests/escrow.rs +++ b/programs/anchor/escrow/tests/escrow.rs @@ -1,49 +1,17 @@ -//! Light Token escrow: peer-to-peer token swap with rent-free vault. +//! Escrow tests for 5 token configurations. Vault is always a Light Token account. //! -//! This test shows make/take escrow patterns adapted for Light Token. -//! -//! 1. **Authority PDA owns the vault** — not the offer account. This lets -//! the authority sign vault withdrawals without needing account data -//! (see `make_offer.rs` `#[light_account(init, token::owner = authority)]`). -//! -//! 2. **Vault is rent-free** — it's a Light token account sponsored by -//! `RENT_SPONSOR`, eliminating the ~0.002 SOL rent per escrow. -//! -//! 3. **Validity proof for account creation** — `get_create_accounts_proof()` -//! fetches a validity proof that the offer PDA's derived address does not -//! yet exist in Light's address tree. Only needed in `make_offer` (creating -//! new state); `take_offer` reads existing accounts and needs no proof. -//! -//! ## Token scenarios -//! -//! The vault is always a Light Token account. The user's account type determines -//! which CPI path `transfer_tokens()` in `shared.rs` selects: -//! -//! | Test | Mint | User accounts | Transfer path | Purpose | -//! |------|------|---------------|---------------|---------| -//! | `test_escrow_spl` | SPL | SPL associated token accounts | `TransferInterfaceCpi` | SPL mints work with Light vault | -//! | `test_escrow_t22` | T22 | T22 associated token accounts | `TransferInterfaceCpi` | T22 mints work with Light vault | -//! | `test_escrow_light` | Light | Light associated token accounts | `TransferCheckedCpi` | Rent-free path | -//! | `test_escrow_spl_light` | SPL | Light associated token accounts | `TransferCheckedCpi` | SPL mint, converted user accounts | -//! | `test_escrow_t22_light` | T22 | Light associated token accounts | `TransferCheckedCpi` | T22 mint, converted user accounts | -//! -//! For `Spl`/`Token2022`: user accounts are SPL/T22, vault is Light → cross-standard -//! (`TransferInterfaceCpi` with SPL interface PDA). -//! -//! For `Light`/`LightSpl`/`LightT22`: all accounts are Light → direct -//! (`TransferCheckedCpi`, no interface PDA needed ). -//! -//! `LightSpl`/`LightT22` convert tokens from SPL/T22 associated token accounts -//! into Light token accounts *before* the escrow starts (in `create_token_account`). -//! The escrow itself only sees Light token accounts. -//! -//! ## Cold/hot lifecycle +//! | Test | Mint | User accounts | Transfer path | +//! |------|------|---------------|---------------| +//! | `test_escrow_spl` | SPL | SPL | `TransferInterfaceCpi` | +//! | `test_escrow_t22` | Token 2022 | Token 2022 | `TransferInterfaceCpi` | +//! | `test_escrow_light` | Light Token | Light Token | `TransferCheckedCpi` | +//! | `test_escrow_spl_light` | SPL | Light Token | `TransferCheckedCpi` | +//! | `test_escrow_t22_light` | Token 2022 | Light Token | `TransferCheckedCpi` | //! +//! Each test also exercises the cold/hot lifecycle: //! Light Token accounts auto-compress when sponsored rent expires. Before each -//! transaction, the test loads cold accounts back on-chain via -//! `load_light_accounts`. After account creation, `warp_to_compress` advances -//! slots to trigger compression to simulate the full lifecycle, where the account might turn cold: -//! create → compress → load → transact. +//! transaction, the test loads compressed light token accounts to associated light token accounts via +//! `load_light_accounts`. mod common; @@ -67,68 +35,47 @@ use solana_keypair::Keypair; use solana_pubkey::Pubkey; use solana_signer::Signer; -// ============================================================================ -// Tests — one per token configuration: SPL, T22, Light. -// ============================================================================ - -/// SPL mint with SPL associated token accounts and Light token vault. -/// -/// Every transfer crosses standards (SPL ↔ Light) via `TransferInterfaceCpi` -/// with SPL interface PDAs. This is the baseline: same mint type as standard -/// SPL escrow, but the vault is a rent-free Light token account. +/// SPL mint with SPL associated token accounts and Light Token vault. #[tokio::test] async fn test_escrow_spl() { let mut rpc = create_test_rpc().await; let ctx = setup_escrow_test(&mut rpc, TokenConfig::Spl).await; - run_escrow_full_flow(&mut rpc, &ctx).await; + run_escrow(&mut rpc, &ctx).await; } -/// Token-2022 mint with T22 associated token accounts and Light token vault. -/// -/// Every transfer crosses standards (T22 ↔ Light) via `TransferInterfaceCpi` -/// with SPL interface PDAs. This is the baseline: same mint type as standard -/// SPL escrow, but the vault is a rent-free Light token account. +/// Token 2022 mint with Token 2022 associated token accounts and Light Token vault. + #[tokio::test] async fn test_escrow_t22() { let mut rpc = create_test_rpc().await; let ctx = setup_escrow_test(&mut rpc, TokenConfig::Token2022).await; - run_escrow_full_flow(&mut rpc, &ctx).await; + run_escrow(&mut rpc, &ctx).await; } -/// Light mint + Light user accounts and a rent-free Light token vault. -/// -/// All accounts are Light — transfers use `TransferCheckedCpi`. +/// Light Token mint + Light Token associated accounts and a Light Token vault. #[tokio::test] async fn test_escrow_light() { let mut rpc = create_test_rpc().await; let ctx = setup_escrow_test(&mut rpc, TokenConfig::Light).await; - run_escrow_full_flow(&mut rpc, &ctx).await; + run_escrow(&mut rpc, &ctx).await; } -/// SPL mint + Light user accounts (interop). -/// -/// Tokens start in SPL associated token accounts, get converted into Light -/// token accounts during setup via `transfer_spl_to_light`. Once in Light -/// token accounts, all escrow transfers are Light-to-Light (`TransferCheckedCpi`). -/// Shows that Light token accounts can hold any SPL mint. +/// SPL mint + Light Token user accounts. SPL tokens converted to Light Token +/// associated token accounts in setup via `transfer_spl_to_light`. #[tokio::test] async fn test_escrow_spl_light() { let mut rpc = create_test_rpc().await; let ctx = setup_escrow_test(&mut rpc, TokenConfig::LightSpl).await; - run_escrow_full_flow(&mut rpc, &ctx).await; + run_escrow(&mut rpc, &ctx).await; } -/// Token-2022 mint + Light user accounts (interop). -/// -/// Tokens start in T22 associated token accounts, get converted into Light -/// token accounts during setup via `transfer_spl_to_light`. Once in Light -/// token accounts, all escrow transfers are Light-to-Light (`TransferCheckedCpi`). -/// Shows that Light token accounts can hold any T22 mint. +/// Token 2022 mint + Light Token user accounts. Token 2022 tokens converted to Light Token +/// associated token accounts in setup via `transfer_spl_to_light`. #[tokio::test] async fn test_escrow_t22_light() { let mut rpc = create_test_rpc().await; let ctx = setup_escrow_test(&mut rpc, TokenConfig::LightT22).await; - run_escrow_full_flow(&mut rpc, &ctx).await; + run_escrow(&mut rpc, &ctx).await; } // ============================================================================ @@ -347,7 +294,7 @@ async fn load_light_pdas( /// 2. Make offer: deposit token A into vault, record escrow terms /// 3. Take offer: taker sends token B to maker, vault releases token A to taker /// 4. Verify balances and account closure -async fn run_escrow_full_flow( +async fn run_escrow( rpc: &mut R, ctx: &EscrowTestContext, ) { @@ -469,6 +416,24 @@ async fn run_escrow_full_flow( .await .unwrap(); + // Account order per make_offer.rs MakeOffer: + // [0] fee_payer (signer, writable) maker, pays for offer + vault + // [1] authority (PDA [AUTH_SEED], owns vault) + // [2] compression_config (per-program compression config) + // [3] pda_rent_sponsor (writable) per-program PDA, pays vault rent + // [4] token_mint_a (mint being offered) + // [5] token_mint_b (mint wanted in return) + // [6] maker_token_account_a (writable) maker's token A associated token account + // [7] offer (writable) PDA [OFFER_SEED, maker, id] + // [8] vault (writable) PDA [VAULT_SEED, offer], Light Token account + // [9] token_program (SPL Token or Token 2022) + // [10] system_program + // [11] light_token_program + // [12] light_token_config (LIGHT_TOKEN_CONFIG) + // [13] light_token_rent_sponsor (writable) global Light Token rent sponsor + // [14] light_token_cpi_authority (writable) + // [15] spl_interface_pda_a (bridges SPL/Light, zeroed if all-Light) + // + remaining_accounts: validity proof accounts from get_create_accounts_proof() let accounts = escrow::accounts::MakeOffer { fee_payer: ctx.maker.pubkey(), authority: ctx.authority_pda, @@ -573,6 +538,24 @@ async fn run_escrow_full_flow( // then vault and offer accounts are closed { + // Account order per take_offer.rs TakeOffer: + // [0] taker (signer, writable) + // [1] maker (writable) receives closed offer rent + // [2] authority (writable) PDA [AUTH_SEED], owns vault + // [3] token_mint_a + // [4] token_mint_b + // [5] taker_token_account_a (writable) receives offered tokens from vault + // [6] taker_token_account_b (writable) source of wanted tokens + // [7] maker_token_account_b (writable) receives wanted tokens from taker + // [8] offer (writable) closed after take, rent to maker + // [9] vault (writable) drained + closed + // [10] token_program (SPL Token or Token 2022) + // [11] system_program + // [12] light_token_program + // [13] light_token_cpi_authority (writable) + // [14] light_token_rent_sponsor (writable) + // [15] spl_interface_pda_a (vault to taker, zeroed if all-Light) + // [16] spl_interface_pda_b (taker to maker, zeroed if all-Light) let accounts = escrow::accounts::TakeOffer { taker: ctx.taker.pubkey(), maker: ctx.maker.pubkey(), From fc1f3e6f987fc2b47bf01541d984a4f120b03809 Mon Sep 17 00:00:00 2001 From: tilo-14 Date: Mon, 16 Feb 2026 17:53:04 +0000 Subject: [PATCH 09/10] escorw full --- programs/anchor/escrow/tests/common/mod.rs | 2 +- programs/anchor/escrow/tests/escrow.rs | 116 ++++++++------------- 2 files changed, 46 insertions(+), 72 deletions(-) diff --git a/programs/anchor/escrow/tests/common/mod.rs b/programs/anchor/escrow/tests/common/mod.rs index b3a8875..f49e0ac 100644 --- a/programs/anchor/escrow/tests/common/mod.rs +++ b/programs/anchor/escrow/tests/common/mod.rs @@ -1,7 +1,7 @@ //! Escrow test setup for 5 token standard combinations: SPL, T22, Light. //! //! Each combination varies the mint type and associated token account type while the vault -//! is always a Light token account: +//! is always a Light Token account: //! //! - `Spl` / `Token2022`: standard associated token accounts, cross-standard transfers to Light vault //! - `Light`: native Light token accounts, direct transfers (lowest cost) diff --git a/programs/anchor/escrow/tests/escrow.rs b/programs/anchor/escrow/tests/escrow.rs index 8c78364..9053018 100644 --- a/programs/anchor/escrow/tests/escrow.rs +++ b/programs/anchor/escrow/tests/escrow.rs @@ -10,8 +10,8 @@ //! //! Each test also exercises the cold/hot lifecycle: //! Light Token accounts auto-compress when sponsored rent expires. Before each -//! transaction, the test loads compressed light token accounts to associated light token accounts via -//! `load_light_accounts`. +//! transaction, the test loads cold Light Token accounts to associated Light Token +//! accounts (hot balance) via `load_light_accounts`. mod common; @@ -44,7 +44,6 @@ async fn test_escrow_spl() { } /// Token 2022 mint with Token 2022 associated token accounts and Light Token vault. - #[tokio::test] async fn test_escrow_t22() { let mut rpc = create_test_rpc().await; @@ -52,7 +51,7 @@ async fn test_escrow_t22() { run_escrow(&mut rpc, &ctx).await; } -/// Light Token mint + Light Token associated accounts and a Light Token vault. +/// Light Token mint + Light Token associated accounts and a Light Token vault. #[tokio::test] async fn test_escrow_light() { let mut rpc = create_test_rpc().await; @@ -78,25 +77,28 @@ async fn test_escrow_t22_light() { run_escrow(&mut rpc, &ctx).await; } -// ============================================================================ -// Cold/Hot Lifecycle Helpers -// ============================================================================ - -/// Advance slots past sponsored rent to trigger Light Token account compression. +/// Simulate the cold/hot lifecycle by advancing slots past sponsored rent. /// -/// After this call, Light token accounts with expired rent are cold (compressed). -/// Standard SPL/T22 accounts are unaffected. +/// Light Token accounts may turn cold between transactions. The Light Token +/// Program sponsors rent-exemption; when an account's virtual rent balance +/// drops below threshold, it auto-compresses: account data moves to a +/// state tree and on-chain lookups return `is_initialized: false`. +/// After compressing, the test loads cold accounts back to active state +/// before the next transaction. +/// Standard SPL/Token 2022 accounts are unaffected. async fn warp_to_compress(rpc: &mut R) { rpc.warp_epoch_forward(30) .await .expect("warp_epoch_forward should succeed"); } -/// Load cold (compressed) Light mints back on-chain before transacting. +/// Load cold Light Token mints to active Light Token mint accounts. /// -/// Uses `get_mint_interface` to check hot/cold state, then `decompress_mint` -/// to build decompression instructions. Permissionless — any signer works. -/// No-op for mints that are already hot or non-Light (SPL/T22). +/// Mints compress just like token accounts. Programs can only reference +/// active (hot) mint accounts, so cold mints must be loaded before any +/// instruction that reads mint data (decimals, supply, authority). +/// Mint loading does not require a specific signer, unlike token account loading. +/// No-op for mints that are already active or non-Light (SPL/Token 2022). async fn load_light_mints( rpc: &mut R, payer: &Keypair, @@ -129,17 +131,11 @@ async fn load_light_mints( } } -/// Load cold (compressed) Light token accounts before next transaction. -/// -/// Accepts the wallet `owner` keypair and a list of mints. For each mint, -/// `get_ata_interface(owner, mint)` resolves the ATA and checks if it's cold. -/// Cold accounts are loaded via `create_load_instructions` which builds -/// `CreateAssociatedTokenAccount` + `Transfer2` instructions to decompress. -/// -/// The owner keypair signs the load transaction — `Transfer2` requires the -/// wallet owner to authorize decompression of their token accounts. +/// Load cold Light Token accounts to associated Light Token accounts (hot balance). /// -/// No-op for accounts that are already hot or non-Light (SPL/T22). +/// Unlike mint loading, token account loading requires the wallet owner +/// to sign because the underlying transfer treats loading as an owner-authorized +/// operation. No-op for accounts that are already hot or non-Light (SPL/Token 2022). async fn load_light_accounts( rpc: &mut R, payer: &Keypair, @@ -182,17 +178,13 @@ async fn load_light_accounts( } } -/// Load cold (compressed) program-owned Light accounts (offer + vault) back on-chain. +/// Load cold program-owned Light accounts (offer + vault) to active state. /// -/// The offer PDA uses `get_account_interface` to fetch cold state, deserializes -/// `Offer` from account data, and wraps it in `LightAccountVariant::Offer`. -/// -/// The vault uses `get_token_account_interface` to fetch cold state, deserializes -/// `Token` from account data, and wraps it in `LightAccountVariant::Vault`. -/// The vault's `ColdContext::Token` is converted to `ColdContext::Account` for `PdaSpec`. -/// -/// The maker must sign because the offer's `Pack` includes `fee_payer` (= maker) -/// as a signer account. No-op if both accounts are already hot. +/// Program-owned PDAs require more setup than associated token accounts: +/// each account's variant enum and seed struct must be reconstructed from +/// its serialized state so `create_load_instructions` can verify ownership. +/// The maker must sign because the offer seeds include `fee_payer` (= maker). +/// No-op if both accounts are already active. async fn load_light_pdas( rpc: &mut R, payer: &Keypair, @@ -230,7 +222,7 @@ async fn load_light_pdas( _ => {} } - // Vault: Light token account (PDA-owned by authority) + // Vault: Light Token account (PDA-owned by authority) match rpc.get_token_account_interface(&vault_pda, None).await { Ok(response) => { if let Some(iface) = response.value { @@ -284,27 +276,23 @@ async fn load_light_pdas( } } -// ============================================================================ -// Full Flow -// ============================================================================ - -/// Run the full escrow flow for any token configuration: SPL, T22, Light. +/// Run the full escrow flow for any token configuration: SPL, Token 2022, or Light. /// -/// 1. Create token accounts (SPL, T22 or Light depends on `TokenConfig` — see `create_token_account`) -/// 2. Make offer: deposit token A into vault, record escrow terms -/// 3. Take offer: taker sends token B to maker, vault releases token A to taker -/// 4. Verify balances and account closure +/// 1. Create token accounts per `TokenConfig` (see `create_token_account`) +/// 2. Compress and load all accounts to active state (simulates cold/hot lifecycle) +/// 3. Make offer: deposit token A into vault, record escrow terms +/// 4. Compress and load again before take (includes program-owned PDAs) +/// 5. Take offer: taker sends token B to maker, vault releases token A to taker +/// 6. Verify balances and account closure async fn run_escrow( rpc: &mut R, ctx: &EscrowTestContext, ) { - // ==================== PHASE 1: Define Escrow Terms ==================== // Maker offers 1 token A, wants 0.5 token B in return let token_a_offered = 1_000_000_000u64; // 1 token (9 decimals) let token_b_wanted = 500_000_000u64; // 0.5 tokens let offer_id = 1u64; - // ==================== PHASE 2: Create Token Accounts ==================== // Maker needs: funded token A account, empty token B account (receives payment) // Taker needs: empty token A account (receives offered tokens), funded token B account @@ -352,7 +340,6 @@ async fn run_escrow( ) .await; - // ==================== PHASE 3: Verify Initial State ==================== verify_light_token_balance(rpc, maker_token_a, token_a_offered, "maker_token_a (initial)") .await; verify_light_token_balance(rpc, maker_token_b, 0, "maker_token_b (initial)").await; @@ -360,19 +347,14 @@ async fn run_escrow( verify_light_token_balance(rpc, taker_token_b, token_b_wanted, "taker_token_b (initial)") .await; - // ==================== PHASE 3.5: Compress → Load ==================== - // Advance slots past sponsored rent to trigger compression. - // Light token accounts become cold (compressed). Standard SPL/T22 accounts - // are unaffected (warp + load is a no-op for non-Light configs). + // Simulate hot-cold lifecycle. No-op for non-Light configs. warp_to_compress(rpc).await; - // Load cold mints back on-chain (Light config only — SPL/T22 mints don't compress). + // Load cold mints to active Light Token mint accounts. No-op for SPL/Token 2022. load_light_mints(rpc, &ctx.payer, &[ctx.mint_a_pubkey, ctx.mint_b_pubkey]).await; - // Load cold token accounts back on-chain before make_offer. - // For Light configs: decompresses maker_token_a (has balance to deposit). - // For SPL/T22 configs: no-op (standard ATAs don't compress). - // Loads are per-owner because Transfer2 requires the wallet owner to sign. + // Load cold token accounts to associated Light Token accounts (hot balance). + // Per-owner because Transfer2 requires wallet-owner authorization. load_light_accounts( rpc, &ctx.payer, @@ -388,7 +370,6 @@ async fn run_escrow( ) .await; - // ==================== PHASE 4: Make Offer ==================== // Transfers token A from maker to vault, creates offer account with escrow terms let (offer_pda, vault_pda, _) = { @@ -407,7 +388,7 @@ async fn run_escrow( ); // Validity proof: verifies that the offer PDA's derived address does not - // yet exist in Light's address tree. Required for any new Light Token mint. + // yet exist in the address tree. Required for Light Token account creation. let proof_result = get_create_accounts_proof( rpc, &ctx.program_id, @@ -467,10 +448,8 @@ async fn run_escrow( }, }; - // Light system accounts (registered program PDA, noop, account compression - // authority, output state tree queue, address tree) are appended as - // remaining_accounts. The Light system program reads these during CPI - // to verify the proof and insert the new address. + // Remaining accounts: Light system accounts for proof verification + // and address tree insertion (see `get_create_accounts_proof`). let ix = Instruction { program_id: ctx.program_id, accounts: [ @@ -488,8 +467,6 @@ async fn run_escrow( (offer_pda, vault_pda, vault_bump) }; - // ==================== PHASE 5: Verify Offer State ==================== - // Vault should hold offered tokens, maker's account should be empty verify_light_token_balance(rpc, vault_pda, token_a_offered, "vault (after make_offer)").await; verify_light_token_balance(rpc, maker_token_a, 0, "maker_token_a (after make_offer)").await; @@ -503,9 +480,9 @@ async fn run_escrow( "Offer account should have data" ); - // ==================== PHASE 5.5: Compress → Load Before Take ==================== - // Advance slots to trigger compression, then load accounts before take_offer. - // Vault and offer are program-owned (not ATAs), loaded separately below. + // Simulate hot-cold lifecycle before take_offer. + // Compress and load all accounts to active state + // Vault and offer are program-owned (not associated token accounts), loaded separately. warp_to_compress(rpc).await; load_light_mints(rpc, &ctx.payer, &[ctx.mint_a_pubkey, ctx.mint_b_pubkey]).await; load_light_pdas( @@ -533,7 +510,6 @@ async fn run_escrow( ) .await; - // ==================== PHASE 6: Take Offer ==================== // Taker sends wanted tokens (B) to maker, vault releases offered tokens (A) to taker, // then vault and offer accounts are closed @@ -597,7 +573,6 @@ async fn run_escrow( .expect("take_offer should succeed"); } - // ==================== PHASE 7: Verify Final State ==================== // Maker: gave token A, received token B // Taker: gave token B, received token A @@ -607,7 +582,6 @@ async fn run_escrow( .await; verify_light_token_balance(rpc, taker_token_b, 0, "taker_token_b (final)").await; - // Verify offer account was closed let offer_after = rpc.get_account(offer_pda).await.unwrap(); assert!( offer_after.is_none(), From 39bd4a70e4fc7756b6e5e67d2f1129e9272ad1df Mon Sep 17 00:00:00 2001 From: tilo-14 Date: Mon, 16 Feb 2026 18:44:43 +0000 Subject: [PATCH 10/10] all comments --- programs/anchor/escrow/tests/common/mod.rs | 56 +++++------ .../anchor/fundraiser/tests/common/mod.rs | 49 +++++----- .../anchor/fundraiser/tests/fundraiser.rs | 84 +++++++--------- .../light-token-minter/tests/minter_test.rs | 70 +------------- .../anchor/token-swap/tests/common/mod.rs | 89 ++++++++--------- programs/anchor/token-swap/tests/swap.rs | 96 ++++++++----------- 6 files changed, 164 insertions(+), 280 deletions(-) diff --git a/programs/anchor/escrow/tests/common/mod.rs b/programs/anchor/escrow/tests/common/mod.rs index f49e0ac..29fff49 100644 --- a/programs/anchor/escrow/tests/common/mod.rs +++ b/programs/anchor/escrow/tests/common/mod.rs @@ -3,11 +3,11 @@ //! Each combination varies the mint type and associated token account type while the vault //! is always a Light Token account: //! -//! - `Spl` / `Token2022`: standard associated token accounts, cross-standard transfers to Light vault -//! - `Light`: native Light token accounts, direct transfers (lowest cost) -//! - `LightSpl` / `LightT22`: SPL/T22 mints converted into Light token accounts before +//! - `Spl` / `Token2022`: standard associated token accounts, transfers via `TransferInterfaceCpi` +//! - `Light`: Light Token accounts, transfers via `TransferCheckedCpi` +//! - `LightSpl` / `LightT22`: SPL/Token 2022 mints converted into Light Token accounts before //! the escrow starts (tokens are minted to a temp associated token account, then -//! transferred to a Light associated token account via `transfer_spl_to_light`) +//! transferred to an associated Light Token account via `transfer_spl_to_light`) //! //! ## Setup flow //! @@ -41,25 +41,23 @@ use solana_signer::Signer; /// Token configuration for parameterized escrow tests. /// /// Each variant determines the mint type and user account type. The vault is -/// always a Light token account (rent-free). The user account type controls +/// always a Light Token account (rent-free). The user account type controls /// which CPI path `transfer_tokens()` selects at runtime: /// -/// - SPL/T22 user accounts → `TransferInterfaceCpi` (cross-standard, needs interface PDA) -/// - Light user accounts → `TransferCheckedCpi` (direct, no interface PDA) +/// - SPL/Token 2022 user accounts → `TransferInterfaceCpi` (needs interface PDA) +/// - Light user accounts → `TransferCheckedCpi` (no interface PDA) #[allow(dead_code)] #[derive(Clone, Copy, Debug)] pub enum TokenConfig { - /// SPL mint + SPL associated token accounts. Transfers cross standards (SPL ↔ Light vault). + /// SPL mint + SPL associated token accounts and Light Token vault. Spl, - /// T22 mint + T22 associated token accounts. Transfers cross standards (T22 ↔ Light vault). + /// Token 2022 mint + Token 2022 associated token accounts and Light Token vault. Token2022, - /// SPL mint + Light associated token accounts. Tokens converted from SPL associated token accounts in setup. - /// During escrow, all transfers are Light-to-Light. + /// SPL mint + associated Light Token accounts. Tokens converted from SPL associated token accounts in setup. LightSpl, - /// T22 mint + Light associated token accounts. Tokens converted from T22 associated token accounts in setup. - /// During escrow, all transfers are Light-to-Light. + /// Token 2022 mint + associated Light Token accounts. Tokens converted from Token 2022 associated token accounts in setup. LightT22, - /// Light mint + Light associated token accounts. Pure Light — lowest cost, no bridging. + /// Light Token mint + associated Light Token accounts and Light Token vault. Light, } @@ -83,12 +81,12 @@ impl TokenConfig { } } - /// Returns true if mints are Light Protocol mints (not SPL/T22) + /// Returns true if mints are Light Token mints (not SPL/Token 2022) pub fn uses_light_mints(&self) -> bool { matches!(self, TokenConfig::Light) } - /// Returns true if user accounts are Light token accounts + /// Returns true if user accounts are Light Token accounts pub fn uses_light_accounts(&self) -> bool { matches!( self, @@ -149,10 +147,10 @@ pub async fn create_test_rpc() -> LightProgramTest { /// Initialize mints, interface PDAs, and participants for a given token config. /// -/// SPL interface PDAs are created for all SPL/T22 configs (including `Spl` and +/// SPL interface PDAs are created for all SPL/Token 2022 configs (including `Spl` and /// `Token2022`, not just `LightSpl`/`LightT22`) because the vault is always a -/// Light token account — any transfer involving an SPL/T22 account and the Light -/// vault crosses standards and requires an interface PDA. +/// Light Token account — `TransferInterfaceCpi` needs the interface PDA when an +/// SPL/Token 2022 account transfers to a Light Token vault. /// /// For `Light` config, no interface PDAs are created (early return). pub async fn setup_escrow_test( @@ -162,10 +160,8 @@ pub async fn setup_escrow_test( let program_id = escrow::ID; let payer = rpc.get_payer().insecure_clone(); - // Initialize rent-free config (returns config PDA + per-program rent sponsor PDA) let (compression_config, rent_sponsor) = initialize_rent_free_config(rpc, &payer, &program_id).await; - // Create maker and taker let maker = Keypair::new(); let taker = Keypair::new(); rpc.airdrop_lamports(&maker.pubkey(), 10_000_000_000) @@ -175,14 +171,10 @@ pub async fn setup_escrow_test( .await .unwrap(); - // Derive authority PDA let (authority_pda, _) = Pubkey::find_program_address(&[escrow::AUTH_SEED], &program_id); if config.uses_light_mints() { - // ========== LIGHT MINT SETUP ========== - println!("\n=== Setting up Light mints ==="); - let light_mint_a = create_light_mint( rpc, &payer, @@ -221,7 +213,7 @@ pub async fn setup_escrow_test( }; } - // ========== SPL/T22 MINT SETUP ========== + // ========== SPL/TOKEN 2022 MINT SETUP ========== let (mint_a, mint_b) = match config { TokenConfig::Spl | TokenConfig::LightSpl => { let a = create_spl_mint(rpc, &payer, &payer.pubkey(), 9).await; @@ -239,7 +231,7 @@ pub async fn setup_escrow_test( let mint_a_pubkey = mint_a.pubkey(); let mint_b_pubkey = mint_b.pubkey(); - // Create SPL interface PDAs for all SPL/T22 configs (needed for TransferInterfaceCpi) + // Required for `TransferInterfaceCpi` between SPL/Token 2022 accounts and Light Token vault. let iface_a = create_spl_interface_pda( rpc, &payer, @@ -284,10 +276,10 @@ pub async fn setup_escrow_test( /// /// Account creation varies by config: /// - `Spl` / `Token2022`: create standard associated token account, mint directly -/// - `Light`: create Light associated token account via `mint_light_tokens` (creates + mints in one call) -/// - `LightSpl` / `LightT22`: create temp SPL/T22 associated token account → mint → -/// create Light associated token account → convert via `transfer_spl_to_light`. -/// If unfunded, just creates the Light associated token account. +/// - `Light`: create associated Light Token account via `mint_light_tokens` (creates + mints in one call) +/// - `LightSpl` / `LightT22`: create temporary SPL/Token 2022 associated token account → mint → +/// create associated Light Token account → convert via `transfer_spl_to_light`. +/// If unfunded, just creates the associated Light Token account. pub async fn create_token_account( rpc: &mut R, ctx: &EscrowTestContext, @@ -316,7 +308,6 @@ pub async fn create_token_account( } TokenConfig::LightSpl => { if funding_amount > 0 { - // Create temp SPL ATA, mint, create Light ATA, transfer let temp_ata = create_spl_ata(rpc, &ctx.payer, mint_pubkey, &owner.pubkey()).await; mint_spl_tokens( @@ -395,7 +386,6 @@ pub async fn create_token_account( let mint_authority = light_mint_authority.expect("Light config requires mint authority"); if funding_amount > 0 { - // mint_light_tokens creates ATA and mints in one call mint_light_tokens( rpc, &ctx.payer, diff --git a/programs/anchor/fundraiser/tests/common/mod.rs b/programs/anchor/fundraiser/tests/common/mod.rs index 50ad681..e6fb6cf 100644 --- a/programs/anchor/fundraiser/tests/common/mod.rs +++ b/programs/anchor/fundraiser/tests/common/mod.rs @@ -1,13 +1,13 @@ -//! Fundraiser test setup for 5 token standard combinations: SPL, T22, Light. +//! Fundraiser test setup for 5 token standard combinations: SPL, Token 2022, Light. //! //! Each combination varies the mint type and contributor account type while the vault -//! is always a Light token account: +//! is always a Light Token account: //! -//! - `Spl` / `Token2022`: standard associated token accounts, cross-standard transfers to Light vault -//! - `Light`: native Light token accounts, direct transfers (lowest cost) -//! - `LightSpl` / `LightT22`: SPL/T22 mints converted into Light token accounts before -//! the fundraiser starts (tokens are minted to a temp associated token account, then -//! transferred to a Light associated token account via `transfer_spl_to_light`) +//! - `Spl` / `Token2022`: standard associated token accounts, transfers via `TransferInterfaceCpi` +//! - `Light`: Light Token accounts, transfers via `TransferCheckedCpi` +//! - `LightSpl` / `LightT22`: SPL/Token 2022 mints converted into Light Token accounts before +//! the fundraiser starts (tokens are minted to a temporary associated token account, then +//! transferred to an associated Light Token account via `transfer_spl_to_light`) //! //! ## Setup flow //! @@ -41,25 +41,25 @@ use solana_signer::Signer; /// Token configuration for parameterized fundraiser tests. /// /// Each variant determines the mint type and contributor account type. The vault is -/// always a Light token account (rent-free). The contributor account type controls +/// always a Light Token account (rent-free). The contributor account type controls /// which CPI path `transfer_tokens()` selects at runtime: /// -/// - SPL/T22 contributor accounts → `TransferInterfaceCpi` (cross-standard, needs interface PDA) -/// - Light contributor accounts → `TransferCheckedCpi` (direct, no interface PDA) +/// - SPL/Token 2022 contributor accounts → `TransferInterfaceCpi` (needs interface PDA) +/// - Light contributor accounts → `TransferCheckedCpi` (no interface PDA) #[allow(dead_code)] #[derive(Clone, Copy, Debug)] pub enum TokenConfig { - /// SPL mint + SPL associated token accounts. Transfers cross standards (SPL ↔ Light vault). + /// SPL mint + SPL associated token accounts and Light Token vault. Spl, - /// T22 mint + T22 associated token accounts. Transfers cross standards (T22 ↔ Light vault). + /// Token 2022 mint + Token 2022 associated token accounts and Light Token vault. Token2022, - /// SPL mint + Light associated token accounts. Tokens converted from SPL associated token accounts in setup. + /// SPL mint + associated Light Token accounts. Tokens converted from SPL associated token accounts in setup. /// During fundraiser, all transfers are Light-to-Light. LightSpl, - /// T22 mint + Light associated token accounts. Tokens converted from T22 associated token accounts in setup. + /// Token 2022 mint + associated Light Token accounts. Tokens converted from Token 2022 associated token accounts in setup. /// During fundraiser, all transfers are Light-to-Light. LightT22, - /// Light mint + Light associated token accounts. Pure Light — lowest cost, no bridging. + /// Light Token mint + associated Light Token accounts and Light Token vault. Light, } @@ -83,7 +83,7 @@ impl TokenConfig { } } - /// Returns true if mints are Light Protocol mints (not SPL/T22) + /// Returns true if mints are Light Token mints (not SPL/Token 2022) pub fn uses_light_mints(&self) -> bool { matches!(self, TokenConfig::Light) } @@ -145,8 +145,8 @@ pub async fn create_test_rpc() -> LightProgramTest { /// /// SPL interface PDAs are created for all SPL/T22 configs (including `Spl` and /// `Token2022`, not just `LightSpl`/`LightT22`) because the vault is always a -/// Light token account — any transfer involving an SPL/T22 account and the Light -/// vault crosses standards and requires an interface PDA. +/// Light Token account — `TransferInterfaceCpi` needs the interface PDA when an +/// SPL/Token 2022 account transfers to a Light Token vault. /// /// For `Light` config, no interface PDA is created (early return). /// @@ -160,24 +160,19 @@ pub async fn setup_fundraiser_test( let program_id = fundraiser::ID; let payer = rpc.get_payer().insecure_clone(); - // Initialize rent-free config (returns config PDA + per-program rent sponsor PDA) let (compression_config, rent_sponsor) = initialize_rent_free_config(rpc, &payer, &program_id).await; - // Create maker let maker = Keypair::new(); rpc.airdrop_lamports(&maker.pubkey(), 10_000_000_000) .await .unwrap(); - // Fundraiser terms let amount_to_raise = 1_000_000_000_000u64; // 1000 tokens (9 decimals) let duration = duration_override.unwrap_or(7u16); - // Derive authority PDA (used by vault operations) let (authority_pda, _) = Pubkey::find_program_address(&[b"authority"], &program_id); - // Derive fundraiser and vault PDAs let (fundraiser_pda, _) = Pubkey::find_program_address(&[b"fundraiser", maker.pubkey().as_ref()], &program_id); @@ -230,7 +225,7 @@ pub async fn setup_fundraiser_test( let mint_pubkey = mint.pubkey(); - // Create SPL interface PDA (needed for cross-standard transfers to Light vault) + // Required for `TransferInterfaceCpi` between SPL/Token 2022 and Light Token vault. let iface = create_spl_interface_pda(rpc, &payer, &mint_pubkey, config.mint_type(), false).await; @@ -261,9 +256,9 @@ pub async fn setup_fundraiser_test( /// /// Account creation varies by config: /// - `Spl` / `Token2022`: create standard associated token account, mint directly -/// - `Light`: create Light associated token account via `mint_light_tokens` (creates + mints in one call) -/// - `LightSpl` / `LightT22`: create temp SPL/T22 associated token account → mint → -/// create Light associated token account → convert via `transfer_spl_to_light`. +/// - `Light`: create associated Light Token account via `mint_light_tokens` (creates + mints in one call) +/// - `LightSpl` / `LightT22`: create temporary SPL/Token 2022 associated token account → mint → +/// create associated Light Token account → convert via `transfer_spl_to_light`. pub async fn create_contributor( rpc: &mut R, ctx: &FundraiserTestContext, diff --git a/programs/anchor/fundraiser/tests/fundraiser.rs b/programs/anchor/fundraiser/tests/fundraiser.rs index ceb18d3..6a97c02 100644 --- a/programs/anchor/fundraiser/tests/fundraiser.rs +++ b/programs/anchor/fundraiser/tests/fundraiser.rs @@ -6,7 +6,7 @@ //! the authority sign vault withdrawals without needing account data //! (see `initialize.rs` `#[light_account(init, token::owner = authority)]`). //! -//! 2. **Vault is rent-free** — it's a Light token account sponsored by +//! 2. **Vault is rent-free** — it's a Light Token account sponsored by //! `RENT_SPONSOR`, eliminating the ~0.002 SOL rent per fundraiser. //! //! 3. **Validity proof for account creation** — `get_create_accounts_proof()` @@ -23,25 +23,25 @@ //! | Test | Mint | Contributor accounts | Transfer path | Purpose | //! |------|------|---------------------|---------------|---------| //! | `test_fundraiser_spl` | SPL | SPL associated token accounts | `TransferInterfaceCpi` | SPL mints work with Light vault | -//! | `test_fundraiser_t22` | T22 | T22 associated token accounts | `TransferInterfaceCpi` | T22 mints work with Light vault | -//! | `test_fundraiser_light` | Light | Light associated token accounts | `TransferCheckedCpi` | Rent-free path | -//! | `test_fundraiser_spl_light` | SPL | Light associated token accounts | `TransferCheckedCpi` | SPL mint, converted contributor accounts | -//! | `test_fundraiser_t22_light` | T22 | Light associated token accounts | `TransferCheckedCpi` | T22 mint, converted contributor accounts | +//! | `test_fundraiser_t22` | Token 2022 | Token 2022 associated token accounts | `TransferInterfaceCpi` | Token 2022 mints work with Light vault | +//! | `test_fundraiser_light` | Light | Associated Light Token accounts | `TransferCheckedCpi` | Rent-free path | +//! | `test_fundraiser_spl_light` | SPL | Associated Light Token accounts | `TransferCheckedCpi` | SPL mint, converted contributor accounts | +//! | `test_fundraiser_t22_light` | Token 2022 | Associated Light Token accounts | `TransferCheckedCpi` | Token 2022 mint, converted contributor accounts | //! -//! For `Spl`/`Token2022`: contributor accounts are SPL/T22, vault is Light → cross-standard -//! (`TransferInterfaceCpi` with SPL interface PDA). +//! For `Spl`/`Token2022`: contributor accounts are SPL/Token 2022, vault is Light → +//! `TransferInterfaceCpi` (with SPL interface PDA). //! -//! For `Light`/`LightSpl`/`LightT22`: all accounts are Light → direct -//! (`TransferCheckedCpi`, no interface PDA needed). +//! For `Light`/`LightSpl`/`LightT22`: all accounts are Light Token → +//! `TransferCheckedCpi` (no interface PDA needed). //! -//! `LightSpl`/`LightT22` convert tokens from SPL/T22 associated token accounts -//! into Light token accounts *before* the fundraiser starts (in `create_contributor`). -//! The fundraiser itself only sees Light token accounts. +//! `LightSpl`/`LightT22` convert tokens from SPL/Token 2022 associated token accounts +//! into associated Light Token accounts *before* the fundraiser starts (in `create_contributor`). +//! The fundraiser itself only sees Light Token accounts. //! //! ## Cold/hot lifecycle //! -//! The vault is a PDA-owned Light token account that auto-compresses when -//! sponsored rent expires. Loading a compressed vault from cold requires +//! The vault is a PDA-owned Light Token account that turns cold when +//! sponsored rent expires. Loading a cold vault back to active requires //! `VaultSeeds` / `LightAccountVariant::Vault` (generated by `#[light_program]` //! when state derives `LightAccount`). Since `Fundraiser` uses standard //! `#[account]`, these types aren't generated, so the test doesn't exercise @@ -68,14 +68,14 @@ use solana_pubkey::Pubkey; use solana_signer::Signer; // ============================================================================ -// Tests — one per token configuration: SPL, T22, Light + 1 refund test. +// Tests — one per token configuration: SPL, Token 2022, Light + 1 refund test. // ============================================================================ -/// SPL mint with SPL associated token accounts and Light token vault. +/// SPL mint with SPL associated token accounts and Light Token vault. /// -/// Every transfer crosses standards (SPL ↔ Light) via `TransferInterfaceCpi` +/// All transfers use `TransferInterfaceCpi` (SPL ↔ Light Token vault) /// with SPL interface PDAs. This is the baseline: same mint type as standard -/// SPL fundraiser, but the vault is a rent-free Light token account. +/// SPL fundraiser, but the vault is a rent-free Light Token account. #[tokio::test] async fn test_fundraiser_spl() { let mut rpc = create_test_rpc().await; @@ -83,9 +83,9 @@ async fn test_fundraiser_spl() { run_fundraiser_full_flow(&mut rpc, &ctx).await; } -/// Token-2022 mint with T22 associated token accounts and Light token vault. +/// Token 2022 mint with Token 2022 associated token accounts and Light Token vault. /// -/// Every transfer crosses standards (T22 ↔ Light) via `TransferInterfaceCpi` +/// All transfers use `TransferInterfaceCpi` (Token 2022 ↔ Light Token vault) /// with SPL interface PDAs. #[tokio::test] async fn test_fundraiser_t22() { @@ -94,9 +94,9 @@ async fn test_fundraiser_t22() { run_fundraiser_full_flow(&mut rpc, &ctx).await; } -/// Light mint + Light contributor accounts and a rent-free Light token vault. +/// Light Token mint + Light Token contributor accounts and Light Token vault. /// -/// All accounts are Light — transfers use `TransferCheckedCpi`. +/// All transfers use `TransferCheckedCpi`. #[tokio::test] async fn test_fundraiser_light() { let mut rpc = create_test_rpc().await; @@ -104,12 +104,10 @@ async fn test_fundraiser_light() { run_fundraiser_full_flow(&mut rpc, &ctx).await; } -/// SPL mint + Light contributor accounts (interop). +/// SPL mint + Light Token contributor accounts. SPL tokens converted to associated +/// Light Token accounts in setup via `transfer_spl_to_light`. /// -/// Tokens start in SPL associated token accounts, get converted into Light -/// token accounts during setup via `transfer_spl_to_light`. Once in Light -/// token accounts, all fundraiser transfers are Light-to-Light (`TransferCheckedCpi`). -/// Shows that Light token accounts can hold any SPL mint. +/// All transfers use `TransferCheckedCpi`. #[tokio::test] async fn test_fundraiser_spl_light() { let mut rpc = create_test_rpc().await; @@ -117,12 +115,10 @@ async fn test_fundraiser_spl_light() { run_fundraiser_full_flow(&mut rpc, &ctx).await; } -/// Token-2022 mint + Light contributor accounts (interop). +/// Token 2022 mint + Light Token contributor accounts. Token 2022 tokens converted to +/// associated Light Token accounts in setup via `transfer_spl_to_light`. /// -/// Tokens start in T22 associated token accounts, get converted into Light -/// token accounts during setup via `transfer_spl_to_light`. Once in Light -/// token accounts, all fundraiser transfers are Light-to-Light (`TransferCheckedCpi`). -/// Shows that Light token accounts can hold any T22 mint. +/// All transfers use `TransferCheckedCpi`. #[tokio::test] async fn test_fundraiser_t22_light() { let mut rpc = create_test_rpc().await; @@ -130,7 +126,7 @@ async fn test_fundraiser_t22_light() { run_fundraiser_full_flow(&mut rpc, &ctx).await; } -/// Light mint refund flow: deadline passes, target not met, contributors refund. +/// Light Token mint refund flow: deadline passes, target not met, contributors refund. /// /// Uses `duration: 1` (1 day) to minimize warp time. Only 3 contributors /// contribute (30% of target), so the target is not met. After advancing @@ -146,7 +142,7 @@ async fn test_fundraiser_refund() { // Full Flow — Claim // ============================================================================ -/// Run the full fundraiser claim flow for any token configuration: SPL, T22, Light. +/// Run the full fundraiser claim flow for any token configuration: SPL, Token 2022, Light. /// /// 1. Initialize fundraiser: create vault, record terms /// 2. Verify vault has 0 balance @@ -159,7 +155,6 @@ async fn run_fundraiser_full_flow( ctx: &FundraiserTestContext, ) { // ==================== PHASE 1: Initialize Fundraiser ==================== - // Create vault, record fundraiser terms (amount, duration, maker) { // Validity proof: verifies that the vault PDA's derived address does not // yet exist in Light's address tree. @@ -194,10 +189,8 @@ async fn run_fundraiser_full_flow( }, }; - // Light system accounts (registered program PDA, noop, account compression - // authority, output state tree queue, address tree) are appended as - // remaining_accounts. The Light system program reads these during CPI - // to verify the proof and insert the new address. + // Remaining accounts: Light system accounts for proof verification + // and address tree insertion (see `get_create_accounts_proof`). let ix = Instruction { program_id: ctx.program_id, accounts: [ @@ -221,7 +214,6 @@ async fn run_fundraiser_full_flow( verify_light_token_balance(rpc, ctx.vault_pda, 0, "vault (initial)").await; // ==================== PHASE 3: Contribute (10x) ==================== - // 10 contributors each contribute 10% of target = 100% total let contribution_amount = ctx.amount_to_raise * 10 / 100; let contributor_funding = contribution_amount * 2; // extra for fees @@ -229,7 +221,6 @@ async fn run_fundraiser_full_flow( let (contributor, contributor_ata) = create_contributor(rpc, ctx, contributor_funding).await; - // Derive contributor account PDA let (contributor_account_pda, _) = Pubkey::find_program_address( &[ b"contributor", @@ -339,10 +330,8 @@ async fn run_fundraiser_full_flow( }; // ==================== PHASE 6: Verify Final State ==================== - // Vault should be empty verify_light_token_balance(rpc, ctx.vault_pda, 0, "vault (after claim)").await; - // Maker should have received all raised funds verify_light_token_balance( rpc, maker_ata, @@ -351,7 +340,6 @@ async fn run_fundraiser_full_flow( ) .await; - // Fundraiser account should be closed let fundraiser_account = rpc.get_account(ctx.fundraiser_pda).await.unwrap(); assert!( fundraiser_account.is_none(), @@ -429,7 +417,6 @@ async fn run_fundraiser_refund_flow( verify_light_token_balance(rpc, ctx.vault_pda, 0, "vault (initial)").await; // ==================== PHASE 2: Partial Contributions (30%) ==================== - // 3 contributors at 10% each — target will not be met let contribution_amount = ctx.amount_to_raise * 10 / 100; let contributor_funding = contribution_amount * 2; let num_contributors = 3; @@ -495,8 +482,8 @@ async fn run_fundraiser_refund_flow( // Advance the Clock sysvar's unix_timestamp directly — `warp_epoch_forward` // only updates the slot, not unix_timestamp, in LiteSVM. // - // We don't warp slots here because `warp_epoch_forward` compresses all Light - // accounts (vault, mints, contributor ATAs), and the fundraiser can't load + // We don't warp slots here because `warp_epoch_forward` turns all Light + // accounts cold (vault, mints, contributor token accounts), and the fundraiser can't load // the vault from cold: `Fundraiser` doesn't derive `LightAccount`, so // `#[light_program]` doesn't generate `VaultSeeds` / `LightAccountVariant::Vault` // needed by `create_load_instructions`. @@ -568,7 +555,6 @@ async fn run_fundraiser_refund_flow( ) .await; - // Verify contributor_account PDA was closed let contributor_acct = rpc.get_account(contributor_account_pda).await.unwrap(); assert!( contributor_acct.is_none(), @@ -577,10 +563,8 @@ async fn run_fundraiser_refund_flow( } // ==================== PHASE 5: Verify Final State ==================== - // Vault should be empty verify_light_token_balance(rpc, ctx.vault_pda, 0, "vault (after all refunds)").await; - // Fundraiser account should still exist (not closed by refund) let fundraiser_account = rpc.get_account(ctx.fundraiser_pda).await.unwrap(); assert!( fundraiser_account.is_some(), diff --git a/programs/anchor/light-token-minter/tests/minter_test.rs b/programs/anchor/light-token-minter/tests/minter_test.rs index 0d772bb..786292f 100644 --- a/programs/anchor/light-token-minter/tests/minter_test.rs +++ b/programs/anchor/light-token-minter/tests/minter_test.rs @@ -1,4 +1,4 @@ -//! Integration tests for Light mint creation using #[light_account(init, mint)] macro. +//! Integration tests for Light Token mint creation using #[light_account(init, mint)] macro. use anchor_lang::{InstructionData, ToAccountMetas}; use light_account::derive_rent_sponsor_pda; @@ -19,7 +19,7 @@ use solana_keypair::Keypair; use solana_pubkey::Pubkey; use solana_signer::Signer; -/// Test creating a Light mint using the #[light_account(init, mint)] macro. +/// Test creating a Light Token mint using the #[light_account(init, mint)] macro. #[tokio::test] async fn test_create_light_mint() { let program_id = light_token_minter::ID; @@ -30,13 +30,10 @@ async fn test_create_light_mint() { let mut rpc = LightProgramTest::new(config).await.unwrap(); let payer = rpc.get_payer().insecure_clone(); - // Setup program data for rent-free config let program_data_pda = setup_mock_program_data(&mut rpc, &payer, &program_id); - // Derive per-program rent sponsor PDA let (rent_sponsor, _) = derive_rent_sponsor_pda(&program_id); - // Initialize rent-free config let (init_config_ix, config_pda) = InitializeRentFreeConfig::new( &program_id, &payer.pubkey(), @@ -50,10 +47,8 @@ async fn test_create_light_mint() { .await .expect("Initialize config should succeed"); - // Authority keypair (mint authority) let authority = Keypair::new(); - // Derive mint signer PDA let (mint_signer_pda, mint_signer_bump) = Pubkey::find_program_address( &[ light_token_minter::MINT_SIGNER_SEED, @@ -62,10 +57,8 @@ async fn test_create_light_mint() { &program_id, ); - // Derive mint PDA from mint signer let (light_mint_pda, _) = find_mint_address(&mint_signer_pda); - // Get proof for the mint let proof_result = get_create_accounts_proof( &rpc, &program_id, @@ -74,15 +67,6 @@ async fn test_create_light_mint() { .await .unwrap(); - println!("Light Mint test setup completed"); - println!("Program ID: {:?}", program_id); - println!( - "Mint Signer PDA: {:?} (bump: {})", - mint_signer_pda, mint_signer_bump - ); - println!("Light Mint PDA: {:?}", light_mint_pda); - - // Build create_mint instruction let accounts = light_token_minter::accounts::CreateMint { fee_payer: payer.pubkey(), authority: authority.pubkey(), @@ -121,28 +105,22 @@ async fn test_create_light_mint() { .await .expect("CreateMint should succeed"); - // Verify mint exists on-chain let light_mint_account = rpc .get_account(light_mint_pda) .await .unwrap() .expect("Mint should exist on-chain"); - // Verify the account has data (mint was created successfully) assert!( !light_mint_account.data.is_empty(), "Mint account should have data" ); - // The account should have significant size for a Light mint assert!( light_mint_account.data.len() > 50, - "Mint account should have sufficient data for a Light mint" + "Mint account should have sufficient data for a Light Token mint" ); - println!("Light Mint created and verified successfully!"); - println!("Mint account size: {} bytes", light_mint_account.data.len()); - println!("Mint PDA: {}", light_mint_pda); } /// Test basic mint signer PDA derivation without creating the mint. @@ -156,7 +134,6 @@ async fn test_mint_signer_derivation() { let rpc = LightProgramTest::new(config).await.unwrap(); let payer = rpc.get_payer().insecure_clone(); - // Derive mint signer PDA let (mint_signer_pda, bump) = Pubkey::find_program_address( &[ light_token_minter::MINT_SIGNER_SEED, @@ -165,16 +142,8 @@ async fn test_mint_signer_derivation() { &program_id, ); - // Derive mint PDA from mint signer let (mint_pda, _) = find_mint_address(&mint_signer_pda); - println!("Light Token Minter test setup completed"); - println!("Program ID: {:?}", program_id); - println!("Mint Signer PDA: {:?} (bump: {})", mint_signer_pda, bump); - println!("Light Mint PDA: {:?}", mint_pda); - println!("Payer: {:?}", payer.pubkey()); - - // Verify the PDA derivations are deterministic let (verify_signer, verify_bump) = Pubkey::find_program_address( &[ light_token_minter::MINT_SIGNER_SEED, @@ -186,7 +155,7 @@ async fn test_mint_signer_derivation() { assert_eq!(bump, verify_bump); } -/// Test the full flow: create Light mint, create token account, mint tokens. +/// Test the full flow: create Light Token mint, create token account, mint tokens. #[tokio::test] async fn test_mint_to() { let program_id = light_token_minter::ID; @@ -197,13 +166,10 @@ async fn test_mint_to() { let mut rpc = LightProgramTest::new(config).await.unwrap(); let payer = rpc.get_payer().insecure_clone(); - // Setup program data for rent-free config let program_data_pda = setup_mock_program_data(&mut rpc, &payer, &program_id); - // Derive per-program rent sponsor PDA let (rent_sponsor, _) = derive_rent_sponsor_pda(&program_id); - // Initialize rent-free config let (init_config_ix, config_pda) = InitializeRentFreeConfig::new( &program_id, &payer.pubkey(), @@ -217,15 +183,11 @@ async fn test_mint_to() { .await .expect("Initialize config should succeed"); - println!("Rent-free config initialized at: {:?}", config_pda); - - // Authority keypair (mint authority) let authority = Keypair::new(); rpc.airdrop_lamports(&authority.pubkey(), 1_000_000_000) .await .unwrap(); - // Derive mint signer PDA let (mint_signer_pda, mint_signer_bump) = Pubkey::find_program_address( &[ light_token_minter::MINT_SIGNER_SEED, @@ -234,13 +196,8 @@ async fn test_mint_to() { &program_id, ); - // Derive mint PDA from mint signer let (light_mint_pda, _) = find_mint_address(&mint_signer_pda); - println!("Mint Signer PDA: {:?}", mint_signer_pda); - println!("Light Mint PDA: {:?}", light_mint_pda); - - // Get proof for the mint let proof_result = get_create_accounts_proof( &rpc, &program_id, @@ -249,7 +206,6 @@ async fn test_mint_to() { .await .unwrap(); - // Build create_mint instruction let create_mint_accounts = light_token_minter::accounts::CreateMint { fee_payer: payer.pubkey(), authority: authority.pubkey(), @@ -288,9 +244,6 @@ async fn test_mint_to() { .await .expect("CreateMint should succeed"); - println!("Light mint created successfully!"); - - // Verify mint exists on-chain let light_mint_account = rpc .get_account(light_mint_pda) .await @@ -300,22 +253,15 @@ async fn test_mint_to() { !light_mint_account.data.is_empty(), "Mint account should have data" ); - println!("Mint verified, size: {} bytes", light_mint_account.data.len()); - // Create a recipient let recipient = Keypair::new(); rpc.airdrop_lamports(&recipient.pubkey(), 1_000_000_000) .await .unwrap(); - // Derive the ATA address (will be created by mint_to via the #[light_account(init, associated_token)] macro) + // Associated Light Token account derived here, created by mint_to via #[light_account(init, associated_token)] let (recipient_ata, ata_bump) = derive_token_ata(&recipient.pubkey(), &light_mint_pda); - println!( - "Recipient ATA (to be created by mint_to): {:?}", - recipient_ata - ); - // Get proof for creating the ATA let mint_to_proof_result = get_create_accounts_proof( &rpc, &program_id, @@ -324,7 +270,6 @@ async fn test_mint_to() { .await .unwrap(); - // Mint tokens using the mint_to instruction (which creates the ATA via macro) let mint_amount = 1_000_000_000u64; // 1 token with 9 decimals let mint_to_accounts = light_token_minter::accounts::MintTo { @@ -362,9 +307,6 @@ async fn test_mint_to() { .await .expect("MintTo should succeed"); - println!("Minted {} tokens to recipient", mint_amount); - - // Verify token balance let ata_account_after = rpc .get_account(recipient_ata) .await @@ -378,7 +320,6 @@ async fn test_mint_to() { spl_pod::bytemuck::pod_from_bytes::(&ata_account_after.data[..165]) .unwrap(); let balance = u64::from(token_state.amount); - println!("Final balance: {} (expected {})", balance, mint_amount); assert_eq!( balance, mint_amount, "Token balance should match minted amount" @@ -390,5 +331,4 @@ async fn test_mint_to() { ); } - println!("\n=== mint_to test completed successfully! ==="); } diff --git a/programs/anchor/token-swap/tests/common/mod.rs b/programs/anchor/token-swap/tests/common/mod.rs index c49c69d..f8e37b2 100644 --- a/programs/anchor/token-swap/tests/common/mod.rs +++ b/programs/anchor/token-swap/tests/common/mod.rs @@ -1,15 +1,15 @@ //! AMM test setup for 6 token standard combinations: SPL, T22, Light. //! //! Each combination varies the mint type and user account type while the pool -//! vaults are always Light token accounts: +//! vaults are always Light Token accounts: //! -//! - `Spl` / `Token2022`: standard associated token accounts, cross-standard transfers to Light vault -//! - `Light` / `FullLight`: native Light token accounts, direct transfers (lowest cost) -//! - `LightSpl` / `LightT22`: SPL/T22 mints converted into Light token accounts before +//! - `Spl` / `Token2022`: standard associated token accounts, transfers via `TransferInterfaceCpi` +//! - `Light` / `FullLight`: Light Token accounts, transfers via `TransferCheckedCpi` +//! - `LightSpl` / `LightT22`: SPL/Token 2022 mints converted into Light Token accounts before //! the AMM starts (tokens are minted to a temp associated token account, then -//! transferred to a Light associated token account via `transfer_spl_to_light`) +//! transferred to an associated Light Token account via `transfer_spl_to_light`) //! -//! `FullLight` additionally creates the LP mint as a Light mint via `create_pool_light_lp`, +//! `FullLight` additionally creates the LP mint as a Light Token mint via `create_pool_light_lp`, //! making the entire pool rent-free. //! //! ## Setup flow @@ -45,33 +45,33 @@ use spl_token_2022::pod::PodAccount; /// Token configuration for parameterized AMM tests. /// /// Each variant determines the mint type and user account type. The pool vaults -/// are always Light token accounts (rent-free). The user account type controls +/// are always Light Token accounts (rent-free). The user account type controls /// which CPI path `transfer_tokens()` selects at runtime: /// -/// - SPL/T22 user accounts → `TransferInterfaceCpi` (cross-standard, needs interface PDA) -/// - Light user accounts → `TransferCheckedCpi` (direct, no interface PDA) +/// - SPL/Token 2022 user accounts → `TransferInterfaceCpi` (needs interface PDA) +/// - Light user accounts → `TransferCheckedCpi` (no interface PDA) #[allow(dead_code)] #[derive(Clone, Copy, Debug)] pub enum TokenConfig { - /// SPL mint + SPL ATAs. Transfers cross standards (SPL ↔ Light vault). + /// SPL mint + SPL ATAs and Light Token vault. Transfers via `TransferInterfaceCpi`. Spl, - /// T22 mint + T22 ATAs. Transfers cross standards (T22 ↔ Light vault). + /// Token 2022 mint + Token 2022 ATAs and Light Token vault. Transfers via `TransferInterfaceCpi`. Token2022, - /// SPL mint + Light ATAs. Tokens converted from SPL ATAs in setup. + /// SPL mint + associated Light Token accounts. Tokens converted from SPL ATAs in setup. /// During AMM operations, all transfers are Light-to-Light. LightSpl, - /// T22 mint + Light ATAs. Tokens converted from T22 ATAs in setup. + /// Token 2022 mint + associated Light Token accounts. Tokens converted from Token 2022 ATAs in setup. /// During AMM operations, all transfers are Light-to-Light. LightT22, - /// Light mint + Light ATAs + SPL LP mint. Pure Light — lowest cost, no bridging. + /// Light Token mint + associated Light Token accounts + SPL LP mint. Light, - /// Full Light: Light mints + Light ATAs + Light LP mint. Entire pool is rent-free. + /// Light Token mints + associated Light Token accounts + Light Token LP mint. FullLight, } impl TokenConfig { /// Returns the underlying mint program type. - /// Light mints use SPL-compatible layout, so this returns `MintType::Spl`. + /// Light Token mints use SPL-compatible layout, so this returns `MintType::Spl`. pub fn mint_type(&self) -> MintType { match self { TokenConfig::Spl | TokenConfig::LightSpl => MintType::Spl, @@ -91,7 +91,7 @@ impl TokenConfig { } } - /// Returns true if user accounts are Light token accounts. + /// Returns true if user accounts are Light Token accounts. pub fn uses_light_user_accounts(&self) -> bool { matches!( self, @@ -102,12 +102,12 @@ impl TokenConfig { ) } - /// Returns true if mints are Light Protocol mints (not SPL/T22). + /// Returns true if mints are Light Token mints (not SPL/Token 2022). pub fn uses_light_mints(&self) -> bool { matches!(self, TokenConfig::Light | TokenConfig::FullLight) } - /// Returns true if LP mint is a Light Protocol mint. + /// Returns true if LP mint is a Light Token mint. pub fn uses_light_lp_mint(&self) -> bool { matches!(self, TokenConfig::FullLight) } @@ -140,12 +140,12 @@ pub struct AmmTestContext { pub depositor_ata_a: Pubkey, pub depositor_ata_b: Pubkey, pub token_config: TokenConfig, - /// Authority keypair for Light mint A (if Light config). + /// Authority keypair for Light Token mint A (if Light config). pub light_mint_authority_a: Option, /// LP mint signer PDA (for FullLight config). pub lp_mint_signer: Option, pub lp_mint_signer_bump: u8, - /// Config PDA for rent-free light mint creation. + /// Config PDA for rent-free Light Token mint creation. pub compression_config: Pubkey, } @@ -169,10 +169,10 @@ pub async fn create_test_rpc() -> LightProgramTest { /// Initialize mints, interface PDAs, depositor, and derive PDAs for a given token config. /// -/// SPL interface PDAs are created for all SPL/T22 configs (including `Spl` and +/// SPL interface PDAs are created for all SPL/Token 2022 configs (including `Spl` and /// `Token2022`, not just `LightSpl`/`LightT22`) because the pool vaults are always -/// Light token accounts — any transfer involving an SPL/T22 account and the Light -/// vault crosses standards and requires an interface PDA. +/// Light Token accounts — `TransferInterfaceCpi` needs the interface PDA when an +/// SPL/Token 2022 account transfers to a Light Token vault. /// /// For `Light`/`FullLight` configs, no interface PDA is created (early return). pub async fn setup_amm_test( @@ -182,17 +182,14 @@ pub async fn setup_amm_test( let program_id = swap_example::ID; let payer = rpc.get_payer().insecure_clone(); - // Initialize rent-free config (returns config PDA + per-program rent sponsor PDA) let (compression_config, _rent_sponsor) = initialize_rent_free_config(rpc, &payer, &program_id).await; - // Create depositor let depositor = Keypair::new(); rpc.airdrop_lamports(&depositor.pubkey(), 10_000_000_000) .await .unwrap(); - // Token amount for depositor let amount = 10_000_000_000_000u64; // 10,000 tokens with 9 decimals if config.uses_light_mints() { @@ -205,11 +202,9 @@ pub async fn setup_amm_test( let mint_a_pubkey = light_mint_a.mint; let mint_b_pubkey = light_mint_b.mint; - // No SPL interface PDAs for pure Light-to-Light let spl_interface_pda_a = Pubkey::default(); let spl_interface_pda_b = Pubkey::default(); - // Mint Light tokens directly to depositor (creates ATA + mints in one call) let depositor_ata_a = mint_light_tokens( rpc, &payer, @@ -229,11 +224,9 @@ pub async fn setup_amm_test( ) .await; - // Derive AMM PDA let amm_id = Pubkey::new_unique(); let (amm_pda, _) = Pubkey::find_program_address(&[amm_id.as_ref()], &program_id); - // Derive pool PDAs let (pool_pda, _) = Pubkey::find_program_address( &[ amm_pda.as_ref(), @@ -251,9 +244,8 @@ pub async fn setup_amm_test( let (pool_account_b, pool_b_bump) = Pubkey::find_program_address(&[b"pool_b", pool_pda.as_ref()], &program_id); - // Derive LP mint address: - // Light config → SPL LP mint derived normally - // FullLight config → Light LP mint derived from lp_mint_signer PDA + // Light config: SPL LP mint via standard PDA. + // FullLight config: Light Token LP mint via lp_mint_signer PDA. let (mint_liquidity, lp_mint_signer, lp_mint_signer_bump) = if config.uses_light_lp_mint() { let (lp_mint_signer, lp_mint_signer_bump) = Pubkey::find_program_address( @@ -324,13 +316,12 @@ pub async fn setup_amm_test( let mint_a_pubkey = mint_a.pubkey(); let mint_b_pubkey = mint_b.pubkey(); - // Create SPL interface PDAs for both mints (needed for cross-standard transfers) + // Required for `TransferInterfaceCpi` between SPL/Token 2022 accounts and Light Token pool vaults. let spl_interface_result_a = create_spl_interface_pda(rpc, &payer, &mint_a_pubkey, config.mint_type(), false).await; let spl_interface_result_b = create_spl_interface_pda(rpc, &payer, &mint_b_pubkey, config.mint_type(), false).await; - // Create depositor ATAs and mint tokens based on config let (depositor_ata_a, depositor_ata_b) = match config { TokenConfig::Spl => { let ata_a = create_spl_ata(rpc, &payer, &mint_a_pubkey, &depositor.pubkey()).await; @@ -347,7 +338,8 @@ pub async fn setup_amm_test( (ata_a, ata_b) } TokenConfig::LightSpl => { - // Create temp SPL ATAs → mint → create Light ATAs → transfer (compress) + // Tokens route through temp SPL ATAs because Light Token accounts + // cannot be direct mint targets for SPL mints. let temp_ata_a = create_spl_ata(rpc, &payer, &mint_a_pubkey, &depositor.pubkey()).await; let temp_ata_b = @@ -392,7 +384,8 @@ pub async fn setup_amm_test( (light_ata_a, light_ata_b) } TokenConfig::LightT22 => { - // Create temp T22 ATAs → mint → create Light ATAs → transfer (compress) + // Tokens route through temp Token 2022 ATAs because Light Token accounts + // cannot be direct mint targets for Token 2022 mints. let temp_ata_a = create_t22_ata(rpc, &payer, &mint_a_pubkey, &depositor.pubkey()).await; let temp_ata_b = @@ -441,11 +434,9 @@ pub async fn setup_amm_test( } }; - // Derive AMM PDA let amm_id = Pubkey::new_unique(); let (amm_pda, _) = Pubkey::find_program_address(&[amm_id.as_ref()], &program_id); - // Derive pool PDAs let (pool_pda, _) = Pubkey::find_program_address( &[ amm_pda.as_ref(), @@ -510,9 +501,9 @@ pub async fn setup_amm_test( /// /// Account creation varies by config: /// - `Spl` / `Token2022`: create standard ATAs, mint directly -/// - `Light` / `FullLight`: create Light ATAs via `mint_light_tokens` (creates + mints in one call) -/// - `LightSpl` / `LightT22`: create temp SPL/T22 ATAs → mint → -/// create Light ATAs → convert via `transfer_spl_to_light` +/// - `Light` / `FullLight`: create associated Light Token accounts via `mint_light_tokens` (creates + mints in one call) +/// - `LightSpl` / `LightT22`: create temp SPL/Token 2022 ATAs, mint, then +/// create associated Light Token accounts and convert via `transfer_spl_to_light` pub async fn create_trader( rpc: &mut R, ctx: &AmmTestContext, @@ -557,7 +548,8 @@ pub async fn create_trader( (ata_a, ata_b) } TokenConfig::LightSpl => { - // Create temp SPL ATAs, mint, then transfer to Light ATAs + // Tokens route through temp SPL ATAs because Light Token accounts + // cannot be direct mint targets for SPL mints. let temp_ata_a = create_spl_ata(rpc, &ctx.payer, &ctx.mint_a_pubkey, &trader.pubkey()).await; let _temp_ata_b = @@ -596,7 +588,8 @@ pub async fn create_trader( (light_ata_a, light_ata_b) } TokenConfig::LightT22 => { - // Create temp T22 ATAs, mint, then transfer to Light ATAs + // Tokens route through temp Token 2022 ATAs because Light Token accounts + // cannot be direct mint targets for Token 2022 mints. let temp_ata_a = create_t22_ata(rpc, &ctx.payer, &ctx.mint_a_pubkey, &trader.pubkey()).await; let _temp_ata_b = @@ -635,7 +628,7 @@ pub async fn create_trader( (light_ata_a, light_ata_b) } TokenConfig::Light | TokenConfig::FullLight => { - // Mint directly to trader's Light ATAs using the mint authority + // Light Token mints support direct minting to associated Light Token accounts. let mint_authority_a = ctx .light_mint_authority_a .as_ref() @@ -651,7 +644,7 @@ pub async fn create_trader( ) .await; - // Create Light ATA for token B (no minting needed initially) + // Token B: trader starts with zero balance, only needs the account created. let light_ata_b = create_light_ata(rpc, &ctx.payer, &ctx.mint_b_pubkey, &trader.pubkey()).await; @@ -666,7 +659,7 @@ pub async fn create_trader( // Helpers // ============================================================================ -/// Get token balance from an on-chain token account (SPL/T22/Light when hot). +/// Get token balance from an active token account (SPL/Token 2022/Light Token). pub async fn get_token_balance(rpc: &mut R, account: Pubkey) -> u64 { let account_data = rpc .get_account(account) diff --git a/programs/anchor/token-swap/tests/swap.rs b/programs/anchor/token-swap/tests/swap.rs index a0f9ea1..6fe9da9 100644 --- a/programs/anchor/token-swap/tests/swap.rs +++ b/programs/anchor/token-swap/tests/swap.rs @@ -7,7 +7,7 @@ //! needing account data (see `create_pool.rs` //! `#[light_account(init, token::owner = pool_authority)]`). //! -//! 2. **Pool vaults are rent-free** — they're Light token accounts sponsored by +//! 2. **Pool vaults are rent-free** — they're Light Token accounts sponsored by //! `RENT_SPONSOR`, eliminating ~0.002 SOL rent per pool vault. //! //! 3. **Validity proof for pool creation** — `get_create_accounts_proof()` @@ -24,28 +24,28 @@ //! | Test | Mint | User accounts | LP mint | Transfer path | Purpose | //! |------|------|---------------|---------|---------------|---------| //! | `test_swap_spl` | SPL | SPL ATAs | SPL | `TransferInterfaceCpi` | SPL mints work with Light vault | -//! | `test_swap_t22` | T22 | T22 ATAs | T22 | `TransferInterfaceCpi` | T22 mints work with Light vault | -//! | `test_swap_light` | Light | Light ATAs | SPL | `TransferCheckedCpi` | Light mints, SPL LP mint | +//! | `test_swap_t22` | Token 2022 | Token 2022 ATAs | Token 2022 | `TransferInterfaceCpi` | Token 2022 mints work with Light Token vault | +//! | `test_swap_light` | Light | Light ATAs | SPL | `TransferCheckedCpi` | Light Token mints, SPL LP mint | //! | `test_swap_spl_light` | SPL | Light ATAs | SPL | `TransferCheckedCpi` | SPL mint, converted user accounts | -//! | `test_swap_t22_light` | T22 | Light ATAs | T22 | `TransferCheckedCpi` | T22 mint, converted user accounts | +//! | `test_swap_t22_light` | Token 2022 | Light ATAs | Token 2022 | `TransferCheckedCpi` | Token 2022 mint, converted user accounts | //! | `test_swap_full_light` | Light | Light ATAs | Light | `TransferCheckedCpi` | Fully rent-free (Light LP mint) | //! -//! For `Spl`/`Token2022`: user accounts are SPL/T22, vaults are Light → cross-standard -//! (`TransferInterfaceCpi` with SPL interface PDA). +//! For `Spl`/`Token2022`: user accounts are SPL/Token 2022, vaults are Light → +//! `TransferInterfaceCpi` (with SPL interface PDA). //! -//! For `Light`/`FullLight`/`LightSpl`/`LightT22`: all accounts are Light → direct -//! (`TransferCheckedCpi`, no interface PDA needed). +//! For `Light`/`FullLight`/`LightSpl`/`LightT22`: all accounts are Light Token → +//! `TransferCheckedCpi` (no interface PDA needed). //! -//! `LightSpl`/`LightT22` convert tokens from SPL/T22 associated token accounts -//! into Light token accounts *before* the AMM interactions start (in -//! `create_trader` / setup). The AMM itself only sees Light token accounts. +//! `LightSpl`/`LightT22` convert tokens from SPL/Token 2022 associated token accounts +//! into Light Token accounts *before* the AMM interactions start (in +//! `create_trader` / setup). The AMM itself only sees Light Token accounts. //! //! ## Pool creation modes //! //! `FullLight` uses `create_pool_light_lp` which creates pool vaults via -//! explicit `CreateTokenAccountCpi` and the LP mint as a Light mint. +//! explicit `CreateTokenAccountCpi` and the LP mint as a Light Token mint. //! All other configs use `create_pool` with macro-initialized vaults and -//! an SPL/T22 LP mint. +//! an SPL/Token 2022 LP mint. //! //! ## Cold/hot lifecycle //! @@ -78,11 +78,11 @@ use solana_signer::Signer; // Tests — one per token configuration, plus a standalone AMM creation test. // ============================================================================ -/// SPL mint with SPL ATAs, SPL LP mint, and Light pool vaults. +/// SPL mint with SPL ATAs, SPL LP mint, and Light Token pool vaults. /// -/// Every transfer crosses standards (SPL ↔ Light) via `TransferInterfaceCpi` +/// All transfers use `TransferInterfaceCpi` (SPL ↔ Light Token vault) /// with SPL interface PDAs. This is the baseline: same mint type as standard -/// SPL AMM, but pool vaults are rent-free Light token accounts. +/// SPL AMM, but pool vaults are rent-free Light Token accounts. #[tokio::test] async fn test_swap_spl() { let mut rpc = create_test_rpc().await; @@ -90,9 +90,9 @@ async fn test_swap_spl() { run_amm_full_flow(&mut rpc, &ctx).await; } -/// Token-2022 mint with T22 ATAs, T22 LP mint, and Light pool vaults. +/// Token 2022 mint with Token 2022 ATAs, Token 2022 LP mint, and Light Token pool vaults. /// -/// Every transfer crosses standards (T22 ↔ Light) via `TransferInterfaceCpi` +/// All transfers use `TransferInterfaceCpi` (Token 2022 ↔ Light Token vault) /// with SPL interface PDAs. #[tokio::test] async fn test_swap_t22() { @@ -101,7 +101,7 @@ async fn test_swap_t22() { run_amm_full_flow(&mut rpc, &ctx).await; } -/// Light mint + Light user accounts, SPL LP mint, and Light pool vaults. +/// Light Token mint + Light Token user accounts, SPL LP mint, and Light Token pool vaults. /// /// All token A/B transfers are Light-to-Light (`TransferCheckedCpi`). /// LP mint is SPL because `create_pool` uses Anchor's `init` macro @@ -113,12 +113,10 @@ async fn test_swap_light() { run_amm_full_flow(&mut rpc, &ctx).await; } -/// SPL mint + Light user accounts (interop), SPL LP mint. +/// SPL mint + Light Token user accounts, SPL LP mint. SPL tokens converted to +/// Light Token accounts in setup via `transfer_spl_to_light`. /// -/// Tokens start in SPL ATAs, get converted into Light token accounts during -/// setup via `transfer_spl_to_light`. Once in Light token accounts, all AMM -/// transfers are Light-to-Light (`TransferCheckedCpi`). -/// Shows that Light token accounts can hold any SPL mint. +/// All transfers use `TransferCheckedCpi`. #[tokio::test] async fn test_swap_spl_light() { let mut rpc = create_test_rpc().await; @@ -126,12 +124,10 @@ async fn test_swap_spl_light() { run_amm_full_flow(&mut rpc, &ctx).await; } -/// Token-2022 mint + Light user accounts (interop), T22 LP mint. +/// Token 2022 mint + Light Token user accounts, Token 2022 LP mint. Token 2022 tokens +/// converted to Light Token accounts in setup via `transfer_spl_to_light`. /// -/// Tokens start in T22 ATAs, get converted into Light token accounts during -/// setup via `transfer_spl_to_light`. Once in Light token accounts, all AMM -/// transfers are Light-to-Light (`TransferCheckedCpi`). -/// Shows that Light token accounts can hold any T22 mint. +/// All transfers use `TransferCheckedCpi`. #[tokio::test] async fn test_swap_t22_light() { let mut rpc = create_test_rpc().await; @@ -139,11 +135,10 @@ async fn test_swap_t22_light() { run_amm_full_flow(&mut rpc, &ctx).await; } -/// Fully rent-free: Light mints + Light user accounts + Light LP mint. +/// Light Token mints + Light Token user accounts + Light Token LP mint. /// -/// Uses `create_pool_light_lp` to create the LP mint as a Light mint via CPI. -/// All token operations use `TransferCheckedCpi` — the entire pool is -/// rent-free. +/// Uses `create_pool_light_lp` to create the LP mint as a Light Token mint via CPI. +/// All transfers use `TransferCheckedCpi`. #[tokio::test] async fn test_swap_full_light() { let mut rpc = create_test_rpc().await; @@ -185,10 +180,10 @@ async fn test_create_amm() { // Full Flow // ============================================================================ -/// Run the full AMM flow for any token configuration: SPL, T22, Light. +/// Run the full AMM flow for any token configuration: SPL, Token 2022, Light. /// /// 1. Create AMM with 2.5% fee -/// 2. Create pool with Light token vaults (standard or FullLight path) +/// 2. Create pool with Light Token vaults (standard or FullLight path) /// 3. Deposit initial liquidity, receive LP tokens /// 4. Create trader with funded accounts /// 5. Swap A→B @@ -208,7 +203,6 @@ async fn run_amm_full_flow( }; // ==================== PHASE 1: Create AMM ==================== - // AMM defines fee structure for all pools under it. { let accounts = swap_example::accounts::CreateAmm { amm: ctx.amm_pda, @@ -234,14 +228,12 @@ async fn run_amm_full_flow( } // ==================== PHASE 2: Create Pool ==================== - // Pool holds liquidity for token pair A/B. Pool vaults are Light token - // accounts. FullLight uses `create_pool_light_lp` (CPI-initialized vaults - // + Light LP mint). All others use `create_pool` (macro-initialized vaults - // + SPL/T22 LP mint). + // FullLight uses `create_pool_light_lp` (CPI-initialized vaults + // + Light Token LP mint). All others use `create_pool` (macro-initialized + // vaults + SPL/Token 2022 LP mint). { - // Proof inputs differ by pool creation mode: - // FullLight: proves LP mint signer (vaults created via explicit CPI) - // Standard: proves pool vault PDAs (vaults created via macro) + // FullLight proves LP mint signer (vaults created via explicit CPI). + // Standard proves pool vault PDAs (vaults created via macro). let proof_inputs = if ctx.token_config.uses_light_lp_mint() { vec![CreateAccountsProofInput::mint( ctx.lp_mint_signer @@ -259,7 +251,7 @@ async fn run_amm_full_flow( .unwrap(); if ctx.token_config.uses_light_lp_mint() { - // FullLight: create_pool_light_lp — CPI-initialized vaults + Light LP mint + // FullLight: create_pool_light_lp — CPI-initialized vaults + Light Token LP mint let lp_mint_signer = ctx .lp_mint_signer .expect("FullLight config should have lp_mint_signer"); @@ -308,7 +300,7 @@ async fn run_amm_full_flow( .await .expect("create_pool_light_lp should succeed"); } else { - // Standard: create_pool — macro-initialized vaults + SPL/T22 LP mint + // Standard: create_pool — macro-initialized vaults + SPL/Token 2022 LP mint let accounts = swap_example::accounts::CreatePool { amm: ctx.amm_pda, pool: ctx.pool_pda, @@ -351,9 +343,8 @@ async fn run_amm_full_flow( .expect("create_pool should succeed"); } - // Fund pool_authority for Light-to-Light transfers (rent top-ups). - // The pool_authority needs lamports to pay for rent top-ups when - // transferring from pool accounts to user accounts. + // pool_authority needs lamports to pay rent top-ups when + // transferring from pool vaults to Light Token user accounts. if ctx.token_config.uses_light_user_accounts() { rpc.airdrop_lamports(&ctx.pool_authority, 1_000_000_000) .await @@ -361,15 +352,12 @@ async fn run_amm_full_flow( } } - // Verify initial pool balances verify_light_token_balance(rpc, ctx.pool_account_a, 0, "pool_account_a (initial)").await; verify_light_token_balance(rpc, ctx.pool_account_b, 0, "pool_account_b (initial)").await; // ==================== PHASE 3: Deposit Liquidity ==================== - // Depositor provides equal amounts of token A and B, receives LP tokens. let deposit_amount = 1_000_000_000u64; // 1 token let depositor_liquidity_ata = { - // Create LP ATA for depositor (varies by LP mint type) let depositor_liquidity_ata = match ctx.token_config { TokenConfig::Spl | TokenConfig::LightSpl | TokenConfig::Light => { create_spl_ata( @@ -445,7 +433,6 @@ async fn run_amm_full_flow( depositor_liquidity_ata }; - // Verify pool balances after deposit verify_light_token_balance( rpc, ctx.pool_account_a, @@ -462,7 +449,6 @@ async fn run_amm_full_flow( .await; // ==================== PHASE 4: Create Trader ==================== - // Trader gets funded accounts for swapping. let trader_initial_a = 100_000_000u64; // 0.1 tokens let (trader, trader_ata_a, trader_ata_b) = create_trader(rpc, ctx, trader_initial_a).await; @@ -507,12 +493,10 @@ async fn run_amm_full_flow( .expect("swap A->B should succeed"); } - // Verify trader received token B let trader_b_balance = get_token_balance(rpc, trader_ata_b).await; assert!(trader_b_balance > 0, "Trader should have received token B"); // ==================== PHASE 6: Swap B → A ==================== - // Swap half of received B back to A. let swap_b_input = trader_b_balance / 2; { let accounts = swap_example::accounts::SwapExactTokensForTokens { @@ -554,7 +538,6 @@ async fn run_amm_full_flow( } // ==================== PHASE 7: Withdraw Liquidity ==================== - // Depositor redeems half of LP tokens for underlying token A and B. let lp_balance = get_token_balance(rpc, depositor_liquidity_ata).await; let withdraw_amount = lp_balance / 2; { @@ -602,7 +585,6 @@ async fn run_amm_full_flow( } // ==================== PHASE 8: Verify Final State ==================== - // LP tokens were burned let lp_balance_after = get_token_balance(rpc, depositor_liquidity_ata).await; assert_eq!( lp_balance_after,