@wildcatfi/wildcat-sdk 3.0.77-beta → 3.1.1-beta

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 (409) hide show
  1. package/README.md +2 -2
  2. package/dist/access/access-control.d.ts +23 -36
  3. package/dist/access/access-control.d.ts.map +1 -1
  4. package/dist/access/access-control.js +104 -142
  5. package/dist/access/access-control.js.map +1 -1
  6. package/dist/access/fixed-term.d.ts +23 -36
  7. package/dist/access/fixed-term.d.ts.map +1 -1
  8. package/dist/access/fixed-term.js +115 -154
  9. package/dist/access/fixed-term.js.map +1 -1
  10. package/dist/access/index.d.ts +9 -15
  11. package/dist/access/index.d.ts.map +1 -1
  12. package/dist/access/index.js +21 -59
  13. package/dist/access/index.js.map +1 -1
  14. package/dist/access/periodic-term.d.ts +84 -0
  15. package/dist/access/periodic-term.d.ts.map +1 -0
  16. package/dist/access/periodic-term.js +298 -0
  17. package/dist/access/periodic-term.js.map +1 -0
  18. package/dist/access/utils.d.ts +1 -11
  19. package/dist/access/utils.d.ts.map +1 -1
  20. package/dist/access/utils.js +11 -87
  21. package/dist/access/utils.js.map +1 -1
  22. package/dist/access/validation.d.ts +8 -32
  23. package/dist/access/validation.d.ts.map +1 -1
  24. package/dist/access/validation.js +1 -18
  25. package/dist/access/validation.js.map +1 -1
  26. package/dist/account/index.d.ts +39 -35
  27. package/dist/account/index.d.ts.map +1 -1
  28. package/dist/account/index.js +301 -315
  29. package/dist/account/index.js.map +1 -1
  30. package/dist/account/validation.d.ts +19 -3
  31. package/dist/account/validation.d.ts.map +1 -1
  32. package/dist/account/validation.js +16 -2
  33. package/dist/account/validation.js.map +1 -1
  34. package/dist/collateral/collateral-events.d.ts +10 -9
  35. package/dist/collateral/collateral-events.d.ts.map +1 -1
  36. package/dist/collateral/collateral-events.js +4 -4
  37. package/dist/collateral/collateral-events.js.map +1 -1
  38. package/dist/collateral/index.d.ts +10 -7
  39. package/dist/collateral/index.d.ts.map +1 -1
  40. package/dist/collateral/index.js +37 -36
  41. package/dist/collateral/index.js.map +1 -1
  42. package/dist/constants.d.ts +13 -100
  43. package/dist/constants.d.ts.map +1 -1
  44. package/dist/constants.js +27 -290
  45. package/dist/constants.js.map +1 -1
  46. package/dist/controller.d.ts +17 -10
  47. package/dist/controller.d.ts.map +1 -1
  48. package/dist/controller.js +67 -67
  49. package/dist/controller.js.map +1 -1
  50. package/dist/gql/getActiveLendersByMarket.d.ts +4 -5
  51. package/dist/gql/getActiveLendersByMarket.d.ts.map +1 -1
  52. package/dist/gql/getActiveLendersByMarket.js +10 -11
  53. package/dist/gql/getActiveLendersByMarket.js.map +1 -1
  54. package/dist/gql/getAllHooksDataForBorrower.d.ts.map +1 -1
  55. package/dist/gql/getAllHooksDataForBorrower.js +8 -11
  56. package/dist/gql/getAllHooksDataForBorrower.js.map +1 -1
  57. package/dist/gql/getAllHooksTemplates.d.ts.map +1 -1
  58. package/dist/gql/getAllHooksTemplates.js +4 -6
  59. package/dist/gql/getAllHooksTemplates.js.map +1 -1
  60. package/dist/gql/getLenderAccountsForAllMarkets.d.ts +1 -8
  61. package/dist/gql/getLenderAccountsForAllMarkets.d.ts.map +1 -1
  62. package/dist/gql/getLenderAccountsForAllMarkets.js +11 -26
  63. package/dist/gql/getLenderAccountsForAllMarkets.js.map +1 -1
  64. package/dist/gql/getMarketRecords.d.ts +2 -2
  65. package/dist/gql/getMarketRecords.d.ts.map +1 -1
  66. package/dist/gql/getMarketRecords.js +6 -2
  67. package/dist/gql/getMarketRecords.js.map +1 -1
  68. package/dist/gql/getMarketsForBorrower.d.ts.map +1 -1
  69. package/dist/gql/getMarketsForBorrower.js +2 -32
  70. package/dist/gql/getMarketsForBorrower.js.map +1 -1
  71. package/dist/gql/getMarketsWithEvents.d.ts.map +1 -1
  72. package/dist/gql/getMarketsWithEvents.js +0 -28
  73. package/dist/gql/getMarketsWithEvents.js.map +1 -1
  74. package/dist/gql/graphql.d.ts +678 -1480
  75. package/dist/gql/graphql.d.ts.map +1 -1
  76. package/dist/gql/graphql.js +243 -591
  77. package/dist/gql/graphql.js.map +1 -1
  78. package/dist/gql/index.d.ts +0 -2
  79. package/dist/gql/index.d.ts.map +1 -1
  80. package/dist/gql/index.js +0 -2
  81. package/dist/gql/index.js.map +1 -1
  82. package/dist/index.d.ts +4 -6
  83. package/dist/index.d.ts.map +1 -1
  84. package/dist/index.js +17 -8
  85. package/dist/index.js.map +1 -1
  86. package/dist/market.d.ts +22 -85
  87. package/dist/market.d.ts.map +1 -1
  88. package/dist/market.js +284 -596
  89. package/dist/market.js.map +1 -1
  90. package/dist/mockerc20factory.d.ts +11 -4
  91. package/dist/mockerc20factory.d.ts.map +1 -1
  92. package/dist/mockerc20factory.js +15 -20
  93. package/dist/mockerc20factory.js.map +1 -1
  94. package/dist/token.d.ts +12 -67
  95. package/dist/token.d.ts.map +1 -1
  96. package/dist/token.js +57 -167
  97. package/dist/token.js.map +1 -1
  98. package/dist/typechain/AccountQuery.d.ts +54 -0
  99. package/dist/typechain/AccountQuery.d.ts.map +1 -0
  100. package/dist/typechain/AccountQuery.js +3 -0
  101. package/dist/typechain/AccountQuery.js.map +1 -0
  102. package/dist/typechain/AccountsQuery.d.ts +54 -0
  103. package/dist/typechain/AccountsQuery.d.ts.map +1 -0
  104. package/dist/typechain/AccountsQuery.js +3 -0
  105. package/dist/typechain/AccountsQuery.js.map +1 -0
  106. package/dist/typechain/CheckBorrowersRegistered.d.ts +29 -0
  107. package/dist/typechain/CheckBorrowersRegistered.d.ts.map +1 -0
  108. package/dist/typechain/CheckBorrowersRegistered.js +3 -0
  109. package/dist/typechain/CheckBorrowersRegistered.js.map +1 -0
  110. package/dist/typechain/CheckSafeSignature.d.ts +29 -0
  111. package/dist/typechain/CheckSafeSignature.d.ts.map +1 -0
  112. package/dist/typechain/CheckSafeSignature.js +3 -0
  113. package/dist/typechain/CheckSafeSignature.js.map +1 -0
  114. package/dist/typechain/CollateralLens.d.ts +220 -0
  115. package/dist/typechain/CollateralLens.d.ts.map +1 -0
  116. package/dist/typechain/CollateralLens.js +3 -0
  117. package/dist/typechain/CollateralLens.js.map +1 -0
  118. package/dist/typechain/DescribeSignature.d.ts +100 -0
  119. package/dist/typechain/DescribeSignature.d.ts.map +1 -0
  120. package/dist/typechain/DescribeSignature.js +3 -0
  121. package/dist/typechain/DescribeSignature.js.map +1 -0
  122. package/dist/typechain/HooksFactory.d.ts +591 -16
  123. package/dist/typechain/HooksFactory.d.ts.map +1 -1
  124. package/dist/typechain/IERC20.d.ts +232 -0
  125. package/dist/typechain/IERC20.d.ts.map +1 -0
  126. package/dist/{lens-types.js → typechain/IERC20.js} +1 -1
  127. package/dist/typechain/IERC20.js.map +1 -0
  128. package/dist/typechain/IFixedTermHooks.d.ts +1032 -0
  129. package/dist/typechain/IFixedTermHooks.d.ts.map +1 -0
  130. package/dist/typechain/IFixedTermHooks.js +3 -0
  131. package/dist/typechain/IFixedTermHooks.js.map +1 -0
  132. package/dist/typechain/IOpenTermHooks.d.ts +987 -0
  133. package/dist/typechain/IOpenTermHooks.d.ts.map +1 -0
  134. package/dist/typechain/IOpenTermHooks.js +3 -0
  135. package/dist/typechain/IOpenTermHooks.js.map +1 -0
  136. package/dist/typechain/IPeriodicTermHooks.d.ts +663 -0
  137. package/dist/typechain/IPeriodicTermHooks.d.ts.map +1 -0
  138. package/dist/typechain/IPeriodicTermHooks.js +3 -0
  139. package/dist/typechain/IPeriodicTermHooks.js.map +1 -0
  140. package/dist/typechain/ISafe.d.ts +124 -0
  141. package/dist/typechain/ISafe.d.ts.map +1 -0
  142. package/dist/typechain/ISafe.js +3 -0
  143. package/dist/typechain/ISafe.js.map +1 -0
  144. package/dist/typechain/MarketLens.d.ts +611 -0
  145. package/dist/typechain/MarketLens.d.ts.map +1 -0
  146. package/dist/typechain/MarketLens.js +3 -0
  147. package/dist/typechain/MarketLens.js.map +1 -0
  148. package/dist/typechain/MarketLensV2.d.ts +710 -0
  149. package/dist/typechain/MarketLensV2.d.ts.map +1 -0
  150. package/dist/typechain/MarketLensV2.js +3 -0
  151. package/dist/typechain/MarketLensV2.js.map +1 -0
  152. package/dist/typechain/MockArchControllerOwner.d.ts +130 -0
  153. package/dist/typechain/MockArchControllerOwner.d.ts.map +1 -0
  154. package/dist/typechain/MockArchControllerOwner.js +3 -0
  155. package/dist/typechain/MockArchControllerOwner.js.map +1 -0
  156. package/dist/typechain/MockERC20Factory.d.ts +122 -0
  157. package/dist/typechain/MockERC20Factory.d.ts.map +1 -0
  158. package/dist/typechain/MockERC20Factory.js +3 -0
  159. package/dist/typechain/MockERC20Factory.js.map +1 -0
  160. package/dist/typechain/SimpleMarketCollateral.d.ts +270 -0
  161. package/dist/typechain/SimpleMarketCollateral.d.ts.map +1 -0
  162. package/dist/typechain/SimpleMarketCollateral.js +3 -0
  163. package/dist/typechain/SimpleMarketCollateral.js.map +1 -0
  164. package/dist/typechain/WildcatArchController.d.ts +545 -0
  165. package/dist/typechain/WildcatArchController.d.ts.map +1 -0
  166. package/dist/typechain/WildcatArchController.js +3 -0
  167. package/dist/typechain/WildcatArchController.js.map +1 -0
  168. package/dist/typechain/WildcatCollateralFactory.d.ts +164 -0
  169. package/dist/typechain/WildcatCollateralFactory.d.ts.map +1 -0
  170. package/dist/typechain/WildcatCollateralFactory.js +3 -0
  171. package/dist/typechain/WildcatCollateralFactory.js.map +1 -0
  172. package/dist/typechain/WildcatMarket.d.ts +1062 -0
  173. package/dist/typechain/WildcatMarket.d.ts.map +1 -0
  174. package/dist/typechain/WildcatMarket.js +3 -0
  175. package/dist/typechain/WildcatMarket.js.map +1 -0
  176. package/dist/typechain/WildcatMarketController.d.ts +553 -0
  177. package/dist/typechain/WildcatMarketController.d.ts.map +1 -0
  178. package/dist/typechain/WildcatMarketController.js +3 -0
  179. package/dist/typechain/WildcatMarketController.js.map +1 -0
  180. package/dist/typechain/WildcatMarketControllerFactory.d.ts +344 -0
  181. package/dist/typechain/WildcatMarketControllerFactory.d.ts.map +1 -0
  182. package/dist/typechain/WildcatMarketControllerFactory.js +3 -0
  183. package/dist/typechain/WildcatMarketControllerFactory.js.map +1 -0
  184. package/dist/typechain/WildcatMarketV2.d.ts +1086 -0
  185. package/dist/typechain/WildcatMarketV2.d.ts.map +1 -0
  186. package/dist/typechain/WildcatMarketV2.js +3 -0
  187. package/dist/typechain/WildcatMarketV2.js.map +1 -0
  188. package/dist/typechain/common.d.ts +23 -0
  189. package/dist/typechain/common.d.ts.map +1 -0
  190. package/dist/typechain/common.js +3 -0
  191. package/dist/typechain/common.js.map +1 -0
  192. package/dist/typechain/factories/AccountQuery__factory.d.ts +59 -0
  193. package/dist/typechain/factories/AccountQuery__factory.d.ts.map +1 -0
  194. package/dist/typechain/factories/AccountQuery__factory.js +91 -0
  195. package/dist/typechain/factories/AccountQuery__factory.js.map +1 -0
  196. package/dist/typechain/factories/AccountsQuery__factory.d.ts +59 -0
  197. package/dist/typechain/factories/AccountsQuery__factory.d.ts.map +1 -0
  198. package/dist/typechain/factories/AccountsQuery__factory.js +91 -0
  199. package/dist/typechain/factories/AccountsQuery__factory.js.map +1 -0
  200. package/dist/typechain/factories/CheckBorrowersRegistered__factory.d.ts +36 -0
  201. package/dist/typechain/factories/CheckBorrowersRegistered__factory.d.ts.map +1 -0
  202. package/dist/typechain/factories/CheckBorrowersRegistered__factory.js +60 -0
  203. package/dist/typechain/factories/CheckBorrowersRegistered__factory.js.map +1 -0
  204. package/dist/typechain/factories/CheckSafeSignature__factory.d.ts +40 -0
  205. package/dist/typechain/factories/CheckSafeSignature__factory.d.ts.map +1 -0
  206. package/dist/typechain/factories/CheckSafeSignature__factory.js +65 -0
  207. package/dist/typechain/factories/CheckSafeSignature__factory.js.map +1 -0
  208. package/dist/typechain/factories/CollateralLens__factory.d.ts +854 -0
  209. package/dist/typechain/factories/CollateralLens__factory.d.ts.map +1 -0
  210. package/dist/typechain/factories/CollateralLens__factory.js +1101 -0
  211. package/dist/typechain/factories/CollateralLens__factory.js.map +1 -0
  212. package/dist/typechain/factories/DescribeSignature__factory.d.ts +141 -0
  213. package/dist/typechain/factories/DescribeSignature__factory.d.ts.map +1 -0
  214. package/dist/typechain/factories/DescribeSignature__factory.js +198 -0
  215. package/dist/typechain/factories/DescribeSignature__factory.js.map +1 -0
  216. package/dist/typechain/factories/HooksFactory__factory.d.ts +902 -0
  217. package/dist/typechain/factories/HooksFactory__factory.d.ts.map +1 -0
  218. package/dist/typechain/factories/HooksFactory__factory.js +1168 -0
  219. package/dist/typechain/factories/HooksFactory__factory.js.map +1 -0
  220. package/dist/typechain/factories/IERC20__factory.d.ts +235 -0
  221. package/dist/typechain/factories/IERC20__factory.d.ts.map +1 -0
  222. package/dist/typechain/factories/IERC20__factory.js +315 -0
  223. package/dist/typechain/factories/IERC20__factory.js.map +1 -0
  224. package/dist/typechain/factories/IFixedTermHooks__factory.d.ts +1894 -0
  225. package/dist/typechain/factories/IFixedTermHooks__factory.d.ts.map +1 -0
  226. package/dist/typechain/factories/IFixedTermHooks__factory.js +2423 -0
  227. package/dist/typechain/factories/IFixedTermHooks__factory.js.map +1 -0
  228. package/dist/typechain/factories/IOpenTermHooks__factory.d.ts +1791 -0
  229. package/dist/typechain/factories/IOpenTermHooks__factory.d.ts.map +1 -0
  230. package/dist/typechain/factories/IOpenTermHooks__factory.js +2293 -0
  231. package/dist/typechain/factories/IOpenTermHooks__factory.js.map +1 -0
  232. package/dist/typechain/factories/IPeriodicTermHooks__factory.d.ts +750 -0
  233. package/dist/typechain/factories/IPeriodicTermHooks__factory.d.ts.map +1 -0
  234. package/dist/typechain/factories/IPeriodicTermHooks__factory.js +975 -0
  235. package/dist/typechain/factories/IPeriodicTermHooks__factory.js.map +1 -0
  236. package/dist/typechain/factories/ISafe__factory.d.ts +163 -0
  237. package/dist/typechain/factories/ISafe__factory.d.ts.map +1 -0
  238. package/dist/typechain/factories/ISafe__factory.js +225 -0
  239. package/dist/typechain/factories/ISafe__factory.js.map +1 -0
  240. package/dist/typechain/factories/MarketLensV2__factory.d.ts +6708 -0
  241. package/dist/typechain/factories/MarketLensV2__factory.d.ts.map +1 -0
  242. package/dist/typechain/factories/MarketLensV2__factory.js +8574 -0
  243. package/dist/typechain/factories/MarketLensV2__factory.js.map +1 -0
  244. package/dist/typechain/factories/MarketLens__factory.d.ts +3572 -0
  245. package/dist/typechain/factories/MarketLens__factory.d.ts.map +1 -0
  246. package/dist/typechain/factories/MarketLens__factory.js +4569 -0
  247. package/dist/typechain/factories/MarketLens__factory.js.map +1 -0
  248. package/dist/typechain/factories/MockArchControllerOwner__factory.d.ts +85 -0
  249. package/dist/typechain/factories/MockArchControllerOwner__factory.d.ts.map +1 -0
  250. package/dist/typechain/factories/MockArchControllerOwner__factory.js +118 -0
  251. package/dist/typechain/factories/MockArchControllerOwner__factory.js.map +1 -0
  252. package/dist/typechain/factories/MockERC20Factory__factory.d.ts +114 -0
  253. package/dist/typechain/factories/MockERC20Factory__factory.d.ts.map +1 -0
  254. package/dist/typechain/factories/MockERC20Factory__factory.js +157 -0
  255. package/dist/typechain/factories/MockERC20Factory__factory.js.map +1 -0
  256. package/dist/typechain/factories/SimpleMarketCollateral__factory.d.ts +264 -0
  257. package/dist/typechain/factories/SimpleMarketCollateral__factory.d.ts.map +1 -0
  258. package/dist/typechain/factories/SimpleMarketCollateral__factory.js +354 -0
  259. package/dist/typechain/factories/SimpleMarketCollateral__factory.js.map +1 -0
  260. package/dist/typechain/factories/WildcatArchController__factory.d.ts +554 -0
  261. package/dist/typechain/factories/WildcatArchController__factory.d.ts.map +1 -0
  262. package/dist/typechain/factories/WildcatArchController__factory.js +728 -0
  263. package/dist/typechain/factories/WildcatArchController__factory.js.map +1 -0
  264. package/dist/typechain/factories/WildcatCollateralFactory__factory.d.ts +160 -0
  265. package/dist/typechain/factories/WildcatCollateralFactory__factory.d.ts.map +1 -0
  266. package/dist/typechain/factories/WildcatCollateralFactory__factory.js +223 -0
  267. package/dist/typechain/factories/WildcatCollateralFactory__factory.js.map +1 -0
  268. package/dist/typechain/factories/WildcatMarketControllerFactory__factory.d.ts +421 -0
  269. package/dist/typechain/factories/WildcatMarketControllerFactory__factory.d.ts.map +1 -0
  270. package/dist/typechain/factories/WildcatMarketControllerFactory__factory.js +549 -0
  271. package/dist/typechain/factories/WildcatMarketControllerFactory__factory.js.map +1 -0
  272. package/dist/typechain/factories/WildcatMarketController__factory.d.ts +671 -0
  273. package/dist/typechain/factories/WildcatMarketController__factory.d.ts.map +1 -0
  274. package/dist/typechain/factories/WildcatMarketController__factory.js +870 -0
  275. package/dist/typechain/factories/WildcatMarketController__factory.js.map +1 -0
  276. package/dist/typechain/factories/WildcatMarketV2__factory.d.ts +1304 -0
  277. package/dist/typechain/factories/WildcatMarketV2__factory.d.ts.map +1 -0
  278. package/dist/typechain/factories/WildcatMarketV2__factory.js +1680 -0
  279. package/dist/typechain/factories/WildcatMarketV2__factory.js.map +1 -0
  280. package/dist/typechain/factories/WildcatMarket__factory.d.ts +1326 -0
  281. package/dist/typechain/factories/WildcatMarket__factory.d.ts.map +1 -0
  282. package/dist/typechain/factories/WildcatMarket__factory.js +1712 -0
  283. package/dist/typechain/factories/WildcatMarket__factory.js.map +1 -0
  284. package/dist/typechain/factories/index.d.ts +24 -0
  285. package/dist/typechain/factories/index.d.ts.map +1 -0
  286. package/dist/typechain/factories/index.js +53 -0
  287. package/dist/typechain/factories/index.js.map +1 -0
  288. package/dist/typechain/index.d.ts +60 -84
  289. package/dist/typechain/index.d.ts.map +1 -1
  290. package/dist/typechain/index.js +71 -120
  291. package/dist/typechain/index.js.map +1 -1
  292. package/dist/types.d.ts +34 -75
  293. package/dist/types.d.ts.map +1 -1
  294. package/dist/types.js +16 -21
  295. package/dist/types.js.map +1 -1
  296. package/dist/utils/check-registered-borrowers.d.ts.map +1 -1
  297. package/dist/utils/check-registered-borrowers.js +6 -7
  298. package/dist/utils/check-registered-borrowers.js.map +1 -1
  299. package/dist/utils/describe-account.d.ts +2 -5
  300. package/dist/utils/describe-account.d.ts.map +1 -1
  301. package/dist/utils/describe-account.js +8 -38
  302. package/dist/utils/describe-account.js.map +1 -1
  303. package/dist/utils/describe-signature.d.ts +1 -1
  304. package/dist/utils/describe-signature.d.ts.map +1 -1
  305. package/dist/utils/describe-signature.js +25 -80
  306. package/dist/utils/describe-signature.js.map +1 -1
  307. package/dist/utils/index.d.ts +0 -2
  308. package/dist/utils/index.d.ts.map +1 -1
  309. package/dist/utils/index.js +0 -2
  310. package/dist/utils/index.js.map +1 -1
  311. package/dist/utils/logger.d.ts.map +1 -1
  312. package/dist/utils/logger.js +1 -0
  313. package/dist/utils/logger.js.map +1 -1
  314. package/dist/utils/math.d.ts +13 -1
  315. package/dist/utils/math.d.ts.map +1 -1
  316. package/dist/utils/math.js +50 -14
  317. package/dist/utils/math.js.map +1 -1
  318. package/dist/utils/misc.d.ts +4 -5
  319. package/dist/utils/misc.d.ts.map +1 -1
  320. package/dist/utils/misc.js +6 -6
  321. package/dist/utils/misc.js.map +1 -1
  322. package/dist/utils/record-types.d.ts +10 -7
  323. package/dist/utils/record-types.d.ts.map +1 -1
  324. package/dist/utils/record-types.js +2 -2
  325. package/dist/utils/record-types.js.map +1 -1
  326. package/dist/utils/type-parsers.d.ts +3 -9
  327. package/dist/utils/type-parsers.d.ts.map +1 -1
  328. package/dist/utils/type-parsers.js +13 -12
  329. package/dist/utils/type-parsers.js.map +1 -1
  330. package/dist/withdrawal-batch.d.ts +9 -12
  331. package/dist/withdrawal-batch.d.ts.map +1 -1
  332. package/dist/withdrawal-batch.js +30 -46
  333. package/dist/withdrawal-batch.js.map +1 -1
  334. package/dist/withdrawal-status.d.ts +7 -12
  335. package/dist/withdrawal-status.d.ts.map +1 -1
  336. package/dist/withdrawal-status.js +12 -29
  337. package/dist/withdrawal-status.js.map +1 -1
  338. package/package.json +12 -20
  339. package/dist/abi/generated.d.ts +0 -34504
  340. package/dist/abi/generated.d.ts.map +0 -1
  341. package/dist/abi/generated.js +0 -44192
  342. package/dist/abi/generated.js.map +0 -1
  343. package/dist/abi/index.d.ts +0 -3
  344. package/dist/abi/index.d.ts.map +0 -1
  345. package/dist/abi/index.js +0 -19
  346. package/dist/abi/index.js.map +0 -1
  347. package/dist/abi/manual.d.ts +0 -354
  348. package/dist/abi/manual.d.ts.map +0 -1
  349. package/dist/abi/manual.js +0 -202
  350. package/dist/abi/manual.js.map +0 -1
  351. package/dist/access/revolving.d.ts +0 -8
  352. package/dist/access/revolving.d.ts.map +0 -1
  353. package/dist/access/revolving.js +0 -15
  354. package/dist/access/revolving.js.map +0 -1
  355. package/dist/access/subgraph-template.d.ts +0 -14
  356. package/dist/access/subgraph-template.d.ts.map +0 -1
  357. package/dist/access/subgraph-template.js +0 -20
  358. package/dist/access/subgraph-template.js.map +0 -1
  359. package/dist/client.d.ts +0 -22
  360. package/dist/client.d.ts.map +0 -1
  361. package/dist/client.js +0 -51
  362. package/dist/client.js.map +0 -1
  363. package/dist/gql/getMarketChartsData.d.ts +0 -35
  364. package/dist/gql/getMarketChartsData.d.ts.map +0 -1
  365. package/dist/gql/getMarketChartsData.js +0 -56
  366. package/dist/gql/getMarketChartsData.js.map +0 -1
  367. package/dist/gql/getMarketList.d.ts +0 -16
  368. package/dist/gql/getMarketList.d.ts.map +0 -1
  369. package/dist/gql/getMarketList.js +0 -23
  370. package/dist/gql/getMarketList.js.map +0 -1
  371. package/dist/internal/arch-controller.d.ts +0 -6
  372. package/dist/internal/arch-controller.d.ts.map +0 -1
  373. package/dist/internal/arch-controller.js +0 -36
  374. package/dist/internal/arch-controller.js.map +0 -1
  375. package/dist/internal/ethers-signer.d.ts +0 -4
  376. package/dist/internal/ethers-signer.d.ts.map +0 -1
  377. package/dist/internal/ethers-signer.js +0 -12
  378. package/dist/internal/ethers-signer.js.map +0 -1
  379. package/dist/internal/ethers-viem.d.ts +0 -4
  380. package/dist/internal/ethers-viem.d.ts.map +0 -1
  381. package/dist/internal/ethers-viem.js +0 -43
  382. package/dist/internal/ethers-viem.js.map +0 -1
  383. package/dist/internal/market-lens.d.ts +0 -28
  384. package/dist/internal/market-lens.d.ts.map +0 -1
  385. package/dist/internal/market-lens.js +0 -125
  386. package/dist/internal/market-lens.js.map +0 -1
  387. package/dist/internal/viem-read.d.ts +0 -3
  388. package/dist/internal/viem-read.d.ts.map +0 -1
  389. package/dist/internal/viem-read.js +0 -13
  390. package/dist/internal/viem-read.js.map +0 -1
  391. package/dist/internal/viem-write.d.ts +0 -10
  392. package/dist/internal/viem-write.d.ts.map +0 -1
  393. package/dist/internal/viem-write.js +0 -51
  394. package/dist/internal/viem-write.js.map +0 -1
  395. package/dist/lens-types.d.ts +0 -309
  396. package/dist/lens-types.d.ts.map +0 -1
  397. package/dist/lens-types.js.map +0 -1
  398. package/dist/utils/bigint.d.ts +0 -22
  399. package/dist/utils/bigint.d.ts.map +0 -1
  400. package/dist/utils/bigint.js +0 -111
  401. package/dist/utils/bigint.js.map +0 -1
  402. package/dist/utils/viem-encoding.d.ts +0 -15
  403. package/dist/utils/viem-encoding.d.ts.map +0 -1
  404. package/dist/utils/viem-encoding.js +0 -33
  405. package/dist/utils/viem-encoding.js.map +0 -1
  406. package/dist/wrapper/index.d.ts +0 -94
  407. package/dist/wrapper/index.d.ts.map +0 -1
  408. package/dist/wrapper/index.js +0 -296
  409. package/dist/wrapper/index.js.map +0 -1
