forked from safe-global/safe-transaction-service
-
Notifications
You must be signed in to change notification settings - Fork 3
/
setup_service.py
419 lines (399 loc) · 17.4 KB
/
setup_service.py
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
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
from dataclasses import dataclass
from typing import Dict, List, Sequence, Tuple
from django.conf import settings
from django.core.management.base import BaseCommand
from django_celery_beat.models import IntervalSchedule, PeriodicTask
from gnosis.eth import EthereumClientProvider
from gnosis.eth.ethereum_client import EthereumNetwork
from ...models import ProxyFactory, SafeMasterCopy
@dataclass
class CeleryTaskConfiguration:
name: str
description: str
interval: int
period: str
enabled: bool = True
def create_task(self) -> Tuple[PeriodicTask, bool]:
interval_schedule, _ = IntervalSchedule.objects.get_or_create(
every=self.interval, period=self.period
)
periodic_task, created = PeriodicTask.objects.get_or_create(
task=self.name,
defaults={
"name": self.description,
"interval": interval_schedule,
"enabled": self.enabled,
},
)
if not created:
periodic_task.name = self.description
periodic_task.interval = interval_schedule
periodic_task.enabled = self.enabled
periodic_task.save()
return periodic_task, created
TASKS = [
CeleryTaskConfiguration(
"safe_transaction_service.history.tasks.index_internal_txs_task",
"Index Internal Txs",
13,
IntervalSchedule.SECONDS,
enabled=not settings.ETH_L2_NETWORK,
),
CeleryTaskConfiguration(
"safe_transaction_service.history.tasks.index_safe_events_task",
"Index Safe events (L2)",
13,
IntervalSchedule.SECONDS,
enabled=settings.ETH_L2_NETWORK,
),
CeleryTaskConfiguration(
"safe_transaction_service.history.tasks.index_new_proxies_task",
"Index new Proxies",
15,
IntervalSchedule.SECONDS,
enabled=settings.ETH_L2_NETWORK,
),
CeleryTaskConfiguration(
"safe_transaction_service.history.tasks.index_erc20_events_task",
"Index ERC20/721 Events",
14,
IntervalSchedule.SECONDS,
),
CeleryTaskConfiguration(
"safe_transaction_service.history.tasks.index_erc20_events_out_of_sync_task",
"Index out of sync ERC20/ERC721 Events",
5,
IntervalSchedule.MINUTES,
),
CeleryTaskConfiguration(
"safe_transaction_service.history.tasks.reindex_last_hours",
"Reindex master copies for the last hours",
110,
IntervalSchedule.MINUTES,
),
CeleryTaskConfiguration(
"safe_transaction_service.history.tasks.process_decoded_internal_txs_task",
"Process Internal Txs",
20,
IntervalSchedule.MINUTES,
),
CeleryTaskConfiguration(
"safe_transaction_service.history.tasks.check_reorgs_task",
"Check Reorgs",
3,
IntervalSchedule.MINUTES,
),
CeleryTaskConfiguration(
"safe_transaction_service.contracts.tasks.create_missing_contracts_with_metadata_task",
"Index contract names and ABIs",
1,
IntervalSchedule.HOURS,
),
CeleryTaskConfiguration(
"safe_transaction_service.contracts.tasks.reindex_contracts_without_metadata_task",
"Reindex contracts with missing names or ABIs",
7,
IntervalSchedule.DAYS,
),
CeleryTaskConfiguration(
"safe_transaction_service.tokens.tasks.fix_pool_tokens_task",
"Fix Pool Token Names",
1,
IntervalSchedule.HOURS,
),
]
MASTER_COPIES: Dict[EthereumNetwork, List[Tuple[str, int, str]]] = {
EthereumNetwork.MAINNET: [
("0x3E5c63644E683549055b9Be8653de26E0B4CD36E", 12504423, "1.3.0+L2"),
("0xd9Db270c1B5E3Bd161E8c8503c55cEABeE709552", 12504268, "1.3.0"),
("0x6851D6fDFAfD08c0295C392436245E5bc78B0185", 10329734, "1.2.0"),
("0x34CfAC646f301356fAa8B21e94227e3583Fe3F5F", 9084503, "1.1.1"),
("0xaE32496491b53841efb51829d6f886387708F99B", 8915728, "1.1.0"),
("0xb6029EA3B2c51D09a50B53CA8012FeEB05bDa35A", 7457553, "1.0.0"),
("0x8942595A2dC5181Df0465AF0D7be08c8f23C93af", 6766257, "0.1.0"),
("0xAC6072986E985aaBE7804695EC2d8970Cf7541A2", 6569433, "0.0.2"),
],
EthereumNetwork.RINKEBY: [
("0x3E5c63644E683549055b9Be8653de26E0B4CD36E", 8527380, "1.3.0+L2"),
("0xd9Db270c1B5E3Bd161E8c8503c55cEABeE709552", 8527381, "1.3.0"),
("0x6851D6fDFAfD08c0295C392436245E5bc78B0185", 6723632, "1.2.0"),
("0x34CfAC646f301356fAa8B21e94227e3583Fe3F5F", 5590754, "1.1.1"),
("0xaE32496491b53841efb51829d6f886387708F99B", 5423491, "1.1.0"),
("0xb6029EA3B2c51D09a50B53CA8012FeEB05bDa35A", 4110083, "1.0.0"),
("0x8942595A2dC5181Df0465AF0D7be08c8f23C93af", 3392692, "0.1.0"),
("0x2727D69C0BD14B1dDd28371B8D97e808aDc1C2f7", 3055781, "0.0.2"),
],
EthereumNetwork.GOERLI: [
("0x3E5c63644E683549055b9Be8653de26E0B4CD36E", 4854168, "1.3.0+L2"),
("0xd9Db270c1B5E3Bd161E8c8503c55cEABeE709552", 4854169, "1.3.0"),
("0x6851D6fDFAfD08c0295C392436245E5bc78B0185", 2930373, "1.2.0"),
("0x34CfAC646f301356fAa8B21e94227e3583Fe3F5F", 1798663, "1.1.1"),
("0xaE32496491b53841efb51829d6f886387708F99B", 1631488, "1.1.0"),
("0xb6029EA3B2c51D09a50B53CA8012FeEB05bDa35A", 319108, "1.0.0"),
("0x8942595A2dC5181Df0465AF0D7be08c8f23C93af", 34096, "0.1.0"),
],
EthereumNetwork.KOVAN: [
("0x3E5c63644E683549055b9Be8653de26E0B4CD36E", 25059609, "1.3.0+L2"),
("0xd9Db270c1B5E3Bd161E8c8503c55cEABeE709552", 25059611, "1.3.0"),
("0x6851D6fDFAfD08c0295C392436245E5bc78B0185", 19242615, "1.2.0"),
("0x34CfAC646f301356fAa8B21e94227e3583Fe3F5F", 15366145, "1.1.1"),
("0xaE32496491b53841efb51829d6f886387708F99B", 14740724, "1.1.0"),
("0xb6029EA3B2c51D09a50B53CA8012FeEB05bDa35A", 10638132, "1.0.0"),
("0x8942595A2dC5181Df0465AF0D7be08c8f23C93af", 9465686, "0.1.0"),
],
EthereumNetwork.XDAI: [
("0x3E5c63644E683549055b9Be8653de26E0B4CD36E", 16236936, "1.3.0+L2"),
("0xd9Db270c1B5E3Bd161E8c8503c55cEABeE709552", 16236998, "1.3.0"),
("0x6851D6fDFAfD08c0295C392436245E5bc78B0185", 10612049, "1.2.0"),
("0x34CfAC646f301356fAa8B21e94227e3583Fe3F5F", 10045292, "1.1.1"),
("0x2CB0ebc503dE87CFD8f0eCEED8197bF7850184ae", 12529466, "1.1.1+Circles"),
("0xb6029EA3B2c51D09a50B53CA8012FeEB05bDa35A", 19560130, "1.0.0"),
],
EthereumNetwork.ENERGY_WEB_CHAIN: [
("0x3E5c63644E683549055b9Be8653de26E0B4CD36E", 12028662, "1.3.0+L2"),
("0xd9Db270c1B5E3Bd161E8c8503c55cEABeE709552", 12028664, "1.3.0"),
("0x6851D6fDFAfD08c0295C392436245E5bc78B0185", 6398655, "1.2.0"),
("0x34CfAC646f301356fAa8B21e94227e3583Fe3F5F", 6399212, "1.1.1"),
],
EthereumNetwork.VOLTA: [
("0x3E5c63644E683549055b9Be8653de26E0B4CD36E", 11942450, "1.3.0+L2"),
("0xd9Db270c1B5E3Bd161E8c8503c55cEABeE709552", 11942451, "1.3.0"),
("0x6851D6fDFAfD08c0295C392436245E5bc78B0185", 6876086, "1.2.0"),
("0x34CfAC646f301356fAa8B21e94227e3583Fe3F5F", 6876642, "1.1.1"),
],
EthereumNetwork.MATIC: [
("0x3E5c63644E683549055b9Be8653de26E0B4CD36E", 14306478, "1.3.0+L2"),
("0xd9Db270c1B5E3Bd161E8c8503c55cEABeE709552", 14306478, "1.3.0"),
],
EthereumNetwork.MUMBAI: [
("0x3E5c63644E683549055b9Be8653de26E0B4CD36E", 13736914, "1.3.0+L2"),
("0xd9Db270c1B5E3Bd161E8c8503c55cEABeE709552", 13736914, "1.3.0"),
],
EthereumNetwork.ARBITRUM: [
("0x3E5c63644E683549055b9Be8653de26E0B4CD36E", 1146, "1.3.0+L2"),
("0xd9Db270c1B5E3Bd161E8c8503c55cEABeE709552", 1140, "1.3.0"),
],
EthereumNetwork.ARBITRUM_TESTNET: [
("0x3E5c63644E683549055b9Be8653de26E0B4CD36E", 57070, "1.3.0+L2"),
("0xd9Db270c1B5E3Bd161E8c8503c55cEABeE709552", 57070, "1.3.0"),
],
EthereumNetwork.BINANCE: [
("0x3E5c63644E683549055b9Be8653de26E0B4CD36E", 8485899, "1.3.0+L2"),
("0xd9Db270c1B5E3Bd161E8c8503c55cEABeE709552", 8485903, "1.3.0"),
],
EthereumNetwork.CELO: [
("0xfb1bffC9d739B8D520DaF37dF666da4C687191EA", 8944350, "1.3.0+L2"),
("0x69f4D1788e39c87893C980c06EdF4b7f686e2938", 8944351, "1.3.0"),
],
EthereumNetwork.AVALANCHE: [
("0xfb1bffC9d739B8D520DaF37dF666da4C687191EA", 4_949_507, "1.3.0+L2"),
("0x69f4D1788e39c87893C980c06EdF4b7f686e2938", 4_949_512, "1.3.0"),
],
EthereumNetwork.MOON_MOONRIVER: [
("0x3E5c63644E683549055b9Be8653de26E0B4CD36E", 707_738, "1.3.0+L2"),
("0xd9Db270c1B5E3Bd161E8c8503c55cEABeE709552", 707_741, "1.3.0"),
],
EthereumNetwork.MOON_MOONBASE: [
("0x3E5c63644E683549055b9Be8653de26E0B4CD36E", 939_244, "1.3.0+L2"),
("0xd9Db270c1B5E3Bd161E8c8503c55cEABeE709552", 939_246, "1.3.0"),
],
EthereumNetwork.FUSE_MAINNET: [
("0x3E5c63644E683549055b9Be8653de26E0B4CD36E", 12_725_078, "1.3.0+L2"),
("0xd9Db270c1B5E3Bd161E8c8503c55cEABeE709552", 12_725_081, "1.3.0"),
],
EthereumNetwork.FUSE_SPARK: [
("0x3E5c63644E683549055b9Be8653de26E0B4CD36E", 1_010_518, "1.3.0+L2"),
("0xd9Db270c1B5E3Bd161E8c8503c55cEABeE709552", 1_010_520, "1.3.0"),
],
EthereumNetwork.OLYMPUS: [
("0x3E5c63644E683549055b9Be8653de26E0B4CD36E", 1227, "1.3.0+L2"),
("0xd9Db270c1B5E3Bd161E8c8503c55cEABeE709552", 1278, "1.3.0"),
],
EthereumNetwork.OPTIMISTIC: [
("0xfb1bffC9d739B8D520DaF37dF666da4C687191EA", 173749, "1.3.0+L2"),
("0x69f4D1788e39c87893C980c06EdF4b7f686e2938", 173751, "1.3.0"),
],
EthereumNetwork.GATHER_DEVNET: [
("0x03A3cF69a09b5B59CDaa84a5cE3a011AC373541c", 49266, "1.3.0+L2"),
("0xFaB2a82fd127590f67EE120626E7A47b67E6912c", 49267, "1.3.0"),
],
EthereumNetwork.GATHER_TESTNET: [
("0x03A3cF69a09b5B59CDaa84a5cE3a011AC373541c", 198663, "1.3.0+L2"),
("0xFaB2a82fd127590f67EE120626E7A47b67E6912c", 198665, "1.3.0"),
],
EthereumNetwork.GATHER_MAINNET: [
("0x03A3cF69a09b5B59CDaa84a5cE3a011AC373541c", 198663, "1.3.0+L2"),
("0xFaB2a82fd127590f67EE120626E7A47b67E6912c", 198665, "1.3.0"),
],
EthereumNetwork.BOBA_RINKEBY: [
("0xfb1bffC9d739B8D520DaF37dF666da4C687191EA", 18854, "1.3.0+L2"),
("0x69f4D1788e39c87893C980c06EdF4b7f686e2938", 18855, "1.3.0"),
],
EthereumNetwork.BOBA: [
("0xfb1bffC9d739B8D520DaF37dF666da4C687191EA", 170908, "1.3.0+L2"),
("0x69f4D1788e39c87893C980c06EdF4b7f686e2938", 170910, "1.3.0"),
],
}
PROXY_FACTORIES: Dict[EthereumNetwork, List[Tuple[str, int]]] = {
EthereumNetwork.MAINNET: [
("0xa6B71E26C5e0845f74c812102Ca7114b6a896AB2", 12504126), # v1.3.0
("0x76E2cFc1F5Fa8F6a5b3fC4c8F4788F0116861F9B", 9084508), # v1.1.1
("0x50e55Af101C777bA7A1d560a774A82eF002ced9F", 8915731), # v1.1.0
("0x12302fE9c02ff50939BaAaaf415fc226C078613C", 7450116), # v1.0.0
],
EthereumNetwork.RINKEBY: [
("0xa6B71E26C5e0845f74c812102Ca7114b6a896AB2", 8493997), # v1.3.0
("0x76E2cFc1F5Fa8F6a5b3fC4c8F4788F0116861F9B", 5590757),
("0x50e55Af101C777bA7A1d560a774A82eF002ced9F", 5423494),
("0x12302fE9c02ff50939BaAaaf415fc226C078613C", 4110083),
],
EthereumNetwork.GOERLI: [
("0xa6B71E26C5e0845f74c812102Ca7114b6a896AB2", 4695402), # v1.3.0
("0x76E2cFc1F5Fa8F6a5b3fC4c8F4788F0116861F9B", 1798666),
("0x50e55Af101C777bA7A1d560a774A82eF002ced9F", 1631491),
("0x12302fE9c02ff50939BaAaaf415fc226C078613C", 312509),
],
EthereumNetwork.KOVAN: [
("0xa6B71E26C5e0845f74c812102Ca7114b6a896AB2", 25059601), # v1.3.0
("0x76E2cFc1F5Fa8F6a5b3fC4c8F4788F0116861F9B", 15366151),
("0x50e55Af101C777bA7A1d560a774A82eF002ced9F", 14740731),
("0x12302fE9c02ff50939BaAaaf415fc226C078613C", 10629898),
],
EthereumNetwork.XDAI: [
("0xa6B71E26C5e0845f74c812102Ca7114b6a896AB2", 16236878), # v1.3.0
("0x76E2cFc1F5Fa8F6a5b3fC4c8F4788F0116861F9B", 10045327), # v1.1.1
("0x12302fE9c02ff50939BaAaaf415fc226C078613C", 17677119), # v1.0.0
],
EthereumNetwork.ENERGY_WEB_CHAIN: [
("0xa6B71E26C5e0845f74c812102Ca7114b6a896AB2", 12028652), # v1.3.0
("0x76E2cFc1F5Fa8F6a5b3fC4c8F4788F0116861F9B", 6399239),
],
EthereumNetwork.VOLTA: [
# ('0xa6B71E26C5e0845f74c812102Ca7114b6a896AB2', 0), # v1.3.0
("0x76E2cFc1F5Fa8F6a5b3fC4c8F4788F0116861F9B", 6876681),
],
EthereumNetwork.MATIC: [
("0xa6B71E26C5e0845f74c812102Ca7114b6a896AB2", 14306478), # v1.3.0
],
EthereumNetwork.MUMBAI: [
("0xa6B71E26C5e0845f74c812102Ca7114b6a896AB2", 13736914), # v1.3.0
],
EthereumNetwork.ARBITRUM: [
("0xa6B71E26C5e0845f74c812102Ca7114b6a896AB2", 1140), # v1.3.0
],
EthereumNetwork.ARBITRUM_TESTNET: [
("0xa6B71E26C5e0845f74c812102Ca7114b6a896AB2", 57070), # v1.3.0
],
EthereumNetwork.BINANCE: [
("0xa6B71E26C5e0845f74c812102Ca7114b6a896AB2", 8485873), # v1.3.0
],
EthereumNetwork.CELO: [
("0xC22834581EbC8527d974F8a1c97E1bEA4EF910BC", 8944342), # v1.3.0
],
EthereumNetwork.AVALANCHE: [
("0xC22834581EbC8527d974F8a1c97E1bEA4EF910BC", 4_949_487), # v1.3.0
],
EthereumNetwork.MOON_MOONRIVER: [
("0xa6B71E26C5e0845f74c812102Ca7114b6a896AB2", 707_721), # v1.3.0
],
EthereumNetwork.MOON_MOONBASE: [
("0xa6B71E26C5e0845f74c812102Ca7114b6a896AB2", 939_239), # v1.3.0
],
EthereumNetwork.FUSE_MAINNET: [
("0xa6B71E26C5e0845f74c812102Ca7114b6a896AB2", 12_725_072), # v1.3.0
],
EthereumNetwork.FUSE_SPARK: [
("0xa6B71E26C5e0845f74c812102Ca7114b6a896AB2", 1_010_506), # v1.3.0
],
EthereumNetwork.OLYMPUS: [
("0xa6B71E26C5e0845f74c812102Ca7114b6a896AB2", 1266), # v1.3.0
],
EthereumNetwork.OPTIMISTIC: [
("0xC22834581EbC8527d974F8a1c97E1bEA4EF910BC", 173709), # v1.3.0
],
EthereumNetwork.GATHER_DEVNET: [
("0xAFE7785C8f5Bb3ABb8dDa81a6b79628Fd64a2794", 49256), # v1.3.0
],
EthereumNetwork.GATHER_TESTNET: [
("0xAFE7785C8f5Bb3ABb8dDa81a6b79628Fd64a2794", 198649), # v1.3.0
],
EthereumNetwork.GATHER_MAINNET: [
("0xAFE7785C8f5Bb3ABb8dDa81a6b79628Fd64a2794", 198649), # v1.3.0
],
EthereumNetwork.BOBA_RINKEBY: [
("0xC22834581EbC8527d974F8a1c97E1bEA4EF910BC", 18847), # v1.3.0
],
EthereumNetwork.BOBA: [
("0xC22834581EbC8527d974F8a1c97E1bEA4EF910BC", 170895), # v1.3.0
],
}
class Command(BaseCommand):
help = "Setup Transaction Service Required Tasks"
def handle(self, *args, **options):
self.stdout.write(self.style.SUCCESS("Removing old tasks"))
PeriodicTask.objects.filter(
name__startswith="safe_transaction_service"
).delete()
self.stdout.write(self.style.SUCCESS("Old tasks were removed"))
for task in TASKS:
_, created = task.create_task()
if created:
self.stdout.write(
self.style.SUCCESS("Created Periodic Task %s" % task.name)
)
else:
self.stdout.write(
self.style.SUCCESS("Task %s was already created" % task.name)
)
self.stdout.write(self.style.SUCCESS("Setting up Safe Contract Addresses"))
ethereum_client = EthereumClientProvider()
ethereum_network = ethereum_client.get_network()
if ethereum_network in MASTER_COPIES:
self.stdout.write(
self.style.SUCCESS(f"Setting up {ethereum_network.name} safe addresses")
)
self._setup_safe_master_copies(MASTER_COPIES[ethereum_network])
if ethereum_network in PROXY_FACTORIES:
self.stdout.write(
self.style.SUCCESS(
f"Setting up {ethereum_network.name} proxy factory addresses"
)
)
self._setup_safe_proxy_factories(PROXY_FACTORIES[ethereum_network])
if not (
ethereum_network in MASTER_COPIES and ethereum_network in PROXY_FACTORIES
):
self.stdout.write(
self.style.WARNING("Cannot detect a valid ethereum-network")
)
def _setup_safe_master_copies(
self, safe_master_copies: Sequence[Tuple[str, int, str]]
):
for address, initial_block_number, version in safe_master_copies:
safe_master_copy, _ = SafeMasterCopy.objects.get_or_create(
address=address,
defaults={
"initial_block_number": initial_block_number,
"tx_block_number": initial_block_number,
"version": version,
"l2": version.endswith("+L2"),
},
)
if (
safe_master_copy.version != version
or safe_master_copy.initial_block_number != initial_block_number
):
safe_master_copy.version = initial_block_number
safe_master_copy.version = version
safe_master_copy.save(update_fields=["initial_block_number", "version"])
def _setup_safe_proxy_factories(
self, safe_proxy_factories: Sequence[Tuple[str, int]]
):
for address, initial_block_number in safe_proxy_factories:
ProxyFactory.objects.get_or_create(
address=address,
defaults={
"initial_block_number": initial_block_number,
"tx_block_number": initial_block_number,
},
)