Smart Contracts API

Smart Contracts API Reference

AnchorShield does not rely on a centralized backend for core operations. The Smart Contract is the API. Integrators can interact with the protocol directly via Soroban RPC.

All contract addresses and ABIs can be found in the Deployments section.

1. Market Factory

The Factory (market-factory) is the central registry for all deployed AnchorShield markets.

get_market

Fetches the configuration of a specific market by its ID.

Parameters

NameTypeDescription
envEnvThe Soroban environment.
market_idu32The integer ID of the market.

Returns: MarketConfig struct

pub struct MarketConfig {
    pub market_id: u32,
    pub label: String,
    pub collateral_token: Address,
    pub covered_asset: String, // e.g., "USDC"
    pub oracle_contract: Address,
    pub depeg_threshold: i128,
    pub breach_duration_seconds: u64,
    pub expiry_timestamp: u64,
    pub anchor_id: Option<Address>,
}

2. Insurance Market

The Insurance Market handles the minting of YES/NO tokens, order book limit orders, and settlement execution. Each market has its own isolated contract address.

mint_complete_set

Locks USDC collateral to mint an equivalent amount of YES and NO tokens. This is the entry point for both hedgers and underwriters.

Parameters

NameTypeDescription
underwriterAddressThe wallet authorizing the transaction.
amounti128The amount of USDC to lock (in stroops, e.g., 10000000 = 1 USDC).
⚠️

Authorization Required: The caller must approve the Insurance Market to transfer amount from their USDC balance.

place_order

Places a limit order on the on-chain order book to trade YES or NO tokens.

Parameters

NameTypeDescription
ownerAddressThe wallet placing the order.
is_buybooltrue if bidding for tokens, false if asking (selling).
price_bpsi64The price in basis points (e.g., 9800 = $0.98).
amounti128The quantity of tokens to trade.

try_settle

Permissionless endpoint that checks the Reflector Oracle. If a sustained depeg has occurred (exceeding the breach_duration_seconds), it permanently closes the market and allows YES tokens to be claimed.

pub fn try_settle(env: Env)