@elemental-stv-core/sdk 0.5.0 → 0.7.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 +36 -29
  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 +108 -30
  61. package/dist/p-stv-core/constants.d.ts +13 -3
  62. package/dist/p-stv-core/constants.js +22 -12
  63. package/dist/p-stv-core/events.d.ts +0 -1
  64. package/dist/p-stv-core/events.js +51 -2
  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 +15 -18
  74. package/dist/p-stv-core/remaining-accounts.js +66 -75
  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 +12 -5
  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
package/LICENSE ADDED
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for describing the origin of the Work and
141
+ reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Support. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or support.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright 2026 Elemental Vaults
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
package/README.md ADDED
@@ -0,0 +1,250 @@
1
+ # @elemental-stv-core/sdk
2
+
3
+ TypeScript SDK for the **Elemental Vaults** on-chain stack. Wraps three Solana programs through one consistent surface so frontends, indexers, and back-end services don't need to hand-roll discriminators, PDA derivation, or account layouts.
4
+
5
+ ```
6
+ @elemental-stv-core/sdk
7
+ ├── /common shared types, buffer helpers, connection type, discriminators
8
+ ├── /p-stv-core vault management — deposits, withdraws, epochs, fees (level N)
9
+ ├── /elemental-lend idle-base lending sweep into Kamino + Jupiter Lend Earn (level N − 1)
10
+ └── /jlpd-strategy JLP-Deconstructed yield strategy + lend-adapter wiring (level N + 1 / N + 2)
11
+ ```
12
+
13
+ ## At a glance
14
+
15
+ | Module | Wraps program | What it gives you |
16
+ | ---------------------------- | ----------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
17
+ | `@elemental-stv-core/sdk/p-stv-core` | `PSTVH77GiPqA3msXmpjAyUXdh3MytK37GCPbPzWu3Rc` | STV / GlobalConfig / WithdrawRequest / ManagerRole accounts; all 14 instruction builders (`createDepositIx`, `createClaimWithdrawIx`, `createProcessEpochIx`, `createMigrateLendIx`, …); event decoders (18 event types); the `sendSmartTx` smart sender (auto CU sim, priority fee, LUT merge); wSOL wrap/unwrap helpers; USD price fetcher |
18
+ | `@elemental-stv-core/sdk/elemental-lend` | `EHaGVh7p6xSxZsq4CcEEZhnV5adDvWg1gS1Rc5rLiBpC` | StrategyState / StvPosition / ManagerRole accounts; CPI + protocol instruction builders; Kamino kVault and Jupiter Lend Earn account-resolution helpers; auto-route / auto-unroute account builders for sweep flows |
19
+ | `@elemental-stv-core/sdk/jlpd-strategy` | `GXqt4ZH2UUBsLWwMNJiZMXza3q7xEGChfW8XjVRjLxr5` | JlpdConfig / per-asset StrategyState / StvPosition; CPI + rebalance instruction builders (`createSwapJlpIx`, `createSettleYieldIx`, `createDepositToAdapterIx`, …); Jupiter swap quote / instruction fetchers; on-chain JLP price + custody readers |
20
+ | `@elemental-stv-core/sdk/common` | (no program) | Buffer reads with bounds checks, ATA derivation, the canonical `SolanaConnection` structural type, and the `StrategyStateHeader` / `StvPosition` interfaces shared across the two strategy programs |
21
+
22
+ ## Module layout
23
+
24
+ Every program-specific module follows the **same file shape**, so you only have to learn the pattern once:
25
+
26
+ ```
27
+ <module>/
28
+ ├── constants.ts program ID, seeds, instruction discriminators, sizes, flags
29
+ ├── pda.ts findXxxPda() helpers — pure synchronous PDA derivation
30
+ ├── types.ts account interfaces + event types
31
+ ├── accounts.ts deserializeXxx() + fetchXxx() readers + GPA queries
32
+ ├── instructions.ts createXxxIx() instruction builders
33
+ ├── events.ts event decoders (p-stv-core: 1-byte disc; Anchor: 8-byte)
34
+ └── (module-specific files)
35
+
36
+ Module-specific files:
37
+ p-stv-core: remaining-accounts.ts, send-tx.ts, sol-wrap.ts, prices.ts
38
+ elemental-lend: kamino-vault.ts, jupiter-lend.ts, protocol-actions.ts
39
+ jlpd-strategy: swap-jlp.ts, settle-yield.ts, jlp-data.ts,
40
+ jlp-borrow.ts, jupusd-earn.ts, adapter.ts
41
+ ```
42
+
43
+ Naming conventions hold across modules:
44
+
45
+ | Pattern | Returns | Side effects |
46
+ | --------------- | ------------------------- | ------------ |
47
+ | `findXxxPda` | `[PublicKey, number]` | none |
48
+ | `deserializeXxx`| typed account | none |
49
+ | `fetchXxx` | typed account | one RPC call |
50
+ | `createXxxIx` | `TransactionInstruction` | none |
51
+ | `buildXxx*` | helper objects | none |
52
+
53
+ `build*` is reserved for helpers that produce ephemeral data (remaining accounts, batched instruction lists). Anything that returns a wire-ready instruction is named `createXxxIx`.
54
+
55
+ ## Naming exceptions worth knowing
56
+
57
+ Each program has its own `ManagerRole` PDA scoped to a different anchor account. To prevent same-named imports from shadowing each other, the helpers carry a per-program prefix:
58
+
59
+ | Program | Function | PDA seeds |
60
+ | --------------- | ------------------------- | ---------------------------------------- |
61
+ | p-stv-core | `findStvManagerRolePda` | `["manager", stv, manager]` |
62
+ | elemental-lend | `findLendManagerRolePda` | `["manager", strategy_state, manager]` |
63
+ | jlpd-strategy | `findJlpdManagerRolePda` | `["manager", config, manager]` |
64
+
65
+ ## Cross-cutting design
66
+
67
+ ### `SolanaConnection` (structural type)
68
+
69
+ Every helper that needs RPC accepts `SolanaConnection`, defined in `common/connection.ts` as a `Pick<Connection, ...>` of just the methods we use. This means callers can pass any version of `@solana/web3.js` without nominal type mismatches across SDK / consumer versions. Narrower call sites use a further `Pick` (e.g. `ProtocolActionConnection` in `elemental-lend/protocol-actions.ts` is `Pick<SolanaConnection, "getAccountInfo" | "getMultipleAccountsInfo">`).
70
+
71
+ ### Numeric convention (BN vs number)
72
+
73
+ Documented at the top of `p-stv-core/types.ts`:
74
+
75
+ - **u64 fields** are deserialized as `BN` (bn.js)
76
+ - **u32 / u16 / u8 fields** are deserialized as plain JavaScript `number`
77
+
78
+ Mixing the two does not auto-convert and silently truncates — when adding new fields to any account interface, follow the rule.
79
+
80
+ ### Discriminators
81
+
82
+ - **p-stv-core (Pinocchio)** uses 1-byte instruction discriminators (0x00–0x0C, 13 instructions). Account discriminators are still 8 bytes for Anchor compatibility.
83
+ - **elemental-lend** and **jlpd-strategy** are Anchor 0.32.1 programs and use 8-byte instruction discriminators throughout.
84
+ - Account discriminators that are truly shared across programs (`ManagerRole`, `StrategyState`, `StvPosition`) live once in `common/constants.ts` and are re-exported by each module.
85
+
86
+ Each constant is documented inline with the source — for example `IX_ADD_MANAGER` in elemental-lend has a `// sha256("global:add_manager")[..8]` comment so an auditor can re-derive it.
87
+
88
+ ### Buffer reads
89
+
90
+ `common/buffer.ts` provides bounds-checked readers (`readPubkey`, `readU64`, `readU32`, `readU16`, `readU8`) and the corresponding writers / optional-encoders. Each read helper validates `offset + width <= data.length` and throws a descriptive `RangeError` rather than silently reading garbage when the offset is wrong.
91
+
92
+ ### Send-tx layer
93
+
94
+ `p-stv-core/send-tx.ts` exposes `sendSmartTx(connection, instructions, payer, signTransaction, options?)`:
95
+
96
+ 1. Pre-checks the legacy serialized size to decide if a versioned tx is needed (no double-sign).
97
+ 2. Fetches blockhash + every default LUT (lend / stv / jlpd) + Helius priority-fee in parallel.
98
+ 3. Simulates with an inflated CU limit, takes the actual `unitsConsumed`, applies a 5% buffer, and prepends the right `ComputeBudgetProgram` instructions.
99
+ 4. Falls back from legacy → versioned automatically when CU instructions push the size over `MAX_LEGACY_SIZE`.
100
+ 5. Confirms via `lastValidBlockHeight`.
101
+
102
+ The `signTransaction` callback is generic over `Transaction | VersionedTransaction` so wallets pass the same callback the SDK uses on either path. The optional `rpcUrl` field in `SmartTxOptions` is the only way the SDK reaches a Helius endpoint — it never reads private fields off the connection object.
103
+
104
+ ### Address Lookup Tables
105
+
106
+ `p-stv-core/send-tx.ts` exports `DEFAULT_LUT_ADDRESSES`:
107
+
108
+ ```ts
109
+ {
110
+ lend: PublicKey, // Elemental Lend infrastructure
111
+ stv: PublicKey, // p-STV Core vaults / evMints / vault ATAs
112
+ jlpd: PublicKey, // JLPD Strategy state / positions / oracles
113
+ }
114
+ ```
115
+
116
+ `sendSmartTx` always fetches all three. Consumers building transactions outside `sendSmartTx` should import these and merge them into their own LUT list. Server-side jobs (`jlpd-server/src/jobs/ltv-rebalance.ts`) use this same export — the SDK is the single source of truth.
117
+
118
+ ## Installation
119
+
120
+ ```bash
121
+ npm install @elemental-stv-core/sdk
122
+ # or
123
+ yarn add @elemental-stv-core/sdk
124
+ # or
125
+ pnpm add @elemental-stv-core/sdk
126
+ ```
127
+
128
+ Peer dependencies must be installed in the consumer:
129
+
130
+ ```bash
131
+ npm install @solana/web3.js@^1.95.0 @solana/spl-token@^0.4.0
132
+ ```
133
+
134
+ ## Quick examples
135
+
136
+ ### Deposit base into a vault from a frontend
137
+
138
+ ```ts
139
+ import {
140
+ findConfigPda,
141
+ findStvPda,
142
+ findEvMintPda,
143
+ createDepositIx,
144
+ buildDepositContext,
145
+ sendSmartTx,
146
+ } from "@elemental-stv-core/sdk/p-stv-core";
147
+
148
+ const [config] = findConfigPda();
149
+ const [stv] = findStvPda(vaultId);
150
+ const [evMint] = findEvMintPda(vaultId);
151
+
152
+ const ctx = await buildDepositContext(connection, vault);
153
+
154
+ const ix = createDepositIx({
155
+ user, config, stv, evMint, vaultAta, baseMint, userBaseAta, userEvAta,
156
+ baseAmount, autoRouteCount: ctx.autoRouteCount, ...
157
+ });
158
+
159
+ const sig = await sendSmartTx(
160
+ connection,
161
+ [...ctx.preInstructions, ix],
162
+ user,
163
+ signTransaction,
164
+ );
165
+ ```
166
+
167
+ ### Read a JLPD strategy state from a server job
168
+
169
+ ```ts
170
+ import { fetchJlpStrategyState } from "@elemental-stv-core/sdk/jlpd-strategy";
171
+
172
+ const state = await fetchJlpStrategyState(connection, baseMint);
173
+ console.log(`PPS: ${state.pps.toString()}`);
174
+ console.log(`base_loaned: ${state.baseLoaned.toString()}`);
175
+ ```
176
+
177
+ ### Build a manager-only `swap_jlp` rebalance from base → JLP
178
+
179
+ ```ts
180
+ import { buildSwapJlpTransaction } from "@elemental-stv-core/sdk/jlpd-strategy";
181
+
182
+ const result = await buildSwapJlpTransaction({
183
+ connection,
184
+ manager,
185
+ baseMint,
186
+ vaultId,
187
+ direction: "BaseToJlp",
188
+ amount: 1_000_000n,
189
+ slippageBps: 30,
190
+ });
191
+
192
+ const sig = await sendSmartTx(
193
+ connection,
194
+ [...result.preInstructions, ...result.instructions],
195
+ manager,
196
+ signTransaction,
197
+ { additionalLuts: result.addressLookupTables },
198
+ );
199
+ ```
200
+
201
+ ## Quality bar
202
+
203
+ This SDK is the artifact submitted for external audit. The following invariants are enforced:
204
+
205
+ - **`tsc` strict mode** with `noUnusedLocals` and `noUnusedParameters`. Zero suppressions in source.
206
+ - **No `any`** in source code. All wallet / connection seams use proper structural types.
207
+ - **No `@deprecated` exports.** Deprecated aliases were removed during the audit cleanup; if you find one, it's a bug.
208
+ - **Buffer reads are bounds-checked.** Every helper in `common/buffer.ts` throws on out-of-range offsets.
209
+ - **Discriminators are documented inline** with their derivation (`// sha256("global:deposit")[..8]`).
210
+ - **Each module follows the same file shape** so the audit pattern is the same per program.
211
+
212
+ ## Project structure
213
+
214
+ ```
215
+ sdk/
216
+ ├── README.md (this file)
217
+ ├── package.json
218
+ ├── tsconfig.json strict + noUnusedLocals + noUnusedParameters
219
+ ├── src/
220
+ │ ├── index.ts namespace re-exports
221
+ │ ├── common/
222
+ │ │ ├── index.ts
223
+ │ │ ├── constants.ts shared discriminators, PPS_DECIMALS, BPS, staleness
224
+ │ │ ├── connection.ts SolanaConnection structural type
225
+ │ │ ├── buffer.ts bounds-checked readers / writers
226
+ │ │ ├── ata.ts findAta()
227
+ │ │ └── strategy-interface.ts StrategyStateHeader + StvPosition + decoders
228
+ │ ├── p-stv-core/ vault management — Pinocchio program (13 instructions, 0x00–0x0C)
229
+ │ │ ├── constants.ts, pda.ts, types.ts, accounts.ts, instructions.ts, events.ts
230
+ │ │ ├── remaining-accounts.ts context builders for deposit/claim/epoch/strategy ops
231
+ │ │ ├── send-tx.ts smart tx: simulate CU → priority fee → LUT → sign → confirm
232
+ │ │ ├── sol-wrap.ts native SOL wrap/unwrap for SOL-denominated vaults
233
+ │ │ └── prices.ts Jupiter Quote API USD price fetcher
234
+ │ ├── elemental-lend/ idle-base lending — Anchor 0.32.1 program
235
+ │ │ ├── constants.ts, pda.ts, types.ts, accounts.ts, instructions.ts
236
+ │ │ ├── kamino-vault.ts Kamino kVault account derivation + CPI + staleness check
237
+ │ │ ├── jupiter-lend.ts Jupiter Lend pool configs + auto-route account builders
238
+ │ │ └── protocol-actions.ts high-level protocol action tx builders
239
+ │ └── jlpd-strategy/ JLP yield strategy — Anchor 0.32.1 program
240
+ │ ├── constants.ts, pda.ts, types.ts, accounts.ts, instructions.ts
241
+ │ ├── swap-jlp.ts Jupiter swap tx builders (BaseToJlp / JlpToBase)
242
+ │ ├── settle-yield.ts settle_yield instruction builder
243
+ │ ├── jlp-data.ts JLP pool data reader (custody weights, AUM, prices)
244
+ │ ├── jlp-borrow.ts Jupiter Lend Borrow constants + position reading
245
+ │ ├── jupusd-earn.ts Jupiter Lend Earn position + APR helpers
246
+ │ └── adapter.ts JLPD Lend Adapter instruction builders
247
+ ├── dist/ tsc output (published to npm; also committed for internal `file:` link consumers)
248
+ └── scripts/
249
+ └── create-luts.ts admin tool: create / extend address lookup tables
250
+ ```
@@ -0,0 +1,14 @@
1
+ import { PublicKey } from "@solana/web3.js";
2
+ /**
3
+ * Derive an Associated Token Account (ATA) address.
4
+ *
5
+ * Equivalent to `@solana/spl-token`'s `getAssociatedTokenAddressSync` but
6
+ * inlined to avoid pulling the runtime helpers into hot paths and to give a
7
+ * single source of truth across all SDK sub-packages (p-stv-core,
8
+ * elemental-lend, jlpd-strategy).
9
+ *
10
+ * @param mint - Token mint
11
+ * @param owner - Owner of the ATA (typically a PDA or wallet)
12
+ * @param tokenProgram - Token program ID (SPL Token or Token-2022)
13
+ */
14
+ export declare function findAta(mint: PublicKey, owner: PublicKey, tokenProgram: PublicKey): PublicKey;
@@ -0,0 +1,21 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.findAta = findAta;
4
+ const web3_js_1 = require("@solana/web3.js");
5
+ const spl_token_1 = require("@solana/spl-token");
6
+ /**
7
+ * Derive an Associated Token Account (ATA) address.
8
+ *
9
+ * Equivalent to `@solana/spl-token`'s `getAssociatedTokenAddressSync` but
10
+ * inlined to avoid pulling the runtime helpers into hot paths and to give a
11
+ * single source of truth across all SDK sub-packages (p-stv-core,
12
+ * elemental-lend, jlpd-strategy).
13
+ *
14
+ * @param mint - Token mint
15
+ * @param owner - Owner of the ATA (typically a PDA or wallet)
16
+ * @param tokenProgram - Token program ID (SPL Token or Token-2022)
17
+ */
18
+ function findAta(mint, owner, tokenProgram) {
19
+ const [ata] = web3_js_1.PublicKey.findProgramAddressSync([owner.toBuffer(), tokenProgram.toBuffer(), mint.toBuffer()], spl_token_1.ASSOCIATED_TOKEN_PROGRAM_ID);
20
+ return ata;
21
+ }
@@ -10,4 +10,3 @@ export declare function writeOptionalPubkey(parts: number[], value: PublicKey |
10
10
  export declare function writeOptionalU64(parts: number[], value: BN | number | undefined | null): void;
11
11
  export declare function writeOptionalU32(parts: number[], value: number | undefined | null): void;
12
12
  export declare function writeOptionalU16(parts: number[], value: number | undefined | null): void;
13
- //# sourceMappingURL=buffer.d.ts.map
@@ -17,20 +17,36 @@ const web3_js_1 = require("@solana/web3.js");
17
17
  const bn_js_1 = __importDefault(require("bn.js"));
18
18
  // ---------------------------------------------------------------------------
19
19
  // Read Helpers (account deserialization)
20
+ //
21
+ // Each helper validates that `offset + width <= data.length` and throws a
22
+ // descriptive error if the slice would run past the buffer end. Catching
23
+ // these at the call site (a malformed account, a layout drift, an incorrect
24
+ // offset constant) is much cheaper than chasing the resulting garbage data
25
+ // through downstream parsing.
20
26
  // ---------------------------------------------------------------------------
27
+ function checkBounds(data, offset, width, label) {
28
+ if (offset < 0 || offset + width > data.length) {
29
+ throw new RangeError(`${label}: cannot read ${width} bytes at offset ${offset} (buffer length=${data.length})`);
30
+ }
31
+ }
21
32
  function readPubkey(data, offset) {
33
+ checkBounds(data, offset, 32, "readPubkey");
22
34
  return new web3_js_1.PublicKey(data.subarray(offset, offset + 32));
23
35
  }
24
36
  function readU64(data, offset) {
37
+ checkBounds(data, offset, 8, "readU64");
25
38
  return new bn_js_1.default(data.subarray(offset, offset + 8), "le");
26
39
  }
27
40
  function readU32(data, offset) {
41
+ checkBounds(data, offset, 4, "readU32");
28
42
  return data.readUInt32LE(offset);
29
43
  }
30
44
  function readU16(data, offset) {
45
+ checkBounds(data, offset, 2, "readU16");
31
46
  return data.readUInt16LE(offset);
32
47
  }
33
48
  function readU8(data, offset) {
49
+ checkBounds(data, offset, 1, "readU8");
34
50
  return data[offset];
35
51
  }
36
52
  // ---------------------------------------------------------------------------
@@ -81,4 +97,3 @@ function writeOptionalU16(parts, value) {
81
97
  parts.push(0x00);
82
98
  }
83
99
  }
