"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.importSPLTokens = void 0;
const fs_1 = __importDefault(require("fs"));
const path_1 = __importDefault(require("path"));
const fetch_1 = require("../../fetch");
const importSPLTokens = async (outputDir) => {
    try {
        console.log("importing spl tokens...");
        const { tokens, hash } = await (0, fetch_1.fetchTokensFromCALService)({ blockchain_name: "solana" }, [
            "id",
            "network",
            "name",
            "ticker",
            "contract_address",
            "decimals",
        ]);
        const splTokens = tokens.map(token => [
            token.id,
            token.network,
            token.name,
            token.ticker,
            token.contract_address,
            token.decimals,
        ]);
        const filePath = path_1.default.join(outputDir, "spl");
        const splTypeStringified = `export type SPLToken = [
  string, // CAL id
  string, // network
  string, // name
  string, // ticker
  string, // address
  number, // decimals
];`;
        fs_1.default.writeFileSync(`${filePath}.json`, JSON.stringify(splTokens));
        if (hash) {
            fs_1.default.writeFileSync(`${filePath}-hash.json`, JSON.stringify(hash));
        }
        fs_1.default.writeFileSync(`${filePath}.ts`, `${splTypeStringified}

import tokens from "./spl.json";

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

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