# Types

> Borsh types of Qoq: swap routes, pool views with their rate sources, creating pools, fee payouts, oracle requests and responses, with the index of every enum variant.

This page is part of the Qoq docs. Qoq is the DEX `slimedragon.near/amp` on the Intear DEX contract, `dex.intear.near`, and every call goes to that contract. https://docs.intear.tech/qoq/llms-full.txt has all of its pages in one file, and https://docs.intear.tech/llms.txt lists every page of the Intear docs.

Qoq reads and writes [Borsh](https://borsh.io/). In Borsh, integers are little-endian, a `Vec` or a string is a `u32` length and then its items, an `Option` is `0` for `None` or `1` and the value, an enum is a `u8` variant index and then the variant's fields, and a `bool` is one byte. Structs and tuples are their fields in order, and a `HashMap` is a `u32` count and then its key/value pairs, sorted by key. `AccountId` is a string.

In Rust, these are in the [`amp-dex-types`](https://github.com/INTEARnear/dex/tree/main/dexes/amp/types) crate, and the types shared with the engine, like `AssetId`, in [`intear-dex-common`](https://docs.intear.tech/intear-dex/reference/types.md#borsh).

## Shared with the engine

`AssetId`, `SwapRequestAmount` and the other types of the engine are described in its [Types](https://docs.intear.tech/intear-dex/reference/types.md#borsh). `AssetId` is `Near` (0), `Nep141(AccountId)` (1), `Nep245(AccountId, String)` (2), `Nep171(AccountId, String)` (3). Qoq doesn't support `Nep171`.

## `PoolId`

`u32`, counted from 0.

## `Price`

`u128` with 18 decimals: `1000000000000000000` is 1. The price of a whole token of a pool's first asset in its second, or of an exchange's price in its quote currency.

## `PublicKey`

An oracle's key: a `u8` curve, `0` for Ed25519 or `1` for secp256k1, then the key's 32 or 64 bytes, with no length. near-api-js and near-primitives write a key the same way.

## `SwapArgs`

The `message` of a swap. See [The message](https://docs.intear.tech/qoq/guides/swaps.md#the-message).

```rust
struct SwapArgs {
    routes: Vec<SwapRoute>,
}

struct SwapRoute {
    fraction: u32, // 1000000 = 100%
    pool_ids: Vec<PoolId>,
}
```

Messages from before [fee discounts](https://docs.intear.tech/intear-dex/guides/swaps.md#fee-discounts) moved to the engine can have a fee discount after the routes, which is read and ignored.

## `PoolView`

What `get_pool` and `get_pools` return, and [`PoolUpdated`](https://docs.intear.tech/qoq/reference/events.md#poolupdated) events carry. A struct:

| Field | Type |
| --- | --- |
| `assets` | `(AssetWithBalance, AssetWithBalance)` |
| `decimals` | `(u8, u8)` |
| `amplification` | `u32` |
| `rate_source` | `PoolRateSource` |
| `fee` | `u32`, out of 1000000 |
| `total_shares` | `Option<u128>`, `None` when all liquidity was removed |

`AssetWithBalance` is `asset_id: AssetId`, `balance: u128`. See [Pools](https://docs.intear.tech/qoq/guides/pools.md#what-a-pool-has).

### `PoolRateSource`

An enum whose variant indexes start at 128, unlike the 0 of [`NewPoolRateSource`](#createpoolargs):

| Index | Variant | Fields |
| --- | --- | --- |
| 128 | `Oracle` | `key: PublicKey`, `last_price: Price`: the price of the pool's last swap, `0` before its first |
| 129 | `Fixed` | `Price` |

### Older pool views

[Events](https://docs.intear.tech/qoq/reference/events.md) from before rate sources have, instead of `rate_source`, the oracle as `oracle_key: PublicKey` and `last_oracle_price: Option<Price>`. Some of them also have the oracle's fee, `((u128, u128), AccountId)`, between `fee` and `total_shares`. Since a `PublicKey` starts with `0` or `1`, the first byte after `amplification` tells the layouts apart.

## `CreatePoolArgs`

What `create_pool` takes. Only Qoq's owner can call it. See [Owner settings](https://docs.intear.tech/qoq/guides/pools.md#owner-settings).

```rust
struct CreatePoolArgs {
    assets: (AssetId, AssetId),
    decimals: (u8, u8),
    amplification: u32,
    rate_source: NewPoolRateSource,
    fee: u32,
    /// The first liquidity, which the attached assets must match
    initial_liquidity: (u128, u128),
    /// How the owner takes its part of the pool's fees
    creator_fee_payout_type: FeePayoutType,
}
```

`NewPoolRateSource` is `Oracle(PublicKey)` (0) or `Fixed(Price)` (1). It responds with `CreatePoolResponse { pool_id: PoolId }`.

## `FeePayoutType`

How a liquidity provider takes its part of the pool's fees. See [Fees](https://docs.intear.tech/qoq/guides/liquidity.md#fees).

| Index | Variant |
| --- | --- |
| 0 | `KeepBoth` |
| 1 | `ConvertToFirstAsset` |
| 2 | `ConvertToSecondAsset` |

## `FeeReceiver`

Who took a fee, in a [`Swap`](https://docs.intear.tech/qoq/reference/events.md#swap) event:

| Index | Variant | Receiver |
| --- | --- | --- |
| 0 | `Pool` | The pool's liquidity providers |
| 1 | `Protocol` | Qoq's protocol fee, `qoq.intear.near` |
| 2 | `Oracle(AccountId)` | Only in events from before the engine took the fees of oracles |

## `LiquidityPositionView`

What `get_liquidity_position` returns: `payout_type: FeePayoutType`, `uncollected_fees: (u128, u128)`, the fees in each of the pool's assets that the provider hasn't collected yet. See [Fees](https://docs.intear.tech/qoq/guides/liquidity.md#fees).

## `PricesRequest` and `PricesResponse`

The `request` of the [`OracleRequest`](https://docs.intear.tech/qoq/guides/swaps.md#pools-an-oracle-prices) of a swap, and what the oracle responds:

```rust
struct PricesRequest {
    asset_ids: Vec<AssetId>,
}

struct PricesResponse {
    exchanges: Vec<ExchangePrices>,
}

struct ExchangePrices {
    exchange: String,
    /// One price of a whole token for each requested asset, in their order,
    /// in the exchange's quote currency
    prices: Vec<Price>,
}
```

## Arguments of calls and views

| Struct | Fields |
| --- | --- |
| `GetPoolArgs`, `RegisterLiquidityArgs`, `CollectLiquidityFeesArgs` | `pool_id: PoolId` |
| `GetPoolsArgs` | `start_index: PoolId`, `limit: u32` |
| `GetPoolSharesArgs` | `pool_ids: Vec<PoolId>`, `account_id: AccountId` |
| `GetLiquidityPositionArgs` | `pool_id: PoolId`, `account_id: AccountId` |
| `AddLiquidityArgs` | `pool_id: PoolId`, `min_shares_received: Option<u128>` |
| `RemoveLiquidityArgs` | `pool_id: PoolId`, `shares_to_remove: Option<u128>`, `min_assets_received: Option<(u128, u128)>` |
| `SetLiquidityFeePayoutArgs` | `pool_id: PoolId`, `payout_type: FeePayoutType` |
| `WithdrawFeesArgs` | `assets: Vec<AssetId>` |
| `GetPendingFeesArgs` | `account_id: AccountId`, `asset_ids: Vec<AssetId>` |
| `SetAmplificationArgs` | `pool_id: PoolId`, `amplification: u32` |
| `SetFeeArgs` | `pool_id: PoolId`, `fee: u32` |
| `SetOracleKeyArgs` | `pool_id: PoolId`, `oracle_key: PublicKey` |

`shares_to_remove` can't be `Some(0)`.
