Dynamic Asset-Backed Stability Pool


Inspiration

Traditional finance holds over $100 trillion in equities, yet these assets sit idle while DeFi offers compelling yields. Tokenized stock holders face a frustrating choice: sell (triggering taxes) or watch their assets earn nothing.

We asked: What if you could use your stock holdings exactly like ETH or USDC in DeFi?

xStocks Protocol answers this by making tokenized equities first-class citizens in DeFi—collateral that earns yield, backs stable assets, and participates in automated strategies.


What it does

xStocks Protocol lets users deposit tokenized equities (xStocks) as collateral to mint xUSD, a stable synthetic asset. The Dynamic Asset-Backed Stability Pool creates a yield-bearing safety net for the entire system.

How It Works

┌─────────────────────────────────────────────────────────────┐
│                                                             │
│   1. DEPOSIT xSTOCKS          2. MINT xUSD                 │
│   ┌─────────────┐            ┌─────────────┐               │
│   │   xAAPL     │   ──────▶  │   xUSD      │               │
│   │   xMSFT     │            │   Stable    │               │
│   │   xGOOGL    │            │   Coin      │               │
│   └─────────────┘            └─────────────┘               │
│         │                          │                        │
│         │                          ▼                        │
│         │              ┌─────────────────────┐             │
│         │              │  STABILITY POOL     │             │
│         │              │  • Earn 5-15% APY   │             │
│         │              │  • Backs liquidations│            │
│         │              │  • Receives discounted│           │
│         │              │    collateral       │             │
│         │              └─────────────────────┘             │
│         │                          │                        │
│         ▼                          ▼                        │
│   ┌─────────────────────────────────────────────┐          │
│   │         AUTOMATED KEEPER NETWORK            │          │
│   │  • Monitors positions  • Triggers liquidations        │
│   │  • Harvests yield      • Updates interest rates       │
│   └─────────────────────────────────────────────┘          │
└─────────────────────────────────────────────────────────────┘

Key Features

Feature What It Does
Collateralized Debt Positions Deposit xStocks, mint xUSD, maintain 150% collateral ratio
Dynamic Interest Rates Rates adjust automatically based on how much of the pool is used
Stability Pool Deposit xUSD to earn yield while providing liquidation protection
Automated Liquidations Keepers earn rewards for maintaining protocol health
Dutch Auctions Fair pricing for large liquidations (price decays over 24 hours)

How we built it

Tech Stack

Layer Technologies
Smart Contracts Solidity, Foundry, OpenZeppelin
Frontend React, TypeScript, ethers.js, wagmi, Vite
Testing Foundry (unit + integration + fork tests)
Automation Node.js keeper bot with ethers.js
Oracles Chainlink-compatible with fallback mechanisms

Contract Architecture

┌─────────────────────────────────────────────────────────────────┐
│                        xStocks Protocol                         │
├─────────────────────────────────────────────────────────────────┤
│                                                                 │
│  ┌──────────────┐     ┌──────────────┐     ┌──────────────┐    │
│  │ xStocksVault │────▶│    xUSD      │◀────│StabilityPool │    │
│  │ (CDP Mgmt)   │     │ (Stablecoin) │     │ (Yield Pool) │    │
│  └──────────────┘     └──────────────┘     └──────────────┘    │
│         │                                       ▲               │
│         │                                       │               │
│         ▼                                       │               │
│  ┌──────────────┐     ┌──────────────┐          │               │
│  │Liquidation   │────▶│Automation    │──────────┘               │
│  │Engine        │     │Keeper        │                          │
│  └──────────────┘     └──────────────┘                          │
│         │                                                       │
│         ▼                                                       │
│  ┌──────────────┐     ┌──────────────┐                         │
│  │xStocksOracle │────▶│VaultRegistry │                         │
│  │(Price Feeds) │     │(Config)      │                         │
│  └──────────────┘     └──────────────┘                         │
└─────────────────────────────────────────────────────────────────┘

Challenges we ran into

1. Decimal Precision (The 10^10 Bug)

