On-Chain Crypto Options Pricing System (Black-Scholes)
On-chain option protocols face a problem that traditional derivatives don't: the Black-Scholes model requires floating-point calculations — logarithms, square roots, normal distributions — but the EVM only handles integers. Deribit computes option prices off-chain and centrally. Lyra, Hegic, and Dopex solve this differently. We have developed and deployed several such systems for DeFi protocols. Our experience shows that the optimal architecture combines off-chain precision with on-chain verification. Yet most protocols lose up to 30% of LP profits due to pricing inaccuracies in their chosen model. Our solutions reduce the error to 0.1% and save up to 70% on gas by offloading computations off-chain. This can save hundreds of thousands of dollars in gas costs at scale. In this article, we'll dissect the key problems and present a ready-made solution.
Black-Scholes Math in Integers
The BSM formula for a European call option: C = S * N(d1) - K * e^(-rT) * N(d2) where d1 = (ln(S/K) + (r + σ²/2) * T) / (σ * √T) Every element introduces error when using integer arithmetic.
Logarithm and Exponential via Tables or Approximation
The classic approach is to approximate ln(x) using a Taylor series with fixed-point arithmetic (18 decimals). Solidity has no native ln, but the PRBMath library implements ln, exp, sqrt with precision up to 1e-9 using 59.18-decimal fixed-point. This is production-ready: Uniswap v3 uses similar techniques for sqrtPriceX96.
An alternative is to use lookup tables for the standard normal distribution N(d). A 1000-point table with interpolation provides sufficient accuracy for options and costs less gas than an analytical approximation. Lyra v1 used this approach.
How Is Implied Volatility Computed On-Chain?
The hardest part is not computing the price from known volatility, but finding implied volatility (IV) from the market price. The equation BSM_price(σ) = market_price has no analytical solution. Methods: Newton-Raphson iterations or bisection search.
On-chain Newton-Raphson converges to IV with 0.1% accuracy in 5–7 iterations — costing around 80–150k gas on Ethereum mainnet. Acceptable for L2s, expensive for mainnet. Solution: IV is computed off-chain, submitted on-chain with an oracle signature, and the contract only verifies the signature and uses the value.
Why Stale Volatility Matters and How to Avoid It
Crypto volatility changes rapidly. Bitcoin's IV can rise from 60% to 120% in 24 hours during a sharp market move. If stale IV is stored on-chain, options are mispriced. A buyer of an option with undervalued IV gets an unfair price at the expense of LPs. Lyra v2 solves this via an off-chain oracle updating IV every 15 minutes. Hegic uses the Chainlink volatility oracle. For a custom system — update via a keeper (Gelato or Chainlink Automation) with bounded updates: IV cannot change by more than X% per update.
Pricing System Architecture
Off-Chain Pricing Engine + On-Chain Verification
The optimal architecture for production: a pricing server in TypeScript/Python with full float64 precision, results signed by an operator or multi-party committee, the contract verifies the signature and uses the price. This is not 'centralized' in a negative sense — there is an explicit trust assumption that is documented. For comparison: Deribit is fully centralized, Lyra v1 used a similar oracle scheme.
The on-chain contract stores: spotPrice (from Chainlink), impliedVolatility (from keeper), lastUpdateTimestamp. If data is stale (> maxStaleness), no new positions can be opened.
| Characteristic | On-Chain Full | Off-Chain + Verification |
|---|---|---|
| Gas per pricing | 150–300k | 40–60k (verification only) |
| Precision | Fixed-point | Float64 |
| Trust assumption | None | Oracle |
| Update speed | Via keeper | Instant |
Calculating Greeks for Risk Management
For an LP pool that acts as counterparty for all options, aggregate delta-hedging is critical. The delta of each option is summed to the pool's net delta, and a keeper executes hedging swaps to maintain delta neutrality.
| Greek | Meaning for the Pool | Calculation Method |
|---|---|---|
| Delta | Exposure to spot price | N(d1) for calls, N(d1)-1 for puts |
| Gamma | Rate of delta change | φ(d1) / (S * σ * √T) |
| Vega | Exposure to volatility | S * φ(d1) * √T |
| Theta | Time decay | Analytical |
The pool's PnL from Greeks is aggregated into netDelta and netVega. If |netDelta| > hedgeThreshold, the keeper initiates a swap on Uniswap v3 to rebalance.
Supported Option Types
Cash-settled vs physical delivery. Cash-settled is simpler: at expiry, the contract requests the spot price from Chainlink, computes the payoff, and transfers USDC. Physical delivery requires storing the underlying asset in the contract. American vs European — American options require a binomial tree or Monte Carlo for correct valuation, which is impractical on-chain. All on-chain option protocols use European style.
Early exercise via flash loan — theoretically, an attacker could try to exercise an option during an oracle manipulation. Protection: the settlement price is computed as a TWAP over the last hour before expiry, not the spot.
Process of Work
- 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 using 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, expiry scenarios.
What's Included in the Pricing System Development
- Mathematical specification and model selection
- Solidity BSM library with PRBMath
- Off-chain pricing engine in TypeScript/Python
- Integration with oracles (Chainlink, Gelato)
- Testing on mainnet fork with real data
- Documentation and team training
- Post-launch support guarantee
Investment in development pays off through reduced gas costs and pricing accuracy.
Timeline Estimates
Pricing system as a library + oracle infrastructure: 3–5 days. Full options protocol with LP pool, hedging, and frontend: 6–10 weeks.
Our team has 10+ years of experience in blockchain development and has built over 20 smart contracts for options protocols. We guarantee pricing accuracy within 0.1% and architectural transparency.
Get a consultation on the architecture — we will help you choose the optimal scheme and implement the system turnkey. Order development of an options pricing system.







