Router
https://github.com/Into-the-Fathom/fathom-swap-smart-contracts/blob/master/contracts/periphery/UniswapV2Router02.sol
The UniswapV2Router02
contract facilitates interactions with the Uniswap decentralized exchange, including adding and removing liquidity, swapping tokens, and retrieving price quotes. It supports the following operations:
Add Liquidity: Allows users to contribute tokens to liquidity pools.
Remove Liquidity: Enables users to withdraw their tokens from liquidity pools.
Token Swaps: Facilitates swapping of tokens through Uniswap pairs.
Supporting Fee-On-Transfer Tokens: Handles tokens with transfer fees during liquidity removal and swaps.
Price Quotes and Amounts: Provides functions to compute price quotes and required token amounts for swaps.
State Variables
factory
: Address of the Uniswap V2 factory contract.WETH
: Address of the wrapped ETH (WETH) token contract.
Set Functions in UniswapV2Router02
addLiquidity
addLiquidity
Adds liquidity to a pair of tokens.
Parameters:
address tokenA
: Address of token A.address tokenB
: Address of token B.uint amountADesired
: Desired amount of token A.uint amountBDesired
: Desired amount of token B.uint amountAMin
: Minimum amount of token A.uint amountBMin
: Minimum amount of token B.address to
: Address to receive liquidity tokens.uint deadline
: Timestamp after which the transaction will revert.
addLiquidityETH
addLiquidityETH
Adds liquidity to a token-ETH pair.
Parameters:
address token
: Address of the token.uint amountTokenDesired
: Desired amount of the token.uint amountTokenMin
: Minimum amount of the token.uint amountETHMin
: Minimum amount of ETH.address to
: Address to receive liquidity tokens.uint deadline
: Timestamp after which the transaction will revert.
removeLiquidity
removeLiquidity
Removes liquidity from a pair of tokens.
Parameters:
address tokenA
: Address of token A.address tokenB
: Address of token B.uint liquidity
: Amount of liquidity tokens to remove.uint amountAMin
: Minimum amount of token A.uint amountBMin
: Minimum amount of token B.address to
: Address to receive tokens.uint deadline
: Timestamp after which the transaction will revert.
removeLiquidityETH
removeLiquidityETH
Removes liquidity from a token-ETH pair.
Parameters:
address token
: Address of the token.uint liquidity
: Amount of liquidity tokens to remove.uint amountTokenMin
: Minimum amount of the token.uint amountETHMin
: Minimum amount of ETH.address to
: Address to receive tokens.uint deadline
: Timestamp after which the transaction will revert.
removeLiquidityWithPermit
removeLiquidityWithPermit
Removes liquidity from a pair of tokens using a permit.
Parameters:
address tokenA
: Address of token A.address tokenB
: Address of token B.uint liquidity
: Amount of liquidity tokens to remove.uint amountAMin
: Minimum amount of token A.uint amountBMin
: Minimum amount of token B.address to
: Address to receive tokens.uint deadline
: Timestamp after which the transaction will revert.bool approveMax
: Whether to approve the maximum amount.uint8 v
: V value of the permit signature.bytes32 r
: R value of the permit signature.bytes32 s
: S value of the permit signature.
removeLiquidityETHWithPermit
removeLiquidityETHWithPermit
Removes liquidity from a token-ETH pair using a permit.
Parameters:
address token
: Address of the token.uint liquidity
: Amount of liquidity tokens to remove.uint amountTokenMin
: Minimum amount of the token.uint amountETHMin
: Minimum amount of ETH.address to
: Address to receive tokens.uint deadline
: Timestamp after which the transaction will revert.bool approveMax
: Whether to approve the maximum amount.uint8 v
: V value of the permit signature.bytes32 r
: R value of the permit signature.bytes32 s
: S value of the permit signature.
swapExactTokensForTokens
swapExactTokensForTokens
Swaps an exact amount of tokens for another token.
Parameters:
uint amountIn
: Amount of input tokens.uint amountOutMin
: Minimum amount of output tokens.address[] calldata path
: Array of token addresses to trade through.address to
: Address to receive output tokens.uint deadline
: Timestamp after which the transaction will revert.
swapTokensForExactTokens
swapTokensForExactTokens
Swaps tokens for an exact amount of another token.
Parameters:
uint amountOut
: Amount of output tokens.uint amountInMax
: Maximum amount of input tokens.address[] calldata path
: Array of token addresses to trade through.address to
: Address to receive output tokens.uint deadline
: Timestamp after which the transaction will revert.
swapExactETHForTokens
swapExactETHForTokens
Swaps an exact amount of ETH for tokens.
Parameters:
uint amountOutMin
: Minimum amount of output tokens.address[] calldata path
: Array of token addresses to trade through.address to
: Address to receive output tokens.uint deadline
: Timestamp after which the transaction will revert.
swapTokensForExactETH
swapTokensForExactETH
Swaps tokens for an exact amount of ETH.
Parameters:
uint amountOut
: Amount of output ETH.uint amountInMax
: Maximum amount of input tokens.address[] calldata path
: Array of token addresses to trade through.address to
: Address to receive ETH.uint deadline
: Timestamp after which the transaction will revert.
swapExactTokensForETH
swapExactTokensForETH
Swaps an exact amount of tokens for ETH.
Parameters:
uint amountIn
: Amount of input tokens.uint amountOutMin
: Minimum amount of output ETH.address[] calldata path
: Array of token addresses to trade through.address to
: Address to receive ETH.uint deadline
: Timestamp after which the transaction will revert.
swapETHForExactTokens
swapETHForExactTokens
Swaps ETH for an exact amount of tokens.
Parameters:
uint amountOut
: Amount of output tokens.address[] calldata path
: Array of token addresses to trade through.address to
: Address to receive output tokens.uint deadline
: Timestamp after which the transaction will revert.
Read Functions
factory
factory
Returns the address of the factory contract.
Parameters: None
Returns:
address
: Address of the factory contract.
Description: Retrieves the address of the factory contract used to create pairs of tokens.
WETH
WETH
Returns the address of the WETH token.
Parameters: None
Returns:
address
: Address of the WETH token.
Description: Retrieves the address of the Wrapped ETH (WETH) token used in the router.
quote
quote
Calculates the amount of token B given an amount of token A and reserves.
Parameters:
uint amountA
: Amount of token A.uint reserveA
: Reserve amount of token A.uint reserveB
: Reserve amount of token B.
Returns:
uint amountB
: Amount of token B.
Description: Computes the equivalent amount of token B given the amount of token A and their respective reserves.
getAmountOut
getAmountOut
Calculates the maximum output amount of the other asset given an input amount and pair reserves.
Parameters:
uint amountIn
: Input amount of the asset.uint reserveIn
: Reserve amount of the input asset.uint reserveOut
: Reserve amount of the output asset.
Returns:
uint amountOut
: Output amount of the asset.
Description: Determines the maximum output amount of the other asset given the input amount and the pair reserves.
getAmountIn
getAmountIn
Calculates the required input amount of the other asset given an output amount and pair reserves.
Parameters:
uint amountOut
: Output amount of the asset.uint reserveIn
: Reserve amount of the input asset.uint reserveOut
: Reserve amount of the output asset.
Returns:
uint amountIn
: Input amount of the asset.
Description: Computes the required input amount of the other asset given the output amount and the pair reserves.
getAmountsOut
getAmountsOut
Performs chained getAmountOut
calculations on any number of pairs.
Parameters:
uint amountIn
: Input amount of the first asset.address[] memory path
: Array of token addresses to trade through.
Returns:
uint[] memory amounts
: Array of output amounts for each step in the path.
Description: Executes a series of getAmountOut
calculations along a specified path of token pairs.
getAmountsIn
getAmountsIn
Performs chained getAmountIn
calculations on any number of pairs.
Parameters:
uint amountOut
: Output amount of the last asset.address[] memory path
: Array of token addresses to trade through.
Returns:
uint[] memory amounts
: Array of input amounts for each step in the path.
Description: Executes a series of getAmountIn
calculations along a specified path of token pairs.
Events
PairCreated
PairCreated
Emitted when a new liquidity pair is created.
Indexed Parameters:
address indexed token0
: The address of the first token in the pair.address indexed token1
: The address of the second token in the pair.address pair
: The address of the created pair.
Non-Indexed Parameters:
uint
: The length of allPairs array after the pair is created.
Approval
Approval
Emitted when a token approval is made.
Indexed Parameters:
address indexed owner
: The address of the token owner.address indexed spender
: The address of the spender.
Non-Indexed Parameters:
uint value
: The amount of tokens approved.
Transfer
Transfer
Emitted when a token transfer occurs.
Indexed Parameters:
address indexed from
: The address of the sender.address indexed to
: The address of the recipient.
Non-Indexed Parameters:
uint value
: The amount of tokens transferred.
Mint
Mint
Emitted when liquidity is added to a pool.
Indexed Parameters:
address indexed sender
: The address that initiated the minting.
Non-Indexed Parameters:
uint amount0
: The amount of token0 added.uint amount1
: The amount of token1 added.
Burn
Burn
Emitted when liquidity is removed from a pool.
Indexed Parameters:
address indexed sender
: The address that initiated the burning.address indexed to
: The address that received the tokens.
Non-Indexed Parameters:
uint amount0
: The amount of token0 removed.uint amount1
: The amount of token1 removed.
Swap
Swap
Emitted when a swap occurs in the pool.
Indexed Parameters:
address indexed sender
: The address that initiated the swap.address indexed to
: The address that received the output tokens.
Non-Indexed Parameters:
uint amount0In
: The amount of token0 input.uint amount1In
: The amount of token1 input.uint amount0Out
: The amount of token0 output.uint amount1Out
: The amount of token1 output.
Sync
Sync
Emitted when reserves are synced in the pool.
Non-Indexed Parameters:
uint112 reserve0
: The reserve of token0.uint112 reserve1
: The reserve of token1.
Deposit
Deposit
Emitted when ETH is deposited to the WETH contract.
Indexed Parameters:
address indexed sender
: The address that deposited ETH.
Non-Indexed Parameters:
uint value
: The amount of ETH deposited.
Withdraw
Withdraw
Emitted when ETH is withdrawn from the WETH contract.
Indexed Parameters:
address indexed sender
: The address that withdrew ETH.
Non-Indexed Parameters:
uint value
: The amount of ETH withdrawn.
Last updated