nautilus_model/defi/token.rs
1// -------------------------------------------------------------------------------------------------
2// Copyright (C) 2015-2025 Posei Systems Pty Ltd. All rights reserved.
3// https://poseitrader.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
16use std::fmt::{Display, Formatter};
17
18use crate::defi::chain::SharedChain;
19
20/// Represents a cryptocurrency token on a blockchain network.
21#[derive(Debug, Clone)]
22pub struct Token {
23 /// The blockchain network where this token exists.
24 pub chain: SharedChain,
25 /// The blockchain address of the token contract.
26 pub address: String,
27 /// The full name of the token.
28 pub name: String,
29 /// The token's ticker symbol.
30 pub symbol: String,
31 /// The number of decimal places used to represent fractional token amounts.
32 pub decimals: u8,
33}
34
35impl Token {
36 /// Creates a new [`Token`] instance with the specified properties.
37 #[must_use]
38 pub fn new(
39 chain: SharedChain,
40 address: String,
41 name: String,
42 symbol: String,
43 decimals: u8,
44 ) -> Self {
45 Self {
46 chain,
47 address,
48 name,
49 symbol,
50 decimals,
51 }
52 }
53}
54
55impl Display for Token {
56 fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
57 write!(f, "Token(symbol={}, name={})", self.symbol, self.name)
58 }
59}