Update Rate
https://developers.ccdata.io/documentation/legacy/Price/SingleSymbolPriceEndpoint/
pragma solidity ^0.8.0;
library LoanUtils {
struct RateData {
uint256 lastRate;
uint256 currentRate;
uint256 lastUpdateTimestamp;
}
}
contract NebeusLending is Ownable {
using LoanUtils for LoanUtils.RateData;
mapping(string => LoanUtils.RateData) public rateData; // Currency to rate mapping
uint256 public rateRequestFrequency = 2 hours;
event RateUpdated(string currency, uint256 lastRate, uint256 currentRate, uint256 timestamp);
/**
* @notice Updates the exchange rate for a specific currency
* @param currency The symbol of the currency (e.g., "ETH")
* @param currentRate The new rate for the currency
*/
function updateRate(string memory currency, uint256 currentRate) external onlyOwner {
LoanUtils.RateData storage rate = rateData[currency];
// Ensure enough time has passed since the last update
require(
block.timestamp >= rate.lastUpdateTimestamp + rateRequestFrequency,
"Rate update frequency not met"
);
// Update the rates
rate.lastRate = rate.currentRate;
rate.currentRate = currentRate;
rate.lastUpdateTimestamp = block.timestamp;
emit RateUpdated(currency, rate.lastRate, rate.currentRate, block.timestamp);
}
}
Last updated
