-
Notifications
You must be signed in to change notification settings - Fork 36
Expand file tree
/
Copy pathschemas.ts
More file actions
226 lines (202 loc) · 6.37 KB
/
schemas.ts
File metadata and controls
226 lines (202 loc) · 6.37 KB
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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
import { z } from 'zod';
import {
type AccountAPIBalance,
type AccountAPIKey,
type AccountAPIResponse,
type AccountListItemAPIResponse,
type AccountListItemBalance,
type AccountListItemTokenBalance,
type ContractInfo,
type GetAccountsAPIResponse,
MirrorNodeKeyType,
type NftInfo,
type TokenAirdropItem,
type TokenAirdropsResponse,
type TokenBalanceInfo,
type TokenBalancesResponse,
type TokenInfo,
type TopicInfo,
type TopicMessage,
type TopicMessageChunkInfo,
type TopicMessagesAPIResponse,
} from './types';
const mirrorKeyObject = z.object({
_type: z.string(),
key: z.string(),
});
const optionalKeyRef = z.union([mirrorKeyObject, z.null()]).optional();
export const TokenInfoSchema: z.ZodType<TokenInfo> = z.object({
token_id: z.string(),
symbol: z.string(),
name: z.string(),
decimals: z.string(),
total_supply: z.string(),
max_supply: z.string(),
type: z.string(),
treasury_account_id: z.string(),
admin_key: optionalKeyRef,
kyc_key: optionalKeyRef,
freeze_key: optionalKeyRef,
wipe_key: optionalKeyRef,
supply_key: optionalKeyRef,
fee_schedule_key: optionalKeyRef,
metadata_key: optionalKeyRef,
pause_key: optionalKeyRef,
created_timestamp: z.string(),
deleted: z.boolean().nullable().optional(),
freeze_default: z.boolean().optional(),
auto_renew_account: z.string(),
auto_renew_period: z.number(),
expiry_timestamp: z.number(),
pause_status: z.string(),
memo: z.string(),
});
const mirrorNodeKeyTypeSchema = z.enum(MirrorNodeKeyType);
export const AccountAPIBalanceSchema: z.ZodType<AccountAPIBalance> = z.object({
balance: z.number(),
timestamp: z.string(),
});
export const AccountAPIKeySchema: z.ZodType<AccountAPIKey> = z.object({
_type: mirrorNodeKeyTypeSchema,
key: z.string(),
});
export const AccountAPIResponseSchema: z.ZodType<AccountAPIResponse> = z.object(
{
account: z.string(),
alias: z.string().nullable().optional(),
balance: AccountAPIBalanceSchema,
created_timestamp: z.string(),
evm_address: z.string().optional(),
key: AccountAPIKeySchema.optional(),
max_automatic_token_associations: z.number(),
memo: z.string(),
receiver_sig_required: z.boolean(),
},
);
const accountListItemTokenBalanceSchema: z.ZodType<AccountListItemTokenBalance> =
z.object({
token_id: z.string(),
balance: z.number(),
});
export const AccountListItemBalanceSchema: z.ZodType<AccountListItemBalance> =
z.object({
timestamp: z.string(),
balance: z.number(),
tokens: z.array(accountListItemTokenBalanceSchema).optional(),
});
export const AccountListItemAPIResponseSchema: z.ZodType<AccountListItemAPIResponse> =
z.object({
account: z.string(),
alias: z.string().nullable().optional(),
balance: AccountListItemBalanceSchema.optional(),
created_timestamp: z.string(),
evm_address: z.string().optional(),
key: z.union([AccountAPIKeySchema, z.null()]).optional(),
deleted: z.boolean().optional(),
memo: z.string().optional(),
});
export const GetAccountsAPIResponseSchema: z.ZodType<GetAccountsAPIResponse> =
z.object({
accounts: z.array(AccountListItemAPIResponseSchema),
links: z
.object({
next: z.string().nullable().optional(),
})
.optional(),
});
const topicMessageChunkInitialTxIdSchema = z.union([
z.string(),
z.record(z.string(), z.unknown()),
]);
const TopicMessageChunkInfoSchema: z.ZodType<TopicMessageChunkInfo> = z.object({
initial_transaction_id: topicMessageChunkInitialTxIdSchema,
number: z.number(),
total: z.number(),
});
export const TopicMessageSchema: z.ZodType<TopicMessage> = z.object({
consensus_timestamp: z.string(),
topic_id: z.string(),
message: z.string(),
running_hash: z.string(),
sequence_number: z.number(),
chunk_info: TopicMessageChunkInfoSchema.optional(),
});
export const TopicMessagesAPIResponseSchema: z.ZodType<TopicMessagesAPIResponse> =
z.object({
messages: z.array(TopicMessageSchema),
links: z
.object({
next: z.string().nullable().optional(),
})
.optional(),
});
export const TokenBalanceInfoSchema: z.ZodType<TokenBalanceInfo> = z.object({
token_id: z.string(),
balance: z.number(),
decimals: z.number().optional(),
});
export const TokenBalancesResponseSchema: z.ZodType<TokenBalancesResponse> =
z.object({
tokens: z.array(TokenBalanceInfoSchema),
links: z
.object({
next: z.string().nullable().optional(),
})
.optional(),
});
const TokenAirdropItemSchema: z.ZodType<TokenAirdropItem> = z.object({
account_id: z.string(),
amount: z.number(),
token_id: z.string(),
timestamp: z.string(),
});
export const TokenAirdropsResponseSchema: z.ZodType<TokenAirdropsResponse> =
z.object({
airdrops: z.array(TokenAirdropItemSchema),
});
const nullableStringKey = z.union([z.string(), z.null()]).optional();
export const NftInfoSchema: z.ZodType<NftInfo> = z.object({
account_id: z.union([z.string(), z.null()]),
created_timestamp: z.string(),
delegating_spender: nullableStringKey,
deleted: z.boolean(),
metadata: z.string().optional(),
modified_timestamp: z.string(),
serial_number: z.number(),
spender: nullableStringKey,
token_id: z.string(),
});
export const TopicInfoSchema: z.ZodType<TopicInfo> = z.object({
topic_id: z.string(),
admin_key: optionalKeyRef,
submit_key: optionalKeyRef,
memo: z.string(),
running_hash: z.string().optional(),
sequence_number: z.number().optional(),
consensus_timestamp: z.string().optional(),
auto_renew_account: z.string().optional(),
auto_renew_period: z.number(),
expiration_timestamp: z.string().optional(),
created_timestamp: z.string(),
deleted: z.boolean(),
});
export const ContractInfoSchema: z.ZodType<ContractInfo> = z.object({
contract_id: z.string(),
account: z.string().optional(),
created_timestamp: z.string(),
deleted: z.boolean(),
memo: z.string(),
evm_address: z.string().optional(),
admin_key: optionalKeyRef,
auto_renew_account: nullableStringKey,
auto_renew_period: z.number(),
expiration_timestamp: nullableStringKey,
file_id: nullableStringKey,
max_automatic_token_associations: z.number(),
obtainer_id: nullableStringKey,
permanent_removal: z.union([z.boolean(), z.null()]).optional(),
proxy_account_id: nullableStringKey,
staked_account_id: nullableStringKey,
staked_node_id: z.union([z.number(), z.null()]).optional(),
stake_period_start: nullableStringKey,
});