|
| 1 | +"""Hyperliquid EVM metrics implementation for HTTP endpoints.""" |
| 2 | + |
| 3 | +from common.metric_types import HttpCallLatencyMetricBase |
| 4 | + |
| 5 | + |
| 6 | +class HTTPEthCallLatencyMetric(HttpCallLatencyMetricBase): |
| 7 | + """Collects response time for eth_call simulation.""" |
| 8 | + |
| 9 | + @property |
| 10 | + def method(self) -> str: |
| 11 | + return "eth_call" |
| 12 | + |
| 13 | + @staticmethod |
| 14 | + def get_params_from_state(state_data: dict) -> list: |
| 15 | + """Get eth_call parameters for Wrapped HYPE total supply query.""" |
| 16 | + return [ |
| 17 | + { |
| 18 | + "to": "0x5555555555555555555555555555555555555555", |
| 19 | + "data": "0x18160ddd", |
| 20 | + }, |
| 21 | + "latest", |
| 22 | + ] |
| 23 | + |
| 24 | + |
| 25 | +class HTTPTxReceiptLatencyMetric(HttpCallLatencyMetricBase): |
| 26 | + """Collects latency for transaction receipt retrieval.""" |
| 27 | + |
| 28 | + @property |
| 29 | + def method(self) -> str: |
| 30 | + return "eth_getTransactionReceipt" |
| 31 | + |
| 32 | + @staticmethod |
| 33 | + def validate_state(state_data: dict) -> bool: |
| 34 | + """Validate blockchain state contains transaction hash.""" |
| 35 | + return bool(state_data and state_data.get("tx")) |
| 36 | + |
| 37 | + @staticmethod |
| 38 | + def get_params_from_state(state_data: dict) -> list: |
| 39 | + """Get parameters using transaction hash from state.""" |
| 40 | + return [state_data["tx"]] |
| 41 | + |
| 42 | + |
| 43 | +class HTTPAccBalanceLatencyMetric(HttpCallLatencyMetricBase): |
| 44 | + """Collects latency for account balance queries.""" |
| 45 | + |
| 46 | + @property |
| 47 | + def method(self) -> str: |
| 48 | + return "eth_getBalance" |
| 49 | + |
| 50 | + @staticmethod |
| 51 | + def validate_state(state_data: dict) -> bool: |
| 52 | + """Validates that required block number (hex) exists in state data.""" |
| 53 | + return bool(state_data and state_data.get("old_block")) |
| 54 | + |
| 55 | + @staticmethod |
| 56 | + def get_params_from_state(state_data: dict) -> list: |
| 57 | + """Get parameters with fixed monitoring address.""" |
| 58 | + return ["0xFC1286EeddF81d6955eDAd5C8D99B8Aa32F3D2AA", state_data["old_block"]] |
| 59 | + |
| 60 | + |
| 61 | +class HTTPDebugTraceTxLatencyMetric(HttpCallLatencyMetricBase): |
| 62 | + """Collects latency for transaction tracing.""" |
| 63 | + |
| 64 | + @property |
| 65 | + def method(self) -> str: |
| 66 | + return "debug_traceTransaction" |
| 67 | + |
| 68 | + @staticmethod |
| 69 | + def validate_state(state_data: dict) -> bool: |
| 70 | + """Validate blockchain state contains transaction hash.""" |
| 71 | + return bool(state_data and state_data.get("tx")) |
| 72 | + |
| 73 | + @staticmethod |
| 74 | + def get_params_from_state(state_data: dict) -> list: |
| 75 | + """Get parameters using transaction hash from state.""" |
| 76 | + return [state_data["tx"], {"tracer": "callTracer"}] |
| 77 | + |
| 78 | + |
| 79 | +class HTTPDebugTraceBlockByNumberLatencyMetric(HttpCallLatencyMetricBase): |
| 80 | + """Collects call latency for the `debug_traceBlockByNumber` method.""" |
| 81 | + |
| 82 | + @property |
| 83 | + def method(self) -> str: |
| 84 | + return "debug_traceBlockByNumber" |
| 85 | + |
| 86 | + @staticmethod |
| 87 | + def get_params_from_state(state_data: dict) -> list: |
| 88 | + """Get fixed parameters for latest block tracing.""" |
| 89 | + return ["latest", {"tracer": "callTracer"}] |
| 90 | + |
| 91 | + |
| 92 | +class HTTPBlockNumberLatencyMetric(HttpCallLatencyMetricBase): |
| 93 | + """Collects call latency for the `eth_blockNumber` method.""" |
| 94 | + |
| 95 | + @property |
| 96 | + def method(self) -> str: |
| 97 | + return "eth_blockNumber" |
| 98 | + |
| 99 | + @staticmethod |
| 100 | + def get_params_from_state(state_data: dict) -> list: |
| 101 | + """Get empty parameter list for block number query.""" |
| 102 | + return [] |
| 103 | + |
| 104 | + |
| 105 | +class HTTPGetLogsLatencyMetric(HttpCallLatencyMetricBase): |
| 106 | + """Collects call latency for the eth_getLogs method.""" |
| 107 | + |
| 108 | + @property |
| 109 | + def method(self) -> str: |
| 110 | + return "eth_getLogs" |
| 111 | + |
| 112 | + @staticmethod |
| 113 | + def get_params_from_state(state_data: dict) -> list: |
| 114 | + """Get parameters for USDC transfer logs from recent block range.""" |
| 115 | + from_block_hex = state_data["old_block"] |
| 116 | + from_block_int = int(from_block_hex, 16) |
| 117 | + to_block_int: int = max(0, from_block_int + 100) |
| 118 | + to_block_hex: str = hex(to_block_int) |
| 119 | + |
| 120 | + return [ |
| 121 | + { |
| 122 | + "fromBlock": from_block_hex, |
| 123 | + "toBlock": to_block_hex, |
| 124 | + "address": "0x5555555555555555555555555555555555555555", # Wrapped HYPE |
| 125 | + "topics": [ |
| 126 | + " 0x7fcf532c15f0a6db0bd6d0e038bea71d30d808c7d98cb3bf7268a95bf5081b65" # Withdrawal event |
| 127 | + ], |
| 128 | + } |
| 129 | + ] |
0 commit comments