From 1653927094a73337a64e01a11fa6cd2bac337508 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment?= Date: Fri, 27 Sep 2024 16:09:34 +0200 Subject: [PATCH 1/3] feat: return true when running test against tenderly testnet. --- script/deploy/AbstractDeployScript.sol | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/script/deploy/AbstractDeployScript.sol b/script/deploy/AbstractDeployScript.sol index 4fa9a6b..8a1b9be 100644 --- a/script/deploy/AbstractDeployScript.sol +++ b/script/deploy/AbstractDeployScript.sol @@ -40,8 +40,19 @@ abstract contract AbstractDeployScript is Script { deployedContracts[name] = addr; } - function isForked() public view returns (bool) { - return vm.isContext(VmSafe.ForgeContext.ScriptDryRun) || vm.isContext(VmSafe.ForgeContext.TestGroup); + function isForked() public returns (bool) { + return isRcpUrlTestnet() || vm.isContext(VmSafe.ForgeContext.ScriptDryRun) + || vm.isContext(VmSafe.ForgeContext.TestGroup); + } + + /// @notice Detect if the RPC URL is a tendrly testnet, by trying to call a specific tenderly method on rpc. + /// @dev if the call success, it means we are on a tenderly testnet, otherwise we arn't. + function isRcpUrlTestnet() public returns (bool) { + try vm.rpc("tenderly_setBalance", "[[\"0x000000000000000000000000000000000000000b\"], \"0x0\"]") { + return true; + } catch { + return false; + } } function setUp() external virtual {} From 8bfe31726602d5414809ab3bcde175204fbcbb77 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment?= Date: Mon, 30 Sep 2024 10:20:44 +0200 Subject: [PATCH 2/3] fix: handler better tenderly testnet --- script/deploy/AbstractDeployScript.sol | 38 ++++++++++++++++++-------- 1 file changed, 27 insertions(+), 11 deletions(-) diff --git a/script/deploy/AbstractDeployScript.sol b/script/deploy/AbstractDeployScript.sol index 8a1b9be..7e8b9bd 100644 --- a/script/deploy/AbstractDeployScript.sol +++ b/script/deploy/AbstractDeployScript.sol @@ -15,6 +15,8 @@ abstract contract AbstractDeployScript is Script { address deployer; uint256 public deployBlockNum = type(uint256).max; + bool public tenderlyTestnet; + // DeployerRecord stuff to be extracted as well struct DeployRecord { string name; @@ -40,22 +42,26 @@ abstract contract AbstractDeployScript is Script { deployedContracts[name] = addr; } - function isForked() public returns (bool) { - return isRcpUrlTestnet() || vm.isContext(VmSafe.ForgeContext.ScriptDryRun) + function isForked() public view returns (bool) { + return tenderlyTestnet || vm.isContext(VmSafe.ForgeContext.ScriptDryRun) || vm.isContext(VmSafe.ForgeContext.TestGroup); } /// @notice Detect if the RPC URL is a tendrly testnet, by trying to call a specific tenderly method on rpc. /// @dev if the call success, it means we are on a tenderly testnet, otherwise we arn't. - function isRcpUrlTestnet() public returns (bool) { - try vm.rpc("tenderly_setBalance", "[[\"0x000000000000000000000000000000000000000b\"], \"0x0\"]") { + function isTenderlyRpc() public returns (bool) { + // Try to give ethers to "0x7E5F4552091A69125d5DfCb7b8C2659029395Bdf" which is the address for pk = 0x0....01 + try vm.rpc("tenderly_setBalance", "[[\"0x7E5F4552091A69125d5DfCb7b8C2659029395Bdf\"], \"0xDE0B6B3A7640000\"]") { + tenderlyTestnet = true; return true; } catch { return false; } } - function setUp() external virtual {} + function setUp() external virtual { + isTenderlyRpc(); + } function run() external { // Will not execute script if after this block number @@ -65,9 +71,15 @@ abstract contract AbstractDeployScript is Script { } if (this.isForked()) { - deployer = Mainnet.INITIAL_DEPLOYER; - console.log("Running script on mainnet fork impersonating: %s", deployer); - vm.startPrank(deployer); + if (tenderlyTestnet) { + deployer = vm.rememberKey(uint256(1)); + console.log("Deploying on Tenderly testnet with deployer: %s", deployer); + vm.startBroadcast(deployer); + } else { + deployer = Mainnet.INITIAL_DEPLOYER; + console.log("Running script on mainnet fork impersonating: %s", deployer); + vm.startPrank(deployer); + } } else { uint256 deployerPrivateKey = vm.envUint("DEPLOYER_PRIVATE_KEY"); deployer = vm.rememberKey(deployerPrivateKey); @@ -78,9 +90,13 @@ abstract contract AbstractDeployScript is Script { _execute(); if (this.isForked()) { - vm.stopPrank(); - _buildGovernanceProposal(); - _fork(); + if (tenderlyTestnet) { + vm.stopBroadcast(); + } else { + vm.stopPrank(); + _buildGovernanceProposal(); + _fork(); + } } else { vm.stopBroadcast(); } From 06a02e689be6c7e5ecaf0bbcc94e12bc3dc26f51 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment?= Date: Mon, 30 Sep 2024 13:50:19 +0200 Subject: [PATCH 3/3] fix: use -unlocked keywork to broadcast & impersonate --- Makefile | 2 +- script/deploy/AbstractDeployScript.sol | 9 +++++---- script/deploy/mainnet/003_UpgradeLidoARMScript.sol | 6 +++++- 3 files changed, 11 insertions(+), 6 deletions(-) diff --git a/Makefile b/Makefile index b8f7787..5f16997 100644 --- a/Makefile +++ b/Makefile @@ -56,7 +56,7 @@ deploy: @forge script script/deploy/DeployManager.sol --rpc-url $(PROVIDER_URL) --private-key ${DEPLOYER_PRIVATE_KEY} --broadcast --slow --verify -vvvv deploy-testnet: - @forge script script/deploy/DeployManager.sol --rpc-url $(TESTNET_URL) --private-key ${DEPLOYER_PRIVATE_KEY} --broadcast --slow -vvvv + @forge script script/deploy/DeployManager.sol --rpc-url $(TESTNET_URL) --broadcast --slow --unlocked -vvvv deploy-holesky: @forge script script/deploy/DeployManager.sol --rpc-url $(HOLESKY_URL) --private-key ${DEPLOYER_PRIVATE_KEY} --broadcast --slow --verify -vvvv diff --git a/script/deploy/AbstractDeployScript.sol b/script/deploy/AbstractDeployScript.sol index 7e8b9bd..293cafd 100644 --- a/script/deploy/AbstractDeployScript.sol +++ b/script/deploy/AbstractDeployScript.sol @@ -50,8 +50,8 @@ abstract contract AbstractDeployScript is Script { /// @notice Detect if the RPC URL is a tendrly testnet, by trying to call a specific tenderly method on rpc. /// @dev if the call success, it means we are on a tenderly testnet, otherwise we arn't. function isTenderlyRpc() public returns (bool) { - // Try to give ethers to "0x7E5F4552091A69125d5DfCb7b8C2659029395Bdf" which is the address for pk = 0x0....01 - try vm.rpc("tenderly_setBalance", "[[\"0x7E5F4552091A69125d5DfCb7b8C2659029395Bdf\"], \"0xDE0B6B3A7640000\"]") { + // Try to give ethers to "ARM_MULTISIG" + try vm.rpc("tenderly_setBalance", "[[\"0xC8F2cF4742C86295653f893214725813B16f7410\"], \"0xDE0B6B3A7640000\"]") { tenderlyTestnet = true; return true; } catch { @@ -71,12 +71,11 @@ abstract contract AbstractDeployScript is Script { } if (this.isForked()) { + deployer = Mainnet.INITIAL_DEPLOYER; if (tenderlyTestnet) { - deployer = vm.rememberKey(uint256(1)); console.log("Deploying on Tenderly testnet with deployer: %s", deployer); vm.startBroadcast(deployer); } else { - deployer = Mainnet.INITIAL_DEPLOYER; console.log("Running script on mainnet fork impersonating: %s", deployer); vm.startPrank(deployer); } @@ -91,7 +90,9 @@ abstract contract AbstractDeployScript is Script { if (this.isForked()) { if (tenderlyTestnet) { + _buildGovernanceProposal(); vm.stopBroadcast(); + _fork(); } else { vm.stopPrank(); _buildGovernanceProposal(); diff --git a/script/deploy/mainnet/003_UpgradeLidoARMScript.sol b/script/deploy/mainnet/003_UpgradeLidoARMScript.sol index 9f8ae83..46ce5dd 100644 --- a/script/deploy/mainnet/003_UpgradeLidoARMScript.sol +++ b/script/deploy/mainnet/003_UpgradeLidoARMScript.sol @@ -68,7 +68,11 @@ contract UpgradeLidoARMMainnetScript is AbstractDeployScript { function _buildGovernanceProposal() internal override {} function _fork() internal override { - vm.startPrank(Mainnet.ARM_MULTISIG); + if (tenderlyTestnet) { + vm.startBroadcast(Mainnet.ARM_MULTISIG); + } else { + vm.startPrank(Mainnet.ARM_MULTISIG); + } if (lidoARMProxy == Proxy(0x0000000000000000000000000000000000000000)) { revert("Lido ARM proxy not found");