fynd_client/lib.rs
1#![deny(missing_docs)]
2//! Rust client for the [Fynd](https://fynd.xyz) DEX router.
3//!
4//! `fynd-client` lets you request swap quotes, build signable transaction payloads, and
5//! broadcast signed orders through the Fynd RPC API — all from a single typed interface.
6//!
7//! For guides, API reference, and setup instructions see **<https://docs.fynd.xyz/>**.
8//!
9//! # Workflow
10//!
11//! A complete swap runs in three steps: **quote → approve → sign and execute**.
12//! See `examples/swap_erc20.rs` for a full walkthrough, or follow the
13//! [quickstart](https://docs.fynd.xyz/get-started/quickstart) to run a local Fynd instance.
14//!
15//! # Constructing a client
16//!
17//! Use [`FyndClientBuilder`] to configure and build a [`FyndClient`]:
18//!
19//! ```rust,no_run
20//! # use fynd_client::FyndClientBuilder;
21//! # #[tokio::main] async fn main() -> Result<(), Box<dyn std::error::Error>> {
22//! // Fynd default: http://localhost:3000 RPC default (Anvil): https://reth-ethereum.ithaca.xyz/rpc
23//! let client = FyndClientBuilder::new("http://localhost:3000")
24//! .with_rpc_url("https://reth-ethereum.ithaca.xyz/rpc")
25//! .build()
26//! .await?;
27//! # Ok(()) }
28//! ```
29//!
30//! For quote-only use (no on-chain transactions), skip the RPC connection with
31//! [`FyndClientBuilder::build_quote_only`]:
32//!
33//! ```rust,no_run
34//! # use fynd_client::FyndClientBuilder;
35//! # fn main() -> Result<(), Box<dyn std::error::Error>> {
36//! let client = FyndClientBuilder::new("http://localhost:3000")
37//! .build_quote_only()?;
38//! # Ok(()) }
39//! ```
40//!
41//! # Requesting a quote
42//!
43//! ```rust,no_run
44//! # use fynd_client::{FyndClientBuilder, Order, OrderSide, QuoteOptions, QuoteParams};
45//! # use alloy::primitives::address;
46//! # use bytes::Bytes;
47//! # use num_bigint::BigUint;
48//! # #[tokio::main] async fn main() -> Result<(), Box<dyn std::error::Error>> {
49//! # let client = FyndClientBuilder::new("http://localhost:3000")
50//! # .build_quote_only()?;
51//! // WETH → USDC on mainnet (Vitalik's address as sender).
52//! let weth: Bytes = address!("C02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2").to_vec().into();
53//! let usdc: Bytes = address!("A0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48").to_vec().into();
54//! let sender: Bytes = address!("d8dA6BF26964aF9D7eEd9e03E53415D37aA96045").to_vec().into();
55//!
56//! let quote = client
57//! .quote(QuoteParams::new(
58//! Order::new(
59//! weth,
60//! usdc,
61//! BigUint::from(1_000_000_000_000_000_000u64), // 1 WETH (18 decimals)
62//! OrderSide::Sell,
63//! sender,
64//! None,
65//! ),
66//! QuoteOptions::default(),
67//! ))
68//! .await?;
69//!
70//! println!("amount out: {}", quote.amount_out());
71//! # Ok(()) }
72//! ```
73
74pub use client::{
75 AllowanceCheck, ApprovalParams, ExecutionOptions, FyndClient, FyndClientBuilder, RetryConfig,
76 SigningHints, StorageOverrides,
77};
78pub use error::{ErrorCode, FyndError};
79pub use signing::{
80 ApprovalPayload, ExecutionReceipt, FyndPayload, MinedTx, SettledOrder, SignedApproval,
81 SignedSwap, SwapPayload, TxReceipt,
82};
83pub use types::{
84 BackendKind, BatchQuoteParams, BlockInfo, ClientFeeParams, EncodingOptions, FeeBreakdown,
85 HealthStatus, InstanceInfo, Order, OrderSide, PermitDetails, PermitSingle, PriceGuardConfig,
86 Quote, QuoteOptions, QuoteParams, QuoteStatus, Route, Swap, Transaction, UserTransferType,
87};
88
89mod client;
90mod error;
91mod mapping;
92mod signing;
93mod types;