@kasufinance/kasu-sdk 2.11.0 → 2.13.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 +37 -2
  2. package/dist/bundle.cjs.js +1516 -71
  3. package/dist/bundle.esm.js +1511 -73
  4. package/dist/domain/index.d.ts +6 -2
  5. package/dist/domain/index.js +2 -0
  6. package/dist/domain/index.js.map +1 -1
  7. package/dist/domain/pool-tvl.d.ts +62 -0
  8. package/dist/domain/pool-tvl.js +22 -0
  9. package/dist/domain/pool-tvl.js.map +1 -0
  10. package/dist/domain/yield-history.d.ts +122 -0
  11. package/dist/domain/yield-history.js +95 -0
  12. package/dist/domain/yield-history.js.map +1 -0
  13. package/dist/facade/chain-configs.js +24 -0
  14. package/dist/facade/chain-configs.js.map +1 -1
  15. package/dist/facade/kasu.d.ts +2 -0
  16. package/dist/facade/kasu.js +13 -5
  17. package/dist/facade/kasu.js.map +1 -1
  18. package/dist/facade/strategies.d.ts +20 -0
  19. package/dist/facade/strategies.js +22 -0
  20. package/dist/facade/strategies.js.map +1 -1
  21. package/dist/facade/types.d.ts +20 -0
  22. package/dist/facade/user-portfolio.d.ts +32 -0
  23. package/dist/facade/user-portfolio.js +34 -0
  24. package/dist/facade/user-portfolio.js.map +1 -1
  25. package/dist/index.d.ts +5 -0
  26. package/dist/index.js +2 -0
  27. package/dist/index.js.map +1 -1
  28. package/dist/kasu-sdk.d.ts +9 -1
  29. package/dist/kasu-sdk.js +2 -2
  30. package/dist/kasu-sdk.js.map +1 -1
  31. package/dist/sdk-config.d.ts +20 -0
  32. package/dist/sdk-config.js +3 -1
  33. package/dist/sdk-config.js.map +1 -1
  34. package/dist/services/DataService/data-service.d.ts +81 -1
  35. package/dist/services/DataService/data-service.js +211 -6
  36. package/dist/services/DataService/data-service.js.map +1 -1
  37. package/dist/services/DataService/tvl-history.d.ts +296 -0
  38. package/dist/services/DataService/tvl-history.js +558 -0
  39. package/dist/services/DataService/tvl-history.js.map +1 -0
  40. package/dist/services/Portfolio/portfolio.d.ts +37 -0
  41. package/dist/services/Portfolio/portfolio.js +136 -56
  42. package/dist/services/Portfolio/portfolio.js.map +1 -1
  43. package/dist/services/Portfolio/queries.js +15 -3
  44. package/dist/services/Portfolio/queries.js.map +1 -1
  45. package/dist/services/Portfolio/types.d.ts +8 -0
  46. package/dist/services/Portfolio/yield-history.d.ts +162 -0
  47. package/dist/services/Portfolio/yield-history.js +378 -0
  48. package/dist/services/Portfolio/yield-history.js.map +1 -0
  49. package/dist/services/shared.d.ts +16 -0
  50. package/dist/services/shared.js +30 -0
  51. package/dist/services/shared.js.map +1 -1
  52. package/package.json +1 -1
  53. package/src/domain/index.ts +15 -10
  54. package/src/domain/pool-tvl.ts +66 -0
  55. package/src/domain/yield-history.ts +194 -0
  56. package/src/facade/chain-configs.ts +26 -0
  57. package/src/facade/kasu.ts +20 -2
  58. package/src/facade/strategies.ts +26 -0
  59. package/src/facade/types.ts +20 -0
  60. package/src/facade/user-portfolio.ts +40 -3
  61. package/src/index.ts +11 -0
  62. package/src/kasu-sdk.ts +19 -2
  63. package/src/sdk-config.ts +22 -0
  64. package/src/services/DataService/data-service.ts +296 -6
  65. package/src/services/DataService/tvl-history.ts +853 -0
  66. package/src/services/Portfolio/portfolio.ts +263 -153
  67. package/src/services/Portfolio/queries.ts +15 -3
  68. package/src/services/Portfolio/types.ts +10 -0
  69. package/src/services/Portfolio/yield-history.ts +541 -0
  70. package/src/services/shared.ts +38 -1
