Onboarding a new Price Feed using Configuration
This document will walk you through configuring and deploying a price feed oracle in IntelliX that fetches data from multiple exchanges, each with its own response format, and publishes the aggregated result to multiple blockchain networks.
Firstly, let's create a intellix.yaml to store the configuration. We begin by defining the oracle name and unique id type in the configuration file
name: BTC/USDT
id: 5d34c60b-e665-44c3-a55e-34851a359dc9
sources:
...
processors:
...
publishers:
...
validators:
...
output_schema:
...The configuration contains the following main sections:
Sources: This section defines how data is retrieved from external sources. It will include the URLs of the data sources (e.g., Binance, Coinbase, Kraken, Bitfinex) from where the BTC/USDT price is fetched.
Processors: This section will define how the raw data fetched from sources is processed. Here, we will use JSONPath processors to extract the relevant price data from the API responses of the exchanges.
Validators: This section specifies the validation method to be applied to the fetched and processed data. In this example, a price validator that combines both the median and average of the prices from different exchanges is used to ensure accuracy before publishing.
Publishers: This section contains details about where the validated price data will be published. The contract addresses for different blockchain networks (e.g., Bitlayer, BSC, Merlin) are included to ensure the data is delivered to the correct destination for on-chain use.
Output Schema:The schema defines the structure of the final output, which in this case is represented by the BTC/USDT price.
Sources Configuration
Define the Data Sources and Processing Rules
Each exchange provides its price feed in JSON format, but the structure of the response varies from one exchange to another. For example, Binance may return a price directly in a simple JSON object, while Kraken or Bitfinex might embed the price deeper within a nested JSON structure.
To handle these differences, IntelliX uses JSONPath expressions to specify exactly how the price data should be extracted from each source. For example:
Binance
URL:
https://api.binance.com/api/v3/ticker/price?symbol=BTCUSDTSample Response:
JSONPath:
$.price
Coinbase
URL:
https://api.exchange.coinbase.com/products/BTC-USD/tickerSample Response:
JSONPath:
$.price
Kraken
URL:
https://api.kraken.com/0/public/Ticker?pair=XBTUSDSample Response:
JSONPath:
$.result.XXBTZUSD.c[0](for last price)
Bitfinex
URL:
https://api-pub.bitfinex.com/v2/ticker/tBTCUSDSample Response:
JSONPath:
$[6](index 6 contains the last price)
These URLs and corresponding JSONPaths will allow you to fetch real-time BTC/USDT price data from each exchange and integrate them into your IntelliX oracle setup.
The configuration will look like the following:
Mode of Operation
IntelliX allows you to configure the mode of operation for your oracle. You can choose between the following modes:
push: The oracle will periodically fetch and publish data based on the defined update frequency.
pull: The oracle only responds when a request is made to pull data.
push_and_pull: The oracle operates in both modes, periodically pushing data and also responding to pull requests.
When the mode is set to push, you must also define the update frequency and, optionally, an end_time. The update frequency determines how often the oracle will fetch and publish data, while the end time specifies the time (in UTC or epoch) the oracle should stop pushing data. If an end time is not provided, the oracle will stop pushing data after the gas has run out.
When the push or push_and_pull mode is employed, the configuration also requires a publishers section, listing the target contract addresses where data will be periodically published.
In contrary, when pull mode is used, the data is fetched and processed only when requested by a smart contract. The smart contract directly queries the oracle to retrieve the necessary data at the time of execution. Since there is no need to automatically push or publish the data on-chain at regular intervals, the publishers section becomes unnecessary in this scenario.
More information about the pull contract requirements is available here.
In the current version, only pull mode is supported
Publishers Configuration (optional)
When the push or push_and_pull mode is employed feeds can be automatically published to multiple networks.
IntelliX requires a standard contract to be deployed on each target network before publishing any data from an oracle. You will need to provide contract addresses for each target network. For example, if we want to publish our price feeds to BitLayer, BSC and Merlin Chain, the configuration will look like the following:
More information about the push contract requirements is available here.
Validators Configuration
The validator section in this configuration specifies how the fetched data should be validated before being published on-chain. In this case, the validator type is set to price_avg_median, which indicates that the data from multiple sources (like exchanges in a price feed use case) will undergo the validation process described here.
Output Schema Configuration
The output schema in the IntelliX configuration defines the structure and format of the data that is ultimately produced by the oracle after processing. This schema ensures that the data, once validated, adheres to a predefined format that is compatible with smart contracts and can be easily consumed by blockchain applications.
In this specific case, the output schema is represnted by a single floating point value.
Full Configuration Example (Pull)
Below is a complete configuration file that specifies multiple data sources, network-specific contract addresses, and JSONPaths for each exchange.
Deployment
With the configuration complete, we can proceed to deploy the oracle using the IntelliX SDK. Before deployment, ensure that the account has sufficient gas to cover the transaction costs for publishing data.
Last updated