@0xslots/sdk 0.9.1 → 0.10.0

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