Accounts

Fetch and decode on-chain account data using the sdk.accounts object.

Overview

The sdk.accounts object provides typed methods to fetch on-chain account data. Mapper functions convert raw Anchor account structs (which use BN and Rust enum objects) into plain TypeScript objects.

Bet accounts

sdk.accounts.betV2.single(address)

Fetch a single V2 bet by its public key.

typescript
const bet = await sdk.accounts.betV2.single(betAddress);
console.log("Question:", bet.question);

Returns Promise<ProgramBetV2>

sdk.accounts.betV2.all(filters?)

Fetch all V2 bets, with optional memcmp filters.

typescript
const allBets = await sdk.accounts.betV2.all();

// Filter by creator
const myBets = await sdk.accounts.betV2.all([
  { memcmp: { offset: 8, bytes: wallet.publicKey.toBase58() } }
]);

Returns Promise<ProgramAccount<ProgramBetV2>[]>

sdk.accounts.betV4.single(address)

Fetch a single V4 (multi-outcome) bet by its public key.

typescript
const bet = await sdk.accounts.betV4.single(betAddress);
console.log("Question:", bet.question);
console.log("Outcomes:", bet.outcomes.length);

Returns Promise<ProgramBetV4>

sdk.accounts.betV4.all(filters?)

Fetch all V4 bets, with optional memcmp filters.

typescript
const allV4Bets = await sdk.accounts.betV4.all();

Returns Promise<ProgramAccount<ProgramBetV4>[]>

User accounts

sdk.accounts.user.single(address)

Fetches a program user account.

typescript
const userAddress = sdk.addresses.user.get(wallet.publicKey);
const user = await sdk.accounts.user.single(userAddress);

console.log("Total wagers:", user.totalWagersCount);
console.log("Wagered (USDC):", user.totalWageredAmount.toNumber() / 1e6);

Protocol account

sdk.accounts.protocol.single(address)

Fetches the protocol configuration account.

typescript
const protocolAddress = sdk.addresses.protocol.get();
const protocol = await sdk.accounts.protocol.single(protocolAddress);

console.log("Fee %:", protocol.feePercentage);
console.log("Total bets:", protocol.totalUniqueBets);

Mapper functions

Raw on-chain accounts use BN for big numbers and Rust enum objects like { pending: {} }. Mapper functions convert these to plain numbers and strings:

sdk.accounts.mapBetV2(rawBet)

Maps a V2 bet to a plain TypeScript object.

typescript
const rawBet = await sdk.accounts.betV2.single(address);
const bet = sdk.accounts.mapBetV2(rawBet);

console.log("Status:", bet.status);        // "Pending" (not { pending: {} })
console.log("For total:", bet.totalOiFor); // number (not BN)

sdk.accounts.mapBetV4(rawBet)

Maps a V4 (multi-outcome) bet to a plain TypeScript object.

typescript
const rawBet = await sdk.accounts.betV4.single(address);
const bet = sdk.accounts.mapBetV4(rawBet);

console.log("Status:", bet.status);                       // "Pending"
console.log("Winner index:", bet.resolvedOutcomeIndex);   // number | null
bet.outcomes.forEach((o, i) => console.log(i, o.label, o.totalOi));

sdk.accounts.mapUser(rawUser)

Maps a user account to a plain object.

typescript
const raw = await sdk.accounts.user.single(userAddress);
const user = sdk.accounts.mapUser(raw);

console.log("Wagered:", user.totalWageredAmount); // plain number

sdk.accounts.mapProtocol(rawProtocol)

Maps the protocol account to a plain object.

typescript
const raw = await sdk.accounts.protocol.single(protocolAddress);
const protocol = sdk.accounts.mapProtocol(raw);

Raw structures

The raw on-chain structures below are returned by account fetch methods before mapping:

ProgramBetV2
interface ProgramBetV2 {
  creator: PublicKey;
  createdAt: BN;
  updatedAt: BN;
  resolvedAt: BN;
  distributedAt: BN;
  voteInitiatedAt: BN;
  status: { pending: {} } | { resolving: {} } | { resolved: {} } | { distributed: {} };
  resolvedOutcome: { for: {} } | { against: {} } | { tied: {} };
  question: string;
  expectedUserCount: number;
  minimumVoteCount: number;
  totalOiFor: BN;
  totalOiAgainst: BN;
  poolAddress: PublicKey;
  wagers: Wager[];
  votes: Vote[];
  wagerId: BN;
  isCreatorResolver: boolean;
  settledUserCount: number;
  totalBatchesRequired: number;
}
Wager
interface Wager {
  user: PublicKey;
  amount: BN;
  outcome: { for: {} } | { against: {} };
  updatedAt: BN;
  status: { open: {} } | { settledWin: {} } | { settledLoss: {} };
  isVoteInitiator: boolean;
}

V4 (multi-outcome) bets replace the binary totalOiFor/totalOiAgainst and the Outcome side with an outcomes array and a numeric outcomeIndex:

ProgramBetV4
interface ProgramBetV4 {
  creator: PublicKey;
  createdAt: BN;
  updatedAt: BN;
  resolvedAt: BN;
  distributedAt: BN;
  voteInitiatedAt: BN;
  status: { draft: {} } | { pending: {} } | { resolving: {} } | { resolved: {} } | { distributed: {} };
  resolvedOutcomeIndex: number | null;  // null = refund-all
  question: string;
  expectedUserCount: number;
  minimumVoteCount: number;
  feeBps: number;
  outcomes: { label: string; totalOi: BN }[];
  poolAddress: PublicKey;
  poolBump: number;
  wagerId: BN;
  isCreatorResolver: boolean;
  votingDisabled: boolean;
  outcomesLocked: boolean;
  wagers: WagerV4[];
  votes: VoteV4[];
  settledUserCount: number;
  totalBatchesRequired: number;
}
WagerV4
interface WagerV4 {
  user: PublicKey;
  outcomeIndex: number;  // which outcome this wager backs
  amount: BN;
  updatedAt: BN;
  status: { open: {} } | { settledWin: {} } | { settledLoss: {} };
  isVoteInitiator: boolean;
}