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
//! Primary Rust SDK facade for `CoW` Protocol.
//!
//! This crate re-exports the main public surface for:
//!
//! - shared core and config types
//! - signing helpers
//! - contracts helpers
//! - orderbook client types
//! - app-data helpers
//! - trading orchestration
//!
//! The facade is trading-first: the high-level trading flow is the primary surface.
//!
//! Read-only subgraph analytics are available behind the off-by-default
//! `subgraph` feature as `cow_sdk::subgraph`; the full subgraph contract stays
//! in `cow-sdk-subgraph`.
//!
//! Native/default ready-state setup:
//!
//! ```rust
//! use cow_sdk::core::{Address, SupportedChainId, address};
//! use cow_sdk::trading::Trading;
//!
//! // Compile-time validated address literal — no runtime parse, no unwrap.
//! // The literal is the lowercase wire form; mixed-case literals reject at
//! // build time because EIP-55 checksums cannot be verified in const eval.
//! const SETTLEMENT: Address = address!("0x9008d19f58aabd9ed0d60971565aa8510560ab41");
//!
//! let _trading = Trading::builder()
//! .chain_id(SupportedChainId::Sepolia)
//! .app_code("your-app-code")
//! .build()
//! .unwrap();
//! ```
//!
//! Once constructed, the fluent swap builder quotes, signs, and posts in one
//! call. Its named token setters cannot be transposed, and the order owner
//! defaults to the signer's address:
//!
//! ```rust,no_run
//! # use std::error::Error;
//! use cow_sdk::core::{Address, Amount, SupportedChainId, address};
//! use cow_sdk::trading::Trading;
//!
//! // Sell 0.1 WETH for COW on Sepolia.
//! const WETH: Address = address!("0xfff9976782d46cc05630d1f6ebab18b2324d6b14");
//! const COW: Address = address!("0x0625afb445c3b6b7b929342a04a22599fd5dbb59");
//! #
//! # async fn run<S>(signer: &S) -> Result<(), Box<dyn Error>>
//! # where
//! # S: cow_sdk::core::Signer,
//! # S::Error: std::fmt::Display + cow_sdk::core::UserRejection,
//! # {
//! let trading = Trading::builder()
//! .chain_id(SupportedChainId::Sepolia)
//! .app_code("your-app-code")
//! .build()?;
//!
//! // One call quotes, signs with `signer`, and posts to the orderbook.
//! let posted = trading
//! .swap()
//! .sell_token(WETH)
//! .buy_token(COW)
//! .sell_amount(Amount::from(100_000_000_000_000_000u128))
//! .execute(signer)
//! .await?;
//! println!("posted order: {}", posted.order_id);
//! # Ok(())
//! # }
//! ```
//!
//! The flat `trading.post_swap_order(params, signer, None)` method and the
//! standalone `post_swap_order(..)` free function remain available for callers
//! that assemble `TradeParams` directly or compose without a bound client.
//!
//! For a resting limit order with an explicit price, `trading.limit()` opens the
//! matching builder: named `sell_amount` / `buy_amount` setters, then `post(signer)`
//! (or `post_presign()` for the smart-account path that needs no signer).
//!
//! For allowance, approval, pre-sign, or on-chain cancellation that does not
//! need an app code, call the crate's free functions directly
//! (`cow_protocol_allowance`, `approval_transaction`,
//! `pre_sign_transaction`, `onchain_cancel_order`) without constructing a
//! trading client.
compile_error!;
// The `cow-sdk` crate root is a thin, module-organised facade: each leaf crate
// is re-exported as a named module (`core`, `trading`, `orderbook`, `signing`,
// `contracts`, `app_data`, …), and every workflow and identity type is reached
// on its module path (`cow_sdk::core::Address`, `cow_sdk::trading::Trading`),
// matching `alloy`, `reqwest`, and `tower`. The crate root itself carries only
// the cross-cutting aggregate error (`CowError` / `ErrorClass`, below) and the
// typed transport leaf surface (the curated `cow_sdk::http` module) consumers
// match against. No crate in the workspace ships a prelude; identity types are reached
// on their module path (`cow_sdk::core::Address`), matching alloy and reqwest.
pub use cow_sdk_alloy as alloy;
pub use cow_sdk_alloy_provider as alloy_provider;
pub use cow_sdk_alloy_signer as alloy_signer;
pub use cow_sdk_app_data as app_data;
pub use cow_sdk_contracts as contracts;
/// Opt-in COW Shed account-abstraction hook helpers (proxy derivation,
/// EIP-712 signing, factory calldata, and the [`cow_shed::CowShedHooks`]
/// orchestrator). Behind the off-by-default `cow-shed` feature, so the default
/// `cow-sdk` surface stays trading-first; enable it with
/// `cow-sdk = { features = ["cow-shed"] }`.
pub use cow_shed;
pub use cow_sdk_core as core;
/// Shared HTTP retry, rate-limit, and classification policy.
/// Browser-native HTTP transport surface — the `wasm32` sibling of the native
/// `ReqwestTransport` default. [`FetchTransport`] is the browser default
/// implementation of [`HttpTransport`](crate::http::HttpTransport); compose it
/// into typed clients as `Arc<dyn cow_sdk_core::HttpTransport + Send + Sync>`
/// exactly like the native transport.
pub use ;
pub use cow_sdk_orderbook as orderbook;
pub use cow_sdk_signing as signing;
/// Optional read-only subgraph analytics (protocol totals, daily and hourly
/// volume, and a typed raw-GraphQL escape hatch). Behind the off-by-default
/// `subgraph` feature so the default facade stays trading-first; enable it with
/// `cow-sdk = { features = ["subgraph"] }`. The full subgraph contract stays in
/// `cow-sdk-subgraph`.
///
/// ```
/// # #[cfg(not(target_arch = "wasm32"))]
/// # {
/// use cow_sdk::core::SupportedChainId;
/// use cow_sdk::subgraph::SubgraphApi;
///
/// let _subgraph = SubgraphApi::builder()
/// .chain(SupportedChainId::Mainnet)
/// .api_key("your-subgraph-api-key")
/// .build()
/// .expect("subgraph client builds with canonical defaults");
/// # }
/// ```
pub use cow_sdk_subgraph as subgraph;
/// In-memory test doubles for the SDK public trait seams, for use from a
/// consumer's `[dev-dependencies]`. Enabled by the opt-in `testing` feature and
/// off by default, so the doubles never enter a production dependency graph
/// (ADR 0063).
pub use cow_sdk_test as testing;
pub use cow_sdk_trading as trading;
use Error;
/// Aggregate error type for the root facade crate.
///
/// `CowError` is the convenience aggregate for consumers that `?`-propagate
/// every SDK call into one type; each leaf error converts in through `#[from]`.
/// A consumer with its own error type, or that needs rejection-specific
/// handling, can match the leaf error directly — every leaf exposes the same
/// [`ErrorClass`] through `class()` (and the orderbook and trading errors also
/// expose `is_retryable()` / `backoff_hint()`), so the verdict is identical
/// whether a caller holds the facade error or a bare leaf.
/// Coarse-grained failure classification, re-exported from `cow-sdk-core`.
///
/// Every public error type the facade aggregates exposes a matching
/// `class()` accessor, so the classification is consistent whether a caller
/// holds the facade [`CowError`] or a bare leaf error.
pub use ErrorClass;
// The per-variant classification now lives on each leaf error type's
// `class()` accessor; `CowError::class()` above delegates to them.