Start > Build your first market

Build your first market

Explain the full market lifecycle from creation to claim.

Build your first market

This tutorial explains how a Quovra market works from creation to payout.

You will create a mental model for four instructions:

  1. create_market
  2. deposit
  3. settle
  4. claim

Lifecycle

mermaid
stateDiagram-v2
  [*] --> Created
  Created --> Funded: deposit YES/NO
  Funded --> Closed: close_ts reached
  Closed --> Resolved: settle(TxLINE proof)
  Resolved --> Claimed: winner claim()
  Closed --> Closed: invalid proof reverts

1. Define the market

A market stores the terms needed to verify a future proof:

FieldExamplePurpose
market_id250701Stable market identifier
fixture_id18250701TxLINE fixture id
stat_key1Stat to prove
threshold0Predicate threshold
close_tskickoff timestampDeposit cutoff
question"Will Spain score in the final?"Public market copy

Quovra rebuilds the predicate from stored terms during settlement. A caller cannot submit different terms later.

2. Create the market

The create_market instruction initializes:

  • Market PDA
  • vault authority PDA
  • SPL token vault
  • stored fixture/stat terms

TypeScript example:

ts
await program.methods
  .createMarket(new BN(250701), new BN(18250701), 1, 0, new BN(closeTs), "Will Spain score in the final?")
  .accounts({
    authority,
    market,
    mint,
    vaultAuthority,
    vault,
    tokenProgram: TOKEN_PROGRAM_ID,
    associatedTokenProgram: ASSOCIATED_TOKEN_PROGRAM_ID,
    systemProgram: SystemProgram.programId,
  })
  .rpc()

Expected result:

  • The market account exists.
  • The vault token account exists.
  • resolved = false.

3. Deposit

Users deposit devnet USDC on YES or NO.

ts
await deposit(connection, wallet, marketPubkey, 1, 10)

Expected result:

  • 10 devnet USDC moves to the vault.
  • The user's Position PDA records outcome 1.
  • Additional deposits must use the same outcome.

4. Settle

After the fixture ends, a keeper submits the TxLINE stat-validation payload.

bash
cd app
SOLANA_KEYPAIR=~/.config/solana/quovra-dev.json npm run keeper:settle -- --execute

Expected result:

  • Quovra CPIs into txoracle.validate_stat.
  • A valid proof returns a boolean.
  • The market stores yes_won.
  • Invalid proof transactions revert.

5. Claim

Winning wallets claim with a separate pull-payment transaction.

ts
const signature = await claim(connection, wallet, marketPubkey)

Expected result:

  • The winner receives stake plus pro-rata losing-pool share.
  • position.claimed = true.
  • Repeated claims fail with AlreadyClaimed.

Related pages

Search keywords

create_market, deposit, settle, claim, lifecycle, prediction market

Last updated: [YYYY-MM-DD]