@kasufinance/kasu-sdk 2.1.0 → 2.2.1

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 (37) hide show
  1. package/dist/bundle.cjs.js +69 -27
  2. package/dist/bundle.esm.js +69 -27
  3. package/dist/facade/chain-configs.d.ts +1 -1
  4. package/dist/facade/chain-configs.js +23 -0
  5. package/dist/facade/chain-configs.js.map +1 -1
  6. package/dist/facade/deposits.d.ts +2 -2
  7. package/dist/facade/deposits.js +3 -3
  8. package/dist/facade/deposits.js.map +1 -1
  9. package/dist/facade/types.d.ts +9 -9
  10. package/dist/sdk-config.d.ts +6 -0
  11. package/dist/sdk-config.js +2 -1
  12. package/dist/sdk-config.js.map +1 -1
  13. package/dist/services/DataService/data-service.js +1 -1
  14. package/dist/services/DataService/data-service.js.map +1 -1
  15. package/dist/services/Locking/locking.d.ts +5 -1
  16. package/dist/services/Locking/locking.js +25 -13
  17. package/dist/services/Locking/locking.js.map +1 -1
  18. package/dist/services/Locking/types.d.ts +1 -1
  19. package/dist/services/Portfolio/portfolio.d.ts +2 -2
  20. package/dist/services/Portfolio/portfolio.js +6 -6
  21. package/dist/services/Portfolio/portfolio.js.map +1 -1
  22. package/dist/services/Portfolio/types.d.ts +2 -2
  23. package/dist/services/UserLending/user-lending.d.ts +3 -1
  24. package/dist/services/UserLending/user-lending.js +9 -3
  25. package/dist/services/UserLending/user-lending.js.map +1 -1
  26. package/package.json +1 -1
  27. package/src/facade/chain-configs.ts +26 -1
  28. package/src/facade/deposits.ts +3 -3
  29. package/src/facade/types.ts +9 -9
  30. package/src/sdk-config.ts +7 -0
  31. package/src/services/DataService/data-service.ts +1 -1
  32. package/src/services/Locking/locking.ts +28 -13
  33. package/src/services/Locking/types.ts +1 -1
  34. package/src/services/Portfolio/portfolio.ts +6 -6
  35. package/src/services/Portfolio/types.ts +2 -2
  36. package/src/services/UserLending/user-lending.ts +13 -4
  37. package/.claude/settings.local.json +0 -15
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kasufinance/kasu-sdk",
3
- "version": "2.1.0",
3
+ "version": "2.2.1",
4
4
  "description": "",
5
5
  "main": "dist/bundle.cjs.js",
6
6
  "module": "dist/bundle.esm.js",
@@ -9,7 +9,7 @@ import { ChainConfigEntry } from './types';
9
9
  * const base = CHAIN_CONFIGS.base;
