1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
use rust_decimal::Decimal;
use serde::{Deserialize, Serialize};
use serde_aux::prelude::*;

use crate::PoolStatus;

/*

*** Pool Statistics Scheme ***

{
		"addAssetLiquidityVolume": "21559093216525",
		"addLiquidityCount": "204",
		"addLiquidityVolume": "35549551832000",
		"addRuneLiquidityVolume": "13990458615475",
		"annualPercentageRate": "",
		"asset": "BTC.BTC",
		"assetDepth": "130912432302",
		"assetPrice": "8032.090469519714",
		"assetPriceUSD": "68607.11551099402",
		"averageSlip": "0.680060937697664",
		"earnings": "15616236427576",
		"earningsAnnualAsPercentOfDepth": "0.18069182395260117",
		"liquidityUnits": "389213036474226",
		"poolAPY": "",
		"runeDepth": "1051500499834539",
		"saversAPR": "",
		"status": PoolStatus,
		"swapCount": "371527",
		"swapVolume": "33935042500592046",
		"synthSupply": "99800573524",
		"synthUnits": "239739881003189",
		"toAssetAverageSlip": "1.193480577072595",
		"toAssetCount": "34727",
		"toAssetFees": "4281185337731",
		"toAssetVolume": "5129969138619083",
		"toRuneAverageSlip": "0.5035594614898463",
		"toRuneCount": "83861",
		"toRuneFees": "1182791124280",
		"toRuneVolume": "5129599530261148",
		"totalFees": "12165405926607",
		"uniqueMemberCount": "3644",
		"uniqueSwapperCount": "0",
		"units": "628952917477415",
		"withdrawAssetVolume": "55473673757483",
		"withdrawCount": "321",
		"withdrawRuneVolume": "40934592243966",
		"withdrawVolume": "96408266001449"
}

*/

#[derive(Debug, Serialize, Deserialize, Clone)]
pub struct PoolStatistics {
	#[serde(rename = "addAssetLiquidityVolume", deserialize_with = "deserialize_number_from_string")]
	add_asset_liquidity_volume: u64,

	#[serde(rename = "addLiquidityCount", deserialize_with = "deserialize_number_from_string")]
	add_liquidity_count: u64,

	#[serde(rename = "addLiquidityVolume", deserialize_with = "deserialize_number_from_string")]
	add_liquidity_volume: u64,

	#[serde(rename = "addRuneLiquidityVolume", deserialize_with = "deserialize_number_from_string")]
	add_rune_liquidity_volume: u64,

	#[serde(rename = "annualPercentageRate", with = "rust_decimal::serde::str_option")]
	annual_percentage_rate: Option<Decimal>,

	asset: String,

	#[serde(rename = "assetDepth", deserialize_with = "deserialize_number_from_string")]
	asset_depth: u64,

	#[serde(rename = "assetPrice", with = "rust_decimal::serde::str_option")]
	asset_price: Option<Decimal>,

	#[serde(rename = "assetPriceUSD", with = "rust_decimal::serde::str_option")]
	asset_price_usd: Option<Decimal>,

	#[serde(rename = "averageSlip", with = "rust_decimal::serde::str_option")]
	average_slip: Option<Decimal>,

	#[serde(deserialize_with = "deserialize_number_from_string")]
	earnings: u64,

	#[serde(rename = "earningsAnnualAsPercentOfDepth", with = "rust_decimal::serde::str_option")]
	earnings_annual_as_percent_of_depth: Option<Decimal>,

	#[serde(rename = "liquidityUnits", deserialize_with = "deserialize_number_from_string")]
	liquidity_units: u64,

	#[serde(rename = "poolAPY", with = "rust_decimal::serde::str_option")]
	pool_apy: Option<Decimal>,

	#[serde(rename = "runeDepth", deserialize_with = "deserialize_number_from_string")]
	rune_depth: u64,

	#[serde(rename = "saversAPR", with = "rust_decimal::serde::str_option")]
	savers_apr: Option<Decimal>,

	status: PoolStatus,

	#[serde(rename = "swapCount", deserialize_with = "deserialize_number_from_string")]
	swap_count: u64,

	#[serde(rename = "swapVolume", deserialize_with = "deserialize_number_from_string")]
	swap_volume: u64,

	#[serde(rename = "synthSupply", deserialize_with = "deserialize_number_from_string")]
	synth_supply: u64,

	#[serde(rename = "synthUnits", deserialize_with = "deserialize_number_from_string")]
	synth_units: u64,

