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

69 lines
2.8 KiB
JavaScript
Raw Permalink 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}`;
2021-06-14 15:58:57 +03:00
let reExportContent = '';
2021-06-08 19:08:11 +03:00
2021-06-14 15:58:57 +03:00
Contracts.forEach(({ address, name, network, amount, currency }) => {
if (network === env && address != null) {
2021-06-10 14:39:00 +03:00
contractsToInstancesContent += `contractsToInstances.set("${address.toLowerCase()}",${space}//${space}${name}-${currency}-${amount}${newLine}${doubleSpace}"${currency}${'-'}${amount}"${newLine});${newLine}`;
2023-09-21 11:04:03 +01:00
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}`;
2021-06-08 19:08:11 +03:00
}
if (network === env) {
2021-06-14 15:58:57 +03:00
reExportContent += `${readOnlyComment}${newLine}export * from "./${name}-${amount}-${currency}/Instance";${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-14 15:58:57 +03:00
const targetIndexFile = path.join(__dirname, '../../../generated/', 'index.ts');
fs.writeFileSync(targetIndexFile, reExportContent, '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
},
};