Skip to content

Commit

Permalink
fix: earning price
Browse files Browse the repository at this point in the history
  • Loading branch information
0xjojoex committed Jun 14, 2024
1 parent d0a229b commit 354a853
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
6 changes: 3 additions & 3 deletions src/pools/service/cakeTokenPrice.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import axios from "axios";

export const fetchCakeTokenPrice = async (): Promise<number> => {
export const fetchTokenPrice = async ({ chainId, address }: { chainId: number; address: string }): Promise<number> => {
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");
Expand Down
4 changes: 2 additions & 2 deletions src/pools/service/poolMetrics.ts
Original file line number Diff line number Diff line change
@@ -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";
Expand All @@ -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,
Expand Down

0 comments on commit 354a853

Please sign in to comment.