Skip to content

Commit

Permalink
chore: stagger liquidation scan events based on bot startup time
Browse files Browse the repository at this point in the history
  • Loading branch information
mootz12 committed Nov 25, 2024
1 parent 88a6266 commit 9223305
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 7 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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. |
Expand Down Expand Up @@ -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. |

Expand Down
17 changes: 13 additions & 4 deletions src/collector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -40,16 +42,23 @@ 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,
timestamp: Date.now(),
};
sendEvent(worker, event);
}
if (latestLedger % 60 === 0) {
if (ledgersProcessed % 60 === 0) {
// approx every 5m
// send an oracle scan event
const event: OracleScanEvent = {
Expand All @@ -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 = {
Expand All @@ -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 = {
Expand Down

0 comments on commit 9223305

Please sign in to comment.