diff --git a/pages/price-feeds/use-pyth-for-morpho.mdx b/pages/price-feeds/use-pyth-for-morpho.mdx index 7448abbe..369e6ca2 100644 --- a/pages/price-feeds/use-pyth-for-morpho.mdx +++ b/pages/price-feeds/use-pyth-for-morpho.mdx @@ -1,52 +1,59 @@ -import { Steps } from "nextra/components"; +import { Callout, 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. +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. +Pyth provides a wrapper which implements Morpho's `IOracle` interface called [`pyth-morpho-wrapper`](https://github.com/pyth-network/pyth-morpho-wrapper). -There are three steps to use Pyth price feeds for Morpho markets: +There are two 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. +1. Run the price pusher or scheduler. +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. -### 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. +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. ### 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. +After running the price pusher or scheduler, you can deploy the Morpho oracle contract using the MorphoPythOracle.sol contract. + +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). + +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). +If you are deploying, please make sure to update the README.md file with the new factory address. + +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: + +- `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). +- `BASE_VAULT`: The ERC4626 token vault for the base asset. +- `BASE_VAULT_CONVERSION_SAMPLE`: A sample amount for converting base vault units. +- `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). +- `BASE_TOKEN_DECIMALS`: Decimal precision of the base asset. +- `QUOTE_VAULT`: The ERC4626 token vault for the quote asset. +- `QUOTE_VAULT_CONVERSION_SAMPLE`: A sample amount for converting quote vault units. +- `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). +- `QUOTE_TOKEN_DECIMALS`: Decimal precision of the quote asset. +- `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. +- `SALT`: A unique identifier to create deterministic addresses for deployed oracles. + +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). -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. + + If there is an ERC4626-compliant vault for `BASE_VAULT` or `QUOTE_VAULT`, the + `BASE_TOKEN_DECIMALS` or `QUOTE_TOKEN_DECIMALS` are still the decimals of the + underlying asset of the vault, and not the decimals of the Vault itself. E.g: + for a MetaMorpho WETH vault, as `BASE_VAULT`, the `BASE_TOKEN_DECIMALS` is 18 + as WETH has 18 decimals. +