@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
@@ -15,6 +15,24 @@
15
15
  * on Base and XDC USDC, AUDD on XDC AUDD) — never converted to USD here;
16
16
  * shares are display units of tranche shares, as the subgraph's BigDecimals.
17
17
  */
18
+ /**
19
+ * The largest change of a lock's shares, as a fraction of its shares before
20
+ * the epoch, that one clearing's fixed-term top-up can make. The top-up is
21
+ * the fixed rate's difference from the variable one on one week's balance
22
+ * (`LendingPool._applyFixedRateInterests`) — a fraction of a percent at any
23
+ * real rate — so 5 % is far above every genuine top-up and far below any
24
+ * accounting fault. A lock-share change outside it is NOT interest: it is
25
+ * left out of the yield (a share movement is never booked as yield). The one
26
+ * seen on chain is a lock whose recorded shares were set to zero at a
27
+ * clearing while its shares stayed in the fixed-term contract.
28
+ */
29
+ export declare const MAX_TOP_UP_SHARE_FRACTION = 0.05;
30
+ /**
31
+ * True when `sharesBefore → sharesAt` is a change one clearing's fixed-term
32
+ * top-up can make (`MAX_TOP_UP_SHARE_FRACTION`). A lock with no shares
33
+ * before has no top-up at all.
34
+ */
35
+ export declare function isPlausibleTopUp(sharesBefore: number, sharesAt: number): boolean;
18
36
  /** One fixed-term lock inside a tranche position, at one epoch. */
19
37
  export interface EpochLockShares {
20
38
  /**
@@ -68,7 +86,13 @@ export interface EpochTrancheYield {
68
86
  * ```
69
87
  *
70
88
  * A zero denominator contributes 0 (a tranche or a lender with no shares
71
- * earned nothing at that close), never `NaN`.
89
+ * earned nothing at that close), never `NaN`. So does a NEGATIVE share count:
90
+ * the subgraph's per-lender shares are a ledger of accepted deposits and
91
+ * withdrawals, and a wallet whose shares arrived some other way (moved to it
92
+ * from another wallet) withdraws more than the ledger ever credited it. That
93
+ * position is not one the ledger can describe, and its negative count is not
94
+ * a negative yield. A lock-share change no top-up can make
95
+ * (`isPlausibleTopUp`) contributes no top-up.
72
96
  */
73
97
  export declare function epochTrancheYield(input: EpochTrancheYieldInput): EpochTrancheYield;
74
98
  /** One lender's settled yield in one tranche at one epoch. */
@@ -15,6 +15,29 @@
15
15
  * on Base and XDC USDC, AUDD on XDC AUDD) — never converted to USD here;
16
16
  * shares are display units of tranche shares, as the subgraph's BigDecimals.
17
17
  */
18
+ /**
19
+ * The largest change of a lock's shares, as a fraction of its shares before
20
+ * the epoch, that one clearing's fixed-term top-up can make. The top-up is
21
+ * the fixed rate's difference from the variable one on one week's balance
22
+ * (`LendingPool._applyFixedRateInterests`) — a fraction of a percent at any
23
+ * real rate — so 5 % is far above every genuine top-up and far below any
24
+ * accounting fault. A lock-share change outside it is NOT interest: it is
25
+ * left out of the yield (a share movement is never booked as yield). The one
26
+ * seen on chain is a lock whose recorded shares were set to zero at a
27
+ * clearing while its shares stayed in the fixed-term contract.
28
+ */
29
+ export const MAX_TOP_UP_SHARE_FRACTION = 0.05;
30
+ /**
31
+ * True when `sharesBefore → sharesAt` is a change one clearing's fixed-term
32
+ * top-up can make (`MAX_TOP_UP_SHARE_FRACTION`). A lock with no shares
33
+ * before has no top-up at all.
34
+ */
35
+ export function isPlausibleTopUp(sharesBefore, sharesAt) {
36
+ if (!(sharesBefore > 0))
37
+ return sharesAt === sharesBefore;
38
+ return (Math.abs(sharesAt - sharesBefore) <=
39
+ sharesBefore * MAX_TOP_UP_SHARE_FRACTION);
40
+ }
18
41
  /**
19
42
  * The ONE per-epoch formula. `Portfolio.getPortfolioLendingData` runs it for
20
43
  * the last settled epoch and `getYieldHistory` for every epoch of a window, so
@@ -29,24 +52,31 @@
29
52
  * ```
30
53
  *
31
54
  * A zero denominator contributes 0 (a tranche or a lender with no shares
32
- * earned nothing at that close), never `NaN`.
55
+ * earned nothing at that close), never `NaN`. So does a NEGATIVE share count:
56
+ * the subgraph's per-lender shares are a ledger of accepted deposits and
57
+ * withdrawals, and a wallet whose shares arrived some other way (moved to it
58
+ * from another wallet) withdraws more than the ledger ever credited it. That
59
+ * position is not one the ledger can describe, and its negative count is not
60
+ * a negative yield. A lock-share change no top-up can make
61
+ * (`isPlausibleTopUp`) contributes no top-up.
33
62
  */
