For the complete documentation index, see llms.txt. This page is also available as Markdown.

amm v2 router

Overview

Routing entrypoint for swaps, liquidity management, and quoting across approved V2 pools.


Read Functions

ETHER

function ETHER() external view returns (address return0)

Reads contract state.

This function does not take parameters.

Return Values

Name
Type
Description

return0

address

Not documented in NatSpec.


defaultFactory

Address of Protocol PoolFactory.sol

This function does not take parameters.

Return Values

Name
Type
Description

return0

address

Not documented in NatSpec.


factoryRegistry

Reads contract state.

This function does not take parameters.

Return Values

Name
Type
Description

return0

address

Not documented in NatSpec.


getAmountsIn

Reads contract state.

Parameters

Name
Type
Description

amountOut

uint256

Not documented in NatSpec.

routes

tuple(address from, address to, bool stable, address factory)[]

Not documented in NatSpec.

Return Values

Name
Type
Description

amounts

uint256[]

Not documented in NatSpec.


getAmountsOut

Reads contract state.

Parameters

Name
Type
Description

amountIn

uint256

Not documented in NatSpec.

routes

tuple(address from, address to, bool stable, address factory)[]

Not documented in NatSpec.

Return Values

Name
Type
Description

amounts

uint256[]

Not documented in NatSpec.


getReserves

Fetch and sort the reserves for a pool

Parameters

Name
Type
Description

tokenA

address

.

tokenB

address

.

stable

bool

True if pool is stable, false if volatile

_factory

address

Address of PoolFactory for tokenA and tokenB

Return Values

Name
Type
Description

reserveA

uint256

Amount of reserves of the sorted token A

reserveB

uint256

Amount of reserves of the sorted token B


isTrustedForwarder

Indicates whether any particular address is the trusted forwarder.

Parameters

Name
Type
Description

forwarder

address

Not documented in NatSpec.

Return Values

Name
Type
Description

return0

bool

Not documented in NatSpec.


poolFor

Calculate the address of a pool by its' factory. Used by all Router functions containing a Route[] or _factory argument. Reverts if _factory is not approved by the FactoryRegistry

Parameters

Name
Type
Description

tokenA

address

Address of token to query

tokenB

address

Address of token to query

stable

bool

True if pool is stable, false if volatile

_factory

address

Address of factory which created the pool

Return Values

Name
Type
Description

pool

address

Not documented in NatSpec.


quoteAddLiquidity

Quote the amount deposited into a Pool

Parameters

Name
Type
Description

tokenA

address

.

tokenB

address

.

stable

bool

True if pool is stable, false if volatile

_factory

address

Address of PoolFactory for tokenA and tokenB

amountADesired

uint256

Amount of tokenA desired to deposit

amountBDesired

uint256

Amount of tokenB desired to deposit

Return Values

Name
Type
Description

amountA

uint256

Amount of tokenA to actually deposit

amountB

uint256

Amount of tokenB to actually deposit

liquidity

uint256

Amount of liquidity token returned from deposit


quoteRemoveLiquidity

Quote the amount of liquidity removed from a Pool

Parameters

Name
Type
Description

tokenA

address

.

tokenB

address

.

stable

bool

True if pool is stable, false if volatile

_factory

address

Address of PoolFactory for tokenA and tokenB

liquidity

uint256

Amount of liquidity to remove

Return Values

Name
Type
Description

amountA

uint256

Amount of tokenA received

amountB

uint256

Amount of tokenB received


quoteStableLiquidityRatio

Used by zapper to determine appropriate ratio of A to B to deposit liquidity. Assumes stable pool.

Parameters

Name
Type
Description

tokenA

address

tokenA of stable pool you are zapping into.

tokenB

address

tokenB of stable pool you are zapping into.

_factory

address

Not documented in NatSpec.

Return Values

Name
Type
Description

ratio

uint256

Ratio of token0 to token1 required to deposit into zap.


sortTokens

Sort two tokens by which address value is less than the other

Parameters

Name
Type
Description

tokenA

address

Address of token to sort

tokenB

address

Address of token to sort

Return Values

Name
Type
Description

token0

address

Lower address value between tokenA and tokenB

token1

address

Higher address value between tokenA and tokenB


trustedForwarder

Returns the address of the trusted forwarder.

This function does not take parameters.

Return Values

Name
Type
Description

return0

address

Not documented in NatSpec.


voter

Address of Voter.sol

This function does not take parameters.

Return Values

Name
Type
Description

return0

address

Not documented in NatSpec.


weth

Interface of WETH contract used for WETH => ETH wrapping/unwrapping

This function does not take parameters.

Return Values

Name
Type
Description

return0

address

Not documented in NatSpec.


Write Functions

UNSAFE_swapExactTokensForTokens

Executes a state-changing call.

Parameters

Name
Type
Description

amounts

uint256[]

Not documented in NatSpec.

routes

tuple(address from, address to, bool stable, address factory)[]

Not documented in NatSpec.

to

address

Not documented in NatSpec.

deadline

uint256

Not documented in NatSpec.

Return Values

Name
Type
Description

return0

uint256[]

Not documented in NatSpec.


addLiquidity

Add liquidity of two tokens to a Pool

Parameters

Name
Type
Description

tokenA

address

.

tokenB

address

.

stable

bool

True if pool is stable, false if volatile

amountADesired

uint256

Amount of tokenA desired to deposit

amountBDesired

uint256

Amount of tokenB desired to deposit

amountAMin

uint256

Minimum amount of tokenA to deposit

