@elemental-stv-core/sdk 0.5.0 → 0.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (155) hide show
  1. package/LICENSE +201 -0
  2. package/README.md +250 -0
  3. package/dist/common/ata.d.ts +14 -0
  4. package/dist/common/ata.js +21 -0
  5. package/dist/common/buffer.d.ts +0 -1
  6. package/dist/common/buffer.js +16 -1
  7. package/dist/common/connection.d.ts +13 -0
  8. package/dist/common/connection.js +2 -0
  9. package/dist/common/constants.d.ts +6 -1
  10. package/dist/common/constants.js +21 -2
  11. package/dist/common/index.d.ts +3 -2
  12. package/dist/common/index.js +6 -2
  13. package/dist/common/strategy-interface.d.ts +35 -5
  14. package/dist/common/strategy-interface.js +7 -5
  15. package/dist/elemental-lend/accounts.d.ts +53 -9
  16. package/dist/elemental-lend/accounts.js +66 -8
  17. package/dist/elemental-lend/constants.d.ts +4 -5
  18. package/dist/elemental-lend/constants.js +11 -10
  19. package/dist/elemental-lend/index.d.ts +0 -1
  20. package/dist/elemental-lend/index.js +0 -1
  21. package/dist/elemental-lend/instructions.d.ts +0 -1
  22. package/dist/elemental-lend/instructions.js +0 -1
  23. package/dist/elemental-lend/jupiter-lend.d.ts +0 -1
  24. package/dist/elemental-lend/jupiter-lend.js +2 -3
  25. package/dist/elemental-lend/kamino-vault.d.ts +6 -6
  26. package/dist/elemental-lend/kamino-vault.js +49 -26
  27. package/dist/elemental-lend/pda.d.ts +9 -2
  28. package/dist/elemental-lend/pda.js +10 -3
  29. package/dist/elemental-lend/protocol-actions.d.ts +6 -5
  30. package/dist/elemental-lend/protocol-actions.js +22 -17
  31. package/dist/elemental-lend/types.d.ts +0 -1
  32. package/dist/elemental-lend/types.js +0 -1
  33. package/dist/index.d.ts +0 -1
  34. package/dist/index.js +0 -1
  35. package/dist/jlpd-strategy/accounts.d.ts +64 -11
  36. package/dist/jlpd-strategy/accounts.js +66 -7
  37. package/dist/jlpd-strategy/adapter.d.ts +1 -2
  38. package/dist/jlpd-strategy/adapter.js +1 -2
  39. package/dist/jlpd-strategy/constants.d.ts +21 -13
  40. package/dist/jlpd-strategy/constants.js +31 -27
  41. package/dist/jlpd-strategy/index.d.ts +0 -1
  42. package/dist/jlpd-strategy/index.js +0 -1
  43. package/dist/jlpd-strategy/instructions.d.ts +0 -1
  44. package/dist/jlpd-strategy/instructions.js +0 -1
  45. package/dist/jlpd-strategy/jlp-borrow.d.ts +29 -1
  46. package/dist/jlpd-strategy/jlp-borrow.js +29 -1
  47. package/dist/jlpd-strategy/jlp-data.d.ts +4 -4
  48. package/dist/jlpd-strategy/jlp-data.js +0 -1
  49. package/dist/jlpd-strategy/jupusd-earn.d.ts +31 -6
  50. package/dist/jlpd-strategy/jupusd-earn.js +40 -26
  51. package/dist/jlpd-strategy/pda.d.ts +9 -4
  52. package/dist/jlpd-strategy/pda.js +10 -6
  53. package/dist/jlpd-strategy/settle-yield.d.ts +12 -45
  54. package/dist/jlpd-strategy/settle-yield.js +14 -19
  55. package/dist/jlpd-strategy/swap-jlp.d.ts +4 -4
  56. package/dist/jlpd-strategy/swap-jlp.js +35 -27
  57. package/dist/jlpd-strategy/types.d.ts +5 -4
  58. package/dist/jlpd-strategy/types.js +0 -1
  59. package/dist/p-stv-core/accounts.d.ts +84 -11
  60. package/dist/p-stv-core/accounts.js +83 -5
  61. package/dist/p-stv-core/constants.d.ts +12 -3
  62. package/dist/p-stv-core/constants.js +20 -11
  63. package/dist/p-stv-core/events.d.ts +0 -1
  64. package/dist/p-stv-core/events.js +50 -1
  65. package/dist/p-stv-core/index.d.ts +0 -1
  66. package/dist/p-stv-core/index.js +0 -1
  67. package/dist/p-stv-core/instructions.d.ts +49 -4
  68. package/dist/p-stv-core/instructions.js +46 -14
  69. package/dist/p-stv-core/pda.d.ts +9 -2
  70. package/dist/p-stv-core/pda.js +10 -3
  71. package/dist/p-stv-core/prices.d.ts +0 -1
  72. package/dist/p-stv-core/prices.js +0 -1
  73. package/dist/p-stv-core/remaining-accounts.d.ts +13 -14
  74. package/dist/p-stv-core/remaining-accounts.js +53 -46
  75. package/dist/p-stv-core/send-tx.d.ts +21 -7
  76. package/dist/p-stv-core/send-tx.js +16 -25
  77. package/dist/p-stv-core/sol-wrap.d.ts +0 -1
  78. package/dist/p-stv-core/sol-wrap.js +5 -6
  79. package/dist/p-stv-core/types.d.ts +9 -2
  80. package/dist/p-stv-core/types.js +0 -1
  81. package/package.json +17 -1
  82. package/dist/common/buffer.d.ts.map +0 -1
  83. package/dist/common/buffer.js.map +0 -1
  84. package/dist/common/constants.d.ts.map +0 -1
  85. package/dist/common/constants.js.map +0 -1
  86. package/dist/common/index.d.ts.map +0 -1
  87. package/dist/common/index.js.map +0 -1
  88. package/dist/common/strategy-interface.d.ts.map +0 -1
  89. package/dist/common/strategy-interface.js.map +0 -1
  90. package/dist/elemental-lend/accounts.d.ts.map +0 -1
  91. package/dist/elemental-lend/accounts.js.map +0 -1
  92. package/dist/elemental-lend/constants.d.ts.map +0 -1
  93. package/dist/elemental-lend/constants.js.map +0 -1
  94. package/dist/elemental-lend/index.d.ts.map +0 -1
  95. package/dist/elemental-lend/index.js.map +0 -1
  96. package/dist/elemental-lend/instructions.d.ts.map +0 -1
  97. package/dist/elemental-lend/instructions.js.map +0 -1
  98. package/dist/elemental-lend/jupiter-lend.d.ts.map +0 -1
  99. package/dist/elemental-lend/jupiter-lend.js.map +0 -1
  100. package/dist/elemental-lend/kamino-vault.d.ts.map +0 -1
  101. package/dist/elemental-lend/kamino-vault.js.map +0 -1
  102. package/dist/elemental-lend/pda.d.ts.map +0 -1
  103. package/dist/elemental-lend/pda.js.map +0 -1
  104. package/dist/elemental-lend/protocol-actions.d.ts.map +0 -1
  105. package/dist/elemental-lend/protocol-actions.js.map +0 -1
  106. package/dist/elemental-lend/types.d.ts.map +0 -1
  107. package/dist/elemental-lend/types.js.map +0 -1
  108. package/dist/index.d.ts.map +0 -1
  109. package/dist/index.js.map +0 -1
  110. package/dist/jlpd-strategy/accounts.d.ts.map +0 -1
  111. package/dist/jlpd-strategy/accounts.js.map +0 -1
  112. package/dist/jlpd-strategy/adapter.d.ts.map +0 -1
  113. package/dist/jlpd-strategy/adapter.js.map +0 -1
  114. package/dist/jlpd-strategy/constants.d.ts.map +0 -1
  115. package/dist/jlpd-strategy/constants.js.map +0 -1
  116. package/dist/jlpd-strategy/index.d.ts.map +0 -1
  117. package/dist/jlpd-strategy/index.js.map +0 -1
  118. package/dist/jlpd-strategy/instructions.d.ts.map +0 -1
  119. package/dist/jlpd-strategy/instructions.js.map +0 -1
  120. package/dist/jlpd-strategy/jlp-borrow.d.ts.map +0 -1
  121. package/dist/jlpd-strategy/jlp-borrow.js.map +0 -1
  122. package/dist/jlpd-strategy/jlp-data.d.ts.map +0 -1
  123. package/dist/jlpd-strategy/jlp-data.js.map +0 -1
  124. package/dist/jlpd-strategy/jupusd-earn.d.ts.map +0 -1
  125. package/dist/jlpd-strategy/jupusd-earn.js.map +0 -1
  126. package/dist/jlpd-strategy/pda.d.ts.map +0 -1
  127. package/dist/jlpd-strategy/pda.js.map +0 -1
  128. package/dist/jlpd-strategy/settle-yield.d.ts.map +0 -1
  129. package/dist/jlpd-strategy/settle-yield.js.map +0 -1
  130. package/dist/jlpd-strategy/swap-jlp.d.ts.map +0 -1
  131. package/dist/jlpd-strategy/swap-jlp.js.map +0 -1
  132. package/dist/jlpd-strategy/types.d.ts.map +0 -1
  133. package/dist/jlpd-strategy/types.js.map +0 -1
  134. package/dist/p-stv-core/accounts.d.ts.map +0 -1
  135. package/dist/p-stv-core/accounts.js.map +0 -1
  136. package/dist/p-stv-core/constants.d.ts.map +0 -1
  137. package/dist/p-stv-core/constants.js.map +0 -1
  138. package/dist/p-stv-core/events.d.ts.map +0 -1
  139. package/dist/p-stv-core/events.js.map +0 -1
  140. package/dist/p-stv-core/index.d.ts.map +0 -1
  141. package/dist/p-stv-core/index.js.map +0 -1
  142. package/dist/p-stv-core/instructions.d.ts.map +0 -1
  143. package/dist/p-stv-core/instructions.js.map +0 -1
  144. package/dist/p-stv-core/pda.d.ts.map +0 -1
  145. package/dist/p-stv-core/pda.js.map +0 -1
  146. package/dist/p-stv-core/prices.d.ts.map +0 -1
  147. package/dist/p-stv-core/prices.js.map +0 -1
  148. package/dist/p-stv-core/remaining-accounts.d.ts.map +0 -1
  149. package/dist/p-stv-core/remaining-accounts.js.map +0 -1
  150. package/dist/p-stv-core/send-tx.d.ts.map +0 -1
  151. package/dist/p-stv-core/send-tx.js.map +0 -1
  152. package/dist/p-stv-core/sol-wrap.d.ts.map +0 -1
  153. package/dist/p-stv-core/sol-wrap.js.map +0 -1
  154. package/dist/p-stv-core/types.d.ts.map +0 -1
  155. package/dist/p-stv-core/types.js.map +0 -1
