MESHswapRouter
The swap router supports all the basic requirements of a front-end offering trading. The functions supported by default can be checked in the table below.
Address
Polygon Mainnet : 0x10f4a785f458bc144e3706575924889954946639
Events, Read-Only Functions, and State-Changing Functions
Events
ExchangePos
event ExchangePos(address token0, uint amount0, address token1, uint amount1);
Positive exchange Event
parameters
token0
: User input token0 addressamount0
: User input token0 amounttoken1
: User get token1 addressamount1
: User get token1 amount
ExchangeNeg
event ExchangeNeg(address token0, uint amount0, address token1, uint amount1);
Negative exchange Event
parameters
token0
: User input token0 addressamount0
: User input token0 amounttoken1
: User get token1 addressamount1
: User get token1 amount
Read-Only Functions
factory
Factory Contract Address
WETH
WETH Contract Address
quote
function quote(uint amount0, uint reserve0, uint reserve1) internal pure returns (uint amount1);
Given some asset amount and reserves, returns an amount of the other asset representing equivalent value.
getAmountIn
function getAmountIn(uint amountOut, uint reserveIn, uint reserveOut) internal pure returns (uint amountIn);
Returns the minimum input asset amount required to buy the given output asset amount (accounting for fees) given reserves.
getAmountOut
function getAmountOut(uint amountIn, uint reserveIn, uint reserveOut) internal pure returns (uint amountOut);
Given an input asset amount, returns the maximum output amount of the other asset (accounting for fees) given reserves.
getAmountsIn
function getAmountsIn(address factory, uint amountOut, address[] memory path) internal view returns (uint[] memory amounts);
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.
getAmountsOut
function getAmountsOut(uint amountIn, address[] memory path) internal view returns (uint[] memory amounts);
Given an input asset amount and an array of token addresses, calculates all subsequent maximum output token amounts by calling getReserves for each pair of token addresses in the path in turn, and using these to call getAmountOut.
State-Changing Functions
addLiquidity
function addLiquidity(
address token0,
address token1,
uint amount0Desired,
uint amount1Desired,
uint amount0Min,
uint amount1Min,
address to,
uint deadline
) external returns (uint amountA, uint amountB, uint liquidity);
Adds liquidity to an ERC-20 / ERC-20 pool.
To cover all possible scenarios,
msg.sender
should have already given the router an allowance of at least amount0Desired/amount1Desired on token0/token1.Always adds assets at the ideal ratio, according to the price when the transaction is executed.
If a pool for the passed tokens does not exists, one is created automatically, and exactly amount0Desired/amount1Desired tokens are added.
Parameters
token0
: A pool token.token1
: A pool token.amount0Desired
: The amount of token0 to add as liquidity if the token1/token0 price is <= amount1Desired/amount0Desired .amount1Desired
: : The amount of tokenB to add as liquidity if the token0/token1 price is <= amountADesired/amountBDesired .amount0Min
: Bounds the extent to which the B/A price can go up before the transaction reverts. Must be <= amount0Desired.amount1Min
: Bounds the extent to which the A/B price can go up before the transaction reverts. Must be <= amount1Desired.to
: Recipient of the liquidity tokens.deadline
: Unix timestamp after which the transaction will revert.amount0
: The amount of token0 sent to the pool.amount1
: The amount of token1 sent to the pool.liquidity
: The amount of liquidity tokens minted.
addLiquidityETH
function addLiquidityETH(
address token,
uint amountTokenDesired,
uint amountTokenMin,
uint amountETHMin,
address to,
uint deadline
) external payable returns (uint amountToken, uint amountETH, uint liquidity);
Adds liquidity to an ERC-20 / WETH pool with ETH.
To cover all possible scenarios,
msg.sender
should have already given the router an allowance of at least amountTokenDesired on token.Always adds assets at the ideal ratio, according to the price when the transaction is executed.
msg.value
is treated as a amountETHDesired.Leftover ETH, if any, is returned to
msg.sender
.If a pool for the passed token and WETH does not exists, one is created automatically, and exactly amountTokenDesired/
msg.value
tokens are added.Parameters
token
: A pool token.amountTokenDesired
: The amount of token to add as liquidity if the WETH/token price is <=msg.value
/amountTokenDesired.amountETHDesired
: : The amount of ETH to add as liquidity if the token/WETH price is <= amountTokenDesired/msg.value
.amountTokenMin
: Bounds the extent to which the WETH/token price can go up before the transaction reverts. Must be <= amountTokenDesired.amountETHMin
: Bounds the extent to which the token/WETH price can go up before the transaction reverts. Must be <=msg.value
.to
: Recipient of the liquidity tokens.deadline
: Unix timestamp after which the transaction will revert.amountToken
: The amount of token sent to the pool.amountETH
: The amount of ETH converted to WETH and sent to the pool.liquidity
: The amount of liquidity tokens minted.
removeLiquidity
function removeLiquidity(
address token0,
address token1,
uint liquidity,
uint amount0Min,
uint amount1Min,
address to,
uint deadline
) external returns (uint amount0, uint amount1);
Removes liquidity from an ERC-20 / ERC-20 pool.
msg.sender
should have already given the router an allowance of at least liquidity on the pool.Parameters
token0
: A pool token.token1
: A pool token.liquidity
: The amount of liquidity tokens to remove.amount0Min
: The minimum amount of tokenA that must be received for the transaction not to revert..amount1Min
: The minimum amount of tokenB that must be received for the transaction not to revert.to
: Recipient of the underlying assets.deadline
: Unix timestamp after which the transaction will revert.amount0
: The amount of token0 received.amount1
: The amount of token1 received.
removeLiquidityETH
function removeLiquidityETH(
address token,
uint liquidity,
uint amountTokenMin,
uint amountETHMin,
address to,
uint deadline
) external returns (uint amountToken, uint amountETH);
Removes liquidity from an ERC-20 / WETH pool and receive ETH.
msg.sender
should have already given the router an allowance of at least liquidity on the pool.Parameters
token
: A pool token.liquidity
: The amount of liquidity tokens to remove.amountTokenMin
: The minimum amount of token that must be received for the transaction not to revert.amountETHMin
: The minimum amount of ETH that must be received for the transaction not to revert.to
: Recipient of the underlying assets.deadline
: Unix timestamp after which the transaction will revert.amount0
: The amount of token received.amount1
: The amount of ETH received.
removeLiquidityWithPermit
function removeLiquidityWithPermit(
address token0,
address token1,
uint liquidity,
uint amountAMin,
uint amountBMin,
address to,
uint deadline,
bool approveMax, uint8 v, bytes32 r, bytes32 s
) external returns (uint amount0, uint amount1);
Removes liquidity from an ERC-20 / ERC-20 pool without pre-approval
Parameters
token0
: A pool token.token1
: A pool token.liquidity
: The amount of liquidity tokens to remove.amount0Min
: The minimum amount of token0 that must be received for the transaction not to revert.amount1Min
: The minimum amount of token1 that must be received for the transaction not to revert.to
: Recipient of the underlying assets.deadline
: Unix timestamp after which the transaction will revert.approveMax
: Whether or not the approval amount in the signature is for liquidity or uint(-1).v
: The v component of the permit signature.r
: The r component of the permit signature.s
: The s component of the permit signature.amount0
: The amount of token0 received.amount1
: The amount of token1 received.
removeLiquidityETHWithPermit
function removeLiquidityWithPermit(
address token0,
address token1,
uint liquidity,
uint amount0Min,
uint amount1Min,
address to,
uint deadline,
bool approveMax, uint8 v, bytes32 r, bytes32 s
) external returns (uint amount0, uint amount1);
Removes liquidity from an ERC-20 / WETTH pool and receive ETH without pre-approva
Parameters
token
: A pool token.liquidity
: The amount of liquidity tokens to remove.amountTokenMin
: The minimum amount of token that must be received for the transaction not to revert.amountETHMin
: The minimum amount of ETH that must be received for the transaction not to revert.to
: Recipient of the underlying assets.deadline
: Unix timestamp after which the transaction will revert.approveMax
: Whether or not the approval amount in the signature is for liquidity or uint(-1).v
: The v component of the permit signature.r
: The r component of the permit signature.s
: The s component of the permit signature.amountToken
: The amount of token received.amountETH
: The amount of ETH received.
swapExactTokensForTokens
function swapExactTokensForTokens(
uint amountIn,
uint amountOutMin,
address[] calldata path,
address to,
uint deadline
) external returns (uint[] memory amounts);
Swaps an exact amount of input tokens for as many output tokens as possible, along the route determined by the path. The first element of path is the input token, the last is the output token, and any intermediate elements represent intermediate pairs to trade through (if, for example, a direct pair does not exist).
msg.sender
should have already given the router an allowance of at least amountIn on the input token.Parameters
amountIn
: The amount of input tokens to send.amountOutMin
: The minimum amount of output tokens that must be received for the transaction not to revert.path
: An array of token addresses. path.length must be >= 2. Pools for each consecutive pair of addresses must exist and have liquidity.to
: Recipient of the output tokens.deadline
: Unix timestamp after which the transaction will revert.amounts
: The input token amount and all subsequent output token amounts.
swapTokensForExactTokens
function swapTokensForExactTokens(
uint amountOut,
uint amountInMax,
address[] calldata path,
address to,
uint deadline
) external returns (uint[] memory amounts);
Receive an exact amount of output tokens for as few input tokens as possible, along the route determined by the path. The first element of path is the input token, the last is the output token, and any intermediate elements represent intermediate pairs to trade through (if, for example, a direct pair does not exist).
msg.sender
should have already given the router an allowance of at least amountInMax on the input token.Parameters
amountOut
: The amount of output tokens to send.amountInMax
: The maximum amount of input tokens that can be required before the transaction reverts.path
: An array of token addresses.path.length
must be >= 2. Pools for each consecutive pair of addresses must exist and have liquidity.to
: Recipient of the output tokens.deadline
: Unix timestamp after which the transaction will revert.amounts
: The input token amount and all subsequent output token amounts.
swapExactETHForTokens
function swapExactETHForTokens(uint amountOutMin, address[] calldata path, address to, uint deadline)
external
payable
returns (uint[] memory amounts);
Swaps an exact amount of ETH for as many output tokens as possible, along the route determined by the path. The first element of path must be WETH, the last is the output token, and any intermediate elements represent intermediate pairs to trade through (if, for example, a direct pair does not exist).
Parameters
amountIn
: The amount of ETH to send.amountOutMin
: The minimum amount of output tokens that must be received for the transaction not to revert.path
: An array of token addresses.path.length
must be >= 2. Pools for each consecutive pair of addresses must exist and have liquidity.to
: Recipient of the output tokens.deadline
: Unix timestamp after which the transaction will revert.amounts
: The input token amount and all subsequent output token amounts.
swapTokensForExactETH
function swapTokensForExactETH(uint amountOut, uint amountInMax, address[] calldata path, address to, uint deadline)
external
returns (uint[] memory amounts);
Receive an exact amount of ETH for as few input tokens as possible, along the route determined by the path. The first element of path is the input token, the last must be WETH, and any intermediate elements represent intermediate pairs to trade through (if, for example, a direct pair does not exist).
msg.sender
should have already given the router an allowance of at least amountInMax on the input token.If the to address is a smart contract, it must have the ability to receive ETH.
Parameters
amountOut
: The amount of output ETH to send.amountInMax
: The maximum amount of input tokens that can be required before the transaction reverts.path
: An array of token addresses.path.length
must be >= 2. Pools for each consecutive pair of addresses must exist and have liquidity.to
: Recipient of the ETH.deadline
: Unix timestamp after which the transaction will revert.amounts
: The input token amount and all subsequent output token amounts.
swapExactTokensForETH
function swapExactTokensForETH(uint amountIn, uint amountOutMin, address[] calldata path, address to, uint deadline)
external
returns (uint[] memory amounts);
Swaps an exact amount of tokens for as much ETH as possible, along the route determined by the path. The first element of path is the input token, the last must be WETH, and any intermediate elements represent intermediate pairs to trade through (if, for example, a direct pair does not exist).
If the to address is a smart contract, it must have the ability to receive ETH.
Parameters
amountIn
: The amount of tokens to send.amountOutMin
: The minimum amount of output tokens that must be received for the transaction not to revert.path
: An array of token addresses.path.length
must be >= 2. Pools for each consecutive pair of addresses must exist and have liquidity.to
: Recipient of the output ETH.deadline
: Unix timestamp after which the transaction will revert.amounts
: The input token amount and all subsequent output token amounts.
swapETHForExactTokens
function swapETHForExactTokens(uint amountOut, address[] calldata path, address to, uint deadline)
external
payable
returns (uint[] memory amounts);
Receive an exact amount of tokens for as little ETH as possible, along the route determined by the path. The first element of path must be WETH, the last is the output token and any intermediate elements represent intermediate pairs to trade through (if, for example, a direct pair does not exist).
Leftover ETH, if any, is returned to
msg.sender
.Parameters
amountOut
: The amount of tokens to receive.amountInMax
: The maximum amount of ETH that can be required before the transaction reverts.path
: An array of token addresses.path.length
must be >= 2. Pools for each consecutive pair of addresses must exist and have liquidity.to
: Recipient of the output tokens.deadline
: Unix timestamp after which the transaction will revert.amounts
: The input token amount and all subsequent output token amounts.
claimReward
function claimReward(address pair, uint deadline) external
Method that a user calls to claim the claimable MESH that has accumulated for the pair
When called, MESH is claimed from the Factory contract and paid to
msg.sender
Parameters
pair
: Pairs that paid liquidity.deadline
: Unix timestamp after which the transaction will revert.
claimReward
function claimReward(address token0, address token1, uint deadline) external
Method that a user calls to claim the claimable MESH that has accumulated for the pair
When called, MESH is claimed from the Factory contract and paid to
msg.sender
Parameters
token0
: token0 address of pairs that paid liquidity.token1
: token1 address of pairs that paid liquidity.deadline
: Unix timestamp after which the transaction will revert.
Last updated