Skip to content

Commit 0184d0b

Browse files
committed
feat: add address and balance to health status
1 parent 79af46a commit 0184d0b

File tree

5 files changed

+160
-144
lines changed

5 files changed

+160
-144
lines changed

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,13 @@
2020
"pino-pretty": "^13.1.1"
2121
},
2222
"devDependencies": {
23-
"@aws-sdk/client-s3": "^3.862.0",
23+
"@aws-sdk/client-s3": "^3.863.0",
2424
"@biomejs/biome": "^2.1.4",
2525
"@commander-js/extra-typings": "^14.0.0",
2626
"@commitlint/cli": "^19.8.1",
2727
"@commitlint/config-conventional": "^19.8.1",
2828
"@gearbox-protocol/biome-config": "^1.0.0",
29-
"@gearbox-protocol/cli-utils": "^5.41.0",
29+
"@gearbox-protocol/cli-utils": "^5.42.1",
3030
"@gearbox-protocol/liquidator-contracts": "^1.36.0-experimental.41",
3131
"@gearbox-protocol/liquidator-v2-contracts": "^2.4.0",
3232
"@gearbox-protocol/sdk": "8.19.0",

src/log/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import type { IFactory } from "di-at-home";
22
import type { Logger as ILogger } from "pino";
3-
import { pino } from "pino";
3+
import pino from "pino";
44

55
import { DI } from "../di.js";
66

src/services/Client.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,8 @@ export default class Client {
5858

5959
#testClient?: AnvilClient;
6060

61+
#balance?: bigint;
62+
6163
public async launch(): Promise<void> {
6264
const { chainId, network, optimistic, privateKey } = this.config;
6365
const transport = createTransport(this.config, {
@@ -224,6 +226,7 @@ export default class Client {
224226

225227
async #checkBalance(): Promise<void> {
226228
const balance = await this.pub.getBalance({ address: this.address });
229+
this.#balance = balance;
227230
this.logger.debug(`liquidator balance is ${formatEther(balance)}`);
228231
if (balance < this.config.minBalance) {
229232
this.notifier.alert(
@@ -269,6 +272,10 @@ export default class Client {
269272
return this.wallet.account.address;
270273
}
271274

275+
public get balance(): bigint | undefined {
276+
return this.#balance;
277+
}
278+
272279
public get anvilForkBlock(): bigint {
273280
const n = this.#anvilInfo?.forkConfig.forkBlockNumber;
274281
if (!n) {

src/services/HealthCheckerService.ts

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,16 @@
11
import { createServer } from "node:http";
2-
import type { GearboxSDK, ICreditAccountsService } from "@gearbox-protocol/sdk";
2+
import {
3+
type GearboxSDK,
4+
type ICreditAccountsService,
5+
json_stringify,
6+
} from "@gearbox-protocol/sdk";
37
import { customAlphabet } from "nanoid";
48
import type { Config } from "../config/index.js";
59
import { DI } from "../di.js";
610
import type { ILogger } from "../log/index.js";
711
import { Logger } from "../log/index.js";
812
import version from "../version.js";
13+
import type Client from "./Client.js";
914
import type { Scanner } from "./Scanner.js";
1015

1116
const nanoid = customAlphabet("1234567890abcdef", 8);
@@ -24,6 +29,9 @@ export default class HealthCheckerService {
2429
@DI.Inject(DI.CreditAccountService)
2530
caService!: ICreditAccountsService;
2631

32+
@DI.Inject(DI.Client)
33+
client!: Client;
34+
2735
#start = Math.round(Date.now() / 1000);
2836
#id = nanoid();
2937

@@ -40,14 +48,15 @@ export default class HealthCheckerService {
4048
if (req.url === "/") {
4149
res.writeHead(200, { "Content-Type": "application/json" });
4250
res.end(
43-
JSON.stringify({
51+
json_stringify({
4452
startTime: this.#start,
4553
version,
4654
network: this.config.network,
4755
family: "liquidators",
4856
liquidationMode: this.config.liquidationMode,
49-
50-
currentBlock: Number(this.sdk.currentBlock),
57+
address: this.client.address,
58+
balance: this.client.balance,
59+
currentBlock: this.sdk.currentBlock,
5160
timestamp: Number(this.sdk.timestamp),
5261
marketsConfigurators:
5362
this.sdk.marketRegister.marketConfigurators.map(mc => mc.address),

0 commit comments

Comments
 (0)