Skip to main content

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

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_out reflects the actual amount sent to destination, which may be capped at route.amount_out if surplus exists
  • Integrator Fees: When using swapIntegrator with fee-based model, amount_out is 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

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: integrator is 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 Swap event in the same transaction

Event: AddHandler

Emitted when a new swap handler is set for a protocol ID.

Signature

Parameters

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 SwapHandlerRemoved event to track handler removals

Event: SwapHandlerRemoved

Emitted when a swap handler is removed for a protocol ID.

Signature

Parameters

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) returns address(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

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

Only IntegratorFeeDistribution.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