Skip to content

Commit c38a341

Browse files
authored
chore(pricefeeds) Add morpho Example (#48)
* chore(pricefeeds) Add morpho Example * merged into one example
1 parent f7b56ad commit c38a341

File tree

5 files changed

+54
-10
lines changed

5 files changed

+54
-10
lines changed
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
PRIVATE_KEY=
2+
RPC_URL=
3+
# https://www.pyth.network/developers/price-feed-ids
4+
PYTH_ADDRESS=
5+
# https://docs.pyth.network/price-feeds/price-feed-ids
6+
PRICE_FEED_ID=
7+
# To verify the contract on the respective chain's explorer
8+
ETHERSCAN_API_KEY=

price_feeds/evm/chainlink_migration/README.md

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ This example demonstrates how to deploy a Chainlink-compatible application to Py
44
The application `src/ChainlinkApp.sol` is designed to use Chainlink price feeds.
55
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.
66

7+
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).
8+
79
## Installation
810

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

3234
```bash copy
33-
forge script script/PythAggregatorV3Deployment.s.sol --rpc-url $RPC_URL --broadcast
35+
forge script script/PythAggregatorV3Deployment.s.sol --rpc-url $RPC_URL --broadcast --verify
36+
```
37+
38+
This command will deploy the `PythAggregatorV3` contract.
39+
40+
To test the Chainlink App, you can run the following command:
41+
42+
```bash copy
43+
forge script script/ChainlinkApp.s.sol --rpc-url $RPC_URL --broadcast --verify
3444
```
3545

3646
This command will print something like:
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
// SPDX-License-Identifier: Apache 2
2+
pragma solidity ^0.8.0;
3+
4+
import "forge-std/Script.sol";
5+
import {PythAggregatorV3} from "@pythnetwork/pyth-sdk-solidity/PythAggregatorV3.sol";
6+
import {ChainlinkApp} from "../src/ChainlinkApp.sol";
7+
8+
contract PythAggregatorV3Deployment is Script {
9+
function run() external {
10+
uint256 deployerPrivateKey = vm.envUint("PRIVATE_KEY");
11+
vm.startBroadcast(deployerPrivateKey);
12+
13+
// Get the address for your ecosystem from:
14+
// https://docs.pyth.network/price-feeds/contract-addresses/evm
15+
address pythPriceFeedsContract = vm.envAddress("PYTH_ADDRESS");
16+
// Get the price feed ids from:
17+
// https://docs.pyth.network/price-feeds/price-feed-ids
18+
bytes32 ethFeedId = 0xff61491a931112ddf1bd8147cd1b641375f79f5825126d665480874634fd0ace;
19+
bytes32 solFeedId = 0xef0d8b6fda2ceba41da15d4095d1da392a0d2f8ed0c6c7bc0f4cfac8c280b56d;
20+
21+
// Deploy an instance of PythAggregatorV3 for every feed.
22+
// You can deploy these contracts beforehand if you are integrating with
23+
PythAggregatorV3 ethAggregator = new PythAggregatorV3(pythPriceFeedsContract, ethFeedId);
24+
PythAggregatorV3 solAggregator = new PythAggregatorV3(pythPriceFeedsContract, solFeedId);
25+
26+
// Pass the address of the PythAggregatorV3 contract to your chainlink-compatible app.
27+
ChainlinkApp app = new ChainlinkApp(address(ethAggregator), address(solAggregator));
28+
29+
vm.stopBroadcast();
30+
}
31+
}

price_feeds/evm/chainlink_migration/script/PythAggregatorV3Deployment.s.sol

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@ pragma solidity ^0.8.0;
33

44
import "forge-std/Script.sol";
55
import {PythAggregatorV3} from "@pythnetwork/pyth-sdk-solidity/PythAggregatorV3.sol";
6-
import {ChainlinkApp} from "../src/ChainlinkApp.sol";
7-
6+
import "forge-std/console.sol";
87
contract PythAggregatorV3Deployment is Script {
98
function run() external {
109
uint256 deployerPrivateKey = vm.envUint("PRIVATE_KEY");
@@ -15,16 +14,13 @@ contract PythAggregatorV3Deployment is Script {
1514
address pythPriceFeedsContract = vm.envAddress("PYTH_ADDRESS");
1615
// Get the price feed ids from:
1716
// https://docs.pyth.network/price-feeds/price-feed-ids
18-
bytes32 ethFeedId = 0xff61491a931112ddf1bd8147cd1b641375f79f5825126d665480874634fd0ace;
19-
bytes32 solFeedId = 0xef0d8b6fda2ceba41da15d4095d1da392a0d2f8ed0c6c7bc0f4cfac8c280b56d;
17+
bytes32 priceFeedId = vm.envBytes32("PRICE_FEED_ID");
2018

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

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

2925
vm.stopBroadcast();
3026
}
Submodule forge-std deleted from 1eea5ba

0 commit comments

Comments
 (0)