@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,85 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getRequirementsPermit2 = void 0;
4
+ const blue_sdk_1 = require("@morpho-org/blue-sdk");
5
+ const morpho_ts_1 = require("@morpho-org/morpho-ts");
6
+ const encodeErc20Permit2_js_1 = require("./encode/encodeErc20Permit2.js");
7
+ const getRequirementsApproval_js_1 = require("./getRequirementsApproval.js");
8
+ /**
9
+ * Computes the Permit2 prerequisites for `GeneralAdapter1` to pull `amount` of `address`.
10
+ *
11
+ * Returns an empty array when the direct adapter allowance already covers `amount`. Otherwise
12
+ * emits two ordered prerequisites:
13
+ *
14
+ * 1. A classic ERC-20 approval to the Permit2 contract (infinite, if not already in place).
15
+ * 2. A Permit2 `Requirement` signed against `GeneralAdapter1` (skipped when the existing
16
+ * Permit2-managed allowance covers `amount` and is not about to expire within four hours).
17
+ *
18
+ * @param params.address - ERC-20 token address.
19
+ * @param params.chainId - The chain the bundle targets.
20
+ * @param params.permit2 - The Permit2 contract address for the chain.
21
+ * @param params.args.amount - Required token amount.
22
+ * @param params.allowancesPermit2 - The user's current allowance of `address` for the Permit2
23
+ * contract.
24
+ * @param params.allowancesGeneralAdapter - The user's current direct allowance of `address` for
25
+ * `GeneralAdapter1` (separate from the Permit2-managed allowance).
26
+ * @param params.allowanceGeneralAdapterPermit2 - The Permit2-managed allowance for
27
+ * `GeneralAdapter1` to spend `address`.
28
+ * @param params.allowanceGeneralAdapterExpiration - Expiration timestamp of the Permit2-managed
29
+ * allowance.
30
+ * @param params.nonce - The user's current Permit2 nonce for `(address, GeneralAdapter1)`.
31
+ * @returns Ordered list of approval transactions and/or `Requirement` objects to satisfy before
32
+ * bundling.
33
+ * @throws {ApprovalAmountLessThanSpendAmountError} from the inner approval helper when its
34
+ * bookkeeping invariants break (should not happen with the values this function passes).
35
+ * @example
36
+ * ```ts
37
+ * import { getChainAddresses } from "@morpho-org/blue-sdk";
38
+ * import { getRequirementsPermit2 } from "@morpho-org/morpho-sdk";
39
+ *
40
+ * const { permit2 } = getChainAddresses(1);
41
+ * if (!permit2) throw new Error("Permit2 not configured for this chain");
42
+ * const requirements = getRequirementsPermit2({
43
+ * address: USDC,
44
+ * chainId: 1,
45
+ * permit2,
46
+ * args: { amount: 1_000_000n },
47
+ * allowancesPermit2: 0n,
48
+ * allowancesGeneralAdapter: 0n,
49
+ * allowanceGeneralAdapterPermit2: 0n,
50
+ * allowanceGeneralAdapterExpiration: 0n,
51
+ * nonce: 0n,
52
+ * });
53
+ * // requirements satisfies (Readonly<Transaction<ERC20ApprovalAction> | Requirement>)[]
54
+ * ```
55
+ */
56
+ const getRequirementsPermit2 = (params) => {
57
+ const { address, chainId, permit2, args: { amount }, allowancesPermit2, allowancesGeneralAdapter, allowanceGeneralAdapterPermit2, allowanceGeneralAdapterExpiration, nonce, } = params;
58
+ if (allowancesGeneralAdapter >= amount) {
59
+ return [];
60
+ }
61
+ const requirements = [];
62
+ const approvalRequirements = (0, getRequirementsApproval_js_1.getRequirementsApproval)({
63
+ address,
64
+ chainId,
65
+ args: {
66
+ approvalAmount: blue_sdk_1.MathLib.MAX_UINT_160, // Always approve infinite.
67
+ spendAmount: amount,
68
+ spender: permit2,
69
+ },
70
+ allowances: allowancesPermit2,
71
+ });
72
+ requirements.push(...approvalRequirements);
73
+ if (allowanceGeneralAdapterPermit2 < amount ||
74
+ allowanceGeneralAdapterExpiration < morpho_ts_1.Time.timestamp() + morpho_ts_1.Time.s.from.h(4n)) {
75
+ requirements.push((0, encodeErc20Permit2_js_1.encodeErc20Permit2)({
76
+ token: address,
77
+ amount,
78
+ chainId,
79
+ nonce,
80
+ expiration: blue_sdk_1.MathLib.MAX_UINT_48, // Always approve indefinitely.
81
+ }));
82
+ }
83
+ return requirements;
84
+ };
85
+ exports.getRequirementsPermit2 = getRequirementsPermit2;
@@ -0,0 +1,6 @@
1
+ export * from "./encode/index.js";
2
+ export * from "./getMorphoAuthorizationRequirement.js";
3
+ export * from "./getRequirements.js";
4
+ export * from "./getRequirementsApproval.js";
5
+ export * from "./getRequirementsPermit.js";
6
+ export * from "./getRequirementsPermit2.js";
@@ -14,9 +14,9 @@ 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("./encode/index"), exports);
18
- __exportStar(require("./getMorphoAuthorizationRequirement"), exports);
19
- __exportStar(require("./getRequirements"), exports);
20
- __exportStar(require("./getRequirementsApproval"), exports);
21
- __exportStar(require("./getRequirementsPermit"), exports);
22
- __exportStar(require("./getRequirementsPermit2"), exports);
17
+ __exportStar(require("./encode/index.js"), exports);
18
+ __exportStar(require("./getMorphoAuthorizationRequirement.js"), exports);
19
+ __exportStar(require("./getRequirements.js"), exports);
20
+ __exportStar(require("./getRequirementsApproval.js"), exports);
21
+ __exportStar(require("./getRequirementsPermit.js"), exports);
22
+ __exportStar(require("./getRequirementsPermit2.js"), exports);
@@ -0,0 +1,72 @@
1
+ import { type Address } from "viem";
2
+ import { type DepositAmountArgs, type Metadata, type RequirementSignature, type Transaction, type VaultV1DepositAction } from "../../types/index.js";
3
+ /** Parameters for {@link vaultV1Deposit}. */
4
+ export interface VaultV1DepositParams {
5
+ vault: {
6
+ chainId: number;
7
+ address: Address;
8
+ asset: Address;
9
+ };
10
+ args: DepositAmountArgs & {
11
+ maxSharePrice: bigint;
12
+ recipient: Address;
13
+ requirementSignature?: RequirementSignature;
14
+ };
15
+ metadata?: Metadata;
16
+ }
17
+ /**
18
+ * Prepares a deposit transaction for a VaultV1 (MetaMorpho) contract.
19
+ *
20
+ * Routed through bundler3 to atomically execute the asset transfer and vault deposit. The
21
+ * `GeneralAdapter1` enforces `maxSharePrice` on-chain to prevent inflation attacks. Never bypass
22
+ * the general adapter.
23
+ *
24
+ * When `nativeAmount > 0`, that amount of native ETH is sent as `msg.value` to the bundler3
25
+ * multicall and wrapped into wNative via `GeneralAdapter1.wrapNative()`. The vault's underlying
26
+ * asset must be the chain's wrapped native token.
27
+ *
28
+ * @param params.vault.chainId - The chain the vault lives on.
29
+ * @param params.vault.address - The VaultV1 (MetaMorpho) address.
30
+ * @param params.vault.asset - The vault's underlying ERC-20 asset.
31
+ * @param params.args.amount - Amount of ERC-20 assets to deposit. At least one of `amount` or
32
+ * `nativeAmount` must be positive. Defaults to `0n`.
33
+ * @param params.args.maxSharePrice - Maximum acceptable share price (in RAY, slippage
34
+ * protection enforced on-chain by `GeneralAdapter1`).
35
+ * @param params.args.recipient - Address that receives the minted vault shares.
36
+ * @param params.args.requirementSignature - Optional pre-signed permit/permit2 approval. When
37
+ * absent, the bundle uses a plain `erc20TransferFrom` and assumes the user has already
38
+ * approved `GeneralAdapter1`.
39
+ * @param params.args.nativeAmount - Optional amount of native token to wrap into wNative for the
40
+ * deposit. Requires the vault asset to be the chain's wNative.
41
+ * @param params.metadata - Optional analytics metadata attached to the bundle.
42
+ * @returns A deep-frozen `Transaction<VaultV1DepositAction>` with `to`, `value`, `data`, and the
43
+ * typed `action` discriminator the simulation layer consumes.
44
+ * @throws {NonPositiveAssetAmountError} when `amount < 0n`.
45
+ * @throws {NonPositiveMaxSharePriceError} when `maxSharePrice <= 0n`.
46
+ * @throws {NegativeNativeAmountError} when `nativeAmount < 0n`.
47
+ * @throws {ChainWNativeMissingError} when `nativeAmount` is provided but the chain has no
48
+ * configured wNative.
49
+ * @throws {NativeAmountOnNonWNativeVaultError} when `nativeAmount` is provided but the vault
50
+ * asset is not the chain's wNative.
51
+ * @throws {DepositAssetMismatchError} from `getRequirementsAction` when `amount > 0n` and
52
+ * `requirementSignature` is provided and the signed asset differs from `vault.asset`. The
53
+ * signature is ignored on the native-only path (`amount === 0n` with `nativeAmount > 0n`).
54
+ * @throws {DepositAmountMismatchError} from `getRequirementsAction` when `amount > 0n` and
55
+ * `requirementSignature` is provided and the signed amount differs from `args.amount`.
56
+ * @throws {ZeroDepositAmountError} when both `amount` and `nativeAmount` resolve to zero.
57
+ * @example
58
+ * ```ts
59
+ * import { vaultV1Deposit } from "@morpho-org/morpho-sdk";
60
+ *
61
+ * const tx = vaultV1Deposit({
62
+ * vault: { chainId: 1, address: vaultAddress, asset: USDC },
63
+ * args: {
64
+ * amount: 1_000_000n,
65
+ * maxSharePrice: 1_010_000_000_000_000_000_000_000_000n, // RAY-scaled, 1.01x
66
+ * recipient: depositor,
67
+ * },
68
+ * });
69
+ * // tx satisfies Readonly<Transaction<VaultV1DepositAction>>
70
+ * ```
71
+ */
72
+ export declare const vaultV1Deposit: ({ vault: { chainId, address: vaultAddress, asset }, args: { amount, maxSharePrice, recipient, requirementSignature, nativeAmount, }, metadata, }: VaultV1DepositParams) => Readonly<Transaction<VaultV1DepositAction>>;
@@ -0,0 +1,146 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.vaultV1Deposit = void 0;
4
+ const blue_sdk_1 = require("@morpho-org/blue-sdk");
5
+ const bundler_sdk_viem_1 = require("@morpho-org/bundler-sdk-viem");
6
+ const morpho_ts_1 = require("@morpho-org/morpho-ts");
7
+ const viem_1 = require("viem");
8
+ const index_js_1 = require("../../helpers/index.js");
9
+ const index_js_2 = require("../../types/index.js");
10
+ const getRequirementsAction_js_1 = require("../requirements/getRequirementsAction.js");
11
+ /**
12
+ * Prepares a deposit transaction for a VaultV1 (MetaMorpho) contract.
13
+ *
14
+ * Routed through bundler3 to atomically execute the asset transfer and vault deposit. The
15
+ * `GeneralAdapter1` enforces `maxSharePrice` on-chain to prevent inflation attacks. Never bypass
16
+ * the general adapter.
17
+ *
18
+ * When `nativeAmount > 0`, that amount of native ETH is sent as `msg.value` to the bundler3
19
+ * multicall and wrapped into wNative via `GeneralAdapter1.wrapNative()`. The vault's underlying
20
+ * asset must be the chain's wrapped native token.
21
+ *
22
+ * @param params.vault.chainId - The chain the vault lives on.
23
+ * @param params.vault.address - The VaultV1 (MetaMorpho) address.
24
+ * @param params.vault.asset - The vault's underlying ERC-20 asset.
25
+ * @param params.args.amount - Amount of ERC-20 assets to deposit. At least one of `amount` or
26
+ * `nativeAmount` must be positive. Defaults to `0n`.
27
+ * @param params.args.maxSharePrice - Maximum acceptable share price (in RAY, slippage
28
+ * protection enforced on-chain by `GeneralAdapter1`).
29
+ * @param params.args.recipient - Address that receives the minted vault shares.
30
+ * @param params.args.requirementSignature - Optional pre-signed permit/permit2 approval. When
31
+ * absent, the bundle uses a plain `erc20TransferFrom` and assumes the user has already
32
+ * approved `GeneralAdapter1`.
33
+ * @param params.args.nativeAmount - Optional amount of native token to wrap into wNative for the
34
+ * deposit. Requires the vault asset to be the chain's wNative.
35
+ * @param params.metadata - Optional analytics metadata attached to the bundle.
36
+ * @returns A deep-frozen `Transaction<VaultV1DepositAction>` with `to`, `value`, `data`, and the
37
+ * typed `action` discriminator the simulation layer consumes.
38
+ * @throws {NonPositiveAssetAmountError} when `amount < 0n`.
39
+ * @throws {NonPositiveMaxSharePriceError} when `maxSharePrice <= 0n`.
40
+ * @throws {NegativeNativeAmountError} when `nativeAmount < 0n`.
41
+ * @throws {ChainWNativeMissingError} when `nativeAmount` is provided but the chain has no
42
+ * configured wNative.
43
+ * @throws {NativeAmountOnNonWNativeVaultError} when `nativeAmount` is provided but the vault
44
+ * asset is not the chain's wNative.
45
+ * @throws {DepositAssetMismatchError} from `getRequirementsAction` when `amount > 0n` and
46
+ * `requirementSignature` is provided and the signed asset differs from `vault.asset`. The
47
+ * signature is ignored on the native-only path (`amount === 0n` with `nativeAmount > 0n`).
48
+ * @throws {DepositAmountMismatchError} from `getRequirementsAction` when `amount > 0n` and
49
+ * `requirementSignature` is provided and the signed amount differs from `args.amount`.
50
+ * @throws {ZeroDepositAmountError} when both `amount` and `nativeAmount` resolve to zero.
51
+ * @example
52
+ * ```ts
53
+ * import { vaultV1Deposit } from "@morpho-org/morpho-sdk";
54
+ *
55
+ * const tx = vaultV1Deposit({
56
+ * vault: { chainId: 1, address: vaultAddress, asset: USDC },
57
+ * args: {
58
+ * amount: 1_000_000n,
59
+ * maxSharePrice: 1_010_000_000_000_000_000_000_000_000n, // RAY-scaled, 1.01x
60
+ * recipient: depositor,
61
+ * },
62
+ * });
63
+ * // tx satisfies Readonly<Transaction<VaultV1DepositAction>>
64
+ * ```
65
+ */
66
+ const vaultV1Deposit = ({ vault: { chainId, address: vaultAddress, asset }, args: { amount = 0n, maxSharePrice, recipient, requirementSignature, nativeAmount, }, metadata, }) => {
67
+ if (amount < 0n) {
68
+ throw new index_js_2.NonPositiveAssetAmountError(asset);
69
+ }
70
+ if (maxSharePrice <= 0n) {
71
+ throw new index_js_2.NonPositiveMaxSharePriceError(vaultAddress);
72
+ }
73
+ const actions = [];
74
+ const { bundler3: { generalAdapter1, bundler3 }, wNative, } = (0, blue_sdk_1.getChainAddresses)(chainId);
75
+ if (nativeAmount) {
76
+ if (nativeAmount < 0n) {
77
+ throw new index_js_2.NegativeNativeAmountError(nativeAmount);
78
+ }
79
+ if (!(0, morpho_ts_1.isDefined)(wNative)) {
80
+ throw new index_js_2.ChainWNativeMissingError(chainId);
81
+ }
82
+ if (!(0, viem_1.isAddressEqual)(asset, wNative)) {
83
+ throw new index_js_2.NativeAmountOnNonWNativeVaultError(asset, wNative);
84
+ }
85
+ actions.push(
86
+ // Transfers native token from Bundler3 to GeneralAdapter1 for wrapping.
87
+ {
88
+ type: "nativeTransfer",
89
+ args: [bundler3, generalAdapter1, nativeAmount, false /* skipRevert */],
90
+ }, {
91
+ type: "wrapNative",
92
+ args: [nativeAmount, generalAdapter1, false /* skipRevert */],
93
+ });
94
+ }
95
+ if (amount > 0n) {
96
+ if (requirementSignature) {
97
+ actions.push(...(0, getRequirementsAction_js_1.getRequirementsAction)({
98
+ chainId,
99
+ asset,
100
+ amount,
101
+ requirementSignature,
102
+ }));
103
+ }
104
+ else {
105
+ actions.push({
106
+ type: "erc20TransferFrom",
107
+ args: [asset, amount, generalAdapter1, false /* skipRevert */],
108
+ });
109
+ }
110
+ }
111
+ const totalAssets = amount + (nativeAmount ?? 0n);
112
+ if (totalAssets === 0n) {
113
+ throw new index_js_2.ZeroDepositAmountError(vaultAddress);
114
+ }
115
+ actions.push({
116
+ type: "erc4626Deposit",
117
+ args: [
118
+ vaultAddress,
119
+ totalAssets,
120
+ maxSharePrice,
121
+ recipient,
122
+ false /* skipRevert */,
123
+ ],
124
+ });
125
+ let tx = bundler_sdk_viem_1.BundlerAction.encodeBundle(chainId, actions);
126
+ if (nativeAmount) {
127
+ tx = { ...tx, value: nativeAmount };
128
+ }
129
+ if (metadata) {
130
+ tx = (0, index_js_1.addTransactionMetadata)(tx, metadata);
131
+ }
132
+ return (0, morpho_ts_1.deepFreeze)({
133
+ ...tx,
134
+ action: {
135
+ type: "vaultV1Deposit",
136
+ args: {
137
+ vault: vaultAddress,
138
+ amount,
139
+ maxSharePrice,
140
+ recipient,
141
+ nativeAmount,
142
+ },
143
+ },
144
+ });
145
+ };
146
+ exports.vaultV1Deposit = vaultV1Deposit;
@@ -0,0 +1,4 @@
1
+ export * from "./deposit.js";
2
+ export * from "./migrateToV2.js";
3
+ export * from "./redeem.js";
4
+ export * from "./withdraw.js";
@@ -14,7 +14,7 @@ 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("./deposit"), exports);
18
- __exportStar(require("./migrateToV2"), exports);
19
- __exportStar(require("./redeem"), exports);
20
- __exportStar(require("./withdraw"), exports);
17
+ __exportStar(require("./deposit.js"), exports);
18
+ __exportStar(require("./migrateToV2.js"), exports);
19
+ __exportStar(require("./redeem.js"), exports);
20
+ __exportStar(require("./withdraw.js"), exports);
@@ -0,0 +1,84 @@
1
+ import { type Address } from "viem";
2
+ import { type Metadata, type RequirementSignature, type Transaction, type VaultV1MigrateToV2Action } from "../../types/index.js";
3
+ /** Parameters for {@link vaultV1MigrateToV2}. */
4
+ export interface VaultV1MigrateToV2Params {
5
+ vault: {
6
+ chainId: number;
7
+ address: Address;
8
+ /** Underlying asset of the source V1 vault. */
9
+ asset: Address;
10
+ };
11
+ args: {
12
+ targetVault: Address;
13
+ /** Underlying asset of the target V2 vault. */
14
+ targetAsset: Address;
15
+ /** Number of V1 shares to migrate. */
16
+ shares: bigint;
17
+ /** Minimum acceptable share price for V1 redeem (slippage protection, in RAY). */
18
+ minSharePriceVaultV1: bigint;
19
+ /** Maximum acceptable share price for V2 deposit (inflation protection, in RAY). */
20
+ maxSharePriceVaultV2: bigint;
21
+ /** Receives the V2 vault shares. */
22
+ recipient: Address;
23
+ /** Pre-signed permit/permit2 approval for V1 share transfer. */
24
+ requirementSignature?: RequirementSignature;
25
+ };
26
+ metadata?: Metadata;
27
+ }
28
+ /**
29
+ * Prepares an atomic full-migration transaction from VaultV1 to VaultV2.
30
+ *
31
+ * Routed through bundler3: transfers V1 shares to `GeneralAdapter1` (via `erc20TransferFrom` or
32
+ * permit/permit2), redeems them via `erc4626Redeem` (GA1 redeems its own shares — no allowance
33
+ * check), then deposits the resulting assets into V2 via `erc4626Deposit`. All operations
34
+ * execute atomically in a single transaction.
35
+ *
36
+ * Prerequisite: the user must either approve `GeneralAdapter1` to spend their V1 vault shares
37
+ * (classic approve) or provide a pre-signed permit/permit2 via `requirementSignature`. Use
38
+ * `getRequirements()` on the entity to resolve the appropriate approval.
39
+ *
40
+ * @param params.vault.chainId - The chain the source vault lives on (used to resolve bundler
41
+ * addresses).
42
+ * @param params.vault.address - The source VaultV1 (MetaMorpho) address.
43
+ * @param params.vault.asset - The underlying asset of the source V1 vault.
44
+ * @param params.args.targetVault - The target VaultV2 address.
45
+ * @param params.args.targetAsset - The underlying asset of the target V2 vault. Must equal
46
+ * `vault.asset`.
47
+ * @param params.args.shares - Number of V1 shares to migrate.
48
+ * @param params.args.minSharePriceVaultV1 - Minimum V1 share price in RAY (slippage protection
49
+ * for the redeem leg).
50
+ * @param params.args.maxSharePriceVaultV2 - Maximum V2 share price in RAY (inflation protection
51
+ * for the deposit leg).
52
+ * @param params.args.recipient - Address that receives the V2 vault shares.
53
+ * @param params.args.requirementSignature - Optional pre-signed permit/permit2 for the V1 share
54
+ * transfer. When absent, the bundle falls back to a plain `erc20TransferFrom`.
55
+ * @param params.metadata - Optional analytics metadata attached to the bundle.
56
+ * @returns A deep-frozen `Transaction<VaultV1MigrateToV2Action>` with `to`, `value`, `data`, and
57
+ * the typed `action` discriminator the simulation layer consumes.
58
+ * @throws {VaultAssetMismatchError} when `targetAsset` differs from `vault.asset`.
59
+ * @throws {NonPositiveSharesAmountError} when `shares <= 0n`.
60
+ * @throws {NegativeMinSharePriceError} when `minSharePriceVaultV1 < 0n`.
61
+ * @throws {NonPositiveMaxSharePriceError} when `maxSharePriceVaultV2 <= 0n`.
62
+ * @throws {DepositAssetMismatchError} from `getRequirementsAction` when `requirementSignature`
63
+ * is provided and the signed asset differs from `vault.address` (the V1 share token).
64
+ * @throws {DepositAmountMismatchError} from `getRequirementsAction` when `requirementSignature`
65
+ * is provided and the signed amount differs from `args.shares`.
66
+ * @example
67
+ * ```ts
68
+ * import { vaultV1MigrateToV2 } from "@morpho-org/morpho-sdk";
69
+ *
70
+ * const tx = vaultV1MigrateToV2({
71
+ * vault: { chainId: 1, address: sourceVault, asset: USDC },
72
+ * args: {
73
+ * targetVault,
74
+ * targetAsset: USDC,
75
+ * shares: 1_000_000n,
76
+ * minSharePriceVaultV1: 0n, // disables redeem-leg slippage protection — production code should compute from source vault state + slippage tolerance
77
+ * maxSharePriceVaultV2: 1_010_000_000_000_000_000_000_000_000n, // RAY-scaled, 1.01x
78
+ * recipient,
79
+ * },
80
+ * });
81
+ * // tx satisfies Readonly<Transaction<VaultV1MigrateToV2Action>>
82
+ * ```
83
+ */
84
+ export declare const vaultV1MigrateToV2: ({ vault: { chainId, address: sourceVault, asset: sourceAsset }, args: { targetVault, targetAsset, shares, minSharePriceVaultV1, maxSharePriceVaultV2, recipient, requirementSignature, }, metadata, }: VaultV1MigrateToV2Params) => Readonly<Transaction<VaultV1MigrateToV2Action>>;
@@ -0,0 +1,143 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.vaultV1MigrateToV2 = void 0;
4
+ const blue_sdk_1 = require("@morpho-org/blue-sdk");
5
+ const bundler_sdk_viem_1 = require("@morpho-org/bundler-sdk-viem");
6
+ const morpho_ts_1 = require("@morpho-org/morpho-ts");
7
+ const viem_1 = require("viem");
8
+ const index_js_1 = require("../../helpers/index.js");
9
+ const index_js_2 = require("../../types/index.js");
10
+ const getRequirementsAction_js_1 = require("../requirements/getRequirementsAction.js");
11
+ /**
12
+ * Prepares an atomic full-migration transaction from VaultV1 to VaultV2.
13
+ *
14
+ * Routed through bundler3: transfers V1 shares to `GeneralAdapter1` (via `erc20TransferFrom` or
15
+ * permit/permit2), redeems them via `erc4626Redeem` (GA1 redeems its own shares — no allowance
16
+ * check), then deposits the resulting assets into V2 via `erc4626Deposit`. All operations
17
+ * execute atomically in a single transaction.
18
+ *
19
+ * Prerequisite: the user must either approve `GeneralAdapter1` to spend their V1 vault shares
20
+ * (classic approve) or provide a pre-signed permit/permit2 via `requirementSignature`. Use
21
+ * `getRequirements()` on the entity to resolve the appropriate approval.
22
+ *
23
+ * @param params.vault.chainId - The chain the source vault lives on (used to resolve bundler
24
+ * addresses).
25
+ * @param params.vault.address - The source VaultV1 (MetaMorpho) address.
26
+ * @param params.vault.asset - The underlying asset of the source V1 vault.
27
+ * @param params.args.targetVault - The target VaultV2 address.
28
+ * @param params.args.targetAsset - The underlying asset of the target V2 vault. Must equal
29
+ * `vault.asset`.
30
+ * @param params.args.shares - Number of V1 shares to migrate.
31
+ * @param params.args.minSharePriceVaultV1 - Minimum V1 share price in RAY (slippage protection
32
+ * for the redeem leg).
33
+ * @param params.args.maxSharePriceVaultV2 - Maximum V2 share price in RAY (inflation protection
34
+ * for the deposit leg).
35
+ * @param params.args.recipient - Address that receives the V2 vault shares.
36
+ * @param params.args.requirementSignature - Optional pre-signed permit/permit2 for the V1 share
37
+ * transfer. When absent, the bundle falls back to a plain `erc20TransferFrom`.
38
+ * @param params.metadata - Optional analytics metadata attached to the bundle.
39
+ * @returns A deep-frozen `Transaction<VaultV1MigrateToV2Action>` with `to`, `value`, `data`, and
40
+ * the typed `action` discriminator the simulation layer consumes.
41
+ * @throws {VaultAssetMismatchError} when `targetAsset` differs from `vault.asset`.
42
+ * @throws {NonPositiveSharesAmountError} when `shares <= 0n`.
43
+ * @throws {NegativeMinSharePriceError} when `minSharePriceVaultV1 < 0n`.
44
+ * @throws {NonPositiveMaxSharePriceError} when `maxSharePriceVaultV2 <= 0n`.
45
+ * @throws {DepositAssetMismatchError} from `getRequirementsAction` when `requirementSignature`
46
+ * is provided and the signed asset differs from `vault.address` (the V1 share token).
47
+ * @throws {DepositAmountMismatchError} from `getRequirementsAction` when `requirementSignature`
48
+ * is provided and the signed amount differs from `args.shares`.
49
+ * @example
50
+ * ```ts
51
+ * import { vaultV1MigrateToV2 } from "@morpho-org/morpho-sdk";
52
+ *
53
+ * const tx = vaultV1MigrateToV2({
54
+ * vault: { chainId: 1, address: sourceVault, asset: USDC },
55
+ * args: {
56
+ * targetVault,
57
+ * targetAsset: USDC,
58
+ * shares: 1_000_000n,
59
+ * minSharePriceVaultV1: 0n, // disables redeem-leg slippage protection — production code should compute from source vault state + slippage tolerance
60
+ * maxSharePriceVaultV2: 1_010_000_000_000_000_000_000_000_000n, // RAY-scaled, 1.01x
61
+ * recipient,
62
+ * },
63
+ * });
64
+ * // tx satisfies Readonly<Transaction<VaultV1MigrateToV2Action>>
65
+ * ```
66
+ */
67
+ const vaultV1MigrateToV2 = ({ vault: { chainId, address: sourceVault, asset: sourceAsset }, args: { targetVault, targetAsset, shares, minSharePriceVaultV1, maxSharePriceVaultV2, recipient, requirementSignature, }, metadata, }) => {
68
+ // Both bundle legs use maxUint256: an asset mismatch leaves the redeemed
69
+ // source asset stranded on GA1 while the user receives only dust shares.
70
+ if (!(0, viem_1.isAddressEqual)(sourceAsset, targetAsset)) {
71
+ throw new index_js_2.VaultAssetMismatchError(sourceAsset, targetAsset);
72
+ }
73
+ if (shares <= 0n) {
74
+ throw new index_js_2.NonPositiveSharesAmountError(sourceVault);
75
+ }
76
+ if (minSharePriceVaultV1 < 0n) {
77
+ throw new index_js_2.NegativeMinSharePriceError(sourceVault);
78
+ }
79
+ if (maxSharePriceVaultV2 <= 0n) {
80
+ throw new index_js_2.NonPositiveMaxSharePriceError(targetVault);
81
+ }
82
+ const { bundler3: { generalAdapter1 }, } = (0, blue_sdk_1.getChainAddresses)(chainId);
83
+ const actions = [];
84
+ // Transfer V1 shares from user to GA1.
85
+ // With a signature: permit/permit2 + transferFrom for the signed amount.
86
+ // Without: plain erc20TransferFrom for the specified shares amount.
87
+ if (requirementSignature) {
88
+ actions.push(...(0, getRequirementsAction_js_1.getRequirementsAction)({
89
+ chainId,
90
+ asset: sourceVault,
91
+ amount: shares,
92
+ requirementSignature,
93
+ }));
94
+ }
95
+ else {
96
+ actions.push({
97
+ type: "erc20TransferFrom",
98
+ args: [sourceVault, shares, generalAdapter1, false /* skipRevert */],
99
+ });
100
+ }
101
+ // GA1 redeems its own shares (owner = GA1, no allowance check).
102
+ actions.push({
103
+ type: "erc4626Redeem",
104
+ args: [
105
+ sourceVault,
106
+ viem_1.maxUint256,
107
+ minSharePriceVaultV1,
108
+ generalAdapter1,
109
+ generalAdapter1,
110
+ false /* skipRevert */,
111
+ ],
112
+ });
113
+ // Deposit all resulting assets into V2.
114
+ actions.push({
115
+ type: "erc4626Deposit",
116
+ args: [
117
+ targetVault,
118
+ viem_1.maxUint256,
119
+ maxSharePriceVaultV2,
120
+ recipient,
121
+ false /* skipRevert */,
122
+ ],
123
+ });
124
+ let tx = bundler_sdk_viem_1.BundlerAction.encodeBundle(chainId, actions);
125
+ if (metadata) {
126
+ tx = (0, index_js_1.addTransactionMetadata)(tx, metadata);
127
+ }
128
+ return (0, morpho_ts_1.deepFreeze)({
129
+ ...tx,
130
+ action: {
131
+ type: "vaultV1MigrateToV2",
132
+ args: {
133
+ sourceVault,
134
+ targetVault,
135
+ shares,
136
+ minSharePriceVaultV1,
137
+ maxSharePriceVaultV2,
138
+ recipient,
139
+ },
140
+ },
141
+ });
142
+ };
143
+ exports.vaultV1MigrateToV2 = vaultV1MigrateToV2;
@@ -0,0 +1,39 @@
1
+ import { type Address } from "viem";
2
+ import { type Metadata, type Transaction, type VaultV1RedeemAction } from "../../types/index.js";
3
+ /** Parameters for {@link vaultV1Redeem}. */
4
+ export interface VaultV1RedeemParams {
5
+ vault: {
6
+ address: Address;
7
+ };
8
+ args: {
9
+ shares: bigint;
10
+ recipient: Address;
11
+ onBehalf: Address;
12
+ };
13
+ metadata?: Metadata;
14
+ }
15
+ /**
16
+ * Prepares a redeem transaction for a VaultV1 (MetaMorpho) contract.
17
+ *
18
+ * Direct vault call — no bundler needed. Redeem has no inflation-attack surface.
19
+ *
20
+ * @param params.vault.address - The VaultV1 (MetaMorpho) address.
21
+ * @param params.args.shares - Amount of vault shares to redeem.
22
+ * @param params.args.recipient - Address that receives the redeemed assets.
23
+ * @param params.args.onBehalf - Address whose shares are burned.
24
+ * @param params.metadata - Optional analytics metadata attached to the transaction.
25
+ * @returns A deep-frozen `Transaction<VaultV1RedeemAction>` with `to`, `value`, `data`, and the
26
+ * typed `action` discriminator the simulation layer consumes.
27
+ * @throws {NonPositiveSharesAmountError} when `shares <= 0n`.
28
+ * @example
29
+ * ```ts
30
+ * import { vaultV1Redeem } from "@morpho-org/morpho-sdk";
31
+ *
32
+ * const tx = vaultV1Redeem({
33
+ * vault: { address: vaultAddress },
34
+ * args: { shares: 1_000_000n, recipient, onBehalf },
35
+ * });
36
+ * // tx satisfies Readonly<Transaction<VaultV1RedeemAction>>
37
+ * ```
38
+ */
39
+ export declare const vaultV1Redeem: ({ vault: { address: vaultAddress }, args: { shares, recipient, onBehalf }, metadata, }: VaultV1RedeemParams) => Readonly<Transaction<VaultV1RedeemAction>>;