@hodlmarkets/sdk 0.1.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.
Files changed (68) hide show
  1. package/README.md +121 -0
  2. package/dist/accounts.cjs +1893 -0
  3. package/dist/accounts.cjs.map +1 -0
  4. package/dist/accounts.d.cts +9 -0
  5. package/dist/accounts.d.ts +9 -0
  6. package/dist/accounts.js +1885 -0
  7. package/dist/accounts.js.map +1 -0
  8. package/dist/client.cjs +2161 -0
  9. package/dist/client.cjs.map +1 -0
  10. package/dist/client.d.cts +44 -0
  11. package/dist/client.d.ts +44 -0
  12. package/dist/client.js +2155 -0
  13. package/dist/client.js.map +1 -0
  14. package/dist/constants.cjs +68 -0
  15. package/dist/constants.cjs.map +1 -0
  16. package/dist/constants.d.cts +62 -0
  17. package/dist/constants.d.ts +62 -0
  18. package/dist/constants.js +50 -0
  19. package/dist/constants.js.map +1 -0
  20. package/dist/errors.cjs +43 -0
  21. package/dist/errors.cjs.map +1 -0
  22. package/dist/errors.d.cts +8 -0
  23. package/dist/errors.d.ts +8 -0
  24. package/dist/errors.js +39 -0
  25. package/dist/errors.js.map +1 -0
  26. package/dist/events.cjs +1923 -0
  27. package/dist/events.cjs.map +1 -0
  28. package/dist/events.d.cts +20 -0
  29. package/dist/events.d.ts +20 -0
  30. package/dist/events.js +1913 -0
  31. package/dist/events.js.map +1 -0
  32. package/dist/index.cjs +2357 -0
  33. package/dist/index.cjs.map +1 -0
  34. package/dist/index.d.cts +12 -0
  35. package/dist/index.d.ts +12 -0
  36. package/dist/index.js +2302 -0
  37. package/dist/index.js.map +1 -0
  38. package/dist/instructions.cjs +2022 -0
  39. package/dist/instructions.cjs.map +1 -0
  40. package/dist/instructions.d.cts +38 -0
  41. package/dist/instructions.d.ts +38 -0
  42. package/dist/instructions.js +2012 -0
  43. package/dist/instructions.js.map +1 -0
  44. package/dist/math.cjs +98 -0
  45. package/dist/math.cjs.map +1 -0
  46. package/dist/math.d.cts +58 -0
  47. package/dist/math.d.ts +58 -0
  48. package/dist/math.js +85 -0
  49. package/dist/math.js.map +1 -0
  50. package/dist/pda.cjs +52 -0
  51. package/dist/pda.cjs.map +1 -0
  52. package/dist/pda.d.cts +10 -0
  53. package/dist/pda.d.ts +10 -0
  54. package/dist/pda.js +41 -0
  55. package/dist/pda.js.map +1 -0
  56. package/dist/transaction.cjs +37 -0
  57. package/dist/transaction.cjs.map +1 -0
  58. package/dist/transaction.d.cts +11 -0
  59. package/dist/transaction.d.ts +11 -0
  60. package/dist/transaction.js +34 -0
  61. package/dist/transaction.js.map +1 -0
  62. package/dist/types.cjs +4 -0
  63. package/dist/types.cjs.map +1 -0
  64. package/dist/types.d.cts +153 -0
  65. package/dist/types.d.ts +153 -0
  66. package/dist/types.js +3 -0
  67. package/dist/types.js.map +1 -0
  68. package/package.json +96 -0
