Tutorial on how to use RedStone for developers

insaino
4 min readAug 27, 2023

--

What RedStone offers us can only be used and reproduced well if people use RedStone features in the right way, what do I mean? To make a quality project on RedStone you need to be a good developer.

About what RedStone is in general.

RedStone is a lightning-fast oracle that provides too frequently updated, reliable and diverse feeds of the most enormous and functional data for your decentralized applications and smart contracts across multiple L1 and L2 that you are most likely to use when doing anything in the cryptocurrency space.

How RedStone helps us.

As I said before, RedStone is an oracle that helps blockchains become faster and more functional, get what? The functionality that the Streamr network has given and the functionality the Arweave blockchain is giving to other blockchains. Blockchain is something we use every day without noticing it, but have you ever noticed how long it takes to process blocks of transactions? I did notice, which is why I decided to take a look at RedStone.

A developer’s perspective on RedStone.

RedStone is an oracle that sends data to the blockchain, but not all the data, only the data that is needed, both for the blockchain to save and for the user to execute the transaction. RedStone is an automated sorter, without which many blockchains lose their true functionality.

Functions RedStone performs.

Putting data directly into storage is the easiest way to make information available for smart contracts. This approach used to work well for long update intervals and a small number of assets. However, DeFi is seeing more and more tokens, and modern derivatives protocols require much lower latency, increasing the cost of maintaining a simple model. Now RedStone is in charge of all these activities that prevent the protocol from working properly, which is quite convenient for 3 parties, the protocol, RedStone, and the protocol users.

RedStone offers a completely new modular design where data is first placed on the data availability layer and then arrives on the chain. This allows a large number of high frequency assets to be translated to a cheaper layer and only brought onto the chain when required by the protocol.

Types of features RedSton provides.

RedStone Core, data is dynamically injected into user transactions, maximizing gas efficiency and maintaining a great user experience as the entire process fits into a single transaction. RedStone’s most basic feature that every protocol needs. Lowest gas costs, latency in seconds, dApp users deliver signed data packets to the destination chain on demand.

RedStone Classic, data is pushed to the chain store via a relay. Designed for protocols developed for the traditional Oracles model that want full control over the data source and update conditions soon. Compatible with traditional Oracles, dApp gains full control over the data source and update conditions with RedStone Classic.

RedStone X targeting the needs of the most advanced protocols such as perpetual contracts, options and derivatives by eliminating the risk of outperformance, ensuring that pricing data is available on the next block after user interaction. It’s also a front end proof of concept for complex protocols like Perps & Options, based on the GMX design.

Types of data processing from RedStone.

Price information comes from various sources such as off-chain DEXs (Binance, Coinbase, etc.), on-chain DEXs (Uniswap, Sushiswap, Balancer, etc.) and aggregators (CoinmarketCap, Coingecko, Kaiko). There are currently over 50 sources integrated, to which RedStone has contributed as the Oracle of data feed processing.

Data is aggregated on independent nodes managed by data providers using various techniques (TWAP, LWAP) and security measures such as outlier detection. The cleaned and processed data is signed by node operators who guarantee its quality. Data aggregation is one of the most complex forms in which information is stored and processed.

Data can be transmitted along the chain either by a special relay operating according to specified conditions (e.g. price deviation), or by a bot (e.g. performing liquidation), or even by end users interacting with the protocol or with smart contracts.

RedStone’s data packaging functionality.

1. Extracting data from the network. Relevant data must be extracted from a decentralized cache layer running on the streamr network and RedStone’s lightweight cache nodes.

2. Express packing. Data is packaged into a message according to the following structure: The packet is appended to the original transaction message, signed and sent to the network.

RedStone’s data unpacking functionality.

1. Unpacking the attached data packets extracted from the msg.data file, which RedStone oracle monitors. Checking if the signature was created by a trusted provider

2. Checking the timestamp, verifying that the information in it is not outdated, this is to avoid storing unnecessary data in storage and slowing down the blockchain performance

3. Calculating the number of unique signatures received, also needed for sorting and speed of the protocol.

4. Calculating the aggregate value (median by default), this is needed to perform efficient processing, or unpacking.

Conclusion.

RedStone is something that will help many blockchains and protocols in the future, as well as developers who will be building their own blockchain, or the same protocol. RedStone removes the very complex tasks that make it difficult for blockchain to work and run fast, RedStone is something that not only sorts and processes data, but something that has been helping many for a long time.

--

--