@wildcatfi/wildcat-sdk 3.0.67-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 +532 -10
  73. package/dist/gql/graphql.d.ts.map +1 -1
  74. package/dist/gql/graphql.js +182 -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 +34 -20
  109. package/dist/market.d.ts.map +1 -1
  110. package/dist/market.js +300 -223
  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,26 +1,45 @@
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
  };
24
+ const toUnifiedMarketDataV2 = (data) => {
25
+ if ("market" in data) {
26
+ return data;
27
+ }
28
+ return {
29
+ market: data,
30
+ commitmentFeeBips: {
31
+ isPresent: false,
32
+ value: 0n
33
+ },
34
+ drawnAmount: {
35
+ isPresent: false,
36
+ value: 0n
37
+ }
38
+ };
39
+ };
17
40
  class Market extends types_1.ContractWrapper {
18
- get _contractAddress() {
19
- return this.address;
20
- }
21
41
  constructor({ provider, ...args }) {
22
42
  super(provider);
23
- this.contractFactory = typechain_1.WildcatMarket__factory;
24
43
  const { address, name, symbol, decimals } = args.marketToken;
25
44
  Object.assign(this, {
26
45
  address,
@@ -29,9 +48,9 @@ class Market extends types_1.ContractWrapper {
29
48
  decimals
30
49
  });
31
50
  Object.assign(this, args);
32
- this.depositRecords = (args.depositRecords ?? []).map((log) => (0, utils_2.parseMarketRecord)(this.underlyingToken, log));
33
- this.repaymentRecords = (args.repaymentRecords ?? []).map((log) => (0, utils_2.parseMarketRecord)(this.underlyingToken, log));
34
- 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));
35
54
  this.feeCollectionRecords = (args.feeCollectionRecords ?? []).map(({ feesCollected, __typename, ...rest }) => ({
36
55
  ...rest,
37
56
  __typename: "FeesCollected",
@@ -56,12 +75,50 @@ class Market extends types_1.ContractWrapper {
56
75
  /** @returns Percentage growth of the market since it was created */
57
76
  get allTimeGrowth() {
58
77
  // 27 - 2 to convert to percentage
59
- return +(0, utils_1.formatUnits)(this.scaleFactor, 25);
78
+ return +(0, utils_1.formatFixedBigint)(this.scaleFactor, 25, 25);
60
79
  }
61
80
  /** @returns Maximum amount of underlying token that can be deposited */
62
81
  get maximumDeposit() {
63
82
  return this.underlyingToken.getAmount(this.maxTotalSupply.satsub(this.totalSupply.raw));
64
83
  }
84
+ get currentRevolvingAprMetrics() {
85
+ const commitmentFeeBips = this.commitmentFeeBips;
86
+ const drawnAmount = this.drawnAmount;
87
+ if (commitmentFeeBips == null || drawnAmount == null) {
88
+ return undefined;
89
+ }
90
+ const totalSupply = this.totalSupply.raw;
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)
95
+ : 0;
96
+ const blendedBaseAprBips = commitmentFeeBips + utilizationAprBips;
97
+ const protocolAprBips = Number((BigInt(blendedBaseAprBips) * BigInt(this.protocolFeeBips)) / utils_1.BIP_BIGINT);
98
+ const penaltyAprBips = this.isIncurringPenalties ? this.delinquencyFeeBips : 0;
99
+ return {
100
+ commitmentFeeBips,
101
+ drawnAmount,
102
+ utilizationBips,
103
+ utilizationAprBips,
104
+ blendedBaseAprBips,
105
+ protocolAprBips,
106
+ penaltyAprBips,
107
+ effectiveLenderAprBips: blendedBaseAprBips + penaltyAprBips
108
+ };
109
+ }
110
+ get currentBaseLenderAprBips() {
111
+ return this.currentRevolvingAprMetrics?.blendedBaseAprBips ?? this.annualInterestBips;
112
+ }
113
+ get currentBaseLenderAPR() {
114
+ return (0, utils_1.bipToRayBigint)(this.currentBaseLenderAprBips);
115
+ }
116
+ get currentPenaltyAPR() {
117
+ return this.isIncurringPenalties ? (0, utils_1.bipToRayBigint)(this.delinquencyFeeBips) : 0n;
118
+ }
119
+ get currentProtocolAPR() {
120
+ return (0, utils_1.bipMulBigint)(this.currentBaseLenderAPR, this.protocolFeeBips);
121
+ }
65
122
  /** @returns Whether the borrower is in penalized delinquency */
66
123
  get isIncurringPenalties() {
67
124
  return this.timeDelinquent > this.delinquencyGracePeriod;
@@ -107,7 +164,7 @@ class Market extends types_1.ContractWrapper {
107
164
  const targetRatio = this.reserveRatioBips / 100;
108
165
  const actualRatio = this.totalSupply.eq(0)
109
166
  ? 100
110
- : +(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);
111
168
  if (this.temporaryReserveRatio) {
112
169
  return {
113
170
  targetRatio,
@@ -120,7 +177,7 @@ class Market extends types_1.ContractWrapper {
120
177
  return { targetRatio, actualRatio };
121
178
  }
122
179
  get normalizedPendingWithdrawals() {
123
- 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));
124
181
  }
125
182
  /** @returns Whether the borrower can change the APR */
126
183
  get canReduceAPR() {
@@ -136,7 +193,7 @@ class Market extends types_1.ContractWrapper {
136
193
  return this.totalAssets.satsub(unavailableAssets);
137
194
  }
138
195
  get minimumReserves() {
139
- return this.underlyingToken.getAmount((0, utils_2.bipMul)(this.outstandingTotalSupply.raw, ethers_1.BigNumber.from(this.reserveRatioBips)));
196
+ return this.outstandingTotalSupply.bipMul(this.reserveRatioBips);
140
197
  }
141
198
  get borrowableAssets() {
142
199
  return this.totalAssets.satsub(this.coverageLiquidity);
@@ -174,63 +231,59 @@ class Market extends types_1.ContractWrapper {
174
231
  };
175
232
  }
176
233
  normalizeAmount(amount) {
177
- return (0, utils_2.rayMul)(amount, this.scaleFactor);
234
+ return (0, utils_1.rayMulBigint)(amount, this.scaleFactor);
178
235
  }
179
236
  scaleAmount(amount) {
180
- return (0, utils_2.rayDiv)(amount, this.scaleFactor);
237
+ return (0, utils_1.rayDivBigint)(amount, this.scaleFactor);
181
238
  }
182
239
  get secondsBeforeDelinquency() {
183
240
  if (this.willBeDelinquent || this.totalDebts.eq(0))
184
241
  return 0;
185
242
  const scaledBase = this.scaledTotalSupply;
186
- const basePrincipal = this.underlyingToken.getAmount((0, utils_2.rayMul)(scaledBase, this.scaleFactor));
187
- const baseAPRRay = (0, utils_2.bipToRay)(this.annualInterestBips);
188
- const protocolFeeAPRRay = (0, utils_2.bipMul)(baseAPRRay, ethers_1.BigNumber.from(this.protocolFeeBips));
189
- const delinquencyFeeAPRRay = this.timeDelinquent > this.delinquencyGracePeriod
190
- ? (0, utils_2.bipToRay)(this.delinquencyFeeBips)
191
- : ethers_1.BigNumber.from(0);
243
+ const basePrincipal = this.underlyingToken.getAmount((0, utils_1.rayMulBigint)(scaledBase, this.scaleFactor));
244
+ const baseAPRRay = this.currentBaseLenderAPR;
245
+ const protocolFeeAPRRay = this.currentProtocolAPR;
246
+ const delinquencyFeeAPRRay = this.currentPenaltyAPR;
192
247
  // lender APR portion
193
248
  const lenderRequirementGrowthPerSecond = basePrincipal
194
- .rayMul(baseAPRRay.add(delinquencyFeeAPRRay))
195
- .div(utils_2.SECONDS_IN_365_DAYS)
249
+ .rayMul(baseAPRRay + delinquencyFeeAPRRay)
250
+ .div(utils_1.SECONDS_IN_365_DAYS)
196
251
  .bipMul(this.reserveRatioBips);
197
252
  // protocol fee portion
198
253
  const protocolRequirementGrowthPerSecond = basePrincipal
199
254
  .rayMul(protocolFeeAPRRay)
200
- .div(utils_2.SECONDS_IN_365_DAYS);
255
+ .div(utils_1.SECONDS_IN_365_DAYS);
201
256
  const totalRequirementGrowthPerSecond = lenderRequirementGrowthPerSecond.add(protocolRequirementGrowthPerSecond.raw);
202
257
  // essentially if apr=0 and rr=0 then bips alone wont move us to delinquency
203
- if (totalRequirementGrowthPerSecond.raw.isZero())
258
+ if (totalRequirementGrowthPerSecond.raw === 0n)
204
259
  return Number.MAX_SAFE_INTEGER;
205
260
  const buffer = this.liquidReserves.sub(this.minimumReserves);
206
- if (buffer.raw.lte(0))
261
+ if (buffer.raw <= 0n)
207
262
  return 0; // we are delinquent
208
- return buffer.div(totalRequirementGrowthPerSecond, true).raw.toNumber(); // seconds until the party
263
+ return Number(buffer.div(totalRequirementGrowthPerSecond, true).raw); // seconds until the party
209
264
  }
210
265
  getSecondsBeforeDelinquencyForBorrowedAmount(borrowAmount) {
211
266
  if (this.isDelinquent || this.totalDebts.eq(0))
212
267
  return 0;
213
268
  const scaledBase = this.scaledTotalSupply;
214
- const basePrincipal = this.underlyingToken.getAmount((0, utils_2.rayMul)(scaledBase, this.scaleFactor));
215
- const baseAPRRay = (0, utils_2.bipToRay)(this.annualInterestBips);
216
- const protocolFeeAPRRay = (0, utils_2.bipMul)(baseAPRRay, ethers_1.BigNumber.from(this.protocolFeeBips));
217
- const delinquencyFeeAPRRay = this.timeDelinquent > this.delinquencyGracePeriod
218
- ? (0, utils_2.bipToRay)(this.delinquencyFeeBips)
219
- : ethers_1.BigNumber.from(0);
269
+ const basePrincipal = this.underlyingToken.getAmount((0, utils_1.rayMulBigint)(scaledBase, this.scaleFactor));
270
+ const baseAPRRay = this.currentBaseLenderAPR;
271
+ const protocolFeeAPRRay = this.currentProtocolAPR;
272
+ const delinquencyFeeAPRRay = this.currentPenaltyAPR;
220
273
  const lenderRequirementGrowthPerSecond = basePrincipal
221
- .rayMul(baseAPRRay.add(delinquencyFeeAPRRay))
222
- .div(utils_2.SECONDS_IN_365_DAYS)
274
+ .rayMul(baseAPRRay + delinquencyFeeAPRRay)
275
+ .div(utils_1.SECONDS_IN_365_DAYS)
223
276
  .bipMul(this.reserveRatioBips);
224
277
  const protocolRequirementGrowthPerSecond = basePrincipal
225
278
  .rayMul(protocolFeeAPRRay)
226
- .div(utils_2.SECONDS_IN_365_DAYS);
279
+ .div(utils_1.SECONDS_IN_365_DAYS);
227
280
  const totalRequirementGrowthPerSecond = lenderRequirementGrowthPerSecond.add(protocolRequirementGrowthPerSecond.raw);
228
- if (totalRequirementGrowthPerSecond.raw.isZero())
281
+ if (totalRequirementGrowthPerSecond.raw === 0n)
229
282
  return Number.MAX_SAFE_INTEGER;
230
283
  const postBorrowBuffer = this.liquidReserves.sub(this.minimumReserves).sub(borrowAmount);
231
- if (postBorrowBuffer.raw.lte(0))
284
+ if (postBorrowBuffer.raw <= 0n)
232
285
  return 0;
233
- return postBorrowBuffer.div(totalRequirementGrowthPerSecond, true).raw.toNumber();
286
+ return Number(postBorrowBuffer.div(totalRequirementGrowthPerSecond, true).raw);
234
287
  }
235
288
  /**
236
289
  * @dev Calculate token amount to be repayed by borrower for a given duration
@@ -238,22 +291,20 @@ class Market extends types_1.ContractWrapper {
238
291
  * @return token amount to be repayed
239
292
  **/
240
293
  repayRequiredForDuration(timeToPayInSeconds) {
241
- const scaledBase = this.scaledTotalSupply.sub(this.scaledPendingWithdrawals);
242
- if (scaledBase.lte(0))
294
+ const scaledBase = this.scaledTotalSupply - this.scaledPendingWithdrawals;
295
+ if (scaledBase <= 0n)
243
296
  return this.underlyingToken.getAmount(0);
244
- const basePrincipal = this.underlyingToken.getAmount((0, utils_2.rayMul)(scaledBase, this.scaleFactor));
245
- const baseAPRRay = (0, utils_2.bipToRay)(this.annualInterestBips);
246
- const protocolFeeAPRRay = (0, utils_2.bipMul)(baseAPRRay, ethers_1.BigNumber.from(this.protocolFeeBips));
247
- const delinquencyFeeAPRRay = this.timeDelinquent > this.delinquencyGracePeriod
248
- ? (0, utils_2.bipToRay)(this.delinquencyFeeBips)
249
- : ethers_1.BigNumber.from(0);
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;
250
301
  const lenderRequirementGrowthPerSecond = basePrincipal
251
- .rayMul(baseAPRRay.add(delinquencyFeeAPRRay))
252
- .div(utils_2.SECONDS_IN_365_DAYS)
302
+ .rayMul(baseAPRRay + delinquencyFeeAPRRay)
303
+ .div(utils_1.SECONDS_IN_365_DAYS)
253
304
  .bipMul(this.reserveRatioBips);
254
305
  const protocolRequirementGrowthPerSecond = basePrincipal
255
306
  .rayMul(protocolFeeAPRRay)
256
- .div(utils_2.SECONDS_IN_365_DAYS);
307
+ .div(utils_1.SECONDS_IN_365_DAYS);
257
308
  const totalRequirementGrowthPerSecond = lenderRequirementGrowthPerSecond.add(protocolRequirementGrowthPerSecond.raw);
258
309
  return totalRequirementGrowthPerSecond.mul(timeToPayInSeconds);
259
310
  }
@@ -265,12 +316,8 @@ class Market extends types_1.ContractWrapper {
265
316
  * @return apr paid by borrower in ray
266
317
  */
267
318
  get effectiveBorrowerAPR() {
268
- // apr + (apr * protocolFee)
269
- let apr = (0, utils_2.bipMul)((0, utils_2.bipToRay)(this.annualInterestBips), utils_2.BIP.add(this.protocolFeeBips));
270
- if (this.timeDelinquent > this.delinquencyGracePeriod) {
271
- apr = apr.add((0, utils_2.bipToRay)(this.delinquencyFeeBips));
272
- }
273
- return apr;
319
+ return ((0, utils_1.bipMulBigint)(this.currentBaseLenderAPR, utils_1.BIP_BIGINT + BigInt(this.protocolFeeBips)) +
320
+ this.currentPenaltyAPR);
274
321
  }
275
322
  /**
276
323
  * @dev Calculate effective interest rate currently earned by lenders.
@@ -279,35 +326,39 @@ class Market extends types_1.ContractWrapper {
279
326
  * @return apr earned by lender in ray
280
327
  */
281
328
  get effectiveLenderAPR() {
282
- let apr = this.annualInterestBips;
283
- if (this.timeDelinquent > this.delinquencyGracePeriod) {
284
- apr += this.delinquencyFeeBips;
285
- }
286
- return (0, utils_2.bipToRay)(apr);
329
+ return this.currentBaseLenderAPR + this.currentPenaltyAPR;
287
330
  }
288
331
  /* -------------------------------------------------------------------------- */
289
332
  /* Withdrawal Execution */
290
333
  /* -------------------------------------------------------------------------- */
291
334
  async executeWithdrawal({ lender, expiry }) {
292
- 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
+ }));
293
341
  }
294
342
  async executeWithdrawals(withdrawals) {
295
343
  const lenders = withdrawals.map((w) => w.lender);
296
344
  const expiries = withdrawals.map((w) => w.expiry);
297
- 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
+ }));
298
351
  }
299
352
  populateRepayAndProcessUnpaidWithdrawalBatches(amount, maxBatches = 10) {
300
- return {
353
+ return (0, utils_1.prepareTransaction)({
301
354
  to: this.address,
302
- data: this.contract.interface.encodeFunctionData("repayAndProcessUnpaidWithdrawalBatches", [
303
- amount.raw,
304
- maxBatches
305
- ]),
306
- value: "0"
307
- };
355
+ abi: abi_1.wildcatMarketAbi,
356
+ functionName: "repayAndProcessUnpaidWithdrawalBatches",
357
+ args: [amount.raw, maxBatches]
358
+ });
308
359
  }
309
360
  async repayAndProcessUnpaidWithdrawalBatches(amount, maxBatches = 10) {
310
- return this.contract.repayAndProcessUnpaidWithdrawalBatches(amount.raw, maxBatches);
361
+ return (0, viem_write_1.submitPreparedTransaction)(this.signer, this.populateRepayAndProcessUnpaidWithdrawalBatches(amount, maxBatches));
311
362
  }
312
363
  /* -------------------------------------------------------------------------- */
313
364
  /* Set APR */
@@ -323,7 +374,8 @@ class Market extends types_1.ContractWrapper {
323
374
  if (annualInterestBips < originalAnnualInterestBips) {
324
375
  let doubleRelativeDiff;
325
376
  if (this.version === types_1.MarketVersion.V2) {
326
- 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));
327
379
  if (relativeDiff <= 2500) {
328
380
  // In v2, if the relative diff is 25% or less, the reserve ratio is not changed
329
381
  return originalReserveRatioBips;
@@ -331,7 +383,8 @@ class Market extends types_1.ContractWrapper {
331
383
  doubleRelativeDiff = 2 * relativeDiff;
332
384
  }
333
385
  else {
334
- 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));
335
388
  }
336
389
  const boundRelativeDiff = Math.min(10000, doubleRelativeDiff);
337
390
  return Math.max(boundRelativeDiff, originalReserveRatioBips);
@@ -343,10 +396,11 @@ class Market extends types_1.ContractWrapper {
343
396
  return originalReserveRatioBips;
344
397
  }
345
398
  calculateLiquidityCoverageForReserveRatio(reserveRatio) {
346
- const scaledRequiredReserves = (0, utils_2.bipMul)(this.scaledTotalSupply.sub(this.scaledPendingWithdrawals), (0, token_1.toBn)(reserveRatio)).add(this.scaledPendingWithdrawals);
347
- return this.underlyingToken.getAmount((0, utils_2.rayMul)(scaledRequiredReserves, this.scaleFactor)
348
- .add(this.lastAccruedProtocolFees.raw)
349
- .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);
350
404
  }
351
405
  canChangeAPR(annualInterestBips) {
352
406
  const originalAnnualInterestBips = this.temporaryReserveRatio
@@ -379,7 +433,7 @@ class Market extends types_1.ContractWrapper {
379
433
  if (this.version === types_1.MarketVersion.V2) {
380
434
  if (hasUnifiedLatestLensForDirectReads(this.chainId)) {
381
435
  try {
382
- const market = await (0, constants_1.getLensV2_5Contract)(this.chainId, this.provider).getMarketData(this.address);
436
+ const market = await (0, market_lens_1.getUnifiedMarketDataV2)(this.chainId, this.provider, this.address);
383
437
  this.updateWith(market);
384
438
  return;
385
439
  }
@@ -387,69 +441,86 @@ class Market extends types_1.ContractWrapper {
387
441
  // Fall back to the pre-2.5 V2 lens until unified lens deployment is reliable.
388
442
  }
389
443
  }
390
- 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);
391
445
  this.updateWith(market);
392
446
  return;
393
447
  }
394
- 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);
395
449
  this.updateWith(market);
396
450
  }
397
451
  updateWith(data) {
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);
398
457
  // Note: this adds all the interest accrued to the base interest accrued, since the lens
399
458
  // doesn't give us any way to distinguish between base interest and delinquency fees.
400
- if (this.scaledTotalSupply.eq(data.scaledTotalSupply) &&
401
- data.scaleFactor.gt(this.scaleFactor) &&
459
+ if (this.scaledTotalSupply === nextScaledTotalSupply &&
460
+ nextScaleFactor > this.scaleFactor &&
402
461
  this.totalBaseInterestAccrued) {
403
- const lastTotalValue = (0, utils_2.rayMul)(this.scaledTotalSupply, this.scaleFactor);
404
- const currentTotalValue = (0, utils_2.rayMul)(this.scaledTotalSupply, data.scaleFactor);
405
- 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;
406
465
  this.totalBaseInterestAccrued = this.totalBaseInterestAccrued.add(baseInterestAccrued);
407
466
  }
408
- if (data.lastAccruedProtocolFees.gt(this.lastAccruedProtocolFees.raw) &&
467
+ if (nextLastAccruedProtocolFees > this.lastAccruedProtocolFees.raw &&
409
468
  this.totalProtocolFeesAccrued) {
410
- this.totalProtocolFeesAccrued = this.totalProtocolFeesAccrued.add(data.lastAccruedProtocolFees.sub(this.lastAccruedProtocolFees.raw));
411
- }
412
- this.feeRecipient = data.feeRecipient;
413
- this.protocolFeeBips = data.protocolFeeBips.toNumber();
414
- this.delinquencyFeeBips = data.delinquencyFeeBips.toNumber();
415
- this.delinquencyGracePeriod = data.delinquencyGracePeriod.toNumber();
416
- this.withdrawalBatchDuration = data.withdrawalBatchDuration.toNumber();
417
- this.reserveRatioBips = data.reserveRatioBips.toNumber();
418
- this.annualInterestBips = data.annualInterestBips.toNumber();
419
- this.temporaryReserveRatio = data.temporaryReserveRatio;
420
- this.originalAnnualInterestBips = data.originalAnnualInterestBips.toNumber();
421
- this.originalReserveRatioBips = data.originalReserveRatioBips.toNumber();
422
- this.temporaryReserveRatioExpiry = data.temporaryReserveRatioExpiry.toNumber();
423
- this.isClosed = data.isClosed;
424
- this.scaleFactor = data.scaleFactor;
425
- this.totalSupply = this.marketToken.getAmount(data.totalSupply);
426
- this.maxTotalSupply = this.marketToken.getAmount(data.maxTotalSupply);
427
- this.scaledTotalSupply = data.scaledTotalSupply;
428
- this.totalAssets = this.underlyingToken.getAmount(data.totalAssets);
429
- this.lastAccruedProtocolFees = this.underlyingToken.getAmount(data.lastAccruedProtocolFees);
430
- this.normalizedUnclaimedWithdrawals = this.underlyingToken.getAmount(data.normalizedUnclaimedWithdrawals);
431
- this.scaledPendingWithdrawals = data.scaledPendingWithdrawals;
432
- this.pendingWithdrawalExpiry = data.pendingWithdrawalExpiry.toNumber();
433
- this.isDelinquent = data.isDelinquent;
434
- this.timeDelinquent = data.timeDelinquent.toNumber();
435
- this.lastInterestAccruedTimestamp = data.lastInterestAccruedTimestamp.toNumber();
436
- this.unpaidWithdrawalBatchExpiries = data.unpaidWithdrawalBatchExpiries;
437
- this.coverageLiquidity = this.underlyingToken.getAmount(data.coverageLiquidity);
438
- if ("hooksFactory" in data) {
439
- this.hooksFactory = data.hooksFactory;
440
- this.marketType = (0, constants_1.getMarketTypeForHooksFactory)(this.chainId, data.hooksFactory);
441
- }
442
- if ("hooksConfig" in data) {
443
- (0, utils_2.assert)(this.version === types_1.MarketVersion.V2, `Can not push V2 lens data to V1 market!`);
469
+ this.totalProtocolFeesAccrued = this.totalProtocolFeesAccrued.add(nextLastAccruedProtocolFees - this.lastAccruedProtocolFees.raw);
470
+ }
471
+ this.feeRecipient = baseData.feeRecipient;
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);
478
+ this.temporaryReserveRatio = baseData.temporaryReserveRatio;
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);
482
+ this.isClosed = baseData.isClosed;
483
+ this.scaleFactor = nextScaleFactor;
484
+ this.totalSupply = this.marketToken.getAmount(baseData.totalSupply);
485
+ this.maxTotalSupply = this.marketToken.getAmount(baseData.maxTotalSupply);
486
+ this.scaledTotalSupply = nextScaledTotalSupply;
487
+ this.totalAssets = this.underlyingToken.getAmount(baseData.totalAssets);
488
+ this.lastAccruedProtocolFees = this.underlyingToken.getAmount(baseData.lastAccruedProtocolFees);
489
+ this.normalizedUnclaimedWithdrawals = this.underlyingToken.getAmount(baseData.normalizedUnclaimedWithdrawals);
490
+ this.scaledPendingWithdrawals = nextScaledPendingWithdrawals;
491
+ this.pendingWithdrawalExpiry = (0, utils_1.toNumber)(baseData.pendingWithdrawalExpiry);
492
+ this.isDelinquent = baseData.isDelinquent;
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);
496
+ this.coverageLiquidity = this.underlyingToken.getAmount(baseData.coverageLiquidity);
497
+ if ("hooksFactory" in baseData) {
498
+ this.hooksFactory = baseData.hooksFactory;
499
+ this.marketType = (0, constants_1.getMarketTypeForHooksFactory)(this.chainId, baseData.hooksFactory);
500
+ }
501
+ if ("hooksConfig" in baseData) {
502
+ (0, utils_1.assert)(this.version === types_1.MarketVersion.V2, `Can not push V2 lens data to V1 market!`);
444
503
  const config = this.hooksConfig;
445
- (0, utils_2.assert)(config !== undefined, `V2 market has no hooksConfig!`);
446
- config.minimumDeposit = this.underlyingToken.getAmount(data.hooksConfig.minimumDeposit);
504
+ (0, utils_1.assert)(config !== undefined, `V2 market has no hooksConfig!`);
505
+ config.minimumDeposit = this.underlyingToken.getAmount(baseData.hooksConfig.minimumDeposit);
447
506
  if (config.kind === types_1.HooksKind.FixedTerm) {
448
- config.fixedTermEndTime = data.hooksConfig.fixedTermEndTime;
507
+ config.fixedTermEndTime = (0, utils_1.toNumber)(baseData.hooksConfig.fixedTermEndTime);
449
508
  }
450
509
  }
