2. Seeing the Intent
To build a robust hedging service in the SYMMIO ecosystem, it's crucial for hedgers (PartyB) to monitor blockchain events triggered by PartyA's intents. This section shows a basic implementation of an event listener using ethers.js or web3.py.

Web3EventPoller
The Web3EventPoller class is a high-level utility designed to:
Connect to the Blockchain: Establish a connection to the blockchain network using
web3.py.Load Contract and ABI: Use the contract's address and ABI to interact with its events.
Monitor Events: Listen for specific on-chain events such as
SendQuoteorForceCancelQuote.Handle Events: Delegate event handling to predefined handler classes (e.g.,
SendQuoteHandler).Maintain State: Use an
EventPollerinstance to manage event polling, handle retries, and ensure 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
