Smart Contracts

For hackathon delivery, we use smart contracts in both the core trading surface and demo flows to prove that market pricing, position accounting, and settlement logic can run on BNB Smart Chain testnet end-to-end.

How contracts are used in this project

Pseudocode: BinaryPredictionAMM

High-level flow used by the demo contract at contracts/BinaryPredictionAMM.sol.

STATE
  Market { question, yesPool, noPool, resolved, outcomeYes, totalYesShares, totalNoShares, finalPool, winningShares }
  markets[marketId]
  userYesShares[marketId][user]
  userNoShares[marketId][user]

INIT(feeBps)
  require feeBps < 10000
  save feeBps

createMarket(question, seed)
  onlyOwner
  require non-empty question
  require msg.value == seed
  split seed into yesPool and noPool
  mark market exists

addLiquidity(marketId)
  require market exists and not resolved
  split msg.value equally into yesPool/noPool

buyYes(marketId)
  require market active and has liquidity
  netIn = msg.value - fee
  sharesOut = cpmmOut(netIn, yesPool+virtual, noPool+virtual)
  update pools: yesPool += netIn, noPool -= sharesOut
  credit userYesShares

buyNo(marketId)
  mirror of buyYes
  update pools: noPool += netIn, yesPool -= sharesOut
  credit userNoShares

sellYes(marketId, sharesIn)
  require user has enough yes shares and market active
  amountOut = cpmmOut(sharesIn, noPool+virtual, yesPool+virtual)
  payout = amountOut - fee
  debit userYesShares
  update pools opposite of buyYes
  transfer payout to seller

sellNo(marketId, sharesIn)
  mirror of sellYes

resolveMarket(marketId, outcomeYes)
  onlyOwner
  mark resolved
  finalPool = yesPool + noPool
  winningShares = totalYesShares or totalNoShares (by outcome)

claimWinnings(marketId)
  require resolved and user has winning shares
  payout = finalPool * userWinningShares / winningShares
  zero-out user winning balance
  transfer payout

cpmmOut(amountIn, reserveIn, reserveOut)
  k = reserveIn * reserveOut
  newReserveIn = reserveIn + amountIn
  newReserveOut = k / newReserveIn
  return reserveOut - newReserveOut

Why this matters for BNB ecosystem builders