Stake tokens on a side of a proposal.
This is the traditional "vote with tokens" mechanism that runs alongside the prediction market. Stakers commit to a side and share in the collateral pool if their side wins.
fn stake(
env: soroban_sdk::Env,
user: soroban_sdk::Address,
proposal_id: u32,
side: u32,
amount: i128,
) -> Result<(), ContractError>
Buy FAIL position tokens using collateral.
Same mechanics as buy_pass but for the FAIL side.
fn buy_fail(
env: soroban_sdk::Env,
user: soroban_sdk::Address,
proposal_id: u32,
collateral_in: i128,
min_position_out: i128,
) -> Result
Buy PASS position tokens using collateral.
The constant-product formula ensures price increases as more people buy PASS (supply decreases in the PASS reserve).
collateral_in: Amount of project tokens to spendmin_position_out: Minimum PASS tokens to receive (slippage protection)Returns the number of PASS position tokens received.
fn buy_pass(
env: soroban_sdk::Env,
user: soroban_sdk::Address,
proposal_id: u32,
collateral_in: i128,
min_position_out: i128,
) -> Result
Get current prediction market prices for a proposal.
Returns (pass_price, fail_price) scaled by PRICE_SCALE (1e7). Prices represent the cost of 1 unit of position token in collateral.
fn get_prices(
env: soroban_sdk::Env,
proposal_id: u32,
) -> Result<(i128, i128), ContractError>
Initialize the governance contract.
admin: Contract administratortoken: Project token address (used as collateral)twap_threshold: PASS/FAIL price ratio threshold (scaled by 10000).
e.g. 10300 means PASS must be 3% higher than FAIL to pass.observation_window: Voting window in ledgersinitial_liquidity: Collateral amount to seed each side of the marketfn initialize(
env: soroban_sdk::Env,
admin: soroban_sdk::Address,
token: soroban_sdk::Address,
twap_threshold: i128,
observation_window: u32,
initial_liquidity: i128,
) -> Result<(), ContractError>
fn get_proposal(
env: soroban_sdk::Env,
proposal_id: u32,
) -> Result
fn get_snapshot(
env: soroban_sdk::Env,
proposal_id: u32,
index: u32,
) -> Result
Claim winnings after a proposal is resolved.
fn claim_winnings(
env: soroban_sdk::Env,
user: soroban_sdk::Address,
proposal_id: u32,
) -> Result<(), ContractError>
fn get_user_stake(
env: soroban_sdk::Env,
proposal_id: u32,
user: soroban_sdk::Address,
) -> Result
Create a new proposal and seed its prediction market.
The creator must have approved at least 2 * initial_liquidity tokens
to this contract. These tokens seed both sides of the market equally,
starting the PASS and FAIL prices at 0.50 each (50/50 odds).
fn create_proposal(
env: soroban_sdk::Env,
creator: soroban_sdk::Address,
description: soroban_sdk::String,
) -> Result
Get the raw market reserves for a proposal.
Returns (pass_reserve, fail_reserve, k).
fn get_market_state(
env: soroban_sdk::Env,
proposal_id: u32,
) -> Result<(i128, i128, i128), ContractError>
Resolve a proposal after the observation window closes.
Uses TWAP of internal market prices to determine outcome:
fn resolve_proposal(
env: soroban_sdk::Env,
proposal_id: u32,
) -> Result<(), ContractError>
Get total collateral and position tracking for a proposal's market.
Returns (market_collateral, total_pass_positions, total_fail_positions).
fn get_market_totals(
env: soroban_sdk::Env,
proposal_id: u32,
) -> Result<(i128, i128, i128), ContractError>
Get a user's market position for a proposal.
fn get_user_position(
env: soroban_sdk::Env,
proposal_id: u32,
user: soroban_sdk::Address,
) -> Result
fn get_proposal_count(env: soroban_sdk::Env) -> u32
fn get_snapshot_count(env: soroban_sdk::Env, proposal_id: u32) -> u32
Claim winnings from prediction market positions after resolution.
fn claim_market_winnings(
env: soroban_sdk::Env,
user: soroban_sdk::Address,
proposal_id: u32,
) -> Result
Record a price snapshot from the internal prediction market.
Permissionless — anyone can call this to record the current market prices. Snapshots are used for TWAP calculation during resolution. Minimum interval: 720 ledgers (~1 hour).
fn record_price_snapshot(
env: soroban_sdk::Env,
proposal_id: u32,
) -> Result<(), ContractError>