cargo-tangle 0.5.0-alpha.10

A command-line tool to create and deploy blueprints on Tangle Network
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
use crate::command::deploy::definition::{
    BinaryArtifactSpec, BlueprintDefinitionInput, DefinitionOverrides, FetcherKind,
    GithubArtifactSpec, NativeSourceOverride, RemoteArtifactSpec, SourceSummary,
    SourceSummaryDetails, load_blueprint_definition,
};
use crate::command::run::tangle::run_blueprint;
use crate::command::signer::KEYSTORE_PATH_ENV;
use crate::command::tangle::{DevnetStack, SpawnMethod, parse_address, run_opts_from_stack};
use crate::settings::load_protocol_settings;
use alloy_primitives::Address;
use blueprint_client_tangle::{
    TangleClient, TangleClientConfig, TangleSettings, TransactionResult,
};
use blueprint_runner::config::Protocol;
use blueprint_runner::tangle::config::TangleProtocolSettings;
use clap::{Args, ValueEnum};
use color_eyre::eyre::{Result, eyre};
use std::env;
use std::fmt;
use std::path::PathBuf;
use std::time::Duration;
use url::Url;

#[derive(Args, Debug, Clone)]
pub struct TangleDeployArgs {
    /// Target network for the deployment.
    #[arg(long, value_enum, default_value_t = DeploymentNetwork::Devnet)]
    pub network: DeploymentNetwork,
    /// Optional settings file with Tangle EVM configuration.
    #[arg(long, value_name = "FILE", default_value = "./settings.env")]
    pub settings_file: PathBuf,
    /// Stream Anvil stdout/stderr for debugging.
    #[arg(long)]
    pub include_anvil_logs: bool,
    /// Allow unchecked attestations when running the manager.
    #[arg(long)]
    pub allow_unchecked_attestations: bool,
    /// Preferred runtime for the service.
    #[arg(long, value_enum, default_value_t = SpawnMethod::Vm)]
    pub spawn_method: SpawnMethod,
    /// Auto-shutdown the devnet run after the specified number of seconds.
    #[arg(long, value_name = "SECONDS")]
    pub exit_after_seconds: Option<u64>,
    /// Path to the blueprint definition file (JSON/YAML/TOML) when targeting non-devnet networks.
    #[arg(long, value_name = "FILE")]
    pub definition: Option<PathBuf>,
    /// Override the first native source with CLI-provided metadata.
    #[arg(long, value_enum)]
    pub artifact_source: Option<NativeArtifactSource>,
    /// Entry point for the overridden native source.
    #[arg(long)]
    pub artifact_entrypoint: Option<String>,
    /// Owner for GitHub artifact overrides.
    #[arg(long)]
    pub github_owner: Option<String>,
    /// Repository for GitHub artifact overrides.
    #[arg(long)]
    pub github_repo: Option<String>,
    /// Tag for GitHub artifact overrides.
    #[arg(long)]
    pub github_tag: Option<String>,
    /// Distribution manifest URL for HTTP/IPFS artifact overrides.
    #[arg(long)]
    pub remote_dist_url: Option<String>,
    /// Archive URL for HTTP/IPFS artifact overrides.
    #[arg(long)]
    pub remote_archive_url: Option<String>,
    /// Binary descriptors in the form NAME:ARCH:OS:SHA256[:BLAKE3].
    #[arg(long = "artifact-binary", value_name = "NAME:ARCH:OS:SHA256[:BLAKE3]")]
    pub artifact_binaries: Vec<String>,
    /// Override the HTTP RPC endpoint (non-devnet).
    #[arg(long)]
    pub http_rpc_url: Option<Url>,
    /// Override the WebSocket RPC endpoint (non-devnet).
    #[arg(long)]
    pub ws_rpc_url: Option<Url>,
    /// Override the keystore path (non-devnet).
    #[arg(long)]
    pub keystore_path: Option<PathBuf>,
    /// Override the Tangle contract address (non-devnet).
    #[arg(long)]
    pub tangle_contract: Option<String>,
    /// Override the MultiAssetDelegation staking contract address (non-devnet).
    #[arg(long = "staking-contract")]
    pub staking_contract: Option<String>,
    /// Override the OperatorStatusRegistry contract address (non-devnet).
    #[arg(long)]
    pub status_registry_contract: Option<String>,
}