@@ -10,6 +10,7 @@ exports.buildSwapJlpTransaction = buildSwapJlpTransaction;
10
10
  exports.buildRebalanceTransaction = buildRebalanceTransaction;
11
11
  const web3_js_1 = require("@solana/web3.js");
12
12
  const spl_token_1 = require("@solana/spl-token");
13
+ const ata_1 = require("../common/ata");
13
14
  const bn_js_1 = __importDefault(require("bn.js"));
14
15
  const constants_1 = require("./constants");
15
16
  const pda_1 = require("./pda");
@@ -26,15 +27,20 @@ const instructions_2 = require("../elemental-lend/instructions");
26
27
  // Helpers
27
28
  // ---------------------------------------------------------------------------
28
29
  const JUPITER_API_BASE = "https://api.jup.ag/swap/v1";
29
- /** Derive ATA address (same logic as @solana/spl-token getAssociatedTokenAddressSync) */
30
- function findAta(mint, owner, tokenProgram) {
31
- const [ata] = web3_js_1.PublicKey.findProgramAddressSync([owner.toBuffer(), tokenProgram.toBuffer(), mint.toBuffer()], spl_token_1.ASSOCIATED_TOKEN_PROGRAM_ID);
32
- return ata;
33
- }
30
+ /**
31
+ * Optional Jupiter API key, read once at module load time. When set,
32
+ * outbound Jupiter requests include an `x-api-key` header for higher rate
33
+ * limits. Read once instead of per-call so the env var is consistent across
34
+ * the lifetime of the process.
35
+ */
36
+ const JUPITER_API_KEY = process.env.NEXT_PUBLIC_JUPITER_API_KEY;
34
37
  function toBigInt(v) {
35
38
  if (typeof v === "bigint")
36
39
  return v;
37
- return BigInt(v.toString());
40
+ const bn = v;
41
+ if (typeof bn.toBigInt === "function")
42
+ return bn.toBigInt();
43
+ return BigInt(bn.toString());
38
44
  }
39
45
  // ---------------------------------------------------------------------------
40
46
  // Low-level instruction builder
