tornado-subgraph/mustache/templates/instance/create-yaml.js

65 lines
2.4 KiB
JavaScript
Raw Normal View History

2021-06-08 18:08:11 +02:00
const fs = require('fs');
const path = require('path');
const Contracts = require('./contracts');
module.exports = {
createYaml: (env) => {
2021-06-10 10:49:47 +02:00
const createInstanceBlock = ({ name, amount, currency, network, startBlocks, address }) => ({
name: `${name}-${amount}-${currency}`,
2021-06-09 16:20:37 +02:00
network,
2021-06-08 18:08:11 +02:00
mappingFile: '../src/mapping-instance.ts',
2021-06-09 16:04:11 +02:00
startBlock: startBlocks.prod,
2021-06-10 10:49:47 +02:00
address: `"${address}"`,
2021-06-09 16:04:11 +02:00
abi: 'Instance',
2021-06-08 18:08:11 +02:00
entities: ['Deposit', 'Withdrawal'],
abis: [
{
name: 'Instance',
2021-06-09 16:39:13 +02:00
path: '../abis/Instance.json',
},
2021-06-08 18:08:11 +02:00
],
events: [
{
event: 'Deposit(indexed bytes32,uint32,uint256)',
handler: 'handleDeposit',
},
{
event: 'Withdrawal(address,bytes32,indexed address,uint256)',
handler: 'handleWithdrawal',
2021-06-09 16:39:13 +02:00
},
2021-06-08 18:08:11 +02:00
],
});
const newLine = '\n';
const readOnlyComment = `// this is a read only file generated by manual inputs to file mustache/templates/rates/contracts.js.${newLine}`;
const space = '\xa0';
const doubleSpace = space + space;
let contractsToInstancesContent = `${readOnlyComment}export let contractsToInstances = new Map<string, string>();${newLine}`;
2021-06-14 14:58:57 +02:00
let reExportContent = '';
2021-06-08 18:08:11 +02:00
2021-06-14 14:58:57 +02:00
Contracts.forEach(({ address, name, network, amount, currency }) => {
2021-06-08 18:08:11 +02:00
if (address != null) {
2021-06-10 13:39:00 +02:00
contractsToInstancesContent += `contractsToInstances.set("${address.toLowerCase()}",${space}//${space}${name}-${currency}-${amount}${newLine}${doubleSpace}"${currency}${'-'}${amount}"${newLine});${newLine}`;
2021-06-08 18:08:11 +02:00
}
2021-06-14 14:58:57 +02:00
if (network === env && reExportContent === '') {
reExportContent += `${readOnlyComment}${newLine}export * from "./${name}-${amount}-${currency}/Instance";${newLine}`;
}
2021-06-08 18:08:11 +02:00
});
contractsToInstancesContent += readOnlyComment;
const targetFile = path.join(__dirname, '../../../src/', 'contractsToInstances.ts');
fs.writeFileSync(targetFile, contractsToInstancesContent, 'utf8');
2021-06-14 14:58:57 +02:00
const targetIndexFile = path.join(__dirname, '../../../generated/', 'index.ts');
fs.writeFileSync(targetIndexFile, reExportContent, 'utf8');
2021-06-10 10:49:47 +02:00
return Contracts.map(({ prod, name, amount, currency, network, address }) => {
2021-06-09 16:04:11 +02:00
const startBlocks = { prod };
if (network === env) {
2021-06-10 10:49:47 +02:00
return createInstanceBlock({ name, startBlocks, amount, currency, network, address });
2021-06-09 16:04:11 +02:00
}
2021-06-09 16:39:13 +02:00
}).filter((e) => e !== undefined);
2021-06-08 18:08:11 +02:00
},
};