Contract 89a1ae9313b9abd1a93c5bf42b2982474dac263593a73a1ee5cd7dd0d8240b63

← Back to Index 📥 Download WASM

Meta

cliver 27.0.0#5a7c5fe76530bf4248477ac812fc757146b98cc4
rssdkver 26.1.0#175aa41306f383057a8cdfc84b68d931664fc34e
rsver 1.96.0

Instances

  • CBVJK35WSLZAEHFRO53W45Q242ON2V4XJYDN3C727LDKJG6L7GZ2O4VT

Interface

Remove liquidity. Returns positionMarginRequirement. caller must be the account owner or the collateral engine (liquidation). Liquidations skip the margin check (returns 0).

fn burn(
    env: soroban_sdk::Env,
    caller: soroban_sdk::Address,
    pool_id: PoolId,
    account: Account,
    tick_lower: i32,
    tick_upper: i32,
    amount: u128,
) -> Result

Add liquidity. Returns (positionMarginRequirement, feeIncurred). caller must be the account owner.

initial_price sets the pool's price when it was created without one (see create_pool): the first mint must pass Some(price), which initializes the pool and emits PoolInitialized. Once the price is set, mints must pass None — supplying a price to an already-priced pool errors with PriceAlreadySet.

fn mint(
    env: soroban_sdk::Env,
    caller: soroban_sdk::Address,
    pool_id: PoolId,
    account: Account,
    tick_lower: i32,
    tick_upper: i32,
    amount: u128,
    initial_price: Option,
) -> Result<(u128, i128), soroban_sdk::Error>

Execute a swap. amount_specified > 0 = fixed taker, < 0 = variable taker. caller must be the account owner or the collateral engine (liquidation). Liquidations skip the margin check (returns 0).

fn swap(
    env: soroban_sdk::Env,
    caller: soroban_sdk::Address,
    pool_id: PoolId,
    params: SwapParams,
) -> Result

The current admin.

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

Derive a pool's id from its key (PoolKey.toId).

fn pool_id(env: soroban_sdk::Env, key: PoolKey) -> PoolId

Replace the contract's wasm (admin-gated). Address and storage are kept.

fn upgrade(env: soroban_sdk::Env, new_wasm_hash: soroban_sdk::BytesN<32>)
fn get_admin(env: soroban_sdk::Env) -> soroban_sdk::Address

Transfer the admin role to new_admin (current admin only). The deploy hands the VAMM over to the governance timelock this way once its owner-driven setup has run; afterwards every admin change (including create_pool) goes through governance.

fn set_admin(env: soroban_sdk::Env, new_admin: soroban_sdk::Address)

Every pool id ever created, in creation order. The on-chain directory: lets a client enumerate pools and then drive mint/burn/swap by id alone.

Reads the whole registry in one call, so it is eventually bounded by the transaction read budget. Clients that must not inherit that bound should page through list_pools_page using pool_count.

fn list_pools(env: soroban_sdk::Env) -> soroban_sdk::Vec

How many pools have ever been created — the length of the directory.

fn pool_count(env: soroban_sdk::Env) -> u32

Create and initialize a new pool (admin only). Returns (tick, poolId). key fully identifies the pool.

sqrt_price may be None to defer the initial price: the pool is created without a price (and without a meaningful tick), and the first mint must supply one. When deferred, the returned tick is None and the PoolInitialized event fires from that first mint instead of here.

fn create_pool(
    env: soroban_sdk::Env,
    key: PoolKey,
    sqrt_price: Option,
) -> Result<(Option, PoolId), soroban_sdk::Error>

Storage/schema version, bumped by a post-upgrade migration when the layout changes.

fn get_version(env: soroban_sdk::Env) -> u32

Whether a pool with this key exists.

fn pool_exists(env: soroban_sdk::Env, key: PoolKey) -> bool

Reconstruct a pool's PoolKey from its stored state — the inverse of pool_id. Useful to label/identify a pool given only its id.

fn get_pool_key(
    env: soroban_sdk::Env,
    pool_id: PoolId,
) -> Result

Set global config: the admin (pool creator) and the shared CollateralEngine.

fn __constructor(
    env: soroban_sdk::Env,
    admin: soroban_sdk::Address,
    engine: soroban_sdk::Address,
)

(tick, sqrtPrice, compoundToken) for the pool.

fn get_vamm_state(
    env: soroban_sdk::Env,
    pool_id: PoolId,
) -> Result<(i32, SqrtPriceX96, soroban_sdk::Address), soroban_sdk::Error>

One page of the directory, in creation order: ids page * 256 .. (page + 1) * 256. Empty past the end. Pair with pool_count to walk the registry at a fixed cost per call, however many pools exist.

fn list_pools_page(env: soroban_sdk::Env, page: u32) -> soroban_sdk::Vec

The amount_specified that retires exactly variable_tokens of a position's variable leg, signed the same way — pass a position's variable_token_balance to get the notional that closes it out to zero.

A swap is quoted in notional and books ceil(notional / (1 + accrued)) of the pool's term-start-anchored tokens, so the two units are not interchangeable once the term is under way, and a caller cannot compute the inverse off-chain: accrued advances with the ledger, so any notional derived before the transaction lands is stale on arrival and leaves a residue. Worse, retrying against the residue leaves 1 / (1 + accrued) of it each time — geometric, never reaching the zero that gates a full close.

The floor here is what makes the round trip exact rather than approximate: ceil(floor(B * (1 + accrued)) / (1 + accrued)) == B for every B, because flooring loses strictly less than one unit and the swap's ceiling puts it back. Rounding the other way would overshoot and flip the leg past zero.

Refresh

fn notional_to_close(
    env: soroban_sdk::Env,
    pool_id: PoolId,
    variable_tokens: i128,
) -> Result

The APR oracle this pool reads its variable factor from and pins term_start on — the engine's own, resolved at create_pool. Exposed so a deployment can be checked against the engine's config without a trade having to fail first.

fn get_pool_apr_oracle(
    env: soroban_sdk::Env,
    pool_id: PoolId,
) -> Result

Remove liquidity as a liquidation step, driven by the collateral engine. Same pool mutation as burn, but returns the resulting UpdatePositionParams instead of calling back into the engine: the engine — already on the call stack inside its own liquidate_position — applies the update to itself in-process (update_position_post_vamm_action). This is what keeps the engine from re-entering itself through the VAMM (engine -> vamm -> engine), which the two-hop burn callback would otherwise require during liquidation. caller must be the configured engine; the margin check burn runs is meaningless here (liquidations are forced closes), so it is skipped. The engine is the only intended caller — see CollateralEngine::liquidate_position.

fn burn_for_liquidation(
    env: soroban_sdk::Env,
    caller: soroban_sdk::Address,
    pool_id: PoolId,
    account: Account,
    tick_lower: i32,
    tick_upper: i32,
    amount: u128,
) -> Result

Execute a swap as a liquidation step, driven by the collateral engine. Same pool math as swap, but returns the resulting UpdatePositionParams instead of calling back into the engine — see burn_for_liquidation for why. caller must be the configured engine.

fn swap_for_liquidation(
    env: soroban_sdk::Env,
    caller: soroban_sdk::Address,
    pool_id: PoolId,
    params: SwapParams,
) -> Result

Fixed/variable token growth accumulated inside [tick_lower, tick_upper) (X128).

fn compute_growth_inside(
    env: soroban_sdk::Env,
    pool_id: PoolId,
    tick_lower: i32,
    tick_upper: i32,
) -> Result<(soroban_sdk::I256, soroban_sdk::I256), soroban_sdk::Error>

Imports

WebAssembly Text (WAT) ▶