Full lesson
AMM
Fluidity meets function
What it does
From the project README:
Fluxa is a next-generation decentralized finance (DeFi) protocol built on Solana. It combines the power of concentrated liquidity, dynamic impermanent loss mitigation, and personalized yield strategies to deliver a secure, efficient, and user-friendly liquidity provisioning experience. Fluxa is designed to maximize capital efficiency, reduce risk, and make advanced DeFi accessible to both novice and experienced users.
- Original
- FluxaAMM/AMM
- SuperStack fork
- Blockchains/AMM @
cf385b3 - Stars
- 3
- Last push (original)
- 2025-11-27
- Languages
- Rust, TypeScript, Makefile, Dockerfile, Shell, RenderScript
- Detected stack
- Anchorweb3.js
- Categories
- DeFi
- Licence
- MIT
Architecture
146 source files. By extension: .rs ×143, .ts ×3.
| Top-level directory | Source files |
|---|---|
programs | 113 |
patched_crates | 30 |
tests | 2 |
types | 1 |
On-chain programs: programs/fluxa_core, programs/fluxa_core/fuzz
Dapp: devnet deploy pending
⏳ Devnet deploy pending — goes live when the devnet wallet is topped up. This fork's own dapp is not deployed yet, so there is no program address or transaction to show. It is queued in dapp-queue.txt; once devnet SOL is available it is deployed, exercised with real devnet transactions, and this section switches to the live dapp at /dapps/amm/. Until then, the lesson and step-by-step guide below are complete, and you can run it locally with the commands below.
Key code, explained
Excerpts chosen automatically where the code uses the most Solana concepts, pinned to the fork's commit.
programs/fluxa_core/src/utils/timelock_operation.rs L457–480 @ cf385b3 · MIT · original #[account( init, payer = payer, space = 8 + std::mem::size_of::<TimelockOperation>(), seeds = [b"timelock_operation", pool_core.key().as_ref(), &operation_id.to_le_bytes()], bump )] pub timelock_operation: AccountLoader<'info, TimelockOperation>, /// CHECK: the pool core account associated with the operation pub pool_core: UncheckedAccount<'info>, /// the payer who will fund the operation #[account(mut)] pub payer: Signer<'info>, /// the proposer who proposed the operation pub proposer: Signer<'info>, /// the system program account pub system_program: Program<'info, System>,} /// Confirm Timelock Operation Context- Line 458
init,: Creates and pays for a new account. Space and payer must be specified. - Line 461
seeds = [b"timelock_operation", pool_core.key().as_ref(), &operation_id.to_le_bytes()],: Declares the PDA seeds. Anchor re-derives the address and rejects the account if it doesn't match. - Line 462
bump: Uses the bump seed, the extra byte that pushes the derived address off the ed25519 curve. - Line 471
pub payer: Signer<'info>,: Requires this account to have signed the transaction.
programs/fluxa_core/src/utils/advanced_account_optimization.rs L301–324 @ cf385b3 · MIT · original /// - Raw memory copy is used for maximum CU efficiency and to preserve zero-copy layouts. /// - Lamports are recycled to the payer, ensuring protocol sustainability. pub fn migrate<'info>( old: &AccountInfo<'info>, new: &AccountInfo<'info>, payer: &Signer<'info>, program_id: &Pubkey, new_space: usize, bump: u8, ) -> Result<()> { // Validate size constraints require!( new_space <= MAX_ACCOUNT_SIZE, AdvancedAccountOptimizationError::AccountSizeExceedsLimit ); require!( new_space > old.data_len(), AdvancedAccountOptimizationError::InvalidAccountSize ); // Validate that new account was created with correct PDA let expected_seeds = &[b"resize_v2", old.key.as_ref(), &[bump]]; let expected_key = Pubkey::create_program_address(expected_seeds, program_id) .map_err(|_| error!(AdvancedAccountOptimizationError::InvalidPDAAddress))?;- Line 306
payer: &Signer<'info>,: Requires this account to have signed the transaction. - Line 309
bump: u8,: Uses the bump seed, the extra byte that pushes the derived address off the ed25519 curve. - Line 312
require!(: An explicit validation that aborts the instruction with an error. - Line 322
let expected_seeds = &[b"resize_v2", old.key.as_ref(), &[bump]];: Declares the PDA seeds. Anchor re-derives the address and rejects the account if it doesn't match.
programs/fluxa_core/src/instructions/security_authority/initialize_emergency_contacts.rs L37–59 @ cf385b3 · MIT · original /// operations where response latency directly impacts protocol security. #[account( init, payer = payer, space = 8 + std::mem::size_of::<EmergencyContacts>(), seeds = [b"emergency_contacts", pool_core.key().as_ref()], bump )] pub emergency_contacts: AccountLoader<'info, EmergencyContacts>, /// CHECK: Pool core account establishing emergency response context and authority relationships. pub pool_core: UncheckedAccount<'info>, /// Funding account for emergency registry creation with separation from operational control. #[account(mut)] pub payer: Signer<'info>, /// Bootstrap authority for emergency system configuration without ongoing privileges. pub authority: Signer<'info>, /// System program for account creation and rent management in emergency contexts. pub system_program: Program<'info, System>,}- Line 39
init,: Creates and pays for a new account. Space and payer must be specified. - Line 42
seeds = [b"emergency_contacts", pool_core.key().as_ref()],: Declares the PDA seeds. Anchor re-derives the address and rejects the account if it doesn't match. - Line 43
bump: Uses the bump seed, the extra byte that pushes the derived address off the ed25519 curve. - Line 52
pub payer: Signer<'info>,: Requires this account to have signed the transaction.
programs/fluxa_core/src/instructions/security_authority/initialize_audit_trail_head.rs L37–59 @ cf385b3 · MIT · original init, payer = payer, space = 8 + std::mem::size_of::<AuditTrailHead>(), seeds = [b"audit_trail_head", pool_core.key().as_ref()], bump )] pub audit_trail_head: AccountLoader<'info, AuditTrailHead>, /// Pool core binding ensuring audit trail scope isolation. /// /// Links audit trail to specific pool to prevent cross-contamination and /// enable pool-specific audit analysis. Validation ensures the pool /// account exists and is properly formatted. /// CHECK: This is not dangerous because we don't read or write from this account pub pool_core: UncheckedAccount<'info>, /// Transaction fee payer enabling flexible cost allocation. /// /// Marked mutable to allow rent payment deduction. Separation from authority /// enables operational models where different entities handle costs versus /// control, improving operational flexibility. #[account(mut)] pub payer: Signer<'info>,- Line 37
init,: Creates and pays for a new account. Space and payer must be specified. - Line 40
seeds = [b"audit_trail_head", pool_core.key().as_ref()],: Declares the PDA seeds. Anchor re-derives the address and rejects the account if it doesn't match. - Line 41
bump: Uses the bump seed, the extra byte that pushes the derived address off the ed25519 curve. - Line 59
pub payer: Signer<'info>,: Requires this account to have signed the transaction.
How to run, build and test
These commands come from the repo's own manifests (package.json scripts, Anchor.toml, Cargo, go.mod, Makefile). Check the README for prerequisites and environment variables.
| Directory | Command | Runs |
|---|---|---|
. | npm run test | node --loader ts-node/esm ./node_modules/mocha/bin/mocha --extensions ts tests/**/*.test.ts --timeout 60000 |
. | anchor build | compile programs and generate IDLs |
. | anchor test | local validator + test suite |
. | cargo build | Rust workspace build |
. | cargo test | Rust tests |
. | make up | Makefile target |
. | make down | Makefile target |
. | make build | Makefile target |
. | make test | Makefile target |
. | make deploy | Makefile target |
. | make clean | Makefile target |
. | make setup-test-accounts | Makefile target |
. | make dev-shell | Makefile target |
What you could build from it
- Fork the SuperStack copy and extend it within the DeFi gaps listed on the idea page.
- Learn the pattern first: Program Derived Addresses (PDAs)
- Learn the pattern first: Cross-Program Invocations (CPIs)
- Learn the pattern first: SPL Tokens: mints, accounts and transfers