@@ -0,0 +1,2161 @@
1
+ 'use strict';
2
+
3
+ var web3_js = require('@solana/web3.js');
4
+ var BN = require('bn.js');
5
+ var anchor = require('@coral-xyz/anchor');
6
+ var splToken = require('@solana/spl-token');
7
+
8
+ function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
9
+
10
+ var BN__default = /*#__PURE__*/_interopDefault(BN);
11
+
12
+ // src/constants.ts
13
+ var PROGRAM_ID = new web3_js.PublicKey("hodLrUfwyK3Z7Td5hdZhyojyznG1rqbHVex11y5s4yG");
14
+ var PROTOCOL_AUTHORITY = new web3_js.PublicKey("EFAquDGAHjkoPB6TGKVibD3BYhbFXNDjuXKpiBHdYzji");
15
+ var VIRTUAL_SOL = new BN__default.default("30000000000");
16
+ var TOTAL_SUPPLY = new BN__default.default("1000000000000000");
17
+ var PROTOCOL_MINT_FEE = new BN__default.default("100000000");
18
+ var DECIMALS = 6;
19
+ var SEEDS = {
20
+ POOL: Buffer.from("pool"),
21
+ VAULT_AUTHORITY: Buffer.from("vault_authority"),
22
+ SOL_VAULT: Buffer.from("sol_vault"),
23
+ POSITION: Buffer.from("position"),
24
+ PROTOCOL_FEES: Buffer.from("protocol_fees"),
25
+ EVENT_AUTHORITY: Buffer.from("__event_authority")
26
+ };
27
+ var MAINNET_CONFIG = {
28
+ programId: PROGRAM_ID,
29
+ virtualSol: VIRTUAL_SOL,
30
+ protocolAuthority: PROTOCOL_AUTHORITY,
31
+ protocolMintFee: PROTOCOL_MINT_FEE,
32
+ decimals: DECIMALS,
33
+ totalSupply: TOTAL_SUPPLY
34
+ };
35
+ function getPoolStatePDA(mint, programId) {
36
+ return web3_js.PublicKey.findProgramAddressSync([SEEDS.POOL, mint.toBuffer()], programId);
37
+ }
38
+ function getVaultAuthorityPDA(poolState, programId) {
39
+ return web3_js.PublicKey.findProgramAddressSync([SEEDS.VAULT_AUTHORITY, poolState.toBuffer()], programId);
40
+ }
41
+ function getSolVaultPDA(poolState, programId) {
42
+ return web3_js.PublicKey.findProgramAddressSync([SEEDS.SOL_VAULT, poolState.toBuffer()], programId);
43
+ }
44
+ function getPositionPDA(poolState, owner, programId) {
45
+ return web3_js.PublicKey.findProgramAddressSync([SEEDS.POSITION, poolState.toBuffer(), owner.toBuffer()], programId);
46
+ }
47
+ function getProtocolFeesPDA(programId) {
48
+ return web3_js.PublicKey.findProgramAddressSync([SEEDS.PROTOCOL_FEES], programId);
49
+ }
50
+ function getEventAuthorityPDA(programId) {
51
+ return web3_js.PublicKey.findProgramAddressSync([SEEDS.EVENT_AUTHORITY], programId);
52
+ }
53
+
54
+ // src/idl/hodl.json
55
+ var hodl_default = {
56
+ address: "hodLrUfwyK3Z7Td5hdZhyojyznG1rqbHVex11y5s4yG",
57
+ metadata: {
58
+ name: "hodl",
59
+ version: "0.1.0",
60
+ spec: "0.1.0"
61
+ },
62
+ instructions: [
63
+ {
64
+ name: "buy",
65
+ docs: [
66
+ "Buy tokens from the vAMM",
67
+ "",
68
+ "Tokens are split into tradable (immediate) and vaulted (accrue linearly).",
69
+ "Allocation is based on token-amount range bands: 40/60 at 0-50M, +5% per 50M band, 100/0 at 600M+.",
70
+ "After vest_duration passes, all buys are 100% tradable."
71
+ ],
72
+ discriminator: [
73
+ 102,
74
+ 6,
75
+ 61,
76
+ 18,
77
+ 1,
78
+ 218,
79
+ 235,
80
+ 234
81
+ ],
82
+ accounts: [
83
+ {
84
+ name: "buyer",
85
+ writable: true,
86
+ signer: true
87
+ },
88
+ {
89
+ name: "pool_state",
90
+ writable: true,
91
+ pda: {
92
+ seeds: [
93
+ {
94
+ kind: "const",
95
+ value: [
96
+ 112,
97
+ 111,
98
+ 111,
99
+ 108
100
+ ]
101
+ },
102
+ {
103
+ kind: "account",
104
+ path: "mint"
105
+ }
106
+ ]
107
+ }
108
+ },
109
+ {
110
+ name: "token_vault",
111
+ writable: true
112
+ },
113
+ {
114
+ name: "vault_authority",
115
+ pda: {
116
+ seeds: [
117
+ {
118
+ kind: "const",
119
+ value: [
120
+ 118,
121
+ 97,
122
+ 117,
123
+ 108,
124
+ 116,
125
+ 95,
126
+ 97,
127
+ 117,
128
+ 116,
129
+ 104,
130
+ 111,
131
+ 114,
132
+ 105,
133
+ 116,
134
+ 121
135
+ ]
136
+ },
137
+ {
138
+ kind: "account",
139
+ path: "pool_state"
140
+ }
141
+ ]
142
+ }
143
+ },
144
+ {
145
+ name: "buyer_token_account",
146
+ writable: true,
147
+ pda: {
148
+ seeds: [
149
+ {
150
+ kind: "account",
151
+ path: "buyer"
152
+ },
153
+ {
154
+ kind: "const",
155
+ value: [
156
+ 6,
157
+ 221,
158
+ 246,
159
+ 225,
160
+ 215,
161
+ 101,
162
+ 161,
163
+ 147,
164
+ 217,
165
+ 203,
166
+ 225,
167
+ 70,
168
+ 206,
169
+ 235,
170
+ 121,
171
+ 172,
172
+ 28,
173
+ 180,
174
+ 133,
175
+ 237,
176
+ 95,
177
+ 91,
178
+ 55,
179
+ 145,
180
+ 58,
181
+ 140,
182
+ 245,
183
+ 133,
184
+ 126,
185
+ 255,
186
+ 0,
187
+ 169
188
+ ]
189
+ },
190
+ {
191
+ kind: "account",
192
+ path: "mint"
193
+ }
194
+ ],
195
+ program: {
196
+ kind: "const",
197
+ value: [
198
+ 140,
199
+ 151,
200
+ 37,
201
+ 143,
202
+ 78,
203
+ 36,
204
+ 137,
205
+ 241,
206
+ 187,
207
+ 61,
208
+ 16,
209
+ 41,
210
+ 20,
211
+ 142,
212
+ 13,
213
+ 131,
214
+ 11,
215
+ 90,
216
+ 19,
217
+ 153,
218
+ 218,
219
+ 255,
220
+ 16,
221
+ 132,
222
+ 4,
223
+ 142,
224
+ 123,
225
+ 216,
226
+ 219,
227
+ 233,
228
+ 248,
229
+ 89
230
+ ]
231
+ }
232
+ }
233
+ },
234
+ {
235
+ name: "pool_sol_account",
236
+ writable: true,
237
+ pda: {
238
+ seeds: [
239
+ {
240
+ kind: "const",
241
+ value: [
242
+ 115,
243
+ 111,
244
+ 108,
245
+ 95,
246
+ 118,
247
+ 97,
248
+ 117,
249
+ 108,
250
+ 116
251
+ ]
252
+ },
253
+ {
254
+ kind: "account",
255
+ path: "pool_state"
256
+ }
257
+ ]
258
+ }
259
+ },
260
+ {
261
+ name: "mint"
262
+ },
263
+ {
264
+ name: "token_program",
265
+ address: "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA"
266
+ },
267
+ {
268
+ name: "associated_token_program",
269
+ address: "ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL"
270
+ },
271
+ {
272
+ name: "system_program",
273
+ address: "11111111111111111111111111111111"
274
+ },
275
+ {
276
+ name: "position",
277
+ writable: true,
278
+ pda: {
279
+ seeds: [
280
+ {
281
+ kind: "const",
282
+ value: [
283
+ 112,
284
+ 111,
285
+ 115,
286
+ 105,
287
+ 116,
288
+ 105,
289
+ 111,
290
+ 110
291
+ ]
292
+ },
293
+ {
294
+ kind: "account",
295
+ path: "pool_state"
296
+ },
297
+ {
298
+ kind: "account",
299
+ path: "buyer"
300
+ }
301
+ ]
302
+ }
303
+ },
304
+ {
305
+ name: "event_authority",
306
+ pda: {
307
+ seeds: [
308
+ {
309
+ kind: "const",
310
+ value: [
311
+ 95,
312
+ 95,
313
+ 101,
314
+ 118,
315
+ 101,
316
+ 110,
317
+ 116,
318
+ 95,
319
+ 97,
320
+ 117,
321
+ 116,
322
+ 104,
323
+ 111,
324
+ 114,
325
+ 105,
326
+ 116,
327
+ 121
328
+ ]
329
+ }
330
+ ]
331
+ }
332
+ },
333
+ {
334
+ name: "program"
335
+ }
336
+ ],
337
+ args: [
338
+ {
339
+ name: "sol_amount",
340
+ type: "u64"
341
+ },
342
+ {
343
+ name: "min_tokens_out",
344
+ type: "u64"
345
+ }
346
+ ]
347
+ },
348
+ {
349
+ name: "claim_accrued",
350
+ docs: [
351
+ "Claim accrued tokens",
352
+ "Transfers tokens that have accrued from vaulted to tradable from vault to wallet"
353
+ ],
354
+ discriminator: [
355
+ 209,
356
+ 92,
357
+ 30,
358
+ 216,
359
+ 89,
360
+ 249,
361
+ 122,
362
+ 243
363
+ ],
364
+ accounts: [
365
+ {
366
+ name: "owner",
367
+ signer: true
368
+ },
369
+ {
370
+ name: "pool_state",
371
+ writable: true,
372
+ pda: {
373
+ seeds: [
374
+ {
375
+ kind: "const",
376
+ value: [
377
+ 112,
378
+ 111,
379
+ 111,
380
+ 108
381
+ ]
382
+ },
383
+ {
384
+ kind: "account",
385
+ path: "pool_state.mint",
386
+ account: "PoolState"
387
+ }
388
+ ]
389
+ }
390
+ },
391
+ {
392
+ name: "position",
393
+ writable: true,
394
+ pda: {
395
+ seeds: [
396
+ {
397
+ kind: "const",
398
+ value: [
399
+ 112,
400
+ 111,
401
+ 115,
402
+ 105,
403
+ 116,
404
+ 105,
405
+ 111,
406
+ 110
407
+ ]
408
+ },
409
+ {
410
+ kind: "account",
411
+ path: "pool_state"
412
+ },
413
+ {
414
+ kind: "account",
415
+ path: "owner"
416
+ }
417
+ ]
418
+ }
419
+ },
420
+ {
421
+ name: "token_vault",
422
+ writable: true
423
+ },
424
+ {
425
+ name: "vault_authority",
426
+ pda: {
427
+ seeds: [
428
+ {
429
+ kind: "const",
430
+ value: [
431
+ 118,
432
+ 97,
433
+ 117,
434
+ 108,
435
+ 116,
436
+ 95,
437
+ 97,
438
+ 117,
439
+ 116,
440
+ 104,
441
+ 111,
442
+ 114,
443
+ 105,
444
+ 116,
445
+ 121
446
+ ]
447
+ },
448
+ {
449
+ kind: "account",
450
+ path: "pool_state"
451
+ }
452
+ ]
453
+ }
454
+ },
455
+ {
456
+ name: "user_token_account",
457
+ writable: true
458
+ },
459
+ {
460
+ name: "token_program",
461
+ address: "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA"
462
+ },
463
+ {
464
+ name: "event_authority",
465
+ pda: {
466
+ seeds: [
467
+ {
468
+ kind: "const",
469
+ value: [
470
+ 95,
471
+ 95,
472
+ 101,
473
+ 118,
474
+ 101,
475
+ 110,
476
+ 116,
477
+ 95,
478
+ 97,
479
+ 117,
480
+ 116,
481
+ 104,
482
+ 111,
483
+ 114,
484
+ 105,
485
+ 116,
486
+ 121
487
+ ]
488
+ }
489
+ ]
490
+ }
491
+ },
492
+ {
493
+ name: "program"
494
+ }
495
+ ],
496
+ args: []
497
+ },
498
+ {
499
+ name: "close_position",
500
+ docs: [
501
+ "Close an empty position account and reclaim rent"
502
+ ],
503
+ discriminator: [
504
+ 123,
505
+ 134,
506
+ 81,
507
+ 0,
508
+ 49,
509
+ 68,
510
+ 98,
511
+ 98
512
+ ],
513
+ accounts: [
514
+ {
515
+ name: "owner",
516
+ writable: true,
517
+ signer: true
518
+ },
519
+ {
520
+ name: "pool_state",
521
+ writable: true
522
+ },
523
+ {
524
+ name: "position",
525
+ writable: true,
526
+ pda: {
527
+ seeds: [
528
+ {
529
+ kind: "const",
530
+ value: [
531
+ 112,
532
+ 111,
533
+ 115,
534
+ 105,
535
+ 116,
536
+ 105,
537
+ 111,
538
+ 110
539
+ ]
540
+ },
541
+ {
542
+ kind: "account",
543
+ path: "pool_state"
544
+ },
545
+ {
546
+ kind: "account",
547
+ path: "owner"
548
+ }
549
+ ]
550
+ }
551
+ },
552
+ {
553
+ name: "user_token_account",
554
+ writable: true
555
+ },
556
+ {
557
+ name: "mint"
558
+ },
559
+ {
560
+ name: "token_program",
561
+ address: "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA"
562
+ },
563
+ {
564
+ name: "system_program",
565
+ address: "11111111111111111111111111111111"
566
+ },
567
+ {
568
+ name: "event_authority",
569
+ pda: {
570
+ seeds: [
571
+ {
572
+ kind: "const",
573
+ value: [
574
+ 95,
575
+ 95,
576
+ 101,
577
+ 118,
578
+ 101,
579
+ 110,
580
+ 116,
581
+ 95,
582
+ 97,
583
+ 117,
584
+ 116,
585
+ 104,
586
+ 111,
587
+ 114,
588
+ 105,
589
+ 116,
590
+ 121
591
+ ]
592
+ }
593
+ ]
594
+ }
595
+ },
596
+ {
597
+ name: "program"
598
+ }
599
+ ],
600
+ args: []
601
+ },
602
+ {
603
+ name: "create_token",
604
+ docs: [
605
+ "Create a new token and initialize vAMM pool"
606
+ ],
607
+ discriminator: [
608
+ 84,
609
+ 52,
610
+ 204,
611
+ 228,
612
+ 24,
613
+ 140,
614
+ 234,
615
+ 75
616
+ ],
617
+ accounts: [
618
+ {
619
+ name: "creator",
620
+ writable: true,
621
+ signer: true
622
+ },
623
+ {
624
+ name: "protocol_authority"
625
+ },
626
+ {
627
+ name: "mint",
628
+ writable: true,
629
+ signer: true
630
+ },
631
+ {
632
+ name: "pool_state",
633
+ writable: true,
634
+ pda: {
635
+ seeds: [
636
+ {
637
+ kind: "const",
638
+ value: [
639
+ 112,
640
+ 111,
641
+ 111,
642
+ 108
643
+ ]
644
+ },
645
+ {
646
+ kind: "account",
647
+ path: "mint"
648
+ }
649
+ ]
650
+ }
651
+ },
652
+ {
653
+ name: "token_vault",
654
+ writable: true
655
+ },
656
+ {
657
+ name: "vault_authority",
658
+ pda: {
659
+ seeds: [
660
+ {
661
+ kind: "const",
662
+ value: [
663
+ 118,
664
+ 97,
665
+ 117,
666
+ 108,
667
+ 116,
668
+ 95,
669
+ 97,
670
+ 117,
671
+ 116,
672
+ 104,
673
+ 111,
674
+ 114,
675
+ 105,
676
+ 116,
677
+ 121
678
+ ]
679
+ },
680
+ {
681
+ kind: "account",
682
+ path: "pool_state"
683
+ }
684
+ ]
685
+ }
686
+ },
687
+ {
688
+ name: "metadata",
689
+ writable: true
690
+ },
691
+ {
692
+ name: "pool_sol_account",
693
+ writable: true
694
+ },
695
+ {
696
+ name: "protocol_fee_wallet",
697
+ writable: true,
698
+ pda: {
699
+ seeds: [
700
+ {
701
+ kind: "const",
702
+ value: [
703
+ 112,
704
+ 114,
705
+ 111,
706
+ 116,
707
+ 111,
708
+ 99,
709
+ 111,
710
+ 108,
711
+ 95,
712
+ 102,
713
+ 101,
714
+ 101,
715
+ 115
716
+ ]
717
+ }
718
+ ]
719
+ }
720
+ },
721
+ {
722
+ name: "token_program",
723
+ address: "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA"
724
+ },
725
+ {
726
+ name: "associated_token_program",
727
+ address: "ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL"
728
+ },
729
+ {
730
+ name: "system_program",
731
+ address: "11111111111111111111111111111111"
732
+ },
733
+ {
734
+ name: "rent",
735
+ address: "SysvarRent111111111111111111111111111111111"
736
+ },
737
+ {
738
+ name: "metadata_program"
739
+ },
740
+ {
741
+ name: "sysvar_instructions"
742
+ },
743
+ {
744
+ name: "event_authority",
745
+ pda: {
746
+ seeds: [
747
+ {
748
+ kind: "const",
749
+ value: [
750
+ 95,
751
+ 95,
752
+ 101,
753
+ 118,
754
+ 101,
755
+ 110,
756
+ 116,
757
+ 95,
758
+ 97,
759
+ 117,
760
+ 116,
761
+ 104,
762
+ 111,
763
+ 114,
764
+ 105,
765
+ 116,
766
+ 121
767
+ ]
768
+ }
769
+ ]
770
+ }
771
+ },
772
+ {
773
+ name: "program"
774
+ }
775
+ ],
776
+ args: [
777
+ {
778
+ name: "name",
779
+ type: "string"
780
+ },
781
+ {
782
+ name: "symbol",
783
+ type: "string"
784
+ },
785
+ {
786
+ name: "uri",
787
+ type: "string"
788
+ },
789
+ {
790
+ name: "pool_description",
791
+ type: "string"
792
+ },
793
+ {
794
+ name: "vest_duration",
795
+ type: "i64"
796
+ }
797
+ ]
798
+ },
799
+ {
800
+ name: "emergency_withdraw_sol",
801
+ docs: [
802
+ "Emergency withdraw SOL from a pool's sol_vault"
803
+ ],
804
+ discriminator: [
805
+ 219,
806
+ 156,
807
+ 123,
808
+ 176,
809
+ 91,
810
+ 105,
811
+ 30,
812
+ 160
813
+ ],
814
+ accounts: [
815
+ {
816
+ name: "authority",
817
+ writable: true,
818
+ signer: true
819
+ },
820
+ {
821
+ name: "pool_state"
822
+ },
823
+ {
824
+ name: "sol_vault",
825
+ writable: true,
826
+ pda: {
827
+ seeds: [
828
+ {
829
+ kind: "const",
830
+ value: [
831
+ 115,
832
+ 111,
833
+ 108,
834
+ 95,
835
+ 118,
836
+ 97,
837
+ 117,
838
+ 108,
839
+ 116
840
+ ]
841
+ },
842
+ {
843
+ kind: "account",
844
+ path: "pool_state"
845
+ }
846
+ ]
847
+ }
848
+ },
849
+ {
850
+ name: "system_program",
851
+ address: "11111111111111111111111111111111"
852
+ }
853
+ ],
854
+ args: [
855
+ {
856
+ name: "amount",
857
+ type: "u64"
858
+ }
859
+ ]
860
+ },
861
+ {
862
+ name: "sell",
863
+ docs: [
864
+ "Sell tokens back to the vAMM",
865
+ "If sell_percentage is provided, it overrides token_amount"
866
+ ],
867
+ discriminator: [
868
+ 51,
869
+ 230,
870
+ 133,
871
+ 164,
872
+ 1,
873
+ 127,
874
+ 131,
875
+ 173
876
+ ],
877
+ accounts: [
878
+ {
879
+ name: "seller",
880
+ writable: true,
881
+ signer: true
882
+ },
883
+ {
884
+ name: "pool_state",
885
+ writable: true,
886
+ pda: {
887
+ seeds: [
888
+ {
889
+ kind: "const",
890
+ value: [
891
+ 112,
892
+ 111,
893
+ 111,
894
+ 108
895
+ ]
896
+ },
897
+ {
898
+ kind: "account",
899
+ path: "mint"
900
+ }
901
+ ]
902
+ }
903
+ },
904
+ {
905
+ name: "position",
906
+ writable: true,
907
+ pda: {
908
+ seeds: [
909
+ {
910
+ kind: "const",
911
+ value: [
912
+ 112,
913
+ 111,
914
+ 115,
915
+ 105,
916
+ 116,
917
+ 105,
918
+ 111,
919
+ 110
920
+ ]
921
+ },
922
+ {
923
+ kind: "account",
924
+ path: "pool_state"
925
+ },
926
+ {
927
+ kind: "account",
928
+ path: "seller"
929
+ }
930
+ ]
931
+ }
932
+ },
933
+ {
934
+ name: "token_vault",
935
+ writable: true
936
+ },
937
+ {
938
+ name: "vault_authority",
939
+ pda: {
940
+ seeds: [
941
+ {
942
+ kind: "const",
943
+ value: [
944
+ 118,
945
+ 97,
946
+ 117,
947
+ 108,
948
+ 116,
949
+ 95,
950
+ 97,
951
+ 117,
952
+ 116,
953
+ 104,
954
+ 111,
955
+ 114,
956
+ 105,
957
+ 116,
958
+ 121
959
+ ]
960
+ },
961
+ {
962
+ kind: "account",
963
+ path: "pool_state"
964
+ }
965
+ ]
966
+ }
967
+ },
968
+ {
969
+ name: "seller_token_account",
970
+ writable: true
971
+ },
972
+ {
973
+ name: "pool_sol_account",
974
+ writable: true,
975
+ pda: {
976
+ seeds: [
977
+ {
978
+ kind: "const",
979
+ value: [
980
+ 115,
981
+ 111,
982
+ 108,
983
+ 95,
984
+ 118,
985
+ 97,
986
+ 117,
987
+ 108,
988
+ 116
989
+ ]
990
+ },
991
+ {
992
+ kind: "account",
993
+ path: "pool_state"
994
+ }
995
+ ]
996
+ }
997
+ },
998
+ {
999
+ name: "mint"
1000
+ },
1001
+ {
1002
+ name: "token_program",
1003
+ address: "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA"
1004
+ },
1005
+ {
1006
+ name: "system_program",
1007
+ address: "11111111111111111111111111111111"
1008
+ },
1009
+ {
1010
+ name: "event_authority",
1011
+ pda: {
1012
+ seeds: [
1013
+ {
1014
+ kind: "const",
1015
+ value: [
1016
+ 95,
1017
+ 95,
1018
+ 101,
1019
+ 118,
1020
+ 101,
1021
+ 110,
1022
+ 116,
1023
+ 95,
1024
+ 97,
1025
+ 117,
1026
+ 116,
1027
+ 104,
1028
+ 111,
1029
+ 114,
1030
+ 105,
1031
+ 116,
1032
+ 121
1033
+ ]
1034
+ }
1035
+ ]
1036
+ }
1037
+ },
1038
+ {
1039
+ name: "program"
1040
+ }
1041
+ ],
1042
+ args: [
1043
+ {
1044
+ name: "token_amount",
1045
+ type: "u64"
1046
+ },
1047
+ {
1048
+ name: "min_sol_out",
1049
+ type: "u64"
1050
+ },
1051
+ {
1052
+ name: "sell_percentage",
1053
+ type: {
1054
+ option: "u8"
1055
+ }
1056
+ }
1057
+ ]
1058
+ },
1059
+ {
1060
+ name: "withdraw_protocol_fees",
1061
+ docs: [
1062
+ "Withdraw accumulated protocol fees"
1063
+ ],
1064
+ discriminator: [
1065
+ 11,
1066
+ 68,
1067
+ 165,
1068
+ 98,
1069
+ 18,
1070
+ 208,
1071
+ 134,
1072
+ 73
1073
+ ],
1074
+ accounts: [
1075
+ {
1076
+ name: "authority",
1077
+ writable: true,
1078
+ signer: true
1079
+ },
1080
+ {
1081
+ name: "protocol_fee_wallet",
1082
+ writable: true,
1083
+ pda: {
1084
+ seeds: [
1085
+ {
1086
+ kind: "const",
1087
+ value: [
1088
+ 112,
1089
+ 114,
1090
+ 111,
1091
+ 116,
1092
+ 111,
1093
+ 99,
1094
+ 111,
1095
+ 108,
1096
+ 95,
1097
+ 102,
1098
+ 101,
1099
+ 101,
1100
+ 115
1101
+ ]
1102
+ }
1103
+ ]
1104
+ }
1105
+ },
1106
+ {
1107
+ name: "system_program",
1108
+ address: "11111111111111111111111111111111"
1109
+ }
1110
+ ],
1111
+ args: [
1112
+ {
1113
+ name: "amount",
1114
+ type: "u64"
1115
+ }
1116
+ ]
1117
+ }
1118
+ ],
1119
+ accounts: [
1120
+ {
1121
+ name: "PoolState",
1122
+ discriminator: [
1123
+ 247,
1124
+ 237,
1125
+ 227,
1126
+ 245,
1127
+ 215,
1128
+ 195,
1129
+ 222,
1130
+ 70
1131
+ ]
1132
+ },
1133
+ {
1134
+ name: "Position",
1135
+ discriminator: [
1136
+ 170,
1137
+ 188,
1138
+ 143,
1139
+ 228,
1140
+ 122,
1141
+ 64,
1142
+ 247,
1143
+ 208
1144
+ ]
1145
+ }
1146
+ ],
1147
+ events: [
1148
+ {
1149
+ name: "AccrualClaimed",
1150
+ discriminator: [
1151
+ 86,
1152
+ 99,
1153
+ 51,
1154
+ 211,
1155
+ 226,
1156
+ 48,
1157
+ 235,
1158
+ 238
1159
+ ]
1160
+ },
1161
+ {
1162
+ name: "PositionClosed",
1163
+ discriminator: [
1164
+ 157,
1165
+ 163,
1166
+ 227,
1167
+ 228,
1168
+ 13,
1169
+ 97,
1170
+ 138,
1171
+ 121
1172
+ ]
1173
+ },
1174
+ {
1175
+ name: "TokenCreated",
1176
+ discriminator: [
1177
+ 236,
1178
+ 19,
1179
+ 41,
1180
+ 255,
1181
+ 130,
1182
+ 78,
1183
+ 147,
1184
+ 172
1185
+ ]
1186
+ },
1187
+ {
1188
+ name: "TokenPurchased",
1189
+ discriminator: [
1190
+ 3,
1191
+ 73,
1192
+ 186,
1193
+ 50,
1194
+ 15,
1195
+ 181,
1196
+ 213,
1197
+ 37
1198
+ ]
1199
+ },
1200
+ {
1201
+ name: "TokenSold",
1202
+ discriminator: [
1203
+ 88,
1204
+ 61,
1205
+ 1,
1206
+ 247,
1207
+ 185,
1208
+ 6,
1209
+ 252,
1210
+ 86
1211
+ ]
1212
+ }
1213
+ ],
1214
+ errors: [
1215
+ {
1216
+ code: 7005,
1217
+ name: "InsufficientTokens",
1218
+ msg: "Insufficient token reserves in vault"
1219
+ },
1220
+ {
1221
+ code: 7100,
1222
+ name: "ArithmeticOverflow",
1223
+ msg: "Arithmetic overflow"
1224
+ },
1225
+ {
1226
+ code: 7102,
1227
+ name: "DivisionError",
1228
+ msg: "Division by zero or invalid division"
1229
+ },
1230
+ {
1231
+ code: 7104,
1232
+ name: "TokenOverflow",
1233
+ msg: "Token calculation overflow"
1234
+ },
1235
+ {
1236
+ code: 7105,
1237
+ name: "TokenUnderflow",
1238
+ msg: "Token calculation underflow"
1239
+ },
1240
+ {
1241
+ code: 7200,
1242
+ name: "SlippageExceeded",
1243
+ msg: "Slippage exceeded: output below minimum threshold"
1244
+ },
1245
+ {
1246
+ code: 7312,
1247
+ name: "AccrualCalculationOverflow",
1248
+ msg: "Accrual calculation overflow"
1249
+ },
1250
+ {
1251
+ code: 7315,
1252
+ name: "PositionNotEmpty",
1253
+ msg: "Position is not empty, must sell all tokens first"
1254
+ },
1255
+ {
1256
+ code: 7319,
1257
+ name: "InvalidProtocolAuthority",
1258
+ msg: "Invalid protocol authority - must match PROTOCOL_AUTHORITY constant"
1259
+ },
1260
+ {
1261
+ code: 7321,
1262
+ name: "MustHaveUnlockedPortion",
1263
+ msg: "Position must have tokens to perform this operation"
1264
+ },
1265
+ {
1266
+ code: 7500,
1267
+ name: "PositionNotOwnedBySigner",
1268
+ msg: "Position not owned by signer"
1269
+ },
1270
+ {
1271
+ code: 7505,
1272
+ name: "InvalidSolVaultPDA",
1273
+ msg: "SOL vault PDA derivation mismatch"
1274
+ },
1275
+ {
1276
+ code: 7601,
1277
+ name: "InvalidVestingType",
1278
+ msg: "Invalid vesting type"
1279
+ },
1280
+ {
1281
+ code: 7604,
1282
+ name: "InvalidPercentage",
1283
+ msg: "Invalid percentage value (must be 0-100)"
1284
+ },
1285
+ {
1286
+ code: 7901,
1287
+ name: "NotAuthorized",
1288
+ msg: "Not authorized"
1289
+ },
1290
+ {
1291
+ code: 8014,
1292
+ name: "InsufficientLiquidity",
1293
+ msg: "Insufficient liquidity"
1294
+ },
1295
+ {
1296
+ code: 8018,
1297
+ name: "VammNotActive",
1298
+ msg: "vAMM is not active"
1299
+ },
1300
+ {
1301
+ code: 8020,
1302
+ name: "InvalidAmount",
1303
+ msg: "Invalid amount"
1304
+ }
1305
+ ],
1306
+ types: [
1307
+ {
1308
+ name: "AccrualClaimed",
1309
+ docs: [
1310
+ "Event emitted when accrued tokens are claimed"
1311
+ ],
1312
+ type: {
1313
+ kind: "struct",
1314
+ fields: [
1315
+ {
1316
+ name: "owner",
1317
+ type: "pubkey"
1318
+ },
1319
+ {
1320
+ name: "pool",
1321
+ type: "pubkey"
1322
+ },
1323
+ {
1324
+ name: "position",
1325
+ type: "pubkey"
1326
+ },
1327
+ {
1328
+ name: "tokens_claimed",
1329
+ type: "u64"
1330
+ },
1331
+ {
1332
+ name: "new_tradable_tokens",
1333
+ type: "u64"
1334
+ },
1335
+ {
1336
+ name: "remaining_vaulted_tokens",
1337
+ type: "u64"
1338
+ },
1339
+ {
1340
+ name: "tokens_transferred",
1341
+ type: "u64"
1342
+ },
1343
+ {
1344
+ name: "initial_vaulted",
1345
+ type: "u64"
1346
+ },
1347
+ {
1348
+ name: "timestamp",
1349
+ type: "i64"
1350
+ }
1351
+ ]
1352
+ }
1353
+ },
1354
+ {
1355
+ name: "PoolMetadata",
1356
+ type: {
1357
+ kind: "struct",
1358
+ fields: [
1359
+ {
1360
+ name: "name",
1361
+ docs: [
1362
+ "Optional pool name"
1363
+ ],
1364
+ type: "string"
1365
+ },
1366
+ {
1367
+ name: "description",
1368
+ docs: [
1369
+ "Optional pool description"
1370
+ ],
1371
+ type: "string"
1372
+ },
1373
+ {
1374
+ name: "version",
1375
+ docs: [
1376
+ "Pool version"
1377
+ ],
1378
+ type: "u8"
1379
+ }
1380
+ ]
1381
+ }
1382
+ },
1383
+ {
1384
+ name: "PoolState",
1385
+ docs: [
1386
+ "Pool state account - main state for a vAMM pool"
1387
+ ],
1388
+ type: {
1389
+ kind: "struct",
1390
+ fields: [
1391
+ {
1392
+ name: "authority",
1393
+ docs: [
1394
+ "Pool authority (creator)"
1395
+ ],
1396
+ type: "pubkey"
1397
+ },
1398
+ {
1399
+ name: "mint",
1400
+ docs: [
1401
+ "Token mint for this pool"
1402
+ ],
1403
+ type: "pubkey"
1404
+ },
1405
+ {
1406
+ name: "token_vault",
1407
+ docs: [
1408
+ "Token vault (holds unsold tokens)"
1409
+ ],
1410
+ type: "pubkey"
1411
+ },
1412
+ {
1413
+ name: "vault_authority",
1414
+ docs: [
1415
+ "Vault authority (PDA)"
1416
+ ],
1417
+ type: "pubkey"
1418
+ },
1419
+ {
1420
+ name: "sol_vault",
1421
+ docs: [
1422
+ "Pool SOL vault (holds raised SOL)"
1423
+ ],
1424
+ type: "pubkey"
1425
+ },
1426
+ {
1427
+ name: "total_positions",
1428
+ docs: [
1429
+ "Total number of positions in this pool"
1430
+ ],
1431
+ type: "u64"
1432
+ },
1433
+ {
1434
+ name: "creation_timestamp",
1435
+ docs: [
1436
+ "Pool creation timestamp (Unix timestamp)"
1437
+ ],
1438
+ type: "i64"
1439
+ },
1440
+ {
1441
+ name: "last_update_timestamp",
1442
+ docs: [
1443
+ "Last update timestamp (Unix timestamp)"
1444
+ ],
1445
+ type: "i64"
1446
+ },
1447
+ {
1448
+ name: "metadata",
1449
+ docs: [
1450
+ "Pool metadata"
1451
+ ],
1452
+ type: {
1453
+ defined: {
1454
+ name: "PoolMetadata"
1455
+ }
1456
+ }
1457
+ },
1458
+ {
1459
+ name: "vest_duration",
1460
+ docs: [
1461
+ "=== ACCRUAL SYSTEM FIELDS ===",
1462
+ "Dev-set unlock duration in seconds (applies to all traders)"
1463
+ ],
1464
+ type: "i64"
1465
+ },
1466
+ {
1467
+ name: "next_position_number",
1468
+ docs: [
1469
+ "Next position number to assign (sequential counter for display/identity)"
1470
+ ],
1471
+ type: "u64"
1472
+ },
1473
+ {
1474
+ name: "vamm_active",
1475
+ docs: [
1476
+ "=== VAMM STATE ===",
1477
+ "vAMM is active for trading"
1478
+ ],
1479
+ type: "bool"
1480
+ },
1481
+ {
1482
+ name: "vamm_real_sol",
1483
+ docs: [
1484
+ "Real SOL in the vAMM"
1485
+ ],
1486
+ type: "u64"
1487
+ },
1488
+ {
1489
+ name: "vamm_tokens",
1490
+ docs: [
1491
+ "Real tokens in the vAMM"
1492
+ ],
1493
+ type: "u64"
1494
+ },
1495
+ {
1496
+ name: "vamm_k",
1497
+ docs: [
1498
+ "The invariant k (set at creation, never changes)",
1499
+ "k = (vamm_real_sol + VIRTUAL_SOL) * vamm_tokens"
1500
+ ],
1501
+ type: "u128"
1502
+ },
1503
+ {
1504
+ name: "tokens_sold",
1505
+ docs: [
1506
+ "Cumulative tokens bought from vAMM (increases on buy, decreases on sell)"
1507
+ ],
1508
+ type: "u64"
1509
+ },
1510
+ {
1511
+ name: "tokens_reserved_for_claims",
1512
+ docs: [
1513
+ "Vault tokens reserved for position claims (not available for vAMM liquidity)",
1514
+ "Incremented on buy (vaulted portion), decremented on claim_accrued"
1515
+ ],
1516
+ type: "u64"
1517
+ },
1518
+ {
1519
+ name: "bump_vault_auth",
1520
+ docs: [
1521
+ "Bump seeds for PDAs"
1522
+ ],
1523
+ type: "u8"
1524
+ },
1525
+ {
1526
+ name: "bump_pool",
1527
+ type: "u8"
1528
+ }
1529
+ ]
1530
+ }
1531
+ },
1532
+ {
1533
+ name: "Position",
1534
+ docs: [
1535
+ "Position in a vAMM pool",
1536
+ "Tokens split into tradable (immediate) and vaulted (accrue linearly over vest_duration)"
1537
+ ],
1538
+ type: {
1539
+ kind: "struct",
1540
+ fields: [
1541
+ {
1542
+ name: "owner",
1543
+ docs: [
1544
+ "Owner's public key"
1545
+ ],
1546
+ type: {
1547
+ array: [
1548
+ "u8",
1549
+ 32
1550
+ ]
1551
+ }
1552
+ },
1553
+ {
1554
+ name: "pool",
1555
+ docs: [
1556
+ "Pool this position belongs to"
1557
+ ],
1558
+ type: {
1559
+ array: [
1560
+ "u8",
1561
+ 32
1562
+ ]
1563
+ }
1564
+ },
1565
+ {
1566
+ name: "tradable_tokens",
1567
+ docs: [
1568
+ "Tradable tokens (can be sold immediately)"
1569
+ ],
1570
+ type: "u64"
1571
+ },
1572
+ {
1573
+ name: "vaulted_tokens",
1574
+ docs: [
1575
+ "Vaulted tokens (accruing linearly to tradable)"
1576
+ ],
1577
+ type: "u64"
1578
+ },
1579
+ {
1580
+ name: "sol_spent",
1581
+ docs: [
1582
+ "SOL spent on this position"
1583
+ ],
1584
+ type: "u64"
1585
+ },
1586
+ {
1587
+ name: "tokens_transferred",
1588
+ docs: [
1589
+ "Cumulative tokens transferred to wallet (for claim_accrued tracking)"
1590
+ ],
1591
+ type: "u64"
1592
+ },
1593
+ {
1594
+ name: "entry_timestamp",
1595
+ docs: [
1596
+ "Entry timestamp (for accrual calculation)"
1597
+ ],
1598
+ type: "i64"
1599
+ },
1600
+ {
1601
+ name: "initial_vaulted",
1602
+ docs: [
1603
+ "Cumulative initial vaulted tokens from all buys (for accrual calculation)",
1604
+ "This tracks the total vaulted amount at buy time, used to calculate accrual progress"
1605
+ ],
1606
+ type: "u64"
1607
+ },
1608
+ {
1609
+ name: "position_number",
1610
+ docs: [
1611
+ "Position number in the pool (sequential counter for display/identity)"
1612
+ ],
1613
+ type: "u64"
1614
+ },
1615
+ {
1616
+ name: "last_update_timestamp",
1617
+ docs: [
1618
+ "Last update timestamp"
1619
+ ],
1620
+ type: "i64"
1621
+ }
1622
+ ]
1623
+ }
1624
+ },
1625
+ {
1626
+ name: "PositionClosed",
1627
+ docs: [
1628
+ "Event emitted when a position account is closed"
1629
+ ],
1630
+ type: {
1631
+ kind: "struct",
1632
+ fields: [
1633
+ {
1634
+ name: "owner",
1635
+ type: "pubkey"
1636
+ },
1637
+ {
1638
+ name: "pool",
1639
+ type: "pubkey"
1640
+ },
1641
+ {
1642
+ name: "position",
1643
+ type: "pubkey"
1644
+ },
1645
+ {
1646
+ name: "rent_reclaimed",
1647
+ type: "u64"
1648
+ },
1649
+ {
1650
+ name: "timestamp",
1651
+ type: "i64"
1652
+ }
1653
+ ]
1654
+ }
1655
+ },
1656
+ {
1657
+ name: "TokenCreated",
1658
+ docs: [
1659
+ "Event emitted when a new token and vAMM pool is created"
1660
+ ],
1661
+ type: {
1662
+ kind: "struct",
1663
+ fields: [
1664
+ {
1665
+ name: "mint",
1666
+ type: "pubkey"
1667
+ },
1668
+ {
1669
+ name: "pool",
1670
+ type: "pubkey"
1671
+ },
1672
+ {
1673
+ name: "creator",
1674
+ type: "pubkey"
1675
+ },
1676
+ {
1677
+ name: "name",
1678
+ type: "string"
1679
+ },
1680
+ {
1681
+ name: "symbol",
1682
+ type: "string"
1683
+ },
1684
+ {
1685
+ name: "total_supply",
1686
+ type: "u64"
1687
+ },
1688
+ {
1689
+ name: "initial_k",
1690
+ type: "u128"
1691
+ },
1692
+ {
1693
+ name: "vamm_tokens",
1694
+ type: "u64"
1695
+ },
1696
+ {
1697
+ name: "vest_duration",
1698
+ type: "i64"
1699
+ },
1700
+ {
1701
+ name: "creation_timestamp",
1702
+ type: "i64"
1703
+ }
1704
+ ]
1705
+ }
1706
+ },
1707
+ {
1708
+ name: "TokenPurchased",
1709
+ docs: [
1710
+ "Event emitted when tokens are bought"
1711
+ ],
1712
+ type: {
1713
+ kind: "struct",
1714
+ fields: [
1715
+ {
1716
+ name: "buyer",
1717
+ type: "pubkey"
1718
+ },
1719
+ {
1720
+ name: "pool",
1721
+ type: "pubkey"
1722
+ },
1723
+ {
1724
+ name: "mint",
1725
+ type: "pubkey"
1726
+ },
1727
+ {
1728
+ name: "sol_amount",
1729
+ type: "u64"
1730
+ },
1731
+ {
1732
+ name: "tokens_received",
1733
+ type: "u64"
1734
+ },
1735
+ {
1736
+ name: "vamm_real_sol",
1737
+ type: "u64"
1738
+ },
1739
+ {
1740
+ name: "vamm_tokens",
1741
+ type: "u64"
1742
+ },
1743
+ {
1744
+ name: "tokens_sold",
1745
+ type: "u64"
1746
+ },
1747
+ {
1748
+ name: "position",
1749
+ type: "pubkey"
1750
+ },
1751
+ {
1752
+ name: "position_number",
1753
+ type: "u64"
1754
+ },
1755
+ {
1756
+ name: "vest_duration",
1757
+ type: "i64"
1758
+ },
1759
+ {
1760
+ name: "unlock_time_seconds",
1761
+ type: "i64"
1762
+ },
1763
+ {
1764
+ name: "tradable_tokens",
1765
+ docs: [
1766
+ "Position state after buy"
1767
+ ],
1768
+ type: "u64"
1769
+ },
1770
+ {
1771
+ name: "vaulted_tokens",
1772
+ type: "u64"
1773
+ },
1774
+ {
1775
+ name: "sol_spent",
1776
+ type: "u64"
1777
+ },
1778
+ {
1779
+ name: "tokens_transferred",
1780
+ type: "u64"
1781
+ },
1782
+ {
1783
+ name: "initial_vaulted",
1784
+ type: "u64"
1785
+ },
1786
+ {
1787
+ name: "timestamp",
1788
+ type: "i64"
1789
+ }
1790
+ ]
1791
+ }
1792
+ },
1793
+ {
1794
+ name: "TokenSold",
1795
+ docs: [
1796
+ "Event emitted when tokens are sold"
1797
+ ],
1798
+ type: {
1799
+ kind: "struct",
1800
+ fields: [
1801
+ {
1802
+ name: "seller",
1803
+ type: "pubkey"
1804
+ },
1805
+ {
1806
+ name: "pool",
1807
+ type: "pubkey"
1808
+ },
1809
+ {
1810
+ name: "mint",
1811
+ type: "pubkey"
1812
+ },
1813
+ {
1814
+ name: "token_amount",
1815
+ type: "u64"
1816
+ },
1817
+ {
1818
+ name: "sol_received",
1819
+ type: "u64"
1820
+ },
1821
+ {
1822
+ name: "vamm_real_sol",
1823
+ type: "u64"
1824
+ },
1825
+ {
1826
+ name: "vamm_tokens",
1827
+ type: "u64"
1828
+ },
1829
+ {
1830
+ name: "tokens_sold",
1831
+ type: "u64"
1832
+ },
1833
+ {
1834
+ name: "position",
1835
+ type: "pubkey"
1836
+ },
1837
+ {
1838
+ name: "position_number",
1839
+ type: "u64"
1840
+ },
1841
+ {
1842
+ name: "vest_duration",
1843
+ type: "i64"
1844
+ },
1845
+ {
1846
+ name: "unlock_time_seconds",
1847
+ type: "i64"
1848
+ },
1849
+ {
1850
+ name: "tradable_tokens",
1851
+ docs: [
1852
+ "Position state after sell"
1853
+ ],
1854
+ type: "u64"
1855
+ },
1856
+ {
1857
+ name: "vaulted_tokens",
1858
+ type: "u64"
1859
+ },
1860
+ {
1861
+ name: "sol_spent",
1862
+ type: "u64"
1863
+ },
1864
+ {
1865
+ name: "tokens_transferred",
1866
+ type: "u64"
1867
+ },
1868
+ {
1869
+ name: "initial_vaulted",
1870
+ type: "u64"
1871
+ },
1872
+ {
1873
+ name: "timestamp",
1874
+ type: "i64"
1875
+ }
1876
+ ]
1877
+ }
1878
+ }
1879
+ ]
1880
+ };
1881
+
1882
+ // src/program.ts
1883
+ var DUMMY_WALLET = {
1884
+ publicKey: web3_js.PublicKey.default,
1885
+ signTransaction: async (tx) => tx,
1886
+ signAllTransactions: async (txs) => txs
1887
+ };
1888
+ function getProgram(connection) {
1889
+ const provider = new anchor.AnchorProvider(connection, DUMMY_WALLET, { commitment: "confirmed" });
1890
+ return new anchor.Program(hodl_default, provider);
1891
+ }
1892
+
1893
+ // src/accounts.ts
1894
+ async function fetchPoolState(connection, mint, config) {
1895
+ const program = getProgram(connection);
1896
+ const [poolStatePDA] = getPoolStatePDA(mint, config.programId);
1897
+ return program.account.poolState.fetch(poolStatePDA);
1898
+ }
1899
+ async function fetchPosition(connection, poolState, owner, config) {
1900
+ const program = getProgram(connection);
1901
+ const [positionPDA] = getPositionPDA(poolState, owner, config.programId);
1902
+ return program.account.position.fetch(positionPDA);
1903
+ }
1904
+ var METADATA_PROGRAM_ID = new web3_js.PublicKey("metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s");
1905
+ function getMetadataPDA(mint) {
1906
+ const [pda] = web3_js.PublicKey.findProgramAddressSync(
1907
+ [Buffer.from("metadata"), METADATA_PROGRAM_ID.toBuffer(), mint.toBuffer()],
1908
+ METADATA_PROGRAM_ID
1909
+ );
1910
+ return pda;
1911
+ }
1912
+ async function buildBuyInstruction(params) {
1913
+ const { buyer, mint, solAmount, minTokensOut, connection, config } = params;
1914
+ const program = getProgram(connection);
1915
+ const [poolState] = getPoolStatePDA(mint, config.programId);
1916
+ const [vaultAuthority] = getVaultAuthorityPDA(poolState, config.programId);
1917
+ const tokenVault = splToken.getAssociatedTokenAddressSync(mint, vaultAuthority, true);
1918
+ const buyerTokenAccount = splToken.getAssociatedTokenAddressSync(mint, buyer);
1919
+ const [poolSolAccount] = getSolVaultPDA(poolState, config.programId);
1920
+ const [position] = getPositionPDA(poolState, buyer, config.programId);
1921
+ const [eventAuthority] = getEventAuthorityPDA(config.programId);
1922
+ return program.methods.buy(solAmount, minTokensOut).accountsPartial({
1923
+ buyer,
1924
+ poolState,
1925
+ tokenVault,
1926
+ vaultAuthority,
1927
+ buyerTokenAccount,
1928
+ poolSolAccount,
1929
+ mint,
1930
+ tokenProgram: splToken.TOKEN_PROGRAM_ID,
1931
+ associatedTokenProgram: splToken.ASSOCIATED_TOKEN_PROGRAM_ID,
1932
+ systemProgram: web3_js.SystemProgram.programId,
1933
+ position,
1934
+ eventAuthority,
1935
+ program: config.programId
1936
+ }).instruction();
1937
+ }
1938
+ async function buildSellInstruction(params) {
1939
+ const { seller, mint, tokenAmount, minSolOut, sellPercentage, connection, config } = params;
1940
+ const program = getProgram(connection);
1941
+ const [poolState] = getPoolStatePDA(mint, config.programId);
1942
+ const [vaultAuthority] = getVaultAuthorityPDA(poolState, config.programId);
1943
+ const tokenVault = splToken.getAssociatedTokenAddressSync(mint, vaultAuthority, true);
1944
+ const sellerTokenAccount = splToken.getAssociatedTokenAddressSync(mint, seller);
1945
+ const [poolSolAccount] = getSolVaultPDA(poolState, config.programId);
1946
+ const [position] = getPositionPDA(poolState, seller, config.programId);
1947
+ const [eventAuthority] = getEventAuthorityPDA(config.programId);
1948
+ return program.methods.sell(tokenAmount, minSolOut, sellPercentage ?? null).accountsPartial({
1949
+ seller,
1950
+ poolState,
1951
+ position,
1952
+ tokenVault,
1953
+ vaultAuthority,
1954
+ sellerTokenAccount,
1955
+ poolSolAccount,
1956
+ mint,
1957
+ tokenProgram: splToken.TOKEN_PROGRAM_ID,
1958
+ systemProgram: web3_js.SystemProgram.programId,
1959
+ eventAuthority,
1960
+ program: config.programId
1961
+ }).instruction();
1962
+ }
1963
+ async function buildCreateTokenInstruction(params) {
1964
+ const { creator, mint, name, symbol, uri, poolDescription, vestDuration, connection, config } = params;
1965
+ const program = getProgram(connection);
1966
+ const [poolState] = getPoolStatePDA(mint, config.programId);
1967
+ const [vaultAuthority] = getVaultAuthorityPDA(poolState, config.programId);
1968
+ const tokenVault = splToken.getAssociatedTokenAddressSync(mint, vaultAuthority, true);
1969
+ const metadata = getMetadataPDA(mint);
1970
+ const [poolSolAccount] = getSolVaultPDA(poolState, config.programId);
1971
+ const [protocolFeeWallet] = getProtocolFeesPDA(config.programId);
1972
+ const [eventAuthority] = getEventAuthorityPDA(config.programId);
1973
+ return program.methods.createToken(name, symbol, uri, poolDescription, vestDuration).accountsPartial({
1974
+ creator,
1975
+ protocolAuthority: config.protocolAuthority,
1976
+ mint,
1977
+ poolState,
1978
+ tokenVault,
1979
+ vaultAuthority,
1980
+ metadata,
1981
+ poolSolAccount,
1982
+ protocolFeeWallet,
1983
+ tokenProgram: splToken.TOKEN_PROGRAM_ID,
1984
+ associatedTokenProgram: splToken.ASSOCIATED_TOKEN_PROGRAM_ID,
1985
+ systemProgram: web3_js.SystemProgram.programId,
1986
+ rent: web3_js.SYSVAR_RENT_PUBKEY,
1987
+ metadataProgram: METADATA_PROGRAM_ID,
1988
+ sysvarInstructions: web3_js.SYSVAR_INSTRUCTIONS_PUBKEY,
1989
+ eventAuthority,
1990
+ program: config.programId
1991
+ }).instruction();
1992
+ }
1993
+ async function buildClaimAccruedInstruction(params) {
1994
+ const { owner, poolState, connection, config } = params;
1995
+ const program = getProgram(connection);
1996
+ const poolData = await program.account.poolState.fetch(poolState);
1997
+ const mint = poolData.mint;
1998
+ const [vaultAuthority] = getVaultAuthorityPDA(poolState, config.programId);
1999
+ const tokenVault = splToken.getAssociatedTokenAddressSync(mint, vaultAuthority, true);
2000
+ const userTokenAccount = splToken.getAssociatedTokenAddressSync(mint, owner);
2001
+ const [position] = getPositionPDA(poolState, owner, config.programId);
2002
+ const [eventAuthority] = getEventAuthorityPDA(config.programId);
2003
+ return program.methods.claimAccrued().accountsPartial({
2004
+ owner,
2005
+ poolState,
2006
+ position,
2007
+ tokenVault,
2008
+ vaultAuthority,
2009
+ userTokenAccount,
2010
+ tokenProgram: splToken.TOKEN_PROGRAM_ID,
2011
+ eventAuthority,
2012
+ program: config.programId
2013
+ }).instruction();
2014
+ }
2015
+ async function buildClosePositionInstruction(params) {
2016
+ const { owner, poolState, mint, userTokenAccount, connection, config } = params;
2017
+ const program = getProgram(connection);
2018
+ const [position] = getPositionPDA(poolState, owner, config.programId);
2019
+ const [eventAuthority] = getEventAuthorityPDA(config.programId);
2020
+ return program.methods.closePosition().accountsPartial({
2021
+ owner,
2022
+ poolState,
2023
+ position,
2024
+ userTokenAccount,
2025
+ mint,
2026
+ tokenProgram: splToken.TOKEN_PROGRAM_ID,
2027
+ systemProgram: web3_js.SystemProgram.programId,
2028
+ eventAuthority,
2029
+ program: config.programId
2030
+ }).instruction();
2031
+ }
2032
+ async function buildTransaction(connection, instructions, payer, opts = {}) {
2033
+ const cuLimit = opts.computeUnits ?? 2e5;
2034
+ const priorityFee = opts.priorityFee ?? 1e3;
2035
+ const computeIxs = [
2036
+ web3_js.ComputeBudgetProgram.setComputeUnitLimit({ units: cuLimit }),
2037
+ web3_js.ComputeBudgetProgram.setComputeUnitPrice({ microLamports: priorityFee })
2038
+ ];
2039
+ const { blockhash } = await connection.getLatestBlockhash("confirmed");
2040
+ const message = new web3_js.TransactionMessage({
2041
+ payerKey: payer,
2042
+ recentBlockhash: blockhash,
2043
+ instructions: [...computeIxs, ...instructions]
2044
+ }).compileToV0Message();
2045
+ return new web3_js.VersionedTransaction(message);
2046
+ }
2047
+ async function sendTransaction(connection, tx, opts = {}) {
2048
+ const sig = await connection.sendTransaction(tx, {
2049
+ skipPreflight: opts.skipPreflight ?? false,
2050
+ maxRetries: 3
2051
+ });
2052
+ const latestBlockhash = await connection.getLatestBlockhash("confirmed");
2053
+ await connection.confirmTransaction({
2054
+ signature: sig,
2055
+ ...latestBlockhash
2056
+ }, "confirmed");
2057
+ return sig;
2058
+ }
2059
+ function parseTransactionEvents(input, config) {
2060
+ if (!input) return [];
2061
+ const logs = Array.isArray(input) ? input : input.meta?.logMessages ?? [];
2062
+ if (logs.length === 0) return [];
2063
+ const coder = new anchor.BorshCoder(hodl_default);
2064
+ const parser = new anchor.EventParser(config.programId, coder);
2065
+ const events = [];
2066
+ try {
2067
+ for (const event of parser.parseLogs(logs)) {
2068
+ events.push({ name: event.name, data: event.data });
2069
+ }
2070
+ } catch {
2071
+ }
2072
+ return events;
2073
+ }
2074
+ async function fetchAndParseTransaction(connection, signature, config) {
2075
+ const tx = await connection.getTransaction(signature, {
2076
+ commitment: "confirmed",
2077
+ maxSupportedTransactionVersion: 0
2078
+ });
2079
+ return parseTransactionEvents(tx, config);
2080
+ }
2081
+ function subscribeToEvents(connection, config, onEvent, opts = {}) {
2082
+ const commitment = opts.commitment ?? "confirmed";
2083
+ const coder = new anchor.BorshCoder(hodl_default);
2084
+ const parser = new anchor.EventParser(config.programId, coder);
2085
+ return connection.onLogs(
2086
+ config.programId,
2087
+ ({ logs, err, signature }, context) => {
2088
+ if (err) {
2089
+ opts.onError?.(new Error(`Log subscription error: ${JSON.stringify(err)}`));
2090
+ return;
2091
+ }
2092
+ try {
2093
+ for (const event of parser.parseLogs(logs)) {
2094
+ onEvent(
2095
+ { name: event.name, data: event.data },
2096
+ context.slot,
2097
+ signature
2098
+ );
2099
+ }
2100
+ } catch (e) {
2101
+ opts.onError?.(e instanceof Error ? e : new Error(String(e)));
2102
+ }
2103
+ },
2104
+ commitment
2105
+ );
2106
+ }
2107
+ function unsubscribeFromEvents(connection, subscriptionId) {
2108
+ return connection.removeOnLogsListener(subscriptionId);
2109
+ }
2110
+
2111
+ // src/client.ts
2112
+ var HodlClient = class {
2113
+ connection;
2114
+ config;
2115
+ constructor({ connection, config }) {
2116
+ this.connection = connection;
2117
+ this.config = config ?? MAINNET_CONFIG;
2118
+ }
2119
+ fetchPool(mint) {
2120
+ return fetchPoolState(this.connection, mint, this.config);
2121
+ }
2122
+ fetchPosition(poolState, owner) {
2123
+ return fetchPosition(this.connection, poolState, owner, this.config);
2124
+ }
2125
+ async buy(params, opts) {
2126
+ const ix = await buildBuyInstruction({ ...params, connection: this.connection, config: this.config });
2127
+ return buildTransaction(this.connection, [ix], params.buyer, opts);
2128
+ }
2129
+ async sell(params, opts) {
2130
+ const ix = await buildSellInstruction({ ...params, connection: this.connection, config: this.config });
2131
+ return buildTransaction(this.connection, [ix], params.seller, opts);
2132
+ }
2133
+ async createToken(params, opts) {
2134
+ const ix = await buildCreateTokenInstruction({ ...params, connection: this.connection, config: this.config });
2135
+ return buildTransaction(this.connection, [ix], params.creator, opts);
2136
+ }
2137
+ async claimAccrued(params, opts) {
2138
+ const ix = await buildClaimAccruedInstruction({ ...params, connection: this.connection, config: this.config });
2139
+ return buildTransaction(this.connection, [ix], params.owner, opts);
2140
+ }
2141
+ async closePosition(params, opts) {
2142
+ const ix = await buildClosePositionInstruction({ ...params, connection: this.connection, config: this.config });
2143
+ return buildTransaction(this.connection, [ix], params.owner, opts);
2144
+ }
2145
+ send(tx, opts) {
2146
+ return sendTransaction(this.connection, tx, opts);
2147
+ }
2148
+ subscribeToEvents(onEvent, opts) {
2149
+ return subscribeToEvents(this.connection, this.config, onEvent, opts);
2150
+ }
2151
+ unsubscribe(subscriptionId) {
2152
+ return unsubscribeFromEvents(this.connection, subscriptionId);
2153
+ }
2154
+ fetchAndParseTransaction(signature) {
2155
+ return fetchAndParseTransaction(this.connection, signature, this.config);
2156
+ }
2157
+ };
2158
+
2159
+ exports.HodlClient = HodlClient;
2160
+ //# sourceMappingURL=client.cjs.map
2161
+ //# sourceMappingURL=client.cjs.map