Data Oracles
In the FinP2P ecosystem there are multiple use cases in which external Data Oracles are useful to provide data from information sources that are acceptable to all parties in a transaction.
For example, in a collateralization scenario there may be rules that define the default of a loan under certain external scenarios (such as the drop in the price of a security below a certain level). In this example , both the lender and the borrower would want to know that the “Default” decision was based on reliable information, from a source that all sides agree is valid and impartial.
The specification does not propose any specific implementation of the Data Oracles layer. Vendors may implement this layer in different ways and select from a marketplace of data oracle providers.
Here we are presenting an example of how a distributed data oracle network such as Chainlink can be accessed from within a FinP2P synchronized process in order to retrieve the price of a security. Chainlink is a a decentralized blockchain oracle network built on Ethereum. The network is intended to be used to facilitate the transfer of tamper-proof data from off-chain sources to on-chain smart contracts.
For example to consume price data from chainlink oracles, your smart contract should reference AggregatorV3Interface
, which defines the external functions implemented by Data Feeds.
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.7;
import "@chainlink/contracts/src/v0.8/interfaces/AggregatorV3Interface.sol";
contract PriceConsumerV3 {
AggregatorV3Interface internal priceFeed;
/**
* Aggregator: SPACEX/USD
* Address: 0x9326BFA02ADD2366b30bacB125260Af641031331
*/
constructor() {
priceFeed = AggregatorV3Interface(0x9326BFA02ADD2366b30bacB125260Af641031331);
}
/**
* Returns the latest price
*/
function getLatestPrice() public view returns (int) {
(
uint80 roundID,
int price,
uint startedAt,
uint timeStamp,
uint80 answeredInRound
) = priceFeed.latestRoundData();
return price;
}
}