@kasufinance/kasu-sdk 2.13.1 → 2.15.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 (56) hide show
  1. package/README.md +68 -5
  2. package/dist/bundle.cjs.js +1038 -29
  3. package/dist/bundle.esm.js +1026 -30
  4. package/dist/domain/index.d.ts +8 -3
  5. package/dist/domain/index.js +6 -2
  6. package/dist/domain/index.js.map +1 -1
  7. package/dist/domain/loan-contract.d.ts +16 -5
  8. package/dist/domain/loan-contract.js +16 -5
  9. package/dist/domain/loan-contract.js.map +1 -1
  10. package/dist/domain/pool-tvl.d.ts +104 -0
  11. package/dist/domain/pool-tvl.js +179 -0
  12. package/dist/domain/pool-tvl.js.map +1 -1
  13. package/dist/domain/requests.js +29 -19
  14. package/dist/domain/requests.js.map +1 -1
  15. package/dist/domain/strategy-details.d.ts +262 -0
  16. package/dist/domain/strategy-details.js +375 -0
  17. package/dist/domain/strategy-details.js.map +1 -0
  18. package/dist/facade/index.d.ts +3 -1
  19. package/dist/facade/index.js +2 -0
  20. package/dist/facade/index.js.map +1 -1
  21. package/dist/facade/strategies.d.ts +102 -4
  22. package/dist/facade/strategies.js +182 -6
  23. package/dist/facade/strategies.js.map +1 -1
  24. package/dist/facade/strategy-deployments.d.ts +65 -0
  25. package/dist/facade/strategy-deployments.js +97 -0
  26. package/dist/facade/strategy-deployments.js.map +1 -0
  27. package/dist/facade/types.d.ts +82 -0
  28. package/dist/flows/deposit-flow.d.ts +19 -5
  29. package/dist/flows/deposit-flow.js.map +1 -1
  30. package/dist/index.d.ts +1 -1
  31. package/dist/index.js.map +1 -1
  32. package/dist/services/DataService/data-service.d.ts +29 -1
  33. package/dist/services/DataService/data-service.js +80 -9
  34. package/dist/services/DataService/data-service.js.map +1 -1
  35. package/dist/services/DataService/tvl-history.d.ts +49 -0
  36. package/dist/services/DataService/tvl-history.js +89 -0
  37. package/dist/services/DataService/tvl-history.js.map +1 -1
  38. package/dist/services/UserLending/queries.js +2 -7
  39. package/dist/services/UserLending/queries.js.map +1 -1
  40. package/dist/services/UserLending/subgraph-types.js.map +1 -1
  41. package/dist/services/UserLending/types.js.map +1 -1
  42. package/dist/services/UserLending/user-lending.js +72 -16
  43. package/dist/services/UserLending/user-lending.js.map +1 -1
  44. package/package.json +1 -1
  45. package/src/domain/index.ts +34 -3
  46. package/src/domain/loan-contract.ts +16 -5
  47. package/src/domain/pool-tvl.ts +281 -0
  48. package/src/domain/strategy-details.ts +528 -0
  49. package/src/facade/index.ts +13 -0
  50. package/src/facade/strategies.ts +231 -11
  51. package/src/facade/strategy-deployments.ts +161 -0
  52. package/src/facade/types.ts +85 -0
  53. package/src/flows/deposit-flow.ts +19 -5
  54. package/src/index.ts +4 -1
  55. package/src/services/DataService/data-service.ts +103 -7
  56. package/src/services/DataService/tvl-history.ts +131 -0
package/README.md CHANGED
@@ -116,7 +116,7 @@ You can also pass a whole `ChainConfigEntry` instead of a chain key.
116
116
 
117
117
  | Facade | Methods | Purpose |
118
118
  | ----------------- | ----------------------------------------------------------------------------------------------------------------------- | ------------------------------- |
119
- | `kasu.strategies` | `getAll()`, `getVisible()`, `getById()`, `getPlatformStats()`, `getPerformanceFeePercent()`, `calculateDepositLimits()`, `getRiskPerformance(poolId)`, `getOriginator(poolId)`, `getPoolTvlHistory(poolId)` | Browse pools, APY, capacity, risk, originator, TVL history |
119
+ | `kasu.strategies` | `getAll()`, `getVisible()`, `getById()`, `getPlatformStats()`, `getPerformanceFeePercent()`, `calculateDepositLimits()`, `getRiskPerformance(poolId)`, `getOriginator(poolId)`, `getOriginatorHistory(poolId)`, `getRiskManagementGroups(poolId)`, `getPoolTvlHistory(poolId)`, `getPoolTvlHistoryWindow(poolId)` | Browse pools, APY, capacity, risk, originator, TVL history |
120
120
  | `kasu.deposits` | `deposit()`, `withdraw()`, `withdrawMax()`, `buildKycParams()`, `isClearingPending()` | Submit transactions |
