π A decentralized options trading platform built on Ethereum using Scaffold-ETH 2, Uniswap V4 hooks, and advanced DeFi protocols. OpSwap enables users to trade options with deep liquidity pools and sophisticated pricing models.
βοΈ Built using NextJS, RainbowKit, Foundry, Wagmi, Viem, TypeScript, and Uniswap V4.
OpSwap is a comprehensive options trading platform that combines:
- πͺ Uniswap V4 Hooks: Custom hooks for options trading integration
- π° Option Pool Vaults: ERC4626 compliant vaults for managing option assets
- π Black-Scholes Pricing: Advanced options pricing using mathematical models
- π Liquidity Management: Automated liquidity provision and management
- π Secure Trading: Whitelisted tokens and permissioned trading
OpHook.sol
: Uniswap V4 hook for options trading integrationOptionPool.sol
: Core options pool with cell-based liquidity managementOptionPoolVault.sol
: ERC4626 vault for option pool asset managementOptionPrice.sol
: Black-Scholes options pricing implementationIOptionToken.sol
: Interface for option token interactions
- NextJS App: Modern React frontend with TypeScript
- OpSwap Interface: Dedicated options trading interface at
/opswapfront
- Debug Interface: Contract interaction and testing tools
- Block Explorer: Local transaction monitoring
Before you begin, you need to install the following tools:
- Node (>= v20.18.3)
- Yarn (v1 or v2+)
- Git
- Install dependencies:
yarn install
- Start local blockchain (Terminal 1):
yarn chain
- Deploy contracts (Terminal 2):
yarn deploy
- Start frontend (Terminal 3):
yarn start
- Access the application:
- Main app:
http://localhost:3000
- OpSwap interface:
http://localhost:3000/opswapfront
- Debug contracts:
http://localhost:3000/debug
- Block explorer:
http://localhost:3000/blockexplorer
- Main app:
Run smart contract tests:
yarn foundry:test
- Call & Put Options: Support for both call and put option types
- Black-Scholes Pricing: Mathematical options pricing model
- Strike Price Management: Flexible strike price configuration
- Expiration Handling: Automated expiration and settlement
- Cell-Based Liquidity: Efficient liquidity distribution across price ranges
- Fee Collection: Automated fee collection and distribution
- Position Management: Advanced position tracking and management
- Vault Integration: ERC4626 compliant vault for asset management
- Whitelisted Tokens: Permissioned trading for approved tokens
- Access Control: Role-based permissions for admin functions
- Emergency Pause: Circuit breakers for emergency situations
- Reentrancy Protection: Secure contract interactions
- Contracts:
packages/foundry/contracts/
- Tests:
packages/foundry/test/
- Deployment Scripts:
packages/foundry/script/
- Main App:
packages/nextjs/app/page.tsx
- OpSwap Interface:
packages/nextjs/app/opswapfront/page.tsx
- Components:
packages/nextjs/components/
- Hooks:
packages/nextjs/hooks/scaffold-eth/
- Scaffold Config:
packages/nextjs/scaffold.config.ts
- Foundry Config:
packages/foundry/foundry.toml
- Deployed Contracts:
packages/nextjs/contracts/deployedContracts.ts
const { data: optionPrice } = useScaffoldReadContract({
contractName: "OptionPrice",
functionName: "blackScholesPrice",
args: [underlying, strike, timeToExpiration, volatility, riskFreeRate, isCall],
});
const { writeContractAsync: writeOpHookAsync } = useScaffoldWriteContract({
contractName: "OpHook"
});
await writeOpHookAsync({
functionName: "addLiquidity",
args: [permit, key, liquidityParams, hookData],
});
We welcome contributions to OpSwap! Please see CONTRIBUTING.md for guidelines.
This project is licensed under the MIT License - see the LICENSE file for details.
This software is for educational and development purposes. Use at your own risk. The contracts have not been audited and should not be used in production without proper security review.