project screenshot 1
project screenshot 2
project screenshot 3

DynamicSpreadLO

Dynamic pricing for limit orders based on real-time market volatility.

DynamicSpreadLO

Created At

Unite Defi

Project Description

VolatilitySpreadCalculator: is a smart contract extension for the 1inch Limit Order Protocol that introduces risk-adjusted dynamic pricing to decentralized trading. The Problem We Solve: Current DeFi limit orders use fixed prices (e.g., "1 ETH for 3000 USDC") regardless of market conditions. This creates a fundamental mismatch between risk and reward - market makers face the same compensation whether they're trading during calm periods or extreme volatility. During events like March 2020's Black Thursday (50% ETH crash), fixed-fee DEX market makers lost millions because their 0.3% fees couldn't cover impermanent loss from massive price swings. Our Solution: We built an intelligent pricing layer that automatically adjusts order prices based on real-time volatility data. Market makers can now create "smart orders" that protect them during volatile periods while remaining competitive during calm markets. How It Works:

Real-time Data Integration: Created a Volatility calculator Fetches on the top of Chainlink price feeds Dynamic Calculation: Applies formula: Final Price = Base Price + (Volatility × Risk Multiplier) Automatic Adjustment: When orders execute, the contract calculates current volatility and adjusts the final amount Risk Protection: Maximum spread caps prevent excessive pricing during black swan events

Technical Implementation:

Core Contract: VolatilitySpreadCalculator implementing 1inch's IAmountGetter interface Volatility Engine: Custom ChainlinkVolatilityLib for multi-timeframe volatility calculation Seamless Integration: Zero changes needed to existing 1inch protocol - pure extension Flexible Parameters: Configurable base spreads, volatility multipliers, and time windows

Example Usage: A trader creates an order: "Sell 1 ETH for ~3000 USDC with dynamic pricing"

Calm market (5% volatility): Taker pays 3018 USDC (0.6% adjustment) Volatile market (30% volatility): Taker pays 3060 USDC (2% adjustment, capped).

https://dashboard.tenderly.co/explorer/vnet/be5ae2b9-fc3c-44d8-9aa0-af465f26db03/transactions

How it's Made

We built a system that automatically adjusts limit order prices based on market volatility. Think of it like a smart market maker that widens spreads when markets are crazy and tightens them when things are calm. Here's how we put it all together:

Traditional limit orders on 1inch use fixed prices. We added a "brain" that watches market volatility and adjusts prices in real-time. When someone fills the order, our system calculates the exact price based on current market conditions, not the conditions when the order was created.

We created a VolatilitySpreadCalculator contract that acts as a pricing oracle for limit orders. This contract:

  • Connects to Chainlink price feeds to track token price movements
  • Calculates volatility using historical price data over different time windows (24 hours, 7 days, or a blend)
  • Implements 1inch's IAmountGetter interface, which allows it to plug directly into their order execution flow
  • Stores configuration for different tokens (which price feed to use, whether it's a stablecoin, custom volatility overrides) The clever part is that this contract never touches any tokens - it's purely a calculator that tells the protocol how much to charge.

1inch's TypeScript SDK is built in a modular way and has support for extending its functionality to support any extension . The SDK has an example for extensions that receive and distribute tokens (like fee collectors), but our extension only calculates amounts. We created three new components:

  1. VolatilitySpreadExtension: Encodes the spread parameters (base spread, volatility multiplier, max spread, time window, and which token to track) into a format the smart contract can decode
  2. LimitOrderWithVolatility: A new order type that knows how to preview spreads and includes volatility parameters in the order data
  3. VolatilitySdk: A simplified interface that handles all the complexity of creating volatility-adjusted orders The Order Flow When Creating an Order The user provides:
  • Basic order info (tokens, amounts, who's selling)
  • Volatility parameters:
    • Base spread: The minimum spread even in calm markets (e.g., 0.5%)
    • Volatility multiplier: How much volatility affects the spread (e.g., 2x means 10% volatility adds 20% to spread)
    • Max spread: Safety cap to prevent excessive spreads (e.g., 3%)
    • Time window: Whether to use 24-hour, 7-day, or blended volatility
    • Target token: Whether to track the token being sold or bought These parameters get encoded into the order's extension data. The magic is that this data becomes part of the order hash that the user signs, making it tamper-proof. When Someone Fills the Order
  1. The 1inch protocol recognizes the order has an extension
  2. It calls our VolatilitySpreadCalculator contract
  3. The calculator:
    • Decodes the spread parameters from the order
    • Queries Chainlink for current price data
    • Calculates recent volatility based on price movements
    • Applies the formula: final_spread = min(base_spread + (volatility × multiplier), max_spread)
    • Returns adjusted token amounts
  4. The trade executes at this dynamically calculated price
background image mobile

Join the mailing list

Get the latest news and updates