# Router

## Module info

* **Name**: <mark style="color:green;">`evo::router`</mark>
* **Description**: This module contains public functions for other modules/contracts to call and interact with the <mark style="color:green;">`evo`</mark> contract.

## Public Functions <a href="#public-functions" id="public-functions"></a>

### Create Pool <a href="#create-pool" id="create-pool"></a>

**Create pool with two fungible assets**

***

Creates a new liquidity pool for two fungible assets. Reverts if the pool already exists.

```
public fun create_pool(
    creator: &signer,
    token_0: Object<Metadata>,
    token_1: Object<Metadata>,
    fee: u64,
    sqrt_price: u128,
)
```

**Function arguments**

| Argument    | Type     | Description                        |
| ----------- | -------- | ---------------------------------- |
| creator     | \&signer | The creator’s signer               |
| token\_0    | Object   | Fungible asset metadata of token 0 |
| token\_1    | Object   | Fungible asset metadata of token 1 |
| fee         | u64      | Fee tier of the pool               |
| sqrt\_price | u128     | Initial sqrt price of the pool     |

### Create pool with one coin and one fungible asset <a href="#create-pool-with-one-coin-and-one-fungible-asset" id="create-pool-with-one-coin-and-one-fungible-asset"></a>

***

Creates a new liquidity pool with one coin (<mark style="color:green;">`Token0`</mark>) and one fungible asset. Reverts if the pool already exists.

```
public fun create_pool_one_coin<Token0>(
    creator: &signer,
    token_1: Object<Metadata>,
    fee: u64,
    sqrt_price: u128,
)
```

**Function type arguments**

| Argument | Description      |
| -------- | ---------------- |
| Token0   | The coin’s type. |

**Function arguments**

| Argument    | Type     | Description                        |
| ----------- | -------- | ---------------------------------- |
| creator     | \&signer | The creator’s signer               |
| token\_1    | Object   | Fungible asset metadata of token 1 |
| fee         | u64      | Fee tier of the pool               |
| sqrt\_price | u128     | Initial sqrt price of the pool     |

### Create pool with two coins <a href="#create-pool-with-two-coins" id="create-pool-with-two-coins"></a>

***

Creates a new liquidity pool with two coins <mark style="color:green;">`Token0`</mark> and <mark style="color:green;">`Token1`</mark>. Reverts if the pool already exists.

```
public fun create_pool_both_coins<Coin0, Coin1>(
    creator: &signer,
    fee: u64,
    sqrt_price: u128,
)
```

**Function type arguments**

| Argument | Description                    |
| -------- | ------------------------------ |
| Coin0    | The coin’s type of the token 0 |
| Coin1    | The coin’s type of the token 1 |

**Function arguments**

| Argument    | Type     | Description                     |
| ----------- | -------- | ------------------------------- |
| creator     | \&signer | The creator’s signer.           |
| fee         | u64      | Fee tier of the pool.           |
| sqrt\_price | u128     | Initial sqrt price of the pool. |

## Add liquidity

### Add liquidity to a pool with two fungible assets

***

Adds liquidity to a pool with two fungible assets.

```
public fun add_liquidity(
    user: &signer,
    pool: Object<LiquidityPool>,
    position_id: u64,
    tick_lower: u32,
    tick_upper: u32,
    token_0: FungibleAsset,
    token_1: FungibleAsset,
    amount_0_min: u64,
    amount_1_min: u64,
): (FungibleAsset, FungibleAsset)
```

**Function arguments**

| Argument       | Type          | Description                                                                                                              |
| -------------- | ------------- | ------------------------------------------------------------------------------------------------------------------------ |
| user           | \&signer      | The user’s signer.                                                                                                       |
| pool           | Object        | The liquidity pool to add liquidity to.                                                                                  |
| position\_id   | u64           | The position ID of the liquidity. Leave it as 0 if you want to create a new position or you don’t have any position yet. |
| tick\_lower    | u32           | The lower tick of the liquidity. Required in the case of creating a new position. Otherwise, leave it as 0.              |
| tick\_upper    | u32           | The upper tick of the liquidity. Required in the case of creating a new position. Otherwise, leave it as 0.              |
| token\_0       | FungibleAsset | The amount of token 0 to add to the liquidity.                                                                           |
| token\_1       | FungibleAsset | The amount of token 1 to add to the liquidity.                                                                           |
| amount\_0\_min | u64           | The minimum amount of token 0 to add to the liquidity.                                                                   |
| amount\_1\_min | u64           | The minimum amount of token 1 to add to the liquidity.                                                                   |

