-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Mev Blocker kickbacks alert (#81)
This PR adds a test that monitors for MEV Blocker kickbacks, and generates an alert if a large enough kickback is received. This is a follow-up PR on PR #79 --------- Co-authored-by: Felix Henneke <felix.henneke@protonmail.com>
- Loading branch information
Showing
3 changed files
with
61 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |