@ajna-finance/sdk
Version:
A typescript SDK that can be used to create Dapps in Ajna ecosystem.
55 lines • 2.22 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.updateAbis = void 0;
const tslib_1 = require("tslib");
const utils_1 = require("ethers/lib/utils");
const fs_1 = tslib_1.__importDefault(require("fs"));
const node_path_1 = tslib_1.__importDefault(require("node:path"));
/**
* Iterate through ABIs in a location specified by the environment.
* Filter in ABIs we care about, translate and write Ethers.js-consumable ABIs
* in the appropriate location.
*/
const updateAbis = function () {
const dir = fs_1.default.opendirSync(process.env.AJNA_ABIS);
let file;
while ((file = dir.readSync()) !== null) {
if (abisWeCareAbout.has(file.name)) {
// read and parse JSON output written by contracts tooling
const jsonAbi = fs_1.default.readFileSync(node_path_1.default.join(dir.path, file.name));
let parsed = JSON.parse(jsonAbi.toString());
if (parsed.abi) {
parsed = parsed.abi;
}
// remove adjacent duplicate definitions
for (let i = 0; i < parsed.length; ++i) {
if (i > 0 && JSON.stringify(parsed[i - 1]) === JSON.stringify(parsed[i])) {
parsed.splice(i, 1);
}
}
// create the Ethers.js Interface used for translation,
// and pass only the desired ABI content
const iface = new utils_1.Interface(parsed);
// perform the translation
const formattedAbi = iface.format(utils_1.FormatTypes.json).toString();
const translatedAbi = JSON.stringify(JSON.parse(formattedAbi));
// write the translated ABI to disk
fs_1.default.writeFileSync(node_path_1.default.join(process.cwd(), 'src/abis', file.name), translatedAbi);
}
}
};
exports.updateAbis = updateAbis;
const abisWeCareAbout = new Set([
'AjnaToken.json',
'BurnWrappedAjna.json',
'ERC20.json',
'ERC20Pool.json',
'ERC20PoolFactory.json',
'ERC721.json',
'ERC721Pool.json',
'ERC721PoolFactory.json',
'GrantFund.json',
'PoolInfoUtils.json',
'PositionManager.json',
]);
//# sourceMappingURL=update-abis.js.map