@@ -4,6 +4,7 @@ import { GoldRushDecoder } from "../../decoder";
4
4
import { TimestampParser } from "../../../../utils/functions" ;
5
5
import { type EventType } from "../../decoder.types" ;
6
6
import PairABI from "./abis/uniswap-v2.pair.abi.json" ;
7
+ import FactoryABI from "./abis/uniswap-v2.factory.abi.json" ;
7
8
import {
8
9
DECODED_ACTION ,
9
10
DECODED_EVENT_CATEGORY ,
@@ -45,8 +46,6 @@ GoldRushDecoder.on(
45
46
inputDecimals : number = 0 ,
46
47
outputDecimals : number = 0 ;
47
48
48
- const prices : number [ ] = [ ] ;
49
-
50
49
const { data } = await covalent_client . XykService . getPoolByAddress (
51
50
chain_name ,
52
51
"uniswap_v2" ,
@@ -70,33 +69,6 @@ GoldRushDecoder.on(
70
69
decoded . amount0Out ,
71
70
] ;
72
71
}
73
-
74
- inputDecimals = + inputToken . contract_decimals ;
75
- outputDecimals = + outputToken . contract_decimals ;
76
-
77
- const date = TimestampParser ( block_signed_at , "YYYY-MM-DD" ) ;
78
- const pricesData = await Promise . all (
79
- [ inputToken , outputToken ] . map (
80
- ( { contract_address : token_address } ) =>
81
- covalent_client . PricingService . getTokenPrices (
82
- chain_name ,
83
- "USD" ,
84
- token_address ,
85
- {
86
- from : date ,
87
- to : date ,
88
- }
89
- )
90
- )
91
- ) ;
92
- pricesData . forEach ( ( { data } ) => {
93
- const price = data ?. [ 0 ] ?. items ;
94
- if ( price ?. [ 0 ] ?. price ) {
95
- prices . push ( price [ 0 ] . price ) ;
96
- } else {
97
- prices . push ( 1 ) ;
98
- }
99
- } ) ;
100
72
}
101
73
102
74
return {
@@ -112,27 +84,31 @@ GoldRushDecoder.on(
112
84
ticker_logo : inputToken ?. logo_url ?? null ,
113
85
ticker_symbol : inputToken ?. contract_ticker_symbol ?? null ,
114
86
value : inputValue . toString ( ) ,
115
- decimals : inputDecimals ,
87
+ decimals : + ( inputToken ?. contract_decimals ?? 18 ) ,
116
88
pretty_quote : prettifyCurrency (
117
89
inputToken ?. quote_rate ??
118
90
0 *
119
91
( Number ( inputValue ) /
120
- Math . pow ( 10 , inputDecimals ) )
92
+ Math . pow ( 10 ,
93
+ + ( inputToken ?. contract_decimals ?? 18 )
94
+ ) )
121
95
) ,
122
- heading : "Input " ,
96
+ heading : "Token In " ,
123
97
} ,
124
98
{
125
99
ticker_logo : outputToken ?. logo_url ?? null ,
126
100
ticker_symbol : outputToken ?. contract_ticker_symbol ?? null ,
127
101
value : outputValue . toString ( ) ,
128
- decimals : outputDecimals ,
102
+ decimals : + ( outputToken ?. contract_decimals ?? 18 ) ,
129
103
pretty_quote : prettifyCurrency (
130
104
outputToken ?. quote_rate ??
131
105
0 *
132
106
( Number ( outputValue ) /
133
- Math . pow ( 10 , outputDecimals ) )
107
+ Math . pow ( 10 ,
108
+ + ( outputToken ?. contract_decimals ?? 18 )
109
+ ) )
134
110
) ,
135
- heading : "Output " ,
111
+ heading : "Token Out " ,
136
112
} ,
137
113
] ,
138
114
} ;
@@ -207,7 +183,7 @@ GoldRushDecoder.on(
207
183
+ ( token0 ?. contract_decimals ?? 18 )
208
184
) )
209
185
) ,
210
- heading : "Input " ,
186
+ heading : "Token 0 Deposited " ,
211
187
} ,
212
188
{
213
189
ticker_logo : token1 ?. logo_url ?? null ,
@@ -223,9 +199,263 @@ GoldRushDecoder.on(
223
199
+ ( token1 ?. contract_decimals ?? 18 )
224
200
) )
225
201
) ,
226
- heading : "Output" ,
202
+ heading : "Token 1 Deposited" ,
203
+ } ,
204
+ ] ,
205
+ } ;
206
+ }
207
+ ) ;
208
+
209
+ GoldRushDecoder . on (
210
+ "uniswap-v2:Burn" ,
211
+ [ "eth-mainnet" ] ,
212
+ PairABI as Abi ,
213
+ async ( log_event , tx , chain_name , covalent_client ) : Promise < EventType > => {
214
+ const {
215
+ sender_address : exchange_contract ,
216
+ block_signed_at,
217
+ raw_log_data,
218
+ raw_log_topics
219
+ } = log_event ;
220
+
221
+ const { args : decoded } = decodeEventLog ( {
222
+ abi : PairABI ,
223
+ topics : raw_log_topics as [ ] ,
224
+ data : raw_log_data as '0x${string}' ,
225
+ eventName : "Burn"
226
+ } ) as {
227
+ eventName : "Burn" ;
228
+ args : {
229
+ sender : string ;
230
+ amount0 : bigint ;
231
+ amount1 : bigint ;
232
+ to : string ;
233
+ } ;
234
+ } ;
235
+
236
+ let token0 : Token | null = null ,
237
+ token1 : Token | null = null ,
238
+ value0 : bigint = BigInt ( 0 ) ,
239
+ value1 : bigint = BigInt ( 0 ) ;
240
+
241
+ const { data } = await covalent_client . XykService . getPoolByAddress (
242
+ chain_name ,
243
+ "uniswap_v2" ,
244
+ exchange_contract
245
+ ) ;
246
+ const { token_0, token_1 } = data ?. items ?. [ 0 ] ;
247
+ if ( token_0 && token_1 ) {
248
+ [ token0 , token1 , value0 , value1 ] = [
249
+ token_0 ,
250
+ token_1 ,
251
+ decoded . amount0 ,
252
+ decoded . amount1 ,
253
+ ] ;
254
+ }
255
+
256
+ return {
257
+ action : DECODED_ACTION . SWAPPED ,
258
+ category : DECODED_EVENT_CATEGORY . DEX ,
259
+ name : "Burn" ,
260
+ protocol : {
261
+ logo : log_event . sender_logo_url as string ,
262
+ name : log_event . sender_name as string ,
263
+ } ,
264
+ tokens : [
265
+ {
266
+ ticker_logo : token0 ?. logo_url ?? null ,
267
+ ticker_symbol : token0 ?. contract_ticker_symbol ?? null ,
268
+ value : value0 . toString ( ) ,
269
+ decimals : + ( token0 ?. contract_decimals ?? 18 ) ,
270
+ pretty_quote : prettifyCurrency (
271
+ token0 ?. quote_rate ??
272
+ 0 *
273
+ ( Number ( value0 ) /
274
+ Math . pow (
275
+ 10 ,
276
+ + ( token0 ?. contract_decimals ?? 18 )
277
+ ) )
278
+ ) ,
279
+ heading : "Token 0 Redeemed" ,
280
+ } ,
281
+ {
282
+ ticker_logo : token1 ?. logo_url ?? null ,
283
+ ticker_symbol : token1 ?. contract_ticker_symbol ?? null ,
284
+ value : value1 . toString ( ) ,
285
+ decimals : + ( token1 ?. contract_decimals ?? 18 ) ,
286
+ pretty_quote : prettifyCurrency (
287
+ token1 ?. quote_rate ??
288
+ 0 *
289
+ ( Number ( value0 ) /
290
+ Math . pow (
291
+ 10 ,
292
+ + ( token1 ?. contract_decimals ?? 18 )
293
+ ) )
294
+ ) ,
295
+ heading : "Token 1 Redeemed" ,
296
+ } ,
297
+ ] ,
298
+ } ;
299
+
300
+ }
301
+ ) ;
302
+
303
+ GoldRushDecoder . on (
304
+ "uniswap-v2:Sync" ,
305
+ [ "eth-mainnet" ] ,
306
+ PairABI as Abi ,
307
+ async ( log_event , tx , chain_name , covalent_client ) : Promise < EventType > => {
308
+ const {
309
+ sender_address : exchange_contract ,
310
+ block_signed_at,
311
+ raw_log_data,
312
+ raw_log_topics
313
+ } = log_event ;
314
+
315
+ const { args : decoded } = decodeEventLog ( {
316
+ abi : PairABI ,
317
+ topics : raw_log_topics as [ ] ,
318
+ data : raw_log_data as '0x${string}' ,
319
+ eventName : "Sync"
320
+ } ) as {
321
+ eventName : "Sync" ;
322
+ args : {
323
+ reserve0 : bigint ;
324
+ reserve1 : bigint ;
325
+ } ;
326
+ } ;
327
+
328
+ let token0 : Token | null = null ,
329
+ token1 : Token | null = null ,
330
+ value0 : bigint = BigInt ( 0 ) ,
331
+ value1 : bigint = BigInt ( 0 ) ;
332
+
333
+ const { data } = await covalent_client . XykService . getPoolByAddress (
334
+ chain_name ,
335
+ "uniswap_v2" ,
336
+ exchange_contract
337
+ ) ;
338
+ const { token_0, token_1 } = data ?. items ?. [ 0 ] ;
339
+ if ( token_0 && token_1 ) {
340
+ [ token0 , token1 , value0 , value1 ] = [
341
+ token_0 ,
342
+ token_1 ,
343
+ decoded . reserve0 ,
344
+ decoded . reserve1 ,
345
+ ] ;
346
+ }
347
+
348
+ return {
349
+ action : DECODED_ACTION . SWAPPED ,
350
+ category : DECODED_EVENT_CATEGORY . DEX ,
351
+ name : "Sync" ,
352
+ protocol : {
353
+ logo : log_event . sender_logo_url as string ,
354
+ name : log_event . sender_name as string ,
355
+ } ,
356
+ tokens : [
357
+ {
358
+ ticker_logo : token0 ?. logo_url ?? null ,
359
+ ticker_symbol : token0 ?. contract_ticker_symbol ?? null ,
360
+ value : value0 . toString ( ) ,
361
+ decimals : + ( token0 ?. contract_decimals ?? 18 ) ,
362
+ pretty_quote : prettifyCurrency (
363
+ token0 ?. quote_rate ??
364
+ 0 *
365
+ ( Number ( value0 ) /
366
+ Math . pow (
367
+ 10 ,
368
+ + ( token0 ?. contract_decimals ?? 18 )
369
+ ) )
370
+ ) ,
371
+ heading : "Reserve 0" ,
372
+ } ,
373
+ {
374
+ ticker_logo : token1 ?. logo_url ?? null ,
375
+ ticker_symbol : token1 ?. contract_ticker_symbol ?? null ,
376
+ value : value1 . toString ( ) ,
377
+ decimals : + ( token1 ?. contract_decimals ?? 18 ) ,
378
+ pretty_quote : prettifyCurrency (
379
+ token1 ?. quote_rate ??
380
+ 0 *
381
+ ( Number ( value0 ) /
382
+ Math . pow (
383
+ 10 ,
384
+ + ( token1 ?. contract_decimals ?? 18 )
385
+ ) )
386
+ ) ,
387
+ heading : "Reserve 1" ,
227
388
} ,
228
389
] ,
229
390
} ;
391
+
230
392
}
231
393
) ;
394
+
395
+ GoldRushDecoder . on (
396
+ "uniswap-v2:Pair Created" ,
397
+ [ "eth-mainnet" ] ,
398
+ FactoryABI as Abi ,
399
+ async ( log_event , tx , chain_name , covalent_client ) : Promise < EventType > => {
400
+ const {
401
+ sender_address : exchange_contract ,
402
+ block_signed_at,
403
+ raw_log_data,
404
+ raw_log_topics
405
+ } = log_event ;
406
+
407
+ const { args : decoded } = decodeEventLog ( {
408
+ abi : FactoryABI ,
409
+ topics : raw_log_topics as [ ] ,
410
+ data : raw_log_data as '0x${string}' ,
411
+ eventName : "Pair Created"
412
+ } ) as {
413
+ eventName : "Pair Created" ;
414
+ args : {
415
+ token0 : string ;
416
+ token1 : string ;
417
+ pair : string ;
418
+ noname : bigint ;
419
+ } ;
420
+ } ;
421
+
422
+ let token0 : Token | null = null ,
423
+ token1 : Token | null = null ,
424
+ pair : Token | null = null ;
425
+
426
+ const { data } = await covalent_client . XykService . getPoolByAddress (
427
+ chain_name ,
428
+ "uniswap_v2" ,
429
+ exchange_contract
430
+ ) ;
431
+ const { token_0, token_1 } = data ?. items ?. [ 0 ] ;
432
+ if ( token_0 && token_1 ) {
433
+ [ token0 , token1 ] = [
434
+ token_0 ,
435
+ token_1 ,
436
+ ] ;
437
+ }
438
+
439
+ return {
440
+ action : DECODED_ACTION . SWAPPED ,
441
+ category : DECODED_EVENT_CATEGORY . DEX ,
442
+ name : "Pair Created" ,
443
+ protocol : {
444
+ logo : log_event . sender_logo_url as string ,
445
+ name : log_event . sender_name as string ,
446
+ } ,
447
+ tokens : [
448
+ {
449
+ ticker_logo : token0 ?. logo_url ?? null ,
450
+ ticker_symbol : token0 ?. contract_ticker_symbol ?? null ,
451
+ heading : "Token 0" ,
452
+ } ,
453
+ {
454
+
455
+ heading : "Token 1" ,
456
+ } ,
457
+ ] ,
458
+ } ;
459
+
460
+ }
461
+ ) ;
0 commit comments