@@ -232,30 +232,47 @@ class ReputationMinerClient {
232
232
this . _adapter . log ( "🏁 Initialised" ) ;
233
233
}
234
234
235
- async updateGasEstimate ( type ) {
236
- if ( this . chainId === 100 ) {
237
- this . _miner . gasPrice = ethers . utils . hexlify ( 1000000000 ) ;
238
- return ;
239
- }
240
- // Get latest from ethGasStation
235
+ async updateGasEstimate ( _type ) {
236
+ let type = _type ;
241
237
const options = {
242
- uri : 'https://ethgasstation.info/json/ethgasAPI.json' ,
243
238
headers : {
244
- 'User-Agent' : 'Request-Promise'
239
+ 'User-Agent' : 'Request-Promise'
245
240
} ,
246
241
json : true // Automatically parses the JSON string in the response
247
242
} ;
243
+ let defaultGasPrice ;
244
+ let factor ;
245
+
246
+ if ( this . chainId === 100 ) {
247
+ options . uri = "https://blockscout.com/xdai/mainnet/api/v1/gas-price-oracle" ;
248
+ defaultGasPrice = ethers . utils . hexlify ( 1000000000 ) ;
249
+ factor = 1 ;
250
+ // This oracle presents the information slightly differently from ethgasstation.
251
+ if ( _type === "safeLow" ) {
252
+ type = "slow" ;
253
+ }
254
+ } else if ( this . chainId === 1 ) {
255
+ options . uri = "https://ethgasstation.info/json/ethgasAPI.json" ;
256
+ defaultGasPrice = ethers . utils . hexlify ( 20000000000 ) ;
257
+ factor = 10 ;
258
+ } else {
259
+ this . _adapter . error ( `Error during gas estimation: unknown chainid ${ this . chainId } ` ) ;
260
+ this . _miner . gasPrice = ethers . utils . hexlify ( 20000000000 ) ;
261
+ return ;
262
+ }
263
+
264
+ // Get latest from whichever oracle
248
265
try {
249
266
const gasEstimates = await request ( options ) ;
250
267
251
268
if ( gasEstimates [ type ] ) {
252
- this . _miner . gasPrice = ethers . utils . hexlify ( gasEstimates [ type ] / 10 * 1e9 ) ;
269
+ this . _miner . gasPrice = ethers . utils . hexlify ( gasEstimates [ type ] / factor * 1e9 ) ;
253
270
} else {
254
- this . _miner . gasPrice = ethers . utils . hexlify ( 20000000000 ) ;
271
+ this . _miner . gasPrice = defaultGasPrice ;
255
272
}
256
273
} catch ( err ) {
257
274
this . _adapter . error ( `Error during gas estimation: ${ err } ` ) ;
258
- this . _miner . gasPrice = ethers . utils . hexlify ( 20000000000 ) ;
275
+ this . _miner . gasPrice = defaultGasPrice ;
259
276
}
260
277
}
261
278
@@ -335,7 +352,7 @@ class ReputationMinerClient {
335
352
if ( canSubmit ) {
336
353
this . _adapter . log ( "⏰ Looks like it's time to submit an entry to the current cycle" ) ;
337
354
this . submissionIndex += 1 ;
338
- await this . updateGasEstimate ( 'safeLow ' ) ;
355
+ await this . updateGasEstimate ( 'average ' ) ;
339
356
await this . submitEntry ( entryIndex ) ;
340
357
}
341
358
}
@@ -380,7 +397,7 @@ class ReputationMinerClient {
380
397
return ;
381
398
}
382
399
}
383
- await this . updateGasEstimate ( 'safeLow ' ) ;
400
+ await this . updateGasEstimate ( 'average ' ) ;
384
401
await repCycle . invalidateHash ( round , oppIndex , { "gasPrice" : this . _miner . gasPrice } ) ;
385
402
this . endDoBlockChecks ( ) ;
386
403
return ;
@@ -398,7 +415,7 @@ class ReputationMinerClient {
398
415
) ;
399
416
if ( responsePossible ) {
400
417
// If so, invalidate them.
401
- await this . updateGasEstimate ( 'safeLow ' ) ;
418
+ await this . updateGasEstimate ( 'average ' ) ;
402
419
await repCycle . invalidateHash ( round , oppIndex , { "gasPrice" : this . _miner . gasPrice } ) ;
403
420
this . endDoBlockChecks ( ) ;
404
421
return ;
@@ -466,7 +483,7 @@ class ReputationMinerClient {
466
483
if ( responsePossible ) {
467
484
this . best12Submissions = [ ] ; // Clear the submissions
468
485
this . submissionIndex = 0 ;
469
- await this . updateGasEstimate ( 'safeLow ' ) ;
486
+ await this . updateGasEstimate ( 'average ' ) ;
470
487
await this . confirmEntry ( ) ;
471
488
}
472
489
}
0 commit comments