EVM Router Events
EVM Router emits events for all important contract operations, including swaps, integrator fee distributions, and handler management. These events are essential for tracking contract activity, monitoring integrations, and building analytics.Event: Swap
Emitted whenever a swap is executed successfully, regardless of whether it uses swap, swapIntegrator, or swapWithPermit.
Signature
Parameters
| Parameter | Type | Description |
|---|---|---|
sender | address | Address that executed the swap transaction (msg.sender) |
amount_in | uint256 | Amount of input tokens swapped (in token’s smallest unit) |
amount_out | uint256 | Amount of output tokens received by the destination (after surplus capping, before integrator fees) |
token_in | address | Contract address of the input token |
token_out | address | Contract address of the output token |
destination | address | Address that received the output tokens (or msg.sender if route.destination == address(0)) |
When Emitted
- After successful execution of
swap() - After successful execution of
swapIntegrator()(amount_out is user amount after integrator fee) - After successful execution of
swapWithPermit()
Usage Example
Important Notes
- Surplus Handling:
amount_outreflects the actual amount sent to destination, which may be capped atroute.amount_outif surplus exists - Integrator Fees: When using
swapIntegratorwith fee-based model,amount_outis the user amount AFTER integrator fee deduction - Indexed Fields: None of the fields are indexed, so filtering requires querying all Swap events and filtering in application code
Event: IntegratorFeeDistribution
Emitted when integrator fees or surplus are distributed during a swapIntegrator call.
Signature
Parameters
| Parameter | Type | Description |
|---|---|---|
integrator | address indexed | Address of the integrator receiving the fee/surplus share |
integrator_amount | uint256 | Amount of tokens sent to the integrator |
user_amount | uint256 | Amount of tokens sent to the user (matches amount_out in the corresponding Swap event) |
When Emitted
- Only emitted when
swapIntegrator()is called - Emitted when
integrator_amount > 0(either fee or surplus share) - Not emitted if integrator parameters are provided but no fee/surplus is distributed
Usage Example
Important Notes
- Indexed Field:
integratoris indexed, allowing efficient filtering by integrator address - Fee vs Surplus: The event doesn’t distinguish between fee-based and surplus-based distributions
- Zero Amounts: Event is not emitted if
integrator_amount == 0 - Correlation: Always check for a corresponding
Swapevent in the same transaction
Event: AddHandler
Emitted when a new swap handler is set for a protocol ID.
Signature
Parameters
| Parameter | Type | Description |
|---|---|---|
protocol_id | int24 | Protocol identifier for which the handler is set |
handler | address | Address of the swap handler contract |
When Emitted
- When
setSwapHandler()is called successfully - Only emitted by the contract owner
- Emitted once per protocol ID (handler can only be set once)
Usage Example
Important Notes
- One-Time Event: Handler can only be set once per protocol ID
- Owner Only: Only contract owner can trigger this event
- Handler Removal: Use
SwapHandlerRemovedevent to track handler removals
Event: SwapHandlerRemoved
Emitted when a swap handler is removed for a protocol ID.
Signature
Parameters
| Parameter | Type | Description |
|---|---|---|
protocol_id | int24 | Protocol identifier for which the handler was removed |
When Emitted
- When
removeSwapHandler()is called successfully - Only emitted by the contract owner
- Handler address is set to
address(0)after removal
Usage Example
Important Notes
- Owner Only: Only contract owner can trigger this event
- Handler State: After removal,
getSwapHandler(protocol_id)returnsaddress(0) - Swap Failures: Swaps using removed handlers will revert with
SwapHandlerNotSet()
Event: SetNativeTokenSupport
Emitted when native token support is enabled or disabled for a protocol.
Signature
Parameters
| Parameter | Type | Description |
|---|---|---|
protocol_id | int24 | Protocol identifier for which native token support is configured |
support | bool | true if native token support is enabled, false if disabled |
When Emitted
- When
setNativeTokenSupport()is called successfully - Only emitted by the contract owner
- Controls whether the protocol can handle native token swaps (e.g., MONAD ↔ WMONAD conversion)
Usage Example
Important Notes
- Owner Only: Only contract owner can trigger this event
- Protocol-Specific: Each protocol can have independent native token support settings
- Conversion Logic: When enabled, router automatically converts native ↔ wrapped tokens as needed
Event Monitoring Best Practices
1. Indexed Fields
OnlyIntegratorFeeDistribution.integrator is indexed. For efficient filtering:
2. Event Correlation
Correlate related events in the same transaction:3. Error Handling
Always handle event parsing errors:4. Block Range Queries
Use appropriate block ranges for event queries:5. Event Storage
Store event data efficiently:Event Indexing and Filtering
Efficient Filtering Strategies
Filter by Token Pair
Filter by Integrator
Filter by Sender
Event Analytics Examples
Calculate Total Volume
Track Integrator Earnings
Monitor Handler Changes
Related Documentation
- EVM Router Swap Functions - Complete guide to swap functions
- Integration Guide - Best practices for integrating with Fibrous API
- Contract Addresses - EVM Router deployment addresses