miraland_program/
native_token.rs1#![allow(clippy::arithmetic_side_effects)]
4
5pub const LAMPORTS_PER_MLN: u64 = 1_000_000_000;
7
8pub fn lamports_to_mln(lamports: u64) -> f64 {
10 lamports as f64 / LAMPORTS_PER_MLN as f64
11}
12
13pub fn mln_to_lamports(mln: f64) -> u64 {
15 (mln * LAMPORTS_PER_MLN as f64) as u64
16}
17
18use std::fmt::{Debug, Display, Formatter, Result};
19pub struct Mln(pub u64);
20
21impl Mln {
22 fn write_in_mln(&self, f: &mut Formatter) -> Result {
23 write!(
24 f,
25 "𝇊{}.{:09}",
26 self.0 / LAMPORTS_PER_MLN,
27 self.0 % LAMPORTS_PER_MLN
28 )
29 }
30}
31
32impl Display for Mln {
33 fn fmt(&self, f: &mut Formatter) -> Result {
34 self.write_in_mln(f)
35 }
36}
37
38impl Debug for Mln {
39 fn fmt(&self, f: &mut Formatter) -> Result {
40 self.write_in_mln(f)
41 }
42}