-
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathupdateAddresses.js
57 lines (50 loc) · 1.55 KB
/
updateAddresses.js
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
const fs = require('fs-extra');
const path = require('path');
const yaml = require('js-yaml');
const { t } = require('typy');
function getNetworkNameForSubgraph() {
switch (process.env.SUBGRAPH) {
case undefined:
case 'tomafrench/notestream':
return 'mainnet';
case 'tomafrench/notestream-goerli':
return 'goerli';
case 'tomafrench/notestream-kovan':
return 'kovan';
case 'tomafrench/notestream-rinkeby':
return 'rinkeby';
case 'tomafrench/notestream-ropsten':
return 'ropsten';
case 'tomafrench/notestream-local':
return 'local';
default:
return null;
}
}
(async () => {
const networkName = process.env.NETWORK_NAME || getNetworkNameForSubgraph();
const addressesDirectory = path.join(
__dirname,
'../contract-artifacts/addresses/',
);
const addressesFilePath = path.join(
addressesDirectory,
`${networkName}.json`,
);
const addresses = JSON.parse(
await fs.readFile(addressesFilePath, { encoding: 'utf-8' }),
);
const networksFilePath = path.join(__dirname, 'networks.yaml');
const networks = yaml.load(
await fs.readFile(networksFilePath, { encoding: 'utf-8' }),
);
const network = t(networks, networkName).safeObject;
if (t(network).isFalsy) {
throw new Error(
'Please set either a "NETWORK_NAME" or a "SUBGRAPH" environment variable',
);
}
network.contracts.NoteStream.address = addresses.NoteStream;
await fs.writeFile(networksFilePath, yaml.safeDump(networks));
console.log('🎉 networks.yaml successfully updated');
})();