import { Contract, EventFilter } from "ethers"; import winston from "winston"; import { AnyObject, BigNumber, DefaultLogLevels, EventSearchConfig, MakeOptional } from "../utils"; import { Deposit, DepositWithBlock, Fill, FillStatus, FillWithBlock, Log, RelayData, RelayerRefundExecutionWithBlock, RootBundleRelayWithBlock, SlowFillRequestWithBlock, SpeedUpWithBlock, TokensBridged } from "../interfaces"; import { BaseAbstractClient, UpdateFailureReason } from "./BaseAbstractClient"; import { HubPoolClient } from "./HubPoolClient"; import { AcrossConfigStoreClient } from "./AcrossConfigStoreClient"; type SpokePoolUpdateSuccess = { success: true; currentTime: number; oldestTime: number; firstDepositId: number; latestDepositId: number; events: Log[][]; searchEndBlock: number; }; type SpokePoolUpdateFailure = { success: false; reason: UpdateFailureReason; }; export type SpokePoolUpdate = SpokePoolUpdateSuccess | SpokePoolUpdateFailure; /** * SpokePoolClient is a client for the SpokePool contract. It is responsible for querying the SpokePool contract * for events and storing them in memory. It also provides some convenience methods for querying the stored events. */ export declare class SpokePoolClient extends BaseAbstractClient { readonly logger: winston.Logger; readonly spokePool: Contract; readonly hubPoolClient: HubPoolClient | null; readonly chainId: number; deploymentBlock: number; protected currentTime: number; protected oldestTime: number; protected depositHashes: { [depositHash: string]: DepositWithBlock; }; protected depositHashesToFills: { [depositHash: string]: FillWithBlock[]; }; protected speedUps: { [depositorAddress: string]: { [depositId: number]: SpeedUpWithBlock[]; }; }; protected slowFillRequests: { [relayDataHash: string]: SlowFillRequestWithBlock; }; protected depositRoutes: { [originToken: string]: { [DestinationChainId: number]: boolean; }; }; protected tokensBridged: TokensBridged[]; protected rootBundleRelays: RootBundleRelayWithBlock[]; protected relayerRefundExecutions: RelayerRefundExecutionWithBlock[]; protected queryableEventNames: string[]; protected configStoreClient: AcrossConfigStoreClient | undefined; earliestDepositIdQueried: number; latestDepositIdQueried: number; firstDepositIdForSpokePool: number; lastDepositIdForSpokePool: number; fills: { [OriginChainId: number]: FillWithBlock[]; }; /** * Creates a new SpokePoolClient. * @param logger A logger instance. * @param spokePool The SpokePool contract instance that this client will query. * @param hubPoolClient An optional HubPoolClient instance. This is used to fetch spoke data that is not stored on the SpokePool contract but is stored on the HubPool contract. * @param chainId The chain ID of the chain that this client is querying. * @param deploymentBlock The block number that the SpokePool contract was deployed at. * @param eventSearchConfig An optional EventSearchConfig object that controls how far back in history the client will search for events. If not provided, the client will only search for events from the deployment block. */ constructor(logger: winston.Logger, spokePool: Contract, hubPoolClient: HubPoolClient | null, chainId: number, deploymentBlock: number, eventSearchConfig?: MakeOptional); _queryableEventNames(): { [eventName: string]: EventFilter; }; /** * Retrieves a list of deposits from the SpokePool contract destined for the given destination chain ID. * @param destinationChainId The destination chain ID. * @returns A list of deposits. */ getDepositsForDestinationChain(destinationChainId: number): DepositWithBlock[]; /** * Retrieves a list of deposits from the SpokePool contract that are associated with this spoke pool. * @returns A list of deposits. * @note This method returns all deposits, regardless of destination chain ID in sorted order. */ getDeposits(filter?: { fromBlock: number; toBlock: number; }): DepositWithBlock[]; /** * Retrieves a list of the tokens that have been bridged. * @returns A list of tokens. */ getTokensBridged(): TokensBridged[]; /** * Retrieves a mapping of tokens and their associated destination chain IDs that can be bridged. * @returns A mapping of tokens and their associated destination chain IDs in a nested mapping. */ getDepositRoutes(): { [originToken: string]: { [DestinationChainId: number]: boolean; }; }; /** * Retrieves a list of fills from the SpokePool contract. * @returns A list of fills. */ getFills(): FillWithBlock[]; /** * Retrieves a list of fills from a specific origin chain ID. * @param originChainId The origin chain ID. * @returns A list of fills. */ getFillsForOriginChain(originChainId: number): FillWithBlock[]; /** * Retrieves a list of fills from a specific relayer address. * @param relayer The relayer address. * @returns A list of fills. */ getFillsForRelayer(relayer: string): FillWithBlock[]; /** * Retrieves a list of fills from a given block range. * @param startingBlock The starting block number. * @param endingBlock The ending block number. * @returns A list of fills. */ getFillsWithBlockInRange(startingBlock: number, endingBlock: number): FillWithBlock[]; /** * Retrieves a list of root bundle relays from the SpokePool contract. * @returns A list of root bundle relays. */ getRootBundleRelays(): RootBundleRelayWithBlock[]; /** * Retrieves the ID of the latest root bundle. * @returns The ID of the latest root bundle. This will be 0 if no root bundles have been relayed. */ getLatestRootBundleId(): number; /** * Retrieves a list of relayer refund executions from the SpokePool contract. * @returns A list of relayer refund executions. */ getRelayerRefundExecutions(): RelayerRefundExecutionWithBlock[]; /** * Appends a speed up signature to a specific deposit. * @param deposit The deposit to append the speed up signature to. * @returns A new deposit instance with the speed up signature appended to the deposit. */ appendMaxSpeedUpSignatureToDeposit(deposit: DepositWithBlock): DepositWithBlock; /** * Find a deposit based on its deposit ID. * @notice If evaluating a fill, be sure to verify it against the resulting deposit. * @param depositId The unique ID of the deposit being queried. * @returns The corresponding deposit if found, undefined otherwise. */ getDeposit(depositId: number): DepositWithBlock | undefined; /** * Find a SlowFillRequested event based on its deposit RelayData. * @param relayData RelayData field for the SlowFill request. * @returns The corresponding SlowFIllRequest event if found, otherwise undefined. */ getSlowFillRequest(relayData: RelayData): SlowFillRequestWithBlock | undefined; /** * Retrieves a list of slow fill requests for deposits from a specific origin chain ID. * @param originChainId The origin chain ID. * @returns A list of slow fill requests. */ getSlowFillRequestsForOriginChain(originChainId: number): SlowFillRequestWithBlock[]; /** * Retrieves speed up requests grouped by depositor and depositId. * @returns A mapping of depositor addresses to deposit ids with their corresponding speed up requests. */ getSpeedUps(): { [depositorAddress: string]: { [depositId: number]: SpeedUpWithBlock[]; }; }; /** * Find a corresponding deposit for a given fill. * @param fill The fill to find a corresponding deposit for. * @returns The corresponding deposit if found, undefined otherwise. */ getDepositForFill(fill: Fill): DepositWithBlock | undefined; /** * Find a valid fill for a given deposit. * @param deposit A deposit event. * @returns A valid fill for the deposit, or undefined. */ getFillForDeposit(deposit: Deposit): FillWithBlock | undefined; /** * Find the unfilled amount for a given deposit. This is the full deposit amount minus the total filled amount. * @param deposit The deposit to find the unfilled amount for. * @param fillCount The number of fills that have been applied to this deposit. * @param invalidFills The invalid fills that have been applied to this deposit. * @returns The unfilled amount. */ getValidUnfilledAmountForDeposit(deposit: Deposit): { unfilledAmount: BigNumber; fillCount: number; invalidFills: Fill[]; }; /** * Formulate a hash for a given deposit or fill * @param event The deposit or fill to formulate a hash for. * @returns The hash. * @note This hash is used to match deposits and fills together. * @note This hash takes the form of: `${depositId}-${originChainId}`. */ getDepositHash(event: { depositId: number; originChainId: number; }): string; /** * Finds the deposit id at a specific block number. * @param blockTag The block number to search for the deposit ID at. * @returns The deposit ID. */ _getDepositIdAtBlock(blockTag: number): Promise; /** * @notice Return maximum of fill deadline buffer at start and end of block range. This is a contract * immutable state variable so we can't query other events to find its updates. * @dev V3 deposits have a fill deadline which can be set to a maximum of fillDeadlineBuffer + deposit.block.timestamp. * Therefore, we cannot evaluate a block range for expired deposits if the spoke pool client doesn't return us * deposits whose block.timestamp is within fillDeadlineBuffer of the end block time. As a conservative check, * we verify that the time between the end block timestamp and the first timestamp queried by the * spoke pool client is greater than the maximum of the fill deadline buffers at the start and end of the block * range. We assume the fill deadline buffer wasn't changed more than once within a bundle. * @param startBlock start block * @param endBlock end block * @returns maximum of fill deadline buffer at start and end block */ getMaxFillDeadlineInRange(startBlock: number, endBlock: number): Promise; /** * Performs an update to refresh the state of this client. This will query the SpokePool contract for new events * and store them in memory. This method is the primary method for updating the state of this client. * @param eventsToQuery An optional list of events to query. If not provided, all events will be queried. * @returns A Promise that resolves to a SpokePoolUpdate object. */ protected _update(eventsToQuery: string[]): Promise; /** * A wrapper over the `_update` method that handles errors and logs. This method additionally calls into the * HubPoolClient to update the state of this client with data from the HubPool contract. * @param eventsToQuery An optional list of events to query. If not provided, all events will be queried. * @returns A Promise that resolves to a SpokePoolUpdate object. * @note This method is the primary method for updating the state of this client externally. * @see _update */ update(eventsToQuery?: string[]): Promise; /** * Retrieves the l2TokenAddress for a given executed refund leaf. * @param chainId The chain ID of the executed refund leaf. * @param eventL2Token The l2TokenAddress of the executed refund leaf. * @returns The l2TokenAddress of the executed refund leaf. */ static getExecutedRefundLeafL2Token(chainId: number, eventL2Token: string): string; /** * Resolve a given timestamp to a block number on the HubPool chain via the HubPoolClient. * @param timestamp A single timestamp to be resolved via the HubPoolClient. * @returns The block number on the HubPool chain corresponding to the supplied timestamp. */ protected getBlockNumber(timestamp: number): Promise; /** * For an array of timestamps, resolve each timestamp to a block number on the HubPool chain via the HubPoolClient. * @param timestamps Array of timestamps to be resolved to a block number via the HubPoolClient. * @returns A mapping of quoteTimestamp -> HubPool block number. */ protected getBlockNumbers(timestamps: number[]): Promise<{ [quoteTimestamp: number]: number; }>; /** * Retrieves the destination token for a given deposit. * @param deposit The deposit to retrieve the destination token for. * @returns The destination token. */ protected getDestinationTokenForDeposit(deposit: DepositWithBlock): string; /** * Performs a log for a specific level, message and data. * @param level The log level. * @param message The log message. * @param data Optional data to log. */ protected log(level: DefaultLogLevels, message: string, data?: AnyObject): void; /** * Retrieves the current time from the SpokePool contract. * @returns The current time, which will be 0 if there has been no update() yet. */ getCurrentTime(): number; /** * Retrieves the oldest time searched on the SpokePool contract. * @returns The oldest time searched, which will be 0 if there has been no update() yet. */ getOldestTime(): number; findDeposit(depositId: number, destinationChainId: number): Promise; /** * Determines whether a deposit originates from a lite chain. * @param deposit The deposit to evaluate. * @returns True if the deposit originates from a lite chain, false otherwise. If the hub pool client is not defined, * this method will return false. */ protected isOriginLiteChain(deposit: DepositWithBlock): boolean; /** * Determines whether the deposit destination chain is a lite chain. * @param deposit The deposit to evaluate. * @returns True if the deposit is destined to a lite chain, false otherwise. If the hub pool client is not defined, * this method will return false. */ protected isDestinationLiteChain(deposit: DepositWithBlock): boolean; getTimestampForBlock(blockTag: number): Promise; /** * Find the amount filled for a deposit at a particular block. * @param relayData Deposit information that is used to complete a fill. * @param blockTag Block tag (numeric or "latest") to query at. * @returns The amount filled for the specified deposit at the requested block (or latest). */ relayFillStatus(relayData: RelayData, blockTag?: number | "latest", destinationChainId?: number): Promise; } export {};