@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
@@ -1,282 +1,322 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.NegativeMinSharePriceError = exports.VaultAssetMismatchError = exports.NonPositiveMinBorrowSharePriceError = exports.MissingPublicAllocatorConfigError = exports.RepaySharesExceedDebtError = exports.InvalidSignatureError = exports.RepayExceedsDebtError = exports.ShareDivideByZeroError = exports.WithdrawMakesPositionUnhealthyError = exports.WithdrawExceedsCollateralError = exports.NonPositiveWithdrawCollateralAmountError = exports.NonPositiveRepayMaxSharePriceError = exports.NonPositiveRepayAmountError = exports.MutuallyExclusiveRepayAmountsError = exports.TransferAmountNotEqualToAssetsError = exports.NonPositiveTransferAmountError = exports.UnsortedReallocationWithdrawalsError = exports.ReallocationWithdrawalOnTargetMarketError = exports.NonPositiveReallocationAmountError = exports.EmptyReallocationWithdrawalsError = exports.NegativeReallocationFeeError = exports.AccrualPositionUserMismatchError = exports.MarketIdMismatchError = exports.MissingMarketPriceError = exports.BorrowExceedsSafeLtvError = exports.NativeAmountOnNonWNativeCollateralError = exports.ZeroCollateralAmountError = exports.NonPositiveBorrowAmountError = exports.VaultAddressMismatchError = exports.ZeroDepositAmountError = exports.NegativeNativeAmountError = exports.ChainWNativeMissingError = exports.NativeAmountOnNonWNativeVaultError = exports.DeallocationsExceedWithdrawError = exports.DepositAssetMismatchError = exports.DepositAmountMismatchError = exports.EmptyDeallocationsError = exports.ExcessiveSlippageToleranceError = exports.MissingAccrualPositionError = exports.NegativeSlippageToleranceError = exports.ApprovalAmountLessThanSpendAmountError = exports.MissingClientPropertyError = exports.ChainIdMismatchError = exports.AddressMismatchError = exports.NonPositiveMaxSharePriceError = exports.NonPositiveSharesAmountError = exports.NonPositiveAssetAmountError = void 0;
3
+ exports.NegativeMinSharePriceError = exports.VaultAssetMismatchError = exports.NonPositiveMinBorrowSharePriceError = exports.MissingPublicAllocatorConfigError = exports.RepaySharesExceedDebtError = exports.InvalidSignatureError = exports.RepayExceedsDebtError = exports.ShareDivideByZeroError = exports.WithdrawMakesPositionUnhealthyError = exports.WithdrawExceedsCollateralError = exports.NonPositiveWithdrawCollateralAmountError = exports.NonPositiveRepayMaxSharePriceError = exports.NonPositiveRepayAmountError = exports.MutuallyExclusiveRepayAmountsError = exports.TransferAmountNotEqualToAssetsError = exports.NonPositiveTransferAmountError = exports.UnsortedReallocationWithdrawalsError = exports.ReallocationWithdrawalOnTargetMarketError = exports.NonPositiveReallocationAmountError = exports.EmptyReallocationWithdrawalsError = exports.NegativeReallocationFeeError = exports.AccrualPositionUserMismatchError = exports.MarketIdMismatchError = exports.MissingMarketPriceError = exports.BorrowExceedsSafeLtvError = exports.NativeAmountOnNonWNativeCollateralError = exports.ZeroCollateralAmountError = exports.NonPositiveBorrowAmountError = exports.VaultAddressMismatchError = exports.ZeroDepositAmountError = exports.NegativeNativeAmountError = exports.ChainWNativeMissingError = exports.NativeAmountOnNonWNativeVaultError = exports.DepositAssetMismatchError = exports.DepositAmountMismatchError = exports.EmptyDeallocationsError = exports.ExcessiveSlippageToleranceError = exports.MissingAccrualPositionError = exports.NegativeSlippageToleranceError = exports.ApprovalAmountLessThanSpendAmountError = exports.MissingClientPropertyError = exports.ChainIdMismatchError = exports.AddressMismatchError = exports.NonPositiveMaxSharePriceError = exports.NonPositiveSharesAmountError = exports.NonPositiveAssetAmountError = void 0;
4
+ /** Thrown when an asset amount is required to be positive but is zero or negative. */
4
5
  class NonPositiveAssetAmountError extends Error {
5
6
  constructor(origin) {
6
7
  super(`Asset amount must be positive for address ${origin}`);
7
8
  }
8
9
  }
