From 40cc406dab7c17ce7d0d177d6414bbb913e9479c Mon Sep 17 00:00:00 2001 From: doomsower <12031673+doomsower@users.noreply.github.com> Date: Sun, 14 Apr 2024 10:42:53 -0400 Subject: [PATCH] fix: make scan interval configurable --- src/config.ts | 10 +++++++++- .../liquidate/AbstractLiquidatorService.ts | 1 + src/services/scan/AbstractScanService.ts | 15 ++++++++------- 3 files changed, 18 insertions(+), 8 deletions(-) diff --git a/src/config.ts b/src/config.ts index 4c5d6b4..bc8b8cd 100644 --- a/src/config.ts +++ b/src/config.ts @@ -81,6 +81,13 @@ export class Config { @Min(0) static skipBlocks: number; + /** + * If 0, every block will be scanned + */ + @IsNotEmpty() + @Min(0) + static scanInterval: number; + @IsNotEmpty() @Min(1) static executorsQty: number; @@ -163,11 +170,12 @@ export class Config { ? parseInt(process.env.JSON_RPC_TIMEOUT, 10) : undefined; Config.privateKey = process.env.PRIVATE_KEY || ""; - Config.slippage = parseFloat(process.env.SLIPPAGE || "0"); + Config.slippage = parseFloat(process.env.SLIPPAGE || "0.5"); Config.walletPassword = process.env.WALLET_PASSWORD || ""; Config.hfThreshold = parseInt(process.env.HF_TRESHOLD || "9950", 10); Config.ampqUrl = process.env.CLOUDAMQP_URL; Config.ampqExchange = process.env.AMPQ_EXCHANGE; + Config.scanInterval = parseInt(process.env.SCAN_INTERVAL || "0", 10); Config.skipBlocks = parseInt(process.env.SKIP_BLOCKS || "0", 10); Config.keyPath = process.env.KEY_PATH; Config.keySecret = process.env.KEY_SECRET; diff --git a/src/services/liquidate/AbstractLiquidatorService.ts b/src/services/liquidate/AbstractLiquidatorService.ts index 6f0dcc7..e465af5 100644 --- a/src/services/liquidate/AbstractLiquidatorService.ts +++ b/src/services/liquidate/AbstractLiquidatorService.ts @@ -60,6 +60,7 @@ export default abstract class AbstractLiquidatorService public async launch(provider: providers.Provider): Promise { this.provider = provider; this.slippage = Math.floor(config.slippage * 100); + this.log.debug(`slippage: ${this.slippage}`); switch (this.addressProvider.network) { case "Mainnet": diff --git a/src/services/scan/AbstractScanService.ts b/src/services/scan/AbstractScanService.ts index 5cc8da0..8d10362 100644 --- a/src/services/scan/AbstractScanService.ts +++ b/src/services/scan/AbstractScanService.ts @@ -44,15 +44,16 @@ export default abstract class AbstractScanService { if (config.optimisticLiquidations) { return; } - if (this.addressProvider.network === "Mainnet") { + this.log.debug(`scan interval is ${config.scanInterval}`); + if (config.scanInterval === 0) { this.provider.on("block", async num => await this.onBlock(num)); - return; + } else { + // on L2 blocks are too frequent + setInterval(async () => { + const block = await this.provider.getBlockNumber(); + await this.onBlock(block); + }, config.scanInterval); } - // on L2 blocks are too frequent - setInterval(async () => { - const block = await this.provider.getBlockNumber(); - await this.onBlock(block); - }, 12_000); } protected abstract _launch(provider: providers.Provider): Promise;