Skip to content

Commit

Permalink
adding getOAppConfig
Browse files Browse the repository at this point in the history
Co-authored-by: Ján Jakub Naništa <[email protected]>
  • Loading branch information
sirarthurmoney and janjakubnanista authored Dec 9, 2023
1 parent 63231ac commit 90363c7
Show file tree
Hide file tree
Showing 12 changed files with 277 additions and 194 deletions.
8 changes: 8 additions & 0 deletions packages/protocol-utils-evm/src/endpoint/sdk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,14 @@ export class Endpoint implements IEndpoint {
return ignoreZero(await this.contract.contract.defaultReceiveLibrary(eid))
}

async getSendLibrary(sender: Address, dstEid: EndpointId): Promise<string | undefined> {
return ignoreZero(await this.contract.contract.getSendLibrary(sender, dstEid))
}

async getReceiveLibrary(receiver: Address, srcEid: EndpointId): Promise<[string | undefined, boolean]> {
return await this.contract.contract.getReceiveLibrary(receiver, srcEid)
}

async setDefaultReceiveLibrary(
eid: EndpointId,
lib: string | null | undefined,
Expand Down
3 changes: 3 additions & 0 deletions packages/protocol-utils/src/endpoint/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ export interface IEndpoint {

isRegisteredLibrary(lib: Address): Promise<boolean>
registerLibrary(lib: Address): Promise<OmniTransaction>

getSendLibrary(sender: Address, dstEid: EndpointId): Promise<string | undefined>
getReceiveLibrary(receiver: Address, srcEid: EndpointId): Promise<[string | undefined, boolean]>
}

export interface EndpointEdgeConfig {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { defaultExecutorConfig, defaultUlnConfig, setupDefaultEndpoint } from '../__utils__/endpoint'
import { createContractFactory, getEidForNetworkName } from '@layerzerolabs/utils-evm-hardhat'
import hre from 'hardhat'
import { TASK_LZ_GET_DEFAULT_CONFIG } from '@layerzerolabs/ua-utils-evm-hardhat'

describe('task: getDefaultConfig', () => {
beforeEach(async () => {
Expand All @@ -9,42 +10,22 @@ describe('task: getDefaultConfig', () => {

it('should return default configurations', async () => {
const networks = Object.keys(hre.userConfig.networks ?? {})
const getDefaultConfigTask = await hre.run('getDefaultConfig', { networks: networks.toString() })
const getDefaultConfigTask = await hre.run(TASK_LZ_GET_DEFAULT_CONFIG, { networks: networks.toString() })
const contractFactory = createContractFactory()

for (const localNetwork of networks) {
const localEid = getEidForNetworkName(localNetwork)

for (const remoteNetwork of networks) {
if (localNetwork === remoteNetwork) continue

const defaultConfig = getDefaultConfigTask[localNetwork][remoteNetwork]

const sendUln302 = await contractFactory({ contractName: 'SendUln302', eid: localEid })
const receiveUln302 = await contractFactory({ contractName: 'ReceiveUln302', eid: localEid })

// verify defaultSendLibrary & defaultReceiveLibrary
expect(defaultConfig.defaultSendLibrary).toEqual(sendUln302.contract.address)
expect(defaultConfig.defaultReceiveLibrary).toEqual(receiveUln302.contract.address)

// verify sendUln
expect(defaultConfig.sendExecutorConfig.maxMessageSize).toEqual(defaultExecutorConfig.maxMessageSize)
expect(defaultConfig.sendExecutorConfig.executor).toEqual(defaultExecutorConfig.executor)
expect(defaultConfig.sendUlnConfig.confirmations.toString()).toEqual(
defaultUlnConfig.confirmations.toString()
)
expect(defaultConfig.sendUlnConfig.optionalDVNThreshold).toEqual(defaultUlnConfig.optionalDVNThreshold)
expect(defaultConfig.sendUlnConfig.requiredDVNs).toEqual(defaultUlnConfig.requiredDVNs)
expect(defaultConfig.sendUlnConfig.optionalDVNs).toEqual(defaultUlnConfig.optionalDVNs)

// verify receiveUln
expect(defaultConfig.receiveUlnConfig.confirmations.toString()).toEqual(
defaultUlnConfig.confirmations.toString()
)
expect(defaultConfig.receiveUlnConfig.optionalDVNThreshold).toEqual(
defaultUlnConfig.optionalDVNThreshold
)
expect(defaultConfig.receiveUlnConfig.requiredDVNs).toEqual(defaultUlnConfig.requiredDVNs)
expect(defaultConfig.receiveUlnConfig.optionalDVNs).toEqual(defaultUlnConfig.optionalDVNs)
expect(defaultConfig.sendExecutorConfig).toEqual(defaultExecutorConfig)
expect(defaultConfig.sendUlnConfig).toEqual(defaultUlnConfig)
expect(defaultConfig.receiveUlnConfig).toEqual(defaultUlnConfig)
}
}
})
Expand Down
41 changes: 41 additions & 0 deletions packages/ua-utils-evm-hardhat-test/test/task/getOAppConfig.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import { defaultExecutorConfig, defaultUlnConfig, setupDefaultEndpoint } from '../__utils__/endpoint'
import { createContractFactory, getEidForNetworkName } from '@layerzerolabs/utils-evm-hardhat'
import hre from 'hardhat'
import { AddressZero } from '@ethersproject/constants'
import { TASK_LZ_GET_OAPP_CONFIG } from '@layerzerolabs/ua-utils-evm-hardhat'

describe('task: getOAppConfig', () => {
beforeEach(async () => {
await setupDefaultEndpoint()
})

it('should return app default configurations when addresses are not oapps', async () => {
const networks = Object.keys(hre.userConfig.networks ?? {})
const addresses = new Array(networks.length).fill(AddressZero).toString()
const getDefaultConfigTask = await hre.run(TASK_LZ_GET_OAPP_CONFIG, {
networks: networks.toString(),
addresses: addresses.toString(),
})
const contractFactory = createContractFactory()
for (const localNetwork of networks) {
const localEid = getEidForNetworkName(localNetwork)
for (const remoteNetwork of networks) {
if (localNetwork === remoteNetwork) continue

const defaultConfig = getDefaultConfigTask[localNetwork][remoteNetwork]
const sendUln302 = await contractFactory({ contractName: 'SendUln302', eid: localEid })
const receiveUln302 = await contractFactory({ contractName: 'ReceiveUln302', eid: localEid })

expect(defaultConfig.defaultSendLibrary).toEqual(sendUln302.contract.address)
expect(defaultConfig.defaultReceiveLibrary).toEqual(receiveUln302.contract.address)
expect(defaultConfig.sendExecutorConfig).toEqual(defaultExecutorConfig)
expect(defaultConfig.sendUlnConfig).toEqual(defaultUlnConfig)
expect(defaultConfig.receiveUlnConfig).toEqual(defaultUlnConfig)
}
}
})

// TODO - app specific configuration testing
// it('should return app specific configurations', async () => {
// })
})
2 changes: 2 additions & 0 deletions packages/ua-utils-evm-hardhat/src/constants/tasks.ts
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
export const TASK_LZ_WIRE_OAPP = 'lz:oapp:wire'
export const TASK_LZ_GET_DEFAULT_CONFIG = 'lz:oapp:getDefaultConfig'
export const TASK_LZ_GET_OAPP_CONFIG = 'lz:oapp:getOAppConfig'
50 changes: 0 additions & 50 deletions packages/ua-utils-evm-hardhat/src/tasks/getConfig.ts

This file was deleted.

118 changes: 0 additions & 118 deletions packages/ua-utils-evm-hardhat/src/tasks/getDefaultConfig.ts

This file was deleted.

1 change: 0 additions & 1 deletion packages/ua-utils-evm-hardhat/src/tasks/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
import './oapp'
import './getDefaultConfig'
50 changes: 50 additions & 0 deletions packages/ua-utils-evm-hardhat/src/tasks/oapp/getDefaultConfig.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import { ActionType } from 'hardhat/types'
import { task } from 'hardhat/config'
import { getReceiveConfig, getSendConfig, printConsoleTable } from '@/utils/taskHelpers'
import { TASK_LZ_GET_DEFAULT_CONFIG } from '@/constants'

interface TaskArgs {
networks: string
}

export const getDefaultConfig: ActionType<TaskArgs> = async (taskArgs) => {
const networks = new Set(taskArgs.networks.split(','))
const configs: Record<string, Record<string, unknown>> = {}
for (const localNetworkName of networks) {
configs[localNetworkName] = {}
for (const remoteNetworkName of networks) {
if (remoteNetworkName === localNetworkName) continue
const [sendLibrary, sendUlnConfig, sendExecutorConfig] = await getSendConfig(
localNetworkName,
remoteNetworkName
)
const [receiveLibrary, receiveUlnConfig] = await getReceiveConfig(localNetworkName, remoteNetworkName)

configs[localNetworkName][remoteNetworkName] = {
defaultSendLibrary: sendLibrary,
defaultReceiveLibrary: receiveLibrary,
sendUlnConfig,
sendExecutorConfig,
receiveUlnConfig,
}

printConsoleTable(
localNetworkName,
remoteNetworkName,
sendLibrary,
receiveLibrary,
sendUlnConfig,
sendExecutorConfig,
receiveUlnConfig
)
}
}
return configs
}

task(
TASK_LZ_GET_DEFAULT_CONFIG,
'outputs the default Send and Receive Messaging Library versions and the default application config'
)
.addParam('networks', 'comma separated list of networks')
.setAction(getDefaultConfig)
Loading

0 comments on commit 90363c7

Please sign in to comment.