Skip to content

v0.5.0

Compare
Choose a tag to compare
@PaulZhemanov PaulZhemanov released this 27 Sep 21:39
· 120 commits to main since this release

[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.5
  • forc 0.63.6
  • fuels-ts v0.94.6.

Added

Market Event Handlers

  • MarketRegisterEvent:
    A new handler for MarketRegisterEvent was 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 MarketRegisterEvent handler records the registration of a market by mapping the base and quote assets to the market contract address.

Market Field in Event Types

  • The market field 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:
    The market field 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_id field was removed from the following event types:
      • TradeOrderEvent
      • DepositEvent
      • WithdrawEvent
      • CancelOrderEvent
      • OpenOrderEvent

    The tx_id was deemed redundant and is now only stored where necessary, improving data efficiency.

Refactor Event Handlers

  • Handler Refactor:

    • Each event handler (DepositEventHandler, WithdrawEventHandler, TradeOrderEventHandler, CancelOrderEventHandler) was refactored to include a market field and to use the new handlerWithLoader pattern. This improves the logic for loading data related to balances and orders, reducing redundant queries.
  • Loader Functions:

    • Deprecation of Loader Functions:
      The explicit loader functions (e.g., depositEventLoader, cancelOrderEventLoader, etc.) were removed in favor of the handlerWithLoader pattern. This provides a more streamlined and efficient way to handle event data without the need for separate loader logic.

Event Handling Improvements

  • HandlerWithLoader:
    • The new handlerWithLoader pattern was introduced to encapsulate both loading and handling logic within a single function, improving performance and reducing the complexity of event processing.

    • Examples:

      • DepositEventHandler now loads the relevant Balance directly before updating it, reducing redundant database queries.
      • TradeOrderEventHandler loads 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 the handlerWithLoader model:

    • cancelOrderEventLoader
    • depositEventLoader
    • openOrderEventLoader
    • tradeOrderEventLoader
    • withdrawEventLoader

    By consolidating the loading logic into the event handlers, these functions are no longer necessary.


Key Improvements

  • Dynamic Market Support:
    With the introduction of the market field 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:
    The handlerWithLoader pattern optimizes the way events are processed, reducing the number of queries and improving overall performance.

  • Simplified Schema:
    The removal of unnecessary fields like tx_id and the addition of indexed fields such as market enhances the clarity and efficiency of the GraphQL schema.

Full Changelog: v0.4.0...v0.5.0