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

Add Mev Blocker kickbacks alert #81

Merged
merged 7 commits into from
Nov 6, 2023
Merged
Show file tree
Hide file tree
Changes from all 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
8 changes: 7 additions & 1 deletion src/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,14 @@
# cap parameter, per CIP-20, measured in ETH
CAP_PARAMETER = 0.01

# requests
# threshold parameter to generate an alert when receiving kickbacks
harisang marked this conversation as resolved.
Show resolved Hide resolved
KICKBACKS_ALERT_THRESHOLD = 0.03

# relevant addresses
SETTLEMENT_CONTRACT_ADDRESS = "0x9008D19f58AAbD9eD0D60971565AA8510560ab41"
MEV_BLOCKER_KICKBACKS_ADDRESS = "0xCe91228789B57DEb45e66Ca10Ff648385fE7093b"

# requests
REQUEST_TIMEOUT = 5
SUCCESS_CODE = 200
FAIL_CODE = 404
Expand Down
4 changes: 4 additions & 0 deletions src/daemon.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@
from src.monitoring_tests.cost_coverage_per_solver_test import (
CostCoveragePerSolverTest,
)
from src.monitoring_tests.mev_blocker_kickbacks_test import (
MEVBlockerRefundsMonitoringTest,
)
from src.constants import SLEEP_TIME_IN_SEC


Expand All @@ -40,6 +43,7 @@ def main() -> None:
PartialFillFeeQuoteTest(),
PartialFillCostCoverageTest(),
CostCoveragePerSolverTest(),
MEVBlockerRefundsMonitoringTest(),
]

start_block: Optional[int] = None
Expand Down
50 changes: 50 additions & 0 deletions src/monitoring_tests/mev_blocker_kickbacks_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
"""
Checks whether there were any kickbacks received after each settlement.
It generates an alert when kickbacks due to a specific settlement are
more than KICKBACKS_ALERT_THRESHOLD
"""
# pylint: disable=logging-fstring-interpolation
from src.monitoring_tests.base_test import BaseTest
from src.apis.web3api import Web3API
from src.constants import (
MEV_BLOCKER_KICKBACKS_ADDRESS,
KICKBACKS_ALERT_THRESHOLD,
)


class MEVBlockerRefundsMonitoringTest(BaseTest):
"""
This test checks whether there was any MEV Blocker kicback, and
generates a log/alert if this is the case.
"""

def __init__(self) -> None:
super().__init__()
self.web3_api = Web3API()

def run(self, tx_hash: str) -> bool:
"""
Wrapper function for the whole test. Checks if kickback is more than
KICKBACK_ETH_THRESHOLD, in which case it generates an alert.
"""
block_number = self.web3_api.get_tx_block_number(tx_hash)
if block_number is None:
return False

total_eth_kickbacks = self.web3_api.get_eth_transfers_by_block_range(
block_number, block_number, MEV_BLOCKER_KICKBACKS_ADDRESS
)
if total_eth_kickbacks is None:
return False
log_output = "\t".join(
[
"MEV Blocker kickbacks test:",
f"Tx Hash: {tx_hash}",
f"Kickback: {total_eth_kickbacks:.5f}ETH",
]
)
if total_eth_kickbacks >= KICKBACKS_ALERT_THRESHOLD:
self.alert(log_output)
else:
self.logger.info(log_output)
return True
Loading