84
- //# sourceMappingURL=buffer.js.map
@@ -0,0 +1,13 @@
1
+ import { Connection } from "@solana/web3.js";
2
+ /**
3
+ * Canonical structural connection type used by every Elemental SDK module
4
+ * that needs to read on-chain state.
5
+ *
6
+ * Using a `Pick<Connection, ...>` here lets callers pass any version of
7
+ * `@solana/web3.js` without nominal type mismatches across module versions.
8
+ *
9
+ * If a builder needs only a subset of these methods, prefer aliasing further
10
+ * (`type ProtocolActionConnection = Pick<SolanaConnection, "getAccountInfo" | "getMultipleAccountsInfo">`)
11
+ * rather than defining a competing top-level type.
12
+ */
13
+ export type SolanaConnection = Pick<Connection, "getAccountInfo" | "getMultipleAccountsInfo" | "getProgramAccounts" | "getTokenAccountsByOwner" | "getSlot" | "getBlockTime">;
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -6,4 +6,9 @@ export declare const BPS_DENOMINATOR = 10000;
6
6
  export declare const SECONDS_PER_YEAR = 31536000;
7
7
  /** Default staleness threshold in seconds */
8
8
  export declare const STALENESS_THRESHOLD = 120;
9
- //# sourceMappingURL=constants.d.ts.map
9
+ /** sha256("account:StrategyState")[..8] — used by elemental-lend, jlpd-strategy */
10
+ export declare const DISC_STRATEGY_STATE: Buffer<ArrayBuffer>;
11
+ /** sha256("account:StvPosition")[..8] — used by elemental-lend, jlpd-strategy */
12
+ export declare const DISC_STV_POSITION: Buffer<ArrayBuffer>;
13
+ /** sha256("account:ManagerRole")[..8] — used by p-stv-core, elemental-lend, jlpd-strategy */
14
+ export declare const DISC_MANAGER_ROLE: Buffer<ArrayBuffer>;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.STALENESS_THRESHOLD = exports.SECONDS_PER_YEAR = exports.BPS_DENOMINATOR = exports.PPS_DECIMALS = void 0;
3
+ exports.DISC_MANAGER_ROLE = exports.DISC_STV_POSITION = exports.DISC_STRATEGY_STATE = exports.STALENESS_THRESHOLD = exports.SECONDS_PER_YEAR = exports.BPS_DENOMINATOR = exports.PPS_DECIMALS = void 0;
4
4
  /** Price per share scale factor (10^9) */
