Skip to content

Commit c202251

Browse files
committed
refactor: wei to eth conversion
1 parent 07fb3bc commit c202251

File tree

2 files changed

+9
-5
lines changed

2 files changed

+9
-5
lines changed

core/chainio/avs_writer.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -134,10 +134,10 @@ func (w *AvsWriter) checkRespondToTaskFeeLimit(tx *types.Transaction, txOpts bin
134134

135135
if respondToTaskFeeLimit.Cmp(simulatedCost) < 0 {
136136
aggregatorDifferenceToPay := new(big.Int).Sub(simulatedCost, respondToTaskFeeLimit)
137-
aggregatorDifferenceToPayInEth, _ := utils.WeiToEth(aggregatorDifferenceToPay).Float64()
137+
aggregatorDifferenceToPayInEth := utils.WeiToEth(aggregatorDifferenceToPay)
138138
w.metrics.AddAggregatorGasPaidForBatcher(aggregatorDifferenceToPayInEth)
139139
w.metrics.IncAggregatorPaidForBatcher()
140-
w.logger.Warn("cost of transaction is higher than Batch.RespondToTaskFeeLimit, aggregator will pay the for the difference, aprox: %v", aggregatorDifferenceToPay)
140+
w.logger.Warnf("cost of transaction is higher than Batch.RespondToTaskFeeLimit, aggregator will pay the for the difference, aprox: %vethers", aggregatorDifferenceToPayInEth)
141141
}
142142

143143
return w.compareBalances(respondToTaskFeeLimit, aggregatorAddress, senderAddress)

core/utils/eth_client_utils.go

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,12 @@ func BytesToQuorumThresholdPercentages(quorumThresholdPercentagesBytes []byte) e
4444
return quorumThresholdPercentages
4545
}
4646

47-
func WeiToEth(wei *big.Int) *big.Int {
48-
weiToEth := new(big.Int).SetInt64(1e18)
47+
func WeiToEth(wei *big.Int) float64 {
48+
weiToEth := new(big.Float).SetFloat64(1e18)
49+
weiFloat := new(big.Float).SetInt(wei)
4950

50-
return new(big.Int).Quo(wei, weiToEth)
51+
result := new(big.Float).Quo(weiFloat, weiToEth)
52+
eth, _ := result.Float64()
53+
54+
return eth
5155
}

0 commit comments

Comments
 (0)