"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.messageFee = messageFee;
const utils_1 = require("../../utils");
const kit_1 = require("@solana/kit");
async function messageFee(provider, opts) {
    const { unsignedTx: _unsignedTx } = opts;
    const unsignedTx = _unsignedTx;
    const compiledTransaction = (0, kit_1.compileTransaction)(unsignedTx);
    const encodedTransactionMessage = Buffer.from(compiledTransaction.messageBytes).toString("base64");
    const baseFeeResponse = await provider.getFeeForMessage(encodedTransactionMessage).send();
    const instructionAddresses = (0, utils_1.dedupArray)(unsignedTx.instructions.map((instruction) => instruction.programAddress));
    const recentPriorityFees = await provider.getRecentPrioritizationFees(instructionAddresses).send();
    const nonzeroPrioritizationFees = recentPriorityFees
        .slice(125)
        .map((value) => value.prioritizationFee)
        .filter((fee) => fee > 0);
    const totalPrioritizationFees = nonzeroPrioritizationFees.reduce((acc, fee) => acc + fee, BigInt(0));
    const microLamportsPerComputeUnit = (0, utils_1.toBN)(totalPrioritizationFees / BigInt(Math.max(nonzeroPrioritizationFees.length, 1)));
    return {
        baseFee: (0, utils_1.toBN)(baseFeeResponse.value),
        microLamportsPerComputeUnit,
    };
}
//# sourceMappingURL=solana.js.map