Initializes the Lobster contract with owner, multisig admin, token pair, and fee configuration.
owner: The address of the pool owner who can manage positionsmultisig: The address of the multisig admin (LOBSTER) that can also manage positionstoken0: Address of the first token in the pairtoken1: Address of the second token in the pairfee_cut_bps: Fee percentage in basis points (0-10000, where 10000 = 100%)fn __constructor(
env: soroban_sdk::Env,
owner: soroban_sdk::Address,
multisig: soroban_sdk::Address,
token0: soroban_sdk::Address,
token1: soroban_sdk::Address,
fee_cut_bps: u32,
)
Reentrancy guard exit: clears the temporary flag.
fn exit_reentrancy(env: soroban_sdk::Env)
Emergency function to reset reentrancy flag if it gets stuck.
This can happen if a panic occurs after enter_reentrancy but before exit_reentrancy.
The flag will eventually expire with temporary storage TTL, but this provides immediate recovery.
caller: The address calling this function (must be owner or admin)Only owner or multisig admin
fn reset_reentrancy(env: soroban_sdk::Env, caller: soroban_sdk::Address)
Returns the address of the contract owner.
The owner address stored during initialization
If contract is not initialized
fn get_owner(env: soroban_sdk::Env) -> soroban_sdk::Address
Returns the address of the multisig admin (LOBSTER).
The multisig admin address stored during initialization
If contract is not initialized
fn get_multisig(env: soroban_sdk::Env) -> soroban_sdk::Address
Updates the multisig admin (LOBSTER) address.
caller: Must be either the pool owner or current multisig adminnew_multisig: The new multisig admin address to storeOnly owner or multisig admin
fn set_multisig(
env: soroban_sdk::Env,
caller: soroban_sdk::Address,
new_multisig: soroban_sdk::Address,
)
Returns the address of the first token (token0) in the pair.
The token0 address stored during initialization
If contract is not initialized
fn get_token0(env: soroban_sdk::Env) -> soroban_sdk::Address
Returns the address of the second token (token1) in the pair.
The token1 address stored during initialization
If contract is not initialized
fn get_token1(env: soroban_sdk::Env) -> soroban_sdk::Address
Returns the currently active DEX protocol identifier.
Protocol identifier: 0 = Soroswap, 1 = Phoenix, 2 = Aquarius, 5 = No active position
If contract is not initialized
fn get_active_protocol(env: soroban_sdk::Env) -> i128
Returns the address of the currently active liquidity pool.
The pool address where liquidity is currently deployed
If contract is not initialized or no active pool exists
fn get_actual_pool(env: soroban_sdk::Env) -> soroban_sdk::Address
Returns the address of the currently active router (for Soroswap).
The router address used for Soroswap operations
If contract is not initialized or no active router exists
fn get_actual_router(env: soroban_sdk::Env) -> soroban_sdk::Address
Returns the address of the LP token/share token for the active position.
The LP token address representing the current liquidity position
If contract is not initialized or no active position exists
fn get_actual_share(env: soroban_sdk::Env) -> soroban_sdk::Address
Pull tokens from caller into this contract using transfer_from.
Access: only owner or multisig admin.
fn deposit(
env: soroban_sdk::Env,
caller: soroban_sdk::Address,
amount0: i128,
amount1: i128,
)
Public entry point for adding liquidity to a Phoenix pool. Validates access and delegates to internal implementation.
caller: Address of the caller (must be owner or multisig admin)amount0: Desired amount of token0 to addamount1: Desired amount of token1 to addamount0_min: Minimum amount of token0 to accept (slippage protection)amount1_min: Minimum amount of token1 to accept (slippage protection)pool_address: Address of the Phoenix pooldeadline: Ledger number deadline for the transactionslippage: Allowed slippage in basis pointsOnly owner or multisig admin
fn add_liquidity_phoenix(
env: soroban_sdk::Env,
caller: soroban_sdk::Address,
amount0: i128,
amount1: i128,
amount0_min: i128,
amount1_min: i128,
pool_address: soroban_sdk::Address,
deadline: u64,
slippage: i64,
)
Calculates optimal deposit amounts for adding liquidity while maintaining pool ratio. Ensures amounts respect minimum requirements and allowed slippage.
desired_a: Desired amount of token A to depositmin_a: Optional minimum amount of token A (slippage protection)desired_b: Desired amount of token B to depositmin_b: Optional minimum amount of token B (slippage protection)pool_balance_a: Current balance of token A in the poolpool_balance_b: Current balance of token B in the poolmy_allowed_slippage: Allowed slippage in basis pointsTuple of (optimal_amount_a, optimal_amount_b) that maintains pool ratio
fn get_deposit_amounts(
env: soroban_sdk::Env,
desired_a: i128,
min_a: Option,
desired_b: i128,
min_b: Option,
pool_balance_a: i128,
pool_balance_b: i128,
my_allowed_slippage: i64,
) -> (i128, i128)
Public entry point for adding liquidity to a Soroswap pool via router. Validates access and delegates to internal implementation.
caller: Address of the caller (must be owner or multisig admin)amount0: Desired amount of token0 to addamount1: Desired amount of token1 to addamount0_min: Minimum amount of token0 to accept (slippage protection)amount1_min: Minimum amount of token1 to accept (slippage protection)deadline_ledger: Ledger number deadline for the transactionrouter_address: Address of the Soroswap routerOnly owner or multisig admin
fn add_liquidity_soroswap(
env: soroban_sdk::Env,
caller: soroban_sdk::Address,
amount0: i128,
amount1: i128,
amount0_min: i128,
amount1_min: i128,
deadline_ledger: u64,
router_address: soroban_sdk::Address,
)
Public entry point for adding liquidity to an Aquarius pool. Validates access and delegates to internal implementation.
caller: Address of the caller (must be owner or multisig admin)amount0: Amount of token0 to addamount1: Amount of token1 to addpool_address: Address of the Aquarius poolOnly owner or multisig admin
fn add_liquidity_aquarius(
env: soroban_sdk::Env,
caller: soroban_sdk::Address,
amount0: i128,
amount1: i128,
pool_address: soroban_sdk::Address,
)
Public entry point for withdrawing all liquidity from an Aquarius pool. Validates access and delegates to internal implementation.
caller: Address of the caller (must be owner or multisig admin)pool_address: Address of the Aquarius pool to withdraw fromamount0_min: Minimum amount of token0 to receive (slippage protection)amount1_min: Minimum amount of token1 to receive (slippage protection)Only owner or multisig admin
fn withdraw_aquarius(
env: soroban_sdk::Env,
caller: soroban_sdk::Address,
pool_address: soroban_sdk::Address,
amount0_min: u128,
amount1_min: u128,
)
Returns the current LP token balance and LP token address for an Aquarius pool.
pool_address: Address of the Aquarius poolTuple of (lp_balance, lp_token_address) - current LP balance and LP token contract address
If pool queries fail
fn get_lp_aquarius(
env: soroban_sdk::Env,
pool_address: soroban_sdk::Address,
) -> (i128, soroban_sdk::Address)
Public entry point for withdrawing all liquidity from a Phoenix pool. Validates access and delegates to internal implementation.
caller: Address of the caller (must be owner or multisig admin)pool_address: Address of the Phoenix pool to withdraw fromamount0_min: Minimum amount of token0 to receive (slippage protection)amount1_min: Minimum amount of token1 to receive (slippage protection)deadline: Ledger number deadline for the transactionOnly owner or multisig admin
fn withdraw_phoenix(
env: soroban_sdk::Env,
caller: soroban_sdk::Address,
pool_address: soroban_sdk::Address,
amount0_min: i128,
amount1_min: i128,
deadline: u64,
)
Returns the current LP token balance and LP token address for a Phoenix pool.
pool_address: Address of the Phoenix poolTuple of (lp_balance, lp_token_address) - current LP balance and LP token contract address
If pool queries fail
fn get_lp_phoenix(
env: soroban_sdk::Env,
pool_address: soroban_sdk::Address,
) -> (i128, soroban_sdk::Address)
Public entry point for withdrawing all liquidity from a Soroswap pool via router. Validates access and delegates to internal implementation.
caller: Address of the caller (must be owner or multisig admin)amount0_min: Minimum amount of token0 to receive (slippage protection)amount1_min: Minimum amount of token1 to receive (slippage protection)pool_address: Address of the Soroswap pool to withdraw fromrouter_address: Address of the Soroswap routerdeadline: Ledger number deadline for the transactionOnly owner or multisig admin
fn withdraw_soroswap(
env: soroban_sdk::Env,
caller: soroban_sdk::Address,
amount0_min: i128,
amount1_min: i128,
pool_address: soroban_sdk::Address,
router_address: soroban_sdk::Address,
deadline: u64,
)
Returns the current LP token balance for a Soroswap pool. In Soroswap, the LP token is the pool address itself.
pool_address: Address of the Soroswap pool (also the LP token address)Current LP token balance held by this contract
If balance query fails
fn get_lp_soroswap(env: soroban_sdk::Env, pool_address: soroban_sdk::Address) -> i128
Public entry point for withdrawing tokens directly from the contract balance. Transfers tokens from contract to owner without interacting with pools.
caller: Address of the caller (must be owner or multisig admin)amount0: Amount of token0 to withdrawamount1: Amount of token1 to withdrawOnly owner or multisig admin
fn withdraw_contract(
env: soroban_sdk::Env,
caller: soroban_sdk::Address,
amount0: i128,
amount1: i128,
)
Retrieves token reserves from a pool, handling different DEX protocols. Returns reserves in pool order (not contract order) to maintain consistency with amounts from correct_token_order and TVL calculations.
pool_address: Address of the liquidity poolprotocol_tvl: Protocol identifier (0 = Soroswap, 1 = Phoenix, 2 = Aquarius)Tuple of (reserve0, reserve1) in pool order (pool's token0, pool's token1)
fn get_reserves(
env: soroban_sdk::Env,
pool_address: soroban_sdk::Address,
protocol_tvl: u32,
) -> (i128, i128)
Calculates token prices from pool reserves.
reserve0: Reserve amount of token0 in the poolreserve1: Reserve amount of token1 in the poolTuple of (price_0_in_1, price_1_in_0) where:
fn get_prices_from_reserves(
env: soroban_sdk::Env,
reserve0: i128,
reserve1: i128,
) -> (i128, i128)
Calculates Total Value Locked (TVL) for both tokens in the position. TVL represents the total value of tokens, accounting for their relative prices.
amount0: Amount of token0amount1: Amount of token1price0_in_1: Price of token0 in terms of token1price1_in_0: Price of token1 in terms of token0Tuple of (token0_tvl, token1_tvl) where:
On arithmetic overflow
fn get_token_tvl_from_reserves(
env: soroban_sdk::Env,
amount0: i128,
amount1: i128,
price0_in_1: i128,
price1_in_0: i128,
) -> (i128, i128)
Calculates the fee amount to be deducted from profits on each token. Fee is calculated as a percentage of total profit, distributed proportionally.
init_tvl0: Initial TVL in token0 terms when position was openedinit_tvl1: Initial TVL in token1 terms when position was openedcurrent_tvl0: Current TVL in token0 termscurrent_tvl1: Current TVL in token1 termscurrent_amount0: Current amount of token0current_amount1: Current amount of token1Tuple of (fee_token0, fee_token1) - fee amounts in each token Returns (0, 0) if there's no profit or total TVL is zero
On arithmetic overflow
fn get_fee_cut(
env: soroban_sdk::Env,
init_tvl0: i128,
init_tvl1: i128,
current_tvl0: i128,
current_tvl1: i128,
current_amount0: i128,
current_amount1: i128,
) -> (i128, i128)
Retrieves the underlying token amounts represented by LP position in a Phoenix pool.
pool_address: Address of the Phoenix poolTuple of (amount_a, amount_b) ordered to match contract's token0/token1
If pool query fails or LP balance cannot be determined
fn get_amounts_from_phoenix(
env: soroban_sdk::Env,
pool_address: soroban_sdk::Address,
) -> (i128, i128)
Retrieves the underlying token amounts represented by LP position in a Soroswap pool. Calculates amounts proportionally based on LP share of total supply.
pool_address: Address of the Soroswap poolTuple of (amount_a, amount_b) ordered to match contract's token0/token1
If pool query fails or calculation overflows
fn get_amounts_from_soroswap(
env: soroban_sdk::Env,
pool_address: soroban_sdk::Address,
) -> (i128, i128)
Retrieves the underlying token amounts represented by LP position in an Aquarius pool. Calculates amounts proportionally based on LP share of total supply.
pool_address: Address of the Aquarius poolTuple of (amount_a, amount_b) ordered to match contract's token0/token1
If pool query fails or calculation overflows
fn get_amounts_from_aquarius(
env: soroban_sdk::Env,
pool_address: soroban_sdk::Address,
) -> (i128, i128)
Returns the current token balances held directly by this contract (not in pools).
Tuple of (amount0, amount1) - current balances of token0 and token1 in contract
If token balance queries fail
fn get_amounts_tokens(env: soroban_sdk::Env) -> (i128, i128)