-
Notifications
You must be signed in to change notification settings - Fork 73
Expand file tree
/
Copy pathgetOrbitChainContractVersions.ts
More file actions
53 lines (45 loc) · 1.35 KB
/
getOrbitChainContractVersions.ts
File metadata and controls
53 lines (45 loc) · 1.35 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
import type { Address } from 'viem';
import { runDockerCommand } from './runDockerCommand';
import { DEFAULT_ORBIT_ACTIONS_IMAGE } from './constants';
export type GetOrbitChainContractVersionsParameters = {
image?: string;
inboxAddress: Address;
network: string;
env?: Record<string, string | undefined>;
};
export type GetOrbitChainContractVersionsResult = {
versions: Record<string, string | null>;
upgradeRecommendation: unknown;
};
export async function getOrbitChainContractVersions({
image = DEFAULT_ORBIT_ACTIONS_IMAGE,
inboxAddress,
network,
env,
}: GetOrbitChainContractVersionsParameters): Promise<GetOrbitChainContractVersionsResult> {
const { stdout } = await runDockerCommand({
image,
entrypoint: 'yarn',
command: ['--silent', 'orbit:contracts:version', '--network', network, '--no-compile'],
env: {
...env,
INBOX_ADDRESS: inboxAddress,
JSON_OUTPUT: 'true',
},
});
let parsed: unknown;
try {
parsed = JSON.parse(stdout) as unknown;
} catch {
throw new Error('Failed to parse Orbit chain contract versions');
}
if (
typeof parsed !== 'object' ||
parsed === null ||
!('versions' in parsed) ||
!('upgradeRecommendation' in parsed)
) {
throw new Error('Failed to parse Orbit chain contract versions');
}
return parsed as GetOrbitChainContractVersionsResult;
}