Contract dc2a7fbf6affd4b0c98c7550fa260b48efc39cc87623ab553d801a0c8e6f56aa

← Back to Index 📥 Download WASM

Meta

rssdkver 22.0.9#3890521426d71bb4d892b21f5a283a1e836cfa38
rsver 1.93.0

Instances

  • CCIIONPML6VQQEJO6UMPT7T7ZX5O5JH4UWPTP3W3OBE3OADX6F2HQA7Z

Interface

Buy outcome tokens.

Arguments

  • user - User buying tokens (must authorize)
  • outcome - 0 for YES, 1 for NO
  • amount - 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.

Returns

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.

Arguments

  • user - User selling tokens (must authorize)
  • outcome - 0 for YES, 1 for NO
  • amount - Amount of tokens to sell (scaled by 10^7)
  • min_return - Minimum collateral to receive (slippage protection)

Returns

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.

Arguments

  • user - User claiming (must authorize)

Returns

Amount of collateral claimed (after fee deduction)

fn claim(
    env: soroban_sdk::Env,
    user: soroban_sdk::Address,
) -> Result

Resolve the market (oracle only).

Arguments

  • oracle - Must match the oracle set at initialization
  • winning_outcome - 0 for YES, 1 for NO
fn resolve(
    env: soroban_sdk::Env,
    oracle: soroban_sdk::Address,
    winning_outcome: u32,
) -> Result<(), MarketError>

Get the current price of an outcome.

Returns

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.

Returns

(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.

Returns

(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.

Arguments

  • oracle - Address that can resolve the market
  • collateral_token - Token contract for collateral (e.g., EURMTL SAC)
  • liquidity_param - LMSR b parameter (scaled by 10^7)
  • metadata_hash - IPFS hash for market metadata
  • initial_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.

Returns

(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.

Arguments

  • oracle - Must match the oracle set at initialization

Returns

Amount 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

Imports

WebAssembly Text (WAT) ▶