# redstone.finance: Unlocking DeFi potential with cost-efficient oracles - 0xHack S02E03 p. 2

- Channel: [ETH Warsaw](https://streameth.org/eth-warsaw)
- Date: 2024-10-07
- Duration: 24:39
- Watch: https://streameth.org/watch/yt-woRDjYyaz-I
- YouTube: https://www.youtube.com/watch?v=woRDjYyaz-I

## Description

Welcome to Episode 3 of Season 2 0xHack Meetup!

👨‍🏫Alex Suvorov, Dev at redstone.finance:
Unlocking DeFi potential with cost-efficient oracles

🍻Our aim is to build a thriving Ethereum community. This event will be hosted online but we will make sure you have plenty of opportunities to network with other developers.

Make sure to follow us on Twitter! https://twitter.com/0xPoland

## Transcript

thank you again for having me here uh i'm a software developer at redstone and today i'd like to tell you about the redstone project and how we want to improve the blockchain oracles as you probably know from the first presentation a blockchain oracle is a third-party service that connects smart contracts uh blockchain with the outside world meaning providing data like real-world data to the blockchain smart contracts and the main use case for oracle's today is providing pricing data because this pricing data may be used in landing markets and decentralized insurance products in liquidity aggregators derivative derivatives protocols and even algorithmic stable coins like die and many many more projects there are a lot of ideas here um yeah so pricing data usually are provided for cryptocurrencies and for fiat currencies and sometimes for also stocks but there are also like many ideas what kind of new data can be provided on chain and the current most popular model how blockchain oracles work is that they post the pricing data to the blockchain regularly for example every 10 minutes which has some advantages like this approach is quite easy to understand and easy to manage however it becomes quite expensive and which leads to expensiveness of oracles in general and creates huge limitations for example in sense of that oracle's cover really small subset of tokens and some small subset of assets in general it also disables like easy ability to switch to the new blockchain but today a new blockchain appears really often uh and this approach needs to run a separate oracle instance for every new blockchain another problem which is not connected to this approach is that oracles are often centralized and prone to manipulation and all these problems resulted in uh more than one billion dollars hacked and stolen from d5 protocols that used blockchain oracles and we at redstone want to propose a solution which we already implemented in some stage and this solution has three main key points uh the first one that we don't want to use a blockchain like ethereum blockchain for storing the data because ethereum was not designed to store larger data sets instead we want to use cheaper storage that allows more data providers to come into the game the second point is adding and adding insurance c to divide protocols uh in sense that data providers will pay some stake that covers data reliability risks and the third key point is that we want to create an accountable system with a permanent track of each record and each data that was provided by data providers and how how do we build this in terms of cheap data storage we want to leverage the rv blockchain which actually was created to store large sets of data it also has many other advantages but even if we compare a cost of one gigabyte storage uh on our weave it cost only 35 while on ethereum it costs more than one and a half million dollars so the second the second thing is managing the provider obligations and the security insurance thing and we do this through introducing manifests which kind of describe what data data providers need to provide how often do they need to provide the data and we do this currently as a just a json file which has a design structure and the second thing here is that as i've said providers need to base some stake which can be taken from them in case of wrong behavior for example providing wrong data or incorrect or not providing data at all because of for example technical problems and this problem resolution or dispute resolution will be handled on using these marked with contracts smart with contracts are smart contracts built on top of the rv blockchain they have very interesting model of lazy evaluation and we at redstone see great potential in this in this protocol and we also contribute a lot here and we've already implemented our own sdk for smartweave contracts which uh which is much more efficient than the original sdk and because of caching and modular architecture but it's a topic for separate calls so i'll skip here and move to the third point which is i think one of the most important here is and the point is the efficient data excess and it's managed using um this on-demand fetching we call it something like on-demand fetching meaning that we don't store the data on ethereum blockchain or any other evm compatible blockchain but instead we provide the data on demand and we provide designed data so that they can be verified using the smart contract code which we've already prepared and and another advantage that comes here is the compatibility with any evm compatible blockchain like ethereum minus margin cello avalanche polygon dixty and others and let's go let's move to the architecture and i'll try to give you a general overview of how how the whole redstone return protocol works the core unit here is the redstone node it's something similar to blockchain node but at this moment it doesn't communicate with other nodes which will which will change in future probably and the main thing that redstone node does is fetching the data from multiple sources currently we fetch data from more than 60 sources including different exchange apis like taxes apis and simply unchain the access data we also use uh standard cryptocurrency exchange apis like binance kraken currency com and many others we also fetch data from yahoo finance website and european central banking api and we fetch all this data and the next thing that we do with this data is the data aggregation for example if we fetch data for bitcoin price from 50 sources we will take the median value it's similar to this bigger tao approach but we do this already here and we fetch the median value and then we sign each data point separately because each redstone node has its own private key and it's used to sign each data point and when the data is signed we post it to the so-called data cache layer and to the rv blockchain posting data to rv blockchain can take about 20 minutes so it's not usually it's not really useful in terms of real-time data that's why we also use this data cache layer and data cache layer is currently our http api and we also we are also working on integration with streamr which is a pops up decentralized network and if users want to use the redstone data they will fetch them from this data cache from this data cache and they will be able to use they are able to use the data using this http api in simple web integrations even not decentralized apps or in decentralized apps but without the smart contracts but they also can use the data using in smart contracts and i'll tell you much more about this because we've implemented a special tool called redstone flash storage and that allows to integrate redstone data in very straightforward way just a few words what happens uh on argue blockchain also because rv blockchain is used by redstone to uh to keep the data permanently and to manage disputes because we also thought about this dispute resolution protocol which is not implemented yet but it will work on the smart with contracts uh what is already implemented is providers registry which is a catalogue of providers and their manifests and their manifest history that can be managed by providers and can be displayed and viewed by any user that has access to our web application because the web application is actually connected to the rv smart contracts and show these this data that can be used and that should be provided by our current providers so let's move to this redstone flash storage thing because i think this is the most the most important part of our solution so when a dab developer wants to use redstone data in their smart contracts they need to install an npm module called redstone flash storage and wrap the ethereum contract instance the javascript contract instance using our special wrapper and this wrapper will update the contract logic in the way that when the contract will send a transaction or will run a view function we automatically will fetch the data from the redstone api first designed data and attach this data to the transaction so that on the on chain live on chain layer the smart contract will be able to verify the data and use it like use it in smart contracts code and today i'll show you this uh on the live coding session with later but the one thing that wars meant mentioning is that we put really much effort to the redstone flash storage optimization and we can say that currently reading the data using redstone flash storage which actually includes this signature verification is cheaper than reading the data from the chain link oracle which is the most popular oracle for blockchain nowadays and of course these costs doesn't include data right costs which are really really cheaper thanks to the affordable are with storage okay so let's go to the demo and if we go to the update redstone.finance we can see all the data points that we currently provide including crypto mostly crypto but also stock prices currencies prices pst avalanche tokens tokens from the avalanche ecosystem etf indexes and also commodities like grains energy metals and livestocks and we can do all of this thanks to this uh scalable model with on-demand fetching uh if we go to the bitcoin for example details we can see the price chart with the bitcoin prices which were provided by the redstone oracle on the right side you can see the sources the list of sources that were used for fetching the bitcoin price we've already we've also implemented this tool to compare the prices for different sources which can be useful for for example finding arbitrage opportunities and on the bottom you can see the list of rv transactions that were used to keep these are brief as i've said we use more than 60 sources now including taxes simple cryptocurrency exchanges and also like ecb european central banking api and others and this application as i've said has this interface to manage manifests by providers so if we click for example to the main redstone provider we can see a list of provided data with the details containing which sources are used and providers also have a web interface to interact with their manifests and with the manifest to see the manifests history uh okay so let's go to the most interesting part and let's try to use the redstone data in our smart contracts i've already prepared a small project with a single smart contract called example and a simple test file which uses hard hat testing framework so if i'm a blockchain developer and i want to use the redstone data i would go to the npmgs.com [Music] and try to find this redstone flash storage module let's type redstone we see the redstone flash storage on the third position let's go here and it starts with the simple explanation that i've already told about let's go to the installation section so the first thing we need to do is to install redstone flash storage i won't do this because i've already installed the redstone flash storage here so let's move to the getting started section it contains two main parts the first one is modifying our contracts and the second one updating the interface so let's start with modifying our contracts the first thing we need to do here is to extend our contract with the price of our contract implementation so let's simply copy this to our contract code okay and from this moment we can use the pricing data in the contract code using this get price from msg method and we need to pass a single argument here which is a bias 32 value created from the symbol string so in our contract we would like to use tesla price in usd and we can go to the prices in the redstone web app and check the tesla price is actually available and has the sla symbol so so we can actually access this price using this method let's do this let's replace the plug the price here replace the symbol and let's do the same thing here okay so now we need to update this function modifier uh great uh one thing that we need to um to check is that is that redstone has eight decimals in their values which means that we multiply the values by 100 millions it's a common approach that chain link also uses so so currently we can we've already prepared our smart contract to use the redstone data and the next thing that we need to do is to update our interface and first firstly we need to import this redstone flash storage rubber let's do this and we need to wrap our contract instance using this rubber builder um and we can select this price feed that we want to use let's do this as well which is rubber builder grab light [Music] where we pass this interior others gs contract instance and just think we want to do is selecting the price if we want to use we can use the resident stocks it also can be checked on the redstone application and we can also specify the asset in our case we will need to have the tesla asset developers added so it should be enough and now in every place where we want to access the redstone data in every function we need to actually replace this standard contract instance with the wrapped contract instance so let's do this okay and the last thing that we need to do is the provider authorization because our smart contract needs to know what providers is trusted and like what ethereum public address can sign the data the data that we can trust and this can be done using this authorized provider method that we've prepared and this method automatically analyzes the price feed that we provided here and actually uses the appropriate provider ethereum address okay so now we can call this test using your best yeah and we can see that the provider was authorized and actually that these uh methods from the contract were recalled correctly you can take a closer look on these functions in the first function we send a transaction and we update this private variable in the contract state called lastprice with the tesla price the second function doesn't interact with the state it simply fetches the residential price from the redstone oracle and if it's higher if it's greater than 1000 then it tells returns true and the last price simply returns the value from this contract state and in the task code we firstly we send this transaction update this price in the contract state in the second step we actually call this is overpriced function and in the third state we return the the value from the contract state yeah so that's how it works and let's get back to the presentation um just few words about traction in our project as i've said we already integrated data from more than 60 sources more than data for more than 1000 assets and already generated more than 1 billion signed data points also our redstone api which is a javascript wrapper for the redstone http api was downloaded 40 000 times since the launch and we already have a few fully working proof of concepts including commodo which is a commodities trading synthetics protocol um built on ethereum and also built on this seller blockchain and we also have a working demo a working project uh landing protocol on the avalanche blockchain here's our team we have cupa who is our founder and very experienced technical guy we have other three developers including me the author and better and the first part is also very experienced software developer and we also have margin who is our head of growth and of course uh as each blockchain team i think we are going to expand our team we are currently closing the seed investment round and we want to find 10 from 10 to 15 new talents so if you are a good developer or just a good person so reach out to us we'll be happy to talk and find opportunities for you and you can do this using our website we have a contact form here so simply go to the redstone.finance or you can write an email to hello at redstonefinance or you can join our discord at redstonefinancediscord and say hi and we'll be happy to chat with you thank you very much so i'll be happy to answer your questions if you have ones when prices are provided by the oracle we cannot afford that daily as other users uh okay that that really depends uh because the delay is very intentional for us so you can actually read data from there directly from the midianizer without the delay it's totally up to you both of them are provided and any there are some projects that are actually using direct medianizer values if that's that's required so i hope this answers the question uh yeah guys so uh if you have any other questions feel free to ask them in the chat we have both alex and pavel to answer them uh we're gonna give you uh some time to type that um it looks like we don't have any questions for today um so yeah uh guys thank you very much for uh joining the meetup today uh next meetup will be in december uh second tuesday of the month uh alex thank you for the presentation and the live coding session and pablo thank you for being here thanks it was a pleasure to host you it is a pleasure this the studio is nice uh yeah so we'll see you next month guys thank you guys thank you bye again bye bye
