@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,206 @@
1
+ import { PoolOverview, TrancheData } from '../DataService/types';
2
+ export interface PortfolioRewards {
3
+ bonusYieldEarnings: {
4
+ claimableBalance: {
5
+ ksuAmount: string;
6
+ };
7
+ lifeTime: {
8
+ ksuAmount: string;
9
+ };
10
+ };
11
+ ksuLaunchBonus: {
12
+ lifeTime: {
13
+ ksuAmount: string;
14
+ };
15
+ };
16
+ protocolFees: {
17
+ claimableBalance: {
18
+ usdcAmount: string;
19
+ };
20
+ lifeTime: {
21
+ usdcAmount: string;
22
+ };
23
+ };
24
+ }
25
+ export interface PortfolioSummary {
26
+ current: {
27
+ totalKsuLocked: string;
28
+ totalLendingPoolInvestments: string;
29
+ weightedAverageApy: string;
30
+ };
31
+ daily: {
32
+ yieldEarnings: string;
33
+ };
34
+ weekly: {
35
+ yieldEarnings: string;
36
+ protocolFeesEarned: string;
37
+ ksuBonusRewards: string;
38
+ };
39
+ lifetime: {
40
+ yieldEarnings: string;
41
+ ksuBonusRewards: string;
42
+ protocolFeesEarned: string;
43
+ };
44
+ }
45
+ export interface PortfolioTrancheDepositDetails {
46
+ timestamp: EpochTimeStamp;
47
+ id: string;
48
+ depositAmount: string;
49
+ acceptedAmount: string;
50
+ }
51
+ export interface PortfolioTranche extends TrancheData {
52
+ investedAmount: string;
53
+ yieldEarnings: {
54
+ lastEpoch: string;
55
+ lifetime: string;
56
+ };
57
+ depositDetails: PortfolioTrancheDepositDetails[];
58
+ fixedLoans: {
59
+ isLocked: boolean;
60
+ lockId: string;
61
+ configId: string;
62
+ epochInterestRate: string;
63
+ epochLockStart: string;
64
+ epochLockEnd: string;
65
+ epochLockDuration: string;
66
+ isWithdrawalRequested: boolean;
67
+ startTime: EpochTimeStamp;
68
+ amount: string;
69
+ endTime: EpochTimeStamp;
70
+ yieldEarnings: {
71
+ lastEpoch: string;
72
+ lifetime: string;
73
+ };
74
+ depositDetails: PortfolioTrancheDepositDetails[];
75
+ }[];
76
+ }
77
+ export interface PortfolioLendingPool extends Omit<PoolOverview, 'tranches'> {
78
+ totalInvestedAmount: string;
79
+ totalYieldEarningsLastEpoch: string;
80
+ totalYieldEarningsLifetime: string;
81
+ isActive: boolean;
82
+ tranches: PortfolioTranche[];
83
+ requestEpochsInAdvance: string;
84
+ }
85
+ export interface LendingPortfolioData {
86
+ lendingPools: PortfolioLendingPool[];
87
+ }
88
+ export interface UserLendingPoolTrancheFixedTermDepositLock {
89
+ isLocked: boolean;
90
+ lockId: string;
91
+ createdOn: string;
92
+ isWithdrawalRequested: boolean;
93
+ initialTrancheShares: string;
94
+ epochLockStart: string;
95
+ epochLockEnd: string;
96
+ lendingPoolTrancheFixedTermConfig: {
97
+ epochLockDuration: string;
98
+ configId: string;
99
+ epochInterestRate: string;
100
+ };
101
+ unlockAmount: string | null;
102
+ initialAmount: string;
103
+ trancheShares: string;
104
+ userLendingPoolTrancheFixedTermDepositLockShareUpdate: {
105
+ shares: string;
106
+ }[] | undefined;
107
+ }
108
+ export interface LastEpochQueryResult {
109
+ user: {
110
+ lendingPoolUserDetails: {
111
+ id: string;
112
+ lendingPool: {
113
+ id: string;
114
+ name: string;
115
+ balance: string;
116
+ configuration: {
117
+ lendingPoolWithdrawalConfig: {
118
+ requestEpochsInAdvance: string;
119
+ cancelRequestEpochsInAdvance: string;
120
+ };
121
+ };
122
+ tranches: {
123
+ shares: string;
124
+ }[];
125
+ };
126
+ lendingPoolTrancheUserDetails: {
127
+ userLendingPoolTrancheFixedTermDepositLocks: {
128
+ lockId: string;
129
+ createdOn: string;
130
+ isWithdrawalRequested: boolean;
131
+ initialTrancheShares: string;
132
+ epochLockStart: string;
133
+ epochLockEnd: string;
134
+ lendingPoolTrancheFixedTermConfig: {
135
+ epochLockDuration: string;
136
+ };
137
+ }[];
138
+ lendingPoolTrancheUserEpochSharesUpdates: {
139
+ shares: string;
140
+ }[];
141
+ tranche: {
142
+ id: string;
143
+ lendingPoolTrancheShareUpdates: {
144
+ shares: string;
145
+ }[];
146
+ lendingPoolTrancheEpochInterest: {
147
+ epochInterestAmount: string;
148
+ }[];
149
+ };
150
+ }[];
151
+ }[];
152
+ } | null;
153
+ }
154
+ export interface LendingPortfolioQueryResult {
155
+ user: {
156
+ lendingPoolUserDetails: {
157
+ id: string;
158
+ lendingPool: {
159
+ id: string;
160
+ name: string;
161
+ balance: string;
162
+ configuration: {
163
+ lendingPoolWithdrawalConfig: {
164
+ requestEpochsInAdvance: string;
165
+ cancelRequestEpochsInAdvance: string;
166
+ };
167
+ };
168
+ tranches: {
169
+ shares: string;
170
+ }[];
171
+ };
172
+ lendingPoolTrancheUserDetails: {
173
+ shares: string;
174
+ userLendingPoolTrancheFixedTermDepositLocks: UserLendingPoolTrancheFixedTermDepositLock[];
175
+ lendingPoolTrancheUserEpochSharesUpdates: {
176
+ shares: string;
177
+ }[] | undefined;
178
+ totalAcceptedDeposits: string;
179
+ totalAcceptedWithdrawnAmount: string;
180
+ tranche: {
181
+ id: string;
182
+ shares: string;
183
+ balance: string;
184
+ lendingPoolTrancheShareUpdates: {
185
+ shares: string;
186
+ }[] | undefined;
187
+ lendingPoolTrancheEpochInterest: {
188
+ epochInterestAmount: string;
189
+ }[] | undefined;
190
+ };
191
+ }[];
192
+ }[];
193
+ } | null;
194
+ userRequests: {
195
+ createdOn: string;
196
+ amountAccepted: string;
197
+ tranche: {
198
+ id: string;
199
+ };
200
+ fixedTermConfigId: string;
201
+ userRequestEvents: {
202
+ id: string;
203
+ assetAmount: string;
204
+ }[];
205
+ }[];
206
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,11 @@
1
+ import { BigNumber } from 'ethers';
2
+ import { OneInchQuoteRes, OneInchSwapRes, SwapDepositBagStruct } from './types';
3
+ export declare class Swapper {
4
+ private readonly PRECISION_DECIMALS;
5
+ private readonly PRECISION;
6
+ getSwapData(url: string, fromTokenAddress: string, toTokenAddress: string, amountInDecimals: string, fromAddress: string, slippage: string): Promise<OneInchSwapRes>;
7
+ getConversionData(url: string, fromTokenAddress: string, toTokenAddress: string, amountInDecimals: string): Promise<OneInchQuoteRes>;
8
+ private getTokenRatioAtMax;
9
+ getSwap(swapUrl: string, inTokens: string[], inAmounts: BigNumber[], inDecimals: BigNumber[], outToken: string, userAddress: string, swapperAddress: string, slippage: string): Promise<SwapDepositBagStruct>;
10
+ getSwapInfo(swapUrl: string, inTokens: string[], inAmounts: BigNumber[], inDecimals: BigNumber[], outToken: string, userAddress: string, swapperAddress: string, slippage: string): Promise<Awaited<OneInchSwapRes>[]>;
11
+ }
@@ -0,0 +1,97 @@
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 axios from 'axios';
11
+ import { BigNumber, ethers } from 'ethers';
12
+ export class Swapper {
13
+ constructor() {
14
+ this.PRECISION_DECIMALS = 18;
15
+ this.PRECISION = BigNumber.from(10).pow(this.PRECISION_DECIMALS);
16
+ }
17
+ getSwapData(url, fromTokenAddress, toTokenAddress, amountInDecimals, fromAddress, slippage) {
18
+ return __awaiter(this, void 0, void 0, function* () {
19
+ const res = yield axios.get(url, {
20
+ params: {
21
+ getRequest: `/swap/v5.2/1/swap?fromTokenAddress=${fromTokenAddress}&toTokenAddress=${toTokenAddress}&amount=${amountInDecimals}&fromAddress=${fromAddress}&slippage=${slippage}&disableEstimate=true&allowPartialFill=false&includeTokensInfo=true`,
22
+ },
23
+ });
24
+ return res.data;
25
+ });
26
+ }
27
+ getConversionData(url, fromTokenAddress, toTokenAddress, amountInDecimals) {
28
+ return __awaiter(this, void 0, void 0, function* () {
29
+ const res = yield axios.get(url, {
30
+ params: {
31
+ getRequest: `/swap/v5.2/1/quote?fromTokenAddress=${fromTokenAddress}&toTokenAddress=${toTokenAddress}&amount=${amountInDecimals}&includeTokensInfo=true&includeGas=true`,
32
+ },
33
+ });
34
+ return res.data;
35
+ });
36
+ }
37
+ getTokenRatioAtMax(swapUrl, inToken, inAmount, outToken) {
38
+ return __awaiter(this, void 0, void 0, function* () {
39
+ const data = yield this.getConversionData(swapUrl, inToken, outToken, inAmount.toString());
40
+ return inAmount
41
+ .mul(this.PRECISION)
42
+ .div(ethers.utils.parseUnits(data.toAmount, this.PRECISION_DECIMALS - data.toToken.decimals));
43
+ });
44
+ }
45
+ getSwap(swapUrl, inTokens, inAmounts, inDecimals, outToken, userAddress, swapperAddress, slippage) {
46
+ return __awaiter(this, void 0, void 0, function* () {
47
+ if (inTokens.length !== inAmounts.length ||
48
+ inTokens.length !== inDecimals.length) {
49
+ throw new Error('Invalid input');
50
+ }
51
+ const transaction = {
52
+ tokensIn: inTokens,
53
+ swapInfo: [],
54
+ tokenOut: outToken,
55
+ receiver: userAddress,
56
+ };
57
+ const swapDataPromises = [];
58
+ for (let i = 0; i < inTokens.length; i++) {
59
+ swapDataPromises[i] = this.getSwapData(swapUrl, inTokens[i], outToken, ethers.utils.formatUnits(inAmounts[i], 0).split('.')[0], swapperAddress, slippage);
60
+ }
61
+ const promiseSwapData2D = Promise.all(swapDataPromises);
62
+ yield promiseSwapData2D.then((values) => {
63
+ for (let i = 0; i < inTokens.length; i++) {
64
+ if (inTokens[i] !== outToken) {
65
+ const swapInfo = {
66
+ swapTarget: values[i].tx.to,
67
+ token: inTokens[i],
68
+ swapCallData: values[i].tx.data,
69
+ };
70
+ transaction.swapInfo.push(swapInfo);
71
+ }
72
+ }
73
+ });
74
+ return transaction;
75
+ });
76
+ }
77
+ getSwapInfo(swapUrl, inTokens, inAmounts, inDecimals, outToken, userAddress, swapperAddress, slippage) {
78
+ return __awaiter(this, void 0, void 0, function* () {
79
+ if (inTokens.length !== inAmounts.length ||
80
+ inTokens.length !== inDecimals.length) {
81
+ throw new Error('Invalid input');
82
+ }
83
+ // const transaction: SwapDepositBagStruct = {
84
+ // tokensIn: inTokens,
85
+ // swapInfo: [],
86
+ // tokenOut: outToken,
87
+ // receiver: userAddress,
88
+ // }
89
+ const swapDataPromises = [];
90
+ for (let i = 0; i < inTokens.length; i++) {
91
+ swapDataPromises[i] = this.getSwapData(swapUrl, inTokens[i], outToken, ethers.utils.formatUnits(inAmounts[i], 0).split('.')[0], swapperAddress, slippage);
92
+ }
93
+ const promiseSwapData2D = Promise.all(swapDataPromises);
94
+ return promiseSwapData2D;
95
+ });
96
+ }
97
+ }
@@ -0,0 +1,51 @@
1
+ import { SwapInfoStruct } from '../../contracts/SwapperAbi';
2
+ export interface SwapDepositBagStruct {
3
+ tokensIn: string[];
4
+ swapInfo: SwapInfoStruct[];
5
+ tokenOut: string;
6
+ receiver: string;
7
+ }
8
+ export interface OneInchQuoteRes {
9
+ fromToken: {
10
+ symbol: string;
11
+ name: string;
12
+ address: string;
13
+ decimals: number;
14
+ logoURI: string;
15
+ };
16
+ toToken: {
17
+ symbol: string;
18
+ name: string;
19
+ address: string;
20
+ decimals: number;
21
+ logoURI: string;
22
+ };
23
+ toAmount: string;
24
+ gas: number;
25
+ }
26
+ export interface OneInchSwapRes {
27
+ fromToken: {
28
+ symbol: string;
29
+ name: string;
30
+ address: string;
31
+ decimals: number;
32
+ logoURI: string;
33
+ };
34
+ toToken: {
35
+ symbol: string;
36
+ name: string;
37
+ address: string;
38
+ decimals: number;
39
+ logoURI: string;
40
+ };
41
+ toAmount: string;
42
+ protocols: string[];
43
+ tx: {
44
+ from: string;
45
+ to: string;
46
+ data: string;
47
+ value: string;
48
+ gasPrice: string;
49
+ gas: number;
50
+ };
51
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,2 @@
1
+ import { UserRequestEventType } from './subgraph-types';
2
+ export declare const mapUserRequestEventType: (requestType: UserRequestEventType) => "Initiated" | "Increased" | "Cancelled" | "Accepted" | "Rejected" | "Reallocated" | "Forced";
@@ -0,0 +1,16 @@
1
+ const USER_REQUEST_EVENT_MAP = {
2
+ DepositAccepted: 'Accepted',
3
+ DepositCancelled: 'Cancelled',
4
+ DepositIncreased: 'Increased',
5
+ DepositInitiated: 'Initiated',
6
+ DepositRejected: 'Rejected',
7
+ DepositReallocated: 'Reallocated',
8
+ WithdrawalAccepted: 'Accepted',
9
+ WithdrawalCancelled: 'Cancelled',
10
+ WithdrawalIncreased: 'Increased',
11
+ WithdrawalInitiated: 'Initiated',
12
+ ImmediateWithdrawalExecuted: 'Forced',
13
+ };
14
+ export const mapUserRequestEventType = (requestType) => {
15
+ return USER_REQUEST_EVENT_MAP[requestType];
16
+ };
@@ -0,0 +1,8 @@
1
+ export declare const userRequestsQuery: string;
2
+ export declare const lendingPoolUserDetailsQuery: string;
3
+ export declare const portfolioUserTrancheDetailsQuery: string;
4
+ export declare const trancheUserDetailsQuery: string;
5
+ export declare const totalUserLoyaltyRewardsQuery: string;
6
+ export declare const currentEpochDepositedAmountQuery: string;
7
+ export declare const currentEpochFtdAmountQuery: string;
8
+ export declare const currentFtdBalanceQuery: string;
@@ -0,0 +1,188 @@
1
+ import { gql } from 'graphql-request';
2
+ export const userRequestsQuery = gql `
3
+ query userRequestsQuery(
4
+ $userAddress: String!
5
+ $unusedPools: [String]!
6
+ $epochId: BigInt!
7
+ ) {
8
+ userRequests(
9
+ where: { user: $userAddress, lendingPool_not_in: $unusedPools }
10
+ ) {
11
+ amountAccepted
12
+ amountRejected
13
+ epochId
14
+ amountRequested
15
+ createdOn
16
+ id
17
+ nftId
18
+ status
19
+ type
20
+ updatedOn
21
+ fixedTermConfigId
22
+ lendingPool {
23
+ id
24
+ name
25
+ balance
26
+ tranches {
27
+ orderId
28
+ shares
29
+ }
30
+ configuration {
31
+ tranchesConfig {
32
+ interestRate
33
+ lendingPoolTrancheInterestRateUpdates(
34
+ orderDirection: desc
35
+ orderBy: epochId
36
+ first: 1
37
+ where: { epochId_lte: $epochId }
38
+ ) {
39
+ epochInterestRate
40
+ }
41
+ id
42
+ lendingPoolTrancheFixedTermConfigs {
43
+ epochLockDuration
44
+ epochInterestRate
45
+ configId
46
+ }
47
+ }
48
+ }
49
+ }
50
+ tranche {
51
+ id
52
+ orderId
53
+ shares
54
+ balance
55
+ }
56
+ user {
57
+ id
58
+ }
59
+ userRequestEvents {
60
+ tranche {
61
+ orderId
62
+ id
63
+ }
64
+ epochId
65
+ sharesAmount
66
+ index
67
+ id
68
+ createdOn
69
+ assetAmount
70
+ transactionHash
71
+ type
72
+ }
73
+ }
74
+ }
75
+ `;
76
+ export const lendingPoolUserDetailsQuery = gql `
77
+ query LendingPoolUserDetailsQuery($userAddress: String!) {
78
+ user(id: $userAddress) {
79
+ lendingPoolUserDetails {
80
+ id
81
+ lendingPool {
82
+ id
83
+ }
84
+ totalAcceptedDeposits
85
+ totalAcceptedWithdrawnAmount
86
+ }
87
+ }
88
+ }
89
+ `;
90
+ export const portfolioUserTrancheDetailsQuery = gql `
91
+ query TrancheUserDetailsQuery($userAddress: String!) {
92
+ user(id: $userAddress) {
93
+ lendingPoolUserDetails {
94
+ lendingPool {
95
+ id
96
+ }
97
+ lendingPoolTrancheUserDetails {
98
+ id
99
+ totalAcceptedDeposits
100
+ totalAcceptedWithdrawnAmount
101
+ shares
102
+ tranche {
103
+ id
104
+ shares
105
+ balance
106
+ }
107
+ }
108
+ }
109
+ }
110
+ }
111
+ `;
112
+ export const trancheUserDetailsQuery = gql `
113
+ query TrancheUserDetailsQuery($userAddress: String!) {
114
+ lendingPoolTrancheUserDetails(id: $userAddress) {
115
+ id
116
+ totalAcceptedDeposits
117
+ totalAcceptedWithdrawnAmount
118
+ shares
119
+ tranche {
120
+ shares
121
+ balance
122
+ }
123
+ }
124
+ }
125
+ `;
126
+ export const totalUserLoyaltyRewardsQuery = gql `
127
+ query TotalUserLoyaltyRewardsQuery($userAddress: String!) {
128
+ user(id: $userAddress) {
129
+ totalUserLoyaltyRewards
130
+ }
131
+ }
132
+ `;
133
+ export const currentEpochDepositedAmountQuery = gql `
134
+ query CurrentEpochDepositedAmountQuery($ids: [ID!]) {
135
+ lendingPoolUserDetails_collection(where: { id_in: $ids }) {
136
+ lendingPoolTrancheUserDetails {
137
+ tranche {
138
+ id
139
+ }
140
+ totalPendingDepositAmount
141
+ }
142
+ }
143
+ }
144
+ `;
145
+ export const currentEpochFtdAmountQuery = gql `
146
+ query CurrentEpochFtdAmountQuery(
147
+ $userId: String
148
+ $poolIds: [String!]
149
+ $currentEpoch: BigInt
150
+ ) {
151
+ userRequests(
152
+ where: {
153
+ user: $userId
154
+ lendingPool_in: $poolIds
155
+ epochId: $currentEpoch
156
+ }
157
+ ) {
158
+ fixedTermConfigId
159
+ amountRequested
160
+ tranche {
161
+ id
162
+ balance
163
+ shares
164
+ }
165
+ }
166
+ }
167
+ `;
168
+ export const currentFtdBalanceQuery = gql `
169
+ query CurrentFtdBalanceQuery($userId: String, $poolId: String) {
170
+ userLendingPoolTrancheFixedTermDepositLocks(
171
+ where: { user: $userId, lendingPool: $poolId, isLocked: true }
172
+ ) {
173
+ trancheShares
174
+ lendingPoolTrancheFixedTermConfig {
175
+ configId
176
+ lendingPoolTranche {
177
+ id
178
+ }
179
+ }
180
+ lendingPool {
181
+ balance
182
+ tranches {
183
+ shares
184
+ }
185
+ }
186
+ }
187
+ }
188
+ `;