Back to Case Studies
DeFi / Trading|Chainlink Labs

Chainlink Data Streams: Low-Latency Price Feeds

Demonstration dApp showcasing low-latency, front-running resistant price feeds for DeFi. Enables secure on-chain trading with real-time price verification and automated execution at intended prices.

Cover Image for Chainlink Data Streams: Low-Latency Price Feeds

Executive Summary

Developed a demonstration platform showcasing Chainlink Data Streams' low-latency, front-running resistant price feed technology. The application proves how decentralized applications can access real-time pricing data while preventing MEV (Miner Extractable Value) attacks that plague traditional oracle implementations.

Key Outcomes:

  • 100% front-running protection through cryptographic price commitments
  • Low-latency price updates enabling near-instant trade execution
  • Guaranteed execution at intended prices, eliminating slippage attacks
  • Multi-source price comparison (Coinbase, Binance, Chainlink)

The Challenge

Decentralized trading applications face a critical vulnerability: the time gap between when users submit trades and when they execute on-chain creates opportunities for exploitation.

The MEV Problem in DeFi

How Front-Running Attacks Work

1. User submits trade: "Buy 1 ETH at $2000"
2. MEV bot sees pending transaction in mempool
3. Bot submits higher gas fee to execute first
4. Bot's trade executes, moves price to $2050
5. User's trade executes at worse price ($2050)
6. User loses $50, bot profits $50

Why Traditional Oracles Enable This

Standard price oracle patterns have inherent vulnerabilities:

  • Polling-based updates: Prices update every N blocks, creating arbitrage windows
  • Public mempool visibility: Attackers see trades before execution
  • No price commitment: Final execution price differs from submission price
  • Gas price auctions: Bots can always pay more to execute first

Business Impact

For Users:

  • Trades execute at worse prices than expected
  • "Slippage" becomes a euphemism for value extraction
  • Reduced trust in decentralized exchanges
  • Hesitation to trade large amounts (greater MEV risk)

For Protocols:

  • User acquisition hampered by poor execution quality
  • Professional traders avoid platforms vulnerable to MEV
  • Liquidity fragmentation as users seek safer venues
  • Competitive disadvantage vs. centralized exchanges with better execution

Technical Requirements for a Solution

A front-running resistant trading system must provide:

  1. Low-latency price data: Sub-second updates, not multi-block delays
  2. Price commitment: Lock in price at submission, not execution
  3. Cryptographic verification: Prove prices haven't been manipulated
  4. Decentralized execution: No centralized operator controlling prices
  5. Automated settlement: Execute when conditions match, not requiring manual triggers

Our Approach

We designed a demonstration platform that showcases the full capabilities of Chainlink Data Streams combined with Chainlink Automation to create MEV-resistant trading.

Core Innovation: Hybrid Price Feeds

The solution uses a two-layer price feed architecture:

Off-Chain Price Subscription (Data Streams)

  • Users subscribe to real-time price feeds via WebSocket
  • Prices stream continuously with sub-second updates
  • Each price includes cryptographic signature from Chainlink DON
  • Prices are cryptographically committed before user submits trade

On-Chain Verification

  • Smart contract verifies cryptographic signature
  • Confirms price data is authentic from Chainlink network
  • Executes trade only if on-chain price matches subscribed price
  • Rejects execution if prices have moved (preventing front-running)

Result: Users lock in their intended price off-chain, then execution only proceeds if that price is still valid on-chain.


The Solution

System Architecture

┌───────────────────────────────────────────────────────────┐
│              User Interface (Next.js)                     │
│   • Real-time price comparison                            │
│   • WalletConnect integration                             │
│   • Trade submission with price commitment                │
└────────────────────┬──────────────────────────────────────┘
                     │
                     ▼
