-
Notifications
You must be signed in to change notification settings - Fork 10
/
render-templates.js
48 lines (44 loc) · 1.29 KB
/
render-templates.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
const fs = require('fs-extra');
const mustache = require('mustache');
const chainNameToChainId = {
xdai: 100,
mainnet: 1,
goerli: 5,
sepolia: 11155111,
};
async function main() {
const networkName = process.argv[2];
const chainId = chainNameToChainId[networkName];
const deployments = JSON.parse(fs.readFileSync('networks.json', 'utf8'));
const {
address: lgtcrFactoryAddr,
startBlock: lgtcrFactoryStartBlock,
} = deployments['LightGTCRFactory'][chainId];
const {
address: gtcrFactoryAddr,
startBlock: gtcrFactoryStartBlock,
} = deployments['GTCRFactory'][chainId];
const templateData = {
network: networkName,
};
templateData['LightGTCRFactory'] = {
address: lgtcrFactoryAddr,
addressLowerCase: lgtcrFactoryAddr.toLowerCase(),
startBlock: lgtcrFactoryStartBlock,
};
templateData['GTCRFactory'] = {
address: gtcrFactoryAddr,
addressLowerCase: gtcrFactoryAddr.toLowerCase(),
startBlock: gtcrFactoryStartBlock,
};
for (const templatedFileDesc of [['subgraph', 'yaml']]) {
const template = fs
.readFileSync(`${templatedFileDesc[0]}.template.${templatedFileDesc[1]}`)
.toString();
fs.writeFileSync(
`${templatedFileDesc[0]}.${templatedFileDesc[1]}`,
mustache.render(template, templateData),
);
}
}
main();