"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
    function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
    return new (P || (P = Promise))(function (resolve, reject) {
        function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
        function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
        function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
        step((generator = generator.apply(thisArg, _arguments || [])).next());
    });
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.closeOutWumboSubmit = void 0;
const spl_token_1 = require("@solana/spl-token");
const spl_utils_1 = require("@strata-foundation/spl-utils");
const closeOutWumboSubmit = ({ tokenBondingSdk, tokens, expectedOutputAmountByToken, setStatus, }) => __awaiter(void 0, void 0, void 0, function* () {
    var _a, _b;
    let processedTokenCount = 0;
    let innerError = null;
    if (!tokenBondingSdk)
        return;
    setStatus("Recouping SOL");
    for (let token of tokens) {
        const { publicKey: tokenBondingKey, targetMint } = token.tokenBonding;
        setStatus(`Swapping: ${(_b = (_a = token.metadata) === null || _a === void 0 ? void 0 : _a.data) === null || _b === void 0 ? void 0 : _b.name}`);
        try {
            yield tokenBondingSdk.swap({
                baseMint: targetMint,
                targetMint: spl_token_1.NATIVE_MINT,
                baseAmount: (0, spl_utils_1.toNumber)(token.account.amount, token.mint),
                expectedOutputAmount: expectedOutputAmountByToken[token.publicKey.toBase58()],
                slippage: 0.05,
            });
            processedTokenCount += 0;
        }
        catch (err) {
            // do nothing with error
            console.log(err);
        }
    }
    if (processedTokenCount == tokens.length) {
        setStatus("successful");
    }
    else {
        setStatus("orphaned");
    }
});
exports.closeOutWumboSubmit = closeOutWumboSubmit;
//# sourceMappingURL=closeOutWumboSubmit.js.map