@morpho-org/morpho-sdk 10.0.2 → 10.1.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 (420) hide show
  1. package/README.md +6 -2
  2. package/lib/cjs/actions/blue/borrow.d.ts +2 -1
  3. package/lib/cjs/actions/blue/borrow.internal.d.ts +13 -0
  4. package/lib/cjs/actions/blue/borrow.internal.js +35 -0
  5. package/lib/cjs/actions/blue/borrow.js +4 -16
  6. package/lib/cjs/actions/blue/common.d.ts +50 -28
  7. package/lib/cjs/actions/blue/common.js +21 -34
  8. package/lib/cjs/actions/blue/encode.d.ts +23 -0
  9. package/lib/cjs/actions/blue/encode.js +171 -0
  10. package/lib/cjs/actions/blue/refinance.d.ts +3 -2
  11. package/lib/cjs/actions/blue/refinance.internal.d.ts +42 -0
  12. package/lib/cjs/actions/blue/refinance.internal.js +62 -0
  13. package/lib/cjs/actions/blue/refinance.js +5 -63
  14. package/lib/cjs/actions/blue/refinanceValidation.d.ts +4 -5
  15. package/lib/cjs/actions/blue/refinanceValidation.js +1 -3
  16. package/lib/cjs/actions/blue/repay.d.ts +1 -1
  17. package/lib/cjs/actions/blue/repay.internal.d.ts +13 -0
  18. package/lib/cjs/actions/blue/repay.internal.js +38 -0
  19. package/lib/cjs/actions/blue/repay.js +2 -17
  20. package/lib/cjs/actions/blue/repayWithdrawCollateral.d.ts +2 -2
  21. package/lib/cjs/actions/blue/repayWithdrawCollateral.internal.d.ts +61 -0
  22. package/lib/cjs/actions/blue/repayWithdrawCollateral.internal.js +112 -0
  23. package/lib/cjs/actions/blue/repayWithdrawCollateral.js +3 -116
  24. package/lib/cjs/actions/blue/signatures.d.ts +30 -0
  25. package/lib/cjs/actions/blue/signatures.js +90 -0
  26. package/lib/cjs/actions/blue/supply.d.ts +1 -1
  27. package/lib/cjs/actions/blue/supply.internal.d.ts +32 -0
  28. package/lib/cjs/actions/blue/supply.internal.js +101 -0
  29. package/lib/cjs/actions/blue/supply.js +2 -67
  30. package/lib/cjs/actions/blue/supplyCollateral.d.ts +1 -1
  31. package/lib/cjs/actions/blue/supplyCollateral.internal.d.ts +13 -0
  32. package/lib/cjs/actions/blue/supplyCollateral.internal.js +37 -0
  33. package/lib/cjs/actions/blue/supplyCollateral.js +2 -17
  34. package/lib/cjs/actions/blue/supplyCollateralBorrow.d.ts +4 -3
  35. package/lib/cjs/actions/blue/supplyCollateralBorrow.internal.d.ts +63 -0
  36. package/lib/cjs/actions/blue/supplyCollateralBorrow.internal.js +94 -0
  37. package/lib/cjs/actions/blue/supplyCollateralBorrow.js +5 -106
  38. package/lib/cjs/actions/blue/withdraw.d.ts +4 -3
  39. package/lib/cjs/actions/blue/withdraw.internal.d.ts +56 -0
  40. package/lib/cjs/actions/blue/withdraw.internal.js +84 -0
  41. package/lib/cjs/actions/blue/withdraw.js +5 -78
  42. package/lib/cjs/actions/blue/withdrawBuyCallback.d.ts +2 -2
  43. package/lib/cjs/actions/blue/withdrawBuyCallback.internal.d.ts +20 -0
  44. package/lib/cjs/actions/blue/withdrawBuyCallback.internal.js +58 -0
  45. package/lib/cjs/actions/blue/withdrawBuyCallback.js +2 -39
  46. package/lib/cjs/actions/blue/withdrawCollateral.internal.d.ts +16 -0
  47. package/lib/cjs/actions/blue/withdrawCollateral.internal.js +39 -0
  48. package/lib/cjs/actions/blue/withdrawCollateral.js +2 -17
  49. package/lib/cjs/actions/bundles/common.d.ts +9 -0
  50. package/lib/cjs/actions/bundles/common.js +18 -6
  51. package/lib/cjs/actions/bundles/index.d.ts +1 -1
  52. package/lib/cjs/actions/bundles/index.js +3 -16
  53. package/lib/cjs/actions/bundles/resolveBundlesTokenRequirements.d.ts +14 -0
  54. package/lib/cjs/actions/bundles/resolveBundlesTokenRequirements.js +59 -60
  55. package/lib/cjs/actions/midnight/cancelAndMake.d.ts +22 -1
  56. package/lib/cjs/actions/midnight/cancelAndMake.js +46 -87
  57. package/lib/cjs/actions/midnight/cancelOffers.d.ts +11 -0
  58. package/lib/cjs/actions/midnight/cancelOffers.js +22 -4
  59. package/lib/cjs/actions/midnight/encode.d.ts +36 -0
  60. package/lib/cjs/actions/midnight/encode.js +554 -0
  61. package/lib/cjs/actions/midnight/index.d.ts +14 -13
  62. package/lib/cjs/actions/midnight/index.js +29 -13
  63. package/lib/cjs/actions/midnight/parse.d.ts +35 -0
  64. package/lib/cjs/actions/midnight/parse.js +73 -0
  65. package/lib/cjs/actions/midnight/parseCollateralBatch.d.ts +58 -0
  66. package/lib/cjs/actions/midnight/parseCollateralBatch.js +216 -0
  67. package/lib/cjs/actions/midnight/redeem.d.ts +16 -3
  68. package/lib/cjs/actions/midnight/redeem.js +22 -51
  69. package/lib/cjs/actions/midnight/repayWithdrawCollateral.d.ts +13 -0
  70. package/lib/cjs/actions/midnight/repayWithdrawCollateral.js +42 -67
  71. package/lib/cjs/actions/midnight/supplyCollateral.d.ts +40 -5
  72. package/lib/cjs/actions/midnight/supplyCollateral.js +60 -54
  73. package/lib/cjs/actions/midnight/supplyCollateralBatch.d.ts +3 -3
  74. package/lib/cjs/actions/midnight/supplyCollateralBatch.js +3 -62
  75. package/lib/cjs/actions/midnight/supplyCollateralTakeBorrow.d.ts +24 -0
  76. package/lib/cjs/actions/midnight/supplyCollateralTakeBorrow.js +39 -66
  77. package/lib/cjs/actions/midnight/supplyCollateralWithNative.d.ts +77 -0
  78. package/lib/cjs/actions/midnight/supplyCollateralWithNative.js +142 -0
  79. package/lib/cjs/actions/midnight/takeBorrow.d.ts +17 -2
  80. package/lib/cjs/actions/midnight/takeBorrow.js +25 -55
  81. package/lib/cjs/actions/midnight/takeLend.d.ts +21 -1
  82. package/lib/cjs/actions/midnight/takeLend.js +30 -57
  83. package/lib/cjs/actions/midnight/takeRepayWithdrawCollateral.d.ts +22 -2
  84. package/lib/cjs/actions/midnight/takeRepayWithdrawCollateral.js +34 -61
  85. package/lib/cjs/actions/midnight/takeWithdraw.d.ts +17 -2
  86. package/lib/cjs/actions/midnight/takeWithdraw.js +78 -115
  87. package/lib/cjs/actions/midnight/withdrawCollateral.d.ts +16 -3
  88. package/lib/cjs/actions/midnight/withdrawCollateral.js +25 -56
  89. package/lib/cjs/actions/midnight/withdrawCollateralBatch.d.ts +3 -3
  90. package/lib/cjs/actions/midnight/withdrawCollateralBatch.js +3 -71
  91. package/lib/cjs/actions/requirements/blue/getBlueAuthorizationRequirement.d.ts +13 -0
  92. package/lib/cjs/actions/requirements/blue/getBlueAuthorizationRequirement.js +39 -19
  93. package/lib/cjs/actions/requirements/blue/index.d.ts +1 -1
  94. package/lib/cjs/actions/requirements/blue/index.js +3 -15
  95. package/lib/cjs/actions/requirements/chainCheck.d.ts +5 -0
  96. package/lib/cjs/actions/requirements/chainCheck.js +10 -0
  97. package/lib/cjs/actions/requirements/encode/encodeBlueSignatureAuthorization.d.ts +10 -0
  98. package/lib/cjs/actions/requirements/encode/encodeBlueSignatureAuthorization.js +40 -27
  99. package/lib/cjs/actions/requirements/encode/encodeErc20Approval.d.ts +11 -1
  100. package/lib/cjs/actions/requirements/encode/encodeErc20Approval.js +36 -17
  101. package/lib/cjs/actions/requirements/encode/encodeErc20Permit.d.ts +14 -1
  102. package/lib/cjs/actions/requirements/encode/encodeErc20Permit.js +44 -9
  103. package/lib/cjs/actions/requirements/encode/encodeErc20Permit2SignatureTransfer.d.ts +10 -0
  104. package/lib/cjs/actions/requirements/encode/encodeErc20Permit2SignatureTransfer.js +61 -24
  105. package/lib/cjs/actions/requirements/encode/encodeVaultSharesPermit.d.ts +10 -0
  106. package/lib/cjs/actions/requirements/encode/encodeVaultSharesPermit.js +25 -4
  107. package/lib/cjs/actions/requirements/encode/index.d.ts +5 -5
  108. package/lib/cjs/actions/requirements/encode/index.js +11 -19
  109. package/lib/cjs/actions/requirements/getRequirementsApproval.d.ts +26 -11
  110. package/lib/cjs/actions/requirements/getRequirementsApproval.js +40 -12
  111. package/lib/cjs/actions/requirements/index.d.ts +1 -1
  112. package/lib/cjs/actions/requirements/index.js +3 -1
  113. package/lib/cjs/actions/requirements/midnight/getMidnightApprovalRequirements.d.ts +11 -0
  114. package/lib/cjs/actions/requirements/midnight/getMidnightApprovalRequirements.js +34 -19
  115. package/lib/cjs/actions/requirements/midnight/getMidnightAuthorizationRequirement.d.ts +11 -0
  116. package/lib/cjs/actions/requirements/midnight/getMidnightAuthorizationRequirement.js +26 -12
  117. package/lib/cjs/actions/requirements/midnight/index.d.ts +2 -2
  118. package/lib/cjs/actions/requirements/midnight/index.js +5 -16
  119. package/lib/cjs/actions/vaultV1/deposit.d.ts +21 -0
  120. package/lib/cjs/actions/vaultV1/deposit.js +46 -10
  121. package/lib/cjs/actions/vaultV1/inKindRedeem.d.ts +18 -1
  122. package/lib/cjs/actions/vaultV1/inKindRedeem.js +36 -16
  123. package/lib/cjs/actions/vaultV1/index.d.ts +5 -5
  124. package/lib/cjs/actions/vaultV1/index.js +11 -19
  125. package/lib/cjs/actions/vaultV1/migrateToV2.d.ts +21 -0
  126. package/lib/cjs/actions/vaultV1/migrateToV2.js +49 -11
  127. package/lib/cjs/actions/vaultV1/redeem.d.ts +19 -0
  128. package/lib/cjs/actions/vaultV1/redeem.js +28 -7
  129. package/lib/cjs/actions/vaultV1/withdraw.d.ts +19 -0
  130. package/lib/cjs/actions/vaultV1/withdraw.js +28 -7
  131. package/lib/cjs/actions/vaultV2/deposit.d.ts +21 -0
  132. package/lib/cjs/actions/vaultV2/deposit.js +46 -10
  133. package/lib/cjs/actions/vaultV2/forceRedeem.d.ts +20 -2
  134. package/lib/cjs/actions/vaultV2/forceRedeem.js +39 -8
  135. package/lib/cjs/actions/vaultV2/forceWithdraw.d.ts +23 -1
  136. package/lib/cjs/actions/vaultV2/forceWithdraw.js +36 -14
  137. package/lib/cjs/actions/vaultV2/inKindRedeem.d.ts +18 -1
  138. package/lib/cjs/actions/vaultV2/inKindRedeem.js +35 -15
  139. package/lib/cjs/actions/vaultV2/index.d.ts +6 -6
  140. package/lib/cjs/actions/vaultV2/index.js +13 -20
  141. package/lib/cjs/actions/vaultV2/redeem.d.ts +19 -0
  142. package/lib/cjs/actions/vaultV2/redeem.js +28 -7
  143. package/lib/cjs/actions/vaultV2/withdraw.d.ts +19 -0
  144. package/lib/cjs/actions/vaultV2/withdraw.js +28 -7
  145. package/lib/cjs/entities/blue/blue.d.ts +35 -8
  146. package/lib/cjs/entities/blue/blue.js +467 -406
  147. package/lib/cjs/entities/midnight/midnight.d.ts +117 -41
  148. package/lib/cjs/entities/midnight/midnight.js +472 -843
  149. package/lib/cjs/entities/midnight/parse.d.ts +74 -0
  150. package/lib/cjs/entities/midnight/parse.js +336 -0
  151. package/lib/cjs/entities/midnight/prepare.d.ts +47 -0
  152. package/lib/cjs/entities/midnight/prepare.js +293 -0
  153. package/lib/cjs/entities/midnight/publication.d.ts +7 -3
  154. package/lib/cjs/entities/midnight/publication.js +10 -7
  155. package/lib/cjs/entities/midnight/types.d.ts +7 -0
  156. package/lib/cjs/entities/requirements/assertContractCode.d.ts +10 -5
  157. package/lib/cjs/entities/requirements/assertContractCode.js +24 -15
  158. package/lib/cjs/entities/requirements/getBundlesTokenRequirements.d.ts +15 -0
  159. package/lib/cjs/entities/requirements/getBundlesTokenRequirements.js +59 -51
  160. package/lib/cjs/entities/requirements/getErc2612Permit.d.ts +7 -3
  161. package/lib/cjs/entities/requirements/getErc2612Permit.js +20 -4
  162. package/lib/cjs/entities/requirements/getUnusedPermit2Nonce.d.ts +15 -0
  163. package/lib/cjs/entities/requirements/getUnusedPermit2Nonce.js +24 -7
  164. package/lib/cjs/entities/requirements/getVaultBundlesSharesRequirements.d.ts +14 -0
  165. package/lib/cjs/entities/requirements/getVaultBundlesSharesRequirements.js +27 -7
  166. package/lib/cjs/entities/requirements/getVaultV1InKindRedeemRequirements.js +4 -3
  167. package/lib/cjs/entities/requirements/getVaultV2ForceWithdrawRequirements.js +4 -3
  168. package/lib/cjs/entities/requirements/getVaultV2InKindRedeemRequirements.js +4 -3
  169. package/lib/cjs/entities/requirements/index.d.ts +2 -2
  170. package/lib/cjs/entities/requirements/index.js +5 -16
  171. package/lib/cjs/entities/requirements/validateNativeRequirements.d.ts +21 -0
  172. package/lib/cjs/entities/requirements/validateNativeRequirements.js +37 -0
  173. package/lib/cjs/entities/vaultV1/inKindRedeemQuote.d.ts +2 -2
  174. package/lib/cjs/entities/vaultV1/inKindRedeemQuote.js +1 -7
  175. package/lib/cjs/entities/vaultV1/vaultV1.d.ts +17 -40
  176. package/lib/cjs/entities/vaultV1/vaultV1.js +228 -159
  177. package/lib/cjs/entities/vaultV2/forceWithdrawQuote.d.ts +4 -0
  178. package/lib/cjs/entities/vaultV2/forceWithdrawQuote.js +9 -4
  179. package/lib/cjs/entities/vaultV2/inKindRedeemQuote.d.ts +2 -2
  180. package/lib/cjs/entities/vaultV2/inKindRedeemQuote.js +1 -7
  181. package/lib/cjs/entities/vaultV2/vaultV2.d.ts +21 -52
  182. package/lib/cjs/entities/vaultV2/vaultV2.js +226 -150
  183. package/lib/cjs/helpers/parse.d.ts +33 -0
  184. package/lib/cjs/helpers/parse.js +71 -0
  185. package/lib/cjs/helpers/parseMidnight.d.ts +48 -0
  186. package/lib/cjs/helpers/parseMidnight.js +95 -0
  187. package/lib/cjs/helpers/parseMidnightMaker.d.ts +44 -0
  188. package/lib/cjs/helpers/parseMidnightMaker.js +154 -0
  189. package/lib/cjs/helpers/validate.d.ts +3 -2
  190. package/lib/cjs/helpers/validate.js +4 -0
  191. package/lib/cjs/helpers/validateMidnightCancelAndMakePublication.d.ts +8 -0
  192. package/lib/cjs/helpers/validateMidnightCancelAndMakePublication.js +4 -4
  193. package/lib/cjs/helpers/validateMidnightPublication.d.ts +17 -1
  194. package/lib/cjs/index.d.ts +1 -0
  195. package/lib/cjs/transactionPlan/blue/refinance.js +17 -9
  196. package/lib/cjs/transactionPlan/blue/repay.js +2 -1
  197. package/lib/cjs/transactionPlan/blue/repayWithdrawCollateral.js +23 -4
  198. package/lib/cjs/transactionPlan/blue/supplyCollateralBorrow.js +2 -2
  199. package/lib/cjs/transactionPlan/blue/withdraw.d.ts +2 -2
  200. package/lib/cjs/transactionPlan/blue/withdraw.js +3 -3
  201. package/lib/cjs/transactionPlan/blue/withdrawCollateral.js +6 -2
  202. package/lib/cjs/transactionPlan/validation.d.ts +1 -1
  203. package/lib/cjs/transactionPlan/validation.js +3 -0
  204. package/lib/cjs/transactionPlan/vaultv1/deposit.d.ts +2 -2
  205. package/lib/cjs/transactionPlan/vaultv1/deposit.js +2 -2
  206. package/lib/cjs/types/action.d.ts +13 -2
  207. package/lib/cjs/types/error.d.ts +20 -2
  208. package/lib/cjs/types/error.js +32 -3
  209. package/lib/cjs/version.d.ts +1 -1
  210. package/lib/cjs/version.js +1 -1
  211. package/lib/esm/actions/blue/borrow.d.ts +2 -1
  212. package/lib/esm/actions/blue/borrow.internal.d.ts +13 -0
  213. package/lib/esm/actions/blue/borrow.internal.js +30 -0
  214. package/lib/esm/actions/blue/borrow.js +4 -16
  215. package/lib/esm/actions/blue/common.d.ts +50 -28
  216. package/lib/esm/actions/blue/common.js +21 -33
  217. package/lib/esm/actions/blue/encode.d.ts +23 -0
  218. package/lib/esm/actions/blue/encode.js +164 -0
  219. package/lib/esm/actions/blue/refinance.d.ts +3 -2
  220. package/lib/esm/actions/blue/refinance.internal.d.ts +42 -0
  221. package/lib/esm/actions/blue/refinance.internal.js +56 -0
  222. package/lib/esm/actions/blue/refinance.js +5 -63
  223. package/lib/esm/actions/blue/refinanceValidation.d.ts +4 -5
  224. package/lib/esm/actions/blue/refinanceValidation.js +2 -4
  225. package/lib/esm/actions/blue/repay.d.ts +1 -1
  226. package/lib/esm/actions/blue/repay.internal.d.ts +13 -0
  227. package/lib/esm/actions/blue/repay.internal.js +33 -0
  228. package/lib/esm/actions/blue/repay.js +2 -17
  229. package/lib/esm/actions/blue/repayWithdrawCollateral.d.ts +2 -2
  230. package/lib/esm/actions/blue/repayWithdrawCollateral.internal.d.ts +61 -0
  231. package/lib/esm/actions/blue/repayWithdrawCollateral.internal.js +104 -0
  232. package/lib/esm/actions/blue/repayWithdrawCollateral.js +3 -116
  233. package/lib/esm/actions/blue/signatures.d.ts +30 -0
  234. package/lib/esm/actions/blue/signatures.js +82 -0
  235. package/lib/esm/actions/blue/supply.d.ts +1 -1
  236. package/lib/esm/actions/blue/supply.internal.d.ts +32 -0
  237. package/lib/esm/actions/blue/supply.internal.js +95 -0
  238. package/lib/esm/actions/blue/supply.js +2 -67
  239. package/lib/esm/actions/blue/supplyCollateral.d.ts +1 -1
  240. package/lib/esm/actions/blue/supplyCollateral.internal.d.ts +13 -0
  241. package/lib/esm/actions/blue/supplyCollateral.internal.js +32 -0
  242. package/lib/esm/actions/blue/supplyCollateral.js +2 -17
  243. package/lib/esm/actions/blue/supplyCollateralBorrow.d.ts +4 -3
  244. package/lib/esm/actions/blue/supplyCollateralBorrow.internal.d.ts +63 -0
  245. package/lib/esm/actions/blue/supplyCollateralBorrow.internal.js +87 -0
  246. package/lib/esm/actions/blue/supplyCollateralBorrow.js +5 -106
  247. package/lib/esm/actions/blue/withdraw.d.ts +4 -3
  248. package/lib/esm/actions/blue/withdraw.internal.d.ts +56 -0
  249. package/lib/esm/actions/blue/withdraw.internal.js +77 -0
  250. package/lib/esm/actions/blue/withdraw.js +5 -78
  251. package/lib/esm/actions/blue/withdrawBuyCallback.d.ts +2 -2
  252. package/lib/esm/actions/blue/withdrawBuyCallback.internal.d.ts +20 -0
  253. package/lib/esm/actions/blue/withdrawBuyCallback.internal.js +53 -0
  254. package/lib/esm/actions/blue/withdrawBuyCallback.js +2 -39
  255. package/lib/esm/actions/blue/withdrawCollateral.internal.d.ts +16 -0
  256. package/lib/esm/actions/blue/withdrawCollateral.internal.js +34 -0
  257. package/lib/esm/actions/blue/withdrawCollateral.js +2 -17
  258. package/lib/esm/actions/bundles/common.d.ts +9 -0
  259. package/lib/esm/actions/bundles/common.js +15 -4
  260. package/lib/esm/actions/bundles/index.d.ts +1 -1
  261. package/lib/esm/actions/bundles/index.js +1 -1
  262. package/lib/esm/actions/bundles/resolveBundlesTokenRequirements.d.ts +14 -0
  263. package/lib/esm/actions/bundles/resolveBundlesTokenRequirements.js +58 -61
  264. package/lib/esm/actions/midnight/cancelAndMake.d.ts +22 -1
  265. package/lib/esm/actions/midnight/cancelAndMake.js +43 -85
  266. package/lib/esm/actions/midnight/cancelOffers.d.ts +11 -0
  267. package/lib/esm/actions/midnight/cancelOffers.js +18 -2
  268. package/lib/esm/actions/midnight/encode.d.ts +36 -0
  269. package/lib/esm/actions/midnight/encode.js +539 -0
  270. package/lib/esm/actions/midnight/index.d.ts +14 -13
  271. package/lib/esm/actions/midnight/index.js +14 -13
  272. package/lib/esm/actions/midnight/parse.d.ts +35 -0
  273. package/lib/esm/actions/midnight/parse.js +68 -0
  274. package/lib/esm/actions/midnight/parseCollateralBatch.d.ts +58 -0
  275. package/lib/esm/actions/midnight/parseCollateralBatch.js +209 -0
  276. package/lib/esm/actions/midnight/redeem.d.ts +16 -3
  277. package/lib/esm/actions/midnight/redeem.js +20 -50
  278. package/lib/esm/actions/midnight/repayWithdrawCollateral.d.ts +13 -0
  279. package/lib/esm/actions/midnight/repayWithdrawCollateral.js +38 -64
  280. package/lib/esm/actions/midnight/supplyCollateral.d.ts +40 -5
  281. package/lib/esm/actions/midnight/supplyCollateral.js +57 -53
  282. package/lib/esm/actions/midnight/supplyCollateralBatch.d.ts +3 -3
  283. package/lib/esm/actions/midnight/supplyCollateralBatch.js +3 -62
  284. package/lib/esm/actions/midnight/supplyCollateralTakeBorrow.d.ts +24 -0
  285. package/lib/esm/actions/midnight/supplyCollateralTakeBorrow.js +33 -61
  286. package/lib/esm/actions/midnight/supplyCollateralWithNative.d.ts +77 -0
  287. package/lib/esm/actions/midnight/supplyCollateralWithNative.js +137 -0
  288. package/lib/esm/actions/midnight/takeBorrow.d.ts +17 -2
  289. package/lib/esm/actions/midnight/takeBorrow.js +20 -51
  290. package/lib/esm/actions/midnight/takeLend.d.ts +21 -1
  291. package/lib/esm/actions/midnight/takeLend.js +26 -54
  292. package/lib/esm/actions/midnight/takeRepayWithdrawCollateral.d.ts +22 -2
  293. package/lib/esm/actions/midnight/takeRepayWithdrawCollateral.js +30 -58
  294. package/lib/esm/actions/midnight/takeWithdraw.d.ts +17 -2
  295. package/lib/esm/actions/midnight/takeWithdraw.js +76 -114
  296. package/lib/esm/actions/midnight/withdrawCollateral.d.ts +16 -3
  297. package/lib/esm/actions/midnight/withdrawCollateral.js +23 -55
  298. package/lib/esm/actions/midnight/withdrawCollateralBatch.d.ts +3 -3
  299. package/lib/esm/actions/midnight/withdrawCollateralBatch.js +3 -71
  300. package/lib/esm/actions/requirements/blue/getBlueAuthorizationRequirement.d.ts +13 -0
  301. package/lib/esm/actions/requirements/blue/getBlueAuthorizationRequirement.js +36 -18
  302. package/lib/esm/actions/requirements/blue/index.d.ts +1 -1
  303. package/lib/esm/actions/requirements/blue/index.js +1 -1
  304. package/lib/esm/actions/requirements/chainCheck.d.ts +5 -0
  305. package/lib/esm/actions/requirements/chainCheck.js +6 -0
  306. package/lib/esm/actions/requirements/encode/encodeBlueSignatureAuthorization.d.ts +10 -0
  307. package/lib/esm/actions/requirements/encode/encodeBlueSignatureAuthorization.js +36 -25
  308. package/lib/esm/actions/requirements/encode/encodeErc20Approval.d.ts +11 -1
  309. package/lib/esm/actions/requirements/encode/encodeErc20Approval.js +33 -16
  310. package/lib/esm/actions/requirements/encode/encodeErc20Permit.d.ts +14 -1
  311. package/lib/esm/actions/requirements/encode/encodeErc20Permit.js +41 -8
  312. package/lib/esm/actions/requirements/encode/encodeErc20Permit2SignatureTransfer.d.ts +10 -0
  313. package/lib/esm/actions/requirements/encode/encodeErc20Permit2SignatureTransfer.js +59 -24
  314. package/lib/esm/actions/requirements/encode/encodeVaultSharesPermit.d.ts +10 -0
  315. package/lib/esm/actions/requirements/encode/encodeVaultSharesPermit.js +21 -2
  316. package/lib/esm/actions/requirements/encode/index.d.ts +5 -5
  317. package/lib/esm/actions/requirements/encode/index.js +5 -5
  318. package/lib/esm/actions/requirements/getRequirementsApproval.d.ts +26 -11
  319. package/lib/esm/actions/requirements/getRequirementsApproval.js +38 -12
  320. package/lib/esm/actions/requirements/index.d.ts +1 -1
  321. package/lib/esm/actions/requirements/index.js +1 -1
  322. package/lib/esm/actions/requirements/midnight/getMidnightApprovalRequirements.d.ts +11 -0
  323. package/lib/esm/actions/requirements/midnight/getMidnightApprovalRequirements.js +31 -18
  324. package/lib/esm/actions/requirements/midnight/getMidnightAuthorizationRequirement.d.ts +11 -0
  325. package/lib/esm/actions/requirements/midnight/getMidnightAuthorizationRequirement.js +22 -10
  326. package/lib/esm/actions/requirements/midnight/index.d.ts +2 -2
  327. package/lib/esm/actions/requirements/midnight/index.js +2 -2
  328. package/lib/esm/actions/vaultV1/deposit.d.ts +21 -0
  329. package/lib/esm/actions/vaultV1/deposit.js +43 -9
  330. package/lib/esm/actions/vaultV1/inKindRedeem.d.ts +18 -1
  331. package/lib/esm/actions/vaultV1/inKindRedeem.js +33 -15
  332. package/lib/esm/actions/vaultV1/index.d.ts +5 -5
  333. package/lib/esm/actions/vaultV1/index.js +5 -5
  334. package/lib/esm/actions/vaultV1/migrateToV2.d.ts +21 -0
  335. package/lib/esm/actions/vaultV1/migrateToV2.js +47 -11
  336. package/lib/esm/actions/vaultV1/redeem.d.ts +19 -0
  337. package/lib/esm/actions/vaultV1/redeem.js +26 -7
  338. package/lib/esm/actions/vaultV1/withdraw.d.ts +19 -0
  339. package/lib/esm/actions/vaultV1/withdraw.js +26 -7
  340. package/lib/esm/actions/vaultV2/deposit.d.ts +21 -0
  341. package/lib/esm/actions/vaultV2/deposit.js +43 -9
  342. package/lib/esm/actions/vaultV2/forceRedeem.d.ts +20 -2
  343. package/lib/esm/actions/vaultV2/forceRedeem.js +35 -6
  344. package/lib/esm/actions/vaultV2/forceWithdraw.d.ts +23 -1
  345. package/lib/esm/actions/vaultV2/forceWithdraw.js +33 -13
  346. package/lib/esm/actions/vaultV2/inKindRedeem.d.ts +18 -1
  347. package/lib/esm/actions/vaultV2/inKindRedeem.js +32 -14
  348. package/lib/esm/actions/vaultV2/index.d.ts +6 -6
  349. package/lib/esm/actions/vaultV2/index.js +6 -6
  350. package/lib/esm/actions/vaultV2/redeem.d.ts +19 -0
  351. package/lib/esm/actions/vaultV2/redeem.js +26 -7
  352. package/lib/esm/actions/vaultV2/withdraw.d.ts +19 -0
  353. package/lib/esm/actions/vaultV2/withdraw.js +26 -7
  354. package/lib/esm/entities/blue/blue.d.ts +35 -8
  355. package/lib/esm/entities/blue/blue.js +449 -388
  356. package/lib/esm/entities/midnight/midnight.d.ts +117 -41
  357. package/lib/esm/entities/midnight/midnight.js +455 -826
  358. package/lib/esm/entities/midnight/parse.d.ts +74 -0
  359. package/lib/esm/entities/midnight/parse.js +320 -0
  360. package/lib/esm/entities/midnight/prepare.d.ts +47 -0
  361. package/lib/esm/entities/midnight/prepare.js +282 -0
  362. package/lib/esm/entities/midnight/publication.d.ts +7 -3
  363. package/lib/esm/entities/midnight/publication.js +7 -3
  364. package/lib/esm/entities/midnight/types.d.ts +7 -0
  365. package/lib/esm/entities/requirements/assertContractCode.d.ts +10 -5
  366. package/lib/esm/entities/requirements/assertContractCode.js +24 -15
  367. package/lib/esm/entities/requirements/getBundlesTokenRequirements.d.ts +15 -0
  368. package/lib/esm/entities/requirements/getBundlesTokenRequirements.js +53 -47
  369. package/lib/esm/entities/requirements/getErc2612Permit.d.ts +7 -3
  370. package/lib/esm/entities/requirements/getErc2612Permit.js +19 -4
  371. package/lib/esm/entities/requirements/getUnusedPermit2Nonce.d.ts +15 -0
  372. package/lib/esm/entities/requirements/getUnusedPermit2Nonce.js +20 -5
  373. package/lib/esm/entities/requirements/getVaultBundlesSharesRequirements.d.ts +14 -0
  374. package/lib/esm/entities/requirements/getVaultBundlesSharesRequirements.js +23 -5
  375. package/lib/esm/entities/requirements/getVaultV1InKindRedeemRequirements.js +4 -3
  376. package/lib/esm/entities/requirements/getVaultV2ForceWithdrawRequirements.js +4 -3
  377. package/lib/esm/entities/requirements/getVaultV2InKindRedeemRequirements.js +4 -3
  378. package/lib/esm/entities/requirements/index.d.ts +2 -2
  379. package/lib/esm/entities/requirements/index.js +2 -2
  380. package/lib/esm/entities/requirements/validateNativeRequirements.d.ts +21 -0
  381. package/lib/esm/entities/requirements/validateNativeRequirements.js +33 -0
  382. package/lib/esm/entities/vaultV1/inKindRedeemQuote.d.ts +2 -2
  383. package/lib/esm/entities/vaultV1/inKindRedeemQuote.js +1 -7
  384. package/lib/esm/entities/vaultV1/vaultV1.d.ts +17 -40
  385. package/lib/esm/entities/vaultV1/vaultV1.js +208 -139
  386. package/lib/esm/entities/vaultV2/forceWithdrawQuote.d.ts +4 -0
  387. package/lib/esm/entities/vaultV2/forceWithdrawQuote.js +10 -5
  388. package/lib/esm/entities/vaultV2/inKindRedeemQuote.d.ts +2 -2
  389. package/lib/esm/entities/vaultV2/inKindRedeemQuote.js +1 -7
  390. package/lib/esm/entities/vaultV2/vaultV2.d.ts +21 -52
  391. package/lib/esm/entities/vaultV2/vaultV2.js +209 -133
  392. package/lib/esm/helpers/parse.d.ts +33 -0
  393. package/lib/esm/helpers/parse.js +61 -0
  394. package/lib/esm/helpers/parseMidnight.d.ts +48 -0
  395. package/lib/esm/helpers/parseMidnight.js +80 -0
  396. package/lib/esm/helpers/parseMidnightMaker.d.ts +44 -0
  397. package/lib/esm/helpers/parseMidnightMaker.js +147 -0
  398. package/lib/esm/helpers/validate.d.ts +3 -2
  399. package/lib/esm/helpers/validate.js +5 -1
  400. package/lib/esm/helpers/validateMidnightCancelAndMakePublication.d.ts +8 -0
  401. package/lib/esm/helpers/validateMidnightCancelAndMakePublication.js +2 -2
  402. package/lib/esm/helpers/validateMidnightPublication.d.ts +17 -1
  403. package/lib/esm/index.d.ts +1 -0
  404. package/lib/esm/transactionPlan/blue/refinance.js +18 -10
  405. package/lib/esm/transactionPlan/blue/repay.js +3 -2
  406. package/lib/esm/transactionPlan/blue/repayWithdrawCollateral.js +24 -5
  407. package/lib/esm/transactionPlan/blue/supplyCollateralBorrow.js +2 -2
  408. package/lib/esm/transactionPlan/blue/withdraw.d.ts +2 -2
  409. package/lib/esm/transactionPlan/blue/withdraw.js +3 -3
  410. package/lib/esm/transactionPlan/blue/withdrawCollateral.js +6 -2
  411. package/lib/esm/transactionPlan/validation.d.ts +1 -1
  412. package/lib/esm/transactionPlan/validation.js +3 -0
  413. package/lib/esm/transactionPlan/vaultv1/deposit.d.ts +2 -2
  414. package/lib/esm/transactionPlan/vaultv1/deposit.js +2 -2
  415. package/lib/esm/types/action.d.ts +13 -2
  416. package/lib/esm/types/error.d.ts +20 -2
  417. package/lib/esm/types/error.js +27 -0
  418. package/lib/esm/version.d.ts +1 -1
  419. package/lib/esm/version.js +1 -1
  420. package/package.json +3 -3