@@ -89,7 +95,6 @@ function createSwapJlpIx(args, programId = constants_1.PROGRAM_ID) {
89
95
  */
90
96
  async function getJupiterSwapQuote(args) {
91
97
  const { inputMint, outputMint, amount, slippageBps = 50, maxAccounts = 40 } = args;
92
- const apiKey = process.env.NEXT_PUBLIC_JUPITER_API_KEY;
93
98
  const params = new URLSearchParams({
94
99
  inputMint: inputMint.toBase58(),
95
100
  outputMint: outputMint.toBase58(),
@@ -99,8 +104,8 @@ async function getJupiterSwapQuote(args) {
99
104
  });
100
105
  const url = `${JUPITER_API_BASE}/quote?${params.toString()}`;
101
106
  const headers = {};
102
- if (apiKey) {
103
- headers["x-api-key"] = apiKey;
107
+ if (JUPITER_API_KEY) {
108
+ headers["x-api-key"] = JUPITER_API_KEY;
104
109
  }
105
110
  const response = await fetch(url, { headers });
106
111
  if (!response.ok) {
@@ -121,7 +126,6 @@ async function getJupiterSwapQuote(args) {
121
126
  */
122
127
  async function getJupiterSwapInstructions(args) {
123
128
  const { quoteResponse, userPublicKey } = args;
124
- const apiKey = process.env.NEXT_PUBLIC_JUPITER_API_KEY;
125
129
  const url = `${JUPITER_API_BASE}/swap-instructions`;
126
130
  const body = {
127
131
  quoteResponse,
@@ -133,8 +137,8 @@ async function getJupiterSwapInstructions(args) {
133
137
  const headers = {
134
138
  "Content-Type": "application/json",
135
139
  };
136
- if (apiKey) {
137
- headers["x-api-key"] = apiKey;
140
+ if (JUPITER_API_KEY) {
141
+ headers["x-api-key"] = JUPITER_API_KEY;
138
142
  }
139
143
  const response = await fetch(url, {
140
144
  method: "POST",
@@ -204,12 +208,12 @@ async function buildSwapJlpTransaction(args) {
204
208
  const { connection, manager, baseMint, direction, amount, slippageBps = 50, jlpMint = constants_1.JLP_MINT, tokenProgram = spl_token_1.TOKEN_PROGRAM_ID, programId = constants_1.PROGRAM_ID, } = args;
205
209
  // 1. Derive PDAs
206
210
  const [config] = (0, pda_1.findJlpdConfigPda)(programId);
207
- const [managerRole] = (0, pda_1.findManagerRolePda)(config, manager, programId);
211
+ const [managerRole] = (0, pda_1.findJlpdManagerRolePda)(config, manager, programId);
208
212
  const [strategyState] = (0, pda_1.findStrategyStatePda)(baseMint, programId);
209
213
  // Derive ATAs
210
- const strategyBaseAta = findAta(baseMint, strategyState, tokenProgram);
211
- const strategyJlpAta = findAta(jlpMint, strategyState, tokenProgram);
212
- const vaultJlpAta = findAta(jlpMint, config, tokenProgram);
214
+ const strategyBaseAta = (0, ata_1.findAta)(baseMint, strategyState, tokenProgram);
215
+ const strategyJlpAta = (0, ata_1.findAta)(jlpMint, strategyState, tokenProgram);
216
+ const vaultJlpAta = (0, ata_1.findAta)(jlpMint, config, tokenProgram);
213
217
  // 2. Determine input/output mints for the Jupiter quote
214
218
  const inputMint = direction === "BaseToJlp" ? baseMint : jlpMint;
215
219
  const outputMint = direction === "BaseToJlp" ? jlpMint : baseMint;
@@ -284,7 +288,7 @@ async function buildBaseToJlpRebalance(args) {
284
288
  const { connection, manager, baseMint, vaultId, amount, slippageBps, jlpMint, tokenProgram, programId, pStvProgramId, liquidity, } = args;
285
289
  // Derive JLPD PDAs
286
290
  const [strategyState] = (0, pda_1.findStrategyStatePda)(baseMint, programId);
287
- const strategyBaseAta = findAta(baseMint, strategyState, tokenProgram);
291
+ const strategyBaseAta = (0, ata_1.findAta)(baseMint, strategyState, tokenProgram);
288
292
  // Check if strategy_base_ata already has enough
289
293
  let strategyBalance = liquidity?.strategyAtaBalance ?? 0n;
290
294
  if (!liquidity) {
@@ -320,7 +324,7 @@ async function buildBaseToJlpRebalance(args) {
320
324
  // Fetch STV on-chain for lend info
321
325
  const stv = await (0, accounts_2.fetchStv)(connection, vaultId, pStvProgramId);
322
326
  const [stvAddress] = (0, pda_2.findStvPda)(vaultId, pStvProgramId);
323
- const [stvManagerRole] = (0, pda_2.findManagerRolePda)(stvAddress, manager, pStvProgramId);
327
+ const [stvManagerRole] = (0, pda_2.findStvManagerRolePda)(stvAddress, manager, pStvProgramId);
324
328
  // Build deposit_to_strategy remaining accounts (lend + auto-unroute)
325
329
  const vaultInfo = {
326
330
  address: stvAddress,
@@ -332,10 +336,12 @@ async function buildBaseToJlpRebalance(args) {
332
336
  const depositCtx = await (0, remaining_accounts_1.buildDepositToStrategyContext)(connection, vaultInfo);
333
337
  // Derive the JLPD strategy's position PDA in p-STV Core
334
338
  const [jlpdStvPosition] = (0, pda_1.findStvPositionPda)(stvAddress, programId);
335
- const vaultAta = findAta(baseMint, stvAddress, tokenProgram);
339
+ const vaultAta = (0, ata_1.findAta)(baseMint, stvAddress, tokenProgram);
340
+ const [configPda] = (0, pda_2.findConfigPda)(pStvProgramId);
336
341
  const depositIx = (0, instructions_1.createDepositToStrategyIx)({
337
342
  manager,
338
343
  managerRole: stvManagerRole,
344
+ config: configPda,
339
345
  stv: stvAddress,
340
346
  vaultAta,
341
347
  baseMint,
@@ -346,6 +352,7 @@ async function buildBaseToJlpRebalance(args) {
346
352
  tokenProgram,
347
353
  amount: new bn_js_1.default(deficit.toString()),
348
354
  minShares: new bn_js_1.default(0),
355
+ protocolAumCount: depositCtx.protocolAumCount,
349
356
  autoUnrouteCount: depositCtx.autoUnrouteCount,
350
357
  remainingAccounts: depositCtx.remainingAccounts,
351
358
  }, pStvProgramId);
@@ -391,17 +398,17 @@ async function buildJlpToBaseRebalance(args) {
391
398
  sharesToWithdraw = positionShares;
392
399
  }
393
400
  // Build withdraw_from_strategy
394
- const [stvManagerRole] = (0, pda_2.findManagerRolePda)(stvAddress, manager, pStvProgramId);
401
+ const [stvManagerRole] = (0, pda_2.findStvManagerRolePda)(stvAddress, manager, pStvProgramId);
395
402
  const [jlpdStvPosition] = (0, pda_1.findStvPositionPda)(stvAddress, programId);
396
- const strategyBaseAta = findAta(baseMint, strategyState, tokenProgram);
397
- const vaultAta = findAta(baseMint, stvAddress, tokenProgram);
403
+ const strategyBaseAta = (0, ata_1.findAta)(baseMint, strategyState, tokenProgram);
404
+ const vaultAta = (0, ata_1.findAta)(baseMint, stvAddress, tokenProgram);
398
405
  // Build lend remaining_accounts for auto-sweep after withdraw
399
406
  const lendAccounts = [];
400
407
  const DEFAULT_PUBKEY = web3_js_1.PublicKey.default;
401
408
  if (!stv.lendProgram.equals(DEFAULT_PUBKEY)) {
402
409
  const [lendStrategyState] = (0, pda_3.findStrategyStatePda)(baseMint, stv.lendProgram);
403
410
  const [lendPosition] = (0, pda_3.findStvPositionPda)(stvAddress, stv.lendProgram);
404
- const lendBaseAta = findAta(baseMint, lendStrategyState, tokenProgram);
411
+ const lendBaseAta = (0, ata_1.findAta)(baseMint, lendStrategyState, tokenProgram);
405
412
  lendAccounts.push(...(0, instructions_1.buildLendRemainingAccounts)({
406
413
  lendProgram: stv.lendProgram,
407
414
  lendStrategyState,
@@ -409,9 +416,11 @@ async function buildJlpToBaseRebalance(args) {
409
416
  lendBaseAta,
410
417
  }));
411
418
  }
419
+ const [configPda] = (0, pda_2.findConfigPda)(pStvProgramId);
412
420
  const withdrawIx = (0, instructions_1.createWithdrawFromStrategyIx)({
413
421
  manager,
414
422
  managerRole: stvManagerRole,
423
+ config: configPda,
415
424
  stv: stvAddress,
416
425
  vaultAta,
417
426
  baseMint,
@@ -431,9 +440,9 @@ async function buildJlpToBaseRebalance(args) {
431
440
  if (!stv.lendProgram.equals(DEFAULT_PUBKEY) && jupPool) {
432
441
  const lendProgramId = stv.lendProgram;
433
442
  const [lendStrategyState] = (0, pda_3.findStrategyStatePda)(baseMint, lendProgramId);
434
- const [lendManagerRole] = (0, pda_3.findManagerRolePda)(lendStrategyState, manager, lendProgramId);
435
- const lendBaseAta = findAta(baseMint, lendStrategyState, tokenProgram);
436
- const lendFtokenAta = findAta(jupPool.fTokenMint, lendStrategyState, tokenProgram);
443
+ const [lendManagerRole] = (0, pda_3.findLendManagerRolePda)(lendStrategyState, manager, lendProgramId);
444
+ const lendBaseAta = (0, ata_1.findAta)(baseMint, lendStrategyState, tokenProgram);
445
+ const lendFtokenAta = (0, ata_1.findAta)(jupPool.fTokenMint, lendStrategyState, tokenProgram);
437
446
  const JUP_LEND_PROG = new web3_js_1.PublicKey("jup3YeL8QhtSx1e253b2FDvsMNC87fDrgQZivbrndc9");
438
447
  const jupLendAccounts = [
439
448
  ...(0, jupiter_lend_1.buildJupLendDepositAccounts)(jupPool, lendStrategyState, lendBaseAta, lendFtokenAta).map((a) => ({ ...a, isSigner: false })),
@@ -462,4 +471,3 @@ async function buildJlpToBaseRebalance(args) {
462
471
  : "Swap JLP → base → withdraw to vault",
463
472
  };
464
473
  }
465
- //# sourceMappingURL=swap-jlp.js.map
@@ -1,7 +1,7 @@
1
1
  import { PublicKey } from "@solana/web3.js";
2
2
  import BN from "bn.js";
3
3
  import type { StrategyStateHeader } from "../common/strategy-interface";
4
- /** JlpdConfig global config (272 bytes) */
4
+ /** JlpdConfig global config (392 bytes) */
5
5
  export interface JlpdConfig {
6
6
  admin: PublicKey;
7
7
  jlpMint: PublicKey;
@@ -11,9 +11,11 @@ export interface JlpdConfig {
11
11
  jlpSlippageBps: number;
12
12
  version: number;
13
13
  bump: number;
14
+ /** JLP loaned to the JLPD Lend Adapter (not in vault ATA). Total JLP = vault_jlp_ata + jlpEarnAmount. */
15
+ jlpEarnAmount: BN;
16
+ /** Whitelisted adapter program. PublicKey.default = no adapter. */
17
+ jlpAdapterProgram: PublicKey;
14
18
  }
15
- /** @deprecated Use JlpdConfig instead */
16
- export type JLPVault = JlpdConfig;
17
19
  /** ManagerRole PDA (80 bytes) — grants manager access to rebalance operations */
18
20
  export interface ManagerRole {
19
21
  config: PublicKey;
@@ -53,4 +55,3 @@ export interface ManagerRemovedEvent {
53
55
  config: PublicKey;
54
56
  manager: PublicKey;
55
57
  }
56
- //# sourceMappingURL=types.d.ts.map
@@ -1,3 +1,2 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- //# sourceMappingURL=types.js.map
@@ -1,17 +1,90 @@
1
- import { Connection, PublicKey } from "@solana/web3.js";
1
+ import { PublicKey } from "@solana/web3.js";
2
2
  import BN from "bn.js";
3
+ import type { SolanaConnection } from "../common/connection";
3
4
  import { GlobalConfig, Stv, WithdrawRequest, ManagerRole } from "./types";
5
+ /**
6
+ * GlobalConfig — singleton protocol registry. Total 56 bytes.
7
+ *
8
+ * Layout (offsets include the 8-byte discriminator):
9
+ * [ 0.. 8] discriminator (sha256("account:GlobalConfig")[..8])
10
+ * [ 8.. 40] admin Pubkey
11
+ * [ 40.. 48] nextVaultId u64
12
+ * [ 48.. 50] flags u16 (CFG_FLAG_*)
13
+ * [ 50.. 51] version u8
14
+ * [ 51.. 52] bump u8
15
+ * [ 52.. 56] _padding [u8; 4]
16
+ */
4
17
  export declare function deserializeGlobalConfig(data: Buffer): GlobalConfig;
18
+ /**
19
+ * STV — per-vault state. Total 664 bytes.
20
+ *
21
+ * Layout (offsets include the 8-byte discriminator):
22
+ * [ 0.. 8] discriminator (sha256("account:Stv")[..8])
23
+ * [ 8.. 40] baseMint Pubkey
24
+ * [ 40.. 72] evMint Pubkey
25
+ * [ 72..104] strategy Pubkey (legacy single-strategy slot)
26
+ * [104..136] feeReceiver Pubkey
27
+ * [136..168] lendProgram Pubkey (zero pubkey if lend not opted-in)
28
+ * [168..488] strategies[10] [Pubkey; 10] (whitelisted strategy programs)
29
+ * [488..496] vaultId u64
30
+ * [496..504] reservedBase u64 (base reserved for pending claims)
31
+ * [504..512] requestedBase u64 (base requested via request_withdraw)
32
+ * [512..520] vaultCapacity u64 (0 = uncapped)
33
+ * [520..528] minDeposit u64
34
+ * [528..536] hwm u64 (high-water mark for perf fees)
35
+ * [536..544] lastFeeTs u64 (last fee crystallization timestamp)
36
+ * [544..552] epochPps u64 (locked PPS for current epoch claims)
37
+ * [552..560] lastNav u64 (snapshot for the rate-limit window)
38
+ * [560..568] dailyWithdrawnBase u64 (rate-limit accumulator)
39
+ * [568..572] nextEpochTs u32
40
+ * [572..576] epochSec u32
41
+ * [576..580] currentEpochId u32
42
+ * [580..584] pendingWithdrawals u32
43
+ * [584..588] withdrawWindowStart u32
44
+ * [588..590] mgmtFeeBps u16
45
+ * [590..592] perfFeeBps u16
46
+ * [592..594] flags u16 (FLAG_PAUSED / DEPOSITS_DISABLED / …)
47
+ * [594..596] dailyWithdrawLimitBps u16
48
+ * [596..597] strategyCount u8
49
+ * [597..598] version u8
50
+ * [598..599] bump u8
51
+ * [599..600] _padding [u8; 1]
52
+ * [600..664] _reserved [u8; 64]
53
+ */
5
54
  export declare function deserializeStv(data: Buffer): Stv;
55
+ /**
56
+ * WithdrawRequest — per-(STV, user, epoch) withdraw escrow. Total 168 bytes.
57
+ *
58
+ * Layout (offsets include the 8-byte discriminator):
59
+ * [ 0.. 8] discriminator (sha256("account:WithdrawRequest")[..8])
60
+ * [ 8.. 40] stv Pubkey
61
+ * [ 40.. 72] user Pubkey
62
+ * [ 72.. 80] shares u64
63
+ * [ 80.. 88] pps u64 (locked at process_epoch time)
64
+ * [ 88.. 92] epochId u32
65
+ * [ 92.. 96] claimAvailableAfter u32 (unix seconds)
66
+ * [ 96.. 97] bump u8
67
+ * [ 97..168] _reserved [u8; 71]
68
+ */
6
69
  export declare function deserializeWithdrawRequest(data: Buffer): WithdrawRequest;
70
+ /**
71
+ * ManagerRole — per-(STV, manager) authorization record. Total 80 bytes.
72
+ *
73
+ * Layout (offsets include the 8-byte discriminator):
74
+ * [ 0.. 8] discriminator (sha256("account:ManagerRole")[..8] —
75
+ * shared with elemental-lend + jlpd-strategy)
76
+ * [ 8.. 40] stv Pubkey
77
+ * [ 40.. 72] manager Pubkey
78
+ * [ 72.. 73] bump u8
79
+ * [ 73.. 80] _padding [u8; 7]
80
+ */
7
81
  export declare function deserializeManagerRole(data: Buffer): ManagerRole;
8
- export declare function fetchGlobalConfig(connection: Connection, programId?: PublicKey): Promise<GlobalConfig>;
9
- export declare function fetchStv(connection: Connection, vaultId: number | BN, programId?: PublicKey): Promise<Stv>;
10
- export declare function fetchStvByAddress(connection: Connection, address: PublicKey): Promise<Stv>;
11
- export declare function fetchWithdrawRequest(connection: Connection, stv: PublicKey, user: PublicKey, epochId: number, programId?: PublicKey): Promise<WithdrawRequest>;
12
- export declare function fetchWithdrawRequestByAddress(connection: Connection, address: PublicKey): Promise<WithdrawRequest>;
13
- export declare function fetchAllStvs(connection: Connection, programId?: PublicKey): Promise<[PublicKey, Stv][]>;
14
- export declare function fetchPendingWithdrawRequests(connection: Connection, stv: PublicKey, epochId: number, programId?: PublicKey): Promise<[PublicKey, WithdrawRequest][]>;
15
- export declare function fetchManagerRole(connection: Connection, stv: PublicKey, manager: PublicKey, programId?: PublicKey): Promise<ManagerRole | null>;
16
- export declare function fetchManagersForStv(connection: Connection, stv: PublicKey, programId?: PublicKey): Promise<[PublicKey, ManagerRole][]>;
17
- //# sourceMappingURL=accounts.d.ts.map
82
+ export declare function fetchGlobalConfig(connection: SolanaConnection, programId?: PublicKey): Promise<GlobalConfig>;
83
+ export declare function fetchStv(connection: SolanaConnection, vaultId: number | BN, programId?: PublicKey): Promise<Stv>;
84
+ export declare function fetchStvByAddress(connection: SolanaConnection, address: PublicKey): Promise<Stv>;
85
+ export declare function fetchWithdrawRequest(connection: SolanaConnection, stv: PublicKey, user: PublicKey, epochId: number, programId?: PublicKey): Promise<WithdrawRequest>;
86
+ export declare function fetchWithdrawRequestByAddress(connection: SolanaConnection, address: PublicKey): Promise<WithdrawRequest>;
87
+ export declare function fetchAllStvs(connection: SolanaConnection, programId?: PublicKey): Promise<[PublicKey, Stv][]>;
88
+ export declare function fetchPendingWithdrawRequests(connection: SolanaConnection, stv: PublicKey, epochId: number, programId?: PublicKey): Promise<[PublicKey, WithdrawRequest][]>;
89
+ export declare function fetchManagerRole(connection: SolanaConnection, stv: PublicKey, manager: PublicKey, programId?: PublicKey): Promise<ManagerRole | null>;
90
+ export declare function fetchManagersForStv(connection: SolanaConnection, stv: PublicKey, programId?: PublicKey): Promise<[PublicKey, ManagerRole][]>;
@@ -18,7 +18,25 @@ const constants_1 = require("./constants");
18
18
  const pda_1 = require("./pda");
19
19
  // ---------------------------------------------------------------------------
20
20
  // Deserialization
21
+ //
22
+ // All offsets below INCLUDE the 8-byte Anchor account discriminator. Layout
23
+ // blocks above each parser show the field map; the helpers in
24
+ // `common/buffer.ts` validate that `offset + width <= data.length` so a
25
+ // drift between this file and the on-chain layout fails loudly with a
26
+ // `RangeError` rather than returning garbage.
21
27
  // ---------------------------------------------------------------------------
28
+ /**
29
+ * GlobalConfig — singleton protocol registry. Total 56 bytes.
30
+ *
31
+ * Layout (offsets include the 8-byte discriminator):
32
+ * [ 0.. 8] discriminator (sha256("account:GlobalConfig")[..8])
33
+ * [ 8.. 40] admin Pubkey
34
+ * [ 40.. 48] nextVaultId u64
35
+ * [ 48.. 50] flags u16 (CFG_FLAG_*)
36
+ * [ 50.. 51] version u8
37
+ * [ 51.. 52] bump u8
38
+ * [ 52.. 56] _padding [u8; 4]
39
+ */
22
40
  function deserializeGlobalConfig(data) {
23
41
  if (data.length < constants_1.GLOBAL_CONFIG_SIZE) {
24
42
  throw new Error(`GlobalConfig data too short: ${data.length} < ${constants_1.GLOBAL_CONFIG_SIZE}`);
@@ -35,6 +53,42 @@ function deserializeGlobalConfig(data) {
35
53
  bump: (0, buffer_1.readU8)(data, 51),
36
54
  };
37
55
  }
56
+ /**
57
+ * STV — per-vault state. Total 664 bytes.
58
+ *
59
+ * Layout (offsets include the 8-byte discriminator):
60
+ * [ 0.. 8] discriminator (sha256("account:Stv")[..8])
61
+ * [ 8.. 40] baseMint Pubkey
62
+ * [ 40.. 72] evMint Pubkey
63
+ * [ 72..104] strategy Pubkey (legacy single-strategy slot)
64
+ * [104..136] feeReceiver Pubkey
65
+ * [136..168] lendProgram Pubkey (zero pubkey if lend not opted-in)
66
+ * [168..488] strategies[10] [Pubkey; 10] (whitelisted strategy programs)
67
+ * [488..496] vaultId u64
68
+ * [496..504] reservedBase u64 (base reserved for pending claims)
69
+ * [504..512] requestedBase u64 (base requested via request_withdraw)
70
+ * [512..520] vaultCapacity u64 (0 = uncapped)
71
+ * [520..528] minDeposit u64
72
+ * [528..536] hwm u64 (high-water mark for perf fees)
73
+ * [536..544] lastFeeTs u64 (last fee crystallization timestamp)
74
+ * [544..552] epochPps u64 (locked PPS for current epoch claims)
75
+ * [552..560] lastNav u64 (snapshot for the rate-limit window)
76
+ * [560..568] dailyWithdrawnBase u64 (rate-limit accumulator)
77
+ * [568..572] nextEpochTs u32
78
+ * [572..576] epochSec u32
79
+ * [576..580] currentEpochId u32
80
+ * [580..584] pendingWithdrawals u32
81
+ * [584..588] withdrawWindowStart u32
82
+ * [588..590] mgmtFeeBps u16
83
+ * [590..592] perfFeeBps u16
84
+ * [592..594] flags u16 (FLAG_PAUSED / DEPOSITS_DISABLED / …)
85
+ * [594..596] dailyWithdrawLimitBps u16
86
+ * [596..597] strategyCount u8
87
+ * [597..598] version u8
88
+ * [598..599] bump u8
89
+ * [599..600] _padding [u8; 1]
90
+ * [600..664] _reserved [u8; 64]
91
+ */
38
92
  function deserializeStv(data) {
39
93
  if (data.length < constants_1.STV_SIZE) {
40
94
  throw new Error(`Stv data too short: ${data.length} < ${constants_1.STV_SIZE}`);
@@ -44,7 +98,7 @@ function deserializeStv(data) {
44
98
  throw new Error(`Invalid Stv discriminator`);
45
99
  }
46
100
  const strategies = [];
47
- for (let i = 0; i < 10; i++) {
101
+ for (let i = 0; i < constants_1.MAX_STRATEGIES; i++) {
48
102
  strategies.push((0, buffer_1.readPubkey)(data, 168 + i * 32));
49
103
  }
50
104
  return {
@@ -78,6 +132,20 @@ function deserializeStv(data) {
78
132
  bump: (0, buffer_1.readU8)(data, 598),
79
133
  };
80
134
  }
135
+ /**
136
+ * WithdrawRequest — per-(STV, user, epoch) withdraw escrow. Total 168 bytes.
137
+ *
138
+ * Layout (offsets include the 8-byte discriminator):
139
+ * [ 0.. 8] discriminator (sha256("account:WithdrawRequest")[..8])
140
+ * [ 8.. 40] stv Pubkey
141
+ * [ 40.. 72] user Pubkey
142
+ * [ 72.. 80] shares u64
143
+ * [ 80.. 88] pps u64 (locked at process_epoch time)
144
+ * [ 88.. 92] epochId u32
145
+ * [ 92.. 96] claimAvailableAfter u32 (unix seconds)
146
+ * [ 96.. 97] bump u8
147
+ * [ 97..168] _reserved [u8; 71]
148
+ */
81
149
  function deserializeWithdrawRequest(data) {
82
150
  if (data.length < constants_1.WITHDRAW_REQUEST_SIZE) {
83
151
  throw new Error(`WithdrawRequest data too short: ${data.length} < ${constants_1.WITHDRAW_REQUEST_SIZE}`);
@@ -96,6 +164,17 @@ function deserializeWithdrawRequest(data) {
96
164
  bump: (0, buffer_1.readU8)(data, 96),
97
165
  };
98
166
  }
167
+ /**
168
+ * ManagerRole — per-(STV, manager) authorization record. Total 80 bytes.
169
+ *
170
+ * Layout (offsets include the 8-byte discriminator):
171
+ * [ 0.. 8] discriminator (sha256("account:ManagerRole")[..8] —
172
+ * shared with elemental-lend + jlpd-strategy)
173
+ * [ 8.. 40] stv Pubkey
174
+ * [ 40.. 72] manager Pubkey
175
+ * [ 72.. 73] bump u8
176
+ * [ 73.. 80] _padding [u8; 7]
177
+ */
99
178
  function deserializeManagerRole(data) {
100
179
  if (data.length < constants_1.MANAGER_ROLE_SIZE) {
101
180
  throw new Error(`ManagerRole data too short: ${data.length} < ${constants_1.MANAGER_ROLE_SIZE}`);
@@ -165,14 +244,14 @@ async function fetchPendingWithdrawRequests(connection, stv, epochId, programId
165
244
  filters: [
166
245
  { dataSize: constants_1.WITHDRAW_REQUEST_SIZE },
167
246
  { memcmp: { offset: 0, bytes: constants_1.DISC_WITHDRAW_REQUEST.toString("base64"), encoding: "base64" } },
168
- { memcmp: { offset: 8, bytes: stv.toBase58() } },
247
+ { memcmp: { offset: 8, bytes: stv.toBuffer().toString("base64"), encoding: "base64" } },
169
248
  { memcmp: { offset: 88, bytes: epochBuf.toString("base64"), encoding: "base64" } },
170
249
  ],
171
250
  });
172
251
  return accounts.map((a) => [a.pubkey, deserializeWithdrawRequest(a.account.data)]);
173
252
  }
174
253
  async function fetchManagerRole(connection, stv, manager, programId = constants_1.PROGRAM_ID) {
175
- const [pda] = (0, pda_1.findManagerRolePda)(stv, manager, programId);
254
+ const [pda] = (0, pda_1.findStvManagerRolePda)(stv, manager, programId);
176
255
  const info = await connection.getAccountInfo(pda);
177
256
  if (!info)
178
257
  return null;
@@ -183,9 +262,8 @@ async function fetchManagersForStv(connection, stv, programId = constants_1.PROG
183
262
  filters: [
184
263
  { dataSize: constants_1.MANAGER_ROLE_SIZE },
185
264
  { memcmp: { offset: 0, bytes: constants_1.DISC_MANAGER_ROLE.toString("base64"), encoding: "base64" } },
186
- { memcmp: { offset: 8, bytes: stv.toBase58() } },
265
+ { memcmp: { offset: 8, bytes: stv.toBuffer().toString("base64"), encoding: "base64" } },
187
266
  ],
188
267
  });
189
268
  return accounts.map((a) => [a.pubkey, deserializeManagerRole(a.account.data)]);
190
269
  }
191
- //# sourceMappingURL=accounts.js.map
@@ -8,7 +8,7 @@ export declare const MANAGER_SEED: Buffer<ArrayBuffer>;
8
8
  export declare const DISC_GLOBAL_CONFIG: Buffer<ArrayBuffer>;
9
9
  export declare const DISC_STV: Buffer<ArrayBuffer>;
10
10
  export declare const DISC_WITHDRAW_REQUEST: Buffer<ArrayBuffer>;
11
- export declare const DISC_MANAGER_ROLE: Buffer<ArrayBuffer>;
11
+ export { DISC_MANAGER_ROLE } from "../common/constants";
12
12
  export declare const IX_INIT_OR_UPDATE_CONFIG = 0;
13
13
  export declare const IX_INIT_OR_UPDATE_STV = 1;
14
14
  export declare const IX_DEPOSIT = 2;
@@ -21,6 +21,7 @@ export declare const IX_CLOSE_STV = 8;
21
21
  export declare const IX_ADD_MANAGER = 9;
22
22
  export declare const IX_REMOVE_MANAGER = 10;
23
23
  export declare const IX_OVERRIDE_CLAIM_WITHDRAW = 11;
24
+ export declare const IX_MIGRATE_LEND = 12;
24
25
  export declare const EVT_CONFIG_INITIALIZED = 0;
25
26
  export declare const EVT_CONFIG_UPDATED = 1;
26
27
  export declare const EVT_STV_CREATED = 2;
@@ -38,13 +39,22 @@ export declare const EVT_STV_CLOSED = 13;
38
39
  export declare const EVT_MANAGER_ADDED = 14;
39
40
  export declare const EVT_MANAGER_REMOVED = 15;
40
41
  export declare const EVT_WITHDRAW_OVERRIDE_CLAIMED = 16;
42
+ export declare const EVT_LEND_MIGRATED = 17;
41
43
  export declare const FLAG_PAUSED = 1;
42
44
  export declare const FLAG_DEPOSITS_DISABLED = 2;
43
45
  export declare const FLAG_WITHDRAWALS_DISABLED = 4;
44
46
  export declare const FLAG_REBALANCE_DISABLED = 8;
45
47
  export declare const FLAG_TEST_MODE = 16;
46
48
  export declare const FLAG_ALLOCATOR = 32;
47
- export declare const CFG_FLAG_ADMIN_LOCKED = 1;
49
+ /**
50
+ * Protocol-wide emergency pause. When set on `GlobalConfig.flags`, blocks
51
+ * every value-movement instruction across every STV (deposit, request/claim
52
+ * withdraw, process_epoch, deposit/withdraw_from_strategy,
53
+ * override_claim_withdraw). Admin/rescue paths
54
+ * (init_or_update_config, init_or_update_stv, close_stv, add/remove_manager)
55
+ * remain open so the admin can reconfigure and clear the pause.
56
+ */
57
+ export declare const CFG_FLAG_GLOBAL_PAUSED = 1;
48
58
  export { PPS_DECIMALS, BPS_DENOMINATOR, STALENESS_THRESHOLD } from "../common/constants";
49
59
  export declare const MAX_STRATEGIES = 10;
50
60
  export declare const FEE_CAP_BPS = 9900;
@@ -52,4 +62,3 @@ export declare const GLOBAL_CONFIG_SIZE = 56;
52
62
  export declare const STV_SIZE = 664;
53
63
  export declare const WITHDRAW_REQUEST_SIZE = 168;
54
64
  export declare const MANAGER_ROLE_SIZE = 80;
55
- //# sourceMappingURL=constants.d.ts.map
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.MAX_STRATEGIES = exports.STALENESS_THRESHOLD = exports.BPS_DENOMINATOR = exports.PPS_DECIMALS = exports.CFG_FLAG_ADMIN_LOCKED = exports.FLAG_ALLOCATOR = exports.FLAG_TEST_MODE = exports.FLAG_REBALANCE_DISABLED = exports.FLAG_WITHDRAWALS_DISABLED = exports.FLAG_DEPOSITS_DISABLED = exports.FLAG_PAUSED = exports.EVT_WITHDRAW_OVERRIDE_CLAIMED = exports.EVT_MANAGER_REMOVED = exports.EVT_MANAGER_ADDED = exports.EVT_STV_CLOSED = exports.EVT_FEES_SETTLED = exports.EVT_EPOCH_ADVANCED = exports.EVT_EPOCH_PROCESSED = exports.EVT_WITHDRAWN_FROM_STRATEGY = exports.EVT_DEPOSITED_TO_STRATEGY = exports.EVT_WITHDRAW_CLAIMED = exports.EVT_WITHDRAW_REQUEST_INCREASED = exports.EVT_WITHDRAW_REQUESTED = exports.EVT_DEPOSITED = exports.EVT_STV_UPDATED = exports.EVT_STV_CREATED = exports.EVT_CONFIG_UPDATED = exports.EVT_CONFIG_INITIALIZED = exports.IX_OVERRIDE_CLAIM_WITHDRAW = exports.IX_REMOVE_MANAGER = exports.IX_ADD_MANAGER = exports.IX_CLOSE_STV = exports.IX_WITHDRAW_FROM_STRATEGY = exports.IX_DEPOSIT_TO_STRATEGY = exports.IX_PROCESS_EPOCH = exports.IX_CLAIM_WITHDRAW = exports.IX_REQUEST_WITHDRAW = exports.IX_DEPOSIT = exports.IX_INIT_OR_UPDATE_STV = exports.IX_INIT_OR_UPDATE_CONFIG = exports.DISC_MANAGER_ROLE = exports.DISC_WITHDRAW_REQUEST = exports.DISC_STV = exports.DISC_GLOBAL_CONFIG = exports.MANAGER_SEED = exports.WITHDRAW_REQUEST_SEED = exports.EV_MINT_SEED = exports.STV_SEED = exports.CONFIG_SEED = exports.PROGRAM_ID = void 0;
4
- exports.MANAGER_ROLE_SIZE = exports.WITHDRAW_REQUEST_SIZE = exports.STV_SIZE = exports.GLOBAL_CONFIG_SIZE = exports.FEE_CAP_BPS = void 0;
3
+ exports.BPS_DENOMINATOR = exports.PPS_DECIMALS = exports.CFG_FLAG_GLOBAL_PAUSED = exports.FLAG_ALLOCATOR = exports.FLAG_TEST_MODE = exports.FLAG_REBALANCE_DISABLED = exports.FLAG_WITHDRAWALS_DISABLED = exports.FLAG_DEPOSITS_DISABLED = exports.FLAG_PAUSED = exports.EVT_LEND_MIGRATED = exports.EVT_WITHDRAW_OVERRIDE_CLAIMED = exports.EVT_MANAGER_REMOVED = exports.EVT_MANAGER_ADDED = exports.EVT_STV_CLOSED = exports.EVT_FEES_SETTLED = exports.EVT_EPOCH_ADVANCED = exports.EVT_EPOCH_PROCESSED = exports.EVT_WITHDRAWN_FROM_STRATEGY = exports.EVT_DEPOSITED_TO_STRATEGY = exports.EVT_WITHDRAW_CLAIMED = exports.EVT_WITHDRAW_REQUEST_INCREASED = exports.EVT_WITHDRAW_REQUESTED = exports.EVT_DEPOSITED = exports.EVT_STV_UPDATED = exports.EVT_STV_CREATED = exports.EVT_CONFIG_UPDATED = exports.EVT_CONFIG_INITIALIZED = exports.IX_MIGRATE_LEND = exports.IX_OVERRIDE_CLAIM_WITHDRAW = exports.IX_REMOVE_MANAGER = exports.IX_ADD_MANAGER = exports.IX_CLOSE_STV = exports.IX_WITHDRAW_FROM_STRATEGY = exports.IX_DEPOSIT_TO_STRATEGY = exports.IX_PROCESS_EPOCH = exports.IX_CLAIM_WITHDRAW = exports.IX_REQUEST_WITHDRAW = exports.IX_DEPOSIT = exports.IX_INIT_OR_UPDATE_STV = exports.IX_INIT_OR_UPDATE_CONFIG = exports.DISC_MANAGER_ROLE = exports.DISC_WITHDRAW_REQUEST = exports.DISC_STV = exports.DISC_GLOBAL_CONFIG = exports.MANAGER_SEED = exports.WITHDRAW_REQUEST_SEED = exports.EV_MINT_SEED = exports.STV_SEED = exports.CONFIG_SEED = exports.PROGRAM_ID = void 0;
4
+ exports.MANAGER_ROLE_SIZE = exports.WITHDRAW_REQUEST_SIZE = exports.STV_SIZE = exports.GLOBAL_CONFIG_SIZE = exports.FEE_CAP_BPS = exports.MAX_STRATEGIES = exports.STALENESS_THRESHOLD = void 0;
5
5
  const web3_js_1 = require("@solana/web3.js");
6
6
  // ---------------------------------------------------------------------------
7
7
  // Program ID
@@ -27,9 +27,9 @@ exports.DISC_STV = Buffer.from([
27
27
  exports.DISC_WITHDRAW_REQUEST = Buffer.from([
28
28
  0xba, 0xef, 0xae, 0xbf, 0xbd, 0x0d, 0x2f, 0xc4,
29
29
  ]);
30
- exports.DISC_MANAGER_ROLE = Buffer.from([
31
- 0x25, 0xe8, 0x64, 0xe9, 0xaa, 0xe9, 0xdb, 0xb9,
32
- ]);
30
+ // Shared with elemental-lend and jlpd-strategy — defined once in common/
31
+ var constants_1 = require("../common/constants");
32
+ Object.defineProperty(exports, "DISC_MANAGER_ROLE", { enumerable: true, get: function () { return constants_1.DISC_MANAGER_ROLE; } });
33
33
  // ---------------------------------------------------------------------------
34
34
  // Instruction Discriminators (1-byte)
35
35
  // ---------------------------------------------------------------------------
@@ -45,6 +45,7 @@ exports.IX_CLOSE_STV = 8;
45
45
  exports.IX_ADD_MANAGER = 9;
46
46
  exports.IX_REMOVE_MANAGER = 10;
47
47
  exports.IX_OVERRIDE_CLAIM_WITHDRAW = 11;
48
+ exports.IX_MIGRATE_LEND = 12;
48
49
  // ---------------------------------------------------------------------------
49
50
  // Event Discriminators (1-byte)
50
51
  // ---------------------------------------------------------------------------
@@ -65,6 +66,7 @@ exports.EVT_STV_CLOSED = 13;
65
66
  exports.EVT_MANAGER_ADDED = 14;
66
67
  exports.EVT_MANAGER_REMOVED = 15;
67
68
  exports.EVT_WITHDRAW_OVERRIDE_CLAIMED = 16;
69
+ exports.EVT_LEND_MIGRATED = 17;
68
70
  // ---------------------------------------------------------------------------
69
71
  // Vault Flags
70
72
  // ---------------------------------------------------------------------------
@@ -76,14 +78,22 @@ exports.FLAG_REBALANCE_DISABLED = 0x0008;
76
78
  exports.FLAG_TEST_MODE = 0x0010;
77
79
  exports.FLAG_ALLOCATOR = 0x0020;
78
80
  // GlobalConfig flags
79
- exports.CFG_FLAG_ADMIN_LOCKED = 0x0001;
81
+ /**
82
+ * Protocol-wide emergency pause. When set on `GlobalConfig.flags`, blocks
83
+ * every value-movement instruction across every STV (deposit, request/claim
84
+ * withdraw, process_epoch, deposit/withdraw_from_strategy,
85
+ * override_claim_withdraw). Admin/rescue paths
86
+ * (init_or_update_config, init_or_update_stv, close_stv, add/remove_manager)
87
+ * remain open so the admin can reconfigure and clear the pause.
88
+ */
89
+ exports.CFG_FLAG_GLOBAL_PAUSED = 0x0001;
80
90
  // ---------------------------------------------------------------------------
81
91
  // Protocol Constants
82
92
  // ---------------------------------------------------------------------------
83
- var constants_1 = require("../common/constants");
84
- Object.defineProperty(exports, "PPS_DECIMALS", { enumerable: true, get: function () { return constants_1.PPS_DECIMALS; } });
85
- Object.defineProperty(exports, "BPS_DENOMINATOR", { enumerable: true, get: function () { return constants_1.BPS_DENOMINATOR; } });
86
- Object.defineProperty(exports, "STALENESS_THRESHOLD", { enumerable: true, get: function () { return constants_1.STALENESS_THRESHOLD; } });
93
+ var constants_2 = require("../common/constants");
94
+ Object.defineProperty(exports, "PPS_DECIMALS", { enumerable: true, get: function () { return constants_2.PPS_DECIMALS; } });
95
+ Object.defineProperty(exports, "BPS_DENOMINATOR", { enumerable: true, get: function () { return constants_2.BPS_DENOMINATOR; } });
96
+ Object.defineProperty(exports, "STALENESS_THRESHOLD", { enumerable: true, get: function () { return constants_2.STALENESS_THRESHOLD; } });
87
97
  exports.MAX_STRATEGIES = 10;
88
98
  exports.FEE_CAP_BPS = 9900;
89
99
  // ---------------------------------------------------------------------------
@@ -93,4 +103,3 @@ exports.GLOBAL_CONFIG_SIZE = 56;
93
103
  exports.STV_SIZE = 664;
94
104
  exports.WITHDRAW_REQUEST_SIZE = 168;
95
105
  exports.MANAGER_ROLE_SIZE = 80;
96
- //# sourceMappingURL=constants.js.map
@@ -5,4 +5,3 @@ import type { StvEvent } from "./types";
5
5
  * p-stv-core uses 1-byte event discriminators via sol_log_data.
6
6
  */
7
7
  export declare function parseEventsFromLogs(logs: string[], programId?: PublicKey): StvEvent[];
8
- //# sourceMappingURL=events.d.ts.map
@@ -40,6 +40,45 @@ function parseEventsFromLogs(logs, programId = constants_1.PROGRAM_ID) {
40
40
  }
41
41
  return events;
42
42
  }
43
+ /**
44
+ * p-stv-core event payload layout reference (offsets are within the
45
+ * `Program data: …` log buffer; see also `EVT_*` discriminators in
46
+ * `constants.ts`):
47
+ *
48
+ * ConfigInitialized [0..1] disc | [1..33] admin
49
+ * ConfigUpdated [0..1] disc | [1..33] admin | [33..35] flags
50
+ * StvCreated [0..1] disc | [1..9] vaultId | [9..41] baseMint |
51
+ * [41..73] evMint | [73..105] feeReceiver | [105..137] strategy |
52
+ * [137..169] lendProgram | [169..173] epochSec |
53
+ * [173..175] mgmtFeeBps | [175..177] perfFeeBps
54
+ * StvUpdated [0..1] disc | [1..9] vaultId | [9..41] feeReceiver |
55
+ * [41..43] flags | [43..45] mgmtFeeBps | [45..47] perfFeeBps |
56
+ * [47..55] vaultCapacity | [55..63] minDeposit |
57
+ * [63..64] strategyCount | [64..96] lendProgram
58
+ * Deposited [0..1] disc | [1..9] vaultId | [9..41] user |
59
+ * [41..49] amount | [49..57] sharesMinted | [57..65] pps
60
+ * WithdrawRequested [0..1] disc | [1..9] vaultId | [9..41] user |
61
+ * [41..49] shares | [49..53] epochId
62
+ * WithdrawRequestIncreased [0..1] disc | [1..9] vaultId | [9..41] user |
63
+ * [41..49] additionalShares | [49..57] totalShares |
64
+ * [57..61] epochId
65
+ * WithdrawClaimed [0..1] disc | [1..9] vaultId | [9..41] user |
66
+ * [41..49] shares | [49..57] baseAmount | [57..61] epochId
67
+ * DepositedToStrategy [0..1] disc | [1..9] vaultId | [9..41] strategy |
68
+ * [41..49] amount | [49..57] sharesReceived
69
+ * WithdrawnFromStrategy [0..1] disc | [1..9] vaultId | [9..41] strategy |
70
+ * [41..49] shares | [49..57] baseReceived
71
+ * EpochProcessed [0..1] disc | [1..9] vaultId | [9..13] epochId |
72
+ * [13..21] epochPps | [21..29] feeSharesMinted
73
+ * EpochAdvanced [0..1] disc | [1..9] vaultId | [9..13] newEpochId |
74
+ * [13..17] nextEpochTs
75
+ * FeesSettled [0..1] disc | [1..9] vaultId | [9..17] mgmtFeeBase |
76
+ * [17..25] perfFeeBase | [25..33] feeSharesMinted |
77
+ * [33..41] postFeePps | [41..49] hwm
78
+ * StvClosed [0..1] disc | [1..9] vaultId
79
+ * ManagerAdded [0..1] disc | [1..33] stv | [33..65] manager
80
+ * ManagerRemoved [0..1] disc | [1..33] stv | [33..65] manager
81
+ */
43
82
  function parseEventBuffer(data) {
44
83
  if (data.length === 0)
45
84
  return null;
@@ -120,8 +159,18 @@ function parseEventBuffer(data) {
120
159
  return data.length >= 65 ? {
121
160
  name: "ManagerRemoved", stv: (0, buffer_1.readPubkey)(data, 1), manager: (0, buffer_1.readPubkey)(data, 33),
122
161
  } : null;
162
+ case constants_1.EVT_WITHDRAW_OVERRIDE_CLAIMED:
163
+ return data.length >= 109 ? {
164
+ name: "WithdrawOverrideClaimed", vaultId: (0, buffer_1.readU64)(data, 1), manager: (0, buffer_1.readPubkey)(data, 9),
165
+ user: (0, buffer_1.readPubkey)(data, 41), shares: (0, buffer_1.readU64)(data, 73), baseAmount: (0, buffer_1.readU64)(data, 81),
166
+ epochId: (0, buffer_1.readU32)(data, 89), dailyWithdrawnBase: (0, buffer_1.readU64)(data, 93), dailyLimit: (0, buffer_1.readU64)(data, 101),
167
+ } : null;
168
+ case constants_1.EVT_LEND_MIGRATED:
169
+ return data.length >= 89 ? {
170
+ name: "LendMigrated", vaultId: (0, buffer_1.readU64)(data, 1), oldLendProgram: (0, buffer_1.readPubkey)(data, 9),
171
+ newLendProgram: (0, buffer_1.readPubkey)(data, 41), sharesWithdrawn: (0, buffer_1.readU64)(data, 73), baseMigrated: (0, buffer_1.readU64)(data, 81),
172
+ } : null;
123
173
  default:
124
174
  return null;
125
175
  }
126
176
  }
127
- //# sourceMappingURL=events.js.map