package/README.md CHANGED
@@ -116,9 +116,9 @@ 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)` | Browse pools, APY, capacity, risk, originator |
119
+ | `kasu.strategies` | `getAll()`, `getVisible()`, `getById()`, `getPlatformStats()`, `getPerformanceFeePercent()`, `calculateDepositLimits()`, `getRiskPerformance(poolId)`, `getOriginator(poolId)`, `getPoolTvlHistory(poolId)` | Browse pools, APY, capacity, risk, originator, TVL history |
120
120
  | `kasu.deposits` | `deposit()`, `withdraw()`, `withdrawMax()`, `buildKycParams()`, `isClearingPending()` | Submit transactions |
121
- | `kasu.portfolio` | `getPositions()`, `getTransactionHistory()`, `getRequestStates()` | Lender balances, yield, history |
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 |
123
123
  | `kasu.calls` | `requestWithdrawal(params)`, `cancelDepositRequest(poolId, dNftId)`, `cancelWithdrawalRequest(poolId, wNftId)`, `withdrawAtExpiry(poolId, lockId)` | Encoded calls for a sponsored relay (read, then encode — never sends) |
124
124
 
@@ -132,6 +132,41 @@ return an empty list; pass it straight through. `SdkConfig` normalises an empty
132
132
  exclusion list to `['']`, because the subgraph reads `id_not_in: []` as "match
133
133
  nothing" and would otherwise hide every pool.
134
134
 
135
+ `kasu.portfolio.getYieldHistory(user, { fromEpoch?, count? })` returns one
136
+ `{ epochId, epochEnd, poolId, trancheId, netYield }` per settled cycle the
137
+ lender held shares in; `aggregateYieldHistory(entries, { poolId? })` turns it
138
+ into chart bars. `netYield` is NET of the performance fee and in the
139
+ deployment's own stable token (AUDD on XDC AUDD — convert before showing USD);
140
+ `epochEnd` is unix seconds. For a fixed-term lock holder the bars can sum to
141
+ slightly more than lifetime interest (up to about 0.2 %, top-ups are valued at
142
+ today's share price), so show "earned to date" from the lifetime figure, not
143
+ from the sum of the bars.
144
+
145
+ `kasu.strategies.getPoolTvlHistory(poolId, { fromEpoch?, count?, timeoutMs?,
146
+ signal? })` returns the strategy's TVL (total lent by everyone) as
147
+ `{ epochId, timestamp, tvl, kind }[]`, ascending in time: one
148
+ `kind: 'clearing'` point per finished clearing, read at the block it finished
149
+ in, then one `kind: 'current'` point. `tvl` is in the deployment's own stable
150
+ token (AUDD on XDC AUDD — convert before showing USD) and is on-chain plus
151
+ off-chain TVL, the same `poolTvl` sum `tvl.total` uses; `timestamp` is unix
152
+ seconds. Plot by `timestamp`, not `epochId`: epoch numbers can jump, and
153
+ clearings run in one block share a point in time.
154
+
155
+ The `current` point is the subgraph's latest balance plus the off-chain TVL
156
+ read at `latest`, so it equals `strategy.tvl.total` when both calls' reads
157
+ succeed. `tvl.total` falls back to an off-chain 0 when its own read fails;
158
+ the history throws instead.
159
+
160
+ The off-chain part at old blocks needs RPCs that serve PAST state (archive
161
+ nodes). Built-in chains carry public ones (`historyRpcUrls`, tried in order,
162
+ 10 s per call), but they are RATE-LIMITED and shared: **partners should pass
163
+ their own archive provider** — `Kasu.create({ chain, historyProvider })` — or
164
+ their own `configOverrides.historyRpcUrls`. A failed past-state read throws
165
+ (after retries); it never becomes 0. Final blocks are cached per SDK
166
+ instance, so a second call reads only what is new. `timeoutMs` (default
167
+ 30 s) and `signal` bound the call and reject with
168
+ `PoolTvlHistoryTimeoutError` / `PoolTvlHistoryAbortedError`.
169
+
135
170
  ## Domain helpers
136
171
 
137
172
  Pure functions shared by every Kasu frontend. They return **numbers and codes,