9
10
  exports.NonPositiveAssetAmountError = NonPositiveAssetAmountError;
11
+ /** Thrown when a shares amount is required to be positive but is zero or negative. */
10
12
  class NonPositiveSharesAmountError extends Error {
11
13
  constructor(vault) {
12
14
  super(`Shares amount must be positive for address: ${vault}`);
13
15
  }
14
16
  }
15
17
  exports.NonPositiveSharesAmountError = NonPositiveSharesAmountError;
18
+ /** Thrown when a vault deposit's `maxSharePrice` slippage bound is zero or negative. */
16
19
  class NonPositiveMaxSharePriceError extends Error {
17
20
  constructor(vault) {
18
21
  super(`Max share price must be positive for vault: ${vault}`);
19
22
  }
20
23
  }
21
24
  exports.NonPositiveMaxSharePriceError = NonPositiveMaxSharePriceError;
25
+ /** Thrown when a viem client's account address does not match the address required by the call. */
22
26
  class AddressMismatchError extends Error {
23
27
  constructor(clientAddress, argsAddress) {
24
28
  super(`Address mismatch between client: ${clientAddress} and args: ${argsAddress}`);
25
29
  }
26
30
  }
27
31
  exports.AddressMismatchError = AddressMismatchError;
32
+ /** Thrown when a viem client's chain id does not match the chain id required by the call. */
28
33
  class ChainIdMismatchError extends Error {
29
34
  constructor(clientChainId, argsChainId) {
30
35
  super(`Chain ID mismatch between client: ${clientChainId} and args: ${argsChainId}`);
31
36
  }
32
37
  }
33
38
  exports.ChainIdMismatchError = ChainIdMismatchError;
39
+ /** Thrown when the viem client is missing a property the call requires (e.g. `account.address`). */
34
40
  class MissingClientPropertyError extends Error {
35
41
  constructor(property) {
36
42
  super(`A required ${property} is missing from the client.`);
37
43
  }
38
44
  }
39
45
  exports.MissingClientPropertyError = MissingClientPropertyError;
46
+ /** Thrown when an approval amount is smaller than the spend amount it must cover. */
40
47
  class ApprovalAmountLessThanSpendAmountError extends Error {
41
48
  constructor() {
42
49
  super("Approval amount is less than spend amount");
43
50
  }
44
51
  }
45
52
  exports.ApprovalAmountLessThanSpendAmountError = ApprovalAmountLessThanSpendAmountError;
53
+ /** Thrown when a slippage tolerance is negative. */
46
54
  class NegativeSlippageToleranceError extends Error {
47
55
  constructor(slippageTolerance) {
48
56
  super(`Slippage tolerance ${slippageTolerance} must not be negative`);
49
57
  }
50
58
  }
51
59
  exports.NegativeSlippageToleranceError = NegativeSlippageToleranceError;
60
+ /** Thrown when a Morpho accrual position is missing for a market the call needs to read. */
52
61
  class MissingAccrualPositionError extends Error {
53
62
  constructor(market) {
54
63
  super(`Accrual position is missing for market: ${market}`);
55
64
  }
56
65
  }
57
66
  exports.MissingAccrualPositionError = MissingAccrualPositionError;
67
+ /** Thrown when a slippage tolerance exceeds `MAX_SLIPPAGE_TOLERANCE` (10%). */
58
68
  class ExcessiveSlippageToleranceError extends Error {
59
69
  constructor(slippageTolerance) {
60
70
  super(`Slippage tolerance ${slippageTolerance} exceeds maximum allowed (10%)`);
61
71
  }
62
72
  }
