Skip to content

Commit

Permalink
fix bsquared pricing
Browse files Browse the repository at this point in the history
  • Loading branch information
vrtnd committed May 10, 2024
1 parent 3e722d1 commit ed3c1ba
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions src/utils/prices.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,17 @@ export const getSingleLlamaPrice = async (
: PRICES_API + `/current/${chain}:${token}`;
const res = await retry(async (_bail: any) => await axios.get(url));
const price = res?.data?.coins?.[`${chain}:${token}`];
if (
!confidenceThreshold ||
!price ||
price.confidence > confidenceThreshold
) {
if (!confidenceThreshold || !price || price.confidence > confidenceThreshold) {
return price;
}
return null;
};

export const getLlamaPrices = async (tokens: string[], timestamp?: number) => {
let finalPrices = {} as any;
let remainingTokens = tokens;
let remainingTokens = tokens?.map((token) =>
token?.includes("b2-mainnet") ? `bsquared:${token?.split(":")[1]}` : token
);
while (remainingTokens.length > 0) {
const url = timestamp
? PRICES_API +
Expand All @@ -49,5 +47,9 @@ export const getLlamaPrices = async (tokens: string[], timestamp?: number) => {
finalPrices = { ...finalPrices, ...prices };
remainingTokens = remainingTokens.slice(maxNumberOfPrices);
}
return finalPrices;
return Object.fromEntries(
Object.entries(finalPrices || {}).map(([key, value]) =>
key?.includes("bsquared") ? [`b2-mainnet:${key?.split(":")[1]}`, value] : [key, value]
)
);
};

0 comments on commit ed3c1ba

Please sign in to comment.