Skip to content

# 5. Replace the Starter GraphQL Schema With SO4 Protocol Entities #182

Description

@IbrahimIjai

Primary outcome: The SubQuery schema models SO4 markets, pools, orders, positions, fees, referrals, and protocol events.

Background

The current starter schema indexes generic accounts, payments, credits, debits, and transfer events. SO4 needs protocol entities based on real contract events and market state: mkt_new, dep_*, wth_*, ord_*, pos_*, liq_*, adl_*, fee/referral events, and token/faucet activity.

Implementation checklist

  • Replace or extend apps/s03-indexer/schema.graphql with SO4-specific entities.
  • Add market and token metadata entities: ProtocolContract, Token, Market, and MarketConfigSnapshot.
  • Add liquidity lifecycle entities: Deposit, Withdrawal, PoolBalanceSnapshot, and MarketTokenTransfer.
  • Add trading lifecycle entities: Order, Position, PositionChange, Liquidation, and AdlEvent.
  • Add fee/referral entities: FeeClaim, UiFeeAccrual, FundingFeeClaim, ReferralCode, TraderReferral, and ReferralOwnershipTransfer.
  • Add useful indexed fields for app filters: account, market, key, status, ledger, timestamp, and transaction hash where available.
  • Preserve numeric precision by storing protocol-scale values as BigInt or strings where needed.
  • Do not downcast USD 1e30 values to JavaScript numbers in mappings.
  • Add schema comments explaining which contract event feeds each entity.
  • Remove starter-only entities unless they are intentionally still used for token/payment observability.

Acceptance checklist

  • subql codegen succeeds with the new schema.
  • Generated types are committed if the project convention requires them.
  • The schema can represent market creation.
  • The schema can represent deposit create, execute, and cancel.
  • The schema can represent withdrawal create, execute, and cancel.
  • The schema can represent order create, update, freeze, execute, and cancel.
  • The schema can represent position increase, decrease, close, liquidation, and ADL reduction.
  • The schema can represent fee claim and referral registration flows.

Verification commands

  • Run bun run --cwd apps/s03-indexer codegen.
  • Run bun run --cwd apps/s03-indexer build.

Metadata

Metadata

Assignees

Labels

GrantFox OSSIssue tracked in GrantFox OSSMaybe RewardedIssue may be eligible for a GrantFox rewardOfficial CampaignCampaign: Official CampaignStellar WaveIssues in the Stellar wave program

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions