-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement upgraded version for price feed smart contract (#218)
* Implement upgraded version for price feed smart contract * Implement deployment scripts * Fix RedStone main demo constant value * Add two new RedStone data service URLs * Apply review suggestions
- Loading branch information
Showing
5 changed files
with
144 additions
and
35 deletions.
There are no files selected for viewing
46 changes: 46 additions & 0 deletions
46
script/contracts/L2/upgraded/L2PriceFeedWithoutRoundsV2.s.sol
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
// SPDX-License-Identifier: Apache-2.0 | ||
pragma solidity 0.8.23; | ||
|
||
import { ERC1967Proxy } from "@openzeppelin/contracts/proxy/ERC1967/ERC1967Proxy.sol"; | ||
import { Upgrades } from "openzeppelin-foundry-upgrades/Upgrades.sol"; | ||
import { Options } from "openzeppelin-foundry-upgrades/Options.sol"; | ||
import { Script, console2 } from "forge-std/Script.sol"; | ||
import { L2PriceFeedWithoutRoundsV2 } from "src/L2/upgraded/L2PriceFeedWithoutRoundsV2.sol"; | ||
|
||
/// @title L2PriceFeedWithoutRoundsV2Script - L2PriceFeedWithoutRoundsV2 contract deployment script | ||
/// @notice This contract is used to deploy L2PriceFeedWithoutRoundsV2 contract which is upgraded version of | ||
/// L2PriceFeedWithoutRounds contract. | ||
contract L2PriceFeedWithoutRoundsV2Script is Script { | ||
function setUp() public { } | ||
|
||
/// @notice This function deploys L2PriceFeedWithoutRoundsV2 contract. | ||
function run() public { | ||
// Deployer's private key. This key is used to deploy the contract. | ||
uint256 deployerPrivateKey = vm.envUint("PRIVATE_KEY"); | ||
|
||
// Validate L2PriceFeedWithoutRoundsV2 contract if it is implemented correctly so that it may be used as new | ||
// implementation for the proxy contract. | ||
Options memory opts; | ||
opts.referenceContract = "L2PriceFeedWithoutRounds.sol"; | ||
opts.unsafeAllow = "constructor"; | ||
Upgrades.validateUpgrade("L2PriceFeedWithoutRoundsV2.sol", opts); | ||
|
||
console2.log("Deploying L2 PriceFeedWithoutRoundsV2 contract..."); | ||
|
||
// deploy L2PriceFeedWithoutRoundsV2 contract | ||
vm.startBroadcast(deployerPrivateKey); | ||
L2PriceFeedWithoutRoundsV2 l2PriceFeedWithoutRoundsV2 = new L2PriceFeedWithoutRoundsV2(); | ||
vm.stopBroadcast(); | ||
|
||
assert(address(l2PriceFeedWithoutRoundsV2) != address(0)); | ||
|
||
// ERC1967Utils: keccak-256 hash of "eip1967.proxy.implementation" subtracted by 1. | ||
assert( | ||
l2PriceFeedWithoutRoundsV2.proxiableUUID() | ||
== bytes32(uint256(keccak256("eip1967.proxy.implementation")) - 1) | ||
); | ||
|
||
console2.log("L2 PriceFeedWithoutRoundsV2 contract successfully deployed!"); | ||
console2.log("L2 PriceFeedWithoutRoundsV2 address: %s", address(l2PriceFeedWithoutRoundsV2)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
#!/usr/bin/env bash | ||
|
||
echo "Instructing the shell to exit immediately if any command returns a non-zero exit status..." | ||
set -e | ||
echo "Done." | ||
|
||
echo "Navigating to the root directory of the project..." | ||
cd ../../ | ||
echo "Done." | ||
|
||
echo "Setting environment variables..." | ||
source .env | ||
echo "Done." | ||
|
||
echo "Creating $NETWORK directory inside deployment/artifacts/contracts directory..." | ||
if [ -z "$NETWORK" ] | ||
then | ||
echo "NETWORK variable inside .env file is not set. Please set NETWORK environment variable." | ||
exit 1 | ||
else | ||
if [ -d "deployment/artifacts/contracts/$NETWORK" ] | ||
then | ||
echo "Directory deployment/artifacts/contracts/$NETWORK already exists." | ||
else | ||
mkdir deployment/artifacts/contracts/$NETWORK | ||
fi | ||
fi | ||
echo "Done." | ||
|
||
echo "Cleaning up the build artifacts to be able to deploy the contract..." | ||
forge clean | ||
echo "Done." | ||
|
||
echo "Deploying and if enabled verifying L2PriceFeedWithoutRoundsV2 smart contract..." | ||
if [ -z "$CONTRACT_VERIFIER" ] | ||
then | ||
forge script --rpc-url="$L2_RPC_URL" --broadcast -vvvv script/contracts/L2/upgraded/L2PriceFeedWithoutRoundsV2.s.sol:L2PriceFeedWithoutRoundsV2Script | ||
else | ||
if [ $CONTRACT_VERIFIER = "blockscout" ] | ||
then | ||
forge script --rpc-url="$L2_RPC_URL" --broadcast --verify --verifier blockscout --verifier-url $L2_VERIFIER_URL -vvvv script/contracts/L2/upgraded/L2PriceFeedWithoutRoundsV2.s.sol:L2PriceFeedWithoutRoundsV2Script | ||
fi | ||
if [ $CONTRACT_VERIFIER = "etherscan" ] | ||
then | ||
forge script --rpc-url="$L2_RPC_URL" --broadcast --verify --verifier etherscan --etherscan-api-key="$L2_ETHERSCAN_API_KEY" -vvvv script/contracts/L2/upgraded/L2PriceFeedWithoutRoundsV2.s.sol:L2PriceFeedWithoutRoundsV2Script | ||
fi | ||
fi | ||
echo "Done." |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
// SPDX-License-Identifier: Apache-2.0 | ||
pragma solidity 0.8.23; | ||
|
||
import { L2PriceFeedWithoutRounds } from "../L2PriceFeedWithoutRounds.sol"; | ||
|
||
/// @title L2PriceFeedWithoutRoundsV2 - L2PriceFeedWithoutRoundsV2 contract | ||
/// @notice This contract represents PriceFeedWithoutRoundsForMultiFeedAdapter contract. It is an upgradeable version of | ||
/// the L2PriceFeedWithoutRounds contract, allowing for updates to the adapter contract address while | ||
/// maintaining the same interface and functionality. | ||
contract L2PriceFeedWithoutRoundsV2 is L2PriceFeedWithoutRounds { | ||
/// @notice Setting global params. | ||
/// @param _newAdapter The address of the new MultiFeedAdapter contract. | ||
function initializeV2(address _newAdapter) public virtual reinitializer(2) { | ||
require(_newAdapter != address(0), "L2PriceFeedWithoutRoundsV2: new adapter contract address can not be zero"); | ||
priceFeedAdapter = _newAdapter; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters