withdrawGasLimit function
Implementation
Future<BigInt> withdrawGasLimit(
double amount,
String fromEthereumAddress,
String? accountIndex,
Token token,
String babyJubJub,
int batchNumber,
List<BigInt> merkleSiblings,
{bool isInstant = true}) async {
final hermezContract = await ContractParser.fromAssets('HermezABI.json',
getCurrentEnvironment()!.contracts['Hermez']!, "Hermez");
BigInt withdrawMaxGas = BigInt.zero;
EthereumAddress from =
EthereumAddress.fromHex(getEthereumAddress(fromEthereumAddress)!);
EthereumAddress to =
EthereumAddress.fromHex(getCurrentEnvironment()!.contracts['Hermez']!);
EtherAmount value = EtherAmount.zero();
Uint8List? data;
final transactionParameters = [
BigInt.from(token.id!),
BigInt.from(amount),
hexToInt(babyJubJub),
BigInt.from(batchNumber),
merkleSiblings,
BigInt.from(getAccountIndex(accountIndex)),
isInstant,
];
print(transactionParameters);
Transaction transaction = Transaction.callContract(
contract: hermezContract,
function: _withdrawMerkleProof(hermezContract),
parameters: transactionParameters);
data = transaction.data;
// TODO: FIX ESTIMATE GAS
/*try {
withdrawMaxGas = await web3client.estimateGas(
sender: from, to: to, value: value, data: data);
} catch (e) {*/
// DEFAULT WITHDRAW: 230K + Transfer + (siblings.length * 31K)
withdrawMaxGas = BigInt.from(GAS_LIMIT_WITHDRAW_DEFAULT);
if (token.id != 0) {
withdrawMaxGas += await transferGasLimit(BigInt.from(amount), 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;
}