Skip to main content

Position

Tracks the full lifecycle of a trading position from open through close. Mutable — updated on increase, reduction, margin changes, and settlement.
type Position @entity {
  id: ID!                    # positionId (uint256)
  account: Account!          # Owner (indexed for filtering)
  pairId: Bytes!             # Currency pair identifier
  side: Int!                 # 0 = LONG, 1 = SHORT
  tenor: Int!                # 0 = TEST_60S, 1 = ONE_DAY, 2 = ONE_WEEK, 3 = ONE_MONTH
  notional: BigInt!          # Position size (USDC 6 decimals)
  entryStrike: BigInt!       # Forward price at open (18 decimals, signed)
  fixingTimestamp: BigInt!   # Maturity date
  imLocked: BigInt!          # Locked initial margin
  mmThreshold: BigInt!       # Maintenance margin threshold
  snapshotImBps: Int!        # IM factor at open
  snapshotMmBps: Int!        # MM factor at open
  status: String!            # "OPEN", "CLOSED_MATURITY", "CLOSED_EARLY", "LIQUIDATED", "REDUCED" (indexed)
  closeReason: String        # null while open
  closedPrice: BigInt        # Settlement price (null while open)
  realizedPnl: BigInt        # Capped PnL (null while open, signed)
  marketPnl: BigInt          # Uncapped PnL (null while open, signed)
  openTxHash: Bytes!
  closeTxHash: Bytes
  openBlock: BigInt!
  closeBlock: BigInt
  openTimestamp: BigInt!     # Indexed for time-range queries
  closeTimestamp: BigInt
  createdAt: BigInt!
  updatedAt: BigInt!
}
Indexed fields: account, status, openTimestamp
The tenor ordinal in the subgraph does not match the Solidity enum. Subgraph uses 0 = TEST_60S, 1 = ONE_DAY, 2 = ONE_WEEK, 3 = ONE_MONTH. The Solidity Tenor enum uses 0 = ONE_DAY, 1 = ONE_WEEK, 2 = ONE_MONTH, 3 = TEST_60S. Always use the string status field rather than ordinals when filtering positions.

Account

Tracks a trader’s margin account state and LP position. Mutable — updated on every collateral or position event.
type Account @entity {
  id: ID!                    # Ethereum address
  collateralBalance: BigInt! # Total deposited collateral
  imLockedTotal: BigInt!     # Total locked margin across positions
  availableBalance: BigInt!  # Free collateral (collateral - locked)
  positionCount: Int!        # Total positions ever opened
  openPositionCount: Int!    # Currently open positions
  positions: [Position!]!    # Derived from Position.account
  totalRealizedPnl: BigInt!  # Cumulative realized PnL (signed)
  lpShares: BigInt!          # Pool shares held
  lpAssetsDeposited: BigInt! # Total USDC deposited as LP
  createdAt: BigInt!
  updatedAt: BigInt!
}
The positions field is a reverse lookup derived from Position.account — it does not store position IDs directly.

PoolState

Singleton entity tracking the liquidity pool’s aggregate state. ID is always "pool".
type PoolState @entity {
  id: ID!                          # "pool"
  totalAssets: BigInt!             # Total USDC in vault
  totalShares: BigInt!             # Total pool shares outstanding
  netExposure: BigInt!             # Net directional exposure (signed)
  grossNotional: BigInt!           # Total gross notional
  sharePrice: BigDecimal!          # Current share price (division result)
  totalPnlApplied: BigInt!         # Cumulative PnL applied (signed)
  totalFeesCollected: BigInt!      # Total fees across all types
  liquidationFeesCollected: BigInt!
  terminationFeesCollected: BigInt!
  tradingFeesCollected: BigInt!
  oracleFeesCollected: BigInt!
  depositCount: Int!               # Total LP deposits
  withdrawCount: Int!              # Total LP withdrawals
  updatedAt: BigInt!
}

OracleRound

Tracks forward price rounds published by the publisher. Mutable — the isLatest flag is updated when a newer round supersedes it.
type OracleRound @entity {
  id: ID!                    # "fixingTimestamp-roundId"
  fixingTimestamp: BigInt!
  forwardPrice: BigInt!      # Forward price (18 decimals, signed)
  roundId: BigInt!
  publishTime: BigInt!
  isLatest: Boolean!         # Indexed — true for the most recent round per fixing timestamp
  createdAt: BigInt!
}
Indexed fields: isLatest

FixingPrice

Immutable record of a settlement fixing price recorded from Pyth. One per (pairId, fixingTimestamp) combination.
type FixingPrice @entity(immutable: true) {
  id: ID!                    # "pairId-fixingTimestamp"
  pairId: Bytes!
  fixingTimestamp: BigInt!
  price: BigInt!             # Fixing price (18 decimals)
  txHash: Bytes!
  block: BigInt!
  timestamp: BigInt!
}

