Architecture
BTCVault’s smart contract system is built on Cairo 2.14.0 for StarkNet, implementing a comprehensive suite of DeFi vault strategies centered around Bitcoin yield generation. The contracts follow the ERC-4626 tokenized vault standard, enabling composable yield strategies across multiple protocols.Core Design Principles
ERC-4626 Vault Standard: All vaults implement the standardized vault interface, allowing users to deposit assets and receive yield-bearing share tokens. The share price increases as the vault accrues yield from underlying strategies. Curator Pattern: Each vault has an owner (curator) who manages strategy execution, including deploying capital to lending protocols, executing leverage loops, and harvesting yield. Users maintain custody of their vault shares. Ownable & Upgradeable: Contracts use a 2-step ownership transfer pattern for security and implement upgradeable proxies via StarkNet’sreplace_class_syscall mechanism.
Flash Loan Unwind: Leveraged vaults use Vesu flash loans to atomically unwind positions, ensuring users can always withdraw their funds without manual deleverage steps.
Contract Inventory
The following Cairo contracts implement the BTCVault protocol:| Contract | Lines | Purpose |
|---|---|---|
btcvault.cairo | 1,210 | Core BTC yield vault: deposits WBTC into Vesu lending pools with 3x leverage loops for amplified yield |
apex.cairo | 1,502 | Advanced multi-strategy vault aggregator with dynamic allocation |
delta_neutral.cairo | 1,095 | Delta-neutral strategy vault combining long BTC collateral with short perpetual positions |
trident.cairo | 1,003 | Liquidity provision strategy for concentrated liquidity pools (Ekubo) |
citadel.cairo | 751 | Vault manager and registry for protocol-level coordination |
stablecoin_vault.cairo | 622 | USDC lending vault on Vesu RE7 USDC Core pool (no leverage) |
sentinel.cairo | 625 | Simple WBTC lending vault on Vesu without leverage |
shielded_pool_v4.cairo | 660 | Latest version of privacy-preserving pool using Garaga ZK proofs |
shielded_pool_v3.cairo | 639 | Privacy pool v3 with Groth16 verification |
shielded_pool.cairo | 490 | Initial privacy pool implementation |
shielded_pool_v2.cairo | 459 | Privacy pool v2 iteration |
shielded_swap_pool.cairo | 499 | Privacy-preserving token swap pool |
dca.cairo | 549 | Dollar-cost averaging vault for automated periodic purchases |
cdp.cairo | 447 | Collateralized debt position vault |
interfaces.cairo | 362 | Interface definitions for Vesu, AVNU, Ekubo, Garaga, Pragma |
strategy.cairo | 47 | Strategy helper utilities and constants |
lib.cairo | 16 | Module declarations |
Common Patterns
Ownable Pattern
All vaults implement 2-step ownership transfer for security:Upgradeable Pattern
Contracts can be upgraded by the curator using StarkNet’s class replacement mechanism:Flash Loan Unwind Pattern
Leveraged vaults implementIFlashloanReceiver to enable atomic position unwinding:
Technology Stack
Core Dependencies
Cairo 2.14.0: StarkNet’s native smart contract language, providing provable computation and low gas costs. Scarb 2.14.0: Cairo package manager and build tool, similar to Cargo for Rust. Garaga 1.0.1: Zero-knowledge proof verification library for StarkNet, enabling privacy features through Groth16 (BN254) and UltraHonk proof systems. StarkNet 2.14.0: Layer 2 scaling solution for Ethereum with native account abstraction.Protocol Integrations
The contracts integrate with the following StarkNet protocols:- Vesu: Lending protocol for collateral deposits and debt borrowing (primary yield source)
- AVNU: DEX aggregator for optimal swap routing between WBTC and USDC
- Ekubo: Concentrated liquidity AMM for efficient swaps and LP positions
- Pragma: Oracle network providing BTC/USD and other price feeds
- OpenZeppelin: Standard contract implementations (via StarkNet dependency)
External Interfaces
Key external interfaces defined ininterfaces.cairo:
IVesuPool: Lending pool operations (deposit, borrow, modify_position, flash_loan)IERC4626: Tokenized vault standard (deposit, withdraw, redeem, mint)IAvnuExchange: Multi-route swap aggregatorIEkuboCore: Concentrated liquidity pool managementIGaragaVerifier: Zero-knowledge proof verification (UltraHonk)IGroth16Verifier: Groth16 BN254 proof verificationIPragmaOracle: Price feed queries and TWAP calculations
Curator Vault Management
The curator role is central to vault operations. Curators are trusted operators who execute strategies on behalf of depositors: Capital Deployment: Deploy idle vault assets to Vesu lending pools:Security Features
- Pausable: Vaults can be paused by curator in emergencies
- 2-Step Ownership Transfer: Prevents accidental ownership loss
- Slippage Protection: All swaps require minimum output amounts
- Dust Threshold Validation: Vesu positions must meet minimum value requirements
- Flash Loan Security: Callbacks verify sender is the vault itself
- Atomic Operations: Leverage loops and unwinds execute atomically to prevent partial state
Next Steps
Deployment Guide
Learn how to build and deploy Cairo contracts to StarkNet
API Reference
Explore contract interfaces and function signatures