Initializes the LongShortPair contract.
This constructor is intended to be called exactly once at deploy time. It:
Admin, PauseAdmin, EmergencyAdmin) to params.adminassetcollateral_token, collateral_per_pair)lower_bound, upper_bound)LongShortPairError::AlreadyInitialized] if the contract has already been initialized.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:
collateral_used = tokens_to_mint * collateral_per_paircollateral_used of collateral from user into the Pair contracttokens_to_mint LONG and tokens_to_mint SHORT to the usertotal_collateralThis is the primary entry mechanism for creating new synthetic exposure.
LongShortPairError::InvalidInput] if tokens_to_mint == 0.LongShortPairError::ActionPaused] if minting is paused.LongShortPairError::MintingDisabled] if the pair is not [PairStatus::Active].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:
sync_collateral)tokens_to_redeem LONG and tokens_to_redeem SHORT from the usercollateral_returned = tokens_to_redeem * collateral_per_paircollateral_returned of collateral back to the usertotal_collateralThis redemption path requires burning both legs (LONG and SHORT) in equal quantity.
LongShortPairError::InvalidInput] if tokens_to_redeem == 0.LongShortPairError::ActionPaused] if redeeming is paused.LongShortPairError::InsufficientInventory] if the contract does not have enough collateral.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:
sync_collateral)sidetokens_to_redeem of the chosen sidetokens_to_redeem * collateral_per_pair * side_pcttotal_collateralLongShortPairError::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.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:
collateral_percent_long via the calculatorlast_update_ts and collateral_percent_longPairStatus::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(env: soroban_sdk::Env)
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.
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.
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 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