> ## Documentation Index
> Fetch the complete documentation index at: https://sonar-cf3aeac7.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# Event payloads

> Fields of the swap and swap-enriched events on the multi-events stream, and how to derive buy or sell from them.

The `data` object of every `event` message is one trade. Its `event` field tells you the kind: `swap` or `swap-enriched`. A `swap-enriched` payload has every `swap` field plus two token objects.

All addresses are lowercase hex strings.

## `swap`

**event** `"swap"`

Event kind.

**chainId** `string`

Chain identifier, for example `"evm:1"`.

**blockNumber** `number`

Block that contains the trade.

**transactionIndex** `number`

Position of the transaction in the block.

**logIndex** `number`

Position of the swap log in the block.

**timestamp** `number`

Block time in Unix epoch **milliseconds**.

**hash** `string`

Transaction hash.

**pool** `string`

Pool address. For pools identified by a 32-byte id (for example Uniswap v4 or PancakeSwap Infinity), this is the `0x`-prefixed 64-hex id.

**poolType** `string`

Protocol of the pool, for example `uniswap-v2`, `uniswap-v3`, `uniswap-v4`, `pancakeswap-v3`, `clanker-v4` or `fourmeme`. Values are lowercase and case-sensitive. Can be missing on some trades. See [Protocols and launchpads](https://sonar-cf3aeac7.mintlify.site/concepts/protocols-and-launchpads.md) and [`GET /protocols`](https://sonar-cf3aeac7.mintlify.site/api-reference/protocols/get-protocols) for the values in use.

**category** `"TRADE"`

Always `"TRADE"`: the stream only carries trades.

**initiator** `string`

Wallet that sent the transaction. This is the field the `sender` filter checks. Empty string if unknown.

**recipient** `string`

Recipient of the swap output. Present only when known.

**token0** `string`

Address of the pool's first token.

**token1** `string`

Address of the pool's second token.

**rawAmount0** `string`

Signed integer amount of `token0` in base units (not adjusted for decimals). **Positive means the token went into the pool** (the trader sold it); negative means it came out of the pool (the trader received it).

**rawAmount1** `string`

Same as `rawAmount0`, for `token1`.

**amount0** `number`

`rawAmount0` adjusted for decimals, with the same sign.

**amount1** `number`

`rawAmount1` adjusted for decimals, with the same sign.

**priceUSD0** `number`

USD price of `token0` at this trade.

**priceUSD1** `number`

USD price of `token1` at this trade.

**amountUSD** `number`

USD value of the trade. This is the field the `tokenAmountUsd` filter checks.

**gasFeesUSD** `number | null`

Gas fee of the transaction in USD, or `null` if unknown.

**nativePriceUSD** `number`

USD price of the chain's native coin at this trade.

**baseToken** `string`

The pool's base token: `token0` or `token1`. It is resolved in this order:

1. If one side is a stablecoin, the other side is the base.
2. Otherwise, if one side is the native coin or its wrapped version (for example WETH), the other side is the base.
3. Otherwise, if one side is another token ChainQuery treats as a quote asset, the other side is the base.
4. Otherwise, `token0` is the base.

For a memecoin/WETH pool the base is the memecoin; for a WETH/USDC pool it is WETH.

### Example

A purchase of about 71.4 WETH for 250,000 USDC on Ethereum. USDC went into the pool (`rawAmount0` positive) and WETH came out (`rawAmount1` negative), so the trader bought WETH.

```json theme={null}
{
  "type": "event",
  "id": "weth-whales",
  "channel": "multi-events",
  "cursor": "26745120-0:3",
  "data": {
    "event": "swap",
    "chainId": "evm:1",
    "blockNumber": 26745120,
    "transactionIndex": 4,
    "logIndex": 12,
    "timestamp": 1796306723000,
    "hash": "0xbb7ce5c3afbaa8efb27bf846d21168e4cb76fd20607a4077cb81a211c0b0059b",
    "pool": "0x88e6a0c2ddd26feeb64f039a2c41296fcb3f5640",
    "poolType": "uniswap-v3",
    "category": "TRADE",
    "initiator": "0x6121f0e92f2514beaa3d73c671cc3ba246724895",
    "recipient": "0x6121f0e92f2514beaa3d73c671cc3ba246724895",
    "token0": "0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48",
    "token1": "0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2",
    "rawAmount0": "250000000000",
    "rawAmount1": "-71428571428571428571",
    "amount0": 250000,
    "amount1": -71.42857142857143,
    "priceUSD0": 1,
    "priceUSD1": 3500,
    "amountUSD": 250000,
    "gasFeesUSD": 4.12,
    "nativePriceUSD": 3500,
    "baseToken": "0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2"
  }
}
```

## `swap-enriched`

Every field of `swap`, with `event` set to `"swap-enriched"`, plus:

**baseTokenData** `object | null`

Metadata of the token named by `baseToken`, or `null`.

**properties**

**address** `string`

Token address.

**name** `string`

Token name.

**symbol** `string`

Token symbol.

**decimals** `number`

Token decimals.

**logo** `string | null`

Logo URL, or `null`.

**priceUSD** `number`

USD price of the token **at this trade**: the matching `priceUSD0` or `priceUSD1` of the swap, not a separate price feed.

**quoteTokenData** `object | null`

The same object for the other token of the pool (whichever of `token0` and `token1` isn't `baseToken`), or `null`.

A token object is `null` when:

* the token isn't in ChainQuery's token store yet, or
* the metadata lookup failed or took longer than 2 seconds. The event is then sent without enrichment and isn't sent again.

Treat `null` as "metadata unavailable" and fall back to the address. Token metadata can be a few seconds old.

Subscribers that only ask for `swap` never wait for enrichment. A `swap-enriched` event can arrive slightly later than the `swap` event for the same trade.

### Example

A sale of 2 WETH for USDC on Base.

```json theme={null}
{
  "type": "event",
  "id": "enriched-trades",
  "channel": "multi-events",
  "pair": "swap-enriched|evm:8453",
  "cursor": "55410325-0:7",
  "data": {
    "event": "swap-enriched",
    "chainId": "evm:8453",
    "blockNumber": 55410325,
    "transactionIndex": 61,
    "logIndex": 233,
    "timestamp": 1796306723000,
    "hash": "0x765bdbd2080bb6529ad2b6afb4f90fa572c2ce6115953d45b35efcf145273adf",
    "pool": "0xd0b53d9277642d899df5c87a3966a349a798f224",
    "poolType": "uniswap-v3",
    "category": "TRADE",
    "initiator": "0x5582745e183cfc16288678e29f7a1ae4ad8b00ad",
    "token0": "0x4200000000000000000000000000000000000006",
    "token1": "0x833589fcd6edb6e08f4c7c32d4f71b54bda02913",
    "rawAmount0": "2000000000000000000",
    "rawAmount1": "-6849310000",
    "amount0": 2,
    "amount1": -6849.31,
    "priceUSD0": 3425.1,
    "priceUSD1": 0.9999,
    "amountUSD": 6849.31,
    "gasFeesUSD": 0.01,
    "nativePriceUSD": 3425.1,
    "baseToken": "0x4200000000000000000000000000000000000006",
    "baseTokenData": {
      "address": "0x4200000000000000000000000000000000000006",
      "name": "Wrapped Ether",
      "symbol": "WETH",
      "decimals": 18,
      "logo": "https://assets.coingecko.com/coins/images/2518/large/weth.png",
      "priceUSD": 3425.1
    },
    "quoteTokenData": {
      "address": "0x833589fcd6edb6e08f4c7c32d4f71b54bda02913",
      "name": "USD Coin",
      "symbol": "USDC",
      "decimals": 6,
      "logo": null,
      "priceUSD": 0.9999
    }
  }
}
```

## Deriving buy or sell

The payload has no `type` or side field. Work it out from the sign of the raw amount of a reference token:

* If the reference token's raw amount is **positive**, the token went into the pool: the trader **sold** it.
* Otherwise (negative or zero), it came out of the pool: the trader **bought** it.

Use the token you care about as the reference. If you don't have one, use `baseToken`. This is the same rule the server uses for the [`type` filter](https://sonar-cf3aeac7.mintlify.site/streams/filters#type-buy-or-sell).

```js JavaScript theme={null}
function sideOf(swap, token = swap.baseToken) {
  // Fall back to the base token if the token isn't in this pool.
  const ref = token === swap.token0 || token === swap.token1 ? token : swap.baseToken;
  const raw = ref === swap.token0 ? swap.rawAmount0 : swap.rawAmount1;
  return BigInt(raw) > 0n ? "sell" : "buy";
}

function describe(swap, token = swap.baseToken) {
  const isToken0 = token === swap.token0;
  return {
    side: sideOf(swap, token),
    amount: Math.abs(isToken0 ? swap.amount0 : swap.amount1),
    priceUSD: isToken0 ? swap.priceUSD0 : swap.priceUSD1,
    valueUSD: swap.amountUSD,
  };
}
```

```python Python theme={null}
def side_of(swap, token=None):
    ref = token if token in (swap["token0"], swap["token1"]) else swap["baseToken"]
    raw = swap["rawAmount0"] if ref == swap["token0"] else swap["rawAmount1"]
    return "sell" if int(raw) > 0 else "buy"

def describe(swap, token=None):
    token = token or swap["baseToken"]
    is_token0 = token == swap["token0"]
    return {
        "side": side_of(swap, token),
        "amount": abs(swap["amount0"] if is_token0 else swap["amount1"]),
        "priceUSD": swap["priceUSD0"] if is_token0 else swap["priceUSD1"],
        "valueUSD": swap["amountUSD"],
    }
```

Parse raw amounts as big integers (`BigInt` in JavaScript, `int` in Python). They often exceed the safe integer range of a JavaScript number.

In the Ethereum example above, the base token is WETH and `rawAmount1` is negative, so the trade is a WETH **buy**. In the Base example, the base token is WETH and `rawAmount0` is positive, so it is a WETH **sell**.

## Field names in filters and payloads

Filters use different names from the payload for some fields:

| Filter field | Payload field |
| - | - |
| `poolType` | `poolType` |
| `poolAddress` | `pool` |
| `tokenAddress` | `token0` or `token1` |
| `sender` | `initiator` |
| `tokenAmountUsd` | `amountUSD` |
| `type` | Not in the payload; derived as above |

See [Filters](https://sonar-cf3aeac7.mintlify.site/streams/filters.md).


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.