"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.tvmBandwidthCostZero = void 0;
exports.getAuxiliaryNativeTokenCost = getAuxiliaryNativeTokenCost;
const utils_1 = require("../../utils");
const TVM_BANDWIDTH_SUN_PER_BYTE = 1000;
const TVM_RAW_DATA_OVERHEAD_BYTES = 290;
const TVM_FILL_RELAY_FIXED_CALLDATA_BYTES = 4 + 96 + 384 + 32;
const TVM_SPEED_UP_FIXED_CALLDATA_EXTRA_BYTES = 128 + 32 + 32 + 96;
function paddedMessageByteLength(message) {
    if (!(0, utils_1.isDefined)(message) || (0, utils_1.isMessageEmpty)(message))
        return 0;
    const bytes = Math.max(0, Math.floor((message.length - 2) / 2));
    return Math.ceil(bytes / 32) * 32;
}
function getAuxiliaryNativeTokenCost(deposit) {
    const paddedMessageBytes = paddedMessageByteLength(deposit.message);
    let speedUpExtraBytes = 0;
    if ((0, utils_1.isDefined)(deposit.speedUpSignature) && deposit.speedUpSignature !== "0x") {
        speedUpExtraBytes = TVM_SPEED_UP_FIXED_CALLDATA_EXTRA_BYTES + paddedMessageByteLength(deposit.updatedMessage);
    }
    const calldataBytes = TVM_FILL_RELAY_FIXED_CALLDATA_BYTES + paddedMessageBytes + speedUpExtraBytes;
    const txBytes = TVM_RAW_DATA_OVERHEAD_BYTES + calldataBytes;
    return (0, utils_1.toBN)(txBytes).mul(TVM_BANDWIDTH_SUN_PER_BYTE);
}
exports.tvmBandwidthCostZero = utils_1.bnZero;
//# sourceMappingURL=MessageUtils.js.map