Flare’s Pricing and Data Oracles for Multi Chain Interaction - ETHGlobal Brussels 2024
ETHGlobal·Wed, Oct 9, 2024, 12:00 AM
Join Filip Koprivec from Flare, for a workshop titled, “Flare’s Pricing and Data Oracles for Multi Chain Interaction.” The workshop will showcase the main advantages of building on Flare: State Connector for trustless attestation of events and transactions on EVM chains Relay for cross-chain communication between any two EVM chains Pricing Oracle on Flare, which provides on-chain access to extensive price streams without centralized 3rd parties On-chain availability of random numbers for any protocol. This workshop took place during ETHGlobal Brussels, a 3-day hackathon held in Brussels, Belgium from July 12 to 14, 2024. ETHGlobal Brussels brought together the most skilled web3 developers, designers and product builders from all around the globe for a weekend-long adventure to advance the Ethereum ecosystem! ---------------- Follow us: x.com/ethglobal Website: https://ethglobal.com Email us at: hello@ethglobal.com
Transcript
[Music] okay so hi um welcome to the Flare's Workshop so what is flare flare is a blockchain for data what does that means well it means that you got your ordinary blockchain that can do all these important necessary security related stuff but what you also get is an additional data sources directly on chain so it's not your everyday multi seek pushing data on chain it's a properly secured data when you know that the whole validator set is making sure that data you get on chain is secure and exactly what you need so what you can do with Flare well you built on an evm chain so evm chain that has all the nice things you're used to building with all the toolings and you can do it with data so we offer two different prices the first one is 7K price for the best utilization of friend flares and shrin pricing oracles together with layer zero V2 or with any other cross chain connectivity that we also offer so use the price use a price you can get every second on every block and do something with it not just on one chain but do it cross chain use liquidity somewhere else use the tokens deployed somewhere else buy something somewhere else use information for Bitcoin and do this and secondly we also have a second track which is the most Innovative application using flar data protocols so apart from just pricing oracles we also offer additional data connectivity Oracle when you can observe what's happening on other chains without any additional interaction from other chains so you can observe non-smart chains you can observe Bitcoin payment you can observe xrp Ledger payments you can observe what's happening on Dogecoin and in that case you can also apply for that track okay so what's specific with Flare we offer native data acquisition protocols so those are enshrined directly into the chain what does that mean well we have three different things you can work on this time so the first one is the fso this is flare time Ser Oracle so for probabilistic data we offer price updates every block so that means that we have 19 different price fits currently only crypto when you can get a price update every block and those price updates are directly published on chain you don't have to query them you don't have to request them you don't have to pay anything for them you just read them from a contract and we'll see how easy it is to do that in the following few minutes in the workshop and all this is operated by a stake network of validators so you know that the prices are always correct and can be manipulated by people that want to gamble your system when you have a Perpetual Dex or when you have some future set up and secondly we have flare State connector and data connector which allows you to connect to additional data sources what does that mean well that means that you can have a deterministic of chain attestations you can attest to data being presented on another blockchain you can attest that Bitcoin transaction has happened more specifically you can attest that in a specific time range Bitcoin transaction hasn't happened so you can know that the payment that was supposed to be made for something wasn't made you can know that if somebody's building a swap when you have one swap on bitcoin side and one swap on sepolia or etherium side you know that one person did not complete their leg of transaction and again this is enshrined directly into the protocol level so you don't have to trust a multi built on top of this you know that this is secured by the same validators that are building the blocks and thirdly uh We've recently integrated with layer zero so what that means that means that you get the whole mesh of all other evm compatible networks directly on flare chain and combining the first two oracles so giving you immediate pricing data and giving you data about the state of other chains about what's happening in the rest of the ecosystem you can easily build a bunch of devs that are integrating cross chain moving data around getting to the best liquidity positions getting to the best information sources executing this on a smart chain and then going whenever you want all this properly secured directly on a validator level okay so just a few things important for the hackaton so flare is an evm layer one Oracle Network what the zvm layer one means well you get all the nice things you're used to when building on ethereum or on polygon or any other chains so we are proof of stake you get the security block time is very quick so you know that you're get a block in the next second or so so you don't have to wait for a while you don't have to wait for the transaction to happen you can do things immediately and combining this with fast pricing updates you know that you can execute quick trades and you can be there on time so you're not waiting neither for an old price neither for stale um State the transaction fees are low due to the efficiency on the network level and you can use pretty much any tooling you want so we offered pre-prepare hard head and Foundry tool sets so you can start with a starter pack that has all all the rpcs already configured all the forets that you would need all the necessary block Scout tools so you can easily interact with the whole ecosystem without having to change anything if you know solidity and if you know some typescript or some Rust it's easy to start you don't have to change anything and as an evm chain you get pretty much all the goodies that can exist on such chains so erc20 tokens natively supported web three authentication directly available so we have also from the defi perspective multiple nft marketplaces tooling periphery support all the sdks you would need and stuff like this so it's easy to start and again a large defi account abstraction support stable coins you know it this is flat so you have oracles you have data directly on chain it's quick and you don't have to change your to and now let's take a look how exactly these things work okay so if you want to build on this the first bet would be you come to our boot or you scan this QR code we have a starter pack which we're going to start building on from now and we have a whole set of developer documentation specifically tailored to start building so um okay let's wait so that people think okay so we'll be starting from this starter P why start pack useful it will be starting from the starter pack why is it useful well it's a simple hardhead project with all the necessary stuff already configured so if you if you've seen the hard head system at some point we have all the necessary contract set up all the private Keys you can just import from the um environment file and all the at scans are already so we don't have to configure anything um if you start running into any problems hitting the RPC a bit too hard just visit us at the boot we'll give you API key so you can just knock yourself out and do whatever you want with the rpcs okay so we start with the starter pack that importantly already has the flares periphery contracts directly in so all the interfaces you're going to see everything you need it's already in it's type safe it's made in solidity so you can easily call them you don't have to hard code anything so you you can just easily start okay and let's take a look at the at the first one so it's thef flare. Network so this is the entry point for documentation and the first one would be the FTS SO2 so that's the that's the most important thing the pricing Oracle getting prices quickly and efficiently on chain and let's just and what you want to see is the systems Explorer so for each fso so we currently offer 19 different prices and for each fdso it's easy to see for each day data source it's easy to see what the prices are so the prices are updated on a block level we offer a bunch of nice visualizations when you can check how this is getting updated so okay here the um the shape is a bit jacked because of the the issues with the with the amount of pixels but in this way you have a fast update every block and you know that this is getting correctly processed by the data okay so these are fast updates and each of these feed is associated with a specific feed ID although this thing here might look a bit scary it's basically just a hex and code at BTC USB so that means that we can easily extend feeds to pretty much any feed you want so you can combine feeds you can add new feeds you can add new feeds that that are not necessarily dollar denominated but can be stable Co denominated and we've seen in the past that stable coins might depag so you want to know what exactly is the feed you're looking at okay so that's the that's the data we'll be observing and let's just take a look at how this data look direct looks directly from the contract okay so this is a simple contract interacting with the FTS so V2 is it big enough can you see it at the back okay so there's a library which I've copied in here just so we can see it in a real world use case you would on a hackaton you would just import it from the registry so we don't want to deal with all the necessary bureaucracy so what do we do if you want to get a feed ID you just Supply a name and we properly encode it to bites so you get this Feit ID that we've seen in the beginning and getting the fits well you just have to query the correct contract and how do you get the correct contract well on chain we always maintain a set a simple contract we de an entry point to the whole Flare's ecosystem so what you do you first get to the um flare contract registry that is always at a fixed address on all the networks where flare um operates so flare is composed of test net and of a main net and we try to keep the addresses for both test net and Main net the same so that it's easily to Port data between those two okay you get the flare contract registry you get the fast updat contract by the address and then you can work on and what do you do well since the data is available off chain you don't have have to do any pre-calculations you don't have to request it you don't have to pay for it the only thing you need to do is you just say FTS so V2 fetch current feeds that's it and you provide some feed indices so each feed is associated with a specific index so indices are hardcoded here flare has zero index Bitcoin has index two and ethereum has index 9 but you don't want to query the feeds by indices you want to query them by name so what you how would you do that well we also provide a configuration contract in the middle that just act as a simple mapping between feed names that you would use encoded and feed IDs um in the on the fast update contract so how would you do this here is another piece of solidity code when you can get feed values by name and what do you do well you just say Okay I want to get this I want to get some strings so I'm just going to supply you xrp Bitcoin Dogecoin whatever and I want to get the pricing for each of those feds so what do I really get I get the values so I get the price of this specific asset at this specific point I get the decimals because the feeds can vary by quite a lot we provide the feed value denominated in some decimals so for Bitcoin you get a bit less decimals for moreti loens you get a bit more decimals and you get a time stamp this is the latest update for this specific feed why do you need this because sometimes you might get a few feed updates in the the same block or you might get two blocks in the same time stamp so it's not only important to know that you're in the correct block it's important to also know that the feed was correctly updated and since all the feeds are updated in batches every block you also get a time stamp just to have some sort of a sanity check to know what it's doing okay and then there's just just a matter of a simple conversion so we use the pre-pro library to convert the feed so we take a look at the configuration file get the feed ID and use it here and after that we just fetch all of them and return them and how do you use this onchain or offchain well simply you just create a um you just create a simple hardhead script to deploy it let's just check it right now we'll deploy this on cant to and also directly validate the smart contract so we can immediately interact with it it's deployed here and in a second the contract okay the contract's verified let's open it okay so we got the contract and it's easy to then just get into the correct set to get to the correct method and say okay I want to know bitcoin price and here it is so might not be very visible and there it is so Bitcoin up to two decimals right now so that's the important stuff so you get it immediately as a view method no checking in it okay those are the fast updates important if you want to do something defi related know what the price is arbitrage an existing decks know that if you have a Perpetual Futures you want to know that the price is correct if you see somebody providing liquidity you can use the onchain Oracle to know if the liquidity is mercenary or not is it doing something good is the price being moved too much and you want to offset this this is the Baseline price Oracle you canuse okay that's the first thing so connecting to external world and getting the pricing data and the second thing you can do on flare is get data from external data sources so you can get data from external chains and connect them let me just open the this one here and to do this you we use flare data connector so what you do you request an attestation about something that's happening somewhere else um so and the easiest thing to check is just go to sepolia take an old block take a random transaction uh take a old block pick a transaction let's say this one and say okay so we have a transaction it's made quite a lot of events and it was it did some contract go why is that useful when when you're observing external networks you want to not just know that something has happened you want to be pretty sure that you go deep and you can extract a lot of information so what state connector does it allow data connector does it allows you to see into this specific transaction and prove all these data on flare so this is just a nice Swagger ux we also provide the same tooling as with the fso to just do this directly from the JavaScript so what I'm saying here is okay go to evm chain go to sepolia and give me information about this transaction so I get I get some additional response which is again a bit small but I get a bunch of information about this transaction that can be then proven on chain and what do I get I get the block number the Tim stamp The Source address and I also get all the events that were emitted inside so do I want to know if a specific Unis swap swap has been made yep I can see this do I want to know even an year C20 token was transferred yep I can see this do I want to know if some liquidation was triggered because of some specific condition yep I can see this I can take this information and I can push it to flare and then on flare I have this information information from other chains information provided by layer zero and then I can execute pretty much anything okay so that's on evm but apart from the smart chains when you can easily do this using existing Bridges we can also do this for Bitcoin Bitcoin Dogecoin and xrp Ledger and we can do this in the same way so we take a transaction and we can check that this specific transaction has had some effect has created something has transferred value and had specific transaction um identifier identified by the oper return and op code so what does that mean that means that you can have a simple payment method when you can say Okay pay me on bitcoin and state connector can safely transfer this directly to flare and then it's again up to you use this information do something with it and that's the connectivity part so you have a smart chain with evm support you have realtime pricing with a lot of assets you have real time data about what's happening on other chains and as a bonus you have layer zero integrating flare with all the other evm chains that are compatible so what that gives you that gives you secure data that gives you connectivity to other chains and it gives you the ability to use this hackaton to build something amazing with price data sources combine this with other chains and get some bounties not just from us but also from layer zero and also from pretty much any other network that is participating so that's it that's flare so getting your data in a secure manner knowing that it's there and acting upon it directly and immediately okay um that's it any questions if you want to find us we're on the boot on the far side um come to sncs [Music]
Automatic transcript — names and jargon may be misspelled.