@@ -9,6 +9,9 @@ import { SuiPriceListener, SuiPricePusher } from "./sui";
9
9
import { Ed25519Keypair } from "@mysten/sui/keypairs/ed25519" ;
10
10
import pino from "pino" ;
11
11
import { filterInvalidPriceItems } from "../utils" ;
12
+ import { PricePusherMetrics } from "../metrics" ;
13
+ import { createSuiBalanceTracker } from "../balance-tracker" ;
14
+ import { SuiClient } from "@mysten/sui/client" ;
12
15
13
16
export default {
14
17
command : "sui" ,
@@ -72,6 +75,8 @@ export default {
72
75
...options . pushingFrequency ,
73
76
...options . logLevel ,
74
77
...options . controllerLogLevel ,
78
+ ...options . enableMetrics ,
79
+ ...options . metricsPort ,
75
80
} ,
76
81
handler : async function ( argv : any ) {
77
82
const {
@@ -89,6 +94,8 @@ export default {
89
94
accountIndex,
90
95
logLevel,
91
96
controllerLogLevel,
97
+ enableMetrics,
98
+ metricsPort,
92
99
} = argv ;
93
100
94
101
const logger = pino ( { level : logLevel } ) ;
@@ -101,11 +108,8 @@ export default {
101
108
mnemonic ,
102
109
`m/44'/784'/${ accountIndex } '/0'/0'` ,
103
110
) ;
104
- logger . info (
105
- `Pushing updates from wallet address: ${ keypair
106
- . getPublicKey ( )
107
- . toSuiAddress ( ) } `,
108
- ) ;
111
+ const suiAddress = keypair . getPublicKey ( ) . toSuiAddress ( ) ;
112
+ logger . info ( `Pushing updates from wallet address: ${ suiAddress } ` ) ;
109
113
110
114
let priceItems = priceConfigs . map ( ( { id, alias } ) => ( { id, alias } ) ) ;
111
115
@@ -123,12 +127,22 @@ export default {
123
127
124
128
priceItems = existingPriceItems ;
125
129
130
+ // Initialize metrics if enabled
131
+ let metrics : PricePusherMetrics | undefined ;
132
+ if ( enableMetrics ) {
133
+ metrics = new PricePusherMetrics ( logger . child ( { module : "Metrics" } ) ) ;
134
+ metrics . start ( metricsPort ) ;
135
+ logger . info ( `Metrics server started on port ${ metricsPort } ` ) ;
136
+ }
137
+
126
138
const pythListener = new PythPriceListener (
127
139
hermesClient ,
128
140
priceItems ,
129
141
logger . child ( { module : "PythPriceListener" } ) ,
130
142
) ;
131
143
144
+ const suiClient = new SuiClient ( { url : endpoint } ) ;
145
+
132
146
const suiListener = new SuiPriceListener (
133
147
pythStateId ,
134
148
wormholeStateId ,
@@ -137,6 +151,7 @@ export default {
137
151
logger . child ( { module : "SuiPriceListener" } ) ,
138
152
{ pollingFrequency } ,
139
153
) ;
154
+
140
155
const suiPusher = await SuiPricePusher . createWithAutomaticGasPool (
141
156
hermesClient ,
142
157
logger . child ( { module : "SuiPricePusher" } ) ,
@@ -155,9 +170,29 @@ export default {
155
170
suiListener ,
156
171
suiPusher ,
157
172
logger . child ( { module : "Controller" } , { level : controllerLogLevel } ) ,
158
- { pushingFrequency } ,
173
+ {
174
+ pushingFrequency,
175
+ metrics,
176
+ } ,
159
177
) ;
160
178
179
+ // Create and start the balance tracker if metrics are enabled
180
+ if ( metrics ) {
181
+ // For Sui, we'll use a simple network identification approach
182
+ // In the future, this could be improved by querying the network directly
183
+ const balanceTracker = createSuiBalanceTracker ( {
184
+ client : suiClient ,
185
+ address : suiAddress ,
186
+ network : "sui" , // Simply use "sui" as the network name for now
187
+ updateInterval : pushingFrequency ,
188
+ metrics,
189
+ logger,
190
+ } ) ;
191
+
192
+ // Start the balance tracker
193
+ await balanceTracker . start ( ) ;
194
+ }
195
+
161
196
controller . start ( ) ;
162
197
} ,
163
198
} ;
0 commit comments