tornado-subgraph/mustache/templates/instance/create-yaml.js
2021-06-10 12:47:29 +03:00

57 lines
1.9 KiB
JavaScript

const fs = require('fs');
const path = require('path');
const Contracts = require('./contracts');
const { createStartBlock } = require('../common');
module.exports = {
createYaml: (env) => {
const createInstanceBlock = ({ name, startBlocks, address }) => ({
name,
mappingFile: '../src/mapping-instance.ts',
startBlock: createStartBlock(startBlocks, env),
address,
entities: ['Deposit', 'Withdrawal'],
abis: [
{
name: 'Instance',
file: './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}`;
Contracts.forEach(({ address, name, amount, currency }) => {
if (address != null) {
contractsToInstancesContent += `contractsToInstances.set(${address.toLowerCase()},${space}//${space}${name}-${currency}-${amount}${newLine}${doubleSpace}${amount}${'-'}${currency}${newLine});${newLine}`;
}
});
contractsToInstancesContent += readOnlyComment;
const targetFile = path.join(__dirname, '../../../src/', 'contractsToInstances.ts');
fs.writeFileSync(targetFile, contractsToInstancesContent, 'utf8');
return Contracts.map(({ type, prod, test, name, address }) => {
const startBlocks = { prod, test };
return createInstanceBlock({ name, startBlocks, address })
});
},
};