63
73
  exports.ExcessiveSlippageToleranceError = ExcessiveSlippageToleranceError;
74
+ /** Thrown when a VaultV2 force-withdraw or force-redeem call has no deallocations to perform. */
64
75
  class EmptyDeallocationsError extends Error {
65
76
  constructor(vault) {
66
77
  super(`Deallocations list cannot be empty for vault: ${vault}`);
67
78
  }
68
79
  }
69
80
  exports.EmptyDeallocationsError = EmptyDeallocationsError;
81
+ /** Thrown when a deposit's amount differs from the amount the supplied permit / permit2 signature was issued for. */
70
82
  class DepositAmountMismatchError extends Error {
71
83
  constructor(depositAmount, signatureAmount) {
72
84
  super(`Deposit amount ${depositAmount} does not match requirement signature amount ${signatureAmount}`);
73
85
  }
74
86
  }
75
87
  exports.DepositAmountMismatchError = DepositAmountMismatchError;
88
+ /** Thrown when a deposit's asset differs from the asset the supplied permit / permit2 signature was issued for. */
76
89
  class DepositAssetMismatchError extends Error {
77
90
  constructor(depositAsset, signatureAsset) {
78
91
  super(`Deposit asset ${depositAsset} does not match requirement signature asset ${signatureAsset}`);
79
92
  }
80
93
  }
81
94
  exports.DepositAssetMismatchError = DepositAssetMismatchError;
82
- class DeallocationsExceedWithdrawError extends Error {
83
- constructor(params) {
84
- super(`Total deallocated amount (${params.totalDeallocated}) exceed withdraw amount (${params.withdrawAmount}) for vault: ${params.vault}`);
85
- }
86
- }
87
- exports.DeallocationsExceedWithdrawError = DeallocationsExceedWithdrawError;
95
+ /** Thrown when a vault deposit uses `nativeAmount` but the vault asset is not the chain's wNative. */
88
96
  class NativeAmountOnNonWNativeVaultError extends Error {
89
97
  constructor(vaultAsset, wNative) {
90
98
  super(`Cannot use nativeAmount: vault asset ${vaultAsset} is not the wrapped native token ${wNative}`);
91
99
  }
92
100
  }
93
101
  exports.NativeAmountOnNonWNativeVaultError = NativeAmountOnNonWNativeVaultError;
102
+ /** Thrown when a `nativeAmount` is supplied but the chain has no configured wNative address. */
94
103
  class ChainWNativeMissingError extends Error {
95
104
  constructor(chainId) {
96
105
  super(`Chain ${chainId} does not have a configured wrapped native token (wNative)`);
97
106
  }
98
107
  }
99
108
  exports.ChainWNativeMissingError = ChainWNativeMissingError;
109
+ /** Thrown when `nativeAmount` is negative. */
100
110
  class NegativeNativeAmountError extends Error {
101
111
  constructor(nativeAmount) {
102
112
  super(`Native amount must not be negative, got ${nativeAmount}`);
103
113
  }
104
114
  }
105
115
  exports.NegativeNativeAmountError = NegativeNativeAmountError;
116
+ /** Thrown when both `amount` and `nativeAmount` resolve to zero on a vault deposit. */
106
117
  class ZeroDepositAmountError extends Error {
107
118
  constructor(vault) {
108
119
  super(`Total deposit amount must be positive for vault: ${vault}. Both amount and nativeAmount are zero.`);
109
120
  }
110
121
  }
111
122
  exports.ZeroDepositAmountError = ZeroDepositAmountError;
123
+ /** Thrown when a vault entity's address does not match the vault address embedded in the call's args. */
112
124
  class VaultAddressMismatchError extends Error {
113
125
  constructor(vaultAddress, argsVaultAddress) {
114
126
  super(`Vault address mismatch between vault: ${vaultAddress} and args: ${argsVaultAddress}`);
115
127
  }
116
128
  }
117
129
  exports.VaultAddressMismatchError = VaultAddressMismatchError;
