import { BigNumber, Contract } from 'ethers';
import { Logger } from '../utils/logger';
import { Config } from '../config/config';
import { CheckRefundableResult, CheckRefundableResultV2, L3BidWinnerResponse, L3OrderCreatedEventData, L3OrderTimestamps, L3OrderTuple, Order, OrderCreatedEventData, OrderResponseL3, OrderStatus, OrderWithTimestamp } from './types';
import { NetworkIdT3rn, USDPriceNetworkAssetValue } from '../pricer/types';
import { AssetName } from '../pricer/enums';
import { DynamoOrder } from '../dynamo/types';
import { Dynamo } from '../dynamo/dynamo.service';
import { RedisClientType } from 'redis';
import { SQSService } from '../sqs/sqs.service';
import { OrderArbitrageStrategies } from '../config/executor-arbitrage-strategies';
import { EventData } from '../types';
export interface BatchStatus {
    isAttestedL3: boolean;
    isAttestedL2: boolean;
    batchOnL3: string;
    batchHash: string;
    attestationBookVersion: string;
    threw?: boolean;
}
export interface IsClaimableResult {
    isClaimable: boolean;
    threw?: boolean;
}
export interface isAttestedL2Response {
    isAttestedL2: boolean;
    threw?: boolean;
}
export interface BatchPayloadStatus {
    isAttestedL3: boolean;
    attestationBookVersion: string;
    batchOnL3: string;
    batchHash: string;
    isAttestedL2?: boolean;
    threw?: boolean;
}
export interface RecoveredOrderStatus {
    order: Order | null;
    bidWinner: string | undefined;
    isOrderClaimable: boolean;
    orderUnclaimableReason?: string;
    status: OrderStatus;
    settledAmount: BigNumber;
    gmpPayloadL2: string;
    batchPayload: string;
    threw?: boolean;
}
interface IsRevertedOnL3Response {
    isReverted: boolean;
    threw?: boolean;
}
interface GMP2PayloadResponse {
    gmp2Payload: string;
    threw?: boolean;
    isClaimed: boolean;
    isRefunded: boolean;
    isKnown: boolean;
}
interface IsExecutedOnL2Response {
    id: string;
    isExecuted: boolean;
    threw?: boolean;
    filledBidWinner?: string;
}
export declare class OrderService {
    private readonly config;
    private readonly configByNetworkId;
    private confirmationBookContract;
    private escrowGMPContract;
    private attestersContract;
    private attestationsBatchMaker;
    private segmentBookContract;
    private payloadGetter;
    private singleAttestationBookContractV1;
    private singleAttestationBookContractV2;
    private singleAttestationBookContractV3;
    private attestationsBatchMakerRemote;
    private remoteOrderContract;
    private claimerGMP;
    private openMarketPricer;
    private BRNRewardsContract;
    private BRNBalanceGetter;
    private orderBookContract;
    private escrowOrderBookContract;
    private biddingBookContract;
    private singleAttestationBookContract;
    private insurance;
    private enabledNetworkIds;
    readonly sqsService: SQSService;
    constructor(config: Config);
    init(orderBookInsurance: BigNumber, _orderBookContract: Contract, _escrowOrderBookContract: Contract, _biddingBookContract: Contract, _singleAttestationBookContract: Contract, _attestationsBatchMaker: Contract, _singleAttestationBookContractV1: Contract, _singleAttestationBookContractV2: Contract, _singleAttestationBookContractV3: Contract, _attestationsBatchMakerRemote: Contract, _confirmationBookContract: Contract, _BRNRewardsContract: Contract, _BRNBalanceGetter: Contract, _payloadGetter: Contract, _segmentBookContract: Contract, _escrowGMPContract: Record<string, Contract>, _attestersContract: Record<string, Contract>, _remoteOrder: Record<string, Contract>, _openMarketPricer: Record<string, Contract>, _claimerGMP: Record<string, Contract>, _enabledNetworkIds: NetworkIdT3rn[]): void;
    static orderToAmountsInNumber(order: Order): {
        amount: string;
        insurance: string;
        maxReward: string;
        orderTimestamp: string;
        profit: BigNumber;
        confirmedAmount: BigNumber | undefined;
        assetNative: boolean;
        sourceAssetCode?: number;
        destinationAssetCode?: number;
        openOrderVerifyTxHash?: string;
        closedOrderVerifyTxHash?: string;
        status: OrderStatus;
        id: string;
        executor: string;
        txHash: string;
        source: NetworkIdT3rn;
        destination: NetworkIdT3rn;
        nonce: number;
        partitionKey: string;
        sourceAsset: string;
        destinationAsset: string;
        sourceAccount: string;
        targetAccount: string;
        batchHash: string | undefined;
        verifiedExecution: boolean | undefined;
        verifiedExecutionL3: boolean | undefined;
        orderTimestampTtl: number;
        bidTimestamp: number;
        confirmationTimestamp: number;
        refundTimestamp: number;
        claimTimestamp: number;
        attestationTimestamp: number;
        txIndex?: string | undefined | undefined;
        bidTxHash: string | undefined;
        bidTxIndex?: string | undefined | undefined;
        confirmationTxHash: string | undefined;
        confirmationTxIndex?: string | undefined | undefined;
        claimTxHash: string | undefined;
        claimTxIndex?: string | undefined | undefined;
        refundTxHash: string | undefined;
        refundTxIndex?: string | undefined | undefined;
        insuranceTxHash: string | undefined;
        orderCreatedGasFee: string;
        confirmationGasFee: string;
        refundAmount: string;
        maxRewardUSD: number;
        amountUSD: number;
        profitUSD: number;
        insuranceUSD: number;
        orderCreatedGasUSD: number;
        confirmationGasUSD: number;
        claimGasUSD: number;
        refundGasUSD: number;
        sourceGasFeesUSD: number;
        destinationGasFeesUSD: number;
        protocolFeeInUSD: number;
        executorFeeUSD: number;
        refundAmountUSD: number;
        totalFeesUSD: number;
    };
    isOrderExecuted(order: Order): Promise<IsExecutedOnL2Response>;
    calculateProfitUSD(order: Order, profit: BigNumber, assetPricePerNetwork: Map<NetworkIdT3rn, Map<AssetName, USDPriceNetworkAssetValue>>): number;
    outputProtocolFeeCut(order: Order, protocolFeeMicroPercent: BigNumber, protocolFeeFlatMin: BigNumber, protocolFeeFlatMax: BigNumber, isNativeAssetOnSource: boolean): BigNumber;
    calculateProtocolFeeCut(order: Order, protocolFeeMicroPercent: BigNumber, protocolFeeFlatMin: BigNumber, protocolFeeFlatMax: BigNumber): BigNumber;
    isOrderExecutedWithAddress(order: Order, address: string, redisClient?: RedisClientType): Promise<IsExecutedOnL2Response>;
    isOrderReverted(order: Order, redisClient?: RedisClientType): Promise<IsRevertedOnL3Response>;
    /**
     * Checks if an order is executable based on the balance, destination, strategy, and asset.
     *
     * @param {Order} order - The order object.
     * @param {BigNumber} balance - The balance of the executor's wallet on the destination network.
     * @param {OrderArbitrageStrategies} arbitrageStrategies - arbitrage strategies for the executor.
     * @param {boolean} debugLogLevel - log warnings on debug mode (to be used by PricerAPI)
     * @returns {Promise<boolean>} - Returns true if the order is executable, false otherwise.
     */
    isOrderExecutable(order: Order, balance: BigNumber, arbitrageStrategies?: OrderArbitrageStrategies): boolean;
    static sortAndGroupOrders(orders: Order[]): Order[];
    static newOnlyIdAndNetworkOrder(orderId: string, network: NetworkIdT3rn, networkType: 'source' | 'destination'): Order;
    getUserBRNRewards(account: string): Promise<string>;
    getBRNBalance(account: string, preferWei?: boolean): Promise<string>;
    getExecutorBRNRewards(account: string): Promise<string>;
    getAttesterBRNRewards(account: string): Promise<string>;
    orderCreatedEventDataToOrderL3Tuple(sourceNetwork: NetworkIdT3rn, args: OrderCreatedEventData): L3OrderTuple;
    orderL3TupleToOrderCreatedEventData(orderId: string, orderL3Tuple: L3OrderTuple, eventData: EventData): OrderCreatedEventData;
    /**
     * Construct an Order object out of the given params
     *
     * @param {OrderCreatedEventData} args
     * @param {NetworkIdT3rn}  sourceNetwork
     * @param externalTxHash - optional external transaction hash to override EventData.transactionHash (for dropped events)
     * @return {Order}
     */
    parseOrderCreatedEvent(args: OrderCreatedEventData, sourceNetwork: NetworkIdT3rn, externalTxHash?: string): Order;
    fetchGMP2PayloadResponse(orderId: string, networkId: string, redisClient?: RedisClientType): Promise<GMP2PayloadResponse>;
    fetchGMP2Payload(orderId: string, networkId: string): Promise<string>;
    /**
     * Construct Order object from event data from OrderBook contract
     *
     * @param {L3OrderCreatedEventData} args
     * @return {Order}
     */
    parseL3OrderCreatedEvent(args: L3OrderCreatedEventData): Order;
    dbOrderToL3Order(order: Order): L3OrderTuple;
    isOrderIsometric(order: Order): boolean;
    /**
     * Checks if the given order is isometric with the L3 order tuple.
     *
     * @param {Order} order - The order to check.
     * @param {L3OrderTuple} l3OrderTuple - The L3 order tuple to compare against.
     * @returns {boolean} - Returns true if the order is isometric with the L3 order tuple, false otherwise.
     */
    isOrderIsometricWithL3(order: Order, l3OrderTuple: L3OrderTuple): boolean;
    getBidWinnerFromOrderBook(orderId: string, childLogger: Logger, debugContext?: string, redisClient?: RedisClientType): Promise<L3BidWinnerResponse>;
    getOrderFromOrderBookResponse(orderId: string, childLogger?: Logger, debugContext?: string, redisClient?: RedisClientType, dynamo?: Dynamo): Promise<OrderResponseL3>;
    checkOrderExistsSafe(orderId: string, networkId: NetworkIdT3rn, childLogger?: Logger, redisClient?: RedisClientType): Promise<OrderResponseL3>;
    checkOrderExists(orderId: string, networkId: NetworkIdT3rn, childLogger?: Logger, redisClient?: RedisClientType): Promise<boolean>;
    checkOrderExistsOnOrderBook(orderId: string, childLogger?: Logger, redisClient?: RedisClientType): Promise<boolean>;
    checkOrderExistsOnOrderBookSafe(orderId: string, childLogger?: Logger, redisClient?: RedisClientType): Promise<OrderResponseL3>;
    /**
     * Fetches the order, its txHash and its timestamp from the OrderBook contract.
     * Parses the order to Order object understood by the services.
     * The txHash and timestamp are returned as are.
     * Returns null, if no order was found for the given orderId.
     *
     * @param {string} orderId
     * @returns {Promise<OrderWithTimestamp | null>}
     */
    getOrderWithTimestampFromOrderBook(orderId: string): Promise<OrderWithTimestamp | null>;
    getOrderExecutionTxHashFromConfirmationBook(orderId: string): Promise<string>;
    checkApplyInvalidRefundState(isRefundableResult: CheckRefundableResult, orderId: string, source: NetworkIdT3rn, dynamo: Dynamo, currentStatus: OrderStatus): Promise<OrderStatus | undefined>;
    checkInvalidRefundState(isRefundableResult: CheckRefundableResult, orderId: string, source: NetworkIdT3rn): Promise<OrderStatus>;
    checkIsRefundableV2(networkId: NetworkIdT3rn, orderId: string, _orderTimestamp: number | BigNumber, _rewardAsset: string, maxReward: BigNumber, account: string, nonce: number, redisClient?: RedisClientType): Promise<CheckRefundableResultV2>;
    checkIsRefundable(networkId: NetworkIdT3rn, orderId: string, _orderTimestamp: number | BigNumber, _rewardAsset: string, _maxReward: BigNumber, account: string, nonce: number): Promise<CheckRefundableResult>;
    getOpenMarketPricerEnabledAssets(networkId: NetworkIdT3rn): Promise<number[]>;
    getOrderLifecycleTimestampsFromConfirmationBook(orderId: string): Promise<L3OrderTimestamps>;
    getBidAmountFromOrderBook(orderId: string, childLogger: Logger, redisClient?: RedisClientType): Promise<BigNumber | null>;
    isEmptyBatchPayload(batchPayload: string): boolean;
    verbalizeCurrentAttestationVersion(): "v2" | "v4" | "v3";
    fetchWithBatchMakerVX(orderId: string, singleAttestationBookContract: Contract, attestationBookVersion: string, redisClient?: RedisClientType): Promise<BatchPayloadStatus>;
    fetchWithRemoteBatchMaker(orderId: string): Promise<BatchPayloadStatus>;
    recoverBatchPayload(orderId: string, redisClient?: RedisClientType): Promise<BatchPayloadStatus>;
    isAttestationApplied(networkId: NetworkIdT3rn, batchHash: string, redisClient?: RedisClientType): Promise<isAttestedL2Response>;
    recoverRevertBatchPayload(orderId: string, redisClient?: RedisClientType, networkId?: NetworkIdT3rn): Promise<BatchPayloadStatus>;
    recoverBatchStatusByOrderId(networkId: NetworkIdT3rn, orderId: string, redisClient?: RedisClientType): Promise<BatchStatus>;
    recoverBatchStatus(networkId: NetworkIdT3rn, batchMessageHash: string): Promise<BatchStatus>;
    checkIsClaimableWithClaimer(networkId: NetworkIdT3rn, orderId: string, rewardAsset: string, maxReward: BigNumber, settledAmount: BigNumber, bidWinner: string, orderTimestamp: BigNumber, batchPayloadHash: string, batchPayload: string, childLogger: Logger, attestationBookVersion?: string): Promise<IsClaimableResult>;
    /**
     * Calculates the timestamp (in seconds) at which the order is refundable.
     *
     * @param {number}  orderTimestamp
     * @param {NetworkIdT3rn} networkId
     * @returns {Promise<number>}
     */
    calculateOrderRefundTimestamp(orderTimestamp: number, networkId: NetworkIdT3rn): number;
    getAllGMPMismatchedOrdersDLQ(networkId: NetworkIdT3rn, childLogger: Logger): Promise<string[]>;
    getAllLateOrdersDLQ(networkId: NetworkIdT3rn, childLogger: Logger): Promise<string[]>;
    deriveCommitmentsOfPayload(encodedBatchPayload: string, account: string, dynamo: Dynamo): Promise<DynamoOrder[]>;
    getSegmentBookBatchPayload(batchHash: string, redisClient?: RedisClientType): Promise<string>;
    doesBatchExistOnSegmentBook(batchHash: string, redisClient?: RedisClientType): Promise<{
        exists: boolean;
        threw: boolean;
    }>;
    calculateProfitAndProtocolFeeCut(assetPricePerNetwork: Map<NetworkIdT3rn, Map<AssetName, USDPriceNetworkAssetValue>>, order: Order, protocolFeeMicroPercent: BigNumber, protocolFeeFlatMin: BigNumber, protocolFeeFlatMax: BigNumber): {
        protocolFeeCut: BigNumber;
        potentialProfit: BigNumber;
        details: string;
    } | {
        protocolFeeCut: BigNumber;
        potentialProfit: BigNumber;
        details?: undefined;
    };
    fetchAssetsRatio(assetPricePerNetwork: Map<NetworkIdT3rn, Map<AssetName, USDPriceNetworkAssetValue>>, assetA: AssetName, assetB: AssetName, networkId: NetworkIdT3rn): number;
    evaluateProfitabilityInWei(maxReward: BigNumber, amount: BigNumber, priceAinEth: BigNumber, priceBinEth: BigNumber, protocolFeeCut: BigNumber, decimals?: number): {
        rewardInEth: BigNumber;
        orderAmountInEth: BigNumber;
        potentialProfit: BigNumber;
        potentialLoss: BigNumber;
    };
    recoverOrderStatus(orderId: string, childLogger: Logger, dynamo?: Dynamo, debugContext?: string, redisClient?: RedisClientType): Promise<RecoveredOrderStatus>;
    /**
     * Decides if order is still pending to get a bid by an executor, based on lifecycle timestamps values.
     *
     * The `order` and `bid` timestamps should be enough to say whether an order is still missing a bid, but we're being
     * extra cautious, in case of failure that `bidTimestamp` wasn't updated, but the others after it were.
     *
     * @param order
     * @returns {boolean} True if still pending, False otherwise
     */
    isOrderBidStillPending(order: L3OrderTimestamps): boolean;
    /**
     * Decides if order claim is still pending, based on lifecycle timestamps values.
     *
     * An order that has been executed should have `confirmation` and `attestation` timestamps set, and `claim` and
     * `refund` timestamps should be zero.
     *
     * @param order
     * @returns {boolean} True if still pending, False otherwise
     */
    isOrderClaimable(order: L3OrderTimestamps): boolean;
    /**
     * Verifies if the given network is enabled with the service.
     *
     * @param {NetworkIdT3rn} networkId
     * @returns True if network is supported, False otherwise
     */
    isNetworkSupported(networkId: NetworkIdT3rn): boolean;
    shouldMarkOrderAsNotExecuted(order: Order, isExecutedResponse: IsExecutedOnL2Response): boolean;
    shouldMarkOrderAsExecuted(order: Order, isExecutedResponse: IsExecutedOnL2Response): boolean;
    /**
     * Verifies that the given networks are enabled
     *
     * @param {NetworkIdT3rn}  sourceNetwork
     * @param {NetworkIdT3rn}  destinationNetwork
     * @returns {boolean} True if both networks supported, False if at least one of the networks is not supported
     */
    areNetworksSupported(sourceNetwork: NetworkIdT3rn, destinationNetwork: NetworkIdT3rn): boolean;
    /**
     * Verifies that the given networks are of the same environment
     * Basically, it's used to prevent transfers between testnet and mainnet.
     *
     * @param {NetworkIdT3rn}  sourceNetwork
     * @param {NetworkIdT3rn}  destinationNetwork
     * @returns {boolean} True if both networks are of the same env (e.g. testnet), False otherwise
     */
    networksAreOfSameEnv(sourceNetwork: NetworkIdT3rn, destinationNetwork: NetworkIdT3rn): boolean;
    isTestnet(networkId: NetworkIdT3rn): boolean;
    isMainnet(networkId: NetworkIdT3rn): boolean;
}
export {};
//# sourceMappingURL=order.service.d.ts.map