@morpho-org/morpho-sdk 10.4.0 → 10.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (193) hide show
  1. package/lib/cjs/actions/blue/common.js +12 -3
  2. package/lib/cjs/actions/midnight/supplyCollateralTakeBorrow.js +16 -11
  3. package/lib/cjs/actions/midnight/takeBorrow.js +14 -8
  4. package/lib/cjs/actions/midnight/takeLend.js +15 -9
  5. package/lib/cjs/actions/midnight/takeRepayWithdrawCollateral.js +19 -13
  6. package/lib/cjs/actions/midnight/takeWithdraw.js +14 -8
  7. package/lib/cjs/constants.d.ts +1 -1
  8. package/lib/cjs/constants.js +3 -2
  9. package/lib/cjs/entities/midnight/midnight.d.ts +106 -103
  10. package/lib/cjs/entities/midnight/midnight.js +120 -101
  11. package/lib/cjs/entities/vaultV1/vaultV1.js +0 -1
  12. package/lib/cjs/entities/vaultV2/vaultV2.js +0 -1
  13. package/lib/cjs/helpers/constant.d.ts +7 -0
  14. package/lib/cjs/helpers/constant.js +8 -1
  15. package/lib/cjs/helpers/index.d.ts +1 -1
  16. package/lib/cjs/helpers/index.js +2 -1
  17. package/lib/cjs/helpers/validate.d.ts +25 -1
  18. package/lib/cjs/helpers/validate.js +25 -1
  19. package/lib/cjs/transactionPlan/assemble.d.ts +24 -0
  20. package/lib/cjs/transactionPlan/assemble.js +25 -0
  21. package/lib/cjs/transactionPlan/blue/borrow.js +14 -64
  22. package/lib/cjs/transactionPlan/blue/refinance.js +9 -11
  23. package/lib/cjs/transactionPlan/blue/repay.js +10 -24
  24. package/lib/cjs/transactionPlan/blue/repayWithdrawCollateral.js +49 -45
  25. package/lib/cjs/transactionPlan/blue/stored.d.ts +26 -0
  26. package/lib/cjs/transactionPlan/blue/stored.js +87 -0
  27. package/lib/cjs/transactionPlan/blue/supply.js +7 -22
  28. package/lib/cjs/transactionPlan/blue/supplyCollateral.d.ts +1 -1
  29. package/lib/cjs/transactionPlan/blue/supplyCollateral.js +10 -15
  30. package/lib/cjs/transactionPlan/blue/supplyCollateralBorrow.js +14 -64
  31. package/lib/cjs/transactionPlan/blue/withdraw.d.ts +2 -3
  32. package/lib/cjs/transactionPlan/blue/withdraw.js +67 -79
  33. package/lib/cjs/transactionPlan/blue/withdrawCollateral.d.ts +2 -3
  34. package/lib/cjs/transactionPlan/blue/withdrawCollateral.js +31 -30
  35. package/lib/cjs/transactionPlan/deposit.js +4 -7
  36. package/lib/cjs/transactionPlan/intent.d.ts +1 -1
  37. package/lib/cjs/transactionPlan/midnight/makeBorrow.d.ts +1 -1
  38. package/lib/cjs/transactionPlan/midnight/makeBorrow.js +1 -1
  39. package/lib/cjs/transactionPlan/midnight/makeLend.d.ts +1 -1
  40. package/lib/cjs/transactionPlan/midnight/makeLend.js +1 -1
  41. package/lib/cjs/transactionPlan/midnight/makeRepay.d.ts +1 -1
  42. package/lib/cjs/transactionPlan/midnight/makeRepay.js +1 -1
  43. package/lib/cjs/transactionPlan/midnight/repayWithdrawCollateral.d.ts +1 -1
  44. package/lib/cjs/transactionPlan/midnight/repayWithdrawCollateral.js +1 -1
  45. package/lib/cjs/transactionPlan/midnight/supplyBlueMakeLend.d.ts +1 -1
  46. package/lib/cjs/transactionPlan/midnight/supplyBlueMakeLend.js +1 -1
  47. package/lib/cjs/transactionPlan/midnight/supplyCollateral.d.ts +1 -1
  48. package/lib/cjs/transactionPlan/midnight/supplyCollateral.js +1 -1
  49. package/lib/cjs/transactionPlan/midnight/supplyCollateralBatch.d.ts +1 -1
  50. package/lib/cjs/transactionPlan/midnight/supplyCollateralBatch.js +1 -1
  51. package/lib/cjs/transactionPlan/midnight/supplyCollateralMakeBorrow.d.ts +1 -1
  52. package/lib/cjs/transactionPlan/midnight/supplyCollateralMakeBorrow.js +1 -1
  53. package/lib/cjs/transactionPlan/midnight/supplyCollateralWithNative.d.ts +1 -1
  54. package/lib/cjs/transactionPlan/midnight/supplyCollateralWithNative.js +1 -1
  55. package/lib/cjs/transactionPlan/midnight/takeBorrow.d.ts +6 -2
  56. package/lib/cjs/transactionPlan/midnight/takeBorrow.js +10 -4
  57. package/lib/cjs/transactionPlan/midnight/takeRepayWithdrawCollateral.d.ts +1 -1
  58. package/lib/cjs/transactionPlan/midnight/takeRepayWithdrawCollateral.js +1 -1
  59. package/lib/cjs/transactionPlan/midnight/takeWithdraw.d.ts +1 -1
  60. package/lib/cjs/transactionPlan/midnight/takeWithdraw.js +1 -1
  61. package/lib/cjs/transactionPlan/permit.d.ts +15 -2
  62. package/lib/cjs/transactionPlan/permit.js +26 -68
  63. package/lib/cjs/transactionPlan/plan.d.ts +51 -1
  64. package/lib/cjs/transactionPlan/plan.js +56 -13
  65. package/lib/cjs/transactionPlan/redeem.js +4 -7
  66. package/lib/cjs/transactionPlan/types.d.ts +4 -3
  67. package/lib/cjs/transactionPlan/vaultBinding.d.ts +29 -0
  68. package/lib/cjs/transactionPlan/vaultBinding.js +69 -0
  69. package/lib/cjs/transactionPlan/vaultRequirements.d.ts +20 -0
  70. package/lib/cjs/transactionPlan/vaultRequirements.js +37 -0
  71. package/lib/cjs/transactionPlan/vaultv1/deposit.d.ts +1 -1
  72. package/lib/cjs/transactionPlan/vaultv1/deposit.js +2 -13
  73. package/lib/cjs/transactionPlan/vaultv1/inKindRedeem.d.ts +2 -2
  74. package/lib/cjs/transactionPlan/vaultv1/inKindRedeem.js +10 -41
  75. package/lib/cjs/transactionPlan/vaultv1/migrateToV2.d.ts +1 -1
  76. package/lib/cjs/transactionPlan/vaultv1/migrateToV2.js +6 -18
  77. package/lib/cjs/transactionPlan/vaultv1/redeem.js +1 -12
  78. package/lib/cjs/transactionPlan/vaultv1/withdraw.d.ts +1 -1
  79. package/lib/cjs/transactionPlan/vaultv1/withdraw.js +2 -13
  80. package/lib/cjs/transactionPlan/vaultv2/deposit.d.ts +1 -1
  81. package/lib/cjs/transactionPlan/vaultv2/deposit.js +2 -13
  82. package/lib/cjs/transactionPlan/vaultv2/forceRedeem.d.ts +1 -1
  83. package/lib/cjs/transactionPlan/vaultv2/forceRedeem.js +4 -7
  84. package/lib/cjs/transactionPlan/vaultv2/forceWithdraw.d.ts +2 -2
  85. package/lib/cjs/transactionPlan/vaultv2/forceWithdraw.js +12 -42
  86. package/lib/cjs/transactionPlan/vaultv2/inKindRedeem.d.ts +2 -2
  87. package/lib/cjs/transactionPlan/vaultv2/inKindRedeem.js +10 -41
  88. package/lib/cjs/transactionPlan/vaultv2/redeem.d.ts +1 -1
  89. package/lib/cjs/transactionPlan/vaultv2/redeem.js +2 -13
  90. package/lib/cjs/transactionPlan/vaultv2/withdraw.d.ts +1 -1
  91. package/lib/cjs/transactionPlan/vaultv2/withdraw.js +2 -13
  92. package/lib/cjs/transactionPlan/withdraw.js +4 -7
  93. package/lib/cjs/types/error.d.ts +27 -1
  94. package/lib/cjs/types/error.js +32 -3
  95. package/lib/cjs/version.d.ts +1 -1
  96. package/lib/cjs/version.js +1 -1
  97. package/lib/esm/actions/blue/common.js +13 -4
  98. package/lib/esm/actions/midnight/supplyCollateralTakeBorrow.js +16 -11
  99. package/lib/esm/actions/midnight/takeBorrow.js +14 -8
  100. package/lib/esm/actions/midnight/takeLend.js +15 -9
  101. package/lib/esm/actions/midnight/takeRepayWithdrawCollateral.js +19 -13
  102. package/lib/esm/actions/midnight/takeWithdraw.js +14 -8
  103. package/lib/esm/constants.d.ts +1 -1
  104. package/lib/esm/constants.js +1 -1
  105. package/lib/esm/entities/midnight/midnight.d.ts +106 -103
  106. package/lib/esm/entities/midnight/midnight.js +120 -101
  107. package/lib/esm/entities/vaultV1/vaultV1.js +0 -1
  108. package/lib/esm/entities/vaultV2/vaultV2.js +0 -1
  109. package/lib/esm/helpers/constant.d.ts +7 -0
  110. package/lib/esm/helpers/constant.js +7 -0
  111. package/lib/esm/helpers/index.d.ts +1 -1
  112. package/lib/esm/helpers/index.js +1 -1
  113. package/lib/esm/helpers/validate.d.ts +25 -1
  114. package/lib/esm/helpers/validate.js +25 -2
  115. package/lib/esm/transactionPlan/assemble.d.ts +24 -0
  116. package/lib/esm/transactionPlan/assemble.js +21 -0
  117. package/lib/esm/transactionPlan/blue/borrow.js +15 -65
  118. package/lib/esm/transactionPlan/blue/refinance.js +10 -12
  119. package/lib/esm/transactionPlan/blue/repay.js +11 -25
  120. package/lib/esm/transactionPlan/blue/repayWithdrawCollateral.js +50 -46
  121. package/lib/esm/transactionPlan/blue/stored.d.ts +26 -0
  122. package/lib/esm/transactionPlan/blue/stored.js +80 -0
  123. package/lib/esm/transactionPlan/blue/supply.js +7 -22
  124. package/lib/esm/transactionPlan/blue/supplyCollateral.d.ts +1 -1
  125. package/lib/esm/transactionPlan/blue/supplyCollateral.js +10 -15
  126. package/lib/esm/transactionPlan/blue/supplyCollateralBorrow.js +15 -65
  127. package/lib/esm/transactionPlan/blue/withdraw.d.ts +2 -3
  128. package/lib/esm/transactionPlan/blue/withdraw.js +70 -82
  129. package/lib/esm/transactionPlan/blue/withdrawCollateral.d.ts +2 -3
  130. package/lib/esm/transactionPlan/blue/withdrawCollateral.js +32 -31
  131. package/lib/esm/transactionPlan/deposit.js +5 -8
  132. package/lib/esm/transactionPlan/intent.d.ts +1 -1
  133. package/lib/esm/transactionPlan/midnight/makeBorrow.d.ts +1 -1
  134. package/lib/esm/transactionPlan/midnight/makeBorrow.js +1 -1
  135. package/lib/esm/transactionPlan/midnight/makeLend.d.ts +1 -1
  136. package/lib/esm/transactionPlan/midnight/makeLend.js +1 -1
  137. package/lib/esm/transactionPlan/midnight/makeRepay.d.ts +1 -1
  138. package/lib/esm/transactionPlan/midnight/makeRepay.js +1 -1
  139. package/lib/esm/transactionPlan/midnight/repayWithdrawCollateral.d.ts +1 -1
  140. package/lib/esm/transactionPlan/midnight/repayWithdrawCollateral.js +1 -1
  141. package/lib/esm/transactionPlan/midnight/supplyBlueMakeLend.d.ts +1 -1
  142. package/lib/esm/transactionPlan/midnight/supplyBlueMakeLend.js +1 -1
  143. package/lib/esm/transactionPlan/midnight/supplyCollateral.d.ts +1 -1
  144. package/lib/esm/transactionPlan/midnight/supplyCollateral.js +1 -1
  145. package/lib/esm/transactionPlan/midnight/supplyCollateralBatch.d.ts +1 -1
  146. package/lib/esm/transactionPlan/midnight/supplyCollateralBatch.js +1 -1
  147. package/lib/esm/transactionPlan/midnight/supplyCollateralMakeBorrow.d.ts +1 -1
  148. package/lib/esm/transactionPlan/midnight/supplyCollateralMakeBorrow.js +1 -1
  149. package/lib/esm/transactionPlan/midnight/supplyCollateralWithNative.d.ts +1 -1
  150. package/lib/esm/transactionPlan/midnight/supplyCollateralWithNative.js +1 -1
  151. package/lib/esm/transactionPlan/midnight/takeBorrow.d.ts +6 -2
  152. package/lib/esm/transactionPlan/midnight/takeBorrow.js +11 -5
  153. package/lib/esm/transactionPlan/midnight/takeRepayWithdrawCollateral.d.ts +1 -1
  154. package/lib/esm/transactionPlan/midnight/takeRepayWithdrawCollateral.js +1 -1
  155. package/lib/esm/transactionPlan/midnight/takeWithdraw.d.ts +1 -1
  156. package/lib/esm/transactionPlan/midnight/takeWithdraw.js +1 -1
  157. package/lib/esm/transactionPlan/permit.d.ts +15 -2
  158. package/lib/esm/transactionPlan/permit.js +25 -68
  159. package/lib/esm/transactionPlan/plan.d.ts +51 -1
  160. package/lib/esm/transactionPlan/plan.js +55 -13
  161. package/lib/esm/transactionPlan/redeem.js +5 -8
  162. package/lib/esm/transactionPlan/types.d.ts +4 -3
  163. package/lib/esm/transactionPlan/vaultBinding.d.ts +29 -0
  164. package/lib/esm/transactionPlan/vaultBinding.js +65 -0
  165. package/lib/esm/transactionPlan/vaultRequirements.d.ts +20 -0
  166. package/lib/esm/transactionPlan/vaultRequirements.js +34 -0
  167. package/lib/esm/transactionPlan/vaultv1/deposit.d.ts +1 -1
  168. package/lib/esm/transactionPlan/vaultv1/deposit.js +3 -14
  169. package/lib/esm/transactionPlan/vaultv1/inKindRedeem.d.ts +2 -2
  170. package/lib/esm/transactionPlan/vaultv1/inKindRedeem.js +12 -43
  171. package/lib/esm/transactionPlan/vaultv1/migrateToV2.d.ts +1 -1
  172. package/lib/esm/transactionPlan/vaultv1/migrateToV2.js +9 -21
  173. package/lib/esm/transactionPlan/vaultv1/redeem.js +2 -13
  174. package/lib/esm/transactionPlan/vaultv1/withdraw.d.ts +1 -1
  175. package/lib/esm/transactionPlan/vaultv1/withdraw.js +3 -14
  176. package/lib/esm/transactionPlan/vaultv2/deposit.d.ts +1 -1
  177. package/lib/esm/transactionPlan/vaultv2/deposit.js +3 -14
  178. package/lib/esm/transactionPlan/vaultv2/forceRedeem.d.ts +1 -1
  179. package/lib/esm/transactionPlan/vaultv2/forceRedeem.js +5 -8
  180. package/lib/esm/transactionPlan/vaultv2/forceWithdraw.d.ts +2 -2
  181. package/lib/esm/transactionPlan/vaultv2/forceWithdraw.js +15 -45
  182. package/lib/esm/transactionPlan/vaultv2/inKindRedeem.d.ts +2 -2
  183. package/lib/esm/transactionPlan/vaultv2/inKindRedeem.js +12 -43
  184. package/lib/esm/transactionPlan/vaultv2/redeem.d.ts +1 -1
  185. package/lib/esm/transactionPlan/vaultv2/redeem.js +3 -14
  186. package/lib/esm/transactionPlan/vaultv2/withdraw.d.ts +1 -1
  187. package/lib/esm/transactionPlan/vaultv2/withdraw.js +3 -14
  188. package/lib/esm/transactionPlan/withdraw.js +5 -8
  189. package/lib/esm/types/error.d.ts +27 -1
  190. package/lib/esm/types/error.js +30 -2
  191. package/lib/esm/version.d.ts +1 -1
  192. package/lib/esm/version.js +1 -1
  193. package/package.json +3 -3
