Contract f49fa741a5001266e54a68aed501221f10628c7479f06b92a569fc0c95fa3a75

← Back to Index 📥 Download WASM

Meta

Description A primary market for Long Short Pair tokens with accurate price enforcement and LP protections
rssdkver 22.0.8#f46e9e0610213bbb72285566f9dd960ff96d03d8
rsver 1.86.0

Instances

  • CDX3TMDOQ66A7UTZWDSEGPS3BVGYWHJRCXVBCMEXKLRF6X3JQNBI3UMN

Interface

Initializes the Treasury contract.

This constructor is intended to be called exactly once at deploy time. It:

  • Sets up core admin roles (Admin, PauseAdmin, EmergencyAdmin) to the provided admin
  • Stores the canonical USDC oracle used by the Treasury

Reverts

  • [TreasuryError::AlreadyInitialized] if the contract has already been initialized.

Arguments

  • e: Soroban environment.
  • admin: Address to assign administrative roles to.
  • oracle: Address of the Normal Oracle contract used for USDC pricing.
fn __constructor(
    env: soroban_sdk::Env,
    admin: soroban_sdk::Address,
    oracle: soroban_sdk::Address,
)

Deposits LP collateral into the Treasury in exchange for newly-minted LP shares.

A deposit consists of:

  • pairs_to_deposit LONG tokens
  • pairs_to_deposit SHORT tokens
  • pairs_to_deposit * collateral_per_pair USDC

Shares are minted proportional to the deposit's NAV relative to the Treasury's total NAV.

Reverts

  • [TreasuryError::InvalidInput] if pairs_to_deposit == 0.
  • [TreasuryError::ActionPaused] if deposits are paused.

Returns

Returns the number of LP shares minted for the depositor.

fn deposit(
    env: soroban_sdk::Env,
    user: soroban_sdk::Address,
    pair: soroban_sdk::Address,
    pairs_to_deposit: u128,
) -> u128

Withdraws LP collateral from the Treasury by burning LP shares.

The caller specifies the number of shares to burn. The Treasury computes the proportional amount of LONG/SHORT/USDC owed, validates safety constraints, and transfers the tokens to the user.

Reverts

  • [TreasuryError::InvalidInput] if shares == 0.
  • [TreasuryError::ActionPaused] if withdrawals are paused.
  • [TreasuryError::InsufficientShares] if shares > user_shares or total_shares == 0.

Returns

Returns the token amounts withdrawn: { long, short, usdc }.

fn withdraw(
    env: soroban_sdk::Env,
    user: soroban_sdk::Address,
    pair: soroban_sdk::Address,
    shares: u128,
) -> PairAmountsWithUSDC

Returns the stored token configuration for a given Pair.

This includes the contract addresses for the Pair, LONG, SHORT, and collateral (USDC) tokens.

fn get_config(env: soroban_sdk::Env, pair: soroban_sdk::Address) -> PairConfig

Returns the current oracle prices for the given Pair.

Prices are returned in the same precision as PRICE_PRECISION.

fn get_prices(env: soroban_sdk::Env, pair: soroban_sdk::Address) -> PairAmountsWithUSDC

Returns the Treasury’s internal accounting balances for the given Pair.

These balances represent the Treasury’s tracked inventory and may be used for quoting, risk checks, and LP accounting.

fn get_balances(
    env: soroban_sdk::Env,
    pair: soroban_sdk::Address,
) -> PairAmountsWithUSDC

Returns the total LP shares outstanding for the given Pair.

fn get_total_shares(env: soroban_sdk::Env, pair: soroban_sdk::Address) -> u128

Returns the LP share balance for user for the given Pair.

Missing records default to zero for read-only UX.

fn get_user_shares(
    env: soroban_sdk::Env,
    pair: soroban_sdk::Address,
    user: soroban_sdk::Address,
) -> u128

Returns the current fee configuration for the given Pair.

fn get_fee_config(
    env: soroban_sdk::Env,
    pair: soroban_sdk::Address,
) -> TreasuryFeeConfig

Returns a snapshot of the Treasury state for the given Pair.

This is a convenience method for frontends/indexers to avoid multiple round-trips.

fn get_summary(env: soroban_sdk::Env, pair: soroban_sdk::Address) -> TreasurySummary

Returns a snapshot of the Treasury state for a Pair plus the user's share balance.

This is a convenience method for frontends/indexers to fetch summary + user position in one call.

fn get_user_with_summary(
    env: soroban_sdk::Env,
    pair: soroban_sdk::Address,
    user: soroban_sdk::Address,
) -> TreasuryUserSummary

Estimates a trade output and fee without executing any token transfers.

This helper is intended for quoting in UIs and off-chain routing. It uses the same pricing + fee model as the on-chain trade methods.

