From f9933ba0c9deb4f17fe6e5da5ade975afe312d96 Mon Sep 17 00:00:00 2001 From: Paul <108695806+pxrl@users.noreply.github.com> Date: Sun, 10 Mar 2024 09:03:55 +1100 Subject: [PATCH] improve(HubPoolClient): Permit selectively overriding search config (#583) This follows the pattern established in the SpokePoolClient, where EnabledDepositRoute overriddes searchConfig.fromBlock on the first update. This will be used in the relayer to reduce the lookback for events related to root bundles, since there's no need to query those all the way back to HubPool genesis. --- package.json | 2 +- src/clients/HubPoolClient.ts | 26 +++++++++++++++++++++++--- 2 files changed, 24 insertions(+), 4 deletions(-) diff --git a/package.json b/package.json index 74e63b8b5..97913d925 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "@across-protocol/sdk-v2", "author": "UMA Team", - "version": "0.22.10", + "version": "0.22.11", "license": "AGPL-3.0", "homepage": "https://docs.across.to/v/developer-docs/developers/across-sdk", "files": [ diff --git a/src/clients/HubPoolClient.ts b/src/clients/HubPoolClient.ts index 61cafe0f2..1494cf76c 100644 --- a/src/clients/HubPoolClient.ts +++ b/src/clients/HubPoolClient.ts @@ -771,17 +771,37 @@ export class HubPoolClient extends BaseAbstractClient { return { success: false }; } + const eventSearchConfigs = eventNames.map((eventName) => { + if (!Object.keys(hubPoolEvents).includes(eventName)) { + throw new Error(`HubPoolClient: Cannot query unrecognised HubPool event name: ${eventName}`); + } + + const _searchConfig = { ...searchConfig }; // shallow copy + + // By default, an event's query range is controlled by the `searchConfig` passed in during + // instantiation. However, certain events generally must be queried back to HubPool genesis. + const overrideEvents = ["CrossChainContractsSet", "L1TokenEnabledForLiquidityProvision", "SetPoolRebalanceRoute"]; + if (overrideEvents.includes(eventName) && !this.isUpdated) { + _searchConfig.fromBlock = this.deploymentBlock; + } + + return { + eventName, + filter: hubPoolEvents[eventName], + searchConfig: _searchConfig, + }; + }); + this.logger.debug({ at: "HubPoolClient", message: "Updating HubPool client", - searchConfig, - eventNames, + searchConfig: eventSearchConfigs.map(({ eventName, searchConfig }) => ({ eventName, searchConfig })), }); const timerStart = Date.now(); const [currentTime, pendingRootBundleProposal, ...events] = await Promise.all([ this.hubPool.getCurrentTime({ blockTag: searchConfig.toBlock }), this.hubPool.rootBundleProposal({ blockTag: searchConfig.toBlock }), - ...eventNames.map((eventName) => paginatedEventQuery(this.hubPool, hubPoolEvents[eventName], searchConfig)), + ...eventSearchConfigs.map((config) => paginatedEventQuery(this.hubPool, config.filter, config.searchConfig)), ]); this.logger.debug({ at: "HubPoolClient#_update",