# Router

The Router smart contract serves as the primary interface for interacting with the PumpSpace decentralized exchange. It handles token swaps, adding/removing liquidity, and routing logic through the Factory and Pair contracts.

## **Address**

[0xE8A55f6b4EE94D2DBe02e724bC23228E15a59946](https://subnets.avax.network/c-chain/address/0xE8A55f6b4EE94D2DBe02e724bC23228E15a59946?tab=code)

{% hint style="info" %}
📝 The contract is verified on [Avalanche C-Chain Explorer](https://subnets.avax.network/c-chain/address/0xE8A55f6b4EE94D2DBe02e724bC23228E15a59946?tab=code), and its source code can be publicly viewed there.
{% endhint %}

***

## Functions

#### addLiquidity

Adds liquidity to a token pair pool. If the pool does not exist, it is created via the Factory.

```solidity
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);
```

#### addLiquidityETH

Adds liquidity to a token-ETH pool. If the pool doesn't exist, it is created via the Factory.

```solidity
function addLiquidityETH(
        address token,
        uint256 amountTokenDesired,
        uint256 amountTokenMin,
        uint256 amountETHMin,
        address to,
        uint256 deadline
) external payable returns (uint256 amountToken, uint256 amountETH,uint256 liquidity);
```

#### removeLiquidity

Removes liquidity from a token pair pool, returning the underlying tokens.

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

#### removeLiquidityETH

Removes liquidity from a token-ETH pool, returning both token and ETH to the user.

```solidity
function removeLiquidityETH(
        address token,
        uint256 liquidity,
        uint256 amountTokenMin,
        uint256 amountETHMin,
        address to,
        uint256 deadline
) external returns (uint256 amountToken, uint256 amountETH);

```

***

#### swapExactTokensForTokens

Swaps an exact amount of tokens for another token through one or more pools.

```solidity
function swapExactTokensForTokens(
        uint256 amountIn,
        uint256 amountOutMin,
        address[] calldata path,
        address to,
        uint256 deadline
) external returns (uint256[] memory amounts);
```

#### swapExactETHForTokens

Swaps an exact amount of ETH for as many output tokens as possible.

```solidity
function swapExactETHForTokens(
    uint256 amountOutMin,
    address[] calldata path,
    address to,
    uint256 deadline
) external payable returns (uint256[] memory amounts);
```

#### swapExactTokensForETH

Swaps **an exact amount of tokens** for as much ETH as possible.

```solidity
function swapExactTokensForETH(
    uint256 amountIn,
    uint256 amountOutMin,
    address[] calldata path,
    address to,
    uint256 deadline
) external returns (uint256[] memory amounts);
```

***

#### getAmountsOut

Given an input amount and token path, returns the expected output amounts at each swap step.

```solidity
function getAmountsOut(
        uint256 amountIn, 
        address[] calldata path
) external view returns (uint256[] memory amounts);
```

#### getAmountsIn

Given a desired output amount and token path, returns the required input amounts at each swap step.

```solidity
function getAmountsIn(
        uint256 amountOut,
        address[] calldata path 
) external view returns (uint256[] memory amounts); 
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://pumpspace.gitbook.io/docs/en/contract/router.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