130
+ /** Thrown when a market borrow amount is zero or negative. */
118
131
  class NonPositiveBorrowAmountError extends Error {
119
132
  constructor(market) {
120
133
  super(`Borrow amount must be positive for market: ${market}`);
121
134
  }
122
135
  }
123
136
  exports.NonPositiveBorrowAmountError = NonPositiveBorrowAmountError;
137
+ /** Thrown when both `amount` and `nativeAmount` resolve to zero on a market collateral supply. */
124
138
  class ZeroCollateralAmountError extends Error {
125
139
  constructor(market) {
126
140
  super(`Total collateral amount must be positive for market: ${market}. Both amount and nativeAmount are zero.`);
127
141
  }
128
142
  }
129
143
  exports.ZeroCollateralAmountError = ZeroCollateralAmountError;
144
+ /** Thrown when a collateral supply uses `nativeAmount` but the collateral token is not the chain's wNative. */
130
145
  class NativeAmountOnNonWNativeCollateralError extends Error {
131
146
  constructor(collateralToken, wNative) {
132
147
  super(`Cannot use nativeAmount: collateral token ${collateralToken} is not the wrapped native token ${wNative}`);
133
148
  }
134
149
  }
135
150
  exports.NativeAmountOnNonWNativeCollateralError = NativeAmountOnNonWNativeCollateralError;
151
+ /** Thrown when a borrow exceeds the LLTV-buffered safe maximum for the position. */
136
152
  class BorrowExceedsSafeLtvError extends Error {
137
153
  constructor(borrowAmount, maxSafeBorrow) {
138
154
  super(`Borrow amount ${borrowAmount} exceeds safe maximum ${maxSafeBorrow} (LLTV minus buffer). Reduce borrow or increase collateral.`);
139
155
  }
140
156
  }
141
157
  exports.BorrowExceedsSafeLtvError = BorrowExceedsSafeLtvError;
158
+ /** Thrown when the market's oracle price is unavailable and position health cannot be validated. */
142
159
  class MissingMarketPriceError extends Error {
143
160
  constructor(market) {
144
161
  super(`Oracle price unavailable for market ${market}. Cannot validate position health.`);
145
162
  }
146
163
  }
147
164
  exports.MissingMarketPriceError = MissingMarketPriceError;
165
+ /** Thrown when a `MarketParams.id` does not match the expected market id derived from the other fields. */
148
166
  class MarketIdMismatchError extends Error {
149
167
  constructor(marketId, expectedMarketId) {
150
168
  super(`Market ${marketId} does not match expected market ${expectedMarketId}`);
151
169
  }
152
170
  }
153
171
  exports.MarketIdMismatchError = MarketIdMismatchError;
172
+ /** Thrown when an accrual position belongs to a different user than the one expected by the call. */
154
173
  class AccrualPositionUserMismatchError extends Error {
155
174
  constructor(positionUser, expectedUser) {
156
175
  super(`Accrual position user ${positionUser} does not match expected user ${expectedUser}`);
157
176
  }
158
177
  }
159
178
  exports.AccrualPositionUserMismatchError = AccrualPositionUserMismatchError;
179
+ /** Thrown when a reallocation's fee is negative. */
160
180
  class NegativeReallocationFeeError extends Error {
161
181
  constructor(vault) {
162
182
  super(`Reallocation fee must not be negative for vault: ${vault}`);
163
183
  }
164
184
  }
165
185
  exports.NegativeReallocationFeeError = NegativeReallocationFeeError;
186
+ /** Thrown when a reallocation has no withdrawals. */
166
187
  class EmptyReallocationWithdrawalsError extends Error {
167
188
  constructor(vault) {
168
189
  super(`Reallocation withdrawals list cannot be empty for vault: ${vault}`);
169
190
  }
170
191
  }
171
192
  exports.EmptyReallocationWithdrawalsError = EmptyReallocationWithdrawalsError;
193
+ /** Thrown when a reallocation withdrawal amount is zero or negative. */
172
194
  class NonPositiveReallocationAmountError extends Error {
173
195
  constructor(vault, market) {
174
196
  super(`Reallocation withdrawal amount must be positive for vault ${vault} on market ${market}`);
175
197
  }
176
198
  }
