From f4d117867fcb57f5e13dbaaf425ae792e961f76e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Bl=C3=A4cker?= Date: Thu, 16 Jan 2025 16:16:20 +0700 Subject: [PATCH 1/5] add isContract check when reading contract addresses from config files --- config/across.json | 10 ++--- deployments/optimism.json | 2 +- script/deploy/facets/DeployAcrossFacet.s.sol | 9 ++-- .../facets/DeployAcrossFacetPacked.s.sol | 9 ++-- .../facets/DeployAcrossFacetPackedV3.s.sol | 9 ++-- .../deploy/facets/DeployAcrossFacetV3.s.sol | 12 +++-- .../deploy/facets/DeployAllBridgeFacet.s.sol | 4 +- script/deploy/facets/DeployAmarokFacet.s.sol | 4 +- .../facets/DeployAmarokFacetPacked.s.sol | 4 +- .../facets/DeployArbitrumBridgeFacet.s.sol | 7 +-- script/deploy/facets/DeployCBridgeFacet.s.sol | 4 +- .../facets/DeployCBridgeFacetPacked.s.sol | 4 +- .../facets/DeployCelerCircleBridgeFacet.s.sol | 9 ++-- script/deploy/facets/DeployCelerIMFacet.s.sol | 13 +++--- .../facets/DeployDeBridgeDlnFacet.s.sol | 6 +-- script/deploy/facets/DeployExecutor.s.sol | 3 +- script/deploy/facets/DeployGasZipFacet.s.sol | 10 ++--- .../deploy/facets/DeployGasZipPeriphery.s.sol | 25 +++++------ .../facets/DeployGenericSwapFacetV3.s.sol | 11 ++--- .../facets/DeployGnosisBridgeFacet.s.sol | 4 +- script/deploy/facets/DeployLiFiDiamond.s.sol | 7 +-- script/deploy/facets/DeployMayanFacet.s.sol | 4 +- .../deploy/facets/DeployOmniBridgeFacet.s.sol | 7 +-- script/deploy/facets/DeployPermit2Proxy.s.sol | 25 ++++------- .../facets/DeployPolygonBridgeFacet.s.sol | 7 +-- script/deploy/facets/DeployReceiver.s.sol | 11 +++-- .../facets/DeployReceiverAcrossV3.s.sol | 14 +++--- .../facets/DeployReceiverStargateV2.s.sol | 10 ++--- script/deploy/facets/DeployRelayFacet.s.sol | 8 ++-- .../deploy/facets/DeployRelayerCelerIM.s.sol | 8 ++-- script/deploy/facets/DeploySquidFacet.s.sol | 4 +- .../deploy/facets/DeployStargateFacet.s.sol | 4 +- .../deploy/facets/DeployStargateFacetV2.s.sol | 4 +- .../deploy/facets/DeploySymbiosisFacet.s.sol | 8 ++-- .../deploy/facets/DeployThorSwapFacet.s.sol | 5 +-- script/deploy/facets/DeployTokenWrapper.s.sol | 17 +++---- script/deploy/facets/UpdateCoreFacets.s.sol | 44 ++++++++++++++----- .../facets/UpdateOptimismBridgeFacet.s.sol | 5 ++- script/deploy/facets/utils/ScriptBase.sol | 24 ++++++++++ templates/facetDeployScript.template.hbs | 10 +++-- 40 files changed, 214 insertions(+), 171 deletions(-) diff --git a/config/across.json b/config/across.json index 48570a8f8..d3e924ce0 100644 --- a/config/across.json +++ b/config/across.json @@ -117,9 +117,7 @@ "chainId": 1135, "acrossSpokePool": "0x9552a0a6624A23B848060AE5901659CDDa1f83f8", "weth": "0x4200000000000000000000000000000000000006", - "tokensToApprove": [ - "0x4200000000000000000000000000000000000006" - ] + "tokensToApprove": ["0x4200000000000000000000000000000000000006"] }, "blast": { "chainId": 81457, @@ -146,8 +144,6 @@ "chainId": 480, "acrossSpokePool": "0x09aea4b2242abC8bb4BB78D537A67a245A7bEC64", "weth": "0x4200000000000000000000000000000000000006", - "tokensToApprove": [ - "0x4200000000000000000000000000000000000006" - ] + "tokensToApprove": ["0x4200000000000000000000000000000000000006"] } -} \ No newline at end of file +} diff --git a/deployments/optimism.json b/deployments/optimism.json index 8a2762394..f41f79936 100644 --- a/deployments/optimism.json +++ b/deployments/optimism.json @@ -49,7 +49,7 @@ "LiFiDEXAggregator": "0x6140b987d6B51Fd75b66C3B07733Beb5167c42fc", "Permit2Proxy": "0x6307119078556Fc8aD77781DFC67df20d75FB4f9", "EmergencyPauseFacet": "0x6F2baA7cd5F156CA1B132F7FF11E0fa2aD775F61", - "AcrossFacetV3": "0x5052fc5c7486162deDf7458E1f7c6ABaFbcd6895", + "AcrossFacetV3": "0x15428c8b134083d4AD765fCDe485D3f2fD026076", "ReceiverAcrossV3": "0xca6e6B692F568055adA0bF72A06D1EBbC938Fb23", "AcrossFacetPackedV3": "0x21a786957c69424A4353Afe743242Bd9Db3cC07b", "GasZipFacet": "0xF5c923a087fb3c554579e2DD10AB6E37E0f6F849", diff --git a/script/deploy/facets/DeployAcrossFacet.s.sol b/script/deploy/facets/DeployAcrossFacet.s.sol index 7a89fdf92..9d2120b41 100644 --- a/script/deploy/facets/DeployAcrossFacet.s.sol +++ b/script/deploy/facets/DeployAcrossFacet.s.sol @@ -21,12 +21,15 @@ contract DeployScript is DeployScriptBase { function getConstructorArgs() internal override returns (bytes memory) { string memory path = string.concat(root, "/config/across.json"); - string memory json = vm.readFile(path); - address acrossSpokePool = json.readAddress( + address acrossSpokePool = _getConfigContractAddress( + path, string.concat(".", network, ".acrossSpokePool") ); - address weth = json.readAddress(string.concat(".", network, ".weth")); + address weth = _getConfigContractAddress( + path, + string.concat(".", network, ".weth") + ); return abi.encode(acrossSpokePool, weth); } diff --git a/script/deploy/facets/DeployAcrossFacetPacked.s.sol b/script/deploy/facets/DeployAcrossFacetPacked.s.sol index 3cd05c69c..e7c0f2f5b 100644 --- a/script/deploy/facets/DeployAcrossFacetPacked.s.sol +++ b/script/deploy/facets/DeployAcrossFacetPacked.s.sol @@ -23,15 +23,16 @@ contract DeployScript is DeployScriptBase { function getConstructorArgs() internal override returns (bytes memory) { string memory path = string.concat(root, "/config/across.json"); - string memory json = vm.readFile(path); - address spokePool = json.readAddress( + address acrossSpokePool = _getConfigContractAddress( + path, string.concat(".", network, ".acrossSpokePool") ); - address wrappedNative = json.readAddress( + address weth = _getConfigContractAddress( + path, string.concat(".", network, ".weth") ); - return abi.encode(spokePool, wrappedNative, deployerAddress); + return abi.encode(acrossSpokePool, weth, deployerAddress); } } diff --git a/script/deploy/facets/DeployAcrossFacetPackedV3.s.sol b/script/deploy/facets/DeployAcrossFacetPackedV3.s.sol index 3ec850727..5688a6b3f 100644 --- a/script/deploy/facets/DeployAcrossFacetPackedV3.s.sol +++ b/script/deploy/facets/DeployAcrossFacetPackedV3.s.sol @@ -23,15 +23,16 @@ contract DeployScript is DeployScriptBase { function getConstructorArgs() internal override returns (bytes memory) { string memory path = string.concat(root, "/config/across.json"); - string memory json = vm.readFile(path); - address spokePool = json.readAddress( + address acrossSpokePool = _getConfigContractAddress( + path, string.concat(".", network, ".acrossSpokePool") ); - address wrappedNative = json.readAddress( + address weth = _getConfigContractAddress( + path, string.concat(".", network, ".weth") ); - return abi.encode(spokePool, wrappedNative, deployerAddress); + return abi.encode(acrossSpokePool, weth, deployerAddress); } } diff --git a/script/deploy/facets/DeployAcrossFacetV3.s.sol b/script/deploy/facets/DeployAcrossFacetV3.s.sol index b994d5c16..6752f54b9 100644 --- a/script/deploy/facets/DeployAcrossFacetV3.s.sol +++ b/script/deploy/facets/DeployAcrossFacetV3.s.sol @@ -21,12 +21,18 @@ contract DeployScript is DeployScriptBase { function getConstructorArgs() internal override returns (bytes memory) { string memory path = string.concat(root, "/config/across.json"); - string memory json = vm.readFile(path); - address acrossSpokePool = json.readAddress( + address acrossSpokePool = _getConfigContractAddress( + path, string.concat(".", network, ".acrossSpokePool") ); - address weth = json.readAddress(string.concat(".", network, ".weth")); + address weth = _getConfigContractAddress( + path, + string.concat(".", network, ".weth") + ); + + //TODO: REMOVE + address erc20Proxy = _getConfigContractAddress(path, ".ERC20Proxy"); return abi.encode(acrossSpokePool, weth); } diff --git a/script/deploy/facets/DeployAllBridgeFacet.s.sol b/script/deploy/facets/DeployAllBridgeFacet.s.sol index f1aeef268..5ef3c7c52 100644 --- a/script/deploy/facets/DeployAllBridgeFacet.s.sol +++ b/script/deploy/facets/DeployAllBridgeFacet.s.sol @@ -21,9 +21,9 @@ contract DeployScript is DeployScriptBase { function getConstructorArgs() internal override returns (bytes memory) { string memory path = string.concat(root, "/config/allbridge.json"); - string memory json = vm.readFile(path); - address allBridge = json.readAddress( + address allBridge = _getConfigContractAddress( + path, string.concat(".", network, ".allBridge") ); diff --git a/script/deploy/facets/DeployAmarokFacet.s.sol b/script/deploy/facets/DeployAmarokFacet.s.sol index 67326ae31..be4429f74 100644 --- a/script/deploy/facets/DeployAmarokFacet.s.sol +++ b/script/deploy/facets/DeployAmarokFacet.s.sol @@ -21,9 +21,9 @@ contract DeployScript is DeployScriptBase { function getConstructorArgs() internal override returns (bytes memory) { string memory path = string.concat(root, "/config/amarok.json"); - string memory json = vm.readFile(path); - address connextHandler = json.readAddress( + address connextHandler = _getConfigContractAddress( + path, string.concat(".", network, ".connextHandler") ); diff --git a/script/deploy/facets/DeployAmarokFacetPacked.s.sol b/script/deploy/facets/DeployAmarokFacetPacked.s.sol index 21c72e954..0f215ad7e 100644 --- a/script/deploy/facets/DeployAmarokFacetPacked.s.sol +++ b/script/deploy/facets/DeployAmarokFacetPacked.s.sol @@ -23,9 +23,9 @@ contract DeployScript is DeployScriptBase { function getConstructorArgs() internal override returns (bytes memory) { string memory path = string.concat(root, "/config/amarok.json"); - string memory json = vm.readFile(path); - address connextHandler = json.readAddress( + address connextHandler = _getConfigContractAddress( + path, string.concat(".", network, ".connextHandler") ); diff --git a/script/deploy/facets/DeployArbitrumBridgeFacet.s.sol b/script/deploy/facets/DeployArbitrumBridgeFacet.s.sol index bc7947fcf..b08c9f6d7 100644 --- a/script/deploy/facets/DeployArbitrumBridgeFacet.s.sol +++ b/script/deploy/facets/DeployArbitrumBridgeFacet.s.sol @@ -23,12 +23,13 @@ contract DeployScript is DeployScriptBase { function getConstructorArgs() internal override returns (bytes memory) { string memory path = string.concat(root, "/config/arbitrum.json"); - string memory json = vm.readFile(path); - address gatewayRouter = json.readAddress( + address gatewayRouter = _getConfigContractAddress( + path, string.concat(".", network, ".gatewayRouter") ); - address inbox = json.readAddress( + address inbox = _getConfigContractAddress( + path, string.concat(".", network, ".inbox") ); diff --git a/script/deploy/facets/DeployCBridgeFacet.s.sol b/script/deploy/facets/DeployCBridgeFacet.s.sol index 5f36512f0..e772665d3 100644 --- a/script/deploy/facets/DeployCBridgeFacet.s.sol +++ b/script/deploy/facets/DeployCBridgeFacet.s.sol @@ -21,9 +21,9 @@ contract DeployScript is DeployScriptBase { function getConstructorArgs() internal override returns (bytes memory) { string memory path = string.concat(root, "/config/cbridge.json"); - string memory json = vm.readFile(path); - address cBridge = json.readAddress( + address cBridge = _getConfigContractAddress( + path, string.concat(".", network, ".cBridge") ); diff --git a/script/deploy/facets/DeployCBridgeFacetPacked.s.sol b/script/deploy/facets/DeployCBridgeFacetPacked.s.sol index 9623e0db3..d99a9b06c 100644 --- a/script/deploy/facets/DeployCBridgeFacetPacked.s.sol +++ b/script/deploy/facets/DeployCBridgeFacetPacked.s.sol @@ -23,9 +23,9 @@ contract DeployScript is DeployScriptBase { function getConstructorArgs() internal override returns (bytes memory) { string memory path = string.concat(root, "/config/cbridge.json"); - string memory json = vm.readFile(path); - address cBridge = json.readAddress( + address cBridge = _getConfigContractAddress( + path, string.concat(".", network, ".cBridge") ); diff --git a/script/deploy/facets/DeployCelerCircleBridgeFacet.s.sol b/script/deploy/facets/DeployCelerCircleBridgeFacet.s.sol index df9fee900..5b1220929 100644 --- a/script/deploy/facets/DeployCelerCircleBridgeFacet.s.sol +++ b/script/deploy/facets/DeployCelerCircleBridgeFacet.s.sol @@ -23,12 +23,15 @@ contract DeployScript is DeployScriptBase { function getConstructorArgs() internal override returns (bytes memory) { string memory path = string.concat(root, "/config/celerCircle.json"); - string memory json = vm.readFile(path); - address circleBridgeProxy = json.readAddress( + address circleBridgeProxy = _getConfigContractAddress( + path, string.concat(".", network, ".circleBridgeProxy") ); - address usdc = json.readAddress(string.concat(".", network, ".usdc")); + address usdc = _getConfigContractAddress( + path, + string.concat(".", network, ".usdc") + ); return abi.encode(circleBridgeProxy, usdc); } diff --git a/script/deploy/facets/DeployCelerIMFacet.s.sol b/script/deploy/facets/DeployCelerIMFacet.s.sol index 0bce174e7..ddeadd48e 100644 --- a/script/deploy/facets/DeployCelerIMFacet.s.sol +++ b/script/deploy/facets/DeployCelerIMFacet.s.sol @@ -38,18 +38,20 @@ contract DeployScript is DeployScriptBase { function getConstructorArgs() internal override returns (bytes memory) { // get messageBus address string memory path = string.concat(root, "/config/cbridge.json"); - string memory json = vm.readFile(path); - address messageBus = json.readAddress( + address messageBus = _getConfigContractAddress( + path, string.concat(".", network, ".messageBus") ); + // get address of cfUSDC token (required for mainnet only, otherwise address(0)) address cfUSDCAddress; if ( keccak256(abi.encodePacked(network)) == keccak256(abi.encodePacked("mainnet")) ) { - cfUSDCAddress = json.readAddress( + cfUSDCAddress = _getConfigContractAddress( + path, string.concat(".", network, ".cfUSDC") ); } @@ -63,7 +65,6 @@ contract DeployScript is DeployScriptBase { fileSuffix, "json" ); - json = vm.readFile(path); // check which diamond to use (from env variable) string memory diamondType = vm.envString("DIAMOND_TYPE"); @@ -73,8 +74,8 @@ contract DeployScript is DeployScriptBase { // get address of the correct diamond contract from network log file address diamondAddress = deployMutable - ? json.readAddress(".LiFiDiamond") - : json.readAddress(".LiFiDiamondImmutable"); + ? _getConfigContractAddress(path, ".LiFiDiamond") + : _getConfigContractAddress(path, ".LiFiDiamondImmutable"); // get path of global config file string memory globalConfigPath = string.concat( diff --git a/script/deploy/facets/DeployDeBridgeDlnFacet.s.sol b/script/deploy/facets/DeployDeBridgeDlnFacet.s.sol index 224a13c5d..29218434f 100644 --- a/script/deploy/facets/DeployDeBridgeDlnFacet.s.sol +++ b/script/deploy/facets/DeployDeBridgeDlnFacet.s.sol @@ -23,10 +23,10 @@ contract DeployScript is DeployScriptBase { function getConstructorArgs() internal override returns (bytes memory) { string memory path = string.concat(root, "/config/dln.json"); - string memory json = vm.readFile(path); - address dlnSource = json.readAddress( - string.concat(".networks.", network, ".dlnSource") + address dlnSource = _getConfigContractAddress( + path, + string.concat(".", network, ".dlnSource") ); return abi.encode(dlnSource); diff --git a/script/deploy/facets/DeployExecutor.s.sol b/script/deploy/facets/DeployExecutor.s.sol index 525c5166e..fac8f0c3c 100644 --- a/script/deploy/facets/DeployExecutor.s.sol +++ b/script/deploy/facets/DeployExecutor.s.sol @@ -28,9 +28,8 @@ contract DeployScript is DeployScriptBase { fileSuffix, "json" ); - string memory json = vm.readFile(path); - address erc20Proxy = json.readAddress(".ERC20Proxy"); + address erc20Proxy = _getConfigContractAddress(path, ".ERC20Proxy"); return abi.encode(erc20Proxy); } diff --git a/script/deploy/facets/DeployGasZipFacet.s.sol b/script/deploy/facets/DeployGasZipFacet.s.sol index 627bb265f..c5da287e6 100644 --- a/script/deploy/facets/DeployGasZipFacet.s.sol +++ b/script/deploy/facets/DeployGasZipFacet.s.sol @@ -20,14 +20,10 @@ contract DeployScript is DeployScriptBase { } function getConstructorArgs() internal override returns (bytes memory) { - string memory gasZipConfig = string.concat( - root, - "/config/gaszip.json" - ); - - string memory gasZipConfigJson = vm.readFile(gasZipConfig); + string memory path = string.concat(root, "/config/gaszip.json"); - address gasZipRouter = gasZipConfigJson.readAddress( + address gasZipRouter = _getConfigContractAddress( + path, string.concat(".gasZipRouters.", network) ); diff --git a/script/deploy/facets/DeployGasZipPeriphery.s.sol b/script/deploy/facets/DeployGasZipPeriphery.s.sol index 0bef977e4..1bf95134f 100644 --- a/script/deploy/facets/DeployGasZipPeriphery.s.sol +++ b/script/deploy/facets/DeployGasZipPeriphery.s.sol @@ -21,19 +21,15 @@ contract DeployScript is DeployScriptBase { function getConstructorArgs() internal override returns (bytes memory) { // get gasZipRouter address - string memory gasZipConfig = string.concat( - root, - "/config/gaszip.json" - ); - - string memory gasZipConfigJson = vm.readFile(gasZipConfig); + string memory path = string.concat(root, "/config/gaszip.json"); - address gasZipRouter = gasZipConfigJson.readAddress( + address gasZipRouter = _getConfigContractAddress( + path, string.concat(".gasZipRouters.", network) ); // get LiFiDEXAggregator address - string memory deployLog = string.concat( + path = string.concat( root, "/deployments/", network, @@ -41,16 +37,17 @@ contract DeployScript is DeployScriptBase { fileSuffix, "json" ); - string memory json = vm.readFile(deployLog); - address liFiDEXAggregator = json.readAddress(".LiFiDEXAggregator"); + address liFiDEXAggregator = _getConfigContractAddress( + path, + ".LiFiDEXAggregator" + ); // get network's SAFE address to become contract owner for potential fund withdrawals - string memory networks = string.concat(root, "/config/networks.json"); - - string memory networksJson = vm.readFile(networks); + path = string.concat(root, "/config/networks.json"); - address safeAddress = networksJson.readAddress( + address safeAddress = _getConfigContractAddress( + path, string.concat(".", network, ".safeAddress") ); diff --git a/script/deploy/facets/DeployGenericSwapFacetV3.s.sol b/script/deploy/facets/DeployGenericSwapFacetV3.s.sol index a862f4ec6..2a29689ee 100644 --- a/script/deploy/facets/DeployGenericSwapFacetV3.s.sol +++ b/script/deploy/facets/DeployGenericSwapFacetV3.s.sol @@ -23,16 +23,11 @@ contract DeployScript is DeployScriptBase { function getConstructorArgs() internal override returns (bytes memory) { // get path of global config file - string memory globalConfigPath = string.concat( - root, - "/config/networks.json" - ); - - // read file into json variable - string memory globalConfigJson = vm.readFile(globalConfigPath); + string memory path = string.concat(root, "/config/networks.json"); // extract network's native address - address nativeAddress = globalConfigJson.readAddress( + address nativeAddress = _getConfigContractAddress( + path, string.concat(".", network, ".nativeAddress") ); diff --git a/script/deploy/facets/DeployGnosisBridgeFacet.s.sol b/script/deploy/facets/DeployGnosisBridgeFacet.s.sol index 9faa57b34..f3ca0c95d 100644 --- a/script/deploy/facets/DeployGnosisBridgeFacet.s.sol +++ b/script/deploy/facets/DeployGnosisBridgeFacet.s.sol @@ -23,9 +23,9 @@ contract DeployScript is DeployScriptBase { function getConstructorArgs() internal override returns (bytes memory) { string memory path = string.concat(root, "/config/gnosis.json"); - string memory json = vm.readFile(path); - address xDaiBridge = json.readAddress( + address xDaiBridge = _getConfigContractAddress( + path, string.concat(".", network, ".xDaiBridge") ); diff --git a/script/deploy/facets/DeployLiFiDiamond.s.sol b/script/deploy/facets/DeployLiFiDiamond.s.sol index 685401aa8..f505ac067 100644 --- a/script/deploy/facets/DeployLiFiDiamond.s.sol +++ b/script/deploy/facets/DeployLiFiDiamond.s.sol @@ -28,9 +28,10 @@ contract DeployScript is DeployScriptBase { fileSuffix, "json" ); - string memory json = vm.readFile(path); - - address diamondCut = json.readAddress(".DiamondCutFacet"); + address diamondCut = _getConfigContractAddress( + path, + ".DiamondCutFacet" + ); return abi.encode(deployerAddress, diamondCut); } diff --git a/script/deploy/facets/DeployMayanFacet.s.sol b/script/deploy/facets/DeployMayanFacet.s.sol index 3455d8045..85b097d09 100644 --- a/script/deploy/facets/DeployMayanFacet.s.sol +++ b/script/deploy/facets/DeployMayanFacet.s.sol @@ -22,9 +22,9 @@ contract DeployScript is DeployScriptBase { function getConstructorArgs() internal override returns (bytes memory) { // If you don't have a constructor or it doesn't take any arguments, you can remove this function string memory path = string.concat(root, "/config/mayan.json"); - string memory json = vm.readFile(path); - address bridge = json.readAddress( + address bridge = _getConfigContractAddress( + path, string.concat(".bridges.", network, ".bridge") ); diff --git a/script/deploy/facets/DeployOmniBridgeFacet.s.sol b/script/deploy/facets/DeployOmniBridgeFacet.s.sol index 1c3a45100..38499cff9 100644 --- a/script/deploy/facets/DeployOmniBridgeFacet.s.sol +++ b/script/deploy/facets/DeployOmniBridgeFacet.s.sol @@ -21,12 +21,13 @@ contract DeployScript is DeployScriptBase { function getConstructorArgs() internal override returns (bytes memory) { string memory path = string.concat(root, "/config/omni.json"); - string memory json = vm.readFile(path); - address foreignOmniBridge = json.readAddress( + address foreignOmniBridge = _getConfigContractAddress( + path, string.concat(".", network, ".foreignOmniBridge") ); - address wethOmniBridge = json.readAddress( + address wethOmniBridge = _getConfigContractAddress( + path, string.concat(".", network, ".wethOmniBridge") ); diff --git a/script/deploy/facets/DeployPermit2Proxy.s.sol b/script/deploy/facets/DeployPermit2Proxy.s.sol index d1553cd3e..c6f60fca9 100644 --- a/script/deploy/facets/DeployPermit2Proxy.s.sol +++ b/script/deploy/facets/DeployPermit2Proxy.s.sol @@ -21,7 +21,7 @@ contract DeployScript is DeployScriptBase { function getConstructorArgs() internal override returns (bytes memory) { // get the address of the LiFiDiamond for the given network - string memory deployments = string.concat( + string memory path = string.concat( root, "/deployments/", network, @@ -29,31 +29,22 @@ contract DeployScript is DeployScriptBase { fileSuffix, "json" ); - string memory deploymentsJSON = vm.readFile(deployments); - address diamond = deploymentsJSON.readAddress(".LiFiDiamond"); + address diamond = _getConfigContractAddress(path, ".LiFiDiamond"); // get the Permit2 contract address for the given network - string memory permit2ProxyConfig = string.concat( - root, - "/config/permit2Proxy.json" - ); - - string memory permit2ProxyConfigJSON = vm.readFile(permit2ProxyConfig); + path = string.concat(root, "/config/permit2Proxy.json"); - address permit2Address = permit2ProxyConfigJSON.readAddress( + address permit2Address = _getConfigContractAddress( + path, string.concat(".", network) ); // get the multisig SAFE address for the given network - string memory networksConfig = string.concat( - root, - "/config/networks.json" - ); - - string memory networksConfigJSON = vm.readFile(networksConfig); + path = string.concat(root, "/config/networks.json"); - address safeAddress = networksConfigJSON.readAddress( + address safeAddress = _getConfigContractAddress( + path, string.concat(".", network, ".safeAddress") ); diff --git a/script/deploy/facets/DeployPolygonBridgeFacet.s.sol b/script/deploy/facets/DeployPolygonBridgeFacet.s.sol index 0262f5bc2..26970f239 100644 --- a/script/deploy/facets/DeployPolygonBridgeFacet.s.sol +++ b/script/deploy/facets/DeployPolygonBridgeFacet.s.sol @@ -23,12 +23,13 @@ contract DeployScript is DeployScriptBase { function getConstructorArgs() internal override returns (bytes memory) { string memory path = string.concat(root, "/config/polygon.json"); - string memory json = vm.readFile(path); - address rootChainManager = json.readAddress( + address rootChainManager = _getConfigContractAddress( + path, string.concat(".", network, ".rootChainManager") ); - address erc20Predicate = json.readAddress( + address erc20Predicate = _getConfigContractAddress( + path, string.concat(".", network, ".erc20Predicate") ); diff --git a/script/deploy/facets/DeployReceiver.s.sol b/script/deploy/facets/DeployReceiver.s.sol index 103be9b1a..533c3c53f 100644 --- a/script/deploy/facets/DeployReceiver.s.sol +++ b/script/deploy/facets/DeployReceiver.s.sol @@ -36,17 +36,17 @@ contract DeployScript is DeployScriptBase { // obtain address of Stargate router in current network from config file string memory path = string.concat(root, "/config/stargate.json"); - string memory json = vm.readFile(path); - address stargateRouter = json.readAddress( + address stargateRouter = _getConfigContractAddress( + path, string.concat(".composers.", network) ); // obtain address of Amarok router in current network from config file path = string.concat(root, "/config/amarok.json"); - json = vm.readFile(path); - address amarokRouter = json.readAddress( + address amarokRouter = _getConfigContractAddress( + path, string.concat(".", network, ".connextHandler") ); @@ -58,8 +58,7 @@ contract DeployScript is DeployScriptBase { fileSuffix, "json" ); - json = vm.readFile(path); - address executor = json.readAddress(".Executor"); + address executor = _getConfigContractAddress(path, ".Executor"); return abi.encode( diff --git a/script/deploy/facets/DeployReceiverAcrossV3.s.sol b/script/deploy/facets/DeployReceiverAcrossV3.s.sol index eb40bcb46..9d547de41 100644 --- a/script/deploy/facets/DeployReceiverAcrossV3.s.sol +++ b/script/deploy/facets/DeployReceiverAcrossV3.s.sol @@ -38,9 +38,9 @@ contract DeployScript is DeployScriptBase { // obtain address of Across's Spokepool contract in current network from config file string memory path = string.concat(root, "/config/across.json"); - string memory json = vm.readFile(path); - address spokePool = json.readAddress( + address acrossSpokePool = _getConfigContractAddress( + path, string.concat(".", network, ".acrossSpokePool") ); @@ -53,12 +53,16 @@ contract DeployScript is DeployScriptBase { fileSuffix, "json" ); - json = vm.readFile(path); - address executor = json.readAddress(".Executor"); + address executor = _getConfigContractAddress(path, ".Executor"); uint256 recoverGas = 100000; return - abi.encode(refundWalletAddress, executor, spokePool, recoverGas); + abi.encode( + refundWalletAddress, + executor, + acrossSpokePool, + recoverGas + ); } } diff --git a/script/deploy/facets/DeployReceiverStargateV2.s.sol b/script/deploy/facets/DeployReceiverStargateV2.s.sol index 15f2daca4..126da67dc 100644 --- a/script/deploy/facets/DeployReceiverStargateV2.s.sol +++ b/script/deploy/facets/DeployReceiverStargateV2.s.sol @@ -38,12 +38,13 @@ contract DeployScript is DeployScriptBase { // obtain address of LayerZero's EndPointV2 contract in current network from config file string memory path = string.concat(root, "/config/stargate.json"); - string memory json = vm.readFile(path); - address endpointV2 = json.readAddress( + address endpointV2 = _getConfigContractAddress( + path, string.concat(".endpointV2.", network) ); - address tokenMessaging = json.readAddress( + address tokenMessaging = _getConfigContractAddress( + path, string.concat(".tokenMessaging.", network) ); @@ -56,8 +57,7 @@ contract DeployScript is DeployScriptBase { fileSuffix, "json" ); - json = vm.readFile(path); - address executor = json.readAddress(".Executor"); + address executor = _getConfigContractAddress(path, ".Executor"); return abi.encode( diff --git a/script/deploy/facets/DeployRelayFacet.s.sol b/script/deploy/facets/DeployRelayFacet.s.sol index f1382e220..3fc8fd2a1 100644 --- a/script/deploy/facets/DeployRelayFacet.s.sol +++ b/script/deploy/facets/DeployRelayFacet.s.sol @@ -21,13 +21,13 @@ contract DeployScript is DeployScriptBase { function getConstructorArgs() internal override returns (bytes memory) { string memory path = string.concat(root, "/config/relay.json"); - string memory json = vm.readFile(path); - address relayReceiver = json.readAddress( + address relayReceiver = _getConfigContractAddress( + path, string.concat(".", network, ".relayReceiver") ); - - address relaySolver = json.readAddress( + address relaySolver = _getConfigContractAddress( + path, string.concat(".", network, ".relaySolver") ); diff --git a/script/deploy/facets/DeployRelayerCelerIM.s.sol b/script/deploy/facets/DeployRelayerCelerIM.s.sol index 1779bb015..0be856e33 100644 --- a/script/deploy/facets/DeployRelayerCelerIM.s.sol +++ b/script/deploy/facets/DeployRelayerCelerIM.s.sol @@ -35,9 +35,9 @@ contract DeployScript is DeployScriptBase { ); string memory path = string.concat(root, "/config/cbridge.json"); - string memory json = vm.readFile(path); - address messageBus = json.readAddress( + address messageBus = _getConfigContractAddress( + path, string.concat(".", network, ".messageBus") ); @@ -49,9 +49,7 @@ contract DeployScript is DeployScriptBase { fileSuffix, "json" ); - json = vm.readFile(path); - - address diamond = json.readAddress(".LiFiDiamond"); + address diamond = _getConfigContractAddress(path, ".LiFiDiamond"); return abi.encode(refundWalletAddress, messageBus, diamond); } diff --git a/script/deploy/facets/DeploySquidFacet.s.sol b/script/deploy/facets/DeploySquidFacet.s.sol index 3d0ba708e..136b64eb7 100644 --- a/script/deploy/facets/DeploySquidFacet.s.sol +++ b/script/deploy/facets/DeploySquidFacet.s.sol @@ -21,9 +21,9 @@ contract DeployScript is DeployScriptBase { function getConstructorArgs() internal override returns (bytes memory) { string memory path = string.concat(root, "/config/squid.json"); - string memory json = vm.readFile(path); - address router = json.readAddress( + address router = _getConfigContractAddress( + path, string.concat(".", network, ".router") ); diff --git a/script/deploy/facets/DeployStargateFacet.s.sol b/script/deploy/facets/DeployStargateFacet.s.sol index 494af52ba..80bd6308e 100644 --- a/script/deploy/facets/DeployStargateFacet.s.sol +++ b/script/deploy/facets/DeployStargateFacet.s.sol @@ -21,9 +21,9 @@ contract DeployScript is DeployScriptBase { function getConstructorArgs() internal override returns (bytes memory) { string memory path = string.concat(root, "/config/stargate.json"); - string memory json = vm.readFile(path); - address composer = json.readAddress( + address composer = _getConfigContractAddress( + path, string.concat(".composers.", network) ); diff --git a/script/deploy/facets/DeployStargateFacetV2.s.sol b/script/deploy/facets/DeployStargateFacetV2.s.sol index dca898e6c..8fda09172 100644 --- a/script/deploy/facets/DeployStargateFacetV2.s.sol +++ b/script/deploy/facets/DeployStargateFacetV2.s.sol @@ -21,9 +21,9 @@ contract DeployScript is DeployScriptBase { function getConstructorArgs() internal override returns (bytes memory) { string memory path = string.concat(root, "/config/stargate.json"); - string memory json = vm.readFile(path); - address tokenMessaging = json.readAddress( + address tokenMessaging = _getConfigContractAddress( + path, string.concat(".tokenMessaging.", network) ); diff --git a/script/deploy/facets/DeploySymbiosisFacet.s.sol b/script/deploy/facets/DeploySymbiosisFacet.s.sol index 3b153a2c4..980d786f9 100644 --- a/script/deploy/facets/DeploySymbiosisFacet.s.sol +++ b/script/deploy/facets/DeploySymbiosisFacet.s.sol @@ -20,11 +20,13 @@ contract DeployScript is DeployScriptBase { function getConstructorArgs() internal override returns (bytes memory) { string memory path = string.concat(root, "/config/symbiosis.json"); - string memory json = vm.readFile(path); - address metaRouter = json.readAddress( + + address metaRouter = _getConfigContractAddress( + path, string.concat(".", network, ".metaRouter") ); - address gateway = json.readAddress( + address gateway = _getConfigContractAddress( + path, string.concat(".", network, ".gateway") ); diff --git a/script/deploy/facets/DeployThorSwapFacet.s.sol b/script/deploy/facets/DeployThorSwapFacet.s.sol index be4dd9d0c..c17a8ec65 100644 --- a/script/deploy/facets/DeployThorSwapFacet.s.sol +++ b/script/deploy/facets/DeployThorSwapFacet.s.sol @@ -21,12 +21,11 @@ contract DeployScript is DeployScriptBase { function getConstructorArgs() internal override returns (bytes memory) { string memory path = string.concat(root, "/config/thorswap.json"); - string memory json = vm.readFile(path); - address thorchainRouter = json.readAddress( + address thorchainRouter = _getConfigContractAddress( + path, string.concat(".", network, ".thorchainRouter") ); - return abi.encode(thorchainRouter); } } diff --git a/script/deploy/facets/DeployTokenWrapper.s.sol b/script/deploy/facets/DeployTokenWrapper.s.sol index 72d0806de..d29966559 100644 --- a/script/deploy/facets/DeployTokenWrapper.s.sol +++ b/script/deploy/facets/DeployTokenWrapper.s.sol @@ -21,9 +21,12 @@ contract DeployScript is DeployScriptBase { function getConstructorArgs() internal override returns (bytes memory) { // get path of global config file - string memory tokenWrapperConfig = string.concat( - root, - "/config/networks.json" + string memory path = string.concat(root, "/config/networks.json"); + + // extract wrapped token address for the given network + address wrappedNativeAddress = _getConfigContractAddress( + path, + string.concat(".", network, ".wrappedNativeAddress") ); // get path of global config file @@ -32,14 +35,6 @@ contract DeployScript is DeployScriptBase { "/config/global.json" ); - // read file into json variable - string memory tokenWrapperConfigJSON = vm.readFile(tokenWrapperConfig); - - // extract wrapped token address for the given network - address wrappedNativeAddress = tokenWrapperConfigJSON.readAddress( - string.concat(".", network, ".wrappedNativeAddress") - ); - // read file into json variable string memory globalConfigJson = vm.readFile(globalConfigPath); diff --git a/script/deploy/facets/UpdateCoreFacets.s.sol b/script/deploy/facets/UpdateCoreFacets.s.sol index a19863189..e56741c4b 100644 --- a/script/deploy/facets/UpdateCoreFacets.s.sol +++ b/script/deploy/facets/UpdateCoreFacets.s.sol @@ -20,17 +20,39 @@ contract DeployScript is UpdateScriptBase { public returns (address[] memory facets, bytes memory cutData) { - address diamondLoupe = json.readAddress(".DiamondLoupeFacet"); - address ownership = json.readAddress(".OwnershipFacet"); - address withdraw = json.readAddress(".WithdrawFacet"); - address dexMgr = json.readAddress(".DexManagerFacet"); - address accessMgr = json.readAddress(".AccessManagerFacet"); - address peripheryRgs = json.readAddress(".PeripheryRegistryFacet"); - address liFuelAddress = json.readAddress(".LIFuelFacet"); - address genSwapAddress = json.readAddress(".GenericSwapFacet"); - address genSwapV3Address = json.readAddress(".GenericSwapFacetV3"); - address standCallAddress = json.readAddress(".StandardizedCallFacet"); - address calldVerifAddress = json.readAddress( + address diamondLoupe = _getConfigContractAddress( + path, + ".DiamondLoupeFacet" + ); + address ownership = _getConfigContractAddress(path, ".OwnershipFacet"); + address withdraw = _getConfigContractAddress(path, ".WithdrawFacet"); + address dexMgr = _getConfigContractAddress(path, ".DexManagerFacet"); + address accessMgr = _getConfigContractAddress( + path, + ".AccessManagerFacet" + ); + address peripheryRgs = _getConfigContractAddress( + path, + ".PeripheryRegistryFacet" + ); + address liFuelAddress = _getConfigContractAddress( + path, + ".LIFuelFacet" + ); + address genSwapAddress = _getConfigContractAddress( + path, + ".GenericSwapFacet" + ); + address genSwapV3Address = _getConfigContractAddress( + path, + ".GenericSwapFacetV3" + ); + address standCallAddress = _getConfigContractAddress( + path, + ".StandardizedCallFacet" + ); + address calldVerifAddress = _getConfigContractAddress( + path, ".CalldataVerificationFacet" ); diff --git a/script/deploy/facets/UpdateOptimismBridgeFacet.s.sol b/script/deploy/facets/UpdateOptimismBridgeFacet.s.sol index da35e9279..637a64268 100644 --- a/script/deploy/facets/UpdateOptimismBridgeFacet.s.sol +++ b/script/deploy/facets/UpdateOptimismBridgeFacet.s.sol @@ -30,9 +30,12 @@ contract DeployScript is UpdateScriptBase { function getCallData() internal override returns (bytes memory) { path = string.concat(root, "/config/optimism.json"); json = vm.readFile(path); - address standardBridge = json.readAddress( + + address standardBridge = _getConfigContractAddress( + path, string.concat(".", network, ".standardBridge") ); + bytes memory rawConfig = json.parseRaw( string.concat(".", network, ".tokens") ); diff --git a/script/deploy/facets/utils/ScriptBase.sol b/script/deploy/facets/utils/ScriptBase.sol index d974aea15..506a3aa8b 100644 --- a/script/deploy/facets/utils/ScriptBase.sol +++ b/script/deploy/facets/utils/ScriptBase.sol @@ -3,8 +3,14 @@ pragma solidity ^0.8.17; import { Script, console } from "forge-std/Script.sol"; import { DSTest } from "ds-test/test.sol"; +import { LibAsset } from "lifi/Libraries/LibAsset.sol"; +import { stdJson } from "forge-std/Script.sol"; contract ScriptBase is Script, DSTest { + using stdJson for string; + + error NotAContract(string key); + uint256 internal deployerPrivateKey; address internal deployerAddress; string internal root; @@ -18,4 +24,22 @@ contract ScriptBase is Script, DSTest { network = vm.envString("NETWORK"); fileSuffix = vm.envString("FILE_SUFFIX"); } + + // reads an address from a config file and makes sure that the address contains code + function _getConfigContractAddress( + string memory path, + string memory key + ) internal returns (address contractAddress) { + // load json file + string memory json = vm.readFile(path); + + // read address + contractAddress = json.readAddress(key); + + // check if address contains code + if (!LibAsset.isContract(contractAddress)) + revert( + string.concat(key, " in file ", path, " is not a contract") + ); + } } diff --git a/templates/facetDeployScript.template.hbs b/templates/facetDeployScript.template.hbs index 840e533a2..0359199dd 100644 --- a/templates/facetDeployScript.template.hbs +++ b/templates/facetDeployScript.template.hbs @@ -24,9 +24,13 @@ contract DeployScript is DeployScriptBase { string memory path = string.concat(root, "/config/{{camelCase name}}.json"); string memory json = vm.readFile(path); - address example = json.readAddress( - string.concat(".", network, ".example") - ); + // If you need to read an address from your config file or from a network deploy log that is supposed to be a contract, use the + // following helper function which makes sure that the address contains code: + // + // address example = _getConfigContractAddress(json,string.concat(".", network, ".weth")); + // + // in the address is not a supposed to be an EOA, you can use the following standard approach: + address example = json.readAddress(".RefundWallet"); return abi.encode(example); } From 64505c8fbd70800fa30d8cc7f7d6294cb5270976 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Bl=C3=A4cker?= Date: Mon, 20 Jan 2025 11:17:34 +0700 Subject: [PATCH 2/5] some fixes --- deployments/optimism.json | 4 ++-- script/deploy/facets/DeployAcrossFacetV3.s.sol | 3 --- script/deploy/facets/DeployDeBridgeDlnFacet.s.sol | 2 +- 3 files changed, 3 insertions(+), 6 deletions(-) diff --git a/deployments/optimism.json b/deployments/optimism.json index f41f79936..09626a844 100644 --- a/deployments/optimism.json +++ b/deployments/optimism.json @@ -49,10 +49,10 @@ "LiFiDEXAggregator": "0x6140b987d6B51Fd75b66C3B07733Beb5167c42fc", "Permit2Proxy": "0x6307119078556Fc8aD77781DFC67df20d75FB4f9", "EmergencyPauseFacet": "0x6F2baA7cd5F156CA1B132F7FF11E0fa2aD775F61", - "AcrossFacetV3": "0x15428c8b134083d4AD765fCDe485D3f2fD026076", + "AcrossFacetV3": "0x5052fc5c7486162deDf7458E1f7c6ABaFbcd6895", "ReceiverAcrossV3": "0xca6e6B692F568055adA0bF72A06D1EBbC938Fb23", "AcrossFacetPackedV3": "0x21a786957c69424A4353Afe743242Bd9Db3cC07b", "GasZipFacet": "0xF5c923a087fb3c554579e2DD10AB6E37E0f6F849", "GasZipPeriphery": "0x9a21E33F1a78b17DAd32010CeDB9Fd2F071C17d3", "RelayFacet": "0x424BDbbaEda89732443fb1B737b6Dc194a6Ddbd5" -} \ No newline at end of file +} diff --git a/script/deploy/facets/DeployAcrossFacetV3.s.sol b/script/deploy/facets/DeployAcrossFacetV3.s.sol index 6752f54b9..636612883 100644 --- a/script/deploy/facets/DeployAcrossFacetV3.s.sol +++ b/script/deploy/facets/DeployAcrossFacetV3.s.sol @@ -31,9 +31,6 @@ contract DeployScript is DeployScriptBase { string.concat(".", network, ".weth") ); - //TODO: REMOVE - address erc20Proxy = _getConfigContractAddress(path, ".ERC20Proxy"); - return abi.encode(acrossSpokePool, weth); } } diff --git a/script/deploy/facets/DeployDeBridgeDlnFacet.s.sol b/script/deploy/facets/DeployDeBridgeDlnFacet.s.sol index 29218434f..818b2b86f 100644 --- a/script/deploy/facets/DeployDeBridgeDlnFacet.s.sol +++ b/script/deploy/facets/DeployDeBridgeDlnFacet.s.sol @@ -26,7 +26,7 @@ contract DeployScript is DeployScriptBase { address dlnSource = _getConfigContractAddress( path, - string.concat(".", network, ".dlnSource") + string.concat(".networks.", network, ".dlnSource") ); return abi.encode(dlnSource); From 8faacccacde1cefadd13cfcda9669d80935d1adc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Bl=C3=A4cker?= Date: Wed, 22 Jan 2025 09:52:54 +0700 Subject: [PATCH 3/5] update missing scripts --- .../zksync/DeployAcrossFacetPackedV3.s.sol | 9 ++++--- .../deploy/zksync/DeployAcrossFacetV3.s.sol | 9 ++++--- script/deploy/zksync/DeployExecutor.s.sol | 3 +-- script/deploy/zksync/DeployGasZipFacet.s.sol | 10 +++----- .../deploy/zksync/DeployGasZipPeriphery.s.sol | 25 ++++++++----------- .../zksync/DeployGenericSwapFacetV3.s.sol | 13 +++------- script/deploy/zksync/DeployLiFiDiamond.s.sol | 7 +++--- script/deploy/zksync/DeployPermit2Proxy.s.sol | 25 ++++++------------- script/deploy/zksync/DeployReceiver.s.sol | 11 ++++---- .../zksync/DeployReceiverAcrossV3.s.sol | 14 +++++++---- script/deploy/zksync/DeployRelayFacet.s.sol | 8 +++--- script/deploy/zksync/DeployTokenWrapper.s.sol | 17 +++++-------- script/deploy/zksync/utils/ScriptBase.sol | 21 ++++++++++++++++ ...ddTokenApprovalsToCBridgeFacetPacked.s.sol | 4 ++- .../solidity/CheckExecutorAndReceiver.s.sol | 4 +-- templates/facetDeployScript.template.hbs | 4 +-- 16 files changed, 94 insertions(+), 90 deletions(-) diff --git a/script/deploy/zksync/DeployAcrossFacetPackedV3.s.sol b/script/deploy/zksync/DeployAcrossFacetPackedV3.s.sol index 3ec850727..f43518a48 100644 --- a/script/deploy/zksync/DeployAcrossFacetPackedV3.s.sol +++ b/script/deploy/zksync/DeployAcrossFacetPackedV3.s.sol @@ -23,15 +23,16 @@ contract DeployScript is DeployScriptBase { function getConstructorArgs() internal override returns (bytes memory) { string memory path = string.concat(root, "/config/across.json"); - string memory json = vm.readFile(path); - address spokePool = json.readAddress( + address acrossSpokePool = _getConfigContractAddress( + path, string.concat(".", network, ".acrossSpokePool") ); - address wrappedNative = json.readAddress( + address weth = _getConfigContractAddress( + path, string.concat(".", network, ".weth") ); - return abi.encode(spokePool, wrappedNative, deployerAddress); + return abi.encode(acrossSpokePool, weth); } } diff --git a/script/deploy/zksync/DeployAcrossFacetV3.s.sol b/script/deploy/zksync/DeployAcrossFacetV3.s.sol index 82ecffbca..4e8075d66 100644 --- a/script/deploy/zksync/DeployAcrossFacetV3.s.sol +++ b/script/deploy/zksync/DeployAcrossFacetV3.s.sol @@ -21,12 +21,15 @@ contract DeployScript is DeployScriptBase { function getConstructorArgs() internal override returns (bytes memory) { string memory path = string.concat(root, "/config/across.json"); - string memory json = vm.readFile(path); - address acrossSpokePool = json.readAddress( + address acrossSpokePool = _getConfigContractAddress( + path, string.concat(".", network, ".acrossSpokePool") ); - address weth = json.readAddress(string.concat(".", network, ".weth")); + address weth = _getConfigContractAddress( + path, + string.concat(".", network, ".weth") + ); return abi.encode(acrossSpokePool, weth); } diff --git a/script/deploy/zksync/DeployExecutor.s.sol b/script/deploy/zksync/DeployExecutor.s.sol index 525c5166e..fac8f0c3c 100644 --- a/script/deploy/zksync/DeployExecutor.s.sol +++ b/script/deploy/zksync/DeployExecutor.s.sol @@ -28,9 +28,8 @@ contract DeployScript is DeployScriptBase { fileSuffix, "json" ); - string memory json = vm.readFile(path); - address erc20Proxy = json.readAddress(".ERC20Proxy"); + address erc20Proxy = _getConfigContractAddress(path, ".ERC20Proxy"); return abi.encode(erc20Proxy); } diff --git a/script/deploy/zksync/DeployGasZipFacet.s.sol b/script/deploy/zksync/DeployGasZipFacet.s.sol index 627bb265f..c5da287e6 100644 --- a/script/deploy/zksync/DeployGasZipFacet.s.sol +++ b/script/deploy/zksync/DeployGasZipFacet.s.sol @@ -20,14 +20,10 @@ contract DeployScript is DeployScriptBase { } function getConstructorArgs() internal override returns (bytes memory) { - string memory gasZipConfig = string.concat( - root, - "/config/gaszip.json" - ); - - string memory gasZipConfigJson = vm.readFile(gasZipConfig); + string memory path = string.concat(root, "/config/gaszip.json"); - address gasZipRouter = gasZipConfigJson.readAddress( + address gasZipRouter = _getConfigContractAddress( + path, string.concat(".gasZipRouters.", network) ); diff --git a/script/deploy/zksync/DeployGasZipPeriphery.s.sol b/script/deploy/zksync/DeployGasZipPeriphery.s.sol index 0bef977e4..1bf95134f 100644 --- a/script/deploy/zksync/DeployGasZipPeriphery.s.sol +++ b/script/deploy/zksync/DeployGasZipPeriphery.s.sol @@ -21,19 +21,15 @@ contract DeployScript is DeployScriptBase { function getConstructorArgs() internal override returns (bytes memory) { // get gasZipRouter address - string memory gasZipConfig = string.concat( - root, - "/config/gaszip.json" - ); - - string memory gasZipConfigJson = vm.readFile(gasZipConfig); + string memory path = string.concat(root, "/config/gaszip.json"); - address gasZipRouter = gasZipConfigJson.readAddress( + address gasZipRouter = _getConfigContractAddress( + path, string.concat(".gasZipRouters.", network) ); // get LiFiDEXAggregator address - string memory deployLog = string.concat( + path = string.concat( root, "/deployments/", network, @@ -41,16 +37,17 @@ contract DeployScript is DeployScriptBase { fileSuffix, "json" ); - string memory json = vm.readFile(deployLog); - address liFiDEXAggregator = json.readAddress(".LiFiDEXAggregator"); + address liFiDEXAggregator = _getConfigContractAddress( + path, + ".LiFiDEXAggregator" + ); // get network's SAFE address to become contract owner for potential fund withdrawals - string memory networks = string.concat(root, "/config/networks.json"); - - string memory networksJson = vm.readFile(networks); + path = string.concat(root, "/config/networks.json"); - address safeAddress = networksJson.readAddress( + address safeAddress = _getConfigContractAddress( + path, string.concat(".", network, ".safeAddress") ); diff --git a/script/deploy/zksync/DeployGenericSwapFacetV3.s.sol b/script/deploy/zksync/DeployGenericSwapFacetV3.s.sol index 9e3b7486a..2a29689ee 100644 --- a/script/deploy/zksync/DeployGenericSwapFacetV3.s.sol +++ b/script/deploy/zksync/DeployGenericSwapFacetV3.s.sol @@ -23,17 +23,12 @@ contract DeployScript is DeployScriptBase { function getConstructorArgs() internal override returns (bytes memory) { // get path of global config file - string memory globalConfigPath = string.concat( - root, - "/config/global.json" - ); - - // read file into json variable - string memory globalConfigJson = vm.readFile(globalConfigPath); + string memory path = string.concat(root, "/config/networks.json"); // extract network's native address - address nativeAddress = globalConfigJson.readAddress( - string.concat(".nativeAddress.", network) + address nativeAddress = _getConfigContractAddress( + path, + string.concat(".", network, ".nativeAddress") ); return abi.encode(nativeAddress); diff --git a/script/deploy/zksync/DeployLiFiDiamond.s.sol b/script/deploy/zksync/DeployLiFiDiamond.s.sol index 685401aa8..f505ac067 100644 --- a/script/deploy/zksync/DeployLiFiDiamond.s.sol +++ b/script/deploy/zksync/DeployLiFiDiamond.s.sol @@ -28,9 +28,10 @@ contract DeployScript is DeployScriptBase { fileSuffix, "json" ); - string memory json = vm.readFile(path); - - address diamondCut = json.readAddress(".DiamondCutFacet"); + address diamondCut = _getConfigContractAddress( + path, + ".DiamondCutFacet" + ); return abi.encode(deployerAddress, diamondCut); } diff --git a/script/deploy/zksync/DeployPermit2Proxy.s.sol b/script/deploy/zksync/DeployPermit2Proxy.s.sol index d1553cd3e..c6f60fca9 100644 --- a/script/deploy/zksync/DeployPermit2Proxy.s.sol +++ b/script/deploy/zksync/DeployPermit2Proxy.s.sol @@ -21,7 +21,7 @@ contract DeployScript is DeployScriptBase { function getConstructorArgs() internal override returns (bytes memory) { // get the address of the LiFiDiamond for the given network - string memory deployments = string.concat( + string memory path = string.concat( root, "/deployments/", network, @@ -29,31 +29,22 @@ contract DeployScript is DeployScriptBase { fileSuffix, "json" ); - string memory deploymentsJSON = vm.readFile(deployments); - address diamond = deploymentsJSON.readAddress(".LiFiDiamond"); + address diamond = _getConfigContractAddress(path, ".LiFiDiamond"); // get the Permit2 contract address for the given network - string memory permit2ProxyConfig = string.concat( - root, - "/config/permit2Proxy.json" - ); - - string memory permit2ProxyConfigJSON = vm.readFile(permit2ProxyConfig); + path = string.concat(root, "/config/permit2Proxy.json"); - address permit2Address = permit2ProxyConfigJSON.readAddress( + address permit2Address = _getConfigContractAddress( + path, string.concat(".", network) ); // get the multisig SAFE address for the given network - string memory networksConfig = string.concat( - root, - "/config/networks.json" - ); - - string memory networksConfigJSON = vm.readFile(networksConfig); + path = string.concat(root, "/config/networks.json"); - address safeAddress = networksConfigJSON.readAddress( + address safeAddress = _getConfigContractAddress( + path, string.concat(".", network, ".safeAddress") ); diff --git a/script/deploy/zksync/DeployReceiver.s.sol b/script/deploy/zksync/DeployReceiver.s.sol index 103be9b1a..533c3c53f 100644 --- a/script/deploy/zksync/DeployReceiver.s.sol +++ b/script/deploy/zksync/DeployReceiver.s.sol @@ -36,17 +36,17 @@ contract DeployScript is DeployScriptBase { // obtain address of Stargate router in current network from config file string memory path = string.concat(root, "/config/stargate.json"); - string memory json = vm.readFile(path); - address stargateRouter = json.readAddress( + address stargateRouter = _getConfigContractAddress( + path, string.concat(".composers.", network) ); // obtain address of Amarok router in current network from config file path = string.concat(root, "/config/amarok.json"); - json = vm.readFile(path); - address amarokRouter = json.readAddress( + address amarokRouter = _getConfigContractAddress( + path, string.concat(".", network, ".connextHandler") ); @@ -58,8 +58,7 @@ contract DeployScript is DeployScriptBase { fileSuffix, "json" ); - json = vm.readFile(path); - address executor = json.readAddress(".Executor"); + address executor = _getConfigContractAddress(path, ".Executor"); return abi.encode( diff --git a/script/deploy/zksync/DeployReceiverAcrossV3.s.sol b/script/deploy/zksync/DeployReceiverAcrossV3.s.sol index eb40bcb46..9d547de41 100644 --- a/script/deploy/zksync/DeployReceiverAcrossV3.s.sol +++ b/script/deploy/zksync/DeployReceiverAcrossV3.s.sol @@ -38,9 +38,9 @@ contract DeployScript is DeployScriptBase { // obtain address of Across's Spokepool contract in current network from config file string memory path = string.concat(root, "/config/across.json"); - string memory json = vm.readFile(path); - address spokePool = json.readAddress( + address acrossSpokePool = _getConfigContractAddress( + path, string.concat(".", network, ".acrossSpokePool") ); @@ -53,12 +53,16 @@ contract DeployScript is DeployScriptBase { fileSuffix, "json" ); - json = vm.readFile(path); - address executor = json.readAddress(".Executor"); + address executor = _getConfigContractAddress(path, ".Executor"); uint256 recoverGas = 100000; return - abi.encode(refundWalletAddress, executor, spokePool, recoverGas); + abi.encode( + refundWalletAddress, + executor, + acrossSpokePool, + recoverGas + ); } } diff --git a/script/deploy/zksync/DeployRelayFacet.s.sol b/script/deploy/zksync/DeployRelayFacet.s.sol index f1382e220..3fc8fd2a1 100644 --- a/script/deploy/zksync/DeployRelayFacet.s.sol +++ b/script/deploy/zksync/DeployRelayFacet.s.sol @@ -21,13 +21,13 @@ contract DeployScript is DeployScriptBase { function getConstructorArgs() internal override returns (bytes memory) { string memory path = string.concat(root, "/config/relay.json"); - string memory json = vm.readFile(path); - address relayReceiver = json.readAddress( + address relayReceiver = _getConfigContractAddress( + path, string.concat(".", network, ".relayReceiver") ); - - address relaySolver = json.readAddress( + address relaySolver = _getConfigContractAddress( + path, string.concat(".", network, ".relaySolver") ); diff --git a/script/deploy/zksync/DeployTokenWrapper.s.sol b/script/deploy/zksync/DeployTokenWrapper.s.sol index 72d0806de..d29966559 100644 --- a/script/deploy/zksync/DeployTokenWrapper.s.sol +++ b/script/deploy/zksync/DeployTokenWrapper.s.sol @@ -21,9 +21,12 @@ contract DeployScript is DeployScriptBase { function getConstructorArgs() internal override returns (bytes memory) { // get path of global config file - string memory tokenWrapperConfig = string.concat( - root, - "/config/networks.json" + string memory path = string.concat(root, "/config/networks.json"); + + // extract wrapped token address for the given network + address wrappedNativeAddress = _getConfigContractAddress( + path, + string.concat(".", network, ".wrappedNativeAddress") ); // get path of global config file @@ -32,14 +35,6 @@ contract DeployScript is DeployScriptBase { "/config/global.json" ); - // read file into json variable - string memory tokenWrapperConfigJSON = vm.readFile(tokenWrapperConfig); - - // extract wrapped token address for the given network - address wrappedNativeAddress = tokenWrapperConfigJSON.readAddress( - string.concat(".", network, ".wrappedNativeAddress") - ); - // read file into json variable string memory globalConfigJson = vm.readFile(globalConfigPath); diff --git a/script/deploy/zksync/utils/ScriptBase.sol b/script/deploy/zksync/utils/ScriptBase.sol index d974aea15..f9e96d627 100644 --- a/script/deploy/zksync/utils/ScriptBase.sol +++ b/script/deploy/zksync/utils/ScriptBase.sol @@ -3,8 +3,11 @@ pragma solidity ^0.8.17; import { Script, console } from "forge-std/Script.sol"; import { DSTest } from "ds-test/test.sol"; +import { stdJson } from "forge-std/Script.sol"; contract ScriptBase is Script, DSTest { + using stdJson for string; + uint256 internal deployerPrivateKey; address internal deployerAddress; string internal root; @@ -18,4 +21,22 @@ contract ScriptBase is Script, DSTest { network = vm.envString("NETWORK"); fileSuffix = vm.envString("FILE_SUFFIX"); } + + // reads an address from a config file and makes sure that the address contains code + function _getConfigContractAddress( + string memory path, + string memory key + ) internal returns (address contractAddress) { + // load json file + string memory json = vm.readFile(path); + + // read address + contractAddress = json.readAddress(key); + + // check if address contains code + if (!LibAsset.isContract(contractAddress)) + revert( + string.concat(key, " in file ", path, " is not a contract") + ); + } } diff --git a/script/tasks/solidity/AddTokenApprovalsToCBridgeFacetPacked.s.sol b/script/tasks/solidity/AddTokenApprovalsToCBridgeFacetPacked.s.sol index aa5c68f18..01d2c0f6b 100644 --- a/script/tasks/solidity/AddTokenApprovalsToCBridgeFacetPacked.s.sol +++ b/script/tasks/solidity/AddTokenApprovalsToCBridgeFacetPacked.s.sol @@ -37,7 +37,9 @@ contract DeployScript is UpdateScriptBase { string.concat(".", network, ".tokensToApprove") ); address[] memory tokens = abi.decode(rawConfig, (address[])); - address cBridge = json.readAddress( + + address cBridge = _getConfigContractAddress( + path, string.concat(".", network, ".cBridge") ); diff --git a/script/tasks/solidity/CheckExecutorAndReceiver.s.sol b/script/tasks/solidity/CheckExecutorAndReceiver.s.sol index c32a0cfb0..4cc1c4e76 100644 --- a/script/tasks/solidity/CheckExecutorAndReceiver.s.sol +++ b/script/tasks/solidity/CheckExecutorAndReceiver.s.sol @@ -13,8 +13,8 @@ contract DeployScript is UpdateScriptBase { using stdJson for string; function run() public returns (bool) { - address executor = json.readAddress(".Executor"); - address receiver = json.readAddress(".Receiver"); + address executor = _getConfigContractAddress(path, ".Executor"); + address receiver = _getConfigContractAddress(path, ".Receiver"); return executor == address(IReceiver(receiver).executor()); } diff --git a/templates/facetDeployScript.template.hbs b/templates/facetDeployScript.template.hbs index 0359199dd..c2a23fc3b 100644 --- a/templates/facetDeployScript.template.hbs +++ b/templates/facetDeployScript.template.hbs @@ -27,10 +27,10 @@ contract DeployScript is DeployScriptBase { // If you need to read an address from your config file or from a network deploy log that is supposed to be a contract, use the // following helper function which makes sure that the address contains code: // - // address example = _getConfigContractAddress(json,string.concat(".", network, ".weth")); + // address example = _getConfigContractAddress(json,string.concat(".", network, ".example")); // // in the address is not a supposed to be an EOA, you can use the following standard approach: - address example = json.readAddress(".RefundWallet"); + address example = json.readAddress(".Example"); return abi.encode(example); } From 632356e0ea99a188cbbb23b8fbcff43f0caf59a1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Bl=C3=A4cker?= Date: Wed, 22 Jan 2025 09:55:37 +0700 Subject: [PATCH 4/5] remove zksync ScripBase.sol duplicate --- .../deploy/zksync/utils/DeployScriptBase.sol | 2 +- script/deploy/zksync/utils/ScriptBase.sol | 42 ------------------- 2 files changed, 1 insertion(+), 43 deletions(-) delete mode 100644 script/deploy/zksync/utils/ScriptBase.sol diff --git a/script/deploy/zksync/utils/DeployScriptBase.sol b/script/deploy/zksync/utils/DeployScriptBase.sol index 81a14a248..4c7c43942 100644 --- a/script/deploy/zksync/utils/DeployScriptBase.sol +++ b/script/deploy/zksync/utils/DeployScriptBase.sol @@ -1,7 +1,7 @@ // SPDX-License-Identifier: UNLICENSED pragma solidity ^0.8.17; -import { ScriptBase } from "./ScriptBase.sol"; +import { ScriptBase } from "../../facets/utils/ScriptBase.sol"; import { stdJson } from "forge-std/Script.sol"; diff --git a/script/deploy/zksync/utils/ScriptBase.sol b/script/deploy/zksync/utils/ScriptBase.sol deleted file mode 100644 index f9e96d627..000000000 --- a/script/deploy/zksync/utils/ScriptBase.sol +++ /dev/null @@ -1,42 +0,0 @@ -// SPDX-License-Identifier: UNLICENSED -pragma solidity ^0.8.17; - -import { Script, console } from "forge-std/Script.sol"; -import { DSTest } from "ds-test/test.sol"; -import { stdJson } from "forge-std/Script.sol"; - -contract ScriptBase is Script, DSTest { - using stdJson for string; - - uint256 internal deployerPrivateKey; - address internal deployerAddress; - string internal root; - string internal network; - string internal fileSuffix; - - constructor() { - deployerPrivateKey = uint256(vm.envBytes32("PRIVATE_KEY")); - deployerAddress = vm.addr(deployerPrivateKey); - root = vm.projectRoot(); - network = vm.envString("NETWORK"); - fileSuffix = vm.envString("FILE_SUFFIX"); - } - - // reads an address from a config file and makes sure that the address contains code - function _getConfigContractAddress( - string memory path, - string memory key - ) internal returns (address contractAddress) { - // load json file - string memory json = vm.readFile(path); - - // read address - contractAddress = json.readAddress(key); - - // check if address contains code - if (!LibAsset.isContract(contractAddress)) - revert( - string.concat(key, " in file ", path, " is not a contract") - ); - } -} From 074dda0b1a1c5575a801696ff92729d6c35785b0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Bl=C3=A4cker?= Date: Wed, 22 Jan 2025 10:07:38 +0700 Subject: [PATCH 5/5] some fixes --- script/deploy/zksync/DeployAcrossFacetV3.s.sol | 2 +- .../solidity/AddTokenApprovalsToCBridgeFacetPacked.s.sol | 5 ++++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/script/deploy/zksync/DeployAcrossFacetV3.s.sol b/script/deploy/zksync/DeployAcrossFacetV3.s.sol index 4e8075d66..d1ce884f3 100644 --- a/script/deploy/zksync/DeployAcrossFacetV3.s.sol +++ b/script/deploy/zksync/DeployAcrossFacetV3.s.sol @@ -31,6 +31,6 @@ contract DeployScript is DeployScriptBase { string.concat(".", network, ".weth") ); - return abi.encode(acrossSpokePool, weth); + return abi.encode(acrossSpokePool, weth, deployerAddress); } } diff --git a/script/tasks/solidity/AddTokenApprovalsToCBridgeFacetPacked.s.sol b/script/tasks/solidity/AddTokenApprovalsToCBridgeFacetPacked.s.sol index 01d2c0f6b..9dc272ac6 100644 --- a/script/tasks/solidity/AddTokenApprovalsToCBridgeFacetPacked.s.sol +++ b/script/tasks/solidity/AddTokenApprovalsToCBridgeFacetPacked.s.sol @@ -14,7 +14,10 @@ contract DeployScript is UpdateScriptBase { address[] internal tokensToApprove; function run() public returns (address[] memory facets) { - address facet = json.readAddress(".CBridgeFacetPacked"); + address facet = _getConfigContractAddress( + path, + string.concat(".", network, ".CBridgeFacetPacked") + ); // The CBridgeFacetPacked owner is the refund wallet because we need access to trigger refunds // As there is only one owner, that address also needs to execute the approvals.