@silo-finance/indexer
v0.0.1
Published
GraphQL client for Silo Finance indexer - fetch markets, positions, and historical data
Downloads
2
Readme
@silo-finance/indexer
GraphQL client for Silo Finance indexer. Fetch markets, positions, vaults, and historical data.
Note: This package fetches data from the Silo indexer (GraphQL). For direct blockchain access, use
@silo-finance/adapter-viem.
Installation
pnpm add @silo-finance/indexerQuick Start
import { createIndexerClient } from "@silo-finance/indexer";
const client = createIndexerClient({
url: "https://your-indexer-url.com",
});
// Fetch all markets on Arbitrum
const markets = await client.getMarkets({ chainId: 42161 });
// Fetch user positions
const positions = await client.getAccountPositions(userAddress, 42161);
// Fetch historical data
const snapshots = await client.getMarketSnapshots({
marketId: "42161-0x...",
from: BigInt(Date.now() / 1000 - 86400 * 7), // Last 7 days
});API
createIndexerClient(config)
Creates an indexer client.
const client = createIndexerClient({
url: "https://indexer.example.com",
headers: { Authorization: "Bearer token" }, // optional
});Methods
| Method | Description |
|--------|-------------|
| isAvailable() | Check if indexer is reachable |
| getSilos(options?) | Get all silos (market pairs) |
| getSilo(configAddress, chainId) | Get a specific silo |
| getMarkets(options?) | Get all markets |
| getMarket(marketAddress, chainId) | Get a specific market |
| getPositions(options?) | Get positions with filters |
| getAccountPositions(address, chainId) | Get all positions for an account |
| getToken(tokenAddress, chainId) | Get token metadata |
| getVaults(options?) | Get all vaults |
| getVault(vaultAddress, chainId) | Get a specific vault |
| getIncentivesPrograms(marketAddress, chainId) | Get incentive programs |
| getMarketSnapshots(options) | Get historical market data |
Query Options
// Pagination
interface PaginationOptions {
limit?: number; // default: 100
offset?: number; // default: 0
}
// Market filters
interface MarketQueryOptions extends PaginationOptions {
chainId?: number;
siloId?: string;
}
// Position filters
interface PositionQueryOptions extends PaginationOptions {
chainId?: number;
account?: Address;
marketId?: string;
openOnly?: boolean;
}
// Historical data
interface SnapshotQueryOptions extends PaginationOptions {
marketId: string;
from?: bigint; // timestamp
to?: bigint; // timestamp
}Data Types
All data uses branded types from @silo-finance/primitives:
import type { MarketData, PositionData, TokenData } from "@silo-finance/indexer";
// MarketData includes:
// - address, chainId, siloId
// - inputToken, sToken, spToken, dToken (TokenData)
// - maxLtv, liquidationThreshold, liquidationFee (Percent)
// - totalSupply, totalBorrowed, liquidity (Amount)
// - utilization, borrowRate, depositRate (Percent)
// PositionData includes:
// - accountAddress, marketId, chainId
// - collateralBalance, protectedBalance, debtBalance (Amount)
// - isOpen, lastUpdatedTimestampUsing with SDK Calculations
Combine indexer data with @silo-finance/core for calculations:
import { createIndexerClient } from "@silo-finance/indexer";
import { calculateLtv } from "@silo-finance/core";
const client = createIndexerClient({ url: "..." });
const market = await client.getMarket(marketAddress, chainId);
const positions = await client.getPositions({ account: userAddress, chainId });
// Use data with SDK calculations
const ltv = calculateLtv({
collateralSilo: {
tokenAddress: market.inputToken.address,
decimals: market.inputToken.decimals,
collateralBalance: positions[0].collateralBalance,
// ...
},
debtSilo: { /* ... */ },
});Type-Safe GraphQL
This package uses gql.tada for type-safe GraphQL queries. Types are automatically inferred from the indexer schema.
# Regenerate types after schema changes
pnpm gql:generateLicense
MIT
