Skip to content

Commit

Permalink
fix: make scan interval configurable
Browse files Browse the repository at this point in the history
  • Loading branch information
doomsower committed Apr 14, 2024
1 parent af88e3d commit 40cc406
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 8 deletions.
10 changes: 9 additions & 1 deletion src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
1 change: 1 addition & 0 deletions src/services/liquidate/AbstractLiquidatorService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ export default abstract class AbstractLiquidatorService
public async launch(provider: providers.Provider): Promise<void> {
this.provider = provider;
this.slippage = Math.floor(config.slippage * 100);
this.log.debug(`slippage: ${this.slippage}`);

switch (this.addressProvider.network) {
case "Mainnet":
Expand Down
15 changes: 8 additions & 7 deletions src/services/scan/AbstractScanService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<void>;
Expand Down

0 comments on commit 40cc406

Please sign in to comment.