|
| 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 | +); |
0 commit comments