121
121
  | `kasu.portfolio` | `getPositions()`, `getYieldHistory()`, `getTransactionHistory()`, `getRequestStates()` | Lender balances, yield, per-cycle earnings (net, in the chain's own stable token), history |
122
122
  | `kasu.flows` | `deposit(ports)`, `withdraw(ports?)` | Headless transaction pipelines |
@@ -167,6 +167,44 @@ instance, so a second call reads only what is new. `timeoutMs` (default
167
167
  30 s) and `signal` bound the call and reject with
168
168
  `PoolTvlHistoryTimeoutError` / `PoolTvlHistoryAbortedError`.
169
169
 
170
+ A strategy can run on more than one deployment (Tax Pay lends on Base and on
171
+ XDC AUDD), and its total lent is the sum of its pools. `strategyDeployments`
172
+ names the pools and `combineTvlHistories` adds their histories in USD at the
173
+ rates you pass. The SDK fetches no exchange rate:
174
+
175
+ ```ts
176
+ import { CHAIN_CONFIGS, combineTvlHistories, strategyDeployments } from '@kasufinance/kasu-sdk';
177
+
178
+ // Your rates, keyed by ISO-4217 code — never a guess. No rate, no total.
179
+ const usdPer: Record<string, number> = { USD: 1, AUD: audToUsd };
180
+
181
+ const legs = strategyDeployments(strategy.id, 'base');
182
+ // [{ chain: 'base', poolId: '0x…' }, { chain: 'xdc', poolId: '0x…' }]
183
+
184
+ const histories = await Promise.all(
185
+ legs.map(async ({ chain, poolId }) => ({
186
+ // { entries, opening } — `opening`: what the pool held just before the window
187
+ ...(await sdks[chain].strategies.getPoolTvlHistoryWindow(poolId, { count: 52 })),
188
+ usdRate: usdPer[CHAIN_CONFIGS[chain].stableAsset.currencyCode],
189
+ })),
190
+ );
191
+ const points = combineTvlHistories(histories); // { timestamp, tvlUsd, kind }[]
192
+ ```
193
+
194
+ `strategyDeployments(poolId, chain)` takes the deployment the id was read on
195
+ (required: an address alone does not name its chain) and returns the same set
196
+ from either side of the mapping; an unmapped id is a strategy of one on its
197
+ own chain, and an id the mapping places on another deployment throws
198
+ `StrategyDeploymentInputError`. `combineTvlHistories` is a step merge by time:
199
+ at every clearing on any leg, each leg's latest point, times its rate, summed;
200
+ a leg's `opening` (the clearing just before its window, read like every
201
+ other point) is one more step, from its own time until the first entry, and
202
+ a pool that started inside the window has none and counts 0 until then, so
203
+ windows cut at different times on each chain draw no false step. It ends with one `current` point, the sum of
204
+ the legs' current values. A missing rate, an empty leg or a bad entry throws
205
+ `TvlHistoryInputError`, so the series never holds `NaN` and never passes off
206
+ one chain's figure as the total.
207
+
170
208
  ## Domain helpers
171
209
 
172
210
  Pure functions shared by every Kasu frontend. They return **numbers and codes,
@@ -185,14 +223,16 @@ application formats them in its own design system and language.
185
223
  | Batch proof | `validateDepositBatchCalls`, `proveDepositInReceipt`, `DepositBatchMismatchError`, `ENTRY_POINT_V07` |
186
224
  | Tranche display name | `getTrancheDisplayName`, `UPPER_MEZZANINE` |
187
225
  | Strategy summary | `pickShortDescription` — the CMS short blurb as one line of plain text, or `undefined` (also on every `Strategy` as `summary`) |
226
+ | Strategy details | `readCmsStartDate`, `splitBusinessTypes`, `parseFacility`, `splitNumberedClauses`, `groupRiskManagementItems`, `RISK_GROUP_ORDER`, `securityStructureOf`, `strategyTotalsUsd`, `StrategyTotalsInputError` — the Details-screen fields as kasu-ui reads them (also on `Strategy` and the two strategy getters above) |
188
227
  | Requests | `deriveRequestState`, `submissionEvents`, `countSubmissions`, `firstSubmissionTimestamp`, `isCycleClosed` |
