It is a decentralized options trading platform built with Solidity using Foundry and a modern Next.js frontend.
- It is a comprehensive Automated Market Maker (AMM) for options trading that I developed leveraging Foundry and React.
- It consists of multiple sub-components:
- Smart Contract (OptionAMM): Core options trading contract with liquidity management
- Frontend Application: Modern Next.js interface for seamless options trading
- Liquidity Management: Users can provide liquidity and earn profits from options trading
- Real-time Price Feeds: Integration with Chainlink oracles for accurate price data
- The platform enables users to create and trade both call and put options with customizable parameters including strike price, lot size, premium, and expiry.
- It implements advanced DeFi strategies including:
- Automated options creation and settlement
- Dynamic premium calculation with minimum thresholds
- Liquidity pool management for options backing
- Real-time ETH/USD price integration via Chainlink
- Supports Ethereum Mainnet and Sepolia testnet with configurable network settings.
- Call & Put Options: Create and trade both types of options
- Flexible Parameters: Customizable strike price, lot size, premium, and expiry
- Option Settlement: Options can be settled after expiry whenever owner wants based on current market price
- Liquidity Provision: Users can add USDC liquidity to back options
- Dynamic Management: Add and remove liquidity as needed
- Chainlink Oracles: Reliable ETH/USD price feeds
- Gas Optimized: Price fetching optimized to use view functions (0 gas cost)
- Accurate Settlement: Options settle based on real market prices
- OptionAMM Contract: Main trading contract handling options creation, trading, and settlement
- IERC20 Integration: USDC token support for premium payments and settlements
- Chainlink Integration: Real-time price feeds for accurate option pricing
- Next.js Application: Modern React-based user interface
- Wallet Integration: RainbowKit for seamless wallet connections
- Real-time Updates: Live price feeds and portfolio tracking
- Responsive Design: Mobile-friendly interface
- git: You'll know you did it right if you can run
git --version
and you see a response likegit version x.x.x
- foundry: You'll know you did it right if you can run
forge --version
and you see a response likeforge 0.2.0 (816e00b 2023-03-16T00:05:26.396218Z)
- Node.js: You'll know you did it right if you can run
node --version
and you see a response likev18.x.x
- npm: You'll know you did it right if you can run
npm --version
and you see a response like8.x.x
- Install OptionAMM
git clone https://github.com/yug49/OptionAMM
cd OptionAMM
- Navigate to the smart contract directory
cd dexCode
- Make a .env file
touch .env
- Open the .env file and fill in the details similar to:
SEPOLIA_RPC_URL=<YOUR SEPOLIA RPC URL>
PRIVATE_KEY=<YOUR PRIVATE KEY>
ETHERSCAN_API_KEY=<YOUR ETHERSCAN API KEY>
- Install dependencies and libraries
forge install
- Build Smart Contract
forge build
- Navigate to the frontend directory
cd ../option-amm-app
- Install frontend dependencies
npm install
- Create frontend environment file
touch .env.local
- Configure your .env.local file:
NEXT_PUBLIC_WALLETCONNECT_PROJECT_ID=<YOUR_WALLETCONNECT_PROJECT_ID>
NEXT_PUBLIC_CONTRACT_ADDRESS=<DEPLOYED_CONTRACT_ADDRESS>
For Sepolia testnet deployment:
cd dexCode
forge script script/DeployOptionAMM.s.sol --rpc-url $SEPOLIA_RPC_URL --private-key $PRIVATE_KEY --etherscan-api-key $ETHERSCAN_API_KEY --broadcast --verify --legacy -vvv
once deployed, grab the deployed contract address of your OptionAMM and replace the previous one in option-amm-app/.env.local
- Build the frontend application:
cd option-amm-app
npm run build
- Start the development server:
npm run dev
- Access the application at
http://localhost:3000
- Connect Wallet: Use a browser or external wallet to connect with the app
- Set Parameters: Choose strike price, lot size, premium, and expiry
- Create Option: Submit transaction to create the option
- Monitor: Track your created options in the dashboard
- Browse Options: View available options in the marketplace
- Purchase Options: Buy options by paying the premium
- Manage Portfolio: Track your option positions
- Settlement: Options can be settled after expiry
- Add Liquidity: Deposit USDC to the liquidity pool
- Manage Position: Add or remove liquidity as needed
cd dexCode
source .env
forge test --fork-url $SEPOLIA_RPC_URL
- The platform supports Sepolia testnet
- Network configuration is handled in the frontend application
- Update contract addresses in the frontend environment variables
- Chainlink ETH/USD price feeds are configured in the smart contract
- Supports multiple networks with different price feed addresses
- Automatic price updates in the market info tab after every 30 seconds.
Loved it? Let's connect on: