System Architecture
Sable is a full-stack DeFi application combining a Next.js frontend, Cairo smart contracts, and integrations with 8+ external protocols on StarkNet.High-Level Architecture
Data Flow
User interactions flow through multiple layers:Example: Vault Deposit Flow
Frontend Stack
Core Technologies
| Layer | Technology | Version | Purpose |
|---|---|---|---|
| Framework | Next.js | 16.1.6 | App Router, RSC, API routes |
| UI Library | React | 19.2.3 | Component rendering |
| Language | TypeScript | 5.x | Type safety |
| Styling | Tailwind CSS | 4.x | Utility-first CSS |
| Animations | Motion | 12.6.3 | Smooth transitions |
| Charts | Recharts | 2.15.3 | APY/TVL visualizations |
| StarkNet Client | starknet.js | 8.1.2 | Contract interactions |
| Wallet Integration | @starknet-react/core | 5.0.3 | Wallet providers |
Key Dependencies
Application Structure
Smart Contract Stack
Technologies
| Component | Technology | Version |
|---|---|---|
| Language | Cairo | 2.14.0 |
| Compiler | Scarb | 2.13.1 |
| Blockchain | StarkNet | Mainnet |
| Standard | ERC-4626 | Tokenized vaults |
| ZK Verifier | Garaga | 1.0.1 |
Contract Inventory
Vault Contracts (ERC-4626)
Vault Contracts (ERC-4626)
All vault contracts implement the ERC-4626 tokenized vault standard:
All vaults expose:
| Contract | File | Strategy | LOC |
|---|---|---|---|
| Sentinel | sentinel.cairo | Pure Vesu PRIME lending | ~500 |
| Citadel | citadel.cairo | Endur staking + Vesu lending | ~600 |
| Trident | trident.cairo | 3x recursive staking loop | ~700 |
| Delta Neutral | delta_neutral.cairo | Collateral → borrow USDC → deploy | ~800 |
| Turbo | btcvault.cairo | Leverage loop (deposit → borrow → swap → repeat) | ~900 |
| Apex | apex.cairo | 40% lending + 35% LP + 25% staking | ~1000 |
deposit(assets, receiver) -> shareswithdraw(assets, receiver, owner) -> sharestotal_assets() -> uint256convert_to_shares(assets) -> sharesconvert_to_assets(shares) -> assets
Privacy Contracts (Groth16)
Privacy Contracts (Groth16)
Zero-knowledge proof contracts for shielded deposits/withdrawals:
Verifier Addresses:
| Contract | File | Proof System | Status |
|---|---|---|---|
| Shielded Pool V4 | shielded_pool_v4.cairo | Groth16 BN254 (7 public inputs) | Current |
| Shielded Pool V3 | shielded_pool_v3.cairo | Groth16 BN254 (6 public inputs) | Legacy |
| Shielded Swap Pool | shielded_swap_pool.cairo | Groth16 BN254 | Current |
| Stablecoin Vault | stablecoin_vault.cairo | Groth16 BN254 | Current |
- V4 Verifier:
0x03329c4d5c2e37dfd20d46c3c20be9230b2152c71947ead441c342d989d52ffa - V3 Verifier:
0x041011d7912b6759f2fe3cc66a1f746b81ec012c2774adabc77eecc299e0878d
DeFi Primitives
DeFi Primitives
| Contract | File | Purpose | LOC |
|---|---|---|---|
| DCA | dca.cairo | Recurring orders with Mayer Multiple strategy | ~600 |
| CDP | cdp.cairo | WBTC → USDC borrowing via Nostra | ~500 |
ERC-4626 Vault Mechanics
All vaults follow the ERC-4626 standard:Protocol Integrations
Vesu V2 — Lending/Borrowing
Role: Primary yield source for all vaults Contract:0x000d8d6dfec4d33bfb6895de9f3852143a17c6f92fd2a21da3d6924d34870160
Integration Points:
- Supply WBTC to PRIME pool (Sentinel, Turbo)
- Supply xWBTC to Re7 xBTC pool (Citadel)
- Borrow USDC against WBTC collateral (Delta Neutral, Turbo)
- Stake WBTC directly via
/stakepage
AVNU — DEX Aggregation
Role: Optimal swap routing for DCA and vault strategies Contract:0x04270219d365d6b017231b52e92b3fb5d7c8378b05e9abc97724537a80e93b0f
Integration Points:
- DCA execution (USDC/ETH/STRK → WBTC)
- Turbo leverage loop (borrowed USDC → WBTC)
- Private swap output (WBTC → ETH/USDC/STRK)
Ekubo — Concentrated Liquidity
Role: LP provision for Apex vault (35% allocation) Integration Points:- Provide liquidity to WBTC-ETH or WBTC-USDC pools
- Earn trading fees from concentrated liquidity positions
- Auto-compound fees back into LP positions
Endur — Liquid Staking
Role: Liquid staking yield for Citadel, Trident, and Apex vaults Integration Points:- Stake WBTC → receive xWBTC (liquid staking token)
- xWBTC accrues staking yield automatically
- Supply xWBTC to Vesu for dual yield (staking + lending)
Nostra — CDP Lending
Role: Backend for Sable CDP contract Contract:0x073f6addc9339de9822cab4dac8c9431779c09077f02ba7bc36904ea342dd9eb
Integration Points:
- Deposit WBTC as collateral (iWBTC-c token)
- Borrow USDC against collateral (dUSDC token)
- Repay debt and withdraw collateral
- iWBTC-c:
0x05b7d301fa769274f20e89222169c0fad4d846c366440afc160aafadd6f88f0c - dUSDC:
0x063d69ae657bd2f40337c39bf35a870ac27ddf91e6623c2f52529db4c1619a51
Pragma — Price Oracle
Role: Price feeds for DCA Mayer Multiple and CDP liquidation calculations Contract:0x02a85bd616f912537c50a49a4076db02c00b29b2cdc8a197ce92ed1837fa875b
Integration Points:
- BTC/USD spot price
- 200-day Time-Weighted Average Price (TWAP)
- Mayer Multiple = spot_price / twap_200d
Garaga — ZK Verification
Role: On-chain Groth16 BN254 proof verification Integration Points:- Verify shielded deposit proofs
- Verify shielded withdrawal proofs
- Poseidon hash function for commitments/nullifiers
0x03329c4d5c2e37dfd20d46c3c20be9230b2152c71947ead441c342d989d52ffa
Proof Structure:
NEAR Intents / 1-Click — Cross-Chain Bridge
Role: Bridge assets to/from StarkNet Supported Chains: Solana, Ethereum, Base, Arbitrum, Polygon, Avalanche, NEAR Integration Points:- Bridge IN: External chain → StarkNet (receive STRK/WBTC/ETH)
- Bridge OUT: StarkNet → External chain (send STRK, receive native tokens)
Security Considerations
Smart Contract Security
- All contracts compiled with Cairo 2.14.0 (stable)
- ERC-4626 standard implementation reduces attack surface
- Ownable pattern: only curator can call
deploy_idle() - Upgradeable via UUPS pattern (owner can upgrade implementation)
- Flash loan protection: reentrancy guards on deposit/withdraw
ZK Privacy Security
- Groth16 proofs verified on-chain via Garaga (audited)
- Poseidon hash function (StarkNet-native, efficient)
- Nullifier prevents double-spend (stored on-chain)
- Merkle tree commitments (depth 20 = ~1M deposits supported)
- Notes stored locally in browser (losing note = losing funds)
Frontend Security
- No private keys stored client-side
- All transactions signed via wallet extension
- Contract addresses hardcoded in constants.ts
- RPC endpoints: Lava (free) or user-provided Alchemy
- CORS protected API routes for curator/relayer operations
Performance Optimizations
Frontend
- Next.js 16 App Router with React Server Components
- Turbopack for instant hot reload in dev
- Static generation for vault listing page
- Dynamic imports for ZK proof WASM (~4MB)
- 30-second cache on price API calls
Smart Contracts
- Batch deposits (3 at a time) reduce Merkle tree update gas
- Flash loans for atomic unwind of complex positions
- Lazy deployment: idle funds not deployed until
deploy_idle()called - Packed storage for gas efficiency
Monitoring & Analytics
On-Chain Data
- All transactions visible on Voyager and Starkscan
- Deployer account:
0x0007842590942b769a203cfcb07540299b86e22ba05b6708b516ec04ca044ef7(408+ txs) - Tester account:
0x0362A762F25f0aa9C3935D4D11D5d5099262E4fF59f5D360d37BD157fBC3ABbc(98+ txs)
APY Calculation
APY is calculated from multiple sources:Development Workflow
Local Development
Contract Deployment
Running Keeper Bot
Additional Resources
Smart Contracts
Detailed documentation on each Cairo contract
API Reference
REST API endpoints for curator, relayer, and keeper operations
Privacy Deep Dive
How zero-knowledge proofs enable shielded transactions
GitHub Repository
View full source code and contribute