Contract f0e10c2924f73476027d5ae53e2c3ad9e63e251b31465559064bbb6555ae0a9e

← Back to Index 📥 Download WASM

Meta

Description A DeFi primitive for financial derivatives using long and short tokens
rssdkver 22.0.8#f46e9e0610213bbb72285566f9dd960ff96d03d8
rsver 1.86.0

Instances

  • CAKZ6DNXKOU7FJISF7CPYKIPOS6CQFDLAPURLB6EVSKUY63GLA5IUTJP
  • CALB4WRAZBO6LSJHWH3GLBJYH45HQ65VWRFLAHTAKUJG25E7Y2MU7PTI
  • CC3G4RXMJOYSXNGYDCYLZYBEDKVOENZ6JVJNV5VGWT7SBPTVBR64XIS5
  • CDFCQKZJ2BTGTPZN3TQC3XBRATKISO4VCJRRLHE62Y3SEOM6SBQLIY6M
  • CDLFUJWTKFCJVYGYFYHUAIKTUGXLWTIJMSBST4OLCHBWX2YHPGYSRKPF

Interface

Initializes the LongShortPair contract.

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

  • Sets core admin roles (Admin, PauseAdmin, EmergencyAdmin) to params.admin
  • Stores immutable-ish pair configuration such as the underlying asset
  • Stores collateral configuration (collateral_token, collateral_per_pair)
  • Stores token contract addresses for the LONG and SHORT tokens
  • Stores oracle and calculator addresses
  • Initializes price bounds (lower_bound, upper_bound)

Reverts

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

Arguments

  • e: Soroban environment.
  • params: Full set of pair parameters used to bootstrap the contract.
fn __constructor(env: soroban_sdk::Env, params: PairParams)

Mints equal amounts of LONG and SHORT tokens by depositing collateral.

For tokens_to_mint, the contract:

  1. Calculates collateral_used = tokens_to_mint * collateral_per_pair
  2. Transfers collateral_used of collateral from user into the Pair contract
  3. Mints tokens_to_mint LONG and tokens_to_mint SHORT to the user
  4. Increments the tracked total_collateral

This is the primary entry mechanism for creating new synthetic exposure.

Reverts

  • [LongShortPairError::InvalidInput] if tokens_to_mint == 0.
  • [LongShortPairError::ActionPaused] if minting is paused.
  • [LongShortPairError::MintingDisabled] if the pair is not [PairStatus::Active].

Returns

Returns the amount of collateral transferred in (collateral_used).

fn mint(
    env: soroban_sdk::Env,
    user: soroban_sdk::Address,
    tokens_to_mint: u128,
) -> u128

Redeems equal amounts of LONG and SHORT tokens for collateral.

For tokens_to_redeem, the contract:

  1. Synchronizes internal collateral accounting (sync_collateral)
  2. Burns tokens_to_redeem LONG and tokens_to_redeem SHORT from the user
  3. Calculates collateral_returned = tokens_to_redeem * collateral_per_pair
  4. Transfers collateral_returned of collateral back to the user
  5. Decrements the tracked total_collateral

This redemption path requires burning both legs (LONG and SHORT) in equal quantity.

Reverts

  • [LongShortPairError::InvalidInput] if tokens_to_redeem == 0.
  • [LongShortPairError::ActionPaused] if redeeming is paused.
  • [LongShortPairError::InsufficientInventory] if the contract does not have enough collateral.

Returns

Returns the amount of collateral returned (collateral_returned).

fn redeem(
    env: soroban_sdk::Env,
    user: soroban_sdk::Address,
    tokens_to_redeem: u128,
) -> u128

Redeems a single side (LONG or SHORT) for collateral after expiration.

This method is only enabled when the pair status is [PairStatus::Expired]. At expiry, settlement determines the collateral split between LONG and SHORT using collateral_percent_long (and 1 - collateral_percent_long for SHORT).

The contract:

  1. Synchronizes internal collateral accounting (sync_collateral)
  2. Requires the pair to be expired
  3. Determines the payout percent for side
  4. Burns tokens_to_redeem of the chosen side
  5. Pays out tokens_to_redeem * collateral_per_pair * side_pct
  6. Decrements tracked total_collateral

