Raffle
"Fortune favors the brave" — Latin proverb
Raffle bet type allows users to create or participate in a prize pool competition based on price prediction accuracy. Each player pays a fixed entry ticket price and submits a prediction (the future price of the chosen asset).

How It Works
The initiator sets up the raffle by choosing an asset and an entry ticket price. They fund the initial prize pool, specify the number of players, prize places, and the percentage of the pool each prize place will receive.
Once created, players join by sending the entry ticket fee and their prediction to the smart contract. Betting closes at the “end of bets” time. At the “event end” time, the contract ranks all predictions by absolute difference from the actual price. The amount collected on top of the initiator’s stake is distributed between the initiator and the winners according to a predefined ratio.
Calculations
Key Variables
Sx – Liquidity (prize pool) provided by the initiator
Sy – Total value of all purchased tickets by players
K – Split ratio (0 < K < 1)
f – Platform commission rate
Rx – Payout to the initiator
Ry – Payout to the winners
Fx – Commission from initiator share
Fy – Commission from winners share
Case 1: Player liquidity covers or exceeds the prize pool (Sy ≥ Sx)
Fx = (Sy - Sx) × K × f Fy = (Sx + (Sy - Sx) × (1 - K)) × f Rx = Sx + (Sy - Sx) × K - Fx Ry = Sx + (Sy - Sx) × (1 - K) - Fy
Case 2: Player liquidity is less than the prize pool (Sy < Sx)
Fx = 0 Fy = Sx × f Rx = Sy Ry = Sx - Fy
Example
Initiator provides Sx = 100
Players buy tickets for Sy = 150; K = 0.5
Commission rate f = 0.1 (10%)
The K value is set by P2PLabs.
Let's do the maths:
Fx = (150 - 100) × 0.5 × 0.1 = 2.5
Fy = (100 + (150 - 100) × (1 - 0.5)) × 0.1 = 12.5
Rx = 100 + (150 - 100) × 0.5 - 2.5 = 122.5
Ry = 100 + (150 - 100) × (1 - 0.5) - 12.5 = 112.5
Entry Conditions
To enter, users pay a fixed entry ticket price defined by the competition initiator. All bets and predictions are recorded on-chain.
Timelines
The initiator chooses a start time (creation of the deal, when bets open), an end of bets time (after which no new entries or predictions can be submitted), and an event end (result) time. These timelines are fixed in the smart contract at deal creation.
Outcome & Winners
When the event end time arrives, the smart contract retrieves the asset price via Binance API. It calculates the difference between each player’s prediction and the actual price. The player with the smallest difference is declared first place, the next smallest is second place, etc., up to the number of winners specified. The winners split the total prize pool according to the percentages set by the bet initiator.
If two or more users submit the same winning predictions, the winnings are distributed equally between them.
Data Source
Chart and price data are sourced from the Binance API. Prediction accuracy is calculated based on the delta between each prediction and the actual closing price.
Commission
A 1% commission is charged only on the winnings.
Refund Policy
If a minimum participation threshold is set but not met, the raffle is cancelled and participants are refunded. In all other cases, no refunds are made.
Visibility
Raffles can be created as public, accessible to all users, or private, accessible via the invite link.
Last updated