> ## Documentation Index
> Fetch the complete documentation index at: https://docs.microset.io/llms.txt
> Use this file to discover all available pages before exploring further.

# Program & Contracts

> The Solana program: ID, instructions, accounts, access control, and events.

<Info>
  This page is the authoritative technical reference for Microset's on-chain
  footprint — a single Anchor program, `prediction_market`, implementing a
  sport-agnostic, parimutuel, multi-outcome market. For a plain-language version,
  see [How Markets Work](/security/smart-contract).
</Info>

## Program identity

| Field                    | Value                                                                                                                      |
| ------------------------ | -------------------------------------------------------------------------------------------------------------------------- |
| Program name             | `prediction_market` (Anchor)                                                                                               |
| Program ID               | `B6nzqfZfxJ2UyAGD7ko3zSa2QLF8aWNjHqjkDqh1dzsC`                                                                             |
| Cluster                  | Solana **devnet**                                                                                                          |
| Used by                  | Frontend (`app.microset.io`) and backend API                                                                               |
| Explorer                 | [View on Solana Explorer](https://explorer.solana.com/address/B6nzqfZfxJ2UyAGD7ko3zSa2QLF8aWNjHqjkDqh1dzsC?cluster=devnet) |
| Treasury (fee recipient) | `3AzAex6froVqKX4EknPHsccZK8YjmFtqkzR3dWDxn9Cz`                                                                             |
| Upgrade authority        | A single key held by Microset                                                                                              |

## Instructions

### Core

| Instruction         | Purpose                                                                          | Who can call                                                                      |
| ------------------- | -------------------------------------------------------------------------------- | --------------------------------------------------------------------------------- |
| `initialize_config` | Create the global `Config` (treasury, fee, resolution authority); unpause        | One-time setup by the deployer                                                    |
| `update_config`     | Update treasury, fee, resolution authority, or pause state                       | `config.authority` only                                                           |
| `create_market`     | Create a market (`market_id`, outcomes, name, close/resolve times) and its vault | Microset's backend authority (markets are created **authority-only** in practice) |
| `place_bet`         | Stake SOL on an outcome                                                          | Any user                                                                          |
| `resolve`           | Set the winning outcome; send the protocol fee to the treasury                   | `config.resolution_authority` only                                                |
| `void_market`       | Void a market so users can claim full refunds                                    | `config.resolution_authority` only                                                |
| `claim`             | Pay a winner's proportional share, or refund a voided market                     | The staking user                                                                  |

### Quick-prediction delegate session

To let users make repeated predictions without re-prompting their wallet, the program
supports an explicit, user-funded **delegate session**:

| Instruction               | Purpose                                                                                                                               |
| ------------------------- | ------------------------------------------------------------------------------------------------------------------------------------- |
| `create_delegate_session` | User signs once to create a session for a delegate key, funding an escrow with a spend cap (`max_lamports`) and expiry (`expires_at`) |
| `fund_delegate_session`   | Add SOL to an existing session (raises escrow and cap)                                                                                |
| `place_bet_with_delegate` | Make a prediction signed by the delegate key, drawn from the capped escrow                                                            |
| `withdraw_delegate_funds` | Withdraw unused escrow back to the owner                                                                                              |
| `revoke_delegate_session` | Revoke the session at any time                                                                                                        |

## Access control

| Role                   | Holder                        | Powers                                                    |
| ---------------------- | ----------------------------- | --------------------------------------------------------- |
| `authority`            | A single key held by Microset | Update config, treasury, fee, resolution authority, pause |
| `resolution_authority` | Microset's backend key        | Resolve and void markets                                  |
| Market creation        | Authority-only in practice    | Markets are created by Microset's backend                 |

<Note>
  The protocol fee (`protocol_fee_bps`) and resolution authority are stored in the
  on-chain `Config` and can be changed only by `config.authority`. The fee is
  capped on-chain (`InvalidFeeBps` if it exceeds 100%).
</Note>

## Accounts

| Account                                     | Role                                                                                                       |
| ------------------------------------------- | ---------------------------------------------------------------------------------------------------------- |
| `Config` (PDA `["config"]`)                 | Global config: `authority`, `treasury`, `protocol_fee_bps`, `resolution_authority`, `paused`               |
| `Market` (PDA `["market", market_id]`)      | One market: outcomes, per-outcome stake totals, close/resolve times, resolved state                        |
| `UserStake` (PDA `["stake", user, market]`) | A user's per-outcome stake and claim status                                                                |
| Vault (PDA `["vault", market]`)             | Program-owned account holding all of a market's staked SOL                                                 |
| `DelegateSession`                           | A quick-prediction session: `owner`, `delegate`, `max_lamports`, `spent_lamports`, `expires_at`, `revoked` |
| `DelegateEscrow`                            | Holds the SOL funding a delegate session                                                                   |

## Funds & settlement

* All stakes for a market sit in **one vault PDA**, with per-outcome accounting.
* On `resolve`, the protocol fee is taken from the pool and sent to the treasury (`3AzAex6f…xn9Cz`); the remainder is locked in for winners. If there are no winners, the pool goes to the treasury.
* `claim` pays each winner their proportional share of the post-fee pool; a voided market refunds stakes in full with no fee.
* Quick-prediction escrow is bounded by the user-set `max_lamports` cap and is revocable and withdrawable at any time.

## Resolution data

Microset does not set outcomes itself. Resolution is **triggered by third-party
data APIs**: when a recognized sports data provider (the Roanuz Sports API for
cricket) reports a final result, that result drives the `resolve` instruction,
which the resolution authority submits on-chain. This keeps outcomes tied to
real-world events rather than to Microset's discretion.

## Events

| Event            | Emitted by                              |
| ---------------- | --------------------------------------- |
| `CreateMarket`   | `create_market`                         |
| `BetPlaced`      | `place_bet` / `place_bet_with_delegate` |
| `MarketResolved` | `resolve`                               |
| `Claimed`        | `claim`                                 |
| `MarketVoided`   | `void_market`                           |

## Source & verification

* The Microset web app at `app.microset.io` and its backend both reference this program ID and IDL, which match the deployed program.
* Security review: internal security audits and vulnerability testing completed.
