@kasufinance/kasu-sdk 1.0.4 → 2.1.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 (77) hide show
  1. package/.claude/settings.local.json +15 -0
  2. package/CLAUDE.md +410 -0
  3. package/README.md +179 -12
  4. package/dist/bundle.cjs.js +616 -67
  5. package/dist/bundle.esm.js +612 -69
  6. package/dist/facade/chain-configs.d.ts +11 -0
  7. package/dist/facade/chain-configs.js +84 -0
  8. package/dist/facade/chain-configs.js.map +1 -0
  9. package/dist/facade/deposits.d.ts +56 -0
  10. package/dist/facade/deposits.js +87 -0
  11. package/dist/facade/deposits.js.map +1 -0
  12. package/dist/facade/index.d.ts +6 -0
  13. package/dist/facade/index.js +9 -0
  14. package/dist/facade/index.js.map +1 -0
  15. package/dist/facade/kasu.d.ts +71 -0
  16. package/dist/facade/kasu.js +101 -0
  17. package/dist/facade/kasu.js.map +1 -0
  18. package/dist/facade/strategies.d.ts +37 -0
  19. package/dist/facade/strategies.js +112 -0
  20. package/dist/facade/strategies.js.map +1 -0
  21. package/dist/facade/types.d.ts +127 -0
  22. package/dist/facade/types.js +2 -0
  23. package/dist/facade/types.js.map +1 -0
  24. package/dist/facade/user-portfolio.d.ts +35 -0
  25. package/dist/facade/user-portfolio.js +53 -0
  26. package/dist/facade/user-portfolio.js.map +1 -0
  27. package/dist/index.d.ts +9 -17
  28. package/dist/index.js +9 -16
  29. package/dist/index.js.map +1 -1
  30. package/dist/kasu-sdk.d.ts +17 -0
  31. package/dist/kasu-sdk.js +17 -0
  32. package/dist/kasu-sdk.js.map +1 -0
  33. package/dist/sdk-config.d.ts +28 -4
  34. package/dist/sdk-config.js +8 -6
  35. package/dist/sdk-config.js.map +1 -1
  36. package/dist/services/DataService/data-service.d.ts +9 -2
  37. package/dist/services/DataService/data-service.js +90 -52
  38. package/dist/services/DataService/data-service.js.map +1 -1
  39. package/dist/services/DataService/queries.d.ts +0 -1
  40. package/dist/services/DataService/queries.js +0 -8
  41. package/dist/services/DataService/queries.js.map +1 -1
  42. package/dist/services/DataService/subgraph-types.d.ts +0 -6
  43. package/dist/services/DataService/types.d.ts +0 -1
  44. package/dist/services/Locking/locking.d.ts +4 -2
  45. package/dist/services/Locking/locking.js +89 -7
  46. package/dist/services/Locking/locking.js.map +1 -1
  47. package/dist/services/Portfolio/portfolio.d.ts +1 -0
  48. package/dist/services/Portfolio/portfolio.js +9 -1
  49. package/dist/services/Portfolio/portfolio.js.map +1 -1
  50. package/dist/tests/facade.test.d.ts +1 -0
  51. package/dist/tests/facade.test.js +196 -0
  52. package/dist/tests/facade.test.js.map +1 -0
  53. package/dist/tests/sample.test.js +19 -14
  54. package/dist/tests/sample.test.js.map +1 -1
  55. package/dist/utils/deployment-mode.d.ts +6 -0
  56. package/dist/utils/deployment-mode.js +8 -0
  57. package/dist/utils/deployment-mode.js.map +1 -0
  58. package/package.json +2 -2
  59. package/src/facade/chain-configs.ts +93 -0
  60. package/src/facade/deposits.ts +102 -0
  61. package/src/facade/index.ts +26 -0
  62. package/src/facade/kasu.ts +144 -0
  63. package/src/facade/strategies.ts +119 -0
  64. package/src/facade/types.ts +168 -0
  65. package/src/facade/user-portfolio.ts +73 -0
  66. package/src/index.ts +59 -25
  67. package/src/kasu-sdk.ts +27 -0
  68. package/src/sdk-config.ts +36 -15
  69. package/src/services/DataService/data-service.ts +105 -65
  70. package/src/services/DataService/queries.ts +0 -9
  71. package/src/services/DataService/subgraph-types.ts +0 -7
  72. package/src/services/DataService/types.ts +0 -1
  73. package/src/services/Locking/locking.ts +113 -12
  74. package/src/services/Portfolio/portfolio.ts +15 -5
  75. package/src/tests/facade.test.ts +245 -0
  76. package/src/tests/sample.test.ts +7 -9
  77. package/src/utils/deployment-mode.ts +9 -0
