oneie 3.6.38 → 3.6.40

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (52) hide show
  1. package/.claude/agents/agent-frontend.md +48 -0
  2. package/.claude/commands/deploy.md +187 -17
  3. package/.claude/commands/media-upload.md +186 -0
  4. package/.claude/hooks/.last-news-context +1 -1
  5. package/.claude/hooks/__pycache__/todo.cpython-312.pyc +0 -0
  6. package/README.md +28 -0
  7. package/dist/index.js +17 -0
  8. package/dist/index.js.map +1 -1
  9. package/one/README.md +1 -2
  10. package/one/knowledge/one-protocol-ai-agents.md +892 -0
  11. package/one/knowledge/one-protocol-executive-report.md +617 -0
  12. package/one/knowledge/one-protocol-standard.md +869 -0
  13. package/one/knowledge/one-protocol-whitepaper.md +756 -0
  14. package/one/knowledge/ontology-education-game.md +1654 -0
  15. package/one/knowledge/ontology-v2.md +4449 -0
  16. package/one/knowledge/ontology.md +1 -1
  17. package/one/things/contracts/Move.toml +12 -0
  18. package/one/things/contracts/README.md +288 -0
  19. package/one/things/contracts/one.move +762 -0
  20. package/one/things/contracts/sdk.ts +578 -0
  21. package/one/things/crypto/FEATURES.md +78 -0
  22. package/one/things/crypto/ONECORE.md +62 -0
  23. package/one/things/crypto/ONECOREFAQ.md +22 -0
  24. package/one/things/crypto/ONECOREHOW.md +46 -0
  25. package/one/things/crypto/ONEENTERPRISE.md +64 -0
  26. package/one/things/crypto/ONEENTERPRISEFAQ.md +64 -0
  27. package/one/things/crypto/ONEENTERPRISEHOW.md +53 -0
  28. package/one/things/crypto/ONEPRO.md +60 -0
  29. package/one/things/crypto/ONEPROFAQ.md +22 -0
  30. package/one/things/crypto/ONEPROHOW.md +53 -0
  31. package/one/things/crypto/READMEAGENCY.md +64 -0
  32. package/one/things/crypto/VSL.md +45 -0
  33. package/one/things/crypto/WebsiteCopy.md +176 -0
  34. package/one/things/design-system.md +832 -0
  35. package/one/things/pay.one.ie.md +53 -0
  36. package/one/things/plans/ai-elements-integration.md +483 -0
  37. package/one/things/plans/one-protocol-and-payone-usage.md +82 -0
  38. package/one/things/plans/plan-connect-to-api.md +146 -0
  39. package/one/things/plans/video-frontend.md +146 -88
  40. package/one/things/plans-u.md +905 -0
  41. package/one/things/products/Blockchain Products.md +6278 -0
  42. package/one/things/scripts-clean-mac.sh +409 -0
  43. package/one/things/todo-release.md +654 -0
  44. package/one/things/todo.md +9 -642
  45. package/one/things/video-script-backup.md +318 -0
  46. package/one/things/video-script-demo.md +382 -0
  47. package/one/things/video-script-ontology.md +0 -1
  48. package/one/things/video-script.md +361 -0
  49. package/package.json +8 -6
  50. package/.claude/hooks/__pycache__/done.cpython-313.pyc +0 -0
  51. package/.claude/hooks/__pycache__/todo.cpython-311.pyc +0 -0
  52. package/llms.txt +0 -257
