Comment on page
OracleHub
The Oracle Hub stores the adressesses and other necessary information of the Price Oracles and returns rates of assets
No end-user should directly interact with the Oracle-Hub, only the Main Registry, Sub-Registries or the contract owner. Current integration is only for mocked Chainlink oracles, and we assume the oracles are honest and functioning properly, no unhappy flows are implemented yet (oracle stops updating, circuit brakers activated...).
mapping(address => bool) public inOracleHub;
mapping(address => OracleInformation) public oracleToOracleInformation;
Constructor
constructor();
Add a new oracle to the Oracle Hub
It is not possible to overwrite the information of an existing Oracle in the Oracle Hub.
Oracles can't have more than 18 decimals.
function addOracle(OracleInformation calldata oracleInformation) external onlyOwner;
Parameters
Name | Type | Description |
---|---|---|
oracleInformation | OracleInformation | A Struct with information about the Oracle: - oracleUnit: the unit of the oracle, equal to 10 to the power of the number of decimals of the oracle - baseAssetBaseCurrency: a unique identifier if the base asset can be used as baseCurrency of a vault, 0 by default if the base asset cannot be used as baseCurrency - baseAssetIsBaseCurrency: boolean indicating if the base asset can be used as baseCurrency of a vault - quoteAsset: The symbol of the quote assets (only used for readability purpose) - baseAsset: The symbol of the base assets (only used for readability purpose) - oracle: The contract address of the oracle - quoteAssetAddress: The contract address of the quote asset |
Checks if a series of oracles adheres to a predefined ruleset
*Function will do nothing if all checks pass, but reverts if at least one check fails. The following checks are performed:
- The oracle-address must be previously added to the Oracle-Hub.
- The last oracle in the series must have USD as base-asset.
- The Base-asset of all oracles must be equal to the quote-asset of the next oracle (except for the last oracle in the series).*
function checkOracleSequence(address[] memory oracles) external view;
Parameters
Name | Type | Description |
---|---|---|
oracles | address[] | An array of addresses of oracle contracts |
Returns the exchange rate of a certain asset, denominated in USD or in another BaseCurrency
*The Function will loop over all oracles-addresses and find the total exchange rate of the asset by multiplying the intermediate exchangerates (max 3) with eachother. Oracles can have any Decimals precision smaller than 18. All intermediate exchange rates are calculated with a precision of 18 decimals and rounded down. Todo: check precision when multiplying multiple small rates -> go to 27 decimals precision?? Function will overflow if any of the intermediate or the final exchange rate overflows Example of 3 oracles with R1 the first exchange rate with D1 decimals and R2 the second exchange rate with D2 decimals R3...
- First intermediate rate will overflow when R1 * 10**18 > MAXUINT256
- Second rate will overflow when R1 * R2 * 10**(18 - D1) > MAXUINT256
- Third and final exchange rate will overflow when R1 * R2 * R3 * 10**(18 - D1 - D2) > MAXUINT256*
The exchange rate of an asset will be denominated in a baseCurrency different from USD if and only if the given baseCurrency is different from USD (baseCurrency is not 0) and one of the intermediate oracles to price the asset has the given baseCurrency as base-asset. The exchange rate of an asset will be denominated in USD if the baseCurrency is USD (baseCurrency equals 0) or the given baseCurrency is different from USD (baseCurrency is not 0) but none of the oracles to price the asset has the given baseCurrency as base-asset. Only one of the two values can be different from 0.
function getRate(address[] memory oracles, uint256 baseCurrency)
public
view
returns (uint256 rateInUsd, uint256 rateInBaseCurrency);
Parameters
Name | Type | Description |
---|---|---|
oracles | address[] | An array of addresses of oracle contracts |
baseCurrency | uint256 | The BaseCurrency (base-asset) in which the exchange rate is ideally expressed |
Returns
Name | Type | Description |
---|---|---|
rateInUsd | uint256 | The exchange rate of the asset denominated in USD, integer with 18 Decimals precision |
rateInBaseCurrency | uint256 | The exchange rate of the asset denominated in a BaseCurrency different from USD, integer with 18 Decimals precision |
struct OracleInformation {
uint64 oracleUnit;
uint8 baseAssetBaseCurrency;
bool baseAssetIsBaseCurrency;
string quoteAsset;
string baseAsset;
address oracle;
address quoteAssetAddress;
}
Last modified 8mo ago