**Returns**

| Type                           | Description                |
| ------------------------------ | -------------------------- |
| (FungibleAsset, FungibleAsset) | The added fungible assets. |

### Remove liquidity from a pool

***

Removes liquidity from a pool.

```
public fun remove_liquidity(
    user: &signer,
    pool: Object<LiquidityPool>,
    position_id: u64,
    liquidity: u128,
    amount_0_min: u64,
    amount_1_min: u64,
): (FungibleAsset, FungibleAsset)
```

**Function arguments**

| Argument       | Type     | Description                                  |
| -------------- | -------- | -------------------------------------------- |
| user           | \&signer | The user’s signer.                           |
| pool           | Object   | The liquidity pool to remove liquidity from. |
| position\_id   | u64      | The position ID of the liquidity.            |
| liquidity      | u128     | The amount of liquidity to remove.           |
| amount\_0\_min | u64      | The minimum amount of token 0 to get.        |
| amount\_1\_min | u64      | The minimum amount of token 1 to get.        |

**Returns**

| Type          | Description                                                           |
| ------------- | --------------------------------------------------------------------- |
| FungibleAsset | The returned fungible assets of the token 0 after removing liquidity. |
| FungibleAsset | The returned fungible assets of the token 1 after removing liquidity. |

### Collect fee

***

Collects fee from a position.

```
public fun collect_fee(
    user: &signer,
    pool: Object<LiquidityPool>,
    position_id: u64,
    amount_0_requested: u64,
    amount_1_requested: u64,
): (FungibleAsset, FungibleAsset)
```

**Function arguments**

| Argument             | Type     | Description                      |
| -------------------- | -------- | -------------------------------- |
| user                 | \&signer | The user’s signer.               |
| pool                 | Object   | The liquidity pool.              |
| position\_id         | u64      | The position ID.                 |
| amount\_0\_requested | u64      | The amount of token 0 requested. |
| amount\_1\_requested | u64      | The amount of token 1 requested. |

**Returns**

| Type          | Description                       |
| ------------- | --------------------------------- |
| FungibleAsset | The collected fee of the token 0. |
| FungibleAsset | The collected fee of the token 1. |

### Collect reward

***

Collects reward from a position.

```
public fun collect_reward(
    user: &signer,
    pool: Object<LiquidityPool>,
    position_id: u64,
    reward_index: u64,
    amount_requested: u64,
): FungibleAsset
```

**Function arguments**

| Argument          | Type     | Description                     |
| ----------------- | -------- | ------------------------------- |
| user              | \&signer | The user’s signer.              |
| pool              | Object   | The liquidity pool.             |
| position\_id      | u64      | The position ID.                |
| reward\_index     | u64      | The reward index.               |
| amount\_requested | u64      | The amount of reward requested. |

**Returns**

| Type          | Description           |
| ------------- | --------------------- |
| FungibleAsset | The collected reward. |

## Swap functions

### Swap exact fungible asset for fungible asset

***

Swaps an exact amount of fungible asset for another fungible asset.

```
public fun swap_exact_fa_for_fa(
    trader: &signer,
    pool: Object<LiquidityPool>,
    token_in: FungibleAsset,
    amount_out_min: u64,
    sqrt_price_limit: u128,
): FungibleAsset
```

**Function arguments**

| Argument           | Type          | Description                         |
| ------------------ | ------------- | ----------------------------------- |
| trader             | \&signer      | The trader’s signer.                |
| pool               | Object        | The liquidity pool.                 |
| token\_in          | FungibleAsset | The input token.                    |
| amount\_out\_min   | u64           | The minimum amount of output token. |
| sqrt\_price\_limit | u128          | The sqrt price limit.               |

**Returns**

| Type          | Description                 |
| ------------- | --------------------------- |
| FungibleAsset | The swapped fungible asset. |

### Swap exact fungible asset for coin

***

Swaps an exact amount of fungible asset for a coin.

```
public fun swap_exact_fa_for_coin<CoinType>(
    trader: &signer,
    pool: Object<LiquidityPool>,
    token_in: FungibleAsset,
    amount_out_min: u64,
    sqrt_price_limit: u128,
): Coin<CoinType>
```

**Function type arguments**

| Argument | Description     |
| -------- | --------------- |
| CoinType | The coin’s type |

