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