@@ -15,18 +15,15 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
17
  exports.MarketAccount = exports.LenderRole = void 0;
18
+ const ethers_1 = require("ethers");
18
19
  const token_1 = require("../token");
19
20
  const market_1 = require("../market");
21
+ const typechain_1 = require("../typechain");
20
22
  const utils_1 = require("../utils");
21
23
  const constants_1 = require("../constants");
22
- const arch_controller_1 = require("../internal/arch-controller");
23
- const market_lens_1 = require("../internal/market-lens");
24
24
  const types_1 = require("../types");
25
25
  const withdrawal_status_1 = require("../withdrawal-status");
26
26
  const validation_1 = require("./validation");
27
- const abi_1 = require("../abi");
28
- const viem_write_1 = require("../internal/viem-write");
29
- const viem_1 = require("viem");
30
27
  __exportStar(require("./validation"), exports);
31
28
  var LenderRole;
32
29
  (function (LenderRole) {
@@ -35,18 +32,7 @@ var LenderRole;
35
32
  LenderRole[LenderRole["WithdrawOnly"] = 2] = "WithdrawOnly";
36
33
  LenderRole[LenderRole["DepositAndWithdraw"] = 3] = "DepositAndWithdraw";
37
34
  })(LenderRole = exports.LenderRole || (exports.LenderRole = {}));
