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