Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit d1a195c

Browse files
committedFeb 22, 2024·
lido updates
1 parent 40f4cea commit d1a195c

File tree

5 files changed

+1827
-0
lines changed

5 files changed

+1827
-0
lines changed
 

‎services/decoder/decoder.constants.ts

+1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ export enum DECODED_EVENT_CATEGORY {
1010
BRIDGE = "Bridge",
1111
GAMING = "Gaming",
1212
SOCIAL = "Social",
13+
STAKING = "Staking",
1314
OTHERS = "Others",
1415
}
1516

‎services/decoder/protocols/lido/abis/lido.steth.abi.json

+1,600
Large diffs are not rendered by default.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import { type Configs } from "../../decoder.types";
2+
3+
const configs: Configs = [
4+
{
5+
address: "0xae7ab96520de3a18e5e111b5eaab095312d7fe84",
6+
is_factory: false,
7+
protocol_name: "lido",
8+
chain_name: "eth-mainnet",
9+
},
10+
];
11+
12+
export default configs;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,192 @@
1+
import { GoldRushDecoder } from "../../decoder";
2+
import type { EventDetails, EventTokens } from "../../decoder.types";
3+
import { type EventType } from "../../decoder.types";
4+
import {
5+
DECODED_ACTION,
6+
DECODED_EVENT_CATEGORY,
7+
} from "../../decoder.constants";
8+
import { decodeEventLog, type Abi } from "viem";
9+
import ABI from "./abis/lido.steth.abi.json";
10+
import { date } from "yup";
11+
12+
GoldRushDecoder.on(
13+
"lido:TransferShares",
14+
["eth-mainnet"],
15+
ABI as Abi,
16+
async (log_event, tx, chain_name, covalent_client): Promise<EventType> => {
17+
const { raw_log_data, raw_log_topics } = log_event;
18+
19+
const { args: decoded } = decodeEventLog({
20+
abi: ABI,
21+
topics: raw_log_topics as [],
22+
data: raw_log_data as `0x${string}`,
23+
eventName: "TransferShares",
24+
}) as {
25+
eventName: "TransferShares";
26+
args: {
27+
from: string;
28+
to: string;
29+
sharesValue: bigint;
30+
};
31+
};
32+
33+
const details: EventDetails = [
34+
{
35+
heading: "from",
36+
value: decoded.from,
37+
type: "address",
38+
},
39+
{
40+
heading: "to",
41+
value: decoded.to,
42+
type: "address",
43+
},
44+
{
45+
heading: "sharesValue",
46+
value: decoded.sharesValue.toString(),
47+
type: "text",
48+
},
49+
];
50+
51+
return {
52+
action: DECODED_ACTION.TRANSFERRED,
53+
category: DECODED_EVENT_CATEGORY.STAKING,
54+
name: "Transfer Shares",
55+
protocol: {
56+
logo: log_event.sender_logo_url as string,
57+
name: "Lido" as string,
58+
},
59+
details,
60+
};
61+
}
62+
);
63+
64+
GoldRushDecoder.on(
65+
"lido:Submitted",
66+
["eth-mainnet"],
67+
ABI as Abi,
68+
async (log_event, tx, chain_name, covalent_client): Promise<EventType> => {
69+
const { raw_log_data, raw_log_topics } = log_event;
70+
71+
const { args: decoded } = decodeEventLog({
72+
abi: ABI,
73+
topics: raw_log_topics as [],
74+
data: raw_log_data as `0x${string}`,
75+
eventName: "Submitted",
76+
}) as {
77+
eventName: "Submitted";
78+
args: {
79+
sender: string;
80+
amount: bigint;
81+
referral: string;
82+
};
83+
};
84+
85+
const details: EventDetails = [
86+
{
87+
heading: "sender",
88+
value: decoded.sender,
89+
type: "address",
90+
},
91+
{
92+
heading: "to",
93+
value: decoded.amount.toString(),
94+
type: "text",
95+
},
96+
{
97+
heading: "referral",
98+
value: decoded.referral,
99+
type: "address",
100+
},
101+
];
102+
103+
const tokens: EventTokens = [
104+
{
105+
heading: "Tokens Staked",
106+
value: tx.value!.toString(),
107+
decimals: tx.gas_metadata.contract_decimals,
108+
ticker_symbol: tx.gas_metadata.contract_ticker_symbol,
109+
ticker_logo: tx.gas_metadata.logo_url,
110+
pretty_quote: tx.value_quote.toString(),
111+
},
112+
];
113+
114+
return {
115+
action: DECODED_ACTION.TRANSFERRED,
116+
category: DECODED_EVENT_CATEGORY.STAKING,
117+
name: "Submitted",
118+
protocol: {
119+
logo: log_event.sender_logo_url as string,
120+
name: "Lido" as string,
121+
},
122+
details,
123+
tokens,
124+
};
125+
}
126+
);
127+
128+
GoldRushDecoder.on(
129+
"lido:TokenRebased",
130+
["eth-mainnet"],
131+
ABI as Abi,
132+
async (log_event, tx, chain_name, covalent_client): Promise<EventType> => {
133+
const { raw_log_data, raw_log_topics } = log_event;
134+
135+
const { args: decoded } = decodeEventLog({
136+
abi: ABI,
137+
topics: raw_log_topics as [],
138+
data: raw_log_data as `0x${string}`,
139+
eventName: "TokenRebased",
140+
}) as {
141+
eventName: "TokenRebased";
142+
args: {
143+
reportTimestamp: bigint;
144+
timeElapsed: bigint;
145+
preTotalShares: bigint;
146+
preTotalEther: bigint;
147+
postTotalShares: bigint;
148+
};
149+
};
150+
151+
const details: EventDetails = [
152+
{
153+
heading: "sender",
154+
value: decoded.sender,
155+
type: "address",
156+
},
157+
{
158+
heading: "to",
159+
value: decoded.amount.toString(),
160+
type: "text",
161+
},
162+
{
163+
heading: "referral",
164+
value: decoded.referral,
165+
type: "address",
166+
},
167+
];
168+
169+
const tokens: EventTokens = [
170+
{
171+
heading: "Tokens Staked",
172+
value: tx.value!.toString(),
173+
decimals: tx.gas_metadata.contract_decimals,
174+
ticker_symbol: tx.gas_metadata.contract_ticker_symbol,
175+
ticker_logo: tx.gas_metadata.logo_url,
176+
pretty_quote: tx.value_quote.toString(),
177+
},
178+
];
179+
180+
return {
181+
action: DECODED_ACTION.TRANSFERRED,
182+
category: DECODED_EVENT_CATEGORY.STAKING,
183+
name: "Submitted",
184+
protocol: {
185+
logo: log_event.sender_logo_url as string,
186+
name: "Lido" as string,
187+
},
188+
details,
189+
tokens,
190+
};
191+
}
192+
);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import request from "supertest";
2+
import app from "../../../../api";
3+
import { type EventType } from "../../decoder.types";
4+
5+
describe("lido", () => {
6+
test("eth-mainnet:TransferShares", async () => {
7+
const res = await request(app)
8+
.post("/api/v1/tx/decode")
9+
.set({ "x-covalent-api-key": process.env.TEST_COVALENT_API_KEY })
10+
.send({
11+
chain_name: "eth-mainnet",
12+
tx_hash:
13+
"0xe9c8e3d7629f0305d75f6bd3171cde37baa8f4d38b1c1f1bb5e158420e4bb144",
14+
});
15+
const { events } = res.body as { events: EventType[] };
16+
const event = events.find(({ name }) => name === "Transfer Shares");
17+
if (!event) {
18+
throw Error("Event not found");
19+
}
20+
expect(event.details?.length).toEqual(3);
21+
});
22+
});

0 commit comments

Comments
 (0)