"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.BundleDataSS = exports.SortableEventSS = void 0;
var tslib_1 = require("tslib");
var superstruct_1 = require("superstruct");
var constants_1 = require("../../../constants");
var utils_1 = require("../../../utils");
var PositiveIntegerStringSS = (0, superstruct_1.pattern)((0, superstruct_1.string)(), /\d+/);
var Web3AddressSS = (0, superstruct_1.pattern)((0, superstruct_1.string)(), /^0x[a-fA-F0-9]{64}$/);
var BigNumberType = (0, superstruct_1.coerce)((0, superstruct_1.instance)(utils_1.BigNumber), (0, superstruct_1.union)([(0, superstruct_1.string)(), (0, superstruct_1.number)()]), function (value) {
    try {
        return utils_1.BigNumber.from(value);
    }
    catch (error) {
        return value;
    }
});
var AddressInstanceSS = (0, superstruct_1.union)([(0, superstruct_1.instance)(utils_1.EvmAddress), (0, superstruct_1.instance)(utils_1.SvmAddress), (0, superstruct_1.instance)(utils_1.RawAddress)]);
var AddressType = (0, superstruct_1.coerce)(AddressInstanceSS, (0, superstruct_1.string)(), function (value) {
    var chainId = value.startsWith("0x") ? constants_1.CHAIN_IDs.MAINNET : constants_1.CHAIN_IDs.SOLANA;
    return (0, utils_1.toAddressType)(value, chainId);
});
var Web3AddressType = (0, superstruct_1.coerce)(Web3AddressSS, (0, superstruct_1.string)(), function (value) {
    return (0, utils_1.toBytes32)(value);
});
var FillTypeSS = (0, superstruct_1.number)();
var V3RelayDataSS = {
    inputToken: AddressType,
    inputAmount: BigNumberType,
    outputToken: AddressType,
    outputAmount: BigNumberType,
    fillDeadline: (0, superstruct_1.number)(),
    exclusiveRelayer: AddressType,
    exclusivityDeadline: (0, superstruct_1.number)(),
    originChainId: (0, superstruct_1.number)(),
    depositor: AddressType,
    recipient: AddressType,
    depositId: BigNumberType,
    message: (0, superstruct_1.string)(),
};
exports.SortableEventSS = {
    blockNumber: (0, superstruct_1.number)(),
    logIndex: (0, superstruct_1.number)(),
    txnRef: (0, superstruct_1.optional)((0, superstruct_1.string)()),
    txnIndex: (0, superstruct_1.optional)((0, superstruct_1.number)()),
    transactionHash: (0, superstruct_1.optional)((0, superstruct_1.string)()),
    transactionIndex: (0, superstruct_1.optional)((0, superstruct_1.number)()),
};
var V3DepositSS = {
    messageHash: (0, superstruct_1.defaulted)((0, superstruct_1.string)(), constants_1.UNDEFINED_MESSAGE_HASH),
    fromLiteChain: (0, superstruct_1.defaulted)((0, superstruct_1.boolean)(), false),
    toLiteChain: (0, superstruct_1.defaulted)((0, superstruct_1.boolean)(), false),
    destinationChainId: (0, superstruct_1.number)(),
    quoteTimestamp: (0, superstruct_1.number)(),
    relayerFeePct: (0, superstruct_1.optional)(BigNumberType),
    speedUpSignature: (0, superstruct_1.optional)((0, superstruct_1.string)()),
    updatedRecipient: (0, superstruct_1.optional)(AddressType),
    updatedOutputAmount: (0, superstruct_1.optional)(BigNumberType),
    updatedMessage: (0, superstruct_1.optional)((0, superstruct_1.string)()),
};
var _V3DepositWithBlockSS = tslib_1.__assign(tslib_1.__assign(tslib_1.__assign({ quoteBlockNumber: (0, superstruct_1.number)() }, V3DepositSS), exports.SortableEventSS), V3RelayDataSS);
var V3DepositWithBlockSS = (0, superstruct_1.object)(_V3DepositWithBlockSS);
var V3DepositWithBlockLpFeeSS = (0, superstruct_1.object)(tslib_1.__assign(tslib_1.__assign({}, _V3DepositWithBlockSS), { lpFeePct: BigNumberType }));
var V3RelayExecutionEventInfoSS = (0, superstruct_1.object)({
    updatedOutputAmount: BigNumberType,
    fillType: FillTypeSS,
    updatedRecipient: AddressType,
    updatedMessage: (0, superstruct_1.optional)((0, superstruct_1.string)()),
    updatedMessageHash: (0, superstruct_1.defaulted)((0, superstruct_1.string)(), constants_1.UNDEFINED_MESSAGE_HASH),
});
var V3FillSS = tslib_1.__assign(tslib_1.__assign({}, V3RelayDataSS), { message: (0, superstruct_1.optional)((0, superstruct_1.string)()), messageHash: (0, superstruct_1.defaulted)((0, superstruct_1.string)(), constants_1.UNDEFINED_MESSAGE_HASH), destinationChainId: (0, superstruct_1.number)(), relayer: AddressType, repaymentChainId: (0, superstruct_1.number)(), relayExecutionInfo: V3RelayExecutionEventInfoSS, quoteTimestamp: (0, superstruct_1.number)() });
var V3FillWithBlockSS = tslib_1.__assign(tslib_1.__assign({}, exports.SortableEventSS), V3FillSS);
var BundleFillV3SS = (0, superstruct_1.object)(tslib_1.__assign(tslib_1.__assign({}, V3FillWithBlockSS), { lpFeePct: BigNumberType }));
var nestedV3DepositRecordSS = (0, superstruct_1.record)(PositiveIntegerStringSS, (0, superstruct_1.record)(Web3AddressType, (0, superstruct_1.array)(V3DepositWithBlockSS)));
var nestedV3DepositRecordWithLpFeePctSS = (0, superstruct_1.record)(PositiveIntegerStringSS, (0, superstruct_1.record)(Web3AddressType, (0, superstruct_1.array)(V3DepositWithBlockLpFeeSS)));
var nestedV3BundleFillsSS = (0, superstruct_1.record)(PositiveIntegerStringSS, (0, superstruct_1.record)(Web3AddressType, (0, superstruct_1.object)({
    fills: (0, superstruct_1.array)(BundleFillV3SS),
    refunds: (0, superstruct_1.record)(Web3AddressType, BigNumberType),
    totalRefundAmount: BigNumberType,
    realizedLpFees: BigNumberType,
})));
exports.BundleDataSS = (0, superstruct_1.type)({
    bundleDepositsV3: nestedV3DepositRecordSS,
    expiredDepositsToRefundV3: nestedV3DepositRecordSS,
    unexecutableSlowFills: nestedV3DepositRecordWithLpFeePctSS,
    bundleSlowFillsV3: nestedV3DepositRecordWithLpFeePctSS,
    bundleFillsV3: nestedV3BundleFillsSS,
});
//# sourceMappingURL=SuperstructUtils.js.map