Skip to content

Commit

Permalink
Update CachingUtils.ts
Browse files Browse the repository at this point in the history
  • Loading branch information
nicholaspai committed Feb 15, 2024
1 parent 202fa75 commit 7ed4422
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions src/utils/CachingUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@ import { DEFAULT_CACHING_SAFE_LAG, DEFAULT_CACHING_TTL } from "../constants";
import { CachingMechanismInterface, Deposit, Fill, SlowFillRequest } from "../interfaces";
import { assert } from "./LogUtils";
import { composeRevivers, objectWithBigNumberReviver } from "./ReviverUtils";
import { getV3RelayHashFromEvent } from "./SpokeUtils";
import { getCurrentTime } from "./TimeUtils";
import { isDefined } from "./TypeGuards";
import { isV2Deposit, isV2Fill } from "./V3Utils";

export function shouldCache(eventTimestamp: number, latestTime: number, cachingMaxAge: number): boolean {
assert(eventTimestamp.toString().length === 10, "eventTimestamp must be in seconds");
Expand Down Expand Up @@ -45,9 +47,15 @@ export async function setDepositInCache(

/**
* Resolves the key for caching a bridge event.
* @param bridgeEvent The depositId, depositor, and originChainId are used to generate the key.
* @param bridgeEvent The depositId, and originChainId are used to generate the key for v2, and the

Check warning on line 50 in src/utils/CachingUtils.ts

View workflow job for this annotation

GitHub Actions / Lint

Delete `·`
* full V3 relay hash is used for v3 events..
* @returns The key for caching the event.
*/
export function getDepositKey(bridgeEvent: Deposit | Fill | SlowFillRequest): string {
return `deposit_${bridgeEvent.originChainId}_${bridgeEvent.depositId}_${bridgeEvent.depositor}`;
if (isV2Deposit(bridgeEvent as Deposit) || isV2Fill(bridgeEvent)) {
return `deposit_${bridgeEvent.originChainId}_${bridgeEvent.depositId}`;
} else {
const relayHash = getV3RelayHashFromEvent(bridgeEvent);
return `deposit_${bridgeEvent.originChainId}_${bridgeEvent.depositId}_${relayHash}`;
}
}

0 comments on commit 7ed4422

Please sign in to comment.