	#[serde(rename = "toAssetAverageSlip", with = "rust_decimal::serde::str_option")]
	to_asset_average_slip: Option<Decimal>,

	#[serde(rename = "toAssetCount", deserialize_with = "deserialize_number_from_string")]
	to_asset_count: u64,

	#[serde(rename = "toAssetFees", deserialize_with = "deserialize_number_from_string")]
	to_asset_fees: u64,

	#[serde(rename = "toAssetVolume", deserialize_with = "deserialize_number_from_string")]
	to_asset_volume: u64,

	#[serde(rename = "toRuneAverageSlip", with = "rust_decimal::serde::str_option")]
	to_rune_average_slip: Option<Decimal>,

	#[serde(rename = "toRuneCount", deserialize_with = "deserialize_number_from_string")]
	to_rune_count: u64,

	#[serde(rename = "toRuneFees", deserialize_with = "deserialize_number_from_string")]
	to_rune_fees: u64,

	#[serde(rename = "toRuneVolume", deserialize_with = "deserialize_number_from_string")]
	to_rune_volume: u64,

	#[serde(rename = "totalFees", deserialize_with = "deserialize_number_from_string")]
	total_fees: u64,

	#[serde(rename = "uniqueMemberCount", deserialize_with = "deserialize_number_from_string")]
	unique_member_count: u64,

	#[serde(rename = "uniqueSwapperCount", deserialize_with = "deserialize_number_from_string")]
	unique_swapper_count: u64,

	#[serde(deserialize_with = "deserialize_number_from_string")]
	units: u64,

	#[serde(rename = "withdrawAssetVolume", deserialize_with = "deserialize_number_from_string")]
	withdraw_asset_volume: u64,

	#[serde(rename = "withdrawCount", deserialize_with = "deserialize_number_from_string")]
	withdraw_count: u64,

	#[serde(rename = "withdrawRuneVolume", deserialize_with = "deserialize_number_from_string")]
	withdraw_rune_volume: u64,

	#[serde(rename = "withdrawVolume", deserialize_with = "deserialize_number_from_string")]
	withdraw_volume: u64,
}

impl PoolStatistics {
	#[must_use]
	pub const fn get_add_asset_liquidity_volume(&self) -> &u64 {
		&self.add_asset_liquidity_volume
	}

	#[must_use]
	pub const fn get_add_liquidity_count(&self) -> &u64 {
		&self.add_liquidity_count
	}

	#[must_use]
	pub const fn get_add_liquidity_volume(&self) -> &u64 {
		&self.add_liquidity_volume
	}

	#[must_use]
	pub const fn get_add_rune_liquidity_volume(&self) -> &u64 {
		&self.add_rune_liquidity_volume
	}

	#[must_use]
	pub const fn get_annual_percentage_rate(&self) -> &Option<Decimal> {
		&self.annual_percentage_rate
	}

	#[must_use]
	pub fn get_asset(&self) -> &str {
		&self.asset
	}

	#[must_use]
	pub const fn get_asset_depth(&self) -> &u64 {
		&self.asset_depth
	}

	#[must_use]
	pub const fn get_asset_price(&self) -> &Option<Decimal> {
		&self.asset_price
	}

	#[must_use]
	pub const fn get_asset_price_usd(&self) -> &Option<Decimal> {
		&self.asset_price_usd
	}

	#[must_use]
	pub const fn get_average_slip(&self) -> &Option<Decimal> {
		&self.average_slip
	}

	#[must_use]
	pub const fn get_earnings(&self) -> &u64 {
		&self.earnings
	}

	#[must_use]
	pub const fn get_earnings_annual_as_percent_of_depth(&self) -> &Option<Decimal> {
		&self.earnings_annual_as_percent_of_depth
	}

	#[must_use]
	pub const fn get_liquidity_units(&self) -> &u64 {
		&self.liquidity_units
	}

	#[must_use]
	pub const fn get_pool_apy(&self) -> &Option<Decimal> {
		&self.pool_apy
	}

	#[must_use]
	pub const fn get_rune_depth(&self) -> &u64 {
		&self.rune_depth
	}

	#[must_use]
	pub const fn get_savers_apr(&self) -> &Option<Decimal> {
		&self.savers_apr
	}

	#[must_use]
	pub const fn get_status(&self) -> &PoolStatus {
		&self.status
	}

	#[must_use]
	pub const fn get_swap_count(&self) -> &u64 {
		&self.swap_count
	}

