RedStone-Data Aggregation: role in blockchain oracles

CaméSennin
5 min readMay 29, 2024

--

In a first article we explored RedStone’s modular design, then in a second the 3 ways to integrate RedStone into your dApp. Today, we explore the role of data aggregation in an oracle, and why it’s important.

What is Data Aggregation ?

Data aggregation is the process where raw data is gathered and expressed in a summary form for statistical analysis.

For example, raw data can be aggregated over a given time period to provide statistics such as average, minimum, maximum, sum, and count. After the data is aggregated and written to a view or report, you can analyze the aggregated data to gain insights about particular resources or resource groups.

https://www.ibm.com/docs/en/tnpm/1.4.2?topic=data-aggregation

In the context of a blockchain, an easy example is collecting price data for a pair of token e.g., ETH/USDC or USDC/USDT, from several exchanges (CEXs or DEXs) and calculating the average value.

In decentralized systems, particularly in blockchain and DeFi applications, data aggregation plays a pivotal role for 3 main reasons:

  • Reliability and Redundancy: getting data from different sources ensures the availability and the accuracy of the information, even if one or more sources fail or provide incorrect data.
  • Accuracy: using data from multiple sources means that the chances of errors or anomalies affecting the overall data quality are minimized. Aggregated data tends to be more accurate and representative of the true state of the market.
  • Security: the aggregation of data helps mitigate risks such as manipulation or inaccuracies that could arise from relying on a single data source. This is particularly important in preventing attacks like front-running in financial markets.

Very recently, we witnessed RedStone’s effectiveness in maintaining the right price for token data in the case of the $ezETH depeg. You can find excellent explanation right here.

The quality of data provided by an oracle service hinges on two primary criteria: the Data Availability and the Data Correctness.

  1. Data Availability: data must be accessible to end users (or smart contracts) and should be updated at the promised frequency.
  2. Data Correctness: data must be correct end as accurate as possible. The ways of doing it depend on the type of data. Defining correctness can be more challenging for assets with highly variable prices over time.

Various data aggregation techniques enable oracles to meet these two criteria as closely as possible. I already gave some details about how data sources and aggregation in this article. In the case of RedStone Oracle, aggregating data from more than 50 sources improves value correctness and data availability. Indeed, the aggregated value is less likely to be corrupted by a unreliable sources and even if some sources fail, the oracle service can still operate effectively.

Let’s dive into 4 ways to aggregate your data:

1 - Average Price Value

The most easy way to aggregate data is calculating the Average Price Value of several data sources. This simple approach does, however, have one significant drawback: it is not resistant to manipulation.

For example, assume that you want to get the ETH/USD value from 5 different exchanges, where 4 of them claim that the current price is around $2000, but one of them insists that it’s only $1. Then the average value is ~$1600, which is too deviated and can not be considered correct.

To avoid that, average price value is combined with interquartile range filter. In the following example, data are aggregated between 3 sources in red, yellow and green, and the Average Price Value is calculated in blue.

https://blog.redstone.finance/2022/08/17/what-you-must-know-about-data-agregation-and-its-role-in-blockchain-oracles/

2 - Median Price Value

A more resistant way to face manipulations by corrupted sources is the Median Price Value. But it is not considered a perfect way to aggregate prices.

As an example, assume that you take the same ETH/USD value from one large crypto exchange ($100m daily trading volume on ETH/USD market) and 4 small ones (~$10k daily trading volume on ETH/USD market), and the large exchange provides value $2000, but all the small ones — less than $1900. Then the aggregated median value, in this case, will be less than $1900, but, as you can guess, it’s not close enough to the “real” market value.

In the following example you can find 6 data sources from different CEXs, and the Median Price Value represented in red.

https://blog.redstone.finance/2022/08/17/what-you-must-know-about-data-agregation-and-its-role-in-blockchain-oracles/

3 - Volume-Weighted Average Price (VWAP)

One of the best aggregation method is the Volume-Weighted Average Price. It takes into account the different volumes of trades in different sources.

The more trading volume a source has — the bigger the weight of its price value.

It is worth mentioning, that thanks to the easy liquidity calculation on Decentralized Exchanges (like Uniswap, Sushiswap, PancakeSwap, and others), it is also possible to calculate the Liquidity-Weighted Average Price (LWAP) aggregated from multiple decentralized exchanges, which has similar advantages to the VWAP.

In the following example, 3 sources are represented in blue, red and yellow. The Volume-Weighted Average Price is in green. The source 2 and 3 represent a small volume, respectively 15% and 5%. As you can see the Volume-Weighted Average Price is very close from the source 1 which represents 80% of the considered volume.

https://blog.redstone.finance/2022/08/17/what-you-must-know-about-data-agregation-and-its-role-in-blockchain-oracles/

4 - Time-weighted Average Price (TWAP)

The last introduced method for price aggregation is based Time-weighted Average Price. It is based on the time criterion and it is very useful for calculating price values based only on decentralized exchanges.

But besides DEX-based oracles, this method can be used to make market manipulation harder in case of a limited amount of data sources.

RedStone Oracle use TWAPs to make the pricing data of low-liquidity assets more stable and reliable.

https://blog.redstone.finance/2022/08/17/what-you-must-know-about-data-agregation-and-its-role-in-blockchain-oracles/

Useful Links

RedStone website: https://redstone.finance/

RedStone blog: https://blog.redstone.finance/

Zealy: https://zealy.io/cw/redstoneoracles/questboard

X: https://x.com/redstone_defi

Discord: https://discord.gg/KYTkpPX6

Lens: https://hey.xyz/u/redstone_oracles

RedStone ambassadors (among others):
https://medium.com/@charlottekindt

https://medium.com/@LeCriptal

--

--