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 directory | Source files |
|---|---|
apps | 144 |
web-old | 49 |
circuits | 3 |
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.
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[..]],- Line 124
let pool_signer_seeds = &[: Declares the PDA seeds. Anchor re-derives the address and rejects the account if it doesn't match. - Line 128
&[pool.bump],: Uses the bump seed, the extra byte that pushes the derived address off the ed25519 curve. - Line 131
msg!("Minting LP tokens");: Logs to the program log, which is visible in explorers and the test output. - Line 136
spl_mint_to(: Mints new tokens. The mint authority must sign. - Line 137
CpiContext::new_with_signer(: Makes a CPI signed by a PDA. The signer seeds prove the program controls that address.
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(- 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. - Line 162
transfer_checked(: A checked token transfer, which also verifies the mint and decimals. - Line 163
CpiContext::new(: Makes a cross-program invocation into another program. - Line 180
CpiContext::new_with_signer(: Makes a CPI signed by a PDA. The signer seeds prove the program controls that address.
apps/anchor/programs/darklake/src/instructions/initialize_pool.rs L13–36 @ 0719aa7 · MIT · originalpub 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- 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. - 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. - 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. - Line 34
pub payer: Signer<'info>,: Requires this account to have signed the transaction.
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], ];- Line 85
msg!("Amount X: {}", amount_x);: Logs to the program log, which is visible in explorers and the test output. - Line 89
CpiContext::new(: Makes a cross-program invocation into another program. - Line 103
let pool_signer_seeds = &[: Declares the PDA seeds. Anchor re-derives the address and rejects the account if it doesn't match. - 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.
| Directory | Command | Runs |
|---|---|---|
. | npm run dev | turbo run dev --parallel |
. | npm run lint | turbo run lint -- --fix --ext .js,.jsx,.ts,.tsx --ignore-pattern 'node_modules/*' |
apps/anchor | npm run build | anchor build |
apps/anchor | npm run test | anchor test |
apps/web | npm run dev | next dev |
apps/web | npm run start | next start |
apps/web | npm run build | next build |
apps/web | npm run test | TZ=UTC jest --detectOpenHandles |
apps/web | npm run lint | next lint && tsc --noEmit |
apps/server | npm run dev | nest start --watch --debug |
apps/server | npm run start | nest start |
apps/server | npm run build | nest build |
apps/server | npm run test | TZ=UTC jest --detectOpenHandles --passWithNoTests |
apps/server | npm run lint | eslint . && tsc --noEmit |
apps/anchor | anchor build | compile programs and generate IDLs |
apps/anchor | anchor test | local validator + test suite |
What you could build from it
- Fork the SuperStack copy and extend it within the Other gaps listed on the idea page.
- Learn the pattern first: Program Derived Addresses (PDAs)
- Learn the pattern first: Cross-Program Invocations (CPIs)