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