@morpho-org/morpho-sdk 1.0.1 → 1.2.0

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 (304) hide show
  1. package/LICENSE +2 -2
  2. package/README.md +31 -33
  3. package/lib/cjs/actions/index.d.ts +4 -0
  4. package/lib/{actions → cjs/actions}/index.js +4 -4
  5. package/lib/cjs/actions/marketV1/borrow.d.ts +69 -0
  6. package/lib/cjs/actions/marketV1/borrow.js +97 -0
  7. package/lib/cjs/actions/marketV1/buildReallocationActions.d.ts +28 -0
  8. package/lib/cjs/actions/marketV1/buildReallocationActions.js +47 -0
  9. package/lib/cjs/actions/marketV1/index.d.ts +6 -0
  10. package/lib/{actions → cjs/actions}/marketV1/index.js +6 -6
  11. package/lib/cjs/actions/marketV1/repay.d.ts +89 -0
  12. package/lib/cjs/actions/marketV1/repay.js +134 -0
  13. package/lib/cjs/actions/marketV1/repayWithdrawCollateral.d.ts +103 -0
  14. package/lib/cjs/actions/marketV1/repayWithdrawCollateral.js +155 -0
  15. package/lib/cjs/actions/marketV1/supplyCollateral.d.ts +59 -0
  16. package/lib/cjs/actions/marketV1/supplyCollateral.js +116 -0
  17. package/lib/cjs/actions/marketV1/supplyCollateralBorrow.d.ts +91 -0
  18. package/lib/cjs/actions/marketV1/supplyCollateralBorrow.js +163 -0
  19. package/lib/cjs/actions/marketV1/withdrawCollateral.d.ts +49 -0
  20. package/lib/cjs/actions/marketV1/withdrawCollateral.js +72 -0
  21. package/lib/cjs/actions/requirements/encode/encodeErc20Approval.d.ts +36 -0
  22. package/lib/{actions → cjs/actions}/requirements/encode/encodeErc20Approval.js +25 -0
  23. package/lib/cjs/actions/requirements/encode/encodeErc20Permit.d.ts +52 -0
  24. package/lib/cjs/actions/requirements/encode/encodeErc20Permit.js +108 -0
  25. package/lib/cjs/actions/requirements/encode/encodeErc20Permit2.d.ts +44 -0
  26. package/lib/{actions → cjs/actions}/requirements/encode/encodeErc20Permit2.js +36 -4
  27. package/lib/cjs/actions/requirements/encode/index.d.ts +3 -0
  28. package/lib/{actions → cjs/actions}/requirements/encode/index.js +3 -3
  29. package/lib/cjs/actions/requirements/getMorphoAuthorizationRequirement.d.ts +37 -0
  30. package/lib/cjs/actions/requirements/getMorphoAuthorizationRequirement.js +71 -0
  31. package/lib/cjs/actions/requirements/getRequirements.d.ts +74 -0
  32. package/lib/cjs/actions/requirements/getRequirements.js +112 -0
  33. package/lib/cjs/actions/requirements/getRequirementsAction.d.ts +33 -0
  34. package/lib/{actions → cjs/actions}/requirements/getRequirementsAction.js +20 -4
  35. package/lib/cjs/actions/requirements/getRequirementsApproval.d.ts +43 -0
  36. package/lib/cjs/actions/requirements/getRequirementsApproval.js +63 -0
  37. package/lib/cjs/actions/requirements/getRequirementsPermit.d.ts +45 -0
  38. package/lib/cjs/actions/requirements/getRequirementsPermit.js +57 -0
  39. package/lib/cjs/actions/requirements/getRequirementsPermit2.d.ts +63 -0
  40. package/lib/cjs/actions/requirements/getRequirementsPermit2.js +85 -0
  41. package/lib/cjs/actions/requirements/index.d.ts +6 -0
  42. package/lib/{actions → cjs/actions}/requirements/index.js +6 -6
  43. package/lib/cjs/actions/vaultV1/deposit.d.ts +72 -0
  44. package/lib/cjs/actions/vaultV1/deposit.js +146 -0
  45. package/lib/cjs/actions/vaultV1/index.d.ts +4 -0
  46. package/lib/{actions → cjs/actions}/vaultV1/index.js +4 -4
  47. package/lib/cjs/actions/vaultV1/migrateToV2.d.ts +84 -0
  48. package/lib/cjs/actions/vaultV1/migrateToV2.js +143 -0
  49. package/lib/cjs/actions/vaultV1/redeem.d.ts +39 -0
  50. package/lib/cjs/actions/vaultV1/redeem.js +57 -0
  51. package/lib/cjs/actions/vaultV1/withdraw.d.ts +39 -0
  52. package/lib/cjs/actions/vaultV1/withdraw.js +57 -0
  53. package/lib/cjs/actions/vaultV2/deposit.d.ts +72 -0
  54. package/lib/cjs/actions/vaultV2/deposit.js +146 -0
  55. package/lib/cjs/actions/vaultV2/forceRedeem.d.ts +63 -0
  56. package/lib/cjs/actions/vaultV2/forceRedeem.js +99 -0
  57. package/lib/cjs/actions/vaultV2/forceWithdraw.d.ts +58 -0
  58. package/lib/cjs/actions/vaultV2/forceWithdraw.js +94 -0
  59. package/lib/cjs/actions/vaultV2/index.d.ts +5 -0
  60. package/lib/{actions → cjs/actions}/vaultV2/index.js +5 -5
  61. package/lib/cjs/actions/vaultV2/redeem.d.ts +40 -0
  62. package/lib/cjs/actions/vaultV2/redeem.js +58 -0
  63. package/lib/cjs/actions/vaultV2/withdraw.d.ts +40 -0
  64. package/lib/cjs/actions/vaultV2/withdraw.js +58 -0
  65. package/lib/cjs/client/index.d.ts +2 -0
  66. package/lib/{client → cjs/client}/index.js +2 -2
  67. package/lib/cjs/client/morphoClient.d.ts +113 -0
  68. package/lib/cjs/client/morphoClient.js +123 -0
  69. package/lib/cjs/client/morphoViemExtension.d.ts +45 -0
  70. package/lib/cjs/client/morphoViemExtension.js +46 -0
  71. package/lib/cjs/entities/index.d.ts +3 -0
  72. package/lib/{entities → cjs/entities}/index.js +3 -3
  73. package/lib/cjs/entities/marketV1/index.d.ts +1 -0
  74. package/lib/{entities/vaultV1 → cjs/entities/marketV1}/index.js +1 -1
  75. package/lib/{entities → cjs/entities}/marketV1/marketV1.d.ts +9 -6
  76. package/lib/{entities → cjs/entities}/marketV1/marketV1.js +89 -87
  77. package/lib/cjs/entities/vaultV1/index.d.ts +1 -0
  78. package/lib/{entities/marketV1 → cjs/entities/vaultV1}/index.js +1 -1
  79. package/lib/{entities → cjs/entities}/vaultV1/vaultV1.d.ts +4 -8
  80. package/lib/{entities → cjs/entities}/vaultV1/vaultV1.js +39 -35
  81. package/lib/cjs/entities/vaultV2/index.d.ts +1 -0
  82. package/lib/{entities → cjs/entities}/vaultV2/index.js +1 -1
  83. package/lib/{entities → cjs/entities}/vaultV2/vaultV2.d.ts +2 -2
  84. package/lib/{entities → cjs/entities}/vaultV2/vaultV2.js +25 -24
  85. package/lib/{helpers → cjs/helpers}/computeReallocations.d.ts +1 -1
  86. package/lib/{helpers → cjs/helpers}/computeReallocations.js +2 -2
  87. package/lib/{helpers → cjs/helpers}/encodeDeallocation.d.ts +1 -1
  88. package/lib/{helpers → cjs/helpers}/encodeDeallocation.js +2 -2
  89. package/lib/{helpers → cjs/helpers}/index.d.ts +4 -4
  90. package/lib/{helpers → cjs/helpers}/index.js +19 -19
  91. package/lib/{helpers → cjs/helpers}/metadata.d.ts +1 -1
  92. package/lib/{helpers → cjs/helpers}/slippage.js +7 -7
  93. package/lib/{helpers → cjs/helpers}/validate.d.ts +1 -1
  94. package/lib/{helpers → cjs/helpers}/validate.js +33 -33
  95. package/lib/cjs/index.d.ts +5 -0
  96. package/lib/cjs/index.js +21 -0
  97. package/lib/cjs/package.json +1 -0
  98. package/lib/{types → cjs/types}/action.d.ts +1 -1
  99. package/lib/{types → cjs/types}/client.d.ts +6 -2
  100. package/lib/{types → cjs/types}/error.d.ts +46 -7
  101. package/lib/{types → cjs/types}/error.js +47 -7
  102. package/lib/cjs/types/index.d.ts +7 -0
  103. package/lib/cjs/types/index.js +23 -0
  104. package/lib/esm/actions/index.d.ts +4 -0
  105. package/lib/esm/actions/index.js +4 -0
  106. package/lib/esm/actions/marketV1/borrow.d.ts +69 -0
  107. package/lib/esm/actions/marketV1/borrow.js +93 -0
  108. package/lib/esm/actions/marketV1/buildReallocationActions.d.ts +28 -0
  109. package/lib/esm/actions/marketV1/buildReallocationActions.js +43 -0
  110. package/lib/esm/actions/marketV1/index.d.ts +6 -0
  111. package/lib/esm/actions/marketV1/index.js +6 -0
  112. package/lib/esm/actions/marketV1/repay.d.ts +89 -0
  113. package/lib/esm/actions/marketV1/repay.js +130 -0
  114. package/lib/esm/actions/marketV1/repayWithdrawCollateral.d.ts +103 -0
  115. package/lib/esm/actions/marketV1/repayWithdrawCollateral.js +151 -0
  116. package/lib/esm/actions/marketV1/supplyCollateral.d.ts +59 -0
  117. package/lib/esm/actions/marketV1/supplyCollateral.js +112 -0
  118. package/lib/esm/actions/marketV1/supplyCollateralBorrow.d.ts +91 -0
  119. package/lib/esm/actions/marketV1/supplyCollateralBorrow.js +159 -0
  120. package/lib/esm/actions/marketV1/withdrawCollateral.d.ts +49 -0
  121. package/lib/esm/actions/marketV1/withdrawCollateral.js +68 -0
  122. package/lib/esm/actions/requirements/encode/encodeErc20Approval.d.ts +36 -0
  123. package/lib/esm/actions/requirements/encode/encodeErc20Approval.js +46 -0
  124. package/lib/esm/actions/requirements/encode/encodeErc20Permit.d.ts +52 -0
  125. package/lib/esm/actions/requirements/encode/encodeErc20Permit.js +104 -0
  126. package/lib/esm/actions/requirements/encode/encodeErc20Permit2.d.ts +44 -0
  127. package/lib/esm/actions/requirements/encode/encodeErc20Permit2.js +98 -0
  128. package/lib/esm/actions/requirements/encode/index.d.ts +3 -0
  129. package/lib/esm/actions/requirements/encode/index.js +3 -0
  130. package/lib/esm/actions/requirements/getMorphoAuthorizationRequirement.d.ts +37 -0
  131. package/lib/esm/actions/requirements/getMorphoAuthorizationRequirement.js +67 -0
  132. package/lib/esm/actions/requirements/getRequirements.d.ts +74 -0
  133. package/lib/esm/actions/requirements/getRequirements.js +108 -0
  134. package/lib/esm/actions/requirements/getRequirementsAction.d.ts +33 -0
  135. package/lib/esm/actions/requirements/getRequirementsAction.js +76 -0
  136. package/lib/esm/actions/requirements/getRequirementsApproval.d.ts +43 -0
  137. package/lib/esm/actions/requirements/getRequirementsApproval.js +59 -0
  138. package/lib/esm/actions/requirements/getRequirementsPermit.d.ts +45 -0
  139. package/lib/esm/actions/requirements/getRequirementsPermit.js +53 -0
  140. package/lib/esm/actions/requirements/getRequirementsPermit2.d.ts +63 -0
  141. package/lib/esm/actions/requirements/getRequirementsPermit2.js +81 -0
  142. package/lib/esm/actions/requirements/index.d.ts +6 -0
  143. package/lib/esm/actions/requirements/index.js +6 -0
  144. package/lib/esm/actions/vaultV1/deposit.d.ts +72 -0
  145. package/lib/esm/actions/vaultV1/deposit.js +142 -0
  146. package/lib/esm/actions/vaultV1/index.d.ts +4 -0
  147. package/lib/esm/actions/vaultV1/index.js +4 -0
  148. package/lib/esm/actions/vaultV1/migrateToV2.d.ts +84 -0
  149. package/lib/esm/actions/vaultV1/migrateToV2.js +139 -0
  150. package/lib/esm/actions/vaultV1/redeem.d.ts +39 -0
  151. package/lib/esm/actions/vaultV1/redeem.js +53 -0
  152. package/lib/esm/actions/vaultV1/withdraw.d.ts +39 -0
  153. package/lib/esm/actions/vaultV1/withdraw.js +53 -0
  154. package/lib/esm/actions/vaultV2/deposit.d.ts +72 -0
  155. package/lib/esm/actions/vaultV2/deposit.js +142 -0
  156. package/lib/esm/actions/vaultV2/forceRedeem.d.ts +63 -0
  157. package/lib/esm/actions/vaultV2/forceRedeem.js +95 -0
  158. package/lib/esm/actions/vaultV2/forceWithdraw.d.ts +58 -0
  159. package/lib/esm/actions/vaultV2/forceWithdraw.js +90 -0
  160. package/lib/esm/actions/vaultV2/index.d.ts +5 -0
  161. package/lib/esm/actions/vaultV2/index.js +5 -0
  162. package/lib/esm/actions/vaultV2/redeem.d.ts +40 -0
  163. package/lib/esm/actions/vaultV2/redeem.js +54 -0
  164. package/lib/esm/actions/vaultV2/withdraw.d.ts +40 -0
  165. package/lib/esm/actions/vaultV2/withdraw.js +54 -0
  166. package/lib/esm/client/index.d.ts +2 -0
  167. package/lib/esm/client/index.js +2 -0
  168. package/lib/esm/client/morphoClient.d.ts +113 -0
  169. package/lib/esm/client/morphoClient.js +119 -0
  170. package/lib/esm/client/morphoViemExtension.d.ts +45 -0
  171. package/lib/esm/client/morphoViemExtension.js +43 -0
  172. package/lib/esm/entities/index.d.ts +3 -0
  173. package/lib/esm/entities/index.js +3 -0
  174. package/lib/esm/entities/marketV1/index.d.ts +1 -0
  175. package/lib/esm/entities/marketV1/index.js +1 -0
  176. package/lib/esm/entities/marketV1/marketV1.d.ts +293 -0
  177. package/lib/esm/entities/marketV1/marketV1.js +529 -0
  178. package/lib/esm/entities/vaultV1/index.d.ts +1 -0
  179. package/lib/esm/entities/vaultV1/index.js +1 -0
  180. package/lib/esm/entities/vaultV1/vaultV1.d.ts +129 -0
  181. package/lib/esm/entities/vaultV1/vaultV1.js +186 -0
  182. package/lib/esm/entities/vaultV2/index.d.ts +1 -0
  183. package/lib/esm/entities/vaultV2/index.js +1 -0
  184. package/lib/esm/entities/vaultV2/vaultV2.d.ts +180 -0
  185. package/lib/esm/entities/vaultV2/vaultV2.js +164 -0
  186. package/lib/esm/helpers/computeReallocations.d.ts +23 -0
  187. package/lib/esm/helpers/computeReallocations.js +94 -0
  188. package/lib/esm/helpers/constant.d.ts +6 -0
  189. package/lib/esm/helpers/constant.js +7 -0
  190. package/lib/esm/helpers/encodeDeallocation.d.ts +10 -0
  191. package/lib/esm/helpers/encodeDeallocation.js +34 -0
  192. package/lib/esm/helpers/index.d.ts +4 -0
  193. package/lib/esm/helpers/index.js +4 -0
  194. package/lib/esm/helpers/metadata.d.ts +33 -0
  195. package/lib/esm/helpers/metadata.js +46 -0
  196. package/lib/esm/helpers/slippage.d.ts +46 -0
  197. package/lib/esm/helpers/slippage.js +69 -0
  198. package/lib/esm/helpers/validate.d.ts +156 -0
  199. package/lib/esm/helpers/validate.js +273 -0
  200. package/lib/esm/index.d.ts +5 -0
  201. package/lib/esm/index.js +5 -0
  202. package/lib/esm/package.json +1 -0
  203. package/lib/esm/types/action.d.ts +216 -0
  204. package/lib/esm/types/action.js +21 -0
  205. package/lib/esm/types/client.d.ts +19 -0
  206. package/lib/esm/types/client.js +1 -0
  207. package/lib/esm/types/data.d.ts +2 -0
  208. package/lib/esm/types/data.js +1 -0
  209. package/lib/esm/types/deallocation.d.ts +15 -0
  210. package/lib/esm/types/deallocation.js +1 -0
  211. package/lib/esm/types/entity.d.ts +5 -0
  212. package/lib/esm/types/entity.js +1 -0
  213. package/lib/esm/types/error.d.ts +205 -0
  214. package/lib/esm/types/error.js +276 -0
  215. package/lib/esm/types/index.d.ts +7 -0
  216. package/lib/esm/types/index.js +7 -0
  217. package/lib/esm/types/metadata.d.ts +4 -0
  218. package/lib/esm/types/metadata.js +1 -0
  219. package/lib/esm/types/sharedLiquidity.d.ts +41 -0
  220. package/lib/esm/types/sharedLiquidity.js +1 -0
  221. package/package.json +33 -56
  222. package/src/index.ts +5 -0
  223. package/lib/actions/index.d.ts +0 -4
  224. package/lib/actions/marketV1/borrow.d.ts +0 -34
  225. package/lib/actions/marketV1/borrow.js +0 -62
  226. package/lib/actions/marketV1/buildReallocationActions.d.ts +0 -17
  227. package/lib/actions/marketV1/buildReallocationActions.js +0 -36
  228. package/lib/actions/marketV1/index.d.ts +0 -6
  229. package/lib/actions/marketV1/repay.d.ts +0 -44
  230. package/lib/actions/marketV1/repay.js +0 -93
  231. package/lib/actions/marketV1/repayWithdrawCollateral.d.ts +0 -51
  232. package/lib/actions/marketV1/repayWithdrawCollateral.js +0 -108
  233. package/lib/actions/marketV1/supplyCollateral.d.ts +0 -28
  234. package/lib/actions/marketV1/supplyCollateral.js +0 -85
  235. package/lib/actions/marketV1/supplyCollateralBorrow.d.ts +0 -37
  236. package/lib/actions/marketV1/supplyCollateralBorrow.js +0 -109
  237. package/lib/actions/marketV1/withdrawCollateral.d.ts +0 -28
  238. package/lib/actions/marketV1/withdrawCollateral.js +0 -51
  239. package/lib/actions/requirements/encode/encodeErc20Approval.d.ts +0 -10
  240. package/lib/actions/requirements/encode/encodeErc20Permit.d.ts +0 -13
  241. package/lib/actions/requirements/encode/encodeErc20Permit.js +0 -70
  242. package/lib/actions/requirements/encode/encodeErc20Permit2.d.ts +0 -11
  243. package/lib/actions/requirements/encode/index.d.ts +0 -3
  244. package/lib/actions/requirements/getMorphoAuthorizationRequirement.d.ts +0 -21
  245. package/lib/actions/requirements/getMorphoAuthorizationRequirement.js +0 -55
  246. package/lib/actions/requirements/getRequirements.d.ts +0 -42
  247. package/lib/actions/requirements/getRequirements.js +0 -80
  248. package/lib/actions/requirements/getRequirementsAction.d.ts +0 -17
  249. package/lib/actions/requirements/getRequirementsApproval.d.ts +0 -31
  250. package/lib/actions/requirements/getRequirementsApproval.js +0 -51
  251. package/lib/actions/requirements/getRequirementsPermit.d.ts +0 -28
  252. package/lib/actions/requirements/getRequirementsPermit.js +0 -40
  253. package/lib/actions/requirements/getRequirementsPermit2.d.ts +0 -37
  254. package/lib/actions/requirements/getRequirementsPermit2.js +0 -59
  255. package/lib/actions/requirements/index.d.ts +0 -6
  256. package/lib/actions/vaultV1/deposit.d.ts +0 -41
  257. package/lib/actions/vaultV1/deposit.js +0 -116
  258. package/lib/actions/vaultV1/index.d.ts +0 -4
  259. package/lib/actions/vaultV1/migrateToV2.d.ts +0 -50
  260. package/lib/actions/vaultV1/migrateToV2.js +0 -108
  261. package/lib/actions/vaultV1/redeem.d.ts +0 -29
  262. package/lib/actions/vaultV1/redeem.js +0 -48
  263. package/lib/actions/vaultV1/withdraw.d.ts +0 -29
  264. package/lib/actions/vaultV1/withdraw.js +0 -48
  265. package/lib/actions/vaultV2/deposit.d.ts +0 -41
  266. package/lib/actions/vaultV2/deposit.js +0 -116
  267. package/lib/actions/vaultV2/forceRedeem.d.ts +0 -48
  268. package/lib/actions/vaultV2/forceRedeem.js +0 -85
  269. package/lib/actions/vaultV2/forceWithdraw.d.ts +0 -40
  270. package/lib/actions/vaultV2/forceWithdraw.js +0 -85
  271. package/lib/actions/vaultV2/index.d.ts +0 -5
  272. package/lib/actions/vaultV2/redeem.d.ts +0 -32
  273. package/lib/actions/vaultV2/redeem.js +0 -51
  274. package/lib/actions/vaultV2/withdraw.d.ts +0 -32
  275. package/lib/actions/vaultV2/withdraw.js +0 -51
  276. package/lib/client/index.d.ts +0 -2
  277. package/lib/client/morphoClient.d.ts +0 -25
  278. package/lib/client/morphoClient.js +0 -28
  279. package/lib/client/morphoViemExtension.d.ts +0 -39
  280. package/lib/client/morphoViemExtension.js +0 -40
  281. package/lib/entities/index.d.ts +0 -3
  282. package/lib/entities/marketV1/index.d.ts +0 -1
  283. package/lib/entities/vaultV1/index.d.ts +0 -1
  284. package/lib/entities/vaultV2/index.d.ts +0 -1
  285. package/lib/index.d.ts +0 -5
  286. package/lib/index.js +0 -21
  287. package/lib/types/index.d.ts +0 -7
  288. package/lib/types/index.js +0 -23
  289. /package/lib/{helpers → cjs/helpers}/constant.d.ts +0 -0
  290. /package/lib/{helpers → cjs/helpers}/constant.js +0 -0
  291. /package/lib/{helpers → cjs/helpers}/metadata.js +0 -0
  292. /package/lib/{helpers → cjs/helpers}/slippage.d.ts +0 -0
  293. /package/lib/{types → cjs/types}/action.js +0 -0
  294. /package/lib/{types → cjs/types}/client.js +0 -0
  295. /package/lib/{types → cjs/types}/data.d.ts +0 -0
  296. /package/lib/{types → cjs/types}/data.js +0 -0
  297. /package/lib/{types → cjs/types}/deallocation.d.ts +0 -0
  298. /package/lib/{types → cjs/types}/deallocation.js +0 -0
  299. /package/lib/{types → cjs/types}/entity.d.ts +0 -0
  300. /package/lib/{types → cjs/types}/entity.js +0 -0
  301. /package/lib/{types → cjs/types}/metadata.d.ts +0 -0
  302. /package/lib/{types → cjs/types}/metadata.js +0 -0
  303. /package/lib/{types → cjs/types}/sharedLiquidity.d.ts +0 -0
  304. /package/lib/{types → cjs/types}/sharedLiquidity.js +0 -0