@@ -1,12 +1,13 @@
1
1
  import { MarketUtils } from "@morpho-org/blue-sdk";
2
- import { deepFreeze } from "@morpho-org/morpho-ts";
3
2
  import { blueSupply } from "../../actions/blue/supply.js";
4
3
  import { normalizeBundlesCommonParams } from "../../actions/bundles/common.js";
5
4
  import { validateClientChainId } from "../../actions/requirements/validateClientChainId.js";
5
+ import { freezePlan, planHeader } from "../assemble.js";
6
6
  import { InvalidTransactionPlanError } from "../error.js";
7
7
  import { getVaultPermit, validateTokenPermitRequest } from "../permit.js";
8
8
  import { getPlanObject, validatePlanField, validatePlanFields, } from "../validation.js";
9
9
  import { prepareBlue } from "./prepare.js";
10
+ import { BUNDLES_COMMON_FIELDS, validateStoredBlueMarketParams, } from "./stored.js";
10
11
  /** @internal Validates the stored supply recipe without requiring class instances. */
11
12
  export function validateBlueSupplyPlanAction(action, path) {
12
13
  const inputs = getPlanObject(action.inputs, `${path}.inputs`);
@@ -14,9 +15,7 @@ export function validateBlueSupplyPlanAction(action, path) {
14
15
  path: `${path}.inputs`,
15
16
  fields: {
16
17
  assets: "uint256 bigint",
17
- deadline: "uint256 bigint",
18
- referralFeePct: "uint256 bigint",
19
- referralFeeRecipient: "address",
18
+ ...BUNDLES_COMMON_FIELDS,
20
19
  },
21
20
  });
