@vibeiao/sdk 0.1.5 → 0.1.7

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,1412 @@
1
+ // src/solana.ts
2
+ import { AnchorProvider, Program } from "@coral-xyz/anchor";
3
+ import {
4
+ LAMPORTS_PER_SOL,
5
+ PublicKey,
6
+ SystemProgram
7
+ } from "@solana/web3.js";
8
+ import BN from "bn.js";
9
+
10
+ // src/idl.ts
11
+ var VIBEIAO_IDL = {
12
+ "address": "5jnUTmty5yjiAFsZJpmmwRL68fNFMDJZQwqkiL2kFSoS",
13
+ "metadata": {
14
+ "name": "vibeiao",
15
+ "version": "0.1.0",
16
+ "spec": "0.1.0"
17
+ },
18
+ "instructions": [
19
+ {
20
+ "name": "create_listing",
21
+ "discriminator": [
22
+ 18,
23
+ 168,
24
+ 45,
25
+ 24,
26
+ 191,
27
+ 31,
28
+ 117,
29
+ 54
30
+ ],
31
+ "accounts": [
32
+ {
33
+ "name": "creator",
34
+ "writable": true,
35
+ "signer": true
36
+ },
37
+ {
38
+ "name": "listing",
39
+ "writable": true,
40
+ "pda": {
41
+ "seeds": [
42
+ {
43
+ "kind": "const",
44
+ "value": [
45
+ 108,
46
+ 105,
47
+ 115,
48
+ 116,
49
+ 105,
50
+ 110,
51
+ 103
52
+ ]
53
+ },
54
+ {
55
+ "kind": "account",
56
+ "path": "creator"
57
+ },
58
+ {
59
+ "kind": "arg",
60
+ "path": "listing_seed"
61
+ }
62
+ ]
63
+ }
64
+ },
65
+ {
66
+ "name": "system_program",
67
+ "address": "11111111111111111111111111111111"
68
+ }
69
+ ],
70
+ "args": [
71
+ {
72
+ "name": "listing_seed",
73
+ "type": {
74
+ "array": [
75
+ "u8",
76
+ 32
77
+ ]
78
+ }
79
+ },
80
+ {
81
+ "name": "revenue_wallet",
82
+ "type": "pubkey"
83
+ },
84
+ {
85
+ "name": "listing_type",
86
+ "type": {
87
+ "defined": {
88
+ "name": "ListingType"
89
+ }
90
+ }
91
+ },
92
+ {
93
+ "name": "name",
94
+ "type": "string"
95
+ },
96
+ {
97
+ "name": "tagline",
98
+ "type": "string"
99
+ },
100
+ {
101
+ "name": "description",
102
+ "type": "string"
103
+ },
104
+ {
105
+ "name": "category",
106
+ "type": "string"
107
+ },
108
+ {
109
+ "name": "image_url",
110
+ "type": "string"
111
+ },
112
+ {
113
+ "name": "product_url",
114
+ "type": "string"
115
+ },
116
+ {
117
+ "name": "endpoint_url",
118
+ "type": "string"
119
+ },
120
+ {
121
+ "name": "manifest_url",
122
+ "type": "string"
123
+ },
124
+ {
125
+ "name": "ticket_price",
126
+ "type": "u64"
127
+ },
128
+ {
129
+ "name": "target_revenue",
130
+ "type": "u64"
131
+ }
132
+ ]
133
+ },
134
+ {
135
+ "name": "initialize_config",
136
+ "discriminator": [
137
+ 208,
138
+ 127,
139
+ 21,
140
+ 1,
141
+ 194,
142
+ 190,
143
+ 196,
144
+ 70
145
+ ],
146
+ "accounts": [
147
+ {
148
+ "name": "authority",
149
+ "writable": true,
150
+ "signer": true
151
+ },
152
+ {
153
+ "name": "config",
154
+ "writable": true,
155
+ "pda": {
156
+ "seeds": [
157
+ {
158
+ "kind": "const",
159
+ "value": [
160
+ 99,
161
+ 111,
162
+ 110,
163
+ 102,
164
+ 105,
165
+ 103
166
+ ]
167
+ }
168
+ ]
169
+ }
170
+ },
171
+ {
172
+ "name": "system_program",
173
+ "address": "11111111111111111111111111111111"
174
+ }
175
+ ],
176
+ "args": [
177
+ {
178
+ "name": "platform_treasury",
179
+ "type": "pubkey"
180
+ },
181
+ {
182
+ "name": "buyback_treasury",
183
+ "type": "pubkey"
184
+ }
185
+ ]
186
+ },
187
+ {
188
+ "name": "initialize_token",
189
+ "discriminator": [
190
+ 38,
191
+ 209,
192
+ 150,
193
+ 50,
194
+ 190,
195
+ 117,
196
+ 16,
197
+ 54
198
+ ],
199
+ "accounts": [
200
+ {
201
+ "name": "creator",
202
+ "writable": true,
203
+ "signer": true,
204
+ "relations": [
205
+ "listing"
206
+ ]
207
+ },
208
+ {
209
+ "name": "listing",
210
+ "writable": true,
211
+ "pda": {
212
+ "seeds": [
213
+ {
214
+ "kind": "const",
215
+ "value": [
216
+ 108,
217
+ 105,
218
+ 115,
219
+ 116,
220
+ 105,
221
+ 110,
222
+ 103
223
+ ]
224
+ },
225
+ {
226
+ "kind": "account",
227
+ "path": "creator"
228
+ },
229
+ {
230
+ "kind": "arg",
231
+ "path": "listing_seed"
232
+ }
233
+ ]
234
+ }
235
+ },
236
+ {
237
+ "name": "mint",
238
+ "writable": true,
239
+ "signer": true
240
+ },
241
+ {
242
+ "name": "creator_token_account",
243
+ "writable": true,
244
+ "pda": {
245
+ "seeds": [
246
+ {
247
+ "kind": "account",
248
+ "path": "creator"
249
+ },
250
+ {
251
+ "kind": "const",
252
+ "value": [
253
+ 6,
254
+ 221,
255
+ 246,
256
+ 225,
257
+ 215,
258
+ 101,
259
+ 161,
260
+ 147,
261
+ 217,
262
+ 203,
263
+ 225,
264
+ 70,
265
+ 206,
266
+ 235,
267
+ 121,
268
+ 172,
269
+ 28,
270
+ 180,
271
+ 133,
272
+ 237,
273
+ 95,
274
+ 91,
275
+ 55,
276
+ 145,
277
+ 58,
278
+ 140,
279
+ 245,
280
+ 133,
281
+ 126,
282
+ 255,
283
+ 0,
284
+ 169
285
+ ]
286
+ },
287
+ {
288
+ "kind": "account",
289
+ "path": "mint"
290
+ }
291
+ ],
292
+ "program": {
293
+ "kind": "const",
294
+ "value": [
295
+ 140,
296
+ 151,
297
+ 37,
298
+ 143,
299
+ 78,
300
+ 36,
301
+ 137,
302
+ 241,
303
+ 187,
304
+ 61,
305
+ 16,
306
+ 41,
307
+ 20,
308
+ 142,
309
+ 13,
310
+ 131,
311
+ 11,
312
+ 90,
313
+ 19,
314
+ 153,
315
+ 218,
316
+ 255,
317
+ 16,
318
+ 132,
319
+ 4,
320
+ 142,
321
+ 123,
322
+ 216,
323
+ 219,
324
+ 233,
325
+ 248,
326
+ 89
327
+ ]
328
+ }
329
+ }
330
+ },
331
+ {
332
+ "name": "token_program",
333
+ "address": "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA"
334
+ },
335
+ {
336
+ "name": "associated_token_program",
337
+ "address": "ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL"
338
+ },
339
+ {
340
+ "name": "system_program",
341
+ "address": "11111111111111111111111111111111"
342
+ },
343
+ {
344
+ "name": "rent",
345
+ "address": "SysvarRent111111111111111111111111111111111"
346
+ }
347
+ ],
348
+ "args": [
349
+ {
350
+ "name": "listing_seed",
351
+ "type": {
352
+ "array": [
353
+ "u8",
354
+ 32
355
+ ]
356
+ }
357
+ },
358
+ {
359
+ "name": "token_symbol",
360
+ "type": "string"
361
+ }
362
+ ]
363
+ },
364
+ {
365
+ "name": "purchase_ticket",
366
+ "discriminator": [
367
+ 90,
368
+ 91,
369
+ 173,
370
+ 20,
371
+ 72,
372
+ 109,
373
+ 15,
374
+ 146
375
+ ],
376
+ "accounts": [
377
+ {
378
+ "name": "buyer",
379
+ "writable": true,
380
+ "signer": true
381
+ },
382
+ {
383
+ "name": "listing",
384
+ "writable": true
385
+ },
386
+ {
387
+ "name": "config",
388
+ "pda": {
389
+ "seeds": [
390
+ {
391
+ "kind": "const",
392
+ "value": [
393
+ 99,
394
+ 111,
395
+ 110,
396
+ 102,
397
+ 105,
398
+ 103
399
+ ]
400
+ }
401
+ ]
402
+ }
403
+ },
404
+ {
405
+ "name": "creator",
406
+ "writable": true,
407
+ "relations": [
408
+ "listing"
409
+ ]
410
+ },
411
+ {
412
+ "name": "revenue_wallet",
413
+ "writable": true
414
+ },
415
+ {
416
+ "name": "platform_treasury",
417
+ "writable": true
418
+ },
419
+ {
420
+ "name": "buyback_treasury",
421
+ "writable": true
422
+ },
423
+ {
424
+ "name": "ticket_receipt",
425
+ "writable": true,
426
+ "pda": {
427
+ "seeds": [
428
+ {
429
+ "kind": "const",
430
+ "value": [
431
+ 116,
432
+ 105,
433
+ 99,
434
+ 107,
435
+ 101,
436
+ 116
437
+ ]
438
+ },
439
+ {
440
+ "kind": "account",
441
+ "path": "listing"
442
+ },
443
+ {
444
+ "kind": "account",
445
+ "path": "buyer"
446
+ }
447
+ ]
448
+ }
449
+ },
450
+ {
451
+ "name": "system_program",
452
+ "address": "11111111111111111111111111111111"
453
+ }
454
+ ],
455
+ "args": []
456
+ },
457
+ {
458
+ "name": "redeem_ticket",
459
+ "discriminator": [
460
+ 129,
461
+ 120,
462
+ 104,
463
+ 224,
464
+ 155,
465
+ 25,
466
+ 22,
467
+ 192
468
+ ],
469
+ "accounts": [
470
+ {
471
+ "name": "buyer",
472
+ "writable": true,
473
+ "signer": true
474
+ },
475
+ {
476
+ "name": "listing"
477
+ },
478
+ {
479
+ "name": "ticket_receipt",
480
+ "writable": true,
481
+ "pda": {
482
+ "seeds": [
483
+ {
484
+ "kind": "const",
485
+ "value": [
486
+ 116,
487
+ 105,
488
+ 99,
489
+ 107,
490
+ 101,
491
+ 116
492
+ ]
493
+ },
494
+ {
495
+ "kind": "account",
496
+ "path": "listing"
497
+ },
498
+ {
499
+ "kind": "account",
500
+ "path": "buyer"
501
+ }
502
+ ]
503
+ }
504
+ }
505
+ ],
506
+ "args": []
507
+ },
508
+ {
509
+ "name": "set_buyback_bps",
510
+ "discriminator": [
511
+ 26,
512
+ 112,
513
+ 151,
514
+ 155,
515
+ 69,
516
+ 147,
517
+ 234,
518
+ 24
519
+ ],
520
+ "accounts": [
521
+ {
522
+ "name": "creator",
523
+ "writable": true,
524
+ "signer": true,
525
+ "relations": [
526
+ "listing"
527
+ ]
528
+ },
529
+ {
530
+ "name": "listing",
531
+ "writable": true
532
+ }
533
+ ],
534
+ "args": [
535
+ {
536
+ "name": "buyback_bps",
537
+ "type": "u16"
538
+ }
539
+ ]
540
+ },
541
+ {
542
+ "name": "trigger_ipo",
543
+ "discriminator": [
544
+ 130,
545
+ 168,
546
+ 9,
547
+ 179,
548
+ 203,
549
+ 226,
550
+ 186,
551
+ 114
552
+ ],
553
+ "accounts": [
554
+ {
555
+ "name": "creator",
556
+ "writable": true,
557
+ "signer": true,
558
+ "relations": [
559
+ "listing"
560
+ ]
561
+ },
562
+ {
563
+ "name": "listing",
564
+ "writable": true,
565
+ "pda": {
566
+ "seeds": [
567
+ {
568
+ "kind": "const",
569
+ "value": [
570
+ 108,
571
+ 105,
572
+ 115,
573
+ 116,
574
+ 105,
575
+ 110,
576
+ 103
577
+ ]
578
+ },
579
+ {
580
+ "kind": "account",
581
+ "path": "creator"
582
+ },
583
+ {
584
+ "kind": "arg",
585
+ "path": "listing_seed"
586
+ }
587
+ ]
588
+ }
589
+ },
590
+ {
591
+ "name": "vault",
592
+ "writable": true,
593
+ "pda": {
594
+ "seeds": [
595
+ {
596
+ "kind": "const",
597
+ "value": [
598
+ 118,
599
+ 97,
600
+ 117,
601
+ 108,
602
+ 116
603
+ ]
604
+ },
605
+ {
606
+ "kind": "account",
607
+ "path": "listing"
608
+ }
609
+ ]
610
+ }
611
+ },
612
+ {
613
+ "name": "system_program",
614
+ "address": "11111111111111111111111111111111"
615
+ }
616
+ ],
617
+ "args": [
618
+ {
619
+ "name": "listing_seed",
620
+ "type": {
621
+ "array": [
622
+ "u8",
623
+ 32
624
+ ]
625
+ }
626
+ },
627
+ {
628
+ "name": "buyback_bps",
629
+ "type": "u16"
630
+ }
631
+ ]
632
+ },
633
+ {
634
+ "name": "update_config",
635
+ "discriminator": [
636
+ 29,
637
+ 158,
638
+ 252,
639
+ 191,
640
+ 10,
641
+ 83,
642
+ 219,
643
+ 99
644
+ ],
645
+ "accounts": [
646
+ {
647
+ "name": "authority",
648
+ "writable": true,
649
+ "signer": true
650
+ },
651
+ {
652
+ "name": "config",
653
+ "writable": true,
654
+ "pda": {
655
+ "seeds": [
656
+ {
657
+ "kind": "const",
658
+ "value": [
659
+ 99,
660
+ 111,
661
+ 110,
662
+ 102,
663
+ 105,
664
+ 103
665
+ ]
666
+ }
667
+ ]
668
+ }
669
+ }
670
+ ],
671
+ "args": [
672
+ {
673
+ "name": "platform_treasury",
674
+ "type": "pubkey"
675
+ },
676
+ {
677
+ "name": "buyback_treasury",
678
+ "type": "pubkey"
679
+ }
680
+ ]
681
+ },
682
+ {
683
+ "name": "update_ticket_price",
684
+ "discriminator": [
685
+ 248,
686
+ 105,
687
+ 7,
688
+ 184,
689
+ 173,
690
+ 88,
691
+ 39,
692
+ 242
693
+ ],
694
+ "accounts": [
695
+ {
696
+ "name": "creator",
697
+ "writable": true,
698
+ "signer": true,
699
+ "relations": [
700
+ "listing"
701
+ ]
702
+ },
703
+ {
704
+ "name": "listing",
705
+ "writable": true
706
+ }
707
+ ],
708
+ "args": [
709
+ {
710
+ "name": "ticket_price",
711
+ "type": "u64"
712
+ }
713
+ ]
714
+ }
715
+ ],
716
+ "accounts": [
717
+ {
718
+ "name": "Listing",
719
+ "discriminator": [
720
+ 218,
721
+ 32,
722
+ 50,
723
+ 73,
724
+ 43,
725
+ 134,
726
+ 26,
727
+ 58
728
+ ]
729
+ },
730
+ {
731
+ "name": "ListingVault",
732
+ "discriminator": [
733
+ 23,
734
+ 14,
735
+ 106,
736
+ 31,
737
+ 168,
738
+ 17,
739
+ 92,
740
+ 121
741
+ ]
742
+ },
743
+ {
744
+ "name": "ProtocolConfig",
745
+ "discriminator": [
746
+ 207,
747
+ 91,
748
+ 250,
749
+ 28,
750
+ 152,
751
+ 179,
752
+ 215,
753
+ 209
754
+ ]
755
+ },
756
+ {
757
+ "name": "TicketReceipt",
758
+ "discriminator": [
759
+ 33,
760
+ 39,
761
+ 194,
762
+ 207,
763
+ 210,
764
+ 208,
765
+ 161,
766
+ 103
767
+ ]
768
+ }
769
+ ],
770
+ "events": [
771
+ {
772
+ "name": "TicketPriceUpdated",
773
+ "discriminator": [
774
+ 92,
775
+ 125,
776
+ 96,
777
+ 126,
778
+ 80,
779
+ 77,
780
+ 64,
781
+ 176
782
+ ]
783
+ },
784
+ {
785
+ "name": "TicketPurchased",
786
+ "discriminator": [
787
+ 108,
788
+ 59,
789
+ 246,
790
+ 95,
791
+ 84,
792
+ 145,
793
+ 13,
794
+ 71
795
+ ]
796
+ },
797
+ {
798
+ "name": "TicketRedeemed",
799
+ "discriminator": [
800
+ 251,
801
+ 171,
802
+ 7,
803
+ 57,
804
+ 152,
805
+ 25,
806
+ 168,
807
+ 38
808
+ ]
809
+ }
810
+ ],
811
+ "errors": [
812
+ {
813
+ "code": 6e3,
814
+ "name": "InvalidTicketPrice",
815
+ "msg": "Ticket price must be greater than zero."
816
+ },
817
+ {
818
+ "code": 6001,
819
+ "name": "InvalidListingStatus",
820
+ "msg": "Listing is not in the expected status."
821
+ },
822
+ {
823
+ "code": 6002,
824
+ "name": "IpoNotReady",
825
+ "msg": "IPO revenue threshold not met."
826
+ },
827
+ {
828
+ "code": 6003,
829
+ "name": "InvalidSymbol",
830
+ "msg": "Symbol length exceeds limit."
831
+ },
832
+ {
833
+ "code": 6004,
834
+ "name": "StringTooLong",
835
+ "msg": "String field exceeds max length."
836
+ },
837
+ {
838
+ "code": 6005,
839
+ "name": "MathOverflow",
840
+ "msg": "Math overflow."
841
+ },
842
+ {
843
+ "code": 6006,
844
+ "name": "MissingBump",
845
+ "msg": "Missing bump."
846
+ },
847
+ {
848
+ "code": 6007,
849
+ "name": "NoTicketsAvailable",
850
+ "msg": "No tickets available."
851
+ },
852
+ {
853
+ "code": 6008,
854
+ "name": "InvalidReceipt",
855
+ "msg": "Invalid ticket receipt."
856
+ },
857
+ {
858
+ "code": 6009,
859
+ "name": "Unauthorized",
860
+ "msg": "Unauthorized."
861
+ },
862
+ {
863
+ "code": 6010,
864
+ "name": "InvalidTreasury",
865
+ "msg": "Invalid treasury address."
866
+ },
867
+ {
868
+ "code": 6011,
869
+ "name": "InvalidBuybackBps",
870
+ "msg": "Invalid buyback percentage."
871
+ }
872
+ ],
873
+ "types": [
874
+ {
875
+ "name": "Listing",
876
+ "type": {
877
+ "kind": "struct",
878
+ "fields": [
879
+ {
880
+ "name": "listing_seed",
881
+ "type": {
882
+ "array": [
883
+ "u8",
884
+ 32
885
+ ]
886
+ }
887
+ },
888
+ {
889
+ "name": "creator",
890
+ "type": "pubkey"
891
+ },
892
+ {
893
+ "name": "revenue_wallet",
894
+ "type": "pubkey"
895
+ },
896
+ {
897
+ "name": "listing_type",
898
+ "type": {
899
+ "defined": {
900
+ "name": "ListingType"
901
+ }
902
+ }
903
+ },
904
+ {
905
+ "name": "status",
906
+ "type": {
907
+ "defined": {
908
+ "name": "ListingStatus"
909
+ }
910
+ }
911
+ },
912
+ {
913
+ "name": "name",
914
+ "type": "string"
915
+ },
916
+ {
917
+ "name": "tagline",
918
+ "type": "string"
919
+ },
920
+ {
921
+ "name": "description",
922
+ "type": "string"
923
+ },
924
+ {
925
+ "name": "category",
926
+ "type": "string"
927
+ },
928
+ {
929
+ "name": "image_url",
930
+ "type": "string"
931
+ },
932
+ {
933
+ "name": "product_url",
934
+ "type": "string"
935
+ },
936
+ {
937
+ "name": "endpoint_url",
938
+ "type": "string"
939
+ },
940
+ {
941
+ "name": "manifest_url",
942
+ "type": "string"
943
+ },
944
+ {
945
+ "name": "ticket_price",
946
+ "type": "u64"
947
+ },
948
+ {
949
+ "name": "target_revenue",
950
+ "type": "u64"
951
+ },
952
+ {
953
+ "name": "revenue",
954
+ "type": "u64"
955
+ },
956
+ {
957
+ "name": "tickets_sold",
958
+ "type": "u64"
959
+ },
960
+ {
961
+ "name": "token_mint",
962
+ "type": "pubkey"
963
+ },
964
+ {
965
+ "name": "token_symbol",
966
+ "type": "string"
967
+ },
968
+ {
969
+ "name": "buyback_bps",
970
+ "type": "u16"
971
+ },
972
+ {
973
+ "name": "buyback_total",
974
+ "type": "u64"
975
+ },
976
+ {
977
+ "name": "platform_buyback_total",
978
+ "type": "u64"
979
+ },
980
+ {
981
+ "name": "bump",
982
+ "type": "u8"
983
+ },
984
+ {
985
+ "name": "vault_bump",
986
+ "type": "u8"
987
+ },
988
+ {
989
+ "name": "created_at",
990
+ "type": "i64"
991
+ }
992
+ ]
993
+ }
994
+ },
995
+ {
996
+ "name": "ListingStatus",
997
+ "type": {
998
+ "kind": "enum",
999
+ "variants": [
1000
+ {
1001
+ "name": "Grind"
1002
+ },
1003
+ {
1004
+ "name": "Ipo"
1005
+ },
1006
+ {
1007
+ "name": "Web2"
1008
+ }
1009
+ ]
1010
+ }
1011
+ },
1012
+ {
1013
+ "name": "ListingType",
1014
+ "type": {
1015
+ "kind": "enum",
1016
+ "variants": [
1017
+ {
1018
+ "name": "Agent"
1019
+ },
1020
+ {
1021
+ "name": "Human"
1022
+ }
1023
+ ]
1024
+ }
1025
+ },
1026
+ {
1027
+ "name": "ListingVault",
1028
+ "type": {
1029
+ "kind": "struct",
1030
+ "fields": []
1031
+ }
1032
+ },
1033
+ {
1034
+ "name": "ProtocolConfig",
1035
+ "type": {
1036
+ "kind": "struct",
1037
+ "fields": [
1038
+ {
1039
+ "name": "authority",
1040
+ "type": "pubkey"
1041
+ },
1042
+ {
1043
+ "name": "platform_treasury",
1044
+ "type": "pubkey"
1045
+ },
1046
+ {
1047
+ "name": "buyback_treasury",
1048
+ "type": "pubkey"
1049
+ },
1050
+ {
1051
+ "name": "bump",
1052
+ "type": "u8"
1053
+ }
1054
+ ]
1055
+ }
1056
+ },
1057
+ {
1058
+ "name": "TicketPriceUpdated",
1059
+ "type": {
1060
+ "kind": "struct",
1061
+ "fields": [
1062
+ {
1063
+ "name": "listing",
1064
+ "type": "pubkey"
1065
+ },
1066
+ {
1067
+ "name": "old_price",
1068
+ "type": "u64"
1069
+ },
1070
+ {
1071
+ "name": "new_price",
1072
+ "type": "u64"
1073
+ },
1074
+ {
1075
+ "name": "timestamp",
1076
+ "type": "i64"
1077
+ }
1078
+ ]
1079
+ }
1080
+ },
1081
+ {
1082
+ "name": "TicketPurchased",
1083
+ "type": {
1084
+ "kind": "struct",
1085
+ "fields": [
1086
+ {
1087
+ "name": "listing",
1088
+ "type": "pubkey"
1089
+ },
1090
+ {
1091
+ "name": "buyer",
1092
+ "type": "pubkey"
1093
+ },
1094
+ {
1095
+ "name": "amount",
1096
+ "type": "u64"
1097
+ },
1098
+ {
1099
+ "name": "creator",
1100
+ "type": "pubkey"
1101
+ },
1102
+ {
1103
+ "name": "platform",
1104
+ "type": "pubkey"
1105
+ },
1106
+ {
1107
+ "name": "creator_amount",
1108
+ "type": "u64"
1109
+ },
1110
+ {
1111
+ "name": "platform_amount",
1112
+ "type": "u64"
1113
+ },
1114
+ {
1115
+ "name": "buyback_amount",
1116
+ "type": "u64"
1117
+ },
1118
+ {
1119
+ "name": "platform_buyback_amount",
1120
+ "type": "u64"
1121
+ },
1122
+ {
1123
+ "name": "status",
1124
+ "type": {
1125
+ "defined": {
1126
+ "name": "ListingStatus"
1127
+ }
1128
+ }
1129
+ },
1130
+ {
1131
+ "name": "remaining",
1132
+ "type": "u64"
1133
+ },
1134
+ {
1135
+ "name": "timestamp",
1136
+ "type": "i64"
1137
+ }
1138
+ ]
1139
+ }
1140
+ },
1141
+ {
1142
+ "name": "TicketReceipt",
1143
+ "type": {
1144
+ "kind": "struct",
1145
+ "fields": [
1146
+ {
1147
+ "name": "listing",
1148
+ "type": "pubkey"
1149
+ },
1150
+ {
1151
+ "name": "buyer",
1152
+ "type": "pubkey"
1153
+ },
1154
+ {
1155
+ "name": "count",
1156
+ "type": "u64"
1157
+ },
1158
+ {
1159
+ "name": "last_purchased_at",
1160
+ "type": "i64"
1161
+ },
1162
+ {
1163
+ "name": "last_redeemed_at",
1164
+ "type": "i64"
1165
+ }
1166
+ ]
1167
+ }
1168
+ },
1169
+ {
1170
+ "name": "TicketRedeemed",
1171
+ "type": {
1172
+ "kind": "struct",
1173
+ "fields": [
1174
+ {
1175
+ "name": "listing",
1176
+ "type": "pubkey"
1177
+ },
1178
+ {
1179
+ "name": "buyer",
1180
+ "type": "pubkey"
1181
+ },
1182
+ {
1183
+ "name": "remaining",
1184
+ "type": "u64"
1185
+ },
1186
+ {
1187
+ "name": "timestamp",
1188
+ "type": "i64"
1189
+ }
1190
+ ]
1191
+ }
1192
+ }
1193
+ ]
1194
+ };
1195
+
1196
+ // src/solana.ts
1197
+ var toPublicKey = (value) => value instanceof PublicKey ? value : new PublicKey(value);
1198
+ var toAnchorWallet = (wallet) => {
1199
+ if ("secretKey" in wallet) {
1200
+ const keypair = wallet;
1201
+ return {
1202
+ publicKey: keypair.publicKey,
1203
+ signTransaction: async (tx) => {
1204
+ if (tx && typeof tx === "object") {
1205
+ const maybeLegacy = tx;
1206
+ const maybeVersioned = tx;
1207
+ if (typeof maybeLegacy.partialSign === "function") {
1208
+ maybeLegacy.partialSign(keypair);
1209
+ } else if (typeof maybeVersioned.sign === "function") {
1210
+ maybeVersioned.sign([keypair]);
1211
+ }
1212
+ }
1213
+ return tx;
1214
+ },
1215
+ signAllTransactions: async (txs) => {
1216
+ txs.forEach((tx) => {
1217
+ if (tx && typeof tx === "object") {
1218
+ const maybeLegacy = tx;
1219
+ const maybeVersioned = tx;
1220
+ if (typeof maybeLegacy.partialSign === "function") {
1221
+ maybeLegacy.partialSign(keypair);
1222
+ } else if (typeof maybeVersioned.sign === "function") {
1223
+ maybeVersioned.sign([keypair]);
1224
+ }
1225
+ }
1226
+ });
1227
+ return txs;
1228
+ }
1229
+ };
1230
+ }
1231
+ const walletLike = wallet;
1232
+ if (typeof walletLike.signAllTransactions !== "function") {
1233
+ return {
1234
+ publicKey: walletLike.publicKey,
1235
+ signTransaction: walletLike.signTransaction,
1236
+ signAllTransactions: async (txs) => {
1237
+ const signed = [];
1238
+ for (const tx of txs) {
1239
+ signed.push(await walletLike.signTransaction(tx));
1240
+ }
1241
+ return signed;
1242
+ }
1243
+ };
1244
+ }
1245
+ return {
1246
+ publicKey: walletLike.publicKey,
1247
+ signTransaction: walletLike.signTransaction,
1248
+ signAllTransactions: walletLike.signAllTransactions
1249
+ };
1250
+ };
1251
+ var toLamports = (sol) => new BN(Math.round(sol * LAMPORTS_PER_SOL));
1252
+ var toSol = (lamports) => Number(lamports) / LAMPORTS_PER_SOL;
1253
+ var deriveListingPda = (creator, seed, programId) => PublicKey.findProgramAddressSync([
1254
+ Buffer.from("listing"),
1255
+ creator.toBuffer(),
1256
+ Buffer.from(seed)
1257
+ ], programId);
1258
+ var deriveTicketReceiptPda = (listing, buyer, programId) => PublicKey.findProgramAddressSync([
1259
+ Buffer.from("ticket"),
1260
+ listing.toBuffer(),
1261
+ buyer.toBuffer()
1262
+ ], programId);
1263
+ var deriveConfigPda = (programId) => PublicKey.findProgramAddressSync([Buffer.from("config")], programId);
1264
+ var fetchSolBalance = async (connection, wallet) => {
1265
+ const pubkey = toPublicKey(wallet);
1266
+ const lamports = await connection.getBalance(pubkey, "confirmed");
1267
+ return toSol(lamports);
1268
+ };
1269
+ var fetchTokenBalance = async (connection, wallet, mint) => {
1270
+ const owner = toPublicKey(wallet);
1271
+ const mintKey = toPublicKey(mint);
1272
+ const response = await connection.getTokenAccountsByOwner(owner, { mint: mintKey });
1273
+ const account = response.value[0];
1274
+ if (!account) return 0;
1275
+ const balance = await connection.getTokenAccountBalance(account.pubkey, "confirmed");
1276
+ return Number(balance.value.uiAmount || 0);
1277
+ };
1278
+ var fetchTokenBalances = async (connection, wallet, mints) => {
1279
+ const owner = toPublicKey(wallet);
1280
+ const results = {};
1281
+ await Promise.all(
1282
+ mints.map(async (mint) => {
1283
+ const mintKey = toPublicKey(mint);
1284
+ const response = await connection.getTokenAccountsByOwner(owner, { mint: mintKey });
1285
+ const account = response.value[0];
1286
+ if (!account) {
1287
+ results[mintKey.toBase58()] = 0;
1288
+ return;
1289
+ }
1290
+ const balance = await connection.getTokenAccountBalance(account.pubkey, "confirmed");
1291
+ results[mintKey.toBase58()] = Number(balance.value.uiAmount || 0);
1292
+ })
1293
+ );
1294
+ return results;
1295
+ };
1296
+ var VibePayments = class {
1297
+ connection;
1298
+ wallet;
1299
+ programId;
1300
+ commitment;
1301
+ constructor(options) {
1302
+ this.connection = options.connection;
1303
+ this.wallet = toAnchorWallet(options.wallet);
1304
+ this.programId = toPublicKey(options.programId);
1305
+ this.commitment = options.commitment || "confirmed";
1306
+ }
1307
+ getProgramId() {
1308
+ return this.programId.toBase58();
1309
+ }
1310
+ getProgram() {
1311
+ const provider = new AnchorProvider(this.connection, this.wallet, {
1312
+ preflightCommitment: this.commitment
1313
+ });
1314
+ return new Program(VIBEIAO_IDL, this.programId, provider);
1315
+ }
1316
+ async fetchProtocolConfig() {
1317
+ const program = this.getProgram();
1318
+ const [config] = deriveConfigPda(this.programId);
1319
+ const data = await program.account.protocolConfig.fetch(config);
1320
+ return {
1321
+ platformTreasury: data.platformTreasury.toBase58(),
1322
+ buybackTreasury: data.buybackTreasury.toBase58()
1323
+ };
1324
+ }
1325
+ getTicketReceiptAddress(listingAccount, buyer) {
1326
+ const listingPubkey = new PublicKey(listingAccount);
1327
+ const buyerKey = buyer ?? this.wallet.publicKey;
1328
+ const [receipt] = deriveTicketReceiptPda(listingPubkey, buyerKey, this.programId);
1329
+ return receipt.toBase58();
1330
+ }
1331
+ async purchaseTicket(input) {
1332
+ const program = this.getProgram();
1333
+ const listingPubkey = new PublicKey(input.listingAccount);
1334
+ const [ticketReceipt] = deriveTicketReceiptPda(listingPubkey, this.wallet.publicKey, this.programId);
1335
+ const [config] = deriveConfigPda(this.programId);
1336
+ let platformTreasury = input.platformTreasury;
1337
+ let buybackTreasury = input.buybackTreasury;
1338
+ if (!platformTreasury || !buybackTreasury) {
1339
+ const protocol = await this.fetchProtocolConfig();
1340
+ platformTreasury = platformTreasury || protocol.platformTreasury;
1341
+ buybackTreasury = buybackTreasury || protocol.buybackTreasury;
1342
+ }
1343
+ if (!platformTreasury || !buybackTreasury) {
1344
+ throw new Error("protocol_config_missing");
1345
+ }
1346
+ return program.methods.purchaseTicket().accounts({
1347
+ buyer: this.wallet.publicKey,
1348
+ listing: listingPubkey,
1349
+ config,
1350
+ creator: new PublicKey(input.creatorWallet),
1351
+ revenueWallet: new PublicKey(input.revenueWallet),
1352
+ platformTreasury: new PublicKey(platformTreasury),
1353
+ buybackTreasury: new PublicKey(buybackTreasury),
1354
+ ticketReceipt,
1355
+ systemProgram: SystemProgram.programId
1356
+ }).rpc();
1357
+ }
1358
+ async purchaseTicketForListing(input) {
1359
+ const listing = input.listing;
1360
+ const listingAccount = listing.chain_listing_account;
1361
+ const creatorWallet = listing.creator_wallet_address;
1362
+ const revenueWallet = listing.revenue_wallet_address || listing.creator_wallet_address;
1363
+ if (!listingAccount) {
1364
+ throw new Error("listing_missing_chain_account");
1365
+ }
1366
+ if (!creatorWallet) {
1367
+ throw new Error("listing_missing_creator_wallet");
1368
+ }
1369
+ if (!revenueWallet) {
1370
+ throw new Error("listing_missing_revenue_wallet");
1371
+ }
1372
+ return this.purchaseTicket({
1373
+ listingAccount,
1374
+ creatorWallet,
1375
+ revenueWallet,
1376
+ platformTreasury: input.platformTreasury,
1377
+ buybackTreasury: input.buybackTreasury
1378
+ });
1379
+ }
1380
+ async redeemTicket(listingAccount) {
1381
+ const program = this.getProgram();
1382
+ const listingPubkey = new PublicKey(listingAccount);
1383
+ const [ticketReceipt] = deriveTicketReceiptPda(listingPubkey, this.wallet.publicKey, this.programId);
1384
+ return program.methods.redeemTicket().accounts({
1385
+ buyer: this.wallet.publicKey,
1386
+ listing: listingPubkey,
1387
+ ticketReceipt
1388
+ }).rpc();
1389
+ }
1390
+ async updateTicketPrice(listingAccount, priceSol) {
1391
+ const program = this.getProgram();
1392
+ const listingPubkey = new PublicKey(listingAccount);
1393
+ const lamports = toLamports(priceSol);
1394
+ return program.methods.updateTicketPrice(lamports).accounts({
1395
+ creator: this.wallet.publicKey,
1396
+ listing: listingPubkey
1397
+ }).rpc();
1398
+ }
1399
+ };
1400
+
1401
+ export {
1402
+ VIBEIAO_IDL,
1403
+ toLamports,
1404
+ toSol,
1405
+ deriveListingPda,
1406
+ deriveTicketReceiptPda,
1407
+ deriveConfigPda,
1408
+ fetchSolBalance,
1409
+ fetchTokenBalance,
1410
+ fetchTokenBalances,
1411
+ VibePayments
1412
+ };