diff --git a/.changeset/heavy-cats-sin.md b/.changeset/heavy-cats-sin.md new file mode 100644 index 000000000..b28c56a09 --- /dev/null +++ b/.changeset/heavy-cats-sin.md @@ -0,0 +1,6 @@ +--- +"@layerzerolabs/ua-devtools-evm-hardhat-test": patch +"@layerzerolabs/ua-devtools-evm-hardhat": patch +--- + +Adding in get executor config task diff --git a/packages/ua-devtools-evm-hardhat/src/constants/tasks.ts b/packages/ua-devtools-evm-hardhat/src/constants/tasks.ts index e186cf4c1..9a8fcedfd 100644 --- a/packages/ua-devtools-evm-hardhat/src/constants/tasks.ts +++ b/packages/ua-devtools-evm-hardhat/src/constants/tasks.ts @@ -3,6 +3,7 @@ export const TASK_LZ_ERRORS_LIST = 'lz:errors:list' export const TASK_LZ_OAPP_WIRE = 'lz:oapp:wire' export const TASK_LZ_OAPP_CONFIG_GET_DEFAULT = 'lz:oapp:config:get:default' +export const TASK_LZ_OAPP_CONFIG_GET_EXECUTOR = 'lz:oapp:config:get:executor' export const TASK_LZ_OAPP_CONFIG_GET = 'lz:oapp:config:get' export const TASK_LZ_OAPP_CONFIG_CHECK = 'lz:oapp:config:check' export const TASK_LZ_OAPP_CONFIG_INIT = 'lz:oapp:config:init' diff --git a/packages/ua-devtools-evm-hardhat/src/tasks/oapp/config.get.executor.ts b/packages/ua-devtools-evm-hardhat/src/tasks/oapp/config.get.executor.ts new file mode 100644 index 000000000..1dd31e453 --- /dev/null +++ b/packages/ua-devtools-evm-hardhat/src/tasks/oapp/config.get.executor.ts @@ -0,0 +1,52 @@ +import { ActionType } from 'hardhat/types' +import { task } from 'hardhat/config' +import { printRecord } from '@layerzerolabs/io-devtools' +import { getExecutorDstConfig } from '@/utils/taskHelpers' +import { TASK_LZ_OAPP_CONFIG_GET_EXECUTOR } from '@/constants' +import { setDefaultLogLevel } from '@layerzerolabs/io-devtools' +import { getEidsByNetworkName, types } from '@layerzerolabs/devtools-evm-hardhat' + +interface TaskArgs { + logLevel?: string + networks?: string[] +} + +export const getExecutorConfig: ActionType = async ( + { logLevel = 'info', networks: networksArgument }, + hre +) => { + // We'll set the global logging level to get as much info as needed + setDefaultLogLevel(logLevel) + + const networks = + networksArgument ?? + Object.entries(getEidsByNetworkName(hre)).flatMap(([networkName, eid]) => (eid == null ? [] : [networkName])) + + const configs: Record> = {} + for (const localNetworkName of networks) { + configs[localNetworkName] = {} + for (const remoteNetworkName of networks) { + if (remoteNetworkName === localNetworkName) continue + const executorDstConfig = await getExecutorDstConfig(localNetworkName, remoteNetworkName) + + configs[localNetworkName]![remoteNetworkName] = executorDstConfig + + console.log( + printRecord({ + localNetworkName, + remoteNetworkName, + executorDstConfig, + }) + ) + } + } + return configs +} + +task( + TASK_LZ_OAPP_CONFIG_GET_EXECUTOR, + 'Outputs the Executors destination configurations including the native max cap amount ' +) + .addParam('networks', 'Comma-separated list of networks', undefined, types.networks, true) + .addParam('logLevel', 'Logging level. One of: error, warn, info, verbose, debug, silly', 'info', types.logLevel) + .setAction(getExecutorConfig) diff --git a/packages/ua-devtools-evm-hardhat/src/tasks/oapp/index.ts b/packages/ua-devtools-evm-hardhat/src/tasks/oapp/index.ts index c6543304e..4108f919b 100644 --- a/packages/ua-devtools-evm-hardhat/src/tasks/oapp/index.ts +++ b/packages/ua-devtools-evm-hardhat/src/tasks/oapp/index.ts @@ -1,5 +1,6 @@ import './wire' import './config.check' import './config.get.default' +import './config.get.executor' import './config.get' import './config.init' diff --git a/packages/ua-devtools-evm-hardhat/src/utils/taskHelpers.ts b/packages/ua-devtools-evm-hardhat/src/utils/taskHelpers.ts index b01fd5321..50635c7db 100644 --- a/packages/ua-devtools-evm-hardhat/src/utils/taskHelpers.ts +++ b/packages/ua-devtools-evm-hardhat/src/utils/taskHelpers.ts @@ -1,12 +1,12 @@ import { Address } from '@layerzerolabs/devtools' -import { Timeout, Uln302ExecutorConfig, Uln302UlnConfig } from '@layerzerolabs/protocol-devtools' +import { ExecutorDstConfig, Timeout, Uln302ExecutorConfig, Uln302UlnConfig } from '@layerzerolabs/protocol-devtools' import { createConnectedContractFactory, getEidForNetworkName, OmniGraphBuilderHardhat, } from '@layerzerolabs/devtools-evm-hardhat' import { createConfigLoader, printJson } from '@layerzerolabs/io-devtools' -import { createEndpointFactory } from '@layerzerolabs/protocol-devtools-evm' +import { createEndpointFactory, createExecutorFactory } from '@layerzerolabs/protocol-devtools-evm' import { OAppOmniGraphHardhat, OAppOmniGraphHardhatSchema } from '@/oapp' import { resolve } from 'path' import { OAppOmniGraph } from '@layerzerolabs/ua-devtools' @@ -146,6 +146,18 @@ export async function getReceiveConfig( return [receiveLibrary, receiveUlnConfig, receiveLibraryTimeout] } +export async function getExecutorDstConfig( + localNetworkName: string, + remoteNetworkName: string +): Promise { + const localEid = getEidForNetworkName(localNetworkName) + const remoteEid = getEidForNetworkName(remoteNetworkName) + const contractFactory = createConnectedContractFactory() + const executorFactory = createExecutorFactory(contractFactory) + const localExecutorSDK = await executorFactory({ eid: localEid, contractName: 'Executor' }) + return await localExecutorSDK.getDstConfig(remoteEid) +} + export async function validateAndTransformOappConfig(oappConfigPath: string, logger: Logger): Promise { /** * Now we create our config loader diff --git a/tests/ua-devtools-evm-hardhat-test/test/__utils__/endpoint.ts b/tests/ua-devtools-evm-hardhat-test/test/__utils__/endpoint.ts index 8c690fca4..b4fb5e921 100644 --- a/tests/ua-devtools-evm-hardhat-test/test/__utils__/endpoint.ts +++ b/tests/ua-devtools-evm-hardhat-test/test/__utils__/endpoint.ts @@ -73,7 +73,7 @@ const defaultPriceData: PriceData = { gasPerByte: 1, } -const defaultExecutorDstConfig: ExecutorDstConfig = { +export const defaultExecutorDstConfig: ExecutorDstConfig = { baseGas: BigInt(200_000), multiplierBps: BigInt(0), floorMarginUSD: BigInt(0), diff --git a/tests/ua-devtools-evm-hardhat-test/test/task/oapp/config.get.executor.test.ts b/tests/ua-devtools-evm-hardhat-test/test/task/oapp/config.get.executor.test.ts new file mode 100644 index 000000000..ad68ba3d7 --- /dev/null +++ b/tests/ua-devtools-evm-hardhat-test/test/task/oapp/config.get.executor.test.ts @@ -0,0 +1,34 @@ +import { defaultExecutorDstConfig, deployEndpoint, setupDefaultEndpoint } from '../../__utils__/endpoint' +import hre from 'hardhat' +import { TASK_LZ_OAPP_CONFIG_GET_EXECUTOR } from '@layerzerolabs/ua-devtools-evm-hardhat' + +describe(`task ${TASK_LZ_OAPP_CONFIG_GET_EXECUTOR}`, () => { + beforeEach(async () => { + await deployEndpoint() + await setupDefaultEndpoint() + }) + + it('should return destination executor configurations with passed in networks', async () => { + const networks = ['britney', 'vengaboys', 'tango'] + const executorConfigReturnData = await hre.run(TASK_LZ_OAPP_CONFIG_GET_EXECUTOR, { networks }) + for (const localNetwork of networks) { + for (const remoteNetwork of networks) { + if (localNetwork === remoteNetwork) continue + const executorConfig = executorConfigReturnData[localNetwork][remoteNetwork] + expect(executorConfig).toEqual(defaultExecutorDstConfig) + } + } + }) + + it('should return destination executor configurations with no input', async () => { + const executorConfigReturnData = await hre.run(TASK_LZ_OAPP_CONFIG_GET_EXECUTOR, {}) + const networks = ['britney', 'vengaboys', 'tango'] + for (const localNetwork of networks) { + for (const remoteNetwork of networks) { + if (localNetwork === remoteNetwork) continue + const executorConfig = executorConfigReturnData[localNetwork][remoteNetwork] + expect(executorConfig).toEqual(defaultExecutorDstConfig) + } + } + }) +})