@exponent-labs/exponent-sdk 0.9.0 → 0.9.1

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 (153) hide show
  1. package/build/client/vaults/index.d.ts +2 -0
  2. package/build/client/vaults/index.js +2 -0
  3. package/build/client/vaults/index.js.map +1 -1
  4. package/build/client/vaults/types/index.d.ts +2 -0
  5. package/build/client/vaults/types/index.js +2 -0
  6. package/build/client/vaults/types/index.js.map +1 -1
  7. package/build/client/vaults/types/kaminoFarmEntry.d.ts +15 -0
  8. package/build/client/vaults/types/kaminoFarmEntry.js +17 -0
  9. package/build/client/vaults/types/kaminoFarmEntry.js.map +1 -0
  10. package/build/client/vaults/types/kaminoObligationEntry.d.ts +24 -7
  11. package/build/client/vaults/types/kaminoObligationEntry.js +2 -1
  12. package/build/client/vaults/types/kaminoObligationEntry.js.map +1 -1
  13. package/build/client/vaults/types/obligationType.d.ts +1 -1
  14. package/build/client/vaults/types/positionUpdate.d.ts +9 -0
  15. package/build/client/vaults/types/positionUpdate.js +23 -0
  16. package/build/client/vaults/types/positionUpdate.js.map +1 -1
  17. package/build/client/vaults/types/proposalAction.d.ts +54 -54
  18. package/build/client/vaults/types/proposalAction.js +0 -3
  19. package/build/client/vaults/types/proposalAction.js.map +1 -1
  20. package/build/client/vaults/types/reserveFarmMapping.d.ts +19 -0
  21. package/build/client/vaults/types/reserveFarmMapping.js +18 -0
  22. package/build/client/vaults/types/reserveFarmMapping.js.map +1 -0
  23. package/build/client/vaults/types/strategyPosition.d.ts +6 -1
  24. package/build/client/vaults/types/strategyPosition.js +5 -0
  25. package/build/client/vaults/types/strategyPosition.js.map +1 -1
  26. package/build/exponentVaults/aumCalculator.d.ts +25 -4
  27. package/build/exponentVaults/aumCalculator.js +236 -15
  28. package/build/exponentVaults/aumCalculator.js.map +1 -1
  29. package/build/exponentVaults/fetcher.d.ts +52 -0
  30. package/build/exponentVaults/fetcher.js +199 -0
  31. package/build/exponentVaults/fetcher.js.map +1 -0
  32. package/build/exponentVaults/index.d.ts +10 -9
  33. package/build/exponentVaults/index.js +25 -8
  34. package/build/exponentVaults/index.js.map +1 -1
  35. package/build/exponentVaults/kamino-farms.d.ts +144 -0
  36. package/build/exponentVaults/kamino-farms.js +396 -0
  37. package/build/exponentVaults/kamino-farms.js.map +1 -0
  38. package/build/exponentVaults/loopscale/client.d.ts +240 -0
  39. package/build/exponentVaults/loopscale/client.js +590 -0
  40. package/build/exponentVaults/loopscale/client.js.map +1 -0
  41. package/build/exponentVaults/loopscale/client.test.d.ts +1 -0
  42. package/build/exponentVaults/loopscale/client.test.js +183 -0
  43. package/build/exponentVaults/loopscale/client.test.js.map +1 -0
  44. package/build/exponentVaults/loopscale/helpers.d.ts +29 -0
  45. package/build/exponentVaults/loopscale/helpers.js +119 -0
  46. package/build/exponentVaults/loopscale/helpers.js.map +1 -0
  47. package/build/exponentVaults/loopscale/index.d.ts +3 -0
  48. package/build/exponentVaults/loopscale/index.js +12 -0
  49. package/build/exponentVaults/loopscale/index.js.map +1 -0
  50. package/build/exponentVaults/loopscale/prepared-transactions.d.ts +13 -0
  51. package/build/exponentVaults/loopscale/prepared-transactions.js +271 -0
  52. package/build/exponentVaults/loopscale/prepared-transactions.js.map +1 -0
  53. package/build/exponentVaults/loopscale/prepared-transactions.test.d.ts +1 -0
  54. package/build/exponentVaults/loopscale/prepared-transactions.test.js +400 -0
  55. package/build/exponentVaults/loopscale/prepared-transactions.test.js.map +1 -0
  56. package/build/exponentVaults/loopscale/prepared-types.d.ts +62 -0
  57. package/build/exponentVaults/loopscale/prepared-types.js +3 -0
  58. package/build/exponentVaults/loopscale/prepared-types.js.map +1 -0
  59. package/build/exponentVaults/loopscale/response-plan.d.ts +69 -0
  60. package/build/exponentVaults/loopscale/response-plan.js +141 -0
  61. package/build/exponentVaults/loopscale/response-plan.js.map +1 -0
  62. package/build/exponentVaults/loopscale/response-plan.test.d.ts +1 -0
  63. package/build/exponentVaults/loopscale/response-plan.test.js +139 -0
  64. package/build/exponentVaults/loopscale/response-plan.test.js.map +1 -0
  65. package/build/exponentVaults/loopscale/send-plan.d.ts +75 -0
  66. package/build/exponentVaults/loopscale/send-plan.js +235 -0
  67. package/build/exponentVaults/loopscale/send-plan.js.map +1 -0
  68. package/build/exponentVaults/loopscale/types.d.ts +443 -0
  69. package/build/exponentVaults/loopscale/types.js +3 -0
  70. package/build/exponentVaults/loopscale/types.js.map +1 -0
  71. package/build/exponentVaults/loopscale-client.d.ts +113 -524
  72. package/build/exponentVaults/loopscale-client.js +296 -539
  73. package/build/exponentVaults/loopscale-client.js.map +1 -1
  74. package/build/exponentVaults/loopscale-client.test.d.ts +1 -0
  75. package/build/exponentVaults/loopscale-client.test.js +162 -0
  76. package/build/exponentVaults/loopscale-client.test.js.map +1 -0
  77. package/build/exponentVaults/loopscale-client.types.d.ts +425 -0
  78. package/build/exponentVaults/loopscale-client.types.js +3 -0
  79. package/build/exponentVaults/loopscale-client.types.js.map +1 -0
  80. package/build/exponentVaults/loopscale-execution.d.ts +125 -0
  81. package/build/exponentVaults/loopscale-execution.js +341 -0
  82. package/build/exponentVaults/loopscale-execution.js.map +1 -0
  83. package/build/exponentVaults/loopscale-execution.test.d.ts +1 -0
  84. package/build/exponentVaults/loopscale-execution.test.js +139 -0
  85. package/build/exponentVaults/loopscale-execution.test.js.map +1 -0
  86. package/build/exponentVaults/loopscale-vault.d.ts +115 -0
  87. package/build/exponentVaults/loopscale-vault.js +275 -0
  88. package/build/exponentVaults/loopscale-vault.js.map +1 -0
  89. package/build/exponentVaults/loopscale-vault.test.d.ts +1 -0
  90. package/build/exponentVaults/loopscale-vault.test.js +102 -0
  91. package/build/exponentVaults/loopscale-vault.test.js.map +1 -0
  92. package/build/exponentVaults/policyBuilders.d.ts +62 -0
  93. package/build/exponentVaults/policyBuilders.js +119 -2
  94. package/build/exponentVaults/policyBuilders.js.map +1 -1
  95. package/build/exponentVaults/pricePathResolver.d.ts +45 -0
  96. package/build/exponentVaults/pricePathResolver.js +198 -0
  97. package/build/exponentVaults/pricePathResolver.js.map +1 -0
  98. package/build/exponentVaults/pricePathResolver.test.d.ts +1 -0
  99. package/build/exponentVaults/pricePathResolver.test.js +369 -0
  100. package/build/exponentVaults/pricePathResolver.test.js.map +1 -0
  101. package/build/exponentVaults/syncTransaction.js +4 -1
  102. package/build/exponentVaults/syncTransaction.js.map +1 -1
  103. package/build/exponentVaults/titan-quote.js +170 -36
  104. package/build/exponentVaults/titan-quote.js.map +1 -1
  105. package/build/exponentVaults/vault-instruction-types.d.ts +363 -0
  106. package/build/exponentVaults/vault-instruction-types.js +128 -0
  107. package/build/exponentVaults/vault-instruction-types.js.map +1 -0
  108. package/build/exponentVaults/vault-interaction.d.ts +156 -313
  109. package/build/exponentVaults/vault-interaction.js +1581 -353
  110. package/build/exponentVaults/vault-interaction.js.map +1 -1
  111. package/build/exponentVaults/vault.d.ts +51 -2
  112. package/build/exponentVaults/vault.js +324 -48
  113. package/build/exponentVaults/vault.js.map +1 -1
  114. package/build/exponentVaults/vaultTransactionBuilder.d.ts +100 -134
  115. package/build/exponentVaults/vaultTransactionBuilder.js +359 -266
  116. package/build/exponentVaults/vaultTransactionBuilder.js.map +1 -1
  117. package/build/exponentVaults/vaultTransactionBuilder.test.d.ts +1 -0
  118. package/build/exponentVaults/vaultTransactionBuilder.test.js +214 -0
  119. package/build/exponentVaults/vaultTransactionBuilder.test.js.map +1 -0
  120. package/build/marketThree.d.ts +6 -2
  121. package/build/marketThree.js +10 -8
  122. package/build/marketThree.js.map +1 -1
  123. package/package.json +32 -32
  124. package/src/client/vaults/index.ts +2 -0
  125. package/src/client/vaults/types/index.ts +2 -0
  126. package/src/client/vaults/types/kaminoFarmEntry.ts +32 -0
  127. package/src/client/vaults/types/kaminoObligationEntry.ts +6 -3
  128. package/src/client/vaults/types/positionUpdate.ts +62 -0
  129. package/src/client/vaults/types/proposalAction.ts +0 -3
  130. package/src/client/vaults/types/reserveFarmMapping.ts +35 -0
  131. package/src/client/vaults/types/strategyPosition.ts +18 -1
  132. package/src/exponentVaults/aumCalculator.ts +353 -16
  133. package/src/exponentVaults/fetcher.ts +257 -0
  134. package/src/exponentVaults/index.ts +64 -40
  135. package/src/exponentVaults/kamino-farms.ts +538 -0
  136. package/src/exponentVaults/loopscale/client.ts +808 -0
  137. package/src/exponentVaults/loopscale/helpers.ts +172 -0
  138. package/src/exponentVaults/loopscale/index.ts +57 -0
  139. package/src/exponentVaults/loopscale/prepared-transactions.ts +435 -0
  140. package/src/exponentVaults/loopscale/prepared-types.ts +73 -0
  141. package/src/exponentVaults/loopscale/types.ts +466 -0
  142. package/src/exponentVaults/policyBuilders.ts +170 -0
  143. package/src/exponentVaults/pricePathResolver.test.ts +466 -0
  144. package/src/exponentVaults/pricePathResolver.ts +273 -0
  145. package/src/exponentVaults/syncTransaction.ts +6 -1
  146. package/src/exponentVaults/titan-quote.ts +231 -45
  147. package/src/exponentVaults/vault-instruction-types.ts +493 -0
  148. package/src/exponentVaults/vault-interaction.ts +2227 -636
  149. package/src/exponentVaults/vault.ts +474 -63
  150. package/src/exponentVaults/vaultTransactionBuilder.test.ts +256 -0
  151. package/src/exponentVaults/vaultTransactionBuilder.ts +555 -413
  152. package/src/marketThree.ts +14 -6
  153. package/src/exponentVaults/loopscale-client.ts +0 -1373
