For the complete documentation index, see llms.txt. This page is also available as Markdown.

2. Seeing the Intent

To build a reliable hedging service in the Symmio ecosystem, hedgers (PartyB) need to monitor the blockchain events triggered by PartyA's intents. This section shows a basic event-listener implementation using ethers.js or web3.py.

Web3EventPoller

The Web3EventPoller class is a high-level utility that:

  1. Connects to the blockchain using web3.py.

  2. Loads the contract and ABI to interact with its events.

  3. Monitors events such as SendQuote or ForceCancelQuote.

  4. Handles events by delegating to predefined handler classes (e.g. SendQuoteHandler).

  5. Maintains state with an EventPoller instance that manages polling, handles retries, and ensures no events are missed.

Event Poller Internals

EventPoller: A utility script that tracks from_block progress (often persisted in something like Redis) and polls in intervals (poll_interval).

Send Quote Handler

The SendQuoteHandler processes SendQuote events from PartyA. It should validate the event data (e.g., whitelist checks, quote status) and construct and stores a structured payload in Redis for further use by the system.

Extract Event Data and Block Information

  • Retrieves the event arguments (args) and the blockchain block details (block).

Fetch Additional Data for the Symbol and Quote

  • Fetches detailed information about the symbol and quote using their IDs.

  • Maps the raw blockchain data into structured fields for easier access.

Check If the Quote Is Already Processed

Checks the status of the quote. If it has already been processed (status 3), the handler exits early.

Validate PartyB Whitelist

Confirms that the current hedger (PartyB) is authorized to act on this quote. If a whitelist exists and the hedger is not included, the handler skips processing.

Constructing the Payload

Creates a structured dictionary containing all relevant event and blockchain data. This includes trade details (e.g., quoteId, price), contextual metadata (e.g., blockNumber), and hedger-specific information (e.g., partyBmm).

Generate a Unique Key for Redis

Ensures that each event is uniquely identified to avoid duplication in the Redis store.

Logging the Event

Logs the event processing for debugging and traceability.

Store the Event Data in Redis

Stores the payload in Redis using the unique key. The setnx method ensures that the event is only stored if the key does not already exist.

Last updated