Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CW-672: Enhance ETH Wallet Fee Calculation - Fix ERC20 Transaction Fee #1548

Merged
merged 11 commits into from
Jul 23, 2024
18 changes: 9 additions & 9 deletions cw_evm/lib/evm_chain_client.dart
Original file line number Diff line number Diff line change
Expand Up @@ -72,12 +72,12 @@ abstract class EVMChainClient {
}
}

Future<int> getGasBaseFee() async {
Future<int?> getGasBaseFee() async {
try {
final blockInfo = await _client!.getBlockInformation(isContainFullObj: false);
final baseFee = blockInfo.baseFeePerGas;

return baseFee!.getInWei.toInt();
return baseFee?.getInWei.toInt();
} catch (_) {
return 0;
}
Expand Down Expand Up @@ -110,19 +110,19 @@ abstract class EVMChainClient {
EthereumAddress.fromHex(contractAddress),
);

final transferFunction = contract.function('transferFrom');
final transfer = contract.function('transfer');

final estimatedGas = await _client!.estimateGas(
// Estimate gas units
final gasEstimate = await _client!.estimateGas(
sender: senderAddress,
to: toAddress,
value: value,
data: transferFunction.encodeCall([
senderAddress,
to: EthereumAddress.fromHex(contractAddress),
data: transfer.encodeCall([
toAddress,
value.getInWei,
]),
);
return estimatedGas.toInt();

return gasEstimate.toInt();
}
} catch (_) {
return 0;
Expand Down
2 changes: 0 additions & 2 deletions cw_evm/lib/evm_chain_wallet.dart
Original file line number Diff line number Diff line change
Expand Up @@ -387,8 +387,6 @@ abstract class EVMChainWalletBase

estimatedFeesForTransaction = BigInt.from(estimateFees);

debugPrint('Estimated Fees for Transaction: $estimatedFeesForTransaction');

if (output.sendAll && transactionCurrency is! Erc20Token) {
totalAmount = (erc20Balance.balance - estimatedFeesForTransaction);

Expand Down
Loading