@@ -1,11 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.blueRefinance = void 0;
4
- const viem_1 = require("viem");
5
- const abis_js_1 = require("../../abis.js");
6
- const validate_js_1 = require("../../helpers/validate.js");
7
- const common_js_1 = require("./common.js");
8
- const refinanceValidation_js_1 = require("./refinanceValidation.js");
4
+ const encode_js_1 = require("./encode.js");
5
+ const refinance_internal_js_1 = require("./refinance.internal.js");
9
6
  /**
10
7
  * Encodes a direct BlueBundlesV1 full borrow-position migration transaction.
11
8
  *
@@ -29,7 +26,8 @@ const refinanceValidation_js_1 = require("./refinanceValidation.js");
29
26
  * @param params.metadata - Optional transaction metadata.
30
27
  * @returns A deep-frozen `Readonly<Transaction<BlueRefinanceAction>>` whose
31
28
  * `to` address is BlueBundlesV1 and whose `action` records the normalized migration inputs.
32
- * @throws {MarketIdMismatchError} when either market's `id` does not hash from its tuple fields.
29
+ * @throws {MarketIdMismatchError} when the migration source, destination, or a reallocation
30
+ * source market has an `id` that does not hash from its tuple fields.
33
31
  * @throws {RefinanceSameMarketError} when source and destination IDs match.
34
32
  * @throws {RefinanceTokenMismatchError} when their loan or collateral tokens differ.
35
33
  * @throws {NegativeInputError} when `maxLtv`, a referral fee, or a reallocation penalty is negative.
@@ -66,61 +64,5 @@ const refinanceValidation_js_1 = require("./refinanceValidation.js");
66
64
  * // tx satisfies Readonly<Transaction<BlueRefinanceAction>>
67
65
  * ```
68
66
  */
