소스 검색

refactor: reorganize balance tracker files and consolidate interfaces into a single location

Daniel Chew 8 달 전
부모
커밋
9210f30a16

+ 4 - 12
apps/price_pusher/src/balance-tracker/index.ts → apps/price_pusher/src/balance-tracker.ts

@@ -1,17 +1,9 @@
-// Export the interfaces
-export * from "./interface";
-
-// Export chain-specific implementations
-export * from "./evm";
-// export * from "./aptos";
-
-// Factory function to create the appropriate balance tracker based on the chain
-import { PricePusherMetrics } from "../metrics";
+import { PricePusherMetrics } from "./metrics";
 import { Logger } from "pino";
-import { DurationInSeconds } from "../utils";
+import { DurationInSeconds } from "./utils";
 import { IBalanceTracker } from "./interface";
-import { EvmBalanceTracker } from "./evm";
-import { SuperWalletClient } from "../evm/super-wallet";
+import { EvmBalanceTracker } from "./evm/balance-tracker";
+import { SuperWalletClient } from "./evm/super-wallet";
 
 /**
  * Parameters for creating an EVM balance tracker

+ 0 - 97
apps/price_pusher/src/balance-tracker/interface.ts

@@ -1,97 +0,0 @@
-import { Logger } from "pino";
-import { PricePusherMetrics } from "../metrics";
-import { DurationInSeconds } from "../utils";
-
-/**
- * Common configuration properties for all balance trackers
- */
-export interface BaseBalanceTrackerConfig {
-  /** Address of the wallet to track */
-  address: string;
-  /** Name/ID of the network/chain */
-  network: string;
-  /** How often to update the balance */
-  updateInterval: DurationInSeconds;
-  /** Metrics instance to report balance updates */
-  metrics: PricePusherMetrics;
-  /** Logger instance */
-  logger: Logger;
-}
-
-/**
- * Interface for all balance trackers to implement
- * Each chain will have its own implementation of this interface
- */
-export interface IBalanceTracker {
-  /**
-   * Start tracking the wallet balance
-   */
-  start(): Promise<void>;
-
-  /**
-   * Stop tracking the wallet balance
-   */
-  stop(): void;
-}
-
-/**
- * Abstract base class that implements common functionality for all balance trackers
- */
-export abstract class BaseBalanceTracker implements IBalanceTracker {
-  protected address: string;
-  protected network: string;
-  protected updateInterval: DurationInSeconds;
-  protected metrics: PricePusherMetrics;
-  protected logger: Logger;
-  protected isRunning: boolean = false;
-
-  constructor(config: BaseBalanceTrackerConfig) {
-    this.address = config.address;
-    this.network = config.network;
-    this.updateInterval = config.updateInterval;
-    this.metrics = config.metrics;
-    this.logger = config.logger;
-  }
-
-  public async start(): Promise<void> {
-    if (this.isRunning) {
-      return;
-    }
-
-    this.isRunning = true;
-
-    // Initial balance update
-    await this.updateBalance();
-
-    // Start the update loop
-    this.startUpdateLoop();
-  }
-
-  private async startUpdateLoop(): Promise<void> {
-    // We're using dynamic import to avoid circular dependencies
-    const { sleep } = await import("../utils");
-
-    // Run in a loop to regularly update the balance
-    for (;;) {
-      // Wait first, since we already did the initial update in start()
-      await sleep(this.updateInterval * 1000);
-
-      // Only continue if we're still running
-      if (!this.isRunning) {
-        break;
-      }
-
-      await this.updateBalance();
-    }
-  }
-
-  /**
-   * Chain-specific balance update implementation
-   * Each chain will implement this method differently
-   */
-  protected abstract updateBalance(): Promise<void>;
-
-  public stop(): void {
-    this.isRunning = false;
-  }
-}

+ 2 - 2
apps/price_pusher/src/balance-tracker/evm.ts → apps/price_pusher/src/evm/balance-tracker.ts

@@ -1,5 +1,5 @@
-import { SuperWalletClient } from "../evm/super-wallet";
-import { BaseBalanceTracker, BaseBalanceTrackerConfig } from "./interface";
+import { SuperWalletClient } from "./super-wallet";
+import { BaseBalanceTracker, BaseBalanceTrackerConfig } from "../interface";
 
 /**
  * EVM-specific configuration for balance tracker

+ 96 - 0
apps/price_pusher/src/interface.ts

@@ -1,5 +1,7 @@
 import { HexString, UnixTimestamp } from "@pythnetwork/hermes-client";
 import { DurationInSeconds } from "./utils";
+import { Logger } from "pino";
+import { PricePusherMetrics } from "./metrics";
 
 export type PriceItem = {
   id: HexString;
@@ -82,3 +84,97 @@ export interface IPricePusher {
     pubTimesToPush: UnixTimestamp[],
   ): Promise<void>;
 }
+
+/**
+ * Common configuration properties for all balance trackers
+ */
+export interface BaseBalanceTrackerConfig {
+  /** Address of the wallet to track */
+  address: string;
+  /** Name/ID of the network/chain */
+  network: string;
+  /** How often to update the balance */
+  updateInterval: DurationInSeconds;
+  /** Metrics instance to report balance updates */
+  metrics: PricePusherMetrics;
+  /** Logger instance */
+  logger: Logger;
+}
+
+/**
+ * Interface for all balance trackers to implement
+ * Each chain will have its own implementation of this interface
+ */
+export interface IBalanceTracker {
+  /**
+   * Start tracking the wallet balance
+   */
+  start(): Promise<void>;
+
+  /**
+   * Stop tracking the wallet balance
+   */
+  stop(): void;
+}
+
+/**
+ * Abstract base class that implements common functionality for all balance trackers
+ */
+export abstract class BaseBalanceTracker implements IBalanceTracker {
+  protected address: string;
+  protected network: string;
+  protected updateInterval: DurationInSeconds;
+  protected metrics: PricePusherMetrics;
+  protected logger: Logger;
+  protected isRunning: boolean = false;
+
+  constructor(config: BaseBalanceTrackerConfig) {
+    this.address = config.address;
+    this.network = config.network;
+    this.updateInterval = config.updateInterval;
+    this.metrics = config.metrics;
+    this.logger = config.logger;
+  }
+
+  public async start(): Promise<void> {
+    if (this.isRunning) {
+      return;
+    }
+
+    this.isRunning = true;
+
+    // Initial balance update
+    await this.updateBalance();
+
+    // Start the update loop
+    this.startUpdateLoop();
+  }
+
+  private async startUpdateLoop(): Promise<void> {
+    // We're using dynamic import to avoid circular dependencies
+    const { sleep } = await import("./utils");
+
+    // Run in a loop to regularly update the balance
+    for (;;) {
+      // Wait first, since we already did the initial update in start()
+      await sleep(this.updateInterval * 1000);
+
+      // Only continue if we're still running
+      if (!this.isRunning) {
+        break;
+      }
+
+      await this.updateBalance();
+    }
+  }
+
+  /**
+   * Chain-specific balance update implementation
+   * Each chain will implement this method differently
+   */
+  protected abstract updateBalance(): Promise<void>;
+
+  public stop(): void {
+    this.isRunning = false;
+  }
+}