@hyperlane-xyz/registry 1.1.2 → 1.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/chainAddresses.d.ts +92 -5
- package/dist/chainAddresses.js +104 -17
- package/dist/chainMetadata.js +104 -1
- package/dist/chains/ancient8/addresses.d.ts +6 -5
- package/dist/chains/ancient8/addresses.js +7 -6
- package/dist/chains/ancient8/addresses.json +7 -6
- package/dist/chains/ancient8/addresses.yaml +7 -6
- package/dist/chains/ancient8/metadata.yaml +1 -1
- package/dist/chains/arbitrum/addresses.d.ts +3 -0
- package/dist/chains/arbitrum/addresses.js +4 -1
- package/dist/chains/arbitrum/addresses.json +4 -1
- package/dist/chains/arbitrum/addresses.yaml +4 -1
- package/dist/chains/avalanche/addresses.d.ts +3 -0
- package/dist/chains/avalanche/addresses.js +4 -1
- package/dist/chains/avalanche/addresses.json +4 -1
- package/dist/chains/avalanche/addresses.yaml +4 -1
- package/dist/chains/avalanche/metadata.js +3 -0
- package/dist/chains/avalanche/metadata.json +3 -0
- package/dist/chains/avalanche/metadata.yaml +1 -0
- package/dist/chains/base/addresses.d.ts +4 -0
- package/dist/chains/base/addresses.js +5 -1
- package/dist/chains/base/addresses.json +5 -1
- package/dist/chains/base/addresses.yaml +5 -1
- package/dist/chains/blast/addresses.d.ts +4 -0
- package/dist/chains/blast/addresses.js +5 -1
- package/dist/chains/blast/addresses.json +5 -1
- package/dist/chains/blast/addresses.yaml +5 -1
- package/dist/chains/bsc/addresses.d.ts +3 -0
- package/dist/chains/bsc/addresses.js +4 -1
- package/dist/chains/bsc/addresses.json +4 -1
- package/dist/chains/bsc/addresses.yaml +4 -1
- package/dist/chains/celo/addresses.js +1 -1
- package/dist/chains/celo/addresses.json +1 -1
- package/dist/chains/celo/addresses.yaml +1 -1
- package/dist/chains/celo/metadata.js +1 -1
- package/dist/chains/celo/metadata.json +1 -1
- package/dist/chains/celo/metadata.yaml +1 -1
- package/dist/chains/ethereum/addresses.d.ts +3 -0
- package/dist/chains/ethereum/addresses.js +4 -1
- package/dist/chains/ethereum/addresses.json +4 -1
- package/dist/chains/ethereum/addresses.yaml +4 -1
- package/dist/chains/gnosis/addresses.d.ts +3 -0
- package/dist/chains/gnosis/addresses.js +4 -1
- package/dist/chains/gnosis/addresses.json +4 -1
- package/dist/chains/gnosis/addresses.yaml +4 -1
- package/dist/chains/holesky/addresses.d.ts +18 -0
- package/dist/chains/holesky/addresses.js +18 -0
- package/dist/chains/holesky/addresses.json +18 -0
- package/dist/chains/holesky/addresses.yaml +16 -0
- package/dist/chains/holesky/index.d.ts +2 -0
- package/dist/chains/holesky/index.js +2 -0
- package/dist/chains/holesky/logo.svg +1 -0
- package/dist/chains/holesky/metadata.d.ts +2 -0
- package/dist/chains/holesky/metadata.js +30 -0
- package/dist/chains/holesky/metadata.json +30 -0
- package/dist/chains/holesky/metadata.yaml +21 -0
- package/dist/chains/inevm/addresses.js +1 -1
- package/dist/chains/inevm/addresses.json +1 -1
- package/dist/chains/inevm/addresses.yaml +1 -1
- package/dist/chains/polygon/addresses.d.ts +3 -0
- package/dist/chains/polygon/addresses.js +4 -1
- package/dist/chains/polygon/addresses.json +4 -1
- package/dist/chains/polygon/addresses.yaml +4 -1
- package/dist/chains/polygonzkevm/metadata.js +1 -0
- package/dist/chains/polygonzkevm/metadata.json +1 -0
- package/dist/chains/polygonzkevm/metadata.yaml +1 -0
- package/dist/chains/redstone/addresses.d.ts +18 -0
- package/dist/chains/redstone/addresses.js +18 -0
- package/dist/chains/redstone/addresses.json +18 -0
- package/dist/chains/redstone/addresses.yaml +16 -0
- package/dist/chains/redstone/index.d.ts +2 -0
- package/dist/chains/redstone/index.js +2 -0
- package/dist/chains/redstone/logo.svg +42 -0
- package/dist/chains/redstone/metadata.d.ts +2 -0
- package/dist/chains/redstone/metadata.js +31 -0
- package/dist/chains/redstone/metadata.json +31 -0
- package/dist/chains/redstone/metadata.yaml +22 -0
- package/dist/chains/scroll/metadata.js +1 -0
- package/dist/chains/scroll/metadata.json +1 -0
- package/dist/chains/scroll/metadata.yaml +1 -0
- package/dist/chains/viction/addresses.d.ts +6 -0
- package/dist/chains/viction/addresses.js +7 -1
- package/dist/chains/viction/addresses.json +7 -1
- package/dist/chains/viction/addresses.yaml +7 -1
- package/dist/chains/zetachain/addresses.d.ts +18 -0
- package/dist/chains/zetachain/addresses.js +18 -0
- package/dist/chains/zetachain/addresses.json +18 -0
- package/dist/chains/zetachain/addresses.yaml +16 -0
- package/dist/chains/zetachain/index.d.ts +2 -0
- package/dist/chains/zetachain/index.js +2 -0
- package/dist/chains/zetachain/logo.svg +4 -0
- package/dist/chains/zetachain/metadata.d.ts +2 -0
- package/dist/chains/zetachain/metadata.js +37 -0
- package/dist/chains/zetachain/metadata.json +37 -0
- package/dist/chains/zetachain/metadata.yaml +24 -0
- package/dist/coreChainAddresses.d.ts +34 -5
- package/dist/coreChainAddresses.js +45 -16
- package/dist/coreChainMetadata.js +6 -1
- package/dist/index-fs.d.ts +1 -0
- package/dist/{index-local.js → index-fs.js} +1 -1
- package/dist/index.d.ts +8 -0
- package/dist/index.js +8 -0
- package/dist/registry/BaseRegistry.d.ts +1 -0
- package/dist/registry/BaseRegistry.js +4 -0
- package/dist/registry/{LocalRegistry.d.ts → FileSystemRegistry.d.ts} +9 -18
- package/dist/registry/{LocalRegistry.js → FileSystemRegistry.js} +11 -37
- package/dist/registry/GithubRegistry.d.ts +5 -0
- package/dist/registry/GithubRegistry.js +5 -0
- package/dist/registry/IRegistry.d.ts +4 -1
- package/dist/registry/IRegistry.js +3 -1
- package/dist/registry/MergedRegistry.d.ts +43 -0
- package/dist/registry/MergedRegistry.js +88 -0
- package/dist/registry/PartialRegistry.d.ts +30 -0
- package/dist/registry/PartialRegistry.js +50 -0
- package/dist/registry/SynchronousRegistry.d.ts +34 -0
- package/dist/registry/SynchronousRegistry.js +41 -0
- package/dist/utils.d.ts +2 -0
- package/dist/utils.js +31 -0
- package/package.json +8 -6
- package/dist/index-local.d.ts +0 -1
|
@@ -4,11 +4,16 @@ import { parse as yamlParse } from 'yaml';
|
|
|
4
4
|
import { SCHEMA_REF } from '../consts.js';
|
|
5
5
|
import { ChainAddressesSchema } from '../types.js';
|
|
6
6
|
import { toYamlString } from '../utils.js';
|
|
7
|
-
import {
|
|
7
|
+
import { CHAIN_FILE_REGEX } from './BaseRegistry.js';
|
|
8
8
|
import { RegistryType, } from './IRegistry.js';
|
|
9
|
+
import { SynchronousRegistry } from './SynchronousRegistry.js';
|
|
9
10
|
import { warpConfigToWarpAddresses } from './warp-utils.js';
|
|
10
|
-
|
|
11
|
-
|
|
11
|
+
/**
|
|
12
|
+
* A registry that uses a local file system path as its data source.
|
|
13
|
+
* Requires file system access so it cannot be used in the browser.
|
|
14
|
+
*/
|
|
15
|
+
export class FileSystemRegistry extends SynchronousRegistry {
|
|
16
|
+
type = RegistryType.FileSystem;
|
|
12
17
|
constructor(options) {
|
|
13
18
|
super(options);
|
|
14
19
|
}
|
|
@@ -29,9 +34,6 @@ export class LocalRegistry extends BaseRegistry {
|
|
|
29
34
|
// TODO add handling for deployment artifact files here too
|
|
30
35
|
return (this.listContentCache = { chains, deployments: {} });
|
|
31
36
|
}
|
|
32
|
-
getChains() {
|
|
33
|
-
return Object.keys(this.listRegistryContent().chains);
|
|
34
|
-
}
|
|
35
37
|
getMetadata() {
|
|
36
38
|
if (this.metadataCache)
|
|
37
39
|
return this.metadataCache;
|
|
@@ -45,10 +47,6 @@ export class LocalRegistry extends BaseRegistry {
|
|
|
45
47
|
}
|
|
46
48
|
return (this.metadataCache = chainMetadata);
|
|
47
49
|
}
|
|
48
|
-
getChainMetadata(chainName) {
|
|
49
|
-
const metadata = this.getMetadata();
|
|
50
|
-
return metadata[chainName] ?? null;
|
|
51
|
-
}
|
|
52
50
|
getAddresses() {
|
|
53
51
|
if (this.addressCache)
|
|
54
52
|
return this.addressCache;
|
|
@@ -62,34 +60,10 @@ export class LocalRegistry extends BaseRegistry {
|
|
|
62
60
|
}
|
|
63
61
|
return (this.addressCache = chainAddresses);
|
|
64
62
|
}
|
|
65
|
-
getChainAddresses(chainName) {
|
|
66
|
-
const addresses = this.getAddresses();
|
|
67
|
-
return addresses[chainName] ?? null;
|
|
68
|
-
}
|
|
69
|
-
addChain(chain) {
|
|
70
|
-
const currentChains = this.listRegistryContent().chains;
|
|
71
|
-
if (currentChains[chain.chainName])
|
|
72
|
-
throw new Error(`Chain ${chain.chainName} already exists in registry`);
|
|
73
|
-
this.createOrUpdateChain(chain);
|
|
74
|
-
}
|
|
75
|
-
updateChain(chain) {
|
|
76
|
-
const currentChains = this.listRegistryContent();
|
|
77
|
-
if (!currentChains.chains[chain.chainName]) {
|
|
78
|
-
this.logger.debug(`Chain ${chain.chainName} not found in registry, adding it now`);
|
|
79
|
-
}
|
|
80
|
-
this.createOrUpdateChain(chain);
|
|
81
|
-
}
|
|
82
63
|
removeChain(chainName) {
|
|
83
|
-
const
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
this.removeFiles(Object.values(currentChains[chainName]));
|
|
87
|
-
if (this.listContentCache?.chains[chainName])
|
|
88
|
-
delete this.listContentCache.chains[chainName];
|
|
89
|
-
if (this.metadataCache?.[chainName])
|
|
90
|
-
delete this.metadataCache[chainName];
|
|
91
|
-
if (this.addressCache?.[chainName])
|
|
92
|
-
delete this.addressCache[chainName];
|
|
64
|
+
const chainFiles = this.listRegistryContent().chains[chainName];
|
|
65
|
+
super.removeChain(chainName);
|
|
66
|
+
this.removeFiles(Object.values(chainFiles));
|
|
93
67
|
}
|
|
94
68
|
listFiles(dirPath) {
|
|
95
69
|
if (!fs.existsSync(dirPath))
|
|
@@ -9,6 +9,11 @@ export interface GithubRegistryOptions {
|
|
|
9
9
|
authToken?: string;
|
|
10
10
|
logger?: Logger;
|
|
11
11
|
}
|
|
12
|
+
/**
|
|
13
|
+
* A registry that uses a github repository as its data source.
|
|
14
|
+
* Reads are performed via the github API and github's raw content URLs.
|
|
15
|
+
* Writes are not yet supported (TODO)
|
|
16
|
+
*/
|
|
12
17
|
export declare class GithubRegistry extends BaseRegistry implements IRegistry {
|
|
13
18
|
readonly type = RegistryType.Github;
|
|
14
19
|
readonly url: URL;
|
|
@@ -3,6 +3,11 @@ import { DEFAULT_GITHUB_REGISTRY, GITHUB_FETCH_CONCURRENCY_LIMIT } from '../cons
|
|
|
3
3
|
import { concurrentMap } from '../utils.js';
|
|
4
4
|
import { BaseRegistry, CHAIN_FILE_REGEX } from './BaseRegistry.js';
|
|
5
5
|
import { RegistryType, } from './IRegistry.js';
|
|
6
|
+
/**
|
|
7
|
+
* A registry that uses a github repository as its data source.
|
|
8
|
+
* Reads are performed via the github API and github's raw content URLs.
|
|
9
|
+
* Writes are not yet supported (TODO)
|
|
10
|
+
*/
|
|
6
11
|
export class GithubRegistry extends BaseRegistry {
|
|
7
12
|
type = RegistryType.Github;
|
|
8
13
|
url;
|
|
@@ -11,7 +11,9 @@ export interface RegistryContent {
|
|
|
11
11
|
}
|
|
12
12
|
export declare enum RegistryType {
|
|
13
13
|
Github = "github",
|
|
14
|
-
|
|
14
|
+
FileSystem = "filesystem",
|
|
15
|
+
Merged = "merged",
|
|
16
|
+
Partial = "partial"
|
|
15
17
|
}
|
|
16
18
|
export interface IRegistry {
|
|
17
19
|
type: RegistryType;
|
|
@@ -35,4 +37,5 @@ export interface IRegistry {
|
|
|
35
37
|
}): MaybePromise<void>;
|
|
36
38
|
removeChain(chain: ChainName): MaybePromise<void>;
|
|
37
39
|
addWarpRoute(config: WarpCoreConfig): MaybePromise<void>;
|
|
40
|
+
merge(otherRegistry: IRegistry): IRegistry;
|
|
38
41
|
}
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
export var RegistryType;
|
|
2
2
|
(function (RegistryType) {
|
|
3
3
|
RegistryType["Github"] = "github";
|
|
4
|
-
RegistryType["
|
|
4
|
+
RegistryType["FileSystem"] = "filesystem";
|
|
5
|
+
RegistryType["Merged"] = "merged";
|
|
6
|
+
RegistryType["Partial"] = "partial";
|
|
5
7
|
})(RegistryType || (RegistryType = {}));
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import type { Logger } from 'pino';
|
|
2
|
+
import type { ChainMap, ChainMetadata, ChainName, WarpCoreConfig } from '@hyperlane-xyz/sdk';
|
|
3
|
+
import { ChainAddresses } from '../types.js';
|
|
4
|
+
import { IRegistry, RegistryContent, RegistryType } from './IRegistry.js';
|
|
5
|
+
export interface MergedRegistryOptions {
|
|
6
|
+
registries: Array<IRegistry>;
|
|
7
|
+
logger?: Logger;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* A registry that accepts multiple sub-registries.
|
|
11
|
+
* Read methods are performed on all sub-registries and the results are merged.
|
|
12
|
+
* Write methods are performed on all sub-registries.
|
|
13
|
+
* Can be created manually or by calling `.merge()` on an existing registry.
|
|
14
|
+
*/
|
|
15
|
+
export declare class MergedRegistry implements IRegistry {
|
|
16
|
+
readonly type = RegistryType.Merged;
|
|
17
|
+
readonly uri = "__merged_registry__";
|
|
18
|
+
readonly registries: Array<IRegistry>;
|
|
19
|
+
protected readonly logger: Logger;
|
|
20
|
+
constructor({ registries, logger }: MergedRegistryOptions);
|
|
21
|
+
listRegistryContent(): Promise<RegistryContent>;
|
|
22
|
+
getChains(): Promise<Array<ChainName>>;
|
|
23
|
+
getMetadata(): Promise<ChainMap<ChainMetadata>>;
|
|
24
|
+
getChainMetadata(chainName: ChainName): Promise<ChainMetadata | null>;
|
|
25
|
+
getAddresses(): Promise<ChainMap<ChainAddresses>>;
|
|
26
|
+
getChainAddresses(chainName: ChainName): Promise<ChainAddresses | null>;
|
|
27
|
+
getChainLogoUri(chainName: ChainName): Promise<string | null>;
|
|
28
|
+
addChain(chain: {
|
|
29
|
+
chainName: ChainName;
|
|
30
|
+
metadata?: ChainMetadata;
|
|
31
|
+
addresses?: ChainAddresses;
|
|
32
|
+
}): Promise<void>;
|
|
33
|
+
updateChain(chain: {
|
|
34
|
+
chainName: ChainName;
|
|
35
|
+
metadata?: ChainMetadata;
|
|
36
|
+
addresses?: ChainAddresses;
|
|
37
|
+
}): Promise<void>;
|
|
38
|
+
removeChain(chain: ChainName): Promise<void>;
|
|
39
|
+
addWarpRoute(config: WarpCoreConfig): Promise<void>;
|
|
40
|
+
protected multiRegistryRead<R>(readFn: (registry: IRegistry) => Promise<R> | R): Promise<(Awaited<R> | Awaited<R>)[]>;
|
|
41
|
+
protected multiRegistryWrite(writeFn: (registry: IRegistry) => Promise<void>, logMsg: string): Promise<void>;
|
|
42
|
+
merge(otherRegistry: IRegistry): IRegistry;
|
|
43
|
+
}
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import { objMerge } from '../utils.js';
|
|
2
|
+
import { RegistryType } from './IRegistry.js';
|
|
3
|
+
/**
|
|
4
|
+
* A registry that accepts multiple sub-registries.
|
|
5
|
+
* Read methods are performed on all sub-registries and the results are merged.
|
|
6
|
+
* Write methods are performed on all sub-registries.
|
|
7
|
+
* Can be created manually or by calling `.merge()` on an existing registry.
|
|
8
|
+
*/
|
|
9
|
+
export class MergedRegistry {
|
|
10
|
+
type = RegistryType.Merged;
|
|
11
|
+
uri = '__merged_registry__';
|
|
12
|
+
registries;
|
|
13
|
+
logger;
|
|
14
|
+
constructor({ registries, logger }) {
|
|
15
|
+
if (!registries.length)
|
|
16
|
+
throw new Error('At least one registry URI is required');
|
|
17
|
+
this.registries = registries;
|
|
18
|
+
// @ts-ignore
|
|
19
|
+
this.logger = logger || console;
|
|
20
|
+
}
|
|
21
|
+
async listRegistryContent() {
|
|
22
|
+
const results = await this.multiRegistryRead((r) => r.listRegistryContent());
|
|
23
|
+
return results.reduce((acc, content) => objMerge(acc, content), {
|
|
24
|
+
chains: {},
|
|
25
|
+
deployments: {},
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
async getChains() {
|
|
29
|
+
return Object.keys(await this.getMetadata());
|
|
30
|
+
}
|
|
31
|
+
async getMetadata() {
|
|
32
|
+
const results = await this.multiRegistryRead((r) => r.getMetadata());
|
|
33
|
+
return results.reduce((acc, content) => objMerge(acc, content), {});
|
|
34
|
+
}
|
|
35
|
+
async getChainMetadata(chainName) {
|
|
36
|
+
return (await this.getMetadata())[chainName] || null;
|
|
37
|
+
}
|
|
38
|
+
async getAddresses() {
|
|
39
|
+
const results = await this.multiRegistryRead((r) => r.getAddresses());
|
|
40
|
+
return results.reduce((acc, content) => objMerge(acc, content), {});
|
|
41
|
+
}
|
|
42
|
+
async getChainAddresses(chainName) {
|
|
43
|
+
return (await this.getAddresses())[chainName] || null;
|
|
44
|
+
}
|
|
45
|
+
async getChainLogoUri(chainName) {
|
|
46
|
+
const results = await this.multiRegistryRead((r) => r.getChainLogoUri(chainName));
|
|
47
|
+
return results.find((uri) => !!uri) || null;
|
|
48
|
+
}
|
|
49
|
+
async addChain(chain) {
|
|
50
|
+
return this.multiRegistryWrite(async (registry) => await registry.addChain(chain), `adding chain ${chain.chainName}`);
|
|
51
|
+
}
|
|
52
|
+
async updateChain(chain) {
|
|
53
|
+
return this.multiRegistryWrite(async (registry) => await registry.updateChain(chain), `updating chain ${chain.chainName}`);
|
|
54
|
+
}
|
|
55
|
+
async removeChain(chain) {
|
|
56
|
+
return this.multiRegistryWrite(async (registry) => await registry.removeChain(chain), `removing chain ${chain}`);
|
|
57
|
+
}
|
|
58
|
+
async addWarpRoute(config) {
|
|
59
|
+
return this.multiRegistryWrite(async (registry) => await registry.addWarpRoute(config), 'adding warp route');
|
|
60
|
+
}
|
|
61
|
+
multiRegistryRead(readFn) {
|
|
62
|
+
return Promise.all(this.registries.map(readFn));
|
|
63
|
+
}
|
|
64
|
+
async multiRegistryWrite(writeFn, logMsg) {
|
|
65
|
+
for (const registry of this.registries) {
|
|
66
|
+
// TODO remove this when GithubRegistry supports write methods
|
|
67
|
+
if (registry.type === RegistryType.Github) {
|
|
68
|
+
this.logger.warn(`Skipping ${logMsg} at ${registry.type} registry`);
|
|
69
|
+
continue;
|
|
70
|
+
}
|
|
71
|
+
try {
|
|
72
|
+
this.logger.info(`Now ${logMsg} at ${registry.type} registry at ${registry.uri}`);
|
|
73
|
+
await writeFn(registry);
|
|
74
|
+
this.logger.info(`Done ${logMsg} at ${registry.type} registry`);
|
|
75
|
+
}
|
|
76
|
+
catch (error) {
|
|
77
|
+
// To prevent loss of artifacts, MergedRegistry write methods are failure tolerant
|
|
78
|
+
this.logger.error(`Failure ${logMsg} at ${registry.type} registry`, error);
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
merge(otherRegistry) {
|
|
83
|
+
return new MergedRegistry({
|
|
84
|
+
registries: [...this.registries, otherRegistry],
|
|
85
|
+
logger: this.logger,
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import type { Logger } from 'pino';
|
|
2
|
+
import type { ChainMap, ChainMetadata, ChainName, WarpCoreConfig } from '@hyperlane-xyz/sdk';
|
|
3
|
+
import { ChainAddresses } from '../types.js';
|
|
4
|
+
import { IRegistry, RegistryContent, RegistryType } from './IRegistry.js';
|
|
5
|
+
import { SynchronousRegistry } from './SynchronousRegistry.js';
|
|
6
|
+
/**
|
|
7
|
+
* A registry that accepts partial data, such as incomplete chain metadata or addresses.
|
|
8
|
+
* Useful for merging with other registries force overrides of subsets of data.
|
|
9
|
+
*/
|
|
10
|
+
export interface PartialRegistryOptions {
|
|
11
|
+
chainMetadata?: ChainMap<Partial<ChainMetadata>>;
|
|
12
|
+
chainAddresses?: ChainMap<Partial<ChainAddresses>>;
|
|
13
|
+
logger?: Logger;
|
|
14
|
+
}
|
|
15
|
+
export declare class PartialRegistry extends SynchronousRegistry implements IRegistry {
|
|
16
|
+
readonly type = RegistryType.Partial;
|
|
17
|
+
chainMetadata: ChainMap<Partial<ChainMetadata>>;
|
|
18
|
+
chainAddresses: ChainMap<Partial<ChainAddresses>>;
|
|
19
|
+
constructor({ chainMetadata, chainAddresses, logger }: PartialRegistryOptions);
|
|
20
|
+
listRegistryContent(): RegistryContent;
|
|
21
|
+
getMetadata(): ChainMap<ChainMetadata>;
|
|
22
|
+
getAddresses(): ChainMap<ChainAddresses>;
|
|
23
|
+
removeChain(chainName: ChainName): void;
|
|
24
|
+
addWarpRoute(_config: WarpCoreConfig): void;
|
|
25
|
+
protected createOrUpdateChain(chain: {
|
|
26
|
+
chainName: ChainName;
|
|
27
|
+
metadata?: ChainMetadata;
|
|
28
|
+
addresses?: ChainAddresses;
|
|
29
|
+
}): void;
|
|
30
|
+
}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { RegistryType } from './IRegistry.js';
|
|
2
|
+
import { SynchronousRegistry } from './SynchronousRegistry.js';
|
|
3
|
+
const PARTIAL_URI_PLACEHOLDER = '__partial_registry__';
|
|
4
|
+
export class PartialRegistry extends SynchronousRegistry {
|
|
5
|
+
type = RegistryType.Partial;
|
|
6
|
+
chainMetadata;
|
|
7
|
+
chainAddresses;
|
|
8
|
+
constructor({ chainMetadata, chainAddresses, logger }) {
|
|
9
|
+
super({ uri: PARTIAL_URI_PLACEHOLDER, logger });
|
|
10
|
+
this.chainMetadata = chainMetadata || {};
|
|
11
|
+
this.chainAddresses = chainAddresses || {};
|
|
12
|
+
}
|
|
13
|
+
listRegistryContent() {
|
|
14
|
+
const chains = {};
|
|
15
|
+
Object.keys(this.chainMetadata).forEach((c) => {
|
|
16
|
+
chains[c] ||= {};
|
|
17
|
+
chains[c].metadata = PARTIAL_URI_PLACEHOLDER;
|
|
18
|
+
});
|
|
19
|
+
Object.keys(this.chainAddresses).forEach((c) => {
|
|
20
|
+
chains[c] ||= {};
|
|
21
|
+
chains[c].addresses = PARTIAL_URI_PLACEHOLDER;
|
|
22
|
+
});
|
|
23
|
+
return {
|
|
24
|
+
chains,
|
|
25
|
+
deployments: {},
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
getMetadata() {
|
|
29
|
+
return this.chainMetadata;
|
|
30
|
+
}
|
|
31
|
+
getAddresses() {
|
|
32
|
+
return this.chainAddresses;
|
|
33
|
+
}
|
|
34
|
+
removeChain(chainName) {
|
|
35
|
+
super.removeChain(chainName);
|
|
36
|
+
if (this.chainMetadata?.[chainName])
|
|
37
|
+
delete this.chainMetadata[chainName];
|
|
38
|
+
if (this.chainAddresses?.[chainName])
|
|
39
|
+
delete this.chainAddresses[chainName];
|
|
40
|
+
}
|
|
41
|
+
addWarpRoute(_config) {
|
|
42
|
+
throw new Error('Method not implemented.');
|
|
43
|
+
}
|
|
44
|
+
createOrUpdateChain(chain) {
|
|
45
|
+
if (chain.metadata)
|
|
46
|
+
this.chainMetadata[chain.chainName] = chain.metadata;
|
|
47
|
+
if (chain.addresses)
|
|
48
|
+
this.chainAddresses[chain.chainName] = chain.addresses;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import type { ChainMap, ChainMetadata, ChainName, WarpCoreConfig } from '@hyperlane-xyz/sdk';
|
|
2
|
+
import { ChainAddresses } from '../types.js';
|
|
3
|
+
import { BaseRegistry } from './BaseRegistry.js';
|
|
4
|
+
import { IRegistry, RegistryContent } from './IRegistry.js';
|
|
5
|
+
/**
|
|
6
|
+
* Shared code for sync registries like the FileSystem and Partial registries.
|
|
7
|
+
* This is required because of the inconsistent sync/async methods across registries.
|
|
8
|
+
* If the Infra package can be updated to work with async-only methods, this code can be moved to the BaseRegistry class.
|
|
9
|
+
*/
|
|
10
|
+
export declare abstract class SynchronousRegistry extends BaseRegistry implements IRegistry {
|
|
11
|
+
abstract listRegistryContent(): RegistryContent;
|
|
12
|
+
getChains(): Array<ChainName>;
|
|
13
|
+
abstract getMetadata(): ChainMap<ChainMetadata>;
|
|
14
|
+
getChainMetadata(chainName: ChainName): ChainMetadata | null;
|
|
15
|
+
abstract getAddresses(): ChainMap<ChainAddresses>;
|
|
16
|
+
getChainAddresses(chainName: ChainName): ChainAddresses | null;
|
|
17
|
+
addChain(chain: {
|
|
18
|
+
chainName: ChainName;
|
|
19
|
+
metadata?: ChainMetadata;
|
|
20
|
+
addresses?: ChainAddresses;
|
|
21
|
+
}): void;
|
|
22
|
+
updateChain(chain: {
|
|
23
|
+
chainName: ChainName;
|
|
24
|
+
metadata?: ChainMetadata;
|
|
25
|
+
addresses?: ChainAddresses;
|
|
26
|
+
}): void;
|
|
27
|
+
removeChain(chainName: ChainName): void;
|
|
28
|
+
abstract addWarpRoute(config: WarpCoreConfig): void;
|
|
29
|
+
protected abstract createOrUpdateChain(chain: {
|
|
30
|
+
chainName: ChainName;
|
|
31
|
+
metadata?: ChainMetadata;
|
|
32
|
+
addresses?: ChainAddresses;
|
|
33
|
+
}): void;
|
|
34
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { BaseRegistry } from './BaseRegistry.js';
|
|
2
|
+
/**
|
|
3
|
+
* Shared code for sync registries like the FileSystem and Partial registries.
|
|
4
|
+
* This is required because of the inconsistent sync/async methods across registries.
|
|
5
|
+
* If the Infra package can be updated to work with async-only methods, this code can be moved to the BaseRegistry class.
|
|
6
|
+
*/
|
|
7
|
+
export class SynchronousRegistry extends BaseRegistry {
|
|
8
|
+
getChains() {
|
|
9
|
+
return Object.keys(this.listRegistryContent().chains);
|
|
10
|
+
}
|
|
11
|
+
getChainMetadata(chainName) {
|
|
12
|
+
return this.getMetadata()[chainName] || null;
|
|
13
|
+
}
|
|
14
|
+
getChainAddresses(chainName) {
|
|
15
|
+
return this.getAddresses()[chainName] || null;
|
|
16
|
+
}
|
|
17
|
+
addChain(chain) {
|
|
18
|
+
const currentChains = this.listRegistryContent().chains;
|
|
19
|
+
if (currentChains[chain.chainName])
|
|
20
|
+
throw new Error(`Chain ${chain.chainName} already exists in registry`);
|
|
21
|
+
this.createOrUpdateChain(chain);
|
|
22
|
+
}
|
|
23
|
+
updateChain(chain) {
|
|
24
|
+
const currentChains = this.listRegistryContent();
|
|
25
|
+
if (!currentChains.chains[chain.chainName]) {
|
|
26
|
+
this.logger.debug(`Chain ${chain.chainName} not found in registry, adding it now`);
|
|
27
|
+
}
|
|
28
|
+
this.createOrUpdateChain(chain);
|
|
29
|
+
}
|
|
30
|
+
removeChain(chainName) {
|
|
31
|
+
const currentChains = this.listRegistryContent().chains;
|
|
32
|
+
if (!currentChains[chainName])
|
|
33
|
+
throw new Error(`Chain ${chainName} does not exist in registry`);
|
|
34
|
+
if (this.listContentCache?.chains[chainName])
|
|
35
|
+
delete this.listContentCache.chains[chainName];
|
|
36
|
+
if (this.metadataCache?.[chainName])
|
|
37
|
+
delete this.metadataCache[chainName];
|
|
38
|
+
if (this.addressCache?.[chainName])
|
|
39
|
+
delete this.addressCache[chainName];
|
|
40
|
+
}
|
|
41
|
+
}
|
package/dist/utils.d.ts
CHANGED
|
@@ -1,2 +1,4 @@
|
|
|
1
1
|
export declare function toYamlString(data: any, prefix?: string): string;
|
|
2
2
|
export declare function concurrentMap<A, B>(concurrency: number, xs: A[], mapFn: (val: A, idx: number) => Promise<B>): Promise<B[]>;
|
|
3
|
+
export declare function isObject(item: any): any;
|
|
4
|
+
export declare function objMerge(a: Record<string, any>, b: Record<string, any>, max_depth?: number): any;
|
package/dist/utils.js
CHANGED
|
@@ -13,3 +13,34 @@ export async function concurrentMap(concurrency, xs, mapFn) {
|
|
|
13
13
|
}
|
|
14
14
|
return res;
|
|
15
15
|
}
|
|
16
|
+
export function isObject(item) {
|
|
17
|
+
return item && typeof item === 'object' && !Array.isArray(item);
|
|
18
|
+
}
|
|
19
|
+
// Recursively merges b into a
|
|
20
|
+
// Where there are conflicts, b takes priority over a
|
|
21
|
+
export function objMerge(a, b, max_depth = 10) {
|
|
22
|
+
if (max_depth === 0) {
|
|
23
|
+
throw new Error('objMerge tried to go too deep');
|
|
24
|
+
}
|
|
25
|
+
if (isObject(a) && isObject(b)) {
|
|
26
|
+
const ret = {};
|
|
27
|
+
const aKeys = new Set(Object.keys(a));
|
|
28
|
+
const bKeys = new Set(Object.keys(b));
|
|
29
|
+
const allKeys = new Set([...aKeys, ...bKeys]);
|
|
30
|
+
for (const key of allKeys.values()) {
|
|
31
|
+
if (aKeys.has(key) && bKeys.has(key)) {
|
|
32
|
+
ret[key] = objMerge(a[key], b[key], max_depth - 1);
|
|
33
|
+
}
|
|
34
|
+
else if (aKeys.has(key)) {
|
|
35
|
+
ret[key] = a[key];
|
|
36
|
+
}
|
|
37
|
+
else {
|
|
38
|
+
ret[key] = b[key];
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
return ret;
|
|
42
|
+
}
|
|
43
|
+
else {
|
|
44
|
+
return b ? b : a;
|
|
45
|
+
}
|
|
46
|
+
}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hyperlane-xyz/registry",
|
|
3
3
|
"description": "A collection of configs, artifacts, and schemas for Hyperlane",
|
|
4
|
-
"version": "1.
|
|
4
|
+
"version": "1.3.0",
|
|
5
5
|
"dependencies": {
|
|
6
6
|
"yaml": "^2",
|
|
7
7
|
"zod": "^3.21.2"
|
|
@@ -16,6 +16,7 @@
|
|
|
16
16
|
"chai": "^4.3.6",
|
|
17
17
|
"eslint": "^9.0.0",
|
|
18
18
|
"eslint-config-prettier": "^9.1.0",
|
|
19
|
+
"eslint-plugin-yml": "^1.14.0",
|
|
19
20
|
"husky": "^9.0.11",
|
|
20
21
|
"lint-staged": "^15.2.2",
|
|
21
22
|
"mocha": "^10.2.0",
|
|
@@ -30,7 +31,7 @@
|
|
|
30
31
|
".": "./dist/index.js",
|
|
31
32
|
"./chains/schema.json": "./dist/chains/schema.json",
|
|
32
33
|
"./chains/*": "./dist/chains/*",
|
|
33
|
-
"./
|
|
34
|
+
"./fs": "./dist/index-fs.js"
|
|
34
35
|
},
|
|
35
36
|
"types": "./dist/index.d.ts",
|
|
36
37
|
"typesVersions": {
|
|
@@ -57,14 +58,15 @@
|
|
|
57
58
|
],
|
|
58
59
|
"license": "MIT",
|
|
59
60
|
"scripts": {
|
|
60
|
-
"clean": "rm -rf ./dist ./tmp",
|
|
61
61
|
"build": "tsx ./scripts/build.ts && tsc --project tsconfig.publish.json",
|
|
62
|
-
"
|
|
62
|
+
"clean": "rm -rf ./dist ./tmp",
|
|
63
|
+
"lint": "eslint ./src/ ./chains ./deployments",
|
|
64
|
+
"lint:fix": "yarn lint --fix",
|
|
63
65
|
"prettier": "prettier --write ./chains ./deployments",
|
|
64
|
-
"test:unit": "yarn build && mocha --config .mocharc.json './test/unit/*.test.ts' --exit",
|
|
65
|
-
"test:health": "yarn build && mocha --config .mocharc.json './test/health/*.test.ts' --exit",
|
|
66
66
|
"prepare": "husky",
|
|
67
67
|
"release": "yarn build && yarn changeset publish",
|
|
68
|
+
"test:unit": "yarn build && mocha --config .mocharc.json './test/unit/*.test.ts' --exit",
|
|
69
|
+
"test:health": "yarn build && mocha --config .mocharc.json './test/health/*.test.ts' --exit",
|
|
68
70
|
"version:prepare": "yarn changeset version && yarn install --no-immutable",
|
|
69
71
|
"version:check": "yarn changeset status"
|
|
70
72
|
},
|
package/dist/index-local.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { LocalRegistry } from './registry/LocalRegistry.js';
|