Swap model
Swaps are abstractions on AMM transfers, procotol & chain agnostic. Identifier on Mobula:swap
Note on Swap Direction and Amount Signs:In a swap, tokens move between
addressToken0 and addressToken1. The direction of the swap and the meaning of the amounts can be understood as follows:
- If
amount0is positive, the token ataddressToken0is going into the pool, and it is being swapped for the token ataddressToken1. - If
amount0is negative, the token ataddressToken0is coming out of the pool, meaning the swap is fromaddressToken1toaddressToken0.
amount1 value reflects the opposite movement:
- Positive → token enters the pool
- Negative → token leaves the pool
- Positive
amount0→ swapping Token0 → Token1 - Negative
amount0→ swapping Token1 → Token0
Enriched Swap model
The Enriched Swap extends the basic Swap model withbaseTokenData, post & pre balances, baseToken and quoteToken identification, and derived fields for UI and analytics.
Important: The baseTokenData field contains enriched data (including price, volume, market cap, liquidity, and many other stats) for the base token as determined by baseQuote logic.
Position data on Enriched Swaps
Everyswap-enriched event includes a position object that tracks the swap sender’s (or recipient’s) running position for the base token. This is computed in real-time from on-chain data and historical trades.
| Field | Type | Description |
|---|---|---|
balance | number | Current token balance (human-readable) |
rawBalance | string | Token balance as raw string (unformatted) |
amountUSD | number | Token balance value in USD (balance × currentPrice) |
nativeBalanceRaw | string | Native chain token balance in lamports/wei |
nativeBalance | number | Native chain token balance (formatted, e.g. SOL not lamports) |
buys | number | Total number of buy transactions |
sells | number | Total number of sell transactions |
volumeBuyToken | number | Total tokens bought |
volumeSellToken | number | Total tokens sold |
volumeBuy | number | Total USD value of buys |
volumeSell | number | Total USD value of sells |
avgBuyPriceUSD | number | Average buy price in USD |
avgSellPriceUSD | number | Average sell price in USD |
realizedPnlUSD | number | Realized profit/loss in USD |
unrealizedPnlUSD | number | Unrealized profit/loss in USD |
totalPnlUSD | number | Total P&L (realized + unrealized) |
realizedPnlPercent | number | Realized PnL as percentage of cost basis |
unrealizedPnlPercent | number | Unrealized PnL as percentage of cost basis |
Pool model
Pools are abstractions on AMM pools, protocol & chain agnostic. Identifier on Mobula:pool
Example: