Skip to content

chore(pricefeeds) Add morpho Example #48

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 2 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
8 changes: 8 additions & 0 deletions price_feeds/evm/chainlink_migration/.example.env
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
PRIVATE_KEY=
RPC_URL=
# https://www.pyth.network/developers/price-feed-ids
PYTH_ADDRESS=
# https://docs.pyth.network/price-feeds/price-feed-ids
PRICE_FEED_ID=
# To verify the contract on the respective chain's explorer
ETHERSCAN_API_KEY=
12 changes: 11 additions & 1 deletion price_feeds/evm/chainlink_migration/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ This example demonstrates how to deploy a Chainlink-compatible application to Py
The application `src/ChainlinkApp.sol` is designed to use Chainlink price feeds.
The script `script/PythAggregatorV3Deployment.sol` deploys this application with the [`PythAggregatorV3`](https://github.com/pyth-network/pyth-crosschain/blob/main/target_chains/ethereum/sdk/solidity/PythAggregatorV3.sol) adapter contract, such that it uses Pyth price feeds.

This aggregator can be used to deploy Pyth Oracles for [Morpho vaults](https://docs.morpho.org/morpho/tutorials/deploy-an-oracle/#2-fill-all-attributes).

## Installation

This example uses [Foundry](https://book.getfoundry.sh/getting-started/installation), `npm` and `jq`.
Expand All @@ -30,7 +32,15 @@ export PYTH_ADDRESS=0x0708325268dF9F66270F1401206434524814508b
Then, deploy the contracts by running:

```bash copy
forge script script/PythAggregatorV3Deployment.s.sol --rpc-url $RPC_URL --broadcast
forge script script/PythAggregatorV3Deployment.s.sol --rpc-url $RPC_URL --broadcast --verify
```

This command will deploy the `PythAggregatorV3` contract.

To test the Chainlink App, you can run the following command:

```bash copy
forge script script/ChainlinkApp.s.sol --rpc-url $RPC_URL --broadcast --verify
```

This command will print something like:
Expand Down
31 changes: 31 additions & 0 deletions price_feeds/evm/chainlink_migration/script/ChainlinkApp.s.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// SPDX-License-Identifier: Apache 2
pragma solidity ^0.8.0;

import "forge-std/Script.sol";
import {PythAggregatorV3} from "@pythnetwork/pyth-sdk-solidity/PythAggregatorV3.sol";
import {ChainlinkApp} from "../src/ChainlinkApp.sol";

contract PythAggregatorV3Deployment is Script {
function run() external {
uint256 deployerPrivateKey = vm.envUint("PRIVATE_KEY");
vm.startBroadcast(deployerPrivateKey);

// Get the address for your ecosystem from:
// https://docs.pyth.network/price-feeds/contract-addresses/evm
address pythPriceFeedsContract = vm.envAddress("PYTH_ADDRESS");
// Get the price feed ids from:
// https://docs.pyth.network/price-feeds/price-feed-ids
bytes32 ethFeedId = 0xff61491a931112ddf1bd8147cd1b641375f79f5825126d665480874634fd0ace;
bytes32 solFeedId = 0xef0d8b6fda2ceba41da15d4095d1da392a0d2f8ed0c6c7bc0f4cfac8c280b56d;

// Deploy an instance of PythAggregatorV3 for every feed.
// You can deploy these contracts beforehand if you are integrating with
PythAggregatorV3 ethAggregator = new PythAggregatorV3(pythPriceFeedsContract, ethFeedId);
PythAggregatorV3 solAggregator = new PythAggregatorV3(pythPriceFeedsContract, solFeedId);

// Pass the address of the PythAggregatorV3 contract to your chainlink-compatible app.
ChainlinkApp app = new ChainlinkApp(address(ethAggregator), address(solAggregator));

vm.stopBroadcast();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@ pragma solidity ^0.8.0;

import "forge-std/Script.sol";
import {PythAggregatorV3} from "@pythnetwork/pyth-sdk-solidity/PythAggregatorV3.sol";
import {ChainlinkApp} from "../src/ChainlinkApp.sol";

import "forge-std/console.sol";
contract PythAggregatorV3Deployment is Script {
function run() external {
uint256 deployerPrivateKey = vm.envUint("PRIVATE_KEY");
Expand All @@ -15,16 +14,13 @@ contract PythAggregatorV3Deployment is Script {
address pythPriceFeedsContract = vm.envAddress("PYTH_ADDRESS");
// Get the price feed ids from:
// https://docs.pyth.network/price-feeds/price-feed-ids
bytes32 ethFeedId = 0xff61491a931112ddf1bd8147cd1b641375f79f5825126d665480874634fd0ace;
bytes32 solFeedId = 0xef0d8b6fda2ceba41da15d4095d1da392a0d2f8ed0c6c7bc0f4cfac8c280b56d;
bytes32 priceFeedId = vm.envBytes32("PRICE_FEED_ID");

// Deploy an instance of PythAggregatorV3 for every feed.
// You can deploy these contracts beforehand if you are integrating with
PythAggregatorV3 ethAggregator = new PythAggregatorV3(pythPriceFeedsContract, ethFeedId);
PythAggregatorV3 solAggregator = new PythAggregatorV3(pythPriceFeedsContract, solFeedId);
PythAggregatorV3 aggregator = new PythAggregatorV3(pythPriceFeedsContract, priceFeedId);

// Pass the address of the PythAggregatorV3 contract to your chainlink-compatible app.
ChainlinkApp app = new ChainlinkApp(address(ethAggregator), address(solAggregator));
console.log("PythAggregatorV3 deployed at", address(aggregator));

vm.stopBroadcast();
}
Expand Down
1 change: 0 additions & 1 deletion price_feeds/evm/pyth_sample/lib/forge-std
Submodule forge-std deleted from 1eea5b
Loading