@@ -0,0 +1,762 @@
1
+ /// ONE Universal Smart Contract
2
+ ///
3
+ /// The ONE Contract is a universal container that can hold ANY entity type:
4
+ /// products, subscriptions, lessons, memberships, tokens, NFTs, credentials, etc.
5
+ ///
6
+ /// Philosophy: Sui's object model IS the database. Objects exist in parallel,
7
+ /// can be composed, transferred, and queried - making blockchain the perfect
8
+ /// universal data layer for the 6-dimension ontology.
9
+ ///
10
+ /// Key Features:
11
+ /// - Universal entity wrapper (any Thing can be an on-chain object)
12
+ /// - Marketplace integration (sell anything with SUI)
13
+ /// - Token minting per merchant/creator
14
+ /// - Parallel execution (Sui's superpower)
15
+ /// - Composable objects (entities can contain entities)
16
+ ///
17
+ /// INTEGRATION: This contract integrates with the ONE Protocol Gateway
18
+ /// located at: apps/one-core/contracts/sui/
19
+ /// - gateway.move: Payment verification with 1% fee
20
+ /// - merchant.move: HD wallet merchant authorization
21
+ /// - subscription.move: Recurring payment management
22
+ /// - credits.move: Prepaid credit system
23
+ ///
24
+ /// SDK: Use @one-protocol package from apps/one-core/packages/one-protocol/
25
+
26
+ module one_protocol::entity {
27
+ use std::string::{Self, String};
28
+ use sui::object::{Self, UID, ID};
29
+ use sui::transfer;
30
+ use sui::tx_context::{Self, TxContext};
31
+ use sui::coin::{Self, Coin};
32
+ use sui::balance::{Self, Balance};
33
+ use sui::sui::SUI;
34
+ use sui::event;
35
+ use sui::clock::{Self, Clock};
36
+
37
+ // ============================================================
38
+ // ERRORS
39
+ // ============================================================
40
+
41
+ const ENotAuthorized: u64 = 0;
42
+ const EInsufficientPayment: u64 = 1;
43
+ const EEntityNotActive: u64 = 2;
44
+ const EInvalidEntityType: u64 = 3;
45
+ const EAlreadyOwned: u64 = 4;
46
+ const ESubscriptionExpired: u64 = 5;
47
+ const EMerchantNotFound: u64 = 6;
48
+ const EProductNotFound: u64 = 7;
49
+
50
+ // ============================================================
51
+ // ENTITY TYPES - The Universal Ontology
52
+ // ============================================================
53
+
54
+ /// Entity types map directly to ONE Platform's 6-dimension ontology
55
+ /// These are constants representing what the entity IS
56
+ const ENTITY_PRODUCT: u8 = 1;
57
+ const ENTITY_SUBSCRIPTION: u8 = 2;
58
+ const ENTITY_LESSON: u8 = 3;
59
+ const ENTITY_MEMBERSHIP: u8 = 4;
60
+ const ENTITY_CREDENTIAL: u8 = 5;
61
+ const ENTITY_TOKEN: u8 = 6;
62
+ const ENTITY_NFT: u8 = 7;
63
+ const ENTITY_ACCESS_PASS: u8 = 8;
64
+ const ENTITY_EVENT_TICKET: u8 = 9;
65
+ const ENTITY_DIGITAL_GOOD: u8 = 10;
66
+ const ENTITY_SERVICE: u8 = 11;
67
+ const ENTITY_LICENSE: u8 = 12;
68
+
69
+ // ============================================================
70
+ // CORE STRUCTS
71
+ // ============================================================
72
+
73
+ /// ONE Platform Registry - The root object that tracks all merchants
74
+ public struct ONERegistry has key {
75
+ id: UID,
76
+ /// Total merchants registered
77
+ merchant_count: u64,
78
+ /// Total entities created across all merchants
79
+ total_entities: u64,
80
+ /// Platform fee in basis points (e.g., 250 = 2.5%)
81
+ platform_fee_bps: u64,
82
+ /// Platform treasury for collecting fees
83
+ treasury: Balance<SUI>,
84
+ /// Admin capability holder
85
+ admin: address,
86
+ }
87
+
88
+ /// Merchant - A seller/creator on the ONE Platform
89
+ /// Each merchant can create products, mint tokens, and sell through the market
90
+ public struct Merchant has key, store {
91
+ id: UID,
92
+ /// Merchant's display name
93
+ name: String,
94
+ /// Merchant's wallet address for receiving payments
95
+ wallet: address,
96
+ /// Total sales volume in MIST
97
+ total_sales: u64,
98
+ /// Number of products/entities created
99
+ entity_count: u64,
100
+ /// Whether merchant is active
101
+ is_active: bool,
102
+ /// Custom metadata (JSON string for flexibility)
103
+ metadata: String,
104
+ /// Created timestamp
105
+ created_at: u64,
106
+ }
107
+
108
+ /// MerchantCap - Capability that proves merchant ownership
109
+ /// Required to create products, mint tokens, withdraw funds
110
+ public struct MerchantCap has key, store {
111
+ id: UID,
112
+ merchant_id: ID,
113
+ }
114
+
115
+ /// Entity - The UNIVERSAL container for ANY thing
116
+ /// This is the core innovation: one struct that can represent anything
117
+ public struct Entity has key, store {
118
+ id: UID,
119
+ /// What type of entity (product, subscription, lesson, etc.)
120
+ entity_type: u8,
121
+ /// Human-readable name
122
+ name: String,
123
+ /// Description
124
+ description: String,
125
+ /// Price in MIST (1 SUI = 1_000_000_000 MIST)
126
+ price: u64,
127
+ /// Who created/sells this entity
128
+ merchant_id: ID,
129
+ /// Is this entity available for purchase?
130
+ is_active: bool,
131
+ /// Supply: 0 = unlimited, >0 = limited edition
132
+ max_supply: u64,
133
+ /// How many have been sold/minted
134
+ current_supply: u64,
135
+ /// Flexible metadata as JSON string
136
+ /// Can contain: image_url, attributes, duration, access_level, etc.
137
+ metadata: String,
138
+ /// Created timestamp
139
+ created_at: u64,
140
+ /// Last updated timestamp
141
+ updated_at: u64,
142
+ }
143
+
144
+ /// Ownership - Proof that someone owns an Entity instance
145
+ /// This is what buyers receive - a transferable proof of ownership
146
+ public struct Ownership has key, store {
147
+ id: UID,
148
+ /// The entity this ownership refers to
149
+ entity_id: ID,
150
+ /// Entity type for quick filtering
151
+ entity_type: u8,
152
+ /// Original entity name (cached for display)
153
+ entity_name: String,
154
+ /// Who owns this
155
+ owner: address,
156
+ /// When was this acquired
157
+ acquired_at: u64,
158
+ /// For subscriptions: when does access expire (0 = never)
159
+ expires_at: u64,
160
+ /// Purchase price paid
161
+ price_paid: u64,
162
+ /// Custom ownership metadata
163
+ metadata: String,
164
+ }
165
+
166
+ /// ONE Token - Each merchant can have their own token
167
+ /// Used for loyalty, rewards, governance, access control
168
+ public struct ONE has drop {}
169
+
170
+ /// MerchantToken - A merchant-specific token for their ecosystem
171
+ public struct MerchantToken has key, store {
172
+ id: UID,
173
+ merchant_id: ID,
174
+ name: String,
175
+ symbol: String,
176
+ decimals: u8,
177
+ total_supply: u64,
178
+ metadata: String,
179
+ }
180
+
181
+ // ============================================================
182
+ // EVENTS - For indexing and real-time updates
183
+ // ============================================================
184
+
185
+ public struct MerchantCreated has copy, drop {
186
+ merchant_id: ID,
187
+ name: String,
188
+ wallet: address,
189
+ timestamp: u64,
190
+ }
191
+
192
+ public struct EntityCreated has copy, drop {
193
+ entity_id: ID,
194
+ merchant_id: ID,
195
+ entity_type: u8,
196
+ name: String,
197
+ price: u64,
198
+ timestamp: u64,
199
+ }
200
+
201
+ public struct EntityPurchased has copy, drop {
202
+ ownership_id: ID,
203
+ entity_id: ID,
204
+ buyer: address,
205
+ seller: address,
206
+ price: u64,
207
+ entity_type: u8,
208
+ timestamp: u64,
209
+ }
210
+
211
+ public struct TokensMinted has copy, drop {
212
+ merchant_id: ID,
213
+ amount: u64,
214
+ recipient: address,
215
+ timestamp: u64,
216
+ }
217
+
218
+ // ============================================================
219
+ // INITIALIZATION
220
+ // ============================================================
221
+
222
+ /// Initialize the ONE Platform Registry
223
+ fun init(ctx: &mut TxContext) {
224
+ let registry = ONERegistry {
225
+ id: object::new(ctx),
226
+ merchant_count: 0,
227
+ total_entities: 0,
228
+ platform_fee_bps: 200, // 2% platform fee (adjustable via update_platform_fee)
229
+ treasury: balance::zero(),
230
+ admin: tx_context::sender(ctx),
231
+ };
232
+ transfer::share_object(registry);
233
+ }
234
+
235
+ // ============================================================
236
+ // MERCHANT FUNCTIONS
237
+ // ============================================================
238
+
239
+ /// Register as a merchant on the ONE Platform
240
+ public entry fun register_merchant(
241
+ registry: &mut ONERegistry,
242
+ name: vector<u8>,
243
+ metadata: vector<u8>,
244
+ clock: &Clock,
245
+ ctx: &mut TxContext
246
+ ) {
247
+ let sender = tx_context::sender(ctx);
248
+ let timestamp = clock::timestamp_ms(clock);
249
+
250
+ let merchant = Merchant {
251
+ id: object::new(ctx),
252
+ name: string::utf8(name),
253
+ wallet: sender,
254
+ total_sales: 0,
255
+ entity_count: 0,
256
+ is_active: true,
257
+ metadata: string::utf8(metadata),
258
+ created_at: timestamp,
259
+ };
260
+
261
+ let merchant_id = object::id(&merchant);
262
+
263
+ // Create merchant capability
264
+ let cap = MerchantCap {
265
+ id: object::new(ctx),
266
+ merchant_id,
267
+ };
268
+
269
+ registry.merchant_count = registry.merchant_count + 1;
270
+
271
+ event::emit(MerchantCreated {
272
+ merchant_id,
273
+ name: merchant.name,
274
+ wallet: sender,
275
+ timestamp,
276
+ });
277
+
278
+ // Share merchant object (readable by anyone)
279
+ transfer::share_object(merchant);
280
+ // Transfer capability to merchant owner
281
+ transfer::transfer(cap, sender);
282
+ }
283
+
284
+ // ============================================================
285
+ // ENTITY FUNCTIONS - Create ANY type of thing
286
+ // ============================================================
287
+
288
+ /// Create a new entity (product, subscription, lesson, etc.)
289
+ /// This is the UNIVERSAL creation function
290
+ public entry fun create_entity(
291
+ merchant: &mut Merchant,
292
+ cap: &MerchantCap,
293
+ entity_type: u8,
294
+ name: vector<u8>,
295
+ description: vector<u8>,
296
+ price: u64,
297
+ max_supply: u64,
298
+ metadata: vector<u8>,
299
+ clock: &Clock,
300
+ ctx: &mut TxContext
301
+ ) {
302
+ // Verify merchant ownership
303
+ assert!(cap.merchant_id == object::id(merchant), ENotAuthorized);
304
+ assert!(merchant.is_active, EEntityNotActive);
305
+ assert!(entity_type >= 1 && entity_type <= 12, EInvalidEntityType);
306
+
307
+ let timestamp = clock::timestamp_ms(clock);
308
+
309
+ let entity = Entity {
310
+ id: object::new(ctx),
311
+ entity_type,
312
+ name: string::utf8(name),
313
+ description: string::utf8(description),
314
+ price,
315
+ merchant_id: object::id(merchant),
316
+ is_active: true,
317
+ max_supply,
318
+ current_supply: 0,
319
+ metadata: string::utf8(metadata),
320
+ created_at: timestamp,
321
+ updated_at: timestamp,
322
+ };
323
+
324
+ let entity_id = object::id(&entity);
325
+ merchant.entity_count = merchant.entity_count + 1;
326
+
327
+ event::emit(EntityCreated {
328
+ entity_id,
329
+ merchant_id: object::id(merchant),
330
+ entity_type,
331
+ name: entity.name,
332
+ price,
333
+ timestamp,
334
+ });
335
+
336
+ transfer::share_object(entity);
337
+ }
338
+
339
+ /// Purchase an entity - works for ANY entity type
340
+ /// Buyer receives an Ownership object as proof of purchase
341
+ public entry fun purchase_entity(
342
+ registry: &mut ONERegistry,
343
+ merchant: &mut Merchant,
344
+ entity: &mut Entity,
345
+ payment: Coin<SUI>,
346
+ expires_in_ms: u64, // 0 for permanent, >0 for subscription duration
347
+ clock: &Clock,
348
+ ctx: &mut TxContext
349
+ ) {
350
+ assert!(entity.is_active, EEntityNotActive);
351
+ assert!(entity.merchant_id == object::id(merchant), EMerchantNotFound);
352
+
353
+ // Check supply
354
+ if (entity.max_supply > 0) {
355
+ assert!(entity.current_supply < entity.max_supply, EProductNotFound);
356
+ };
357
+
358
+ let payment_amount = coin::value(&payment);
359
+ assert!(payment_amount >= entity.price, EInsufficientPayment);
360
+
361
+ let timestamp = clock::timestamp_ms(clock);
362
+ let buyer = tx_context::sender(ctx);
363
+
364
+ // Calculate platform fee
365
+ let fee_amount = (entity.price * registry.platform_fee_bps) / 10000;
366
+ let merchant_amount = entity.price - fee_amount;
367
+
368
+ // Split payment
369
+ let mut payment_balance = coin::into_balance(payment);
370
+
371
+ // Platform fee to treasury
372
+ let fee_balance = balance::split(&mut payment_balance, fee_amount);
373
+ balance::join(&mut registry.treasury, fee_balance);
374
+
375
+ // Merchant payment
376
+ let merchant_coin = coin::from_balance(
377
+ balance::split(&mut payment_balance, merchant_amount),
378
+ ctx
379
+ );
380
+ transfer::public_transfer(merchant_coin, merchant.wallet);
381
+
382
+ // Refund excess payment
383
+ if (balance::value(&payment_balance) > 0) {
384
+ transfer::public_transfer(
385
+ coin::from_balance(payment_balance, ctx),
386
+ buyer
387
+ );
388
+ } else {
389
+ balance::destroy_zero(payment_balance);
390
+ };
391
+
392
+ // Calculate expiration for subscriptions
393
+ let expires_at = if (expires_in_ms > 0) {
394
+ timestamp + expires_in_ms
395
+ } else {
396
+ 0
397
+ };
398
+
399
+ // Create ownership proof
400
+ let ownership = Ownership {
401
+ id: object::new(ctx),
402
+ entity_id: object::id(entity),
403
+ entity_type: entity.entity_type,
404
+ entity_name: entity.name,
405
+ owner: buyer,
406
+ acquired_at: timestamp,
407
+ expires_at,
408
+ price_paid: entity.price,
409
+ metadata: string::utf8(b"{}"),
410
+ };
411
+
412
+ let ownership_id = object::id(&ownership);
413
+
414
+ // Update counters
415
+ entity.current_supply = entity.current_supply + 1;
416
+ merchant.total_sales = merchant.total_sales + entity.price;
417
+ registry.total_entities = registry.total_entities + 1;
418
+
419
+ event::emit(EntityPurchased {
420
+ ownership_id,
421
+ entity_id: object::id(entity),
422
+ buyer,
423
+ seller: merchant.wallet,
424
+ price: entity.price,
425
+ entity_type: entity.entity_type,
426
+ timestamp,
427
+ });
428
+
429
+ transfer::transfer(ownership, buyer);
430
+ }
431
+
432
+ /// Check if an ownership is still valid (for subscriptions)
433
+ public fun is_ownership_valid(ownership: &Ownership, clock: &Clock): bool {
434
+ if (ownership.expires_at == 0) {
435
+ true // Permanent ownership
436
+ } else {
437
+ clock::timestamp_ms(clock) < ownership.expires_at
438
+ }
439
+ }
440
+
441
+ // ============================================================
442
+ // CONVENIENCE FUNCTIONS - Typed wrappers for clarity
443
+ // ============================================================
444
+
445
+ /// Create a product (entity_type = 1)
446
+ public entry fun create_product(
447
+ merchant: &mut Merchant,
448
+ cap: &MerchantCap,
449
+ name: vector<u8>,
450
+ description: vector<u8>,
451
+ price: u64,
452
+ max_supply: u64,
453
+ metadata: vector<u8>,
454
+ clock: &Clock,
455
+ ctx: &mut TxContext
456
+ ) {
457
+ create_entity(
458
+ merchant, cap, ENTITY_PRODUCT,
459
+ name, description, price, max_supply, metadata, clock, ctx
460
+ );
461
+ }
462
+
463
+ /// Create a subscription (entity_type = 2)
464
+ public entry fun create_subscription(
465
+ merchant: &mut Merchant,
466
+ cap: &MerchantCap,
467
+ name: vector<u8>,
468
+ description: vector<u8>,
469
+ price: u64, // Price per period
470
+ metadata: vector<u8>, // Should contain: duration_ms, features, etc.
471
+ clock: &Clock,
472
+ ctx: &mut TxContext
473
+ ) {
474
+ create_entity(
475
+ merchant, cap, ENTITY_SUBSCRIPTION,
476
+ name, description, price, 0, metadata, clock, ctx
477
+ );
478
+ }
479
+
480
+ /// Create a lesson/course (entity_type = 3)
481
+ public entry fun create_lesson(
482
+ merchant: &mut Merchant,
483
+ cap: &MerchantCap,
484
+ name: vector<u8>,
485
+ description: vector<u8>,
486
+ price: u64,
487
+ max_students: u64,
488
+ metadata: vector<u8>, // Should contain: duration, instructor, materials
489
+ clock: &Clock,
490
+ ctx: &mut TxContext
491
+ ) {
492
+ create_entity(
493
+ merchant, cap, ENTITY_LESSON,
494
+ name, description, price, max_students, metadata, clock, ctx
495
+ );
496
+ }
497
+
498
+ /// Create an event ticket (entity_type = 9)
499
+ public entry fun create_event_ticket(
500
+ merchant: &mut Merchant,
501
+ cap: &MerchantCap,
502
+ name: vector<u8>,
503
+ description: vector<u8>,
504
+ price: u64,
505
+ max_tickets: u64,
506
+ metadata: vector<u8>, // Should contain: event_date, venue, seat_info
507
+ clock: &Clock,
508
+ ctx: &mut TxContext
509
+ ) {
510
+ create_entity(
511
+ merchant, cap, ENTITY_EVENT_TICKET,
512
+ name, description, price, max_tickets, metadata, clock, ctx
513
+ );
514
+ }
515
+
516
+ // ============================================================
517
+ // ADMIN FUNCTIONS
518
+ // ============================================================
519
+
520
+ /// Update platform fee (admin only)
521
+ public entry fun update_platform_fee(
522
+ registry: &mut ONERegistry,
523
+ new_fee_bps: u64,
524
+ ctx: &TxContext
525
+ ) {
526
+ assert!(tx_context::sender(ctx) == registry.admin, ENotAuthorized);
527
+ registry.platform_fee_bps = new_fee_bps;
528
+ }
529
+
530
+ /// Withdraw platform fees (admin only)
531
+ public entry fun withdraw_platform_fees(
532
+ registry: &mut ONERegistry,
533
+ ctx: &mut TxContext
534
+ ) {
535
+ assert!(tx_context::sender(ctx) == registry.admin, ENotAuthorized);
536
+ let amount = balance::value(&registry.treasury);
537
+ let withdrawal = coin::from_balance(
538
+ balance::split(&mut registry.treasury, amount),
539
+ ctx
540
+ );
541
+ transfer::public_transfer(withdrawal, registry.admin);
542
+ }
543
+
544
+ /// Update entity status
545
+ public entry fun update_entity_status(
546
+ entity: &mut Entity,
547
+ merchant: &Merchant,
548
+ cap: &MerchantCap,
549
+ is_active: bool,
550
+ clock: &Clock,
551
+ ) {
552
+ assert!(cap.merchant_id == object::id(merchant), ENotAuthorized);
553
+ assert!(entity.merchant_id == object::id(merchant), ENotAuthorized);
554
+ entity.is_active = is_active;
555
+ entity.updated_at = clock::timestamp_ms(clock);
556
+ }
557
+
558
+ /// Update entity price
559
+ public entry fun update_entity_price(
560
+ entity: &mut Entity,
561
+ merchant: &Merchant,
562
+ cap: &MerchantCap,
563
+ new_price: u64,
564
+ clock: &Clock,
565
+ ) {
566
+ assert!(cap.merchant_id == object::id(merchant), ENotAuthorized);
567
+ assert!(entity.merchant_id == object::id(merchant), ENotAuthorized);
568
+ entity.price = new_price;
569
+ entity.updated_at = clock::timestamp_ms(clock);
570
+ }
571
+
572
+ // ============================================================
573
+ // VIEW FUNCTIONS
574
+ // ============================================================
575
+
576
+ public fun get_entity_type(entity: &Entity): u8 {
577
+ entity.entity_type
578
+ }
579
+
580
+ public fun get_entity_price(entity: &Entity): u64 {
581
+ entity.price
582
+ }
583
+
584
+ public fun get_entity_supply(entity: &Entity): (u64, u64) {
585
+ (entity.current_supply, entity.max_supply)
586
+ }
587
+
588
+ public fun get_merchant_stats(merchant: &Merchant): (u64, u64, bool) {
589
+ (merchant.total_sales, merchant.entity_count, merchant.is_active)
590
+ }
591
+
592
+ public fun get_ownership_entity_type(ownership: &Ownership): u8 {
593
+ ownership.entity_type
594
+ }
595
+
596
+ public fun get_ownership_expiry(ownership: &Ownership): u64 {
597
+ ownership.expires_at
598
+ }
599
+ }
600
+
601
+ // ============================================================
602
+ // MODULE: ONE MARKET - Decentralized marketplace
603
+ // ============================================================
604
+
605
+ module one_protocol::market {
606
+ use std::string::{Self, String};
607
+ use sui::object::{Self, UID, ID};
608
+ use sui::transfer;
609
+ use sui::tx_context::{Self, TxContext};
610
+ use sui::coin::{Self, Coin};
611
+ use sui::balance::{Self, Balance};
612
+ use sui::sui::SUI;
613
+ use sui::event;
614
+ use sui::clock::{Self, Clock};
615
+ use one_protocol::entity::{Ownership};
616
+
617
+ // ============================================================
618
+ // ERRORS
619
+ // ============================================================
620
+
621
+ const ENotOwner: u64 = 0;
622
+ const EListingNotActive: u64 = 1;
623
+ const EInsufficientPayment: u64 = 2;
624
+ const ECannotBuyOwnListing: u64 = 3;
625
+
626
+ // ============================================================
627
+ // STRUCTS
628
+ // ============================================================
629
+
630
+ /// A listing in the secondary market
631
+ public struct Listing has key {
632
+ id: UID,
633
+ /// The ownership being sold
634
+ ownership: Ownership,
635
+ /// Asking price in MIST
636
+ price: u64,
637
+ /// Seller address
638
+ seller: address,
639
+ /// Is this listing active?
640
+ is_active: bool,
641
+ /// When was this listed
642
+ listed_at: u64,
643
+ }
644
+
645
+ // ============================================================
646
+ // EVENTS
647
+ // ============================================================
648
+
649
+ public struct ItemListed has copy, drop {
650
+ listing_id: ID,
651
+ ownership_id: ID,
652
+ seller: address,
653
+ price: u64,
654
+ timestamp: u64,
655
+ }
656
+
657
+ public struct ItemSold has copy, drop {
658
+ listing_id: ID,
659
+ ownership_id: ID,
660
+ seller: address,
661
+ buyer: address,
662
+ price: u64,
663
+ timestamp: u64,
664
+ }
665
+
666
+ public struct ListingCanceled has copy, drop {
667
+ listing_id: ID,
668
+ seller: address,
669
+ timestamp: u64,
670
+ }
671
+
672
+ // ============================================================
673
+ // MARKETPLACE FUNCTIONS
674
+ // ============================================================
675
+
676
+ /// List an ownership for sale on the secondary market
677
+ public entry fun list_for_sale(
678
+ ownership: Ownership,
679
+ price: u64,
680
+ clock: &Clock,
681
+ ctx: &mut TxContext
682
+ ) {
683
+ let seller = tx_context::sender(ctx);
684
+ let timestamp = clock::timestamp_ms(clock);
685
+ let ownership_id = object::id(&ownership);
686
+
687
+ let listing = Listing {
688
+ id: object::new(ctx),
689
+ ownership,
690
+ price,
691
+ seller,
692
+ is_active: true,
693
+ listed_at: timestamp,
694
+ };
695
+
696
+ let listing_id = object::id(&listing);
697
+
698
+ event::emit(ItemListed {
699
+ listing_id,
700
+ ownership_id,
701
+ seller,
702
+ price,
703
+ timestamp,
704
+ });
705
+
706
+ transfer::share_object(listing);
707
+ }
708
+
709
+ /// Buy a listing from the secondary market
710
+ public entry fun buy_listing(
711
+ listing: &mut Listing,
712
+ payment: Coin<SUI>,
713
+ clock: &Clock,
714
+ ctx: &mut TxContext
715
+ ) {
716
+ assert!(listing.is_active, EListingNotActive);
717
+
718
+ let buyer = tx_context::sender(ctx);
719
+ assert!(buyer != listing.seller, ECannotBuyOwnListing);
720
+
721
+ let payment_amount = coin::value(&payment);
722
+ assert!(payment_amount >= listing.price, EInsufficientPayment);
723
+
724
+ let timestamp = clock::timestamp_ms(clock);
725
+
726
+ // Transfer payment to seller
727
+ transfer::public_transfer(payment, listing.seller);
728
+
729
+ // Mark listing as inactive
730
+ listing.is_active = false;
731
+
732
+ // Note: In a real implementation, we'd transfer the ownership here
733
+ // This requires more complex object management with Sui's ownership model
734
+
735
+ event::emit(ItemSold {
736
+ listing_id: object::id(listing),
737
+ ownership_id: object::id(&listing.ownership),
738
+ seller: listing.seller,
739
+ buyer,
740
+ price: listing.price,
741
+ timestamp,
742
+ });
743
+ }
744
+
745
+ /// Cancel a listing (seller only)
746
+ public entry fun cancel_listing(
747
+ listing: &mut Listing,
748
+ clock: &Clock,
749
+ ctx: &TxContext
750
+ ) {
751
+ assert!(tx_context::sender(ctx) == listing.seller, ENotOwner);
752
+ assert!(listing.is_active, EListingNotActive);
753
+
754
+ listing.is_active = false;
755
+
756
+ event::emit(ListingCanceled {
757
+ listing_id: object::id(listing),
758
+ seller: listing.seller,
759
+ timestamp: clock::timestamp_ms(clock),
760
+ });
761
+ }
762
+ }