forked from Synthetixio/synthetix-subgraph
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprepare-abis.js
37 lines (31 loc) · 1.23 KB
/
prepare-abis.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
/* eslint-disable @typescript-eslint/no-var-requires */
'use strict';
const fs = require('fs');
const path = require('path');
const { gray, yellow } = require('chalk');
const program = require('commander');
const snx = require('synthetix');
program.action(async () => {
const abiPath = path.join(__dirname, 'abis');
const sources = snx.getSource({ network: 'mainnet' });
const doesEntryHaveMultidimensionalArrays = ({ type }) => /\[[0-9]*\]\[[0-9]*\]/.test(type);
Object.entries(sources)
.map(([source, { abi }]) => {
const { name } =
abi.find(
({ inputs = [], outputs = [] }) =>
inputs.find(doesEntryHaveMultidimensionalArrays) || outputs.find(doesEntryHaveMultidimensionalArrays),
) || {};
if (name) {
console.log(yellow(`Note: Found multidimensional array in ABI and stripping it: ${source}.${name}`));
abi = abi.filter(entry => entry.name !== name);
}
return [source, { abi }];
})
.forEach(([source, { abi }]) => {
const targetFile = path.join(abiPath, `${source}.json`);
console.log(gray('Writing ABI:', `${source}.json`));
fs.writeFileSync(targetFile, JSON.stringify(abi, null, 2) + '\n');
});
});
program.parse(process.argv);