-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaddress-activity.ts
118 lines (110 loc) · 2.33 KB
/
address-activity.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
import {
array,
literal,
number,
pipe,
startsWith,
strictObject,
string,
union,
variant,
type InferOutput,
} from "@valibot/valibot";
import {
ActivityLog as Log,
Address,
Hash,
Hex,
Id,
Integer,
IsoTimestamp,
Network,
WebhookId,
Erc1155Metadata,
} from "./shared.ts";
const BaseTransfer = strictObject({
fromAddress: Address,
toAddress: Address,
blockNum: Hex,
hash: Hash,
});
const EthTransfer = strictObject({
...BaseTransfer.entries,
value: number(),
asset: literal("ETH"),
category: literal("external"),
rawContract: strictObject({
rawValue: Hex,
decimals: Integer,
}),
});
// TODO: rename?
const InternalTransfer = strictObject({
...BaseTransfer.entries,
value: number(),
typeTraceAddress: union([
pipe(string(), startsWith("CALL_")),
pipe(string(), startsWith("DELEGATECALL_")),
pipe(string(), startsWith("STATICCALL_")),
]),
asset: string(),
category: literal("internal"),
rawContract: strictObject({
rawValue: Hex,
decimals: Integer,
}),
});
export type AddressActivityErc20Transfer = InferOutput<typeof Erc20Transfer>;
const Erc20Transfer = strictObject({
...BaseTransfer.entries,
value: number(),
asset: string(),
category: literal("token"),
rawContract: strictObject({
rawValue: Hex,
address: Address,
decimals: Integer,
}),
log: Log,
});
export type AddressActivityErc721Transfer = InferOutput<typeof Erc721Transfer>;
const Erc721Transfer = strictObject({
...BaseTransfer.entries,
erc721TokenId: Hex,
category: literal("token"),
rawContract: strictObject({
rawValue: union([Hex, literal("0x")]),
address: Address,
}),
log: Log,
});
export type AddressActivityErc1155Transfer = InferOutput<
typeof Erc1155Transfer
>;
const Erc1155Transfer = strictObject({
...BaseTransfer.entries,
erc1155Metadata: Erc1155Metadata,
category: literal("erc1155"),
rawContract: strictObject({
rawValue: Hex,
address: Address,
}),
log: Log,
});
const Transfers = variant("category", [
EthTransfer,
InternalTransfer,
Erc20Transfer,
Erc721Transfer,
Erc1155Transfer,
]);
export const AddressActivitySchema = strictObject({
webhookId: WebhookId,
id: Id,
createdAt: IsoTimestamp,
type: literal("ADDRESS_ACTIVITY"),
event: strictObject({
network: Network,
activity: array(Transfers),
}),
});