Hello guys, please help me. I want my program to fetch the price. Like I call getSolPrice in my program, and it returns the price. I just don’t wanna update the price. Tried this function
fn calculate_sol_price(price_update: &Account<PriceUpdateV2>) -> Result<PriceData> {
let price = price_update.get_price_no_older_than(
&Clock::get()?,
MAXIMUM_AGE,
&get_feed_id_from_hex(FEED_ID)?,
)?;
require!(price.price > 0, LockerError::InvalidPrice);
let normalized_price = if price.exponent >= 0 {
price.price as u64 * 10_u64.pow(price.exponent as u32)
} else {
(price.price as u64) / 10_u64.pow((-price.exponent) as u32)
};
Ok(PriceData {
price: price.price,
exponent: price.exponent,
normalized_price,
publish_time: price.publish_time,
confidence: price.conf,
})
}
But it needs a price update account, I can’t find one, nor do I want to create/maintain one. For reference: This is a solidity function, I want something similar.
function getEthUsdPrice() public view returns (uint256) {
(, int256 price,,,) = ethUsdPriceFeed.latestRoundData();
require(price > 0, "Invalid price");
return uint256(price); // 8 decimals
}