Contract 013487869cda1bee3eea0826f04601383ff572cba9cbe5106ecaed9692605740

← Back to Index 📥 Download WASM

Meta

rssdkver 23.2.1#ab415a33cc1f6bdce20ac4a12f0ddbe41a648949
rsver 1.90.0

Instances

  • CCUUH6JZU47YJJZ24BRAPIVX5VQYZEO47OOP5KXUG3HLNDUJWNMNQXKJ

Interface

Initialize the contract with the trading pair and dependencies

Arguments:

  • admin: Admin address for contract management
  • pool: Blend pool address
  • margin_manager: MarginManager contract address
  • base_token: The base token of the pair (e.g., XLM)
  • quote_token: The quote token of the pair (e.g., USDC)
fn initialize(
    env: soroban_sdk::Env,
    admin: soroban_sdk::Address,
    pool: soroban_sdk::Address,
    margin_manager: soroban_sdk::Address,
    base_token: soroban_sdk::Address,
    quote_token: soroban_sdk::Address,
) -> Result<(), EntrypointError>

Update the margin manager contract address

fn set_margin_manager(
    env: soroban_sdk::Env,
    admin: soroban_sdk::Address,
    margin_manager: soroban_sdk::Address,
) -> Result<(), EntrypointError>

Get the pool address

fn get_pool(env: soroban_sdk::Env) -> soroban_sdk::Address

Get the admin address

fn get_admin(env: soroban_sdk::Env) -> soroban_sdk::Address

Get the margin manager contract address

fn get_margin_manager(env: soroban_sdk::Env) -> soroban_sdk::Address

Get the base token address

fn get_base_token(env: soroban_sdk::Env) -> soroban_sdk::Address

Get the quote token address

fn get_quote_token(env: soroban_sdk::Env) -> soroban_sdk::Address

Get a position by user and position type

fn get_position(
    env: soroban_sdk::Env,
    user: soroban_sdk::Address,
    position_type: PositionType,
) -> Option

Check if a user has a position of a specific type

fn has_position(
    env: soroban_sdk::Env,
    user: soroban_sdk::Address,
    position_type: PositionType,
) -> bool

Open a LONG position on Base token

LONG Base = betting Base will appreciate vs Quote Flow: Flash loan Quote → Swap Quote→Base → Supply Base as collateral → Borrow Quote → Repay flash loan Result: Collateral=Base, Debt=Quote

Arguments:

  • caller: The user opening the position
  • flash_amount: Amount of Quote token to flash loan (also repay amount)
  • initial_margin: Amount of token the user provides as margin
  • collateral_amount: Amount of Base token to supply as collateral (for supply_collateral request)
  • collateral_from_base: If true, user provides Base token as margin. collateral_amount = swap_output + initial_margin borrow_amount = flash_amount (need full amount since margin is different token) If false, user provides Quote token as margin. collateral_amount = swap_output only borrow_amount = flash_amount - initial_margin (margin helps repay flash loan)
fn open_long(
    env: soroban_sdk::Env,
    caller: soroban_sdk::Address,
    flash_amount: i128,
    initial_margin: i128,
    collateral_amount: i128,
    collateral_from_base: bool,
) -> Result<(), EntrypointError>

Open a SHORT position on Base token

SHORT Base = betting Base will depreciate vs Quote Flow: Flash loan Base → Swap Base→Quote → Supply Quote as collateral → Borrow Base → Repay flash loan Result: Collateral=Quote, Debt=Base

Arguments:

  • caller: The user opening the position
  • flash_amount: Amount of Base token to flash loan (also repay amount)
  • initial_margin: Amount of token the user provides as margin
  • collateral_amount: Amount of Quote token to supply as collateral (for supply_collateral request)
  • collateral_from_quote: If true, user provides Quote token as margin. collateral_amount = swap_output + initial_margin borrow_amount = flash_amount (need full amount since margin is different token) If false, user provides Base token as margin. collateral_amount = swap_output only borrow_amount = flash_amount - initial_margin (margin helps repay flash loan)
fn open_short(
    env: soroban_sdk::Env,
    caller: soroban_sdk::Address,
    flash_amount: i128,
    initial_margin: i128,
    collateral_amount: i128,
    collateral_from_quote: bool,
) -> Result<(), EntrypointError>

Reduce or close a LONG position on Base token

To reduce/close long (Collateral=Base, Debt=Quote): Flow: Flash loan Base → Swap Base→Quote → Repay Quote debt → Withdraw Base collateral → Repay Base flash loan

Arguments:

  • caller: The user reducing the position
  • flash_amount: Amount of Base token to flash loan (will be swapped to Quote)
  • repay_amount: Amount of Quote debt to repay (expected output from swap)
  • withdraw_amount: Amount of Base collateral to withdraw (used to repay flash loan)
fn close_long(
    env: soroban_sdk::Env,
    caller: soroban_sdk::Address,
    flash_amount: i128,
    repay_amount: i128,
    withdraw_amount: i128,
) -> Result<(), EntrypointError>

Reduce or close a SHORT position on Base token

To reduce/close short (Collateral=Quote, Debt=Base): Flow: Flash loan Quote → Swap Quote→Base → Repay Base debt → Withdraw Quote collateral → Repay Quote flash loan

Arguments:

  • caller: The user reducing the position
  • flash_amount: Amount of Quote token to flash loan (will be swapped to Base)
  • repay_amount: Amount of Base debt to repay (expected output from swap)
  • withdraw_amount: Amount of Quote collateral to withdraw (used to repay flash loan)
fn close_short(
    env: soroban_sdk::Env,
    caller: soroban_sdk::Address,
    flash_amount: i128,
    repay_amount: i128,
    withdraw_amount: i128,
) -> Result<(), EntrypointError>

Create a supply collateral request

fn make_supply_collateral_request(
    env: soroban_sdk::Env,
    asset: soroban_sdk::Address,
    amount: i128,
) -> Request

Create a borrow request

fn make_borrow_request(
    env: soroban_sdk::Env,
    asset: soroban_sdk::Address,
    amount: i128,
) -> Request

Create a repay request

fn make_repay_request(
    env: soroban_sdk::Env,
    asset: soroban_sdk::Address,
    amount: i128,
) -> Request

Create a withdraw collateral request

fn make_withdraw_collateral_request(
    env: soroban_sdk::Env,
    asset: soroban_sdk::Address,
    amount: i128,
) -> Request

Imports

WebAssembly Text (WAT) ▶