How to use Pyth for Morpho Markets
This guide will show how you can leverage Pyth real time price data to power Morpho markets.
At the time of writing, Morpho supports an oracle interface (opens in a new tab) similar to ChainlinkAggregatorV3Interface (opens in a new tab). We need to wrap the Pyth oracle with this interface to use it with Morpho.
There are three steps to use Pyth price feeds for Morpho markets:
- Deploy the
PythAggregatorV3
(opens in a new tab) contract to provide a Chainlink-compatible feed interface. - Run the price pusher or scheduler.
- Deploy the Morpho oracle contract.
Deploy the PythAggregatorV3
contract
Pyth provides a wrapper called PythAggregatorV3
that implements the ChainlinkAggregatorV3Interface.
This wrapper allows you to use Pyth price feeds with Morpho markets.
Migrate from Chainlink to Pyth explains how to deploy the PythAggregatorV3
contract.
You can use the forge script (opens in a new tab) from the pyth-examples (opens in a new tab) directory to deploy the PythAggregatorV3
contract.
forge script script/PythAggregatorV3Deployment.s.sol --rpc-url $RPC_URL --broadcast --verify
This script will deploy the PythAggregatorV3
contract and verify it on the target chain.
You have to run the script for both BASE
and QUOTE
price feeds.
Run the price pusher or scheduler
As a pull oracle, Pyth's users are typically responsible for updating the state of on-chain feeds. Please see What is a Pull Oracle? to learn more about pull updates.
If you are using the PythAggregatorV3
contract, you must push price updates to the contract at regular intervals.
The Pyth Data Association sponsors regular on-chain updates for some price feeds.
See Sponsored Feeds for the current list of feeds and their update parameters.
If you don't find relevant price IDs in the Sponsored Feeds list, you can run the scheduler/price pusher for the price feed you need.
Please see Schedule Price Updates for more information on how to schedule price updates.
Deploy the Morpho oracle contract
After deploying the PythAggregatorV3
contract and scheduling price updates, you can deploy the Morpho oracle contract with the address of the PythAggregatorV3
contract deployed in the first step.
Please refer to the Morpho documentation (opens in a new tab) for more information on how to deploy the Morpho oracle contract.