-
Notifications
You must be signed in to change notification settings - Fork 72
/
config-utils.ts
99 lines (89 loc) · 3.19 KB
/
config-utils.ts
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
import { writeFileSync } from 'fs';
import { join } from 'path';
import { Config, LocalOrCloudProvider } from '@api3/airnode-node';
import { go } from '@api3/promise-utils';
import { format } from 'prettier';
import {
cliPrint,
getDeployedContract,
readChainId,
readIntegrationInfo,
SameOrCrossChain,
getExistingAirnodeRrpV0,
} from '../src';
import { version as packageVersion } from '../package.json';
export const createCloudProviderConfiguration = (generateExampleFile: boolean): LocalOrCloudProvider => {
if (generateExampleFile) {
return {
type: 'local',
};
}
const integrationInfo = readIntegrationInfo();
const airnodeType = integrationInfo.airnodeType;
switch (airnodeType) {
case 'aws':
return {
type: airnodeType,
region: 'us-east-1',
disableConcurrencyReservations: true,
};
case 'local':
return {
type: airnodeType,
};
case 'gcp': {
return {
type: airnodeType,
region: 'us-east1',
projectId: integrationInfo.gcpProjectId!,
disableConcurrencyReservations: true,
};
}
}
};
export const getAirnodeRrpAddress = async (generateExampleFile: boolean, chain = SameOrCrossChain.same) => {
if (generateExampleFile) return '0x5FbDB2315678afecb367f032d93F642f64180aa3';
if (chain === SameOrCrossChain.cross) {
const crossChainNetwork = readIntegrationInfo().crossChainNetwork!;
// localhost requires lookup with getDeployedContract below
if (crossChainNetwork !== 'localhost') {
return getExistingAirnodeRrpV0(crossChainNetwork);
}
}
const airnodeRrp = await getDeployedContract('@api3/airnode-protocol/contracts/rrp/AirnodeRrpV0.sol');
return airnodeRrp.address;
};
export const getChainId = async (generateExampleFile: boolean, chain = SameOrCrossChain.same) =>
(generateExampleFile ? 31337 : await readChainId(chain)).toString();
export const createNodeVersion = () => {
return packageVersion;
};
/**
* If the AirnodeRrpV0DryRun contract has been deployed, add its address to the config file,
* otherwise, return the config file as is.
*
* Note when using a public blockchain an AirnodeRrpV0DryRun deployment is not necessary as we default
* to using the API3 deployment
*/
export const addAirnodeRrpV0DryRunAddress = async (config: Config) => {
const goAirnodeRrpDryRun = await go(() =>
getDeployedContract('@api3/airnode-protocol/contracts/rrp/AirnodeRrpV0DryRun.sol')
);
if (!goAirnodeRrpDryRun.success) {
return config;
}
const airnodeRrpDryRun = goAirnodeRrpDryRun.data;
return {
...config,
chains: [
{ ...config.chains[0], contracts: { ...config.chains[0].contracts, AirnodeRrpDryRun: airnodeRrpDryRun.address } },
],
};
};
export const generateConfigFile = async (dirname: string, config: Config, generateExampleFile: boolean) => {
const filename = generateExampleFile ? 'config.example.json' : 'config.json';
const updatedConfig = await addAirnodeRrpV0DryRunAddress(config);
const formattedConfig = format(JSON.stringify(updatedConfig, null, 2), { parser: 'json', printWidth: 120 });
writeFileSync(join(dirname, filename), formattedConfig);
cliPrint.info(`A '${filename}' has been created.`);
};