Subgraph
1. Overview
Project name: Earnium Subgraph
Networks supported: Aptos
Subgraph Endpoints:
Subgraph Playground:
Primary use case: TVL/volume tracking, pool stats, token stats
Type Dex: v2
2. Data Model (Entities)
2.1. Core Entities
factory: global stats (TVL, total volume, total fees)
pool: pool with token0/token1, reserve, reserveUSD (liquidity)
token: symbol, decimals, name, volume
swap: trade records with amounts, fee, sender
mint / burn: liquidity add/remove;
transaction: records transaction swap, mint, burn, stake, unstake…
eventStakeUnStake: event stake and unstake
swapFeePaidEvent: event paid swap fee
2.2. Time‑Series Entities
poolDayData / poolHourData / poolMinuteData: volume, fees, transaction count
tokenDayData / tokenHourData / tokenMinuteData: price, volume, fee
factoryDayData / factoryHourData / factoryMinuteData: global stats
3. Detail Data Modal
3.1. Factory
Field
Data Type
Description
txCount
number
Total number of transactions recorded by the Factory (including swaps, mints, burns).
totalTvl
number
Total Value Locked (TVL) across all pools.
totalVolume
number
Cumulative trading volume since inception.
totalFees
number
Total transaction fees collected by the protocol.
typeDex
string
Type of DEX ('V2', 'V3', 'ALL')
.
3.2. Pool
Field
Data Type
Description
name
string
Pool name (identifier, e.g., USDC-USDt
).
address
string
On-chain address of the pool contract.
token0
Token
Reference to the first token entity of the pair.
token1
Token
Reference to the second token entity of the pair.
token0Price
number
Price of token0 in terms of token1
token1Price
number
Price of token1 in terms of token0
volumeToken0
number
Total trading volume of token0.
volumeToken1
number
Total trading volume of token1.
volumeUsd
number
Total trading volume in USD.
reserve0
number
Current reserve of token0 in the pool.
reserve1
number
Current reserve of token1 in the pool.
totalSupply
number
Total supply of pool’s liquidity tokens (LP tokens).
token0Address
string
Contract address of token0.
token1Address
string
Contract address of token1.
token0WrapperAddress
string
Wrapper contract address for token0
token1WrapperAddress
string
Wrapper contract address for token1
type
string
Pool type (V2).
stable
boolean
Indicates whether the pool is a stable swap pool.
feeToken0
number
Fees collected in token0.
feeToken1
number
Fees collected in token1.
reserveUsd
number
Current reserve value converted to USD.
3.3. Token
Field
Data Type
Description
address
string
Contract address of the token.
symbol
string
Token ticker symbol (e.g., USDt
, USDC
).
name
string
Full name of the token.
decimals
number
Number of decimals the token uses (ERC-20 standard).
totalSupply
number
Total supply of the token.
tradeVolume
number
Cumulative trade volume of this token
tradeVolumeUSD
number
Cumulative trade volume converted to USD.
txCount
number
Total number of transactions involving this token.
totalValueLocked
number
Total value locked for this token across pools (liquidity).
price
number
Current token price
feesUSD
number
Accumulated trading fees involving this token in USD.
wrapAddress
string
Wrapper contract address (if token has a wrapped version).
type
string
Token type (COIN, FUNGIBLE_ASSET
).
fee
number
Fee metric associated with the token
3.4. Swap
Field
Data Type
Description
transactionTxnId
string
Transaction version
timestamp
number
Block timestamp when the swap occurred.
poolAddress
string
Address of the pool in which the swap took place.
token0
Token
First token involved in the swap
token1
Token
Second token involved in the swap
sender
string
Address of the account that initiated the swap.
amount0
number
Amount of token0 traded in this swap
amount1
number
Amount of token1 traded in this swap
amountUsd
number
Value of the swap in USD at the time of execution.
feesUsd
number
Total fees collected from the swap in USD.
feeToken0
number
Fees collected in token0
feeToken1
number
Fees collected in token1
eventIndex
number
Log index of the swap event inside the transaction (ensures uniqueness when multiple swaps occur in the same transaction).
3.5. Mint
Field
Data Type
Description
transactionTxnId
string
Transaction version
timestamp
number
Block timestamp when the liquidity was minted.
poolAddress
string
Address of the pool where liquidity was added.
token0
Token
First token in the pool (reference to Token schema).
token1
Token
Second token in the pool (reference to Token schema).
sender
string
Address that initiated the mint transaction.
amount0
number
Amount of token0 provided as liquidity.
amount1
number
Amount of token1 provided as liquidity.
amountUsd
number
Value of the minted liquidity in USD.
amountLp
number
Amount of LP tokens minted
eventIndex
number
Log index of the mint event inside the transaction (ensures uniqueness).
3.6. Burn
Field
Data Type
Description
transactionTxnId
string
Transaction version
timestamp
number
Block timestamp when the liquidity was burned.
poolAddress
string
Address of the pool where liquidity was removed.
token0
Token
First token in the pool (reference to Token schema).
token1
Token
Second token in the pool (reference to Token schema).
amount0
number
Amount of token0 withdrawn.
amount1
number
Amount of token1 withdrawn.
amountUsd
number
Value of the burned liquidity in USD.
amountLp
number
Amount of LP tokens burned
eventIndex
number
Log index of the burn event inside the transaction (ensures uniqueness).
3.7. Transaction
Field
Data Type
Description
txnId
string
Transaction version
timestamp
number
Block timestamp when the transaction was recorded.
data
object
Raw event data associated with the transaction.
type
string
Type of transaction ( CREATE_POOL, MINT, BURN, SWAP, SYNC_EVENT, STAKE, UNSTAKE, SWAP_FEE_PAID_EVENT
).
txHash
string
On-chain transaction hash.
userAddress
string
Address of the user who initiated the transaction.
eventIndex
number
Log index of the transaction event inside the block/transaction.
3.8. eventStakeUnStake
Field
Data Type
Description
data
object
Raw event payload or metadata captured from the stake/unstake transaction.
transactionVersion
number
Transaction version
eventIndex
number
Index of the event within the transaction
pool
string
Address of the staking/unstake pool where the event occurred.
amount
number
Amount of tokens staked or unstaked.
permanentlyLocked
boolean
Indicates if the staked amount is permanently locked.
unlockTime
number
Timestamp when the staked tokens can be unlocked (if not permanently locked).
timestamp
number
Block timestamp when the stake/unstake event occurred.
type
string
Event type (STAKE
, UNSTAKE
).
nftAddress
string
Address of an NFT associated with the staking event
3.9. swapFeePaidEvent
Field
Data Type
Description
swapFeeAmount
number
Amount of swap fees collected in this event.
referrerFeeAmount
number
Amount fee paid to a referrer
tokenAddress
string
Address of the token in which the fee was paid.
timestamp
number
Block timestamp when the fee payment occurred.
poolAddress
string
Address of the pool where the swap happened.
referrerAddress
string
Address of the referrer who received part of the fee.
sender
string
Address of the user who paid the swap fee.
fromToken
Token
Token being swapped from.
toToken
Token
Token being swapped to.
3.10. poolDayData
Field
Data Type
Description
id_1
string
Unique identifier for the daily record (often poolAddress + date
)
date
number
Unix timestamp (start of the day, e.g. midnight UTC) for this snapshot.
poolAddress
string
Address of the pool
volumeUsd
number
Trading volume in USD during this day.
volumeToken0
number
Trading volume of token0 during this day.
volumeToken1
number
Trading volume of token1 during this day.
token0
Token
Reference to token0
token1
Token
Reference to token1.
totalSupply
number
Total LP token supply for the pool
reserve0
number
Snapshot reserve of token0
reserve1
number
Snapshot reserve of token1
feesUsd
number
Snapshot fees collected in USD
feeToken0
number
Snapshot fees token0
feeToken1
number
Snapshot fees token1
3.11. poolHourData
Field
Data Type
Description
id_1
string
Unique identifier for the hourly record (often poolAddress + hourStartUnix
).
hourStartUnix
number
Unix timestamp marking the start of the hour
poolAddress
string
Address of the pool
totalSupply
number
Total LP token supply for the pool
reserve0
number
Snapshot reserve of token0
reserve1
number
Snapshot reserve of token1
hourlyVolumeToken0
number
Trading volume of token0 during the hour.
hourlyVolumeToken1
number
Trading volume of token1 during the hour.
hourlyVolumeUSD
number
Trading volume in USD during the hour.
feesUsd
number
Total fees collected in USD during the hour.
feeToken0
number
Fees collected token0
feeToken1
number
Fees collected token1
token0
Token
Reference to token0 entity.
token1
Token
Reference to token1 entity.
3.12. poolMinuteData
Field
Data Type
Description
id_1
string
Unique identifier for the minute-level record (commonly poolAddress + periodStartUnix
).
periodStartUnix
number
Unix timestamp marking the start of the minute interval.
poolAddress
string
Address of the pool
volumeUsd
number
Trading volume in USD during this minute.
volumeToken0
number
Trading volume of token0 during this minute.
volumeToken1
number
Trading volume of token1 during this minute.
token0
Token
Reference to the token0 entity.
token1
Token
Reference to the token1 entity.
totalSupply
number
Total LP token supply
reserve0
number
Snapshot reserve of token0
reserve1
number
Snapshot reserve of token1
feesUSD
number
Total fees collected in USD
feeToken0
number
Fees collected token0
feeToken1
number
Fees collected token1
3.13. tokenDayData
Field
Data Type
Description
id_1
string
Unique identifier for the daily record (commonly tokenAddress + date
).
date
number
Unix timestamp marking the start of the day
token
Token
Reference to the token entity
volumeToken
number
Total trading volume of this token (in token units) during the day.
volumeUsd
number
Total trading volume of this token in USD during the day.
price
number
Price snapshot of the token
totalLiquidityToken
number
Total liquidity available for this token (in token units) across pools at end of day.
totalLiquidityUSD
number
Total liquidity for this token expressed in USD at end of day.
feesUsd
number
Fees collected by this token
feeToken
number
Fees collected in token units
3.14. tokenHourData
Field
Data Type
Description
id_1
string
Unique identifier for the hourly record (commonly tokenAddress + periodStartUnix
).
periodStartUnix
number
Unix timestamp marking the start of the hour (UTC).
token
Token
Reference to the token entity.
volume
number
Trading volume of this token (in token units) during the hour.
volumeUsd
number
Trading volume in USD during the hour.
totalValueLocked
number
Total liquidity available for this token (in token units) at the end of the hour.
totalValueLockedUsd
number
Total liquidity for this token expressed in USD at the end of the hour.
priceUsd
number
Price snapshot of the token in USD
feesUsd
number
Fees collected by this token
feeToken
number
Fees collected by this token
3.14. tokenMinuteData
Field
Data Type
Description
id_1
string
Unique identifier for the minute-level record (commonly tokenAddress + periodStartUnix
).
periodStartUnix
number
Unix timestamp marking the start of the minute interval (UTC).
token
Token
Reference to the token entity.
volume
number
Trading volume of this token
volumeUSD
number
Trading volume of this token in USD during the minute.
totalValueLocked
number
Total liquidity available for this token (in token units) at the end of the minute.
totalValueLockedUsd
number
Total liquidity for this token expressed in USD at the end of the minute.
priceUsd
number
Price snapshot of the token in USD at the end of the minute.
feesUsd
number
Fees collected by this token
fee
number
Fees collected by this token
3.15. factoryDayData
Field
Data Type
Description
id_1
string
Unique identifier for the daily factory (typeDex + date
).
date
number
Unix timestamp marking the start of the day
totalTvl
number
Total Value Locked (TVL) across all pools for this day.
totalVolume
number
Trading volume across the entire DEX during the day.
cumulativeVolume
number
Cumulative trading volume across the DEX since inception (up to this day).
typeDex
string
Type of DEX ('V2', 'V3', 'ALL')
.
totalFees
number
Total fees collected by the DEX during the day.
3.16. factoryHourData
Field
Data Type
Description
id_1
string
Unique identifier for the hourly factory-level record (typeDex + hourStartUnix
).
hourStartUnix
number
Unix timestamp marking the start of the hour (UTC).
totalTvl
number
Total Value Locked (TVL) across all pools at the end of this hour.
totalVolume
number
Trading volume across the DEX during this hour.
cumulativeVolume
number
Cumulative trading volume across the DEX since inception (up to this hour).
typeDex
string
Type of DEX ('V2', 'V3', 'ALL')
.
totalFees
number
Total fees collected by the DEX during this hour.
3.17. factoryMinuteData
Field
Data Type
Description
id_1
string
Unique identifier for the minute-level factory record (typeDex + periodStartUnix
).
periodStartUnix
number
Unix timestamp marking the start of the minute interval (UTC).
totalTvl
number
Total Value Locked (TVL) across all pools
totalVolume
number
Trading volume across the DEX during this minute.
cumulativeVolume
number
Cumulative trading volume across the DEX since inception (up to this minute).
typeDex
string
Type of DEX ('V2', 'V3', 'ALL')
.
totalFees
number
Total fees collected by the DEX during this minute.
4. Subgraph Query Examples
4.1. factory
The factory
entity stores global-level statistics about the entire protocol. Examples include:
totalTvl
→ Total value locked (TVL) across all pools in the protocol.txCount
→ Total number of transactions executed in the protocol.totalVolume
→ Cumulative trading volume across all pools, expressed in USD.totalFees
→ Total fees generated by all pools since inception, expressed in USD.
query factoryQuery {
factory {
totalTvl
txCount
totalVolume
totalFees
typeDex
}
}
4.2 factoryDayData
You can also query historical data by specifying a date.
query factoryDayDataQuery {
factoryDayData(where: {date: {_eq: 1755129600}}) {
id_1
date
totalTvl
totalFees
totalVolume
typeDex
}
}
4.3. pool
4.3.1. Pool query
To get data about a certain pool, pass in the pool address. Reference the full pool schema and adjust the query fields to retrieve the data points you want.
query poolQuery {
pool {
address
name
token0 {
name
}
token1 {
name
}
stable
reserve0
reserve1
}
}
4.3.2 Pool detail query
You can fetch the details of a pool if you know its address.
query poolDetailQuery {
pool(where: {address: {_eq: "0xab9d6e6445deaea449a73d4c7e43d250c62554cba3ce73090fdec3d52688a400"}}) {
address
name
token0 {
name
}
token1 {
name
}
stable
reserve0
reserve1
}
}
4.3.3. Total number of pools
You can fetch the total number of pools currently available.
query poolCountQuery {
poolAggregate {
_count
}
}
4.3.4. Most Liquid Pools
Retrieve the top 10 most liquid pools. You can use this similar set up to order_by
other variables like reserveUsd
.
query poolDetailQuery {
pool(order_by: {reserveUsd: Desc}) {
address
name
token0 {
name
}
token1 {
name
}
stable
reserve0
reserve1
reserveUsd
}
}
4.4. Swap
4.4.1. General Swap Data
To query data for a specific swap, provide the transaction version when querying the swaps entity.
The query will return details such as the sender, token amounts, fee, and timestamp for the selected swap.
query swapDetailQuery {
swap(where: {transactionTxnId: {_eq: "3208087606"}}) {
transactionTxnId
sender
amount0
amount1
feeToken0
feeToken1
timestamp
}
}
4.4.2. Recent Swaps Within a Pool
You can set the where field to filter swap data by pool address. This example fetches data about multiple swaps for the USDC-USDT pool, ordered by timestamp.
query swapQuery {
swap(
where: {poolAddress: {_eq: "0xab9d6e6445deaea449a73d4c7e43d250c62554cba3ce73090fdec3d52688a400"}}
limit: 10
order_by: {timestamp: Desc}
) {
transactionTxnId
sender
amount0
amount1
feeToken0
feeToken1
timestamp
}
}
4.5. Token
4.5.1. Token detail data
This queries the decimals, symbol, name, and volume for the USDt
token.
query tokenDetailQuery {
token(
where: {address: {_eq: "0x357b0b74bc833e95a115ad22604854d6b0fca151cecd94111770e5d6ffc9dc2b"}}
) {
address
name
price
symbol
tradeVolume
}
}
4.5.2. List token
query tokenQuery {
token {
address
name
price
symbol
tradeVolume
}
}
4.5. Mint
4.5.1. General Mint Data
To query data for a specific mint event, provide the transaction ID when querying the mint
entity.
query mintDetailQuery {
mint(where: {transactionTxnId: {_eq: "3208601562"}}) {
id
amount0
amount1
amountUsd
poolAddress
sender
}
}
4.5.2. Recent Mints Within a Pool
You can filter mint events by pool address. This example fetches recent liquidity additions for a given pool, ordered by timestamp.
query mintQuery {
mint(
where: {poolAddress: {_eq: "0xab9d6e6445deaea449a73d4c7e43d250c62554cba3ce73090fdec3d52688a400"}}
limit: 10
order_by: {timestamp: Desc}
) {
transactionTxnId
sender
amount0
amount1
timestamp
amountUsd
poolAddress
}
}
4.6. Burn
4.6.1. General Burn Data
To query data for a specific burn event, provide the transaction ID when querying the burn
entity.
query burnDetailQuery {
burn(where: {transactionTxnId: {_eq: "3213523880"}}) {
id
amount0
amount1
amountUsd
poolAddress
}
}
4.6.2 Recent Burns Within a Pool
You can filter burn events by pool address. This example fetches recent liquidity removals for a given pool, ordered by timestamp.
query burnQuery {
burn(
where: {poolAddress: {_eq: "0xab9d6e6445deaea449a73d4c7e43d250c62554cba3ce73090fdec3d52688a400"}}
limit: 10
order_by: {timestamp: Desc}
) {
transactionTxnId
amount0
amount1
amountUsd
poolAddress
timestamp
}
}
4.7. Transaction
4.7.1. Recent Transactions
You can query the latest transactions across the protocol. This example fetches the most recent 10 transactions, ordered by timestamp (latest first).
query transactionQuery {
transaction(
limit: 10
order_by: {timestamp: Desc}
where: {type: {_in: ["SWAP", "MINT", "BURN"]}}
) {
txnId
txHash
userAddress
type
timestamp
data {
amount0
amount1
amountUsd
}
}
}
4.8. eventStakeUnStake
4.8.1. Recent Stake/Unstake Events in a Pool
You can filter stake/unstake events by pool address. This example fetches the latest 10 events for a specific pool, ordered by timestamp.
query stakeUnstakeQuery {
eventStakeUnStake(
where: {pool: {_eq: "0xab9d6e6445deaea449a73d4c7e43d250c62554cba3ce73090fdec3d52688a400"}}
limit: 10
order_by: {timestamp: Desc}
) {
transactionVersion
pool
amount
type
permanentlyLocked
unlockTime
timestamp
}
}
4.9. swapFeePaidEvent
4.9.1. Recent Swap Fee Events Within a Pool
query swapFeePaidEventQuery {
swapFeePaidEvent(
where: {poolAddress: {_eq: "0xab9d6e6445deaea449a73d4c7e43d250c62554cba3ce73090fdec3d52688a400"}}
limit: 10
order_by: {timestamp: Desc}
) {
sender
poolAddress
tokenAddress
swapFeeAmount
referrerFeeAmount
referrerAddress
timestamp
}
}
Last updated