Skip to content

Commit

Permalink
improve(utils): remove async requirement on functions (#55)
Browse files Browse the repository at this point in the history
Signed-off-by: james-a-morris <jaamorris@cs.stonybrook.edu>
  • Loading branch information
james-a-morris authored Oct 2, 2024
1 parent 72891ed commit b50f8ac
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 11 deletions.
4 changes: 2 additions & 2 deletions packages/indexer/src/services/hubPoolIndexer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,13 +59,13 @@ export class Indexer extends BaseIndexer {
logger,
...hubConfig,
});
this.configStoreClient = await utils.getConfigStoreClient({
this.configStoreClient = utils.getConfigStoreClient({
logger,
provider: configStoreProvider,
maxBlockLookBack: hubConfig.maxBlockLookBack,
chainId: hubConfig.chainId,
});
this.hubPoolClient = await utils.getHubPoolClient({
this.hubPoolClient = utils.getHubPoolClient({
configStoreClient: this.configStoreClient,
provider: hubPoolProvider,
logger,
Expand Down
2 changes: 1 addition & 1 deletion packages/indexer/src/services/spokePoolIndexer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ export class Indexer extends BaseIndexer {
toBlock,
});

const spokeClient = await utils.getSpokeClient({
const spokeClient = utils.getSpokeClient({
hubPoolClient: this.hubPoolClient,
provider: this.spokePoolProvider,
logger: this.logger,
Expand Down
42 changes: 34 additions & 8 deletions packages/indexer/src/utils/contractUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,21 @@ export type GetSpokeClientParams = {
hubPoolClient: across.clients.HubPoolClient;
};

export async function getSpokeClient(
/**
* Resolves a spoke pool client with the given parameters
* @param params Parameters to resolve a spoke client.
* @returns A spoke pool client configured with the given parameters
* @see {@link across.clients.SpokePoolClient} for client
* @see {@link GetSpokeClientParams} for params
*/
export function getSpokeClient(
params: GetSpokeClientParams,
): Promise<across.clients.SpokePoolClient> {
): across.clients.SpokePoolClient {
const { provider, logger, maxBlockLookBack, chainId, hubPoolClient } = params;
const address = getDeployedAddress("SpokePool", chainId);
const deployedBlockNumber = getDeployedBlockNumber("SpokePool", chainId);

const toBlock = params.toBlock ?? (await provider.getBlockNumber());
const toBlock = params.toBlock;
const fromBlock = params.fromBlock ?? deployedBlockNumber;

const eventSearchConfig = {
Expand All @@ -38,11 +45,12 @@ export async function getSpokeClient(
};
logger.debug({
message: "Initializing spoke pool",
at: "getSpokeClient",
chainId,
address,
deployedBlockNumber,
...eventSearchConfig,
blockRangeSearched: toBlock - fromBlock,
blockRangeSearched: `${fromBlock} to ${toBlock ?? "latest"}`,
});
const spokePoolContract = new Contract(
address,
Expand All @@ -66,7 +74,16 @@ export type GetConfigStoreClientParams = {
chainId: number;
};

export async function getConfigStoreClient(params: GetConfigStoreClientParams) {
/**
* Resolves a config store client with the given parameters
* @param params Parameters to resolve a config store client
* @returns A config store client configured with the given parameters
* @see {@link across.clients.AcrossConfigStoreClient} for client
* @see {@link GetConfigStoreClientParams} for params
*/
export function getConfigStoreClient(
params: GetConfigStoreClientParams,
): across.clients.AcrossConfigStoreClient {
const { provider, logger, maxBlockLookBack, chainId } = params;
const address = getDeployedAddress("AcrossConfigStore", chainId);
const deployedBlockNumber = getDeployedBlockNumber(
Expand Down Expand Up @@ -102,15 +119,24 @@ export type GetHubPoolClientParams = {
toBlock?: number;
};

export async function getHubPoolClient(params: GetHubPoolClientParams) {
/**
* Resolves a hub pool client with the given parameters
* @param params Parameters to resolve a hub pool client
* @returns A hub pool client configured with the given parameters
* @see {@link across.clients.HubPoolClient} for client
* @see {@link GetHubPoolClientParams} for params
*/
export function getHubPoolClient(
params: GetHubPoolClientParams,
): across.clients.HubPoolClient {
const { provider, logger, maxBlockLookBack, chainId, configStoreClient } =
params;
const address = getDeployedAddress("HubPool", chainId);
const deployedBlockNumber = getDeployedBlockNumber("HubPool", chainId);

const hubPoolContract = new Contract(address, HubPoolFactory.abi, provider);
const fromBlock = params.fromBlock ?? deployedBlockNumber;
const toBlock = params.toBlock ?? (await provider.getBlockNumber());
const toBlock = params.toBlock;

const eventSearchConfig = {
fromBlock,
Expand All @@ -121,7 +147,7 @@ export async function getHubPoolClient(params: GetHubPoolClientParams) {
message: "Initializing hubpool",
chainId,
...eventSearchConfig,
blockRangeSearched: toBlock - fromBlock,
blockRangeSearched: `${fromBlock} to ${toBlock ?? "latest"}`,
});
return new across.clients.HubPoolClient(
logger,
Expand Down

0 comments on commit b50f8ac

Please sign in to comment.