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