-
Notifications
You must be signed in to change notification settings - Fork 18
/
render-templates.js
79 lines (75 loc) · 2.16 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
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
const fs = require("fs-extra");
const mustache = require("mustache");
module.exports = function (callback) {
(async () => {
const chainId = await web3.eth.net.getId();
const templateData = {
network:
{
[1]: "mainnet",
[4]: "rinkeby",
[77]: "poa-sokol",
[100]: "xdai",
}[chainId] || "development",
nuancedBinaryTemplateId:
{
[1]: 6,
}[chainId] || 5,
};
for (const contractName of [
"FPMMDeterministicFactory",
"FPMMDeterministicFactoryV2",
"FixedProductMarketMaker",
"ConditionalTokens",
"Realitio",
"RealitioProxy",
"RealitioScalarAdapter",
"ERC20Detailed",
"DXTokenRegistry",
"GeneralizedTCR",
"UniswapV2Factory",
"SwaprFactory",
"UniswapV2Pair",
"WETH9",
"DAI",
"USDC",
"USDT",
"StakingRewardsFactory",
"StakingRewardsDistribution",
]) {
const { abi } = fs.readJsonSync(`build/contracts/${contractName}.json`);
fs.outputJsonSync(`abis/${contractName}.json`, abi, { spaces: 2 });
const C = artifacts.require(contractName);
try {
const { address } = C;
templateData[contractName] = {
address,
addressLowerCase: address.toLowerCase(),
startBlock: (await web3.eth.getTransactionReceipt(C.transactionHash))
.blockNumber,
};
} catch (e) {
console.error("Error rendering templates: ", e);
}
}
for (const templatedFileDesc of [
["subgraph", "yaml"],
["src/utils/token", "ts"],
["src/FPMMDeterministicFactoryMapping", "ts"],
["src/ConditionalTokensMapping", "ts"],
["src/RealitioMapping", "ts"],
["src/UniswapV2PairMapping", "ts"],
["src/StakingRewardsDistributionMapping", "ts"],
]) {
const template = fs
.readFileSync(
`${templatedFileDesc[0]}.template.${templatedFileDesc[1]}`
)
.toString();
fs.writeFileSync(
`${templatedFileDesc[0]}.${templatedFileDesc[1]}`,
mustache.render(template, templateData)
);
}
})().then(() => callback(), callback);
};