22
21
  if (inputs.nativeAssets !== undefined) {
@@ -26,17 +25,7 @@ export function validateBlueSupplyPlanAction(action, path) {
26
25
  });
27
26
  validateNativeAssets(inputs, `${path}.inputs.nativeAssets`);
28
27
  }
29
- const market = getPlanObject(inputs.marketParams, `${path}.inputs.marketParams`);
30
- validatePlanFields(market, {
31
- path: `${path}.inputs.marketParams`,
32
- fields: {
33
- loanToken: "address",
34
- collateralToken: "address",
35
- oracle: "address",
36
- irm: "address",
37
- lltv: "uint256 bigint",
38
- },
39
- });
28
+ validateStoredBlueMarketParams(inputs.marketParams, `${path}.inputs.marketParams`);
40
29
  getPlanObject(action.signatureRequestIds, `${path}.signatureRequestIds`);
41
30
  }
42
31
  /**
@@ -151,12 +140,8 @@ export async function prepareBlueSupply(client, params) {
151
140
  });
152
141
  await validateClientChainId(client, chainId);
153
142
  const { intent, steps, signatureRequests } = prepared;
154
- return deepFreeze(structuredClone({
155
- version: 2,
156
- chainId,
157
- account,
158
- expiresAt: intent.expiresAt,
159
- ...(intent.calldataOrigin && { calldataOrigin: intent.calldataOrigin }),
143
+ return freezePlan({
144
+ ...planHeader({ chainId, account }, intent),
160
145
  steps: [
161
146
  ...steps,
162
147
  {
@@ -179,7 +164,7 @@ export async function prepareBlueSupply(client, params) {
179
164
  },
180
165
  ],
181
166
  signatureRequests,
182
- }));
167
+ }, { detach: true });
183
168
  }
184
169
  /** @internal Binds an exact token permit to this supply's pull. */
