Track Swap Events
Near real-time monitoring of swap events
Below are the common methods to monitor swap events:
- Polling Swap events for all pairs
- Subscription using eth_subscribe (coming later - HIP-694)
For production environments, itโs highly recommended to use a paid Mirror Node provider for commercial and high-traffic purposes. While Hederaโs public mirror node offers free REST API and JSON API endpoints, they have global rate limits. These are best suited for development or low rate usage scenarios.
Polling Swap Events for all Pairs
โฝ No gas cost
Every time a user executes a swap, the contract emits a โSwapโ event with the updated reserve values for the token pair. The following code demonstrates how to listen to these โSwapโ events for all pairs using either the REST API or JSON RPC.
Listening to โSwapโ events without specifying an address in the filter data will return logs for all pairs on SaucerSwap, as well as other DEXs on Hedera that share the same โtopic0โ hash signature for the โSwapโ event. To identify and filter specific pairs, extract the pairโs EVM address from the log.
When a swap involves multiple liquidity pairs, a successful smart contract call will emit multiple โSwapโ events. To determine the route used, as well as the initial input amount and the final output amount, aggregate all the โSwapโ event logs.