v0.5.0
[v0.5.0] - 2024-09-28
Overview
This release introduces significant changes to support dynamic market contracts, moving from a static market structure to a dynamic, multi-contract approach. The key focus of version 0.5.0 is to handle multiple markets more efficiently by adding market identifiers to events and refactoring the event handler logic. Additionally, there are improvements in schema structure and handler performance. Release supports the latest updates of key libraries and tools:
fuels-rs v0.66.5forc 0.63.6fuels-ts v0.94.6.
Added
Market Event Handlers
- MarketRegisterEvent:
A new handler forMarketRegisterEventwas added to track the registration of new markets.- Schema: The following fields were added to the schema for
MarketRegisterEvent:id: The unique identifier for the event.base_asset: The base asset of the market, indexed for querying.quote_asset: The quote asset of the market, indexed for querying.market: The address of the market contract, indexed.timestamp: The time when the event occurred.tx_id: Transaction ID associated with the market registration event.
- Handler: The
MarketRegisterEventhandler records the registration of a market by mapping the base and quote assets to the market contract address.
- Schema: The following fields were added to the schema for
Market Field in Event Types
-
The
marketfield was added to multiple event types to support handling of balances and orders across different markets:- DepositEvent
- WithdrawEvent
- TradeOrderEvent
- OpenOrderEvent
- CancelOrderEvent
- ActiveSellOrder
- ActiveBuyOrder
- Balance
This ensures that each event is tied to a specific market, enabling dynamic contract support.
Updated
GraphQL Schema Enhancements
-
Market Field Addition:
Themarketfield was added to the following GraphQL types:- DepositEvent
- WithdrawEvent
- TradeOrderEvent
- CancelOrderEvent
- OpenOrderEvent
- ActiveSellOrder
- ActiveBuyOrder
- Balance
This change allows each event or balance to be associated with a specific market contract and supports querying of data by market.
-
Event Schema Changes:
- The
tx_idfield was removed from the following event types:TradeOrderEventDepositEventWithdrawEventCancelOrderEventOpenOrderEvent
The
tx_idwas deemed redundant and is now only stored where necessary, improving data efficiency. - The
Refactor Event Handlers
-
Handler Refactor:
- Each event handler (
DepositEventHandler,WithdrawEventHandler,TradeOrderEventHandler,CancelOrderEventHandler) was refactored to include amarketfield and to use the newhandlerWithLoaderpattern. This improves the logic for loading data related to balances and orders, reducing redundant queries.
- Each event handler (
-
Loader Functions:
- Deprecation of Loader Functions:
The explicit loader functions (e.g.,depositEventLoader,cancelOrderEventLoader, etc.) were removed in favor of thehandlerWithLoaderpattern. This provides a more streamlined and efficient way to handle event data without the need for separate loader logic.
- Deprecation of Loader Functions:
Event Handling Improvements
- HandlerWithLoader:
-
The new
handlerWithLoaderpattern was introduced to encapsulate both loading and handling logic within a single function, improving performance and reducing the complexity of event processing. -
Examples:
DepositEventHandlernow loads the relevantBalancedirectly before updating it, reducing redundant database queries.TradeOrderEventHandlerloads both the buyer’s and seller’s balances and updates them atomically, ensuring that trade data is processed efficiently across dynamic markets.
-
Removed
Loader Functions
-
Deprecated Loader Functions:
The following loader functions were removed as part of the migration to thehandlerWithLoadermodel:cancelOrderEventLoaderdepositEventLoaderopenOrderEventLoadertradeOrderEventLoaderwithdrawEventLoader
By consolidating the loading logic into the event handlers, these functions are no longer necessary.
Key Improvements
-
Dynamic Market Support:
With the introduction of themarketfield across events and balances, the indexer now fully supports dynamic market contracts. This is a shift from the previous static market model, allowing for greater flexibility in handling multiple contracts. -
Optimized Event Handling:
ThehandlerWithLoaderpattern optimizes the way events are processed, reducing the number of queries and improving overall performance. -
Simplified Schema:
The removal of unnecessary fields liketx_idand the addition of indexed fields such asmarketenhances the clarity and efficiency of the GraphQL schema.
Full Changelog: v0.4.0...v0.5.0