Skip to content

Commit a027bd2

Browse files
committed
refactor: variables names and wei to eth
1 parent fb67fbd commit a027bd2

File tree

2 files changed

+14
-4
lines changed

2 files changed

+14
-4
lines changed

core/chainio/avs_writer.go

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import (
1616
"github.com/ethereum/go-ethereum/core/types"
1717
servicemanager "github.com/yetanotherco/aligned_layer/contracts/bindings/AlignedLayerServiceManager"
1818
"github.com/yetanotherco/aligned_layer/core/config"
19+
"github.com/yetanotherco/aligned_layer/core/utils"
1920
"github.com/yetanotherco/aligned_layer/metrics"
2021
)
2122

@@ -29,7 +30,7 @@ type AvsWriter struct {
2930
metrics *metrics.Metrics
3031
}
3132

32-
func NewAvsWriterFromConfig(baseConfig *config.BaseConfig, ecdsaConfig *config.EcdsaConfig) (*AvsWriter, error) {
33+
func NewAvsWriterFromConfig(baseConfig *config.BaseConfig, ecdsaConfig *config.EcdsaConfig, metrics *metrics.Metrics) (*AvsWriter, error) {
3334

3435
buildAllConfig := clients.BuildAllConfig{
3536
EthHttpUrl: baseConfig.EthRpcUrl,
@@ -69,6 +70,7 @@ func NewAvsWriterFromConfig(baseConfig *config.BaseConfig, ecdsaConfig *config.E
6970
Signer: privateKeySigner,
7071
Client: baseConfig.EthRpcClient,
7172
ClientFallback: baseConfig.EthRpcClientFallback,
73+
metrics: metrics,
7274
}, nil
7375
}
7476

@@ -131,10 +133,11 @@ func (w *AvsWriter) checkRespondToTaskFeeLimit(tx *types.Transaction, txOpts bin
131133
w.logger.Info("Batch RespondToTaskFeeLimit", "RespondToTaskFeeLimit", respondToTaskFeeLimit)
132134

133135
if respondToTaskFeeLimit.Cmp(simulatedCost) < 0 {
134-
a, _ := respondToTaskFeeLimit.Sub(big.NewInt(0), simulatedCost).Float64()
135-
w.metrics.AddAccumulatedGasPayedAggregator(a)
136+
aggregatorDifferenceToPay := new(big.Int).Sub(simulatedCost, respondToTaskFeeLimit)
137+
aggregatorDifferenceToPayInEth, _ := utils.WeiToEth(aggregatorDifferenceToPay).Float64()
138+
w.metrics.AddAccumulatedGasPayedAggregator(aggregatorDifferenceToPayInEth)
136139
w.metrics.IncAggregatorAccumResponse()
137-
w.logger.Warn("cost of transaction is higher than Batch.RespondToTaskFeeLimit, aggregator will pay the for the difference")
140+
w.logger.Warn("cost of transaction is higher than Batch.RespondToTaskFeeLimit, aggregator will pay the for the difference, aprox: %v", aggregatorDifferenceToPay)
138141
}
139142

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

core/utils/eth_client_utils.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package utils
22

33
import (
44
"context"
5+
"math/big"
56
"time"
67

78
"fmt"
@@ -42,3 +43,9 @@ func BytesToQuorumThresholdPercentages(quorumThresholdPercentagesBytes []byte) e
4243
}
4344
return quorumThresholdPercentages
4445
}
46+
47+
func WeiToEth(wei *big.Int) *big.Int {
48+
weiToEth := new(big.Int).SetInt64(1e18)
49+
50+
return new(big.Int).Quo(wei, weiToEth)
51+
}

0 commit comments

Comments
 (0)