Skip to content

Commit bf59dab

Browse files
committed
fix(uniswap v2): pair created
1 parent 1db38b8 commit bf59dab

File tree

2 files changed

+89
-63
lines changed

2 files changed

+89
-63
lines changed

services/decoder/protocols/uniswap-v2/abis/uniswap-v2.factory.abi.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
{
3636
"indexed": false,
3737
"internalType": "uint256",
38-
"name": "",
38+
"name": "allPairsLength",
3939
"type": "uint256"
4040
}
4141
],
@@ -190,4 +190,4 @@
190190
"stateMutability": "nonpayable",
191191
"type": "function"
192192
}
193-
]
193+
]

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

+87-61
Original file line numberDiff line numberDiff line change
@@ -417,67 +417,93 @@ GoldRushDecoder.on(
417417
}
418418
);
419419

420-
// GoldRushDecoder.on(
421-
// "uniswap-v2:PairCreated",
422-
// ["eth-mainnet"],
423-
// FactoryABI as Abi,
424-
// async (log_event, tx, chain_name, covalent_client): Promise<EventType> => {
425-
// const { raw_log_data, raw_log_topics } = log_event;
426-
427-
// const { args: decoded } = decodeEventLog({
428-
// abi: FactoryABI,
429-
// topics: raw_log_topics as [],
430-
// data: raw_log_data as `0x${string}`,
431-
// eventName: "LOL",
432-
// }) as {
433-
// eventName: "LOL";
434-
// args: {};
435-
// };
436-
437-
// console.log(decoded);
420+
GoldRushDecoder.on(
421+
"uniswap-v2:PairCreated",
422+
["eth-mainnet"],
423+
FactoryABI as Abi,
424+
async (log_event, tx, chain_name, covalent_client): Promise<EventType> => {
425+
const { raw_log_data, raw_log_topics } = log_event;
438426

439-
// let token0: Token | null = null,
440-
// token1: Token | null = null;
427+
const { args: decoded } = decodeEventLog({
428+
abi: FactoryABI,
429+
topics: raw_log_topics as [],
430+
data: raw_log_data as `0x${string}`,
431+
eventName: "PairCreated",
432+
strict: false,
433+
}) as {
434+
eventName: "PairCreated";
435+
args: {
436+
token0: string;
437+
token1: string;
438+
pair: string;
439+
allPairsLength: bigint;
440+
};
441+
};
441442

442-
// // const { data } = await covalent_client.XykService.getPoolByAddress(
443-
// // chain_name,
444-
// // "uniswap_v2",
445-
// // decoded.pair
446-
// // );
447-
// // console.log(data)
448-
// // const { token_0, token_1 } = data?.items?.[0];
449-
// // if (token_0 && token_1) {
450-
// // [token0, token1] = [
451-
// // token_0,
452-
// // token_1,
453-
// // ];
454-
// // }
443+
const { data } = await covalent_client.XykService.getPoolByAddress(
444+
chain_name,
445+
"uniswap_v2",
446+
decoded.pair
447+
);
455448

456-
// return {
457-
// action: DECODED_ACTION.SWAPPED,
458-
// category: DECODED_EVENT_CATEGORY.DEX,
459-
// name: "Pair Created",
460-
// protocol: {
461-
// logo: log_event.sender_logo_url as string,
462-
// name: log_event.sender_name as string,
463-
// },
464-
// details: [
465-
// // {
466-
// // title: `${token0?.contract_name || ""} Symbol`, // USDC Name
467-
// // value: token0?.contract_ticker_symbol || "",
468-
// // type: "text",
469-
// // },
470-
// // {
471-
// // title: `${token0?.contract_name || ""} Decimals`,
472-
// // value: (token0?.contract_decimals ?? 18).toString(),
473-
// // type: "text",
474-
// // },
475-
// // {
476-
// // title: `${token0?.contract_name || ""} Address`,
477-
// // value: token0?.contract_address || "",
478-
// // type: "address",
479-
// // },
480-
// ],
481-
// };
482-
// }
483-
// );
449+
return {
450+
action: DECODED_ACTION.SWAPPED,
451+
category: DECODED_EVENT_CATEGORY.DEX,
452+
name: "Pair Created",
453+
protocol: {
454+
logo: log_event.sender_logo_url as string,
455+
name: log_event.sender_name as string,
456+
},
457+
details: [
458+
{
459+
title: `${
460+
data?.items?.[0]?.token_0?.contract_name || ""
461+
} Symbol`,
462+
value:
463+
data?.items?.[0]?.token_0?.contract_ticker_symbol || "",
464+
type: "text",
465+
},
466+
{
467+
title: `${
468+
data?.items?.[0]?.token_0?.contract_name || ""
469+
} Decimals`,
470+
value: (
471+
data?.items?.[0]?.token_0?.contract_decimals ?? 18
472+
).toString(),
473+
type: "text",
474+
},
475+
{
476+
title: `${
477+
data?.items?.[0]?.token_0?.contract_name || ""
478+
} Address`,
479+
value: data?.items?.[0]?.token_0?.contract_address || "",
480+
type: "address",
481+
},
482+
{
483+
title: `${
484+
data?.items?.[0]?.token_1?.contract_name || ""
485+
} Symbol`,
486+
value:
487+
data?.items?.[0]?.token_1?.contract_ticker_symbol || "",
488+
type: "text",
489+
},
490+
{
491+
title: `${
492+
data?.items?.[0]?.token_1?.contract_name || ""
493+
} Decimals`,
494+
value: (
495+
data?.items?.[0]?.token_1?.contract_decimals ?? 18
496+
).toString(),
497+
type: "text",
498+
},
499+
{
500+
title: `${
501+
data?.items?.[0]?.token_1?.contract_name || ""
502+
} Address`,
503+
value: data?.items?.[0]?.token_1?.contract_address || "",
504+
type: "address",
505+
},
506+
],
507+
};
508+
}
509+
);

0 commit comments

Comments
 (0)