Subgraph

Querying historical on-chain event data through the Goldsky-indexed GraphQL endpoint.

Overview

The Delphi SDK includes a SubgraphClient that queries on-chain event data indexed by a Goldsky subgraph.

This gives read-only access to historical buys, sells, redemptions, liquidations, and winner submissions without needing an archive node or parsing raw logs.

For more information on using Goldsky to build on Gensyn, click here.

Accessing the Subgraph Client

getSubgraph() returns a SubgraphClient instance configured with the correct Goldsky endpoint for the active network.

import { DelphiClient } from "@gensyn-ai/gensyn-delphi-sdk";

const client = new DelphiClient();
const subgraph = client.getSubgraph();

URL Resolution Order

  1. config.subgraphUrl (constructor option on DelphiClient)

  2. DELPHI_SUBGRAPH_URL environment variable

  3. Network default (Testnet or Mainnet)

Network
Default endpoint

Testnet

https://api.goldsky.com/api/public/project_cmgzfvv29eu3601tm97hzgzg5/subgraphs/test-graph/1.0.0/gn

Mainnet

https://api.goldsky.com/api/public/project_cmgzfvv29eu3601tm97hzgzg5/subgraphs/delphi-mainnet/1.0.0/gn

SubgraphClient API

query(query, variables?)

You can execute any arbitrary GraphQL query against the subgraph. Returns the data field from the response or throws on errors.

getMarketTrades(marketProxy, params?)

Returns all buy and sell events for a given market proxy address, sorted most-recent-first.

Defaults: first = 100, skip = 0.

getMeta()

Returns the current indexed block, deployment hash, and whether the subgraph has indexing errors. Useful for checking data freshness.

Types

SubgraphBuy

SubgraphSell

SubgraphMeta

GraphQL Schema Entities

The subgraph indexes six on-chain event types.

Each entity is available as both a singular query (by id) and a plural collection query with filtering, ordering, and pagination.

Entity
Singular query
Collection query
Description

GatewayBuy

gatewayBuy(id)

gatewayBuys(...)

Share purchase events

GatewaySell

gatewaySell(id)

gatewaySells(...)

Share sale events

GatewayRedemption

gatewayRedemption(id)

gatewayRedemptions(...)

Settled market redemptions

GatewayLiquidation

gatewayLiquidation(id)

gatewayLiquidations(...)

Position liquidations

GatewayWinnerSubmitted

gatewayWinnerSubmitted(id)

gatewayWinnerSubmitteds(...)

Winner declaration events

Initialized

initialized(id)

initializeds(...)

Entity Fields

Common Fields (All Entities)

Field
Type
Description

id

ID!

Unique event identifier

block_number

BigInt!

Block number of the event

timestamp_

BigInt!

Unix timestamp (seconds)

transactionHash_

String!

Transaction hash

contractId_

String!

Gateway contract address

Additional Fields (Specific Entities)

  • GatewayBuy additional fields: marketProxy, buyer, outcomeIdx, tokensIn (USDC, 6-dec), sharesOut (shares, 18-dec)

  • GatewaySell additional fields: marketProxy, seller, outcomeIdx, sharesIn (shares, 18-dec), tokensOut (USDC, 6-dec)

  • GatewayRedemption additional fields: marketProxy, redeemer, sharesIn (18-dec), tokensOut (USDC, 6-dec)

  • GatewayLiquidation additional fields: marketProxy, liquidator, outcomeIndices, sharesIn, totalTokensOut (USDC, 6-dec)

  • GatewayWinnerSubmitted additional fields: marketProxy, winningOutcomeIdx

Collection Query Parameters

All plural queries accept these:

Parameter
Type
Description

first

Int

Max results (default 100, max 1000)

skip

Int

Pagination offset

orderBy

<Entity>_orderBy

Field to sort by (e.g. timestamp_, tokensIn)

orderDirection

OrderDirection

asc or desc

where

<Entity>_filter

Filter conditions

block

Block_height

Query at a specific block height

Filtering (where clause)

Suffix
Operator
Example

(none)

equals

{ marketProxy: "0x..." }

_not

not equals

{ buyer_not: "0x..." }

_gt

greater than

{ timestamp__gt: "1700000000" }

_lt

less than

{ tokensIn_lt: "1000000" }

_gte

greater or equal

{ block_number_gte: "100" }

_lte

less or equal

{ block_number_lte: "500" }

_in

in list

{ outcomeIdx_in: ["0", "1"] }

_not_in

not in list

{ marketProxy_not_in: [...] }

String fields also support: _contains, _contains_nocase, _not_contains, _starts_with, _starts_with_nocase, _ends_with, _ends_with_nocase (and their _not_ variants).

Usage Examples

Here are some common subgraph query examples.

1. Listing recent trades for a given market

2. Querying global recent buys

3. Filtering buys by wallet address

4. Filtering buys by time range

5. Querying redemptions for a given market

6. Querying winner submissions

7. Checking subgraph indexing status

8. Pagination

9. Parsing subgraph values

Last updated