Skip to content

Commit 94965f8

Browse files
jagnani73gane5h
andauthored
fix(decoders): details type + token pretty quote (#9)
Co-authored-by: Ganesh Swami <[email protected]>
1 parent 9c8247a commit 94965f8

File tree

10 files changed

+112
-21
lines changed

10 files changed

+112
-21
lines changed

README.md

+2
Original file line numberDiff line numberDiff line change
@@ -137,3 +137,5 @@ Follow the following steps to add a Decoding logic for an event from a contract
137137
}[];
138138
}
139139
```
140+
141+

services/decoder/decoder.types.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ export type Configs = {
1818
export type EventDetails = {
1919
title: string;
2020
value: string;
21+
type: "address" | "text";
2122
}[];
2223

2324
export type EventNFTs = {
@@ -39,7 +40,7 @@ export type EventTokens = {
3940
decimals: number;
4041
ticker_symbol: string | null;
4142
ticker_logo: string | null;
42-
pretty: string;
43+
pretty_quote: string;
4344
}[];
4445

4546
export interface EventType {

services/decoder/protocols/4337-entry-point/4337-entry-point.decoders.ts

+5
Original file line numberDiff line numberDiff line change
@@ -47,25 +47,30 @@ Decoder.on(
4747
decoded.actualGasCost /
4848
BigInt(Math.pow(10, sender_contract_decimals))
4949
).toString(),
50+
type: "text",
5051
},
5152
{
5253
title: "Gas Used",
5354
value: (
5455
decoded.actualGasUsed /
5556
BigInt(Math.pow(10, sender_contract_decimals))
5657
).toString(),
58+
type: "text",
5759
},
5860
{
5961
title: "Paymaster",
6062
value: decoded.paymaster,
63+
type: "address",
6164
},
6265
{
6366
title: "Sender",
6467
value: decoded.sender,
68+
type: "address",
6569
},
6670
{
6771
title: "User Operation Hash",
6872
value: decoded.userOpHash,
73+
type: "text",
6974
},
7075
],
7176
};

services/decoder/protocols/covalent-network/covalent-network.decoders.ts

+3
Original file line numberDiff line numberDiff line change
@@ -43,16 +43,19 @@ Decoder.on(
4343
{
4444
title: "Specimen Hash",
4545
value: decoded.specimenHash,
46+
type: "text",
4647
},
4748
{
4849
title: "Storage URL",
4950
value: decoded.storageURL,
51+
type: "text",
5052
},
5153
{
5254
title: "Submitted Stake",
5355
value: (
5456
decoded.submittedStake / BigInt(Math.pow(10, 18))
5557
).toString(),
58+
type: "text",
5659
},
5760
],
5861
};

services/decoder/protocols/grindery-one/grindery-one.decoders.ts

+3
Original file line numberDiff line numberDiff line change
@@ -40,17 +40,20 @@ Decoder.on(
4040
{
4141
title: "From",
4242
value: decoded.from,
43+
type: "address",
4344
},
4445
{
4546
title: "To",
4647
value: decoded.to,
48+
type: "address",
4749
},
4850
{
4951
title: "Value",
5052
value: (
5153
decoded.value /
5254
BigInt(Math.pow(10, sender_contract_decimals))
5355
).toString(),
56+
type: "text",
5457
},
5558
],
5659
};

services/decoder/protocols/opensea/opensea.configs.ts

+6
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,12 @@ const configs: Configs = [
77
is_factory: false,
88
network: "eth-mainnet",
99
},
10+
{
11+
protocol_name: "opensea",
12+
address: "0x00000000006c3852cbef3e08e8df289169ede581",
13+
is_factory: false,
14+
network: "matic-mainnet",
15+
},
1016
];
1117

1218
export default configs;

services/decoder/protocols/opensea/opensea.decoders.ts

+15-3
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,11 @@ import {
1212
import { decodeEventLog, type Abi } from "viem";
1313
import Seaport from "./abis/seaport-1.1.abi.json";
1414
import { TimestampParser } from "../../../../utils/functions";
15+
import { prettifyCurrency } from "@covalenthq/client-sdk";
1516

1617
Decoder.on(
1718
"opensea:OrderFulfilled",
18-
["eth-mainnet"],
19+
["eth-mainnet", "matic-mainnet"],
1920
Seaport as Abi,
2021
async (log, chain_name, covalent_client): Promise<EventType> => {
2122
const { block_signed_at, raw_log_data, raw_log_topics } = log;
@@ -63,14 +64,17 @@ Decoder.on(
6364
{
6465
title: "Offerer",
6566
value: decoded.offerer,
67+
type: "address",
6668
},
6769
{
6870
title: "Recipient",
6971
value: decoded.recipient,
72+
type: "address",
7073
},
7174
{
7275
title: "Order Hash",
7376
value: decoded.orderHash,
77+
type: "address",
7478
},
7579
];
7680

@@ -103,7 +107,15 @@ Decoder.on(
103107
decimals:
104108
data?.[0]?.items?.[0]?.contract_metadata
105109
?.contract_decimals ?? 18,
106-
pretty: data?.[0]?.items?.[0]?.pretty_price,
110+
pretty_quote: prettifyCurrency(
111+
data?.[0]?.items?.[0]?.price *
112+
(Number(amount) /
113+
Math.pow(
114+
10,
115+
data?.[0]?.items?.[0]?.contract_metadata
116+
?.contract_decimals ?? 18
117+
))
118+
),
107119
ticker_symbol:
108120
data?.[0]?.items?.[0]?.contract_metadata
109121
?.contract_ticker_symbol,
@@ -172,7 +184,7 @@ Decoder.on(
172184
name: "Basic Order Fulfilled",
173185
protocol: {
174186
logo: log.sender_logo_url as string,
175-
name: log.sender_name as string,
187+
name: "Opensea",
176188
},
177189
details: details,
178190
nfts: nfts,

services/decoder/protocols/opensea/opensea.test.ts

+27
Original file line numberDiff line numberDiff line change
@@ -29,4 +29,31 @@ describe("opensea", () => {
2929
}
3030
expect(event.details?.length).toEqual(3);
3131
});
32+
33+
test("matic-mainnet:OrderFulfilled", async () => {
34+
const res = await request(app)
35+
.post("/api/v1/tx/decode")
36+
.set({
37+
"x-covalent-api-key": process.env.TEST_COVALENT_API_KEY,
38+
})
39+
.send({
40+
network: "matic-mainnet",
41+
tx_hash:
42+
"0xbb0849b132f97174bd1f0c41ef39b4105ddb0e07b8f6730910d56d48dfffa0e8",
43+
});
44+
const { events } = res.body as { events: EventType[] };
45+
const event = events.find(
46+
({ name }) => name === "Basic Order Fulfilled"
47+
);
48+
if (!event) {
49+
throw Error("Event not found");
50+
}
51+
if (event.nfts) {
52+
expect(event.nfts?.length).toBeGreaterThan(0);
53+
}
54+
if (event.tokens) {
55+
expect(event.tokens?.length).toBeGreaterThan(0);
56+
}
57+
expect(event.details?.length).toEqual(3);
58+
});
3259
});

services/decoder/protocols/paraswap-v5/paraswap-v5.decoders.ts

+20-8
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,10 @@ import {
1010
} from "../../decoder.constants";
1111
import { decodeEventLog, type Abi } from "viem";
1212
import SimpleSwapABI from "./abis/paraswap-v5.simple-swap.abi.json";
13-
import { calculatePrettyBalance } from "@covalenthq/client-sdk";
13+
import {
14+
calculatePrettyBalance,
15+
prettifyCurrency,
16+
} from "@covalenthq/client-sdk";
1417

1518
Decoder.on(
1619
"paraswap-v5:SwappedV3",
@@ -54,31 +57,36 @@ Decoder.on(
5457
{
5558
title: "UUID",
5659
value: decoded.uuid,
60+
type: "text",
5761
},
5862
{
5963
title: "Beneficiary",
6064
value: decoded.beneficiary,
65+
type: "address",
6166
},
6267
{
6368
title: "Initiator",
6469
value: decoded.initiator,
70+
type: "address",
6571
},
6672
{
6773
title: "Expected Amount",
6874
value: calculatePrettyBalance(
6975
decoded.expectedAmount,
7076
destToken?.[0]?.contract_decimals ?? 0
7177
),
78+
type: "text",
7279
},
7380
];
7481

7582
const tokens: EventTokens = [
7683
{
7784
decimals: srcToken?.[0]?.contract_decimals ?? 0,
7885
heading: "Input",
79-
pretty: calculatePrettyBalance(
80-
decoded.srcAmount,
81-
srcToken?.[0]?.contract_decimals ?? 0
86+
pretty_quote: prettifyCurrency(
87+
srcToken?.[0]?.prices?.[0].price *
88+
(Number(decoded.srcAmount) /
89+
Math.pow(10, srcToken?.[0]?.contract_decimals ?? 0))
8290
),
8391
ticker_logo: srcToken?.[0]?.logo_url ?? null,
8492
ticker_symbol: srcToken?.[0]?.contract_ticker_symbol ?? null,
@@ -87,9 +95,13 @@ Decoder.on(
8795
{
8896
decimals: destToken?.[0]?.contract_decimals ?? 0,
8997
heading: "Output",
90-
pretty: calculatePrettyBalance(
91-
decoded.receivedAmount,
92-
destToken?.[0]?.contract_decimals ?? 0
98+
pretty_quote: prettifyCurrency(
99+
destToken?.[0]?.prices?.[0].price *
100+
(Number(decoded.receivedAmount) /
101+
Math.pow(
102+
10,
103+
destToken?.[0]?.contract_decimals ?? 0
104+
))
93105
),
94106
ticker_logo: destToken?.[0]?.logo_url ?? null,
95107
ticker_symbol: destToken?.[0]?.contract_ticker_symbol ?? null,
@@ -103,7 +115,7 @@ Decoder.on(
103115
name: "Swap V3",
104116
protocol: {
105117
logo: log.sender_logo_url as string,
106-
name: log.sender_name as string,
118+
name: "Paraswap V5",
107119
},
108120
details: details,
109121
tokens: tokens,

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

+29-9
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { calculatePrettyBalance, type Token } from "@covalenthq/client-sdk";
1+
import { prettifyCurrency, type Token } from "@covalenthq/client-sdk";
22
import { type Abi, decodeEventLog } from "viem";
33
import { Decoder } from "../../decoder";
44
import { TimestampParser } from "../../../../utils/functions";
@@ -113,15 +113,25 @@ Decoder.on(
113113
ticker_symbol: inputToken?.contract_ticker_symbol ?? null,
114114
value: inputValue.toString(),
115115
decimals: inputDecimals,
116-
pretty: calculatePrettyBalance(inputValue, inputDecimals),
116+
pretty_quote: prettifyCurrency(
117+
inputToken?.quote_rate ??
118+
0 *
119+
(Number(inputValue) /
120+
Math.pow(10, inputDecimals))
121+
),
117122
heading: "Input",
118123
},
119124
{
120125
ticker_logo: outputToken?.logo_url ?? null,
121126
ticker_symbol: outputToken?.contract_ticker_symbol ?? null,
122127
value: outputValue.toString(),
123128
decimals: outputDecimals,
124-
pretty: calculatePrettyBalance(outputValue, outputDecimals),
129+
pretty_quote: prettifyCurrency(
130+
outputToken?.quote_rate ??
131+
0 *
132+
(Number(outputValue) /
133+
Math.pow(10, outputDecimals))
134+
),
125135
heading: "Output",
126136
},
127137
],
@@ -188,9 +198,14 @@ Decoder.on(
188198
ticker_symbol: token0?.contract_ticker_symbol ?? null,
189199
value: value0.toString(),
190200
decimals: +(token0?.contract_decimals ?? 18),
191-
pretty: calculatePrettyBalance(
192-
value0,
193-
+(token0?.contract_decimals ?? 18)
201+
pretty_quote: prettifyCurrency(
202+
token0?.quote_rate ??
203+
0 *
204+
(Number(value0) /
205+
Math.pow(
206+
10,
207+
+(token0?.contract_decimals ?? 18)
208+
))
194209
),
195210
heading: "Input",
196211
},
@@ -199,9 +214,14 @@ Decoder.on(
199214
ticker_symbol: token1?.contract_ticker_symbol ?? null,
200215
value: value1.toString(),
201216
decimals: +(token1?.contract_decimals ?? 18),
202-
pretty: calculatePrettyBalance(
203-
value1,
204-
+(token1?.contract_decimals ?? 18)
217+
pretty_quote: prettifyCurrency(
218+
token1?.quote_rate ??
219+
0 *
220+
(Number(value1) /
221+
Math.pow(
222+
10,
223+
+(token1?.contract_decimals ?? 18)
224+
))
205225
),
206226
heading: "Output",
207227
},

0 commit comments

Comments
 (0)