Repository: MystenLabs/sui
File: crates/sui-bridge/src/node.rs (Rust)

Code before:
            eth_provider.clone(),
            vault_address,
            wbtc_address,
            VaultAsset::WBTC,
            watchdog_metrics.wbtc_vault_balance.clone(),
        )
        .await
        .unwrap_or_else(|e| panic!("Failed to create wbtc vault balance: {}", e));

        let lbtc_vault_balance = if !lbtc_address.is_zero() {
            Some(
                EthereumVaultBalance::new(
                    eth_provider.clone(),
                    vault_address,
                    lbtc_address,
                    VaultAsset::LBTC,
                    watchdog_metrics.lbtc_vault_balance.clone(),
                )
                .await
                .unwrap_or_else(|e| panic!("Failed to create lbtc vault balance: {}", e)),
            )
        } else {
            None
        };

        let eth_bridge_status = EthBridgeStatus::new(
            eth_provider,
            eth_bridge_proxy_address,
            watchdog_metrics.eth_bridge_paused.clone(),
        );

        let sui_bridge_status = SuiBridgeStatus::new(
            sui_client.clone(),
            watchdog_metrics.sui_bridge_paused.clone(),
        );

        let mut obs: Vec<Box<dyn Observable + Send + Sync>> = vec![
            Box::new(eth_vault_balance),
            Box::new(usdt_vault_balance),
            Box::new(wbtc_vault_balance),
            Box::new(eth_bridge_status),
            Box::new(sui_bridge_status),
        ];

        if let Some(balance) = lbtc_vault_balance {
            obs.push(Box::new(balance));
        }
        obs
    } else {
        // When vault addresses are zero (storage layout mismatch), only monitor bridge status
        let eth_bridge_status = EthBridgeStatus::new(

Review comment (refactor):
Getting `eth_bridge_status` and `sui_bridge_status` is duplicated across both branches, can factor out.

Code after:
        .await
        .unwrap_or_else(|e| panic!("Failed to create eth vault balance: {}", e));

        let usdt_vault_balance = EthereumVaultBalance::new(
            eth_provider.clone(),
            vault_address,
            usdt_address,
            VaultAsset::USDT,
            watchdog_metrics.usdt_vault_balance.clone(),
        )
        .await
        .unwrap_or_else(|e| panic!("Failed to create usdt vault balance: {}", e));

        let wbtc_vault_balance = EthereumVaultBalance::new(
            eth_provider.clone(),
            vault_address,
            wbtc_address,
            VaultAsset::WBTC,
            watchdog_metrics.wbtc_vault_balance.clone(),
        )
        .await
        .unwrap_or_else(|e| panic!("Failed to create wbtc vault balance: {}", e));

        observables.push(Box::new(eth_vault_balance));
        observables.push(Box::new(usdt_vault_balance));
        observables.push(Box::new(wbtc_vault_balance));

        if !lbtc_address.is_zero() {
            let lbtc_vault_balance = EthereumVaultBalance::new(
                eth_provider,
                vault_address,
                lbtc_address,
                VaultAsset::LBTC,
                watchdog_metrics.lbtc_vault_balance.clone(),
            )
            .await
            .unwrap_or_else(|e| panic!("Failed to create lbtc vault balance: {}", e));
            observables.push(Box::new(lbtc_vault_balance));
        }
    }

    if let Some(watchdog_config) = watchdog_config
        && !watchdog_config.total_supplies.is_empty()
    {
        let total_supplies = TotalSupplies::new(
            Arc::new(sui_client.jsonrpc_client().clone()),
            watchdog_config.total_supplies,
            watchdog_metrics.total_supplies.clone(),
        );
        observables.push(Box::new(total_supplies));
    }