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
- Demo-market execution layer: the BinaryPredictionAMM contract handles market creation, YES/NO position trading, resolution, and winner claims.
- Main engine integration path: the C++ matcher finds spread opportunities, then execution tooling can route selected opportunities into on-chain transaction flow when live execution is enabled.
- Hackathon validation: this setup validates arbitrage behavior, market-state transitions, and payout correctness before scaling to broader production integrations.
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 - newReserveOutWhy this matters for BNB ecosystem builders
- Deterministic on-chain settlement for prediction positions.
- Composable interfaces that downstream arbitrage agents can automate against.
- Faster iteration with testnet-first market simulations during hackathons.