Multi-Hop DEX Swaps: Route vs Pool Events
Group multi-hop swap events into a route without losing pool-level evidence, double-counting intermediate assets or misidentifying the end user.

Overview
When translating these concepts into an integration, keep the scope described by the wallet history api with the result. The examples in wallet transaction history and smart contract event logs show how the same distinction affects neighbouring data questions.
One user swap can execute through several pools and intermediate tokens. Pool events describe local execution steps; a route summary describes a higher-level interpretation of those steps.
Keep the levels separate
Store each pool event with its own identity, participants and asset quantities. Then derive a route interpretation using execution context and a documented rule. The event sender can be a router contract rather than the user. Do not assume that every swap in the same transaction belongs to one simple route.
Worked example: A through B to C
A transaction trades A for B in pool one, then B for C in pool two. A portfolio view generally needs the net A outflow and C inflow, while a market view may need both pool trades. Summing both route turnover and its pool turnover into one metric double-counts the interpretation layers.
Test non-linear execution
Include split routes, refunds and multiple independent swaps in one transaction. Preserve unresolved route assignments rather than forcing all events into a single action. If the interpretation changes, rebuild the route layer from retained events. Report whether volume is measured per pool, per route or per user-facing transaction.
A practical acceptance test
Build a two-pool A-to-B-to-C route with a zero net B holding. Assert two pool trades but one derived route, and ensure the portfolio does not retain B as a final inflow. Then add an independent swap in the same transaction. A route classifier must not merge it solely because the transaction hash matches.
Questions about the topic
Frequently asked questions
Is the router always the economic trader?
No. It may execute on behalf of another participant.
Should intermediate tokens always appear as final holdings?
No. A complete route can have zero net intermediate balance change.
Standards & technical documentation