Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🚧 adding getOAppConfig #74

Merged
merged 23 commits into from
Dec 9, 2023
Merged
Show file tree
Hide file tree
Changes from 18 commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
cfadbf5
wip testing task
sirarthurmoney Dec 2, 2023
0a2638f
Merge branch 'main' into getDefaultConfigV2
sirarthurmoney Dec 5, 2023
0daa21c
Merge branch 'main' into getDefaultConfigV2
sirarthurmoney Dec 6, 2023
52932f0
tested and working getDefaultConfig task
sirarthurmoney Dec 6, 2023
c5c7460
Merge branch 'main' into getDefaultConfigV2
sirarthurmoney Dec 6, 2023
df55d5a
updating lint
sirarthurmoney Dec 6, 2023
b2882ad
removing console logs
sirarthurmoney Dec 6, 2023
c05f5c5
chore: Small adjustments
janjakubnanista Dec 6, 2023
4749e5b
🧹 clean up
sirarthurmoney Dec 6, 2023
0104051
Use SDKs to pull the ULN302 configs
janjakubnanista Dec 6, 2023
07067e7
updating task and unit test
sirarthurmoney Dec 7, 2023
825d60f
Merge branch 'main' into getDefaultConfigV2
sirarthurmoney Dec 7, 2023
7e4e969
updating unit test
sirarthurmoney Dec 7, 2023
3401721
Refactoring getDefaultConfig logic into getConfig. Adding in getOAppC…
sirarthurmoney Dec 7, 2023
372e87c
Merge branch 'main' into getDefaultConfigV2
sirarthurmoney Dec 7, 2023
e833eb9
refactoring getOAppConfig and getDefaultConfig tasks
sirarthurmoney Dec 8, 2023
3452f84
Merge branch 'main' into getOAppConfig
sirarthurmoney Dec 8, 2023
e018306
Merge branch 'main' into getOAppConfig
sirarthurmoney Dec 8, 2023
47cf99b
adding in getSendLibrary and getReceiveLibrary to IEndpoint
sirarthurmoney Dec 9, 2023
0c04461
Merge branch 'main' into getOAppConfig
sirarthurmoney Dec 9, 2023
11bdf49
refactor unit test
sirarthurmoney Dec 9, 2023
28e7c71
Merge branch 'main' into getOAppConfig
sirarthurmoney Dec 9, 2023
97fd102
adding in constants for task names
sirarthurmoney Dec 9, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)
}

sirarthurmoney marked this conversation as resolved.
Show resolved Hide resolved
async setDefaultReceiveLibrary(
eid: EndpointId,
lib: string | null | undefined,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,12 @@ describe('task: getDefaultConfig', () => {
const networks = Object.keys(hre.userConfig.networks ?? {})
const getDefaultConfigTask = await hre.run('getDefaultConfig', { 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 })

Expand Down
61 changes: 61 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,61 @@
import { describe } from 'mocha'
import { defaultExecutorConfig, defaultUlnConfig, setupDefaultEndpoint } from '../__utils__/endpoint'
import { createContractFactory, getEidForNetworkName } from '@layerzerolabs/utils-evm-hardhat'
import hre from 'hardhat'
import { expect, assert } from 'chai'
import { AddressZero } from '@ethersproject/constants'

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('getOAppConfig', {
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 })

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

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

// verify receiveUln
expect(defaultConfig.receiveUlnConfig.confirmations.toString()).to.eql(
defaultUlnConfig.confirmations.toString()
)
expect(defaultConfig.receiveUlnConfig.optionalDVNThreshold).to.eql(
defaultUlnConfig.optionalDVNThreshold
)
expect(defaultConfig.receiveUlnConfig.requiredDVNs).to.eql(defaultUlnConfig.requiredDVNs)
expect(defaultConfig.receiveUlnConfig.optionalDVNs).to.eql(defaultUlnConfig.optionalDVNs)
}
}
})

// TODO - app specific configuration testing
// it('should return app specific configurations', async () => {
// })
})
50 changes: 0 additions & 50 deletions packages/ua-utils-evm-hardhat/src/tasks/getConfig.ts

This file was deleted.

87 changes: 9 additions & 78 deletions packages/ua-utils-evm-hardhat/src/tasks/getDefaultConfig.ts
Original file line number Diff line number Diff line change
@@ -1,48 +1,27 @@
import { ActionType } from 'hardhat/types'
import { task } from 'hardhat/config'
import { createConnectedContractFactory, getEidForNetworkName } from '@layerzerolabs/utils-evm-hardhat'
import { Endpoint, Uln302 } from '@layerzerolabs/protocol-utils-evm'
import { getReceiveConfig, getSendConfig, printConsoleTable } from '@/utils/taskHelpers'

interface TaskArgs {
networks: string
}