@@ -0,0 +1,15 @@
1
+ {
2
+ "permissions": {
3
+ "allow": [
4
+ "Bash(npx tsc:*)",
5
+ "Bash(npm run build:*)",
6
+ "Bash(npm test:*)",
7
+ "Bash(find:*)",
8
+ "Bash(npx jest:*)",
9
+ "Bash(npm run rollup-build:*)",
10
+ "Bash(npm publish:*)",
11
+ "Bash(npm whoami:*)",
12
+ "Bash(npm config get:*)"
13
+ ]
14
+ }
15
+ }
package/CLAUDE.md ADDED
@@ -0,0 +1,410 @@
1
+ # CLAUDE.md
2
+
3
+ This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
4
+
5
+ ## Project Overview
6
+
7
+ `@kasufinance/kasu-sdk` is the shared TypeScript SDK for Kasu frontends. It provides:
8
+ - Contract wrappers (ethers.js v5) for all Kasu smart contracts
9
+ - Subgraph queries for pool data, user positions, and locking info
10
+ - Directus CMS integration for pool descriptions and KPIs
11
+ - Portfolio calculations (APY, yield, rewards)
12
+ - Support for both Full (Base) and Lite (XDC, Plume) deployments
13
+
14
+ **Current Version:** 2.0.0 (added Lite deployment support)
15
+
16
+ ## Build Commands
17
+
18
+ ```bash
19
+ npm install # Install dependencies
20
+ npm run build-tc # Regenerate typechain factories from ABIs
21
+ npm run build # Lint + TypeScript compile
22
+ npm run rollup-build # Build distribution bundles
23
+ npm test # Run Jest tests
24
+ npm run lint # Fix lint issues
25
+ ```
26
+
27
+ ## Architecture
28
+
29
+ ### Directory Structure
30
+
31
+ ```
32
+ src/
33
+ ├── contracts/ # Typechain-generated contract bindings
34
+ │ ├── factories/ # Contract factory classes
35
+ │ └── *.ts # Contract type definitions
36
+ ├── services/
37
+ │ ├── DataService/ # Pool data, subgraph queries, Directus
38
+ │ ├── Locking/ # KSU locking, loyalty levels, rewards
39
+ │ ├── Portfolio/ # User portfolio, balances, yields
40
+ │ ├── Swapper/ # Token swap helpers
41
+ │ └── UserLending/ # Deposit/withdraw, transaction history
42
+ ├── utils/
43
+ │ └── deployment-mode.ts # Lite/Full mode detection utility
44
+ ├── index.ts # Main exports (KasuSdk class)
45
+ └── sdk-config.ts # Configuration types and SdkConfig class
46
+ ```
47
+
48
+ ### Key Files
49
+
50
+ | File | Purpose |
51
+ |------|---------|
52
+ | `src/sdk-config.ts` | `SdkConfig` class and `ContractAddresses` interface |
53
+ | `src/index.ts` | `KasuSdk` main class, exports all services |
54
+ | `src/services/Locking/locking.ts` | KSU locking service with Lite mode guards |
55
+ | `src/services/Portfolio/portfolio.ts` | Portfolio aggregation service |
56
+ | `src/services/DataService/data-service.ts` | Subgraph + Directus data fetching |
57
+ | `src/services/UserLending/user-lending.ts` | User deposit/withdraw operations |
58
+ | `src/utils/deployment-mode.ts` | `isLiteDeployment()` utility |
59
+
60
+ ---
61
+
62
+ ## Multi-Chain Support
63
+
64
+ ### Supported Networks
65
+
66
+ | Network | Chain ID | Deployment Type | Status | Subgraph |
67
+ |---------|----------|-----------------|--------|----------|
68
+ | Base Mainnet | 8453 | Full | Production | `kasu-base/v1.0.13` |
69
+ | XDC Mainnet | 50 | Lite | WIP (frontend pending pools) | `kasu-xdc/v1.0.0` |
70
+ | Plume Mainnet | 98866 | Lite | Future | `kasu-plume/prod` |
71
+
72
+ ### Full vs Lite Deployments
73
+
74
+ **Full Deployment** (Base mainnet):
75
+ - KSU token, locking, loyalty rewards enabled
76
+ - `KSUToken` and `KasuNFTs` contract addresses required
77
+ - `isLiteDeployment: false`
78
+
79
+ **Lite Deployment** (XDC, Plume):
80
+ - No KSU token or locking features
81
+ - KYC/KYB deposits still work
82
+ - `KSUToken` and `KasuNFTs` are `undefined`
83
+ - `isLiteDeployment: true`
84
+ - Locking methods return empty/zero values
85
+ - Transaction methods throw descriptive errors
86
+
87
+ ### Feature Matrix
88
+
89
+ | Feature | Full (Base) | Lite (XDC, Plume) |
90
+ |---------|-------------|-------------------|
91
+ | KSU Token | Yes | No |
92
+ | KSU Locking | Yes | No |
93
+ | Loyalty Levels | Yes | No |
94
+ | APY Bonus | Yes | No |
95
+ | NFT Boosts | Yes | No |
96
+ | KYC/KYB Deposits | Yes | Yes |
97
+ | Lending Pools | Yes | Yes |
98
+ | Fixed Term Deposits | Yes | Yes |
99
+ | Pool Descriptions | Yes (Directus) | Yes (Directus) |
100
+
101
+ ---
102
+
103
+ ## SDK Configuration
104
+
105
+ ### ContractAddresses Interface
106
+
107
+ ```typescript
108
+ export interface ContractAddresses {
109
+ /** Only on Full deployments (Base) */
110
+ KSUToken?: string;
111
+ /** Only on Full deployments */
112
+ KasuNFTs?: string;
113
+
114
+ // Always required
115
+ IKSULocking: string;
116
+ IKSULockBonus: string;
117
+ UserManager: string;
118
+ LendingPoolManager: string;
119
+ KasuAllowList: string;
120
+ SystemVariables: string;
121
+ UserLoyaltyRewards: string;
122
+ KsuPrice: string;
123
+ ClearingCoordinator: string;
124
+ ExternalTVL: string;
125
+ }
126
+ ```
127
+
128
+ ### SdkConfigOptions Interface
129
+
130
+ ```typescript
131
+ export interface SdkConfigOptions {
132
+ subgraphUrl: string;
133
+ contracts: ContractAddresses;
134
+ directusUrl: string;
135
+ UNUSED_LENDING_POOL_IDS: string[];
136
+ isLiteDeployment?: boolean; // default: false
137
+ }
138
+ ```
139
+
140
+ ---
141
+
142
+ ## Contract Addresses by Chain
143
+
144
+ ### Base Mainnet (Chain ID: 8453)
145
+
146
+ ```
147
+ USDC: 0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913
148
+ KSUToken: 0x... (see kasu-fe-next config)
149
+ KSULocking: 0x...
150
+ LendingPoolManager: 0x...
151
+ UserManager: 0x...
152
+ KasuAllowList: 0x...
153
+ SystemVariables: 0x...
154
+ KsuPrice: 0x...
155
+ UserLoyaltyRewards: 0x...
156
+ ClearingCoordinator: 0x...
157
+ KasuNFTs: 0x...
158
+ ExternalTVL: 0x...
159
+ ```
160
+
161
+ See `kasu-fe-next/src/config/sdk/addresses-base-mainnet.json` for full addresses.
162
+
163
+ ### XDC Mainnet (Chain ID: 50)
164
+
165
+ ```
166
+ USDC: 0xfa2958cb79b0491cc627c1557f441ef849ca8eb1
167
+ KasuController: 0xe81D1C0E031da0E357928ED19aA1EbF6A2f5C904
168
+ KSULocking: 0x7fF469f8c5fba92A9051B8D28794CBb891760e81
169
+ KsuPrice: 0x666b589933965bF8B378eD973f0404b6cae0eb52
170
+ SystemVariables: 0x34d17c9DD1f31Fb34757DE923EC083601d0eDFFe
171
+ LendingPoolManager: 0xa46143db92aBe5bB1f61d13d8C1cCd50fc40Ca10
172
+ UserManager: 0x9b57dF89e59235f0481A5Fae942302c8831e1B81
173
+ KasuAllowList: 0x32c1Ff5FbBe6D28503ddc46E5001C0D13d6E9B2A
174
+ ClearingCoordinator: 0xAF0a66953Eba1c5353eB7425b398B213Bb2c6121
175
+ UserLoyaltyRewards: 0xb95834C5610A178be9065Dd1EF78258D29879CDb
176
+ ExternalTVL: 0xCCB4156964377CF36441f3775A2A800dbeCB8094
177
+ FixedTermDeposit: 0xD498baBCF8D0eC89E129fB874DAB9e4C35cD2a52
178
+ ```
179
+
180
+ See `kasu-fe-next/src/config/sdk/addresses-xdc.json` for full addresses.
181
+
182
+ ### Subgraph URLs
183
+
184
+ | Chain | URL |
185
+ |-------|-----|
186
+ | Base | `https://api.goldsky.com/api/public/project_cmgzlpxm300765np2a19421om/subgraphs/kasu-base/v1.0.13/gn` |
187
+ | XDC | `https://api.goldsky.com/api/public/project_cmgzlpxm300765np2a19421om/subgraphs/kasu-xdc/v1.0.0/gn` |
188
+ | Plume | `https://api.goldsky.com/api/public/project_cmgzlpxm300765np2a19421om/subgraphs/kasu-plume/prod` |
189
+
190
+ ---
191
+
192
+ ## Lite Mode Implementation
193
+
194
+ ### Guard Pattern
195
+
196
+ When modifying services, check for Lite mode before accessing KSU-related functionality:
197
+
198
+ ```typescript
199
+ // In service constructor
200
+ this._isLiteDeployment = config.isLiteDeployment;
201
+
202
+ // In methods that return data (silent fallback)
203
+ async getUserLockedAmount(address: string): Promise<string> {
204
+ if (this._isLiteDeployment) {
205
+ return '0'; // Return safe default
206
+ }
207
+ // ... normal implementation
208
+ }
209
+
210
+ // For transaction methods (throw error)
211
+ async lockTokens(amount: BigNumber): Promise<TransactionResponse> {
212
+ if (this._isLiteDeployment) {
213
+ throw new Error('Locking is not available on Lite deployments');
214
+ }
215
+ // ... normal implementation
216
+ }
217
+ ```
218
+
219
+ ### Lite Mode Behavior by Service
220
+
221
+ **Locking Service** (47+ guard clauses):
222
+ | Method | Lite Behavior |
223
+ |--------|---------------|
224
+ | `lockKSUTokens()` | Throws error |
225
+ | `unlockKSU()` | Throws error |
226
+ | `getUserLocks()` | Returns `[]` |
227
+ | `getUserTotalLockedAmount()` | Returns `'0'` |
228
+ | `getLoyaltyLevelAndApyBonusFromRatio()` | Returns `{ loyaltyLevel: 0, apyBonus: 0 }` |
229
+ | `getClaimableRewards()` | Returns `BigNumber.from(0)` |
230
+ | `getAvailableKsuBonus()` | Returns `'0'` |
231
+ | `getKasuEpochTokenPrice()` | Returns `{ price: 0, decimals: 18 }` |
232
+
233
+ **Portfolio Service** (6+ guard clauses):
234
+ | Method | Lite Behavior |
235
+ |--------|---------------|
236
+ | `getUserNfts()` | Returns `[]` |
237
+ | `getPortfolioRewards()` | Returns zeros for KSU-related fields |
238
+
239
+ **UserLending Service** (0 guard clauses):
240
+ - All lending operations work identically on all chains
241
+ - KYC/KYB deposit flows supported
242
+
243
+ **DataService** (0 guard clauses):
244
+ - Pool data queries are chain-agnostic
245
+ - Works on any subgraph
246
+
247
+ **Swapper Service** (0 guard clauses):
248
+ - Swap operations identical across chains
249
+
250
+ ---
251
+
252
+ ## Current Integration Status
253
+
254
+ ### SDK (This Repository)
255
+
256
+ | Task | Status |
257
+ |------|--------|
258
+ | `isLiteDeployment` config flag | Done |
259
+ | Optional `KSUToken` contract address | Done |
260
+ | Optional `KasuNFTs` contract address | Done |
261
+ | Locking service Lite mode guards | Done |
262
+ | Portfolio service Lite mode guards | Done |
263
+ | README multi-chain documentation | Done |
264
+
265
+ ### Frontend (kasu-fe-next)
266
+
267
+ | Task | Status |
268
+ |------|--------|
269
+ | Chain configuration system | Done |
270
+ | Chain context provider | Done |
271
+ | Chain switcher UI | Done |
272
+ | SDK provider chain awareness | Done |
273
+ | Conditional UI rendering | Done |
274
+ | SWR cache keys with chainId | Partial |
275
+ | Block explorer links | TODO |
276
+
277
+ ### Blocking Issue: XDC Pools
278
+
279
+ XDC chain integration in the frontend is blocked because:
280
+ 1. No lending pools are deployed on XDC yet
281
+ 2. Server-side data fetching always uses Base (DEFAULT_CHAIN_ID)
282
+ 3. Frontend shows "Coming Soon to XDC" when user switches to XDC
283
+
284
+ **To enable XDC:**
285
+ 1. Deploy lending pools via kasu-contracts
286
+ 2. Remove `ChainAwareContent` wrapper in `kasu-fe-next/src/app/lending/()/layout.tsx`
287
+ 3. Test deposit/withdraw flows with Nexera KYC
288
+
289
+ ---
290
+
291
+ ## Contract ABIs
292
+
293
+ ABIs are stored in `abis/*.json`. When contract interfaces change:
294
+
295
+ 1. Copy new ABI JSON files to `abis/`
296
+ 2. Run `npm run build-tc` to regenerate typechain bindings
297
+ 3. Update service code if method signatures changed
298
+
299
+ ### ABI Files (21 total)
300
+
301
+ ```
302
+ Core Lending:
303
+ ├── ILendingPoolManager.abi.json
304
+ ├── ILendingPool.abi.json
305
+ ├── ILendingPoolTranche.abi.json
306
+ ├── ILendingPoolFactory.abi.json
307
+
308
+ KSU Locking/Rewards:
309
+ ├── IKSULocking.abi.json
310
+ ├── KSULockBonus.abi.json
311
+ ├── IUserLoyaltyRewards.abi.json
312
+ ├── IKsuPrice.abi.json
313
+
314
+ User Management:
315
+ ├── IUserManager.abi.json
316
+ ├── IKasuAllowList.abi.json
317
+
318
+ System:
319
+ ├── ISystemVariables.abi.json
320
+ ├── IClearingCoordinator.abi.json
321
+
322
+ Full Deployments Only:
323
+ ├── IKasuNFTs.abi.json
324
+
325
+ Other:
326
+ ├── IERC20Metadata.abi.json
327
+ ├── Swapper.abi.json
328
+ ├── KasuPoolExternalTVL.abi.json
329
+ └── IKasuController.abi.json
330
+ ```
331
+
332
+ ---
333
+
334
+ ## Testing
335
+
336
+ ```bash
337
+ npm test # Run all tests
338
+ npm test -- --watch # Watch mode
339
+ npm test -- --coverage # Coverage report
340
+ ```
341
+
342
+ Tests use Jest. Test files are in `src/tests/`.
343
+
344
+ ---
345
+
346
+ ## Publishing
347
+
348
+ Version is in `package.json`. The SDK is published to npm as `@kasufinance/kasu-sdk`.
349
+
350
+ ```bash
351
+ # Before publishing:
352
+ npm run build-tc # Regenerate typechain
353
+ npm run build # Type-check + lint
354
+ npm run rollup-build # Build bundles
355
+ npm test # Run tests
356
+
357
+ # Publish:
358
+ npm version patch|minor|major
359
+ npm publish
360
+ ```
361
+
362
+ ---
363
+
364
+ ## Related Repositories
365
+
366
+ | Repository | Path | Relationship |
367
+ |------------|------|--------------|
368
+ | `kasu-fe-next` | `/Users/kirilivanov/DEV/Kasu/kasu-fe-next` | Main consumer - imports SDK for all contract/data interactions |
369
+ | `kasu-contracts` | `/Users/kirilivanov/DEV/Kasu/kasu-contracts` | Source of ABIs and contract logic |
370
+ | `kasu-subgraph` | `/Users/kirilivanov/DEV/Kasu/kasu-subgraph` | Source of subgraph schema and queries |
371
+
372
+ ---
373
+
374
+ ## Adding a New Chain
375
+
376
+ 1. **Determine deployment type**: Full (has KSU token) or Lite (no KSU token)
377
+
378
+ 2. **Deploy contracts** via kasu-contracts:
379
+ - For Lite: Deploy all contracts except KSU, KasuNFTs
380
+ - Record addresses in `.openzeppelin/<chain>-addresses.json`
381
+
382
+ 3. **Deploy subgraph** via kasu-subgraph:
383
+ - Create chain config in `src/config/<chain>.json`
384
+ - Deploy to Goldsky
385
+ - Note subgraph URL
386
+
387
+ 4. **No SDK changes needed** if contracts match existing ABIs:
388
+ - SDK already supports `isLiteDeployment` flag
389
+ - Just configure frontend with new chain config
390
+
391
+ 5. **Frontend changes** (in kasu-fe-next):
392
+ - Add chain to `src/config/chains/index.ts`
393
+ - Add contract addresses to `src/config/sdk/addresses-<chain>.json`
394
+ - Chain switcher will automatically include new chain
395
+
396
+ 6. **If new ABIs needed**:
397
+ - Copy ABIs to `abis/`
398
+ - Run `npm run build-tc`
399
+ - Update services if signatures changed
400
+ - Publish new SDK version
401
+
402
+ ---
403
+
404
+ ## XDC Multisig Addresses
405
+
406
+ | Role | Address |
407
+ |------|---------|
408
+ | Kasu Multisig | `0x1E9ed74140DA7B81a1612AA5df33F98Eb5Ea0B4D` |
409
+ | Pool Manager Multisig | `0x21567eA21b14BEd14657e9725C2FE11C7be942B1` |
410
+ | Pool Admin Multisig | `0x880Aa2d6eEC5bD573059444cF1b3C09658f8c112` |
package/README.md CHANGED
@@ -33,9 +33,92 @@ on it (or install it alongside the SDK).
33
33
  `Provider` for read-only usage. The SDK does not create its own provider,
