This document provides a detailed reference for all instructions and account structures of the Signals Breakout Contracts Solana program.
97i8BgDJG6yZggN2Di5UnERs6X5PqYqnkSvkMdvw1d5J
An account that stores overall program settings and state.
pub struct ProgramState {
pub owner: Pubkey, // Program owner (administrator)
pub market_count: u64, // Market ID sequence (auto-incrementing)
pub last_closed_market: Option<u64>, // Most recently closed market ID
}An account that stores the state and configuration of individual prediction markets.
pub struct Market {
pub active: bool, // Active status
pub closed: bool, // Closed status
pub tick_spacing: u32, // Tick spacing
pub min_tick: i64, // Minimum tick
pub max_tick: i64, // Maximum tick
pub t_total: u64, // Total sum of tokens across all bins (T)
pub collateral_balance: u64, // Collateral balance
pub winning_bin: Option<u16>, // Winning bin index
pub open_ts: i64, // Time when market was opened
pub close_ts: i64, // Time when market is scheduled to close
pub bins: Vec<u64>, // Token quantities by bin
}An account that tracks a user's position in a specific market.
pub struct UserMarketPosition {
pub owner: Pubkey, // Position owner
pub market_id: u64, // Market ID
pub bins: Vec<BinBal>, // Balances by bin
}
pub struct BinBal {
pub index: u16, // Bin index
pub amount: u64, // Token quantity
}Initializes and sets up the program for first use.
Parameters: None
Accounts:
initializer: User performing the initialization (signature required)program_state: Program state account (PDA)system_program: System programrent: Rent Sysvar
Example:
await program.methods
.initializeProgram()
.accounts({
initializer: wallet.publicKey,
})
.signers([wallet])
.rpc();Creates a new prediction market.
Parameters:
tick_spacing: u32 - Tick spacingmin_tick: i64 - Minimum tick valuemax_tick: i64 - Maximum tick valueclose_ts: i64 - Scheduled market closing time (Unix timestamp)
Accounts:
owner: Market creator (program owner)program_state: Program state accountmarket: New market account to createcollateral_mint: Collateral token Mintvault: Market's collateral token storage accountvault_authority: Vault authority PDAtoken_program: Token programassociated_token_program: Associated token programsystem_program: System programrent: Rent Sysvar
Example:
await program.methods
.createMarket(
20, // tick_spacing
new BN(-240), // min_tick
new BN(960), // max_tick
new BN(closeTime) // close_ts
)
.accounts({
owner: wallet.publicKey,
collateralMint: COLLATERAL_MINT,
})
.signers([wallet])
.rpc();Purchases tokens in multiple bins of a specific market.
Parameters:
market_id: u64 - Market IDbin_indices: Vec - Array of bin indices to purchaseamounts: Vec - Array of token quantities to purchase for each binmax_collateral: u64 - Maximum collateral willing to pay
Accounts:
user: Token purchaser (signature required)market: Market accountuser_position: User's market position accountuser_token_account: User's collateral token accountvault: Market's collateral token accounttoken_program: Token programsystem_program: System programrent: Rent Sysvar
Example:
await program.methods
.buyTokens(marketId, [0, 3], [100000000, 50000000], 200000000)
.accounts({
user: wallet.publicKey,
userTokenAccount: userTokenAccount,
vault: marketVault,
})
.signers([wallet])
.rpc();Closes a market and sets the winning bin.
Parameters:
market_id: u64 - Market IDwinning_bin: u16 - Winning bin index
Accounts:
authority: Market administrator (signature required)market: Market accountprogram_state: Program state account
Example:
await program.methods
.closeMarket(marketId, winningBin)
.accounts({
authority: wallet.publicKey,
})
.signers([wallet])
.rpc();Allows users who bet on the winning bin to claim their rewards.
Parameters: None
Accounts:
user: Reward claimer (signature required)market: Market accountuser_position: User's market position accountuser_token_account: User's collateral token accountvault: Market's collateral token accountvault_authority: Vault authority PDAtoken_program: Token program
Example:
await program.methods
.claimReward()
.accounts({
user: wallet.publicKey,
userTokenAccount: userTokenAccount,
vault: marketVault,
vaultAuthority: vaultAuthPDA,
})
.signers([wallet])
.rpc();Changes a market's active status.
Parameters:
market_id: u64 - Market IDactive: bool - Activation status (true: activate, false: deactivate)
Accounts:
owner: Market administrator (signature required)market: Market account
Example:
await program.methods
.activateMarket(marketId, true)
.accounts({
owner: wallet.publicKey,
})
.signers([wallet])
.rpc();Withdraws remaining collateral from a closed market.
Parameters:
market_id: u64 - Market ID
Accounts:
owner: Market administrator (signature required)market: Market accountvault: Market's collateral token accountvault_authority: Vault authority PDAowner_token_account: Administrator's collateral token accounttoken_program: Token program
Example:
await program.methods
.withdrawCollateral(marketId)
.accounts({
owner: wallet.publicKey,
ownerTokenAccount: ownerTokenAccount,
vault: marketVault,
})
.signers([wallet])
.rpc();Transfers part or all of a market position to another user.
Parameters:
market_id: u64 - Market IDbin_indices: Vec - Array of bin indices to transferamounts: Vec - Array of token quantities to transfer for each bin
Accounts:
user: Position owner (signature required)recipient: Recipient addressmarket: Market accountuser_position: User's market position accountrecipient_position: Recipient's market position accountsystem_program: System programrent: Rent Sysvar
Example:
await program.methods
.transferPosition(marketId, binIndices, amounts)
.accounts({
fromUser: wallet.publicKey,
toUser: recipientPubkey,
})
.signers([wallet])
.rpc();Calculates the cost to purchase tokens in a specific bin.
Parameters:
market_id: u64 - Market IDindex: u16 - Bin indexamount: u64 - Token quantity to purchase
Accounts:
market: Market account
Return Value: u64 - Purchase cost
Example:
const cost = await program.methods
.calculateBinCost(marketId, binIndex, amount)
.accounts({})
.view();Calculates the token quantity that can be purchased with a specific cost.
Parameters:
market_id: u64 - Market IDindex: u16 - Bin indexcost: u64 - Cost to pay
Accounts:
market: Market account
Return Value: u64 - Purchasable token quantity
Example:
const tokens = await program.methods
.calculateXForBin(marketId, binIndex, cost)
.accounts({})
.view();Calculates the collateral amount that can be obtained by selling tokens.
Parameters:
market_id: u64 - Market IDindex: u16 - Bin indexamount: u64 - Token quantity to sell
Accounts:
market: Market account
Return Value: u64 - Sale proceeds
Example:
const sellCost = await program.methods
.calculateBinSellCost(marketId, binIndex, amount)
.accounts({})
.view();The mathematical functions are implemented in a separate math-core crate to allow reuse across different contexts. This crate provides functions for both on-chain and WASM (client-side) use.
The WASM build is published as an NPM package named range-bet-math-core. For detailed documentation and usage examples of the WASM package, see the WASM Package README.
Calculates the cost to purchase tokens in a single bin.
pub fn calculate_bin_buy_cost(x: u64, q: u64, t: u64) -> Result<u64>Parameters:
x: Amount of tokens to purchaseq: Current token quantity in the bint: Total token quantity in the market
Returns:
Result<u64>: Cost of the purchase or an error
Calculates the revenue from selling tokens in a single bin.
pub fn calculate_bin_sell_cost(x: u64, q: u64, t: u64) -> Result<u64>Parameters:
x: Amount of tokens to sellq: Current token quantity in the bint: Total token quantity in the market
Returns:
Result<u64>: Revenue from the sale or an error
Calculates the total cost to purchase tokens across multiple bins.
pub fn calculate_multi_bins_buy_cost(x: u64, qs: &[u64], t: u64) -> Result<u64>Parameters:
x: Amount of tokens to purchase for each binqs: Array of current token quantities in each bint: Total token quantity in the market
Returns:
Result<u64>: Total cost of the purchase or an error
Calculates the revenue from selling tokens across multiple bins.
pub fn calculate_multi_bins_sell_cost(x: u64, qs: &[u64], t: u64) -> Result<u64>Parameters:
x: Amount of tokens to sell for each binqs: Array of current token quantities in each bint: Total token quantity in the market
Returns:
Result<u64>: Total revenue from the sale or an error
Calculates the maximum token quantity that can be purchased with a given budget across multiple bins.
pub fn calculate_x_for_multi_bins(budget: u64, qs: &[u64], t: u64) -> Result<u64>Parameters:
budget: Maximum cost willing to payqs: Array of current token quantities in each bint: Total token quantity in the market
Returns:
Result<u64>: Maximum purchasable token quantity or an error
Event emitted when a market is created.
pub struct MarketCreated {
pub market_id: u64,
pub tick_spacing: u32,
pub min_tick: i64,
pub max_tick: i64,
}Event emitted when tokens are purchased.
pub struct TokensBought {
pub market_id: u64,
pub buyer: Pubkey,
pub total_cost: u64,
}Event emitted when a market is closed.
pub struct MarketClosed {
pub market_id: u64,
pub winning_bin: u16,
}Event emitted when rewards are claimed.
pub struct RewardClaimed {
pub market_id: u64,
pub claimer: Pubkey,
pub amount: u64,
}Event emitted when collateral is withdrawn.
pub struct CollateralOut {
pub to: Pubkey,
pub amount: u64,
}DDFXv1hETR8pQSpNbzCxTX7jm1Hr57V4oihDGosXQfgC
A PDA derived from the seed "collateral_faucet" that serves as the mint authority for the collateral token.
// This is a PDA without data structure - UncheckedAccount is used in the account validationInitializes the faucet program.
Parameters: None
Accounts:
- No specific accounts required
Example:
await faucetProgram.methods.initialize().rpc();Mints collateral tokens to a specified receiver.
Parameters:
amount: u64 - The amount of tokens to mint (in raw units, accounting for decimals)
Accounts:
mint: Collateral token mint account (must have Faucet PDA as authority)faucet_pda: The PDA that acts as mint authorityreceiver: Token account to receive the minted tokensuser: The transaction signer (pays fees)token_program: Token programsystem_program: System programassociated_token_program: Associated token programrent: Rent Sysvar
Example:
await faucetProgram.methods
.mintCollateralTokens(new BN(1_000_000_000))
.accounts({
mint: COLLATERAL_MINT,
receiver: userTokenAccount,
user: wallet.publicKey,
})
.signers([wallet])
.rpc();For detailed information about the Collateral Token Faucet, see the Collateral Token Faucet Documentation.