@kasufinance/kasu-sdk 2.4.2 → 2.6.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 (180) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +201 -253
  3. package/dist/bundle.cjs.js +5472 -1710
  4. package/dist/bundle.esm.js +5415 -1713
  5. package/dist/domain/au-minimum.d.ts +135 -0
  6. package/dist/domain/au-minimum.js +154 -0
  7. package/dist/domain/au-minimum.js.map +1 -0
  8. package/dist/domain/au-minimum.test.js +202 -0
  9. package/dist/domain/au-minimum.test.js.map +1 -0
  10. package/dist/domain/deposit-bounds.d.ts +62 -0
  11. package/dist/domain/deposit-bounds.js +84 -0
  12. package/dist/domain/deposit-bounds.js.map +1 -0
  13. package/dist/domain/deposit-bounds.test.d.ts +1 -0
  14. package/dist/domain/deposit-bounds.test.js +135 -0
  15. package/dist/domain/deposit-bounds.test.js.map +1 -0
  16. package/dist/domain/index.d.ts +40 -0
  17. package/dist/domain/index.js +33 -0
  18. package/dist/domain/index.js.map +1 -0
  19. package/dist/domain/loan-contract.d.ts +174 -0
  20. package/dist/domain/loan-contract.js +160 -0
  21. package/dist/domain/loan-contract.js.map +1 -0
  22. package/dist/domain/loan-contract.test.d.ts +1 -0
  23. package/dist/domain/loan-contract.test.js +255 -0
  24. package/dist/domain/loan-contract.test.js.map +1 -0
  25. package/dist/domain/partners.d.ts +34 -0
  26. package/dist/domain/partners.js +43 -0
  27. package/dist/domain/partners.js.map +1 -0
  28. package/dist/domain/partners.test.d.ts +1 -0
  29. package/dist/domain/partners.test.js +53 -0
  30. package/dist/domain/partners.test.js.map +1 -0
  31. package/dist/domain/pools.d.ts +70 -0
  32. package/dist/domain/pools.js +134 -0
  33. package/dist/domain/pools.js.map +1 -0
  34. package/dist/domain/pools.test.d.ts +1 -0
  35. package/dist/domain/pools.test.js +184 -0
  36. package/dist/domain/pools.test.js.map +1 -0
  37. package/dist/domain/rates.d.ts +83 -0
  38. package/dist/domain/rates.js +120 -0
  39. package/dist/domain/rates.js.map +1 -0
  40. package/dist/domain/rates.test.d.ts +1 -0
  41. package/dist/domain/rates.test.js +181 -0
  42. package/dist/domain/rates.test.js.map +1 -0
  43. package/dist/domain/requests.d.ts +181 -0
  44. package/dist/domain/requests.js +202 -0
  45. package/dist/domain/requests.js.map +1 -0
  46. package/dist/domain/requests.test.d.ts +1 -0
  47. package/dist/domain/requests.test.js +470 -0
  48. package/dist/domain/requests.test.js.map +1 -0
  49. package/dist/domain/settlement.d.ts +97 -0
  50. package/dist/domain/settlement.js +117 -0
  51. package/dist/domain/settlement.js.map +1 -0
  52. package/dist/domain/settlement.test.d.ts +1 -0
  53. package/dist/domain/settlement.test.js +152 -0
  54. package/dist/domain/settlement.test.js.map +1 -0
  55. package/dist/domain/tranche-display-name.d.ts +17 -0
  56. package/dist/domain/tranche-display-name.js +30 -0
  57. package/dist/domain/tranche-display-name.js.map +1 -0
  58. package/dist/domain/tranche-display-name.test.d.ts +1 -0
  59. package/dist/domain/tranche-display-name.test.js +58 -0
  60. package/dist/domain/tranche-display-name.test.js.map +1 -0
  61. package/dist/domain/tranches.d.ts +89 -0
  62. package/dist/domain/tranches.js +150 -0
  63. package/dist/domain/tranches.js.map +1 -0
  64. package/dist/domain/tranches.test.d.ts +1 -0
  65. package/dist/domain/tranches.test.js +206 -0
  66. package/dist/domain/tranches.test.js.map +1 -0
  67. package/dist/domain/wallet-errors.d.ts +37 -0
  68. package/dist/domain/wallet-errors.js +56 -0
  69. package/dist/domain/wallet-errors.js.map +1 -0
  70. package/dist/domain/wallet-errors.test.d.ts +1 -0
  71. package/dist/domain/wallet-errors.test.js +71 -0
  72. package/dist/domain/wallet-errors.test.js.map +1 -0
  73. package/dist/facade/chain-configs.js +61 -1
  74. package/dist/facade/chain-configs.js.map +1 -1
  75. package/dist/facade/config.test.d.ts +1 -0
  76. package/dist/facade/config.test.js +216 -0
  77. package/dist/facade/config.test.js.map +1 -0
  78. package/dist/facade/deposits.d.ts +22 -1
  79. package/dist/facade/deposits.js +24 -1
  80. package/dist/facade/deposits.js.map +1 -1
  81. package/dist/facade/facade.test.d.ts +1 -0
  82. package/dist/{tests → facade}/facade.test.js +87 -5
  83. package/dist/facade/facade.test.js.map +1 -0
  84. package/dist/facade/index.d.ts +2 -1
  85. package/dist/facade/index.js +2 -0
  86. package/dist/facade/index.js.map +1 -1
  87. package/dist/facade/kasu.d.ts +49 -8
  88. package/dist/facade/kasu.js +117 -13
  89. package/dist/facade/kasu.js.map +1 -1
  90. package/dist/facade/strategies.d.ts +25 -0
  91. package/dist/facade/strategies.js +36 -0
  92. package/dist/facade/strategies.js.map +1 -1
  93. package/dist/facade/types.d.ts +57 -2
  94. package/dist/facade/unused-pool-ids.d.ts +31 -0
  95. package/dist/facade/unused-pool-ids.js +57 -0
  96. package/dist/facade/unused-pool-ids.js.map +1 -0
  97. package/dist/facade/user-portfolio.d.ts +18 -0
  98. package/dist/facade/user-portfolio.js +23 -0
  99. package/dist/facade/user-portfolio.js.map +1 -1
  100. package/dist/index.d.ts +2 -0
  101. package/dist/index.js +6 -0
  102. package/dist/index.js.map +1 -1
  103. package/dist/sdk-config.d.ts +11 -0
  104. package/dist/sdk-config.js +8 -1
  105. package/dist/sdk-config.js.map +1 -1
  106. package/dist/services/DataService/data-service.d.ts +5 -0
  107. package/dist/services/DataService/data-service.js +10 -12
  108. package/dist/services/DataService/data-service.js.map +1 -1
  109. package/dist/services/DataService/directus-client.d.ts +26 -0
  110. package/dist/services/DataService/directus-client.js +38 -0
  111. package/dist/services/DataService/directus-client.js.map +1 -0
  112. package/dist/services/Locking/calculate-apy.test.d.ts +1 -0
  113. package/dist/services/Locking/calculate-apy.test.js +41 -0
  114. package/dist/services/Locking/calculate-apy.test.js.map +1 -0
  115. package/dist/services/Locking/locking.d.ts +14 -0
  116. package/dist/services/Locking/locking.js +16 -2
  117. package/dist/services/Locking/locking.js.map +1 -1
  118. package/dist/services/UserLending/user-lending.js +11 -7
  119. package/dist/services/UserLending/user-lending.js.map +1 -1
  120. package/dist/tests/sample.test.js +46 -25
  121. package/dist/tests/sample.test.js.map +1 -1
  122. package/package.json +43 -12
  123. package/src/domain/au-minimum.test.ts +371 -0
  124. package/src/domain/au-minimum.ts +192 -0
  125. package/src/domain/deposit-bounds.test.ts +200 -0
  126. package/src/domain/deposit-bounds.ts +118 -0
  127. package/src/domain/index.ts +134 -0
  128. package/src/domain/loan-contract.test.ts +343 -0
  129. package/src/domain/loan-contract.ts +275 -0
  130. package/src/domain/partners.test.ts +83 -0
  131. package/src/domain/partners.ts +66 -0
  132. package/src/domain/pools.test.ts +260 -0
  133. package/src/domain/pools.ts +150 -0
  134. package/src/domain/rates.test.ts +254 -0
  135. package/src/domain/rates.ts +120 -0
  136. package/src/domain/requests.test.ts +653 -0
  137. package/src/domain/requests.ts +414 -0
  138. package/src/domain/settlement.test.ts +198 -0
  139. package/src/domain/settlement.ts +161 -0
  140. package/src/domain/tranche-display-name.test.ts +96 -0
  141. package/src/domain/tranche-display-name.ts +34 -0
  142. package/src/domain/tranches.test.ts +300 -0
  143. package/src/domain/tranches.ts +177 -0
  144. package/src/domain/wallet-errors.test.ts +100 -0
  145. package/src/domain/wallet-errors.ts +56 -0
  146. package/src/facade/chain-configs.ts +62 -1
  147. package/src/facade/config.test.ts +265 -0
  148. package/src/facade/deposits.ts +25 -0
  149. package/src/{tests → facade}/facade.test.ts +134 -5
  150. package/src/facade/index.ts +4 -0
  151. package/src/facade/kasu.ts +155 -12
  152. package/src/facade/strategies.ts +36 -0
  153. package/src/facade/types.ts +60 -2
  154. package/src/facade/unused-pool-ids.ts +59 -0
  155. package/src/facade/user-portfolio.ts +24 -0
  156. package/src/index.ts +8 -0
  157. package/src/sdk-config.ts +19 -1
  158. package/src/services/DataService/data-service.ts +14 -26
  159. package/src/services/DataService/directus-client.ts +54 -0
  160. package/src/services/Locking/calculate-apy.test.ts +52 -0
  161. package/src/services/Locking/locking.ts +16 -2
  162. package/src/services/UserLending/user-lending.ts +17 -21
  163. package/src/tests/sample.test.ts +54 -33
  164. package/.eslintignore +0 -3
  165. package/.eslintrc.json +0 -90
  166. package/.github/workflows/ci.yml +0 -39
  167. package/.github/workflows/gitleaks.yml +0 -22
  168. package/.github/workflows/main.yml +0 -41
  169. package/.gitleaksignore +0 -19
  170. package/.prettierignore +0 -3
  171. package/.prettierrc +0 -28
  172. package/CLAUDE.md +0 -410
  173. package/copy-abi.ps1 +0 -15
  174. package/dist/tests/facade.test.js.map +0 -1
  175. package/index.ts +0 -2
  176. package/jest-config.ts +0 -9
  177. package/jest.config.js +0 -8
  178. package/rollup.config.js +0 -45
  179. package/tsconfig.json +0 -27
  180. /package/dist/{tests/facade.test.d.ts → domain/au-minimum.test.d.ts} +0 -0
