@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
@@ -1,5 +1,21 @@
1
1
  import { PublicKey } from "@solana/web3.js";
2
2
  import BN from "bn.js";
3
+ /**
4
+ * StrategyStateHeader — 104-byte prefix shared by every strategy program.
5
+ *
6
+ * Layout (offsets include the 8-byte discriminator):
7
+ * [ 0.. 8] discriminator (set by the wrapping account)
8
+ * [ 8.. 40] baseMint Pubkey
9
+ * [ 40.. 72] authority Pubkey (p-stv-core program)
10
+ * [ 72.. 80] pps u64 (scaled by PPS_DECIMALS = 10^9)
11
+ * [ 80.. 88] totalAum u64
12
+ * [ 88.. 96] totalShares u64
13
+ * [ 96..104] lastUpdated u64 (unix seconds)
14
+ * [104..106] flags u16
15
+ * [106..107] version u8
16
+ * [107..108] bump u8
17
+ * [108..112] _headerPadding [u8; 4]
18
+ */
3
19
  export interface StrategyStateHeader {
4
20
  baseMint: PublicKey;
5
21
  authority: PublicKey;
@@ -12,18 +28,32 @@ export interface StrategyStateHeader {
12
28
  bump: number;
13
29
  }
14
30
  /**
15
- * Deserialize the standard 104-byte StrategyState header from any strategy account.
16
- * Data must include the 8-byte discriminator prefix.
31
+ * Deserialize the standard 104-byte StrategyState header from any strategy
32
+ * account. `data` must include the 8-byte discriminator prefix; the caller
33
+ * is responsible for validating that the discriminator matches the expected
34
+ * type before invoking this helper.
17
35
  */
18
36
  export declare function deserializeStrategyStateHeader(data: Buffer): StrategyStateHeader;
37
+ /**
38
+ * StvPosition — per-STV virtual share record. 48 bytes of meaningful data
39
+ * (full account is 120 bytes including the 8-byte discriminator and trailing
40
+ * reserved padding).
41
+ *
42
+ * Layout (offsets include the 8-byte discriminator):
43
+ * [ 0.. 8] discriminator (set by the wrapping account)
44
+ * [ 8.. 40] stv Pubkey
45
+ * [ 40.. 48] shares u64
46
+ * [ 48.. 49] bump u8
47
+ * [ 49..120] _reserved [u8; 71]
48
+ */
19
49
  export interface StvPosition {
20
50
  stv: PublicKey;
21
51
  shares: BN;
22
52
  bump: number;
23
53
  }
24
54
  /**
25
- * Deserialize the standard StvPosition from any strategy account.
26
- * Data must include the 8-byte discriminator prefix.
55
+ * Deserialize the standard StvPosition from any strategy account. `data`
56
+ * must include the 8-byte discriminator prefix; the caller validates the
57
+ * discriminator before invoking this helper.
27
58
  */
28
59
  export declare function deserializeStvPosition(data: Buffer): StvPosition;
29
- //# sourceMappingURL=strategy-interface.d.ts.map
@@ -4,8 +4,10 @@ exports.deserializeStrategyStateHeader = deserializeStrategyStateHeader;
4
4
  exports.deserializeStvPosition = deserializeStvPosition;
5
5
  const buffer_1 = require("./buffer");
6
6
  /**
7
- * Deserialize the standard 104-byte StrategyState header from any strategy account.
8
- * Data must include the 8-byte discriminator prefix.
7
+ * Deserialize the standard 104-byte StrategyState header from any strategy
8
+ * account. `data` must include the 8-byte discriminator prefix; the caller
9
+ * is responsible for validating that the discriminator matches the expected
10
+ * type before invoking this helper.
9
11
  */
10
12
  function deserializeStrategyStateHeader(data) {
11
13
  if (data.length < 112) {
@@ -24,8 +26,9 @@ function deserializeStrategyStateHeader(data) {
24
26
  };
25
27
  }
26
28
  /**
27
- * Deserialize the standard StvPosition from any strategy account.
28
- * Data must include the 8-byte discriminator prefix.
29
+ * Deserialize the standard StvPosition from any strategy account. `data`
30
+ * must include the 8-byte discriminator prefix; the caller validates the
31
+ * discriminator before invoking this helper.
29
32
  */
30
33
  function deserializeStvPosition(data) {
31
34
  if (data.length < 56) {
@@ -37,4 +40,3 @@ function deserializeStvPosition(data) {
37
40
  bump: (0, buffer_1.readU8)(data, 48),
38
41
  };
39
42
  }
40
- //# sourceMappingURL=strategy-interface.js.map
@@ -1,15 +1,60 @@
1
- import { AccountMeta, Connection, PublicKey } from "@solana/web3.js";
1
+ import { AccountMeta, PublicKey } from "@solana/web3.js";
2
2
  import type { StvPosition } from "../common/strategy-interface";
3
+ import type { SolanaConnection } from "../common/connection";
3
4
  import { LendStrategyState, ManagerRole } from "./types";
5
+ /**
6
+ * LendStrategyState — Elemental Lend's per-base-mint strategy account. Total 536 bytes.
7
+ *
8
+ * Layout (offsets include the 8-byte discriminator):
9
+ * [ 0.. 8] discriminator (sha256("account:StrategyState")[..8] —
10
+ * shared with jlpd-strategy)
11
+ * --- StrategyStateHeader (104 bytes, identical across all strategy programs) ---
12
+ * [ 8.. 40] baseMint Pubkey
13
+ * [ 40.. 72] authority Pubkey (p-stv-core program)
14
+ * [ 72.. 80] pps u64 (scaled by PPS_DECIMALS = 10^9)
15
+ * [ 80.. 88] totalAum u64
16
+ * [ 88.. 96] totalShares u64
17
+ * [ 96..104] lastUpdated u64 (unix seconds)
18
+ * [104..106] flags u16 (FLAG_PAUSED, …)
19
+ * [106..107] version u8
20
+ * [107..108] bump u8
21
+ * [108..112] _headerPadding [u8; 4]
22
+ * --- Custom Elemental Lend fields (424 bytes) ---
23
+ * [112..144] admin Pubkey
24
+ * [144..464] protocols[10] [Pubkey; 10] (registered protocol accounts)
25
+ * [464..465] protocolCount u8
26
+ * [465..472] _padding [u8; 7]
27
+ * [472..536] _reserved [u8; 64]
28
+ */
4
29
  export declare function deserializeLendStrategyState(data: Buffer): LendStrategyState;
30
+ /**
31
+ * StvPosition — per-STV virtual share record. Total 120 bytes.
32
+ *
33
+ * The on-disk layout is identical across elemental-lend and jlpd-strategy
34
+ * (`StvPosition` from `common/strategy-interface.ts`). The 8-byte
35
+ * discriminator validation here distinguishes the two so a `JlpdStvPosition`
36
+ * can't be parsed as a lend position by mistake. See
37
+ * `common/strategy-interface.ts` for the field-by-field layout.
38
+ */
5
39
  export declare function deserializeLendStvPosition(data: Buffer): StvPosition;
40
+ /**
41
+ * ManagerRole — per-(strategy_state, manager) authorization. Total 80 bytes.
42
+ *
43
+ * Layout (offsets include the 8-byte discriminator):
44
+ * [ 0.. 8] discriminator (sha256("account:ManagerRole")[..8] —
45
+ * shared with p-stv-core + jlpd-strategy)
46
+ * [ 8.. 40] strategyState Pubkey
47
+ * [ 40.. 72] manager Pubkey
48
+ * [ 72.. 73] bump u8
49
+ * [ 73.. 80] _padding [u8; 7]
50
+ */
6
51
  export declare function deserializeManagerRole(data: Buffer): ManagerRole;
7
- export declare function fetchLendStrategyState(connection: Connection, baseMint: PublicKey, programId?: PublicKey): Promise<LendStrategyState>;
8
- export declare function fetchLendStrategyStateByAddress(connection: Connection, address: PublicKey): Promise<LendStrategyState>;
9
- export declare function fetchLendStvPosition(connection: Connection, stv: PublicKey, programId?: PublicKey): Promise<StvPosition>;
10
- export declare function fetchManagerRole(connection: Connection, strategyState: PublicKey, manager: PublicKey, programId?: PublicKey): Promise<ManagerRole | null>;
11
- export declare function fetchAllLendStrategyStates(connection: Connection, programId?: PublicKey): Promise<[PublicKey, LendStrategyState][]>;
12
- export declare function fetchManagersForStrategy(connection: Connection, strategyState: PublicKey, programId?: PublicKey): Promise<[PublicKey, ManagerRole][]>;
52
+ export declare function fetchLendStrategyState(connection: SolanaConnection, baseMint: PublicKey, programId?: PublicKey): Promise<LendStrategyState>;
53
+ export declare function fetchLendStrategyStateByAddress(connection: SolanaConnection, address: PublicKey): Promise<LendStrategyState>;
54
+ export declare function fetchLendStvPosition(connection: SolanaConnection, stv: PublicKey, programId?: PublicKey): Promise<StvPosition>;
55
+ export declare function fetchManagerRole(connection: SolanaConnection, strategyState: PublicKey, manager: PublicKey, programId?: PublicKey): Promise<ManagerRole | null>;
56
+ export declare function fetchAllLendStrategyStates(connection: SolanaConnection, programId?: PublicKey): Promise<[PublicKey, LendStrategyState][]>;
57
+ export declare function fetchManagersForStrategy(connection: SolanaConnection, strategyState: PublicKey, programId?: PublicKey): Promise<[PublicKey, ManagerRole][]>;
13
58
  /**
14
59
  * Build remaining_accounts for the update_aum CPI on elemental-lend.
15
60
  * For each registered protocol, returns the accounts needed for AUM valuation:
@@ -21,5 +66,4 @@ export declare function fetchManagersForStrategy(connection: Connection, strateg
21
66
  * @param strategyStatePda - The strategy state PDA (owns the token ATAs)
22
67
  * @param tokenProgramId - Token program (SPL Token or Token-2022)
23
68
  */
24
- export declare function buildProtocolAccountsForAum(connection: Connection, strategy: LendStrategyState, strategyStatePda: PublicKey, tokenProgramId: PublicKey): Promise<AccountMeta[]>;
25
- //# sourceMappingURL=accounts.d.ts.map
69
+ export declare function buildProtocolAccountsForAum(connection: SolanaConnection, strategy: LendStrategyState, strategyStatePda: PublicKey, tokenProgramId: PublicKey): Promise<AccountMeta[]>;
@@ -17,7 +17,37 @@ const constants_1 = require("./constants");
17
17
  const pda_1 = require("./pda");
18
18
  // ---------------------------------------------------------------------------
19
19
  // Deserialization
20
+ //
21
+ // All offsets below INCLUDE the 8-byte Anchor account discriminator. Layout
22
+ // blocks above each parser show the field map; the helpers in
23
+ // `common/buffer.ts` validate that `offset + width <= data.length` so a
24
+ // drift between this file and the on-chain layout fails loudly with a
25
+ // `RangeError` rather than returning garbage.
20
26
  // ---------------------------------------------------------------------------
27
+ /**
28
+ * LendStrategyState — Elemental Lend's per-base-mint strategy account. Total 536 bytes.
29
+ *
30
+ * Layout (offsets include the 8-byte discriminator):
31
+ * [ 0.. 8] discriminator (sha256("account:StrategyState")[..8] —
32
+ * shared with jlpd-strategy)
33
+ * --- StrategyStateHeader (104 bytes, identical across all strategy programs) ---
34
+ * [ 8.. 40] baseMint Pubkey
35
+ * [ 40.. 72] authority Pubkey (p-stv-core program)
36
+ * [ 72.. 80] pps u64 (scaled by PPS_DECIMALS = 10^9)
37
+ * [ 80.. 88] totalAum u64
38
+ * [ 88.. 96] totalShares u64
39
+ * [ 96..104] lastUpdated u64 (unix seconds)
40
+ * [104..106] flags u16 (FLAG_PAUSED, …)
41
+ * [106..107] version u8
42
+ * [107..108] bump u8
43
+ * [108..112] _headerPadding [u8; 4]
44
+ * --- Custom Elemental Lend fields (424 bytes) ---
45
+ * [112..144] admin Pubkey
46
+ * [144..464] protocols[10] [Pubkey; 10] (registered protocol accounts)
47
+ * [464..465] protocolCount u8
48
+ * [465..472] _padding [u8; 7]
49
+ * [472..536] _reserved [u8; 64]
50
+ */
21
51
  function deserializeLendStrategyState(data) {
22
52
  if (data.length < constants_1.STRATEGY_STATE_SIZE) {
23
53
  throw new Error(`LendStrategyState data too short: ${data.length} < ${constants_1.STRATEGY_STATE_SIZE}`);
@@ -48,6 +78,15 @@ function deserializeLendStrategyState(data) {
48
78
  protocolCount,
49
79
  };
50
80
  }
81
+ /**
82
+ * StvPosition — per-STV virtual share record. Total 120 bytes.
83
+ *
84
+ * The on-disk layout is identical across elemental-lend and jlpd-strategy
85
+ * (`StvPosition` from `common/strategy-interface.ts`). The 8-byte
86
+ * discriminator validation here distinguishes the two so a `JlpdStvPosition`
87
+ * can't be parsed as a lend position by mistake. See
88
+ * `common/strategy-interface.ts` for the field-by-field layout.
89
+ */
51
90
  function deserializeLendStvPosition(data) {
52
91
  if (data.length < constants_1.STV_POSITION_SIZE) {
53
92
  throw new Error(`StvPosition data too short: ${data.length} < ${constants_1.STV_POSITION_SIZE}`);
@@ -58,6 +97,17 @@ function deserializeLendStvPosition(data) {
58
97
  }
59
98
  return (0, strategy_interface_1.deserializeStvPosition)(data);
60
99
  }
100
+ /**
101
+ * ManagerRole — per-(strategy_state, manager) authorization. Total 80 bytes.
102
+ *
103
+ * Layout (offsets include the 8-byte discriminator):
104
+ * [ 0.. 8] discriminator (sha256("account:ManagerRole")[..8] —
105
+ * shared with p-stv-core + jlpd-strategy)
106
+ * [ 8.. 40] strategyState Pubkey
107
+ * [ 40.. 72] manager Pubkey
108
+ * [ 72.. 73] bump u8
109
+ * [ 73.. 80] _padding [u8; 7]
110
+ */
61
111
  function deserializeManagerRole(data) {
62
112
  if (data.length < constants_1.MANAGER_ROLE_SIZE) {
63
113
  throw new Error(`ManagerRole data too short: ${data.length} < ${constants_1.MANAGER_ROLE_SIZE}`);
@@ -96,7 +146,7 @@ async function fetchLendStvPosition(connection, stv, programId = constants_1.PRO
96
146
  return deserializeLendStvPosition(info.data);
97
147
  }
98
148
  async function fetchManagerRole(connection, strategyState, manager, programId = constants_1.PROGRAM_ID) {
99
- const [pda] = (0, pda_1.findManagerRolePda)(strategyState, manager, programId);
149
+ const [pda] = (0, pda_1.findLendManagerRolePda)(strategyState, manager, programId);
100
150
  const info = await connection.getAccountInfo(pda);
101
151
  if (!info)
102
152
  return null;
@@ -119,7 +169,7 @@ async function fetchManagersForStrategy(connection, strategyState, programId = c
119
169
  filters: [
120
170
  { dataSize: constants_1.MANAGER_ROLE_SIZE },
121
171
  { memcmp: { offset: 0, bytes: constants_1.DISC_MANAGER_ROLE.toString("base64"), encoding: "base64" } },
122
- { memcmp: { offset: 8, bytes: strategyState.toBase58() } },
172
+ { memcmp: { offset: 8, bytes: strategyState.toBuffer().toString("base64"), encoding: "base64" } },
123
173
  ],
124
174
  });
125
175
  return accounts.map((a) => [a.pubkey, deserializeManagerRole(a.account.data)]);
@@ -153,10 +203,12 @@ async function buildProtocolAccountsForAum(connection, strategy, strategyStatePd
153
203
  if (!protocolInfo)
154
204
  continue;
155
205
  if (protocolInfo.owner.equals(constants_1.KAMINO_VAULT_PROGRAM)) {
156
- // kVault: [kvtoken_ata, vault_state]
206
+ // kVault: AUM accounts = [kvtoken_ata, vault_state]
157
207
  // Derive the shares_mint PDA from vault_state: ["shares", vault_state]
158
208
  const [sharesMint] = web3_js_1.PublicKey.findProgramAddressSync([Buffer.from("shares"), protocolKey.toBuffer()], constants_1.KAMINO_VAULT_PROGRAM);
159
- // Find the kvToken ATA (matching shares_mint)
209
+ // Find the kvToken ATA (matching shares_mint).
210
+ // SPL Token account layout: [mint(0..32)][owner(32..64)][amount(64..72)]…
211
+ // We're reading the mint field at offset 0 to identify the share-token ATA.
160
212
  let kvTokenAta = null;
161
213
  for (const ta of tokenAccounts.value) {
162
214
  const mintKey = new web3_js_1.PublicKey(ta.account.data.subarray(0, 32));
@@ -169,9 +221,16 @@ async function buildProtocolAccountsForAum(connection, strategy, strategyStatePd
169
221
  accounts.push({ pubkey: kvTokenAta, isSigner: false, isWritable: false }, { pubkey: protocolKey, isSigner: false, isWritable: false });
170
222
  }
171
223
  }
172
- else if (protocolInfo.owner.equals(constants_1.JUP_LEND_PROGRAM)) {
173
- // Jupiter Lend: [ftoken_ata, lending_account, rewards_rate_model]
174
- // Read fToken mint (offset 40) and rewards_rate_model (offset 75) from lending account data
224
+ else if (protocolInfo.owner.equals(constants_1.JUP_LEND_EARN_PROGRAM)) {
225
+ // Jupiter Lend Earn: AUM accounts = [ftoken_ata, lending_account, rewards_rate_model]
226
+ //
227
+ // Lending account layout (Jupiter Lend Earn — Anchor 8-byte disc):
228
+ // [ 0.. 8] discriminator
229
+ // [ 8.. 40] authority Pubkey
230
+ // [ 40.. 72] fTokenMint Pubkey
231
+ // [ 72.. 75] _padding [u8; 3]
232
+ // [ 75..107] rewardsRateModel Pubkey
233
+ // [107..] remaining fields …
175
234
  const lendingData = protocolInfo.data;
176
235
  if (lendingData.length >= 107) {
177
236
  const fTokenMint = new web3_js_1.PublicKey(lendingData.subarray(40, 72));
@@ -193,4 +252,3 @@ async function buildProtocolAccountsForAum(connection, strategy, strategyStatePd
193
252
  }
194
253
  return accounts;
195
254
  }
196
- //# sourceMappingURL=accounts.js.map
@@ -3,9 +3,7 @@ export declare const PROGRAM_ID: PublicKey;
3
3
  export declare const STRATEGY_STATE_SEED: Buffer<ArrayBuffer>;
4
4
  export declare const POSITION_SEED: Buffer<ArrayBuffer>;
5
5
  export declare const MANAGER_SEED: Buffer<ArrayBuffer>;
6
- export declare const DISC_STRATEGY_STATE: Buffer<ArrayBuffer>;
7
- export declare const DISC_STV_POSITION: Buffer<ArrayBuffer>;
8
- export declare const DISC_MANAGER_ROLE: Buffer<ArrayBuffer>;
6
+ export { DISC_STRATEGY_STATE, DISC_STV_POSITION, DISC_MANAGER_ROLE, } from "../common/constants";
9
7
  export declare const IX_INIT_OR_UPDATE_STRATEGY: Buffer<ArrayBuffer>;
10
8
  export declare const IX_INIT_POSITION: Buffer<ArrayBuffer>;
11
9
  export declare const IX_DEPOSIT: Buffer<ArrayBuffer>;
@@ -17,12 +15,13 @@ export declare const IX_JUP_LEND_DEPOSIT: Buffer<ArrayBuffer>;
17
15
  export declare const IX_JUP_LEND_WITHDRAW: Buffer<ArrayBuffer>;
18
16
  export declare const IX_ADD_MANAGER: Buffer<ArrayBuffer>;
19
17
  export declare const IX_REMOVE_MANAGER: Buffer<ArrayBuffer>;
20
- export declare const STRATEGY_STATE_SIZE = 472;
21
- export declare const STV_POSITION_SIZE = 56;
18
+ export declare const STRATEGY_STATE_SIZE = 536;
19
+ export declare const STV_POSITION_SIZE = 120;
22
20
  export declare const MANAGER_ROLE_SIZE = 80;
23
21
  export declare const FLAG_PAUSED = 1;
24
22
  export declare const MAX_PROTOCOLS = 10;
25
23
  export declare const KAMINO_VAULT_PROGRAM: PublicKey;
26
- export declare const JUP_LEND_PROGRAM: PublicKey;
24
+ export declare const KLEND_PROGRAM: PublicKey;
25
+ /** Jupiter Lend Earn program (the supply-side product). */
26
+ export declare const JUP_LEND_EARN_PROGRAM: PublicKey;
27
27
  export { PPS_DECIMALS } from "../common/constants";
28
- //# sourceMappingURL=constants.d.ts.map
@@ -1,17 +1,17 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.PPS_DECIMALS = exports.JUP_LEND_PROGRAM = exports.KAMINO_VAULT_PROGRAM = exports.MAX_PROTOCOLS = exports.FLAG_PAUSED = exports.MANAGER_ROLE_SIZE = exports.STV_POSITION_SIZE = exports.STRATEGY_STATE_SIZE = exports.IX_REMOVE_MANAGER = exports.IX_ADD_MANAGER = exports.IX_JUP_LEND_WITHDRAW = exports.IX_JUP_LEND_DEPOSIT = exports.IX_KVAULT_WITHDRAW = exports.IX_KVAULT_DEPOSIT = exports.IX_UPDATE_AUM = exports.IX_WITHDRAW = exports.IX_DEPOSIT = exports.IX_INIT_POSITION = exports.IX_INIT_OR_UPDATE_STRATEGY = exports.DISC_MANAGER_ROLE = exports.DISC_STV_POSITION = exports.DISC_STRATEGY_STATE = exports.MANAGER_SEED = exports.POSITION_SEED = exports.STRATEGY_STATE_SEED = exports.PROGRAM_ID = void 0;
3
+ exports.PPS_DECIMALS = exports.JUP_LEND_EARN_PROGRAM = exports.KLEND_PROGRAM = exports.KAMINO_VAULT_PROGRAM = exports.MAX_PROTOCOLS = exports.FLAG_PAUSED = exports.MANAGER_ROLE_SIZE = exports.STV_POSITION_SIZE = exports.STRATEGY_STATE_SIZE = exports.IX_REMOVE_MANAGER = exports.IX_ADD_MANAGER = exports.IX_JUP_LEND_WITHDRAW = exports.IX_JUP_LEND_DEPOSIT = exports.IX_KVAULT_WITHDRAW = exports.IX_KVAULT_DEPOSIT = exports.IX_UPDATE_AUM = exports.IX_WITHDRAW = exports.IX_DEPOSIT = exports.IX_INIT_POSITION = exports.IX_INIT_OR_UPDATE_STRATEGY = exports.DISC_MANAGER_ROLE = exports.DISC_STV_POSITION = exports.DISC_STRATEGY_STATE = exports.MANAGER_SEED = exports.POSITION_SEED = exports.STRATEGY_STATE_SEED = exports.PROGRAM_ID = void 0;
4
4
  const web3_js_1 = require("@solana/web3.js");
5
5
  exports.PROGRAM_ID = new web3_js_1.PublicKey("EHaGVh7p6xSxZsq4CcEEZhnV5adDvWg1gS1Rc5rLiBpC");
6
6
  // PDA Seeds
7
7
  exports.STRATEGY_STATE_SEED = Buffer.from("strategy_state");
8
8
  exports.POSITION_SEED = Buffer.from("position");
9
9
  exports.MANAGER_SEED = Buffer.from("manager");
10
- // Account discriminators (Anchor 8-byte)
11
- exports.DISC_STRATEGY_STATE = Buffer.from([83, 18, 224, 109, 174, 100, 39, 139]);
12
- exports.DISC_STV_POSITION = Buffer.from([47, 212, 251, 176, 138, 160, 30, 87]);
13
- // sha256("account:ManagerRole")[..8]
14
- exports.DISC_MANAGER_ROLE = Buffer.from([0x25, 0xe8, 0x64, 0xe9, 0xaa, 0xe9, 0xdb, 0xb9]);
10
+ // Account discriminators (Anchor 8-byte) — defined once in common/, re-exported here
11
+ var constants_1 = require("../common/constants");
12
+ Object.defineProperty(exports, "DISC_STRATEGY_STATE", { enumerable: true, get: function () { return constants_1.DISC_STRATEGY_STATE; } });
13
+ Object.defineProperty(exports, "DISC_STV_POSITION", { enumerable: true, get: function () { return constants_1.DISC_STV_POSITION; } });
14
+ Object.defineProperty(exports, "DISC_MANAGER_ROLE", { enumerable: true, get: function () { return constants_1.DISC_MANAGER_ROLE; } });
15
15
  // Instruction discriminators (Anchor 8-byte)
16
16
  exports.IX_INIT_OR_UPDATE_STRATEGY = Buffer.from([221, 4, 60, 139, 83, 148, 116, 247]);
17
17
  exports.IX_INIT_POSITION = Buffer.from([197, 20, 10, 1, 97, 160, 177, 91]);
@@ -27,8 +27,8 @@ exports.IX_ADD_MANAGER = Buffer.from([0x7d, 0x26, 0xc0, 0xd4, 0x65, 0x5b, 0xb3,
27
27
  // sha256("global:remove_manager")[..8]
28
28
  exports.IX_REMOVE_MANAGER = Buffer.from([0x96, 0x37, 0x9d, 0x4d, 0x80, 0x94, 0x07, 0x0f]);
29
29
  // Account sizes
30
- exports.STRATEGY_STATE_SIZE = 472;
31
- exports.STV_POSITION_SIZE = 56;
30
+ exports.STRATEGY_STATE_SIZE = 536;
31
+ exports.STV_POSITION_SIZE = 120;
32
32
  exports.MANAGER_ROLE_SIZE = 80;
33
33
  // Flags
34
34
  exports.FLAG_PAUSED = 0x0001;
@@ -36,7 +36,8 @@ exports.FLAG_PAUSED = 0x0001;
36
36
  exports.MAX_PROTOCOLS = 10;
37
37
  // External protocol programs
38
38
  exports.KAMINO_VAULT_PROGRAM = new web3_js_1.PublicKey("KvauGMspG5k6rtzrqqn7WNn3oZdyKqLKwK2XWQ8FLjd");
39
- exports.JUP_LEND_PROGRAM = new web3_js_1.PublicKey("jup3YeL8QhtSx1e253b2FDvsMNC87fDrgQZivbrndc9");
40
- var constants_1 = require("../common/constants");
41
- Object.defineProperty(exports, "PPS_DECIMALS", { enumerable: true, get: function () { return constants_1.PPS_DECIMALS; } });
42
- //# sourceMappingURL=constants.js.map
39
+ exports.KLEND_PROGRAM = new web3_js_1.PublicKey("KLend2g3cP87fffoy8q1mQqGKjrxjC8boSyAYavgmjD");
40
+ /** Jupiter Lend Earn program (the supply-side product). */
41
+ exports.JUP_LEND_EARN_PROGRAM = new web3_js_1.PublicKey("jup3YeL8QhtSx1e253b2FDvsMNC87fDrgQZivbrndc9");
42
+ var constants_2 = require("../common/constants");
43
+ Object.defineProperty(exports, "PPS_DECIMALS", { enumerable: true, get: function () { return constants_2.PPS_DECIMALS; } });
@@ -6,4 +6,3 @@ export * from "./instructions";
6
6
  export * from "./jupiter-lend";
7
7
  export * from "./kamino-vault";
8
8
  export * from "./protocol-actions";
9
- //# sourceMappingURL=index.d.ts.map
@@ -22,4 +22,3 @@ __exportStar(require("./instructions"), exports);
22
22
  __exportStar(require("./jupiter-lend"), exports);
23
23
  __exportStar(require("./kamino-vault"), exports);
24
24
  __exportStar(require("./protocol-actions"), exports);
25
- //# sourceMappingURL=index.js.map
@@ -72,4 +72,3 @@ export interface RemoveManagerArgs {
72
72
  managerRole: PublicKey;
73
73
  }
74
74
  export declare function createRemoveManagerIx(args: RemoveManagerArgs, programId?: PublicKey): TransactionInstruction;
75
- //# sourceMappingURL=instructions.d.ts.map
@@ -180,4 +180,3 @@ function createRemoveManagerIx(args, programId = constants_1.PROGRAM_ID) {
180
180
  data: constants_1.IX_REMOVE_MANAGER,
181
181
  });
182
182
  }
183
- //# sourceMappingURL=instructions.js.map
@@ -89,4 +89,3 @@ export declare function buildJupLendWithdrawAccounts(pool: JupiterLendPool, sign
89
89
  * This is what p-stv-core's `unsweep_from_lend` forwards to elemental-lend's withdraw.
90
90
  */
91
91
  export declare function buildJupLendAutoUnrouteAccounts(pool: JupiterLendPool, strategyStatePda: PublicKey, strategyFtokenAta: PublicKey, strategyBaseAta: PublicKey): AccountMeta[];
92
- //# sourceMappingURL=jupiter-lend.d.ts.map
@@ -118,7 +118,7 @@ function buildJupLendDepositAccounts(pool, signer, depositorTokenAccount, recipi
118
118
  function buildJupLendAutoRouteAccounts(pool, strategyStatePda, strategyBaseAta, strategyFtokenAta) {
119
119
  return [
120
120
  // [0] Protocol program (identifies the route)
121
- { pubkey: constants_1.JUP_LEND_PROGRAM, isSigner: false, isWritable: false },
121
+ { pubkey: constants_1.JUP_LEND_EARN_PROGRAM, isSigner: false, isWritable: false },
122
122
  // [1..18] Full CPI account array
123
123
  ...buildJupLendDepositAccounts(pool, strategyStatePda, strategyBaseAta, strategyFtokenAta),
124
124
  ];
@@ -182,9 +182,8 @@ function buildJupLendWithdrawAccounts(pool, signer, ownerTokenAccount, recipient
182
182
  function buildJupLendAutoUnrouteAccounts(pool, strategyStatePda, strategyFtokenAta, strategyBaseAta) {
183
183
  return [
184
184
  // [0] Protocol program (identifies the route)
185
- { pubkey: constants_1.JUP_LEND_PROGRAM, isSigner: false, isWritable: false },
185
+ { pubkey: constants_1.JUP_LEND_EARN_PROGRAM, isSigner: false, isWritable: false },
186
186
  // [1..19] Full CPI account array
187
187
  ...buildJupLendWithdrawAccounts(pool, strategyStatePda, strategyFtokenAta, strategyBaseAta),
188
188
  ];
189
189
  }
190
- //# sourceMappingURL=jupiter-lend.js.map
@@ -8,9 +8,10 @@
8
8
  * For withdraw: 21 fixed accounts — first 12 derivable, then 9 KLend-specific
9
9
  * accounts read from vault_state and reserve on-chain data.
10
10
  */
11
- import { AccountMeta, Connection, PublicKey, TransactionInstruction } from "@solana/web3.js";
12
- /** KLend program ID */
13
- export declare const KLEND_PROGRAM: PublicKey;
11
+ import { AccountMeta, PublicKey, TransactionInstruction } from "@solana/web3.js";
12
+ import { KLEND_PROGRAM } from "./constants";
13
+ import type { SolanaConnection } from "../common/connection";
14
+ export { KLEND_PROGRAM };
14
15
  /** Kamino Vault global config (singleton, mainnet) */
15
16
  export declare const KAMINO_GLOBAL_CONFIG: PublicKey;
16
17
  /** Derive token_vault PDA: ["token_vault", vault_state] under Kamino Vault */
@@ -141,7 +142,7 @@ export declare function isKvaultStale(vaultStateData: Buffer | Uint8Array, curre
141
142
  * @param protocols - Protocol pubkeys from the lend strategy state
142
143
  * @returns Array of stale kVault state pubkeys
143
144
  */
144
- export declare function findStaleKvaults(connection: Connection, protocols: PublicKey[]): Promise<PublicKey[]>;
145
+ export declare function findStaleKvaults(connection: SolanaConnection, protocols: PublicKey[]): Promise<PublicKey[]>;
145
146
  /**
146
147
  * Build a Kamino `invest` instruction to refresh a stale kVault.
147
148
  *
@@ -169,5 +170,4 @@ export declare function buildKaminoInvestIx(payer: PublicKey, payerTokenAccount:
169
170
  * @param baseMint - Base token mint
170
171
  * @param protocols - Registered protocol pubkeys from lend strategy state
171
172
  */
172
- export declare function buildKaminoInvestIxsIfStale(connection: Connection, payer: PublicKey, baseMint: PublicKey, protocols: PublicKey[]): Promise<TransactionInstruction[]>;
173
- //# sourceMappingURL=kamino-vault.d.ts.map
173
+ export declare function buildKaminoInvestIxsIfStale(connection: SolanaConnection, payer: PublicKey, baseMint: PublicKey, protocols: PublicKey[]): Promise<TransactionInstruction[]>;
@@ -28,11 +28,10 @@ exports.buildKaminoInvestIx = buildKaminoInvestIx;
28
28
  exports.buildKaminoInvestIxsIfStale = buildKaminoInvestIxsIfStale;
29
29
  const web3_js_1 = require("@solana/web3.js");
30
30
  const constants_1 = require("./constants");
31
+ Object.defineProperty(exports, "KLEND_PROGRAM", { enumerable: true, get: function () { return constants_1.KLEND_PROGRAM; } });
31
32
  // ---------------------------------------------------------------------------
32
33
  // Constants
33
34
  // ---------------------------------------------------------------------------
34
- /** KLend program ID */
35
- exports.KLEND_PROGRAM = new web3_js_1.PublicKey("KLend2g3cP87fffoy8q1mQqGKjrxjC8boSyAYavgmjD");
36
35
  /** Kamino Vault global config (singleton, mainnet) */
37
36
  exports.KAMINO_GLOBAL_CONFIG = new web3_js_1.PublicKey("BKyTcUe6daNG8HbgBix2ugdRHbykG2dK9hPBBqhUyoEX");
38
37
  /** SPL Token program */
@@ -60,7 +59,7 @@ function findKvaultEventAuthority() {
60
59
  }
61
60
  /** Derive lending_market_authority PDA: ["lma", lending_market] under KLend */
62
61
  function findLendingMarketAuthority(lendingMarket) {
63
- return web3_js_1.PublicKey.findProgramAddressSync([Buffer.from("lma"), lendingMarket.toBuffer()], exports.KLEND_PROGRAM);
62
+ return web3_js_1.PublicKey.findProgramAddressSync([Buffer.from("lma"), lendingMarket.toBuffer()], constants_1.KLEND_PROGRAM);
64
63
  }
65
64
  // ---------------------------------------------------------------------------
66
65
  // VaultState / Reserve Data Readers
@@ -157,7 +156,7 @@ function buildKvaultDepositAccounts(vaultState, strategyStatePda, strategyBaseAt
157
156
  { pubkey: sharesMint, isSigner: false, isWritable: true }, // 5
158
157
  { pubkey: strategyBaseAta, isSigner: false, isWritable: true }, // 6
159
158
  { pubkey: strategySharesAta, isSigner: false, isWritable: true }, // 7
160
- { pubkey: exports.KLEND_PROGRAM, isSigner: false, isWritable: false }, // 8
159
+ { pubkey: constants_1.KLEND_PROGRAM, isSigner: false, isWritable: false }, // 8
161
160
  { pubkey: SPL_TOKEN_PROGRAM, isSigner: false, isWritable: false }, // 9
162
161
  { pubkey: SPL_TOKEN_PROGRAM, isSigner: false, isWritable: false }, // 10
163
162
  { pubkey: eventAuthority, isSigner: false, isWritable: false }, // 11 (Anchor event CPI)
@@ -249,7 +248,7 @@ function buildKvaultWithdrawAccounts(vaultState, strategyStatePda, strategyBaseA
249
248
  { pubkey: sharesMint, isSigner: false, isWritable: true }, // 8
250
249
  { pubkey: SPL_TOKEN_PROGRAM, isSigner: false, isWritable: false }, // 9
251
250
  { pubkey: SPL_TOKEN_PROGRAM, isSigner: false, isWritable: false }, // 10
252
- { pubkey: exports.KLEND_PROGRAM, isSigner: false, isWritable: false }, // 11
251
+ { pubkey: constants_1.KLEND_PROGRAM, isSigner: false, isWritable: false }, // 11
253
252
  // WithdrawFromAvailable event CPI (12-13)
254
253
  { pubkey: eventAuthority, isSigner: false, isWritable: false }, // 12
255
254
  { pubkey: constants_1.KAMINO_VAULT_PROGRAM, isSigner: false, isWritable: false }, // 13
@@ -315,8 +314,9 @@ async function findStaleKvaults(connection, protocols) {
315
314
  connection.getMultipleAccountsInfo(protocols),
316
315
  connection.getSlot("confirmed"),
317
316
  ]);
318
- // Estimate timestamp from slot (not exact, but close enough for staleness)
319
- const epochInfo = await connection.getEpochInfo("confirmed");
317
+ // Approximate current timestamp via the slot's block time. If the RPC has
318
+ // no block time available, fall back to wall-clock — close enough for the
319
+ // 120s staleness check.
320
320
  const blockTime = await connection.getBlockTime(slot);
321
321
  const currentTs = blockTime ?? Math.floor(Date.now() / 1000);
322
322
  const stale = [];
@@ -331,7 +331,6 @@ async function findStaleKvaults(connection, protocols) {
331
331
  stale.push(protocols[i]);
332
332
  }
333
333
  }
334
- void epochInfo; // suppress unused warning
335
334
  return stale;
336
335
  }
337
336
  // ---------------------------------------------------------------------------
@@ -382,7 +381,7 @@ function buildKaminoInvestIx(payer, payerTokenAccount, vaultState, baseMint, vau
382
381
  { pubkey: res.reserveLiquiditySupply, isSigner: false, isWritable: true }, // 10: reserve_liquidity_supply
383
382
  { pubkey: res.reserveCollateralMint, isSigner: false, isWritable: true }, // 11: reserve_collateral_mint
384
383
  { pubkey: reserveWhitelist, isSigner: false, isWritable: false }, // 12: reserve_whitelist_entry (optional)
385
- { pubkey: exports.KLEND_PROGRAM, isSigner: false, isWritable: false }, // 13: klend_program
384
+ { pubkey: constants_1.KLEND_PROGRAM, isSigner: false, isWritable: false }, // 13: klend_program
386
385
  { pubkey: SPL_TOKEN_PROGRAM, isSigner: false, isWritable: false }, // 14: reserve_collateral_token_program
387
386
  { pubkey: SPL_TOKEN_PROGRAM, isSigner: false, isWritable: false }, // 15: token_program
388
387
  { pubkey: SYSVAR_INSTRUCTIONS, isSigner: false, isWritable: false }, // 16: instruction_sysvar_account
@@ -432,29 +431,53 @@ async function buildKaminoInvestIxsIfStale(connection, payer, baseMint, protocol
432
431
  const ATA_PROG = new web3_js_1.PublicKey("ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL");
433
432
  // Payer's base ATA (for crank fee — usually 0)
434
433
  const [payerAta] = web3_js_1.PublicKey.findProgramAddressSync([payer.toBuffer(), TOKEN_PROG.toBuffer(), baseMint.toBuffer()], ATA_PROG);
434
+ // Batch-fetch all vault states in one round-trip, then derive the reserve
435
+ // pubkeys from the returned buffers, then batch-fetch all reserves. Total:
436
+ // 2 RPC calls regardless of how many vaults are stale (previous loop did
437
+ // 2N sequential calls).
438
+ const vaultInfos = await connection.getMultipleAccountsInfo(staleVaults, "confirmed");
439
+ const reserveKeys = vaultInfos.map((info) => {
440
+ if (!info)
441
+ return null;
442
+ try {
443
+ const alloc = readVaultAllocation(info.data, 0);
444
+ return alloc.reserve.equals(web3_js_1.PublicKey.default) ? null : alloc.reserve;
445
+ }
446
+ catch {
447
+ return null;
448
+ }
449
+ });
450
+ // Reserves to fetch: only the non-null ones, but remember which original
451
+ // index each corresponds to so we can line them back up.
452
+ const reserveFetchList = [];
453
+ const reserveIdx = [];
454
+ for (let i = 0; i < reserveKeys.length; i++) {
455
+ const r = reserveKeys[i];
456
+ if (r) {
457
+ reserveIdx.push(i);
458
+ reserveFetchList.push(r);
459
+ }
460
+ }
461
+ const reserveInfos = reserveFetchList.length > 0
462
+ ? await connection.getMultipleAccountsInfo(reserveFetchList, "confirmed")
463
+ : [];
435
464
  const ixs = [];
436
- for (const vaultState of staleVaults) {
465
+ for (let j = 0; j < reserveFetchList.length; j++) {
466
+ const origIdx = reserveIdx[j];
467
+ const vaultInfo = vaultInfos[origIdx];
468
+ const reserveInfo = reserveInfos[j];
469
+ if (!reserveInfo)
470
+ continue;
471
+ // Validate reserve is owned by KLend (skip if migrated/closed)
472
+ if (!reserveInfo.owner.equals(constants_1.KLEND_PROGRAM))
473
+ continue;
437
474
  try {
438
- // Fetch vault_state and its first reserve
439
- const vaultInfo = await connection.getAccountInfo(vaultState);
440
- if (!vaultInfo)
441
- continue;
442
- const alloc = readVaultAllocation(vaultInfo.data, 0);
443
- if (alloc.reserve.equals(web3_js_1.PublicKey.default))
444
- continue;
445
- const reserveInfo = await connection.getAccountInfo(alloc.reserve);
446
- if (!reserveInfo)
447
- continue;
448
- // Validate reserve is owned by KLend (skip if migrated/closed)
449
- if (!reserveInfo.owner.equals(exports.KLEND_PROGRAM))
450
- continue;
451
- ixs.push(buildKaminoInvestIx(payer, payerAta, vaultState, baseMint, vaultInfo.data, reserveInfo.data, 0));
475
+ ixs.push(buildKaminoInvestIx(payer, payerAta, staleVaults[origIdx], baseMint, vaultInfo.data, reserveInfo.data, 0));
452
476
  }
453
477
  catch {
454
- // Skip vault if any account data is unreadable
478
+ // Skip if ix builder can't parse the data
455
479
  continue;
456
480
  }
457
481
  }
458
482
  return ixs;
459
483
  }
460
- //# sourceMappingURL=kamino-vault.js.map
@@ -1,5 +1,12 @@
1
1
  import { PublicKey } from "@solana/web3.js";
2
2
  export declare function findStrategyStatePda(baseMint: PublicKey, programId?: PublicKey): [PublicKey, number];
3
3
  export declare function findStvPositionPda(stv: PublicKey, programId?: PublicKey): [PublicKey, number];
4
- export declare function findManagerRolePda(strategyState: PublicKey, manager: PublicKey, programId?: PublicKey): [PublicKey, number];
5
- //# sourceMappingURL=pda.d.ts.map
4
+ /**
5
+ * Derive the per-strategy_state `ManagerRole` PDA for Elemental Lend.
6
+ * Seeds: `["manager", strategy_state, manager]`.
7
+ *
8
+ * Note the per-program prefix on the name: each Elemental program has its
9
+ * own `ManagerRole` PDA scoped to a different anchor account (`p-stv-core`
10
+ * → STV, `jlpd-strategy` → JlpdConfig).
11
+ */
12
+ export declare function findLendManagerRolePda(strategyState: PublicKey, manager: PublicKey, programId?: PublicKey): [PublicKey, number];
@@ -2,7 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.findStrategyStatePda = findStrategyStatePda;
4
4
  exports.findStvPositionPda = findStvPositionPda;
5
- exports.findManagerRolePda = findManagerRolePda;
5
+ exports.findLendManagerRolePda = findLendManagerRolePda;
6
6
  const web3_js_1 = require("@solana/web3.js");
7
7
  const constants_1 = require("./constants");
8
8
  function findStrategyStatePda(baseMint, programId = constants_1.PROGRAM_ID) {
@@ -11,7 +11,14 @@ function findStrategyStatePda(baseMint, programId = constants_1.PROGRAM_ID) {
11
11
  function findStvPositionPda(stv, programId = constants_1.PROGRAM_ID) {
12
12
  return web3_js_1.PublicKey.findProgramAddressSync([constants_1.POSITION_SEED, stv.toBuffer()], programId);
13
13
  }
14
- function findManagerRolePda(strategyState, manager, programId = constants_1.PROGRAM_ID) {
14
+ /**
15
+ * Derive the per-strategy_state `ManagerRole` PDA for Elemental Lend.
16
+ * Seeds: `["manager", strategy_state, manager]`.
17
+ *
18
+ * Note the per-program prefix on the name: each Elemental program has its
19
+ * own `ManagerRole` PDA scoped to a different anchor account (`p-stv-core`
20
+ * → STV, `jlpd-strategy` → JlpdConfig).
21
+ */
22
+ function findLendManagerRolePda(strategyState, manager, programId = constants_1.PROGRAM_ID) {
15
23
  return web3_js_1.PublicKey.findProgramAddressSync([constants_1.MANAGER_SEED, strategyState.toBuffer(), manager.toBuffer()], programId);
16
24
  }
17
- //# sourceMappingURL=pda.js.map