RedWilly / Pump-UI

pump fun EVM ( UI )
https://bondle.xyz
7 stars 10 forks source link

The historical USD price is not really historical USD price for the charts. #34

Open jshekhawat opened 2 weeks ago

jshekhawat commented 2 weeks ago

Am I correct in my assumption that this snippet only calculates the historical price with the current price of BONE? So any changes will just update the chart.

export async function getTokenUSDPriceHistory(address: string): Promise<USDHistoricalPrice[]> {
  try {
    const [ethPrice, historicalPrices] = await Promise.all([
      getCurrentPrice(),
      getHistoricalPriceData(address)
    ]);

    return historicalPrices.map((price: HistoricalPrice) => {
      const tokenPriceInWei = ethers.BigNumber.from(price.tokenPrice);
      const tokenPriceInETH = ethers.utils.formatEther(tokenPriceInWei);
      const tokenPriceUSD = parseFloat(tokenPriceInETH) * parseFloat(ethPrice);

      return {
        tokenPriceUSD: tokenPriceUSD.toFixed(9),  // Adjust decimal places as needed
        timestamp: price.timestamp
      };
    });
  } catch (error) {
    console.error('Error calculating USD price history:', error);
    throw new Error('Failed to calculate USD price history');
  }
}
RedWilly commented 2 weeks ago

yes :)