Motivation:
- Create a simple, trustless, decentralized betting platform
- Users can bet on the price of BTC in V1, and multiple assets in V2
- Users bet with USDC
- The winner of the bet gets the loser's USDC
- The winner is determined by the price of BTC at the closing time of the bet
- The winner can withdraw their winnings at any time
Overview flow:
- Isolated deposit token (USDC) and single betting asset (BTC)
- Isolated deposit token (USDC) and multiple betting assets (BTC, ETH, LINK, etc.) - V2
- User A opens a pending bet position
- Selects side (long/short)
- Bet amount in USDC
- Expiration time (counterparty has to accept the bet before this time)
- Closing time (what point in time the conditions of the bet must be evaluated)
- Deposits USDC
- User B selects a pending bet to join
- Opposing side of User A's bet (short/long)
- Deposits USDC (same amount as User A's bet)
- Bet becomes active
- Fetch btcusd price (Chainlink price feed), store in contract
- Winner is determined once closing time is reached
- Fetch btcusd price (Chainlink price feed)
- If price is higher than opening price, long wins, else short wins
- If long wins, long gets their deposit back + short's deposit
- If short wins, short gets their deposit back + long's deposit
- Winner withdraws their winnings
Requirements:
git: https://git-scm.com/book/en/v2/Getting-Started-Installing-Git foundry: https://getfoundry.sh/
Quickstart
git clone https://github.com/smughal55/bet-broker-protocol cd bet-broker-protocol
Dependencies
Run forge install smartcontractkit/chainlink-brownie-contracts Openzeppelin/openzeppelin-contracts
Build
forge build
Testing
Run forge test