Skip to content

Commit b47e3e3

Browse files
committed
fix: improve notifications
1 parent 8146520 commit b47e3e3

File tree

3 files changed

+84
-24
lines changed

3 files changed

+84
-24
lines changed

src/services/Scanner.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ import { DI } from "../di.js";
2323
import { type ILogger, Logger } from "../log/index.js";
2424
import type Client from "./Client.js";
2525
import type { ILiquidatorService } from "./liquidate/index.js";
26-
import type { INotifier } from "./notifier/index.js";
26+
import { type INotifier, ZeroHFAccountsMessage } from "./notifier/index.js";
2727

2828
const RESTAKING_CMS: Partial<Record<NetworkType, Address>> = {
2929
Mainnet:
@@ -406,10 +406,7 @@ export class Scanner {
406406
}
407407
this.#lastZeroHFNotification = now;
408408
this.log.debug("notifying on zero HF accounts");
409-
this.notifier.alert({
410-
plain: `found ${count} accounts with HF=0, bad tokens: ${badTokens}`,
411-
markdown: `found ${count} accounts with HF=0, bad tokens: ${badTokens}`,
412-
});
409+
this.notifier.alert(new ZeroHFAccountsMessage(count, badTokens));
413410
}
414411

415412
public get lastUpdated(): bigint {

src/services/notifier/messages.ts

Lines changed: 75 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { etherscanUrl, formatBN } from "@gearbox-protocol/sdk";
33
import type { OptimisticResult } from "@gearbox-protocol/types/optimist";
44
import type { Markdown } from "@vlad-yakovlev/telegram-md";
55
import { md } from "@vlad-yakovlev/telegram-md";
6-
import type { Address, TransactionReceipt } from "viem";
6+
import type { Address, BaseError, TransactionReceipt } from "viem";
77

88
import type { Config } from "../../config/index.js";
99
import { DI } from "../../di.js";
@@ -320,6 +320,80 @@ Error: ${md.inlineCode(this.#error)}`,
320320
}
321321
}
322322

323+
export class ProviderRotationSuccessMessage
324+
extends BaseMessage
325+
implements INotifierMessage
326+
{
327+
#oldT: string;
328+
#newT: string;
329+
#reason: string;
330+
331+
constructor(oldT: string, newT: string, reason?: BaseError) {
332+
super({});
333+
this.#oldT = oldT;
334+
this.#newT = newT;
335+
this.#reason = reason ? `: ${reason.shortMessage} ${reason.details}` : "";
336+
}
337+
338+
public get plain(): string {
339+
return `[${this.network}] rotated rpc provider from ${this.#oldT} to ${this.#newT}${this.#reason}`;
340+
}
341+
342+
public get markdown(): string {
343+
return md.build(
344+
md`[${this.network}] rotated rpc provider from ${md.bold(this.#oldT)} to ${md.bold(this.#newT)}${this.#reason}`,
345+
);
346+
}
347+
}
348+
349+
export class ProviderRotationErrorMessage
350+
extends BaseMessage
351+
implements INotifierMessage
352+
{
353+
#oldT: string;
354+
#reason: string;
355+
356+
constructor(oldT: string, reason?: BaseError) {
357+
super({});
358+
this.#oldT = oldT;
359+
this.#reason = reason ? `: ${reason.shortMessage} ${reason.details}` : "";
360+
}
361+
362+
public get plain(): string {
363+
return `[${this.network}] failed to rotate rpc provider from ${this.#oldT}${this.#reason}`;
364+
}
365+
366+
public get markdown(): string {
367+
return md.build(
368+
md`[${this.network}] failed to rotate rpc provider from ${md.bold(this.#oldT)}${this.#reason}`,
369+
);
370+
}
371+
}
372+
373+
export class ZeroHFAccountsMessage
374+
extends BaseMessage
375+
implements INotifierMessage
376+
{
377+
#count: number;
378+
#badTokens: string;
379+
380+
constructor(count: number, badTokens: string) {
381+
super({});
382+
this.#count = count;
383+
this.#badTokens = badTokens;
384+
}
385+
386+
public get plain(): string {
387+
return `[${this.network}] found ${this.#count} accounts with HF=0, bad tokens: ${this.#badTokens}`;
388+
}
389+
390+
public get markdown(): string {
391+
return md.build(
392+
md`[${this.network}] found ${this.#count} accounts with HF=0, bad tokens: ${this.#badTokens}`,
393+
);
394+
}
395+
}
396+
323397
function callsPlain(calls?: string[]): string {
324398
return calls ? calls.map(c => ` ➤ ${c}`).join("\n") : "-";
325399
}

src/utils/createTransport.ts

Lines changed: 7 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,13 @@ import {
33
type ProviderConfig,
44
RevolverTransport,
55
} from "@gearbox-protocol/sdk/dev";
6-
import { md } from "@vlad-yakovlev/telegram-md";
76
import type { Transport } from "viem";
87
import type { CommonSchema } from "../config/common.js";
9-
import type { INotifier } from "../services/notifier/index.js";
8+
import {
9+
type INotifier,
10+
ProviderRotationErrorMessage,
11+
ProviderRotationSuccessMessage,
12+
} from "../services/notifier/index.js";
1013

1114
export function createTransport(
1215
config: CommonSchema,
@@ -75,24 +78,10 @@ export function createTransport(
7578
retryCount: config.optimistic ? 3 : undefined,
7679
logger: logger?.child?.({ name: "transport" }),
7780
onRotateSuccess: (oldT, newT, reason) => {
78-
const reasonS = reason
79-
? `: ${reason.shortMessage} ${reason.details}`
80-
: "";
81-
notifier.alert({
82-
plain: `Rotated rpc provider from ${oldT} to ${newT}${reasonS}`,
83-
markdown:
84-
md`Rotated rpc provider from ${md.bold(oldT)} to ${md.bold(newT)}${reasonS}`.toString(),
85-
});
81+
notifier.notify(new ProviderRotationSuccessMessage(oldT, newT, reason));
8682
},
8783
onRotateFailed: (oldT, reason) => {
88-
const reasonS = reason
89-
? `: ${reason.shortMessage} ${reason.details}`
90-
: "";
91-
notifier.alert({
92-
plain: `Failed to rotate rpc provider from ${oldT}${reasonS}`,
93-
markdown:
94-
md`Failed to rotate rpc provider from ${md.bold(oldT)}${reasonS}`.toString(),
95-
});
84+
notifier.alert(new ProviderRotationErrorMessage(oldT, reason));
9685
},
9786
});
9887
}

0 commit comments

Comments
 (0)