189
228
  | Settlement | `computeSettlementWindow`, `nextCycleBoundary`, `deriveCycleDates`, `CLEARING_WINDOW_SECONDS` |
190
- | Loan contract | `encodeDepositData`, `buildContractVersionType`, `buildLoanAgreementSignMessage`, `buildLegacyContractRequestMessage`, `buildFullNameRequestMessage`, `formatSignTimestampUtc`, `parseFormattedMessage`, `asContractType` |
229
+ | Loan contract | `encodeDepositData`, `buildContractVersionType`, `buildLoanAgreementSignMessage`, `buildLegacyContractRequestMessage` (deprecated), `buildFullNameRequestMessage`, `formatSignTimestampUtc`, `parseFormattedMessage`, `asContractType` |
191
230
  | Wallet errors | `isUserRejected`, `isUnpredictableGas`, `classifyWalletFailure` |
231
+ | Pool TVL | `poolTvl`, `combineTvlHistories`, `TvlHistoryInputError` — one strategy's history summed across deployments, in USD at the caller's rates |
192
232
  | Revert errors | `decodeRevert`, `extractRevertData` — the bytes a reverted call came back with, read as the custom error the contract named |
193
233
  | AU minimum | `auMinimumRemaining`, `isAustralianKyc`, `auThresholdFor`, `isAuMinimumExempt`, `parseMinorUnits`, `AU_ALPHA3`, `AU_MIN_CUMULATIVE_BY_STABLE` |
194
234
 
195
- Three rules worth knowing:
235
+ Rules worth knowing:
196
236
 
197
237
  - **Protocol strings are the exception to "never copy".** The messages
198
238
  `loan-contract` builds are reconstructed byte-for-byte by the Kasu backend to
@@ -213,6 +253,29 @@ Three rules worth knowing:
213
253
  `liteDescription` and `description` stay the raw CMS values. It is NOT
214
254
  sanitised: HTML tags and link syntax pass through unchanged, so render it
215
255
  as text, never as HTML or markdown.
256
+ - **The Details-screen fields omit, never stub.** `Strategy.strategyHistory`,
257
+ `Strategy.endBorrowers`, `Strategy.securityStructure`,
258
+ `getOriginatorHistory` and `getRiskManagementGroups` carry only what the CMS
259
+ actually authors: an empty, blank or malformed value is an absent key (or
260
+ `null` for a whole section), never a `0`, a dash or a sentence of the
261
+ SDK's own. A start date is `YYYY-MM-DD` and must be a real date from 2000
262
+ up to today. The originator's money figures are editorial USD on every
263
+ deployment — never FX-convert them. A risk item's `description` is present
264
+ exactly when its `clauses` are non-empty.
265
+ - **A failed CMS read rejects; it is not "no data".** `getOriginatorHistory`
266
+ and `getRiskManagementGroups` reject on a CMS outage (or no
267
+ `directusUrl`). For what to SHOW, treat a rejected `getRiskManagementGroups`
268
+ like `null`: fall back to `Strategy.securityStructure`. The pool getters
269
+ share their CMS reads per instance for 30 seconds (`getRiskPerformance` with
270
+ `getRiskManagementGroups`, `getOriginator` with `getOriginatorHistory`), so
271
+ a Details screen reads each collection once; a failed read is never reused.
272
+ - **`strategyTotalsUsd(legs, expectedDeployments)` states its coverage.** It
273
+ sums a strategy's Total Active Lending and Lender Interest Earned in USD
274
+ over the legs the caller loaded, each at its own rate. It is `null`
275
+ (withheld) when there are no legs or any loaded leg lacks a usable rate;
276
+ otherwise `isPartial` / `missingDeployments` name every expected deployment
277
+ the sum does not cover. Only `isPartial: false` is the whole strategy. A
278
+ duplicated or unexpected leg throws `StrategyTotalsInputError`.
216
279
  - **The tranche rename is display-only.** `getTrancheDisplayName` maps the
217
280
  `Senior` tranche to "Upper Mezzanine" on Apxium strategies, because the true
218
281
  senior position is held by an institutional lender. Call it at the view
@@ -623,8 +686,8 @@ tag workflow only verifies that a pushed `vX.Y.Z` tag matches `package.json`.
623
686
  ## Support
624
687
 
625
688
  - Issues: <https://github.com/Kasu-Finance/kasu-sdk/issues>
626
- - Developer documentation: <https://devdocs.kasu.finance>
627
- - Product documentation: <https://docs.kasu.finance>
689
+ - Developer documentation: <https://kasu.finance/docs/developers>
690
+ - Product documentation: <https://kasu.finance/docs/user>
628
691
 
629
692
  ## License
630
693