Accounts
Reference for account fetching and data structures.
Overview
The sdk.accounts object provides methods to fetch onchain account data.
Bet Accounts
sdk.accounts.bet.single()
Fetches a single V1 bet account.
typescript
const bet = await sdk.accounts.bet.single(betAddress);
console.log("Question:", bet.question);Parameters:
| Name | Type | Description |
|---|---|---|
address | PublicKey | Bet account address |
Returns: Promise<ProgramBet>
sdk.accounts.bet.all()
Fetches all V1 bet accounts with optional filters.
typescript
const allBets = await sdk.accounts.bet.all();
console.log("Total bets:", allBets.length);
// With filters
const filteredBets = await sdk.accounts.bet.all([
{ memcmp: { offset: 8, bytes: creatorAddress.toBase58() } }
]);Returns: Promise<ProgramAccount<ProgramBet>[]>
sdk.accounts.betV2.single()
Fetches a single V2 bet account.
typescript
const bet = await sdk.accounts.betV2.single(betAddress);sdk.accounts.betV2.all()
Fetches all V2 bet accounts.
typescript
const allBetsV2 = await sdk.accounts.betV2.all();User Accounts
sdk.accounts.user.single()
Fetches a 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("Total wagered:", user.totalWageredAmount.toNumber() / 1e6);Returns: Promise<ProgramUser>
sdk.accounts.user.all()
Fetches all user accounts.
typescript
const allUsers = await sdk.accounts.user.all();Protocol Account
sdk.accounts.protocol.single()
Fetches the protocol configuration.
typescript
const protocolAddress = sdk.addresses.protocol.get();
const protocol = await sdk.accounts.protocol.single(protocolAddress);
console.log("Fee percentage:", protocol.feePercentage);
console.log("Total bets:", protocol.totalUniqueBets);Game Accounts
sdk.accounts.game.single()
Fetches a game account.
typescript
const game = await sdk.accounts.game.single(gameAddress);sdk.accounts.game.all()
Fetches all game accounts.
typescript
const allGames = await sdk.accounts.game.all();Mapper Functions
The SDK provides helper functions to convert raw account data to typed objects.
sdk.accounts.mapBetV2()
Maps a raw V2 bet account to a typed object.
typescript
const rawBet = await sdk.accounts.betV2.single(address);
const mappedBet = sdk.accounts.mapBetV2(rawBet);
console.log("Status:", mappedBet.status); // "Pending", "Resolving", etc.
console.log("Total For:", mappedBet.totalOiFor); // Number, not BNMapped Bet Structure:
typescript
interface MappedBet {
creator: string; // Base58 address
createdAt: number; // Unix timestamp
updatedAt: number;
resolvedAt: number;
distributedAt: number;
voteInitiatedAt: number;
status: string; // "Pending", "Resolving", etc.
resolvedOutcome: string; // "For", "Against", "Tied"
question: string;
expectedUserCount: number;
minimumVoteCount: number;
totalOiFor: number; // In raw units (divide by 1e6 for USDC)
totalOiAgainst: number;
poolAddress: string;
wagers: MappedWager[];
votes: MappedVote[];
poolBump: number;
wagerId: number;
isCreatorResolver: boolean;
settledUserCount: number;
totalBatchesRequired: number;
}sdk.accounts.mapProtocol()
Maps a protocol account.
typescript
const mapped = sdk.accounts.mapProtocol(rawProtocol);sdk.accounts.mapUser()
Maps a user account.
typescript
const mapped = sdk.accounts.mapUser(rawUser);Mapped User Structure:
typescript
interface MappedUser {
totalWagersCount: number;
totalWageredAmount: number; // Raw units
inWagerAmount: number;
nextWagerId: number;
nextGameId: number;
}sdk.accounts.mapGame()
Maps a game account.
typescript
const mapped = sdk.accounts.mapGame(rawGame);Raw Account Structures
ProgramBetV2
typescript
interface ProgramBetV2 {
creator: PublicKey;
createdAt: BN;
updatedAt: BN;
resolvedAt: BN;
distributedAt: BN;
voteInitiatedAt: BN;
status: { pending: {} } | { resolving: {} } | ...;
resolvedOutcome: { for: {} } | { against: {} } | ...;
question: string;
expectedUserCount: number;
minimumVoteCount: number;
totalOiFor: BN;
totalOiAgainst: BN;
poolAddress: PublicKey;
wagers: Wager[];
votes: Vote[];
poolBump: number;
wagerId: BN;
isCreatorResolver: boolean;
settledUserCount: number;
totalBatchesRequired: number;
}Wager
typescript
interface Wager {
user: PublicKey;
amount: BN;
outcome: { for: {} } | { against: {} };
updatedAt: BN;
status: { open: {} } | { settledWin: {} } | { settledLoss: {} };
isVoteInitiator: boolean;
}Vote
typescript
interface Vote {
user: PublicKey;
outcome: { for: {} } | { against: {} } | { tied: {} };
createdAt: BN;
}