38
- const NullProviderIndex = 2 ** 24 - 1;
39
- const ZERO_ADDRESS = "0x0000000000000000000000000000000000000000";
40
- const hasUnifiedLatestLensForAccountReads = (chainId) => {
41
- return (0, constants_1.hasDeploymentAddress)(chainId, "MarketLensV2_5");
42
- };
43
- const zeroLenderBalances = (info) => ({
44
- ...info,
45
- scaledBalance: 0n,
46
- normalizedBalance: 0n,
47
- underlyingBalance: 0n,
48
- underlyingApproval: 0n
49
- });
35
+ const NullProviderIndex = ethers_1.BigNumber.from(2).pow(24).sub(1).toNumber();
50
36
  /**
51
37
  * Class to provide information about a market user's account
52
38
  * and to wrap interactions.
@@ -150,6 +136,9 @@ class MarketAccount {
150
136
  // Can not withdraw if market in fixed term
151
137
  if (this.market.isInFixedTerm)
152
138
  return validation_1.QueueWithdrawalStatus.MarketInClosedTerm;
139
+ if (config.kind === types_1.HooksKind.PeriodicTerm && !this.market.isPeriodicWithdrawalWindowOpen) {
140
+ return validation_1.QueueWithdrawalStatus.OutsideWithdrawalWindow;
141
+ }
153
142
  // Can not withdraw if market requires access and lender has no credential and is not a known lender
154
143
  if (config.flags.useOnQueueWithdrawal &&
155
144
  (config.kind === types_1.HooksKind.OpenTerm || config.queueWithdrawalRequiresAccess) &&
@@ -215,6 +204,27 @@ class MarketAccount {
215
204
  return { status: validation_1.SetAprStatus.NotBorrower };
216
205
  if (!(apr > 0 && apr <= 10000))
217
206
  return { status: validation_1.SetAprStatus.InvalidApr };
207
+ if (this.market.version === types_1.MarketVersion.V2 &&
208
+ this.market.hooksConfig?.kind === types_1.HooksKind.PeriodicTerm &&
209
+ apr < this.market.annualInterestBips) {
210
+ const config = this.market.hooksConfig;
211
+ if (config.pendingAnnualInterestProposalTimestamp === 0) {
212
+ return { status: validation_1.SetAprStatus.NoPendingAprChange };
213
+ }
214
+ if (config.pendingAnnualInterestBips !== apr) {
215
+ return { status: validation_1.SetAprStatus.AprChangeDoesNotMatchProposal };
216
+ }
217
+ if (Math.floor(Date.now() / 1000) < config.pendingAnnualInterestResponseWindowEnd) {
218
+ return { status: validation_1.SetAprStatus.AprChangeNotReady };
219
+ }
220
+ if (!this.market.scaledPendingWithdrawals.isZero()) {
221
+ return { status: validation_1.SetAprStatus.UnpaidWithdrawalsExist };
222
+ }
223
+ return {
224
+ status: validation_1.SetAprStatus.Ready,
225
+ willChangeReserveRatio: false
226
+ };
227
+ }
218
228
  const [originalReserveRatioBips, originalAnnualInterestBips] = this.market.originalReserveRatioAndAnnualInterestBips;
219
229
  const newReserveRatioBips = this.market.getReserveRatioForNewAPR(apr);
220
230
  const willChangeReserveRatio = newReserveRatioBips !== this.market.reserveRatioBips;
@@ -267,6 +277,26 @@ class MarketAccount {
267
277
  return { status: validation_1.SetMinimumDepositStatus.NotBorrower };
268
278
  return { status: validation_1.SetMinimumDepositStatus.Ready };
269
279
  }
280
+ previewProposeAnnualInterestBips(apr) {
281
+ if (this.market.version !== types_1.MarketVersion.V2) {
282
+ return { status: validation_1.ProposeAnnualInterestBipsStatus.NotV2Market };
283
+ }
284
+ if (!this.isBorrower)
285
+ return { status: validation_1.ProposeAnnualInterestBipsStatus.NotBorrower };
286
+ if (this.market.hooksConfig?.kind !== types_1.HooksKind.PeriodicTerm) {
287
+ return { status: validation_1.ProposeAnnualInterestBipsStatus.NotPeriodicTermMarket };
288
+ }
289
+ if (!(apr > 0 && apr <= 10000)) {
290
+ return { status: validation_1.ProposeAnnualInterestBipsStatus.InvalidApr };
291
+ }
292
+ if (apr >= this.market.annualInterestBips) {
293
+ return { status: validation_1.ProposeAnnualInterestBipsStatus.NotReduction };
294
+ }
295
+ if (this.market.isPeriodicWithdrawalWindowOpen) {
296
+ return { status: validation_1.ProposeAnnualInterestBipsStatus.WithdrawalWindowOpen };
297
+ }
298
+ return { status: validation_1.ProposeAnnualInterestBipsStatus.Ready };
299
+ }
270
300
  previewSetFixedTermEndTime(endTime) {
271
301
  if (this.market.version !== types_1.MarketVersion.V2)
272
302
  return { status: validation_1.SetFixedTermEndTimeStatus.NotV2Market };
@@ -291,101 +321,130 @@ class MarketAccount {
291
321
  (0, utils_1.assert)(status === validation_1.SetMinimumDepositStatus.Ready, `Cannot set minimum deposit: ${status}`);
292
322
  const config = this.market.hooksConfig;
293
323
  (0, utils_1.assert)(config !== undefined, `V2 market missing hooksConfig`);
294
- return (0, utils_1.prepareTransaction)({
324
+ const iface = typechain_1.IOpenTermHooks__factory.createInterface();
325
+ return {
295
326
  to: config.hooksAddress,
296
- abi: abi_1.iOpenTermHooksAbi,
297
- functionName: "setMinimumDeposit",
298
- args: [this.market.address, amount.raw]
299
- });
327
+ data: iface.encodeFunctionData("setMinimumDeposit", [this.market.address, amount.raw]),
328
+ value: "0"
329
+ };
330
+ }
331
+ async populateProposeAnnualInterestBips(apr) {
332
+ const { status } = this.previewProposeAnnualInterestBips(apr);
333
+ (0, utils_1.assert)(status === validation_1.ProposeAnnualInterestBipsStatus.Ready, `Cannot propose APR reduction: ${status}`);
334
+ const config = this.market.hooksConfig;
335
+ (0, utils_1.assert)(config !== undefined, `V2 market missing hooksConfig`);
336
+ const iface = typechain_1.IPeriodicTermHooks__factory.createInterface();
337
+ return {
338
+ to: config.hooksAddress,
339
+ data: iface.encodeFunctionData("proposeAnnualInterestBips", [this.market.address, apr]),
340
+ value: "0"
341
+ };
300
342
  }
301
343
  async populateSetFixedTermEndTime(endTime) {
302
344
  const { status } = this.previewSetFixedTermEndTime(endTime);
303
345
  (0, utils_1.assert)(status === validation_1.SetFixedTermEndTimeStatus.Ready, `Cannot set fixed term end time: ${status}`);
304
346
  const config = this.market.hooksConfig;
305
347
  (0, utils_1.assert)(config !== undefined, `V2 market missing hooksConfig`);
306
- return (0, utils_1.prepareTransaction)({
348
+ const iface = typechain_1.IFixedTermHooks__factory.createInterface();
349
+ return {
307
350
  to: config.hooksAddress,
308
- abi: abi_1.iFixedTermHooksAbi,
309
- functionName: "setFixedTermEndTime",
310
- args: [this.market.address, endTime]
311
- });
351
+ data: iface.encodeFunctionData("setFixedTermEndTime", [this.market.address, endTime]),
352
+ value: "0"
353
+ };
312
354
  }
313
355
  async setMinimumDeposit(amount) {
314
- return (0, viem_write_1.submitPreparedTransaction)(this.market.signer, await this.populateSetMinimumDeposit(amount));
356
+ const { status } = this.previewSetMinimumDeposit(amount);
357
+ (0, utils_1.assert)(status === validation_1.SetMinimumDepositStatus.Ready, `Cannot set minimum deposit: ${status}`);
358
+ const config = this.market.hooksConfig;
359
+ (0, utils_1.assert)(config !== undefined, `V2 market missing hooksConfig`);
360
+ const contract = typechain_1.IOpenTermHooks__factory.connect(config.hooksAddress, this.market.signer);
361
+ return contract.setMinimumDeposit(this.market.address, amount.raw);
362
+ }
363
+ async proposeAnnualInterestBips(apr) {
364
+ const { status } = this.previewProposeAnnualInterestBips(apr);
365
+ (0, utils_1.assert)(status === validation_1.ProposeAnnualInterestBipsStatus.Ready, `Cannot propose APR reduction: ${status}`);
366
+ const config = this.market.hooksConfig;
367
+ (0, utils_1.assert)(config !== undefined, `V2 market missing hooksConfig`);
368
+ const contract = typechain_1.IPeriodicTermHooks__factory.connect(config.hooksAddress, this.market.signer);
369
+ return contract.proposeAnnualInterestBips(this.market.address, apr);
315
370
  }
316
371
  async setFixedTermEndTime(endTime) {
317
- return (0, viem_write_1.submitPreparedTransaction)(this.market.signer, await this.populateSetFixedTermEndTime(endTime));
372
+ const { status } = this.previewSetFixedTermEndTime(endTime);
373
+ (0, utils_1.assert)(status === validation_1.SetFixedTermEndTimeStatus.Ready, `Cannot set fixed term end time: ${status}`);
374
+ const config = this.market.hooksConfig;
375
+ (0, utils_1.assert)(config !== undefined, `V2 market missing hooksConfig`);
376
+ const contract = typechain_1.IFixedTermHooks__factory.connect(config.hooksAddress, this.market.signer);
377
+ return contract.setFixedTermEndTime(this.market.address, endTime);
318
378
  }
319
379
  /* -------------------------------------------------------------------------- */
320
380
  /* Management Actions */
321
381
  /* -------------------------------------------------------------------------- */
322
382
  async closeMarket() {
323
- return (0, viem_write_1.submitPreparedTransaction)(this.market.signer, this.populateCloseMarket());
383
+ const { status } = this.previewCloseMarket();
384
+ (0, utils_1.assert)(status === validation_1.CloseMarketStatus.Ready, `Cannot close market: ${status}`);
385
+ if (this.market.version === types_1.MarketVersion.V1) {
386
+ (0, utils_1.assert)(this.market.controller !== undefined, "Controller address is required for V1 markets");
387
+ const controller = (0, constants_1.getControllerContract)(this.market.signer, this.market.controller);
388
+ return controller.closeMarket(this.market.address);
389
+ }
390
+ return this.market.contract.closeMarket();
324
391
  }
325
392
  populateCloseMarket() {
326
393
  const { status } = this.previewCloseMarket();
327
394
  (0, utils_1.assert)(status === validation_1.CloseMarketStatus.Ready, `Cannot close market: ${status}`);
328
395
  if (this.market.version === types_1.MarketVersion.V1) {
329
396
  (0, utils_1.assert)(this.market.controller !== undefined, "Controller address is required for V1 markets");
330
- return (0, utils_1.prepareTransaction)({
331
- to: this.market.controller,
332
- abi: abi_1.wildcatMarketControllerAbi,
333
- functionName: "closeMarket",
334
- args: [this.market.address]
335
- });
336
- }
337
- return (0, utils_1.prepareTransaction)({
397
+ const controller = (0, constants_1.getControllerContract)(this.market.signer, this.market.controller);
398
+ return {
399
+ to: controller.address,
400
+ data: controller.interface.encodeFunctionData("closeMarket", [this.market.address]),
401
+ value: "0"
402
+ };
403
+ }
404
+ return {
338
405
  to: this.market.address,
339
- abi: abi_1.wildcatMarketV2Abi,
340
- functionName: "closeMarket"
341
- });
406
+ data: this.market.contract.interface.encodeFunctionData("closeMarket"),
407
+ value: "0"
408
+ };
342
409
  }
