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