btcusd-stablecoin/
βββ contracts/ # Cairo smart contracts
β βββ Scarb.toml # Scarb package config
β βββ src/
β β βββ lib.cairo # Main library entry point
β β β
β β βββ interfaces/ # All contract interfaces (imported first)
β β β βββ lib.cairo
β β β βββ i_btcusd_token.cairo
β β β βββ i_btcusd_vault.cairo
β β β βββ i_yield_manager.cairo
β β β βββ i_price_oracle.cairo
β β β βββ i_wbtc.cairo
β β β βββ i_liquidator.cairo
β β β
β β βββ core/ # Core protocol contracts
β β β βββ lib.cairo
β β β βββ btcusd_token.cairo
β β β βββ btcusd_vault.cairo
β β β βββ yield_manager.cairo
β β β
β β βββ oracles/ # Oracle adapters (Stage 2+)
β β β βββ lib.cairo
β β β βββ mock_oracle.cairo
β β β βββ pragma_oracle.cairo
β β β
β β βββ liquidation/ # Liquidation module (Stage 2)
β β β βββ lib.cairo
β β β βββ liquidator.cairo
β β β
β β βββ integrations/ # External integrations (Stage 3-4)
β β β βββ lib.cairo
β β β βββ vesu_adapter.cairo
β β β βββ atomiq_adapter.cairo
β β β
β β βββ mocks/ # Mock contracts for testing
β β βββ lib.cairo
β β βββ mock_wbtc.cairo
β β βββ mock_vesu_pool.cairo
β β
β βββ tests/ # Contract tests
β βββ test_btcusd_token.cairo
β βββ test_btcusd_vault.cairo
β βββ test_yield_manager.cairo
β βββ test_integration.cairo
β
βββ app/ # React Native mobile app
β βββ package.json
β βββ tsconfig.json
β βββ app.json
β βββ App.tsx
β βββ src/
β β βββ screens/
β β β βββ ConnectWallet.tsx
β β β βββ Dashboard.tsx
β β β βββ Deposit.tsx
β β β βββ Withdraw.tsx
β β βββ components/
β β β βββ PositionCard.tsx
β β β βββ YieldCard.tsx
β β β βββ TransactionButton.tsx
β β βββ services/
β β β βββ starknet.ts # Starknet provider setup
β β β βββ contracts.ts # Contract ABIs and addresses
β β β βββ wallet.ts # Wallet connection
β β βββ hooks/
β β β βββ usePosition.ts
β β β βββ useYield.ts
β β β βββ useWallet.ts
β β βββ store/
β β β βββ index.ts # Zustand store
β β βββ types/
β β β βββ index.ts
β β βββ constants/
β β βββ addresses.ts
β β βββ abis.ts
β βββ assets/
β
βββ backend/ # Keeper services & monitoring
β βββ package.json
β βββ tsconfig.json
β βββ src/
β β βββ keepers/
β β β βββ liquidation-bot.ts
β β β βββ yield-harvester.ts
β β β βββ price-monitor.ts
β β βββ services/
β β β βββ starknet.ts
β β β βββ alerts.ts
β β βββ config/
β β βββ index.ts
β βββ scripts/
β βββ deploy.ts
β βββ verify.ts
β
βββ packages/ # Shared packages
β βββ common/
β βββ package.json
β βββ src/
β βββ types.ts # Shared TypeScript types
β βββ constants.ts # Protocol constants
β βββ utils.ts # Shared utilities
β
βββ docs/ # Documentation
β βββ ROADMAP.md
β βββ DEPLOYMENT.md
β βββ SECURITY.md
β βββ API.md
β
βββ scripts/ # Root-level scripts
β βββ setup.sh
β βββ deploy-testnet.sh
β
βββ .github/
β βββ workflows/
β βββ test.yml
β βββ deploy.yml
β
βββ package.json # Root workspace config
βββ README.md # This file
Goal: Working vault with deposit/mint/burn/withdraw, mock yield tracking
| Component | Description | Status |
|---|---|---|
| BTCUSDToken | ERC20 stablecoin with vault-only minting | β Done |
| BTCUSDVault | Core collateralization logic | β Done |
| MockYieldManager | Virtual yield tracking (no real Vesu) | β Done |
| MockOracle | Configurable BTC price for testing | β Done |
| MockWBTC | Test ERC20 for wBTC | β Done |
Deliverables:
- Contracts compile with Cairo 2.9 / OZ v0.20.0
- Comprehensive test suite (5 test files, 80+ tests)
- Deploy script for testnet
- Basic mobile app connects to testnet
- Can deposit β mint β burn β withdraw
Goal: Add liquidation mechanism with health factor monitoring
| Component | Description | Status |
|---|---|---|
| PragmaOracle adapter | Real price feeds from Pragma Network | β Done |
| Liquidator contract | Handles partial and full liquidations | β Done |
| Health factor calculations | Already in vault (needs integration) | β Done |
| Keeper bot | Monitors positions, triggers liquidations | β Done |
Deployed Contracts (Sepolia):
- Liquidator:
0x047920e18d296dd5f5da36613a83e3b9badc019cb4e0d59f5fae8af2bae9141c
Goal: Collateral earns yield in Vesu lending pools
| Component | Description | Status |
|---|---|---|
| VesuYieldManager | Replaces MockYieldManager with real Vesu | β Done |
| IVesuSingleton adapter | Interface to Vesu Singleton contract | β Done |
| Deposit/withdraw to Vesu | Real wBTC yield generation | β Done |
| Fee distribution | Split yield between users and protocol | β Done |
Deployed Contracts (Sepolia):
- VesuYieldManager:
0x050079ad8253da45dc0ab0c724c85cd07198b230e0cd7d123b8bd6520ce879f0 - Vesu Singleton:
0x2110b3cde727cd34407e257e1070857a06010cf02a14b1ee181612fb1b61c30 - Vesu Pool ID:
566154675190438152544449762131613456939576463701265245209877893089848934391
Goal: Real BTC β wBTC bridge flow with Xverse wallet integration
| Component | Description |
|---|---|
| AtomiqAdapter | Interface to Atomiq bridge contracts |
| Bridge relayer | Backend service for BTC confirmation |
| Xverse/Sats Connect | Mobile wallet connection |
| Deep linking | Open Xverse from BTCUSD app |
Atomiq Integration:
// backend/src/services/atomiq-bridge.ts
interface AtomiqBridge {
// Generate deposit address for user
generateDepositAddress(starknetAddress: string): Promise<{
btcAddress: string;
expiresAt: number;
}>;
// Monitor for BTC confirmations
watchDeposit(btcAddress: string): Promise<{
txHash: string;
amount: bigint;
confirmations: number;
}>;
// Mint wBTC on Starknet once confirmed
completeBridge(
starknetAddress: string,
btcTxHash: string,
amount: bigint
): Promise<string>; // Returns Starknet tx hash
}Xverse/Sats Connect Integration:
// app/src/services/xverse.ts
import { request, RpcMethod } from 'sats-connect';
interface XverseWallet {
// Check if Xverse is installed (mobile: always false, use deep link)
isInstalled(): boolean;
// Connect and get BTC address
connect(): Promise<{
btcAddress: string;
starknetAddress?: string;
}>;
// Send BTC to bridge address
sendBTC(params: {
recipient: string;
amount: number; // in satoshis
}): Promise<string>; // Returns BTC tx hash
// Deep link to Xverse browser with our app
openInXverse(url: string): void;
}
// Deep link format for mobile:
// https://connect.xverse.app/browser?url=YOUR_APP_URLMobile App Flow (Stage 4):
- User taps "Deposit BTC"
- App requests deposit address from Atomiq
- Shows QR code OR opens Xverse via deep link
- User sends BTC from Xverse
- Backend monitors BTC tx, triggers wBTC mint
- App shows wBTC balance, user can deposit to vault
Goal: Full system running on Starknet Sepolia
| Component | Description | Status |
|---|---|---|
| Deployment scripts | Automated testnet deployment | β Done |
| Contract verification | Verify on Starkscan/Voyager | β Done |
| Monitoring dashboard | Protocol health metrics | β Done |
| User documentation | How-to guides | Pending |
| Bug bounty setup | Immunefi or similar | Pending |
Deployment:
./scripts/deploy-testnet.shMonitoring: The backend includes a monitoring service that exports Prometheus-compatible metrics:
- TVL and debt tracking
- Collateral ratio monitoring
- Price feed health
- Yield statistics
- Alert generation
Goal: Production-ready protocol
| Component | Description |
|---|---|
| Internal review | Code freeze, final testing |
| External audit | Professional security audit |
| Fixes & re-audit | Address findings |
| Formal verification | Invariant proofs (optional) |
| Mainnet deployment | Production launch |
Security Audit Scope:
-
Core Contracts:
BTCUSDToken- ERC20 with vault-only mintingBTCUSDVault- Collateralization, position managementMockYieldManager/VesuYieldManager- Yield generation
-
Liquidation Module:
Liquidator- Health checks, liquidation execution- Keeper bot logic
-
External Integrations:
VesuYieldManager- Vesu Singleton integrationAtomiqAdapter- Bitcoin bridge interface
-
Access Control:
- Owner functions and pause mechanisms
- Vault-only token minting
- Liquidator authorization
Security Checklist:
- No reentrancy vulnerabilities
- Integer overflow/underflow protection (Cairo handles this)
- Access control properly implemented
- Oracle manipulation resistance
- Flash loan attack resistance
- Front-running resistance
- Emergency pause functionality
- Upgrade timelock (if upgradeable)
Mainnet Launch Plan:
- Soft Launch: Limited TVL cap ($100k), invite-only
- Public Launch: Remove cap, public access
- Growth: Marketing, partnerships, integrations
- wBTC: 8 decimals (standard Bitcoin)
- BTCUSD: 18 decimals (standard ERC20)
- Prices: 8 decimals (Pragma/Chainlink standard)
- Ratios: Basis points (10000 = 100%)
MIN_COLLATERAL_RATIO = 15000 (150%)
LIQUIDATION_THRESHOLD = 12000 (120%)
MAX_LTV = 6667 (66.67%)
health_factor = (collateral_value * PRECISION) / debt_value
liquidatable if health_factor < LIQUIDATION_THRESHOLD
USER_SHARE = 7000 (70%)
PROTOCOL_SHARE = 3000 (30%)
user_yield = total_yield * USER_SHARE / 10000
protocol_yield = total_yield * PROTOCOL_SHARE / 10000
- Owner: Can pause, upgrade, set parameters
- Vault: Only address that can mint/burn BTCUSD
- YieldManager: Only vault can deposit/withdraw collateral
- Liquidator: Anyone can liquidate unhealthy positions
// Precision for percentage calculations (basis points)
const PRECISION: u256 = 10000;
// Collateralization parameters
const MIN_COLLATERAL_RATIO: u256 = 15000; // 150%
const LIQUIDATION_THRESHOLD: u256 = 12000; // 120%
const MAX_LTV: u256 = 6667; // 66.67%
// Liquidation parameters
const LIQUIDATION_PENALTY: u256 = 1000; // 10%
const LIQUIDATION_REWARD: u256 = 500; // 5% to liquidator
// Yield parameters
const USER_YIELD_SHARE: u256 = 7000; // 70%
const PROTOCOL_YIELD_SHARE: u256 = 3000; // 30%
// Decimals
const WBTC_DECIMALS: u8 = 8;
const BTCUSD_DECIMALS: u8 = 18;
const PRICE_DECIMALS: u8 = 8;- Solvency:
total_collateral_value >= total_debt_value * MIN_COLLATERAL_RATIO / PRECISION - Supply:
btcusd_total_supply == sum(all_user_debts) - Collateral:
vault_wbtc_balance + yield_manager_wbtc_balance >= sum(all_user_collateral) - Minting: Only vault can mint/burn BTCUSD
- No free lunch: User cannot mint BTCUSD without depositing collateral
- Health: After any operation, position must have
collateral_ratio >= MIN_COLLATERAL_RATIOORdebt == 0 - Withdrawal: Cannot withdraw collateral if it would make position unhealthy
- Minting: Cannot mint if it would make position unhealthy
| Contract | Address |
|---|---|
| BTCUSDVault | 0x05d8736f22d6eb6b347ec1ee9b8f7cf093057610ed394dd54593c7c93757a6c1 |
| BTCUSDToken | 0x01cacb0278219b58914ea2a02695a7288f3b4f4a4fdf7911f56f21a1c3095345 |
| MockWBTC | 0x034127ccbb52ed9ab742db89fdb6d261833e118dd5aa1c69f54258553388f6fb |
| MockOracle | 0x0198de7b85d16fa058a9d9736d2243a6e50478105008f5482ad8e8c4fa0aa13e |
| MockYieldManager | 0x07fe41efd9c731c25610f7d9d28d0de8ec4e46695155354845da1c9b7fef94b8 |
| VesuYieldManager | 0x050079ad8253da45dc0ab0c724c85cd07198b230e0cd7d123b8bd6520ce879f0 |
| Liquidator | 0x047920e18d296dd5f5da36613a83e3b9badc019cb4e0d59f5fae8af2bae9141c |
- Node.js 18+
- Scarb (Cairo package manager)
- Expo CLI for mobile development
cd contracts
scarb build
snforge testcd app
npm install
npm run ios # or npm run androidcd backend
npm install
npm run dev