@@ -0,0 +1,240 @@
1
+ /**
2
+ * Loopscale manager flow:
3
+ *
4
+ * 1. Call a raw Loopscale endpoint such as `createStrategy(...)`,
5
+ * `createLoan(...)`, or `borrowPrincipal(...)`.
6
+ * 2. Hand the raw response back to this client.
7
+ * 3. Choose one of two paths:
8
+ * - `prepareVaultTransactions(...)` when you want appendable instruction
9
+ * pieces you can compose with your own transaction building logic.
10
+ * - `buildVaultTransactions(...)` when you want locally signed
11
+ * `VersionedTransaction`s that are ready for optional Loopscale
12
+ * co-signing and then `connection.sendTransaction(...)`.
13
+ * 4. Call `coSign(...)` only on returned transactions where
14
+ * `requiresLoopscaleCoSign === true`.
15
+ *
16
+ * This distinction is intentional:
17
+ *
18
+ * - Wrapped Loopscale sync transactions require Loopscale MPC because they
19
+ * represent Loopscale-authored flows that expect Loopscale's signature.
20
+ * - Setup transactions and other top-level non-Loopscale transactions must
21
+ * stay local. They are constructed by the SDK to make the manager flow
22
+ * complete, but they are not Loopscale-signed transactions and should not
23
+ * be sent to Loopscale's MPC endpoint.
24
+ *
25
+ * In other words, `requiresLoopscaleCoSign` is not a convenience flag. It is
26
+ * the contract that tells the caller which transactions belong to Loopscale's
27
+ * signing domain and which ones do not.
28
+ *
29
+ * Example:
30
+ *
31
+ * ```ts
32
+ * const client = new LoopscaleClient({
33
+ * connection,
34
+ * userWallet: squadsVault,
35
+ * payer: squadsVault,
36
+ * })
37
+ *
38
+ * const response = await client.createStrategy({
39
+ * principalMint,
40
+ * lender: squadsVault,
41
+ * amount: 0,
42
+ * })
43
+ *
44
+ * const builtTransactions = await client.buildVaultTransactions({
45
+ * response,
46
+ * context: {
47
+ * connection,
48
+ * signer: manager.publicKey,
49
+ * signers: [manager],
50
+ * vaultPda: squadsVault,
51
+ * vaultAddress,
52
+ * squadsProgram,
53
+ * },
54
+ * })
55
+ *
56
+ * for (const built of builtTransactions) {
57
+ * const transaction = built.requiresLoopscaleCoSign
58
+ * ? await client.coSign(built.transaction)
59
+ * : built.transaction
60
+ *
61
+ * await connection.sendTransaction(transaction, { skipPreflight: false })
62
+ * }
63
+ * ```
64
+ */
65
+ import { PublicKey, VersionedTransaction } from "@solana/web3.js";
66
+ import type { LoopscaleBorrowPrincipalParams, LoopscaleClientConfig, LoopscaleCloseLoanParams, LoopscaleCloseStrategyParams, LoopscaleCreateLoanParams, LoopscaleCreateLoanResponse, LoopscaleCreateStrategyParams, LoopscaleDepositCollateralParams, LoopscaleDepositStrategyParams, LoopscaleGetStrategiesParams, LoopscaleLoanInfoParams, LoopscaleLoanInfoResponse, LoopscaleLoanTransactionResponse, LoopscaleMaxQuote, LoopscaleMaxQuoteParams, LoopscaleQuote, LoopscaleQuoteParams, LoopscaleRepayLoanSimpleParams, LoopscaleStrategyInfoResponse, LoopscaleTransactionResponse, LoopscaleTransactionsResponse, LoopscaleUpdateStrategyParams, LoopscaleVersionedTransactionBatchResponse, LoopscaleVersionedTransactionResponse, LoopscaleWithdrawCollateralParams, LoopscaleWithdrawStrategyParams } from "./types";
67
+ import type { LoopscaleBuildTransactionsContext, LoopscaleBuiltTransaction, LoopscalePreparedTransaction, LoopscaleVaultPreparationContext } from "./prepared-types";
68
+ import { deserializeLoopscaleTransactionBatchResponse, deserializeLoopscaleTransactionResponse, extractCreatedStrategyAddress, extractCreatedStrategyNonce, getLoopscaleTransactionResponses, identifyLoopscaleInstruction } from "./helpers";
69
+ /**
70
+ * Thin docs-aligned Loopscale client for strategies, loans, and related query endpoints.
71
+ *
72
+ * Transaction methods intentionally return the raw Loopscale response shapes
73
+ * instead of derived sync-action bundles. Use
74
+ * {@link LoopscaleClient.prepareVaultTransactions} when you need appendable
75
+ * transaction pieces, or {@link LoopscaleClient.buildVaultTransactions} when
76
+ * you want locally signed transactions that are ready for optional
77
+ * `client.coSign(...)` and `connection.sendTransaction(...)`.
78
+ *
79
+ * Refinancing and other lock/unlock maintenance flows remain intentionally
80
+ * excluded. The client only covers strategies, loans, and cleanup endpoints
81
+ * that can be represented as raw transaction responses.
82
+ *
83
+ * Typical usage:
84
+ *
85
+ * - Query Loopscale data through the read methods on this client.
86
+ * - Build raw Loopscale transactions through the strategy and loan methods.
87
+ * - Turn raw responses into appendable instruction pieces with
88
+ * {@link LoopscaleClient.prepareVaultTransactions}.
89
+ * - Or compile ready-to-send transactions with
90
+ * {@link LoopscaleClient.buildVaultTransactions}.
91
+ * - Call {@link LoopscaleClient.coSign} only for transactions flagged with
92
+ * `requiresLoopscaleCoSign`.
93
+ */
94
+ export declare class LoopscaleClient {
95
+ private readonly connection;
96
+ private readonly baseUrl;
97
+ private readonly userWallet;
98
+ private readonly payer;
99
+ private readonly debug;
100
+ constructor(config: LoopscaleClientConfig);
101
+ /**
102
+ * Load Loopscale quotes for a principal/collateral pair.
103
+ */
104
+ getQuotes(params: LoopscaleQuoteParams): Promise<LoopscaleQuote[]>;
105
+ /**
106
+ * Load the best quote for one or more specific collateral assets.
107
+ */
108
+ getMaxQuote(params: LoopscaleMaxQuoteParams): Promise<LoopscaleMaxQuote[]>;
109
+ /**
110
+ * Load Loopscale loan positions.
111
+ */
112
+ getLoanInfo(params: LoopscaleLoanInfoParams): Promise<LoopscaleLoanInfoResponse>;
113
+ /**
114
+ * Load Loopscale lending strategies.
115
+ */
116
+ getStrategies(params: LoopscaleGetStrategiesParams): Promise<LoopscaleStrategyInfoResponse>;
117
+ /**
118
+ * Build a raw Loopscale `createStrategy` transaction batch.
119
+ */
120
+ createStrategy(params: LoopscaleCreateStrategyParams): Promise<LoopscaleVersionedTransactionBatchResponse>;
121
+ /**
122
+ * Build a raw Loopscale `depositStrategy` transaction.
123
+ */
124
+ depositStrategy(params: LoopscaleDepositStrategyParams): Promise<LoopscaleVersionedTransactionResponse>;
125
+ /**
126
+ * Build a raw Loopscale `withdrawStrategy` transaction.
127
+ */
128
+ withdrawStrategy(params: LoopscaleWithdrawStrategyParams): Promise<LoopscaleVersionedTransactionResponse>;
129
+ /**
130
+ * Build a raw Loopscale `closeStrategy` transaction.
131
+ */
132
+ closeStrategy(params: LoopscaleCloseStrategyParams): Promise<LoopscaleVersionedTransactionResponse>;
133
+ /**
134
+ * Build raw Loopscale `updateStrategy` transactions.
135
+ */
136
+ updateStrategy(params: LoopscaleUpdateStrategyParams): Promise<LoopscaleVersionedTransactionBatchResponse>;
137
+ /**
138
+ * Build a raw Loopscale `createLoan` transaction.
139
+ */
140
+ createLoan(params: LoopscaleCreateLoanParams): Promise<LoopscaleCreateLoanResponse>;
141
+ /**
142
+ * Build a raw Loopscale `borrowPrincipal` transaction.
143
+ *
144
+ * The published OpenAPI schema currently documents a single serialized
145
+ * transaction response, but live responses can also return a wrapped
146
+ * `transactions` array with `expectedLoanInfo` when Loopscale inserts
147
+ * additional internal maintenance steps.
148
+ */
149
+ borrowPrincipal(params: LoopscaleBorrowPrincipalParams): Promise<LoopscaleLoanTransactionResponse>;
150
+ /**
151
+ * Build a raw Loopscale `depositCollateral` transaction.
152
+ */
153
+ depositCollateral(params: LoopscaleDepositCollateralParams): Promise<LoopscaleVersionedTransactionResponse>;
154
+ /**
155
+ * Build a raw Loopscale `withdrawCollateral` transaction.
156
+ *
157
+ * Full collateral removal can trigger internal loan-maintenance instructions,
158
+ * so callers should accept either a single serialized transaction or a wrapped
159
+ * `transactions` array.
160
+ */
161
+ withdrawCollateral(params: LoopscaleWithdrawCollateralParams): Promise<LoopscaleLoanTransactionResponse>;
162
+ /**
163
+ * Build a raw Loopscale `repay_simple` transaction response.
164
+ */
165
+ repayLoanSimple(params: LoopscaleRepayLoanSimpleParams): Promise<LoopscaleTransactionsResponse>;
166
+ /**
167
+ * Build a raw Loopscale `close_loan` transaction response.
168
+ */
169
+ closeLoan(params: LoopscaleCloseLoanParams): Promise<LoopscaleLoanTransactionResponse>;
170
+ /**
171
+ * Convert a raw Loopscale response into manager-ready vault transaction pieces.
172
+ *
173
+ * This is the lower-level, appendable "lego" API.
174
+ *
175
+ * Each returned entry represents one manager-facing transaction:
176
+ * send `setupInstructions` first when present, then send the main
177
+ * `instructions`. Wrapped sync transactions are already flattened into one
178
+ * instruction list, so callers do not need to manually inspect the raw
179
+ * Loopscale response to figure out which instructions should be wrapped.
180
+ *
181
+ * Use this when you want to compose Loopscale output with your own custom
182
+ * transaction building logic.
183
+ */
184
+ prepareVaultTransactions({ response, context, }: {
185
+ response: LoopscaleTransactionResponse;
186
+ context: LoopscaleVaultPreparationContext;
187
+ }): Promise<LoopscalePreparedTransaction[]>;
188
+ /**
189
+ * Build locally signed transactions from a raw Loopscale response.
190
+ *
191
+ * This is the simplest manager-facing API.
192
+ *
193
+ * The returned transactions are ready for:
194
+ * 1. `await client.coSign(tx)` when `requiresLoopscaleCoSign === true`
195
+ * 2. `connection.sendTransaction(tx)`
196
+ *
197
+ * The co-signing flag is deliberately per-transaction, not global. A single
198
+ * Loopscale response can produce:
199
+ *
200
+ * - local setup transactions that must be sent as-is,
201
+ * - local top-level transactions that do not belong to Loopscale's signing
202
+ * domain,
203
+ * - one wrapped Loopscale sync transaction that does require Loopscale MPC.
204
+ *
205
+ * The client returns all of them in send order and marks only the wrapped
206
+ * Loopscale transaction for MPC co-signing. This is the correct boundary:
207
+ * callers should not guess which transactions need Loopscale's signature.
208
+ *
209
+ * The first signer in `context.signers` must match `context.signer`, since
210
+ * that signer is used as the fee payer for the compiled transactions.
211
+ */
212
+ buildVaultTransactions({ response, context, }: {
213
+ response: LoopscaleTransactionResponse;
214
+ context: LoopscaleBuildTransactionsContext;
215
+ }): Promise<LoopscaleBuiltTransaction[]>;
216
+ /**
217
+ * Co-sign a prepared transaction with Loopscale's back-end signer.
218
+ *
219
+ * This uses Loopscale's public MPC co-signing endpoint. The returned
220
+ * transaction is required to keep the exact same message as the locally
221
+ * signed input, and any local signatures that are missing from the response
222
+ * are copied back onto the returned transaction before it is handed to the
223
+ * caller.
224
+ *
225
+ * Only call this for transactions flagged with
226
+ * `requiresLoopscaleCoSign === true`. Transactions not flagged that way do
227
+ * not belong to Loopscale's signing domain and should be sent directly.
228
+ */
229
+ coSign(transaction: VersionedTransaction): Promise<VersionedTransaction>;
230
+ /**
231
+ * Extract the strategy PDA from a `createStrategy` response using the client's connection.
232
+ */
233
+ extractCreatedStrategyAddress(response: LoopscaleTransactionResponse): Promise<PublicKey>;
234
+ /**
235
+ * Extract the strategy nonce from a `createStrategy` response using the client's connection.
236
+ */
237
+ extractCreatedStrategyNonce(response: LoopscaleTransactionResponse): Promise<PublicKey>;
238
+ private post;
239
+ }
240
+ export { deserializeLoopscaleTransactionBatchResponse, deserializeLoopscaleTransactionResponse, extractCreatedStrategyAddress, extractCreatedStrategyNonce, getLoopscaleTransactionResponses, identifyLoopscaleInstruction, };