@wildcatfi/wildcat-sdk 3.0.68-beta → 3.0.69-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 (416) hide show
  1. package/README.md +2 -2
  2. package/dist/abi/generated.d.ts +34207 -0
  3. package/dist/abi/generated.d.ts.map +1 -0
  4. package/dist/abi/generated.js +43811 -0
  5. package/dist/abi/generated.js.map +1 -0
  6. package/dist/abi/index.d.ts +3 -0
  7. package/dist/abi/index.d.ts.map +1 -0
  8. package/dist/abi/index.js +19 -0
  9. package/dist/abi/index.js.map +1 -0
  10. package/dist/abi/manual.d.ts +354 -0
  11. package/dist/abi/manual.d.ts.map +1 -0
  12. package/dist/abi/manual.js +202 -0
  13. package/dist/abi/manual.js.map +1 -0
  14. package/dist/access/access-control.d.ts +16 -18
  15. package/dist/access/access-control.d.ts.map +1 -1
  16. package/dist/access/access-control.js +101 -101
  17. package/dist/access/access-control.js.map +1 -1
  18. package/dist/access/fixed-term.d.ts +16 -18
  19. package/dist/access/fixed-term.d.ts.map +1 -1
  20. package/dist/access/fixed-term.js +115 -104
  21. package/dist/access/fixed-term.js.map +1 -1
  22. package/dist/access/index.d.ts +3 -3
  23. package/dist/access/index.d.ts.map +1 -1
  24. package/dist/access/index.js +47 -13
  25. package/dist/access/index.js.map +1 -1
  26. package/dist/access/revolving.d.ts +2 -1
  27. package/dist/access/revolving.d.ts.map +1 -1
  28. package/dist/access/revolving.js +6 -6
  29. package/dist/access/revolving.js.map +1 -1
  30. package/dist/access/utils.d.ts +2 -1
  31. package/dist/access/utils.d.ts.map +1 -1
  32. package/dist/access/utils.js +40 -10
  33. package/dist/access/utils.js.map +1 -1
  34. package/dist/access/validation.d.ts +7 -6
  35. package/dist/access/validation.d.ts.map +1 -1
  36. package/dist/access/validation.js +1 -0
  37. package/dist/access/validation.js.map +1 -1
  38. package/dist/account/index.d.ts +21 -30
  39. package/dist/account/index.d.ts.map +1 -1
  40. package/dist/account/index.js +193 -224
  41. package/dist/account/index.js.map +1 -1
  42. package/dist/client.d.ts +22 -0
  43. package/dist/client.d.ts.map +1 -0
  44. package/dist/client.js +51 -0
  45. package/dist/client.js.map +1 -0
  46. package/dist/collateral/collateral-events.d.ts +9 -10
  47. package/dist/collateral/collateral-events.d.ts.map +1 -1
  48. package/dist/collateral/collateral-events.js +4 -4
  49. package/dist/collateral/collateral-events.js.map +1 -1
  50. package/dist/collateral/index.d.ts +7 -10
  51. package/dist/collateral/index.d.ts.map +1 -1
  52. package/dist/collateral/index.js +36 -37
  53. package/dist/collateral/index.js.map +1 -1
  54. package/dist/constants.d.ts +72 -16
  55. package/dist/constants.d.ts.map +1 -1
  56. package/dist/constants.js +137 -23
  57. package/dist/constants.js.map +1 -1
  58. package/dist/controller.d.ts +10 -17
  59. package/dist/controller.d.ts.map +1 -1
  60. package/dist/controller.js +66 -67
  61. package/dist/controller.js.map +1 -1
  62. package/dist/gql/getActiveLendersByMarket.d.ts +2 -3
  63. package/dist/gql/getActiveLendersByMarket.d.ts.map +1 -1
  64. package/dist/gql/getActiveLendersByMarket.js +10 -10
  65. package/dist/gql/getActiveLendersByMarket.js.map +1 -1
  66. package/dist/gql/getAllHooksDataForBorrower.d.ts.map +1 -1
  67. package/dist/gql/getAllHooksDataForBorrower.js +6 -3
  68. package/dist/gql/getAllHooksDataForBorrower.js.map +1 -1
  69. package/dist/gql/getAllHooksTemplates.d.ts.map +1 -1
  70. package/dist/gql/getAllHooksTemplates.js +3 -3
  71. package/dist/gql/getAllHooksTemplates.js.map +1 -1
  72. package/dist/gql/graphql.d.ts +373 -10
  73. package/dist/gql/graphql.d.ts.map +1 -1
  74. package/dist/gql/graphql.js +78 -4
  75. package/dist/gql/graphql.js.map +1 -1
  76. package/dist/index.d.ts +2 -1
  77. package/dist/index.d.ts.map +1 -1
  78. package/dist/index.js +3 -14
  79. package/dist/index.js.map +1 -1
  80. package/dist/internal/arch-controller.d.ts +6 -0
  81. package/dist/internal/arch-controller.d.ts.map +1 -0
  82. package/dist/internal/arch-controller.js +36 -0
  83. package/dist/internal/arch-controller.js.map +1 -0
  84. package/dist/internal/ethers-signer.d.ts +4 -0
  85. package/dist/internal/ethers-signer.d.ts.map +1 -0
  86. package/dist/internal/ethers-signer.js +12 -0
  87. package/dist/internal/ethers-signer.js.map +1 -0
  88. package/dist/internal/ethers-viem.d.ts +4 -0
  89. package/dist/internal/ethers-viem.d.ts.map +1 -0
  90. package/dist/internal/ethers-viem.js +43 -0
  91. package/dist/internal/ethers-viem.js.map +1 -0
  92. package/dist/internal/market-lens.d.ts +26 -0
  93. package/dist/internal/market-lens.d.ts.map +1 -0
  94. package/dist/internal/market-lens.js +117 -0
  95. package/dist/internal/market-lens.js.map +1 -0
  96. package/dist/internal/viem-read.d.ts +3 -0
  97. package/dist/internal/viem-read.d.ts.map +1 -0
  98. package/dist/internal/viem-read.js +13 -0
  99. package/dist/internal/viem-read.js.map +1 -0
  100. package/dist/internal/viem-write.d.ts +9 -0
  101. package/dist/internal/viem-write.d.ts.map +1 -0
  102. package/dist/internal/viem-write.js +24 -0
  103. package/dist/internal/viem-write.js.map +1 -0
  104. package/dist/lens-types.d.ts +283 -0
  105. package/dist/lens-types.d.ts.map +1 -0
  106. package/dist/{typechain/ISafe.js → lens-types.js} +1 -1
  107. package/dist/lens-types.js.map +1 -0
  108. package/dist/market.d.ts +13 -16
  109. package/dist/market.d.ts.map +1 -1
  110. package/dist/market.js +207 -198
  111. package/dist/market.js.map +1 -1
  112. package/dist/mockerc20factory.d.ts +4 -15
  113. package/dist/mockerc20factory.d.ts.map +1 -1
  114. package/dist/mockerc20factory.js +20 -15
  115. package/dist/mockerc20factory.js.map +1 -1
  116. package/dist/token.d.ts +24 -11
  117. package/dist/token.d.ts.map +1 -1
  118. package/dist/token.js +78 -61
  119. package/dist/token.js.map +1 -1
  120. package/dist/types.d.ts +53 -12
  121. package/dist/types.d.ts.map +1 -1
  122. package/dist/types.js +6 -15
  123. package/dist/types.js.map +1 -1
  124. package/dist/utils/bigint.d.ts +22 -0
  125. package/dist/utils/bigint.d.ts.map +1 -0
  126. package/dist/utils/bigint.js +111 -0
  127. package/dist/utils/bigint.js.map +1 -0
  128. package/dist/utils/check-registered-borrowers.d.ts.map +1 -1
  129. package/dist/utils/check-registered-borrowers.js +7 -6
  130. package/dist/utils/check-registered-borrowers.js.map +1 -1
  131. package/dist/utils/describe-account.d.ts.map +1 -1
  132. package/dist/utils/describe-account.js +33 -4
  133. package/dist/utils/describe-account.js.map +1 -1
  134. package/dist/utils/describe-signature.d.ts.map +1 -1
  135. package/dist/utils/describe-signature.js +66 -14
  136. package/dist/utils/describe-signature.js.map +1 -1
  137. package/dist/utils/index.d.ts +2 -0
  138. package/dist/utils/index.d.ts.map +1 -1
  139. package/dist/utils/index.js +2 -0
  140. package/dist/utils/index.js.map +1 -1
  141. package/dist/utils/math.d.ts +1 -13
  142. package/dist/utils/math.d.ts.map +1 -1
  143. package/dist/utils/math.js +14 -50
  144. package/dist/utils/math.js.map +1 -1
  145. package/dist/utils/misc.d.ts +5 -4
  146. package/dist/utils/misc.d.ts.map +1 -1
  147. package/dist/utils/misc.js +6 -6
  148. package/dist/utils/misc.js.map +1 -1
  149. package/dist/utils/record-types.d.ts +4 -5
  150. package/dist/utils/record-types.d.ts.map +1 -1
  151. package/dist/utils/record-types.js +2 -2
  152. package/dist/utils/record-types.js.map +1 -1
  153. package/dist/utils/type-parsers.d.ts +9 -3
  154. package/dist/utils/type-parsers.d.ts.map +1 -1
  155. package/dist/utils/type-parsers.js +14 -13
  156. package/dist/utils/type-parsers.js.map +1 -1
  157. package/dist/utils/viem-encoding.d.ts +15 -0
  158. package/dist/utils/viem-encoding.d.ts.map +1 -0
  159. package/dist/utils/viem-encoding.js +33 -0
  160. package/dist/utils/viem-encoding.js.map +1 -0
  161. package/dist/withdrawal-batch.d.ts +6 -7
  162. package/dist/withdrawal-batch.d.ts.map +1 -1
  163. package/dist/withdrawal-batch.js +29 -30
  164. package/dist/withdrawal-batch.js.map +1 -1
  165. package/dist/withdrawal-status.d.ts +5 -5
  166. package/dist/withdrawal-status.d.ts.map +1 -1
  167. package/dist/withdrawal-status.js +15 -12
  168. package/dist/withdrawal-status.js.map +1 -1
  169. package/dist/wrapper/index.d.ts +14 -31
  170. package/dist/wrapper/index.d.ts.map +1 -1
  171. package/dist/wrapper/index.js +80 -83
  172. package/dist/wrapper/index.js.map +1 -1
  173. package/package.json +13 -11
  174. package/dist/typechain/AccountQuery.d.ts +0 -56
  175. package/dist/typechain/AccountQuery.d.ts.map +0 -1
  176. package/dist/typechain/AccountQuery.js +0 -3
  177. package/dist/typechain/AccountQuery.js.map +0 -1
  178. package/dist/typechain/AccountsQuery.d.ts +0 -56
  179. package/dist/typechain/AccountsQuery.d.ts.map +0 -1
  180. package/dist/typechain/AccountsQuery.js +0 -3
  181. package/dist/typechain/AccountsQuery.js.map +0 -1
  182. package/dist/typechain/CheckBorrowersRegistered.d.ts +0 -29
  183. package/dist/typechain/CheckBorrowersRegistered.d.ts.map +0 -1
  184. package/dist/typechain/CheckBorrowersRegistered.js +0 -3
  185. package/dist/typechain/CheckBorrowersRegistered.js.map +0 -1
  186. package/dist/typechain/CheckSafeSignature.d.ts +0 -29
  187. package/dist/typechain/CheckSafeSignature.d.ts.map +0 -1
  188. package/dist/typechain/CheckSafeSignature.js +0 -3
  189. package/dist/typechain/CheckSafeSignature.js.map +0 -1
  190. package/dist/typechain/CollateralLens.d.ts +0 -220
  191. package/dist/typechain/CollateralLens.d.ts.map +0 -1
  192. package/dist/typechain/CollateralLens.js +0 -3
  193. package/dist/typechain/CollateralLens.js.map +0 -1
  194. package/dist/typechain/DescribeSignature.d.ts +0 -102
  195. package/dist/typechain/DescribeSignature.d.ts.map +0 -1
  196. package/dist/typechain/DescribeSignature.js +0 -3
  197. package/dist/typechain/DescribeSignature.js.map +0 -1
  198. package/dist/typechain/HooksFactory.d.ts +0 -593
  199. package/dist/typechain/HooksFactory.d.ts.map +0 -1
  200. package/dist/typechain/HooksFactory.js +0 -3
  201. package/dist/typechain/HooksFactory.js.map +0 -1
  202. package/dist/typechain/HooksFactoryRevolving.d.ts +0 -603
  203. package/dist/typechain/HooksFactoryRevolving.d.ts.map +0 -1
  204. package/dist/typechain/HooksFactoryRevolving.js +0 -3
  205. package/dist/typechain/HooksFactoryRevolving.js.map +0 -1
  206. package/dist/typechain/IERC20.d.ts +0 -232
  207. package/dist/typechain/IERC20.d.ts.map +0 -1
  208. package/dist/typechain/IERC20.js +0 -3
  209. package/dist/typechain/IERC20.js.map +0 -1
  210. package/dist/typechain/IFixedTermHooks.d.ts +0 -1032
  211. package/dist/typechain/IFixedTermHooks.d.ts.map +0 -1
  212. package/dist/typechain/IFixedTermHooks.js +0 -3
  213. package/dist/typechain/IFixedTermHooks.js.map +0 -1
  214. package/dist/typechain/IOpenTermHooks.d.ts +0 -987
  215. package/dist/typechain/IOpenTermHooks.d.ts.map +0 -1
  216. package/dist/typechain/IOpenTermHooks.js +0 -3
  217. package/dist/typechain/IOpenTermHooks.js.map +0 -1
  218. package/dist/typechain/ISafe.d.ts +0 -124
  219. package/dist/typechain/ISafe.d.ts.map +0 -1
  220. package/dist/typechain/ISafe.js.map +0 -1
  221. package/dist/typechain/MarketLens.d.ts +0 -611
  222. package/dist/typechain/MarketLens.d.ts.map +0 -1
  223. package/dist/typechain/MarketLens.js +0 -3
  224. package/dist/typechain/MarketLens.js.map +0 -1
  225. package/dist/typechain/MarketLensV2.d.ts +0 -704
  226. package/dist/typechain/MarketLensV2.d.ts.map +0 -1
  227. package/dist/typechain/MarketLensV2.js +0 -3
  228. package/dist/typechain/MarketLensV2.js.map +0 -1
  229. package/dist/typechain/MarketLensV2_5.d.ts +0 -996
  230. package/dist/typechain/MarketLensV2_5.d.ts.map +0 -1
  231. package/dist/typechain/MarketLensV2_5.js +0 -3
  232. package/dist/typechain/MarketLensV2_5.js.map +0 -1
  233. package/dist/typechain/MockArchControllerOwner.d.ts +0 -130
  234. package/dist/typechain/MockArchControllerOwner.d.ts.map +0 -1
  235. package/dist/typechain/MockArchControllerOwner.js +0 -3
  236. package/dist/typechain/MockArchControllerOwner.js.map +0 -1
  237. package/dist/typechain/MockERC20Factory.d.ts +0 -122
  238. package/dist/typechain/MockERC20Factory.d.ts.map +0 -1
  239. package/dist/typechain/MockERC20Factory.js +0 -3
  240. package/dist/typechain/MockERC20Factory.js.map +0 -1
  241. package/dist/typechain/SimpleMarketCollateral.d.ts +0 -270
  242. package/dist/typechain/SimpleMarketCollateral.d.ts.map +0 -1
  243. package/dist/typechain/SimpleMarketCollateral.js +0 -3
  244. package/dist/typechain/SimpleMarketCollateral.js.map +0 -1
  245. package/dist/typechain/Wildcat4626Wrapper.sol/IWildcatMarketToken.d.ts +0 -176
  246. package/dist/typechain/Wildcat4626Wrapper.sol/IWildcatMarketToken.d.ts.map +0 -1
  247. package/dist/typechain/Wildcat4626Wrapper.sol/IWildcatMarketToken.js +0 -3
  248. package/dist/typechain/Wildcat4626Wrapper.sol/IWildcatMarketToken.js.map +0 -1
  249. package/dist/typechain/Wildcat4626Wrapper.sol/IWildcatSanctionsSentinel.d.ts +0 -44
  250. package/dist/typechain/Wildcat4626Wrapper.sol/IWildcatSanctionsSentinel.d.ts.map +0 -1
  251. package/dist/typechain/Wildcat4626Wrapper.sol/IWildcatSanctionsSentinel.js +0 -3
  252. package/dist/typechain/Wildcat4626Wrapper.sol/IWildcatSanctionsSentinel.js.map +0 -1
  253. package/dist/typechain/Wildcat4626Wrapper.sol/Wildcat4626Wrapper.d.ts +0 -501
  254. package/dist/typechain/Wildcat4626Wrapper.sol/Wildcat4626Wrapper.d.ts.map +0 -1
  255. package/dist/typechain/Wildcat4626Wrapper.sol/Wildcat4626Wrapper.js +0 -3
  256. package/dist/typechain/Wildcat4626Wrapper.sol/Wildcat4626Wrapper.js.map +0 -1
  257. package/dist/typechain/Wildcat4626Wrapper.sol/index.d.ts +0 -4
  258. package/dist/typechain/Wildcat4626Wrapper.sol/index.d.ts.map +0 -1
  259. package/dist/typechain/Wildcat4626Wrapper.sol/index.js +0 -3
  260. package/dist/typechain/Wildcat4626Wrapper.sol/index.js.map +0 -1
  261. package/dist/typechain/Wildcat4626WrapperFactory.d.ts +0 -83
  262. package/dist/typechain/Wildcat4626WrapperFactory.d.ts.map +0 -1
  263. package/dist/typechain/Wildcat4626WrapperFactory.js +0 -3
  264. package/dist/typechain/Wildcat4626WrapperFactory.js.map +0 -1
  265. package/dist/typechain/WildcatArchController.d.ts +0 -545
  266. package/dist/typechain/WildcatArchController.d.ts.map +0 -1
  267. package/dist/typechain/WildcatArchController.js +0 -3
  268. package/dist/typechain/WildcatArchController.js.map +0 -1
  269. package/dist/typechain/WildcatCollateralFactory.d.ts +0 -164
  270. package/dist/typechain/WildcatCollateralFactory.d.ts.map +0 -1
  271. package/dist/typechain/WildcatCollateralFactory.js +0 -3
  272. package/dist/typechain/WildcatCollateralFactory.js.map +0 -1
  273. package/dist/typechain/WildcatMarket.d.ts +0 -1062
  274. package/dist/typechain/WildcatMarket.d.ts.map +0 -1
  275. package/dist/typechain/WildcatMarket.js +0 -3
  276. package/dist/typechain/WildcatMarket.js.map +0 -1
  277. package/dist/typechain/WildcatMarketController.d.ts +0 -553
  278. package/dist/typechain/WildcatMarketController.d.ts.map +0 -1
  279. package/dist/typechain/WildcatMarketController.js +0 -3
  280. package/dist/typechain/WildcatMarketController.js.map +0 -1
  281. package/dist/typechain/WildcatMarketControllerFactory.d.ts +0 -344
  282. package/dist/typechain/WildcatMarketControllerFactory.d.ts.map +0 -1
  283. package/dist/typechain/WildcatMarketControllerFactory.js +0 -3
  284. package/dist/typechain/WildcatMarketControllerFactory.js.map +0 -1
  285. package/dist/typechain/WildcatMarketV2.d.ts +0 -1086
  286. package/dist/typechain/WildcatMarketV2.d.ts.map +0 -1
  287. package/dist/typechain/WildcatMarketV2.js +0 -3
  288. package/dist/typechain/WildcatMarketV2.js.map +0 -1
  289. package/dist/typechain/common.d.ts +0 -23
  290. package/dist/typechain/common.d.ts.map +0 -1
  291. package/dist/typechain/common.js +0 -3
  292. package/dist/typechain/common.js.map +0 -1
  293. package/dist/typechain/factories/AccountQuery__factory.d.ts +0 -63
  294. package/dist/typechain/factories/AccountQuery__factory.d.ts.map +0 -1
  295. package/dist/typechain/factories/AccountQuery__factory.js +0 -96
  296. package/dist/typechain/factories/AccountQuery__factory.js.map +0 -1
  297. package/dist/typechain/factories/AccountsQuery__factory.d.ts +0 -63
  298. package/dist/typechain/factories/AccountsQuery__factory.d.ts.map +0 -1
  299. package/dist/typechain/factories/AccountsQuery__factory.js +0 -96
  300. package/dist/typechain/factories/AccountsQuery__factory.js.map +0 -1
  301. package/dist/typechain/factories/CheckBorrowersRegistered__factory.d.ts +0 -36
  302. package/dist/typechain/factories/CheckBorrowersRegistered__factory.d.ts.map +0 -1
  303. package/dist/typechain/factories/CheckBorrowersRegistered__factory.js +0 -60
  304. package/dist/typechain/factories/CheckBorrowersRegistered__factory.js.map +0 -1
  305. package/dist/typechain/factories/CheckSafeSignature__factory.d.ts +0 -40
  306. package/dist/typechain/factories/CheckSafeSignature__factory.d.ts.map +0 -1
  307. package/dist/typechain/factories/CheckSafeSignature__factory.js +0 -65
  308. package/dist/typechain/factories/CheckSafeSignature__factory.js.map +0 -1
  309. package/dist/typechain/factories/CollateralLens__factory.d.ts +0 -854
  310. package/dist/typechain/factories/CollateralLens__factory.d.ts.map +0 -1
  311. package/dist/typechain/factories/CollateralLens__factory.js +0 -1101
  312. package/dist/typechain/factories/CollateralLens__factory.js.map +0 -1
  313. package/dist/typechain/factories/DescribeSignature__factory.d.ts +0 -145
  314. package/dist/typechain/factories/DescribeSignature__factory.d.ts.map +0 -1
  315. package/dist/typechain/factories/DescribeSignature__factory.js +0 -203
  316. package/dist/typechain/factories/DescribeSignature__factory.js.map +0 -1
  317. package/dist/typechain/factories/HooksFactoryRevolving__factory.d.ts +0 -872
  318. package/dist/typechain/factories/HooksFactoryRevolving__factory.d.ts.map +0 -1
  319. package/dist/typechain/factories/HooksFactoryRevolving__factory.js +0 -1131
  320. package/dist/typechain/factories/HooksFactoryRevolving__factory.js.map +0 -1
  321. package/dist/typechain/factories/HooksFactory__factory.d.ts +0 -902
  322. package/dist/typechain/factories/HooksFactory__factory.d.ts.map +0 -1
  323. package/dist/typechain/factories/HooksFactory__factory.js +0 -1168
  324. package/dist/typechain/factories/HooksFactory__factory.js.map +0 -1
  325. package/dist/typechain/factories/IERC20__factory.d.ts +0 -235
  326. package/dist/typechain/factories/IERC20__factory.d.ts.map +0 -1
  327. package/dist/typechain/factories/IERC20__factory.js +0 -315
  328. package/dist/typechain/factories/IERC20__factory.js.map +0 -1
  329. package/dist/typechain/factories/IFixedTermHooks__factory.d.ts +0 -1894
  330. package/dist/typechain/factories/IFixedTermHooks__factory.d.ts.map +0 -1
  331. package/dist/typechain/factories/IFixedTermHooks__factory.js +0 -2423
  332. package/dist/typechain/factories/IFixedTermHooks__factory.js.map +0 -1
  333. package/dist/typechain/factories/IOpenTermHooks__factory.d.ts +0 -1791
  334. package/dist/typechain/factories/IOpenTermHooks__factory.d.ts.map +0 -1
  335. package/dist/typechain/factories/IOpenTermHooks__factory.js +0 -2293
  336. package/dist/typechain/factories/IOpenTermHooks__factory.js.map +0 -1
  337. package/dist/typechain/factories/ISafe__factory.d.ts +0 -163
  338. package/dist/typechain/factories/ISafe__factory.d.ts.map +0 -1
  339. package/dist/typechain/factories/ISafe__factory.js +0 -225
  340. package/dist/typechain/factories/ISafe__factory.js.map +0 -1
  341. package/dist/typechain/factories/MarketLensV2_5__factory.d.ts +0 -14397
  342. package/dist/typechain/factories/MarketLensV2_5__factory.d.ts.map +0 -1
  343. package/dist/typechain/factories/MarketLensV2_5__factory.js +0 -18393
  344. package/dist/typechain/factories/MarketLensV2_5__factory.js.map +0 -1
  345. package/dist/typechain/factories/MarketLensV2__factory.d.ts +0 -6612
  346. package/dist/typechain/factories/MarketLensV2__factory.d.ts.map +0 -1
  347. package/dist/typechain/factories/MarketLensV2__factory.js +0 -8454
  348. package/dist/typechain/factories/MarketLensV2__factory.js.map +0 -1
  349. package/dist/typechain/factories/MarketLens__factory.d.ts +0 -3572
  350. package/dist/typechain/factories/MarketLens__factory.d.ts.map +0 -1
  351. package/dist/typechain/factories/MarketLens__factory.js +0 -4569
  352. package/dist/typechain/factories/MarketLens__factory.js.map +0 -1
  353. package/dist/typechain/factories/MockArchControllerOwner__factory.d.ts +0 -85
  354. package/dist/typechain/factories/MockArchControllerOwner__factory.d.ts.map +0 -1
  355. package/dist/typechain/factories/MockArchControllerOwner__factory.js +0 -118
  356. package/dist/typechain/factories/MockArchControllerOwner__factory.js.map +0 -1
  357. package/dist/typechain/factories/MockERC20Factory__factory.d.ts +0 -114
  358. package/dist/typechain/factories/MockERC20Factory__factory.d.ts.map +0 -1
  359. package/dist/typechain/factories/MockERC20Factory__factory.js +0 -157
  360. package/dist/typechain/factories/MockERC20Factory__factory.js.map +0 -1
  361. package/dist/typechain/factories/SimpleMarketCollateral__factory.d.ts +0 -264
  362. package/dist/typechain/factories/SimpleMarketCollateral__factory.d.ts.map +0 -1
  363. package/dist/typechain/factories/SimpleMarketCollateral__factory.js +0 -354
  364. package/dist/typechain/factories/SimpleMarketCollateral__factory.js.map +0 -1
  365. package/dist/typechain/factories/Wildcat4626Wrapper.sol/IWildcatMarketToken__factory.d.ts +0 -193
  366. package/dist/typechain/factories/Wildcat4626Wrapper.sol/IWildcatMarketToken__factory.d.ts.map +0 -1
  367. package/dist/typechain/factories/Wildcat4626Wrapper.sol/IWildcatMarketToken__factory.js +0 -263
  368. package/dist/typechain/factories/Wildcat4626Wrapper.sol/IWildcatMarketToken__factory.js.map +0 -1
  369. package/dist/typechain/factories/Wildcat4626Wrapper.sol/IWildcatSanctionsSentinel__factory.d.ts +0 -27
  370. package/dist/typechain/factories/Wildcat4626Wrapper.sol/IWildcatSanctionsSentinel__factory.d.ts.map +0 -1
  371. package/dist/typechain/factories/Wildcat4626Wrapper.sol/IWildcatSanctionsSentinel__factory.js +0 -44
  372. package/dist/typechain/factories/Wildcat4626Wrapper.sol/IWildcatSanctionsSentinel__factory.js.map +0 -1
  373. package/dist/typechain/factories/Wildcat4626Wrapper.sol/Wildcat4626Wrapper__factory.d.ts +0 -718
  374. package/dist/typechain/factories/Wildcat4626Wrapper.sol/Wildcat4626Wrapper__factory.d.ts.map +0 -1
  375. package/dist/typechain/factories/Wildcat4626Wrapper.sol/Wildcat4626Wrapper__factory.js +0 -946
  376. package/dist/typechain/factories/Wildcat4626Wrapper.sol/Wildcat4626Wrapper__factory.js.map +0 -1
  377. package/dist/typechain/factories/Wildcat4626Wrapper.sol/index.d.ts +0 -4
  378. package/dist/typechain/factories/Wildcat4626Wrapper.sol/index.d.ts.map +0 -1
  379. package/dist/typechain/factories/Wildcat4626Wrapper.sol/index.js +0 -13
  380. package/dist/typechain/factories/Wildcat4626Wrapper.sol/index.js.map +0 -1
  381. package/dist/typechain/factories/Wildcat4626WrapperFactory__factory.d.ts +0 -82
  382. package/dist/typechain/factories/Wildcat4626WrapperFactory__factory.d.ts.map +0 -1
  383. package/dist/typechain/factories/Wildcat4626WrapperFactory__factory.js +0 -117
  384. package/dist/typechain/factories/Wildcat4626WrapperFactory__factory.js.map +0 -1
  385. package/dist/typechain/factories/WildcatArchController__factory.d.ts +0 -554
  386. package/dist/typechain/factories/WildcatArchController__factory.d.ts.map +0 -1
  387. package/dist/typechain/factories/WildcatArchController__factory.js +0 -728
  388. package/dist/typechain/factories/WildcatArchController__factory.js.map +0 -1
  389. package/dist/typechain/factories/WildcatCollateralFactory__factory.d.ts +0 -160
  390. package/dist/typechain/factories/WildcatCollateralFactory__factory.d.ts.map +0 -1
  391. package/dist/typechain/factories/WildcatCollateralFactory__factory.js +0 -223
  392. package/dist/typechain/factories/WildcatCollateralFactory__factory.js.map +0 -1
  393. package/dist/typechain/factories/WildcatMarketControllerFactory__factory.d.ts +0 -421
  394. package/dist/typechain/factories/WildcatMarketControllerFactory__factory.d.ts.map +0 -1
  395. package/dist/typechain/factories/WildcatMarketControllerFactory__factory.js +0 -549
  396. package/dist/typechain/factories/WildcatMarketControllerFactory__factory.js.map +0 -1
  397. package/dist/typechain/factories/WildcatMarketController__factory.d.ts +0 -671
  398. package/dist/typechain/factories/WildcatMarketController__factory.d.ts.map +0 -1
  399. package/dist/typechain/factories/WildcatMarketController__factory.js +0 -870
  400. package/dist/typechain/factories/WildcatMarketController__factory.js.map +0 -1
  401. package/dist/typechain/factories/WildcatMarketV2__factory.d.ts +0 -1304
  402. package/dist/typechain/factories/WildcatMarketV2__factory.d.ts.map +0 -1
  403. package/dist/typechain/factories/WildcatMarketV2__factory.js +0 -1680
  404. package/dist/typechain/factories/WildcatMarketV2__factory.js.map +0 -1
  405. package/dist/typechain/factories/WildcatMarket__factory.d.ts +0 -1326
  406. package/dist/typechain/factories/WildcatMarket__factory.d.ts.map +0 -1
  407. package/dist/typechain/factories/WildcatMarket__factory.js +0 -1712
  408. package/dist/typechain/factories/WildcatMarket__factory.js.map +0 -1
  409. package/dist/typechain/factories/index.d.ts +0 -27
  410. package/dist/typechain/factories/index.d.ts.map +0 -1
  411. package/dist/typechain/factories/index.js +0 -81
  412. package/dist/typechain/factories/index.js.map +0 -1
  413. package/dist/typechain/index.d.ts +0 -73
  414. package/dist/typechain/index.d.ts.map +0 -1
  415. package/dist/typechain/index.js +0 -84
  416. package/dist/typechain/index.js.map +0 -1
