// SPDX-License-Identifier: MIT pragma solidity >=0.6.2; /** * @title SOMA Swap Router Contract. * @author SOMA.finance * @notice Interface for the {SomaSwapRouter} contract. */ interface ISomaSwapRouter { /** * @notice Returns the address of the factory contract. */ function factory() external view returns (address); /** * @notice Returns the address of the WETH token. */ function WETH() external view returns (address); /** * @notice Adds liquidity to the pool. * @param tokenA The token0 of the pair to add liquidity to. * @param tokenB The token1 of the pair to add liquidity to. * @param amountADesired The amount of token0 to add as liquidity. * @param amountBDesired The amount of token1 to add as liquidity. * @param amountAMin The bound of the tokenB / tokenA price can go up * before transaction reverts. * @param amountBMin The bound of the tokenA / tokenB price can go up * before transaction reverts. * @param to The address to receive the liquidity tokens. * @param deadline The unix timestamp after which the transaction will revert. * @custom:requirement `tokenA` and `tokenB` pair must already exist. * @custom:requirement the router's expiration deadline must be greater than the timestamp of the * function call * @return amountA The amount of tokenA added as liquidity. * @return amountB The amount of tokenB added as liquidity. * @return liquidity The amount of liquidity tokens minted. */ function addLiquidity( address tokenA, address tokenB, uint256 amountADesired, uint256 amountBDesired, uint256 amountAMin, uint256 amountBMin, address to, uint256 deadline ) external returns (uint256 amountA, uint256 amountB, uint256 liquidity); /** * @notice Adds liquidity to the pool with ETH. * @param token The pool token. * @param amountTokenDesired The amount of token to add as liquidity if WETH/token price * is less or equal to the value of msg.value/amountTokenDesired (token depreciates). * @param amountTokenMin The bound that WETH/token price can go up before the transactions * reverts. * @param amountETHMin The bound that token/WETH price can go up before the transaction reverts. * @param to The recipient of the liquidity tokens. * @param deadline The unix timestamp after which the transaction will revert. * @custom:requirement `tokenA` and `tokenB` pair must already exist. * @custom:requirement the router's expiration deadline must be greater than the timestamp of the * function call * @return amountToken The amount of token sent to the pool. * @return amountETH The amount of ETH converted to WETH and sent to the pool. * @return liquidity The amount of liquidity tokens minted. */ function addLiquidityETH( address token, uint256 amountTokenDesired, uint256 amountTokenMin, uint256 amountETHMin, address to, uint256 deadline ) external payable returns (uint256 amountToken, uint256 amountETH, uint256 liquidity); /** * @notice Removes liquidity from the pool. * @param tokenA The pool token. * @param tokenB The pool token. * @param liquidity The amount of liquidity tokens to remove. * @param amountAMin The minimum amount of tokenA that must be received * for the transaction not to revert. * @param amountBMin The minimum amount of tokenB that must be received * for the transaction not to revert. * @param to The recipient of the underlying asset. * @param deadline The unix timestamp after which the transaction will revert. * @custom:requirement `amountA` must be greater than or equal to `amountAMin`. * @custom:requirement `amountB` must be greater than or equal to `amountBMin`. * @return amountA The amount of tokenA received. * @return amountB The amount of tokenB received. */ function removeLiquidity( address tokenA, address tokenB, uint256 liquidity, uint256 amountAMin, uint256 amountBMin, address to, uint256 deadline ) external returns (uint256 amountA, uint256 amountB); /** * @notice Removes liquidity from the pool and the caller receives ETH. * @param token The pool token. * @param liquidity The amount of liquidity tokens to remove. * @param amountTokenMin The minimum amount of tokens that must be received * for the transaction not to revert. * @param amountETHMin The minimum amount of ETH that must be received for the * transaction not to revert. * @param to The recipient of the underlying assets. * @param deadline The unix timestamp after which the transaction will revert. * @custom:requirement `amountA` must be greater than or equal to `amountAMin`. * @custom:requirement `amountB` must be greater than or equal to `amountBMin`. * @return amountToken The amount of token received. * @return amountETH The amount of ETH received. */ function removeLiquidityETH( address token, uint256 liquidity, uint256 amountTokenMin, uint256 amountETHMin, address to, uint256 deadline ) external returns (uint256 amountToken, uint256 amountETH); /** * @notice Removes liquidity from the pool without pre-approval. * @param tokenA The pool token0. * @param tokenB The pool token1. * @param liquidity The amount of liquidity to remove. * @param amountAMin The minimum amount of tokenA that must be received for the * transaction not to revert. * @param amountBMin The minimum amount of tokenB that must be received for the * transaction not to revert. * @param to The recipient of the underlying asset. * @param deadline The unix timestamp after which the transaction will revert. * @param approveMax Boolean value indicating if the approval amount in the signature * is for liquidity or uint(-1). * @param v The v component of the permit signature. * @param r The r component of the permit signature. * @param s The s component of the permit signature. * @custom:requirement `amountA` must be greater than or equal to `amountAMin`. * @custom:requirement `amountB` must be greater than or equal to `amountBMin`. * @return amountA The amount of tokenA received. * @return amountB The amount of tokenB received. */ function removeLiquidityWithPermit( address tokenA, address tokenB, uint256 liquidity, uint256 amountAMin, uint256 amountBMin, address to, uint256 deadline, bool approveMax, uint8 v, bytes32 r, bytes32 s ) external returns (uint256 amountA, uint256 amountB); /** * @notice Removes liquidity from the pool and the caller receives ETH without pre-approval. * @param token The pool token. * @param liquidity The amount of liquidity to remove. * @param amountTokenMin The minimum amount of token that must be received for the transaction * not to revert. * @param amountETHMin The minimum amount of ETH that must be received for the transaction not * to revert. * @param to The recipient of the underlying asset. * @param deadline The unix timestamp after which the transaction will revert. * @param approveMax Boolean value indicating if the approval amount in the signature * is for liquidity or uint(-1). * @param v The v component of the permit signature. * @param r The r component of the permit signature. * @param s The s component of the permit signature. * @return amountToken The amount fo token received. * @return amountETH The amount of ETH received. */ function removeLiquidityETHWithPermit( address token, uint256 liquidity, uint256 amountTokenMin, uint256 amountETHMin, address to, uint256 deadline, bool approveMax, uint8 v, bytes32 r, bytes32 s ) external returns (uint256 amountToken, uint256 amountETH); /** * @notice Swaps an exact amount of input tokens for as many output tokens as possible, along * with the route determined by the path. * @param amountIn The amount of input tokens to send. * @param amountOutMin The minimum amount of output tokens that must be received for the transaction * not to revert. * @param path The array of token addresses, where pools for each pair of addresses must exist and * have liquidity. * @param to The recipient of the output tokens. * @param deadline The unix timestamp after which the transaction will revert. * @custom:requirement The value at the last index of `amounts` (from `SomaSwapLibrary.getAmountsOut()`) must be greater than or equal to `amountOutMin`. * @return amounts The input token amount and all subsequent output token amounts. */ function swapExactTokensForTokens( uint256 amountIn, uint256 amountOutMin, address[] calldata path, address to, uint256 deadline ) external returns (uint256[] memory amounts); /** * @notice Caller receives an exact amount of output tokens for as few input input tokens as possible, along * with the route determined by the path. * @param amountOut The amount of output tokens to receive. * @param amountInMax The maximum amount of input tokens that can be required before the transaction reverts. * @param path The array of token addresses, where pools for each pair of addresses must exist and * have liquidity. * @param to The recipient of the output tokens. * @param deadline The unix timestamp after which the transaction will revert. * @custom:requirement The value of the first index of `amounts` (from `SomaSwapLibrary.getAmountsIn()`) must be less than or equal to `amountInMax`. * @return amounts The input token amount and all subsequent output token amounts. */ function swapTokensForExactTokens( uint256 amountOut, uint256 amountInMax, address[] calldata path, address to, uint256 deadline ) external returns (uint256[] memory amounts); /** * @notice Swaps an exact amount of ETH for as many output tokens as possible, along with the route * determined by the path. * @param amountOutMin The minimum amount of output tokens that must be received for the transaction not to revert. * @param path The array of token addresses, where pools for each pair of addresses must exist and * have liquidity. * @param to The recipient of the output tokens. * @param deadline The unix timestamp after which the transaction will revert. * @custom:requirement The first element of `path` must be equal to the WETH address. * @custom:requirement The last element of `amounts` (from `SomaSwapLibrary.getAmountsOut()`) must be greater than or equal to `amount0Min`. * @return amounts The input token amount and all subsequent output token amounts. */ function swapExactETHForTokens(uint256 amountOutMin, address[] calldata path, address to, uint256 deadline) external payable returns (uint256[] memory amounts); /** * @notice Caller receives an exact amount of ETH for as few input tokens as possible, along with the route * determined by the path. * @param amountOut The amount of ETH to receive. * @param amountInMax The maximum amount of input tokens that can be required before the transaction reverts. * @param path The array of token addresses, where pools for each pair of addresses must exist and * have liquidity. * @param to The recipient of the output tokens. * @param deadline The unix timestamp after which the transaction will revert. * @custom:requirement The last element of `path` must be equal to the WETH address. * @custom:requirement The first element of `amounts` (from `SomaSwapLibrary.getAmountsIn()`) must be less than or equal to `amountInMax`. * @return amounts The input token amount and all subsequent output token amounts. */ function swapTokensForExactETH( uint256 amountOut, uint256 amountInMax, address[] calldata path, address to, uint256 deadline ) external returns (uint256[] memory amounts); /** * @notice Swaps an exact amount of tokens for as much ETH as possible, along with the route determined * by the path. * @param amountIn The amount of input tokens to send. * @param amountOutMin The minimum amount of output tokens that must be received for the transaction not to revert. * @param path The array of token addresses, where pools for each pair of addresses must exist and * have liquidity. * @param to The recipient of the output tokens. * @param deadline The unix timestamp after which the transaction will revert. * @custom:requirement The last element of `path` must be equal to the WETH address. * @custom:requirement The last element of `amounts` (from `SomaSwapLibrary.getAmountsOut()`) must be greater than or * equal to `amountOutMin`. * @return amounts The input token amount and all subsequent output token amounts. */ function swapExactTokensForETH( uint256 amountIn, uint256 amountOutMin, address[] calldata path, address to, uint256 deadline ) external returns (uint256[] memory amounts); /** * @notice Caller receives an exact amount of tokens for as little ETH as possible, along with the route determined * by the path. * @param amountOut The amount of tokens to receive. * @param path The array of token addresses, where pools for each pair of addresses must exist and * have liquidity. * @param to The recipient of the output tokens. * @param deadline The unix timestamp after which the transaction will revert. * @custom:requirement The first element of `path` must be equal to the WETH address. * @custom:requirement The first element of `amounts` (from `SomaSwapLibrary.getAmountIn()`) must be less than or equal * to the `msg.value`. * @return amounts The input token amount and all subsequent output token amounts. */ function swapETHForExactTokens(uint256 amountOut, address[] calldata path, address to, uint256 deadline) external payable returns (uint256[] memory amounts); /** * @notice Given some asset amount and reserves, returns the amount of the other asset representing equivalent value. * @param amountA The amount of token0. * @param reserveA The reserves of token0. * @param reserveB The reserves of token1. * @custom:requirement `amountA` must be greater than zero. * @custom:requirement `reserveA` must be greater than zero. * @custom:requirement `reserveB` must be greater than zero. * @return amountB The amount of token1. */ function quote(uint256 amountA, uint256 reserveA, uint256 reserveB) external pure returns (uint256 amountB); /** * @notice Given some asset amount and reserves, returns the maximum output amount of the other asset (accounting for fees). * @param amountIn The amount of the input token. * @param reserveIn The reserves of the input token. * @param reserveOut The reserves of the output token. * @custom:requirement `amountIn` must be greater than zero. * @custom:requirement `reserveIn` must be greater than zero. * @custom:requirement `reserveOut` must be greater than zero. * @return amountOut The amount of the output token. */ function getAmountOut(uint256 amountIn, uint256 reserveIn, uint256 reserveOut) external pure returns (uint256 amountOut); /** * @notice Returns the minimum input asset amount required to buy the given output asset amount (accounting for fees). * @param amountOut The amount of the output token. * @param reserveIn The reserves of the input token. * @param reserveOut The reserves of the output token. * @custom:requirement `amountOut` must be greater than zero. * @custom:requirement `reserveIn` must be greater than zero. * @custom:requirement `reserveOut` must be greater than zero. * @return amountIn The required input amount of the input asset. */ function getAmountIn(uint256 amountOut, uint256 reserveIn, uint256 reserveOut) external pure returns (uint256 amountIn); /** * @notice Given an input asset amount and an array of token addresses, calculates all subsequent maximum output token amounts * calling `getReserves()` for each pair of token addresses in the path in turn, and using these to call `getAmountOut()`. * @param amountIn The amount of the input token. * @param path The array of token addresses, where pools for each pair of addresses must exist and * have liquidity. * @custom:requirement `path` length must be greater than or equal to 2. * @return amounts The maximum output amounts. */ function getAmountsOut(uint256 amountIn, address[] calldata path) external view returns (uint256[] memory amounts); /** * @notice Given an output asset amount and an array of token addresses, calculates all preceding minimum input token amounts * by calling `getReserves()` for each pair of token addresses in the path in turn, and using these to call `getAmountIn()`. * @param amountOut The amount of the output token. * @param path The array of token addresses, where pools for each pair of addresses must exist and * have liquidity. * @custom:requirement `path` length must be greater than or equal to 2. * @return amounts The required input amounts. */ function getAmountsIn(uint256 amountOut, address[] calldata path) external view returns (uint256[] memory amounts); /** * @notice See {ISomaSwapRouter-removeLiquidityETH} - Identical but succeeds for tokens that take a fee on transfer. * @param token The pool token. * @param liquidity The amount of liquidity tokens to remove. * @param amountTokenMin The minimum amount of token that must be received for the transaction not to revert. * @param amountETHMin The minimum amount of ETH that must be received for the transaction not to revert. * @param to Recipient of the underlying assets. * @param deadline Unix timestamp after which the transaction will revert. * @custom:requirement There must be enough liquidity for both token amounts to be removed. * @return amountETH The amount of ETH received. */ function removeLiquidityETHSupportingFeeOnTransferTokens( address token, uint256 liquidity, uint256 amountTokenMin, uint256 amountETHMin, address to, uint256 deadline ) external returns (uint256 amountETH); /** * @notice See {ISomaSwapRouter-removeLiquidityETHWithPermit} - Identical but succeeds for tokens that take a fee on transfer. * @param token The pool token. * @param liquidity The amount of liquidity tokens to remove. * @param amountTokenMin The minimum amount of token that must be received for the transaction not to revert. * @param amountETHMin The minimum amount of ETH that must be received for the transaction not to revert. * @param to The recipient of the underlying assets. * @param deadline The unix timestamp after which the transaction will revert. * @param approveMax Whether or not the approval amount in the signature is for liquidity or uint(-1). * @param v The v component of the permit signature. * @param r The r component of the permit signature. * @param s The s component of the permit signature. * @custom:requirement There must be enough liquidity for both token amounts to be removed. * @return amountETH The amount of ETH received. */ function removeLiquidityETHWithPermitSupportingFeeOnTransferTokens( address token, uint256 liquidity, uint256 amountTokenMin, uint256 amountETHMin, address to, uint256 deadline, bool approveMax, uint8 v, bytes32 r, bytes32 s ) external returns (uint256 amountETH); /** * @notice See {ISomaSwapRouter-swapExactTokensForTokens} - Identical but succeeds for tokens that take a fee on transfer. * @param amountIn The amount of input tokens to send. * @param amountOutMin The minimum amount of output tokens that must be received for the transaction not to revert. * @param path The array of token addresses, where pools for each pair of addresses must exist and * have liquidity. * @param to The recipient of the underlying assets. * @param deadline The unix timestamp after which the transaction will revert. */ function swapExactTokensForTokensSupportingFeeOnTransferTokens( uint256 amountIn, uint256 amountOutMin, address[] calldata path, address to, uint256 deadline ) external; /** * @notice See {ISomaSwapRouter-swapExactETHForTokens} - Identical but succeeds for tokens that take a fee on transfer. * @param amountOutMin The minimum amount of output tokens that must be received for the transaction not to revert. * @param path The array of token addresses, where pools for each pair of addresses must exist and * have liquidity. * @param to The recipient of the output tokens. * @param deadline The unix timestamp after which the transaction will revert. * @custom:requirement The first element of `path` must be equal to the WETH address. * @custom:requirement The increase in balance of the last element of `path` for the `to` address must be greater than * or equal to `amountOutMin`. */ function swapExactETHForTokensSupportingFeeOnTransferTokens( uint256 amountOutMin, address[] calldata path, address to, uint256 deadline ) external payable; /** * @notice See {ISomaSwapRouter-swapExactTokensForETH} - Identical but succeeds for tokens that take a fee on transfer. * @param amountIn The amount of input tokens to send. * @param amountOutMin The minimum amount of output tokens that must be received for the transaction not to revert. * @param path The array of token addresses, where pools for each pair of addresses must exist and * have liquidity. * @param to The recipient of the output tokens. * @param deadline The unix timestamp after which the transaction will revert. * @custom:requirement The last element of `path` must be equal to the WETH address. * @custom:requirement The WETH balance of the router must be greater than or equal to `amountOutMin`. */ function swapExactTokensForETHSupportingFeeOnTransferTokens( uint256 amountIn, uint256 amountOutMin, address[] calldata path, address to, uint256 deadline ) external; }