@elmntl/jlpd-sdk 0.2.0 → 0.13.4

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 (115) hide show
  1. package/LICENSE +201 -0
  2. package/README.md +185 -404
  3. package/dist/common/ata.d.ts +26 -0
  4. package/dist/common/ata.js +48 -0
  5. package/dist/common/buffer.d.ts +15 -0
  6. package/dist/common/buffer.js +118 -0
  7. package/dist/common/connection.d.ts +13 -0
  8. package/dist/common/connection.js +2 -0
  9. package/dist/common/constants.d.ts +14 -0
  10. package/dist/common/constants.js +31 -0
  11. package/dist/common/index.d.ts +6 -0
  12. package/dist/common/index.js +28 -0
  13. package/dist/common/strategy-interface.d.ts +59 -0
  14. package/dist/common/strategy-interface.js +42 -0
  15. package/dist/elemental-lend/accounts.d.ts +103 -0
  16. package/dist/elemental-lend/accounts.js +354 -0
  17. package/dist/elemental-lend/constants.d.ts +25 -0
  18. package/dist/elemental-lend/constants.js +48 -0
  19. package/dist/elemental-lend/index.d.ts +8 -0
  20. package/dist/elemental-lend/index.js +24 -0
  21. package/dist/elemental-lend/instructions.d.ts +104 -0
  22. package/dist/elemental-lend/instructions.js +266 -0
  23. package/dist/elemental-lend/jupiter-lend.d.ts +91 -0
  24. package/dist/elemental-lend/jupiter-lend.js +189 -0
  25. package/dist/elemental-lend/kamino-vault.d.ts +173 -0
  26. package/dist/elemental-lend/kamino-vault.js +483 -0
  27. package/dist/elemental-lend/pda.d.ts +12 -0
  28. package/dist/elemental-lend/pda.js +24 -0
  29. package/dist/elemental-lend/protocol-actions.d.ts +56 -0
  30. package/dist/elemental-lend/protocol-actions.js +244 -0
  31. package/dist/elemental-lend/types.d.ts +113 -0
  32. package/dist/elemental-lend/types.js +2 -0
  33. package/dist/elemental-lend-v2/accounts.d.ts +14 -0
  34. package/dist/elemental-lend-v2/accounts.js +136 -0
  35. package/dist/elemental-lend-v2/adapters.d.ts +22 -0
  36. package/dist/elemental-lend-v2/adapters.js +50 -0
  37. package/dist/elemental-lend-v2/constants.d.ts +48 -0
  38. package/dist/elemental-lend-v2/constants.js +104 -0
  39. package/dist/elemental-lend-v2/index.d.ts +8 -0
  40. package/dist/elemental-lend-v2/index.js +24 -0
  41. package/dist/elemental-lend-v2/instructions.d.ts +96 -0
  42. package/dist/elemental-lend-v2/instructions.js +190 -0
  43. package/dist/elemental-lend-v2/lut.d.ts +20 -0
  44. package/dist/elemental-lend-v2/lut.js +65 -0
  45. package/dist/elemental-lend-v2/pda.d.ts +9 -0
  46. package/dist/elemental-lend-v2/pda.js +27 -0
  47. package/dist/elemental-lend-v2/types.d.ts +105 -0
  48. package/dist/elemental-lend-v2/types.js +2 -0
  49. package/dist/elemental-lend-v2/update-aum.d.ts +29 -0
  50. package/dist/elemental-lend-v2/update-aum.js +82 -0
  51. package/dist/index.d.ts +5 -4199
  52. package/dist/index.js +37 -5187
  53. package/dist/jlpd-strategy/accounts.d.ts +83 -0
  54. package/dist/jlpd-strategy/accounts.js +216 -0
  55. package/dist/jlpd-strategy/adapter.d.ts +81 -0
  56. package/dist/jlpd-strategy/adapter.js +118 -0
  57. package/dist/jlpd-strategy/base-to-base-swap.d.ts +74 -0
  58. package/dist/jlpd-strategy/base-to-base-swap.js +205 -0
  59. package/dist/jlpd-strategy/constants.d.ts +127 -0
  60. package/dist/jlpd-strategy/constants.js +174 -0
  61. package/dist/jlpd-strategy/fluid-view.d.ts +199 -0
  62. package/dist/jlpd-strategy/fluid-view.js +799 -0
  63. package/dist/jlpd-strategy/hedge-derived.d.ts +135 -0
  64. package/dist/jlpd-strategy/hedge-derived.js +231 -0
  65. package/dist/jlpd-strategy/hedge-instructions.d.ts +210 -0
  66. package/dist/jlpd-strategy/hedge-instructions.js +300 -0
  67. package/dist/jlpd-strategy/hedge-state.d.ts +88 -0
  68. package/dist/jlpd-strategy/hedge-state.js +110 -0
  69. package/dist/jlpd-strategy/index.d.ts +17 -0
  70. package/dist/jlpd-strategy/index.js +33 -0
  71. package/dist/jlpd-strategy/instructions.d.ts +159 -0
  72. package/dist/jlpd-strategy/instructions.js +234 -0
  73. package/dist/jlpd-strategy/jlp-borrow.d.ts +63 -0
  74. package/dist/jlpd-strategy/jlp-borrow.js +87 -0
  75. package/dist/jlpd-strategy/jlp-data.d.ts +166 -0
  76. package/dist/jlpd-strategy/jlp-data.js +611 -0
  77. package/dist/jlpd-strategy/jupusd-earn.d.ts +90 -0
  78. package/dist/jlpd-strategy/jupusd-earn.js +166 -0
  79. package/dist/jlpd-strategy/live-jlp-price.d.ts +46 -0
  80. package/dist/jlpd-strategy/live-jlp-price.js +267 -0
  81. package/dist/jlpd-strategy/pda.d.ts +13 -0
  82. package/dist/jlpd-strategy/pda.js +28 -0
  83. package/dist/jlpd-strategy/settle-yield.d.ts +45 -0
  84. package/dist/jlpd-strategy/settle-yield.js +113 -0
  85. package/dist/jlpd-strategy/swap-jlp.d.ts +198 -0
  86. package/dist/jlpd-strategy/swap-jlp.js +586 -0
  87. package/dist/jlpd-strategy/types.d.ts +101 -0
  88. package/dist/jlpd-strategy/types.js +29 -0
  89. package/dist/p-stv-core/accounts.d.ts +152 -0
  90. package/dist/p-stv-core/accounts.js +407 -0
  91. package/dist/p-stv-core/constants.d.ts +138 -0
  92. package/dist/p-stv-core/constants.js +181 -0
  93. package/dist/p-stv-core/events.d.ts +7 -0
  94. package/dist/p-stv-core/events.js +246 -0
  95. package/dist/p-stv-core/index.d.ts +11 -0
  96. package/dist/p-stv-core/index.js +27 -0
  97. package/dist/p-stv-core/instructions.d.ts +637 -0
  98. package/dist/p-stv-core/instructions.js +670 -0
  99. package/dist/p-stv-core/lut.d.ts +41 -0
  100. package/dist/p-stv-core/lut.js +81 -0
  101. package/dist/p-stv-core/pda.d.ts +30 -0
  102. package/dist/p-stv-core/pda.js +65 -0
  103. package/dist/p-stv-core/prices.d.ts +20 -0
  104. package/dist/p-stv-core/prices.js +77 -0
  105. package/dist/p-stv-core/remaining-accounts.d.ts +107 -0
  106. package/dist/p-stv-core/remaining-accounts.js +326 -0
  107. package/dist/p-stv-core/send-tx.d.ts +72 -0
  108. package/dist/p-stv-core/send-tx.js +290 -0
  109. package/dist/p-stv-core/sol-wrap.d.ts +34 -0
  110. package/dist/p-stv-core/sol-wrap.js +74 -0
  111. package/dist/p-stv-core/types.d.ts +361 -0
  112. package/dist/p-stv-core/types.js +2 -0
  113. package/package.json +56 -15
  114. package/dist/index.d.mts +0 -4199
  115. package/dist/index.mjs +0 -5090
