# vRouter 1.3

## Events

#### Event RouterFactoryChanged

```solidity
event RouterFactoryChanged(
    address newFactoryAddress
);
```

Emitted when the Factory address is changed in [`changeFactory`](#function-changefactory) function.

## Read-only functions

#### function getAmountOut

```solidity
function getAmountOut(
    address tokenIn,
    address tokenOut,
    uint256 amountIn
) external view virtual override returns (uint256 amountOut)
```

Returns the amount that will be returned by swapping a given amount of tokenIn to tokenOut in the direct pool between the two tokens.

✏️ A native pool between tokenIn and tokenOut must exist in VirtuSwap. If it doesn't exist, the operation fails.

Parameters:

<table><thead><tr><th width="163.203007518797">Name</th><th width="148">Type</th><th>Description</th></tr></thead><tbody><tr><td>tokenIn</td><td>address</td><td>Address of the token to be sold (input token)</td></tr><tr><td>tokenOut</td><td>address</td><td>Address of the token to be bought (output token)</td></tr><tr><td>amountIn</td><td>uint256</td><td>Amount to be sold</td></tr></tbody></table>

#### function getAmountIn

```solidity
function getAmountIn(
    address tokenIn,
    address tokenOut,
    uint256 amountOut
) external view virtual override returns (uint256 amountIn)
```

Returns the amount of tokenIn that is required to be swapped to receive a given amount of tokenOut from the direct pool between the two tokens.&#x20;

✏️ A native pool between tokenIn and tokenOut must exist in VirtuSwap. If it doesn't exist, the operation fails.

Parameters:

<table><thead><tr><th width="163.203007518797">Name</th><th width="148">Type</th><th>Description</th></tr></thead><tbody><tr><td>tokenIn</td><td>address</td><td>Address of the token to be sold (input token)</td></tr><tr><td>tokenOut</td><td>address</td><td>Address of the token to be bought (output token)</td></tr><tr><td>amountOut</td><td>uint256</td><td>Amount to be bought</td></tr></tbody></table>

#### function getVirtualAmountOut

```solidity
function getVirtualAmountOut(
    address jkPair,
    address ikPair,
    uint256 amountIn
) public view override returns (uint256 amountOut) 
```

Returns the amount of output tokens that will be returned by swapping a given amount of input tokens in a Virtual Pool constructed from  given Active Pool and Reference Pool.

✏️ The identity of input and output tokens is determined automatically: the input token is the non-common token of the Reference Pool, and the output token is the non-common token of the Active Pool.  See [Virtual Pools ](https://docs.virtuswap.io/virtuswap-documentation/virtuswap-basics/virtuswap-technology)for more details.

Parameters:

<table><thead><tr><th width="163.203007518797">Name</th><th width="148">Type</th><th>Description</th></tr></thead><tbody><tr><td>jkPair</td><td>address</td><td>Address of the Active Pool</td></tr><tr><td>ikPair</td><td>address</td><td>Address of the Reference Pool</td></tr><tr><td>amountIn</td><td>uint256</td><td>Amount to be sold</td></tr></tbody></table>

#### function getVirtualAmountIn

```solidity
function getVirtualAmountIn(
        address jkPair,
        address ikPair,
        uint256 amountOut
    ) external view override returns (uint256 amountIn)
```

Returns the amount of input tokens required to receive a given amount of output tokens from the Virtual Pool constructed from  given Active Pool and Reference Pool.

✏️ The identity of input and output tokens is determined automatically: the input token is the non-common token of the Reference Pool, and the output token is the non-common token of the Active Pool. See [Virtual Pools ](https://docs.virtuswap.io/virtuswap-documentation/virtuswap-basics/virtuswap-technology)for more details.

Parameters:

<table><thead><tr><th width="163.203007518797">Name</th><th width="148">Type</th><th>Description</th></tr></thead><tbody><tr><td>jkPair</td><td>address</td><td>Address of the Active Pool</td></tr><tr><td>ikPair</td><td>address</td><td>Address of the Reference Pool</td></tr><tr><td>amountOut</td><td>uint256</td><td>Amount to be bought</td></tr></tbody></table>

#### function quote

```solidity
  function quote(
        address inputToken,
        address outputToken,
        uint256 amountIn
    ) external view override returns (uint256 amountOut)
```

Returns the *implied output amount* of output token in the direct pool between  input token and output token, given an amountIn. Essentially, the implied amount out is the the input amount multiplied by the ratio between the amounts of two assets in the pool. Implied amount out can be thought of as the output amount that would be received with infinite liquidity and without fees.

✏️ A native pool between tokenIn and tokenOut must exist in VirtuSwap. If it doesn't exist, the operation fails.

Parameters:

<table><thead><tr><th width="163.203007518797">Name</th><th width="148">Type</th><th>Description</th></tr></thead><tbody><tr><td>inputToken</td><td>address</td><td>Input token</td></tr><tr><td>outputToken</td><td>address</td><td>Output token</td></tr><tr><td>amountIn</td><td>uint256</td><td>amount to be sold</td></tr></tbody></table>

#### function getMaxVirtualTradeAmountRtoN

```solidity
function getMaxVirtualTradeAmountRtoN(
     address jkPair,
     address ikPair
) external view override returns (uint256 maxAmountIn) 
```

Returns the maximum amount of a reserve asset token that can be swapped for the native asset in a Virtual Pool created from a given Active and Reference Pools. The method takes into account the value of all reserves already present in the Active Pool and the Reserve Threshold of the Active Pool. See [Reserve Ratio and Threshold](https://docs.virtuswap.io/virtuswap-documentation/virtuswap-basics/virtuswap-technology/reserve-ratio-and-threshold) for more details.

✏️ The identity of the reserve and the native tokens to be swapped is determined automatically: the reserve token is the non-common token of the Reference Pool, and the native token is the non-common token of the Active Pool. See [Virtual Pools ](https://docs.virtuswap.io/virtuswap-documentation/virtuswap-basics/virtuswap-technology)for more details.

Parameters:

<table><thead><tr><th width="163.203007518797">Name</th><th width="148">Type</th><th>Description</th></tr></thead><tbody><tr><td>jkPair</td><td>address</td><td>Address of the Active Pool of the Virtual Pool</td></tr><tr><td>ikPair</td><td>address</td><td>Address of the Reference Pool of the Virtual Pool</td></tr></tbody></table>

#### function getVirtualPool

```solidity
function getVirtualPool(
        address jkPair, 
        address ikPair
) internal view returns (VirtualPoolModel memory vPool)
```

Returns a [`VirtualPoolModel`](https://docs.virtuswap.io/virtuswap-documentation/technical-reference/smart-contracts-v1/structures#virtualpoolmodel) structure reflecting the state of the virtual pool composed from the given Active Pool and Reference Pool.

✏️ Active Pool and the Reference Pool must have one asset in common. Also, Active Pool must accept the non-common token of Reference Pool as reserve. If either of those conditions is false, the operation fails.&#x20;

Parameters:

<table><thead><tr><th width="163.203007518797">Name</th><th width="148">Type</th><th>Description</th></tr></thead><tbody><tr><td>jkPair</td><td>address</td><td>Address of the Active Pool of the Virtual Pool</td></tr><tr><td>ikPair</td><td>address</td><td>Address of the Reference Pool of the Virtual Pool</td></tr></tbody></table>

#### function getVirtualPools

```solidity
function getVirtualPools(
    address token0,
    address token1
) external view returns (VirtualPoolModel[] memory vPools);
```

Returns an array of [`VirtualPoolModel`](https://docs.virtuswap.io/virtuswap-documentation/technical-reference/smart-contracts-v1/structures#virtualpoolmodel) instances representing all Virtual Pools that are available between two given tokens.&#x20;

See [How Virtual Pools Work](https://docs.virtuswap.io/virtuswap-documentation/virtuswap-basics/virtuswap-technology/how-virtual-pools-work) for details on how Virtual Pools are constructed.

Parameters:

<table><thead><tr><th width="163.203007518797">Name</th><th width="148">Type</th><th>Description</th></tr></thead><tbody><tr><td>token0</td><td>address</td><td>First token</td></tr><tr><td>token1</td><td>address</td><td>Second token</td></tr></tbody></table>

#### function factory

```solidity
function factory() 
    external view 
returns (address);
```

Returns the [`vPairFactory`](https://docs.virtuswap.io/virtuswap-documentation/technical-reference/smart-contracts-v1/dex-contracts/vpairfactory) instance.

#### function WETH9

```solidity
function WETH9() external view returns (address);
```

Returns the canonical address of the network's native currency (ETH for Ethereum mainnet, MATIC for Polygon PoS, etc.)

The WETH9 address is passed by the creator to the constructor of the vRouter instance.

## Swap Functions

#### function multiSwapExactETHForTokens

```solidity
function multiSwapExactETHForTokens(
    uint256 deadline,
    RouteData[] calldata routeData,
    address[] calldata transitTokens,
    address tokenOut,
    address to,
    uint256 minAmountOut
) external payable;
```

Receive a maximum amount of output token for a given amount of [`WETH9`](#function-weth9) following a given swap path provided in the `routeData` array of route steps. The `transitTokens` array of token addresses determines the list of pools between those tokens. The `tokenOut` is the output token.

The function uses the [`swapNative`](https://docs.virtuswap.io/virtuswap-documentation/technical-reference/smart-contracts-v1/vpair#function-swapnative) and [`swapReserveToNative`](https://docs.virtuswap.io/virtuswap-documentation/technical-reference/smart-contracts-v1/vpair#function-swapreservetonative) methods of the relevant [`vPair`](https://docs.virtuswap.io/virtuswap-documentation/technical-reference/smart-contracts-v1/dex-contracts/vpair) instances.

If the resulting output amount is lower than `minAmountOut`, the operation fails.

Parameters:

<table><thead><tr><th width="205.203007518797">Name</th><th width="148">Type</th><th>Description</th></tr></thead><tbody><tr><td>deadline</td><td>uint256</td><td>The deadline for the trade to happen. If the trade is executed after the deadline timestamp, it will be reverted.</td></tr><tr><td>routeData</td><td><a href="../user-defined-value-types#routedata">RouteData</a>[] calldata</td><td>List of compact information about trading routes</td></tr><tr><td>transitTokens</td><td>address[] calldata</td><td>List of addresses of transit tokens that define vPair instances to be used to perform the swap</td></tr><tr><td>tokenOut</td><td>address</td><td>The output token</td></tr><tr><td>to</td><td>address</td><td>Address to receive the bought tokens</td></tr><tr><td>minAmountOut</td><td>uint256</td><td>Minimum amount of <code>tokenOut</code> to be received</td></tr></tbody></table>

#### function multiSwapExactTokensForETH

```solidity
function multiSwapExactTokensForETH(
    uint256 deadline,
    RouteData[] calldata routeData,
    address[] calldata transitTokens,
    address tokenIn,
    address to,
    uint256 minAmountOut
) external;
```

Receive a maximum amount of [`WETH9`](#function-weth9) for a given amount of input token following a given swap path provided in the `routeData` array of route steps. The `transitTokens` array of token addresses determines the list of pools between those tokens. The `tokenIn` is the input token.

The function uses the [`swapNative`](https://docs.virtuswap.io/virtuswap-documentation/technical-reference/smart-contracts-v1/vpair#function-swapnative) and [`swapReserveToNative`](https://docs.virtuswap.io/virtuswap-documentation/technical-reference/smart-contracts-v1/vpair#function-swapreservetonative) methods of the relevant [`vPair`](https://docs.virtuswap.io/virtuswap-documentation/technical-reference/smart-contracts-v1/dex-contracts/vpair) instances.

If the resulting output amount is lower than `minAmountOut`, the operation fails.

Parameters:

<table><thead><tr><th width="205.203007518797">Name</th><th width="148">Type</th><th>Description</th></tr></thead><tbody><tr><td>deadline</td><td>uint256</td><td>The deadline for the trade to happen. If the trade is executed after the deadline timestamp, it will be reverted.</td></tr><tr><td>routeData</td><td><a href="../user-defined-value-types#routedata">RouteData</a>[] calldata</td><td>List of compact information about trading routes</td></tr><tr><td>transitTokens</td><td>address[] calldata</td><td>List of addresses of transit tokens that define vPair instances to be used to perform the swap</td></tr><tr><td>tokenIn</td><td>address</td><td>The input token</td></tr><tr><td>to</td><td>address</td><td>Address to receive the bought tokens</td></tr><tr><td>minAmountOut</td><td>uint256</td><td>Minimum amount of ETH to be received</td></tr></tbody></table>

#### function multiSwapETHForExactTokens

```solidity
function multiSwapETHForExactTokens(
    uint256 deadline,
    RouteData[] calldata routeData,
    address[] calldata transitTokens,
    address tokenOut,
    address to,
    uint256 maxAmountIn
) external payable;
```

Receive an exact amount of output token for as few [`WETH9`](#function-weth9) as possible, following a given swap path provided in the `routeData` array of route steps. The `transitTokens` array of token addresses determines the list of pools between those tokens. The `tokenOut` is the output token.

The function uses the [`swapNative`](https://docs.virtuswap.io/virtuswap-documentation/technical-reference/smart-contracts-v1/vpair#function-swapnative) and [`swapReserveToNative`](https://docs.virtuswap.io/virtuswap-documentation/technical-reference/smart-contracts-v1/vpair#function-swapreservetonative) methods of the relevant [`vPair`](https://docs.virtuswap.io/virtuswap-documentation/technical-reference/smart-contracts-v1/dex-contracts/vpair) instances.

If the amount of ETH required to receive the `amountOut` is greater than `maxAmountIn`, the operation fails.

Parameters:

<table><thead><tr><th width="205.203007518797">Name</th><th width="148">Type</th><th>Description</th></tr></thead><tbody><tr><td>deadline</td><td>uint256</td><td>The deadline for the trade to happen. If the trade is executed after the deadline timestamp, it will be reverted.</td></tr><tr><td>routeData</td><td><a href="../user-defined-value-types#routedata">RouteData</a>[] calldata</td><td>List of compact information about trading routes</td></tr><tr><td>transitTokens</td><td>address[] calldata</td><td>List of addresses of transit tokens that define vPair instances to be used to perform the swap</td></tr><tr><td>tokenOut</td><td>address</td><td>The output token</td></tr><tr><td>to</td><td>address</td><td>Address to receive the bought tokens</td></tr><tr><td>maxAmountIn</td><td>uint256</td><td>Maximum amount of ETH to be spent</td></tr></tbody></table>

#### function multiSwapTokensForExactETH

```solidity
function multiSwapTokensForExactETH(
    uint256 deadline,
    RouteData[] calldata routeData,
    address[] calldata transitTokens,
    address tokenIn,
    address to,
    uint256 maxAmountIn
) external;
```

Receive an exact amount of [`WETH9`](#function-weth9) for as few input tokens as possible, following a given swap path provided in the `routeData` array of route steps. The `transitTokens` array of token addresses determines the list of pools between those tokens. The `tokenIn` is the input token.

The function uses the [`swapNative`](https://docs.virtuswap.io/virtuswap-documentation/technical-reference/smart-contracts-v1/vpair#function-swapnative) and [`swapReserveToNative`](https://docs.virtuswap.io/virtuswap-documentation/technical-reference/smart-contracts-v1/vpair#function-swapreservetonative) methods of the relevant [`vPair`](https://docs.virtuswap.io/virtuswap-documentation/technical-reference/smart-contracts-v1/dex-contracts/vpair) instances.

If the amount of token required to receive the `amountOut` [`WETH9`](#function-weth9) is greater than `maxAmountIn`, the operation fails.

Parameters:

<table><thead><tr><th width="205.203007518797">Name</th><th width="148">Type</th><th>Description</th></tr></thead><tbody><tr><td>deadline</td><td>uint256</td><td>The deadline for the trade to happen. If the trade is executed after the deadline timestamp, it will be reverted.</td></tr><tr><td>routeData</td><td><a href="../user-defined-value-types#routedata">RouteData</a>[] calldata</td><td>List of compact information about trading routes</td></tr><tr><td>transitTokens</td><td>address[] calldata</td><td>List of addresses of transit tokens that define vPair instances to be used to perform the swap</td></tr><tr><td>tokenIn</td><td>address</td><td>The input token</td></tr><tr><td>to</td><td>address</td><td>Address to receive the bought tokens</td></tr><tr><td>maxAmountIn</td><td>uint256</td><td>Maximum amount of <code>tokenIn</code> to be spent</td></tr></tbody></table>

#### function multiSwapTokensForExactTokens

```solidity
function multiSwapTokensForExactTokens(
    uint256 deadline,
    RouteData[] calldata routeData,
    address[] calldata transitTokens,
    address tokenIn,
    address tokenOut,
    address to,
    uint256 maxAmountIn
) external;
```

Receive a given `amountOut` of the output token for as few input tokens as possible performing a series of  swaps along the route determined by the `routeData` array of route steps. The `transitTokens` is an array of token addresses that determines the list of pools between those tokens (note: in VirtuSwap there is always one pool connecting two tokens). The `tokenIn` is the input token and the `tokenOut` in the output token.

The function uses the [`swapNative`](https://docs.virtuswap.io/virtuswap-documentation/technical-reference/smart-contracts-v1/vpair#function-swapnative) and [`swapReserveToNative`](https://docs.virtuswap.io/virtuswap-documentation/technical-reference/smart-contracts-v1/vpair#function-swapreservetonative) methods of the relevant [`vPair`](https://docs.virtuswap.io/virtuswap-documentation/technical-reference/smart-contracts-v1/dex-contracts/vpair) instances.

If the amount of sold token required to receive the `amountOut` is greater than `maxAmountIn`, the operation fails.

Parameters:

<table><thead><tr><th width="205.203007518797">Name</th><th width="148">Type</th><th>Description</th></tr></thead><tbody><tr><td>deadline</td><td>uint256</td><td>The deadline for the trade to happen. If the trade is executed after the deadline timestamp, it will be reverted.</td></tr><tr><td>routeData</td><td><a href="../user-defined-value-types#routedata">RouteData</a>[] calldata</td><td>List of compact information about trading routes</td></tr><tr><td>transitTokens</td><td>address[] calldata</td><td>List of addresses of transit tokens that define vPair instances to be used to perform the swap</td></tr><tr><td>tokenIn</td><td>address</td><td>The input token</td></tr><tr><td>tokenOut</td><td>address</td><td>The output token</td></tr><tr><td>to</td><td>address</td><td>Address to receive the bought tokens</td></tr><tr><td>maxAmountIn</td><td>uint256</td><td>Maximum amount of <code>tokenIn</code> to be spent</td></tr></tbody></table>

#### function multiSwapExactTokensForTokens

```solidity
function multiSwapExactTokensForTokens(
    uint256 deadline,
    RouteData[] calldata routeData,
    address[] calldata transitTokens,
    address tokenIn,
    address tokenOut,
    address to,
    uint256 minAmountOut
) external;
```

Swaps an exact amount input token for as many output tokens as possible, along the route determined by the `routeData` array of route steps. The `transitTokens` is an array of token addresses that determines the list of pools between those tokens (note: in VirtuSwap there is always one pool connecting two tokens). The `tokenIn` is the input token and the `tokenOut` in the output token.

The function uses the [`swapNative`](https://docs.virtuswap.io/virtuswap-documentation/technical-reference/smart-contracts-v1/vpair#function-swapnative) and [`swapReserveToNative`](https://docs.virtuswap.io/virtuswap-documentation/technical-reference/smart-contracts-v1/vpair#function-swapreservetonative) methods of the relevant [`vPair`](https://docs.virtuswap.io/virtuswap-documentation/technical-reference/smart-contracts-v1/dex-contracts/vpair) instances.

If the amount of received token is lower than `minAmountOut`, the operation fails.

Parameters:

<table><thead><tr><th width="205.203007518797">Name</th><th width="148">Type</th><th>Description</th></tr></thead><tbody><tr><td>deadline</td><td>uint256</td><td>The deadline for the trade to happen. If the trade is executed after the deadline timestamp, it will be reverted.</td></tr><tr><td>routeData</td><td><a href="../user-defined-value-types#routedata">RouteData</a>[] calldata</td><td>List of compact information about trading routes</td></tr><tr><td>transitTokens</td><td>address[] calldata</td><td>List of addresses of transit tokens that define vPair instances to be used to perform the swap</td></tr><tr><td>tokenIn</td><td>address</td><td>The input token</td></tr><tr><td>tokenOut</td><td>address</td><td>The output token</td></tr><tr><td>to</td><td>address</td><td>Address to receive the bought tokens</td></tr><tr><td>minAmountOut</td><td>uint256</td><td>Minimum amount of <code>tokenOut</code> to be received</td></tr></tbody></table>

#### function vFlashSwapCallback

```solidity
function vFlashSwapCallback( 
        address tokenIn, 
        address tokenOut, 
        uint256 requiredBackAmount, 
        bytes calldata data 
) external override
```

A callback method called by a [`vPair`](https://docs.virtuswap.io/virtuswap-documentation/technical-reference/smart-contracts-v1/dex-contracts/vpair) instance to request transfer of the necessary amount of  input tokens to perform the swap. The call is performed from vPair's [`swapReserveToNative`](https://docs.virtuswap.io/virtuswap-documentation/technical-reference/smart-contracts-v1/vpair#function-swapreservetonative) method after it is called from `vRouter`'s `trySwapReserveExactIn` or `trySwapReserveExactOut` methods. `vFlashSwapCallback` checks that the sender is the expected `vPair` and performs the transfer to the `vPair` instance.

Parameters:

<table><thead><tr><th width="231.203007518797">Name</th><th width="116">Type</th><th>Description</th></tr></thead><tbody><tr><td>tokenIn</td><td>address</td><td>Address of the token being sold in the swap</td></tr><tr><td>tokenOut</td><td>address</td><td>Address of the token being bought in the swap</td></tr><tr><td>requiredBackAmount</td><td>uint256</td><td>Amount of tokens requested to transfer to vPair</td></tr><tr><td>calldata</td><td>bytes</td><td><p>Encoded call data</p><pre class="language-solidity"><code class="lang-solidity">struct PoolCallbackData {
    address from; // token sender
    address poolToken; // token to recover and verify the pair address
}
</code></pre></td></tr></tbody></table>

## Liquidity provision functions

#### function addLiquidity

```solidity
    function addLiquidity(
        address tokenA,
        address tokenB,
        uint256 amountADesired,
        uint256 amountBDesired,
        uint256 amountAMin,
        uint256 amountBMin,
        address to,
        uint256 deadline
    ) external override notAfter(deadline)
        returns (
            uint256 amountA,
            uint256 amountB,
            address pairAddress,
            uint256 liquidity
        )
```

Adds liquidity to a pool, according to the current ratio between the two assets in the pool.&#x20;

Prior to the call, the sender must give the router  allowance of at least amountADesired and amountBDesired of tokenA and tokenB respectively. The functions adds assets according to the ratio between the two sides at the moment the function is called.&#x20;

The function calls the [`mint`](https://docs.virtuswap.io/virtuswap-documentation/technical-reference/smart-contracts-v1/vpair#function-mint) function of the underlying [`vPair`](https://docs.virtuswap.io/virtuswap-documentation/technical-reference/smart-contracts-v1/dex-contracts/vpair) instance.

✏️ The actual amount to be deposited is calculated according to the ratio between the tokens at the time of the actual transaction, and thus may not be equal to the desired amounts. If the calculated amounts in one of the tokens is lower than the respective minimum amount, the transaction fails.

✏️ If the pair between TokenA and TokenB does not exist, it will be created.

Parameters:

<table><thead><tr><th width="177.203007518797">Name</th><th width="116">Type</th><th>Description</th></tr></thead><tbody><tr><td>tokenA</td><td>address</td><td>Address of the first token in the pair</td></tr><tr><td>tokenB</td><td>address</td><td>Address of the second token in the pair</td></tr><tr><td>amountADesired</td><td>uint256</td><td>Amount of token A the caller wishes to deposit to the pool</td></tr><tr><td>amountBDesired</td><td>uint256</td><td>Amount of token A the caller wishes to deposit to the pool</td></tr><tr><td>amountAMin</td><td>uint256</td><td>Minimum amount of token A the caller is willing to deposit in the pool. </td></tr><tr><td>amountBMin</td><td>address</td><td>Minimum amount of token B the caller is willing to deposit in the pool.</td></tr><tr><td>to</td><td>address</td><td>address to receive the LP tokens</td></tr><tr><td>deadline</td><td>uint256</td><td>The deadline for the operation to happen. </td></tr></tbody></table>

Returns:

<table><thead><tr><th width="143.203007518797">Name</th><th width="116">Type</th><th>Description</th></tr></thead><tbody><tr><td>amountA</td><td>uint256</td><td>Amount of tokenA that was actually deposited to the pool</td></tr><tr><td>amountB</td><td>uint256</td><td>Amount of tokenB that was actually deposited to the pool</td></tr><tr><td>pairAddress</td><td>address</td><td>Address of the pool </td></tr><tr><td>liquidity</td><td>uint256</td><td>Product of balances of the two tokens in the pool (K)</td></tr></tbody></table>

#### function removeLiquidity

```solidity
function removeLiquidity(
        address tokenA,
        address tokenB,
        uint256 liquidity,
        uint256 amountAMin,
        uint256 amountBMin,
        address to,
        uint256 deadline
    )   external override notAfter(deadline)
        returns (
                uint256 amountA, 
                uint256 amountB
        )
```

Removes liquidity from a, according to the current ratio between the two assets in the pool.&#x20;

Prior to the call, the sender must give the router allowance of the amount of LP Tokens they wish to redeem

The function calls the [`burn`](https://docs.virtuswap.io/virtuswap-documentation/technical-reference/smart-contracts-v1/vpair#function-burn) function of the underlying [`vPair`](https://docs.virtuswap.io/virtuswap-documentation/technical-reference/smart-contracts-v1/dex-contracts/vpair) instance.

✏️ The actual amount to be removed is calculated according to the ratio between the tokens at the time of the actual transaction. If the calculated amounts in one of the tokens is lower than the respective minimum amount, the transaction fails.

✏️ A pair between TokenA and TokenB must exist.

Parameters:

<table><thead><tr><th width="148.203007518797">Name</th><th width="116">Type</th><th>Description</th></tr></thead><tbody><tr><td>tokenA</td><td>address</td><td>Address of the first token in the pair</td></tr><tr><td>tokenB</td><td>address</td><td>Address of the second token in the pair</td></tr><tr><td>liquidity</td><td>uint256</td><td>Number of LP tokens to be redeemed</td></tr><tr><td>amountAMin</td><td>uint256</td><td>Minimum amount of token A the caller is willing to get.</td></tr><tr><td>amountBMin</td><td>address</td><td>Minimum amount of token B the caller is willing to get.</td></tr><tr><td>to</td><td>address</td><td>address to receive the  tokens</td></tr><tr><td>deadline</td><td>uint256</td><td>The deadline for the operation to happen. </td></tr></tbody></table>

Returns:

<table><thead><tr><th width="139.203007518797">Name</th><th width="116">Type</th><th>Description</th></tr></thead><tbody><tr><td>amountA</td><td>uint256</td><td>Amount of tokenA that was actually removed from the pool</td></tr><tr><td>amountB</td><td>uint256</td><td>Amount of tokenB that was actually removed from the pool</td></tr></tbody></table>

## State-changing Functions

#### function changeFactory

```solidity
function changeFactory(
    address _factory
) external override onlyOwner
```

Changes the address of the PairFactory contract instance. The [PairFactory](https://docs.virtuswap.io/virtuswap-documentation/technical-reference/smart-contracts-v1/dex-contracts/vpairfactory) is responsible for creating and keeping the information on [Pair](https://docs.virtuswap.io/virtuswap-documentation/technical-reference/smart-contracts-v1/dex-contracts/vpair) instances.

✏️Can only be called by the owner of the Router contract.