343
410
  async setMaxTotalSupply(amount) {
344
411
  const { status } = this.previewSetMaxTotalSupply(amount);
345
412
  (0, utils_1.assert)(status === validation_1.SetMaxTotalSupplyStatus.Ready, `Cannot close market: ${status}`);
346
413
  if (this.market.version === types_1.MarketVersion.V1) {
347
414
  (0, utils_1.assert)(this.market.controller !== undefined, "Controller address is required for V1 markets");
348
- return (0, viem_write_1.submitPreparedTransaction)(this.market.signer, (0, utils_1.prepareTransaction)({
349
- to: this.market.controller,
350
- abi: abi_1.wildcatMarketControllerAbi,
351
- functionName: "setMaxTotalSupply",
352
- args: [this.market.address, amount.raw]
353
- }));
354
- }
355
- return (0, viem_write_1.submitPreparedTransaction)(this.market.signer, (0, utils_1.prepareTransaction)({
356
- to: this.market.address,
357
- abi: abi_1.wildcatMarketV2Abi,
358
- functionName: "setMaxTotalSupply",
359
- args: [amount.raw]
360
- }));
415
+ const controller = (0, constants_1.getControllerContract)(this.market.signer, this.market.controller);
416
+ return controller.setMaxTotalSupply(this.market.address, amount.raw);
417
+ }
418
+ else {
419
+ return this.market.contract.setMaxTotalSupply(amount.raw);
420
+ }
361
421
  }
362
422
  async setAnnualInterestBips(newAprBips) {
363
423
  const { status } = this.previewSetAPR(newAprBips);
364
424
  (0, utils_1.assert)(status === validation_1.SetAprStatus.Ready, `Cannot set new APR of ${newAprBips / 10000}%: ${status}`);
365
425
  if (this.market.version === types_1.MarketVersion.V1) {
366
426
  (0, utils_1.assert)(this.market.controller !== undefined, "Controller address is required for V1 markets");
367
- return (0, viem_write_1.submitPreparedTransaction)(this.market.signer, (0, utils_1.prepareTransaction)({
368
- to: this.market.controller,
369
- abi: abi_1.wildcatMarketControllerAbi,
370
- functionName: "setAnnualInterestBips",
371
- args: [this.market.address, newAprBips]
372
- }));
373
- }
374
- return (0, viem_write_1.submitPreparedTransaction)(this.market.signer, (0, utils_1.prepareTransaction)({
375
- to: this.market.address,
376
- abi: abi_1.wildcatMarketV2Abi,
377
- functionName: "setAnnualInterestAndReserveRatioBips",
378
- args: [newAprBips, this.market.reserveRatioBips]
379
- }));
427
+ const controller = (0, constants_1.getControllerContract)(this.market.provider, this.market.controller);
428
+ return controller.setAnnualInterestBips(this.market.address, newAprBips);
429
+ }
430
+ else {
431
+ const contract = typechain_1.WildcatMarketV2__factory.connect(this.market.address, this.market.signer);
432
+ return contract.setAnnualInterestAndReserveRatioBips(newAprBips, this.market.reserveRatioBips);
433
+ }
380
434
  }
381
435
  /* -------------------------------------------------------------------------- */
382
436
  /* Approval */
383
437
  /* -------------------------------------------------------------------------- */
384
438
  isApprovedFor(amount) {
385
- return this.underlyingApproval >= amount.raw;
439
+ return this.underlyingApproval.gte(amount.raw);
386
440
  }
387
441
  async approveMarket(amount) {
388
- return (0, viem_write_1.submitPreparedTransaction)(this.market.signer, await this.populateApproveMarket(amount));
442
+ const token = this.market.underlyingToken;
443
+ const signer = await token.signer.getAddress();
444
+ if (signer.toLowerCase() !== this.account.toLowerCase()) {
445
+ throw Error(`MarketAccount signer ${signer} does not match ${this.account}`);
446
+ }
447
+ return token.contract.approve(this.market.address, amount.raw);
389
448
  }
