Contract cb3fc8b548bbf3981b0892642f58d9c0f3799e3babab9ff76b6039f14056c5ab

← Back to Index 📥 Download WASM

Meta

rssdkver 23.1.0#7456be9d91fe1f4cb070fc2732bac78244ce6c3f
rsver 1.91.0

Instances

  • CAK6Z6KFMB3V2ENEJ7THVKXUYQ5EG7EL2TM5UQ2FLDXI37FS6DRIMIZH

Interface

Pause the contract (emergency stop)

When paused, all player-facing functions are disabled except admin functions. This is an emergency mechanism to protect player funds in case of discovered vulnerabilities.

Errors

  • NotAdmin - If caller is not the admin
fn pause(env: soroban_sdk::Env) -> Result<(), soroban_sdk::Error>

Check if a contract is an approved game

fn is_game(env: soroban_sdk::Env, id: soroban_sdk::Address) -> bool

Unpause the contract

Restores normal contract functionality after emergency pause.

Errors

  • NotAdmin - If caller is not the admin
fn unpause(env: soroban_sdk::Env) -> Result<(), soroban_sdk::Error>

Update the contract WASM hash (upgrade contract)

Errors

  • NotAdmin - If caller is not the admin
fn upgrade(
    env: soroban_sdk::Env,
    new_wasm_hash: soroban_sdk::BytesN<32>,
) -> Result<(), soroban_sdk::Error>

Add a game contract to the approved list

Errors

  • NotAdmin - If caller is not the admin
fn add_game(
    env: soroban_sdk::Env,
    id: soroban_sdk::Address,
) -> Result<(), soroban_sdk::Error>

End a game session with outcome verification

Requires game contract authorization. Both players' FP wagers are spent/burned. Only the winner's wager contributes to their faction standings. ZK proof verification handled client-side for MVP.

Errors

  • SessionNotFound - If session doesn't exist
  • InvalidSessionState - If session is not Pending
  • InvalidGameOutcome - If outcome data doesn't match session
  • ProofVerificationFailed - If ZK proof is invalid
fn end_game(
    env: soroban_sdk::Env,
    game_id: soroban_sdk::Address,
    session_id: u32,
    proof: soroban_sdk::Bytes,
    outcome: GameOutcome,
) -> Result<(), soroban_sdk::Error>

Get the admin address

fn get_admin(env: soroban_sdk::Env) -> soroban_sdk::Address

Get epoch information

Returns current epoch if no number specified, otherwise the specified epoch.

Errors

  • EpochNotFinalized - If requested epoch doesn't exist
fn get_epoch(
    env: soroban_sdk::Env,
    epoch: Option,
) -> Result

Check if contract is paused

fn is_paused(env: soroban_sdk::Env) -> bool

Update the admin address

Errors

  • NotAdmin - If caller is not the current admin
fn set_admin(
    env: soroban_sdk::Env,
    new_admin: soroban_sdk::Address,
) -> Result<(), soroban_sdk::Error>

Get the current configuration

fn get_config(env: soroban_sdk::Env) -> Config

Get player information

Returns complete persistent player data including selected faction, total deposited, and deposit timestamp.

Errors

  • PlayerNotFound - If player has never interacted with the contract
fn get_player(
    env: soroban_sdk::Env,
    player: soroban_sdk::Address,
) -> Result

Start a new game session

Locks factions and fp for both players. If this is a player's first game in the epoch, initializes their fp and locks their faction.

Errors

  • GameNotWhitelisted - If game_id is not approved
  • SessionAlreadyExists - If session_id already exists
  • InvalidAmount - If wagers are <= 0
  • InsufficientFactionPoints - If players don't have enough fp
  • ContractPaused - If contract is in emergency pause mode
fn start_game(
    env: soroban_sdk::Env,
    game_id: soroban_sdk::Address,
    session_id: u32,
    player1: soroban_sdk::Address,
    player2: soroban_sdk::Address,
    player1_wager: i128,
    player2_wager: i128,
) -> Result<(), soroban_sdk::Error>

Cycle to the next epoch

Finalizes current epoch (determines winner, withdraws BLND, swaps to USDC, sets reward pool) and opens next epoch.

Returns

The new epoch number

Errors

  • EpochNotReady - If not enough time has passed
  • EpochAlreadyFinalized - If current epoch is already finalized
  • FeeVaultError - If fee-vault operations fail
  • SwapError - If BLND → USDC swap fails
fn cycle_epoch(env: soroban_sdk::Env) -> Result

Remove a game contract from the approved list

Errors

  • NotAdmin - If caller is not the admin
fn remove_game(
    env: soroban_sdk::Env,
    id: soroban_sdk::Address,
) -> Result<(), soroban_sdk::Error>

Initialize the contract

Sets up the admin, external contract addresses, and creates the first epoch.

Arguments

  • admin - Admin address (can modify config and upgrade contract)
  • fee_vault - fee-vault-v2 contract address
  • soroswap_router - Soroswap router contract address
  • blnd_token - BLND token address
  • usdc_token - USDC token address
  • epoch_duration - Duration of each epoch in seconds (default: 345,600 = 4 days)
  • reserve_token_ids - Reserve token IDs for claiming BLND emissions (e.g., vec![&env, 1] for reserve 0 b-tokens)