@@ -0,0 +1 @@
1
+ export * from "./marketV1.js";
@@ -14,4 +14,4 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
14
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
- __exportStar(require("./vaultV1"), exports);
17
+ __exportStar(require("./marketV1.js"), exports);
@@ -1,8 +1,8 @@
1
1
  import { type AccrualPosition, type Market, type MarketParams } from "@morpho-org/blue-sdk";
2
2
  import { type MinimalBlock, SimulationState } from "@morpho-org/simulation-sdk";
3
3
  import type { Address } from "viem";
4
- import { type DepositAmountArgs, type ERC20ApprovalAction, type MarketV1BorrowAction, type MarketV1RepayAction, type MarketV1RepayWithdrawCollateralAction, type MarketV1SupplyCollateralAction, type MarketV1SupplyCollateralBorrowAction, type MarketV1WithdrawCollateralAction, type MorphoAuthorizationAction, type MorphoClientType, type ReallocationComputeOptions, type RepayAmountArgs, type Requirement, type RequirementSignature, type Transaction, type VaultReallocation } from "../../types";
5
- import type { FetchParameters } from "../../types/data";
4
+ import type { FetchParameters } from "../../types/data.js";
5
+ import { type DepositAmountArgs, type ERC20ApprovalAction, type MarketV1BorrowAction, type MarketV1RepayAction, type MarketV1RepayWithdrawCollateralAction, type MarketV1SupplyCollateralAction, type MarketV1SupplyCollateralBorrowAction, type MarketV1WithdrawCollateralAction, type MorphoAuthorizationAction, type MorphoClientType, type ReallocationComputeOptions, type RepayAmountArgs, type Requirement, type RequirementSignature, type Transaction, type VaultReallocation } from "../../types/index.js";
6
6
  export interface MarketV1Actions {
7
7
  /**
8
8
  * Fetches the latest market data with accrued interest.
@@ -176,6 +176,12 @@ export interface MarketV1Actions {
176
176
  * Fetches all on-chain data needed to construct a {@link SimulationState}
177
177
  * for computing vault reallocations via the public allocator.
178
178
  *
179
+ * The target market is refetched internally at `block.number` so the
180
+ * reallocation planner always sees a snapshot from the same block as the
181
+ * source vaults. A caller-owned market would let stale or adversarial data
182
+ * inject unnecessary `reallocateTo` actions (and their PublicAllocator
183
+ * fees) into the resulting bundle.
184
+ *
179
185
  * The returned simulation state can be passed to {@link getReallocations}
180
186
  * to compute the `VaultReallocation[]` array for `borrow()` or
181
187
  * `supplyCollateralBorrow()`.
@@ -183,13 +189,11 @@ export interface MarketV1Actions {
183
189
  * **Stale data reverts on-chain (fail-safe).**
184
190
  *
185
191
  * @param params.vaultAddresses - Addresses of MetaMorpho vaults that allocate to this market.
186
- * @param params.market - The target market data (from {@link getPositionData} or {@link getMarketData}).
187
192
  * @param params.block - The block to fetch data at (number and timestamp).
188
193
  * @returns A SimulationState populated with all required data.
189
194
  */
190
195
  getReallocationData: (params: {
191
196
  vaultAddresses: readonly Address[];
192
- market: Market;
193
197
  block: MinimalBlock;
194
198
  }) => Promise<SimulationState>;
195
199
  /**
@@ -277,9 +281,8 @@ export declare class MorphoMarketV1 implements MarketV1Actions {
277
281
  }) => Promise<(Requirement | Readonly<Transaction<ERC20ApprovalAction>> | Readonly<Transaction<MorphoAuthorizationAction>>)[]>;
278
282
  buildTx: (requirementSignature?: RequirementSignature) => Readonly<Transaction<MarketV1SupplyCollateralBorrowAction>>;
279
283
  };
280
- getReallocationData({ vaultAddresses, market, block, }: {
284
+ getReallocationData({ vaultAddresses, block, }: {
281
285
  vaultAddresses: readonly Address[];
282
- market: Market;
283
286
  block: MinimalBlock;
284
287
  }): Promise<SimulationState>;
285
288
  getReallocations({ reallocationData, borrowAmount, options, }: {
@@ -5,20 +5,21 @@ const blue_sdk_1 = require("@morpho-org/blue-sdk");
5
5
  const blue_sdk_viem_1 = require("@morpho-org/blue-sdk-viem");
6
6
  const morpho_ts_1 = require("@morpho-org/morpho-ts");
7
7
  const simulation_sdk_1 = require("@morpho-org/simulation-sdk");
8
- const actions_1 = require("../../actions");
9
- const helpers_1 = require("../../helpers");
10
- const types_1 = require("../../types");
8
+ const index_js_1 = require("../../actions/index.js");
9
+ const index_js_2 = require("../../helpers/index.js");
10
+ const index_js_3 = require("../../types/index.js");
11
11
  class MorphoMarketV1 {
12
12
  client;
13
13
  marketParams;
14
14
  chainId;
15
+ // biome-ignore lint/complexity/useMaxParams: TODO refactor to ≤2 params
15
16
  constructor(client, marketParams, chainId) {
16
17
  this.client = client;
17
18
  this.marketParams = marketParams;
18
19
  this.chainId = chainId;
19
20
  }
20
21
  async getMarketData(parameters) {
21
- (0, helpers_1.validateChainId)(this.client.viemClient.chain?.id, this.chainId);
22
+ (0, index_js_2.validateChainId)(this.client.viemClient.chain?.id, this.chainId);
22
23
  return (0, blue_sdk_viem_1.fetchMarket)(this.marketParams.id, this.client.viemClient, {
23
24
  ...parameters,
24
25
  chainId: this.chainId,
@@ -26,7 +27,7 @@ class MorphoMarketV1 {
26
27
  });
27
28
  }
28
29
  async getPositionData(userAddress, parameters) {
29
- (0, helpers_1.validateChainId)(this.client.viemClient.chain?.id, this.chainId);
30
+ (0, index_js_2.validateChainId)(this.client.viemClient.chain?.id, this.chainId);
30
31
  return (0, blue_sdk_viem_1.fetchAccrualPosition)(userAddress, this.marketParams.id, this.client.viemClient, {
31
32
  ...parameters,
32
33
  deployless: this.client.options.supportDeployless,
@@ -34,23 +35,23 @@ class MorphoMarketV1 {
34
35
  });
35
36
  }
36
37
  supplyCollateral({ amount = 0n, userAddress, nativeAmount, }) {
37
- (0, helpers_1.validateChainId)(this.client.viemClient.chain?.id, this.chainId);
38
- (0, helpers_1.validateUserAddress)(this.client.viemClient.account?.address, userAddress);
38
+ (0, index_js_2.validateChainId)(this.client.viemClient.chain?.id, this.chainId);
39
+ (0, index_js_2.validateUserAddress)(this.client.viemClient.account?.address, userAddress);
39
40
  if (amount < 0n) {
40
- throw new types_1.NonPositiveAssetAmountError(this.marketParams.collateralToken);
41
+ throw new index_js_3.NonPositiveAssetAmountError(this.marketParams.collateralToken);
41
42
  }
42
43
  if (nativeAmount !== undefined && nativeAmount < 0n) {
43
- throw new types_1.NegativeNativeAmountError(nativeAmount);
44
+ throw new index_js_3.NegativeNativeAmountError(nativeAmount);
44
45
  }
45
46
  const totalCollateral = amount + (nativeAmount ?? 0n);
46
47
  if (totalCollateral === 0n) {
47
- throw new types_1.ZeroCollateralAmountError(this.marketParams.id);
48
+ throw new index_js_3.ZeroCollateralAmountError(this.marketParams.id);
48
49
  }
49
50
  if (nativeAmount !== undefined && nativeAmount > 0n) {
50
- (0, helpers_1.validateNativeCollateral)(this.chainId, this.marketParams.collateralToken);
51
+ (0, index_js_2.validateNativeCollateral)(this.chainId, this.marketParams.collateralToken);
51
52
  }
52
53
  return {
53
- getRequirements: (params) => (0, actions_1.getRequirements)(this.client.viemClient, {
54
+ getRequirements: (params) => (0, index_js_1.getRequirements)(this.client.viemClient, {
54
55
  address: this.marketParams.collateralToken,
55
56
  chainId: this.chainId,
56
57
  supportSignature: this.client.options.supportSignature,
@@ -58,7 +59,7 @@ class MorphoMarketV1 {
58
59
  useSimplePermit: params?.useSimplePermit,
59
60
  args: { amount, from: userAddress },
60
61
  }),
61
- buildTx: (requirementSignature) => (0, actions_1.marketV1SupplyCollateral)({
62
+ buildTx: (requirementSignature) => (0, index_js_1.marketV1SupplyCollateral)({
62
63
  market: {
63
64
  chainId: this.chainId,
64
65
  marketParams: this.marketParams,
@@ -74,42 +75,42 @@ class MorphoMarketV1 {
74
75
  };
75
76
  }
76
77
  borrow({ amount, userAddress, positionData, slippageTolerance = blue_sdk_1.DEFAULT_SLIPPAGE_TOLERANCE, reallocations, }) {
77
- (0, helpers_1.validateChainId)(this.client.viemClient.chain?.id, this.chainId);
78
- (0, helpers_1.validateUserAddress)(this.client.viemClient.account?.address, userAddress);
78
+ (0, index_js_2.validateChainId)(this.client.viemClient.chain?.id, this.chainId);
79
+ (0, index_js_2.validateUserAddress)(this.client.viemClient.account?.address, userAddress);
79
80
  if (amount <= 0n) {
80
- throw new types_1.NonPositiveBorrowAmountError(this.marketParams.id);
81
+ throw new index_js_3.NonPositiveBorrowAmountError(this.marketParams.id);
81
82
  }
82
- (0, helpers_1.validateSlippageTolerance)(slippageTolerance);
83
+ (0, index_js_2.validateSlippageTolerance)(slippageTolerance);
83
84
  if (!positionData) {
84
- throw new types_1.MissingAccrualPositionError(this.marketParams.id);
85
+ throw new index_js_3.MissingAccrualPositionError(this.marketParams.id);
85
86
  }
86
- (0, helpers_1.validateAccrualPosition)({
87
+ (0, index_js_2.validateAccrualPosition)({
87
88
  positionData,
88
89
  expectedMarketId: this.marketParams.id,
89
90
  expectedUser: userAddress,
90
91
  });
91
- (0, helpers_1.validatePositionHealth)({
92
+ (0, index_js_2.validatePositionHealth)({
92
93
  positionData,
93
94
  additionalCollateral: 0n,
94
95
  borrowAmount: amount,
95
96
  marketId: this.marketParams.id,
96
97
  lltv: this.marketParams.lltv,
97
98
  });
98
- const minSharePrice = (0, helpers_1.computeMinBorrowSharePrice)({
99
+ const minSharePrice = (0, index_js_2.computeMinBorrowSharePrice)({
99
100
  borrowAmount: amount,
100
101
  market: positionData.market,
101
102
  slippageTolerance,
102
103
  });
103
104
  return {
104
105
  getRequirements: async () => {
105
- const authTx = await (0, actions_1.getMorphoAuthorizationRequirement)({
106
+ const authTx = await (0, index_js_1.getMorphoAuthorizationRequirement)({
106
107
  viemClient: this.client.viemClient,
107
108
  chainId: this.chainId,
108
109
  userAddress,
109
110
  });
110
111
  return authTx ? [authTx] : [];
111
112
  },
112
- buildTx: () => (0, actions_1.marketV1Borrow)({
113
+ buildTx: () => (0, index_js_1.marketV1Borrow)({
113
114
  market: {
114
115
  chainId: this.chainId,
115
116
  marketParams: this.marketParams,
@@ -125,28 +126,28 @@ class MorphoMarketV1 {
125
126
  };
126
127
  }
127
128
  repay(params) {
128
- (0, helpers_1.validateChainId)(this.client.viemClient.chain?.id, this.chainId);
129
- (0, helpers_1.validateUserAddress)(this.client.viemClient.account?.address, params.userAddress);
129
+ (0, index_js_2.validateChainId)(this.client.viemClient.chain?.id, this.chainId);
130
+ (0, index_js_2.validateUserAddress)(this.client.viemClient.account?.address, params.userAddress);
130
131
  const { userAddress, positionData, slippageTolerance = blue_sdk_1.DEFAULT_SLIPPAGE_TOLERANCE, } = params;
131
132
  if ("assets" in params && "shares" in params) {
132
- throw new types_1.MutuallyExclusiveRepayAmountsError(this.marketParams.id);
133
+ throw new index_js_3.MutuallyExclusiveRepayAmountsError(this.marketParams.id);
133
134
  }
134
135
  const isSharesMode = "shares" in params;
135
136
  if (isSharesMode) {
136
137
  if (params.shares <= 0n) {
137
- throw new types_1.NonPositiveRepayAmountError(this.marketParams.id);
138
+ throw new index_js_3.NonPositiveRepayAmountError(this.marketParams.id);
138
139
  }
139
140
  }
140
141
  else {
141
142
  if (params.assets <= 0n) {
142
- throw new types_1.NonPositiveRepayAmountError(this.marketParams.id);
143
+ throw new index_js_3.NonPositiveRepayAmountError(this.marketParams.id);
143
144
  }
144
145
  }
145
- (0, helpers_1.validateSlippageTolerance)(slippageTolerance);
146
+ (0, index_js_2.validateSlippageTolerance)(slippageTolerance);
146
147
  if (!positionData) {
147
- throw new types_1.MissingAccrualPositionError(this.marketParams.id);
148
+ throw new index_js_3.MissingAccrualPositionError(this.marketParams.id);
148
149
  }
149
- (0, helpers_1.validateAccrualPosition)({
150
+ (0, index_js_2.validateAccrualPosition)({
150
151
  positionData,
151
152
  expectedMarketId: this.marketParams.id,
152
153
  expectedUser: userAddress,
@@ -155,7 +156,7 @@ class MorphoMarketV1 {
155
156
  let shares;
156
157
  let transferAmount;
157
158
  if (isSharesMode) {
158
- (0, helpers_1.validateRepayShares)({
159
+ (0, index_js_2.validateRepayShares)({
159
160
  positionData,
160
161
  repayShares: params.shares,
161
162
  marketId: this.marketParams.id,
@@ -168,7 +169,7 @@ class MorphoMarketV1 {
168
169
  transferAmount = blue_sdk_1.MathLib.wMulUp(baseTransferAmount, blue_sdk_1.MathLib.WAD + slippageTolerance);
169
170
  }
170
171
  else {
171
- (0, helpers_1.validateRepayAmount)({
172
+ (0, index_js_2.validateRepayAmount)({
172
173
  positionData,
173
174
  repayAssets: params.assets,
174
175
  marketId: this.marketParams.id,
@@ -177,14 +178,14 @@ class MorphoMarketV1 {
177
178
  shares = 0n;
178
179
  transferAmount = params.assets;
179
180
  }
180
- const maxSharePrice = (0, helpers_1.computeMaxRepaySharePrice)({
181
+ const maxSharePrice = (0, index_js_2.computeMaxRepaySharePrice)({
181
182
  repayAssets: assets,
182
183
  repayShares: shares,
183
184
  market: positionData.market,
184
185
  slippageTolerance,
185
186
  });
186
187
  return {
187
- getRequirements: (reqParams) => (0, actions_1.getRequirements)(this.client.viemClient, {
188
+ getRequirements: (reqParams) => (0, index_js_1.getRequirements)(this.client.viemClient, {
188
189
  address: this.marketParams.loanToken,
189
190
  chainId: this.chainId,
190
191
  supportSignature: this.client.options.supportSignature,
@@ -192,7 +193,7 @@ class MorphoMarketV1 {
192
193
  useSimplePermit: reqParams?.useSimplePermit,
193
194
  args: { amount: transferAmount, from: userAddress },
194
195
  }),
195
- buildTx: (requirementSignature) => (0, actions_1.marketV1Repay)({
196
+ buildTx: (requirementSignature) => (0, index_js_1.marketV1Repay)({
196
197
  market: {
197
198
  chainId: this.chainId,
198
199
  marketParams: this.marketParams,
@@ -211,34 +212,34 @@ class MorphoMarketV1 {
211
212
  };
212
213
  }
213
214
  withdrawCollateral({ userAddress, amount, positionData, }) {
214
- (0, helpers_1.validateChainId)(this.client.viemClient.chain?.id, this.chainId);
215
- (0, helpers_1.validateUserAddress)(this.client.viemClient.account?.address, userAddress);
215
+ (0, index_js_2.validateChainId)(this.client.viemClient.chain?.id, this.chainId);
216
+ (0, index_js_2.validateUserAddress)(this.client.viemClient.account?.address, userAddress);
216
217
  if (amount <= 0n) {
217
- throw new types_1.NonPositiveWithdrawCollateralAmountError(this.marketParams.id);
218
+ throw new index_js_3.NonPositiveWithdrawCollateralAmountError(this.marketParams.id);
218
219
  }
219
220
  if (!positionData) {
220
- throw new types_1.MissingAccrualPositionError(this.marketParams.id);
221
+ throw new index_js_3.MissingAccrualPositionError(this.marketParams.id);
221
222
  }
222
- (0, helpers_1.validateAccrualPosition)({
223
+ (0, index_js_2.validateAccrualPosition)({
223
224
  positionData,
224
225
  expectedMarketId: this.marketParams.id,
225
226
  expectedUser: userAddress,
226
227
  });
227
228
  if (amount > positionData.collateral) {
228
- throw new types_1.WithdrawExceedsCollateralError({
229
+ throw new index_js_3.WithdrawExceedsCollateralError({
229
230
  withdrawAmount: amount,
230
231
  available: positionData.collateral,
231
232
  market: positionData.marketId,
232
233
  });
233
234
  }
234
- (0, helpers_1.validatePositionHealthAfterWithdraw)({
235
+ (0, index_js_2.validatePositionHealthAfterWithdraw)({
235
236
  positionData,
236
237
  withdrawAmount: amount,
237
238
  lltv: this.marketParams.lltv,
238
239
  marketId: this.marketParams.id,
239
240
  });
240
241
  return {
241
- buildTx: () => (0, actions_1.marketV1WithdrawCollateral)({
242
+ buildTx: () => (0, index_js_1.marketV1WithdrawCollateral)({
242
243
  market: {
243
244
  chainId: this.chainId,
244
245
  marketParams: this.marketParams,
@@ -253,31 +254,31 @@ class MorphoMarketV1 {
253
254
  };
254
255
  }
255
256
  repayWithdrawCollateral(params) {
256
- (0, helpers_1.validateChainId)(this.client.viemClient.chain?.id, this.chainId);
257
- (0, helpers_1.validateUserAddress)(this.client.viemClient.account?.address, params.userAddress);
257
+ (0, index_js_2.validateChainId)(this.client.viemClient.chain?.id, this.chainId);
258
+ (0, index_js_2.validateUserAddress)(this.client.viemClient.account?.address, params.userAddress);
258
259
  const { userAddress, withdrawAmount, positionData, slippageTolerance = blue_sdk_1.DEFAULT_SLIPPAGE_TOLERANCE, } = params;
259
260
  if ("assets" in params && "shares" in params) {
260
- throw new types_1.MutuallyExclusiveRepayAmountsError(this.marketParams.id);
261
+ throw new index_js_3.MutuallyExclusiveRepayAmountsError(this.marketParams.id);
261
262
  }
262
263
  const isSharesMode = "shares" in params;
263
264
  if (isSharesMode) {
264
265
  if (params.shares <= 0n) {
265
- throw new types_1.NonPositiveRepayAmountError(this.marketParams.id);
266
+ throw new index_js_3.NonPositiveRepayAmountError(this.marketParams.id);
266
267
  }
267
268
  }
268
269
  else {
269
270
  if (params.assets <= 0n) {
270
- throw new types_1.NonPositiveRepayAmountError(this.marketParams.id);
271
+ throw new index_js_3.NonPositiveRepayAmountError(this.marketParams.id);
271
272
  }
272
273
  }
273
274
  if (withdrawAmount <= 0n) {
274
- throw new types_1.NonPositiveWithdrawCollateralAmountError(this.marketParams.id);
275
+ throw new index_js_3.NonPositiveWithdrawCollateralAmountError(this.marketParams.id);
275
276
  }
276
- (0, helpers_1.validateSlippageTolerance)(slippageTolerance);
277
+ (0, index_js_2.validateSlippageTolerance)(slippageTolerance);
277
278
  if (!positionData) {
278
- throw new types_1.MissingAccrualPositionError(this.marketParams.id);
279
+ throw new index_js_3.MissingAccrualPositionError(this.marketParams.id);
279
280
  }
280
- (0, helpers_1.validateAccrualPosition)({
281
+ (0, index_js_2.validateAccrualPosition)({
281
282
  positionData,
282
283
  expectedMarketId: this.marketParams.id,
283
284
  expectedUser: userAddress,
@@ -286,7 +287,7 @@ class MorphoMarketV1 {
286
287
  let shares;
287
288
  let transferAmount;
288
289
  if (isSharesMode) {
289
- (0, helpers_1.validateRepayShares)({
290
+ (0, index_js_2.validateRepayShares)({
290
291
  positionData,
291
292
  repayShares: params.shares,
292
293
  marketId: this.marketParams.id,
@@ -297,7 +298,7 @@ class MorphoMarketV1 {
297
298
  transferAmount = blue_sdk_1.MathLib.wMulUp(baseTransferAmount, blue_sdk_1.MathLib.WAD + slippageTolerance);
298
299
  }
299
300
  else {
300
- (0, helpers_1.validateRepayAmount)({
301
+ (0, index_js_2.validateRepayAmount)({
301
302
  positionData,
302
303
  repayAssets: params.assets,
303
304
  marketId: this.marketParams.id,
@@ -307,7 +308,7 @@ class MorphoMarketV1 {
307
308
  transferAmount = params.assets;
308
309
  }
309
310
  if (withdrawAmount > positionData.collateral) {
310
- throw new types_1.WithdrawExceedsCollateralError({
311
+ throw new index_js_3.WithdrawExceedsCollateralError({
311
312
  withdrawAmount,
312
313
  available: positionData.collateral,
313
314
  market: positionData.marketId,
@@ -317,13 +318,13 @@ class MorphoMarketV1 {
317
318
  const accrualTimestamp = blue_sdk_1.MathLib.max(morpho_ts_1.Time.timestamp(), positionData.market.lastUpdate) +
318
319
  morpho_ts_1.Time.s.from.min(10n);
319
320
  const { position: positionAfterRepay } = positionData.repay(assets, shares, accrualTimestamp);
320
- (0, helpers_1.validatePositionHealthAfterWithdraw)({
321
+ (0, index_js_2.validatePositionHealthAfterWithdraw)({
321
322
  positionData: positionAfterRepay,
322
323
  withdrawAmount,
323
324
  lltv: this.marketParams.lltv,
324
325
  marketId: this.marketParams.id,
325
326
  });
326
- const maxSharePrice = (0, helpers_1.computeMaxRepaySharePrice)({
327
+ const maxSharePrice = (0, index_js_2.computeMaxRepaySharePrice)({
327
328
  repayAssets: assets,
328
329
  repayShares: shares,
329
330
  market: positionData.market,
@@ -332,7 +333,7 @@ class MorphoMarketV1 {
332
333
  return {
333
334
  getRequirements: async (reqParams) => {
334
335
  const [erc20Requirements, authTx] = await Promise.all([
335
- (0, actions_1.getRequirements)(this.client.viemClient, {
336
+ (0, index_js_1.getRequirements)(this.client.viemClient, {
336
337
  address: this.marketParams.loanToken,
337
338
  chainId: this.chainId,
338
339
  supportSignature: this.client.options.supportSignature,
@@ -340,7 +341,7 @@ class MorphoMarketV1 {
340
341
  useSimplePermit: reqParams?.useSimplePermit,
341
342
  args: { amount: transferAmount, from: userAddress },
342
343
  }),
343
- (0, actions_1.getMorphoAuthorizationRequirement)({
344
+ (0, index_js_1.getMorphoAuthorizationRequirement)({
344
345
  viemClient: this.client.viemClient,
345
346
  chainId: this.chainId,
346
347
  userAddress,
@@ -348,7 +349,7 @@ class MorphoMarketV1 {
348
349
  ]);
349
350
  return [...erc20Requirements, ...(authTx ? [authTx] : [])];
350
351
  },
351
- buildTx: (requirementSignature) => (0, actions_1.marketV1RepayWithdrawCollateral)({
352
+ buildTx: (requirementSignature) => (0, index_js_1.marketV1RepayWithdrawCollateral)({
352
353
  market: {
353
354
  chainId: this.chainId,
354
355
  marketParams: this.marketParams,
@@ -368,41 +369,41 @@ class MorphoMarketV1 {
368
369
  };
369
370
  }
370
371
  supplyCollateralBorrow({ amount = 0n, userAddress, positionData, borrowAmount, nativeAmount, slippageTolerance = blue_sdk_1.DEFAULT_SLIPPAGE_TOLERANCE, reallocations, }) {
371
- (0, helpers_1.validateChainId)(this.client.viemClient.chain?.id, this.chainId);
372
- (0, helpers_1.validateUserAddress)(this.client.viemClient.account?.address, userAddress);
372
+ (0, index_js_2.validateChainId)(this.client.viemClient.chain?.id, this.chainId);
373
+ (0, index_js_2.validateUserAddress)(this.client.viemClient.account?.address, userAddress);
373
374
  if (amount < 0n) {
374
- throw new types_1.NonPositiveAssetAmountError(this.marketParams.collateralToken);
375
+ throw new index_js_3.NonPositiveAssetAmountError(this.marketParams.collateralToken);
375
376
  }
376
377
  if (nativeAmount !== undefined && nativeAmount < 0n) {
377
- throw new types_1.NegativeNativeAmountError(nativeAmount);
378
+ throw new index_js_3.NegativeNativeAmountError(nativeAmount);
378
379
  }
379
380
  if (borrowAmount <= 0n) {
380
- throw new types_1.NonPositiveBorrowAmountError(this.marketParams.id);
381
+ throw new index_js_3.NonPositiveBorrowAmountError(this.marketParams.id);
381
382
  }
382
383
  if (!positionData) {
383
- throw new types_1.MissingAccrualPositionError(this.marketParams.id);
384
+ throw new index_js_3.MissingAccrualPositionError(this.marketParams.id);
384
385
  }
385
- (0, helpers_1.validateAccrualPosition)({
386
+ (0, index_js_2.validateAccrualPosition)({
386
387
  positionData,
387
388
  expectedMarketId: this.marketParams.id,
388
389
  expectedUser: userAddress,
389
390
  });
390
391
  const totalCollateral = amount + (nativeAmount ?? 0n);
391
392
  if (totalCollateral === 0n) {
392
- throw new types_1.ZeroCollateralAmountError(this.marketParams.id);
393
+ throw new index_js_3.ZeroCollateralAmountError(this.marketParams.id);
393
394
  }
394
- (0, helpers_1.validateSlippageTolerance)(slippageTolerance);
395
+ (0, index_js_2.validateSlippageTolerance)(slippageTolerance);
395
396
  if (nativeAmount !== undefined && nativeAmount > 0n) {
396
- (0, helpers_1.validateNativeCollateral)(this.chainId, this.marketParams.collateralToken);
397
+ (0, index_js_2.validateNativeCollateral)(this.chainId, this.marketParams.collateralToken);
397
398
  }
398
- (0, helpers_1.validatePositionHealth)({
399
+ (0, index_js_2.validatePositionHealth)({
399
400
  positionData,
400
401
  additionalCollateral: totalCollateral,
401
402
  borrowAmount,
402
403
  marketId: this.marketParams.id,
403
404
  lltv: this.marketParams.lltv,
404
405
  });
405
- const minSharePrice = (0, helpers_1.computeMinBorrowSharePrice)({
406
+ const minSharePrice = (0, index_js_2.computeMinBorrowSharePrice)({
406
407
  borrowAmount,
407
408
  market: positionData.market,
408
409
  slippageTolerance,
@@ -410,7 +411,7 @@ class MorphoMarketV1 {
410
411
  return {
411
412
  getRequirements: async (params) => {
412
413
  const [erc20Requirements, authTx] = await Promise.all([
413
- (0, actions_1.getRequirements)(this.client.viemClient, {
414
+ (0, index_js_1.getRequirements)(this.client.viemClient, {
414
415
  address: this.marketParams.collateralToken,
415
416
  chainId: this.chainId,
416
417
  supportSignature: this.client.options.supportSignature,
@@ -418,7 +419,7 @@ class MorphoMarketV1 {
418
419
  useSimplePermit: params?.useSimplePermit,
419
420
  args: { amount, from: userAddress },
420
421
  }),
421
- (0, actions_1.getMorphoAuthorizationRequirement)({
422
+ (0, index_js_1.getMorphoAuthorizationRequirement)({
422
423
  viemClient: this.client.viemClient,
423
424
  chainId: this.chainId,
424
425
  userAddress,
@@ -426,7 +427,7 @@ class MorphoMarketV1 {
426
427
  ]);
427
428
  return [...erc20Requirements, ...(authTx ? [authTx] : [])];
428
429
  },
429
- buildTx: (requirementSignature) => (0, actions_1.marketV1SupplyCollateralBorrow)({
430
+ buildTx: (requirementSignature) => (0, index_js_1.marketV1SupplyCollateralBorrow)({
430
431
  market: {
431
432
  chainId: this.chainId,
432
433
  marketParams: this.marketParams,
@@ -445,21 +446,22 @@ class MorphoMarketV1 {
445
446
  }),
446
447
  };
447
448
  }
448
- async getReallocationData({ vaultAddresses, market, block, }) {
449
- (0, helpers_1.validateChainId)(this.client.viemClient.chain?.id, this.chainId);
450
- if (market.id !== this.marketParams.id) {
451
- throw new types_1.MarketIdMismatchError(market.id, this.marketParams.id);
452
- }
449
+ async getReallocationData({ vaultAddresses, block, }) {
450
+ (0, index_js_2.validateChainId)(this.client.viemClient.chain?.id, this.chainId);
453
451
  const client = this.client.viemClient;
454
452
  const fetchParams = {
455
453
  blockNumber: block.number,
456
454
  chainId: this.chainId,
457
455
  deployless: this.client.options.supportDeployless,
458
456
  };
459
- // Phase 1: Fetch all vaults in parallel to get their withdrawQueues.
460
- const vaults = await Promise.all(vaultAddresses.map((addr) => (0, blue_sdk_viem_1.fetchVault)(addr, client, fetchParams)));
461
- // Collect unique market IDs from all vault withdrawQueues + target market.
462
457
  const targetMarketId = this.marketParams.id;
458
+ // Phase 1: Fetch the target market and all vaults at `block.number` in
459
+ // parallel so every row of the resulting state comes from the same epoch
460
+ // and the planner never trusts a caller-owned target-market snapshot.
461
+ const [targetMarket, vaults] = await Promise.all([
462
+ (0, blue_sdk_viem_1.fetchMarket)(targetMarketId, client, fetchParams),
463
+ Promise.all(vaultAddresses.map((addr) => (0, blue_sdk_viem_1.fetchVault)(addr, client, fetchParams))),
464
+ ]);
463
465
  const allMarketIds = new Set([targetMarketId]);
464
466
  const vaultMarketPairs = [];
465
467
  for (const vault of vaults) {
@@ -475,7 +477,7 @@ class MorphoMarketV1 {
475
477
  }
476
478
  // Phase 2: Fetch all source markets, vault configs, and positions in parallel.
477
479
  const sourceMarketIds = [...allMarketIds].filter((mid) => mid !== targetMarketId);
478
- const loanToken = market.params.loanToken;
480
+ const loanToken = targetMarket.params.loanToken;
479
481
  const [markets, configs, positions, holdings] = await Promise.all([
480
482
  Promise.all(sourceMarketIds.map((mid) => (0, blue_sdk_viem_1.fetchMarket)(mid, client, fetchParams))),
481
483
  Promise.all(vaultMarketPairs.map(({ vault, marketId: mid }) => (0, blue_sdk_viem_1.fetchVaultMarketConfig)(vault, mid, client, fetchParams).then((config) => ({ vault, mid, config })))),
@@ -488,7 +490,7 @@ class MorphoMarketV1 {
488
490
  ]);
489
491
  // Assemble records for SimulationState.
490
492
  const marketsRecord = {
491
- [targetMarketId]: market,
493
+ [targetMarketId]: targetMarket,
492
494
  };
493
495
  for (const m of markets) {
494
496
  marketsRecord[m.id] = m;
@@ -520,7 +522,7 @@ class MorphoMarketV1 {
520
522
  });
521
523
  }
522
524
  getReallocations({ reallocationData, borrowAmount, options, }) {
523
- return (0, helpers_1.computeReallocations)({
525
+ return (0, index_js_2.computeReallocations)({
524
526
  reallocationData,
525
527
  marketId: this.marketParams.id,
526
528
  borrowAmount,
@@ -0,0 +1 @@
1
+ export * from "./vaultV1.js";
@@ -14,4 +14,4 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
14
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
- __exportStar(require("./marketV1"), exports);
17
+ __exportStar(require("./vaultV1.js"), exports);
@@ -1,8 +1,8 @@
1
1
  import { type AccrualVault, type AccrualVaultV2 } from "@morpho-org/blue-sdk";
2
2
  import { fetchAccrualVault } from "@morpho-org/blue-sdk-viem";
3
3
  import { type Address } from "viem";
4
- import { type DepositAmountArgs, type ERC20ApprovalAction, type MorphoClientType, type Requirement, type RequirementSignature, type Transaction, type VaultV1DepositAction, type VaultV1MigrateToV2Action, type VaultV1RedeemAction, type VaultV1WithdrawAction } from "../../types";
5
- import type { FetchParameters } from "../../types/data";
4
+ import type { FetchParameters } from "../../types/data.js";
5
+ import { type DepositAmountArgs, type ERC20ApprovalAction, type MorphoClientType, type Requirement, type RequirementSignature, type Transaction, type VaultV1DepositAction, type VaultV1MigrateToV2Action, type VaultV1RedeemAction, type VaultV1WithdrawAction } from "../../types/index.js";
6
6
  export interface VaultV1Actions {
7
7
  /**
8
8
  * Fetches the latest vault data with accrued interest.
@@ -85,9 +85,7 @@ export interface VaultV1Actions {
85
85
  slippageTolerance?: bigint;
86
86
  }) => {
87
87
  buildTx: (requirementSignature?: RequirementSignature) => Readonly<Transaction<VaultV1MigrateToV2Action>>;
88
- getRequirements: (params?: {
89
- useSimplePermit?: boolean;
90
- }) => Promise<(Readonly<Transaction<ERC20ApprovalAction>> | Requirement)[]>;
88
+ getRequirements: () => Promise<(Readonly<Transaction<ERC20ApprovalAction>> | Requirement)[]>;
91
89
  };
92
90
  }
93
91
  export declare class MorphoVaultV1 implements VaultV1Actions {
@@ -125,9 +123,7 @@ export declare class MorphoVaultV1 implements VaultV1Actions {
125
123
  shares: bigint;
126
124
  slippageTolerance?: bigint;
127
125
  }): {
128
- getRequirements: (params?: {
129
- useSimplePermit?: boolean;
130
- }) => Promise<(Requirement | Readonly<Transaction<ERC20ApprovalAction>>)[]>;
126
+ getRequirements: () => Promise<(Requirement | Readonly<Transaction<ERC20ApprovalAction>>)[]>;
131
127
  buildTx: (requirementSignature?: RequirementSignature) => Readonly<Transaction<VaultV1MigrateToV2Action>>;
132
128
  };
133
129
  }