451
510
  else {
452
- (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!`);
512
+ }
513
+ if ("market" in data) {
514
+ this.commitmentFeeBips = data.commitmentFeeBips.isPresent
515
+ ? (0, utils_1.toNumber)(data.commitmentFeeBips.value)
516
+ : undefined;
517
+ this.drawnAmount = data.drawnAmount.isPresent
518
+ ? this.underlyingToken.getAmount(data.drawnAmount.value)
519
+ : undefined;
520
+ }
521
+ else {
522
+ this.commitmentFeeBips = undefined;
523
+ this.drawnAmount = undefined;
453
524
  }
454
525
  }
455
526
  /* -------------------------------------------------------------------------- */
@@ -458,17 +529,18 @@ class Market extends types_1.ContractWrapper {
458
529
  static fromSubgraphMarketData(chainId, provider, data, signerAddress) {
459
530
  const underlyingToken = token_1.Token.fromSubgraphToken(chainId, data._asset, provider);
460
531
  const marketToken = token_1.Token.fromSubgraphMarketData(chainId, data, provider);
461
- const scaledTotalSupply = ethers_1.BigNumber.from(data.scaledTotalSupply);
462
- const scaleFactor = ethers_1.BigNumber.from(data.scaleFactor);
463
- const scaledWithdrawals = ethers_1.BigNumber.from(data.scaledPendingWithdrawals);
464
- const scaledRequiredReserves = (0, utils_2.bipMul)(scaledTotalSupply.sub(scaledWithdrawals), ethers_1.BigNumber.from(data.reserveRatioBips)).add(scaledWithdrawals);
465
- const coverageLiquidity = (0, utils_2.rayMul)(scaledRequiredReserves, scaleFactor)
466
- .add(data.pendingProtocolFees)
467
- .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);
468
540
  let hooksConfig;
469
541
  if (data.version === types_1.MarketVersion.V2) {
470
- (0, utils_2.assert)(!!data.hooks, `V2 markets require hooks`);
471
- (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`);
472
544
  const { minimumDeposit: _minimumDeposit, depositRequiresAccess, transferRequiresAccess, queueWithdrawalRequiresAccess, allowClosureBeforeTerm, allowForceBuyBacks, allowTermReduction, fixedTermEndTime, transfersDisabled } = data.hooksConfig;
473
545
  const flags = {
474
546
  useOnDeposit: data.hooksConfig.useOnDeposit,
@@ -540,20 +612,22 @@ class Market extends types_1.ContractWrapper {
540
612
  originalReserveRatioBips: data.originalReserveRatioBips,
541
613
  temporaryReserveRatioExpiry: data.temporaryReserveRatioExpiry,
542
614
  isClosed: data.isClosed,
543
- scaleFactor: ethers_1.BigNumber.from(data.scaleFactor),
544
- totalSupply: marketToken.getAmount((0, utils_2.rayMul)(scaledTotalSupply, scaleFactor)),
615
+ scaleFactor,
616
+ totalSupply: marketToken.getAmount((0, utils_1.rayMulBigint)(scaledTotalSupply, scaleFactor)),
545
617
  maxTotalSupply: marketToken.getAmount(data.maxTotalSupply),
546
618
  scaledTotalSupply: scaledTotalSupply,
547
619
  totalAssets: underlyingToken.getAmount(0),
548
620
  lastAccruedProtocolFees: underlyingToken.getAmount(data.pendingProtocolFees),
549
621
  normalizedUnclaimedWithdrawals: underlyingToken.getAmount(data.normalizedUnclaimedWithdrawals),
550
- scaledPendingWithdrawals: ethers_1.BigNumber.from(data.scaledPendingWithdrawals),
622
+ scaledPendingWithdrawals: scaledWithdrawals,
551
623
  pendingWithdrawalExpiry: +data.pendingWithdrawalExpiry,
552
624
  isDelinquent: data.isDelinquent,
553
625
  timeDelinquent: data.timeDelinquent,
554
626
  lastInterestAccruedTimestamp: data.lastInterestAccruedTimestamp,
555
627
  unpaidWithdrawalBatchExpiries: [] /* data.unpaidWithdrawalBatchExpiries */,
556
628
  coverageLiquidity: underlyingToken.getAmount(coverageLiquidity),
629
+ commitmentFeeBips: data.commitmentFeeBips != null ? Number(data.commitmentFeeBips) : undefined,
630
+ drawnAmount: data.drawnAmount != null ? underlyingToken.getAmount(data.drawnAmount) : undefined,
557
631
  totalBorrowed: underlyingToken.getAmount(data.totalBorrowed),
558
632
  totalRepaid: underlyingToken.getAmount(data.totalRepaid),
559
633
  totalBaseInterestAccrued: underlyingToken.getAmount(data.totalBaseInterestAccrued),
@@ -582,30 +656,30 @@ class Market extends types_1.ContractWrapper {
582
656
  borrower: data.borrower,
583
657
  controller: data.controller,
584
658
  feeRecipient: data.feeRecipient,
585
- protocolFeeBips: data.protocolFeeBips.toNumber(),
586
- delinquencyFeeBips: data.delinquencyFeeBips.toNumber(),
587
- delinquencyGracePeriod: data.delinquencyGracePeriod.toNumber(),
588
- withdrawalBatchDuration: data.withdrawalBatchDuration.toNumber(),
589
- reserveRatioBips: data.reserveRatioBips.toNumber(),
590
- 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),
591
665
  temporaryReserveRatio: data.temporaryReserveRatio,
592
- originalAnnualInterestBips: data.originalAnnualInterestBips.toNumber(),
593
- originalReserveRatioBips: data.originalReserveRatioBips.toNumber(),
594
- 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),
595
669
  isClosed: data.isClosed,
596
- scaleFactor: data.scaleFactor,
670
+ scaleFactor: (0, token_1.toRawAmount)(data.scaleFactor),
597
671
  totalSupply: marketToken.getAmount(data.totalSupply),
598
672
  maxTotalSupply: marketToken.getAmount(data.maxTotalSupply),
599
- scaledTotalSupply: data.scaledTotalSupply,
673
+ scaledTotalSupply: (0, token_1.toRawAmount)(data.scaledTotalSupply),
600
674
  totalAssets: underlyingToken.getAmount(data.totalAssets),
601
675
  lastAccruedProtocolFees: underlyingToken.getAmount(data.lastAccruedProtocolFees),
602
676
  normalizedUnclaimedWithdrawals: underlyingToken.getAmount(data.normalizedUnclaimedWithdrawals),
603
- scaledPendingWithdrawals: data.scaledPendingWithdrawals,
604
- pendingWithdrawalExpiry: data.pendingWithdrawalExpiry.toNumber(),
677
+ scaledPendingWithdrawals: (0, token_1.toRawAmount)(data.scaledPendingWithdrawals),
678
+ pendingWithdrawalExpiry: (0, utils_1.toNumber)(data.pendingWithdrawalExpiry),
605
679
  isDelinquent: data.isDelinquent,
606
- timeDelinquent: data.timeDelinquent.toNumber(),
607
- lastInterestAccruedTimestamp: data.lastInterestAccruedTimestamp.toNumber(),
608
- 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),
609
683
  coverageLiquidity: underlyingToken.getAmount(data.coverageLiquidity),
610
684
  totalBorrowed: undefined,
611
685
  totalRepaid: undefined,
@@ -627,7 +701,8 @@ class Market extends types_1.ContractWrapper {
627
701
  const underlyingToken = token_1.Token.fromTokenMetadata(chainId, data.underlyingToken, provider);
628
702
  const { hooksAddress } = hooks;
629
703
  let hooksConfig;
630
- if (hooksConfigData.kind === 1) {
704
+ const hooksKind = (0, utils_1.toNumber)(hooksConfigData.kind);
705
+ if (hooksKind === 1) {
631
706
  hooksConfig = {
632
707
  kind: types_1.HooksKind.OpenTerm,
633
708
  hooksAddress: hooksAddress,
@@ -639,7 +714,7 @@ class Market extends types_1.ContractWrapper {
639
714
  allowForceBuyBacks: hooksConfigData.allowForceBuyBacks
640
715
  };
641
716
  }
642
- else if (hooksConfigData.kind === 2) {
717
+ else if (hooksKind === 2) {
643
718
  hooksConfig = {
644
719
  kind: types_1.HooksKind.FixedTerm,
645
720
  hooksAddress: hooksAddress,
@@ -648,7 +723,7 @@ class Market extends types_1.ContractWrapper {
648
723
  transferRequiresAccess: hooksConfigData.transferRequiresAccess,
649
724
  transfersDisabled: hooksConfigData.transfersDisabled,
650
725
  minimumDeposit: underlyingToken.getAmount(hooksConfigData.minimumDeposit),
651
- fixedTermEndTime: hooksConfigData.fixedTermEndTime,
726
+ fixedTermEndTime: (0, utils_1.toNumber)(hooksConfigData.fixedTermEndTime),
652
727
  queueWithdrawalRequiresAccess: hooksConfigData.withdrawalRequiresAccess,
653
728
  allowTermReduction: hooksConfigData.allowTermReduction,
654
729
  allowClosureBeforeTerm: hooksConfigData.allowClosureBeforeTerm,
@@ -656,7 +731,7 @@ class Market extends types_1.ContractWrapper {
656
731
  };
657
732
  }
658
733
  else {
659
- throw Error(`Unknown hooks kind: ${hooks.hooksTemplate.name}, version #${hooksConfigData.kind}`);
734
+ throw Error(`Unknown hooks kind: ${hooks.hooksTemplate.name}, version #${hooksKind}`);
660
735
  }
661
736
  return new Market({
662
737
  provider,
@@ -669,41 +744,43 @@ class Market extends types_1.ContractWrapper {
669
744
  underlyingToken: underlyingToken,
670
745
  borrower: data.borrower,
671
746
  feeRecipient: data.feeRecipient,
672
- protocolFeeBips: data.protocolFeeBips.toNumber(),
673
- delinquencyFeeBips: data.delinquencyFeeBips.toNumber(),
674
- delinquencyGracePeriod: data.delinquencyGracePeriod.toNumber(),
675
- withdrawalBatchDuration: data.withdrawalBatchDuration.toNumber(),
676
- reserveRatioBips: data.reserveRatioBips.toNumber(),
677
- 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),
678
753
  temporaryReserveRatio: data.temporaryReserveRatio,
679
- originalAnnualInterestBips: data.originalAnnualInterestBips.toNumber(),
680
- originalReserveRatioBips: data.originalReserveRatioBips.toNumber(),
681
- 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),
682
757
  isClosed: data.isClosed,
683
- scaleFactor: data.scaleFactor,
758
+ scaleFactor: (0, token_1.toRawAmount)(data.scaleFactor),
684
759
  totalSupply: marketToken.getAmount(data.totalSupply),
685
760
  maxTotalSupply: marketToken.getAmount(data.maxTotalSupply),
686
- scaledTotalSupply: data.scaledTotalSupply,
761
+ scaledTotalSupply: (0, token_1.toRawAmount)(data.scaledTotalSupply),
687
762
  totalAssets: underlyingToken.getAmount(data.totalAssets),
688
763
  lastAccruedProtocolFees: underlyingToken.getAmount(data.lastAccruedProtocolFees),
689
764
  normalizedUnclaimedWithdrawals: underlyingToken.getAmount(data.normalizedUnclaimedWithdrawals),
690
- scaledPendingWithdrawals: data.scaledPendingWithdrawals,
691
- pendingWithdrawalExpiry: data.pendingWithdrawalExpiry.toNumber(),
765
+ scaledPendingWithdrawals: (0, token_1.toRawAmount)(data.scaledPendingWithdrawals),
766
+ pendingWithdrawalExpiry: (0, utils_1.toNumber)(data.pendingWithdrawalExpiry),
692
767
  isDelinquent: data.isDelinquent,
693
- timeDelinquent: data.timeDelinquent.toNumber(),
694
- lastInterestAccruedTimestamp: data.lastInterestAccruedTimestamp.toNumber(),
695
- 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),
696
771
  coverageLiquidity: underlyingToken.getAmount(data.coverageLiquidity),
697
772
  signerAddress
698
773
  // borrowableAssets: underlyingToken.getAmount(data.borrowableAssets)
699
774
  });
700
775
  }
701
- static fromMarketDataV2_5(chainId, provider, { hooks, hooksConfig: hooksConfigData, ...data }, allowForceBuyBacks, signerAddress) {
776
+ static fromMarketDataV2_5(chainId, provider, { market, commitmentFeeBips, drawnAmount }, allowForceBuyBacks, signerAddress) {
777
+ const { hooks, hooksConfig: hooksConfigData, ...data } = market;
702
778
  const marketToken = token_1.Token.fromTokenMetadata(chainId, data.marketToken, provider);
703
779
  const underlyingToken = token_1.Token.fromTokenMetadata(chainId, data.underlyingToken, provider);
704
780
  const { hooksAddress } = hooks;
705
781
  let hooksConfig;
706
- if (hooksConfigData.kind === 1) {
782
+ const hooksKind = (0, utils_1.toNumber)(hooksConfigData.kind);
783
+ if (hooksKind === 1) {
707
784
  hooksConfig = {
708
785
  kind: types_1.HooksKind.OpenTerm,
709
786
  hooksAddress,
@@ -715,7 +792,7 @@ class Market extends types_1.ContractWrapper {
715
792
  allowForceBuyBacks
716
793
  };
717
794
  }
718
- else if (hooksConfigData.kind === 2) {
795
+ else if (hooksKind === 2) {
719
796
  hooksConfig = {
720
797
  kind: types_1.HooksKind.FixedTerm,
721
798
  hooksAddress,
@@ -724,7 +801,7 @@ class Market extends types_1.ContractWrapper {
724
801
  transferRequiresAccess: hooksConfigData.transferRequiresAccess,
725
802
  transfersDisabled: hooksConfigData.transfersDisabled,
726
803
  minimumDeposit: underlyingToken.getAmount(hooksConfigData.minimumDeposit),
727
- fixedTermEndTime: hooksConfigData.fixedTermEndTime,
804
+ fixedTermEndTime: (0, utils_1.toNumber)(hooksConfigData.fixedTermEndTime),
728
805
  queueWithdrawalRequiresAccess: hooksConfigData.withdrawalRequiresAccess,
729
806
  allowTermReduction: hooksConfigData.allowTermReduction,
730
807
  allowClosureBeforeTerm: hooksConfigData.allowClosureBeforeTerm,
@@ -732,7 +809,7 @@ class Market extends types_1.ContractWrapper {
732
809
  };
733
810
  }
734
811
  else {
735
- throw Error(`Unknown hooks kind: ${hooks.hooksTemplate.name}, version #${hooksConfigData.kind}`);
812
+ throw Error(`Unknown hooks kind: ${hooks.hooksTemplate.name}, version #${hooksKind}`);
736
813
  }
737
814
  return new Market({
738
815
  provider,
@@ -745,48 +822,54 @@ class Market extends types_1.ContractWrapper {
745
822
  underlyingToken,
746
823
  borrower: data.borrower,
747
824
  feeRecipient: data.feeRecipient,
748
- protocolFeeBips: data.protocolFeeBips.toNumber(),
749
- delinquencyFeeBips: data.delinquencyFeeBips.toNumber(),
750
- delinquencyGracePeriod: data.delinquencyGracePeriod.toNumber(),
751
- withdrawalBatchDuration: data.withdrawalBatchDuration.toNumber(),
752
- reserveRatioBips: data.reserveRatioBips.toNumber(),
753
- 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),
754
831
  temporaryReserveRatio: data.temporaryReserveRatio,
755
- originalAnnualInterestBips: data.originalAnnualInterestBips.toNumber(),
756
- originalReserveRatioBips: data.originalReserveRatioBips.toNumber(),
757
- 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),
758
835
  isClosed: data.isClosed,
759
- scaleFactor: data.scaleFactor,
836
+ scaleFactor: (0, token_1.toRawAmount)(data.scaleFactor),
760
837
  totalSupply: marketToken.getAmount(data.totalSupply),
761
838
  maxTotalSupply: marketToken.getAmount(data.maxTotalSupply),
762
- scaledTotalSupply: data.scaledTotalSupply,
839
+ scaledTotalSupply: (0, token_1.toRawAmount)(data.scaledTotalSupply),
763
840
  totalAssets: underlyingToken.getAmount(data.totalAssets),
764
841
  lastAccruedProtocolFees: underlyingToken.getAmount(data.lastAccruedProtocolFees),
765
842
  normalizedUnclaimedWithdrawals: underlyingToken.getAmount(data.normalizedUnclaimedWithdrawals),
766
- scaledPendingWithdrawals: data.scaledPendingWithdrawals,
767
- pendingWithdrawalExpiry: data.pendingWithdrawalExpiry.toNumber(),
843
+ scaledPendingWithdrawals: (0, token_1.toRawAmount)(data.scaledPendingWithdrawals),
844
+ pendingWithdrawalExpiry: (0, utils_1.toNumber)(data.pendingWithdrawalExpiry),
768
845
  isDelinquent: data.isDelinquent,
769
- timeDelinquent: data.timeDelinquent.toNumber(),
770
- lastInterestAccruedTimestamp: data.lastInterestAccruedTimestamp.toNumber(),
771
- 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),
772
849
  coverageLiquidity: underlyingToken.getAmount(data.coverageLiquidity),
850
+ commitmentFeeBips: commitmentFeeBips.isPresent
851
+ ? (0, utils_1.toNumber)(commitmentFeeBips.value)
852
+ : undefined,
853
+ drawnAmount: drawnAmount.isPresent ? underlyingToken.getAmount(drawnAmount.value) : undefined,
773
854
  signerAddress
774
855
  });
775
856
  }
776
857
  static async resolveAllowForceBuyBacks(provider, marketAddress, data) {
777
- if (data.hooksConfig.kind === 1) {
778
- const hookedMarket = await typechain_1.IOpenTermHooks__factory.connect(data.hooksConfig.hooksAddress, provider).getHookedMarket(marketAddress);
779
- return hookedMarket.allowForceBuyBacks;
858
+ const marketData = "market" in data ? data.market : data;
859
+ if (marketData.hooksConfig.kind === 1) {
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);
780
862
  }
781
- if (data.hooksConfig.kind === 2) {
782
- const hookedMarket = await typechain_1.IFixedTermHooks__factory.connect(data.hooksConfig.hooksAddress, provider).getHookedMarket(marketAddress);
783
- return hookedMarket.allowForceBuyBacks;
863
+ if (marketData.hooksConfig.kind === 2) {
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);
784
866
  }
785
867
  return false;
786
868
  }
787
869
  static async fromUnifiedMarketData(chainId, provider, data, signerAddress) {
788
- const allowForceBuyBacks = await Market.resolveAllowForceBuyBacks(provider, data.marketToken.token, data);
789
- return Market.fromMarketDataV2_5(chainId, provider, data, allowForceBuyBacks, signerAddress);
870
+ const marketData = toUnifiedMarketDataV2(data);
871
+ const allowForceBuyBacks = await Market.resolveAllowForceBuyBacks(provider, marketData.market.marketToken.token, marketData);
872
+ return Market.fromMarketDataV2_5(chainId, provider, marketData, allowForceBuyBacks, signerAddress);
790
873
  }
791
874
  /* -------------------------------------------------------------------------- */
792
875
  /* Static Queries */
@@ -795,62 +878,58 @@ class Market extends types_1.ContractWrapper {
795
878
  * @returns `Market` instance for `market`
796
879
  */
797
880
  static async getMarket(chainId, market, provider) {
798
- const signerAddress = abstract_signer_1.Signer.isSigner(provider) ? await provider.getAddress() : undefined;
881
+ const signerAddress = await (0, ethers_signer_1.getEthersSignerAddress)(provider);
799
882
  if (hasUnifiedLatestLensForDirectReads(chainId)) {
800
883
  try {
801
- const data = await (0, constants_1.getLensV2_5Contract)(chainId, provider).getMarketData(market);
884
+ const data = await (0, market_lens_1.getUnifiedMarketDataV2)(chainId, provider, market);
802
885
  return Market.fromUnifiedMarketData(chainId, provider, data, signerAddress);
803
886
  }
804
887
  catch (_) {
805
888
  // Fall back to the legacy lens for V1 markets and pre-unified deployments.
806
889
  }
807
890
  }
808
- const lens = (0, constants_1.getLensContract)(chainId, provider);
809
- const data = await lens.getMarketData(market);
891
+ const data = await (0, market_lens_1.getLegacyMarketData)(chainId, provider, market);
810
892
  return Market.fromMarketData(chainId, data, provider, signerAddress);
811
893
  }
812
894
  /**
813
895
  * @returns `Market` instance for `market`
814
896
  */
815
897
  static async getMarketV2(chainId, market, provider) {
816
- const signerAddress = abstract_signer_1.Signer.isSigner(provider) ? await provider.getAddress() : undefined;
898
+ const signerAddress = await (0, ethers_signer_1.getEthersSignerAddress)(provider);
817
899
  if (hasUnifiedLatestLensForDirectReads(chainId)) {
818
900
  try {
819
- const data = await (0, constants_1.getLensV2_5Contract)(chainId, provider).getMarketData(market);
901
+ const data = await (0, market_lens_1.getUnifiedMarketDataV2)(chainId, provider, market);
820
902
  return Market.fromUnifiedMarketData(chainId, provider, data, signerAddress);
821
903
  }
822
904
  catch (_) {
823
905
  // Fall back to the pre-2.5 V2 lens for chains that have not fully migrated.
824
906
  }
825
907
  }
826
- const lens = (0, constants_1.getLensV2Contract)(chainId, provider);
827
- const data = await lens.getMarketData(market);
908
+ const data = await (0, market_lens_1.getV2MarketData)(chainId, provider, market);
828
909
  return Market.fromMarketDataV2(chainId, provider, data, signerAddress);
829
910
  }
830
911
  /**
831
912
  * @returns `Market` instances for `markets`
832
913
  */
833
914
  static async getMarkets(chainId, markets, provider) {
834
- const signerAddress = abstract_signer_1.Signer.isSigner(provider) ? await provider.getAddress() : undefined;
915
+ const signerAddress = await (0, ethers_signer_1.getEthersSignerAddress)(provider);
835
916
  if (hasUnifiedLatestLensForDirectReads(chainId)) {
836
917
  try {
837
- const data = await (0, constants_1.getLensV2_5Contract)(chainId, provider).getMarketsData(markets);
918
+ const data = await (0, market_lens_1.getUnifiedMarketsDataV2)(chainId, provider, markets);
838
919
  return Promise.all(data.map((market) => Market.fromUnifiedMarketData(chainId, provider, market, signerAddress)));
839
920
  }
840
921
  catch (_) {
841
922
  return Promise.all(markets.map((market) => Market.getMarket(chainId, market, provider)));
842
923
  }
843
924
  }
844
- const lens = (0, constants_1.getLensContract)(chainId, provider);
845
- const data = await lens.getMarketsData(markets);
925
+ const data = await (0, market_lens_1.getLegacyMarketsData)(chainId, provider, markets);
846
926
  return data.map((market) => Market.fromMarketData(chainId, market, provider, signerAddress));
847
927
  }
848
928
  /**
849
929
  * @return All deployed markets
850
930
  */
851
931
  static async getAllMarkets(chainId, provider) {
852
- const archController = (0, constants_1.getArchControllerContract)(chainId, provider);
853
- const markets = await archController["getRegisteredMarkets()"]();
932
+ const markets = await (0, arch_controller_1.getRegisteredMarkets)(chainId, provider);
854
933
  if (!markets.length) {
855
934
  return [];
856
935
  }
@@ -863,13 +942,12 @@ class Market extends types_1.ContractWrapper {
863
942
  if (count <= 0) {
864
943
  return [];
865
944
  }
866
- const archController = (0, constants_1.getArchControllerContract)(chainId, provider);
867
- const totalMarkets = (await archController.getRegisteredMarketsCount()).toNumber();
945
+ const totalMarkets = await (0, arch_controller_1.getRegisteredMarketsCount)(chainId, provider);
868
946
  if (start >= totalMarkets) {
869
947
  return [];
870
948
  }
871
949
  const end = Math.min(start + count, totalMarkets);
872
- const markets = await archController["getRegisteredMarkets(uint256,uint256)"](start, end);
950
+ const markets = await (0, arch_controller_1.getRegisteredMarketsPage)(chainId, provider, start, end);
873
951
  if (!markets.length) {
874
952
  return [];
875
953
  }
@@ -879,8 +957,7 @@ class Market extends types_1.ContractWrapper {
879
957
  * @return Total number of deployed markets.
880
958
  */
881
959
  static async getMarketsCount(chainId, provider) {
882
- const archController = (0, constants_1.getArchControllerContract)(chainId, provider);
883
- return archController.getRegisteredMarketsCount().then((count) => count.toNumber());
960
+ return (0, arch_controller_1.getRegisteredMarketsCount)(chainId, provider);
884
961
  }
885
962
  }
886
963
  exports.Market = Market;