Reverts

  • [TreasuryError::InvalidInput] if amount_in == 0.
  • Reverts if pair is not configured (via get_config).

Returns

Returns (amount_out, usdc_fee).

fn estimate_trade(
    env: soroban_sdk::Env,
    pair: soroban_sdk::Address,
    direction: Direction,
    side: Side,
    amount_in: u128,
) -> (u128, u128)

Buys LONG tokens from the Treasury using USDC.

The caller supplies usdc_in and receives long_out quoted from the current oracle price and fee model. This trade is executed against Treasury inventory: the Treasury must already hold sufficient LONG to deliver the trade.

Pricing & Fees

  • Uses prices.long from the oracle.
  • Computes a dynamic taker fee via calculate_fee(...).
  • quote_buy_token returns (long_out, usdc_fee); usdc_fee is retained and tracked.

Slippage Protection

Reverts if long_out < min_long_out.

Reverts

  • [TreasuryError::InvalidInput] if usdc_in == 0.
  • [TreasuryError::ActionPaused] if trading is paused.
  • [TreasuryError::Slippage] if output is zero or below min_long_out.
  • [TreasuryError::InsufficientInventory] if the Treasury lacks LONG inventory.

Returns

Returns the amount of LONG transferred to the user.

fn buy_long(
    env: soroban_sdk::Env,
    user: soroban_sdk::Address,
    pair: soroban_sdk::Address,
    usdc_in: u128,
    min_long_out: u128,
) -> (u128, u128)

Sells LONG tokens to the Treasury in exchange for USDC.

The caller supplies long_in and receives usdc_out quoted from the current oracle price and fee model. This trade is executed against Treasury USDC inventory: the Treasury must have sufficient USDC to pay out.

Additional safety checks apply to protect LPs:

  • LONG-side trades may be blocked as "toxic"
  • USDC floor constraints prevent draining too much collateral in a single trade

Slippage Protection

Reverts if usdc_out < min_usdc_out.

Reverts

  • [TreasuryError::InvalidInput] if long_in == 0.
  • [TreasuryError::ActionPaused] if trading is paused.
  • [TreasuryError::ToxicSideNotAccepted] if risk logic blocks LONG sells.
  • [TreasuryError::Slippage] if output is zero or below min_usdc_out.
  • [TreasuryError::InsufficientInventory] if the Treasury lacks USDC to pay out.
  • [TreasuryError::CannotPassFloor] if paying out violates the USDC floor.

Returns

Returns the amount of USDC transferred to the user.

fn sell_long(
    env: soroban_sdk::Env,
    user: soroban_sdk::Address,
    pair: soroban_sdk::Address,
    long_in: u128,
    min_usdc_out: u128,
) -> (u128, u128)

Buys SHORT tokens from the Treasury using USDC.

The caller supplies usdc_in and receives short_out quoted from the current oracle price and fee model. This trade is executed against Treasury inventory: the Treasury must already hold sufficient SHORT to deliver the trade.

Pricing & Fees

  • Uses prices.short from the oracle.
  • Computes a dynamic taker fee via calculate_fee(...).
  • quote_buy_token returns (short_out, usdc_fee); usdc_fee is retained and tracked.

Slippage Protection

Reverts if short_out < min_short_out.

Reverts

  • [TreasuryError::InvalidInput] if usdc_in == 0.
  • [TreasuryError::ActionPaused] if trading is paused.
  • [TreasuryError::Slippage] if output is zero or below min_short_out.
  • [TreasuryError::InsufficientInventory] if the Treasury lacks SHORT inventory.

Returns

Returns the amount of SHORT transferred to the user.

fn buy_short(
    env: soroban_sdk::Env,
    user: soroban_sdk::Address,
    pair: soroban_sdk::Address,
    usdc_in: u128,
    min_short_out: u128,
) -> (u128, u128)

Sells SHORT tokens to the Treasury in exchange for USDC.

The caller supplies short_in and receives usdc_out quoted from the current oracle price and fee model. This trade is executed against Treasury USDC inventory: the Treasury must have sufficient USDC to pay out.

Additional safety checks apply to protect LPs:

  • SHORT-side trades may be blocked as "toxic"
  • USDC floor constraints prevent draining too much collateral in a single trade

Slippage Protection

Reverts if usdc_out < min_usdc_out.

Reverts

  • [TreasuryError::InvalidInput] if short_in == 0.
  • [TreasuryError::ActionPaused] if trading is paused.
  • [TreasuryError::ToxicSideNotAccepted] if risk logic blocks SHORT sells.
  • [TreasuryError::Slippage] if output is zero or below min_usdc_out.
  • [TreasuryError::InsufficientInventory] if the Treasury lacks USDC to pay out.
  • [TreasuryError::CannotPassFloor] if paying out violates the USDC floor.

