# Raffle

**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).

<figure><img src="https://4084606022-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FKsOkSrx0HgRuOZgFBrtZ%2Fuploads%2F1dp9jeCTpSJBKPmObIsQ%2FRaffle.png?alt=media&#x26;token=159ec7ca-3acf-4e62-b94c-f9a2dfc4936b" alt=""><figcaption><p>Raffle</p></figcaption></figure>

### 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 submitting their prediction. Betting closes at the “end of bets” time. At the “event end” time all predictions are ranked 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 <a href="#calculations" id="calculations"></a>

**Key Variables**

* S<sub>x</sub> – Liquidity (prize pool) provided by the initiator
* S<sub>y</sub> – Total value of all purchased tickets by players
* K – Split ratio (0 < K < 1)
* f – Platform commission rate
* R<sub>x</sub> – Payout to the initiator
* R<sub>y</sub> – Payout to the winners
* F<sub>x</sub> – Commission from initiator share
* F<sub>y</sub> – Commission from winners share

**Case 1: Player liquidity covers or exceeds the prize pool (S**<sub>**y**</sub>**&#x20;≥ S**<sub>**x**</sub>**)**

> F<sub>x</sub> = (S<sub>y</sub> - S<sub>x</sub>) × K × f F<sub>y</sub> = (S<sub>x</sub> + (S<sub>y</sub> - S<sub>x</sub>) × (1 - K)) × f R<sub>x</sub> = S<sub>x</sub> + (S<sub>y</sub> - S<sub>x</sub>) × K - F<sub>x</sub> R<sub>y</sub> = S<sub>x</sub> + (S<sub>y</sub> - S<sub>x</sub>) × (1 - K) - F<sub>y</sub>

**Case 2: Player liquidity is less than the prize pool (S**<sub>**y**</sub>**&#x20;< S**<sub>**x**</sub>**)**

> F<sub>x</sub> = 0 F<sub>y</sub> = S<sub>x</sub> × f R<sub>x</sub> = S<sub>y</sub> R<sub>y</sub> = S<sub>x</sub> - F<sub>y</sub>

#### Example <a href="#example" id="example"></a>

* Initiator provides S<sub>x</sub> = 100
* Players buy tickets for S<sub>y</sub> = 150; K = 0.5
* Commission rate f = 0.1 (10%)
* The K value is set by **P2PLabs**.

Let's do the maths:

> F<sub>x</sub> = (150 - 100) × 0.5 × 0.1 = 2.5
>
> F<sub>y</sub> = (100 + (150 - 100) × (1 - 0.5)) × 0.1 = 12.5
>
> R<sub>x</sub> = 100 + (150 - 100) × 0.5 - 2.5 = 122.5
>
> R<sub>y</sub> = 100 + (150 - 100) × (1 - 0.5) - 12.5 = 112.5

### Entry Conditions <a href="#entry-conditions" id="entry-conditions"></a>

To enter, users pay a fixed entry ticket price defined by the competition initiator. All bets and predictions are recorded by the platform.

### Timelines <a href="#timelines" id="timelines"></a>

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 platform at deal creation.

### Outcome & Winners <a href="#outcome-and-winners" id="outcome-and-winners"></a>

When the event end time arrives, the asset price is retrieved via the Binance API. 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 <a href="#data-source" id="data-source"></a>

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.

### Refund Policy <a href="#refund-policy" id="refund-policy"></a>

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 <a href="#visibility" id="visibility"></a>

Raffles can be created as **public**, accessible to all users, or **private**, accessible via the invite link.
