# Types

> Borsh types of Plach: swap routes, pool types, fee configurations, fee payouts and pool views, with the index of every enum variant.

This page is part of the Plach docs. Plach is the DEX `slimedragon.near/xyk` on the Intear DEX contract, `dex.intear.near`, and every call goes to that contract. https://docs.intear.tech/plach/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.

Plach 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, all of these are in the [`xyk-dex-types`](https://github.com/INTEARnear/dex/tree/main/dexes/xyk/types) crate.

## 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). Plach doesn't support `Nep171`.

## `PoolId`

`u32`. In a route, `4294967295` (`u32::MAX`) is the [pool created last](https://docs.intear.tech/plach/guides/swaps.md#the-last-created-pool).

## `PublicKey`

The key of `set_fee_discount_signer` and `get_fee_discount_signer`. In Borsh it's a `Vec<u8>`: a `u32` length (33 for Ed25519, 65 for secp256k1), then the curve (`0` for Ed25519, `1` for secp256k1) and the key. near-api-js and near-primitives write a key without the length, so their layout doesn't work here.

## `SwapArgs`

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

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

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

A single `PoolId`, 4 bytes, is read as one route of that pool with no fee discount. Messages from before [referral fees](https://docs.intear.tech/intear-dex/guides/referral-fees.md) moved to the engine can have a `Vec<(AccountId, u32)>` of them after `fee_discount`, which is read and ignored. `SignedFeeDiscount` is in [Fee discounts](https://docs.intear.tech/plach/guides/fees.md#fee-discounts).

## `PoolType`

| Index | Variant | Fields |
| --- | --- | --- |
| 0 | `PrivateLatest` | |
| 1 | `PublicLatest` | |
| 2 | `LaunchLatest` | `phantom_liquidity: u128` |
| 3 | `LaunchV1` | `phantom_liquidity_near: u128` |
| 4 | `PrivateV1` | |
| 5 | `PublicV1` | |
| 6 | `PrivateV2` | |
| 7 | `PublicV2` | |
| 8 | `LaunchV2` | `phantom_liquidity: u128` |
| 9 | `PublicV3` | |

Use the `Latest` variants for new pools. The others create a pool of the current version of their kind too. See [Older pool types](https://docs.intear.tech/plach/guides/pools.md#older-pool-types).

## `FeeConfiguration`

A struct, `receivers: Vec<(FeeReceiver, FeeAmount)>`. In Rust it's `FeeConfigurationV2`. It used to be an enum of `V1` and `V2` with a variant index first, which is only in [older events](#older-pool-views) now.

### `FeeReceiver`

| Index | Variant | Fields |
| --- | --- | --- |
| 1 | `Pool` | |
| 3 | `Account` | `account_id: AccountId`, `payout_type: FeePayoutType`, `claim_mode: ClaimMode` |
| 4 | `Protocol` | Only in the fees of a swap, never in a fee configuration |

Indexes 0 and 2 are the receivers of older versions, `Account(AccountId)` and `Community(AccountId)`. Plach still reads them, as an `Account` with `KeepBoth` and `OnlyOwner`, and with `KeepBoth` and `Anyone`, but never writes them.

### `FeePayoutType`

| Index | Variant |
| --- | --- |
| 0 | `KeepBoth` |
| 1 | `ConvertToFirstAsset` |
| 2 | `ConvertToSecondAsset` |
| 3 | `Reinvest`, only for liquidity providers |

See [The asset a fee is paid in](https://docs.intear.tech/plach/guides/fees.md#the-asset-a-fee-is-paid-in).

### `ClaimMode`

| Index | Variant |
| --- | --- |
| 0 | `OnlyOwner` |
| 1 | `Anyone` |

See [Collected fees](https://docs.intear.tech/plach/guides/fees.md#collected-fees).

### `FeeAmount`

| Index | Variant | Fields |
| --- | --- | --- |
| 0 | `Fixed` | `u32` |
| 1 | `Scheduled` | `start: (u64, u32)`, `end: (u64, u32)`, `curve: ScheduledFeeCurve` |
| 2 | `Dynamic` | `min: u32`, `max: u32`. Not supported yet |

`ScheduledFeeCurve` has one variant, `Linear` (0). Times are in nanoseconds. See [Pool fees](https://docs.intear.tech/plach/guides/fees.md#pool-fees).

## `CreatePoolArgs`

```rust
struct CreatePoolArgs {
    assets: (AssetId, AssetId),
    fees: FeeConfiguration,
    pool_type: PoolType,
    initial_liquidity: Option<(u128, u128)>,
    creator_fee_payout_type: Option<FeePayoutType>,
}
```

For launch pools, the first asset is the quote asset. `creator_fee_payout_type` is required for public pools, and must be `None` for others. See [Create a pool](https://docs.intear.tech/plach/guides/pools.md#create-a-pool).

## `PoolView`

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

| Index | Variant | Fields |
| --- | --- | --- |
| 4 | `Private` | `assets: (AssetWithBalance, AssetWithBalance)`, `fees: CurrentFees`, `fee_configuration: FeeConfiguration`, `owner_id: AccountId`, `locked: bool` |
| 5 | `Public` | `assets: (AssetWithBalance, AssetWithBalance)`, `fees: CurrentFees`, `fee_configuration: FeeConfiguration`, `total_shares: Option<u128>` |
| 6 | `Launch` | `quote_asset: AssetWithBalance`, `launched_asset: AssetWithBalance`, `fees: CurrentFees`, `fee_configuration: FeeConfiguration`, `phantom_liquidity: u128` |

- `AssetWithBalance` is `asset_id: AssetId`, `balance: u128`.
- `CurrentFees` is `receivers: Vec<(FeeReceiver, u32)>`: the fees of a swap right now, each receiver's share after the [protocol fee](https://docs.intear.tech/plach/guides/fees.md#protocol-fee), and the protocol fee last, as `Protocol`.
- `fee_configuration` is the pool's own configuration, before the protocol takes its share.
- A `Launch` pool's quote balance includes the phantom liquidity.
- `total_shares` is `None` when all liquidity was removed.

### Older pool views

[Events](https://docs.intear.tech/plach/reference/events.md) from before the current version have the variants 0 to 3, with a `FeeConfiguration` that starts with its variant index (`0` for `V1`, a `Vec<(FeeReceiver, u32)>`, and `1` for `V2`):

| Index | Variant | Fields |
| --- | --- | --- |
| 0 | `Private` | as variant 4 |
| 1 | `Public` | as variant 5 |
| 2 | `Launch` | `near_amount: u128`, `launched_asset: AssetWithBalance`, `fees: CurrentFees`, `fee_configuration`, `phantom_liquidity_near: u128`. A launch pool quoted in NEAR |
| 3 | `LaunchV2` | as variant 6 |

## `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 [Liquidity](https://docs.intear.tech/plach/guides/liquidity.md#fees).

## Arguments of calls and views

| Struct | Fields |
| --- | --- |
| `GetPoolArgs`, `RegisterLiquidityArgs`, `LockPoolArgs`, `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` |
| `SetLiquidityFeePayoutArgs` | `pool_id: PoolId`, `payout_type: FeePayoutType` |
| `AddLiquidityArgs` | `pool_id: PoolId`, `min_shares_received: Option<u128>` |
| `RemoveLiquidityArgs` | `pool_id: PoolId`, `shares_to_remove: Option<u128>`, `min_assets_received: Option<(u128, u128)>` |
| `EditFeesArgs` | `pool_id: PoolId`, `fees: FeeConfiguration` |
| `RegisterFeeAssetsArgs` | `asset_ids: Vec<AssetId>` |
| `WithdrawFeesArgs` | `assets: Vec<AssetId>` |
| `GetPendingFeesArgs`, `GetClaimableFeesArgs`, `ClaimFeesArgs` | `account_id: AccountId`, `asset_ids: Vec<AssetId>` |
| `SetFeeDiscountSignerArgs` | `fee_discount_signer_public_key: Option<PublicKey>` |

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