Notes

  • Redeeming a worthless side is forbidden (e.g., side percent is 0).
  • A computed payout of 0 is rejected (e.g., tiny redemption amount).

Reverts

  • [LongShortPairError::InvalidInput] if tokens_to_redeem == 0 or payout would be 0.
  • [LongShortPairError::ActionPaused] if redeeming is paused.
  • [LongShortPairError::InvalidStatus] if the pair is not expired.
  • [`LongShortPairErro
fn redeem_one(
    env: soroban_sdk::Env,
    user: soroban_sdk::Address,
    side: Side,
    tokens_to_redeem: u128,
) -> u128

Updates the Pair's settlement allocation (collateral_percent_long) using the oracle TWAP.

This is a passthrough to crate::utils::sync_collateral(&e).

Despite the name, this does not transfer collateral or reconcile balances. It only:

  • Queries the oracle TWAP
  • Computes a new collateral_percent_long via the calculator
  • Updates last_update_ts and collateral_percent_long
  • Potentially marks the Pair as [PairStatus::Expired] and sets expiration_ts if the TWAP reaches or crosses the configured bounds.

This function is useful for keepers/frontends that want to “poke” the Pair so that settlement state is fresh before mint/redeem flows or UI display.

fn sync_collateral_with_price(env: soroban_sdk::Env) -> u128

Returns the token contract addresses for the Pair: LONG, SHORT, and collateral.

fn get_tokens(env: soroban_sdk::Env) -> PairTokens

Returns the current configured price bounds for the Pair.

These bounds define the linear mapping used to convert settlement percent into a scaled price.

fn get_price_bounds(env: soroban_sdk::Env) -> PairPriceBounds

Returns the user's balances of LONG and SHORT tokens.

fn get_user_token_balances(
    env: soroban_sdk::Env,
    user: soroban_sdk::Address,
) -> PairAmounts

Returns the total supply of LONG and SHORT tokens.

fn get_total_token_supplies(env: soroban_sdk::Env) -> PairAmounts

Returns current collateral configuration and settlement information.

collateral_percent_long is the settlement allocation to LONG in PRICE_PRECISION units. SHORT receives PRICE_PRECISION - collateral_percent_long.

fn get_collateral_info(env: soroban_sdk::Env) -> CollateralInfo

Returns an aggregated snapshot of the Pair state.

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

fn get_summary(env: soroban_sdk::Env) -> PairSummary

Returns the current pair status.

fn get_status(env: soroban_sdk::Env) -> PairStatus

Updates the calculator address used by this Pair.

Reverts

  • Reverts if admin is not authorized.
fn set_calculator(
    env: soroban_sdk::Env,
    admin: soroban_sdk::Address,
    calculator: soroban_sdk::Address,
)

Updates the oracle address used by this Pair.

Reverts

  • Reverts if admin is not authorized.
fn set_oracle(
    env: soroban_sdk::Env,
    admin: soroban_sdk::Address,
    oracle: soroban_sdk::Address,
)
fn kill_mint(env: soroban_sdk::Env, admin: soroban_sdk::Address)
fn kill_redeem(env: soroban_sdk::Env, admin: soroban_sdk::Address)
fn unkill_mint(env: soroban_sdk::Env, admin: soroban_sdk::Address)
fn unkill_redeem(env: soroban_sdk::Env, admin: soroban_sdk::Address)
fn get_is_killed_mint(env: soroban_sdk::Env) -> bool
fn get_is_killed_redeem(env: soroban_sdk::Env) -> bool

Returns the current settlement allocation to LONG in PRICE_PRECISION units.

This is not a spot price. It is the settlement fraction of collateral assigned to LONG.

fn get_price(env: soroban_sdk::Env) -> u128

Returns the "scaled price" implied by the current settlement allocation.

This maps collateral_percent_long linearly into the configured [lower_bound, upper_bound] range:

scaled_price = lower_bound + (upper_bound - lower_bound) * collateral_percent_long / PRICE_PRECISION

Returns

Returns the scaled price in the same units as the configured bounds.

fn get_scaled_price(env: soroban_sdk::Env) -> u128
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) ▶