@morpho-org/morpho-sdk 1.1.0 → 1.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (304) hide show
  1. package/LICENSE +2 -2
  2. package/README.md +31 -33
  3. package/lib/cjs/actions/index.d.ts +4 -0
  4. package/lib/{actions → cjs/actions}/index.js +4 -4
  5. package/lib/cjs/actions/marketV1/borrow.d.ts +69 -0
  6. package/lib/cjs/actions/marketV1/borrow.js +97 -0
  7. package/lib/cjs/actions/marketV1/buildReallocationActions.d.ts +28 -0
  8. package/lib/cjs/actions/marketV1/buildReallocationActions.js +47 -0
  9. package/lib/cjs/actions/marketV1/index.d.ts +6 -0
  10. package/lib/{actions → cjs/actions}/marketV1/index.js +6 -6
  11. package/lib/cjs/actions/marketV1/repay.d.ts +89 -0
  12. package/lib/cjs/actions/marketV1/repay.js +134 -0
  13. package/lib/cjs/actions/marketV1/repayWithdrawCollateral.d.ts +103 -0
  14. package/lib/cjs/actions/marketV1/repayWithdrawCollateral.js +155 -0
  15. package/lib/cjs/actions/marketV1/supplyCollateral.d.ts +59 -0
  16. package/lib/cjs/actions/marketV1/supplyCollateral.js +116 -0
  17. package/lib/cjs/actions/marketV1/supplyCollateralBorrow.d.ts +91 -0
  18. package/lib/cjs/actions/marketV1/supplyCollateralBorrow.js +163 -0
  19. package/lib/cjs/actions/marketV1/withdrawCollateral.d.ts +49 -0
  20. package/lib/cjs/actions/marketV1/withdrawCollateral.js +72 -0
  21. package/lib/cjs/actions/requirements/encode/encodeErc20Approval.d.ts +36 -0
  22. package/lib/{actions → cjs/actions}/requirements/encode/encodeErc20Approval.js +25 -0
  23. package/lib/cjs/actions/requirements/encode/encodeErc20Permit.d.ts +52 -0
  24. package/lib/cjs/actions/requirements/encode/encodeErc20Permit.js +108 -0
  25. package/lib/cjs/actions/requirements/encode/encodeErc20Permit2.d.ts +44 -0
  26. package/lib/{actions → cjs/actions}/requirements/encode/encodeErc20Permit2.js +36 -4
  27. package/lib/cjs/actions/requirements/encode/index.d.ts +3 -0
  28. package/lib/{actions → cjs/actions}/requirements/encode/index.js +3 -3
  29. package/lib/cjs/actions/requirements/getMorphoAuthorizationRequirement.d.ts +37 -0
  30. package/lib/cjs/actions/requirements/getMorphoAuthorizationRequirement.js +71 -0
  31. package/lib/cjs/actions/requirements/getRequirements.d.ts +74 -0
  32. package/lib/cjs/actions/requirements/getRequirements.js +112 -0
  33. package/lib/cjs/actions/requirements/getRequirementsAction.d.ts +33 -0
  34. package/lib/{actions → cjs/actions}/requirements/getRequirementsAction.js +20 -4
  35. package/lib/cjs/actions/requirements/getRequirementsApproval.d.ts +43 -0
  36. package/lib/cjs/actions/requirements/getRequirementsApproval.js +63 -0
  37. package/lib/cjs/actions/requirements/getRequirementsPermit.d.ts +45 -0
  38. package/lib/cjs/actions/requirements/getRequirementsPermit.js +57 -0
  39. package/lib/cjs/actions/requirements/getRequirementsPermit2.d.ts +63 -0
  40. package/lib/cjs/actions/requirements/getRequirementsPermit2.js +85 -0
  41. package/lib/cjs/actions/requirements/index.d.ts +6 -0
  42. package/lib/{actions → cjs/actions}/requirements/index.js +6 -6
  43. package/lib/cjs/actions/vaultV1/deposit.d.ts +72 -0
  44. package/lib/cjs/actions/vaultV1/deposit.js +146 -0
  45. package/lib/cjs/actions/vaultV1/index.d.ts +4 -0
  46. package/lib/{actions → cjs/actions}/vaultV1/index.js +4 -4
  47. package/lib/cjs/actions/vaultV1/migrateToV2.d.ts +84 -0
  48. package/lib/cjs/actions/vaultV1/migrateToV2.js +143 -0
  49. package/lib/cjs/actions/vaultV1/redeem.d.ts +39 -0
  50. package/lib/cjs/actions/vaultV1/redeem.js +57 -0
  51. package/lib/cjs/actions/vaultV1/withdraw.d.ts +39 -0
  52. package/lib/cjs/actions/vaultV1/withdraw.js +57 -0
  53. package/lib/cjs/actions/vaultV2/deposit.d.ts +72 -0
  54. package/lib/cjs/actions/vaultV2/deposit.js +146 -0
  55. package/lib/cjs/actions/vaultV2/forceRedeem.d.ts +63 -0
  56. package/lib/cjs/actions/vaultV2/forceRedeem.js +99 -0
  57. package/lib/cjs/actions/vaultV2/forceWithdraw.d.ts +58 -0
  58. package/lib/cjs/actions/vaultV2/forceWithdraw.js +94 -0
  59. package/lib/cjs/actions/vaultV2/index.d.ts +5 -0
  60. package/lib/{actions → cjs/actions}/vaultV2/index.js +5 -5
  61. package/lib/cjs/actions/vaultV2/redeem.d.ts +40 -0
  62. package/lib/cjs/actions/vaultV2/redeem.js +58 -0
  63. package/lib/cjs/actions/vaultV2/withdraw.d.ts +40 -0
  64. package/lib/cjs/actions/vaultV2/withdraw.js +58 -0
  65. package/lib/cjs/client/index.d.ts +2 -0
  66. package/lib/{client → cjs/client}/index.js +2 -2
  67. package/lib/cjs/client/morphoClient.d.ts +113 -0
  68. package/lib/cjs/client/morphoClient.js +123 -0
  69. package/lib/cjs/client/morphoViemExtension.d.ts +45 -0
  70. package/lib/cjs/client/morphoViemExtension.js +46 -0
  71. package/lib/cjs/entities/index.d.ts +3 -0
  72. package/lib/{entities → cjs/entities}/index.js +3 -3
  73. package/lib/cjs/entities/marketV1/index.d.ts +1 -0
  74. package/lib/{entities/vaultV1 → cjs/entities/marketV1}/index.js +1 -1
  75. package/lib/{entities → cjs/entities}/marketV1/marketV1.d.ts +9 -6
  76. package/lib/{entities → cjs/entities}/marketV1/marketV1.js +89 -87
  77. package/lib/cjs/entities/vaultV1/index.d.ts +1 -0
  78. package/lib/{entities/marketV1 → cjs/entities/vaultV1}/index.js +1 -1
  79. package/lib/{entities → cjs/entities}/vaultV1/vaultV1.d.ts +4 -8
  80. package/lib/{entities → cjs/entities}/vaultV1/vaultV1.js +39 -35
  81. package/lib/cjs/entities/vaultV2/index.d.ts +1 -0
  82. package/lib/{entities → cjs/entities}/vaultV2/index.js +1 -1
  83. package/lib/{entities → cjs/entities}/vaultV2/vaultV2.d.ts +2 -2
  84. package/lib/{entities → cjs/entities}/vaultV2/vaultV2.js +25 -24
  85. package/lib/{helpers → cjs/helpers}/computeReallocations.d.ts +1 -1
  86. package/lib/{helpers → cjs/helpers}/computeReallocations.js +2 -2
  87. package/lib/{helpers → cjs/helpers}/encodeDeallocation.d.ts +1 -1
  88. package/lib/{helpers → cjs/helpers}/encodeDeallocation.js +2 -2
  89. package/lib/{helpers → cjs/helpers}/index.d.ts +4 -4
  90. package/lib/{helpers → cjs/helpers}/index.js +19 -19
  91. package/lib/{helpers → cjs/helpers}/metadata.d.ts +1 -1
  92. package/lib/{helpers → cjs/helpers}/slippage.js +7 -7
  93. package/lib/{helpers → cjs/helpers}/validate.d.ts +1 -1
  94. package/lib/{helpers → cjs/helpers}/validate.js +33 -33
  95. package/lib/cjs/index.d.ts +5 -0
  96. package/lib/cjs/index.js +21 -0
  97. package/lib/cjs/package.json +1 -0
  98. package/lib/{types → cjs/types}/action.d.ts +1 -1
  99. package/lib/{types → cjs/types}/client.d.ts +6 -2
  100. package/lib/{types → cjs/types}/error.d.ts +46 -0
  101. package/lib/{types → cjs/types}/error.js +46 -0
  102. package/lib/cjs/types/index.d.ts +7 -0
  103. package/lib/cjs/types/index.js +23 -0
  104. package/lib/esm/actions/index.d.ts +4 -0
  105. package/lib/esm/actions/index.js +4 -0
  106. package/lib/esm/actions/marketV1/borrow.d.ts +69 -0
  107. package/lib/esm/actions/marketV1/borrow.js +93 -0
  108. package/lib/esm/actions/marketV1/buildReallocationActions.d.ts +28 -0
  109. package/lib/esm/actions/marketV1/buildReallocationActions.js +43 -0
  110. package/lib/esm/actions/marketV1/index.d.ts +6 -0
  111. package/lib/esm/actions/marketV1/index.js +6 -0
  112. package/lib/esm/actions/marketV1/repay.d.ts +89 -0
  113. package/lib/esm/actions/marketV1/repay.js +130 -0
  114. package/lib/esm/actions/marketV1/repayWithdrawCollateral.d.ts +103 -0
  115. package/lib/esm/actions/marketV1/repayWithdrawCollateral.js +151 -0
  116. package/lib/esm/actions/marketV1/supplyCollateral.d.ts +59 -0
  117. package/lib/esm/actions/marketV1/supplyCollateral.js +112 -0
  118. package/lib/esm/actions/marketV1/supplyCollateralBorrow.d.ts +91 -0
  119. package/lib/esm/actions/marketV1/supplyCollateralBorrow.js +159 -0
  120. package/lib/esm/actions/marketV1/withdrawCollateral.d.ts +49 -0
  121. package/lib/esm/actions/marketV1/withdrawCollateral.js +68 -0
  122. package/lib/esm/actions/requirements/encode/encodeErc20Approval.d.ts +36 -0
  123. package/lib/esm/actions/requirements/encode/encodeErc20Approval.js +46 -0
  124. package/lib/esm/actions/requirements/encode/encodeErc20Permit.d.ts +52 -0
  125. package/lib/esm/actions/requirements/encode/encodeErc20Permit.js +104 -0
  126. package/lib/esm/actions/requirements/encode/encodeErc20Permit2.d.ts +44 -0
  127. package/lib/esm/actions/requirements/encode/encodeErc20Permit2.js +98 -0
  128. package/lib/esm/actions/requirements/encode/index.d.ts +3 -0
  129. package/lib/esm/actions/requirements/encode/index.js +3 -0
  130. package/lib/esm/actions/requirements/getMorphoAuthorizationRequirement.d.ts +37 -0
  131. package/lib/esm/actions/requirements/getMorphoAuthorizationRequirement.js +67 -0
  132. package/lib/esm/actions/requirements/getRequirements.d.ts +74 -0
  133. package/lib/esm/actions/requirements/getRequirements.js +108 -0
  134. package/lib/esm/actions/requirements/getRequirementsAction.d.ts +33 -0
  135. package/lib/esm/actions/requirements/getRequirementsAction.js +76 -0
  136. package/lib/esm/actions/requirements/getRequirementsApproval.d.ts +43 -0
  137. package/lib/esm/actions/requirements/getRequirementsApproval.js +59 -0
  138. package/lib/esm/actions/requirements/getRequirementsPermit.d.ts +45 -0
  139. package/lib/esm/actions/requirements/getRequirementsPermit.js +53 -0
  140. package/lib/esm/actions/requirements/getRequirementsPermit2.d.ts +63 -0
  141. package/lib/esm/actions/requirements/getRequirementsPermit2.js +81 -0
  142. package/lib/esm/actions/requirements/index.d.ts +6 -0
  143. package/lib/esm/actions/requirements/index.js +6 -0
  144. package/lib/esm/actions/vaultV1/deposit.d.ts +72 -0
  145. package/lib/esm/actions/vaultV1/deposit.js +142 -0
  146. package/lib/esm/actions/vaultV1/index.d.ts +4 -0
  147. package/lib/esm/actions/vaultV1/index.js +4 -0
  148. package/lib/esm/actions/vaultV1/migrateToV2.d.ts +84 -0
  149. package/lib/esm/actions/vaultV1/migrateToV2.js +139 -0
  150. package/lib/esm/actions/vaultV1/redeem.d.ts +39 -0
  151. package/lib/esm/actions/vaultV1/redeem.js +53 -0
  152. package/lib/esm/actions/vaultV1/withdraw.d.ts +39 -0
  153. package/lib/esm/actions/vaultV1/withdraw.js +53 -0
  154. package/lib/esm/actions/vaultV2/deposit.d.ts +72 -0
  155. package/lib/esm/actions/vaultV2/deposit.js +142 -0
  156. package/lib/esm/actions/vaultV2/forceRedeem.d.ts +63 -0
  157. package/lib/esm/actions/vaultV2/forceRedeem.js +95 -0
  158. package/lib/esm/actions/vaultV2/forceWithdraw.d.ts +58 -0
  159. package/lib/esm/actions/vaultV2/forceWithdraw.js +90 -0
  160. package/lib/esm/actions/vaultV2/index.d.ts +5 -0
  161. package/lib/esm/actions/vaultV2/index.js +5 -0
  162. package/lib/esm/actions/vaultV2/redeem.d.ts +40 -0
  163. package/lib/esm/actions/vaultV2/redeem.js +54 -0
  164. package/lib/esm/actions/vaultV2/withdraw.d.ts +40 -0
  165. package/lib/esm/actions/vaultV2/withdraw.js +54 -0
  166. package/lib/esm/client/index.d.ts +2 -0
  167. package/lib/esm/client/index.js +2 -0
  168. package/lib/esm/client/morphoClient.d.ts +113 -0
  169. package/lib/esm/client/morphoClient.js +119 -0
  170. package/lib/esm/client/morphoViemExtension.d.ts +45 -0
  171. package/lib/esm/client/morphoViemExtension.js +43 -0
  172. package/lib/esm/entities/index.d.ts +3 -0
  173. package/lib/esm/entities/index.js +3 -0
  174. package/lib/esm/entities/marketV1/index.d.ts +1 -0
  175. package/lib/esm/entities/marketV1/index.js +1 -0
  176. package/lib/esm/entities/marketV1/marketV1.d.ts +293 -0
  177. package/lib/esm/entities/marketV1/marketV1.js +529 -0
  178. package/lib/esm/entities/vaultV1/index.d.ts +1 -0
  179. package/lib/esm/entities/vaultV1/index.js +1 -0
  180. package/lib/esm/entities/vaultV1/vaultV1.d.ts +129 -0
  181. package/lib/esm/entities/vaultV1/vaultV1.js +186 -0
  182. package/lib/esm/entities/vaultV2/index.d.ts +1 -0
  183. package/lib/esm/entities/vaultV2/index.js +1 -0
  184. package/lib/esm/entities/vaultV2/vaultV2.d.ts +180 -0
  185. package/lib/esm/entities/vaultV2/vaultV2.js +164 -0
  186. package/lib/esm/helpers/computeReallocations.d.ts +23 -0
  187. package/lib/esm/helpers/computeReallocations.js +94 -0
  188. package/lib/esm/helpers/constant.d.ts +6 -0
  189. package/lib/esm/helpers/constant.js +7 -0
  190. package/lib/esm/helpers/encodeDeallocation.d.ts +10 -0
  191. package/lib/esm/helpers/encodeDeallocation.js +34 -0
  192. package/lib/esm/helpers/index.d.ts +4 -0
  193. package/lib/esm/helpers/index.js +4 -0
  194. package/lib/esm/helpers/metadata.d.ts +33 -0
  195. package/lib/esm/helpers/metadata.js +46 -0
  196. package/lib/esm/helpers/slippage.d.ts +46 -0
  197. package/lib/esm/helpers/slippage.js +69 -0
  198. package/lib/esm/helpers/validate.d.ts +156 -0
  199. package/lib/esm/helpers/validate.js +273 -0
  200. package/lib/esm/index.d.ts +5 -0
  201. package/lib/esm/index.js +5 -0
  202. package/lib/esm/package.json +1 -0
  203. package/lib/esm/types/action.d.ts +216 -0
  204. package/lib/esm/types/action.js +21 -0
  205. package/lib/esm/types/client.d.ts +19 -0
  206. package/lib/esm/types/client.js +1 -0
  207. package/lib/esm/types/data.d.ts +2 -0
  208. package/lib/esm/types/data.js +1 -0
  209. package/lib/esm/types/deallocation.d.ts +15 -0
  210. package/lib/esm/types/deallocation.js +1 -0
  211. package/lib/esm/types/entity.d.ts +5 -0
  212. package/lib/esm/types/entity.js +1 -0
  213. package/lib/esm/types/error.d.ts +205 -0
  214. package/lib/esm/types/error.js +276 -0
  215. package/lib/esm/types/index.d.ts +7 -0
  216. package/lib/esm/types/index.js +7 -0
  217. package/lib/esm/types/metadata.d.ts +4 -0
  218. package/lib/esm/types/metadata.js +1 -0
  219. package/lib/esm/types/sharedLiquidity.d.ts +41 -0
  220. package/lib/esm/types/sharedLiquidity.js +1 -0
  221. package/package.json +33 -56
  222. package/src/index.ts +5 -0
  223. package/lib/actions/index.d.ts +0 -4
  224. package/lib/actions/marketV1/borrow.d.ts +0 -34
  225. package/lib/actions/marketV1/borrow.js +0 -62
  226. package/lib/actions/marketV1/buildReallocationActions.d.ts +0 -17
  227. package/lib/actions/marketV1/buildReallocationActions.js +0 -36
  228. package/lib/actions/marketV1/index.d.ts +0 -6
  229. package/lib/actions/marketV1/repay.d.ts +0 -44
  230. package/lib/actions/marketV1/repay.js +0 -93
  231. package/lib/actions/marketV1/repayWithdrawCollateral.d.ts +0 -51
  232. package/lib/actions/marketV1/repayWithdrawCollateral.js +0 -108
  233. package/lib/actions/marketV1/supplyCollateral.d.ts +0 -28
  234. package/lib/actions/marketV1/supplyCollateral.js +0 -85
  235. package/lib/actions/marketV1/supplyCollateralBorrow.d.ts +0 -37
  236. package/lib/actions/marketV1/supplyCollateralBorrow.js +0 -109
  237. package/lib/actions/marketV1/withdrawCollateral.d.ts +0 -28
  238. package/lib/actions/marketV1/withdrawCollateral.js +0 -51
  239. package/lib/actions/requirements/encode/encodeErc20Approval.d.ts +0 -10
  240. package/lib/actions/requirements/encode/encodeErc20Permit.d.ts +0 -13
  241. package/lib/actions/requirements/encode/encodeErc20Permit.js +0 -70
  242. package/lib/actions/requirements/encode/encodeErc20Permit2.d.ts +0 -11
  243. package/lib/actions/requirements/encode/index.d.ts +0 -3
  244. package/lib/actions/requirements/getMorphoAuthorizationRequirement.d.ts +0 -21
  245. package/lib/actions/requirements/getMorphoAuthorizationRequirement.js +0 -55
  246. package/lib/actions/requirements/getRequirements.d.ts +0 -42
  247. package/lib/actions/requirements/getRequirements.js +0 -80
  248. package/lib/actions/requirements/getRequirementsAction.d.ts +0 -17
  249. package/lib/actions/requirements/getRequirementsApproval.d.ts +0 -31
  250. package/lib/actions/requirements/getRequirementsApproval.js +0 -51
  251. package/lib/actions/requirements/getRequirementsPermit.d.ts +0 -28
  252. package/lib/actions/requirements/getRequirementsPermit.js +0 -40
  253. package/lib/actions/requirements/getRequirementsPermit2.d.ts +0 -37
  254. package/lib/actions/requirements/getRequirementsPermit2.js +0 -59
  255. package/lib/actions/requirements/index.d.ts +0 -6
  256. package/lib/actions/vaultV1/deposit.d.ts +0 -41
  257. package/lib/actions/vaultV1/deposit.js +0 -116
  258. package/lib/actions/vaultV1/index.d.ts +0 -4
  259. package/lib/actions/vaultV1/migrateToV2.d.ts +0 -50
  260. package/lib/actions/vaultV1/migrateToV2.js +0 -108
  261. package/lib/actions/vaultV1/redeem.d.ts +0 -29
  262. package/lib/actions/vaultV1/redeem.js +0 -48
  263. package/lib/actions/vaultV1/withdraw.d.ts +0 -29
  264. package/lib/actions/vaultV1/withdraw.js +0 -48
  265. package/lib/actions/vaultV2/deposit.d.ts +0 -41
  266. package/lib/actions/vaultV2/deposit.js +0 -116
  267. package/lib/actions/vaultV2/forceRedeem.d.ts +0 -48
  268. package/lib/actions/vaultV2/forceRedeem.js +0 -85
  269. package/lib/actions/vaultV2/forceWithdraw.d.ts +0 -40
  270. package/lib/actions/vaultV2/forceWithdraw.js +0 -77
  271. package/lib/actions/vaultV2/index.d.ts +0 -5
  272. package/lib/actions/vaultV2/redeem.d.ts +0 -32
  273. package/lib/actions/vaultV2/redeem.js +0 -51
  274. package/lib/actions/vaultV2/withdraw.d.ts +0 -32
  275. package/lib/actions/vaultV2/withdraw.js +0 -51
  276. package/lib/client/index.d.ts +0 -2
  277. package/lib/client/morphoClient.d.ts +0 -25
  278. package/lib/client/morphoClient.js +0 -28
  279. package/lib/client/morphoViemExtension.d.ts +0 -39
  280. package/lib/client/morphoViemExtension.js +0 -40
  281. package/lib/entities/index.d.ts +0 -3
  282. package/lib/entities/marketV1/index.d.ts +0 -1
  283. package/lib/entities/vaultV1/index.d.ts +0 -1
  284. package/lib/entities/vaultV2/index.d.ts +0 -1
  285. package/lib/index.d.ts +0 -5
  286. package/lib/index.js +0 -21
  287. package/lib/types/index.d.ts +0 -7
  288. package/lib/types/index.js +0 -23
  289. /package/lib/{helpers → cjs/helpers}/constant.d.ts +0 -0
  290. /package/lib/{helpers → cjs/helpers}/constant.js +0 -0
  291. /package/lib/{helpers → cjs/helpers}/metadata.js +0 -0
  292. /package/lib/{helpers → cjs/helpers}/slippage.d.ts +0 -0
  293. /package/lib/{types → cjs/types}/action.js +0 -0
  294. /package/lib/{types → cjs/types}/client.js +0 -0
  295. /package/lib/{types → cjs/types}/data.d.ts +0 -0
  296. /package/lib/{types → cjs/types}/data.js +0 -0
  297. /package/lib/{types → cjs/types}/deallocation.d.ts +0 -0
  298. /package/lib/{types → cjs/types}/deallocation.js +0 -0
  299. /package/lib/{types → cjs/types}/entity.d.ts +0 -0
  300. /package/lib/{types → cjs/types}/entity.js +0 -0
  301. /package/lib/{types → cjs/types}/metadata.d.ts +0 -0
  302. /package/lib/{types → cjs/types}/metadata.js +0 -0
  303. /package/lib/{types → cjs/types}/sharedLiquidity.d.ts +0 -0
  304. /package/lib/{types → cjs/types}/sharedLiquidity.js +0 -0