5
5
  exports.PPS_DECIMALS = 1000000000;
6
6
  /** Basis points denominator */
@@ -9,4 +9,23 @@ exports.BPS_DENOMINATOR = 10000;
9
9
  exports.SECONDS_PER_YEAR = 31536000;
10
10
  /** Default staleness threshold in seconds */
11
11
  exports.STALENESS_THRESHOLD = 120;
12
- //# sourceMappingURL=constants.js.map
12
+ // ---------------------------------------------------------------------------
13
+ // Shared Anchor account discriminators
14
+ //
15
+ // All three Elemental programs use Anchor's `sha256("account:<Type>")[..8]`
16
+ // discriminator format. The following types share the same on-chain layout
17
+ // across programs and therefore the same discriminator bytes — defining them
18
+ // once in `common` keeps them in lock-step.
19
+ // ---------------------------------------------------------------------------
20
+ /** sha256("account:StrategyState")[..8] — used by elemental-lend, jlpd-strategy */
21
+ exports.DISC_STRATEGY_STATE = Buffer.from([
22
+ 0x53, 0x12, 0xe0, 0x6d, 0xae, 0x64, 0x27, 0x8b,
23
+ ]);
24
+ /** sha256("account:StvPosition")[..8] — used by elemental-lend, jlpd-strategy */
25
+ exports.DISC_STV_POSITION = Buffer.from([
26
+ 0x2f, 0xd4, 0xfb, 0xb0, 0x8a, 0xa0, 0x1e, 0x57,
27
+ ]);
28
+ /** sha256("account:ManagerRole")[..8] — used by p-stv-core, elemental-lend, jlpd-strategy */
29
+ exports.DISC_MANAGER_ROLE = Buffer.from([
30
+ 0x25, 0xe8, 0x64, 0xe9, 0xaa, 0xe9, 0xdb, 0xb9,
31
+ ]);
@@ -1,5 +1,6 @@
1
1
  export { readPubkey, readU64, readU32, readU16, readU8, writeU64, writeOptionalPubkey, writeOptionalU64, writeOptionalU32, writeOptionalU16, } from "./buffer";
