Skip to content

Commit

Permalink
🪚👷‍♂️Removing setConfig. Refactor getConfig into getExecutorConfig & …
Browse files Browse the repository at this point in the history
…getUlnConfig
  • Loading branch information
sirarthurmoney committed Dec 13, 2023
1 parent 59be4c5 commit 5306f5d
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 50 deletions.
54 changes: 15 additions & 39 deletions packages/protocol-utils-evm/src/endpoint/sdk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,20 @@ import assert from 'assert'
import type {
IEndpoint,
IUln302,
SetConfigParam,
Uln302ExecutorConfig,
Uln302Factory,
Uln302UlnConfig,
} from '@layerzerolabs/protocol-utils'
import { formatEid, type Address, type OmniTransaction, formatOmniPoint } from '@layerzerolabs/utils'
import type { EndpointId } from '@layerzerolabs/lz-definitions'
import { ignoreZero, isZero, makeZeroAddress, type OmniContract, OmniSDK } from '@layerzerolabs/utils-evm'
import { CONFIG_TYPE_EXECUTOR, CONFIG_TYPE_ULN, Timeout } from '@layerzerolabs/protocol-utils'
import { Timeout } from '@layerzerolabs/protocol-utils'
import { defaultAbiCoder } from '@ethersproject/abi'

export const CONFIG_TYPE_EXECUTOR = 1

export const CONFIG_TYPE_ULN = 2

export class Endpoint extends OmniSDK implements IEndpoint {
constructor(
contract: OmniContract,
Expand Down Expand Up @@ -129,46 +132,19 @@ export class Endpoint extends OmniSDK implements IEndpoint {
return await this.contract.contract.receiveLibraryTimeout(receiver, srcEid)
}

async setConfig(lib: Address, params: SetConfigParam[]): Promise<OmniTransaction> {
const data = this.contract.contract.interface.encodeFunctionData('setConfig', [lib, params])

console.log({ params })

let description: string = ''
for (const param of params) {
description += `Setting ${
param.configType === CONFIG_TYPE_EXECUTOR ? 'executor' : 'uln'
} config for endpoint ${formatEid(param.eid)}. `
}

return {
...this.createTransaction(data),
description: description,
}
async getExecutorConfig(oapp: Address, lib: Address, eid: EndpointId): Promise<Uln302ExecutorConfig> {
const encodedExecutorBytes = await this.contract.contract.getConfig(oapp, lib, eid, CONFIG_TYPE_EXECUTOR)
const [maxMessageSize, executor] = defaultAbiCoder.decode(['uint32', 'address'], encodedExecutorBytes)
return { maxMessageSize, executor }
}

async getConfig(
oapp: Address,
lib: Address,
eid: EndpointId,
configType: number
): Promise<Uln302ExecutorConfig | Uln302UlnConfig> {
assert(
configType === CONFIG_TYPE_EXECUTOR || configType === CONFIG_TYPE_ULN,
`configType invalid ${configType}`
async getUlnConfig(oapp: Address, lib: Address, eid: EndpointId): Promise<Uln302UlnConfig> {
const encodedUlnBytes = await this.contract.contract.getConfig(oapp, lib, eid, CONFIG_TYPE_ULN)
const [confirmations, , , optionalDVNThreshold, requiredDVNs, optionalDVNs] = defaultAbiCoder.decode(
['tuple(uint64,uint8,uint8,uint8,address[],address[])'],
encodedUlnBytes
)
if (configType === CONFIG_TYPE_EXECUTOR) {
const encodedExecutorBytes = await this.contract.contract.getConfig(oapp, lib, eid, configType)
const [maxMessageSize, executor] = defaultAbiCoder.decode(['uint32', 'address'], encodedExecutorBytes)
return { maxMessageSize, executor }
} else {
const encodedUlnBytes = await this.contract.contract.getConfig(oapp, lib, eid, configType)
const [confirmations, , , optionalDVNThreshold, requiredDVNs, optionalDVNs] = defaultAbiCoder.decode(
['tuple(uint64,uint8,uint8,uint8,address[],address[])'],
encodedUlnBytes
)
return { confirmations, optionalDVNThreshold, requiredDVNs, optionalDVNs }
}
return { confirmations, optionalDVNThreshold, requiredDVNs, optionalDVNs }
}

isRegisteredLibrary(lib: Address): Promise<boolean> {
Expand Down
10 changes: 3 additions & 7 deletions packages/protocol-utils/src/endpoint/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,9 @@ export interface IEndpoint extends IOmniSDK {
setReceiveLibrary(eid: EndpointId, newLib: Address, gracePeriod: number): Promise<OmniTransaction>
setReceiveLibraryTimeout(eid: EndpointId, newLib: Address, expiry: number): Promise<OmniTransaction>

setConfig(lib: Address, params: SetConfigParam[]): Promise<OmniTransaction>
getConfig(
oapp: Address,
lib: Address,
eid: EndpointId,
configType: number
): Promise<Uln302ExecutorConfig | Uln302UlnConfig>
getExecutorConfig(oapp: Address, lib: Address, eid: EndpointId): Promise<Uln302ExecutorConfig>

getUlnConfig(oapp: Address, lib: Address, eid: EndpointId): Promise<Uln302UlnConfig>
}

export interface SetConfigParam {
Expand Down
4 changes: 0 additions & 4 deletions packages/protocol-utils/src/uln302/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,6 @@ export interface IUln302 extends IOmniSDK {
setDefaultUlnConfig(eid: EndpointId, config: Uln302UlnConfig): Promise<OmniTransaction>
}

export const CONFIG_TYPE_EXECUTOR = 1

export const CONFIG_TYPE_ULN = 2

export interface Uln302ExecutorConfig {
maxMessageSize: number
executor: string
Expand Down

0 comments on commit 5306f5d

Please sign in to comment.