OracleId examples
As the Opium Protocol OracleAggregator is designed to be data source agnostic, it is up to the developer to implement what kind of on-chain or off-chain mechanism is the most suitable to their application.
As it was explained in the previous chapter, in the Opium protocol a financial instrument is defined by two separate entities:
Derivative recipe
Oracle recipe
For the purpose of sharing a common vocabulary, we refer to the contract entity implementing the oracle recipe as OracleId.
In fact, the OracleAggregator itself uses the same terminology. In the OracleAggregator we have a nested mapping that maps the address of an OracleId to a mapping that maps the timestamp when the OracleId provided data to the OracleAggregator to the numerical value provided.
The OracleId’s value is therefore cached and made available to the Opium Protocol Core contract for the execution of the related derivative’s positions (see below):(.
A possible pattern for the development of OracleIds is to split their logic in an OracleId and an OracleSubId. This allows to reason more clearly on the oracle logic and enforce a better separation of concerns and single responsibility principle.
The OracleId is responsible for pushing data into the OracleAggregator contract by calling the OracleAggregator callback function and the OracleSubId is responsible for implementing the oracle-specific logic. The OracleSubId logic can be implemented using Chainlink, UMA etc..
As the most popular oracle solution in the Ethereum space thus far is Chainlink, in the following example we showcase how to implement the OracleId/OracleSubId pattern:
In the above code snippet, the contract implements the OracleId interface. In the OracleId __callback function, the contract fetches the required data from the OracleSubId and provides it to the OracleAggregator.
The OracleSubId is a basic implementation of a Chainlink pricefeed:
Last updated