This document describes how to handle balance updates across different events (DepositEventWithdrawEventOpenOrderEventCancelOrderEvent) 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.

1. Balance Entity Structure

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!
}

2. General Strategy for Balance Updates

For each event type, the system must:

  1. Generate or load the Balance entity for the specific user and asset combination.
  2. Adjust the amount field based on the event (either increasing or decreasing the balance).
  3. Save or update the Balance entity after the adjustment.

Key Considerations: