@kasufinance/kasu-sdk 1.0.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 (219) hide show
  1. package/.eslintignore +3 -0
  2. package/.eslintrc.json +90 -0
  3. package/.github/workflows/ci.yml +0 -0
  4. package/.github/workflows/main.yml +43 -0
  5. package/.prettierignore +3 -0
  6. package/.prettierrc +28 -0
  7. package/abis/IClearingCoordinator.abi.json +410 -0
  8. package/abis/IERC20Metadata.abi.json +224 -0
  9. package/abis/IFeeManager.abi.json +66 -0
  10. package/abis/IKSULocking.abi.json +754 -0
  11. package/abis/IKasuAllowList.abi.json +455 -0
  12. package/abis/IKasuController.abi.json +423 -0
  13. package/abis/IKasuNFTs.abi.json +1523 -0
  14. package/abis/IKsuPrice.abi.json +15 -0
  15. package/abis/ILendingPool.abi.json +1431 -0
  16. package/abis/ILendingPoolFactory.abi.json +97 -0
  17. package/abis/ILendingPoolManager.abi.json +1347 -0
  18. package/abis/ILendingPoolTranche.abi.json +1317 -0
  19. package/abis/IPriceFeed.abi.json +1 -0
  20. package/abis/ISystemVariables.abi.json +431 -0
  21. package/abis/IUserLoyaltyRewards.abi.json +288 -0
  22. package/abis/IUserManager.abi.json +321 -0
  23. package/abis/KSULockBonus.abi.json +91 -0
  24. package/abis/KasuPoolExternalTVL.abi.json +812 -0
  25. package/abis/Swapper.abi.json +146 -0
  26. package/copy-abi.ps1 +15 -0
  27. package/dist/bundle.cjs.js +21646 -0
  28. package/dist/bundle.esm.js +21644 -0
  29. package/dist/contracts/IClearingCoordinatorAbi.d.ts +169 -0
  30. package/dist/contracts/IClearingCoordinatorAbi.js +1 -0
  31. package/dist/contracts/IERC20MetadataAbi.d.ts +162 -0
  32. package/dist/contracts/IERC20MetadataAbi.js +1 -0
  33. package/dist/contracts/IFeeManagerAbi.d.ts +96 -0
  34. package/dist/contracts/IFeeManagerAbi.js +1 -0
  35. package/dist/contracts/IKSULockingAbi.d.ts +466 -0
  36. package/dist/contracts/IKSULockingAbi.js +1 -0
  37. package/dist/contracts/IKasuAllowListAbi.d.ts +304 -0
  38. package/dist/contracts/IKasuAllowListAbi.js +1 -0
  39. package/dist/contracts/IKasuControllerAbi.d.ts +309 -0
  40. package/dist/contracts/IKasuControllerAbi.js +1 -0
  41. package/dist/contracts/IKasuNFTsAbi.d.ts +1121 -0
  42. package/dist/contracts/IKasuNFTsAbi.js +1 -0
  43. package/dist/contracts/IKsuPriceAbi.d.ts +42 -0
  44. package/dist/contracts/IKsuPriceAbi.js +1 -0
  45. package/dist/contracts/ILendingPoolAbi.d.ts +968 -0
  46. package/dist/contracts/ILendingPoolAbi.js +1 -0
  47. package/dist/contracts/ILendingPoolFactoryAbi.d.ts +103 -0
  48. package/dist/contracts/ILendingPoolFactoryAbi.js +1 -0
  49. package/dist/contracts/ILendingPoolManagerAbi.d.ts +779 -0
  50. package/dist/contracts/ILendingPoolManagerAbi.js +1 -0
  51. package/dist/contracts/ILendingPoolTrancheAbi.d.ts +752 -0
  52. package/dist/contracts/ILendingPoolTrancheAbi.js +1 -0
  53. package/dist/contracts/ISystemVariablesAbi.d.ts +378 -0
  54. package/dist/contracts/ISystemVariablesAbi.js +1 -0
  55. package/dist/contracts/IUserLoyaltyRewardsAbi.d.ts +248 -0
  56. package/dist/contracts/IUserLoyaltyRewardsAbi.js +1 -0
  57. package/dist/contracts/IUserManagerAbi.d.ts +270 -0
  58. package/dist/contracts/IUserManagerAbi.js +1 -0
  59. package/dist/contracts/KSULockBonusAbi.d.ts +61 -0
  60. package/dist/contracts/KSULockBonusAbi.js +1 -0
  61. package/dist/contracts/KasuPoolExternalTVLAbi.d.ts +411 -0
  62. package/dist/contracts/KasuPoolExternalTVLAbi.js +1 -0
  63. package/dist/contracts/SwapperAbi.d.ts +120 -0
  64. package/dist/contracts/SwapperAbi.js +1 -0
  65. package/dist/contracts/common.d.ts +21 -0
  66. package/dist/contracts/common.js +1 -0
  67. package/dist/contracts/factories/IClearingCoordinatorAbi__factory.d.ts +320 -0
  68. package/dist/contracts/factories/IClearingCoordinatorAbi__factory.js +423 -0
  69. package/dist/contracts/factories/IERC20MetadataAbi__factory.d.ts +178 -0
  70. package/dist/contracts/factories/IERC20MetadataAbi__factory.js +237 -0
  71. package/dist/contracts/factories/IFeeManagerAbi__factory.d.ts +59 -0
  72. package/dist/contracts/factories/IFeeManagerAbi__factory.js +79 -0
  73. package/dist/contracts/factories/IKSULockingAbi__factory.d.ts +588 -0
  74. package/dist/contracts/factories/IKSULockingAbi__factory.js +767 -0
  75. package/dist/contracts/factories/IKasuAllowListAbi__factory.d.ts +354 -0
  76. package/dist/contracts/factories/IKasuAllowListAbi__factory.js +468 -0
  77. package/dist/contracts/factories/IKasuControllerAbi__factory.d.ts +339 -0
  78. package/dist/contracts/factories/IKasuControllerAbi__factory.js +436 -0
  79. package/dist/contracts/factories/IKasuNFTsAbi__factory.d.ts +1629 -0
  80. package/dist/contracts/factories/IKasuNFTsAbi__factory.js +2108 -0
  81. package/dist/contracts/factories/IKsuPriceAbi__factory.d.ts +18 -0
  82. package/dist/contracts/factories/IKsuPriceAbi__factory.js +28 -0
  83. package/dist/contracts/factories/ILendingPoolAbi__factory.d.ts +1109 -0
  84. package/dist/contracts/factories/ILendingPoolAbi__factory.js +1444 -0
  85. package/dist/contracts/factories/ILendingPoolFactoryAbi__factory.d.ts +81 -0
  86. package/dist/contracts/factories/ILendingPoolFactoryAbi__factory.js +110 -0
  87. package/dist/contracts/factories/ILendingPoolManagerAbi__factory.d.ts +1045 -0
  88. package/dist/contracts/factories/ILendingPoolManagerAbi__factory.js +1360 -0
  89. package/dist/contracts/factories/ILendingPoolTrancheAbi__factory.d.ts +1015 -0
  90. package/dist/contracts/factories/ILendingPoolTrancheAbi__factory.js +1330 -0
  91. package/dist/contracts/factories/ISystemVariablesAbi__factory.d.ts +338 -0
  92. package/dist/contracts/factories/ISystemVariablesAbi__factory.js +444 -0
  93. package/dist/contracts/factories/IUserLoyaltyRewardsAbi__factory.d.ts +230 -0
  94. package/dist/contracts/factories/IUserLoyaltyRewardsAbi__factory.js +301 -0
  95. package/dist/contracts/factories/IUserManagerAbi__factory.d.ts +250 -0
  96. package/dist/contracts/factories/IUserManagerAbi__factory.js +334 -0
  97. package/dist/contracts/factories/KSULockBonusAbi__factory.d.ts +76 -0
  98. package/dist/contracts/factories/KSULockBonusAbi__factory.js +104 -0
  99. package/dist/contracts/factories/KasuPoolExternalTVLAbi__factory.d.ts +631 -0
  100. package/dist/contracts/factories/KasuPoolExternalTVLAbi__factory.js +825 -0
  101. package/dist/contracts/factories/SwapperAbi__factory.d.ts +120 -0
  102. package/dist/contracts/factories/SwapperAbi__factory.js +159 -0
  103. package/dist/contracts/factories/index.d.ts +18 -0
  104. package/dist/contracts/factories/index.js +21 -0
  105. package/dist/contracts/index.d.ts +37 -0
  106. package/dist/contracts/index.js +19 -0
  107. package/dist/index.d.ts +17 -0
  108. package/dist/index.js +16 -0
  109. package/dist/sdk-config.d.ts +22 -0
  110. package/dist/sdk-config.js +9 -0
  111. package/dist/services/DataService/data-service.d.ts +37 -0
  112. package/dist/services/DataService/data-service.js +586 -0
  113. package/dist/services/DataService/directus-types.d.ts +187 -0
  114. package/dist/services/DataService/directus-types.js +1 -0
  115. package/dist/services/DataService/queries.d.ts +7 -0
  116. package/dist/services/DataService/queries.js +158 -0
  117. package/dist/services/DataService/subgraph-types.d.ts +95 -0
  118. package/dist/services/DataService/subgraph-types.js +1 -0
  119. package/dist/services/DataService/types.d.ts +169 -0
  120. package/dist/services/DataService/types.js +1 -0
  121. package/dist/services/Locking/locking.d.ts +61 -0
  122. package/dist/services/Locking/locking.js +344 -0
  123. package/dist/services/Locking/queries.d.ts +10 -0
  124. package/dist/services/Locking/queries.js +108 -0
  125. package/dist/services/Locking/types.d.ts +117 -0
  126. package/dist/services/Locking/types.js +1 -0
  127. package/dist/services/Portfolio/portfolio.d.ts +22 -0
  128. package/dist/services/Portfolio/portfolio.js +325 -0
  129. package/dist/services/Portfolio/queries.d.ts +2 -0
  130. package/dist/services/Portfolio/queries.js +164 -0
  131. package/dist/services/Portfolio/types.d.ts +206 -0
  132. package/dist/services/Portfolio/types.js +1 -0
  133. package/dist/services/Swapper/swapper.d.ts +11 -0
  134. package/dist/services/Swapper/swapper.js +97 -0
  135. package/dist/services/Swapper/types.d.ts +51 -0
  136. package/dist/services/Swapper/types.js +1 -0
  137. package/dist/services/UserLending/helper.d.ts +2 -0
  138. package/dist/services/UserLending/helper.js +16 -0
  139. package/dist/services/UserLending/queries.d.ts +8 -0
  140. package/dist/services/UserLending/queries.js +188 -0
  141. package/dist/services/UserLending/subgraph-types.d.ts +147 -0
  142. package/dist/services/UserLending/subgraph-types.js +6 -0
  143. package/dist/services/UserLending/types.d.ts +102 -0
  144. package/dist/services/UserLending/types.js +13 -0
  145. package/dist/services/UserLending/user-lending.d.ts +55 -0
  146. package/dist/services/UserLending/user-lending.js +490 -0
  147. package/dist/services/shared.d.ts +1 -0
  148. package/dist/services/shared.js +11 -0
  149. package/dist/tests/sample.test.d.ts +1 -0
  150. package/dist/tests/sample.test.js +32 -0
  151. package/index.ts +2 -0
  152. package/jest-config.ts +9 -0
  153. package/jest.config.js +8 -0
  154. package/package.json +49 -0
  155. package/rollup.config.js +45 -0
  156. package/src/contracts/IClearingCoordinatorAbi.ts +406 -0
  157. package/src/contracts/IERC20MetadataAbi.ts +364 -0
  158. package/src/contracts/IFeeManagerAbi.ts +182 -0
  159. package/src/contracts/IKSULockingAbi.ts +965 -0
  160. package/src/contracts/IKasuAllowListAbi.ts +605 -0
  161. package/src/contracts/IKasuControllerAbi.ts +703 -0
  162. package/src/contracts/IKasuNFTsAbi.ts +2744 -0
  163. package/src/contracts/IKsuPriceAbi.ts +87 -0
  164. package/src/contracts/ILendingPoolAbi.ts +2081 -0
  165. package/src/contracts/ILendingPoolFactoryAbi.ts +161 -0
  166. package/src/contracts/ILendingPoolManagerAbi.ts +1917 -0
  167. package/src/contracts/ILendingPoolTrancheAbi.ts +1911 -0
  168. package/src/contracts/ISystemVariablesAbi.ts +908 -0
  169. package/src/contracts/IUserLoyaltyRewardsAbi.ts +544 -0
  170. package/src/contracts/IUserManagerAbi.ts +612 -0
  171. package/src/contracts/KSULockBonusAbi.ts +124 -0
  172. package/src/contracts/KasuPoolExternalTVLAbi.ts +1071 -0
  173. package/src/contracts/SwapperAbi.ts +266 -0
  174. package/src/contracts/common.ts +44 -0
  175. package/src/contracts/factories/IClearingCoordinatorAbi__factory.ts +438 -0
  176. package/src/contracts/factories/IERC20MetadataAbi__factory.ts +248 -0
  177. package/src/contracts/factories/IFeeManagerAbi__factory.ts +90 -0
  178. package/src/contracts/factories/IKSULockingAbi__factory.ts +778 -0
  179. package/src/contracts/factories/IKasuAllowListAbi__factory.ts +479 -0
  180. package/src/contracts/factories/IKasuControllerAbi__factory.ts +447 -0
  181. package/src/contracts/factories/IKasuNFTsAbi__factory.ts +2116 -0
  182. package/src/contracts/factories/IKsuPriceAbi__factory.ts +36 -0
  183. package/src/contracts/factories/ILendingPoolAbi__factory.ts +1455 -0
  184. package/src/contracts/factories/ILendingPoolFactoryAbi__factory.ts +125 -0
  185. package/src/contracts/factories/ILendingPoolManagerAbi__factory.ts +1375 -0
  186. package/src/contracts/factories/ILendingPoolTrancheAbi__factory.ts +1345 -0
  187. package/src/contracts/factories/ISystemVariablesAbi__factory.ts +455 -0
  188. package/src/contracts/factories/IUserLoyaltyRewardsAbi__factory.ts +316 -0
  189. package/src/contracts/factories/IUserManagerAbi__factory.ts +345 -0
  190. package/src/contracts/factories/KSULockBonusAbi__factory.ts +115 -0
  191. package/src/contracts/factories/KasuPoolExternalTVLAbi__factory.ts +840 -0
  192. package/src/contracts/factories/SwapperAbi__factory.ts +167 -0
  193. package/src/contracts/factories/index.ts +21 -0
  194. package/src/contracts/index.ts +40 -0
  195. package/src/index.ts +27 -0
  196. package/src/sdk-config.ts +35 -0
  197. package/src/services/DataService/data-service.ts +1017 -0
  198. package/src/services/DataService/directus-types.ts +199 -0
  199. package/src/services/DataService/queries.ts +165 -0
  200. package/src/services/DataService/subgraph-types.ts +104 -0
  201. package/src/services/DataService/types.ts +184 -0
  202. package/src/services/Locking/locking.ts +541 -0
  203. package/src/services/Locking/queries.ts +118 -0
  204. package/src/services/Locking/types.ts +141 -0
  205. package/src/services/Portfolio/portfolio.ts +593 -0
  206. package/src/services/Portfolio/queries.ts +166 -0
  207. package/src/services/Portfolio/types.ts +220 -0
  208. package/src/services/Swapper/swapper.ts +158 -0
  209. package/src/services/Swapper/types.ts +54 -0
  210. package/src/services/UserLending/helper.ts +28 -0
  211. package/src/services/UserLending/queries.ts +196 -0
  212. package/src/services/UserLending/subgraph-types.ts +173 -0
  213. package/src/services/UserLending/types.ts +123 -0
  214. package/src/services/UserLending/user-lending.ts +933 -0
  215. package/src/services/shared.ts +11 -0
  216. package/src/tests/sample.test.ts +44 -0
  217. package/tsconfig.json +27 -0
  218. package/tsconfig.tsbuildinfo +1 -0
  219. package/versioner.sh +6 -0
