"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.importTRC20Tokens = void 0;
const fs_1 = __importDefault(require("fs"));
const path_1 = __importDefault(require("path"));
const fetch_1 = require("../../fetch");
const importTRC20Tokens = async (outputDir) => {
    try {
        console.log("importing trc20 tokens...");
        const { tokens, hash } = await (0, fetch_1.fetchTokensFromCALService)({ blockchain_name: "tron" }, [
            "id",
            "ticker",
            "name",
            "contract_address",
            "decimals",
            "delisted",
            "live_signature",
        ]);
        const trc20tokens = tokens.map(token => {
            const [, , tokenIdentifier] = token.id.split("/");
            return [
                tokenIdentifier,
                token.ticker,
                token.name,
                token.contract_address,
                token.decimals,
                token.delisted,
                token.live_signature,
            ];
        });
        const filePath = path_1.default.join(outputDir, "trc20");
        const trc20TypeStringified = `export type TRC20Token = [
  string, // id
  string, // ticker
  string, // name
  string, // contractAddress
  number, // decimals
  boolean?, // delisted
  string?, // live signature
];`;
        fs_1.default.writeFileSync(`${filePath}.json`, JSON.stringify(trc20tokens));
        if (hash) {
            fs_1.default.writeFileSync(`${filePath}-hash.json`, JSON.stringify(hash));
        }
        fs_1.default.writeFileSync(`${filePath}.ts`, `${trc20TypeStringified}

import tokens from "./trc20.json";

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

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