package/dist/market.js CHANGED
@@ -1,16 +1,23 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.Market = void 0;
4
- const ethers_1 = require("ethers");
5
- const abstract_signer_1 = require("@ethersproject/abstract-signer");
6
- const typechain_1 = require("./typechain");
7
4
  const constants_1 = require("./constants");
5
+ const arch_controller_1 = require("./internal/arch-controller");
6
+ const market_lens_1 = require("./internal/market-lens");
8
7
  const token_1 = require("./token");
9
8
  const types_1 = require("./types");
10
- const utils_1 = require("ethers/lib/utils");
11
9
  const account_1 = require("./account");
12
- const utils_2 = require("./utils");
10
+ const utils_1 = require("./utils");
13
11
  const access_1 = require("./access");
12
+ const abi_1 = require("./abi");
13
+ const viem_write_1 = require("./internal/viem-write");
14
+ const ethers_signer_1 = require("./internal/ethers-signer");
15
+ const ethers_viem_1 = require("./internal/ethers-viem");
16
+ const viem_read_1 = require("./internal/viem-read");
17
+ const getAllowForceBuyBacksFromHookedMarket = (hookedMarket, allowForceBuyBacksIndex) => {
18
+ return (hookedMarket.allowForceBuyBacks ??
19
+ Boolean(hookedMarket[allowForceBuyBacksIndex]));
20
+ };
14
21
  const hasUnifiedLatestLensForDirectReads = (chainId) => {
15
22
  return (0, constants_1.hasDeploymentAddress)(chainId, "MarketLensV2_5");
16
23
  };
