From ebac7be88fb7d353ee4f4fda03ee273755edb6c3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?lz=2Esir=CE=94rthurmoney=28=29?= Date: Tue, 14 Nov 2023 15:03:10 -0800 Subject: [PATCH] updating getConfig task --- packages/ua-utils/src/getConfig.ts | 85 ++++++++++++++++-------------- packages/ua-utils/src/index.ts | 3 +- 2 files changed, 48 insertions(+), 40 deletions(-) diff --git a/packages/ua-utils/src/getConfig.ts b/packages/ua-utils/src/getConfig.ts index fb1768e93..08ff79831 100644 --- a/packages/ua-utils/src/getConfig.ts +++ b/packages/ua-utils/src/getConfig.ts @@ -1,49 +1,56 @@ -import { getDeploymentAddresses, getApplicationConfig, getEndpointAddress } from "./utils/crossChainHelper" -import { ENDPOINT_ABI, MESSAGING_LIBRARY_ABI } from "./constants/abi" -import { logError } from "./utils/helpers" +import { ActionType, HardhatRuntimeEnvironment } from "hardhat/types" +import { task, types } from "hardhat/config" +import { ethers } from "ethers" +import { createGetNetworkEnvironment } from "@layerzerolabs/hardhat-utils" -export default async (taskArgs: any, hre: any) => { - const network = hre.network.name - const remoteNetworks = taskArgs.remoteNetworks.split(",") - const contractName = taskArgs.name - let contractAddress = taskArgs.address +const action: ActionType = async (taskArgs, hre) => { + // TODO add logging + // const logger = createLogger() + + const localNetwork = hre.network.name + const getEnvironment = createGetNetworkEnvironment(hre) + const localEnvironment = await getEnvironment(localNetwork) + const localEndpointV2 = await localEnvironment.getContract("EndpointV2", localEnvironment.provider) + const localEid = await localEndpointV2.eid() - if (!contractName && !contractAddress) { - logError("Provide contract name or address") + let localContractAddress + if (taskArgs.name !== undefined) { + localContractAddress = (await localEnvironment.getContract(taskArgs.name, localEnvironment.provider)).address + } else if (taskArgs.address !== undefined) { + localContractAddress = taskArgs.address + } else { + // TODO log error return } - if (contractName && !contractAddress) { - contractAddress = getDeploymentAddresses(network, false)[contractName] - if (!contractAddress) { - logError(`Deployment information isn't found for ${contractName}`) - return - } - } + const ulnConfigDeployment = await hre.deployments.get("UlnConfig") + const remoteNetworks = taskArgs.remoteNetworks.split(",") + const configByNetwork = await Promise.all( + remoteNetworks.map(async (remoteNetwork: string) => { + const remoteEnvironment = await getEnvironment(remoteNetwork) + const remoteEndpointV2 = await remoteEnvironment.getContract("EndpointV2", remoteEnvironment.provider) + const remoteEid = await remoteEndpointV2.eid() - const endpoint = await hre.ethers.getContractAt(ENDPOINT_ABI, getEndpointAddress(network)) - const appConfig = await endpoint.uaConfigLookup(contractAddress) - const sendVersion = appConfig.sendVersion - const receiveVersion = appConfig.receiveVersion - const sendLibraryAddress = sendVersion === 0 ? await endpoint.defaultSendLibrary() : appConfig.sendLibrary - const sendLibrary = await hre.ethers.getContractAt(MESSAGING_LIBRARY_ABI, sendLibraryAddress) - let receiveLibrary: any + const localSendLibrary = await localEndpointV2.getSendLibrary(localContractAddress, remoteEid) + const localUlnConfig = await ethers.getContractAt(ulnConfigDeployment.abi, localSendLibrary) + const [ulnConfigStruct, outboundConfigStruct] = await localUlnConfig.getUlnAndOutboundConfig(localContractAddress, remoteEid) - if (sendVersion !== receiveVersion) { - const receiveLibraryAddress = receiveVersion === 0 ? await endpoint.defaultReceiveLibraryAddress() : appConfig.receiveLibraryAddress - receiveLibrary = await hre.ethers.getContractAt(MESSAGING_LIBRARY_ABI, receiveLibraryAddress) - } - - const remoteConfig: any[] = await Promise.all( - remoteNetworks.map(async (remoteNetwork: string) => { - if (network === remoteNetwork) return - return await getApplicationConfig(remoteNetwork, sendLibrary, receiveLibrary, contractAddress) + return { + Network: localNetwork, + OAppaddress: localContractAddress, + ...ulnConfigStruct, + ...outboundConfigStruct, + } }) ) - - console.log("Network ", network) - console.log("Application address", contractAddress) - console.log("Send version ", sendVersion) - console.log("Receive version ", receiveVersion) - console.table(remoteConfig) + console.table(configByNetwork) } + +task("getConfig", "outputs the application's Send and Receive Messaging Library versions and the config for remote networks") + .addParam("remoteNetworks", "comma separated list of remote networks") + .addOptionalParam( + "name", + "name of the deployed contract. Should be specified only if the deployment information is located in the deployments folder" + ) + .addOptionalParam("address", "the contract address") + .setAction(action) diff --git a/packages/ua-utils/src/index.ts b/packages/ua-utils/src/index.ts index 32fc8853f..b35900460 100644 --- a/packages/ua-utils/src/index.ts +++ b/packages/ua-utils/src/index.ts @@ -1 +1,2 @@ -import checkWireAllConfig from "./checkWireAllConfig" +import getDefaultConfig from "./getDefaultConfig" +import getConfig from "./getConfig"