Skip to content

Account.numTrades is 0 for CLOB orderbook trades (enrichedOrderFilleds not counted) #66

@Tydog99

Description

@Tydog99

Bug Description

The Account entity's numTrades field returns 0 for accounts that have traded via the CLOB orderbook, even when they have significant volume and profit recorded.

Evidence

For wallet 0x4c73db6d5db018013fa9b372b4388d12ac0c20a0:

Account entity query:

{
  account(id: "0x4c73db6d5db018013fa9b372b4388d12ac0c20a0") {
    numTrades
    collateralVolume
    profit
    transactions(first: 5) { id }
  }
}

Result:

{
  "numTrades": "0",
  "collateralVolume": "195038943",
  "profit": "-115849799",
  "transactions": []
}
  • numTrades: 0
  • collateralVolume: ~$195 ✓
  • profit: ~-$115 ✓
  • transactions: empty ❌

However, querying enrichedOrderFilleds directly shows 5 trades:

{
  asMaker: enrichedOrderFilleds(where: {maker: "0x4c73db6d5db018013fa9b372b4388d12ac0c20a0"}, first: 10) { id }
  asTaker: enrichedOrderFilleds(where: {taker: "0x4c73db6d5db018013fa9b372b4388d12ac0c20a0"}, first: 10) { id }
}

Result: 2 maker trades + 3 taker trades = 5 total trades

Root Cause Hypothesis

It appears that Account.numTrades and Account.transactions are only incremented for legacy FPMM/AMM trades, not for CLOB orderbook trades (enrichedOrderFilleds/OrderFilledEvent).

Impact

This affects anyone trying to get per-account trade statistics without querying all enrichedOrderFilleds events and counting manually, which is:

  1. Slow (requires pagination through all trades)
  2. Expensive (high query complexity)
  3. Unreliable (indexers often timeout on large batch queries)

Affected Subgraph

Subgraph ID: 81Dm16JjuFSrqz813HysXoUPvzTwE7fsfPk2RTf66nyC

Suggested Fix

Update the orderbook event handler to increment Account.numTrades when processing OrderFilled events, similar to how collateralVolume and profit are already being updated.

Environment

  • Queried via The Graph Gateway
  • Issue observed on multiple accounts with CLOB trading activity
  • Accounts with only FPMM activity may work correctly (not tested)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions