Skip to content

Commit 91f9341

Browse files
committed
added collect fees
1 parent 0e70d0e commit 91f9341

File tree

2 files changed

+274
-1
lines changed

2 files changed

+274
-1
lines changed

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

+223-1
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ GoldRushDecoder.on(
125125
const { raw_log_data, raw_log_topics } = log_event;
126126

127127
const { args: decoded } = decodeEventLog({
128-
abi: FactoryABI,
128+
abi: PairABI,
129129
topics: raw_log_topics as [],
130130
data: raw_log_data as `0x${string}`,
131131
eventName: "Burn",
@@ -186,3 +186,225 @@ GoldRushDecoder.on(
186186
};
187187
}
188188
);
189+
190+
GoldRushDecoder.on(
191+
"uniswap-v3:Mint",
192+
["eth-mainnet"],
193+
PairABI as Abi,
194+
async (log_event, tx, chain_name, covalent_client): Promise<EventType> => {
195+
const { raw_log_data, raw_log_topics } = log_event;
196+
197+
const { args: decoded } = decodeEventLog({
198+
abi: PairABI,
199+
topics: raw_log_topics as [],
200+
data: raw_log_data as `0x${string}`,
201+
eventName: "Mint",
202+
}) as {
203+
eventName: "Mint";
204+
args: {
205+
sender: string;
206+
owner: string;
207+
tickLower: bigint;
208+
tickUpper: bigint;
209+
amount: bigint;
210+
amount0: bigint;
211+
amount1: bigint;
212+
};
213+
};
214+
215+
const details: EventDetails = [
216+
{
217+
heading: "sender",
218+
value: decoded.sender,
219+
type: "address"
220+
},
221+
{
222+
heading: "owner",
223+
value: decoded.owner,
224+
type: "address"
225+
},
226+
{
227+
heading: "tickLower",
228+
value: decoded.tickLower.toString(),
229+
type: "text"
230+
},
231+
{
232+
heading: "tickUpper",
233+
value: decoded.tickUpper.toString(),
234+
type: "text"
235+
},
236+
{
237+
heading: "amount",
238+
value: decoded.amount.toString(),
239+
type: "text"
240+
},
241+
{
242+
heading: "amount0",
243+
value: decoded.amount0.toString(),
244+
type: "text"
245+
},
246+
{
247+
heading: "amount1",
248+
value: decoded.amount1.toString(),
249+
type: "text"
250+
},
251+
];
252+
253+
return {
254+
action: DECODED_ACTION.SWAPPED,
255+
category: DECODED_EVENT_CATEGORY.DEX,
256+
name: "Mint",
257+
protocol: {
258+
logo: log_event.sender_logo_url as string,
259+
name: "Uniswap V3",
260+
},
261+
details,
262+
};
263+
}
264+
);
265+
266+
GoldRushDecoder.on(
267+
"uniswap-v3:Swap",
268+
["eth-mainnet"],
269+
PairABI as Abi,
270+
async (log_event, tx, chain_name, covalent_client): Promise<EventType> => {
271+
const { raw_log_data, raw_log_topics } = log_event;
272+
273+
const { args: decoded } = decodeEventLog({
274+
abi: PairABI,
275+
topics: raw_log_topics as [],
276+
data: raw_log_data as `0x${string}`,
277+
eventName: "Swap",
278+
}) as {
279+
eventName: "Swap";
280+
args: {
281+
sender: string;
282+
recipient: string;
283+
amount0: bigint;
284+
amount1: bigint;
285+
sqrtPriceX96: bigint;
286+
liquidity: bigint;
287+
tick: bigint;
288+
};
289+
};
290+
291+
const details: EventDetails = [
292+
{
293+
heading: "sender",
294+
value: decoded.sender,
295+
type: "address"
296+
},
297+
{
298+
heading: "recipient",
299+
value: decoded.recipient,
300+
type: "address"
301+
},
302+
{
303+
heading: "amount0",
304+
value: decoded.amount0.toString(),
305+
type: "text"
306+
},
307+
{
308+
heading: "amount1",
309+
value: decoded.amount1.toString(),
310+
type: "text"
311+
},
312+
{
313+
heading: "sqrtPriceX96",
314+
value: decoded.sqrtPriceX96.toString(),
315+
type: "text"
316+
},
317+
{
318+
heading: "liquidity",
319+
value: decoded.liquidity.toString(),
320+
type: "text"
321+
},
322+
{
323+
heading: "tick",
324+
value: decoded.tick.toString(),
325+
type: "text"
326+
},
327+
];
328+
329+
return {
330+
action: DECODED_ACTION.SWAPPED,
331+
category: DECODED_EVENT_CATEGORY.DEX,
332+
name: "Swap",
333+
protocol: {
334+
logo: log_event.sender_logo_url as string,
335+
name: "Uniswap V3",
336+
},
337+
details,
338+
};
339+
}
340+
);
341+
342+
GoldRushDecoder.on(
343+
"uniswap-v3:Collect",
344+
["eth-mainnet"],
345+
PairABI as Abi,
346+
async (log_event, tx, chain_name, covalent_client): Promise<EventType> => {
347+
const { raw_log_data, raw_log_topics } = log_event;
348+
349+
const { args: decoded } = decodeEventLog({
350+
abi: PairABI,
351+
topics: raw_log_topics as [],
352+
data: raw_log_data as `0x${string}`,
353+
eventName: "Collect",
354+
}) as {
355+
eventName: "Collect";
356+
args: {
357+
owner: string;
358+
recipient: string;
359+
tickLower: bigint;
360+
tickUpper: bigint;
361+
amount0: bigint;
362+
amount1: bigint;
363+
};
364+
};
365+
366+
const details: EventDetails = [
367+
{
368+
heading: "owner",
369+
value: decoded.owner,
370+
type: "address"
371+
},
372+
{
373+
heading: "recipient",
374+
value: decoded.recipient,
375+
type: "address"
376+
},
377+
{
378+
heading: "tickLower",
379+
value: decoded.tickLower.toString(),
380+
type: "text"
381+
},
382+
{
383+
heading: "tickUpper",
384+
value: decoded.tickUpper.toString(),
385+
type: "text"
386+
},
387+
{
388+
heading: "amount0",
389+
value: decoded.amount0.toString(),
390+
type: "text"
391+
},
392+
{
393+
heading: "amount1",
394+
value: decoded.amount1.toString(),
395+
type: "text"
396+
},
397+
];
398+
399+
return {
400+
action: DECODED_ACTION.SWAPPED,
401+
category: DECODED_EVENT_CATEGORY.DEX,
402+
name: "Collect Fees",
403+
protocol: {
404+
logo: log_event.sender_logo_url as string,
405+
name: "Uniswap V3",
406+
},
407+
details,
408+
};
409+
}
410+
);

services/decoder/protocols/uniswap-v3/uniswap-v3.test.ts

+51
Original file line numberDiff line numberDiff line change
@@ -36,4 +36,55 @@ describe("uniswap-v3", () => {
3636
const testAdded: boolean = false;
3737
expect(testAdded).toEqual(true);
3838
});
39+
40+
test("eth-mainnet:Burn", async () => {
41+
const res = await request(app)
42+
.post("/api/v1/tx/decode")
43+
.set({ "x-covalent-api-key": process.env.TEST_COVALENT_API_KEY })
44+
.send({
45+
chain_name: "eth-mainnet",
46+
tx_hash: "0x509ffb3e2e1338991b27284d6365a93bdf36ac50a9a89e6260b5f791bf0e50e6",
47+
});
48+
const { events } = res.body as { events: EventType[] };
49+
const event = events.find(({ name }) => name === "Burn");
50+
if (!event) {
51+
throw Error("Event not found");
52+
}
53+
const testAdded: boolean = false;
54+
expect(testAdded).toEqual(true);
55+
});
56+
57+
test("eth-mainnet:Swap", async () => {
58+
const res = await request(app)
59+
.post("/api/v1/tx/decode")
60+
.set({ "x-covalent-api-key": process.env.TEST_COVALENT_API_KEY })
61+
.send({
62+
chain_name: "eth-mainnet",
63+
tx_hash: "0xf0c18bcdeb3b167a7323499307b6a18031450bf955cf9ec1153231f97898f391",
64+
});
65+
const { events } = res.body as { events: EventType[] };
66+
const event = events.find(({ name }) => name === "Swap");
67+
if (!event) {
68+
throw Error("Event not found");
69+
}
70+
const testAdded: boolean = false;
71+
expect(testAdded).toEqual(true);
72+
});
73+
74+
test("eth-mainnet:Collect", async () => {
75+
const res = await request(app)
76+
.post("/api/v1/tx/decode")
77+
.set({ "x-covalent-api-key": process.env.TEST_COVALENT_API_KEY })
78+
.send({
79+
chain_name: "eth-mainnet",
80+
tx_hash: "0x7c927bbab8a2f60f0a36ee9425c03db556a44c87dddf855d5641f5f1c2270ebd",
81+
});
82+
const { events } = res.body as { events: EventType[] };
83+
const event = events.find(({ name }) => name === "Collect");
84+
if (!event) {
85+
throw Error("Event not found");
86+
}
87+
const testAdded: boolean = false;
88+
expect(testAdded).toEqual(true);
89+
});
3990
});

0 commit comments

Comments
 (0)