@morpho-org/morpho-sdk 5.9.0 → 6.0.0-next.1

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 (243) hide show
  1. package/MIGRATION-v5-to-v6.md +404 -0
  2. package/README.md +127 -69
  3. package/lib/cjs/abis.d.ts +210 -0
  4. package/lib/cjs/abis.js +142 -2
  5. package/lib/cjs/actions/blue/borrow.d.ts +62 -61
  6. package/lib/cjs/actions/blue/borrow.js +48 -80
  7. package/lib/cjs/actions/blue/common.d.ts +86 -0
  8. package/lib/cjs/actions/blue/common.js +205 -0
  9. package/lib/cjs/actions/blue/refinance.d.ts +72 -112
  10. package/lib/cjs/actions/blue/refinance.js +97 -199
  11. package/lib/cjs/actions/blue/repay.d.ts +72 -68
  12. package/lib/cjs/actions/blue/repay.js +56 -118
  13. package/lib/cjs/actions/blue/repayWithdrawCollateral.d.ts +85 -90
  14. package/lib/cjs/actions/blue/repayWithdrawCollateral.js +148 -137
  15. package/lib/cjs/actions/blue/supply.d.ts +62 -45
  16. package/lib/cjs/actions/blue/supply.js +94 -70
  17. package/lib/cjs/actions/blue/supplyCollateral.d.ts +63 -40
  18. package/lib/cjs/actions/blue/supplyCollateral.js +52 -69
  19. package/lib/cjs/actions/blue/supplyCollateralBorrow.d.ts +82 -90
  20. package/lib/cjs/actions/blue/supplyCollateralBorrow.js +133 -120
  21. package/lib/cjs/actions/blue/withdraw.d.ts +68 -79
  22. package/lib/cjs/actions/blue/withdraw.js +101 -97
  23. package/lib/cjs/actions/blue/withdrawCollateral.d.ts +56 -28
  24. package/lib/cjs/actions/blue/withdrawCollateral.js +45 -50
  25. package/lib/cjs/actions/bundles/common.d.ts +200 -0
  26. package/lib/cjs/actions/bundles/common.js +469 -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 +2 -1
  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 +29 -17
  40. package/lib/cjs/actions/requirements/blue/getBlueAuthorizationRequirement.js +60 -19
  41. package/lib/cjs/actions/requirements/blue/getUnusedPermit2Nonce.d.ts +48 -0
  42. package/lib/cjs/actions/requirements/blue/getUnusedPermit2Nonce.js +72 -0
  43. package/lib/cjs/actions/requirements/blue/index.d.ts +1 -0
  44. package/lib/cjs/actions/requirements/blue/index.js +1 -0
  45. package/lib/cjs/actions/requirements/encode/encodeBlueSignatureAuthorization.d.ts +10 -7
  46. package/lib/cjs/actions/requirements/encode/encodeBlueSignatureAuthorization.js +30 -5
  47. package/lib/cjs/actions/requirements/encode/encodeErc20Approval.d.ts +2 -1
  48. package/lib/cjs/actions/requirements/encode/encodeErc20Approval.js +8 -2
  49. package/lib/cjs/actions/requirements/encode/encodeErc20Permit.d.ts +16 -7
  50. package/lib/cjs/actions/requirements/encode/encodeErc20Permit.js +39 -6
  51. package/lib/cjs/actions/requirements/encode/encodeErc20Permit2SignatureTransfer.d.ts +61 -0
  52. package/lib/cjs/actions/requirements/encode/encodeErc20Permit2SignatureTransfer.js +123 -0
  53. package/lib/cjs/actions/requirements/encode/encodeVaultSharesPermit.d.ts +4 -4
  54. package/lib/cjs/actions/requirements/encode/encodeVaultSharesPermit.js +6 -5
  55. package/lib/cjs/actions/requirements/encode/index.d.ts +1 -0
  56. package/lib/cjs/actions/requirements/encode/index.js +1 -0
  57. package/lib/cjs/actions/requirements/generalAdapter/getGeneralAdapterRequirementsPermit.d.ts +1 -1
  58. package/lib/cjs/actions/requirements/getRequirementsApproval.d.ts +6 -4
  59. package/lib/cjs/actions/requirements/getRequirementsApproval.js +6 -4
  60. package/lib/cjs/actions/signatures/getTokenRequirementActions.d.ts +1 -0
  61. package/lib/cjs/actions/signatures/getTokenRequirementActions.js +4 -0
  62. package/lib/cjs/actions/signatures/getVaultExitBundlesV1PermitStruct.d.ts +22 -30
  63. package/lib/cjs/actions/signatures/getVaultExitBundlesV1PermitStruct.js +18 -66
  64. package/lib/cjs/actions/vaultV1/deposit.d.ts +73 -57
  65. package/lib/cjs/actions/vaultV1/deposit.js +110 -109
  66. package/lib/cjs/actions/vaultV1/migrateToV2.d.ts +43 -66
  67. package/lib/cjs/actions/vaultV1/migrateToV2.js +91 -104
  68. package/lib/cjs/actions/vaultV1/redeem.d.ts +30 -23
  69. package/lib/cjs/actions/vaultV1/redeem.js +56 -33
  70. package/lib/cjs/actions/vaultV1/withdraw.d.ts +58 -24
  71. package/lib/cjs/actions/vaultV1/withdraw.js +86 -34
  72. package/lib/cjs/actions/vaultV2/deposit.d.ts +74 -57
  73. package/lib/cjs/actions/vaultV2/deposit.js +111 -109
  74. package/lib/cjs/actions/vaultV2/redeem.d.ts +30 -24
  75. package/lib/cjs/actions/vaultV2/redeem.js +56 -34
  76. package/lib/cjs/actions/vaultV2/withdraw.d.ts +58 -25
  77. package/lib/cjs/actions/vaultV2/withdraw.js +86 -35
  78. package/lib/cjs/bundler/actions.d.ts +4 -4
  79. package/lib/cjs/bundler/actions.js +4 -4
  80. package/lib/cjs/client/morphoViemExtension.d.ts +2 -1
  81. package/lib/cjs/client/morphoViemExtension.js +2 -1
  82. package/lib/cjs/entities/blue/blue.d.ts +806 -374
  83. package/lib/cjs/entities/blue/blue.js +449 -696
  84. package/lib/cjs/entities/index.d.ts +2 -0
  85. package/lib/cjs/entities/index.js +15 -0
  86. package/lib/cjs/entities/midnight/midnight.d.ts +2 -2
  87. package/lib/cjs/entities/requirements/getBundlesTokenRequirements.d.ts +87 -0
  88. package/lib/cjs/entities/requirements/getBundlesTokenRequirements.js +203 -0
  89. package/lib/cjs/entities/requirements/getVaultBundlesSharesRequirements.d.ts +28 -0
  90. package/lib/cjs/entities/requirements/getVaultBundlesSharesRequirements.js +74 -0
  91. package/lib/cjs/entities/requirements/index.d.ts +1 -0
  92. package/lib/cjs/entities/requirements/index.js +17 -0
  93. package/lib/cjs/entities/vaultV1/vaultV1.d.ts +348 -98
  94. package/lib/cjs/entities/vaultV1/vaultV1.js +322 -120
  95. package/lib/cjs/entities/vaultV2/vaultV2.d.ts +221 -68
  96. package/lib/cjs/entities/vaultV2/vaultV2.js +219 -77
  97. package/lib/cjs/helpers/computeVaultV1Reallocations.d.ts +3 -9
  98. package/lib/cjs/helpers/computeVaultV1Reallocations.js +3 -9
  99. package/lib/cjs/helpers/index.d.ts +2 -1
  100. package/lib/cjs/helpers/index.js +5 -1
  101. package/lib/cjs/helpers/referralFee.d.ts +21 -0
  102. package/lib/cjs/helpers/referralFee.js +35 -0
  103. package/lib/cjs/helpers/slippage.d.ts +90 -1
  104. package/lib/cjs/helpers/slippage.js +123 -0
  105. package/lib/cjs/helpers/validate.d.ts +16 -23
  106. package/lib/cjs/helpers/validate.js +41 -48
  107. package/lib/cjs/helpers/validateRequirementSpender.d.ts +2 -1
  108. package/lib/cjs/helpers/validateRequirementSpender.js +3 -0
  109. package/lib/cjs/index.d.ts +1 -0
  110. package/lib/cjs/index.js +1 -0
  111. package/lib/cjs/types/action.d.ts +303 -210
  112. package/lib/cjs/types/action.js +29 -2
  113. package/lib/cjs/types/client.d.ts +9 -0
  114. package/lib/cjs/types/error.d.ts +193 -18
  115. package/lib/cjs/types/error.js +267 -24
  116. package/lib/cjs/types/sharedLiquidity.d.ts +0 -7
  117. package/lib/esm/abis.d.ts +210 -0
  118. package/lib/esm/abis.js +140 -0
  119. package/lib/esm/actions/blue/borrow.d.ts +62 -61
  120. package/lib/esm/actions/blue/borrow.js +48 -80
  121. package/lib/esm/actions/blue/common.d.ts +86 -0
  122. package/lib/esm/actions/blue/common.js +193 -0
  123. package/lib/esm/actions/blue/refinance.d.ts +72 -112
  124. package/lib/esm/actions/blue/refinance.js +98 -200
  125. package/lib/esm/actions/blue/repay.d.ts +72 -68
  126. package/lib/esm/actions/blue/repay.js +56 -118
  127. package/lib/esm/actions/blue/repayWithdrawCollateral.d.ts +85 -90
  128. package/lib/esm/actions/blue/repayWithdrawCollateral.js +149 -138
  129. package/lib/esm/actions/blue/supply.d.ts +62 -45
  130. package/lib/esm/actions/blue/supply.js +94 -70
  131. package/lib/esm/actions/blue/supplyCollateral.d.ts +63 -40
  132. package/lib/esm/actions/blue/supplyCollateral.js +52 -69
  133. package/lib/esm/actions/blue/supplyCollateralBorrow.d.ts +82 -90
  134. package/lib/esm/actions/blue/supplyCollateralBorrow.js +134 -121
  135. package/lib/esm/actions/blue/withdraw.d.ts +68 -79
  136. package/lib/esm/actions/blue/withdraw.js +100 -96
  137. package/lib/esm/actions/blue/withdrawCollateral.d.ts +56 -28
  138. package/lib/esm/actions/blue/withdrawCollateral.js +45 -50
  139. package/lib/esm/actions/bundles/common.d.ts +200 -0
  140. package/lib/esm/actions/bundles/common.js +457 -0
  141. package/lib/esm/actions/bundles/index.d.ts +3 -0
  142. package/lib/esm/actions/bundles/index.js +2 -0
  143. package/lib/esm/actions/bundles/resolveBundlesTokenRequirements.d.ts +76 -0
  144. package/lib/esm/actions/bundles/resolveBundlesTokenRequirements.js +121 -0
  145. package/lib/esm/actions/index.d.ts +2 -1
  146. package/lib/esm/actions/index.js +1 -0
  147. package/lib/esm/actions/midnight/supplyCollateralTakeBorrow.d.ts +2 -2
  148. package/lib/esm/actions/midnight/supplyCollateralTakeBorrow.js +2 -2
  149. package/lib/esm/actions/midnight/takeBorrow.d.ts +2 -2
  150. package/lib/esm/actions/midnight/takeBorrow.js +2 -2
  151. package/lib/esm/actions/midnight/takeLend.d.ts +2 -2
  152. package/lib/esm/actions/midnight/takeLend.js +2 -2
  153. package/lib/esm/actions/requirements/blue/getBlueAuthorizationRequirement.d.ts +29 -17
  154. package/lib/esm/actions/requirements/blue/getBlueAuthorizationRequirement.js +63 -22
  155. package/lib/esm/actions/requirements/blue/getUnusedPermit2Nonce.d.ts +48 -0
  156. package/lib/esm/actions/requirements/blue/getUnusedPermit2Nonce.js +68 -0
  157. package/lib/esm/actions/requirements/blue/index.d.ts +1 -0
  158. package/lib/esm/actions/requirements/blue/index.js +1 -0
  159. package/lib/esm/actions/requirements/encode/encodeBlueSignatureAuthorization.d.ts +10 -7
  160. package/lib/esm/actions/requirements/encode/encodeBlueSignatureAuthorization.js +31 -6
  161. package/lib/esm/actions/requirements/encode/encodeErc20Approval.d.ts +2 -1
  162. package/lib/esm/actions/requirements/encode/encodeErc20Approval.js +9 -3
  163. package/lib/esm/actions/requirements/encode/encodeErc20Permit.d.ts +16 -7
  164. package/lib/esm/actions/requirements/encode/encodeErc20Permit.js +40 -7
  165. package/lib/esm/actions/requirements/encode/encodeErc20Permit2SignatureTransfer.d.ts +61 -0
  166. package/lib/esm/actions/requirements/encode/encodeErc20Permit2SignatureTransfer.js +119 -0
  167. package/lib/esm/actions/requirements/encode/encodeVaultSharesPermit.d.ts +4 -4
  168. package/lib/esm/actions/requirements/encode/encodeVaultSharesPermit.js +6 -5
  169. package/lib/esm/actions/requirements/encode/index.d.ts +1 -0
  170. package/lib/esm/actions/requirements/encode/index.js +1 -0
  171. package/lib/esm/actions/requirements/generalAdapter/getGeneralAdapterRequirementsPermit.d.ts +1 -1
  172. package/lib/esm/actions/requirements/getRequirementsApproval.d.ts +6 -4
  173. package/lib/esm/actions/requirements/getRequirementsApproval.js +6 -4
  174. package/lib/esm/actions/signatures/getTokenRequirementActions.d.ts +1 -0
  175. package/lib/esm/actions/signatures/getTokenRequirementActions.js +5 -1
  176. package/lib/esm/actions/signatures/getVaultExitBundlesV1PermitStruct.d.ts +22 -30
  177. package/lib/esm/actions/signatures/getVaultExitBundlesV1PermitStruct.js +19 -67
  178. package/lib/esm/actions/vaultV1/deposit.d.ts +73 -57
  179. package/lib/esm/actions/vaultV1/deposit.js +112 -111
  180. package/lib/esm/actions/vaultV1/migrateToV2.d.ts +43 -66
  181. package/lib/esm/actions/vaultV1/migrateToV2.js +93 -106
  182. package/lib/esm/actions/vaultV1/redeem.d.ts +30 -23
  183. package/lib/esm/actions/vaultV1/redeem.js +56 -33
  184. package/lib/esm/actions/vaultV1/withdraw.d.ts +58 -24
  185. package/lib/esm/actions/vaultV1/withdraw.js +86 -34
  186. package/lib/esm/actions/vaultV2/deposit.d.ts +74 -57
  187. package/lib/esm/actions/vaultV2/deposit.js +113 -111
  188. package/lib/esm/actions/vaultV2/redeem.d.ts +30 -24
  189. package/lib/esm/actions/vaultV2/redeem.js +56 -34
  190. package/lib/esm/actions/vaultV2/withdraw.d.ts +58 -25
  191. package/lib/esm/actions/vaultV2/withdraw.js +86 -35
  192. package/lib/esm/bundler/actions.d.ts +4 -4
  193. package/lib/esm/bundler/actions.js +4 -4
  194. package/lib/esm/client/morphoViemExtension.d.ts +2 -1
  195. package/lib/esm/client/morphoViemExtension.js +2 -1
  196. package/lib/esm/entities/blue/blue.d.ts +806 -374
  197. package/lib/esm/entities/blue/blue.js +455 -702
  198. package/lib/esm/entities/index.d.ts +2 -0
  199. package/lib/esm/entities/index.js +1 -0
  200. package/lib/esm/entities/midnight/midnight.d.ts +2 -2
  201. package/lib/esm/entities/requirements/getBundlesTokenRequirements.d.ts +87 -0
  202. package/lib/esm/entities/requirements/getBundlesTokenRequirements.js +199 -0
  203. package/lib/esm/entities/requirements/getVaultBundlesSharesRequirements.d.ts +28 -0
  204. package/lib/esm/entities/requirements/getVaultBundlesSharesRequirements.js +70 -0
  205. package/lib/esm/entities/requirements/index.d.ts +1 -0
  206. package/lib/esm/entities/requirements/index.js +1 -0
  207. package/lib/esm/entities/vaultV1/vaultV1.d.ts +348 -98
  208. package/lib/esm/entities/vaultV1/vaultV1.js +326 -124
  209. package/lib/esm/entities/vaultV2/vaultV2.d.ts +221 -68
  210. package/lib/esm/entities/vaultV2/vaultV2.js +222 -80
  211. package/lib/esm/helpers/computeVaultV1Reallocations.d.ts +3 -9
  212. package/lib/esm/helpers/computeVaultV1Reallocations.js +3 -9
  213. package/lib/esm/helpers/index.d.ts +2 -1
  214. package/lib/esm/helpers/index.js +2 -1
  215. package/lib/esm/helpers/referralFee.d.ts +21 -0
  216. package/lib/esm/helpers/referralFee.js +31 -0
  217. package/lib/esm/helpers/slippage.d.ts +90 -1
  218. package/lib/esm/helpers/slippage.js +122 -2
  219. package/lib/esm/helpers/validate.d.ts +16 -23
  220. package/lib/esm/helpers/validate.js +40 -48
  221. package/lib/esm/helpers/validateRequirementSpender.d.ts +2 -1
  222. package/lib/esm/helpers/validateRequirementSpender.js +3 -0
  223. package/lib/esm/index.d.ts +1 -0
  224. package/lib/esm/index.js +1 -0
  225. package/lib/esm/types/action.d.ts +303 -210
  226. package/lib/esm/types/action.js +28 -2
  227. package/lib/esm/types/client.d.ts +9 -0
  228. package/lib/esm/types/error.d.ts +193 -18
  229. package/lib/esm/types/error.js +252 -21
  230. package/lib/esm/types/sharedLiquidity.d.ts +0 -7
  231. package/package.json +6 -5
  232. package/lib/cjs/actions/blue/buildAssetFundingActions.d.ts +0 -47
  233. package/lib/cjs/actions/blue/buildAssetFundingActions.js +0 -63
  234. package/lib/cjs/actions/blue/buildReallocationActions.d.ts +0 -69
  235. package/lib/cjs/actions/blue/buildReallocationActions.js +0 -141
  236. package/lib/cjs/actions/blue/resolveRepayFunding.d.ts +0 -66
  237. package/lib/cjs/actions/blue/resolveRepayFunding.js +0 -85
  238. package/lib/esm/actions/blue/buildAssetFundingActions.d.ts +0 -47
  239. package/lib/esm/actions/blue/buildAssetFundingActions.js +0 -59
  240. package/lib/esm/actions/blue/buildReallocationActions.d.ts +0 -69
  241. package/lib/esm/actions/blue/buildReallocationActions.js +0 -135
  242. package/lib/esm/actions/blue/resolveRepayFunding.d.ts +0 -66
  243. package/lib/esm/actions/blue/resolveRepayFunding.js +0 -81
@@ -1,7 +1,7 @@
1
- import { AccrualPosition, type Market, type MarketParams } from "@morpho-org/blue-sdk";
1
+ import { type AccrualPosition, type Market, type MarketParams } from "@morpho-org/blue-sdk";
2
2
  import { type Address } from "viem";
3
3
  import type { FetchParameters } from "../../types/data.js";
4
- import { type AssetsOrSharesArgs, type BlueAuthorizationAction, type BlueBorrowAction, type BlueReallocationPlan, type BlueRefinanceAction, type BlueRepayAction, type BlueRepayWithdrawCollateralAction, type BlueSupplyAction, type BlueSupplyCollateralAction, type BlueSupplyCollateralBorrowAction, type BlueWithdrawAction, type BlueWithdrawCollateralAction, type DepositAmountArgs, type ERC20ApprovalAction, type MorphoClientType, type PermitRequirementSignature, type ReallocationComputeOptions, type RepayAmountArgs, type Requirement, type RequirementSignature, type Transaction, type VaultV1Reallocation, type VaultV2BluePublicAllocatorOptions, type VaultV2BlueReallocation } from "../../types/index.js";
4
+ import { type ActionOutput, type ActionRequirement, type AssetsOrSharesArgs, type BlueBorrowAction, type BlueRefinanceAction, type BlueRepayAction, type BlueRepayWithdrawCollateralAction, type BlueSupplyAction, type BlueSupplyCollateralAction, type BlueSupplyCollateralBorrowAction, type BlueWithdrawAction, type BlueWithdrawCollateralAction, type MorphoClientType, type ReallocationComputeOptions, type RequirementSignature, type VaultV1Reallocation, type VaultV2BluePublicAllocatorOptions, type VaultV2BlueReallocation } from "../../types/index.js";
5
5
  import { VaultV1ReallocationData } from "../vaultV1ReallocationData.js";
6
6
  import { VaultV2BlueReallocationData } from "../vaultV2BlueReallocationData.js";
7
7
  type VaultV1ReallocationsParams = {
@@ -26,6 +26,18 @@ type VaultV2BlueReallocationsParams = {
26
26
  };
27
27
  };
28
28
  };
29
+ /** Options for resolving token-backed BlueBundlesV1 approval or signature prerequisites. */
30
+ export interface BlueTokenRequirementsParams {
31
+ /** Prefer ERC-2612 when the funded token exposes a compatible nonce. */
32
+ readonly useSimplePermit?: boolean;
33
+ /** Explicit unused Permit2 SignatureTransfer unordered nonce. */
34
+ readonly permit2Nonce?: bigint;
35
+ /**
36
+ * Classic ERC-20 allowance to set when an approval is needed, enabling a reusable approval (for
37
+ * example `maxUint256`). Defaults to the exact pulled amount. Ignored by signature paths.
38
+ */
39
+ readonly approvalAmount?: bigint;
40
+ }
29
41
  export interface BlueActions {
30
42
  /**
31
43
  * Fetches the latest market data with accrued interest.
@@ -43,325 +55,715 @@ export interface BlueActions {
43
55
  */
44
56
  getPositionData: (userAddress: Address, parameters?: FetchParameters) => Promise<AccrualPosition>;
45
57
  /**
46
- * Prepares a supply-collateral transaction.
58
+ * Prepares a direct BlueBundlesV1 collateral supply.
47
59
  *
48
- * Routed through bundler via GeneralAdapter1.
49
- * `getRequirements` returns ERC20 approval or permit for GeneralAdapter1.
50
- * When `nativeAmount` is provided, native token is wrapped; collateral must be wNative.
60
+ * This is the single-operation form of {@link BlueActions.supplyCollateralBorrow}; it supplies
61
+ * `collateralAssets` and fixes the inactive borrow leg to zero. Token requirements target
62
+ * BlueBundlesV1 unless the collateral is funded exclusively with the chain's native asset.
63
+ *
64
+ * @param params.userAddress - User funding and receiving the collateral position.
65
+ * @param params.collateralAssets - Gross collateral assets supplied.
66
+ * @param params.nativeAmount - Optional full native funding equal to `collateralAssets`.
67
+ * @param params.deadline - Final call deadline in Unix seconds.
68
+ * @param params.referralFeePct - Optional WAD-scaled referral fee below 100%.
69
+ * @param params.referralFeeRecipient - Recipient required for a positive fee.
70
+ * @returns Lazy token prerequisite resolution and a synchronous deep-frozen transaction.
71
+ * @throws {ChainIdMismatchError} when the client targets another chain.
72
+ * @throws {ExpiredDeadlineError} when the deadline is stale.
73
+ * @throws {NonPositiveInputError} when `collateralAssets` is not positive.
74
+ * @throws {NegativeInputError} when collateral, native funding, or the referral fee is negative.
75
+ * @throws {NativeFundingAmountMismatchError} when native funding is partial or mixed.
76
+ * @throws {ChainWNativeMissingError} when native funding is requested without registered wNative.
77
+ * @throws {NativeAmountOnNonWNativeAssetError} when native funding targets another token.
78
+ * @throws {InputExceedsMaxError} when the referral fee is at least WAD.
79
+ * @throws {MissingReferralFeeRecipientError} when a positive fee has no recipient.
80
+ * @throws {MissingPermit2SignatureTransferNonceError} from `getRequirements()` when Permit2 is selected without a nonce.
81
+ * @throws {Permit2SignatureTransferNonceAlreadyUsedError} from `getRequirements()` when the explicit Permit2 nonce is consumed.
82
+ * @throws {AmbiguousRequirementSignaturesError} from `buildTx()` when multiple token signatures are supplied.
83
+ * @throws {UnexpectedRequirementSignatureError} from `buildTx()` when an unsupported signature is supplied.
84
+ * @throws {DepositOwnerMismatchError} from `buildTx()` when the signed owner differs from `userAddress`.
85
+ * @throws {DepositAssetMismatchError} from `buildTx()` when the signed asset differs from the collateral token.
86
+ * @throws {DepositAmountMismatchError} from `buildTx()` when the signed amount differs from `collateralAssets`.
87
+ * @throws {DepositSpenderMismatchError} from `buildTx()` when the signed spender is not BlueBundlesV1.
88
+ * @throws {BundlesRequirementSignatureMismatchError} from `buildTx()` when a signature cannot be encoded safely.
89
+ * @throws {UnsupportedChainIdError} when the chain is absent from the address registry.
90
+ * @throws {UnknownAddressError} when BlueBundlesV1 is not registered.
91
+ * @throws {viem.BaseError} from `getRequirements()` when an allowance, nonce, or token metadata read fails.
92
+ * @example
93
+ * ```ts
94
+ * import { markets } from "@morpho-org/morpho-test";
95
+ * import { createPublicClient, http, zeroAddress } from "viem";
96
+ * import { mainnet } from "viem/chains";
97
+ * import { morphoViemExtension } from "@morpho-org/morpho-sdk";
51
98
  *
52
- * @param params - Supply collateral parameters.
53
- * @returns Object with `buildTx` and `getRequirements`.
99
+ * const client = createPublicClient({ chain: mainnet, transport: http() })
100
+ * .extend(morphoViemExtension());
101
+ * const market = client.morpho.blue(markets[mainnet.id].usdc_wbtc, mainnet.id);
102
+ * const action = market.supplyCollateral({
103
+ * userAddress: zeroAddress,
104
+ * collateralAssets: 10n ** 18n,
105
+ * deadline: 1_900_000_000n,
106
+ * });
107
+ * const requirements = await action.getRequirements();
108
+ * const tx = action.buildTx();
109
+ * ```
54
110
  */
55
111
  supplyCollateral: (params: {
56
- userAddress: Address;
57
- } & DepositAmountArgs) => {
58
- buildTx: (signatures?: readonly RequirementSignature[]) => Readonly<Transaction<BlueSupplyCollateralAction>>;
59
- getRequirements: (params?: {
60
- /**
61
- * Prefer the ERC-2612 simple-permit path when the SDK detects support.
62
- * Leave unset or set to `false` to force the Permit2/classic approval fallback when
63
- * a token is known to be incompatible despite passing the SDK's shallow nonce probe.
64
- */
65
- useSimplePermit?: boolean;
66
- }) => Promise<(Readonly<Transaction<ERC20ApprovalAction>> | Requirement<PermitRequirementSignature>)[]>;
67
- };
112
+ readonly userAddress: Address;
113
+ readonly collateralAssets: bigint;
114
+ readonly nativeAmount?: bigint;
115
+ readonly deadline: bigint;
116
+ readonly referralFeePct?: bigint;
117
+ readonly referralFeeRecipient?: Address;
118
+ }) => ActionOutput<BlueSupplyCollateralAction, readonly RequirementSignature[], BlueTokenRequirementsParams>;
68
119
  /**
69
- * Prepares a loan-asset supply transaction.
120
+ * Prepares a direct BlueBundlesV1 loan-asset supply.
70
121
  *
71
- * Routed through bundler via GeneralAdapter1. Computes `maxSharePrice` from the supply state of
72
- * `marketData` forward-accrued to execution and `slippageTolerance` to protect against
73
- * share-price inflation.
74
- * `getRequirements` returns ERC20 approval or permit for `GeneralAdapter1` on the loan token.
75
- * When `nativeAmount` is provided, native token is wrapped; the loan token must be wNative.
122
+ * `getRequirements()` reads only the loan-token allowance and selected ERC-2612 or Permit2
123
+ * nonce state. Direct approvals and ERC-2612 name BlueBundlesV1 as spender; Permit2 keeps its
124
+ * ERC-20 approval on canonical Permit2. Native funding is exclusive and skips token requirements.
125
+ * The referral fee is deducted from the gross `assets` supplied. This route exposes no Bundler3
126
+ * share-price bound or `slippageTolerance`.
76
127
  *
77
- * No Morpho authorization required (supplier is crediting, not withdrawing).
128
+ * @param params.userAddress - User funding and receiving the supply position.
129
+ * @param params.assets - Gross loan-token assets funded before the referral fee.
130
+ * @param params.nativeAmount - Optional full native funding; must equal `assets` and requires wNative.
131
+ * @param params.deadline - Final call deadline in Unix seconds.
132
+ * @param params.referralFeePct - Optional WAD-scaled referral fee below 100%.
133
+ * @param params.referralFeeRecipient - Recipient required for a positive fee.
134
+ * @returns Lazy prerequisite resolution and a synchronous deep-frozen transaction builder.
135
+ * @throws {ChainIdMismatchError} when the client targets another chain.
136
+ * @throws {ExpiredDeadlineError} when the deadline is not in the future at creation or requirement resolution.
137
+ * @throws {NonPositiveInputError} when `assets` is not positive.
138
+ * @throws {NegativeInputError} when native funding or the referral fee is negative, or from `getRequirements()` when an explicit `permit2Nonce` is negative.
139
+ * @throws {NativeFundingAmountMismatchError} when native funding is partial or mixed.
140
+ * @throws {ChainWNativeMissingError} when native funding is requested on a chain without wNative.
141
+ * @throws {NativeAmountOnNonWNativeAssetError} when native funding targets another token.
142
+ * @throws {InputExceedsMaxError} when `assets` or `deadline` exceeds `uint256`, when the referral fee is at least WAD, or from `getRequirements()` when an explicit `permit2Nonce` exceeds `uint256`.
143
+ * @throws {MissingReferralFeeRecipientError} when a positive fee has no recipient.
144
+ * @throws {MissingPermit2SignatureTransferNonceError} from `getRequirements()` when Permit2 is selected without an explicit nonce.
145
+ * @throws {Permit2SignatureTransferNonceAlreadyUsedError} from `getRequirements()` when the explicit Permit2 nonce is consumed.
146
+ * @throws {ApprovalAmountLessThanSpendAmountError} from `getRequirements()` when a classic `approvalAmount` is below the funded `assets`.
147
+ * @throws {AmbiguousRequirementSignaturesError} from `buildTx()` when multiple token signatures are supplied.
148
+ * @throws {UnexpectedRequirementSignatureError} from `buildTx()` when the route cannot consume a supplied signature.
149
+ * @throws {DepositOwnerMismatchError} from `buildTx()` when the signed owner differs from `userAddress`.
150
+ * @throws {DepositAssetMismatchError} from `buildTx()` when the signed asset differs from the loan token.
151
+ * @throws {DepositAmountMismatchError} from `buildTx()` when the signed amount differs from `assets`.
152
+ * @throws {DepositSpenderMismatchError} from `buildTx()` when the signed spender is not BlueBundlesV1.
153
+ * @throws {BundlesRequirementSignatureMismatchError} from `buildTx()` when a signature cannot be encoded safely.
154
+ * @throws {UnsupportedChainIdError} when the chain is absent from the address registry.
155
+ * @throws {UnknownAddressError} when BlueBundlesV1 is not registered.
156
+ * @throws {viem.BaseError} from `getRequirements()` when a required allowance, nonce, or token metadata read fails.
157
+ * @example
158
+ * ```ts
159
+ * import { markets } from "@morpho-org/morpho-test";
160
+ * import { createPublicClient, http, zeroAddress } from "viem";
161
+ * import { mainnet } from "viem/chains";
162
+ * import { morphoViemExtension } from "@morpho-org/morpho-sdk";
78
163
  *
79
- * @param params - Supply parameters.
80
- * @returns Object with `buildTx` and `getRequirements`.
164
+ * const userAddress = zeroAddress;
165
+ * const client = createPublicClient({ chain: mainnet, transport: http() })
166
+ * .extend(morphoViemExtension());
167
+ * const market = client.morpho.blue(markets[mainnet.id].usdc_wbtc, mainnet.id);
168
+ * const action = market.supply({
169
+ * userAddress,
170
+ * assets: 1_000_000n,
171
+ * deadline: BigInt(Math.floor(Date.now() / 1_000) + 3_600),
172
+ * });
173
+ * const requirements = await action.getRequirements();
174
+ * const tx = action.buildTx();
175
+ * // tx satisfies Readonly<Transaction<BlueSupplyAction>>
176
+ * ```
81
177
  */
82
178
  supply: (params: {
83
- userAddress: Address;
84
- marketData: Market;
85
- slippageTolerance?: bigint;
86
- } & DepositAmountArgs) => {
87
- buildTx: (signatures?: readonly RequirementSignature[]) => Readonly<Transaction<BlueSupplyAction>>;
88
- getRequirements: (params?: {
89
- /**
90
- * Prefer the ERC-2612 simple-permit path when the SDK detects support.
91
- * Leave unset or set to `false` to force the Permit2/classic approval fallback when
92
- * a token is known to be incompatible despite passing the SDK's shallow nonce probe.
93
- */
94
- useSimplePermit?: boolean;
95
- }) => Promise<(Readonly<Transaction<ERC20ApprovalAction>> | Requirement<PermitRequirementSignature>)[]>;
96
- };
179
+ readonly userAddress: Address;
180
+ readonly assets: bigint;
181
+ readonly nativeAmount?: bigint;
182
+ readonly deadline: bigint;
183
+ readonly referralFeePct?: bigint;
184
+ readonly referralFeeRecipient?: Address;
185
+ }) => ActionOutput<BlueSupplyAction, readonly RequirementSignature[], BlueTokenRequirementsParams>;
97
186
  /**
98
- * Prepares a loan-asset withdraw transaction.
99
- *
100
- * Routed through bundler3 via `morphoWithdraw`. Supports two modes via {@link AssetsOrSharesArgs}:
101
- * - **By assets** (`{ assets }`): withdraws an exact asset amount.
102
- * - **By shares** (`{ shares }`): burns an exact share count (full close, immune to interest accrual).
103
- *
104
- * Computes `minSharePrice` from market supply state and `slippageTolerance`.
105
- *
106
- * When `reallocations` is provided, its homogeneous V1 or V2 actions are
107
- * prepended to move liquidity before withdrawing. V1 fees add
108
- * to the transaction value; V2 penalties are paid in the loan token.
109
- * Vault V1 inputs are deprecated for high-level Blue writes; use Vault V2
110
- * reallocations for new integrations.
111
- *
112
- * `getRequirements` returns the loan-token approval needed for V2 penalties
113
- * and `morpho.setAuthorization(generalAdapter1, true)` when GA1 is not yet
114
- * authorized on Morpho.
115
- *
116
- * **Stale `positionData` may cause unexpected supply share calculations.**
117
- *
118
- * @param params - Withdraw parameters including pre-fetched `positionData`.
119
- * @returns Object with `buildTx` and `getRequirements`.
120
- * @throws {BundlerErrors.UnexpectedAction} when a V2 plan is unsupported on the chain.
121
- * @throws {InputExceedsMaxError} when a V2 reallocation asset amount exceeds `uint128` or its penalty exceeds WAD.
122
- * @throws {InconsistentReallocationPenaltyError} when V2 entries for one vault use different penalties.
123
- * @throws {InvalidReallocationAddressError} when a V2 vault or adapter address is malformed.
124
- * @throws {InvalidReallocationSourceTypeError} when a V2 source is absent, incomplete, or has an unknown discriminator.
125
- * @throws {InvalidReallocationShapeError} when an entry matches both or neither V1/V2 shape.
126
- * @throws {MixedReallocationVersionsError} when one plan contains both V1 and V2 entries.
187
+ * Prepares a direct BlueBundlesV1 loan-asset withdrawal by assets or shares.
188
+ *
189
+ * `getRequirements()` reads Morpho authorization state for BlueBundlesV1. Optional reallocations
190
+ * are Vault V2-only; their penalties and the referral fee reduce withdrawal proceeds. Shares
191
+ * mode has neither a saturated full-close sentinel nor an onchain minimum-assets guarantee.
192
+ * This route exposes no Bundler3 share-price bound or `slippageTolerance`.
193
+ *
194
+ * @param params.userAddress - User whose supply position is withdrawn.
195
+ * @param params.positionData - Pre-fetched position used for ownership and balance validation.
196
+ * @param params.assets - Exact assets withdrawn, exclusive with `shares`.
197
+ * @param params.shares - Exact shares burned, exclusive with `assets`.
198
+ * @param params.reallocations - Optional Vault V2 reallocations executed before withdrawal.
199
+ * @param params.deadline - Final call deadline in Unix seconds.
200
+ * @param params.referralFeePct - Optional WAD-scaled referral fee below 100%.
201
+ * @param params.referralFeeRecipient - Recipient required for a positive fee.
202
+ * @returns Lazy authorization resolution and a synchronous deep-frozen transaction builder.
203
+ * @throws {ChainIdMismatchError} when the client targets another chain.
204
+ * @throws {ExpiredDeadlineError} when the deadline is stale.
205
+ * @throws {MissingAccrualPositionError} when no position snapshot is provided at runtime.
206
+ * @throws {MarketIdMismatchError} when `positionData` belongs to another market.
207
+ * @throws {AccrualPositionUserMismatchError} when `positionData` belongs to another user.
208
+ * @throws {NegativeInputError} when an amount, referral fee, or reallocation penalty is negative.
209
+ * @throws {NonPositiveInputError} when no withdrawal mode or positive reallocation amount is provided.
210
+ * @throws {MutuallyExclusiveWithdrawAmountsError} when assets and shares are both nonzero.
211
+ * @throws {WithdrawExceedsSupplyError} when assets exceed the supplied balance.
212
+ * @throws {WithdrawSharesExceedSupplyError} when shares exceed the owned balance.
213
+ * @throws {InputExceedsMaxError} when a fee or reallocation exceeds its ABI bound.
214
+ * @throws {MissingReferralFeeRecipientError} when a positive fee has no recipient.
215
+ * @throws {InvalidReallocationAddressError} when a vault or adapter address is malformed.
216
+ * @throws {InvalidReallocationShapeError} when a reallocation entry is not a valid Vault V2 reallocation.
217
+ * @throws {InvalidReallocationSourceTypeError} when a reallocation source is malformed.
218
+ * @throws {InconsistentReallocationPenaltyError} when one vault uses different penalties.
219
+ * @throws {ReallocationWithdrawalOnTargetMarketError} when a source is the target market.
220
+ * @throws {ReallocationLoanTokenMismatchError} when a source uses another loan token.
221
+ * @throws {AmbiguousRequirementSignaturesError} from `buildTx()` when multiple authorization signatures are supplied.
222
+ * @throws {UnexpectedRequirementSignatureError} from `buildTx()` when a non-authorization signature is supplied.
223
+ * @throws {DepositOwnerMismatchError} from `buildTx()` when the signed owner differs from `userAddress`.
224
+ * @throws {BundlesRequirementSignatureMismatchError} from `buildTx()` when authorization cannot be encoded safely.
225
+ * @throws {UnsupportedChainIdError} when the chain is absent from the address registry.
226
+ * @throws {UnknownAddressError} when BlueBundlesV1 is not registered.
227
+ * @throws {viem.BaseError} from `getRequirements()` when authorization reads fail.
228
+ * @example
229
+ * ```ts
230
+ * import { AccrualPosition } from "@morpho-org/blue-sdk";
231
+ * import { markets } from "@morpho-org/morpho-test";
232
+ * import { createPublicClient, http, zeroAddress } from "viem";
233
+ * import { mainnet } from "viem/chains";
234
+ * import { morphoViemExtension } from "@morpho-org/morpho-sdk";
235
+ *
236
+ * const userAddress = zeroAddress;
237
+ * const client = createPublicClient({ chain: mainnet, transport: http() })
238
+ * .extend(morphoViemExtension());
239
+ * const market = client.morpho.blue(markets[mainnet.id].usdc_wbtc, mainnet.id);
240
+ * const positionData = new AccrualPosition(
241
+ * { user: userAddress, supplyShares: 1n, borrowShares: 0n, collateral: 0n },
242
+ * await market.getMarketData(),
243
+ * );
244
+ * const action = market.withdraw({
245
+ * userAddress,
246
+ * positionData,
247
+ * shares: 1n,
248
+ * deadline: BigInt(Math.floor(Date.now() / 1_000) + 3_600),
249
+ * });
250
+ * const requirements = await action.getRequirements();
251
+ * const tx = action.buildTx();
252
+ * // tx satisfies Readonly<Transaction<BlueWithdrawAction>>
253
+ * ```
127
254
  */
128
255
  withdraw: (params: {
129
- userAddress: Address;
130
- receiver?: Address;
131
- positionData: AccrualPosition;
132
- slippageTolerance?: bigint;
133
- /** Vault V1 inputs are deprecated for high-level Blue writes; prefer Vault V2. */
134
- reallocations?: BlueReallocationPlan;
135
- } & AssetsOrSharesArgs) => {
136
- buildTx: (signatures?: readonly RequirementSignature[]) => Readonly<Transaction<BlueWithdrawAction>>;
137
- getRequirements: () => Promise<(Readonly<Transaction<ERC20ApprovalAction>> | Readonly<Transaction<BlueAuthorizationAction>> | Requirement)[]>;
138
- };
256
+ readonly userAddress: Address;
257
+ readonly positionData: AccrualPosition;
258
+ readonly reallocations?: Iterable<VaultV2BlueReallocation>;
259
+ readonly deadline: bigint;
260
+ readonly referralFeePct?: bigint;
261
+ readonly referralFeeRecipient?: Address;
262
+ } & AssetsOrSharesArgs) => ActionOutput<BlueWithdrawAction, readonly RequirementSignature[], undefined>;
139
263
  /**
140
- * Prepares a borrow transaction.
141
- *
142
- * Routed through bundler3 via `morphoBorrow`.
143
- * Validates position health with LLTV buffer (0.5%) using the pre-fetched `positionData`.
144
- * Computes `minSharePrice` from market borrow state and `slippageTolerance`.
145
- *
146
- * When `reallocations` is provided, its homogeneous V1 or V2 actions are
147
- * prepended before borrowing. V1 fees add to the transaction
148
- * value; V2 penalties are paid in the loan token.
149
- * Vault V1 inputs are deprecated for high-level Blue writes; use Vault V2
150
- * reallocations for new integrations.
151
- *
152
- * `getRequirements` returns the loan-token approval needed for V2 penalties
153
- * and Morpho authorization for GeneralAdapter1 when needed.
154
- *
155
- * **Stale `positionData` may cause unexpected health.**
156
- *
157
- * @param params - Borrow parameters including pre-fetched `positionData` for health validation.
158
- * @returns Object with `buildTx` and `getRequirements`.
159
- * @throws {BundlerErrors.UnexpectedAction} when a V2 plan is unsupported on the chain.
160
- * @throws {InputExceedsMaxError} when a V2 reallocation asset amount exceeds `uint128` or its penalty exceeds WAD.
161
- * @throws {InconsistentReallocationPenaltyError} when V2 entries for one vault use different penalties.
162
- * @throws {InvalidReallocationAddressError} when a V2 vault or adapter address is malformed.
163
- * @throws {InvalidReallocationSourceTypeError} when a V2 source is absent, incomplete, or has an unknown discriminator.
164
- * @throws {InvalidReallocationShapeError} when an entry matches both or neither V1/V2 shape.
165
- * @throws {MixedReallocationVersionsError} when one plan contains both V1 and V2 entries.
264
+ * Prepares a direct BlueBundlesV1 loan-asset borrow.
265
+ *
266
+ * This is the single-operation form of {@link BlueActions.supplyCollateralBorrow}; it borrows
267
+ * `borrowAssets` and fixes the inactive collateral-supply leg to zero. The pre-fetched position
268
+ * is forward-accrued for the buffered LLTV check.
269
+ *
270
+ * @param params.userAddress - User whose debt position changes.
271
+ * @param params.borrowAssets - Gross loan assets borrowed before penalties and referral fees.
272
+ * @param params.positionData - Pre-fetched position used for the health check.
273
+ * @param params.reallocations - Optional Vault V2 reallocations before borrowing.
274
+ * @param params.deadline - Final call deadline in Unix seconds.
275
+ * @param params.referralFeePct - Optional WAD-scaled referral fee below 100%.
276
+ * @param params.referralFeeRecipient - Recipient required for a positive fee.
277
+ * @returns Lazy Blue authorization resolution and a synchronous deep-frozen transaction.
278
+ * @throws {ChainIdMismatchError} when the client targets another chain.
279
+ * @throws {ExpiredDeadlineError} when the deadline is stale.
280
+ * @throws {MissingAccrualPositionError} when no position snapshot is provided.
281
+ * @throws {MarketIdMismatchError} when `positionData` belongs to another market.
282
+ * @throws {AccrualPositionUserMismatchError} when `positionData` belongs to another user.
283
+ * @throws {MissingMarketPriceError} when the health check has no oracle price.
284
+ * @throws {BorrowExceedsSafeLtvError} when the resulting position exceeds buffered LLTV.
285
+ * @throws {NonPositiveInputError} when `borrowAssets` is not positive.
286
+ * @throws {NegativeInputError} when the borrow, fee, or a reallocation value is negative.
287
+ * @throws {InputExceedsMaxError} when a fee, penalty, or reallocation exceeds its bound.
288
+ * @throws {MissingReferralFeeRecipientError} when a positive fee has no recipient.
289
+ * @throws {InvalidReallocationAddressError} when a vault or adapter address is malformed.
290
+ * @throws {InvalidReallocationShapeError} when a reallocation entry is not a valid Vault V2 reallocation.
291
+ * @throws {InvalidReallocationSourceTypeError} when a reallocation source is malformed.
292
+ * @throws {InconsistentReallocationPenaltyError} when one vault uses different penalties.
293
+ * @throws {ReallocationWithdrawalOnTargetMarketError} when a source is the target market.
294
+ * @throws {ReallocationLoanTokenMismatchError} when a source uses another loan token.
295
+ * @throws {AmbiguousRequirementSignaturesError} from `buildTx()` when multiple authorization signatures are supplied.
296
+ * @throws {UnexpectedRequirementSignatureError} from `buildTx()` when a token signature is supplied.
297
+ * @throws {DepositOwnerMismatchError} from `buildTx()` when the signed owner differs from `userAddress`.
298
+ * @throws {BundlesRequirementSignatureMismatchError} from `buildTx()` when authorization cannot be encoded safely.
299
+ * @throws {UnsupportedChainIdError} when the chain is absent from the address registry.
300
+ * @throws {UnknownAddressError} when BlueBundlesV1 is not registered.
301
+ * @throws {viem.BaseError} from `getRequirements()` when authorization reads fail.
302
+ * @example
303
+ * ```ts
304
+ * import { AccrualPosition } from "@morpho-org/blue-sdk";
305
+ * import { markets } from "@morpho-org/morpho-test";
306
+ * import { createPublicClient, http, zeroAddress } from "viem";
307
+ * import { mainnet } from "viem/chains";
308
+ * import { morphoViemExtension } from "@morpho-org/morpho-sdk";
309
+ *
310
+ * const client = createPublicClient({ chain: mainnet, transport: http() })
311
+ * .extend(morphoViemExtension());
312
+ * const market = client.morpho.blue(markets[mainnet.id].usdc_wbtc, mainnet.id);
313
+ * const userAddress = zeroAddress;
314
+ * const positionData = new AccrualPosition(
315
+ * { user: userAddress, supplyShares: 0n, borrowShares: 0n, collateral: 10n ** 18n },
316
+ * await market.getMarketData(),
317
+ * );
318
+ * const action = market.borrow({
319
+ * userAddress,
320
+ * borrowAssets: 1_000_000n,
321
+ * positionData,
322
+ * deadline: 1_900_000_000n,
323
+ * });
324
+ * const requirements = await action.getRequirements();
325
+ * const tx = action.buildTx();
326
+ * ```
166
327
  */
167
328
  borrow: (params: {
168
- userAddress: Address;
169
- amount: bigint;
170
- positionData: AccrualPosition;
171
- slippageTolerance?: bigint;
172
- /** Vault V1 inputs are deprecated for high-level Blue writes; prefer Vault V2. */
173
- reallocations?: BlueReallocationPlan;
174
- }) => {
175
- buildTx: (signatures?: readonly RequirementSignature[]) => Readonly<Transaction<BlueBorrowAction>>;
176
- getRequirements: () => Promise<(Readonly<Transaction<ERC20ApprovalAction>> | Readonly<Transaction<BlueAuthorizationAction>> | Requirement)[]>;
177
- };
329
+ readonly userAddress: Address;
330
+ readonly borrowAssets: bigint;
331
+ readonly positionData: AccrualPosition;
332
+ readonly reallocations?: Iterable<VaultV2BlueReallocation>;
333
+ readonly deadline: bigint;
334
+ readonly referralFeePct?: bigint;
335
+ readonly referralFeeRecipient?: Address;
336
+ }) => ActionOutput<BlueBorrowAction, readonly RequirementSignature[], undefined>;
178
337
  /**
179
- * Prepares a repay transaction.
180
- *
181
- * Routed through bundler3 via GeneralAdapter1.
182
- * Supports two modes via {@link RepayAmountArgs}:
183
- * - **By assets** (`{ amount }`): repays an exact asset amount (partial repay).
184
- * - **By shares** (`{ shares }`): repays exact shares (full repay, immune to interest accrual).
338
+ * Prepares a direct BlueBundlesV1 loan-asset repayment.
185
339
  *
186
- * Computes `maxSharePrice` from market borrow state and `slippageTolerance`.
340
+ * This is the single-operation form of {@link BlueActions.repayWithdrawCollateral}; it repays
341
+ * exact assets or shares and fixes the inactive collateral-withdrawal leg to zero. A saturated
342
+ * `repayShares = maxUint256` closes the live debt using a bounded, refundable funding cap.
187
343
  *
188
- * `getRequirements` returns ERC20 approval for loan token to GeneralAdapter1.
189
- * Does NOT require Morpho authorization (anyone can repay on behalf of anyone).
190
- *
191
- * **Shares mode:** `slippageTolerance` also caps `transferAmount`.
344
+ * @param params.userAddress - User whose debt position changes.
345
+ * @param params.positionData - Pre-fetched position used to validate and quote repayment.
346
+ * @param params.repayAssets - Exact assets repaid, exclusive with `repayShares`.
347
+ * @param params.repayShares - Exact shares, or `maxUint256` for a full repay.
348
+ * @param params.nativeAmount - Optional full native funding equal to the derived repayment cap.
349
+ * @param params.deadline - Final call deadline in Unix seconds.
350
+ * @param params.referralFeePct - Optional WAD-scaled referral fee below 100%.
351
+ * @param params.referralFeeRecipient - Recipient required for a positive fee.
352
+ * @returns Lazy token prerequisite resolution and a synchronous deep-frozen transaction.
353
+ * @throws {ChainIdMismatchError} when the client targets another chain.
354
+ * @throws {ExpiredDeadlineError} when the deadline is stale.
355
+ * @throws {MissingAccrualPositionError} when no position snapshot is provided.
356
+ * @throws {MarketIdMismatchError} when `positionData` belongs to another market.
357
+ * @throws {AccrualPositionUserMismatchError} when `positionData` belongs to another user.
358
+ * @throws {NegativeInputError} when an amount, native funding, or referral fee is negative.
359
+ * @throws {NonPositiveInputError} when no positive repayment is provided.
360
+ * @throws {MutuallyExclusiveRepayAmountsError} when assets and shares are both nonzero.
361
+ * @throws {RepayExceedsDebtError} when an exact asset repay exceeds current debt.
362
+ * @throws {RepaySharesExceedDebtError} when non-saturated shares exceed current debt shares.
363
+ * @throws {InputExceedsMaxError} when a fee is out of bounds or a share quote deadline is too far away.
364
+ * @throws {MaxRepayAssetsBelowRepayAssetsError} when a signed share cap no longer covers the fresh quote.
365
+ * @throws {MissingReferralFeeRecipientError} when a positive fee has no recipient.
366
+ * @throws {NativeFundingAmountMismatchError} when native funding is partial or mixed.
367
+ * @throws {ChainWNativeMissingError} when native funding is requested on a chain without wNative.
368
+ * @throws {NativeAmountOnNonWNativeAssetError} when native funding targets another token.
369
+ * @throws {MissingPermit2SignatureTransferNonceError} from `getRequirements()` when Permit2 is selected without a nonce.
370
+ * @throws {Permit2SignatureTransferNonceAlreadyUsedError} from `getRequirements()` when the explicit Permit2 nonce is consumed.
371
+ * @throws {AmbiguousRequirementSignaturesError} from `buildTx()` when multiple token signatures are supplied.
372
+ * @throws {UnexpectedRequirementSignatureError} from `buildTx()` when an authorization signature is supplied.
373
+ * @throws {DepositOwnerMismatchError} from `buildTx()` when the signed owner differs from `userAddress`.
374
+ * @throws {DepositAssetMismatchError} from `buildTx()` when the signed asset differs from the loan token.
375
+ * @throws {DepositAmountMismatchError} from `buildTx()` when the signed amount differs from the derived funding cap.
376
+ * @throws {DepositSpenderMismatchError} from `buildTx()` when the signed spender is not BlueBundlesV1.
377
+ * @throws {BundlesRequirementSignatureMismatchError} from `buildTx()` when a signature cannot be encoded safely.
378
+ * @throws {UnsupportedChainIdError} when the chain is absent from the address registry.
379
+ * @throws {UnknownAddressError} when BlueBundlesV1 is not registered.
380
+ * @throws {viem.BaseError} from `getRequirements()` when an allowance, nonce, or token metadata read fails.
381
+ * @example
382
+ * ```ts
383
+ * import { AccrualPosition } from "@morpho-org/blue-sdk";
384
+ * import { markets } from "@morpho-org/morpho-test";
385
+ * import { createPublicClient, http, maxUint256, zeroAddress } from "viem";
386
+ * import { mainnet } from "viem/chains";
387
+ * import { morphoViemExtension } from "@morpho-org/morpho-sdk";
192
388
  *
193
- * @param params - Repay parameters including pre-fetched `positionData`.
194
- * @returns Object with `buildTx` and `getRequirements`.
389
+ * const client = createPublicClient({ chain: mainnet, transport: http() })
390
+ * .extend(morphoViemExtension());
391
+ * const market = client.morpho.blue(markets[mainnet.id].usdc_wbtc, mainnet.id);
392
+ * const userAddress = zeroAddress;
393
+ * const positionData = new AccrualPosition(
394
+ * { user: userAddress, supplyShares: 0n, borrowShares: 1n, collateral: 10n ** 18n },
395
+ * await market.getMarketData(),
396
+ * );
397
+ * const action = market.repay({
398
+ * userAddress,
399
+ * positionData,
400
+ * repayShares: maxUint256,
401
+ * deadline: 1_900_000_000n,
402
+ * });
403
+ * const requirements = await action.getRequirements();
404
+ * const tx = action.buildTx();
405
+ * ```
195
406
  */
