@@ -19,7 +19,7 @@ import {
1919 iCreditManagerV3Abi ,
2020 iPartialLiquidationBotV3Abi ,
2121} from "@gearbox-protocol/types/abi" ;
22- import type { Address , Block , PublicClient } from "viem" ;
22+ import type { Address , Block , HttpTransportConfig , PublicClient } from "viem" ;
2323import { createPublicClient , getContract , http } from "viem" ;
2424import type { Config } from "../config/index.js" ;
2525import { DI } from "../di.js" ;
@@ -53,9 +53,6 @@ export class Scanner {
5353 @DI . Inject ( DI . CreditAccountService )
5454 caService ! : ICreditAccountsService ;
5555
56- @DI . Inject ( DI . MulticallSpy )
57- multicallSpy ! : MulticallSpy ;
58-
5956 #processing: bigint | null = null ;
6057 #restakingCMAddr?: Address ;
6158 #restakingMinHF?: bigint ;
@@ -387,6 +384,9 @@ class ScannerDiagnoster {
387384 @DI . Inject ( DI . Notifier )
388385 notifier ! : INotifier ;
389386
387+ @DI . Inject ( DI . MulticallSpy )
388+ multicallSpy ! : MulticallSpy ;
389+
390390 #drpc?: WorkaroundCAS ;
391391 #alchemy?: WorkaroundCAS ;
392392
@@ -398,7 +398,17 @@ class ScannerDiagnoster {
398398 "http" ,
399399 ) ;
400400 if ( rpcURL ) {
401- this . #drpc = new WorkaroundCAS ( this . caService . sdk , { rpcURL } ) ;
401+ this . #drpc = new WorkaroundCAS ( this . caService . sdk , {
402+ rpcURL,
403+ rpcOptions : {
404+ onFetchRequest : this . config . debugScanner
405+ ? ( r , o ) => this . multicallSpy . multicallRequestSpy ( r , o )
406+ : undefined ,
407+ onFetchResponse : this . config . debugScanner
408+ ? r => this . multicallSpy . multicallResponseSpy ( r )
409+ : undefined ,
410+ } ,
411+ } ) ;
402412 }
403413 }
404414 if ( this . config . alchemyKeys ?. length ) {
@@ -408,7 +418,17 @@ class ScannerDiagnoster {
408418 "http" ,
409419 ) ;
410420 if ( rpcURL ) {
411- this . #alchemy = new WorkaroundCAS ( this . caService . sdk , { rpcURL } ) ;
421+ this . #alchemy = new WorkaroundCAS ( this . caService . sdk , {
422+ rpcURL,
423+ rpcOptions : {
424+ onFetchRequest : this . config . debugScanner
425+ ? ( r , o ) => this . multicallSpy . multicallRequestSpy ( r , o )
426+ : undefined ,
427+ onFetchResponse : this . config . debugScanner
428+ ? r => this . multicallSpy . multicallResponseSpy ( r )
429+ : undefined ,
430+ } ,
431+ } ) ;
412432 }
413433 }
414434 if ( ! ! this . #drpc && ! ! this . #alchemy) {
@@ -460,6 +480,7 @@ class ScannerDiagnoster {
460480 plain : `Found ${ numZeroHF } zero HF accounts in block ${ blockNumber } , second pass ${ dprcZeroHF } drpc, ${ alchemyZeroHF } alchemy` ,
461481 markdown : `Found ${ numZeroHF } zero HF accounts in block ${ blockNumber } , second pass ${ dprcZeroHF } drpc, ${ alchemyZeroHF } alchemy` ,
462482 } ) ;
483+ await this . multicallSpy . dumpCalls ( ) ;
463484 return alchemyZeroHF < dprcZeroHF ? alchemyAccs : drpcAccs ;
464485 } catch ( e ) {
465486 this . log . error ( e ) ;
@@ -470,6 +491,7 @@ class ScannerDiagnoster {
470491
471492interface WorkaroundCASOptions extends CreditAccountServiceOptions {
472493 rpcURL : string ;
494+ rpcOptions ?: HttpTransportConfig ;
473495}
474496
475497class WorkaroundCAS extends AbstractCreditAccountService {
@@ -478,7 +500,10 @@ class WorkaroundCAS extends AbstractCreditAccountService {
478500 constructor ( sdk : GearboxSDK , opts : WorkaroundCASOptions ) {
479501 super ( sdk , opts ) ;
480502 this . #client = createPublicClient ( {
481- transport : http ( opts . rpcURL , { timeout : 600_000 } ) ,
503+ transport : http ( opts . rpcURL , {
504+ timeout : 600_000 ,
505+ ...opts . rpcOptions ,
506+ } ) ,
482507 chain : sdk . provider . chain ,
483508 } ) ;
484509 }
0 commit comments