hyperspace-rs 0.2.0

A Rust library to interact with [Hyperspace](https://avax.hyperspace.xyz/) NFT marketplace on Avalanche
Documentation
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
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
use serde::{Deserialize, Serialize};

// Object {
//     "animation_url": Null,
//     "attributes": Object {
//         "Background": Object {
//             "value": String("Beige"),
//         },
//         "Clothing": Object {
//             "value": String("Sherlock"),
//         },
//         "Hair": Object {
//             "value": String("Buzz Taper"),
//         },
//         "Mask": Object {
//             "value": String("Mori Kitsune"),
//         },
//         "Skin": Object {
//             "value": String("Yuki"),
//         },
//         "Special": Object {
//             "value": String("None"),
//         },
//     },
//     "bid_snapshot": Object {
//         "amount": Null,
//         "block_number": Null,
//         "block_timestamp": Null,
//         "buyer_address": Null,
//         "buyer_referral_address": Null,
//         "buyer_referral_fee": Null,
//         "created_at": Null,
//         "currency": Null,
//         "currency_price": Null,
//         "decimal": Null,
//         "display_price": Null,
//         "escrow_address": Null,
//         "expiry_time": Null,
//         "fee": Null,
//         "metadata": Null,
//         "price": Null,
//         "program_fee_address": Null,
//         "program_id": Null,
//         "program_instance_id": Null,
//         "project_id": String("c43f2070-8d90-40f2-a81a-d564889263ee"),
//         "token_address": String("0x54c800d2331e10467143911aabca092d68bf4166_643"),
//         "tx_id": Null,
//         "updated_at": Null,
//     },
//     "created_at": Null,
//     "creator_royalty": Null,
//     "feeless_floor_price": Number(42.43902439024391),
//     "floor_price": Number(43.50000000000001),
//     "floor_price_1day_change": Number(-0.0021),
//     "is_project_verified": Bool(true),
//     "last_sale_snapshot": Null,
//     "listing_snapshot": Object {
//         "amount": Null,
//         "block_number": Null,
//         "block_timestamp": Null,
//         "created_at": Null,
//         "currency": Null,
//         "currency_price": Null,
//         "decimal": Null,
//         "display_price": Null,
//         "escrow_address": Null,
//         "expiry_time": Null,
//         "fee": Null,
//         "listing_type": String("NOT_LISTED"),
//         "marketplace_config": Object {
//             "display_name": Null,
//             "id": Null,
//             "img_url": Null,
//             "is_bidding_enabled": Null,
//             "is_bulk_buy_enabled": Null,
//             "is_buying_enabled": Null,
//             "is_delisting_enabled": Null,
//             "is_listing_enabled": Null,
//             "is_sweeping_enabled": Null,
//             "item_path": Null,
//             "program_id": Null,
//             "program_instance_id": Null,
//             "protocol": Null,
//             "should_redirect": Null,
//             "website": Null,
//         },
//         "metadata": Null,
//         "price": Null,
//         "program_fee_address": Null,
//         "program_id": Null,
//         "program_instance_id": Null,
//         "project_id": String("c43f2070-8d90-40f2-a81a-d564889263ee"),
//         "seller_address": Null,
//         "seller_referral_address": Null,
//         "seller_referral_fee": Null,
//         "token_address": String("0x54c800d2331e10467143911aabca092d68bf4166_643"),
//         "tx_id": Null,
//         "updated_at": Null,
//     },
//     "marketplace_state": Null,
//     "metadata_img": String("https://ipfs.io/ipfs/bafybeifh7tfdndlqw3cmokhfkajnyvwsi36ijzrbv3jocu46e3xvsdokge/643"),
//     "metadata_uri": String(""),
//     "name": String("Dokyo #643"),
//     "nft_standard": String("ERC721"),
//     "non_marketplace_state": Null,
//     "owner": String("0x8cdd7a500f21455361cf1c2e01c0525ce92481b2"),
//     "project_description": String("A world of courage awaits."),
//     "project_display_name_type": String("NAME_TOKEN_ID"),
//     "project_id": String("c43f2070-8d90-40f2-a81a-d564889263ee"),
//     "project_image": String("https://storage.googleapis.com/feliz-crypto/project_photos/dokyopfp.png"),
//     "project_metadata": Object {
//         "allow_list_id": Null,
//         "contract_address": String("0x54c800d2331e10467143911aabca092d68bf4166"),
//         "minimum_royalty": Null,
//         "orderbook_id": Null,
//         "royalty_strategy_id": String("0x610512654af4fa883bb727afdff2dd78b65342b7"),
//         "token_type": Null,
//         "transfer_policy_id": Null,
//         "withdraw_policy_id": Null,
//     },
//     "project_name": String("Dokyo"),
//     "project_protocol": String("AVAX"),
//     "project_slug": String("dokyo"),
//     "project_supply": Number(5555),
//     "rarity_snapshot": Object {
//         "hyperspace": Number(5402),
//         "project_id": Null,
//         "token_address": Null,
//     },
//     "supply": Number(1),
//     "token_address": String("0x54c800d2331e10467143911aabca092d68bf4166_643"),
//     "token_id": String("643"),
//     "token_type": Null,
//     "updated_at": Null,
// },
#[derive(Debug, Clone, Deserialize, Serialize)]
pub struct MarketplaceSnapshot {
    // pub animation_url: Option<String>,
    // pub attributes: MarketplaceSnapshotAttributes,
    // pub bid_snapshot: MarketplaceSnapshotBidSnapshot,
    // pub created_at: Option<String>,
    // pub creator_royalty: Option<String>,
    // pub feeless_floor_price: f64,
    // pub floor_price: f64,
    // pub floor_price_1day_change: f64,
    // pub is_project_verified: bool,
    // pub last_sale_snapshot: Option<String>,
    // pub listing_snapshot: MarketplaceSnapshotListingSnapshot,
    // pub marketplace_state: Option<String>,
    // pub metadata_img: String,
    // pub metadata_uri: String,
    // pub name: String,
    // pub nft_standard: String,
    // pub non_marketplace_state: Option<String>,
    // pub owner: String,
    // pub project_description: String,
    // pub project_display_name_type: String,
    // pub project_id: String,
    // pub project_image: String,
    // pub project_metadata: MarketplaceSnapshotProjectMetadata,
    // pub project_name: String,
    // pub project_protocol: String,
    // pub project_slug: String,
    // pub project_supply: u64,
    // pub rarity_snapshot: MarketplaceSnapshotRaritySnapshot,
    // pub supply: u64,
    pub token_address: String,
    // pub token_id: String,
    // pub token_type: Option<String>,
    // pub updated_at: Option<String>,
}

#[derive(Debug, Clone, Deserialize, Serialize)]
pub struct MarketplaceSnapshotAttributes {
    #[serde(rename = "Background")]
    pub background: MarketplaceSnapshotAttribute,
    #[serde(rename = "Clothing")]
    pub clothing: MarketplaceSnapshotAttribute,
    #[serde(rename = "Hair")]
    pub hair: MarketplaceSnapshotAttribute,
    #[serde(rename = "Mask")]
    pub mask: MarketplaceSnapshotAttribute,
    #[serde(rename = "Skin")]
    pub skin: MarketplaceSnapshotAttribute,
    #[serde(rename = "Special")]
    pub special: MarketplaceSnapshotAttribute,
}

#[derive(Debug, Clone, Deserialize, Serialize)]
pub struct MarketplaceSnapshotAttribute {
    pub value: String,
}

#[derive(Debug, Clone, Deserialize, Serialize)]
pub struct MarketplaceSnapshotBidSnapshot {
    pub amount: Option<String>,
    pub block_number: Option<String>,
    pub block_timestamp: Option<String>,
    pub buyer_address: Option<String>,
    pub buyer_referral_address: Option<String>,
    pub buyer_referral_fee: Option<String>,
    pub created_at: Option<String>,
    pub currency: Option<String>,
    pub currency_price: Option<String>,
    pub decimal: Option<String>,
    pub display_price: Option<String>,
    pub escrow_address: Option<String>,
    pub expiry_time: Option<String>,
    pub fee: Option<String>,
    pub metadata: Option<Metadata>,
    pub price: Option<String>,
    pub program_fee_address: Option<String>,
    pub program_id: Option<String>,
    pub program_instance_id: Option<String>,
    pub project_id: String,
    pub token_address: String,
    pub tx_id: Option<String>,
    pub updated_at: Option<String>,
}

#[derive(Debug, Clone, Deserialize, Serialize)]
pub struct MarketplaceSnapshotListingSnapshot {
    pub amount: Option<u64>,
    pub block_number: Option<u64>,
    pub block_timestamp: Option<u64>,
    pub created_at: Option<String>,
    pub currency: Option<String>,
    pub currency_price: Option<f64>,
    pub decimal: Option<u64>,
    pub display_price: Option<f64>,
    pub escrow_address: Option<String>,
    pub expiry_time: Option<String>,
    pub fee: Option<f64>,
    pub listing_type: String,
    pub marketplace_config: MarketplaceSnapshotMarketplaceConfig,
    pub metadata: Option<Metadata>,
    pub price: Option<f64>,
    pub program_fee_address: Option<String>,
    pub program_id: Option<String>,
    pub program_instance_id: Option<String>,
    pub project_id: String,
    pub seller_address: Option<String>,
    pub seller_referral_address: Option<String>,
    pub seller_referral_fee: Option<f64>,
    pub token_address: String,
    pub tx_id: Option<String>,
    pub updated_at: Option<String>,
}

#[derive(Debug, Clone, Deserialize, Serialize)]
pub struct MarketplaceSnapshotMarketplaceConfig {
    pub display_name: Option<String>,
    pub id: Option<String>,
    pub img_url: Option<String>,
    pub is_bidding_enabled: Option<String>,
    pub is_bulk_buy_enabled: Option<String>,
    pub is_buying_enabled: Option<String>,
    pub is_delisting_enabled: Option<String>,
    pub is_listing_enabled: Option<String>,
    pub is_sweeping_enabled: Option<String>,
    pub item_path: Option<String>,
    pub program_id: Option<String>,
    pub program_instance_id: Option<String>,
    pub protocol: Option<String>,
    pub should_redirect: Option<String>,
    pub website: Option<String>,
}

#[derive(Debug, Clone, Deserialize, Serialize)]
pub struct MarketplaceSnapshotProjectMetadata {
    pub allow_list_id: Option<String>,
    pub contract_address: String,
    pub minimum_royalty: Option<String>,
    pub orderbook_id: Option<String>,
    pub royalty_strategy_id: String,
    pub token_type: Option<String>,
    pub transfer_policy_id: Option<String>,
    pub withdraw_policy_id: Option<String>,
}

#[derive(Debug, Clone, Deserialize, Serialize)]
pub struct MarketplaceSnapshotRaritySnapshot {
    pub hyperspace: Option<String>,
    pub project_id: Option<String>,
    pub token_address: Option<String>,
}

#[derive(Debug, Clone, Deserialize, Serialize)]
pub struct CollectionStats {
    pub average_price: f64,
    pub average_price_1day_change: f64,
    pub average_price_7day_change: f64,
    pub created_at: String,
    pub discord_members: Option<u64>,
    pub feeless_floor_price: f64,
    pub floor_price: f64,
    pub floor_price_1day_change: f64,
    pub market_cap: u64,
    pub max_price: u64,
    pub num_of_token_holders: u64,
    pub num_of_token_listed: u64,
    pub percentage_of_token_listed: f64,
    pub project: Project,
    pub project_id: String,
    pub rank: Option<u64>,
    pub raw_market_cap: u64,
    pub raw_volume: Option<u64>,
    pub raw_volume_1day: f64,
    pub raw_volume_1day_change: f64,
    pub raw_volume_1hr: f64,
    pub raw_volume_7day: f64,
    pub raw_volume_7day_change: f64,
    pub supply: u64,
    pub twitter_followers: Option<u64>,
    pub updated_at: String,
    pub volume: Option<u64>,
    pub volume_15m: Option<u64>,
    pub volume_1day: f64,
    pub volume_1day_change: f64,
    pub volume_1hr: f64,
    pub volume_1m: Option<u64>,
    pub volume_30m: Option<u64>,
    pub volume_5m: Option<u64>,
    pub volume_7day: f64,
    pub volume_7day_change: f64,
}

#[derive(Debug, Clone, Deserialize, Serialize)]
pub struct Project {
    pub allow_list_id: Option<u64>,
    pub banner_url: String,
    pub contract_address: String,
    pub created_at: Option<String>,
    pub description: String,
    pub discord: Option<String>,
    pub display_id: Option<u64>,
    pub display_name: String,
    pub display_name_type: String,
    pub img_url: String,
    pub is_launchpad: bool,
    pub is_trading_disabled: bool,
    pub is_trading_enabled: bool,
    pub is_verified: bool,
    pub launch_date: Option<String>,
    pub launch_timestamp: Option<String>,
    pub launchpad_details: Option<String>,
    pub metadata: CollectionMetadata,
    pub minimum_royalty: Option<String>,
    pub orderbook_id: Option<u64>,
    pub project_attributes: Option<String>,
    pub project_id: String,
    pub project_identifiers: Option<String>,
    pub project_slug: String,
    pub protocol: String,
    pub rarities: Option<String>,
    pub rewards_earning: bool,
    pub royalty: Option<String>,
    pub royalty_strategy_id: Option<String>,
    pub short_description: Option<String>,
    pub supply: u64,
    pub token_type: Option<String>,
    pub transfer_policy_id: Option<String>,
    pub twitter: String,
    pub updated_at: Option<String>,
    pub website: String,
    pub withdraw_policy_id: Option<String>,
}

#[derive(Debug, Clone, Deserialize, Serialize)]
pub struct CollectionMetadata {
    pub allow_list_id: Option<u64>,
    pub orderbook_id: Option<u64>,
    pub royalty_strategy_id: String,
    pub token_type: Option<String>,
    pub transfer_policy_id: Option<String>,
    pub withdraw_policy_id: Option<String>,
}

#[derive(Debug, Clone, Deserialize, Serialize)]
pub struct Bid {
    pub amount: u64,
    pub block_number: u64,
    pub block_timestamp: u64,
    pub buyer_address: String,
    pub buyer_referral_address: String,
    pub buyer_referral_fee: f64,
    pub created_at: String,
    pub currency: String,
    pub currency_price: f64,
    pub decimal: u64,
    pub display_price: f64,
    pub expiration: Option<String>,
    pub expiry_time: Option<String>,
    pub fee: f64,
    pub fee_address: Option<String>,
    pub identifier_index: u64,
    pub identifier_key: String,
    pub identifier_type: String,
    pub instruction_index: Option<String>,
    pub metadata: Metadata,
    pub price: f64,
    pub program_id: String,
    pub program_instance_id: String,
    pub protocol: Option<String>,
    pub seller_address: String,
    pub seller_referral_address: String,
    pub seller_referral_fee: f64,
    pub trade_state: String,
    pub tx_id: String,
    pub r#type: String,
    pub updated_at: String,
}

#[derive(Debug, Clone, Deserialize, Serialize)]
pub struct Metadata {
    pub event_log: EventLog,
    pub is_offchain: bool,
    pub raw_total_price: String,
}

#[derive(Debug, Clone, Deserialize, Serialize)]
pub struct EventLog {
    pub direction: u64,
    #[serde(rename = "erc20Token")]
    pub erc20_token: String,
    #[serde(rename = "erc20TokenAmount")]
    pub erc20_token_amount: String,
    #[serde(rename = "erc721Token")]
    pub erc721_token: String,
    #[serde(rename = "erc721TokenId")]
    pub erc721_token_id: String,
    #[serde(rename = "erc721TokenProperties")]
    pub erc721_token_properties: Vec<Erc721TokenProperties>,
    pub expiry: String,
    pub fees: Vec<Fee>,
    pub maker: String,
    pub nonce: String,
    #[serde(rename = "rawSignature")]
    pub raw_signature: String,
    pub signature: Signature,
    pub taker: String,
}

#[derive(Debug, Clone, Deserialize, Serialize)]
pub struct Erc721TokenProperties {
    #[serde(rename = "propertyData")]
    pub property_data: Vec<String>,
    #[serde(rename = "propertyValidator")]
    pub property_validator: String,
}

#[derive(Debug, Clone, Deserialize, Serialize)]
pub struct Fee {
    pub amount: String,
    #[serde(rename = "feeData")]
    pub fee_data: String,
    pub recipient: String,
}

#[derive(Debug, Clone, Deserialize, Serialize)]
pub struct Signature {
    pub r: String,
    pub s: String,
    #[serde(rename = "signatureType")]
    pub signature_type: u64,
    pub v: u64,
}

// fn deserialize_u256_from_u64<'de, D>(deserializer: D) -> Result<U256, D::Error>
// where
//     D: Deserializer<'de>,
// {
//     let s: u64 = Deserialize::deserialize(deserializer)?;
//     if s == 0 {
//         Ok(U256::zero())
//     } else {
//         Ok(U256::from(s))
//     }
// }

// fn deserialize_u256_from_option_u64<'de, D>(deserializer: D) -> Result<Option<U256>, D::Error>
// where
//     D: Deserializer<'de>,
// {
//     let s: Option<u64> = Deserialize::deserialize(deserializer)?;
//     if let Some(s) = s {
//         if s == 0 {
//             Ok(Some(U256::zero()))
//         } else {
//             Ok(Some(U256::from(s)))
//         }
//     } else {
//         Ok(None)
//     }
// }

// fn deserialize_u256_radix_10<'de, D>(deserializer: D) -> Result<U256, D::Error>
// where
//     D: Deserializer<'de>,
// {
//     let s: String = Deserialize::deserialize(deserializer)?;
//     U256::from_str_radix(&s, 10).map_err(serde::de::Error::custom)
// }

// fn deserialize_address_on_empty<'de, D>(deserializer: D) -> Result<H160, D::Error>
// where
//     D: Deserializer<'de>,
// {
//     let s: String = Deserialize::deserialize(deserializer)?;
//     if s.is_empty() {
//         Ok(H160::zero())
//     } else {
//         Ok(H160::from_str(&s).map_err(serde::de::Error::custom)?)
//     }
// }

#[derive(Debug, Serialize)]
pub(crate) struct PaginationConfig {
    pub(crate) page_number: u64,
    pub(crate) page_size: Option<u64>,
}

impl PaginationConfig {
    pub(crate) fn new(page_number: u64, page_size: Option<u64>) -> Self {
        Self {
            page_number,
            page_size,
        }
    }

    pub(crate) fn default() -> Self {
        Self {
            page_number: 1,
            page_size: Some(32),
        }
    }
}

#[derive(Debug, Deserialize)]
pub(crate) struct PaginationInfo {
    pub(crate) current_page_number: u64,
    pub(crate) current_page_size: u64,
    pub(crate) has_next_page: bool,
    pub(crate) total_page_number: Option<u64>,
}