Skip to main content

hyperspace_rs/
types.rs

1use serde::{Deserialize, Serialize};
2
3// Object {
4//     "animation_url": Null,
5//     "attributes": Object {
6//         "Background": Object {
7//             "value": String("Beige"),
8//         },
9//         "Clothing": Object {
10//             "value": String("Sherlock"),
11//         },
12//         "Hair": Object {
13//             "value": String("Buzz Taper"),
14//         },
15//         "Mask": Object {
16//             "value": String("Mori Kitsune"),
17//         },
18//         "Skin": Object {
19//             "value": String("Yuki"),
20//         },
21//         "Special": Object {
22//             "value": String("None"),
23//         },
24//     },
25//     "bid_snapshot": Object {
26//         "amount": Null,
27//         "block_number": Null,
28//         "block_timestamp": Null,
29//         "buyer_address": Null,
30//         "buyer_referral_address": Null,
31//         "buyer_referral_fee": Null,
32//         "created_at": Null,
33//         "currency": Null,
34//         "currency_price": Null,
35//         "decimal": Null,
36//         "display_price": Null,
37//         "escrow_address": Null,
38//         "expiry_time": Null,
39//         "fee": Null,
40//         "metadata": Null,
41//         "price": Null,
42//         "program_fee_address": Null,
43//         "program_id": Null,
44//         "program_instance_id": Null,
45//         "project_id": String("c43f2070-8d90-40f2-a81a-d564889263ee"),
46//         "token_address": String("0x54c800d2331e10467143911aabca092d68bf4166_643"),
47//         "tx_id": Null,
48//         "updated_at": Null,
49//     },
50//     "created_at": Null,
51//     "creator_royalty": Null,
52//     "feeless_floor_price": Number(42.43902439024391),
53//     "floor_price": Number(43.50000000000001),
54//     "floor_price_1day_change": Number(-0.0021),
55//     "is_project_verified": Bool(true),
56//     "last_sale_snapshot": Null,
57//     "listing_snapshot": Object {
58//         "amount": Null,
59//         "block_number": Null,
60//         "block_timestamp": Null,
61//         "created_at": Null,
62//         "currency": Null,
63//         "currency_price": Null,
64//         "decimal": Null,
65//         "display_price": Null,
66//         "escrow_address": Null,
67//         "expiry_time": Null,
68//         "fee": Null,
69//         "listing_type": String("NOT_LISTED"),
70//         "marketplace_config": Object {
71//             "display_name": Null,
72//             "id": Null,
73//             "img_url": Null,
74//             "is_bidding_enabled": Null,
75//             "is_bulk_buy_enabled": Null,
76//             "is_buying_enabled": Null,
77//             "is_delisting_enabled": Null,
78//             "is_listing_enabled": Null,
79//             "is_sweeping_enabled": Null,
80//             "item_path": Null,
81//             "program_id": Null,
82//             "program_instance_id": Null,
83//             "protocol": Null,
84//             "should_redirect": Null,
85//             "website": Null,
86//         },
87//         "metadata": Null,
88//         "price": Null,
89//         "program_fee_address": Null,
90//         "program_id": Null,
91//         "program_instance_id": Null,
92//         "project_id": String("c43f2070-8d90-40f2-a81a-d564889263ee"),
93//         "seller_address": Null,
94//         "seller_referral_address": Null,
95//         "seller_referral_fee": Null,
96//         "token_address": String("0x54c800d2331e10467143911aabca092d68bf4166_643"),
97//         "tx_id": Null,
98//         "updated_at": Null,
99//     },
100//     "marketplace_state": Null,
101//     "metadata_img": String("https://ipfs.io/ipfs/bafybeifh7tfdndlqw3cmokhfkajnyvwsi36ijzrbv3jocu46e3xvsdokge/643"),
102//     "metadata_uri": String(""),
103//     "name": String("Dokyo #643"),
104//     "nft_standard": String("ERC721"),
105//     "non_marketplace_state": Null,
106//     "owner": String("0x8cdd7a500f21455361cf1c2e01c0525ce92481b2"),
107//     "project_description": String("A world of courage awaits."),
108//     "project_display_name_type": String("NAME_TOKEN_ID"),
109//     "project_id": String("c43f2070-8d90-40f2-a81a-d564889263ee"),
110//     "project_image": String("https://storage.googleapis.com/feliz-crypto/project_photos/dokyopfp.png"),
111//     "project_metadata": Object {
112//         "allow_list_id": Null,
113//         "contract_address": String("0x54c800d2331e10467143911aabca092d68bf4166"),
114//         "minimum_royalty": Null,
115//         "orderbook_id": Null,
116//         "royalty_strategy_id": String("0x610512654af4fa883bb727afdff2dd78b65342b7"),
117//         "token_type": Null,
118//         "transfer_policy_id": Null,
119//         "withdraw_policy_id": Null,
120//     },
121//     "project_name": String("Dokyo"),
122//     "project_protocol": String("AVAX"),
123//     "project_slug": String("dokyo"),
124//     "project_supply": Number(5555),
125//     "rarity_snapshot": Object {
126//         "hyperspace": Number(5402),
127//         "project_id": Null,
128//         "token_address": Null,
129//     },
130//     "supply": Number(1),
131//     "token_address": String("0x54c800d2331e10467143911aabca092d68bf4166_643"),
132//     "token_id": String("643"),
133//     "token_type": Null,
134//     "updated_at": Null,
135// },
136#[derive(Debug, Clone, Deserialize, Serialize)]
137pub struct MarketplaceSnapshot {
138    // pub animation_url: Option<String>,
139    // pub attributes: MarketplaceSnapshotAttributes,
140    // pub bid_snapshot: MarketplaceSnapshotBidSnapshot,
141    // pub created_at: Option<String>,
142    // pub creator_royalty: Option<String>,
143    // pub feeless_floor_price: f64,
144    // pub floor_price: f64,
145    // pub floor_price_1day_change: f64,
146    // pub is_project_verified: bool,
147    // pub last_sale_snapshot: Option<String>,
148    // pub listing_snapshot: MarketplaceSnapshotListingSnapshot,
149    // pub marketplace_state: Option<String>,
150    // pub metadata_img: String,
151    // pub metadata_uri: String,
152    // pub name: String,
153    // pub nft_standard: String,
154    // pub non_marketplace_state: Option<String>,
155    // pub owner: String,
156    // pub project_description: String,
157    // pub project_display_name_type: String,
158    // pub project_id: String,
159    // pub project_image: String,
160    // pub project_metadata: MarketplaceSnapshotProjectMetadata,
161    // pub project_name: String,
162    // pub project_protocol: String,
163    // pub project_slug: String,
164    // pub project_supply: u64,
165    // pub rarity_snapshot: MarketplaceSnapshotRaritySnapshot,
166    // pub supply: u64,
167    pub token_address: String,
168    // pub token_id: String,
169    // pub token_type: Option<String>,
170    // pub updated_at: Option<String>,
171}
172
173#[derive(Debug, Clone, Deserialize, Serialize)]
174pub struct MarketplaceSnapshotAttributes {
175    #[serde(rename = "Background")]
176    pub background: MarketplaceSnapshotAttribute,
177    #[serde(rename = "Clothing")]
178    pub clothing: MarketplaceSnapshotAttribute,
179    #[serde(rename = "Hair")]
180    pub hair: MarketplaceSnapshotAttribute,
181    #[serde(rename = "Mask")]
182    pub mask: MarketplaceSnapshotAttribute,
183    #[serde(rename = "Skin")]
184    pub skin: MarketplaceSnapshotAttribute,
185    #[serde(rename = "Special")]
186    pub special: MarketplaceSnapshotAttribute,
187}
188
189#[derive(Debug, Clone, Deserialize, Serialize)]
190pub struct MarketplaceSnapshotAttribute {
191    pub value: String,
192}
193
194#[derive(Debug, Clone, Deserialize, Serialize)]
195pub struct MarketplaceSnapshotBidSnapshot {
196    pub amount: Option<String>,
197    pub block_number: Option<String>,
198    pub block_timestamp: Option<String>,
199    pub buyer_address: Option<String>,
200    pub buyer_referral_address: Option<String>,
201    pub buyer_referral_fee: Option<String>,
202    pub created_at: Option<String>,
203    pub currency: Option<String>,
204    pub currency_price: Option<String>,
205    pub decimal: Option<String>,
206    pub display_price: Option<String>,
207    pub escrow_address: Option<String>,
208    pub expiry_time: Option<String>,
209    pub fee: Option<String>,
210    pub metadata: Option<Metadata>,
211    pub price: Option<String>,
212    pub program_fee_address: Option<String>,
213    pub program_id: Option<String>,
214    pub program_instance_id: Option<String>,
215    pub project_id: String,
216    pub token_address: String,
217    pub tx_id: Option<String>,
218    pub updated_at: Option<String>,
219}
220
221#[derive(Debug, Clone, Deserialize, Serialize)]
222pub struct MarketplaceSnapshotListingSnapshot {
223    pub amount: Option<u64>,
224    pub block_number: Option<u64>,
225    pub block_timestamp: Option<u64>,
226    pub created_at: Option<String>,
227    pub currency: Option<String>,
228    pub currency_price: Option<f64>,
229    pub decimal: Option<u64>,
230    pub display_price: Option<f64>,
231    pub escrow_address: Option<String>,
232    pub expiry_time: Option<String>,
233    pub fee: Option<f64>,
234    pub listing_type: String,
235    pub marketplace_config: MarketplaceSnapshotMarketplaceConfig,
236    pub metadata: Option<Metadata>,
237    pub price: Option<f64>,
238    pub program_fee_address: Option<String>,
239    pub program_id: Option<String>,
240    pub program_instance_id: Option<String>,
241    pub project_id: String,
242    pub seller_address: Option<String>,
243    pub seller_referral_address: Option<String>,
244    pub seller_referral_fee: Option<f64>,
245    pub token_address: String,
246    pub tx_id: Option<String>,
247    pub updated_at: Option<String>,
248}
249
250#[derive(Debug, Clone, Deserialize, Serialize)]
251pub struct MarketplaceSnapshotMarketplaceConfig {
252    pub display_name: Option<String>,
253    pub id: Option<String>,
254    pub img_url: Option<String>,
255    pub is_bidding_enabled: Option<String>,
256    pub is_bulk_buy_enabled: Option<String>,
257    pub is_buying_enabled: Option<String>,
258    pub is_delisting_enabled: Option<String>,
259    pub is_listing_enabled: Option<String>,
260    pub is_sweeping_enabled: Option<String>,
261    pub item_path: Option<String>,
262    pub program_id: Option<String>,
263    pub program_instance_id: Option<String>,
264    pub protocol: Option<String>,
265    pub should_redirect: Option<String>,
266    pub website: Option<String>,
267}
268
269#[derive(Debug, Clone, Deserialize, Serialize)]
270pub struct MarketplaceSnapshotProjectMetadata {
271    pub allow_list_id: Option<String>,
272    pub contract_address: String,
273    pub minimum_royalty: Option<String>,
274    pub orderbook_id: Option<String>,
275    pub royalty_strategy_id: String,
276    pub token_type: Option<String>,
277    pub transfer_policy_id: Option<String>,
278    pub withdraw_policy_id: Option<String>,
279}
280
281#[derive(Debug, Clone, Deserialize, Serialize)]
282pub struct MarketplaceSnapshotRaritySnapshot {
283    pub hyperspace: Option<String>,
284    pub project_id: Option<String>,
285    pub token_address: Option<String>,
286}
287
288#[derive(Debug, Clone, Deserialize, Serialize)]
289pub struct CollectionStats {
290    pub average_price: f64,
291    pub average_price_1day_change: f64,
292    pub average_price_7day_change: f64,
293    pub created_at: String,
294    pub discord_members: Option<u64>,
295    pub feeless_floor_price: f64,
296    pub floor_price: f64,
297    pub floor_price_1day_change: f64,
298    pub market_cap: u64,
299    pub max_price: u64,
300    pub num_of_token_holders: u64,
301    pub num_of_token_listed: u64,
302    pub percentage_of_token_listed: f64,
303    pub project: Project,
304    pub project_id: String,
305    pub rank: Option<u64>,
306    pub raw_market_cap: u64,
307    pub raw_volume: Option<u64>,
308    pub raw_volume_1day: f64,
309    pub raw_volume_1day_change: f64,
310    pub raw_volume_1hr: f64,
311    pub raw_volume_7day: f64,
312    pub raw_volume_7day_change: f64,
313    pub supply: u64,
314    pub twitter_followers: Option<u64>,
315    pub updated_at: String,
316    pub volume: Option<u64>,
317    pub volume_15m: Option<u64>,
318    pub volume_1day: f64,
319    pub volume_1day_change: f64,
320    pub volume_1hr: f64,
321    pub volume_1m: Option<u64>,
322    pub volume_30m: Option<u64>,
323    pub volume_5m: Option<u64>,
324    pub volume_7day: f64,
325    pub volume_7day_change: f64,
326}
327
328#[derive(Debug, Clone, Deserialize, Serialize)]
329pub struct Project {
330    pub allow_list_id: Option<u64>,
331    pub banner_url: String,
332    pub contract_address: String,
333    pub created_at: Option<String>,
334    pub description: String,
335    pub discord: Option<String>,
336    pub display_id: Option<u64>,
337    pub display_name: String,
338    pub display_name_type: String,
339    pub img_url: String,
340    pub is_launchpad: bool,
341    pub is_trading_disabled: bool,
342    pub is_trading_enabled: bool,
343    pub is_verified: bool,
344    pub launch_date: Option<String>,
345    pub launch_timestamp: Option<String>,
346    pub launchpad_details: Option<String>,
347    pub metadata: CollectionMetadata,
348    pub minimum_royalty: Option<String>,
349    pub orderbook_id: Option<u64>,
350    pub project_attributes: Option<String>,
351    pub project_id: String,
352    pub project_identifiers: Option<String>,
353    pub project_slug: String,
354    pub protocol: String,
355    pub rarities: Option<String>,
356    pub rewards_earning: bool,
357    pub royalty: Option<String>,
358    pub royalty_strategy_id: Option<String>,
359    pub short_description: Option<String>,
360    pub supply: u64,
361    pub token_type: Option<String>,
362    pub transfer_policy_id: Option<String>,
363    pub twitter: String,
364    pub updated_at: Option<String>,
365    pub website: String,
366    pub withdraw_policy_id: Option<String>,
367}
368
369#[derive(Debug, Clone, Deserialize, Serialize)]
370pub struct CollectionMetadata {
371    pub allow_list_id: Option<u64>,
372    pub orderbook_id: Option<u64>,
373    pub royalty_strategy_id: String,
374    pub token_type: Option<String>,
375    pub transfer_policy_id: Option<String>,
376    pub withdraw_policy_id: Option<String>,
377}
378
379#[derive(Debug, Clone, Deserialize, Serialize)]
380pub struct Bid {
381    pub amount: u64,
382    pub block_number: u64,
383    pub block_timestamp: u64,
384    pub buyer_address: String,
385    pub buyer_referral_address: String,
386    pub buyer_referral_fee: f64,
387    pub created_at: String,
388    pub currency: String,
389    pub currency_price: f64,
390    pub decimal: u64,
391    pub display_price: f64,
392    pub expiration: Option<String>,
393    pub expiry_time: Option<String>,
394    pub fee: f64,
395    pub fee_address: Option<String>,
396    pub identifier_index: u64,
397    pub identifier_key: String,
398    pub identifier_type: String,
399    pub instruction_index: Option<String>,
400    pub metadata: Metadata,
401    pub price: f64,
402    pub program_id: String,
403    pub program_instance_id: String,
404    pub protocol: Option<String>,
405    pub seller_address: String,
406    pub seller_referral_address: String,
407    pub seller_referral_fee: f64,
408    pub trade_state: String,
409    pub tx_id: String,
410    pub r#type: String,
411    pub updated_at: String,
412}
413
414#[derive(Debug, Clone, Deserialize, Serialize)]
415pub struct Metadata {
416    pub event_log: EventLog,
417    pub is_offchain: bool,
418    pub raw_total_price: String,
419}
420
421#[derive(Debug, Clone, Deserialize, Serialize)]
422pub struct EventLog {
423    pub direction: u64,
424    #[serde(rename = "erc20Token")]
425    pub erc20_token: String,
426    #[serde(rename = "erc20TokenAmount")]
427    pub erc20_token_amount: String,
428    #[serde(rename = "erc721Token")]
429    pub erc721_token: String,
430    #[serde(rename = "erc721TokenId")]
431    pub erc721_token_id: String,
432    #[serde(rename = "erc721TokenProperties")]
433    pub erc721_token_properties: Vec<Erc721TokenProperties>,
434    pub expiry: String,
435    pub fees: Vec<Fee>,
436    pub maker: String,
437    pub nonce: String,
438    #[serde(rename = "rawSignature")]
439    pub raw_signature: String,
440    pub signature: Signature,
441    pub taker: String,
442}
443
444#[derive(Debug, Clone, Deserialize, Serialize)]
445pub struct Erc721TokenProperties {
446    #[serde(rename = "propertyData")]
447    pub property_data: Vec<String>,
448    #[serde(rename = "propertyValidator")]
449    pub property_validator: String,
450}
451
452#[derive(Debug, Clone, Deserialize, Serialize)]
453pub struct Fee {
454    pub amount: String,
455    #[serde(rename = "feeData")]
456    pub fee_data: String,
457    pub recipient: String,
458}
459
460#[derive(Debug, Clone, Deserialize, Serialize)]
461pub struct Signature {
462    pub r: String,
463    pub s: String,
464    #[serde(rename = "signatureType")]
465    pub signature_type: u64,
466    pub v: u64,
467}
468
469// fn deserialize_u256_from_u64<'de, D>(deserializer: D) -> Result<U256, D::Error>
470// where
471//     D: Deserializer<'de>,
472// {
473//     let s: u64 = Deserialize::deserialize(deserializer)?;
474//     if s == 0 {
475//         Ok(U256::zero())
476//     } else {
477//         Ok(U256::from(s))
478//     }
479// }
480
481// fn deserialize_u256_from_option_u64<'de, D>(deserializer: D) -> Result<Option<U256>, D::Error>
482// where
483//     D: Deserializer<'de>,
484// {
485//     let s: Option<u64> = Deserialize::deserialize(deserializer)?;
486//     if let Some(s) = s {
487//         if s == 0 {
488//             Ok(Some(U256::zero()))
489//         } else {
490//             Ok(Some(U256::from(s)))
491//         }
492//     } else {
493//         Ok(None)
494//     }
495// }
496
497// fn deserialize_u256_radix_10<'de, D>(deserializer: D) -> Result<U256, D::Error>
498// where
499//     D: Deserializer<'de>,
500// {
501//     let s: String = Deserialize::deserialize(deserializer)?;
502//     U256::from_str_radix(&s, 10).map_err(serde::de::Error::custom)
503// }
504
505// fn deserialize_address_on_empty<'de, D>(deserializer: D) -> Result<H160, D::Error>
506// where
507//     D: Deserializer<'de>,
508// {
509//     let s: String = Deserialize::deserialize(deserializer)?;
510//     if s.is_empty() {
511//         Ok(H160::zero())
512//     } else {
513//         Ok(H160::from_str(&s).map_err(serde::de::Error::custom)?)
514//     }
515// }
516
517#[derive(Debug, Serialize)]
518pub(crate) struct PaginationConfig {
519    pub(crate) page_number: u64,
520    pub(crate) page_size: Option<u64>,
521}
522
523impl PaginationConfig {
524    pub(crate) fn new(page_number: u64, page_size: Option<u64>) -> Self {
525        Self {
526            page_number,
527            page_size,
528        }
529    }
530
531    pub(crate) fn default() -> Self {
532        Self {
533            page_number: 1,
534            page_size: Some(32),
535        }
536    }
537}
538
539#[derive(Debug, Deserialize)]
540pub(crate) struct PaginationInfo {
541    pub(crate) current_page_number: u64,
542    pub(crate) current_page_size: u64,
543    pub(crate) has_next_page: bool,
544    pub(crate) total_page_number: Option<u64>,
545}