This project implements a decentralized automated market maker (AMM) for prediction markets using Solidity. It allows users to add liquidity, buy shares, and predict outcomes in a decentralized manner. The contract is fully compatible with ERC20 tokens for collateral and integrates key functionalities like liquidity provision, share trading, and market resolution.
- Overview
- Features
- Technology Stack
- Getting Started
- Usage
- Smart Contract Details
- Security Considerations
- License
The AMM Prediction Market Contracts allow users to:
- Provide liquidity in ERC20 tokens.
- Buy shares for
yes
orno
outcomes of a prediction market. - Resolve markets based on outcomes and redeem winnings.
The AMM uses a constant product formula to calculate the price of shares, ensuring liquidity is always available. A small fee is charged on each transaction to incentivize liquidity providers.
-
Automated Market Maker (AMM):
- Liquidity pools for
yes
andno
outcomes. - Dynamic pricing based on the constant product formula.
- Liquidity pools for
-
Liquidity Provision:
- Add or remove liquidity in ERC20 tokens.
- Reward liquidity providers with a share of the pool.
-
Prediction Market:
- Buy shares for
yes
orno
outcomes. - Resolve markets and redeem winnings.
- Buy shares for
-
Fee Mechanism:
- 1% fee on every share purchase.
- Solidity: Smart contract programming language.
- Foundry: Development framework for Ethereum smart contracts.
- OpenZeppelin: Reusable, secure smart contract components.
- ERC20 Standard: Token standard for collateral.
Before running the project, ensure you have the following installed:
-
Clone the repository:
git clone <repository_url> cd AMM-Prediction-Market-Contracts
-
Install dependencies:
forge install
-
Compile the contracts:
forge build
- Deploy the contracts using Foundry:
forge script script/Deploy.s.sol --tc Deploy --broadcast --rpc-url $RPC_URL --private-key $PRIVATE_KEY
- Run the test using Foundry:
forge test
The main contract for the prediction market. Users can:
- Add liquidity to the pool.
- Buy
yes
orno
shares. - Resolve the market and redeem winnings.
addLiquidity(uint256 amount)
: Add liquidity to the market.buyShares(uint256 yesAmount, uint256 noAmount)
: Buy shares foryes
orno
outcomes.resolveMarket(address winningOutcome)
: Resolve the market with the winning outcome.redeemWinnings()
: Redeem winnings after the market is resolved.
LiquidityAdded
: Emitted when liquidity is added.LiquidityRemoved
: Emitted when liquidity is removed.SharesPurchased
: Emitted when shares are purchased.MarketResolved
: Emitted when the market is resolved.
-
Modular AMM Liquidity Management:
- Create a separate smart contract dedicated to managing AMM liquidity.
- Improves code modularity, readability, and ease of maintenance.
- Allows better scalability and flexibility in upgrading liquidity mechanisms.
-
Decouple Auction Mechanism:
- Separate the auction logic from the main smart contract.
- Facilitates cleaner architecture and enables independent upgrades or changes to the auction system.
-
Support for Multiple Auction Types:
- Implement various auction mechanisms (e.g., Dutch auctions, English auctions, sealed-bid auctions).
- Enhance the platform's functionality and cater to diverse use cases.
-
Enhanced Administrative Controls:
- Introduce a more robust and granular administration framework for managing auctions and liquidity.
- Implement role-based access control (RBAC) for better governance and reduced risk of misuse.
-
Comprehensive Testing Suite:
- Write extensive test cases using Foundry to ensure reliability and security:
- Load Testing: Simulate high transaction volumes to test contract performance under stress.
- Fuzzy Testing: Use random inputs to uncover edge cases and unexpected behaviors.
- Negative Testing: Test invalid scenarios to ensure the contract handles errors gracefully and securely.
- Write extensive test cases using Foundry to ensure reliability and security:
A mock ERC20 token used for testing and as collateral in the AMM.
- Implements the ERC20 standard.
- Mints 1 million tokens to the deployer.
- Ensure the
owner
account is securely managed, as it has the ability to resolve the market. - Validate external input carefully to avoid exploits.
- Perform rigorous testing, especially when deploying on a production network.
- Auditing by a third party is recommended before production deployment.