New Ethereum talks, every Monday. The week's conference uploads by event, in your inbox.

Loading player…

Most Innovative use of Pyth pull oracle (Price Feeds) - Superhack 2024

ETHGlobalWed, Oct 9, 2024, 12:00 AM

Join us for a workshop with Ali Behjati titled, "Most Innovative use of Pyth pull oracle (Price Feeds)." This workshop is part of Superhack 2024, an async hackathon that takes place from Aug 02 – Aug 16, 2024. ----------------- Follow us: https://x.com/ethglobal Check us out: https://ethglobal.com/ Email us at: hello@ethglobal.com

Transcript

[Music] I'm Ali and I'm a core contributor to the p network the way P works is that there are multiple dozens of Publishers that publish very high quality price with low latency to the pece network and then later these prices gets aggregated and is available to be used on other chains I have an example to send $5,000 worth of ethereum to a friend and I want to show you how we can write a contract that communicates with the piece contract to both update the price on demand and use that price to send some money to a friend and this is a UI that communicates with the contract that I have written so let's begin this is a piece example contract and as you can see it's very simple it has a method called send to friend which gets the address that you want to pay to and also the amount in USD that you want to pay to your friend it also gets a Bice array of update data which is the verified price that Wormhole Guardians have attested to that you can get and then pass to your contract and then what you need to do is that you call the piece contract to actually update upate the price feeds and what it does is that it takes the update it parses it and also it verifies that it's coming from the right Source there's also an update fee Associated to each price update that protocols and users need to pay that is to keep protocol sustainable in the long run currently the value is set to one way so the protocols can always do the technical work and later it won't be any breaking change so you update the price and then what you do is that you can simply query the price by calling piece. getet price and you pass down the price ID that you are looking for the price IDs of price fees are available in our website and you can look the price feeds and their corresponding IDs in both main net and test net in different networks that we are live on so for example here I might want to use the ethereum price feed which is this ID so here I call the get price method and get the ethereum current price and it is wrapped in a price structure with which contains a price and a confidence confidence is a unique thing that P provides to Consumers and protocols which tells them that we as P believe that this price is around the given price with the confidence interval that is given to you so for example if each price is 1,000 and the confidence is 10 it means that the Oracle has concluded that the price of it is something between $990 and $1,010 this is very useful because the price value is never 100% accurate because you can not tell simply how much something is valued and it's different per different exchanges this is why we have confidence here and we encourage protocols and users to use this although we are not using it in this example there is also a publish Time Field in the price which is very important to be fresh and if you for example use an old price with an old publish time then you are screwed because then someone can front on you or manipulate you with an older price so you should always check the price to be recent enough based on what you need and here in the get price method we do that check for you with a default value that we have assigned to each of the networks that we are live on for example on ethereum that is 2 minutes but on binance chain that is only one minute we can also use get price no older than and and pass down your your desired recency time that is acceptable okay so simply like that you get the current price and then with doing some simple mathematical operations you can convert that price to know how much the amount of USD is in ethereum or in V with the price and the exponent that is given to you and then you can basically transfer that way amount to your friend and also transfer back the remaining amounts the contract is as simple as that and you should just update the price first and then use that price and then we want to communicate with the contract to write down for example the front end of our contract where we can get the update data from so we have created a price service which is like an RPC for any other network that you can communicate with to get the latest available verified price feed or the update data Associated to that and we also created some JavaScript sdks that you can use to Simply pass down the the end point of the price feed and use the utilities that we have provided in the SDK to be able to communicate with that in an easy way so here you see that we have evm price service connection which is a class at home only takes the endpoint RPC of the price service and when you have this then you can for example subscribe to the price feeds just to show the live prices on your UI because they are no longer updated on contract so you should use the live prices that are available to be served on target chains and that's simply using this subscribe price fees method and you pass down here for example the ethereum price price ID and then you just change the UI when a new price update comes so as you can see here the price is changing as we go it's also showing how $5,000 is worth in ethereum just for the sake of our example and then when you want to actually communicate with your contract you need to update data and you can simply get the update data by by calling the get price feeds update data and just passing down your price ID and then later when you are calling your contract you simply pass down the update data that you got from our endpoint to your contract and then you can simply call your method with that data so it is as simple as that there are other Utilities in the SDK you can for example get different price IDs that are available also you can query the latest price feed and do other first stuff it's as easy as that and let me just show you how you can do it in UI so here in the UI there is a connect button I press that to connect to my wallet you see that it's showing my address also I have hardcoded my friend address and I just press this send method and then as this is a fork I just say that yeah I'm okay to proceed and yeah confirm the transaction and then yeah it's it's done so simply the way that I showed you with just only a few lines of code you can use our utilities and sdks to use the prices update the prices and do whatever you want with the prices all of the codes that are shown in this video are available in our GitHub then we are looking forward to see you on board [Music]

Automatic transcript — names and jargon may be misspelled.