Skip to content

Commit

Permalink
fix: use Wei in gas strategies
Browse files Browse the repository at this point in the history
  • Loading branch information
iamdefinitelyahuman authored and lost-theory committed Jun 15, 2021
1 parent e7c8fd8 commit 9dbc630
Showing 1 changed file with 14 additions and 13 deletions.
27 changes: 14 additions & 13 deletions brownie/network/gas/strategies.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

import requests

from brownie.convert import Wei
from brownie.exceptions import RPCRequestError
from brownie.network.web3 import web3

Expand Down Expand Up @@ -59,22 +60,22 @@ class LinearScalingStrategy(TimeGasStrategy):

def __init__(
self,
initial_gas_price: int,
max_gas_price: int,
initial_gas_price: Wei,
max_gas_price: Wei,
increment: float = 1.125,
time_duration: int = 30,
):
super().__init__(time_duration)
self.initial_gas_price = initial_gas_price
self.max_gas_price = max_gas_price
self.initial_gas_price = Wei(initial_gas_price)
self.max_gas_price = Wei(max_gas_price)
self.increment = increment

def get_gas_price(self) -> Generator[int, None, None]:
def get_gas_price(self) -> Generator[Wei, None, None]:
last_gas_price = self.initial_gas_price
yield last_gas_price

while True:
last_gas_price = min(int(last_gas_price * self.increment), self.max_gas_price)
last_gas_price = min(Wei(last_gas_price * self.increment), self.max_gas_price)
yield last_gas_price


Expand All @@ -88,27 +89,27 @@ class ExponentialScalingStrategy(TimeGasStrategy):
Arguments
---------
initial_gas_price : int
initial_gas_price : Wei
The initial gas price to use in the first transaction
max_gas_price : int
max_gas_price : Wei
The maximum gas price to use
increment : float
Multiplier applied to the previous gas price in order to determine the new gas price
time_duration : int
Number of seconds between transactions
"""

def __init__(self, initial_gas_price: int, max_gas_price: int, time_duration: int = 30):
def __init__(self, initial_gas_price: Wei, max_gas_price: Wei, time_duration: int = 30):
super().__init__(time_duration)
self.initial_gas_price = initial_gas_price
self.max_gas_price = max_gas_price
self.initial_gas_price = Wei(initial_gas_price)
self.max_gas_price = Wei(max_gas_price)

def get_gas_price(self) -> Generator[int, None, None]:
def get_gas_price(self) -> Generator[Wei, None, None]:
last_gas_price = self.initial_gas_price
yield last_gas_price

for i in itertools.count(1):
last_gas_price = int(last_gas_price * 1.1 ** i)
last_gas_price = Wei(last_gas_price * 1.1 ** i)
yield min(last_gas_price, self.max_gas_price)


Expand Down

0 comments on commit 9dbc630

Please sign in to comment.