-
Notifications
You must be signed in to change notification settings - Fork 52
Description
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:
- Slow (requires pagination through all trades)
- Expensive (high query complexity)
- 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)