Sol.College

Full lesson

darklake-monorepo

What it does

From the project README:

Darklake is a decentralized exchange (DEX) protocol built on the Solana blockchain, inspired by Uniswap v3. It aims to provide efficient and flexible liquidity provision with concentrated liquidity and confidential swaps.
Original
darklakefi/darklake-monorepo
SuperStack fork
Blockchains/darklake-monorepo @ 0719aa7
Stars
16
Last push (original)
2025-10-01
Languages
TypeScript, Rust, Circom, JavaScript, CSS, Dockerfile
Detected stack
AnchorMetaplexNext.jsweb3.js
Categories
Other
Licence
MIT
Homepage
https://darklake.fi

Architecture

196 source files. By extension: .tsx ×98, .ts ×74, .rs ×16, .js ×8.

Top-level directorySource files
apps144
web-old49
circuits3

On-chain programs: apps/anchor/programs/darklake

Dapp: deploying

This fork is queued for its own live dapp on Sol.College, with a Devnet/Mainnet switch. It appears here, at /dapps/darklake-monorepo/, once it is deployed and checked on devnet. Until then, 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.

darklakefi/darklake-monorepo · apps/anchor/programs/darklake/src/instructions/add_liquidity.rs L121–144 @ 0719aa7 · MIT · original
        let token_mint_x_key = self.token_mint_x.key();        let token_mint_y_key = self.token_mint_y.key();                let pool_signer_seeds = &[            b"pool",            token_mint_x_key.as_ref(),            token_mint_y_key.as_ref(),            &[pool.bump],        ];         msg!("Minting LP tokens");        msg!("Mint: {}", self.token_mint_lp.key().to_string());        msg!("To: {}", self.user_token_account_lp.key().to_string());        msg!("Authority: {}", self.pool.key().to_string());         spl_mint_to(            CpiContext::new_with_signer(                self.token_mint_lp_program.to_account_info(),                SplMintTo {                    mint: self.token_mint_lp.to_account_info(),                    to: self.user_token_account_lp.to_account_info(),                    authority: self.pool.to_account_info(),                },                &[&pool_signer_seeds[..]],
  1. Line 124 let pool_signer_seeds = &[: Declares the PDA seeds. Anchor re-derives the address and rejects the account if it doesn't match.
  2. Line 128 &[pool.bump],: Uses the bump seed, the extra byte that pushes the derived address off the ed25519 curve.
  3. Line 131 msg!("Minting LP tokens");: Logs to the program log, which is visible in explorers and the test output.
  4. Line 136 spl_mint_to(: Mints new tokens. The mint authority must sign.
  5. Line 137 CpiContext::new_with_signer(: Makes a CPI signed by a PDA. The signer seeds prove the program controls that address.
darklakefi/darklake-monorepo · apps/anchor/programs/darklake/src/instructions/confidential_swap.rs L157–180 @ 0719aa7 · MIT · original
            msg!("pool_token_account_y balance: {}", self.pool_token_account_y.amount);             msg!("1st transfer - from: {:?}, to: {:?}", from_user_account.key(), to_pool_account.key());             // Transfer from user to pool            transfer_checked(                CpiContext::new(                    from_token_program.to_account_info(),                    TransferChecked {                        from: from_user_account.to_account_info(),                        mint: from_mint.to_account_info(),                        to: to_pool_account.to_account_info(),                        authority: self.user.to_account_info(),                    },                ),                amount_sent,                from_mint.decimals,            )?;             msg!("2nd transfer - from: {:?}, to: {:?}", from_pool_account.key(), to_user_account.key());             // Transfer from pool to user            transfer_checked(                CpiContext::new_with_signer(
  1. Line 157 msg!("pool_token_account_y balance: {}", self.pool_token_account_y.amount);: Logs to the program log, which is visible in explorers and the test output.
  2. Line 162 transfer_checked(: A checked token transfer, which also verifies the mint and decimals.
  3. Line 163 CpiContext::new(: Makes a cross-program invocation into another program.
  4. Line 180 CpiContext::new_with_signer(: Makes a CPI signed by a PDA. The signer seeds prove the program controls that address.
darklakefi/darklake-monorepo · apps/anchor/programs/darklake/src/instructions/initialize_pool.rs L13–36 @ 0719aa7 · MIT · original
pub struct InitializePool<'info> {    #[account(init, payer = payer, space = 8 + Pool::INIT_SPACE, seeds = [b"pool", token_mint_x.key().as_ref(), token_mint_y.key().as_ref()], bump)]    pub pool: Account<'info, Pool>,    pub token_mint_x: InterfaceAccount<'info, Mint>,    pub token_mint_y: InterfaceAccount<'info, Mint>,    /// CHECK: PDA will be checked in the instruction handler.    #[account(        mut,        seeds = [b"lp", token_mint_x.key().as_ref(), token_mint_y.key().as_ref()],        bump    )]    pub token_mint_lp: UncheckedAccount<'info>,    ///CHECK: This account is checked in the instruction    #[account(        mut,        seeds = [b"metadata", TOKEN_METADATA_PROGRAM_ID.as_ref(), token_mint_lp.key().as_ref()],        bump,        seeds::program = TOKEN_METADATA_PROGRAM_ID    )]    pub metadata_account: UncheckedAccount<'info>,    #[account(mut)]    pub payer: Signer<'info>,    pub lp_token_program: Program<'info, SplToken>,    /// CHECK: metaplex account
  1. Line 14 #[account(init, payer = payer, space = 8 + Pool::INIT_SPACE, seeds = [b"pool", token_mint_: Declares the PDA seeds. Anchor re-derives the address and rejects the account if it doesn't match.
  2. Line 14 #[account(init, payer = payer, space = 8 + Pool::INIT_SPACE, seeds = [b"pool", token_mint_: Uses the bump seed, the extra byte that pushes the derived address off the ed25519 curve.
  3. Line 14 #[account(init, payer = payer, space = 8 + Pool::INIT_SPACE, seeds = [b"pool", token_mint_: Creates and pays for a new account. Space and payer must be specified.
  4. Line 34 pub payer: Signer<'info>,: Requires this account to have signed the transaction.
darklakefi/darklake-monorepo · apps/anchor/programs/darklake/src/instructions/remove_liquidity.rs L85–108 @ 0719aa7 · MIT · original
        msg!("Amount X: {}", amount_x);        msg!("Amount Y: {}", amount_y);         spl_burn(            CpiContext::new(                self.token_mint_lp_program.to_account_info(),                SplBurn {                    from: self.user_token_account_lp.to_account_info(),                    authority: self.user.to_account_info(),                    mint: self.token_mint_lp.to_account_info(),                },            ),            amount,        )?;         let token_mint_x_key = self.token_mint_x.key();        let token_mint_y_key = self.token_mint_y.key();         let pool_signer_seeds = &[            b"pool",            token_mint_x_key.as_ref(),            token_mint_y_key.as_ref(),            &[self.pool.bump],        ];
  1. Line 85 msg!("Amount X: {}", amount_x);: Logs to the program log, which is visible in explorers and the test output.
  2. Line 89 CpiContext::new(: Makes a cross-program invocation into another program.
  3. Line 103 let pool_signer_seeds = &[: Declares the PDA seeds. Anchor re-derives the address and rejects the account if it doesn't match.
  4. Line 107 &[self.pool.bump],: Uses the bump seed, the extra byte that pushes the derived address off the ed25519 curve.

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.

DirectoryCommandRuns
.npm run devturbo run dev --parallel
.npm run lintturbo run lint -- --fix --ext .js,.jsx,.ts,.tsx --ignore-pattern 'node_modules/*'
apps/anchornpm run buildanchor build
apps/anchornpm run testanchor test
apps/webnpm run devnext dev
apps/webnpm run startnext start
apps/webnpm run buildnext build
apps/webnpm run testTZ=UTC jest --detectOpenHandles
apps/webnpm run lintnext lint && tsc --noEmit
apps/servernpm run devnest start --watch --debug
apps/servernpm run startnest start
apps/servernpm run buildnest build
apps/servernpm run testTZ=UTC jest --detectOpenHandles --passWithNoTests
apps/servernpm run linteslint . && tsc --noEmit
apps/anchoranchor buildcompile programs and generate IDLs
apps/anchoranchor testlocal validator + test suite

What you could build from it

Used in lessons