perpcity_sdk/
constants.rs1use alloy::primitives::{Address, U256, address, uint};
7
8pub const POOL_MANAGER: Address = address!("05E73354cFDd6745C338b50BcFDfA3Aa6fA03408");
10
11pub const USDC: Address = address!("C1a5D4E99BB224713dd179eA9CA2Fa6600706210");
13
14pub const Q96: U256 = U256::from_limbs([0, 0x1_0000_0000, 0, 0]);
16
17pub const Q96_U128: u128 = 1_u128 << 96;
19
20pub const SCALE_1E6: u32 = 1_000_000;
22
23pub const ONE_HALF: u32 = 500_000;
25
26pub const WAD: U256 = U256::from_limbs([1_000_000_000_000_000_000, 0, 0, 0]);
28
29pub const WAD_ONE_PERCENT: U256 = U256::from_limbs([10_000_000_000_000_000, 0, 0, 0]);
31
32pub const TICK_SPACING: i32 = 30;
34
35pub const TWAVG_WINDOW: u32 = 3600;
37
38pub const MIN_OPENING_MARGIN: u32 = 5_000_000;
40
41pub const INTERVAL: u64 = 86_400;
43
44pub const MIN_SQRT_PRICE_X96: U256 = uint!(2505414483750479311864138016_U256);
46
47pub const MAX_SQRT_PRICE_X96: U256 = uint!(2505414483750479311864138015696_U256);
49
50pub const MIN_TICK: i32 = -69_090;
52
53pub const MAX_TICK: i32 = 69_090;
55
56pub const ACCOUNTING_TOKEN_SUPPLY: U256 = U256::from_limbs([u64::MAX, u64::MAX >> 8, 0, 0]); pub const MAX_PROTOCOL_FEE: u32 = 50_000;
61
62pub const ERC721_NAME: &str = "Perp City Positions";
64
65pub const ERC721_SYMBOL: &str = "PERPCITY";
67
68#[cfg(test)]
69mod tests {
70 use super::*;
71
72 #[test]
75 fn q96_equals_two_pow_96() {
76 assert_eq!(Q96, U256::from(1u64) << 96);
77 }
78
79 #[test]
80 fn q96_u128_equals_two_pow_96() {
81 assert_eq!(Q96_U128, 79_228_162_514_264_337_593_543_950_336);
82 }
83
84 #[test]
85 fn one_half_is_half_of_scale() {
86 assert_eq!(ONE_HALF, SCALE_1E6 / 2);
87 }
88
89 #[test]
90 fn wad_value() {
91 assert_eq!(WAD, U256::from(10u64).pow(U256::from(18)));
92 }
93
94 #[test]
95 fn wad_one_percent_value() {
96 assert_eq!(WAD_ONE_PERCENT, U256::from(10u64).pow(U256::from(16)));
97 }
98
99 #[test]
100 fn tick_range_symmetric() {
101 assert_eq!(MIN_TICK, -MAX_TICK);
102 }
103
104 #[test]
105 fn accounting_token_supply_is_uint120_max() {
106 assert_eq!(
107 ACCOUNTING_TOKEN_SUPPLY,
108 (U256::from(1u64) << 120) - U256::from(1u64)
109 );
110 }
111
112 #[test]
113 fn min_sqrt_price_less_than_max() {
114 assert!(MIN_SQRT_PRICE_X96 < MAX_SQRT_PRICE_X96);
115 }
116
117 #[test]
120 fn min_sqrt_price_x96_matches_contract() {
121 let expected = U256::from_str_radix("2505414483750479311864138016", 10).unwrap();
122 assert_eq!(MIN_SQRT_PRICE_X96, expected);
123 }
124
125 #[test]
126 fn max_sqrt_price_x96_matches_contract() {
127 let expected = U256::from_str_radix("2505414483750479311864138015696", 10).unwrap();
128 assert_eq!(MAX_SQRT_PRICE_X96, expected);
129 }
130
131 #[test]
134 fn usdc_address() {
135 assert_eq!(
136 USDC,
137 "0xC1a5D4E99BB224713dd179eA9CA2Fa6600706210"
138 .parse::<Address>()
139 .unwrap()
140 );
141 }
142
143 #[test]
144 fn pool_manager_address() {
145 assert_eq!(
146 POOL_MANAGER,
147 "0x05E73354cFDd6745C338b50BcFDfA3Aa6fA03408"
148 .parse::<Address>()
149 .unwrap()
150 );
151 }
152}