Tracking Liquidity
This guide explains how to monitor liquidity in OraclePool and how to track changes via events.
Pool Balances
OraclePool exposes a single getter for what it holds:
function getBalances() external view returns (uint256 totalX, uint256 totalY);These balances are what the oracle uses as reserveX / reserveY when computing quotes — there is no separate "reserves vs unallocated" split, no allocator role, and no allocate() function. Anything sitting in the pool participates in pricing.
The pair's tokens are returned together:
function getTokens() external view returns (address tokenX, address tokenY);Reading Current State
(address tokenX, address tokenY) = pool.getTokens();
(uint256 balanceX, uint256 balanceY) = pool.getBalances();Caveat: fees that have already been forwarded to the FeeRewarder are no longer in the pool's balance — getBalances reflects what the pool actually owns at the moment of the call.
Events
Swap Event
Emitted on every swap. Balances change as tokens flow in/out.
event Swap(
address indexed sender,
address indexed recipient,
bool indexed swapXtoY,
uint256 actualAmountIn,
uint256 amountOut,
uint256 feeIn,
uint256 feeOut
);Parameters:
sender- Address that initiated the swap (and implements the swap callback)recipient- Address that received the output tokensswapXtoY- Direction:true= tokenX → tokenY,false= tokenY → tokenXactualAmountIn- Gross amount of input token consumed (includesfeeIn)amountOut- Amount of output token sent torecipientfeeIn- Fee charged on the input side. Non-zero only for Y→X swaps (in tokenY).feeOut- Fee charged on the output side. Non-zero only for X→Y swaps (in tokenY).
Both fee fields cannot be non-zero in the same swap. Fees are transferred to the FeeRewarder immediately after the swap (when one is set); otherwise they remain in the pool.
Balance changes from Swap:
swapXtoY = true(X → Y):balanceX += actualAmountIn,balanceY -= amountOut + feeOutswapXtoY = false(Y → X):balanceY += actualAmountIn - feeIn,balanceX -= amountOut
(Each side then loses the corresponding fee transferred to the FeeRewarder, if set.)
Deposited Event
Emitted when liquidity is added.
event Deposited(
address indexed user,
address indexed receiver,
uint256 amountX,
uint256 amountY,
uint256 shares
);amountX / amountY are the absolute amounts pulled into the pool; shares is the LP token amount minted to receiver.
Withdrawn Event
Emitted when liquidity is removed.
shares is the LP token amount burned from user; amountX / amountY are the absolute amounts sent to receiver.
TypeScript Example: Tracking Liquidity
Python Example
Understanding Balance Changes
From Swaps
For X → Y swaps (swapXtoY = true):
(feeIn is 0 in this direction.)
For Y → X swaps (swapXtoY = false):
(feeOut is 0 in this direction.)
After the swap, the pool transfers feeIn (in tokenIn) and feeOut (in tokenOut) to the FeeRewarder when one is configured. If feeRewarder == address(0), the fees stay in the pool's balance.
From Deposits and Withdrawals
Deposited:balanceX += amountX,balanceY += amountY(andsharesLP tokens minted).Withdrawn:balanceX -= amountX,balanceY -= amountY(andsharesLP tokens burned).
Pool size is capped by getMaxValue() (set by the Factory admin via setMaxValue). Deposits self-cap to getMaxDeposit() so the pool's tokenY-denominated value stays under that cap.
Key Points
The pool uses its raw
tokenX/tokenYbalance as the "reserves" fed to the oracle — there is no separate allocated-vs-unallocated split.The
Swapevent carries seven fields, including bothfeeInandfeeOut. Only one is non-zero per swap.Fees are transferred out to the FeeRewarder immediately after the swap (when set), so
getBalancesreflects the post-fee state.Pool size is gated by
getMaxValue()/setMaxValue(), not by anallocate()function.
Agent Instructions: Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.
Perform an HTTP GET request on the current page URL with the ask query parameter:
The question should be specific, self-contained, and written in natural language. The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.
Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
Last updated