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
//! # Avalanche Atomic Swap Daemon
//!
//! A production-ready HTLC (Hash Time-Locked Contract) atomic swap daemon for bidirectional
//! swaps between Avalanche C-Chain and any Subnet-EVM chain.
//!
//! ## Features
//!
//! - **Bidirectional Swaps**: Supports both C-Chain → Subnet and Subnet → C-Chain atomic swaps
//! - **Automatic Recovery**: Recovers in-flight swaps on startup by scanning recent blocks
//! - **Transaction Finality**: Validates transaction finality before proceeding with swaps
//! - **Prometheus Metrics**: Built-in metrics endpoint for monitoring swap activity
//! - **Configurable Thresholds**: Set minimum swap amounts and polling intervals
//!
//! ## Quick Start
//!
//! ```bash
//! cargo install avalanche-atomic-swap-daemon
//! avalanche-atomic-swap-daemon --help
//! ```
//!
//! ## Configuration
//!
//! Configure via environment variables or command-line arguments:
//!
//! ```bash
//! export SUBNET_RPC="https://subnet.example.com/rpc"
//! export DAEMON_PRIVATE_KEY="0x..."
//! export HTLC_CCHAIN="0x..."
//! export HTLC_SUBNET="0x..."
//! avalanche-atomic-swap-daemon
//! ```
//!
//! ## Architecture
//!
//! The daemon monitors HTLC contracts on both chains:
//!
//! 1. **Initiation**: User locks funds on Chain A with a hashlock
//! 2. **Mirror Lock**: Daemon detects the lock and mirrors it on Chain B
//! 3. **Claim**: User reveals the secret on Chain B to claim funds
//! 4. **Complete**: Daemon uses the revealed secret to claim funds on Chain A
//!
//! ## Library Usage
//!
//! While primarily a binary application, the library exposes core components
//! for building custom atomic swap solutions:
//!
//! ```rust,no_run
//! use avalanche_atomic_swap_daemon::{
//! clients::{CChainClient, SubnetClient},
//! watcher::SwapWatcher,
//! config::Config,
//! };
//! use std::sync::Arc;
//!
//! # async fn example() -> eyre::Result<()> {
//! // Configuration would typically come from Config::parse()
//! # let config = Config::parse();
//! # let signer = "0x1234".parse().unwrap();
//! # let cchain = Arc::new(CChainClient::new(config.cchain_rpc, config.htlc_cchain, signer.clone()).await?);
//! # let subnet = Arc::new(SubnetClient::new(config.subnet_rpc, config.htlc_subnet, signer).await?);
//!
//! // Create swap watcher
//! let watcher = SwapWatcher::new(cchain, subnet, config.min_amount).await;
//!
//! // Recover in-flight swaps
//! watcher.recover_state(200).await?;
//!
//! // Start monitoring (this runs forever)
//! watcher.run().await;
//! # Ok(())
//! # }
//! ```
/// Client implementations for C-Chain and Subnet-EVM chains
/// Configuration parsing and management
/// HTLC contract bindings generated from Solidity
/// Prometheus metrics server and collectors
/// Swap state definitions and types
/// Trait definitions for chain interactions
/// Main swap watcher and orchestration logic
// Re-export commonly used types
pub use crateCChainClient;
pub use crateSubnetClient;
pub use Config;
pub use ;
pub use ;
pub use SwapWatcher;