10
10
  * ```
11
11
  */
12
- export const CHAIN_CONFIGS: Record<'base' | 'xdc' | 'plume', ChainConfigEntry> = {
12
+ export const CHAIN_CONFIGS: Record<'base' | 'xdc' | 'xdc-usdc' | 'plume', ChainConfigEntry> = {
13
13
  base: {
14
14
  chainId: 8453,
15
15
  name: 'Base Mainnet',
@@ -67,6 +67,31 @@ export const CHAIN_CONFIGS: Record<'base' | 'xdc' | 'plume', ChainConfigEntry> =
67
67
  },
68
68
  },
69
69
 
70
+ 'xdc-usdc': {
71
+ chainId: 50,
72
+ name: 'XDC Mainnet (USDC)',
73
+ isLiteDeployment: true,
74
+ contracts: {
75
+ // No KSUToken on Lite deployments
76
+ IKSULocking: '0x47e7C147955FAC86c4AeAe5a8691C1A702A9C4FA',
77
+ IKSULockBonus: '0xe99c77d800E1065f2f1Ab23A6D70cBc7D1102943',
78
+ LendingPoolManager: '0x5ba223175F61221fbc795F71a41f52Bff825C68b',
79
+ UserManager: '0xFd407a09049C4d60a81C708E5587B8C7b6Cf6BdD',
80
+ KasuAllowList: '0xaf911547FD38686a88fc26B2A722F870426bCD6D',
81
+ SystemVariables: '0xb73Ebe67c8597d55A5F4FCc2C1638eDd5512BfBb',
82
+ KsuPrice: '0xA622DE9d439C05266C63EfeA3B7853792aD61f45',
83
+ UserLoyaltyRewards: '0x8e2033DcF9C6D3B9D3B24C651a03c0Af65A113b8',
84
+ ClearingCoordinator: '0x84022117eAD4C22D8A01bC7Fc9743dd101C6a882',
85
+ // No KasuNFTs on Lite deployments
86
+ ExternalTVL: '0xb2367F0B074Ec1788b28283A8af953aaA498d779',
87
+ },
88
+ subgraphUrl:
89
+ 'https://api.goldsky.com/api/public/project_cmgzlpxm300765np2a19421om/subgraphs/kasu-xdc-usdc/v1.0.0/gn',
90
+ directusUrl: 'https://kasu-finance.directus.app/',
91
+ unusedPoolIds: [],
92
+ poolMetadataMapping: undefined,
93
+ },
94
+
70
95
  plume: {
71
96
  chainId: 98866,
72
97
  name: 'Plume Mainnet',
@@ -28,7 +28,7 @@ export class DepositsFacade {
28
28
  * const tx = await kasu.deposits.deposit({
29
29
  * poolId: '0x...',
30
30
  * trancheId: '0x...',
31
- * amount: parseUnits('1000', 6),
31
+ * amount: parseUnits('1000', 6), // 6 decimals for USDC/AUDD; use token's actual decimals
32
32
  * kycSignature: { blockExpiration, signature },
33
33
  * });
34
34
  * ```
@@ -47,10 +47,10 @@ export class DepositsFacade {
47
47
  }
48
48
 
49
49
  /**
50
- * Submit a withdrawal request for a specific USDC amount.
50
+ * Submit a withdrawal request for a specific stable asset amount.
51
51
  */
