Full lesson
Anala
Anala is a research and lending layer for tokenized pre-IPO assets. It turns live market data, company signals, and protocol rules into a clear next action.
What it does
From the project README:
[](https://opensource.org/licenses/MIT) [](https://www.typescriptlang.org/) [](https://solana.com/) [](https://www.anchor-lang.com/)
- Original
- Agozie180/Anala
- SuperStack fork
- Blockchains/Anala @
11bef46 - Stars
- 0
- Last push (original)
- 2026-09-27
- Languages
- TypeScript, Rust, CSS, Shell, PowerShell, JavaScript
- Detected stack
- AnchorNext.jsweb3.js
- Categories
- DeFi
- Licence
- MIT
- Homepage
- https://anala-mu.vercel.app
Architecture
106 source files. By extension: .ts ×100, .tsx ×5, .rs ×1.
| Top-level directory | Source files |
|---|---|
src | 89 |
scripts | 13 |
(root) | 2 |
programs | 1 |
tests | 1 |
On-chain programs: programs/anala-lending
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/anala/. 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/anala-lending/src/lib.rs L85–108 @ 11bef46 · MIT · original let cpi_accounts = Transfer { from: ctx.accounts.user_token_account.to_account_info(), to: ctx.accounts.collateral_vault.to_account_info(), authority: ctx.accounts.user.to_account_info(), }; let cpi_program = ctx.accounts.token_program.to_account_info(); let cpi_ctx = CpiContext::new(cpi_program, cpi_accounts); token::transfer(cpi_ctx, amount)?; // Update position let position = &mut ctx.accounts.user_position; if position.owner == Pubkey::default() { position.owner = ctx.accounts.user.key(); position.pool = ctx.accounts.lending_pool.key(); position.collateral_amount = 0; position.borrowed_amount = 0; position.borrowed_at = 0; position.last_interest_update = Clock::get()?.unix_timestamp; position.bump = ctx.bumps.user_position; } position.collateral_amount = position.collateral_amount.checked_add(amount) .ok_or(ErrorCode::Overflow)?; // Update pool- Line 91
let cpi_ctx = CpiContext::new(cpi_program, cpi_accounts);: Makes a cross-program invocation into another program. - Line 92
token::transfer(cpi_ctx, amount)?;: An SPL token transfer through the Token Program. - Line 102
position.last_interest_update = Clock::get()?.unix_timestamp;: Reads on-chain time from the Clock sysvar. - Line 103
position.bump = ctx.bumps.user_position;: Uses the bump seed, the extra byte that pushes the derived address off the ed25519 curve. - Line 105
position.collateral_amount = position.collateral_amount.checked_add(amount): Uses checked arithmetic so overflow fails instead of wrapping.
scripts/push-prices.ts L61–84 @ 11bef46 · MIT · original OPENAI: process.env.NEXT_PUBLIC_OPENAI_MINT || '', SPACEX: process.env.NEXT_PUBLIC_SPACEX_MINT || '', };} function poolPda(collateralMint: PublicKey): PublicKey { return PublicKey.findProgramAddressSync( [Buffer.from('lending_pool'), collateralMint.toBuffer()], PROGRAM_ID, )[0];} async function send(connection: Connection, wallet: Keypair, ix: TransactionInstruction): Promise<string> { const { blockhash, lastValidBlockHeight } = await connection.getLatestBlockhash(); const tx = new Transaction({ feePayer: wallet.publicKey, blockhash, lastValidBlockHeight }).add(ix); const sig = await connection.sendTransaction(tx, [wallet], { preflightCommitment: 'confirmed' }); await connection.confirmTransaction({ signature: sig, blockhash, lastValidBlockHeight }, 'confirmed'); return sig;} /** Best-effort refreshed LTV (bps), clamped to the on-chain [3000, 7500] bounds. */async function ltvBpsFor(symbol: string): Promise<number | null> { const withTimeout = <T>(p: Promise<T>, ms: number) => Promise.race([p, new Promise<T>((_, r) => setTimeout(() => r(new Error(`timeout after ${ms}ms`)), ms))]);- Line 67
return PublicKey.findProgramAddressSync(: Derives a PDA from seeds and the program ID and returns the address with its canonical bump. - Line 74
const { blockhash, lastValidBlockHeight } = await connection.getLatestBlockhash();: Fetches a recent blockhash. Transactions expire if it gets too old. - Line 76
const sig = await connection.sendTransaction(tx, [wallet], { preflightCommitment: 'confirm: Submits the signed transaction to the cluster.
src/lib/defi/lending.ts L241–264 @ 11bef46 · MIT · original return 0; // no ATA yet, or RPC hiccup — treat as zero balance }} // --- transaction context supplied by the wallet adapter ---export interface WalletCtx { connection: Connection; publicKey: PublicKey; sendTransaction: (tx: Transaction, connection: Connection) => Promise<TransactionSignature>;} async function sendIxs(ctx: WalletCtx, instructions: TransactionInstruction[]): Promise<string> { const { connection, publicKey, sendTransaction } = ctx; const { blockhash, lastValidBlockHeight } = await connection.getLatestBlockhash(); const tx = new Transaction({ feePayer: publicKey, blockhash, lastValidBlockHeight }); tx.add(...instructions); const signature = await sendTransaction(tx, connection); await connection.confirmTransaction({ signature, blockhash, lastValidBlockHeight }, 'confirmed'); return signature;} /** Prepend an ATA-creation instruction when `owner` has no token account for `mint`. */async function ensureAtaIx( connection: Connection,- Line 249
sendTransaction: (tx: Transaction, connection: Connection) => Promise<TransactionSignature: Submits the signed transaction to the cluster. - Line 254
const { blockhash, lastValidBlockHeight } = await connection.getLatestBlockhash();: Fetches a recent blockhash. Transactions expire if it gets too old.
scripts/setup-devnet.ts L133–156 @ 11bef46 · MIT · original): Promise<{ pool: PublicKey; borrowVault: PublicKey; created: boolean }> { const { pool, collateralVault, borrowVault } = derivePdas(collateralMint); if (await connection.getAccountInfo(pool)) { console.log(' pool already initialized:', pool.toBase58()); return { pool, borrowVault, created: false }; } const data = Buffer.concat([disc('initialize_pool'), u16(ltvBps), u16(interestBps), u64(priceBase)]); const keys = [ { pubkey: pool, isSigner: false, isWritable: true }, { pubkey: collateralMint, isSigner: false, isWritable: false }, { pubkey: usdcMint, isSigner: false, isWritable: false }, { pubkey: collateralVault, isSigner: false, isWritable: true }, { pubkey: borrowVault, isSigner: false, isWritable: true }, { pubkey: wallet.publicKey, isSigner: true, isWritable: true }, { pubkey: SystemProgram.programId, isSigner: false, isWritable: false }, { pubkey: TOKEN_PROGRAM_ID, isSigner: false, isWritable: false }, { pubkey: SYSVAR_RENT_PUBKEY, isSigner: false, isWritable: false }, ]; const ix = new TransactionInstruction({ programId: PROGRAM_ID, keys, data }); const { blockhash, lastValidBlockHeight } = await connection.getLatestBlockhash(); const tx = new Transaction({ feePayer: wallet.publicKey, blockhash, lastValidBlockHeight }).add(ix); const sig = await connection.sendTransaction(tx, [wallet], { preflightCommitment: 'confirmed' }); await connection.confirmTransaction({ signature: sig, blockhash, lastValidBlockHeight }, 'confirmed'); console.log(' ✓ pool initialized:', pool.toBase58(), 'tx', sig);- Line 152
const { blockhash, lastValidBlockHeight } = await connection.getLatestBlockhash();: Fetches a recent blockhash. Transactions expire if it gets too old. - Line 154
const sig = await connection.sendTransaction(tx, [wallet], { preflightCommitment: 'confirm: Submits the signed transaction to the cluster.
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 | next dev --port 3100 |
. | npm run start | next start --port 3100 |
. | npm run build | next build |
. | npm run test | vitest run --config vitest.config.mjs |
. | anchor build | compile programs and generate IDLs |
. | anchor test | local validator + test suite |
. | anchor run test | yarn run ts-mocha -p ./tsconfig.json -t 1000000 tests/**/*.ts |
. | cargo build | Rust workspace build |
. | cargo test | Rust tests |
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