Overview
The QuantumDEX Subgraph indexes all on-chain events from QuantumDEX contracts and exposes them via a GraphQL API. It is powered by the ThiChain indexer, compatible with The Graph protocol schema conventions.
import { createSubgraphClient } from '@qubismic/quantumdex-subgraph';
const subgraph = createSubgraphClient({
endpoint: 'https://subgraph.thichain.io/quantumdex',
// or testnet:
// endpoint: 'https://subgraph-testnet.thichain.io/quantumdex',
});
Pool Queries
# Get top pools by TVL
query TopPools {
pools(first: 10, orderBy: totalValueLockedUSD, orderDirection: desc) {
id
token0 { symbol, decimals }
token1 { symbol, decimals }
reserve0
reserve1
totalValueLockedUSD
volumeUSD
feeBps
txCount
createdAtTimestamp
}
}
# Get pools for a specific token
query TokenPools($tokenAddress: String!) {
pools(where: { or: [
{ token0: $tokenAddress },
{ token1: $tokenAddress }
]}) {
id
token0 { symbol }
token1 { symbol }
totalValueLockedUSD
}
}
Swap Queries
# Recent swaps for a user
query UserSwaps($user: String!, $first: Int = 20) {
swaps(
first: $first,
where: { sender: $user },
orderBy: timestamp,
orderDirection: desc
) {
id
timestamp
pair { token0 { symbol }, token1 { symbol } }
amount0In
amount1In
amount0Out
amount1Out
amountUSD
feeBps
karmaTier
sender
transactionHash
}
}
# Aggregate swap volume by day
query DailyVolume($startTime: Int!) {
pairDayDatas(
first: 30,
orderBy: date,
orderDirection: desc,
where: { date_gte: $startTime }
) {
date
dailyVolumeUSD
dailyTxns
}
}
Karma Event Queries
# Karma score history for an address
query KarmaHistory($address: String!) {
karmaEvents(
where: { address: $address },
orderBy: blockTimestamp,
orderDirection: desc
) {
id
address
previousScore
newScore
delta
eventType # SWAP, LIQUIDITY, GOVERNANCE, BRIDGE, VIOLATION
yama # Which of the 5 Yamas was relevant
transactionHash
blockTimestamp
}
}
# Karma leaderboard
query KarmaLeaderboard {
karmaProfiles(
first: 100,
orderBy: score,
orderDirection: desc
) {
address
score
tier
totalSwaps
governanceVotes
}
}
Governance Queries
# Active proposals
query ActiveProposals {
proposals(where: { state: ACTIVE }) {
id
proposer
description
forVotes
againstVotes
abstainVotes
startBlock
endBlock
dharmicScore # Six Sages assessment score
state
}
}
# Votes cast by address
query MyVotes($voter: String!) {
votes(where: { voter: $voter }) {
proposal { id, description }
support # 0=Against, 1=For, 2=Abstain
weight
reason
blockTimestamp
}
}
Subscriptions (WebSocket)
import { createSubgraphClient } from '@qubismic/quantumdex-subgraph';
const subgraph = createSubgraphClient({
endpoint: 'wss://subgraph.thichain.io/quantumdex/ws',
});
// Subscribe to new swaps
const unsubscribe = subgraph.subscribe(
`subscription NewSwaps {
swaps(orderBy: timestamp, orderDirection: desc, first: 1) {
id
amountUSD
karmaTier
transactionHash
}
}`,
(data) => {
console.log('New swap:', data.swaps[0]);
}
);
// Clean up on unmount
// unsubscribe();