diff --git a/price_feeds/evm/chainlink_migration/.example.env b/price_feeds/evm/chainlink_migration/.example.env new file mode 100644 index 0000000..14cf252 --- /dev/null +++ b/price_feeds/evm/chainlink_migration/.example.env @@ -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= 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/chainlink_migration/script/ChainlinkApp.s.sol b/price_feeds/evm/chainlink_migration/script/ChainlinkApp.s.sol new file mode 100644 index 0000000..2843207 --- /dev/null +++ b/price_feeds/evm/chainlink_migration/script/ChainlinkApp.s.sol @@ -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(); + } +} 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/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