Skip to content

Commit

Permalink
feat: Added total gas calculator func
Browse files Browse the repository at this point in the history
  • Loading branch information
reasje committed Dec 7, 2023
1 parent 2aeb2be commit f18f152
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions logic/lib/src/domain/utils/mxc_gas.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import 'dart:math';

import 'package:mxc_logic/mxc_logic.dart';
import 'package:web3dart/web3dart.dart';

Expand All @@ -16,6 +18,7 @@ class MXCGas {
return maxFeePerGas;
}

/// The returned value is in Wei.
static double calculateMaxFeePerGasDouble(double gasPrice) {
final estimatedGasFeeAsDouble = gasPrice * Config.priority;

Expand All @@ -25,6 +28,28 @@ class MXCGas {
return maxFeePerGas.toDouble();
}

/// calculates total base fee based on base gas price & gas limit,
/// The returned value is in Eth.
static double calculateTotalFee(double gasPrice, int gasLimit) {
double gasFee = gasPrice * gasLimit;
gasFee = gasFee / pow(10, 18);
return gasFee;
}

/// calculates total max fee based on base gas price & gas limit,
/// The returned value is in Eth
static double calculateTotalMaxFee(double gasPrice, int gasLimit) {
final estimatedGasFeeAsDouble = gasPrice * gasLimit * Config.priority;

BigInt maxFeeBigInt = BigInt.from(estimatedGasFeeAsDouble) +
Config.maxPriorityFeePerGas.getInWei;

double maxFee = maxFeeBigInt.toDouble();
maxFee = maxFee / pow(10, 18);

return maxFee;
}

/// This functions adds to the fee by multiplying the gas price by the Config.extraGasPercentage.
static double addExtraFeeForTxReplacement(double gasPrice) {
final gasPriceDouble = gasPrice * Config.extraGasPercentage;
Expand Down

0 comments on commit f18f152

Please sign in to comment.