11import type { NetworkType } from "@gearbox-protocol/sdk-gov" ;
22import { formatBN , TIMELOCK } from "@gearbox-protocol/sdk-gov" ;
33import { EventEmitter } from "eventemitter3" ;
4- import { type Address , http } from "viem" ;
4+ import type { Address , Hex , Log } from "viem" ;
5+ import { http } from "viem" ;
56
6- import { BaseContract } from "./base" ;
7+ import type { BaseContract } from "./base" ;
78import { Provider } from "./chain" ;
89import {
910 ADDRESS_PROVIDER ,
@@ -22,7 +23,7 @@ import { PriceFeedRegister } from "./market/pricefeeds";
2223import { RouterV3Contract } from "./router" ;
2324import type { SDKEventsMap } from "./SDKEvents" ;
2425import type { GearboxState } from "./state/state" ;
25- import type { ILogger } from "./types" ;
26+ import type { ILogger , MultiCall } from "./types" ;
2627import { AddressMap } from "./utils" ;
2728import { createAnvilClient } from "./utils/viem" ;
2829
@@ -88,8 +89,14 @@ export class GearboxSDK extends EventEmitter<SDKEventsMap> {
8889 public readonly interestRateModels = new AddressMap <
8990 BaseContract < readonly unknown [ ] >
9091 > ( ) ;
91-
92+ /**
93+ * All price feeds known to sdk, without oracle-related data (stalenessPeriod, main/reserve, etc.)
94+ */
9295 public readonly priceFeeds : PriceFeedRegister ;
96+ /**
97+ * All contracts known to sdk
98+ */
99+ public readonly contracts = new AddressMap < BaseContract < any > > ( ) ;
93100
94101 public static async attach ( options : SDKAttachOptions ) : Promise < GearboxSDK > {
95102 const { rpcURL, timeout, logger } = options ;
@@ -174,6 +181,36 @@ export class GearboxSDK extends EventEmitter<SDKEventsMap> {
174181 return this ;
175182 }
176183
184+ public parseLogs ( logs : Array < Log > ) : void {
185+ logs . forEach ( log => {
186+ const contract = this . contracts . get ( log . address ) ;
187+ contract ?. parseLog ( log ) ;
188+ } ) ;
189+ }
190+
191+ /**
192+ * Converts contract call into some human-friendly string
193+ * @param address
194+ * @param calldata
195+ * @returns
196+ */
197+ public parseFunctionData ( address : Address , calldata : Hex ) : string {
198+ const contract = this . contracts . mustGet ( address ) ;
199+ return contract . parseFunctionData ( calldata ) ;
200+ }
201+
202+ /**
203+ * Converts multicalls into some human-friendly strings
204+ * @param address
205+ * @param calldata
206+ * @returns
207+ */
208+ public parseMultiCall ( calls : MultiCall [ ] ) : string [ ] {
209+ return calls . map ( call =>
210+ this . parseFunctionData ( call . target , call . callData ) ,
211+ ) ;
212+ }
213+
177214 public async updateBlock ( ) : Promise < void > {
178215 const block = await this . provider . publicClient . getBlock ( {
179216 blockTag : "latest" ,
@@ -215,7 +252,7 @@ export class GearboxSDK extends EventEmitter<SDKEventsMap> {
215252 toBlock : BigInt ( toBlock ) ,
216253 } ) ;
217254
218- BaseContract . parseLogs ( events ) ;
255+ this . parseLogs ( events ) ;
219256
220257 for ( const pf of this . marketRegister . getPoolFactories ( ) ) {
221258 if ( pf . poolContract . hasOperation ) {
0 commit comments