tokenomics_simulator/
lib.rs

1#![forbid(unsafe_code)]
2#![warn(missing_docs)]
3#![warn(clippy::missing_docs_in_private_items)]
4
5//! # Tokenomics Simulator
6//!
7//!
8//! An open-source engine for simulating the tokenomics of a project.
9//!
10//! It allows users to simulate trades, calculate various metrics, and predict user behaviour over different time intervals.
11//!
12//! <p align="center">
13//!     <picture><img src="https://raw.githubusercontent.com/slavik-pastushenko/tokenomics-simulator-rs/refs/heads/main/examples/preview.png" alt="An open-source engine for simulating the tokenomics of a project." style="width:auto;"></picture>
14//! </p>
15//!
16//! ## Examples
17//!
18//! In addition to the usage example below, there are more examples available in the [`examples`](https://github.com/slavik-pastushenko/tokenomics-simulator-rs/tree/main/examples) directory of the repository.
19//!
20//! These examples demonstrate various ways to use the `tokenomics-simulator` crate.
21//!
22//! ## Usage
23//!
24//! To use the `tokenomics-simulator` crate in your project, add it to your `Cargo.toml`:
25//!
26//! ```toml
27//! [dependencies]
28//! tokenomics-simulator = "0.5.7"
29//! ```
30//!
31//! You can also include additional features, such as logging, by specifying them in your `Cargo.toml`:
32//!
33//! ```toml
34//! [dependencies]
35//! tokenomics-simulator = { version = "0.5.7", features = ["log", "serde"] }
36//! ```
37//!
38//! Below is an example of how to create and run a simulation using the crate.
39//! This example demonstrates how to build simulation options, create a simulation, and run it with a token.
40//!
41//! ```rust
42//! use tokenomics_simulator::{Simulation, SimulationError};
43//!
44//! fn main() -> Result<(), SimulationError> {
45//!     // Build a new token
46//!     let token = Simulation::token_builder()
47//!         .name("Token".to_string())
48//!         .symbol("TKN".to_string())
49//!         .total_supply(1_000_000)
50//!         .airdrop_percentage(5.0)
51//!         .burn_rate(1.0)
52//!         .build()?;
53//!
54//!     // Build the simulation options
55//!     let options = Simulation::options_builder()
56//!         .total_users(100)
57//!         .market_volatility(0.5)
58//!         .build()?;
59//!
60//!     // Build a new simulation with the token and options
61//!     let mut simulation = Simulation::builder()
62//!         .name("Simulation".to_string())
63//!         .description("Initial simulation".to_string())
64//!         .token(token)
65//!         .options(options)
66//!         .build()?;
67//!
68//!     // Run the simulation
69//!     simulation.run()?;
70//!
71//!     // Get the simulation interval reports
72//!     for report in simulation.interval_reports.iter() {
73//!         println!("Interval report: {:#?}", report);
74//!     }
75//!
76//!     // Get the final simulation report
77//!     println!("Final report: {:#?}", simulation.report);
78//!
79//!     Ok(())
80//! }
81//! ```
82//!
83//! ## Benchmarks
84//!
85//! We use the `criterion` crate to benchmark the performance of the `tokenomics-simulator` crate.
86//!
87//! Benchmarks help us understand the performance characteristics of the simulation engine and identify areas for optimization.
88//!
89//! ### Running Benchmarks
90//!
91//! To run the benchmarks, use the following command:
92//!
93//! ```sh
94//! cargo bench
95//! ```
96//!
97//! ### Benchmark Scenarios
98//!
99//! We have several benchmark scenarios to test different aspects of the simulation engine:
100//!
101//! - **Small Simulation**: Tests a simulation with 100 users.
102//! - **Large Simulation**: Tests a simulation with 500,000 users.
103//! - **Extreme Simulation**: Tests a simulation with 1,000,000 users.
104//!
105//! For more detailed benchmark scenarios, please refer to the [`benches`](https://github.com/slavik-pastushenko/tokenomics-simulator-rs/tree/main/benches) directory in the repository.
106//!
107//! ## Safety
108//!
109//! This crate uses `#![forbid(unsafe_code)]` to ensure everything is implemented in 100% safe Rust.
110//!
111//! ## Contributing
112//!
113//! 🎈 Thanks for your help improving the project! We are so happy to have you!
114//!
115//! We have a [contributing guide](https://github.com/slavik-pastushenko/tokenomics-simulator-rs/blob/main/CONTRIBUTING.md) to help you get involved in the project.
116
117use thiserror::Error;
118
119/// Engine module.
120/// Is used to run the simulation with the desired configuration.
121pub mod engine;
122
123/// Engine builder module.
124/// Is used to create a new engine with the desired configuration.
125pub mod engine_builder;
126
127/// Engine configuration module.
128/// Is used to create a new engine configuration.
129pub mod engine_config;
130
131/// Report module.
132/// Is used to generate reports.
133pub mod report;
134
135/// Token module.
136/// Is used to apply token related operations for the simulation.
137pub mod token;
138
139/// Token builder module.
140/// Is used to create a new token with the desired configuration.
141pub mod token_builder;
142
143/// User module.
144/// Is used to apply user related operations for the simulation.
145pub mod user;
146
147pub use engine::*;
148pub use engine_builder::*;
149pub use engine_config::*;
150pub use report::*;
151pub use token::*;
152pub use token_builder::*;
153pub use user::*;
154
155/// Simulation error.
156/// A list of possible errors that can occur during the simulation.
157#[derive(Debug, Error, PartialEq, Eq)]
158pub enum SimulationError {
159    /// Missing required field: name.
160    #[error("Missing required field: name.")]
161    MissingName,
162
163    /// Missing required field: token.
164    #[error("Missing required field: token.")]
165    MissingToken,
166
167    /// Missing required field: options.
168    #[error("Missing required field: options.")]
169    MissingOptions,
170
171    /// Missing required field: total_users.
172    #[error("Missing required field: total_users.")]
173    MissingTotalUsers,
174
175    /// Invalid decimal value.
176    #[error("Invalid decimal value.")]
177    InvalidDecimal,
178}