apply_gas_multiplier

Function

def apply_gas_multiplier(tx, multiplier=None):
    if not multiplier:
        multiplier = os.getenv('GAS_MULTIPLIER')
    try:
        multiplier = float(multiplier)
    except ValueError:
        raise ValueError("Invalid float for GAS_MULTIPLIER")
    else:
        tx['gas'] = int(tx['gas'] * multiplier)
        if 'maxFeePerGas' in tx:
            tx['maxFeePerGas'] = int(tx['maxFeePerGas'] * multiplier)
        return tx

Description

  • Check if a multiplier was specified in the function’s parameters

  • If no multiplier then get the one from “.env”

  • Try to cast the multiplier as a float

  • Take the estimated gas and multiply it

  • If maxFeePerGas is used then multiply it

  • Return the transaction