> For the complete documentation index, see [llms.txt](https://docs.evo.market/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.evo.market/technical/clmm/liquidity-pool.md).

# Liquidity Pool

## Module Info <a href="#module-info" id="module-info"></a>

* **Name**: <mark style="color:green;">`evo::liquidity_pool`</mark>
* **Description**: This module contains the core logic for the liquidity pool of the <mark style="color:green;">`evo`</mark> contract. This module only works with fungible assets. If you want to use coins, please check the <mark style="color:green;">`router`</mark> module, which contains functions to work with coins.

## Public Functions

### Swap releated functions

The <mark style="color:green;">`liquidity_pool`</mark> uses the <mark style="color:green;">`"Hot potato"`</mark> pattern for swapping feature.

### Swap Functions

***

Swaps tokens in the liquidity pool. This function returns a <mark style="color:green;">`SwapReciept`</mark> object and requires to pay back in the same transaction to complete (<mark style="color:green;">`"Hot potato"`</mark> pattern).

```
public fun swap(
    trader: &signer,
    pool: Object<LiquidityPool>,
    zero_for_one: bool,
    is_exact_in: bool,
    specified_amount: u64,
    sqrt_price_limit: u128,
): (FungibleAsset, SwapReciept)
```

#### Function arguments

| Argument           | Type     | Description                                                                                                                                               |
| ------------------ | -------- | --------------------------------------------------------------------------------------------------------------------------------------------------------- |
| trade              | \&signer | The trader’s signer.                                                                                                                                      |
| pool               | Object   | The liquidity pool.                                                                                                                                       |
| zero\_for\_one     | bool     | Direction of the swap. <mark style="color:green;">`true`</mark> for token 0 to token 1, <mark style="color:green;">`false`</mark> for token 1 to token 0. |
| is\_exact\_in      | bool     | Whether the specified amount is the exact input amount.                                                                                                   |
| specified\_amount  | u64      | The specified amount for the swap.                                                                                                                        |
| sqrt\_price\_limit | u128     | The sqrt price limit for the swap.                                                                                                                        |

#### Returns

| Type          | Description                |
| ------------- | -------------------------- |
| FungibleAsset | The swapped fungible asset |
| SwapReciept   | The swap receipt.          |

#### SwapReciept

```
struct SwapReciept {
    pool: Object<LiquidityPool>,
    token_metadata: Object<Metadata>,
    amount_in: u64,
}
```

| Field           | Type   | Description                                           |
| --------------- | ------ | ----------------------------------------------------- |
| pool            | Object | The liquidity pool of the swap.                       |
| token\_metadata | Object | The metadata of the token in of the swap.             |
| amount\_in      | u64    | The amount of token in needs to be paid for the swap. |

### Get swap receipt amount

***

Gets the amount from a <mark style="color:green;">`SwapReciept`</mark>.

```
public fun get_swap_receipt_amount(swap_receipt: &SwapReciept): u64
```

#### Function arguments

| Argument      | Type          | Description       |
| ------------- | ------------- | ----------------- |
| swap\_receipt | \&SwapReciept | The swap receipt. |

#### Returns

| Type | Description                |
| ---- | -------------------------- |
| u64  | The amount in the receipt. |

### Get swap receipt token metadata

***

Gets the token metadata from a <mark style="color:green;">`SwapReciept`</mark>.

```
public fun get_swap_receipt_token_metadata(swap_receipt: &SwapReciept): Object<Metadata>
```

#### Function arguments

| Argument      | Type          | Description   |
| ------------- | ------------- | ------------- |
| swap\_receipt | \&SwapReciept | \&SwapReciept |

#### Returns

| Type   | Description                        |
| ------ | ---------------------------------- |
| Object | The token metadata in the receipt. |

### Pay swap

***

Pays the swap using the provided token and receipt.

```
public fun pay_swap(
    token_in: FungibleAsset,
    reciept: SwapReciept,
)
```

#### Function arguments

| Argument  | Type          | Description               |
| --------- | ------------- | ------------------------- |
| token\_in | FungibleAsset | The input fungible asset. |
| receipt   | SwapReciept   | The swap receipt.         |

### Quote swap

***

Quotes a swap in the liquidity pool without executing it.

```
public fun quote_swap(
    trader: address,
    pool: Object<LiquidityPool>,
    zero_for_one: bool,
    is_exact_in: bool,
    specified_amount: u64,
    sqrt_price_limit: u128,
): (u64, u64, u64)
```

#### Function arguments

| Argument           | Type    | Description                                                                                                                                               |
| ------------------ | ------- | --------------------------------------------------------------------------------------------------------------------------------------------------------- |
| trader             | address | The trader’s address.                                                                                                                                     |
| pool               | Object  | The liquidity pool.                                                                                                                                       |
| zero\_for\_one     | bool    | Direction of the swap. <mark style="color:green;">`true`</mark> for token 0 to token 1, <mark style="color:green;">`false`</mark> for token 1 to token 0. |
| is\_exact\_in      | bool    | Whether the specified amount is the exact input amount.                                                                                                   |
| specified\_amount  | u64     | The specified amount for the swap.                                                                                                                        |
| sqrt\_price\_limit | u128    | The sqrt price limit for the swap.                                                                                                                        |

#### Returns

| Type | Description                  |
| ---- | ---------------------------- |
| u64  | The amount of token in.      |
| u64  | The amount of token out.     |
| u64  | The fee amount for the swap. |
