"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.importVip180Tokens = void 0;
const fs_1 = __importDefault(require("fs"));
const path_1 = __importDefault(require("path"));
const fetch_1 = require("../../fetch");
const importVip180Tokens = async (outputDir) => {
    try {
        console.log("importing Vechain tokens...");
        const { tokens, hash } = await (0, fetch_1.fetchTokensFromCALService)({ blockchain_name: "vechain" }, [
            "id",
            "ticker",
            "name",
            "contract_address",
            "decimals",
        ]);
        const vip180Tokens = 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 [tokenIdentifier, token.ticker, token.name, token.contract_address, token.decimals];
        });
        const filePath = path_1.default.join(outputDir, "vip180");
        const vip180TypeStringified = `export type Vip180Token = [
  string, // token identifier
  string, // ticker
  string, // name
  string, // contract address
  number, // decimals
];`;
        fs_1.default.writeFileSync(`${filePath}.json`, JSON.stringify(vip180Tokens));
        if (hash) {
            fs_1.default.writeFileSync(`${filePath}-hash.json`, JSON.stringify(hash));
        }
        fs_1.default.writeFileSync(`${filePath}.ts`, `${vip180TypeStringified}

import tokens from "./vip180.json";

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

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