generated from ChainSafe/yarn-workspaces-typescript-template
-
Notifications
You must be signed in to change notification settings - Fork 0
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
Showing
4 changed files
with
86 additions
and
33 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,42 +1,88 @@ | ||
import { array, number, object, string, union } from "zod"; | ||
import { | ||
array, | ||
assign, | ||
bigint, | ||
define, | ||
number, | ||
object, | ||
optional, | ||
refine, | ||
string, | ||
type Struct, | ||
union, | ||
} from "superstruct"; | ||
|
||
const hexString = (): Struct<string> => | ||
define("hexString", (value) => { | ||
if (typeof value !== "string") return false; | ||
const hexRegex = /^0x[0-9a-fA-F]+$/; | ||
return hexRegex.test(value); | ||
}); | ||
|
||
const numberLike = refine( | ||
union([number(), hexString(), bigint()]), | ||
"numberLike", | ||
(value) => { | ||
if (typeof value === "string") return !isNaN(Number(value)); | ||
return true; // If it's a number or bigint, it's already valid | ||
}, | ||
); | ||
|
||
const BridgeCoreSchema = object({ | ||
account: string(), | ||
account: hexString(), | ||
destinationChain: number(), | ||
token: string(), | ||
amount: number(), | ||
threshold: number().optional(), | ||
amount: numberLike, | ||
threshold: optional(number()), | ||
}); | ||
|
||
const ContractCallCoreSchema = object({ | ||
callData: string(), | ||
contractAddress: string(), | ||
gasLimit: number(), | ||
callData: hexString(), | ||
contractAddress: hexString(), | ||
gasLimit: numberLike, | ||
}); | ||
|
||
const NativeContractCallSchema = ContractCallCoreSchema.extend({ | ||
recipient: string(), | ||
}); | ||
const NativeContractCallSchema = assign( | ||
ContractCallCoreSchema, | ||
object({ | ||
recipient: hexString(), | ||
}), | ||
); | ||
|
||
const TokenContractCallSchema = ContractCallCoreSchema.extend({ | ||
outputTokenAddress: string().optional(), | ||
approvalAddress: string().optional(), | ||
}); | ||
const TokenContractCallSchema = assign( | ||
ContractCallCoreSchema, | ||
object({ | ||
outputTokenAddress: optional(hexString()), | ||
approvalAddress: optional(hexString()), | ||
}), | ||
); | ||
|
||
export const SingleHopSchema = BridgeCoreSchema.extend({ | ||
sourceChains: number(), // whitelistedSourceChains | ||
}); | ||
export const SingleHopSchema = assign( | ||
BridgeCoreSchema, | ||
object({ | ||
sourceChains: number(), // whitelistedSourceChains | ||
}), | ||
); | ||
|
||
export const MultiHopSchema = BridgeCoreSchema.extend({ | ||
sourceChains: array(number()), // whitelistedSourceChains | ||
}); | ||
export const MultiHopSchema = assign( | ||
BridgeCoreSchema, | ||
object({ | ||
sourceChains: array(number()), // whitelistedSourceChains | ||
}), | ||
); | ||
|
||
export const SingleHopWithContractSchema = BridgeCoreSchema.extend({ | ||
contractCall: union([NativeContractCallSchema, TokenContractCallSchema]), | ||
sourceChains: number(), // whitelistedSourceChains | ||
}); | ||
export const SingleHopWithContractSchema = assign( | ||
BridgeCoreSchema, | ||
object({ | ||
contractCall: union([NativeContractCallSchema, TokenContractCallSchema]), | ||
sourceChains: number(), // whitelistedSourceChains | ||
}), | ||
); | ||
|
||
export const MultiHopWithContractSchema = BridgeCoreSchema.extend({ | ||
contractCall: union([NativeContractCallSchema, TokenContractCallSchema]), | ||
sourceChains: array(number()), // whitelistedSourceChains | ||
}); | ||
export const MultiHopWithContractSchema = assign( | ||
BridgeCoreSchema, | ||
object({ | ||
contractCall: union([NativeContractCallSchema, TokenContractCallSchema]), | ||
sourceChains: array(number()), // whitelistedSourceChains | ||
}), | ||
); |
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