Skip to content

chore(pricefeed) Add morpho guide #622

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Mar 4, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions pages/price-feeds/_meta.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
"fetch-price-updates": "Fetch Price Updates",
"schedule-price-updates": "Schedule Price Updates",
"migrate-an-app-to-pyth": "Migrate an App to Pyth",
"use-pyth-for-morpho": "Use Pyth for Morpho Markets",
"publish-data": "Publish Data",
"troubleshoot": "Troubleshoot Errors",

Expand Down
52 changes: 52 additions & 0 deletions pages/price-feeds/use-pyth-for-morpho.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import { Steps } from "nextra/components";

# 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](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).
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:

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.
2. Run the price pusher or scheduler.
3. Deploy the Morpho oracle contract.

<Steps>

### 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](./migrate-an-app-to-pyth/chainlink.md) explains how to deploy the `PythAggregatorV3` contract.

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.

```bash copy
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?](/price-feeds/pull-updates) 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](./sponsored-feeds.mdx) for the current list of feeds and their update parameters.

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.

Please see [Schedule Price Updates](./schedule-price-updates.mdx) 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](https://docs.morpho.org/morpho/tutorials/deploy-an-oracle/) for more information on how to deploy the Morpho oracle contract.

</Steps>