# Swap

{% hint style="warning" %}
Movemement testnet is unstable by the time of writing and using the contracts below are for testing and development purposes only
{% endhint %}

### **Contract Info**

* **Contract Name**: `yuzu::swap`
* **Contract Address**: \[tba]
* **Admin Multi Sig**: \[tba]

### Types

| Name | Type         | Description                                   |
| ---- | ------------ | --------------------------------------------- |
| X    | type address | The coin type address of token X in the pair. |
| Y    | type address | The coin type address of token Y in the pair. |

### Resources

#### **LPToken**

The liquidity token corresponds to each pool XY.

```move
struct LPToken<phantom X, phantom Y> has key {}
```

***

#### **TokenPairMetadata**

Metadata related to the token pair and liquidity pool.

```move
struct TokenPairMetadata<phantom X, phantom Y> has key {
    creator: address,
    fee_on_transfer_x: Option<FeeOnTransferInfo<X>>,
    fee_on_transfer_y: Option<FeeOnTransferInfo<Y>>,
    k_last: u128,
    liquidity_fee: u128,
    rewards_fee: u128,
    team_fee: u128,
    treasury_fee: u128,
    balance_x: coin::Coin<X>,
    balance_y: coin::Coin<Y>,
    mint_cap: coin::MintCapability<LPToken<X, Y>>,
    burn_cap: coin::BurnCapability<LPToken<X, Y>>,
    freeze_cap: coin::FreezeCapability<LPToken<X, Y>>,
}
```

| Name          | Type                 | Description                                                   |
| ------------- | -------------------- | ------------------------------------------------------------- |
| creator       | address              | The creator address of the pool.                              |
| k\_last       | u128                 | The last recorded reserve product (reserve\_x \* reserve\_y). |
| balance\_x    | coin::Coin           | The total amount of token X in the pool.                      |
| balance\_y    | coin::Coin           | The total amount of token Y in the pool.                      |
| mint\_cap     | coin::MintCapability | Capability to mint LP tokens.                                 |
| burn\_cap     | coin::BurnCapability | Capability to burn LP tokens.                                 |
| treasury\_fee | u128                 | The fee collected by the treasury.                            |

***

#### **TokenPairReserve**

Reserve balances and metadata related to liquidity reserves.

```move
struct TokenPairReserve<phantom X, phantom Y> has key {
    reserve_x: u64,
    reserve_y: u64,
    block_timestamp_last: u64
}
```

| Name                   | Type | Description                              |
| ---------------------- | ---- | ---------------------------------------- |
| reserve\_x             | u64  | The total amount of token X in the pool. |
| reserve\_y             | u64  | The total amount of token Y in the pool. |
| block\_timestamp\_last | u64  | The last time the reserves were updated. |

***

### Public Functions

#### **Register LP**

Register the LP token to the account.

```move
public fun register_lp<X, Y>(sender: &signer)
```

#### **Is Pair Created**

Check if the pool XY is created or not.

```move
public fun is_pair_created<X, Y>(): bool
```

#### **LP Balance**

Check the LP balance of a user.

```move
public fun lp_balance<X, Y>(addr: address): u64
```

#### **Total LP Supply**

Retrieve the total amount of LP tokens in the pool.

```move
public fun total_lp_supply<X, Y>(): u128
```

#### **Token Reserves**

Retrieve the reserves of the token pair XY.

```move
public fun token_reserves<X, Y>(): (u64, u64, u64)
```

#### **Token Balance**

Retrieve the token balances in the pool XY.

```move
public fun token_balances<X, Y>(): (u64, u64)
```


---

# 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.yuzu.finance/technical/smart-contracts/yuzu-amm-testnet/swap.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.