**Function arguments**

| Argument           | Type          | Description                         |
| ------------------ | ------------- | ----------------------------------- |
| trader             | \&signer      | The trader’s signer.                |
| pool               | Object        | The liquidity pool.                 |
| token\_in          | FungibleAsset | The input token.                    |
| amount\_out\_min   | u64           | The minimum amount of output token. |
| sqrt\_price\_limit | u128          | The sqrt price limit.               |

**Returns**

| Type | Description       |
| ---- | ----------------- |
| Coin | The swapped coin. |

### Swap exact coin for fungible asset

***

Swaps an exact amount of coin for a fungible asset.

```
public fun swap_exact_coin_for_fa<CoinType>(
    trader: &signer,
    pool: Object<LiquidityPool>,
    token_in: Coin<CoinType>,
    amount_out_min: u64,
    sqrt_price_limit: u128,
): FungibleAsset
```

**Function type arguments**

| Argument | Description     |
| -------- | --------------- |
| CoinType | The coin’s type |

**Function arguments**

| Argument           | Type     | Description                         |
| ------------------ | -------- | ----------------------------------- |
| trader             | \&signer | The trader’s signer.                |
| pool               | Object   | The liquidity pool.                 |
| token\_in          | Coin     | The input coin.                     |
| amount\_out\_min   | u64      | The minimum amount of output token. |
| sqrt\_price\_limit | u128     | The sqrt price limit.               |

**Returns**

| Type          | Description                 |
| ------------- | --------------------------- |
| FungibleAsset | The swapped fungible asset. |

### Swap exact coin for coin

***

Swaps an exact amount of coin for another coin.

```
public fun swap_exact_coin_for_coin<CoinIn, CoinOut>(
    trader: &signer,
    pool: Object<LiquidityPool>,
    token_in: Coin<CoinIn>,
    amount_out_min: u64,
    sqrt_price_limit: u128,
): Coin<CoinOut>
```

**Function type arguments**

| Argument | Description            |
| -------- | ---------------------- |
| CoinIn   | The input coin’s type  |
| CoinOut  | The output coin’s type |

**Function arguments**

| Argument           | Type     | Description                         |
| ------------------ | -------- | ----------------------------------- |
| trader             | \&signer | The trader’s signer.                |
| pool               | Object   | The liquidity pool.                 |
| token\_in          | Coin     | The input coin.                     |
| amount\_out\_min   | u64      | The minimum amount of output token. |
| sqrt\_price\_limit | u128     | The sqrt price limit.               |

**Returns**

| Type | Description       |
| ---- | ----------------- |
| Coin | The swapped coin. |

### Swap fungible asset for exact fungible asset

***

Swaps a fungible asset for an exact amount of another fungible asset.

```
public fun swap_fa_for_exact_fa(
    trader: &signer,
    pool: Object<LiquidityPool>,
    token_in: FungibleAsset,
    amount_out_desired: u64,
    sqrt_price_limit: u128,
): (FungibleAsset, FungibleAsset)
```

**Function arguments**

| Argument             | Type          | Description                         |
| -------------------- | ------------- | ----------------------------------- |
| trader               | \&signer      | The trader’s signer.                |
| pool                 | Object        | The liquidity pool.                 |
| token\_in            | FungibleAsset | The input token.                    |
| amount\_out\_desired | u64           | The desired amount of output token. |
| sqrt\_price\_limit   | u128          | The sqrt price limit.               |

**Returns**

| Type          | Description                                      |
| ------------- | ------------------------------------------------ |
| FungibleAsset | The remaining fungible asset of the input token. |
| FungibleAsset | The swapped fungible asset of the output token.  |

### Swap fungible asset for exact coin

***

Swaps a fungible asset for an exact amount of a coin.

```
public fun swap_fa_for_exact_coin<CoinType>(
    trader: &signer,
    pool: Object<LiquidityPool>,
    token_in: FungibleAsset,
    amount_out_desired: u64,
    sqrt_price_limit: u128,
): (FungibleAsset, Coin<CoinType>)
```

**Function type arguments**

| Argument | Description     |
| -------- | --------------- |
| CoinType | The coin’s type |

**Function arguments**

| Argument             | Type          | Description                         |
| -------------------- | ------------- | ----------------------------------- |
| trader               | \&signer      | The trader’s signer.                |
| pool                 | Object        | The liquidity pool.                 |
| token\_in            | FungibleAsset | The input token.                    |
| amount\_out\_desired | u64           | The desired amount of output token. |
| sqrt\_price\_limit   | u128          | The sqrt price limit.               |

