From f9ba048e183e5df027885755bbccd3a2c1427431 Mon Sep 17 00:00:00 2001 From: evgeny-stakewise <123374581+evgeny-stakewise@users.noreply.github.com> Date: Tue, 12 Nov 2024 15:00:40 +0300 Subject: [PATCH] Add auto relayer endpoint (#426) --- src/commands/start_api.py | 14 +++++++++++++- src/config/networks.py | 5 +++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/src/commands/start_api.py b/src/commands/start_api.py index 8918375f..899919e9 100644 --- a/src/commands/start_api.py +++ b/src/commands/start_api.py @@ -11,7 +11,7 @@ from src.common.utils import log_verbose from src.common.validators import validate_eth_address from src.common.vault_config import VaultConfig -from src.config.networks import AVAILABLE_NETWORKS +from src.config.networks import AVAILABLE_NETWORKS, NETWORKS from src.config.settings import ( DEFAULT_MAX_FEE_PER_GAS_GWEI, DEFAULT_METRICS_HOST, @@ -26,6 +26,10 @@ logger = logging.getLogger(__name__) +# Special value used to dynamically determine option value +AUTO = 'AUTO' + + @click.option( '--data-dir', default=str(Path.home() / '.stakewise'), @@ -183,6 +187,7 @@ help='Relayer endpoint.', prompt='Enter the relayer endpoint', envvar='RELAYER_ENDPOINT', + default=AUTO, ) @click.command(help='Start operator service') # pylint: disable-next=too-many-arguments,too-many-locals @@ -214,6 +219,13 @@ def start_api( vault_config.load() network = vault_config.network + if relayer_endpoint == AUTO and relayer_type == RelayerTypes.DVT: + network_config = NETWORKS[network] + relayer_endpoint = network_config.DEFAULT_DVT_RELAYER_ENDPOINT + + if relayer_endpoint == AUTO and relayer_type == RelayerTypes.DEFAULT: + raise click.ClickException('Relayer endpoint must be specified for default relayer type') + validators_registration_mode = ValidatorsRegistrationMode.API settings.set( diff --git a/src/config/networks.py b/src/config/networks.py index 9a39f9db..7c020668 100644 --- a/src/config/networks.py +++ b/src/config/networks.py @@ -44,6 +44,7 @@ class NetworkConfig: STAKEWISE_API_URL: str RATED_API_URL: str CONFIG_UPDATE_EVENT_BLOCK: BlockNumber + DEFAULT_DVT_RELAYER_ENDPOINT: str @property def SHAPELLA_FORK(self) -> ConsensusFork: @@ -109,6 +110,7 @@ def IS_SUPPORT_V2_MIGRATION(self) -> bool: STAKEWISE_API_URL='https://mainnet-api.stakewise.io/graphql', RATED_API_URL='https://api.rated.network', CONFIG_UPDATE_EVENT_BLOCK=BlockNumber(18470104), + DEFAULT_DVT_RELAYER_ENDPOINT='https://mainnet-dvt-relayer.stakewise.io', ), HOLESKY: NetworkConfig( CHAIN_ID=17000, @@ -154,6 +156,7 @@ def IS_SUPPORT_V2_MIGRATION(self) -> bool: STAKEWISE_API_URL='https://holesky-api.stakewise.io/graphql', RATED_API_URL='https://api.rated.network', CONFIG_UPDATE_EVENT_BLOCK=BlockNumber(215397), + DEFAULT_DVT_RELAYER_ENDPOINT='https://holesky-dvt-relayer.stakewise.io', ), GNOSIS: NetworkConfig( CHAIN_ID=100, @@ -201,6 +204,7 @@ def IS_SUPPORT_V2_MIGRATION(self) -> bool: STAKEWISE_API_URL='https://gnosis-api.stakewise.io/graphql', RATED_API_URL='https://api.rated.network', CONFIG_UPDATE_EVENT_BLOCK=BlockNumber(34778569), + DEFAULT_DVT_RELAYER_ENDPOINT='gnosis-dvt-relayer.stakewise.io', ), CHIADO: NetworkConfig( CHAIN_ID=10200, @@ -246,5 +250,6 @@ def IS_SUPPORT_V2_MIGRATION(self) -> bool: STAKEWISE_API_URL='https://chiado-api.stakewise.io/graphql', RATED_API_URL='https://api.rated.network', CONFIG_UPDATE_EVENT_BLOCK=BlockNumber(10627606), + DEFAULT_DVT_RELAYER_ENDPOINT='chiado-dvt-relayer.stakewise.io', ), }