185
170
  export function validateBlueSupplyPermitRequest(request, action) {
@@ -45,7 +45,7 @@ export interface BlueSupplyCollateralPlanParams extends IntentParams, ReferenceT
45
45
  * @param params.supportSignature - Prefer an ERC-2612 permit where available; defaults to false.
46
46
  * @param params.now - Reference Unix timestamp in seconds; defaults to the device clock.
47
47
  * @param params.expiresAt - Expiry in Unix seconds, later than `now`; defaults to `now + 2h`.
48
- * @param params.calldataOrigin - Optional non-empty hex bytes appended to each built transaction.
48
+ * @param params.calldataOrigin - Optional non-empty hex bytes appended to the action transaction's calldata; approval and authorization steps carry none.
49
49
  * @param params.deployless - Whether permit metadata reads may use deployless aggregation.
50
50
  * @returns A frozen plan containing the collateral supply step and any token prerequisites.
51
51
  * @throws {BlueSnapshotChainMismatchError} when the snapshot comes from another chain.
@@ -1,14 +1,15 @@
1
1
  import { MarketUtils } from "@morpho-org/blue-sdk";
2
- import { deepFreeze } from "@morpho-org/morpho-ts";
3
2
  import { zeroAddress } from "viem";
4
3
  import { blueSupplyCollateral } from "../../actions/blue/supplyCollateral.js";
5
4
  import { validateClientChainId } from "../../actions/requirements/validateClientChainId.js";
6
5
  import { validateNativeAsset, validateReferralFee, validateUint256Field, } from "../../helpers/validate.js";
7
6
  import { NonPositiveInputError, } from "../../types/index.js";
7
+ import { freezePlan, planHeader } from "../assemble.js";
8
8
  import { InvalidTransactionPlanError, TransactionPlanSignatureMismatchError, } from "../error.js";
9
9
  import { getSignedTokenPermit, validateTokenPermitRequest } from "../permit.js";
10
10
  import { getPlanObject, validatePlanFields } from "../validation.js";
11
11
  import { prepareBlue } from "./prepare.js";
12
+ import { BUNDLES_COMMON_FIELDS, signatureRoles } from "./stored.js";
12
13
  const actionId = "blueSupplyCollateral";
13
14
  /**
14
15
  * Prepares a collateral-only supply through BlueBundlesV1 from a caller-fetched market snapshot.
@@ -28,7 +29,7 @@ const actionId = "blueSupplyCollateral";
28
29
  * @param params.supportSignature - Prefer an ERC-2612 permit where available; defaults to false.
29
30
  * @param params.now - Reference Unix timestamp in seconds; defaults to the device clock.
30
31
  * @param params.expiresAt - Expiry in Unix seconds, later than `now`; defaults to `now + 2h`.
31
- * @param params.calldataOrigin - Optional non-empty hex bytes appended to each built transaction.
32
+ * @param params.calldataOrigin - Optional non-empty hex bytes appended to the action transaction's calldata; approval and authorization steps carry none.
32
33
  * @param params.deployless - Whether permit metadata reads may use deployless aggregation.
33
34
  * @returns A frozen plan containing the collateral supply step and any token prerequisites.
34
35
  * @throws {BlueSnapshotChainMismatchError} when the snapshot comes from another chain.
@@ -93,12 +94,8 @@ export async function prepareBlueSupplyCollateral(client, params) {
93
94
  await validateClientChainId(client, chainId);
94
95
  }
95
96
  const tokenPermit = signatureRequests.find(({ kind }) => kind === "permit");
96
- return deepFreeze(structuredClone({
97
- version: 2,
98
- chainId,
99
- account,
100
- expiresAt: intent.expiresAt,
101
- ...(intent.calldataOrigin && { calldataOrigin: intent.calldataOrigin }),
97
+ return freezePlan({
98
+ ...planHeader({ chainId, account }, intent),
102
99
  steps: [
103
100
  ...steps,
104
101
  {
@@ -116,14 +113,14 @@ export async function prepareBlueSupplyCollateral(client, params) {
116
113
  referralFeePct: intent.referralFeePct,
117
114
  referralFeeRecipient: intent.referralFeeRecipient ?? zeroAddress,
118
115
  },
119
- signatureRequestIds: tokenPermit
120
- ? { tokenPermit: tokenPermit.id }
121
- : {},
116
+ signatureRequestIds: signatureRoles({
117
+ tokenPermit: tokenPermit?.id,
118
+ }),
122
119
  },
123
120
  },
124
121
  ],
125
122
  signatureRequests,
126
- }));
123
+ }, { detach: true });
127
124
  }
128
125
  /** @internal Validates the stored collateral supply action and its token permit role. */
129
126
  export function validateSupplyCollateralPlanAction(action, path) {
@@ -133,9 +130,7 @@ export function validateSupplyCollateralPlanAction(action, path) {
133
130
  path: inputsPath,
134
131
  fields: {
135
132
  collateralAssets: "uint256 bigint",
136
- deadline: "uint256 bigint",
137
- referralFeePct: "uint256 bigint",
138
- referralFeeRecipient: "address",
133
+ ...BUNDLES_COMMON_FIELDS,
139
134
  },
140
135
  });
141
136
  const marketPath = `${inputsPath}.marketParams`;
@@ -1,5 +1,5 @@
1
1
  import { MathLib } from "@morpho-org/blue-sdk";
2
- import { deepFreeze, Time } from "@morpho-org/morpho-ts";
2
+ import { Time } from "@morpho-org/morpho-ts";
3
3
  import { maxUint256 } from "viem";
4
4
  import { blueSupplyCollateralBorrow } from "../../actions/blue/supplyCollateralBorrow.js";
5
5
  import { validateClientChainId } from "../../actions/requirements/validateClientChainId.js";
@@ -7,11 +7,13 @@ import { getBlueBundlesV1QuoteTimestamp } from "../../helpers/getBlueBundlesV1Qu
7
7
  import { DEFAULT_LLTV_BUFFER, validatePositionHealth, } from "../../helpers/index.js";
8
8
  import { parseNativeFunding } from "../../helpers/parse.js";
9
9
  import { MissingAccrualPositionError, } from "../../types/index.js";
10
+ import { freezePlan, planHeader } from "../assemble.js";
10
11
  import { IncompleteTransactionPlanError, InvalidTransactionPlanError, TransactionPlanSignatureMismatchError, } from "../error.js";
11
12
  import { getVaultPermit, validateTokenPermitRequest } from "../permit.js";
12
13
  import { getPlanObject, validatePlanField, validatePlanFields, } from "../validation.js";
13
14
  import { validateMorphoAuthorizationRequest } from "./authorization.js";
14
15
  import { prepareBlue, } from "./prepare.js";
16
+ import { signatureRoles, validateStoredBlueMarket, validateStoredReallocations, } from "./stored.js";
15
17
  /**
16
18
  * Prepares collateral funding and Morpho authorization for one BlueBundlesV1 call. Snapshots
17
19
  * are validated before reads; health uses the expiry floored at max(now, lastUpdate).
@@ -156,14 +158,8 @@ export async function prepareBlueSupplyCollateralBorrow(client, params) {
156
158
  await validateClientChainId(client, chainId);
157
159
  const authorization = prepared.signatureRequests.find((request) => request.id === prepared.morphoAuthorizationRequestId);
158
160
  const permit = prepared.signatureRequests.find((request) => request.kind === "permit");
159
- return deepFreeze(structuredClone({
160
- version: 2,
161
- chainId,
162
- account,
163
- expiresAt: prepared.intent.expiresAt,
164
- ...(prepared.intent.calldataOrigin && {
165
- calldataOrigin: prepared.intent.calldataOrigin,
166
- }),
161
+ return freezePlan({
162
+ ...planHeader({ chainId, account }, prepared.intent),
167
163
  steps: [
168
164
  ...prepared.steps,
169
165
  {
@@ -199,15 +195,15 @@ export async function prepareBlueSupplyCollateralBorrow(client, params) {
199
195
  authorizationNonce: authorization.args.nonce,
200
196
  }),
201
197
  },
202
- signatureRequestIds: {
203
- ...(permit && { tokenPermit: permit.id }),
204
- ...(authorization && { morphoAuthorization: authorization.id }),
205
- },
198
+ signatureRequestIds: signatureRoles({
199
+ tokenPermit: permit?.id,
200
+ morphoAuthorization: authorization?.id,
201
+ }),
206
202
  },
207
203
  },
208
204
  ],
209
205
  signatureRequests: prepared.signatureRequests,
210
- }));
206
+ }, { detach: true });
211
207
  }
212
208
  function captureSupplyBorrowIntent(params) {
213
209
  const { chainId, account, marketId, marketData, positionData, expiresAt, referralFee, supportSignature, calldataOrigin, deployless, now = Time.timestamp(), } = params;
@@ -294,26 +290,6 @@ export function buildBlueSupplyCollateralBorrow(action, requests) {
294
290
  },
295
291
  });
296
292
  }
297
- function validateMarket(value, path) {
298
- const market = getPlanObject(value, path);
299
- validatePlanFields(market, {
300
- path,
301
- fields: {
302
- id: "hex",
303
- loanToken: "address",
304
- collateralToken: "address",
305
- oracle: "address",
306
- irm: "address",
307
- lltv: "uint256 bigint",
308
- },
309
- });
310
- if (typeof market.id !== "string" || market.id.length !== 66) {
311
- throw new InvalidTransactionPlanError({
312
- path: `${path}.id`,
313
- reason: "expected a 32-byte market ID",
314
- });
315
- }
316
- }
317
293
  /** @internal Validates the complete stored input and reallocation shape. */
318
294
  export function validateSupplyCollateralBorrowPlanAction(action, path) {
319
295
  const inputs = getPlanObject(action.inputs, `${path}.inputs`);
@@ -346,7 +322,7 @@ export function validateSupplyCollateralBorrowPlanAction(action, path) {
346
322
  type: "address",
347
323
  });
348
324
  }
