@@ -4,20 +4,10 @@ import { IPriceListener, IPricePusher } from "./interface";
44import { PriceConfig , shouldUpdate , UpdateCondition } from "./price-config" ;
55import { Logger } from "pino" ;
66import { PricePusherMetrics } from "./metrics" ;
7- import { SuperWalletClient } from "./evm/super-wallet" ;
8-
9- // Define the wallet balance info interface
10- interface WalletBalanceInfo {
11- client : SuperWalletClient ;
12- address : `0x${string } `;
13- network : string ;
14- updateInterval : DurationInSeconds ;
15- }
167
178export class Controller {
189 private pushingFrequency : DurationInSeconds ;
1910 private metrics ?: PricePusherMetrics ;
20- private walletBalanceInfo ?: WalletBalanceInfo ;
2111
2212 constructor (
2313 private priceConfigs : PriceConfig [ ] ,
@@ -28,46 +18,20 @@ export class Controller {
2818 config : {
2919 pushingFrequency : DurationInSeconds ;
3020 metrics ?: PricePusherMetrics ;
31- walletBalanceInfo ?: WalletBalanceInfo ;
3221 } ,
3322 ) {
3423 this . pushingFrequency = config . pushingFrequency ;
3524 this . metrics = config . metrics ;
36- this . walletBalanceInfo = config . walletBalanceInfo ;
3725
3826 // Set the number of price feeds if metrics are enabled
3927 this . metrics ?. setPriceFeedsTotal ( this . priceConfigs . length ) ;
4028 }
4129
42- // Get wallet balance and update metrics
43- private async updateWalletBalance ( ) : Promise < void > {
44- if ( ! this . metrics || ! this . walletBalanceInfo ) return ;
45-
46- try {
47- const { client, address, network } = this . walletBalanceInfo ;
48- const balance = await client . getBalance ( {
49- address : address ,
50- } ) ;
51-
52- this . metrics . updateWalletBalance ( address , network , balance ) ;
53- this . logger . debug (
54- `Updated wallet balance: ${ address } = ${ balance . toString ( ) } ` ,
55- ) ;
56- } catch ( error ) {
57- this . logger . error ( { error } , "Error fetching wallet balance for metrics" ) ;
58- }
59- }
60-
6130 async start ( ) {
6231 // start the listeners
6332 await this . sourcePriceListener . start ( ) ;
6433 await this . targetPriceListener . start ( ) ;
6534
66- // Update wallet balance initially if metrics are enabled
67- if ( this . metrics && this . walletBalanceInfo ) {
68- await this . updateWalletBalance ( ) ;
69- }
70-
7135 // wait for the listeners to get updated. There could be a restart
7236 // before this run and we need to respect the cooldown duration as
7337 // their might be a message sent before.
@@ -80,11 +44,6 @@ export class Controller {
8044 const pricesToPush : PriceConfig [ ] = [ ] ;
8145 const pubTimesToPush : UnixTimestamp [ ] = [ ] ;
8246
83- // Update wallet balance if metrics are enabled
84- if ( this . metrics && this . walletBalanceInfo ) {
85- await this . updateWalletBalance ( ) ;
86- }
87-
8847 for ( const priceConfig of this . priceConfigs ) {
8948 const priceId = priceConfig . id ;
9049 const alias = priceConfig . alias ;
0 commit comments