Returns

Returns the amount of USDC transferred to the user.

fn sell_short(
    env: soroban_sdk::Env,
    user: soroban_sdk::Address,
    pair: soroban_sdk::Address,
    short_in: u128,
    min_usdc_out: u128,
) -> (u128, u128)

Registers a new Pair with the Treasury and initializes its state.

This call:

  • Stores the token addresses for LONG/SHORT/USDC from the Pair contract
  • Initializes balances, shares, risk parameters, fee config, and protocol fee counters

Reverts

  • [TreasuryError::InvalidInput] if fee fields are out of range.
fn add_pair(
    env: soroban_sdk::Env,
    admin: soroban_sdk::Address,
    pair: soroban_sdk::Address,
    fee_config: TreasuryFeeConfig,
)

Updates the fee configuration for an existing Pair.

Reverts

  • [TreasuryError::InvalidInput] if any configured fee exceeds its maximum bound.
fn set_fee_config(
    env: soroban_sdk::Env,
    admin: soroban_sdk::Address,
    pair: soroban_sdk::Address,
    config: TreasuryFeeConfig,
)

Sets the global USDC floor fraction used by risk checks.

The floor fraction is expressed in PRICE_PRECISION units (e.g. 0.10e7 for 10%).

Reverts

  • [TreasuryError::InvalidInput] if floor_fraction is zero or below the minimum allowed.
fn set_usdc_floor(
    env: soroban_sdk::Env,
    admin: soroban_sdk::Address,
    floor_fraction: u128,
)

Returns the protocol fees accumulated for the given Pair (denominated in USDC).

fn get_protocol_fees(env: soroban_sdk::Env, pair: soroban_sdk::Address) -> u128

Transfers accumulated protocol fees for pair to destination.

Reverts

  • Reverts if admin is not authorized.

Returns

Returns the amount of fees transferred.

fn claim_protocol_fees(
    env: soroban_sdk::Env,
    admin: soroban_sdk::Address,
    pair: soroban_sdk::Address,
    destination: soroban_sdk::Address,
) -> u128
fn kill_deposit(env: soroban_sdk::Env, admin: soroban_sdk::Address)
fn kill_withdraw(env: soroban_sdk::Env, admin: soroban_sdk::Address)
fn kill_trade(env: soroban_sdk::Env, admin: soroban_sdk::Address)
fn kill_withdraw_floor(env: soroban_sdk::Env, admin: soroban_sdk::Address)
fn unkill_deposit(env: soroban_sdk::Env, admin: soroban_sdk::Address)
fn unkill_withdraw(env: soroban_sdk::Env, admin: soroban_sdk::Address)
fn unkill_trade(env: soroban_sdk::Env, admin: soroban_sdk::Address)
fn unkill_withdraw_floor(env: soroban_sdk::Env, admin: soroban_sdk::Address)
fn get_is_killed_deposit(env: soroban_sdk::Env) -> bool
fn get_is_killed_withdraw(env: soroban_sdk::Env) -> bool
fn get_is_killed_trade(env: soroban_sdk::Env) -> bool
fn get_is_killed_withdraw_floor(env: soroban_sdk::Env) -> bool
fn version(env: soroban_sdk::Env) -> u32
fn contract_name(env: soroban_sdk::Env) -> soroban_sdk::Symbol
fn commit_upgrade(
    env: soroban_sdk::Env,
    admin: soroban_sdk::Address,
    new_wasm_hash: soroban_sdk::BytesN<32>,
)
fn apply_upgrade(
    env: soroban_sdk::Env,
    admin: soroban_sdk::Address,
) -> soroban_sdk::BytesN<32>
fn revert_upgrade(env: soroban_sdk::Env, admin: soroban_sdk::Address)
fn set_emergency_mode(
    env: soroban_sdk::Env,
    emergency_admin: soroban_sdk::Address,
    value: bool,
)
fn get_emergency_mode(env: soroban_sdk::Env) -> bool
fn commit_transfer_ownership(
    env: soroban_sdk::Env,
    admin: soroban_sdk::Address,
    role_name: soroban_sdk::Symbol,
    new_address: soroban_sdk::Address,
)
fn apply_transfer_ownership(
    env: soroban_sdk::Env,
    admin: soroban_sdk::Address,
    role_name: soroban_sdk::Symbol,
)
fn revert_transfer_ownership(
    env: soroban_sdk::Env,
    admin: soroban_sdk::Address,
    role_name: soroban_sdk::Symbol,
)
fn get_future_address(
    env: soroban_sdk::Env,
    role_name: soroban_sdk::Symbol,
) -> soroban_sdk::Address

Imports

WebAssembly Text (WAT) ▶