	#[must_use]
	pub const fn get_swap_volume(&self) -> &u64 {
		&self.swap_volume
	}

	#[must_use]

	pub const fn get_synth_supply(&self) -> &u64 {
		&self.synth_supply
	}

	#[must_use]
	pub const fn get_synth_units(&self) -> &u64 {
		&self.synth_units
	}

	#[must_use]
	pub const fn get_to_asset_average_slip(&self) -> &Option<Decimal> {
		&self.to_asset_average_slip
	}

	#[must_use]
	pub const fn get_to_asset_count(&self) -> &u64 {
		&self.to_asset_count
	}

	#[must_use]
	pub const fn get_to_asset_fees(&self) -> &u64 {
		&self.to_asset_fees
	}

	#[must_use]
	pub const fn get_to_asset_volume(&self) -> &u64 {
		&self.to_asset_volume
	}

	#[must_use]
	pub const fn get_to_rune_average_slip(&self) -> &Option<Decimal> {
		&self.to_rune_average_slip
	}

	#[must_use]
	pub const fn get_to_rune_count(&self) -> &u64 {
		&self.to_rune_count
	}

	#[must_use]
	pub const fn get_to_rune_fees(&self) -> &u64 {
		&self.to_rune_fees
	}

	#[must_use]
	pub const fn get_to_rune_volume(&self) -> &u64 {
		&self.to_rune_volume
	}

	#[must_use]
	pub const fn get_total_fees(&self) -> &u64 {
		&self.total_fees
	}

	#[must_use]
	pub const fn get_unique_member_count(&self) -> &u64 {
		&self.unique_member_count
	}

	#[must_use]
	pub const fn get_unique_swapper_count(&self) -> &u64 {
		&self.unique_swapper_count
	}

	#[must_use]
	pub const fn get_units(&self) -> &u64 {
		&self.units
	}

	#[must_use]
	pub const fn get_withdraw_asset_volume(&self) -> &u64 {
		&self.withdraw_asset_volume
	}

	#[must_use]
	pub const fn get_withdraw_count(&self) -> &u64 {
		&self.withdraw_count
	}

	#[must_use]
	pub const fn get_withdraw_rune_volume(&self) -> &u64 {
		&self.withdraw_rune_volume
	}

	#[must_use]
	pub const fn get_withdraw_volume(&self) -> &u64 {
		&self.withdraw_volume
	}
}

#[cfg(test)]
mod tests {
	use serde_json::json;

	use super::*;

	#[test]
	fn test_pool_statistics() {
		let data = json!({
			"addAssetLiquidityVolume": "24590890355026",
			"addLiquidityCount": "360",
			"addLiquidityVolume": "40221344358897",
			"addRuneLiquidityVolume": "15630454003871",
			"annualPercentageRate": "",
			"asset": "BTC.BTC",
			"assetDepth": "122158911333",
			"assetPrice": "8111.36126510733",
			"assetPriceUSD": "66087.27652984028",
			"averageSlip": "0.7842017800749017",
			"earnings": "13922336835230",
			"earningsAnnualAsPercentOfDepth": "0.1709483244297171",
			"liquidityUnits": "371333607382410",
			"poolAPY": "",
			"runeDepth": "990875061574177",
			"saversAPR": "",
			"status": "available",
			"swapCount": "453127",
			"swapVolume": "42931017080131394",
			"synthSupply": "91549958430",
			"synthUnits": "222530939275319",
			"toAssetAverageSlip": "1.104416718060629",
			"toAssetCount": "42158",
			"toAssetFees": "2675601169560",
			"toAssetVolume": "5359469309862998",
			"toRuneAverageSlip": "0.5682455108466249",
			"toRuneCount": "86709",
			"toRuneFees": "1213533800335",
			"toRuneVolume": "5382511018523059",
			"totalFees": "11903589201397",
			"uniqueMemberCount": "3605",
			"uniqueSwapperCount": "0",
			"units": "593864546657729",
			"withdrawAssetVolume": "96548803913783",
			"withdrawCount": "435",
			"withdrawRuneVolume": "65049683457029",
			"withdrawVolume": "161598487370812"
		})
		.to_string();

		let pool_statistics: PoolStatistics = serde_json::from_str(&data).unwrap();

		println!("pool_statistics: {}", json!(pool_statistics));

		assert_eq!(pool_statistics.get_add_asset_liquidity_volume(), &24590890355026);
	}
}