Skip to content

Commit

Permalink
Typeguard WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
nicholaspai committed Feb 8, 2024
1 parent 128f7a7 commit 06ffbf5
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/clients/SpokePoolClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ import {
isV2SpeedUp,
isV3SpeedUp,
toBN,
isValidType,
assert,
} from "../utils";
import {
paginatedEventQuery,
Expand Down Expand Up @@ -49,6 +51,7 @@ import {
V2SpeedUp,
V3DepositWithBlock,
V3FillWithBlock,
V3FundsDepositEventProps,
V3FundsDepositedEvent,
V3RelayData,
V3RelayerRefundExecutionWithBlock,
Expand Down Expand Up @@ -1158,7 +1161,7 @@ export class SpokePoolClient extends BaseAbstractClient {
);
}
const partialDeposit = spreadEventWithBlockNumber(event) as V3DepositWithBlock;
// @TODO Validate partialDeposit here.
assert(isValidType(partialDeposit, V3FundsDepositEventProps), "Invalid FundsDeposited event");
const { realizedLpFeePct, quoteBlock: quoteBlockNumber } = (await this.batchComputeRealizedLpFeePct([event]))[0]; // Append the realizedLpFeePct.

// Append destination token and realized lp fee to deposit.
Expand Down
25 changes: 25 additions & 0 deletions src/interfaces/SpokePool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,31 @@ export interface V3Deposit extends V3RelayData {
updatedMessage?: string;
}

export const SortableEventProps = [

Check warning on line 61 in src/interfaces/SpokePool.ts

View workflow job for this annotation

GitHub Actions / Lint

Replace `⏎··"blockNumber",⏎··"transactionIndex",⏎··"logIndex",⏎··"transactionHash"⏎]` with `"blockNumber",·"transactionIndex",·"logIndex",·"transactionHash"];`
"blockNumber",
"transactionIndex",
"logIndex",
"transactionHash"
]

Check failure on line 66 in src/interfaces/SpokePool.ts

View workflow job for this annotation

GitHub Actions / Lint

Missing semicolon
export const V3RelayDataProps = [
"originChainId",
"depositor",
"recipient",
"depositId",
"message",
"inputToken",
"inputAmount",
"outputToken",
"outputAmount",
"fillDeadline",
"exclusiveRelayer",
"exclusivityDeadline",
]

Check warning on line 80 in src/interfaces/SpokePool.ts

View workflow job for this annotation

GitHub Actions / Lint

Insert `;`

Check failure on line 80 in src/interfaces/SpokePool.ts

View workflow job for this annotation

GitHub Actions / Lint

Missing semicolon
export const V3FundsDepositEventProps = [

Check warning on line 81 in src/interfaces/SpokePool.ts

View workflow job for this annotation

GitHub Actions / Lint

Replace `⏎··...SortableEventProps,⏎··...V3RelayDataProps⏎]` with `...SortableEventProps,·...V3RelayDataProps];`
...SortableEventProps,
...V3RelayDataProps
]

Check failure on line 84 in src/interfaces/SpokePool.ts

View workflow job for this annotation

GitHub Actions / Lint

Missing semicolon

export interface V3DepositWithBlock extends V3Deposit, SortableEvent {
quoteBlockNumber: number;
}
Expand Down
9 changes: 9 additions & 0 deletions src/utils/TypeGuards.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,12 @@ export function isPromiseRejected<T>(
export function isDefined<T>(input: T | null | undefined): input is T {
return input !== null && input !== undefined;
}

export function isValidType(input: object, expectedTypeProps: string[]): boolean {
for (const prop of expectedTypeProps) {
if (!(prop in input)) {
return false;
}
}
return true;
}

Check warning on line 24 in src/utils/TypeGuards.ts

View workflow job for this annotation

GitHub Actions / Lint

Insert `⏎`

0 comments on commit 06ffbf5

Please sign in to comment.