UNPKG

tensaikit

Version:

An autonomous DeFi AI Agent Kit on Katana enabling AI agents to plan and execute on-chain financial operations.

39 lines (38 loc) 1.63 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.fetchAllTokensFromSubgraph = void 0; const errors_1 = require("../../../common/errors"); const utils_1 = require("../../../common/utils"); const subGraphQuery_1 = require("../subGraphQuery"); const utlis_1 = require("../utlis"); /** * Fetches a paginated list of tokens from the SushiSwap subgraph for a given chain. * * @param args - An object containing pagination parameters: * - skip: Number of items to skip (for pagination). * - first: Number of items to fetch. * @returns A promise resolving to an array of token objects, or a string message if no data is found. * @throws Throws a formatted error if the subgraph query fails. */ const fetchAllTokensFromSubgraph = async (walletProvider, args) => { try { const network = walletProvider.getNetwork(); const chainId = network.chainId; if (!chainId) { throw (0, errors_1.createError)("Invalid or missing network", errors_1.ErrorCode.INVALID_NETWORK); } const response = await (0, utils_1.makeSubgraphQueryCall)(utlis_1.SUSHI_SWAP_GRAPH_URL, (0, subGraphQuery_1.querySushiSwapAllTokens)({ skip: args.skip, first: args.first, chainId: Number(chainId), })); if (!response || !response.tokenList) { return `No token data found.`; } return response.tokenList; } catch (error) { throw (0, errors_1.handleError)("Failed to fetch all tokens from subgraph", error); } }; exports.fetchAllTokensFromSubgraph = fetchAllTokensFromSubgraph;