Use onchain price oracles to get accurate point-in-time USD prices of tokens, without needing to use any offchain price APIs.
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.
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.