65 lines
2.4 KiB
JavaScript
65 lines
2.4 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 (address != null) {
|
|
contractsToInstancesContent += `contractsToInstances.set("${address.toLowerCase()}_${network}",${space}//${space}${name}-${currency}-${amount}${newLine}${doubleSpace}"${currency}${'-'}${amount}"${newLine});${newLine}`;
|
|
}
|
|
if (network === env && reExportContent === '') {
|
|
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);
|
|
},
|
|
};
|