package/dist/index.mjs DELETED
@@ -1,5090 +0,0 @@
1
- // src/client.ts
2
- import {
3
- PublicKey as PublicKey8,
4
- TransactionMessage,
5
- VersionedTransaction,
6
- ComputeBudgetProgram,
7
- SystemProgram as SystemProgram2
8
- } from "@solana/web3.js";
9
- import { BN as BN5 } from "@coral-xyz/anchor";
10
- import {
11
- TOKEN_PROGRAM_ID as TOKEN_PROGRAM_ID2,
12
- ASSOCIATED_TOKEN_PROGRAM_ID as ASSOCIATED_TOKEN_PROGRAM_ID2,
13
- getAssociatedTokenAddressSync as getAssociatedTokenAddressSync2
14
- } from "@solana/spl-token";
15
-
16
- // src/program.ts
17
- import { Program, AnchorProvider } from "@coral-xyz/anchor";
18
- import { Keypair } from "@solana/web3.js";
19
-
20
- // idl/jlp_d_program.json
21
- var jlp_d_program_default = {
22
- address: "ELEM2bAobpZNuysfhyF28XGVjA1aTUwm6rPYyv1JX3oq",
23
- metadata: {
24
- name: "jlp_d_program",
25
- version: "0.1.0",
26
- spec: "0.1.0",
27
- description: "Created with Anchor"
28
- },
29
- instructions: [
30
- {
31
- name: "claim_fees",
32
- discriminator: [
33
- 82,
34
- 251,
35
- 233,
36
- 156,
37
- 12,
38
- 52,
39
- 184,
40
- 202
41
- ],
42
- accounts: [
43
- {
44
- name: "manager",
45
- docs: [
46
- "Manager claiming fees on behalf of fee_receiver"
47
- ],
48
- signer: true
49
- },
50
- {
51
- name: "jlp_vault",
52
- docs: [
53
- "The JLP Vault PDA account",
54
- "Note: PDA verified in handler via get_pda() to avoid multiple loads"
55
- ]
56
- },
57
- {
58
- name: "stv",
59
- docs: [
60
- "The STV PDA account",
61
- "Note: PDA verified in handler via get_pda() to avoid multiple loads"
62
- ],
63
- writable: true
64
- },
65
- {
66
- name: "base_mint",
67
- docs: [
68
- "Base asset mint"
69
- ]
70
- },
71
- {
72
- name: "jl_mint",
73
- docs: [
74
- "jlX mint (Jupiter Lend token) - for decimals in transfer_checked"
75
- ]
76
- },
77
- {
78
- name: "jv_mint",
79
- docs: [
80
- "jvX mint (vault share token) - for supply reading in crystallization"
81
- ]
82
- },
83
- {
84
- name: "stv_base_ata",
85
- docs: [
86
- "STV's base ATA (for NAV calculation)"
87
- ]
88
- },
89
- {
90
- name: "stv_jlx_ata",
91
- docs: [
92
- "STV's jlX ATA (source for fee transfer)"
93
- ],
94
- writable: true
95
- },
96
- {
97
- name: "fee_receiver_jlx_ata",
98
- docs: [
99
- "Fee receiver's jlX ATA (destination for fees)"
100
- ],
101
- writable: true
102
- },
103
- {
104
- name: "token_program",
105
- docs: [
106
- "Token program"
107
- ]
108
- }
109
- ],
110
- args: []
111
- },
112
- {
113
- name: "claim_withdraw",
114
- docs: [
115
- "Claim processed withdrawal (epoch-based delayed withdrawal)",
116
- "",
117
- "# Flow",
118
- "1. Verify request is processed (pps > 0) and claim period reached",
119
- "2. Transfer base from STV to user",
120
- "3. Close request's jvX ATA and WithdrawRequest PDA (rent to user)"
121
- ],
122
- discriminator: [
123
- 232,
124
- 89,
125
- 154,
126
- 117,
127
- 16,
128
- 204,
129
- 182,
130
- 224
131
- ],
132
- accounts: [
133
- {
134
- name: "user",
135
- docs: [
136
- "User claiming their withdrawal"
137
- ],
138
- writable: true,
139
- signer: true
140
- },
141
- {
142
- name: "stv",
143
- docs: [
144
- "The STV PDA account (mut for reserved_base update)"
145
- ],
146
- writable: true
147
- },
148
- {
149
- name: "base_mint",
150
- docs: [
151
- "Base asset mint (for transfer_checked)"
152
- ]
153
- },
154
- {
155
- name: "jv_mint",
156
- docs: [
157
- "jvX mint (for ATA close verification)"
158
- ]
159
- },
160
- {
161
- name: "user_base_ata",
162
- docs: [
163
- "User's base token destination"
164
- ],
165
- writable: true
166
- },
167
- {
168
- name: "stv_base_ata",
169
- docs: [
170
- "STV's base ATA (source for base transfer)"
171
- ],
172
- writable: true
173
- },
174
- {
175
- name: "withdraw_request",
176
- docs: [
177
- "WithdrawRequest PDA - closed after claim (rent to user)"
178
- ],
179
- writable: true,
180
- pda: {
181
- seeds: [
182
- {
183
- kind: "const",
184
- value: [
185
- 119,
186
- 105,
187
- 116,
188
- 104,
189
- 100,
190
- 114,
191
- 97,
192
- 119,
193
- 95,
194
- 114,
195
- 101,
196
- 113,
197
- 117,
198
- 101,
199
- 115,
200
- 116
201
- ]
202
- },
203
- {
204
- kind: "account",
205
- path: "stv"
206
- },
207
- {
208
- kind: "account",
209
- path: "user"
210
- },
211
- {
212
- kind: "account",
213
- path: "withdraw_request.epoch_id",
214
- account: "WithdrawRequest"
215
- }
216
- ]
217
- }
218
- },
219
- {
220
- name: "request_jvx_ata",
221
- docs: [
222
- "Empty jvX ATA owned by WithdrawRequest PDA (to close, rent to user)"
223
- ],
224
- writable: true
225
- },
226
- {
227
- name: "token_program"
228
- }
229
- ],
230
- args: []
231
- },
232
- {
233
- name: "deposit",
234
- docs: [
235
- "Deposit base asset into the STV and receive jvX shares",
236
- "",
237
- "# Flow",
238
- "1. Crystallize fees inline (ensures fair PPS)",
239
- "2. Transfer base asset from user to STV's base ATA",
240
- "3. Mint jvX shares to user at post-fee PPS",
241
- "",
242
- "# Note",
243
- "For pools with Jupiter Earn support (SOL, USDC), manager can later convert",
244
- "base to jlX via jup_earn_deposit_withdraw instruction.",
245
- "For pools without Jupiter Earn (BTC, ETH), base stays in STV's base ATA.",
246
- "",
247
- "Remaining accounts (optional, for exchange rate):",
248
- "[0] = Jupiter Lend lending account",
249
- "[1] = Jupiter Lend rewards rate model"
250
- ],
251
- discriminator: [
252
- 242,
253
- 35,
254
- 198,
255
- 137,
256
- 82,
257
- 225,
258
- 242,
259
- 182
260
- ],
261
- accounts: [
262
- {
263
- name: "user",
264
- docs: [
265
- "User performing the deposit"
266
- ],
267
- writable: true,
268
- signer: true
269
- },
270
- {
271
- name: "jlp_vault",
272
- docs: [
273
- "The JLP Vault PDA account",
274
- "Note: bump verified in handler after load() to avoid multiple loads"
275
- ]
276
- },
277
- {
278
- name: "stv",
279
- docs: [
280
- "The STV PDA account",
281
- "Note: uses base_mint account for seeds; bump verified in handler"
282
- ],
283
- writable: true
284
- },
285
- {
286
- name: "base_mint",
287
- docs: [
288
- "Base asset mint (underlying token: SOL, BTC, ETH, USDC)"
289
- ]
290
- },
291
- {
292
- name: "jl_mint",
293
- docs: [
294
- "jlX mint (Jupiter Lend token) - used for exchange rate reading"
295
- ]
296
- },
297
- {
298
- name: "jv_mint",
299
- docs: [
300
- "jvX mint (vault share token) - STV is mint authority",
301
- "Verified against STV.jv_mint in handler"
302
- ],
303
- writable: true
304
- },
305
- {
306
- name: "user_base_ata",
307
- docs: [
308
- "User's base asset token account (source for deposit)"
309
- ],
310
- writable: true
311
- },
312
- {
313
- name: "user_jvx_ata",
314
- docs: [
315
- "User's jvX token account (destination for shares)"
316
- ],
317
- writable: true
318
- },
319
- {
320
- name: "stv_base_ata",
321
- docs: [
322
- "STV's base ATA (destination for user's base tokens)"
323
- ],
324
- writable: true
325
- },
326
- {
327
- name: "stv_jlx_ata",
328
- docs: [
329
- "STV's jlX ATA (used for NAV calculation)"
330
- ]
331
- },
332
- {
333
- name: "token_program",
334
- docs: [
335
- "Token program"
336
- ]
337
- }
338
- ],
339
- args: [
340
- {
341
- name: "amount",
342
- type: "u64"
343
- }
344
- ]
345
- },
346
- {
347
- name: "init_or_update_jlp_vault",
348
- docs: [
349
- "Initialize or update the global JLP Vault",
350
- "Init: Creates vault PDA with admin, jlp_mint, base_asset_mints (immutable after init)",
351
- "Update: Modifies manager, fee_receiver, and rebalance parameters",
352
- "Note: ATAs are created externally via script"
353
- ],
354
- discriminator: [
355
- 234,
356
- 24,
357
- 218,
358
- 120,
359
- 213,
360
- 149,
361
- 245,
362
- 213
363
- ],
364
- accounts: [
365
- {
366
- name: "admin",
367
- docs: [
368
- "Admin who controls the vault"
369
- ],
370
- writable: true,
371
- signer: true
372
- },
373
- {
374
- name: "jlp_vault",
375
- docs: [
376
- "The JLP Vault PDA account (zero-copy)",
377
- "Uses init_if_needed to support both init and update paths"
378
- ],
379
- writable: true,
380
- pda: {
381
- seeds: [
382
- {
383
- kind: "const",
384
- value: [
385
- 106,
386
- 108,
387
- 112,
388
- 95,
389
- 118,
390
- 97,
391
- 117,
392
- 108,
393
- 116
394
- ]
395
- }
396
- ]
397
- }
398
- },
399
- {
400
- name: "system_program",
401
- docs: [
402
- "System program"
403
- ],
404
- address: "11111111111111111111111111111111"
405
- }
406
- ],
407
- args: [
408
- {
409
- name: "params",
410
- type: {
411
- defined: {
412
- name: "InitOrUpdateJlpVaultParams"
413
- }
414
- }
415
- }
416
- ]
417
- },
418
- {
419
- name: "initialize_stv",
420
- docs: [
421
- "Initialize a Single Token Vault (STV) for a specific asset",
422
- "Creates the STV PDA, jvX mint (with STV as authority), and jlX ATA"
423
- ],
424
- discriminator: [
425
- 136,
426
- 8,
427
- 178,
428
- 176,
429
- 57,
430
- 33,
431
- 1,
432
- 106
433
- ],
434
- accounts: [
435
- {
436
- name: "admin",
437
- docs: [
438
- "Admin of the JLP Vault"
439
- ],
440
- writable: true,
441
- signer: true
442
- },
443
- {
444
- name: "jlp_vault",
445
- docs: [
446
- "The JLP Vault PDA account",
447
- "Note: PDA and admin verified in handler via get_pda() to avoid multiple loads"
448
- ]
449
- },
450
- {
451
- name: "stv",
452
- docs: [
453
- "The STV PDA account (zero-copy)"
454
- ],
455
- writable: true,
456
- pda: {
457
- seeds: [
458
- {
459
- kind: "const",
460
- value: [
461
- 115,
462
- 116,
463
- 118
464
- ]
465
- },
466
- {
467
- kind: "account",
468
- path: "base_mint"
469
- }
470
- ]
471
- }
472
- },
473
- {
474
- name: "base_mint",
475
- docs: [
476
- "Base asset mint (BTC, ETH, SOL, or USDC)"
477
- ]
478
- },
479
- {
480
- name: "jl_mint",
481
- docs: [
482
- "Jupiter Lend token mint for this asset"
483
- ]
484
- },
485
- {
486
- name: "jv_mint",
487
- docs: [
488
- "Vault share token mint (jvX) - STV is the mint authority",
489
- "Uses init_if_needed in case mint exists from a previous STV initialization"
490
- ],
491
- writable: true,
492
- signer: true
493
- },
494
- {
495
- name: "stv_jlx_ata",
496
- docs: [
497
- "STV's jlX ATA (holds Jupiter Lend tokens)",
498
- "Uses init_if_needed in case ATA exists from a previous STV initialization"
499
- ],
500
- writable: true,
501
- pda: {
502
- seeds: [
503
- {
504
- kind: "account",
505
- path: "stv"
506
- },
507
- {
508
- kind: "const",
509
- value: [
510
- 6,
511
- 221,
512
- 246,
513
- 225,
514
- 215,
515
- 101,
516
- 161,
517
- 147,
518
- 217,
519
- 203,
520
- 225,
521
- 70,
522
- 206,
523
- 235,
524
- 121,
525
- 172,
526
- 28,
527
- 180,
528
- 133,
529
- 237,
530
- 95,
531
- 91,
532
- 55,
533
- 145,
534
- 58,
535
- 140,
536
- 245,
537
- 133,
538
- 126,
539
- 255,
540
- 0,
541
- 169
542
- ]
543
- },
544
- {
545
- kind: "account",
546
- path: "jl_mint"
547
- }
548
- ],
549
- program: {
550
- kind: "const",
551
- value: [
552
- 140,
553
- 151,
554
- 37,
555
- 143,
556
- 78,
557
- 36,
558
- 137,
559
- 241,
560
- 187,
561
- 61,
562
- 16,
563
- 41,
564
- 20,
565
- 142,
566
- 13,
567
- 131,
568
- 11,
569
- 90,
570
- 19,
571
- 153,
572
- 218,
573
- 255,
574
- 16,
575
- 132,
576
- 4,
577
- 142,
578
- 123,
579
- 216,
580
- 219,
581
- 233,
582
- 248,
583
- 89
584
- ]
585
- }
586
- }
587
- },
588
- {
589
- name: "system_program",
590
- docs: [
591
- "System program"
592
- ],
593
- address: "11111111111111111111111111111111"
594
- },
595
- {
596
- name: "token_program",
597
- docs: [
598
- "Token program"
599
- ]
600
- },
601
- {
602
- name: "associated_token_program",
603
- docs: [
604
- "Associated token program"
605
- ],
606
- address: "ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL"
607
- },
608
- {
609
- name: "rent",
610
- docs: [
611
- "Rent sysvar"
612
- ],
613
- address: "SysvarRent111111111111111111111111111111111"
614
- }
615
- ],
616
- args: [
617
- {
618
- name: "params",
619
- type: {
620
- defined: {
621
- name: "InitializeStvParams"
622
- }
623
- }
624
- }
625
- ]
626
- },
627
- {
628
- name: "jup_earn_deposit_withdraw",
629
- docs: [
630
- "Deposit base to or withdraw from Jupiter Earn",
631
- "",
632
- "Manager-only operation to convert between base asset and jlX tokens",
633
- "via Jupiter Lend. This is used for pools that support Jupiter Earn",
634
- "(SOL, USDC) to earn yield on idle funds.",
635
- "",
636
- "# Directions",
637
- "- Deposit: Convert base asset -> jlX (earn Jupiter Earn yield)",
638
- "- Withdraw: Convert jlX -> base asset (provide withdrawal liquidity)",
639
- "",
640
- "# Use Cases",
641
- "- After user deposits, manager can deposit base to Jupiter Earn",
642
- "- Before user withdrawals, manager can withdraw from Jupiter Earn",
643
- "- BTC/ETH pools cannot use Jupiter Earn (not supported)",
644
- "",
645
- "# Remaining Accounts",
646
- "- Deposit: 17 Jupiter Lend accounts (see jup_lend::deposit_accounts)",
647
- "- Withdraw: 18 Jupiter Lend accounts (see jup_lend::withdraw_accounts)"
648
- ],
649
- discriminator: [
650
- 124,
651
- 60,
652
- 71,
653
- 122,
654
- 162,
655
- 212,
656
- 164,
657
- 191
658
- ],
659
- accounts: [
660
- {
661
- name: "manager",
662
- docs: [
663
- "Manager performing the operation"
664
- ],
665
- signer: true
666
- },
667
- {
668
- name: "jlp_vault",
669
- docs: [
670
- "The JLP Vault PDA account",
671
- "Note: PDA and manager verified in handler"
672
- ]
673
- },
674
- {
675
- name: "stv",
676
- docs: [
677
- "The STV PDA account",
678
- "Note: PDA verified in handler"
679
- ]
680
- },
681
- {
682
- name: "base_mint",
683
- docs: [
684
- "Using UncheckedAccount to avoid borrow conflicts with Jupiter Lend CPI"
685
- ]
686
- },
687
- {
688
- name: "jl_mint",
689
- docs: [
690
- "Using UncheckedAccount to avoid borrow conflicts with Jupiter Lend CPI"
691
- ],
692
- writable: true
693
- },
694
- {
695
- name: "stv_base_ata",
696
- docs: [
697
- "Using UncheckedAccount to avoid borrow conflicts with Jupiter Lend CPI"
698
- ],
699
- writable: true
700
- },
701
- {
702
- name: "stv_jlx_ata",
703
- docs: [
704
- "Using UncheckedAccount to avoid borrow conflicts with Jupiter Lend CPI"
705
- ],
706
- writable: true
707
- },
708
- {
709
- name: "token_program",
710
- docs: [
711
- "Token program - used to validate ATA ownership"
712
- ],
713
- address: "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA"
714
- }
715
- ],
716
- args: [
717
- {
718
- name: "params",
719
- type: {
720
- defined: {
721
- name: "JupEarnParams"
722
- }
723
- }
724
- }
725
- ]
726
- },
727
- {
728
- name: "move_stv_to_from_vault",
729
- docs: [
730
- "Move jlX tokens between STV and JLPVault staging ATA",
731
- "Direction::ToVault: STV jlX ATA -> Vault staging ATA (preparation for swap)",
732
- "Direction::FromVault: Vault staging ATA -> STV jlX ATA (return after swap/unwind)",
733
- "",
734
- "Remaining accounts (optional, for pools with Jupiter Earn):",
735
- "[0] = Jupiter Lend lending account (for exchange rate)",
736
- "[1] = Jupiter Lend rewards rate model (for exchange rate)",
737
- "",
738
- "For base-only pools (BTC, ETH where jl_mint == base_mint):",
739
- "No remaining accounts needed - uses 1.0 exchange rate"
740
- ],
741
- discriminator: [
742
- 60,
743
- 104,
744
- 8,
745
- 126,
746
- 254,
747
- 244,
748
- 95,
749
- 221
750
- ],
751
- accounts: [
752
- {
753
- name: "manager",
754
- docs: [
755
- "Manager performing the operation"
756
- ],
757
- signer: true
758
- },
759
- {
760
- name: "jlp_vault",
761
- docs: [
762
- "The JLP Vault PDA account",
763
- "Note: PDA and manager verified in handler via get_pda() to avoid multiple loads"
764
- ]
765
- },
766
- {
767
- name: "stv",
768
- docs: [
769
- "The STV PDA account (mutable to update base_loaned)",
770
- "Note: PDA verified in handler via get_pda() to avoid multiple loads"
771
- ],
772
- writable: true
773
- },
774
- {
775
- name: "base_mint",
776
- docs: [
777
- "Base asset mint (for detection of base-only pools)"
778
- ]
779
- },
780
- {
781
- name: "jl_mint",
782
- docs: [
783
- "jlX mint (for decimals in transfer_checked)",
784
- "For base-only pools (BTC, ETH), jl_mint == base_mint"
785
- ]
786
- },
787
- {
788
- name: "stv_jlx_ata",
789
- docs: [
790
- "STV's jlX ATA",
791
- "For base-only pools, this is the base ATA (jl_mint == base_mint)"
792
- ],
793
- writable: true
794
- },
795
- {
796
- name: "vault_staging_ata",
797
- docs: [
798
- "Vault's staging jlX ATA (for this specific jl_mint)",
799
- "For base-only pools, this is the staging base ATA"
800
- ],
801
- writable: true
802
- },
803
- {
804
- name: "token_program",
805
- docs: [
806
- "Token program"
807
- ]
808
- }
809
- ],
810
- args: [
811
- {
812
- name: "params",
813
- type: {
814
- defined: {
815
- name: "MoveJlxParams"
816
- }
817
- }
818
- }
819
- ]
820
- },
821
- {
822
- name: "process_epoch",
823
- docs: [
824
- "Process epoch: burn jvX from withdraw requests, record PPS, earmark base",
825
- "",
826
- "Permissionless (anyone can call after epoch ends).",
827
- "Processes WithdrawRequest pairs from remaining_accounts.",
828
- "Uses epoch_pps for multi-batch consistency.",
829
- "",
830
- "# Remaining Accounts",
831
- "- [0-1]: Jupiter Lend accounts (if jl_mint != base_mint)",
832
- "- [N..]: pairs of [WithdrawRequest (mut), request_jvx_ata (mut)]"
833
- ],
834
- discriminator: [
835
- 115,
836
- 194,
837
- 215,
838
- 160,
839
- 113,
840
- 154,
841
- 81,
842
- 5
843
- ],
844
- accounts: [
845
- {
846
- name: "payer",
847
- docs: [
848
- "Payer/caller - permissionless (anyone can call after epoch ends)"
849
- ],
850
- writable: true,
851
- signer: true
852
- },
853
- {
854
- name: "jlp_vault",
855
- docs: [
856
- "The JLP Vault PDA account (for pause checks)"
857
- ]
858
- },
859
- {
860
- name: "stv",
861
- docs: [
862
- "The STV PDA account (mut for epoch state + fee crystallization)"
863
- ],
864
- writable: true
865
- },
866
- {
867
- name: "base_mint",
868
- docs: [
869
- "Base asset mint (for NAV calc)"
870
- ]
871
- },
872
- {
873
- name: "jl_mint",
874
- docs: [
875
- "jlX mint (for exchange rate)"
876
- ]
877
- },
878
- {
879
- name: "jv_mint",
880
- docs: [
881
- "jvX mint (mut for burn - supply decreases)"
882
- ],
883
- writable: true
884
- },
885
- {
886
- name: "stv_base_ata",
887
- docs: [
888
- "STV's base ATA (for NAV)"
889
- ]
890
- },
891
- {
892
- name: "stv_jlx_ata",
893
- docs: [
894
- "STV's jlX ATA (for NAV)"
895
- ]
896
- },
897
- {
898
- name: "token_program"
899
- }
900
- ],
901
- args: []
902
- },
903
- {
904
- name: "request_withdraw",
905
- docs: [
906
- "Request withdrawal of jvX shares (epoch-based delayed withdrawal)",
907
- "",
908
- "# Flow",
909
- "1. Validate epoch is active and not ended",
910
- "2. Create or accumulate into WithdrawRequest PDA for this epoch",
911
- "3. Transfer jvX from user to request's escrow ATA",
912
- "",
913
- "User must wait for process_epoch + claim_withdraw to receive base."
914
- ],
915
- discriminator: [
916
- 137,
917
- 95,
918
- 187,
919
- 96,
920
- 250,
921
- 138,
922
- 31,
923
- 182
924
- ],
925
- accounts: [
926
- {
927
- name: "user",
928
- docs: [
929
- "User requesting withdrawal"
930
- ],
931
- writable: true,
932
- signer: true
933
- },
934
- {
935
- name: "jlp_vault",
936
- docs: [
937
- "The JLP Vault PDA account (for pause checks)"
938
- ]
939
- },
940
- {
941
- name: "stv",
942
- docs: [
943
- "The STV PDA account (for epoch validation)"
944
- ],
945
- writable: true
946
- },
947
- {
948
- name: "jv_mint",
949
- docs: [
950
- "jvX mint (vault share token)"
951
- ]
952
- },
953
- {
954
- name: "user_jvx_ata",
955
- docs: [
956
- "User's jvX token account (source of shares)"
957
- ],
958
- writable: true
959
- },
960
- {
961
- name: "withdraw_request",
962
- docs: [
963
- "WithdrawRequest PDA - created or accumulated into"
964
- ],
965
- writable: true,
966
- pda: {
967
- seeds: [
968
- {
969
- kind: "const",
970
- value: [
971
- 119,
972
- 105,
973
- 116,
974
- 104,
975
- 100,
976
- 114,
977
- 97,
978
- 119,
979
- 95,
980
- 114,
981
- 101,
982
- 113,
983
- 117,
984
- 101,
985
- 115,
986
- 116
987
- ]
988
- },
989
- {
990
- kind: "account",
991
- path: "stv"
992
- },
993
- {
994
- kind: "account",
995
- path: "user"
996
- },
997
- {
998
- kind: "arg",
999
- path: "epoch_id"
1000
- }
1001
- ]
1002
- }
1003
- },
1004
- {
1005
- name: "request_jvx_ata",
1006
- docs: [
1007
- "jvX ATA owned by the WithdrawRequest PDA (escrow for shares)"
1008
- ],
1009
- writable: true,
1010
- pda: {
1011
- seeds: [
1012
- {
1013
- kind: "account",
1014
- path: "withdraw_request"
1015
- },
1016
- {
1017
- kind: "const",
1018
- value: [
1019
- 6,
1020
- 221,
1021
- 246,
1022
- 225,
1023
- 215,
1024
- 101,
1025
- 161,
1026
- 147,
1027
- 217,
1028
- 203,
1029
- 225,
1030
- 70,
1031
- 206,
1032
- 235,
1033
- 121,
1034
- 172,
1035
- 28,
1036
- 180,
1037
- 133,
1038
- 237,
1039
- 95,
1040
- 91,
1041
- 55,
1042
- 145,
1043
- 58,
1044
- 140,
1045
- 245,
1046
- 133,
1047
- 126,
1048
- 255,
1049
- 0,
1050
- 169
1051
- ]
1052
- },
1053
- {
1054
- kind: "account",
1055
- path: "jv_mint"
1056
- }
1057
- ],
1058
- program: {
1059
- kind: "const",
1060
- value: [
1061
- 140,
1062
- 151,
1063
- 37,
1064
- 143,
1065
- 78,
1066
- 36,
1067
- 137,
1068
- 241,
1069
- 187,
1070
- 61,
1071
- 16,
1072
- 41,
1073
- 20,
1074
- 142,
1075
- 13,
1076
- 131,
1077
- 11,
1078
- 90,
1079
- 19,
1080
- 153,
1081
- 218,
1082
- 255,
1083
- 16,
1084
- 132,
1085
- 4,
1086
- 142,
1087
- 123,
1088
- 216,
1089
- 219,
1090
- 233,
1091
- 248,
1092
- 89
1093
- ]
1094
- }
1095
- }
1096
- },
1097
- {
1098
- name: "token_program"
1099
- },
1100
- {
1101
- name: "associated_token_program",
1102
- address: "ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL"
1103
- },
1104
- {
1105
- name: "system_program",
1106
- address: "11111111111111111111111111111111"
1107
- }
1108
- ],
1109
- args: [
1110
- {
1111
- name: "shares",
1112
- type: "u64"
1113
- },
1114
- {
1115
- name: "epoch_id",
1116
- type: "u32"
1117
- }
1118
- ]
1119
- },
1120
- {
1121
- name: "settle_yield",
1122
- docs: [
1123
- "Settle yield/loss from JLP positions across all STVs",
1124
- "Called periodically (~8 hours) to update all STV values based on JLP performance",
1125
- "",
1126
- "# USD-Based Settlement",
1127
- "1. Values total vault holdings (JLP + staging jlX) in USD using oracles",
1128
- "2. Values total base_loaned across all STVs in USD",
1129
- "3. Distributes surplus (yield) or deficit (bad debt) proportionally",
1130
- "",
1131
- "# Security",
1132
- "- BTC/ETH/SOL prices come from Doves oracles (manipulation-resistant)",
1133
- "- JLP price computed directly from Jupiter Perps Pool account (aumUsd / jlp_supply)",
1134
- "- Exchange rates come from Jupiter Earn (audited, TWAP-based)",
1135
- "- Distribution is proportional to each STV's share of total loans",
1136
- "",
1137
- "# Accounts",
1138
- "Requires all 5 STVs, 5 staging jlX ATAs, 3 Doves oracles (BTC/ETH/SOL),",
1139
- "Jupiter Perps Pool account, JLP mint account",
1140
- "",
1141
- "# Remaining Accounts (15 accounts)",
1142
- "For exchange rate calculation with time-accrued rewards:",
1143
- "- [0-4]: Jupiter Lend lending accounts (BTC, ETH, SOL, USDC, JupUSD)",
1144
- "- [5-9]: Jupiter Lend rewards rate model accounts (BTC, ETH, SOL, USDC, JupUSD)",
1145
- "- [10-14]: jlX mint accounts (jlBTC, jlETH, jlSOL, jlUSDC, jlJupUSD)"
1146
- ],
1147
- discriminator: [
1148
- 64,
1149
- 28,
1150
- 44,
1151
- 24,
1152
- 43,
1153
- 204,
1154
- 58,
1155
- 215
1156
- ],
1157
- accounts: [
1158
- {
1159
- name: "jlp_vault",
1160
- writable: true
1161
- },
1162
- {
1163
- name: "vault_jlp_ata",
1164
- docs: [
1165
- "JLP token account owned by vault"
1166
- ]
1167
- },
1168
- {
1169
- name: "stv_0",
1170
- writable: true
1171
- },
1172
- {
1173
- name: "stv_1",
1174
- writable: true
1175
- },
1176
- {
1177
- name: "stv_2",
1178
- writable: true
1179
- },
1180
- {
1181
- name: "stv_3",
1182
- writable: true
1183
- },
1184
- {
1185
- name: "stv_4",
1186
- writable: true
1187
- },
1188
- {
1189
- name: "staging_jlx_0"
1190
- },
1191
- {
1192
- name: "staging_jlx_1"
1193
- },
1194
- {
1195
- name: "staging_jlx_2"
1196
- },
1197
- {
1198
- name: "staging_jlx_3"
1199
- },
1200
- {
1201
- name: "staging_jlx_4"
1202
- },
1203
- {
1204
- name: "doves_btc_usd"
1205
- },
1206
- {
1207
- name: "doves_eth_usd"
1208
- },
1209
- {
1210
- name: "doves_sol_usd"
1211
- },
1212
- {
1213
- name: "jlp_pool"
1214
- },
1215
- {
1216
- name: "jlp_mint_account"
1217
- },
1218
- {
1219
- name: "manager",
1220
- docs: [
1221
- "Manager who can perform rebalance operations (verified in handler)"
1222
- ],
1223
- signer: true
1224
- }
1225
- ],
1226
- args: []
1227
- },
1228
- {
1229
- name: "swap_jlx_to_from_jlp",
1230
- docs: [
1231
- "Swap between different jlX types (e.g., jlSOL -> jlUSDC) via Jupiter",
1232
- "Manager-only operation for rebalancing vault composition",
1233
- "",
1234
- "Remaining accounts: Jupiter swap accounts from API (varies based on route)",
1235
- "Swap between jlX and JLP tokens via Jupiter",
1236
- "JlxToJlp: Swap jlX -> JLP (increase vault JLP balance)",
1237
- "JlpToJlx: Swap JLP -> jlX (decrease vault JLP balance)",
1238
- "Manager-only operation for JLP position management",
1239
- "",
1240
- "Note: JLP positions are tracked via STV.base_loaned and settled",
1241
- "using settle_yield with Doves oracle prices (USD-based settlement).",
1242
- "",
1243
- "Remaining accounts: Jupiter swap accounts from API (varies based on route)"
1244
- ],
1245
- discriminator: [
1246
- 229,
1247
- 185,
1248
- 136,
1249
- 170,
1250
- 210,
1251
- 189,
1252
- 172,
1253
- 241
1254
- ],
1255
- accounts: [
1256
- {
1257
- name: "manager",
1258
- docs: [
1259
- "Manager performing the swap"
1260
- ],
1261
- signer: true
1262
- },
1263
- {
1264
- name: "jlp_vault",
1265
- docs: [
1266
- "The JLP Vault PDA account",
1267
- "Note: PDA and manager verified in handler via get_pda() to avoid multiple loads"
1268
- ]
1269
- },
1270
- {
1271
- name: "vault_jlx_ata",
1272
- docs: [
1273
- "Vault's staging jlX ATA (source for JlxToJlp, dest for JlpToJlx)",
1274
- "This is the jlX token that corresponds to stv_index"
1275
- ],
1276
- writable: true
1277
- },
1278
- {
1279
- name: "vault_jlp_ata",
1280
- docs: [
1281
- "Vault's JLP ATA (dest for JlxToJlp, source for JlpToJlx)"
1282
- ],
1283
- writable: true
1284
- },
1285
- {
1286
- name: "jlp_mint",
1287
- docs: [
1288
- "JLP mint"
1289
- ]
1290
- },
1291
- {
1292
- name: "token_program",
1293
- docs: [
1294
- "Token program"
1295
- ]
1296
- },
1297
- {
1298
- name: "jupiter_program",
1299
- docs: [
1300
- "Jupiter aggregator program"
1301
- ]
1302
- }
1303
- ],
1304
- args: [
1305
- {
1306
- name: "params",
1307
- type: {
1308
- defined: {
1309
- name: "SwapJlxJlpParams"
1310
- }
1311
- }
1312
- }
1313
- ]
1314
- },
1315
- {
1316
- name: "update_stv",
1317
- docs: [
1318
- "Update STV parameters including fees and flags",
1319
- "Admin-only operation to modify STV configuration"
1320
- ],
1321
- discriminator: [
1322
- 72,
1323
- 173,
1324
- 200,
1325
- 203,
1326
- 74,
1327
- 83,
1328
- 242,
1329
- 43
1330
- ],
1331
- accounts: [
1332
- {
1333
- name: "admin",
1334
- docs: [
1335
- "Admin of the JLP Vault"
1336
- ],
1337
- writable: true,
1338
- signer: true
1339
- },
1340
- {
1341
- name: "jlp_vault",
1342
- docs: [
1343
- "The JLP Vault PDA account",
1344
- "Note: PDA and admin verified in handler via get_pda() to avoid multiple loads"
1345
- ]
1346
- },
1347
- {
1348
- name: "stv",
1349
- docs: [
1350
- "The STV PDA account to update",
1351
- "Note: PDA verified in handler via get_pda() to avoid multiple loads"
1352
- ],
1353
- writable: true
1354
- }
1355
- ],
1356
- args: [
1357
- {
1358
- name: "params",
1359
- type: {
1360
- defined: {
1361
- name: "UpdateStvParams"
1362
- }
1363
- }
1364
- }
1365
- ]
1366
- }
1367
- ],
1368
- accounts: [
1369
- {
1370
- name: "JLPVault",
1371
- discriminator: [
1372
- 41,
1373
- 108,
1374
- 189,
1375
- 168,
1376
- 199,
1377
- 152,
1378
- 221,
1379
- 119
1380
- ]
1381
- },
1382
- {
1383
- name: "STV",
1384
- discriminator: [
1385
- 214,
1386
- 2,
1387
- 96,
1388
- 41,
1389
- 85,
1390
- 163,
1391
- 17,
1392
- 230
1393
- ]
1394
- },
1395
- {
1396
- name: "WithdrawRequest",
1397
- discriminator: [
1398
- 186,
1399
- 239,
1400
- 174,
1401
- 191,
1402
- 189,
1403
- 13,
1404
- 47,
1405
- 196
1406
- ]
1407
- }
1408
- ],
1409
- events: [
1410
- {
1411
- name: "Deposited",
1412
- discriminator: [
1413
- 111,
1414
- 141,
1415
- 26,
1416
- 45,
1417
- 161,
1418
- 35,
1419
- 100,
1420
- 57
1421
- ]
1422
- },
1423
- {
1424
- name: "EpochAdvanced",
1425
- discriminator: [
1426
- 41,
1427
- 220,
1428
- 14,
1429
- 123,
1430
- 117,
1431
- 70,
1432
- 117,
1433
- 157
1434
- ]
1435
- },
1436
- {
1437
- name: "EpochProcessed",
1438
- discriminator: [
1439
- 18,
1440
- 238,
1441
- 2,
1442
- 247,
1443
- 238,
1444
- 178,
1445
- 94,
1446
- 138
1447
- ]
1448
- },
1449
- {
1450
- name: "FeesClaimSkipped",
1451
- discriminator: [
1452
- 7,
1453
- 214,
1454
- 20,
1455
- 27,
1456
- 90,
1457
- 132,
1458
- 198,
1459
- 77
1460
- ]
1461
- },
1462
- {
1463
- name: "FeesClaimed",
1464
- discriminator: [
1465
- 22,
1466
- 104,
1467
- 110,
1468
- 222,
1469
- 38,
1470
- 157,
1471
- 14,
1472
- 62
1473
- ]
1474
- },
1475
- {
1476
- name: "JlpSwapped",
1477
- discriminator: [
1478
- 253,
1479
- 47,
1480
- 169,
1481
- 18,
1482
- 222,
1483
- 203,
1484
- 169,
1485
- 15
1486
- ]
1487
- },
1488
- {
1489
- name: "JlpVaultInitialized",
1490
- discriminator: [
1491
- 52,
1492
- 94,
1493
- 202,
1494
- 211,
1495
- 2,
1496
- 98,
1497
- 77,
1498
- 229
1499
- ]
1500
- },
1501
- {
1502
- name: "JlpVaultUpdated",
1503
- discriminator: [
1504
- 20,
1505
- 204,
1506
- 5,
1507
- 243,
1508
- 122,
1509
- 9,
1510
- 109,
1511
- 130
1512
- ]
1513
- },
1514
- {
1515
- name: "JlxMoved",
1516
- discriminator: [
1517
- 251,
1518
- 80,
1519
- 253,
1520
- 180,
1521
- 106,
1522
- 69,
1523
- 129,
1524
- 70
1525
- ]
1526
- },
1527
- {
1528
- name: "JlxSwapped",
1529
- discriminator: [
1530
- 200,
1531
- 218,
1532
- 196,
1533
- 94,
1534
- 186,
1535
- 141,
1536
- 86,
1537
- 223
1538
- ]
1539
- },
1540
- {
1541
- name: "JupEarnEvent",
1542
- discriminator: [
1543
- 138,
1544
- 10,
1545
- 64,
1546
- 209,
1547
- 244,
1548
- 49,
1549
- 1,
1550
- 188
1551
- ]
1552
- },
1553
- {
1554
- name: "SettleYieldEvent",
1555
- discriminator: [
1556
- 208,
1557
- 142,
1558
- 20,
1559
- 32,
1560
- 204,
1561
- 216,
1562
- 242,
1563
- 189
1564
- ]
1565
- },
1566
- {
1567
- name: "SettleYieldSkipped",
1568
- discriminator: [
1569
- 189,
1570
- 221,
1571
- 140,
1572
- 115,
1573
- 37,
1574
- 102,
1575
- 42,
1576
- 195
1577
- ]
1578
- },
1579
- {
1580
- name: "SettleYieldStvEvent",
1581
- discriminator: [
1582
- 12,
1583
- 42,
1584
- 226,
1585
- 95,
1586
- 60,
1587
- 95,
1588
- 192,
1589
- 238
1590
- ]
1591
- },
1592
- {
1593
- name: "StvInitialized",
1594
- discriminator: [
1595
- 41,
1596
- 106,
1597
- 196,
1598
- 230,
1599
- 138,
1600
- 22,
1601
- 195,
1602
- 188
1603
- ]
1604
- },
1605
- {
1606
- name: "StvUpdated",
1607
- discriminator: [
1608
- 108,
1609
- 129,
1610
- 139,
1611
- 80,
1612
- 212,
1613
- 111,
1614
- 83,
1615
- 199
1616
- ]
1617
- },
1618
- {
1619
- name: "WithdrawClaimed",
1620
- discriminator: [
1621
- 77,
1622
- 130,
1623
- 89,
1624
- 38,
1625
- 239,
1626
- 172,
1627
- 174,
1628
- 85
1629
- ]
1630
- },
1631
- {
1632
- name: "WithdrawRequested",
1633
- discriminator: [
1634
- 114,
1635
- 16,
1636
- 240,
1637
- 206,
1638
- 93,
1639
- 128,
1640
- 151,
1641
- 39
1642
- ]
1643
- }
1644
- ],
1645
- errors: [
1646
- {
1647
- code: 6e3,
1648
- name: "Unauthorized",
1649
- msg: "Unauthorized: not admin"
1650
- },
1651
- {
1652
- code: 6001,
1653
- name: "NotManager",
1654
- msg: "Unauthorized: not manager"
1655
- },
1656
- {
1657
- code: 6002,
1658
- name: "VaultPaused",
1659
- msg: "Vault is paused"
1660
- },
1661
- {
1662
- code: 6003,
1663
- name: "DepositsDisabled",
1664
- msg: "Deposits disabled"
1665
- },
1666
- {
1667
- code: 6004,
1668
- name: "WithdrawalsDisabled",
1669
- msg: "Withdrawals disabled"
1670
- },
1671
- {
1672
- code: 6005,
1673
- name: "JlpDisabled",
1674
- msg: "JLP operations disabled"
1675
- },
1676
- {
1677
- code: 6006,
1678
- name: "RebalanceDisabled",
1679
- msg: "Rebalance operations disabled"
1680
- },
1681
- {
1682
- code: 6007,
1683
- name: "MathOverflow",
1684
- msg: "Math overflow"
1685
- },
1686
- {
1687
- code: 6008,
1688
- name: "InvalidTimestamp",
1689
- msg: "Invalid timestamp"
1690
- },
1691
- {
1692
- code: 6009,
1693
- name: "DivisionByZero",
1694
- msg: "Division by zero"
1695
- },
1696
- {
1697
- code: 6010,
1698
- name: "StagingNotZero",
1699
- msg: "Staging ATAs must be zero"
1700
- },
1701
- {
1702
- code: 6011,
1703
- name: "InsufficientLiquidity",
1704
- msg: "Insufficient liquidity for withdrawal"
1705
- },
1706
- {
1707
- code: 6012,
1708
- name: "InsufficientBalance",
1709
- msg: "Insufficient balance"
1710
- },
1711
- {
1712
- code: 6013,
1713
- name: "SlippageExceeded",
1714
- msg: "Slippage exceeded"
1715
- },
1716
- {
1717
- code: 6014,
1718
- name: "InvalidJlpVaultBump",
1719
- msg: "Invalid JLP vault PDA bump"
1720
- },
1721
- {
1722
- code: 6015,
1723
- name: "InvalidStvBump",
1724
- msg: "Invalid STV PDA bump"
1725
- },
1726
- {
1727
- code: 6016,
1728
- name: "InvalidJlMint",
1729
- msg: "Invalid jlX mint (Jupiter Lend token)"
1730
- },
1731
- {
1732
- code: 6017,
1733
- name: "InvalidJvMint",
1734
- msg: "Invalid jvX mint (vault share token)"
1735
- },
1736
- {
1737
- code: 6018,
1738
- name: "InvalidBaseMint",
1739
- msg: "Invalid base asset mint"
1740
- },
1741
- {
1742
- code: 6019,
1743
- name: "InvalidJlpMint",
1744
- msg: "Invalid JLP mint"
1745
- },
1746
- {
1747
- code: 6020,
1748
- name: "InvalidOwner",
1749
- msg: "Invalid account owner"
1750
- },
1751
- {
1752
- code: 6021,
1753
- name: "InvalidStvIndex",
1754
- msg: "Invalid STV index"
1755
- },
1756
- {
1757
- code: 6022,
1758
- name: "InvalidFeeParams",
1759
- msg: "Invalid fee parameters"
1760
- },
1761
- {
1762
- code: 6023,
1763
- name: "AmountTooSmall",
1764
- msg: "Amount too small"
1765
- },
1766
- {
1767
- code: 6024,
1768
- name: "ZeroAmount",
1769
- msg: "Zero amount not allowed"
1770
- },
1771
- {
1772
- code: 6025,
1773
- name: "FeeCapExceeded",
1774
- msg: "Fee cap exceeded"
1775
- },
1776
- {
1777
- code: 6026,
1778
- name: "MintMismatch",
1779
- msg: "Mint mismatch"
1780
- },
1781
- {
1782
- code: 6027,
1783
- name: "InsufficientAccounts",
1784
- msg: "Insufficient accounts provided"
1785
- },
1786
- {
1787
- code: 6028,
1788
- name: "InvalidProgram",
1789
- msg: "Invalid program ID"
1790
- },
1791
- {
1792
- code: 6029,
1793
- name: "InvalidSwapDiscriminator",
1794
- msg: "Invalid swap discriminator"
1795
- },
1796
- {
1797
- code: 6030,
1798
- name: "MaxDepositExceeded",
1799
- msg: "Deposit exceeds maximum allowed"
1800
- },
1801
- {
1802
- code: 6031,
1803
- name: "InvalidLendingAccount",
1804
- msg: "Invalid Jupiter Lend lending account"
1805
- },
1806
- {
1807
- code: 6032,
1808
- name: "MissingExchangeRateAccounts",
1809
- msg: "Missing exchange rate accounts - lending and rewards_rate_model required for pools with Jupiter Earn"
1810
- },
1811
- {
1812
- code: 6033,
1813
- name: "JupiterLendCpiFailed",
1814
- msg: "Jupiter Lend CPI failed"
1815
- },
1816
- {
1817
- code: 6034,
1818
- name: "JupiterSwapCpiFailed",
1819
- msg: "Jupiter swap CPI failed"
1820
- },
1821
- {
1822
- code: 6035,
1823
- name: "OracleStale",
1824
- msg: "Oracle price is stale - older than staleness threshold"
1825
- },
1826
- {
1827
- code: 6036,
1828
- name: "OraclePriceNegative",
1829
- msg: "Oracle returned negative price"
1830
- },
1831
- {
1832
- code: 6037,
1833
- name: "InvalidBaseAssetIndex",
1834
- msg: "Invalid base asset index"
1835
- },
1836
- {
1837
- code: 6038,
1838
- name: "PriceFeedMismatch",
1839
- msg: "Price feed mismatch"
1840
- },
1841
- {
1842
- code: 6039,
1843
- name: "OracleAccountInvalid",
1844
- msg: "Oracle account invalid"
1845
- },
1846
- {
1847
- code: 6040,
1848
- name: "InvalidAccountData",
1849
- msg: "Invalid account data - could not parse account"
1850
- },
1851
- {
1852
- code: 6041,
1853
- name: "InvalidExchangeRate",
1854
- msg: "Invalid exchange rate from Jupiter Lend"
1855
- },
1856
- {
1857
- code: 6042,
1858
- name: "InvalidOracleAccount",
1859
- msg: "Invalid oracle account - not owned by expected program"
1860
- },
1861
- {
1862
- code: 6043,
1863
- name: "JlpPriceOutOfRange",
1864
- msg: "JLP price out of reasonable range ($0.50 - $50.00)"
1865
- },
1866
- {
1867
- code: 6044,
1868
- name: "TestModeRequired",
1869
- msg: "Test mode required: FLAG_TEST_MODE must be set for devnet/localnet builds"
1870
- },
1871
- {
1872
- code: 6045,
1873
- name: "NotAdmin",
1874
- msg: "Unauthorized: not admin"
1875
- },
1876
- {
1877
- code: 6046,
1878
- name: "TokenAccountNotEmpty",
1879
- msg: "Token account balance must be zero before closing"
1880
- },
1881
- {
1882
- code: 6047,
1883
- name: "TokenAccountOwnerMismatch",
1884
- msg: "Token account not owned by expected PDA"
1885
- },
1886
- {
1887
- code: 6048,
1888
- name: "EpochEnded",
1889
- msg: "Epoch has ended - call process_epoch first"
1890
- },
1891
- {
1892
- code: 6049,
1893
- name: "EpochNotEnded",
1894
- msg: "Epoch has not ended yet"
1895
- },
1896
- {
1897
- code: 6050,
1898
- name: "ClaimNotAvailableYet",
1899
- msg: "Claim not available yet - wait for next epoch"
1900
- },
1901
- {
1902
- code: 6051,
1903
- name: "InvalidEpochInterval",
1904
- msg: "Withdraw epoch interval must be > 0"
1905
- },
1906
- {
1907
- code: 6052,
1908
- name: "ActiveWithdrawReserves",
1909
- msg: "Cannot update epoch interval with active reserves"
1910
- },
1911
- {
1912
- code: 6053,
1913
- name: "EpochIdMismatch",
1914
- msg: "Epoch ID mismatch"
1915
- },
1916
- {
1917
- code: 6054,
1918
- name: "WithdrawRequestNotProcessed",
1919
- msg: "Withdraw request not processed yet"
1920
- },
1921
- {
1922
- code: 6055,
1923
- name: "WithdrawRequestAlreadyProcessed",
1924
- msg: "Withdraw request already processed"
1925
- }
1926
- ],
1927
- types: [
1928
- {
1929
- name: "Deposited",
1930
- type: {
1931
- kind: "struct",
1932
- fields: [
1933
- {
1934
- name: "stv",
1935
- type: "pubkey"
1936
- },
1937
- {
1938
- name: "user",
1939
- type: "pubkey"
1940
- },
1941
- {
1942
- name: "amount_base",
1943
- docs: [
1944
- "Amount of base asset deposited"
1945
- ],
1946
- type: "u64"
1947
- },
1948
- {
1949
- name: "shares_minted",
1950
- type: "u64"
1951
- },
1952
- {
1953
- name: "pps",
1954
- type: "u64"
1955
- }
1956
- ]
1957
- }
1958
- },
1959
- {
1960
- name: "Direction",
1961
- docs: [
1962
- "Direction of jlX token movement between STV and Vault"
1963
- ],
1964
- type: {
1965
- kind: "enum",
1966
- variants: [
1967
- {
1968
- name: "ToVault"
1969
- },
1970
- {
1971
- name: "FromVault"
1972
- }
1973
- ]
1974
- }
1975
- },
1976
- {
1977
- name: "EpochAdvanced",
1978
- type: {
1979
- kind: "struct",
1980
- fields: [
1981
- {
1982
- name: "stv",
1983
- type: "pubkey"
1984
- },
1985
- {
1986
- name: "new_epoch_id",
1987
- type: "u32"
1988
- },
1989
- {
1990
- name: "new_next_epoch_ts",
1991
- type: "u32"
1992
- }
1993
- ]
1994
- }
1995
- },
1996
- {
1997
- name: "EpochProcessed",
1998
- type: {
1999
- kind: "struct",
2000
- fields: [
2001
- {
2002
- name: "stv",
2003
- type: "pubkey"
2004
- },
2005
- {
2006
- name: "epoch_id",
2007
- type: "u32"
2008
- },
2009
- {
2010
- name: "pps",
2011
- type: "u64"
2012
- },
2013
- {
2014
- name: "total_shares",
2015
- type: "u64"
2016
- },
2017
- {
2018
- name: "total_base",
2019
- type: "u64"
2020
- },
2021
- {
2022
- name: "new_epoch_id",
2023
- type: "u32"
2024
- },
2025
- {
2026
- name: "new_next_epoch_ts",
2027
- type: "u32"
2028
- }
2029
- ]
2030
- }
2031
- },
2032
- {
2033
- name: "FeesClaimSkipped",
2034
- docs: [
2035
- "Event emitted when claim_fees returns early (no fees to claim)"
2036
- ],
2037
- type: {
2038
- kind: "struct",
2039
- fields: [
2040
- {
2041
- name: "stv",
2042
- docs: [
2043
- "The STV account"
2044
- ],
2045
- type: "pubkey"
2046
- },
2047
- {
2048
- name: "reason",
2049
- docs: [
2050
- 'Reason for skipping: "NoFeesToClaim"'
2051
- ],
2052
- type: "string"
2053
- }
2054
- ]
2055
- }
2056
- },
2057
- {
2058
- name: "FeesClaimed",
2059
- docs: [
2060
- "Fee claim event - when manager claims accrued fees"
2061
- ],
2062
- type: {
2063
- kind: "struct",
2064
- fields: [
2065
- {
2066
- name: "stv",
2067
- type: "pubkey"
2068
- },
2069
- {
2070
- name: "amount_jlx",
2071
- docs: [
2072
- "Total jlX claimed by fee receiver"
2073
- ],
2074
- type: "u64"
2075
- },
2076
- {
2077
- name: "fee_receiver",
2078
- docs: [
2079
- "Fee receiver who received the fees"
2080
- ],
2081
- type: "pubkey"
2082
- }
2083
- ]
2084
- }
2085
- },
2086
- {
2087
- name: "InitOrUpdateJlpVaultParams",
2088
- docs: [
2089
- "Parameters for initializing or updating the JLP Vault"
2090
- ],
2091
- type: {
2092
- kind: "struct",
2093
- fields: [
2094
- {
2095
- name: "jlp_mint",
2096
- docs: [
2097
- "JLP token mint - required for init, ignored on update"
2098
- ],
2099
- type: {
2100
- option: "pubkey"
2101
- }
2102
- },
2103
- {
2104
- name: "base_asset_mints",
2105
- docs: [
2106
- "Base asset token mints [BTC, ETH, SOL, USDC, JupUSD] - required for init, ignored on update"
2107
- ],
2108
- type: {
2109
- option: {
2110
- array: [
2111
- "pubkey",
2112
- 5
2113
- ]
2114
- }
2115
- }
2116
- },
2117
- {
2118
- name: "jlx_asset_mints",
2119
- docs: [
2120
- "jlX token mints [jlBTC, jlETH, jlSOL, jlUSDC, jlJupUSD] - required for init, ignored on update"
2121
- ],
2122
- type: {
2123
- option: {
2124
- array: [
2125
- "pubkey",
2126
- 5
2127
- ]
2128
- }
2129
- }
2130
- },
2131
- {
2132
- name: "new_admin",
2133
- docs: [
2134
- "New admin address - if Some, transfers admin ownership (only current admin can do this)"
2135
- ],
2136
- type: {
2137
- option: "pubkey"
2138
- }
2139
- },
2140
- {
2141
- name: "manager",
2142
- docs: [
2143
- "Manager address (can perform rebalance operations)"
2144
- ],
2145
- type: "pubkey"
2146
- },
2147
- {
2148
- name: "fee_receiver",
2149
- docs: [
2150
- "Fee receiver address"
2151
- ],
2152
- type: "pubkey"
2153
- },
2154
- {
2155
- name: "flags",
2156
- docs: [
2157
- "Vault flags (paused, deposits disabled, etc.)"
2158
- ],
2159
- type: "u16"
2160
- },
2161
- {
2162
- name: "jlp_slippage_bps",
2163
- docs: [
2164
- "JLP swap slippage tolerance in basis points (e.g., 100 = 1%)"
2165
- ],
2166
- type: "u16"
2167
- },
2168
- {
2169
- name: "oracle_staleness_threshold",
2170
- docs: [
2171
- "Maximum age in seconds for Doves oracle prices to be considered valid.",
2172
- "On init: defaults to 60 seconds if None.",
2173
- "On update: if None, keeps existing value; if Some, updates to new value."
2174
- ],
2175
- type: {
2176
- option: "u64"
2177
- }
2178
- }
2179
- ]
2180
- }
2181
- },
2182
- {
2183
- name: "InitializeStvParams",
2184
- docs: [
2185
- "Parameters for initializing an STV"
2186
- ],
2187
- type: {
2188
- kind: "struct",
2189
- fields: [
2190
- {
2191
- name: "mgmt_fee_bps",
2192
- docs: [
2193
- "Management fee in basis points (annual)"
2194
- ],
2195
- type: "u16"
2196
- },
2197
- {
2198
- name: "perf_fee_bps",
2199
- docs: [
2200
- "Performance fee in basis points"
2201
- ],
2202
- type: "u16"
2203
- },
2204
- {
2205
- name: "max_deposit",
2206
- docs: [
2207
- "Maximum deposit amount in base asset (0 = unlimited)"
2208
- ],
2209
- type: "u64"
2210
- },
2211
- {
2212
- name: "min_deposit",
2213
- docs: [
2214
- "Minimum deposit amount in base asset (0 = no minimum)"
2215
- ],
2216
- type: "u64"
2217
- },
2218
- {
2219
- name: "epoch_sec",
2220
- docs: [
2221
- "Epoch duration in seconds for delayed withdrawals"
2222
- ],
2223
- type: "u32"
2224
- }
2225
- ]
2226
- }
2227
- },
2228
- {
2229
- name: "JLPVault",
2230
- docs: [
2231
- "JLPVault - Global vault configuration account",
2232
- 'Seeds: ["jlp_vault"]',
2233
- "Size: 8 (discriminator) + 464 (data) = 472 bytes",
2234
- "",
2235
- "## USD-Based Settlement Model",
2236
- "This vault uses USD-based settlement where JLP positions are tracked via",
2237
- "each STV's `base_loaned` field. Yield is settled by marking `base_loaned`",
2238
- "to market using Doves oracle prices."
2239
- ],
2240
- serialization: "bytemuck",
2241
- repr: {
2242
- kind: "c"
2243
- },
2244
- type: {
2245
- kind: "struct",
2246
- fields: [
2247
- {
2248
- name: "admin",
2249
- docs: [
2250
- "Admin who can update vault configuration"
2251
- ],
2252
- type: "pubkey"
2253
- },
2254
- {
2255
- name: "manager",
2256
- docs: [
2257
- "Manager who can perform rebalance operations"
2258
- ],
2259
- type: "pubkey"
2260
- },
2261
- {
2262
- name: "fee_receiver",
2263
- docs: [
2264
- "Account that receives fees"
2265
- ],
2266
- type: "pubkey"
2267
- },
2268
- {
2269
- name: "jlp_mint",
2270
- docs: [
2271
- "JLP token mint address"
2272
- ],
2273
- type: "pubkey"
2274
- },
2275
- {
2276
- name: "base_asset_mints",
2277
- docs: [
2278
- "Base asset token mints [BTC, ETH, SOL, USDC, JupUSD]"
2279
- ],
2280
- type: {
2281
- array: [
2282
- "pubkey",
2283
- 5
2284
- ]
2285
- }
2286
- },
2287
- {
2288
- name: "jlx_asset_mints",
2289
- docs: [
2290
- "jlX token mints [jlBTC, jlETH, jlSOL, jlUSDC, jlJupUSD]"
2291
- ],
2292
- type: {
2293
- array: [
2294
- "pubkey",
2295
- 5
2296
- ]
2297
- }
2298
- },
2299
- {
2300
- name: "oracle_staleness_threshold",
2301
- docs: [
2302
- "Maximum age in seconds for Doves oracle prices to be considered valid.",
2303
- "Used during yield settlement to ensure price freshness.",
2304
- "Default: 60 seconds. Setting to 0 disables staleness check (not recommended)."
2305
- ],
2306
- type: "u64"
2307
- },
2308
- {
2309
- name: "flags",
2310
- docs: [
2311
- "Vault state flags"
2312
- ],
2313
- type: "u16"
2314
- },
2315
- {
2316
- name: "jlp_slippage_bps",
2317
- docs: [
2318
- "JLP swap slippage tolerance in basis points (e.g., 100 = 1%)"
2319
- ],
2320
- type: "u16"
2321
- },
2322
- {
2323
- name: "version",
2324
- docs: [
2325
- "Account version for migrations"
2326
- ],
2327
- type: "u8"
2328
- },
2329
- {
2330
- name: "bump",
2331
- docs: [
2332
- "PDA bump seed"
2333
- ],
2334
- type: "u8"
2335
- },
2336
- {
2337
- name: "reserved",
2338
- docs: [
2339
- "Reserved for 8-byte alignment"
2340
- ],
2341
- type: {
2342
- array: [
2343
- "u8",
2344
- 2
2345
- ]
2346
- }
2347
- }
2348
- ]
2349
- }
2350
- },
2351
- {
2352
- name: "JlpSwapped",
2353
- type: {
2354
- kind: "struct",
2355
- fields: [
2356
- {
2357
- name: "vault",
2358
- type: "pubkey"
2359
- },
2360
- {
2361
- name: "stv_index",
2362
- type: "u8"
2363
- },
2364
- {
2365
- name: "amount_in",
2366
- type: "u64"
2367
- },
2368
- {
2369
- name: "amount_out",
2370
- type: "u64"
2371
- },
2372
- {
2373
- name: "direction",
2374
- docs: [
2375
- "Direction: 0 = JlxToJlp, 1 = JlpToJlx"
2376
- ],
2377
- type: "u8"
2378
- },
2379
- {
2380
- name: "jlp_balance_before",
2381
- type: "u64"
2382
- },
2383
- {
2384
- name: "jlp_balance_after",
2385
- type: "u64"
2386
- }
2387
- ]
2388
- }
2389
- },
2390
- {
2391
- name: "JlpVaultInitialized",
2392
- type: {
2393
- kind: "struct",
2394
- fields: [
2395
- {
2396
- name: "vault",
2397
- type: "pubkey"
2398
- },
2399
- {
2400
- name: "admin",
2401
- type: "pubkey"
2402
- },
2403
- {
2404
- name: "manager",
2405
- type: "pubkey"
2406
- },
2407
- {
2408
- name: "fee_receiver",
2409
- type: "pubkey"
2410
- },
2411
- {
2412
- name: "jlp_mint",
2413
- type: "pubkey"
2414
- }
2415
- ]
2416
- }
2417
- },
2418
- {
2419
- name: "JlpVaultUpdated",
2420
- type: {
2421
- kind: "struct",
2422
- fields: [
2423
- {
2424
- name: "vault",
2425
- type: "pubkey"
2426
- },
2427
- {
2428
- name: "old_manager",
2429
- type: "pubkey"
2430
- },
2431
- {
2432
- name: "new_manager",
2433
- type: "pubkey"
2434
- },
2435
- {
2436
- name: "old_fee_receiver",
2437
- type: "pubkey"
2438
- },
2439
- {
2440
- name: "new_fee_receiver",
2441
- type: "pubkey"
2442
- },
2443
- {
2444
- name: "old_flags",
2445
- type: "u16"
2446
- },
2447
- {
2448
- name: "new_flags",
2449
- type: "u16"
2450
- },
2451
- {
2452
- name: "old_jlp_slippage_bps",
2453
- type: "u16"
2454
- },
2455
- {
2456
- name: "new_jlp_slippage_bps",
2457
- type: "u16"
2458
- },
2459
- {
2460
- name: "old_oracle_staleness_threshold",
2461
- type: "u64"
2462
- },
2463
- {
2464
- name: "new_oracle_staleness_threshold",
2465
- type: "u64"
2466
- }
2467
- ]
2468
- }
2469
- },
2470
- {
2471
- name: "JlxMoved",
2472
- type: {
2473
- kind: "struct",
2474
- fields: [
2475
- {
2476
- name: "stv",
2477
- type: "pubkey"
2478
- },
2479
- {
2480
- name: "vault",
2481
- type: "pubkey"
2482
- },
2483
- {
2484
- name: "amount_jlx",
2485
- type: "u64"
2486
- },
2487
- {
2488
- name: "direction",
2489
- docs: [
2490
- "Direction: 0 = ToVault (STV -> Vault), 1 = FromVault (Vault -> STV)"
2491
- ],
2492
- type: "u8"
2493
- },
2494
- {
2495
- name: "base_value",
2496
- docs: [
2497
- "Base asset value of the jlX moved (at current exchange rate)"
2498
- ],
2499
- type: "u64"
2500
- },
2501
- {
2502
- name: "exchange_rate",
2503
- docs: [
2504
- "Jupiter Lend exchange rate used for calculation (12 decimals)"
2505
- ],
2506
- type: "u64"
2507
- },
2508
- {
2509
- name: "new_base_loaned",
2510
- docs: [
2511
- "New base_loaned after the move"
2512
- ],
2513
- type: "u64"
2514
- }
2515
- ]
2516
- }
2517
- },
2518
- {
2519
- name: "JlxSwapped",
2520
- type: {
2521
- kind: "struct",
2522
- fields: [
2523
- {
2524
- name: "vault",
2525
- type: "pubkey"
2526
- },
2527
- {
2528
- name: "from_index",
2529
- type: "u8"
2530
- },
2531
- {
2532
- name: "to_index",
2533
- type: "u8"
2534
- },
2535
- {
2536
- name: "amount_in",
2537
- type: "u64"
2538
- },
2539
- {
2540
- name: "min_out",
2541
- type: "u64"
2542
- },
2543
- {
2544
- name: "amount_out",
2545
- type: "u64"
2546
- }
2547
- ]
2548
- }
2549
- },
2550
- {
2551
- name: "JupEarnDirection",
2552
- docs: [
2553
- "Direction for Jupiter Earn operations"
2554
- ],
2555
- type: {
2556
- kind: "enum",
2557
- variants: [
2558
- {
2559
- name: "Deposit"
2560
- },
2561
- {
2562
- name: "Withdraw"
2563
- }
2564
- ]
2565
- }
2566
- },
2567
- {
2568
- name: "JupEarnEvent",
2569
- docs: [
2570
- "Event emitted for Jupiter Earn deposit/withdraw operations"
2571
- ],
2572
- type: {
2573
- kind: "struct",
2574
- fields: [
2575
- {
2576
- name: "stv",
2577
- docs: [
2578
- "The STV account"
2579
- ],
2580
- type: "pubkey"
2581
- },
2582
- {
2583
- name: "direction",
2584
- docs: [
2585
- "Direction: 0 = Deposit (base -> jlX), 1 = Withdraw (jlX -> base)"
2586
- ],
2587
- type: "u8"
2588
- },
2589
- {
2590
- name: "base_amount",
2591
- docs: [
2592
- "Amount of base asset (deposited or received)"
2593
- ],
2594
- type: "u64"
2595
- },
2596
- {
2597
- name: "jlx_amount",
2598
- docs: [
2599
- "Amount of jlX (received or burned)"
2600
- ],
2601
- type: "u64"
2602
- }
2603
- ]
2604
- }
2605
- },
2606
- {
2607
- name: "JupEarnParams",
2608
- docs: [
2609
- "Parameters for Jupiter Earn deposit/withdraw"
2610
- ],
2611
- type: {
2612
- kind: "struct",
2613
- fields: [
2614
- {
2615
- name: "direction",
2616
- docs: [
2617
- "Direction of the operation"
2618
- ],
2619
- type: {
2620
- defined: {
2621
- name: "JupEarnDirection"
2622
- }
2623
- }
2624
- },
2625
- {
2626
- name: "amount",
2627
- docs: [
2628
- "Amount to deposit (base) or withdraw (jlX)"
2629
- ],
2630
- type: "u64"
2631
- }
2632
- ]
2633
- }
2634
- },
2635
- {
2636
- name: "MoveJlxParams",
2637
- docs: [
2638
- "Parameters for moving jlX tokens between STV and Vault"
2639
- ],
2640
- type: {
2641
- kind: "struct",
2642
- fields: [
2643
- {
2644
- name: "amount_jlx",
2645
- docs: [
2646
- "Amount of jlX tokens to move"
2647
- ],
2648
- type: "u64"
2649
- },
2650
- {
2651
- name: "direction",
2652
- docs: [
2653
- "Direction of the transfer"
2654
- ],
2655
- type: {
2656
- defined: {
2657
- name: "Direction"
2658
- }
2659
- }
2660
- }
2661
- ]
2662
- }
2663
- },
2664
- {
2665
- name: "STV",
2666
- docs: [
2667
- "STV - Single Token Vault account",
2668
- 'Seeds: ["stv", base_mint.key().as_ref()]',
2669
- "Size: 8 (discriminator) + 200 (data) = 208 bytes"
2670
- ],
2671
- serialization: "bytemuck",
2672
- repr: {
2673
- kind: "c"
2674
- },
2675
- type: {
2676
- kind: "struct",
2677
- fields: [
2678
- {
2679
- name: "base_mint",
2680
- docs: [
2681
- "Base asset mint (BTC, ETH, SOL, or USDC)"
2682
- ],
2683
- type: "pubkey"
2684
- },
2685
- {
2686
- name: "jl_mint",
2687
- docs: [
2688
- "Jupiter Lend token mint (jlBTC, jlETH, jlSOL, jlUSDC, jlJupUSD)"
2689
- ],
2690
- type: "pubkey"
2691
- },
2692
- {
2693
- name: "jv_mint",
2694
- docs: [
2695
- "Vault share token mint (jvBTC, jvETH, jvSOL, jvUSDC, jvJupUSD)"
2696
- ],
2697
- type: "pubkey"
2698
- },
2699
- {
2700
- name: "pps",
2701
- docs: [
2702
- "Price per share in base asset terms (scaled by PPS_DECIMALS)"
2703
- ],
2704
- type: "u64"
2705
- },
2706
- {
2707
- name: "hwm",
2708
- docs: [
2709
- "High water mark for performance fee (scaled by PPS_DECIMALS)"
2710
- ],
2711
- type: "u64"
2712
- },
2713
- {
2714
- name: "last_mgmt_fee_ts",
2715
- docs: [
2716
- "Timestamp of last management fee accrual"
2717
- ],
2718
- type: "u64"
2719
- },
2720
- {
2721
- name: "base_loaned",
2722
- docs: [
2723
- "Base asset value loaned to JLP Vault (illiquid assets)",
2724
- "Updated on: move_stv_to_from_vault (+/-), settle_yield (+/-)",
2725
- "Denominated in base asset (SOL, BTC, etc.), NOT jlX"
2726
- ],
2727
- type: "u64"
2728
- },
2729
- {
2730
- name: "accrued_fees_jlx",
2731
- docs: [
2732
- "Accrued fees in jlX terms (unclaimed, reduces effective NAV for PPS)",
2733
- "Updated on: crystallize_fees (+), claim_fees (reset to 0)"
2734
- ],
2735
- type: "u64"
2736
- },
2737
- {
2738
- name: "max_deposit",
2739
- docs: [
2740
- "Maximum deposit amount in base asset (0 = unlimited)"
2741
- ],
2742
- type: "u64"
2743
- },
2744
- {
2745
- name: "min_deposit",
2746
- docs: [
2747
- "Minimum deposit amount in base asset (0 = no minimum)"
2748
- ],
2749
- type: "u64"
2750
- },
2751
- {
2752
- name: "requested_base",
2753
- docs: [
2754
- "Estimated base for current epoch's withdrawal requests (reset on process_epoch)",
2755
- "Manager reads this to know how much to unwind before next epoch"
2756
- ],
2757
- type: "u64"
2758
- },
2759
- {
2760
- name: "reserved_base",
2761
- docs: [
2762
- "Base earmarked for unclaimed withdrawals (+process_epoch, -claim_withdraw)",
2763
- "Subtracted from NAV so reserved funds don't inflate PPS"
2764
- ],
2765
- type: "u64"
2766
- },
2767
- {
2768
- name: "epoch_pps",
2769
- docs: [
2770
- "PPS locked at first process_epoch batch (0 = not set, reset on epoch advance)"
2771
- ],
2772
- type: "u64"
2773
- },
2774
- {
2775
- name: "next_epoch_ts",
2776
- docs: [
2777
- "Unix timestamp when current epoch ends"
2778
- ],
2779
- type: "u32"
2780
- },
2781
- {
2782
- name: "epoch_sec",
2783
- docs: [
2784
- "Epoch duration in seconds"
2785
- ],
2786
- type: "u32"
2787
- },
2788
- {
2789
- name: "current_epoch_id",
2790
- docs: [
2791
- "Incrementing epoch counter"
2792
- ],
2793
- type: "u32"
2794
- },
2795
- {
2796
- name: "mgmt_fee_bps",
2797
- docs: [
2798
- "Management fee in basis points (annual)"
2799
- ],
2800
- type: "u16"
2801
- },
2802
- {
2803
- name: "perf_fee_bps",
2804
- docs: [
2805
- "Performance fee in basis points"
2806
- ],
2807
- type: "u16"
2808
- },
2809
- {
2810
- name: "flags",
2811
- docs: [
2812
- "STV state flags"
2813
- ],
2814
- type: "u16"
2815
- },
2816
- {
2817
- name: "version",
2818
- docs: [
2819
- "Account version for migrations"
2820
- ],
2821
- type: "u8"
2822
- },
2823
- {
2824
- name: "bump",
2825
- docs: [
2826
- "PDA bump seed"
2827
- ],
2828
- type: "u8"
2829
- },
2830
- {
2831
- name: "_padding",
2832
- docs: [
2833
- "Alignment padding"
2834
- ],
2835
- type: {
2836
- array: [
2837
- "u8",
2838
- 4
2839
- ]
2840
- }
2841
- }
2842
- ]
2843
- }
2844
- },
2845
- {
2846
- name: "SettleYieldEvent",
2847
- docs: [
2848
- "Aggregate yield settlement event - emitted once per settle_yield call"
2849
- ],
2850
- type: {
2851
- kind: "struct",
2852
- fields: [
2853
- {
2854
- name: "vault",
2855
- docs: [
2856
- "The JLP vault"
2857
- ],
2858
- type: "pubkey"
2859
- },
2860
- {
2861
- name: "vault_usd",
2862
- docs: [
2863
- "Total vault USD value (JLP + staging jlX) with 6 decimals"
2864
- ],
2865
- type: "u128"
2866
- },
2867
- {
2868
- name: "total_loaned_usd",
2869
- docs: [
2870
- "Total base_loaned USD value across all STVs with 6 decimals"
2871
- ],
2872
- type: "u128"
2873
- },
2874
- {
2875
- name: "delta_usd",
2876
- docs: [
2877
- "Absolute delta between vault_usd and total_loaned_usd"
2878
- ],
2879
- type: "u128"
2880
- },
2881
- {
2882
- name: "is_surplus",
2883
- docs: [
2884
- "True if vault_usd >= total_loaned_usd (yield), false if deficit (bad debt)"
2885
- ],
2886
- type: "bool"
2887
- },
2888
- {
2889
- name: "timestamp",
2890
- docs: [
2891
- "Settlement timestamp"
2892
- ],
2893
- type: "i64"
2894
- }
2895
- ]
2896
- }
2897
- },
2898
- {
2899
- name: "SettleYieldSkipped",
2900
- docs: [
2901
- "Event emitted when settle_yield returns early (no loans outstanding)"
2902
- ],
2903
- type: {
2904
- kind: "struct",
2905
- fields: [
2906
- {
2907
- name: "vault",
2908
- docs: [
2909
- "The JLP vault"
2910
- ],
2911
- type: "pubkey"
2912
- },
2913
- {
2914
- name: "reason",
2915
- docs: [
2916
- 'Reason for skipping: "NoLoansOutstanding"'
2917
- ],
2918
- type: "string"
2919
- }
2920
- ]
2921
- }
2922
- },
2923
- {
2924
- name: "SettleYieldStvEvent",
2925
- docs: [
2926
- "Per-STV yield settlement event - emitted for each STV with non-zero base_loaned"
2927
- ],
2928
- type: {
2929
- kind: "struct",
2930
- fields: [
2931
- {
2932
- name: "stv",
2933
- docs: [
2934
- "The STV account"
2935
- ],
2936
- type: "pubkey"
2937
- },
2938
- {
2939
- name: "old_base_loaned",
2940
- docs: [
2941
- "base_loaned before settlement"
2942
- ],
2943
- type: "u64"
2944
- },
2945
- {
2946
- name: "new_base_loaned",
2947
- docs: [
2948
- "base_loaned after settlement"
2949
- ],
2950
- type: "u64"
2951
- },
2952
- {
2953
- name: "adjustment_base",
2954
- docs: [
2955
- "Adjustment amount in base asset terms"
2956
- ],
2957
- type: "u64"
2958
- },
2959
- {
2960
- name: "is_surplus",
2961
- docs: [
2962
- "True if surplus (yield added), false if deficit (bad debt deducted)"
2963
- ],
2964
- type: "bool"
2965
- }
2966
- ]
2967
- }
2968
- },
2969
- {
2970
- name: "StvInitialized",
2971
- type: {
2972
- kind: "struct",
2973
- fields: [
2974
- {
2975
- name: "stv",
2976
- type: "pubkey"
2977
- },
2978
- {
2979
- name: "base_mint",
2980
- type: "pubkey"
2981
- },
2982
- {
2983
- name: "jl_mint",
2984
- type: "pubkey"
2985
- },
2986
- {
2987
- name: "jv_mint",
2988
- type: "pubkey"
2989
- }
2990
- ]
2991
- }
2992
- },
2993
- {
2994
- name: "StvUpdated",
2995
- type: {
2996
- kind: "struct",
2997
- fields: [
2998
- {
2999
- name: "stv",
3000
- type: "pubkey"
3001
- },
3002
- {
3003
- name: "base_mint",
3004
- type: "pubkey"
3005
- },
3006
- {
3007
- name: "old_mgmt_fee_bps",
3008
- type: "u16"
3009
- },
3010
- {
3011
- name: "new_mgmt_fee_bps",
3012
- type: "u16"
3013
- },
3014
- {
3015
- name: "old_perf_fee_bps",
3016
- type: "u16"
3017
- },
3018
- {
3019
- name: "new_perf_fee_bps",
3020
- type: "u16"
3021
- },
3022
- {
3023
- name: "old_flags",
3024
- type: "u16"
3025
- },
3026
- {
3027
- name: "new_flags",
3028
- type: "u16"
3029
- },
3030
- {
3031
- name: "old_max_deposit",
3032
- type: "u64"
3033
- },
3034
- {
3035
- name: "new_max_deposit",
3036
- type: "u64"
3037
- },
3038
- {
3039
- name: "old_min_deposit",
3040
- type: "u64"
3041
- },
3042
- {
3043
- name: "new_min_deposit",
3044
- type: "u64"
3045
- },
3046
- {
3047
- name: "old_jl_mint",
3048
- type: "pubkey"
3049
- },
3050
- {
3051
- name: "new_jl_mint",
3052
- type: "pubkey"
3053
- }
3054
- ]
3055
- }
3056
- },
3057
- {
3058
- name: "SwapDirection",
3059
- docs: [
3060
- "Direction of the swap operation"
3061
- ],
3062
- type: {
3063
- kind: "enum",
3064
- variants: [
3065
- {
3066
- name: "JlxToJlp"
3067
- },
3068
- {
3069
- name: "JlpToJlx"
3070
- }
3071
- ]
3072
- }
3073
- },
3074
- {
3075
- name: "SwapJlxJlpParams",
3076
- docs: [
3077
- "Parameters for the swap instruction"
3078
- ],
3079
- type: {
3080
- kind: "struct",
3081
- fields: [
3082
- {
3083
- name: "stv_index",
3084
- docs: [
3085
- "Which STV this JLP belongs to (0-4: BTC, ETH, SOL, USDC, JupUSD)"
3086
- ],
3087
- type: "u8"
3088
- },
3089
- {
3090
- name: "direction",
3091
- docs: [
3092
- "Direction of the swap"
3093
- ],
3094
- type: {
3095
- defined: {
3096
- name: "SwapDirection"
3097
- }
3098
- }
3099
- },
3100
- {
3101
- name: "amount_in",
3102
- docs: [
3103
- "Amount of input token being swapped"
3104
- ],
3105
- type: "u64"
3106
- },
3107
- {
3108
- name: "expected_amount_out",
3109
- docs: [
3110
- "Expected output amount (used for devnet mock, verified on mainnet)"
3111
- ],
3112
- type: "u64"
3113
- },
3114
- {
3115
- name: "jupiter_data",
3116
- docs: [
3117
- "Jupiter swap instruction data (includes discriminator and route)",
3118
- "This is obtained from Jupiter API off-chain",
3119
- "On devnet (with `devnet` feature), this can be empty"
3120
- ],
3121
- type: "bytes"
3122
- }
3123
- ]
3124
- }
3125
- },
3126
- {
3127
- name: "UpdateStvParams",
3128
- docs: [
3129
- "Parameters for updating an STV"
3130
- ],
3131
- type: {
3132
- kind: "struct",
3133
- fields: [
3134
- {
3135
- name: "mgmt_fee_bps",
3136
- docs: [
3137
- "Management fee in basis points (annual)"
3138
- ],
3139
- type: "u16"
3140
- },
3141
- {
3142
- name: "perf_fee_bps",
3143
- docs: [
3144
- "Performance fee in basis points"
3145
- ],
3146
- type: "u16"
3147
- },
3148
- {
3149
- name: "flags",
3150
- docs: [
3151
- "STV state flags"
3152
- ],
3153
- type: "u16"
3154
- },
3155
- {
3156
- name: "max_deposit",
3157
- docs: [
3158
- "Maximum deposit amount in base asset (0 = unlimited)"
3159
- ],
3160
- type: "u64"
3161
- },
3162
- {
3163
- name: "min_deposit",
3164
- docs: [
3165
- "Minimum deposit amount in base asset (0 = no minimum)"
3166
- ],
3167
- type: "u64"
3168
- },
3169
- {
3170
- name: "jl_mint",
3171
- docs: [
3172
- "Optional new jl_mint for migrating base-only pools to Jupiter Lend"
3173
- ],
3174
- type: {
3175
- option: "pubkey"
3176
- }
3177
- },
3178
- {
3179
- name: "pps",
3180
- docs: [
3181
- "Override price per share (9 decimals, e.g. 1_000_000_000 = 1.0)"
3182
- ],
3183
- type: {
3184
- option: "u64"
3185
- }
3186
- },
3187
- {
3188
- name: "hwm",
3189
- docs: [
3190
- "Override high water mark (9 decimals)"
3191
- ],
3192
- type: {
3193
- option: "u64"
3194
- }
3195
- },
3196
- {
3197
- name: "base_loaned",
3198
- docs: [
3199
- "Override base_loaned accounting field"
3200
- ],
3201
- type: {
3202
- option: "u64"
3203
- }
3204
- },
3205
- {
3206
- name: "epoch_sec",
3207
- docs: [
3208
- "Optional new epoch duration in seconds"
3209
- ],
3210
- type: {
3211
- option: "u32"
3212
- }
3213
- }
3214
- ]
3215
- }
3216
- },
3217
- {
3218
- name: "WithdrawClaimed",
3219
- type: {
3220
- kind: "struct",
3221
- fields: [
3222
- {
3223
- name: "stv",
3224
- type: "pubkey"
3225
- },
3226
- {
3227
- name: "user",
3228
- type: "pubkey"
3229
- },
3230
- {
3231
- name: "shares",
3232
- type: "u64"
3233
- },
3234
- {
3235
- name: "base_amount",
3236
- type: "u64"
3237
- },
3238
- {
3239
- name: "epoch_id",
3240
- type: "u32"
3241
- }
3242
- ]
3243
- }
3244
- },
3245
- {
3246
- name: "WithdrawRequest",
3247
- docs: [
3248
- "WithdrawRequest - Per-user per-epoch withdrawal request",
3249
- 'Seeds: ["withdraw_request", stv.key(), user.key(), &epoch_id.to_le_bytes()]',
3250
- "",
3251
- "One PDA per user per STV per epoch. Multiple request_withdraw calls",
3252
- "in the same epoch accumulate into the same PDA.",
3253
- "",
3254
- "Lifecycle:",
3255
- "1. Created by request_withdraw (user escrows jvX into request's ATA)",
3256
- "2. Processed by process_epoch (jvX burned, pps + claim_available_after set)",
3257
- "3. Closed by claim_withdraw (base transferred, PDA + ATA closed)"
3258
- ],
3259
- type: {
3260
- kind: "struct",
3261
- fields: [
3262
- {
3263
- name: "stv",
3264
- docs: [
3265
- "Back-reference to the STV"
3266
- ],
3267
- type: "pubkey"
3268
- },
3269
- {
3270
- name: "user",
3271
- docs: [
3272
- "The user who requested the withdrawal"
3273
- ],
3274
- type: "pubkey"
3275
- },
3276
- {
3277
- name: "shares",
3278
- docs: [
3279
- "Total jvX shares escrowed (accumulated across multiple requests in same epoch)"
3280
- ],
3281
- type: "u64"
3282
- },
3283
- {
3284
- name: "pps",
3285
- docs: [
3286
- "PPS at process time (0 = unprocessed)"
3287
- ],
3288
- type: "u64"
3289
- },
3290
- {
3291
- name: "epoch_id",
3292
- docs: [
3293
- "Epoch when request was made"
3294
- ],
3295
- type: "u32"
3296
- },
3297
- {
3298
- name: "claim_available_after",
3299
- docs: [
3300
- "Unix timestamp after which claim is available (0 = unprocessed)"
3301
- ],
3302
- type: "u32"
3303
- },
3304
- {
3305
- name: "bump",
3306
- docs: [
3307
- "PDA bump seed"
3308
- ],
3309
- type: "u8"
3310
- }
3311
- ]
3312
- }
3313
- },
3314
- {
3315
- name: "WithdrawRequested",
3316
- type: {
3317
- kind: "struct",
3318
- fields: [
3319
- {
3320
- name: "stv",
3321
- type: "pubkey"
3322
- },
3323
- {
3324
- name: "user",
3325
- type: "pubkey"
3326
- },
3327
- {
3328
- name: "shares",
3329
- type: "u64"
3330
- },
3331
- {
3332
- name: "total_shares",
3333
- type: "u64"
3334
- },
3335
- {
3336
- name: "epoch_id",
3337
- type: "u32"
3338
- }
3339
- ]
3340
- }
3341
- }
3342
- ]
3343
- };
3344
-
3345
- // src/program.ts
3346
- var DUMMY_WALLET = {
3347
- publicKey: Keypair.generate().publicKey,
3348
- signTransaction: async (tx) => tx,
3349
- signAllTransactions: async (txs) => txs
3350
- };
3351
- function createProgram(connection) {
3352
- const provider = new AnchorProvider(connection, DUMMY_WALLET, {
3353
- commitment: "confirmed"
3354
- });
3355
- return new Program(jlp_d_program_default, provider);
3356
- }
3357
-
3358
- // src/constants.ts
3359
- import { PublicKey } from "@solana/web3.js";
3360
- import { NATIVE_MINT } from "@solana/spl-token";
3361
- var JLPD_PROGRAM_ID = new PublicKey(
3362
- "ELEM2bAobpZNuysfhyF28XGVjA1aTUwm6rPYyv1JX3oq"
3363
- );
3364
- var JUPITER_LEND_PROGRAM_ID = new PublicKey(
3365
- "jup3YeL8QhtSx1e253b2FDvsMNC87fDrgQZivbrndc9"
3366
- );
3367
- var JUPITER_SWAP_PROGRAM_ID = new PublicKey(
3368
- "JUP6LkbZbjS1jKKwapdHNy74zcZ3tLUZoi5QNyVTaV4"
3369
- );
3370
- var SEED_JLP_VAULT = "jlp_vault";
3371
- var SEED_STV = "stv";
3372
- var SEED_WITHDRAW_REQUEST = "withdraw_request";
3373
- var FLAG_PAUSED = 1;
3374
- var FLAG_DEPOSITS_DISABLED = 2;
3375
- var FLAG_WITHDRAWALS_DISABLED = 4;
3376
- var FLAG_JLP_DISABLED = 8;
3377
- var FLAG_REBALANCE_DISABLED = 16;
3378
- var PPS_DECIMALS = 1e9;
3379
- var EXCHANGE_RATE_PRECISION = 1e12;
3380
- var MINTS = {
3381
- JLP: new PublicKey("27G8MtK7VtTcCHkpASjSDdkWWYfoqT6ggEuKidVJidD4"),
3382
- WSOL: NATIVE_MINT,
3383
- USDC: new PublicKey("EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v"),
3384
- WBTC: new PublicKey("3NZ9JMVBmGAqocybic2c7LQCJScmgsAZ6vQqTDzcqmJh"),
3385
- WETH: new PublicKey("7vfCXTUXx5WJV5JADk17DUJ4ksgau7utNKj4b963voxs"),
3386
- JupUSD: new PublicKey("JuprjznTrTSp2UFa3ZBUFgwdAmtZCq4MQCwysN55USD")
3387
- };
3388
- var STV_INDEX = /* @__PURE__ */ ((STV_INDEX2) => {
3389
- STV_INDEX2[STV_INDEX2["BTC"] = 0] = "BTC";
3390
- STV_INDEX2[STV_INDEX2["ETH"] = 1] = "ETH";
3391
- STV_INDEX2[STV_INDEX2["SOL"] = 2] = "SOL";
3392
- STV_INDEX2[STV_INDEX2["USDC"] = 3] = "USDC";
3393
- STV_INDEX2[STV_INDEX2["JupUSD"] = 4] = "JupUSD";
3394
- return STV_INDEX2;
3395
- })(STV_INDEX || {});
3396
- var ORACLES = {
3397
- // Doves oracles (Jupiter Perps oracle system)
3398
- DOVES_BTC_USD: new PublicKey("4HBbPx9QJdjJ7GUe6bsiJjGybvfpDhQMMPXP1UEa7VT5"),
3399
- DOVES_ETH_USD: new PublicKey("5URYohbPy32nxK1t3jAHVNfdWY2xTubHiFvLrE3VhXEp"),
3400
- DOVES_SOL_USD: new PublicKey("39cWjvHrpHNz2SbXv6ME4NPhqBDBd4KsjUYv5JkHEAJU")
3401
- };
3402
- var JLP_POOL_PUBKEY = new PublicKey("5BUwFW4nRbftYTDMbgxykoFWqWHPzahFSNAaaaJtVKsq");
3403
- var JUPITER_PERPS_PROGRAM_ID = new PublicKey("PERPHjGBqRHArX4DySjwM6UJHiR3sWAatqfdBS2qQJu");
3404
-
3405
- // src/accounts/pdas.ts
3406
- import { PublicKey as PublicKey2 } from "@solana/web3.js";
3407
- var SEED_JLP_VAULT_BUFFER = Buffer.from(SEED_JLP_VAULT);
3408
- var SEED_STV_BUFFER = Buffer.from(SEED_STV);
3409
- var SEED_WITHDRAW_REQUEST_BUFFER = Buffer.from(SEED_WITHDRAW_REQUEST);
3410
- var pdaCache = /* @__PURE__ */ new Map();
3411
- function deriveVaultPda(programId) {
3412
- const key = `vault:${programId.toBase58()}`;
3413
- let cached = pdaCache.get(key);
3414
- if (!cached) {
3415
- cached = PublicKey2.findProgramAddressSync(
3416
- [SEED_JLP_VAULT_BUFFER],
3417
- programId
3418
- );
3419
- pdaCache.set(key, cached);
3420
- }
3421
- return cached;
3422
- }
3423
- function deriveStvPda(baseMint, programId) {
3424
- const key = `stv:${baseMint.toBase58()}:${programId.toBase58()}`;
3425
- let cached = pdaCache.get(key);
3426
- if (!cached) {
3427
- cached = PublicKey2.findProgramAddressSync(
3428
- [SEED_STV_BUFFER, baseMint.toBuffer()],
3429
- programId
3430
- );
3431
- pdaCache.set(key, cached);
3432
- }
3433
- return cached;
3434
- }
3435
- function deriveWithdrawRequestPda(stvPda, user, epochId, programId) {
3436
- const key = `wr:${stvPda.toBase58()}:${user.toBase58()}:${epochId}:${programId.toBase58()}`;
3437
- let cached = pdaCache.get(key);
3438
- if (!cached) {
3439
- const epochIdBuffer = Buffer.alloc(4);
3440
- epochIdBuffer.writeUInt32LE(epochId);
3441
- cached = PublicKey2.findProgramAddressSync(
3442
- [SEED_WITHDRAW_REQUEST_BUFFER, stvPda.toBuffer(), user.toBuffer(), epochIdBuffer],
3443
- programId
3444
- );
3445
- pdaCache.set(key, cached);
3446
- }
3447
- return cached;
3448
- }
3449
- function clearPdaCache() {
3450
- pdaCache.clear();
3451
- }
3452
-
3453
- // src/accounts/vault.ts
3454
- import { PublicKey as PublicKey3 } from "@solana/web3.js";
3455
- import { BN } from "@coral-xyz/anchor";
3456
- var JLP_VAULT_DATA_SIZE = 464;
3457
- var JLP_VAULT_ACCOUNT_SIZE = 8 + JLP_VAULT_DATA_SIZE;
3458
- var JLP_VAULT_DISCRIMINATOR = Buffer.from([
3459
- 41,
3460
- 108,
3461
- 189,
3462
- 168,
3463
- 199,
3464
- 152,
3465
- 221,
3466
- 119
3467
- ]);
3468
- function parseVault(data) {
3469
- if (data.length < JLP_VAULT_ACCOUNT_SIZE) {
3470
- throw new Error(
3471
- `Invalid JLPVault data size: expected ${JLP_VAULT_ACCOUNT_SIZE}, got ${data.length}`
3472
- );
3473
- }
3474
- const discriminator = data.subarray(0, 8);
3475
- if (!discriminator.equals(JLP_VAULT_DISCRIMINATOR)) {
3476
- throw new Error(
3477
- `Invalid JLPVault discriminator: expected ${JLP_VAULT_DISCRIMINATOR.toString("hex")}, got ${discriminator.toString("hex")}`
3478
- );
3479
- }
3480
- let offset = 8;
3481
- const admin = new PublicKey3(data.subarray(offset, offset + 32));
3482
- offset += 32;
3483
- const manager = new PublicKey3(data.subarray(offset, offset + 32));
3484
- offset += 32;
3485
- const feeReceiver = new PublicKey3(data.subarray(offset, offset + 32));
3486
- offset += 32;
3487
- const jlpMint = new PublicKey3(data.subarray(offset, offset + 32));
3488
- offset += 32;
3489
- const baseAssetMints = [];
3490
- for (let i = 0; i < 5; i++) {
3491
- baseAssetMints.push(new PublicKey3(data.subarray(offset, offset + 32)));
3492
- offset += 32;
3493
- }
3494
- const jlxAssetMints = [];
3495
- for (let i = 0; i < 5; i++) {
3496
- jlxAssetMints.push(new PublicKey3(data.subarray(offset, offset + 32)));
3497
- offset += 32;
3498
- }
3499
- const oracleStalenessThreshold = new BN(data.subarray(offset, offset + 8), "le");
3500
- offset += 8;
3501
- const flags = data.readUInt16LE(offset);
3502
- offset += 2;
3503
- const jlpSlippageBps = data.readUInt16LE(offset);
3504
- offset += 2;
3505
- const version = data.readUInt8(offset);
3506
- offset += 1;
3507
- const bump = data.readUInt8(offset);
3508
- offset += 1;
3509
- return {
3510
- admin,
3511
- manager,
3512
- feeReceiver,
3513
- jlpMint,
3514
- baseAssetMints,
3515
- jlxAssetMints,
3516
- oracleStalenessThreshold,
3517
- flags,
3518
- jlpSlippageBps,
3519
- version,
3520
- bump
3521
- };
3522
- }
3523
-
3524
- // src/accounts/stv.ts
3525
- import { PublicKey as PublicKey4 } from "@solana/web3.js";
3526
- import { BN as BN2 } from "@coral-xyz/anchor";
3527
- var STV_DATA_SIZE = 200;
3528
- var STV_ACCOUNT_SIZE = 8 + STV_DATA_SIZE;
3529
- var STV_DISCRIMINATOR = Buffer.from([
3530
- 214,
3531
- 2,
3532
- 96,
3533
- 41,
3534
- 85,
3535
- 163,
3536
- 17,
3537
- 230
3538
- ]);
3539
- function parseStv(data) {
3540
- if (data.length < STV_ACCOUNT_SIZE) {
3541
- throw new Error(
3542
- `Invalid STV data size: expected ${STV_ACCOUNT_SIZE}, got ${data.length}`
3543
- );
3544
- }
3545
- const discriminator = data.subarray(0, 8);
3546
- if (!discriminator.equals(STV_DISCRIMINATOR)) {
3547
- throw new Error(
3548
- `Invalid STV discriminator: expected ${STV_DISCRIMINATOR.toString("hex")}, got ${discriminator.toString("hex")}`
3549
- );
3550
- }
3551
- let offset = 8;
3552
- const baseMint = new PublicKey4(data.subarray(offset, offset + 32));
3553
- offset += 32;
3554
- const jlMint = new PublicKey4(data.subarray(offset, offset + 32));
3555
- offset += 32;
3556
- const jvMint = new PublicKey4(data.subarray(offset, offset + 32));
3557
- offset += 32;
3558
- const pps = new BN2(data.subarray(offset, offset + 8), "le");
3559
- offset += 8;
3560
- const hwm = new BN2(data.subarray(offset, offset + 8), "le");
3561
- offset += 8;
3562
- const lastMgmtFeeTs = new BN2(data.subarray(offset, offset + 8), "le");
3563
- offset += 8;
3564
- const baseLoaned = new BN2(data.subarray(offset, offset + 8), "le");
3565
- offset += 8;
3566
- const accruedFeesJlx = new BN2(data.subarray(offset, offset + 8), "le");
3567
- offset += 8;
3568
- const maxDeposit = new BN2(data.subarray(offset, offset + 8), "le");
3569
- offset += 8;
3570
- const minDeposit = new BN2(data.subarray(offset, offset + 8), "le");
3571
- offset += 8;
3572
- const requestedBase = new BN2(data.subarray(offset, offset + 8), "le");
3573
- offset += 8;
3574
- const reservedBase = new BN2(data.subarray(offset, offset + 8), "le");
3575
- offset += 8;
3576
- const epochPps = new BN2(data.subarray(offset, offset + 8), "le");
3577
- offset += 8;
3578
- const nextEpochTs = data.readUInt32LE(offset);
3579
- offset += 4;
3580
- const epochSec = data.readUInt32LE(offset);
3581
- offset += 4;
3582
- const currentEpochId = data.readUInt32LE(offset);
3583
- offset += 4;
3584
- const mgmtFeeBps = data.readUInt16LE(offset);
3585
- offset += 2;
3586
- const perfFeeBps = data.readUInt16LE(offset);
3587
- offset += 2;
3588
- const flags = data.readUInt16LE(offset);
3589
- offset += 2;
3590
- const version = data.readUInt8(offset);
3591
- offset += 1;
3592
- const bump = data.readUInt8(offset);
3593
- return {
3594
- baseMint,
3595
- jlMint,
3596
- jvMint,
3597
- pps,
3598
- hwm,
3599
- lastMgmtFeeTs,
3600
- baseLoaned,
3601
- accruedFeesJlx,
3602
- maxDeposit,
3603
- minDeposit,
3604
- requestedBase,
3605
- reservedBase,
3606
- epochPps,
3607
- nextEpochTs,
3608
- epochSec,
3609
- currentEpochId,
3610
- mgmtFeeBps,
3611
- perfFeeBps,
3612
- flags,
3613
- version,
3614
- bump
3615
- };
3616
- }
3617
-
3618
- // src/utils/ata.ts
3619
- import { getAssociatedTokenAddressSync } from "@solana/spl-token";
3620
- var ataCache = /* @__PURE__ */ new Map();
3621
- function deriveAta(mint, owner, allowPda = false) {
3622
- const key = `${mint.toBase58()}:${owner.toBase58()}:${allowPda}`;
3623
- let cached = ataCache.get(key);
3624
- if (!cached) {
3625
- cached = getAssociatedTokenAddressSync(mint, owner, allowPda);
3626
- ataCache.set(key, cached);
3627
- }
3628
- return cached;
3629
- }
3630
- function deriveUserAtas(baseMint, jvMint, userWallet) {
3631
- return {
3632
- baseAta: deriveAta(baseMint, userWallet, false),
3633
- jvxAta: deriveAta(jvMint, userWallet, false)
3634
- };
3635
- }
3636
- function deriveStvAtas(baseMint, jlxMint, stvPda) {
3637
- return {
3638
- baseAta: deriveAta(baseMint, stvPda, true),
3639
- jlxAta: deriveAta(jlxMint, stvPda, true)
3640
- };
3641
- }
3642
- function deriveVaultAtas(jlxMint, jlpMint, vaultPda) {
3643
- return {
3644
- stagingAta: deriveAta(jlxMint, vaultPda, true),
3645
- jlpAta: deriveAta(jlpMint, vaultPda, true)
3646
- };
3647
- }
3648
- function clearAtaCache() {
3649
- ataCache.clear();
3650
- }
3651
-
3652
- // src/utils/math.ts
3653
- import { BN as BN3 } from "@coral-xyz/anchor";
3654
- var PPS_DECIMALS_BN = new BN3(PPS_DECIMALS);
3655
- var EXCHANGE_RATE_PRECISION_BN = new BN3(EXCHANGE_RATE_PRECISION);
3656
- var EXCHANGE_RATE_PRECISION_BI = BigInt(EXCHANGE_RATE_PRECISION);
3657
- var RETURN_PERCENT_PRECISION = EXCHANGE_RATE_PRECISION_BI * 100n;
3658
- var SECONDS_PER_YEAR = BigInt(365 * 24 * 60 * 60);
3659
- var MAX_REWARDS_RATE = 50n * EXCHANGE_RATE_PRECISION_BI;
3660
- function calculateNav(stvBaseBalance, stvJlxBalance, exchangeRate, baseLoaned, reservedBase) {
3661
- const jlxValue = stvJlxBalance.mul(new BN3(exchangeRate.toString())).div(EXCHANGE_RATE_PRECISION_BN);
3662
- let nav = stvBaseBalance.add(jlxValue).add(baseLoaned);
3663
- if (reservedBase && !reservedBase.isZero()) {
3664
- nav = nav.sub(reservedBase);
3665
- }
3666
- return nav;
3667
- }
3668
- function calculatePps(nav, jvSupply) {
3669
- if (jvSupply.isZero()) {
3670
- return new BN3(PPS_DECIMALS);
3671
- }
3672
- return nav.mul(PPS_DECIMALS_BN).div(jvSupply);
3673
- }
3674
- function sharesToBase(shares, pps) {
3675
- if (pps.isZero()) {
3676
- throw new Error("Price per share cannot be zero");
3677
- }
3678
- return shares.mul(pps).div(PPS_DECIMALS_BN);
3679
- }
3680
- function baseToShares(base, pps) {
3681
- if (pps.isZero()) {
3682
- throw new Error("Price per share cannot be zero");
3683
- }
3684
- return base.mul(PPS_DECIMALS_BN).div(pps);
3685
- }
3686
- function jlxToBase(jlxAmount, exchangeRate) {
3687
- if (exchangeRate.isZero()) {
3688
- throw new Error("Exchange rate cannot be zero");
3689
- }
3690
- return jlxAmount.mul(exchangeRate).div(EXCHANGE_RATE_PRECISION_BN);
3691
- }
3692
- function baseToJlx(baseAmount, exchangeRate) {
3693
- if (exchangeRate.isZero()) {
3694
- throw new Error("Exchange rate cannot be zero");
3695
- }
3696
- return baseAmount.mul(EXCHANGE_RATE_PRECISION_BN).div(exchangeRate);
3697
- }
3698
- function calculateExchangeRate(storedRate, rewardsRate, currentTimestamp, lastUpdateTimestamp, fTokenTotalSupply) {
3699
- if (fTokenTotalSupply === 0n) {
3700
- return storedRate;
3701
- }
3702
- const totalAssets = storedRate * fTokenTotalSupply / EXCHANGE_RATE_PRECISION_BI;
3703
- if (totalAssets === 0n || rewardsRate === 0n) {
3704
- return storedRate;
3705
- }
3706
- const timeDiff = currentTimestamp - lastUpdateTimestamp;
3707
- if (timeDiff <= 0n) {
3708
- return storedRate;
3709
- }
3710
- const rate = rewardsRate * RETURN_PERCENT_PRECISION / totalAssets;
3711
- const cappedRate = rate > MAX_REWARDS_RATE ? MAX_REWARDS_RATE : rate;
3712
- const priceIncrease = storedRate * cappedRate * timeDiff / RETURN_PERCENT_PRECISION / SECONDS_PER_YEAR;
3713
- return storedRate + priceIncrease;
3714
- }
3715
-
3716
- // src/jupiter/pools.ts
3717
- import { PublicKey as PublicKey5 } from "@solana/web3.js";
3718
- import { NATIVE_MINT as NATIVE_MINT2 } from "@solana/spl-token";
3719
- var LENDING_ADMIN = new PublicKey5("5nmGjA4s7ATzpBQXC5RNceRpaJ7pYw2wKsNBWyuSAZV6");
3720
- var LIQUIDITY_PROGRAM_ID = new PublicKey5("jupeiUmn818Jg1ekPURTpr4mFo29p46vygyykFJ3wZC");
3721
- var LIQUIDITY_SINGLETON = new PublicKey5("7s1da8DduuBFqGra5bJBjpnvL5E9mGzCuMk1Qkh4or2Z");
3722
- var WSOL_POOL = {
3723
- mint: NATIVE_MINT2,
3724
- name: "SOL",
3725
- lending: new PublicKey5("BeAqbxfrcXmzEYT2Ra62oW2MqkuFDHaCtps47Mzg6Zj3"),
3726
- fTokenMint: new PublicKey5("2uQsyo1fXXQkDtcpXnLofWy88PxcvnfH2L8FPSE62FVU"),
3727
- tokenReservesLiquidity: new PublicKey5("4Y66HtUEqbbbpZdENGtFdVhUMS3tnagffn3M4do59Nfy"),
3728
- supplyPositionOnLiquidity: new PublicKey5("4SkEYxmiRgQ4VYyvh9VB4k39M49BpqazyzDUFDzJhXQm"),
3729
- rewardsRateModel: new PublicKey5("CkeQGDRsgMZcCaU8cZEdC2aFAohia4jLzL36RaLcUDsR"),
3730
- vault: new PublicKey5("5JP5zgYCb9W37QQLgAHRHuinFLrKt87akDY1CgZoTPzr"),
3731
- rateModel: new PublicKey5("Acvyi9HBGmqh3Exe1N4PjBVyY8fokq2AdC6fSLqV6KSo"),
3732
- claimAccount: new PublicKey5("6AQGR8zK4KTVZfZ9UZaRzyEL5ynvwVaF5ywVdmtJT24N"),
3733
- decimals: 9,
3734
- stvIndex: 2 /* SOL */,
3735
- hasJupiterLend: true,
3736
- jupDirectSwap: false
3737
- };
3738
- var USDC_POOL = {
3739
- mint: MINTS.USDC,
3740
- name: "USDC",
3741
- lending: new PublicKey5("2vVYHYM8VYnvZqQWpTJSj8o8DBf1wM8pVs3bsTgYZiqJ"),
3742
- fTokenMint: new PublicKey5("9BEcn9aPEmhSPbPQeFGjidRiEKki46fVQDyPpSQXPA2D"),
3743
- tokenReservesLiquidity: new PublicKey5("94vK29npVbyRHXH63rRcTiSr26SFhrQTzbpNJuhQEDu"),
3744
- supplyPositionOnLiquidity: new PublicKey5("Hf9gtkM4dpVBahVSzEXSVCAPpKzBsBcns3s8As3z77oF"),
3745
- rewardsRateModel: new PublicKey5("5xSPBiD3TibamAnwHDhZABdB4z4F9dcj5PnbteroBTTd"),
3746
- vault: new PublicKey5("BmkUoKMFYBxNSzWXyUjyMJjMAaVz4d8ZnxwwmhDCUXFB"),
3747
- rateModel: new PublicKey5("5pjzT5dFTsXcwixoab1QDLvZQvpYJxJeBphkyfHGn688"),
3748
- claimAccount: new PublicKey5("HN1r4VfkDn53xQQfeGDYrNuDKFdemAhZsHYRwBrFhsW"),
3749
- decimals: 6,
3750
- stvIndex: 3 /* USDC */,
3751
- hasJupiterLend: true,
3752
- jupDirectSwap: true
3753
- };
3754
- var JUPUSD_POOL = {
3755
- mint: MINTS.JupUSD,
3756
- name: "JupUSD",
3757
- lending: new PublicKey5("papYEgeG5uPE4niUWZhihUUzVVotJn1mAWbYo2UBSHi"),
3758
- fTokenMint: new PublicKey5("7GxATsNMnaC88vdwd2t3mwrFuQwwGvmYPrUQ4D6FotXk"),
3759
- tokenReservesLiquidity: new PublicKey5("2tQE8jVR5ezDw3PDa21BNzfyQ14Ug5cTf6n3swJNjkod"),
3760
- supplyPositionOnLiquidity: new PublicKey5("DXFoJruECdEch2KpzLQ2cSpxoBSsyg4bpYPnHYofsbD4"),
3761
- rewardsRateModel: new PublicKey5("E3U32h49TL9Qof3NeLja9qJxTrGYpY1o1NQPtrSLJjcc"),
3762
- vault: new PublicKey5("9kGqd5zsQGaFfFPdUuEgbRM4V7x72Jdt7WTS4uRouAQ7"),
3763
- rateModel: new PublicKey5("2hT44GA9r5PiqsbbmqN5CuF7ymtquoEdokRncAs9CVej"),
3764
- claimAccount: new PublicKey5("6q9vTzAsTMEPUCwuhEdJSJdpRNXnubwKZbi2go1B8nvg"),
3765
- decimals: 6,
3766
- stvIndex: 4 /* JupUSD */,
3767
- hasJupiterLend: true,
3768
- jupDirectSwap: true
3769
- };
3770
- var WBTC_POOL = {
3771
- mint: MINTS.WBTC,
3772
- name: "BTC",
3773
- lending: PublicKey5.default,
3774
- fTokenMint: MINTS.WBTC,
3775
- // jlBTC = WBTC (base-only)
3776
- tokenReservesLiquidity: PublicKey5.default,
3777
- supplyPositionOnLiquidity: PublicKey5.default,
3778
- rewardsRateModel: PublicKey5.default,
3779
- vault: PublicKey5.default,
3780
- rateModel: PublicKey5.default,
3781
- claimAccount: PublicKey5.default,
3782
- decimals: 8,
3783
- stvIndex: 0 /* BTC */,
3784
- hasJupiterLend: false,
3785
- jupDirectSwap: true
3786
- };
3787
- var WETH_POOL = {
3788
- mint: MINTS.WETH,
3789
- name: "ETH",
3790
- lending: PublicKey5.default,
3791
- fTokenMint: MINTS.WETH,
3792
- // jlETH = WETH (base-only)
3793
- tokenReservesLiquidity: PublicKey5.default,
3794
- supplyPositionOnLiquidity: PublicKey5.default,
3795
- rewardsRateModel: PublicKey5.default,
3796
- vault: PublicKey5.default,
3797
- rateModel: PublicKey5.default,
3798
- claimAccount: PublicKey5.default,
3799
- decimals: 8,
3800
- stvIndex: 1 /* ETH */,
3801
- hasJupiterLend: false,
3802
- jupDirectSwap: true
3803
- };
3804
- var POOLS = {
3805
- SOL: WSOL_POOL,
3806
- USDC: USDC_POOL,
3807
- JupUSD: JUPUSD_POOL,
3808
- BTC: WBTC_POOL,
3809
- ETH: WETH_POOL
3810
- };
3811
- var POOLS_BY_MINT = new Map(
3812
- Object.values(POOLS).map((p) => [p.mint.toBase58(), p])
3813
- );
3814
- function getPoolByName(name) {
3815
- return POOLS[name];
3816
- }
3817
- function getPoolByMint(mint) {
3818
- return POOLS_BY_MINT.get(mint.toBase58());
3819
- }
3820
-
3821
- // src/jupiter/lend.ts
3822
- import { PublicKey as PublicKey6, SystemProgram } from "@solana/web3.js";
3823
- import { TOKEN_PROGRAM_ID, ASSOCIATED_TOKEN_PROGRAM_ID } from "@solana/spl-token";
3824
- var JUPITER_LEND_PROGRAM_ID2 = new PublicKey6(
3825
- "jup3YeL8QhtSx1e253b2FDvsMNC87fDrgQZivbrndc9"
3826
- );
3827
- function buildExchangeRateAccounts(pool) {
3828
- if (!pool.hasJupiterLend) {
3829
- return null;
3830
- }
3831
- return {
3832
- lending: pool.lending,
3833
- rewardsRateModel: pool.rewardsRateModel
3834
- };
3835
- }
3836
- function buildJupEarnDepositAccounts(pool, stvPda, stvBaseAta, stvJlxAta) {
3837
- if (!pool.hasJupiterLend) {
3838
- throw new Error(`Pool ${pool.name} does not support Jupiter Lend`);
3839
- }
3840
- return [
3841
- { pubkey: stvPda, isSigner: false, isWritable: true },
3842
- { pubkey: stvBaseAta, isSigner: false, isWritable: true },
3843
- { pubkey: stvJlxAta, isSigner: false, isWritable: true },
3844
- { pubkey: pool.mint, isSigner: false, isWritable: false },
3845
- { pubkey: LENDING_ADMIN, isSigner: false, isWritable: false },
3846
- { pubkey: pool.lending, isSigner: false, isWritable: true },
3847
- { pubkey: pool.fTokenMint, isSigner: false, isWritable: true },
3848
- { pubkey: pool.tokenReservesLiquidity, isSigner: false, isWritable: true },
3849
- { pubkey: pool.supplyPositionOnLiquidity, isSigner: false, isWritable: true },
3850
- { pubkey: pool.rateModel, isSigner: false, isWritable: false },
3851
- { pubkey: pool.vault, isSigner: false, isWritable: true },
3852
- { pubkey: LIQUIDITY_SINGLETON, isSigner: false, isWritable: true },
3853
- { pubkey: LIQUIDITY_PROGRAM_ID, isSigner: false, isWritable: true },
3854
- { pubkey: pool.rewardsRateModel, isSigner: false, isWritable: false },
3855
- { pubkey: TOKEN_PROGRAM_ID, isSigner: false, isWritable: false },
3856
- { pubkey: ASSOCIATED_TOKEN_PROGRAM_ID, isSigner: false, isWritable: false },
3857
- { pubkey: SystemProgram.programId, isSigner: false, isWritable: false },
3858
- { pubkey: JUPITER_LEND_PROGRAM_ID2, isSigner: false, isWritable: false }
3859
- ];
3860
- }
3861
- function buildJupEarnWithdrawAccounts(pool, stvPda, stvJlxAta, stvBaseAta) {
3862
- if (!pool.hasJupiterLend) {
3863
- throw new Error(`Pool ${pool.name} does not support Jupiter Lend`);
3864
- }
3865
- return [
3866
- { pubkey: stvPda, isSigner: false, isWritable: true },
3867
- { pubkey: stvJlxAta, isSigner: false, isWritable: true },
3868
- { pubkey: stvBaseAta, isSigner: false, isWritable: true },
3869
- { pubkey: LENDING_ADMIN, isSigner: false, isWritable: false },
3870
- { pubkey: pool.lending, isSigner: false, isWritable: true },
3871
- { pubkey: pool.mint, isSigner: false, isWritable: false },
3872
- { pubkey: pool.fTokenMint, isSigner: false, isWritable: true },
3873
- { pubkey: pool.tokenReservesLiquidity, isSigner: false, isWritable: true },
3874
- { pubkey: pool.supplyPositionOnLiquidity, isSigner: false, isWritable: true },
3875
- { pubkey: pool.rateModel, isSigner: false, isWritable: false },
3876
- { pubkey: pool.vault, isSigner: false, isWritable: true },
3877
- { pubkey: pool.claimAccount, isSigner: false, isWritable: true },
3878
- { pubkey: LIQUIDITY_SINGLETON, isSigner: false, isWritable: true },
3879
- { pubkey: LIQUIDITY_PROGRAM_ID, isSigner: false, isWritable: true },
3880
- { pubkey: pool.rewardsRateModel, isSigner: false, isWritable: false },
3881
- { pubkey: TOKEN_PROGRAM_ID, isSigner: false, isWritable: false },
3882
- { pubkey: ASSOCIATED_TOKEN_PROGRAM_ID, isSigner: false, isWritable: false },
3883
- { pubkey: SystemProgram.programId, isSigner: false, isWritable: false },
3884
- { pubkey: JUPITER_LEND_PROGRAM_ID2, isSigner: false, isWritable: false }
3885
- ];
3886
- }
3887
- function parseLendingAccount(data) {
3888
- return {
3889
- mint: new PublicKey6(data.slice(8, 40)),
3890
- fTokenMint: new PublicKey6(data.slice(40, 72)),
3891
- lendingId: data.readUInt16LE(72),
3892
- decimals: data[74],
3893
- rewardsRateModel: new PublicKey6(data.slice(75, 107)),
3894
- liquidityExchangePrice: data.readBigUInt64LE(107),
3895
- tokenExchangePrice: data.readBigUInt64LE(115),
3896
- lastUpdateTimestamp: data.readBigUInt64LE(123),
3897
- tokenReservesLiquidity: new PublicKey6(data.slice(131, 163)),
3898
- supplyPositionOnLiquidity: new PublicKey6(data.slice(163, 195)),
3899
- bump: data[195]
3900
- };
3901
- }
3902
- function parseRewardsRateModel(data) {
3903
- return {
3904
- mint: new PublicKey6(data.slice(8, 40)),
3905
- startTvl: data.readBigUInt64LE(40),
3906
- duration: data.readBigUInt64LE(48),
3907
- startTime: data.readBigUInt64LE(56),
3908
- yearlyReward: data.readBigUInt64LE(64),
3909
- nextDuration: data.readBigUInt64LE(72),
3910
- nextRewardAmount: data.readBigUInt64LE(80),
3911
- bump: data[88]
3912
- };
3913
- }
3914
-
3915
- // src/jupiter/swap.ts
3916
- import {
3917
- PublicKey as PublicKey7,
3918
- AddressLookupTableAccount
3919
- } from "@solana/web3.js";
3920
- var JUPITER_API_BASE = "https://api.jup.ag/swap/v1";
3921
- var DEFAULT_TIMEOUT_MS = 3e4;
3922
- var MAX_RETRIES = 3;
3923
- var RETRY_DELAY_MS = 1e3;
3924
- function sleep(ms) {
3925
- return new Promise((resolve) => setTimeout(resolve, ms));
3926
- }
3927
- async function fetchWithRetry(url, options = {}, timeoutMs = DEFAULT_TIMEOUT_MS, retries = MAX_RETRIES) {
3928
- let lastError = null;
3929
- for (let attempt = 0; attempt < retries; attempt++) {
3930
- try {
3931
- const controller = new AbortController();
3932
- const timeoutId = setTimeout(() => controller.abort(), timeoutMs);
3933
- const response = await fetch(url, {
3934
- ...options,
3935
- signal: controller.signal
3936
- });
3937
- clearTimeout(timeoutId);
3938
- if (response.ok) {
3939
- return response;
3940
- }
3941
- if (response.status >= 400 && response.status < 500) {
3942
- const errorText = await response.text();
3943
- throw new Error(`Jupiter API error (${response.status}): ${errorText}`);
3944
- }
3945
- lastError = new Error(`Jupiter API returned ${response.status}`);
3946
- } catch (error) {
3947
- if (error instanceof Error) {
3948
- if (error.name === "AbortError") {
3949
- lastError = new Error(`Request timed out after ${timeoutMs}ms`);
3950
- } else {
3951
- lastError = error;
3952
- }
3953
- }
3954
- }
3955
- if (attempt < retries - 1) {
3956
- await sleep(RETRY_DELAY_MS * (attempt + 1));
3957
- }
3958
- }
3959
- throw lastError ?? new Error("Unknown error during fetch");
3960
- }
3961
- async function getJupiterQuote(inputMint, outputMint, amount, slippageBps = 50, maxAccounts = 40, apiKey) {
3962
- const params = new URLSearchParams({
3963
- inputMint: inputMint.toBase58(),
3964
- outputMint: outputMint.toBase58(),
3965
- amount: amount.toString(),
3966
- slippageBps: slippageBps.toString(),
3967
- maxAccounts: maxAccounts.toString()
3968
- });
3969
- const url = `${JUPITER_API_BASE}/quote?${params.toString()}`;
3970
- const headers = {};
3971
- if (apiKey) {
3972
- headers["x-api-key"] = apiKey;
3973
- }
3974
- const response = await fetchWithRetry(url, { headers });
3975
- const data = await response.json();
3976
- if (data.error) {
3977
- throw new Error(`Jupiter quote error: ${data.error}`);
3978
- }
3979
- return data;
3980
- }
3981
- async function getJupiterSwapInstructions(quote, userPubkey, apiKey) {
3982
- const url = `${JUPITER_API_BASE}/swap-instructions`;
3983
- const body = {
3984
- quoteResponse: quote,
3985
- userPublicKey: userPubkey.toBase58(),
3986
- wrapAndUnwrapSol: false,
3987
- dynamicComputeUnitLimit: true,
3988
- skipUserAccountsRpcCalls: true
3989
- };
3990
- const headers = {
3991
- "Content-Type": "application/json"
3992
- };
3993
- if (apiKey) {
3994
- headers["x-api-key"] = apiKey;
3995
- }
3996
- const response = await fetchWithRetry(url, {
3997
- method: "POST",
3998
- headers,
3999
- body: JSON.stringify(body)
4000
- });
4001
- const data = await response.json();
4002
- if (data.error) {
4003
- throw new Error(`Jupiter swap instructions error: ${data.error}`);
4004
- }
4005
- return data;
4006
- }
4007
- function parseSwapRemainingAccounts(swapInstruction) {
4008
- return swapInstruction.accounts.map((acc) => ({
4009
- pubkey: new PublicKey7(acc.pubkey),
4010
- isSigner: false,
4011
- // Always false for CPI — vault PDA signs via seeds
4012
- isWritable: acc.isWritable
4013
- }));
4014
- }
4015
- async function fetchAddressLookupTables(connection, addresses) {
4016
- if (addresses.length === 0) {
4017
- return [];
4018
- }
4019
- const pubkeys = addresses.map((addr) => new PublicKey7(addr));
4020
- const accountInfos = await connection.getMultipleAccountsInfo(pubkeys);
4021
- const tables = [];
4022
- for (let i = 0; i < accountInfos.length; i++) {
4023
- const info = accountInfos[i];
4024
- if (info === null) {
4025
- console.warn(`ALT not found: ${addresses[i]}`);
4026
- continue;
4027
- }
4028
- const table = new AddressLookupTableAccount({
4029
- key: pubkeys[i],
4030
- state: AddressLookupTableAccount.deserialize(info.data)
4031
- });
4032
- tables.push(table);
4033
- }
4034
- return tables;
4035
- }
4036
- async function buildSwapData(connection, inputMint, outputMint, amount, userPubkey, slippageBps = 50, maxAccounts = 40, apiKey) {
4037
- const quote = await getJupiterQuote(
4038
- inputMint,
4039
- outputMint,
4040
- amount,
4041
- slippageBps,
4042
- maxAccounts,
4043
- apiKey
4044
- );
4045
- const instructions = await getJupiterSwapInstructions(quote, userPubkey, apiKey);
4046
- const remainingAccounts = parseSwapRemainingAccounts(instructions.swapInstruction);
4047
- const addressLookupTables = await fetchAddressLookupTables(
4048
- connection,
4049
- instructions.addressLookupTableAddresses
4050
- );
4051
- return {
4052
- quote,
4053
- instructions,
4054
- remainingAccounts,
4055
- addressLookupTables
4056
- };
4057
- }
4058
-
4059
- // src/jupiter/price.ts
4060
- import { BN as BN4 } from "@coral-xyz/anchor";
4061
- async function fetchJupiterPriceUsd(mint, apiKey) {
4062
- const url = `https://api.jup.ag/price/v3?ids=${mint}`;
4063
- try {
4064
- const response = await fetch(url, {
4065
- headers: {
4066
- "x-api-key": apiKey
4067
- }
4068
- });
4069
- if (!response.ok) {
4070
- console.warn(`Jupiter Price API error: ${response.status}`);
4071
- return null;
4072
- }
4073
- const data = await response.json();
4074
- const priceData = data[mint];
4075
- if (!priceData?.usdPrice) {
4076
- console.warn(`No price data for ${mint}`);
4077
- return null;
4078
- }
4079
- return priceData.usdPrice;
4080
- } catch (error) {
4081
- console.warn(`Failed to fetch Jupiter price: ${error.message}`);
4082
- return null;
4083
- }
4084
- }
4085
- async function fetchJlpRate(jlpMint, fallbackPrice = 4.6, apiKey) {
4086
- const priceUsd = await fetchJupiterPriceUsd(jlpMint, apiKey);
4087
- if (priceUsd === null) {
4088
- console.warn(`Using fallback JLP price: $${fallbackPrice}`);
4089
- return new BN4(Math.round(fallbackPrice * 1e8));
4090
- }
4091
- console.log(`JLP price: $${priceUsd.toFixed(4)} -> ${Math.round(priceUsd * 1e8)} (8 decimals)`);
4092
- return new BN4(Math.round(priceUsd * 1e8));
4093
- }
4094
-
4095
- // src/instructions/admin.ts
4096
- async function createInitOrUpdateVaultInstruction(program, params, accounts) {
4097
- return await program.methods.initOrUpdateJlpVault({
4098
- jlpMint: params.jlpMint,
4099
- baseAssetMints: params.baseAssetMints,
4100
- jlxAssetMints: params.jlxAssetMints,
4101
- newAdmin: params.newAdmin,
4102
- manager: params.manager,
4103
- feeReceiver: params.feeReceiver,
4104
- flags: params.flags,
4105
- jlpSlippageBps: params.jlpSlippageBps,
4106
- oracleStalenessThreshold: params.oracleStalenessThreshold
4107
- }).accounts({
4108
- admin: accounts.admin
4109
- }).instruction();
4110
- }
4111
- async function createInitializeStvInstruction(program, params, accounts) {
4112
- return await program.methods.initializeStv({
4113
- mgmtFeeBps: params.mgmtFeeBps,
4114
- perfFeeBps: params.perfFeeBps,
4115
- maxDeposit: params.maxDeposit,
4116
- minDeposit: params.minDeposit,
4117
- epochSec: params.epochSec
4118
- }).accounts({
4119
- admin: accounts.admin,
4120
- jlpVault: accounts.jlpVault,
4121
- baseMint: accounts.baseMint,
4122
- jlMint: accounts.jlMint,
4123
- jvMint: accounts.jvMint,
4124
- tokenProgram: accounts.tokenProgram
4125
- }).instruction();
4126
- }
4127
- async function createUpdateStvInstruction(program, params, accounts) {
4128
- return await program.methods.updateStv({
4129
- mgmtFeeBps: params.mgmtFeeBps,
4130
- perfFeeBps: params.perfFeeBps,
4131
- flags: params.flags,
4132
- maxDeposit: params.maxDeposit,
4133
- minDeposit: params.minDeposit,
4134
- jlMint: params.jlMint,
4135
- pps: params.pps,
4136
- hwm: params.hwm,
4137
- baseLoaned: params.baseLoaned,
4138
- epochSec: params.epochSec
4139
- }).accounts({
4140
- admin: accounts.admin,
4141
- jlpVault: accounts.jlpVault,
4142
- stv: accounts.stv
4143
- }).instruction();
4144
- }
4145
-
4146
- // src/instructions/user.ts
4147
- async function createDepositInstruction(program, amount, accounts, remainingAccounts = []) {
4148
- return await program.methods.deposit(amount).accounts({
4149
- user: accounts.user,
4150
- jlpVault: accounts.jlpVault,
4151
- stv: accounts.stv,
4152
- baseMint: accounts.baseMint,
4153
- jlMint: accounts.jlMint,
4154
- jvMint: accounts.jvMint,
4155
- userBaseAta: accounts.userBaseAta,
4156
- userJvxAta: accounts.userJvxAta,
4157
- stvBaseAta: accounts.stvBaseAta,
4158
- stvJlxAta: accounts.stvJlxAta,
4159
- tokenProgram: accounts.tokenProgram
4160
- }).remainingAccounts(remainingAccounts).instruction();
4161
- }
4162
- async function createRequestWithdrawInstruction(program, params, accounts) {
4163
- return await program.methods.requestWithdraw(params.shares, params.epochId).accounts({
4164
- user: accounts.user,
4165
- jlpVault: accounts.jlpVault,
4166
- stv: accounts.stv,
4167
- jvMint: accounts.jvMint,
4168
- userJvxAta: accounts.userJvxAta,
4169
- withdrawRequest: accounts.withdrawRequest,
4170
- requestJvxAta: accounts.requestJvxAta,
4171
- tokenProgram: accounts.tokenProgram,
4172
- associatedTokenProgram: accounts.associatedTokenProgram,
4173
- systemProgram: accounts.systemProgram
4174
- }).instruction();
4175
- }
4176
- async function createClaimWithdrawInstruction(program, accounts) {
4177
- return await program.methods.claimWithdraw().accounts({
4178
- user: accounts.user,
4179
- stv: accounts.stv,
4180
- baseMint: accounts.baseMint,
4181
- jvMint: accounts.jvMint,
4182
- userBaseAta: accounts.userBaseAta,
4183
- stvBaseAta: accounts.stvBaseAta,
4184
- withdrawRequest: accounts.withdrawRequest,
4185
- requestJvxAta: accounts.requestJvxAta,
4186
- tokenProgram: accounts.tokenProgram
4187
- }).instruction();
4188
- }
4189
-
4190
- // src/instructions/manager.ts
4191
- function toAnchorJupEarnDirection(dir) {
4192
- return dir === "Deposit" ? { deposit: {} } : { withdraw: {} };
4193
- }
4194
- function toAnchorMoveDirection(dir) {
4195
- return dir === "ToVault" ? { toVault: {} } : { fromVault: {} };
4196
- }
4197
- function toAnchorSwapDirection(dir) {
4198
- return dir === "JlxToJlp" ? { jlxToJlp: {} } : { jlpToJlx: {} };
4199
- }
4200
- async function createJupEarnInstruction(program, params, accounts, remainingAccounts = []) {
4201
- return await program.methods.jupEarnDepositWithdraw({
4202
- direction: toAnchorJupEarnDirection(params.direction),
4203
- amount: params.amount
4204
- }).accounts({
4205
- manager: accounts.manager,
4206
- jlpVault: accounts.jlpVault,
4207
- stv: accounts.stv,
4208
- baseMint: accounts.baseMint,
4209
- jlMint: accounts.jlMint,
4210
- stvBaseAta: accounts.stvBaseAta,
4211
- stvJlxAta: accounts.stvJlxAta
4212
- }).remainingAccounts(remainingAccounts).instruction();
4213
- }
4214
- async function createMoveJlxInstruction(program, params, accounts, remainingAccounts = []) {
4215
- return await program.methods.moveStvToFromVault({
4216
- amountJlx: params.amountJlx,
4217
- direction: toAnchorMoveDirection(params.direction)
4218
- }).accounts({
4219
- manager: accounts.manager,
4220
- jlpVault: accounts.jlpVault,
4221
- stv: accounts.stv,
4222
- baseMint: accounts.baseMint,
4223
- jlMint: accounts.jlMint,
4224
- stvJlxAta: accounts.stvJlxAta,
4225
- vaultStagingAta: accounts.vaultStagingAta,
4226
- tokenProgram: accounts.tokenProgram
4227
- }).remainingAccounts(remainingAccounts).instruction();
4228
- }
4229
- async function createSwapJlxJlpInstruction(program, params, accounts, remainingAccounts = []) {
4230
- return await program.methods.swapJlxToFromJlp({
4231
- stvIndex: params.stvIndex,
4232
- direction: toAnchorSwapDirection(params.direction),
4233
- amountIn: params.amountIn,
4234
- expectedAmountOut: params.expectedAmountOut,
4235
- jupiterData: params.jupiterData
4236
- }).accounts({
4237
- manager: accounts.manager,
4238
- jlpVault: accounts.jlpVault,
4239
- vaultJlxAta: accounts.vaultJlxAta,
4240
- vaultJlpAta: accounts.vaultJlpAta,
4241
- jlpMint: accounts.jlpMint,
4242
- tokenProgram: accounts.tokenProgram,
4243
- jupiterProgram: accounts.jupiterProgram
4244
- }).remainingAccounts(remainingAccounts).instruction();
4245
- }
4246
- async function createProcessEpochInstruction(program, accounts, remainingAccounts = []) {
4247
- return await program.methods.processEpoch().accounts({
4248
- payer: accounts.payer,
4249
- jlpVault: accounts.jlpVault,
4250
- stv: accounts.stv,
4251
- baseMint: accounts.baseMint,
4252
- jlMint: accounts.jlMint,
4253
- jvMint: accounts.jvMint,
4254
- stvBaseAta: accounts.stvBaseAta,
4255
- stvJlxAta: accounts.stvJlxAta,
4256
- tokenProgram: accounts.tokenProgram
4257
- }).remainingAccounts(remainingAccounts).instruction();
4258
- }
4259
- async function createSettleYieldInstruction(program, params, accounts, remainingAccounts = []) {
4260
- return await program.methods.settleYield().accounts({
4261
- jlpVault: accounts.jlpVault,
4262
- vaultJlpAta: accounts.vaultJlpAta,
4263
- stv0: accounts.stvBtc,
4264
- stv1: accounts.stvEth,
4265
- stv2: accounts.stvSol,
4266
- stv3: accounts.stvUsdc,
4267
- stv4: accounts.stvJupusd,
4268
- stagingJlx0: accounts.stagingBtc,
4269
- stagingJlx1: accounts.stagingEth,
4270
- stagingJlx2: accounts.stagingSol,
4271
- stagingJlx3: accounts.stagingUsdc,
4272
- stagingJlx4: accounts.stagingJupusd,
4273
- dovesBtcUsd: accounts.oracleBtc,
4274
- dovesEthUsd: accounts.oracleEth,
4275
- dovesSolUsd: accounts.oracleSol,
4276
- jlpPool: accounts.jlpPool,
4277
- jlpMintAccount: accounts.jlpMintAccount,
4278
- manager: accounts.manager
4279
- }).remainingAccounts(remainingAccounts).instruction();
4280
- }
4281
-
4282
- // src/instructions/fees.ts
4283
- async function createClaimFeesInstruction(program, accounts, remainingAccounts = []) {
4284
- return await program.methods.claimFees().accounts({
4285
- manager: accounts.manager,
4286
- jlpVault: accounts.jlpVault,
4287
- stv: accounts.stv,
4288
- baseMint: accounts.baseMint,
4289
- jlMint: accounts.jlMint,
4290
- jvMint: accounts.jvMint,
4291
- stvBaseAta: accounts.stvBaseAta,
4292
- stvJlxAta: accounts.stvJlxAta,
4293
- feeReceiverJlxAta: accounts.feeReceiverJlxAta,
4294
- tokenProgram: accounts.tokenProgram
4295
- }).remainingAccounts(remainingAccounts).instruction();
4296
- }
4297
-
4298
- // src/client.ts
4299
- var JlpdClientError = class extends Error {
4300
- constructor(message) {
4301
- super(message);
4302
- this.name = "JlpdClientError";
4303
- }
4304
- };
4305
- var JlpdClient = class _JlpdClient {
4306
- constructor(connection, programId = JLPD_PROGRAM_ID, options) {
4307
- // Cache for PoolContext instances (avoids re-deriving PDAs/ATAs)
4308
- this.poolContextCache = /* @__PURE__ */ new Map();
4309
- this.connection = connection;
4310
- this.programId = programId;
4311
- const [vaultPda, vaultBump] = deriveVaultPda(programId);
4312
- this.vaultPda = vaultPda;
4313
- this.vaultBump = vaultBump;
4314
- this.program = createProgram(connection);
4315
- this.jupiterApiKey = options?.jupiterApiKey;
4316
- }
4317
- static mainnet(connection, options) {
4318
- return new _JlpdClient(connection, JLPD_PROGRAM_ID, options);
4319
- }
4320
- static devnet(connection, options) {
4321
- const devnetProgramId = new PublicKey8(
4322
- "AcVcAihjB9Z3Lg3ZiboWxni2sTzXUrrsF3unGX4ntn6p"
4323
- );
4324
- return new _JlpdClient(connection, devnetProgramId, options);
4325
- }
4326
- // Fetch vault account
4327
- async fetchVault() {
4328
- const accountInfo = await this.connection.getAccountInfo(this.vaultPda);
4329
- if (!accountInfo) return null;
4330
- return parseVault(accountInfo.data);
4331
- }
4332
- // Fetch STV by base mint
4333
- async fetchStv(baseMint) {
4334
- const [stvPda] = deriveStvPda(baseMint, this.programId);
4335
- const accountInfo = await this.connection.getAccountInfo(stvPda);
4336
- if (!accountInfo) return null;
4337
- return parseStv(accountInfo.data);
4338
- }
4339
- // Fetch exchange rate for a pool
4340
- async fetchExchangeRate(poolName) {
4341
- const pool = getPoolByName(poolName);
4342
- if (!pool) throw new JlpdClientError(`Unknown pool: ${poolName}`);
4343
- if (!pool.hasJupiterLend) {
4344
- return {
4345
- rate: 1,
4346
- rawRate: BigInt(EXCHANGE_RATE_PRECISION),
4347
- storedRate: 1,
4348
- staleness: 0,
4349
- isFresh: true
4350
- };
4351
- }
4352
- const accounts = await this.connection.getMultipleAccountsInfo([
4353
- pool.lending,
4354
- pool.rewardsRateModel,
4355
- pool.fTokenMint
4356
- ]);
4357
- const [lendingInfo, rewardsInfo, mintInfo] = accounts;
4358
- if (!lendingInfo || !rewardsInfo || !mintInfo) {
4359
- throw new JlpdClientError("Failed to fetch Jupiter Lend accounts");
4360
- }
4361
- const lendingData = parseLendingAccount(lendingInfo.data);
4362
- const rewardsData = parseRewardsRateModel(rewardsInfo.data);
4363
- const slot = await this.connection.getSlot();
4364
- const timestamp = await this.connection.getBlockTime(slot);
4365
- if (!timestamp) throw new JlpdClientError("Failed to get block time");
4366
- const supply = mintInfo.data.readBigUInt64LE(36);
4367
- const rawRate = calculateExchangeRate(
4368
- lendingData.tokenExchangePrice,
4369
- rewardsData.yearlyReward,
4370
- BigInt(timestamp),
4371
- lendingData.lastUpdateTimestamp,
4372
- supply
4373
- );
4374
- const rate = Number(rawRate) / EXCHANGE_RATE_PRECISION;
4375
- const storedRate = Number(lendingData.tokenExchangePrice) / EXCHANGE_RATE_PRECISION;
4376
- const staleness = timestamp - Number(lendingData.lastUpdateTimestamp);
4377
- return {
4378
- rate,
4379
- rawRate,
4380
- storedRate,
4381
- staleness,
4382
- isFresh: staleness < 300
4383
- };
4384
- }
4385
- /**
4386
- * Calculate APY based on PPS growth over time
4387
- *
4388
- * @param poolName Pool to calculate APY for
4389
- * @param startPps PPS at the start of the period (as BN with 9 decimals)
4390
- * @param startTime Unix timestamp (seconds) when startPps was recorded
4391
- * @returns APY as a decimal (e.g., 0.12 = 12% APY)
4392
- *
4393
- * @example
4394
- * ```typescript
4395
- * // Calculate APY from a week ago
4396
- * const startPps = new BN("1050000000"); // 1.05 (9 decimals)
4397
- * const startTime = Math.floor(Date.now() / 1000) - 7 * 24 * 60 * 60;
4398
- * const apy = await client.calculateApy("SOL", startPps, startTime);
4399
- * console.log(`APY: ${(apy * 100).toFixed(2)}%`);
4400
- * ```
4401
- */
4402
- async calculateApy(poolName, startPps, startTime) {
4403
- const pool = getPoolByName(poolName);
4404
- if (!pool) throw new JlpdClientError(`Unknown pool: ${poolName}`);
4405
- const [stv, slot] = await Promise.all([
4406
- this.fetchStv(pool.mint),
4407
- this.connection.getSlot()
4408
- ]);
4409
- if (!stv) throw new JlpdClientError(`STV not found for pool: ${poolName}`);
4410
- const currentTime = await this.connection.getBlockTime(slot);
4411
- if (!currentTime) throw new JlpdClientError("Failed to get block time");
4412
- const currentPps = stv.pps;
4413
- const startPpsNum = Number(startPps.toString()) / PPS_DECIMALS;
4414
- const currentPpsNum = Number(currentPps.toString()) / PPS_DECIMALS;
4415
- const timeElapsed = currentTime - startTime;
4416
- if (timeElapsed <= 0) {
4417
- throw new JlpdClientError("Start time must be in the past");
4418
- }
4419
- const SECONDS_PER_YEAR2 = 365.25 * 24 * 60 * 60;
4420
- const ppsGrowthRatio = currentPpsNum / startPpsNum;
4421
- if (ppsGrowthRatio <= 0) {
4422
- return -1;
4423
- }
4424
- const annualizationFactor = SECONDS_PER_YEAR2 / timeElapsed;
4425
- const apy = Math.pow(ppsGrowthRatio, annualizationFactor) - 1;
4426
- return apy;
4427
- }
4428
- /**
4429
- * Calculate simple APY (non-compounded) based on PPS growth
4430
- *
4431
- * @param poolName Pool to calculate APY for
4432
- * @param startPps PPS at the start of the period
4433
- * @param startTime Unix timestamp when startPps was recorded
4434
- * @returns Simple APY as a decimal
4435
- */
4436
- async calculateSimpleApy(poolName, startPps, startTime) {
4437
- const pool = getPoolByName(poolName);
4438
- if (!pool) throw new JlpdClientError(`Unknown pool: ${poolName}`);
4439
- const [stv, slot] = await Promise.all([
4440
- this.fetchStv(pool.mint),
4441
- this.connection.getSlot()
4442
- ]);
4443
- if (!stv) throw new JlpdClientError(`STV not found for pool: ${poolName}`);
4444
- const currentTime = await this.connection.getBlockTime(slot);
4445
- if (!currentTime) throw new JlpdClientError("Failed to get block time");
4446
- const startPpsNum = Number(startPps.toString()) / PPS_DECIMALS;
4447
- const currentPpsNum = Number(stv.pps.toString()) / PPS_DECIMALS;
4448
- const timeElapsed = currentTime - startTime;
4449
- if (timeElapsed <= 0) {
4450
- throw new JlpdClientError("Start time must be in the past");
4451
- }
4452
- const SECONDS_PER_YEAR2 = 365.25 * 24 * 60 * 60;
4453
- const growthRate = (currentPpsNum - startPpsNum) / startPpsNum;
4454
- const simpleApy = growthRate * (SECONDS_PER_YEAR2 / timeElapsed);
4455
- return simpleApy;
4456
- }
4457
- // Get pool context for pool-specific operations (cached)
4458
- pool(poolNameOrMint) {
4459
- const key = typeof poolNameOrMint === "string" ? poolNameOrMint : poolNameOrMint.toBase58();
4460
- let ctx = this.poolContextCache.get(key);
4461
- if (!ctx) {
4462
- const pool = typeof poolNameOrMint === "string" ? getPoolByName(poolNameOrMint) : getPoolByMint(poolNameOrMint);
4463
- if (!pool) throw new JlpdClientError(`Unknown pool: ${key}`);
4464
- ctx = new PoolContext(this, pool);
4465
- this.poolContextCache.set(key, ctx);
4466
- if (typeof poolNameOrMint === "string") {
4467
- this.poolContextCache.set(pool.mint.toBase58(), ctx);
4468
- } else {
4469
- this.poolContextCache.set(pool.name, ctx);
4470
- }
4471
- }
4472
- return ctx;
4473
- }
4474
- // Get swap context for swap operations
4475
- swap() {
4476
- return new SwapContext(this);
4477
- }
4478
- // Get admin context for admin operations
4479
- admin() {
4480
- return new AdminContext(this);
4481
- }
4482
- // Build a versioned transaction
4483
- async buildTransaction(payer, ixs, alts = []) {
4484
- const { blockhash } = await this.connection.getLatestBlockhash("confirmed");
4485
- const message = new TransactionMessage({
4486
- payerKey: payer,
4487
- recentBlockhash: blockhash,
4488
- instructions: ixs
4489
- }).compileToV0Message(alts);
4490
- return new VersionedTransaction(message);
4491
- }
4492
- };
4493
- var PoolContext = class {
4494
- constructor(client, pool) {
4495
- this.client = client;
4496
- this.pool = pool;
4497
- const [pda, bump] = deriveStvPda(pool.mint, client.programId);
4498
- this.stvPda = pda;
4499
- this.stvBump = bump;
4500
- const vaultAtas = deriveVaultAtas(pool.fTokenMint, MINTS.JLP, client.vaultPda);
4501
- this.vaultStagingAta = vaultAtas.stagingAta;
4502
- this.vaultJlpAta = vaultAtas.jlpAta;
4503
- this.vaultBaseAta = deriveAta(pool.mint, client.vaultPda, true);
4504
- const stvAtas = deriveStvAtas(pool.mint, pool.fTokenMint, this.stvPda);
4505
- this.stvBaseAta = stvAtas.baseAta;
4506
- this.stvJlxAta = stvAtas.jlxAta;
4507
- }
4508
- // Deposit base asset and receive jvX shares
4509
- async deposit(params) {
4510
- if (params.amount.isZero() || params.amount.isNeg()) {
4511
- throw new JlpdClientError("Deposit amount must be positive");
4512
- }
4513
- const [stv, { blockhash }] = await Promise.all([
4514
- this.client.fetchStv(this.pool.mint),
4515
- this.client.connection.getLatestBlockhash("confirmed")
4516
- ]);
4517
- if (!stv) throw new JlpdClientError("STV not found");
4518
- const userAtas = deriveUserAtas(this.pool.mint, stv.jvMint, params.user);
4519
- const erAccounts = this.pool.hasJupiterLend ? buildExchangeRateAccounts(this.pool) : null;
4520
- const ix = await createDepositInstruction(
4521
- this.client.program,
4522
- params.amount,
4523
- {
4524
- user: params.user,
4525
- jlpVault: this.client.vaultPda,
4526
- stv: this.stvPda,
4527
- baseMint: this.pool.mint,
4528
- jlMint: this.pool.fTokenMint,
4529
- jvMint: stv.jvMint,
4530
- userBaseAta: userAtas.baseAta,
4531
- userJvxAta: userAtas.jvxAta,
4532
- stvBaseAta: this.stvBaseAta,
4533
- stvJlxAta: this.stvJlxAta,
4534
- tokenProgram: TOKEN_PROGRAM_ID2
4535
- },
4536
- erAccounts ? [
4537
- { pubkey: erAccounts.lending, isSigner: false, isWritable: false },
4538
- { pubkey: erAccounts.rewardsRateModel, isSigner: false, isWritable: false }
4539
- ] : []
4540
- );
4541
- const message = new TransactionMessage({
4542
- payerKey: params.user,
4543
- recentBlockhash: blockhash,
4544
- instructions: [ix]
4545
- }).compileToV0Message();
4546
- return new VersionedTransaction(message);
4547
- }
4548
- // Request withdrawal: escrow jvX shares for the current epoch
4549
- async requestWithdraw(params) {
4550
- if (params.shares.isZero() || params.shares.isNeg()) {
4551
- throw new JlpdClientError("Withdraw shares must be positive");
4552
- }
4553
- const [stv, { blockhash }] = await Promise.all([
4554
- this.client.fetchStv(this.pool.mint),
4555
- this.client.connection.getLatestBlockhash("confirmed")
4556
- ]);
4557
- if (!stv) throw new JlpdClientError("STV not found");
4558
- const epochId = stv.currentEpochId;
4559
- const [withdrawRequestPda] = deriveWithdrawRequestPda(
4560
- this.stvPda,
4561
- params.user,
4562
- epochId,
4563
- this.client.programId
4564
- );
4565
- const requestJvxAta = getAssociatedTokenAddressSync2(stv.jvMint, withdrawRequestPda, true);
4566
- const userAtas = deriveUserAtas(this.pool.mint, stv.jvMint, params.user);
4567
- const ix = await createRequestWithdrawInstruction(
4568
- this.client.program,
4569
- { shares: params.shares, epochId },
4570
- {
4571
- user: params.user,
4572
- jlpVault: this.client.vaultPda,
4573
- stv: this.stvPda,
4574
- jvMint: stv.jvMint,
4575
- userJvxAta: userAtas.jvxAta,
4576
- withdrawRequest: withdrawRequestPda,
4577
- requestJvxAta,
4578
- tokenProgram: TOKEN_PROGRAM_ID2,
4579
- associatedTokenProgram: ASSOCIATED_TOKEN_PROGRAM_ID2,
4580
- systemProgram: SystemProgram2.programId
4581
- }
4582
- );
4583
- const message = new TransactionMessage({
4584
- payerKey: params.user,
4585
- recentBlockhash: blockhash,
4586
- instructions: [ix]
4587
- }).compileToV0Message();
4588
- return new VersionedTransaction(message);
4589
- }
4590
- // Claim withdrawal: receive base tokens for a processed WithdrawRequest
4591
- async claimWithdraw(params) {
4592
- const [stv, { blockhash }] = await Promise.all([
4593
- this.client.fetchStv(this.pool.mint),
4594
- this.client.connection.getLatestBlockhash("confirmed")
4595
- ]);
4596
- if (!stv) throw new JlpdClientError("STV not found");
4597
- const [withdrawRequestPda] = deriveWithdrawRequestPda(
4598
- this.stvPda,
4599
- params.user,
4600
- params.epochId,
4601
- this.client.programId
4602
- );
4603
- const requestJvxAta = getAssociatedTokenAddressSync2(stv.jvMint, withdrawRequestPda, true);
4604
- const userAtas = deriveUserAtas(this.pool.mint, stv.jvMint, params.user);
4605
- const ix = await createClaimWithdrawInstruction(
4606
- this.client.program,
4607
- {
4608
- user: params.user,
4609
- stv: this.stvPda,
4610
- baseMint: this.pool.mint,
4611
- jvMint: stv.jvMint,
4612
- userBaseAta: userAtas.baseAta,
4613
- stvBaseAta: this.stvBaseAta,
4614
- withdrawRequest: withdrawRequestPda,
4615
- requestJvxAta,
4616
- tokenProgram: TOKEN_PROGRAM_ID2
4617
- }
4618
- );
4619
- const message = new TransactionMessage({
4620
- payerKey: params.user,
4621
- recentBlockhash: blockhash,
4622
- instructions: [ix]
4623
- }).compileToV0Message();
4624
- return new VersionedTransaction(message);
4625
- }
4626
- // Jupiter Earn deposit/withdraw
4627
- async jupEarn(params) {
4628
- if (!this.pool.hasJupiterLend) {
4629
- throw new JlpdClientError(`Pool ${this.pool.name} does not support Jupiter Earn`);
4630
- }
4631
- const remainingAccounts = params.direction === "Deposit" ? buildJupEarnDepositAccounts(this.pool, this.stvPda, this.stvBaseAta, this.stvJlxAta) : buildJupEarnWithdrawAccounts(this.pool, this.stvPda, this.stvJlxAta, this.stvBaseAta);
4632
- const ix = await createJupEarnInstruction(
4633
- this.client.program,
4634
- { direction: params.direction, amount: params.amount },
4635
- {
4636
- manager: params.manager,
4637
- jlpVault: this.client.vaultPda,
4638
- stv: this.stvPda,
4639
- baseMint: this.pool.mint,
4640
- jlMint: this.pool.fTokenMint,
4641
- stvBaseAta: this.stvBaseAta,
4642
- stvJlxAta: this.stvJlxAta
4643
- },
4644
- remainingAccounts
4645
- );
4646
- return this.client.buildTransaction(params.manager, [ix]);
4647
- }
4648
- // Move jlX between STV and vault
4649
- async moveJlx(params) {
4650
- const erAccounts = this.pool.hasJupiterLend ? buildExchangeRateAccounts(this.pool) : null;
4651
- const ix = await createMoveJlxInstruction(
4652
- this.client.program,
4653
- { amountJlx: params.jlxAmount, direction: params.direction },
4654
- {
4655
- manager: params.manager,
4656
- jlpVault: this.client.vaultPda,
4657
- stv: this.stvPda,
4658
- baseMint: this.pool.mint,
4659
- jlMint: this.pool.fTokenMint,
4660
- stvJlxAta: this.stvJlxAta,
4661
- vaultStagingAta: this.vaultStagingAta,
4662
- tokenProgram: TOKEN_PROGRAM_ID2
4663
- },
4664
- erAccounts ? [
4665
- { pubkey: erAccounts.lending, isSigner: false, isWritable: false },
4666
- { pubkey: erAccounts.rewardsRateModel, isSigner: false, isWritable: false }
4667
- ] : []
4668
- );
4669
- return this.client.buildTransaction(params.manager, [ix]);
4670
- }
4671
- // Claim fees
4672
- async claimFees(params) {
4673
- const [vault, stv] = await Promise.all([
4674
- this.client.fetchVault(),
4675
- this.client.fetchStv(this.pool.mint)
4676
- ]);
4677
- if (!vault) throw new JlpdClientError("Vault not found");
4678
- if (!stv) throw new JlpdClientError("STV not found");
4679
- const feeReceiverJlxAta = getAssociatedTokenAddressSync2(
4680
- this.pool.fTokenMint,
4681
- vault.feeReceiver,
4682
- true
4683
- );
4684
- const erAccounts = this.pool.hasJupiterLend ? buildExchangeRateAccounts(this.pool) : null;
4685
- const ix = await createClaimFeesInstruction(
4686
- this.client.program,
4687
- {
4688
- manager: params.manager,
4689
- jlpVault: this.client.vaultPda,
4690
- stv: this.stvPda,
4691
- baseMint: this.pool.mint,
4692
- jlMint: this.pool.fTokenMint,
4693
- jvMint: stv.jvMint,
4694
- stvBaseAta: this.stvBaseAta,
4695
- stvJlxAta: this.stvJlxAta,
4696
- feeReceiverJlxAta,
4697
- tokenProgram: TOKEN_PROGRAM_ID2
4698
- },
4699
- erAccounts ? [
4700
- { pubkey: erAccounts.lending, isSigner: false, isWritable: false },
4701
- { pubkey: erAccounts.rewardsRateModel, isSigner: false, isWritable: false }
4702
- ] : []
4703
- );
4704
- return this.client.buildTransaction(params.manager, [ix]);
4705
- }
4706
- // Update STV parameters (admin only)
4707
- async updateStv(params) {
4708
- const stv = await this.client.fetchStv(this.pool.mint);
4709
- if (!stv) throw new JlpdClientError("STV not found");
4710
- const ix = await createUpdateStvInstruction(
4711
- this.client.program,
4712
- {
4713
- mgmtFeeBps: params.mgmtFeeBps ?? stv.mgmtFeeBps,
4714
- perfFeeBps: params.perfFeeBps ?? stv.perfFeeBps,
4715
- flags: params.flags ?? stv.flags,
4716
- maxDeposit: params.maxDeposit ?? stv.maxDeposit,
4717
- minDeposit: params.minDeposit ?? stv.minDeposit,
4718
- jlMint: params.jlMint ?? null,
4719
- pps: params.pps ?? null,
4720
- hwm: params.hwm ?? null,
4721
- baseLoaned: params.baseLoaned ?? null,
4722
- epochSec: params.epochSec ?? null
4723
- },
4724
- {
4725
- admin: params.admin,
4726
- jlpVault: this.client.vaultPda,
4727
- stv: this.stvPda
4728
- }
4729
- );
4730
- return this.client.buildTransaction(params.admin, [ix]);
4731
- }
4732
- };
4733
- var SwapContext = class {
4734
- constructor(client) {
4735
- this.client = client;
4736
- }
4737
- // Get a quote for jlX <-> JLP swap
4738
- async quoteJlxJlp(params) {
4739
- const poolConfig = getPoolByName(params.pool);
4740
- if (!poolConfig) throw new JlpdClientError(`Unknown pool: ${params.pool}`);
4741
- const swapMint = poolConfig.jupDirectSwap ? poolConfig.fTokenMint : poolConfig.mint;
4742
- const inputMint = params.direction === "JlxToJlp" ? swapMint : MINTS.JLP;
4743
- const outputMint = params.direction === "JlxToJlp" ? MINTS.JLP : swapMint;
4744
- const quote = await getJupiterQuote(
4745
- inputMint,
4746
- outputMint,
4747
- BigInt(params.amountIn.toString()),
4748
- params.slippageBps ?? 30,
4749
- 40,
4750
- this.client.jupiterApiKey
4751
- );
4752
- const swapIxs = await getJupiterSwapInstructions(quote, this.client.vaultPda, this.client.jupiterApiKey);
4753
- const remainingAccounts = parseSwapRemainingAccounts(swapIxs.swapInstruction);
4754
- const alts = await fetchAddressLookupTables(
4755
- this.client.connection,
4756
- swapIxs.addressLookupTableAddresses
4757
- );
4758
- return {
4759
- inputMint,
4760
- outputMint,
4761
- inAmount: new BN5(quote.inAmount),
4762
- outAmount: new BN5(quote.outAmount),
4763
- minOutAmount: new BN5(quote.otherAmountThreshold),
4764
- priceImpactPct: parseFloat(quote.priceImpactPct),
4765
- route: quote.routePlan.map((r) => r.swapInfo.label || "unknown"),
4766
- jupiterData: Buffer.from(swapIxs.swapInstruction.data, "base64"),
4767
- remainingAccounts,
4768
- addressLookupTables: alts,
4769
- computeUnitLimit: swapIxs.computeUnitLimit ?? 6e5
4770
- };
4771
- }
4772
- // Build jlX <-> JLP swap transaction
4773
- async swapJlxJlp(params) {
4774
- const poolConfig = getPoolByName(params.pool);
4775
- if (!poolConfig) throw new JlpdClientError(`Unknown pool: ${params.pool}`);
4776
- const poolCtx = this.client.pool(params.pool);
4777
- const computeIx = ComputeBudgetProgram.setComputeUnitLimit({
4778
- units: params.quote.computeUnitLimit
4779
- });
4780
- const jupiterProgram = JUPITER_SWAP_PROGRAM_ID;
4781
- const swapIx = await createSwapJlxJlpInstruction(
4782
- this.client.program,
4783
- {
4784
- stvIndex: poolConfig.stvIndex,
4785
- direction: params.direction,
4786
- amountIn: params.amountIn,
4787
- expectedAmountOut: params.expectedOut,
4788
- jupiterData: params.quote.jupiterData
4789
- },
4790
- {
4791
- manager: params.manager,
4792
- jlpVault: this.client.vaultPda,
4793
- vaultJlxAta: poolConfig.jupDirectSwap ? poolCtx.vaultStagingAta : poolCtx.vaultBaseAta,
4794
- vaultJlpAta: poolCtx.vaultJlpAta,
4795
- jlpMint: MINTS.JLP,
4796
- tokenProgram: TOKEN_PROGRAM_ID2,
4797
- jupiterProgram
4798
- },
4799
- params.quote.remainingAccounts
4800
- );
4801
- const { blockhash } = await this.client.connection.getLatestBlockhash("confirmed");
4802
- const message = new TransactionMessage({
4803
- payerKey: params.manager,
4804
- recentBlockhash: blockhash,
4805
- instructions: [computeIx, swapIx]
4806
- }).compileToV0Message(params.quote.addressLookupTables);
4807
- return new VersionedTransaction(message);
4808
- }
4809
- };
4810
- var AdminContext = class {
4811
- constructor(client) {
4812
- this.client = client;
4813
- }
4814
- // Initialize or update vault
4815
- async initOrUpdateVault(params) {
4816
- const currentVault = await this.client.fetchVault();
4817
- const ix = await createInitOrUpdateVaultInstruction(
4818
- this.client.program,
4819
- {
4820
- jlpMint: params.jlpMint ?? null,
4821
- baseAssetMints: params.baseAssetMints ?? null,
4822
- jlxAssetMints: params.jlxAssetMints ?? null,
4823
- newAdmin: params.newAdmin ?? null,
4824
- manager: params.manager ?? currentVault.manager,
4825
- feeReceiver: params.feeReceiver ?? currentVault.feeReceiver,
4826
- flags: params.flags ?? currentVault.flags,
4827
- jlpSlippageBps: params.jlpSlippageBps ?? currentVault.jlpSlippageBps,
4828
- oracleStalenessThreshold: params.oracleStalenessThreshold ?? null
4829
- },
4830
- {
4831
- admin: params.admin
4832
- }
4833
- );
4834
- return this.client.buildTransaction(params.admin, [ix]);
4835
- }
4836
- // Initialize STV
4837
- async initializeStv(params, jvMintKeypair) {
4838
- const pool = getPoolByName(params.poolName);
4839
- if (!pool) throw new JlpdClientError(`Unknown pool: ${params.poolName}`);
4840
- const ix = await createInitializeStvInstruction(
4841
- this.client.program,
4842
- {
4843
- mgmtFeeBps: params.mgmtFeeBps,
4844
- perfFeeBps: params.perfFeeBps,
4845
- maxDeposit: params.maxDeposit,
4846
- minDeposit: params.minDeposit,
4847
- epochSec: params.withdrawEpochSec
4848
- },
4849
- {
4850
- admin: params.admin,
4851
- jlpVault: this.client.vaultPda,
4852
- baseMint: pool.mint,
4853
- jlMint: pool.fTokenMint,
4854
- jvMint: jvMintKeypair,
4855
- tokenProgram: TOKEN_PROGRAM_ID2
4856
- }
4857
- );
4858
- return this.client.buildTransaction(params.admin, [ix]);
4859
- }
4860
- // Process epoch for a pool (manager operation)
4861
- async processEpoch(params) {
4862
- const pool = getPoolByName(params.poolName);
4863
- if (!pool) throw new JlpdClientError(`Unknown pool: ${params.poolName}`);
4864
- const [stvPda] = deriveStvPda(pool.mint, this.client.programId);
4865
- const stv = await this.client.fetchStv(pool.mint);
4866
- if (!stv) throw new JlpdClientError(`STV not found for pool: ${params.poolName}`);
4867
- const stvAtas = deriveStvAtas(pool.mint, pool.fTokenMint, stvPda);
4868
- const erAccounts = pool.hasJupiterLend ? buildExchangeRateAccounts(pool) : null;
4869
- const remainingAccounts = [];
4870
- if (erAccounts) {
4871
- remainingAccounts.push(
4872
- { pubkey: erAccounts.lending, isSigner: false, isWritable: false },
4873
- { pubkey: erAccounts.rewardsRateModel, isSigner: false, isWritable: false }
4874
- );
4875
- }
4876
- for (const wrPubkey of params.withdrawRequests) {
4877
- const requestJvxAta = getAssociatedTokenAddressSync2(stv.jvMint, wrPubkey, true);
4878
- remainingAccounts.push(
4879
- { pubkey: wrPubkey, isSigner: false, isWritable: true },
4880
- { pubkey: requestJvxAta, isSigner: false, isWritable: true }
4881
- );
4882
- }
4883
- const ix = await createProcessEpochInstruction(
4884
- this.client.program,
4885
- {
4886
- payer: params.payer,
4887
- jlpVault: this.client.vaultPda,
4888
- stv: stvPda,
4889
- baseMint: pool.mint,
4890
- jlMint: pool.fTokenMint,
4891
- jvMint: stv.jvMint,
4892
- stvBaseAta: stvAtas.baseAta,
4893
- stvJlxAta: stvAtas.jlxAta,
4894
- tokenProgram: TOKEN_PROGRAM_ID2
4895
- },
4896
- remainingAccounts
4897
- );
4898
- return this.client.buildTransaction(params.payer, [ix]);
4899
- }
4900
- // Settle yield across all STVs
4901
- async settleYield(params) {
4902
- const poolNames = ["BTC", "ETH", "SOL", "USDC", "JupUSD"];
4903
- const pools = poolNames.map((name) => {
4904
- const pool = getPoolByName(name);
4905
- if (!pool) throw new JlpdClientError(`Unknown pool: ${name}`);
4906
- return pool;
4907
- });
4908
- const stvPdas = pools.map((p) => deriveStvPda(p.mint, this.client.programId)[0]);
4909
- const stagingAtas = pools.map(
4910
- (p) => getAssociatedTokenAddressSync2(p.fTokenMint, this.client.vaultPda, true)
4911
- );
4912
- const lendingAccounts = pools.map((p) => ({
4913
- pubkey: p.hasJupiterLend ? p.lending : PublicKey8.default,
4914
- isSigner: false,
4915
- isWritable: false
4916
- }));
4917
- const rewardsAccounts = pools.map((p) => ({
4918
- pubkey: p.hasJupiterLend ? p.rewardsRateModel : PublicKey8.default,
4919
- isSigner: false,
4920
- isWritable: false
4921
- }));
4922
- const mintAccounts = pools.map((p) => ({
4923
- pubkey: p.fTokenMint,
4924
- isSigner: false,
4925
- isWritable: false
4926
- }));
4927
- const remainingAccounts = [...lendingAccounts, ...rewardsAccounts, ...mintAccounts];
4928
- const ix = await createSettleYieldInstruction(
4929
- this.client.program,
4930
- {},
4931
- {
4932
- manager: params.manager,
4933
- jlpVault: this.client.vaultPda,
4934
- vaultJlpAta: getAssociatedTokenAddressSync2(MINTS.JLP, this.client.vaultPda, true),
4935
- jlpMint: MINTS.JLP,
4936
- stvBtc: stvPdas[0],
4937
- stvEth: stvPdas[1],
4938
- stvSol: stvPdas[2],
4939
- stvUsdc: stvPdas[3],
4940
- stvJupusd: stvPdas[4],
4941
- stagingBtc: stagingAtas[0],
4942
- stagingEth: stagingAtas[1],
4943
- stagingSol: stagingAtas[2],
4944
- stagingUsdc: stagingAtas[3],
4945
- stagingJupusd: stagingAtas[4],
4946
- oracleBtc: ORACLES.DOVES_BTC_USD,
4947
- oracleEth: ORACLES.DOVES_ETH_USD,
4948
- oracleSol: ORACLES.DOVES_SOL_USD,
4949
- jlpPool: JLP_POOL_PUBKEY,
4950
- jlpMintAccount: MINTS.JLP
4951
- },
4952
- remainingAccounts
4953
- );
4954
- return this.client.buildTransaction(params.manager, [ix]);
4955
- }
4956
- };
4957
-
4958
- // src/accounts/withdraw_request.ts
4959
- import { PublicKey as PublicKey9 } from "@solana/web3.js";
4960
- import { BN as BN6 } from "@coral-xyz/anchor";
4961
- var WITHDRAW_REQUEST_DATA_SIZE = 89;
4962
- var WITHDRAW_REQUEST_ACCOUNT_SIZE = 8 + WITHDRAW_REQUEST_DATA_SIZE;
4963
- var WITHDRAW_REQUEST_DISCRIMINATOR = Buffer.from([
4964
- 186,
4965
- 239,
4966
- 174,
4967
- 191,
4968
- 189,
4969
- 13,
4970
- 47,
4971
- 196
4972
- ]);
4973
- function parseWithdrawRequest(data) {
4974
- if (data.length < WITHDRAW_REQUEST_ACCOUNT_SIZE) {
4975
- throw new Error(
4976
- `Invalid WithdrawRequest data size: expected ${WITHDRAW_REQUEST_ACCOUNT_SIZE}, got ${data.length}`
4977
- );
4978
- }
4979
- const discriminator = data.subarray(0, 8);
4980
- if (!discriminator.equals(WITHDRAW_REQUEST_DISCRIMINATOR)) {
4981
- throw new Error(
4982
- `Invalid WithdrawRequest discriminator: expected ${WITHDRAW_REQUEST_DISCRIMINATOR.toString("hex")}, got ${discriminator.toString("hex")}`
4983
- );
4984
- }
4985
- let offset = 8;
4986
- const stv = new PublicKey9(data.subarray(offset, offset + 32));
4987
- offset += 32;
4988
- const user = new PublicKey9(data.subarray(offset, offset + 32));
4989
- offset += 32;
4990
- const shares = new BN6(data.subarray(offset, offset + 8), "le");
4991
- offset += 8;
4992
- const pps = new BN6(data.subarray(offset, offset + 8), "le");
4993
- offset += 8;
4994
- const epochId = data.readUInt32LE(offset);
4995
- offset += 4;
4996
- const claimAvailableAfter = data.readUInt32LE(offset);
4997
- offset += 4;
4998
- const bump = data.readUInt8(offset);
4999
- return { stv, user, shares, pps, epochId, claimAvailableAfter, bump };
5000
- }
5001
- export {
5002
- AdminContext,
5003
- EXCHANGE_RATE_PRECISION,
5004
- FLAG_DEPOSITS_DISABLED,
5005
- FLAG_JLP_DISABLED,
5006
- FLAG_PAUSED,
5007
- FLAG_REBALANCE_DISABLED,
5008
- FLAG_WITHDRAWALS_DISABLED,
5009
- JLPD_PROGRAM_ID,
5010
- JLP_POOL_PUBKEY,
5011
- JLP_VAULT_ACCOUNT_SIZE,
5012
- JLP_VAULT_DATA_SIZE,
5013
- JLP_VAULT_DISCRIMINATOR,
5014
- JUPITER_LEND_PROGRAM_ID,
5015
- JUPITER_PERPS_PROGRAM_ID,
5016
- JUPITER_SWAP_PROGRAM_ID,
5017
- JUPUSD_POOL,
5018
- JUPITER_LEND_PROGRAM_ID2 as JUP_LEND_PROGRAM_ID,
5019
- JlpdClient,
5020
- JlpdClientError,
5021
- LENDING_ADMIN,
5022
- LIQUIDITY_PROGRAM_ID,
5023
- LIQUIDITY_SINGLETON,
5024
- MINTS,
5025
- ORACLES,
5026
- POOLS,
5027
- PPS_DECIMALS,
5028
- PoolContext,
5029
- SEED_JLP_VAULT,
5030
- SEED_STV,
5031
- SEED_WITHDRAW_REQUEST,
5032
- STV_ACCOUNT_SIZE,
5033
- STV_DATA_SIZE,
5034
- STV_DISCRIMINATOR,
5035
- STV_INDEX,
5036
- SwapContext,
5037
- USDC_POOL,
5038
- WBTC_POOL,
5039
- WETH_POOL,
5040
- WITHDRAW_REQUEST_ACCOUNT_SIZE,
5041
- WITHDRAW_REQUEST_DATA_SIZE,
5042
- WITHDRAW_REQUEST_DISCRIMINATOR,
5043
- WSOL_POOL,
5044
- baseToJlx,
5045
- baseToShares,
5046
- buildExchangeRateAccounts,
5047
- buildJupEarnDepositAccounts,
5048
- buildJupEarnWithdrawAccounts,
5049
- buildSwapData,
5050
- calculateExchangeRate,
5051
- calculateNav,
5052
- calculatePps,
5053
- clearAtaCache,
5054
- clearPdaCache,
5055
- createClaimFeesInstruction,
5056
- createClaimWithdrawInstruction,
5057
- createDepositInstruction,
5058
- createInitOrUpdateVaultInstruction,
5059
- createInitializeStvInstruction,
5060
- createJupEarnInstruction,
5061
- createMoveJlxInstruction,
5062
- createProcessEpochInstruction,
5063
- createProgram,
5064
- createRequestWithdrawInstruction,
5065
- createSettleYieldInstruction,
5066
- createSwapJlxJlpInstruction,
5067
- createUpdateStvInstruction,
5068
- deriveAta,
5069
- deriveStvAtas,
5070
- deriveStvPda,
5071
- deriveUserAtas,
5072
- deriveVaultAtas,
5073
- deriveVaultPda,
5074
- deriveWithdrawRequestPda,
5075
- fetchAddressLookupTables,
5076
- fetchJlpRate,
5077
- fetchJupiterPriceUsd,
5078
- getJupiterQuote,
5079
- getJupiterSwapInstructions,
5080
- getPoolByMint,
5081
- getPoolByName,
5082
- jlxToBase,
5083
- parseLendingAccount,
5084
- parseRewardsRateModel,
5085
- parseStv,
5086
- parseSwapRemainingAccounts,
5087
- parseVault,
5088
- parseWithdrawRequest,
5089
- sharesToBase
5090
- };