"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.getMessageHash = exports.isUnsafeDepositId = exports.getRelayHashFromEvent = exports.getRelayDataHash = exports.getSlowFillLeafLpFeePct = exports.isSlowFill = void 0;
var tslib_1 = require("tslib");
var viem_1 = require("viem");
var common_1 = require("./common");
var constants_1 = require("../constants");
var interfaces_1 = require("../interfaces");
var BigNumberUtils_1 = require("./BigNumberUtils");
var DepositUtils_1 = require("./DepositUtils");
var NetworkUtils_1 = require("./NetworkUtils");
var arch_1 = require("../arch");
function isSlowFill(fill) {
    return fill.relayExecutionInfo.fillType === interfaces_1.FillType.SlowFill;
}
exports.isSlowFill = isSlowFill;
function getSlowFillLeafLpFeePct(leaf) {
    var relayData = leaf.relayData, updatedOutputAmount = leaf.updatedOutputAmount;
    return relayData.inputAmount.sub(updatedOutputAmount).mul(common_1.fixedPointAdjustment).div(relayData.inputAmount);
}
exports.getSlowFillLeafLpFeePct = getSlowFillLeafLpFeePct;
function getRelayDataHash(relayData, destinationChainId) {
    var abi = [
        {
            type: "tuple",
            components: [
                { type: "bytes32", name: "depositor" },
                { type: "bytes32", name: "recipient" },
                { type: "bytes32", name: "exclusiveRelayer" },
                { type: "bytes32", name: "inputToken" },
                { type: "bytes32", name: "outputToken" },
                { type: "uint256", name: "inputAmount" },
                { type: "uint256", name: "outputAmount" },
                { type: "uint256", name: "originChainId" },
                { type: "uint256", name: "depositId" },
                { type: "uint32", name: "fillDeadline" },
                { type: "uint32", name: "exclusivityDeadline" },
                { type: "bytes", name: "message" },
            ],
        },
        { type: "uint256", name: "destinationChainId" },
    ];
    var _relayData = tslib_1.__assign(tslib_1.__assign({}, relayData), { depositor: relayData.depositor.toBytes32(), recipient: relayData.recipient.toBytes32(), inputToken: relayData.inputToken.toBytes32(), outputToken: relayData.outputToken.toBytes32(), exclusiveRelayer: relayData.exclusiveRelayer.toBytes32() });
    if ((0, NetworkUtils_1.chainIsSvm)(destinationChainId)) {
        return arch_1.svm.getRelayDataHash(relayData, destinationChainId);
    }
    return (0, viem_1.keccak256)((0, viem_1.encodeAbiParameters)(abi, [_relayData, destinationChainId]));
}
exports.getRelayDataHash = getRelayDataHash;
function getRelayHashFromEvent(e) {
    return getRelayDataHash(e, e.destinationChainId);
}
exports.getRelayHashFromEvent = getRelayHashFromEvent;
function isUnsafeDepositId(depositId) {
    var maxSafeDepositId = BigNumberUtils_1.BigNumber.from(constants_1.MAX_SAFE_DEPOSIT_ID);
    return maxSafeDepositId.lt(depositId);
}
exports.isUnsafeDepositId = isUnsafeDepositId;
function getMessageHash(message) {
    return (0, DepositUtils_1.isMessageEmpty)(message) ? constants_1.ZERO_BYTES : (0, viem_1.keccak256)(message);
}
exports.getMessageHash = getMessageHash;
//# sourceMappingURL=SpokeUtils.js.map