34
34
  so you are free to reuse whatever the dapp already uses.
35
35
 
36
- ## Configuring the SDK
36
+ ## Integrator Quick Start
37
37
 
38
- The `SdkConfig` object wires the SDK to the right contracts and backends:
38
+ The simplest way to use the SDK is via the `Kasu` facade, which bundles built-in
39
+ chain configs and provides three domain-specific interfaces:
40
+
41
+ ```ts
42
+ import { JsonRpcProvider } from '@ethersproject/providers';
43
+ import { Kasu } from '@kasufinance/kasu-sdk';
44
+
45
+ const provider = new JsonRpcProvider('https://mainnet.base.org');
46
+ const kasu = Kasu.create({ chain: 'base', signerOrProvider: provider });
47
+
48
+ // 1. Browse lending strategies
49
+ const strategies = await kasu.strategies.getAll();
50
+ for (const s of strategies) {
51
+ console.log(s.name, `${(s.apy * 100).toFixed(1)}% APY`, `TVL: $${s.tvl.total}`);
52
+ }
53
+
54
+ // 2. Get a single strategy and check deposit limits
55
+ const strategy = await kasu.strategies.getById(poolId);
56
+ const limits = kasu.strategies.calculateDepositLimits(strategy.tranches[0]);
57
+ console.log(`Min: ${limits.min} USDC, Max: ${limits.max} USDC`);
58
+
59
+ // 3. Deposit (requires a Signer and KYC signature from Nexera)
60
+ const kycParams = kasu.deposits.buildKycParams('0xYourAddress...');
61
+ // ... obtain kycSignature via your backend + Nexera signing service ...
62
+ const tx = await kasu.deposits.deposit({
63
+ poolId: strategy.id,
64
+ trancheId: strategy.tranches[0].id,
65
+ amount: parseUnits('1000', 6), // 1000 USDC
66
+ kycSignature: { blockExpiration, signature },
67
+ });
68
+
69
+ // 4. Check user positions and yield
70
+ const positions = await kasu.portfolio.getPositions('0xUserAddress...');
71
+ console.log(positions.summary.current.totalLendingPoolInvestments);
72
+
73
+ // 5. Withdraw
74
+ const withdrawTx = await kasu.deposits.withdraw({
75
+ poolId: strategy.id,
76
+ trancheId: strategy.tranches[0].id,
77
+ amount: parseUnits('500', 6),
78
+ });
79
+ ```
80
+
81
+ ### Supported chains
82
+
83
+ | Chain | Usage | Deployment Type |
84
+ |-------|-------|-----------------|
85
+ | Base | `Kasu.create({ chain: 'base', ... })` | Full (KSU + lending) |
86
+ | XDC | `Kasu.create({ chain: 'xdc', ... })` | Lite (lending only) |
87
+ | Plume | `Kasu.create({ chain: 'plume', ... })` | Lite (lending only) |
88
+
89
+ You can also provide a custom `ChainConfigEntry` instead of a chain name:
90
+
91
+ ```ts
92
+ const kasu = Kasu.create({
93
+ chain: { chainId: 123, name: 'MyChain', isLiteDeployment: true, contracts: { ... }, ... },
94
+ signerOrProvider: provider,
95
+ });
96
+ ```
97
+
98
+ ### Facade API overview
99
+
100
+ | Facade | Methods | Purpose |
101
+ |--------|---------|---------|
102
+ | `kasu.strategies` | `getAll()`, `getById()`, `getPlatformStats()`, `calculateDepositLimits()` | Browse pools, APY, capacity |
103
+ | `kasu.deposits` | `deposit()`, `withdraw()`, `withdrawMax()`, `buildKycParams()`, `isClearingPending()` | Submit transactions |
104
+ | `kasu.portfolio` | `getPositions()`, `getTransactionHistory()` | User balances, yield, history |
105
+
106
+ For advanced use cases (locking, swaps, NFTs), access the underlying services directly:
107
+
108
+ ```ts
109
+ const locks = await kasu.services.Locking.getUserLocks('0x...');
110
+ ```
111
+
112
+ ---
113
+
114
+ ## Low-level SDK Configuration
115
+
116
+ The sections below show how to configure the SDK manually using `SdkConfig` and
117
+ `KasuSdk` directly. Most integrators should use the `Kasu` facade above instead.
118
+
119
+ ### Full Deployment (Base)
120
+
121
+ Full deployments have all features including KSU token, locking, and loyalty rewards:
39
122
 