2
- export { PPS_DECIMALS, BPS_DENOMINATOR, SECONDS_PER_YEAR, STALENESS_THRESHOLD, } from "./constants";
2
+ export { PPS_DECIMALS, BPS_DENOMINATOR, SECONDS_PER_YEAR, STALENESS_THRESHOLD, DISC_STRATEGY_STATE, DISC_STV_POSITION, DISC_MANAGER_ROLE, } from "./constants";
3
+ export type { SolanaConnection } from "./connection";
3
4
  export type { StrategyStateHeader, StvPosition, } from "./strategy-interface";
4
5
  export { deserializeStrategyStateHeader, deserializeStvPosition, } from "./strategy-interface";
5
- //# sourceMappingURL=index.d.ts.map
6
+ export { findAta } from "./ata";
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.deserializeStvPosition = exports.deserializeStrategyStateHeader = exports.STALENESS_THRESHOLD = exports.SECONDS_PER_YEAR = exports.BPS_DENOMINATOR = exports.PPS_DECIMALS = exports.writeOptionalU16 = exports.writeOptionalU32 = exports.writeOptionalU64 = exports.writeOptionalPubkey = exports.writeU64 = exports.readU8 = exports.readU16 = exports.readU32 = exports.readU64 = exports.readPubkey = void 0;
3
+ exports.findAta = exports.deserializeStvPosition = exports.deserializeStrategyStateHeader = exports.DISC_MANAGER_ROLE = exports.DISC_STV_POSITION = exports.DISC_STRATEGY_STATE = exports.STALENESS_THRESHOLD = exports.SECONDS_PER_YEAR = exports.BPS_DENOMINATOR = exports.PPS_DECIMALS = exports.writeOptionalU16 = exports.writeOptionalU32 = exports.writeOptionalU64 = exports.writeOptionalPubkey = exports.writeU64 = exports.readU8 = exports.readU16 = exports.readU32 = exports.readU64 = exports.readPubkey = void 0;
4
4
  var buffer_1 = require("./buffer");
