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

58 lines
2.0 KiB
JavaScript
Raw Normal View History

2021-06-08 19:08:11 +03:00
const fs = require('fs');
const path = require('path');
const Contracts = require('./contracts');
module.exports = {
createYaml: (env) => {
2021-06-10 11:49:47 +03:00
const createInstanceBlock = ({ name, amount, currency, network, startBlocks, address }) => ({
name: `${name}-${amount}-${currency}`,
2021-06-09 17:20:37 +03:00
network,
2021-06-08 19:08:11 +03:00
mappingFile: '../src/mapping-instance.ts',
2021-06-09 17:04:11 +03:00
startBlock: startBlocks.prod,
2021-06-10 11:49:47 +03:00
address: `"${address}"`,
2021-06-09 17:04:11 +03:00
abi: 'Instance',
2021-06-08 19:08:11 +03:00
entities: ['Deposit', 'Withdrawal'],
abis: [
{
name: 'Instance',
2021-06-09 17:39:13 +03:00
path: '../abis/Instance.json',
},
2021-06-08 19:08:11 +03:00
],
events: [
{
event: 'Deposit(indexed bytes32,uint32,uint256)',
handler: 'handleDeposit',
},
{
event: 'Withdrawal(address,bytes32,indexed address,uint256)',
handler: 'handleWithdrawal',
2021-06-09 17:39:13 +03:00
},
2021-06-08 19:08:11 +03: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}`;
Contracts.forEach(({ address, name, amount, currency }) => {
if (address != null) {
2021-06-10 11:49:47 +03:00
contractsToInstancesContent += `contractsToInstances.set("${address.toLowerCase()}",${space}//${space}${name}-${currency}-${amount}${newLine}${doubleSpace}"${amount}${'-'}${currency}"${newLine});${newLine}`;
2021-06-08 19:08:11 +03:00
}
});
contractsToInstancesContent += readOnlyComment;
const targetFile = path.join(__dirname, '../../../src/', 'contractsToInstances.ts');
fs.writeFileSync(targetFile, contractsToInstancesContent, 'utf8');
2021-06-10 11:49:47 +03:00
return Contracts.map(({ prod, name, amount, currency, network, address }) => {
2021-06-09 17:04:11 +03:00
const startBlocks = { prod };
if (network === env) {
2021-06-10 11:49:47 +03:00
return createInstanceBlock({ name, startBlocks, amount, currency, network, address });
2021-06-09 17:04:11 +03:00
}
2021-06-09 17:39:13 +03:00
}).filter((e) => e !== undefined);
2021-06-08 19:08:11 +03:00
},
};