Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
Object.keys(allContracts).forEach(contractName => {
let target = contractName;
let source = contractName;
if (typeof allContracts[contractName] === 'object') {
target = allContracts[contractName].target || target;
source = allContracts[contractName].source || source;
}
// get the abis from the network's deploy from synthetix
const { abi } = snx.getSource({ network, contract: source }) || {};
// some environments might not have an ABI for this contract yet
if (abi) {
// track which contracts exist in this netork
contractsInNetwork.push(contractName);
// now create import header for index files
const importStringForIndexFile = `import ${contractName} from './${contractName}';`;
srcNetworkIndexFileHeader.push(importStringForIndexFile);
// now only for source contracts in the original contract object
if (contractName in contracts) {
// write out ABI files (using ABIs from mainnet deploy)
writeABIFileAsJS(network, contractName, abi);
abiNetworkIndexFileHeader.push(importStringForIndexFile);
// and track it
() => {
expect(snxjs[synth].contract.interface.abi).toEqual(
snx.getSource({ network, contract }).abi
);
};
});
const writeAllABIFiles = network => {
const folder = path.join(__dirname, '..', 'lib', 'abis', network);
if (!fs.existsSync(folder)) {
fs.mkdirSync(folder);
}
const sources = snx.getSource({ network });
for (const [source, { abi }] of Object.entries(sources)) {
const abiPath = path.join(folder, `${source}.json`);
fs.writeFile(abiPath, JSON.stringify(abi, null, '\t') + '\n', err => {
if (err) {
console.log(err);
} else {
console.log(`ABI ${source}.son on ${network} successfully generated locally.`);
}
});
}
};