Orakl Network Fetcher
Description
The Orakl Network Fetcher is an auxiliary service for Data Feed solution to collect the most up-to-date data from various sources.
The code is located under fetcher
directory.
State Setup
Adapter & Aggregator
The Orakl Network Fetcher and the Orakl Network Data Feed are configured with adapter and aggregator abstractions. Every data feed collected by the Orakl Network Fetcher and then submitted to on-chain by the Orakl Network Data Feed is defined with an adapter-aggregator pair. Adapters and aggregators are defined in JSON format. You can find a detailed description of them below.
An adapter is a set of data sources (feeds
) and post-processing rules (reducers
) that are applied on data received from feeds
. Additionally, every adapter has a name
, decimals
and an adapterHash
. decimals
property represents a number of decimal points in which the post processed values are encoded. The values itself are in an integer
format and decimal points are stored separately. Lastly, adapterHash
is computed from all properties of adapter except the adapterHash
itself. It was defined for safety reasons so nobody can accidentally modify the adapter without anybody noticing.
An aggregator is described with on-chain metadata (address
), off-chain metadata (name
, heartbeat
, threshold
, absoluteThreshold
), and connection to an adapter (adapterHash
). address
corresponds to deployed smart contract Aggregator
that accepts submissions from whitelisted node operators for a data feed defined using an adapter that is identified with adapterHash
. name
offers a description of the aggregator. heartbeat
defines the lowest frequency update (value is denoted in milliseconds) of Aggregator
smart contract. threshold
represents a minimum required value deviation (e.g. 0.05 equals to ±5 % deviation) in the data feed that leads to early submission to data feed. When the range of possible values in data feed is between 0 and ∞, absoluteThreshold
is used to define a minimum absolute change that must be observed before the data feed starts being updated again after the data feed value became a zero. adapterHash
represents a unary relationship between aggregator and adapter.
Add Adapter & Aggregator
If there are no adapters and aggregators in Orakl Network state, you can create them through the Orakl Network CLI. To find out, if there are any adapter and aggregator in Orakl Network state, you can execute the command below.
Agregators are associated with chain
, therefore if you have not defined any chain through the Orakl Network API yet, you need to do it before adding any aggregator.
An example of adding adapter and aggregator to localhost
chain is shown at the code listing below. Please note that adapterHash
in adapter and aggregator JSON files has to be same, otherwise they would not be associated. If you try to add aggregator with adapterHash
that has not been registered, the operation will be aborted.
example
Proxies (Optional)
In addition to configuring adapters and aggregators, the Orakl Network also provides the option to add proxies, which can be used for data fetching through defined proxy configurations.
Add proxy
An example to add proxy with host:127.0.0.1
, with port:88
Activate Aggregator
After the adapters and aggregators are registered to Orakl Network state, they are in an inactive state at first. If we want them to use for data collection, we have to activate them. Activation can be performed through the Orakl Network CLI.
example
Deactivate Aggregator
Data collection defined with an adapter-aggregator pair can be stopped anytime by executing a command below with appropriate aggregatorHash
.
example
Configuration
Before we launch the Orakl Network Fetcher, we must specify several environment variables. The environment variables are automatically loaded from a .env
file.
REDIS_HOST
REDIS_PORT
ORAKL_NETWORK_API_URL
APP_PORT
CHAIN
FETCHER_TYPE
REDIS_HOST
and REDIS_PORT
represent host and port of Redis to which the Orakl Network Fetcher connect to. The default values are localhost
and 6379
, respectively. Redis is used indirectly through BullMQ to collect data in regular predefined intervals.
ORAKL_NETWORK_API_URL
corresponds to url where the Orakl Network API is running. Collected and aggregated data by the Orakl Network Fetcher will be send to PostgreSQL through the Orakl Network API interface.
APP_PORT
represents a port on which the Orakl Network Fetcher will be running. This port will be necessary when we connect to Orakl Network API from other services (e.g. Orakl Network CLI).
CHAIN
represents name of chain for which data are collected.
FETCHER_TYPE
represents type of fetcher will be used for the current fetcher.
Launch
To launch the Orakl Network Fetcher from source code in the production, one must first build the service, and then it can be launched.
After the Orakl Network Fetcher is launched, all active aggregators will start to
collect data for each data source defined in adapter feeds of activated aggregator, and
compute and store their aggregate.
The collected and computed data are sent through the Orakl Network API to PostgreSQL. Aggregators can be actived and deactivated while the Orakl Network Fetcher is running.
Architecture
Last updated