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
//! # paralock-evm
//!
//! The EVM layer of [Paralock](https://paralock.xyz) — trustless swaps between shielded ZEC and stablecoins on EVM
//! chains (Tempo, Base, Ethereum, Arbitrum, Robinhood Chain, HyperEVM). It is the Rust counterpart of the TypeScript
//! package `@paralock/evm`, built on [alloy](https://alloy.rs):
//!
//! - [`EvmHtlcClient`] for `ParalockHTLC` (htlc mode) and [`AdaptorEscrowClient`] for `ParalockAdaptorEscrow`
//! (adaptor mode): exact approvals, lock, claim, refund, lock lookups with block and transaction, outcomes
//! (empty / active / claimed with the preimage or signature / refunded), EVM time and balances;
//! - the protocol math they rely on ([`hashlock_of`], [`HtlcSwap::commitment`], [`AdaptorSwap::id`],
//! [`claim_digest`], [`ClaimSignature`] normalization), identical to the contracts and to `spec/vectors/evm.json`;
//! - [`EvmConnection`]: chain-id verification before anything is sent, simulation with typed revert decoding
//! ([`EvmError::TransactionReverted`], [`RevertReason`]), gas and fee estimation with a fee cap, process-wide nonce
//! management, receipt waits with per-call timeouts ([`EvmConnection::send_and_confirm_with`]), fee bumps that
//! replace a stuck transaction ([`EvmConnection::bump`]), status lookups ([`EvmConnection::transaction_status`]),
//! and bounded retries with backoff on transport errors and 429/5xx. Every error raised after a transaction was
//! signed carries its hash ([`EvmError::tx_hash`]);
//! - escrow address checks against the embedded bytecode ([`EvmConnection::verify_escrow_code`]);
//! - Tempo transactions that pay gas in a TIP-20 fee token, through Tempo's official `tempo-alloy` (feature `tempo`,
//! on by default; opt out with `default-features = false` if you don't need fee tokens; see [`tempo`]);
//! - [`KNOWN_NETWORKS`] (verified public networks and stablecoins) and [`TESTNET_DEPLOYMENTS`] (Paralock's public
//! testnet contracts), and [`deploy_paralock_contracts`] for local chains.
//!
//! The clients need a Tokio runtime. Amounts are token base units ([`alloy::primitives::U256`]; every supported
//! stablecoin has 6 decimals) and expiries are Unix **seconds** of EVM block time.
//!
//! ```no_run
//! use paralock_evm::{EvmConfig, EvmConnection, EvmHtlcClient, HtlcSwap, ScanConfig, testnet_deployment};
//! use alloy::primitives::{B256, U256};
//!
//! # async fn run() -> Result<(), paralock_evm::EvmError> {
//! let deployment = testnet_deployment(84532).expect("Base Sepolia");
//! let config = EvmConfig::new("https://sepolia.base.org", 84532).with_private_key("0x…")?;
//! let conn = EvmConnection::connect(config).await?; // verifies the chain id
//! let htlc = EvmHtlcClient::new(conn.clone(), deployment.htlc, ScanConfig::from_block(deployment.start_block));
//!
//! let preimage = B256::random();
//! let swap = HtlcSwap {
//! hashlock: paralock_evm::hashlock_of(&preimage),
//! token: deployment.quote_token_address().expect("USDC"),
//! sender: conn.address().expect("signer"),
//! recipient: "0x36e33698492d087ee35db0830ba305faf075d087".parse().expect("address"),
//! amount: U256::from(25_000_000u64), // 25 USDC
//! expiry: htlc.now().await? + 3_600,
//! };
//! htlc.approve_and_lock(&swap).await?;
//! println!("{:?}", htlc.outcome(swap.hashlock).await?);
//! # Ok(()) }
//! ```
//!
//! The code is experimental and not audited.
pub use ;
pub use ;
pub use ;
pub use ;
pub use ;
pub use ;
pub use ;
pub use ;
pub use ;
pub use ;
pub use ;
/// Re-export of the alloy version this crate is built on.
pub use alloy;
/// Compiles the README's examples as doctests.
;