-
Notifications
You must be signed in to change notification settings - Fork 169
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: Shorten names and move stuff under omnigraph directory
- Loading branch information
1 parent
6ee0709
commit 692b7ae
Showing
14 changed files
with
173 additions
and
160 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export const getCoordinate = (contractName: string): OmniNodeCoordinate | undefined => {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import type { OmniGraph } from "@layerzerolabs/ua-utils" | ||
import { z } from "zod" | ||
|
||
export type OAppContractConfig = z.TypeOf<typeof OAppContractConfigSchema> | ||
|
||
export type OAppConnectionConfig = z.TypeOf<typeof OAppConnectionConfigSchema> | ||
|
||
export type OAppOmnichainConfig = OmniGraph<OAppContractConfig, OAppConnectionConfig> | ||
|
||
export const OAppContractConfigSchema = z.object({}) | ||
|
||
export const OAppConnectionConfigSchema = z.object({}) |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1 @@ | ||
export * from "./coordinates" | ||
export * from "./schema" | ||
export * from "./types" | ||
export * from "./omnigraph" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import { OmniEdgeCoordinates, OmniNodeCoordinate } from "./types" | ||
|
||
/** | ||
* Compares two coordinates by value | ||
* | ||
* @param a `OmniNodeCoordinate` | ||
* @param b `OmniNodeCoordinate` | ||
* | ||
* @returns `true` if the coordinates point to the same point in omniverse | ||
*/ | ||
export const isCoordinateEqual = (a: OmniNodeCoordinate, b: OmniNodeCoordinate): boolean => a.address === b.address && a.eid === b.eid | ||
|
||
/** | ||
* Compares two coordinate vectors | ||
* | ||
* @param a `OmniEdgeCoordinates` | ||
* @param b `OmniEdgeCoordinates` | ||
* | ||
* @returns `true` if the coordinates point from and to the same point in omniverse | ||
*/ | ||
export const areCoordinatesEqual = (a: OmniEdgeCoordinates, b: OmniEdgeCoordinates): boolean => | ||
isCoordinateEqual(a.from, b.from) && isCoordinateEqual(a.to, b.to) | ||
|
||
/** | ||
* Serializes a coordinate. Useful for when coordinates need to be used in Map | ||
* where we cannot adjust the default behavior of using a reference equality | ||
* | ||
* @param coordinate `OmniNodeCoordinate` | ||
* | ||
* @returns `string` | ||
*/ | ||
export const serializeCoordinate = ({ address, eid }: OmniNodeCoordinate): string => `${eid}|${address}` | ||
|
||
/** | ||
* Serializes coordinate vector. Useful for when coordinates need to be used in Map | ||
* where we cannot adjust the default behavior of using a reference equality | ||
* | ||
* @param coordinate `OmniEdgeCoordinates` | ||
* | ||
* @returns `string` | ||
*/ | ||
export const serializeCoordinates = ({ from, to }: OmniEdgeCoordinates): string => `${serializeCoordinate(from)} → ${serializeCoordinate(to)}` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export * from "./coordinates" | ||
export * from "./schema" | ||
export * from "./types" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import { EndpointId } from "@layerzerolabs/lz-definitions" | ||
import { z } from "zod" | ||
import type { OmniNodeCoordinate, OmniNode, OmniEdgeCoordinates, OmniEdge } from "./types" | ||
|
||
export const AddressSchema = z.string() | ||
|
||
export const EndpointIdSchema: z.ZodSchema<EndpointId, z.ZodTypeDef, unknown> = z.nativeEnum(EndpointId).pipe(z.number()) | ||
|
||
export const OmniNodeCoordinateSchema: z.ZodSchema<OmniNodeCoordinate, z.ZodTypeDef, unknown> = z.object({ | ||
address: AddressSchema, | ||
eid: EndpointIdSchema, | ||
}) | ||
|
||
export const OmniEdgeCoordinatesSchema: z.ZodSchema<OmniEdgeCoordinates, z.ZodTypeDef, unknown> = z.object({ | ||
from: OmniNodeCoordinateSchema, | ||
to: OmniNodeCoordinateSchema, | ||
}) | ||
|
||
/** | ||
* Factory for OmniNode schemas | ||
* | ||
* @param configSchema Schema of the config contained in the node | ||
* | ||
* @returns `z.ZodSchema<OmniNode<TConfig>>` schema for a node with the particular config type | ||
*/ | ||
export const createOmniNodeSchema = <TConfig = unknown>( | ||
configSchema: z.ZodSchema<TConfig, z.ZodTypeDef, unknown> | ||
): z.ZodSchema<OmniNode<TConfig>, z.ZodTypeDef, unknown> => | ||
z.object({ | ||
coordinate: OmniNodeCoordinateSchema, | ||
config: configSchema, | ||
}) as z.ZodSchema<OmniNode<TConfig>, z.ZodTypeDef, unknown> | ||
|
||
/** | ||
* Factory for OmniEdge schemas | ||
* | ||
* @param configSchema `z.ZodSchema<TConfig>` Schema of the config contained in the edge | ||
* | ||
* @returns `z.ZodSchema<OmniEdge<TConfig>>` schema for an edge with the particular config type | ||
*/ | ||
export const createOmniEdgeSchema = <TConfig = unknown>( | ||
configSchema: z.ZodSchema<TConfig, z.ZodTypeDef, unknown> | ||
): z.ZodSchema<OmniEdge<TConfig>, z.ZodTypeDef, unknown> => | ||
z.object({ | ||
coordinates: OmniEdgeCoordinatesSchema, | ||
config: configSchema, | ||
}) as z.ZodSchema<OmniEdge<TConfig>, z.ZodTypeDef, unknown> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
import type { EndpointId } from "@layerzerolabs/lz-definitions" | ||
|
||
export type Address = string | ||
|
||
/** | ||
* OmniNodeCoordinate identifies a point in omniverse, an omnichain universe. | ||
* | ||
* In layman terms this is a contract deployed on a particular network (represented by an endpoint). | ||
*/ | ||
export interface OmniNodeCoordinate { | ||
eid: EndpointId | ||
address: Address | ||
} | ||
|
||
/** | ||
* OmniEdgeCoordinates identify a line in omniverse, an omnichain universe. | ||
* | ||
* In layman terms this is a directional connection between two contracts | ||
*/ | ||
export interface OmniEdgeCoordinates { | ||
from: OmniNodeCoordinate | ||
to: OmniNodeCoordinate | ||
} | ||
|
||
/** | ||
* OmniNode represents a point in omniverse | ||
* with an additional piece of information attached | ||
*/ | ||
export interface OmniNode<TConfig = unknown> { | ||
coordinate: OmniNodeCoordinate | ||
config: TConfig | ||
} | ||
|
||
/** | ||
* OmniEdge represents a connection between two points in omniverse | ||
* with an additional piece of information attached | ||
*/ | ||
export interface OmniEdge<TConfig = unknown> { | ||
coordinates: OmniEdgeCoordinates | ||
config: TConfig | ||
} | ||
|
||
/** | ||
* OmniGraph is a collection of nodes and edges of omniverse | ||
* that together represent an omnichain app a.k.a. OApp. | ||
* | ||
* For purposes of readability and to avoid overabstraction on the user end, | ||
* the names are set to be `contracts` rather than `nodes` and `connections` rather than `edges` | ||
*/ | ||
export interface OmniGraph<TNodeConfig = unknown, TEdgeConfig = unknown> { | ||
contracts: OmniNode<TNodeConfig>[] | ||
connections: OmniEdge<TEdgeConfig>[] | ||
} |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,18 @@ | ||
import fc from "fast-check" | ||
import { EndpointId } from "@layerzerolabs/lz-definitions" | ||
import { ENDPOINT_IDS } from "./constants" | ||
import { OmnichainNodeCoordinate, OmnichainEdgeCoordinates } from "@/types" | ||
import { OmniNodeCoordinate, OmniEdgeCoordinates } from "@/omnigraph/types" | ||
|
||
export const addressArbitrary = fc.string() | ||
|
||
export const endpointArbitrary: fc.Arbitrary<EndpointId> = fc.constantFrom(...ENDPOINT_IDS) | ||
|
||
export const coordinateArbitrary: fc.Arbitrary<OmnichainNodeCoordinate> = fc.record({ | ||
export const coordinateArbitrary: fc.Arbitrary<OmniNodeCoordinate> = fc.record({ | ||
eid: endpointArbitrary, | ||
address: addressArbitrary, | ||
}) | ||
|
||
export const coordinatesArbitrary: fc.Arbitrary<OmnichainEdgeCoordinates> = fc.record({ | ||
export const coordinatesArbitrary: fc.Arbitrary<OmniEdgeCoordinates> = fc.record({ | ||
from: coordinateArbitrary, | ||
to: coordinateArbitrary, | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
import { EndpointId } from "@layerzerolabs/lz-definitions" | ||
import { EndpointIdSchema } from "../../src/schema" | ||
import { EndpointIdSchema } from "../../src/omnigraph/schema" | ||
|
||
export const ENDPOINT_IDS = Object.values(EndpointId).filter((value): value is EndpointId => EndpointIdSchema.safeParse(value).success) |
6 changes: 3 additions & 3 deletions
6
packages/ua-utils/test/coordinates.test.ts → ...-utils/test/omnigraph/coordinates.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters