@morpho-org/morpho-sdk 6.0.0-next.0 → 6.0.0-next.2

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 (296) hide show
  1. package/MIGRATION-v5-to-v6.md +329 -15
  2. package/README.md +93 -47
  3. package/lib/cjs/abis.d.ts +227 -2
  4. package/lib/cjs/abis.js +156 -3
  5. package/lib/cjs/actions/blue/borrow.d.ts +1 -1
  6. package/lib/cjs/actions/blue/borrow.js +1 -1
  7. package/lib/cjs/actions/blue/common.d.ts +6 -19
  8. package/lib/cjs/actions/blue/common.js +28 -162
  9. package/lib/cjs/actions/blue/refinance.d.ts +1 -1
  10. package/lib/cjs/actions/blue/refinance.js +1 -1
  11. package/lib/cjs/actions/blue/repay.d.ts +3 -3
  12. package/lib/cjs/actions/blue/repay.js +1 -1
  13. package/lib/cjs/actions/blue/repayWithdrawCollateral.d.ts +3 -3
  14. package/lib/cjs/actions/blue/repayWithdrawCollateral.js +1 -1
  15. package/lib/cjs/actions/blue/supply.d.ts +3 -3
  16. package/lib/cjs/actions/blue/supply.js +3 -8
  17. package/lib/cjs/actions/blue/supplyCollateral.d.ts +3 -3
  18. package/lib/cjs/actions/blue/supplyCollateral.js +1 -1
  19. package/lib/cjs/actions/blue/supplyCollateralBorrow.d.ts +3 -3
  20. package/lib/cjs/actions/blue/supplyCollateralBorrow.js +1 -1
  21. package/lib/cjs/actions/blue/withdraw.d.ts +1 -1
  22. package/lib/cjs/actions/blue/withdraw.js +1 -1
  23. package/lib/cjs/actions/blue/withdrawCollateral.d.ts +1 -1
  24. package/lib/cjs/actions/blue/withdrawCollateral.js +1 -1
  25. package/lib/cjs/actions/bundles/common.d.ts +230 -0
  26. package/lib/cjs/actions/bundles/common.js +507 -0
  27. package/lib/cjs/actions/bundles/index.d.ts +3 -0
  28. package/lib/cjs/actions/bundles/index.js +23 -0
  29. package/lib/cjs/actions/bundles/resolveBundlesTokenRequirements.d.ts +76 -0
  30. package/lib/cjs/actions/bundles/resolveBundlesTokenRequirements.js +125 -0
  31. package/lib/cjs/actions/index.d.ts +1 -0
  32. package/lib/cjs/actions/index.js +1 -0
  33. package/lib/cjs/actions/midnight/supplyCollateralTakeBorrow.d.ts +2 -2
  34. package/lib/cjs/actions/midnight/supplyCollateralTakeBorrow.js +2 -2
  35. package/lib/cjs/actions/midnight/takeBorrow.d.ts +2 -2
  36. package/lib/cjs/actions/midnight/takeBorrow.js +2 -2
  37. package/lib/cjs/actions/midnight/takeLend.d.ts +2 -2
  38. package/lib/cjs/actions/midnight/takeLend.js +2 -2
  39. package/lib/cjs/actions/requirements/blue/getBlueAuthorizationRequirement.d.ts +3 -0
  40. package/lib/cjs/actions/requirements/blue/getBlueAuthorizationRequirement.js +6 -10
  41. package/lib/cjs/actions/requirements/blue/index.d.ts +0 -2
  42. package/lib/cjs/actions/requirements/blue/index.js +0 -2
  43. package/lib/cjs/actions/requirements/encode/encodeBlueSignatureAuthorization.d.ts +15 -8
  44. package/lib/cjs/actions/requirements/encode/encodeBlueSignatureAuthorization.js +21 -21
  45. package/lib/cjs/actions/requirements/encode/encodeErc20Approval.d.ts +1 -1
  46. package/lib/cjs/actions/requirements/encode/encodeErc20Approval.js +2 -1
  47. package/lib/cjs/actions/requirements/encode/encodeErc20Permit.d.ts +19 -10
  48. package/lib/cjs/actions/requirements/encode/encodeErc20Permit.js +43 -31
  49. package/lib/cjs/actions/requirements/encode/encodeErc20Permit2Approve.d.ts +4 -2
  50. package/lib/cjs/actions/requirements/encode/encodeErc20Permit2Approve.js +15 -10
  51. package/lib/{esm/actions/requirements/encode/encodeErc20Permit2TransferFrom.d.ts → cjs/actions/requirements/encode/encodeErc20Permit2SignatureTransfer.d.ts} +16 -14
  52. package/lib/cjs/actions/requirements/encode/{encodeErc20Permit2TransferFrom.js → encodeErc20Permit2SignatureTransfer.js} +27 -22
  53. package/lib/cjs/actions/requirements/encode/encodeVaultSharesPermit.d.ts +12 -9
  54. package/lib/cjs/actions/requirements/encode/encodeVaultSharesPermit.js +27 -21
  55. package/lib/cjs/actions/requirements/encode/index.d.ts +1 -1
  56. package/lib/cjs/actions/requirements/encode/index.js +1 -1
  57. package/lib/cjs/actions/requirements/generalAdapter/getGeneralAdapterRequirements.js +1 -0
  58. package/lib/cjs/actions/requirements/generalAdapter/getGeneralAdapterRequirementsPermit.d.ts +4 -1
  59. package/lib/cjs/actions/requirements/generalAdapter/getGeneralAdapterRequirementsPermit.js +5 -2
  60. package/lib/cjs/actions/requirements/getRequirementsApproval.d.ts +4 -3
  61. package/lib/cjs/actions/requirements/getRequirementsApproval.js +4 -3
  62. package/lib/cjs/actions/signatures/getTokenRequirementActions.js +2 -2
  63. package/lib/cjs/actions/signatures/getVaultExitBundlesV1PermitStruct.d.ts +28 -30
  64. package/lib/cjs/actions/signatures/getVaultExitBundlesV1PermitStruct.js +20 -66
  65. package/lib/cjs/actions/vaultV1/deposit.d.ts +73 -57
  66. package/lib/cjs/actions/vaultV1/deposit.js +110 -109
  67. package/lib/cjs/actions/vaultV1/inKindRedeem.d.ts +1 -0
  68. package/lib/cjs/actions/vaultV1/inKindRedeem.js +3 -2
  69. package/lib/cjs/actions/vaultV1/migrateToV2.d.ts +43 -66
  70. package/lib/cjs/actions/vaultV1/migrateToV2.js +91 -104
  71. package/lib/cjs/actions/vaultV1/redeem.d.ts +30 -23
  72. package/lib/cjs/actions/vaultV1/redeem.js +56 -33
  73. package/lib/cjs/actions/vaultV1/withdraw.d.ts +58 -24
  74. package/lib/cjs/actions/vaultV1/withdraw.js +86 -34
  75. package/lib/cjs/actions/vaultV2/deposit.d.ts +74 -57
  76. package/lib/cjs/actions/vaultV2/deposit.js +111 -109
  77. package/lib/cjs/actions/vaultV2/forceWithdraw.d.ts +58 -39
  78. package/lib/cjs/actions/vaultV2/forceWithdraw.js +87 -60
  79. package/lib/cjs/actions/vaultV2/inKindRedeem.d.ts +1 -0
  80. package/lib/cjs/actions/vaultV2/inKindRedeem.js +3 -2
  81. package/lib/cjs/actions/vaultV2/redeem.d.ts +30 -24
  82. package/lib/cjs/actions/vaultV2/redeem.js +56 -34
  83. package/lib/cjs/actions/vaultV2/withdraw.d.ts +58 -25
  84. package/lib/cjs/actions/vaultV2/withdraw.js +86 -35
  85. package/lib/cjs/augment/VaultMarketPublicAllocatorConfig.d.ts +4 -1
  86. package/lib/cjs/blue/abis.d.ts +5 -1
  87. package/lib/cjs/blue/abis.js +2 -0
  88. package/lib/cjs/blue/entities.d.ts +8 -2
  89. package/lib/cjs/blue/entities.js +1 -0
  90. package/lib/cjs/blue/errors.d.ts +1 -1
  91. package/lib/cjs/blue/errors.js +2 -1
  92. package/lib/cjs/blue/fetch.d.ts +3 -1
  93. package/lib/cjs/blue/fetch.js +1 -0
  94. package/lib/cjs/entities/blue/blue.d.ts +29 -20
  95. package/lib/cjs/entities/blue/blue.js +6 -1
  96. package/lib/cjs/entities/index.d.ts +9 -2
  97. package/lib/cjs/entities/index.js +16 -0
  98. package/lib/cjs/entities/midnight/midnight.d.ts +2 -2
  99. package/lib/cjs/entities/midnight/midnight.js +20 -24
  100. package/lib/cjs/{actions/requirements/blue/getBlueBundlesV1TokenRequirements.d.ts → entities/requirements/getBundlesTokenRequirements.d.ts} +27 -19
  101. package/lib/cjs/{actions/requirements/blue/getBlueBundlesV1TokenRequirements.js → entities/requirements/getBundlesTokenRequirements.js} +76 -75
  102. package/lib/{esm/actions/requirements/blue → cjs/entities/requirements}/getUnusedPermit2Nonce.d.ts +1 -1
  103. package/lib/cjs/{actions/requirements/blue → entities/requirements}/getUnusedPermit2Nonce.js +4 -4
  104. package/lib/cjs/entities/requirements/getVaultBundlesSharesRequirements.d.ts +28 -0
  105. package/lib/cjs/entities/requirements/getVaultBundlesSharesRequirements.js +74 -0
  106. package/lib/cjs/entities/requirements/index.d.ts +2 -0
  107. package/lib/cjs/entities/requirements/index.js +18 -0
  108. package/lib/cjs/entities/vaultV1/vaultV1.d.ts +356 -101
  109. package/lib/cjs/entities/vaultV1/vaultV1.js +334 -120
  110. package/lib/cjs/entities/vaultV1ReallocationData.d.ts +6 -0
  111. package/lib/cjs/entities/vaultV1ReallocationData.js +20 -5
  112. package/lib/cjs/entities/vaultV2/vaultV2.d.ts +359 -100
  113. package/lib/cjs/entities/vaultV2/vaultV2.js +448 -93
  114. package/lib/cjs/entities/vaultV2BlueReallocationData.d.ts +8 -1
  115. package/lib/cjs/entities/vaultV2BlueReallocationData.js +46 -13
  116. package/lib/cjs/errors.d.ts +1 -1
  117. package/lib/cjs/errors.js +3 -2
  118. package/lib/cjs/fetch.d.ts +3 -1
  119. package/lib/cjs/fetch.js +1 -0
  120. package/lib/cjs/helpers/computeVaultV1Reallocations.d.ts +2 -0
  121. package/lib/cjs/helpers/computeVaultV1Reallocations.js +2 -0
  122. package/lib/cjs/helpers/index.d.ts +4 -1
  123. package/lib/cjs/helpers/index.js +14 -1
  124. package/lib/cjs/helpers/metadata.d.ts +3 -5
  125. package/lib/cjs/helpers/metadata.js +4 -6
  126. package/lib/cjs/helpers/previewVaultV2ForceWithdraw.d.ts +107 -0
  127. package/lib/cjs/helpers/previewVaultV2ForceWithdraw.js +164 -0
  128. package/lib/cjs/helpers/previewVaultV2InKindRedeem.d.ts +1 -0
  129. package/lib/cjs/helpers/previewVaultV2InKindRedeem.js +2 -0
  130. package/lib/cjs/helpers/referralFee.d.ts +21 -0
  131. package/lib/cjs/helpers/referralFee.js +35 -0
  132. package/lib/cjs/helpers/slippage.d.ts +136 -1
  133. package/lib/cjs/helpers/slippage.js +188 -0
  134. package/lib/cjs/helpers/validate.d.ts +67 -8
  135. package/lib/cjs/helpers/validate.js +94 -9
  136. package/lib/cjs/helpers/validateRequirementSpender.d.ts +1 -1
  137. package/lib/cjs/helpers/validateRequirementSpender.js +1 -0
  138. package/lib/cjs/helpers/vaultV2ForceWithdrawPlan.d.ts +274 -0
  139. package/lib/cjs/helpers/vaultV2ForceWithdrawPlan.js +369 -0
  140. package/lib/cjs/index.d.ts +1 -0
  141. package/lib/cjs/index.js +1 -0
  142. package/lib/cjs/types/action.d.ts +273 -82
  143. package/lib/cjs/types/action.js +12 -12
  144. package/lib/cjs/types/error.d.ts +349 -23
  145. package/lib/cjs/types/error.js +393 -39
  146. package/lib/cjs/types/sharedLiquidity.d.ts +2 -2
  147. package/lib/cjs/utils.d.ts +3 -1
  148. package/lib/cjs/utils.js +10 -1
  149. package/lib/esm/abis.d.ts +227 -2
  150. package/lib/esm/abis.js +157 -2
  151. package/lib/esm/actions/blue/borrow.d.ts +1 -1
  152. package/lib/esm/actions/blue/borrow.js +1 -1
  153. package/lib/esm/actions/blue/common.d.ts +6 -19
  154. package/lib/esm/actions/blue/common.js +30 -164
  155. package/lib/esm/actions/blue/refinance.d.ts +1 -1
  156. package/lib/esm/actions/blue/refinance.js +1 -1
  157. package/lib/esm/actions/blue/repay.d.ts +3 -3
  158. package/lib/esm/actions/blue/repay.js +1 -1
  159. package/lib/esm/actions/blue/repayWithdrawCollateral.d.ts +3 -3
  160. package/lib/esm/actions/blue/repayWithdrawCollateral.js +1 -1
  161. package/lib/esm/actions/blue/supply.d.ts +3 -3
  162. package/lib/esm/actions/blue/supply.js +5 -10
  163. package/lib/esm/actions/blue/supplyCollateral.d.ts +3 -3
  164. package/lib/esm/actions/blue/supplyCollateral.js +1 -1
  165. package/lib/esm/actions/blue/supplyCollateralBorrow.d.ts +3 -3
  166. package/lib/esm/actions/blue/supplyCollateralBorrow.js +1 -1
  167. package/lib/esm/actions/blue/withdraw.d.ts +1 -1
  168. package/lib/esm/actions/blue/withdraw.js +1 -1
  169. package/lib/esm/actions/blue/withdrawCollateral.d.ts +1 -1
  170. package/lib/esm/actions/blue/withdrawCollateral.js +1 -1
  171. package/lib/esm/actions/bundles/common.d.ts +230 -0
  172. package/lib/esm/actions/bundles/common.js +494 -0
  173. package/lib/esm/actions/bundles/index.d.ts +3 -0
  174. package/lib/esm/actions/bundles/index.js +2 -0
  175. package/lib/esm/actions/bundles/resolveBundlesTokenRequirements.d.ts +76 -0
  176. package/lib/esm/actions/bundles/resolveBundlesTokenRequirements.js +121 -0
  177. package/lib/esm/actions/index.d.ts +1 -0
  178. package/lib/esm/actions/index.js +1 -0
  179. package/lib/esm/actions/midnight/supplyCollateralTakeBorrow.d.ts +2 -2
  180. package/lib/esm/actions/midnight/supplyCollateralTakeBorrow.js +2 -2
  181. package/lib/esm/actions/midnight/takeBorrow.d.ts +2 -2
  182. package/lib/esm/actions/midnight/takeBorrow.js +2 -2
  183. package/lib/esm/actions/midnight/takeLend.d.ts +2 -2
  184. package/lib/esm/actions/midnight/takeLend.js +2 -2
  185. package/lib/esm/actions/requirements/blue/getBlueAuthorizationRequirement.d.ts +3 -0
  186. package/lib/esm/actions/requirements/blue/getBlueAuthorizationRequirement.js +8 -12
  187. package/lib/esm/actions/requirements/blue/index.d.ts +0 -2
  188. package/lib/esm/actions/requirements/blue/index.js +0 -2
  189. package/lib/esm/actions/requirements/encode/encodeBlueSignatureAuthorization.d.ts +15 -8
  190. package/lib/esm/actions/requirements/encode/encodeBlueSignatureAuthorization.js +22 -22
  191. package/lib/esm/actions/requirements/encode/encodeErc20Approval.d.ts +1 -1
  192. package/lib/esm/actions/requirements/encode/encodeErc20Approval.js +2 -1
  193. package/lib/esm/actions/requirements/encode/encodeErc20Permit.d.ts +19 -10
  194. package/lib/esm/actions/requirements/encode/encodeErc20Permit.js +44 -32
  195. package/lib/esm/actions/requirements/encode/encodeErc20Permit2Approve.d.ts +4 -2
  196. package/lib/esm/actions/requirements/encode/encodeErc20Permit2Approve.js +15 -10
  197. package/lib/{cjs/actions/requirements/encode/encodeErc20Permit2TransferFrom.d.ts → esm/actions/requirements/encode/encodeErc20Permit2SignatureTransfer.d.ts} +16 -14
  198. package/lib/esm/actions/requirements/encode/{encodeErc20Permit2TransferFrom.js → encodeErc20Permit2SignatureTransfer.js} +25 -20
  199. package/lib/esm/actions/requirements/encode/encodeVaultSharesPermit.d.ts +12 -9
  200. package/lib/esm/actions/requirements/encode/encodeVaultSharesPermit.js +27 -21
  201. package/lib/esm/actions/requirements/encode/index.d.ts +1 -1
  202. package/lib/esm/actions/requirements/encode/index.js +1 -1
  203. package/lib/esm/actions/requirements/generalAdapter/getGeneralAdapterRequirements.js +1 -0
  204. package/lib/esm/actions/requirements/generalAdapter/getGeneralAdapterRequirementsPermit.d.ts +4 -1
  205. package/lib/esm/actions/requirements/generalAdapter/getGeneralAdapterRequirementsPermit.js +5 -2
  206. package/lib/esm/actions/requirements/getRequirementsApproval.d.ts +4 -3
  207. package/lib/esm/actions/requirements/getRequirementsApproval.js +4 -3
  208. package/lib/esm/actions/signatures/getTokenRequirementActions.js +3 -3
  209. package/lib/esm/actions/signatures/getVaultExitBundlesV1PermitStruct.d.ts +28 -30
  210. package/lib/esm/actions/signatures/getVaultExitBundlesV1PermitStruct.js +21 -67
  211. package/lib/esm/actions/vaultV1/deposit.d.ts +73 -57
  212. package/lib/esm/actions/vaultV1/deposit.js +112 -111
  213. package/lib/esm/actions/vaultV1/inKindRedeem.d.ts +1 -0
  214. package/lib/esm/actions/vaultV1/inKindRedeem.js +3 -2
  215. package/lib/esm/actions/vaultV1/migrateToV2.d.ts +43 -66
  216. package/lib/esm/actions/vaultV1/migrateToV2.js +93 -106
  217. package/lib/esm/actions/vaultV1/redeem.d.ts +30 -23
  218. package/lib/esm/actions/vaultV1/redeem.js +56 -33
  219. package/lib/esm/actions/vaultV1/withdraw.d.ts +58 -24
  220. package/lib/esm/actions/vaultV1/withdraw.js +86 -34
  221. package/lib/esm/actions/vaultV2/deposit.d.ts +74 -57
  222. package/lib/esm/actions/vaultV2/deposit.js +113 -111
  223. package/lib/esm/actions/vaultV2/forceWithdraw.d.ts +58 -39
  224. package/lib/esm/actions/vaultV2/forceWithdraw.js +89 -62
  225. package/lib/esm/actions/vaultV2/inKindRedeem.d.ts +1 -0
  226. package/lib/esm/actions/vaultV2/inKindRedeem.js +3 -2
  227. package/lib/esm/actions/vaultV2/redeem.d.ts +30 -24
  228. package/lib/esm/actions/vaultV2/redeem.js +56 -34
  229. package/lib/esm/actions/vaultV2/withdraw.d.ts +58 -25
  230. package/lib/esm/actions/vaultV2/withdraw.js +86 -35
  231. package/lib/esm/augment/VaultMarketPublicAllocatorConfig.d.ts +4 -1
  232. package/lib/esm/augment/VaultMarketPublicAllocatorConfig.js +3 -1
  233. package/lib/esm/blue/abis.d.ts +5 -1
  234. package/lib/esm/blue/abis.js +5 -1
  235. package/lib/esm/blue/entities.d.ts +8 -2
  236. package/lib/esm/blue/entities.js +3 -1
  237. package/lib/esm/blue/errors.d.ts +1 -1
  238. package/lib/esm/blue/errors.js +1 -1
  239. package/lib/esm/blue/fetch.d.ts +3 -1
  240. package/lib/esm/blue/fetch.js +3 -1
  241. package/lib/esm/entities/blue/blue.d.ts +29 -20
  242. package/lib/esm/entities/blue/blue.js +7 -2
  243. package/lib/esm/entities/index.d.ts +9 -2
  244. package/lib/esm/entities/index.js +4 -1
  245. package/lib/esm/entities/midnight/midnight.d.ts +2 -2
  246. package/lib/esm/entities/midnight/midnight.js +20 -24
  247. package/lib/esm/{actions/requirements/blue/getBlueBundlesV1TokenRequirements.d.ts → entities/requirements/getBundlesTokenRequirements.d.ts} +27 -19
  248. package/lib/esm/{actions/requirements/blue/getBlueBundlesV1TokenRequirements.js → entities/requirements/getBundlesTokenRequirements.js} +67 -66
  249. package/lib/{cjs/actions/requirements/blue → esm/entities/requirements}/getUnusedPermit2Nonce.d.ts +1 -1
  250. package/lib/esm/{actions/requirements/blue → entities/requirements}/getUnusedPermit2Nonce.js +4 -4
  251. package/lib/esm/entities/requirements/getVaultBundlesSharesRequirements.d.ts +28 -0
  252. package/lib/esm/entities/requirements/getVaultBundlesSharesRequirements.js +70 -0
  253. package/lib/esm/entities/requirements/index.d.ts +2 -0
  254. package/lib/esm/entities/requirements/index.js +2 -0
  255. package/lib/esm/entities/vaultV1/vaultV1.d.ts +356 -101
  256. package/lib/esm/entities/vaultV1/vaultV1.js +338 -124
  257. package/lib/esm/entities/vaultV1ReallocationData.d.ts +6 -0
  258. package/lib/esm/entities/vaultV1ReallocationData.js +20 -5
  259. package/lib/esm/entities/vaultV2/vaultV2.d.ts +359 -100
  260. package/lib/esm/entities/vaultV2/vaultV2.js +452 -97
  261. package/lib/esm/entities/vaultV2BlueReallocationData.d.ts +8 -1
  262. package/lib/esm/entities/vaultV2BlueReallocationData.js +46 -13
  263. package/lib/esm/errors.d.ts +1 -1
  264. package/lib/esm/errors.js +1 -1
  265. package/lib/esm/fetch.d.ts +3 -1
  266. package/lib/esm/fetch.js +3 -1
  267. package/lib/esm/helpers/computeVaultV1Reallocations.d.ts +2 -0
  268. package/lib/esm/helpers/computeVaultV1Reallocations.js +2 -0
  269. package/lib/esm/helpers/index.d.ts +4 -1
  270. package/lib/esm/helpers/index.js +4 -1
  271. package/lib/esm/helpers/metadata.d.ts +3 -5
  272. package/lib/esm/helpers/metadata.js +4 -6
  273. package/lib/esm/helpers/previewVaultV2ForceWithdraw.d.ts +107 -0
  274. package/lib/esm/helpers/previewVaultV2ForceWithdraw.js +161 -0
  275. package/lib/esm/helpers/previewVaultV2InKindRedeem.d.ts +1 -0
  276. package/lib/esm/helpers/previewVaultV2InKindRedeem.js +2 -0
  277. package/lib/esm/helpers/referralFee.d.ts +21 -0
  278. package/lib/esm/helpers/referralFee.js +31 -0
  279. package/lib/esm/helpers/slippage.d.ts +136 -1
  280. package/lib/esm/helpers/slippage.js +186 -2
  281. package/lib/esm/helpers/validate.d.ts +67 -8
  282. package/lib/esm/helpers/validate.js +92 -10
  283. package/lib/esm/helpers/validateRequirementSpender.d.ts +1 -1
  284. package/lib/esm/helpers/validateRequirementSpender.js +1 -0
  285. package/lib/esm/helpers/vaultV2ForceWithdrawPlan.d.ts +274 -0
  286. package/lib/esm/helpers/vaultV2ForceWithdrawPlan.js +362 -0
  287. package/lib/esm/index.d.ts +1 -0
  288. package/lib/esm/index.js +1 -0
  289. package/lib/esm/types/action.d.ts +273 -82
  290. package/lib/esm/types/action.js +11 -11
  291. package/lib/esm/types/error.d.ts +349 -23
  292. package/lib/esm/types/error.js +377 -31
  293. package/lib/esm/types/sharedLiquidity.d.ts +2 -2
  294. package/lib/esm/utils.d.ts +3 -1
  295. package/lib/esm/utils.js +3 -1
  296. package/package.json +7 -7