Problem: xStocks use 18 decimals, Chainlink prices use 8 decimals, and xUSD uses 18 decimals. A naive calculation made every position appear undercollateralized by a factor of 10¹⁰.

Solution: We created a normalization function that converts everything to 18 decimals before ratio calculations.

2. Double-Spend in Token Transfers

Problem: Our transferFrom was consuming allowances twice, breaking all token transfers.

Solution: Refactored to use _transfer directly after allowance check.

3. Gas Limits for Liquidations

Problem: Scanning all positions on-chain would hit gas limits with even 100 users.

Solution: Off-chain keeper bot identifies positions and passes them to liquidateBatch().

4. Fee Semantics

Problem: Initial fee model burned tokens on top of transfers, breaking ERC20 conventions.

Solution: Fees now accumulate in contract balance, preserving standard transfer behavior.

5. Testing Time-Based Logic

Problem: Testing interest accrual and cooldowns required precise time manipulation.

Solution: Foundry's vm.warp() and vm.roll() enabled comprehensive time-based testing.


Accomplishments we're proud of

Complete End-to-End Protocol

7 core contracts, comprehensive tests, production-ready frontend, and automated keeper bot—all within hackathon timeframe.

Novel Stability Pool Design

Combines yield generation with liquidation backstop using share-based accounting (inspired by Lido's stETH). Fair yield distribution without per-user updates.

Production-Grade Code

  • Comprehensive natspec documentation
  • Reentrancy protection
  • Role-based access control
  • Event emission for monitoring
  • Emergency pause mechanisms

90%+ Test Coverage

Unit tests, integration tests, stress tests (20+ users), and mainnet fork tests.

Developer-Friendly Frontend

Type-safe hooks, real-time position monitoring, transaction notifications with explorer links.

Oracle Resilience

Multi-provider support (Chainlink, Pyth), automatic fallback, circuit breakers, volatility tracking.


What we learned

Technical

Lesson Insight
Decimal normalization One off-by-10^10 error breaks everything
ERC20 overrides Changing standard behavior breaks composability
Gas limits are real Unbounded loops = failed transactions
CEI pattern Checks-Effects-Interactions is non-negotiable for security

DeFi Architecture

  • Share-based accounting beats per-user updates for gas efficiency
  • Dutch auctions fairly price large liquidations without relying on keeper profitability
  • Modular design makes upgrades and maintenance easier
  • Permissionless keepers with economic incentives beat centralized automation

Collaboration

  • Interfaces first made integration testing easier
  • Natspec comments helped reason about function interactions
  • Descriptive commits made reverting broken changes faster

What's next

Phase 1: Production Readiness

  • Security audits (Code4rena, Spearbit)
  • Mainnet deployment with real Chainlink feeds
  • Bug bounty program

Phase 2: Protocol Expansion

  • Add more xStocks (xAMZN, xTSLA, xMETA)
  • Cross-chain deployment (Arbitrum, Optimism, Base)
  • Additional yield sources (Curve, Convex, Morpho)

Phase 3: Governance

  • xStocks DAO with community voting
  • Multi-sig risk management committee
  • Liquidity mining incentives

Phase 4: Advanced Features

  • Leveraged positions
  • Mobile app (React Native)
  • Institutional API

Technical Deep Dive (Optional)

For those interested in the math:

Collateral Ratio Calculation: $$ \text{Ratio} = \frac{\text{Collateral Value (18 decimals)} \times 10,000}{\text{Debt (18 decimals)}} $$

Interest Accrual: $$ \text{Interest} = \text{Debt} \times \text{Rate} \times \frac{\text{Time Elapsed}}{365 \text{ days}} $$

Share Value (Stability Pool): $$ \text{Share Value} = \frac{\text{Total Deposits (xUSD)}}{\text{Total Shares}} $$

Dutch Auction Price Decay: $$ \text{Price}(t) = \text{Start Price} \times \left(1 - \frac{t}{2 \times \text{Duration}}\right) $$


Built With

Share this project:

Updates