This repository has been archived by the owner on Jun 7, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 56
/
contractTypes.ts
129 lines (118 loc) 路 3.03 KB
/
contractTypes.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
import { z, ZodType } from 'zod';
// /**
// * #### Summary
// * Zod Schema for {@link TBasicContract}
// */
// export const basicContractSchema = z.object({
// address: z.string(),
// abi: z.array(z.any()).optional(),
// });
/**
* #### Summary
* Describes the basic structure of each contract
*
* @category Models
*/
export type TBasicContract = {
contractName: string;
address: string;
abi?: Readonly<Record<string, any>[]>;
};
/**
* #### Summary
* Describes a basic contract data record.
* A record of key:chainId. value:{address, chainId}
* @category Models
*/
export type TBasicContractDeployment = {
[chainId: number]: {
chainId: number;
address: string;
};
};
// /**
// * #### Summary
// * Zod Schema for {@link TBasicContractConfig}
// */
// export const basicContractConfigSchema = z.record(
// z.number({ description: 'chainId' }),
// z.object({
// address: z.string(),
// chainId: z.number(),
// })
// );
/**
* #### Summary
* Contracts by contract name
* - A record key: contractNames, values: {@link TBasicContractDeployment}
*/
export type TContractDeploymentMap = {
[contractName: string]: {
config: TBasicContractDeployment;
};
};
/**
* #### Summary
* Zod Schema for {@link TContractDeploymentMap}
*/
export const contractDeploymentMapSchema: ZodType<TContractDeploymentMap> = z.record(
z.string({ description: 'contractName' }),
z.object({
config: z.record(
z.number({ description: 'chainId' }),
z.object({
address: z.string(),
chainId: z.number(),
})
),
})
);
/**
* #### Summary
* Contracts by contract name, used by eth-hooks to connect and load contracts
* - A record of key:{contract names}, values: Hardhat contract json
* - includes chain id
*/
export type TContractMapWithAbi = {
[contractName: string]: {
config: TBasicContractDeployment;
abi: Readonly<Record<string, any>[]>;
};
};
/**
* #### Summary
* Zod Schema for {@link TContractMapWithAbi}
*/
export const contractMapWithAbiSchema: ZodType<TContractMapWithAbi> = z.record(
z.string({ description: 'contractName' }),
z.object({
config: z.record(
z.number({ description: 'chainId' }),
z.object({
address: z.string(),
chainId: z.number(),
})
),
abi: z.array(z.any()),
})
);
/**
* {chainId: {contract: address}}, contains an record of contracts
* #### Summary
* A type for external contracts
* - it is a record of contract names and their deployed address
* - this data type is used by {@link ContractsAppContext} to connect to external contracts
*
* @category Models
*/
export type TExternalContractsAddressMap = z.infer<typeof externalContractAddressMap>;
/**
* #### Summary
* Zod Schema for {@link TExternalContractsAddressMap}
*/
export const externalContractAddressMap = z.record(
z
.union([z.string({ description: 'chainId' }), z.number({ description: 'chainId' })])
.transform((s) => parseInt(s.toString())),
z.record(z.string({ description: 'contractName' }), z.string({ description: 'address' }))
);