amountBMin

uint256

Minimum amount of tokenB to deposit

to

address

Recipient of liquidity token

deadline

uint256

Deadline to receive liquidity

Return Values

Name
Type
Description

amountA

uint256

Amount of tokenA to actually deposit

amountB

uint256

Amount of tokenB to actually deposit

liquidity

uint256

Amount of liquidity token returned from deposit


addLiquidityETH

Add liquidity of a token and WETH (transferred as ETH) to a Pool

Parameters

Name
Type
Description

token

address

.

stable

bool

True if pool is stable, false if volatile

amountTokenDesired

uint256

Amount of token desired to deposit

amountTokenMin

uint256

Minimum amount of token to deposit

amountETHMin

uint256

Minimum amount of ETH to deposit

to

address

Recipient of liquidity token

deadline

uint256

Deadline to add liquidity

Return Values

Name
Type
Description

amountToken

uint256

Amount of token to actually deposit

amountETH

uint256

Amount of tokenETH to actually deposit

liquidity

uint256

Amount of liquidity token returned from deposit


removeLiquidity

Remove liquidity of two tokens from a Pool

Parameters

Name
Type
Description

tokenA

address

.

tokenB

address

.

stable

bool

True if pool is stable, false if volatile

liquidity

uint256

Amount of liquidity to remove

amountAMin

uint256

Minimum amount of tokenA to receive

amountBMin

uint256

Minimum amount of tokenB to receive

to

address

Recipient of tokens received

deadline

uint256

Deadline to remove liquidity

Return Values

Name
Type
Description

amountA

uint256

Amount of tokenA received

amountB

uint256

Amount of tokenB received


removeLiquidityETH

Remove liquidity of a token and WETH (returned as ETH) from a Pool

Parameters

Name
Type
Description

token

address

.

stable

bool

True if pool is stable, false if volatile

liquidity

uint256

Amount of liquidity to remove

amountTokenMin

uint256

Minimum amount of token to receive

amountETHMin

uint256

Minimum amount of ETH to receive

to

address

Recipient of liquidity token

deadline

uint256

Deadline to receive liquidity

Return Values

Name
Type
Description

amountToken

uint256

Amount of token received

amountETH

uint256

Amount of ETH received


removeLiquidityETHSupportingFeeOnTransferTokens

Remove liquidity of a fee-on-transfer token and WETH (returned as ETH) from a Pool

Parameters

Name
Type
Description

token

address

.

stable

bool

True if pool is stable, false if volatile

liquidity

uint256

Amount of liquidity to remove

amountTokenMin

uint256

Minimum amount of token to receive

amountETHMin

uint256

Minimum amount of ETH to receive

to

address

Recipient of liquidity token

deadline

uint256

Deadline to receive liquidity

Return Values

Name
Type
Description

amountETH

uint256

Amount of ETH received


swapExactETHForTokens

Executes a payable state-changing call.

Parameters

Name
Type
Description

amountOutMin

uint256

Not documented in NatSpec.

routes

tuple(address from, address to, bool stable, address factory)[]

Not documented in NatSpec.

to

address

Not documented in NatSpec.

deadline

uint256

Not documented in NatSpec.

Return Values

Name
Type
Description

amounts

uint256[]

Not documented in NatSpec.


swapExactETHForTokensSupportingFeeOnTransferTokens

Executes a payable state-changing call.

Parameters

Name
Type
Description

amountOutMin

uint256

Not documented in NatSpec.

routes

tuple(address from, address to, bool stable, address factory)[]

Not documented in NatSpec.

to

address

Not documented in NatSpec.

deadline

uint256

Not documented in NatSpec.

This function does not return a value.


swapExactTokensForETH

Executes a state-changing call.

Parameters

Name
Type
Description

amountIn

uint256

Not documented in NatSpec.

amountOutMin

uint256

Not documented in NatSpec.

routes

tuple(address from, address to, bool stable, address factory)[]

Not documented in NatSpec.

to

address

Not documented in NatSpec.

deadline

uint256

Not documented in NatSpec.

Return Values

Name
Type
Description

amounts

uint256[]

Not documented in NatSpec.


swapExactTokensForETHSupportingFeeOnTransferTokens

Executes a state-changing call.

Parameters

Name
Type
Description

amountIn

uint256

Not documented in NatSpec.

amountOutMin

uint256

Not documented in NatSpec.

routes

tuple(address from, address to, bool stable, address factory)[]

Not documented in NatSpec.

to

address

Not documented in NatSpec.

deadline

uint256

Not documented in NatSpec.

This function does not return a value.


swapExactTokensForTokens

Executes a state-changing call.

Parameters

Name
Type
Description

amountIn

uint256

Not documented in NatSpec.

amountOutMin

uint256

Not documented in NatSpec.

routes

tuple(address from, address to, bool stable, address factory)[]

Not documented in NatSpec.

to

address

Not documented in NatSpec.

deadline

uint256

Not documented in NatSpec.

Return Values

Name
Type
Description

amounts

uint256[]

Not documented in NatSpec.


swapExactTokensForTokensSupportingFeeOnTransferTokens

Executes a state-changing call.

Parameters

Name
Type
Description

amountIn

uint256

Not documented in NatSpec.

amountOutMin

uint256

Not documented in NatSpec.

routes

tuple(address from, address to, bool stable, address factory)[]

Not documented in NatSpec.

to

address

Not documented in NatSpec.

deadline

uint256

Not documented in NatSpec.

This function does not return a value.

Last updated