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