-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
06ffbf5
commit 4de36c2
Showing
4 changed files
with
150 additions
and
116 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,4 +21,4 @@ export function isValidType(input: object, expectedTypeProps: string[]): boolean | |
} | ||
} | ||
return true; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,36 +1,76 @@ | ||
import { BigNumber, ethers } from "ethers"; | ||
import { object, min as Min, define, optional, string, integer } from "superstruct"; | ||
import { DepositWithBlock } from "../interfaces"; | ||
import { object, min as Min, define, optional, string, integer, assign } from "superstruct"; | ||
import { DepositWithBlock, PartialDepositWithBlock } from "../interfaces"; | ||
import { isV2Deposit } from "./V3Utils"; | ||
|
||
const AddressValidator = define<string>("AddressValidator", (v) => ethers.utils.isAddress(String(v))); | ||
const HexValidator = define<string>("HexValidator", (v) => ethers.utils.isHexString(String(v))); | ||
const BigNumberValidator = define<BigNumber>("BigNumberValidator", (v) => ethers.BigNumber.isBigNumber(v)); | ||
|
||
const DepositSchema = object({ | ||
depositId: Min(integer(), 0), | ||
depositor: AddressValidator, | ||
recipient: AddressValidator, | ||
originToken: AddressValidator, | ||
amount: BigNumberValidator, | ||
originChainId: Min(integer(), 0), | ||
destinationChainId: Min(integer(), 0), | ||
relayerFeePct: BigNumberValidator, | ||
quoteTimestamp: Min(integer(), 0), | ||
realizedLpFeePct: optional(BigNumberValidator), | ||
destinationToken: AddressValidator, | ||
message: string(), | ||
speedUpSignature: optional(string()), | ||
newRelayerFeePct: optional(BigNumberValidator), | ||
updatedRecipient: optional(string()), | ||
updatedMessage: optional(string()), | ||
const CommonEventSchema = object({ | ||
blockNumber: Min(integer(), 0), | ||
transactionIndex: Min(integer(), 0), | ||
logIndex: Min(integer(), 0), | ||
quoteBlockNumber: Min(integer(), 0), | ||
transactionHash: HexValidator, | ||
blockTimestamp: optional(Min(integer(), 0)), | ||
}); | ||
const CommonPartialDepositSchema = assign( | ||
CommonEventSchema, | ||
object({ | ||
depositId: Min(integer(), 0), | ||
depositor: AddressValidator, | ||
recipient: AddressValidator, | ||
originChainId: Min(integer(), 0), | ||
destinationChainId: Min(integer(), 0), | ||
quoteTimestamp: Min(integer(), 0), | ||
message: string(), | ||
}) | ||
); | ||
const V2PartialDepositSchema = assign( | ||
assign(CommonEventSchema, CommonPartialDepositSchema), | ||
object({ | ||
originToken: AddressValidator, | ||
amount: BigNumberValidator, | ||
relayerFeePct: BigNumberValidator, | ||
}) | ||
); | ||
const V3PartialDepositSchema = assign( | ||
assign(CommonEventSchema, CommonPartialDepositSchema), | ||
object({ | ||
inputToken: AddressValidator, | ||
inputAmount: BigNumberValidator, | ||
outputToken: AddressValidator, | ||
outputAmount: BigNumberValidator, | ||
exclusivityDeadline: Min(integer(), 0), | ||
exclusiveRelayer: AddressValidator, | ||
fillDeadline: Min(integer(), 0), | ||
}) | ||
); | ||
const CommonDepositSchema = object({ | ||
realizedLpFeePct: BigNumberValidator, | ||
speedUpSignature: optional(string()), | ||
updatedRecipient: optional(string()), | ||
updatedMessage: optional(string()), | ||
}); | ||
const V2DepositSchema = assign( | ||
assign(V2PartialDepositSchema, CommonDepositSchema), | ||
object({ | ||
destinationToken: AddressValidator, | ||
newRelayerFeePct: optional(BigNumberValidator), | ||
}) | ||
); | ||
const V3DepositSchema = assign( | ||
assign(V3PartialDepositSchema, CommonDepositSchema), | ||
object({ | ||
updatedOutputAmount: optional(BigNumberValidator), | ||
}) | ||
); | ||
|
||
export function isPartialDepositFormedCorrectly(deposit: unknown): deposit is PartialDepositWithBlock { | ||
if (isV2Deposit(deposit as DepositWithBlock)) return V2PartialDepositSchema.is(deposit); | ||
else return V3PartialDepositSchema.is(deposit); | ||
} | ||
|
||
export function isDepositFormedCorrectly(deposit: unknown): deposit is DepositWithBlock { | ||
return DepositSchema.is(deposit); | ||
if (isV2Deposit(deposit as DepositWithBlock)) return V2DepositSchema.is(deposit); | ||
else return V3DepositSchema.is(deposit); | ||
} |