40
123
  ```ts
41
124
  import { JsonRpcProvider } from '@ethersproject/providers';
@@ -46,9 +129,9 @@ global.XMLHttpRequest = XMLHttpRequest; // required on Node runtimes
46
129
 
47
130
  const provider = new JsonRpcProvider(process.env.RPC_URL!, { skipFetchSetup: true });
48
131
 
49
- const config: SdkConfig = {
132
+ const config = new SdkConfig({
50
133
  contracts: {
51
- KSUToken: '0x…',
134
+ KSUToken: '0x…', // Required for Full deployment
52
135
  IKSULocking: '0x…',
53
136
  IKSULockBonus: '0x…',
54
137
  UserManager: '0x…',
@@ -58,25 +141,84 @@ const config: SdkConfig = {
58
141
  UserLoyaltyRewards: '0x…',
59
142
  KsuPrice: '0x…',
60
143
  ClearingCoordinator: '0x…',
61
- KasuNFTs: '0x…',
144
+ KasuNFTs: '0x…', // Required for Full deployment
62
145
  ExternalTVL: '0x…',
63
146
  },
64
- // If certain pools should be hidden from users, provide their ids. Empty string
65
- // keeps the Graph queries happy when nothing is filtered out.
66
147
  UNUSED_LENDING_POOL_IDS: [''],
67
148
  directusUrl: 'https://kasu-finance.directus.app/',
68
- subgraphUrl: 'https://subgraph.satsuma-prod.com/.../api',
69
- plumeSubgraphUrl: 'https://api.goldsky.com/.../kasu-plume/prod/gn',
70
- };
149
+ subgraphUrl: 'https://api.goldsky.com/.../kasu-base/v1/gn',
150
+ isLiteDeployment: false, // Full deployment (default)
151
+ });
152
+
153
+ export const kasuSdk = new KasuSdk(config, provider);
154
+ ```
155
+
156
+ ### Lite Deployment (XDC, Plume)
157
+
158
+ Lite deployments don't have KSU token, locking, or loyalty features. They still support
159
+ KYC/KYB gated deposits and all lending pool functionality:
160
+
161
+ ```ts
162
+ const config = new SdkConfig({
163
+ contracts: {
164
+ // KSUToken: undefined, // Not available on Lite
165
+ IKSULocking: '0x…', // Lite version contract
166
+ IKSULockBonus: '0x…', // Lite version contract
167
+ UserManager: '0x…', // Lite version contract
168
+ LendingPoolManager: '0x…',
169
+ KasuAllowList: '0x…',
170
+ SystemVariables: '0x…',
171
+ UserLoyaltyRewards: '0x…', // Lite version contract
172
+ KsuPrice: '0x…', // Lite version contract
173
+ ClearingCoordinator: '0x…',
174
+ // KasuNFTs: undefined, // Not available on Lite
175
+ ExternalTVL: '0x…',
176
+ },
177
+ UNUSED_LENDING_POOL_IDS: [''],
178
+ directusUrl: 'https://kasu-finance.directus.app/',
179
+ subgraphUrl: 'https://api.goldsky.com/.../kasu-xdc/v1.0.0/gn',
180
+ isLiteDeployment: true, // Lite deployment - disables KSU features
181
+ });
71
182
 
72
183
  export const kasuSdk = new KasuSdk(config, provider);
73
184
  ```
