# How Betonchain Works

## Betting

#### Market Creation

Betting is opened 5 minutes after bet positions are intitialized for a game. Betting is closed 15 minutes before game start time. These buffers are represented by `uint256 public betStartBuffer` and `uint256 public betEndBuffer`contract variables and are updateable.

#### Market Finalization

After a batch request of game results is fulfilled on-chain, corresponding bet positions are closed and locked/available user balances are adjusted based on results. Any unused collateral is freed and rolled over to new active bet positions. Any house profit is claimed at the end of an LP round. For more details on house liquidity, visit [this section](https://docs.betonchain.gg/platform-reference/bookmaker-protocol-to-decentralize-the-house-edge).

{% hint style="info" %}
It can currently take up to **\~12-24** hours after game completion for results to post and user balances to update. Please be patient!
{% endhint %}

## Odds

Odds and game data is stored on-chain after requests to the Chainlink node are fulfilled. Deployed jobs request our public API endpoints and parse responses.&#x20;

{% hint style="success" %}
Response data from `/chainlink` endpoints called by our contracts is all `uint256` for low gas consumption.
{% endhint %}

GET <https://betonchain.gg/api/chainlink/health> (not called on-chain) should return the response

```json
{
    "status": "ok",
    "version": "0.1.0"
}
```

## Fantasy

Betonchain offers accessible, secure, and trustless on-chain **Fantasy contests** through a dedicated Progressive Web DApp (PWDA). Contests are created and managed via protocol smart contracts. **To install the app, visit** [**https://betonchain.gg/**](https://betonchain.gg/) **from your mobile device.**&#x20;

Contests are currently at a team-level, and transpire over various time lengths (daily, weekly, season-long, etc). These include 50/50 Matchup Winner and other types of player contests. Players create and submit their lineups along with an entry fee to participate.&#x20;

The prize pool consists of all collected entry fees minus a winners fee charged by the protocol. Prize pools are evenly distributed to winners.&#x20;

Winners can claim their winnings at any time. Winners and losers are finalized off-chain depending on the pool type, and are easily verifyable.&#x20;

Odds and game data is available on-chain and pulled from our Chainlink consumer. For team-level fantasy contests, a player's points are determined by their selected positions' odds. For example, the underdog in a matchup would yield more points than the favored team. Winners and losers are determined based on points earned.&#x20;

{% hint style="info" %}
**Users earn no points for postponed or canceled games.** If a contest pool consists only of postponed or canceled games, then everyone is tied.
{% endhint %}

### Contest Types

#### 50/50 Matchup WInner

Players submit a lineup of matchup winners. Top 50% of the players win, bottom 50% lose. Ties are determined at random via Chainlink VRF. If there is an odd number of players, there will be an extra winner.

#### All or Nothing Matchup Winner

Players submit a lineup of matchup winners. The top player wins the entire prize pool, everyone else loses. Ties are determined at random via Chainlink VRF.

#### Long Tail Matchup Winner

Players submit a lineup of matchup winners. Ties are determined at random via Chainlink VRF. The prize pool distribution depends on the number of participants as follows:

<table><thead><tr><th width="146">Participants</th><th width="212">Position Paid</th><th>Prize</th></tr></thead><tbody><tr><td>1</td><td>1st</td><td>100%</td></tr><tr><td>2 - 4</td><td>1st and 2nd</td><td>70% and 30%</td></tr><tr><td>5 - 9</td><td>1st 2nd and 3rd</td><td>50% 30% and 20%</td></tr><tr><td>10 - 19</td><td>1st 2nd 3rd and 4th</td><td>50% 25% 15% and 10%</td></tr><tr><td>20+</td><td>1st 2nd 3rd 4th and 5th</td><td>40% 25% 20% 10% and 5%</td></tr></tbody></table>

### LP Vaults

Betonchain pools liquidity in USDT, USDC and DAI. These tokens are provided by LPs and used to seed active bet positions with collateral. LPs are directly incentivized by the protocol via juice from fixed-odds. The protocol's immutable contract checks ensure potential payouts based on odds and volume on counter positions and seeded liquidity. Seeded liquidity for bet positions are managed by the Betonchain DAO and are a % of TVL in [House liquidity pools](https://docs.betonchain.gg/bookmaker-protocol-to-decentralize-the-house-edge#house-liquidity-pools) to manage risk.

{% hint style="success" %}
**Betonchain can drive infinite volume** (provided seeded liquidity is large enough).
{% endhint %}

If available collateral is fully used for a bet position, betting would be halted for that position (0 max bet allowed) until users, or automated betting vaults, take risk on a counter position. Betonchain is arbitrage-proof with no fees (besides inherent juice), slippage, or skew.&#x20;

### API

Our API aggregates consistent, accurate and real-time odds data from 11+ high volume bookies across more than a dozen sports leagues. The backend stack includes scripts that ensure attribute bindings and perform pragma optimized database operations with custom error handling and logging. Our API is written in Rust and features robust request handlers with consistent responses and powerful request routing. For more information on the API please visit the [framework docs](https://docs.rs/actix-web/latest/actix_web/) or [reach out](https://discord.gg/rrpyAwWEb7) on our Discord.&#x20;

### Smart Contracts

Contract methods that initialize and update state variables (game results, odds, etc.) are immutable and directly pull data from the Chainlink consumer contract **BetConsumer.sol**. **BetCore.sol** interacts with child contracts and faciltiates betting on Moneylines, Over Under, Point Spread and Parlays with fund forwarding and available user balances. **BetPoolDeployer.sol** creates and manages on-chain fantasy pools.

Contracts emit events relevant to the scope of their functionalities, for more details please visit the [Developers](https://docs.betonchain.gg/platform-reference/developers) section.
