Contract 4b0d1e4d709caa240ff7329892e9e02e6ab32bb39d2ad29ef19710f292133c95

← Back to Index 📥 Download WASM

Meta

rssdkver 22.0.11#34f7f53ae31e0fd02aab436a9872e79fa671ca02
rsver 1.94.0

Instances

  • CDC2QIOCUFM35M64HT4HLP2GN3USNERPEGUKOYOSMDPR7XUAUGFA7FKY

Interface

Get a single feed's configuration.

fn get_feed(env: soroban_sdk::Env, token: soroban_sdk::Address) -> Option

Get TWAP price from Reflector.

HIGH-02 fix: uses the real lastprice() timestamp from the oracle instead of forging env.ledger().timestamp(), and applies the same staleness validation as get_price / get_price_pair to ensure the TWAP is not stale.

fn get_twap(
    env: soroban_sdk::Env,
    token: soroban_sdk::Address,
    records: u32,
) -> Result
fn get_price(
    env: soroban_sdk::Env,
    token: soroban_sdk::Address,
) -> Result

Extend the contract's TTL. Anyone can call this.

fn extend_ttl(env: soroban_sdk::Env)

Get the oracle address.

fn get_oracle(env: soroban_sdk::Env) -> Result

Initialize the contract. Can only be called once.

fn initialize(
    env: soroban_sdk::Env,
    admin: soroban_sdk::Address,
    oracle: soroban_sdk::Address,
    max_staleness: u64,
) -> Result<(), OracleError>

Set the oracle (Reflector) address. Admin only.

fn set_oracle(
    env: soroban_sdk::Env,
    oracle: soroban_sdk::Address,
) -> Result<(), OracleError>

Remove a feed. Swaps with the last index entry to keep the index compact.

fn remove_feed(
    env: soroban_sdk::Env,
    token: soroban_sdk::Address,
) -> Result<(), OracleError>

Update an existing feed's asset mapping.

fn update_feed(
    env: soroban_sdk::Env,
    token: soroban_sdk::Address,
    asset: Asset,
) -> Result<(), OracleError>

Accept a pending admin proposal (step 2 of two-step transfer).

Must be called by the pending_admin address. Overwrites the current admin with pending_admin and clears the pending slot.

fn accept_admin(env: soroban_sdk::Env) -> Result<(), OracleError>

Get decimals from the oracle.

fn get_decimals(env: soroban_sdk::Env) -> Result

Get all feeds (returns Vec of (token, FeedConfig) pairs).

fn get_all_feeds(
    env: soroban_sdk::Env,
) -> soroban_sdk::Vec<(soroban_sdk::Address, FeedConfig)>

Propose a new admin (step 1 of two-step transfer). Admin only. (MEDIUM-01)

Writes the pend_admin storage key without overwriting the current admin. The new admin must call accept_admin() to complete the transfer. This prevents permanent lock-out from a typo or misrouted address.

fn propose_admin(
    env: soroban_sdk::Env,
    new_admin: soroban_sdk::Address,
) -> Result<(), OracleError>

Register a new price feed mapping: token address -> Reflector asset.

fn register_feed(
    env: soroban_sdk::Env,
    token: soroban_sdk::Address,
    asset: Asset,
) -> Result<(), OracleError>

Get the cross-rate price of token_a denominated in token_b (2-hop). Formula: pair_price = (price_a * 10^decimals) / price_b Uses checked arithmetic to prevent overflow/division-by-zero.

fn get_price_pair(
    env: soroban_sdk::Env,
    token_a: soroban_sdk::Address,
    token_b: soroban_sdk::Address,
) -> Result

Set the global max staleness threshold (seconds). Admin only.

fn set_max_staleness(
    env: soroban_sdk::Env,
    max_staleness: u64,
) -> Result<(), OracleError>

Set per-feed staleness override. 0 means use global default.

fn set_feed_staleness(
    env: soroban_sdk::Env,
    token: soroban_sdk::Address,
    max_staleness: u64,
) -> Result<(), OracleError>

Get feeds with pagination.

fn get_feeds_paginated(
    env: soroban_sdk::Env,
    offset: u32,
    limit: u32,
) -> soroban_sdk::Vec<(soroban_sdk::Address, FeedConfig)>

Set a specific oracle address for an asset ID. Admin only.

This allows per-asset oracle configuration, enabling:

  • Different oracle sources for different assets
  • Custom price feeds for assets not supported by the default oracle

asset_id format:

  • For classic assets: {CODE}-{ISSUER} e.g., USDC-GA5ZSEJY...
  • For Soroban contracts: the contract address itself

Example: set_oracle_for_asset("AQUA", CALI2_ORACLE) sets AQUA to use CALI2 oracle.

fn set_oracle_for_asset(
    env: soroban_sdk::Env,
    token: soroban_sdk::Address,
    oracle: soroban_sdk::Address,
) -> Result<(), OracleError>
fn set_feed_twap_preference(
    env: soroban_sdk::Env,
    token: soroban_sdk::Address,
    prefer_twap: bool,
) -> Result<(), OracleError>

Set the number of TWAP records to use as fallback when spot price is stale or unavailable. Admin only.

fn set_twap_fallback_records(
    env: soroban_sdk::Env,
    records: u32,
) -> Result<(), OracleError>

Imports

WebAssembly Text (WAT) ▶