nautilus_model/defi/
mod.rs

1// -------------------------------------------------------------------------------------------------
2//  Copyright (C) 2015-2025 Nautech Systems Pty Ltd. All rights reserved.
3//  https://nautechsystems.io
4//
5//  Licensed under the GNU Lesser General Public License Version 3.0 (the "License");
6//  You may not use this file except in compliance with the License.
7//  You may obtain a copy of the License at https://www.gnu.org/licenses/lgpl-3.0.en.html
8//
9//  Unless required by applicable law or agreed to in writing, software
10//  distributed under the License is distributed on an "AS IS" BASIS,
11//  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12//  See the License for the specific language governing permissions and
13//  limitations under the License.
14// -------------------------------------------------------------------------------------------------
15
16//! DeFi (Decentralized Finance) domain model.
17//!
18//! This module gathers all constructs required to model on-chain markets and decentralised
19//! exchange (DEX) activity.
20//!
21//! • `chain`    – Blockchain networks supported by Nautilus (Ethereum, Arbitrum, …).
22//! • `token`    – ERC-20 and other fungible token metadata.
23//! • `dex`      – DEX protocol definitions (Uniswap V3, PancakeSwap, …).
24//! • `data`     – Domain events & state snapshots that flow through the system (Block, PoolSwap).
25//! • `types`    – Numeric value types (Money, Quantity, Price) shared across the DeFi layer.
26//! • `rpc`      – Lightweight JSON-RPC helpers used by on-chain adapters.
27
28pub mod amm;
29pub mod chain;
30pub mod data;
31pub mod dex;
32pub mod hex;
33pub mod pool_analysis;
34pub mod reporting;
35pub mod rpc;
36pub mod tick_map;
37pub mod token;
38pub mod types;
39pub mod validation;
40
41// Re-exports
42pub use amm::{Pool, SharedPool};
43pub use chain::{Blockchain, Chain, SharedChain};
44pub use data::{
45    DefiData,
46    block::Block,
47    collect::PoolFeeCollect,
48    flash::PoolFlash,
49    liquidity::{PoolLiquidityUpdate, PoolLiquidityUpdateType},
50    swap::PoolSwap,
51    transaction::Transaction,
52};
53pub use dex::{AmmType, Dex, DexType, SharedDex};
54pub use pool_analysis::PoolProfiler;
55pub use token::{SharedToken, Token};
56
57/// Number of decimal places used by the native Ether denomination.
58///
59/// On the EVM all ERC-20 balances are expressed in **wei** – the
60/// smallest indivisible unit of Ether, named after cryptographer
61/// Wei Dai. One ether equals `10^18` wei, so using 18 decimal
62/// places is sufficient to represent any value expressible on-chain.
63///
64/// Tokens that choose a smaller precision (e.g. USDC’s 6, WBTC’s 8)
65/// still fall below this upper bound.
66pub static WEI_PRECISION: u8 = 18;