From 720b0a74fcd8c29332a590c84d0c4928edf2d48c Mon Sep 17 00:00:00 2001 From: Aditya Arora Date: Tue, 25 Feb 2025 18:43:30 -0700 Subject: [PATCH 1/2] chore(pricefeeds) Add morpho Example --- .../evm/morpho-pyth-oracle/.example.env | 7 ++ price_feeds/evm/morpho-pyth-oracle/.gitignore | 19 ++++++ price_feeds/evm/morpho-pyth-oracle/README.md | 66 +++++++++++++++++++ .../evm/morpho-pyth-oracle/foundry.toml | 6 ++ .../evm/morpho-pyth-oracle/package-lock.json | 22 +++++++ .../evm/morpho-pyth-oracle/package.json | 19 ++++++ .../evm/morpho-pyth-oracle/remappings.txt | 1 + .../script/PythAggregatorV3Deployment.s.sol | 27 ++++++++ 8 files changed, 167 insertions(+) create mode 100644 price_feeds/evm/morpho-pyth-oracle/.example.env create mode 100644 price_feeds/evm/morpho-pyth-oracle/.gitignore create mode 100644 price_feeds/evm/morpho-pyth-oracle/README.md create mode 100644 price_feeds/evm/morpho-pyth-oracle/foundry.toml create mode 100644 price_feeds/evm/morpho-pyth-oracle/package-lock.json create mode 100644 price_feeds/evm/morpho-pyth-oracle/package.json create mode 100644 price_feeds/evm/morpho-pyth-oracle/remappings.txt create mode 100644 price_feeds/evm/morpho-pyth-oracle/script/PythAggregatorV3Deployment.s.sol diff --git a/price_feeds/evm/morpho-pyth-oracle/.example.env b/price_feeds/evm/morpho-pyth-oracle/.example.env new file mode 100644 index 0000000..0fde874 --- /dev/null +++ b/price_feeds/evm/morpho-pyth-oracle/.example.env @@ -0,0 +1,7 @@ +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= +ETHERSCAN_API_KEY= \ No newline at end of file diff --git a/price_feeds/evm/morpho-pyth-oracle/.gitignore b/price_feeds/evm/morpho-pyth-oracle/.gitignore new file mode 100644 index 0000000..1f22e96 --- /dev/null +++ b/price_feeds/evm/morpho-pyth-oracle/.gitignore @@ -0,0 +1,19 @@ +# Compiler files +cache/ +out/ + +# Ignores development broadcast logs +broadcast/ + +# Docs +docs/ + +# Dotenv file +.env + +lib/* +!lib/README.md + +*~ + +node_modules \ No newline at end of file diff --git a/price_feeds/evm/morpho-pyth-oracle/README.md b/price_feeds/evm/morpho-pyth-oracle/README.md new file mode 100644 index 0000000..9265b45 --- /dev/null +++ b/price_feeds/evm/morpho-pyth-oracle/README.md @@ -0,0 +1,66 @@ +## Foundry + +**Foundry is a blazing fast, portable and modular toolkit for Ethereum application development written in Rust.** + +Foundry consists of: + +- **Forge**: Ethereum testing framework (like Truffle, Hardhat and DappTools). +- **Cast**: Swiss army knife for interacting with EVM smart contracts, sending transactions and getting chain data. +- **Anvil**: Local Ethereum node, akin to Ganache, Hardhat Network. +- **Chisel**: Fast, utilitarian, and verbose solidity REPL. + +## Documentation + +https://book.getfoundry.sh/ + +## Usage + +### Build + +```shell +$ forge build +``` + +### Test + +```shell +$ forge test +``` + +### Format + +```shell +$ forge fmt +``` + +### Gas Snapshots + +```shell +$ forge snapshot +``` + +### Anvil + +```shell +$ anvil +``` + +### Deploy + +```shell +$ forge script script/Counter.s.sol:CounterScript --rpc-url --private-key +``` + +### Cast + +```shell +$ cast +``` + +### Help + +```shell +$ forge --help +$ anvil --help +$ cast --help +``` diff --git a/price_feeds/evm/morpho-pyth-oracle/foundry.toml b/price_feeds/evm/morpho-pyth-oracle/foundry.toml new file mode 100644 index 0000000..25b918f --- /dev/null +++ b/price_feeds/evm/morpho-pyth-oracle/foundry.toml @@ -0,0 +1,6 @@ +[profile.default] +src = "src" +out = "out" +libs = ["lib"] + +# See more config options https://github.com/foundry-rs/foundry/blob/master/crates/config/README.md#all-options diff --git a/price_feeds/evm/morpho-pyth-oracle/package-lock.json b/price_feeds/evm/morpho-pyth-oracle/package-lock.json new file mode 100644 index 0000000..9c1cc69 --- /dev/null +++ b/price_feeds/evm/morpho-pyth-oracle/package-lock.json @@ -0,0 +1,22 @@ +{ + "name": "morpho-pyth-oracle", + "version": "1.0.0", + "lockfileVersion": 3, + "requires": true, + "packages": { + "": { + "name": "morpho-pyth-oracle", + "version": "1.0.0", + "license": "ISC", + "dependencies": { + "@pythnetwork/pyth-sdk-solidity": "^4.0.0" + } + }, + "node_modules/@pythnetwork/pyth-sdk-solidity": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/@pythnetwork/pyth-sdk-solidity/-/pyth-sdk-solidity-4.0.0.tgz", + "integrity": "sha512-Cy2MvSN1Oh5YpIYmZd2In6/gfXbGjnpazmXKioTuq07Drp4Rl2XHcvtqHdgilplCl32IG4pU+XoRafpexID08A==", + "license": "Apache-2.0" + } + } +} diff --git a/price_feeds/evm/morpho-pyth-oracle/package.json b/price_feeds/evm/morpho-pyth-oracle/package.json new file mode 100644 index 0000000..24544f7 --- /dev/null +++ b/price_feeds/evm/morpho-pyth-oracle/package.json @@ -0,0 +1,19 @@ +{ + "name": "morpho-pyth-oracle", + "version": "1.0.0", + "description": "**Foundry is a blazing fast, portable and modular toolkit for Ethereum application development written in Rust.**", + "main": "index.js", + "directories": { + "lib": "lib", + "test": "test" + }, + "scripts": { + "test": "echo \"Error: no test specified\" && exit 1" + }, + "keywords": [], + "author": "", + "license": "ISC", + "dependencies": { + "@pythnetwork/pyth-sdk-solidity": "^4.0.0" + } +} diff --git a/price_feeds/evm/morpho-pyth-oracle/remappings.txt b/price_feeds/evm/morpho-pyth-oracle/remappings.txt new file mode 100644 index 0000000..fae9ede --- /dev/null +++ b/price_feeds/evm/morpho-pyth-oracle/remappings.txt @@ -0,0 +1 @@ +@pythnetwork/pyth-sdk-solidity=node_modules/@pythnetwork/pyth-sdk-solidity diff --git a/price_feeds/evm/morpho-pyth-oracle/script/PythAggregatorV3Deployment.s.sol b/price_feeds/evm/morpho-pyth-oracle/script/PythAggregatorV3Deployment.s.sol new file mode 100644 index 0000000..f6385d5 --- /dev/null +++ b/price_feeds/evm/morpho-pyth-oracle/script/PythAggregatorV3Deployment.s.sol @@ -0,0 +1,27 @@ +// 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 "forge-std/console.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 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 aggregator = new PythAggregatorV3(pythPriceFeedsContract, priceFeedId); + + console.log("PythAggregatorV3 deployed at", address(aggregator)); + + vm.stopBroadcast(); + } +} From ec8bc31e49d92b3632e636aa44b20ae9751fd6ac Mon Sep 17 00:00:00 2001 From: Aditya Arora Date: Tue, 4 Mar 2025 00:01:52 -0500 Subject: [PATCH 2/2] merged into one example --- .../.example.env | 3 +- price_feeds/evm/chainlink_migration/README.md | 12 +++- .../script/ChainlinkApp.s.sol} | 12 ++-- .../script/PythAggregatorV3Deployment.s.sol | 12 ++-- price_feeds/evm/morpho-pyth-oracle/.gitignore | 19 ------ price_feeds/evm/morpho-pyth-oracle/README.md | 66 ------------------- .../evm/morpho-pyth-oracle/foundry.toml | 6 -- .../evm/morpho-pyth-oracle/package-lock.json | 22 ------- .../evm/morpho-pyth-oracle/package.json | 19 ------ .../evm/morpho-pyth-oracle/remappings.txt | 1 - price_feeds/evm/pyth_sample/lib/forge-std | 1 - 11 files changed, 25 insertions(+), 148 deletions(-) rename price_feeds/evm/{morpho-pyth-oracle => chainlink_migration}/.example.env (66%) rename price_feeds/evm/{morpho-pyth-oracle/script/PythAggregatorV3Deployment.s.sol => chainlink_migration/script/ChainlinkApp.s.sol} (57%) delete mode 100644 price_feeds/evm/morpho-pyth-oracle/.gitignore delete mode 100644 price_feeds/evm/morpho-pyth-oracle/README.md delete mode 100644 price_feeds/evm/morpho-pyth-oracle/foundry.toml delete mode 100644 price_feeds/evm/morpho-pyth-oracle/package-lock.json delete mode 100644 price_feeds/evm/morpho-pyth-oracle/package.json delete mode 100644 price_feeds/evm/morpho-pyth-oracle/remappings.txt delete mode 160000 price_feeds/evm/pyth_sample/lib/forge-std diff --git a/price_feeds/evm/morpho-pyth-oracle/.example.env b/price_feeds/evm/chainlink_migration/.example.env similarity index 66% rename from price_feeds/evm/morpho-pyth-oracle/.example.env rename to price_feeds/evm/chainlink_migration/.example.env index 0fde874..14cf252 100644 --- a/price_feeds/evm/morpho-pyth-oracle/.example.env +++ b/price_feeds/evm/chainlink_migration/.example.env @@ -4,4 +4,5 @@ RPC_URL= PYTH_ADDRESS= # https://docs.pyth.network/price-feeds/price-feed-ids PRICE_FEED_ID= -ETHERSCAN_API_KEY= \ No newline at end of file +# To verify the contract on the respective chain's explorer +ETHERSCAN_API_KEY= diff --git a/price_feeds/evm/chainlink_migration/README.md b/price_feeds/evm/chainlink_migration/README.md index db979f7..26e0b78 100644 --- a/price_feeds/evm/chainlink_migration/README.md +++ b/price_feeds/evm/chainlink_migration/README.md @@ -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`. @@ -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: diff --git a/price_feeds/evm/morpho-pyth-oracle/script/PythAggregatorV3Deployment.s.sol b/price_feeds/evm/chainlink_migration/script/ChainlinkApp.s.sol similarity index 57% rename from price_feeds/evm/morpho-pyth-oracle/script/PythAggregatorV3Deployment.s.sol rename to price_feeds/evm/chainlink_migration/script/ChainlinkApp.s.sol index f6385d5..2843207 100644 --- a/price_feeds/evm/morpho-pyth-oracle/script/PythAggregatorV3Deployment.s.sol +++ b/price_feeds/evm/chainlink_migration/script/ChainlinkApp.s.sol @@ -3,7 +3,8 @@ pragma solidity ^0.8.0; import "forge-std/Script.sol"; import {PythAggregatorV3} from "@pythnetwork/pyth-sdk-solidity/PythAggregatorV3.sol"; -import "forge-std/console.sol"; +import {ChainlinkApp} from "../src/ChainlinkApp.sol"; + contract PythAggregatorV3Deployment is Script { function run() external { uint256 deployerPrivateKey = vm.envUint("PRIVATE_KEY"); @@ -14,13 +15,16 @@ 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 priceFeedId = vm.envBytes32("PRICE_FEED_ID"); + 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 aggregator = new PythAggregatorV3(pythPriceFeedsContract, priceFeedId); + PythAggregatorV3 ethAggregator = new PythAggregatorV3(pythPriceFeedsContract, ethFeedId); + PythAggregatorV3 solAggregator = new PythAggregatorV3(pythPriceFeedsContract, solFeedId); - console.log("PythAggregatorV3 deployed at", address(aggregator)); + // Pass the address of the PythAggregatorV3 contract to your chainlink-compatible app. + ChainlinkApp app = new ChainlinkApp(address(ethAggregator), address(solAggregator)); vm.stopBroadcast(); } diff --git a/price_feeds/evm/chainlink_migration/script/PythAggregatorV3Deployment.s.sol b/price_feeds/evm/chainlink_migration/script/PythAggregatorV3Deployment.s.sol index 2843207..f6385d5 100644 --- a/price_feeds/evm/chainlink_migration/script/PythAggregatorV3Deployment.s.sol +++ b/price_feeds/evm/chainlink_migration/script/PythAggregatorV3Deployment.s.sol @@ -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"); @@ -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(); } diff --git a/price_feeds/evm/morpho-pyth-oracle/.gitignore b/price_feeds/evm/morpho-pyth-oracle/.gitignore deleted file mode 100644 index 1f22e96..0000000 --- a/price_feeds/evm/morpho-pyth-oracle/.gitignore +++ /dev/null @@ -1,19 +0,0 @@ -# Compiler files -cache/ -out/ - -# Ignores development broadcast logs -broadcast/ - -# Docs -docs/ - -# Dotenv file -.env - -lib/* -!lib/README.md - -*~ - -node_modules \ No newline at end of file diff --git a/price_feeds/evm/morpho-pyth-oracle/README.md b/price_feeds/evm/morpho-pyth-oracle/README.md deleted file mode 100644 index 9265b45..0000000 --- a/price_feeds/evm/morpho-pyth-oracle/README.md +++ /dev/null @@ -1,66 +0,0 @@ -## Foundry - -**Foundry is a blazing fast, portable and modular toolkit for Ethereum application development written in Rust.** - -Foundry consists of: - -- **Forge**: Ethereum testing framework (like Truffle, Hardhat and DappTools). -- **Cast**: Swiss army knife for interacting with EVM smart contracts, sending transactions and getting chain data. -- **Anvil**: Local Ethereum node, akin to Ganache, Hardhat Network. -- **Chisel**: Fast, utilitarian, and verbose solidity REPL. - -## Documentation - -https://book.getfoundry.sh/ - -## Usage - -### Build - -```shell -$ forge build -``` - -### Test - -```shell -$ forge test -``` - -### Format - -```shell -$ forge fmt -``` - -### Gas Snapshots - -```shell -$ forge snapshot -``` - -### Anvil - -```shell -$ anvil -``` - -### Deploy - -```shell -$ forge script script/Counter.s.sol:CounterScript --rpc-url --private-key -``` - -### Cast - -```shell -$ cast -``` - -### Help - -```shell -$ forge --help -$ anvil --help -$ cast --help -``` diff --git a/price_feeds/evm/morpho-pyth-oracle/foundry.toml b/price_feeds/evm/morpho-pyth-oracle/foundry.toml deleted file mode 100644 index 25b918f..0000000 --- a/price_feeds/evm/morpho-pyth-oracle/foundry.toml +++ /dev/null @@ -1,6 +0,0 @@ -[profile.default] -src = "src" -out = "out" -libs = ["lib"] - -# See more config options https://github.com/foundry-rs/foundry/blob/master/crates/config/README.md#all-options diff --git a/price_feeds/evm/morpho-pyth-oracle/package-lock.json b/price_feeds/evm/morpho-pyth-oracle/package-lock.json deleted file mode 100644 index 9c1cc69..0000000 --- a/price_feeds/evm/morpho-pyth-oracle/package-lock.json +++ /dev/null @@ -1,22 +0,0 @@ -{ - "name": "morpho-pyth-oracle", - "version": "1.0.0", - "lockfileVersion": 3, - "requires": true, - "packages": { - "": { - "name": "morpho-pyth-oracle", - "version": "1.0.0", - "license": "ISC", - "dependencies": { - "@pythnetwork/pyth-sdk-solidity": "^4.0.0" - } - }, - "node_modules/@pythnetwork/pyth-sdk-solidity": { - "version": "4.0.0", - "resolved": "https://registry.npmjs.org/@pythnetwork/pyth-sdk-solidity/-/pyth-sdk-solidity-4.0.0.tgz", - "integrity": "sha512-Cy2MvSN1Oh5YpIYmZd2In6/gfXbGjnpazmXKioTuq07Drp4Rl2XHcvtqHdgilplCl32IG4pU+XoRafpexID08A==", - "license": "Apache-2.0" - } - } -} diff --git a/price_feeds/evm/morpho-pyth-oracle/package.json b/price_feeds/evm/morpho-pyth-oracle/package.json deleted file mode 100644 index 24544f7..0000000 --- a/price_feeds/evm/morpho-pyth-oracle/package.json +++ /dev/null @@ -1,19 +0,0 @@ -{ - "name": "morpho-pyth-oracle", - "version": "1.0.0", - "description": "**Foundry is a blazing fast, portable and modular toolkit for Ethereum application development written in Rust.**", - "main": "index.js", - "directories": { - "lib": "lib", - "test": "test" - }, - "scripts": { - "test": "echo \"Error: no test specified\" && exit 1" - }, - "keywords": [], - "author": "", - "license": "ISC", - "dependencies": { - "@pythnetwork/pyth-sdk-solidity": "^4.0.0" - } -} diff --git a/price_feeds/evm/morpho-pyth-oracle/remappings.txt b/price_feeds/evm/morpho-pyth-oracle/remappings.txt deleted file mode 100644 index fae9ede..0000000 --- a/price_feeds/evm/morpho-pyth-oracle/remappings.txt +++ /dev/null @@ -1 +0,0 @@ -@pythnetwork/pyth-sdk-solidity=node_modules/@pythnetwork/pyth-sdk-solidity diff --git a/price_feeds/evm/pyth_sample/lib/forge-std b/price_feeds/evm/pyth_sample/lib/forge-std deleted file mode 160000 index 1eea5ba..0000000 --- a/price_feeds/evm/pyth_sample/lib/forge-std +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 1eea5bae12ae557d589f9f0f0edae2faa47cb262