# Events

> Events of Plach: swaps, pool updates, liquidity changes and liquidity fees, logged in Borsh inside the dex_events_borsh event of Intear DEX, and the older JSON events.

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 logs its events through the engine, in Borsh. They arrive in the engine's [`dex_events_borsh`](https://docs.intear.tech/intear-dex/reference/events.md#dex_events_borsh) event, one per call: decode it to a list of `DexEventData`, and the `event` of each one whose [`dex_id`](https://docs.intear.tech/intear-dex/reference/types.md#borsh) is deployer `slimedragon.near` and id `xyk` is a Plach event: a Borsh enum of the events below. `DexEventData` also has the `referrer` and `user` (the caller, or the [alleged sender](https://docs.intear.tech/intear-dex/guides/dexes.md#what-a-dex-sees) of a deposit) of the call.

| Index | Event | Logged when |
| --- | --- | --- |
| 0 | [`PoolUpdated`](#poolupdated) | A pool changed: created, swapped in, liquidity, fees or locked |
| 1 | [`Swap`](#swap) | A swap went through a pool |
| 2 | [`LiquidityAdded`](#liquidityadded) | Liquidity was added, including the initial liquidity of a new public or private pool |
| 3 | [`LiquidityRemoved`](#liquidityremoved) | Liquidity was removed |
| 4 | [`LiquidityFeePayoutSet`](#liquidityfeepayoutset) | A provider chose how to take a pool's fees |
| 5 | [`LiquidityFeesCollected`](#liquidityfeescollected) | A provider collected fees it earned in a pool |

In Rust, the type is `XykDexEvent` in [`xyk-dex-types`](https://github.com/INTEARnear/dex/tree/main/dexes/xyk/types).

## `PoolUpdated`

| Field | Type |
| --- | --- |
| `pool_id` | `u32` |
| `pool` | [`PoolView`](https://docs.intear.tech/plach/reference/types.md#poolview) |

The pool as it is after the change. A swap logs one for each pool it went through, after all of its `Swap` events. Events from before Plach's current version have the [older pool views](https://docs.intear.tech/plach/reference/types.md#older-pool-views).

## `Swap`

One for each pool a route goes through, route by route, in the order the pools ran: from the first pool for an exact input, from the last for an exact output. A pool in two routes logs two.

| Field | Type | Description |
| --- | --- | --- |
| `pool_id` | `u32` | |
| `asset_in` | `AssetId` | What went into the pool |
| `asset_out` | `AssetId` | What came out |
| `amount_in` | `u128` | Including the fees |
| `fees_breakdown` | `Vec<(FeeReceiver, AssetId, u128)>` | Each fee, its receiver and the asset it was paid in, after [converting](https://docs.intear.tech/plach/guides/fees.md#the-asset-a-fee-is-paid-in) it: the pool's `fees` in order, and the protocol fee, `Protocol`, last. A `Pool` fee has an entry for the part in `asset_in`, and one for the part converted to `asset_out` if there is any. Swaps from before the current version list the protocol fee as `Account(plach.intear.near)`, and those from before [referral fees](https://docs.intear.tech/intear-dex/guides/referral-fees.md) moved to the engine also list the referral fees, after the protocol fee, whose entry includes its 20% of them |
| `amount_out` | `u128` | |

## `LiquidityAdded`

| Field | Type | Description |
| --- | --- | --- |
| `pool_id` | `u32` | |
| `asset_0`, `asset_1` | `AssetId` | The pool's assets |
| `added_amount_0`, `added_amount_1` | `u128` | What was added |
| `minted_shares` | `u128` | `0` in private pools |
| `new_owned_asset_0`, `new_owned_asset_1` | `u128` | What the provider's shares are worth after. In private pools, the pool's balances |
| `new_owned_shares` | `u128` | The provider's shares after. `0` in private pools |
| `new_total_asset_0`, `new_total_asset_1` | `u128` | The pool's balances after |
| `new_total_shares` | `u128` | The pool's shares after. `0` in private pools |

## `LiquidityRemoved`

The same fields as `LiquidityAdded`, with `removed_amount_0`, `removed_amount_1` and `burned_shares` instead of the added amounts and minted shares. In private pools, every field after the removed amounts is `0`, including the pool's totals. Read the balances from the [`PoolUpdated`](#poolupdated) event that follows.

## `LiquidityFeePayoutSet`

| Field | Type |
| --- | --- |
| `pool_id` | `u32` |
| `account_id` | `AccountId` |
| `payout_type` | [`FeePayoutType`](https://docs.intear.tech/plach/reference/types.md#feepayouttype) |

Logged by `set_liquidity_fee_payout`, after the `LiquidityFeesCollected` of what the provider earned with its old payout.

## `LiquidityFeesCollected`

| Field | Type | Description |
| --- | --- | --- |
| `pool_id` | `u32` | |
| `account_id` | `AccountId` | The provider |
| `asset_0`, `asset_1` | `AssetId` | The pool's assets |
| `amount_0`, `amount_1` | `u128` | What the provider collected of each, now in its [collected fees](https://docs.intear.tech/plach/guides/fees.md#collected-fees) |

Logged when a provider adds or removes liquidity, changes its payout, or calls `collect_liquidity_fees`, if it earned anything since it last collected.

## Older JSON events

Before it logged Borsh, Plach logged JSON events, which the engine wrapped in its [`dex_event`](https://docs.intear.tech/intear-dex/reference/events.md#dex_event) events. They're only in old transactions. Their `standard` is `"xyk"`, version `1.0.0`, with the same four events in snake case (`pool_updated`, `swap`, `liquidity_added`, `liquidity_removed`). The JSON `swap` has the `request` of the hop (the pool's `asset_in`, `asset_out` and amount, with the swap's `message` and `referrer`) instead of `asset_in` and `asset_out`.