196
407
  repay: (params: {
197
- userAddress: Address;
198
- positionData: AccrualPosition;
199
- slippageTolerance?: bigint;
200
- } & RepayAmountArgs) => {
201
- buildTx: (signatures?: readonly RequirementSignature[]) => Readonly<Transaction<BlueRepayAction>>;
202
- getRequirements: (params?: {
203
- /**
204
- * Prefer the ERC-2612 simple-permit path when the SDK detects support.
205
- * Leave unset or set to `false` to force the Permit2/classic approval fallback when
206
- * a token is known to be incompatible despite passing the SDK's shallow nonce probe.
207
- */
208
- useSimplePermit?: boolean;
209
- }) => Promise<(Readonly<Transaction<ERC20ApprovalAction>> | Requirement<PermitRequirementSignature>)[]>;
210
- };
408
+ readonly userAddress: Address;
409
+ readonly positionData: AccrualPosition;
410
+ readonly nativeAmount?: bigint;
411
+ readonly deadline: bigint;
412
+ readonly referralFeePct?: bigint;
413
+ readonly referralFeeRecipient?: Address;
414
+ } & ({
415
+ readonly repayAssets: bigint;
416
+ readonly repayShares?: never;
417
+ } | {
418
+ readonly repayShares: bigint;
419
+ readonly repayAssets?: never;
420
+ })) => ActionOutput<BlueRepayAction, readonly RequirementSignature[], BlueTokenRequirementsParams>;
211
421
  /**
212
- * Prepares a withdraw-collateral transaction.
422
+ * Prepares a direct BlueBundlesV1 collateral withdrawal.
213
423
  *
214
- * Direct call to `morpho.withdrawCollateral()` — no bundler, no GeneralAdapter1.
215
- * The caller (`msg.sender`) must be `onBehalf`.
216
- * Validates position health after withdrawal using the LLTV buffer.
424
+ * This is the single-operation form of {@link BlueActions.repayWithdrawCollateral}; it withdraws
425
+ * `collateralAssets` and fixes both inactive repayment fields to zero. The pre-fetched position
426
+ * is forward-accrued before applying the buffered LLTV health check.
217
427
  *
218
- * No `getRequirements` — no ERC20 approval or GeneralAdapter1 authorization needed
219
- * (collateral flows out of Morpho, not in).
220
- *
221
- * **No on-chain slippage guard — stale `positionData` risks liquidation.**
428
+ * @param params.userAddress - User whose collateral position changes.
429
+ * @param params.positionData - Pre-fetched position used for balance and health validation.
430
+ * @param params.collateralAssets - Collateral assets withdrawn.
431
+ * @param params.deadline - Final call deadline in Unix seconds.
432
+ * @param params.referralFeePct - Optional WAD-scaled referral fee below 100%.
433
+ * @param params.referralFeeRecipient - Recipient required for a positive fee.
434
+ * @returns Lazy Blue authorization resolution and a synchronous deep-frozen transaction.
435
+ * @throws {ChainIdMismatchError} when the client targets another chain.
436
+ * @throws {ExpiredDeadlineError} when the deadline is stale.
437
+ * @throws {MissingAccrualPositionError} when no position snapshot is provided.
438
+ * @throws {MarketIdMismatchError} when `positionData` belongs to another market.
439
+ * @throws {AccrualPositionUserMismatchError} when `positionData` belongs to another user.
440
+ * @throws {WithdrawExceedsCollateralError} when the withdrawal exceeds the position collateral.
441
+ * @throws {MissingMarketPriceError} when the health check has no oracle price.
442
+ * @throws {WithdrawMakesPositionUnhealthyError} when the result exceeds buffered LLTV.
443
+ * @throws {NonPositiveInputError} when `collateralAssets` is not positive.
444
+ * @throws {NegativeInputError} when collateral or the referral fee is negative.
445
+ * @throws {InputExceedsMaxError} when the referral fee is at least WAD.
446
+ * @throws {MissingReferralFeeRecipientError} when a positive fee has no recipient.
447
+ * @throws {AmbiguousRequirementSignaturesError} from `buildTx()` when multiple authorization signatures are supplied.
448
+ * @throws {UnexpectedRequirementSignatureError} from `buildTx()` when a token signature is supplied.
449
+ * @throws {DepositOwnerMismatchError} from `buildTx()` when the signed owner differs from `userAddress`.
450
+ * @throws {BundlesRequirementSignatureMismatchError} from `buildTx()` when authorization cannot be encoded safely.
451
+ * @throws {UnsupportedChainIdError} when the chain is absent from the address registry.
452
+ * @throws {UnknownAddressError} when BlueBundlesV1 is not registered.
453
+ * @throws {viem.BaseError} from `getRequirements()` when authorization reads fail.
454
+ * @example
455
+ * ```ts
456
+ * import { AccrualPosition } from "@morpho-org/blue-sdk";
457
+ * import { markets } from "@morpho-org/morpho-test";
458
+ * import { createPublicClient, http, zeroAddress } from "viem";
459
+ * import { mainnet } from "viem/chains";
460
+ * import { morphoViemExtension } from "@morpho-org/morpho-sdk";
222
461
  *
223
- * @param params - Withdraw collateral parameters including pre-fetched `positionData` for health validation.
224
- * @returns Object with `buildTx`.
462
+ * const client = createPublicClient({ chain: mainnet, transport: http() })
463
+ * .extend(morphoViemExtension());
464
+ * const market = client.morpho.blue(markets[mainnet.id].usdc_wbtc, mainnet.id);
465
+ * const userAddress = zeroAddress;
466
+ * const positionData = new AccrualPosition(
467
+ * { user: userAddress, supplyShares: 0n, borrowShares: 0n, collateral: 10n ** 18n },
468
+ * await market.getMarketData(),
469
+ * );
470
+ * const action = market.withdrawCollateral({
471
+ * userAddress,
472
+ * positionData,
473
+ * collateralAssets: 10n ** 17n,
474
+ * deadline: 1_900_000_000n,
475
+ * });
476
+ * const requirements = await action.getRequirements();
477
+ * const tx = action.buildTx();
478
+ * ```
225
479
  */
226
480
  withdrawCollateral: (params: {
227
- userAddress: Address;
228
- amount: bigint;
229
- positionData: AccrualPosition;
230
- }) => {
231
- buildTx: () => Readonly<Transaction<BlueWithdrawCollateralAction>>;
232
- };
481
+ readonly userAddress: Address;
482
+ readonly positionData: AccrualPosition;
483
+ readonly collateralAssets: bigint;
484
+ readonly deadline: bigint;
485
+ readonly referralFeePct?: bigint;
486
+ readonly referralFeeRecipient?: Address;
487
+ }) => ActionOutput<BlueWithdrawCollateralAction, readonly RequirementSignature[], undefined>;
233
488
  /**
234
- * Prepares an atomic repay-and-withdraw-collateral transaction.
235
- *
236
- * Routed through bundler3. Bundle order: repay FIRST, then withdraw.
237
- * Validates combined position health: simulates the repay, then checks
238
- * that the resulting position can sustain the collateral withdrawal.
489
+ * Prepares a direct BlueBundlesV1 repay, collateral withdrawal, or atomic combination.
239
490
  *
240
- * `getRequirements` returns in parallel:
241
- * - ERC20 approval for loan token to GeneralAdapter1 (for the repay).
242
- * - `morpho.setAuthorization(generalAdapter1, true)` if not yet authorized (for the withdraw).
491
+ * Repayment accepts exact assets or shares. `repayShares = maxUint256` requests the contract's
492
+ * saturated full close; the entity derives `maxRepayAssets` from debt projected through the
493
+ * requested deadline plus the referral fee, and the contract refunds unused funding. A
494
+ * previously signed share-mode cap remains valid when it still covers the fresh derived minimum.
495
+ * Saturated full-repay requirements use the token's reusable maximum allowance when signatures
496
+ * are disabled, while the transaction itself remains bounded by the derived cap.
497
+ * Share-mode deadlines cannot exceed the two-hour quote horizon. Blue authorization is required
498
+ * only for collateral withdrawal. Pure repay uses `maxLtv = maxUint256`; withdrawals use buffered
499
+ * LLTV. No Bundler3 share-price or `slippageTolerance` input exists.
243
500
  *
244
- * **Stale `positionData` risks underestimated debt and unsafe withdrawal.**
501
+ * @param params.userAddress - User whose debt and collateral position changes.
502
+ * @param params.positionData - Pre-fetched position used for repayment and health validation.
503
+ * @param params.repayAssets - Exact assets repaid, exclusive with `repayShares`.
504
+ * @param params.repayShares - Exact shares, or `maxUint256` for full repay.
505
+ * @param params.collateralAssets - Collateral withdrawn, or zero for pure repay.
506
+ * @param params.nativeAmount - Optional full native funding; must equal derived `maxRepayAssets`.
507
+ * @param params.deadline - Final call deadline in Unix seconds; share mode is limited to the two-hour funding quote horizon.
508
+ * @param params.referralFeePct - Optional WAD-scaled referral fee below 100%.
509
+ * @param params.referralFeeRecipient - Recipient required for a positive fee.
510
+ * @returns Lazy funding/authorization resolution and a synchronous deep-frozen transaction builder.
511
+ * @throws {ChainIdMismatchError} when the client targets another chain.
512
+ * @throws {MissingAccrualPositionError} when no position snapshot is provided at runtime.
513
+ * @throws {MarketIdMismatchError} when `positionData` belongs to another market.
514
+ * @throws {AccrualPositionUserMismatchError} when `positionData` belongs to another user.
515
+ * @throws {NegativeInputError} when an amount, native funding, or referral fee is negative.
516
+ * @throws {NonPositiveInputError} when no operation leg is provided.
517
+ * @throws {MutuallyExclusiveRepayAmountsError} when assets and shares are both nonzero.
518
+ * @throws {RepayExceedsDebtError} when an exact asset repay exceeds current debt.
519
+ * @throws {RepaySharesExceedDebtError} when non-saturated shares exceed current debt shares.
520
+ * @throws {WithdrawExceedsCollateralError} when collateral withdrawal exceeds the position.
521
+ * @throws {MissingMarketPriceError} when withdrawal health cannot be validated without an oracle price.
522
+ * @throws {WithdrawMakesPositionUnhealthyError} when the post-repay withdrawal exceeds buffered LLTV.
523
+ * @throws {ExpiredDeadlineError} when the deadline is stale.
524
+ * @throws {InputExceedsMaxError} when the referral fee is at least WAD or a share-mode deadline exceeds the funding quote horizon.
525
+ * @throws {MaxRepayAssetsBelowRepayAssetsError} from `buildTx()` when a previously signed share-mode cap no longer covers the fresh derived minimum.
526
+ * @throws {MissingReferralFeeRecipientError} when a positive fee has no recipient.
527
+ * @throws {NativeFundingAmountMismatchError} when native funding is partial or mixed.
528
+ * @throws {ChainWNativeMissingError} when native funding is requested on a chain without wNative.
529
+ * @throws {NativeAmountOnNonWNativeAssetError} when native funding targets another token.
530
+ * @throws {MissingPermit2SignatureTransferNonceError} from `getRequirements()` when Permit2 is selected without an explicit nonce.
531
+ * @throws {Permit2SignatureTransferNonceAlreadyUsedError} from `getRequirements()` when the explicit Permit2 nonce is consumed.
532
+ * @throws {AmbiguousRequirementSignaturesError} from `buildTx()` when multiple signatures of one kind are supplied.
533
+ * @throws {UnexpectedRequirementSignatureError} from `buildTx()` when an inactive leg cannot consume a supplied signature.
534
+ * @throws {DepositOwnerMismatchError} from `buildTx()` when a signed owner differs from `userAddress`.
535
+ * @throws {DepositAssetMismatchError} from `buildTx()` when the signed asset differs from the loan token.
536
+ * @throws {DepositAmountMismatchError} from `buildTx()` when the signed amount differs from the derived funding cap.
537
+ * @throws {DepositSpenderMismatchError} from `buildTx()` when the signed spender is not BlueBundlesV1.
538
+ * @throws {BundlesRequirementSignatureMismatchError} from `buildTx()` when a signature cannot be encoded safely.
539
+ * @throws {UnsupportedChainIdError} when the chain is absent from the address registry.
540
+ * @throws {UnknownAddressError} when BlueBundlesV1 is not registered.
541
+ * @throws {viem.BaseError} from `getRequirements()` when a required allowance, nonce, token metadata, or authorization read fails.
542
+ * @example
543
+ * ```ts
544
+ * import { AccrualPosition } from "@morpho-org/blue-sdk";
545
+ * import { markets } from "@morpho-org/morpho-test";
546
+ * import { createPublicClient, http, maxUint256, zeroAddress } from "viem";
547
+ * import { mainnet } from "viem/chains";
548
+ * import { morphoViemExtension } from "@morpho-org/morpho-sdk";
245
549
  *
246
- * @param params - Combined parameters including pre-fetched `positionData`.
247
- * @returns Object with `buildTx` and `getRequirements`.
550
+ * const userAddress = zeroAddress;
551
+ * const client = createPublicClient({ chain: mainnet, transport: http() })
552
+ * .extend(morphoViemExtension());
553
+ * const market = client.morpho.blue(markets[mainnet.id].usdc_wbtc, mainnet.id);
554
+ * const positionData = new AccrualPosition(
555
+ * { user: userAddress, supplyShares: 0n, borrowShares: 1n, collateral: 100_000_000n },
556
+ * await market.getMarketData(),
557
+ * );
558
+ * const action = market.repayWithdrawCollateral({
559
+ * userAddress,
560
+ * positionData,
561
+ * repayShares: maxUint256,
562
+ * collateralAssets: 1n,
563
+ * deadline: BigInt(Math.floor(Date.now() / 1_000) + 3_600),
564
+ * });
565
+ * const requirements = await action.getRequirements(); // Satisfy these first.
566
+ * const tx = action.buildTx(); // For a client configured with supportSignature: false.
567
+ * // tx satisfies Readonly<Transaction<BlueRepayWithdrawCollateralAction>>
568
+ * ```
248
569
  */
249
570
  repayWithdrawCollateral: (params: {
250
- userAddress: Address;
251
- withdrawAmount: bigint;
252
- positionData: AccrualPosition;
253
- slippageTolerance?: bigint;
254
- } & RepayAmountArgs) => {
255
- buildTx: (signatures?: readonly RequirementSignature[]) => Readonly<Transaction<BlueRepayWithdrawCollateralAction>>;
256
- getRequirements: (params?: {
257
- /**
258
- * Prefer the ERC-2612 simple-permit path when the SDK detects support.
259
- * Leave unset or set to `false` to force the Permit2/classic approval fallback when
260
- * a token is known to be incompatible despite passing the SDK's shallow nonce probe.
261
- */
262
- useSimplePermit?: boolean;
263
- }) => Promise<(Readonly<Transaction<ERC20ApprovalAction>> | Readonly<Transaction<BlueAuthorizationAction>> | Requirement)[]>;
264
- };
571
+ readonly userAddress: Address;
572
+ readonly positionData: AccrualPosition;
573
+ readonly collateralAssets: bigint;
574
+ readonly nativeAmount?: bigint;
575
+ readonly deadline: bigint;
576
+ readonly referralFeePct?: bigint;
577
+ readonly referralFeeRecipient?: Address;
578
+ } & ({
579
+ readonly repayAssets: bigint;
580
+ readonly repayShares?: never;
581
+ } | {
582
+ readonly repayShares: bigint;
583
+ readonly repayAssets?: never;
584
+ } | {
585
+ readonly repayAssets?: undefined;
586
+ readonly repayShares?: undefined;
587
+ })) => ActionOutput<BlueRepayWithdrawCollateralAction, readonly RequirementSignature[], BlueTokenRequirementsParams>;
265
588
  /**
266
- * Prepares an atomic supply-collateral-and-borrow transaction.
267
- *
268
- * Routed through the bundler. Validates position health with LLTV buffer
269
- * to prevent instant liquidation on new positions near the LLTV threshold.
270
- *
271
- * When `reallocations` is provided, its homogeneous V1 or V2 actions run
272
- * between the collateral supply and `morphoBorrow`. V1 fees add
273
- * to the transaction value; V2 penalties are paid in the loan token.
274
- * Vault V1 inputs are deprecated for high-level Blue writes; use Vault V2
275
- * reallocations for new integrations.
276
- *
277
- * `getRequirements` returns in parallel:
278
- * - ERC20 approval or permit for collateral token (to GeneralAdapter1).
279
- * - Classic ERC20 approval for any V2 loan-token penalties.
280
- * - `morpho.setAuthorization(generalAdapter1, true)` if adapter is not yet authorized.
281
- *
282
- * **Stale `positionData` may cause unexpected health.**
283
- *
284
- * @param params - Combined parameters including pre-fetched `positionData` for health validation.
285
- * @returns Object with `buildTx` and `getRequirements`.
286
- * @throws {BundlerErrors.UnexpectedAction} when a V2 plan is unsupported on the chain.
287
- * @throws {InputExceedsMaxError} when a V2 reallocation asset amount exceeds `uint128` or its penalty exceeds WAD.
288
- * @throws {InconsistentReallocationPenaltyError} when V2 entries for one vault use different penalties.
289
- * @throws {InvalidReallocationAddressError} when a V2 vault or adapter address is malformed.
290
- * @throws {InvalidReallocationSourceTypeError} when a V2 source is absent, incomplete, or has an unknown discriminator.
291
- * @throws {InvalidReallocationShapeError} when an entry matches both or neither V1/V2 shape.
292
- * @throws {MixedReallocationVersionsError} when one plan contains both V1 and V2 entries.
589
+ * Prepares a direct BlueBundlesV1 collateral supply, borrow, or atomic combination.
590
+ *
591
+ * At least one leg must be positive. A borrow requires `positionData` and Blue authorization;
592
+ * collateral funding requires token approval/signature unless it is exclusively native. Vault V2
593
+ * reallocations are accepted only with a borrow. Penalties and referral fees reduce borrow
594
+ * proceeds. The entity uses `maxUint256` for a pure collateral supply and buffered LLTV otherwise.
595
+ * No Bundler3 share-price or `slippageTolerance` input exists.
596
+ *
597
+ * @param params.userAddress - User whose collateral and debt position changes.
598
+ * @param params.collateralAssets - Gross collateral supplied, or zero for pure borrow.
599
+ * @param params.borrowAssets - Loan assets borrowed, or zero for pure collateral supply.
600
+ * @param params.positionData - Pre-fetched position; required when `borrowAssets` is positive.
601
+ * @param params.nativeAmount - Optional full native collateral funding; must equal `collateralAssets`.
602
+ * @param params.reallocations - Optional Vault V2 reallocations; valid only for a borrow.
603
+ * @param params.deadline - Final call deadline in Unix seconds.
604
+ * @param params.referralFeePct - Optional WAD-scaled referral fee below 100%.
605
+ * @param params.referralFeeRecipient - Recipient required for a positive fee.
606
+ * @returns Lazy funding/authorization resolution and a synchronous deep-frozen transaction builder.
607
+ * @throws {ChainIdMismatchError} when the client targets another chain.
608
+ * @throws {MissingAccrualPositionError} when a borrow has no position snapshot.
609
+ * @throws {MarketIdMismatchError} when `positionData` belongs to another market.
610
+ * @throws {AccrualPositionUserMismatchError} when `positionData` belongs to another user.
611
+ * @throws {MissingMarketPriceError} when a borrow cannot be validated without an oracle price.
612
+ * @throws {BorrowExceedsSafeLtvError} when the resulting debt exceeds buffered LLTV.
613
+ * @throws {ReallocationsRequireBorrowError} when reallocations accompany no borrow.
614
+ * @throws {ExpiredDeadlineError} when the deadline is stale.
615
+ * @throws {NegativeInputError} when an amount, native funding, referral fee, or reallocation penalty is negative.
616
+ * @throws {NonPositiveInputError} when both legs or a reallocation amount is not positive.
617
+ * @throws {NativeFundingAmountMismatchError} when native funding is partial or mixed.
618
+ * @throws {ChainWNativeMissingError} when native funding is requested on a chain without wNative.
619
+ * @throws {NativeAmountOnNonWNativeAssetError} when native funding targets another token.
620
+ * @throws {InputExceedsMaxError} when a fee or reallocation exceeds its ABI bound.
621
+ * @throws {MissingReferralFeeRecipientError} when a positive fee has no recipient.
622
+ * @throws {InvalidReallocationAddressError} when a vault or adapter address is malformed.
623
+ * @throws {InvalidReallocationShapeError} when a reallocation entry is not a valid Vault V2 reallocation.
624
+ * @throws {InvalidReallocationSourceTypeError} when a reallocation source is malformed.
625
+ * @throws {InconsistentReallocationPenaltyError} when one vault uses different penalties.
626
+ * @throws {ReallocationWithdrawalOnTargetMarketError} when a source is the target market.
627
+ * @throws {ReallocationLoanTokenMismatchError} when a source uses another loan token.
628
+ * @throws {MissingPermit2SignatureTransferNonceError} from `getRequirements()` when Permit2 is selected without an explicit nonce.
629
+ * @throws {Permit2SignatureTransferNonceAlreadyUsedError} from `getRequirements()` when the explicit Permit2 nonce is consumed.
630
+ * @throws {AmbiguousRequirementSignaturesError} from `buildTx()` when multiple signatures of one kind are supplied.
631
+ * @throws {UnexpectedRequirementSignatureError} from `buildTx()` when an inactive leg cannot consume a supplied signature.
632
+ * @throws {DepositOwnerMismatchError} from `buildTx()` when a signed owner differs from `userAddress`.
633
+ * @throws {DepositAssetMismatchError} from `buildTx()` when the signed asset differs from the collateral token.
634
+ * @throws {DepositAmountMismatchError} from `buildTx()` when the signed amount differs from `collateralAssets`.
635
+ * @throws {DepositSpenderMismatchError} from `buildTx()` when the signed spender is not BlueBundlesV1.
636
+ * @throws {BundlesRequirementSignatureMismatchError} from `buildTx()` when a signature cannot be encoded safely.
637
+ * @throws {UnsupportedChainIdError} when the chain is absent from the address registry.
638
+ * @throws {UnknownAddressError} when BlueBundlesV1 is not registered.
639
+ * @throws {viem.BaseError} from `getRequirements()` when a required allowance, nonce, token metadata, or authorization read fails.
640
+ * @example
641
+ * ```ts
642
+ * import { markets } from "@morpho-org/morpho-test";
643
+ * import { createPublicClient, http, zeroAddress } from "viem";
644
+ * import { mainnet } from "viem/chains";
645
+ * import { morphoViemExtension } from "@morpho-org/morpho-sdk";
646
+ *
647
+ * const userAddress = zeroAddress;
648
+ * const client = createPublicClient({ chain: mainnet, transport: http() })
649
+ * .extend(morphoViemExtension());
650
+ * const market = client.morpho.blue(markets[mainnet.id].usdc_wbtc, mainnet.id);
651
+ * const positionData = await market.getPositionData(userAddress);
652
+ * const action = market.supplyCollateralBorrow({
653
+ * userAddress,
654
+ * positionData,
655
+ * collateralAssets: 100_000_000n,
656
+ * borrowAssets: 1_000_000n,
657
+ * deadline: BigInt(Math.floor(Date.now() / 1_000) + 3_600),
658
+ * });
659
+ * const requirements = await action.getRequirements(); // Satisfy these first.
660
+ * const tx = action.buildTx(); // For a client configured with supportSignature: false.
661
+ * // tx satisfies Readonly<Transaction<BlueSupplyCollateralBorrowAction>>
662
+ * ```
293
663
  */
