From 354a853a57804d63653977e0568eeed8d779894c Mon Sep 17 00:00:00 2001 From: ChefJoJo <94336009+chef-jojo@users.noreply.github.com> Date: Fri, 14 Jun 2024 17:46:08 +0800 Subject: [PATCH] fix: earning price --- src/pools/service/cakeTokenPrice.ts | 6 +++--- src/pools/service/poolMetrics.ts | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/pools/service/cakeTokenPrice.ts b/src/pools/service/cakeTokenPrice.ts index 6dc891f..3dd116b 100644 --- a/src/pools/service/cakeTokenPrice.ts +++ b/src/pools/service/cakeTokenPrice.ts @@ -1,9 +1,9 @@ import axios from "axios"; -export const fetchCakeTokenPrice = async (): Promise => { +export const fetchTokenPrice = async ({ chainId, address }: { chainId: number; address: string }): Promise => { try { - const response = await axios.get("https://farms-api.pancakeswap.com/price/cake"); - return parseFloat(response.data.price); + const response = await axios.get(`https://wallet-api.pancakeswap.com/v0/prices/${chainId}/${address}`); + return parseFloat(response.data); } catch (error) { console.error("Error fetching cake price:", error); throw new Error("Failed to fetch cake price"); diff --git a/src/pools/service/poolMetrics.ts b/src/pools/service/poolMetrics.ts index b3e2f2b..a3be5ef 100644 --- a/src/pools/service/poolMetrics.ts +++ b/src/pools/service/poolMetrics.ts @@ -1,7 +1,7 @@ import { SerializedPool } from "../constants/types"; import { fetchAlpTokenPrice } from "./alpTokenPrice"; import { getPoolAprByTokenPerSecond } from "./poolApr"; -import { fetchCakeTokenPrice } from "./cakeTokenPrice"; +import { fetchTokenPrice } from "./cakeTokenPrice"; import { fetchEndTimestamp } from "./endTimestamp"; import { fetchTotalStaked } from "./totalStacked"; import { ChainId } from "@pancakeswap/sdk"; @@ -14,7 +14,7 @@ export const calculatePoolMetrics = async (poolsConfigs: SerializedPool[], chain const fillMetric = async (poolConfig: SerializedPool, chainId) => { const totalStaked = await fetchTotalStaked(poolConfig.contractAddress, poolConfig.stakingToken.address, chainId); const stakingTokenPrice = await fetchAlpTokenPrice(); - const earningTokenPrice = await fetchCakeTokenPrice(); + const earningTokenPrice = await fetchTokenPrice(poolConfig.earningToken); const apr = await getPoolAprByTokenPerSecond( stakingTokenPrice, earningTokenPrice,