349
- validateMarket(inputs.marketParams, `${path}.inputs.marketParams`);
325
+ validateStoredBlueMarket(inputs.marketParams, `${path}.inputs.marketParams`);
350
326
  const ids = getPlanObject(action.signatureRequestIds, `${path}.signatureRequestIds`);
351
327
  for (const key of Object.keys(ids)) {
352
328
  if (key !== "tokenPermit" && key !== "morphoAuthorization") {
@@ -373,34 +349,8 @@ export function validateSupplyCollateralBorrowPlanAction(action, path) {
373
349
  type: "uint256 bigint",
374
350
  });
375
351
  }
376
- for (const [index, value] of inputs.reallocations.entries()) {
377
- const entryPath = `${path}.inputs.reallocations[${index}]`;
378
- const entry = getPlanObject(value, entryPath);
379
- validatePlanFields(entry, {
380
- path: entryPath,
381
- fields: {
382
- vault: "address",
383
- assets: "uint256 bigint",
384
- penalty: "uint256 bigint",
385
- },
386
- });
387
- validatePlanFields(getPlanObject(entry.to, `${entryPath}.to`), {
388
- path: `${entryPath}.to`,
389
- fields: { adapter: "address" },
390
- });
391
- const from = getPlanObject(entry.from, `${entryPath}.from`);
392
- if (from.type === "market") {
393
- validatePlanFields(from, {
394
- path: `${entryPath}.from`,
395
- fields: { adapter: "address" },
396
- });
397
- validateMarket(from.marketParams, `${entryPath}.from.marketParams`);
398
- }
399
- else if (from.type !== "idle") {
400
- throw new InvalidTransactionPlanError({
401
- path: `${entryPath}.from.type`,
402
- reason: "expected market or idle",
403
- });
404
- }
405
- }
352
+ validateStoredReallocations(inputs.reallocations, {
353
+ path: `${path}.inputs.reallocations`,
354
+ marketParams: validateStoredBlueMarket,
355
+ });
406
356
  }