impl TangleDeployArgs {
    fn definition_overrides(&self) -> Result<Option<DefinitionOverrides>> {
        let override_requested = self.artifact_source.is_some()
            || self.artifact_entrypoint.is_some()
            || !self.artifact_binaries.is_empty()
            || self.github_owner.is_some()
            || self.github_repo.is_some()
            || self.github_tag.is_some()
            || self.remote_dist_url.is_some()
            || self.remote_archive_url.is_some();

        if !override_requested {
            return Ok(None);
        }

        let fetcher = self.artifact_source.ok_or_else(|| {
            eyre!("--artifact-source must be provided when overriding native metadata")
        })?;

        let entrypoint = self
            .artifact_entrypoint
            .as_ref()
            .ok_or_else(|| {
                eyre!("--artifact-entrypoint is required when overriding native metadata")
            })?
            .trim()
            .to_string();

        if entrypoint.is_empty() {
            return Err(eyre!("--artifact-entrypoint must not be empty"));
        }

        if self.artifact_binaries.is_empty() {
            return Err(eyre!(
                "at least one --artifact-binary must be specified when overriding native metadata"
            ));
        }

        let binaries = self
            .artifact_binaries
            .iter()
            .map(|raw| parse_cli_binary(raw))
            .collect::<Result<Vec<_>>>()?;

        let override_spec = match fetcher {
            NativeArtifactSource::Github => {
                let owner = self
                    .github_owner
                    .as_ref()
                    .ok_or_else(|| eyre!("--github-owner is required for GitHub artifacts"))?
                    .clone();
                let repo = self
                    .github_repo
                    .as_ref()
                    .ok_or_else(|| eyre!("--github-repo is required for GitHub artifacts"))?
                    .clone();
                let tag = self
                    .github_tag
                    .as_ref()
                    .ok_or_else(|| eyre!("--github-tag is required for GitHub artifacts"))?
                    .clone();

                NativeSourceOverride::github(
                    entrypoint,
                    GithubArtifactSpec {
                        owner,
                        repo,
                        tag,
                        binaries,
                    },
                )
            }
            NativeArtifactSource::Http | NativeArtifactSource::Ipfs => {
                let dist_url = self
                    .remote_dist_url
                    .as_ref()
                    .ok_or_else(|| eyre!("--remote-dist-url is required for HTTP/IPFS artifacts"))?
                    .clone();
                let archive_url = self
                    .remote_archive_url
                    .as_ref()
                    .ok_or_else(|| {
                        eyre!("--remote-archive-url is required for HTTP/IPFS artifacts")
                    })?
                    .clone();

                NativeSourceOverride::remote(
                    entrypoint,
                    fetcher.to_fetcher_kind(),
                    RemoteArtifactSpec {
                        dist_url,
                        archive_url,
                        binaries,
                    },
                )
            }
        };

        let mut overrides = DefinitionOverrides::default();
        overrides.push_native(override_spec);
        Ok(Some(overrides))
    }
}

pub async fn execute(args: TangleDeployArgs) -> Result<()> {
    let protocol_settings = load_protocol_settings(Protocol::Tangle, &args.settings_file)
        .map_err(|e| eyre!(e.to_string()))?;
    let tangle_settings = protocol_settings
        .tangle()
        .map_err(|e| eyre!("failed to load Tangle settings: {e}"))?;
    let tangle_settings = tangle_settings.clone();

    let plan = match args.network {
        DeploymentNetwork::Devnet => {
            let stack = DevnetStack::spawn(args.include_anvil_logs).await?;
            DeploymentPlan::Devnet(DevnetDeployment::new(
                stack,
                tangle_settings,
                args.allow_unchecked_attestations,
                args.spawn_method,
                args.exit_after_seconds.map(Duration::from_secs),
            ))
        }
        DeploymentNetwork::Testnet | DeploymentNetwork::Mainnet => {
            let definition_path = args
                .definition
                .as_ref()
                .ok_or_else(|| eyre!("--definition is required for testnet/mainnet deployments"))?;
            let overrides = args.definition_overrides()?;
            let loaded = load_blueprint_definition(definition_path, overrides.as_ref())?;
            print_source_summaries(&loaded.summaries);
            let remote = NetworkDeploymentConfig::from_args(&args, &tangle_settings)?;
            DeploymentPlan::Network(NetworkDeployment::new(
                args.network,
                remote,
                loaded.definition,
            ))
        }
    };

    let outcome = plan.execute().await?;
    log_deployment_summary(&outcome);
    Ok(())
}

#[derive(Clone, Copy, Debug, Eq, PartialEq, ValueEnum)]
pub enum DeploymentNetwork {
    Devnet,
    Testnet,
    Mainnet,
}