┌───────────────────────────────────────────────────────────┐
│        Chainlink Data Streams (Off-Chain)                 │
│   • Subscribe to BTC/USD, ETH/USD price feeds             │
│   • Sub-second price updates                              │
│   • Cryptographically signed reports                      │
└────────────────────┬──────────────────────────────────────┘
                     │
                     ▼
┌───────────────────────────────────────────────────────────┐
│         Trading Smart Contract (On-Chain)                 │
│   • Receives trade request with price commitment          │
│   • Verifies Data Streams signature                       │
│   • Integrates with Uniswap for execution                 │
└────────────────────┬──────────────────────────────────────┘
                     │
                     ▼
┌───────────────────────────────────────────────────────────┐
│         Chainlink Automation                              │
│   • Monitors pending trades                               │
│   • Executes when on-chain price matches commitment       │
│   • Automatic settlement without manual keepers           │
└───────────────────────────────────────────────────────────┘

Core Components

Frontend Application

Built with modern web technologies for optimal performance:

Price Comparison Dashboard

  • Real-time prices from three sources side-by-side:
    • Coinbase API (centralized exchange)
    • Binance API (centralized exchange)
    • Chainlink Data Streams (decentralized oracle)
  • Visible price differences and latency metrics
  • Educational: shows why Data Streams matters

Trade Submission Interface

  • Users input: token pair, amount, intended price
  • Price is locked at submission time via Data Streams signature
  • Clear indication of price commitment guarantees
  • WalletConnect integration for seamless wallet interaction

Trading Smart Contract

Solidity contract implementing MEV-resistant execution logic:

// Simplified pseudocode
struct TradeRequest {
    address user;
    uint256 amount;
    uint256 committedPrice;
    bytes chainlinkSignature;
    uint256 expirationTime;
}

function submitTrade(
    uint256 amount,
    uint256 committedPrice,
    bytes memory priceSignature
) external {
    // 1. Store trade with price commitment
    // 2. Verify Chainlink Data Streams signature
    // 3. Register with Chainlink Automation for execution
}

function executeTrade(uint256 tradeId) external {
    TradeRequest memory trade = trades[tradeId];

    // 1. Fetch current on-chain price
    uint256 currentPrice = getCurrentPrice();

    // 2. Verify price still matches commitment (within tolerance)
    require(
        abs(currentPrice - trade.committedPrice) < TOLERANCE,
        "Price moved, protecting user from front-run"
    );

    // 3. Execute trade via Uniswap at committed price
    executeSwap(trade.user, trade.amount, trade.committedPrice);
}

Key Features:

  • Price verification: Cryptographic proof of Data Streams price
  • Execution guarantee: Trade only executes at committed price ± small tolerance
  • Time-bounded: Trades expire if not executable within timeframe
  • MEV protection: Front-runners can't profit by moving price

Chainlink Data Streams Integration

Off-chain price feed with cryptographic guarantees:

How It Works:

  1. User's browser subscribes to Data Streams WebSocket
  2. Receives continuous price updates with DON signatures
  3. When user submits trade, includes latest signed price report
  4. Smart contract verifies signature on-chain
  5. Execution proceeds only if signature is valid and price unchanged

Benefits:

  • Low latency: Sub-second price updates
  • Cryptographic proof: Can't be forged or manipulated
  • Decentralized: Chainlink DON provides consensus
  • Gas efficient: No need for continuous on-chain price updates

Chainlink Automation Integration

Automates trade execution when conditions are met:

Conditional Execution Pattern:

// Automation checks this function repeatedly
function checkUpkeep(bytes calldata checkData)
    external
    view
    returns (bool upkeepNeeded, bytes memory performData)
{
    // Check if any pending trades are executable
    for (uint256 i = 0; i < pendingTrades.length; i++) {
        if (isTradeExecutable(pendingTrades[i])) {
            return (true, abi.encode(pendingTrades[i]));
        }
    }
    return (false, "");
}

// If checkUpkeep returns true, Automation calls this
function performUpkeep(bytes calldata performData) external {
    uint256 tradeId = abi.decode(performData, (uint256));
    executeTrade(tradeId);
}