294
664
  supplyCollateralBorrow: (params: {
295
- userAddress: Address;
296
- positionData: AccrualPosition;
297
- borrowAmount: bigint;
298
- slippageTolerance?: bigint;
299
- /** Vault V1 inputs are deprecated for high-level Blue writes; prefer Vault V2. */
300
- reallocations?: BlueReallocationPlan;
301
- } & DepositAmountArgs) => {
302
- buildTx: (signatures?: readonly RequirementSignature[]) => Readonly<Transaction<BlueSupplyCollateralBorrowAction>>;
303
- getRequirements: (params?: {
304
- /**
305
- * Prefer the ERC-2612 simple-permit path when the SDK detects support.
306
- * Leave unset or set to `false` to force the Permit2/classic approval fallback when
307
- * a token is known to be incompatible despite passing the SDK's shallow nonce probe.
308
- */
309
- useSimplePermit?: boolean;
310
- }) => Promise<(Readonly<Transaction<ERC20ApprovalAction>> | Readonly<Transaction<BlueAuthorizationAction>> | Requirement)[]>;
311
- };
665
+ readonly userAddress: Address;
666
+ readonly collateralAssets: bigint;
667
+ readonly borrowAssets: bigint;
668
+ readonly positionData?: AccrualPosition;
669
+ readonly nativeAmount?: bigint;
670
+ readonly reallocations?: Iterable<VaultV2BlueReallocation>;
671
+ readonly deadline: bigint;
672
+ readonly referralFeePct?: bigint;
673
+ readonly referralFeeRecipient?: Address;
674
+ }) => ActionOutput<BlueSupplyCollateralBorrowAction, readonly RequirementSignature[], BlueTokenRequirementsParams>;
312
675
  /**
313
- * Prepares an atomic refinance migrating this market's position to another Morpho Blue market
314
- * that shares the same loan and collateral tokens. See {@link blueRefinance} for the bundle.
315
- *
316
- * Validates ownership, token/id match, that amounts do not exceed the source position, and that
317
- * both the residual source and the aggregate target position stay within LLTV − buffer. Both
318
- * markets are forward-accrued to `now`; in shares mode the target borrow is overshot by
319
- * `slippageTolerance` and the callback sweeps the residual.
320
- * A homogeneous V1 or V2 target reallocation plan runs first; V1 fees add
321
- * to the transaction value and V2 penalties are paid
322
- * in the loan token.
323
- * Vault V1 inputs are deprecated for high-level Blue writes; use Vault V2
324
- * reallocations for new integrations.
325
- *
326
- * `getRequirements` returns the loan-token approval needed for V2 penalties
327
- * and Morpho authorization for GeneralAdapter1 when needed.
328
- *
329
- * @param params.userAddress - Position owner on both markets.
330
- * @param params.positionData - Pre-fetched source-market accrual position.
331
- * @param params.target.marketParams - Target market params.
332
- * @param params.target.positionData - Pre-fetched target-market accrual position (zero-position if none).
333
- * @param params.collateralAmount - Amount of collateral to migrate from source to target.
334
- * @param params.borrowAssets - Loan assets to repay on source; exclusive with `borrowShares`.
335
- * @param params.borrowShares - Borrow shares to repay on source; exclusive with `borrowAssets`.
336
- * @param params.slippageTolerance - WAD slippage tolerance. Defaults to `DEFAULT_SLIPPAGE_TOLERANCE`.
337
- * @param params.targetReallocations - Homogeneous Vault V1 or Vault V2 reallocations into the
338
- * target market. Vault V1 inputs are deprecated; prefer Vault V2.
339
- * @returns Object with `buildTx` and `getRequirements`.
340
- * @throws {BundlerErrors.UnexpectedAction} when a V2 plan is unsupported on the chain.
341
- * @throws {InputExceedsMaxError} when a V2 reallocation asset amount exceeds `uint128` or its penalty exceeds WAD.
342
- * @throws {InconsistentReallocationPenaltyError} when V2 entries for one vault use different penalties.
343
- * @throws {InvalidReallocationAddressError} when a V2 vault or adapter address is malformed.
344
- * @throws {InvalidReallocationSourceTypeError} when a V2 source is absent, incomplete, or has an unknown discriminator.
345
- * @throws {InvalidReallocationShapeError} when an entry matches both or neither V1/V2 shape.
346
- * @throws {MixedReallocationVersionsError} when one plan contains both V1 and V2 entries.
676
+ * Prepares a direct BlueBundlesV1 full borrow-position migration.
677
+ *
678
+ * The scoped market is the source. BlueBundlesV1 reads the live source debt/collateral at
679
+ * execution and extends the destination position; zero live debt reverts. The markets must share
680
+ * both tokens. Referral fees and Vault V2 reallocation penalties increase destination debt, whose
681
+ * complete position is checked against buffered LLTV. Partial and collateral-only migration are
682
+ * unsupported.
683
+ *
684
+ * @param params.userAddress - Intended owner used to validate both snapshots and resolve Morpho
685
+ * authorization. It must also send the transaction: the builder cannot enforce this alignment
686
+ * because this field is not encoded and BlueBundlesV1 always migrates `msg.sender`.
687
+ * @param params.positionData - Pre-fetched source position with nonzero debt.
688
+ * @param params.destination.marketParams - Distinct destination market with matching tokens.
689
+ * @param params.destination.positionData - User's pre-fetched destination position.
690
+ * @param params.reallocations - Optional Vault V2 reallocations into the destination.
691
+ * @param params.deadline - Final call deadline in Unix seconds.
692
+ * @param params.referralFeePct - Optional WAD-scaled referral fee below 100%.
693
+ * @param params.referralFeeRecipient - Recipient required for a positive fee.
694
+ * @returns Lazy Blue authorization resolution and a synchronous deep-frozen transaction builder.
695
+ * @throws {ChainIdMismatchError} when the client targets another chain.
696
+ * @throws {MissingAccrualPositionError} when either position snapshot is absent at runtime.
697
+ * @throws {MarketIdMismatchError} when a position snapshot belongs to another market.
698
+ * @throws {AccrualPositionUserMismatchError} when a position snapshot belongs to another user.
699
+ * @throws {RefinanceSameMarketError} when source and destination IDs match.
700
+ * @throws {RefinanceTokenMismatchError} when their loan or collateral tokens differ.
701
+ * @throws {NegativeInputError} when a referral fee or reallocation penalty is negative.
702
+ * @throws {NonPositiveInputError} when the source has no borrow shares or a reallocation amount is not positive.
703
+ * @throws {MissingMarketPriceError} when destination health cannot be validated without an oracle price.
704
+ * @throws {BorrowExceedsSafeLtvError} when the complete destination exceeds buffered LLTV.
705
+ * @throws {ExpiredDeadlineError} when the deadline is stale.
706
+ * @throws {InputExceedsMaxError} when a fee or reallocation exceeds its ABI bound.
707
+ * @throws {MissingReferralFeeRecipientError} when a positive fee has no recipient.
708
+ * @throws {InvalidReallocationAddressError} when a vault or adapter address is malformed.
709
+ * @throws {InvalidReallocationShapeError} when a reallocation entry is not a valid Vault V2 reallocation.
710
+ * @throws {InvalidReallocationSourceTypeError} when a reallocation source is malformed.
711
+ * @throws {InconsistentReallocationPenaltyError} when one vault uses different penalties.
712
+ * @throws {ReallocationWithdrawalOnTargetMarketError} when a source is the destination market.
713
+ * @throws {ReallocationLoanTokenMismatchError} when a source uses another loan token.
714
+ * @throws {AmbiguousRequirementSignaturesError} from `buildTx()` when multiple authorization signatures are supplied.
715
+ * @throws {UnexpectedRequirementSignatureError} from `buildTx()` when a non-authorization signature is supplied.
716
+ * @throws {DepositOwnerMismatchError} from `buildTx()` when the signed owner differs from `userAddress`.
717
+ * @throws {BundlesRequirementSignatureMismatchError} from `buildTx()` when authorization cannot be encoded safely.
718
+ * @throws {UnsupportedChainIdError} when the chain is absent from the address registry.
719
+ * @throws {UnknownAddressError} when BlueBundlesV1 is not registered.
720
+ * @throws {viem.BaseError} from `getRequirements()` when authorization reads fail.
721
+ * @example
722
+ * ```ts
723
+ * import { AccrualPosition } from "@morpho-org/blue-sdk";
724
+ * import { markets } from "@morpho-org/morpho-test";
725
+ * import { createPublicClient, http, zeroAddress } from "viem";
726
+ * import { mainnet } from "viem/chains";
727
+ * import { morphoViemExtension } from "@morpho-org/morpho-sdk";
728
+ *
729
+ * const userAddress = zeroAddress;
730
+ * const client = createPublicClient({ chain: mainnet, transport: http() })
731
+ * .extend(morphoViemExtension());
732
+ * const sourceParams = markets[mainnet.id].eth_wstEth_2;
733
+ * const destinationParams = markets[mainnet.id].eth_wstEth;
734
+ * const market = client.morpho.blue(sourceParams, mainnet.id);
735
+ * const destinationMarket = client.morpho.blue(destinationParams, mainnet.id);
736
+ * const source = new AccrualPosition(
737
+ * { user: userAddress, supplyShares: 0n, borrowShares: 1n, collateral: 10n ** 18n },
738
+ * await market.getMarketData(),
739
+ * );
740
+ * const destination = new AccrualPosition(
741
+ * { user: userAddress, supplyShares: 0n, borrowShares: 0n, collateral: 0n },
742
+ * await destinationMarket.getMarketData(),
743
+ * );
744
+ * const action = market.refinance({
745
+ * userAddress,
746
+ * positionData: source,
747
+ * destination: { marketParams: destinationParams, positionData: destination },
748
+ * deadline: BigInt(Math.floor(Date.now() / 1_000) + 3_600),
749
+ * });
750
+ * const requirements = await action.getRequirements(); // Satisfy these first.
751
+ * const tx = action.buildTx(); // For a client configured with supportSignature: false.
752
+ * // tx satisfies Readonly<Transaction<BlueRefinanceAction>>
753
+ * ```
347
754
  */
348
755
  refinance: (params: {
349
- userAddress: Address;
350
- positionData: AccrualPosition;
351
- target: {
352
- marketParams: MarketParams;
353
- positionData: AccrualPosition;
756
+ readonly userAddress: Address;
757
+ readonly positionData: AccrualPosition;
758
+ readonly destination: {
759
+ readonly marketParams: MarketParams;
760
+ readonly positionData: AccrualPosition;
354
761
  };
355
- collateralAmount: bigint;
356
- borrowAssets?: bigint;
357
- borrowShares?: bigint;
358
- slippageTolerance?: bigint;
359
- /** Vault V1 inputs are deprecated for high-level Blue writes; prefer Vault V2. */
360
- targetReallocations?: BlueReallocationPlan;
361
- }) => {
362
- buildTx: (signatures?: readonly RequirementSignature[]) => Readonly<Transaction<BlueRefinanceAction>>;
363
- getRequirements: () => Promise<(Readonly<Transaction<ERC20ApprovalAction>> | Readonly<Transaction<BlueAuthorizationAction>> | Requirement)[]>;
364
- };
762
+ readonly reallocations?: Iterable<VaultV2BlueReallocation>;
763
+ readonly deadline: bigint;
764
+ readonly referralFeePct?: bigint;
765
+ readonly referralFeeRecipient?: Address;
766
+ }) => ActionOutput<BlueRefinanceAction, readonly RequirementSignature[], undefined>;
365
767
  /**
366
768
  * Fetches all on-chain data needed to construct a {@link VaultV1ReallocationData}
367
769
  * for computing vault reallocations via the public allocator.
@@ -372,9 +774,8 @@ export interface BlueActions {
372
774
  * inject unnecessary `reallocateTo` actions (and their PublicAllocator
373
775
  * fees) into the resulting bundle.
374
776
  *
375
- * The returned reallocation data can be passed to {@link getVaultV1Reallocations}
376
- * to compute the `VaultV1Reallocation[]` array for `borrow()` or
377
- * `supplyCollateralBorrow()`.
777
+ * The returned data can be passed to {@link getVaultV1Reallocations} for explicit low-level
778
+ * Bundler3 composition.
378
779
  *
379
780
  * **Stale data reverts on-chain (fail-safe).**
380
781
  *
@@ -400,8 +801,9 @@ export interface BlueActions {
400
801
  * @param params.block.timestamp - Timestamp corresponding to the fetched block.
401
802
  * @returns A `VaultV1ReallocationData` snapshot populated from one block.
402
803
  * @throws {ChainIdMismatchError} when the client chain does not match this market.
403
- * @deprecated Vault V1 shared-liquidity planning will be removed in the next major. Use
404
- * {@link getVaultV2BlueReallocationData}.
804
+ * @deprecated Use {@link getVaultV1ReallocationData} for deprecated low-level Bundler3
805
+ * planning. Vault V1 shared-liquidity planning will be removed in the next major; use
806
+ * {@link getVaultV2BlueReallocationData} for high-level Blue writes.
405
807
  */