69
- const blueRefinance = (params) => {
70
- const { chainId, sourceMarketParams, destinationMarketParams } = params.market;
71
- (0, validate_js_1.validateMarketParamsId)(sourceMarketParams);
72
- (0, validate_js_1.validateMarketParamsId)(destinationMarketParams);
73
- const { userAddress, maxLtv, authorizationSignature } = params.args;
74
- // Reject same-market migrations and token mismatches before encoding.
75
- (0, refinanceValidation_js_1.validateBlueRefinanceMarkets)(sourceMarketParams, destinationMarketParams);
76
- (0, validate_js_1.validateUint256Field)("maxLtv", maxLtv);
77
- const common = {
78
- chainId,
79
- userAddress,
80
- deadline: params.args.deadline,
81
- referralFeePct: params.args.referralFeePct,
82
- referralFeeRecipient: params.args.referralFeeRecipient,
83
- metadata: params.metadata,
84
- };
85
- const { referralFeePct, referralFeeRecipient } = (0, common_js_1.normalizeBlueBundlesV1CommonParams)(common);
86
- const signedAuthorization = (0, common_js_1.getBlueBundlesV1SignedAuthorization)({
87
- chainId,
88
- userAddress,
89
- authorizationSignature,
90
- });
91
- const publicAllocations = (0, common_js_1.getBlueBundlesV1PublicAllocations)([...(params.args.reallocations ?? [])], destinationMarketParams);
92
- const reallocationPenaltyAssets = (0, common_js_1.getBlueBundlesV1PenaltyAssets)(publicAllocations);
93
- return (0, common_js_1.finalizeBlueBundlesV1Transaction)({
94
- common,
95
- value: 0n,
96
- data: (0, viem_1.encodeFunctionData)({
97
- abi: abis_js_1.blueBundlesV1Abi,
98
- functionName: "blueBundlesV1MigrateBorrowPosition",
99
- args: [
100
- sourceMarketParams,
101
- destinationMarketParams,
102
- maxLtv,
103
- signedAuthorization,
104
- publicAllocations,
105
- referralFeePct,
106
- referralFeeRecipient,
107
- params.args.deadline,
108
- ],
109
- }),
110
- action: {
111
- type: "blueRefinance",
112
- args: {
113
- sourceMarket: sourceMarketParams.id,
114
- destinationMarket: destinationMarketParams.id,
115
- maxLtv,
116
- onBehalf: userAddress,
117
- reallocations: publicAllocations.length,
118
- reallocationPenaltyAssets,
119
- referralFeePct,
120
- referralFeeRecipient,
121
- deadline: params.args.deadline,
122
- },
123
- },
124
- });
125
- };
67
+ const blueRefinance = (params) => (0, encode_js_1.encodeBlueRefinance)((0, refinance_internal_js_1.parseBlueRefinance)(params));
126
68
  exports.blueRefinance = blueRefinance;
