@morpho-org/morpho-sdk 1.1.0 → 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 -0
  101. package/lib/{types → cjs/types}/error.js +46 -0
  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 -77
  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,529 @@
1
+ import { DEFAULT_SLIPPAGE_TOLERANCE, MathLib, } from "@morpho-org/blue-sdk";
2
+ import { fetchAccrualPosition, fetchHolding, fetchMarket, fetchPosition, fetchVault, fetchVaultMarketConfig, } from "@morpho-org/blue-sdk-viem";
3
+ import { Time } from "@morpho-org/morpho-ts";
4
+ import { SimulationState } from "@morpho-org/simulation-sdk";
5
+ import { getMorphoAuthorizationRequirement, getRequirements, marketV1Borrow, marketV1Repay, marketV1RepayWithdrawCollateral, marketV1SupplyCollateral, marketV1SupplyCollateralBorrow, marketV1WithdrawCollateral, } from "../../actions/index.js";
6
+ import { computeMaxRepaySharePrice, computeMinBorrowSharePrice, computeReallocations, validateAccrualPosition, validateChainId, validateNativeCollateral, validatePositionHealth, validatePositionHealthAfterWithdraw, validateRepayAmount, validateRepayShares, validateSlippageTolerance, validateUserAddress, } from "../../helpers/index.js";
7
+ import { MissingAccrualPositionError, MutuallyExclusiveRepayAmountsError, NegativeNativeAmountError, NonPositiveAssetAmountError, NonPositiveBorrowAmountError, NonPositiveRepayAmountError, NonPositiveWithdrawCollateralAmountError, WithdrawExceedsCollateralError, ZeroCollateralAmountError, } from "../../types/index.js";
8
+ export class MorphoMarketV1 {
9
+ client;
10
+ marketParams;
11
+ chainId;
12
+ // biome-ignore lint/complexity/useMaxParams: TODO refactor to ≤2 params
13
+ constructor(client, marketParams, chainId) {
14
+ this.client = client;
15
+ this.marketParams = marketParams;
16
+ this.chainId = chainId;
17
+ }
18
+ async getMarketData(parameters) {
19
+ validateChainId(this.client.viemClient.chain?.id, this.chainId);
20
+ return fetchMarket(this.marketParams.id, this.client.viemClient, {
21
+ ...parameters,
22
+ chainId: this.chainId,
23
+ deployless: this.client.options.supportDeployless,
24
+ });
25
+ }
26
+ async getPositionData(userAddress, parameters) {
27
+ validateChainId(this.client.viemClient.chain?.id, this.chainId);
28
+ return fetchAccrualPosition(userAddress, this.marketParams.id, this.client.viemClient, {
29
+ ...parameters,
30
+ deployless: this.client.options.supportDeployless,
31
+ chainId: this.chainId,
32
+ });
33
+ }
34
+ supplyCollateral({ amount = 0n, userAddress, nativeAmount, }) {
35
+ validateChainId(this.client.viemClient.chain?.id, this.chainId);
36
+ validateUserAddress(this.client.viemClient.account?.address, userAddress);
37
+ if (amount < 0n) {
38
+ throw new NonPositiveAssetAmountError(this.marketParams.collateralToken);
39
+ }
40
+ if (nativeAmount !== undefined && nativeAmount < 0n) {
41
+ throw new NegativeNativeAmountError(nativeAmount);
42
+ }
43
+ const totalCollateral = amount + (nativeAmount ?? 0n);
44
+ if (totalCollateral === 0n) {
45
+ throw new ZeroCollateralAmountError(this.marketParams.id);
46
+ }
47
+ if (nativeAmount !== undefined && nativeAmount > 0n) {
48
+ validateNativeCollateral(this.chainId, this.marketParams.collateralToken);
49
+ }
50
+ return {
51
+ getRequirements: (params) => getRequirements(this.client.viemClient, {
52
+ address: this.marketParams.collateralToken,
53
+ chainId: this.chainId,
54
+ supportSignature: this.client.options.supportSignature,
55
+ supportDeployless: this.client.options.supportDeployless,
56
+ useSimplePermit: params?.useSimplePermit,
57
+ args: { amount, from: userAddress },
58
+ }),
59
+ buildTx: (requirementSignature) => marketV1SupplyCollateral({
60
+ market: {
61
+ chainId: this.chainId,
62
+ marketParams: this.marketParams,
63
+ },
64
+ args: {
65
+ amount,
66
+ nativeAmount,
67
+ onBehalf: userAddress,
68
+ requirementSignature,
69
+ },
70
+ metadata: this.client.options.metadata,
71
+ }),
72
+ };
73
+ }
74
+ borrow({ amount, userAddress, positionData, slippageTolerance = DEFAULT_SLIPPAGE_TOLERANCE, reallocations, }) {
75
+ validateChainId(this.client.viemClient.chain?.id, this.chainId);
76
+ validateUserAddress(this.client.viemClient.account?.address, userAddress);
77
+ if (amount <= 0n) {
78
+ throw new NonPositiveBorrowAmountError(this.marketParams.id);
79
+ }
80
+ validateSlippageTolerance(slippageTolerance);
81
+ if (!positionData) {
82
+ throw new MissingAccrualPositionError(this.marketParams.id);
83
+ }
84
+ validateAccrualPosition({
85
+ positionData,
86
+ expectedMarketId: this.marketParams.id,
87
+ expectedUser: userAddress,
88
+ });
89
+ validatePositionHealth({
90
+ positionData,
91
+ additionalCollateral: 0n,
92
+ borrowAmount: amount,
93
+ marketId: this.marketParams.id,
94
+ lltv: this.marketParams.lltv,
95
+ });
96
+ const minSharePrice = computeMinBorrowSharePrice({
97
+ borrowAmount: amount,
98
+ market: positionData.market,
99
+ slippageTolerance,
100
+ });
101
+ return {
102
+ getRequirements: async () => {
103
+ const authTx = await getMorphoAuthorizationRequirement({
104
+ viemClient: this.client.viemClient,
105
+ chainId: this.chainId,
106
+ userAddress,
107
+ });
108
+ return authTx ? [authTx] : [];
109
+ },
110
+ buildTx: () => marketV1Borrow({
111
+ market: {
112
+ chainId: this.chainId,
113
+ marketParams: this.marketParams,
114
+ },
115
+ args: {
116
+ amount,
117
+ receiver: userAddress,
118
+ minSharePrice,
119
+ reallocations,
120
+ },
121
+ metadata: this.client.options.metadata,
122
+ }),
123
+ };
124
+ }
125
+ repay(params) {
126
+ validateChainId(this.client.viemClient.chain?.id, this.chainId);
127
+ validateUserAddress(this.client.viemClient.account?.address, params.userAddress);
128
+ const { userAddress, positionData, slippageTolerance = DEFAULT_SLIPPAGE_TOLERANCE, } = params;
129
+ if ("assets" in params && "shares" in params) {
130
+ throw new MutuallyExclusiveRepayAmountsError(this.marketParams.id);
131
+ }
132
+ const isSharesMode = "shares" in params;
133
+ if (isSharesMode) {
134
+ if (params.shares <= 0n) {
135
+ throw new NonPositiveRepayAmountError(this.marketParams.id);
136
+ }
137
+ }
138
+ else {
139
+ if (params.assets <= 0n) {
140
+ throw new NonPositiveRepayAmountError(this.marketParams.id);
141
+ }
142
+ }
143
+ validateSlippageTolerance(slippageTolerance);
144
+ if (!positionData) {
145
+ throw new MissingAccrualPositionError(this.marketParams.id);
146
+ }
147
+ validateAccrualPosition({
148
+ positionData,
149
+ expectedMarketId: this.marketParams.id,
150
+ expectedUser: userAddress,
151
+ });
152
+ let assets;
153
+ let shares;
154
+ let transferAmount;
155
+ if (isSharesMode) {
156
+ validateRepayShares({
157
+ positionData,
158
+ repayShares: params.shares,
159
+ marketId: this.marketParams.id,
160
+ });
161
+ assets = 0n;
162
+ shares = params.shares;
163
+ // Add slippage buffer to cover interest accrued between tx construction and execution.
164
+ // Without this, the on-chain repay amount may exceed the pre-transferred ERC20 amount.
165
+ const baseTransferAmount = positionData.market.toBorrowAssets(shares, "Up");
166
+ transferAmount = MathLib.wMulUp(baseTransferAmount, MathLib.WAD + slippageTolerance);
167
+ }
168
+ else {
169
+ validateRepayAmount({
170
+ positionData,
171
+ repayAssets: params.assets,
172
+ marketId: this.marketParams.id,
173
+ });
174
+ assets = params.assets;
175
+ shares = 0n;
176
+ transferAmount = params.assets;
177
+ }
178
+ const maxSharePrice = computeMaxRepaySharePrice({
179
+ repayAssets: assets,
180
+ repayShares: shares,
181
+ market: positionData.market,
182
+ slippageTolerance,
183
+ });
184
+ return {
185
+ getRequirements: (reqParams) => getRequirements(this.client.viemClient, {
186
+ address: this.marketParams.loanToken,
187
+ chainId: this.chainId,
188
+ supportSignature: this.client.options.supportSignature,
189
+ supportDeployless: this.client.options.supportDeployless,
190
+ useSimplePermit: reqParams?.useSimplePermit,
191
+ args: { amount: transferAmount, from: userAddress },
192
+ }),
193
+ buildTx: (requirementSignature) => marketV1Repay({
194
+ market: {
195
+ chainId: this.chainId,
196
+ marketParams: this.marketParams,
197
+ },
198
+ args: {
199
+ assets,
200
+ shares,
201
+ transferAmount,
202
+ onBehalf: userAddress,
203
+ receiver: userAddress,
204
+ maxSharePrice,
205
+ requirementSignature,
206
+ },
207
+ metadata: this.client.options.metadata,
208
+ }),
209
+ };
210
+ }
211
+ withdrawCollateral({ userAddress, amount, positionData, }) {
212
+ validateChainId(this.client.viemClient.chain?.id, this.chainId);
213
+ validateUserAddress(this.client.viemClient.account?.address, userAddress);
214
+ if (amount <= 0n) {
215
+ throw new NonPositiveWithdrawCollateralAmountError(this.marketParams.id);
216
+ }
217
+ if (!positionData) {
218
+ throw new MissingAccrualPositionError(this.marketParams.id);
219
+ }
220
+ validateAccrualPosition({
221
+ positionData,
222
+ expectedMarketId: this.marketParams.id,
223
+ expectedUser: userAddress,
224
+ });
225
+ if (amount > positionData.collateral) {
226
+ throw new WithdrawExceedsCollateralError({
227
+ withdrawAmount: amount,
228
+ available: positionData.collateral,
229
+ market: positionData.marketId,
230
+ });
231
+ }
232
+ validatePositionHealthAfterWithdraw({
233
+ positionData,
234
+ withdrawAmount: amount,
235
+ lltv: this.marketParams.lltv,
236
+ marketId: this.marketParams.id,
237
+ });
238
+ return {
239
+ buildTx: () => marketV1WithdrawCollateral({
240
+ market: {
241
+ chainId: this.chainId,
242
+ marketParams: this.marketParams,
243
+ },
244
+ args: {
245
+ amount,
246
+ onBehalf: userAddress,
247
+ receiver: userAddress,
248
+ },
249
+ metadata: this.client.options.metadata,
250
+ }),
251
+ };
252
+ }
253
+ repayWithdrawCollateral(params) {
254
+ validateChainId(this.client.viemClient.chain?.id, this.chainId);
255
+ validateUserAddress(this.client.viemClient.account?.address, params.userAddress);
256
+ const { userAddress, withdrawAmount, positionData, slippageTolerance = DEFAULT_SLIPPAGE_TOLERANCE, } = params;
257
+ if ("assets" in params && "shares" in params) {
258
+ throw new MutuallyExclusiveRepayAmountsError(this.marketParams.id);
259
+ }
260
+ const isSharesMode = "shares" in params;
261
+ if (isSharesMode) {
262
+ if (params.shares <= 0n) {
263
+ throw new NonPositiveRepayAmountError(this.marketParams.id);
264
+ }
265
+ }
266
+ else {
267
+ if (params.assets <= 0n) {
268
+ throw new NonPositiveRepayAmountError(this.marketParams.id);
269
+ }
270
+ }
271
+ if (withdrawAmount <= 0n) {
272
+ throw new NonPositiveWithdrawCollateralAmountError(this.marketParams.id);
273
+ }
274
+ validateSlippageTolerance(slippageTolerance);
275
+ if (!positionData) {
276
+ throw new MissingAccrualPositionError(this.marketParams.id);
277
+ }
278
+ validateAccrualPosition({
279
+ positionData,
280
+ expectedMarketId: this.marketParams.id,
281
+ expectedUser: userAddress,
282
+ });
283
+ let assets;
284
+ let shares;
285
+ let transferAmount;
286
+ if (isSharesMode) {
287
+ validateRepayShares({
288
+ positionData,
289
+ repayShares: params.shares,
290
+ marketId: this.marketParams.id,
291
+ });
292
+ assets = 0n;
293
+ shares = params.shares;
294
+ const baseTransferAmount = positionData.market.toBorrowAssets(shares, "Up");
295
+ transferAmount = MathLib.wMulUp(baseTransferAmount, MathLib.WAD + slippageTolerance);
296
+ }
297
+ else {
298
+ validateRepayAmount({
299
+ positionData,
300
+ repayAssets: params.assets,
301
+ marketId: this.marketParams.id,
302
+ });
303
+ assets = params.assets;
304
+ shares = 0n;
305
+ transferAmount = params.assets;
306
+ }
307
+ if (withdrawAmount > positionData.collateral) {
308
+ throw new WithdrawExceedsCollateralError({
309
+ withdrawAmount,
310
+ available: positionData.collateral,
311
+ market: positionData.marketId,
312
+ });
313
+ }
314
+ // +10 min accrual buffer: residual debt grows between build and execute.
315
+ const accrualTimestamp = MathLib.max(Time.timestamp(), positionData.market.lastUpdate) +
316
+ Time.s.from.min(10n);
317
+ const { position: positionAfterRepay } = positionData.repay(assets, shares, accrualTimestamp);
318
+ validatePositionHealthAfterWithdraw({
319
+ positionData: positionAfterRepay,
320
+ withdrawAmount,
321
+ lltv: this.marketParams.lltv,
322
+ marketId: this.marketParams.id,
323
+ });
324
+ const maxSharePrice = computeMaxRepaySharePrice({
325
+ repayAssets: assets,
326
+ repayShares: shares,
327
+ market: positionData.market,
328
+ slippageTolerance,
329
+ });
330
+ return {
331
+ getRequirements: async (reqParams) => {
332
+ const [erc20Requirements, authTx] = await Promise.all([
333
+ getRequirements(this.client.viemClient, {
334
+ address: this.marketParams.loanToken,
335
+ chainId: this.chainId,
336
+ supportSignature: this.client.options.supportSignature,
337
+ supportDeployless: this.client.options.supportDeployless,
338
+ useSimplePermit: reqParams?.useSimplePermit,
339
+ args: { amount: transferAmount, from: userAddress },
340
+ }),
341
+ getMorphoAuthorizationRequirement({
342
+ viemClient: this.client.viemClient,
343
+ chainId: this.chainId,
344
+ userAddress,
345
+ }),
346
+ ]);
347
+ return [...erc20Requirements, ...(authTx ? [authTx] : [])];
348
+ },
349
+ buildTx: (requirementSignature) => marketV1RepayWithdrawCollateral({
350
+ market: {
351
+ chainId: this.chainId,
352
+ marketParams: this.marketParams,
353
+ },
354
+ args: {
355
+ assets,
356
+ shares,
357
+ transferAmount,
358
+ withdrawAmount,
359
+ onBehalf: userAddress,
360
+ receiver: userAddress,
361
+ maxSharePrice,
362
+ requirementSignature,
363
+ },
364
+ metadata: this.client.options.metadata,
365
+ }),
366
+ };
367
+ }
368
+ supplyCollateralBorrow({ amount = 0n, userAddress, positionData, borrowAmount, nativeAmount, slippageTolerance = DEFAULT_SLIPPAGE_TOLERANCE, reallocations, }) {
369
+ validateChainId(this.client.viemClient.chain?.id, this.chainId);
370
+ validateUserAddress(this.client.viemClient.account?.address, userAddress);
371
+ if (amount < 0n) {
372
+ throw new NonPositiveAssetAmountError(this.marketParams.collateralToken);
373
+ }
374
+ if (nativeAmount !== undefined && nativeAmount < 0n) {
375
+ throw new NegativeNativeAmountError(nativeAmount);
376
+ }
377
+ if (borrowAmount <= 0n) {
378
+ throw new NonPositiveBorrowAmountError(this.marketParams.id);
379
+ }
380
+ if (!positionData) {
381
+ throw new MissingAccrualPositionError(this.marketParams.id);
382
+ }
383
+ validateAccrualPosition({
384
+ positionData,
385
+ expectedMarketId: this.marketParams.id,
386
+ expectedUser: userAddress,
387
+ });
388
+ const totalCollateral = amount + (nativeAmount ?? 0n);
389
+ if (totalCollateral === 0n) {
390
+ throw new ZeroCollateralAmountError(this.marketParams.id);
391
+ }
392
+ validateSlippageTolerance(slippageTolerance);
393
+ if (nativeAmount !== undefined && nativeAmount > 0n) {
394
+ validateNativeCollateral(this.chainId, this.marketParams.collateralToken);
395
+ }
396
+ validatePositionHealth({
397
+ positionData,
398
+ additionalCollateral: totalCollateral,
399
+ borrowAmount,
400
+ marketId: this.marketParams.id,
401
+ lltv: this.marketParams.lltv,
402
+ });
403
+ const minSharePrice = computeMinBorrowSharePrice({
404
+ borrowAmount,
405
+ market: positionData.market,
406
+ slippageTolerance,
407
+ });
408
+ return {
409
+ getRequirements: async (params) => {
410
+ const [erc20Requirements, authTx] = await Promise.all([
411
+ getRequirements(this.client.viemClient, {
412
+ address: this.marketParams.collateralToken,
413
+ chainId: this.chainId,
414
+ supportSignature: this.client.options.supportSignature,
415
+ supportDeployless: this.client.options.supportDeployless,
416
+ useSimplePermit: params?.useSimplePermit,
417
+ args: { amount, from: userAddress },
418
+ }),
419
+ getMorphoAuthorizationRequirement({
420
+ viemClient: this.client.viemClient,
421
+ chainId: this.chainId,
422
+ userAddress,
423
+ }),
424
+ ]);
425
+ return [...erc20Requirements, ...(authTx ? [authTx] : [])];
426
+ },
427
+ buildTx: (requirementSignature) => marketV1SupplyCollateralBorrow({
428
+ market: {
429
+ chainId: this.chainId,
430
+ marketParams: this.marketParams,
431
+ },
432
+ args: {
433
+ amount,
434
+ nativeAmount,
435
+ borrowAmount,
436
+ onBehalf: userAddress,
437
+ receiver: userAddress,
438
+ minSharePrice,
439
+ requirementSignature,
440
+ reallocations,
441
+ },
442
+ metadata: this.client.options.metadata,
443
+ }),
444
+ };
445
+ }
446
+ async getReallocationData({ vaultAddresses, block, }) {
447
+ validateChainId(this.client.viemClient.chain?.id, this.chainId);
448
+ const client = this.client.viemClient;
449
+ const fetchParams = {
450
+ blockNumber: block.number,
451
+ chainId: this.chainId,
452
+ deployless: this.client.options.supportDeployless,
453
+ };
454
+ const targetMarketId = this.marketParams.id;
455
+ // Phase 1: Fetch the target market and all vaults at `block.number` in
456
+ // parallel so every row of the resulting state comes from the same epoch
457
+ // and the planner never trusts a caller-owned target-market snapshot.
458
+ const [targetMarket, vaults] = await Promise.all([
459
+ fetchMarket(targetMarketId, client, fetchParams),
460
+ Promise.all(vaultAddresses.map((addr) => fetchVault(addr, client, fetchParams))),
461
+ ]);
462
+ const allMarketIds = new Set([targetMarketId]);
463
+ const vaultMarketPairs = [];
464
+ for (const vault of vaults) {
465
+ // Always include target market pair so its config/position is fetched
466
+ // even when the target market is only in the vault's supplyQueue.
467
+ vaultMarketPairs.push({ vault: vault.address, marketId: targetMarketId });
468
+ for (const mid of vault.withdrawQueue) {
469
+ allMarketIds.add(mid);
470
+ if (mid !== targetMarketId) {
471
+ vaultMarketPairs.push({ vault: vault.address, marketId: mid });
472
+ }
473
+ }
474
+ }
475
+ // Phase 2: Fetch all source markets, vault configs, and positions in parallel.
476
+ const sourceMarketIds = [...allMarketIds].filter((mid) => mid !== targetMarketId);
477
+ const loanToken = targetMarket.params.loanToken;
478
+ const [markets, configs, positions, holdings] = await Promise.all([
479
+ Promise.all(sourceMarketIds.map((mid) => fetchMarket(mid, client, fetchParams))),
480
+ Promise.all(vaultMarketPairs.map(({ vault, marketId: mid }) => fetchVaultMarketConfig(vault, mid, client, fetchParams).then((config) => ({ vault, mid, config })))),
481
+ Promise.all(vaultMarketPairs.map(({ vault, marketId: mid }) => fetchPosition(vault, mid, client, fetchParams).then((position) => ({
482
+ vault,
483
+ mid,
484
+ position,
485
+ })))),
486
+ Promise.all(vaultAddresses.map((addr) => fetchHolding(addr, loanToken, client, fetchParams))),
487
+ ]);
488
+ // Assemble records for SimulationState.
489
+ const marketsRecord = {
490
+ [targetMarketId]: targetMarket,
491
+ };
492
+ for (const m of markets) {
493
+ marketsRecord[m.id] = m;
494
+ }
495
+ const vaultsRecord = {};
496
+ for (const v of vaults) {
497
+ vaultsRecord[v.address] = v;
498
+ }
499
+ const vaultMarketConfigsRecord = {};
500
+ for (const { vault, mid, config } of configs) {
501
+ (vaultMarketConfigsRecord[vault] ??= {})[mid] = config;
502
+ }
503
+ const positionsRecord = {};
504
+ for (const { vault, mid, position } of positions) {
505
+ (positionsRecord[vault] ??= {})[mid] = position;
506
+ }
507
+ const holdingsRecord = {};
508
+ for (const holding of holdings) {
509
+ (holdingsRecord[holding.user] ??= {})[holding.token] = holding;
510
+ }
511
+ return new SimulationState({
512
+ chainId: this.chainId,
513
+ block,
514
+ markets: marketsRecord,
515
+ vaults: vaultsRecord,
516
+ vaultMarketConfigs: vaultMarketConfigsRecord,
517
+ positions: positionsRecord,
518
+ holdings: holdingsRecord,
519
+ });
520
+ }
521
+ getReallocations({ reallocationData, borrowAmount, options, }) {
522
+ return computeReallocations({
523
+ reallocationData,
524
+ marketId: this.marketParams.id,
525
+ borrowAmount,
526
+ options: { enabled: true, ...options },
527
+ });
528
+ }
529
+ }
@@ -0,0 +1 @@
1
+ export * from "./vaultV1.js";
@@ -0,0 +1 @@
1
+ export * from "./vaultV1.js";
@@ -0,0 +1,129 @@
1
+ import { type AccrualVault, type AccrualVaultV2 } from "@morpho-org/blue-sdk";
2
+ import { fetchAccrualVault } from "@morpho-org/blue-sdk-viem";
3
+ import { type Address } from "viem";
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
+ export interface VaultV1Actions {
7
+ /**
8
+ * Fetches the latest vault data with accrued interest.
9
+ *
10
+ * @param {FetchParameters} [parameters] - Optional fetch parameters (block number, state overrides, etc.).
11
+ * @returns {Promise<Awaited<ReturnType<typeof fetchAccrualVault>>>} The latest accrued vault data.
12
+ */
13
+ getData: (parameters?: FetchParameters) => Promise<Awaited<ReturnType<typeof fetchAccrualVault>>>;
14
+ /**
15
+ * Prepares a deposit into a VaultV1 (MetaMorpho) contract.
16
+ *
17
+ * Uses pre-fetched accrual vault data to compute `maxSharePrice` with slippage tolerance,
18
+ * then returns `buildTx` and `getRequirements` for lazy evaluation.
19
+ *
20
+ * @param {Object} params - The deposit parameters.
21
+ * @param {bigint} params.amount - Amount of assets to deposit.
22
+ * @param {Address} params.userAddress - User address initiating the deposit.
23
+ * @param {AccrualVault} params.accrualVault - Pre-fetched vault data with asset address and share conversion.
24
+ * @param {bigint} [params.slippageTolerance=DEFAULT_SLIPPAGE_TOLERANCE] - Slippage tolerance (default 0.03%, max 10%).
25
+ * @param {bigint} [params.nativeAmount] - Amount of native ETH to wrap into WETH. Vault asset must be wNative.
26
+ * @returns {Object} Object with `buildTx` and `getRequirements`.
27
+ */
28
+ deposit: (params: {
29
+ userAddress: Address;
30
+ accrualVault: AccrualVault;
31
+ slippageTolerance?: bigint;
32
+ } & DepositAmountArgs) => {
33
+ buildTx: (requirementSignature?: RequirementSignature) => Readonly<Transaction<VaultV1DepositAction>>;
34
+ getRequirements: (params?: {
35
+ useSimplePermit?: boolean;
36
+ }) => Promise<(Readonly<Transaction<ERC20ApprovalAction>> | Requirement)[]>;
37
+ };
38
+ /**
39
+ * Prepares a withdraw from a VaultV1 (MetaMorpho) contract.
40
+ *
41
+ * @param {Object} params - The withdraw parameters.
42
+ * @param {bigint} params.amount - Amount of assets to withdraw.
43
+ * @param {Address} params.userAddress - User address initiating the withdraw.
44
+ * @returns {Object} Object with `buildTx`.
45
+ */
46
+ withdraw: (params: {
47
+ amount: bigint;
48
+ userAddress: Address;
49
+ }) => {
50
+ buildTx: () => Readonly<Transaction<VaultV1WithdrawAction>>;
51
+ };
52
+ /**
53
+ * Prepares a redeem from a VaultV1 (MetaMorpho) contract.
54
+ *
55
+ * @param {Object} params - The redeem parameters.
56
+ * @param {bigint} params.shares - Amount of shares to redeem.
57
+ * @param {Address} params.userAddress - User address initiating the redeem.
58
+ * @returns {Object} Object with `buildTx`.
59
+ */
60
+ redeem: (params: {
61
+ shares: bigint;
62
+ userAddress: Address;
63
+ }) => {
64
+ buildTx: () => Readonly<Transaction<VaultV1RedeemAction>>;
65
+ };
66
+ /**
67
+ * Prepares a full migration from VaultV1 to VaultV2.
68
+ *
69
+ * Redeems all V1 shares and atomically deposits the resulting assets into V2
70
+ * via bundler3. Computes slippage-protected share prices for both legs.
71
+ *
72
+ * @param {Object} params - The migration parameters.
73
+ * @param {Address} params.userAddress - User address initiating the migration.
74
+ * @param {AccrualVault} params.sourceVault - Pre-fetched V1 vault data.
75
+ * @param {AccrualVaultV2} params.targetVault - Pre-fetched V2 vault data.
76
+ * @param {bigint} params.shares - User's V1 share balance to migrate.
77
+ * @param {bigint} [params.slippageTolerance=DEFAULT_SLIPPAGE_TOLERANCE] - Slippage tolerance (default 0.03%, max 10%).
78
+ * @returns {Object} Object with `buildTx` and `getRequirements`.
79
+ */
80
+ migrateToV2: (params: {
81
+ userAddress: Address;
82
+ sourceVault: AccrualVault;
83
+ targetVault: AccrualVaultV2;
84
+ shares: bigint;
85
+ slippageTolerance?: bigint;
86
+ }) => {
87
+ buildTx: (requirementSignature?: RequirementSignature) => Readonly<Transaction<VaultV1MigrateToV2Action>>;
88
+ getRequirements: () => Promise<(Readonly<Transaction<ERC20ApprovalAction>> | Requirement)[]>;
89
+ };
90
+ }
91
+ export declare class MorphoVaultV1 implements VaultV1Actions {
92
+ private readonly client;
93
+ private readonly vault;
94
+ private readonly chainId;
95
+ constructor(client: MorphoClientType, vault: Address, chainId: number);
96
+ getData(parameters?: FetchParameters): Promise<AccrualVault>;
97
+ deposit({ amount, userAddress, accrualVault, slippageTolerance, nativeAmount, }: {
98
+ userAddress: Address;
99
+ accrualVault: AccrualVault;
100
+ slippageTolerance?: bigint;
101
+ } & DepositAmountArgs): {
102
+ getRequirements: (params?: {
103
+ useSimplePermit?: boolean;
104
+ }) => Promise<(Requirement | Readonly<Transaction<ERC20ApprovalAction>>)[]>;
105
+ buildTx: (requirementSignature?: RequirementSignature) => Readonly<Transaction<VaultV1DepositAction>>;
106
+ };
107
+ withdraw({ amount, userAddress }: {
108
+ amount: bigint;
109
+ userAddress: Address;
110
+ }): {
111
+ buildTx: () => Readonly<Transaction<VaultV1WithdrawAction>>;
112
+ };
113
+ redeem({ shares, userAddress }: {
114
+ shares: bigint;
115
+ userAddress: Address;
116
+ }): {
117
+ buildTx: () => Readonly<Transaction<VaultV1RedeemAction>>;
118
+ };
119
+ migrateToV2({ userAddress, sourceVault, targetVault, shares, slippageTolerance, }: {
120
+ userAddress: Address;
121
+ sourceVault: AccrualVault;
122
+ targetVault: AccrualVaultV2;
123
+ shares: bigint;
124
+ slippageTolerance?: bigint;
125
+ }): {
126
+ getRequirements: () => Promise<(Requirement | Readonly<Transaction<ERC20ApprovalAction>>)[]>;
127
+ buildTx: (requirementSignature?: RequirementSignature) => Readonly<Transaction<VaultV1MigrateToV2Action>>;
128
+ };
129
+ }