diff --git a/logic/lib/src/domain/utils/mxc_gas.dart b/logic/lib/src/domain/utils/mxc_gas.dart index 10e3f58..d14a830 100644 --- a/logic/lib/src/domain/utils/mxc_gas.dart +++ b/logic/lib/src/domain/utils/mxc_gas.dart @@ -1,3 +1,5 @@ +import 'dart:math'; + import 'package:mxc_logic/mxc_logic.dart'; import 'package:web3dart/web3dart.dart'; @@ -16,6 +18,7 @@ class MXCGas { return maxFeePerGas; } + /// The returned value is in Wei. static double calculateMaxFeePerGasDouble(double gasPrice) { final estimatedGasFeeAsDouble = gasPrice * Config.priority; @@ -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;