Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Gas strategy with addendum #285

Open
wants to merge 5 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,21 @@
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.5.0 # Use the latest stable version
hooks:
- id: trailing-whitespace
- id: end-of-file-fixer
- id: check-yaml

- repo: local
hooks:
- id: poetry-pytest-unit
name: Run pytest unit tests with Poetry
entry: poetry run pytest -m unit
language: system
pass_filenames: false
always_run: true
stages: [commit]

- repo: https://github.com/astral-sh/ruff-pre-commit
# Ruff version.
rev: v0.4.4
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ Unvetting is the proces of decreasing approved depositable signing keys.
| GAS_FEE_PERCENTILE_1 | 20 | Percentile for first recommended fee calculation |
| GAS_FEE_PERCENTILE_DAYS_HISTORY_1 | 1 | Percentile for first recommended calculates from N days of the fee history |
| GAS_PRIORITY_FEE_PERCENTILE | 25 | Priority transaction will be N percentile from priority fees in last block (min MIN_PRIORITY_FEE - max MAX_PRIORITY_FEE) |
| GAS_ADDENDUM | 6 | Number of weis to add to the GAS_PRIORITY_FEE_PERCENTILE percentile value |
F4ever marked this conversation as resolved.
Show resolved Hide resolved
| MAX_BUFFERED_ETHERS | 5000 ether | Maximum amount of ETH in the buffer, after which the bot deposits at any gas |
| PROMETHEUS_PORT | 9000 | Port with metrics server |
| PROMETHEUS_PREFIX | depositor_bot | Prefix for the metrics |
Expand Down
2 changes: 1 addition & 1 deletion src/blockchain/deposit_strategy/gas_price_calculator.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def get_pending_base_fee(self) -> Wei:

def get_recommended_gas_fee(self) -> Wei:
gas_history = self._fetch_gas_fee_history(variables.GAS_FEE_PERCENTILE_DAYS_HISTORY_1)
return Wei(int(numpy.percentile(gas_history, variables.GAS_FEE_PERCENTILE_1)))
return Wei(int(numpy.percentile(gas_history, variables.GAS_FEE_PERCENTILE_1)) + variables.GAS_ADDENDUM)

def _fetch_gas_fee_history(self, days: int) -> list[int]:
latest_block_num = self.w3.eth.get_block('latest')['number']
Expand Down
12 changes: 12 additions & 0 deletions src/variables.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,18 @@
_env_whitelist = os.getenv('DEPOSIT_MODULES_WHITELIST', '').strip()
DEPOSIT_MODULES_WHITELIST = [int(module_id) for module_id in _env_whitelist.split(',')] if _env_whitelist else []

"""
GAS_ADDENDUM is used to increase number of deposits during to calm market. The value should be increased if bot
wants to deposit more often.
The value 6 was calculated this way:
profit_per_val = 32 * 10**9 * 0.03(APR) / 12 / 30
gas_per_validator = 112176
x = profit_per_val / gas_per_validator

x / 4(we assume that chances of significant gas drop during 8 hours are low)
"""
GAS_ADDENDUM = int(os.getenv('GAS_ADDENDUM', 6))

# All non-private env variables to the logs in main
PUBLIC_ENV_VARS = {
'LIDO_LOCATOR': LIDO_LOCATOR,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,10 @@ def test_get_recommended_gas_fee(gas_price_calculator):
variables.GAS_FEE_PERCENTILE_DAYS_HISTORY_1 = 1
variables.GAS_FEE_PERCENTILE_1 = 50

assert gas_price_calculator.get_recommended_gas_fee() == 5
assert gas_price_calculator.get_recommended_gas_fee() == 11

variables.GAS_FEE_PERCENTILE_1 = 30
assert gas_price_calculator.get_recommended_gas_fee() == 3
assert gas_price_calculator.get_recommended_gas_fee() == 9


@pytest.mark.integration
Expand Down
Loading