UNPKG

@kamino-finance/farms-sdk

Version:
38 lines 1.35 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.JUPITER_PRICE_API = void 0; exports.getPriceForTokenMint = getPriceForTokenMint; const axios_1 = __importDefault(require("axios")); const decimal_js_1 = __importDefault(require("decimal.js")); exports.JUPITER_PRICE_API = "https://lite-api.jup.ag/price/v2"; async function fetchJupiterPrice(query) { const response = await axios_1.default.get(exports.JUPITER_PRICE_API, { params: query, headers: { "Content-Type": "application/json" }, }); return response.data; } async function getPriceForTokenMint(mint) { const mintString = mint.toString(); const query = { ids: mintString, }; return fetchJupiterPrice(query) .then((response) => { const tokenInfo = response.data[mintString]; if (tokenInfo) { return new decimal_js_1.default(tokenInfo.price); } else { throw new Error(`No price found for token mint: ${mintString}`); } }) .catch((error) => { console.error(`Error fetching price for token mint ${mintString}:`, error); throw error; }); } //# sourceMappingURL=price.js.map