Skip to content

Commit 0a8833e

Browse files
committed
fix: remove multicall spy
1 parent f6e305f commit 0a8833e

File tree

6 files changed

+0
-306
lines changed

6 files changed

+0
-306
lines changed

src/MulticallSpy.ts

Lines changed: 0 additions & 139 deletions
This file was deleted.

src/attachSDK.ts

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,13 @@ import {
1111
import type { Config } from "./config/index.js";
1212
import { DI } from "./di.js";
1313
import type { ILogger } from "./log/index.js";
14-
import type MulticallSpy from "./MulticallSpy.js";
1514
import type Client from "./services/Client.js";
1615
import { createTransport, formatTs } from "./utils/index.js";
1716

1817
export default async function attachSDK(): Promise<ICreditAccountsService> {
1918
const config: Config = DI.get(DI.Config);
2019
const client: Client = DI.get(DI.Client);
2120
const logger: ILogger = DI.create(DI.Logger, "sdk");
22-
const multicallSpy: MulticallSpy = DI.create(DI.MulticallSpy);
23-
DI.set(DI.MulticallSpy, multicallSpy);
2421

2522
await client.launch();
2623
let optimisticTimestamp: number | undefined;
@@ -62,8 +59,6 @@ export default async function attachSDK(): Promise<ICreditAccountsService> {
6259

6360
const transport = createTransport(config, {
6461
timeout: 600_000,
65-
onFetchRequest: multicallSpy.onFetchRequest,
66-
onFetchResponse: multicallSpy.onFetchResponse,
6762
});
6863

6964
const sdk = await GearboxSDK.attach({

src/config/common.ts

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -60,14 +60,6 @@ export const CommonSchema = z.object({
6060
description: "These accounts will not be liquidated",
6161
env: "IGNORE_ACCOUNTS",
6262
}),
63-
/**
64-
* Enables debug workaround to diagnose scanner in prod
65-
*/
66-
debugScanner: boolLike().optional().register(zommandRegistry, {
67-
flags: "--debug-scanner",
68-
description: "Enables debug workaround to diagnose scanner in prod",
69-
env: "DEBUG_SCANNER",
70-
}),
7163
/**
7264
* Only check this account during local debug session
7365
*/

src/di.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ const Injectables = {
1313
Scanner: "Scanner",
1414
Swapper: "Swapper",
1515
CreditAccountService: "CreditAccountService",
16-
MulticallSpy: "MulticallSpy",
1716
} as const;
1817

1918
export const DI = Object.assign(
@@ -33,7 +32,6 @@ export const DI = Object.assign(
3332
Scanner: [];
3433
Swapper: [];
3534
CreditAccountService: [];
36-
MulticallSpy: [];
3735
}>(),
3836
Injectables,
3937
);

src/index.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import "./services/liquidate/index.js";
66
import "./services/output/index.js";
77
import "./services/notifier/index.js";
88
import "./services/swap/index.js";
9-
import "./MulticallSpy.js";
109

1110
import { setTimeout } from "node:timers/promises";
1211

src/services/Scanner.ts

Lines changed: 0 additions & 151 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,8 @@ import { createPublicClient, getContract, http } from "viem";
2424
import type { Config } from "../config/index.js";
2525
import { DI } from "../di.js";
2626
import { type ILogger, Logger } from "../log/index.js";
27-
import type MulticallSpy from "../MulticallSpy.js";
2827
import type Client from "./Client.js";
2928
import type { ILiquidatorService } from "./liquidate/index.js";
30-
import type { INotifier } from "./notifier/index.js";
3129

3230
const 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

Comments
 (0)