@@ -69,7 +69,7 @@ export type BlueWithdrawPlanParams = IntentParams & AssetsOrSharesArgs & {
69
69
  * @param params.supportSignature - Optional Morpho authorization signature preference; defaults to `false`, selecting a direct authorization transaction when needed. Neither mode requests a token allowance or Permit2 signature.
70
70
  * @param params.now - Optional reference timestamp in seconds, normally the latest block timestamp; defaults to the device clock.
71
71
  * @param params.expiresAt - Optional Unix expiry in safe-integer seconds, later than `now`; defaults to `now + 2h`.
72
- * @param params.calldataOrigin - Optional non-empty, even-length hex bytes appended to every built transaction; omitted by default.
72
+ * @param params.calldataOrigin - Optional non-empty, even-length hex bytes appended to the action transaction's calldata, not to approval or authorization steps; omitted by default.
73
73
  * @param params.deployless - Optional shared intent field; unused because withdrawal reads no token metadata.
74
74
  * @returns A deep-frozen, data-only `{ version, chainId, account, expiresAt, steps, signatureRequests, calldataOrigin? }` plan with a withdrawal step. Direct Morpho authorization is a preceding step; signed authorization is consumed inline by the withdrawal. Attach signatures before building.
75
75
  * @throws {InvalidBigIntInputError} when a supplied maxPenalty is not a bigint.
@@ -100,7 +100,6 @@ export type BlueWithdrawPlanParams = IntentParams & AssetsOrSharesArgs & {
100
100
  * @throws {WithdrawSharesExceedSupplyError} when `shares` exceeds the position's supply shares.
101
101
  * @throws {MissingContractCodeError} when registered BlueBundlesV1 or Blue has no deployed code.
102
102
  * @throws {viem.BaseError} when a chain, bytecode, authorization or nonce RPC read fails, or ABI encoding rejects malformed input.
103
- * @throws {UnexpectedRequirementSignatureError} when an authorization requirement returns a nonce that is not a bigint.
104
103
  * @throws {TransactionPlanSignatureMismatchError} when the authorization requirement does not match the prepared account, chain, nonce or deadline.
105
104
  * @example
106
105
  * ```ts
@@ -120,7 +119,7 @@ export type BlueWithdrawPlanParams = IntentParams & AssetsOrSharesArgs & {
120
119
  * positionData: { chainId: mainnet.id, position },
121
120
  * now: (await client.getBlock()).timestamp,
122
121
  * });
123
- * // plan: { version: 1, chainId, account, expiresAt, steps, signatureRequests }
122
+ * // plan: { version: 2, chainId, account, expiresAt, steps, signatureRequests }
124
123
  * // Sign any pending Morpho authorization request, then build and submit each step in order.
125
124
  * ```
126
125
  * @experimental TransactionPlan is in beta; breaking changes may ship in minor releases.
@@ -1,15 +1,16 @@
1
- import { AccrualPosition, MarketParams, } from "@morpho-org/blue-sdk";
2
- import { deepFreeze } from "@morpho-org/morpho-ts";
1
+ import { AccrualPosition, MarketUtils, } from "@morpho-org/blue-sdk";
3
2
  import { zeroAddress } from "viem";
4
3
  import { getBlueBundlesV1PenaltyAssets } from "../../actions/blue/common.js";
5
4
  import { blueWithdraw } from "../../actions/blue/withdraw.js";
6
5
  import { validateClientChainId } from "../../actions/requirements/validateClientChainId.js";
7
6
  import { validateVaultV2BlueReallocations, validateWithdrawAmount, validateWithdrawShares, } from "../../helpers/validate.js";
8
- import { InputExceedsMaxError, MissingAccrualPositionError, } from "../../types/index.js";
9
- import { IncompleteTransactionPlanError, InvalidTransactionPlanError, TransactionPlanSignatureMismatchError, } from "../error.js";
7
+ import { InputExceedsMaxError, InvalidVaultV2BlueReallocationShapeError, MissingAccrualPositionError, } from "../../types/index.js";
8
+ import { freezePlan, planHeader } from "../assemble.js";
9
+ import { IncompleteTransactionPlanError, TransactionPlanSignatureMismatchError, } from "../error.js";
10
10
  import { getPlanObject, validatePlanField, validatePlanFields, } from "../validation.js";
11
11
  import { validateMorphoAuthorizationRequest } from "./authorization.js";
12
12
  import { prepareBlue, } from "./prepare.js";
13
+ import { BUNDLES_COMMON_FIELDS, validateStoredBlueMarketParams, validateStoredReallocations, } from "./stored.js";
13
14
  /**
14
15
  * Prepares a BlueBundlesV1 withdrawal with only Morpho authorization prerequisites, never token approvals.
15
16
  * The caller supplies market and position snapshots; the SDK reads authorization but never signs.
@@ -42,7 +43,7 @@ import { prepareBlue, } from "./prepare.js";
42
43
  * @param params.supportSignature - Optional Morpho authorization signature preference; defaults to `false`, selecting a direct authorization transaction when needed. Neither mode requests a token allowance or Permit2 signature.
43
44
  * @param params.now - Optional reference timestamp in seconds, normally the latest block timestamp; defaults to the device clock.
44
45
  * @param params.expiresAt - Optional Unix expiry in safe-integer seconds, later than `now`; defaults to `now + 2h`.
45
- * @param params.calldataOrigin - Optional non-empty, even-length hex bytes appended to every built transaction; omitted by default.
46
+ * @param params.calldataOrigin - Optional non-empty, even-length hex bytes appended to the action transaction's calldata, not to approval or authorization steps; omitted by default.
46
47
  * @param params.deployless - Optional shared intent field; unused because withdrawal reads no token metadata.
47
48
  * @returns A deep-frozen, data-only `{ version, chainId, account, expiresAt, steps, signatureRequests, calldataOrigin? }` plan with a withdrawal step. Direct Morpho authorization is a preceding step; signed authorization is consumed inline by the withdrawal. Attach signatures before building.
48
49
  * @throws {InvalidBigIntInputError} when a supplied maxPenalty is not a bigint.
@@ -73,7 +74,6 @@ import { prepareBlue, } from "./prepare.js";
73
74
  * @throws {WithdrawSharesExceedSupplyError} when `shares` exceeds the position's supply shares.
74
75
  * @throws {MissingContractCodeError} when registered BlueBundlesV1 or Blue has no deployed code.
75
76
  * @throws {viem.BaseError} when a chain, bytecode, authorization or nonce RPC read fails, or ABI encoding rejects malformed input.
76
- * @throws {UnexpectedRequirementSignatureError} when an authorization requirement returns a nonce that is not a bigint.
77
77
  * @throws {TransactionPlanSignatureMismatchError} when the authorization requirement does not match the prepared account, chain, nonce or deadline.
78
78
  * @example
79
79
  * ```ts
@@ -93,33 +93,65 @@ import { prepareBlue, } from "./prepare.js";
93
93
  * positionData: { chainId: mainnet.id, position },
94
94
  * now: (await client.getBlock()).timestamp,
95
95
  * });
96
- * // plan: { version: 1, chainId, account, expiresAt, steps, signatureRequests }
96
+ * // plan: { version: 2, chainId, account, expiresAt, steps, signatureRequests }
97
97
  * // Sign any pending Morpho authorization request, then build and submit each step in order.
98
98
  * ```
99
99
  * @experimental TransactionPlan is in beta; breaking changes may ship in minor releases.
100
100
  */
101
101
  export async function prepareBlueWithdraw(client, params) {
102
- const { maxPenalty } = params;
103
- await validateClientChainId(client, params.chainId);
102
+ const { maxPenalty, chainId, account } = params;
103
+ const supplied = params.reallocations ?? [];
104
+ let reallocations;
105
+ try {
106
+ reallocations = structuredClone(Array.isArray(supplied)
107
+ ? supplied.map((entry) => {
108
+ if (entry === null ||
109
+ typeof entry !== "object" ||
110
+ "withdrawals" in entry ||
111
+ "fee" in entry) {
112
+ return entry;
113
+ }
114
+ const { vault, from, to, assets, penalty } = entry;
115
+ return { vault, from, to, assets, penalty };
116
+ })
117
+ : supplied);
118
+ }
119
+ catch (cause) {
120
+ throw new InvalidVaultV2BlueReallocationShapeError({ cause });
121
+ }
122
+ await validateClientChainId(client, chainId);
104
123
  const { positionData: snapshot } = params;
105
124
  if (snapshot == null) {
106
125
  throw new MissingAccrualPositionError(params.marketId);
107
126
  }
108
127
  const withdrawals = [];
109
- const { intent: resolvedIntent, steps, signatureRequests, } = await prepareBlue({ client, params }, (intent) => {
128
+ const captured = {
129
+ chainId,
130
+ account,
131
+ marketId: params.marketId,
132
+ marketData: params.marketData,
133
+ positionData: snapshot,
134
+ now: params.now,
135
+ expiresAt: params.expiresAt,
136
+ supportSignature: params.supportSignature,
137
+ referralFee: params.referralFee,
138
+ calldataOrigin: params.calldataOrigin,
139
+ deployless: params.deployless,
140
+ };
141
+ const { intent: resolvedIntent, steps, signatureRequests, } = await prepareBlue({ client, params: captured }, (intent) => {
110
142
  const inputs = {
111
- chainId: params.chainId,
112
- account: params.account,
143
+ chainId,
144
+ account,
113
145
  marketParams: {
114
- loanToken: params.marketData.market.params.loanToken,
115
- collateralToken: params.marketData.market.params.collateralToken,
116
- oracle: params.marketData.market.params.oracle,
117
- irm: params.marketData.market.params.irm,
118
- lltv: params.marketData.market.params.lltv,
146
+ loanToken: captured.marketData.market.params.loanToken,
147
+ collateralToken: captured.marketData.market.params.collateralToken,
148
+ oracle: captured.marketData.market.params.oracle,
149
+ irm: captured.marketData.market.params.irm,
150
+ lltv: captured.marketData.market.params.lltv,
119
151
  },
120
152
  withdrawAssets: "assets" in params ? (params.assets ?? 0n) : 0n,
121
153
  withdrawShares: "shares" in params ? (params.shares ?? 0n) : 0n,
122
- reallocations: params.reallocations ?? [],
154
+ reallocations,
123
155
  ...(maxPenalty !== undefined && { maxPenalty }),
124
156
  deadline: intent.deadline,
125
157
  referralFeePct: intent.referralFeePct,
@@ -151,7 +183,7 @@ export async function prepareBlueWithdraw(client, params) {
151
183
  positionData,
152
184
  withdrawShares: inputs.withdrawShares,
153
185
  withdrawAssets: inputs.withdrawAssets,
154
- marketId: params.marketId,
186
+ marketId: captured.marketId,
155
187
  });
156
188
  withdrawals.push({
157
189
  id: "blueWithdraw",
@@ -160,14 +192,8 @@ export async function prepareBlueWithdraw(client, params) {
160
192
  });
161
193
  return { id: "blueWithdraw", needsAuthorization: true };
162
194
  });
163
- return deepFreeze(structuredClone({
164
- version: 2,
165
- chainId: params.chainId,
166
- account: params.account,
167
- expiresAt: resolvedIntent.expiresAt,
168
- ...(resolvedIntent.calldataOrigin && {
169
- calldataOrigin: resolvedIntent.calldataOrigin,
170
- }),
195
+ return freezePlan({
196
+ ...planHeader({ chainId, account }, resolvedIntent),
171
197
  steps: [
172
198
  ...steps,
173
199
  ...withdrawals.map((step) => {
@@ -190,7 +216,7 @@ export async function prepareBlueWithdraw(client, params) {
190
216
  }),
191
217
  ],
192
218
  signatureRequests,
193
- }));
219
+ }, { detach: true });
194
220
  }
195
221
  /** @internal Binds an inline authorization to the withdrawal that consumes it. */
196
222
  export function validateBlueWithdrawAuthorizationRequest(request, action) {
@@ -244,7 +270,7 @@ export function buildBlueWithdraw(action, requests = []) {
244
270
  },
245
271
  };
246
272
  }
247
- const targetMarketParams = new MarketParams(marketParams);
273
+ const targetMarketParams = toEncoderMarketParams(marketParams);
248
274
  // Reject malformed entries with typed errors before reading their source fields.
249
275
  validateVaultV2BlueReallocations(args.reallocations, {
250
276
  targetMarketId: targetMarketParams.id,
@@ -255,7 +281,7 @@ export function buildBlueWithdraw(action, requests = []) {
255
281
  from: entry.from.type === "market"
256
282
  ? {
257
283
  ...entry.from,
258
- marketParams: new MarketParams(entry.from.marketParams),
284
+ marketParams: toEncoderMarketParams(entry.from.marketParams),
259
285
  }
260
286
  : entry.from,
261
287
  }));
@@ -269,6 +295,15 @@ export function buildBlueWithdraw(action, requests = []) {
269
295
  },
270
296
  });
271
297
  }
298
+ function toEncoderMarketParams(marketParams) {
299
+ const { loanToken, collateralToken, oracle, irm, lltv } = marketParams;
300
+ const tuple = { loanToken, collateralToken, oracle, irm, lltv };
301
+ return {
302
+ ...tuple,
303
+ id: MarketUtils.getMarketId(tuple),
304
+ liquidationIncentiveFactor: MarketUtils.getLiquidationIncentiveFactor(tuple),
305
+ };
306
+ }
272
307
  /** @internal Validates stored withdrawal scalars and allocator input shapes. */
273
308
  export function validateBlueWithdrawPlanAction(action, path) {
274
309
  const inputs = getPlanObject(action.inputs, `${path}.inputs`);
@@ -294,60 +329,13 @@ export function validateBlueWithdrawPlanAction(action, path) {
294
329
  fields: {
295
330
  withdrawAssets: "uint256 bigint",
296
331
  withdrawShares: "uint256 bigint",
297
- deadline: "uint256 bigint",
298
- referralFeePct: "uint256 bigint",
299
- referralFeeRecipient: "address",
332
+ ...BUNDLES_COMMON_FIELDS,
300
333
  reallocations: "array",
301
334
  },
302
335
  });
303
- validatePlanFields(getPlanObject(inputs.marketParams, `${path}.inputs.marketParams`), {
304
- path: `${path}.inputs.marketParams`,
305
- fields: {
306
- loanToken: "address",
307
- collateralToken: "address",
308
- oracle: "address",
309
- irm: "address",
310
- lltv: "uint256 bigint",
311
- },
336
+ validateStoredBlueMarketParams(inputs.marketParams, `${path}.inputs.marketParams`);
337
+ validateStoredReallocations(inputs.reallocations, {
338
+ path: `${path}.inputs.reallocations`,
339
+ marketParams: validateStoredBlueMarketParams,
312
340
  });
313
- for (const [index, value] of inputs.reallocations.entries()) {
314
- const entryPath = `${path}.inputs.reallocations[${index}]`;
315
- const entry = getPlanObject(value, entryPath);
316
- validatePlanFields(entry, {
317
- path: entryPath,
318
- fields: {
319
- vault: "address",
320
- assets: "uint256 bigint",
321
- penalty: "uint256 bigint",
322
- },
323
- });
324
- validatePlanFields(getPlanObject(entry.to, `${entryPath}.to`), {
325
- path: `${entryPath}.to`,
326
- fields: { adapter: "address" },
327
- });
328
- const from = getPlanObject(entry.from, `${entryPath}.from`);
329
- if (from.type === "idle") {
330
- continue;
331
- }
332
- if (from.type !== "market") {
333
- throw new InvalidTransactionPlanError({
334
- path: `${entryPath}.from.type`,
335
- reason: "expected market or idle",
336
- });
337
- }
338
- validatePlanFields(from, {
339
- path: `${entryPath}.from`,
340
- fields: { adapter: "address" },
341
- });
342
- validatePlanFields(getPlanObject(from.marketParams, `${entryPath}.from.marketParams`), {
343
- path: `${entryPath}.from.marketParams`,
344
- fields: {
345
- loanToken: "address",
346
- collateralToken: "address",
347
- oracle: "address",
348
- irm: "address",
349
- lltv: "uint256 bigint",
350
- },
351
- });
352
- }
353
341
  }
@@ -48,7 +48,7 @@ export interface BlueWithdrawCollateralPlanParams extends IntentParams, Referenc
48
48
  * @param params.supportSignature - Optional Morpho authorization signature preference, defaulting to `false`; otherwise prepares a direct authorization transaction when needed.
49
49
  * @param params.now - Optional reference timestamp in Unix seconds, normally the latest block timestamp; defaults to the device clock.
50
50
  * @param params.expiresAt - Optional safe-integer Unix expiry later than `now`; defaults to `now + 2h` and governs every deadline.
51
- * @param params.calldataOrigin - Optional non-empty, even-length hex bytes appended verbatim to every built transaction.
51
+ * @param params.calldataOrigin - Optional non-empty, even-length hex bytes appended verbatim to the action transaction's calldata; approval and authorization steps carry none.
52
52
  * @param params.deployless - Optional shared intent field; unused because this operation reads no token metadata or allowances.
53
53
  * @returns A deep-frozen, data-only `TransactionPlan` with chain, account, expiry, withdrawal step,
54
54
  * and any preceding Morpho authorization step and signature request. The caller signs; the SDK never does.
@@ -74,7 +74,6 @@ export interface BlueWithdrawCollateralPlanParams extends IntentParams, Referenc
74
74
  * @throws {viem.BaseError} when a contract-code, chain ID, authorization or nonce RPC read fails.
75
75
  * @example
76
76
  * ```ts
77
- * import assert from "node:assert/strict";
78
77
  * import { markets } from "@morpho-org/morpho-test";
79
78
  * import { fetchAccrualPosition } from "@morpho-org/morpho-sdk/blue/fetch";
80
79
  * import {
@@ -89,7 +88,7 @@ export interface BlueWithdrawCollateralPlanParams extends IntentParams, Referenc
89
88
  * if (!ethereum) throw new Error("Install an Ethereum wallet to continue.");
90
89
  * const wallet = createWalletClient({ chain: mainnet, transport: custom(ethereum) });
91
90
  * const [account] = await wallet.requestAddresses();
92
- * assert(account, "Connect a wallet holding collateral in this market.");
91
+ * if (!account) throw new Error("Connect a wallet holding collateral in this market.");
93
92
  * const market = markets[mainnet.id].usdc_wbtc;
94
93
  * const position = await fetchAccrualPosition(account, market.id, client);
95
94
  * const plan = await prepareBlueWithdrawCollateral(client, {