perpcity_sdk/
constants.rs1use alloy::primitives::{Address, U256, address, uint};
7
8pub const MULTICALL3: Address = address!("cA11bde05977b3631167028862bE2a173976CA11");
12
13pub const Q96: U256 = U256::from_limbs([0, 0x1_0000_0000, 0, 0]);
15
16pub const Q96_U128: u128 = 1_u128 << 96;
18
19pub const SCALE_1E6: u32 = 1_000_000;
21
22pub const ONE_HALF: u32 = 500_000;
24
25pub const WAD: U256 = U256::from_limbs([1_000_000_000_000_000_000, 0, 0, 0]);
27
28pub const WAD_ONE_PERCENT: U256 = U256::from_limbs([10_000_000_000_000_000, 0, 0, 0]);
30
31pub const TICK_SPACING: i32 = 30;
33
34pub const TWAVG_WINDOW: u32 = 3600;
36
37pub const MIN_OPENING_MARGIN: u32 = 5_000_000;
39
40pub const INTERVAL: u64 = 86_400;
42
43pub const MIN_SQRT_PRICE_X96: U256 = uint!(2505414483750479311864138016_U256);
45
46pub const MAX_SQRT_PRICE_X96: U256 = uint!(2505414483750479311864138015696_U256);
48
49pub const MIN_TICK: i32 = -69_090;
51
52pub const MAX_TICK: i32 = 69_090;
54
55pub const ACCOUNTING_TOKEN_SUPPLY: U256 = U256::from_limbs([u64::MAX, u64::MAX >> 8, 0, 0]); pub const MAX_PROTOCOL_FEE: u32 = 50_000;
60
61pub const Q96_PRECISION: f64 = 0.000001;
68
69pub const ERC721_NAME: &str = "Perp City Positions";
71
72pub const ERC721_SYMBOL: &str = "PERPCITY";
74
75#[cfg(test)]
76mod tests {
77 use super::*;
78
79 #[test]
82 fn q96_equals_two_pow_96() {
83 assert_eq!(Q96, U256::from(1u64) << 96);
84 }
85
86 #[test]
87 fn q96_u128_equals_two_pow_96() {
88 assert_eq!(Q96_U128, 79_228_162_514_264_337_593_543_950_336);
89 }
90
91 #[test]
92 fn one_half_is_half_of_scale() {
93 assert_eq!(ONE_HALF, SCALE_1E6 / 2);
94 }
95
96 #[test]
97 fn wad_value() {
98 assert_eq!(WAD, U256::from(10u64).pow(U256::from(18)));
99 }
100
101 #[test]
102 fn wad_one_percent_value() {
103 assert_eq!(WAD_ONE_PERCENT, U256::from(10u64).pow(U256::from(16)));
104 }
105
106 #[test]
107 fn tick_range_symmetric() {
108 assert_eq!(MIN_TICK, -MAX_TICK);
109 }
110
111 #[test]
112 fn accounting_token_supply_is_uint120_max() {
113 assert_eq!(
114 ACCOUNTING_TOKEN_SUPPLY,
115 (U256::from(1u64) << 120) - U256::from(1u64)
116 );
117 }
118
119 #[test]
120 fn min_sqrt_price_less_than_max() {
121 assert!(MIN_SQRT_PRICE_X96 < MAX_SQRT_PRICE_X96);
122 }
123
124 #[test]
127 fn min_sqrt_price_x96_matches_contract() {
128 let expected = U256::from_str_radix("2505414483750479311864138016", 10).unwrap();
129 assert_eq!(MIN_SQRT_PRICE_X96, expected);
130 }
131
132 #[test]
133 fn max_sqrt_price_x96_matches_contract() {
134 let expected = U256::from_str_radix("2505414483750479311864138015696", 10).unwrap();
135 assert_eq!(MAX_SQRT_PRICE_X96, expected);
136 }
137}