@@ -1,5 +1,4 @@
1
1
  import { type AccrualPosition, type MarketParams } from "@morpho-org/blue-sdk";
2
- import { type VaultV2BlueReallocation } from "../../types/index.js";
3
2
  /** @internal Rejects an empty source debt or incompatible refinance markets. */
4
3
  export declare function validateBlueRefinanceSource({ sourceMarketParams, destinationMarketParams, borrowShares, }: {
5
4
  readonly sourceMarketParams: MarketParams;
@@ -7,13 +6,13 @@ export declare function validateBlueRefinanceSource({ sourceMarketParams, destin
7
6
  readonly borrowShares: bigint;
8
7
  }): void;
9
8
  /** @internal Requires distinct markets with identical loan and collateral tokens. */
10
- export declare function validateBlueRefinanceMarkets(sourceMarketParams: MarketParams, destinationMarketParams: MarketParams): void;
9
+ export declare function validateBlueRefinanceMarkets(sourceMarketParams: Pick<MarketParams, "id" | "loanToken" | "collateralToken">, destinationMarketParams: Pick<MarketParams, "id" | "loanToken" | "collateralToken">): void;
11
10
  /** @internal Checks the migration quote, including destination debt from allocator penalties and fees. */
12
- export declare function validateBlueRefinanceQuote({ destinationMarketParams, sourcePosition, destinationPosition, reallocations, referralFeePct, now, }: {
13
- readonly destinationMarketParams: MarketParams;
11
+ export declare function validateBlueRefinanceQuote({ destinationMarketParams, sourcePosition, destinationPosition, penaltyAssets, referralFeePct, now, }: {
12
+ readonly destinationMarketParams: Pick<MarketParams, "id" | "lltv">;
14
13
  readonly sourcePosition: Readonly<AccrualPosition>;
15
14
  readonly destinationPosition: Readonly<AccrualPosition>;
16
- readonly reallocations: readonly VaultV2BlueReallocation[];
15
+ readonly penaltyAssets: bigint;
17
16
  readonly referralFeePct: bigint;
18
17
  readonly now: bigint;
19
18
  }): void;
@@ -28,9 +28,7 @@ function validateBlueRefinanceMarkets(sourceMarketParams, destinationMarketParam
28
28
  }
29
29
  }
30
30
  /** @internal Checks the migration quote, including destination debt from allocator penalties and fees. */
31
- function validateBlueRefinanceQuote({ destinationMarketParams, sourcePosition, destinationPosition, reallocations, referralFeePct, now, }) {
32
- const allocations = (0, common_js_1.getBlueBundlesV1PublicAllocations)(reallocations, destinationMarketParams);
33
- const penaltyAssets = (0, common_js_1.getBlueBundlesV1PenaltyAssets)(allocations);
31
+ function validateBlueRefinanceQuote({ destinationMarketParams, sourcePosition, destinationPosition, penaltyAssets, referralFeePct, now, }) {
34
32
  const accrualTimestamp = blue_sdk_1.MathLib.max(now, sourcePosition.market.lastUpdate, destinationPosition.market.lastUpdate) + morpho_ts_1.Time.s.from.h(2n);
35
33
  const source = sourcePosition.accrueInterest(accrualTimestamp);
36
34
  const destination = destinationPosition.accrueInterest(accrualTimestamp);
@@ -1,5 +1,5 @@
1
1
  import type { MarketParams } from "@morpho-org/blue-sdk";
2
- import { type Address } from "viem";
2
+ import type { Address } from "viem";
3
3
  import type { BlueRepayAction, BundlesTokenRequirementSignature, Metadata, Transaction } from "../../types/index.js";
4
4
  /** Parameters for {@link blueRepay}. */
5
5
  export interface BlueRepayParams {
@@ -0,0 +1,13 @@
1
+ import type { BlueRepayAction, Transaction } from "../../types/index.js";
2
+ import type { BlueRepayParams } from "./repay.js";
3
+ import { type BlueRepayInput, parseBlueRepayWithdrawCollateral } from "./repayWithdrawCollateral.internal.js";
4
+ /** Complete pure-repay input with collateral withdrawal disabled. @internal */
5
+ export interface BlueRepayOnlyInput extends BlueRepayInput {
6
+ readonly collateralAssets: 0n;
7
+ }
8
+ /** Constructs the complete raw repay with a fixed inactive collateral leg. @internal */
9
+ export declare const parseBlueRepay: (params: BlueRepayParams & {
10
+ readonly args: Pick<Parameters<typeof parseBlueRepayWithdrawCollateral>[0]["args"], "authorizationSignature">;
11
+ }) => BlueRepayOnlyInput & Pick<ReturnType<typeof parseBlueRepayWithdrawCollateral>, "bound">;
12
+ /** Encodes only a completed pure repay operation. @internal */
13
+ export declare const buildBlueRepay: (parsed: ReturnType<typeof parseBlueRepay>) => Readonly<Transaction<BlueRepayAction>>;
@@ -0,0 +1,38 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.buildBlueRepay = exports.parseBlueRepay = void 0;
4
+ const morpho_ts_1 = require("@morpho-org/morpho-ts");
5
+ const viem_1 = require("viem");
6
+ const encode_js_1 = require("./encode.js");
7
+ const repayWithdrawCollateral_internal_js_1 = require("./repayWithdrawCollateral.internal.js");
8
+ /** Constructs the complete raw repay with a fixed inactive collateral leg. @internal */
9
+ const parseBlueRepay = (params) => ({
10
+ ...(0, repayWithdrawCollateral_internal_js_1.parseBlueRepayWithdrawCollateral)({
11
+ ...params,
12
+ args: {
13
+ authorizationSignature: params.args.authorizationSignature,
14
+ userAddress: params.args.userAddress,
15
+ repayAssets: params.args.repayAssets,
16
+ repayShares: params.args.repayShares,
17
+ maxRepayAssets: params.args.maxRepayAssets,
18
+ nativeAmount: params.args.nativeAmount,
19
+ deadline: params.args.deadline,
20
+ referralFeePct: params.args.referralFeePct,
21
+ referralFeeRecipient: params.args.referralFeeRecipient,
22
+ requirementSignature: params.args.requirementSignature,
23
+ collateralAssets: 0n,
24
+ maxLtv: viem_1.maxUint256,
25
+ },
26
+ }),
27
+ collateralAssets: 0n,
28
+ });
29
+ exports.parseBlueRepay = parseBlueRepay;
30
+ /** Encodes only a completed pure repay operation. @internal */
31
+ const buildBlueRepay = (parsed) => {
32
+ const transaction = (0, encode_js_1.encodeBlueRepayWithdrawCollateral)(parsed);
33
+ return (0, morpho_ts_1.deepFreeze)({
34
+ ...transaction,
35
+ action: { ...transaction.action, type: "blueRepay" },
36
+ });
37
+ };
38
+ exports.buildBlueRepay = buildBlueRepay;
@@ -1,9 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.blueRepay = void 0;
4
- const morpho_ts_1 = require("@morpho-org/morpho-ts");
5
- const viem_1 = require("viem");
6
- const repayWithdrawCollateral_js_1 = require("./repayWithdrawCollateral.js");
4
+ const repay_internal_js_1 = require("./repay.internal.js");
7
5
  /**
8
6
  * Encodes a pure repayment through BlueBundlesV1.
9
7
  *
@@ -63,18 +61,5 @@ const repayWithdrawCollateral_js_1 = require("./repayWithdrawCollateral.js");
63
61
  * // tx satisfies Readonly<Transaction<BlueRepayAction>>
64
62
  * ```
65
63
  */
66
- const blueRepay = (params) => {
67
- const transaction = (0, repayWithdrawCollateral_js_1.blueRepayWithdrawCollateral)({
68
- ...params,
69
- args: {
70
- ...params.args,
71
- collateralAssets: 0n,
72
- maxLtv: viem_1.maxUint256,
73
- },
74
- });
75
- return (0, morpho_ts_1.deepFreeze)({
76
- ...transaction,
77
- action: { ...transaction.action, type: "blueRepay" },
78
- });
79
- };
64
+ const blueRepay = (params) => (0, repay_internal_js_1.buildBlueRepay)((0, repay_internal_js_1.parseBlueRepay)(params));
80
65
  exports.blueRepay = blueRepay;
@@ -1,6 +1,6 @@
1
1
  import type { MarketParams } from "@morpho-org/blue-sdk";
2
- import { type Address } from "viem";
3
- import { type AuthorizationRequirementSignature, type BlueRepayWithdrawCollateralAction, type BundlesTokenRequirementSignature, type Metadata, type Transaction } from "../../types/index.js";
2
+ import type { Address } from "viem";
3
+ import type { AuthorizationRequirementSignature, BlueRepayWithdrawCollateralAction, BundlesTokenRequirementSignature, Metadata, Transaction } from "../../types/index.js";
4
4
  /** Parameters for {@link blueRepayWithdrawCollateral}. */
5
5
  export interface BlueRepayWithdrawCollateralParams {
6
6
  /** Chain and scoped Morpho Blue market. */
@@ -0,0 +1,61 @@
1
+ import { parseBlueMarket, parseUint256 } from "../../helpers/parse.js";
2
+ import { type BlueRepayWithdrawCollateralAction, type Transaction } from "../../types/index.js";
3
+ import type { BlueOperationInput } from "./common.js";
4
+ import type { BlueRepayWithdrawCollateralParams } from "./repayWithdrawCollateral.js";
5
+ declare const blueRepayBrand: unique symbol;
6
+ /** Complete repay params, including covered funding and exclusive legs. @internal */
7
+ export interface BlueRepayInput extends BlueOperationInput {
8
+ readonly repayAssets: bigint;
9
+ readonly repayShares: bigint;
10
+ readonly collateralAssets: bigint;
11
+ readonly maxLtv: bigint;
12
+ readonly hasRepay: boolean;
13
+ readonly minimumRepayAssets: bigint;
14
+ readonly maxRepayAssets: bigint;
15
+ readonly value: bigint;
16
+ readonly [blueRepayBrand]: true;
17
+ }
18
+ /** Constructs the complete raw repay operation, preserving signature and funding precedence. @internal */
19
+ export declare const parseBlueRepayWithdrawCollateral: (params: BlueRepayWithdrawCollateralParams) => {
20
+ deadline: bigint;
21
+ referralFeePct: bigint;
22
+ referralFeeRecipient: import("viem").Address;
23
+ chainId: number;
24
+ userAddress: import("viem").Address;
25
+ marketParams: import("../../helpers/parse.js").BlueMarket;
26
+ metadata?: import("../../index.js").Metadata;
27
+ repayAssets: bigint;
28
+ repayShares: bigint;
29
+ collateralAssets: bigint;
30
+ maxLtv: bigint;
31
+ hasRepay: boolean;
32
+ minimumRepayAssets: bigint;
33
+ maxRepayAssets: bigint;
34
+ value: bigint;
35
+ [blueRepayBrand]: true;
36
+ bound: {
37
+ readonly maxRepayAssets: bigint;
38
+ readonly loanTokenPermit: ReturnType<typeof import("./common.js").getBlueBundlesV1TokenPermit>;
39
+ readonly signedAuthorization: ReturnType<typeof import("./common.js").getBlueBundlesV1SignedAuthorization>;
40
+ };
41
+ };
42
+ /** Parses mutually exclusive repay modes and the nonempty leg rule. @internal */
43
+ export declare const parseBlueRepayMode: (marketParams: ReturnType<typeof parseBlueMarket>, amounts: {
44
+ readonly repayAssets: bigint;
45
+ readonly repayShares: bigint;
46
+ readonly collateralAssets: bigint;
47
+ }) => {
48
+ hasRepay: boolean;
49
+ collateralAssets: bigint;
50
+ };
51
+ /** Parses active/inactive funding-cap rules. @internal */
52
+ export declare const parseBlueRepayCap: (mode: Pick<ReturnType<typeof parseBlueRepayMode>, "hasRepay">, maxRepayAssets: ReturnType<typeof parseUint256>) => bigint;
53
+ /** Parses cap coverage, after common referral normalization. @internal */
54
+ export declare const parseBlueRepayCoverage: (legs: {
55
+ readonly minimumRepayAssets: bigint;
56
+ }, maxRepayAssets: ReturnType<typeof parseBlueRepayCap>) => bigint;
57
+ /** Independently validates fresh buildTx signatures before encoding. @internal */
58
+ export declare const buildBlueRepayWithdrawCollateral: (parsed: BlueRepayInput, signatures?: Pick<BlueRepayWithdrawCollateralParams["args"], "requirementSignature" | "authorizationSignature"> & {
59
+ readonly signatureFunding?: boolean;
60
+ }) => Readonly<Transaction<BlueRepayWithdrawCollateralAction>>;
61
+ export {};
@@ -0,0 +1,112 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.buildBlueRepayWithdrawCollateral = exports.parseBlueRepayCoverage = exports.parseBlueRepayCap = exports.parseBlueRepayMode = exports.parseBlueRepayWithdrawCollateral = void 0;
4
+ const parse_js_1 = require("../../helpers/parse.js");
5
+ const index_js_1 = require("../../types/index.js");
6
+ const common_js_1 = require("./common.js");
7
+ const encode_js_1 = require("./encode.js");
8
+ const signatures_js_1 = require("./signatures.js");
9
+ /** Constructs the complete raw repay operation, preserving signature and funding precedence. @internal */
10
+ const parseBlueRepayWithdrawCollateral = (params) => {
11
+ const marketParams = (0, parse_js_1.parseBlueMarket)(params.market.marketParams);
12
+ const amounts = {
13
+ repayAssets: (0, parse_js_1.parseUint256)("repayAssets", params.args.repayAssets),
14
+ repayShares: (0, parse_js_1.parseUint256)("repayShares", params.args.repayShares),
15
+ maxRepayAssets: (0, parse_js_1.parseUint256)("maxRepayAssets", params.args.maxRepayAssets),
16
+ collateralAssets: (0, parse_js_1.parseUint256)("collateralAssets", params.args.collateralAssets),
17
+ maxLtv: (0, parse_js_1.parseUint256)("maxLtv", params.args.maxLtv),
18
+ };
19
+ const mode = (0, exports.parseBlueRepayMode)(marketParams, amounts);
20
+ const cap = (0, exports.parseBlueRepayCap)(mode, amounts.maxRepayAssets);
21
+ // Reject signatures for inactive legs before continuing.
22
+ (0, signatures_js_1.validateBlueRepaySignatureLegs)(mode, params.args);
23
+ const common = {
24
+ chainId: params.market.chainId,
25
+ userAddress: params.args.userAddress,
26
+ deadline: params.args.deadline,
27
+ referralFeePct: params.args.referralFeePct,
28
+ referralFeeRecipient: params.args.referralFeeRecipient,
29
+ metadata: params.metadata,
30
+ };
31
+ const normalized = (0, common_js_1.parseBlueBundlesV1Common)(common);
32
+ const legs = {
33
+ ...normalized,
34
+ chainId: common.chainId,
35
+ userAddress: common.userAddress,
36
+ marketParams,
37
+ metadata: common.metadata,
38
+ ...amounts,
39
+ hasRepay: mode.hasRepay,
40
+ minimumRepayAssets: amounts.repayAssets +
41
+ (0, common_js_1.getBlueBundlesV1ReferralFeeAssets)(amounts.repayAssets, normalized.referralFeePct),
42
+ };
43
+ const maxRepayAssets = (0, exports.parseBlueRepayCoverage)(legs, cap);
44
+ const value = (0, parse_js_1.parseNativeFunding)({
45
+ chainId: common.chainId,
46
+ token: marketParams.loanToken,
47
+ fundedAmount: maxRepayAssets,
48
+ nativeAmount: params.args.nativeAmount,
49
+ });
50
+ const fields = {
51
+ ...legs,
52
+ maxRepayAssets,
53
+ value,
54
+ };
55
+ const input = fields;
56
+ return {
57
+ ...input,
58
+ bound: (0, signatures_js_1.bindBlueRepaySignatures)(input, {
59
+ maxRepayAssets,
60
+ signatures: params.args,
61
+ }),
62
+ };
63
+ };
64
+ exports.parseBlueRepayWithdrawCollateral = parseBlueRepayWithdrawCollateral;
65
+ /** Parses mutually exclusive repay modes and the nonempty leg rule. @internal */
66
+ const parseBlueRepayMode = (marketParams, amounts) => {
67
+ const { repayAssets, repayShares, collateralAssets } = amounts;
68
+ if (repayAssets > 0n && repayShares > 0n) {
69
+ throw new index_js_1.MutuallyExclusiveRepayAmountsError(marketParams.id);
70
+ }
71
+ const hasRepay = repayAssets > 0n || repayShares > 0n;
72
+ if (!hasRepay && collateralAssets === 0n) {
73
+ throw new index_js_1.NonPositiveInputError("repayAssets, repayShares, or collateralAssets", 0n);
74
+ }
75
+ const result = { hasRepay, collateralAssets };
76
+ return result;
77
+ };
78
+ exports.parseBlueRepayMode = parseBlueRepayMode;
79
+ /** Parses active/inactive funding-cap rules. @internal */
80
+ const parseBlueRepayCap = (mode, maxRepayAssets) => {
81
+ if (mode.hasRepay && maxRepayAssets === 0n) {
82
+ throw new index_js_1.NonPositiveInputError("maxRepayAssets", maxRepayAssets);
83
+ }
84
+ if (!mode.hasRepay && maxRepayAssets > 0n) {
85
+ throw new index_js_1.InputExceedsMaxError({
86
+ field: "maxRepayAssets",
87
+ value: maxRepayAssets,
88
+ max: 0n,
89
+ });
90
+ }
91
+ return maxRepayAssets;
92
+ };
93
+ exports.parseBlueRepayCap = parseBlueRepayCap;
94
+ /** Parses cap coverage, after common referral normalization. @internal */
95
+ const parseBlueRepayCoverage = (legs, maxRepayAssets) => {
96
+ if (legs.minimumRepayAssets > maxRepayAssets) {
97
+ throw new index_js_1.MaxRepayAssetsBelowRepayAssetsError(maxRepayAssets, legs.minimumRepayAssets);
98
+ }
99
+ return maxRepayAssets;
100
+ };
101
+ exports.parseBlueRepayCoverage = parseBlueRepayCoverage;
102
+ /** Independently validates fresh buildTx signatures before encoding. @internal */
103
+ const buildBlueRepayWithdrawCollateral = (parsed, signatures = {}) => {
104
+ const maxRepayAssets = (0, signatures_js_1.parseBlueRepaySignatureFunding)(parsed, signatures);
105
+ // Reject signatures for inactive legs before continuing.
106
+ (0, signatures_js_1.validateBlueRepaySignatureLegs)(parsed, signatures);
107
+ return (0, encode_js_1.encodeBlueRepayWithdrawCollateral)({
108
+ ...parsed,
109
+ bound: (0, signatures_js_1.bindBlueRepaySignatures)(parsed, { maxRepayAssets, signatures }),
110
+ });
111
+ };
112
+ exports.buildBlueRepayWithdrawCollateral = buildBlueRepayWithdrawCollateral;
@@ -1,11 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.blueRepayWithdrawCollateral = void 0;
4
- const viem_1 = require("viem");
5
- const abis_js_1 = require("../../abis.js");
6
- const validate_js_1 = require("../../helpers/validate.js");
7
- const index_js_1 = require("../../types/index.js");
8
- const common_js_1 = require("./common.js");
4
+ const encode_js_1 = require("./encode.js");
5
+ const repayWithdrawCollateral_internal_js_1 = require("./repayWithdrawCollateral.internal.js");
9
6
  /**
10
7
  * Encodes a direct BlueBundlesV1 repay and/or collateral-withdrawal transaction.
11
8
  *
@@ -72,115 +69,5 @@ const common_js_1 = require("./common.js");
72
69
  * // tx satisfies Readonly<Transaction<BlueRepayWithdrawCollateralAction>>
73
70
  * ```
74
71
  */
75
- const blueRepayWithdrawCollateral = (params) => {
76
- const { chainId, marketParams } = params.market;
77
- (0, validate_js_1.validateMarketParamsId)(marketParams);
78
- const { userAddress, repayAssets, repayShares, maxRepayAssets, collateralAssets, maxLtv, requirementSignature, authorizationSignature, } = params.args;
79
- for (const [field, value] of [
80
- ["repayAssets", repayAssets],
81
- ["repayShares", repayShares],
82
- ["maxRepayAssets", maxRepayAssets],
83
- ["collateralAssets", collateralAssets],
84
- ["maxLtv", maxLtv],
85
- ]) {
86
- (0, validate_js_1.validateUint256Field)(field, value);
87
- }
88
- if (repayAssets > 0n && repayShares > 0n) {
89
- throw new index_js_1.MutuallyExclusiveRepayAmountsError(marketParams.id);
90
- }
91
- const hasRepay = repayAssets + repayShares > 0n;
92
- if (repayAssets + repayShares + collateralAssets === 0n) {
93
- throw new index_js_1.NonPositiveInputError("repayAssets, repayShares, or collateralAssets", 0n);
94
- }
95
- if (hasRepay && maxRepayAssets === 0n) {
96
- throw new index_js_1.NonPositiveInputError("maxRepayAssets", maxRepayAssets);
97
- }
98
- if (!hasRepay && maxRepayAssets > 0n) {
99
- // Withdrawal-only has no repay leg to fund: reject stray funding that would encode a phantom
100
- // repay. Native funding is transitively rejected — `validateBlueBundlesV1NativeFunding`
101
- // requires `nativeAmount === maxRepayAssets` (= 0).
102
- throw new index_js_1.InputExceedsMaxError({
103
- field: "maxRepayAssets",
104
- value: maxRepayAssets,
105
- max: 0n,
106
- });
107
- }
108
- if (!hasRepay && requirementSignature != null) {
109
- throw new index_js_1.UnexpectedRequirementSignatureError(requirementSignature.action.type);
110
- }
111
- if (collateralAssets === 0n && authorizationSignature != null) {
112
- throw new index_js_1.UnexpectedRequirementSignatureError("authorization");
113
- }
114
- const common = {
115
- chainId,
116
- userAddress,
117
- deadline: params.args.deadline,
118
- referralFeePct: params.args.referralFeePct,
119
- referralFeeRecipient: params.args.referralFeeRecipient,
120
- metadata: params.metadata,
121
- };
122
- const { referralFeePct, referralFeeRecipient } = (0, common_js_1.normalizeBlueBundlesV1CommonParams)(common);
123
- const minimumRepayAssets = repayAssets +
124
- (0, common_js_1.getBlueBundlesV1ReferralFeeAssets)(repayAssets, referralFeePct);
125
- if (minimumRepayAssets > maxRepayAssets) {
126
- throw new index_js_1.MaxRepayAssetsBelowRepayAssetsError(maxRepayAssets, minimumRepayAssets);
127
- }
128
- const value = (0, common_js_1.validateBlueBundlesV1NativeFunding)({
129
- chainId,
130
- token: marketParams.loanToken,
131
- fundedAmount: maxRepayAssets,
132
- nativeAmount: params.args.nativeAmount,
133
- requirementSignature,
134
- });
135
- const loanTokenPermit = (0, common_js_1.getBlueBundlesV1TokenPermit)({
136
- chainId,
137
- userAddress,
138
- token: marketParams.loanToken,
139
- amount: maxRepayAssets,
140
- requirementSignature,
141
- });
142
- const signedAuthorization = (0, common_js_1.getBlueBundlesV1SignedAuthorization)({
143
- chainId,
144
- userAddress,
145
- authorizationSignature,
146
- });
147
- return (0, common_js_1.finalizeBlueBundlesV1Transaction)({
148
- common,
149
- value,
150
- data: (0, viem_1.encodeFunctionData)({
151
- abi: abis_js_1.blueBundlesV1Abi,
152
- functionName: "blueBundlesV1RepayAndWithdrawCollateral",
153
- args: [
154
- marketParams,
155
- repayAssets,
156
- repayShares,
157
- maxRepayAssets,
158
- collateralAssets,
159
- maxLtv,
160
- loanTokenPermit,
161
- signedAuthorization,
162
- referralFeePct,
163
- referralFeeRecipient,
164
- params.args.deadline,
165
- ],
166
- }),
167
- action: {
168
- type: "blueRepayWithdrawCollateral",
169
- args: {
170
- market: marketParams.id,
171
- repayAssets,
172
- repayShares,
173
- maxRepayAssets,
174
- collateralAssets,
175
- maxLtv,
176
- onBehalf: userAddress,
177
- nativeAmount: value > 0n ? value : undefined,
178
- referralFeePct,
179
- referralFeeRecipient,
180
- referralFeeAssets: repayAssets > 0n ? minimumRepayAssets - repayAssets : undefined,
181
- deadline: params.args.deadline,
182
- },
183
- },
184
- });
185
- };
72
+ const blueRepayWithdrawCollateral = (params) => (0, encode_js_1.encodeBlueRepayWithdrawCollateral)((0, repayWithdrawCollateral_internal_js_1.parseBlueRepayWithdrawCollateral)(params));
186
73
  exports.blueRepayWithdrawCollateral = blueRepayWithdrawCollateral;
@@ -0,0 +1,30 @@
1
+ import { getBlueBundlesV1SignedAuthorization, getBlueBundlesV1TokenPermit } from "./common.js";
2
+ import type { BlueRepayInput, parseBlueRepayMode } from "./repayWithdrawCollateral.internal.js";
3
+ import type { BlueRepayWithdrawCollateralParams } from "./repayWithdrawCollateral.js";
4
+ import type { BlueSupplyCollateralBorrowInput } from "./supplyCollateralBorrow.internal.js";
5
+ import type { BlueSupplyCollateralBorrowParams } from "./supplyCollateralBorrow.js";
6
+ /** Validates signature presence for inactive legs. @internal */
7
+ export declare const validateBlueSupplyCollateralBorrowSignatureLegs: (amounts: {
8
+ readonly collateralAssets: bigint;
9
+ readonly borrowAssets: bigint;
10
+ }, signatures: Pick<BlueSupplyCollateralBorrowParams["args"], "requirementSignature" | "authorizationSignature">) => void;
11
+ /** Independently binds signatures for active funding and borrow legs. @internal */
12
+ export declare const bindBlueSupplyCollateralBorrowSignatures: (parsed: Pick<BlueSupplyCollateralBorrowInput, "chainId" | "userAddress" | "marketParams" | "collateralAssets" | "value">, signatures: Pick<BlueSupplyCollateralBorrowParams["args"], "requirementSignature" | "authorizationSignature">) => {
13
+ readonly collateralPermit: ReturnType<typeof getBlueBundlesV1TokenPermit>;
14
+ readonly signedAuthorization: ReturnType<typeof getBlueBundlesV1SignedAuthorization>;
15
+ };
16
+ /** Validates signatures for inactive repay/withdraw legs. @internal */
17
+ export declare const validateBlueRepaySignatureLegs: (mode: Pick<ReturnType<typeof parseBlueRepayMode>, "hasRepay" | "collateralAssets">, signatures: Pick<BlueRepayWithdrawCollateralParams["args"], "requirementSignature" | "authorizationSignature">) => void;
18
+ /** Parses fresh signature-selected full-repay funding. @internal */
19
+ export declare const parseBlueRepaySignatureFunding: (parsed: BlueRepayInput, signatures: Pick<BlueRepayWithdrawCollateralParams["args"], "requirementSignature" | "authorizationSignature"> & {
20
+ readonly signatureFunding?: boolean;
21
+ }) => bigint;
22
+ /** Binds independently supplied token and authorization signatures. @internal */
23
+ export declare const bindBlueRepaySignatures: (parsed: BlueRepayInput, params: {
24
+ readonly maxRepayAssets: bigint;
25
+ readonly signatures: Pick<BlueRepayWithdrawCollateralParams["args"], "requirementSignature" | "authorizationSignature">;
26
+ }) => {
27
+ readonly maxRepayAssets: bigint;
28
+ readonly loanTokenPermit: ReturnType<typeof getBlueBundlesV1TokenPermit>;
29
+ readonly signedAuthorization: ReturnType<typeof getBlueBundlesV1SignedAuthorization>;
30
+ };
@@ -0,0 +1,90 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.bindBlueRepaySignatures = exports.parseBlueRepaySignatureFunding = exports.validateBlueRepaySignatureLegs = exports.bindBlueSupplyCollateralBorrowSignatures = exports.validateBlueSupplyCollateralBorrowSignatureLegs = void 0;
4
+ const parse_js_1 = require("../../helpers/parse.js");
5
+ const index_js_1 = require("../../types/index.js");
6
+ const common_js_1 = require("./common.js");
7
+ /** Validates signature presence for inactive legs. @internal */
8
+ const validateBlueSupplyCollateralBorrowSignatureLegs = (amounts, signatures) => {
9
+ const { collateralAssets, borrowAssets } = amounts;
10
+ const { requirementSignature, authorizationSignature } = signatures;
11
+ if (collateralAssets === 0n && requirementSignature != null) {
12
+ throw new index_js_1.UnexpectedRequirementSignatureError(requirementSignature.action.type);
13
+ }
14
+ if (borrowAssets === 0n && authorizationSignature != null) {
15
+ throw new index_js_1.UnexpectedRequirementSignatureError("authorization");
16
+ }
17
+ };
18
+ exports.validateBlueSupplyCollateralBorrowSignatureLegs = validateBlueSupplyCollateralBorrowSignatureLegs;
19
+ /** Independently binds signatures for active funding and borrow legs. @internal */
20
+ const bindBlueSupplyCollateralBorrowSignatures = (parsed, signatures) => {
21
+ const { chainId, userAddress, marketParams, collateralAssets, value } = parsed;
22
+ const { requirementSignature, authorizationSignature } = signatures;
23
+ if (value > 0n && requirementSignature != null) {
24
+ throw new index_js_1.UnexpectedRequirementSignatureError(requirementSignature.action.type);
25
+ }
26
+ const collateralPermit = (0, common_js_1.getBlueBundlesV1TokenPermit)({
27
+ chainId,
28
+ userAddress,
29
+ token: marketParams.collateralToken,
30
+ amount: collateralAssets,
31
+ requirementSignature,
32
+ });
33
+ const signedAuthorization = (0, common_js_1.getBlueBundlesV1SignedAuthorization)({
34
+ chainId,
35
+ userAddress,
36
+ authorizationSignature,
37
+ });
38
+ return { collateralPermit, signedAuthorization };
39
+ };
40
+ exports.bindBlueSupplyCollateralBorrowSignatures = bindBlueSupplyCollateralBorrowSignatures;
41
+ /** Validates signatures for inactive repay/withdraw legs. @internal */
42
+ const validateBlueRepaySignatureLegs = (mode, signatures) => {
43
+ const { hasRepay, collateralAssets } = mode;
44
+ const { requirementSignature, authorizationSignature } = signatures;
45
+ if (!hasRepay && requirementSignature != null) {
46
+ throw new index_js_1.UnexpectedRequirementSignatureError(requirementSignature.action.type);
47
+ }
48
+ if (collateralAssets === 0n && authorizationSignature != null) {
49
+ throw new index_js_1.UnexpectedRequirementSignatureError("authorization");
50
+ }
51
+ };
52
+ exports.validateBlueRepaySignatureLegs = validateBlueRepaySignatureLegs;
53
+ /** Parses fresh signature-selected full-repay funding. @internal */
54
+ const parseBlueRepaySignatureFunding = (parsed, signatures) => {
55
+ const { repayShares } = parsed;
56
+ const { requirementSignature, signatureFunding = false } = signatures;
57
+ const selectedMaxRepayAssets = signatureFunding && repayShares > 0n && requirementSignature != null
58
+ ? requirementSignature.args.amount
59
+ : parsed.maxRepayAssets;
60
+ if (selectedMaxRepayAssets < parsed.maxRepayAssets) {
61
+ throw new index_js_1.MaxRepayAssetsBelowRepayAssetsError(selectedMaxRepayAssets, parsed.maxRepayAssets);
62
+ }
63
+ const maxRepayAssets = signatureFunding && repayShares > 0n && requirementSignature != null
64
+ ? (0, parse_js_1.parseUint256)("maxRepayAssets", selectedMaxRepayAssets)
65
+ : selectedMaxRepayAssets;
66
+ return maxRepayAssets;
67
+ };
68
+ exports.parseBlueRepaySignatureFunding = parseBlueRepaySignatureFunding;
69
+ /** Binds independently supplied token and authorization signatures. @internal */
70
+ const bindBlueRepaySignatures = (parsed, params) => {
71
+ const { chainId, userAddress, marketParams, value } = parsed;
72
+ const { maxRepayAssets, signatures: { requirementSignature, authorizationSignature }, } = params;
73
+ if (value > 0n && requirementSignature != null) {
74
+ throw new index_js_1.UnexpectedRequirementSignatureError(requirementSignature.action.type);
75
+ }
76
+ const loanTokenPermit = (0, common_js_1.getBlueBundlesV1TokenPermit)({
77
+ chainId,
78
+ userAddress,
79
+ token: marketParams.loanToken,
80
+ amount: maxRepayAssets,
81
+ requirementSignature,
82
+ });
83
+ const signedAuthorization = (0, common_js_1.getBlueBundlesV1SignedAuthorization)({
84
+ chainId,
85
+ userAddress,
86
+ authorizationSignature,
87
+ });
88
+ return { maxRepayAssets, loanTokenPermit, signedAuthorization };
89
+ };
90
+ exports.bindBlueRepaySignatures = bindBlueRepaySignatures;