@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,90 @@
1
+ import { vaultV2Abi } from "@morpho-org/blue-sdk-viem";
2
+ import { deepFreeze } from "@morpho-org/morpho-ts";
3
+ import { encodeFunctionData } from "viem";
4
+ import { encodeForceDeallocateCall } from "../../helpers/encodeDeallocation.js";
5
+ import { addTransactionMetadata } from "../../helpers/index.js";
6
+ import { EmptyDeallocationsError, NonPositiveAssetAmountError, } from "../../types/index.js";
7
+ /**
8
+ * Prepares a force-withdraw transaction for a VaultV2 contract via the vault's native `multicall`.
9
+ *
10
+ * Encodes one or more `forceDeallocate` calls followed by a single `withdraw`, executed
11
+ * atomically through VaultV2's `multicall`. Frees liquidity from non-liquidity adapters and
12
+ * withdraws the resulting assets in one transaction.
13
+ *
14
+ * A penalty is taken from `onBehalf` for each deallocation to discourage allocation
15
+ * manipulation. The penalty is applied as a share burn where assets are returned to the vault,
16
+ * so the share price stays stable (except for rounding).
17
+ *
18
+ * @param params.vault.address - The VaultV2 address.
19
+ * @param params.args.deallocations - The deallocations to perform before withdrawing. Must be
20
+ * non-empty.
21
+ * @param params.args.withdraw.amount - Amount of underlying assets to withdraw after the
22
+ * deallocations complete.
23
+ * @param params.args.withdraw.recipient - Address that receives the withdrawn assets.
24
+ * @param params.args.onBehalf - Address whose shares are burned and from which the deallocation
25
+ * penalty is taken.
26
+ * @param params.metadata - Optional analytics metadata attached to the multicall transaction.
27
+ * @returns A deep-frozen `Transaction<VaultV2ForceWithdrawAction>` with `to`, `value`, `data`,
28
+ * and the typed `action` discriminator the simulation layer consumes.
29
+ * @throws {EmptyDeallocationsError} when `deallocations` is empty.
30
+ * @throws {NonPositiveAssetAmountError} when `withdraw.amount <= 0n`, or when any
31
+ * `deallocations[i].amount <= 0n` (raised by `encodeForceDeallocateCall`).
32
+ * @example
33
+ * ```ts
34
+ * import { vaultV2ForceWithdraw } from "@morpho-org/morpho-sdk";
35
+ *
36
+ * const tx = vaultV2ForceWithdraw({
37
+ * vault: { address: vaultAddress },
38
+ * args: {
39
+ * deallocations: [{ adapter, marketParams, amount: 500_000n }],
40
+ * withdraw: { amount: 500_000n, recipient },
41
+ * onBehalf,
42
+ * },
43
+ * });
44
+ * // tx satisfies Readonly<Transaction<VaultV2ForceWithdrawAction>>
45
+ * ```
46
+ */
47
+ export const vaultV2ForceWithdraw = ({ vault: { address: vaultAddress }, args: { deallocations, withdraw, onBehalf }, metadata, }) => {
48
+ if (deallocations.length === 0) {
49
+ throw new EmptyDeallocationsError(vaultAddress);
50
+ }
51
+ if (withdraw.amount <= 0n) {
52
+ throw new NonPositiveAssetAmountError(vaultAddress);
53
+ }
54
+ const calls = [];
55
+ for (const deallocation of deallocations) {
56
+ calls.push(encodeForceDeallocateCall(deallocation, onBehalf));
57
+ }
58
+ calls.push(encodeFunctionData({
59
+ abi: vaultV2Abi,
60
+ functionName: "withdraw",
61
+ args: [withdraw.amount, withdraw.recipient, onBehalf],
62
+ }));
63
+ let tx = {
64
+ to: vaultAddress,
65
+ data: encodeFunctionData({
66
+ abi: vaultV2Abi,
67
+ functionName: "multicall",
68
+ args: [calls],
69
+ }),
70
+ value: 0n,
71
+ };
72
+ if (metadata) {
73
+ tx = addTransactionMetadata(tx, metadata);
74
+ }
75
+ return deepFreeze({
76
+ ...tx,
77
+ action: {
78
+ type: "vaultV2ForceWithdraw",
79
+ args: {
80
+ vault: vaultAddress,
81
+ deallocations: deallocations.map((d) => ({ ...d })),
82
+ withdraw: {
83
+ amount: withdraw.amount,
84
+ recipient: withdraw.recipient,
85
+ },
86
+ onBehalf,
87
+ },
88
+ },
89
+ });
90
+ };
@@ -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";
@@ -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";
@@ -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,54 @@
1
+ import { vaultV2Abi } from "@morpho-org/blue-sdk-viem";
2
+ import { deepFreeze } from "@morpho-org/morpho-ts";
3
+ import { encodeFunctionData } from "viem";
4
+ import { addTransactionMetadata } from "../../helpers/index.js";
5
+ import { NonPositiveSharesAmountError, } from "../../types/index.js";
6
+ /**
7
+ * Prepares a redeem transaction for a VaultV2 contract.
8
+ *
9
+ * Direct vault call — not routed through the bundler. Redeem has no inflation-attack surface,
10
+ * so skipping the bundler avoids an unnecessary approval and keeps the UX clean.
11
+ *
12
+ * @param params.vault.address - The VaultV2 address.
13
+ * @param params.args.shares - Amount of vault shares to redeem.
14
+ * @param params.args.recipient - Address that receives the redeemed assets.
15
+ * @param params.args.onBehalf - Address whose shares are burned.
16
+ * @param params.metadata - Optional analytics metadata attached to the transaction.
17
+ * @returns A deep-frozen `Transaction<VaultV2RedeemAction>` with `to`, `value`, `data`, and the
18
+ * typed `action` discriminator the simulation layer consumes.
19
+ * @throws {NonPositiveSharesAmountError} when `shares <= 0n`.
20
+ * @example
21
+ * ```ts
22
+ * import { vaultV2Redeem } from "@morpho-org/morpho-sdk";
23
+ *
24
+ * const tx = vaultV2Redeem({
25
+ * vault: { address: vaultAddress },
26
+ * args: { shares: 1_000_000n, recipient, onBehalf },
27
+ * });
28
+ * // tx satisfies Readonly<Transaction<VaultV2RedeemAction>>
29
+ * ```
30
+ */
31
+ export const vaultV2Redeem = ({ vault: { address: vaultAddress }, args: { shares, recipient, onBehalf }, metadata, }) => {
32
+ if (shares <= 0n) {
33
+ throw new NonPositiveSharesAmountError(vaultAddress);
34
+ }
35
+ let tx = {
36
+ to: vaultAddress,
37
+ data: encodeFunctionData({
38
+ abi: vaultV2Abi,
39
+ functionName: "redeem",
40
+ args: [shares, recipient, onBehalf],
41
+ }),
42
+ value: 0n,
43
+ };
44
+ if (metadata) {
45
+ tx = addTransactionMetadata(tx, metadata);
46
+ }
47
+ return deepFreeze({
48
+ ...tx,
49
+ action: {
50
+ type: "vaultV2Redeem",
51
+ args: { vault: vaultAddress, shares, recipient },
52
+ },
53
+ });
54
+ };
@@ -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,54 @@
1
+ import { vaultV2Abi } from "@morpho-org/blue-sdk-viem";
2
+ import { deepFreeze } from "@morpho-org/morpho-ts";
3
+ import { encodeFunctionData } from "viem";
4
+ import { addTransactionMetadata } from "../../helpers/index.js";
5
+ import { NonPositiveAssetAmountError, } from "../../types/index.js";
6
+ /**
7
+ * Prepares a withdraw transaction for a VaultV2 contract.
8
+ *
9
+ * Direct vault call — not routed through the bundler. Withdraw has no inflation-attack surface,
10
+ * so skipping the bundler avoids an unnecessary approval and keeps the UX clean.
11
+ *
12
+ * @param params.vault.address - The VaultV2 address.
13
+ * @param params.args.amount - Amount of underlying assets to withdraw.
14
+ * @param params.args.recipient - Address that receives the withdrawn assets.
15
+ * @param params.args.onBehalf - Address whose shares are burned.
16
+ * @param params.metadata - Optional analytics metadata attached to the transaction.
17
+ * @returns A deep-frozen `Transaction<VaultV2WithdrawAction>` with `to`, `value`, `data`, and the
18
+ * typed `action` discriminator the simulation layer consumes.
19
+ * @throws {NonPositiveAssetAmountError} when `amount <= 0n`.
20
+ * @example
21
+ * ```ts
22
+ * import { vaultV2Withdraw } from "@morpho-org/morpho-sdk";
23
+ *
24
+ * const tx = vaultV2Withdraw({
25
+ * vault: { address: vaultAddress },
26
+ * args: { amount: 500_000n, recipient, onBehalf },
27
+ * });
28
+ * // tx satisfies Readonly<Transaction<VaultV2WithdrawAction>>
29
+ * ```
30
+ */
31
+ export const vaultV2Withdraw = ({ vault: { address: vaultAddress }, args: { amount, recipient, onBehalf }, metadata, }) => {
32
+ if (amount <= 0n) {
33
+ throw new NonPositiveAssetAmountError(vaultAddress);
34
+ }
35
+ let tx = {
36
+ to: vaultAddress,
37
+ data: encodeFunctionData({
38
+ abi: vaultV2Abi,
39
+ functionName: "withdraw",
40
+ args: [amount, recipient, onBehalf],
41
+ }),
42
+ value: 0n,
43
+ };
44
+ if (metadata) {
45
+ tx = addTransactionMetadata(tx, metadata);
46
+ }
47
+ return deepFreeze({
48
+ ...tx,
49
+ action: {
50
+ type: "vaultV2Withdraw",
51
+ args: { vault: vaultAddress, amount, recipient },
52
+ },
53
+ });
54
+ };
@@ -0,0 +1,2 @@
1
+ export * from "./morphoClient.js";
2
+ export * from "./morphoViemExtension.js";
@@ -0,0 +1,2 @@
1
+ export * from "./morphoClient.js";
2
+ export * from "./morphoViemExtension.js";
@@ -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,119 @@
1
+ import { MarketUtils } from "@morpho-org/blue-sdk";
2
+ import { MorphoMarketV1, MorphoVaultV1, MorphoVaultV2, } from "../entities/index.js";
3
+ import { MarketIdMismatchError, } from "../types/index.js";
4
+ /**
5
+ * Stateless entry point of the SDK. Wraps a viem `Client` plus a frozen options bag and exposes
6
+ * factory methods for the protocol entities.
7
+ *
8
+ * Holds no state beyond configuration: no cache, no `init()`, no warm-up. Each factory call
9
+ * (`vaultV1`, `vaultV2`, `marketV1`) returns a fresh entity bound to this client.
10
+ */
11
+ export class MorphoClient {
12
+ viemClient;
13
+ _options;
14
+ /** SDK-wide options resolved from the constructor's `_options` argument. */
15
+ options;
16
+ /**
17
+ * @param viemClient - Connected viem `Client`. Public reads use it as-is; signature flows use
18
+ * it as a `WalletClient` and require `account` to be set.
19
+ * @param _options - SDK-wide options.
20
+ * @param _options.supportSignature - Whether the integrator can collect EIP-712 signatures for
21
+ * permit / permit2. Defaults to `false` (classic approvals only).
22
+ * @param _options.supportDeployless - Whether entity fetchers may use deployless multicall.
23
+ * @param _options.metadata - Optional analytics metadata applied to every transaction this
24
+ * client builds.
25
+ * @example
26
+ * ```ts
27
+ * import { createWalletClient, http } from "viem";
28
+ * import { mainnet } from "viem/chains";
29
+ * import { MorphoClient } from "@morpho-org/morpho-sdk";
30
+ *
31
+ * const client = new MorphoClient(
32
+ * createWalletClient({ chain: mainnet, transport: http(), account: user }),
33
+ * { supportSignature: true },
34
+ * );
35
+ * ```
36
+ */
37
+ constructor(viemClient, _options) {
38
+ this.viemClient = viemClient;
39
+ this._options = _options;
40
+ this.options = {
41
+ ..._options,
42
+ supportSignature: _options?.supportSignature ?? false,
43
+ supportDeployless: _options?.supportDeployless,
44
+ };
45
+ }
46
+ /**
47
+ * Returns a `MorphoVaultV1` (MetaMorpho) entity bound to this client.
48
+ *
49
+ * @param vault - VaultV1 address.
50
+ * @param chainId - Chain the vault lives on.
51
+ * @returns A fresh `MorphoVaultV1` entity.
52
+ * @example
53
+ * ```ts
54
+ * const vault = client.vaultV1(vaultAddress, 1);
55
+ * const accrualVault = await vault.getData();
56
+ * const { buildTx } = vault.deposit({
57
+ * amount: 1_000_000n,
58
+ * userAddress: depositor,
59
+ * accrualVault,
60
+ * });
61
+ * const tx = buildTx();
62
+ * ```
63
+ */
64
+ vaultV1(vault, chainId) {
65
+ return new MorphoVaultV1(this, vault, chainId);
66
+ }
67
+ /**
68
+ * Returns a `MorphoVaultV2` entity bound to this client.
69
+ *
70
+ * @param vault - VaultV2 address.
71
+ * @param chainId - Chain the vault lives on.
72
+ * @returns A fresh `MorphoVaultV2` entity.
73
+ * @example
74
+ * ```ts
75
+ * const vault = client.vaultV2(vaultAddress, 1);
76
+ * const accrualVault = await vault.getData();
77
+ * const { buildTx } = vault.deposit({
78
+ * amount: 1_000_000n,
79
+ * userAddress: depositor,
80
+ * accrualVault,
81
+ * });
82
+ * const tx = buildTx();
83
+ * ```
84
+ */
85
+ vaultV2(vault, chainId) {
86
+ return new MorphoVaultV2(this, vault, chainId);
87
+ }
88
+ /**
89
+ * Returns a `MorphoMarketV1` entity bound to this client. Validates that the supplied
90
+ * `marketParams.id` matches the hash of the other params, so a hand-rolled or agent-written
91
+ * `MarketParams` cannot point at the wrong market silently.
92
+ *
93
+ * @param marketParams - Market params (`loanToken`, `collateralToken`, `oracle`, `irm`, `lltv`,
94
+ * `id`).
95
+ * @param chainId - Chain the market lives on.
96
+ * @returns A fresh `MorphoMarketV1` entity.
97
+ * @throws {MarketIdMismatchError} when `marketParams.id` does not equal the hash derived from
98
+ * the other fields.
99
+ * @example
100
+ * ```ts
101
+ * const market = client.marketV1(marketParams, 1);
102
+ * const positionData = await market.getPositionData(borrower);
103
+ * const { buildTx } = market.borrow({
104
+ * userAddress: borrower,
105
+ * amount: 1_000_000n,
106
+ * positionData,
107
+ * });
108
+ * const tx = buildTx();
109
+ * ```
110
+ */
111
+ marketV1(marketParams, chainId) {
112
+ const derivedId = MarketUtils.getMarketId(marketParams);
113
+ // Can happen with one-time/hardcoded/agent-written possibly inconsistent input market params.
114
+ if (marketParams.id !== derivedId) {
115
+ throw new MarketIdMismatchError(marketParams.id, derivedId);
116
+ }
117
+ return new MorphoMarketV1(this, marketParams, chainId);
118
+ }
119
+ }
@@ -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,43 @@
1
+ import { MorphoClient } from "./morphoClient.js";
2
+ /**
3
+ * Returns a viem `extend(...)` function that adds a `morpho` namespace to a viem client. The
4
+ * namespace exposes a `MorphoClient` instance built from the same client and the supplied
5
+ * options.
6
+ *
7
+ * @param _options - Optional SDK-wide options forwarded to the inner `MorphoClient`.
8
+ * @param _options.metadata - Optional analytics metadata applied to every transaction the
9
+ * resulting `MorphoClient` builds.
10
+ * @param _options.supportSignature - Whether the integrator can collect EIP-712 signatures for
11
+ * permit / permit2.
12
+ * @param _options.supportDeployless - Whether entity fetchers may use deployless multicall.
13
+ * @returns A viem extension function — `client.extend(morphoViemExtension(...))` adds
14
+ * `client.morpho`.
15
+ * @example
16
+ * ```ts
17
+ * import { createWalletClient, http } from "viem";
18
+ * import { mainnet } from "viem/chains";
19
+ * import { morphoViemExtension } from "@morpho-org/morpho-sdk";
20
+ *
21
+ * const client = createWalletClient({
22
+ * chain: mainnet,
23
+ * transport: http(),
24
+ * account: user,
25
+ * }).extend(morphoViemExtension({ supportSignature: true }));
26
+ *
27
+ * const vault = client.morpho.vaultV1(vaultAddress, 1);
28
+ * const accrualVault = await vault.getData();
29
+ * const { buildTx } = vault.deposit({
30
+ * amount: 1_000_000n,
31
+ * userAddress: user,
32
+ * accrualVault,
33
+ * });
34
+ * const tx = buildTx();
35
+ * ```
36
+ */
37
+ export function morphoViemExtension(_options) {
38
+ return (client) => {
39
+ return {
40
+ morpho: new MorphoClient(client, _options),
41
+ };
42
+ };
43
+ }
@@ -0,0 +1,3 @@
1
+ export * from "./marketV1/index.js";
2
+ export * from "./vaultV1/index.js";
3
+ export * from "./vaultV2/index.js";
@@ -0,0 +1,3 @@
1
+ export * from "./marketV1/index.js";
2
+ export * from "./vaultV1/index.js";
3
+ export * from "./vaultV2/index.js";
@@ -0,0 +1 @@
1
+ export * from "./marketV1.js";
@@ -0,0 +1 @@
1
+ export * from "./marketV1.js";