"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.importESDTTokens = void 0;
const fs_1 = __importDefault(require("fs"));
const path_1 = __importDefault(require("path"));
const fetch_1 = require("../../fetch");
const importESDTTokens = async (outputDir) => {
    try {
        console.log("importing esdt tokens...");
        // const { tokens, hash } = await fetchTokensFromCALService({ blockchain_name: "multiversx" }, [
        const { tokens, hash } = await (0, fetch_1.fetchTokensFromCALService)({ blockchain_name: "elrond" }, [
            "ticker",
            "id",
            "decimals",
            "live_signature",
            "name",
        ]);
        const esdtTokens = tokens.map(token => {
            // This shouldn't be necessary, we should consumme the ID directly
            // but for now, I'll keep this to maintain a compatibility layer
            // with the content of the CDN (which should be removed soon)
            const [, , tokenIdentifier] = token.id.split("/");
            return [token.ticker, tokenIdentifier, token.decimals, token.live_signature, token.name];
        });
        const filePath = path_1.default.join(outputDir, "esdt");
        const estTypeStringified = `export type MultiversXESDTToken = [
  string, // ticker
  string, // identifier
  number, // decimals
  string, // signature
  string, // name
];`;
        fs_1.default.writeFileSync(`${filePath}.json`, JSON.stringify(esdtTokens));
        if (hash) {
            fs_1.default.writeFileSync(`${filePath}-hash.json`, JSON.stringify(hash));
        }
        fs_1.default.writeFileSync(`${filePath}.ts`, `${estTypeStringified}

import tokens from "./esdt.json";

${hash ? `export { default as hash } from "./esdt-hash.json";` : ""}

export default tokens as MultiversXESDTToken[];
`);
        console.log("importing esdt tokens sucess");
    }
    catch (err) {
        console.error(err);
    }
};
exports.importESDTTokens = importESDTTokens;
//# sourceMappingURL=index.js.map