Skip to content

Architecture

System Overview

┌─────────────────────────────────────────────────────────┐
│                      STARKNET                           │
│  ┌─────────────────────────────────────────────────┐   │
│  │              Rhadow Vault (Cairo)                │   │
│  │  • ERC-4626 tokenized vault                      │   │
│  │  • Holds USDC + wBTC                             │   │
│  │  • Access control (Admin, Keeper, Strategist)   │   │
│  │  • Upgradeable proxy                             │   │
│  └─────────────────────────────────────────────────┘   │
└─────────────────────────────────────────────────────────┘

                           │ Starknet RPC

┌─────────────────────────────────────────────────────────┐
│                    KEEPER (Python)                       │
│  ┌──────────────┐  ┌──────────────┐  ┌──────────────┐  │
│  │ Vault Client │  │Extended Client│  │ AVNU Client  │  │
│  │ (starknet-py)│  │  (REST API)  │  │  (REST API)  │  │
│  └──────────────┘  └──────────────┘  └──────────────┘  │
│                           │                             │
│  ┌─────────────────────────────────────────────────┐   │
│  │           Delta-Neutral Strategy Engine          │   │
│  │  • State machine (IDLE/ACTIVE/REBALANCING)      │   │
│  │  • Funding rate monitoring                       │   │
│  │  • Position management                           │   │
│  │  • Profit harvesting                             │   │
│  └─────────────────────────────────────────────────┘   │
└─────────────────────────────────────────────────────────┘

            ┌──────────────┴──────────────┐
            ▼                             ▼
┌───────────────────────┐    ┌───────────────────────┐
│     Extended DEX      │    │         AVNU          │
│  • BTC perpetuals     │    │  • DEX aggregator     │
│  • Funding payments   │    │  • wBTC ↔ USDC swaps  │
│  • SNIP-12 signing    │    │  • Multi-route        │
└───────────────────────┘    └───────────────────────┘

Components

Vault Contract (Cairo)

~1,300 lines of Cairo implementing:

ComponentPurpose
ERC-4626Tokenized vault standard
ERC-20Share token (rUSDC)
AccessControlRole-based permissions
PausableEmergency stop
ReentrancyGuardAttack prevention
UpgradeableProxy pattern

Storage:

cairo
asset_token: USDC (bridged)
native_usdc_token: USDC (native)
wbtc_token: wBTC
trading_account: Keeper's account
allocated_margin: USDC on Extended
btc_price_usd: Price oracle
avnu_exchange: Swap router

Keeper Service (Python)

~4,600 lines of Python with:

ModulePurpose
main.pyEntry point, lifecycle
strategy/delta_neutral.pyCore strategy logic
vault/client.pyStarknet interactions
extended/client.pyPerp DEX API
extended/signer.pySNIP-12 order signing
dex/avnu.pySwap aggregator
api.pyStats REST API

API Server (FastAPI)

Exposes vault statistics:

EndpointDescription
GET /healthHealth check
GET /statsVault TVL, APR, positions
GET /user/{address}User share balance and value

Data Flow

Deposit:

User USDC → Vault → Mint rUSDC shares

         Keeper allocates:
         • 50% → Buy wBTC (AVNU)
         • 50% → Short margin (Extended)

Yield:

Extended funding → Keeper margin account

              Keeper calls report(profit)

              Vault total_assets increases

              Share price increases

Withdraw:

User burns rUSDC → Vault checks liquidity

              If sufficient: Send USDC
              If not: Keeper unwinds position

Security Model

Roles:

RolePermissions
AdminConfiguration, upgrades, roles
KeeperMargin allocation, swaps, reporting
StrategistPause/unpause
UserDeposit, withdraw

Safety:

  • 1x leverage (no liquidation)
  • 20% min liquidity buffer
  • 24h stale threshold blocks withdrawals
  • Reentrancy protection
  • Pausable for emergencies