Development of Options Pricing System (Black-Scholes for Crypto)
On-chain options protocol faces a problem that traditional derivatives don't: the Black-Scholes model requires floating-point computations — logarithms, square roots, normal distribution — while EVM operates only with integers. Deribit calculates option prices off-chain and centrally. Lyra, Hegic, and Dopex solve this differently. Building your own pricing system is, first and foremost, a choice of compromise between precision and gas cost.
Black-Scholes Mathematics in Integers
The BSM formula for European call option:
C = S * N(d1) - K * e^(-rT) * N(d2)
where d1 = (ln(S/K) + (r + σ²/2) * T) / (σ * √T)
Each element is a source of error with integer arithmetic.
Logarithm and Exponential via Tables or Approximation
The classic approach — approximating ln(x) via Taylor series with fixed-point (fixed-point arithmetic, 18 decimals). Solidity doesn't have native ln, but PRBMath library (Paul Razvan Berg) implements ln, exp, sqrt with precision to 1e-9 using 59.18-decimal fixed-point. This is production-ready: Uniswap v3 uses similar techniques for sqrtPriceX96.
Alternative — lookup tables for standard normal distribution N(d). Table with 1000 points and interpolation gives sufficient precision for options and costs less gas than analytical approximation. Lyra v1 used exactly this approach.
Implied Volatility — The Inverse Problem
The hardest part — not computing price from known volatility, but finding implied volatility from market price. The equation BSM_price(σ) = market_price doesn't solve analytically. Methods: Newton-Raphson iterations or bisection search.
On-chain Newton-Raphson converges to IV with 0.1% precision in 5-7 iterations — costs around 80-150k gas on Ethereum mainnet. For L2 acceptable, for mainnet — expensive. Solution: IV is computed off-chain, submitted on-chain with oracle signature, contract only verifies signature and uses the value.
Stale Volatility Problem
Crypto volatility changes fast. Bitcoin IV can increase from 60% to 120% in 24 hours during sharp market moves. If on-chain stores stale IV — options are mispriced. Option buyer with underpriced IV gets unfair price at LP expense.
Lyra v2 solves this via off-chain oracle (first SNX keeper, then Lyra-specific) updating IV every 15 minutes. Hegic uses Chainlink volatility oracle (experimental feed). For a custom system — update via keeper (Gelato or Chainlink Automation) with bounded update: IV can't change more than X% per update.
Pricing System Architecture
Off-Chain Pricing Engine + On-Chain Verification
Optimal architecture for production: pricing on TypeScript/Python server with full float64 precision, result is signed by operator or multi-party committee, contract verifies signature and uses price.
This isn't "centralized" in a negative sense — there's explicit trust assumption that's documented. For comparison: Deribit is fully centralized, Lyra v1 used similar oracle scheme.
On-chain contract stores: spotPrice (from Chainlink), impliedVolatility (from keeper), lastUpdateTimestamp. With stale data (> maxStaleness) — new positions can't open.
Greeks Calculation for Risk Management
For LP pool acting as counterparty for all options, critical — pool's aggregated delta-hedging. Each option's delta sums into pool's net delta, keeper executes hedging swaps to maintain delta-neutrality.
| Greek | Meaning for Pool | Calculation Method |
|---|---|---|
| Delta | Exposure to spot | N(d1) for call, N(d1)-1 for put |
| Gamma | Rate of delta change | φ(d1) / (S * σ * √T) |
| Vega | Exposure to volatility | S * φ(d1) * √T |
| Theta | Time decay | Analytical |
Pool's PnL from greeks sums into netDelta, netVega. If |netDelta| > hedgeThreshold — keeper initiates swap on Uniswap v3 for balancing.
Option Types and Settlement
Cash-settled vs. physical delivery. Cash-settled is simpler: at expiration contract requests spot price from Chainlink, calculates payoff, transfers USDC. Physical delivery requires holding underlying asset in contract.
American vs. European. American options (exercise anytime) require binomial tree or Monte Carlo for correct valuation — on-chain impractical. All on-chain options protocols use European style.
Early exercise via flash loan. Theoretically attacker could try exercising option at oracle manipulation moment. Protection: settlement price calculated as TWAP for last hour before expiration, not spot.
Development Process
Mathematical specification (2-3 days). Formalize: option type, settlement mechanics, data sources for S and σ, fee model, hedging mechanism.
Pricing library (2-3 days). Solidity library for BSM with PRBMath. Unit tests compare results with Python scipy.stats reference implementation.
Oracle and keeper (2-3 days). Off-chain pricing engine, data signing, Gelato automation for IV updates.
Core contracts (3-5 days). OptionPool (LP), OptionToken (ERC-1155), settlement logic.
Testing (2-3 days). Fork tests on mainnet with real Chainlink feeds, expiration scenarios.
Timeline Reference
Pricing system as library + oracle infrastructure — 3-5 days. Full options protocol with LP pool, hedging, and frontend — 6-10 weeks.