impl fmt::Display for DeploymentNetwork {
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        match self {
            DeploymentNetwork::Devnet => write!(f, "devnet"),
            DeploymentNetwork::Testnet => write!(f, "testnet"),
            DeploymentNetwork::Mainnet => write!(f, "mainnet"),
        }
    }
}

#[derive(Clone, Copy, Debug, Eq, PartialEq, ValueEnum)]
pub enum NativeArtifactSource {
    Github,
    Http,
    Ipfs,
}

impl NativeArtifactSource {
    fn to_fetcher_kind(self) -> FetcherKind {
        match self {
            NativeArtifactSource::Github => FetcherKind::Github,
            NativeArtifactSource::Http => FetcherKind::Http,
            NativeArtifactSource::Ipfs => FetcherKind::Ipfs,
        }
    }
}

#[derive(Debug)]
struct DeploymentOutcome {
    network: DeploymentNetwork,
    blueprint_id: u64,
    service_id: Option<u64>,
    transactions: Vec<TransactionResult>,
}

impl DeploymentOutcome {
    fn new(
        network: DeploymentNetwork,
        blueprint_id: u64,
        service_id: Option<u64>,
        transactions: Vec<TransactionResult>,
    ) -> Self {
        Self {
            network,
            blueprint_id,
            service_id,
            transactions,
        }
    }
}

enum DeploymentPlan {
    Devnet(DevnetDeployment),
    Network(NetworkDeployment),
}

impl DeploymentPlan {
    async fn execute(self) -> Result<DeploymentOutcome> {
        match self {
            DeploymentPlan::Devnet(plan) => plan.execute().await,
            DeploymentPlan::Network(plan) => plan.execute().await,
        }
    }
}

fn print_source_summaries(summaries: &[SourceSummary]) {
    if summaries.is_empty() {
        println!("No blueprint sources were detected in the definition.");
        return;
    }

    println!("\nBlueprint sources:");
    for summary in summaries {
        let fetcher = summary
            .fetcher
            .map(|kind| kind.to_string())
            .unwrap_or_else(|| "n/a".into());
        let entrypoint = summary
            .entrypoint
            .as_deref()
            .filter(|value| !value.is_empty())
            .unwrap_or("n/a");
        println!(
            "  [{}] kind: {}, fetcher: {fetcher}, entrypoint: {entrypoint}",
            summary.index + 1,
            summary.kind
        );

        match &summary.details {
            SourceSummaryDetails::Container {
                registry,
                image,
                tag,
            } => {
                println!("      image: {registry}/{image}:{tag}");
            }
            SourceSummaryDetails::Native { has_testing } => {
                if *has_testing {
                    println!("      includes testing harness");
                }
            }
            SourceSummaryDetails::Wasm { runtime } => {
                println!("      runtime: {:?}", runtime);
            }
        }
    }
    println!();
}

fn parse_cli_binary(value: &str) -> Result<BinaryArtifactSpec> {
    let mut parts = value.split(':').collect::<Vec<_>>();
    if parts.len() < 4 || parts.len() > 5 {
        return Err(eyre!(
            "invalid --artifact-binary `{value}`; expected NAME:ARCH:OS:SHA256[:BLAKE3]"
        ));
    }
    let blake3 = if parts.len() == 5 {
        Some(parts.pop().unwrap().to_string())
    } else {
        None
    };
    let sha256 = parts.pop().unwrap().to_string();
    let os = parts.pop().unwrap().to_string();
    let arch = parts.pop().unwrap().to_string();
    let name = parts.pop().unwrap().to_string();
    Ok(BinaryArtifactSpec {
        name,
        arch,
        os,
        sha256,
        blake3,
    })
}

#[derive(Debug)]
struct DevnetDeployment {
    stack: DevnetStack,
    settings: TangleProtocolSettings,
    allow_unchecked_attestations: bool,
    spawn_method: SpawnMethod,
    shutdown_after: Option<Duration>,
}

impl DevnetDeployment {
    fn new(
        stack: DevnetStack,
        settings: TangleProtocolSettings,
        allow_unchecked_attestations: bool,
        spawn_method: SpawnMethod,
        shutdown_after: Option<Duration>,
    ) -> Self {
        Self {
            stack,
            settings,
            allow_unchecked_attestations,
            spawn_method,
            shutdown_after,
        }
    }

