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