xFUND Oracle of Oracles for Secure On-Chain Pricing Information
To address the recent issues of multiple “Defi Hacks” due to Oracle price manipulation, the Unification Foundation has developed and is releasing a testnet version of the FUND Oracle of Oracles or OoO.
The FUND OoO (built on the data structure of Finchains.io) takes into account pricing across 15 sources to provide a trusted, true and unaltered price but removing any pricing which is outside the normal standard deviation of the average.
The service can be integrated and accessed from any solidity smart contract to serve & secure all participants in the Defi market.
What this would mean, for example, is that if the price of DAI is manipulated on one exchange to be 15% different from other sources, the number would be removed to not allow any hacks based on that manipulation.
Access and utilisation of the FUND Price Oracle will require xFund, which is an emission of Unification’s FUND token distributed to the network’s validators and also traded on ERC-20 markets.
The FUND price Oracle’s structure includes the xFUND Router and Data Provision service, which utilises data — initially from the Finchains WRKChain — to enable developers to use xFUND tokens in order to pay for real world, off-chain numerical data to be included in their Ethereum smart contracts.
The testnet for the initiative has already been deployed on Rinkeby and is ready for testing. Integration is straight forward, and will be covered in a more detailed technical article to accompany this introduction soon. Mainnet deployment is planned for 1–2 weeks after testnet QA and feedback.
We have also released a full demo, which can be modified, deployed and run on Rinkeby testnet. The demo contains everything required (including instructions, and code comments) to quickly deploy and test a simple Data Consumer smart contract implementation, and can be found in the Github repo. The full documentation and implementation guide is also available.
The project consists of three main components: the Router, the Consumer Library, and the Data Provider Oracle(s), each of which are covered in further detail below.
The first Oracle to be deployed will serve data from the Finchains API, providing tamper resistant immutable crypto pricing on-chain, and will be maintained by the Unification Foundation. The source code can be viewed in our Github repo.
The Router is a smart contract deployed and maintained by Unification Foundation, and is responsible for routing data requests from Consumers to Providers, facilitating data fulfilment from the Provider to the Consumer, and handling the payment of xFUND tokens to Providers upon successful request fulfilment.
Consumers initialise a data request via their own smart contract functions, which forwards a standardised request structure to the Router. The Router then emits a
DataRequested log event, which the Provider Oracles monitor and watch for. When a provider sees an event for them, they grab the off-chain data (for example, querying the Finchains API), and send it back to the Router. The Router then calls the specified function in the Consumer’s smart contract to set the requested data, and finally, if the call was successful, pays the xFUND fee to the Provider.
The Rinkeby testnet deployment is currently live — the contract can be viewed here, along with the source code in our Github repo. The testnet version is currently linked to an “xFUNDMOCK” token, which can be used by developers for testing.
The ConsumerLib is a library of contracts maintained by the Unification Foundation, available via npm. It contains all of the necessary functions required for interacting with the Router smart contract on behalf of the Consumer, and facilitates interaction between the Consumer and Router in a standardised way.
Developers need only import the ConsumerBase.sol thin smart contract into their own smart contract. This not only helps keep the size of the Consumer’s smart contract lower, but means the developer need only define a couple of simple functions in their own smart contract in order to integrate the Consumer features.
Data Provider Oracle
The Oracle is an off-chain application, which runs independently and can grab numerical data from off-chain sources and APIs. The Oracle software listens for any
DataRequested events emitted from the Router smart contract, and acts accordingly.
If the event specifies the Provider’s wallet address, it will decode the data request, and fetch the required data from its linked source API. The Oracle converts the data (by a 10 ** 18 multiplier, to remove any decimals and convert to a standardised integer value), and sends it back to the Router. Upon receiving the fulfilment, the Router runs some basic checks (the provider is authorised, and the Consumer has enough funds to pay the fees etc.), and forwards the data back to the function specified in the Consumer’s smart contract.
Rinkeby Testnet Addresses
Finally, the architecture is currently deployed on the Rinkyby testnet so that developers can test and interact with the system, and the relevant addresses for contracts and the Finchains data provider oracle are as follows:
xFUND Mock Token:
Finchains Oracle Provider:
Paul Hodgson, Unification CTO