ethers.js v6.
Reading a Specific Offer
If you already know an offer ID, you can fetch its current state directly from contract storage with a singleoffers call. The returned struct contains the seller address, total assets remaining, price, expiry, and fill history.
Offer IDs are sequential unsigned integers starting from
0. You can enumerate all offers by iterating from 0 to nextOfferId - 1, or by reading the nextOfferId public variable to know the total count.Reading All Offers for a Trading Pair
To discover all offers for a given asset without knowing individual offer IDs, filter theOfferCreated event log by asset address. This returns every offer ever created for that asset. Cross-reference the results against OfferFilled and OfferCancelled events to determine which offers are still active.
Getting Series Info for Deferred Markets
Canopy forward series are identified by a deterministic series ID derived from the asset address and unlock time. Compute the series ID using the venue’s helper function or locally, then read the series data:The series key is
(asset, unlockTime) — the quote token is not part of the series identifier. All deferred fills for the same asset with the same unlock time share a single claim token, regardless of which quote token was used.Checking Claim Token Balances
Each series deploys its own ERC-20 claim token at the address stored inseriesData.claimToken. Once you have that address, interact with it using any standard ERC-20 ABI — no Canopy-specific interface is required for balance and transfer reads.
Previewing Fill Cost
The venue provides a view function to compute the exact quote cost for a prospective fill without sending a transaction:Building a Live Order Book
Reconstructing a full order book for a trading pair requires combining event history with simple state-machine logic. Follow this pattern to build an accurate, always-current view of available liquidity:Index OfferCreated from the deployment block
Query all
OfferCreated events from the contract’s deployment block to the current head. Store each event’s offerId, asset, quote, escrowedAssetAmount, pricePerUnit, expiry, unlockTime, and allowedBuyer fields. Set assetFilled = 0 and status = OPEN for every new record.Apply OfferFilled deltas
For each
OfferFilled event, locate the matching offer by offerId and increment assetFilled by the event’s assetUnits. When assetFilled equals the original escrowed amount, mark the offer FILLED.Remove cancelled offers
For each
OfferCancelled event, mark the corresponding offer CANCELLED. Cancelled offers should be excluded from any live depth calculation.All the information needed for full state reconstruction is encoded in the events themselves. You do not need to make additional contract storage reads during initial sync — the events are self-contained.