fynd_core/lib.rs
1#![deny(missing_docs)]
2//! Pure solving logic for the [Fynd](https://fynd.xyz) DEX router.
3//!
4//! This crate contains the route-finding algorithms, market-data pipeline, and encoder that
5//! powers Fynd. It has **no HTTP dependencies** and can be embedded directly in any application.
6//!
7//! For documentation, guides, and API reference see **<https://docs.fynd.xyz/>**.
8//!
9//! # Use cases
10//!
11//! - **Standalone routing** — embed Fynd's algorithms directly without running an HTTP server.
12//! - **Custom algorithms** — implement the [`Algorithm`] trait and plug in via
13//! [`FyndBuilder::with_algorithm`](solver::FyndBuilder).
14//! - **HTTP server** — use the [`fynd-rpc`](https://crates.io/crates/fynd-rpc) crate, which wraps
15//! this crate with Actix Web.
16//!
17//! # Quick start
18//!
19//! See the [Fynd quickstart](https://docs.fynd.xyz/get-started/quickstart) to run a local
20//! instance, or the [custom algorithm guide](https://docs.fynd.xyz/guides/custom-algorithm)
21//! to implement your own routing strategy.
22
23/// Route-finding algorithms. Includes [`MostLiquidAlgorithm`],
24/// [`algorithm::BellmanFordAlgorithm`], [`PathFrankWolfeAlgorithm`],
25/// [`algorithm::WaterFillAlgorithm`], and the pluggable [`Algorithm`] trait.
26pub mod algorithm;
27/// Derived data computations: spot prices, component depths, and gas prices.
28pub mod derived;
29/// Encodes solved routes into ABI-encoded on-chain calldata via Tycho's router contracts.
30pub mod encoding;
31/// Market data feed: Tycho WebSocket integration, gas price fetching, and protocol registry.
32pub mod feed;
33/// Graph management for algorithms. Provides [`GraphManager`](graph::GraphManager)
34/// trait and the reusable [`PetgraphStableDiGraphManager`](graph::PetgraphStableDiGraphManager).
35pub mod graph;
36/// External price validation for quotes.
37pub mod price_guard;
38/// Computes the amount out a route delivers when its pAMM legs fall back to Uniswap V3, so the
39/// encoder can drop a quote whose fallback pays less than `min_amount_out`.
40pub mod propamm_fallback;
41/// Re-execute an already-built route against a (possibly newer) market state.
42pub mod replay;
43/// `eth_call` plumbing shared by the tasks that read contract state.
44mod rpc;
45/// [`FyndBuilder`](solver::FyndBuilder) assembles the full pipeline and returns a
46/// [`Solver`](solver::Solver).
47pub mod solver;
48/// Core domain types: [`Order`](types::Order), [`Route`](types::Route), [`Quote`](types::Quote),
49/// etc.
50pub mod types;
51/// Multi-threaded solver pool management with pluggable algorithm registry.
52pub mod worker_pool;
53/// Request orchestration: fans out orders to all solver pools and selects the best result.
54pub mod worker_pool_router;
55
56// Re-export commonly used types for convenience
57pub use algorithm::{
58 Algorithm, AlgorithmConfig, AlgorithmError, MostLiquidAlgorithm, NoPathReason,
59 PathFrankWolfeAlgorithm,
60};
61// Required for implementing the Algorithm trait externally
62pub use derived::computation::ComputationRequirements;
63pub use feed::{events::MarketEvent, market_data::StateLabel};
64pub use price_guard::{
65 config::PriceGuardConfig,
66 provider::{ExternalPrice, PriceProvider, PriceProviderError},
67};
68pub use replay::{replay_route, ReplayError, RouteReplay};
69// `GraphManager`, `Route` and the market data readers take `FxHashMap`/`FxHashSet`.
70// Re-exported so an external implementor names the same types without matching our
71// `rustc-hash` version itself.
72pub use rustc_hash;
73pub use solver::{FyndBuilder, PoolConfig, Solver, SolverBuildError, SolverParts, WaitReadyError};
74/// Processes ephemeral pending bundles against live Tycho market state. Obtained by calling
75/// [`FyndBuilder::build_with_pending`](solver::FyndBuilder::build_with_pending).
76pub use tycho_simulation::evm::pending::PendingBlockProcessor;
77/// Error type produced by [`PendingBlockProcessor`] when simulating a pending bundle.
78pub use tycho_simulation::evm::pending::PendingError;
79/// A pending transaction bundle passed to [`PendingBlockProcessor`] for simulation.
80pub use tycho_simulation::evm::pending::PendingUpdate;
81/// Handle returned by [`FyndBuilder::build_with_step_controller`] that controls when each
82/// buffered block is released for decoding. See [`tycho_simulation`] for the full API.
83#[cfg(feature = "experimental")]
84pub use tycho_simulation::evm::stream::BlockStepController;
85/// Implement this trait and register it via
86/// [`FyndBuilder::with_pending_indexer`](solver::FyndBuilder::with_pending_indexer)
87/// to receive raw transaction deltas during pending-block simulation.
88pub use tycho_simulation::tycho_common::traits::TxDeltaIndexer;
89pub use types::{
90 BlockInfo, ClientFeeParams, ComponentId, EncodingOptions, FeeBreakdown, Order, OrderQuote,
91 OrderSide, OrderValidationError, PermitDetails, PermitSingle, Quote, QuoteOptions,
92 QuoteRequest, QuoteStatus, Route, RouteValidationError, SingleOrderQuote, SolveError,
93 SolveParams, SolveResult, SurplusInfo, Swap, TaskId, Transaction, UserTransferType,
94};
95pub use worker_pool::{
96 pool::{WorkerPool, WorkerPoolBuilder, WorkerPoolConfig},
97 registry::UnknownAlgorithmError,
98 TaskQueueHandle,
99};
100pub use worker_pool_router::{
101 config::WorkerPoolRouterConfig, ExclusiveAccess, LiquidityScope, SolverPoolHandle,
102 WorkerPoolRouter,
103};