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
//! # ScemaDEX SDK — an Agentic Liquidity Layer
//!
//! ScemaDEX is not "a DEX." It is an SDK in which **the routing intelligence
//! itself is a metered, learning, accountable product.** Autonomous agents
//! solve swap *intents*, **bond** their promises, sell their inferences, and
//! trade learned experience with one another — all settled in stablecoins over
//! the x402 payment rails.
//!
//! ## The four composing primitives
//!
//! - **A · Metered inference routing.** Every quote is produced by a learning
//! policy and can be sold per-call via x402. The *quality of the decision* is
//! the SKU. See [`policy`].
//! - **B · Intent solving.** Callers express *what they want*
//! ([`intent::Intent`] with an [`intent::Objective`]), not a path spec. The
//! policy decides venue / split / timing.
//! - **C · Signal & reputation oracle.** Reputation, pool scores and advice are
//! monetized read endpoints. See [`oracle`].
//! - **D · Conviction Routing (the defining pillar).** The policy escrows a
//! slashable performance **bond** against its own promise. Meet the
//! guarantee → reclaim the bond and collect the fee; miss it → the bond
//! settles to the caller. This is what makes a paid black-box inference
//! *trustworthy*. See [`bond`].
//!
//! ## The headline: a mesh of agents trading intelligence
//!
//! Compose A–D across many nodes and you get the revolutionary endgame: a
//! [`mesh::PeerMarket`] where agents **sell bonded inferences and learned
//! experience, and buy better ones from peers** — an economy of machine
//! intelligence, not a swap widget. An agent earns USDC selling what it knows
//! and spends USDC to learn faster.
//!
//! ## The adversarial layer: four primitives with no precedent
//!
//! - **E · The Counter-Market.** Any agent can stake *against* an open bond
//! ([`counter::CounterMarket`]) — the first market that prices individual
//! machine inferences. The gap between self-conviction and market-implied
//! conviction (the *doubt spread*) is a brand-new policy feature.
//! - **F · The Scar Market.** Slashed bonds are the only un-fakeable proof a
//! decision cost real collateral; [`scar::certify_scar`] turns the trajectory
//! behind a slash into sellable, verified negative training data.
//! - **G · Experience royalties.** [`lineage::LineageLedger`] records which
//! purchased experience trained which policy, and streams a royalty slice of
//! every downstream fee back to the sellers — training data as a
//! yield-bearing asset.
//! - **H · Bonded teaching.** A teacher answers a student's most uncertain
//! states per metered query, bonding its tuition against the student's
//! *measured* improvement ([`teach::TeachingEngine`]) — distillation with a
//! money-back guarantee.
//!
//! ## Architecture: lean core, injected power
//!
//! The published crate carries **no `solana-sdk` or bot dependency**. It defines
//! the trait surface ([`policy::RoutePolicy`], [`bond::BondEngine`],
//! [`venue::VenueExecutor`], [`oracle::SignalSource`], [`mesh::PeerMarket`]) plus
//! reference implementations. Enabling the `scematica` feature injects the real
//! Deep Q* agent, the Raydium/Orca/Meteora/Jupiter executors, and the x402
//! facilitator from the bot workspace.
//!
//! ```
//! use scemadex_sdk::reference_client;
//! # async fn run() -> scemadex_sdk::Result<()> {
//! let dex = reference_client();
//! let intent = scemadex_sdk::demo_intent();
//! let (solution, bond) = dex.quote(&intent).await?;
//! assert!(solution.route.splits_valid());
//! let _ = bond;
//! # Ok(()) }
//! ```
/// Concrete wiring of the SDK traits to the real Scematica Deep Q* agent. Only
/// compiled with the `scematica` feature; the default published crate carries no
/// such dependency.
/// Natural-language intent parsing + route/bond narration via an LLM. Requires
/// the `ai` feature.
/// Networked [`PeerMarket`] client over an HTTP/JSON relay. Requires the `net`
/// feature.
pub use ;
pub use ScemaDex;
pub use ;
pub use ;
pub use ;
pub use ;
pub use ;
pub use ;
pub use ;
pub use ;
pub use ;
pub use ;
pub use ;
pub use ;
pub use ;
/// Build a [`ScemaDex`] wired with the lean reference implementations. Useful for
/// examples, tests, and consumers who haven't enabled the `scematica` feature.
///
/// Note the bond engine here is [`NoBondEngine`], which escrows a *zero* bond —
/// it exercises the intent/route surface but does **not** demonstrate Conviction
/// Routing (Primitive D). For the conviction-weighted, ledger-tracking bond
/// engine, use [`conviction_client`].
/// Build a [`ScemaDex`] whose bond engine is the conviction-weighted
/// [`EscrowBondEngine`] — the lean reference wiring that actually exercises
/// **Conviction Routing** (Primitive D) end-to-end, offline.
///
/// Unlike [`reference_client`], each [`ScemaDex::quote`] here escrows a real,
/// conviction-sized bond with a guaranteed-minimum-output haircut, and
/// [`ScemaDex::execute`] settles it (honored or slashed) into the engine's
/// [`BondLedger`]. The only thing missing versus the `scematica` feature is the
/// on-chain x402 USDC transfer; the settlement state machine is identical.
///
/// ```
/// use scemadex_sdk::{conviction_client, demo_intent, BondOutcome};
/// # async fn run() -> scemadex_sdk::Result<()> {
/// let dex = conviction_client();
/// let (solution, bond) = dex.quote(&demo_intent()).await?;
/// assert!(bond.amount.0 > 0, "conviction-weighted bond is escrowed");
/// assert!(bond.min_out_raw <= solution.route.expected_out.raw);
/// let (_fill, outcome) = dex.execute(&demo_intent()).await?;
/// assert_eq!(outcome, BondOutcome::Honored);
/// # Ok(()) }
/// ```
/// A canonical WSOL → USDC demo intent used by docs and tests.