Skip to content
Lattice

ICurveStableSwapPool

Git Source

Title: ICurveStableSwapPool

Author: Vendored minimal subset of Curve StableSwap (https://github.com/curvefi/curve-contract/blob/master/contracts/pool-templates/base/SwapTemplateBase.vy).

Upstream license: none granted ("Copyright (c) Curve.Fi, 2020 - all rights reserved").

Minimal vendored subset of a Curve StableSwap pool, specialized to a 2-coin pool.

Curve pools are generated per-N (the coins array is fixed-size in the Vyper source), so a single Solidity signature must pin N. The Lattice Curve adapter targets the dominant 2-coin StableSwap shape (e.g. stETH/ETH, FRAX/USDC, USDe/USDC); the adapter supplies one side via a configured coinIndex (0 or 1) and leaves the other at zero. Only the selectors the adapter calls are declared. Methods that move funds are non-view; valuation reads are view. NOTE: get_virtual_price() is read-only-reentrancy-exposed on real pools — see CurveStableSwapAdapterLib.totalAssetsManaged for how the adapter avoids reading it mid external interaction.

Functions

add_liquidity

Deposits amounts (indexed by coin) and mints at least minMint LP tokens to caller.

function add_liquidity(uint256[2] calldata amounts, uint256 minMint) external returns (uint256 minted);

Parameters

NameTypeDescription
amountsuint256[2]Per-coin deposit amounts (the adapter sets only its coinIndex slot).
minMintuint256Minimum LP to mint (slippage floor); reverts if the pool would mint less.

Returns

NameTypeDescription
minteduint256The amount of LP tokens minted to the caller.

remove_liquidity_one_coin

Burns lp LP tokens and withdraws a single coin i, sending at least minOut.

function remove_liquidity_one_coin(uint256 lp, int128 i, uint256 minOut) external returns (uint256 out);

Parameters

NameTypeDescription
lpuint256LP token amount to burn.
iint128Coin index to receive (int128 per Curve ABI).
minOutuint256Minimum coin out (slippage floor); reverts if the pool would return less.

Returns

NameTypeDescription
outuint256The amount of coin i returned to the caller.

get_virtual_price

The price of one LP token in the pool's invariant units (WAD, 1e18 == 1.0). Monotonically non-decreasing as the pool earns fees, so lp * virtualPrice / 1e18 lower-bounds the redeemable single-coin value (a safe NAV for an over-collateralized stable pool).

Read-only-reentrancy hazard: this can be manipulated mid-callback on real pools. Never call it during the adapter's own external interaction. See the adapter NatSpec.

function get_virtual_price() external view returns (uint256);

Returns

NameTypeDescription
<none>uint256

coins

Returns the token address at coin index i.

function coins(uint256 i) external view returns (address);

Parameters

NameTypeDescription
iuint256

Returns

NameTypeDescription
<none>address

calc_token_amount

Estimates LP minted (deposit==true) or burned (deposit==false) for amounts.

Used to size the slippage floor for add_liquidity / single-coin withdrawals. Does not account for fees on most pools, so callers apply an extra slippageBps haircut.

function calc_token_amount(uint256[2] calldata amounts, bool deposit) external view returns (uint256);

Parameters

NameTypeDescription
amountsuint256[2]
depositbool

Returns

NameTypeDescription
<none>uint256

calc_withdraw_one_coin

Estimates the single-coin output of burning lp LP for coin i.

Used to size the minOut slippage floor on withdrawals.

function calc_withdraw_one_coin(uint256 lp, int128 i) external view returns (uint256);

Parameters

NameTypeDescription
lpuint256
iint128

Returns

NameTypeDescription
<none>uint256