Skip to content

Commit 7cc7ef2

Browse files
authored
chore(pricefeed) New Morpho Guide (#786)
1 parent 6fa3e44 commit 7cc7ef2

File tree

1 file changed

+36
-29
lines changed

1 file changed

+36
-29
lines changed
Lines changed: 36 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,52 +1,59 @@
1-
import { Steps } from "nextra/components";
1+
import { Callout, Steps } from "nextra/components";
22

33
# How to use Pyth for Morpho Markets
44

5-
This guide will show how you can leverage Pyth real time price data to power Morpho markets.
5+
This guide will show how you can leverage Pyth real-time price data to power Morpho markets.
66

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.
7+
Pyth provides a wrapper which implements Morpho's `IOracle` interface called [`pyth-morpho-wrapper`](https://github.com/pyth-network/pyth-morpho-wrapper).
98

10-
There are three steps to use Pyth price feeds for Morpho markets:
9+
There are two steps to use Pyth price feeds for Morpho markets:
1110

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.
11+
1. Run the price pusher or scheduler.
12+
2. Deploy the [`MorphoPythOracle.sol`](https://github.com/pyth-network/pyth-morpho-wrapper/blob/main/src/morpho-pyth/MorphoPythOracle.sol) contract for the respective price feed pair.
1513

1614
<Steps>
1715

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-
3316
### Run the price pusher or scheduler
3417

3518
As a pull oracle, Pyth's users are typically responsible for updating the state of on-chain feeds.
3619
Please see [What is a Pull Oracle?](/price-feeds/pull-updates) to learn more about pull updates.
3720

38-
If you are using the `PythAggregatorV3` contract, you must push price updates to the contract at regular intervals.
3921
The Pyth Data Association sponsors regular on-chain updates for some price feeds.
4022
See [Sponsored Feeds](./sponsored-feeds.mdx) for the current list of feeds and their update parameters.
4123

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.
24+
If you don't find relevant price IDs in the [Sponsored Feeds](./sponsored-feeds.mdx) list, please contact the Pyth team [here](https://tally.so/r/nGz2jj) to run the scheduler/price pusher for the price feed you need.
4525

4626
### Deploy the Morpho oracle contract
4727

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.
28+
After running the price pusher or scheduler, you can deploy the Morpho oracle contract using the MorphoPythOracle.sol contract.
29+
30+
To deploy a MorphoPythOracle on an EVM chain, we highly recommend using the factory MorphoPythOracleFactory. Please refer to the factory addresses [here](https://github.com/pyth-network/pyth-morpho-wrapper?tab=readme-ov-file#factory-addresses).
31+
32+
If you don't see the factory address for your chain, you can deploy your own factory by using the [`scripts/MorphoPythOracleFactoryDeploy.s.sol`](https://github.com/pyth-network/pyth-morpho-wrapper/blob/main/scripts/MorphoPythOracleFactoryDeploy.s.sol) script or by creating an issue on [this repository](https://github.com/pyth-network/pyth-morpho-wrapper).
33+
If you are deploying, please make sure to update the README.md file with the new factory address.
34+
35+
To do so, run the [`MorphoPythOracleDeploy.s.sol`](https://github.com/pyth-network/pyth-morpho-wrapper/blob/main/scripts/MorphoPythOracleDeploy.s.sol) script with the following environment variables set:
36+
37+
- `PYTH_ADDRESS`: The Pyth contract address. This is the address of the Pyth contract deployed on the chain. You can find the address of the Pyth contract for each chain [here](./contract-addresses/evm.md).
38+
- `BASE_VAULT`: The ERC4626 token vault for the base asset.
39+
- `BASE_VAULT_CONVERSION_SAMPLE`: A sample amount for converting base vault units.
40+
- `BASE_FEED1`, `BASE_FEED2`: Pyth price feed ids for the base asset. You can find the price feed ids for each asset in our [price feeds directory](./price-feeds.mdx).
41+
- `BASE_TOKEN_DECIMALS`: Decimal precision of the base asset.
42+
- `QUOTE_VAULT`: The ERC4626 token vault for the quote asset.
43+
- `QUOTE_VAULT_CONVERSION_SAMPLE`: A sample amount for converting quote vault units.
44+
- `QUOTE_FEED1`, `QUOTE_FEED2`: Pyth price feed ids for the quote asset. You can find the price feed ids for each asset in our [price feeds directory](./price-feeds.mdx).
45+
- `QUOTE_TOKEN_DECIMALS`: Decimal precision of the quote asset.
46+
- `PRICE_FEED_MAX_AGE`: The maximum age of the price feed in seconds. Note: This adds an extra safety net to avoid using stale prices.
47+
- `SALT`: A unique identifier to create deterministic addresses for deployed oracles.
48+
49+
Check more information about these immutable parameters [here](https://docs.morpho.org/getting-started/resources/contracts/oracles/#immutables) and some assumptions to take into account [here](https://docs.morpho.org/getting-started/resources/contracts/oracles/#assumptions).
4950

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+
<Callout type="info">
52+
If there is an ERC4626-compliant vault for `BASE_VAULT` or `QUOTE_VAULT`, the
53+
`BASE_TOKEN_DECIMALS` or `QUOTE_TOKEN_DECIMALS` are still the decimals of the
54+
underlying asset of the vault, and not the decimals of the Vault itself. E.g:
55+
for a MetaMorpho WETH vault, as `BASE_VAULT`, the `BASE_TOKEN_DECIMALS` is 18
56+
as WETH has 18 decimals.
57+
</Callout>
5158

5259
</Steps>

0 commit comments

Comments
 (0)