This Prediction Market project integrates Uniswap V3 for token trading and UMA's Optimistic Oracle V3 for market resolution. Users can create markets, trade outcome tokens, and settle markets based on resolved outcomes.
- Manages market creation, outcome token minting, and resolution.
- Interacts with UMA's Optimistic Oracle V3 for outcome assertion and market resolution.
- Automated Market Maker (AMM) for trading outcome tokens.
- Enables liquidity provision and token swaps based on predictions.
- Provides utility functions for managing markets and calculating payouts.
Function: initializeMarket()
Parameters:
outcome1: Name of the first outcome (e.g., "Yes").outcome2: Name of the second outcome (e.g., "No").description: Market description (e.g., "Will it rain tomorrow?").reward: Reward amount in ERC20 currency tokens.requiredBond: Bond amount required for market assertion.poolFee: Fee tier for the associated Uniswap V3 pool.
Frontend Considerations:
- Users must approve the contract to spend the
rewardamount. - Returns a unique
marketIdused for all future interactions.
Function: createOutcomeTokens()
Parameters:
marketId: The unique identifier of the market.tokensToCreate: Amount of tokens to mint.
Frontend Considerations:
- Users must approve the contract to spend currency tokens.
- Equal amounts of
outcome1andoutcome2tokens are minted. - Tokens can be traded in the associated Uniswap V3 pool.
Contract: UniswapV3AMMContract.sol
Methods:
swap(): Swap between outcome tokens based on predictions.addLiquidity(): Provide liquidity to the Uniswap pool.removeLiquidity(): Remove liquidity from the pool.
Frontend Considerations:
- Could use Uniswap V3 SDK for precise liquidity management (Only Idea)
- Ensure correct token approvals for liquidity provision and swaps.
Function: assertMarket()
Parameters:
marketId: ID of the market being asserted.assertedOutcome: Proposed outcome (outcome1,outcome2, orUnresolvable).
Frontend Considerations:
- Users must approve the contract to spend the
requiredBondamount. - Only one assertion is allowed per market.
- Assertions are processed through UMA's Optimistic Oracle V3.
Function: settleOutcomeTokens()
Parameters:
marketId: ID of the market being settled.
Payout Logic:
- If
outcome1is resolved: Full payout foroutcome1tokens. - If
outcome2is resolved: Full payout foroutcome2tokens. - If
Unresolvable: Equal split between token holders.
Frontend Considerations:
- Users must hold outcome tokens to claim payouts.
- Settlement is only possible after market resolution.
- Market does not exist: Ensure the correct
marketIdis used. - Insufficient token approvals: Approve enough tokens for transactions.
- Market not resolved: Wait for UMA Oracle resolution before settling.
- Invalid assertion outcome: Use valid outcome strings (
outcome1,outcome2, orUnresolvable).
// Example interaction flow
async function createAndTradeMarket() {
// Approve currency tokens
await currencyToken.approve(predictionMarketAddress, rewardAmount);
// Initialize a new market
const marketId = await predictionMarket.initializeMarket(
"Team A Win",
"Team B Win",
"Football Match Outcome",
rewardAmount,
bondAmount,
poolFee
);
// Mint outcome tokens
await predictionMarket.createOutcomeTokens(marketId, tokenAmount);
// Trade outcome tokens on Uniswap
await uniswapV3AMM.swap(marketId, inputAmount, minOutputAmount, zeroForOne);
}-
Token Approvals:
- Approve the contract for all necessary ERC20 transactions (reward, bond, token minting).
-
Market Status:
- Verify the market status before asserting or settling.
-
Uniswap V3 Pools:
- Carefully manage liquidity and tick ranges for optimal performance.
-
UMA Resolution:
- Understand the resolution and dispute process for assertions.