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

69 lines
2.8 KiB
JavaScript

const fs = require('fs');
const path = require('path');
const Contracts = require('./contracts');
module.exports = {
createYaml: (env) => {
const createInstanceBlock = ({ name, amount, currency, network, startBlocks, address }) => ({
name: `${name}-${amount}-${currency}`,
network,
mappingFile: '../src/mapping-instance.ts',
startBlock: startBlocks.prod,
address: `"${address}"`,
abi: 'Instance',
entities: ['Deposit', 'Withdrawal'],
abis: [
{
name: 'Instance',
path: '../abis/Instance.json',
},
],
events: [
{
event: 'Deposit(indexed bytes32,uint32,uint256)',
handler: 'handleDeposit',
},
{
event: 'Withdrawal(address,bytes32,indexed address,uint256)',
handler: 'handleWithdrawal',
},
],
});
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}`;
let reExportContent = '';
Contracts.forEach(({ address, name, network, amount, currency }) => {
if (network === env && address != null) {
contractsToInstancesContent += `contractsToInstances.set("${address.toLowerCase()}",${space}//${space}${name}-${currency}-${amount}${newLine}${doubleSpace}"${currency}${'-'}${amount}"${newLine});${newLine}`;
contractsToInstancesContent += `contractsToInstances.set("0x${address
.replace('0x', '')
.toUpperCase()}",${space}//${space}${name}-${currency}-${amount}${newLine}${doubleSpace}"${currency}${'-'}${amount}"${newLine});${newLine}`;
contractsToInstancesContent += `contractsToInstances.set("${address}",${space}//${space}${name}-${currency}-${amount}${newLine}${doubleSpace}"${currency}${'-'}${amount}"${newLine});${newLine}`;
}
if (network === env) {
reExportContent += `${readOnlyComment}${newLine}export * from "./${name}-${amount}-${currency}/Instance";${newLine}`;
}
});
contractsToInstancesContent += readOnlyComment;
const targetFile = path.join(__dirname, '../../../src/', 'contractsToInstances.ts');
fs.writeFileSync(targetFile, contractsToInstancesContent, 'utf8');
const targetIndexFile = path.join(__dirname, '../../../generated/', 'index.ts');
fs.writeFileSync(targetIndexFile, reExportContent, 'utf8');
return Contracts.map(({ prod, name, amount, currency, network, address }) => {
const startBlocks = { prod };
if (network === env) {
return createInstanceBlock({ name, startBlocks, amount, currency, network, address });
}
}).filter((e) => e !== undefined);
},
};