Skip to content

Commit

Permalink
chore: refactor blockutils
Browse files Browse the repository at this point in the history
  • Loading branch information
james-a-morris committed Oct 10, 2023
1 parent e3507d2 commit be1f173
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
12 changes: 6 additions & 6 deletions src/utils/BlockUtils.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
import { BlockFinder } from "@uma/financial-templates-lib";
import { Block, getProvider, getRedis, isDefined, setRedisKey, shouldCache } from "./";
import { getProvider, getRedis, isDefined, setRedisKey, shouldCache } from "./";
import { utils as sdkUtils } from "@across-protocol/sdk-v2";

const blockFinders: { [chainId: number]: BlockFinder<Block> } = {};
const blockFinders: { [chainId: number]: sdkUtils.BlockFinder } = {};

/**
* @notice Return block finder for chain. Loads from in memory blockFinder cache if this function was called before
* for this chain ID. Otherwise creates a new block finder and adds it to the cache.
* @param chainId
* @returns
*/
export async function getBlockFinder(chainId: number): Promise<BlockFinder<Block>> {
export async function getBlockFinder(chainId: number): Promise<sdkUtils.BlockFinder> {
if (!isDefined(blockFinders[chainId])) {
const providerForChain = await getProvider(chainId);
blockFinders[chainId] = new BlockFinder<Block>(providerForChain.getBlock.bind(providerForChain), [], chainId);
blockFinders[chainId] = new sdkUtils.BlockFinder(providerForChain);
}
return blockFinders[chainId];
}
Expand All @@ -29,7 +29,7 @@ export async function getBlockFinder(chainId: number): Promise<BlockFinder<Block
export async function getBlockForTimestamp(
chainId: number,
timestamp: number,
blockFinder?: BlockFinder<Block>
blockFinder?: sdkUtils.BlockFinder
): Promise<number> {
blockFinder ??= await getBlockFinder(chainId);
const redisClient = await getRedis();
Expand Down
1 change: 1 addition & 0 deletions src/utils/SDKUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,5 @@ export const {
blockExplorerLink,
blockExplorerLinks,
createShortHexString: shortenHexString,
BlockFinder,
} = sdkUtils;

0 comments on commit be1f173

Please sign in to comment.