-
Notifications
You must be signed in to change notification settings - Fork 23
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
ff8ae9e
commit b0b478f
Showing
19 changed files
with
226 additions
and
165 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
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 |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import { z } from 'zod'; | ||
|
||
import { ETH_ADDRESS_REGEXP, USER_ADDRESS_PARAM } from '../const'; | ||
|
||
export const returnValueTestSchema = z.object({ | ||
index: z.number().optional(), | ||
comparator: z.enum(['==', '>', '<', '>=', '<=', '!=']), | ||
value: z.unknown(), | ||
}); | ||
|
||
export type ReturnValueTestProps = z.infer<typeof returnValueTestSchema>; | ||
|
||
const EthAddressSchema = z.string().regex(ETH_ADDRESS_REGEXP); | ||
const UserAddressSchema = z.literal(USER_ADDRESS_PARAM); | ||
export const EthAddressOrUserAddressSchema = z.union([ | ||
EthAddressSchema, | ||
UserAddressSchema, | ||
]); |
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
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,3 +1,12 @@ | ||
import { ChainId } from '../web3'; | ||
|
||
export const USER_ADDRESS_PARAM = ':userAddress'; | ||
|
||
export const ETH_ADDRESS_REGEXP = new RegExp('^0x[a-fA-F0-9]{40}$'); | ||
|
||
export const SUPPORTED_CHAIN_IDS = [ | ||
ChainId.POLYGON, | ||
ChainId.MUMBAI, | ||
ChainId.GOERLI, | ||
ChainId.MAINNET, | ||
]; |
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 |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import { Primitive, z, ZodLiteral } from 'zod'; | ||
|
||
// Source: https://github.com/colinhacks/zod/issues/831#issuecomment-1063481764 | ||
const createUnion = < | ||
T extends Readonly<[Primitive, Primitive, ...Primitive[]]> | ||
>( | ||
values: T | ||
) => { | ||
const zodLiterals = values.map((value) => z.literal(value)) as unknown as [ | ||
ZodLiteral<Primitive>, | ||
ZodLiteral<Primitive>, | ||
...ZodLiteral<Primitive>[] | ||
]; | ||
return z.union(zodLiterals); | ||
}; | ||
|
||
function createUnionSchema<T extends readonly Primitive[]>(values: T) { | ||
if (values.length === 0) { | ||
return z.never(); | ||
} | ||
|
||
if (values.length === 1) { | ||
return z.literal(values[0]); | ||
} | ||
|
||
return createUnion( | ||
values as unknown as Readonly<[Primitive, Primitive, ...Primitive[]]> | ||
); | ||
} | ||
|
||
export default createUnionSchema; |
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,10 +1,3 @@ | ||
export type ChecksumAddress = string; | ||
export type HexEncodedBytes = string; | ||
export type Base64EncodedBytes = string; | ||
|
||
export enum ChainId { | ||
POLYGON = 137, | ||
MUMBAI = 80001, | ||
GOERLI = 5, | ||
MAINNET = 1, | ||
} |
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
Oops, something went wrong.