177
199
  exports.NonPositiveReallocationAmountError = NonPositiveReallocationAmountError;
200
+ /** Thrown when a reallocation withdrawal references the borrow target market (which would be a no-op or self-deal). */
178
201
  class ReallocationWithdrawalOnTargetMarketError extends Error {
179
202
  constructor(vault, marketId) {
180
203
  super(`Reallocation withdrawal cannot include the borrow target market ${marketId} for vault ${vault}.`);
181
204
  }
182
205
  }
183
206
  exports.ReallocationWithdrawalOnTargetMarketError = ReallocationWithdrawalOnTargetMarketError;
207
+ /** Thrown when reallocation withdrawals within a vault are not strictly sorted by market id. */
184
208
  class UnsortedReallocationWithdrawalsError extends Error {
185
209
  constructor(vault, marketId) {
186
210
  super(`Reallocation withdrawals must be strictly sorted by market ID for vault ${vault}. Market ${marketId} is out of order.`);
187
211
  }
188
212
  }
189
213
  exports.UnsortedReallocationWithdrawalsError = UnsortedReallocationWithdrawalsError;
214
+ /** Thrown when a market repay's `transferAmount` is zero or negative. */
190
215
  class NonPositiveTransferAmountError extends Error {
191
216
  constructor(market) {
192
217
  super(`Transfer amount must be positive for market: ${market}`);
193
218
  }
194
219
  }
195
220
  exports.NonPositiveTransferAmountError = NonPositiveTransferAmountError;
221
+ /** Thrown when a market repay in assets mode has `transferAmount !== assets` (asset-mode requires exact transfer). */
196
222
  class TransferAmountNotEqualToAssetsError extends Error {
197
223
  constructor(params) {
198
224
  super(`Transfer amount ${params.transferAmount} is not equal to repay assets ${params.assets} for market: ${params.market}`);
199
225
  }
200
226
  }
201
227
  exports.TransferAmountNotEqualToAssetsError = TransferAmountNotEqualToAssetsError;
228
+ /** Thrown when a market repay specifies both `assets` and `shares` as non-zero (modes are mutually exclusive). */
202
229
  class MutuallyExclusiveRepayAmountsError extends Error {
203
230
  constructor(market) {
204
231
  super(`Exactly one of assets or shares must be non-zero for market: ${market}. Both were provided.`);
205
232
  }
206
233
  }
207
234
  exports.MutuallyExclusiveRepayAmountsError = MutuallyExclusiveRepayAmountsError;
235
+ /** Thrown when a market repay has non-positive amounts: both `assets` and `shares` are zero, or either is negative. */
208
236
  class NonPositiveRepayAmountError extends Error {
209
237
  constructor(market) {
210
238
  super(`Repay amount must be positive for market: ${market}`);
211
239
  }
212
240
  }
213
241
  exports.NonPositiveRepayAmountError = NonPositiveRepayAmountError;
242
+ /** Thrown when a market repay's `maxSharePrice` slippage bound is zero or negative. */
214
243
  class NonPositiveRepayMaxSharePriceError extends Error {
215
244
  constructor(market) {
216
245
  super(`Max share price must be positive for market: ${market}`);
217
246
  }
218
247
  }
219
248
  exports.NonPositiveRepayMaxSharePriceError = NonPositiveRepayMaxSharePriceError;
249
+ /** Thrown when a market `withdrawCollateral` amount is zero or negative. */
220
250
  class NonPositiveWithdrawCollateralAmountError extends Error {
221
251
  constructor(market) {
222
252
  super(`Withdraw collateral amount must be positive for market: ${market}`);
223
253
  }
224
254
  }
225
255
  exports.NonPositiveWithdrawCollateralAmountError = NonPositiveWithdrawCollateralAmountError;
256
+ /** Thrown when a withdraw amount exceeds the position's available collateral. */
226
257
  class WithdrawExceedsCollateralError extends Error {
227
258
  constructor(params) {
228
259
  super(`Withdraw amount ${params.withdrawAmount} exceeds available collateral ${params.available} for market: ${params.market}`);
229
260
  }
230
261
  }
