dexpaprika-sdk
Version:
JavaScript SDK for the DexPaprika API
137 lines (136 loc) • 7.39 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.TokensAPI = void 0;
const base_1 = require("./base");
const searchParams_1 = require("../utils/searchParams");
/**
* API service for token-related endpoints.
*/
class TokensAPI extends base_1.BaseAPI {
/**
* Get detailed information about a specific token on a network.
*
* @param networkId - Network ID (e.g., "ethereum", "solana")
* @param tokenAddress - Token address or identifier
* @returns Detailed information about the token
*/
async getDetails(networkId, tokenAddress) {
return this._get(`/networks/${networkId}/tokens/${tokenAddress}`);
}
/**
* Get a list of top liquidity pools that contain a specific token on a network.
*
* Backed by the unified /networks/{network}/pools/search endpoint with its
* `token_address` parameter (the old /tokens/{address}/pools endpoint was
* removed, HTTP 410). The filter is network-scoped only: the cross-network
* /pools/search endpoint accepts `token_address` but silently ignores it, so
* a network is always required here. Legacy `orderBy` values (e.g.
* 'volume_usd') are mapped to canonical sort fields; the endpoint is
* cursor-paginated (pass `cursor`; read `has_next_page`/`next_cursor` from
* the response; `page` is ignored). An unknown token address returns an
* empty result set, not an error.
*
* @param networkId - Network ID (e.g., "ethereum", "solana")
* @param tokenAddress - Token address or identifier
* @param options - Sorting, limit and cursor pagination options
* @returns Search response with pools that contain the specified token
*/
async getPools(networkId, tokenAddress, options) {
var _a, _b;
const params = {
token_address: tokenAddress,
limit: (_a = options === null || options === void 0 ? void 0 : options.limit) !== null && _a !== void 0 ? _a : 10,
sort: (_b = options === null || options === void 0 ? void 0 : options.sort) !== null && _b !== void 0 ? _b : 'desc',
order_by: (0, searchParams_1.mapPoolSortField)(options === null || options === void 0 ? void 0 : options.orderBy),
};
if (options === null || options === void 0 ? void 0 : options.cursor)
params.cursor = options.cursor;
// Note: options.pairWith is deprecated and intentionally not sent.
// /pools/search has no pair filter. Repeating token_address does not
// act as a pair filter; the API uses only one of the values (not
// guaranteed by order).
return this._get(`/networks/${networkId}/pools/search`, params);
}
/**
* Get top tokens on a network ranked by volume, liquidity, or other metrics.
*
* Backed by the unified /networks/{network}/tokens/search endpoint. Legacy
* `orderBy` values (e.g. 'volume_24h') are accepted and mapped to canonical
* sort fields; the endpoint is cursor-paginated (pass `cursor`; read
* `has_next_page`/`next_cursor` from the response).
*
* @param networkId - Network ID (e.g., "ethereum", "solana")
* @param options - Sorting, limit and cursor pagination options
* @returns Search response with token results
*/
async getTop(networkId, options) {
var _a, _b;
const params = {
limit: (_a = options === null || options === void 0 ? void 0 : options.limit) !== null && _a !== void 0 ? _a : 10,
order_by: (0, searchParams_1.mapTokenSortField)(options === null || options === void 0 ? void 0 : options.orderBy),
sort: (_b = options === null || options === void 0 ? void 0 : options.sort) !== null && _b !== void 0 ? _b : 'desc',
};
if (options === null || options === void 0 ? void 0 : options.cursor)
params.cursor = options.cursor;
return this._get(`/networks/${networkId}/tokens/search`, params);
}
/**
* Filter tokens on a network by volume, liquidity, FDV, transactions, and creation date.
*
* Backed by the unified /networks/{network}/tokens/search endpoint. The request
* sends `order_by` (mapped from the legacy `sortBy`) and `sort` (direction),
* and is cursor-paginated (pass `cursor`; read `has_next_page`/`next_cursor`
* from the response). Legacy filter param names are mapped to canonical ones.
*
* @param networkId - Network ID (e.g., "ethereum", "solana")
* @param options - Filter criteria and cursor pagination options
* @returns Search response with filtered token results
*/
async filter(networkId, options) {
var _a, _b;
const params = {
limit: (_a = options === null || options === void 0 ? void 0 : options.limit) !== null && _a !== void 0 ? _a : 10,
order_by: (0, searchParams_1.mapTokenSortField)(options === null || options === void 0 ? void 0 : options.sortBy),
sort: (_b = options === null || options === void 0 ? void 0 : options.sortDir) !== null && _b !== void 0 ? _b : 'desc',
};
if (options === null || options === void 0 ? void 0 : options.cursor)
params.cursor = options.cursor;
const filters = {};
if ((options === null || options === void 0 ? void 0 : options.volume24hMin) !== undefined)
filters.volume_24h_min = options.volume24hMin;
if ((options === null || options === void 0 ? void 0 : options.volume24hMax) !== undefined)
filters.volume_24h_max = options.volume24hMax;
if ((options === null || options === void 0 ? void 0 : options.liquidityUsdMin) !== undefined)
filters.liquidity_usd_min = options.liquidityUsdMin;
if ((options === null || options === void 0 ? void 0 : options.fdvMin) !== undefined)
filters.fdv_min = options.fdvMin;
if ((options === null || options === void 0 ? void 0 : options.fdvMax) !== undefined)
filters.fdv_max = options.fdvMax;
if ((options === null || options === void 0 ? void 0 : options.txns24hMin) !== undefined)
filters.txns_24h_min = options.txns24hMin;
if ((options === null || options === void 0 ? void 0 : options.createdAfter) !== undefined)
filters.created_after = options.createdAfter;
if ((options === null || options === void 0 ? void 0 : options.createdBefore) !== undefined)
filters.created_before = options.createdBefore;
Object.assign(params, (0, searchParams_1.mapTokenFilterParams)(filters));
return this._get(`/networks/${networkId}/tokens/search`, params);
}
/**
* Get batch prices for multiple tokens on a network.
*
* @param networkId - Network ID (e.g., "ethereum", "solana")
* @param tokens - Array of token addresses (max 10)
* @returns Array of token prices
*/
async getMultiPrices(networkId, tokens) {
if (!tokens || tokens.length === 0) {
throw new Error('tokens array is required and must not be empty');
}
if (tokens.length > 10) {
throw new Error('tokens array must contain at most 10 addresses');
}
const params = { tokens: tokens.join(',') };
return this._get(`/networks/${networkId}/multi/prices`, params);
}
}
exports.TokensAPI = TokensAPI;