diff --git a/packages/protocol-utils-evm/src/endpoint/factory.ts b/packages/protocol-utils-evm/src/endpoint/factory.ts new file mode 100644 index 000000000..2e1d14815 --- /dev/null +++ b/packages/protocol-utils-evm/src/endpoint/factory.ts @@ -0,0 +1,14 @@ +import pMemoize from 'p-memoize' +import { OmniContractFactory } from '@layerzerolabs/utils-evm' +import { Endpoint } from './sdk' +import { EndpointFactory } from '@layerzerolabs/protocol-utils' + +/** + * Syntactic sugar that creates an instance of EVM `Endpoint` SDK + * based on an `OmniPoint` with help of an `OmniContractFactory` + * + * @param {OmniContractFactory} contractFactory + * @returns {EndpointFactory} + */ +export const createEndpointFactory = (contractFactory: OmniContractFactory): EndpointFactory => + pMemoize(async (point) => new Endpoint(await contractFactory(point))) diff --git a/packages/protocol-utils-evm/src/endpoint/index.ts b/packages/protocol-utils-evm/src/endpoint/index.ts index 7db67b18a..244dbb9aa 100644 --- a/packages/protocol-utils-evm/src/endpoint/index.ts +++ b/packages/protocol-utils-evm/src/endpoint/index.ts @@ -1 +1,2 @@ +export * from './factory' export * from './sdk' diff --git a/packages/protocol-utils-evm/src/endpoint/sdk.ts b/packages/protocol-utils-evm/src/endpoint/sdk.ts index 6c5e5a562..51f7c9fa1 100644 --- a/packages/protocol-utils-evm/src/endpoint/sdk.ts +++ b/packages/protocol-utils-evm/src/endpoint/sdk.ts @@ -6,7 +6,7 @@ import { ignoreZero, makeZeroAddress, omniContractToPoint, type OmniContract } f export class Endpoint implements IEndpoint { constructor(public readonly contract: OmniContract) {} - async defaultReceiveLibrary(eid: EndpointId): Promise { + async getDefaultReceiveLibrary(eid: EndpointId): Promise { return ignoreZero(await this.contract.contract.defaultReceiveLibrary(eid)) } @@ -35,7 +35,7 @@ export class Endpoint implements IEndpoint { } } - async defaultSendLibrary(eid: EndpointId): Promise { + async getDefaultSendLibrary(eid: EndpointId): Promise { return ignoreZero(await this.contract.contract.defaultSendLibrary(eid)) } diff --git a/packages/protocol-utils/src/endpoint/config.ts b/packages/protocol-utils/src/endpoint/config.ts index 78d7a87cd..3277c53dc 100644 --- a/packages/protocol-utils/src/endpoint/config.ts +++ b/packages/protocol-utils/src/endpoint/config.ts @@ -14,7 +14,7 @@ export const configureEndpointDefaultReceiveLibraries: EndpointConfigurator = as await Promise.all( graph.connections.map(async ({ vector: { from, to }, config }): Promise => { const sdk = await createSdk(from) - const address = await sdk.defaultReceiveLibrary(to.eid) + const address = await sdk.getDefaultReceiveLibrary(to.eid) // If the library is already set as default, do nothing if (config.defaultReceiveLibrary === address) return [] @@ -40,7 +40,7 @@ export const configureEndpointDefaultSendLibraries: EndpointConfigurator = async await Promise.all( graph.connections.map(async ({ vector: { from, to }, config }): Promise => { const sdk = await createSdk(from) - const address = await sdk.defaultSendLibrary(to.eid) + const address = await sdk.getDefaultSendLibrary(to.eid) // If the library is already set as default, do nothing if (config.defaultSendLibrary === address) return [] diff --git a/packages/protocol-utils/src/endpoint/types.ts b/packages/protocol-utils/src/endpoint/types.ts index 4ece6a499..93b80c4f9 100644 --- a/packages/protocol-utils/src/endpoint/types.ts +++ b/packages/protocol-utils/src/endpoint/types.ts @@ -2,14 +2,14 @@ import type { Address, OmniGraph, OmniPointBasedFactory, OmniTransaction } from import type { EndpointId } from '@layerzerolabs/lz-definitions' export interface IEndpoint { - defaultReceiveLibrary(eid: EndpointId): Promise
+ getDefaultReceiveLibrary(eid: EndpointId): Promise
setDefaultReceiveLibrary( eid: EndpointId, lib: Address | null | undefined, gracePeriod?: number ): Promise - defaultSendLibrary(eid: EndpointId): Promise
+ getDefaultSendLibrary(eid: EndpointId): Promise
setDefaultSendLibrary(eid: EndpointId, lib: Address | null | undefined): Promise isRegisteredLibrary(lib: Address): Promise @@ -27,4 +27,4 @@ export interface EndpointEdgeConfig { export type EndpointOmniGraph = OmniGraph -export type EndpointFactory = OmniPointBasedFactory +export type EndpointFactory = OmniPointBasedFactory diff --git a/packages/protocol-utils/src/uln302/types.ts b/packages/protocol-utils/src/uln302/types.ts index 51d89b05f..1e59bb93f 100644 --- a/packages/protocol-utils/src/uln302/types.ts +++ b/packages/protocol-utils/src/uln302/types.ts @@ -27,4 +27,4 @@ export interface Uln302NodeConfig { export type Uln302OmniGraph = OmniGraph -export type Uln302Factory = OmniPointBasedFactory +export type Uln302Factory = OmniPointBasedFactory diff --git a/packages/ua-utils-evm-hardhat-test/test/endpoint/config.test.ts b/packages/ua-utils-evm-hardhat-test/test/endpoint/config.test.ts index 4c5c111e8..c0e549de3 100644 --- a/packages/ua-utils-evm-hardhat-test/test/endpoint/config.test.ts +++ b/packages/ua-utils-evm-hardhat-test/test/endpoint/config.test.ts @@ -34,8 +34,8 @@ describe('endpoint/config', () => { const avaxEndpointSdk = await sdkFactory(avaxEndpointPoint) // First let's check the send libraries - const ethDefaultSendLib = await ethEndpointSdk.defaultSendLibrary(avaxEndpointPoint.eid) - const avaxDefaultSendLib = await avaxEndpointSdk.defaultSendLibrary(ethEndpointPoint.eid) + const ethDefaultSendLib = await ethEndpointSdk.getDefaultSendLibrary(avaxEndpointPoint.eid) + const avaxDefaultSendLib = await avaxEndpointSdk.getDefaultSendLibrary(ethEndpointPoint.eid) const ethSendUlnPoint = omniContractToPoint(await connectedContractFactory(ethSendUln)) const avaxSendUlnPoint = omniContractToPoint(await connectedContractFactory(avaxSendUln)) @@ -44,8 +44,8 @@ describe('endpoint/config', () => { expect(avaxDefaultSendLib).toBe(avaxSendUlnPoint.address) // Then let's check the receive libraries - const ethDefaultReceiveLib = await ethEndpointSdk.defaultReceiveLibrary(avaxEndpointPoint.eid) - const avaxDefaultReceiveLib = await avaxEndpointSdk.defaultReceiveLibrary(ethEndpointPoint.eid) + const ethDefaultReceiveLib = await ethEndpointSdk.getDefaultReceiveLibrary(avaxEndpointPoint.eid) + const avaxDefaultReceiveLib = await avaxEndpointSdk.getDefaultReceiveLibrary(ethEndpointPoint.eid) const ethReceiveUlnPoint = omniContractToPoint(await connectedContractFactory(ethReceiveUln)) const avaxReceiveUlnPoint = omniContractToPoint(await connectedContractFactory(avaxReceiveUln)) diff --git a/packages/ua-utils-evm-hardhat-test/test/oapp/config.test.ts b/packages/ua-utils-evm-hardhat-test/test/oapp/config.test.ts index 67ae9aa01..8462cc4cc 100644 --- a/packages/ua-utils-evm-hardhat-test/test/oapp/config.test.ts +++ b/packages/ua-utils-evm-hardhat-test/test/oapp/config.test.ts @@ -1,14 +1,12 @@ import 'hardhat' import { configureOApp } from '@layerzerolabs/ua-utils' -import { OApp } from '@layerzerolabs/ua-utils-evm' +import { createOAppFactory } from '@layerzerolabs/ua-utils-evm' import { createConnectedContractFactory, - createContractFactory, createSignerFactory, OmniGraphBuilderHardhat, } from '@layerzerolabs/utils-evm-hardhat' import type { OmniGraphHardhat } from '@layerzerolabs/utils-evm-hardhat' -import type { OmniPoint } from '@layerzerolabs/utils' import { omniContractToPoint } from '@layerzerolabs/utils-evm' import { EndpointId } from '@layerzerolabs/lz-definitions' import { setupDefaultEndpoint } from '../__utils__/endpoint' @@ -49,9 +47,7 @@ describe('oapp/config', () => { // This is the required tooling we need to set up const contractFactory = createConnectedContractFactory() const builder = await OmniGraphBuilderHardhat.fromConfig(config) - - // This so far the only non-oneliner, a function that returns an SDK for a contract on a network - const sdkFactory = async (point: OmniPoint) => new OApp(await contractFactory(point)) + const sdkFactory = createOAppFactory(contractFactory) // This is where the configuration happens const transactions = await configureOApp(builder.graph, sdkFactory) @@ -71,12 +67,9 @@ describe('oapp/config', () => { it('should exclude setPeer transactions for peers that have been set', async () => { // This is the required tooling we need to set up - const contractFactory = createContractFactory() - const connectedContractFactory = createConnectedContractFactory(contractFactory) + const contractFactory = createConnectedContractFactory() const builder = await OmniGraphBuilderHardhat.fromConfig(config) - - // This so far the only non-oneliner, a function that returns an SDK for a contract on a network - const sdkFactory = async (point: OmniPoint) => new OApp(await connectedContractFactory(point)) + const sdkFactory = createOAppFactory(contractFactory) const ethPoint = omniContractToPoint(await contractFactory(ethContract)) const ethSdk = await sdkFactory(ethPoint) diff --git a/packages/ua-utils-evm-hardhat/package.json b/packages/ua-utils-evm-hardhat/package.json index faffe15c6..6d9de6b1f 100644 --- a/packages/ua-utils-evm-hardhat/package.json +++ b/packages/ua-utils-evm-hardhat/package.json @@ -35,6 +35,9 @@ "lint": "npx eslint '**/*.{js,ts,json}'", "test": "jest --passWithNoTests" }, + "dependencies": { + "p-memoize": "~4.0.1" + }, "devDependencies": { "@ethersproject/contracts": "^5.7.0", "@gnosis.pm/safe-core-sdk": "^2.0.0", @@ -44,6 +47,7 @@ "@layerzerolabs/io-utils": "~0.0.1", "@layerzerolabs/lz-definitions": "~1.5.70", "@layerzerolabs/ua-utils": "~0.1.0", + "@layerzerolabs/ua-utils-evm": "~0.0.1", "@layerzerolabs/utils": "~0.0.1", "@layerzerolabs/utils-evm-hardhat": "~0.0.2", "@types/jest": "^29.5.10", @@ -69,6 +73,7 @@ "@layerzerolabs/io-utils": "~0.0.1", "@layerzerolabs/lz-definitions": "~1.5.70", "@layerzerolabs/ua-utils": "~0.1.0", + "@layerzerolabs/ua-utils-evm": "~0.0.1", "@layerzerolabs/utils": "~0.0.1", "@layerzerolabs/utils-evm-hardhat": "~0.0.2", "ethers": "^5.5.2", diff --git a/packages/ua-utils-evm-hardhat/src/utils/taskHelpers.ts b/packages/ua-utils-evm-hardhat/src/utils/taskHelpers.ts index 9eaf2120f..a7ffbdb2b 100644 --- a/packages/ua-utils-evm-hardhat/src/utils/taskHelpers.ts +++ b/packages/ua-utils-evm-hardhat/src/utils/taskHelpers.ts @@ -18,7 +18,7 @@ export async function getSendConfig( if (address) { sendLibrary = await localEndpointSDK.getSendLibrary(address, remoteEid) } else { - sendLibrary = await localEndpointSDK.defaultSendLibrary(remoteEid) + sendLibrary = await localEndpointSDK.getDefaultSendLibrary(remoteEid) } const localSendUlnSDK = new Uln302( @@ -45,7 +45,7 @@ export async function getReceiveConfig( if (address) { receiveLibrary = (await localEndpointSDK.getReceiveLibrary(address, remoteEid))[0] } else { - receiveLibrary = await localEndpointSDK.defaultReceiveLibrary(remoteEid) + receiveLibrary = await localEndpointSDK.getDefaultReceiveLibrary(remoteEid) } const localReceiveUlnSDK = new Uln302( diff --git a/packages/ua-utils-evm/package.json b/packages/ua-utils-evm/package.json index 43474f4d6..4d0e928ab 100644 --- a/packages/ua-utils-evm/package.json +++ b/packages/ua-utils-evm/package.json @@ -33,6 +33,8 @@ "@ethersproject/constants": "^5.7.0", "@ethersproject/contracts": "^5.7.0", "@layerzerolabs/lz-definitions": "~1.5.70", + "@layerzerolabs/protocol-utils": "~0.0.1", + "@layerzerolabs/protocol-utils-evm": "~0.0.1", "@layerzerolabs/test-utils": "~0.0.1", "@layerzerolabs/ua-utils": "~0.1.0", "@layerzerolabs/utils-evm": "~0.0.1", @@ -48,6 +50,8 @@ }, "peerDependencies": { "@layerzerolabs/lz-definitions": "~1.5.70", + "@layerzerolabs/protocol-utils": "~0.0.1", + "@layerzerolabs/protocol-utils-evm": "~0.0.1", "@layerzerolabs/ua-utils": "~0.0.1", "@layerzerolabs/utils-evm": "~0.0.1", "zod": "^3.22.4" diff --git a/packages/ua-utils-evm/src/oapp/factory.ts b/packages/ua-utils-evm/src/oapp/factory.ts new file mode 100644 index 000000000..646730d7c --- /dev/null +++ b/packages/ua-utils-evm/src/oapp/factory.ts @@ -0,0 +1,20 @@ +import pMemoize from 'p-memoize' +import type { OAppFactory } from '@layerzerolabs/ua-utils' +import type { OmniContractFactory } from '@layerzerolabs/utils-evm' +import type { EndpointFactory } from '@layerzerolabs/protocol-utils' +import { createEndpointFactory } from '@layerzerolabs/protocol-utils-evm' +import { OApp } from './sdk' + +/** + * Syntactic sugar that creates an instance of EVM `OApp` SDK + * based on an `OmniPoint` with help of an `OmniContractFactory` + * and an (optional) `EndpointFactory` + * + * @param {OmniContractFactory} contractFactory + * @param {EndpointFactory} [endpointFactory] + * @returns {EndpointFactory} + */ +export const createOAppFactory = ( + contractFactory: OmniContractFactory, + endpointFactory: EndpointFactory = createEndpointFactory(contractFactory) +): OAppFactory => pMemoize(async (point) => new OApp(await contractFactory(point), endpointFactory)) diff --git a/packages/ua-utils-evm/src/oapp/index.ts b/packages/ua-utils-evm/src/oapp/index.ts index 7db67b18a..244dbb9aa 100644 --- a/packages/ua-utils-evm/src/oapp/index.ts +++ b/packages/ua-utils-evm/src/oapp/index.ts @@ -1 +1,2 @@ +export * from './factory' export * from './sdk' diff --git a/packages/ua-utils-evm/src/oapp/sdk.ts b/packages/ua-utils-evm/src/oapp/sdk.ts index dbcdcfe77..0d9a26a2b 100644 --- a/packages/ua-utils-evm/src/oapp/sdk.ts +++ b/packages/ua-utils-evm/src/oapp/sdk.ts @@ -1,17 +1,52 @@ import type { IOApp } from '@layerzerolabs/ua-utils' import type { Bytes32, Address, OmniTransaction } from '@layerzerolabs/utils' -import { omniContractToPoint, OmniContract, ignoreZero, makeBytes32, areBytes32Equal } from '@layerzerolabs/utils-evm' +import { + omniContractToPoint, + OmniContract, + ignoreZero, + makeBytes32, + areBytes32Equal, + isZero, + formatOmniContract, +} from '@layerzerolabs/utils-evm' import type { EndpointId } from '@layerzerolabs/lz-definitions' +import type { EndpointFactory, IEndpoint } from '@layerzerolabs/protocol-utils' export class OApp implements IOApp { - constructor(public readonly contract: OmniContract) {} + constructor( + public readonly contract: OmniContract, + private readonly endpointFactory: EndpointFactory + ) {} - async peers(eid: EndpointId): Promise { + async getEndpoint(): Promise { + let address: string + + // First we'll need the endpoint address from the contract + try { + address = await this.contract.contract.endpoint() + } catch (error) { + // We'll just wrap the error in some nice words + throw new Error(`Failed to get endpoint address for OApp ${formatOmniContract(this.contract)}: ${error}`) + } + + // We'll also do an additional check to see whether the endpoint has been set to a non-zero address + if (isZero(address)) { + throw new Error( + `Endpoint cannot be instantiated: Endpoint address has been set to a zero value for OApp ${formatOmniContract( + this.contract + )}` + ) + } + + return await this.endpointFactory({ address, eid: this.contract.eid }) + } + + async getPeer(eid: EndpointId): Promise { return ignoreZero(await this.contract.contract.peers(eid)) } async hasPeer(eid: EndpointId, address: Bytes32 | Address | null | undefined): Promise { - return areBytes32Equal(await this.peers(eid), address) + return areBytes32Equal(await this.getPeer(eid), address) } async setPeer(eid: EndpointId, address: Bytes32 | Address | null | undefined): Promise { diff --git a/packages/ua-utils-evm/test/oapp/sdk.test.ts b/packages/ua-utils-evm/test/oapp/sdk.test.ts index 02fb76e22..6e5548305 100644 --- a/packages/ua-utils-evm/test/oapp/sdk.test.ts +++ b/packages/ua-utils-evm/test/oapp/sdk.test.ts @@ -12,6 +12,7 @@ describe('oapp/sdk', () => { const oappOmniContractArbitrary = fc.record({ address: evmAddressArbitrary, peers: jestFunctionArbitrary, + endpoint: jestFunctionArbitrary, interface: fc.record({ encodeFunctionData: jestFunctionArbitrary, }), @@ -22,13 +23,15 @@ describe('oapp/sdk', () => { contract: oappOmniContractArbitrary, }) - describe('peers', () => { + const endpointFactory = jest.fn().mockRejectedValue('No endpoint') + + describe('getPeer', () => { it('should call peers on the contract', async () => { await fc.assert( fc.asyncProperty(omniContractArbitrary, endpointArbitrary, async (omniContract, peerEid) => { - const sdk = new OApp(omniContract) + const sdk = new OApp(omniContract, endpointFactory) - await sdk.peers(peerEid) + await sdk.getPeer(peerEid) expect(omniContract.contract.peers).toHaveBeenCalledTimes(1) expect(omniContract.contract.peers).toHaveBeenCalledWith(peerEid) @@ -45,9 +48,9 @@ describe('oapp/sdk', () => { async (omniContract, peerEid, peer) => { omniContract.contract.peers.mockResolvedValue(peer) - const sdk = new OApp(omniContract) + const sdk = new OApp(omniContract, endpointFactory) - expect(sdk.peers(peerEid)).resolves.toBeUndefined() + expect(sdk.getPeer(peerEid)).resolves.toBeUndefined() } ) ) @@ -62,9 +65,9 @@ describe('oapp/sdk', () => { async (omniContract, peerEid, peer) => { omniContract.contract.peers.mockResolvedValue(peer) - const sdk = new OApp(omniContract) + const sdk = new OApp(omniContract, endpointFactory) - await expect(sdk.peers(peerEid)).resolves.toBe(peer) + await expect(sdk.getPeer(peerEid)).resolves.toBe(peer) } ) ) @@ -83,7 +86,7 @@ describe('oapp/sdk', () => { async (omniContract, peerEid, peer, probePeer) => { omniContract.contract.peers.mockResolvedValue(peer) - const sdk = new OApp(omniContract) + const sdk = new OApp(omniContract, endpointFactory) await expect(sdk.hasPeer(peerEid, probePeer)).resolves.toBe(true) } @@ -103,7 +106,7 @@ describe('oapp/sdk', () => { omniContract.contract.peers.mockResolvedValue(peer) - const sdk = new OApp(omniContract) + const sdk = new OApp(omniContract, endpointFactory) await expect(sdk.hasPeer(peerEid, probePeer)).resolves.toBe(false) } @@ -125,7 +128,7 @@ describe('oapp/sdk', () => { omniContract.contract.peers.mockResolvedValue(peer) - const sdk = new OApp(omniContract) + const sdk = new OApp(omniContract, endpointFactory) await expect(sdk.hasPeer(peerEid, probePeer)).resolves.toBe(false) await expect(sdk.hasPeer(peerEid, makeBytes32(probePeer))).resolves.toBe(false) @@ -145,7 +148,7 @@ describe('oapp/sdk', () => { omniContract.contract.peers.mockResolvedValue(peer) - const sdk = new OApp(omniContract) + const sdk = new OApp(omniContract, endpointFactory) await expect(sdk.hasPeer(peerEid, peer)).resolves.toBe(true) await expect(sdk.hasPeer(peerEid, makeBytes32(peer))).resolves.toBe(true) @@ -165,7 +168,7 @@ describe('oapp/sdk', () => { omniContract.contract.peers.mockResolvedValue(makeBytes32(peer)) - const sdk = new OApp(omniContract) + const sdk = new OApp(omniContract, endpointFactory) await expect(sdk.hasPeer(peerEid, peer)).resolves.toBe(true) await expect(sdk.hasPeer(peerEid, makeBytes32(peer))).resolves.toBe(true) @@ -184,7 +187,7 @@ describe('oapp/sdk', () => { endpointArbitrary, evmAddressArbitrary, async (omniContract, peerEid, peerAddress) => { - const sdk = new OApp(omniContract) + const sdk = new OApp(omniContract, endpointFactory) const encodeFunctionData = omniContract.contract.interface.encodeFunctionData ;(encodeFunctionData as jest.Mock).mockClear() @@ -209,7 +212,7 @@ describe('oapp/sdk', () => { const encodeFunctionData = omniContract.contract.interface.encodeFunctionData as jest.Mock encodeFunctionData.mockReturnValue(data) - const sdk = new OApp(omniContract) + const sdk = new OApp(omniContract, endpointFactory) const transaction = await sdk.setPeer(peerEid, peerAddress) expect(transaction).toEqual({ @@ -224,4 +227,64 @@ describe('oapp/sdk', () => { ) }) }) + + describe('getEndpoint', () => { + it('should reject if the call to endpoint() rejects', async () => { + await fc.assert( + fc.asyncProperty(omniContractArbitrary, async (omniContract) => { + omniContract.contract.endpoint.mockRejectedValue('No you did not') + + const sdk = new OApp(omniContract, endpointFactory) + + await expect(sdk.getEndpoint()).rejects.toThrow(/Failed to get endpoint address for OApp/) + }) + ) + }) + + it('should reject if the call to endpoint() resolves with a zeroish address', async () => { + await fc.assert( + fc.asyncProperty( + omniContractArbitrary, + nullishAddressArbitrary, + async (omniContract, endpointAddress) => { + omniContract.contract.endpoint.mockResolvedValue(endpointAddress) + + const sdk = new OApp(omniContract, endpointFactory) + + await expect(sdk.getEndpoint()).rejects.toThrow( + /Endpoint cannot be instantiated: Endpoint address has been set to a zero value for OApp/ + ) + } + ) + ) + }) + + it('should call the endpointFactory if the call to endpoint() resolves with a non-zeroish address', async () => { + await fc.assert( + fc.asyncProperty( + omniContractArbitrary, + evmAddressArbitrary, + fc.anything(), + async (omniContract, endpointAddress, endpointSdk) => { + fc.pre(!isZero(endpointAddress)) + + omniContract.contract.endpoint.mockResolvedValue(endpointAddress) + + endpointFactory.mockReset().mockResolvedValue(endpointSdk) + + const sdk = new OApp(omniContract, endpointFactory) + const endpoint = await sdk.getEndpoint() + + expect(endpoint).toBe(endpointSdk) + + expect(endpointFactory).toHaveBeenCalledTimes(1) + expect(endpointFactory).toHaveBeenCalledWith({ + eid: omniContract.eid, + address: endpointAddress, + }) + } + ) + ) + }) + }) }) diff --git a/packages/ua-utils/package.json b/packages/ua-utils/package.json index a15ed0e55..2a6939472 100644 --- a/packages/ua-utils/package.json +++ b/packages/ua-utils/package.json @@ -31,6 +31,7 @@ }, "devDependencies": { "@layerzerolabs/lz-definitions": "~1.5.70", + "@layerzerolabs/protocol-utils": "~0.0.1", "@layerzerolabs/test-utils": "~0.0.1", "@layerzerolabs/utils": "~0.0.1", "@types/jest": "^29.5.10", @@ -45,6 +46,7 @@ }, "peerDependencies": { "@layerzerolabs/lz-definitions": "~1.5.70", + "@layerzerolabs/protocol-utils": "~0.0.1", "@layerzerolabs/utils": "~0.0.1", "zod": "^3.22.4" } diff --git a/packages/ua-utils/src/oapp/types.ts b/packages/ua-utils/src/oapp/types.ts index c443b4b40..320e5f2a7 100644 --- a/packages/ua-utils/src/oapp/types.ts +++ b/packages/ua-utils/src/oapp/types.ts @@ -1,14 +1,16 @@ import type { EndpointId } from '@layerzerolabs/lz-definitions' +import type { IEndpoint } from '@layerzerolabs/protocol-utils' import type { Address, OmniGraph, OmniTransaction } from '@layerzerolabs/utils' -import { Bytes32 } from '@layerzerolabs/utils' -import { OmniPointBasedFactory } from '@layerzerolabs/utils' +import type { Bytes32 } from '@layerzerolabs/utils' +import type { OmniPointBasedFactory } from '@layerzerolabs/utils' export interface IOApp { - peers(eid: EndpointId): Promise + getEndpoint(): Promise + getPeer(eid: EndpointId): Promise hasPeer(eid: EndpointId, address: Bytes32 | Address | null | undefined): Promise setPeer(eid: EndpointId, peer: Bytes32 | Address | null | undefined): Promise } export type OAppOmniGraph = OmniGraph -export type OAppFactory = OmniPointBasedFactory +export type OAppFactory = OmniPointBasedFactory diff --git a/packages/utils-evm/src/omnigraph/format.ts b/packages/utils-evm/src/omnigraph/format.ts new file mode 100644 index 000000000..955306ecf --- /dev/null +++ b/packages/utils-evm/src/omnigraph/format.ts @@ -0,0 +1,6 @@ +import { formatOmniPoint } from '@layerzerolabs/utils' +import type { OmniContract } from './types' +import { omniContractToPoint } from './coordinates' + +export const formatOmniContract = (contract: OmniContract): string => + `EVM contract at ${formatOmniPoint(omniContractToPoint(contract))}` diff --git a/packages/utils-evm/src/omnigraph/index.ts b/packages/utils-evm/src/omnigraph/index.ts index 84c0bd062..01b288f65 100644 --- a/packages/utils-evm/src/omnigraph/index.ts +++ b/packages/utils-evm/src/omnigraph/index.ts @@ -1,2 +1,3 @@ export * from './coordinates' +export * from './format' export * from './types'