Stableswap

This section contains a full API reference of all public functions & events related to Connext's stableswap contracts.

Events

TokenSwap

event TokenSwap(bytes32 key, address buyer, uint256 tokensSold, uint256 tokensBought, uint128 soldId, uint128 boughtId)

AddLiquidity

event AddLiquidity(bytes32 key, address provider, uint256[] tokenAmounts, uint256[] fees, uint256 invariant, uint256 lpTokenSupply)

RemoveLiquidity

event RemoveLiquidity(bytes32 key, address provider, uint256[] tokenAmounts, uint256 lpTokenSupply)

RemoveLiquidityOne

event RemoveLiquidityOne(bytes32 key, address provider, uint256 lpTokenAmount, uint256 lpTokenSupply, uint256 boughtId, uint256 tokensBought)

Getters

getSwapStorage

function getSwapStorage(bytes32 key) external view returns (struct SwapUtils.Swap)

Return Stable swap storage

Parameters

Return Values

getSwapLPToken

function getSwapLPToken(bytes32 key) external view returns (address)

Return LP token for canonical Id

Parameters

Return Values

getSwapA

function getSwapA(bytes32 key) external view returns (uint256)

Return A, the amplification coefficient _ n _ (n - 1)

See the StableSwap paper for details

Parameters

Return Values

getSwapAPrecise

function getSwapAPrecise(bytes32 key) external view returns (uint256)

Return A in its raw precision form

See the StableSwap paper for details

Parameters

Return Values

getSwapToken

function getSwapToken(bytes32 key, uint8 index) public view returns (contract IERC20)

Return address of the pooled token at given index. Reverts if tokenIndex is out of range.

Parameters

Return Values

getSwapTokenIndex

function getSwapTokenIndex(bytes32 key, address tokenAddress) public view returns (uint8)

Return the index of the given token address. Reverts if no matching token is found.

Parameters

Return Values

getSwapTokenBalance

function getSwapTokenBalance(bytes32 key, uint8 index) external view returns (uint256)

Return current balance of the pooled token at given index

Parameters

Return Values

getSwapVirtualPrice

function getSwapVirtualPrice(bytes32 key) external view returns (uint256)

Get the virtual price, to help calculate profit

Parameters

Return Values

calculateSwap

function calculateSwap(bytes32 key, uint8 tokenIndexFrom, uint8 tokenIndexTo, uint256 dx) external view returns (uint256)

Calculate amount of tokens you receive on swap

Parameters

Return Values

calculateSwapTokenAmount

function calculateSwapTokenAmount(bytes32 key, uint256[] amounts, bool deposit) external view returns (uint256)

A simple method to calculate prices from deposits or withdrawals, excluding fees but including slippage. This is helpful as an input into the various "min" parameters on calls to fight front-running

This shouldn't be used outside frontends for user estimates.

Parameters

Return Values

calculateRemoveSwapLiquidity

function calculateRemoveSwapLiquidity(bytes32 key, uint256 amount) external view returns (uint256[])

A simple method to calculate amount of each underlying tokens that is returned upon burning given amount of LP tokens

Parameters

Return Values

calculateRemoveSwapLiquidityOneToken

function calculateRemoveSwapLiquidityOneToken(bytes32 key, uint256 tokenAmount, uint8 tokenIndex) external view returns (uint256 availableTokenAmount)

Calculate the amount of underlying token available to withdraw when withdrawing via only single token

Parameters

Return Values


Functions

swap

function swap(bytes32 key, uint8 tokenIndexFrom, uint8 tokenIndexTo, uint256 dx, uint256 minDy, uint256 deadline) external returns (uint256)

Swap two tokens using this pool

Parameters

swapExact

function swapExact(bytes32 key, uint256 amountIn, address assetIn, address assetOut, uint256 minAmountOut, uint256 deadline) external returns (uint256)

Swap two tokens using this pool

Parameters

swapExactOut

function swapExactOut(bytes32 key, uint256 amountOut, address assetIn, address assetOut, uint256 maxAmountIn, uint256 deadline) external returns (uint256)

Swap two tokens using this pool

Parameters

addSwapLiquidity

function addSwapLiquidity(bytes32 key, uint256[] amounts, uint256 minToMint, uint256 deadline) external returns (uint256)

Add liquidity to the pool with the given amounts of tokens

Parameters

Return Values

removeSwapLiquidity

function removeSwapLiquidity(bytes32 key, uint256 amount, uint256[] minAmounts, uint256 deadline) external returns (uint256[])

Burn LP tokens to remove liquidity from the pool. Withdraw fee that decays linearly over period of 4 weeks since last deposit will apply.

Liquidity can always be removed, even when the pool is paused.

Parameters

Return Values

removeSwapLiquidityOneToken

function removeSwapLiquidityOneToken(bytes32 key, uint256 tokenAmount, uint8 tokenIndex, uint256 minAmount, uint256 deadline) external returns (uint256)

Remove liquidity from the pool all in one token. Withdraw fee that decays linearly over period of 4 weeks since last deposit will apply.

Parameters

Return Values

Last updated