    async fn execute(self) -> Result<DeploymentOutcome> {
        let Self {
            stack,
            settings,
            allow_unchecked_attestations,
            spawn_method,
            shutdown_after,
        } = self;

        println!(
            "Deploying blueprint to local Anvil devnet at HTTP {} / WS {}",
            stack.http_rpc_url(),
            stack.ws_rpc_url()
        );

        let mut run_opts = run_opts_from_stack(
            &stack,
            &settings,
            allow_unchecked_attestations,
            spawn_method,
        );
        run_opts.shutdown_after = shutdown_after;
        let service_id = run_opts.service_id;
        let run_result = run_blueprint(run_opts).await;

        stack.shutdown().await;
        run_result?;

        Ok(DeploymentOutcome::new(
            DeploymentNetwork::Devnet,
            settings.blueprint_id,
            service_id,
            Vec::new(),
        ))
    }
}

#[derive(Debug)]
struct NetworkDeployment {
    network: DeploymentNetwork,
    rpc: NetworkDeploymentConfig,
    definition: BlueprintDefinitionInput,
}

impl NetworkDeployment {
    fn new(
        network: DeploymentNetwork,
        rpc: NetworkDeploymentConfig,
        definition: BlueprintDefinitionInput,
    ) -> Self {
        Self {
            network,
            rpc,
            definition,
        }
    }

    async fn execute(self) -> Result<DeploymentOutcome> {
        let Self {
            network,
            rpc,
            definition,
        } = self;

        println!(
            "Deploying blueprint definition (metadata {} @ {}) to {}",
            definition.metadata_uri, definition.metadata_hash, network
        );

        let client = rpc.connect_client().await?;
        let (tx, blueprint_id) = client
            .create_blueprint(definition.call_data_bytes().to_vec())
            .await?;

        Ok(DeploymentOutcome::new(
            network,
            blueprint_id,
            None,
            vec![tx],
        ))
    }
}

#[derive(Clone, Debug)]
struct NetworkDeploymentConfig {
    http_rpc_url: Url,
    ws_rpc_url: Url,
    keystore_path: PathBuf,
    tangle_contract: Address,
    staking_contract: Address,
    status_registry_contract: Address,
}

impl NetworkDeploymentConfig {
    fn from_args(args: &TangleDeployArgs, settings: &TangleProtocolSettings) -> Result<Self> {
        let defaults = network_defaults(args.network);
        let http_rpc_url = infer_url(
            args.http_rpc_url.clone(),
            HTTP_RPC_URL_ENV,
            "--http-rpc-url",
            defaults.http_rpc_url,
        )?;
        let ws_rpc_url = infer_url(
            args.ws_rpc_url.clone(),
            WS_RPC_URL_ENV,
            "--ws-rpc-url",
            defaults.ws_rpc_url,
        )?;
        let keystore_path = resolve_keystore_path(args.keystore_path.clone());
        let tangle_contract = parse_contract_override(
            args.tangle_contract.as_deref(),
            settings.tangle_contract,
            "TANGLE_CONTRACT",
            "--tangle-contract",
            defaults.tangle_contract,
        )?;
        let staking_contract = parse_contract_override(
            args.staking_contract.as_deref(),
            settings.staking_contract,
            "STAKING_CONTRACT",
            "--staking-contract",
            defaults.staking_contract,
        )?;
        let status_registry_contract = parse_contract_override(
            args.status_registry_contract.as_deref(),
            settings.status_registry_contract,
            "STATUS_REGISTRY_CONTRACT",
            "--status-registry-contract",
            defaults.status_registry_contract,
        )?;

        Ok(Self {
            http_rpc_url,
            ws_rpc_url,
            keystore_path,
            tangle_contract,
            staking_contract,
            status_registry_contract,
        })
    }

    async fn connect_client(&self) -> Result<TangleClient> {
        if !self.keystore_path.exists() {
            return Err(eyre!(
                "Keystore {} not found; pass --keystore-path or set {KEYSTORE_PATH_ENV}",
                self.keystore_path.display()
            ));
        }

        let settings = TangleSettings {
            blueprint_id: 0,
            service_id: None,
            tangle_contract: self.tangle_contract,
            staking_contract: self.staking_contract,
            status_registry_contract: self.status_registry_contract,
        };
        let config = TangleClientConfig::new(
            self.http_rpc_url.clone(),
            self.ws_rpc_url.clone(),
            self.keystore_path.display().to_string(),
            settings,
        );
        TangleClient::new(config)
            .await
            .map_err(|e| eyre!(e.to_string()))
    }
}

fn infer_url(
    value: Option<Url>,
    env_key: &str,
    flag: &str,
    default: Option<&'static str>,
) -> Result<Url> {
    if let Some(url) = value {
        return Ok(url);
    }

    if let Ok(raw) = env::var(env_key) {
        return Url::parse(&raw).map_err(|err| eyre!("Invalid {env_key} URL: {err}"));
    }

    if let Some(raw) = default {
        return Url::parse(raw)
            .map_err(|err| eyre!("Built-in default URL for {env_key} failed to parse: {err}"));
    }

    Err(eyre!(
        "Missing RPC endpoint. Set {env_key} in settings.env or pass {flag}."
    ))
}

