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