@renegade-fi/core
Version:
VanillaJS library for Renegade
31 lines • 1.18 kB
JavaScript
import { BaseError } from "viem";
import { getSDKConfig } from "../chains/defaults.js";
import { GET_TOKEN_PRICES_ROUTE } from "../constants.js";
import { createConfig } from "../createConfig.js";
import { getRelayerRaw } from "../utils/http.js";
export async function getTokenPrices(config) {
let relayerConfig = config;
if (config.renegadeKeyType === "none") {
const chainId = config.getChainId();
const sdkConfig = getSDKConfig(chainId);
relayerConfig = createConfig({
darkPoolAddress: sdkConfig.darkpoolAddress,
priceReporterUrl: sdkConfig.priceReporterUrl,
relayerUrl: sdkConfig.relayerUrl,
chainId,
utils: config.utils,
});
}
const { getBaseUrl } = relayerConfig;
const res = await getRelayerRaw(getBaseUrl(GET_TOKEN_PRICES_ROUTE));
if (!res.token_prices) {
throw new BaseError("Could not fetch token prices");
}
return {
token_prices: res.token_prices.map((tokenPrice) => ({
...tokenPrice,
price: Number.parseFloat(tokenPrice.price.toString()),
})),
};
}
//# sourceMappingURL=getTokenPrices.js.map