@0xslots/sdk 0.9.2 → 0.10.1

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.
@@ -0,0 +1,1628 @@
1
+ import gql from 'graphql-tag';
2
+ import { metadataModuleAbi, getSlotsHubAddress, slotAbi, slotFactoryAbi } from '@0xslots/contracts';
3
+ import { gql as gql$1, GraphQLClient } from 'graphql-request';
4
+ import { encodeFunctionData, erc20Abi } from 'viem';
5
+
6
+ // src/errors.ts
7
+ var SlotsError = class extends Error {
8
+ constructor(operation, cause) {
9
+ const msg = cause instanceof Error ? cause.message : String(cause);
10
+ super(`${operation}: ${msg}`);
11
+ this.operation = operation;
12
+ this.name = "SlotsError";
13
+ this.cause = cause;
14
+ }
15
+ };
16
+ var AccountFieldsFragmentDoc = gql`
17
+ fragment AccountFields on Account {
18
+ id
19
+ type
20
+ slotCount
21
+ occupiedCount
22
+ slotsAsRecipient {
23
+ id
24
+ }
25
+ slotsAsOccupant {
26
+ id
27
+ }
28
+ }
29
+ `;
30
+ var CurrencyFieldsFragmentDoc = gql`
31
+ fragment CurrencyFields on Currency {
32
+ id
33
+ name
34
+ symbol
35
+ decimals
36
+ }
37
+ `;
38
+ var MetadataSlotFieldsFragmentDoc = gql`
39
+ fragment MetadataSlotFields on MetadataSlot {
40
+ id
41
+ uri
42
+ rawJson
43
+ adType
44
+ updatedBy
45
+ updateCount
46
+ createdAt
47
+ createdTx
48
+ updatedAt
49
+ updatedTx
50
+ slot {
51
+ id
52
+ recipient
53
+ occupant
54
+ price
55
+ deposit
56
+ currency {
57
+ id
58
+ symbol
59
+ decimals
60
+ }
61
+ }
62
+ }
63
+ `;
64
+ var SlotFieldsFragmentDoc = gql`
65
+ fragment SlotFields on Slot {
66
+ id
67
+ recipient
68
+ recipientAccount {
69
+ id
70
+ type
71
+ slotCount
72
+ occupiedCount
73
+ }
74
+ currency {
75
+ id
76
+ name
77
+ symbol
78
+ decimals
79
+ }
80
+ manager
81
+ mutableTax
82
+ mutableModule
83
+ taxPercentage
84
+ module {
85
+ id
86
+ verified
87
+ name
88
+ version
89
+ }
90
+ occupant
91
+ occupantAccount {
92
+ id
93
+ type
94
+ slotCount
95
+ occupiedCount
96
+ }
97
+ price
98
+ deposit
99
+ collectedTax
100
+ totalCollected
101
+ liquidationBountyBps
102
+ minDepositSeconds
103
+ createdAt
104
+ createdTx
105
+ updatedAt
106
+ }
107
+ `;
108
+ var GetAccountDocument = gql`
109
+ query GetAccount($id: ID!, $block: Block_height) {
110
+ account(id: $id, block: $block) {
111
+ ...AccountFields
112
+ }
113
+ }
114
+ ${AccountFieldsFragmentDoc}`;
115
+ var GetAccountsDocument = gql`
116
+ query GetAccounts($first: Int!, $skip: Int, $orderBy: Account_orderBy, $orderDirection: OrderDirection, $where: Account_filter, $block: Block_height) {
117
+ accounts(
118
+ first: $first
119
+ skip: $skip
120
+ orderBy: $orderBy
121
+ orderDirection: $orderDirection
122
+ where: $where
123
+ block: $block
124
+ ) {
125
+ ...AccountFields
126
+ }
127
+ }
128
+ ${AccountFieldsFragmentDoc}`;
129
+ var GetSlotDeployedEventsDocument = gql`
130
+ query GetSlotDeployedEvents($first: Int!, $skip: Int, $orderBy: SlotDeployedEvent_orderBy, $orderDirection: OrderDirection, $where: SlotDeployedEvent_filter, $block: Block_height) {
131
+ slotDeployedEvents(
132
+ first: $first
133
+ skip: $skip
134
+ orderBy: $orderBy
135
+ orderDirection: $orderDirection
136
+ where: $where
137
+ block: $block
138
+ ) {
139
+ id
140
+ slot {
141
+ id
142
+ }
143
+ recipient
144
+ currency {
145
+ ...CurrencyFields
146
+ }
147
+ manager
148
+ mutableTax
149
+ mutableModule
150
+ taxPercentage
151
+ module
152
+ liquidationBountyBps
153
+ minDepositSeconds
154
+ deployer
155
+ timestamp
156
+ blockNumber
157
+ tx
158
+ }
159
+ }
160
+ ${CurrencyFieldsFragmentDoc}`;
161
+ var GetRecentEventsDocument = gql`
162
+ query GetRecentEvents($first: Int!, $skip: Int) {
163
+ slotDeployedEvents(
164
+ first: $first
165
+ skip: $skip
166
+ orderBy: timestamp
167
+ orderDirection: desc
168
+ ) {
169
+ id
170
+ slot {
171
+ id
172
+ }
173
+ recipient
174
+ currency {
175
+ ...CurrencyFields
176
+ }
177
+ deployer
178
+ timestamp
179
+ tx
180
+ }
181
+ boughtEvents(
182
+ first: $first
183
+ skip: $skip
184
+ orderBy: timestamp
185
+ orderDirection: desc
186
+ ) {
187
+ id
188
+ slot {
189
+ id
190
+ }
191
+ currency {
192
+ ...CurrencyFields
193
+ }
194
+ buyer
195
+ previousOccupant
196
+ price
197
+ selfAssessedPrice
198
+ deposit
199
+ timestamp
200
+ tx
201
+ }
202
+ releasedEvents(
203
+ first: $first
204
+ skip: $skip
205
+ orderBy: timestamp
206
+ orderDirection: desc
207
+ ) {
208
+ id
209
+ slot {
210
+ id
211
+ }
212
+ currency {
213
+ ...CurrencyFields
214
+ }
215
+ occupant
216
+ refund
217
+ timestamp
218
+ tx
219
+ }
220
+ liquidatedEvents(
221
+ first: $first
222
+ skip: $skip
223
+ orderBy: timestamp
224
+ orderDirection: desc
225
+ ) {
226
+ id
227
+ slot {
228
+ id
229
+ }
230
+ currency {
231
+ ...CurrencyFields
232
+ }
233
+ liquidator
234
+ occupant
235
+ bounty
236
+ timestamp
237
+ tx
238
+ }
239
+ priceUpdatedEvents(
240
+ first: $first
241
+ skip: $skip
242
+ orderBy: timestamp
243
+ orderDirection: desc
244
+ ) {
245
+ id
246
+ slot {
247
+ id
248
+ }
249
+ currency {
250
+ ...CurrencyFields
251
+ }
252
+ oldPrice
253
+ newPrice
254
+ timestamp
255
+ tx
256
+ }
257
+ depositedEvents(
258
+ first: $first
259
+ skip: $skip
260
+ orderBy: timestamp
261
+ orderDirection: desc
262
+ ) {
263
+ id
264
+ slot {
265
+ id
266
+ }
267
+ currency {
268
+ ...CurrencyFields
269
+ }
270
+ depositor
271
+ amount
272
+ timestamp
273
+ tx
274
+ }
275
+ withdrawnEvents(
276
+ first: $first
277
+ skip: $skip
278
+ orderBy: timestamp
279
+ orderDirection: desc
280
+ ) {
281
+ id
282
+ slot {
283
+ id
284
+ }
285
+ currency {
286
+ ...CurrencyFields
287
+ }
288
+ occupant
289
+ amount
290
+ timestamp
291
+ tx
292
+ }
293
+ taxCollectedEvents(
294
+ first: $first
295
+ skip: $skip
296
+ orderBy: timestamp
297
+ orderDirection: desc
298
+ ) {
299
+ id
300
+ slot {
301
+ id
302
+ }
303
+ currency {
304
+ ...CurrencyFields
305
+ }
306
+ recipient
307
+ amount
308
+ timestamp
309
+ tx
310
+ }
311
+ taxUpdateProposedEvents(
312
+ first: $first
313
+ skip: $skip
314
+ orderBy: timestamp
315
+ orderDirection: desc
316
+ ) {
317
+ id
318
+ slot {
319
+ id
320
+ }
321
+ newPercentage
322
+ timestamp
323
+ tx
324
+ }
325
+ moduleUpdateProposedEvents(
326
+ first: $first
327
+ skip: $skip
328
+ orderBy: timestamp
329
+ orderDirection: desc
330
+ ) {
331
+ id
332
+ slot {
333
+ id
334
+ }
335
+ newModule
336
+ timestamp
337
+ tx
338
+ }
339
+ pendingUpdateCancelledEvents(
340
+ first: $first
341
+ skip: $skip
342
+ orderBy: timestamp
343
+ orderDirection: desc
344
+ ) {
345
+ id
346
+ slot {
347
+ id
348
+ }
349
+ timestamp
350
+ tx
351
+ }
352
+ }
353
+ ${CurrencyFieldsFragmentDoc}`;
354
+ var GetBoughtEventsDocument = gql`
355
+ query GetBoughtEvents($first: Int!, $skip: Int, $orderBy: BoughtEvent_orderBy, $orderDirection: OrderDirection, $where: BoughtEvent_filter, $block: Block_height) {
356
+ boughtEvents(
357
+ first: $first
358
+ skip: $skip
359
+ orderBy: $orderBy
360
+ orderDirection: $orderDirection
361
+ where: $where
362
+ block: $block
363
+ ) {
364
+ id
365
+ slot {
366
+ id
367
+ }
368
+ currency {
369
+ ...CurrencyFields
370
+ }
371
+ buyer
372
+ previousOccupant
373
+ price
374
+ deposit
375
+ selfAssessedPrice
376
+ timestamp
377
+ blockNumber
378
+ tx
379
+ }
380
+ }
381
+ ${CurrencyFieldsFragmentDoc}`;
382
+ var GetReleasedEventsDocument = gql`
383
+ query GetReleasedEvents($first: Int!, $skip: Int, $orderBy: ReleasedEvent_orderBy, $orderDirection: OrderDirection, $where: ReleasedEvent_filter, $block: Block_height) {
384
+ releasedEvents(
385
+ first: $first
386
+ skip: $skip
387
+ orderBy: $orderBy
388
+ orderDirection: $orderDirection
389
+ where: $where
390
+ block: $block
391
+ ) {
392
+ id
393
+ slot {
394
+ id
395
+ }
396
+ currency {
397
+ ...CurrencyFields
398
+ }
399
+ occupant
400
+ refund
401
+ timestamp
402
+ blockNumber
403
+ tx
404
+ }
405
+ }
406
+ ${CurrencyFieldsFragmentDoc}`;
407
+ var GetLiquidatedEventsDocument = gql`
408
+ query GetLiquidatedEvents($first: Int!, $skip: Int, $orderBy: LiquidatedEvent_orderBy, $orderDirection: OrderDirection, $where: LiquidatedEvent_filter, $block: Block_height) {
409
+ liquidatedEvents(
410
+ first: $first
411
+ skip: $skip
412
+ orderBy: $orderBy
413
+ orderDirection: $orderDirection
414
+ where: $where
415
+ block: $block
416
+ ) {
417
+ id
418
+ slot {
419
+ id
420
+ }
421
+ currency {
422
+ ...CurrencyFields
423
+ }
424
+ liquidator
425
+ occupant
426
+ bounty
427
+ timestamp
428
+ blockNumber
429
+ tx
430
+ }
431
+ }
432
+ ${CurrencyFieldsFragmentDoc}`;
433
+ var GetSettledEventsDocument = gql`
434
+ query GetSettledEvents($first: Int!, $skip: Int, $orderBy: SettledEvent_orderBy, $orderDirection: OrderDirection, $where: SettledEvent_filter, $block: Block_height) {
435
+ settledEvents(
436
+ first: $first
437
+ skip: $skip
438
+ orderBy: $orderBy
439
+ orderDirection: $orderDirection
440
+ where: $where
441
+ block: $block
442
+ ) {
443
+ id
444
+ slot {
445
+ id
446
+ }
447
+ currency {
448
+ ...CurrencyFields
449
+ }
450
+ taxOwed
451
+ taxPaid
452
+ depositRemaining
453
+ timestamp
454
+ blockNumber
455
+ tx
456
+ }
457
+ }
458
+ ${CurrencyFieldsFragmentDoc}`;
459
+ var GetTaxCollectedEventsDocument = gql`
460
+ query GetTaxCollectedEvents($first: Int!, $skip: Int, $orderBy: TaxCollectedEvent_orderBy, $orderDirection: OrderDirection, $where: TaxCollectedEvent_filter, $block: Block_height) {
461
+ taxCollectedEvents(
462
+ first: $first
463
+ skip: $skip
464
+ orderBy: $orderBy
465
+ orderDirection: $orderDirection
466
+ where: $where
467
+ block: $block
468
+ ) {
469
+ id
470
+ slot {
471
+ id
472
+ }
473
+ currency {
474
+ ...CurrencyFields
475
+ }
476
+ recipient
477
+ amount
478
+ timestamp
479
+ blockNumber
480
+ tx
481
+ }
482
+ }
483
+ ${CurrencyFieldsFragmentDoc}`;
484
+ var GetDepositedEventsDocument = gql`
485
+ query GetDepositedEvents($first: Int!, $skip: Int, $orderBy: DepositedEvent_orderBy, $orderDirection: OrderDirection, $where: DepositedEvent_filter, $block: Block_height) {
486
+ depositedEvents(
487
+ first: $first
488
+ skip: $skip
489
+ orderBy: $orderBy
490
+ orderDirection: $orderDirection
491
+ where: $where
492
+ block: $block
493
+ ) {
494
+ id
495
+ slot {
496
+ id
497
+ }
498
+ currency {
499
+ ...CurrencyFields
500
+ }
501
+ depositor
502
+ amount
503
+ timestamp
504
+ blockNumber
505
+ tx
506
+ }
507
+ }
508
+ ${CurrencyFieldsFragmentDoc}`;
509
+ var GetWithdrawnEventsDocument = gql`
510
+ query GetWithdrawnEvents($first: Int!, $skip: Int, $orderBy: WithdrawnEvent_orderBy, $orderDirection: OrderDirection, $where: WithdrawnEvent_filter, $block: Block_height) {
511
+ withdrawnEvents(
512
+ first: $first
513
+ skip: $skip
514
+ orderBy: $orderBy
515
+ orderDirection: $orderDirection
516
+ where: $where
517
+ block: $block
518
+ ) {
519
+ id
520
+ slot {
521
+ id
522
+ }
523
+ currency {
524
+ ...CurrencyFields
525
+ }
526
+ occupant
527
+ amount
528
+ timestamp
529
+ blockNumber
530
+ tx
531
+ }
532
+ }
533
+ ${CurrencyFieldsFragmentDoc}`;
534
+ var GetPriceUpdatedEventsDocument = gql`
535
+ query GetPriceUpdatedEvents($first: Int!, $skip: Int, $orderBy: PriceUpdatedEvent_orderBy, $orderDirection: OrderDirection, $where: PriceUpdatedEvent_filter, $block: Block_height) {
536
+ priceUpdatedEvents(
537
+ first: $first
538
+ skip: $skip
539
+ orderBy: $orderBy
540
+ orderDirection: $orderDirection
541
+ where: $where
542
+ block: $block
543
+ ) {
544
+ id
545
+ slot {
546
+ id
547
+ }
548
+ currency {
549
+ ...CurrencyFields
550
+ }
551
+ oldPrice
552
+ newPrice
553
+ timestamp
554
+ blockNumber
555
+ tx
556
+ }
557
+ }
558
+ ${CurrencyFieldsFragmentDoc}`;
559
+ var GetSlotActivityDocument = gql`
560
+ query GetSlotActivity($slotId: String!, $first: Int!, $skip: Int) {
561
+ boughtEvents(
562
+ first: $first
563
+ skip: $skip
564
+ orderBy: timestamp
565
+ orderDirection: desc
566
+ where: {slot: $slotId}
567
+ ) {
568
+ id
569
+ currency {
570
+ ...CurrencyFields
571
+ }
572
+ buyer
573
+ previousOccupant
574
+ price
575
+ selfAssessedPrice
576
+ deposit
577
+ timestamp
578
+ tx
579
+ }
580
+ releasedEvents(
581
+ first: $first
582
+ skip: $skip
583
+ orderBy: timestamp
584
+ orderDirection: desc
585
+ where: {slot: $slotId}
586
+ ) {
587
+ id
588
+ currency {
589
+ ...CurrencyFields
590
+ }
591
+ occupant
592
+ refund
593
+ timestamp
594
+ tx
595
+ }
596
+ liquidatedEvents(
597
+ first: $first
598
+ skip: $skip
599
+ orderBy: timestamp
600
+ orderDirection: desc
601
+ where: {slot: $slotId}
602
+ ) {
603
+ id
604
+ currency {
605
+ ...CurrencyFields
606
+ }
607
+ liquidator
608
+ occupant
609
+ bounty
610
+ timestamp
611
+ tx
612
+ }
613
+ priceUpdatedEvents(
614
+ first: $first
615
+ skip: $skip
616
+ orderBy: timestamp
617
+ orderDirection: desc
618
+ where: {slot: $slotId}
619
+ ) {
620
+ id
621
+ currency {
622
+ ...CurrencyFields
623
+ }
624
+ oldPrice
625
+ newPrice
626
+ timestamp
627
+ tx
628
+ }
629
+ depositedEvents(
630
+ first: $first
631
+ skip: $skip
632
+ orderBy: timestamp
633
+ orderDirection: desc
634
+ where: {slot: $slotId}
635
+ ) {
636
+ id
637
+ currency {
638
+ ...CurrencyFields
639
+ }
640
+ depositor
641
+ amount
642
+ timestamp
643
+ tx
644
+ }
645
+ withdrawnEvents(
646
+ first: $first
647
+ skip: $skip
648
+ orderBy: timestamp
649
+ orderDirection: desc
650
+ where: {slot: $slotId}
651
+ ) {
652
+ id
653
+ currency {
654
+ ...CurrencyFields
655
+ }
656
+ occupant
657
+ amount
658
+ timestamp
659
+ tx
660
+ }
661
+ taxCollectedEvents(
662
+ first: $first
663
+ skip: $skip
664
+ orderBy: timestamp
665
+ orderDirection: desc
666
+ where: {slot: $slotId}
667
+ ) {
668
+ id
669
+ currency {
670
+ ...CurrencyFields
671
+ }
672
+ recipient
673
+ amount
674
+ timestamp
675
+ tx
676
+ }
677
+ taxUpdateProposedEvents(
678
+ first: $first
679
+ skip: $skip
680
+ orderBy: timestamp
681
+ orderDirection: desc
682
+ where: {slot: $slotId}
683
+ ) {
684
+ id
685
+ newPercentage
686
+ timestamp
687
+ tx
688
+ }
689
+ moduleUpdateProposedEvents(
690
+ first: $first
691
+ skip: $skip
692
+ orderBy: timestamp
693
+ orderDirection: desc
694
+ where: {slot: $slotId}
695
+ ) {
696
+ id
697
+ newModule
698
+ timestamp
699
+ tx
700
+ }
701
+ pendingUpdateCancelledEvents(
702
+ first: $first
703
+ skip: $skip
704
+ orderBy: timestamp
705
+ orderDirection: desc
706
+ where: {slot: $slotId}
707
+ ) {
708
+ id
709
+ timestamp
710
+ tx
711
+ }
712
+ }
713
+ ${CurrencyFieldsFragmentDoc}`;
714
+ var GetFactoryDocument = gql`
715
+ query GetFactory {
716
+ factories(first: 1) {
717
+ id
718
+ slotCount
719
+ }
720
+ }
721
+ `;
722
+ var GetModulesDocument = gql`
723
+ query GetModules($first: Int!) {
724
+ modules(first: $first) {
725
+ id
726
+ verified
727
+ name
728
+ version
729
+ }
730
+ }
731
+ `;
732
+ var GetMetadataSlotsDocument = gql`
733
+ query GetMetadataSlots($first: Int = 100, $skip: Int = 0, $orderBy: MetadataSlot_orderBy = updatedAt, $orderDirection: OrderDirection = desc) {
734
+ metadataSlots(
735
+ first: $first
736
+ skip: $skip
737
+ orderBy: $orderBy
738
+ orderDirection: $orderDirection
739
+ ) {
740
+ ...MetadataSlotFields
741
+ }
742
+ }
743
+ ${MetadataSlotFieldsFragmentDoc}`;
744
+ var GetMetadataSlotDocument = gql`
745
+ query GetMetadataSlot($id: ID!) {
746
+ metadataSlot(id: $id) {
747
+ ...MetadataSlotFields
748
+ }
749
+ }
750
+ ${MetadataSlotFieldsFragmentDoc}`;
751
+ var GetMetadataSlotsByRecipientDocument = gql`
752
+ query GetMetadataSlotsByRecipient($recipient: Bytes!, $first: Int = 100) {
753
+ metadataSlots(
754
+ first: $first
755
+ where: {slot_: {recipient: $recipient}}
756
+ orderBy: updatedAt
757
+ orderDirection: desc
758
+ ) {
759
+ ...MetadataSlotFields
760
+ }
761
+ }
762
+ ${MetadataSlotFieldsFragmentDoc}`;
763
+ var GetMetadataUpdatedEventsDocument = gql`
764
+ query GetMetadataUpdatedEvents($slot: String, $first: Int = 50, $orderBy: MetadataUpdatedEvent_orderBy = timestamp, $orderDirection: OrderDirection = desc) {
765
+ metadataUpdatedEvents(
766
+ first: $first
767
+ where: {slot: $slot}
768
+ orderBy: $orderBy
769
+ orderDirection: $orderDirection
770
+ ) {
771
+ id
772
+ slot {
773
+ id
774
+ }
775
+ author {
776
+ id
777
+ type
778
+ }
779
+ uri
780
+ rawJson
781
+ adType
782
+ timestamp
783
+ blockNumber
784
+ tx
785
+ }
786
+ }
787
+ `;
788
+ var GetSlotsDocument = gql`
789
+ query GetSlots($first: Int!, $skip: Int, $orderBy: Slot_orderBy, $orderDirection: OrderDirection, $where: Slot_filter, $block: Block_height) {
790
+ slots(
791
+ first: $first
792
+ skip: $skip
793
+ orderBy: $orderBy
794
+ orderDirection: $orderDirection
795
+ where: $where
796
+ block: $block
797
+ ) {
798
+ ...SlotFields
799
+ }
800
+ }
801
+ ${SlotFieldsFragmentDoc}`;
802
+ var GetSlotDocument = gql`
803
+ query GetSlot($id: ID!, $block: Block_height) {
804
+ slot(id: $id, block: $block) {
805
+ ...SlotFields
806
+ }
807
+ }
808
+ ${SlotFieldsFragmentDoc}`;
809
+ var GetSlotsByRecipientDocument = gql`
810
+ query GetSlotsByRecipient($recipient: Bytes!, $first: Int!, $skip: Int, $orderBy: Slot_orderBy, $orderDirection: OrderDirection, $block: Block_height) {
811
+ slots(
812
+ first: $first
813
+ skip: $skip
814
+ orderBy: $orderBy
815
+ orderDirection: $orderDirection
816
+ where: {recipient: $recipient}
817
+ block: $block
818
+ ) {
819
+ ...SlotFields
820
+ }
821
+ }
822
+ ${SlotFieldsFragmentDoc}`;
823
+ var GetSlotsByOccupantDocument = gql`
824
+ query GetSlotsByOccupant($occupant: Bytes!, $first: Int!, $skip: Int, $orderBy: Slot_orderBy, $orderDirection: OrderDirection, $block: Block_height) {
825
+ slots(
826
+ first: $first
827
+ skip: $skip
828
+ orderBy: $orderBy
829
+ orderDirection: $orderDirection
830
+ where: {occupant: $occupant}
831
+ block: $block
832
+ ) {
833
+ ...SlotFields
834
+ }
835
+ }
836
+ ${SlotFieldsFragmentDoc}`;
837
+ var defaultWrapper = (action, _operationName, _operationType, _variables) => action();
838
+ function getSdk(client, withWrapper = defaultWrapper) {
839
+ return {
840
+ GetAccount(variables, requestHeaders, signal) {
841
+ return withWrapper((wrappedRequestHeaders) => client.request({ document: GetAccountDocument, variables, requestHeaders: { ...requestHeaders, ...wrappedRequestHeaders }, signal }), "GetAccount", "query", variables);
842
+ },
843
+ GetAccounts(variables, requestHeaders, signal) {
844
+ return withWrapper((wrappedRequestHeaders) => client.request({ document: GetAccountsDocument, variables, requestHeaders: { ...requestHeaders, ...wrappedRequestHeaders }, signal }), "GetAccounts", "query", variables);
845
+ },
846
+ GetSlotDeployedEvents(variables, requestHeaders, signal) {
847
+ return withWrapper((wrappedRequestHeaders) => client.request({ document: GetSlotDeployedEventsDocument, variables, requestHeaders: { ...requestHeaders, ...wrappedRequestHeaders }, signal }), "GetSlotDeployedEvents", "query", variables);
848
+ },
849
+ GetRecentEvents(variables, requestHeaders, signal) {
850
+ return withWrapper((wrappedRequestHeaders) => client.request({ document: GetRecentEventsDocument, variables, requestHeaders: { ...requestHeaders, ...wrappedRequestHeaders }, signal }), "GetRecentEvents", "query", variables);
851
+ },
852
+ GetBoughtEvents(variables, requestHeaders, signal) {
853
+ return withWrapper((wrappedRequestHeaders) => client.request({ document: GetBoughtEventsDocument, variables, requestHeaders: { ...requestHeaders, ...wrappedRequestHeaders }, signal }), "GetBoughtEvents", "query", variables);
854
+ },
855
+ GetReleasedEvents(variables, requestHeaders, signal) {
856
+ return withWrapper((wrappedRequestHeaders) => client.request({ document: GetReleasedEventsDocument, variables, requestHeaders: { ...requestHeaders, ...wrappedRequestHeaders }, signal }), "GetReleasedEvents", "query", variables);
857
+ },
858
+ GetLiquidatedEvents(variables, requestHeaders, signal) {
859
+ return withWrapper((wrappedRequestHeaders) => client.request({ document: GetLiquidatedEventsDocument, variables, requestHeaders: { ...requestHeaders, ...wrappedRequestHeaders }, signal }), "GetLiquidatedEvents", "query", variables);
860
+ },
861
+ GetSettledEvents(variables, requestHeaders, signal) {
862
+ return withWrapper((wrappedRequestHeaders) => client.request({ document: GetSettledEventsDocument, variables, requestHeaders: { ...requestHeaders, ...wrappedRequestHeaders }, signal }), "GetSettledEvents", "query", variables);
863
+ },
864
+ GetTaxCollectedEvents(variables, requestHeaders, signal) {
865
+ return withWrapper((wrappedRequestHeaders) => client.request({ document: GetTaxCollectedEventsDocument, variables, requestHeaders: { ...requestHeaders, ...wrappedRequestHeaders }, signal }), "GetTaxCollectedEvents", "query", variables);
866
+ },
867
+ GetDepositedEvents(variables, requestHeaders, signal) {
868
+ return withWrapper((wrappedRequestHeaders) => client.request({ document: GetDepositedEventsDocument, variables, requestHeaders: { ...requestHeaders, ...wrappedRequestHeaders }, signal }), "GetDepositedEvents", "query", variables);
869
+ },
870
+ GetWithdrawnEvents(variables, requestHeaders, signal) {
871
+ return withWrapper((wrappedRequestHeaders) => client.request({ document: GetWithdrawnEventsDocument, variables, requestHeaders: { ...requestHeaders, ...wrappedRequestHeaders }, signal }), "GetWithdrawnEvents", "query", variables);
872
+ },
873
+ GetPriceUpdatedEvents(variables, requestHeaders, signal) {
874
+ return withWrapper((wrappedRequestHeaders) => client.request({ document: GetPriceUpdatedEventsDocument, variables, requestHeaders: { ...requestHeaders, ...wrappedRequestHeaders }, signal }), "GetPriceUpdatedEvents", "query", variables);
875
+ },
876
+ GetSlotActivity(variables, requestHeaders, signal) {
877
+ return withWrapper((wrappedRequestHeaders) => client.request({ document: GetSlotActivityDocument, variables, requestHeaders: { ...requestHeaders, ...wrappedRequestHeaders }, signal }), "GetSlotActivity", "query", variables);
878
+ },
879
+ GetFactory(variables, requestHeaders, signal) {
880
+ return withWrapper((wrappedRequestHeaders) => client.request({ document: GetFactoryDocument, variables, requestHeaders: { ...requestHeaders, ...wrappedRequestHeaders }, signal }), "GetFactory", "query", variables);
881
+ },
882
+ GetModules(variables, requestHeaders, signal) {
883
+ return withWrapper((wrappedRequestHeaders) => client.request({ document: GetModulesDocument, variables, requestHeaders: { ...requestHeaders, ...wrappedRequestHeaders }, signal }), "GetModules", "query", variables);
884
+ },
885
+ GetMetadataSlots(variables, requestHeaders, signal) {
886
+ return withWrapper((wrappedRequestHeaders) => client.request({ document: GetMetadataSlotsDocument, variables, requestHeaders: { ...requestHeaders, ...wrappedRequestHeaders }, signal }), "GetMetadataSlots", "query", variables);
887
+ },
888
+ GetMetadataSlot(variables, requestHeaders, signal) {
889
+ return withWrapper((wrappedRequestHeaders) => client.request({ document: GetMetadataSlotDocument, variables, requestHeaders: { ...requestHeaders, ...wrappedRequestHeaders }, signal }), "GetMetadataSlot", "query", variables);
890
+ },
891
+ GetMetadataSlotsByRecipient(variables, requestHeaders, signal) {
892
+ return withWrapper((wrappedRequestHeaders) => client.request({ document: GetMetadataSlotsByRecipientDocument, variables, requestHeaders: { ...requestHeaders, ...wrappedRequestHeaders }, signal }), "GetMetadataSlotsByRecipient", "query", variables);
893
+ },
894
+ GetMetadataUpdatedEvents(variables, requestHeaders, signal) {
895
+ return withWrapper((wrappedRequestHeaders) => client.request({ document: GetMetadataUpdatedEventsDocument, variables, requestHeaders: { ...requestHeaders, ...wrappedRequestHeaders }, signal }), "GetMetadataUpdatedEvents", "query", variables);
896
+ },
897
+ GetSlots(variables, requestHeaders, signal) {
898
+ return withWrapper((wrappedRequestHeaders) => client.request({ document: GetSlotsDocument, variables, requestHeaders: { ...requestHeaders, ...wrappedRequestHeaders }, signal }), "GetSlots", "query", variables);
899
+ },
900
+ GetSlot(variables, requestHeaders, signal) {
901
+ return withWrapper((wrappedRequestHeaders) => client.request({ document: GetSlotDocument, variables, requestHeaders: { ...requestHeaders, ...wrappedRequestHeaders }, signal }), "GetSlot", "query", variables);
902
+ },
903
+ GetSlotsByRecipient(variables, requestHeaders, signal) {
904
+ return withWrapper((wrappedRequestHeaders) => client.request({ document: GetSlotsByRecipientDocument, variables, requestHeaders: { ...requestHeaders, ...wrappedRequestHeaders }, signal }), "GetSlotsByRecipient", "query", variables);
905
+ },
906
+ GetSlotsByOccupant(variables, requestHeaders, signal) {
907
+ return withWrapper((wrappedRequestHeaders) => client.request({ document: GetSlotsByOccupantDocument, variables, requestHeaders: { ...requestHeaders, ...wrappedRequestHeaders }, signal }), "GetSlotsByOccupant", "query", variables);
908
+ }
909
+ };
910
+ }
911
+ var EXPECTED_MODULE_NAME = "MetadataModule";
912
+ var MetadataModuleClient = class {
913
+ constructor(opts) {
914
+ this.sdk = opts.sdk;
915
+ this._publicClient = opts.publicClient;
916
+ this._walletClient = opts.walletClient;
917
+ }
918
+ get wallet() {
919
+ if (!this._walletClient)
920
+ throw new SlotsError("metadata", "No walletClient provided");
921
+ return this._walletClient;
922
+ }
923
+ get account() {
924
+ const account = this.wallet.account;
925
+ if (!account)
926
+ throw new SlotsError("metadata", "WalletClient must have an account");
927
+ return account.address;
928
+ }
929
+ get chain() {
930
+ const chain = this.wallet.chain;
931
+ if (!chain)
932
+ throw new SlotsError("metadata", "WalletClient must have a chain");
933
+ return chain;
934
+ }
935
+ get publicClient() {
936
+ if (!this._publicClient)
937
+ throw new SlotsError("metadata", "No publicClient provided");
938
+ return this._publicClient;
939
+ }
940
+ async query(operation, fn) {
941
+ try {
942
+ return await fn();
943
+ } catch (error) {
944
+ throw new SlotsError(operation, error);
945
+ }
946
+ }
947
+ /**
948
+ * Verify that a given address is a MetadataModule by calling `name()` on-chain.
949
+ * @param moduleAddress - The module contract address to verify
950
+ * @throws SlotsError if the contract doesn't return the expected name
951
+ */
952
+ async verifyModule(moduleAddress) {
953
+ const name = await this.publicClient.readContract({
954
+ address: moduleAddress,
955
+ abi: metadataModuleAbi,
956
+ functionName: "name"
957
+ });
958
+ if (name !== EXPECTED_MODULE_NAME) {
959
+ throw new SlotsError(
960
+ "metadata",
961
+ `Contract at ${moduleAddress} is not a MetadataModule (name: "${name}")`
962
+ );
963
+ }
964
+ }
965
+ // ═══════════════════════════════════════════════════════════════════════════
966
+ // READ — Subgraph
967
+ // ═══════════════════════════════════════════════════════════════════════════
968
+ /** Get all slots with metadata, ordered by most recently updated. */
969
+ getSlots(...args) {
970
+ return this.query(
971
+ "metadata.getSlots",
972
+ () => this.sdk.GetMetadataSlots(...args)
973
+ );
974
+ }
975
+ /** Get a single metadata slot by slot address. */
976
+ getSlot(...args) {
977
+ return this.query(
978
+ "metadata.getSlot",
979
+ () => this.sdk.GetMetadataSlot(...args)
980
+ );
981
+ }
982
+ /** Get all metadata slots for a given recipient. */
983
+ getSlotsByRecipient(...args) {
984
+ return this.query(
985
+ "metadata.getSlotsByRecipient",
986
+ () => this.sdk.GetMetadataSlotsByRecipient(...args)
987
+ );
988
+ }
989
+ /** Get metadata update history for a slot. */
990
+ getUpdateHistory(...args) {
991
+ return this.query(
992
+ "metadata.getUpdateHistory",
993
+ () => this.sdk.GetMetadataUpdatedEvents(...args)
994
+ );
995
+ }
996
+ // ═══════════════════════════════════════════════════════════════════════════
997
+ // READ — RPC
998
+ // ═══════════════════════════════════════════════════════════════════════════
999
+ /**
1000
+ * Read the current URI for a slot directly from chain (bypasses subgraph).
1001
+ * @param moduleAddress - The MetadataModule contract address (from the slot's on-chain module field)
1002
+ * @param slot - The slot contract address
1003
+ */
1004
+ async getURI(moduleAddress, slot) {
1005
+ return this.query(
1006
+ "metadata.getURI",
1007
+ () => this.publicClient.readContract({
1008
+ address: moduleAddress,
1009
+ abi: metadataModuleAbi,
1010
+ functionName: "tokenURI",
1011
+ args: [slot]
1012
+ })
1013
+ );
1014
+ }
1015
+ // ═══════════════════════════════════════════════════════════════════════════
1016
+ // WRITE
1017
+ // ═══════════════════════════════════════════════════════════════════════════
1018
+ /**
1019
+ * Update the metadata URI for a slot. Only callable by the current occupant.
1020
+ * Verifies on-chain that the address is a MetadataModule before writing.
1021
+ * @param moduleAddress - The MetadataModule contract address (from the slot's on-chain module field)
1022
+ * @param slot - The slot contract address
1023
+ * @param uri - The new URI (e.g. ipfs://..., https://...)
1024
+ * @returns Transaction hash
1025
+ */
1026
+ async updateMetadata(moduleAddress, slot, uri) {
1027
+ await this.verifyModule(moduleAddress);
1028
+ return this.wallet.writeContract({
1029
+ address: moduleAddress,
1030
+ abi: metadataModuleAbi,
1031
+ functionName: "updateMetadata",
1032
+ args: [slot, uri],
1033
+ account: this.account,
1034
+ chain: this.chain
1035
+ });
1036
+ }
1037
+ };
1038
+ var META_QUERY = gql$1`
1039
+ query GetMeta {
1040
+ _meta {
1041
+ block {
1042
+ number
1043
+ hash
1044
+ timestamp
1045
+ }
1046
+ hasIndexingErrors
1047
+ }
1048
+ }
1049
+ `;
1050
+ var SlotsChain = /* @__PURE__ */ ((SlotsChain2) => {
1051
+ SlotsChain2[SlotsChain2["BASE"] = 8453] = "BASE";
1052
+ SlotsChain2[SlotsChain2["BASE_SEPOLIA"] = 84532] = "BASE_SEPOLIA";
1053
+ return SlotsChain2;
1054
+ })(SlotsChain || {});
1055
+ var SUBGRAPH_URLS = {
1056
+ [84532 /* BASE_SEPOLIA */]: "https://gateway.thegraph.com/api/subgraphs/id/Z361DLoMdPh9WAopH7shJP8WoXYAB9XeKrLUCTYjdZR",
1057
+ [8453 /* BASE */]: "https://gateway.thegraph.com/api/subgraphs/id/4sZrdv1SFzN4KzE9jiWDRuUyM4CnCrmvQ54Rv1s65qUq"
1058
+ };
1059
+ var SlotsClient = class {
1060
+ constructor(config) {
1061
+ this.chainId = config.chainId;
1062
+ this._publicClient = config.publicClient;
1063
+ this.walletClient = config.walletClient;
1064
+ this._factory = config.factoryAddress ?? getSlotsHubAddress(config.chainId);
1065
+ const url = config.subgraphUrl || SUBGRAPH_URLS[config.chainId];
1066
+ if (!url) throw new Error(`No subgraph URL for chain ${config.chainId}`);
1067
+ const headers = { ...config.headers };
1068
+ if (config.subgraphApiKey) {
1069
+ headers["Authorization"] = `Bearer ${config.subgraphApiKey}`;
1070
+ }
1071
+ this.gqlClient = new GraphQLClient(url, { headers });
1072
+ this.sdk = getSdk(this.gqlClient);
1073
+ this.modules = {
1074
+ metadata: new MetadataModuleClient({
1075
+ sdk: this.sdk,
1076
+ publicClient: config.publicClient,
1077
+ walletClient: config.walletClient
1078
+ })
1079
+ };
1080
+ }
1081
+ // ─── Accessors ──────────────────────────────────────────────────────────────
1082
+ /** Returns the chain ID this client was configured for. */
1083
+ getChainId() {
1084
+ return this.chainId;
1085
+ }
1086
+ /** Returns the underlying GraphQL client (for advanced usage). */
1087
+ getClient() {
1088
+ return this.gqlClient;
1089
+ }
1090
+ /** Returns the generated GraphQL SDK (for queries not wrapped by this client). */
1091
+ getSdk() {
1092
+ return this.sdk;
1093
+ }
1094
+ get publicClient() {
1095
+ if (!this._publicClient) throw new Error("No publicClient provided");
1096
+ return this._publicClient;
1097
+ }
1098
+ get factory() {
1099
+ if (!this._factory) throw new Error("No factoryAddress provided");
1100
+ return this._factory;
1101
+ }
1102
+ get wallet() {
1103
+ if (!this.walletClient) throw new Error("No walletClient provided");
1104
+ return this.walletClient;
1105
+ }
1106
+ get account() {
1107
+ const account = this.wallet.account;
1108
+ if (!account) throw new Error("WalletClient must have an account");
1109
+ return account.address;
1110
+ }
1111
+ get chain() {
1112
+ const chain = this.wallet.chain;
1113
+ if (!chain) throw new Error("WalletClient must have a chain");
1114
+ return chain;
1115
+ }
1116
+ // ─── Helpers ────────────────────────────────────────────────────────────────
1117
+ assertPositive(value, name) {
1118
+ if (value <= 0n) throw new SlotsError(name, `${name} must be > 0`);
1119
+ }
1120
+ async query(operation, fn) {
1121
+ try {
1122
+ return await fn();
1123
+ } catch (error) {
1124
+ throw new SlotsError(operation, error);
1125
+ }
1126
+ }
1127
+ // ═══════════════════════════════════════════════════════════════════════════
1128
+ // READ — Subgraph Queries
1129
+ // ═══════════════════════════════════════════════════════════════════════════
1130
+ // Slot queries
1131
+ /** Fetch a paginated list of slots. */
1132
+ getSlots(...args) {
1133
+ return this.query("getSlots", () => this.sdk.GetSlots(...args));
1134
+ }
1135
+ /** Fetch a single slot by its address. */
1136
+ getSlot(...args) {
1137
+ return this.query("getSlot", () => this.sdk.GetSlot(...args));
1138
+ }
1139
+ /** Fetch all slots owned by a given recipient address. */
1140
+ getSlotsByRecipient(...args) {
1141
+ return this.query(
1142
+ "getSlotsByRecipient",
1143
+ () => this.sdk.GetSlotsByRecipient(...args)
1144
+ );
1145
+ }
1146
+ /** Fetch all slots currently occupied by a given address. */
1147
+ getSlotsByOccupant(...args) {
1148
+ return this.query(
1149
+ "getSlotsByOccupant",
1150
+ () => this.sdk.GetSlotsByOccupant(...args)
1151
+ );
1152
+ }
1153
+ // Factory queries
1154
+ /** Fetch factory configuration. */
1155
+ getFactory() {
1156
+ return this.query("getFactory", () => this.sdk.GetFactory());
1157
+ }
1158
+ /** Fetch registered modules. */
1159
+ getModules(...args) {
1160
+ return this.query("getModules", () => this.sdk.GetModules(...args));
1161
+ }
1162
+ // Event queries
1163
+ /** Fetch slot deployed events with optional filters. */
1164
+ getSlotDeployedEvents(...args) {
1165
+ return this.query(
1166
+ "getSlotDeployedEvents",
1167
+ () => this.sdk.GetSlotDeployedEvents(...args)
1168
+ );
1169
+ }
1170
+ /** Fetch bought events with optional filters. */
1171
+ getBoughtEvents(...args) {
1172
+ return this.query(
1173
+ "getBoughtEvents",
1174
+ () => this.sdk.GetBoughtEvents(...args)
1175
+ );
1176
+ }
1177
+ /** Fetch settled events with optional filters. */
1178
+ getSettledEvents(...args) {
1179
+ return this.query(
1180
+ "getSettledEvents",
1181
+ () => this.sdk.GetSettledEvents(...args)
1182
+ );
1183
+ }
1184
+ /** Fetch tax-collected events with optional filters. */
1185
+ getTaxCollectedEvents(...args) {
1186
+ return this.query(
1187
+ "getTaxCollectedEvents",
1188
+ () => this.sdk.GetTaxCollectedEvents(...args)
1189
+ );
1190
+ }
1191
+ /** Fetch all activity for a specific slot (all event types). */
1192
+ getSlotActivity(...args) {
1193
+ return this.query(
1194
+ "getSlotActivity",
1195
+ () => this.sdk.GetSlotActivity(...args)
1196
+ );
1197
+ }
1198
+ /** Fetch the most recent events across all slots. */
1199
+ getRecentEvents(...args) {
1200
+ return this.query(
1201
+ "getRecentEvents",
1202
+ () => this.sdk.GetRecentEvents(...args)
1203
+ );
1204
+ }
1205
+ // Account queries
1206
+ /** Fetch a single account by address. */
1207
+ getAccount(...args) {
1208
+ return this.query("getAccount", () => this.sdk.GetAccount(...args));
1209
+ }
1210
+ /** Fetch a paginated list of accounts. */
1211
+ getAccounts(...args) {
1212
+ return this.query("getAccounts", () => this.sdk.GetAccounts(...args));
1213
+ }
1214
+ // Individual event queries
1215
+ /** Fetch released events with optional filters. */
1216
+ getReleasedEvents(...args) {
1217
+ return this.query(
1218
+ "getReleasedEvents",
1219
+ () => this.sdk.GetReleasedEvents(...args)
1220
+ );
1221
+ }
1222
+ /** Fetch liquidated events with optional filters. */
1223
+ getLiquidatedEvents(...args) {
1224
+ return this.query(
1225
+ "getLiquidatedEvents",
1226
+ () => this.sdk.GetLiquidatedEvents(...args)
1227
+ );
1228
+ }
1229
+ /** Fetch deposited events with optional filters. */
1230
+ getDepositedEvents(...args) {
1231
+ return this.query(
1232
+ "getDepositedEvents",
1233
+ () => this.sdk.GetDepositedEvents(...args)
1234
+ );
1235
+ }
1236
+ /** Fetch withdrawn events with optional filters. */
1237
+ getWithdrawnEvents(...args) {
1238
+ return this.query(
1239
+ "getWithdrawnEvents",
1240
+ () => this.sdk.GetWithdrawnEvents(...args)
1241
+ );
1242
+ }
1243
+ /** Fetch price-updated events with optional filters. */
1244
+ getPriceUpdatedEvents(...args) {
1245
+ return this.query(
1246
+ "getPriceUpdatedEvents",
1247
+ () => this.sdk.GetPriceUpdatedEvents(...args)
1248
+ );
1249
+ }
1250
+ // Meta
1251
+ /** Fetch subgraph indexing metadata (latest block, indexing errors). */
1252
+ getMeta() {
1253
+ return this.query(
1254
+ "getMeta",
1255
+ () => this.gqlClient.request(META_QUERY)
1256
+ );
1257
+ }
1258
+ // ═══════════════════════════════════════════════════════════════════════════
1259
+ // READ — On-chain (RPC)
1260
+ // ═══════════════════════════════════════════════════════════════════════════
1261
+ /**
1262
+ * Read full slot info from on-chain (RPC, not subgraph).
1263
+ * @param slot - Slot contract address.
1264
+ * @returns On-chain slot info tuple.
1265
+ * @throws {SlotsError} If the RPC call fails.
1266
+ */
1267
+ getSlotInfo(slot) {
1268
+ return this.query(
1269
+ "getSlotInfo",
1270
+ () => this.publicClient.readContract({
1271
+ address: slot,
1272
+ abi: slotAbi,
1273
+ functionName: "getSlotInfo"
1274
+ })
1275
+ );
1276
+ }
1277
+ // ═══════════════════════════════════════════════════════════════════════════
1278
+ // WRITE — Factory Functions
1279
+ // ═══════════════════════════════════════════════════════════════════════════
1280
+ /**
1281
+ * Deploy a new slot via the factory contract.
1282
+ * @param params - Slot creation parameters (recipient, currency, config, initParams).
1283
+ * @returns Transaction hash.
1284
+ */
1285
+ async createSlot(params) {
1286
+ return this.wallet.writeContract({
1287
+ address: this.factory,
1288
+ abi: slotFactoryAbi,
1289
+ functionName: "createSlot",
1290
+ args: [params.recipient, params.currency, params.config, params.initParams],
1291
+ account: this.account,
1292
+ chain: this.chain
1293
+ });
1294
+ }
1295
+ /**
1296
+ * Deploy multiple identical slots in a single transaction via the factory contract.
1297
+ * @param params - Slot creation parameters including count.
1298
+ * @returns Transaction hash.
1299
+ */
1300
+ async createSlots(params) {
1301
+ return this.wallet.writeContract({
1302
+ address: this.factory,
1303
+ abi: slotFactoryAbi,
1304
+ functionName: "createSlots",
1305
+ args: [
1306
+ params.recipient,
1307
+ params.currency,
1308
+ params.config,
1309
+ params.initParams,
1310
+ params.count
1311
+ ],
1312
+ account: this.account,
1313
+ chain: this.chain
1314
+ });
1315
+ }
1316
+ // ═══════════════════════════════════════════════════════════════════════════
1317
+ // WRITE — Slot Functions
1318
+ // ═══════════════════════════════════════════════════════════════════════════
1319
+ /**
1320
+ * Buy a slot (or force-buy an occupied one). Handles ERC-20 approval automatically.
1321
+ * @param params - Buy parameters (slot address, deposit amount, self-assessed price).
1322
+ * @returns Transaction hash.
1323
+ * @throws {SlotsError} If depositAmount or selfAssessedPrice is not positive, or the transaction fails.
1324
+ */
1325
+ async buy(params) {
1326
+ this.assertPositive(params.depositAmount, "depositAmount");
1327
+ this.assertPositive(params.selfAssessedPrice, "selfAssessedPrice");
1328
+ return this.withAllowance(params.slot, params.depositAmount, {
1329
+ to: params.slot,
1330
+ abi: slotAbi,
1331
+ functionName: "buy",
1332
+ args: [params.depositAmount, params.selfAssessedPrice]
1333
+ });
1334
+ }
1335
+ /**
1336
+ * Self-assess a new price for an occupied slot (occupant only).
1337
+ * @param slot - The slot contract address.
1338
+ * @param newPrice - The new self-assessed price (can be 0).
1339
+ * @returns Transaction hash.
1340
+ */
1341
+ async selfAssess(slot, newPrice) {
1342
+ return this.wallet.writeContract({
1343
+ address: slot,
1344
+ abi: slotAbi,
1345
+ functionName: "selfAssess",
1346
+ args: [newPrice],
1347
+ account: this.account,
1348
+ chain: this.chain
1349
+ });
1350
+ }
1351
+ /**
1352
+ * Top up deposit on a slot (occupant only). Handles ERC-20 approval automatically.
1353
+ * @param slot - The slot contract address.
1354
+ * @param amount - The amount to deposit (must be > 0).
1355
+ * @returns Transaction hash.
1356
+ * @throws {SlotsError} If amount is not positive, or the transaction fails.
1357
+ */
1358
+ async topUp(slot, amount) {
1359
+ this.assertPositive(amount, "amount");
1360
+ return this.withAllowance(slot, amount, {
1361
+ to: slot,
1362
+ abi: slotAbi,
1363
+ functionName: "topUp",
1364
+ args: [amount]
1365
+ });
1366
+ }
1367
+ /**
1368
+ * Withdraw from deposit (occupant only). Cannot go below minimum deposit.
1369
+ * @param slot - The slot contract address.
1370
+ * @param amount - The amount to withdraw (must be > 0).
1371
+ * @returns Transaction hash.
1372
+ * @throws {SlotsError} If amount is not positive, or the transaction fails.
1373
+ */
1374
+ async withdraw(slot, amount) {
1375
+ this.assertPositive(amount, "amount");
1376
+ return this.wallet.writeContract({
1377
+ address: slot,
1378
+ abi: slotAbi,
1379
+ functionName: "withdraw",
1380
+ args: [amount],
1381
+ account: this.account,
1382
+ chain: this.chain
1383
+ });
1384
+ }
1385
+ /**
1386
+ * Release a slot (occupant only). Returns remaining deposit to the occupant.
1387
+ * @param slot - The slot contract address.
1388
+ * @returns Transaction hash.
1389
+ */
1390
+ async release(slot) {
1391
+ return this.wallet.writeContract({
1392
+ address: slot,
1393
+ abi: slotAbi,
1394
+ functionName: "release",
1395
+ account: this.account,
1396
+ chain: this.chain
1397
+ });
1398
+ }
1399
+ /**
1400
+ * Collect accumulated tax (permissionless).
1401
+ * @param slot - The slot contract address.
1402
+ * @returns Transaction hash.
1403
+ */
1404
+ async collect(slot) {
1405
+ return this.wallet.writeContract({
1406
+ address: slot,
1407
+ abi: slotAbi,
1408
+ functionName: "collect",
1409
+ account: this.account,
1410
+ chain: this.chain
1411
+ });
1412
+ }
1413
+ /**
1414
+ * Liquidate an insolvent slot (permissionless). Caller receives bounty.
1415
+ * @param slot - The slot contract address.
1416
+ * @returns Transaction hash.
1417
+ */
1418
+ async liquidate(slot) {
1419
+ return this.wallet.writeContract({
1420
+ address: slot,
1421
+ abi: slotAbi,
1422
+ functionName: "liquidate",
1423
+ account: this.account,
1424
+ chain: this.chain
1425
+ });
1426
+ }
1427
+ // ═══════════════════════════════════════════════════════════════════════════
1428
+ // WRITE — Manager Functions
1429
+ // ═══════════════════════════════════════════════════════════════════════════
1430
+ /**
1431
+ * Propose a tax rate update (manager only, slot must have mutableTax).
1432
+ * @param slot - The slot contract address.
1433
+ * @param newPct - The new tax percentage.
1434
+ * @returns Transaction hash.
1435
+ */
1436
+ async proposeTaxUpdate(slot, newPct) {
1437
+ return this.wallet.writeContract({
1438
+ address: slot,
1439
+ abi: slotAbi,
1440
+ functionName: "proposeTaxUpdate",
1441
+ args: [newPct],
1442
+ account: this.account,
1443
+ chain: this.chain
1444
+ });
1445
+ }
1446
+ /**
1447
+ * Propose a module update (manager only, slot must have mutableModule).
1448
+ * @param slot - The slot contract address.
1449
+ * @param newModule - The new module contract address.
1450
+ * @returns Transaction hash.
1451
+ */
1452
+ async proposeModuleUpdate(slot, newModule) {
1453
+ return this.wallet.writeContract({
1454
+ address: slot,
1455
+ abi: slotAbi,
1456
+ functionName: "proposeModuleUpdate",
1457
+ args: [newModule],
1458
+ account: this.account,
1459
+ chain: this.chain
1460
+ });
1461
+ }
1462
+ /**
1463
+ * Cancel pending updates (manager only).
1464
+ * @param slot - The slot contract address.
1465
+ * @returns Transaction hash.
1466
+ */
1467
+ async cancelPendingUpdates(slot) {
1468
+ return this.wallet.writeContract({
1469
+ address: slot,
1470
+ abi: slotAbi,
1471
+ functionName: "cancelPendingUpdates",
1472
+ account: this.account,
1473
+ chain: this.chain
1474
+ });
1475
+ }
1476
+ /**
1477
+ * Set liquidation bounty bps (manager only).
1478
+ * @param slot - The slot contract address.
1479
+ * @param newBps - The new bounty in basis points (0-10000).
1480
+ * @returns Transaction hash.
1481
+ * @throws {SlotsError} If newBps is outside 0-10000, or the transaction fails.
1482
+ */
1483
+ async setLiquidationBounty(slot, newBps) {
1484
+ if (newBps < 0n || newBps > 10000n)
1485
+ throw new SlotsError("setLiquidationBounty", "newBps must be 0-10000");
1486
+ return this.wallet.writeContract({
1487
+ address: slot,
1488
+ abi: slotAbi,
1489
+ functionName: "setLiquidationBounty",
1490
+ args: [newBps],
1491
+ account: this.account,
1492
+ chain: this.chain
1493
+ });
1494
+ }
1495
+ // ═══════════════════════════════════════════════════════════════════════════
1496
+ // WRITE — Multicall
1497
+ // ═══════════════════════════════════════════════════════════════════════════
1498
+ /**
1499
+ * Batch multiple slot calls into one transaction via multicall.
1500
+ * @param slot - The slot contract address.
1501
+ * @param calls - Array of function calls to batch.
1502
+ * @returns Transaction hash.
1503
+ * @throws {SlotsError} If calls array is empty, or the transaction fails.
1504
+ */
1505
+ async multicall(slot, calls) {
1506
+ if (calls.length === 0)
1507
+ throw new SlotsError("multicall", "calls array must not be empty");
1508
+ const data = calls.map(
1509
+ (call) => encodeFunctionData({
1510
+ abi: slotAbi,
1511
+ functionName: call.functionName,
1512
+ args: call.args
1513
+ })
1514
+ );
1515
+ return this.wallet.writeContract({
1516
+ address: slot,
1517
+ abi: slotAbi,
1518
+ functionName: "multicall",
1519
+ args: [data],
1520
+ account: this.account,
1521
+ chain: this.chain
1522
+ });
1523
+ }
1524
+ // ─── Internals ──────────────────────────────────────────────────────────────
1525
+ /** Check if wallet supports atomic batch calls (EIP-5792). */
1526
+ async supportsAtomicBatch() {
1527
+ if (this._atomicSupport !== void 0) return this._atomicSupport;
1528
+ try {
1529
+ const capabilities = await this.wallet.getCapabilities?.();
1530
+ if (!capabilities) {
1531
+ this._atomicSupport = false;
1532
+ return false;
1533
+ }
1534
+ const chainId = this.chain.id;
1535
+ const chainCaps = capabilities[chainId] || capabilities[`0x${chainId.toString(16)}`];
1536
+ const atomic = chainCaps?.atomicBatch ?? chainCaps?.atomic;
1537
+ const status = atomic && typeof atomic === "object" && "status" in atomic ? atomic.status : void 0;
1538
+ this._atomicSupport = status === "supported" || status === "ready";
1539
+ } catch {
1540
+ this._atomicSupport = false;
1541
+ }
1542
+ return this._atomicSupport;
1543
+ }
1544
+ /** Poll EIP-5792 getCallsStatus until the batch settles, then return a tx hash. */
1545
+ async pollBatchReceipt(id) {
1546
+ const MAX_ATTEMPTS = 60;
1547
+ const INTERVAL = 1500;
1548
+ for (let i = 0; i < MAX_ATTEMPTS; i++) {
1549
+ const result = await this.wallet.getCallsStatus({ id });
1550
+ if (result.status === "success") {
1551
+ const receipts = result.receipts ?? [];
1552
+ return receipts[receipts.length - 1]?.transactionHash ?? id;
1553
+ }
1554
+ if (result.status === "failure") {
1555
+ throw new Error("Batch transaction reverted");
1556
+ }
1557
+ await new Promise((r) => setTimeout(r, INTERVAL));
1558
+ }
1559
+ throw new Error("Batch transaction timed out");
1560
+ }
1561
+ /**
1562
+ * Execute a contract call that needs ERC-20 allowance.
1563
+ * If wallet supports atomic batch (EIP-5792): sends approve + action as one atomic call.
1564
+ * Otherwise: chains approve tx (if needed) then action tx.
1565
+ */
1566
+ async withAllowance(spender, amount, call) {
1567
+ const currency = await this.publicClient.readContract({
1568
+ address: spender,
1569
+ abi: slotAbi,
1570
+ functionName: "currency"
1571
+ });
1572
+ const allowance = await this.publicClient.readContract({
1573
+ address: currency,
1574
+ abi: erc20Abi,
1575
+ functionName: "allowance",
1576
+ args: [this.account, spender]
1577
+ });
1578
+ const needsApproval = allowance < amount;
1579
+ if (needsApproval && await this.supportsAtomicBatch()) {
1580
+ const approveData = encodeFunctionData({
1581
+ abi: erc20Abi,
1582
+ functionName: "approve",
1583
+ args: [spender, amount]
1584
+ });
1585
+ const actionData = encodeFunctionData({
1586
+ abi: call.abi,
1587
+ functionName: call.functionName,
1588
+ args: call.args
1589
+ });
1590
+ const id = await this.wallet.sendCalls({
1591
+ account: this.account,
1592
+ chain: this.chain,
1593
+ calls: [
1594
+ { to: currency, data: approveData },
1595
+ { to: call.to, data: actionData }
1596
+ ]
1597
+ });
1598
+ const txHash = await this.pollBatchReceipt(id);
1599
+ return txHash;
1600
+ }
1601
+ if (needsApproval) {
1602
+ const hash = await this.wallet.writeContract({
1603
+ address: currency,
1604
+ abi: erc20Abi,
1605
+ functionName: "approve",
1606
+ args: [spender, amount],
1607
+ account: this.account,
1608
+ chain: this.chain
1609
+ });
1610
+ await this.publicClient.waitForTransactionReceipt({ hash });
1611
+ }
1612
+ return this.wallet.writeContract({
1613
+ address: call.to,
1614
+ abi: call.abi,
1615
+ functionName: call.functionName,
1616
+ args: call.args,
1617
+ account: this.account,
1618
+ chain: this.chain
1619
+ });
1620
+ }
1621
+ };
1622
+ function createSlotsClient(config) {
1623
+ return new SlotsClient(config);
1624
+ }
1625
+
1626
+ export { AccountFieldsFragmentDoc, CurrencyFieldsFragmentDoc, GetAccountDocument, GetAccountsDocument, GetBoughtEventsDocument, GetDepositedEventsDocument, GetFactoryDocument, GetLiquidatedEventsDocument, GetMetadataSlotDocument, GetMetadataSlotsByRecipientDocument, GetMetadataSlotsDocument, GetMetadataUpdatedEventsDocument, GetModulesDocument, GetPriceUpdatedEventsDocument, GetRecentEventsDocument, GetReleasedEventsDocument, GetSettledEventsDocument, GetSlotActivityDocument, GetSlotDeployedEventsDocument, GetSlotDocument, GetSlotsByOccupantDocument, GetSlotsByRecipientDocument, GetSlotsDocument, GetTaxCollectedEventsDocument, GetWithdrawnEventsDocument, MetadataModuleClient, MetadataSlotFieldsFragmentDoc, SUBGRAPH_URLS, SlotFieldsFragmentDoc, SlotsChain, SlotsClient, SlotsError, createSlotsClient, getSdk };
1627
+ //# sourceMappingURL=chunk-VQ5PSOCE.js.map
1628
+ //# sourceMappingURL=chunk-VQ5PSOCE.js.map