export const getDefaultConfig: ActionType<TaskArgs> = async (taskArgs) => {
const networks = new Set(taskArgs.networks.split(','))
const contractFactory = createConnectedContractFactory()
const configs: Record<string, Record<string, unknown>> = {}

for (const localNetworkName of networks) {
const localEid = getEidForNetworkName(localNetworkName)
const localEndpointSDK = new Endpoint(await contractFactory({ eid: localEid, contractName: 'EndpointV2' }))

configs[localNetworkName] = {}

for (const remoteNetworkName of networks) {
if (remoteNetworkName === localNetworkName) continue

const remoteEid = getEidForNetworkName(remoteNetworkName)

// First we get the SDK for the local send library
const defaultSendLibrary = await localEndpointSDK.defaultSendLibrary(remoteEid)
const localSendUlnSDK = new Uln302(
await contractFactory({ eid: localEid, contractName: 'SendUln302', address: defaultSendLibrary })
)

// Then we get the SDK for the local receive library
const defaultReceiveLibrary = await localEndpointSDK.defaultReceiveLibrary(remoteEid)
const localReceiveUlnSDK = new Uln302(
await contractFactory({ eid: localEid, contractName: 'ReceiveUln302', address: defaultReceiveLibrary })
const [sendLibrary, sendUlnConfig, sendExecutorConfig] = await getSendConfig(
localNetworkName,
remoteNetworkName
)

// Now let's get the configs
const sendUlnConfig = await localSendUlnSDK.getUlnConfig(remoteEid)
const sendExecutorConfig = await localSendUlnSDK.getExecutorConfig(remoteEid)
const receiveUlnConfig = await localReceiveUlnSDK.getUlnConfig(remoteEid)
const [receiveLibrary, receiveUlnConfig] = await getReceiveConfig(localNetworkName, remoteNetworkName)

configs[localNetworkName][remoteNetworkName] = {
defaultSendLibrary: defaultSendLibrary,
defaultReceiveLibrary: defaultReceiveLibrary,
defaultSendLibrary: sendLibrary,
defaultReceiveLibrary: receiveLibrary,
sendUlnConfig,
sendExecutorConfig,
receiveUlnConfig,
Expand All @@ -51,8 +30,8 @@ export const getDefaultConfig: ActionType<TaskArgs> = async (taskArgs) => {
printConsoleTable(
localNetworkName,
remoteNetworkName,
defaultSendLibrary,
defaultReceiveLibrary,
sendLibrary,
receiveLibrary,
sendUlnConfig,
sendExecutorConfig,
receiveUlnConfig
Expand All @@ -68,51 +47,3 @@ task(
)
.addParam('networks', 'comma separated list of networks')
.setAction(getDefaultConfig)

const printConsoleTable = (
localNetworkName: string,
remoteNetworkName: string,
defaultSendLibrary: string,
defaultReceiveLibrary: string,
sendUlnConfig: Record<any, any>,
sendExecutorConfig: Record<any, any>,
receiveUlnConfig: Record<any, any>
) => {
const defaultLibraryTable = {
network: localNetworkName,
remoteNetwork: remoteNetworkName,
defaultSendLibrary: defaultSendLibrary,
defaultReceiveLibrary: defaultReceiveLibrary,
}

const sendUln = {
maxMessageSize: sendExecutorConfig.maxMessageSize,
executor: sendExecutorConfig.executor,
confirmations: parseInt(sendUlnConfig.confirmations.toString()),
optionalDVNThreshold: sendUlnConfig.optionalDVNThreshold,
requiredDVNs: sendUlnConfig.requiredDVNs,
optionalDVNs: sendUlnConfig.optionalDVNs,
}

const receiveUln = {
confirmations: parseInt(receiveUlnConfig.confirmations.toString()),
optionalDVNThreshold: receiveUlnConfig.optionalDVNThreshold,
requiredDVNs: receiveUlnConfig.requiredDVNs,
optionalDVNs: receiveUlnConfig.optionalDVNs,
}

const sendUlnConfigTable = {
sendUln: sendUln,
}

const receiveUlnConfigTable = {
receiveUln: receiveUln,
}

console.log(`************************************************`)
console.log(`${localNetworkName.toUpperCase()}`)
console.log(`************************************************`)
console.table(defaultLibraryTable)
console.table(sendUlnConfigTable)
console.table(receiveUlnConfigTable)
}
60 changes: 60 additions & 0 deletions packages/ua-utils-evm-hardhat/src/tasks/getOAppConfig.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
import { ActionType } from 'hardhat/types'
import { task } from 'hardhat/config'
import { getReceiveConfig, getSendConfig, printConsoleTable } from '@/utils/taskHelpers'
import assert from 'assert'

interface TaskArgs {
networks: string
addresses: string
}

export const getOAppConfig: ActionType<TaskArgs> = async (taskArgs, ...args) => {
const networks = taskArgs.networks.split(',')
const addresses = taskArgs.addresses.split(',')
assert(networks.length === addresses.length, 'Passed in networks must match length of passed in addresses.')
const configs: Record<string, Record<string, unknown>> = {}

for (const [index, localNetworkName] of networks.entries()) {
configs[localNetworkName] = {}
for (const remoteNetworkName of networks) {
if (remoteNetworkName === localNetworkName) continue
const [sendLibrary, sendUlnConfig, sendExecutorConfig] = await getSendConfig(
localNetworkName,
remoteNetworkName,
addresses[index]
)
const [receiveLibrary, receiveUlnConfig] = await getReceiveConfig(
localNetworkName,
remoteNetworkName,
addresses[index]
)

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

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

task(
'getOAppConfig',
'outputs the default Send and Receive Messaging Library versions and the default application config'
)
.addParam('networks', 'comma separated list of networks')
.addParam('addresses', 'comma separated list of addresses')
.setAction(getOAppConfig)
1 change: 1 addition & 0 deletions packages/ua-utils-evm-hardhat/src/tasks/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
import './getDefaultConfig'
import './getOAppConfig'
Loading
Loading