Conditional Token Framework (CTF) implementation for prediction markets using ERC1155 tokens and AMM integration.
- Purpose: Manages prediction market conditions and position tokens
- Inherits: ERC1155 for token management
- Key Functions:
prepareCondition(): Creates new prediction marketsplitPosition(): Converts collateral into outcome tokensmergePositions(): Combines outcome tokens back to collateralredeemPositions(): Redeems winning tokens after resolution
- conditionId:
keccak256(oracle + questionId + outcomeSlotCount) - collectionId:
keccak256(parentCollectionId + conditionId + indexSet) - positionId:
keccak256(collateralToken + collectionId)
- Tokens minted directly to AMM address
- Users cannot acquire tokens for trading
- No mechanism for users to participate in markets
User deposits USDC → CTF mints YES/NO tokens → AMM holds all tokens
❌ Users can't trade because they don't have tokens
User deposits USDC → CTF mints YES/NO tokens → Users get tokens
LP deposits USDC → AMM gets liquidity → Users trade tokens on AMM
✅ Users have tokens to trade, AMM has liquidity to facilitate trading
- Token Distribution: Mint tokens to users, not AMM
- Liquidity Provision: Separate LP mechanism for AMM
- Pricing:
price(YES) + price(NO) = 1(constant sum)
- AMM Contract: For token trading and liquidity management
- LP Functions: For liquidity provision
- Trading Interface: Buy/sell functions for users
- Price Discovery: Constant sum pricing mechanism
// AMM Contract
function buyTokens(uint positionId, uint amount, uint maxPrice)
function sellTokens(uint positionId, uint amount, uint minPrice)
function addLiquidity(uint amount)
function getPrice(uint positionId)- Market Creation: Creator sets up condition and provides initial liquidity
- Position Creation: User deposits collateral, gets outcome tokens
- Trading: User trades tokens on AMM with LP liquidity
- Resolution: Oracle reports results, users redeem winning tokens
- User Ownership: Users actually own tradeable tokens
- Proper Liquidity: AMM has USDC for trading operations
- Efficient Pricing: Constant sum constraint ensures proper price discovery
- LP Rewards: Liquidity providers earn trading fees
- Market Efficiency: Reflects true market sentiment without arbitrage
on the AMM I need to have an initializePool Function that will be called after the a bet is created.
CTF Contract is only to mint yes/no against collateral token(USDC).
Hierarchial relationship between conditionId collectionId and positionId
conditionId (Question: "Will Bitcoin hit $100K?")
├── collectionId (Outcome: "YES" - indexSet=1)
│ └── positionId (USDC-backed YES tokens)
├── collectionId (Outcome: "NO" - indexSet=2)
│ └── positionId (USDC-backed NO tokens)
└── collectionId (Outcome: "YES|NO" - indexSet=3)
└── positionId (USDC-backed YES|NO tokens)