Verified contractPartialGPL-3.0
ContinuousPriceOracle
Address0xb5aafa3fd91d76befc75ccdc9766732d4300e74a
- Balance
0 ETH
- Transactions
12
- Compiler
solc 0.8.33
- Same code
1 more contract
Details
- Compiler
- solc 0.8.33+commit.64118f21
- Language
- solidity
- Optimization
- Yes, 200 runs
- EVM version
- prague
- License
- GPL-3.0
- Match
- Partialcreation code: yes, runtime code: yes
- Verified on Sourcify
- Created in block
- 26,234,190
- Creation transaction
- 0xaeb426ebea…54e376fa47
12 files
- contracts/rwaOracles/ContinuousPriceOracle.solmain20.45 KB
- contracts/external/m0/ContinuousIndexingMath.sol5.31 KB
- contracts/external/openzeppelin-v5/contracts/access/AccessControl.sol7.05 KB
- contracts/external/openzeppelin-v5/contracts/access/IAccessControl.sol3.26 KB
- contracts/external/openzeppelin-v5/contracts/access/extensions/AccessControlEnumerable.sol2.69 KB
- contracts/external/openzeppelin-v5/contracts/access/extensions/IAccessControlEnumerable.sol1.28 KB
- contracts/external/openzeppelin-v5/contracts/utils/Context.sol963 B
- contracts/external/openzeppelin-v5/contracts/utils/introspection/ERC165.sol911 B
- contracts/external/openzeppelin-v5/contracts/utils/introspection/IERC165.sol869 B
- contracts/external/openzeppelin-v5/contracts/utils/structs/EnumerableSet.sol12.97 KB
- contracts/rwaOracles/IRWADynamicOracle.sol1.49 KB
- contracts/rwaOracles/IRWAOracle.sol1.51 KB
contracts/rwaOracles/ContinuousPriceOracle.sol
// SPDX-License-Identifier: GPL-3.0
/*
▄▄█████████▄
╓██▀└ ,╓▄▄▄, '▀██▄
██▀ ▄██▀▀╙╙▀▀██▄ └██µ ,, ,, , ,,, ,,,
██ ,██¬ ▄████▄ ▀█▄ ╙█▄ ▄███▀▀███▄ ███▄ ██ ███▀▀▀███▄ ▄███▀▀███,
██ ██ ╒█▀' ╙█▌ ╙█▌ ██ ▐██ ███ █████, ██ ██▌ └██▌ ██▌ └██▌
██ ▐█▌ ██ ╟█ █▌ ╟█ ██▌ ▐██ ██ └███ ██ ██▌ ╟██ j██ ╟██
╟█ ██ ╙██ ▄█▀ ▐█▌ ██ ╙██ ██▌ ██ ╙████ ██▌ ▄██▀ ██▌ ,██▀
██ "██, ╙▀▀███████████⌐ ╙████████▀ ██ ╙██ ███████▀▀ ╙███████▀`
██▄ ╙▀██▄▄▄▄▄,,, ¬─ '─¬
╙▀██▄ '╙╙╙▀▀▀▀▀▀▀▀
╙▀▀██████R⌐
*/
pragma solidity 0.8.33;
import {
AccessControlEnumerable
} from "contracts/external/openzeppelin-v5/contracts/access/extensions/AccessControlEnumerable.sol";
import {ContinuousIndexingMath} from "contracts/external/m0/ContinuousIndexingMath.sol";
import {IRWADynamicOracle} from "contracts/rwaOracles/IRWADynamicOracle.sol";
import {IRWAOracle} from "contracts/rwaOracles/IRWAOracle.sol";
/**
* @title ContinuousPriceOracle
* @author Ondo Finance
* @notice Price oracle for an RWA token, accruing from the last stored price at a continuously
* compounded yearly rate, with an optional scheduled next yearly rate
*/
contract ContinuousPriceOracle is IRWADynamicOracle, IRWAOracle, AccessControlEnumerable {
/// Role to set the price and yearly rate outside the ORACLE_SETTER_ROLE bounds and to set those
/// bounds
bytes32 public constant TIMELOCKED_ADMIN_ROLE = keccak256("TIMELOCKED_ADMIN_ROLE");
/// Role to call `syncRateAndPriceStoredToNow`
bytes32 public constant SYNCER_ROLE = keccak256("SYNCER_ROLE");
/// Role to set the price and yearly rate of the RWA token within bounds set by the admin, while
/// the current yearly rate is non-zero
bytes32 public constant ORACLE_SETTER_ROLE = keccak256("ORACLE_SETTER_ROLE");
/// Role to call `freezePrice`
bytes32 public constant PRICE_FREEZER_ROLE = keccak256("PRICE_FREEZER_ROLE");
/// The precision of the yearly rate and APY, 12 decimals (1e12 = 100%)
uint64 public constant RATE_PRECISION = ContinuousIndexingMath.EXP_SCALED_ONE;
/// The maximum yearly rate, 100% continuously compounded
uint64 internal constant MAX_YEARLY_RATE = RATE_PRECISION;
/// The maximum allowed difference between an intended APY and the APY a yearly rate produces
uint64 internal constant INTENDED_APY_TOLERANCE = 10;
/// The `nextRateStart` value when no next yearly rate is set
uint64 public constant MAX_UINT64 = type(uint64).max;
/// The precision of basis points values (1e4 = 100%)
uint64 public constant BPS_PRECISION = 1e4;
/// The symbol of the RWA token this oracle is serving the price for
string public symbol;
/// The last price stored, with 18 decimals of precision
uint256 public priceStored;
/// The timestamp of when `priceStored` was last stored
uint64 public lastPriceStoredTimestamp;
/// The yearly rate the price accrues at before `nextRateStart`, as `ln(1 + APY)` scaled by
/// `RATE_PRECISION`
uint64 public currentYearlyRate;
/// The price at `nextRateStart`, with 18 decimals of precision
uint256 public priceAtNextRateStart;
/// The timestamp of when the next yearly rate will start, `MAX_UINT64` if unset
uint64 public nextRateStart;
/// The yearly rate the price accrues at from `nextRateStart`, as `ln(1 + APY)` scaled by
/// `RATE_PRECISION`
uint64 public nextYearlyRate;
/// The timestamp of the last `setPriceNow`
uint64 public lastPriceChangeTimestamp;
/// The timestamp of the last `setRateNow` or `setNextRate`
uint64 public lastRateChangeTimestamp;
/// The maximum yearly rate change by the ORACLE_SETTER_ROLE, in bps of the current yearly rate
uint64 public maxRateChangeBps;
/// The maximum price change by the ORACLE_SETTER_ROLE, in bps of the current price
uint64 public maxPriceChangeBps;
/// The minimum time in seconds between ORACLE_SETTER_ROLE price changes, and between its yearly
/// rate changes
uint64 public minimumChangeWindow;
/**
* @notice Emitted when the current yearly rate is set
* @param yearlyRate The yearly rate set
* @param timestamp The timestamp of when the yearly rate took effect
*/
event CurrentYearlyRateSet(uint64 indexed yearlyRate, uint64 timestamp);
/**
* @notice Emitted when the price is stored
* @param price The price set
* @param timestamp The timestamp of when the price was set
*/
event PriceSet(uint256 indexed price, uint64 timestamp);
/**
* @notice Emitted when the next yearly rate is set or cleared
* @param yearlyRate The yearly rate set, 0 when cleared
* @param startTime The timestamp of when the yearly rate will start, `MAX_UINT64` when cleared
*/
event NextYearlyRateSet(uint64 indexed yearlyRate, uint64 startTime);
/**
* @notice Emitted when the maximum yearly rate change is set
* @param oldMaxRateChangeBps The old maximum yearly rate change in bps
* @param newMaxRateChangeBps The new maximum yearly rate change in bps
*/
event MaxRateChangeSet(uint64 indexed oldMaxRateChangeBps, uint64 indexed newMaxRateChangeBps);
/**
* @notice Emitted when the maximum price change is set
* @param oldMaxPriceChangeBps The old maximum price change in bps
* @param newMaxPriceChangeBps The new maximum price change in bps
*/
event MaxPriceChangeSet(uint64 indexed oldMaxPriceChangeBps, uint64 indexed newMaxPriceChangeBps);
/**
* @notice Emitted when the minimum change window is set
* @param oldMinimumChangeWindow The old minimum change window in seconds
* @param newMinimumChangeWindow The new minimum change window in seconds
*/
event MinimumChangeWindowSet(
uint64 indexed oldMinimumChangeWindow, uint64 indexed newMinimumChangeWindow
);
/// Error thrown when the ORACLE_SETTER_ROLE attempts to set the price within the window
error PriceChangeWindowNotPassed();
/// Error thrown when the ORACLE_SETTER_ROLE attempts to set the yearly rate within the window
error RateChangeWindowNotPassed();
/// Error thrown when the ORACLE_SETTER_ROLE attempts to set the price too high or too low
error PriceChangeTooLarge();
/// Error thrown when the ORACLE_SETTER_ROLE attempts to change the yearly rate by too much
error RateChangeTooLarge();
/// Error thrown when attempting to set `nextRateStart` to a time that is not in the future
error InvalidStartTime();
/// Error thrown when `nextRateStart` is more than a year away
error StartTimeTooFar();
/// Error thrown when the minimum change window is set to 0
error ChangeWindowCantBeZero();
/// Error thrown when the sender has neither the TIMELOCKED_ADMIN_ROLE nor the ORACLE_SETTER_ROLE
error MsgSenderNotSetter();
/// Error thrown when the yearly rate's APY differs from the intended APY beyond the tolerance
error IntendedAPYMismatch();
/// Error thrown when the yearly rate exceeds `MAX_YEARLY_RATE`
error RateTooHigh();
/// Error thrown when the ORACLE_SETTER_ROLE acts while the current yearly rate is zero
error ZeroRateAdminOnly();
/// Error thrown when the guardian is the zero address
error ZeroAddress();
/// Error thrown when the initial price is zero
error ZeroInitialPrice();
/**
* @param guardian The address that will be granted the DEFAULT_ADMIN_ROLE
* @param _symbol The symbol of the RWA token
* @param _initialPrice The initial price to set, with 18 decimals of precision
* @param _initialYearlyRate The initial yearly rate to set
* @param _maxRateChangeBps The maximum yearly rate change by the ORACLE_SETTER_ROLE, in bps of
* the current yearly rate
* @param _maxPriceChangeBps The maximum price change by the ORACLE_SETTER_ROLE, in bps of the
* current price
*/
constructor(
address guardian,
string memory _symbol,
uint256 _initialPrice,
uint64 _initialYearlyRate,
uint64 _maxRateChangeBps,
uint64 _maxPriceChangeBps
) {
if (_initialYearlyRate > MAX_YEARLY_RATE) revert RateTooHigh();
if (guardian == address(0)) revert ZeroAddress();
if (_initialPrice == 0) revert ZeroInitialPrice();
_grantRole(DEFAULT_ADMIN_ROLE, guardian);
symbol = _symbol;
priceStored = _initialPrice;
lastPriceStoredTimestamp = _currentTime();
lastPriceChangeTimestamp = _currentTime();
lastRateChangeTimestamp = _currentTime();
currentYearlyRate = _initialYearlyRate;
nextRateStart = MAX_UINT64;
maxRateChangeBps = _maxRateChangeBps;
maxPriceChangeBps = _maxPriceChangeBps;
minimumChangeWindow = 8 hours;
emit PriceSet(_initialPrice, _currentTime());
emit CurrentYearlyRateSet(_initialYearlyRate, _currentTime());
}
/**
* @notice Get the current price of the RWA token
* @return price The current price of the RWA token, with 18 decimals of precision
*/
function getPrice() public view returns (uint256 price) {
if (_currentTime() < nextRateStart) {
return (priceStored
* ContinuousIndexingMath.getContinuousIndex(
currentYearlyRate,
// forge-lint: disable-next-line(unsafe-typecast)
uint32(_currentTime() - lastPriceStoredTimestamp)
)) / RATE_PRECISION;
} else {
return (priceAtNextRateStart
* ContinuousIndexingMath.getContinuousIndex(
nextYearlyRate,
// forge-lint: disable-next-line(unsafe-typecast)
uint32(_currentTime() - nextRateStart)
)) / RATE_PRECISION;
}
}
/**
* @notice Get the current price and timestamp of the RWA token
* @return price The current price of the RWA token, with 18 decimals of precision
* @return timestamp The timestamp this price is accurate to
*/
function getPriceData() external view returns (uint256 price, uint256 timestamp) {
return (getPrice(), _currentTime());
}
/**
* @notice Get the current APY of the RWA token
* @return The current APY of the RWA token, with 12 decimals of precision (1e12 = 100% APY)
*/
function getCurrentAPY() external view returns (uint64) {
// The set yearly rate r in this contract is used in e^rt where t is years to calculate a price
// index so converting it to APY is just e^r - 1
uint64 yearlyRate = _currentTime() < nextRateStart ? currentYearlyRate : nextYearlyRate;
return ContinuousIndexingMath.getContinuousIndex(
yearlyRate, ContinuousIndexingMath.SECONDS_PER_YEAR
) - RATE_PRECISION;
}
/**
* @notice Get the current time
* @return The current time, cast to a uint64
*/
function _currentTime() internal view returns (uint64) {
return uint64(block.timestamp);
}
/**
* @notice Set the current price of the RWA token
* @param newPriceNow The price to set, with 18 decimals of precision
* @dev The TIMELOCKED_ADMIN_ROLE is not bound by the ORACLE_SETTER_ROLE bounds.
*/
function setPriceNow(uint256 newPriceNow) external onlySetter {
_syncRateAndPriceStoredToNow();
_requireAdminWhenRateIsZero();
// The TIMELOCKED_ADMIN_ROLE can set the price to any value
if (!hasRole(TIMELOCKED_ADMIN_ROLE, _msgSender())) {
if (minimumChangeWindow > _currentTime() - lastPriceChangeTimestamp) {
revert PriceChangeWindowNotPassed();
}
uint256 currentPrice = priceStored;
uint256 priceChange =
newPriceNow > currentPrice ? newPriceNow - currentPrice : currentPrice - newPriceNow;
if (priceChange > (maxPriceChangeBps * currentPrice) / BPS_PRECISION) {
revert PriceChangeTooLarge();
}
}
priceStored = newPriceNow;
lastPriceStoredTimestamp = _currentTime();
lastPriceChangeTimestamp = _currentTime();
if (_isNextRateSet()) priceAtNextRateStart = _getPriceAtNextRateStart();
emit PriceSet(priceStored, lastPriceStoredTimestamp);
}
/**
* @notice Set the current yearly rate of the RWA token, clearing any pending next yearly rate
* @param _currentYearlyRate The yearly rate to set
* @param intendedApy The APY corresponding to the yearly rate
* @dev The TIMELOCKED_ADMIN_ROLE is not bound by the ORACLE_SETTER_ROLE bounds. The minimum
* change window is shared with `setNextRate`.
*/
function setRateNow(uint64 _currentYearlyRate, uint64 intendedApy) external onlySetter {
_syncRateAndPriceStoredToNow();
_requireAdminWhenRateIsZero();
_verifyRateChange(_currentYearlyRate, intendedApy);
currentYearlyRate = _currentYearlyRate;
lastPriceStoredTimestamp = _currentTime();
lastRateChangeTimestamp = _currentTime();
// We clear the next rate if it has been set, isolating state changes of each function
if (_isNextRateSet()) _clearNextRate();
emit CurrentYearlyRateSet(currentYearlyRate, lastPriceStoredTimestamp);
}
/**
* @notice Set the next yearly rate of the RWA token and when it starts, replacing any pending
* next yearly rate
* @param _nextYearlyRate The yearly rate to set
* @param intendedApy The APY corresponding to the yearly rate
* @param _nextRateStart The timestamp of when the yearly rate will start
* @dev The TIMELOCKED_ADMIN_ROLE is not bound by the ORACLE_SETTER_ROLE bounds. The minimum
* change window is shared with `setRateNow`.
*/
function setNextRate(uint64 _nextYearlyRate, uint64 intendedApy, uint64 _nextRateStart)
external
onlySetter
{
if (_nextRateStart <= _currentTime()) {
revert InvalidStartTime();
}
if (_nextRateStart - _currentTime() > ContinuousIndexingMath.SECONDS_PER_YEAR) {
revert StartTimeTooFar();
}
_syncRateAndPriceStoredToNow();
_requireAdminWhenRateIsZero();
_verifyRateChange(_nextYearlyRate, intendedApy);
nextYearlyRate = _nextYearlyRate;
nextRateStart = _nextRateStart;
priceAtNextRateStart = _getPriceAtNextRateStart();
lastRateChangeTimestamp = _currentTime();
emit NextYearlyRateSet(nextYearlyRate, nextRateStart);
}
/// Clear the pending next yearly rate
function clearNextRate() external onlySetter {
_syncRateAndPriceStoredToNow();
_requireAdminWhenRateIsZero();
// Gas optimization in case syncing the rate clears the next rate
if (_isNextRateSet()) _clearNextRate();
}
/// Freeze the price by setting the current yearly rate to zero and clearing the next yearly rate
function freezePrice() external onlyRole(PRICE_FREEZER_ROLE) {
_syncRateAndPriceStoredToNow();
currentYearlyRate = 0;
emit CurrentYearlyRateSet(currentYearlyRate, lastPriceStoredTimestamp);
if (_isNextRateSet()) _clearNextRate();
}
/// Store the accrued price and apply the next yearly rate if it has started
function syncRateAndPriceStoredToNow() external onlyRole(SYNCER_ROLE) {
_syncRateAndPriceStoredToNow();
}
/**
* @notice Set the maximum yearly rate change by the ORACLE_SETTER_ROLE
* @param _maxRateChangeBps The maximum rate change, in bps of the current yearly rate
*/
function setMaxRateChangeBps(uint64 _maxRateChangeBps) external onlyRole(TIMELOCKED_ADMIN_ROLE) {
emit MaxRateChangeSet(maxRateChangeBps, _maxRateChangeBps);
maxRateChangeBps = _maxRateChangeBps;
}
/**
* @notice Set the maximum price change by the ORACLE_SETTER_ROLE
* @param _maxPriceChangeBps The maximum price change, in bps of the current price
*/
function setMaxPriceChangeBps(uint64 _maxPriceChangeBps)
external
onlyRole(TIMELOCKED_ADMIN_ROLE)
{
emit MaxPriceChangeSet(maxPriceChangeBps, _maxPriceChangeBps);
maxPriceChangeBps = _maxPriceChangeBps;
}
/**
* @notice Set the minimum time in seconds between ORACLE_SETTER_ROLE price changes, and between
* its yearly rate changes
* @param _minimumChangeWindow The minimum change window in seconds
*/
function setMinimumChangeWindow(uint64 _minimumChangeWindow)
external
onlyRole(TIMELOCKED_ADMIN_ROLE)
{
// A zero window would let the ORACLE_SETTER_ROLE bypass the bounds within one block
if (_minimumChangeWindow == 0) revert ChangeWindowCantBeZero();
emit MinimumChangeWindowSet(minimumChangeWindow, _minimumChangeWindow);
minimumChangeWindow = _minimumChangeWindow;
}
/**
* @notice Verify a yearly rate against `MAX_YEARLY_RATE`, the intended APY and the
* ORACLE_SETTER_ROLE change window and bounds
* @param yearlyRate The yearly rate to verify
* @param intendedApy The intended APY to verify against
*/
function _verifyRateChange(uint64 yearlyRate, uint64 intendedApy) internal view {
if (yearlyRate > MAX_YEARLY_RATE) revert RateTooHigh();
// Double check the yearly rate against the intended APY
uint64 actualAPY = ContinuousIndexingMath.getContinuousIndex(
yearlyRate, ContinuousIndexingMath.SECONDS_PER_YEAR
) - RATE_PRECISION;
uint64 diff = intendedApy > actualAPY ? intendedApy - actualAPY : actualAPY - intendedApy;
if (diff > INTENDED_APY_TOLERANCE) revert IntendedAPYMismatch();
// Check that the yearly rate change is within bounds if the sender is not the admin
if (!hasRole(TIMELOCKED_ADMIN_ROLE, _msgSender())) {
if (minimumChangeWindow > _currentTime() - lastRateChangeTimestamp) {
revert RateChangeWindowNotPassed();
}
uint64 rateChange = yearlyRate > currentYearlyRate
? yearlyRate - currentYearlyRate
: currentYearlyRate - yearlyRate;
if (rateChange > (uint256(maxRateChangeBps) * currentYearlyRate) / BPS_PRECISION) {
revert RateChangeTooLarge();
}
}
}
/// Revert if the current yearly rate is zero and the sender is not the TIMELOCKED_ADMIN_ROLE
function _requireAdminWhenRateIsZero() internal view {
if (currentYearlyRate == 0 && !hasRole(TIMELOCKED_ADMIN_ROLE, _msgSender())) {
revert ZeroRateAdminOnly();
}
}
/// Store the accrued price and apply the next yearly rate if it has started, otherwise
/// recompute its start price from the new anchor
function _syncRateAndPriceStoredToNow() internal {
priceStored = getPrice();
lastPriceStoredTimestamp = _currentTime();
emit PriceSet(priceStored, lastPriceStoredTimestamp);
if (_currentTime() >= nextRateStart) {
currentYearlyRate = nextYearlyRate;
emit CurrentYearlyRateSet(currentYearlyRate, nextRateStart);
_clearNextRate();
} else if (_isNextRateSet()) {
priceAtNextRateStart = _getPriceAtNextRateStart();
}
}
/**
* @notice Calculate the price at `nextRateStart` from `priceStored` at the current yearly rate
* @return The price at `nextRateStart`, with 18 decimals of precision
*/
function _getPriceAtNextRateStart() internal view returns (uint256) {
return (priceStored
* ContinuousIndexingMath.getContinuousIndex(
currentYearlyRate,
// forge-lint: disable-next-line(unsafe-typecast)
uint32(nextRateStart - lastPriceStoredTimestamp)
)) / RATE_PRECISION;
}
/// Clear the next yearly rate
function _clearNextRate() internal {
nextYearlyRate = 0;
nextRateStart = MAX_UINT64;
priceAtNextRateStart = 0;
emit NextYearlyRateSet(nextYearlyRate, nextRateStart);
}
/**
* @notice Check if the next rate has been set
* @return True if the next rate has been set, false otherwise
*/
function _isNextRateSet() internal view returns (bool) {
return nextRateStart < MAX_UINT64;
}
/// Verify that the sender has the TIMELOCKED_ADMIN_ROLE or the ORACLE_SETTER_ROLE
modifier onlySetter() {
if (!(hasRole(ORACLE_SETTER_ROLE, _msgSender())
|| hasRole(TIMELOCKED_ADMIN_ROLE, _msgSender()))) revert MsgSenderNotSetter();
_;
}
}
contracts/external/m0/ContinuousIndexingMath.sol
// SPDX-License-Identifier: GPL-3.0
// https://github.com/m0-foundation/common/blob/3692db150ad90b21d7c213ea535f34792ad8873f/src/libs/ContinuousIndexingMath.sol
pragma solidity ^0.8.4;
/**
* @title Arithmetic library with operations for calculating continuous indexing.
* @author M^0 Labs
*/
library ContinuousIndexingMath {
/* ============ Variables ============ */
/// @notice The scaling of indexes for exponent math.
uint56 internal constant EXP_SCALED_ONE = 1e12;
/// @notice The number of seconds in a year.
uint32 internal constant SECONDS_PER_YEAR = 31_536_000;
/// @notice 100% in basis points.
uint16 internal constant BPS_SCALED_ONE = 1e4;
/* ============ Internal View/Pure Functions ============ */
/**
* @notice Helper function to calculate `(index * deltaIndex) / EXP_SCALED_ONE`, rounded down.
* @dev Inspired by USM (https://github.com/usmfum/USM/blob/master/contracts/WadMath.sol)
*/
function multiplyIndicesDown(uint128 index, uint48 deltaIndex) internal pure returns (uint144) {
unchecked {
return uint144((uint256(index) * deltaIndex) / EXP_SCALED_ONE);
}
}
/**
* @notice Helper function to calculate `(index * deltaIndex) / EXP_SCALED_ONE`, rounded up.
* @dev Inspired by USM (https://github.com/usmfum/USM/blob/master/contracts/WadMath.sol)
*/
function multiplyIndicesUp(uint128 index, uint48 deltaIndex) internal pure returns (uint144) {
unchecked {
return uint144((uint256(index) * deltaIndex + (EXP_SCALED_ONE - 1)) / EXP_SCALED_ONE);
}
}
/**
* @notice Helper function to calculate e^rt (continuous compounding formula).
* @dev `uint64 yearlyRate` can accommodate 1000% interest per year.
* @dev `uint32 time` can accommodate 100 years.
* @dev `type(uint64).max * type(uint32).max / SECONDS_PER_YEAR` fits in a `uint72`.
*/
function getContinuousIndex(uint64 yearlyRate, uint32 time) internal pure returns (uint48) {
unchecked {
// NOTE: Casting `uint256(yearlyRate) * time` to a `uint72` is safe because the largest value is
// `type(uint64).max * type(uint32).max / SECONDS_PER_YEAR`, which is less than `type(uint72).max`.
return exponent(uint72((uint256(yearlyRate) * time) / SECONDS_PER_YEAR));
}
}
/**
* @notice Helper function to calculate y = e^x using R(4,4) Padé approximation:
* e(x) = (1 + x/2 + 3(x^2)/28 + x^3/84 + x^4/1680) / (1 - x/2 + 3(x^2)/28 - x^3/84 + x^4/1680)
* See: https://en.wikipedia.org/wiki/Pad%C3%A9_table
* See: https://www.wolframalpha.com/input?i=PadeApproximant%5Bexp%5Bx%5D%2C%7Bx%2C0%2C%7B4%2C+4%7D%7D%5D
* Despite itself being a whole number, `x` represents a real number scaled by `EXP_SCALED_ONE`, thus
* allowing for y = e^x where x is a real number.
* @dev Output for a `uint72` input `x` will fit in `uint48`
*/
function exponent(uint72 x) internal pure returns (uint48) {
// NOTE: This can be done unchecked even for `x = type(uint72).max`.
// Verify by removing `unchecked` and running `test_exponent()`.
unchecked {
uint256 x2 = uint256(x) * x;
// `additiveTerms` is `(1 + 3(x^2)/28 + x^4/1680)`, and scaled by `84e27`.
// NOTE: `84e27` the cleanest and largest scalar, given the various intermediate overflow possibilities.
// NOTE: The resulting `(x2 * x2) / 20e21` term has been split to avoid overflow of `x2 * x2`.
// forge-lint: disable-next-line(divide-before-multiply)
uint256 additiveTerms = 84e27 + (9e3 * x2) + ((x2 / 2e11) * (x2 / 1e11));
// `differentTerms` is `(- x/2 - x^3/84)`, but positive (will be subtracted later), and scaled by `84e27`.
uint256 differentTerms = uint256(x) * (42e15 + (x2 / 1e9));
// Result needs to be scaled by `1e12`.
// NOTE: Can cast to `uint48` because contents can never be larger than `type(uint48).max` for any `x`.
// Max `y` is ~200e12, before falling off. See links above for reference.
return uint48(((additiveTerms + differentTerms) * 1e12) / (additiveTerms - differentTerms));
}
}
/**
* @notice Helper function to convert a scaled 12-decimal percentage to basis points.
* @param input A percentage represented as a scaled 12-decimal number.
* @return The percentage represented as basis points.
*/
function convertToBasisPoints(uint64 input) internal pure returns (uint40) {
unchecked {
// forge-lint: disable-next-line(unsafe-typecast)
return uint40((uint256(input) * BPS_SCALED_ONE) / EXP_SCALED_ONE);
}
}
/**
* @notice Helper function to convert basis points to a scaled 12-decimal percentage.
* @param input A percentage represented as basis points.
* @return The percentage represented as a scaled 12-decimal number.
*/
function convertFromBasisPoints(uint32 input) internal pure returns (uint64) {
unchecked {
return uint64((uint256(input) * EXP_SCALED_ONE) / BPS_SCALED_ONE);
}
}
}contracts/external/openzeppelin-v5/contracts/access/AccessControl.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (access/AccessControl.sol)
pragma solidity ^0.8.20;
import {IAccessControl} from "./IAccessControl.sol";
import {Context} from "../utils/Context.sol";
import {ERC165} from "../utils/introspection/ERC165.sol";
/**
* @dev Contract module that allows children to implement role-based access
* control mechanisms. This is a lightweight version that doesn't allow enumerating role
* members except through off-chain means by accessing the contract event logs. Some
* applications may benefit from on-chain enumerability, for those cases see
* {AccessControlEnumerable}.
*
* Roles are referred to by their `bytes32` identifier. These should be exposed
* in the external API and be unique. The best way to achieve this is by
* using `public constant` hash digests:
*
* ```solidity
* bytes32 public constant MY_ROLE = keccak256("MY_ROLE");
* ```
*
* Roles can be used to represent a set of permissions. To restrict access to a
* function call, use {hasRole}:
*
* ```solidity
* function foo() public {
* require(hasRole(MY_ROLE, msg.sender));
* ...
* }
* ```
*
* Roles can be granted and revoked dynamically via the {grantRole} and
* {revokeRole} functions. Each role has an associated admin role, and only
* accounts that have a role's admin role can call {grantRole} and {revokeRole}.
*
* By default, the admin role for all roles is `DEFAULT_ADMIN_ROLE`, which means
* that only accounts with this role will be able to grant or revoke other
* roles. More complex role relationships can be created by using
* {_setRoleAdmin}.
*
* WARNING: The `DEFAULT_ADMIN_ROLE` is also its own admin: it has permission to
* grant and revoke this role. Extra precautions should be taken to secure
* accounts that have been granted it. We recommend using {AccessControlDefaultAdminRules}
* to enforce additional security measures for this role.
*/
abstract contract AccessControl is Context, IAccessControl, ERC165 {
struct RoleData {
mapping(address account => bool) hasRole;
bytes32 adminRole;
}
mapping(bytes32 role => RoleData) private _roles;
bytes32 public constant DEFAULT_ADMIN_ROLE = 0x00;
/**
* @dev Modifier that checks that an account has a specific role. Reverts
* with an {AccessControlUnauthorizedAccount} error including the required role.
*/
modifier onlyRole(bytes32 role) {
_checkRole(role);
_;
}
/**
* @dev See {IERC165-supportsInterface}.
*/
function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {
return interfaceId == type(IAccessControl).interfaceId || super.supportsInterface(interfaceId);
}
/**
* @dev Returns `true` if `account` has been granted `role`.
*/
function hasRole(bytes32 role, address account) public view virtual returns (bool) {
return _roles[role].hasRole[account];
}
/**
* @dev Reverts with an {AccessControlUnauthorizedAccount} error if `_msgSender()`
* is missing `role`. Overriding this function changes the behavior of the {onlyRole} modifier.
*/
function _checkRole(bytes32 role) internal view virtual {
_checkRole(role, _msgSender());
}
/**
* @dev Reverts with an {AccessControlUnauthorizedAccount} error if `account`
* is missing `role`.
*/
function _checkRole(bytes32 role, address account) internal view virtual {
if (!hasRole(role, account)) {
revert AccessControlUnauthorizedAccount(account, role);
}
}
/**
* @dev Returns the admin role that controls `role`. See {grantRole} and
* {revokeRole}.
*
* To change a role's admin, use {_setRoleAdmin}.
*/
function getRoleAdmin(bytes32 role) public view virtual returns (bytes32) {
return _roles[role].adminRole;
}
/**
* @dev Grants `role` to `account`.
*
* If `account` had not been already granted `role`, emits a {RoleGranted}
* event.
*
* Requirements:
*
* - the caller must have ``role``'s admin role.
*
* May emit a {RoleGranted} event.
*/
function grantRole(bytes32 role, address account) public virtual onlyRole(getRoleAdmin(role)) {
_grantRole(role, account);
}
/**
* @dev Revokes `role` from `account`.
*
* If `account` had been granted `role`, emits a {RoleRevoked} event.
*
* Requirements:
*
* - the caller must have ``role``'s admin role.
*
* May emit a {RoleRevoked} event.
*/
function revokeRole(bytes32 role, address account) public virtual onlyRole(getRoleAdmin(role)) {
_revokeRole(role, account);
}
/**
* @dev Revokes `role` from the calling account.
*
* Roles are often managed via {grantRole} and {revokeRole}: this function's
* purpose is to provide a mechanism for accounts to lose their privileges
* if they are compromised (such as when a trusted device is misplaced).
*
* If the calling account had been revoked `role`, emits a {RoleRevoked}
* event.
*
* Requirements:
*
* - the caller must be `callerConfirmation`.
*
* May emit a {RoleRevoked} event.
*/
function renounceRole(bytes32 role, address callerConfirmation) public virtual {
if (callerConfirmation != _msgSender()) {
revert AccessControlBadConfirmation();
}
_revokeRole(role, callerConfirmation);
}
/**
* @dev Sets `adminRole` as ``role``'s admin role.
*
* Emits a {RoleAdminChanged} event.
*/
function _setRoleAdmin(bytes32 role, bytes32 adminRole) internal virtual {
bytes32 previousAdminRole = getRoleAdmin(role);
_roles[role].adminRole = adminRole;
emit RoleAdminChanged(role, previousAdminRole, adminRole);
}
/**
* @dev Attempts to grant `role` to `account` and returns a boolean indicating if `role` was granted.
*
* Internal function without access restriction.
*
* May emit a {RoleGranted} event.
*/
function _grantRole(bytes32 role, address account) internal virtual returns (bool) {
if (!hasRole(role, account)) {
_roles[role].hasRole[account] = true;
emit RoleGranted(role, account, _msgSender());
return true;
} else {
return false;
}
}
/**
* @dev Attempts to revoke `role` to `account` and returns a boolean indicating if `role` was revoked.
*
* Internal function without access restriction.
*
* May emit a {RoleRevoked} event.
*/
function _revokeRole(bytes32 role, address account) internal virtual returns (bool) {
if (hasRole(role, account)) {
_roles[role].hasRole[account] = false;
emit RoleRevoked(role, account, _msgSender());
return true;
} else {
return false;
}
}
}
contracts/external/openzeppelin-v5/contracts/access/IAccessControl.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (access/IAccessControl.sol)
pragma solidity ^0.8.20;
/**
* @dev External interface of AccessControl declared to support ERC165 detection.
*/
interface IAccessControl {
/**
* @dev The `account` is missing a role.
*/
error AccessControlUnauthorizedAccount(address account, bytes32 neededRole);
/**
* @dev The caller of a function is not the expected one.
*
* NOTE: Don't confuse with {AccessControlUnauthorizedAccount}.
*/
error AccessControlBadConfirmation();
/**
* @dev Emitted when `newAdminRole` is set as ``role``'s admin role, replacing `previousAdminRole`
*
* `DEFAULT_ADMIN_ROLE` is the starting admin for all roles, despite
* {RoleAdminChanged} not being emitted signaling this.
*/
event RoleAdminChanged(bytes32 indexed role, bytes32 indexed previousAdminRole, bytes32 indexed newAdminRole);
/**
* @dev Emitted when `account` is granted `role`.
*
* `sender` is the account that originated the contract call, an admin role
* bearer except when using {AccessControl-_setupRole}.
*/
event RoleGranted(bytes32 indexed role, address indexed account, address indexed sender);
/**
* @dev Emitted when `account` is revoked `role`.
*
* `sender` is the account that originated the contract call:
* - if using `revokeRole`, it is the admin role bearer
* - if using `renounceRole`, it is the role bearer (i.e. `account`)
*/
event RoleRevoked(bytes32 indexed role, address indexed account, address indexed sender);
/**
* @dev Returns `true` if `account` has been granted `role`.
*/
function hasRole(bytes32 role, address account) external view returns (bool);
/**
* @dev Returns the admin role that controls `role`. See {grantRole} and
* {revokeRole}.
*
* To change a role's admin, use {AccessControl-_setRoleAdmin}.
*/
function getRoleAdmin(bytes32 role) external view returns (bytes32);
/**
* @dev Grants `role` to `account`.
*
* If `account` had not been already granted `role`, emits a {RoleGranted}
* event.
*
* Requirements:
*
* - the caller must have ``role``'s admin role.
*/
function grantRole(bytes32 role, address account) external;
/**
* @dev Revokes `role` from `account`.
*
* If `account` had been granted `role`, emits a {RoleRevoked} event.
*
* Requirements:
*
* - the caller must have ``role``'s admin role.
*/
function revokeRole(bytes32 role, address account) external;
/**
* @dev Revokes `role` from the calling account.
*
* Roles are often managed via {grantRole} and {revokeRole}: this function's
* purpose is to provide a mechanism for accounts to lose their privileges
* if they are compromised (such as when a trusted device is misplaced).
*
* If the calling account had been granted `role`, emits a {RoleRevoked}
* event.
*
* Requirements:
*
* - the caller must be `callerConfirmation`.
*/
function renounceRole(bytes32 role, address callerConfirmation) external;
}
contracts/external/openzeppelin-v5/contracts/access/extensions/AccessControlEnumerable.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (access/extensions/AccessControlEnumerable.sol)
pragma solidity ^0.8.20;
import {IAccessControlEnumerable} from "./IAccessControlEnumerable.sol";
import {AccessControl} from "../AccessControl.sol";
import {EnumerableSet} from "../../utils/structs/EnumerableSet.sol";
/**
* @dev Extension of {AccessControl} that allows enumerating the members of each role.
*/
abstract contract AccessControlEnumerable is IAccessControlEnumerable, AccessControl {
using EnumerableSet for EnumerableSet.AddressSet;
mapping(bytes32 role => EnumerableSet.AddressSet) private _roleMembers;
/**
* @dev See {IERC165-supportsInterface}.
*/
function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {
return interfaceId == type(IAccessControlEnumerable).interfaceId || super.supportsInterface(interfaceId);
}
/**
* @dev Returns one of the accounts that have `role`. `index` must be a
* value between 0 and {getRoleMemberCount}, non-inclusive.
*
* Role bearers are not sorted in any particular way, and their ordering may
* change at any point.
*
* WARNING: When using {getRoleMember} and {getRoleMemberCount}, make sure
* you perform all queries on the same block. See the following
* https://forum.openzeppelin.com/t/iterating-over-elements-on-enumerableset-in-openzeppelin-contracts/2296[forum post]
* for more information.
*/
function getRoleMember(bytes32 role, uint256 index) public view virtual returns (address) {
return _roleMembers[role].at(index);
}
/**
* @dev Returns the number of accounts that have `role`. Can be used
* together with {getRoleMember} to enumerate all bearers of a role.
*/
function getRoleMemberCount(bytes32 role) public view virtual returns (uint256) {
return _roleMembers[role].length();
}
/**
* @dev Overload {AccessControl-_grantRole} to track enumerable memberships
*/
function _grantRole(bytes32 role, address account) internal virtual override returns (bool) {
bool granted = super._grantRole(role, account);
if (granted) {
_roleMembers[role].add(account);
}
return granted;
}
/**
* @dev Overload {AccessControl-_revokeRole} to track enumerable memberships
*/
function _revokeRole(bytes32 role, address account) internal virtual override returns (bool) {
bool revoked = super._revokeRole(role, account);
if (revoked) {
_roleMembers[role].remove(account);
}
return revoked;
}
}
contracts/external/openzeppelin-v5/contracts/access/extensions/IAccessControlEnumerable.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (access/extensions/IAccessControlEnumerable.sol)
pragma solidity ^0.8.20;
import {IAccessControl} from "../IAccessControl.sol";
/**
* @dev External interface of AccessControlEnumerable declared to support ERC165 detection.
*/
interface IAccessControlEnumerable is IAccessControl {
/**
* @dev Returns one of the accounts that have `role`. `index` must be a
* value between 0 and {getRoleMemberCount}, non-inclusive.
*
* Role bearers are not sorted in any particular way, and their ordering may
* change at any point.
*
* WARNING: When using {getRoleMember} and {getRoleMemberCount}, make sure
* you perform all queries on the same block. See the following
* https://forum.openzeppelin.com/t/iterating-over-elements-on-enumerableset-in-openzeppelin-contracts/2296[forum post]
* for more information.
*/
function getRoleMember(bytes32 role, uint256 index) external view returns (address);
/**
* @dev Returns the number of accounts that have `role`. Can be used
* together with {getRoleMember} to enumerate all bearers of a role.
*/
function getRoleMemberCount(bytes32 role) external view returns (uint256);
}
contracts/external/openzeppelin-v5/contracts/utils/Context.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.1) (utils/Context.sol)
pragma solidity ^0.8.20;
/**
* @dev Provides information about the current execution context, including the
* sender of the transaction and its data. While these are generally available
* via msg.sender and msg.data, they should not be accessed in such a direct
* manner, since when dealing with meta-transactions the account sending and
* paying for execution may not be the actual sender (as far as an application
* is concerned).
*
* This contract is only required for intermediate, library-like contracts.
*/
abstract contract Context {
function _msgSender() internal view virtual returns (address) {
return msg.sender;
}
function _msgData() internal view virtual returns (bytes calldata) {
return msg.data;
}
function _contextSuffixLength() internal view virtual returns (uint256) {
return 0;
}
}
contracts/external/openzeppelin-v5/contracts/utils/introspection/ERC165.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (utils/introspection/ERC165.sol)
pragma solidity ^0.8.20;
import {IERC165} from "./IERC165.sol";
/**
* @dev Implementation of the {IERC165} interface.
*
* Contracts that want to implement ERC165 should inherit from this contract and override {supportsInterface} to check
* for the additional interface id that will be supported. For example:
*
* ```solidity
* function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {
* return interfaceId == type(MyInterface).interfaceId || super.supportsInterface(interfaceId);
* }
* ```
*/
abstract contract ERC165 is IERC165 {
/**
* @dev See {IERC165-supportsInterface}.
*/
function supportsInterface(bytes4 interfaceId) public view virtual returns (bool) {
return interfaceId == type(IERC165).interfaceId;
}
}
contracts/external/openzeppelin-v5/contracts/utils/introspection/IERC165.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (utils/introspection/IERC165.sol)
pragma solidity ^0.8.20;
/**
* @dev Interface of the ERC165 standard, as defined in the
* https://eips.ethereum.org/EIPS/eip-165[EIP].
*
* Implementers can declare support of contract interfaces, which can then be
* queried by others ({ERC165Checker}).
*
* For an implementation, see {ERC165}.
*/
interface IERC165 {
/**
* @dev Returns true if this contract implements the interface defined by
* `interfaceId`. See the corresponding
* https://eips.ethereum.org/EIPS/eip-165#how-interfaces-are-identified[EIP section]
* to learn more about how these ids are created.
*
* This function call must use less than 30 000 gas.
*/
function supportsInterface(bytes4 interfaceId) external view returns (bool);
}
contracts/external/openzeppelin-v5/contracts/utils/structs/EnumerableSet.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (utils/structs/EnumerableSet.sol)
// This file was procedurally generated from scripts/generate/templates/EnumerableSet.js.
pragma solidity ^0.8.20;
/**
* @dev Library for managing
* https://en.wikipedia.org/wiki/Set_(abstract_data_type)[sets] of primitive
* types.
*
* Sets have the following properties:
*
* - Elements are added, removed, and checked for existence in constant time
* (O(1)).
* - Elements are enumerated in O(n). No guarantees are made on the ordering.
*
* ```solidity
* contract Example {
* // Add the library methods
* using EnumerableSet for EnumerableSet.AddressSet;
*
* // Declare a set state variable
* EnumerableSet.AddressSet private mySet;
* }
* ```
*
* As of v3.3.0, sets of type `bytes32` (`Bytes32Set`), `address` (`AddressSet`)
* and `uint256` (`UintSet`) are supported.
*
* [WARNING]
* ====
* Trying to delete such a structure from storage will likely result in data corruption, rendering the structure
* unusable.
* See https://github.com/ethereum/solidity/pull/11843[ethereum/solidity#11843] for more info.
*
* In order to clean an EnumerableSet, you can either remove all elements one by one or create a fresh instance using an
* array of EnumerableSet.
* ====
*/
library EnumerableSet {
// To implement this library for multiple types with as little code
// repetition as possible, we write it in terms of a generic Set type with
// bytes32 values.
// The Set implementation uses private functions, and user-facing
// implementations (such as AddressSet) are just wrappers around the
// underlying Set.
// This means that we can only create new EnumerableSets for types that fit
// in bytes32.
struct Set {
// Storage of set values
bytes32[] _values;
// Position is the index of the value in the `values` array plus 1.
// Position 0 is used to mean a value is not in the set.
mapping(bytes32 value => uint256) _positions;
}
/**
* @dev Add a value to a set. O(1).
*
* Returns true if the value was added to the set, that is if it was not
* already present.
*/
function _add(Set storage set, bytes32 value) private returns (bool) {
if (!_contains(set, value)) {
set._values.push(value);
// The value is stored at length-1, but we add 1 to all indexes
// and use 0 as a sentinel value
set._positions[value] = set._values.length;
return true;
} else {
return false;
}
}
/**
* @dev Removes a value from a set. O(1).
*
* Returns true if the value was removed from the set, that is if it was
* present.
*/
function _remove(Set storage set, bytes32 value) private returns (bool) {
// We cache the value's position to prevent multiple reads from the same storage slot
uint256 position = set._positions[value];
if (position != 0) {
// Equivalent to contains(set, value)
// To delete an element from the _values array in O(1), we swap the element to delete with the last one in
// the array, and then remove the last element (sometimes called as 'swap and pop').
// This modifies the order of the array, as noted in {at}.
uint256 valueIndex = position - 1;
uint256 lastIndex = set._values.length - 1;
if (valueIndex != lastIndex) {
bytes32 lastValue = set._values[lastIndex];
// Move the lastValue to the index where the value to delete is
set._values[valueIndex] = lastValue;
// Update the tracked position of the lastValue (that was just moved)
set._positions[lastValue] = position;
}
// Delete the slot where the moved value was stored
set._values.pop();
// Delete the tracked position for the deleted slot
delete set._positions[value];
return true;
} else {
return false;
}
}
/**
* @dev Returns true if the value is in the set. O(1).
*/
function _contains(Set storage set, bytes32 value) private view returns (bool) {
return set._positions[value] != 0;
}
/**
* @dev Returns the number of values on the set. O(1).
*/
function _length(Set storage set) private view returns (uint256) {
return set._values.length;
}
/**
* @dev Returns the value stored at position `index` in the set. O(1).
*
* Note that there are no guarantees on the ordering of values inside the
* array, and it may change when more values are added or removed.
*
* Requirements:
*
* - `index` must be strictly less than {length}.
*/
function _at(Set storage set, uint256 index) private view returns (bytes32) {
return set._values[index];
}
/**
* @dev Return the entire set in an array
*
* WARNING: This operation will copy the entire storage to memory, which can be quite expensive. This is designed
* to mostly be used by view accessors that are queried without any gas fees. Developers should keep in mind that
* this function has an unbounded cost, and using it as part of a state-changing function may render the function
* uncallable if the set grows to a point where copying to memory consumes too much gas to fit in a block.
*/
function _values(Set storage set) private view returns (bytes32[] memory) {
return set._values;
}
// Bytes32Set
struct Bytes32Set {
Set _inner;
}
/**
* @dev Add a value to a set. O(1).
*
* Returns true if the value was added to the set, that is if it was not
* already present.
*/
function add(Bytes32Set storage set, bytes32 value) internal returns (bool) {
return _add(set._inner, value);
}
/**
* @dev Removes a value from a set. O(1).
*
* Returns true if the value was removed from the set, that is if it was
* present.
*/
function remove(Bytes32Set storage set, bytes32 value) internal returns (bool) {
return _remove(set._inner, value);
}
/**
* @dev Returns true if the value is in the set. O(1).
*/
function contains(Bytes32Set storage set, bytes32 value) internal view returns (bool) {
return _contains(set._inner, value);
}
/**
* @dev Returns the number of values in the set. O(1).
*/
function length(Bytes32Set storage set) internal view returns (uint256) {
return _length(set._inner);
}
/**
* @dev Returns the value stored at position `index` in the set. O(1).
*
* Note that there are no guarantees on the ordering of values inside the
* array, and it may change when more values are added or removed.
*
* Requirements:
*
* - `index` must be strictly less than {length}.
*/
function at(Bytes32Set storage set, uint256 index) internal view returns (bytes32) {
return _at(set._inner, index);
}
/**
* @dev Return the entire set in an array
*
* WARNING: This operation will copy the entire storage to memory, which can be quite expensive. This is designed
* to mostly be used by view accessors that are queried without any gas fees. Developers should keep in mind that
* this function has an unbounded cost, and using it as part of a state-changing function may render the function
* uncallable if the set grows to a point where copying to memory consumes too much gas to fit in a block.
*/
function values(Bytes32Set storage set) internal view returns (bytes32[] memory) {
bytes32[] memory store = _values(set._inner);
bytes32[] memory result;
/// @solidity memory-safe-assembly
assembly {
result := store
}
return result;
}
// AddressSet
struct AddressSet {
Set _inner;
}
/**
* @dev Add a value to a set. O(1).
*
* Returns true if the value was added to the set, that is if it was not
* already present.
*/
function add(AddressSet storage set, address value) internal returns (bool) {
return _add(set._inner, bytes32(uint256(uint160(value))));
}
/**
* @dev Removes a value from a set. O(1).
*
* Returns true if the value was removed from the set, that is if it was
* present.
*/
function remove(AddressSet storage set, address value) internal returns (bool) {
return _remove(set._inner, bytes32(uint256(uint160(value))));
}
/**
* @dev Returns true if the value is in the set. O(1).
*/
function contains(AddressSet storage set, address value) internal view returns (bool) {
return _contains(set._inner, bytes32(uint256(uint160(value))));
}
/**
* @dev Returns the number of values in the set. O(1).
*/
function length(AddressSet storage set) internal view returns (uint256) {
return _length(set._inner);
}
/**
* @dev Returns the value stored at position `index` in the set. O(1).
*
* Note that there are no guarantees on the ordering of values inside the
* array, and it may change when more values are added or removed.
*
* Requirements:
*
* - `index` must be strictly less than {length}.
*/
function at(AddressSet storage set, uint256 index) internal view returns (address) {
return address(uint160(uint256(_at(set._inner, index))));
}
/**
* @dev Return the entire set in an array
*
* WARNING: This operation will copy the entire storage to memory, which can be quite expensive. This is designed
* to mostly be used by view accessors that are queried without any gas fees. Developers should keep in mind that
* this function has an unbounded cost, and using it as part of a state-changing function may render the function
* uncallable if the set grows to a point where copying to memory consumes too much gas to fit in a block.
*/
function values(AddressSet storage set) internal view returns (address[] memory) {
bytes32[] memory store = _values(set._inner);
address[] memory result;
/// @solidity memory-safe-assembly
assembly {
result := store
}
return result;
}
// UintSet
struct UintSet {
Set _inner;
}
/**
* @dev Add a value to a set. O(1).
*
* Returns true if the value was added to the set, that is if it was not
* already present.
*/
function add(UintSet storage set, uint256 value) internal returns (bool) {
return _add(set._inner, bytes32(value));
}
/**
* @dev Removes a value from a set. O(1).
*
* Returns true if the value was removed from the set, that is if it was
* present.
*/
function remove(UintSet storage set, uint256 value) internal returns (bool) {
return _remove(set._inner, bytes32(value));
}
/**
* @dev Returns true if the value is in the set. O(1).
*/
function contains(UintSet storage set, uint256 value) internal view returns (bool) {
return _contains(set._inner, bytes32(value));
}
/**
* @dev Returns the number of values in the set. O(1).
*/
function length(UintSet storage set) internal view returns (uint256) {
return _length(set._inner);
}
/**
* @dev Returns the value stored at position `index` in the set. O(1).
*
* Note that there are no guarantees on the ordering of values inside the
* array, and it may change when more values are added or removed.
*
* Requirements:
*
* - `index` must be strictly less than {length}.
*/
function at(UintSet storage set, uint256 index) internal view returns (uint256) {
return uint256(_at(set._inner, index));
}
/**
* @dev Return the entire set in an array
*
* WARNING: This operation will copy the entire storage to memory, which can be quite expensive. This is designed
* to mostly be used by view accessors that are queried without any gas fees. Developers should keep in mind that
* this function has an unbounded cost, and using it as part of a state-changing function may render the function
* uncallable if the set grows to a point where copying to memory consumes too much gas to fit in a block.
*/
function values(UintSet storage set) internal view returns (uint256[] memory) {
bytes32[] memory store = _values(set._inner);
uint256[] memory result;
/// @solidity memory-safe-assembly
assembly {
result := store
}
return result;
}
}
contracts/rwaOracles/IRWADynamicOracle.sol
/**
* SPDX-License-Identifier: BUSL-1.1
*
* ▄▄█████████▄
* ╓██▀└ ,╓▄▄▄, '▀██▄
* ██▀ ▄██▀▀╙╙▀▀██▄ └██µ ,, ,, , ,,, ,,,
* ██ ,██¬ ▄████▄ ▀█▄ ╙█▄ ▄███▀▀███▄ ███▄ ██ ███▀▀▀███▄ ▄███▀▀███,
* ██ ██ ╒█▀' ╙█▌ ╙█▌ ██ ▐██ ███ █████, ██ ██▌ └██▌ ██▌ └██▌
* ██ ▐█▌ ██ ╟█ █▌ ╟█ ██▌ ▐██ ██ └███ ██ ██▌ ╟██ j██ ╟██
* ╟█ ██ ╙██ ▄█▀ ▐█▌ ██ ╙██ ██▌ ██ ╙████ ██▌ ▄██▀ ██▌ ,██▀
* ██ "██, ╙▀▀███████████⌐ ╙████████▀ ██ ╙██ ███████▀▀ ╙███████▀`
* ██▄ ╙▀██▄▄▄▄▄,,, ¬─ '─¬
* ╙▀██▄ '╙╙╙▀▀▀▀▀▀▀▀
* ╙▀▀██████R⌐
*
*/
pragma solidity ^0.8.4;
interface IRWADynamicOracle {
/// @notice Retrieve RWA price data
function getPrice() external view returns (uint256);
}
contracts/rwaOracles/IRWAOracle.sol
/**
* SPDX-License-Identifier: BUSL-1.1
*
* ▄▄█████████▄
* ╓██▀└ ,╓▄▄▄, '▀██▄
* ██▀ ▄██▀▀╙╙▀▀██▄ └██µ ,, ,, , ,,, ,,,
* ██ ,██¬ ▄████▄ ▀█▄ ╙█▄ ▄███▀▀███▄ ███▄ ██ ███▀▀▀███▄ ▄███▀▀███,
* ██ ██ ╒█▀' ╙█▌ ╙█▌ ██ ▐██ ███ █████, ██ ██▌ └██▌ ██▌ └██▌
* ██ ▐█▌ ██ ╟█ █▌ ╟█ ██▌ ▐██ ██ └███ ██ ██▌ ╟██ j██ ╟██
* ╟█ ██ ╙██ ▄█▀ ▐█▌ ██ ╙██ ██▌ ██ ╙████ ██▌ ▄██▀ ██▌ ,██▀
* ██ "██, ╙▀▀███████████⌐ ╙████████▀ ██ ╙██ ███████▀▀ ╙███████▀`
* ██▄ ╙▀██▄▄▄▄▄,,, ¬─ '─¬
* ╙▀██▄ '╙╙╙▀▀▀▀▀▀▀▀
* ╙▀▀██████R⌐
*
*/
pragma solidity ^0.8.4;
interface IRWAOracle {
/// @notice Retrieve RWA price data
function getPriceData() external view returns (uint256 price, uint256 timestamp);
}
Compiler settingsShow
{
"viaIR": false,
"metadata": {
"appendCBOR": true,
"bytecodeHash": "ipfs",
"useLiteralContent": false
},
"optimizer": {
"runs": 200,
"enabled": true
},
"evmVersion": "prague",
"remappings": [
"eth-gas-reporter/=node_modules/eth-gas-reporter/",
"forge-tests/=forge-tests/",
"lib/=lib/",
"forge-std/=lib/forge-std/src/"
]
}Source code and metadata: Sourcify.
The source code belongs to the authors of the contract.