This guide provides examples and best practices for querying the Kodiak Islands subgraph using GraphQL. Whether you're building a dashboard, analysis tool, or integrating with another application, these queries will help you extract the data you need.
Getting Started
To query the Kodiak Islands subgraph, you'll need to:
query {
kodiakIslandProtocols {
id
totalValueLockedUSD
cumulativeTotalFeesUSD
totalPoolCount
}
}
2. List All Vaults
Retrieve all vaults with basic information:
query {
kodiakVaults(first: 100) {
id
name
symbol
totalValueLockedUSD
inputToken {
id
symbol
decimals
}
outputToken {
id
symbol
decimals
}
manager
managerFee
createdTimestamp
}
}
3. Get Vault Details
Get detailed information about a specific vault:
query {
kodiakVault(id: "0x1234567890abcdef1234567890abcdef12345678") {
id
name
symbol
totalValueLockedUSD
cumulativeTotalFeesUSD
cumulativeLpFeesUSD
cumulativeManagerFeesUSD
inputTokenBalance
outputTokenSupply
pricePerShare
volumeUSD
weeklyVolumeUSD
weeklyFeesEarnedUSD
lowerTick
upperTick
apr {
averageApr
}
_token0 {
symbol
}
_token1 {
symbol
}
_token0Amount
_token1Amount
_token0AmountUSD
_token1AmountUSD
}
}
query {
kodiakVaults(
where: {
totalValueLockedUSD_gt: "1000000" # > $1M TVL
}
) {
id
name
totalValueLockedUSD
}
}
Sorting Results
Sort vaults by TVL in descending order:
query {
kodiakVaults(
orderBy: totalValueLockedUSD
orderDirection: desc
) {
id
name
totalValueLockedUSD
}
}
Pagination
For large result sets, use pagination with first and skip:
query {
kodiakVaults(
first: 20 # Get 20 records
skip: 20 # Skip first 20 records (for page 2)
orderBy: totalValueLockedUSD
orderDirection: desc
) {
id
name
totalValueLockedUSD
}
}
Advanced Queries
Get User Activity Across Vaults
Find all deposits and withdrawals for a specific user:
query {
deposits: kodiakDeposits(
where: { from: "0xuser_address_here" }
) {
timestamp
vault {
id
name
}
amountUSD
}
withdraws: kodiakWithdraws(
where: { to: "0xuser_address_here" }
) {
timestamp
vault {
id
name
}
amountUSD
}
}
Compare Multiple Vaults
Compare performance metrics for multiple vaults:
query {
vault1: kodiakVault(id: "0xvault1_address_here") {
id
name
totalValueLockedUSD
weeklyFeesEarnedUSD
apr {
averageApr
}
}
vault2: kodiakVault(id: "0xvault2_address_here") {
id
name
totalValueLockedUSD
weeklyFeesEarnedUSD
apr {
averageApr
}
}
}
Best Practices
Query Only What You Need: Only request the fields you actually need to minimize response size.
Use Pagination: For large collections, always use pagination to prevent timeouts.
Filter Efficiently: Apply filters at the query level rather than filtering results in your application.
Optimize Sorting: Sort at the query level for better performance.
Cache Results: GraphQL responses are highly cacheable. Implement client-side caching for better performance.
Handle Time Data Correctly: Remember that timestamps are in seconds since Unix epoch.
Error Handling
The subgraph may return errors for various reasons:
Invalid query syntax
Non-existent entities or fields
Server timeouts for complex queries
Always implement proper error handling in your application to handle these cases gracefully.
Real-World Use Cases
Building a Dashboard
For a vault performance dashboard, you might combine protocol metrics with vault-specific data:
With these query examples and best practices, you should be well-equipped to extract valuable data from the Kodiak Islands subgraph for your applications.