Contract 798286f090725b03aefe51f90766c858a2e87f3aeca72d218539d8ec6a3371b3

← Back to Index 📥 Download WASM

Meta

rssdkver 22.0.10#9a1b75b509a5053b676b09fdbd224fe8c5f2fcd5
rsver 1.94.0

Instances

  • CC2H4AFD323RVEVOHTABTFBOOGRYLEIOWDNHHHVH54WI4IAUMU36T2KE
  • CCPORWQXWMK3CTCG2QP2HJB25MGHFDXQBRE5X37ZOA7ONUQAVNUSQIKY

Interface

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 spend
  • min_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 administrator
  • token: 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 ledgers
  • initial_liquidity: Collateral amount to seed each side of the market
fn 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.

  • If PASS won: PASS stakers split all staked collateral proportionally
  • If FAIL won: FAIL stakers split all staked collateral proportionally
  • If Expired: everyone gets their own stake back
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:

  • If pass_twap / fail_twap > threshold → PASSED (status 1)
  • Otherwise → FAILED (status 2)
  • If no snapshots → EXPIRED (status 3)
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.

  • If PASS won: PASS position holders split the entire market collateral pool proportionally based on their PASS position tokens
  • If FAIL won: FAIL position holders split the entire market collateral pool proportionally based on their FAIL position tokens
  • If Expired: everyone gets back their total_spent collateral
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>

Imports

WebAssembly Text (WAT) ▶