This document describes how to handle balance updates across different events (DepositEvent
, WithdrawEvent
, OpenOrderEvent
, CancelOrderEvent
) in the system. The Balance
entity reflects a user's holdings of a specific asset, and it must be properly updated in response to various events in the system.
The Balance
entity tracks the amount of a specific asset held by a user. Here’s the structure of the Balance
entity:
type Balance {
id: ID!
amount: BigInt!
asset: String!
user: String!
}
id
: A unique identifier for the balance, generated by hashing the user and asset.amount
: The amount of the asset the user holds.asset
: The specific asset the balance tracks (e.g., USDC, BTC, etc.).user
: The identifier of the user who holds this balance.For each event type, the system must:
Balance
entity for the specific user and asset combination.amount
field based on the event (either increasing or decreasing the balance).Balance
entity after the adjustment.id
of a Balance
entity is typically generated by hashing a combination of the user
and asset
. This ensures uniqueness across user-asset pairs.