@@ -0,0 +1,265 @@
1
+ import { providers, Wallet } from 'ethers';
2
+
3
+ import { SdkConfig } from '../sdk-config';
4
+
5
+ import { CHAIN_CONFIGS } from './chain-configs';
6
+ import { Kasu } from './kasu';
7
+ import { ChainConfigEntry } from './types';
8
+
9
+ // Pure config assertions — no network, unlike `facade.test.ts`.
10
+
11
+ const BASE_CONTRACTS = CHAIN_CONFIGS.base.contracts;
12
+
13
+ /** A signer with a provider attached, offline — nothing here sends anything. */
14
+ function signer(): Wallet {
15
+ return Wallet.createRandom().connect(
16
+ new providers.StaticJsonRpcProvider(
17
+ CHAIN_CONFIGS.base.rpcUrls[0],
18
+ CHAIN_CONFIGS.base.chainId,
19
+ ),
20
+ );
21
+ }
22
+
23
+ describe('SdkConfig — UNUSED_LENDING_POOL_IDS normalisation', () => {
24
+ it("turns an empty exclusion list into the [''] sentinel", () => {
25
+ // `id_not_in: []` matches NOTHING in the subgraph: on Base it returns
26
+ // 0 pools where `['']` returns all 9 (verified live 2026-09-04).
27
+ const config = new SdkConfig({
28
+ subgraphUrl: 'https://example.invalid/subgraph',
29
+ contracts: BASE_CONTRACTS,
30
+ UNUSED_LENDING_POOL_IDS: [],
31
+ });
32
+ expect(config.UNUSED_LENDING_POOL_IDS).toEqual(['']);
33
+ });
34
+
35
+ it('leaves a caller-supplied exclusion list untouched', () => {
36
+ const config = new SdkConfig({
37
+ subgraphUrl: 'https://example.invalid/subgraph',
38
+ contracts: BASE_CONTRACTS,
39
+ UNUSED_LENDING_POOL_IDS: ['0xdead'],
40
+ });
41
+ expect(config.UNUSED_LENDING_POOL_IDS).toEqual(['0xdead']);
42
+ });
43
+
44
+ it('leaves a sentinel a consumer already passes untouched', () => {
45
+ // kasu-ui passes [''], kasu-mobile passes the zero address.
46
+ const zeroAddress = '0x0000000000000000000000000000000000000000';
47
+ for (const sentinel of [[''], [zeroAddress]]) {
48
+ const config = new SdkConfig({
49
+ subgraphUrl: 'https://example.invalid/subgraph',
50
+ contracts: BASE_CONTRACTS,
51
+ UNUSED_LENDING_POOL_IDS: sentinel,
52
+ });
53
+ expect(config.UNUSED_LENDING_POOL_IDS).toEqual(sentinel);
54
+ }
55
+ });
56
+ });
57
+
58
+ describe('CHAIN_CONFIGS — stable asset', () => {
59
+ it('gives every chain exactly one stable asset', () => {
60
+ for (const [chain, config] of Object.entries(CHAIN_CONFIGS)) {
61
+ expect(config.stableAsset.address).toMatch(/^0x[0-9a-fA-F]{40}$/);
62
+ expect(config.stableAsset.symbol.length).toBeGreaterThan(0);
63
+ expect(config.stableAsset.decimals).toBeGreaterThan(0);
64
+ expect(config.stableAsset.currencyCode).toMatch(/^[A-Z]{3}$/);
65
+ expect(chain).toBeTruthy();
66
+ }
67
+ });
68
+
69
+ it('carries the live token per deployment', () => {
70
+ expect(CHAIN_CONFIGS.base.stableAsset).toEqual({
71
+ address: '0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913',
72
+ symbol: 'USDC',
73
+ name: 'USD Coin',
74
+ decimals: 6,
75
+ currencyCode: 'USD',
76
+ });
77
+ expect(CHAIN_CONFIGS.xdc.stableAsset.symbol).toBe('AUDD');
78
+ expect(CHAIN_CONFIGS.xdc.stableAsset.currencyCode).toBe('AUD');
79
+ expect(CHAIN_CONFIGS['xdc-usdc'].stableAsset.symbol).toBe('USDC');
80
+ expect(CHAIN_CONFIGS.plume.stableAsset.symbol).toBe('pUSD');
81
+ });
82
+ });
83
+
84
+ describe('CHAIN_CONFIGS — rpcUrls', () => {
85
+ it('gives every live deployment at least one default endpoint', () => {
86
+ for (const chain of ['base', 'xdc', 'xdc-usdc'] as const) {
87
+ expect(CHAIN_CONFIGS[chain].rpcUrls.length).toBeGreaterThan(0);
88
+ expect(CHAIN_CONFIGS[chain].retired).toBeUndefined();
89
+ }
90
+ });
91
+
92
+ it('never lists an XDC endpoint that fails CORS preflight', () => {
93
+ // `rpc.xdc.org` / `erpc.xdc.org` answer OPTIONS without
94
+ // `access-control-allow-origin`, so a browser call hangs. House rule.
95
+ for (const config of Object.values(CHAIN_CONFIGS)) {
96
+ for (const url of config.rpcUrls) {
97
+ expect(url).not.toContain('rpc.xdc.org');
98
+ expect(url).not.toContain('erpc.xdc.org');
99
+ }
100
+ }
101
+ });
102
+
103
+ it('marks the retired deployment and leaves it without a default RPC', () => {
104
+ expect(CHAIN_CONFIGS.plume.retired).toBe(true);
105
+ expect(CHAIN_CONFIGS.plume.rpcUrls).toEqual([]);
106
+ });
107
+ });
108
+
109
+ describe('Kasu — read-only create and connect', () => {
110
+ it('creates a read-only instance with no signerOrProvider', () => {
111
+ const kasu = Kasu.create({ chain: 'base' });
112
+ expect(kasu.isReadOnly).toBe(true);
113
+ expect(kasu.provider).toBeInstanceOf(providers.StaticJsonRpcProvider);
114
+ });
115
+
116
+ it('uses rpcUrls[0] and the config chain id, with no network detection', () => {
117
+ const kasu = Kasu.create({ chain: 'base' });
118
+ const provider = kasu.provider as providers.StaticJsonRpcProvider;
119
+ expect(provider.connection.url).toBe(CHAIN_CONFIGS.base.rpcUrls[0]);
120
+ expect(provider.network.chainId).toBe(CHAIN_CONFIGS.base.chainId);
121
+ });
122
+
123
+ it('refuses a read-only create on a retired chain with no default RPC', () => {
124
+ expect(() => Kasu.create({ chain: 'plume' })).toThrow(
125
+ 'Kasu.create: chain "plume" has no default RPC (retired); pass signerOrProvider',
126
+ );
127
+ });
128
+
129
+ it('still accepts an explicit provider for the retired chain', () => {
130
+ const provider = new providers.StaticJsonRpcProvider(
131
+ 'https://example.invalid/plume',
132
+ CHAIN_CONFIGS.plume.chainId,
133
+ );
134
+ const kasu = Kasu.create({ chain: 'plume', signerOrProvider: provider });
135
+ expect(kasu.isReadOnly).toBe(true);
136
+ expect(kasu.provider).toBe(provider);
137
+ });
138
+
139
+ it('is writable when created from a signer', () => {
140
+ const kasu = Kasu.create({ chain: 'base', signerOrProvider: signer() });
141
+ expect(kasu.isReadOnly).toBe(false);
142
+ });
143
+
144
+ it('connect returns a NEW writable instance, leaving the original read-only', () => {
145
+ const readOnly = Kasu.create({ chain: 'base' });
146
+ const connected = readOnly.connect(signer());
147
+ expect(connected).not.toBe(readOnly);
148
+ expect(connected.isReadOnly).toBe(false);
149
+ expect(readOnly.isReadOnly).toBe(true);
150
+ });
151
+
152
+ it('connect keeps the chain config and the configOverrides', () => {
153
+ const readOnly = Kasu.create({
154
+ chain: 'base',
155
+ configOverrides: { UNUSED_LENDING_POOL_IDS: ['0xhidden'] },
156
+ });
157
+ const connected = readOnly.connect(signer());
158
+ expect(connected.chainConfig).toBe(readOnly.chainConfig);
159
+ const configOf = (kasu: Kasu): SdkConfig =>
160
+ (kasu.services.DataService as unknown as { _kasuConfig: SdkConfig })
161
+ ._kasuConfig;
162
+ expect(configOf(connected).UNUSED_LENDING_POOL_IDS).toEqual([
163
+ '0xhidden',
164
+ ]);
165
+ });
166
+
167
+ it('exposes the signer’s own provider on a connected instance', () => {
168
+ const wallet = signer();
169
+ const kasu = Kasu.create({ chain: 'base', signerOrProvider: wallet });
170
+ expect(kasu.provider).toBe(wallet.provider);
171
+ });
172
+
173
+ it('throws rather than returning undefined for a provider-less signer', () => {
174
+ const kasu = Kasu.create({
175
+ chain: 'base',
176
+ signerOrProvider: Wallet.createRandom(),
177
+ });
178
+ expect(() => kasu.provider).toThrow('has no provider attached');
179
+ });
180
+ });
181
+
182
+ describe('DepositsFacade — read-only writes', () => {
183
+ const readOnly = (): Kasu => Kasu.create({ chain: 'base' });
184
+ const READ_ONLY_MESSAGE =
185
+ 'Kasu: this instance is read-only; call kasu.connect(signer) first';
186
+
187
+ it('refuses deposit before touching the contract', async () => {
188
+ await expect(
189
+ readOnly().deposits.deposit({
190
+ poolId: '0xpool',
191
+ trancheId: '0xtranche',
192
+ amount: 1,
193
+ kycSignature: { blockExpiration: 0, signature: '0x' },
194
+ }),
195
+ ).rejects.toThrow(READ_ONLY_MESSAGE);
196
+ });
197
+
198
+ it('refuses withdraw', async () => {
199
+ await expect(
200
+ readOnly().deposits.withdraw({
201
+ poolId: '0xpool',
202
+ trancheId: '0xtranche',
203
+ amount: 1,
204
+ }),
205
+ ).rejects.toThrow(READ_ONLY_MESSAGE);
206
+ });
207
+
208
+ it('refuses withdrawMax', async () => {
209
+ await expect(
210
+ readOnly().deposits.withdrawMax('0xpool', '0xtranche', '0xuser'),
211
+ ).rejects.toThrow(READ_ONLY_MESSAGE);
212
+ });
213
+
214
+ it('lets a connected instance past the guard', () => {
215
+ const connected = readOnly().connect(signer());
216
+ // Reaches the contract call (and fails there on a fake address) rather
217
+ // than being refused up front. Probing the guard directly keeps the
218
+ // assertion off the network.
219
+ const guard = connected.deposits as unknown as {
220
+ assertWritable(): void;
221
+ };
222
+ expect(() => {
223
+ guard.assertWritable();
224
+ }).not.toThrow();
225
+ });
226
+ });
227
+
228
+ describe('Kasu.create — a ChainConfigEntry written before 2.5.0', () => {
229
+ // kasu-app-admin hand-builds one of these for base-sepolia. TypeScript will
230
+ // ask it for `stableAsset` and `rpcUrls` on bump; the runtime must not
231
+ // crash first.
232
+ const legacy = (): ChainConfigEntry =>
233
+ ({
234
+ chainId: 84532,
235
+ name: 'base-sepolia',
236
+ isLiteDeployment: false,
237
+ contracts: BASE_CONTRACTS,
238
+ subgraphUrl: 'https://example.invalid/subgraph',
239
+ // Non-empty: `SdkConfig` documents `directusUrl` as optional, but
240
+ // `createDirectus('')` throws `TypeError: Invalid URL`. Pre-existing,
241
+ // and unrelated to what this test covers.
242
+ directusUrl: 'https://example.invalid/directus/',
243
+ unusedPoolIds: [''],
244
+ }) as unknown as ChainConfigEntry;
245
+
246
+ it('constructs with an explicit provider and falls back to 6 decimals', () => {
247
+ const kasu = Kasu.create({
248
+ chain: legacy(),
249
+ signerOrProvider: new providers.StaticJsonRpcProvider(
250
+ 'https://example.invalid/rpc',
251
+ 84532,
252
+ ),
253
+ });
254
+ const config = (
255
+ kasu.services.DataService as unknown as { _kasuConfig: SdkConfig }
256
+ )._kasuConfig;
257
+ expect(config.stableAssetDecimals).toBe(6);
258
+ });
259
+
260
+ it('refuses a read-only create with the same message a retired chain gives', () => {
261
+ expect(() => Kasu.create({ chain: legacy() })).toThrow(
262
+ 'Kasu.create: chain "base-sepolia" has no default RPC (retired); pass signerOrProvider',
263
+ );
264
+ });
265
+ });
@@ -14,8 +14,30 @@ export class DepositsFacade {
14
14
  constructor(
15
15
  private _userLending: UserLending,
16
16
  private _chainId: string,
17
+ /**
18
+ * True when the SDK holds a Provider rather than a Signer. Optional and
19
+ * defaulting to false so constructing this facade directly keeps
20
+ * working; `Kasu` always passes it.
21
+ */
22
+ private _isReadOnly = false,
17
23
  ) {}
18
24
 
25
+ /**
26
+ * Refuse a write BEFORE touching the contract.
27
+ *
28
+ * ethers would throw its own "sending a transaction requires a signer" a
29
+ * few frames deeper, after the params have been encoded — a message that
30
+ * says nothing about how to get a signer onto THIS object. Failing here
31
+ * names the fix.
32
+ */
33
+ private assertWritable(): void {
34
+ if (this._isReadOnly) {
35
+ throw new Error(
36
+ 'Kasu: this instance is read-only; call kasu.connect(signer) first',
37
+ );
38
+ }
39
+ }
40
+
19
41
  /**
20
42
  * Submit a deposit request.
21
43
  *
@@ -34,6 +56,7 @@ export class DepositsFacade {
34
56
  * ```
35
57
  */
36
58
  async deposit(params: DepositParams): Promise<ContractTransaction> {
59
+ this.assertWritable();
37
60
  return await this._userLending.requestDepositWithKyc(
38
61
  params.poolId,
39
62
  params.trancheId,
@@ -50,6 +73,7 @@ export class DepositsFacade {
50
73
  * Submit a withdrawal request for a specific stable asset amount.
51
74
  */
52
75
  async withdraw(params: WithdrawParams): Promise<ContractTransaction> {
76
+ this.assertWritable();
53
77
  return await this._userLending.requestWithdrawalInAsset(
54
78
  params.poolId,
55
79
  params.trancheId,
@@ -65,6 +89,7 @@ export class DepositsFacade {
65
89
  trancheId: string,
66
90
  userAddress: string,
67
91
  ): Promise<ContractTransaction> {
92
+ this.assertWritable();
68
93
  return await this._userLending.requestWithdrawalMax(
69
94
  poolId,
70
95
  trancheId,
@@ -1,8 +1,20 @@
1
- import { CHAIN_CONFIGS } from '../facade/chain-configs';
2
- import { DepositsFacade } from '../facade/deposits';
3
- import { Kasu } from '../facade/kasu';
4
- import { StrategiesFacade } from '../facade/strategies';
5
- import { PortfolioFacade } from '../facade/user-portfolio';
1
+ /**
2
+ * Offline facade specs — a mock provider and pure helpers, no network. Moved
3
+ * here from `src/tests/` so it runs beside the code it covers, and so the
4
+ * opt-in `LIVE_TESTS` gate on `src/tests/` does not take it out of CI.
5
+ */
6
+ import { DataService } from '../services/DataService/data-service';
7
+ import { NO_DIRECTUS_URL_MESSAGE } from '../services/DataService/directus-client';
8
+ import { Portfolio } from '../services/Portfolio/portfolio';
9
+ import { UserRequestStatus } from '../services/UserLending/subgraph-types';
10
+ import { UserRequest } from '../services/UserLending/types';
11
+ import { UserLending } from '../services/UserLending/user-lending';
12
+
13
+ import { CHAIN_CONFIGS } from './chain-configs';
14
+ import { DepositsFacade } from './deposits';
15
+ import { Kasu } from './kasu';
16
+ import { StrategiesFacade } from './strategies';
17
+ import { PortfolioFacade } from './user-portfolio';
6
18
 
7
19
  // ---------------------------------------------------------------------------
8
20
  // Chain configs
@@ -47,6 +59,18 @@ describe('CHAIN_CONFIGS', () => {
47
59
  }
48
60
  });
49
61
 
62
+ it('plume points at the LEGACY goldsky project its frozen history is on', () => {
63
+ // Plume was indexed before the live chains moved to the current
64
+ // project; the same path under that project returns HTTP 404, so the
65
+ // retired deployment's history is only readable at this spelling —
66
+ // note the `/gn` suffix the current project's URLs do not carry.
67
+ const projectOf = (url: string): string => url.split('/')[5] ?? '';
68
+ expect(projectOf(CHAIN_CONFIGS.plume.subgraphUrl)).not.toBe(
69
+ projectOf(CHAIN_CONFIGS.base.subgraphUrl),
70
+ );
71
+ expect(CHAIN_CONFIGS.plume.subgraphUrl.endsWith('/gn')).toBe(true);
72
+ });
73
+
50
74
  it('xdc should have poolMetadataMapping', () => {
51
75
  const mapping = CHAIN_CONFIGS.xdc.poolMetadataMapping;
52
76
  expect(mapping).toBeDefined();
@@ -126,6 +150,35 @@ describe('Kasu.create()', () => {
126
150
  expect(kasu).toBeInstanceOf(Kasu);
127
151
  });
128
152
 
153
+ it('constructs without a directusUrl — on-chain data does not need one', () => {
154
+ // `createDirectus('')` throws `Invalid URL`, so an SDK configured
155
+ // without the (documented-optional) CMS URL used to be
156
+ // unconstructable rather than merely CMS-less.
157
+ const kasu = Kasu.create({
158
+ chain: 'base',
159
+ signerOrProvider: mockProvider as never,
160
+ configOverrides: { directusUrl: '' },
161
+ });
162
+
163
+ expect(kasu).toBeInstanceOf(Kasu);
164
+ expect(kasu.services.DataService).toBeDefined();
165
+ expect(kasu.services.UserLending).toBeDefined();
166
+ });
167
+
168
+ it('refuses a CMS-only call clearly when no directusUrl is configured', async () => {
169
+ const kasu = Kasu.create({
170
+ chain: 'base',
171
+ signerOrProvider: mockProvider as never,
172
+ configOverrides: { directusUrl: '' },
173
+ });
174
+
175
+ // A sentence naming what to configure, not a null dereference thrown
176
+ // from inside the vendor SDK.
177
+ await expect(
178
+ kasu.services.DataService.getPlatformOverview(),
179
+ ).rejects.toThrow(NO_DIRECTUS_URL_MESSAGE);
180
+ });
181
+
129
182
  it('should expose the underlying KasuSdk via .services', () => {
130
183
  const kasu = Kasu.create({
131
184
  chain: 'base',
@@ -196,6 +249,59 @@ describe('StrategiesFacade.calculateDepositLimits()', () => {
196
249
  });
197
250
  });
198
251
 
252
+ // ---------------------------------------------------------------------------
253
+ // PortfolioFacade.getRequestStates()
254
+ // ---------------------------------------------------------------------------
255
+
256
+ describe('PortfolioFacade.getRequestStates()', () => {
257
+ it('maps the transaction history through deriveRequestState', async () => {
258
+ const requests: UserRequest[] = [
259
+ makeUserRequest({ id: 'req-1' }),
260
+ makeUserRequest({
261
+ id: 'req-2',
262
+ requestType: 'Withdrawal',
263
+ status: UserRequestStatus.PROCESSED,
264
+ canCancel: false,
265
+ acceptedAmount: '100',
266
+ }),
267
+ ];
268
+ const userLending = {
269
+ getCurrentEpoch: (): Promise<string> => Promise.resolve('42'),
270
+ getUserRequests: (): Promise<UserRequest[]> =>
271
+ Promise.resolve(requests),
272
+ } as unknown as UserLending;
273
+
274
+ const facade = new PortfolioFacade(
275
+ {} as unknown as DataService,
276
+ userLending,
277
+ {} as unknown as Portfolio,
278
+ );
279
+
280
+ const states = await facade.getRequestStates('0xuser');
281
+
282
+ expect(states.map((s) => s.id)).toEqual(['req-1', 'req-2']);
283
+ expect(states[0].statusCode).toBe('pending');
284
+ expect(states[0].amount).toBe(100);
285
+ expect(states[1].statusCode).toBe('complete');
286
+ expect(states[1].amount).toBe(-100);
287
+ });
288
+
289
+ it('returns an empty list for a wallet with no history', async () => {
290
+ const userLending = {
291
+ getCurrentEpoch: (): Promise<string> => Promise.resolve('42'),
292
+ getUserRequests: (): Promise<UserRequest[]> => Promise.resolve([]),
293
+ } as unknown as UserLending;
294
+
295
+ const facade = new PortfolioFacade(
296
+ {} as unknown as DataService,
297
+ userLending,
298
+ {} as unknown as Portfolio,
299
+ );
300
+
301
+ await expect(facade.getRequestStates('0xuser')).resolves.toEqual([]);
302
+ });
303
+ });
304
+
199
305
  // ---------------------------------------------------------------------------
200
306
  // Type exports — verify key facade types are importable
201
307
  // ---------------------------------------------------------------------------
@@ -243,3 +349,26 @@ function makeTranche(raw: {
243
349
  },
244
350
  } as never;
245
351
  }
352
+
353
+
354
+ function makeUserRequest(overrides: Partial<UserRequest> = {}): UserRequest {
355
+ return {
356
+ id: 'req-1',
357
+ userId: '0xuser',
358
+ lendingPool: { id: '0xpool', name: 'Pool', tranches: [{ orderId: '0' }] },
359
+ requestType: 'Deposit',
360
+ trancheId: '0xtranche',
361
+ trancheName: 'Senior',
362
+ requestedAmount: '100',
363
+ acceptedAmount: '0',
364
+ rejectedAmount: '0',
365
+ timestamp: 1_700_000_000,
366
+ status: UserRequestStatus.REQUESTED,
367
+ canCancel: true,
368
+ events: [],
369
+ nftId: '',
370
+ apy: '0',
371
+ fixedTermConfig: undefined,
372
+ ...overrides,
373
+ };
374
+ }
@@ -9,10 +9,14 @@ export { PortfolioFacade } from './user-portfolio';
9
9
  // Chain configurations
10
10
  export { CHAIN_CONFIGS } from './chain-configs';
11
11
 
12
+ // Directus-backed helpers (I/O — not part of `domain/`)
13
+ export { fetchUnusedPoolIds } from './unused-pool-ids';
14
+
12
15
  // All facade types
13
16
  export type {
14
17
  SupportedChain,
15
18
  ChainConfigEntry,
19
+ StableAsset,
16
20
  KasuOptions,
17
21
  Strategy,
18
22
  StrategyTranche,