@@ -0,0 +1,490 @@
1
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
+ return new (P || (P = Promise))(function (resolve, reject) {
4
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
8
+ });
9
+ };
10
+ import { authentication, createDirectus, readItems, rest, } from '@directus/sdk';
11
+ import { BigNumber, ethers, } from 'ethers';
12
+ import { defaultAbiCoder, formatEther, formatUnits, parseEther, parseUnits, } from 'ethers/lib/utils';
13
+ import { GraphQLClient } from 'graphql-request';
14
+ import { IClearingCoordinatorAbi__factory, IKasuAllowListAbi__factory, ILendingPoolAbi__factory, ILendingPoolManagerAbi__factory, ILendingPoolTrancheAbi__factory, ISystemVariablesAbi__factory, IUserLoyaltyRewardsAbi__factory, IUserManagerAbi__factory, } from '../../contracts';
15
+ import { DataService } from '../DataService/data-service';
16
+ import { mapUserRequestEventType } from './helper';
17
+ import { currentEpochDepositedAmountQuery, currentEpochFtdAmountQuery, currentFtdBalanceQuery, lendingPoolUserDetailsQuery, portfolioUserTrancheDetailsQuery, totalUserLoyaltyRewardsQuery, trancheUserDetailsQuery, userRequestsQuery, } from './queries';
18
+ export class UserLending {
19
+ constructor(_kasuConfig, signerOrProvider) {
20
+ this._kasuConfig = _kasuConfig;
21
+ this._signerOrProvider = signerOrProvider;
22
+ this._graph = new GraphQLClient(_kasuConfig.subgraphUrl);
23
+ this._userManagerAbi = IUserManagerAbi__factory.connect(_kasuConfig.contracts.UserManager, signerOrProvider);
24
+ this._lendingPoolManagerAbi = ILendingPoolManagerAbi__factory.connect(_kasuConfig.contracts.LendingPoolManager, signerOrProvider);
25
+ this._userLoyaltyRewardsAbi = IUserLoyaltyRewardsAbi__factory.connect(_kasuConfig.contracts.UserLoyaltyRewards, signerOrProvider);
26
+ this._clearingCoordinatorAbi = IClearingCoordinatorAbi__factory.connect(_kasuConfig.contracts.ClearingCoordinator, signerOrProvider);
27
+ this._systemVariablesAbi = ISystemVariablesAbi__factory.connect(_kasuConfig.contracts.SystemVariables, signerOrProvider);
28
+ this._dataService = new DataService(_kasuConfig, signerOrProvider);
29
+ this._directus = createDirectus(_kasuConfig.directusUrl)
30
+ .with(authentication())
31
+ .with(rest());
32
+ }
33
+ getUserTotalPendingAndActiveDepositedAmount(user) {
34
+ return __awaiter(this, void 0, void 0, function* () {
35
+ return yield this._userManagerAbi.userTotalPendingAndActiveDepositedAmount(user);
36
+ });
37
+ }
38
+ getUserTotalPendingAndActiveDepositedAmountForCurrentEpoch(user) {
39
+ return __awaiter(this, void 0, void 0, function* () {
40
+ return yield this._userManagerAbi.userTotalPendingAndActiveDepositedAmountForCurrentEpoch(user);
41
+ });
42
+ }
43
+ hasUserRKSU(user) {
44
+ return __awaiter(this, void 0, void 0, function* () {
45
+ return yield this._userManagerAbi.hasUserRKSU(user);
46
+ });
47
+ }
48
+ buildKycSignatureParams(userAddress, chainId) {
49
+ const address = userAddress.toLowerCase();
50
+ return {
51
+ contractAbi: IKasuAllowListAbi__factory.abi,
52
+ contractAddress: this._kasuConfig.contracts.KasuAllowList.toLowerCase(),
53
+ functionName: 'verifyUserKyc',
54
+ args: [address],
55
+ userAddress: address,
56
+ chainId,
57
+ };
58
+ }
59
+ buildDepositSwapData(fromToken, fromAmount, routerAddress, swapCallData, minAmountOut) {
60
+ return defaultAbiCoder.encode([
61
+ 'tuple(address[], uint256[], (address, address,bytes)[], uint256)',
62
+ ], [
63
+ [
64
+ [fromToken],
65
+ [fromAmount],
66
+ [[routerAddress, fromToken, swapCallData]],
67
+ minAmountOut,
68
+ ],
69
+ ]);
70
+ }
71
+ requestDepositWithKyc(lendingPool, tranche, maxAmount, swapData, fixedTermConfigId, depositData, kycData, ethValue) {
72
+ return __awaiter(this, void 0, void 0, function* () {
73
+ return yield this._lendingPoolManagerAbi.requestDepositWithKyc(lendingPool, tranche, maxAmount, swapData, fixedTermConfigId, depositData, kycData, {
74
+ value: ethValue,
75
+ });
76
+ });
77
+ }
78
+ requestDeposit(lendingPool, tranche, amount, swapData, fixedTermConfigId, depositData) {
79
+ return __awaiter(this, void 0, void 0, function* () {
80
+ return yield this._lendingPoolManagerAbi.requestDeposit(lendingPool, tranche, amount, swapData, fixedTermConfigId, depositData);
81
+ });
82
+ }
83
+ withdrawAtExpiry(lendingPool, fixedTermDepositId) {
84
+ return __awaiter(this, void 0, void 0, function* () {
85
+ return yield this._lendingPoolManagerAbi.requestFixedTermDepositWithdrawal(lendingPool, fixedTermDepositId);
86
+ });
87
+ }
88
+ lockDepositForFixedTerm(lendingPool, tranche, amount, fixedTermConfigId) {
89
+ return __awaiter(this, void 0, void 0, function* () {
90
+ const trancheContract = ILendingPoolTrancheAbi__factory.connect(tranche, this._signerOrProvider);
91
+ const shareAmount = yield trancheContract.convertToShares(amount);
92
+ return yield this._lendingPoolManagerAbi.lockDepositForFixedTerm(lendingPool, tranche, shareAmount, fixedTermConfigId);
93
+ });
94
+ }
95
+ cancelDepositRequest(lendingPool, dNftID) {
96
+ return __awaiter(this, void 0, void 0, function* () {
97
+ return yield this._lendingPoolManagerAbi.cancelDepositRequest(lendingPool, dNftID);
98
+ });
99
+ }
100
+ requestWithdrawal(lendingPool, tranche, amount) {
101
+ return __awaiter(this, void 0, void 0, function* () {
102
+ return yield this._lendingPoolManagerAbi.requestWithdrawal(lendingPool, tranche, amount);
103
+ });
104
+ }
105
+ requestWithdrawalInUSDC(lendingPool, tranche, usdcAmount) {
106
+ return __awaiter(this, void 0, void 0, function* () {
107
+ const trancheContract = ILendingPoolTrancheAbi__factory.connect(tranche, this._signerOrProvider);
108
+ const shareAmount = yield trancheContract.convertToShares(usdcAmount);
109
+ return yield this._lendingPoolManagerAbi.requestWithdrawal(lendingPool, tranche, shareAmount);
110
+ });
111
+ }
112
+ requestWithdrawalMax(lendingPool, tranche, user) {
113
+ return __awaiter(this, void 0, void 0, function* () {
114
+ const trancheContract = ILendingPoolTrancheAbi__factory.connect(tranche, this._signerOrProvider);
115
+ const userShares = yield trancheContract['balanceOf(address)'](user);
116
+ return yield this._lendingPoolManagerAbi.requestWithdrawal(lendingPool, tranche, userShares);
117
+ });
118
+ }
119
+ cancelWithdrawalRequest(lendingPool, dNftID) {
120
+ return __awaiter(this, void 0, void 0, function* () {
121
+ return yield this._lendingPoolManagerAbi.cancelWithdrawalRequest(lendingPool, dNftID);
122
+ });
123
+ }
124
+ claimRepaidLoss(lendingPool, tranche, lossId) {
125
+ return __awaiter(this, void 0, void 0, function* () {
126
+ return yield this._lendingPoolManagerAbi.claimRepaidLoss(lendingPool, tranche, lossId);
127
+ });
128
+ }
129
+ getUserRequests(userAddress, epochId) {
130
+ return __awaiter(this, void 0, void 0, function* () {
131
+ var _a, _b;
132
+ const trancheNames = [
133
+ ['Senior'],
134
+ ['Junior', 'Senior'],
135
+ ['Junior', 'Mezzanine', 'Senior'],
136
+ ];
137
+ const [subgraphResult, directusResult] = yield Promise.all([
138
+ this._graph.request(userRequestsQuery, {
139
+ userAddress: userAddress.toLowerCase(),
140
+ unusedPools: this._kasuConfig.UNUSED_LENDING_POOL_IDS,
141
+ epochId,
142
+ }),
143
+ this._directus.request(readItems('PoolOverview', {
144
+ fields: ['id', 'poolName', 'subheading'],
145
+ })),
146
+ ]);
147
+ const retn = [];
148
+ for (const userRequest of subgraphResult.userRequests) {
149
+ const directusPool = directusResult.find(({ id }) => id === userRequest.lendingPool.id);
150
+ const trancheName = trancheNames[userRequest.lendingPool.tranches.length - 1][parseInt(userRequest.tranche.orderId)];
151
+ const events = [];
152
+ for (const event of userRequest.userRequestEvents) {
153
+ let totalRequested = '0';
154
+ let totalAccepted = '0';
155
+ let totalRejected = '0';
156
+ const eventTrancheId = event.tranche.id;
157
+ const eventTrancheName = trancheNames[userRequest.lendingPool.tranches.length - 1][parseInt(event.tranche.orderId)];
158
+ if (eventTrancheId !== userRequest.tranche.id) {
159
+ event.type = 'DepositReallocated';
160
+ }
161
+ const assetAmount = (_a = event.assetAmount) !== null && _a !== void 0 ? _a : this.convertSharesToAssets(event.sharesAmount, userRequest.tranche.balance, userRequest.tranche.shares).toString();
162
+ switch (event.type) {
163
+ case 'DepositAccepted':
164
+ case 'WithdrawalAccepted':
165
+ case 'DepositReallocated':
166
+ case 'ImmediateWithdrawalExecuted':
167
+ totalAccepted = assetAmount;
168
+ break;
169
+ case 'DepositCancelled':
170
+ case 'WithdrawalCancelled':
171
+ case 'DepositRejected':
172
+ totalRejected = assetAmount;
173
+ break;
174
+ case 'DepositInitiated':
175
+ case 'WithdrawalInitiated':
176
+ case 'DepositIncreased':
177
+ case 'WithdrawalIncreased':
178
+ totalRequested = assetAmount;
179
+ break;
180
+ }
181
+ const eventTranche = userRequest.lendingPool.configuration.tranchesConfig.find((trancheConfig) => trancheConfig.id === event.tranche.id);
182
+ // shouldn't be possible, just adding type checking here
183
+ if (!eventTranche)
184
+ continue;
185
+ const interestRate = eventTranche
186
+ .lendingPoolTrancheInterestRateUpdates.length
187
+ ? eventTranche.lendingPoolTrancheInterestRateUpdates[0]
188
+ .epochInterestRate
189
+ : eventTranche.interestRate;
190
+ const baseApy = this._dataService.calculateApyForTranche(interestRate);
191
+ events.push({
192
+ id: event.id,
193
+ requestType: mapUserRequestEventType(event.type),
194
+ timestamp: parseInt(event.createdOn),
195
+ totalRequested,
196
+ totalAccepted,
197
+ totalRejected,
198
+ assetAmount,
199
+ index: parseInt(event.index),
200
+ transactionHash: event.transactionHash,
201
+ trancheName: eventTrancheName,
202
+ trancheId: event.tranche.id,
203
+ apy: baseApy.toString(),
204
+ epochId: event.epochId,
205
+ });
206
+ }
207
+ const tranche = userRequest.lendingPool.configuration.tranchesConfig.find((trancheConfig) => trancheConfig.id === userRequest.tranche.id);
208
+ // shouldn't be possible, just adding type checking here
209
+ if (!tranche)
210
+ continue;
211
+ const interestRate = tranche.lendingPoolTrancheInterestRateUpdates
212
+ .length
213
+ ? tranche.lendingPoolTrancheInterestRateUpdates[0]
214
+ .epochInterestRate
215
+ : tranche.interestRate;
216
+ const baseApy = this._dataService.calculateApyForTranche(interestRate);
217
+ const ftdConfig = tranche.lendingPoolTrancheFixedTermConfigs.find((config) => config.configId === userRequest.fixedTermConfigId);
218
+ let fixedTermConfig;
219
+ if (ftdConfig) {
220
+ const fixedTermApy = this._dataService.calculateApyForTranche(ftdConfig.epochInterestRate);
221
+ fixedTermConfig = {
222
+ configId: ftdConfig.configId,
223
+ apy: fixedTermApy.toString(),
224
+ epochLockDuration: ftdConfig.epochLockDuration,
225
+ epochInterestRate: ftdConfig.epochInterestRate,
226
+ };
227
+ }
228
+ const poolName = (_b = directusPool === null || directusPool === void 0 ? void 0 : directusPool.poolName) !== null && _b !== void 0 ? _b : userRequest.lendingPool.name;
229
+ const userRequestBase = {
230
+ id: userRequest.id,
231
+ userId: userRequest.user.id,
232
+ lendingPool: {
233
+ id: userRequest.lendingPool.id,
234
+ name: (directusPool === null || directusPool === void 0 ? void 0 : directusPool.subheading)
235
+ ? `${poolName} - ${directusPool.subheading}`
236
+ : poolName,
237
+ tranches: userRequest.lendingPool.tranches,
238
+ },
239
+ requestType: userRequest.type === 'DepositRequest'
240
+ ? 'Deposit'
241
+ : 'Withdrawal',
242
+ trancheName: trancheName,
243
+ trancheId: userRequest.tranche.id,
244
+ requestedAmount: parseUnits(userRequest.tranche.shares).isZero()
245
+ ? userRequest.amountRequested
246
+ : this.convertSharesToAssets(userRequest.amountRequested, userRequest.tranche.balance, userRequest.tranche.shares).toString(),
247
+ acceptedAmount: userRequest.amountAccepted,
248
+ rejectedAmount: userRequest.amountRejected,
249
+ status: userRequest.status,
250
+ timestamp: parseInt(userRequest.createdOn),
251
+ canCancel: yield this.isCancelable(userRequest.status, userRequest.lendingPool.id),
252
+ nftId: userRequest.nftId,
253
+ events: events,
254
+ fixedTermConfig,
255
+ apy: baseApy.toString(),
256
+ };
257
+ retn.push(userRequestBase);
258
+ }
259
+ return retn;
260
+ });
261
+ }
262
+ getCurrentEpoch() {
263
+ return __awaiter(this, void 0, void 0, function* () {
264
+ const currentEpochNumber = yield this._systemVariablesAbi.currentEpochNumber();
265
+ return currentEpochNumber.toString();
266
+ });
267
+ }
268
+ getCurrentFtdBalance(poolId, userId) {
269
+ return __awaiter(this, void 0, void 0, function* () {
270
+ var _a;
271
+ const currentFtdBalance = yield this._graph.request(currentFtdBalanceQuery, {
272
+ userId: userId.toLowerCase(),
273
+ poolId: poolId.toLowerCase(),
274
+ });
275
+ const trancheMap = new Map();
276
+ for (const userFTD of currentFtdBalance.userLendingPoolTrancheFixedTermDepositLocks) {
277
+ const ftdID = parseFloat(userFTD.lendingPoolTrancheFixedTermConfig.configId);
278
+ const trancheID = userFTD.lendingPoolTrancheFixedTermConfig.lendingPoolTranche.id.toLowerCase();
279
+ const totalSupply = userFTD.lendingPool.tranches.reduce((total, cur) => total.add(parseEther(cur.shares)), BigNumber.from(0));
280
+ const amount = this.convertSharesToAssets(userFTD.trancheShares, userFTD.lendingPool.balance, formatEther(totalSupply));
281
+ const item = (_a = trancheMap.get(trancheID)) !== null && _a !== void 0 ? _a : [];
282
+ if (item[ftdID]) {
283
+ item[ftdID] += parseFloat(amount);
284
+ }
285
+ else {
286
+ item[ftdID] = parseFloat(amount);
287
+ }
288
+ trancheMap.set(trancheID, item);
289
+ }
290
+ return trancheMap;
291
+ });
292
+ }
293
+ getCurrentEpochFtdAmount(poolIds, userId, currentEpoch) {
294
+ return __awaiter(this, void 0, void 0, function* () {
295
+ const currentEpochFtdAmountRes = yield this._graph.request(currentEpochFtdAmountQuery, {
296
+ userId: userId.toLowerCase(),
297
+ poolIds: poolIds.map((id) => id.toLowerCase()),
298
+ currentEpoch: parseFloat(currentEpoch),
299
+ });
300
+ const currentEpochFtdAmounts = new Map();
301
+ for (const userRequest of currentEpochFtdAmountRes.userRequests) {
302
+ const ftdID = parseFloat(userRequest.fixedTermConfigId);
303
+ const item = currentEpochFtdAmounts.get(userRequest.tranche.id);
304
+ const amountRequested = this.convertSharesToAssets(userRequest.amountRequested, userRequest.tranche.balance, userRequest.tranche.shares);
305
+ if (item) {
306
+ const clonedItem = [...item];
307
+ clonedItem[ftdID] = amountRequested;
308
+ currentEpochFtdAmounts.set(userRequest.tranche.id, clonedItem);
309
+ continue;
310
+ }
311
+ const ftdAmounts = [];
312
+ ftdAmounts[ftdID] = amountRequested;
313
+ currentEpochFtdAmounts.set(userRequest.tranche.id, ftdAmounts);
314
+ }
315
+ return currentEpochFtdAmounts;
316
+ });
317
+ }
318
+ getCurrentEpochDepositedAmount(lendingPoolIds, userId) {
319
+ return __awaiter(this, void 0, void 0, function* () {
320
+ var _a;
321
+ const currentEpochDepositedAmountRes = yield this._graph.request(currentEpochDepositedAmountQuery, {
322
+ ids: lendingPoolIds.map((poolId) => `${poolId}-${userId}`),
323
+ });
324
+ const amountMap = new Map();
325
+ if (!((_a = currentEpochDepositedAmountRes.lendingPoolUserDetails_collection) === null || _a === void 0 ? void 0 : _a.length))
326
+ return amountMap;
327
+ const lendingPoolTrancheUserDetails = currentEpochDepositedAmountRes.lendingPoolUserDetails_collection.flatMap(({ lendingPoolTrancheUserDetails }) => lendingPoolTrancheUserDetails);
328
+ for (const { tranche, totalPendingDepositAmount, } of lendingPoolTrancheUserDetails) {
329
+ amountMap.set(tranche.id.toLowerCase(), totalPendingDepositAmount);
330
+ }
331
+ return amountMap;
332
+ });
333
+ }
334
+ convertSharesToAssets(sharesAmount, totalAssets, totalSupply) {
335
+ if (parseUnits(totalSupply).isZero())
336
+ return '0';
337
+ return formatUnits(parseUnits(sharesAmount)
338
+ .mul(parseUnits(totalAssets.toString()))
339
+ .div(parseUnits(totalSupply.toString())));
340
+ }
341
+ isClearingPending(poolId) {
342
+ return __awaiter(this, void 0, void 0, function* () {
343
+ return yield this._clearingCoordinatorAbi.isLendingPoolClearingPending(poolId);
344
+ });
345
+ }
346
+ isCancelable(status, lendingPoolId) {
347
+ return __awaiter(this, void 0, void 0, function* () {
348
+ if (status === 'Processed')
349
+ return false;
350
+ const isClearingPending = yield this.isClearingPending(lendingPoolId);
351
+ return !isClearingPending;
352
+ });
353
+ }
354
+ getUserPoolBalance(user, poolIds, provider) {
355
+ return __awaiter(this, void 0, void 0, function* () {
356
+ var _a;
357
+ const poolBalances = [];
358
+ for (const poolId of poolIds) {
359
+ const lendingPool = ILendingPoolAbi__factory.connect(poolId, provider !== null && provider !== void 0 ? provider : this._signerOrProvider);
360
+ if (this._kasuConfig.UNUSED_LENDING_POOL_IDS.includes(poolId.toLowerCase())) {
361
+ console.error('This pool is no longer in used');
362
+ continue;
363
+ }
364
+ poolBalances.push({
365
+ poolId,
366
+ balance: lendingPool.userBalance(user),
367
+ });
368
+ }
369
+ const [userDetailsSubgraph, balances] = yield Promise.all([
370
+ this._graph.request(lendingPoolUserDetailsQuery, {
371
+ userAddress: user.toLowerCase(),
372
+ }),
373
+ Promise.all(poolBalances.map((_a) => __awaiter(this, [_a], void 0, function* ({ balance, poolId }) {
374
+ return ({
375
+ poolId,
376
+ balance: yield balance,
377
+ });
378
+ }))),
379
+ ]);
380
+ if (!((_a = userDetailsSubgraph.user) === null || _a === void 0 ? void 0 : _a.lendingPoolUserDetails)) {
381
+ return poolIds.map((poolId) => ({
382
+ poolId,
383
+ yieldEarned: 0,
384
+ balance: BigNumber.from(0),
385
+ }));
386
+ }
387
+ return userDetailsSubgraph.user.lendingPoolUserDetails.map(({ lendingPool, totalAcceptedDeposits, totalAcceptedWithdrawnAmount, }) => {
388
+ var _a, _b;
389
+ const balance = (_b = (_a = balances.find(({ poolId }) => poolId.toLowerCase() ===
390
+ lendingPool.id.toLowerCase())) === null || _a === void 0 ? void 0 : _a.balance) !== null && _b !== void 0 ? _b : BigNumber.from(0);
391
+ return {
392
+ poolId: lendingPool.id,
393
+ yieldEarned: parseFloat(ethers.utils.formatUnits(balance, 6)) -
394
+ parseFloat(totalAcceptedDeposits) -
395
+ -parseFloat(totalAcceptedWithdrawnAmount),
396
+ balance,
397
+ };
398
+ });
399
+ });
400
+ }
401
+ getPortfolioUserTrancheBalances(user) {
402
+ return __awaiter(this, void 0, void 0, function* () {
403
+ const userDetails = yield this._graph.request(portfolioUserTrancheDetailsQuery, {
404
+ userAddress: user.toLowerCase(),
405
+ });
406
+ const mapper = new Map();
407
+ if (!userDetails.user)
408
+ return mapper;
409
+ for (const lendingPoolUserDetail of userDetails.user
410
+ .lendingPoolUserDetails) {
411
+ const tranches = [];
412
+ for (const trancheDetail of lendingPoolUserDetail.lendingPoolTrancheUserDetails) {
413
+ let yieldEarned = 0;
414
+ let userBalance = '0';
415
+ if (trancheDetail) {
416
+ userBalance = this.convertSharesToAssets(trancheDetail.shares, trancheDetail.tranche.balance, trancheDetail.tranche.shares);
417
+ const totalAcceptedDeposits = parseFloat(trancheDetail.totalAcceptedDeposits);
418
+ const totalAcceptedWithdrawals = parseFloat(trancheDetail.totalAcceptedWithdrawnAmount);
419
+ yieldEarned =
420
+ parseFloat(userBalance) -
421
+ totalAcceptedDeposits -
422
+ -totalAcceptedWithdrawals;
423
+ tranches.push({
424
+ trancheId: trancheDetail.tranche.id,
425
+ yieldEarned,
426
+ userBalance,
427
+ });
428
+ }
429
+ }
430
+ mapper.set(lendingPoolUserDetail.lendingPool.id, tranches);
431
+ }
432
+ return mapper;
433
+ });
434
+ }
435
+ getUserTrancheBalance(user, poolId, trancheId) {
436
+ return __awaiter(this, void 0, void 0, function* () {
437
+ const tranche = ILendingPoolTrancheAbi__factory.connect(trancheId, this._signerOrProvider);
438
+ const [availableToWithdraw, userDetails] = yield Promise.all([
439
+ tranche.maxWithdraw(user),
440
+ this._graph.request(trancheUserDetailsQuery, {
441
+ userAddress: `${poolId}-${user}-${trancheId}`,
442
+ }),
443
+ ]);
444
+ const userDetailsSubgraph = userDetails;
445
+ let yieldEarned = 0;
446
+ let userBalance = '0';
447
+ if (userDetailsSubgraph.lendingPoolTrancheUserDetails &&
448
+ !parseUnits(userDetailsSubgraph.lendingPoolTrancheUserDetails.tranche
449
+ .shares).isZero()) {
450
+ userBalance = this.convertSharesToAssets(userDetailsSubgraph.lendingPoolTrancheUserDetails.shares, userDetailsSubgraph.lendingPoolTrancheUserDetails.tranche
451
+ .balance, userDetailsSubgraph.lendingPoolTrancheUserDetails.tranche
452
+ .shares);
453
+ const totalAcceptedDeposits = parseFloat(userDetailsSubgraph.lendingPoolTrancheUserDetails
454
+ .totalAcceptedDeposits);
455
+ const totalAcceptedWithdrawals = parseFloat(userDetailsSubgraph.lendingPoolTrancheUserDetails
456
+ .totalAcceptedWithdrawnAmount);
457
+ yieldEarned =
458
+ parseFloat(userBalance) -
459
+ totalAcceptedDeposits -
460
+ -totalAcceptedWithdrawals;
461
+ }
462
+ return {
463
+ userId: user,
464
+ address: trancheId,
465
+ yieldEarned,
466
+ balance: userBalance,
467
+ availableToWithdraw,
468
+ trancheId,
469
+ };
470
+ });
471
+ }
472
+ getUserApyBonus(user) {
473
+ return __awaiter(this, void 0, void 0, function* () {
474
+ const subgraphResult = yield this._graph.request(totalUserLoyaltyRewardsQuery, {
475
+ userAddress: user,
476
+ });
477
+ if (!subgraphResult.user) {
478
+ return {
479
+ balance: BigNumber.from(0),
480
+ lifetime: 0,
481
+ };
482
+ }
483
+ const balance = yield this._userLoyaltyRewardsAbi.userRewards(user);
484
+ return {
485
+ balance: balance,
486
+ lifetime: parseFloat(subgraphResult.user.totalUserLoyaltyRewards),
487
+ };
488
+ });
489
+ }
490
+ }
@@ -0,0 +1 @@
1
+ export declare function filterArray<T>(array: T[], id_in?: string[]): T[];
@@ -0,0 +1,11 @@
1
+ export function filterArray(array, id_in) {
2
+ if (!id_in) {
3
+ return array;
4
+ }
5
+ else {
6
+ return array.filter(data => {
7
+ const { id } = data;
8
+ return id_in.includes(id);
9
+ });
10
+ }
11
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,32 @@
1
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
+ return new (P || (P = Promise))(function (resolve, reject) {
4
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
8
+ });
9
+ };
10
+ import * as ethers from 'ethers';
11
+ import { KasuSdk } from '..';
12
+ import { SdkConfig } from '../sdk-config';
13
+ test('subgraphCall', () => __awaiter(void 0, void 0, void 0, function* () {
14
+ const provider = new ethers.providers.JsonRpcProvider('https://sepolia.base.org');
15
+ const wallet = new ethers.Wallet('dddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddd', provider);
16
+ const config = new SdkConfig('https://api.studio.thegraph.com/query/63245/kasu-wip-sepolia/version/latest', 'https://api.goldsky.com/api/public/project_cm9t3064xeuyn01tgctdo3c17/subgraphs/kasu-plume/prod/gn', {
17
+ IKSULocking: '0x529A81c11ab6176c5E88670d293BB771800066a2',
18
+ IKSULockBonus: '0xBBfFd5F744156FFc526df12F5e09dC7b208Be740',
19
+ KSUToken: '0xa0f698Feb9Bc2BeA6E85eb071D5E3F59dc5bC56b',
20
+ UserManager: '0xA788e9223fDd7c9Db91Ef133BbeB73515c174773',
21
+ LendingPoolManager: '0xc074Aaf2565aae18db2c7498ee1387610a809F40',
22
+ KasuAllowList: '0xaE94F9D187c9eA649ADd4966340831F7cc62B69c',
23
+ SystemVariables: '0xB174a3240B23e595e90bC2736A5b8ec674Cba73A',
24
+ UserLoyaltyRewards: '0x259631CE76FD9F65296549Cd81232aa59D53Dd0c',
25
+ KsuPrice: '0x2027192aCFB4810Ad734A212F19d7030F698aCE3',
26
+ ClearingCoordinator: '0x2027192aCFB4810Ad734A212F19d7030F698aCE3',
27
+ KasuNFTs: '0x0000000000000000000000000000000000000000',
28
+ ExternalTVL: '0x0000000000000000000000000000000000000000',
29
+ }, 'https://kasu-finance.directus.app', ['']);
30
+ const sdk = new KasuSdk(config, wallet);
31
+ console.log(yield sdk.UserLending.getUserApyBonus('0xef38c432682ab49095e00442aaa354e955ac03a5'));
32
+ }));
package/index.ts ADDED
@@ -0,0 +1,2 @@
1
+ // exlude from eslint
2
+ export * from './src';
package/jest-config.ts ADDED
@@ -0,0 +1,9 @@
1
+
2
+ /** @type {import('ts-jest').JestConfigWithTsJest} */
3
+ module.exports = {
4
+ preset: 'ts-jest',
5
+ testEnvironment: 'node',
6
+ testMatch: ['**/*.test.ts'],
7
+ testTimeout: 50000,
8
+ };
9
+
package/jest.config.js ADDED
@@ -0,0 +1,8 @@
1
+ /** @type {import('ts-jest').JestConfigWithTsJest} */
2
+ module.exports = {
3
+ preset: 'ts-jest',
4
+ testEnvironment: 'node',
5
+ moduleFileExtensions: ['ts', 'js'],
6
+ testMatch: ['**/*.test.ts'],
7
+ testTimeout: 600 * 1000,
8
+ };
package/package.json ADDED
@@ -0,0 +1,49 @@
1
+ {
2
+ "name": "@kasufinance/kasu-sdk",
3
+ "version": "1.0.1",
4
+ "description": "",
5
+ "main": "dist/bundle.cjs.js",
6
+ "module": "dist/bundle.esm.js",
7
+ "types": "dist/types/index.d.ts",
8
+ "scripts": {
9
+ "test": "jest --config=jest-config.ts",
10
+ "build-tc": "typechain --target ethers-v5 --out-dir src/contracts './abis/*.json'",
11
+ "build": "eslint . && tsc --build --force tsconfig.json",
12
+ "rollup-build": "rollup -c",
13
+ "lint": "eslint . --fix"
14
+ },
15
+ "publishConfig": {
16
+ "registry": "https://registry.npmjs.org/",
17
+ "access": "public"
18
+ },
19
+ "author": "",
20
+ "license": "ISC",
21
+ "devDependencies": {
22
+ "@rollup/plugin-node-resolve": "^15.2.3",
23
+ "@rollup/plugin-typescript": "^11.1.6",
24
+ "@types/jest": "^29.5.11",
25
+ "@types/node": "^22.15.29",
26
+ "@typescript-eslint/eslint-plugin": "^6.19.0",
27
+ "eslint-config-prettier": "^9.1.0",
28
+ "eslint-plugin-import": "^2.29.1",
29
+ "graphql": "^16.8.1",
30
+ "prettier": "^3.2.2",
31
+ "rollup": "^4.14.3",
32
+ "ts-jest": "^29.1.2",
33
+ "typechain": "^8.3.2",
34
+ "typescript": "^5.8.3"
35
+ },
36
+ "dependencies": {
37
+ "@directus/sdk": "^16.1.0",
38
+ "@rollup/plugin-commonjs": "^25.0.7",
39
+ "@typechain/ethers-v5": "^11.1.2",
40
+ "@typescript-eslint/parser": "^6.0.0",
41
+ "axios": "^1.7.0",
42
+ "eslint": "^8.56.0",
43
+ "ethers": "^5.7.2",
44
+ "graphql-request": "^6.1.0",
45
+ "jest": "^29.7.0",
46
+ "ts-node": "^10.9.2",
47
+ "tslib": "^2.6.2"
48
+ }
49
+ }
@@ -0,0 +1,45 @@
1
+ // This plugin allows Rollup to process TypeScript files.
2
+ const typescript = require('@rollup/plugin-typescript');
3
+
4
+ // This plugin allows Rollup to resolve modules in 'node_modules'.
5
+ const nodeResolve = require('@rollup/plugin-node-resolve').nodeResolve;
6
+
7
+ // This plugin allows Rollup to convert CommonJS modules to ES6 modules.
8
+ const commonjs = require('@rollup/plugin-commonjs');
9
+
10
+ // Export the configuration object for Rollup.
11
+ module.exports = {
12
+ // The entry point file of library, from which Rollup will start bundling.
13
+ input: 'src/index.ts',
14
+
15
+ // Array of output configurations - defines how the build outputs should be written.
16
+ output: [
17
+ {
18
+ // Output path and filename for the CommonJS version of your library.
19
+ file: 'dist/bundle.cjs.js',
20
+ // Output format set to CommonJS, suitable for Node.js and other systems that support require().
21
+ format: 'cjs'
22
+ },
23
+ {
24
+ // Output path and filename for the ES Module version of your library.
25
+ file: 'dist/bundle.esm.js',
26
+ // Output format set to ES Module, suitable for use in modern browsers and ES Module-supporting environments.
27
+ format: 'esm'
28
+ }
29
+ ],
30
+
31
+ // Plugins to be used in the build process.
32
+ plugins: [
33
+ // Configuration for the nodeResolve plugin. This setup helps resolve third-party dependencies found in 'node_modules'.
34
+ nodeResolve({
35
+ // Specifies that the resolver should prefer built-in modules (like 'fs' or 'path') over npm-installed ones. False here because in browsers there are no built-ins.
36
+ browser: true,
37
+ preferBuiltins: false
38
+ }),
39
+ commonjs({
40
+ include: /node_modules/ // Include all CommonJS modules from node_modules to be converted
41
+ }),
42
+ typescript({ tsconfig: './tsconfig.json' }),
43
+ ],
44
+ external: ['ethers', 'ethers/lib/utils'], // Do not bundle these dependencies cus they are already bundled in frontend app
45
+ };