-
Notifications
You must be signed in to change notification settings - Fork 0
/
seed.ts
325 lines (302 loc) Β· 10.8 KB
/
seed.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
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
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
/**
* Use any TypeScript runner to run this script, for example: `npx tsx seed.ts`
* Learn more about the Seed Client by following our guide: https://docs.snaplet.dev/seed/getting-started
*/
import { createClient } from "@supabase/supabase-js";
import * as dotenv from "dotenv";
export const ZERO_ADDRESS = "0x0000000000000000000000000000000000000000";
const main = async () => {
dotenv.config();
const isLocalDb =
process.env.SUPABASE_CACHING_DB_URL?.includes("localhost") ||
process.env.SUPABASE_CACHING_DB_URL?.includes("127.0.0.1");
const overrideLocalDbProtectionFlag =
process.env.OVERRIDE_LOCAL_DB_PROTECTION === "true";
if (!isLocalDb && !overrideLocalDbProtectionFlag) {
console.error(
"This script is only intended to be run on a local development environment",
);
process.exit();
}
const supabase = createClient(
process.env.SUPABASE_CACHING_DB_URL!,
process.env.SUPABASE_CACHING_SERVICE_API_KEY!,
);
const easContractSlug = "eas-contract";
const marketplaceContractSlug = "marketplace-contract";
const minterContractSlug = "minter-contract";
// Seed the database with default events
console.log("ποΈ Seeding events...");
await supabase.from("events").upsert(
[
{
name: "Attested",
abi: "event Attested(address indexed recipient, address indexed attester, bytes32 uid, bytes32 indexed schema)",
contract_slug: easContractSlug,
},
{
name: "ClaimStored",
abi: "event ClaimStored(uint256 indexed claimID, string uri, uint256 totalUnits)",
contract_slug: minterContractSlug,
},
{
name: "TransferSingle",
abi: "event TransferSingle(address indexed operator, address indexed from, address indexed to, uint256 id, uint256 value)",
contract_slug: minterContractSlug,
},
{
name: "TransferBatch",
abi: "event TransferBatch(address indexed operator, address indexed from, address indexed to, uint256[] ids, uint256[] values)",
contract_slug: minterContractSlug,
},
{
name: "ValueTransfer",
abi: "event ValueTransfer(uint256 claimID, uint256 fromTokenID, uint256 toTokenID, uint256 value)",
contract_slug: minterContractSlug,
},
{
name: "BatchValueTransfer",
abi: "event BatchValueTransfer(uint256[] claimIDs, uint256[] fromTokenIDs, uint256[] toTokenIDs, uint256[] values)",
contract_slug: minterContractSlug,
},
{
name: "LeafClaimed",
abi: "event LeafClaimed(uint256 tokenID, bytes32 leaf)",
contract_slug: minterContractSlug,
},
{
name: "URI",
abi: "event URI(string value, uint256 id)",
contract_slug: minterContractSlug,
},
{
name: "TakerBid",
abi: "event TakerBid((bytes32 orderHash, uint256 orderNonce, bool isNonceInvalidated) nonceInvalidationParameters, address bidUser, address bidRecipient, uint256 strategyId, address currency, address collection, uint256[] itemIds, uint256[] amounts, address[2] feeRecipients, uint256[3] feeAmounts)",
contract_slug: marketplaceContractSlug,
},
],
{
onConflict: "abi",
ignoreDuplicates: true,
},
);
console.log("ποΈ Seeding contracts...");
await supabase.from("contracts").upsert(
[
{
chain_id: 42161,
contract_address: "0xcE8fa09562f07c23B9C21b5d0A29a293F8a8BC83",
start_block: 258720235,
contract_slug: marketplaceContractSlug,
},
{
chain_id: 42161,
contract_address: "0xC2679fBD37d54388Ce493F1DB75320D236e1815e",
start_block: 258705973,
contract_slug: easContractSlug,
},
{
chain_id: 10,
contract_address: "0x4200000000000000000000000000000000000021",
start_block: 126023023,
contract_slug: easContractSlug,
},
{
chain_id: 8453,
contract_address: "0x4200000000000000000000000000000000000021",
start_block: 20427818,
contract_slug: easContractSlug,
},
{
chain_id: 42220,
contract_address: "0xC2679fBD37d54388Ce493F1DB75320D236e1815e",
start_block: 27994577,
contract_slug: easContractSlug,
},
{
chain_id: 42161,
contract_address: "0x822F17A9A5EeCFd66dBAFf7946a8071C265D1d07",
start_block: 251729365,
contract_slug: minterContractSlug,
},
{
chain_id: 421614,
contract_address: "0x0A00a2f09cd37B24E7429c5238323bfebCfF3Ed9",
start_block: 69066523,
contract_slug: minterContractSlug,
},
{
chain_id: 421614,
contract_address: "0x1d905Bec93E48C64649300688B99D5F7d11ac412",
start_block: 72624136,
contract_slug: marketplaceContractSlug,
},
{
chain_id: 42220,
contract_address: "0x16bA53B74c234C870c61EFC04cD418B8f2865959",
start_block: 22079540,
contract_slug: minterContractSlug,
},
{
chain_id: 8453,
contract_address: "0xC2d179166bc9dbB00A03686a5b17eCe2224c2704",
start_block: 6771210,
contract_slug: minterContractSlug,
},
{
chain_id: 84532,
contract_address: "0xC2d179166bc9dbB00A03686a5b17eCe2224c2704",
start_block: 6771210,
contract_slug: minterContractSlug,
},
{
chain_id: 84532,
contract_address: "0x5DD43eff9FCC6F70564794e997A47722fE315847",
start_block: 14121595,
contract_slug: marketplaceContractSlug,
},
{
chain_id: 11155111,
contract_address: "0xa16DFb32Eb140a6f3F2AC68f41dAd8c7e83C4941",
start_block: 4421945,
contract_slug: minterContractSlug,
},
{
chain_id: 10,
contract_address: "0x822F17A9A5EeCFd66dBAFf7946a8071C265D1d07",
start_block: 76066993,
contract_slug: minterContractSlug,
},
{
chain_id: 10,
contract_address: "0x2F7Ab1844594112E00708e18835ba2e731880Db1",
start_block: 124234816,
contract_slug: marketplaceContractSlug,
},
{
chain_id: 11155111,
contract_address: "0xB1991E985197d14669852Be8e53ee95A1f4621c0",
start_block: 6326571,
contract_slug: marketplaceContractSlug,
},
{
chain_id: 11155111,
contract_address: "0xC2679fBD37d54388Ce493F1DB75320D236e1815e",
start_block: 6098991,
contract_slug: easContractSlug,
},
],
{
onConflict: "contract_address, chain_id",
ignoreDuplicates: true,
},
);
console.log("ποΈ Seeding supported schemas...");
await supabase.from("supported_schemas").upsert(
[
{
chain_id: 11155111,
uid: "0x2f4f575d5df78ac52e8b124c4c900ec4c540f1d44f5b8825fac0af5308c91449",
schema:
"uint256 chain_id,address contract_address,uint256 token_id,uint8 evaluate_basic,uint8 evaluate_work,uint8 evaluate_contributors,uint8 evaluate_properties,string comments,string[] tags",
resolver: ZERO_ADDRESS,
revocable: true,
},
{
chain_id: 84532,
uid: "0x2f4f575d5df78ac52e8b124c4c900ec4c540f1d44f5b8825fac0af5308c91449",
schema:
"uint256 chain_id,address contract_address,uint256 token_id,uint8 evaluate_basic,uint8 evaluate_work,uint8 evaluate_contributors,uint8 evaluate_properties,string comments,string[] tags",
resolver: ZERO_ADDRESS,
revocable: true,
},
{
chain_id: 10,
uid: "0x2f4f575d5df78ac52e8b124c4c900ec4c540f1d44f5b8825fac0af5308c91449",
schema:
"uint256 chain_id,address contract_address,uint256 token_id,uint8 evaluate_basic,uint8 evaluate_work,uint8 evaluate_contributors,uint8 evaluate_properties,string comments,string[] tags",
resolver: ZERO_ADDRESS,
revocable: true,
},
{
chain_id: 8453,
uid: "0x2f4f575d5df78ac52e8b124c4c900ec4c540f1d44f5b8825fac0af5308c91449",
schema:
"uint256 chain_id,address contract_address,uint256 token_id,uint8 evaluate_basic,uint8 evaluate_work,uint8 evaluate_contributors,uint8 evaluate_properties,string comments,string[] tags",
resolver: ZERO_ADDRESS,
revocable: true,
},
{
chain_id: 42220,
uid: "0x2f4f575d5df78ac52e8b124c4c900ec4c540f1d44f5b8825fac0af5308c91449",
schema:
"uint256 chain_id,address contract_address,uint256 token_id,uint8 evaluate_basic,uint8 evaluate_work,uint8 evaluate_contributors,uint8 evaluate_properties,string comments,string[] tags",
resolver: ZERO_ADDRESS,
revocable: true,
},
{
chain_id: 42161,
uid: "0x2f4f575d5df78ac52e8b124c4c900ec4c540f1d44f5b8825fac0af5308c91449",
schema:
"uint256 chain_id,address contract_address,uint256 token_id,uint8 evaluate_basic,uint8 evaluate_work,uint8 evaluate_contributors,uint8 evaluate_properties,string comments,string[] tags",
resolver: ZERO_ADDRESS,
revocable: true,
},
],
{
onConflict: "uid, chain_id",
ignoreDuplicates: true,
},
);
const { data: supportedSchemas } = await supabase
.from("supported_schemas")
.select("*");
// combine all contract_ids with the event_ids
console.log("ποΈ Seeding contract_events...");
const { data: events } = await supabase.from("events").select("*");
const { data: contracts } = await supabase.from("contracts").select("*");
if (!supportedSchemas) {
console.error("No supported schemas found in the database");
process.exit();
}
console.log(`β
Found ${supportedSchemas.length} supported schemas`);
if (!events) {
console.error("No events found in the database");
process.exit();
}
console.log(`β
Found ${events.length} events`);
if (!contracts) {
console.error("No contracts found in the database");
process.exit();
}
console.log(`β
Found ${contracts.length} contracts`);
const contractEvents = events.map((event) => {
const contractsWithMatchingSlug = contracts.filter(
(contract) => contract.contract_slug === event.contract_slug,
);
return contractsWithMatchingSlug.map((contract) => {
return {
contracts_id: contract.id!,
events_id: event.id!,
last_block_indexed: 0,
};
});
});
const { error } = await supabase
.from("contract_events")
.upsert(contractEvents.flat(), {
onConflict: "contracts_id, events_id",
ignoreDuplicates: true,
});
if (error) {
console.error("Error seeding contract events", error);
process.exit();
}
const { data: _contractEvents } = await supabase
.from("contract_events")
.select("*");
console.log(`β
Found ${_contractEvents.length} contract events`);
console.log("π Database seeded successfully!");
process.exit();
};
main();