5
5
  Object.defineProperty(exports, "readPubkey", { enumerable: true, get: function () { return buffer_1.readPubkey; } });
6
6
  Object.defineProperty(exports, "readU64", { enumerable: true, get: function () { return buffer_1.readU64; } });
@@ -17,7 +17,11 @@ Object.defineProperty(exports, "PPS_DECIMALS", { enumerable: true, get: function
17
17
  Object.defineProperty(exports, "BPS_DENOMINATOR", { enumerable: true, get: function () { return constants_1.BPS_DENOMINATOR; } });
18
18
  Object.defineProperty(exports, "SECONDS_PER_YEAR", { enumerable: true, get: function () { return constants_1.SECONDS_PER_YEAR; } });
19
19
  Object.defineProperty(exports, "STALENESS_THRESHOLD", { enumerable: true, get: function () { return constants_1.STALENESS_THRESHOLD; } });
20
+ Object.defineProperty(exports, "DISC_STRATEGY_STATE", { enumerable: true, get: function () { return constants_1.DISC_STRATEGY_STATE; } });
21
+ Object.defineProperty(exports, "DISC_STV_POSITION", { enumerable: true, get: function () { return constants_1.DISC_STV_POSITION; } });
22
+ Object.defineProperty(exports, "DISC_MANAGER_ROLE", { enumerable: true, get: function () { return constants_1.DISC_MANAGER_ROLE; } });
20
23
  var strategy_interface_1 = require("./strategy-interface");
21
24
  Object.defineProperty(exports, "deserializeStrategyStateHeader", { enumerable: true, get: function () { return strategy_interface_1.deserializeStrategyStateHeader; } });
22
25
  Object.defineProperty(exports, "deserializeStvPosition", { enumerable: true, get: function () { return strategy_interface_1.deserializeStvPosition; } });
23
- //# sourceMappingURL=index.js.map
26
+ var ata_1 = require("./ata");
27
+ Object.defineProperty(exports, "findAta", { enumerable: true, get: function () { return ata_1.findAta; } });