**Returns**

| Type          | Description                                      |
| ------------- | ------------------------------------------------ |
| FungibleAsset | The remaining fungible asset of the input token. |
| Coin          | The swapped coin of the output token.            |

### Swap coin for exact fungible asset

***

Swaps a coin for an exact amount of a fungible asset.

```
public fun swap_coin_for_exact_fa<CoinType>(
    trader: &signer,
    pool: Object<LiquidityPool>,
    token_in: Coin<CoinType>,
    amount_out_desired: u64,
    sqrt_price_limit: u128,
): (Coin<CoinType>, FungibleAsset)
```

**Function type arguments**

| Argument | Description     |
| -------- | --------------- |
| CoinType | The coin’s type |

**Function arguments**

| Argument             | Type     | Description                         |
| -------------------- | -------- | ----------------------------------- |
| trader               | \&signer | The trader’s signer.                |
| pool                 | Object   | The liquidity pool.                 |
| token\_in            | Coin     | The input coin.                     |
| amount\_out\_desired | u64      | The desired amount of output token. |
| sqrt\_price\_limit   | u128     | The sqrt price limit.               |

**Returns**

| Type          | Description                                     |
| ------------- | ----------------------------------------------- |
| Coin          | The remaining coin of the input token.          |
| FungibleAsset | The swapped fungible asset of the output token. |

### Swap coin for exact coin

***

Swaps a coin for an exact amount of another coin.

```
public fun swap_coin_for_exact_coin<CoinIn, CoinOut>(
    trader: &signer,
    pool: Object<LiquidityPool>,
    token_in: Coin<CoinIn>,
    amount_out_desired: u64,
    sqrt_price_limit: u128,
): (Coin<CoinIn>, Coin<CoinOut>)
```

**Function type arguments**

| Argument | Description            |
| -------- | ---------------------- |
| CoinIn   | The input coin’s type  |
| CoinOut  | The output coin’s type |

**Function arguments**

| Argument             | Type     | Description                         |
| -------------------- | -------- | ----------------------------------- |
| trader               | \&signer | The trader’s signer.                |
| pool                 | Object   | The liquidity pool.                 |
| token\_in            | Coin     | The input coin.                     |
| amount\_out\_desired | u64      | The desired amount of output token. |
| sqrt\_price\_limit   | u128     | The sqrt price limit.               |

**Returns**

| Type | Description                            |
| ---- | -------------------------------------- |
| Coin | The remaining coin of the input token. |
| Coin | The swapped coin of the output token.  |

### Swap exact fungible asset for fungible asset with multiple hops

***

Swaps an exact amount of fungible asset for another fungible asset with multiple hops.

```
public fun swap_exact_fa_for_fa_multi_hops(
    trader: &signer,
    pools: vector<Object<LiquidityPool>>,
    token_in: FungibleAsset,
    amount_out_min: u64,
): FungibleAsset
```

**Function arguments**

| Argument         | Type            | Description                         |
| ---------------- | --------------- | ----------------------------------- |
| trader           | \&signer        | The trader’s signer.                |
| pools            | vector\<Object> | The liquidity pools.                |
| token\_in        | FungibleAsset   | The input token.                    |
| amount\_out\_min | u64             | The minimum amount of output token. |

**Returns**

| Type          | Description                 |
| ------------- | --------------------------- |
| FungibleAsset | The swapped fungible asset. |

### Swap exact coin for fungible asset with multiple hops

***

Swaps an exact amount of coin for a fungible asset with multiple hops.

```
public fun swap_exact_coin_for_fa_multi_hops<CoinType>(
    trader: &signer,
    pools: vector<Object<LiquidityPool>>,
    token_in: Coin<CoinType>,
    amount_out_min: u64,
): FungibleAsset
```

**Function type arguments**

| Argument | Description     |
| -------- | --------------- |
| CoinType | The coin’s type |

**Function arguments**

| Argument         | Type            | Description                         |
| ---------------- | --------------- | ----------------------------------- |
| trader           | \&signer        | The trader’s signer.                |
| pools            | vector\<Object> | The liquidity pools.                |
| token\_in        | Coin            | The input coin.                     |
| amount\_out\_min | u64             | The minimum amount of output token. |

**Returns**

| Type          | Description                 |
| ------------- | --------------------------- |
| FungibleAsset | The swapped fungible asset. |

