|
| 1 | +import { Steps } from "nextra/components"; |
| 2 | + |
| 3 | +# How to use Pyth for Morpho Markets |
| 4 | + |
| 5 | +This guide will show how you can leverage Pyth real time price data to power Morpho markets. |
| 6 | + |
| 7 | +At the time of writing, Morpho supports an [oracle interface](https://github.com/morpho-org/morpho-blue-oracles/tree/main/src) similar to [ChainlinkAggregatorV3Interface](https://github.com/smartcontractkit/chainlink/blob/develop/contracts/src/v0.8/shared/interfaces/AggregatorV3Interface.sol). |
| 8 | +We need to wrap the Pyth oracle with this interface to use it with Morpho. |
| 9 | + |
| 10 | +There are three steps to use Pyth price feeds for Morpho markets: |
| 11 | + |
| 12 | +1. Deploy the [`PythAggregatorV3`](https://github.com/pyth-network/pyth-crosschain/blob/main/target_chains/ethereum/sdk/solidity/PythAggregatorV3.sol) contract to provide a Chainlink-compatible feed interface. |
| 13 | +2. Run the price pusher or scheduler. |
| 14 | +3. Deploy the Morpho oracle contract. |
| 15 | + |
| 16 | +<Steps> |
| 17 | + |
| 18 | +### Deploy the `PythAggregatorV3` contract |
| 19 | + |
| 20 | +Pyth provides a wrapper called `PythAggregatorV3` that implements the ChainlinkAggregatorV3Interface. |
| 21 | +This wrapper allows you to use Pyth price feeds with Morpho markets. |
| 22 | +[Migrate from Chainlink to Pyth](./migrate-an-app-to-pyth/chainlink.md) explains how to deploy the `PythAggregatorV3` contract. |
| 23 | + |
| 24 | +You can use the forge [script](https://github.com/pyth-network/pyth-examples/blob/main/price_feeds/evm/chainlink_migration/script/PythAggregatorV3Deployment.s.sol) from the [pyth-examples](https://github.com/pyth-network/pyth-examples/tree/main/price_feeds/evm/chainlink_migration) directory to deploy the `PythAggregatorV3` contract. |
| 25 | + |
| 26 | +```bash copy |
| 27 | +forge script script/PythAggregatorV3Deployment.s.sol --rpc-url $RPC_URL --broadcast --verify |
| 28 | +``` |
| 29 | + |
| 30 | +This script will deploy the `PythAggregatorV3` contract and verify it on the target chain. |
| 31 | +You have to run the script for both `BASE` and `QUOTE` price feeds. |
| 32 | + |
| 33 | +### Run the price pusher or scheduler |
| 34 | + |
| 35 | +As a pull oracle, Pyth's users are typically responsible for updating the state of on-chain feeds. |
| 36 | +Please see [What is a Pull Oracle?](/price-feeds/pull-updates) to learn more about pull updates. |
| 37 | + |
| 38 | +If you are using the `PythAggregatorV3` contract, you must push price updates to the contract at regular intervals. |
| 39 | +The Pyth Data Association sponsors regular on-chain updates for some price feeds. |
| 40 | +See [Sponsored Feeds](./sponsored-feeds.mdx) for the current list of feeds and their update parameters. |
| 41 | + |
| 42 | +If you don't find relevant price IDs in the [Sponsored Feeds](./sponsored-feeds.mdx) list, you can run the scheduler/price pusher for the price feed you need. |
| 43 | + |
| 44 | +Please see [Schedule Price Updates](./schedule-price-updates.mdx) for more information on how to schedule price updates. |
| 45 | + |
| 46 | +### Deploy the Morpho oracle contract |
| 47 | + |
| 48 | +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. |
| 49 | + |
| 50 | +Please refer to the [Morpho documentation](https://docs.morpho.org/morpho/tutorials/deploy-an-oracle/) for more information on how to deploy the Morpho oracle contract. |
| 51 | + |
| 52 | +</Steps> |
0 commit comments