# Pools

> Qoq pools: their assets, decimals, amplification, price from an oracle or fixed, and fee, reading pools, and the settings that only Qoq's owner changes.

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.

A pool holds two different assets, NEAR, NEP-141 or NEP-245, and swaps between them on a StableSwap curve around a price. Pool IDs are counted from 0 in the order pools were created.

## What a pool has

| Field | Description |
| --- | --- |
| `assets` | The two assets and the pool's balance of each |
| `decimals` | The decimals of each asset, at most 38. The price is of whole tokens, so these turn amounts into whole tokens |
| `amplification` | `A` of the StableSwap curve, from 1 to 1000000. The higher it is, the closer the pool keeps to its price as it gets out of balance |
| `rate_source` | Where the price of a whole token of the first asset in the second comes from: an `Oracle`, with the key of the oracle and the price of the last swap, or `Fixed`. Prices have 18 decimals |
| `fee` | Out of 1000000, so `750` is 0.075%. 20% of it goes to Qoq. Less than 100% |
| `total_shares` | The shares of all liquidity providers. `None` when all liquidity was removed |

See [How prices are computed](https://docs.intear.tech/qoq/guides/swaps.md#how-prices-are-computed) for how these make a swap's price.

A pool's rate source can't change between `Oracle` and `Fixed`, and a fixed price can't change. An oracle pool can get another oracle.

## Read pools

`get_pool` takes a pool ID, a Borsh `u32`, and returns a Borsh `Option<PoolView>`, `None` if there's no such pool. `get_pool_count` returns the number of pools, and `get_pools` takes a `start_index` and a `limit` and returns the pools from there, so the ID of each is `start_index` plus its position. For views without arguments, pass `""` as `args`.

```sh
near contract call-function as-read-only dex.intear.near dex_view \
  json-args '{"dex_id": "slimedragon.near/amp", "method": "get_pool_count", "args": ""}' \
  network-config mainnet now

near contract call-function as-read-only dex.intear.near dex_view \
  json-args '{"dex_id": "slimedragon.near/amp", "method": "get_pool", "args": "AQAAAA=="}' \
  network-config mainnet now
```

The whole file, tested in CI: https://docs.intear.tech/snippets/cli/qoq-swaps.sh

A [`PoolView`](https://docs.intear.tech/qoq/reference/types.md#poolview) is a struct with the fields above, not an enum like Plach's.

## Owner settings

Only Qoq's owner, slimedragon.near, which deployed it, can create pools and change them. Changes take effect at once.

| Method | Arguments | What it does |
| --- | --- | --- |
| `create_pool` | [`CreatePoolArgs`](https://docs.intear.tech/qoq/reference/types.md#createpoolargs) | Creates a pool with its first liquidity, for which the owner gets 10<sup>18</sup> shares. Attach the liquidity and NEAR for storage |
| `set_amplification` | `SetAmplificationArgs { pool_id: u32, amplification: u32 }` | Changes `A`, from 1 to 1000000 |
| `set_fee` | `SetFeeArgs { pool_id: u32, fee: u32 }` | Changes the fee, to less than 100% |
| `set_oracle_key` | `SetOracleKeyArgs { pool_id: u32, oracle_key: PublicKey }` | Gives a pool that an oracle prices another oracle. Attach NEAR if the new key takes more storage |

Each change logs a [`PoolUpdated`](https://docs.intear.tech/qoq/reference/events.md#poolupdated) event.
