@wildcatfi/wildcat-sdk 3.0.77-beta → 3.1.2-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 (443) 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 +14 -99
  43. package/dist/constants.d.ts.map +1 -1
  44. package/dist/constants.js +21 -278
  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 +699 -1459
  75. package/dist/gql/graphql.d.ts.map +1 -1
  76. package/dist/gql/graphql.js +243 -545
  77. package/dist/gql/graphql.js.map +1 -1
  78. package/dist/gql/index.d.ts +0 -1
  79. package/dist/gql/index.d.ts.map +1 -1
  80. package/dist/gql/index.js +0 -1
  81. package/dist/gql/index.js.map +1 -1
  82. package/dist/index.d.ts +4 -5
  83. package/dist/index.d.ts.map +1 -1
  84. package/dist/index.js +17 -7
  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 +56 -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 +56 -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 +102 -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/Wildcat4626Wrapper.sol/IWildcatMarketToken.d.ts +176 -0
  165. package/dist/typechain/Wildcat4626Wrapper.sol/IWildcatMarketToken.d.ts.map +1 -0
  166. package/dist/typechain/Wildcat4626Wrapper.sol/IWildcatMarketToken.js +3 -0
  167. package/dist/typechain/Wildcat4626Wrapper.sol/IWildcatMarketToken.js.map +1 -0
  168. package/dist/typechain/Wildcat4626Wrapper.sol/IWildcatSanctionsSentinel.d.ts +44 -0
  169. package/dist/typechain/Wildcat4626Wrapper.sol/IWildcatSanctionsSentinel.d.ts.map +1 -0
  170. package/dist/typechain/Wildcat4626Wrapper.sol/IWildcatSanctionsSentinel.js +3 -0
  171. package/dist/typechain/Wildcat4626Wrapper.sol/IWildcatSanctionsSentinel.js.map +1 -0
  172. package/dist/typechain/Wildcat4626Wrapper.sol/Wildcat4626Wrapper.d.ts +501 -0
  173. package/dist/typechain/Wildcat4626Wrapper.sol/Wildcat4626Wrapper.d.ts.map +1 -0
  174. package/dist/typechain/Wildcat4626Wrapper.sol/Wildcat4626Wrapper.js +3 -0
  175. package/dist/typechain/Wildcat4626Wrapper.sol/Wildcat4626Wrapper.js.map +1 -0
  176. package/dist/typechain/Wildcat4626Wrapper.sol/index.d.ts +4 -0
  177. package/dist/typechain/Wildcat4626Wrapper.sol/index.d.ts.map +1 -0
  178. package/dist/typechain/Wildcat4626Wrapper.sol/index.js +3 -0
  179. package/dist/typechain/Wildcat4626Wrapper.sol/index.js.map +1 -0
  180. package/dist/typechain/Wildcat4626WrapperFactory.d.ts +83 -0
  181. package/dist/typechain/Wildcat4626WrapperFactory.d.ts.map +1 -0
  182. package/dist/typechain/Wildcat4626WrapperFactory.js +3 -0
  183. package/dist/typechain/Wildcat4626WrapperFactory.js.map +1 -0
  184. package/dist/typechain/WildcatArchController.d.ts +545 -0
  185. package/dist/typechain/WildcatArchController.d.ts.map +1 -0
  186. package/dist/typechain/WildcatArchController.js +3 -0
  187. package/dist/typechain/WildcatArchController.js.map +1 -0
  188. package/dist/typechain/WildcatCollateralFactory.d.ts +164 -0
  189. package/dist/typechain/WildcatCollateralFactory.d.ts.map +1 -0
  190. package/dist/typechain/WildcatCollateralFactory.js +3 -0
  191. package/dist/typechain/WildcatCollateralFactory.js.map +1 -0
  192. package/dist/typechain/WildcatMarket.d.ts +1062 -0
  193. package/dist/typechain/WildcatMarket.d.ts.map +1 -0
  194. package/dist/typechain/WildcatMarket.js +3 -0
  195. package/dist/typechain/WildcatMarket.js.map +1 -0
  196. package/dist/typechain/WildcatMarketController.d.ts +553 -0
  197. package/dist/typechain/WildcatMarketController.d.ts.map +1 -0
  198. package/dist/typechain/WildcatMarketController.js +3 -0
  199. package/dist/typechain/WildcatMarketController.js.map +1 -0
  200. package/dist/typechain/WildcatMarketControllerFactory.d.ts +344 -0
  201. package/dist/typechain/WildcatMarketControllerFactory.d.ts.map +1 -0
  202. package/dist/typechain/WildcatMarketControllerFactory.js +3 -0
  203. package/dist/typechain/WildcatMarketControllerFactory.js.map +1 -0
  204. package/dist/typechain/WildcatMarketV2.d.ts +1086 -0
  205. package/dist/typechain/WildcatMarketV2.d.ts.map +1 -0
  206. package/dist/typechain/WildcatMarketV2.js +3 -0
  207. package/dist/typechain/WildcatMarketV2.js.map +1 -0
  208. package/dist/typechain/common.d.ts +23 -0
  209. package/dist/typechain/common.d.ts.map +1 -0
  210. package/dist/typechain/common.js +3 -0
  211. package/dist/typechain/common.js.map +1 -0
  212. package/dist/typechain/factories/AccountQuery__factory.d.ts +63 -0
  213. package/dist/typechain/factories/AccountQuery__factory.d.ts.map +1 -0
  214. package/dist/typechain/factories/AccountQuery__factory.js +96 -0
  215. package/dist/typechain/factories/AccountQuery__factory.js.map +1 -0
  216. package/dist/typechain/factories/AccountsQuery__factory.d.ts +63 -0
  217. package/dist/typechain/factories/AccountsQuery__factory.d.ts.map +1 -0
  218. package/dist/typechain/factories/AccountsQuery__factory.js +96 -0
  219. package/dist/typechain/factories/AccountsQuery__factory.js.map +1 -0
  220. package/dist/typechain/factories/CheckBorrowersRegistered__factory.d.ts +36 -0
  221. package/dist/typechain/factories/CheckBorrowersRegistered__factory.d.ts.map +1 -0
  222. package/dist/typechain/factories/CheckBorrowersRegistered__factory.js +60 -0
  223. package/dist/typechain/factories/CheckBorrowersRegistered__factory.js.map +1 -0
  224. package/dist/typechain/factories/CheckSafeSignature__factory.d.ts +40 -0
  225. package/dist/typechain/factories/CheckSafeSignature__factory.d.ts.map +1 -0
  226. package/dist/typechain/factories/CheckSafeSignature__factory.js +65 -0
  227. package/dist/typechain/factories/CheckSafeSignature__factory.js.map +1 -0
  228. package/dist/typechain/factories/CollateralLens__factory.d.ts +854 -0
  229. package/dist/typechain/factories/CollateralLens__factory.d.ts.map +1 -0
  230. package/dist/typechain/factories/CollateralLens__factory.js +1101 -0
  231. package/dist/typechain/factories/CollateralLens__factory.js.map +1 -0
  232. package/dist/typechain/factories/DescribeSignature__factory.d.ts +145 -0
  233. package/dist/typechain/factories/DescribeSignature__factory.d.ts.map +1 -0
  234. package/dist/typechain/factories/DescribeSignature__factory.js +203 -0
  235. package/dist/typechain/factories/DescribeSignature__factory.js.map +1 -0
  236. package/dist/typechain/factories/HooksFactory__factory.d.ts +902 -0
  237. package/dist/typechain/factories/HooksFactory__factory.d.ts.map +1 -0
  238. package/dist/typechain/factories/HooksFactory__factory.js +1168 -0
  239. package/dist/typechain/factories/HooksFactory__factory.js.map +1 -0
  240. package/dist/typechain/factories/IERC20__factory.d.ts +235 -0
  241. package/dist/typechain/factories/IERC20__factory.d.ts.map +1 -0
  242. package/dist/typechain/factories/IERC20__factory.js +315 -0
  243. package/dist/typechain/factories/IERC20__factory.js.map +1 -0
  244. package/dist/typechain/factories/IFixedTermHooks__factory.d.ts +1894 -0
  245. package/dist/typechain/factories/IFixedTermHooks__factory.d.ts.map +1 -0
  246. package/dist/typechain/factories/IFixedTermHooks__factory.js +2423 -0
  247. package/dist/typechain/factories/IFixedTermHooks__factory.js.map +1 -0
  248. package/dist/typechain/factories/IOpenTermHooks__factory.d.ts +1791 -0
  249. package/dist/typechain/factories/IOpenTermHooks__factory.d.ts.map +1 -0
  250. package/dist/typechain/factories/IOpenTermHooks__factory.js +2293 -0
  251. package/dist/typechain/factories/IOpenTermHooks__factory.js.map +1 -0
  252. package/dist/typechain/factories/IPeriodicTermHooks__factory.d.ts +750 -0
  253. package/dist/typechain/factories/IPeriodicTermHooks__factory.d.ts.map +1 -0
  254. package/dist/typechain/factories/IPeriodicTermHooks__factory.js +975 -0
  255. package/dist/typechain/factories/IPeriodicTermHooks__factory.js.map +1 -0
  256. package/dist/typechain/factories/ISafe__factory.d.ts +163 -0
  257. package/dist/typechain/factories/ISafe__factory.d.ts.map +1 -0
  258. package/dist/typechain/factories/ISafe__factory.js +225 -0
  259. package/dist/typechain/factories/ISafe__factory.js.map +1 -0
  260. package/dist/typechain/factories/MarketLensV2__factory.d.ts +6708 -0
  261. package/dist/typechain/factories/MarketLensV2__factory.d.ts.map +1 -0
  262. package/dist/typechain/factories/MarketLensV2__factory.js +8574 -0
  263. package/dist/typechain/factories/MarketLensV2__factory.js.map +1 -0
  264. package/dist/typechain/factories/MarketLens__factory.d.ts +3572 -0
  265. package/dist/typechain/factories/MarketLens__factory.d.ts.map +1 -0
  266. package/dist/typechain/factories/MarketLens__factory.js +4569 -0
  267. package/dist/typechain/factories/MarketLens__factory.js.map +1 -0
  268. package/dist/typechain/factories/MockArchControllerOwner__factory.d.ts +85 -0
  269. package/dist/typechain/factories/MockArchControllerOwner__factory.d.ts.map +1 -0
  270. package/dist/typechain/factories/MockArchControllerOwner__factory.js +118 -0
  271. package/dist/typechain/factories/MockArchControllerOwner__factory.js.map +1 -0
  272. package/dist/typechain/factories/MockERC20Factory__factory.d.ts +114 -0
  273. package/dist/typechain/factories/MockERC20Factory__factory.d.ts.map +1 -0
  274. package/dist/typechain/factories/MockERC20Factory__factory.js +157 -0
  275. package/dist/typechain/factories/MockERC20Factory__factory.js.map +1 -0
  276. package/dist/typechain/factories/SimpleMarketCollateral__factory.d.ts +264 -0
  277. package/dist/typechain/factories/SimpleMarketCollateral__factory.d.ts.map +1 -0
  278. package/dist/typechain/factories/SimpleMarketCollateral__factory.js +354 -0
  279. package/dist/typechain/factories/SimpleMarketCollateral__factory.js.map +1 -0
  280. package/dist/typechain/factories/Wildcat4626Wrapper.sol/IWildcatMarketToken__factory.d.ts +193 -0
  281. package/dist/typechain/factories/Wildcat4626Wrapper.sol/IWildcatMarketToken__factory.d.ts.map +1 -0
  282. package/dist/typechain/factories/Wildcat4626Wrapper.sol/IWildcatMarketToken__factory.js +263 -0
  283. package/dist/typechain/factories/Wildcat4626Wrapper.sol/IWildcatMarketToken__factory.js.map +1 -0
  284. package/dist/typechain/factories/Wildcat4626Wrapper.sol/IWildcatSanctionsSentinel__factory.d.ts +27 -0
  285. package/dist/typechain/factories/Wildcat4626Wrapper.sol/IWildcatSanctionsSentinel__factory.d.ts.map +1 -0
  286. package/dist/typechain/factories/Wildcat4626Wrapper.sol/IWildcatSanctionsSentinel__factory.js +44 -0
  287. package/dist/typechain/factories/Wildcat4626Wrapper.sol/IWildcatSanctionsSentinel__factory.js.map +1 -0
  288. package/dist/typechain/factories/Wildcat4626Wrapper.sol/Wildcat4626Wrapper__factory.d.ts +718 -0
  289. package/dist/typechain/factories/Wildcat4626Wrapper.sol/Wildcat4626Wrapper__factory.d.ts.map +1 -0
  290. package/dist/typechain/factories/Wildcat4626Wrapper.sol/Wildcat4626Wrapper__factory.js +946 -0
  291. package/dist/typechain/factories/Wildcat4626Wrapper.sol/Wildcat4626Wrapper__factory.js.map +1 -0
  292. package/dist/typechain/factories/Wildcat4626Wrapper.sol/index.d.ts +4 -0
  293. package/dist/typechain/factories/Wildcat4626Wrapper.sol/index.d.ts.map +1 -0
  294. package/dist/typechain/factories/Wildcat4626Wrapper.sol/index.js +13 -0
  295. package/dist/typechain/factories/Wildcat4626Wrapper.sol/index.js.map +1 -0
  296. package/dist/typechain/factories/Wildcat4626WrapperFactory__factory.d.ts +82 -0
  297. package/dist/typechain/factories/Wildcat4626WrapperFactory__factory.d.ts.map +1 -0
  298. package/dist/typechain/factories/Wildcat4626WrapperFactory__factory.js +117 -0
  299. package/dist/typechain/factories/Wildcat4626WrapperFactory__factory.js.map +1 -0
  300. package/dist/typechain/factories/WildcatArchController__factory.d.ts +554 -0
  301. package/dist/typechain/factories/WildcatArchController__factory.d.ts.map +1 -0
  302. package/dist/typechain/factories/WildcatArchController__factory.js +728 -0
  303. package/dist/typechain/factories/WildcatArchController__factory.js.map +1 -0
  304. package/dist/typechain/factories/WildcatCollateralFactory__factory.d.ts +160 -0
  305. package/dist/typechain/factories/WildcatCollateralFactory__factory.d.ts.map +1 -0
  306. package/dist/typechain/factories/WildcatCollateralFactory__factory.js +223 -0
  307. package/dist/typechain/factories/WildcatCollateralFactory__factory.js.map +1 -0
  308. package/dist/typechain/factories/WildcatMarketControllerFactory__factory.d.ts +421 -0
  309. package/dist/typechain/factories/WildcatMarketControllerFactory__factory.d.ts.map +1 -0
  310. package/dist/typechain/factories/WildcatMarketControllerFactory__factory.js +549 -0
  311. package/dist/typechain/factories/WildcatMarketControllerFactory__factory.js.map +1 -0
  312. package/dist/typechain/factories/WildcatMarketController__factory.d.ts +671 -0
  313. package/dist/typechain/factories/WildcatMarketController__factory.d.ts.map +1 -0
  314. package/dist/typechain/factories/WildcatMarketController__factory.js +870 -0
  315. package/dist/typechain/factories/WildcatMarketController__factory.js.map +1 -0
  316. package/dist/typechain/factories/WildcatMarketV2__factory.d.ts +1304 -0
  317. package/dist/typechain/factories/WildcatMarketV2__factory.d.ts.map +1 -0
  318. package/dist/typechain/factories/WildcatMarketV2__factory.js +1680 -0
  319. package/dist/typechain/factories/WildcatMarketV2__factory.js.map +1 -0
  320. package/dist/typechain/factories/WildcatMarket__factory.d.ts +1326 -0
  321. package/dist/typechain/factories/WildcatMarket__factory.d.ts.map +1 -0
  322. package/dist/typechain/factories/WildcatMarket__factory.js +1712 -0
  323. package/dist/typechain/factories/WildcatMarket__factory.js.map +1 -0
  324. package/dist/typechain/factories/index.d.ts +26 -0
  325. package/dist/typechain/factories/index.d.ts.map +1 -0
  326. package/dist/typechain/factories/index.js +79 -0
  327. package/dist/typechain/factories/index.js.map +1 -0
  328. package/dist/typechain/index.d.ts +70 -84
  329. package/dist/typechain/index.d.ts.map +1 -1
  330. package/dist/typechain/index.js +79 -120
  331. package/dist/typechain/index.js.map +1 -1
  332. package/dist/types.d.ts +34 -75
  333. package/dist/types.d.ts.map +1 -1
  334. package/dist/types.js +16 -21
  335. package/dist/types.js.map +1 -1
  336. package/dist/utils/check-registered-borrowers.d.ts.map +1 -1
  337. package/dist/utils/check-registered-borrowers.js +6 -7
  338. package/dist/utils/check-registered-borrowers.js.map +1 -1
  339. package/dist/utils/describe-account.d.ts.map +1 -1
  340. package/dist/utils/describe-account.js +4 -33
  341. package/dist/utils/describe-account.js.map +1 -1
  342. package/dist/utils/describe-signature.d.ts.map +1 -1
  343. package/dist/utils/describe-signature.js +14 -66
  344. package/dist/utils/describe-signature.js.map +1 -1
  345. package/dist/utils/index.d.ts +0 -2
  346. package/dist/utils/index.d.ts.map +1 -1
  347. package/dist/utils/index.js +0 -2
  348. package/dist/utils/index.js.map +1 -1
  349. package/dist/utils/logger.d.ts.map +1 -1
  350. package/dist/utils/logger.js +1 -0
  351. package/dist/utils/logger.js.map +1 -1
  352. package/dist/utils/math.d.ts +13 -1
  353. package/dist/utils/math.d.ts.map +1 -1
  354. package/dist/utils/math.js +50 -14
  355. package/dist/utils/math.js.map +1 -1
  356. package/dist/utils/misc.d.ts +4 -5
  357. package/dist/utils/misc.d.ts.map +1 -1
  358. package/dist/utils/misc.js +6 -6
  359. package/dist/utils/misc.js.map +1 -1
  360. package/dist/utils/record-types.d.ts +10 -7
  361. package/dist/utils/record-types.d.ts.map +1 -1
  362. package/dist/utils/record-types.js +2 -2
  363. package/dist/utils/record-types.js.map +1 -1
  364. package/dist/utils/type-parsers.d.ts +3 -9
  365. package/dist/utils/type-parsers.d.ts.map +1 -1
  366. package/dist/utils/type-parsers.js +13 -12
  367. package/dist/utils/type-parsers.js.map +1 -1
  368. package/dist/withdrawal-batch.d.ts +9 -10
  369. package/dist/withdrawal-batch.d.ts.map +1 -1
  370. package/dist/withdrawal-batch.js +31 -30
  371. package/dist/withdrawal-batch.js.map +1 -1
  372. package/dist/withdrawal-status.d.ts +7 -10
  373. package/dist/withdrawal-status.d.ts.map +1 -1
  374. package/dist/withdrawal-status.js +13 -16
  375. package/dist/withdrawal-status.js.map +1 -1
  376. package/dist/wrapper/index.d.ts +25 -43
  377. package/dist/wrapper/index.d.ts.map +1 -1
  378. package/dist/wrapper/index.js +73 -161
  379. package/dist/wrapper/index.js.map +1 -1
  380. package/package.json +12 -20
  381. package/dist/abi/generated.d.ts +0 -34504
  382. package/dist/abi/generated.d.ts.map +0 -1
  383. package/dist/abi/generated.js +0 -44192
  384. package/dist/abi/generated.js.map +0 -1
  385. package/dist/abi/index.d.ts +0 -3
  386. package/dist/abi/index.d.ts.map +0 -1
  387. package/dist/abi/index.js +0 -19
  388. package/dist/abi/index.js.map +0 -1
  389. package/dist/abi/manual.d.ts +0 -354
  390. package/dist/abi/manual.d.ts.map +0 -1
  391. package/dist/abi/manual.js +0 -202
  392. package/dist/abi/manual.js.map +0 -1
  393. package/dist/access/revolving.d.ts +0 -8
  394. package/dist/access/revolving.d.ts.map +0 -1
  395. package/dist/access/revolving.js +0 -15
  396. package/dist/access/revolving.js.map +0 -1
  397. package/dist/access/subgraph-template.d.ts +0 -14
  398. package/dist/access/subgraph-template.d.ts.map +0 -1
  399. package/dist/access/subgraph-template.js +0 -20
  400. package/dist/access/subgraph-template.js.map +0 -1
  401. package/dist/client.d.ts +0 -22
  402. package/dist/client.d.ts.map +0 -1
  403. package/dist/client.js +0 -51
  404. package/dist/client.js.map +0 -1
  405. package/dist/gql/getMarketList.d.ts +0 -16
  406. package/dist/gql/getMarketList.d.ts.map +0 -1
  407. package/dist/gql/getMarketList.js +0 -23
  408. package/dist/gql/getMarketList.js.map +0 -1
  409. package/dist/internal/arch-controller.d.ts +0 -6
  410. package/dist/internal/arch-controller.d.ts.map +0 -1
  411. package/dist/internal/arch-controller.js +0 -36
  412. package/dist/internal/arch-controller.js.map +0 -1
  413. package/dist/internal/ethers-signer.d.ts +0 -4
  414. package/dist/internal/ethers-signer.d.ts.map +0 -1
  415. package/dist/internal/ethers-signer.js +0 -12
  416. package/dist/internal/ethers-signer.js.map +0 -1
  417. package/dist/internal/ethers-viem.d.ts +0 -4
  418. package/dist/internal/ethers-viem.d.ts.map +0 -1
  419. package/dist/internal/ethers-viem.js +0 -43
  420. package/dist/internal/ethers-viem.js.map +0 -1
  421. package/dist/internal/market-lens.d.ts +0 -28
  422. package/dist/internal/market-lens.d.ts.map +0 -1
  423. package/dist/internal/market-lens.js +0 -125
  424. package/dist/internal/market-lens.js.map +0 -1
  425. package/dist/internal/viem-read.d.ts +0 -3
  426. package/dist/internal/viem-read.d.ts.map +0 -1
  427. package/dist/internal/viem-read.js +0 -13
  428. package/dist/internal/viem-read.js.map +0 -1
  429. package/dist/internal/viem-write.d.ts +0 -10
  430. package/dist/internal/viem-write.d.ts.map +0 -1
  431. package/dist/internal/viem-write.js +0 -51
  432. package/dist/internal/viem-write.js.map +0 -1
  433. package/dist/lens-types.d.ts +0 -309
  434. package/dist/lens-types.d.ts.map +0 -1
  435. package/dist/lens-types.js.map +0 -1
  436. package/dist/utils/bigint.d.ts +0 -22
  437. package/dist/utils/bigint.d.ts.map +0 -1
  438. package/dist/utils/bigint.js +0 -111
  439. package/dist/utils/bigint.js.map +0 -1
  440. package/dist/utils/viem-encoding.d.ts +0 -15
  441. package/dist/utils/viem-encoding.d.ts.map +0 -1
  442. package/dist/utils/viem-encoding.js +0 -33
  443. package/dist/utils/viem-encoding.js.map +0 -1
