pharos-agent-kit
Version:
Connect AI Agents to Pharos protocols
30 lines • 1.27 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.fetchPrices = fetchPrices;
const constants_1 = require("./constants");
/**
* @param chainTokenAddrStrings String array of strings in format of "chain:token_address" (e.g. "ethereum:0x0000000000000000000000000000000000000000")
* @param searchWidth The width of the search window for the price data. Default is "6h"
* @returns JSON string of the price data
*/
async function fetchPrices(args) {
try {
const { chainTokenAddrStrings, searchWidth } = args;
const params = new URLSearchParams({});
const tokens = chainTokenAddrStrings.join(",");
if (searchWidth) {
params.set("searchWidth", searchWidth);
}
const url = `${constants_1.DEFILLAMA_PRICES_URL}/prices/current/${tokens}?${params.toString()}`;
const response = await fetch(url);
if (!response.ok) {
throw new Error(`HTTP error! status: ${response.status}`);
}
const data = await response.json();
return JSON.stringify(data, null, 2);
}
catch (error) {
return `Error fetching token prices: ${error instanceof Error ? error.message : String(error)}`;
}
}
//# sourceMappingURL=fetch_price.js.map