How derivexyz/v1-core works
Project type and purpose
• This is an on-chain derivatives protocol SDK written in Solidity, with a TypeScript Hardhat wrapper (“TestSystem”) for deployment, seeding, and integration testing.
• It exposes core option-market functionality (boards, strikes, open/close, settlement), liquidity pools, Greek caching, collateral management, and periphery adapters (GMX, SNX, Uniswap, Chainlink).
File-structure analysis
• Root: Hardhat config (hardhat.config.ts), package.json, tsconfig.json.
• /contracts: Solidity modules split into:
– core (OptionMarket, OptionGreekCache, OptionToken, ShortCollateral, LiquidityPool, SynthetixAdapter, PerpsV2Adapter)
– periphery wrappers/adapters (LyraAdapter, GWAVOracle, MultistepSwapper)
– governance-wrapper modules (GMX, SNX)
– interfaces (GMX, perpsV2) & libraries (BlackScholes, GWAV, Maths)
• /deployments: network-specific deployment manifests (mainnet-ovm, goerli-arbi, local, etc.)
• /scripts: TS scripts for deploy, seed, governance wraps, integration tests, and utility functions
• /test: Mocha/Chai integration & unit tests organized per contract module
• /test/utils: helper functions for fixtures, price mocks, event parsing
• /examples: sample deploy & interaction scripts
README insights
• The project publishes an NPM SDK (“@lyrafinance/protocol”) that a user imports into their contract or test harness.
• TestSystem.deploy() and .seed() spin up a full Lyra market on Hardhat.
• Guides for local, goerli-ovm, mainnet-ovm deployments and integration tests.
a. Main components:
1. Developer/Test Harness (TypeScript + Hardhat + TestSystem SDK)
2. Deployment layer (Hardhat Runtime Environment + Ethers.js)
3. On-chain Smart Contracts:
• Core modules: OptionMarket, OptionGreekCache, OptionToken, ShortCollateral, LiquidityPool
• Periphery: LyraAdapter, GWAVOracle, MultistepSwapper, KeeperHelper
• Governance wrappers: GMXWrapper, SNXWrapper
• External-protocol adapters: GMXAdapter, SynthetixAdapter, PerpsV2Adapter
4. External services:
• GMX protocol
• Synthetix (SNX, sETH, sUSD)
• Uniswap (for swaps)
• Chainlink oracles (price feeds)
5. Data stores: on-chain state in contract storage
6. Testing & CI: Mocha/Chai tests, Slither static analysis, GitHub Actions
b. Relationships & data flows:
• TS Scripts → deploy & seed → Contract factory calls → On-chain deployment
• TestSystem SDK → calls contract functions (openPosition, deposit, hedge, settle)
• Core modules inter-call each other: OptionMarket reads GreekCache, issues OptionToken, interacts with ShortCollateral & LiquidityPool
• Periphery adapters wrap core calls (multistep swaps, external integrations)
• Governance wrappers trigger upgrades or parameter tweaks on core modules
• Contracts call external protocols: e.g. GMXAdapter routes trades/liquidity on GMX, SynthetixAdapter routes collateral on Synthetix, Uniswap via MultistepSwapper
• Oracle modules fetch prices from Chainlink or GWAV feed
c. Architectural patterns & principles:
• Modular, pluggable smart-contract architecture (core vs periphery vs governance vs adapters)
• Facade pattern in periphery wrappers (simplify group calls)
• Adapter pattern for external protocols (GMXAdapter, SynthetixAdapter, PerpsV2Adapter)
• Dependency Injection via TestSystem for seamless testing & seeding
• Single-responsibility modules (each contract focuses on one domain)
d. Key technologies:
• Solidity (contracts)
• Hardhat + TypeScript (deployment, tests, SDK)
• Ethers.js (contract interfacing)
• Mocha/Chai (tests)
• Slither (static analysis)
• GMX, Synthetix, Uniswap, Chainlink integrations