Cap Bet LogoCap Bet Docs

Smart Contracts SDK

Interact with Cap Bet's Anchor programs on Solana

Smart Contracts SDK

Cap Bet's smart contracts are built with the Anchor framework and deployed on Solana devnet.

Program Information

  • Program ID: 13vTbpPE73XtVZ9AxWQMDdasp3M3LXKMMiujqPZvxbkD
  • Network: Solana Devnet
  • Framework: Anchor
  • Language: Rust

Installation

npm install @capbet/sdk @coral-xyz/anchor @solana/web3.js

Quick Start

import { AnchorProvider, Program } from '@coral-xyz/anchor';
import { Connection, Keypair } from '@solana/web3.js';
import { CapBet } from '@capbet/sdk';
import idl from '@capbet/sdk/idl.json';

// Setup connection
const connection = new Connection('https://api.devnet.solana.com');
const wallet = Keypair.generate();
const provider = new AnchorProvider(connection, wallet, {});

// Initialize program
const program = new Program(idl, provider);

Instructions

Create Market

Create a new betting market:

const marketKeypair = Keypair.generate();

await program.methods
  .createMarket(
    "Will SOL reach $200?",
    new BN(Date.now() / 1000 + 86400 * 30), // Lock time (30 days)
    new BN(0.1 * LAMPORTS_PER_SOL), // Min bet
    new BN(1000 * LAMPORTS_PER_SOL), // Max bet
  )
  .accounts({
    market: marketKeypair.publicKey,
    creator: wallet.publicKey,
    systemProgram: SystemProgram.programId,
  })
  .signers([marketKeypair])
  .rpc();

Take Opposite Side

Bet on the opposite side of a market:

await program.methods
  .takeOpposite(
    true, // isYes
    new BN(10 * LAMPORTS_PER_SOL), // Amount
  )
  .accounts({
    market: marketPubkey,
    position: positionPubkey,
    user: wallet.publicKey,
    systemProgram: SystemProgram.programId,
  })
  .rpc();

Claim Winnings

Claim winnings after market resolution:

await program.methods
  .claim()
  .accounts({
    market: marketPubkey,
    position: positionPubkey,
    user: wallet.publicKey,
  })
  .rpc();

State Accounts

Market Account

pub struct Market {
    pub creator: Pubkey,
    pub title: String,
    pub lock_ts: i64,
    pub total_yes: u64,
    pub total_no: u64,
    pub status: MarketStatus,
    pub oracle_result: Option<bool>,
}

Position Account

pub struct Position {
    pub market: Pubkey,
    pub user: Pubkey,
    pub is_yes: bool,
    pub amount: u64,
    pub matched_amount: u64,
    pub claimed: bool,
}

Complete Instruction List

  1. create_market - Create a new betting market
  2. take_opposite - Take opposite side of a bet
  3. claim - Claim winnings
  4. cancel_if_no_opponent - Cancel if no opponent
  5. challenge - Challenge oracle resolution
  6. adjudicate_challenge - Adjudicate challenge
  7. manual_resolve - Propose manual resolution
  8. adjudicate_manual_resolution - Validate manual resolution
  9. timeout_manual_proposal - Timeout manual proposal
  10. resolve_pending - Resolve market (oracle)
  11. finalize - Finalize after challenge window
  12. withdraw_unmatched - Withdraw unmatched funds
  13. sweep_market - Clean up market data

Error Codes

CodeNameDescription
6000MarketLockedMarket is locked for new positions
6001MarketNotLockedMarket not yet locked
6002AlreadyClaimedPosition already claimed
6003NotResolvedMarket not yet resolved
6004InvalidAmountInvalid bet amount

Examples

See complete examples for more detailed use cases.

Smart Contracts SDK | Cap Bet Docs