Developer Hub

Use Pyth for Morpho Markets

Learn how to use Pyth for Morpho Markets

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

Pyth provides a wrapper which implements Morpho's IOracle interface called pyth-morpho-wrapper.

There are two steps to use Pyth price feeds for Morpho markets:

  1. Schedule Price Updates.
  2. Deploy the MorphoPythOracle.sol contract for the respective price feed pair.

Schedule Price Updates

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.

Consult Schedule Price Updates guide for more information.

The Pyth Data Association sponsors regular on-chain updates for some price feeds. See Push Feeds for the current list of feeds and their update parameters.

If you don't find relevant price IDs in the Push Feeds list, please contact the Pyth team here to run the Price Pusher for the price feed you need.

Deploy the Morpho oracle contract

After running the Price Pusher, 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.

If you don't see the factory address for your chain, you can deploy your own factory by using the scripts/MorphoPythOracleFactoryDeploy.s.sol script or by creating an issue on this repository. 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 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.
  • 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.
  • 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.
  • 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 and some assumptions to take into account here.

ERC4626 Decimals

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.