@@ -0,0 +1,507 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.finalizeVaultBundlesV1Transaction = exports.getBundlesReferralFeeAssets = exports.selectBundlesSharesPermitSignature = exports.selectBundlesSharesRequirementSignature = exports.selectBundlesTokenRequirementSignature = exports.getBundlesSharesPermit = exports.normalizeBundlesSignature = exports.getBundlesTokenPermit = exports.resolveBundlesFunding = exports.normalizeBundlesCommonParams = exports.BundlesPermitKind = void 0;
4
+ const blue_sdk_1 = require("@morpho-org/blue-sdk");
5
+ const morpho_ts_1 = require("@morpho-org/morpho-ts");
6
+ const viem_1 = require("viem");
7
+ const index_js_1 = require("../../helpers/index.js");
8
+ const validate_js_1 = require("../../helpers/validate.js");
9
+ const index_js_2 = require("../../types/index.js");
10
+ /** Numeric permit kinds consumed by `TokenLib.pullToken`. */
11
+ exports.BundlesPermitKind = {
12
+ None: 0,
13
+ ERC2612: 1,
14
+ Permit2: 2,
15
+ };
16
+ const EMPTY_TOKEN_PERMIT = {
17
+ kind: exports.BundlesPermitKind.None,
18
+ data: "0x",
19
+ };
20
+ /**
21
+ * Validates and normalizes a bundles deadline and referral fee configuration.
22
+ *
23
+ * @internal
24
+ *
25
+ * @param params - Common bundles parameters.
26
+ * @returns Validated values with explicit zero defaults.
27
+ * @throws {NonPositiveInputError} when `deadline` is not positive.
28
+ * @throws {InputExceedsMaxError} when `deadline` exceeds uint256.
29
+ * @throws {NegativeInputError} when `referralFeePct` is negative.
30
+ * @throws {ReferralFeePctExceededError} when `referralFeePct >= WAD`.
31
+ * @throws {ReferralFeeRecipientMissingError} when a positive fee has no recipient.
32
+ */
33
+ const normalizeBundlesCommonParams = (params) => {
34
+ (0, validate_js_1.validateDeadline)(params.deadline);
35
+ const { referralFeePct, referralFeeRecipient } = (0, validate_js_1.validateReferralFee)(params);
36
+ return {
37
+ deadline: params.deadline,
38
+ referralFeePct,
39
+ referralFeeRecipient,
40
+ };
41
+ };
42
+ exports.normalizeBundlesCommonParams = normalizeBundlesCommonParams;
43
+ /**
44
+ * Resolves mutually exclusive ERC-20/native funding into the entrypoint amount and transaction value.
45
+ *
46
+ * @param params - Exclusive bundles funding.
47
+ * @param params.amount - ERC-20 funding in the token's smallest unit; mutually exclusive with `nativeAmount`.
48
+ * @param params.nativeAmount - Native funding in wei; mutually exclusive with `amount`.
49
+ * @returns The gross ABI asset amount and native transaction value.
50
+ * @throws {MixedBundlesFundingError} when both funding keys are present.
51
+ * @throws {NegativeInputError} when the selected amount is negative.
52
+ * @throws {NonPositiveInputError} when the selected amount is not positive.
53
+ * @example
54
+ * ```ts
55
+ * import { resolveBundlesFunding } from "@morpho-org/morpho-sdk";
56
+ *
57
+ * const funding = resolveBundlesFunding({ amount: 1_000_000n });
58
+ * // funding is { assets: 1_000_000n, value: 0n }
59
+ * ```
60
+ */
61
+ const resolveBundlesFunding = (params) => {
62
+ const amount = "amount" in params ? params.amount : undefined;
63
+ const nativeAmount = "nativeAmount" in params ? params.nativeAmount : undefined;
64
+ if (amount != null && nativeAmount != null) {
65
+ throw new index_js_2.MixedBundlesFundingError();
66
+ }
67
+ const assets = amount ?? nativeAmount ?? 0n;
68
+ if (assets < 0n) {
69
+ throw new index_js_2.NegativeInputError(amount != null ? "amount" : "nativeAmount", assets);
70
+ }
71
+ if (assets === 0n) {
72
+ throw new index_js_2.NonPositiveInputError(amount != null ? "amount" : "nativeAmount", assets);
73
+ }
74
+ return { assets, value: nativeAmount ?? 0n };
75
+ };
76
+ exports.resolveBundlesFunding = resolveBundlesFunding;
77
+ /**
78
+ * Converts an optional signed token requirement into the ABI-ready TokenLib permit tuple.
79
+ *
80
+ * @param params - Expected funding values and optional signed requirement.
81
+ * @param params.userAddress - Account funding the operation; must match the signature owner.
82
+ * @param params.token - ERC-20 funding token; must match the signed asset.
83
+ * @param params.spender - Fixed bundles contract authorized to pull the token.
84
+ * @param params.amount - Exact pull amount in the token's smallest unit; must match both signed amount fields.
85
+ * @param params.requirementSignature - Optional signed ERC-2612 or Permit2 SignatureTransfer requirement; omit for allowance funding.
86
+ * @returns An empty, ERC-2612, or Permit2 SignatureTransfer token permit.
87
+ * @throws {UnexpectedRequirementSignatureError} when Permit2 AllowanceTransfer is supplied.
88
+ * @throws {DepositOwnerMismatchError} when the signature owner differs from `userAddress`.
89
+ * @throws {DepositAssetMismatchError} when the signed token differs from `token`.
90
+ * @throws {DepositAmountMismatchError} when the signed amount differs from `amount`.
91
+ * @throws {DepositSpenderMismatchError} when the signed spender differs from `spender`.
92
+ * @throws {BundlesRequirementSignatureMismatchError} when signature metadata is malformed.
93
+ * @example
94
+ * ```ts
95
+ * import { getBundlesTokenPermit } from "@morpho-org/morpho-sdk";
96
+ * import { zeroAddress } from "viem";
97
+ *
98
+ * const permit = getBundlesTokenPermit({
99
+ * userAddress: zeroAddress,
100
+ * token: zeroAddress,
101
+ * spender: zeroAddress,
102
+ * amount: 1n,
103
+ * });
104
+ * // permit is { kind: 0, data: "0x" }
105
+ * ```
106
+ */
107
+ const getBundlesTokenPermit = (params) => {
108
+ const { requirementSignature } = params;
109
+ if (requirementSignature == null)
110
+ return { ...EMPTY_TOKEN_PERMIT };
111
+ if (requirementSignature.action.type === "permit2") {
112
+ throw new index_js_2.UnexpectedRequirementSignatureError("permit");
113
+ }
114
+ if (!(0, viem_1.isAddressEqual)(requirementSignature.args.owner, params.userAddress)) {
115
+ throw new index_js_2.DepositOwnerMismatchError(params.userAddress, requirementSignature.args.owner);
116
+ }
117
+ if (!(0, viem_1.isAddressEqual)(requirementSignature.args.asset, params.token)) {
118
+ throw new index_js_2.DepositAssetMismatchError(params.token, requirementSignature.args.asset);
119
+ }
120
+ if (requirementSignature.args.amount !== params.amount ||
121
+ requirementSignature.action.args.amount !== params.amount) {
122
+ throw new index_js_2.DepositAmountMismatchError(params.amount, requirementSignature.args.amount);
123
+ }
124
+ if (!(0, viem_1.isAddressEqual)(requirementSignature.action.args.spender, params.spender)) {
125
+ throw new index_js_2.DepositSpenderMismatchError(params.spender, requirementSignature.action.args.spender);
126
+ }
127
+ if (requirementSignature.action.args.deadline !==
128
+ requirementSignature.args.deadline) {
129
+ throw new index_js_2.BundlesRequirementSignatureMismatchError({
130
+ field: "deadline",
131
+ expected: String(requirementSignature.args.deadline),
132
+ actual: String(requirementSignature.action.args.deadline),
133
+ });
134
+ }
135
+ if (requirementSignature.action.type === "permit2SignatureTransfer" &&
136
+ requirementSignature.action.args.nonce !== requirementSignature.args.nonce) {
137
+ throw new index_js_2.BundlesRequirementSignatureMismatchError({
138
+ field: "nonce",
139
+ expected: String(requirementSignature.args.nonce),
140
+ actual: String(requirementSignature.action.args.nonce),
141
+ });
142
+ }
143
+ if (requirementSignature.action.type === "permit2SignatureTransfer") {
144
+ return {
145
+ kind: exports.BundlesPermitKind.Permit2,
146
+ data: (0, viem_1.encodeAbiParameters)([
147
+ { type: "uint256", name: "nonce" },
148
+ { type: "uint256", name: "deadline" },
149
+ { type: "bytes", name: "signature" },
150
+ ], [
151
+ requirementSignature.args.nonce,
152
+ requirementSignature.args.deadline,
153
+ requirementSignature.args.signature,
154
+ ]),
155
+ };
156
+ }
157
+ let signature;
158
+ try {
159
+ signature = (0, exports.normalizeBundlesSignature)(requirementSignature.args.signature);
160
+ }
161
+ catch (cause) {
162
+ if (cause instanceof index_js_2.BundlesPermitMismatchError) {
163
+ throw new index_js_2.BundlesRequirementSignatureMismatchError({
164
+ field: "signature",
165
+ expected: cause.expected,
166
+ actual: cause.actual,
167
+ cause,
168
+ });
169
+ }
170
+ throw cause;
171
+ }
172
+ return {
173
+ kind: exports.BundlesPermitKind.ERC2612,
174
+ data: (0, viem_1.encodeAbiParameters)([
175
+ { type: "uint256", name: "deadline" },
176
+ { type: "uint8", name: "v" },
177
+ { type: "bytes32", name: "r" },
178
+ { type: "bytes32", name: "s" },
179
+ ], [
180
+ requirementSignature.args.deadline,
181
+ signature.v,
182
+ signature.r,
183
+ signature.s,
184
+ ]),
185
+ };
186
+ };
187
+ exports.getBundlesTokenPermit = getBundlesTokenPermit;
188
+ /**
189
+ * Normalizes a compact or serialized ECDSA signature for bundles permit tuples.
190
+ *
191
+ * @internal
192
+ *
193
+ * @param serializedSignature - Compact or serialized ECDSA signature.
194
+ * @param onInvalid - Error factory used when parsing or extracting the recovery identifier fails.
195
+ * @returns The normalized signature tuple.
196
+ * @throws {BundlesPermitMismatchError} when the signature is malformed.
197
+ */
198
+ const normalizeBundlesSignature = (serializedSignature, onInvalid = (details) => new index_js_2.BundlesPermitMismatchError({ field: "signature", ...details })) => {
199
+ let parsed;
200
+ try {
201
+ parsed =
202
+ (0, viem_1.size)(serializedSignature) === 64
203
+ ? (0, viem_1.compactSignatureToSignature)((0, viem_1.parseCompactSignature)(serializedSignature))
204
+ : (0, viem_1.parseSignature)(serializedSignature);
205
+ }
206
+ catch (cause) {
207
+ throw onInvalid({
208
+ expected: "a 64-byte compact or 65-byte serialized ECDSA signature",
209
+ actual: serializedSignature,
210
+ cause,
211
+ });
212
+ }
213
+ const normalizedV = parsed.v ??
214
+ (parsed.yParity == null ? undefined : BigInt(parsed.yParity + 27));
215
+ if (normalizedV == null) {
216
+ throw onInvalid({
217
+ expected: "a signature containing v or yParity",
218
+ actual: serializedSignature,
219
+ });
220
+ }
221
+ return { v: Number(normalizedV), r: parsed.r, s: parsed.s };
222
+ };
223
+ exports.normalizeBundlesSignature = normalizeBundlesSignature;
224
+ /**
225
+ * Converts an optional vault-share ERC-2612 requirement into the ABI-ready Permit tuple.
226
+ *
227
+ * @param params - Vault token, empty-sentinel deadline, and optional signed requirement.
228
+ * @param params.vault - Vault share token authorized by the permit.
229
+ * @param params.deadline - Unix timestamp in seconds used by the empty-permit sentinel.
230
+ * @param params.owner - Optional expected signature owner.
231
+ * @param params.spender - Optional expected fixed bundles contract authorized to pull shares.
232
+ * @param params.amount - Optional exact share allowance in the vault share token's smallest unit.
233
+ * @param params.requirementSignature - Optional signed ERC-2612 share requirement; omit for the empty-permit sentinel.
234
+ * @returns The signed share permit or the contract's empty-permit sentinel.
235
+ * @throws {BundlesPermitMismatchError} when the requirement kind, token, or signature is invalid.
236
+ * @example
237
+ * ```ts
238
+ * import { getBundlesSharesPermit } from "@morpho-org/morpho-sdk";
239
+ * import { zeroAddress } from "viem";
240
+ *
241
+ * const permit = getBundlesSharesPermit({
242
+ * vault: zeroAddress,
243
+ * deadline: 1_900_000_000n,
244
+ * });
245
+ * // permit.value === 0n
246
+ * ```
247
+ */
248
+ const getBundlesSharesPermit = (params) => {
249
+ const { requirementSignature } = params;
250
+ if (requirementSignature == null) {
251
+ return {
252
+ value: 0n,
253
+ nonce: 0n,
254
+ deadline: params.deadline,
255
+ v: 0,
256
+ r: viem_1.zeroHash,
257
+ s: viem_1.zeroHash,
258
+ };
259
+ }
260
+ if (requirementSignature.action.type !== "permit") {
261
+ throw new index_js_2.BundlesPermitMismatchError({
262
+ field: "type",
263
+ expected: "permit",
264
+ actual: requirementSignature.action.type,
265
+ });
266
+ }
267
+ if (!(0, viem_1.isAddressEqual)(requirementSignature.args.asset, params.vault)) {
268
+ throw new index_js_2.BundlesPermitMismatchError({
269
+ field: "asset",
270
+ expected: params.vault,
271
+ actual: requirementSignature.args.asset,
272
+ });
273
+ }
274
+ if (params.owner != null &&
275
+ !(0, viem_1.isAddressEqual)(requirementSignature.args.owner, params.owner)) {
276
+ throw new index_js_2.BundlesPermitMismatchError({
277
+ field: "owner",
278
+ expected: params.owner,
279
+ actual: requirementSignature.args.owner,
280
+ });
281
+ }
282
+ if (params.spender != null &&
283
+ !(0, viem_1.isAddressEqual)(requirementSignature.action.args.spender, params.spender)) {
284
+ throw new index_js_2.BundlesPermitMismatchError({
285
+ field: "spender",
286
+ expected: params.spender,
287
+ actual: requirementSignature.action.args.spender,
288
+ });
289
+ }
290
+ if (params.amount != null &&
291
+ (requirementSignature.args.amount !== params.amount ||
292
+ requirementSignature.action.args.amount !== params.amount)) {
293
+ throw new index_js_2.BundlesPermitMismatchError({
294
+ field: "amount",
295
+ expected: String(params.amount),
296
+ actual: String(requirementSignature.args.amount),
297
+ });
298
+ }
299
+ if ((params.owner != null || params.spender != null || params.amount != null) &&
300
+ requirementSignature.action.args.deadline !==
301
+ requirementSignature.args.deadline) {
302
+ throw new index_js_2.BundlesPermitMismatchError({
303
+ field: "deadline",
304
+ expected: String(requirementSignature.args.deadline),
305
+ actual: String(requirementSignature.action.args.deadline),
306
+ });
307
+ }
308
+ const signature = (0, exports.normalizeBundlesSignature)(requirementSignature.args.signature);
309
+ return {
310
+ value: requirementSignature.args.amount,
311
+ nonce: requirementSignature.args.nonce,
312
+ deadline: requirementSignature.args.deadline,
313
+ ...signature,
314
+ };
315
+ };
316
+ exports.getBundlesSharesPermit = getBundlesSharesPermit;
317
+ /**
318
+ * Selects the one token signature accepted by a bundles-funded call.
319
+ *
320
+ * @internal
321
+ *
322
+ * @param signatures - Signatures passed to `buildTx`.
323
+ * @param expectedRequirement - Signature requirement captured by this prepared operation.
324
+ * @returns The selected ERC-2612 or Permit2 SignatureTransfer signature.
325
+ * @throws {UnexpectedRequirementSignatureError} when a non-token signature is supplied.
326
+ * @throws {AmbiguousRequirementSignaturesError} when both token signature kinds are supplied.
327
+ */
328
+ const selectBundlesTokenRequirementSignature = (signatures, expectedRequirement) => {
329
+ if (signatures == null || signatures.length === 0)
330
+ return undefined;
331
+ const selected = signatures.filter((signature) => signature.action.type === "permit" ||
332
+ signature.action.type === "permit2SignatureTransfer");
333
+ if (selected.length !== signatures.length) {
334
+ const unexpected = signatures.find((signature) => signature.action.type !== "permit" &&
335
+ signature.action.type !== "permit2SignatureTransfer");
336
+ throw new index_js_2.UnexpectedRequirementSignatureError(unexpected?.action.type === "authorization"
337
+ ? "authorization"
338
+ : unexpected?.action.type === "midnightOfferRootSignature"
339
+ ? "midnightOfferRootSignature"
340
+ : "permit");
341
+ }
342
+ if (selected.length > 1) {
343
+ throw new index_js_2.AmbiguousRequirementSignaturesError("permit", selected.length);
344
+ }
345
+ const selectedSignature = selected[0];
346
+ if (selectedSignature == null)
347
+ return undefined;
348
+ validatePreparedBundlesRequirementSignature(selectedSignature, expectedRequirement);
349
+ return selectedSignature;
350
+ };
351
+ exports.selectBundlesTokenRequirementSignature = selectBundlesTokenRequirementSignature;
352
+ const validatePreparedBundlesRequirementSignature = (signature, expectedRequirement) => {
353
+ if (expectedRequirement == null) {
354
+ throw new index_js_2.BundlesPermitMismatchError({
355
+ field: "nonce",
356
+ expected: "the nonce from getRequirements()",
357
+ actual: String(signature.args.nonce),
358
+ });
359
+ }
360
+ if (signature.action.type !== expectedRequirement.type) {
361
+ throw new index_js_2.BundlesPermitMismatchError({
362
+ field: "type",
363
+ expected: expectedRequirement.type,
364
+ actual: signature.action.type,
365
+ });
366
+ }
367
+ const expectedArgs = expectedRequirement.args;
368
+ if (!(0, viem_1.isAddressEqual)(signature.action.args.spender, expectedArgs.spender)) {
369
+ throw new index_js_2.BundlesPermitMismatchError({
370
+ field: "spender",
371
+ expected: expectedArgs.spender,
372
+ actual: signature.action.args.spender,
373
+ });
374
+ }
375
+ if (signature.args.amount !== expectedArgs.amount ||
376
+ signature.action.args.amount !== expectedArgs.amount) {
377
+ throw new index_js_2.BundlesPermitMismatchError({
378
+ field: "amount",
379
+ expected: String(expectedArgs.amount),
380
+ actual: String(signature.args.amount),
381
+ });
382
+ }
383
+ if (signature.args.deadline !== expectedArgs.deadline ||
384
+ signature.action.args.deadline !== expectedArgs.deadline) {
385
+ throw new index_js_2.BundlesPermitMismatchError({
386
+ field: "deadline",
387
+ expected: String(expectedArgs.deadline),
388
+ actual: String(signature.args.deadline),
389
+ });
390
+ }
391
+ if (expectedArgs.nonce == null ||
392
+ signature.args.nonce !== expectedArgs.nonce ||
393
+ signature.action.args.nonce !== expectedArgs.nonce) {
394
+ throw new index_js_2.BundlesPermitMismatchError({
395
+ field: "nonce",
396
+ expected: expectedArgs.nonce == null
397
+ ? "the nonce from getRequirements()"
398
+ : String(expectedArgs.nonce),
399
+ actual: String(signature.args.nonce),
400
+ });
401
+ }
402
+ };
403
+ /**
404
+ * Selects the exact ERC-2612 vault-share permit produced for one prepared exit.
405
+ *
406
+ * @internal
407
+ *
408
+ * @param signatures - Signatures passed to the prepared operation's `buildTx` function.
409
+ * @param prepared - Exact share cap and permit requirement captured by this prepared operation.
410
+ * @returns The matching ERC-2612 signature, or `undefined` when no signature is supplied.
411
+ * @throws {BundlesPermitMismatchError} when the signature is not ERC-2612, was built for another
412
+ * share cap, or is supplied before this operation resolves its share cap.
413
+ */
414
+ const selectBundlesSharesRequirementSignature = (signatures, prepared) => {
415
+ const { permit } = (0, index_js_2.selectRequirementSignatures)(signatures, { permit: true });
416
+ if (permit == null)
417
+ return undefined;
418
+ const { action } = permit;
419
+ if (action.type !== "permit") {
420
+ throw new index_js_2.BundlesPermitMismatchError({
421
+ field: "type",
422
+ expected: "permit",
423
+ actual: action.type,
424
+ });
425
+ }
426
+ if (prepared.requiredShareAllowance == null ||
427
+ permit.args.amount !== prepared.requiredShareAllowance ||
428
+ action.args.amount !== prepared.requiredShareAllowance) {
429
+ throw new index_js_2.BundlesPermitMismatchError({
430
+ field: "amount",
431
+ expected: prepared.requiredShareAllowance == null
432
+ ? "the current cap from getRequirements()"
433
+ : String(prepared.requiredShareAllowance),
434
+ actual: String(permit.args.amount),
435
+ });
436
+ }
437
+ const selectedPermit = { args: permit.args, action };
438
+ validatePreparedBundlesRequirementSignature(selectedPermit, prepared.expectedRequirement);
439
+ return selectedPermit;
440
+ };
441
+ exports.selectBundlesSharesRequirementSignature = selectBundlesSharesRequirementSignature;
442
+ /**
443
+ * Selects the ERC-2612 vault-share permit for one exit from its immutable operation fields alone.
444
+ *
445
+ * @internal
446
+ *
447
+ * @param signatures - Signatures passed to the operation's `buildTx` function.
448
+ * @param expected - Immutable spender, amount, and deadline required by the operation.
449
+ * @returns The matching ERC-2612 signature, or `undefined` when no signature is supplied.
450
+ * @throws {BundlesPermitMismatchError} when the signature is not ERC-2612 or its spender, amount or
451
+ * deadline differ from the operation's. The nonce is not checked here: it is onchain state the
452
+ * vault's `permit` verifies at execution.
453
+ */
454
+ const selectBundlesSharesPermitSignature = (signatures, expected) => {
455
+ const { permit } = (0, index_js_2.selectRequirementSignatures)(signatures, { permit: true });
456
+ if (permit == null)
457
+ return undefined;
458
+ const { action } = permit;
459
+ if (action.type !== "permit") {
460
+ throw new index_js_2.BundlesPermitMismatchError({
461
+ field: "type",
462
+ expected: "permit",
463
+ actual: action.type,
464
+ });
465
+ }
466
+ if (!(0, viem_1.isAddressEqual)(action.args.spender, expected.spender)) {
467
+ throw new index_js_2.BundlesPermitMismatchError({
468
+ field: "spender",
469
+ expected: expected.spender,
470
+ actual: action.args.spender,
471
+ });
472
+ }
473
+ if (permit.args.amount !== expected.amount ||
474
+ action.args.amount !== expected.amount) {
475
+ throw new index_js_2.BundlesPermitMismatchError({
476
+ field: "amount",
477
+ expected: String(expected.amount),
478
+ actual: String(permit.args.amount),
479
+ });
480
+ }
481
+ if (permit.args.deadline !== expected.deadline ||
482
+ action.args.deadline !== expected.deadline) {
483
+ throw new index_js_2.BundlesPermitMismatchError({
484
+ field: "deadline",
485
+ expected: String(expected.deadline),
486
+ actual: String(permit.args.deadline),
487
+ });
488
+ }
489
+ return { args: permit.args, action };
490
+ };
491
+ exports.selectBundlesSharesPermitSignature = selectBundlesSharesPermitSignature;
492
+ /** @internal Returns the exact referral fee deducted from a fixed gross asset amount. */
493
+ const getBundlesReferralFeeAssets = (assets, referralFeePct) => blue_sdk_1.MathLib.mulDivDown(assets, referralFeePct, blue_sdk_1.MathLib.WAD);
494
+ exports.getBundlesReferralFeeAssets = getBundlesReferralFeeAssets;
495
+ /** @internal Finalizes a direct VaultBundlesV1 transaction with metadata and immutable action data. */
496
+ const finalizeVaultBundlesV1Transaction = (params) => {
497
+ let transaction = {
498
+ to: (0, morpho_ts_1.getChainAddress)(params.chainId, "bundles.vaultBundlesV1"),
499
+ value: params.value,
500
+ data: params.data,
501
+ };
502
+ if (params.metadata != null) {
503
+ transaction = (0, index_js_1.addTransactionMetadata)(transaction, params.metadata);
504
+ }
505
+ return (0, morpho_ts_1.deepFreeze)({ ...transaction, action: params.action });
506
+ };
507
+ exports.finalizeVaultBundlesV1Transaction = finalizeVaultBundlesV1Transaction;
@@ -0,0 +1,3 @@
1
+ export type { BundleSharesPermit, BundlesCommonParams, BundlesSharesPermit, BundlesTokenPermit, NormalizedBundlesCommonParams, } from "./common.js";
2
+ export { BundlesPermitKind, getBundlesSharesPermit, getBundlesTokenPermit, resolveBundlesFunding, } from "./common.js";
3
+ export * from "./resolveBundlesTokenRequirements.js";
@@ -0,0 +1,23 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ exports.resolveBundlesFunding = exports.getBundlesTokenPermit = exports.getBundlesSharesPermit = exports.BundlesPermitKind = void 0;
18
+ var common_js_1 = require("./common.js");
19
+ Object.defineProperty(exports, "BundlesPermitKind", { enumerable: true, get: function () { return common_js_1.BundlesPermitKind; } });
20
+ Object.defineProperty(exports, "getBundlesSharesPermit", { enumerable: true, get: function () { return common_js_1.getBundlesSharesPermit; } });
21
+ Object.defineProperty(exports, "getBundlesTokenPermit", { enumerable: true, get: function () { return common_js_1.getBundlesTokenPermit; } });
22
+ Object.defineProperty(exports, "resolveBundlesFunding", { enumerable: true, get: function () { return common_js_1.resolveBundlesFunding; } });
23
+ __exportStar(require("./resolveBundlesTokenRequirements.js"), exports);
@@ -0,0 +1,76 @@
1
+ import type { Address } from "viem";
2
+ import { type BundlesTokenSignatureRequirement, type ERC20ApprovalAction, type Transaction } from "../../types/index.js";
3
+ /** Plain onchain state used by {@link resolveBundlesTokenRequirements}. */
4
+ export type BundlesTokenRequirementsState = {
5
+ readonly type: "approval";
6
+ /** Current allowance of the funding token for `spender`. */
7
+ readonly allowance: bigint;
8
+ /** Allowance to set when the current allowance cannot cover `amount`. */
9
+ readonly approvalAmount: bigint;
10
+ } | {
11
+ readonly type: "permit2SignatureTransfer";
12
+ readonly permit2Allowance: bigint;
13
+ readonly permit2Nonce: bigint;
14
+ readonly nonceBitmap: bigint;
15
+ };
16
+ /**
17
+ * Resolves pre-fetched allowance and Permit2 nonce state into ordered bundles requirements.
18
+ *
19
+ * `spender` is validated against the chain registry's fixed bundles deployments, and the
20
+ * SignatureTransfer branch resolves canonical Permit2 from that same registry, so no caller can
21
+ * route an approval or a signed pull to an address the SDK does not know.
22
+ *
23
+ * The SignatureTransfer branch always places any ERC-20 approval to canonical Permit2 before the
24
+ * one-time signature requirement.
25
+ *
26
+ * @param params - Funding values, expected bundles spender, and pre-fetched state.
27
+ * @param params.token - ERC-20 token funded by the operation.
28
+ * @param params.spender - Registered fixed bundles contract that pulls the token; must be the
29
+ * chain's BlueBundlesV1 or VaultBundlesV1 deployment.
30
+ * @param params.owner - Account funding the operation and owning the Permit2 nonce bitmap.
31
+ * @param params.chainId - Target chain id used to resolve supported approval spenders and canonical Permit2.
32
+ * @param params.amount - Exact pull amount in the token's smallest unit; zero returns no requirements.
33
+ * @param params.deadline - Signature expiration as a Unix timestamp in seconds.
34
+ * @param params.state - Prefetched state for either classic approval or Permit2 SignatureTransfer.
35
+ * @param params.state.type - `approval` for a direct allowance or `permit2SignatureTransfer` for a signed pull.
36
+ * @param params.state.allowance - In the approval branch, current token allowance from `owner` to `spender`.
37
+ * @param params.state.approvalAmount - In the approval branch, allowance to set if needed; must cover `amount`.
38
+ * @param params.state.permit2Allowance - In the SignatureTransfer branch, current token allowance from `owner` to canonical Permit2.
39
+ * @param params.state.permit2Nonce - In the SignatureTransfer branch, caller-selected unused uint256 unordered nonce.
40
+ * @param params.state.nonceBitmap - In the SignatureTransfer branch, owner's Permit2 bitmap word at `permit2Nonce >> 8n`.
41
+ * @returns Ordered approval transactions and/or a Permit2 SignatureTransfer requirement.
42
+ * @throws {UnsupportedChainIdError} when `chainId` is absent from the address registry.
43
+ * @throws {UnsupportedErc20ApprovalSpenderError} when `spender` is not the chain's registered
44
+ * BlueBundlesV1 or VaultBundlesV1 deployment, including for a zero-amount request.
45
+ * @throws {NegativeInputError} when an amount or Permit2 nonce is negative.
46
+ * @throws {InputExceedsMaxError} when `amount` or the Permit2 nonce exceeds uint256.
47
+ * @throws {Permit2SignatureTransferNonceAlreadyUsedError} when the selected nonce bit is set.
48
+ * @throws {ApprovalAmountLessThanSpendAmountError} when a classic approval cannot cover the pull.
49
+ * @throws {UnknownAddressError} when the SignatureTransfer branch runs on a chain without canonical Permit2.
50
+ * @example
51
+ * ```ts
52
+ * import { resolveBundlesTokenRequirements } from "@morpho-org/morpho-sdk";
53
+ * import { getChainAddress } from "@morpho-org/morpho-ts";
54
+ * import { zeroAddress } from "viem";
55
+ *
56
+ * const requirements = resolveBundlesTokenRequirements({
57
+ * token: zeroAddress,
58
+ * spender: getChainAddress(1, "bundles.vaultBundlesV1"),
59
+ * owner: zeroAddress,
60
+ * chainId: 1,
61
+ * amount: 1_000_000n,
62
+ * deadline: 1_900_000_000n,
63
+ * state: { type: "approval", allowance: 1_000_000n, approvalAmount: 1_000_000n },
64
+ * });
65
+ * // requirements is empty because the allowance already covers the amount.
66
+ * ```
67
+ */
68
+ export declare const resolveBundlesTokenRequirements: (params: {
69
+ readonly token: Address;
70
+ readonly spender: Address;
71
+ readonly owner: Address;
72
+ readonly chainId: number;
73
+ readonly amount: bigint;
74
+ readonly deadline: bigint;
75
+ readonly state: BundlesTokenRequirementsState;
76
+ }) => readonly (Readonly<Transaction<ERC20ApprovalAction>> | BundlesTokenSignatureRequirement)[];