Errors

  • AlreadyInitialized - If contract has already been initialized
fn __constructor(
    env: soroban_sdk::Env,
    admin: soroban_sdk::Address,
    fee_vault: soroban_sdk::Address,
    soroswap_router: soroban_sdk::Address,
    blnd_token: soroban_sdk::Address,
    usdc_token: soroban_sdk::Address,
    epoch_duration: u64,
    reserve_token_ids: soroban_sdk::Vec,
) -> Result<(), soroban_sdk::Error>

Update global configuration

Allows admin to update specific configuration parameters. Only updates parameters that are provided (non-None).

Arguments

  • new_fee_vault - New fee-vault-v2 contract address (optional)
  • new_soroswap_router - New Soroswap router contract address (optional)
  • new_blnd_token - New BLND token address (optional)
  • new_usdc_token - New USDC token address (optional)
  • new_epoch_duration - New epoch duration in seconds (optional)
  • new_reserve_token_ids - New reserve token IDs for claiming BLND emissions (optional)

Errors

  • NotAdmin - If caller is not the admin
fn update_config(
    env: soroban_sdk::Env,
    new_fee_vault: Option,
    new_soroswap_router: Option,
    new_blnd_token: Option,
    new_usdc_token: Option,
    new_epoch_duration: Option,
    new_reserve_token_ids: Option>,
) -> Result<(), soroban_sdk::Error>

Migration: Update Player struct from old formats to current format

This migration fixes deserialization errors caused by Player struct schema changes:

  • V0 (pre-Nov 10): Had total_deposited field instead of last_epoch_balance
  • V1 (Nov 10-12): Had deposit_timestamp field instead of time_multiplier_start
  • V2 (current): Uses time_multiplier_start and last_epoch_balance

The migration reads old formats, deletes them, and writes back the current format.

Usage

Call this for each player address that needs migration. This is typically called:

  • By players themselves when they encounter deserialization errors
  • By admin for known active players

Arguments

  • player - Player address to migrate

Returns

  • true if migration was performed (player had V0 or V1 data)
  • false if player data doesn't exist or is already in V2 format
fn migrate_player(env: soroban_sdk::Env, player: soroban_sdk::Address) -> bool

Select a faction for the player

Sets the player's persistent faction preference. Can be changed at ANY time. If you haven't played a game this epoch, the new faction applies immediately. If you've already played this epoch, the current epoch stays locked to your old faction, and the new selection applies starting next epoch.

Arguments

  • faction - Faction ID (0=WholeNoodle, 1=PointyStick, 2=SpecialRock)

Errors

  • InvalidFaction - If faction ID is not 0, 1, or 2
fn select_faction(
    env: soroban_sdk::Env,
    player: soroban_sdk::Address,
    faction: u32,
) -> Result<(), soroban_sdk::Error>

Get player's epoch-specific information for the current epoch

Returns complete epoch-specific data including locked faction, available/locked FP, total FP contributed, and balance snapshot.

NEW BEHAVIOR: If player hasn't played any games this epoch yet, calculates what their FP WOULD be based on current vault balance without writing to storage. This allows UIs to display FP before the player's first game.

Errors

  • FactionNotSelected - If player hasn't selected a faction yet
fn get_epoch_player(
    env: soroban_sdk::Env,
    player: soroban_sdk::Address,
) -> Result

Claim epoch reward for a player for a specific epoch

Players who contributed FP to the winning faction can claim their share of the epoch's reward pool (USDC converted from BLND yield).

Note: To check claimable amounts or claim status before calling, use transaction simulation. This is the idiomatic Soroban pattern.

Returns

Amount of USDC claimed

Errors

  • EpochNotFinalized - If epoch doesn't exist or isn't finalized
  • RewardAlreadyClaimed - If player already claimed for this epoch
  • NotWinningFaction - If player wasn't in the winning faction
  • NoRewardsAvailable - If player has no rewards to claim
  • ContractPaused - If contract is in emergency pause mode
fn claim_epoch_reward(
    env: soroban_sdk::Env,
    player: soroban_sdk::Address,
    epoch: u32,
) -> Result

Migration: Update EpochPlayer storage key from old format to new format

This migration handles the storage key rename from DataKey::EpochUser to DataKey::EpochPlayer. The EpochPlayer struct itself hasn't changed, only the storage key name changed as part of the user→player terminology standardization.

Usage

Call this for each (epoch, player) pair that might have old data. Typically called:

  • By players when they encounter issues claiming rewards or checking epoch data
  • By admin for active epochs with known players
  • Can be called proactively for the current epoch

Arguments

  • epoch - Epoch number to migrate
  • player - Player address to migrate

Returns

  • true if migration was performed (found data in old DataKey::EpochUser)
  • false if data doesn't exist or is already migrated to DataKey::EpochPlayer
fn migrate_epoch_player(
    env: soroban_sdk::Env,
    epoch: u32,
    player: soroban_sdk::Address,
) -> bool

Imports

WebAssembly Text (WAT) ▶