@kasufinance/kasu-sdk 2.13.0 → 2.14.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.
- package/README.md +40 -1
- package/dist/bundle.cjs.js +580 -60
- package/dist/bundle.esm.js +577 -61
- package/dist/domain/index.d.ts +2 -2
- package/dist/domain/pool-tvl.d.ts +104 -0
- package/dist/domain/requests.d.ts +11 -10
- package/dist/facade/index.d.ts +2 -0
- package/dist/facade/strategies.d.ts +17 -1
- package/dist/facade/strategy-deployments.d.ts +65 -0
- package/dist/index.d.ts +1 -1
- package/dist/services/DataService/data-service.d.ts +29 -1
- package/dist/services/DataService/tvl-history.d.ts +49 -0
- package/dist/services/UserLending/subgraph-types.d.ts +2 -8
- package/dist/services/UserLending/types.d.ts +10 -0
- package/dist/services/UserLending/user-lending.d.ts +14 -0
- package/package.json +1 -1
- package/src/domain/index.ts +7 -2
- package/src/domain/pool-tvl.ts +281 -0
- package/src/domain/requests.ts +37 -23
- package/src/facade/index.ts +10 -0
- package/src/facade/strategies.ts +26 -1
- package/src/facade/strategy-deployments.ts +161 -0
- package/src/index.ts +4 -1
- package/src/services/DataService/data-service.ts +103 -7
- package/src/services/DataService/tvl-history.ts +131 -0
- package/src/services/UserLending/queries.ts +2 -7
- package/src/services/UserLending/subgraph-types.ts +2 -8
- package/src/services/UserLending/types.ts +10 -0
- package/src/services/UserLending/user-lending.ts +98 -40
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)`, `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,
|
|
@@ -189,6 +227,7 @@ application formats them in its own design system and language.
|
|
|
189
227
|
| Settlement | `computeSettlementWindow`, `nextCycleBoundary`, `deriveCycleDates`, `CLEARING_WINDOW_SECONDS` |
|
|
190
228
|
| Loan contract | `encodeDepositData`, `buildContractVersionType`, `buildLoanAgreementSignMessage`, `buildLegacyContractRequestMessage`, `buildFullNameRequestMessage`, `formatSignTimestampUtc`, `parseFormattedMessage`, `asContractType` |
|
|
191
229
|
| Wallet errors | `isUserRejected`, `isUnpredictableGas`, `classifyWalletFailure` |
|
|
230
|
+
| Pool TVL | `poolTvl`, `combineTvlHistories`, `TvlHistoryInputError` — one strategy's history summed across deployments, in USD at the caller's rates |
|
|
192
231
|
| Revert errors | `decodeRevert`, `extractRevertData` — the bytes a reverted call came back with, read as the custom error the contract named |
|
|
193
232
|
| AU minimum | `auMinimumRemaining`, `isAustralianKyc`, `auThresholdFor`, `isAuMinimumExempt`, `parseMinorUnits`, `AU_ALPHA3`, `AU_MIN_CUMULATIVE_BY_STABLE` |
|
|
194
233
|
|