forceExitGasLimit function

Future<BigInt> forceExitGasLimit(
  1. String hezEthereumAddress,
  2. HermezCompressedAmount amount,
  3. String accountIndex,
  4. Token token,
)

Estimates a force Exit Max Gas. This is the L1 transaction equivalent of Exit.

@param {BigInt} amount - The amount to be withdrawn @param {String} accountIndex - The account index in hez address format e.g. hez:DAI:4444 @param {Object} token - The token information object as returned from the API @param {String} providerUrl - Network url (i.e, http://localhost:8545). Optional @param {Object} signerData - Signer data used to build a Signer to send the transaction @param {Number} gasLimit - Optional gas limit @param {Number} gasMultiplier - Optional gas multiplier

Implementation

Future<BigInt> forceExitGasLimit(String hezEthereumAddress,
    HermezCompressedAmount amount, String accountIndex, Token token) async {
  BigInt forceExitMaxGas = BigInt.zero;
  EthereumAddress from =
      EthereumAddress.fromHex(getEthereumAddress(hezEthereumAddress)!);
  EthereumAddress to =
      EthereumAddress.fromHex(getCurrentEnvironment()!.contracts['Hermez']!);
  EtherAmount value = EtherAmount.zero();
  Uint8List? data;

  final hermezContract = await ContractParser.fromAssets('HermezABI.json',
      getCurrentEnvironment()!.contracts['Hermez']!, "Hermez");

  final transactionParameters = [
    BigInt.zero,
    BigInt.from(getAccountIndex(accountIndex)),
    BigInt.zero,
    BigInt.from(amount.value),
    BigInt.from(token.id!),
    BigInt.one,
    hexToBytes('0x')
  ];

  Transaction transaction = Transaction.callContract(
      contract: hermezContract,
      function: _addL1Transaction(hermezContract),
      parameters: transactionParameters);

  data = transaction.data;

  try {
    forceExitMaxGas = await HermezSDK.currentWeb3Client!
        .estimateGas(sender: from, to: to, value: value, data: data);
    forceExitMaxGas += BigInt.from(GAS_LIMIT_DEPOSIT_OFFSET);
    forceExitMaxGas = BigInt.from(
        (forceExitMaxGas.toInt() / pow(10, 3)).floor() * pow(10, 3));
  } catch (e) {
    forceExitMaxGas = BigInt.from(GAS_LIMIT_LOW);
    forceExitMaxGas = BigInt.from(
        (forceExitMaxGas.toInt() / pow(10, 3)).floor() * pow(10, 3));
  }

  return forceExitMaxGas;
}