Skip to content

Commit

Permalink
feat: instead of error, configures DVN on lack of default with hardco…
Browse files Browse the repository at this point in the history
…ded values
  • Loading branch information
CarsonCase committed Aug 16, 2024
1 parent 538f757 commit 41aaf28
Showing 1 changed file with 49 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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());
}
Expand Down Expand Up @@ -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);
}
}

0 comments on commit 41aaf28

Please sign in to comment.