### Swap fungible asset for exact fungible asset with multiple hops

***

Swaps a fungible asset for an exact amount of another fungible asset with multiple hops.

```
public fun swap_fa_for_exact_fa_multi_hops(
    trader: &signer,
    pools: vector<Object<LiquidityPool>>,
    token_in: FungibleAsset,
    amount_out_desired: u64,
): (FungibleAsset, FungibleAsset)
```

**Function arguments**

| Argument             | Type            | Description                         |
| -------------------- | --------------- | ----------------------------------- |
| trader               | \&signer        | The trader’s signer.                |
| pools                | vector\<Object> | The liquidity pools.                |
| token\_in            | FungibleAsset   | The input token.                    |
| amount\_out\_desired | u64             | The desired amount of output token. |
| sqrt\_price\_limit   | u128            | The sqrt price limit.               |

**Returns**

| Type          | Description                                      |
| ------------- | ------------------------------------------------ |
| FungibleAsset | The remaining fungible asset of the input token. |
| FungibleAsset | The swapped fungible asset of the output token.  |

### Swap coin for exact fungible asset with multiple hops

***

Swaps a coin for an exact amount of a fungible asset with multiple hops.

```
public fun swap_coin_for_exact_fa_multi_hops<CoinType>(
    trader: &signer,
    pools: vector<Object<LiquidityPool>>,
    token_in: Coin<CoinType>,
    amount_out_desired: u64,
): (Coin<CoinType>, FungibleAsset)
```

**Function type arguments**

| Argument | Description     |
| -------- | --------------- |
| CoinType | The coin’s type |

**Function arguments**

| Argument             | Type            | Description                         |
| -------------------- | --------------- | ----------------------------------- |
| trader               | \&signer        | The trader’s signer.                |
| pools                | vector\<Object> | The liquidity pools.                |
| token\_in            | Coin            | The input coin.                     |
| amount\_out\_desired | u64             | The desired amount of output token. |

**Returns**

| Type          | Description                                     |
| ------------- | ----------------------------------------------- |
| Coin          | The remaining coin of the input token.          |
| FungibleAsset | The swapped fungible asset of the output token. |

## Get pool functions

### Get pool

***

Gets the liquidity pool for two fungible assets.

```
#[view]
public fun get_pool(
    token_0: Object<Metadata>,
    token_1: Object<Metadata>,
    fee: u64,
): Object<LiquidityPool>
```

**Function arguments**

| Argument | Type   | Description                        |
| -------- | ------ | ---------------------------------- |
| token\_0 | Object | Fungible asset metadata of token 0 |
| token\_1 | Object | Fungible asset metadata of token 1 |
| fee      | u64    | Fee tier of the pool               |

**Returns**

| Type   | Description         |
| ------ | ------------------- |
| Object | The liquidity pool. |

### Get pool with one coin and one fungible asset

***

Gets the liquidity pool for one coin (<mark style="color:green;">`CoinType`</mark>) and one fungible asset.

```
#[view]
public fun get_pool_one_coin<CoinType>(
    token_1: Object<Metadata>,
    fee: u64,
): Object<LiquidityPool>
```

**Function type arguments**

| Argument | Description     |
| -------- | --------------- |
| CoinType | The coin’s type |

**Function arguments**

| Argument | Type   | Description                        |
| -------- | ------ | ---------------------------------- |
| token\_1 | Object | Fungible asset metadata of token 1 |
| fee      | u64    | Fee tier of the pool               |

**Returns**

| Type   | Description         |
| ------ | ------------------- |
| Object | The liquidity pool. |

### Get pool with two coins

***

Gets the liquidity pool for two coins <mark style="color:green;">`Coin0`</mark> and <mark style="color:green;">`Coin1`</mark>.

```
#[view]
public fun get_pool_both_coins<Coin0, Coin1>(
    fee: u64,
): Object<LiquidityPool>
```

**Function type arguments**

| Argument | Description                    |
| -------- | ------------------------------ |
| Coin0    | The coin’s type of the token 0 |
| Coin1    | The coin’s type of the token 1 |

**Function arguments**

| Argument | Type | Description          |
| -------- | ---- | -------------------- |
| fee      | u64  | Fee tier of the pool |

**Returns**

| Type   | Description         |
| ------ | ------------------- |
| Object | The liquidity pool. |


---

# 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://docs.evo.market/technical/clmm/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.
