Skip to content

Commit

Permalink
Del max_priority_fee_per_gas_gwei setting
Browse files Browse the repository at this point in the history
  • Loading branch information
evgeny-stakewise committed Mar 10, 2024
1 parent 5188e51 commit 2194641
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 27 deletions.
8 changes: 0 additions & 8 deletions src/commands/start.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,6 @@
f'Default is {DEFAULT_MAX_FEE_PER_GAS_GWEI} Gwei.',
default=DEFAULT_MAX_FEE_PER_GAS_GWEI,
)
@click.option(
'--max-priority-fee-per-gas-gwei',
type=int,
envvar='MAX_PRIORITY_FEE_PER_GAS_GWEI',
help='Maximum priority fee per gas for transactions.',
)
@click.option(
'--hot-wallet-password-file',
type=click.Path(exists=True, file_okay=True, dir_okay=False),
Expand Down Expand Up @@ -222,7 +216,6 @@ def start(
hot_wallet_file: str | None,
hot_wallet_password_file: str | None,
max_fee_per_gas_gwei: int,
max_priority_fee_per_gas_gwei: int | None,
database_dir: str | None,
pool_size: int | None,
) -> None:
Expand Down Expand Up @@ -252,7 +245,6 @@ def start(
hot_wallet_file=hot_wallet_file,
hot_wallet_password_file=hot_wallet_password_file,
max_fee_per_gas_gwei=max_fee_per_gas_gwei,
max_priority_fee_per_gas_gwei=max_priority_fee_per_gas_gwei,
database_dir=database_dir,
log_level=log_level,
log_format=log_format,
Expand Down
8 changes: 0 additions & 8 deletions src/commands/start_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,6 @@
f'Default is {DEFAULT_MAX_FEE_PER_GAS_GWEI} Gwei.',
default=DEFAULT_MAX_FEE_PER_GAS_GWEI,
)
@click.option(
'--max-priority-fee-per-gas-gwei',
type=int,
envvar='MAX_PRIORITY_FEE_PER_GAS_GWEI',
help='Maximum priority fee per gas for transactions.',
)
@click.option(
'--hot-wallet-password-file',
type=click.Path(exists=True, file_okay=True, dir_okay=False),
Expand Down Expand Up @@ -193,7 +187,6 @@ def start_api(
hot_wallet_file: str | None,
hot_wallet_password_file: str | None,
max_fee_per_gas_gwei: int,
max_priority_fee_per_gas_gwei: int | None,
database_dir: str | None,
api_host: str,
api_port: int,
Expand All @@ -220,7 +213,6 @@ def start_api(
hot_wallet_file=hot_wallet_file,
hot_wallet_password_file=hot_wallet_password_file,
max_fee_per_gas_gwei=max_fee_per_gas_gwei,
max_priority_fee_per_gas_gwei=max_priority_fee_per_gas_gwei,
database_dir=database_dir,
log_level=log_level,
log_format=log_format,
Expand Down
30 changes: 22 additions & 8 deletions src/common/execution.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,20 +153,34 @@ async def get_oracles() -> Oracles:
async def get_tx_params() -> TxParams:
tx_params: TxParams = {}

if settings.max_priority_fee_per_gas_gwei:
max_priority_fee_per_gas = Web3.to_wei(settings.max_priority_fee_per_gas_gwei, 'gwei')
max_priority_fee_per_gas = await _calc_priority_fee()

# Reference: `_max_fee_per_gas` in web3/_utils/async_transactions.py
block = await execution_client.eth.get_block('latest')
max_fee_per_gas = Wei(max_priority_fee_per_gas + (2 * block['baseFeePerGas']))
# Reference: `_max_fee_per_gas` in web3/_utils/async_transactions.py
block = await execution_client.eth.get_block('latest')
max_fee_per_gas = Wei(max_priority_fee_per_gas + (2 * block['baseFeePerGas']))

tx_params['maxPriorityFeePerGas'] = max_priority_fee_per_gas
tx_params['maxFeePerGas'] = max_fee_per_gas
logger.debug('tx_params %s', tx_params)
tx_params['maxPriorityFeePerGas'] = max_priority_fee_per_gas
tx_params['maxFeePerGas'] = max_fee_per_gas
logger.debug('tx_params %s', tx_params)

return tx_params


async def _calc_priority_fee() -> Wei:
"""
reference: "high" priority value from https://etherscan.io/gastracker
"""
num_blocks = 10
percentile = 80.0
history = await execution_client.eth.fee_history(num_blocks, 'pending', [percentile])
validator_rewards = [r[0] for r in history['reward']]
logger.info(
'validator_rewards %s', sorted([round(Web3.from_wei(r, 'gwei')) for r in validator_rewards])
)
mean_reward = int(sum(validator_rewards) / len(validator_rewards))
return Wei(mean_reward)


async def check_gas_price(custom_priority_fee: bool = False) -> bool:
if custom_priority_fee:
# custom gas-price logic
Expand Down
3 changes: 0 additions & 3 deletions src/config/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ class Settings(metaclass=Singleton):
hot_wallet_file: Path
hot_wallet_password_file: Path
max_fee_per_gas_gwei: int
max_priority_fee_per_gas_gwei: int | None
database: Path

log_level: str
Expand Down Expand Up @@ -92,7 +91,6 @@ def set(
metrics_port: int = DEFAULT_METRICS_PORT,
metrics_host: str = DEFAULT_METRICS_HOST,
max_fee_per_gas_gwei: int = DEFAULT_MAX_FEE_PER_GAS_GWEI,
max_priority_fee_per_gas_gwei: int | None = None,
deposit_data_file: str | None = None,
keystores_dir: str | None = None,
keystores_password_file: str | None = None,
Expand Down Expand Up @@ -123,7 +121,6 @@ def set(
self.metrics_host = metrics_host
self.metrics_port = metrics_port
self.max_fee_per_gas_gwei = max_fee_per_gas_gwei
self.max_priority_fee_per_gas_gwei = max_priority_fee_per_gas_gwei

self.deposit_data_file = (
Path(deposit_data_file) if deposit_data_file else vault_dir / 'deposit_data.json'
Expand Down

0 comments on commit 2194641

Please sign in to comment.