Skip to main content

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, pool 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/// Re-execute an already-built route against a (possibly newer) market state.
39pub mod replay;
40/// [`FyndBuilder`](solver::FyndBuilder) assembles the full pipeline and returns a
41/// [`Solver`](solver::Solver).
42pub mod solver;
43/// Core domain types: [`Order`](types::Order), [`Route`](types::Route), [`Quote`](types::Quote),
44/// etc.
45pub mod types;
46/// Multi-threaded solver pool management with pluggable algorithm registry.
47pub mod worker_pool;
48/// Request orchestration: fans out orders to all solver pools and selects the best result.
49pub mod worker_pool_router;
50
51// Re-export commonly used types for convenience
52pub use algorithm::{
53    Algorithm, AlgorithmConfig, AlgorithmError, MostLiquidAlgorithm, NoPathReason,
54    PathFrankWolfeAlgorithm,
55};
56// Required for implementing the Algorithm trait externally
57pub use derived::computation::ComputationRequirements;
58pub use feed::{events::MarketEvent, market_data::StateLabel};
59pub use price_guard::{
60    config::PriceGuardConfig,
61    provider::{ExternalPrice, PriceProvider, PriceProviderError},
62};
63pub use replay::{replay_route, ReplayError, RouteReplay};
64pub use solver::{FyndBuilder, PoolConfig, Solver, SolverBuildError, SolverParts, WaitReadyError};
65/// Processes ephemeral pending bundles against live Tycho market state. Obtained by calling
66/// [`FyndBuilder::build_with_pending`](solver::FyndBuilder::build_with_pending).
67pub use tycho_simulation::evm::pending::PendingBlockProcessor;
68/// Error type produced by [`PendingBlockProcessor`] when simulating a pending bundle.
69pub use tycho_simulation::evm::pending::PendingError;
70/// A pending transaction bundle passed to [`PendingBlockProcessor`] for simulation.
71pub use tycho_simulation::evm::pending::PendingUpdate;
72/// Handle returned by [`FyndBuilder::build_with_step_controller`] that controls when each
73/// buffered block is released for decoding. See [`tycho_simulation`] for the full API.
74#[cfg(feature = "experimental")]
75pub use tycho_simulation::evm::stream::BlockStepController;
76/// Implement this trait and register it via
77/// [`FyndBuilder::with_pending_indexer`](solver::FyndBuilder::with_pending_indexer)
78/// to receive raw transaction deltas during pending-block simulation.
79pub use tycho_simulation::tycho_common::traits::TxDeltaIndexer;
80pub use types::{
81    BlockInfo, ClientFeeParams, ComponentId, EncodingOptions, FeeBreakdown, Order, OrderQuote,
82    OrderSide, OrderValidationError, PermitDetails, PermitSingle, Quote, QuoteOptions,
83    QuoteRequest, QuoteStatus, Route, RouteValidationError, SingleOrderQuote, SolveError,
84    SolveParams, SolveResult, SurplusInfo, Swap, TaskId, Transaction, UserTransferType,
85};
86pub use worker_pool::{
87    pool::{WorkerPool, WorkerPoolBuilder, WorkerPoolConfig},
88    registry::UnknownAlgorithmError,
89    TaskQueueHandle,
90};
91pub use worker_pool_router::{
92    config::WorkerPoolRouterConfig, LiquidityScope, SolverPoolHandle, WorkerPoolRouter,
93};