import type { Chain } from "../types" import { getAccountTokenActivityPath, getBatchTokensPath, getSwapExecutePath, getSwapQuotePath, getTokenActivityPath, getTokenActivityStatsPath, getTokenGroupPath, getTokenGroupsPath, getTokenHoldersPath, getTokenLiquidityPoolsPath, getTokenOhlcvPath, getTokenPath, getTokenPriceHistoryPath, getTopTokensPath, getTrendingTokensPath, } from "./apiPaths" import type { Fetcher } from "./fetcher" import type { BatchTokensRequest, GetAccountTokenActivityArgs, GetAccountTokenActivityResponse, GetSwapQuoteArgs, GetSwapQuoteResponse, GetTokenGroupResponse, GetTokenGroupsArgs, GetTokenGroupsResponse, GetTokenResponse, GetTokensArgs, GetTopTokensResponse, GetTrendingTokensResponse, OhlcvResponse, PriceHistoryResponse, SwapExecuteRequest, SwapExecuteResponse, TokenActivityArgs, TokenActivityStatsArgs, TokenActivityStatsResponse, TokenBatchResponse, TokenHoldersArgs, TokenHoldersResponse, TokenLiquidityPoolsArgs, TokenLiquidityPoolsResponse, TokenSwapActivityPaginatedResponse, TokenTimeSeriesArgs, } from "./types" /** * Token-related API operations */ export class TokensAPI { constructor(private fetcher: Fetcher) {} /** * Gets a list of trending tokens. */ async getTrendingTokens( args?: GetTokensArgs, ): Promise { const response = await this.fetcher.get( getTrendingTokensPath(), args, ) return response } /** * Gets a list of top tokens. */ async getTopTokens(args?: GetTokensArgs): Promise { const response = await this.fetcher.get( getTopTokensPath(), args, ) return response } /** * Gets a swap quote. */ async getSwapQuote(args: GetSwapQuoteArgs): Promise { const response = await this.fetcher.get( getSwapQuotePath(), args, ) return response } /** * Get executable transactions for a token swap. * Supports same-chain and cross-chain swaps with multiple from/to assets. */ async executeSwap(request: SwapExecuteRequest): Promise { return this.fetcher.post(getSwapExecutePath(), request) } /** * Gets details for a specific token. */ async getToken(chain: string, address: string): Promise { const response = await this.fetcher.get( getTokenPath(chain, address), ) return response } /** * Gets a paginated list of token groups (equivalent currencies across chains). */ async getTokenGroups( args?: GetTokenGroupsArgs, ): Promise { return this.fetcher.get(getTokenGroupsPath(), args) } /** * Gets a single token group by its slug. */ async getTokenGroup(slug: string): Promise { return this.fetcher.get(getTokenGroupPath(slug)) } /** * Fetch multiple tokens in a single request by chain + contract address. */ async getTokensBatch( request: BatchTokensRequest, ): Promise { return this.fetcher.post(getBatchTokensPath(), request) } /** * Fetch the price history of a token. `start_time` is required and the * default `end_time` is "now". */ async getTokenPriceHistory( chain: Chain, address: string, args: TokenTimeSeriesArgs, ): Promise { return this.fetcher.get( getTokenPriceHistoryPath(chain, address), args, ) } /** * Fetch OHLCV (open / high / low / close / volume) candles for a token. * `startTime` and `bucketSize` are required. */ async getTokenOhlcv( chain: Chain, address: string, args: TokenTimeSeriesArgs & { bucketSize: string }, ): Promise { return this.fetcher.get( getTokenOhlcvPath(chain, address), args, ) } /** * Fetch recent swap activity for a token. */ async getTokenActivity( chain: Chain, address: string, args?: TokenActivityArgs, ): Promise { return this.fetcher.get( getTokenActivityPath(chain, address), args, ) } /** * Fetch materialized trade count, USD volume, and average trade size for a * token across the requested windows. */ async getTokenActivityStats( chain: Chain, address: string, args?: TokenActivityStatsArgs, ): Promise { return this.fetcher.get( getTokenActivityStatsPath(chain, address), args ? { windows: args.windows?.join(",") } : undefined, ) } /** * Fetch paginated fungible token activity (transfers, swaps, wraps, and * unwraps) for an account across all chains. */ async getAccountTokenActivity( address: string, args?: GetAccountTokenActivityArgs, ): Promise { return this.fetcher.get( getAccountTokenActivityPath(address), args, ) } /** * Fetch paginated holders for a token, including quantity held, USD value, * and an aggregate distribution health label (STRONG | HEALTHY | * CONCERNING | BAD). */ async getTokenHolders( chain: Chain, address: string, args?: TokenHoldersArgs, ): Promise { return this.fetcher.get( getTokenHoldersPath(chain, address), args, ) } /** * Fetch liquidity pools for a token (pool type, reserves in USD, and * bonding-curve progress / graduation flag where applicable). */ async getTokenLiquidityPools( chain: Chain, address: string, args?: TokenLiquidityPoolsArgs, ): Promise { return this.fetcher.get( getTokenLiquidityPoolsPath(chain, address), args, ) } }