From 9223305ddfbf28adfc7720a59ab1fb1bcb618339 Mon Sep 17 00:00:00 2001 From: mootz12 Date: Mon, 25 Nov 2024 09:57:15 -0500 Subject: [PATCH] chore: stagger liquidation scan events based on bot startup time --- README.md | 6 +++--- src/collector.ts | 17 +++++++++++++---- 2 files changed, 16 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 5d3e4e8..632791b 100644 --- a/README.md +++ b/README.md @@ -66,8 +66,8 @@ The `fillers` array contains configurations for individual filler accounts. The | `name` | A unique name for this filler account. Used in logs and slack notifications. | | `keypair` | The secret key for this filler account. **Keep this secret and secure!** | | `primaryAsset` | The primary asset the filler will use as collateral in the pool. | -| `defaultProfitPct` | The default profit percentage required for the filler to bid on an auction. | -| `minHealthFactor` | The minimum health factor the filler will take on during liquidation and bad debt auctions. | +| `defaultProfitPct` | The default profit percentage required for the filler to bid on an auction, as a decimal. (e.g. 0.08 = 8%) | +| `minHealthFactor` | The minimum health factor the filler will take on during liquidation and bad debt auctions, as calculated by `collateral / liabilities`. | | `minPrimaryCollateral` | The minimum amount of the primary asset the Filler will maintain as collateral in the pool. | | `forceFill` | Boolean flag to indicate if the bot should force fill auctions even if profit expectations aren't met to ensure pool health. | | `supportedBid` | An array of asset addresses that this filler bot is allowed to bid with. Bids are taken as additional liabilities (dTokens) for liquidation and bad debt auctions, and tokens for interest auctions. Must include the `backstopTokenAddress` to bid on interest auctions. | @@ -97,7 +97,7 @@ Each profit entry has the following fields: | Field | Description | |-------|-------------| -| `profitPct` | The profit percentage required to bid for the auction. | +| `profitPct` | The profit percentage required to bid for the auction, as a decimal. (e.g. 0.08 = 8%) | | `supportedBid` | An array of asset addresses that the auction bid can contain for this `profitPct` to be used. If any auction bid asset exists outside this list, the `profitPct` will not be used. | | `supportedLot` | An array of asset addresses that the auction lot can contain for this `profitPct` to be used. If any auction lot asset exists outside this list, the `profitPct` will not be used. | diff --git a/src/collector.ts b/src/collector.ts index e82d720..02fd654 100644 --- a/src/collector.ts +++ b/src/collector.ts @@ -16,6 +16,8 @@ import { stringify } from './utils/json.js'; import { logger } from './utils/logger.js'; import { sendEvent } from './utils/messages.js'; +let startup_ledger = 0; + export async function runCollector( worker: ChildProcess, bidder: ChildProcess, @@ -40,8 +42,15 @@ export async function runCollector( }; sendEvent(bidder, ledger_event); + // determine ledgers since bot was started to send long running work events + // this staggers the events from different bots running on the same pool + if (startup_ledger === 0) { + startup_ledger = latestLedger; + } + const ledgersProcessed = latestLedger - startup_ledger; + // send long running work events to worker - if (latestLedger % 10 === 0) { + if (ledgersProcessed % 10 === 0) { // approx every minute const event: PriceUpdateEvent = { type: EventType.PRICE_UPDATE, @@ -49,7 +58,7 @@ export async function runCollector( }; sendEvent(worker, event); } - if (latestLedger % 60 === 0) { + if (ledgersProcessed % 60 === 0) { // approx every 5m // send an oracle scan event const event: OracleScanEvent = { @@ -58,7 +67,7 @@ export async function runCollector( }; sendEvent(worker, event); } - if (latestLedger % 1203 === 0) { + if (ledgersProcessed % 1203 === 0) { // approx every 2hr // send a user update event to update any users that have not been updated in ~2 weeks const event: UserRefreshEvent = { @@ -68,7 +77,7 @@ export async function runCollector( }; sendEvent(worker, event); } - if (latestLedger % 1207 === 0) { + if (ledgersProcessed % 1207 === 0) { // approx every 2hr // send a liq scan event const event: LiqScanEvent = {