@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
@@ -8,4 +8,3 @@ export * from "./remaining-accounts";
8
8
  export * from "./send-tx";
9
9
  export * from "./sol-wrap";
10
10
  export * from "./prices";
11
- //# sourceMappingURL=index.d.ts.map
@@ -24,4 +24,3 @@ __exportStar(require("./remaining-accounts"), exports);
24
24
  __exportStar(require("./send-tx"), exports);
25
25
  __exportStar(require("./sol-wrap"), exports);
26
26
  __exportStar(require("./prices"), exports);
27
- //# sourceMappingURL=index.js.map
@@ -42,6 +42,8 @@ export interface InitOrUpdateStvArgs {
42
42
  export declare function createInitOrUpdateStvIx(args: InitOrUpdateStvArgs, programId?: PublicKey): TransactionInstruction;
43
43
  export interface DepositArgs {
44
44
  user: PublicKey;
45
+ /** GlobalConfig PDA — checked for CFG_FLAG_GLOBAL_PAUSED */
46
+ config: PublicKey;
45
47
  stv: PublicKey;
46
48
  vaultAta: PublicKey;
47
49
  userBaseAta: PublicKey;
@@ -61,6 +63,8 @@ export interface DepositArgs {
61
63
  export declare function createDepositIx(args: DepositArgs, programId?: PublicKey): TransactionInstruction;
62
64
  export interface RequestWithdrawArgs {
63
65
  user: PublicKey;
66
+ /** GlobalConfig PDA — checked for CFG_FLAG_GLOBAL_PAUSED */
67
+ config: PublicKey;
64
68
  stv: PublicKey;
65
69
  withdrawRequest: PublicKey;
66
70
  userEvAta: PublicKey;
@@ -74,6 +78,8 @@ export interface RequestWithdrawArgs {
74
78
  export declare function createRequestWithdrawIx(args: RequestWithdrawArgs, programId?: PublicKey): TransactionInstruction;
75
79
  export interface ClaimWithdrawArgs {
76
80
  user: PublicKey;
81
+ /** GlobalConfig PDA — checked for CFG_FLAG_GLOBAL_PAUSED */
82
+ config: PublicKey;
77
83
  stv: PublicKey;
78
84
  withdrawRequest: PublicKey;
79
85
  vaultAta: PublicKey;
@@ -88,6 +94,8 @@ export declare function createClaimWithdrawIx(args: ClaimWithdrawArgs, programId
88
94
  export interface OverrideClaimWithdrawArgs {
89
95
  manager: PublicKey;
90
96
  managerRole: PublicKey;
97
+ /** GlobalConfig PDA — checked for CFG_FLAG_GLOBAL_PAUSED */
98
+ config: PublicKey;
91
99
  user: PublicKey;
92
100
  stv: PublicKey;
93
101
  withdrawRequest: PublicKey;
@@ -101,6 +109,8 @@ export interface OverrideClaimWithdrawArgs {
101
109
  export declare function createOverrideClaimWithdrawIx(args: OverrideClaimWithdrawArgs, programId?: PublicKey): TransactionInstruction;
102
110
  export interface ProcessEpochArgs {
103
111
  payer: PublicKey;
112
+ /** GlobalConfig PDA — checked for CFG_FLAG_GLOBAL_PAUSED */
113
+ config: PublicKey;
104
114
  stv: PublicKey;
105
115
  evMint: PublicKey;
106
116
  feeReceiverEvAta: PublicKey;
@@ -116,6 +126,8 @@ export declare function createProcessEpochIx(args: ProcessEpochArgs, programId?:
116
126
  export interface DepositToStrategyArgs {
117
127
  manager: PublicKey;
118
128
  managerRole: PublicKey;
129
+ /** GlobalConfig PDA — checked for CFG_FLAG_GLOBAL_PAUSED */
130
+ config: PublicKey;
119
131
  stv: PublicKey;
120
132
  vaultAta: PublicKey;
121
133
  baseMint: PublicKey;
@@ -126,7 +138,13 @@ export interface DepositToStrategyArgs {
126
138
  tokenProgram: PublicKey;
127
139
  amount: BN | number;
128
140
  minShares: BN | number;
129
- /** Number of auto-unroute accounts appended after lend accounts (0 = no auto-unroute) */
141
+ /**
142
+ * Number of protocol AUM accounts (kVault: 2/protocol, Jupiter Lend: 3/protocol)
143
+ * used by update_lend_aum for fresh lend valuation before the reserved_base
144
+ * liquidity lock check. Always required (0 if lend has no active protocols).
145
+ */
146
+ protocolAumCount: number;
147
+ /** Number of auto-unroute accounts appended after protocol accounts (0 = no auto-unroute) */
130
148
  autoUnrouteCount?: number;
131
149
  remainingAccounts?: AccountMeta[];
132
150
  }
@@ -134,6 +152,8 @@ export declare function createDepositToStrategyIx(args: DepositToStrategyArgs, p
134
152
  export interface WithdrawFromStrategyArgs {
135
153
  manager: PublicKey;
136
154
  managerRole: PublicKey;
155
+ /** GlobalConfig PDA — checked for CFG_FLAG_GLOBAL_PAUSED */
156
+ config: PublicKey;
137
157
  stv: PublicKey;
138
158
  vaultAta: PublicKey;
139
159
  baseMint: PublicKey;
@@ -153,9 +173,7 @@ export interface CloseStvArgs {
153
173
  stv: PublicKey;
154
174
  evMint: PublicKey;
155
175
  vaultAta: PublicKey;
156
- baseMint: PublicKey;
157
176
  tokenProgram: PublicKey;
158
- remainingAccounts?: AccountMeta[];
159
177
  }
160
178
  export declare function createCloseStvIx(args: CloseStvArgs, programId?: PublicKey): TransactionInstruction;
161
179
  export interface AddManagerArgs {
@@ -176,6 +194,34 @@ export interface RemoveManagerArgs {
176
194
  managerRole: PublicKey;
177
195
  }
178
196
  export declare function createRemoveManagerIx(args: RemoveManagerArgs, programId?: PublicKey): TransactionInstruction;
197
+ export interface MigrateLendArgs {
198
+ admin: PublicKey;
199
+ payer: PublicKey;
200
+ config: PublicKey;
201
+ stv: PublicKey;
202
+ vaultAta: PublicKey;
203
+ baseMint: PublicKey;
204
+ tokenProgram: PublicKey;
205
+ systemProgram?: PublicKey;
206
+ /** Current lend program — must match stv.lend_program on-chain. */
207
+ oldLendProgram: PublicKey;
208
+ /** New lend program (PublicKey.default to deactivate lend entirely). */
209
+ newLendProgram: PublicKey;
210
+ /** Protocol AUM accounts for old lend update_aum. */
211
+ protocolAumCount: number;
212
+ /** Auto-unroute accounts for old lend withdraw. */
213
+ autoUnrouteCount: number;
214
+ /**
215
+ * remaining_accounts layout:
216
+ * Old section (4 + protocolAumCount + autoUnrouteCount):
217
+ * [oldLendProgram, oldStrategyState, oldStvPosition, oldBaseAta,
218
+ * ...protocolAumAccounts, ...autoUnrouteAccounts]
219
+ * New section (if newLendProgram != default, 4 accounts):
220
+ * [newLendProgram, newStrategyState, newPositionPda, newBaseAta]
221
+ */
222
+ remainingAccounts?: AccountMeta[];
223
+ }
224
+ export declare function createMigrateLendIx(args: MigrateLendArgs, programId?: PublicKey): TransactionInstruction;
179
225
  export declare function buildLendRemainingAccounts(lend: {
180
226
  lendProgram: PublicKey;
181
227
  lendStrategyState: PublicKey;
@@ -186,4 +232,3 @@ export declare function buildStrategyRemainingAccounts(strategies: {
186
232
  strategyState: PublicKey;
187
233
  stvPosition: PublicKey;
188
234
  }[]): AccountMeta[];
189
- //# sourceMappingURL=instructions.d.ts.map
@@ -12,6 +12,7 @@ exports.createWithdrawFromStrategyIx = createWithdrawFromStrategyIx;
12
12
  exports.createCloseStvIx = createCloseStvIx;
13
13
  exports.createAddManagerIx = createAddManagerIx;
14
14
  exports.createRemoveManagerIx = createRemoveManagerIx;
15
+ exports.createMigrateLendIx = createMigrateLendIx;
15
16
  exports.buildLendRemainingAccounts = buildLendRemainingAccounts;
16
17
  exports.buildStrategyRemainingAccounts = buildStrategyRemainingAccounts;
17
18
  const web3_js_1 = require("@solana/web3.js");
@@ -71,7 +72,7 @@ function createInitOrUpdateStvIx(args, programId = constants_1.PROGRAM_ID) {
71
72
  });
72
73
  }
73
74
  function createDepositIx(args, programId = constants_1.PROGRAM_ID) {
74
- const { user, stv, vaultAta, userBaseAta, userEvAta, evMint, feeReceiverEvAta, baseMint, tokenProgram, amount, minShares, protocolAumCount = 0, autoRouteCount = 0, remainingAccounts = [], } = args;
75
+ const { user, config, stv, vaultAta, userBaseAta, userEvAta, evMint, feeReceiverEvAta, baseMint, tokenProgram, amount, minShares, protocolAumCount = 0, autoRouteCount = 0, remainingAccounts = [], } = args;
75
76
  const data = [constants_1.IX_DEPOSIT];
76
77
  (0, buffer_1.writeU64)(data, amount);
77
78
  (0, buffer_1.writeU64)(data, minShares);
@@ -80,6 +81,7 @@ function createDepositIx(args, programId = constants_1.PROGRAM_ID) {
80
81
  return new web3_js_1.TransactionInstruction({
81
82
  keys: [
82
83
  { pubkey: user, isSigner: true, isWritable: true },
84
+ { pubkey: config, isSigner: false, isWritable: false },
83
85
  { pubkey: stv, isSigner: false, isWritable: true },
84
86
  { pubkey: vaultAta, isSigner: false, isWritable: true },
85
87
  { pubkey: userBaseAta, isSigner: false, isWritable: true },
@@ -95,13 +97,14 @@ function createDepositIx(args, programId = constants_1.PROGRAM_ID) {
95
97
  });
96
98
  }
97
99
  function createRequestWithdrawIx(args, programId = constants_1.PROGRAM_ID) {
98
- const { user, stv, withdrawRequest, userEvAta, escrowEvAta, evMint, tokenProgram, systemProgram = web3_js_1.SystemProgram.programId, shares, wrBump, } = args;
100
+ const { user, config, stv, withdrawRequest, userEvAta, escrowEvAta, evMint, tokenProgram, systemProgram = web3_js_1.SystemProgram.programId, shares, wrBump, } = args;
99
101
  const data = [constants_1.IX_REQUEST_WITHDRAW];
100
102
  (0, buffer_1.writeU64)(data, shares);
101
103
  data.push(wrBump & 0xff);
102
104
  return new web3_js_1.TransactionInstruction({
103
105
  keys: [
104
106
  { pubkey: user, isSigner: true, isWritable: true },
107
+ { pubkey: config, isSigner: false, isWritable: false },
105
108
  { pubkey: stv, isSigner: false, isWritable: true },
106
109
  { pubkey: withdrawRequest, isSigner: false, isWritable: true },
107
110
  { pubkey: userEvAta, isSigner: false, isWritable: true },
@@ -115,13 +118,15 @@ function createRequestWithdrawIx(args, programId = constants_1.PROGRAM_ID) {
115
118
  });
116
119
  }
117
120
  function createClaimWithdrawIx(args, programId = constants_1.PROGRAM_ID) {
118
- const { user, stv, withdrawRequest, vaultAta, userBaseAta, baseMint, tokenProgram, remainingAccounts = [], autoUnrouteCount = 0, } = args;
119
- const data = autoUnrouteCount > 0
120
- ? Buffer.from([constants_1.IX_CLAIM_WITHDRAW, autoUnrouteCount & 0xff])
121
- : Buffer.from([constants_1.IX_CLAIM_WITHDRAW]);
121
+ const { user, config, stv, withdrawRequest, vaultAta, userBaseAta, baseMint, tokenProgram, remainingAccounts = [], autoUnrouteCount = 0, } = args;
122
+ // Always serialize the auto_unroute_count byte (write 0 when there's no
123
+ // auto-unroute). The on-chain handler always reads this byte from
124
+ // instruction data.
125
+ const data = Buffer.from([constants_1.IX_CLAIM_WITHDRAW, autoUnrouteCount & 0xff]);
122
126
  return new web3_js_1.TransactionInstruction({
123
127
  keys: [
124
128
  { pubkey: user, isSigner: true, isWritable: true },
129
+ { pubkey: config, isSigner: false, isWritable: false },
125
130
  { pubkey: stv, isSigner: false, isWritable: true },
126
131
  { pubkey: withdrawRequest, isSigner: false, isWritable: true },
127
132
  { pubkey: vaultAta, isSigner: false, isWritable: true },
@@ -135,7 +140,7 @@ function createClaimWithdrawIx(args, programId = constants_1.PROGRAM_ID) {
135
140
  });
136
141
  }
137
142
  function createOverrideClaimWithdrawIx(args, programId = constants_1.PROGRAM_ID) {
138
- const { manager, managerRole, user, stv, withdrawRequest, vaultAta, userBaseAta, baseMint, tokenProgram, remainingAccounts = [], autoUnrouteCount = 0, } = args;
143
+ const { manager, managerRole, config, user, stv, withdrawRequest, vaultAta, userBaseAta, baseMint, tokenProgram, remainingAccounts = [], autoUnrouteCount = 0, } = args;
139
144
  const data = autoUnrouteCount > 0
140
145
  ? Buffer.from([constants_1.IX_OVERRIDE_CLAIM_WITHDRAW, autoUnrouteCount & 0xff])
141
146
  : Buffer.from([constants_1.IX_OVERRIDE_CLAIM_WITHDRAW]);
@@ -143,6 +148,7 @@ function createOverrideClaimWithdrawIx(args, programId = constants_1.PROGRAM_ID)
143
148
  keys: [
144
149
  { pubkey: manager, isSigner: true, isWritable: false },
145
150
  { pubkey: managerRole, isSigner: false, isWritable: false },
151
+ { pubkey: config, isSigner: false, isWritable: false },
146
152
  { pubkey: user, isSigner: false, isWritable: true },
147
153
  { pubkey: stv, isSigner: false, isWritable: true },
148
154
  { pubkey: withdrawRequest, isSigner: false, isWritable: true },
@@ -157,10 +163,11 @@ function createOverrideClaimWithdrawIx(args, programId = constants_1.PROGRAM_ID)
157
163
  });
158
164
  }
159
165
  function createProcessEpochIx(args, programId = constants_1.PROGRAM_ID) {
160
- const { payer, stv, evMint, feeReceiverEvAta, escrowEvAta, vaultAta, tokenProgram, advanceEpoch, protocolAumCount = 0, remainingAccounts = [], } = args;
166
+ const { payer, config, stv, evMint, feeReceiverEvAta, escrowEvAta, vaultAta, tokenProgram, advanceEpoch, protocolAumCount = 0, remainingAccounts = [], } = args;
161
167
  return new web3_js_1.TransactionInstruction({
162
168
  keys: [
163
169
  { pubkey: payer, isSigner: true, isWritable: true },
170
+ { pubkey: config, isSigner: false, isWritable: false },
164
171
  { pubkey: stv, isSigner: false, isWritable: true },
165
172
  { pubkey: evMint, isSigner: false, isWritable: true },
166
173
  { pubkey: feeReceiverEvAta, isSigner: false, isWritable: true },
@@ -174,10 +181,13 @@ function createProcessEpochIx(args, programId = constants_1.PROGRAM_ID) {
174
181
  });
175
182
  }
176
183
  function createDepositToStrategyIx(args, programId = constants_1.PROGRAM_ID) {
177
- const { manager, managerRole, stv, vaultAta, baseMint, strategyProgram, strategyState, stvPosition, strategyBaseAta, tokenProgram, amount, minShares, autoUnrouteCount = 0, remainingAccounts = [], } = args;
184
+ const { manager, managerRole, config, stv, vaultAta, baseMint, strategyProgram, strategyState, stvPosition, strategyBaseAta, tokenProgram, amount, minShares, protocolAumCount, autoUnrouteCount = 0, remainingAccounts = [], } = args;
178
185
  const data = [constants_1.IX_DEPOSIT_TO_STRATEGY];
179
186
  (0, buffer_1.writeU64)(data, amount);
180
187
  (0, buffer_1.writeU64)(data, minShares);
188
+ // Always emit protocol_aum_count at offset 16 (even if 0); auto_unroute_count
189
+ // remains optional and is appended only when > 0.
190
+ data.push(protocolAumCount & 0xff);
181
191
  if (autoUnrouteCount > 0) {
182
192
  data.push(autoUnrouteCount & 0xff);
183
193
  }
@@ -185,6 +195,7 @@ function createDepositToStrategyIx(args, programId = constants_1.PROGRAM_ID) {
185
195
  keys: [
186
196
  { pubkey: manager, isSigner: true, isWritable: true },
187
197
  { pubkey: managerRole, isSigner: false, isWritable: false },
198
+ { pubkey: config, isSigner: false, isWritable: false },
188
199
  { pubkey: stv, isSigner: false, isWritable: true },
189
200
  { pubkey: vaultAta, isSigner: false, isWritable: true },
190
201
  { pubkey: baseMint, isSigner: false, isWritable: false },
@@ -200,13 +211,14 @@ function createDepositToStrategyIx(args, programId = constants_1.PROGRAM_ID) {
200
211
  });
201
212
  }
202
213
  function createWithdrawFromStrategyIx(args, programId = constants_1.PROGRAM_ID) {
203
- const { manager, managerRole, stv, vaultAta, baseMint, strategyProgram, strategyState, stvPosition, strategyBaseAta, tokenProgram, shares, remainingAccounts = [], } = args;
214
+ const { manager, managerRole, config, stv, vaultAta, baseMint, strategyProgram, strategyState, stvPosition, strategyBaseAta, tokenProgram, shares, remainingAccounts = [], } = args;
204
215
  const data = [constants_1.IX_WITHDRAW_FROM_STRATEGY];
205
216
  (0, buffer_1.writeU64)(data, shares);
206
217
  return new web3_js_1.TransactionInstruction({
207
218
  keys: [
208
219
  { pubkey: manager, isSigner: true, isWritable: true },
209
220
  { pubkey: managerRole, isSigner: false, isWritable: false },
221
+ { pubkey: config, isSigner: false, isWritable: false },
210
222
  { pubkey: stv, isSigner: false, isWritable: true },
211
223
  { pubkey: vaultAta, isSigner: false, isWritable: true },
212
224
  { pubkey: baseMint, isSigner: false, isWritable: false },
@@ -222,7 +234,7 @@ function createWithdrawFromStrategyIx(args, programId = constants_1.PROGRAM_ID)
222
234
  });
223
235
  }
224
236
  function createCloseStvIx(args, programId = constants_1.PROGRAM_ID) {
225
- const { admin, payer, config, stv, evMint, vaultAta, baseMint, tokenProgram, remainingAccounts = [] } = args;
237
+ const { admin, payer, config, stv, evMint, vaultAta, tokenProgram } = args;
226
238
  return new web3_js_1.TransactionInstruction({
227
239
  keys: [
228
240
  { pubkey: admin, isSigner: true, isWritable: false },
@@ -231,9 +243,7 @@ function createCloseStvIx(args, programId = constants_1.PROGRAM_ID) {
231
243
  { pubkey: stv, isSigner: false, isWritable: true },
232
244
  { pubkey: evMint, isSigner: false, isWritable: true },
233
245
  { pubkey: vaultAta, isSigner: false, isWritable: true },
234
- { pubkey: baseMint, isSigner: false, isWritable: false },
235
246
  { pubkey: tokenProgram, isSigner: false, isWritable: false },
236
- ...remainingAccounts,
237
247
  ],
238
248
  programId,
239
249
  data: Buffer.from([constants_1.IX_CLOSE_STV]),
@@ -269,6 +279,29 @@ function createRemoveManagerIx(args, programId = constants_1.PROGRAM_ID) {
269
279
  data: Buffer.from([constants_1.IX_REMOVE_MANAGER]),
270
280
  });
271
281
  }
282
+ function createMigrateLendIx(args, programId = constants_1.PROGRAM_ID) {
283
+ const { admin, payer, config, stv, vaultAta, baseMint, tokenProgram, systemProgram = web3_js_1.SystemProgram.programId, oldLendProgram, newLendProgram, protocolAumCount, autoUnrouteCount, remainingAccounts = [], } = args;
284
+ const data = [constants_1.IX_MIGRATE_LEND];
285
+ data.push(...oldLendProgram.toBuffer());
286
+ data.push(...newLendProgram.toBuffer());
287
+ data.push(protocolAumCount & 0xff);
288
+ data.push(autoUnrouteCount & 0xff);
289
+ return new web3_js_1.TransactionInstruction({
290
+ keys: [
291
+ { pubkey: admin, isSigner: true, isWritable: false },
292
+ { pubkey: payer, isSigner: true, isWritable: true },
293
+ { pubkey: config, isSigner: false, isWritable: false },
294
+ { pubkey: stv, isSigner: false, isWritable: true },
295
+ { pubkey: vaultAta, isSigner: false, isWritable: true },
296
+ { pubkey: baseMint, isSigner: false, isWritable: false },
297
+ { pubkey: tokenProgram, isSigner: false, isWritable: false },
298
+ { pubkey: systemProgram, isSigner: false, isWritable: false },
299
+ ...remainingAccounts,
300
+ ],
301
+ programId,
302
+ data: Buffer.from(data),
303
+ });
304
+ }
272
305
  // ---------------------------------------------------------------------------
273
306
  // Remaining Accounts Helpers
274
307
  // ---------------------------------------------------------------------------
@@ -287,4 +320,3 @@ function buildStrategyRemainingAccounts(strategies) {
287
320
  }
288
321
  return accounts;
289
322
  }
290
- //# sourceMappingURL=instructions.js.map
@@ -4,5 +4,12 @@ export declare function findConfigPda(programId?: PublicKey): [PublicKey, number
4
4
  export declare function findStvPda(vaultId: number | BN, programId?: PublicKey): [PublicKey, number];
5
5
  export declare function findEvMintPda(vaultId: number | BN, programId?: PublicKey): [PublicKey, number];
6
6
  export declare function findWithdrawRequestPda(stv: PublicKey, user: PublicKey, epochId: number, programId?: PublicKey): [PublicKey, number];
7
- export declare function findManagerRolePda(stv: PublicKey, manager: PublicKey, programId?: PublicKey): [PublicKey, number];
8
- //# sourceMappingURL=pda.d.ts.map
7
+ /**
8
+ * Derive the per-STV `ManagerRole` PDA for p-STV Core.
9
+ * Seeds: `["manager", stv, manager]`.
10
+ *
11
+ * Note the per-program prefix on the name: each Elemental program has its
12
+ * own `ManagerRole` PDA scoped to a different anchor account
13
+ * (`elemental-lend` → strategy_state, `jlpd-strategy` → config).
14
+ */
15
+ export declare function findStvManagerRolePda(stv: PublicKey, manager: PublicKey, programId?: PublicKey): [PublicKey, number];
@@ -7,7 +7,7 @@ exports.findConfigPda = findConfigPda;
7
7
  exports.findStvPda = findStvPda;
8
8
  exports.findEvMintPda = findEvMintPda;
9
9
  exports.findWithdrawRequestPda = findWithdrawRequestPda;
10
- exports.findManagerRolePda = findManagerRolePda;
10
+ exports.findStvManagerRolePda = findStvManagerRolePda;
11
11
  const web3_js_1 = require("@solana/web3.js");
12
12
  const bn_js_1 = __importDefault(require("bn.js"));
13
13
  const constants_1 = require("./constants");
@@ -27,7 +27,14 @@ function findWithdrawRequestPda(stv, user, epochId, programId = constants_1.PROG
27
27
  epochBuf.writeUInt32LE(epochId, 0);
28
28
  return web3_js_1.PublicKey.findProgramAddressSync([constants_1.WITHDRAW_REQUEST_SEED, stv.toBuffer(), user.toBuffer(), epochBuf], programId);
29
29
  }
30
- function findManagerRolePda(stv, manager, programId = constants_1.PROGRAM_ID) {
30
+ /**
31
+ * Derive the per-STV `ManagerRole` PDA for p-STV Core.
32
+ * Seeds: `["manager", stv, manager]`.
33
+ *
34
+ * Note the per-program prefix on the name: each Elemental program has its
35
+ * own `ManagerRole` PDA scoped to a different anchor account
36
+ * (`elemental-lend` → strategy_state, `jlpd-strategy` → config).
37
+ */
38
+ function findStvManagerRolePda(stv, manager, programId = constants_1.PROGRAM_ID) {
31
39
  return web3_js_1.PublicKey.findProgramAddressSync([constants_1.MANAGER_SEED, stv.toBuffer(), manager.toBuffer()], programId);
32
40
  }
33
- //# sourceMappingURL=pda.js.map
@@ -18,4 +18,3 @@ export interface TokenPrice {
18
18
  * @returns Record<mint, usdPrice>
19
19
  */
20
20
  export declare function fetchUsdPrices(mints: string[]): Promise<Record<string, number>>;
21
- //# sourceMappingURL=prices.d.ts.map
@@ -75,4 +75,3 @@ async function fetchUsdPrices(mints) {
75
75
  }
76
76
  return prices;
77
77
  }
78
- //# sourceMappingURL=prices.js.map
@@ -6,13 +6,9 @@
6
6
  * lend + protocol AUM + strategy pair + auto-route/unroute account building
7
7
  * logic out of the frontend and into the SDK.
8
8
  */
9
- import { AccountMeta, Connection, PublicKey, TransactionInstruction } from "@solana/web3.js";
10
- /**
11
- * Minimal connection interface accepted by the context builders.
12
- * Using a structural type avoids nominal type mismatches when the
13
- * consumer has a different version of @solana/web3.js installed.
14
- */
15
- export type SolanaConnection = Pick<Connection, "getAccountInfo" | "getMultipleAccountsInfo" | "getTokenAccountsByOwner" | "getSlot" | "getEpochInfo" | "getBlockTime">;
9
+ import { AccountMeta, PublicKey, TransactionInstruction } from "@solana/web3.js";
10
+ import type { SolanaConnection } from "../common/connection";
11
+ export type { SolanaConnection };
16
12
  /** Minimal vault shape required by the context builders. */
17
13
  export interface VaultInfo {
18
14
  /** STV account address */
@@ -43,6 +39,8 @@ export interface ClaimWithdrawContext {
43
39
  }
44
40
  export interface DepositToStrategyContext {
45
41
  remainingAccounts: AccountMeta[];
42
+ /** Number of protocol AUM accounts (after the 4 fixed lend accounts). */
43
+ protocolAumCount: number;
46
44
  autoUnrouteCount: number;
47
45
  preInstructions: TransactionInstruction[];
48
46
  }
@@ -76,17 +74,19 @@ export declare function buildDepositContext(connection: SolanaConnection, vault:
76
74
  * - If lend is active, derives lend PDAs
77
75
  * - If USDC + Jupiter Lend, appends auto-unroute accounts
78
76
  */
79
- export declare function buildClaimWithdrawContext(connection: SolanaConnection, vault: VaultInfo): Promise<ClaimWithdrawContext>;
77
+ export declare function buildClaimWithdrawContext(vault: VaultInfo): Promise<ClaimWithdrawContext>;
80
78
  /**
81
79
  * Build the complete remaining_accounts for a deposit_to_strategy instruction.
82
80
  *
83
- * Layout: [4 lend, K auto_unroute]
81
+ * Layout: [4 fixed lend, N protocol_aum, K auto_unroute]
84
82
  *
85
- * Same as claim_withdraw: if lend is active, derives lend PDAs.
86
- * If USDC + Jupiter Lend, appends auto-unroute accounts for unsweep.
83
+ * - Fixed lend accounts (if lend is active)
84
+ * - Protocol AUM accounts: required by the on-chain handler to refresh lend
85
+ * valuation via update_lend_aum before the reserved_base liquidity lock check
86
+ * - Auto-unroute accounts: forwarded to the lend withdraw CPI for unsweep
87
87
  *
88
- * Note: no Kamino invest pre-instructions here deposit_to_strategy unsweeps
89
- * from the active protocol (Jupiter Lend for USDC), not Kamino.
88
+ * The `connection` parameter is required to fetch LendStrategyState and
89
+ * resolve protocol AUM accounts.
90
90
  */
91
91
  export declare function buildDepositToStrategyContext(connection: SolanaConnection, vault: VaultInfo): Promise<DepositToStrategyContext>;
92
92
  /**
@@ -96,4 +96,3 @@ export declare function buildDepositToStrategyContext(connection: SolanaConnecti
96
96
  * 'advance': empty remaining_accounts.
97
97
  */
98
98
  export declare function buildProcessEpochContext(connection: SolanaConnection, vault: VaultInfo, phase: "lockPps" | "advance"): Promise<ProcessEpochContext>;
99
- //# sourceMappingURL=remaining-accounts.d.ts.map
@@ -17,30 +17,24 @@ const pda_1 = require("../elemental-lend/pda");
17
17
  const accounts_1 = require("../elemental-lend/accounts");
18
18
  const jupiter_lend_1 = require("../elemental-lend/jupiter-lend");
19
19
  const kamino_vault_1 = require("../elemental-lend/kamino-vault");
20
- const spl_token_1 = require("@solana/spl-token");
20
+ const ata_1 = require("../common/ata");
21
21
  // ---------------------------------------------------------------------------
22
22
  // Helpers
23
23
  // ---------------------------------------------------------------------------
24
24
  const DEFAULT_PUBKEY = web3_js_1.PublicKey.default;
25
25
  const TOKEN_PROGRAM = new web3_js_1.PublicKey("TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA");
26
- const USDC_MINT = new web3_js_1.PublicKey("EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v");
27
26
  const STRATEGY_STATE_SEED = Buffer.from("strategy_state");
28
27
  const POSITION_SEED = Buffer.from("position");
29
28
  function isDefault(pubkey) {
30
29
  return pubkey.equals(DEFAULT_PUBKEY);
31
30
  }
32
- /** Derive the ATA address (same logic as @solana/spl-token getAssociatedTokenAddressSync) */
33
- function findAta(mint, owner, tokenProgram) {
34
- const [ata] = web3_js_1.PublicKey.findProgramAddressSync([owner.toBuffer(), tokenProgram.toBuffer(), mint.toBuffer()], spl_token_1.ASSOCIATED_TOKEN_PROGRAM_ID);
35
- return ata;
36
- }
37
31
  /**
38
32
  * Build the 4 fixed lend accounts: [lendProgram, lendStrategyState, lendPosition, lendBaseAta]
39
33
  */
40
34
  function buildFixedLendAccounts(lendProgram, baseMint, stvAddress) {
41
35
  const [lendStrategyState] = (0, pda_1.findStrategyStatePda)(baseMint, lendProgram);
42
36
  const [lendPosition] = (0, pda_1.findStvPositionPda)(stvAddress, lendProgram);
43
- const lendBaseAta = findAta(baseMint, lendStrategyState, TOKEN_PROGRAM);
37
+ const lendBaseAta = (0, ata_1.findAta)(baseMint, lendStrategyState, TOKEN_PROGRAM);
44
38
  return {
45
39
  lendStrategyState,
46
40
  accounts: [
@@ -95,32 +89,30 @@ async function buildDepositContext(connection, vault, payer) {
95
89
  if (!isDefault(vault.lendProgram)) {
96
90
  const { accounts: lendAccounts, lendStrategyState } = buildFixedLendAccounts(vault.lendProgram, vault.baseMint, vault.address);
97
91
  remainingAccounts.push(...lendAccounts);
98
- // Protocol AUM accounts
99
- const conn = connection;
100
- try {
101
- const lendState = await (0, accounts_1.fetchLendStrategyState)(conn, vault.baseMint, vault.lendProgram);
102
- const protocolAccounts = await (0, accounts_1.buildProtocolAccountsForAum)(conn, lendState, lendStrategyState, TOKEN_PROGRAM);
103
- protocolAumCount = protocolAccounts.length;
104
- remainingAccounts.push(...protocolAccounts);
105
- }
106
- catch {
107
- // If strategy state not found, skip protocol accounts
108
- }
109
- // Check kVault staleness prepend invest ix if stale
110
- try {
111
- const conn = connection;
112
- const lendState = await (0, accounts_1.fetchLendStrategyState)(conn, vault.baseMint, vault.lendProgram).catch(() => null);
113
- if (lendState) {
92
+ // Single fetch of LendStrategyState — used for both protocol AUM
93
+ // accounts and kVault staleness check.
94
+ const lendState = await (0, accounts_1.fetchLendStrategyState)(connection, vault.baseMint, vault.lendProgram).catch(() => null);
95
+ if (lendState) {
96
+ // Protocol AUM accounts
97
+ try {
98
+ const protocolAccounts = await (0, accounts_1.buildProtocolAccountsForAum)(connection, lendState, lendStrategyState, TOKEN_PROGRAM);
99
+ protocolAumCount = protocolAccounts.length;
100
+ remainingAccounts.push(...protocolAccounts);
101
+ }
102
+ catch {
103
+ // If protocol resolution fails, skip protocol accounts
104
+ }
105
+ // Check kVault staleness — prepend invest ix if stale
106
+ try {
114
107
  const protocolKeys = lendState.protocols
115
108
  .filter((p) => !isDefault(p));
116
109
  // Need a payer for the invest ix — will be set by the caller
117
- // Use PublicKey.default as placeholder; the caller replaces it
118
- const investIxs = payer ? await (0, kamino_vault_1.buildKaminoInvestIxsIfStale)(conn, payer, vault.baseMint, protocolKeys) : [];
110
+ const investIxs = payer ? await (0, kamino_vault_1.buildKaminoInvestIxsIfStale)(connection, payer, vault.baseMint, protocolKeys) : [];
119
111
  preInstructions.push(...investIxs);
120
112
  }
121
- }
122
- catch {
123
- // Skip if staleness check fails
113
+ catch {
114
+ // Skip if staleness check fails
115
+ }
124
116
  }
125
117
  }
126
118
  // 2. Strategy pair accounts (2 per strategy: state + position)
@@ -132,8 +124,8 @@ async function buildDepositContext(connection, vault, payer) {
132
124
  if (!isDefault(vault.lendProgram) && jupPool) {
133
125
  try {
134
126
  const [lendSS] = (0, pda_1.findStrategyStatePda)(vault.baseMint, vault.lendProgram);
135
- const strategyBaseAta = findAta(vault.baseMint, lendSS, TOKEN_PROGRAM);
136
- const strategyFtokenAta = findAta(jupPool.fTokenMint, lendSS, TOKEN_PROGRAM);
127
+ const strategyBaseAta = (0, ata_1.findAta)(vault.baseMint, lendSS, TOKEN_PROGRAM);
128
+ const strategyFtokenAta = (0, ata_1.findAta)(jupPool.fTokenMint, lendSS, TOKEN_PROGRAM);
137
129
  const autoRouteAccounts = (0, jupiter_lend_1.buildJupLendAutoRouteAccounts)(jupPool, lendSS, strategyBaseAta, strategyFtokenAta);
138
130
  autoRouteCount = autoRouteAccounts.length;
139
131
  for (const acc of autoRouteAccounts) {
@@ -168,7 +160,7 @@ async function buildDepositContext(connection, vault, payer) {
168
160
  * - If lend is active, derives lend PDAs
169
161
  * - If USDC + Jupiter Lend, appends auto-unroute accounts
170
162
  */
171
- async function buildClaimWithdrawContext(connection, vault) {
163
+ async function buildClaimWithdrawContext(vault) {
172
164
  const remainingAccounts = [];
173
165
  const preInstructions = [];
174
166
  let autoUnrouteCount = 0;
@@ -179,8 +171,8 @@ async function buildClaimWithdrawContext(connection, vault) {
179
171
  const jupPoolForUnroute = jupiter_lend_1.JUP_LEND_POOLS[vault.baseMint.toBase58()];
180
172
  if (jupPoolForUnroute) {
181
173
  try {
182
- const lendBaseAta = findAta(vault.baseMint, lendStrategyState, TOKEN_PROGRAM);
183
- const strategyFtokenAta = findAta(jupPoolForUnroute.fTokenMint, lendStrategyState, TOKEN_PROGRAM);
174
+ const lendBaseAta = (0, ata_1.findAta)(vault.baseMint, lendStrategyState, TOKEN_PROGRAM);
175
+ const strategyFtokenAta = (0, ata_1.findAta)(jupPoolForUnroute.fTokenMint, lendStrategyState, TOKEN_PROGRAM);
184
176
  const autoUnrouteAccounts = (0, jupiter_lend_1.buildJupLendAutoUnrouteAccounts)(jupPoolForUnroute, lendStrategyState, strategyFtokenAta, lendBaseAta);
185
177
  autoUnrouteCount = autoUnrouteAccounts.length;
186
178
  remainingAccounts.push(...autoUnrouteAccounts.map(a => ({ ...a, isSigner: false })));
@@ -195,26 +187,43 @@ async function buildClaimWithdrawContext(connection, vault) {
195
187
  /**
196
188
  * Build the complete remaining_accounts for a deposit_to_strategy instruction.
197
189
  *
198
- * Layout: [4 lend, K auto_unroute]
190
+ * Layout: [4 fixed lend, N protocol_aum, K auto_unroute]
199
191
  *
200
- * Same as claim_withdraw: if lend is active, derives lend PDAs.
201
- * If USDC + Jupiter Lend, appends auto-unroute accounts for unsweep.
192
+ * - Fixed lend accounts (if lend is active)
193
+ * - Protocol AUM accounts: required by the on-chain handler to refresh lend
194
+ * valuation via update_lend_aum before the reserved_base liquidity lock check
195
+ * - Auto-unroute accounts: forwarded to the lend withdraw CPI for unsweep
202
196
  *
203
- * Note: no Kamino invest pre-instructions here deposit_to_strategy unsweeps
204
- * from the active protocol (Jupiter Lend for USDC), not Kamino.
197
+ * The `connection` parameter is required to fetch LendStrategyState and
198
+ * resolve protocol AUM accounts.
205
199
  */
206
200
  async function buildDepositToStrategyContext(connection, vault) {
207
201
  const remainingAccounts = [];
202
+ let protocolAumCount = 0;
208
203
  let autoUnrouteCount = 0;
209
204
  if (!isDefault(vault.lendProgram)) {
210
205
  const { accounts: lendAccounts, lendStrategyState } = buildFixedLendAccounts(vault.lendProgram, vault.baseMint, vault.address);
211
206
  remainingAccounts.push(...lendAccounts);
207
+ // Fetch LendStrategyState once — used for protocol AUM resolution.
208
+ const lendState = await (0, accounts_1.fetchLendStrategyState)(connection, vault.baseMint, vault.lendProgram).catch(() => null);
209
+ if (lendState) {
210
+ // Protocol AUM accounts (kVault: 2/protocol, Jupiter Lend: 3/protocol)
211
+ try {
212
+ const protocolAccounts = await (0, accounts_1.buildProtocolAccountsForAum)(connection, lendState, lendStrategyState, TOKEN_PROGRAM);
213
+ protocolAumCount = protocolAccounts.length;
214
+ remainingAccounts.push(...protocolAccounts);
215
+ }
216
+ catch {
217
+ // Skip protocol accounts if resolution fails — on-chain update_lend_aum
218
+ // will then reject if protocols are active.
219
+ }
220
+ }
212
221
  // Auto-unroute from Jupiter Lend (for any asset with a configured pool)
213
222
  const jupPoolForUnroute = jupiter_lend_1.JUP_LEND_POOLS[vault.baseMint.toBase58()];
214
223
  if (jupPoolForUnroute) {
215
224
  try {
216
- const lendBaseAta = findAta(vault.baseMint, lendStrategyState, TOKEN_PROGRAM);
217
- const strategyFtokenAta = findAta(jupPoolForUnroute.fTokenMint, lendStrategyState, TOKEN_PROGRAM);
225
+ const lendBaseAta = (0, ata_1.findAta)(vault.baseMint, lendStrategyState, TOKEN_PROGRAM);
226
+ const strategyFtokenAta = (0, ata_1.findAta)(jupPoolForUnroute.fTokenMint, lendStrategyState, TOKEN_PROGRAM);
218
227
  const autoUnrouteAccounts = (0, jupiter_lend_1.buildJupLendAutoUnrouteAccounts)(jupPoolForUnroute, lendStrategyState, strategyFtokenAta, lendBaseAta);
219
228
  autoUnrouteCount = autoUnrouteAccounts.length;
220
229
  remainingAccounts.push(...autoUnrouteAccounts.map(a => ({ ...a, isSigner: false })));
@@ -224,7 +233,7 @@ async function buildDepositToStrategyContext(connection, vault) {
224
233
  }
225
234
  }
226
235
  }
227
- return { remainingAccounts, autoUnrouteCount, preInstructions: [] };
236
+ return { remainingAccounts, protocolAumCount, autoUnrouteCount, preInstructions: [] };
228
237
  }
229
238
  /**
230
239
  * Build the complete remaining_accounts for a process_epoch instruction.
@@ -243,10 +252,9 @@ async function buildProcessEpochContext(connection, vault, phase) {
243
252
  if (!isDefault(vault.lendProgram)) {
244
253
  const { accounts: lendAccounts, lendStrategyState } = buildFixedLendAccounts(vault.lendProgram, vault.baseMint, vault.address);
245
254
  remainingAccounts.push(...lendAccounts);
246
- const conn = connection;
247
255
  try {
248
- const lendState = await (0, accounts_1.fetchLendStrategyState)(conn, vault.baseMint, vault.lendProgram);
249
- const protocolAccounts = await (0, accounts_1.buildProtocolAccountsForAum)(conn, lendState, lendStrategyState, TOKEN_PROGRAM);
256
+ const lendState = await (0, accounts_1.fetchLendStrategyState)(connection, vault.baseMint, vault.lendProgram);
257
+ const protocolAccounts = await (0, accounts_1.buildProtocolAccountsForAum)(connection, lendState, lendStrategyState, TOKEN_PROGRAM);
250
258
  protocolAumCount = protocolAccounts.length;
251
259
  remainingAccounts.push(...protocolAccounts);
252
260
  }
@@ -259,4 +267,3 @@ async function buildProcessEpochContext(connection, vault, phase) {
259
267
  remainingAccounts.push(...strategyAccounts);
260
268
  return { remainingAccounts, protocolAumCount, preInstructions };
261
269
  }
262
- //# sourceMappingURL=remaining-accounts.js.map