231
262
  exports.WithdrawExceedsCollateralError = WithdrawExceedsCollateralError;
263
+ /** Thrown when a collateral withdrawal would leave the borrower's position above the LLTV-buffered safe maximum. */
232
264
  class WithdrawMakesPositionUnhealthyError extends Error {
233
265
  constructor(params) {
234
266
  super(`Withdrawing ${params.withdrawAmount} collateral would make position unhealthy. Max safe borrow after withdrawal: ${params.maxSafeBorrow}. Actual Borrow assets: ${params.borrowAssets}.`);
235
267
  }
236
268
  }
237
269
  exports.WithdrawMakesPositionUnhealthyError = WithdrawMakesPositionUnhealthyError;
270
+ /** Thrown when a share-amount conversion would divide by zero (the market has no shares of the relevant kind). */
238
271
  class ShareDivideByZeroError extends Error {
239
272
  constructor(market) {
240
273
  super(`Share divide by zero error for market: ${market}`);
241
274
  }
242
275
  }
243
276
  exports.ShareDivideByZeroError = ShareDivideByZeroError;
277
+ /** Thrown when a repay amount in assets exceeds the borrower's outstanding debt. */
244
278
  class RepayExceedsDebtError extends Error {
245
279
  constructor(params) {
246
280
  super(`Repay amount ${params.repayAmount} exceeds outstanding debt ${params.debt} for market: ${params.market}`);
247
281
  }
248
282
  }
249
283
  exports.RepayExceedsDebtError = RepayExceedsDebtError;
284
+ /** Thrown when EIP-712 signature verification fails (the signed data does not match the expected signer). */
250
285
  class InvalidSignatureError extends Error {
251
286
  constructor() {
252
287
  super("Signature verification failed: the signed data does not match the expected signer address");
253
288
  }
254
289
  }
255
290
  exports.InvalidSignatureError = InvalidSignatureError;
291
+ /** Thrown when a repay in shares mode supplies more shares than the borrower owes. */
256
292
  class RepaySharesExceedDebtError extends Error {
257
293
  constructor(params) {
258
294
  super(`Repay shares ${params.repayShares} exceed outstanding borrow shares ${params.borrowShares} for market: ${params.market}`);
259
295
  }
260
296
  }
261
297
  exports.RepaySharesExceedDebtError = RepaySharesExceedDebtError;
298
+ /** Thrown when a vault selected for reallocation has no configured `PublicAllocator`. */
262
299
  class MissingPublicAllocatorConfigError extends Error {
263
300
  constructor(vault) {
264
301
  super(`Vault ${vault} has no public allocator configured but was selected for reallocation`);
265
302
  }
266
303
  }
267
304
  exports.MissingPublicAllocatorConfigError = MissingPublicAllocatorConfigError;
305
+ /** Thrown when a market borrow's `minSharePrice` slippage bound is negative. */
268
306
  class NonPositiveMinBorrowSharePriceError extends Error {
269
307
  constructor(market) {
270
308
  super(`Min share price must be non-negative for market: ${market}`);
271
309
  }
272
310
  }
273
311
  exports.NonPositiveMinBorrowSharePriceError = NonPositiveMinBorrowSharePriceError;
312
+ /** Thrown when a vault migration's source vault asset differs from the target vault asset. */
274
313
  class VaultAssetMismatchError extends Error {
275
314
  constructor(sourceAsset, targetAsset) {
276
315
  super(`Source vault asset ${sourceAsset} does not match target vault asset ${targetAsset}`);
277
316
  }
278
317
  }
279
318
  exports.VaultAssetMismatchError = VaultAssetMismatchError;