@@ -0,0 +1,94 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.vaultV2ForceWithdraw = void 0;
4
+ const blue_sdk_viem_1 = require("@morpho-org/blue-sdk-viem");
5
+ const morpho_ts_1 = require("@morpho-org/morpho-ts");
6
+ const viem_1 = require("viem");
7
+ const encodeDeallocation_js_1 = require("../../helpers/encodeDeallocation.js");
8
+ const index_js_1 = require("../../helpers/index.js");
9
+ const index_js_2 = require("../../types/index.js");
10
+ /**
11
+ * Prepares a force-withdraw transaction for a VaultV2 contract via the vault's native `multicall`.
12
+ *
13
+ * Encodes one or more `forceDeallocate` calls followed by a single `withdraw`, executed
14
+ * atomically through VaultV2's `multicall`. Frees liquidity from non-liquidity adapters and
15
+ * withdraws the resulting assets in one transaction.
16
+ *
17
+ * A penalty is taken from `onBehalf` for each deallocation to discourage allocation
18
+ * manipulation. The penalty is applied as a share burn where assets are returned to the vault,
19
+ * so the share price stays stable (except for rounding).
20
+ *
21
+ * @param params.vault.address - The VaultV2 address.
22
+ * @param params.args.deallocations - The deallocations to perform before withdrawing. Must be
23
+ * non-empty.
24
+ * @param params.args.withdraw.amount - Amount of underlying assets to withdraw after the
25
+ * deallocations complete.
26
+ * @param params.args.withdraw.recipient - Address that receives the withdrawn assets.
27
+ * @param params.args.onBehalf - Address whose shares are burned and from which the deallocation
28
+ * penalty is taken.
29
+ * @param params.metadata - Optional analytics metadata attached to the multicall transaction.
30
+ * @returns A deep-frozen `Transaction<VaultV2ForceWithdrawAction>` with `to`, `value`, `data`,
31
+ * and the typed `action` discriminator the simulation layer consumes.
32
+ * @throws {EmptyDeallocationsError} when `deallocations` is empty.
33
+ * @throws {NonPositiveAssetAmountError} when `withdraw.amount <= 0n`, or when any
34
+ * `deallocations[i].amount <= 0n` (raised by `encodeForceDeallocateCall`).
35
+ * @example
36
+ * ```ts
37
+ * import { vaultV2ForceWithdraw } from "@morpho-org/morpho-sdk";
38
+ *
39
+ * const tx = vaultV2ForceWithdraw({
40
+ * vault: { address: vaultAddress },
41
+ * args: {
42
+ * deallocations: [{ adapter, marketParams, amount: 500_000n }],
43
+ * withdraw: { amount: 500_000n, recipient },
44
+ * onBehalf,
45
+ * },
46
+ * });
47
+ * // tx satisfies Readonly<Transaction<VaultV2ForceWithdrawAction>>
48
+ * ```
49
+ */
50
+ const vaultV2ForceWithdraw = ({ vault: { address: vaultAddress }, args: { deallocations, withdraw, onBehalf }, metadata, }) => {
51
+ if (deallocations.length === 0) {
52
+ throw new index_js_2.EmptyDeallocationsError(vaultAddress);
53
+ }
54
+ if (withdraw.amount <= 0n) {
55
+ throw new index_js_2.NonPositiveAssetAmountError(vaultAddress);
56
+ }
57
+ const calls = [];
58
+ for (const deallocation of deallocations) {
59
+ calls.push((0, encodeDeallocation_js_1.encodeForceDeallocateCall)(deallocation, onBehalf));
60
+ }
61
+ calls.push((0, viem_1.encodeFunctionData)({
62
+ abi: blue_sdk_viem_1.vaultV2Abi,
63
+ functionName: "withdraw",
64
+ args: [withdraw.amount, withdraw.recipient, onBehalf],
65
+ }));
66
+ let tx = {
67
+ to: vaultAddress,
68
+ data: (0, viem_1.encodeFunctionData)({
69
+ abi: blue_sdk_viem_1.vaultV2Abi,
70
+ functionName: "multicall",
71
+ args: [calls],
72
+ }),
73
+ value: 0n,
74
+ };
75
+ if (metadata) {
76
+ tx = (0, index_js_1.addTransactionMetadata)(tx, metadata);
77
+ }
78
+ return (0, morpho_ts_1.deepFreeze)({
79
+ ...tx,
80
+ action: {
81
+ type: "vaultV2ForceWithdraw",
82
+ args: {
83
+ vault: vaultAddress,
84
+ deallocations: deallocations.map((d) => ({ ...d })),
85
+ withdraw: {
86
+ amount: withdraw.amount,
87
+ recipient: withdraw.recipient,
88
+ },
89
+ onBehalf,
90
+ },
91
+ },
92
+ });
93
+ };
94
+ exports.vaultV2ForceWithdraw = vaultV2ForceWithdraw;
@@ -0,0 +1,5 @@
1
+ export * from "./deposit.js";
2
+ export * from "./forceRedeem.js";
3
+ export * from "./forceWithdraw.js";
4
+ export * from "./redeem.js";
5
+ export * from "./withdraw.js";
@@ -14,8 +14,8 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
14
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
- __exportStar(require("./deposit"), exports);
18
- __exportStar(require("./forceRedeem"), exports);
19
- __exportStar(require("./forceWithdraw"), exports);
20
- __exportStar(require("./redeem"), exports);
21
- __exportStar(require("./withdraw"), exports);
17
+ __exportStar(require("./deposit.js"), exports);
18
+ __exportStar(require("./forceRedeem.js"), exports);
19
+ __exportStar(require("./forceWithdraw.js"), exports);
20
+ __exportStar(require("./redeem.js"), exports);
21
+ __exportStar(require("./withdraw.js"), exports);
@@ -0,0 +1,40 @@
1
+ import { type Address } from "viem";
2
+ import { type Metadata, type Transaction, type VaultV2RedeemAction } from "../../types/index.js";
3
+ /** Parameters for {@link vaultV2Redeem}. */
4
+ export interface VaultV2RedeemParams {
5
+ vault: {
6
+ address: Address;
7
+ };
8
+ args: {
9
+ shares: bigint;
10
+ recipient: Address;
11
+ onBehalf: Address;
12
+ };
13
+ metadata?: Metadata;
14
+ }
15
+ /**
16
+ * Prepares a redeem transaction for a VaultV2 contract.
17
+ *
18
+ * Direct vault call — not routed through the bundler. Redeem has no inflation-attack surface,
19
+ * so skipping the bundler avoids an unnecessary approval and keeps the UX clean.
20
+ *
21
+ * @param params.vault.address - The VaultV2 address.
22
+ * @param params.args.shares - Amount of vault shares to redeem.
23
+ * @param params.args.recipient - Address that receives the redeemed assets.
24
+ * @param params.args.onBehalf - Address whose shares are burned.
25
+ * @param params.metadata - Optional analytics metadata attached to the transaction.
26
+ * @returns A deep-frozen `Transaction<VaultV2RedeemAction>` with `to`, `value`, `data`, and the
27
+ * typed `action` discriminator the simulation layer consumes.
28
+ * @throws {NonPositiveSharesAmountError} when `shares <= 0n`.
29
+ * @example
30
+ * ```ts
31
+ * import { vaultV2Redeem } from "@morpho-org/morpho-sdk";
32
+ *
33
+ * const tx = vaultV2Redeem({
34
+ * vault: { address: vaultAddress },
35
+ * args: { shares: 1_000_000n, recipient, onBehalf },
36
+ * });
37
+ * // tx satisfies Readonly<Transaction<VaultV2RedeemAction>>
38
+ * ```
39
+ */
40
+ export declare const vaultV2Redeem: ({ vault: { address: vaultAddress }, args: { shares, recipient, onBehalf }, metadata, }: VaultV2RedeemParams) => Readonly<Transaction<VaultV2RedeemAction>>;
@@ -0,0 +1,58 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.vaultV2Redeem = void 0;
4
+ const blue_sdk_viem_1 = require("@morpho-org/blue-sdk-viem");
5
+ const morpho_ts_1 = require("@morpho-org/morpho-ts");
6
+ const viem_1 = require("viem");
7
+ const index_js_1 = require("../../helpers/index.js");
8
+ const index_js_2 = require("../../types/index.js");
9
+ /**
10
+ * Prepares a redeem transaction for a VaultV2 contract.
11
+ *
12
+ * Direct vault call — not routed through the bundler. Redeem has no inflation-attack surface,
13
+ * so skipping the bundler avoids an unnecessary approval and keeps the UX clean.
14
+ *
15
+ * @param params.vault.address - The VaultV2 address.
16
+ * @param params.args.shares - Amount of vault shares to redeem.
17
+ * @param params.args.recipient - Address that receives the redeemed assets.
18
+ * @param params.args.onBehalf - Address whose shares are burned.
19
+ * @param params.metadata - Optional analytics metadata attached to the transaction.
20
+ * @returns A deep-frozen `Transaction<VaultV2RedeemAction>` with `to`, `value`, `data`, and the
21
+ * typed `action` discriminator the simulation layer consumes.
22
+ * @throws {NonPositiveSharesAmountError} when `shares <= 0n`.
23
+ * @example
24
+ * ```ts
25
+ * import { vaultV2Redeem } from "@morpho-org/morpho-sdk";
26
+ *
27
+ * const tx = vaultV2Redeem({
28
+ * vault: { address: vaultAddress },
29
+ * args: { shares: 1_000_000n, recipient, onBehalf },
30
+ * });
31
+ * // tx satisfies Readonly<Transaction<VaultV2RedeemAction>>
32
+ * ```
33
+ */
34
+ const vaultV2Redeem = ({ vault: { address: vaultAddress }, args: { shares, recipient, onBehalf }, metadata, }) => {
35
+ if (shares <= 0n) {
36
+ throw new index_js_2.NonPositiveSharesAmountError(vaultAddress);
37
+ }
38
+ let tx = {
39
+ to: vaultAddress,
40
+ data: (0, viem_1.encodeFunctionData)({
41
+ abi: blue_sdk_viem_1.vaultV2Abi,
42
+ functionName: "redeem",
43
+ args: [shares, recipient, onBehalf],
44
+ }),
45
+ value: 0n,
46
+ };
47
+ if (metadata) {
48
+ tx = (0, index_js_1.addTransactionMetadata)(tx, metadata);
49
+ }
50
+ return (0, morpho_ts_1.deepFreeze)({
51
+ ...tx,
52
+ action: {
53
+ type: "vaultV2Redeem",
54
+ args: { vault: vaultAddress, shares, recipient },
55
+ },
56
+ });
57
+ };
58
+ exports.vaultV2Redeem = vaultV2Redeem;
@@ -0,0 +1,40 @@
1
+ import { type Address } from "viem";
2
+ import { type Metadata, type Transaction, type VaultV2WithdrawAction } from "../../types/index.js";
3
+ /** Parameters for {@link vaultV2Withdraw}. */
4
+ export interface VaultV2WithdrawParams {
5
+ vault: {
6
+ address: Address;
7
+ };
8
+ args: {
9
+ amount: bigint;
10
+ recipient: Address;
11
+ onBehalf: Address;
12
+ };
13
+ metadata?: Metadata;
14
+ }
15
+ /**
16
+ * Prepares a withdraw transaction for a VaultV2 contract.
17
+ *
18
+ * Direct vault call — not routed through the bundler. Withdraw has no inflation-attack surface,
19
+ * so skipping the bundler avoids an unnecessary approval and keeps the UX clean.
20
+ *
21
+ * @param params.vault.address - The VaultV2 address.
22
+ * @param params.args.amount - Amount of underlying assets to withdraw.
23
+ * @param params.args.recipient - Address that receives the withdrawn assets.
24
+ * @param params.args.onBehalf - Address whose shares are burned.
25
+ * @param params.metadata - Optional analytics metadata attached to the transaction.
26
+ * @returns A deep-frozen `Transaction<VaultV2WithdrawAction>` with `to`, `value`, `data`, and the
27
+ * typed `action` discriminator the simulation layer consumes.
28
+ * @throws {NonPositiveAssetAmountError} when `amount <= 0n`.
29
+ * @example
30
+ * ```ts
31
+ * import { vaultV2Withdraw } from "@morpho-org/morpho-sdk";
32
+ *
33
+ * const tx = vaultV2Withdraw({
34
+ * vault: { address: vaultAddress },
35
+ * args: { amount: 500_000n, recipient, onBehalf },
36
+ * });
37
+ * // tx satisfies Readonly<Transaction<VaultV2WithdrawAction>>
38
+ * ```
39
+ */
40
+ export declare const vaultV2Withdraw: ({ vault: { address: vaultAddress }, args: { amount, recipient, onBehalf }, metadata, }: VaultV2WithdrawParams) => Readonly<Transaction<VaultV2WithdrawAction>>;
@@ -0,0 +1,58 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.vaultV2Withdraw = void 0;
4
+ const blue_sdk_viem_1 = require("@morpho-org/blue-sdk-viem");
5
+ const morpho_ts_1 = require("@morpho-org/morpho-ts");
6
+ const viem_1 = require("viem");
7
+ const index_js_1 = require("../../helpers/index.js");
8
+ const index_js_2 = require("../../types/index.js");
9
+ /**
10
+ * Prepares a withdraw transaction for a VaultV2 contract.
11
+ *
12
+ * Direct vault call — not routed through the bundler. Withdraw has no inflation-attack surface,
13
+ * so skipping the bundler avoids an unnecessary approval and keeps the UX clean.
14
+ *
15
+ * @param params.vault.address - The VaultV2 address.
16
+ * @param params.args.amount - Amount of underlying assets to withdraw.
17
+ * @param params.args.recipient - Address that receives the withdrawn assets.
18
+ * @param params.args.onBehalf - Address whose shares are burned.
19
+ * @param params.metadata - Optional analytics metadata attached to the transaction.
20
+ * @returns A deep-frozen `Transaction<VaultV2WithdrawAction>` with `to`, `value`, `data`, and the
21
+ * typed `action` discriminator the simulation layer consumes.
22
+ * @throws {NonPositiveAssetAmountError} when `amount <= 0n`.
23
+ * @example
24
+ * ```ts
25
+ * import { vaultV2Withdraw } from "@morpho-org/morpho-sdk";
26
+ *
27
+ * const tx = vaultV2Withdraw({
28
+ * vault: { address: vaultAddress },
29
+ * args: { amount: 500_000n, recipient, onBehalf },
30
+ * });
31
+ * // tx satisfies Readonly<Transaction<VaultV2WithdrawAction>>
32
+ * ```
33
+ */
34
+ const vaultV2Withdraw = ({ vault: { address: vaultAddress }, args: { amount, recipient, onBehalf }, metadata, }) => {
35
+ if (amount <= 0n) {
36
+ throw new index_js_2.NonPositiveAssetAmountError(vaultAddress);
37
+ }
38
+ let tx = {
39
+ to: vaultAddress,
40
+ data: (0, viem_1.encodeFunctionData)({
41
+ abi: blue_sdk_viem_1.vaultV2Abi,
42
+ functionName: "withdraw",
43
+ args: [amount, recipient, onBehalf],
44
+ }),
45
+ value: 0n,
46
+ };
47
+ if (metadata) {
48
+ tx = (0, index_js_1.addTransactionMetadata)(tx, metadata);
49
+ }
50
+ return (0, morpho_ts_1.deepFreeze)({
51
+ ...tx,
52
+ action: {
53
+ type: "vaultV2Withdraw",
54
+ args: { vault: vaultAddress, amount, recipient },
55
+ },
56
+ });
57
+ };
58
+ exports.vaultV2Withdraw = vaultV2Withdraw;
@@ -0,0 +1,2 @@
1
+ export * from "./morphoClient.js";
2
+ export * from "./morphoViemExtension.js";
@@ -14,5 +14,5 @@ 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("./morphoClient"), exports);
18
- __exportStar(require("./morphoViemExtension"), exports);
17
+ __exportStar(require("./morphoClient.js"), exports);
18
+ __exportStar(require("./morphoViemExtension.js"), exports);
@@ -0,0 +1,113 @@
1
+ import { type MarketParams } from "@morpho-org/blue-sdk";
2
+ import type { Address, Client } from "viem";
3
+ import { MorphoMarketV1, MorphoVaultV1, MorphoVaultV2 } from "../entities/index.js";
4
+ import { type Metadata, type MorphoClientType } from "../types/index.js";
5
+ /**
6
+ * Stateless entry point of the SDK. Wraps a viem `Client` plus a frozen options bag and exposes
7
+ * factory methods for the protocol entities.
8
+ *
9
+ * Holds no state beyond configuration: no cache, no `init()`, no warm-up. Each factory call
10
+ * (`vaultV1`, `vaultV2`, `marketV1`) returns a fresh entity bound to this client.
11
+ */
12
+ export declare class MorphoClient implements MorphoClientType {
13
+ readonly viemClient: Client;
14
+ readonly _options?: {
15
+ readonly supportSignature?: boolean;
16
+ readonly supportDeployless?: boolean;
17
+ readonly metadata?: Metadata;
18
+ } | undefined;
19
+ /** SDK-wide options resolved from the constructor's `_options` argument. */
20
+ readonly options: {
21
+ readonly supportSignature: boolean;
22
+ readonly supportDeployless?: boolean;
23
+ readonly metadata?: Metadata;
24
+ };
25
+ /**
26
+ * @param viemClient - Connected viem `Client`. Public reads use it as-is; signature flows use
27
+ * it as a `WalletClient` and require `account` to be set.
28
+ * @param _options - SDK-wide options.
29
+ * @param _options.supportSignature - Whether the integrator can collect EIP-712 signatures for
30
+ * permit / permit2. Defaults to `false` (classic approvals only).
31
+ * @param _options.supportDeployless - Whether entity fetchers may use deployless multicall.
32
+ * @param _options.metadata - Optional analytics metadata applied to every transaction this
33
+ * client builds.
34
+ * @example
35
+ * ```ts
36
+ * import { createWalletClient, http } from "viem";
37
+ * import { mainnet } from "viem/chains";
38
+ * import { MorphoClient } from "@morpho-org/morpho-sdk";
39
+ *
40
+ * const client = new MorphoClient(
41
+ * createWalletClient({ chain: mainnet, transport: http(), account: user }),
42
+ * { supportSignature: true },
43
+ * );
44
+ * ```
45
+ */
46
+ constructor(viemClient: Client, _options?: {
47
+ readonly supportSignature?: boolean;
48
+ readonly supportDeployless?: boolean;
49
+ readonly metadata?: Metadata;
50
+ } | undefined);
51
+ /**
52
+ * Returns a `MorphoVaultV1` (MetaMorpho) entity bound to this client.
53
+ *
54
+ * @param vault - VaultV1 address.
55
+ * @param chainId - Chain the vault lives on.
56
+ * @returns A fresh `MorphoVaultV1` entity.
57
+ * @example
58
+ * ```ts
59
+ * const vault = client.vaultV1(vaultAddress, 1);
60
+ * const accrualVault = await vault.getData();
61
+ * const { buildTx } = vault.deposit({
62
+ * amount: 1_000_000n,
63
+ * userAddress: depositor,
64
+ * accrualVault,
65
+ * });
66
+ * const tx = buildTx();
67
+ * ```
68
+ */
69
+ vaultV1(vault: Address, chainId: number): MorphoVaultV1;
70
+ /**
71
+ * Returns a `MorphoVaultV2` entity bound to this client.
72
+ *
73
+ * @param vault - VaultV2 address.
74
+ * @param chainId - Chain the vault lives on.
75
+ * @returns A fresh `MorphoVaultV2` entity.
76
+ * @example
77
+ * ```ts
78
+ * const vault = client.vaultV2(vaultAddress, 1);
79
+ * const accrualVault = await vault.getData();
80
+ * const { buildTx } = vault.deposit({
81
+ * amount: 1_000_000n,
82
+ * userAddress: depositor,
83
+ * accrualVault,
84
+ * });
85
+ * const tx = buildTx();
86
+ * ```
87
+ */
88
+ vaultV2(vault: Address, chainId: number): MorphoVaultV2;
89
+ /**
90
+ * Returns a `MorphoMarketV1` entity bound to this client. Validates that the supplied
91
+ * `marketParams.id` matches the hash of the other params, so a hand-rolled or agent-written
92
+ * `MarketParams` cannot point at the wrong market silently.
93
+ *
94
+ * @param marketParams - Market params (`loanToken`, `collateralToken`, `oracle`, `irm`, `lltv`,
95
+ * `id`).
96
+ * @param chainId - Chain the market lives on.
97
+ * @returns A fresh `MorphoMarketV1` entity.
98
+ * @throws {MarketIdMismatchError} when `marketParams.id` does not equal the hash derived from
99
+ * the other fields.
100
+ * @example
101
+ * ```ts
102
+ * const market = client.marketV1(marketParams, 1);
103
+ * const positionData = await market.getPositionData(borrower);
104
+ * const { buildTx } = market.borrow({
105
+ * userAddress: borrower,
106
+ * amount: 1_000_000n,
107
+ * positionData,
108
+ * });
109
+ * const tx = buildTx();
110
+ * ```
111
+ */
112
+ marketV1(marketParams: MarketParams, chainId: number): MorphoMarketV1;
113
+ }
@@ -0,0 +1,123 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.MorphoClient = void 0;
4
+ const blue_sdk_1 = require("@morpho-org/blue-sdk");
5
+ const index_js_1 = require("../entities/index.js");
6
+ const index_js_2 = require("../types/index.js");
7
+ /**
8
+ * Stateless entry point of the SDK. Wraps a viem `Client` plus a frozen options bag and exposes
9
+ * factory methods for the protocol entities.
10
+ *
11
+ * Holds no state beyond configuration: no cache, no `init()`, no warm-up. Each factory call
12
+ * (`vaultV1`, `vaultV2`, `marketV1`) returns a fresh entity bound to this client.
13
+ */
14
+ class MorphoClient {
15
+ viemClient;
16
+ _options;
17
+ /** SDK-wide options resolved from the constructor's `_options` argument. */
18
+ options;
19
+ /**
20
+ * @param viemClient - Connected viem `Client`. Public reads use it as-is; signature flows use
21
+ * it as a `WalletClient` and require `account` to be set.
22
+ * @param _options - SDK-wide options.
23
+ * @param _options.supportSignature - Whether the integrator can collect EIP-712 signatures for
24
+ * permit / permit2. Defaults to `false` (classic approvals only).
25
+ * @param _options.supportDeployless - Whether entity fetchers may use deployless multicall.
26
+ * @param _options.metadata - Optional analytics metadata applied to every transaction this
27
+ * client builds.
28
+ * @example
29
+ * ```ts
30
+ * import { createWalletClient, http } from "viem";
31
+ * import { mainnet } from "viem/chains";
32
+ * import { MorphoClient } from "@morpho-org/morpho-sdk";
33
+ *
34
+ * const client = new MorphoClient(
35
+ * createWalletClient({ chain: mainnet, transport: http(), account: user }),
36
+ * { supportSignature: true },
37
+ * );
38
+ * ```
39
+ */
40
+ constructor(viemClient, _options) {
41
+ this.viemClient = viemClient;
42
+ this._options = _options;
43
+ this.options = {
44
+ ..._options,
45
+ supportSignature: _options?.supportSignature ?? false,
46
+ supportDeployless: _options?.supportDeployless,
47
+ };
48
+ }
49
+ /**
50
+ * Returns a `MorphoVaultV1` (MetaMorpho) entity bound to this client.
51
+ *
52
+ * @param vault - VaultV1 address.
53
+ * @param chainId - Chain the vault lives on.
54
+ * @returns A fresh `MorphoVaultV1` entity.
55
+ * @example
56
+ * ```ts
57
+ * const vault = client.vaultV1(vaultAddress, 1);
58
+ * const accrualVault = await vault.getData();
59
+ * const { buildTx } = vault.deposit({
60
+ * amount: 1_000_000n,
61
+ * userAddress: depositor,
62
+ * accrualVault,
63
+ * });
64
+ * const tx = buildTx();
65
+ * ```
66
+ */
67
+ vaultV1(vault, chainId) {
68
+ return new index_js_1.MorphoVaultV1(this, vault, chainId);
69
+ }
70
+ /**
71
+ * Returns a `MorphoVaultV2` entity bound to this client.
72
+ *
73
+ * @param vault - VaultV2 address.
74
+ * @param chainId - Chain the vault lives on.
75
+ * @returns A fresh `MorphoVaultV2` entity.
76
+ * @example
77
+ * ```ts
78
+ * const vault = client.vaultV2(vaultAddress, 1);
79
+ * const accrualVault = await vault.getData();
80
+ * const { buildTx } = vault.deposit({
81
+ * amount: 1_000_000n,
82
+ * userAddress: depositor,
83
+ * accrualVault,
84
+ * });
85
+ * const tx = buildTx();
86
+ * ```
87
+ */
88
+ vaultV2(vault, chainId) {
89
+ return new index_js_1.MorphoVaultV2(this, vault, chainId);
90
+ }
91
+ /**
92
+ * Returns a `MorphoMarketV1` entity bound to this client. Validates that the supplied
93
+ * `marketParams.id` matches the hash of the other params, so a hand-rolled or agent-written
94
+ * `MarketParams` cannot point at the wrong market silently.
95
+ *
96
+ * @param marketParams - Market params (`loanToken`, `collateralToken`, `oracle`, `irm`, `lltv`,
97
+ * `id`).
98
+ * @param chainId - Chain the market lives on.
99
+ * @returns A fresh `MorphoMarketV1` entity.
100
+ * @throws {MarketIdMismatchError} when `marketParams.id` does not equal the hash derived from
101
+ * the other fields.
102
+ * @example
103
+ * ```ts
104
+ * const market = client.marketV1(marketParams, 1);
105
+ * const positionData = await market.getPositionData(borrower);
106
+ * const { buildTx } = market.borrow({
107
+ * userAddress: borrower,
108
+ * amount: 1_000_000n,
109
+ * positionData,
110
+ * });
111
+ * const tx = buildTx();
112
+ * ```
113
+ */
114
+ marketV1(marketParams, chainId) {
115
+ const derivedId = blue_sdk_1.MarketUtils.getMarketId(marketParams);
116
+ // Can happen with one-time/hardcoded/agent-written possibly inconsistent input market params.
117
+ if (marketParams.id !== derivedId) {
118
+ throw new index_js_2.MarketIdMismatchError(marketParams.id, derivedId);
119
+ }
120
+ return new index_js_1.MorphoMarketV1(this, marketParams, chainId);
121
+ }
122
+ }
123
+ exports.MorphoClient = MorphoClient;
@@ -0,0 +1,45 @@
1
+ import type { Client } from "viem";
2
+ import type { Metadata } from "../types/index.js";
3
+ import { MorphoClient } from "./morphoClient.js";
4
+ /**
5
+ * Returns a viem `extend(...)` function that adds a `morpho` namespace to a viem client. The
6
+ * namespace exposes a `MorphoClient` instance built from the same client and the supplied
7
+ * options.
8
+ *
9
+ * @param _options - Optional SDK-wide options forwarded to the inner `MorphoClient`.
10
+ * @param _options.metadata - Optional analytics metadata applied to every transaction the
11
+ * resulting `MorphoClient` builds.
12
+ * @param _options.supportSignature - Whether the integrator can collect EIP-712 signatures for
13
+ * permit / permit2.
14
+ * @param _options.supportDeployless - Whether entity fetchers may use deployless multicall.
15
+ * @returns A viem extension function — `client.extend(morphoViemExtension(...))` adds
16
+ * `client.morpho`.
17
+ * @example
18
+ * ```ts
19
+ * import { createWalletClient, http } from "viem";
20
+ * import { mainnet } from "viem/chains";
21
+ * import { morphoViemExtension } from "@morpho-org/morpho-sdk";
22
+ *
23
+ * const client = createWalletClient({
24
+ * chain: mainnet,
25
+ * transport: http(),
26
+ * account: user,
27
+ * }).extend(morphoViemExtension({ supportSignature: true }));
28
+ *
29
+ * const vault = client.morpho.vaultV1(vaultAddress, 1);
30
+ * const accrualVault = await vault.getData();
31
+ * const { buildTx } = vault.deposit({
32
+ * amount: 1_000_000n,
33
+ * userAddress: user,
34
+ * accrualVault,
35
+ * });
36
+ * const tx = buildTx();
37
+ * ```
38
+ */
39
+ export declare function morphoViemExtension(_options?: {
40
+ readonly metadata?: Metadata;
41
+ readonly supportSignature?: boolean;
42
+ readonly supportDeployless?: boolean;
43
+ }): <TClient extends Client>(client: TClient) => {
44
+ morpho: MorphoClient;
45
+ };
@@ -0,0 +1,46 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.morphoViemExtension = morphoViemExtension;
4
+ const morphoClient_js_1 = require("./morphoClient.js");
5
+ /**
6
+ * Returns a viem `extend(...)` function that adds a `morpho` namespace to a viem client. The
7
+ * namespace exposes a `MorphoClient` instance built from the same client and the supplied
8
+ * options.
9
+ *
10
+ * @param _options - Optional SDK-wide options forwarded to the inner `MorphoClient`.
11
+ * @param _options.metadata - Optional analytics metadata applied to every transaction the
12
+ * resulting `MorphoClient` builds.
13
+ * @param _options.supportSignature - Whether the integrator can collect EIP-712 signatures for
14
+ * permit / permit2.
15
+ * @param _options.supportDeployless - Whether entity fetchers may use deployless multicall.
16
+ * @returns A viem extension function — `client.extend(morphoViemExtension(...))` adds
17
+ * `client.morpho`.
18
+ * @example
19
+ * ```ts
20
+ * import { createWalletClient, http } from "viem";
21
+ * import { mainnet } from "viem/chains";
22
+ * import { morphoViemExtension } from "@morpho-org/morpho-sdk";
23
+ *
24
+ * const client = createWalletClient({
25
+ * chain: mainnet,
26
+ * transport: http(),
27
+ * account: user,
28
+ * }).extend(morphoViemExtension({ supportSignature: true }));
29
+ *
30
+ * const vault = client.morpho.vaultV1(vaultAddress, 1);
31
+ * const accrualVault = await vault.getData();
32
+ * const { buildTx } = vault.deposit({
33
+ * amount: 1_000_000n,
34
+ * userAddress: user,
35
+ * accrualVault,
36
+ * });
37
+ * const tx = buildTx();
38
+ * ```
39
+ */
40
+ function morphoViemExtension(_options) {
41
+ return (client) => {
42
+ return {
43
+ morpho: new morphoClient_js_1.MorphoClient(client, _options),
44
+ };
45
+ };
46
+ }
@@ -0,0 +1,3 @@
1
+ export * from "./marketV1/index.js";
2
+ export * from "./vaultV1/index.js";
3
+ export * from "./vaultV2/index.js";
@@ -14,6 +14,6 @@ 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("./vaultV1"), exports);
19
- __exportStar(require("./vaultV2"), exports);
17
+ __exportStar(require("./marketV1/index.js"), exports);
18
+ __exportStar(require("./vaultV1/index.js"), exports);
19
+ __exportStar(require("./vaultV2/index.js"), exports);