Skip to content

lababidi/op-hook

Repository files navigation

🎯 OpSwap - Decentralized Options Trading Platform

πŸš€ 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.

🎯 Project Overview

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

πŸ—οΈ Architecture

Smart Contracts

  • OpHook.sol: Uniswap V4 hook for options trading integration
  • OptionPool.sol: Core options pool with cell-based liquidity management
  • OptionPoolVault.sol: ERC4626 vault for option pool asset management
  • OptionPrice.sol: Black-Scholes options pricing implementation
  • IOptionToken.sol: Interface for option token interactions

Frontend

  • 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

πŸš€ Quickstart

Prerequisites

Before you begin, you need to install the following tools:

Installation & Setup

  1. Install dependencies:
yarn install
  1. Start local blockchain (Terminal 1):
yarn chain
  1. Deploy contracts (Terminal 2):
yarn deploy
  1. Start frontend (Terminal 3):
yarn start
  1. 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

Testing

Run smart contract tests:

yarn foundry:test

🎯 Key Features

Options Trading

  • 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

Liquidity Management

  • 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

Security & Access Control

  • 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

πŸ› οΈ Development

Smart Contract Development

  • Contracts: packages/foundry/contracts/
  • Tests: packages/foundry/test/
  • Deployment Scripts: packages/foundry/script/

Frontend Development

  • 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/

Configuration

  • Scaffold Config: packages/nextjs/scaffold.config.ts
  • Foundry Config: packages/foundry/foundry.toml
  • Deployed Contracts: packages/nextjs/contracts/deployedContracts.ts

πŸ”§ Contract Interactions

Reading Data

const { data: optionPrice } = useScaffoldReadContract({
  contractName: "OptionPrice",
  functionName: "blackScholesPrice",
  args: [underlying, strike, timeToExpiration, volatility, riskFreeRate, isCall],
});

Writing Data

const { writeContractAsync: writeOpHookAsync } = useScaffoldWriteContract({
  contractName: "OpHook"
});

await writeOpHookAsync({
  functionName: "addLiquidity",
  args: [permit, key, liquidityParams, hookData],
});

πŸ“š Documentation

🀝 Contributing

We welcome contributions to OpSwap! Please see CONTRIBUTING.md for guidelines.

πŸ“„ License

This project is licensed under the MIT License - see the LICENSE file for details.

⚠️ Disclaimer

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.

About

No description, website, or topics provided.

Resources

License

Contributing

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published