319
+ /** Thrown when a vault redeem's `minSharePrice` slippage bound is negative. */
280
320
  class NegativeMinSharePriceError extends Error {
281
321
  constructor(vault) {
282
322
  super(`Min share price must be non-negative for vault: ${vault}`);
@@ -0,0 +1,7 @@
1
+ export * from "./action.js";
2
+ export * from "./client.js";
3
+ export * from "./deallocation.js";
4
+ export * from "./entity.js";
5
+ export * from "./error.js";
6
+ export * from "./metadata.js";
7
+ export * from "./sharedLiquidity.js";
@@ -0,0 +1,23 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./action.js"), exports);
18
+ __exportStar(require("./client.js"), exports);
19
+ __exportStar(require("./deallocation.js"), exports);
20
+ __exportStar(require("./entity.js"), exports);
21
+ __exportStar(require("./error.js"), exports);
22
+ __exportStar(require("./metadata.js"), exports);
23
+ __exportStar(require("./sharedLiquidity.js"), exports);
@@ -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";
@@ -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";
@@ -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,93 @@
1
+ import { BundlerAction } from "@morpho-org/bundler-sdk-viem";
2
+ import { deepFreeze } from "@morpho-org/morpho-ts";
3
+ import { addTransactionMetadata } from "../../helpers/index.js";
4
+ import { NonPositiveBorrowAmountError, NonPositiveMinBorrowSharePriceError, } from "../../types/index.js";
5
+ import { buildReallocationActions } from "./buildReallocationActions.js";
6
+ /**
7
+ * Prepares a borrow transaction for a Morpho Blue market.
8
+ *
9
+ * Routed through bundler3 via `morphoBorrow`. The bundler uses the transaction initiator as
10
+ * `onBehalf`. Uses `minSharePrice` to protect against share price manipulation between
11
+ * transaction construction and execution.
12
+ *
13
+ * When `reallocations` are provided, `reallocateTo` actions are prepended to the bundle, moving
14
+ * liquidity from other markets via the PublicAllocator before borrowing. Reallocation fees
15
+ * accumulate in `tx.value`.
16
+ *
17
+ * @param params.market.chainId - The chain the market lives on.
18
+ * @param params.market.marketParams - Market params (loanToken, collateralToken, oracle, irm, lltv).
19
+ * @param params.args.amount - Loan asset amount to borrow, in the loan token's smallest unit.
20
+ * @param params.args.receiver - Address that receives the borrowed assets.
21
+ * @param params.args.minSharePrice - Minimum borrow share price (in ray). Slippage protection.
22
+ * @param params.args.reallocations - Optional vault reallocations to execute before borrowing,
23
+ * computed by the entity layer.
24
+ * @param params.metadata - Optional analytics metadata attached to the bundle.
25
+ * @returns A deep-frozen `Transaction<MarketV1BorrowAction>` with `to`, `value`, `data`, and the
26
+ * typed `action` discriminator the simulation layer consumes.
27
+ * @throws {NonPositiveBorrowAmountError} when `amount <= 0n`.
28
+ * @throws {NonPositiveMinBorrowSharePriceError} when `minSharePrice < 0n` (negative; zero is
29
+ * allowed despite the class name).
30
+ * @throws {NegativeReallocationFeeError} from `buildReallocationActions` when
31
+ * `reallocations` is non-empty and any `reallocation.fee < 0n`.
32
+ * @throws {EmptyReallocationWithdrawalsError} from `buildReallocationActions` when any
33
+ * `reallocation.withdrawals` is empty.
34
+ * @throws {NonPositiveReallocationAmountError} from `buildReallocationActions` when any
35
+ * `reallocation.withdrawals[i].amount <= 0n`.
36
+ * @throws {ReallocationWithdrawalOnTargetMarketError} from `buildReallocationActions` when any
37
+ * reallocation withdrawal references the target market.
38
+ * @throws {UnsortedReallocationWithdrawalsError} from `buildReallocationActions` when
39
+ * reallocation withdrawals are not strictly sorted by market id.
40
+ * @example
41
+ * ```ts
42
+ * import { marketV1Borrow } from "@morpho-org/morpho-sdk";
43
+ *
44
+ * const tx = marketV1Borrow({
45
+ * market: { chainId: 1, marketParams },
46
+ * args: {
47
+ * amount: 1_000_000n,
48
+ * receiver: borrower,
49
+ * minSharePrice: 0n, // disables slippage protection — production code should compute via `computeMinBorrowSharePrice` from market state + slippage tolerance
50
+ * },
51
+ * });
52
+ * // tx satisfies Readonly<Transaction<MarketV1BorrowAction>>
53
+ * ```
54
+ */
55
+ export const marketV1Borrow = ({ market: { chainId, marketParams }, args: { amount, receiver, minSharePrice, reallocations }, metadata, }) => {
56
+ if (amount <= 0n) {
57
+ throw new NonPositiveBorrowAmountError(marketParams.id);
58
+ }
59
+ if (minSharePrice < 0n) {
60
+ throw new NonPositiveMinBorrowSharePriceError(marketParams.id);
61
+ }
62
+ const actions = [];
63
+ let reallocationFee = 0n;
64
+ if (reallocations && reallocations.length > 0) {
65
+ const result = buildReallocationActions(reallocations, marketParams);
66
+ actions.push(...result.actions);
67
+ reallocationFee = result.fee;
68
+ }
69
+ actions.push({
70
+ type: "morphoBorrow",
71
+ args: [marketParams, amount, 0n, minSharePrice, receiver, false],
72
+ });
73
+ let tx = {
74
+ ...BundlerAction.encodeBundle(chainId, actions),
75
+ value: reallocationFee,
76
+ };
77
+ if (metadata) {
78
+ tx = addTransactionMetadata(tx, metadata);
79
+ }
80
+ return deepFreeze({
81
+ ...tx,
82
+ action: {
83
+ type: "marketV1Borrow",
84
+ args: {
85
+ market: marketParams.id,
86
+ amount,
87
+ receiver,
88
+ minSharePrice,
89
+ reallocationFee,
90
+ },
91
+ },
92
+ });
93
+ };
@@ -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,43 @@
1
+ import { validateReallocations } from "../../helpers/index.js";
2
+ /**
3
+ * Builds reallocation bundler actions and computes the total fee.
4
+ *
5
+ * Validates the reallocations, then encodes each as a `reallocateTo` action against the target
6
+ * market. Returns `{ actions: [], fee: 0n }` for an empty input — callers gate on
7
+ * `reallocations.length > 0` and skip the call entirely in that case. Internal helper —
8
+ * consumed only by `marketV1Borrow` and `marketV1SupplyCollateralBorrow`; not re-exported on the
9
+ * public surface.
10
+ *
11
+ * @param reallocations - The vault reallocations to encode.
12
+ * @param targetMarketParams - The target market params the freed liquidity is destined for.
13
+ * @returns The encoded `reallocateTo` actions and the summed reallocation fee (in native, used
14
+ * as `tx.value` in the parent bundle).
15
+ * @throws {NegativeReallocationFeeError} when any reallocation fee is negative.
16
+ * @throws {EmptyReallocationWithdrawalsError} when any reallocation has no withdrawals.
17
+ * @throws {NonPositiveReallocationAmountError} when any withdrawal amount is non-positive.
18
+ * @throws {ReallocationWithdrawalOnTargetMarketError} when a withdrawal references the target market.
19
+ * @throws {UnsortedReallocationWithdrawalsError} when withdrawals within a reallocation are not
20
+ * strictly sorted by market id.
21
+ * @internal
22
+ */
23
+ export const buildReallocationActions = (reallocations, targetMarketParams) => {
24
+ validateReallocations(reallocations, targetMarketParams.id);
25
+ const fee = reallocations.reduce((sum, r) => sum + r.fee, 0n);
26
+ const actions = [];
27
+ for (const r of reallocations) {
28
+ actions.push({
29
+ type: "reallocateTo",
30
+ args: [
31
+ r.vault,
32
+ r.fee,
33
+ r.withdrawals.map((w) => ({
34
+ marketParams: w.marketParams,
35
+ amount: w.amount,
36
+ })),
37
+ targetMarketParams,
38
+ false,
39
+ ],
40
+ });
41
+ }
42
+ return { actions, fee };
43
+ };
@@ -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";
@@ -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";