Benefits:

  • No manual keeper infrastructure needed
  • Trades execute as soon as conditions match
  • Decentralized execution (no single operator)
  • Users don't need to monitor and trigger trades manually

Results

MEV Protection Metrics

MetricTraditional DEXWith Data Streams
Front-Running VulnerabilityHighEliminated
Price CommitmentNoYes (cryptographically enforced)
Execution GuaranteeNoAt intended price or no execution
Latency~12 seconds (block time)Sub-second price updates

User Experience Impact

Before: Standard DEX Experience

  1. User submits trade
  2. Transaction sits in mempool (visible to bots)
  3. MEV bot front-runs
  4. User's trade executes at worse price
  5. User experiences "slippage" (value extracted)

After: Data Streams + Automation

  1. User locks in price off-chain (Data Streams)
  2. Submits trade with cryptographic price commitment
  3. Chainlink Automation monitors for execution opportunity
  4. Trade executes only if on-chain price matches commitment
  5. User gets intended price or trade doesn't execute (no loss)

Technical Achievements

Cryptographic Price Commitment

  • Users prove their intended price using Data Streams signature
  • Smart contract verifies signature authenticity
  • Execution proceeds only if verification succeeds
  • No trusted intermediary required

Automated Execution Without Centralization

  • Chainlink Automation eliminates need for manual keepers
  • Decentralized oracle network ensures no single executor
  • Trades settle when conditions match, not when convenient for operator
  • Users don't need to monitor and manually execute

Multi-Source Price Transparency The interface compares three price sources:

  • Educational value: Shows Data Streams latency advantage
  • Trust building: Users see consistency across sources
  • Market awareness: Price differences highlight arbitrage opportunities

Architectural Insights

The Hybrid Model Advantage

By combining off-chain data subscription with on-chain verification, the architecture achieves what pure on-chain or pure off-chain solutions cannot:

CharacteristicPure On-Chain (Traditional Oracles)Pure Off-ChainHybrid (Data Streams + Automation)
Latency❌ High (multi-block updates)✅ Low✅ Low (sub-second)
MEV Vulnerability❌ Prices visible before update❌ No on-chain execution✅ Protected via price commitment
Cost❌ Expensive (every update costs gas)✅ Low✅ Gas efficient (verify signatures only)
Trust Model✅ Decentralized❌ Centralized price provider✅ Decentralized
Cryptographic Guarantees✅ On-chain verification❌ None✅ On-chain signature verification
Smart Contract Execution✅ Can trigger❌ Cannot trigger✅ Automated execution

Uniswap Integration

The platform integrates with Uniswap to demonstrate real trading:

  • Executes actual swaps on-chain
  • Uses Data Streams prices to determine acceptable execution bounds
  • Shows how oracle integration works with existing DeFi primitives
  • Proves production viability, not just theoretical concepts

Extensibility

The demonstrated patterns apply to multiple use cases:

Decentralized Exchanges

  • Limit orders with guaranteed execution prices
  • Protection from sandwich attacks
  • Reduced slippage for large trades

Lending Protocols

  • Accurate liquidation pricing
  • Fair interest rate calculations
  • Protection from oracle manipulation attacks

Derivatives

  • Fair mark-to-market pricing
  • Protection from price oracle attacks
  • Timely settlement triggers

Gaming & NFTs

  • Fair pricing for in-game asset purchases
  • Protection from price manipulation
  • Accurate reward calculations

Technologies Used

Solidity Hardhat Chainlink Data Streams Chainlink Automation Uniswap Next.js TypeScript WalletConnect Ethereum Binance API Coinbase API

Ready to ship your blockchain project?

From smart contracts to full-stack dApps, we turn your Web3 vision into reality. Let's talk about what you're building.

hello@hack.bg

By submitting, you agree to our privacy policy.