Accuracy.Fun

0%

Smart Contract

Technical reference for the MarketV1 Compact contract — the core of every Precizion market.

Overview

MarketV1 is a zero-knowledge smart contract written in Compact (v0.23+) for the Midnight Network. It manages the full lifecycle of a single prediction market — from bet placement through resolution and reward distribution.

Language
Compact v0.23
Network
Midnight
Privacy
ZK Proofs
Token
NIGHT

Ledger Fields

Field
Type
Description
admin
Bytes<32>
Admin public key hash (access control currently open)
status
Status
Market state: Active, Closed, Resolved, or Cancelled
totalPool
Uint<128>
Total NIGHT tokens deposited across all bets
endTime
Uint<64>
Unix timestamp when betting period ends
finalValue
Uint<64>
Resolved outcome value (set during resolution)
rewardPool
Uint<128>
Pool allocated for participant rewards (after fee deduction)
feesCollected
Uint<128>
Accumulated platform fees (2% of total pool)
minBet
Uint<128>
Minimum bet amount per participant
maxBet
Uint<128>
Maximum bet amount per participant
betCount
Counter
Total number of bets placed
bets
Map<Bytes<32>, Uint<128>>
Participant public key → bet amount mapping

Circuits

placeBet(_predictedValue: Uint<64>, _betAmount: Uint<128>) → []

Submit a numeric prediction with a NIGHT token stake. Records the bet in the bets map and increments the total pool.

resolve(_finalValue: Uint<64>, _rewardPool: Uint<128>, _fees: Uint<128>) → []

Set the actual outcome value and finalize the reward pool and fee amounts. Transitions market status to Resolved.

closeBetting(—) → []

Close the betting period early. Transitions market status to Closed.

cancelMarket(—) → []

Cancel the market. All participants become eligible for full refunds.

claimRefund(—) → []

Claim a full refund of your bet amount. Available only when market is Cancelled.

withdrawFees(—) → []

Withdraw accumulated platform fees. Currently requires admin authorization.

Market Status

0Pending

Market created but not yet active

1Active

Accepting bets

2Closed

Betting period ended, awaiting resolution

3Resolving

Resolution in progress

4Resolved

Outcome determined, rewards distributed

5Cancelled

Market cancelled, refunds available

Fee Structure

Platform Fee
2%
Deducted from total pool before rewards
Fee Basis
200 bps
Expressed in basis points (feeBps / 10000)
Distribution
100%
All remaining pool goes to participants
rewardPool = totalPool − (totalPool × feeBps / 10000)

Key Constants

Constant
Value
Purpose
PRECISION
1e18 (1,000,000,000,000,000,000)
Fixed-point arithmetic for reward calculations
feeBps
200
Platform fee in basis points (2%)
FEE_DENOMINATOR
10,000
Basis point conversion denominator
DURATION_7_DAYS
604,800 seconds
Default distribution deadline
MIN_DUST_COINS
3
DUST threshold for contract deployment
PROOF_PADDING
8
Merkle proof padding (32-byte words)