OracleState

Singleton tracking aggregate oracle statistics. ID is always "oracle".
type OracleState @entity {
  id: ID!                    # "oracle"
  forwardRoundCount: Int!    # Total forward rounds published
  fixingPriceCount: Int!     # Total fixing prices recorded
  updatedAt: BigInt!
}

ModeTransition

Immutable audit trail of every operating mode change.
type ModeTransition @entity(immutable: true) {
  id: ID!                    # "txHash-logIndex"
  fromMode: Int!             # 0 = NORMAL, 1 = REDUCE_ONLY, 2 = PAUSED
  toMode: Int!
  reasonCode: Bytes!         # keccak256 of reason string
  actor: Bytes!              # Address that triggered the transition
  timestamp: BigInt!
  block: BigInt!
  txHash: Bytes!
}

ProtocolState

Singleton tracking current protocol mode and transition history. ID is always "protocol".
type ProtocolState @entity {
  id: ID!                          # "protocol"
  currentMode: Int!                # Current operating mode ordinal
  lastModeTransition: ModeTransition  # Reference to most recent transition
  modeTransitionCount: Int!
  oracleInvalidatedCount: Int!
  updatedAt: BigInt!
}

FeeEvent

Immutable record of fee collection events from SettlementEngine.
type FeeEvent @entity(immutable: true) {
  id: ID!                    # "txHash-logIndex"
  feeType: Int!              # 0 = liquidation, 1 = early termination
  amount: BigInt!            # Fee amount (USDC 6 decimals)
  positionId: BigInt!
  txHash: Bytes!
  block: BigInt!
  timestamp: BigInt!
}

PositionReduction

Immutable record of each partial position reduction.
type PositionReduction @entity(immutable: true) {
  id: ID!                    # "txHash-logIndex"
  position: Position!        # Reference to the reduced position
  account: Bytes!
  reductionNotional: BigInt! # Notional amount reduced
  remainingNotional: BigInt! # Notional remaining after reduction
  settledPnl: BigInt!        # PnL settled on the reduced portion (signed)
  fee: BigInt!               # Fee charged on reduction
  txHash: Bytes!
  block: BigInt!
  timestamp: BigInt!
}

VaultEvent

Immutable record of LP deposit and withdrawal events.
type VaultEvent @entity(immutable: true) {
  id: ID!                    # "txHash-logIndex"
  type: String!              # "DEPOSIT" or "WITHDRAW"
  sender: Bytes!
  owner: Bytes!
  assets: BigInt!            # USDC amount (6 decimals)
  shares: BigInt!            # Pool shares minted or burned
  txHash: Bytes!
  block: BigInt!
  timestamp: BigInt!         # Indexed for time-range queries
}
Indexed fields: timestamp

PoolTransaction

Unified activity feed combining all position-related events into a single timeline. Immutable.
type PoolTransaction @entity(immutable: true) {
  id: ID!                    # "txHash-logIndex"
  type: String!              # "OPEN", "INCREASED", "MATURED", "EARLY_CLOSE", "LIQUIDATED", "REDUCED"
  positionId: BigInt!
  account: Bytes!
  notional: BigInt!          # Context-dependent: open notional, additional notional, reduction notional
  pnl: BigInt                # Realized PnL (null for opens/increases, signed)
  tradingFee: BigInt         # Trading/liquidation/termination fee (null if none)
  oracleFee: BigInt          # Oracle fee (null if none)
  txHash: Bytes!
  block: BigInt!
  timestamp: BigInt!         # Indexed for time-range queries
}
Indexed fields: timestamp

DailyStats

Daily aggregate analytics. Mutable — updated throughout each day.
type DailyStats @entity {
  id: ID!                    # Unix day number (timestamp / 86400)
  date: String!              # Human-readable date
  positionsOpened: Int!
  positionsClosed: Int!
  totalVolume: BigInt!       # Total notional volume
  totalPnl: BigInt!          # Aggregate PnL (signed)
  totalFees: BigInt!         # Aggregate fees collected
  forwardRounds: Int!        # Forward price updates
}

Field Type Conventions

GraphQL TypeUsage
BigIntMoney amounts, timestamps, block numbers, prices
BigDecimalDivision results only (share price)
IntCounters, enum ordinals, basis points
BytesAddresses, tx hashes, pair IDs
StringStatus labels, event type labels, dates
BooleanFlags (e.g., isLatest)

Query Examples

Common query patterns for each entity.

Pagination

Cursor-based pagination and filtering.

Types Reference

Solidity enum ordinals and struct definitions.