406
808
  getReallocationData: (params: {
407
809
  vaultAddresses: readonly Address[];
@@ -453,8 +855,7 @@ export interface BlueActions {
453
855
  * @param params.options - Optional reallocation computation options
454
856
  * (timestamp, utilization targets, reallocatable vaults filter, etc.).
455
857
  * Pass the fetched block timestamp to compute reallocations at the same block.
456
- * @returns Array of vault reallocations ready to pass to `borrow()`, `supplyCollateralBorrow()`,
457
- * or `withdraw()`. Empty array if no reallocation is needed.
858
+ * @returns Vault V1 reallocations for explicit low-level Bundler3 composition.
458
859
  * @throws {ChainIdMismatchError} when `reallocationData` belongs to a different chain than this market.
459
860
  * @throws {InsufficientSharedLiquidityError} when shared liquidity cannot cover the operation's absolute shortfall on the target market — preventing fee-bearing reallocations from being attached to a call that would still revert onchain.
460
861
  * @throws {ReallocationWithdrawExceedsMarketSupplyError} when a withdrawal exceeds the target market supply.
@@ -480,7 +881,7 @@ export interface BlueActions {
480
881
  * @param params.amount - The borrow or withdraw amount used to compute post-state utilization.
481
882
  * @param params.borrowAmount - Deprecated borrow amount alias.
482
883
  * @param params.options - Optional allocator and utilization options.
483
- * @returns Vault V1 reallocations ready for a Blue action.
884
+ * @returns Vault V1 reallocations for explicit low-level Bundler3 composition.
484
885
  * @throws {ChainIdMismatchError} when `reallocationData` belongs to another chain.
485
886
  * @throws {InsufficientSharedLiquidityError} when shared liquidity cannot cover the operation.
486
887
  * @throws {ReallocationWithdrawExceedsMarketSupplyError} when a withdrawal exceeds market supply.
@@ -536,102 +937,133 @@ export declare class MorphoBlue implements BlueActions {
536
937
  readonly marketParams: MarketParams;
537
938
  private readonly chainId;
538
939
  constructor(client: MorphoClientType, marketParams: MarketParams, chainId: number);
539
- private getReallocationPenaltyRequirements;
940
+ private validateDeadline;
941
+ private validateWriteCommon;
942
+ private getMaxLtv;
943
+ private getBlueBundlesV1QuoteTimestamp;
944
+ private getTokenRequirements;
945
+ private getAuthorizationRequirements;
540
946
  getMarketData(parameters?: FetchParameters): Promise<Market>;
541
947
  getPositionData(userAddress: Address, parameters?: FetchParameters): Promise<AccrualPosition>;
542
- supply({ amount, userAddress, nativeAmount, marketData, slippageTolerance, }: {
543
- userAddress: Address;
544
- marketData: Market;
545
- slippageTolerance?: bigint;
546
- } & DepositAmountArgs): {
547
- getRequirements: (params?: {
548
- useSimplePermit?: boolean;
549
- }) => Promise<(import("../../index.js").Bundler3TokenSignatureRequirement | Readonly<Transaction<ERC20ApprovalAction>>)[]>;
550
- buildTx: (signatures?: readonly RequirementSignature[]) => Readonly<Transaction<BlueSupplyAction>>;
948
+ /** {@inheritDoc BlueActions.supply} */
949
+ supply(params: {
950
+ readonly userAddress: Address;
951
+ readonly assets: bigint;
952
+ readonly nativeAmount?: bigint;
953
+ readonly deadline: bigint;
954
+ readonly referralFeePct?: bigint;
955
+ readonly referralFeeRecipient?: Address;
956
+ }): {
957
+ getRequirements: (requirementsParams?: BlueTokenRequirementsParams) => Promise<readonly ActionRequirement[]>;
958
+ buildTx: (signatures?: readonly RequirementSignature[]) => Readonly<import("../../index.js").Transaction<BlueSupplyAction>>;
551
959
  };
960
+ /** {@inheritDoc BlueActions.withdraw} */
552
961
  withdraw(params: {
553
- userAddress: Address;
554
- receiver?: Address;
555
- positionData: AccrualPosition;
556
- slippageTolerance?: bigint;
557
- reallocations?: BlueReallocationPlan;
962
+ readonly userAddress: Address;
963
+ readonly positionData: AccrualPosition;
964
+ readonly reallocations?: Iterable<VaultV2BlueReallocation>;
965
+ readonly deadline: bigint;
966
+ readonly referralFeePct?: bigint;
967
+ readonly referralFeeRecipient?: Address;
558
968
  } & AssetsOrSharesArgs): {
559
- getRequirements: () => Promise<(import("../../index.js").Bundler3TokenSignatureRequirement | Readonly<Transaction<BlueAuthorizationAction>> | Readonly<Transaction<ERC20ApprovalAction>> | Requirement<import("../../index.js").AuthorizationRequirementSignature, undefined>)[]>;
560
- buildTx: (signatures?: readonly RequirementSignature[]) => Readonly<Transaction<BlueWithdrawAction>>;
561
- };
562
- supplyCollateral({ amount, userAddress, nativeAmount, }: {
563
- userAddress: Address;
564
- } & DepositAmountArgs): {
565
- getRequirements: (params?: {
566
- useSimplePermit?: boolean;
567
- }) => Promise<(import("../../index.js").Bundler3TokenSignatureRequirement | Readonly<Transaction<ERC20ApprovalAction>>)[]>;
568
- buildTx: (signatures?: readonly RequirementSignature[]) => Readonly<Transaction<BlueSupplyCollateralAction>>;
569
- };
570
- borrow({ amount, userAddress, positionData, slippageTolerance, reallocations, }: {
571
- amount: bigint;
572
- userAddress: Address;
573
- positionData: AccrualPosition;
574
- slippageTolerance?: bigint;
575
- reallocations?: BlueReallocationPlan;
576
- }): {
577
- getRequirements: () => Promise<(import("../../index.js").Bundler3TokenSignatureRequirement | Readonly<Transaction<BlueAuthorizationAction>> | Readonly<Transaction<ERC20ApprovalAction>> | Requirement<import("../../index.js").AuthorizationRequirementSignature, undefined>)[]>;
578
- buildTx: (signatures?: readonly RequirementSignature[]) => Readonly<Transaction<BlueBorrowAction>>;
969
+ getRequirements: () => Promise<readonly ActionRequirement[]>;
970
+ buildTx: (signatures?: readonly RequirementSignature[]) => Readonly<import("../../index.js").Transaction<BlueWithdrawAction>>;
579
971
  };
972
+ /** {@inheritDoc BlueActions.supplyCollateral} */
973
+ supplyCollateral(params: {
974
+ readonly userAddress: Address;
975
+ readonly collateralAssets: bigint;
976
+ readonly nativeAmount?: bigint;
977
+ readonly deadline: bigint;
978
+ readonly referralFeePct?: bigint;
979
+ readonly referralFeeRecipient?: Address;
980
+ }): ActionOutput<BlueSupplyCollateralAction, readonly RequirementSignature[], BlueTokenRequirementsParams>;
981
+ /** {@inheritDoc BlueActions.borrow} */
982
+ borrow(params: {
983
+ readonly userAddress: Address;
984
+ readonly borrowAssets: bigint;
985
+ readonly positionData: AccrualPosition;
986
+ readonly reallocations?: Iterable<VaultV2BlueReallocation>;
987
+ readonly deadline: bigint;
988
+ readonly referralFeePct?: bigint;
989
+ readonly referralFeeRecipient?: Address;
990
+ }): ActionOutput<BlueBorrowAction, readonly RequirementSignature[], undefined>;
991
+ /** {@inheritDoc BlueActions.repay} */
580
992
  repay(params: {
581
- userAddress: Address;
582
- positionData: AccrualPosition;
583
- slippageTolerance?: bigint;
584
- } & RepayAmountArgs): {
585
- getRequirements: (reqParams?: {
586
- useSimplePermit?: boolean;
587
- }) => Promise<(import("../../index.js").Bundler3TokenSignatureRequirement | Readonly<Transaction<ERC20ApprovalAction>>)[]>;
588
- buildTx: (signatures?: readonly RequirementSignature[]) => Readonly<Transaction<BlueRepayAction>>;
589
- };
590
- withdrawCollateral({ userAddress, amount, positionData, }: {
591
- userAddress: Address;
592
- amount: bigint;
593
- positionData: AccrualPosition;
594
- }): {
595
- buildTx: () => Readonly<Transaction<BlueWithdrawCollateralAction>>;
596
- };
993
+ readonly userAddress: Address;
994
+ readonly positionData: AccrualPosition;
995
+ readonly nativeAmount?: bigint;
996
+ readonly deadline: bigint;
997
+ readonly referralFeePct?: bigint;
998
+ readonly referralFeeRecipient?: Address;
999
+ } & ({
1000
+ readonly repayAssets: bigint;
1001
+ readonly repayShares?: never;
1002
+ } | {
1003
+ readonly repayShares: bigint;
1004
+ readonly repayAssets?: never;
1005
+ })): ActionOutput<BlueRepayAction, readonly RequirementSignature[], BlueTokenRequirementsParams>;
1006
+ /** {@inheritDoc BlueActions.withdrawCollateral} */
1007
+ withdrawCollateral(params: {
1008
+ readonly userAddress: Address;
1009
+ readonly positionData: AccrualPosition;
1010
+ readonly collateralAssets: bigint;
1011
+ readonly deadline: bigint;
1012
+ readonly referralFeePct?: bigint;
1013
+ readonly referralFeeRecipient?: Address;
1014
+ }): ActionOutput<BlueWithdrawCollateralAction, readonly RequirementSignature[], undefined>;
1015
+ /** {@inheritDoc BlueActions.repayWithdrawCollateral} */
597
1016
  repayWithdrawCollateral(params: {
598
- userAddress: Address;
599
- withdrawAmount: bigint;
600
- positionData: AccrualPosition;
601
- slippageTolerance?: bigint;
602
- } & RepayAmountArgs): {
603
- getRequirements: (reqParams?: {
604
- useSimplePermit?: boolean;
605
- }) => Promise<(import("../../index.js").Bundler3TokenSignatureRequirement | Readonly<Transaction<BlueAuthorizationAction>> | Readonly<Transaction<ERC20ApprovalAction>> | Requirement<import("../../index.js").AuthorizationRequirementSignature, undefined>)[]>;
606
- buildTx: (signatures?: readonly RequirementSignature[]) => Readonly<Transaction<BlueRepayWithdrawCollateralAction>>;
1017
+ readonly userAddress: Address;
1018
+ readonly positionData: AccrualPosition;
1019
+ readonly collateralAssets: bigint;
1020
+ readonly nativeAmount?: bigint;
1021
+ readonly deadline: bigint;
1022
+ readonly referralFeePct?: bigint;
1023
+ readonly referralFeeRecipient?: Address;
1024
+ } & ({
1025
+ readonly repayAssets: bigint;
1026
+ readonly repayShares?: never;
1027
+ } | {
1028
+ readonly repayShares: bigint;
1029
+ readonly repayAssets?: never;
1030
+ } | {
1031
+ readonly repayAssets?: undefined;
1032
+ readonly repayShares?: undefined;
1033
+ })): {
1034
+ getRequirements: (requirementsParams?: BlueTokenRequirementsParams) => Promise<readonly ActionRequirement[]>;
1035
+ buildTx: (signatures?: readonly RequirementSignature[]) => Readonly<import("../../index.js").Transaction<BlueRepayWithdrawCollateralAction>>;
607
1036
  };
608
- supplyCollateralBorrow({ amount, userAddress, positionData, borrowAmount, nativeAmount, slippageTolerance, reallocations, }: {
609
- userAddress: Address;
610
- positionData: AccrualPosition;
611
- borrowAmount: bigint;
612
- slippageTolerance?: bigint;
613
- reallocations?: BlueReallocationPlan;
614
- } & DepositAmountArgs): {
615
- getRequirements: (params?: {
616
- useSimplePermit?: boolean;
617
- }) => Promise<(import("../../index.js").Bundler3TokenSignatureRequirement | Readonly<Transaction<BlueAuthorizationAction>> | Readonly<Transaction<ERC20ApprovalAction>> | Requirement<import("../../index.js").AuthorizationRequirementSignature, undefined>)[]>;
618
- buildTx: (signatures?: readonly RequirementSignature[]) => Readonly<Transaction<BlueSupplyCollateralBorrowAction>>;
1037
+ /** {@inheritDoc BlueActions.supplyCollateralBorrow} */
1038
+ supplyCollateralBorrow(params: {
1039
+ readonly userAddress: Address;
1040
+ readonly collateralAssets: bigint;
1041
+ readonly borrowAssets: bigint;
1042
+ readonly positionData?: AccrualPosition;
1043
+ readonly nativeAmount?: bigint;
1044
+ readonly reallocations?: Iterable<VaultV2BlueReallocation>;
1045
+ readonly deadline: bigint;
1046
+ readonly referralFeePct?: bigint;
1047
+ readonly referralFeeRecipient?: Address;
1048
+ }): {
1049
+ getRequirements: (requirementsParams?: BlueTokenRequirementsParams) => Promise<readonly ActionRequirement[]>;
1050
+ buildTx: (signatures?: readonly RequirementSignature[]) => Readonly<import("../../index.js").Transaction<BlueSupplyCollateralBorrowAction>>;
619
1051
  };
620
- refinance({ userAddress, positionData, target, collateralAmount, borrowAssets, borrowShares, slippageTolerance, targetReallocations, }: {
621
- userAddress: Address;
622
- positionData: AccrualPosition;
623
- target: {
624
- marketParams: MarketParams;
625
- positionData: AccrualPosition;
1052
+ /** {@inheritDoc BlueActions.refinance} */
1053
+ refinance(params: {
1054
+ readonly userAddress: Address;
1055
+ readonly positionData: AccrualPosition;
1056
+ readonly destination: {
1057
+ readonly marketParams: MarketParams;
1058
+ readonly positionData: AccrualPosition;
626
1059
  };
627
- collateralAmount: bigint;
628
- borrowAssets?: bigint;
629
- borrowShares?: bigint;
630
- slippageTolerance?: bigint;
631
- targetReallocations?: BlueReallocationPlan;
1060
+ readonly reallocations?: Iterable<VaultV2BlueReallocation>;
1061
+ readonly deadline: bigint;
1062
+ readonly referralFeePct?: bigint;
1063
+ readonly referralFeeRecipient?: Address;
632
1064
  }): {
633
- getRequirements: () => Promise<(import("../../index.js").Bundler3TokenSignatureRequirement | Readonly<Transaction<BlueAuthorizationAction>> | Readonly<Transaction<ERC20ApprovalAction>> | Requirement<import("../../index.js").AuthorizationRequirementSignature, undefined>)[]>;
634
- buildTx: (signatures?: readonly RequirementSignature[]) => Readonly<Transaction<BlueRefinanceAction>>;
1065
+ getRequirements: () => Promise<readonly ActionRequirement[]>;
1066
+ buildTx: (signatures?: readonly RequirementSignature[]) => Readonly<import("../../index.js").Transaction<BlueRefinanceAction>>;
635
1067
  };
636
1068
  /**
637
1069
  * Fetches all on-chain inputs needed to compute public allocator reallocations.
@@ -747,7 +1179,7 @@ export declare class MorphoBlue implements BlueActions {
747
1179
  * @param params.amount - The borrow or withdraw amount used to compute the post-state utilization.
748
1180
  * @param params.borrowAmount - {@deprecated Pass `{ operation: "borrow", amount }` instead.}
749
1181
  * @param params.options - Optional allocator and utilization options.
750
- * @returns Vault reallocations ready to pass to `borrow`, `supplyCollateralBorrow`, or `withdraw`.
1182
+ * @returns Vault V1 reallocations for explicit low-level Bundler3 composition.
751
1183
  * @throws {ChainIdMismatchError} when `reallocationData` belongs to a different chain than this market.
752
1184
  * @throws {InsufficientSharedLiquidityError} when shared liquidity cannot cover the operation's absolute shortfall on the target market.
753
1185
  * @throws {ReallocationWithdrawExceedsMarketSupplyError} when `operation === "withdraw"` and `amount` exceeds the target market's `totalSupplyAssets`.
@@ -773,7 +1205,7 @@ export declare class MorphoBlue implements BlueActions {
773
1205
  * @param params.amount - The borrow or withdraw amount used to compute post-state utilization.
774
1206
  * @param params.borrowAmount - Deprecated borrow amount alias.
775
1207
  * @param params.options - Optional allocator and utilization options.
776
- * @returns Vault V1 reallocations ready for a Blue action.
1208
+ * @returns Vault V1 reallocations for explicit low-level Bundler3 composition.
777
1209
  * @throws {ChainIdMismatchError} when `reallocationData` belongs to another chain.
778
1210
  * @throws {InsufficientSharedLiquidityError} when shared liquidity cannot cover the operation.
779
1211
  * @throws {ReallocationWithdrawExceedsMarketSupplyError} when a withdrawal exceeds market supply.