fn resolve_keystore_path(explicit: Option<PathBuf>) -> PathBuf {
    if let Some(path) = explicit {
        return path;
    }

    if let Ok(raw) = env::var(KEYSTORE_PATH_ENV) {
        return PathBuf::from(raw);
    }

    if let Ok(raw) = env::var("KEYSTORE_URI") {
        return PathBuf::from(raw);
    }

    PathBuf::from("./keystore")
}

fn parse_contract_override(
    value: Option<&str>,
    fallback: Address,
    env_key: &str,
    flag: &str,
    default: Option<&'static str>,
) -> Result<Address> {
    if let Some(raw) = value {
        return parse_address(raw, env_key);
    }

    if fallback != Address::ZERO {
        return Ok(fallback);
    }

    if let Some(raw) = default {
        return parse_address(raw, env_key);
    }

    Err(eyre!(
        "Missing {env_key}. Set it in settings.env or pass {flag}."
    ))
}

fn log_deployment_summary(outcome: &DeploymentOutcome) {
    println!(
        "\nDeployment complete → network={} blueprint={} service={}",
        outcome.network,
        outcome.blueprint_id,
        outcome
            .service_id
            .map_or_else(|| "-".to_string(), |id| id.to_string())
    );

    if outcome.transactions.is_empty() {
        println!("No transactions were submitted for this deployment.");
        return;
    }

    println!("Submitted transactions:");
    for tx in &outcome.transactions {
        println!(
            "  tx={:#x} block={:?} success={}",
            tx.tx_hash, tx.block_number, tx.success
        );
    }
}

const HTTP_RPC_URL_ENV: &str = "HTTP_RPC_URL";
const WS_RPC_URL_ENV: &str = "WS_RPC_URL";

/// Built-in endpoints + protocol addresses per network.
///
/// Order of precedence inside [`NetworkDeploymentConfig::from_args`] is
/// explicit CLI flag → `settings.env` value → these built-in defaults
/// → error. The defaults exist so the common case (`cargo tangle
/// blueprint deploy tangle --network testnet --definition …`) Just
/// Works without every blueprint repo carrying its own copy of the
/// same RPC URL + contract address.
///
/// Mainnet entries stay `None` until a real production deployment
/// exists; until then the script will continue to require explicit
/// configuration on `--network mainnet`.
struct NetworkDefaults {
    http_rpc_url: Option<&'static str>,
    ws_rpc_url: Option<&'static str>,
    tangle_contract: Option<&'static str>,
    staking_contract: Option<&'static str>,
    status_registry_contract: Option<&'static str>,
}

const NETWORK_DEFAULTS_TESTNET: NetworkDefaults = NetworkDefaults {
    // Base Sepolia (chainId 84532). Addresses match the first published
    // testnet deployment of tnt-core.
    http_rpc_url: Some("https://sepolia.base.org"),
    ws_rpc_url: Some("wss://base-sepolia-rpc.publicnode.com"),
    tangle_contract: Some("0xC9b0716a187072be0f38A5D972392C6479b9Cfe3"),
    staking_contract: Some("0xfEB417fc6d343e0fc88EC9fDb8294BF84d69F0Ca"),
    status_registry_contract: Some("0x81443688Fce1e4eDb822c1D5794C3DAc608e9a23"),
};

const NETWORK_DEFAULTS_MAINNET: NetworkDefaults = NetworkDefaults {
    http_rpc_url: None,
    ws_rpc_url: None,
    tangle_contract: None,
    staking_contract: None,
    status_registry_contract: None,
};

const NETWORK_DEFAULTS_DEVNET: NetworkDefaults = NetworkDefaults {
    // Devnet uses an in-process anvil spawn (see `DeploymentNetwork::Devnet`
    // arm in `run`), so these built-ins are unused — present for symmetry.
    http_rpc_url: None,
    ws_rpc_url: None,
    tangle_contract: None,
    staking_contract: None,
    status_registry_contract: None,
};

fn network_defaults(network: DeploymentNetwork) -> &'static NetworkDefaults {
    match network {
        DeploymentNetwork::Devnet => &NETWORK_DEFAULTS_DEVNET,
        DeploymentNetwork::Testnet => &NETWORK_DEFAULTS_TESTNET,
        DeploymentNetwork::Mainnet => &NETWORK_DEFAULTS_MAINNET,
    }
}