@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
package/LICENSE CHANGED
@@ -1,6 +1,6 @@
1
1
  MIT License
2
2
 
3
- Copyright (c) 2026 Morpho Association
3
+ Copyright (c) 2024 Morpho Association
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
@@ -18,4 +18,4 @@ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
18
  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
19
  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
20
  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
- SOFTWARE.
21
+ SOFTWARE.
package/README.md CHANGED
@@ -5,6 +5,8 @@
5
5
  [![License: MIT](https://img.shields.io/badge/License-MIT-green.svg)](./LICENSE)
6
6
  [![CI](https://github.com/morpho-org/morpho-sdk/actions/workflows/ci.yml/badge.svg)](https://github.com/morpho-org/morpho-sdk/actions/workflows/ci.yml)
7
7
 
8
+ ## Overview
9
+
8
10
  > **The abstraction layer that simplifies Morpho protocol**
9
11
 
10
12
  Build transactions for **VaultV1** (MetaMorpho), **VaultV2**, and **MarketV1** (Morpho Blue) on EVM-compatible chains.
@@ -15,7 +17,9 @@ Build transactions for **VaultV1** (MetaMorpho), **VaultV2**, and **MarketV1** (
15
17
  pnpm add @morpho-org/morpho-sdk
16
18
  ```
17
19
 
18
- ## Entities & Actions
20
+ ## Usage
21
+
22
+ ### Entities & Actions
19
23
 
20
24
  | Entity | Action | Route | Why |
21
25
  | ------------ | ------------------------- | ------------------------- | --------------------------------------------------------------------------------------------------- |
@@ -34,7 +38,7 @@ pnpm add @morpho-org/morpho-sdk
34
38
  | | `withdrawCollateral` | Direct Morpho call | No bundler overhead. Validates position health after withdrawal. |
35
39
  | | `repayWithdrawCollateral` | Bundler (general adapter) | Atomic repay + withdraw. Bundle order matters: repay first, then withdraw. |
36
40
 
37
- ## The `getRequirements` flow
41
+ ### The `getRequirements` flow
38
42
 
39
43
  Every action that touches a user's tokens or positions returns two things:
40
44
 
@@ -62,7 +66,7 @@ const requirements = await getRequirements();
62
66
  const tx = buildTx(permitSignature);
63
67
  ```
64
68
 
65
- ## Integration invariant — builder = signer
69
+ ### Integration invariant — builder = signer
66
70
 
67
71
  **`userAddress` MUST equal the connected account on the viem client used to build the tx, and that same client MUST sign it.** Enforced by `validateUserAddress` (throws `MissingClientPropertyError` / `AddressMismatchError`); critical for `repayWithdrawCollateral`, whose bundle mixes explicit `onBehalf` (repay) with implicit `msg.sender` (transfer-from + withdraw) — see [BUNDLER3.md](./BUNDLER3.md#other-pitfalls).
68
72
 
@@ -81,7 +85,7 @@ const tx = buildTx(permitSignature);
81
85
  | | `borrow` | Bundler (general adapter) | `morphoBorrow` with `minSharePrice` slippage protection. Requires GA1 auth. Supports reallocations. |
82
86
  | | `supplyCollateralBorrow` | Bundler (general adapter) | Atomic supply + borrow. LLTV buffer prevents instant liquidation. Supports reallocations. |
83
87
 
84
- ## VaultV2
88
+ ### VaultV2
85
89
 
86
90
  ```typescript
87
91
  import { MorphoClient } from "@morpho-org/morpho-sdk";
@@ -94,7 +98,7 @@ const morpho = new MorphoClient(viemClient);
94
98
  const vault = morpho.vaultV2("0xVault...", 1);
95
99
  ```
96
100
 
97
- ### Deposit
101
+ #### Deposit
98
102
 
99
103
  ```typescript
100
104
  const { buildTx, getRequirements } = await vault.deposit({
@@ -106,7 +110,7 @@ const requirements = await getRequirements();
106
110
  const tx = buildTx(requirementSignature);
107
111
  ```
108
112
 
109
- #### Deposit with native token wrapping
113
+ ##### Deposit with native token wrapping
110
114
 
111
115
  For vaults whose underlying asset is wNative, you can deposit native token that will be automatically wrapped:
112
116
 
@@ -127,7 +131,7 @@ const { buildTx, getRequirements } = await vault.deposit({
127
131
 
128
132
  The bundler atomically transfers native token, wraps it to wNative, and deposits alongside any ERC-20 amount. The transaction's `value` field is set to `nativeAmount`.
129
133
 
130
- ### Withdraw
134
+ #### Withdraw
131
135
 
132
136
  ```typescript
133
137
  const { buildTx } = vault.withdraw({
@@ -138,7 +142,7 @@ const { buildTx } = vault.withdraw({
138
142
  const tx = buildTx();
139
143
  ```
140
144
 
141
- ### Redeem
145
+ #### Redeem
142
146
 
143
147
  ```typescript
144
148
  const { buildTx } = vault.redeem({
@@ -149,7 +153,7 @@ const { buildTx } = vault.redeem({
149
153
  const tx = buildTx();
150
154
  ```
151
155
 
152
- ### Force Withdraw
156
+ #### Force Withdraw
153
157
 
154
158
  ```typescript
155
159
  const { buildTx } = vault.forceWithdraw({
@@ -161,7 +165,7 @@ const { buildTx } = vault.forceWithdraw({
161
165
  const tx = buildTx();
162
166
  ```
163
167
 
164
- ### Force Redeem
168
+ #### Force Redeem
165
169
 
166
170
  ```typescript
167
171
  const { buildTx } = vault.forceRedeem({
@@ -173,13 +177,13 @@ const { buildTx } = vault.forceRedeem({
173
177
  const tx = buildTx();
174
178
  ```
175
179
 
176
- ## VaultV1
180
+ ### VaultV1
177
181
 
178
182
  ```typescript
179
183
  const vault = morpho.vaultV1("0xVault...", 1);
180
184
  ```
181
185
 
182
- ### Deposit
186
+ #### Deposit
183
187
 
184
188
  ```typescript
185
189
  const { buildTx, getRequirements } = await vault.deposit({
@@ -191,7 +195,7 @@ const requirements = await getRequirements();
191
195
  const tx = buildTx(requirementSignature);
192
196
  ```
193
197
 
194
- ### Withdraw
198
+ #### Withdraw
195
199
 
196
200
  ```typescript
197
201
  const { buildTx } = vault.withdraw({
@@ -202,7 +206,7 @@ const { buildTx } = vault.withdraw({
202
206
  const tx = buildTx();
203
207
  ```
204
208
 
205
- ### Redeem
209
+ #### Redeem
206
210
 
207
211
  ```typescript
208
212
  const { buildTx } = vault.redeem({
@@ -213,7 +217,7 @@ const { buildTx } = vault.redeem({
213
217
  const tx = buildTx();
214
218
  ```
215
219
 
216
- ### Migrate to V2
220
+ #### Migrate to V2
217
221
 
218
222
  Atomically migrate a full position from a VaultV1 (MetaMorpho) vault into a VaultV2 vault. The bundler redeems the V1 shares and deposits the resulting assets into V2 in a single transaction. Both vaults must share the same underlying asset.
219
223
 
@@ -232,7 +236,7 @@ const requirements = await getRequirements();
232
236
  const tx = buildTx(requirementSignature);
233
237
  ```
234
238
 
235
- ## MarketV1
239
+ ### MarketV1
236
240
 
237
241
  ```typescript
238
242
  const market = morpho.marketV1(
@@ -247,7 +251,7 @@ const market = morpho.marketV1(
247
251
  );
248
252
  ```
249
253
 
250
- ### Supply Collateral
254
+ #### Supply Collateral
251
255
 
252
256
  ```typescript
253
257
  const { buildTx, getRequirements } = market.supplyCollateral({
@@ -259,7 +263,7 @@ const requirements = await getRequirements();
259
263
  const tx = buildTx(requirementSignature);
260
264
  ```
261
265
 
262
- ### Borrow
266
+ #### Borrow
263
267
 
264
268
  ```typescript
265
269
  const positionData = await market.getPositionData("0xUser...");
@@ -274,7 +278,7 @@ const requirements = await getRequirements();
274
278
  const tx = buildTx();
275
279
  ```
276
280
 
277
- ### Supply Collateral & Borrow
281
+ #### Supply Collateral & Borrow
278
282
 
279
283
  ```typescript
280
284
  const positionData = await market.getPositionData("0xUser...");
@@ -290,7 +294,7 @@ const requirements = await getRequirements();
290
294
  const tx = buildTx(requirementSignature);
291
295
  ```
292
296
 
293
- ### Repay
297
+ #### Repay
294
298
 
295
299
  Two modes depending on whether the caller specifies `assets` (partial repay) or `shares` (full repay, immune to interest accrual between quote and inclusion):
296
300
 
@@ -317,7 +321,7 @@ const tx = buildTx(requirementSignature);
317
321
 
318
322
  Repay does **not** require Morpho authorization (it only requires a loan token approval for `GeneralAdapter1`).
319
323
 
320
- ### Withdraw Collateral
324
+ #### Withdraw Collateral
321
325
 
322
326
  ```typescript
323
327
  const positionData = await market.getPositionData("0xUser...");
@@ -333,7 +337,7 @@ const tx = buildTx();
333
337
 
334
338
  Direct call to `morpho.withdrawCollateral()` — no bundler, no `GeneralAdapter1` authorization needed. The SDK validates position health after withdrawal against the LLTV buffer to prevent instant liquidation.
335
339
 
336
- ### Repay & Withdraw Collateral
340
+ #### Repay & Withdraw Collateral
337
341
 
338
342
  ```typescript
339
343
  const positionData = await market.getPositionData("0xUser...");
@@ -351,7 +355,7 @@ const tx = buildTx(requirementSignature);
351
355
 
352
356
  Atomically bundles repay → withdraw collateral via bundler3. Bundle order is critical: repay runs first to reduce debt, then withdraw. Requires both a loan token approval (for repay) and a Morpho authorization (for withdraw). The SDK validates combined position health by simulating the repay before checking withdrawal safety.
353
357
 
354
- ### Borrow with Shared Liquidity (Reallocations)
358
+ #### Borrow with Shared Liquidity (Reallocations)
355
359
 
356
360
  When a market lacks sufficient liquidity, you can reallocate liquidity from other markets managed by MetaMorpho Vaults via the **PublicAllocator** contract:
357
361
 
@@ -398,7 +402,7 @@ const { buildTx, getRequirements } = market.supplyCollateralBorrow({
398
402
  });
399
403
  ```
400
404
 
401
- ## Architecture
405
+ ### Architecture
402
406
 
403
407
  ```mermaid
404
408
  graph LR
@@ -467,7 +471,7 @@ graph LR
467
471
  style PA fill:#fff9c4,stroke:#f9a825
468
472
  ```
469
473
 
470
- ## Local Development
474
+ ## Development
471
475
 
472
476
  Link this package to your app for local debugging:
473
477
 
@@ -483,14 +487,8 @@ In your other project:
483
487
  pnpm link @morpho-org/morpho-sdk
484
488
  ```
485
489
 
486
- ## Contributing
487
-
488
- Contributions are welcome. See [CONTRIBUTING.md](./CONTRIBUTING.md) for development setup, code style, and the PR workflow.
489
-
490
- ## Security
491
-
492
- To report a vulnerability, see [SECURITY.md](./SECURITY.md). **Please do not open a public issue for security reports.**
490
+ Contribute from the monorepo root. See [CONTRIBUTING.md](../../CONTRIBUTING.md) for setup, checks, and package workflow. Report vulnerabilities through [SECURITY.md](../../SECURITY.md).
493
491
 
494
492
  ## License
495
493
 
496
- MIT — see [LICENSE](./LICENSE).
494
+ MIT. See [LICENSE](./LICENSE).
@@ -0,0 +1,4 @@
1
+ export * from "./marketV1/index.js";
2
+ export * from "./requirements/index.js";
3
+ export * from "./vaultV1/index.js";
4
+ export * from "./vaultV2/index.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("./marketV1"), exports);
18
- __exportStar(require("./requirements"), exports);
19
- __exportStar(require("./vaultV1"), exports);
20
- __exportStar(require("./vaultV2"), exports);
17
+ __exportStar(require("./marketV1/index.js"), exports);
18
+ __exportStar(require("./requirements/index.js"), exports);
19
+ __exportStar(require("./vaultV1/index.js"), exports);
20
+ __exportStar(require("./vaultV2/index.js"), exports);
@@ -0,0 +1,69 @@
1
+ import type { MarketParams } from "@morpho-org/blue-sdk";
2
+ import type { Address } from "viem";
3
+ import { type MarketV1BorrowAction, type Metadata, type Transaction, type VaultReallocation } from "../../types/index.js";
4
+ /** Parameters for {@link marketV1Borrow}. */
5
+ export interface MarketV1BorrowParams {
6
+ market: {
7
+ readonly chainId: number;
8
+ readonly marketParams: MarketParams;
9
+ };
10
+ args: {
11
+ amount: bigint;
12
+ receiver: Address;
13
+ /** Minimum borrow share price (in ray). Protects against share price manipulation. */
14
+ minSharePrice: bigint;
15
+ /** Vault reallocations to execute before borrowing (computed by entity). */
16
+ reallocations?: readonly VaultReallocation[];
17
+ };
18
+ metadata?: Metadata;
19
+ }
20
+ /**
21
+ * Prepares a borrow transaction for a Morpho Blue market.
22
+ *
23
+ * Routed through bundler3 via `morphoBorrow`. The bundler uses the transaction initiator as
24
+ * `onBehalf`. Uses `minSharePrice` to protect against share price manipulation between
25
+ * transaction construction and execution.
26
+ *
27
+ * When `reallocations` are provided, `reallocateTo` actions are prepended to the bundle, moving
28
+ * liquidity from other markets via the PublicAllocator before borrowing. Reallocation fees
29
+ * accumulate in `tx.value`.
30
+ *
31
+ * @param params.market.chainId - The chain the market lives on.
32
+ * @param params.market.marketParams - Market params (loanToken, collateralToken, oracle, irm, lltv).
33
+ * @param params.args.amount - Loan asset amount to borrow, in the loan token's smallest unit.
34
+ * @param params.args.receiver - Address that receives the borrowed assets.
35
+ * @param params.args.minSharePrice - Minimum borrow share price (in ray). Slippage protection.
36
+ * @param params.args.reallocations - Optional vault reallocations to execute before borrowing,
37
+ * computed by the entity layer.
38
+ * @param params.metadata - Optional analytics metadata attached to the bundle.
39
+ * @returns A deep-frozen `Transaction<MarketV1BorrowAction>` with `to`, `value`, `data`, and the
40
+ * typed `action` discriminator the simulation layer consumes.
41
+ * @throws {NonPositiveBorrowAmountError} when `amount <= 0n`.
42
+ * @throws {NonPositiveMinBorrowSharePriceError} when `minSharePrice < 0n` (negative; zero is
43
+ * allowed despite the class name).
44
+ * @throws {NegativeReallocationFeeError} from `buildReallocationActions` when
45
+ * `reallocations` is non-empty and any `reallocation.fee < 0n`.
46
+ * @throws {EmptyReallocationWithdrawalsError} from `buildReallocationActions` when any
47
+ * `reallocation.withdrawals` is empty.
48
+ * @throws {NonPositiveReallocationAmountError} from `buildReallocationActions` when any
49
+ * `reallocation.withdrawals[i].amount <= 0n`.
50
+ * @throws {ReallocationWithdrawalOnTargetMarketError} from `buildReallocationActions` when any
51
+ * reallocation withdrawal references the target market.
52
+ * @throws {UnsortedReallocationWithdrawalsError} from `buildReallocationActions` when
53
+ * reallocation withdrawals are not strictly sorted by market id.
54
+ * @example
55
+ * ```ts
56
+ * import { marketV1Borrow } from "@morpho-org/morpho-sdk";
57
+ *
58
+ * const tx = marketV1Borrow({
59
+ * market: { chainId: 1, marketParams },
60
+ * args: {
61
+ * amount: 1_000_000n,
62
+ * receiver: borrower,
63
+ * minSharePrice: 0n, // disables slippage protection — production code should compute via `computeMinBorrowSharePrice` from market state + slippage tolerance
64
+ * },
65
+ * });
66
+ * // tx satisfies Readonly<Transaction<MarketV1BorrowAction>>
67
+ * ```
68
+ */
69
+ export declare const marketV1Borrow: ({ market: { chainId, marketParams }, args: { amount, receiver, minSharePrice, reallocations }, metadata, }: MarketV1BorrowParams) => Readonly<Transaction<MarketV1BorrowAction>>;
@@ -0,0 +1,97 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.marketV1Borrow = void 0;
4
+ const bundler_sdk_viem_1 = require("@morpho-org/bundler-sdk-viem");
5
+ const morpho_ts_1 = require("@morpho-org/morpho-ts");
6
+ const index_js_1 = require("../../helpers/index.js");
7
+ const index_js_2 = require("../../types/index.js");
8
+ const buildReallocationActions_js_1 = require("./buildReallocationActions.js");
9
+ /**
10
+ * Prepares a borrow transaction for a Morpho Blue market.
11
+ *
12
+ * Routed through bundler3 via `morphoBorrow`. The bundler uses the transaction initiator as
13
+ * `onBehalf`. Uses `minSharePrice` to protect against share price manipulation between
14
+ * transaction construction and execution.
15
+ *
16
+ * When `reallocations` are provided, `reallocateTo` actions are prepended to the bundle, moving
17
+ * liquidity from other markets via the PublicAllocator before borrowing. Reallocation fees
18
+ * accumulate in `tx.value`.
19
+ *
20
+ * @param params.market.chainId - The chain the market lives on.
21
+ * @param params.market.marketParams - Market params (loanToken, collateralToken, oracle, irm, lltv).
22
+ * @param params.args.amount - Loan asset amount to borrow, in the loan token's smallest unit.
23
+ * @param params.args.receiver - Address that receives the borrowed assets.
24
+ * @param params.args.minSharePrice - Minimum borrow share price (in ray). Slippage protection.
25
+ * @param params.args.reallocations - Optional vault reallocations to execute before borrowing,
26
+ * computed by the entity layer.
27
+ * @param params.metadata - Optional analytics metadata attached to the bundle.
28
+ * @returns A deep-frozen `Transaction<MarketV1BorrowAction>` with `to`, `value`, `data`, and the
29
+ * typed `action` discriminator the simulation layer consumes.
30
+ * @throws {NonPositiveBorrowAmountError} when `amount <= 0n`.
31
+ * @throws {NonPositiveMinBorrowSharePriceError} when `minSharePrice < 0n` (negative; zero is
32
+ * allowed despite the class name).
33
+ * @throws {NegativeReallocationFeeError} from `buildReallocationActions` when
34
+ * `reallocations` is non-empty and any `reallocation.fee < 0n`.
35
+ * @throws {EmptyReallocationWithdrawalsError} from `buildReallocationActions` when any
36
+ * `reallocation.withdrawals` is empty.
37
+ * @throws {NonPositiveReallocationAmountError} from `buildReallocationActions` when any
38
+ * `reallocation.withdrawals[i].amount <= 0n`.
39
+ * @throws {ReallocationWithdrawalOnTargetMarketError} from `buildReallocationActions` when any
40
+ * reallocation withdrawal references the target market.
41
+ * @throws {UnsortedReallocationWithdrawalsError} from `buildReallocationActions` when
42
+ * reallocation withdrawals are not strictly sorted by market id.
43
+ * @example
44
+ * ```ts
45
+ * import { marketV1Borrow } from "@morpho-org/morpho-sdk";
46
+ *
47
+ * const tx = marketV1Borrow({
48
+ * market: { chainId: 1, marketParams },
49
+ * args: {
50
+ * amount: 1_000_000n,
51
+ * receiver: borrower,
52
+ * minSharePrice: 0n, // disables slippage protection — production code should compute via `computeMinBorrowSharePrice` from market state + slippage tolerance
53
+ * },
54
+ * });
55
+ * // tx satisfies Readonly<Transaction<MarketV1BorrowAction>>
56
+ * ```
57
+ */
58
+ const marketV1Borrow = ({ market: { chainId, marketParams }, args: { amount, receiver, minSharePrice, reallocations }, metadata, }) => {
59
+ if (amount <= 0n) {
60
+ throw new index_js_2.NonPositiveBorrowAmountError(marketParams.id);
61
+ }
62
+ if (minSharePrice < 0n) {
63
+ throw new index_js_2.NonPositiveMinBorrowSharePriceError(marketParams.id);
64
+ }
65
+ const actions = [];
66
+ let reallocationFee = 0n;
67
+ if (reallocations && reallocations.length > 0) {
68
+ const result = (0, buildReallocationActions_js_1.buildReallocationActions)(reallocations, marketParams);
69
+ actions.push(...result.actions);
70
+ reallocationFee = result.fee;
71
+ }
72
+ actions.push({
73
+ type: "morphoBorrow",
74
+ args: [marketParams, amount, 0n, minSharePrice, receiver, false],
75
+ });
76
+ let tx = {
77
+ ...bundler_sdk_viem_1.BundlerAction.encodeBundle(chainId, actions),
78
+ value: reallocationFee,
79
+ };
80
+ if (metadata) {
81
+ tx = (0, index_js_1.addTransactionMetadata)(tx, metadata);
82
+ }
83
+ return (0, morpho_ts_1.deepFreeze)({
84
+ ...tx,
85
+ action: {
86
+ type: "marketV1Borrow",
87
+ args: {
88
+ market: marketParams.id,
89
+ amount,
90
+ receiver,
91
+ minSharePrice,
92
+ reallocationFee,
93
+ },
94
+ },
95
+ });
96
+ };
97
+ exports.marketV1Borrow = marketV1Borrow;
@@ -0,0 +1,28 @@
1
+ import type { MarketParams } from "@morpho-org/blue-sdk";
2
+ import type { Action } from "@morpho-org/bundler-sdk-viem";
3
+ import type { VaultReallocation } from "../../types/index.js";
4
+ /**
5
+ * Builds reallocation bundler actions and computes the total fee.
6
+ *
7
+ * Validates the reallocations, then encodes each as a `reallocateTo` action against the target
8
+ * market. Returns `{ actions: [], fee: 0n }` for an empty input — callers gate on
9
+ * `reallocations.length > 0` and skip the call entirely in that case. Internal helper —
10
+ * consumed only by `marketV1Borrow` and `marketV1SupplyCollateralBorrow`; not re-exported on the
11
+ * public surface.
12
+ *
13
+ * @param reallocations - The vault reallocations to encode.
14
+ * @param targetMarketParams - The target market params the freed liquidity is destined for.
15
+ * @returns The encoded `reallocateTo` actions and the summed reallocation fee (in native, used
16
+ * as `tx.value` in the parent bundle).
17
+ * @throws {NegativeReallocationFeeError} when any reallocation fee is negative.
18
+ * @throws {EmptyReallocationWithdrawalsError} when any reallocation has no withdrawals.
19
+ * @throws {NonPositiveReallocationAmountError} when any withdrawal amount is non-positive.
20
+ * @throws {ReallocationWithdrawalOnTargetMarketError} when a withdrawal references the target market.
21
+ * @throws {UnsortedReallocationWithdrawalsError} when withdrawals within a reallocation are not
22
+ * strictly sorted by market id.
23
+ * @internal
24
+ */
25
+ export declare const buildReallocationActions: (reallocations: readonly VaultReallocation[], targetMarketParams: MarketParams) => {
26
+ readonly actions: Action[];
27
+ readonly fee: bigint;
28
+ };
@@ -0,0 +1,47 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.buildReallocationActions = void 0;
4
+ const index_js_1 = require("../../helpers/index.js");
5
+ /**
6
+ * Builds reallocation bundler actions and computes the total fee.
7
+ *
8
+ * Validates the reallocations, then encodes each as a `reallocateTo` action against the target
9
+ * market. Returns `{ actions: [], fee: 0n }` for an empty input — callers gate on
10
+ * `reallocations.length > 0` and skip the call entirely in that case. Internal helper —
11
+ * consumed only by `marketV1Borrow` and `marketV1SupplyCollateralBorrow`; not re-exported on the
12
+ * public surface.
13
+ *
14
+ * @param reallocations - The vault reallocations to encode.
15
+ * @param targetMarketParams - The target market params the freed liquidity is destined for.
16
+ * @returns The encoded `reallocateTo` actions and the summed reallocation fee (in native, used
17
+ * as `tx.value` in the parent bundle).
18
+ * @throws {NegativeReallocationFeeError} when any reallocation fee is negative.
19
+ * @throws {EmptyReallocationWithdrawalsError} when any reallocation has no withdrawals.
20
+ * @throws {NonPositiveReallocationAmountError} when any withdrawal amount is non-positive.
21
+ * @throws {ReallocationWithdrawalOnTargetMarketError} when a withdrawal references the target market.
22
+ * @throws {UnsortedReallocationWithdrawalsError} when withdrawals within a reallocation are not
23
+ * strictly sorted by market id.
24
+ * @internal
25
+ */
26
+ const buildReallocationActions = (reallocations, targetMarketParams) => {
27
+ (0, index_js_1.validateReallocations)(reallocations, targetMarketParams.id);
28
+ const fee = reallocations.reduce((sum, r) => sum + r.fee, 0n);
29
+ const actions = [];
30
+ for (const r of reallocations) {
31
+ actions.push({
32
+ type: "reallocateTo",
33
+ args: [
34
+ r.vault,
35
+ r.fee,
36
+ r.withdrawals.map((w) => ({
37
+ marketParams: w.marketParams,
38
+ amount: w.amount,
39
+ })),
40
+ targetMarketParams,
41
+ false,
42
+ ],
43
+ });
44
+ }
45
+ return { actions, fee };
46
+ };
47
+ exports.buildReallocationActions = buildReallocationActions;
@@ -0,0 +1,6 @@
1
+ export * from "./borrow.js";
2
+ export * from "./repay.js";
3
+ export * from "./repayWithdrawCollateral.js";
4
+ export * from "./supplyCollateral.js";
5
+ export * from "./supplyCollateralBorrow.js";
6
+ export * from "./withdrawCollateral.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("./borrow"), exports);
18
- __exportStar(require("./repay"), exports);
19
- __exportStar(require("./repayWithdrawCollateral"), exports);
20
- __exportStar(require("./supplyCollateral"), exports);
21
- __exportStar(require("./supplyCollateralBorrow"), exports);
22
- __exportStar(require("./withdrawCollateral"), exports);
17
+ __exportStar(require("./borrow.js"), exports);
18
+ __exportStar(require("./repay.js"), exports);
19
+ __exportStar(require("./repayWithdrawCollateral.js"), exports);
20
+ __exportStar(require("./supplyCollateral.js"), exports);
21
+ __exportStar(require("./supplyCollateralBorrow.js"), exports);
22
+ __exportStar(require("./withdrawCollateral.js"), exports);
@@ -0,0 +1,89 @@
1
+ import { type MarketParams } from "@morpho-org/blue-sdk";
2
+ import { type Address } from "viem";
3
+ import type { MarketV1RepayAction, Metadata, RequirementSignature, Transaction } from "../../types/index.js";
4
+ /** Parameters for {@link marketV1Repay}. */
5
+ export interface MarketV1RepayParams {
6
+ market: {
7
+ readonly chainId: number;
8
+ readonly marketParams: MarketParams;
9
+ };
10
+ args: {
11
+ /** Repay assets amount (0n when repaying by shares). */
12
+ assets: bigint;
13
+ /** Repay shares amount (0n when repaying by assets). */
14
+ shares: bigint;
15
+ /**
16
+ * ERC-20 amount to pull into `GeneralAdapter1`. In assets mode, must equal `assets`
17
+ * exactly (`TransferAmountNotEqualToAssetsError` fires otherwise). In shares mode, an
18
+ * upper-bound estimate to absorb share-price drift; residual is skimmed back to `receiver`.
19
+ */
20
+ transferAmount: bigint;
21
+ /** Address whose debt is being repaid. */
22
+ onBehalf: Address;
23
+ /** Receives residual loan tokens in shares mode. */
24
+ receiver: Address;
25
+ /** Maximum repay share price (in ray). Protects against share price manipulation. */
26
+ maxSharePrice: bigint;
27
+ requirementSignature?: RequirementSignature;
28
+ };
29
+ metadata?: Metadata;
30
+ }
31
+ /**
32
+ * Prepares a repay transaction for a Morpho Blue market.
33
+ *
34
+ * Routed through bundler3 via `GeneralAdapter1`. Supports two modes:
35
+ *
36
+ * - **By assets** (`assets > 0, shares = 0`): repays an exact asset amount.
37
+ * - **By shares** (`assets = 0, shares > 0`): repays exact shares (full repay), with
38
+ * `transferAmount` set to an upper-bound asset estimate; residual loan tokens are skimmed back
39
+ * to `receiver` after the call.
40
+ *
41
+ * Exactly one of `assets` / `shares` must be non-zero. Uses `maxSharePrice` to protect against
42
+ * share price manipulation between transaction construction and execution.
43
+ *
44
+ * @param params.market.chainId - The chain the market lives on.
45
+ * @param params.market.marketParams - Market params (loanToken, collateralToken, oracle, irm, lltv).
46
+ * @param params.args.assets - Repay amount in loan-token assets. Set to `0n` when repaying by shares.
47
+ * @param params.args.shares - Repay amount in borrow shares. Set to `0n` when repaying by assets.
48
+ * @param params.args.transferAmount - ERC-20 amount to pull into `GeneralAdapter1`. In assets
49
+ * mode, must equal `assets` exactly (`TransferAmountNotEqualToAssetsError` fires otherwise).
50
+ * In shares mode, this is an upper-bound estimate to absorb share-price drift; residual loan
51
+ * tokens are skimmed back to `receiver`.
52
+ * @param params.args.onBehalf - Address whose Morpho debt is being repaid.
53
+ * @param params.args.receiver - Address that receives residual loan tokens in shares mode.
54
+ * @param params.args.maxSharePrice - Maximum acceptable repay share price (in ray). Slippage
55
+ * protection.
56
+ * @param params.args.requirementSignature - Optional pre-signed permit/permit2 approval for the
57
+ * loan-token transfer.
58
+ * @param params.metadata - Optional analytics metadata attached to the bundle.
59
+ * @returns A deep-frozen `Transaction<MarketV1RepayAction>` with `to`, `value`, `data`, and the
60
+ * typed `action` discriminator the simulation layer consumes.
61
+ * @throws {NonPositiveRepayMaxSharePriceError} when `maxSharePrice <= 0n`.
62
+ * @throws {NonPositiveRepayAmountError} when either `assets` or `shares` is negative, or when
63
+ * both are zero.
64
+ * @throws {MutuallyExclusiveRepayAmountsError} when both `assets` and `shares` are non-zero.
65
+ * @throws {NonPositiveTransferAmountError} when `transferAmount <= 0n`.
66
+ * @throws {TransferAmountNotEqualToAssetsError} when in assets mode and `transferAmount !== assets`.
67
+ * @throws {DepositAssetMismatchError} from `getRequirementsAction` when `requirementSignature`
68
+ * is provided and the signed asset differs from `marketParams.loanToken`.
69
+ * @throws {DepositAmountMismatchError} from `getRequirementsAction` when `requirementSignature`
70
+ * is provided and the signed amount differs from `args.transferAmount`.
71
+ * @example
72
+ * ```ts
73
+ * import { marketV1Repay } from "@morpho-org/morpho-sdk";
74
+ *
75
+ * const tx = marketV1Repay({
76
+ * market: { chainId: 1, marketParams },
77
+ * args: {
78
+ * assets: 500_000_000n,
79
+ * shares: 0n,
80
+ * transferAmount: 500_000_000n,
81
+ * onBehalf: borrower,
82
+ * receiver: borrower,
83
+ * maxSharePrice: 1_010_000_000_000_000_000_000_000_000n, // RAY-scaled, 1.01x
84
+ * },
85
+ * });
86
+ * // tx satisfies Readonly<Transaction<MarketV1RepayAction>>
87
+ * ```
88
+ */
89
+ export declare const marketV1Repay: ({ market: { chainId, marketParams }, args: { assets, shares, transferAmount, onBehalf, receiver, maxSharePrice, requirementSignature, }, metadata, }: MarketV1RepayParams) => Readonly<Transaction<MarketV1RepayAction>>;