@elemental-stv-core/sdk 0.4.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 (149) 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 +6 -7
  18. package/dist/elemental-lend/constants.js +13 -12
  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 +60 -0
  38. package/dist/jlpd-strategy/adapter.js +90 -0
  39. package/dist/jlpd-strategy/constants.d.ts +27 -16
  40. package/dist/jlpd-strategy/constants.js +40 -29
  41. package/dist/jlpd-strategy/index.d.ts +3 -1
  42. package/dist/jlpd-strategy/index.js +3 -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 +63 -0
  46. package/dist/jlpd-strategy/jlp-borrow.js +87 -0
  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 +90 -0
  50. package/dist/jlpd-strategy/jupusd-earn.js +166 -0
  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 +13 -3
  62. package/dist/p-stv-core/constants.js +23 -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 +23 -7
  76. package/dist/p-stv-core/send-tx.js +17 -26
  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/constants.d.ts.map +0 -1
  113. package/dist/jlpd-strategy/constants.js.map +0 -1
  114. package/dist/jlpd-strategy/index.d.ts.map +0 -1
  115. package/dist/jlpd-strategy/index.js.map +0 -1
  116. package/dist/jlpd-strategy/instructions.d.ts.map +0 -1
  117. package/dist/jlpd-strategy/instructions.js.map +0 -1
  118. package/dist/jlpd-strategy/jlp-data.d.ts.map +0 -1
  119. package/dist/jlpd-strategy/jlp-data.js.map +0 -1
  120. package/dist/jlpd-strategy/pda.d.ts.map +0 -1
  121. package/dist/jlpd-strategy/pda.js.map +0 -1
  122. package/dist/jlpd-strategy/settle-yield.d.ts.map +0 -1
  123. package/dist/jlpd-strategy/settle-yield.js.map +0 -1
  124. package/dist/jlpd-strategy/swap-jlp.d.ts.map +0 -1
  125. package/dist/jlpd-strategy/swap-jlp.js.map +0 -1
  126. package/dist/jlpd-strategy/types.d.ts.map +0 -1
  127. package/dist/jlpd-strategy/types.js.map +0 -1
  128. package/dist/p-stv-core/accounts.d.ts.map +0 -1
  129. package/dist/p-stv-core/accounts.js.map +0 -1
  130. package/dist/p-stv-core/constants.d.ts.map +0 -1
  131. package/dist/p-stv-core/constants.js.map +0 -1
  132. package/dist/p-stv-core/events.d.ts.map +0 -1
  133. package/dist/p-stv-core/events.js.map +0 -1
  134. package/dist/p-stv-core/index.d.ts.map +0 -1
  135. package/dist/p-stv-core/index.js.map +0 -1
  136. package/dist/p-stv-core/instructions.d.ts.map +0 -1
  137. package/dist/p-stv-core/instructions.js.map +0 -1
  138. package/dist/p-stv-core/pda.d.ts.map +0 -1
  139. package/dist/p-stv-core/pda.js.map +0 -1
  140. package/dist/p-stv-core/prices.d.ts.map +0 -1
  141. package/dist/p-stv-core/prices.js.map +0 -1
  142. package/dist/p-stv-core/remaining-accounts.d.ts.map +0 -1
  143. package/dist/p-stv-core/remaining-accounts.js.map +0 -1
  144. package/dist/p-stv-core/send-tx.d.ts.map +0 -1
  145. package/dist/p-stv-core/send-tx.js.map +0 -1
  146. package/dist/p-stv-core/sol-wrap.d.ts.map +0 -1
  147. package/dist/p-stv-core/sol-wrap.js.map +0 -1
  148. package/dist/p-stv-core/types.d.ts.map +0 -1
  149. package/dist/p-stv-core/types.js.map +0 -1
@@ -4,12 +4,14 @@
4
4
  * Builds complete instruction arrays for deposit/withdraw to/from
5
5
  * Kamino kVault and Jupiter Lend protocols. Ready to pass to sendSmartTx.
6
6
  */
7
- import { Connection, PublicKey, TransactionInstruction } from "@solana/web3.js";
7
+ import { PublicKey, TransactionInstruction } from "@solana/web3.js";
8
8
  /**
9
- * Minimal connection interface to avoid nominal type mismatches when the
10
- * consumer has a different version of @solana/web3.js installed.
9
+ * Connection interface required by the protocol-action builders. This is a
10
+ * narrower subset of the canonical `SolanaConnection` defined in
11
+ * `common/connection.ts` — protocol actions only ever need to read accounts.
11
12
  */
12
- export type ProtocolActionConnection = Pick<Connection, "getAccountInfo" | "getMultipleAccountsInfo">;
13
+ import type { SolanaConnection } from "../common/connection";
14
+ export type ProtocolActionConnection = Pick<SolanaConnection, "getAccountInfo" | "getMultipleAccountsInfo">;
13
15
  import type { JupiterLendPool } from "./jupiter-lend";
14
16
  export type ProtocolType = "Kamino kVault" | "Jupiter Lend";
15
17
  export type ProtocolAction = "deposit" | "withdraw";