390
449
  async populateApproveMarket(amount) {
391
450
  const token = this.market.underlyingToken;
@@ -393,12 +452,14 @@ class MarketAccount {
393
452
  if (signer.toLowerCase() !== this.account.toLowerCase()) {
394
453
  throw Error(`MarketAccount signer ${signer} does not match ${this.account}`);
395
454
  }
396
- return (0, utils_1.prepareTransaction)({
455
+ return {
397
456
  to: token.address,
398
- abi: abi_1.iERC20Abi,
399
- functionName: "approve",
400
- args: [this.market.address, amount.raw]
401
- });
457
+ data: token.contract.interface.encodeFunctionData("approve", [
458
+ this.market.address,
459
+ amount.raw
460
+ ]),
461
+ value: "0"
462
+ };
402
463
  }
403
464
  /* -------------------------------------------------------------------------- */
404
465
  /* ForceBuyBack */
@@ -412,9 +473,6 @@ class MarketAccount {
412
473
  if (this.market.chainId !== constants_1.SupportedChainId.Sepolia) {
413
474
  return { status: validation_1.ForceBuyBackStatus.MainnetNotSupported };
414
475
  }
415
- if (!this.market.hooksConfig?.allowForceBuyBacks) {
416
- return { status: validation_1.ForceBuyBackStatus.HooksNotSupported };
417
- }
418
476
  if (amount.gt(this.underlyingBalance)) {
419
477
  return { status: validation_1.ForceBuyBackStatus.InsufficientBalance };
420
478
  }
@@ -429,17 +487,20 @@ class MarketAccount {
429
487
  };
430
488
  }
431
489
  async forceBuyBack(lender, amount) {
432
- return (0, viem_write_1.submitPreparedTransaction)(this.market.signer, this.populateForceBuyBack(lender, amount));
490
+ const { status } = this.previewForceBuyBack(lender, amount);
491
+ (0, utils_1.assert)(status === validation_1.ForceBuyBackStatus.Ready, `Cannot force buy back: ${status}`);
492
+ const contract = typechain_1.WildcatMarketV2__factory.connect(this.market.address, this.market.signer);
493
+ return await contract.forceBuyBack(lender, amount.raw);
433
494
  }
434
495
  populateForceBuyBack(lender, amount) {
435
496
  const { status } = this.previewForceBuyBack(lender, amount);
436
497
  (0, utils_1.assert)(status === validation_1.ForceBuyBackStatus.Ready, `Cannot force buy back: ${status}`);
437
- return (0, utils_1.prepareTransaction)({
498
+ const contract = typechain_1.WildcatMarketV2__factory.connect(this.market.address, this.market.signer);
499
+ return {
438
500
  to: this.market.address,
439
- abi: abi_1.wildcatMarketV2Abi,
440
- functionName: "forceBuyBack",
441
- args: [lender, amount.raw]
442
- });
501
+ data: contract.interface.encodeFunctionData("forceBuyBack", [lender, amount.raw]),
502
+ value: "0"
503
+ };
443
504
  }
444
505
  /* -------------------------------------------------------------------------- */
445
506
  /* Deposits */
@@ -485,15 +546,20 @@ class MarketAccount {
485
546
  if (signer.toLowerCase() !== this.account.toLowerCase()) {
486
547
  throw Error(`MarketAccount signer ${signer} does not match ${this.account}`);
487
548
  }
488
- return (0, utils_1.prepareTransaction)({
549
+ return {
489
550
  to: this.market.address,
490
- abi: abi_1.wildcatMarketAbi,
491
- functionName: "deposit",
492
- args: [amount.raw]
493
- });
551
+ data: this.market.contract.interface.encodeFunctionData("deposit", [amount.raw]),
552
+ value: "0"
553
+ };
494
554
  }
495
555
  async deposit(amount) {
496
- return (0, viem_write_1.submitPreparedTransaction)(this.market.signer, await this.populateDeposit(amount));
556
+ const { status } = this.previewDeposit(amount);
557
+ (0, utils_1.assert)(status === validation_1.DepositStatus.Ready, `Cannot deposit: ${status}`);
558
+ const signer = await this.market.signer.getAddress();
559
+ if (signer.toLowerCase() !== this.account.toLowerCase()) {
560
+ throw Error(`MarketAccount signer ${signer} does not match ${this.account}`);
561
+ }
562
+ return this.market.contract.deposit(amount.raw);
497
563
  }
498
564
  /* ------ Withdrawals ------ */
499
565
  previewQueueWithdrawal(amount) {
@@ -512,19 +578,17 @@ class MarketAccount {
512
578
  if (signer.toLowerCase() !== this.account.toLowerCase()) {
513
579
  throw Error(`MarketAccount signer ${signer} does not match ${this.account}`);
514
580
  }
515
- const { hash, receipt, transaction } = await (0, viem_write_1.submitPreparedTransactionAndWait)(this.market.provider, this.market.signer, (0, utils_1.prepareTransaction)({
516
- to: this.market.address,
517
- abi: abi_1.wildcatMarketAbi,
518
- functionName: "queueWithdrawal",
519
- args: [amount.raw]
520
- }));
521
- const queuedWithdrawalTransaction = toQueueWithdrawalTransaction(this.market.underlyingToken, receipt, this.market.address);
581
+ const transaction = await this.market.contract.queueWithdrawal(amount.raw);
582
+ const receipt = await transaction.wait();
583
+ const queuedWithdrawalTopic = this.market.contract.interface.getEventTopic("WithdrawalQueued");
584
+ const queuedWithdrawalTransaction = toQueueWithdrawalTransaction(this.market.underlyingToken, receipt.events.find((e) => e.topics[0] === queuedWithdrawalTopic));
585
+ if (!queuedWithdrawalTransaction)
586
+ throw Error("No queued withdrawal event found");
522
587
  const withdrawal = await withdrawal_status_1.LenderWithdrawalStatus.getWithdrawalForLender(this.market, queuedWithdrawalTransaction.expiry, this.account);
523
588
  return {
524
- hash,
525
- receipt,
589
+ withdrawal,
526
590
  transaction,
527
- result: withdrawal
591
+ receipt
528
592
  };
529
593
  }
530
594
  async queueFullWithdrawal() {
@@ -534,25 +598,24 @@ class MarketAccount {
534
598
  if (signer.toLowerCase() !== this.account.toLowerCase()) {
535
599
  throw Error(`MarketAccount signer ${signer} does not match ${this.account}`);
536
600
  }
537
- const { hash, receipt, transaction } = await (0, viem_write_1.submitPreparedTransactionAndWait)(this.market.provider, this.market.signer, this.market.version === types_1.MarketVersion.V2
538
- ? (0, utils_1.prepareTransaction)({
539
- to: this.market.address,
540
- abi: abi_1.wildcatMarketV2Abi,
541
- functionName: "queueFullWithdrawal"
542
- })
543
- : (0, utils_1.prepareTransaction)({
544
- to: this.market.address,
545
- abi: abi_1.wildcatMarketAbi,
546
- functionName: "queueWithdrawal",
547
- args: [this.marketBalance.raw]
548
- }));
549
- const queuedWithdrawalTransaction = toQueueWithdrawalTransaction(this.market.underlyingToken, receipt, this.market.address);
601
+ let transaction;
602
+ if (this.market.version === types_1.MarketVersion.V2) {
603
+ const contract = typechain_1.WildcatMarketV2__factory.connect(this.market.address, this.market.signer);
604
+ transaction = await contract.queueFullWithdrawal();
605
+ }
606
+ else {
607
+ transaction = await this.market.contract.queueWithdrawal(this.marketBalance.raw);
608
+ }
609
+ const receipt = await transaction.wait();
610
+ const queuedWithdrawalTopic = this.market.contract.interface.getEventTopic("WithdrawalQueued");
611
+ const queuedWithdrawalTransaction = toQueueWithdrawalTransaction(this.market.underlyingToken, receipt.events.find((e) => e.topics[0] === queuedWithdrawalTopic));
612
+ if (!queuedWithdrawalTransaction)
613
+ throw Error("No queued withdrawal event found");
550
614
  const withdrawal = await withdrawal_status_1.LenderWithdrawalStatus.getWithdrawalForLender(this.market, queuedWithdrawalTransaction.expiry, this.account);
551
615
  return {
552
- hash,
553
- receipt,
616
+ withdrawal,
554
617
  transaction,
555
- result: withdrawal
618
+ receipt
556
619
  };
557
620
  }
558
621
  /* -------------------------------------------------------------------------- */
@@ -589,7 +652,13 @@ class MarketAccount {
589
652
  return { status: validation_1.RepayStatus.Ready };
590
653
  }
591
654
  async repay(amount) {
592
- return (0, viem_write_1.submitPreparedTransaction)(this.market.signer, await this.populateRepay(amount));
655
+ const signer = await this.market.signer.getAddress();
656
+ if (signer.toLowerCase() !== this.account.toLowerCase()) {
657
+ throw Error(`MarketAccount signer ${signer} does not match ${this.account}`);
658
+ }
659
+ if (!this.isBorrower)
660
+ throw Error("Only borrower can repay");
661
+ return this.market.contract.repay(amount);
593
662
  }
594
663
  async populateRepay(amount) {
595
664
  const signer = await this.market.signer.getAddress();
@@ -598,15 +667,23 @@ class MarketAccount {
598
667
  }
599
668
  if (!this.isBorrower)
600
669
  throw Error("Only borrower can repay");
601
- return (0, utils_1.prepareTransaction)({
670
+ return {
602
671
  to: this.market.address,
603
- abi: abi_1.wildcatMarketAbi,
604
- functionName: "repay",
605
- args: [(0, token_1.toRawAmount)(amount)]
606
- });
672
+ data: this.market.contract.interface.encodeFunctionData("repay", [amount]),
673
+ value: "0"
674
+ };
607
675
  }
608
676
  async repayOutstandingDebt() {
609
- return (0, viem_write_1.submitPreparedTransaction)(this.market.signer, await this.populateRepayOutstandingDebt());
677
+ if (this.market.version !== types_1.MarketVersion.V1) {
678
+ throw Error(`Only V1 supports repayOutstandingDebt`);
679
+ }
680
+ if (!this.isBorrower)
681
+ throw Error("Only borrower can repay");
682
+ const signer = await this.market.signer.getAddress();
683
+ if (signer.toLowerCase() !== this.account.toLowerCase()) {
684
+ throw Error(`MarketAccount signer ${signer} does not match ${this.account}`);
685
+ }
686
+ return this.market.contract.repayOutstandingDebt();
610
687
  }
611
688
  async populateRepayOutstandingDebt() {
612
689
  if (this.market.version !== types_1.MarketVersion.V1) {
@@ -618,14 +695,23 @@ class MarketAccount {
618
695
  if (signer.toLowerCase() !== this.account.toLowerCase()) {
619
696
  throw Error(`MarketAccount signer ${signer} does not match ${this.account}`);
620
697
  }
621
- return (0, utils_1.prepareTransaction)({
698
+ return {
622
699
  to: this.market.address,
623
- abi: abi_1.wildcatMarketAbi,
624
- functionName: "repayOutstandingDebt"
625
- });
700
+ data: this.market.contract.interface.encodeFunctionData("repayOutstandingDebt"),
701
+ value: "0"
702
+ };
626
703
  }
627
704
  async repayDelinquentDebt() {
628
- return (0, viem_write_1.submitPreparedTransaction)(this.market.signer, await this.populateRepayDelinquentDebt());
705
+ if (this.market.version !== types_1.MarketVersion.V1) {
706
+ throw Error(`Only V1 supports repayDelinquentDebt`);
707
+ }
708
+ if (!this.isBorrower)
709
+ throw Error("Only borrower can repay");
710
+ const signer = await this.market.signer.getAddress();
711
+ if (signer.toLowerCase() !== this.account.toLowerCase()) {
712
+ throw Error(`MarketAccount signer ${signer} does not match ${this.account}`);
713
+ }
714
+ return this.market.contract.repayDelinquentDebt();
629
715
  }
630
716
  async populateRepayDelinquentDebt() {
631
717
  if (this.market.version !== types_1.MarketVersion.V1) {
@@ -637,11 +723,11 @@ class MarketAccount {
637
723
  if (signer.toLowerCase() !== this.account.toLowerCase()) {
638
724
  throw Error(`MarketAccount signer ${signer} does not match ${this.account}`);
639
725
  }
640
- return (0, utils_1.prepareTransaction)({
726
+ return {
641
727
  to: this.market.address,
642
- abi: abi_1.wildcatMarketAbi,
643
- functionName: "repayDelinquentDebt"
644
- });
728
+ data: this.market.contract.interface.encodeFunctionData("repayDelinquentDebt"),
729
+ value: "0"
730
+ };
645
731
  }
646
732
  /* -------------------------------------------------------------------------- */
647
733
  /* Borrow */
@@ -662,69 +748,59 @@ class MarketAccount {
662
748
  if (amount.gt(this.market.borrowableAssets)) {
663
749
  throw Error("Insufficient borrowable assets");
664
750
  }
665
- return (0, viem_write_1.submitPreparedTransaction)(this.market.signer, (0, utils_1.prepareTransaction)({
666
- to: this.market.address,
667
- abi: abi_1.wildcatMarketAbi,
668
- functionName: "borrow",
669
- args: [amount.raw]
670
- }));
751
+ return this.market.contract.borrow(amount.raw);
671
752
  }
672
753
  /* -------------------------------------------------------------------------- */
673
754
  /* Updates */
674
755
  /* -------------------------------------------------------------------------- */
675
756
  async update() {
676
- if (this.market.version === types_1.MarketVersion.V1) {
677
- const acccountMarketInfo = await (0, market_lens_1.getLegacyMarketLenderStatus)(this.chainId, this.market.provider, this.account, this.market.address);
678
- this.updateWith(acccountMarketInfo);
679
- return;
680
- }
681
- const accountMarketInfo = await (0, market_lens_1.getLatestLenderAccountData)(this.chainId, this.market.provider, this.account, this.market.address);
682
- this.updateWith(accountMarketInfo);
757
+ const acccountMarketInfo = await (0, constants_1.getLensContract)(this.chainId, this.market.provider).getMarketLenderStatus(this.account, this.market.address);
758
+ this.updateWith(acccountMarketInfo);
683
759
  }
684
760
  updateWith(info) {
685
761
  if ("isAuthorizedOnController" in info) {
686
762
  (0, utils_1.assert)(this.market.version === types_1.MarketVersion.V1, "V2 market can not be updated with V1 lens data");
687
763
  this.isAuthorizedOnController = info.isAuthorizedOnController;
688
- this.role = (0, utils_1.toNumber)(info.role);
764
+ this.role = info.role;
689
765
  }
690
766
  else {
691
767
  (0, utils_1.assert)(this.market.version === types_1.MarketVersion.V2, "V1 market can not be updated with V2 lens data");
692
768
  this.credential = {
693
769
  canRefresh: info.canRefresh,
694
770
  isBlockedFromDeposits: info.isBlockedFromDeposits,
695
- lastApprovalTimestamp: (0, utils_1.toNumber)(info.lastApprovalTimestamp),
771
+ lastApprovalTimestamp: info.lastApprovalTimestamp,
696
772
  lastProvider: {
697
773
  isApproved: true,
698
774
  providerAddress: info.lastProvider.providerAddress,
699
- isPullProvider: (0, utils_1.toNumber)(info.lastProvider.pullProviderIndex) !== NullProviderIndex,
700
- isPushProvider: (0, utils_1.toNumber)(info.lastProvider.pushProviderIndex) !== NullProviderIndex,
701
- pullProviderIndex: (0, utils_1.toNumber)(info.lastProvider.pullProviderIndex),
702
- pushProviderIndex: (0, utils_1.toNumber)(info.lastProvider.pushProviderIndex),
703
- timeToLive: (0, utils_1.toNumber)(info.lastProvider.timeToLive)
775
+ isPullProvider: info.lastProvider.pullProviderIndex !== NullProviderIndex,
776
+ isPushProvider: info.lastProvider.pushProviderIndex !== NullProviderIndex,
777
+ pullProviderIndex: info.lastProvider.pullProviderIndex,
778
+ pushProviderIndex: info.lastProvider.pushProviderIndex,
779
+ timeToLive: info.lastProvider.timeToLive
704
780
  }
705
781
  };
706
782
  this.isKnownLender = info.isKnownLender;
707
783
  }
708
- this.scaledMarketBalance = (0, token_1.toRawAmount)(info.scaledBalance);
784
+ this.scaledMarketBalance = info.scaledBalance;
709
785
  this.marketBalance = this.market.marketToken.getAmount(info.normalizedBalance);
710
786
  this.underlyingBalance = this.market.underlyingToken.getAmount(info.underlyingBalance);
711
- this.underlyingApproval = (0, token_1.toRawAmount)(info.underlyingApproval);
787
+ this.underlyingApproval = info.underlyingApproval;
712
788
  this.processInterestAccrued();
713
789
  }
714
790
  calculateInterestEarned() {
715
791
  if (!this.lastScaleFactor)
716
- return 0n;
717
- if (this.scaledMarketBalance === 0n || this.lastScaleFactor === this.market.scaleFactor) {
718
- return 0n;
792
+ return ethers_1.BigNumber.from(0);
793
+ if (this.scaledMarketBalance.eq(0) || this.lastScaleFactor?.eq(this.market.scaleFactor)) {
794
+ return ethers_1.BigNumber.from(0);
719
795
  }
720
- const lastBalance = (0, utils_1.rayMulBigint)(this.scaledMarketBalance, this.lastScaleFactor);
721
- const currentBalance = (0, utils_1.rayMulBigint)(this.scaledMarketBalance, this.market.scaleFactor);
722
- return currentBalance - lastBalance;
796
+ const lastBalance = (0, utils_1.rayMul)(this.scaledMarketBalance, this.lastScaleFactor);
797
+ const currentBalance = (0, utils_1.rayMul)(this.scaledMarketBalance, this.market.scaleFactor);
798
+ return currentBalance.sub(lastBalance);
723
799
  }
724
800
  processInterestAccrued() {
725
801
  if (!this.lastScaleFactor || !this.totalInterestEarned)
726
802
  return;
727
- if (this.lastScaleFactor !== this.market.scaleFactor) {
803
+ if (!this.lastScaleFactor.eq(this.market.scaleFactor)) {
728
804
  const interestEarned = this.calculateInterestEarned();
729
805
  this.lastScaleFactor = this.market.scaleFactor;
730
806
  this.totalInterestEarned = this.totalInterestEarned.add(interestEarned);
@@ -737,19 +813,19 @@ class MarketAccount {
737
813
  /* Builders / Getters */
738
814
  /* -------------------------------------------------------------------------- */
739
815
  static fromSubgraphAccountData(market, data) {
740
- const scaledBalance = (0, token_1.toRawAmount)(data.scaledBalance);
816
+ const scaledBalance = ethers_1.BigNumber.from(data.scaledBalance);
741
817
  const account = new MarketAccount({
742
818
  account: data.address,
743
819
  isAuthorizedOnController: data.controllerAuthorization?.authorized ?? false,
744
820
  role: (0, utils_1.parseSubgraphLenderStatus)(data.role),
745
821
  scaledMarketBalance: scaledBalance,
746
- marketBalance: market.marketToken.getAmount((0, utils_1.rayMulBigint)(scaledBalance, market.scaleFactor)),
822
+ marketBalance: market.marketToken.getAmount((0, utils_1.rayMul)(scaledBalance, market.scaleFactor)),
747
823
  underlyingBalance: market.underlyingToken.getAmount(0),
748
- underlyingApproval: 0n,
824
+ underlyingApproval: ethers_1.BigNumber.from(0),
749
825
  market,
750
- deposits: "deposits" in data ? data.deposits : undefined,
826
+ deposits: data.deposits,
751
827
  totalDeposited: market.underlyingToken.getAmount(data.totalDeposited),
752
- lastScaleFactor: (0, token_1.toRawAmount)(data.lastScaleFactor),
828
+ lastScaleFactor: ethers_1.BigNumber.from(data.lastScaleFactor),
753
829
  lastUpdatedTimestamp: data.lastUpdatedTimestamp,
754
830
  totalInterestEarned: market.underlyingToken.getAmount(data.totalInterestEarned),
755
831
  numPendingWithdrawalBatches: data.numPendingWithdrawalBatches,
@@ -765,10 +841,10 @@ class MarketAccount {
765
841
  account,
766
842
  isAuthorizedOnController: info.isAuthorizedOnController,
767
843
  role: info.role,
768
- scaledMarketBalance: (0, token_1.toRawAmount)(info.scaledBalance),
844
+ scaledMarketBalance: info.scaledBalance,
769
845
  marketBalance: market.marketToken.getAmount(info.normalizedBalance),
770
846
  underlyingBalance: market.underlyingToken.getAmount(info.underlyingBalance),
771
- underlyingApproval: (0, token_1.toRawAmount)(info.underlyingApproval),
847
+ underlyingApproval: info.underlyingApproval,
772
848
  market
773
849
  });
774
850
  }
@@ -778,52 +854,46 @@ class MarketAccount {
778
854
  market,
779
855
  role: LenderRole.Null,
780
856
  marketBalance: market.marketToken.getAmount(data.normalizedBalance),
781
- scaledMarketBalance: (0, token_1.toRawAmount)(data.scaledBalance),
782
- underlyingApproval: (0, token_1.toRawAmount)(data.underlyingApproval),
857
+ scaledMarketBalance: data.scaledBalance,
858
+ underlyingApproval: data.underlyingApproval,
783
859
  underlyingBalance: market.underlyingToken.getAmount(data.underlyingBalance),
784
860
  isAuthorizedOnController: false,
785
861
  isKnownLender: data.isKnownLender,
786
862
  credential: {
787
863
  canRefresh: data.canRefresh,
788
864
  isBlockedFromDeposits: data.isBlockedFromDeposits,
789
- lastApprovalTimestamp: (0, utils_1.toNumber)(data.lastApprovalTimestamp),
865
+ lastApprovalTimestamp: data.lastApprovalTimestamp,
790
866
  lastProvider: {
791
867
  isApproved: true,
792
868
  providerAddress: data.lastProvider.providerAddress,
793
- isPullProvider: (0, utils_1.toNumber)(data.lastProvider.pullProviderIndex) !== NullProviderIndex,
794
- pullProviderIndex: (0, utils_1.toNumber)(data.lastProvider.pullProviderIndex),
795
- isPushProvider: (0, utils_1.toNumber)(data.lastProvider.pushProviderIndex) !== NullProviderIndex,
796
- pushProviderIndex: (0, utils_1.toNumber)(data.lastProvider.pushProviderIndex),
797
- timeToLive: (0, utils_1.toNumber)(data.lastProvider.timeToLive)
869
+ isPullProvider: data.lastProvider.pullProviderIndex !== NullProviderIndex,
870
+ pullProviderIndex: data.lastProvider.pullProviderIndex,
871
+ isPushProvider: data.lastProvider.pushProviderIndex !== NullProviderIndex,
872
+ pushProviderIndex: data.lastProvider.pushProviderIndex,
873
+ timeToLive: data.lastProvider.timeToLive
798
874
  }
799
875
  }
800
876
  });
801
877
  }
802
- static async fromMarketDataWithLenderStatus(chainId, provider, account, info) {
878
+ static fromMarketDataWithLenderStatus(chainId, provider, account, info) {
803
879
  if ("controller" in info.market) {
804
880
  info = info;
805
881
  return MarketAccount.fromMarketLenderStatus(account, info.lenderStatus, market_1.Market.fromMarketData(chainId, info.market, provider));
806
882
  }
807
- if ("allowForceBuyBacks" in info.market.hooksConfig) {
808
- const infoV2 = info;
809
- return MarketAccount.fromLenderAccountData(market_1.Market.fromMarketDataV2(chainId, provider, infoV2.market), infoV2.lenderStatus);
883
+ else {
884
+ info = info;
885
+ return MarketAccount.fromLenderAccountData(market_1.Market.fromMarketDataV2(chainId, provider, info.market), info.lenderStatus);
810
886
  }
811
- const infoV2_5 = info;
812
- const market = await market_1.Market.fromUnifiedMarketData(chainId, provider, infoV2_5.market);
813
- return MarketAccount.fromLenderAccountData(market, infoV2_5.lenderStatus);
814
- }
815
- static async hydrateMarketAccounts(chainId, provider, account, infos) {
816
- return Promise.all(infos.map((info) => MarketAccount.fromMarketDataWithLenderStatus(chainId, provider, account, info)));
817
887
  }
818
888
  static fromMarketDataOnly(market, account, isAuthorizedOnController) {
819
889
  return new MarketAccount({
820
890
  account,
821
891
  isAuthorizedOnController,
822
892
  role: LenderRole.Null,
823
- scaledMarketBalance: 0n,
893
+ scaledMarketBalance: ethers_1.BigNumber.from(0),
824
894
  marketBalance: market.marketToken.getAmount(0),
825
895
  underlyingBalance: market.underlyingToken.getAmount(0),
826
- underlyingApproval: 0n,
896
+ underlyingApproval: ethers_1.BigNumber.from(0),
827
897
  market
828
898
  });
829
899
  }
@@ -832,19 +902,16 @@ class MarketAccount {
832
902
  * If `market` is a string, the market data will be fetched in the same call as the account data.
833
903
  */
834
904
  static async getMarketAccount(chainId, provider, account, market) {
905
+ const lens = (0, constants_1.getLensContract)(chainId, provider);
835
906
  if (market instanceof market_1.Market) {
836
- if (market.version === types_1.MarketVersion.V1) {
837
- return (0, market_lens_1.getLegacyMarketLenderStatus)(chainId, provider, account, market.address).then((info) => MarketAccount.fromMarketLenderStatus(account, info, market));
838
- }
839
- return (0, market_lens_1.getLatestLenderAccountData)(chainId, provider, account, market.address).then((info) => MarketAccount.fromLenderAccountData(market, info));
840
- }
841
- try {
842
- const info = await (0, market_lens_1.getLatestMarketDataWithLenderStatus)(chainId, provider, account, market);
843
- return MarketAccount.fromMarketDataWithLenderStatus(chainId, provider, account, info);
907
+ return lens
908
+ .getMarketLenderStatus(account, market.address)
909
+ .then((info) => MarketAccount.fromMarketLenderStatus(account, info, market));
844
910
  }
845
- catch (_) {
846
- const info = await (0, market_lens_1.getLegacyMarketDataWithLenderStatus)(chainId, provider, account, market);
847
- return MarketAccount.fromMarketDataWithLenderStatus(chainId, provider, account, info);
911
+ else {
912
+ return lens
913
+ .getMarketDataWithLenderStatus(account, market)
914
+ .then((info) => MarketAccount.fromMarketDataWithLenderStatus(chainId, provider, account, info));
848
915
  }
849
916
  }
850
917
  /**
@@ -852,10 +919,17 @@ class MarketAccount {
852
919
  * If `market` is a string, the market data will be fetched in the same call as the account data.
853
920
  */
854
921
  static async getMarketAccountV2(chainId, provider, account, market) {
922
+ const lens = (0, constants_1.getLensV2Contract)(chainId, provider);
855
923
  if (market instanceof market_1.Market) {
856
- return (0, market_lens_1.getLatestLenderAccountData)(chainId, provider, account, market.address).then((info) => MarketAccount.fromLenderAccountData(market, info));
924
+ return lens
925
+ .getMarketDataWithLenderStatus(account, market.address)
926
+ .then((info) => MarketAccount.fromMarketDataWithLenderStatus(chainId, provider, account, info));
927
+ }
928
+ else {
929
+ return lens
930
+ .getMarketDataWithLenderStatus(account, market)
931
+ .then((info) => MarketAccount.fromMarketDataWithLenderStatus(chainId, provider, account, info));
857
932
  }
858
- return (0, market_lens_1.getLatestMarketDataWithLenderStatus)(chainId, provider, account, market).then((info) => MarketAccount.fromMarketDataWithLenderStatus(chainId, provider, account, info));
859
933
  }
860
934
  /**
861
935
  * Get multiple `MarketAccount`s given an account and existing list of `Market`
@@ -863,139 +937,51 @@ class MarketAccount {
863
937
  * data will be fetched in the same call as the account data.
864
938
  */
865
939
  static async getMarketAccountsForLender(chainId, provider, account, markets) {
940
+ const lens = (0, constants_1.getLensContract)(chainId, provider);
866
941
  if (markets.length === 0) {
867
942
  return [];
868
943
  }
869
944
  if ((0, validation_1.isMarketInstanceArray)(markets)) {
870
- const results = new Array(markets.length);
871
- const legacyIndexes = [];
872
- const latestIndexes = [];
873
- markets.forEach((market, index) => {
874
- if (market.version === types_1.MarketVersion.V1) {
875
- legacyIndexes.push(index);
876
- }
877
- else {
878
- latestIndexes.push(index);
879
- }
880
- });
881
- if (legacyIndexes.length > 0) {
882
- const legacyMarkets = legacyIndexes.map((index) => markets[index]);
883
- const infos = await (0, market_lens_1.getLegacyMarketsLenderStatus)(chainId, provider, account, legacyMarkets.map((market) => market.address));
884
- infos.forEach((info, i) => {
885
- results[legacyIndexes[i]] = MarketAccount.fromMarketLenderStatus(account, info, legacyMarkets[i]);
886
- });
887
- }
888
- if (latestIndexes.length > 0) {
889
- const latestMarkets = latestIndexes.map((index) => markets[index]);
890
- const infos = await (0, market_lens_1.getLatestLenderAccountsData)(chainId, provider, account, latestMarkets.map((market) => market.address));
891
- infos.forEach((info, i) => {
892
- results[latestIndexes[i]] = MarketAccount.fromLenderAccountData(latestMarkets[i], info);
893
- });
894
- }
895
- return results;
896
- }
897
- try {
898
- const infos = await (0, market_lens_1.getLatestMarketsDataWithLenderStatus)(chainId, provider, account, markets);
899
- return MarketAccount.hydrateMarketAccounts(chainId, provider, account, infos);
945
+ return lens
946
+ .getMarketsLenderStatus(account, markets.map((v) => v.address))
947
+ .then((infos) => infos.map((info, i) => MarketAccount.fromMarketLenderStatus(account, info, markets[i])));
900
948
  }
901
- catch (_) {
902
- const infos = await (0, market_lens_1.getLegacyMarketsDataWithLenderStatus)(chainId, provider, account, markets);
903
- return MarketAccount.hydrateMarketAccounts(chainId, provider, account, infos);
949
+ else {
950
+ return lens
951
+ .getMarketsDataWithLenderStatus(account, markets)
952
+ .then((infos) => infos.map((info) => MarketAccount.fromMarketDataWithLenderStatus(chainId, provider, account, info)));
904
953
  }
905
954
  }
906
- /**
907
- * Refresh existing V2 lender market accounts using the focused live lens surface when available.
908
- * Falls back to existing broad V2 market reads plus lender-account reads.
909
- */
910
- static async refreshMarketAccountsV2LiveData(chainId, provider, account, marketAccounts) {
911
- if (marketAccounts.length === 0) {
912
- return marketAccounts;
913
- }
914
- const lender = account ?? ZERO_ADDRESS;
915
- const shouldZeroBalances = !account;
916
- const marketAddresses = marketAccounts.map((marketAccount) => marketAccount.market.address);
917
- if (hasUnifiedLatestLensForAccountReads(chainId)) {
918
- try {
919
- const updates = await (0, market_lens_1.getUnifiedMarketsLiveDataWithLenderStatusV2)(chainId, provider, lender, marketAddresses);
920
- updates.forEach((update, i) => {
921
- marketAccounts[i].market.updateWithLiveData(update.market);
922
- marketAccounts[i].updateWith(shouldZeroBalances ? zeroLenderBalances(update.lenderStatus) : update.lenderStatus);
923
- });
924
- return marketAccounts;
925
- }
926
- catch (_) {
927
- // Fall back to existing reads for older unified lens deployments.
928
- }
929
- }
930
- const [refreshedMarkets, lenderStatuses] = await Promise.all([
931
- market_1.Market.getMarketsV2(chainId, marketAddresses, provider),
932
- (0, market_lens_1.getLatestLenderAccountsData)(chainId, provider, lender, marketAddresses)
933
- ]);
934
- marketAccounts.forEach((marketAccount, i) => {
935
- Object.assign(marketAccount.market, refreshedMarkets[i]);
936
- marketAccount.updateWith(shouldZeroBalances ? zeroLenderBalances(lenderStatuses[i]) : lenderStatuses[i]);
937
- });
938
- return marketAccounts;
939
- }
940
955
  /**
941
956
  * Get all `MarketAccount`s for a given account.
942
957
  * Fetches the market data in the same call as the account data.
943
958
  */
944
- static async getAllMarketAccountsForLender(chainId, provider, account) {
945
- if (hasUnifiedLatestLensForAccountReads(chainId)) {
946
- const markets = await (0, arch_controller_1.getRegisteredMarkets)(chainId, provider);
947
- if (markets.length === 0) {
948
- return [];
949
- }
950
- const infos = await (0, market_lens_1.getLatestMarketsDataWithLenderStatus)(chainId, provider, account, markets);
951
- return MarketAccount.hydrateMarketAccounts(chainId, provider, account, infos);
952
- }
953
- const infos = await (0, market_lens_1.getLegacyAllMarketsDataWithLenderStatus)(chainId, provider, account);
954
- return MarketAccount.hydrateMarketAccounts(chainId, provider, account, infos);
959
+ static getAllMarketAccountsForLender(chainId, provider, account) {
960
+ const lens = (0, constants_1.getLensContract)(chainId, provider);
961
+ return lens
962
+ .getAllMarketsDataWithLenderStatus(account)
963
+ .then((infos) => infos.map((info) => MarketAccount.fromMarketDataWithLenderStatus(chainId, provider, account, info)));
955
964
  }
956
965
  /**
957
966
  * Get paginated `MarketAccount`s for a given account.
958
967
  * Fetches the market data in the same call as the account data.
959
968
  * @note Throws an error if `start + count` exceeds the number of markets.
960
969
  */
961
- static async getPaginatedMarketAccounts(chainId, provider, account, start = 0, count) {
962
- if (hasUnifiedLatestLensForAccountReads(chainId)) {
963
- if (count <= 0) {
964
- return [];
965
- }
966
- const totalMarkets = await (0, arch_controller_1.getRegisteredMarketsCount)(chainId, provider);
967
- if (start >= totalMarkets) {
968
- return [];
969
- }
970
- const end = Math.min(start + count, totalMarkets);
971
- const markets = await (0, arch_controller_1.getRegisteredMarketsPage)(chainId, provider, start, end);
972
- if (markets.length === 0) {
973
- return [];
974
- }
975
- const infos = await (0, market_lens_1.getLatestMarketsDataWithLenderStatus)(chainId, provider, account, markets);
976
- return MarketAccount.hydrateMarketAccounts(chainId, provider, account, infos);
977
- }
978
- const infos = await (0, market_lens_1.getLegacyPaginatedMarketsDataWithLenderStatus)(chainId, provider, account, start, count);
979
- return MarketAccount.hydrateMarketAccounts(chainId, provider, account, infos);
970
+ static getPaginatedMarketAccounts(chainId, provider, account, start = 0, count) {
971
+ const lens = (0, constants_1.getLensContract)(chainId, provider);
972
+ return lens
973
+ .getPaginatedMarketsDataWithLenderStatus(account, start, count)
974
+ .then((infos) => infos.map((info) => MarketAccount.fromMarketDataWithLenderStatus(chainId, provider, account, info)));
980
975
  }
981
976
  }
982
977
  exports.MarketAccount = MarketAccount;
983
- const toQueueWithdrawalTransaction = (underlyingToken, receipt, marketAddress) => {
984
- const event = (0, viem_1.parseEventLogs)({
985
- abi: abi_1.wildcatMarketAbi,
986
- eventName: "WithdrawalQueued",
987
- logs: receipt.logs
988
- })[0];
989
- if (!event)
990
- throw Error("No queued withdrawal event found");
991
- return {
992
- transactionHash: receipt.transactionHash,
993
- blockNumber: Number(receipt.blockNumber),
994
- expiry: Number(event.args.expiry),
995
- lender: event.args.account,
996
- market: marketAddress,
997
- scaledAmount: (0, token_1.toRawAmount)(event.args.scaledAmount),
998
- originalAmount: underlyingToken.getAmount(event.args.normalizedAmount)
999
- };
1000
- };
978
+ const toQueueWithdrawalTransaction = (underlyingToken, log) => ({
979
+ transactionHash: log.transactionHash,
980
+ blockNumber: log.blockNumber,
981
+ expiry: log.args.expiry.toNumber(),
982
+ lender: log.args.account,
983
+ market: log.address,
984
+ scaledAmount: log.args.scaledAmount,
985
+ originalAmount: underlyingToken.getAmount(log.args.normalizedAmount)
986
+ });
1001
987
  //# sourceMappingURL=index.js.map