delayedWithdrawGasLimit function
Implementation
Future<BigInt> delayedWithdrawGasLimit(
String fromEthereumAddress, Token token) async {
BigInt withdrawMaxGas = BigInt.zero;
EthereumAddress from =
EthereumAddress.fromHex(getEthereumAddress(fromEthereumAddress)!);
EthereumAddress to = EthereumAddress.fromHex(
getCurrentEnvironment()!.contracts[ContractName.withdrawalDelayer]!);
EtherAmount value = EtherAmount.zero();
Uint8List? data;
final withdrawalDelayerContract = await ContractParser.fromAssets(
'WithdrawalDelayerABI.json',
getCurrentEnvironment()!.contracts[ContractName.withdrawalDelayer]!,
ContractName.withdrawalDelayer);
final transactionParameters = [
from,
token.id == 0 ? 0x0 : EthereumAddress.fromHex(token.ethereumAddress!)
];
Transaction transaction = Transaction.callContract(
contract: withdrawalDelayerContract,
function: _withdrawal(withdrawalDelayerContract),
parameters: transactionParameters);
data = transaction.data;
try {
withdrawMaxGas = await HermezSDK.currentWeb3Client!
.estimateGas(sender: from, to: to, value: value, data: data);
} catch (e) {
// DEFAULT DELAYED WITHDRAW: ???? 230K + Transfer + (siblings.length * 31K)
withdrawMaxGas = BigInt.from(GAS_LIMIT_WITHDRAW_DEFAULT);
if (token.id != 0) {
withdrawMaxGas += await transferGasLimit(
value.getInWei, to.hex, from.hex, token.ethereumAddress, token.name);
}
//withdrawMaxGas += BigInt.from(GAS_LIMIT_WITHDRAW_SIBLING * merkleSiblings.length);
}
withdrawMaxGas += BigInt.from(GAS_LIMIT_OFFSET);
withdrawMaxGas =
BigInt.from((withdrawMaxGas.toInt() / pow(10, 3)).floor() * pow(10, 3));
return withdrawMaxGas;
}