@@ -24,10 +24,8 @@ import { createPublicClient, getContract, http } from "viem";
2424import type { Config } from "../config/index.js" ;
2525import { DI } from "../di.js" ;
2626import { type ILogger , Logger } from "../log/index.js" ;
27- import type MulticallSpy from "../MulticallSpy.js" ;
2827import type Client from "./Client.js" ;
2928import type { ILiquidatorService } from "./liquidate/index.js" ;
30- import type { INotifier } from "./notifier/index.js" ;
3129
3230const RESTAKING_CMS : Partial < Record < NetworkType , Address > > = {
3331 Mainnet :
@@ -60,7 +58,6 @@ export class Scanner {
6058 #maxHealthFactor = MAX_UINT256 ;
6159 #minHealthFactor = 0n ;
6260 #unwatch?: ( ) => void ;
63- #diagnoster?: ScannerDiagnoster ;
6461
6562 public async launch ( ) : Promise < void > {
6663 await this . liquidatorService . launch ( ) ;
@@ -94,10 +91,6 @@ export class Scanner {
9491 }
9592 }
9693
97- if ( this . config . debugScanner ) {
98- this . #diagnoster = new ScannerDiagnoster ( ) ;
99- }
100-
10194 // we should not pin block during optimistic liquidations
10295 // because during optimistic liquidations we need to call evm_mine to make redstone work
10396 await this . #updateAccounts(
@@ -169,13 +162,6 @@ export class Scanner {
169162 ! this . config . updateReservePrices ,
170163 } ;
171164 accounts = await this . caService . getCreditAccounts ( queue , blockNumber ) ;
172- if ( this . #diagnoster) {
173- accounts = await this . #diagnoster. checkAccounts (
174- accounts ,
175- queue ,
176- blockNumber ,
177- ) ;
178- }
179165 }
180166 if ( this . config . restakingWorkaround ) {
181167 const before = accounts . length ;
@@ -373,140 +359,3 @@ export class Scanner {
373359 this . log . info ( "stopped" ) ;
374360 }
375361}
376-
377- class ScannerDiagnoster {
378- @Logger ( "ScannerDiagnoster" )
379- log ! : ILogger ;
380-
381- @DI . Inject ( DI . Config )
382- config ! : Config ;
383-
384- @DI . Inject ( DI . CreditAccountService )
385- caService ! : ICreditAccountsService ;
386-
387- @DI . Inject ( DI . Notifier )
388- notifier ! : INotifier ;
389-
390- @DI . Inject ( DI . MulticallSpy )
391- multicallSpy ! : MulticallSpy ;
392-
393- #drpc?: WorkaroundCAS ;
394- #alchemy?: WorkaroundCAS ;
395-
396- constructor ( ) {
397- if ( this . config . drpcKeys ?. length ) {
398- const rpcURL = getDrpcUrl (
399- this . config . network ,
400- this . config . drpcKeys [ 0 ] . value ,
401- "http" ,
402- ) ;
403- if ( rpcURL ) {
404- this . #drpc = new WorkaroundCAS ( this . caService . sdk , {
405- rpcURL,
406- rpcOptions : {
407- onFetchRequest : this . multicallSpy . onFetchRequest ,
408- onFetchResponse : this . multicallSpy . onFetchResponse ,
409- } ,
410- } ) ;
411- }
412- }
413- if ( this . config . alchemyKeys ?. length ) {
414- const rpcURL = getAlchemyUrl (
415- this . config . network ,
416- this . config . alchemyKeys [ 0 ] . value ,
417- "http" ,
418- ) ;
419- if ( rpcURL ) {
420- this . #alchemy = new WorkaroundCAS ( this . caService . sdk , {
421- rpcURL,
422- rpcOptions : {
423- onFetchRequest : this . multicallSpy . onFetchRequest ,
424- onFetchResponse : this . multicallSpy . onFetchResponse ,
425- } ,
426- } ) ;
427- }
428- }
429- if ( ! ! this . #drpc && ! ! this . #alchemy) {
430- this . log . info ( "scanner diagnoster enabled" ) ;
431- }
432- }
433-
434- public async checkAccounts (
435- accounts : CreditAccountData [ ] ,
436- queue : GetCreditAccountsOptions ,
437- blockNumber ?: bigint ,
438- ) : Promise < CreditAccountData [ ] > {
439- let result = accounts ;
440- try {
441- if ( ! accounts . length || ! blockNumber || this . config . optimistic ) {
442- return result ;
443- }
444- const numZeroHF = accounts . filter ( a => a . healthFactor === 0n ) . length ;
445- let [ success , drpcSuccess , dprcZeroHF , alchemySuccess , alchemyZeroHF ] = [
446- 0 , 0 , 0 , 0 , 0 ,
447- ] ;
448- for ( const a of accounts ) {
449- success += a . success ? 1 : 0 ;
450- }
451- this . log . debug (
452- `found ${ accounts . length } liquidatable accounts (${ success } successful, ${ numZeroHF } zero HF) in block ${ blockNumber } ` ,
453- ) ;
454- if ( numZeroHF === 0 ) {
455- return result ;
456- }
457- if ( ! ! this . #drpc && ! ! this . #alchemy) {
458- const [ drpcAccs , alchemyAccs ] = await Promise . all ( [
459- this . #drpc. getCreditAccounts ( queue , blockNumber ) ,
460- this . #alchemy. getCreditAccounts ( queue , blockNumber ) ,
461- ] ) ;
462- for ( const a of drpcAccs ) {
463- dprcZeroHF += a . healthFactor === 0n ? 1 : 0 ;
464- drpcSuccess += a . success ? 1 : 0 ;
465- }
466- for ( const a of alchemyAccs ) {
467- alchemyZeroHF += a . healthFactor === 0n ? 1 : 0 ;
468- alchemySuccess += a . success ? 1 : 0 ;
469- }
470- this . log . debug (
471- `found ${ drpcAccs . length } liquidatable accounts (${ drpcSuccess } successful, ${ dprcZeroHF } zero HF) in block ${ blockNumber } with drpc` ,
472- ) ;
473- this . log . debug (
474- `found ${ alchemyAccs . length } liquidatable accounts (${ alchemySuccess } successful, ${ alchemyZeroHF } zero HF) in block ${ blockNumber } with alchemy` ,
475- ) ;
476- this . notifier . alert ( {
477- plain : `Found ${ numZeroHF } zero HF accounts in block ${ blockNumber } , second pass ${ dprcZeroHF } drpc, ${ alchemyZeroHF } alchemy` ,
478- markdown : `Found ${ numZeroHF } zero HF accounts in block ${ blockNumber } , second pass ${ dprcZeroHF } drpc, ${ alchemyZeroHF } alchemy` ,
479- } ) ;
480- result = alchemyZeroHF < dprcZeroHF ? alchemyAccs : drpcAccs ;
481- }
482- await this . multicallSpy . dumpCalls ( ) ;
483- } catch ( e ) {
484- this . log . error ( e ) ;
485- }
486- return result ;
487- }
488- }
489-
490- interface WorkaroundCASOptions extends CreditAccountServiceOptions {
491- rpcURL : string ;
492- rpcOptions ?: HttpTransportConfig ;
493- }
494-
495- class WorkaroundCAS extends AbstractCreditAccountService {
496- #client: PublicClient ;
497-
498- constructor ( sdk : GearboxSDK , opts : WorkaroundCASOptions ) {
499- super ( sdk , opts ) ;
500- this . #client = createPublicClient ( {
501- transport : http ( opts . rpcURL , {
502- timeout : 600_000 ,
503- ...opts . rpcOptions ,
504- } ) ,
505- chain : sdk . provider . chain ,
506- } ) ;
507- }
508-
509- public override get client ( ) : PublicClient {
510- return this . #client;
511- }
512- }
0 commit comments