74
185
 
186
+ ### Multi-Chain Configuration
187
+
188
+ For frontends supporting multiple chains, create a config per chain:
189
+
190
+ ```ts
191
+ // config/chains.ts
192
+ const chainConfigs = {
193
+ base: {
194
+ chainId: 8453,
195
+ subgraphUrl: 'https://api.goldsky.com/.../kasu-base/v1/gn',
196
+ isLiteDeployment: false,
197
+ contracts: { /* Base contract addresses */ },
198
+ },
199
+ xdc: {
200
+ chainId: 50,
201
+ subgraphUrl: 'https://api.goldsky.com/.../kasu-xdc/v1.0.0/gn',
202
+ isLiteDeployment: true,
203
+ contracts: { /* XDC contract addresses */ },
204
+ },
205
+ };
206
+
207
+ // Create SDK for current chain
208
+ const chainConfig = chainConfigs[currentChain];
209
+ const config = new SdkConfig({
210
+ ...chainConfig,
211
+ directusUrl: 'https://kasu-finance.directus.app/',
212
+ UNUSED_LENDING_POOL_IDS: [''],
213
+ });
214
+ const sdk = new KasuSdk(config, provider);
215
+ ```
216
+
75
217
  See `kasu-fe-next/src/config/sdk` in the Kasu frontend repository for full