@@ -22,21 +29,17 @@ const toUnifiedMarketDataV2 = (data) => {
22
29
  market: data,
23
30
  commitmentFeeBips: {
24
31
  isPresent: false,
25
- value: ethers_1.BigNumber.from(0)
32
+ value: 0n
26
33
  },
27
34
  drawnAmount: {
28
35
  isPresent: false,
29
- value: ethers_1.BigNumber.from(0)
36
+ value: 0n
30
37
  }
31
38
  };
32
39
  };
33
40
  class Market extends types_1.ContractWrapper {
34
- get _contractAddress() {
35
- return this.address;
36
- }
37
41
  constructor({ provider, ...args }) {
38
42
  super(provider);
39
- this.contractFactory = typechain_1.WildcatMarket__factory;
40
43
  const { address, name, symbol, decimals } = args.marketToken;
41
44
  Object.assign(this, {
42
45
  address,
@@ -45,9 +48,9 @@ class Market extends types_1.ContractWrapper {
45
48
  decimals
46
49
  });
47
50
  Object.assign(this, args);
48
- this.depositRecords = (args.depositRecords ?? []).map((log) => (0, utils_2.parseMarketRecord)(this.underlyingToken, log));
49
- this.repaymentRecords = (args.repaymentRecords ?? []).map((log) => (0, utils_2.parseMarketRecord)(this.underlyingToken, log));
50
- this.borrowRecords = (args.borrowRecords ?? []).map((log) => (0, utils_2.parseMarketRecord)(this.underlyingToken, log));
51
+ this.depositRecords = (args.depositRecords ?? []).map((log) => (0, utils_1.parseMarketRecord)(this.underlyingToken, log));
52
+ this.repaymentRecords = (args.repaymentRecords ?? []).map((log) => (0, utils_1.parseMarketRecord)(this.underlyingToken, log));
53
+ this.borrowRecords = (args.borrowRecords ?? []).map((log) => (0, utils_1.parseMarketRecord)(this.underlyingToken, log));
51
54
  this.feeCollectionRecords = (args.feeCollectionRecords ?? []).map(({ feesCollected, __typename, ...rest }) => ({
52
55
  ...rest,
53
56
  __typename: "FeesCollected",
@@ -72,7 +75,7 @@ class Market extends types_1.ContractWrapper {
72
75
  /** @returns Percentage growth of the market since it was created */
73
76
  get allTimeGrowth() {
74
77
  // 27 - 2 to convert to percentage
75
- return +(0, utils_1.formatUnits)(this.scaleFactor, 25);
78
+ return +(0, utils_1.formatFixedBigint)(this.scaleFactor, 25, 25);
76
79
  }
77
80
  /** @returns Maximum amount of underlying token that can be deposited */
78
81
  get maximumDeposit() {
@@ -85,18 +88,13 @@ class Market extends types_1.ContractWrapper {
85
88
  return undefined;
86
89
  }
87
90
  const totalSupply = this.totalSupply.raw;
88
- const drawnAmountRaw = drawnAmount.raw.gt(totalSupply) ? totalSupply : drawnAmount.raw;
89
- const utilizationBips = totalSupply.gt(0)
90
- ? drawnAmountRaw.mul(utils_2.BIP).div(totalSupply).toNumber()
91
- : 0;
92
- const utilizationAprBips = totalSupply.gt(0)
93
- ? drawnAmountRaw.mul(this.annualInterestBips).div(totalSupply).toNumber()
91
+ const drawnAmountRaw = drawnAmount.raw > totalSupply ? totalSupply : drawnAmount.raw;
92
+ const utilizationBips = totalSupply > 0n ? Number((drawnAmountRaw * utils_1.BIP_BIGINT) / totalSupply) : 0;
93
+ const utilizationAprBips = totalSupply > 0n
94
+ ? Number((drawnAmountRaw * BigInt(this.annualInterestBips)) / totalSupply)
94
95
  : 0;
95
96
  const blendedBaseAprBips = commitmentFeeBips + utilizationAprBips;
96
- const protocolAprBips = ethers_1.BigNumber.from(blendedBaseAprBips)
97
- .mul(this.protocolFeeBips)
98
- .div(utils_2.BIP)
99
- .toNumber();
97
+ const protocolAprBips = Number((BigInt(blendedBaseAprBips) * BigInt(this.protocolFeeBips)) / utils_1.BIP_BIGINT);
100
98
  const penaltyAprBips = this.isIncurringPenalties ? this.delinquencyFeeBips : 0;
101
99
  return {
102
100
  commitmentFeeBips,
@@ -113,13 +111,13 @@ class Market extends types_1.ContractWrapper {
113
111
  return this.currentRevolvingAprMetrics?.blendedBaseAprBips ?? this.annualInterestBips;
114
112
  }
115
113
  get currentBaseLenderAPR() {
116
- return (0, utils_2.bipToRay)(this.currentBaseLenderAprBips);
114
+ return (0, utils_1.bipToRayBigint)(this.currentBaseLenderAprBips);
117
115
  }
118
116
  get currentPenaltyAPR() {
119
- return this.isIncurringPenalties ? (0, utils_2.bipToRay)(this.delinquencyFeeBips) : ethers_1.BigNumber.from(0);
117
+ return this.isIncurringPenalties ? (0, utils_1.bipToRayBigint)(this.delinquencyFeeBips) : 0n;
120
118
  }
121
119
  get currentProtocolAPR() {
122
- return (0, utils_2.bipMul)(this.currentBaseLenderAPR, ethers_1.BigNumber.from(this.protocolFeeBips));
120
+ return (0, utils_1.bipMulBigint)(this.currentBaseLenderAPR, this.protocolFeeBips);
123
121
  }
124
122
  /** @returns Whether the borrower is in penalized delinquency */
125
123
  get isIncurringPenalties() {
@@ -166,7 +164,7 @@ class Market extends types_1.ContractWrapper {
166
164
  const targetRatio = this.reserveRatioBips / 100;
167
165
  const actualRatio = this.totalSupply.eq(0)
168
166
  ? 100
169
- : +(0, utils_1.formatUnits)(this.totalAssets.raw.mul(utils_2.RAY).div(this.totalSupply.raw), 25);
167
+ : +(0, utils_1.formatFixedBigint)((this.totalAssets.raw * utils_1.RAY_BIGINT) / this.totalSupply.raw, 25, 25);
170
168
  if (this.temporaryReserveRatio) {
171
169
  return {
172
170
  targetRatio,
@@ -179,7 +177,7 @@ class Market extends types_1.ContractWrapper {
179
177
  return { targetRatio, actualRatio };
180
178
  }
181
179
  get normalizedPendingWithdrawals() {
182
- return this.underlyingToken.getAmount((0, utils_2.rayMul)(this.scaledPendingWithdrawals, this.scaleFactor));
180
+ return this.underlyingToken.getAmount((0, utils_1.rayMulBigint)(this.scaledPendingWithdrawals, this.scaleFactor));
183
181
  }
184
182
  /** @returns Whether the borrower can change the APR */
185
183
  get canReduceAPR() {
@@ -195,7 +193,7 @@ class Market extends types_1.ContractWrapper {
195
193
  return this.totalAssets.satsub(unavailableAssets);
196
194
  }
197
195
  get minimumReserves() {
198
- return this.underlyingToken.getAmount((0, utils_2.bipMul)(this.outstandingTotalSupply.raw, ethers_1.BigNumber.from(this.reserveRatioBips)));
196
+ return this.outstandingTotalSupply.bipMul(this.reserveRatioBips);
199
197
  }
200
198
  get borrowableAssets() {
201
199
  return this.totalAssets.satsub(this.coverageLiquidity);
@@ -233,59 +231,59 @@ class Market extends types_1.ContractWrapper {
233
231
  };
234
232
  }
235
233
  normalizeAmount(amount) {
236
- return (0, utils_2.rayMul)(amount, this.scaleFactor);
234
+ return (0, utils_1.rayMulBigint)(amount, this.scaleFactor);
237
235
  }
238
236
  scaleAmount(amount) {
239
- return (0, utils_2.rayDiv)(amount, this.scaleFactor);
237
+ return (0, utils_1.rayDivBigint)(amount, this.scaleFactor);
240
238
  }
241
239
  get secondsBeforeDelinquency() {
242
240
  if (this.willBeDelinquent || this.totalDebts.eq(0))
243
241
  return 0;
244
242
  const scaledBase = this.scaledTotalSupply;
245
- const basePrincipal = this.underlyingToken.getAmount((0, utils_2.rayMul)(scaledBase, this.scaleFactor));
243
+ const basePrincipal = this.underlyingToken.getAmount((0, utils_1.rayMulBigint)(scaledBase, this.scaleFactor));
246
244
  const baseAPRRay = this.currentBaseLenderAPR;
247
245
  const protocolFeeAPRRay = this.currentProtocolAPR;
248
246
  const delinquencyFeeAPRRay = this.currentPenaltyAPR;
249
247
  // lender APR portion
250
248
  const lenderRequirementGrowthPerSecond = basePrincipal
251
- .rayMul(baseAPRRay.add(delinquencyFeeAPRRay))
252
- .div(utils_2.SECONDS_IN_365_DAYS)
249
+ .rayMul(baseAPRRay + delinquencyFeeAPRRay)
250
+ .div(utils_1.SECONDS_IN_365_DAYS)
253
251
  .bipMul(this.reserveRatioBips);
254
252
  // protocol fee portion
255
253
  const protocolRequirementGrowthPerSecond = basePrincipal
256
254
  .rayMul(protocolFeeAPRRay)
257
- .div(utils_2.SECONDS_IN_365_DAYS);
255
+ .div(utils_1.SECONDS_IN_365_DAYS);
258
256
  const totalRequirementGrowthPerSecond = lenderRequirementGrowthPerSecond.add(protocolRequirementGrowthPerSecond.raw);
259
257
  // essentially if apr=0 and rr=0 then bips alone wont move us to delinquency
260
- if (totalRequirementGrowthPerSecond.raw.isZero())
258
+ if (totalRequirementGrowthPerSecond.raw === 0n)
261
259
  return Number.MAX_SAFE_INTEGER;
262
260
  const buffer = this.liquidReserves.sub(this.minimumReserves);
263
- if (buffer.raw.lte(0))
261
+ if (buffer.raw <= 0n)
264
262
  return 0; // we are delinquent
265
- return buffer.div(totalRequirementGrowthPerSecond, true).raw.toNumber(); // seconds until the party
263
+ return Number(buffer.div(totalRequirementGrowthPerSecond, true).raw); // seconds until the party
266
264
  }
267
265
  getSecondsBeforeDelinquencyForBorrowedAmount(borrowAmount) {
268
266
  if (this.isDelinquent || this.totalDebts.eq(0))
269
267
  return 0;
270
268
  const scaledBase = this.scaledTotalSupply;
271
- const basePrincipal = this.underlyingToken.getAmount((0, utils_2.rayMul)(scaledBase, this.scaleFactor));
269
+ const basePrincipal = this.underlyingToken.getAmount((0, utils_1.rayMulBigint)(scaledBase, this.scaleFactor));
272
270
  const baseAPRRay = this.currentBaseLenderAPR;
273
271
  const protocolFeeAPRRay = this.currentProtocolAPR;
274
272
  const delinquencyFeeAPRRay = this.currentPenaltyAPR;
275
273
  const lenderRequirementGrowthPerSecond = basePrincipal
276
- .rayMul(baseAPRRay.add(delinquencyFeeAPRRay))
277
- .div(utils_2.SECONDS_IN_365_DAYS)
274
+ .rayMul(baseAPRRay + delinquencyFeeAPRRay)
275
+ .div(utils_1.SECONDS_IN_365_DAYS)
278
276
  .bipMul(this.reserveRatioBips);
279
277
  const protocolRequirementGrowthPerSecond = basePrincipal
280
278
  .rayMul(protocolFeeAPRRay)
281
- .div(utils_2.SECONDS_IN_365_DAYS);
279
+ .div(utils_1.SECONDS_IN_365_DAYS);
282
280
  const totalRequirementGrowthPerSecond = lenderRequirementGrowthPerSecond.add(protocolRequirementGrowthPerSecond.raw);
283
- if (totalRequirementGrowthPerSecond.raw.isZero())
281
+ if (totalRequirementGrowthPerSecond.raw === 0n)
284
282
  return Number.MAX_SAFE_INTEGER;
285
283
  const postBorrowBuffer = this.liquidReserves.sub(this.minimumReserves).sub(borrowAmount);
286
- if (postBorrowBuffer.raw.lte(0))
284
+ if (postBorrowBuffer.raw <= 0n)
287
285
  return 0;
288
- return postBorrowBuffer.div(totalRequirementGrowthPerSecond, true).raw.toNumber();
286
+ return Number(postBorrowBuffer.div(totalRequirementGrowthPerSecond, true).raw);
289
287
  }
290
288
  /**
291
289
  * @dev Calculate token amount to be repayed by borrower for a given duration
@@ -293,20 +291,20 @@ class Market extends types_1.ContractWrapper {
293
291
  * @return token amount to be repayed
294
292
  **/
295
293
  repayRequiredForDuration(timeToPayInSeconds) {
296
- const scaledBase = this.scaledTotalSupply.sub(this.scaledPendingWithdrawals);
297
- if (scaledBase.lte(0))
294
+ const scaledBase = this.scaledTotalSupply - this.scaledPendingWithdrawals;
295
+ if (scaledBase <= 0n)
298
296
  return this.underlyingToken.getAmount(0);
299
- const basePrincipal = this.underlyingToken.getAmount((0, utils_2.rayMul)(scaledBase, this.scaleFactor));
297
+ const basePrincipal = this.underlyingToken.getAmount((0, utils_1.rayMulBigint)(scaledBase, this.scaleFactor));
300
298
  const baseAPRRay = this.currentBaseLenderAPR;
301
299
  const protocolFeeAPRRay = this.currentProtocolAPR;
302
300
  const delinquencyFeeAPRRay = this.currentPenaltyAPR;
303
301
  const lenderRequirementGrowthPerSecond = basePrincipal
304
- .rayMul(baseAPRRay.add(delinquencyFeeAPRRay))
305
- .div(utils_2.SECONDS_IN_365_DAYS)
302
+ .rayMul(baseAPRRay + delinquencyFeeAPRRay)
303
+ .div(utils_1.SECONDS_IN_365_DAYS)
306
304
  .bipMul(this.reserveRatioBips);
307
305
  const protocolRequirementGrowthPerSecond = basePrincipal
308
306
  .rayMul(protocolFeeAPRRay)
309
- .div(utils_2.SECONDS_IN_365_DAYS);
307
+ .div(utils_1.SECONDS_IN_365_DAYS);
310
308
  const totalRequirementGrowthPerSecond = lenderRequirementGrowthPerSecond.add(protocolRequirementGrowthPerSecond.raw);
311
309
  return totalRequirementGrowthPerSecond.mul(timeToPayInSeconds);
312
310
  }
@@ -318,9 +316,8 @@ class Market extends types_1.ContractWrapper {
318
316
  * @return apr paid by borrower in ray
319
317
  */
320
318
  get effectiveBorrowerAPR() {
321
- let apr = (0, utils_2.bipMul)(this.currentBaseLenderAPR, utils_2.BIP.add(this.protocolFeeBips));
322
- apr = apr.add(this.currentPenaltyAPR);
323
- return apr;
319
+ return ((0, utils_1.bipMulBigint)(this.currentBaseLenderAPR, utils_1.BIP_BIGINT + BigInt(this.protocolFeeBips)) +
320
+ this.currentPenaltyAPR);
324
321
  }
325
322
  /**
326
323
  * @dev Calculate effective interest rate currently earned by lenders.
@@ -329,31 +326,39 @@ class Market extends types_1.ContractWrapper {
329
326
  * @return apr earned by lender in ray
330
327
  */
331
328
  get effectiveLenderAPR() {
332
- return this.currentBaseLenderAPR.add(this.currentPenaltyAPR);
329
+ return this.currentBaseLenderAPR + this.currentPenaltyAPR;
333
330
  }
334
331
  /* -------------------------------------------------------------------------- */
335
332
  /* Withdrawal Execution */
336
333
  /* -------------------------------------------------------------------------- */
337
334
  async executeWithdrawal({ lender, expiry }) {
338
- return this.contract.executeWithdrawal(lender, expiry);
335
+ return (0, viem_write_1.submitPreparedTransaction)(this.signer, (0, utils_1.prepareTransaction)({
336
+ to: this.address,
337
+ abi: abi_1.wildcatMarketAbi,
338
+ functionName: "executeWithdrawal",
339
+ args: [lender, expiry]
340
+ }));
339
341
  }
340
342
  async executeWithdrawals(withdrawals) {
341
343
  const lenders = withdrawals.map((w) => w.lender);
342
344
  const expiries = withdrawals.map((w) => w.expiry);
343
- return this.contract.executeWithdrawals(lenders, expiries);
345
+ return (0, viem_write_1.submitPreparedTransaction)(this.signer, (0, utils_1.prepareTransaction)({
346
+ to: this.address,
347
+ abi: abi_1.wildcatMarketAbi,
348
+ functionName: "executeWithdrawals",
349
+ args: [lenders, expiries]
350
+ }));
344
351
  }
345
352
  populateRepayAndProcessUnpaidWithdrawalBatches(amount, maxBatches = 10) {
346
- return {
353
+ return (0, utils_1.prepareTransaction)({
347
354
  to: this.address,
348
- data: this.contract.interface.encodeFunctionData("repayAndProcessUnpaidWithdrawalBatches", [
349
- amount.raw,
350
- maxBatches
351
- ]),
352
- value: "0"
353
- };
355
+ abi: abi_1.wildcatMarketAbi,
356
+ functionName: "repayAndProcessUnpaidWithdrawalBatches",
357
+ args: [amount.raw, maxBatches]
358
+ });
354
359
  }
355
360
  async repayAndProcessUnpaidWithdrawalBatches(amount, maxBatches = 10) {
356
- return this.contract.repayAndProcessUnpaidWithdrawalBatches(amount.raw, maxBatches);
361
+ return (0, viem_write_1.submitPreparedTransaction)(this.signer, this.populateRepayAndProcessUnpaidWithdrawalBatches(amount, maxBatches));
357
362
  }
358
363
  /* -------------------------------------------------------------------------- */
359
364
  /* Set APR */
@@ -369,7 +374,8 @@ class Market extends types_1.ContractWrapper {
369
374
  if (annualInterestBips < originalAnnualInterestBips) {
370
375
  let doubleRelativeDiff;
371
376
  if (this.version === types_1.MarketVersion.V2) {
372
- const relativeDiff = (0, utils_2.mulDiv)((0, token_1.toBn)(10000), (0, token_1.toBn)(originalAnnualInterestBips - annualInterestBips), (0, token_1.toBn)(originalAnnualInterestBips)).toNumber();
377
+ const relativeDiff = Number((10000n * BigInt(originalAnnualInterestBips - annualInterestBips)) /
378
+ BigInt(originalAnnualInterestBips));
373
379
  if (relativeDiff <= 2500) {
374
380
  // In v2, if the relative diff is 25% or less, the reserve ratio is not changed
375
381
  return originalReserveRatioBips;
@@ -377,7 +383,8 @@ class Market extends types_1.ContractWrapper {
377
383
  doubleRelativeDiff = 2 * relativeDiff;
378
384
  }
379
385
  else {
380
- doubleRelativeDiff = (0, utils_2.mulDiv)((0, token_1.toBn)(20000), (0, token_1.toBn)(originalAnnualInterestBips - annualInterestBips), (0, token_1.toBn)(originalAnnualInterestBips)).toNumber();
386
+ doubleRelativeDiff = Number((20000n * BigInt(originalAnnualInterestBips - annualInterestBips)) /
387
+ BigInt(originalAnnualInterestBips));
381
388
  }
382
389
  const boundRelativeDiff = Math.min(10000, doubleRelativeDiff);
383
390
  return Math.max(boundRelativeDiff, originalReserveRatioBips);
@@ -389,10 +396,11 @@ class Market extends types_1.ContractWrapper {
389
396
  return originalReserveRatioBips;
390
397
  }
391
398
  calculateLiquidityCoverageForReserveRatio(reserveRatio) {
392
- const scaledRequiredReserves = (0, utils_2.bipMul)(this.scaledTotalSupply.sub(this.scaledPendingWithdrawals), (0, token_1.toBn)(reserveRatio)).add(this.scaledPendingWithdrawals);
393
- return this.underlyingToken.getAmount((0, utils_2.rayMul)(scaledRequiredReserves, this.scaleFactor)
394
- .add(this.lastAccruedProtocolFees.raw)
395
- .add(this.normalizedUnclaimedWithdrawals.raw));
399
+ const scaledRequiredReserves = (0, utils_1.bipMulBigint)(this.scaledTotalSupply - this.scaledPendingWithdrawals, reserveRatio) +
400
+ this.scaledPendingWithdrawals;
401
+ return this.underlyingToken.getAmount((0, utils_1.rayMulBigint)(scaledRequiredReserves, this.scaleFactor) +
402
+ this.lastAccruedProtocolFees.raw +
403
+ this.normalizedUnclaimedWithdrawals.raw);
396
404
  }
397
405
  canChangeAPR(annualInterestBips) {
398
406
  const originalAnnualInterestBips = this.temporaryReserveRatio
@@ -425,7 +433,7 @@ class Market extends types_1.ContractWrapper {
425
433
  if (this.version === types_1.MarketVersion.V2) {
426
434
  if (hasUnifiedLatestLensForDirectReads(this.chainId)) {
427
435
  try {
428
- const market = await (0, constants_1.getLensV2_5Contract)(this.chainId, this.provider).getMarketDataV2(this.address);
436
+ const market = await (0, market_lens_1.getUnifiedMarketDataV2)(this.chainId, this.provider, this.address);
429
437
  this.updateWith(market);
430
438
  return;
431
439
  }
@@ -433,74 +441,78 @@ class Market extends types_1.ContractWrapper {
433
441
  // Fall back to the pre-2.5 V2 lens until unified lens deployment is reliable.
434
442
  }
435
443
  }
436
- const market = await (0, constants_1.getLensV2Contract)(this.chainId, this.provider).getMarketData(this.address);
444
+ const market = await (0, market_lens_1.getV2MarketData)(this.chainId, this.provider, this.address);
437
445
  this.updateWith(market);
438
446
  return;
439
447
  }
440
- const market = await (0, constants_1.getLensContract)(this.chainId, this.provider).getMarketData(this.address);
448
+ const market = await (0, market_lens_1.getLegacyMarketData)(this.chainId, this.provider, this.address);
441
449
  this.updateWith(market);
442
450
  }
443
451
  updateWith(data) {
444
452
  const baseData = "market" in data ? data.market : data;
453
+ const nextScaleFactor = (0, token_1.toRawAmount)(baseData.scaleFactor);
454
+ const nextScaledTotalSupply = (0, token_1.toRawAmount)(baseData.scaledTotalSupply);
455
+ const nextScaledPendingWithdrawals = (0, token_1.toRawAmount)(baseData.scaledPendingWithdrawals);
456
+ const nextLastAccruedProtocolFees = (0, token_1.toRawAmount)(baseData.lastAccruedProtocolFees);
445
457
  // Note: this adds all the interest accrued to the base interest accrued, since the lens
446
458
  // doesn't give us any way to distinguish between base interest and delinquency fees.
447
- if (this.scaledTotalSupply.eq(baseData.scaledTotalSupply) &&
448
- baseData.scaleFactor.gt(this.scaleFactor) &&
459
+ if (this.scaledTotalSupply === nextScaledTotalSupply &&
460
+ nextScaleFactor > this.scaleFactor &&
449
461
  this.totalBaseInterestAccrued) {
450
- const lastTotalValue = (0, utils_2.rayMul)(this.scaledTotalSupply, this.scaleFactor);
451
- const currentTotalValue = (0, utils_2.rayMul)(this.scaledTotalSupply, baseData.scaleFactor);
452
- const baseInterestAccrued = currentTotalValue.sub(lastTotalValue);
462
+ const lastTotalValue = (0, utils_1.rayMulBigint)(this.scaledTotalSupply, this.scaleFactor);
463
+ const currentTotalValue = (0, utils_1.rayMulBigint)(this.scaledTotalSupply, nextScaleFactor);
464
+ const baseInterestAccrued = currentTotalValue - lastTotalValue;
453
465
  this.totalBaseInterestAccrued = this.totalBaseInterestAccrued.add(baseInterestAccrued);
454
466
  }
455
- if (baseData.lastAccruedProtocolFees.gt(this.lastAccruedProtocolFees.raw) &&
467
+ if (nextLastAccruedProtocolFees > this.lastAccruedProtocolFees.raw &&
456
468
  this.totalProtocolFeesAccrued) {
457
- this.totalProtocolFeesAccrued = this.totalProtocolFeesAccrued.add(baseData.lastAccruedProtocolFees.sub(this.lastAccruedProtocolFees.raw));
469
+ this.totalProtocolFeesAccrued = this.totalProtocolFeesAccrued.add(nextLastAccruedProtocolFees - this.lastAccruedProtocolFees.raw);
458
470
  }
459
471
  this.feeRecipient = baseData.feeRecipient;
460
- this.protocolFeeBips = baseData.protocolFeeBips.toNumber();
461
- this.delinquencyFeeBips = baseData.delinquencyFeeBips.toNumber();
462
- this.delinquencyGracePeriod = baseData.delinquencyGracePeriod.toNumber();
463
- this.withdrawalBatchDuration = baseData.withdrawalBatchDuration.toNumber();
464
- this.reserveRatioBips = baseData.reserveRatioBips.toNumber();
465
- this.annualInterestBips = baseData.annualInterestBips.toNumber();
472
+ this.protocolFeeBips = (0, utils_1.toNumber)(baseData.protocolFeeBips);
473
+ this.delinquencyFeeBips = (0, utils_1.toNumber)(baseData.delinquencyFeeBips);
474
+ this.delinquencyGracePeriod = (0, utils_1.toNumber)(baseData.delinquencyGracePeriod);
475
+ this.withdrawalBatchDuration = (0, utils_1.toNumber)(baseData.withdrawalBatchDuration);
476
+ this.reserveRatioBips = (0, utils_1.toNumber)(baseData.reserveRatioBips);
477
+ this.annualInterestBips = (0, utils_1.toNumber)(baseData.annualInterestBips);
466
478
  this.temporaryReserveRatio = baseData.temporaryReserveRatio;
467
- this.originalAnnualInterestBips = baseData.originalAnnualInterestBips.toNumber();
468
- this.originalReserveRatioBips = baseData.originalReserveRatioBips.toNumber();
469
- this.temporaryReserveRatioExpiry = baseData.temporaryReserveRatioExpiry.toNumber();
479
+ this.originalAnnualInterestBips = (0, utils_1.toNumber)(baseData.originalAnnualInterestBips);
480
+ this.originalReserveRatioBips = (0, utils_1.toNumber)(baseData.originalReserveRatioBips);
481
+ this.temporaryReserveRatioExpiry = (0, utils_1.toNumber)(baseData.temporaryReserveRatioExpiry);
470
482
  this.isClosed = baseData.isClosed;
471
- this.scaleFactor = baseData.scaleFactor;
483
+ this.scaleFactor = nextScaleFactor;
472
484
  this.totalSupply = this.marketToken.getAmount(baseData.totalSupply);
473
485
  this.maxTotalSupply = this.marketToken.getAmount(baseData.maxTotalSupply);
474
- this.scaledTotalSupply = baseData.scaledTotalSupply;
486
+ this.scaledTotalSupply = nextScaledTotalSupply;
475
487
  this.totalAssets = this.underlyingToken.getAmount(baseData.totalAssets);
476
488
  this.lastAccruedProtocolFees = this.underlyingToken.getAmount(baseData.lastAccruedProtocolFees);
477
489
  this.normalizedUnclaimedWithdrawals = this.underlyingToken.getAmount(baseData.normalizedUnclaimedWithdrawals);
478
- this.scaledPendingWithdrawals = baseData.scaledPendingWithdrawals;
479
- this.pendingWithdrawalExpiry = baseData.pendingWithdrawalExpiry.toNumber();
490
+ this.scaledPendingWithdrawals = nextScaledPendingWithdrawals;
491
+ this.pendingWithdrawalExpiry = (0, utils_1.toNumber)(baseData.pendingWithdrawalExpiry);
480
492
  this.isDelinquent = baseData.isDelinquent;
481
- this.timeDelinquent = baseData.timeDelinquent.toNumber();
482
- this.lastInterestAccruedTimestamp = baseData.lastInterestAccruedTimestamp.toNumber();
483
- this.unpaidWithdrawalBatchExpiries = baseData.unpaidWithdrawalBatchExpiries;
493
+ this.timeDelinquent = (0, utils_1.toNumber)(baseData.timeDelinquent);
494
+ this.lastInterestAccruedTimestamp = (0, utils_1.toNumber)(baseData.lastInterestAccruedTimestamp);
495
+ this.unpaidWithdrawalBatchExpiries = baseData.unpaidWithdrawalBatchExpiries.map(utils_1.toNumber);
484
496
  this.coverageLiquidity = this.underlyingToken.getAmount(baseData.coverageLiquidity);
485
497
  if ("hooksFactory" in baseData) {
486
498
  this.hooksFactory = baseData.hooksFactory;
487
499
  this.marketType = (0, constants_1.getMarketTypeForHooksFactory)(this.chainId, baseData.hooksFactory);
488
500
  }
489
501
  if ("hooksConfig" in baseData) {
490
- (0, utils_2.assert)(this.version === types_1.MarketVersion.V2, `Can not push V2 lens data to V1 market!`);
502
+ (0, utils_1.assert)(this.version === types_1.MarketVersion.V2, `Can not push V2 lens data to V1 market!`);
491
503
  const config = this.hooksConfig;
492
- (0, utils_2.assert)(config !== undefined, `V2 market has no hooksConfig!`);
504
+ (0, utils_1.assert)(config !== undefined, `V2 market has no hooksConfig!`);
493
505
  config.minimumDeposit = this.underlyingToken.getAmount(baseData.hooksConfig.minimumDeposit);
494
506
  if (config.kind === types_1.HooksKind.FixedTerm) {
495
- config.fixedTermEndTime = baseData.hooksConfig.fixedTermEndTime;
507
+ config.fixedTermEndTime = (0, utils_1.toNumber)(baseData.hooksConfig.fixedTermEndTime);
496
508
  }
497
509
  }
498
510
  else {
499
- (0, utils_2.assert)(this.version === types_1.MarketVersion.V1, `Can not push V1 lens data to V2 market!`);
511
+ (0, utils_1.assert)(this.version === types_1.MarketVersion.V1, `Can not push V1 lens data to V2 market!`);
500
512
  }
501
513
  if ("market" in data) {
502
514
  this.commitmentFeeBips = data.commitmentFeeBips.isPresent
503
- ? data.commitmentFeeBips.value.toNumber()
515
+ ? (0, utils_1.toNumber)(data.commitmentFeeBips.value)
504
516
  : undefined;
505
517
  this.drawnAmount = data.drawnAmount.isPresent
506
518
  ? this.underlyingToken.getAmount(data.drawnAmount.value)
@@ -517,17 +529,18 @@ class Market extends types_1.ContractWrapper {
517
529
  static fromSubgraphMarketData(chainId, provider, data, signerAddress) {
518
530
  const underlyingToken = token_1.Token.fromSubgraphToken(chainId, data._asset, provider);
519
531
  const marketToken = token_1.Token.fromSubgraphMarketData(chainId, data, provider);
520
- const scaledTotalSupply = ethers_1.BigNumber.from(data.scaledTotalSupply);
521
- const scaleFactor = ethers_1.BigNumber.from(data.scaleFactor);
522
- const scaledWithdrawals = ethers_1.BigNumber.from(data.scaledPendingWithdrawals);
523
- const scaledRequiredReserves = (0, utils_2.bipMul)(scaledTotalSupply.sub(scaledWithdrawals), ethers_1.BigNumber.from(data.reserveRatioBips)).add(scaledWithdrawals);
524
- const coverageLiquidity = (0, utils_2.rayMul)(scaledRequiredReserves, scaleFactor)
525
- .add(data.pendingProtocolFees)
526
- .add(data.normalizedUnclaimedWithdrawals);
532
+ const scaledTotalSupply = (0, token_1.toRawAmount)(data.scaledTotalSupply);
533
+ const scaleFactor = (0, token_1.toRawAmount)(data.scaleFactor);
534
+ const scaledWithdrawals = (0, token_1.toRawAmount)(data.scaledPendingWithdrawals);
535
+ const scaledRequiredReserves = (0, utils_1.bipMulBigint)(scaledTotalSupply - scaledWithdrawals, data.reserveRatioBips) +
536
+ scaledWithdrawals;
537
+ const coverageLiquidity = (0, utils_1.rayMulBigint)(scaledRequiredReserves, scaleFactor) +
538
+ (0, token_1.toRawAmount)(data.pendingProtocolFees) +
539
+ (0, token_1.toRawAmount)(data.normalizedUnclaimedWithdrawals);
527
540
  let hooksConfig;
528
541
  if (data.version === types_1.MarketVersion.V2) {
529
- (0, utils_2.assert)(!!data.hooks, `V2 markets require hooks`);
530
- (0, utils_2.assert)(!!data.hooksConfig, `V2 markets require hooksConfig`);
542
+ (0, utils_1.assert)(!!data.hooks, `V2 markets require hooks`);
543
+ (0, utils_1.assert)(!!data.hooksConfig, `V2 markets require hooksConfig`);
531
544
  const { minimumDeposit: _minimumDeposit, depositRequiresAccess, transferRequiresAccess, queueWithdrawalRequiresAccess, allowClosureBeforeTerm, allowForceBuyBacks, allowTermReduction, fixedTermEndTime, transfersDisabled } = data.hooksConfig;
532
545
  const flags = {
533
546
  useOnDeposit: data.hooksConfig.useOnDeposit,
@@ -599,14 +612,14 @@ class Market extends types_1.ContractWrapper {
599
612
  originalReserveRatioBips: data.originalReserveRatioBips,
600
613
  temporaryReserveRatioExpiry: data.temporaryReserveRatioExpiry,
601
614
  isClosed: data.isClosed,
602
- scaleFactor: ethers_1.BigNumber.from(data.scaleFactor),
603
- totalSupply: marketToken.getAmount((0, utils_2.rayMul)(scaledTotalSupply, scaleFactor)),
615
+ scaleFactor,
616
+ totalSupply: marketToken.getAmount((0, utils_1.rayMulBigint)(scaledTotalSupply, scaleFactor)),
604
617
  maxTotalSupply: marketToken.getAmount(data.maxTotalSupply),
605
618
  scaledTotalSupply: scaledTotalSupply,
606
619
  totalAssets: underlyingToken.getAmount(0),
607
620
  lastAccruedProtocolFees: underlyingToken.getAmount(data.pendingProtocolFees),
608
621
  normalizedUnclaimedWithdrawals: underlyingToken.getAmount(data.normalizedUnclaimedWithdrawals),
609
- scaledPendingWithdrawals: ethers_1.BigNumber.from(data.scaledPendingWithdrawals),
622
+ scaledPendingWithdrawals: scaledWithdrawals,
610
623
  pendingWithdrawalExpiry: +data.pendingWithdrawalExpiry,
611
624
  isDelinquent: data.isDelinquent,
612
625
  timeDelinquent: data.timeDelinquent,
@@ -643,30 +656,30 @@ class Market extends types_1.ContractWrapper {
643
656
  borrower: data.borrower,
644
657
  controller: data.controller,
645
658
  feeRecipient: data.feeRecipient,
646
- protocolFeeBips: data.protocolFeeBips.toNumber(),
647
- delinquencyFeeBips: data.delinquencyFeeBips.toNumber(),
648
- delinquencyGracePeriod: data.delinquencyGracePeriod.toNumber(),
649
- withdrawalBatchDuration: data.withdrawalBatchDuration.toNumber(),
650
- reserveRatioBips: data.reserveRatioBips.toNumber(),
651
- annualInterestBips: data.annualInterestBips.toNumber(),
659
+ protocolFeeBips: (0, utils_1.toNumber)(data.protocolFeeBips),
660
+ delinquencyFeeBips: (0, utils_1.toNumber)(data.delinquencyFeeBips),
661
+ delinquencyGracePeriod: (0, utils_1.toNumber)(data.delinquencyGracePeriod),
662
+ withdrawalBatchDuration: (0, utils_1.toNumber)(data.withdrawalBatchDuration),
663
+ reserveRatioBips: (0, utils_1.toNumber)(data.reserveRatioBips),
664
+ annualInterestBips: (0, utils_1.toNumber)(data.annualInterestBips),
652
665
  temporaryReserveRatio: data.temporaryReserveRatio,
653
- originalAnnualInterestBips: data.originalAnnualInterestBips.toNumber(),
654
- originalReserveRatioBips: data.originalReserveRatioBips.toNumber(),
655
- temporaryReserveRatioExpiry: data.temporaryReserveRatioExpiry.toNumber(),
666
+ originalAnnualInterestBips: (0, utils_1.toNumber)(data.originalAnnualInterestBips),
667
+ originalReserveRatioBips: (0, utils_1.toNumber)(data.originalReserveRatioBips),
668
+ temporaryReserveRatioExpiry: (0, utils_1.toNumber)(data.temporaryReserveRatioExpiry),
656
669
  isClosed: data.isClosed,
657
- scaleFactor: data.scaleFactor,
670
+ scaleFactor: (0, token_1.toRawAmount)(data.scaleFactor),
658
671
  totalSupply: marketToken.getAmount(data.totalSupply),
659
672
  maxTotalSupply: marketToken.getAmount(data.maxTotalSupply),
660
- scaledTotalSupply: data.scaledTotalSupply,
673
+ scaledTotalSupply: (0, token_1.toRawAmount)(data.scaledTotalSupply),
661
674
  totalAssets: underlyingToken.getAmount(data.totalAssets),
662
675
  lastAccruedProtocolFees: underlyingToken.getAmount(data.lastAccruedProtocolFees),
663
676
  normalizedUnclaimedWithdrawals: underlyingToken.getAmount(data.normalizedUnclaimedWithdrawals),
664
- scaledPendingWithdrawals: data.scaledPendingWithdrawals,
665
- pendingWithdrawalExpiry: data.pendingWithdrawalExpiry.toNumber(),
677
+ scaledPendingWithdrawals: (0, token_1.toRawAmount)(data.scaledPendingWithdrawals),
678
+ pendingWithdrawalExpiry: (0, utils_1.toNumber)(data.pendingWithdrawalExpiry),
666
679
  isDelinquent: data.isDelinquent,
667
- timeDelinquent: data.timeDelinquent.toNumber(),
668
- lastInterestAccruedTimestamp: data.lastInterestAccruedTimestamp.toNumber(),
669
- unpaidWithdrawalBatchExpiries: data.unpaidWithdrawalBatchExpiries,
680
+ timeDelinquent: (0, utils_1.toNumber)(data.timeDelinquent),
681
+ lastInterestAccruedTimestamp: (0, utils_1.toNumber)(data.lastInterestAccruedTimestamp),
682
+ unpaidWithdrawalBatchExpiries: data.unpaidWithdrawalBatchExpiries.map(utils_1.toNumber),
670
683
  coverageLiquidity: underlyingToken.getAmount(data.coverageLiquidity),
671
684
  totalBorrowed: undefined,
672
685
  totalRepaid: undefined,
@@ -688,7 +701,8 @@ class Market extends types_1.ContractWrapper {
688
701
  const underlyingToken = token_1.Token.fromTokenMetadata(chainId, data.underlyingToken, provider);
689
702
  const { hooksAddress } = hooks;
690
703
  let hooksConfig;
691
- if (hooksConfigData.kind === 1) {
704
+ const hooksKind = (0, utils_1.toNumber)(hooksConfigData.kind);
705
+ if (hooksKind === 1) {
692
706
  hooksConfig = {
693
707
  kind: types_1.HooksKind.OpenTerm,
694
708
  hooksAddress: hooksAddress,
@@ -700,7 +714,7 @@ class Market extends types_1.ContractWrapper {
700
714
  allowForceBuyBacks: hooksConfigData.allowForceBuyBacks
701
715
  };
702
716
  }
703
- else if (hooksConfigData.kind === 2) {
717
+ else if (hooksKind === 2) {
704
718
  hooksConfig = {
705
719
  kind: types_1.HooksKind.FixedTerm,
706
720
  hooksAddress: hooksAddress,
@@ -709,7 +723,7 @@ class Market extends types_1.ContractWrapper {
709
723
  transferRequiresAccess: hooksConfigData.transferRequiresAccess,
710
724
  transfersDisabled: hooksConfigData.transfersDisabled,
711
725
  minimumDeposit: underlyingToken.getAmount(hooksConfigData.minimumDeposit),
712
- fixedTermEndTime: hooksConfigData.fixedTermEndTime,
726
+ fixedTermEndTime: (0, utils_1.toNumber)(hooksConfigData.fixedTermEndTime),
713
727
  queueWithdrawalRequiresAccess: hooksConfigData.withdrawalRequiresAccess,
714
728
  allowTermReduction: hooksConfigData.allowTermReduction,
715
729
  allowClosureBeforeTerm: hooksConfigData.allowClosureBeforeTerm,
@@ -717,7 +731,7 @@ class Market extends types_1.ContractWrapper {
717
731
  };
718
732
  }
719
733
  else {
720
- throw Error(`Unknown hooks kind: ${hooks.hooksTemplate.name}, version #${hooksConfigData.kind}`);
734
+ throw Error(`Unknown hooks kind: ${hooks.hooksTemplate.name}, version #${hooksKind}`);
721
735
  }
722
736
  return new Market({
723
737
  provider,
@@ -730,30 +744,30 @@ class Market extends types_1.ContractWrapper {
730
744
  underlyingToken: underlyingToken,
731
745
  borrower: data.borrower,
732
746
  feeRecipient: data.feeRecipient,
733
- protocolFeeBips: data.protocolFeeBips.toNumber(),
734
- delinquencyFeeBips: data.delinquencyFeeBips.toNumber(),
735
- delinquencyGracePeriod: data.delinquencyGracePeriod.toNumber(),
736
- withdrawalBatchDuration: data.withdrawalBatchDuration.toNumber(),
737
- reserveRatioBips: data.reserveRatioBips.toNumber(),
738
- annualInterestBips: data.annualInterestBips.toNumber(),
747
+ protocolFeeBips: (0, utils_1.toNumber)(data.protocolFeeBips),
748
+ delinquencyFeeBips: (0, utils_1.toNumber)(data.delinquencyFeeBips),
749
+ delinquencyGracePeriod: (0, utils_1.toNumber)(data.delinquencyGracePeriod),
750
+ withdrawalBatchDuration: (0, utils_1.toNumber)(data.withdrawalBatchDuration),
751
+ reserveRatioBips: (0, utils_1.toNumber)(data.reserveRatioBips),
752
+ annualInterestBips: (0, utils_1.toNumber)(data.annualInterestBips),
739
753
  temporaryReserveRatio: data.temporaryReserveRatio,
740
- originalAnnualInterestBips: data.originalAnnualInterestBips.toNumber(),
741
- originalReserveRatioBips: data.originalReserveRatioBips.toNumber(),
742
- temporaryReserveRatioExpiry: data.temporaryReserveRatioExpiry.toNumber(),
754
+ originalAnnualInterestBips: (0, utils_1.toNumber)(data.originalAnnualInterestBips),
755
+ originalReserveRatioBips: (0, utils_1.toNumber)(data.originalReserveRatioBips),
756
+ temporaryReserveRatioExpiry: (0, utils_1.toNumber)(data.temporaryReserveRatioExpiry),
743
757
  isClosed: data.isClosed,
744
- scaleFactor: data.scaleFactor,
758
+ scaleFactor: (0, token_1.toRawAmount)(data.scaleFactor),
745
759
  totalSupply: marketToken.getAmount(data.totalSupply),
746
760
  maxTotalSupply: marketToken.getAmount(data.maxTotalSupply),
747
- scaledTotalSupply: data.scaledTotalSupply,
761
+ scaledTotalSupply: (0, token_1.toRawAmount)(data.scaledTotalSupply),
748
762
  totalAssets: underlyingToken.getAmount(data.totalAssets),
749
763
  lastAccruedProtocolFees: underlyingToken.getAmount(data.lastAccruedProtocolFees),
750
764
  normalizedUnclaimedWithdrawals: underlyingToken.getAmount(data.normalizedUnclaimedWithdrawals),
751
- scaledPendingWithdrawals: data.scaledPendingWithdrawals,
752
- pendingWithdrawalExpiry: data.pendingWithdrawalExpiry.toNumber(),
765
+ scaledPendingWithdrawals: (0, token_1.toRawAmount)(data.scaledPendingWithdrawals),
766
+ pendingWithdrawalExpiry: (0, utils_1.toNumber)(data.pendingWithdrawalExpiry),
753
767
  isDelinquent: data.isDelinquent,
754
- timeDelinquent: data.timeDelinquent.toNumber(),
755
- lastInterestAccruedTimestamp: data.lastInterestAccruedTimestamp.toNumber(),
756
- unpaidWithdrawalBatchExpiries: data.unpaidWithdrawalBatchExpiries,
768
+ timeDelinquent: (0, utils_1.toNumber)(data.timeDelinquent),
769
+ lastInterestAccruedTimestamp: (0, utils_1.toNumber)(data.lastInterestAccruedTimestamp),
770
+ unpaidWithdrawalBatchExpiries: data.unpaidWithdrawalBatchExpiries.map(utils_1.toNumber),
757
771
  coverageLiquidity: underlyingToken.getAmount(data.coverageLiquidity),
758
772
  signerAddress
759
773
  // borrowableAssets: underlyingToken.getAmount(data.borrowableAssets)
@@ -765,7 +779,8 @@ class Market extends types_1.ContractWrapper {
765
779
  const underlyingToken = token_1.Token.fromTokenMetadata(chainId, data.underlyingToken, provider);
766
780
  const { hooksAddress } = hooks;
767
781
  let hooksConfig;
768
- if (hooksConfigData.kind === 1) {
782
+ const hooksKind = (0, utils_1.toNumber)(hooksConfigData.kind);
783
+ if (hooksKind === 1) {
769
784
  hooksConfig = {
770
785
  kind: types_1.HooksKind.OpenTerm,
771
786
  hooksAddress,
@@ -777,7 +792,7 @@ class Market extends types_1.ContractWrapper {
777
792
  allowForceBuyBacks
778
793
  };
779
794
  }
780
- else if (hooksConfigData.kind === 2) {
795
+ else if (hooksKind === 2) {
781
796
  hooksConfig = {
782
797
  kind: types_1.HooksKind.FixedTerm,
783
798
  hooksAddress,
@@ -786,7 +801,7 @@ class Market extends types_1.ContractWrapper {
786
801
  transferRequiresAccess: hooksConfigData.transferRequiresAccess,
787
802
  transfersDisabled: hooksConfigData.transfersDisabled,
788
803
  minimumDeposit: underlyingToken.getAmount(hooksConfigData.minimumDeposit),
789
- fixedTermEndTime: hooksConfigData.fixedTermEndTime,
804
+ fixedTermEndTime: (0, utils_1.toNumber)(hooksConfigData.fixedTermEndTime),
790
805
  queueWithdrawalRequiresAccess: hooksConfigData.withdrawalRequiresAccess,
791
806
  allowTermReduction: hooksConfigData.allowTermReduction,
792
807
  allowClosureBeforeTerm: hooksConfigData.allowClosureBeforeTerm,
@@ -794,7 +809,7 @@ class Market extends types_1.ContractWrapper {
794
809
  };
795
810
  }
796
811
  else {
797
- throw Error(`Unknown hooks kind: ${hooks.hooksTemplate.name}, version #${hooksConfigData.kind}`);
812
+ throw Error(`Unknown hooks kind: ${hooks.hooksTemplate.name}, version #${hooksKind}`);
798
813
  }
799
814
  return new Market({
800
815
  provider,
@@ -807,47 +822,47 @@ class Market extends types_1.ContractWrapper {
807
822
  underlyingToken,
808
823
  borrower: data.borrower,
809
824
  feeRecipient: data.feeRecipient,
810
- protocolFeeBips: data.protocolFeeBips.toNumber(),
811
- delinquencyFeeBips: data.delinquencyFeeBips.toNumber(),
812
- delinquencyGracePeriod: data.delinquencyGracePeriod.toNumber(),
813
- withdrawalBatchDuration: data.withdrawalBatchDuration.toNumber(),
814
- reserveRatioBips: data.reserveRatioBips.toNumber(),
815
- annualInterestBips: data.annualInterestBips.toNumber(),
825
+ protocolFeeBips: (0, utils_1.toNumber)(data.protocolFeeBips),
826
+ delinquencyFeeBips: (0, utils_1.toNumber)(data.delinquencyFeeBips),
827
+ delinquencyGracePeriod: (0, utils_1.toNumber)(data.delinquencyGracePeriod),
828
+ withdrawalBatchDuration: (0, utils_1.toNumber)(data.withdrawalBatchDuration),
829
+ reserveRatioBips: (0, utils_1.toNumber)(data.reserveRatioBips),
830
+ annualInterestBips: (0, utils_1.toNumber)(data.annualInterestBips),
816
831
  temporaryReserveRatio: data.temporaryReserveRatio,
817
- originalAnnualInterestBips: data.originalAnnualInterestBips.toNumber(),
818
- originalReserveRatioBips: data.originalReserveRatioBips.toNumber(),
819
- temporaryReserveRatioExpiry: data.temporaryReserveRatioExpiry.toNumber(),
832
+ originalAnnualInterestBips: (0, utils_1.toNumber)(data.originalAnnualInterestBips),
833
+ originalReserveRatioBips: (0, utils_1.toNumber)(data.originalReserveRatioBips),
834
+ temporaryReserveRatioExpiry: (0, utils_1.toNumber)(data.temporaryReserveRatioExpiry),
820
835
  isClosed: data.isClosed,
821
- scaleFactor: data.scaleFactor,
836
+ scaleFactor: (0, token_1.toRawAmount)(data.scaleFactor),
822
837
  totalSupply: marketToken.getAmount(data.totalSupply),
823
838
  maxTotalSupply: marketToken.getAmount(data.maxTotalSupply),
824
- scaledTotalSupply: data.scaledTotalSupply,
839
+ scaledTotalSupply: (0, token_1.toRawAmount)(data.scaledTotalSupply),
825
840
  totalAssets: underlyingToken.getAmount(data.totalAssets),
826
841
  lastAccruedProtocolFees: underlyingToken.getAmount(data.lastAccruedProtocolFees),
827
842
  normalizedUnclaimedWithdrawals: underlyingToken.getAmount(data.normalizedUnclaimedWithdrawals),
828
- scaledPendingWithdrawals: data.scaledPendingWithdrawals,
829
- pendingWithdrawalExpiry: data.pendingWithdrawalExpiry.toNumber(),
843
+ scaledPendingWithdrawals: (0, token_1.toRawAmount)(data.scaledPendingWithdrawals),
844
+ pendingWithdrawalExpiry: (0, utils_1.toNumber)(data.pendingWithdrawalExpiry),
830
845
  isDelinquent: data.isDelinquent,
831
- timeDelinquent: data.timeDelinquent.toNumber(),
832
- lastInterestAccruedTimestamp: data.lastInterestAccruedTimestamp.toNumber(),
833
- unpaidWithdrawalBatchExpiries: data.unpaidWithdrawalBatchExpiries,
846
+ timeDelinquent: (0, utils_1.toNumber)(data.timeDelinquent),
847
+ lastInterestAccruedTimestamp: (0, utils_1.toNumber)(data.lastInterestAccruedTimestamp),
848
+ unpaidWithdrawalBatchExpiries: data.unpaidWithdrawalBatchExpiries.map(utils_1.toNumber),
834
849
  coverageLiquidity: underlyingToken.getAmount(data.coverageLiquidity),
835
- commitmentFeeBips: commitmentFeeBips.isPresent ? commitmentFeeBips.value.toNumber() : undefined,
836
- drawnAmount: drawnAmount.isPresent
837
- ? underlyingToken.getAmount(drawnAmount.value)
850
+ commitmentFeeBips: commitmentFeeBips.isPresent
851
+ ? (0, utils_1.toNumber)(commitmentFeeBips.value)
838
852
  : undefined,
853
+ drawnAmount: drawnAmount.isPresent ? underlyingToken.getAmount(drawnAmount.value) : undefined,
839
854
  signerAddress
840
855
  });
841
856
  }
842
857
  static async resolveAllowForceBuyBacks(provider, marketAddress, data) {
843
858
  const marketData = "market" in data ? data.market : data;
844
859
  if (marketData.hooksConfig.kind === 1) {
845
- const hookedMarket = await typechain_1.IOpenTermHooks__factory.connect(marketData.hooksConfig.hooksAddress, provider).getHookedMarket(marketAddress);
846
- return hookedMarket.allowForceBuyBacks;
860
+ const hookedMarket = await (0, viem_read_1.readViemContract)((0, ethers_viem_1.getViemPublicClientFromEthers)(provider), marketData.hooksConfig.hooksAddress, abi_1.iOpenTermHooksAbi, "getHookedMarket", [marketAddress]);
861
+ return getAllowForceBuyBacksFromHookedMarket(hookedMarket, 5);
847
862
  }
848
863
  if (marketData.hooksConfig.kind === 2) {
849
- const hookedMarket = await typechain_1.IFixedTermHooks__factory.connect(marketData.hooksConfig.hooksAddress, provider).getHookedMarket(marketAddress);
850
- return hookedMarket.allowForceBuyBacks;
864
+ const hookedMarket = await (0, viem_read_1.readViemContract)((0, ethers_viem_1.getViemPublicClientFromEthers)(provider), marketData.hooksConfig.hooksAddress, abi_1.iFixedTermHooksAbi, "getHookedMarket", [marketAddress]);
865
+ return getAllowForceBuyBacksFromHookedMarket(hookedMarket, 9);
851
866
  }
852
867
  return false;
853
868
  }
@@ -863,62 +878,58 @@ class Market extends types_1.ContractWrapper {
863
878
  * @returns `Market` instance for `market`
864
879
  */
865
880
  static async getMarket(chainId, market, provider) {
866
- const signerAddress = abstract_signer_1.Signer.isSigner(provider) ? await provider.getAddress() : undefined;
881
+ const signerAddress = await (0, ethers_signer_1.getEthersSignerAddress)(provider);
867
882
  if (hasUnifiedLatestLensForDirectReads(chainId)) {
868
883
  try {
869
- const data = await (0, constants_1.getLensV2_5Contract)(chainId, provider).getMarketDataV2(market);
884
+ const data = await (0, market_lens_1.getUnifiedMarketDataV2)(chainId, provider, market);
870
885
  return Market.fromUnifiedMarketData(chainId, provider, data, signerAddress);
871
886
  }
872
887
  catch (_) {
873
888
  // Fall back to the legacy lens for V1 markets and pre-unified deployments.
874
889
  }
875
890
  }
876
- const lens = (0, constants_1.getLensContract)(chainId, provider);
877
- const data = await lens.getMarketData(market);
891
+ const data = await (0, market_lens_1.getLegacyMarketData)(chainId, provider, market);
878
892
  return Market.fromMarketData(chainId, data, provider, signerAddress);
879
893
  }
880
894
  /**
881
895
  * @returns `Market` instance for `market`
882
896
  */
883
897
  static async getMarketV2(chainId, market, provider) {
884
- const signerAddress = abstract_signer_1.Signer.isSigner(provider) ? await provider.getAddress() : undefined;
898
+ const signerAddress = await (0, ethers_signer_1.getEthersSignerAddress)(provider);
885
899
  if (hasUnifiedLatestLensForDirectReads(chainId)) {
886
900
  try {
887
- const data = await (0, constants_1.getLensV2_5Contract)(chainId, provider).getMarketDataV2(market);
901
+ const data = await (0, market_lens_1.getUnifiedMarketDataV2)(chainId, provider, market);
888
902
  return Market.fromUnifiedMarketData(chainId, provider, data, signerAddress);
889
903
  }
890
904
  catch (_) {
891
905
  // Fall back to the pre-2.5 V2 lens for chains that have not fully migrated.
892
906
  }
893
907
  }
894
- const lens = (0, constants_1.getLensV2Contract)(chainId, provider);
895
- const data = await lens.getMarketData(market);
908
+ const data = await (0, market_lens_1.getV2MarketData)(chainId, provider, market);
896
909
  return Market.fromMarketDataV2(chainId, provider, data, signerAddress);
897
910
  }
898
911
  /**
899
912
  * @returns `Market` instances for `markets`
900
913
  */
901
914
  static async getMarkets(chainId, markets, provider) {
902
- const signerAddress = abstract_signer_1.Signer.isSigner(provider) ? await provider.getAddress() : undefined;
915
+ const signerAddress = await (0, ethers_signer_1.getEthersSignerAddress)(provider);
903
916
  if (hasUnifiedLatestLensForDirectReads(chainId)) {
904
917
  try {
905
- const data = await (0, constants_1.getLensV2_5Contract)(chainId, provider).getMarketsDataV2(markets);
918
+ const data = await (0, market_lens_1.getUnifiedMarketsDataV2)(chainId, provider, markets);
906
919
  return Promise.all(data.map((market) => Market.fromUnifiedMarketData(chainId, provider, market, signerAddress)));
907
920
  }
908
921
  catch (_) {
909
922
  return Promise.all(markets.map((market) => Market.getMarket(chainId, market, provider)));
910
923
  }
911
924
  }
912
- const lens = (0, constants_1.getLensContract)(chainId, provider);
913
- const data = await lens.getMarketsData(markets);
925
+ const data = await (0, market_lens_1.getLegacyMarketsData)(chainId, provider, markets);
914
926
  return data.map((market) => Market.fromMarketData(chainId, market, provider, signerAddress));
915
927
  }
916
928
  /**
917
929
  * @return All deployed markets
918
930
  */
919
931
  static async getAllMarkets(chainId, provider) {
920
- const archController = (0, constants_1.getArchControllerContract)(chainId, provider);
921
- const markets = await archController["getRegisteredMarkets()"]();
932
+ const markets = await (0, arch_controller_1.getRegisteredMarkets)(chainId, provider);
922
933
  if (!markets.length) {
923
934
  return [];
924
935
  }
@@ -931,13 +942,12 @@ class Market extends types_1.ContractWrapper {
931
942
  if (count <= 0) {
932
943
  return [];
933
944
  }
934
- const archController = (0, constants_1.getArchControllerContract)(chainId, provider);
935
- const totalMarkets = (await archController.getRegisteredMarketsCount()).toNumber();
945
+ const totalMarkets = await (0, arch_controller_1.getRegisteredMarketsCount)(chainId, provider);
936
946
  if (start >= totalMarkets) {
937
947
  return [];
938
948
  }
939
949
  const end = Math.min(start + count, totalMarkets);
940
- const markets = await archController["getRegisteredMarkets(uint256,uint256)"](start, end);
950
+ const markets = await (0, arch_controller_1.getRegisteredMarketsPage)(chainId, provider, start, end);
941
951
  if (!markets.length) {
942
952
  return [];
943
953
  }
@@ -947,8 +957,7 @@ class Market extends types_1.ContractWrapper {
947
957
  * @return Total number of deployed markets.
948
958
  */
949
959
  static async getMarketsCount(chainId, provider) {
950
- const archController = (0, constants_1.getArchControllerContract)(chainId, provider);
951
- return archController.getRegisteredMarketsCount().then((count) => count.toNumber());
960
+ return (0, arch_controller_1.getRegisteredMarketsCount)(chainId, provider);
952
961
  }
953
962
  }
954
963
  exports.Market = Market;