@kasufinance/kasu-sdk 2.14.0 → 2.16.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 (70) hide show
  1. package/README.md +45 -5
  2. package/dist/bundle.cjs.js +1484 -228
  3. package/dist/bundle.esm.js +1476 -229
  4. package/dist/domain/index.d.ts +6 -1
  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.js +179 -0
  11. package/dist/domain/pool-tvl.js.map +1 -1
  12. package/dist/domain/requests.js +29 -19
  13. package/dist/domain/requests.js.map +1 -1
  14. package/dist/domain/strategy-details.d.ts +262 -0
  15. package/dist/domain/strategy-details.js +375 -0
  16. package/dist/domain/strategy-details.js.map +1 -0
  17. package/dist/domain/yield-history.d.ts +25 -1
  18. package/dist/domain/yield-history.js +41 -11
  19. package/dist/domain/yield-history.js.map +1 -1
  20. package/dist/facade/index.d.ts +1 -1
  21. package/dist/facade/index.js +2 -0
  22. package/dist/facade/index.js.map +1 -1
  23. package/dist/facade/strategies.d.ts +85 -3
  24. package/dist/facade/strategies.js +182 -6
  25. package/dist/facade/strategies.js.map +1 -1
  26. package/dist/facade/strategy-deployments.js +97 -0
  27. package/dist/facade/strategy-deployments.js.map +1 -0
  28. package/dist/facade/types.d.ts +82 -0
  29. package/dist/flows/deposit-flow.d.ts +19 -5
  30. package/dist/flows/deposit-flow.js.map +1 -1
  31. package/dist/index.js.map +1 -1
  32. package/dist/services/DataService/data-service.js +80 -9
  33. package/dist/services/DataService/data-service.js.map +1 -1
  34. package/dist/services/DataService/tvl-history.js +89 -0
  35. package/dist/services/DataService/tvl-history.js.map +1 -1
  36. package/dist/services/Portfolio/portfolio.d.ts +54 -1
  37. package/dist/services/Portfolio/portfolio.js +357 -80
  38. package/dist/services/Portfolio/portfolio.js.map +1 -1
  39. package/dist/services/Portfolio/queries.d.ts +16 -0
  40. package/dist/services/Portfolio/queries.js +119 -2
  41. package/dist/services/Portfolio/queries.js.map +1 -1
  42. package/dist/services/Portfolio/types.d.ts +94 -6
  43. package/dist/services/Portfolio/yield-history.d.ts +148 -10
  44. package/dist/services/Portfolio/yield-history.js +241 -31
  45. package/dist/services/Portfolio/yield-history.js.map +1 -1
  46. package/dist/services/UserLending/queries.js +2 -7
  47. package/dist/services/UserLending/queries.js.map +1 -1
  48. package/dist/services/UserLending/subgraph-types.js.map +1 -1
  49. package/dist/services/UserLending/types.js.map +1 -1
  50. package/dist/services/UserLending/user-lending.d.ts +16 -0
  51. package/dist/services/UserLending/user-lending.js +96 -16
  52. package/dist/services/UserLending/user-lending.js.map +1 -1
  53. package/dist/services/shared.d.ts +7 -0
  54. package/dist/services/shared.js +48 -0
  55. package/dist/services/shared.js.map +1 -1
  56. package/package.json +1 -1
  57. package/src/domain/index.ts +27 -1
  58. package/src/domain/loan-contract.ts +16 -5
  59. package/src/domain/strategy-details.ts +528 -0
  60. package/src/domain/yield-history.ts +47 -11
  61. package/src/facade/index.ts +3 -0
  62. package/src/facade/strategies.ts +205 -10
  63. package/src/facade/types.ts +85 -0
  64. package/src/flows/deposit-flow.ts +19 -5
  65. package/src/services/Portfolio/portfolio.ts +559 -126
  66. package/src/services/Portfolio/queries.ts +119 -2
  67. package/src/services/Portfolio/types.ts +91 -6
  68. package/src/services/Portfolio/yield-history.ts +405 -56
  69. package/src/services/UserLending/user-lending.ts +46 -0
  70. package/src/services/shared.ts +48 -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)`, `getPoolTvlHistoryWindow(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 |
@@ -142,6 +142,22 @@ slightly more than lifetime interest (up to about 0.2 %, top-ups are valued at
142
142
  today's share price), so show "earned to date" from the lifetime figure, not
143
143
  from the sum of the bars.
144
144
 
145
+ Each cycle's interest is paired with the shares in force when that cycle's
146
+ clearing applied it — before the clearing accepted any request — so a
147
+ withdrawal the pool manager accepted between clearings is out of the next
148
+ cycle's figures, and the newest bar equals `getPositions`' last-epoch figure.
149
+
150
+ The subgraph counts a lender's shares as a ledger of accepted deposits and
151
+ withdrawals. Shares moved to or from a wallet any other way are not on it.
152
+ `getPositions` compares the ledger with the chain AT THE BLOCK THE SUBGRAPH
153
+ ANSWERED AT (so indexing lag is never a fault). Where they disagree it reads
154
+ the tranche balances from the chain, so a balance is never negative, and
155
+ sets `ledgerMismatch` on the pool. `ledger-exceeds-chain` (the wallet sent
156
+ shares away) withholds the pool's last-cycle figures and leaves the pool out
157
+ of `getYieldHistory`. An `investedAmount` raised to 0 carries
158
+ `investedAmountFloored`. Lifetime figures stay ledger figures, which include
159
+ the moved principal.
160
+
145
161
  `kasu.strategies.getPoolTvlHistory(poolId, { fromEpoch?, count?, timeoutMs?,
146
162
  signal? })` returns the strategy's TVL (total lent by everyone) as
147
163
  `{ epochId, timestamp, tvl, kind }[]`, ascending in time: one
@@ -223,15 +239,16 @@ application formats them in its own design system and language.
223
239
  | Batch proof | `validateDepositBatchCalls`, `proveDepositInReceipt`, `DepositBatchMismatchError`, `ENTRY_POINT_V07` |
224
240
  | Tranche display name | `getTrancheDisplayName`, `UPPER_MEZZANINE` |
225
241
  | Strategy summary | `pickShortDescription` — the CMS short blurb as one line of plain text, or `undefined` (also on every `Strategy` as `summary`) |
242
+ | 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) |
226
243
  | Requests | `deriveRequestState`, `submissionEvents`, `countSubmissions`, `firstSubmissionTimestamp`, `isCycleClosed` |
227
244
  | Settlement | `computeSettlementWindow`, `nextCycleBoundary`, `deriveCycleDates`, `CLEARING_WINDOW_SECONDS` |
228
- | Loan contract | `encodeDepositData`, `buildContractVersionType`, `buildLoanAgreementSignMessage`, `buildLegacyContractRequestMessage`, `buildFullNameRequestMessage`, `formatSignTimestampUtc`, `parseFormattedMessage`, `asContractType` |
245
+ | Loan contract | `encodeDepositData`, `buildContractVersionType`, `buildLoanAgreementSignMessage`, `buildLegacyContractRequestMessage` (deprecated), `buildFullNameRequestMessage`, `formatSignTimestampUtc`, `parseFormattedMessage`, `asContractType` |
229
246
  | Wallet errors | `isUserRejected`, `isUnpredictableGas`, `classifyWalletFailure` |
230
247
  | Pool TVL | `poolTvl`, `combineTvlHistories`, `TvlHistoryInputError` — one strategy's history summed across deployments, in USD at the caller's rates |
231
248
  | Revert errors | `decodeRevert`, `extractRevertData` — the bytes a reverted call came back with, read as the custom error the contract named |
232
249
  | AU minimum | `auMinimumRemaining`, `isAustralianKyc`, `auThresholdFor`, `isAuMinimumExempt`, `parseMinorUnits`, `AU_ALPHA3`, `AU_MIN_CUMULATIVE_BY_STABLE` |
233
250
 
234
- Three rules worth knowing:
251
+ Rules worth knowing:
235
252
 
236
253
  - **Protocol strings are the exception to "never copy".** The messages
237
254
  `loan-contract` builds are reconstructed byte-for-byte by the Kasu backend to
@@ -252,6 +269,29 @@ Three rules worth knowing:
252
269
  `liteDescription` and `description` stay the raw CMS values. It is NOT
253
270
  sanitised: HTML tags and link syntax pass through unchanged, so render it
254
271
  as text, never as HTML or markdown.
272
+ - **The Details-screen fields omit, never stub.** `Strategy.strategyHistory`,
273
+ `Strategy.endBorrowers`, `Strategy.securityStructure`,
274
+ `getOriginatorHistory` and `getRiskManagementGroups` carry only what the CMS
275
+ actually authors: an empty, blank or malformed value is an absent key (or
276
+ `null` for a whole section), never a `0`, a dash or a sentence of the
277
+ SDK's own. A start date is `YYYY-MM-DD` and must be a real date from 2000
278
+ up to today. The originator's money figures are editorial USD on every
279
+ deployment — never FX-convert them. A risk item's `description` is present
280
+ exactly when its `clauses` are non-empty.
281
+ - **A failed CMS read rejects; it is not "no data".** `getOriginatorHistory`
282
+ and `getRiskManagementGroups` reject on a CMS outage (or no
283
+ `directusUrl`). For what to SHOW, treat a rejected `getRiskManagementGroups`
284
+ like `null`: fall back to `Strategy.securityStructure`. The pool getters
285
+ share their CMS reads per instance for 30 seconds (`getRiskPerformance` with
286
+ `getRiskManagementGroups`, `getOriginator` with `getOriginatorHistory`), so
287
+ a Details screen reads each collection once; a failed read is never reused.
288
+ - **`strategyTotalsUsd(legs, expectedDeployments)` states its coverage.** It
289
+ sums a strategy's Total Active Lending and Lender Interest Earned in USD
290
+ over the legs the caller loaded, each at its own rate. It is `null`
291
+ (withheld) when there are no legs or any loaded leg lacks a usable rate;
292
+ otherwise `isPartial` / `missingDeployments` name every expected deployment
293
+ the sum does not cover. Only `isPartial: false` is the whole strategy. A
294
+ duplicated or unexpected leg throws `StrategyTotalsInputError`.
255
295
  - **The tranche rename is display-only.** `getTrancheDisplayName` maps the
256
296
  `Senior` tranche to "Upper Mezzanine" on Apxium strategies, because the true
257
297
  senior position is held by an institutional lender. Call it at the view
@@ -662,8 +702,8 @@ tag workflow only verifies that a pushed `vX.Y.Z` tag matches `package.json`.
662
702
  ## Support
663
703
 
664
704
  - Issues: <https://github.com/Kasu-Finance/kasu-sdk/issues>
665
- - Developer documentation: <https://devdocs.kasu.finance>
666
- - Product documentation: <https://docs.kasu.finance>
705
+ - Developer documentation: <https://kasu.finance/docs/developers>
706
+ - Product documentation: <https://kasu.finance/docs/user>
667
707
 
668
708
  ## License
669
709