@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,109 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.marketV1SupplyCollateralBorrow = void 0;
4
- const blue_sdk_1 = require("@morpho-org/blue-sdk");
5
- const bundler_sdk_viem_1 = require("@morpho-org/bundler-sdk-viem");
6
- const morpho_ts_1 = require("@morpho-org/morpho-ts");
7
- const helpers_1 = require("../../helpers");
8
- const types_1 = require("../../types");
9
- const getRequirementsAction_1 = require("../requirements/getRequirementsAction");
10
- const buildReallocationActions_1 = require("./buildReallocationActions");
11
- /**
12
- * Prepares an atomic supply-collateral-and-borrow transaction for a Morpho Blue market.
13
- *
14
- * Routed through the bundler: collateral transfer + `morphoSupplyCollateral` + `morphoBorrow`.
15
- * When `nativeAmount` is provided, native ETH is wrapped via GeneralAdapter1.
16
- *
17
- * **Prerequisite:** GeneralAdapter1 must be authorized on Morpho to borrow on behalf of the user.
18
- * Use `getRequirements()` on the entity to check and obtain the authorization transaction.
19
- *
20
- * Zero loss: all collateral reaches Morpho, all borrowed tokens reach the receiver.
21
- * No dust left in bundler or adapter.
22
- *
23
- * @param params - Combined supply collateral and borrow parameters.
24
- * @returns Deep-frozen transaction.
25
- */
26
- const marketV1SupplyCollateralBorrow = ({ market: { chainId, marketParams }, args: { amount = 0n, borrowAmount, onBehalf, receiver, minSharePrice, requirementSignature, nativeAmount, reallocations, }, metadata, }) => {
27
- if (amount < 0n) {
28
- throw new types_1.NonPositiveAssetAmountError(marketParams.collateralToken);
29
- }
30
- if (nativeAmount !== undefined && nativeAmount < 0n) {
31
- throw new types_1.NegativeNativeAmountError(nativeAmount);
32
- }
33
- if (borrowAmount <= 0n) {
34
- throw new types_1.NonPositiveBorrowAmountError(marketParams.id);
35
- }
36
- if (minSharePrice < 0n) {
37
- throw new types_1.NonPositiveMinBorrowSharePriceError(marketParams.id);
38
- }
39
- const totalCollateral = amount + (nativeAmount ?? 0n);
40
- if (totalCollateral === 0n) {
41
- throw new types_1.ZeroCollateralAmountError(marketParams.id);
42
- }
43
- const { bundler3: { generalAdapter1, bundler3 }, } = (0, blue_sdk_1.getChainAddresses)(chainId);
44
- const actions = [];
45
- if (nativeAmount !== undefined && nativeAmount > 0n) {
46
- (0, helpers_1.validateNativeCollateral)(chainId, marketParams.collateralToken);
47
- actions.push({
48
- type: "nativeTransfer",
49
- args: [bundler3, generalAdapter1, nativeAmount, false],
50
- }, {
51
- type: "wrapNative",
52
- args: [nativeAmount, generalAdapter1, false],
53
- });
54
- }
55
- if (amount > 0n) {
56
- if (requirementSignature) {
57
- actions.push(...(0, getRequirementsAction_1.getRequirementsAction)({
58
- chainId,
59
- asset: marketParams.collateralToken,
60
- amount,
61
- requirementSignature,
62
- }));
63
- }
64
- else {
65
- actions.push({
66
- type: "erc20TransferFrom",
67
- args: [marketParams.collateralToken, amount, generalAdapter1, false],
68
- });
69
- }
70
- }
71
- actions.push({
72
- type: "morphoSupplyCollateral",
73
- args: [marketParams, totalCollateral, onBehalf, [], false],
74
- });
75
- let reallocationFee = 0n;
76
- if (reallocations && reallocations.length > 0) {
77
- const result = (0, buildReallocationActions_1.buildReallocationActions)(reallocations, marketParams);
78
- actions.push(...result.actions);
79
- reallocationFee = result.fee;
80
- }
81
- actions.push({
82
- type: "morphoBorrow",
83
- args: [marketParams, borrowAmount, 0n, minSharePrice, receiver, false],
84
- });
85
- let tx = {
86
- ...bundler_sdk_viem_1.BundlerAction.encodeBundle(chainId, actions),
87
- value: (nativeAmount ?? 0n) + reallocationFee,
88
- };
89
- if (metadata) {
90
- tx = (0, helpers_1.addTransactionMetadata)(tx, metadata);
91
- }
92
- return (0, morpho_ts_1.deepFreeze)({
93
- ...tx,
94
- action: {
95
- type: "marketV1SupplyCollateralBorrow",
96
- args: {
97
- market: marketParams.id,
98
- collateralAmount: totalCollateral,
99
- borrowAmount,
100
- minSharePrice,
101
- onBehalf,
102
- receiver,
103
- nativeAmount,
104
- reallocationFee,
105
- },
106
- },
107
- });
108
- };
109
- exports.marketV1SupplyCollateralBorrow = marketV1SupplyCollateralBorrow;
@@ -1,28 +0,0 @@
1
- import { type MarketParams } from "@morpho-org/blue-sdk";
2
- import { type Address } from "viem";
3
- import { type MarketV1WithdrawCollateralAction, type Metadata, type Transaction } from "../../types";
4
- /** Parameters for {@link marketV1WithdrawCollateral}. */
5
- export interface MarketV1WithdrawCollateralParams {
6
- market: {
7
- readonly chainId: number;
8
- readonly marketParams: MarketParams;
9
- };
10
- args: {
11
- amount: bigint;
12
- onBehalf: Address;
13
- receiver: Address;
14
- };
15
- metadata?: Metadata;
16
- }
17
- /**
18
- * Prepares a withdraw-collateral transaction for a Morpho Blue market.
19
- *
20
- * Direct call to `morpho.withdrawCollateral`. No bundler needed — collateral
21
- * flows out of Morpho, so there is no attack surface requiring the bundler.
22
- *
23
- * The caller (`msg.sender`) must be `onBehalf` or be authorized by them.
24
- *
25
- * @param params - Withdraw collateral parameters.
26
- * @returns Deep-frozen transaction.
27
- */
28
- export declare const marketV1WithdrawCollateral: ({ market: { chainId, marketParams }, args: { amount, onBehalf, receiver }, metadata, }: MarketV1WithdrawCollateralParams) => Readonly<Transaction<MarketV1WithdrawCollateralAction>>;
@@ -1,51 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.marketV1WithdrawCollateral = void 0;
4
- const blue_sdk_1 = require("@morpho-org/blue-sdk");
5
- const blue_sdk_viem_1 = require("@morpho-org/blue-sdk-viem");
6
- const morpho_ts_1 = require("@morpho-org/morpho-ts");
7
- const viem_1 = require("viem");
8
- const helpers_1 = require("../../helpers");
9
- const types_1 = require("../../types");
10
- /**
11
- * Prepares a withdraw-collateral transaction for a Morpho Blue market.
12
- *
13
- * Direct call to `morpho.withdrawCollateral`. No bundler needed — collateral
14
- * flows out of Morpho, so there is no attack surface requiring the bundler.
15
- *
16
- * The caller (`msg.sender`) must be `onBehalf` or be authorized by them.
17
- *
18
- * @param params - Withdraw collateral parameters.
19
- * @returns Deep-frozen transaction.
20
- */
21
- const marketV1WithdrawCollateral = ({ market: { chainId, marketParams }, args: { amount, onBehalf, receiver }, metadata, }) => {
22
- if (amount <= 0n) {
23
- throw new types_1.NonPositiveWithdrawCollateralAmountError(marketParams.id);
24
- }
25
- const { morpho } = (0, blue_sdk_1.getChainAddresses)(chainId);
26
- let tx = {
27
- to: morpho,
28
- data: (0, viem_1.encodeFunctionData)({
29
- abi: blue_sdk_viem_1.blueAbi,
30
- functionName: "withdrawCollateral",
31
- args: [marketParams, amount, onBehalf, receiver],
32
- }),
33
- value: 0n,
34
- };
35
- if (metadata) {
36
- tx = (0, helpers_1.addTransactionMetadata)(tx, metadata);
37
- }
38
- return (0, morpho_ts_1.deepFreeze)({
39
- ...tx,
40
- action: {
41
- type: "marketV1WithdrawCollateral",
42
- args: {
43
- market: marketParams.id,
44
- amount,
45
- onBehalf,
46
- receiver,
47
- },
48
- },
49
- });
50
- };
51
- exports.marketV1WithdrawCollateral = marketV1WithdrawCollateral;
@@ -1,10 +0,0 @@
1
- import { type Address } from "@morpho-org/blue-sdk";
2
- import type { ERC20ApprovalAction, Transaction } from "../../../types";
3
- interface EncodeErc20ApprovalParams {
4
- token: Address;
5
- spender: Address;
6
- amount: bigint;
7
- chainId: number;
8
- }
9
- export declare const encodeErc20Approval: (params: EncodeErc20ApprovalParams) => Transaction<ERC20ApprovalAction>;
10
- export {};
@@ -1,13 +0,0 @@
1
- import type { Address } from "@morpho-org/blue-sdk";
2
- import { type Client } from "viem";
3
- import { type Requirement } from "../../../types";
4
- interface EncodeErc20PermitParams {
5
- token: Address;
6
- spender: Address;
7
- amount: bigint;
8
- chainId: number;
9
- nonce: bigint;
10
- supportDeployless?: boolean;
11
- }
12
- export declare const encodeErc20Permit: (viemClient: Client, params: EncodeErc20PermitParams) => Promise<Requirement>;
13
- export {};
@@ -1,70 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.encodeErc20Permit = 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 actions_1 = require("viem/actions");
8
- const types_1 = require("../../../types");
9
- const encodeErc20Permit = async (viemClient, params) => {
10
- const { token, spender, amount, chainId, nonce, supportDeployless } = params;
11
- if (viemClient.chain?.id !== chainId) {
12
- throw new types_1.ChainIdMismatchError(viemClient.chain?.id, chainId);
13
- }
14
- const now = morpho_ts_1.Time.timestamp();
15
- const deadline = now + morpho_ts_1.Time.s.from.h(2n);
16
- const tokenData = await (0, blue_sdk_viem_1.fetchToken)(token, viemClient, {
17
- deployless: supportDeployless,
18
- });
19
- const action = {
20
- type: "permit",
21
- args: {
22
- spender,
23
- amount,
24
- deadline,
25
- },
26
- };
27
- return {
28
- action,
29
- async sign(client, userAddress) {
30
- if (!client.account?.address) {
31
- throw new types_1.MissingClientPropertyError("client.account.address");
32
- }
33
- if (client.account.address !== userAddress) {
34
- throw new types_1.AddressMismatchError(client.account.address, userAddress);
35
- }
36
- const typedData = (0, blue_sdk_viem_1.getPermitTypedData)({
37
- erc20: tokenData,
38
- owner: userAddress,
39
- spender,
40
- allowance: amount,
41
- nonce,
42
- deadline,
43
- }, chainId);
44
- const signature = await (0, actions_1.signTypedData)(client, {
45
- ...typedData,
46
- account: client.account,
47
- });
48
- const isValid = await (0, viem_1.verifyTypedData)({
49
- ...typedData,
50
- address: userAddress, // Verify against the permit's owner.
51
- signature,
52
- });
53
- if (!isValid) {
54
- throw new types_1.InvalidSignatureError();
55
- }
56
- return (0, morpho_ts_1.deepFreeze)({
57
- args: {
58
- owner: userAddress,
59
- signature,
60
- deadline,
61
- amount,
62
- asset: token,
63
- nonce,
64
- },
65
- action,
66
- });
67
- },
68
- };
69
- };
70
- exports.encodeErc20Permit = encodeErc20Permit;
@@ -1,11 +0,0 @@
1
- import { type Address } from "@morpho-org/blue-sdk";
2
- import { type Requirement } from "../../../types";
3
- interface EncodeErc20Permit2Params {
4
- token: Address;
5
- amount: bigint;
6
- chainId: number;
7
- nonce: bigint;
8
- expiration: bigint;
9
- }
10
- export declare const encodeErc20Permit2: (params: EncodeErc20Permit2Params) => Requirement;
11
- export {};
@@ -1,3 +0,0 @@
1
- export * from "./encodeErc20Approval";
2
- export * from "./encodeErc20Permit";
3
- export * from "./encodeErc20Permit2";
@@ -1,21 +0,0 @@
1
- import type { Client } from "viem";
2
- import { type Address } from "viem";
3
- import { type MorphoAuthorizationAction, type Transaction } from "../../types";
4
- /**
5
- * Checks whether GeneralAdapter1 is authorized on Morpho for the given user.
6
- * If not authorized, returns a deep-frozen `morpho.setAuthorization(generalAdapter1, true)` transaction.
7
- * Returns `null` if authorization is already in place.
8
- *
9
- * Required before any bundled borrow on behalf of the user (e.g. `supplyCollateralBorrow`).
10
- *
11
- * @param params - Request parameters.
12
- * @param params.viemClient - Connected viem client.
13
- * @param params.chainId - Target chain ID (used to look up Morpho and GeneralAdapter1 addresses).
14
- * @param params.userAddress - The user who needs to authorize GeneralAdapter1.
15
- * @returns Deep-frozen authorization transaction, or `null` if already authorized.
16
- */
17
- export declare const getMorphoAuthorizationRequirement: (params: {
18
- viemClient: Client;
19
- chainId: number;
20
- userAddress: Address;
21
- }) => Promise<Readonly<Transaction<MorphoAuthorizationAction>> | null>;
@@ -1,55 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getMorphoAuthorizationRequirement = void 0;
4
- const blue_sdk_1 = require("@morpho-org/blue-sdk");
5
- const blue_sdk_viem_1 = require("@morpho-org/blue-sdk-viem");
6
- const morpho_ts_1 = require("@morpho-org/morpho-ts");
7
- const viem_1 = require("viem");
8
- const types_1 = require("../../types");
9
- /**
10
- * Checks whether GeneralAdapter1 is authorized on Morpho for the given user.
11
- * If not authorized, returns a deep-frozen `morpho.setAuthorization(generalAdapter1, true)` transaction.
12
- * Returns `null` if authorization is already in place.
13
- *
14
- * Required before any bundled borrow on behalf of the user (e.g. `supplyCollateralBorrow`).
15
- *
16
- * @param params - Request parameters.
17
- * @param params.viemClient - Connected viem client.
18
- * @param params.chainId - Target chain ID (used to look up Morpho and GeneralAdapter1 addresses).
19
- * @param params.userAddress - The user who needs to authorize GeneralAdapter1.
20
- * @returns Deep-frozen authorization transaction, or `null` if already authorized.
21
- */
22
- const getMorphoAuthorizationRequirement = async (params) => {
23
- const { viemClient, chainId, userAddress } = params;
24
- if (viemClient.chain?.id !== chainId) {
25
- throw new types_1.ChainIdMismatchError(viemClient.chain?.id, chainId);
26
- }
27
- const { morpho, bundler3: { generalAdapter1 }, } = (0, blue_sdk_1.getChainAddresses)(chainId);
28
- const pc = viemClient.extend(viem_1.publicActions);
29
- const isAuthorized = await pc.readContract({
30
- address: morpho,
31
- abi: blue_sdk_viem_1.blueAbi,
32
- functionName: "isAuthorized",
33
- args: [userAddress, generalAdapter1],
34
- });
35
- if (isAuthorized) {
36
- return null;
37
- }
38
- return (0, morpho_ts_1.deepFreeze)({
39
- to: morpho,
40
- data: (0, viem_1.encodeFunctionData)({
41
- abi: blue_sdk_viem_1.blueAbi,
42
- functionName: "setAuthorization",
43
- args: [generalAdapter1, true],
44
- }),
45
- value: 0n,
46
- action: {
47
- type: "morphoAuthorization",
48
- args: {
49
- authorized: generalAdapter1,
50
- isAuthorized: true,
51
- },
52
- },
53
- });
54
- };
55
- exports.getMorphoAuthorizationRequirement = getMorphoAuthorizationRequirement;
@@ -1,42 +0,0 @@
1
- import { type Address } from "@morpho-org/blue-sdk";
2
- import type { Client } from "viem";
3
- import { type ERC20ApprovalAction, type Requirement, type Transaction } from "../../types";
4
- type GetRequirementsBaseParams = {
5
- address: Address;
6
- chainId: number;
7
- supportDeployless?: boolean;
8
- args: {
9
- amount: bigint;
10
- from: Address;
11
- };
12
- };
13
- type GetRequirementsParams = (GetRequirementsBaseParams & {
14
- /** Signature-based approvals are not supported. Classic approval (transaction) will be used. */
15
- supportSignature: false;
16
- }) | (GetRequirementsBaseParams & {
17
- /** Signature-based approvals are supported. Will try permit (EIP-2612), else fallback to permit2. */
18
- supportSignature: true;
19
- /** Allow simple permit if EIP-2612 is supported. Only applicable when `supportSignature` is `true`. */
20
- useSimplePermit?: boolean;
21
- });
22
- /**
23
- * Get token "requirement" for approval/permit before interacting with protocol.
24
- *
25
- * Three flows:
26
- * 1. If signature not supported, use classic approval (transaction).
27
- * 2. If signature supported, try simple permit (EIP-2612), else fallback to permit2.
28
- *
29
- * @param viemClient - The connected viem Client instance, with the correct chain and account.
30
- * @param params - Destructured object with:
31
- * @param params.address - ERC20 token address.
32
- * @param params.chainId - Chain/network id.
33
- * @param params.args - Object with:
34
- * @param params.args.amount - Required token amount.
35
- * @param params.args.from - The account that will grant approval.
36
- * @param params.supportSignature - Whether signature-based approvals are supported. If true, will try to use permit or permit2.
37
- * @param params.supportDeployless - Whether to use deployless mode.
38
- * @param params.useSimplePermit - use simple permit if EIP-2612 is supported. Only available when `supportSignature` is `true`.
39
- * @returns Promise of array of approval transaction or requirement objects.
40
- */
41
- export declare const getRequirements: (viemClient: Client, params: GetRequirementsParams) => Promise<(Readonly<Transaction<ERC20ApprovalAction>> | Requirement)[]>;
42
- export {};
@@ -1,80 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getRequirements = void 0;
4
- const blue_sdk_1 = require("@morpho-org/blue-sdk");
5
- const blue_sdk_viem_1 = require("@morpho-org/blue-sdk-viem");
6
- const morpho_ts_1 = require("@morpho-org/morpho-ts");
7
- const types_1 = require("../../types");
8
- const getRequirementsApproval_1 = require("./getRequirementsApproval");
9
- const getRequirementsPermit_1 = require("./getRequirementsPermit");
10
- const getRequirementsPermit2_1 = require("./getRequirementsPermit2");
11
- /**
12
- * Get token "requirement" for approval/permit before interacting with protocol.
13
- *
14
- * Three flows:
15
- * 1. If signature not supported, use classic approval (transaction).
16
- * 2. If signature supported, try simple permit (EIP-2612), else fallback to permit2.
17
- *
18
- * @param viemClient - The connected viem Client instance, with the correct chain and account.
19
- * @param params - Destructured object with:
20
- * @param params.address - ERC20 token address.
21
- * @param params.chainId - Chain/network id.
22
- * @param params.args - Object with:
23
- * @param params.args.amount - Required token amount.
24
- * @param params.args.from - The account that will grant approval.
25
- * @param params.supportSignature - Whether signature-based approvals are supported. If true, will try to use permit or permit2.
26
- * @param params.supportDeployless - Whether to use deployless mode.
27
- * @param params.useSimplePermit - use simple permit if EIP-2612 is supported. Only available when `supportSignature` is `true`.
28
- * @returns Promise of array of approval transaction or requirement objects.
29
- */
30
- const getRequirements = async (viemClient, params) => {
31
- const { address, chainId, supportSignature, args: { amount, from }, } = params;
32
- if (viemClient.chain?.id !== chainId) {
33
- throw new types_1.ChainIdMismatchError(viemClient.chain?.id, chainId);
34
- }
35
- if (amount === 0n) {
36
- return [];
37
- }
38
- const { permit2, dai, bundler3: { generalAdapter1 }, } = (0, blue_sdk_1.getChainAddresses)(chainId);
39
- const { erc20Allowances, erc2612Nonce, permit2BundlerAllowance } = await (0, blue_sdk_viem_1.fetchHolding)(from, address, viemClient, {
40
- deployless: params.supportDeployless,
41
- });
42
- if (supportSignature) {
43
- const { useSimplePermit } = params;
44
- const supportSimplePermit = (0, morpho_ts_1.isDefined)(erc2612Nonce) && address !== dai;
45
- if (supportSimplePermit && useSimplePermit) {
46
- return await (0, getRequirementsPermit_1.getRequirementsPermit)(viemClient, {
47
- token: address,
48
- chainId,
49
- args: { amount },
50
- allowancesGeneralAdapter: erc20Allowances["bundler3.generalAdapter1"],
51
- nonce: erc2612Nonce,
52
- supportDeployless: params.supportDeployless,
53
- });
54
- }
55
- if (permit2) {
56
- return (0, getRequirementsPermit2_1.getRequirementsPermit2)({
57
- address,
58
- chainId,
59
- permit2,
60
- args: { amount },
61
- allowancesGeneralAdapter: erc20Allowances["bundler3.generalAdapter1"],
62
- allowancesPermit2: erc20Allowances.permit2,
63
- allowanceGeneralAdapterPermit2: permit2BundlerAllowance.amount,
64
- allowanceGeneralAdapterExpiration: permit2BundlerAllowance.expiration,
65
- nonce: permit2BundlerAllowance.nonce,
66
- });
67
- }
68
- }
69
- return (0, getRequirementsApproval_1.getRequirementsApproval)({
70
- address,
71
- chainId,
72
- args: {
73
- spendAmount: amount,
74
- approvalAmount: amount,
75
- spender: generalAdapter1,
76
- },
77
- allowances: erc20Allowances["bundler3.generalAdapter1"],
78
- });
79
- };
80
- exports.getRequirements = getRequirements;
@@ -1,17 +0,0 @@
1
- import type { Action } from "@morpho-org/bundler-sdk-viem";
2
- import { type Address } from "viem";
3
- import { type Permit2Action, type PermitAction, type PermitArgs } from "../../types";
4
- interface GetRequirementsActionParams {
5
- chainId: number;
6
- asset: Address;
7
- amount: bigint;
8
- requirementSignature: {
9
- args: PermitArgs;
10
- action: PermitAction | Permit2Action;
11
- };
12
- }
13
- /**
14
- * Get the actions required to transfer the asset based on the requirement signature.
15
- */
16
- export declare const getRequirementsAction: ({ chainId, asset, amount, requirementSignature, }: GetRequirementsActionParams) => Action[];
17
- export {};
@@ -1,31 +0,0 @@
1
- import type { Address } from "@morpho-org/blue-sdk";
2
- import { type ERC20ApprovalAction, type Transaction } from "../../types";
3
- /**
4
- * Get token "requirement" for approval.
5
- *
6
- * Verify if the allowance is enough on the spender contract.
7
- * => If not, approve the token to the spender contract with classic approval transaction on the required amount.
8
- * => If the allowance is enough, return an empty array.
9
- *
10
- * Handle logic for reset approval before approving (if needed).
11
- *
12
- * @param params - Destructured object with:
13
- * @param params.address - ERC20 token address.
14
- * @param params.chainId - Chain/network id.
15
- * @param params.args - Object with:
16
- * @param params.args.spendAmount - Spend amount required for the action.
17
- * @param params.args.approvalAmount - Approval amount to be approved.
18
- * @param params.args.spender - Spender contract address.
19
- * @param params.allowances - Allowance for the spender contract.
20
- * @returns An array of requirement transaction object.
21
- */
22
- export declare const getRequirementsApproval: (params: {
23
- address: Address;
24
- chainId: number;
25
- args: {
26
- approvalAmount: bigint;
27
- spendAmount: bigint;
28
- spender: Address;
29
- };
30
- allowances: bigint;
31
- }) => Readonly<Transaction<ERC20ApprovalAction>>[];
@@ -1,51 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getRequirementsApproval = void 0;
4
- const simulation_sdk_1 = require("@morpho-org/simulation-sdk");
5
- const types_1 = require("../../types");
6
- const encodeErc20Approval_1 = require("./encode/encodeErc20Approval");
7
- /**
8
- * Get token "requirement" for approval.
9
- *
10
- * Verify if the allowance is enough on the spender contract.
11
- * => If not, approve the token to the spender contract with classic approval transaction on the required amount.
12
- * => If the allowance is enough, return an empty array.
13
- *
14
- * Handle logic for reset approval before approving (if needed).
15
- *
16
- * @param params - Destructured object with:
17
- * @param params.address - ERC20 token address.
18
- * @param params.chainId - Chain/network id.
19
- * @param params.args - Object with:
20
- * @param params.args.spendAmount - Spend amount required for the action.
21
- * @param params.args.approvalAmount - Approval amount to be approved.
22
- * @param params.args.spender - Spender contract address.
23
- * @param params.allowances - Allowance for the spender contract.
24
- * @returns An array of requirement transaction object.
25
- */
26
- const getRequirementsApproval = (params) => {
27
- const { address, chainId, args: { spendAmount, approvalAmount, spender }, allowances, } = params;
28
- if (approvalAmount < spendAmount) {
29
- throw new types_1.ApprovalAmountLessThanSpendAmountError();
30
- }
31
- const approvals = [];
32
- if (allowances < spendAmount) {
33
- if (simulation_sdk_1.APPROVE_ONLY_ONCE_TOKENS[chainId]?.includes(address) &&
34
- allowances > 0n) {
35
- approvals.push((0, encodeErc20Approval_1.encodeErc20Approval)({
36
- token: address,
37
- spender,
38
- amount: 0n,
39
- chainId,
40
- }));
41
- }
42
- approvals.push((0, encodeErc20Approval_1.encodeErc20Approval)({
43
- token: address,
44
- spender,
45
- amount: approvalAmount,
46
- chainId,
47
- }));
48
- }
49
- return approvals;
50
- };
51
- exports.getRequirementsApproval = getRequirementsApproval;
@@ -1,28 +0,0 @@
1
- import type { Address, Client } from "viem";
2
- /**
3
- * Get token "requirement" for permit (EIP-2612).
4
- *
5
- * Verify if the allowance is enough on general adapter from permit (EIP-2612) contract.
6
- * => If not, approve the token to general adapter from permit via EIP-2612 with permit signature on the required amount.
7
- *
8
- * @param viemClient - The viem Client instance
9
- * @param params - Destructured object with:
10
- * @param params.token - ERC20 token.
11
- * @param params.chainId - Chain/network id.
12
- * @param params.args - Object with:
13
- * @param params.args.amount - Required token amount.
14
- * @param params.allowancesGeneralAdapter - Allowance for general adapter from permit contract.
15
- * @param params.nonce - Nonce for permit (EIP-2612).
16
- * @param params.supportDeployless - Whether to use deployless mode.
17
- * @returns An array of requirement signature object.
18
- */
19
- export declare const getRequirementsPermit: (viemClient: Client, params: {
20
- token: Address;
21
- chainId: number;
22
- args: {
23
- amount: bigint;
24
- };
25
- allowancesGeneralAdapter: bigint;
26
- nonce: bigint;
27
- supportDeployless?: boolean;
28
- }) => Promise<import("../..").Requirement[]>;