Skip to content

Commit 937363c

Browse files
harisangfhenneke
andauthored
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>
1 parent ee5e4c9 commit 937363c

File tree

3 files changed

+61
-1
lines changed

3 files changed

+61
-1
lines changed

src/constants.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,14 @@
2525
# cap parameter, per CIP-20, measured in ETH
2626
CAP_PARAMETER = 0.01
2727

28-
# requests
28+
# threshold parameter to generate an alert when receiving kickbacks
29+
KICKBACKS_ALERT_THRESHOLD = 0.03
30+
31+
# relevant addresses
2932
SETTLEMENT_CONTRACT_ADDRESS = "0x9008D19f58AAbD9eD0D60971565AA8510560ab41"
33+
MEV_BLOCKER_KICKBACKS_ADDRESS = "0xCe91228789B57DEb45e66Ca10Ff648385fE7093b"
34+
35+
# requests
3036
REQUEST_TIMEOUT = 5
3137
SUCCESS_CODE = 200
3238
FAIL_CODE = 404

src/daemon.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@
2424
from src.monitoring_tests.cost_coverage_per_solver_test import (
2525
CostCoveragePerSolverTest,
2626
)
27+
from src.monitoring_tests.mev_blocker_kickbacks_test import (
28+
MEVBlockerRefundsMonitoringTest,
29+
)
2730
from src.constants import SLEEP_TIME_IN_SEC
2831

2932

@@ -40,6 +43,7 @@ def main() -> None:
4043
PartialFillFeeQuoteTest(),
4144
PartialFillCostCoverageTest(),
4245
CostCoveragePerSolverTest(),
46+
MEVBlockerRefundsMonitoringTest(),
4347
]
4448

4549
start_block: Optional[int] = None
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
"""
2+
Checks whether there were any kickbacks received after each settlement.
3+
It generates an alert when kickbacks due to a specific settlement are
4+
more than KICKBACKS_ALERT_THRESHOLD
5+
"""
6+
# pylint: disable=logging-fstring-interpolation
7+
from src.monitoring_tests.base_test import BaseTest
8+
from src.apis.web3api import Web3API
9+
from src.constants import (
10+
MEV_BLOCKER_KICKBACKS_ADDRESS,
11+
KICKBACKS_ALERT_THRESHOLD,
12+
)
13+
14+
15+
class MEVBlockerRefundsMonitoringTest(BaseTest):
16+
"""
17+
This test checks whether there was any MEV Blocker kicback, and
18+
generates a log/alert if this is the case.
19+
"""
20+
21+
def __init__(self) -> None:
22+
super().__init__()
23+
self.web3_api = Web3API()
24+
25+
def run(self, tx_hash: str) -> bool:
26+
"""
27+
Wrapper function for the whole test. Checks if kickback is more than
28+
KICKBACK_ETH_THRESHOLD, in which case it generates an alert.
29+
"""
30+
block_number = self.web3_api.get_tx_block_number(tx_hash)
31+
if block_number is None:
32+
return False
33+
34+
total_eth_kickbacks = self.web3_api.get_eth_transfers_by_block_range(
35+
block_number, block_number, MEV_BLOCKER_KICKBACKS_ADDRESS
36+
)
37+
if total_eth_kickbacks is None:
38+
return False
39+
log_output = "\t".join(
40+
[
41+
"MEV Blocker kickbacks test:",
42+
f"Tx Hash: {tx_hash}",
43+
f"Kickback: {total_eth_kickbacks:.5f}ETH",
44+
]
45+
)
46+
if total_eth_kickbacks >= KICKBACKS_ALERT_THRESHOLD:
47+
self.alert(log_output)
48+
else:
49+
self.logger.info(log_output)
50+
return True

0 commit comments

Comments
 (0)