package/dist/market.js CHANGED
@@ -1,83 +1,40 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.Market = void 0;
4
- const viem_1 = require("viem");
4
+ const ethers_1 = require("ethers");
5
+ const abstract_signer_1 = require("@ethersproject/abstract-signer");
6
+ const typechain_1 = require("./typechain");
5
7
  const constants_1 = require("./constants");
6
- const arch_controller_1 = require("./internal/arch-controller");
7
- const market_lens_1 = require("./internal/market-lens");
8
8
  const token_1 = require("./token");
9
9
  const types_1 = require("./types");
10
+ const utils_1 = require("ethers/lib/utils");
10
11
  const account_1 = require("./account");
11
- const utils_1 = require("./utils");
12
+ const utils_2 = require("./utils");
12
13
  const access_1 = require("./access");
13
- const abi_1 = require("./abi");
14
- const viem_write_1 = require("./internal/viem-write");
15
- const ethers_signer_1 = require("./internal/ethers-signer");
16
- const hasUnifiedLatestLensForDirectReads = (chainId) => {
17
- return (0, constants_1.hasDeploymentAddress)(chainId, "MarketLensV2_5");
18
- };
19
- const toUnifiedMarketDataV2 = (data) => {
20
- if ("market" in data) {
21
- return data;
22
- }
23
- return {
24
- market: data,
25
- commitmentFeeBips: {
26
- isPresent: false,
27
- value: 0n
28
- },
29
- drawnAmount: {
30
- isPresent: false,
31
- value: 0n
32
- }
33
- };
34
- };
35
- const hasSubgraphMarketTotals = (data) => "totalBorrowed" in data;
36
- const hasSubgraphMarketRecords = (data) => "depositRecords" in data;
37
14
  class Market extends types_1.ContractWrapper {
15
+ get _contractAddress() {
16
+ return this.address;
17
+ }
38
18
  constructor({ provider, ...args }) {
39
19
  super(provider);
20
+ this.contractFactory = typechain_1.WildcatMarket__factory;
40
21
  const { address, name, symbol, decimals } = args.marketToken;
41
22
  Object.assign(this, {
42
23
  address,
43
24
  name,
44
25
  symbol,
45
- decimals,
46
- contract: {
47
- address,
48
- interface: {
49
- encodeFunctionData: (functionName, args = []) => (0, viem_1.encodeFunctionData)({
50
- abi: abi_1.wildcatMarketAbi,
51
- functionName,
52
- args
53
- })
54
- }
55
- }
26
+ decimals
56
27
  });
57
28
  Object.assign(this, args);
58
- this.depositRecords = (args.depositRecords ?? []).map((log) => (0, utils_1.parseMarketRecord)(this.underlyingToken, log));
59
- this.repaymentRecords = (args.repaymentRecords ?? []).map((log) => (0, utils_1.parseMarketRecord)(this.underlyingToken, log));
60
- this.borrowRecords = (args.borrowRecords ?? []).map((log) => (0, utils_1.parseMarketRecord)(this.underlyingToken, log));
29
+ this.depositRecords = (args.depositRecords ?? []).map((log) => (0, utils_2.parseMarketRecord)(this.underlyingToken, log));
30
+ this.repaymentRecords = (args.repaymentRecords ?? []).map((log) => (0, utils_2.parseMarketRecord)(this.underlyingToken, log));
31
+ this.borrowRecords = (args.borrowRecords ?? []).map((log) => (0, utils_2.parseMarketRecord)(this.underlyingToken, log));
61
32
  this.feeCollectionRecords = (args.feeCollectionRecords ?? []).map(({ feesCollected, __typename, ...rest }) => ({
62
33
  ...rest,
63
34
  __typename: "FeesCollected",
64
35
  amount: this.underlyingToken.getAmount(feesCollected)
65
36
  }));
66
37
  }
67
- toJSON() {
68
- return {
69
- type: "Market",
70
- chainId: this.chainId,
71
- address: this.address,
72
- name: this.name,
73
- symbol: this.symbol,
74
- decimals: this.decimals,
75
- version: this.version,
76
- marketType: this.marketType,
77
- hooksFactory: this.hooksFactory,
78
- borrower: this.borrower
79
- };
80
- }
81
38
  /* -------------------------------------------------------------------------- */
82
39
  /* Property Getters */
83
40
  /* -------------------------------------------------------------------------- */
@@ -93,86 +50,47 @@ class Market extends types_1.ContractWrapper {
93
50
  const fixedTermEndTime = config.fixedTermEndTime;
94
51
  return fixedTermEndTime >= Date.now() / 1000;
95
52
  }
53
+ get isPeriodicWithdrawalWindowOpen() {
54
+ if (this.version !== types_1.MarketVersion.V2)
55
+ return false;
56
+ const config = this.hooksConfig;
57
+ if (!config || config.kind !== types_1.HooksKind.PeriodicTerm)
58
+ return false;
59
+ if (this.isClosed || config.periodicTermClosed)
60
+ return true;
61
+ if (config.periodDuration === 0)
62
+ return false;
63
+ const now = Math.floor(Date.now() / 1000);
64
+ if (now < config.firstWithdrawalWindowStart)
65
+ return false;
66
+ return ((now - config.firstWithdrawalWindowStart) % config.periodDuration <
67
+ config.withdrawalWindowDuration);
68
+ }
69
+ get currentOrNextPeriodicWithdrawalWindowStart() {
70
+ if (this.version !== types_1.MarketVersion.V2)
71
+ return undefined;
72
+ const config = this.hooksConfig;
73
+ if (!config || config.kind !== types_1.HooksKind.PeriodicTerm || config.periodDuration === 0) {
74
+ return undefined;
75
+ }
76
+ const now = Math.floor(Date.now() / 1000);
77
+ if (now < config.firstWithdrawalWindowStart)
78
+ return config.firstWithdrawalWindowStart;
79
+ const timeInPeriod = (now - config.firstWithdrawalWindowStart) % config.periodDuration;
80
+ const windowStart = now - timeInPeriod;
81
+ return timeInPeriod < config.withdrawalWindowDuration
82
+ ? windowStart
83
+ : windowStart + config.periodDuration;
84
+ }
96
85
  /** @returns Percentage growth of the market since it was created */
97
86
  get allTimeGrowth() {
98
87
  // 27 - 2 to convert to percentage
99
- return +(0, utils_1.formatFixedBigint)(this.scaleFactor, 25, 25);
88
+ return +(0, utils_1.formatUnits)(this.scaleFactor, 25);
100
89
  }
101
90
  /** @returns Maximum amount of underlying token that can be deposited */
102
91
  get maximumDeposit() {
103
92
  return this.underlyingToken.getAmount(this.maxTotalSupply.satsub(this.totalSupply.raw));
104
93
  }
105
- get currentRevolvingAprMetrics() {
106
- const commitmentFeeBips = this.commitmentFeeBips;
107
- const drawnAmount = this.drawnAmount;
108
- if (commitmentFeeBips == null || drawnAmount == null) {
109
- return undefined;
110
- }
111
- const totalSupply = this.totalSupply.raw;
112
- const drawnAmountRaw = drawnAmount.raw > totalSupply ? totalSupply : drawnAmount.raw;
113
- const utilizationBips = totalSupply > 0n ? Number((drawnAmountRaw * utils_1.BIP_BIGINT) / totalSupply) : 0;
114
- const utilizationAprBips = totalSupply > 0n
115
- ? Number((drawnAmountRaw * BigInt(this.annualInterestBips)) / totalSupply)
116
- : 0;
117
- const blendedBaseAprBips = commitmentFeeBips + utilizationAprBips;
118
- const protocolAprBips = Number((BigInt(blendedBaseAprBips) * BigInt(this.protocolFeeBips)) / utils_1.BIP_BIGINT);
119
- const penaltyAprBips = this.isIncurringPenalties ? this.delinquencyFeeBips : 0;
120
- return {
121
- commitmentFeeBips,
122
- drawnAmount,
123
- utilizationBips,
124
- utilizationAprBips,
125
- blendedBaseAprBips,
126
- protocolAprBips,
127
- penaltyAprBips,
128
- effectiveLenderAprBips: blendedBaseAprBips + penaltyAprBips
129
- };
130
- }
131
- get currentBaseLenderAprBips() {
132
- return this.currentRevolvingAprMetrics?.blendedBaseAprBips ?? this.annualInterestBips;
133
- }
134
- get currentAprDisplayBips() {
135
- const revolvingMetrics = this.currentRevolvingAprMetrics;
136
- if (revolvingMetrics) {
137
- return {
138
- isRevolving: true,
139
- marketType: this.marketType,
140
- configuredAprKind: "utilization",
141
- configuredAprBips: this.annualInterestBips,
142
- configuredAnnualInterestBips: this.annualInterestBips,
143
- configuredUtilizationAprBips: this.annualInterestBips,
144
- commitmentAprBips: revolvingMetrics.commitmentFeeBips,
145
- utilizationBips: revolvingMetrics.utilizationBips,
146
- currentUtilizationAprBips: revolvingMetrics.utilizationAprBips,
147
- currentBaseLenderAprBips: revolvingMetrics.blendedBaseAprBips,
148
- currentProtocolAprBips: revolvingMetrics.protocolAprBips,
149
- currentPenaltyAprBips: revolvingMetrics.penaltyAprBips,
150
- currentEffectiveLenderAprBips: revolvingMetrics.effectiveLenderAprBips
151
- };
152
- }
153
- const currentProtocolAprBips = Number((BigInt(this.annualInterestBips) * BigInt(this.protocolFeeBips)) / utils_1.BIP_BIGINT);
154
- const currentPenaltyAprBips = this.isIncurringPenalties ? this.delinquencyFeeBips : 0;
155
- return {
156
- isRevolving: false,
157
- marketType: this.marketType,
158
- configuredAprKind: "annualInterest",
159
- configuredAprBips: this.annualInterestBips,
160
- configuredAnnualInterestBips: this.annualInterestBips,
161
- currentBaseLenderAprBips: this.annualInterestBips,
162
- currentProtocolAprBips,
163
- currentPenaltyAprBips,
164
- currentEffectiveLenderAprBips: this.annualInterestBips + currentPenaltyAprBips
165
- };
166
- }
167
- get currentBaseLenderAPR() {
168
- return (0, utils_1.bipToRayBigint)(this.currentBaseLenderAprBips);
169
- }
170
- get currentPenaltyAPR() {
171
- return this.isIncurringPenalties ? (0, utils_1.bipToRayBigint)(this.delinquencyFeeBips) : 0n;
172
- }
173
- get currentProtocolAPR() {
174
- return (0, utils_1.bipMulBigint)(this.currentBaseLenderAPR, this.protocolFeeBips);
175
- }
176
94
  /** @returns Whether the borrower is in penalized delinquency */
177
95
  get isIncurringPenalties() {
178
96
  return this.timeDelinquent > this.delinquencyGracePeriod;
@@ -218,7 +136,7 @@ class Market extends types_1.ContractWrapper {
218
136
  const targetRatio = this.reserveRatioBips / 100;
219
137
  const actualRatio = this.totalSupply.eq(0)
220
138
  ? 100
221
- : +(0, utils_1.formatFixedBigint)((this.totalAssets.raw * utils_1.RAY_BIGINT) / this.totalSupply.raw, 25, 25);
139
+ : +(0, utils_1.formatUnits)(this.totalAssets.raw.mul(utils_2.RAY).div(this.totalSupply.raw), 25);
222
140
  if (this.temporaryReserveRatio) {
223
141
  return {
224
142
  targetRatio,
@@ -231,7 +149,7 @@ class Market extends types_1.ContractWrapper {
231
149
  return { targetRatio, actualRatio };
232
150
  }
233
151
  get normalizedPendingWithdrawals() {
234
- return this.underlyingToken.getAmount((0, utils_1.rayMulBigint)(this.scaledPendingWithdrawals, this.scaleFactor));
152
+ return this.underlyingToken.getAmount((0, utils_2.rayMul)(this.scaledPendingWithdrawals, this.scaleFactor));
235
153
  }
236
154
  /** @returns Whether the borrower can change the APR */
237
155
  get canReduceAPR() {
@@ -247,7 +165,7 @@ class Market extends types_1.ContractWrapper {
247
165
  return this.totalAssets.satsub(unavailableAssets);
248
166
  }
249
167
  get minimumReserves() {
250
- return this.outstandingTotalSupply.bipMul(this.reserveRatioBips);
168
+ return this.underlyingToken.getAmount((0, utils_2.bipMul)(this.outstandingTotalSupply.raw, ethers_1.BigNumber.from(this.reserveRatioBips)));
251
169
  }
252
170
  get borrowableAssets() {
253
171
  return this.totalAssets.satsub(this.coverageLiquidity);
@@ -285,59 +203,63 @@ class Market extends types_1.ContractWrapper {
285
203
  };
286
204
  }
287
205
  normalizeAmount(amount) {
288
- return (0, utils_1.rayMulBigint)(amount, this.scaleFactor);
206
+ return (0, utils_2.rayMul)(amount, this.scaleFactor);
289
207
  }
290
208
  scaleAmount(amount) {
291
- return (0, utils_1.rayDivBigint)(amount, this.scaleFactor);
209
+ return (0, utils_2.rayDiv)(amount, this.scaleFactor);
292
210
  }
293
211
  get secondsBeforeDelinquency() {
294
212
  if (this.willBeDelinquent || this.totalDebts.eq(0))
295
213
  return 0;
296
214
  const scaledBase = this.scaledTotalSupply;
297
- const basePrincipal = this.underlyingToken.getAmount((0, utils_1.rayMulBigint)(scaledBase, this.scaleFactor));
298
- const baseAPRRay = this.currentBaseLenderAPR;
299
- const protocolFeeAPRRay = this.currentProtocolAPR;
300
- const delinquencyFeeAPRRay = this.currentPenaltyAPR;
215
+ const basePrincipal = this.underlyingToken.getAmount((0, utils_2.rayMul)(scaledBase, this.scaleFactor));
216
+ const baseAPRRay = (0, utils_2.bipToRay)(this.annualInterestBips);
217
+ const protocolFeeAPRRay = (0, utils_2.bipMul)(baseAPRRay, ethers_1.BigNumber.from(this.protocolFeeBips));
218
+ const delinquencyFeeAPRRay = this.timeDelinquent > this.delinquencyGracePeriod
219
+ ? (0, utils_2.bipToRay)(this.delinquencyFeeBips)
220
+ : ethers_1.BigNumber.from(0);
301
221
  // lender APR portion
302
222
  const lenderRequirementGrowthPerSecond = basePrincipal
303
- .rayMul(baseAPRRay + delinquencyFeeAPRRay)
304
- .div(utils_1.SECONDS_IN_365_DAYS)
223
+ .rayMul(baseAPRRay.add(delinquencyFeeAPRRay))
224
+ .div(utils_2.SECONDS_IN_365_DAYS)
305
225
  .bipMul(this.reserveRatioBips);
306
226
  // protocol fee portion
307
227
  const protocolRequirementGrowthPerSecond = basePrincipal
308
228
  .rayMul(protocolFeeAPRRay)
309
- .div(utils_1.SECONDS_IN_365_DAYS);
229
+ .div(utils_2.SECONDS_IN_365_DAYS);
310
230
  const totalRequirementGrowthPerSecond = lenderRequirementGrowthPerSecond.add(protocolRequirementGrowthPerSecond.raw);
311
231
  // essentially if apr=0 and rr=0 then bips alone wont move us to delinquency
312
- if (totalRequirementGrowthPerSecond.raw === 0n)
232
+ if (totalRequirementGrowthPerSecond.raw.isZero())
313
233
  return Number.MAX_SAFE_INTEGER;
314
234
  const buffer = this.liquidReserves.sub(this.minimumReserves);
315
- if (buffer.raw <= 0n)
235
+ if (buffer.raw.lte(0))
316
236
  return 0; // we are delinquent
317
- return Number(buffer.div(totalRequirementGrowthPerSecond, true).raw); // seconds until the party
237
+ return buffer.div(totalRequirementGrowthPerSecond, true).raw.toNumber(); // seconds until the party
318
238
  }
319
239
  getSecondsBeforeDelinquencyForBorrowedAmount(borrowAmount) {
320
240
  if (this.isDelinquent || this.totalDebts.eq(0))
321
241
  return 0;
322
242
  const scaledBase = this.scaledTotalSupply;
323
- const basePrincipal = this.underlyingToken.getAmount((0, utils_1.rayMulBigint)(scaledBase, this.scaleFactor));
324
- const baseAPRRay = this.currentBaseLenderAPR;
325
- const protocolFeeAPRRay = this.currentProtocolAPR;
326
- const delinquencyFeeAPRRay = this.currentPenaltyAPR;
243
+ const basePrincipal = this.underlyingToken.getAmount((0, utils_2.rayMul)(scaledBase, this.scaleFactor));
244
+ const baseAPRRay = (0, utils_2.bipToRay)(this.annualInterestBips);
245
+ const protocolFeeAPRRay = (0, utils_2.bipMul)(baseAPRRay, ethers_1.BigNumber.from(this.protocolFeeBips));
246
+ const delinquencyFeeAPRRay = this.timeDelinquent > this.delinquencyGracePeriod
247
+ ? (0, utils_2.bipToRay)(this.delinquencyFeeBips)
248
+ : ethers_1.BigNumber.from(0);
327
249
  const lenderRequirementGrowthPerSecond = basePrincipal
328
- .rayMul(baseAPRRay + delinquencyFeeAPRRay)
329
- .div(utils_1.SECONDS_IN_365_DAYS)
250
+ .rayMul(baseAPRRay.add(delinquencyFeeAPRRay))
251
+ .div(utils_2.SECONDS_IN_365_DAYS)
330
252
  .bipMul(this.reserveRatioBips);
331
253
  const protocolRequirementGrowthPerSecond = basePrincipal
332
254
  .rayMul(protocolFeeAPRRay)
333
- .div(utils_1.SECONDS_IN_365_DAYS);
255
+ .div(utils_2.SECONDS_IN_365_DAYS);
334
256
  const totalRequirementGrowthPerSecond = lenderRequirementGrowthPerSecond.add(protocolRequirementGrowthPerSecond.raw);
335
- if (totalRequirementGrowthPerSecond.raw === 0n)
257
+ if (totalRequirementGrowthPerSecond.raw.isZero())
336
258
  return Number.MAX_SAFE_INTEGER;
337
259
  const postBorrowBuffer = this.liquidReserves.sub(this.minimumReserves).sub(borrowAmount);
338
- if (postBorrowBuffer.raw <= 0n)
260
+ if (postBorrowBuffer.raw.lte(0))
339
261
  return 0;
340
- return Number(postBorrowBuffer.div(totalRequirementGrowthPerSecond, true).raw);
262
+ return postBorrowBuffer.div(totalRequirementGrowthPerSecond, true).raw.toNumber();
341
263
  }
342
264
  /**
343
265
  * @dev Calculate token amount to be repayed by borrower for a given duration
@@ -345,20 +267,22 @@ class Market extends types_1.ContractWrapper {
345
267
  * @return token amount to be repayed
346
268
  **/
347
269
  repayRequiredForDuration(timeToPayInSeconds) {
348
- const scaledBase = this.scaledTotalSupply - this.scaledPendingWithdrawals;
349
- if (scaledBase <= 0n)
270
+ const scaledBase = this.scaledTotalSupply.sub(this.scaledPendingWithdrawals);
271
+ if (scaledBase.lte(0))
350
272
  return this.underlyingToken.getAmount(0);
351
- const basePrincipal = this.underlyingToken.getAmount((0, utils_1.rayMulBigint)(scaledBase, this.scaleFactor));
352
- const baseAPRRay = this.currentBaseLenderAPR;
353
- const protocolFeeAPRRay = this.currentProtocolAPR;
354
- const delinquencyFeeAPRRay = this.currentPenaltyAPR;
273
+ const basePrincipal = this.underlyingToken.getAmount((0, utils_2.rayMul)(scaledBase, this.scaleFactor));
274
+ const baseAPRRay = (0, utils_2.bipToRay)(this.annualInterestBips);
275
+ const protocolFeeAPRRay = (0, utils_2.bipMul)(baseAPRRay, ethers_1.BigNumber.from(this.protocolFeeBips));
276
+ const delinquencyFeeAPRRay = this.timeDelinquent > this.delinquencyGracePeriod
277
+ ? (0, utils_2.bipToRay)(this.delinquencyFeeBips)
278
+ : ethers_1.BigNumber.from(0);
355
279
  const lenderRequirementGrowthPerSecond = basePrincipal
356
- .rayMul(baseAPRRay + delinquencyFeeAPRRay)
357
- .div(utils_1.SECONDS_IN_365_DAYS)
280
+ .rayMul(baseAPRRay.add(delinquencyFeeAPRRay))
281
+ .div(utils_2.SECONDS_IN_365_DAYS)
358
282
  .bipMul(this.reserveRatioBips);
359
283
  const protocolRequirementGrowthPerSecond = basePrincipal
360
284
  .rayMul(protocolFeeAPRRay)
361
- .div(utils_1.SECONDS_IN_365_DAYS);
285
+ .div(utils_2.SECONDS_IN_365_DAYS);
362
286
  const totalRequirementGrowthPerSecond = lenderRequirementGrowthPerSecond.add(protocolRequirementGrowthPerSecond.raw);
363
287
  return totalRequirementGrowthPerSecond.mul(timeToPayInSeconds);
364
288
  }
@@ -369,12 +293,13 @@ class Market extends types_1.ContractWrapper {
369
293
  *
370
294
  * @return apr paid by borrower in ray
371
295
  */
372
- // Preserve ethers-era consumers whose formatting helpers typed APR rays as BigNumber.
373
- // Runtime remains bigint, with BigInt compatibility methods installed by token.ts.
374
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
375
296
  get effectiveBorrowerAPR() {
376
- return ((0, utils_1.bipMulBigint)(this.currentBaseLenderAPR, utils_1.BIP_BIGINT + BigInt(this.protocolFeeBips)) +
377
- this.currentPenaltyAPR);
297
+ // apr + (apr * protocolFee)
298
+ let apr = (0, utils_2.bipMul)((0, utils_2.bipToRay)(this.annualInterestBips), utils_2.BIP.add(this.protocolFeeBips));
299
+ if (this.timeDelinquent > this.delinquencyGracePeriod) {
300
+ apr = apr.add((0, utils_2.bipToRay)(this.delinquencyFeeBips));
301
+ }
302
+ return apr;
378
303
  }
379
304
  /**
380
305
  * @dev Calculate effective interest rate currently earned by lenders.
@@ -382,41 +307,36 @@ class Market extends types_1.ContractWrapper {
382
307
  *
383
308
  * @return apr earned by lender in ray
384
309
  */
385
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
386
310
  get effectiveLenderAPR() {
387
- return this.currentBaseLenderAPR + this.currentPenaltyAPR;
311
+ let apr = this.annualInterestBips;
312
+ if (this.timeDelinquent > this.delinquencyGracePeriod) {
313
+ apr += this.delinquencyFeeBips;
314
+ }
315
+ return (0, utils_2.bipToRay)(apr);
388
316
  }
389
317
  /* -------------------------------------------------------------------------- */
390
318
  /* Withdrawal Execution */
391
319
  /* -------------------------------------------------------------------------- */
392
320
  async executeWithdrawal({ lender, expiry }) {
393
- return (0, viem_write_1.submitPreparedTransaction)(this.signer, (0, utils_1.prepareTransaction)({
394
- to: this.address,
395
- abi: abi_1.wildcatMarketAbi,
396
- functionName: "executeWithdrawal",
397
- args: [lender, expiry]
398
- }));
321
+ return this.contract.executeWithdrawal(lender, expiry);
399
322
  }
400
323
  async executeWithdrawals(withdrawals) {
401
324
  const lenders = withdrawals.map((w) => w.lender);
402
325
  const expiries = withdrawals.map((w) => w.expiry);
403
- return (0, viem_write_1.submitPreparedTransaction)(this.signer, (0, utils_1.prepareTransaction)({
404
- to: this.address,
405
- abi: abi_1.wildcatMarketAbi,
406
- functionName: "executeWithdrawals",
407
- args: [lenders, expiries]
408
- }));
326
+ return this.contract.executeWithdrawals(lenders, expiries);
409
327
  }
410
328
  populateRepayAndProcessUnpaidWithdrawalBatches(amount, maxBatches = 10) {
411
- return (0, utils_1.prepareTransaction)({
329
+ return {
412
330
  to: this.address,
413
- abi: abi_1.wildcatMarketAbi,
414
- functionName: "repayAndProcessUnpaidWithdrawalBatches",
415
- args: [amount.raw, maxBatches]
416
- });
331
+ data: this.contract.interface.encodeFunctionData("repayAndProcessUnpaidWithdrawalBatches", [
332
+ amount.raw,
333
+ maxBatches
334
+ ]),
335
+ value: "0"
336
+ };
417
337
  }
418
338
  async repayAndProcessUnpaidWithdrawalBatches(amount, maxBatches = 10) {
419
- return (0, viem_write_1.submitPreparedTransaction)(this.signer, this.populateRepayAndProcessUnpaidWithdrawalBatches(amount, maxBatches));
339
+ return this.contract.repayAndProcessUnpaidWithdrawalBatches(amount.raw, maxBatches);
420
340
  }
421
341
  /* -------------------------------------------------------------------------- */
422
342
  /* Set APR */
@@ -432,8 +352,7 @@ class Market extends types_1.ContractWrapper {
432
352
  if (annualInterestBips < originalAnnualInterestBips) {
433
353
  let doubleRelativeDiff;
434
354
  if (this.version === types_1.MarketVersion.V2) {
435
- const relativeDiff = Number((10000n * BigInt(originalAnnualInterestBips - annualInterestBips)) /
436
- BigInt(originalAnnualInterestBips));
355
+ const relativeDiff = (0, utils_2.mulDiv)((0, token_1.toBn)(10000), (0, token_1.toBn)(originalAnnualInterestBips - annualInterestBips), (0, token_1.toBn)(originalAnnualInterestBips)).toNumber();
437
356
  if (relativeDiff <= 2500) {
438
357
  // In v2, if the relative diff is 25% or less, the reserve ratio is not changed
439
358
  return originalReserveRatioBips;
@@ -441,8 +360,7 @@ class Market extends types_1.ContractWrapper {
441
360
  doubleRelativeDiff = 2 * relativeDiff;
442
361
  }
443
362
  else {
444
- doubleRelativeDiff = Number((20000n * BigInt(originalAnnualInterestBips - annualInterestBips)) /
445
- BigInt(originalAnnualInterestBips));
363
+ doubleRelativeDiff = (0, utils_2.mulDiv)((0, token_1.toBn)(20000), (0, token_1.toBn)(originalAnnualInterestBips - annualInterestBips), (0, token_1.toBn)(originalAnnualInterestBips)).toNumber();
446
364
  }
447
365
  const boundRelativeDiff = Math.min(10000, doubleRelativeDiff);
448
366
  return Math.max(boundRelativeDiff, originalReserveRatioBips);
@@ -454,11 +372,10 @@ class Market extends types_1.ContractWrapper {
454
372
  return originalReserveRatioBips;
455
373
  }
456
374
  calculateLiquidityCoverageForReserveRatio(reserveRatio) {
457
- const scaledRequiredReserves = (0, utils_1.bipMulBigint)(this.scaledTotalSupply - this.scaledPendingWithdrawals, reserveRatio) +
458
- this.scaledPendingWithdrawals;
459
- return this.underlyingToken.getAmount((0, utils_1.rayMulBigint)(scaledRequiredReserves, this.scaleFactor) +
460
- this.lastAccruedProtocolFees.raw +
461
- this.normalizedUnclaimedWithdrawals.raw);
375
+ const scaledRequiredReserves = (0, utils_2.bipMul)(this.scaledTotalSupply.sub(this.scaledPendingWithdrawals), (0, token_1.toBn)(reserveRatio)).add(this.scaledPendingWithdrawals);
376
+ return this.underlyingToken.getAmount((0, utils_2.rayMul)(scaledRequiredReserves, this.scaleFactor)
377
+ .add(this.lastAccruedProtocolFees.raw)
378
+ .add(this.normalizedUnclaimedWithdrawals.raw));
462
379
  }
463
380
  canChangeAPR(annualInterestBips) {
464
381
  const originalAnnualInterestBips = this.temporaryReserveRatio
@@ -488,186 +405,89 @@ class Market extends types_1.ContractWrapper {
488
405
  /* Updates */
489
406
  /* -------------------------------------------------------------------------- */
490
407
  async update() {
491
- if (this.version === types_1.MarketVersion.V2) {
492
- if (hasUnifiedLatestLensForDirectReads(this.chainId)) {
493
- try {
494
- const market = await (0, market_lens_1.getUnifiedMarketDataV2)(this.chainId, this.provider, this.address);
495
- this.updateWith(market);
496
- return;
497
- }
498
- catch (_) {
499
- // Fall back to the pre-2.5 V2 lens until unified lens deployment is reliable.
500
- }
501
- }
502
- const market = await (0, market_lens_1.getV2MarketData)(this.chainId, this.provider, this.address);
503
- this.updateWith(market);
504
- return;
505
- }
506
- const market = await (0, market_lens_1.getLegacyMarketData)(this.chainId, this.provider, this.address);
408
+ const market = await (0, constants_1.getLensContract)(this.chainId, this.provider).getMarketData(this.address);
507
409
  this.updateWith(market);
508
410
  }
509
411
  updateWith(data) {
510
- const baseData = "market" in data ? data.market : data;
511
- const nextScaleFactor = (0, token_1.toRawAmount)(baseData.scaleFactor);
512
- const nextScaledTotalSupply = (0, token_1.toRawAmount)(baseData.scaledTotalSupply);
513
- const nextScaledPendingWithdrawals = (0, token_1.toRawAmount)(baseData.scaledPendingWithdrawals);
514
- const nextLastAccruedProtocolFees = (0, token_1.toRawAmount)(baseData.lastAccruedProtocolFees);
515
412
  // Note: this adds all the interest accrued to the base interest accrued, since the lens
516
413
  // doesn't give us any way to distinguish between base interest and delinquency fees.
517
- if (this.scaledTotalSupply === nextScaledTotalSupply &&
518
- nextScaleFactor > this.scaleFactor &&
414
+ if (this.scaledTotalSupply.eq(data.scaledTotalSupply) &&
415
+ data.scaleFactor.gt(this.scaleFactor) &&
519
416
  this.totalBaseInterestAccrued) {
520
- const lastTotalValue = (0, utils_1.rayMulBigint)(this.scaledTotalSupply, this.scaleFactor);
521
- const currentTotalValue = (0, utils_1.rayMulBigint)(this.scaledTotalSupply, nextScaleFactor);
522
- const baseInterestAccrued = currentTotalValue - lastTotalValue;
417
+ const lastTotalValue = (0, utils_2.rayMul)(this.scaledTotalSupply, this.scaleFactor);
418
+ const currentTotalValue = (0, utils_2.rayMul)(this.scaledTotalSupply, data.scaleFactor);
419
+ const baseInterestAccrued = currentTotalValue.sub(lastTotalValue);
523
420
  this.totalBaseInterestAccrued = this.totalBaseInterestAccrued.add(baseInterestAccrued);
524
421
  }
525
- if (nextLastAccruedProtocolFees > this.lastAccruedProtocolFees.raw &&
422
+ if (data.lastAccruedProtocolFees.gt(this.lastAccruedProtocolFees.raw) &&
526
423
  this.totalProtocolFeesAccrued) {
527
- this.totalProtocolFeesAccrued = this.totalProtocolFeesAccrued.add(nextLastAccruedProtocolFees - this.lastAccruedProtocolFees.raw);
528
- }
529
- this.feeRecipient = baseData.feeRecipient;
530
- this.protocolFeeBips = (0, utils_1.toNumber)(baseData.protocolFeeBips);
531
- this.delinquencyFeeBips = (0, utils_1.toNumber)(baseData.delinquencyFeeBips);
532
- this.delinquencyGracePeriod = (0, utils_1.toNumber)(baseData.delinquencyGracePeriod);
533
- this.withdrawalBatchDuration = (0, utils_1.toNumber)(baseData.withdrawalBatchDuration);
534
- this.reserveRatioBips = (0, utils_1.toNumber)(baseData.reserveRatioBips);
535
- this.annualInterestBips = (0, utils_1.toNumber)(baseData.annualInterestBips);
536
- this.temporaryReserveRatio = baseData.temporaryReserveRatio;
537
- this.originalAnnualInterestBips = (0, utils_1.toNumber)(baseData.originalAnnualInterestBips);
538
- this.originalReserveRatioBips = (0, utils_1.toNumber)(baseData.originalReserveRatioBips);
539
- this.temporaryReserveRatioExpiry = (0, utils_1.toNumber)(baseData.temporaryReserveRatioExpiry);
540
- this.isClosed = baseData.isClosed;
541
- this.scaleFactor = nextScaleFactor;
542
- this.totalSupply = this.marketToken.getAmount(baseData.totalSupply);
543
- this.maxTotalSupply = this.marketToken.getAmount(baseData.maxTotalSupply);
544
- this.scaledTotalSupply = nextScaledTotalSupply;
545
- this.totalAssets = this.underlyingToken.getAmount(baseData.totalAssets);
546
- this.lastAccruedProtocolFees = this.underlyingToken.getAmount(baseData.lastAccruedProtocolFees);
547
- this.normalizedUnclaimedWithdrawals = this.underlyingToken.getAmount(baseData.normalizedUnclaimedWithdrawals);
548
- this.scaledPendingWithdrawals = nextScaledPendingWithdrawals;
549
- this.pendingWithdrawalExpiry = (0, utils_1.toNumber)(baseData.pendingWithdrawalExpiry);
550
- this.isDelinquent = baseData.isDelinquent;
551
- this.timeDelinquent = (0, utils_1.toNumber)(baseData.timeDelinquent);
552
- this.lastInterestAccruedTimestamp = (0, utils_1.toNumber)(baseData.lastInterestAccruedTimestamp);
553
- this.unpaidWithdrawalBatchExpiries = baseData.unpaidWithdrawalBatchExpiries.map(utils_1.toNumber);
554
- this.coverageLiquidity = this.underlyingToken.getAmount(baseData.coverageLiquidity);
555
- if ("hooksFactory" in baseData) {
556
- this.hooksFactory = baseData.hooksFactory;
557
- this.marketType = (0, constants_1.getMarketTypeForHooksFactory)(this.chainId, baseData.hooksFactory);
558
- }
559
- if ("hooksConfig" in baseData) {
560
- (0, utils_1.assert)(this.version === types_1.MarketVersion.V2, `Can not push V2 lens data to V1 market!`);
561
- const config = this.hooksConfig;
562
- (0, utils_1.assert)(config !== undefined, `V2 market has no hooksConfig!`);
563
- config.minimumDeposit = this.underlyingToken.getAmount(baseData.hooksConfig.minimumDeposit);
564
- if (config.kind === types_1.HooksKind.FixedTerm) {
565
- config.fixedTermEndTime = (0, utils_1.toNumber)(baseData.hooksConfig.fixedTermEndTime);
566
- }
567
- }
568
- else {
569
- (0, utils_1.assert)(this.version === types_1.MarketVersion.V1, `Can not push V1 lens data to V2 market!`);
570
- }
571
- if ("market" in data) {
572
- this.commitmentFeeBips = data.commitmentFeeBips.isPresent
573
- ? (0, utils_1.toNumber)(data.commitmentFeeBips.value)
574
- : undefined;
575
- this.drawnAmount = data.drawnAmount.isPresent
576
- ? this.underlyingToken.getAmount(data.drawnAmount.value)
577
- : undefined;
578
- }
579
- else {
580
- this.commitmentFeeBips = undefined;
581
- this.drawnAmount = undefined;
582
- }
583
- }
584
- updateWithLiveData(data) {
585
- (0, utils_1.assert)(data.market.toLowerCase() === this.address.toLowerCase(), `Live market data address mismatch`);
586
- const nextScaleFactor = (0, token_1.toRawAmount)(data.scaleFactor);
587
- const nextScaledTotalSupply = (0, token_1.toRawAmount)(data.scaledTotalSupply);
588
- const nextScaledPendingWithdrawals = (0, token_1.toRawAmount)(data.scaledPendingWithdrawals);
589
- const nextLastAccruedProtocolFees = (0, token_1.toRawAmount)(data.lastAccruedProtocolFees);
590
- if (this.scaledTotalSupply === nextScaledTotalSupply &&
591
- nextScaleFactor > this.scaleFactor &&
592
- this.totalBaseInterestAccrued) {
593
- const lastTotalValue = (0, utils_1.rayMulBigint)(this.scaledTotalSupply, this.scaleFactor);
594
- const currentTotalValue = (0, utils_1.rayMulBigint)(this.scaledTotalSupply, nextScaleFactor);
595
- this.totalBaseInterestAccrued = this.totalBaseInterestAccrued.add(currentTotalValue - lastTotalValue);
596
- }
597
- if (nextLastAccruedProtocolFees > this.lastAccruedProtocolFees.raw &&
598
- this.totalProtocolFeesAccrued) {
599
- this.totalProtocolFeesAccrued = this.totalProtocolFeesAccrued.add(nextLastAccruedProtocolFees - this.lastAccruedProtocolFees.raw);
600
- }
601
- this.protocolFeeBips = (0, utils_1.toNumber)(data.protocolFeeBips);
602
- this.reserveRatioBips = (0, utils_1.toNumber)(data.reserveRatioBips);
603
- this.annualInterestBips = (0, utils_1.toNumber)(data.annualInterestBips);
424
+ this.totalProtocolFeesAccrued = this.totalProtocolFeesAccrued.add(data.lastAccruedProtocolFees.sub(this.lastAccruedProtocolFees.raw));
425
+ }
426
+ this.feeRecipient = data.feeRecipient;
427
+ this.protocolFeeBips = data.protocolFeeBips.toNumber();
428
+ this.delinquencyFeeBips = data.delinquencyFeeBips.toNumber();
429
+ this.delinquencyGracePeriod = data.delinquencyGracePeriod.toNumber();
430
+ this.withdrawalBatchDuration = data.withdrawalBatchDuration.toNumber();
431
+ this.reserveRatioBips = data.reserveRatioBips.toNumber();
432
+ this.annualInterestBips = data.annualInterestBips.toNumber();
433
+ this.temporaryReserveRatio = data.temporaryReserveRatio;
434
+ this.originalAnnualInterestBips = data.originalAnnualInterestBips.toNumber();
435
+ this.originalReserveRatioBips = data.originalReserveRatioBips.toNumber();
436
+ this.temporaryReserveRatioExpiry = data.temporaryReserveRatioExpiry.toNumber();
604
437
  this.isClosed = data.isClosed;
605
- this.scaleFactor = nextScaleFactor;
438
+ this.scaleFactor = data.scaleFactor;
606
439
  this.totalSupply = this.marketToken.getAmount(data.totalSupply);
607
440
  this.maxTotalSupply = this.marketToken.getAmount(data.maxTotalSupply);
608
- this.scaledTotalSupply = nextScaledTotalSupply;
441
+ this.scaledTotalSupply = data.scaledTotalSupply;
609
442
  this.totalAssets = this.underlyingToken.getAmount(data.totalAssets);
610
443
  this.lastAccruedProtocolFees = this.underlyingToken.getAmount(data.lastAccruedProtocolFees);
611
444
  this.normalizedUnclaimedWithdrawals = this.underlyingToken.getAmount(data.normalizedUnclaimedWithdrawals);
612
- this.scaledPendingWithdrawals = nextScaledPendingWithdrawals;
613
- this.pendingWithdrawalExpiry = (0, utils_1.toNumber)(data.pendingWithdrawalExpiry);
445
+ this.scaledPendingWithdrawals = data.scaledPendingWithdrawals;
446
+ this.pendingWithdrawalExpiry = data.pendingWithdrawalExpiry.toNumber();
614
447
  this.isDelinquent = data.isDelinquent;
615
- this.timeDelinquent = (0, utils_1.toNumber)(data.timeDelinquent);
616
- this.lastInterestAccruedTimestamp = (0, utils_1.toNumber)(data.lastInterestAccruedTimestamp);
448
+ this.timeDelinquent = data.timeDelinquent.toNumber();
449
+ this.lastInterestAccruedTimestamp = data.lastInterestAccruedTimestamp.toNumber();
450
+ this.unpaidWithdrawalBatchExpiries = data.unpaidWithdrawalBatchExpiries;
617
451
  this.coverageLiquidity = this.underlyingToken.getAmount(data.coverageLiquidity);
618
- this.commitmentFeeBips = data.commitmentFeeBips.isPresent
619
- ? (0, utils_1.toNumber)(data.commitmentFeeBips.value)
620
- : undefined;
621
- this.drawnAmount = data.drawnAmount.isPresent
622
- ? this.underlyingToken.getAmount(data.drawnAmount.value)
623
- : undefined;
452
+ if ("hooksConfig" in data) {
453
+ (0, utils_2.assert)(this.version === types_1.MarketVersion.V2, `Can not push V2 lens data to V1 market!`);
454
+ const config = this.hooksConfig;
455
+ (0, utils_2.assert)(config !== undefined, `V2 market has no hooksConfig!`);
456
+ config.minimumDeposit = this.underlyingToken.getAmount(data.hooksConfig.minimumDeposit);
457
+ if (config.kind === types_1.HooksKind.FixedTerm) {
458
+ config.fixedTermEndTime = data.hooksConfig.fixedTermEndTime;
459
+ }
460
+ else if (config.kind === types_1.HooksKind.PeriodicTerm) {
461
+ config.firstWithdrawalWindowStart = data.hooksConfig.firstWithdrawalWindowStart;
462
+ config.periodDuration = data.hooksConfig.periodDuration;
463
+ config.withdrawalWindowDuration = data.hooksConfig.withdrawalWindowDuration;
464
+ config.periodicTermClosed = data.hooksConfig.periodicTermClosed;
465
+ }
466
+ }
467
+ else {
468
+ (0, utils_2.assert)(this.version === types_1.MarketVersion.V1, `Can not push V1 lens data to V2 market!`);
469
+ }
624
470
  }
625
471
  /* -------------------------------------------------------------------------- */
626
472
  /* Class Builder Methods */
627
473
  /* -------------------------------------------------------------------------- */
628
474
  static fromSubgraphMarketData(chainId, provider, data, signerAddress) {
629
475
  const underlyingToken = token_1.Token.fromSubgraphToken(chainId, data._asset, provider);
630
- const marketToken = new token_1.Token(chainId, data.id, data.name, data.symbol, data.decimals, false, provider);
631
- const hasTotals = hasSubgraphMarketTotals(data);
632
- const hasRecords = hasSubgraphMarketRecords(data);
633
- const scaledTotalSupply = (0, token_1.toRawAmount)(data.scaledTotalSupply);
634
- const scaleFactor = (0, token_1.toRawAmount)(data.scaleFactor);
635
- const scaledWithdrawals = (0, token_1.toRawAmount)(data.scaledPendingWithdrawals);
636
- const scaledRequiredReserves = (0, utils_1.bipMulBigint)(scaledTotalSupply - scaledWithdrawals, data.reserveRatioBips) +
637
- scaledWithdrawals;
638
- const coverageLiquidity = (0, utils_1.rayMulBigint)(scaledRequiredReserves, scaleFactor) +
639
- (0, token_1.toRawAmount)(data.pendingProtocolFees) +
640
- (0, token_1.toRawAmount)(data.normalizedUnclaimedWithdrawals);
476
+ const marketToken = token_1.Token.fromSubgraphMarketData(chainId, data, provider);
477
+ const scaledTotalSupply = ethers_1.BigNumber.from(data.scaledTotalSupply);
478
+ const scaleFactor = ethers_1.BigNumber.from(data.scaleFactor);
479
+ const scaledWithdrawals = ethers_1.BigNumber.from(data.scaledPendingWithdrawals);
480
+ const scaledRequiredReserves = (0, utils_2.bipMul)(scaledTotalSupply.sub(scaledWithdrawals), ethers_1.BigNumber.from(data.reserveRatioBips)).add(scaledWithdrawals);
481
+ const coverageLiquidity = (0, utils_2.rayMul)(scaledRequiredReserves, scaleFactor)
482
+ .add(data.pendingProtocolFees)
483
+ .add(data.normalizedUnclaimedWithdrawals);
641
484
  let hooksConfig;
642
- let hooksFactory;
643
485
  if (data.version === types_1.MarketVersion.V2) {
644
- (0, utils_1.assert)(!!data.hooks, `V2 markets require hooks`);
645
- (0, utils_1.assert)(!!data.hooksConfig, `V2 markets require hooksConfig`);
646
- const { minimumDeposit: _minimumDeposit, depositRequiresAccess, transferRequiresAccess, queueWithdrawalRequiresAccess, allowClosureBeforeTerm, allowTermReduction, fixedTermEndTime, transfersDisabled } = data.hooksConfig;
647
- const flags = {
648
- useOnDeposit: data.hooksConfig.useOnDeposit,
649
- useOnQueueWithdrawal: data.hooksConfig.useOnQueueWithdrawal,
650
- useOnExecuteWithdrawal: data.hooksConfig.useOnExecuteWithdrawal,
651
- useOnTransfer: data.hooksConfig.useOnTransfer,
652
- useOnBorrow: data.hooksConfig.useOnBorrow,
653
- useOnRepay: data.hooksConfig.useOnRepay,
654
- useOnCloseMarket: data.hooksConfig.useOnCloseMarket,
655
- useOnNukeFromOrbit: data.hooksConfig.useOnNukeFromOrbit,
656
- useOnSetMaxTotalSupply: data.hooksConfig.useOnSetMaxTotalSupply,
657
- useOnSetAnnualInterestAndReserveRatioBips: data.hooksConfig.useOnSetAnnualInterestAndReserveRatioBips,
658
- useOnSetProtocolFeeBips: data.hooksConfig.useOnSetProtocolFeeBips
659
- };
660
- const { id } = data.hooks;
661
- const templateData = data.hooks.factoryHooksTemplate.name
662
- ? data.hooks.factoryHooksTemplate
663
- : {
664
- ...data.hooks.factoryHooksTemplate,
665
- // Older subgraph deployments can contain placeholder factory-template rows
666
- // created before HooksTemplateAdded populated the template name.
667
- name: fixedTermEndTime > 0 ? "FixedTermHooks" : "OpenTermHooks"
668
- };
669
- const template = (0, access_1.hooksTemplateFromSubgraph)(chainId, provider, templateData);
670
- hooksFactory = template.hooksFactory;
486
+ (0, utils_2.assert)(!!data.hooks, `V2 markets require hooks`);
487
+ (0, utils_2.assert)(!!data.hooksConfig, `V2 markets require hooksConfig`);
488
+ const { __typename: _, minimumDeposit: _minimumDeposit, depositRequiresAccess, transferRequiresAccess, queueWithdrawalRequiresAccess, allowClosureBeforeTerm, allowForceBuyBacks, allowTermReduction, fixedTermEndTime, firstWithdrawalWindowStart, periodDuration, withdrawalWindowDuration, periodicTermClosed, pendingAnnualInterestBips, pendingAnnualInterestProposalTimestamp, pendingAnnualInterestResponseWindowStart, pendingAnnualInterestResponseWindowEnd, transfersDisabled, ...flags } = data.hooksConfig;
489
+ const { id, hooksTemplate: hooksTemplateData } = data.hooks;
490
+ const template = (0, access_1.hooksTemplateFromSubgraph)(chainId, provider, hooksTemplateData);
671
491
  const minimumDeposit = _minimumDeposit
672
492
  ? underlyingToken.getAmount(_minimumDeposit)
673
493
  : undefined;
@@ -680,7 +500,7 @@ class Market extends types_1.ContractWrapper {
680
500
  minimumDeposit,
681
501
  transferRequiresAccess,
682
502
  depositRequiresAccess,
683
- allowForceBuyBacks: false,
503
+ allowForceBuyBacks,
684
504
  transfersDisabled
685
505
  };
686
506
  }
@@ -695,19 +515,38 @@ class Market extends types_1.ContractWrapper {
695
515
  depositRequiresAccess,
696
516
  queueWithdrawalRequiresAccess,
697
517
  allowClosureBeforeTerm,
698
- allowForceBuyBacks: false,
518
+ allowForceBuyBacks,
699
519
  allowTermReduction,
700
520
  fixedTermEndTime,
701
521
  transfersDisabled
702
522
  };
703
523
  }
524
+ else if (template.kind === types_1.HooksKind.PeriodicTerm) {
525
+ hooksConfig = {
526
+ kind: types_1.HooksKind.PeriodicTerm,
527
+ hooksAddress: id,
528
+ template,
529
+ flags,
530
+ minimumDeposit,
531
+ transferRequiresAccess,
532
+ depositRequiresAccess,
533
+ queueWithdrawalRequiresAccess,
534
+ transfersDisabled,
535
+ firstWithdrawalWindowStart,
536
+ periodDuration,
537
+ withdrawalWindowDuration,
538
+ periodicTermClosed,
539
+ pendingAnnualInterestBips,
540
+ pendingAnnualInterestProposalTimestamp,
541
+ pendingAnnualInterestResponseWindowStart,
542
+ pendingAnnualInterestResponseWindowEnd
543
+ };
544
+ }
704
545
  }
705
546
  return new Market({
706
547
  chainId,
707
548
  provider,
708
549
  version: data.version,
709
- hooksFactory,
710
- marketType: hooksFactory ? (0, constants_1.getMarketTypeForHooksFactory)(chainId, hooksFactory) : undefined,
711
550
  hooksConfig,
712
551
  marketToken,
713
552
  underlyingToken,
@@ -725,32 +564,30 @@ class Market extends types_1.ContractWrapper {
725
564
  originalReserveRatioBips: data.originalReserveRatioBips,
726
565
  temporaryReserveRatioExpiry: data.temporaryReserveRatioExpiry,
727
566
  isClosed: data.isClosed,
728
- scaleFactor,
729
- totalSupply: marketToken.getAmount((0, utils_1.rayMulBigint)(scaledTotalSupply, scaleFactor)),
567
+ scaleFactor: ethers_1.BigNumber.from(data.scaleFactor),
568
+ totalSupply: marketToken.getAmount((0, utils_2.rayMul)(scaledTotalSupply, scaleFactor)),
730
569
  maxTotalSupply: marketToken.getAmount(data.maxTotalSupply),
731
570
  scaledTotalSupply: scaledTotalSupply,
732
571
  totalAssets: underlyingToken.getAmount(0),
733
572
  lastAccruedProtocolFees: underlyingToken.getAmount(data.pendingProtocolFees),
734
573
  normalizedUnclaimedWithdrawals: underlyingToken.getAmount(data.normalizedUnclaimedWithdrawals),
735
- scaledPendingWithdrawals: scaledWithdrawals,
574
+ scaledPendingWithdrawals: ethers_1.BigNumber.from(data.scaledPendingWithdrawals),
736
575
  pendingWithdrawalExpiry: +data.pendingWithdrawalExpiry,
737
576
  isDelinquent: data.isDelinquent,
738
577
  timeDelinquent: data.timeDelinquent,
739
578
  lastInterestAccruedTimestamp: data.lastInterestAccruedTimestamp,
740
579
  unpaidWithdrawalBatchExpiries: [] /* data.unpaidWithdrawalBatchExpiries */,
741
580
  coverageLiquidity: underlyingToken.getAmount(coverageLiquidity),
742
- commitmentFeeBips: data.commitmentFeeBips != null ? Number(data.commitmentFeeBips) : undefined,
743
- drawnAmount: data.drawnAmount != null ? underlyingToken.getAmount(data.drawnAmount) : undefined,
744
- totalBorrowed: underlyingToken.getAmount(hasTotals ? data.totalBorrowed : 0),
745
- totalRepaid: underlyingToken.getAmount(hasTotals ? data.totalRepaid : 0),
746
- totalBaseInterestAccrued: underlyingToken.getAmount(hasTotals ? data.totalBaseInterestAccrued : 0),
747
- totalDelinquencyFeesAccrued: underlyingToken.getAmount(hasTotals ? data.totalDelinquencyFeesAccrued : 0),
748
- totalProtocolFeesAccrued: underlyingToken.getAmount(hasTotals ? data.totalProtocolFeesAccrued : 0),
749
- totalDeposited: underlyingToken.getAmount(hasTotals ? data.totalDeposited : 0),
750
- depositRecords: hasRecords ? data.depositRecords : undefined,
751
- repaymentRecords: hasRecords ? data.repaymentRecords : undefined,
752
- borrowRecords: hasRecords ? data.borrowRecords : undefined,
753
- feeCollectionRecords: hasRecords ? data.feeCollectionRecords : undefined,
581
+ totalBorrowed: underlyingToken.getAmount(data.totalBorrowed),
582
+ totalRepaid: underlyingToken.getAmount(data.totalRepaid),
583
+ totalBaseInterestAccrued: underlyingToken.getAmount(data.totalBaseInterestAccrued),
584
+ totalDelinquencyFeesAccrued: underlyingToken.getAmount(data.totalDelinquencyFeesAccrued),
585
+ totalProtocolFeesAccrued: underlyingToken.getAmount(data.totalProtocolFeesAccrued),
586
+ totalDeposited: underlyingToken.getAmount(data.totalDeposited),
587
+ depositRecords: data.depositRecords,
588
+ repaymentRecords: data.repaymentRecords,
589
+ borrowRecords: data.borrowRecords,
590
+ feeCollectionRecords: data.feeCollectionRecords,
754
591
  deployedEvent: data.deployedEvent,
755
592
  eventIndex: data.eventIndex,
756
593
  numCollateralContracts: data.numCollateralContracts,
@@ -769,30 +606,30 @@ class Market extends types_1.ContractWrapper {
769
606
  borrower: data.borrower,
770
607
  controller: data.controller,
771
608
  feeRecipient: data.feeRecipient,
772
- protocolFeeBips: (0, utils_1.toNumber)(data.protocolFeeBips),
773
- delinquencyFeeBips: (0, utils_1.toNumber)(data.delinquencyFeeBips),
774
- delinquencyGracePeriod: (0, utils_1.toNumber)(data.delinquencyGracePeriod),
775
- withdrawalBatchDuration: (0, utils_1.toNumber)(data.withdrawalBatchDuration),
776
- reserveRatioBips: (0, utils_1.toNumber)(data.reserveRatioBips),
777
- annualInterestBips: (0, utils_1.toNumber)(data.annualInterestBips),
609
+ protocolFeeBips: data.protocolFeeBips.toNumber(),
610
+ delinquencyFeeBips: data.delinquencyFeeBips.toNumber(),
611
+ delinquencyGracePeriod: data.delinquencyGracePeriod.toNumber(),
612
+ withdrawalBatchDuration: data.withdrawalBatchDuration.toNumber(),
613
+ reserveRatioBips: data.reserveRatioBips.toNumber(),
614
+ annualInterestBips: data.annualInterestBips.toNumber(),
778
615
  temporaryReserveRatio: data.temporaryReserveRatio,
779
- originalAnnualInterestBips: (0, utils_1.toNumber)(data.originalAnnualInterestBips),
780
- originalReserveRatioBips: (0, utils_1.toNumber)(data.originalReserveRatioBips),
781
- temporaryReserveRatioExpiry: (0, utils_1.toNumber)(data.temporaryReserveRatioExpiry),
616
+ originalAnnualInterestBips: data.originalAnnualInterestBips.toNumber(),
617
+ originalReserveRatioBips: data.originalReserveRatioBips.toNumber(),
618
+ temporaryReserveRatioExpiry: data.temporaryReserveRatioExpiry.toNumber(),
782
619
  isClosed: data.isClosed,
783
- scaleFactor: (0, token_1.toRawAmount)(data.scaleFactor),
620
+ scaleFactor: data.scaleFactor,
784
621
  totalSupply: marketToken.getAmount(data.totalSupply),
785
622
  maxTotalSupply: marketToken.getAmount(data.maxTotalSupply),
786
- scaledTotalSupply: (0, token_1.toRawAmount)(data.scaledTotalSupply),
623
+ scaledTotalSupply: data.scaledTotalSupply,
787
624
  totalAssets: underlyingToken.getAmount(data.totalAssets),
788
625
  lastAccruedProtocolFees: underlyingToken.getAmount(data.lastAccruedProtocolFees),
789
626
  normalizedUnclaimedWithdrawals: underlyingToken.getAmount(data.normalizedUnclaimedWithdrawals),
790
- scaledPendingWithdrawals: (0, token_1.toRawAmount)(data.scaledPendingWithdrawals),
791
- pendingWithdrawalExpiry: (0, utils_1.toNumber)(data.pendingWithdrawalExpiry),
627
+ scaledPendingWithdrawals: data.scaledPendingWithdrawals,
628
+ pendingWithdrawalExpiry: data.pendingWithdrawalExpiry.toNumber(),
792
629
  isDelinquent: data.isDelinquent,
793
- timeDelinquent: (0, utils_1.toNumber)(data.timeDelinquent),
794
- lastInterestAccruedTimestamp: (0, utils_1.toNumber)(data.lastInterestAccruedTimestamp),
795
- unpaidWithdrawalBatchExpiries: data.unpaidWithdrawalBatchExpiries.map(utils_1.toNumber),
630
+ timeDelinquent: data.timeDelinquent.toNumber(),
631
+ lastInterestAccruedTimestamp: data.lastInterestAccruedTimestamp.toNumber(),
632
+ unpaidWithdrawalBatchExpiries: data.unpaidWithdrawalBatchExpiries,
796
633
  coverageLiquidity: underlyingToken.getAmount(data.coverageLiquidity),
797
634
  totalBorrowed: undefined,
798
635
  totalRepaid: undefined,
@@ -809,13 +646,13 @@ class Market extends types_1.ContractWrapper {
809
646
  signerAddress: signerAddress
810
647
  });
811
648
  }
812
- static fromMarketDataV2(chainId, provider, { hooks, hooksConfig: hooksConfigData, ...data }, signerAddress) {
649
+ static fromMarketDataV2(chainId, provider, { hooks, hooksConfig: hooksConfigData, ...data }) {
813
650
  const marketToken = token_1.Token.fromTokenMetadata(chainId, data.marketToken, provider);
814
651
  const underlyingToken = token_1.Token.fromTokenMetadata(chainId, data.underlyingToken, provider);
815
652
  const { hooksAddress } = hooks;
816
653
  let hooksConfig;
817
- const hooksKind = (0, utils_1.toNumber)(hooksConfigData.kind);
818
- if (hooksKind === 1) {
654
+ const allowForceBuyBacks = hooksConfigData.allowForceBuyBacks ?? false;
655
+ if (hooksConfigData.kind === 1) {
819
656
  hooksConfig = {
820
657
  kind: types_1.HooksKind.OpenTerm,
821
658
  hooksAddress: hooksAddress,
@@ -824,10 +661,10 @@ class Market extends types_1.ContractWrapper {
824
661
  transferRequiresAccess: hooksConfigData.transferRequiresAccess,
825
662
  transfersDisabled: hooksConfigData.transfersDisabled,
826
663
  minimumDeposit: underlyingToken.getAmount(hooksConfigData.minimumDeposit),
827
- allowForceBuyBacks: false
664
+ allowForceBuyBacks
828
665
  };
829
666
  }
830
- else if (hooksKind === 2) {
667
+ else if (hooksConfigData.kind === 2) {
831
668
  hooksConfig = {
832
669
  kind: types_1.HooksKind.FixedTerm,
833
670
  hooksAddress: hooksAddress,
@@ -836,142 +673,73 @@ class Market extends types_1.ContractWrapper {
836
673
  transferRequiresAccess: hooksConfigData.transferRequiresAccess,
837
674
  transfersDisabled: hooksConfigData.transfersDisabled,
838
675
  minimumDeposit: underlyingToken.getAmount(hooksConfigData.minimumDeposit),
839
- fixedTermEndTime: (0, utils_1.toNumber)(hooksConfigData.fixedTermEndTime),
676
+ fixedTermEndTime: hooksConfigData.fixedTermEndTime,
840
677
  queueWithdrawalRequiresAccess: hooksConfigData.withdrawalRequiresAccess,
841
678
  allowTermReduction: hooksConfigData.allowTermReduction,
842
679
  allowClosureBeforeTerm: hooksConfigData.allowClosureBeforeTerm,
843
- allowForceBuyBacks: false
680
+ allowForceBuyBacks
844
681
  };
845
682
  }
846
- else {
847
- throw Error(`Unknown hooks kind: ${hooks.hooksTemplate.name}, version #${hooksKind}`);
848
- }
849
- return new Market({
850
- provider,
851
- hooksFactory: data.hooksFactory,
852
- marketType: (0, constants_1.getMarketTypeForHooksFactory)(chainId, data.hooksFactory),
853
- hooksConfig,
854
- version: types_1.MarketVersion.V2,
855
- chainId: chainId,
856
- marketToken: marketToken,
857
- underlyingToken: underlyingToken,
858
- borrower: data.borrower,
859
- feeRecipient: data.feeRecipient,
860
- protocolFeeBips: (0, utils_1.toNumber)(data.protocolFeeBips),
861
- delinquencyFeeBips: (0, utils_1.toNumber)(data.delinquencyFeeBips),
862
- delinquencyGracePeriod: (0, utils_1.toNumber)(data.delinquencyGracePeriod),
863
- withdrawalBatchDuration: (0, utils_1.toNumber)(data.withdrawalBatchDuration),
864
- reserveRatioBips: (0, utils_1.toNumber)(data.reserveRatioBips),
865
- annualInterestBips: (0, utils_1.toNumber)(data.annualInterestBips),
866
- temporaryReserveRatio: data.temporaryReserveRatio,
867
- originalAnnualInterestBips: (0, utils_1.toNumber)(data.originalAnnualInterestBips),
868
- originalReserveRatioBips: (0, utils_1.toNumber)(data.originalReserveRatioBips),
869
- temporaryReserveRatioExpiry: (0, utils_1.toNumber)(data.temporaryReserveRatioExpiry),
870
- isClosed: data.isClosed,
871
- scaleFactor: (0, token_1.toRawAmount)(data.scaleFactor),
872
- totalSupply: marketToken.getAmount(data.totalSupply),
873
- maxTotalSupply: marketToken.getAmount(data.maxTotalSupply),
874
- scaledTotalSupply: (0, token_1.toRawAmount)(data.scaledTotalSupply),
875
- totalAssets: underlyingToken.getAmount(data.totalAssets),
876
- lastAccruedProtocolFees: underlyingToken.getAmount(data.lastAccruedProtocolFees),
877
- normalizedUnclaimedWithdrawals: underlyingToken.getAmount(data.normalizedUnclaimedWithdrawals),
878
- scaledPendingWithdrawals: (0, token_1.toRawAmount)(data.scaledPendingWithdrawals),
879
- pendingWithdrawalExpiry: (0, utils_1.toNumber)(data.pendingWithdrawalExpiry),
880
- isDelinquent: data.isDelinquent,
881
- timeDelinquent: (0, utils_1.toNumber)(data.timeDelinquent),
882
- lastInterestAccruedTimestamp: (0, utils_1.toNumber)(data.lastInterestAccruedTimestamp),
883
- unpaidWithdrawalBatchExpiries: data.unpaidWithdrawalBatchExpiries.map(utils_1.toNumber),
884
- coverageLiquidity: underlyingToken.getAmount(data.coverageLiquidity),
885
- signerAddress
886
- // borrowableAssets: underlyingToken.getAmount(data.borrowableAssets)
887
- });
888
- }
889
- static fromMarketDataV2_5(chainId, provider, { market, commitmentFeeBips, drawnAmount }, allowForceBuyBacks, signerAddress) {
890
- void allowForceBuyBacks;
891
- const { hooks, hooksConfig: hooksConfigData, ...data } = market;
892
- const marketToken = token_1.Token.fromTokenMetadata(chainId, data.marketToken, provider);
893
- const underlyingToken = token_1.Token.fromTokenMetadata(chainId, data.underlyingToken, provider);
894
- const { hooksAddress } = hooks;
895
- let hooksConfig;
896
- const hooksKind = (0, utils_1.toNumber)(hooksConfigData.kind);
897
- if (hooksKind === 1) {
683
+ else if (hooksConfigData.kind === 3) {
898
684
  hooksConfig = {
899
- kind: types_1.HooksKind.OpenTerm,
900
- hooksAddress,
901
- flags: { ...hooksConfigData.flags },
902
- depositRequiresAccess: hooksConfigData.depositRequiresAccess,
903
- transferRequiresAccess: hooksConfigData.transferRequiresAccess,
904
- transfersDisabled: hooksConfigData.transfersDisabled,
905
- minimumDeposit: underlyingToken.getAmount(hooksConfigData.minimumDeposit),
906
- allowForceBuyBacks: false
907
- };
908
- }
909
- else if (hooksKind === 2) {
910
- hooksConfig = {
911
- kind: types_1.HooksKind.FixedTerm,
912
- hooksAddress,
685
+ kind: types_1.HooksKind.PeriodicTerm,
686
+ hooksAddress: hooksAddress,
913
687
  flags: { ...hooksConfigData.flags },
914
688
  depositRequiresAccess: hooksConfigData.depositRequiresAccess,
915
689
  transferRequiresAccess: hooksConfigData.transferRequiresAccess,
916
690
  transfersDisabled: hooksConfigData.transfersDisabled,
917
691
  minimumDeposit: underlyingToken.getAmount(hooksConfigData.minimumDeposit),
918
- fixedTermEndTime: (0, utils_1.toNumber)(hooksConfigData.fixedTermEndTime),
919
692
  queueWithdrawalRequiresAccess: hooksConfigData.withdrawalRequiresAccess,
920
- allowTermReduction: hooksConfigData.allowTermReduction,
921
- allowClosureBeforeTerm: hooksConfigData.allowClosureBeforeTerm,
922
- allowForceBuyBacks: false
693
+ firstWithdrawalWindowStart: hooksConfigData.firstWithdrawalWindowStart,
694
+ periodDuration: hooksConfigData.periodDuration,
695
+ withdrawalWindowDuration: hooksConfigData.withdrawalWindowDuration,
696
+ periodicTermClosed: hooksConfigData.periodicTermClosed,
697
+ pendingAnnualInterestBips: 0,
698
+ pendingAnnualInterestProposalTimestamp: 0,
699
+ pendingAnnualInterestResponseWindowStart: 0,
700
+ pendingAnnualInterestResponseWindowEnd: 0
923
701
  };
924
702
  }
925
703
  else {
926
- throw Error(`Unknown hooks kind: ${hooks.hooksTemplate.name}, version #${hooksKind}`);
704
+ throw Error(`Unknown hooks kind: ${hooks.hooksTemplate.name}, version #${hooksConfigData.kind}`);
927
705
  }
928
706
  return new Market({
929
707
  provider,
930
- hooksFactory: data.hooksFactory,
931
- marketType: (0, constants_1.getMarketTypeForHooksFactory)(chainId, data.hooksFactory),
932
708
  hooksConfig,
933
709
  version: types_1.MarketVersion.V2,
934
- chainId,
935
- marketToken,
936
- underlyingToken,
710
+ chainId: chainId,
711
+ marketToken: marketToken,
712
+ underlyingToken: underlyingToken,
937
713
  borrower: data.borrower,
938
714
  feeRecipient: data.feeRecipient,
939
- protocolFeeBips: (0, utils_1.toNumber)(data.protocolFeeBips),
940
- delinquencyFeeBips: (0, utils_1.toNumber)(data.delinquencyFeeBips),
941
- delinquencyGracePeriod: (0, utils_1.toNumber)(data.delinquencyGracePeriod),
942
- withdrawalBatchDuration: (0, utils_1.toNumber)(data.withdrawalBatchDuration),
943
- reserveRatioBips: (0, utils_1.toNumber)(data.reserveRatioBips),
944
- annualInterestBips: (0, utils_1.toNumber)(data.annualInterestBips),
715
+ protocolFeeBips: data.protocolFeeBips.toNumber(),
716
+ delinquencyFeeBips: data.delinquencyFeeBips.toNumber(),
717
+ delinquencyGracePeriod: data.delinquencyGracePeriod.toNumber(),
718
+ withdrawalBatchDuration: data.withdrawalBatchDuration.toNumber(),
719
+ reserveRatioBips: data.reserveRatioBips.toNumber(),
720
+ annualInterestBips: data.annualInterestBips.toNumber(),
945
721
  temporaryReserveRatio: data.temporaryReserveRatio,
946
- originalAnnualInterestBips: (0, utils_1.toNumber)(data.originalAnnualInterestBips),
947
- originalReserveRatioBips: (0, utils_1.toNumber)(data.originalReserveRatioBips),
948
- temporaryReserveRatioExpiry: (0, utils_1.toNumber)(data.temporaryReserveRatioExpiry),
722
+ originalAnnualInterestBips: data.originalAnnualInterestBips.toNumber(),
723
+ originalReserveRatioBips: data.originalReserveRatioBips.toNumber(),
724
+ temporaryReserveRatioExpiry: data.temporaryReserveRatioExpiry.toNumber(),
949
725
  isClosed: data.isClosed,
950
- scaleFactor: (0, token_1.toRawAmount)(data.scaleFactor),
726
+ scaleFactor: data.scaleFactor,
951
727
  totalSupply: marketToken.getAmount(data.totalSupply),
952
728
  maxTotalSupply: marketToken.getAmount(data.maxTotalSupply),
953
- scaledTotalSupply: (0, token_1.toRawAmount)(data.scaledTotalSupply),
729
+ scaledTotalSupply: data.scaledTotalSupply,
954
730
  totalAssets: underlyingToken.getAmount(data.totalAssets),
955
731
  lastAccruedProtocolFees: underlyingToken.getAmount(data.lastAccruedProtocolFees),
956
732
  normalizedUnclaimedWithdrawals: underlyingToken.getAmount(data.normalizedUnclaimedWithdrawals),
957
- scaledPendingWithdrawals: (0, token_1.toRawAmount)(data.scaledPendingWithdrawals),
958
- pendingWithdrawalExpiry: (0, utils_1.toNumber)(data.pendingWithdrawalExpiry),
733
+ scaledPendingWithdrawals: data.scaledPendingWithdrawals,
734
+ pendingWithdrawalExpiry: data.pendingWithdrawalExpiry.toNumber(),
959
735
  isDelinquent: data.isDelinquent,
960
- timeDelinquent: (0, utils_1.toNumber)(data.timeDelinquent),
961
- lastInterestAccruedTimestamp: (0, utils_1.toNumber)(data.lastInterestAccruedTimestamp),
962
- unpaidWithdrawalBatchExpiries: data.unpaidWithdrawalBatchExpiries.map(utils_1.toNumber),
963
- coverageLiquidity: underlyingToken.getAmount(data.coverageLiquidity),
964
- commitmentFeeBips: commitmentFeeBips.isPresent
965
- ? (0, utils_1.toNumber)(commitmentFeeBips.value)
966
- : undefined,
967
- drawnAmount: drawnAmount.isPresent ? underlyingToken.getAmount(drawnAmount.value) : undefined,
968
- signerAddress
736
+ timeDelinquent: data.timeDelinquent.toNumber(),
737
+ lastInterestAccruedTimestamp: data.lastInterestAccruedTimestamp.toNumber(),
738
+ unpaidWithdrawalBatchExpiries: data.unpaidWithdrawalBatchExpiries,
739
+ coverageLiquidity: underlyingToken.getAmount(data.coverageLiquidity)
740
+ // borrowableAssets: underlyingToken.getAmount(data.borrowableAssets)
969
741
  });
970
742
  }
971
- static async fromUnifiedMarketData(chainId, provider, data, signerAddress) {
972
- const marketData = toUnifiedMarketDataV2(data);
973
- return Market.fromMarketDataV2_5(chainId, provider, marketData, false, signerAddress);
974
- }
975
743
  /* -------------------------------------------------------------------------- */
976
744
  /* Static Queries */
977
745
  /* -------------------------------------------------------------------------- */
@@ -979,133 +747,53 @@ class Market extends types_1.ContractWrapper {
979
747
  * @returns `Market` instance for `market`
980
748
  */
981
749
  static async getMarket(chainId, market, provider) {
982
- const signerAddress = await (0, ethers_signer_1.getEthersSignerAddress)(provider);
983
- if (hasUnifiedLatestLensForDirectReads(chainId)) {
984
- try {
985
- const data = await (0, market_lens_1.getUnifiedMarketDataV2)(chainId, provider, market);
986
- return Market.fromUnifiedMarketData(chainId, provider, data, signerAddress);
987
- }
988
- catch (_) {
989
- // Fall back to the legacy lens for V1 markets and pre-unified deployments.
990
- }
991
- }
992
- const data = await (0, market_lens_1.getLegacyMarketData)(chainId, provider, market);
993
- return Market.fromMarketData(chainId, data, provider, signerAddress);
750
+ const lens = (0, constants_1.getLensContract)(chainId, provider);
751
+ const data = await lens.getMarketData(market);
752
+ return Market.fromMarketData(chainId, data, provider, abstract_signer_1.Signer.isSigner(provider) ? await provider.getAddress() : undefined);
994
753
  }
995
754
  /**
996
755
  * @returns `Market` instance for `market`
997
756
  */
998
757
  static async getMarketV2(chainId, market, provider) {
999
- const signerAddress = await (0, ethers_signer_1.getEthersSignerAddress)(provider);
1000
- if (hasUnifiedLatestLensForDirectReads(chainId)) {
1001
- try {
1002
- const data = await (0, market_lens_1.getUnifiedMarketDataV2)(chainId, provider, market);
1003
- return Market.fromUnifiedMarketData(chainId, provider, data, signerAddress);
1004
- }
1005
- catch (_) {
1006
- // Fall back to the pre-2.5 V2 lens for chains that have not fully migrated.
1007
- }
1008
- }
1009
- const data = await (0, market_lens_1.getV2MarketData)(chainId, provider, market);
1010
- return Market.fromMarketDataV2(chainId, provider, data, signerAddress);
1011
- }
1012
- /**
1013
- * @returns V2 `Market` instances for `markets`, preserving V2.5/RCF fields
1014
- * when the current lens exposes them.
1015
- */
1016
- static async getMarketsV2(chainId, markets, provider) {
1017
- const signerAddress = await (0, ethers_signer_1.getEthersSignerAddress)(provider);
1018
- if (hasUnifiedLatestLensForDirectReads(chainId)) {
1019
- try {
1020
- const data = await (0, market_lens_1.getUnifiedMarketsDataV2)(chainId, provider, markets);
1021
- return Promise.all(data.map((market) => Market.fromUnifiedMarketData(chainId, provider, market, signerAddress)));
1022
- }
1023
- catch (_) {
1024
- // Fall back to the pre-2.5 V2 lens for chains that have not fully migrated.
1025
- }
1026
- }
1027
- return Promise.all(markets.map(async (market) => {
1028
- const data = await (0, market_lens_1.getV2MarketData)(chainId, provider, market);
1029
- return Market.fromMarketDataV2(chainId, provider, data, signerAddress);
1030
- }));
1031
- }
1032
- /**
1033
- * Refresh existing V2 market instances with the focused live lens surface when available.
1034
- * Falls back to broad V2 market reads so callers can use this as a route-intent API.
1035
- */
1036
- static async refreshMarketsV2LiveData(chainId, markets, provider) {
1037
- if (markets.length === 0) {
1038
- return markets;
1039
- }
1040
- const marketAddresses = markets.map((market) => market.address);
1041
- if (hasUnifiedLatestLensForDirectReads(chainId)) {
1042
- try {
1043
- const updates = await (0, market_lens_1.getUnifiedMarketsLiveDataV2)(chainId, provider, marketAddresses);
1044
- updates.forEach((update, i) => {
1045
- markets[i].updateWithLiveData(update);
1046
- });
1047
- return markets;
1048
- }
1049
- catch (_) {
1050
- // Fall back to broad reads for older unified lens deployments.
1051
- }
1052
- }
1053
- const refreshedMarkets = await Market.getMarketsV2(chainId, marketAddresses, provider);
1054
- refreshedMarkets.forEach((market, i) => {
1055
- Object.assign(markets[i], market);
1056
- });
1057
- return markets;
758
+ const lens = (0, constants_1.getLensV2Contract)(chainId, provider);
759
+ const data = await lens.getMarketData(market);
760
+ return Market.fromMarketDataV2(chainId, provider, data);
1058
761
  }
1059
762
  /**
1060
763
  * @returns `Market` instances for `markets`
1061
764
  */
1062
765
  static async getMarkets(chainId, markets, provider) {
1063
- const signerAddress = await (0, ethers_signer_1.getEthersSignerAddress)(provider);
1064
- if (hasUnifiedLatestLensForDirectReads(chainId)) {
1065
- try {
1066
- const data = await (0, market_lens_1.getUnifiedMarketsDataV2)(chainId, provider, markets);
1067
- return Promise.all(data.map((market) => Market.fromUnifiedMarketData(chainId, provider, market, signerAddress)));
1068
- }
1069
- catch (_) {
1070
- return Promise.all(markets.map((market) => Market.getMarket(chainId, market, provider)));
1071
- }
1072
- }
1073
- const data = await (0, market_lens_1.getLegacyMarketsData)(chainId, provider, markets);
766
+ const lens = (0, constants_1.getLensContract)(chainId, provider);
767
+ const data = await lens.getMarketsData(markets);
768
+ const signerAddress = abstract_signer_1.Signer.isSigner(provider) ? await provider.getAddress() : undefined;
1074
769
  return data.map((market) => Market.fromMarketData(chainId, market, provider, signerAddress));
1075
770
  }
1076
771
  /**
1077
772
  * @return All deployed markets
1078
773
  */
1079
774
  static async getAllMarkets(chainId, provider) {
1080
- const markets = await (0, arch_controller_1.getRegisteredMarkets)(chainId, provider);
1081
- if (!markets.length) {
1082
- return [];
1083
- }
1084
- return Market.getMarkets(chainId, markets, provider);
775
+ const lens = (0, constants_1.getLensContract)(chainId, provider);
776
+ const signerAddress = abstract_signer_1.Signer.isSigner(provider) ? await provider.getAddress() : undefined;
777
+ return lens
778
+ .getAllMarketsData()
779
+ .then((data) => data.map((market) => Market.fromMarketData(chainId, market, provider, signerAddress)));
1085
780
  }
1086
781
  /**
1087
782
  * @dev Get a paginated list of deployed markets.
1088
783
  */
1089
784
  static async getPaginatedMarkets(chainId, provider, start = 0, count) {
1090
- if (count <= 0) {
1091
- return [];
1092
- }
1093
- const totalMarkets = await (0, arch_controller_1.getRegisteredMarketsCount)(chainId, provider);
1094
- if (start >= totalMarkets) {
1095
- return [];
1096
- }
1097
- const end = Math.min(start + count, totalMarkets);
1098
- const markets = await (0, arch_controller_1.getRegisteredMarketsPage)(chainId, provider, start, end);
1099
- if (!markets.length) {
1100
- return [];
1101
- }
1102
- return Market.getMarkets(chainId, markets, provider);
785
+ const signerAddress = abstract_signer_1.Signer.isSigner(provider) ? await provider.getAddress() : undefined;
786
+ const lens = (0, constants_1.getLensContract)(chainId, provider);
787
+ return lens
788
+ .getPaginatedMarketsData(start, count)
789
+ .then((data) => data.map((market) => Market.fromMarketData(chainId, market, provider, signerAddress)));
1103
790
  }
1104
791
  /**
1105
792
  * @return Total number of deployed markets.
1106
793
  */
1107
794
  static async getMarketsCount(chainId, provider) {
1108
- return (0, arch_controller_1.getRegisteredMarketsCount)(chainId, provider);
795
+ const lens = (0, constants_1.getLensContract)(chainId, provider);
796
+ return lens.getMarketsCount().then((count) => count.toNumber());
1109
797
  }
1110
798
  }
1111
799
  exports.Market = Market;