@@ -266,12 +266,14 @@ export class GasPriceOracleService extends BaseService<GasPriceOracleOptions> {
266
266
const historyJsonRaw = await fsPromise . readFile ( dumpsPath )
267
267
const historyJSON = JSON . parse ( historyJsonRaw . toString ( ) )
268
268
if ( historyJSON . L1ETHCostFee ) {
269
- /* eslint-disable */
270
269
this . state . L1ETHBalance = BigNumber . from ( historyJSON . L1ETHBalance )
271
270
this . state . L1ETHCostFee = BigNumber . from ( historyJSON . L1ETHCostFee )
272
- this . state . L1RelayerBalance = BigNumber . from ( historyJSON . L1RelayerBalance )
273
- this . state . L1RelayerCostFee = BigNumber . from ( historyJSON . L1RelayerCostFee )
274
- /* eslint-enable */
271
+ this . state . L1RelayerBalance = BigNumber . from (
272
+ historyJSON . L1RelayerBalance
273
+ )
274
+ this . state . L1RelayerCostFee = BigNumber . from (
275
+ historyJSON . L1RelayerCostFee
276
+ )
275
277
} else {
276
278
this . logger . warn ( 'Invalid L1 cost history!' )
277
279
}
@@ -296,20 +298,34 @@ export class GasPriceOracleService extends BaseService<GasPriceOracleOptions> {
296
298
this . logger . warn ( 'Loading L2 cost history...' )
297
299
const historyJsonRaw = await fsPromise . readFile ( dumpsPath )
298
300
const historyJSON = JSON . parse ( historyJsonRaw . toString ( ) )
299
- /* eslint-disable */
300
301
this . _readL2FeeCost ( historyJSON , ETHVaultBalance , 'L2ETHCollectFee' )
301
302
this . _readL2FeeCost ( historyJSON , BOBAVaultBalance , 'L2BOBACollectFee' )
302
- this . _readL2FeeCost ( historyJSON , BOBABillingBalance , 'L2BOBABillingCollectFee' )
303
+ this . _readL2FeeCost (
304
+ historyJSON ,
305
+ BOBABillingBalance ,
306
+ 'L2BOBABillingCollectFee'
307
+ )
303
308
} else {
304
309
this . logger . warn ( 'No L2 cost history Found!' )
305
310
this . state . L2ETHCollectFee = ETHVaultBalance
306
311
this . state . L2BOBACollectFee = BOBAVaultBalance
307
312
this . state . L2BOBABillingCollectFee = BOBABillingBalance
308
313
}
309
- this . _adjustL2FeeCost ( ETHVaultBalance , this . state . L2ETHCollectFee , 'L2ETHCollectFee' )
310
- this . _adjustL2FeeCost ( BOBAVaultBalance , this . state . L2BOBACollectFee , 'L2BOBACollectFee' )
311
- this . _adjustL2FeeCost ( BOBABillingBalance , this . state . L2BOBABillingCollectFee , 'L2BOBABillingCollectFee' )
312
- /* eslint-enable */
314
+ this . _adjustL2FeeCost (
315
+ ETHVaultBalance ,
316
+ this . state . L2ETHCollectFee ,
317
+ 'L2ETHCollectFee'
318
+ )
319
+ this . _adjustL2FeeCost (
320
+ BOBAVaultBalance ,
321
+ this . state . L2BOBACollectFee ,
322
+ 'L2BOBACollectFee'
323
+ )
324
+ this . _adjustL2FeeCost (
325
+ BOBABillingBalance ,
326
+ this . state . L2BOBABillingCollectFee ,
327
+ 'L2BOBABillingCollectFee'
328
+ )
313
329
this . state . L2ETHVaultBalance = ETHVaultBalance
314
330
this . state . L2BOBAVaultBalance = BOBAVaultBalance
315
331
this . logger . info ( 'Loaded L2 Cost Data' , {
@@ -412,13 +428,21 @@ export class GasPriceOracleService extends BaseService<GasPriceOracleOptions> {
412
428
this . logger . info ( 'Got L1 ETH balances' , {
413
429
network : 'L1' ,
414
430
data : {
415
- /* eslint-disable */
416
431
L1ETHBalance : this . _formatBigNumberToEther ( this . state . L1ETHBalance ) ,
417
432
L1ETHCostFee : this . _formatBigNumberToEther ( this . state . L1ETHCostFee ) ,
418
- L1ETHCostFeeUSD : this . _formatBigNumberToEtherUSD ( this . state . L1ETHCostFee , this . state . ETHUSDPrice , 2 ) ,
419
- L1RelayerCostFee : this . _formatBigNumberToEther ( this . state . L1RelayerCostFee ) ,
420
- L1RelayerCostFeeUSD : this . _formatBigNumberToEtherUSD ( this . state . L1RelayerCostFee , this . state . ETHUSDPrice , 2 ) ,
421
- /* eslint-enable */
433
+ L1ETHCostFeeUSD : this . _formatBigNumberToEtherUSD (
434
+ this . state . L1ETHCostFee ,
435
+ this . state . ETHUSDPrice ,
436
+ 2
437
+ ) ,
438
+ L1RelayerCostFee : this . _formatBigNumberToEther (
439
+ this . state . L1RelayerCostFee
440
+ ) ,
441
+ L1RelayerCostFeeUSD : this . _formatBigNumberToEtherUSD (
442
+ this . state . L1RelayerCostFee ,
443
+ this . state . ETHUSDPrice ,
444
+ 2
445
+ ) ,
422
446
} ,
423
447
} )
424
448
} catch ( error ) {
@@ -467,16 +491,32 @@ export class GasPriceOracleService extends BaseService<GasPriceOracleOptions> {
467
491
this . logger . info ( 'Got L2 Gas Collect' , {
468
492
network : 'L2' ,
469
493
data : {
470
- /* eslint-disable */
471
- L2ETHCollectFee : this . _formatBigNumberToEther ( this . state . L2ETHCollectFee ) ,
472
- L2BOBACollectFee : this . _formatBigNumberToEther ( this . state . L2BOBACollectFee ) ,
473
- L2BOBABillingCollectFee : this . _formatBigNumberToEther ( this . state . L2BOBABillingCollectFee ) ,
474
- L2ETHCollectFeeUSD : this . _formatBigNumberToEtherUSD ( this . state . L2ETHCollectFee , this . state . ETHUSDPrice , 2 ) ,
475
- L2BOBACollectFeeUSD : this . _formatBigNumberToEtherUSD ( this . state . L2BOBACollectFee , this . state . BOBAUSDPrice , 2 ) ,
476
- L2BOBABillingCollectFeeUSD : this . _formatBigNumberToEtherUSD ( this . state . L2BOBABillingCollectFee , this . state . BOBAUSDPrice , 2 ) ,
494
+ L2ETHCollectFee : this . _formatBigNumberToEther (
495
+ this . state . L2ETHCollectFee
496
+ ) ,
497
+ L2BOBACollectFee : this . _formatBigNumberToEther (
498
+ this . state . L2BOBACollectFee
499
+ ) ,
500
+ L2BOBABillingCollectFee : this . _formatBigNumberToEther (
501
+ this . state . L2BOBABillingCollectFee
502
+ ) ,
503
+ L2ETHCollectFeeUSD : this . _formatBigNumberToEtherUSD (
504
+ this . state . L2ETHCollectFee ,
505
+ this . state . ETHUSDPrice ,
506
+ 2
507
+ ) ,
508
+ L2BOBACollectFeeUSD : this . _formatBigNumberToEtherUSD (
509
+ this . state . L2BOBACollectFee ,
510
+ this . state . BOBAUSDPrice ,
511
+ 2
512
+ ) ,
513
+ L2BOBABillingCollectFeeUSD : this . _formatBigNumberToEtherUSD (
514
+ this . state . L2BOBABillingCollectFee ,
515
+ this . state . BOBAUSDPrice ,
516
+ 2
517
+ ) ,
477
518
BOBAUSDPrice : Number ( this . state . BOBAUSDPrice . toFixed ( 2 ) ) ,
478
519
ETHUSDPrice : Number ( this . state . ETHUSDPrice . toFixed ( 2 ) ) ,
479
- /* eslint-enable */
480
520
} ,
481
521
} )
482
522
} catch ( error ) {
@@ -570,11 +610,11 @@ export class GasPriceOracleService extends BaseService<GasPriceOracleOptions> {
570
610
) . toNumber ( )
571
611
572
612
if (
573
- /* eslint-disable */
574
- targetOverheadGas > overheadProduction * ( 1 + this . options . overheadMinPercentChange ) &&
575
- targetOverheadGas < overheadProduction * ( 1 - this . options . overheadMinPercentChange ) &&
613
+ targetOverheadGas >
614
+ overheadProduction * ( 1 + this . options . overheadMinPercentChange ) &&
615
+ targetOverheadGas <
616
+ overheadProduction * ( 1 - this . options . overheadMinPercentChange ) &&
576
617
targetOverheadGas > this . options . minOverhead
577
- /* eslint-enable */
578
618
) {
579
619
this . logger . debug ( 'Updating overhead gas...' )
580
620
const tx = await this . state . OVM_GasPriceOracle . setOverhead (
@@ -621,17 +661,20 @@ export class GasPriceOracleService extends BaseService<GasPriceOracleOptions> {
621
661
622
662
private async _queryTokenPrice ( tokenPair : string ) : Promise < void > {
623
663
if ( tokenPair === 'ETH/USD' ) {
624
- const latestAnswer = await this . state . BobaStraw_ETHUSD . latestAnswer ( )
625
- const decimals = await this . state . BobaStraw_ETHUSD . decimals ( )
626
- this . state . ETHUSDPrice = this . _calculateTokenPrice ( latestAnswer , decimals )
664
+ const ETHUSDPrice = Number (
665
+ await this . _getTokenPriceFromCoinGecko ( 'ethereum' )
666
+ )
667
+ if ( ETHUSDPrice > 0 ) {
668
+ this . state . ETHUSDPrice = ETHUSDPrice
669
+ }
627
670
}
628
671
if ( tokenPair === 'BOBA/USD' ) {
629
- const latestAnswer = await this . state . BobaStraw_BOBAUSD . latestAnswer ( )
630
- const decimals = await this . state . BobaStraw_BOBAUSD . decimals ( )
631
- this . state . BOBAUSDPrice = this . _calculateTokenPrice (
632
- latestAnswer ,
633
- decimals
672
+ const BOBAUSDPrice = Number (
673
+ await this . _getTokenPriceFromCoinGecko ( 'boba-network' )
634
674
)
675
+ if ( BOBAUSDPrice > 0 ) {
676
+ this . state . BOBAUSDPrice = BOBAUSDPrice
677
+ }
635
678
}
636
679
}
637
680
@@ -687,10 +730,10 @@ export class GasPriceOracleService extends BaseService<GasPriceOracleOptions> {
687
730
prefixVaultBalance : string = null ,
688
731
prefixCollectFee : string = null
689
732
) {
690
- /* eslint-disable */
691
- const vaultBalanceName = prefixVaultBalance === null ? `${ prefix } VaultBalance` : prefixVaultBalance
692
- const collectFeeName = prefixCollectFee === null ? ` ${ prefix } CollectFee` : prefixCollectFee
693
- /* eslint-enable */
733
+ const vaultBalanceName =
734
+ prefixVaultBalance === null ? `${ prefix } VaultBalance` : prefixVaultBalance
735
+ const collectFeeName =
736
+ prefixCollectFee === null ? ` ${ prefix } CollectFee` : prefixCollectFee
694
737
// If vault balance is lower than the cache, it means that the vault has been drained
695
738
if ( latestCollectFee . lt ( vaultBalanceHistory ) ) {
696
739
this . state [ vaultBalanceName ] = latestCollectFee
@@ -709,14 +752,27 @@ export class GasPriceOracleService extends BaseService<GasPriceOracleOptions> {
709
752
minDecimals : number = 2
710
753
) : number {
711
754
if ( decimals >= minDecimals ) {
712
- /* eslint-disable */
713
- const tokenPriceX = tokenPrice . div ( BigNumber . from ( 10 ) . pow ( decimals - minDecimals ) )
755
+ const tokenPriceX = tokenPrice . div (
756
+ BigNumber . from ( 10 ) . pow ( decimals - minDecimals )
757
+ )
714
758
return tokenPriceX . toNumber ( ) / 100
715
- /* eslint-enable */
716
759
}
717
760
return tokenPrice . toNumber ( ) / 10 ** decimals
718
761
}
719
762
763
+ // Data provided by CoinGecko
764
+ private async _getTokenPriceFromCoinGecko ( id : string ) : Promise < number > {
765
+ try {
766
+ const URL = `https:///api.coingecko.com/api/v3/coins/${ id } ?localization=false&tickers=false&community_date=false&developer_data=false&sparkline=false`
767
+ const payload = await fetch ( URL )
768
+ const payloadParsed = await payload . json ( )
769
+ return Number ( payloadParsed . market_data . current_price . usd )
770
+ } catch ( err ) {
771
+ this . logger . warn ( `CAN\'T QUERY TOKEN PRICE ${ err } - ${ id } FROM CoinGecko` )
772
+ return 0
773
+ }
774
+ }
775
+
720
776
private _formatBigNumberToEther (
721
777
number : BigNumber | string ,
722
778
decimal = 6
@@ -923,7 +979,6 @@ export class GasPriceOracleAltL1Service extends BaseService<GasPriceOracleOption
923
979
const historyJsonRaw = await fsPromise . readFile ( dumpsPath )
924
980
const historyJSON = JSON . parse ( historyJsonRaw . toString ( ) )
925
981
if ( historyJSON . L1SecondaryFeeTokenCostFee ) {
926
- /* eslint-disable */
927
982
this . state . L1SecondaryFeeTokenBalance = BigNumber . from (
928
983
historyJSON . L1SecondaryFeeTokenBalance
929
984
)
@@ -936,7 +991,6 @@ export class GasPriceOracleAltL1Service extends BaseService<GasPriceOracleOption
936
991
this . state . L1RelayerCostFee = BigNumber . from (
937
992
historyJSON . L1RelayerCostFee
938
993
)
939
- /* eslint-enable */
940
994
} else {
941
995
this . logger . warn ( 'Invalid L1 cost history!' )
942
996
}
@@ -963,7 +1017,6 @@ export class GasPriceOracleAltL1Service extends BaseService<GasPriceOracleOption
963
1017
this . logger . warn ( 'Loading L2 cost history...' )
964
1018
const historyJsonRaw = await fsPromise . readFile ( dumpsPath )
965
1019
const historyJSON = JSON . parse ( historyJsonRaw . toString ( ) )
966
- /* eslint-disable */
967
1020
this . _readL2FeeCost ( historyJSON , ETHVaultBalance , 'L2BOBACollectFee' )
968
1021
this . _readL2FeeCost (
969
1022
historyJSON ,
@@ -996,7 +1049,6 @@ export class GasPriceOracleAltL1Service extends BaseService<GasPriceOracleOption
996
1049
this . state . L2SecondaryFeeTokenCollectFee ,
997
1050
'L2SecondaryFeeTokenCollectFee'
998
1051
)
999
- /* eslint-enable */
1000
1052
this . state . L2BOBAVaultBalance = ETHVaultBalance
1001
1053
this . logger . info ( 'Loaded L2 Cost Data' , {
1002
1054
L2BOBAVaultBalance : this . state . L2BOBAVaultBalance . toString ( ) ,
@@ -1100,7 +1152,6 @@ export class GasPriceOracleAltL1Service extends BaseService<GasPriceOracleOption
1100
1152
this . logger . info ( 'Got L1 ETH balances' , {
1101
1153
network : 'L1' ,
1102
1154
data : {
1103
- /* eslint-disable */
1104
1155
L1SecondaryFeeTokenBalance : this . _formatBigNumberToEther (
1105
1156
this . state . L1SecondaryFeeTokenBalance
1106
1157
) ,
@@ -1125,7 +1176,6 @@ export class GasPriceOracleAltL1Service extends BaseService<GasPriceOracleOption
1125
1176
this . state . L1NativeTokenPrice ,
1126
1177
2
1127
1178
) ,
1128
- /* eslint-enable */
1129
1179
} ,
1130
1180
} )
1131
1181
} catch ( error ) {
@@ -1175,7 +1225,6 @@ export class GasPriceOracleAltL1Service extends BaseService<GasPriceOracleOption
1175
1225
this . logger . info ( 'Got L2 Gas Collect' , {
1176
1226
network : 'L2' ,
1177
1227
data : {
1178
- /* eslint-disable */
1179
1228
L2BOBACollectFee : this . _formatBigNumberToEther (
1180
1229
this . state . L2BOBACollectFee
1181
1230
) ,
@@ -1197,7 +1246,6 @@ export class GasPriceOracleAltL1Service extends BaseService<GasPriceOracleOption
1197
1246
this . state . L2SecondaryFeeTokenCollectFee ,
1198
1247
this . state . L1NativeTokenPrice
1199
1248
) ,
1200
- /* eslint-enable */
1201
1249
} ,
1202
1250
} )
1203
1251
} catch ( error ) {
@@ -1260,13 +1308,11 @@ export class GasPriceOracleAltL1Service extends BaseService<GasPriceOracleOption
1260
1308
) . toNumber ( )
1261
1309
1262
1310
if (
1263
- /* eslint-disable */
1264
1311
targetOverheadGas >
1265
1312
overheadProduction * ( 1 + this . options . overheadMinPercentChange ) &&
1266
1313
targetOverheadGas <
1267
1314
overheadProduction * ( 1 - this . options . overheadMinPercentChange ) &&
1268
1315
targetOverheadGas > this . options . minOverhead
1269
- /* eslint-enable */
1270
1316
) {
1271
1317
this . logger . debug ( 'Updating overhead gas...' )
1272
1318
const tx = await this . state . OVM_GasPriceOracle . setOverhead (
@@ -1313,7 +1359,6 @@ export class GasPriceOracleAltL1Service extends BaseService<GasPriceOracleOption
1313
1359
1314
1360
private async _updatePriceRatio ( ) : Promise < void > {
1315
1361
try {
1316
- /* eslint-disable */
1317
1362
const BobaPriceFromCoinGecko = await this . _getTokenPriceFromCoinGecko (
1318
1363
'boba-network'
1319
1364
)
@@ -1350,7 +1395,6 @@ export class GasPriceOracleAltL1Service extends BaseService<GasPriceOracleOption
1350
1395
const l1NativeTokenPrice = calculateAverage (
1351
1396
this . filterOutliers ( l1NativeTokenMarketPricesFromCoinMarketCap )
1352
1397
)
1353
- /* eslint-enable */
1354
1398
1355
1399
// store prices
1356
1400
this . state . BobaPrice = BobaPrice
@@ -1369,14 +1413,12 @@ export class GasPriceOracleAltL1Service extends BaseService<GasPriceOracleOption
1369
1413
( marketPriceRatio * this . options . bobaFeeRatio100X ) / 100
1370
1414
)
1371
1415
1372
- /* eslint-disable */
1373
1416
const originalPriceRatio = (
1374
1417
await this . state . Boba_GasPriceOracle . priceRatio ( )
1375
1418
) . toNumber ( )
1376
1419
const originalMarketPriceRatio = (
1377
1420
await this . state . Boba_GasPriceOracle . marketPriceRatio ( )
1378
1421
) . toNumber ( )
1379
- /* eslint-enable */
1380
1422
1381
1423
if (
1382
1424
priceRatio !== originalPriceRatio ||
@@ -1541,12 +1583,10 @@ export class GasPriceOracleAltL1Service extends BaseService<GasPriceOracleOption
1541
1583
prefixVaultBalance : string = null ,
1542
1584
prefixCollectFee : string = null
1543
1585
) {
1544
- /* eslint-disable */
1545
1586
const vaultBalanceName =
1546
1587
prefixVaultBalance === null ? `${ prefix } VaultBalance` : prefixVaultBalance
1547
1588
const collectFeeName =
1548
1589
prefixCollectFee === null ? `${ prefix } CollectFee` : prefixCollectFee
1549
- /* eslint-enable */
1550
1590
// If vault balance is lower than the cache, it means that the vault has been drained
1551
1591
if ( latestCollectFee . lt ( vaultBalanceHistory ) ) {
1552
1592
this . state [ vaultBalanceName ] = latestCollectFee
0 commit comments