Using oracles
Last updated
Last updated
Without Shadow, augmenting blockchain data with point-in-time accurate prices requires complex data pipelines and integrations with third-party price feed APIs. Shadow drastically simplifies this by allowing you to leverage existing oracle contracts, in <100 lines of code.
In this example, we’ll be updating the 1inch Aggregator contract to emit a shadow event called OrderFilledDetails
that contains additional metadata of a trade, including the point-in-time USD price of the trade. We’ll be fetching the point-in-time prices via a Chainlink oracle.
Open the example on the Shadow Playground: This will open the playground editor at the 1inch Aggregation Router v5 contract on Ethereum at (as of Jul 2024).
At L4302, we’ve defined the OrderFilledDetails
event and a helper OrderDetails
struct:
At L4567, we call a new function called getOrderAmountUsd
and emit the OrderFilledDetails
event:
At the bottom of the contract at L4667, we define the getOrderAmountUsd
function and two other helper functions:
Notice that we also pasted Chainlink’s AggregatorV3Interface
into this file. This allows us to call the Chainlink oracle contract via its interface. You’ll have to do this any time you introduce shadow changes that interact with a contract interface that it doesn’t currently interact with.
You should see your custom OrderFilledDetails
event in the output!
If you want to apply these changes on your shadow fork, click the button on the top right corner that says “Apply to your shadow fork”.
This will take you to the editor for your shadow fork, where you can deploy the changes by hitting “Compile > Deploy”
Click “Compile” > “Test Run” in the top right corner, and paste in this transaction hash (or simulate any other order filled transaction).