tensaikit
Version:
An autonomous DeFi AI Agent Kit on Katana enabling AI agents to plan and execute on-chain financial operations.
25 lines (24 loc) • 992 B
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.fetchTokenPrice = void 0;
const errors_1 = require("../../../common/errors");
const utlis_1 = require("../utlis");
/**
* Fetches the USD price of a specific token on the specified EVM chain using the SushiSwap module.
*
* @param chainId - The chain ID representing the target blockchain network.
* @param tokenAddress - The address of the token to fetch the price for.
* @returns A promise resolving to the token's USD price.
* @throws Throws a formatted error if the price retrieval fails.
*/
const fetchTokenPrice = async (chainId, tokenAddress) => {
try {
const sushiSwapModule = await (0, utlis_1.SushiSwapModule)();
const typedChainId = chainId;
return await sushiSwapModule.price(typedChainId, tokenAddress);
}
catch (error) {
throw (0, errors_1.handleError)("Failed to fetch token price", error);
}
};
exports.fetchTokenPrice = fetchTokenPrice;