Expand description
§paralock
The Rust SDK of Paralock: trustless swaps between ZEC and stablecoins on EVM chains (Tempo, Base, Ethereum, Arbitrum, Robinhood Chain, HyperEVM). A lock on each chain and one secret open both: either both sides settle or both refund. No bridge, custodian or wrapped token.
Embed a market maker (Maker, served with maker_router) or a taker (Taker) in a Rust server without a
Node process. The engines are a port of the TypeScript @paralock/sdk (protocol v1.1) and interoperate with it on
the wire: a Rust taker swaps with a TypeScript maker and the other way around. All protocol logic (scripts,
transactions, signatures, adaptor signatures, ids, digests, wire messages and the safety checks) comes from
paralock_core; this crate adds I/O: node clients, stores, HTTP, and the persisted state machines.
Status: experimental and not formally audited. The Zcash leg is transparent in both modes.
Trust model. The protocol protects each party from the other, but each one trusts its own nodes: the taker
reveals its secret after checking the maker’s lock through its EVM RPC endpoint (see TakerChain::verifier for a
quorum of two), and the maker locks its stablecoins on what its Zcash backend reports about the funding (a
lightwalletd / Zaino server does no proof-of-work verification). Run your own nodes for real funds; builder’s
module docs (feature evm) have the details.
Re-exports§
pub use api::MakerApi;pub use builder::create_maker;evmpub use builder::create_taker;evmpub use error::Error;pub use error::Result;pub use evm::AdaptorEvmClient;pub use evm::AdaptorOutcome;pub use evm::ChainClients;pub use evm::ChainInfo;pub use evm::EvmClient;pub use evm::EvmError;pub use evm::EvmLock;pub use evm::HtlcOutcome;pub use evm::RelayerClients;pub use evm::SentTx;pub use evm::TakerChain;pub use evm::TxHash;pub use evm::TxStatus;pub use evm::VerifierClients;pub use http::ClientAddress;serverpub use http::CorsOrigins;serverpub use http::RateLimit;serverpub use http::ServerOptions;serverpub use http::maker_router;serverpub use http::serve;serverpub use http::serve_with_shutdown;serverpub use http::HttpMakerApi;clientpub use http::HttpMakerApiOptions;clientpub use lightwalletd::Lightwalletd;lightwalletdpub use lightwalletd::LightwalletdOptions;lightwalletdpub use maker::AfterClaim;pub use maker::Inventory;pub use maker::Maker;pub use maker::MakerConfig;pub use maker::MakerStage;pub use maker::MakerSwapRecord;pub use maker::MakerUpdateHook;pub use maker::public_view;pub use price::CoinGecko;price-feedpub use price::CoinGeckoOptions;price-feedpub use price::FixedPrice;pub use price::PriceFn;pub use price::PriceSource;pub use runtime::Clock;pub use runtime::DEFAULT_USER_AGENT;pub use runtime::Entropy;pub use runtime::OsEntropy;pub use runtime::SystemClock;pub use store::FileStore;pub use store::MemoryStore;pub use store::StoreError;pub use store::SwapStore;pub use taker::DEFAULT_MAKER_FEE_ZAT;pub use taker::DEFAULT_TAKER_LIMITS;pub use taker::DEFAULT_TAKER_TIMEOUTS;pub use taker::ResumeOptions;pub use taker::SwapOptions;pub use taker::Taker;pub use taker::TakerConfig;pub use taker::TakerLimits;pub use taker::TakerPriceCheck;pub use taker::TakerStage;pub use taker::TakerSwapRecord;pub use taker::TakerTimeouts;pub use zcash::NodeError;pub use zcash::ZcashNode;pub use zcash::ZcashRpc;pub use zcash::ZcashRpcOptions;pub use paralock_core;pub use paralock_evm;evm
Modules§
- api
- How a taker talks to a maker: in-process (
crate::Maker) or over HTTP (HttpMakerApi, featureclient). - builder
evm - Plain configuration → engines:
create_takerandcreate_maker(the TypeScriptcreateTaker/createMaker). They connect a Zcash backend, the EVM escrow clients ofparalock-evm(featureevm), the maker client and a store. For other EVM client libraries or custody APIs, build aTakerConfig/MakerConfigwith your own trait objects instead. - error
- The SDK’s error type.
- evm
- What the swap engines need from an EVM chain:
EvmClient(ParalockHTLC, htlc mode) andAdaptorEvmClient(ParalockAdaptorEscrow, private mode), mirroring@paralock/sdk’sevm-client.ts. With theevmfeature,crate::evm_adapterimplements them overparalock-evm(alloy); implement them yourself to plug in another client library, a custody API or a KMS. - evm_
adapter evm - The engine traits (
EvmClient,AdaptorEvmClient) overparalock-evm’s alloy clients for both escrows (featureevm). Tempo fee tokens, nonce management, transaction simulation, receipts, fee bumps and event scans areparalock-evm’s; this module only converts types. - http
- The maker HTTP API: the axum server (feature
server) and the reqwest client (featureclient). - lightwalletd
lightwalletd - A
ZcashNodeover a lightwalletd-compatible gRPC server (lightwalletd or Zaino), so swaps don’t need a full node. The protos are vendored frompackages/lightwalletd/proto(seeproto/). - maker
- The market-maker engine: quotes, commitments (htlc accepts and adaptor proposals), and a persisted settlement
state machine per swap (watch the funding, lock the stablecoins, claim the ZEC or refund), resumed by
Maker::startafter a restart. A port of@paralock/sdk’sMaker(protocol v1.1). - price
- USD/ZEC prices: what the maker quotes from and what the taker checks quotes against.
- records
- Serde building blocks shared by the taker’s and the maker’s persisted records, and their versioning.
- runtime
- Time and randomness, injectable so the engines can be tested deterministically, plus the retry backoff they share.
- store
- Durable storage for swap state.
- taker
- The taker engine: validates quotes, prepares and persists the funding, has the maker commit before any ZEC moves
(protocol v1.1), broadcasts, verifies the maker’s lock and claims; resumes and refunds from the store after a
restart. A port of
@paralock/sdk’sTaker. - zcash
- The Zcash backend the engines need (
ZcashNode) and its implementations:ZcashRpc(Zebra / Zakura JSON-RPC) and, with thelightwalletdfeature,crate::lightwalletd::Lightwalletd(lightwalletd / Zaino gRPC).
Structs§
- Claim
Limits - The taker’s floors on the time left to claim and on the EVM lock’s confirmations (spec §7.3, §7.4, §7.6).
Constructed with
ClaimLimits::new, which refuses values belowMIN_CLAIM_WINDOW_SECONDSandMIN_EVM_CONFIRMATIONS; going below them takes the explicitClaimLimits::new_below_floor. - Hex
0x-prefixed hex with an even number of digits (the TypeScriptHex). The original letter case is preserved, so re-serializing a parsed message reproduces it exactly.- Maker
Limits - Per-swap and capacity limits of a maker (
MakerLimits). - Paralock
Error - An expected failure with a stable
ParalockErrorCode. Messages are safe to show to a counterparty: they never include keys, secrets or internal details. - Privacy
Options - Level-1 privacy options. None of them hides the link between the two legs of one swap (adaptor mode does that); they keep a swap from linking to the rest of your activity.
- Quote
- A maker’s offer.
Deserializerunssuper::parse_quote(shape only); check a quote withsuper::validate_quotebefore acting on it. - Quote
Limits - Bounds a taker enforces on every quote before locking anything.
- Swap
- Public view of a swap. Never contains secrets or private keys. Fields serialize in the order the engines build
them (
id, quote, mode, status, zcash, evm, events, then the optional ones). - Timeout
Policy - Timeout policy. Safety rule: the EVM lock (the maker’s money) must expire well before the Zcash refund height (the taker’s money), so whoever learns the secret always has time to use it on the other chain.
- Timeout
Policy Params - The values of a
TimeoutPolicy, before validation.
Enums§
- EvmChain
- The EVM chains a swap can settle on (each name works with any chain id where the escrows are deployed).
- Network
- A Zcash network.
Regtestshares address prefixes withTestnet. - Paralock
Error Code - Machine-readable error codes. Each maps to an HTTP status (
ParalockErrorCode::status). - Swap
Mode htlc(shared sha256 hashlock) oradaptor(private mode: adaptor signatures, no shared value on-chain).- Swap
Status - Public progress of a swap, as both parties report it.
Constants§
- DEVNET_
POLICY - Short windows so refunds can be demoed; the devnet mines a Zcash block every few seconds.
- MAINNET_
POLICY - Production defaults: ~3 h Zcash window at 75 s blocks, 1 h EVM lock, 2 confirmations.
Traits§
- Swap
Status Ext as_strforSwapStatus: its wire name (quoted,zcash_locked,evm_locked,evm_claimed,completed,refunded_zcash,refunded_evm,failed).