34
63
  export function epochTrancheYield(input) {
35
- const base = input.trancheShares === 0
36
- ? 0
37
- : (input.epochInterest * input.userShares) / input.trancheShares;
64
+ const base = input.trancheShares > 0 && input.userShares > 0
65
+ ? (input.epochInterest * input.userShares) / input.trancheShares
66
+ : 0;
38
67
  let variable = base;
39
68
  const locks = input.locks.map((lock) => {
40
69
  if (!lock.active)
41
70
  return 0;
42
- const topUp = input.trancheSharesNow === 0
43
- ? 0
44
- : ((lock.sharesAtEpoch - lock.sharesBeforeEpoch) *
71
+ const topUp = input.trancheSharesNow > 0 &&
72
+ isPlausibleTopUp(lock.sharesBeforeEpoch, lock.sharesAtEpoch)
73
+ ? ((lock.sharesAtEpoch - lock.sharesBeforeEpoch) *
45
74
  input.trancheBalanceNow) /
46
- input.trancheSharesNow;
47
- const lockBase = input.userShares === 0
48
- ? 0
49
- : (base * lock.sharesBeforeEpoch) / input.userShares;
75
+ input.trancheSharesNow
76
+ : 0;
77
+ const lockBase = input.userShares > 0
78
+ ? (base * lock.sharesBeforeEpoch) / input.userShares
79
+ : 0;
50
80
  variable -= lockBase;
51
81
  return lockBase + topUp;
52
82
  });
@@ -1 +1 @@
1
- {"version":3,"file":"yield-history.js","sourceRoot":"","sources":["../../src/domain/yield-history.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AA4CH;;;;;;;;;;;;;;;GAeG;AACH,MAAM,UAAU,iBAAiB,CAC7B,KAA6B;IAE7B,MAAM,IAAI,GACN,KAAK,CAAC,aAAa,KAAK,CAAC;QACrB,CAAC,CAAC,CAAC;QACH,CAAC,CAAC,CAAC,KAAK,CAAC,aAAa,GAAG,KAAK,CAAC,UAAU,CAAC,GAAG,KAAK,CAAC,aAAa,CAAC;IAEzE,IAAI,QAAQ,GAAG,IAAI,CAAC;IACpB,MAAM,KAAK,GAAG,KAAK,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE;QACnC,IAAI,CAAC,IAAI,CAAC,MAAM;YAAE,OAAO,CAAC,CAAC;QAE3B,MAAM,KAAK,GACP,KAAK,CAAC,gBAAgB,KAAK,CAAC;YACxB,CAAC,CAAC,CAAC;YACH,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,aAAa,GAAG,IAAI,CAAC,iBAAiB,CAAC;gBAC1C,KAAK,CAAC,iBAAiB,CAAC;gBAC5B,KAAK,CAAC,gBAAgB,CAAC;QAEjC,MAAM,QA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AAW,EAAE,KAAK,MAAM,EAAE,CAAC;YAChE,SAAS;QACb,CAAC;QACD,IACI,SAAS,KAAK,SAAS;YACvB,KAAK,CAAC,SAAS,CAAC,WAAW,EAAE,KAAK,SAAS,EAC7C,CAAC;YACC,SAAS;QACb,CAAC;QAED,MAAM,KAAK,GAAG,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;QACzC,IAAI,KAAK,EAAE,CAAC;YACR,KAAK,CAAC,QAAQ,IAAI,KAAK,CAAC,QAAQ,CAAC;YACjC,SAAS;QACb,CAAC;QACD,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,OAAO,EAAE;YACvB,OAAO,EAAE,KAAK,CAAC,OAAO;YACtB,QAAQ,EAAE,KAAK,CAAC,QAAQ;YACxB,QAAQ,EAAE,KAAK,CAAC,QAAQ;SAC3B,CAAC,CAAC;IACP,CAAC;IAED,OAAO,CAAC,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,OAAO,GAAG,CAAC,CAAC,OAAO,CAAC,CAAC;AACvE,CAAC"}
@@ -11,4 +11,4 @@ export { CHAIN_CONFIGS } from './chain-configs';
11
11
  export { StrategyDeploymentInputError, strategyDeployments, } from './strategy-deployments';
12
12
  export type { StrategyDeployment, StrategyDeploymentInputErrorCode, } from './strategy-deployments';
13
13
  export { fetchUnusedPoolIds } from './unused-pool-ids';
14
- export type { SupportedChain, ChainConfigEntry, StableAsset, KasuOptions, Strategy, StrategyTranche, FixedTermOption, DepositParams, WithdrawParams, DepositLimits, KycParams, UserPositions, PlatformStats, StrategyRiskPerformance, } from './types';
14
+ export type { SupportedChain, ChainConfigEntry, StableAsset, KasuOptions, Strategy, StrategyTranche, FixedTermOption, DepositParams, WithdrawParams, DepositLimits, KycParams, UserPositions, PlatformStats, StrategyRiskPerformance, StrategyHistory, StrategyEndBorrowers, OriginatorHistory, } from './types';
@@ -10,6 +10,8 @@ export { CallsFacade } from './calls';
10
10
  export { READ_ONLY_MESSAGE } from './read-only';
11
11
  // Chain configurations
12
12
  export { CHAIN_CONFIGS } from './chain-configs';
13
+ // Strategy ↔ deployment resolution (pure, over CHAIN_CONFIGS)
14
+ export { StrategyDeploymentInputError, strategyDeployments, } from './strategy-deployments';
13
15
  // Directus-backed helpers (I/O — not part of `domain/`)
14
16
  export { fetchUnusedPoolIds } from './unused-pool-ids';
15
17
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/facade/index.ts"],"names":[],"mappings":"AAAA,mBAAmB;AACnB,OAAO,EAAE,IAAI,EAAE,MAAM,QAAQ,CAAC;AAE9B,gDAAgD;AAChD,OAAO,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;AAChD,OAAO,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAC5C,OAAO,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAC;AACnD,OAAO,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AACtC,OAAO,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AAOtC,0CAA0C;AAC1C,OAAO,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAEhD,uBAAuB;AACvB,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAEhD,wDAAwD;AACxD,OAAO,EAAE,kBAAkB,EAAE,MAAM,mBAAmB,CAAC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/facade/index.ts"],"names":[],"mappings":"AAAA,mBAAmB;AACnB,OAAO,EAAE,IAAI,EAAE,MAAM,QAAQ,CAAC;AAE9B,gDAAgD;AAChD,OAAO,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;AAChD,OAAO,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAC5C,OAAO,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAC;AACnD,OAAO,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AACtC,OAAO,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AAOtC,0CAA0C;AAC1C,OAAO,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAEhD,uBAAuB;AACvB,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAEhD,8DAA8D;AAC9D,OAAO,EACH,4BAA4B,EAC5B,mBAAmB,GACtB,MAAM,wBAAwB,CAAC;AAMhC,wDAAwD;AACxD,OAAO,EAAE,kBAAkB,EAAE,MAAM,mBAAmB,CAAC"}
@@ -1,9 +1,10 @@
1
1
  import { PoolTvlHistoryEntry } from '../domain/pool-tvl';
2
+ import { StrategyRiskGroup } from '../domain/strategy-details';
2
3
  import { DataService } from '../services/DataService/data-service';
3
4
  import { PoolTvlHistoryOptions, PoolTvlHistoryResult } from '../services/DataService/tvl-history';
4
5
  import { PoolDelegateProfileAndHistory } from '../services/DataService/types';
5
6
  import { UserLending } from '../services/UserLending/user-lending';
6
- import { DepositLimits, PlatformStats, Strategy, StrategyRiskPerformance, StrategyTranche } from './types';
7
+ import { DepositLimits, OriginatorHistory, PlatformStats, Strategy, StrategyRiskPerformance, StrategyTranche } from './types';
7
8
  /**
8
9
  * High-level facade for browsing Kasu lending strategies (pools).
9
10
  *
@@ -17,12 +18,48 @@ export declare class StrategiesFacade {
17
18
  * share their Base counterpart's editorial record). Lowercase keys.
18
19
  */
19
20
  private _poolMetadataMapping;
21
+ /**
22
+ * The clock the CMS start dates are checked against (a date after it
23
+ * is refused). Injected for tests; the current time otherwise.
24
+ */
25
+ private _now;
26
+ /**
27
+ * Milliseconds on a clock that only moves forward, for the shared
28
+ * CMS reads' 30-second lifetime — separate from `_now`, so a pinned
29
+ * date clock cannot keep a read alive for ever. Injected for tests;
30
+ * `Date.now` otherwise.
31
+ */
32
+ private _memoClockMs;
20
33
  constructor(_dataService: DataService, _userLending: UserLending,
21
34
  /**
22
35
  * Chain pool id → the pool id its CMS record is keyed by (XDC pools
23
36
  * share their Base counterpart's editorial record). Lowercase keys.
24
37
  */
25
- _poolMetadataMapping?: Record<string, string>);
38
+ _poolMetadataMapping?: Record<string, string>,
39
+ /**
40
+ * The clock the CMS start dates are checked against (a date after it
41
+ * is refused). Injected for tests; the current time otherwise.
42
+ */
43
+ _now?: () => Date,
44
+ /**
45
+ * Milliseconds on a clock that only moves forward, for the shared
46
+ * CMS reads' 30-second lifetime — separate from `_now`, so a pinned
47
+ * date clock cannot keep a read alive for ever. Injected for tests;
48
+ * `Date.now` otherwise.
49
+ */
50
+ _memoClockMs?: () => number);
51
+ /**
52
+ * Short-lived, per-instance memo of the two CMS-wide reads the pool
53
+ * getters share, so a Details screen asking for the loss rate, the risk
54
+ * groups and the originator together reads each collection once. Keyed
55
+ * by read; holds the in-flight promise, so concurrent callers share it.
56
+ * A REJECTED read is dropped at once, never served again — the next call
57
+ * retries.
58
+ */
59
+ private _cmsReads;
60
+ private _memoCmsRead;
61
+ private _riskManagementRecords;
62
+ private _originatorProfiles;
26
63
  /**
27
64
  * The pool's loss rate and first-loss capital, from its CMS
28
65
  * risk-management record. `null` when the pool has no record.
@@ -34,7 +71,9 @@ export declare class StrategiesFacade {
34
71
  * 0..1 fraction.
35
72
  *
36
73
  * Requires `directusUrl`; without it the call rejects with
37
- * `NO_DIRECTUS_URL_MESSAGE`, like every CMS-only read.
74
+ * `NO_DIRECTUS_URL_MESSAGE`, like every CMS-only read. Shares its CMS
75
+ * read with `getRiskManagementGroups` for 30 seconds per instance; a
76
+ * failed read is never reused.
38
77
  */
39
78
  getRiskPerformance(poolId: string): Promise<StrategyRiskPerformance | null>;
40
79
  /**
@@ -50,8 +89,51 @@ export declare class StrategiesFacade {
50
89
  * deployment every profile lists no pools and this resolves `null` —
51
90
  * the same answer kasu-ui's own lookup gives there today. The metadata
52
91
  * candidate becomes live once the service resolves the mapping.
92
+ *
93
+ * Shares its reads with `getOriginatorHistory` for 30 seconds per
94
+ * instance; a failed read is never reused. Each call returns its own
95
+ * copy of the profile, so mutating it changes nothing shared.
53
96
  */
54
97
  getOriginator(poolId: string): Promise<PoolDelegateProfileAndHistory | null>;
98
+ /**
99
+ * The credit originator's ENTIRE lending history for a pool — since when,
100
+ * total originated, loans outstanding, loss rate — read from the profile
101
+ * `getOriginator` finds, each figure validated. `null` when no profile
102
+ * lists the pool, or the profile authors none of the four.
103
+ *
104
+ * kasu-ui's Details tab shows these as its Credit Originator strip, and
105
+ * hides the strip when there is no profile. The money figures are
106
+ * editorial USD on every deployment: never FX-convert them. An XDC pool
107
+ * resolves `null` today, as it does in kasu-ui (see `getOriginator`).
108
+ *
109
+ * Requires `directusUrl`, like every CMS-only read; rejects when the
110
+ * read fails. Shares its reads with `getOriginator` for 30 seconds per
111
+ * instance; a failed read is never reused.
112
+ */
113
+ getOriginatorHistory(poolId: string): Promise<OriginatorHistory | null>;
114
+ /**
115
+ * The pool's Risk Management groups, from its CMS risk-management record:
116
+ * each group with its items (name, the pool's description of it split
117
+ * into lines, the shared tooltip), the groups in `RISK_GROUP_ORDER`
118
+ * (Security & Recourse, Structural Controls, Financial Covenants,
119
+ * Reporting Covenants, Key Eligibility Criteria, then any other in CMS
120
+ * order). See `groupRiskManagementItems`.
121
+ *
122
+ * `null` when the pool has no record, or the record has no usable item —
123
+ * then kasu-ui falls back to `Strategy.securityStructure`. XDC pools
124
+ * resolve through the metadata mapping to their Base record, like
125
+ * `getRiskPerformance`.
126
+ *
127
+ * REJECTS when the CMS read fails (an outage, or no `directusUrl` —
128
+ * `NO_DIRECTUS_URL_MESSAGE`), so a failure stays visible rather than
129
+ * reading as "no items". For what to SHOW, treat a rejection like `null`:
130
+ * fall back to `Strategy.securityStructure`, which arrives with the
131
+ * strategy and needs no second read.
132
+ *
133
+ * Shares its CMS read with `getRiskPerformance` for 30 seconds per
134
+ * instance; a failed read is never reused.
135
+ */
136
+ getRiskManagementGroups(poolId: string): Promise<StrategyRiskGroup[] | null>;
55
137
  private _metadataIdOf;
56
138
  /**
57
139
  * Fetch all active lending strategies.
@@ -8,6 +8,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
8
8
  });
9
9
  };
10
10
  import { selectVisiblePools } from '../domain/pools';
11
+ import { finiteOrUndefined, groupRiskManagementItems, parseFacility, readCmsStartDate, securityStructureOf, splitBusinessTypes, } from '../domain/strategy-details';
11
12
  import { pickShortDescription } from '../domain/strategy-summary';
12
13
  /**
13
14
  * High-level facade for browsing Kasu lending strategies (pools).
@@ -20,10 +21,55 @@ export class StrategiesFacade {
20
21
  * Chain pool id → the pool id its CMS record is keyed by (XDC pools
21
22
  * share their Base counterpart's editorial record). Lowercase keys.
22
23
  */
23
- _poolMetadataMapping = {}) {
24
+ _poolMetadataMapping = {},
25
+ /**
26
+ * The clock the CMS start dates are checked against (a date after it
27
+ * is refused). Injected for tests; the current time otherwise.
28
+ */
29
+ _now = () => new Date(),
30
+ /**
31
+ * Milliseconds on a clock that only moves forward, for the shared
32
+ * CMS reads' 30-second lifetime — separate from `_now`, so a pinned
33
+ * date clock cannot keep a read alive for ever. Injected for tests;
34
+ * `Date.now` otherwise.
35
+ */
36
+ _memoClockMs = () => Date.now()) {
24
37
  this._dataService = _dataService;
25
38
  this._userLending = _userLending;
26
39
  this._poolMetadataMapping = _poolMetadataMapping;
40
+ this._now = _now;
41
+ this._memoClockMs = _memoClockMs;
42
+ /**
43
+ * Short-lived, per-instance memo of the two CMS-wide reads the pool
44
+ * getters share, so a Details screen asking for the loss rate, the risk
45
+ * groups and the originator together reads each collection once. Keyed
46
+ * by read; holds the in-flight promise, so concurrent callers share it.
47
+ * A REJECTED read is dropped at once, never served again — the next call
48
+ * retries.
49
+ */
50
+ this._cmsReads = new Map();
51
+ }
52
+ _memoCmsRead(key, read) {
53
+ const nowMs = this._memoClockMs();
54
+ const cached = this._cmsReads.get(key);
55
+ if (cached && cached.expiresAt > nowMs) {
56
+ return cached.promise;
57
+ }
58
+ const promise = read();
59
+ const entry = { promise, expiresAt: nowMs + CMS_READ_TTL_MS };
60
+ this._cmsReads.set(key, entry);
61
+ promise.catch(() => {
62
+ // Only our own entry: a newer read may have replaced it.
63
+ if (this._cmsReads.get(key) === entry)
64
+ this._cmsReads.delete(key);
65
+ });
66
+ return promise;
67
+ }
68
+ _riskManagementRecords() {
69
+ return this._memoCmsRead('riskManagement', () => this._dataService.getRiskManagement());
70
+ }
71
+ _originatorProfiles() {
72
+ return this._memoCmsRead('originatorProfiles', () => this._dataService.getPoolDelegateProfileAndHistory());
27
73
  }
28
74
  /**
29
75
  * The pool's loss rate and first-loss capital, from its CMS
@@ -36,12 +82,14 @@ export class StrategiesFacade {
36
82
  * 0..1 fraction.
37
83
  *
38
84
  * Requires `directusUrl`; without it the call rejects with
39
- * `NO_DIRECTUS_URL_MESSAGE`, like every CMS-only read.
85
+ * `NO_DIRECTUS_URL_MESSAGE`, like every CMS-only read. Shares its CMS
86
+ * read with `getRiskManagementGroups` for 30 seconds per instance; a
87
+ * failed read is never reused.
40
88
  */
41
89
  getRiskPerformance(poolId) {
42
90
  return __awaiter(this, void 0, void 0, function* () {
43
91
  const metadataId = this._metadataIdOf(poolId);
44
- const records = yield this._dataService.getRiskManagement();
92
+ const records = yield this._riskManagementRecords();
45
93
  const record = records.find((r) => String(r.poolIdFK).toLowerCase() === metadataId);
46
94
  if (!record)
47
95
  return null;
@@ -65,16 +113,95 @@ export class StrategiesFacade {
65
113
  * deployment every profile lists no pools and this resolves `null` —
66
114
  * the same answer kasu-ui's own lookup gives there today. The metadata
67
115
  * candidate becomes live once the service resolves the mapping.
116
+ *
117
+ * Shares its reads with `getOriginatorHistory` for 30 seconds per
118
+ * instance; a failed read is never reused. Each call returns its own
119
+ * copy of the profile, so mutating it changes nothing shared.
68
120
  */
69
121
  getOriginator(poolId) {
70
122
  return __awaiter(this, void 0, void 0, function* () {
71
- var _a;
72
123
  const candidates = new Set([
73
124
  poolId.toLowerCase(),
74
125
  this._metadataIdOf(poolId),
75
126
  ]);
76
- const profiles = yield this._dataService.getPoolDelegateProfileAndHistory();
77
- return ((_a = profiles.find((profile) => profile.otherKASUPools.some((pool) => candidates.has(String(pool.id).toLowerCase())))) !== null && _a !== void 0 ? _a : null);
127
+ const profiles = yield this._originatorProfiles();
128
+ const profile = profiles.find((candidate) => candidate.otherKASUPools.some((pool) => candidates.has(String(pool.id).toLowerCase())));
129
+ // A copy: the profiles are shared between calls (see
130
+ // `_memoCmsRead`), so a caller sorting or editing its result must
131
+ // not change what the next call returns.
132
+ return profile
133
+ ? Object.assign(Object.assign({}, profile), { otherKASUPools: profile.otherKASUPools.map((pool) => (Object.assign({}, pool))) }) : null;
134
+ });
135
+ }
136
+ /**
137
+ * The credit originator's ENTIRE lending history for a pool — since when,
138
+ * total originated, loans outstanding, loss rate — read from the profile
139
+ * `getOriginator` finds, each figure validated. `null` when no profile
140
+ * lists the pool, or the profile authors none of the four.
141
+ *
142
+ * kasu-ui's Details tab shows these as its Credit Originator strip, and
143
+ * hides the strip when there is no profile. The money figures are
144
+ * editorial USD on every deployment: never FX-convert them. An XDC pool
145
+ * resolves `null` today, as it does in kasu-ui (see `getOriginator`).
146
+ *
147
+ * Requires `directusUrl`, like every CMS-only read; rejects when the
148
+ * read fails. Shares its reads with `getOriginator` for 30 seconds per
149
+ * instance; a failed read is never reused.
150
+ */
151
+ getOriginatorHistory(poolId) {
152
+ return __awaiter(this, void 0, void 0, function* () {
153
+ const profile = yield this.getOriginator(poolId);
154
+ if (!profile)
155
+ return null;
156
+ const history = {};
157
+ const since = readCmsStartDate(profile.delegateLendingHistory, this._now(), { unixSeconds: true });
158
+ if (since !== undefined)
159
+ history.since = since;
160
+ const totalOriginated = finiteOrUndefined(profile.totalLoanFundsOriginated);
161
+ if (totalOriginated !== undefined) {
162
+ history.totalOriginated = totalOriginated;
163
+ }
164
+ const loansOutstanding = finiteOrUndefined(profile.loansUnderManagement);
165
+ if (loansOutstanding !== undefined) {
166
+ history.loansOutstanding = loansOutstanding;
167
+ }
168
+ const lossRate = finiteOrUndefined(profile.historicLossRate);
169
+ if (lossRate !== undefined)
170
+ history.lossRate = lossRate;
171
+ return Object.keys(history).length > 0 ? history : null;
172
+ });
173
+ }
174
+ /**
175
+ * The pool's Risk Management groups, from its CMS risk-management record:
176
+ * each group with its items (name, the pool's description of it split
177
+ * into lines, the shared tooltip), the groups in `RISK_GROUP_ORDER`
178
+ * (Security & Recourse, Structural Controls, Financial Covenants,
179
+ * Reporting Covenants, Key Eligibility Criteria, then any other in CMS
180
+ * order). See `groupRiskManagementItems`.
181
+ *
182
+ * `null` when the pool has no record, or the record has no usable item —
183
+ * then kasu-ui falls back to `Strategy.securityStructure`. XDC pools
184
+ * resolve through the metadata mapping to their Base record, like
185
+ * `getRiskPerformance`.
186
+ *
187
+ * REJECTS when the CMS read fails (an outage, or no `directusUrl` —
188
+ * `NO_DIRECTUS_URL_MESSAGE`), so a failure stays visible rather than
189
+ * reading as "no items". For what to SHOW, treat a rejection like `null`:
190
+ * fall back to `Strategy.securityStructure`, which arrives with the
191
+ * strategy and needs no second read.
192
+ *
193
+ * Shares its CMS read with `getRiskPerformance` for 30 seconds per
194
+ * instance; a failed read is never reused.
195
+ */
196
+ getRiskManagementGroups(poolId) {
197
+ return __awaiter(this, void 0, void 0, function* () {
198
+ const metadataId = this._metadataIdOf(poolId);
199
+ const records = yield this._riskManagementRecords();
200
+ const record = records.find((r) => String(r.poolIdFK).toLowerCase() === metadataId);
201
+ if (!record || !Array.isArray(record.items))
202
+ return null;
203
+ const groups = groupRiskManagementItems(record.items);
204
+ return groups.length > 0 ? groups : null;
78
205
  });
79
206
  }
80
207
  _metadataIdOf(poolId) {
@@ -153,6 +280,26 @@ export class StrategiesFacade {
153
280
  return yield this._dataService.getPoolTvlHistory(poolId, options);
154
281
  });
155
282
  }
283
+ /**
284
+ * `getPoolTvlHistory` plus `opening` — the newest clearing before the
285
+ * window, read at its own block like every other point, or `null` when
286
+ * the pool has none — from the same read. Pass the result to
287
+ * `combineTvlHistories` as a leg with its `usdRate`: the opening is what
288
+ * the leg held before its first point, so a window cut at a different
289
+ * time on another chain does not count it 0. Same options and errors as
290
+ * `getPoolTvlHistory`; the extra cost is one clearing row (or, for
291
+ * `fromEpoch`, one small request) and one block.
292
+ *
293
+ * ```ts
294
+ * const leg = await kasu.strategies.getPoolTvlHistoryWindow(poolId, { count: 52 });
295
+ * // { entries: PoolTvlHistoryEntry[], opening: PoolTvlHistoryEntry | null }
296
+ * ```
297
+ */
298
+ getPoolTvlHistoryWindow(poolId_1) {
299
+ return __awaiter(this, arguments, void 0, function* (poolId, options = {}) {
300
+ return yield this._dataService.getPoolTvlHistoryWindow(poolId, options);
301
+ });
302
+ }
156
303
  /**
157
304
  * Fetch a single strategy by pool ID. Returns `null` if not found.
158
305
  */
@@ -228,10 +375,39 @@ export class StrategiesFacade {
228
375
  apyStructure: pool.poolApyStructure,
229
376
  thumbnailUrl: pool.thumbnailImageUrl,
230
377
  bannerUrl: pool.bannerImageUrl,
378
+ strategyHistory: strategyHistoryOf(pool, this._now()),
379
+ endBorrowers: endBorrowersOf(pool),
380
+ securityStructure: securityStructureOf(pool.security),
231
381
  _raw: pool,
232
382
  };
233
383
  }
234
384
  }
385
+ /**
386
+ * How long a CMS-wide read is shared between the pool getters. Long enough
387
+ * for one screen's worth of calls, short enough that a CMS edit shows on the
388
+ * next visit; apps cache further on their own terms.
389
+ */
390
+ const CMS_READ_TTL_MS = 30000;
391
+ /** `Strategy.strategyHistory`: an absent figure is an absent key. */
392
+ function strategyHistoryOf(pool, now) {
393
+ const history = {};
394
+ const since = readCmsStartDate(pool.operatingSince, now);
395
+ if (since !== undefined)
396
+ history.since = since;
397
+ const lenderInterestEarned = finiteOrUndefined(pool.yieldEarned);
398
+ if (lenderInterestEarned !== undefined) {
399
+ history.lenderInterestEarned = lenderInterestEarned;
400
+ }
401
+ return history;
402
+ }
403
+ /** Business Types and Facility Type, or `undefined` when neither is authored. */
404
+ function endBorrowersOf(pool) {
405
+ const businessTypes = splitBusinessTypes(pool.industryExposure);
406
+ const facility = parseFacility(pool.loanStructure);
407
+ if (!businessTypes && !facility)
408
+ return undefined;
409
+ return Object.assign(Object.assign({}, (businessTypes ? { businessTypes } : {})), (facility ? { facility } : {}));
410
+ }
235
411
  /**
236
412
  * A CMS text field as a string, or `undefined` when it is absent, not a
237
413
  * string, or empty (blank included) — the CMS stores an emptied field as `''`, and an empty
@@ -1 +1 @@
1
- {"version":3,"file":"strategies.js","sourceRoot":"","sources":["../../src/facade/strategies.ts"],"names":[],"mappings":";;;;;;;;;AACA,OAAO,EAAE,kBAAkB,EAAE,MAAM,iBAAiB,CAAC;AACrD,OAAO,EAAE,oBAAoB,EAAE,MAAM,4BAA4B,CAAC;AAkBlE;;;;GAIG;AACH,MAAM,OAAO,gBAAgB;IACzB,YACY,YAAyB,EACzB,YAAyB;IACjC;;;OAGG;IACK,uBAA+C,EAAE;QANjD,iBAAY,GAAZ,YAAY,CAAa;QACzB,iBAAY,GAAZ,YAAY,CAAa;QAKzB,yBAAoB,GAApB,oBAAoB,CAA6B;IAC1D,CAAC;IAEJ;;;;;;;;;;;;OAYG;IACG,kBAAkB,CACpB,MAAc;;YAEd,MAAM,UAAU,GAAG,IAAI,CAAC,aAAa,CAAC,MAAM,CAAC,CAAC;YAC9C,MAAM,OAAO,GAAG,MAAM,IAAI,CAAC,YAAY,CAAC,iBAAiB,EAAE,CAAC;YAC5D,MAAM,MAAM,GAAG,OAAO,CAAC,IAAI,CACvB,CAAC,CAAC,EAAE,EAAE,CAAC,MAAM,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,WAAW,EAAE,KAAK,UAAU,CACzD,CAAC;YACF,IAAI,CAAC,MAAM;gBAAE,OAAO,IAAI,CAAC;YACzB,MAAM,WAAW,GAAG,MAAM,CAAC,eAGZ,CAAC;YAChB,OAAO;gBACH,YAAY,EAAE,YAAY,CAAC,WAAW,aAAX,WAAW,uBAAX,WAAW,CAAE,YAAY,CAAC;gBACrD,gBAAg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OAAO,SAAS,CAAC;IAClD,uCACO,CAAC,aAAa,CAAC,CAAC,CAAC,EAAE,aAAa,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,GACxC,CAAC,QAAQ,CAAC,CAAC,CAAC,EAAE,QAAQ,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,EACnC;AACN,CAAC;AAED;;;;GAIG;AACH,SAAS,mBAAmB,CAAC,KAAc;IACvC,OAAO,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,CAAC,IAAI,EAAE,CAAC,MAAM,GAAG,CAAC;QACvD,CAAC,CAAC,KAAK;QACP,CAAC,CAAC,SAAS,CAAC;AACpB,CAAC;AAED;;;GAGG;AACH,SAAS,YAAY,CAAC,KAAc;IAChC,IAAI,OAAO,KAAK,KAAK,QAAQ;QAAE,OAAO,MAAM,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,CAAC;IAC5E,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE,CAAC;QAC5B,IAAI,KAAK,CAAC,IAAI,EAAE,KAAK,EAAE;YAAE,OAAO,IAAI,CAAC;QACrC,MAAM,OAAO,GAAG,MAAM,CAAC,KAAK,CAAC,CAAC;QAC9B,OAAO,MAAM,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,IAAI,CAAC;IACrD,CAAC;IACD,OAAO,IAAI,CAAC;AAChB,CAAC"}
@@ -0,0 +1,97 @@
1
+ import { CHAIN_CONFIGS } from './chain-configs';
2
+ /** What `strategyDeployments` throws for an id it cannot place. */
3
+ export class StrategyDeploymentInputError extends Error {
4
+ constructor(code) {
5
+ super(`strategyDeployments: input refused (${code})`);
6
+ this.name = 'StrategyDeploymentInputError';
7
+ this.code = code;
8
+ Object.setPrototypeOf(this, StrategyDeploymentInputError.prototype);
9
+ }
10
+ }
11
+ /** The canonical deployment: its pool ids ARE the strategies' ids. */
12
+ const CANONICAL_CHAIN = 'base';
13
+ const ADDRESS_RE = /^0x[0-9a-f]{40}$/;
14
+ /** The deployment's mapping with both sides lowercased; Base never has one. */
15
+ function mappingOf(configs, chain) {
16
+ var _a;
17
+ if (chain === CANONICAL_CHAIN)
18
+ return [];
19
+ return Object.entries((_a = configs[chain].poolMetadataMapping) !== null && _a !== void 0 ? _a : {}).map(([local, canonical]) => [local.toLowerCase(), canonical.toLowerCase()]);
20
+ }
21
+ /**
22
+ * `strategyDeployments` over any configs — the export reads `CHAIN_CONFIGS`;
23
+ * the spec passes its own to cover shapes the built-in mapping lacks.
24
+ */
25
+ export function resolveStrategyDeployments(configs, poolId, chain) {
26
+ const id = typeof poolId === 'string' ? poolId.trim().toLowerCase() : '';
27
+ if (!ADDRESS_RE.test(id)) {
28
+ throw new StrategyDeploymentInputError('pool-id');
29
+ }
30
+ if (typeof chain !== 'string' ||
31
+ !Object.prototype.hasOwnProperty.call(configs, chain)) {
32
+ throw new StrategyDeploymentInputError('chain');
33
+ }
34
+ const chains = Object.keys(configs);
35
+ const mappings = chains.map((c) => [c, mappingOf(configs, c)]);
36
+ const isLocalElsewhere = mappings.some(([c, mapping]) => c !== chain && mapping.some(([local]) => local === id));
37
+ let canonical;
38
+ if (chain === CANONICAL_CHAIN) {
39
+ // A Base id is its own Base pool — unless the mapping says it is
40
+ // another deployment's chain-local id, which names no Base pool.
41
+ if (isLocalElsewhere) {
42
+ throw new StrategyDeploymentInputError('wrong-chain');
43
+ }
44
+ canonical = id;
45
+ }
46
+ else {
47
+ const own = mappingOf(configs, chain).find(([local]) => local === id);
48
+ if (own) {
49
+ canonical = own[1];
50
+ }
51
+ else {
52
+ const isCanonical = mappings.some(([, mapping]) => mapping.some(([, target]) => target === id));
53
+ if (isLocalElsewhere || isCanonical) {
54
+ throw new StrategyDeploymentInputError('wrong-chain');
55
+ }
56
+ // Unmapped off Base: a strategy of one on its own chain (every
57
+ // XDC USDC pool today). Claiming a Base counterpart would read
58
+ // Base with an XDC address.
59
+ return [{ chain, poolId: id }];
60
+ }
61
+ }
62
+ const found = [
63
+ { chain: CANONICAL_CHAIN, poolId: canonical },
64
+ ];
65
+ for (const [c, mapping] of mappings) {
66
+ for (const [local, target] of mapping) {
67
+ if (target === canonical)
68
+ found.push({ chain: c, poolId: local });
69
+ }
70
+ }
71
+ return found;
72
+ }
73
+ /**
74
+ * Every deployment a strategy has a pool on, canonical (Base) first, then the
75
+ * others in `CHAIN_CONFIGS` order — the legs to fetch and pass to
76
+ * `combineTvlHistories`. One entry for a strategy that lives on one chain
77
+ * only (PayFi, on Base).
78
+ *
79
+ * `chain` is the deployment `poolId` was read on — required, because an
80
+ * address alone does not say which chain it belongs to. From either side of
81
+ * a mapping the answer is the same set: Tax Pay's Base id on `'base'` and
82
+ * its XDC id on `'xdc'` both return both pools. An id the mapping does not
83
+ * know is a strategy of one on its own chain. Ids are compared
84
+ * case-insensitively and returned lowercase.
85
+ *
86
+ * Throws `StrategyDeploymentInputError` for a malformed id, an unknown chain,
87
+ * or an id the mapping places on another deployment (`'wrong-chain'`).
88
+ *
89
+ * ```ts
90
+ * strategyDeployments(strategy.id, 'base');
91
+ * // [{ chain: 'base', poolId: '0x…' }, { chain: 'xdc', poolId: '0x…' }]
92
+ * ```
93
+ */
94
+ export function strategyDeployments(poolId, chain) {
95
+ return resolveStrategyDeployments(CHAIN_CONFIGS, poolId, chain);
96
+ }
97
+ //# sourceMappingURL=strategy-deployments.js.map