Skip to content

Commit 636cc60

Browse files
committed
Added Burn & Sync events
1 parent 3740730 commit 636cc60

File tree

4 files changed

+327
-38
lines changed

4 files changed

+327
-38
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
[
2+
{
3+
"inputs":[{"internalType":"address","name":"_feeToSetter","type":"address"}],
4+
"payable":false,"stateMutability":"nonpayable","type":"constructor"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"token0","type":"address"},{"indexed":true,"internalType":"address","name":"token1","type":"address"},{"indexed":false,"internalType":"address","name":"pair","type":"address"},{"indexed":false,"internalType":"uint256","name":"","type":"uint256"}],"name":"PairCreated","type":"event"},{"constant":true,"inputs":[{"internalType":"uint256","name":"","type":"uint256"}],"name":"allPairs","outputs":[{"internalType":"address","name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"allPairsLength","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"internalType":"address","name":"tokenA","type":"address"},{"internalType":"address","name":"tokenB","type":"address"}],"name":"createPair","outputs":[{"internalType":"address","name":"pair","type":"address"}],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"feeTo","outputs":[{"internalType":"address","name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"feeToSetter","outputs":[{"internalType":"address","name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"internalType":"address","name":"","type":"address"},{"internalType":"address","name":"","type":"address"}],"name":"getPair","outputs":[{"internalType":"address","name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"internalType":"address","name":"_feeTo","type":"address"}],"name":"setFeeTo","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"internalType":"address","name":"_feeToSetter","type":"address"}],"name":"setFeeToSetter","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"}]

services/decoder/protocols/uniswap-v2/uniswap-v2.configs.ts

+18-1
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,28 @@ import { type Configs } from "../../decoder.types";
33
const configs: Configs = [
44
{
55
protocol_name: "uniswap-v2",
6-
// ? only for testing
76
address: "0xaf31fd9c3b0350424bf96e551d2d1264d8466205",
87
is_factory: false,
98
network: "eth-mainnet",
109
},
10+
{
11+
address: "0xb4e16d0168e52d35cacd2c6185b44281ec28c9dc",
12+
is_factory: false,
13+
protocol_name: "uniswap-v2",
14+
network: "eth-mainnet",
15+
},
16+
{
17+
address: "0x0d4a11d5eeaac28ec3f61d100daf4d40471f1852",
18+
is_factory: false,
19+
protocol_name: "uniswap-v2",
20+
network: "eth-mainnet",
21+
},
22+
{
23+
address: "0x5c69bee701ef814a2b6a3edd4b1652cb9cc5aa6f",
24+
is_factory: true,
25+
protocol_name: "uniswap-v2",
26+
network: "eth-mainnet",
27+
},
1128
];
1229

1330
export default configs;

services/decoder/protocols/uniswap-v2/uniswap-v2.decoders.ts

+267-37
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { GoldRushDecoder } from "../../decoder";
44
import { TimestampParser } from "../../../../utils/functions";
55
import { type EventType } from "../../decoder.types";
66
import PairABI from "./abis/uniswap-v2.pair.abi.json";
7+
import FactoryABI from "./abis/uniswap-v2.factory.abi.json";
78
import {
89
DECODED_ACTION,
910
DECODED_EVENT_CATEGORY,
@@ -45,8 +46,6 @@ GoldRushDecoder.on(
4546
inputDecimals: number = 0,
4647
outputDecimals: number = 0;
4748

48-
const prices: number[] = [];
49-
5049
const { data } = await covalent_client.XykService.getPoolByAddress(
5150
chain_name,
5251
"uniswap_v2",
@@ -70,33 +69,6 @@ GoldRushDecoder.on(
7069
decoded.amount0Out,
7170
];
7271
}
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-
});
10072
}
10173

10274
return {
@@ -112,27 +84,31 @@ GoldRushDecoder.on(
11284
ticker_logo: inputToken?.logo_url ?? null,
11385
ticker_symbol: inputToken?.contract_ticker_symbol ?? null,
11486
value: inputValue.toString(),
115-
decimals: inputDecimals,
87+
decimals: +(inputToken?.contract_decimals ?? 18),
11688
pretty_quote: prettifyCurrency(
11789
inputToken?.quote_rate ??
11890
0 *
11991
(Number(inputValue) /
120-
Math.pow(10, inputDecimals))
92+
Math.pow(10,
93+
+(inputToken?.contract_decimals ?? 18)
94+
))
12195
),
122-
heading: "Input",
96+
heading: "Token In",
12397
},
12498
{
12599
ticker_logo: outputToken?.logo_url ?? null,
126100
ticker_symbol: outputToken?.contract_ticker_symbol ?? null,
127101
value: outputValue.toString(),
128-
decimals: outputDecimals,
102+
decimals: +(outputToken?.contract_decimals ?? 18),
129103
pretty_quote: prettifyCurrency(
130104
outputToken?.quote_rate ??
131105
0 *
132106
(Number(outputValue) /
133-
Math.pow(10, outputDecimals))
107+
Math.pow(10,
108+
+(outputToken?.contract_decimals ?? 18)
109+
))
134110
),
135-
heading: "Output",
111+
heading: "Token Out",
136112
},
137113
],
138114
};
@@ -207,7 +183,7 @@ GoldRushDecoder.on(
207183
+(token0?.contract_decimals ?? 18)
208184
))
209185
),
210-
heading: "Input",
186+
heading: "Token 0 Deposited",
211187
},
212188
{
213189
ticker_logo: token1?.logo_url ?? null,
@@ -223,9 +199,263 @@ GoldRushDecoder.on(
223199
+(token1?.contract_decimals ?? 18)
224200
))
225201
),
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",
227388
},
228389
],
229390
};
391+
230392
}
231393
);
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

Comments
 (0)