@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,101 +1,90 @@
1
1
  import type { MarketParams } from "@morpho-org/blue-sdk";
2
- import type { Address } from "viem";
3
- import { type AuthorizationRequirementSignature, type BlueReallocationPlan, type BlueWithdrawAction, type Metadata, type Transaction } from "../../types/index.js";
2
+ import { type Address } from "viem";
3
+ import { type AuthorizationRequirementSignature, type BlueWithdrawAction, type Metadata, type Transaction, type VaultV2BlueReallocation } from "../../types/index.js";
4
4
  /** Parameters for {@link blueWithdraw}. */
5
5
  export interface BlueWithdrawParams {
6
- market: {
6
+ /** Chain and scoped Morpho Blue market. */
7
+ readonly market: {
7
8
  readonly chainId: number;
8
9
  readonly marketParams: MarketParams;
9
10
  };
10
- args: {
11
- /** Withdraw assets amount (`0n` when withdrawing by shares). */
12
- assets: bigint;
13
- /** Withdraw shares amount (`0n` when withdrawing by assets). */
14
- shares: bigint;
15
- /** Address that receives the withdrawn assets. */
16
- receiver: Address;
17
- /** Minimum withdraw share price (in ray). Slippage protection. */
18
- minSharePrice: bigint;
19
- /**
20
- * Homogeneous Vault V1 or Vault V2 reallocations to execute before withdrawing. V1 entries can be
21
- * computed via `MorphoBlue.getVaultV1Reallocations({ operation: "withdraw", amount })` or directly
22
- * via `computeVaultV1Reallocations({ operation: "withdraw", amount, ... })`.
23
- * Vault V1 inputs are deprecated for high-level Blue writes; use Vault V2 for new integrations.
24
- */
25
- reallocations?: BlueReallocationPlan;
26
- /**
27
- * Optional signed Morpho authorization. When provided, a `setAuthorizationWithSig` call is
28
- * prepended to the bundle so GeneralAdapter1 is authorized in-bundle instead of via a
29
- * standalone `setAuthorization` transaction.
30
- */
31
- authorizationSignature?: AuthorizationRequirementSignature;
11
+ /** Direct BlueBundlesV1 withdrawal arguments. */
12
+ readonly args: {
13
+ /** User whose supply position is withdrawn. */
14
+ readonly userAddress: Address;
15
+ /** Exact loan assets withdrawn, exclusive with `withdrawShares`. */
16
+ readonly withdrawAssets: bigint;
17
+ /** Exact supply shares burned, exclusive with `withdrawAssets`. */
18
+ readonly withdrawShares: bigint;
19
+ /** Optional validated Vault V2 BluePublicAllocator reallocations. */
20
+ readonly reallocations?: Iterable<VaultV2BlueReallocation>;
21
+ /** Final call deadline in Unix seconds. */
22
+ readonly deadline: bigint;
23
+ /** Optional WAD-scaled referral fee, strictly below 100%. */
24
+ readonly referralFeePct?: bigint;
25
+ /** Recipient required when `referralFeePct` is positive. */
26
+ readonly referralFeeRecipient?: Address;
27
+ /** Optional Morpho authorization signature for BlueBundlesV1. */
28
+ readonly authorizationSignature?: AuthorizationRequirementSignature;
32
29
  };
33
- metadata?: Metadata;
30
+ /** Optional transaction metadata suffix. */
31
+ readonly metadata?: Metadata;
34
32
  }
35
33
  /**
36
- * Prepares a loan-asset withdraw transaction for a Morpho Blue market.
34
+ * Encodes a direct BlueBundlesV1 loan-asset withdrawal transaction.
37
35
  *
38
- * Routed through bundler3 via `morphoWithdraw`. Supports two modes (exactly one):
36
+ * Vault V2 allocator penalties and referral fees reduce the assets received. Shares mode has no
37
+ * saturated full-close sentinel or onchain minimum-assets guarantee, and this route has no
38
+ * Bundler3 share-price bound or `slippageTolerance` input.
39
39
  *
40
- * - **By assets** (`assets > 0, shares = 0`): withdraws an exact asset amount.
41
- * - **By shares** (`assets = 0, shares > 0`): burns an exact share count (typical for a full
42
- * supplier position close; immune to interest accrual between tx construction and execution).
43
- *
44
- * A `reallocations` plan contains either V1 entries or V2 market/idle entries,
45
- * never both. The calls run before the withdraw. V1
46
- * fees accumulate in `tx.value`; V2 penalties are paid in the target loan
47
- * token and donated to the vaults. The on-chain `morphoWithdraw` sends the
48
- * assets computed on-chain directly to `receiver`; no skim is required.
49
- *
50
- * The withdraw is performed on behalf of the transaction initiator (signer) — there is no
51
- * separate `onBehalf` field; mirror `blueBorrow`. The entity layer keeps `receiver` aligned
52
- * with the user when none is provided. Requires the user to have authorized `GeneralAdapter1`
53
- * on Morpho.
54
- *
55
- * @param params.market.chainId - The chain the market lives on.
56
- * @param params.market.marketParams - Market params (loanToken, collateralToken, oracle, irm, lltv).
57
- * @param params.args.assets - Withdraw amount in loan-token assets. Set to `0n` in shares mode.
58
- * @param params.args.shares - Withdraw amount in supply shares. Set to `0n` in assets mode.
59
- * @param params.args.receiver - Address that receives the withdrawn assets.
60
- * @param params.args.minSharePrice - Minimum acceptable withdraw share price (in ray). Slippage
61
- * protection.
62
- * @param params.args.reallocations - Optional homogeneous Vault V1 or Vault V2 reallocations to
63
- * execute before withdrawing. Vault V1 inputs are deprecated; use Vault V2 for new integrations.
64
- * @param params.args.authorizationSignature - Optional signed Morpho authorization; when present,
65
- * a `setAuthorizationWithSig` call is prepended to the bundle.
66
- * @param params.metadata - Optional analytics metadata attached to the bundle.
67
- * @returns A deep-frozen `Transaction<BlueWithdrawAction>` with `to`, `value`, `data`, and
68
- * the typed `action` discriminator the simulation layer consumes.
69
- * @throws {NegativeInputError} when `assets`, `shares`, `minSharePrice`, a V1 fee, or a V2
70
- * penalty is negative.
71
- * @throws {NonPositiveInputError} when both `assets` and `shares` are zero or any reallocation
72
- * withdrawal amount is non-positive.
73
- * @throws {InputExceedsMaxError} when a V2 reallocation asset amount exceeds `uint128` or its penalty exceeds WAD.
74
- * @throws {InconsistentReallocationPenaltyError} when V2 entries for one vault use different penalties.
75
- * @throws {InvalidReallocationAddressError} when a V2 vault or adapter address is malformed.
76
- * @throws {InvalidReallocationSourceTypeError} when a V2 source is absent, incomplete, or has an unknown discriminator.
77
- * @throws {InvalidReallocationShapeError} when an entry matches both or neither V1/V2 shape.
78
- * @throws {MixedReallocationVersionsError} when one plan contains both V1 and V2 entries.
79
- * @throws {MutuallyExclusiveWithdrawAmountsError} when both `assets` and `shares` are non-zero.
80
- * @throws {EmptyReallocationWithdrawalsError} when any reallocation has no withdrawals.
81
- * @throws {ReallocationWithdrawalOnTargetMarketError} when a reallocation withdrawal references
82
- * the target market.
83
- * @throws {UnsortedReallocationWithdrawalsError} when reallocation withdrawals are not strictly
84
- * sorted by market id.
40
+ * @param params - Withdrawal encoding parameters.
41
+ * @param params.market.chainId - Chain containing BlueBundlesV1.
42
+ * @param params.market.marketParams - Scoped Morpho Blue market parameters.
43
+ * @param params.args.userAddress - User whose supply position is withdrawn.
44
+ * @param params.args.withdrawAssets - Exact assets withdrawn, exclusive with shares.
45
+ * @param params.args.withdrawShares - Exact shares burned, exclusive with assets.
46
+ * @param params.args.reallocations - Vault V2 reallocations executed before withdrawal.
47
+ * @param params.args.deadline - Final call deadline in Unix seconds.
48
+ * @param params.args.referralFeePct - Optional WAD-scaled fee below 100%.
49
+ * @param params.args.referralFeeRecipient - Recipient required for a positive fee.
50
+ * @param params.args.authorizationSignature - Optional Blue authorization signature.
51
+ * @param params.metadata - Optional transaction metadata.
52
+ * @returns A deep-frozen `Readonly<Transaction<BlueWithdrawAction>>` whose `to` address is
53
+ * BlueBundlesV1 and whose `action` records the normalized withdrawal inputs.
54
+ * @throws {NegativeInputError} when an amount, fee, or reallocation penalty is negative.
55
+ * @throws {MutuallyExclusiveWithdrawAmountsError} when assets and shares are both nonzero.
56
+ * @throws {NonPositiveInputError} when neither mode, no valid deadline, or a non-positive
57
+ * reallocation amount is provided.
58
+ * @throws {InputExceedsMaxError} when a withdraw amount, fee, reallocation amount, or penalty exceeds its ABI bound.
59
+ * @throws {MissingReferralFeeRecipientError} when a positive fee has no recipient.
60
+ * @throws {InvalidReallocationAddressError} when a vault or adapter address is malformed.
61
+ * @throws {InvalidReallocationShapeError} when a reallocation entry is not a valid Vault V2 reallocation.
62
+ * @throws {InvalidReallocationSourceTypeError} when a reallocation source is malformed.
63
+ * @throws {InconsistentReallocationPenaltyError} when one vault uses different penalties.
64
+ * @throws {ReallocationWithdrawalOnTargetMarketError} when a source is the target market.
65
+ * @throws {ReallocationLoanTokenMismatchError} when a source market uses another loan token.
66
+ * @throws {DepositOwnerMismatchError} when the signed authorization owner differs from `userAddress`.
67
+ * @throws {BundlesRequirementSignatureMismatchError} when authorization cannot be bound safely.
68
+ * @throws {UnsupportedChainIdError} when the chain is absent from the registry.
69
+ * @throws {UnknownAddressError} when BlueBundlesV1 is not registered.
85
70
  * @example
86
71
  * ```ts
72
+ * import { markets } from "@morpho-org/morpho-test";
87
73
  * import { blueWithdraw } from "@morpho-org/morpho-sdk";
74
+ * import { zeroAddress } from "viem";
75
+ * import { mainnet } from "viem/chains";
88
76
  *
77
+ * const marketParams = markets[mainnet.id].usdc_wbtc;
89
78
  * const tx = blueWithdraw({
90
- * market: { chainId: 1, marketParams },
79
+ * market: { chainId: mainnet.id, marketParams },
91
80
  * args: {
92
- * assets: 1_000_000_000n,
93
- * shares: 0n,
94
- * receiver: supplier,
95
- * minSharePrice: 0n, // disables slippage protection — production code should compute via `computeMinWithdrawSharePrice` from market state + slippage tolerance
81
+ * userAddress: zeroAddress,
82
+ * withdrawAssets: 1_000_000n,
83
+ * withdrawShares: 0n,
84
+ * deadline: 1_900_000_000n,
96
85
  * },
97
86
  * });
98
87
  * // tx satisfies Readonly<Transaction<BlueWithdrawAction>>
99
88
  * ```
100
89
  */
101
- export declare const blueWithdraw: ({ market: { chainId, marketParams }, args: { assets, shares, receiver, minSharePrice, reallocations, authorizationSignature, }, metadata, }: BlueWithdrawParams) => Readonly<Transaction<BlueWithdrawAction>>;
90
+ export declare const blueWithdraw: (params: BlueWithdrawParams) => Readonly<Transaction<BlueWithdrawAction>>;
@@ -1,124 +1,128 @@
1
- import { deepFreeze } from "@morpho-org/morpho-ts";
2
- import { BundlerAction } from "../../bundler/index.js";
3
- import { addTransactionMetadata } from "../../helpers/index.js";
4
- import { MutuallyExclusiveWithdrawAmountsError, NegativeInputError, NonPositiveInputError, } from "../../types/index.js";
5
- import { getBlueAuthorizationAction } from "../signatures/getBlueAuthorizationAction.js";
6
- import { buildBlueReallocationActions } from "./buildReallocationActions.js";
1
+ import { encodeFunctionData } from "viem";
2
+ import { blueBundlesV1Abi } from "../../abis.js";
3
+ import { validateUint256Field } from "../../helpers/validate.js";
4
+ import { InputExceedsMaxError, MutuallyExclusiveWithdrawAmountsError, NonPositiveInputError, } from "../../types/index.js";
5
+ import { finalizeBlueBundlesV1Transaction, getBlueBundlesV1PenaltyAssets, getBlueBundlesV1PublicAllocations, getBlueBundlesV1SignedAuthorization, normalizeBlueBundlesV1CommonParams, } from "./common.js";
7
6
  /**
8
- * Prepares a loan-asset withdraw transaction for a Morpho Blue market.
7
+ * Encodes a direct BlueBundlesV1 loan-asset withdrawal transaction.
9
8
  *
10
- * Routed through bundler3 via `morphoWithdraw`. Supports two modes (exactly one):
9
+ * Vault V2 allocator penalties and referral fees reduce the assets received. Shares mode has no
10
+ * saturated full-close sentinel or onchain minimum-assets guarantee, and this route has no
11
+ * Bundler3 share-price bound or `slippageTolerance` input.
11
12
  *
12
- * - **By assets** (`assets > 0, shares = 0`): withdraws an exact asset amount.
13
- * - **By shares** (`assets = 0, shares > 0`): burns an exact share count (typical for a full
14
- * supplier position close; immune to interest accrual between tx construction and execution).
15
- *
16
- * A `reallocations` plan contains either V1 entries or V2 market/idle entries,
17
- * never both. The calls run before the withdraw. V1
18
- * fees accumulate in `tx.value`; V2 penalties are paid in the target loan
19
- * token and donated to the vaults. The on-chain `morphoWithdraw` sends the
20
- * assets computed on-chain directly to `receiver`; no skim is required.
21
- *
22
- * The withdraw is performed on behalf of the transaction initiator (signer) — there is no
23
- * separate `onBehalf` field; mirror `blueBorrow`. The entity layer keeps `receiver` aligned
24
- * with the user when none is provided. Requires the user to have authorized `GeneralAdapter1`
25
- * on Morpho.
26
- *
27
- * @param params.market.chainId - The chain the market lives on.
28
- * @param params.market.marketParams - Market params (loanToken, collateralToken, oracle, irm, lltv).
29
- * @param params.args.assets - Withdraw amount in loan-token assets. Set to `0n` in shares mode.
30
- * @param params.args.shares - Withdraw amount in supply shares. Set to `0n` in assets mode.
31
- * @param params.args.receiver - Address that receives the withdrawn assets.
32
- * @param params.args.minSharePrice - Minimum acceptable withdraw share price (in ray). Slippage
33
- * protection.
34
- * @param params.args.reallocations - Optional homogeneous Vault V1 or Vault V2 reallocations to
35
- * execute before withdrawing. Vault V1 inputs are deprecated; use Vault V2 for new integrations.
36
- * @param params.args.authorizationSignature - Optional signed Morpho authorization; when present,
37
- * a `setAuthorizationWithSig` call is prepended to the bundle.
38
- * @param params.metadata - Optional analytics metadata attached to the bundle.
39
- * @returns A deep-frozen `Transaction<BlueWithdrawAction>` with `to`, `value`, `data`, and
40
- * the typed `action` discriminator the simulation layer consumes.
41
- * @throws {NegativeInputError} when `assets`, `shares`, `minSharePrice`, a V1 fee, or a V2
42
- * penalty is negative.
43
- * @throws {NonPositiveInputError} when both `assets` and `shares` are zero or any reallocation
44
- * withdrawal amount is non-positive.
45
- * @throws {InputExceedsMaxError} when a V2 reallocation asset amount exceeds `uint128` or its penalty exceeds WAD.
46
- * @throws {InconsistentReallocationPenaltyError} when V2 entries for one vault use different penalties.
47
- * @throws {InvalidReallocationAddressError} when a V2 vault or adapter address is malformed.
48
- * @throws {InvalidReallocationSourceTypeError} when a V2 source is absent, incomplete, or has an unknown discriminator.
49
- * @throws {InvalidReallocationShapeError} when an entry matches both or neither V1/V2 shape.
50
- * @throws {MixedReallocationVersionsError} when one plan contains both V1 and V2 entries.
51
- * @throws {MutuallyExclusiveWithdrawAmountsError} when both `assets` and `shares` are non-zero.
52
- * @throws {EmptyReallocationWithdrawalsError} when any reallocation has no withdrawals.
53
- * @throws {ReallocationWithdrawalOnTargetMarketError} when a reallocation withdrawal references
54
- * the target market.
55
- * @throws {UnsortedReallocationWithdrawalsError} when reallocation withdrawals are not strictly
56
- * sorted by market id.
13
+ * @param params - Withdrawal encoding parameters.
14
+ * @param params.market.chainId - Chain containing BlueBundlesV1.
15
+ * @param params.market.marketParams - Scoped Morpho Blue market parameters.
16
+ * @param params.args.userAddress - User whose supply position is withdrawn.
17
+ * @param params.args.withdrawAssets - Exact assets withdrawn, exclusive with shares.
18
+ * @param params.args.withdrawShares - Exact shares burned, exclusive with assets.
19
+ * @param params.args.reallocations - Vault V2 reallocations executed before withdrawal.
20
+ * @param params.args.deadline - Final call deadline in Unix seconds.
21
+ * @param params.args.referralFeePct - Optional WAD-scaled fee below 100%.
22
+ * @param params.args.referralFeeRecipient - Recipient required for a positive fee.
23
+ * @param params.args.authorizationSignature - Optional Blue authorization signature.
24
+ * @param params.metadata - Optional transaction metadata.
25
+ * @returns A deep-frozen `Readonly<Transaction<BlueWithdrawAction>>` whose `to` address is
26
+ * BlueBundlesV1 and whose `action` records the normalized withdrawal inputs.
27
+ * @throws {NegativeInputError} when an amount, fee, or reallocation penalty is negative.
28
+ * @throws {MutuallyExclusiveWithdrawAmountsError} when assets and shares are both nonzero.
29
+ * @throws {NonPositiveInputError} when neither mode, no valid deadline, or a non-positive
30
+ * reallocation amount is provided.
31
+ * @throws {InputExceedsMaxError} when a withdraw amount, fee, reallocation amount, or penalty exceeds its ABI bound.
32
+ * @throws {MissingReferralFeeRecipientError} when a positive fee has no recipient.
33
+ * @throws {InvalidReallocationAddressError} when a vault or adapter address is malformed.
34
+ * @throws {InvalidReallocationShapeError} when a reallocation entry is not a valid Vault V2 reallocation.
35
+ * @throws {InvalidReallocationSourceTypeError} when a reallocation source is malformed.
36
+ * @throws {InconsistentReallocationPenaltyError} when one vault uses different penalties.
37
+ * @throws {ReallocationWithdrawalOnTargetMarketError} when a source is the target market.
38
+ * @throws {ReallocationLoanTokenMismatchError} when a source market uses another loan token.
39
+ * @throws {DepositOwnerMismatchError} when the signed authorization owner differs from `userAddress`.
40
+ * @throws {BundlesRequirementSignatureMismatchError} when authorization cannot be bound safely.
41
+ * @throws {UnsupportedChainIdError} when the chain is absent from the registry.
42
+ * @throws {UnknownAddressError} when BlueBundlesV1 is not registered.
57
43
  * @example
58
44
  * ```ts
45
+ * import { markets } from "@morpho-org/morpho-test";
59
46
  * import { blueWithdraw } from "@morpho-org/morpho-sdk";
47
+ * import { zeroAddress } from "viem";
48
+ * import { mainnet } from "viem/chains";
60
49
  *
50
+ * const marketParams = markets[mainnet.id].usdc_wbtc;
61
51
  * const tx = blueWithdraw({
62
- * market: { chainId: 1, marketParams },
52
+ * market: { chainId: mainnet.id, marketParams },
63
53
  * args: {
64
- * assets: 1_000_000_000n,
65
- * shares: 0n,
66
- * receiver: supplier,
67
- * minSharePrice: 0n, // disables slippage protection — production code should compute via `computeMinWithdrawSharePrice` from market state + slippage tolerance
54
+ * userAddress: zeroAddress,
55
+ * withdrawAssets: 1_000_000n,
56
+ * withdrawShares: 0n,
57
+ * deadline: 1_900_000_000n,
68
58
  * },
69
59
  * });
70
60
  * // tx satisfies Readonly<Transaction<BlueWithdrawAction>>
71
61
  * ```
72
62
  */
73
- export const blueWithdraw = ({ market: { chainId, marketParams }, args: { assets, shares, receiver, minSharePrice, reallocations, authorizationSignature, }, metadata, }) => {
74
- // Mutual exclusion is detected on "both values present" (either non-zero),
75
- // before sign checks — otherwise `{ assets: -1n, shares: 5n }` would be
76
- // misreported as a positivity error rather than the actual mode conflict.
77
- if (assets !== 0n && shares !== 0n) {
63
+ export const blueWithdraw = (params) => {
64
+ const { chainId, marketParams } = params.market;
65
+ const { userAddress, withdrawAssets, withdrawShares, authorizationSignature, } = params.args;
66
+ validateUint256Field("withdrawAssets", withdrawAssets);
67
+ validateUint256Field("withdrawShares", withdrawShares);
68
+ if (withdrawAssets > 0n && withdrawShares > 0n) {
78
69
  throw new MutuallyExclusiveWithdrawAmountsError(marketParams.id);
79
70
  }
80
- if (assets < 0n) {
81
- throw new NegativeInputError("assets", assets);
82
- }
83
- if (shares < 0n) {
84
- throw new NegativeInputError("shares", shares);
85
- }
86
- if (assets === 0n && shares === 0n) {
87
- throw new NonPositiveInputError("assets or shares", 0n);
71
+ if (withdrawAssets === 0n && withdrawShares === 0n) {
72
+ throw new NonPositiveInputError("withdrawAssets or withdrawShares", 0n);
88
73
  }
89
- if (minSharePrice < 0n) {
90
- throw new NegativeInputError("minSharePrice", minSharePrice);
91
- }
92
- const actions = [];
93
- if (authorizationSignature) {
94
- actions.push(getBlueAuthorizationAction(chainId, authorizationSignature));
95
- }
96
- const { actions: reallocationActions, fee: reallocationFee, penaltyAssets: reallocationPenaltyAssets, } = buildBlueReallocationActions({
74
+ const common = {
97
75
  chainId,
98
- reallocations,
99
- targetMarketParams: marketParams,
100
- });
101
- actions.push(...reallocationActions);
102
- actions.push({
103
- type: "morphoWithdraw",
104
- args: [marketParams, assets, shares, minSharePrice, receiver, false],
76
+ userAddress,
77
+ deadline: params.args.deadline,
78
+ referralFeePct: params.args.referralFeePct,
79
+ referralFeeRecipient: params.args.referralFeeRecipient,
80
+ metadata: params.metadata,
81
+ };
82
+ const { referralFeePct, referralFeeRecipient } = normalizeBlueBundlesV1CommonParams(common);
83
+ const signedAuthorization = getBlueBundlesV1SignedAuthorization({
84
+ chainId,
85
+ userAddress,
86
+ authorizationSignature,
105
87
  });
106
- let tx = BundlerAction.encodeBundle(chainId, actions);
107
- if (metadata) {
108
- tx = addTransactionMetadata(tx, metadata);
88
+ const publicAllocations = getBlueBundlesV1PublicAllocations([...(params.args.reallocations ?? [])], marketParams);
89
+ const reallocationPenaltyAssets = getBlueBundlesV1PenaltyAssets(publicAllocations);
90
+ if (withdrawAssets > 0n && reallocationPenaltyAssets > withdrawAssets) {
91
+ throw new InputExceedsMaxError({
92
+ field: "reallocationPenaltyAssets",
93
+ value: reallocationPenaltyAssets,
94
+ max: withdrawAssets,
95
+ });
109
96
  }
110
- return deepFreeze({
111
- ...tx,
97
+ return finalizeBlueBundlesV1Transaction({
98
+ common,
99
+ value: 0n,
100
+ data: encodeFunctionData({
101
+ abi: blueBundlesV1Abi,
102
+ functionName: "blueBundlesV1Withdraw",
103
+ args: [
104
+ marketParams,
105
+ withdrawAssets,
106
+ withdrawShares,
107
+ signedAuthorization,
108
+ publicAllocations,
109
+ referralFeePct,
110
+ referralFeeRecipient,
111
+ params.args.deadline,
112
+ ],
113
+ }),
112
114
  action: {
113
115
  type: "blueWithdraw",
114
116
  args: {
115
117
  market: marketParams.id,
116
- assets,
117
- shares,
118
- receiver,
119
- minSharePrice,
120
- reallocationFee,
118
+ withdrawAssets,
119
+ withdrawShares,
120
+ onBehalf: userAddress,
121
+ reallocations: publicAllocations.length,
121
122
  reallocationPenaltyAssets,
123
+ referralFeePct,
124
+ referralFeeRecipient,
125
+ deadline: params.args.deadline,
122
126
  },
123
127
  },
124
128
  });
@@ -1,49 +1,77 @@
1
- import { type MarketParams } from "@morpho-org/blue-sdk";
2
- import { type Address } from "viem";
3
- import { type BlueWithdrawCollateralAction, type Metadata, type Transaction } from "../../types/index.js";
1
+ import type { MarketParams } from "@morpho-org/blue-sdk";
2
+ import type { Address } from "viem";
3
+ import type { AuthorizationRequirementSignature, BlueWithdrawCollateralAction, Metadata, Transaction } from "../../types/index.js";
4
4
  /** Parameters for {@link blueWithdrawCollateral}. */
5
5
  export interface BlueWithdrawCollateralParams {
6
- market: {
6
+ /** Chain and scoped Morpho Blue market. */
7
+ readonly market: {
7
8
  readonly chainId: number;
8
9
  readonly marketParams: MarketParams;
9
10
  };
10
- args: {
11
- amount: bigint;
12
- onBehalf: Address;
13
- receiver: Address;
11
+ /** Direct BlueBundlesV1 collateral-withdrawal arguments. */
12
+ readonly args: {
13
+ /** User whose collateral position is reduced. */
14
+ readonly userAddress: Address;
15
+ /** Collateral assets withdrawn. */
16
+ readonly collateralAssets: bigint;
17
+ /** Maximum post-operation LTV enforced by BlueBundlesV1. */
18
+ readonly maxLtv: bigint;
19
+ /** Final call deadline in Unix seconds. */
20
+ readonly deadline: bigint;
21
+ /** Optional WAD-scaled referral fee, strictly below 100%. */
22
+ readonly referralFeePct?: bigint;
23
+ /** Recipient required when `referralFeePct` is positive. */
24
+ readonly referralFeeRecipient?: Address;
25
+ /** Optional Morpho authorization signature for BlueBundlesV1. */
26
+ readonly authorizationSignature?: AuthorizationRequirementSignature;
14
27
  };
15
- metadata?: Metadata;
28
+ /** Optional transaction metadata suffix. */
29
+ readonly metadata?: Metadata;
16
30
  }
17
31
  /**
18
- * Prepares a withdraw-collateral transaction for a Morpho Blue market.
32
+ * Encodes a pure collateral withdrawal through BlueBundlesV1.
19
33
  *
20
- * Direct call to `Morpho.withdrawCollateral` — no bundler needed. Collateral flows out of Morpho,
21
- * so there is no inflation-attack surface requiring the bundler.
34
+ * Delegates to {@link blueRepayWithdrawCollateral} with a zero repay leg. BlueBundlesV1 enforces
35
+ * the supplied post-operation LTV, and no standalone Morpho or Bundler3 call is encoded.
22
36
  *
23
- * The caller (`msg.sender`) must be `onBehalf` or be authorized by them on Morpho.
24
- *
25
- * @param params.market.chainId - The chain the market lives on.
26
- * @param params.market.marketParams - Market params (loanToken, collateralToken, oracle, irm, lltv).
27
- * @param params.args.amount - Amount of collateral to withdraw.
28
- * @param params.args.onBehalf - Address whose Morpho position the collateral is withdrawn from.
29
- * @param params.args.receiver - Address that receives the withdrawn collateral.
30
- * @param params.metadata - Optional analytics metadata attached to the transaction.
31
- * @returns A deep-frozen `Transaction<BlueWithdrawCollateralAction>` with `to`, `value`,
32
- * `data`, and the typed `action` discriminator the simulation layer consumes.
33
- * @throws {NonPositiveInputError} when `amount <= 0n`.
37
+ * @param params - Collateral-withdrawal encoding parameters.
38
+ * @param params.market.chainId - Chain containing BlueBundlesV1.
39
+ * @param params.market.marketParams - Scoped Morpho Blue market parameters.
40
+ * @param params.args.userAddress - User whose collateral position is reduced.
41
+ * @param params.args.collateralAssets - Collateral assets withdrawn.
42
+ * @param params.args.maxLtv - Maximum post-operation LTV.
43
+ * @param params.args.deadline - Final call deadline in Unix seconds.
44
+ * @param params.args.referralFeePct - Optional WAD-scaled referral fee.
45
+ * @param params.args.referralFeeRecipient - Recipient required for a positive fee.
46
+ * @param params.args.authorizationSignature - Optional Blue authorization signature.
47
+ * @param params.metadata - Optional transaction metadata.
48
+ * @returns A deep-frozen `Readonly<Transaction<BlueWithdrawCollateralAction>>` whose calldata
49
+ * invokes the combined BlueBundlesV1 entrypoint with a zero repay leg.
50
+ * @throws {NegativeInputError} when collateral, LTV, or fee is negative.
51
+ * @throws {NonPositiveInputError} when collateral or deadline is not positive.
52
+ * @throws {InputExceedsMaxError} when the referral fee is at least WAD.
53
+ * @throws {MissingReferralFeeRecipientError} when a positive fee has no recipient.
54
+ * @throws {DepositOwnerMismatchError} when the signed authorization owner differs from `userAddress`.
55
+ * @throws {BundlesRequirementSignatureMismatchError} when authorization cannot be bound safely.
56
+ * @throws {UnsupportedChainIdError} when the chain is absent from the registry.
57
+ * @throws {UnknownAddressError} when BlueBundlesV1 is not registered.
34
58
  * @example
35
59
  * ```ts
60
+ * import { markets } from "@morpho-org/morpho-test";
36
61
  * import { blueWithdrawCollateral } from "@morpho-org/morpho-sdk";
62
+ * import { zeroAddress } from "viem";
63
+ * import { mainnet } from "viem/chains";
37
64
  *
38
65
  * const tx = blueWithdrawCollateral({
39
- * market: { chainId: 1, marketParams },
66
+ * market: { chainId: mainnet.id, marketParams: markets[mainnet.id].usdc_wbtc },
40
67
  * args: {
41
- * amount: 1_000_000_000_000_000_000n,
42
- * onBehalf: borrower,
43
- * receiver: borrower,
68
+ * userAddress: zeroAddress,
69
+ * collateralAssets: 1_000_000_000_000_000_000n,
70
+ * maxLtv: 850000000000000000n,
71
+ * deadline: 1_900_000_000n,
44
72
  * },
45
73
  * });
46
74
  * // tx satisfies Readonly<Transaction<BlueWithdrawCollateralAction>>
47
75
  * ```
48
76
  */
49
- export declare const blueWithdrawCollateral: ({ market: { chainId, marketParams }, args: { amount, onBehalf, receiver }, metadata, }: BlueWithdrawCollateralParams) => Readonly<Transaction<BlueWithdrawCollateralAction>>;
77
+ export declare const blueWithdrawCollateral: (params: BlueWithdrawCollateralParams) => Readonly<Transaction<BlueWithdrawCollateralAction>>;