52
52
  async withdraw(params: WithdrawParams): Promise<ContractTransaction> {
53
- return await this._userLending.requestWithdrawalInUSDC(
53
+ return await this._userLending.requestWithdrawalInAsset(
54
54
  params.poolId,
55
55
  params.trancheId,
56
56
  params.amount,
@@ -11,7 +11,7 @@ import {
11
11
  // Chain & SDK Configuration
12
12
  // ---------------------------------------------------------------------------
13
13
 
14
- export type SupportedChain = 'base' | 'xdc' | 'plume';
14
+ export type SupportedChain = 'base' | 'xdc' | 'xdc-usdc' | 'plume';
15
15
 
16
16
  export interface ChainConfigEntry {
17
17
  chainId: number;
@@ -74,9 +74,9 @@ export interface StrategyTranche {
74
74
  apy: number;
75
75
  minApy: number;
76
76
  maxApy: number;
77
- /** Minimum deposit in USDC (ether-formatted string). */
77
+ /** Minimum deposit in stable asset units (ether-formatted string). */
78
78
  minimumDeposit: string;
79
- /** Maximum deposit in USDC (ether-formatted string). */
79
+ /** Maximum deposit in stable asset units (ether-formatted string). */
80
80
  maximumDeposit: string;
81
81
  /** Remaining tranche capacity (ether-formatted string). */
82
82
  availableCapacity: string;
@@ -101,7 +101,7 @@ export interface FixedTermOption {
101
101
  export interface DepositParams {
102
102
  poolId: string;
103
103
  trancheId: string;
104
- /** Amount in USDC base units (BigNumberish). */
104
+ /** Amount in stable asset base units (BigNumberish). */
105
105
  amount: BigNumberish;
106
106
  /** KYC signature obtained from the Nexera flow. */
107
107
  kycSignature: {
@@ -112,7 +112,7 @@ export interface DepositParams {
112
112
  depositData?: BytesLike;
113
113
  /** Fixed-term config ID. Pass `0` for variable deposits. */
114
114
  fixedTermConfigId?: BigNumberish;
115
- /** Swap calldata. Pass `'0x'` when depositing USDC directly. */
115
+ /** Swap calldata. Pass `'0x'` when depositing the stable asset directly. */
116
116
  swapData?: BytesLike;
117
117
  /** Native token value to send (e.g. for gas on some chains). Defaults to `'0'`. */
118
118
  ethValue?: string;
@@ -121,18 +121,18 @@ export interface DepositParams {
121
121
  export interface WithdrawParams {
122
122
  poolId: string;
123
123
  trancheId: string;
124
- /** USDC amount to withdraw, or `'max'` to withdraw entire balance. */
124
+ /** Stable asset amount to withdraw, or `'max'` to withdraw entire balance. */
125
125
  amount: BigNumberish;
126
126
  /** Required when `amount` is `'max'`. */
127
127
  userAddress?: string;
128
128
  }
129
129
 
130
130
  export interface DepositLimits {
131
- /** Minimum deposit (ether-formatted USDC). */
131
+ /** Minimum deposit (ether-formatted stable asset amount). */
132
132
  min: string;
133
- /** Maximum deposit (ether-formatted USDC). */
133
+ /** Maximum deposit (ether-formatted stable asset amount). */
134
134
  max: string;
135
- /** Remaining tranche capacity (ether-formatted USDC). */
135
+ /** Remaining tranche capacity (ether-formatted stable asset amount). */
136
136
  availableCapacity: string;
137
137
  }
138
138
 
package/src/sdk-config.ts CHANGED
@@ -34,6 +34,11 @@ export interface SdkConfigOptions {
34
34
  * Value: pool address in Directus / Base pool (lowercase)
35
35
  */
36
36
  poolMetadataMapping?: Record<string, string>;
37
+ /**
38
+ * Decimals of the stable asset used by lending pools (e.g. 6 for USDC/AUDD).
39
+ * @default 6
40
+ */
41
+ stableAssetDecimals?: number;
37
42
  }
38
43
 
39
44
  export class SdkConfig {
@@ -44,6 +49,7 @@ export class SdkConfig {
44
49
  UNUSED_LENDING_POOL_IDS: string[];
45
50
  isLiteDeployment: boolean;
46
51
  poolMetadataMapping: Record<string, string>;
52
+ stableAssetDecimals: number;
47
53
 
48
54
  constructor(options: SdkConfigOptions) {
49
55
  this.subgraphUrl = options.subgraphUrl;
@@ -52,5 +58,6 @@ export class SdkConfig {
52
58
  this.UNUSED_LENDING_POOL_IDS = options.UNUSED_LENDING_POOL_IDS;
53
59
  this.isLiteDeployment = options.isLiteDeployment ?? false;
54
60
  this.poolMetadataMapping = options.poolMetadataMapping ?? {};
61
+ this.stableAssetDecimals = options.stableAssetDecimals ?? 6;
55
62
  }
56
63
  }
@@ -199,7 +199,7 @@ export class DataService {
199
199
  );
200
200
 
201
201
  for (const [id, tvl] of results) {
202
- tvlMap.set(id, formatUnits(tvl, 6));
202
+ tvlMap.set(id, formatUnits(tvl, this._kasuConfig.stableAssetDecimals));
203
203
  }
204
204
  } catch (error) {
205
205
  console.error('getOffChainTvl :', error);
@@ -280,17 +280,17 @@ export class KSULocking {
280
280
  });
281
281
  const resultPromises = result.userLocks.map(async (userLock) => {
282
282
  const [, id] = userLock.id.split('-');
283
- const rKSUtoUSDCRatio = await this.getRKSUvsUSDCRatio(
283
+ const rKSUtoStableRatio = await this.getRKSUvsStableRatio(
284
284
  userLock.rKSUAmount,
285
285
  userAddress,
286
286
  );
287
287
  const loyaltyStatus =
288
- this.getLoyaltyLevelAndApyBonusFromRatio(rKSUtoUSDCRatio);
288
+ this.getLoyaltyLevelAndApyBonusFromRatio(rKSUtoStableRatio);
289
289
  return {
290
290
  id: BigNumber.from(id),
291
291
  lockedAmount: userLock.ksuAmount,
292
292
  rKSUAmount: userLock.rKSUAmount,
293
- rKSUtoUSDCRatio: rKSUtoUSDCRatio,
293
+ rKSUtoStableRatio: rKSUtoStableRatio,
294
294
  apyBonus: loyaltyStatus.apyBonus,
295
295
  loyaltyLevel: loyaltyStatus.loyaltyLevel,
296
296
  startTime: parseFloat(userLock.startTimestamp),
@@ -367,7 +367,7 @@ export class KSULocking {
367
367
  };
368
368
  }
369
369
 
370
- getLoyaltyLevelAndApyBonusFromRatio(rKSUtoUSDCRatio: number): {
370
+ getLoyaltyLevelAndApyBonusFromRatio(rKSUtoStableRatio: number): {
371
371
  loyaltyLevel: number;
372
372
  apyBonus: number;
373
373
  } {
@@ -376,15 +376,15 @@ export class KSULocking {
376
376
  return { loyaltyLevel: 0, apyBonus: 0 };
377
377
  }
378
378
 
379
- if (rKSUtoUSDCRatio < 0.01) {
379
+ if (rKSUtoStableRatio < 0.01) {
380
380
  return { loyaltyLevel: 0, apyBonus: this.apyBonuses[0] };
381
- } else if (rKSUtoUSDCRatio < 0.05) {
381
+ } else if (rKSUtoStableRatio < 0.05) {
382
382
  return { loyaltyLevel: 1, apyBonus: this.apyBonuses[1] };
383
383
  }
384
384
  return { loyaltyLevel: 2, apyBonus: this.apyBonuses[2] };
385
385
  }
386
386
 
387
- async getRKSUvsUSDCRatio(
387
+ async getRKSUvsStableRatio(
388
388
  rKSUAmount: string,
389
389
  userAddress: string,
390
390
  ): Promise<number> {
@@ -403,15 +403,25 @@ export class KSULocking {
403
403
  18,
404
404
  );
405
405
 
406
- const totalUserUsdcAmount =
406
+ const totalUserStableAmount =
407
407
  depositedAmount.toNumber() + pendingAmount.toNumber();
408
408
 
409
- const rKSUInUSDC = rKSUAmountBignumber
409
+ // Convert rKSU value to stable asset units: rKSU * ksuPrice / 1e18 / 1e(18 - stableDecimals)
410
+ const decimalDiff = 18 - this._kasuConfig.stableAssetDecimals;
411
+ const rKSUInStable = rKSUAmountBignumber
410
412
  .mul(ksuPrice)
411
413
  .div(ethers.utils.parseUnits('1', 18))
412
- .div(ethers.utils.parseUnits('1', 12));
414
+ .div(ethers.utils.parseUnits('1', decimalDiff));
413
415
 
414
- return rKSUInUSDC.toNumber() / totalUserUsdcAmount;
416
+ return rKSUInStable.toNumber() / totalUserStableAmount;
417
+ }
418
+
419
+ /** @deprecated Use `getRKSUvsStableRatio` instead. */
420
+ async getRKSUvsUSDCRatio(
421
+ rKSUAmount: string,
422
+ userAddress: string,
423
+ ): Promise<number> {
424
+ return this.getRKSUvsStableRatio(rKSUAmount, userAddress);
415
425
  }
416
426
 
417
427
  async getClaimableRewards(userAddress: string): Promise<BigNumber> {
@@ -554,7 +564,7 @@ export class KSULocking {
554
564
  };
555
565
  }
556
566
 
557
- const rewardDecimals = 6;
567
+ const rewardDecimals = this._kasuConfig.stableAssetDecimals;
558
568
 
559
569
  const claimableRewards = await this.getClaimableRewards(userAddress);
560
570
 
@@ -636,7 +646,12 @@ export class KSULocking {
636
646
  return '10.00';
637
647
  }
638
648
 
639
- getProjectedUSDC(): string {
649
+ getProjectedStableAmount(): string {
640
650
  return '20.00';
641
651
  }
652
+
653
+ /** @deprecated Use `getProjectedStableAmount` instead. */
654
+ getProjectedUSDC(): string {
655
+ return this.getProjectedStableAmount();
656
+ }
642
657
  }
@@ -25,7 +25,7 @@ export interface UserLock {
25
25
  id: BigNumber;
26
26
  lockedAmount: string;
27
27
  rKSUAmount: string;
28
- rKSUtoUSDCRatio: number;
28
+ rKSUtoStableRatio: number;
29
29
  apyBonus: number;
30
30
  startTime: EpochTimeStamp;
31
31
  endTime: EpochTimeStamp;
@@ -160,8 +160,8 @@ export class Portfolio {
160
160
  }
161
161
 
162
162
  /**
163
- * Calculate the user's weekly protocol fee share (USDC) given tranche balances/configs,
164
- * system variables and locking summary. All inputs are expected to be pre-fetched.
163
+ * Calculate the user's weekly protocol fee share (in stable asset units) given tranche
164
+ * balances/configs, system variables and locking summary. All inputs are expected to be pre-fetched.
165
165
  */
166
166
  public calculateWeeklyProtocolFees(params: {
167
167
  trancheBalances: TrancheSubgraphResult;
@@ -245,13 +245,13 @@ export class Portfolio {
245
245
 
246
246
  if (totalUserDeposits.isZero()) return 0;
247
247
 
248
- const rKSUtoUSDCRatio = await this._lockingService.getRKSUvsUSDCRatio(
248
+ const rKSUtoStableRatio = await this._lockingService.getRKSUvsStableRatio(
249
249
  userRksuAmount,
250
250
  userAddress,
251
251
  );
252
252
  const { loyaltyLevel } =
253
253
  this._lockingService.getLoyaltyLevelAndApyBonusFromRatio(
254
- rKSUtoUSDCRatio,
254
+ rKSUtoStableRatio,
255
255
  );
256
256
 
257
257
  const loyaltyRewardRate =
@@ -289,9 +289,9 @@ export class Portfolio {
289
289
  },
290
290
  protocolFees: {
291
291
  claimableBalance: {
292
- usdcAmount: lockingRewards.claimableRewards,
292
+ stableAmount: lockingRewards.claimableRewards,
293
293
  },
294
- lifeTime: { usdcAmount: lockingRewards.lifeTimeRewards },
294
+ lifeTime: { stableAmount: lockingRewards.lifeTimeRewards },
295
295
  },
296
296
  ksuLaunchBonus: { lifeTime: { ksuAmount: ksuLaunchBonus } },
297
297
  };
@@ -16,10 +16,10 @@ export interface PortfolioRewards {
16
16
  };
17
17
  protocolFees: {
18
18
  claimableBalance: {
19
- usdcAmount: string;
19
+ stableAmount: string;
20
20
  };
21
21
  lifeTime: {
22
- usdcAmount: string;
22
+ stableAmount: string;
23
23
  };
24
24
  };
25
25
  }
@@ -287,17 +287,17 @@ export class UserLending {
287
287
  );
288
288
  }
289
289
 
290
- async requestWithdrawalInUSDC(
290
+ async requestWithdrawalInAsset(
291
291
  lendingPool: string,
292
292
  tranche: string,
293
- usdcAmount: BigNumberish,
293
+ assetAmount: BigNumberish,
294
294
  ): Promise<ContractTransaction> {
295
295
  const trancheContract: ILendingPoolTrancheAbi =
296
296
  ILendingPoolTrancheAbi__factory.connect(
297
297
  tranche,
298
298
  this._signerOrProvider,
299
299
  );
300
- const shareAmount = await trancheContract.convertToShares(usdcAmount);
300
+ const shareAmount = await trancheContract.convertToShares(assetAmount);
301
301
 
302
302
  return await this._lendingPoolManagerAbi.requestWithdrawal(
303
303
  lendingPool,
@@ -306,6 +306,15 @@ export class UserLending {
306
306
  );
307
307
  }
308
308
 
309
+ /** @deprecated Use `requestWithdrawalInAsset` instead. */
310
+ async requestWithdrawalInUSDC(
311
+ lendingPool: string,
312
+ tranche: string,
313
+ amount: BigNumberish,
314
+ ): Promise<ContractTransaction> {
315
+ return this.requestWithdrawalInAsset(lendingPool, tranche, amount);
316
+ }
317
+
309
318
  async requestWithdrawalMax(
310
319
  lendingPool: string,
311
320
  tranche: string,
@@ -775,7 +784,7 @@ export class UserLending {
775
784
  return {
776
785
  poolId: lendingPool.id,
777
786
  yieldEarned:
778
- parseFloat(ethers.utils.formatUnits(balance, 6)) -
787
+ parseFloat(ethers.utils.formatUnits(balance, this._kasuConfig.stableAssetDecimals)) -
779
788
  parseFloat(totalAcceptedDeposits) -
780
789
  -parseFloat(totalAcceptedWithdrawnAmount),
781
790
  balance,
@@ -1,15 +0,0 @@
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
- }