@@ -46,4 +48,3 @@ export interface ProtocolActionArgs {
46
48
  * @returns TransactionInstruction[] ready for sendSmartTx
47
49
  */
48
50
  export declare function buildProtocolActionIxs(args: ProtocolActionArgs): Promise<TransactionInstruction[]>;
49
- //# sourceMappingURL=protocol-actions.d.ts.map
@@ -9,18 +9,12 @@ Object.defineProperty(exports, "__esModule", { value: true });
9
9
  exports.buildProtocolActionIxs = buildProtocolActionIxs;
10
10
  const web3_js_1 = require("@solana/web3.js");
11
11
  const spl_token_1 = require("@solana/spl-token");
12
+ const ata_1 = require("../common/ata");
12
13
  const constants_1 = require("./constants");
13
14
  const pda_1 = require("./pda");
14
15
  const kamino_vault_1 = require("./kamino-vault");
15
16
  const jupiter_lend_1 = require("./jupiter-lend");
16
17
  // ---------------------------------------------------------------------------
17
- // ATA derivation (inline to avoid spl-token runtime dep)
18
- // ---------------------------------------------------------------------------
19
- function findAta(mint, owner, tokenProgram) {
20
- const [ata] = web3_js_1.PublicKey.findProgramAddressSync([owner.toBuffer(), tokenProgram.toBuffer(), mint.toBuffer()], spl_token_1.ASSOCIATED_TOKEN_PROGRAM_ID);
21
- return ata;
22
- }
23
- // ---------------------------------------------------------------------------
24
18
  // Main Builder
25
19
  // ---------------------------------------------------------------------------
26
20
  /**
@@ -40,8 +34,8 @@ async function buildProtocolActionIxs(args) {
40
34
  const [strategyStatePda] = args.strategyState
41
35
  ? [args.strategyState]
42
36
  : (0, pda_1.findStrategyStatePda)(baseMint, programId);
43
- const strategyBaseAta = findAta(baseMint, strategyStatePda, tokenProgram);
44
- const [managerRolePda] = (0, pda_1.findManagerRolePda)(strategyStatePda, manager, programId);
37
+ const strategyBaseAta = (0, ata_1.findAta)(baseMint, strategyStatePda, tokenProgram);
38
+ const [managerRolePda] = (0, pda_1.findLendManagerRolePda)(strategyStatePda, manager, programId);
45
39
  if (protocolType === "Jupiter Lend") {
46
40
  return buildJupLendActionIxs({
47
41
  connection,
@@ -76,7 +70,7 @@ async function buildProtocolActionIxs(args) {
76
70
  }
77
71
  function buildJupLendActionIxs(params) {
78
72
  const { manager, strategyStatePda, strategyBaseAta, managerRolePda, action, amount, tokenProgram, pool, programId, } = params;
79
- const strategyFtokenAta = findAta(pool.fTokenMint, strategyStatePda, tokenProgram);
73
+ const strategyFtokenAta = (0, ata_1.findAta)(pool.fTokenMint, strategyStatePda, tokenProgram);
80
74
  const JUP_LEND_PROG = new web3_js_1.PublicKey("jup3YeL8QhtSx1e253b2FDvsMNC87fDrgQZivbrndc9");
81
75
  // Fixed accounts for the Anchor instruction
82
76
  const fixedAccounts = [
@@ -132,18 +126,25 @@ async function buildKvaultActionIxs(params) {
132
126
  break;
133
127
  }
134
128
  }
135
- // Fetch all reserves to read their lending_market field
129
+ // Fetch all reserves to read their lending_market field. `readReserveAccounts`
130
+ // (from kamino-vault.ts) is the canonical parser — keeps the KLend Reserve
131
+ // layout constants in one place.
136
132
  const reserveInfos = await connection.getMultipleAccountsInfo(reserveKeys);
137
133
  const klendReserves = [];
138
134
  for (let i = 0; i < reserveKeys.length; i++) {
139
135
  const rInfo = reserveInfos[i];
140
- if (rInfo && rInfo.data.length >= 64) {
141
- const lendingMarket = new web3_js_1.PublicKey(rInfo.data.subarray(32, 64));
136
+ if (!rInfo)
137
+ continue;
138
+ try {
139
+ const { lendingMarket } = (0, kamino_vault_1.readReserveAccounts)(rInfo.data);
142
140
  klendReserves.push({ reserve: reserveKeys[i], lendingMarket });
143
141
  }
142
+ catch {
143
+ // Skip reserves whose data isn't long enough for a full parse
144
+ }
144
145
  }
145
146
  const [sharesMint] = (0, kamino_vault_1.findKvaultSharesMint)(vaultState);
146
- const strategySharesAta = findAta(sharesMint, strategyStatePda, tokenProgram);
147
+ const strategySharesAta = (0, ata_1.findAta)(sharesMint, strategyStatePda, tokenProgram);
147
148
  // Fixed accounts for the Anchor instruction
148
149
  const fixedAccounts = [
149
150
  { pubkey: manager, isSigner: true, isWritable: true },
@@ -188,7 +189,8 @@ async function buildKvaultWithdrawIxs(connection, fixedAccounts, vaultState, vau
188
189
  else {
189
190
  withdrawShares = amount; // fallback: 1:1
190
191
  }
191
- // Cap to actual kvToken balance
192
+ // Cap to actual kvToken balance.
193
+ // SPL Token Account layout: [mint(0..32)][owner(32..64)][amount(64..72)]…
192
194
  const sharesAtaInfo = await connection.getAccountInfo(strategySharesAta);
193
195
  if (sharesAtaInfo) {
194
196
  const actualBalance = sharesAtaInfo.data.readBigUInt64LE(64);
@@ -196,7 +198,11 @@ async function buildKvaultWithdrawIxs(connection, fixedAccounts, vaultState, vau
196
198
  withdrawShares = actualBalance;
197
199
  }
198
200
  }
199
- // Read reserve data for withdraw accounts
201
+ // Read reserve data for withdraw accounts.
202
+ // Kamino VaultState — first allocation slot starts at offset 312:
203
+ // [312..344] reserve Pubkey
204
+ // [344..376] ctokenVault Pubkey
205
+ // (See `kamino-vault.ts:VAULT_ALLOCATION_OFFSET` for the full table.)
200
206
  const reserveKey = new web3_js_1.PublicKey(vaultData.subarray(312, 344));
201
207
  const reserveInfo = await connection.getAccountInfo(reserveKey);
202
208
  if (!reserveInfo)
@@ -225,4 +231,3 @@ async function buildKvaultWithdrawIxs(connection, fixedAccounts, vaultState, vau
225
231
  });
226
232
  return [ix];
227
233
  }
228
- //# sourceMappingURL=protocol-actions.js.map
@@ -110,4 +110,3 @@ export interface ManagerRemovedEvent {
110
110
  manager: PublicKey;
111
111
  }
112
112
  export type LendEvent = StrategyInitializedEvent | StrategyUpdatedEvent | PositionInitializedEvent | LendDepositEvent | LendWithdrawEvent | AumUpdatedEvent | KvaultDepositEvent | KvaultWithdrawEvent | JupLendDepositEvent | JupLendWithdrawEvent | ProtocolAddedEvent | ProtocolRemovedEvent | ManagerAddedEvent | ManagerRemovedEvent;
113
- //# 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
package/dist/index.d.ts CHANGED
@@ -2,4 +2,3 @@ export * as common from "./common";
2
2
  export * as pStvCore from "./p-stv-core";
3
3
  export * as elementalLend from "./elemental-lend";
4
4
  export * as jlpdStrategy from "./jlpd-strategy";
5
- //# sourceMappingURL=index.d.ts.map
package/dist/index.js CHANGED
@@ -38,4 +38,3 @@ exports.common = __importStar(require("./common"));
38
38
  exports.pStvCore = __importStar(require("./p-stv-core"));
39
39
  exports.elementalLend = __importStar(require("./elemental-lend"));
40
40
  exports.jlpdStrategy = __importStar(require("./jlpd-strategy"));
41
- //# sourceMappingURL=index.js.map
@@ -1,17 +1,70 @@
1
- import { Connection, PublicKey } from "@solana/web3.js";
1
+ import { PublicKey } from "@solana/web3.js";
2
2
  import type { StvPosition } from "../common/strategy-interface";
3
+ import type { SolanaConnection } from "../common/connection";
3
4
  import { JlpdConfig, ManagerRole, JlpStrategyState } from "./types";
5
+ /**
6
+ * JlpdConfig — singleton config shared across all five base-asset strategies.
7
+ * Total 272 bytes.
8
+ *
9
+ * Layout (offsets include the 8-byte discriminator):
10
+ * [ 0.. 8] discriminator (sha256("account:JlpdConfig")[..8])
11
+ * [ 8.. 40] admin Pubkey
12
+ * [ 40.. 72] jlpMint Pubkey
13
+ * [ 72..232] baseAssetMints[5] [Pubkey; 5] (BTC, ETH, SOL, USDC, JupUSD)
14
+ * [232..240] oracleStalenessTh u64 (max age in seconds)
15
+ * [240..242] flags u16
16
+ * [242..244] jlpSlippageBps u16 (max slippage on swap_jlp)
17
+ * [244..245] version u8
18
+ * [245..246] bump u8
19
+ * [246..272] _reserved [u8; 26]
20
+ */
4
21
  export declare function deserializeJlpdConfig(data: Buffer): JlpdConfig;
5
- /** @deprecated Use deserializeJlpdConfig instead */
6
- export declare const deserializeJlpVault: typeof deserializeJlpdConfig;
22
+ /**
23
+ * ManagerRole per-(config, manager) authorization. Total 80 bytes.
24
+ *
25
+ * Layout (offsets include the 8-byte discriminator):
26
+ * [ 0.. 8] discriminator (sha256("account:ManagerRole")[..8] —
27
+ * shared with p-stv-core + elemental-lend)
28
+ * [ 8.. 40] config Pubkey
29
+ * [ 40.. 72] manager Pubkey
30
+ * [ 72.. 73] bump u8
31
+ * [ 73.. 80] _padding [u8; 7]
32
+ */
7
33
  export declare function deserializeManagerRole(data: Buffer): ManagerRole;
34
+ /**
35
+ * JlpStrategyState — per-base-asset JLPD strategy account. Total 224 bytes.
36
+ *
37
+ * Layout (offsets include the 8-byte discriminator):
38
+ * [ 0.. 8] discriminator (sha256("account:StrategyState")[..8] —
39
+ * shared with elemental-lend)
40
+ * --- StrategyStateHeader (104 bytes, identical across all strategy programs) ---
41
+ * [ 8.. 40] baseMint Pubkey
42
+ * [ 40.. 72] authority Pubkey (p-stv-core program)
43
+ * [ 72.. 80] pps u64 (scaled by PPS_DECIMALS = 10^9)
44
+ * [ 80.. 88] totalAum u64
45
+ * [ 88.. 96] totalShares u64
46
+ * [ 96..104] lastUpdated u64 (unix seconds)
47
+ * [104..106] flags u16
48
+ * [106..107] version u8
49
+ * [107..108] bump u8
50
+ * [108..112] _headerPadding [u8; 4]
51
+ * --- Custom JLPD fields (112 bytes) ---
52
+ * [112..120] baseLoaned u64 (base assets swapped into JLP)
53
+ * [120..224] _reserved [u8; 104]
54
+ */
8
55
  export declare function deserializeJlpStrategyState(data: Buffer): JlpStrategyState;
56
+ /**
57
+ * StvPosition — per-STV virtual share record. Total 120 bytes.
58
+ *
59
+ * The on-disk layout is identical across elemental-lend and jlpd-strategy
60
+ * (`StvPosition` from `common/strategy-interface.ts`). The 8-byte
61
+ * discriminator validation here distinguishes the two so a `LendStvPosition`
62
+ * can't be parsed as a JLPD position by mistake. See
63
+ * `common/strategy-interface.ts` for the field-by-field layout.
64
+ */
9
65
  export declare function deserializeJlpStvPosition(data: Buffer): StvPosition;
10
- export declare function fetchJlpdConfig(connection: Connection, programId?: PublicKey): Promise<JlpdConfig>;
11
- /** @deprecated Use fetchJlpdConfig instead */
12
- export declare const fetchJlpVault: typeof fetchJlpdConfig;
13
- export declare function fetchJlpStrategyState(connection: Connection, baseMint: PublicKey, programId?: PublicKey): Promise<JlpStrategyState>;
14
- export declare function fetchJlpStvPosition(connection: Connection, stv: PublicKey, programId?: PublicKey): Promise<StvPosition>;
15
- export declare function fetchAllJlpStrategyStates(connection: Connection, programId?: PublicKey): Promise<[PublicKey, JlpStrategyState][]>;
16
- export declare function fetchManagersForConfig(connection: Connection, config: PublicKey, programId?: PublicKey): Promise<[PublicKey, ManagerRole][]>;
17
- //# sourceMappingURL=accounts.d.ts.map
66
+ export declare function fetchJlpdConfig(connection: SolanaConnection, programId?: PublicKey): Promise<JlpdConfig>;
67
+ export declare function fetchJlpStrategyState(connection: SolanaConnection, baseMint: PublicKey, programId?: PublicKey): Promise<JlpStrategyState>;
68
+ export declare function fetchJlpStvPosition(connection: SolanaConnection, stv: PublicKey, programId?: PublicKey): Promise<StvPosition>;
69
+ export declare function fetchAllJlpStrategyStates(connection: SolanaConnection, programId?: PublicKey): Promise<[PublicKey, JlpStrategyState][]>;
70
+ export declare function fetchManagersForConfig(connection: SolanaConnection, config: PublicKey, programId?: PublicKey): Promise<[PublicKey, ManagerRole][]>;
@@ -1,6 +1,5 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.fetchJlpVault = exports.deserializeJlpVault = void 0;
4
3
  exports.deserializeJlpdConfig = deserializeJlpdConfig;
5
4
  exports.deserializeManagerRole = deserializeManagerRole;
6
5
  exports.deserializeJlpStrategyState = deserializeJlpStrategyState;
@@ -16,7 +15,29 @@ const constants_1 = require("./constants");
16
15
  const pda_1 = require("./pda");
17
16
  // ---------------------------------------------------------------------------
18
17
  // Deserialization
18
+ //
19
+ // All offsets below INCLUDE the 8-byte Anchor account discriminator. Layout
20
+ // blocks above each parser show the field map; the helpers in
21
+ // `common/buffer.ts` validate that `offset + width <= data.length` so a
22
+ // drift between this file and the on-chain layout fails loudly with a
23
+ // `RangeError` rather than returning garbage.
19
24
  // ---------------------------------------------------------------------------
25
+ /**
26
+ * JlpdConfig — singleton config shared across all five base-asset strategies.
27
+ * Total 272 bytes.
28
+ *
29
+ * Layout (offsets include the 8-byte discriminator):
30
+ * [ 0.. 8] discriminator (sha256("account:JlpdConfig")[..8])
31
+ * [ 8.. 40] admin Pubkey
32
+ * [ 40.. 72] jlpMint Pubkey
33
+ * [ 72..232] baseAssetMints[5] [Pubkey; 5] (BTC, ETH, SOL, USDC, JupUSD)
34
+ * [232..240] oracleStalenessTh u64 (max age in seconds)
35
+ * [240..242] flags u16
36
+ * [242..244] jlpSlippageBps u16 (max slippage on swap_jlp)
37
+ * [244..245] version u8
38
+ * [245..246] bump u8
39
+ * [246..272] _reserved [u8; 26]
40
+ */
20
41
  function deserializeJlpdConfig(data) {
21
42
  if (data.length < constants_1.JLPD_CONFIG_SIZE) {
22
43
  throw new Error(`JlpdConfig data too short: ${data.length} < ${constants_1.JLPD_CONFIG_SIZE}`);
@@ -38,10 +59,21 @@ function deserializeJlpdConfig(data) {
38
59
  jlpSlippageBps: (0, buffer_1.readU16)(data, 242),
39
60
  version: (0, buffer_1.readU8)(data, 244),
40
61
  bump: (0, buffer_1.readU8)(data, 245),
62
+ jlpEarnAmount: (0, buffer_1.readU64)(data, 248),
63
+ jlpAdapterProgram: (0, buffer_1.readPubkey)(data, 256),
41
64
  };
42
65
  }
43
- /** @deprecated Use deserializeJlpdConfig instead */
44
- exports.deserializeJlpVault = deserializeJlpdConfig;
66
+ /**
67
+ * ManagerRole — per-(config, manager) authorization. Total 80 bytes.
68
+ *
69
+ * Layout (offsets include the 8-byte discriminator):
70
+ * [ 0.. 8] discriminator (sha256("account:ManagerRole")[..8] —
71
+ * shared with p-stv-core + elemental-lend)
72
+ * [ 8.. 40] config Pubkey
73
+ * [ 40.. 72] manager Pubkey
74
+ * [ 72.. 73] bump u8
75
+ * [ 73.. 80] _padding [u8; 7]
76
+ */
45
77
  function deserializeManagerRole(data) {
46
78
  if (data.length < constants_1.MANAGER_ROLE_SIZE) {
47
79
  throw new Error(`ManagerRole data too short: ${data.length} < ${constants_1.MANAGER_ROLE_SIZE}`);
@@ -56,6 +88,27 @@ function deserializeManagerRole(data) {
56
88
  bump: (0, buffer_1.readU8)(data, 72),
57
89
  };
58
90
  }
91
+ /**
92
+ * JlpStrategyState — per-base-asset JLPD strategy account. Total 224 bytes.
93
+ *
94
+ * Layout (offsets include the 8-byte discriminator):
95
+ * [ 0.. 8] discriminator (sha256("account:StrategyState")[..8] —
96
+ * shared with elemental-lend)
97
+ * --- StrategyStateHeader (104 bytes, identical across all strategy programs) ---
98
+ * [ 8.. 40] baseMint Pubkey
99
+ * [ 40.. 72] authority Pubkey (p-stv-core program)
100
+ * [ 72.. 80] pps u64 (scaled by PPS_DECIMALS = 10^9)
101
+ * [ 80.. 88] totalAum u64
102
+ * [ 88.. 96] totalShares u64
103
+ * [ 96..104] lastUpdated u64 (unix seconds)
104
+ * [104..106] flags u16
105
+ * [106..107] version u8
106
+ * [107..108] bump u8
107
+ * [108..112] _headerPadding [u8; 4]
108
+ * --- Custom JLPD fields (112 bytes) ---
109
+ * [112..120] baseLoaned u64 (base assets swapped into JLP)
110
+ * [120..224] _reserved [u8; 104]
111
+ */
59
112
  function deserializeJlpStrategyState(data) {
60
113
  if (data.length < constants_1.STRATEGY_STATE_SIZE) {
61
114
  throw new Error(`JlpStrategyState data too short: ${data.length} < ${constants_1.STRATEGY_STATE_SIZE}`);
@@ -79,6 +132,15 @@ function deserializeJlpStrategyState(data) {
79
132
  baseLoaned: (0, buffer_1.readU64)(data, 112),
80
133
  };
81
134
  }
135
+ /**
136
+ * StvPosition — per-STV virtual share record. Total 120 bytes.
137
+ *
138
+ * The on-disk layout is identical across elemental-lend and jlpd-strategy
139
+ * (`StvPosition` from `common/strategy-interface.ts`). The 8-byte
140
+ * discriminator validation here distinguishes the two so a `LendStvPosition`
141
+ * can't be parsed as a JLPD position by mistake. See
142
+ * `common/strategy-interface.ts` for the field-by-field layout.
143
+ */
82
144
  function deserializeJlpStvPosition(data) {
83
145
  if (data.length < constants_1.STV_POSITION_SIZE) {
84
146
  throw new Error(`StvPosition data too short: ${data.length} < ${constants_1.STV_POSITION_SIZE}`);
@@ -99,8 +161,6 @@ async function fetchJlpdConfig(connection, programId = constants_1.PROGRAM_ID) {
99
161
  throw new Error("JlpdConfig account not found");
100
162
  return deserializeJlpdConfig(info.data);
101
163
  }
102
- /** @deprecated Use fetchJlpdConfig instead */
103
- exports.fetchJlpVault = fetchJlpdConfig;
104
164
  async function fetchJlpStrategyState(connection, baseMint, programId = constants_1.PROGRAM_ID) {
105
165
  const [pda] = (0, pda_1.findStrategyStatePda)(baseMint, programId);
106
166
  const info = await connection.getAccountInfo(pda);
@@ -132,9 +192,8 @@ async function fetchManagersForConfig(connection, config, programId = constants_
132
192
  filters: [
133
193
  { dataSize: constants_1.MANAGER_ROLE_SIZE },
134
194
  { memcmp: { offset: 0, bytes: constants_1.DISC_MANAGER_ROLE.toString("base64"), encoding: "base64" } },
135
- { memcmp: { offset: 8, bytes: config.toBase58() } },
195
+ { memcmp: { offset: 8, bytes: config.toBuffer().toString("base64"), encoding: "base64" } },
136
196
  ],
137
197
  });
138
198
  return accounts.map((a) => [a.pubkey, deserializeManagerRole(a.account.data)]);
139
199
  }
140
- //# sourceMappingURL=accounts.js.map
@@ -0,0 +1,60 @@
1
+ /**
2
+ * JLPD Adapter instruction builders.
3
+ *
4
+ * These build JLPD-side instructions (deposit_to_adapter, withdraw_from_adapter)
5
+ * that CPI into the JLPD Lend Adapter program.
6
+ */
7
+ import { PublicKey, TransactionInstruction, AccountMeta } from "@solana/web3.js";
8
+ import BN from "bn.js";
9
+ export interface DepositToAdapterArgs {
10
+ manager: PublicKey;
11
+ config: PublicKey;
12
+ managerRole: PublicKey;
13
+ vaultJlpAta: PublicKey;
14
+ adapterState: PublicKey;
15
+ adapterProgram: PublicKey;
16
+ amount: BN | number;
17
+ /** Protocol-specific remaining accounts for the adapter's deposit CPI */
18
+ remainingAccounts?: AccountMeta[];
19
+ }
20
+ /**
21
+ * Build `deposit_to_adapter` instruction.
22
+ *
23
+ * Anchor data: [8-byte disc, DepositToAdapterParams(u64 + bool + u16 + u32)]
24
+ */
25
+ export declare function createDepositToAdapterIx(args: DepositToAdapterArgs, programId?: PublicKey): TransactionInstruction;
26
+ export interface WithdrawFromAdapterArgs {
27
+ manager: PublicKey;
28
+ config: PublicKey;
29
+ managerRole: PublicKey;
30
+ vaultJlpAta: PublicKey;
31
+ adapterState: PublicKey;
32
+ adapterProgram: PublicKey;
33
+ amount: BN | number;
34
+ remainingAccounts?: AccountMeta[];
35
+ }
36
+ export declare function createWithdrawFromAdapterIx(args: WithdrawFromAdapterArgs, programId?: PublicKey): TransactionInstruction;
37
+ /** Adapter instruction discriminators for adapter_manage */
38
+ export declare const ADAPTER_DISC_BORROW = 3;
39
+ export declare const ADAPTER_DISC_DEPOSIT_EARN = 4;
40
+ export declare const ADAPTER_DISC_WITHDRAW_EARN = 5;
41
+ export declare const ADAPTER_DISC_REPAY = 6;
42
+ export interface AdapterManageArgs {
43
+ manager: PublicKey;
44
+ config: PublicKey;
45
+ managerRole: PublicKey;
46
+ adapterState: PublicKey;
47
+ adapterProgram: PublicKey;
48
+ /** Adapter instruction discriminator (e.g. ADAPTER_DISC_BORROW) */
49
+ adapterDisc: number;
50
+ amount: BN | number;
51
+ /** Protocol-specific remaining accounts for the adapter CPI */
52
+ remainingAccounts?: AccountMeta[];
53
+ }
54
+ /**
55
+ * Build `adapter_manage` instruction.
56
+ *
57
+ * Routes borrow/repay/earn operations through JLPD for config PDA signer propagation.
58
+ * Anchor data: [8-byte disc, AdapterManageParams(u8 + u64)]
59
+ */
60
+ export declare function createAdapterManageIx(args: AdapterManageArgs, programId?: PublicKey): TransactionInstruction;
@@ -0,0 +1,90 @@
1
+ "use strict";
2
+ /**
3
+ * JLPD Adapter instruction builders.
4
+ *
5
+ * These build JLPD-side instructions (deposit_to_adapter, withdraw_from_adapter)
6
+ * that CPI into the JLPD Lend Adapter program.
7
+ */
8
+ var __importDefault = (this && this.__importDefault) || function (mod) {
9
+ return (mod && mod.__esModule) ? mod : { "default": mod };
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.ADAPTER_DISC_REPAY = exports.ADAPTER_DISC_WITHDRAW_EARN = exports.ADAPTER_DISC_DEPOSIT_EARN = exports.ADAPTER_DISC_BORROW = void 0;
13
+ exports.createDepositToAdapterIx = createDepositToAdapterIx;
14
+ exports.createWithdrawFromAdapterIx = createWithdrawFromAdapterIx;
15
+ exports.createAdapterManageIx = createAdapterManageIx;
16
+ const web3_js_1 = require("@solana/web3.js");
17
+ const bn_js_1 = __importDefault(require("bn.js"));
18
+ const constants_1 = require("./constants");
19
+ /**
20
+ * Internal helper — builds the instruction for deposit_to_adapter or
21
+ * withdraw_from_adapter. Both share the same account layout and data
22
+ * format (8-byte disc + u64 amount); only the discriminator differs.
23
+ */
24
+ function buildAdapterIx(disc, args, programId) {
25
+ const { manager, config, managerRole, vaultJlpAta, adapterState, adapterProgram, amount, remainingAccounts = [], } = args;
26
+ const data = Buffer.alloc(16);
27
+ disc.copy(data, 0);
28
+ const amtBuf = typeof amount === "number" ? new bn_js_1.default(amount) : amount;
29
+ amtBuf.toArrayLike(Buffer, "le", 8).copy(data, 8);
30
+ return new web3_js_1.TransactionInstruction({
31
+ programId,
32
+ keys: [
33
+ { pubkey: manager, isSigner: true, isWritable: false },
34
+ { pubkey: config, isSigner: false, isWritable: true },
35
+ { pubkey: managerRole, isSigner: false, isWritable: false },
36
+ { pubkey: vaultJlpAta, isSigner: false, isWritable: true },
37
+ { pubkey: adapterState, isSigner: false, isWritable: true },
38
+ { pubkey: adapterProgram, isSigner: false, isWritable: false },
39
+ ...remainingAccounts,
40
+ ],
41
+ data,
42
+ });
43
+ }
44
+ /**
45
+ * Build `deposit_to_adapter` instruction.
46
+ *
47
+ * Anchor data: [8-byte disc, DepositToAdapterParams(u64 + bool + u16 + u32)]
48
+ */
49
+ function createDepositToAdapterIx(args, programId = constants_1.PROGRAM_ID) {
50
+ return buildAdapterIx(constants_1.IX_DEPOSIT_TO_ADAPTER, args, programId);
51
+ }
52
+ function createWithdrawFromAdapterIx(args, programId = constants_1.PROGRAM_ID) {
53
+ return buildAdapterIx(constants_1.IX_WITHDRAW_FROM_ADAPTER, args, programId);
54
+ }
55
+ // ============================================================================
56
+ // adapter_manage (generic: borrow, repay, deposit_earn, withdraw_earn)
57
+ // ============================================================================
58
+ /** Adapter instruction discriminators for adapter_manage */
59
+ exports.ADAPTER_DISC_BORROW = 0x03;
60
+ exports.ADAPTER_DISC_DEPOSIT_EARN = 0x04;
61
+ exports.ADAPTER_DISC_WITHDRAW_EARN = 0x05;
62
+ exports.ADAPTER_DISC_REPAY = 0x06;
63
+ /**
64
+ * Build `adapter_manage` instruction.
65
+ *
66
+ * Routes borrow/repay/earn operations through JLPD for config PDA signer propagation.
67
+ * Anchor data: [8-byte disc, AdapterManageParams(u8 + u64)]
68
+ */
69
+ function createAdapterManageIx(args, programId = constants_1.PROGRAM_ID) {
70
+ const { manager, config, managerRole, adapterState, adapterProgram, adapterDisc, amount, remainingAccounts = [], } = args;
71
+ // Anchor data: [8-byte disc, adapter_disc: u8, amount: u64]
72
+ const data = Buffer.alloc(17);
73
+ constants_1.IX_ADAPTER_MANAGE.copy(data, 0);
74
+ data[8] = adapterDisc;
75
+ const amtBuf = typeof amount === "number" ? new bn_js_1.default(amount) : amount;
76
+ amtBuf.toArrayLike(Buffer, "le", 8).copy(data, 9);
77
+ return new web3_js_1.TransactionInstruction({
78
+ programId,
79
+ keys: [
80
+ { pubkey: manager, isSigner: true, isWritable: false },
81
+ { pubkey: config, isSigner: false, isWritable: true },
82
+ { pubkey: managerRole, isSigner: false, isWritable: false },
83
+ // remaining_accounts: [adapter_state, adapter_program, ...jupiter accounts]
84
+ { pubkey: adapterState, isSigner: false, isWritable: true },
85
+ { pubkey: adapterProgram, isSigner: false, isWritable: false },
86
+ ...remainingAccounts,
87
+ ],
88
+ data,
89
+ });
90
+ }
@@ -20,14 +20,8 @@ export declare const CONFIG_SEED: Buffer<ArrayBuffer>;
20
20
  export declare const MANAGER_SEED: Buffer<ArrayBuffer>;
21
21
  export declare const STRATEGY_STATE_SEED: Buffer<ArrayBuffer>;
22
22
  export declare const POSITION_SEED: Buffer<ArrayBuffer>;
23
- /** @deprecated Use CONFIG_SEED instead */
24
- export declare const JLP_VAULT_SEED: Buffer<ArrayBuffer>;
25
23
  export declare const DISC_JLPD_CONFIG: Buffer<ArrayBuffer>;
26
- export declare const DISC_MANAGER_ROLE: Buffer<ArrayBuffer>;
27
- export declare const DISC_STRATEGY_STATE: Buffer<ArrayBuffer>;
28
- export declare const DISC_STV_POSITION: Buffer<ArrayBuffer>;
29
- /** @deprecated Use DISC_JLPD_CONFIG instead */
30
- export declare const DISC_JLP_VAULT: Buffer<ArrayBuffer>;
24
+ export { DISC_STRATEGY_STATE, DISC_STV_POSITION, DISC_MANAGER_ROLE, } from "../common/constants";
31
25
  export declare const IX_INIT_OR_UPDATE_CONFIG: Buffer<ArrayBuffer>;
32
26
  export declare const IX_INIT_OR_UPDATE_STRATEGY_STATE: Buffer<ArrayBuffer>;
33
27
  export declare const IX_INIT_POSITION: Buffer<ArrayBuffer>;
@@ -37,16 +31,15 @@ export declare const IX_WITHDRAW: Buffer<ArrayBuffer>;
37
31
  export declare const IX_UPDATE_AUM: Buffer<ArrayBuffer>;
38
32
  export declare const IX_SWAP_JLP: Buffer<ArrayBuffer>;
39
33
  export declare const IX_SETTLE_YIELD: Buffer<ArrayBuffer>;
34
+ export declare const IX_DEPOSIT_TO_ADAPTER: Buffer<ArrayBuffer>;
35
+ export declare const IX_WITHDRAW_FROM_ADAPTER: Buffer<ArrayBuffer>;
36
+ export declare const IX_ADAPTER_MANAGE: Buffer<ArrayBuffer>;
40
37
  export declare const IX_ADD_MANAGER: Buffer<ArrayBuffer>;
41
38
  export declare const IX_REMOVE_MANAGER: Buffer<ArrayBuffer>;
42
- /** @deprecated Use IX_INIT_OR_UPDATE_CONFIG instead */
43
- export declare const IX_INIT_OR_UPDATE_JLP_VAULT: Buffer<ArrayBuffer>;
44
- export declare const JLPD_CONFIG_SIZE = 272;
39
+ export declare const JLPD_CONFIG_SIZE = 392;
45
40
  export declare const MANAGER_ROLE_SIZE = 80;
46
- export declare const STRATEGY_STATE_SIZE = 160;
47
- export declare const STV_POSITION_SIZE = 56;
48
- /** @deprecated Use JLPD_CONFIG_SIZE instead */
49
- export declare const JLP_VAULT_SIZE = 272;
41
+ export declare const STRATEGY_STATE_SIZE = 224;
42
+ export declare const STV_POSITION_SIZE = 120;
50
43
  export declare const FLAG_PAUSED = 1;
51
44
  export declare const FLAG_DEPOSITS_DISABLED = 2;
52
45
  export declare const FLAG_WITHDRAWALS_DISABLED = 4;
@@ -57,6 +50,24 @@ export declare const NUM_ASSETS = 5;
57
50
  export declare const MAX_MGMT_FEE_BPS = 500;
58
51
  export declare const MAX_PERF_FEE_BPS = 3000;
59
52
  export { PPS_DECIMALS, BPS_DENOMINATOR } from "../common/constants";
60
- /** Maps base_mint address → p-STV Core vault_id for JLPD strategy STVs */
53
+ /** Stable per-pool registry for JLPD strategy STVs.
54
+ *
55
+ * Each entry is the canonical record for a pool: short symbol, base mint
56
+ * address (base58), p-STV Core vault id, and base mint decimals. The
57
+ * `JLPD_VAULT_IDS` and `JLPD_POOL_NAMES_BY_VAULT_ID` lookups below are
58
+ * derived from this single table so consumers cannot get out of sync.
59
+ */
60
+ export declare const JLPD_POOLS: ReadonlyArray<{
61
+ readonly name: "BTC" | "ETH" | "SOL" | "USDC" | "JupUSD";
62
+ readonly mint: string;
63
+ readonly vaultId: number;
64
+ readonly decimals: number;
65
+ }>;
66
+ /** Pool symbol type derived from `JLPD_POOLS`. */
67
+ export type JlpdPoolName = (typeof JLPD_POOLS)[number]["name"];
68
+ /** Lookup: base_mint (base58) → vault_id. Derived from `JLPD_POOLS`. */
61
69
  export declare const JLPD_VAULT_IDS: Record<string, number>;
62
- //# sourceMappingURL=constants.d.ts.map
70
+ /** Lookup: pool symbol → vault_id. Derived from `JLPD_POOLS`. */
71
+ export declare const JLPD_VAULT_IDS_BY_POOL: Record<JlpdPoolName, number>;
72
+ /** Lookup: pool symbol → base mint decimals. Derived from `JLPD_POOLS`. */
73
+ export declare const JLPD_POOL_DECIMALS: Record<JlpdPoolName, number>;