Skip to main content

icydb/base/types/
finance.rs

1use crate::design::prelude::*;
2
3///
4/// Usd
5///
6/// Decimal amount denominated in USD.
7/// - Enforces at most 2 decimal places.
8/// - Must be non-negative.
9///
10
11#[newtype(
12    primitive = "Decimal",
13    item(prim = "Decimal", scale = 2),
14    ty(
15        sanitizer(path = "base::sanitizer::num::RoundDecimalPlaces", args(2)),
16        validator(path = "base::validator::decimal::MaxDecimalPlaces", args(2)),
17        validator(path = "base::validator::num::Gte", args(0))
18    )
19)]
20pub struct Usd {}
21
22///
23/// E8s
24///
25/// Decimal amount constrained to at most 8 decimal places and non-negative.
26///
27
28#[newtype(
29    primitive = "Decimal",
30    item(prim = "Decimal", scale = 8),
31    ty(
32        validator(path = "base::validator::decimal::MaxDecimalPlaces", args(8)),
33        validator(path = "base::validator::num::Gte", args(0))
34    )
35)]
36pub struct E8s {}
37
38///
39/// E18s
40///
41/// Decimal amount constrained to at most 18 decimal places and non-negative.
42///
43
44#[newtype(
45    primitive = "Decimal",
46    item(prim = "Decimal", scale = 18),
47    ty(
48        validator(path = "base::validator::decimal::MaxDecimalPlaces", args(18)),
49        validator(path = "base::validator::num::Gte", args(0))
50    )
51)]
52pub struct E18s {}