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: performance fee in basis points, capped at MAX_FEE_BPS (2000 = 20%)soroswap_router: the trusted Soroswap router the add path routes throughfn __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,
soroswap_router: soroban_sdk::Address,
)
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 the pool ownernew_multisig: The new multisig admin address to storeOwner only
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, 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 LP/share token address for the active position, derived from the active pool and protocol. ACT_SHARE stores the share count (an i128), not an address, so it is not returned here.
The LP token address representing the current liquidity position
If there is no active position, or a pool query fails
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 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 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, the only supported protocol)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)
Fee taken on the position's gain, measured in a single numeraire (token0). Profit is current_tvl0 - init_tvl0 (both value the whole position in token0 terms); the fee is that gain times the bps, taken in kind as an equal fraction of each held token.
init_tvl0: token0-denominated value of the position when it was openedinit_tvl1: token1-denominated value at open (only the sign is checked)current_tvl0: token0-denominated value nowcurrent_tvl1: token1-denominated value now (unused in the profit metric)current_amount0: Current amount of token0current_amount1: Current amount of token1Tuple of (fee_token0, fee_token1) - fee amounts in each token Returns (0, 0) if the position did not gain value in token0 terms
On arithmetic overflow, or if an initial TVL is negative
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 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)
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)