@@ -21,6 +21,10 @@ import pino from "pino";
2121import { Logger } from "pino" ;
2222import { HermesClient } from "@pythnetwork/hermes-client" ;
2323import { filterInvalidPriceItems } from "../utils" ;
24+ import { PricePusherMetrics } from "../metrics" ;
25+ import { createSolanaBalanceTracker } from "./balance-tracker" ;
26+ import { IBalanceTracker } from "../interface" ;
27+
2428export default {
2529 command : "solana" ,
2630 describe : "run price pusher for solana" ,
@@ -99,6 +103,8 @@ export default {
99103 ...options . pushingFrequency ,
100104 ...options . logLevel ,
101105 ...options . controllerLogLevel ,
106+ ...options . enableMetrics ,
107+ ...options . metricsPort ,
102108 } ,
103109 handler : async function ( argv : any ) {
104110 const {
@@ -122,6 +128,8 @@ export default {
122128 treasuryId,
123129 logLevel,
124130 controllerLogLevel,
131+ enableMetrics,
132+ metricsPort,
125133 } = argv ;
126134
127135 const logger = pino ( { level : logLevel } ) ;
@@ -130,6 +138,14 @@ export default {
130138
131139 const hermesClient = new HermesClient ( priceServiceEndpoint ) ;
132140
141+ // Initialize metrics if enabled
142+ let metrics : PricePusherMetrics | undefined ;
143+ if ( enableMetrics ) {
144+ metrics = new PricePusherMetrics ( logger . child ( { module : "Metrics" } ) ) ;
145+ metrics . start ( metricsPort ) ;
146+ logger . info ( `Metrics server started on port ${ metricsPort } ` ) ;
147+ }
148+
133149 let priceItems = priceConfigs . map ( ( { id, alias } ) => ( { id, alias } ) ) ;
134150
135151 // Better to filter out invalid price items before creating the pyth listener
@@ -152,11 +168,10 @@ export default {
152168 logger . child ( { module : "PythPriceListener" } ) ,
153169 ) ;
154170
155- const wallet = new NodeWallet (
156- Keypair . fromSecretKey (
157- Uint8Array . from ( JSON . parse ( fs . readFileSync ( keypairFile , "ascii" ) ) ) ,
158- ) ,
171+ const keypair = Keypair . fromSecretKey (
172+ Uint8Array . from ( JSON . parse ( fs . readFileSync ( keypairFile , "ascii" ) ) ) ,
159173 ) ;
174+ const wallet = new NodeWallet ( keypair ) ;
160175
161176 const connection = new Connection ( endpoint , "processed" ) ;
162177 const pythSolanaReceiver = new PythSolanaReceiver ( {
@@ -166,6 +181,21 @@ export default {
166181 treasuryId : treasuryId ,
167182 } ) ;
168183
184+ // Create and start the balance tracker if metrics are enabled
185+ if ( metrics ) {
186+ const balanceTracker : IBalanceTracker = createSolanaBalanceTracker ( {
187+ connection,
188+ publicKey : keypair . publicKey ,
189+ network : "solana" ,
190+ updateInterval : 60 ,
191+ metrics,
192+ logger,
193+ } ) ;
194+
195+ // Start the balance tracker
196+ await balanceTracker . start ( ) ;
197+ }
198+
169199 // Fetch the account lookup table if provided
170200 const lookupTableAccount = addressLookupTableAccount
171201 ? await connection
@@ -220,7 +250,10 @@ export default {
220250 solanaPriceListener ,
221251 solanaPricePusher ,
222252 logger . child ( { module : "Controller" } , { level : controllerLogLevel } ) ,
223- { pushingFrequency } ,
253+ {
254+ pushingFrequency,
255+ metrics,
256+ } ,
224257 ) ;
225258
226259 controller . start ( ) ;
0 commit comments