templar_common/
lib.rs

1pub mod accumulator;
2pub mod asset;
3pub mod borrow;
4pub mod chunked_append_only_list;
5pub mod event;
6pub mod fee;
7pub mod incoming_deposit;
8pub mod interest_rate_strategy;
9pub mod market;
10pub mod number;
11pub mod oracle;
12pub mod price;
13pub mod registry;
14pub mod snapshot;
15pub mod supply;
16pub mod time_chunk;
17#[cfg(feature = "rpc")]
18pub mod utils;
19pub mod vault;
20pub mod withdrawal_queue;
21
22pub use primitive_types;
23pub use schemars;
24
25/// Panic helper that works in both WASM and native contexts.
26///
27/// In WASM contexts (contract compilation), uses `near_sdk::env::panic_str`.
28/// In native contexts (bots, tests), uses standard `panic!`.
29#[cfg(target_arch = "wasm32")]
30#[inline]
31pub fn panic_with_message(msg: &str) -> ! {
32    near_sdk::env::panic_str(msg);
33}
34
35/// Panic helper that works in both WASM and native contexts.
36///
37/// In WASM contexts (contract compilation), uses `near_sdk::env::panic_str`.
38/// In native contexts (bots, tests), uses standard `panic!`.
39#[cfg(not(target_arch = "wasm32"))]
40#[inline]
41pub fn panic_with_message(msg: &str) -> ! {
42    panic!("{}", msg);
43}
44
45/// Approximation of `1 / (1000 * 60 * 60 * 24 * 365.2425)`.
46///
47/// exact = 0.00000000003168873850681143096456210346297...
48/// this  = 0.00000000003168873850681143096456210346
49///
50/// error =~ 9.375e-27 %
51pub static YEAR_PER_MS: number::Decimal =
52    number::Decimal::from_repr([0x40FC_AB61_4AE4_B2B5, 0x22D7_9641, 0, 0, 0, 0, 0, 0]);
53
54pub mod contract {
55    pub fn list<T, U: FromIterator<T>>(
56        i: impl IntoIterator<Item = T>,
57        offset: Option<u32>,
58        count: Option<u32>,
59    ) -> U {
60        let offset = offset.map_or(0, |o| o as usize);
61        let count = count.map_or(usize::MAX, |c| c as usize);
62        i.into_iter().skip(offset).take(count).collect()
63    }
64
65    #[macro_export]
66    macro_rules! self_ext {
67        ($gas:expr) => {
68            Self::ext(::near_sdk::env::current_account_id()).with_static_gas($gas)
69        };
70    }
71}