Fully On-Chain European Options Protocol with Black-Scholes Pricing Engine
Architecture β’ Getting Started β’ Contracts β’ Math Engine β’ Testing β’ Security β’ Contributing
MantissaFi is a fully on-chain European options protocol that computes Black-Scholes-Merton pricing, Greeks (Delta, Gamma, Theta, Vega), and the cumulative normal distribution function (Ξ¦) entirely in Solidity β with provable accuracy bounds and gas efficiency.
- Gas-Optimized BSM Engine β Full Black-Scholes pricing in <80K gas using PRBMath SD59x18 with Rational Chebyshev approximation for Ξ¦(x) achieving <0.0001% error
- Liquidity-Sensitive IV Surface (LSIVS) β On-chain implied volatility derived from realized volatility, skew modeling, and pool utilization β no off-chain IV oracle dependency
- On-Chain Greeks β Delta, Gamma, Theta, Vega computed fully on-chain with shared intermediate values
- Formally Verified β Certora/Halmos invariant proofs for solvency, put-call parity, pricing monotonicity, and CDF bounds
| Feature | Lyra/Derive | Dopex/Stryke | Panoptic | MantissaFi |
|---|---|---|---|---|
| Pricing model | BSM (off-chain IV) | BSM (off-chain IV) | Oracle-free (LP) | BSM (fully on-chain) |
| IV source | GWAV + Deribit | External | N/A | On-chain LSIVS |
| Greeks on-chain | β | β | Partial | β Full suite |
| Formal verification | β | β | β | β Certora proofs |
| Gas per price | N/A (off-chain) | N/A (off-chain) | ~80K | < 80K |
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β MantissaFi Protocol β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ€
β β
β ββββββββββββββββ ββββββββββββββββ βββββββββββββββββββββββββ β
β β OptionVault β β BSMEngine β β VolatilitySurface β β
β β β β β β β β
β β β’ mint() ββββ β’ price() ββββ β’ getIV() β β
β β β’ exercise() β β β’ delta() β β β’ updateRealizedVol() β β
β β β’ settle() β β β’ gamma() β β β’ skewAdjust() β β
β β β’ liquidate()β β β’ theta() β β β’ utilizationAdjust() β β
β ββββββββ¬ββββββββ β β’ vega() β βββββββββββββ¬ββββββββββββ β
β β β β’ cdf() β β β
β β ββββββββββββββββ β β
β ββββββββΌββββββββ ββββββββββββββββ ββββββββββββΌβββββββββββββ β
β β LiquidityPoolβ β FixedPoint β β OracleAdapter β β
β β β β MathLib β β β β
β β β’ deposit() β β β’ exp() β β β’ Chainlink β β
β β β’ withdraw() β β β’ ln() β β β’ Pyth β β
β β β’ allocate() β β β’ sqrt() β β β’ TWAP β β
β β β’ hedgeDelta β β β’ cdf() β β β’ RealizedVol β β
β ββββββββββββββββ β β’ pdf() β βββββββββββββββββββββββββ β
β ββββββββββββββββ β
β ββββββββββββββββ ββββββββββββββββ βββββββββββββββββββββββββ β
β β OptionToken β β Settlement β β AccessControl β β
β β (ERC-1155) β β Engine β β & Governance β β
β ββββββββββββββββ ββββββββββββββββ βββββββββββββββββββββββββ β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
git clone https://github.com/0xfandom/mantissa-fi.git
cd mantissa-fi
forge installforge build# Unit tests
forge test
# Fuzz tests (10,000 runs)
forge test --match-path "test/fuzz/*" -vvv
# Gas report
forge test --gas-report
# Fork tests (requires RPC URL)
FORK_URL=<your-rpc-url> forge test --match-path "test/fork/*" --fork-url $FORK_URLforge script script/Deploy.s.sol --rpc-url $RPC_URL --broadcast --verifysrc/
βββ core/
β βββ OptionVault.sol # Main entry β mint, exercise, settle options
β βββ LiquidityPool.sol # LP deposits, withdrawals, delta hedging
β βββ OptionToken.sol # ERC-1155 multi-token for option positions
β βββ Settlement.sol # Expiry settlement, ITM/OTM resolution
βββ pricing/
β βββ BSMEngine.sol # Black-Scholes-Merton pricing engine
β βββ FixedPointMathLib.sol # exp, ln, sqrt optimized for BSM
β βββ CumulativeNormal.sol # High-precision Ξ¦(x) β Hart's approximation
β βββ Greeks.sol # Delta, Gamma, Theta, Vega computation
βββ volatility/
β βββ VolatilitySurface.sol # LSIVS β implied volatility surface
β βββ RealizedVolOracle.sol # EWMA realized volatility from price feeds
β βββ SkewModel.sol # Strike-dependent IV adjustment
βββ oracle/
β βββ OracleAdapter.sol # Multi-oracle: Chainlink + Pyth + TWAP
β βββ PriceValidator.sol # Staleness & deviation checks
βββ periphery/
β βββ OptionRouter.sol # User-facing multicall helper
β βββ OptionLens.sol # View functions for frontends
β βββ FeeController.sol # Dynamic fee model
βββ libraries/
βββ OptionMath.sol # Payoff calculations, moneyness helpers
βββ TimeLib.sol # Timestamp β annualized time conversion
βββ Constants.sol # Fixed-point constants (β2Ο, e, etc.)
C = S Β· Ξ¦(dβ) - K Β· e^(-rT) Β· Ξ¦(dβ)
dβ = [ln(S/K) + (r + ΟΒ²/2) Β· T] / (Ο Β· βT)
dβ = dβ - Ο Β· βT
The cumulative normal distribution Ξ¦(x) is computed using a 7-term rational polynomial achieving < 7.5 Γ 10β»βΈ maximum error at approximately 8,000 gas.
| Operation | Target Gas |
|---|---|
| Ξ¦(x) β CDF | < 10,000 |
| Full BSM price | < 80,000 |
| All 4 Greeks | < 100,000 |
| Mint option | < 150,000 |
| Exercise option | < 100,000 |
All pricing outputs are validated against scipy.stats.norm (Python) across 10,000+ fuzzed input vectors:
- CDF max error: < 1 Γ 10β»β΅
- BSM price max relative error: < 0.01%
- Put-call parity deviation: < 0.001 USDC per option
| Category | Location | Description |
|---|---|---|
| Unit | test/unit/ |
Individual function correctness |
| Fuzz | test/fuzz/ |
Property-based with random inputs |
| Invariant | test/invariant/ |
Protocol-wide invariant testing |
| Integration | test/integration/ |
Full option lifecycle |
| Fork | test/fork/ |
Against mainnet state |
| Differential | test/differential/ |
Solidity vs Python reference |
| Gas | test/gas/ |
Gas benchmarking suite |
cd analysis/
pip install -r requirements.txt
python precision_test.py # Generates test vectors
cd ..
forge test --match-path "test/differential/*"| Invariant | Description | Status |
|---|---|---|
| Solvency | Pool assets β₯ max payoff obligations | π² |
| Pricing Monotonicity | βC/βS > 0, βP/βS < 0, Vega > 0 | π² |
| Put-Call Parity | C - P = S - KΒ·e^(-rT) within Ξ΅ | π² |
| CDF Bounds | 0 β€ Ξ¦(x) β€ 1, Ξ¦(-x) = 1 - Ξ¦(x) | π² |
| No Value Extraction | profit β€ intrinsic - premium | π² |
slither src/
aderyn .See SECURITY.md for the complete threat model covering oracle manipulation, flash loan attacks, precision exploits, IV manipulation, and donation attacks.
- Phase 0: Project setup, repository structure
- Phase 1: Math engine (CDF, BSM, Greeks) β Weeks 1β3
- Phase 2: Protocol core (Vault, Pool, Settlement) β Weeks 4β7
- Phase 3: Volatility surface (LSIVS, EWMA, Skew) β Weeks 8β10
- Phase 4: Security & formal verification β Weeks 11β13
- Phase 5: Documentation, paper, presentation β Weeks 14β16
| Component | Technology |
|---|---|
| Language | Solidity ^0.8.25 |
| Framework | Foundry |
| Math Library | PRBMath v4 (SD59x18) |
| Token Standard | ERC-1155 (OpenZeppelin) |
| Oracle | Chainlink, Pyth, Custom TWAP |
| Formal Verification | Certora / Halmos |
| Static Analysis | Slither, Aderyn |
| Differential Testing | Python (scipy, numpy) |
Contributions are welcome! Please read CONTRIBUTING.md before submitting PRs.
- Fork the repository
- Create your feature branch (
git checkout -b feature/amazing-feature) - Run tests (
forge test) - Commit changes (
git commit -m 'feat: add amazing feature') - Push to branch (
git push origin feature/amazing-feature) - Open a Pull Request
This project is licensed under the MIT License β see the LICENSE file for details.
- PRBMath β Fixed-point arithmetic
- SolStat β Statistical functions in Solidity
- OpenZeppelin β Security standards
- Black, F. & Scholes, M. (1973) β The Pricing of Options and Corporate Liabilities
- Abramowitz & Stegun (1964) β Handbook of Mathematical Functions