From 41aaf286798c63e1bee30b41bfd14166167e9422 Mon Sep 17 00:00:00 2001 From: Carson Date: Fri, 16 Aug 2024 16:55:03 -0400 Subject: [PATCH] feat: instead of error, configures DVN on lack of default with hardcoded values --- ...LayerZeroTellerWithMultiAssetSupport.s.sol | 57 ++++++++++++++++--- 1 file changed, 49 insertions(+), 8 deletions(-) diff --git a/script/deploy/single/05b_DeployMultiChainLayerZeroTellerWithMultiAssetSupport.s.sol b/script/deploy/single/05b_DeployMultiChainLayerZeroTellerWithMultiAssetSupport.s.sol index 59f46f7..dacd8ca 100644 --- a/script/deploy/single/05b_DeployMultiChainLayerZeroTellerWithMultiAssetSupport.s.sol +++ b/script/deploy/single/05b_DeployMultiChainLayerZeroTellerWithMultiAssetSupport.s.sol @@ -7,9 +7,12 @@ import { MultiChainLayerZeroTellerWithMultiAssetSupport } from import { BaseScript } from "./../../Base.s.sol"; import { stdJson as StdJson } from "@forge-std/StdJson.sol"; import { ConfigReader } from "../../ConfigReader.s.sol"; -import {ILayerZeroEndpointV2} from "@layerzerolabs/lz-evm-protocol-v2/contracts/interfaces/ILayerZeroEndpointV2.sol"; +import { ILayerZeroEndpointV2 } from "@layerzerolabs/lz-evm-protocol-v2/contracts/interfaces/ILayerZeroEndpointV2.sol"; +import {SetConfigParam} from "@layerzerolabs/lz-evm-protocol-v2/contracts/interfaces/IMessageLibManager.sol"; + contract DeployMultiChainLayerZeroTellerWithMultiAssetSupport is BaseScript { using StdJson for string; + address dead = 0x000000000000000000000000000000000000dEaD; struct UlnConfig { @@ -21,7 +24,7 @@ contract DeployMultiChainLayerZeroTellerWithMultiAssetSupport is BaseScript { address[] requiredDVNs; // no duplicates. sorted an an ascending order. allowed overlap with optionalDVNs address[] optionalDVNs; // no duplicates. sorted an an ascending order. allowed overlap with requiredDVNs } - + function run() public returns (address teller) { return deploy(getConfig()); } @@ -61,20 +64,58 @@ contract DeployMultiChainLayerZeroTellerWithMultiAssetSupport is BaseScript { require(address(teller.endpoint()) == config.lzEndpoint, "OP Teller must have messenger set"); // check if the DVN is configured and print a message to the screen to inform the deployer if not. + return address(teller); + } + + + function _checkUlnConfig(ConfigReader.Config memory config) internal { ILayerZeroEndpointV2 endpoint = ILayerZeroEndpointV2(config.lzEndpoint); address lib = endpoint.defaultSendLibrary(config.peerEid); bytes memory configBytes = endpoint.getConfig(config.teller, lib, config.peerEid, 2); UlnConfig memory ulnConfig = abi.decode(configBytes, (UlnConfig)); - require(ulnConfig.confirmations != 0, "uln config confirmations cannot be 0"); + if(ulnConfig.confirmations == 0){ + _setConfig(endpoint, lib, config); + return; + } uint8 numRequiredDVN = ulnConfig.requiredDVNCount; uint8 numOptionalDVN = ulnConfig.optionalDVNCount; - for(uint i; i < numRequiredDVN; ++i){ - require(ulnConfig.requiredDVNs[i] != dead, "uln config must not include dead"); + for (uint256 i; i < numRequiredDVN; ++i) { + if(ulnConfig.requiredDVNs[i] == dead){ + _setConfig(endpoint, lib, config); + return; + } } - for(uint i; i < numRequiredDVN; ++i){ - require(ulnConfig.optionalDVNs[i] != dead, "uln config must not include dead"); + for (uint256 i; i < numRequiredDVN; ++i) { + if(ulnConfig.optionalDVNs[i] == dead){ + _setConfig(endpoint, lib, config); + return; + } } - return address(teller); + + } + + function _setConfig(ILayerZeroEndpointV2 endpoint, address lib, ConfigReader.Config memory config) internal{ + address[] memory requiredDVNs = new address[](1); + address[] memory optionalDVNs = new address[](0); + + requiredDVNs[0] = 0x589dEDbD617e0CBcB916A9223F4d1300c294236b; + + bytes memory ulnConfigBytes = abi.encode(UlnConfig( + 15, + 1, + 0, + 0, + requiredDVNs, + optionalDVNs + )); + + SetConfigParam[] memory setConfigParams = new SetConfigParam[](1); + setConfigParams[0] = SetConfigParam( + config.peerEid, + 2, + ulnConfigBytes + ); + endpoint.setConfig(config.teller, lib, setConfigParams); } }