"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 });
const spl_token_1 = require("@solana/spl-token");
const web3_js_1 = require("@solana/web3.js");
const solana_1 = require("../solana");
const wasm_1 = require("../solana/wasm");
function claimShares(connection, payerAddress, program_id, from_mint, to_mint, output_token_account, lp_share_token_account, amount) {
    return __awaiter(this, void 0, void 0, function* () {
        const { authority_address, claim_shares } = yield wasm_1.importMigrationWasm();
        const approvalIx = spl_token_1.Token.createApproveInstruction(spl_token_1.TOKEN_PROGRAM_ID, new web3_js_1.PublicKey(lp_share_token_account), new web3_js_1.PublicKey(authority_address(program_id)), new web3_js_1.PublicKey(payerAddress), [], new spl_token_1.u64(amount.toString(16), 16));
        const ix = solana_1.ixFromRust(claim_shares(program_id, from_mint, to_mint, output_token_account, lp_share_token_account, amount.valueOf()));
        const transaction = new web3_js_1.Transaction().add(approvalIx, ix);
        const { blockhash } = yield connection.getRecentBlockhash();
        transaction.recentBlockhash = blockhash;
        transaction.feePayer = new web3_js_1.PublicKey(payerAddress);
        return transaction;
    });
}
exports.default = claimShares;