76
218
  mainnet and testnet examples, including how Kasu fetches unused pool ids before
77
219
  instantiating the SDK.
78
220
 
79
- ## Quick start
221
+ ### Low-level Quick start
80
222
 
81
223
  ```ts
82
224
  import { JsonRpcProvider } from '@ethersproject/providers';
@@ -91,7 +233,7 @@ const userSummary = await sdk.Portfolio.getPortfolioSummary(userAddress);
91
233
  await sdk.Locking.lockKSUTokens(amountBn, lockPeriodBn); // signer required
92
234
  ```
93
235
 
94
- The SDK exposes services as properties on `KasuSdk`. Each service contains the
236
+ `KasuSdk` exposes services as properties. Each service contains the
95
237
  methods for a single protocol facet:
96
238
 
97
239
  | Service | Purpose |
@@ -106,6 +248,23 @@ Every method is fully typed, so your editor can discover the shape of responses
106
248
  (`PoolOverview`, `LockPeriod`, `PortfolioRewards`, etc.) without digging into
107
249
  the implementation.
108
250
 
251
+ ## Lite Deployment Behavior
252
+
253
+ When `isLiteDeployment: true` is set in the config, the SDK gracefully handles
254
+ missing KSU-related functionality:
255
+
256
+ | Service Method | Full Deployment | Lite Deployment |
257
+ |----------------|-----------------|-----------------|
258
+ | `Locking.lockKSUTokens()` | Works normally | Throws error |
259
+ | `Locking.getUserTotalLockedAmount()` | Returns locked amount | Returns `'0'` |
260
+ | `Locking.getLoyaltyLevelAndApyBonusFromRatio()` | Calculates level | Returns level 0, 0% bonus |
261
+ | `Locking.getKasuEpochTokenPrice()` | Returns current price | Returns `{ price: 0, decimals: 18 }` |
262
+ | `Portfolio.getUserNfts()` | Returns NFT ids | Returns `[]` |
263
+ | `Portfolio.getPortfolioRewards()` | Returns rewards | Returns zeros |
264
+
265
+ **UI Implications**: Frontends should hide KSU-related UI elements (locking panel,
266
+ loyalty badges, KSU rewards) when `config.isLiteDeployment` is true.
267
+
109
268
  ### Working with pool filters
110
269
 
111
270
  Many queries accept a list of pool ids to ignore (see `UNUSED_LENDING_POOL_IDS`
@@ -136,6 +295,14 @@ npm test
136
295
  These are the same steps executed by the release workflow before publishing to
137
296
  npm.
138
297
 
298
+ ## Networks
299
+
300
+ | Network | Chain ID | Deployment Type | Subgraph |
301
+ |---------|----------|-----------------|----------|
302
+ | Base | 8453 | Full | `kasu-base/v1` |
303
+ | XDC | 50 | Lite | `kasu-xdc/v1.0.0` |
304
+ | Plume | 98866 | Lite | `kasu-plume/prod` |
305
+
139
306
  ## Support
140
307
  For questions, issues, or contributions:
141
308
  - GitHub Issues: [Create an issue](https://github.com/kasufinance/kasu-sdk/issues)