Buy outcome tokens.
user - User buying tokens (must authorize)outcome - 0 for YES, 1 for NOamount - Amount of tokens to buy (scaled by 10^7)max_cost - Maximum collateral willing to pay (slippage protection).
The transaction reverts if calculated cost exceeds this value,
protecting users from price movements between quote and execution.Actual cost paid in collateral
fn buy(
env: soroban_sdk::Env,
user: soroban_sdk::Address,
outcome: u32,
amount: i128,
max_cost: i128,
) -> Result
Sell outcome tokens.
user - User selling tokens (must authorize)outcome - 0 for YES, 1 for NOamount - Amount of tokens to sell (scaled by 10^7)min_return - Minimum collateral to receive (slippage protection)Actual collateral received
fn sell(
env: soroban_sdk::Env,
user: soroban_sdk::Address,
outcome: u32,
amount: i128,
min_return: i128,
) -> Result
Claim winnings after market resolution. Each winning token is redeemable for 1 unit of collateral (1:1 redemption), minus a 2% fee that stays in the pool (recoverable by oracle via withdraw_remaining). Note: Losing tokens have zero value and are not claimed.
user - User claiming (must authorize)Amount of collateral claimed (after fee deduction)
fn claim(
env: soroban_sdk::Env,
user: soroban_sdk::Address,
) -> Result
Resolve the market (oracle only).
oracle - Must match the oracle set at initializationwinning_outcome - 0 for YES, 1 for NOfn resolve(
env: soroban_sdk::Env,
oracle: soroban_sdk::Address,
winning_outcome: u32,
) -> Result<(), MarketError>
Get the current price of an outcome.
Price scaled by 10^7 (5_000_000 = 0.5 = 50%)
fn get_price(env: soroban_sdk::Env, outcome: u32) -> Result
Get a quote for buying tokens.
(cost, price_after) both scaled by 10^7
fn get_quote(
env: soroban_sdk::Env,
outcome: u32,
amount: i128,
) -> Result<(i128, i128), MarketError>
Get market state.
(yes_sold, no_sold, collateral_pool, is_resolved)
fn get_state(env: soroban_sdk::Env) -> Result<(i128, i128, i128, bool), MarketError>
Get the oracle address.
fn get_oracle(env: soroban_sdk::Env) -> Result
Initialize the market with oracle, collateral token, liquidity parameter, and metadata.
Can be called directly for manual deployment, or via constructor for factory deployment.
oracle - Address that can resolve the marketcollateral_token - Token contract for collateral (e.g., EURMTL SAC)liquidity_param - LMSR b parameter (scaled by 10^7)metadata_hash - IPFS hash for market metadatainitial_funding - Initial collateral to fund the market (scaled by 10^7)fn initialize(
env: soroban_sdk::Env,
oracle: soroban_sdk::Address,
collateral_token: soroban_sdk::Address,
liquidity_param: i128,
metadata_hash: soroban_sdk::String,
initial_funding: i128,
) -> Result<(), MarketError>
Get user's token balance for an outcome.
fn get_balance(env: soroban_sdk::Env, user: soroban_sdk::Address, outcome: u32) -> i128
Constructor: Called automatically when deployed via factory's deploy_v2.
Delegates to initialize() for the actual setup logic.
fn __constructor(
env: soroban_sdk::Env,
oracle: soroban_sdk::Address,
collateral_token: soroban_sdk::Address,
liquidity_param: i128,
metadata_hash: soroban_sdk::String,
initial_funding: i128,
)
Get a quote for selling tokens.
(return_amount, price_after) both scaled by 10^7
fn get_sell_quote(
env: soroban_sdk::Env,
outcome: u32,
amount: i128,
) -> Result<(i128, i128), MarketError>
Get the metadata hash (IPFS CID for market metadata JSON).
fn get_metadata_hash(env: soroban_sdk::Env) -> Result
Withdraw remaining pool after market resolution (oracle only).
Withdraws only the excess funds (losers' bets + fees) while reserving enough collateral for unclaimed winning tokens. This prevents the oracle from withdrawing funds that winners haven't claimed yet.
oracle - Must match the oracle set at initializationAmount of collateral withdrawn
fn withdraw_remaining(
env: soroban_sdk::Env,
oracle: soroban_sdk::Address,
) -> Result
Get the liquidity parameter.
fn get_liquidity_param(env: soroban_sdk::Env) -> Result
Get the winning outcome (only valid after resolution).
fn get_winning_outcome(env: soroban_sdk::Env) -> Result
Get the collateral token address.
fn get_collateral_token(
env: soroban_sdk::Env,
) -> Result