@morpho-org/morpho-sdk 4.2.0 → 5.1.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 (191) hide show
  1. package/README.md +16 -16
  2. package/lib/cjs/actions/blue/borrow.d.ts +12 -2
  3. package/lib/cjs/actions/blue/borrow.js +7 -1
  4. package/lib/cjs/actions/blue/buildAssetFundingActions.d.ts +47 -0
  5. package/lib/cjs/actions/blue/buildAssetFundingActions.js +63 -0
  6. package/lib/cjs/actions/blue/refinance.d.ts +13 -3
  7. package/lib/cjs/actions/blue/refinance.js +8 -2
  8. package/lib/cjs/actions/blue/repay.d.ts +44 -43
  9. package/lib/cjs/actions/blue/repay.js +70 -59
  10. package/lib/cjs/actions/blue/repayWithdrawCollateral.d.ts +50 -41
  11. package/lib/cjs/actions/blue/repayWithdrawCollateral.js +75 -54
  12. package/lib/cjs/actions/blue/resolveRepayFunding.d.ts +69 -0
  13. package/lib/cjs/actions/blue/resolveRepayFunding.js +82 -0
  14. package/lib/cjs/actions/blue/supply.d.ts +8 -8
  15. package/lib/cjs/actions/blue/supply.js +11 -35
  16. package/lib/cjs/actions/blue/supplyCollateral.d.ts +9 -9
  17. package/lib/cjs/actions/blue/supplyCollateral.js +12 -36
  18. package/lib/cjs/actions/blue/supplyCollateralBorrow.d.ts +19 -7
  19. package/lib/cjs/actions/blue/supplyCollateralBorrow.js +17 -32
  20. package/lib/cjs/actions/blue/withdraw.d.ts +10 -2
  21. package/lib/cjs/actions/blue/withdraw.js +7 -1
  22. package/lib/cjs/actions/index.d.ts +1 -0
  23. package/lib/cjs/actions/index.js +1 -0
  24. package/lib/cjs/actions/requirements/blue/getBlueAuthorizationRequirement.d.ts +49 -0
  25. package/lib/cjs/actions/requirements/blue/getBlueAuthorizationRequirement.js +111 -0
  26. package/lib/cjs/actions/requirements/blue/index.d.ts +1 -0
  27. package/lib/cjs/actions/requirements/blue/index.js +17 -0
  28. package/lib/cjs/actions/requirements/encode/encodeBlueSignatureAuthorization.d.ts +55 -0
  29. package/lib/cjs/actions/requirements/encode/encodeBlueSignatureAuthorization.js +89 -0
  30. package/lib/cjs/actions/requirements/encode/encodeErc20Approval.d.ts +6 -5
  31. package/lib/cjs/actions/requirements/encode/encodeErc20Approval.js +17 -5
  32. package/lib/cjs/actions/requirements/encode/encodeErc20Permit.d.ts +9 -7
  33. package/lib/cjs/actions/requirements/encode/encodeErc20Permit.js +18 -4
  34. package/lib/cjs/actions/requirements/encode/{encodeErc20Permit2.d.ts → encodeErc20Permit2Approve.d.ts} +11 -13
  35. package/lib/cjs/actions/requirements/encode/{encodeErc20Permit2.js → encodeErc20Permit2Approve.js} +10 -14
  36. package/lib/cjs/actions/requirements/encode/index.d.ts +2 -1
  37. package/lib/cjs/actions/requirements/encode/index.js +2 -1
  38. package/lib/cjs/actions/requirements/{getRequirements.d.ts → generalAdapter/getGeneralAdapterRequirements.d.ts} +34 -20
  39. package/lib/cjs/actions/requirements/generalAdapter/getGeneralAdapterRequirements.js +151 -0
  40. package/lib/{esm/actions/requirements/getRequirementsPermit.d.ts → cjs/actions/requirements/generalAdapter/getGeneralAdapterRequirementsPermit.d.ts} +6 -14
  41. package/lib/cjs/actions/requirements/generalAdapter/getGeneralAdapterRequirementsPermit.js +50 -0
  42. package/lib/cjs/actions/requirements/generalAdapter/getGeneralAdapterRequirementsPermit2.d.ts +57 -0
  43. package/lib/cjs/actions/requirements/generalAdapter/getGeneralAdapterRequirementsPermit2.js +74 -0
  44. package/lib/cjs/actions/requirements/generalAdapter/index.d.ts +3 -0
  45. package/lib/cjs/actions/requirements/generalAdapter/index.js +19 -0
  46. package/lib/cjs/actions/requirements/getRequirementsApproval.d.ts +3 -2
  47. package/lib/cjs/actions/requirements/getRequirementsApproval.js +3 -2
  48. package/lib/cjs/actions/requirements/index.d.ts +2 -5
  49. package/lib/cjs/actions/requirements/index.js +2 -5
  50. package/lib/cjs/actions/signatures/getBlueAuthorizationAction.d.ts +29 -0
  51. package/lib/cjs/actions/signatures/getBlueAuthorizationAction.js +48 -0
  52. package/lib/{esm/actions/requirements/getRequirementsAction.d.ts → cjs/actions/signatures/getTokenRequirementActions.d.ts} +17 -17
  53. package/lib/cjs/actions/{requirements/getRequirementsAction.js → signatures/getTokenRequirementActions.js} +26 -13
  54. package/lib/cjs/actions/signatures/index.d.ts +2 -0
  55. package/lib/cjs/actions/signatures/index.js +18 -0
  56. package/lib/cjs/actions/vaultV1/deposit.d.ts +6 -8
  57. package/lib/cjs/actions/vaultV1/deposit.js +11 -21
  58. package/lib/cjs/actions/vaultV1/migrateToV2.d.ts +6 -6
  59. package/lib/cjs/actions/vaultV1/migrateToV2.js +12 -20
  60. package/lib/cjs/actions/vaultV2/deposit.d.ts +6 -8
  61. package/lib/cjs/actions/vaultV2/deposit.js +11 -21
  62. package/lib/cjs/addresses.d.ts +2 -2
  63. package/lib/cjs/addresses.js +2 -1
  64. package/lib/cjs/bundler/actions.d.ts +44 -4
  65. package/lib/cjs/bundler/actions.js +75 -2
  66. package/lib/cjs/bundler/types.d.ts +6 -0
  67. package/lib/cjs/constants.d.ts +2 -2
  68. package/lib/cjs/constants.js +3 -3
  69. package/lib/cjs/entities/blue/blue.d.ts +58 -33
  70. package/lib/cjs/entities/blue/blue.js +309 -189
  71. package/lib/cjs/entities/reallocationData.d.ts +0 -44
  72. package/lib/cjs/entities/reallocationData.js +3 -50
  73. package/lib/cjs/entities/vaultV1/vaultV1.d.ts +9 -9
  74. package/lib/cjs/entities/vaultV1/vaultV1.js +44 -34
  75. package/lib/cjs/entities/vaultV2/vaultV2.d.ts +6 -6
  76. package/lib/cjs/entities/vaultV2/vaultV2.js +21 -16
  77. package/lib/cjs/errors.d.ts +3 -2
  78. package/lib/cjs/errors.js +5 -2
  79. package/lib/cjs/helpers/index.d.ts +1 -1
  80. package/lib/cjs/helpers/index.js +1 -2
  81. package/lib/cjs/helpers/validate.d.ts +2 -20
  82. package/lib/cjs/helpers/validate.js +2 -39
  83. package/lib/cjs/types/action.d.ts +164 -12
  84. package/lib/cjs/types/action.js +79 -5
  85. package/lib/cjs/types/error.d.ts +97 -2
  86. package/lib/cjs/types/error.js +113 -7
  87. package/lib/cjs/types.d.ts +2 -1
  88. package/lib/cjs/utils.d.ts +2 -2
  89. package/lib/cjs/utils.js +2 -4
  90. package/lib/esm/actions/blue/borrow.d.ts +12 -2
  91. package/lib/esm/actions/blue/borrow.js +7 -1
  92. package/lib/esm/actions/blue/buildAssetFundingActions.d.ts +47 -0
  93. package/lib/esm/actions/blue/buildAssetFundingActions.js +59 -0
  94. package/lib/esm/actions/blue/refinance.d.ts +13 -3
  95. package/lib/esm/actions/blue/refinance.js +8 -2
  96. package/lib/esm/actions/blue/repay.d.ts +44 -43
  97. package/lib/esm/actions/blue/repay.js +71 -60
  98. package/lib/esm/actions/blue/repayWithdrawCollateral.d.ts +50 -41
  99. package/lib/esm/actions/blue/repayWithdrawCollateral.js +76 -55
  100. package/lib/esm/actions/blue/resolveRepayFunding.d.ts +69 -0
  101. package/lib/esm/actions/blue/resolveRepayFunding.js +78 -0
  102. package/lib/esm/actions/blue/supply.d.ts +8 -8
  103. package/lib/esm/actions/blue/supply.js +12 -36
  104. package/lib/esm/actions/blue/supplyCollateral.d.ts +9 -9
  105. package/lib/esm/actions/blue/supplyCollateral.js +13 -37
  106. package/lib/esm/actions/blue/supplyCollateralBorrow.d.ts +19 -7
  107. package/lib/esm/actions/blue/supplyCollateralBorrow.js +18 -33
  108. package/lib/esm/actions/blue/withdraw.d.ts +10 -2
  109. package/lib/esm/actions/blue/withdraw.js +7 -1
  110. package/lib/esm/actions/index.d.ts +1 -0
  111. package/lib/esm/actions/index.js +1 -0
  112. package/lib/esm/actions/requirements/blue/getBlueAuthorizationRequirement.d.ts +49 -0
  113. package/lib/esm/actions/requirements/blue/getBlueAuthorizationRequirement.js +107 -0
  114. package/lib/esm/actions/requirements/blue/index.d.ts +1 -0
  115. package/lib/esm/actions/requirements/blue/index.js +1 -0
  116. package/lib/esm/actions/requirements/encode/encodeBlueSignatureAuthorization.d.ts +55 -0
  117. package/lib/esm/actions/requirements/encode/encodeBlueSignatureAuthorization.js +85 -0
  118. package/lib/esm/actions/requirements/encode/encodeErc20Approval.d.ts +6 -5
  119. package/lib/esm/actions/requirements/encode/encodeErc20Approval.js +19 -7
  120. package/lib/esm/actions/requirements/encode/encodeErc20Permit.d.ts +9 -7
  121. package/lib/esm/actions/requirements/encode/encodeErc20Permit.js +20 -6
  122. package/lib/esm/actions/requirements/encode/{encodeErc20Permit2.d.ts → encodeErc20Permit2Approve.d.ts} +11 -13
  123. package/lib/esm/actions/requirements/encode/{encodeErc20Permit2.js → encodeErc20Permit2Approve.js} +8 -12
  124. package/lib/esm/actions/requirements/encode/index.d.ts +2 -1
  125. package/lib/esm/actions/requirements/encode/index.js +2 -1
  126. package/lib/esm/actions/requirements/{getRequirements.d.ts → generalAdapter/getGeneralAdapterRequirements.d.ts} +34 -20
  127. package/lib/esm/actions/requirements/generalAdapter/getGeneralAdapterRequirements.js +147 -0
  128. package/lib/{cjs/actions/requirements/getRequirementsPermit.d.ts → esm/actions/requirements/generalAdapter/getGeneralAdapterRequirementsPermit.d.ts} +6 -14
  129. package/lib/esm/actions/requirements/generalAdapter/getGeneralAdapterRequirementsPermit.js +46 -0
  130. package/lib/esm/actions/requirements/generalAdapter/getGeneralAdapterRequirementsPermit2.d.ts +57 -0
  131. package/lib/esm/actions/requirements/generalAdapter/getGeneralAdapterRequirementsPermit2.js +70 -0
  132. package/lib/esm/actions/requirements/generalAdapter/index.d.ts +3 -0
  133. package/lib/esm/actions/requirements/generalAdapter/index.js +3 -0
  134. package/lib/esm/actions/requirements/getRequirementsApproval.d.ts +3 -2
  135. package/lib/esm/actions/requirements/getRequirementsApproval.js +3 -2
  136. package/lib/esm/actions/requirements/index.d.ts +2 -5
  137. package/lib/esm/actions/requirements/index.js +2 -5
  138. package/lib/esm/actions/signatures/getBlueAuthorizationAction.d.ts +29 -0
  139. package/lib/esm/actions/signatures/getBlueAuthorizationAction.js +44 -0
  140. package/lib/{cjs/actions/requirements/getRequirementsAction.d.ts → esm/actions/signatures/getTokenRequirementActions.d.ts} +17 -17
  141. package/lib/esm/actions/{requirements/getRequirementsAction.js → signatures/getTokenRequirementActions.js} +24 -11
  142. package/lib/esm/actions/signatures/index.d.ts +2 -0
  143. package/lib/esm/actions/signatures/index.js +2 -0
  144. package/lib/esm/actions/vaultV1/deposit.d.ts +6 -8
  145. package/lib/esm/actions/vaultV1/deposit.js +11 -21
  146. package/lib/esm/actions/vaultV1/migrateToV2.d.ts +6 -6
  147. package/lib/esm/actions/vaultV1/migrateToV2.js +12 -20
  148. package/lib/esm/actions/vaultV2/deposit.d.ts +6 -8
  149. package/lib/esm/actions/vaultV2/deposit.js +11 -21
  150. package/lib/esm/addresses.d.ts +2 -2
  151. package/lib/esm/addresses.js +1 -1
  152. package/lib/esm/bundler/actions.d.ts +44 -4
  153. package/lib/esm/bundler/actions.js +77 -4
  154. package/lib/esm/bundler/types.d.ts +6 -0
  155. package/lib/esm/constants.d.ts +2 -2
  156. package/lib/esm/constants.js +2 -2
  157. package/lib/esm/entities/blue/blue.d.ts +58 -33
  158. package/lib/esm/entities/blue/blue.js +311 -191
  159. package/lib/esm/entities/reallocationData.d.ts +0 -44
  160. package/lib/esm/entities/reallocationData.js +2 -49
  161. package/lib/esm/entities/vaultV1/vaultV1.d.ts +9 -9
  162. package/lib/esm/entities/vaultV1/vaultV1.js +46 -36
  163. package/lib/esm/entities/vaultV2/vaultV2.d.ts +6 -6
  164. package/lib/esm/entities/vaultV2/vaultV2.js +23 -18
  165. package/lib/esm/errors.d.ts +3 -2
  166. package/lib/esm/errors.js +2 -1
  167. package/lib/esm/helpers/index.d.ts +1 -1
  168. package/lib/esm/helpers/index.js +1 -1
  169. package/lib/esm/helpers/validate.d.ts +2 -20
  170. package/lib/esm/helpers/validate.js +2 -38
  171. package/lib/esm/types/action.d.ts +164 -12
  172. package/lib/esm/types/action.js +75 -4
  173. package/lib/esm/types/error.d.ts +97 -2
  174. package/lib/esm/types/error.js +107 -5
  175. package/lib/esm/types.d.ts +2 -1
  176. package/lib/esm/utils.d.ts +2 -2
  177. package/lib/esm/utils.js +2 -2
  178. package/package.json +22 -21
  179. package/lib/cjs/actions/requirements/getMorphoAuthorizationRequirement.d.ts +0 -37
  180. package/lib/cjs/actions/requirements/getMorphoAuthorizationRequirement.js +0 -71
  181. package/lib/cjs/actions/requirements/getRequirements.js +0 -112
  182. package/lib/cjs/actions/requirements/getRequirementsPermit.js +0 -57
  183. package/lib/cjs/actions/requirements/getRequirementsPermit2.d.ts +0 -63
  184. package/lib/cjs/actions/requirements/getRequirementsPermit2.js +0 -85
  185. package/lib/esm/actions/requirements/getMorphoAuthorizationRequirement.d.ts +0 -37
  186. package/lib/esm/actions/requirements/getMorphoAuthorizationRequirement.js +0 -67
  187. package/lib/esm/actions/requirements/getRequirements.js +0 -108
  188. package/lib/esm/actions/requirements/getRequirementsPermit.js +0 -53
  189. package/lib/esm/actions/requirements/getRequirementsPermit2.d.ts +0 -63
  190. package/lib/esm/actions/requirements/getRequirementsPermit2.js +0 -81
  191. package/src/index.ts +0 -4
@@ -132,6 +132,8 @@ export interface BlueRepayAction extends BaseAction<"blueRepay", {
132
132
  onBehalf: Address;
133
133
  receiver: Address;
134
134
  maxSharePrice: bigint;
135
+ /** Native token wrapped into wNative to fund the repay. Present when `> 0n`. */
136
+ nativeAmount?: bigint;
135
137
  }> {
136
138
  }
137
139
  export interface BlueWithdrawCollateralAction extends BaseAction<"blueWithdrawCollateral", {
@@ -150,6 +152,8 @@ export interface BlueRepayWithdrawCollateralAction extends BaseAction<"blueRepay
150
152
  maxSharePrice: bigint;
151
153
  onBehalf: Address;
152
154
  receiver: Address;
155
+ /** Native token wrapped into wNative to fund the repay. Present when `> 0n`. */
156
+ nativeAmount?: bigint;
153
157
  }> {
154
158
  }
155
159
  export interface BlueRefinanceAction extends BaseAction<"blueRefinance", {
@@ -171,21 +175,66 @@ export interface BlueRefinanceAction extends BaseAction<"blueRefinance", {
171
175
  * - `shares`: operate on an exact share count (typical for full position closes,
172
176
  * immune to interest accrual between tx construction and execution).
173
177
  *
174
- * Used by repay (asserts on borrow side) and withdraw (asserts on supply side).
178
+ * Used by withdraw (asserts on supply side). Repay uses {@link RepayAmountArgs},
179
+ * which additionally supports native wrapping.
175
180
  */
176
181
  export type AssetsOrSharesArgs = {
177
182
  assets: bigint;
178
183
  } | {
179
184
  shares: bigint;
180
185
  };
181
- /** @deprecated Use {@link AssetsOrSharesArgs}. Kept as an alias for back-compat. */
182
- export type RepayAmountArgs = AssetsOrSharesArgs;
183
- export interface MorphoAuthorizationAction extends BaseAction<"morphoAuthorization", {
186
+ /**
187
+ * Repay funding sources for the **entity layer** (`MorphoBlue.repay` /
188
+ * `MorphoBlue.repayWithdrawCollateral`), which computes the loan-token
189
+ * `transferAmount` itself from live market state.
190
+ *
191
+ * - **assets mode** ({@link DepositAmountArgs}): repay an exact asset total of
192
+ * `amount` (ERC-20) + `nativeAmount` (wrapped native). Additive — mirrors `blueSupply`.
193
+ * - **shares mode** (`{ shares }`): repay an exact borrow-share count (full close,
194
+ * immune to interest accrual). `nativeAmount` funds part of the transfer.
195
+ *
196
+ * `nativeAmount` requires the market's loan token to be the chain's wNative.
197
+ */
198
+ export type RepayAmountArgs = DepositAmountArgs | {
199
+ shares: bigint;
200
+ nativeAmount?: bigint;
201
+ };
202
+ /**
203
+ * Repay funding sources for the **action layer** (`blueRepay` /
204
+ * `blueRepayWithdrawCollateral`) — a flat, pre-resolved shape. The entity layer
205
+ * ({@link RepayAmountArgs}) derives these from live market state; the action does no
206
+ * amount arithmetic. The mode is discriminated on `shares`:
207
+ *
208
+ * - **assets mode** (`shares` unset/`0n`): repays `transferAmount` assets
209
+ * (`= amount + nativeAmount`, additive like `blueSupply`), pulling `amount` ERC-20
210
+ * and wrapping `nativeAmount`. No residual.
211
+ * - **shares mode** (`shares > 0n`): repays an exact borrow-share count (full close),
212
+ * pulling `transferAmount` ERC-20 (already net of native) and wrapping `nativeAmount`;
213
+ * the residual loan token is skimmed back to `receiver`.
214
+ *
215
+ * `nativeAmount` requires the market's loan token to be the chain's wNative.
216
+ */
217
+ export interface RepayActionAmountArgs {
218
+ /** Assets-mode ERC-20 loan tokens pulled from the payer. Omit (or `0n`) in shares mode. */
219
+ amount?: bigint;
220
+ /** Shares-mode borrow shares to repay (full close). Omit (or `0n`) in assets mode. */
221
+ shares?: bigint;
222
+ /** Native ETH wrapped into wNative to help fund the repay. Loan token must be wNative. */
223
+ nativeAmount?: bigint;
224
+ /**
225
+ * Loan tokens routed into `GeneralAdapter1`. Assets mode: the total repaid
226
+ * (`amount + nativeAmount`). Shares mode: the ERC-20 pulled
227
+ * (`toBorrowAssets(shares) − nativeAmount`).
228
+ */
229
+ transferAmount: bigint;
230
+ }
231
+ /** Metadata for a Blue authorization prerequisite transaction. */
232
+ export interface BlueAuthorizationAction extends BaseAction<"blueAuthorization", {
184
233
  authorized: Address;
185
234
  isAuthorized: boolean;
186
235
  }> {
187
236
  }
188
- export type TransactionAction = ERC20ApprovalAction | VaultV2DepositAction | VaultV2WithdrawAction | VaultV2RedeemAction | VaultV2ForceWithdrawAction | VaultV2ForceRedeemAction | VaultV1DepositAction | VaultV1WithdrawAction | VaultV1RedeemAction | VaultV1MigrateToV2Action | BlueSupplyAction | BlueWithdrawAction | BlueSupplyCollateralAction | BlueBorrowAction | BlueSupplyCollateralBorrowAction | BlueRepayAction | BlueWithdrawCollateralAction | BlueRepayWithdrawCollateralAction | BlueRefinanceAction | MorphoAuthorizationAction;
237
+ export type TransactionAction = ERC20ApprovalAction | VaultV2DepositAction | VaultV2WithdrawAction | VaultV2RedeemAction | VaultV2ForceWithdrawAction | VaultV2ForceRedeemAction | VaultV1DepositAction | VaultV1WithdrawAction | VaultV1RedeemAction | VaultV1MigrateToV2Action | BlueSupplyAction | BlueWithdrawAction | BlueSupplyCollateralAction | BlueBorrowAction | BlueSupplyCollateralBorrowAction | BlueRepayAction | BlueWithdrawCollateralAction | BlueRepayWithdrawCollateralAction | BlueRefinanceAction | BlueAuthorizationAction;
189
238
  export interface Transaction<TAction extends BaseAction = TransactionAction> {
190
239
  readonly to: Address;
191
240
  readonly value: bigint;
@@ -223,9 +272,36 @@ export interface Permit2Args {
223
272
  deadline: bigint;
224
273
  expiration: bigint;
225
274
  }
226
- export interface Requirement {
227
- sign: (client: WalletClient, userAddress: Address) => Promise<RequirementSignature>;
228
- action: PermitAction | Permit2Action;
275
+ /**
276
+ * Signed Morpho Blue authorization payload produced when an integrator opts into offchain
277
+ * signatures (`supportSignature: true`). Consumed by the action layer to emit a
278
+ * `setAuthorizationWithSig` bundler call in place of a standalone `setAuthorization` transaction.
279
+ */
280
+ export interface AuthorizationSignatureArgs {
281
+ /** Account granting the authorization (the position owner). */
282
+ owner: Address;
283
+ /** Account being authorized to operate on Morpho on the owner's behalf (GeneralAdapter1). */
284
+ authorized: Address;
285
+ /** Whether the authorization is granted (`true`) or revoked (`false`). */
286
+ isAuthorized: boolean;
287
+ /** Morpho authorization nonce consumed by the signature. */
288
+ nonce: bigint;
289
+ /** Signature deadline timestamp in seconds. */
290
+ deadline: bigint;
291
+ /** EIP-712 signature over the Morpho `Authorization` typed data. */
292
+ signature: Hex;
293
+ }
294
+ /**
295
+ * A signable approval / authorization requirement. `sign()` returns the matching
296
+ * {@link RequirementSignature}; `action` describes the requirement without signing.
297
+ *
298
+ * Generic over the signature it produces so permit encoders narrow to
299
+ * {@link PermitRequirementSignature} and the authorization encoder to
300
+ * {@link AuthorizationRequirementSignature}; the default keeps the broad union for mixed arrays.
301
+ */
302
+ export interface Requirement<TSignature extends RequirementSignature = RequirementSignature> {
303
+ sign: (client: WalletClient, userAddress: Address) => Promise<TSignature>;
304
+ action: TSignature["action"];
229
305
  }
230
306
  export interface PermitAction extends BaseAction<"permit", {
231
307
  spender: Address;
@@ -240,10 +316,86 @@ export interface Permit2Action extends BaseAction<"permit2", {
240
316
  expiration: bigint;
241
317
  }> {
242
318
  }
243
- export interface RequirementSignature {
319
+ /**
320
+ * Signable Morpho authorization requirement. Emitted by the entity layer when a bundled path
321
+ * needs GeneralAdapter1 authorized and the client opts into offchain signatures.
322
+ */
323
+ export interface AuthorizationAction extends BaseAction<"authorization", {
324
+ authorized: Address;
325
+ isAuthorized: boolean;
326
+ deadline: bigint;
327
+ }> {
328
+ }
329
+ /** A signed ERC-2612 permit or Permit2 approval requirement. */
330
+ export interface PermitRequirementSignature {
244
331
  args: PermitArgs | Permit2Args;
245
332
  action: PermitAction | Permit2Action;
246
333
  }
247
- export declare function isRequirementApproval(requirement: Transaction<ERC20ApprovalAction> | Transaction<MorphoAuthorizationAction> | Requirement | undefined): requirement is Transaction<ERC20ApprovalAction>;
248
- export declare function isRequirementAuthorization(requirement: Transaction<ERC20ApprovalAction> | Transaction<MorphoAuthorizationAction> | Requirement | undefined): requirement is Transaction<MorphoAuthorizationAction>;
249
- export declare function isRequirementSignature(requirement: Transaction<ERC20ApprovalAction> | Transaction<MorphoAuthorizationAction> | Requirement | undefined): requirement is Requirement;
334
+ /** A signed Morpho authorization requirement (consumed via `setAuthorizationWithSig`). */
335
+ export interface AuthorizationRequirementSignature {
336
+ args: AuthorizationSignatureArgs;
337
+ action: AuthorizationAction;
338
+ }
339
+ /**
340
+ * The deep-frozen output of `Requirement.sign()`. Discriminated on `action.type`:
341
+ * `"permit"` / `"permit2"` carry token-approval args, `"authorization"` carries the signed
342
+ * Morpho authorization. Narrow with {@link isPermitSignature} / {@link isAuthorizationSignature}.
343
+ */
344
+ export type RequirementSignature = PermitRequirementSignature | AuthorizationRequirementSignature;
345
+ /** Bundler3 token signature requirement. */
346
+ export type Bundler3TokenSignatureRequirement = Requirement<PermitRequirementSignature>;
347
+ export declare function isRequirementApproval(requirement: unknown): requirement is Transaction<ERC20ApprovalAction>;
348
+ /** Checks whether an action requirement is a Blue authorization transaction. */
349
+ export declare function isRequirementBlueAuthorization(requirement: unknown): requirement is Transaction<BlueAuthorizationAction>;
350
+ export declare function isRequirementSignature<T extends RequirementSignature = RequirementSignature>(requirement: Transaction<ERC20ApprovalAction> | Transaction<BlueAuthorizationAction> | Requirement<T> | undefined): requirement is Requirement<T>;
351
+ /**
352
+ * Narrows a {@link RequirementSignature} to a permit / Permit2 token-approval signature.
353
+ *
354
+ * @param signature - The signed requirement to test.
355
+ * @returns `true` when `signature.action.type` is `"permit"` or `"permit2"`.
356
+ */
357
+ export declare function isPermitSignature(signature: RequirementSignature): signature is PermitRequirementSignature;
358
+ /**
359
+ * Narrows a {@link RequirementSignature} to a signed Morpho authorization.
360
+ *
361
+ * @param signature - The signed requirement to test.
362
+ * @returns `true` when `signature.action.type` is `"authorization"`.
363
+ */
364
+ export declare function isAuthorizationSignature(signature: RequirementSignature): signature is AuthorizationRequirementSignature;
365
+ /** The typed permit / authorization slots a bundled path consumes, split from a `buildTx` array. */
366
+ export interface SelectedRequirementSignatures {
367
+ /** The single permit / Permit2 signature, when present. */
368
+ permit?: PermitRequirementSignature;
369
+ /** The single Morpho authorization signature, when present. */
370
+ authorization?: AuthorizationRequirementSignature;
371
+ }
372
+ /**
373
+ * Splits a `buildTx` signature array into its typed permit / authorization slots, rejecting
374
+ * ambiguous or unexpected input so a path never silently consumes the wrong signature.
375
+ *
376
+ * A bundled path consumes at most one permit and one authorization signature. Passing several of
377
+ * the same kind, or a kind the path does not consume, is rejected with a typed error rather than
378
+ * silently dropping the extras — the latter could otherwise leave a required authorization or
379
+ * permit unsigned (and the bundle reverting on-chain) or apply the wrong signature.
380
+ *
381
+ * @param signatures - The signatures passed to `buildTx`.
382
+ * @param accepts - Which signature kinds this operation consumes.
383
+ * @param accepts.permit - Whether a permit / Permit2 signature is consumed.
384
+ * @param accepts.authorization - Whether a Morpho authorization signature is consumed.
385
+ * @returns The single permit and/or authorization signature, when present.
386
+ * @throws {AmbiguousRequirementSignaturesError} when more than one signature of an accepted kind is present.
387
+ * @throws {UnexpectedRequirementSignatureError} when a signature of a kind the operation does not consume is present.
388
+ * @example
389
+ * ```ts
390
+ * import { selectRequirementSignatures } from "@morpho-org/morpho-sdk";
391
+ *
392
+ * const { permit, authorization } = selectRequirementSignatures(signatures, {
393
+ * permit: true,
394
+ * authorization: true,
395
+ * });
396
+ * ```
397
+ */
398
+ export declare function selectRequirementSignatures(signatures: readonly RequirementSignature[] | undefined, accepts: {
399
+ permit?: boolean;
400
+ authorization?: boolean;
401
+ }): SelectedRequirementSignatures;
@@ -1,26 +1,100 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.isRequirementApproval = isRequirementApproval;
4
- exports.isRequirementAuthorization = isRequirementAuthorization;
4
+ exports.isRequirementBlueAuthorization = isRequirementBlueAuthorization;
5
5
  exports.isRequirementSignature = isRequirementSignature;
6
+ exports.isPermitSignature = isPermitSignature;
7
+ exports.isAuthorizationSignature = isAuthorizationSignature;
8
+ exports.selectRequirementSignatures = selectRequirementSignatures;
9
+ const error_js_1 = require("./error.js");
6
10
  function isRequirementApproval(requirement) {
7
- return (requirement !== undefined &&
11
+ return (typeof requirement === "object" &&
12
+ requirement !== null &&
8
13
  "to" in requirement &&
9
14
  "value" in requirement &&
10
15
  "data" in requirement &&
11
16
  "action" in requirement &&
17
+ typeof requirement.action === "object" &&
18
+ requirement.action !== null &&
19
+ "type" in requirement.action &&
12
20
  requirement.action.type === "erc20Approval");
13
21
  }
14
- function isRequirementAuthorization(requirement) {
15
- return (requirement !== undefined &&
22
+ /** Checks whether an action requirement is a Blue authorization transaction. */
23
+ function isRequirementBlueAuthorization(requirement) {
24
+ return (typeof requirement === "object" &&
25
+ requirement !== null &&
16
26
  "to" in requirement &&
17
27
  "value" in requirement &&
18
28
  "data" in requirement &&
19
29
  "action" in requirement &&
20
- requirement.action.type === "morphoAuthorization");
30
+ typeof requirement.action === "object" &&
31
+ requirement.action !== null &&
32
+ "type" in requirement.action &&
33
+ requirement.action.type === "blueAuthorization");
21
34
  }
22
35
  function isRequirementSignature(requirement) {
23
36
  return (requirement !== undefined &&
37
+ typeof requirement === "object" &&
38
+ requirement !== null &&
24
39
  "sign" in requirement &&
25
40
  typeof requirement.sign === "function");
26
41
  }
42
+ /**
43
+ * Narrows a {@link RequirementSignature} to a permit / Permit2 token-approval signature.
44
+ *
45
+ * @param signature - The signed requirement to test.
46
+ * @returns `true` when `signature.action.type` is `"permit"` or `"permit2"`.
47
+ */
48
+ function isPermitSignature(signature) {
49
+ return (signature.action.type === "permit" || signature.action.type === "permit2");
50
+ }
51
+ /**
52
+ * Narrows a {@link RequirementSignature} to a signed Morpho authorization.
53
+ *
54
+ * @param signature - The signed requirement to test.
55
+ * @returns `true` when `signature.action.type` is `"authorization"`.
56
+ */
57
+ function isAuthorizationSignature(signature) {
58
+ return signature.action.type === "authorization";
59
+ }
60
+ /**
61
+ * Splits a `buildTx` signature array into its typed permit / authorization slots, rejecting
62
+ * ambiguous or unexpected input so a path never silently consumes the wrong signature.
63
+ *
64
+ * A bundled path consumes at most one permit and one authorization signature. Passing several of
65
+ * the same kind, or a kind the path does not consume, is rejected with a typed error rather than
66
+ * silently dropping the extras — the latter could otherwise leave a required authorization or
67
+ * permit unsigned (and the bundle reverting on-chain) or apply the wrong signature.
68
+ *
69
+ * @param signatures - The signatures passed to `buildTx`.
70
+ * @param accepts - Which signature kinds this operation consumes.
71
+ * @param accepts.permit - Whether a permit / Permit2 signature is consumed.
72
+ * @param accepts.authorization - Whether a Morpho authorization signature is consumed.
73
+ * @returns The single permit and/or authorization signature, when present.
74
+ * @throws {AmbiguousRequirementSignaturesError} when more than one signature of an accepted kind is present.
75
+ * @throws {UnexpectedRequirementSignatureError} when a signature of a kind the operation does not consume is present.
76
+ * @example
77
+ * ```ts
78
+ * import { selectRequirementSignatures } from "@morpho-org/morpho-sdk";
79
+ *
80
+ * const { permit, authorization } = selectRequirementSignatures(signatures, {
81
+ * permit: true,
82
+ * authorization: true,
83
+ * });
84
+ * ```
85
+ */
86
+ function selectRequirementSignatures(signatures, accepts) {
87
+ if (signatures == null)
88
+ return {};
89
+ const permits = signatures.filter(isPermitSignature);
90
+ const authorizations = signatures.filter(isAuthorizationSignature);
91
+ if (!accepts.permit && permits.length > 0)
92
+ throw new error_js_1.UnexpectedRequirementSignatureError("permit");
93
+ if (!accepts.authorization && authorizations.length > 0)
94
+ throw new error_js_1.UnexpectedRequirementSignatureError("authorization");
95
+ if (permits.length > 1)
96
+ throw new error_js_1.AmbiguousRequirementSignaturesError("permit", permits.length);
97
+ if (authorizations.length > 1)
98
+ throw new error_js_1.AmbiguousRequirementSignaturesError("authorization", authorizations.length);
99
+ return { permit: permits[0], authorization: authorizations[0] };
100
+ }
@@ -43,6 +43,67 @@ export declare namespace BundlerErrors {
43
43
  */
44
44
  constructor(type: string, chainId: number);
45
45
  }
46
+ /**
47
+ * Thrown when a Morpho authorization signature names a forbidden `authorized` account
48
+ * (for example Bundler3 itself), which would grant operator rights to an unintended address.
49
+ *
50
+ * @example
51
+ * ```ts
52
+ * import { BundlerErrors } from "@morpho-org/morpho-sdk";
53
+ *
54
+ * if (error instanceof BundlerErrors.UnexpectedSignature) {
55
+ * // Re-sign the authorization targeting GeneralAdapter1.
56
+ * }
57
+ * ```
58
+ */
59
+ class UnexpectedSignature extends Error {
60
+ /**
61
+ * @param authorized - The forbidden `authorized` address carried by the signature.
62
+ */
63
+ constructor(authorized: Address);
64
+ }
65
+ }
66
+ /**
67
+ * Thrown when `buildTx` receives more than one requirement signature of the same kind.
68
+ *
69
+ * A bundled path consumes at most one permit and one authorization signature; passing several of
70
+ * the same kind is ambiguous and would silently drop all but the first, so it is rejected instead.
71
+ *
72
+ * @example
73
+ * ```ts
74
+ * import { AmbiguousRequirementSignaturesError } from "@morpho-org/morpho-sdk";
75
+ *
76
+ * if (error instanceof AmbiguousRequirementSignaturesError) {
77
+ * // Pass a single permit (and at most one authorization) signature to buildTx.
78
+ * }
79
+ * ```
80
+ */
81
+ export declare class AmbiguousRequirementSignaturesError extends Error {
82
+ /**
83
+ * @param kind - The over-supplied signature kind (`"permit"` or `"authorization"`).
84
+ * @param count - How many signatures of that kind were received.
85
+ */
86
+ constructor(kind: "permit" | "authorization", count: number);
87
+ }
88
+ /**
89
+ * Thrown when `buildTx` receives a requirement signature of a kind the operation does not consume
90
+ * (for example an authorization signature on a plain supply path). Surfacing it prevents a signed
91
+ * authorization or permit from being silently ignored.
92
+ *
93
+ * @example
94
+ * ```ts
95
+ * import { UnexpectedRequirementSignatureError } from "@morpho-org/morpho-sdk";
96
+ *
97
+ * if (error instanceof UnexpectedRequirementSignatureError) {
98
+ * // Remove the signature this operation does not use from the buildTx array.
99
+ * }
100
+ * ```
101
+ */
102
+ export declare class UnexpectedRequirementSignatureError extends Error {
103
+ /**
104
+ * @param kind - The unexpected signature kind (`"permit"` or `"authorization"`).
105
+ */
106
+ constructor(kind: "permit" | "authorization");
46
107
  }
47
108
  /** Thrown when an asset amount is required to be positive but is zero or negative. */
48
109
  export declare class NonPositiveAssetAmountError extends Error {
@@ -72,6 +133,18 @@ export declare class MissingClientPropertyError extends Error {
72
133
  export declare class ApprovalAmountLessThanSpendAmountError extends Error {
73
134
  constructor();
74
135
  }
136
+ /** Thrown when a requirement encoder targets an unsupported spender. */
137
+ export declare class UnsupportedErc20ApprovalSpenderError extends Error {
138
+ constructor(params: {
139
+ readonly spender: Address;
140
+ readonly chainId: number;
141
+ readonly generalAdapter1: Address;
142
+ readonly permit2?: Address;
143
+ readonly midnight?: Address;
144
+ readonly midnightBundles?: Address;
145
+ readonly supportedSpenders?: readonly (Address | undefined)[];
146
+ });
147
+ }
75
148
  /** Thrown when a slippage tolerance is negative. */
76
149
  export declare class NegativeSlippageToleranceError extends Error {
77
150
  constructor(slippageTolerance: bigint);
@@ -171,11 +244,22 @@ export declare class ReallocationWithdrawalOnTargetMarketError extends Error {
171
244
  export declare class UnsortedReallocationWithdrawalsError extends Error {
172
245
  constructor(vault: string, marketId: string);
173
246
  }
174
- /** Thrown when a market repay's `transferAmount` is zero or negative. */
247
+ /**
248
+ * Thrown when a market repay's `transferAmount` is zero or negative.
249
+ *
250
+ * @deprecated No longer thrown. The repay action layer no longer validates `transferAmount`
251
+ * directly (assets mode uses {@link NonPositiveRepayAmountError}; shares mode allows a zero
252
+ * ERC-20 transfer for fully-native repays). Retained as exported API for back-compat; slated
253
+ * for removal in a future major.
254
+ */
175
255
  export declare class NonPositiveTransferAmountError extends Error {
176
256
  constructor(market: string);
177
257
  }
178
- /** Thrown when a market repay in assets mode has `transferAmount !== assets` (asset-mode requires exact transfer). */
258
+ /**
259
+ * Thrown when a market repay in assets mode has `transferAmount !== amount + nativeAmount` — the
260
+ * pre-resolved ERC-20 pull plus the wrapped native must equal the assets repaid, so the bundle
261
+ * neither strands over-pulled loan tokens on `GeneralAdapter1` nor under-funds the repay.
262
+ */
179
263
  export declare class TransferAmountNotEqualToAssetsError extends Error {
180
264
  constructor(params: {
181
265
  transferAmount: bigint;
@@ -183,6 +267,17 @@ export declare class TransferAmountNotEqualToAssetsError extends Error {
183
267
  market: string;
184
268
  });
185
269
  }
270
+ /**
271
+ * Thrown when a shares-mode repay's `nativeAmount` exceeds `transferAmount`, which
272
+ * would make the ERC-20 amount to pull (`transferAmount − nativeAmount`) negative.
273
+ */
274
+ export declare class NativeAmountExceedsTransferAmountError extends Error {
275
+ constructor(params: {
276
+ nativeAmount: bigint;
277
+ transferAmount: bigint;
278
+ market: string;
279
+ });
280
+ }
186
281
  /** Thrown when a market repay specifies both `assets` and `shares` as non-zero (modes are mutually exclusive). */
187
282
  export declare class MutuallyExclusiveRepayAmountsError extends Error {
188
283
  constructor(market: string);
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.UnknownReallocationVaultError = exports.UnknownReallocationMarketError = exports.InsufficientSharedLiquidityError = exports.DisabledReallocationMarketError = exports.MissingPublicAllocatorConfigError = exports.RepaySharesExceedDebtError = exports.InvalidSignatureError = exports.RepayExceedsDebtError = exports.ShareDivideByZeroError = exports.WithdrawMakesPositionUnhealthyError = exports.WithdrawExceedsCollateralError = exports.NonPositiveWithdrawCollateralAmountError = exports.NonPositiveRepayMaxSharePriceError = exports.NonPositiveRepayAmountError = exports.MutuallyExclusiveRepayAmountsError = exports.TransferAmountNotEqualToAssetsError = exports.NonPositiveTransferAmountError = exports.UnsortedReallocationWithdrawalsError = exports.ReallocationWithdrawalOnTargetMarketError = exports.NonPositiveReallocationAmountError = exports.EmptyReallocationWithdrawalsError = exports.NegativeReallocationFeeError = exports.AccrualPositionUserMismatchError = exports.MarketIdMismatchError = exports.MissingMarketPriceError = exports.BorrowExceedsSafeLtvError = exports.NativeAmountOnNonWNativeCollateralError = exports.NativeAmountOnNonWNativeAssetError = exports.ZeroCollateralAmountError = exports.NonPositiveBorrowAmountError = exports.VaultAddressMismatchError = exports.ZeroDepositAmountError = exports.NegativeNativeAmountError = exports.ChainWNativeMissingError = exports.NativeAmountOnNonWNativeVaultError = exports.Permit2ExpirationMissingError = exports.DepositAssetMismatchError = exports.DepositAmountMismatchError = exports.EmptyDeallocationsError = exports.ExcessiveSlippageToleranceError = exports.MissingAccrualPositionError = exports.NegativeSlippageToleranceError = exports.ApprovalAmountLessThanSpendAmountError = exports.MissingClientPropertyError = exports.ChainIdMismatchError = exports.AddressMismatchError = exports.NonPositiveMaxSharePriceError = exports.NonPositiveSharesAmountError = exports.NonPositiveAssetAmountError = exports.BundlerErrors = void 0;
4
- exports.RefinanceSharesMissingBorrowAssetsError = exports.RefinanceExceedsBorrowAssetsError = exports.RefinanceExceedsBorrowSharesError = exports.RefinanceExceedsCollateralError = exports.RefinanceTokenMismatchError = exports.RefinanceSameMarketError = exports.NegativeMaxRepaySharePriceError = exports.BorrowAmountAndSharesExclusiveError = exports.NegativeBorrowSharesError = exports.NegativeMinSharePriceError = exports.VaultAssetMismatchError = exports.ReallocationWithdrawExceedsMarketSupplyError = exports.WithdrawSharesExceedSupplyError = exports.WithdrawExceedsSupplyError = exports.MutuallyExclusiveWithdrawAmountsError = exports.NegativeWithdrawMinSharePriceError = exports.NonPositiveWithdrawAmountError = exports.ZeroSupplyAmountError = exports.NegativeSupplyMaxSharePriceError = exports.NegativeSupplyAmountError = exports.NonPositiveMinBorrowSharePriceError = exports.UnknownReallocationPositionError = exports.UnknownReallocationVaultMarketConfigError = void 0;
3
+ exports.MissingPublicAllocatorConfigError = exports.RepaySharesExceedDebtError = exports.InvalidSignatureError = exports.RepayExceedsDebtError = exports.ShareDivideByZeroError = exports.WithdrawMakesPositionUnhealthyError = exports.WithdrawExceedsCollateralError = exports.NonPositiveWithdrawCollateralAmountError = exports.NonPositiveRepayMaxSharePriceError = exports.NonPositiveRepayAmountError = exports.MutuallyExclusiveRepayAmountsError = exports.NativeAmountExceedsTransferAmountError = exports.TransferAmountNotEqualToAssetsError = exports.NonPositiveTransferAmountError = exports.UnsortedReallocationWithdrawalsError = exports.ReallocationWithdrawalOnTargetMarketError = exports.NonPositiveReallocationAmountError = exports.EmptyReallocationWithdrawalsError = exports.NegativeReallocationFeeError = exports.AccrualPositionUserMismatchError = exports.MarketIdMismatchError = exports.MissingMarketPriceError = exports.BorrowExceedsSafeLtvError = exports.NativeAmountOnNonWNativeCollateralError = exports.NativeAmountOnNonWNativeAssetError = exports.ZeroCollateralAmountError = exports.NonPositiveBorrowAmountError = exports.VaultAddressMismatchError = exports.ZeroDepositAmountError = exports.NegativeNativeAmountError = exports.ChainWNativeMissingError = exports.NativeAmountOnNonWNativeVaultError = exports.Permit2ExpirationMissingError = exports.DepositAssetMismatchError = exports.DepositAmountMismatchError = exports.EmptyDeallocationsError = exports.ExcessiveSlippageToleranceError = exports.MissingAccrualPositionError = exports.NegativeSlippageToleranceError = exports.UnsupportedErc20ApprovalSpenderError = exports.ApprovalAmountLessThanSpendAmountError = exports.MissingClientPropertyError = exports.ChainIdMismatchError = exports.AddressMismatchError = exports.NonPositiveMaxSharePriceError = exports.NonPositiveSharesAmountError = exports.NonPositiveAssetAmountError = exports.UnexpectedRequirementSignatureError = exports.AmbiguousRequirementSignaturesError = exports.BundlerErrors = void 0;
4
+ exports.RefinanceSharesMissingBorrowAssetsError = exports.RefinanceExceedsBorrowAssetsError = exports.RefinanceExceedsBorrowSharesError = exports.RefinanceExceedsCollateralError = exports.RefinanceTokenMismatchError = exports.RefinanceSameMarketError = exports.NegativeMaxRepaySharePriceError = exports.BorrowAmountAndSharesExclusiveError = exports.NegativeBorrowSharesError = exports.NegativeMinSharePriceError = exports.VaultAssetMismatchError = exports.ReallocationWithdrawExceedsMarketSupplyError = exports.WithdrawSharesExceedSupplyError = exports.WithdrawExceedsSupplyError = exports.MutuallyExclusiveWithdrawAmountsError = exports.NegativeWithdrawMinSharePriceError = exports.NonPositiveWithdrawAmountError = exports.ZeroSupplyAmountError = exports.NegativeSupplyMaxSharePriceError = exports.NegativeSupplyAmountError = exports.NonPositiveMinBorrowSharePriceError = exports.UnknownReallocationPositionError = exports.UnknownReallocationVaultMarketConfigError = exports.UnknownReallocationVaultError = exports.UnknownReallocationMarketError = exports.InsufficientSharedLiquidityError = exports.DisabledReallocationMarketError = void 0;
5
5
  const blue_sdk_1 = require("@morpho-org/blue-sdk");
6
6
  /**
7
7
  * Typed errors thrown while encoding supported Bundler3 actions.
@@ -53,7 +53,77 @@ var BundlerErrors;
53
53
  }
54
54
  }
55
55
  BundlerErrors.UnexpectedAction = UnexpectedAction;
56
+ /**
57
+ * Thrown when a Morpho authorization signature names a forbidden `authorized` account
58
+ * (for example Bundler3 itself), which would grant operator rights to an unintended address.
59
+ *
60
+ * @example
61
+ * ```ts
62
+ * import { BundlerErrors } from "@morpho-org/morpho-sdk";
63
+ *
64
+ * if (error instanceof BundlerErrors.UnexpectedSignature) {
65
+ * // Re-sign the authorization targeting GeneralAdapter1.
66
+ * }
67
+ * ```
68
+ */
69
+ class UnexpectedSignature extends Error {
70
+ /**
71
+ * @param authorized - The forbidden `authorized` address carried by the signature.
72
+ */
73
+ constructor(authorized) {
74
+ super(`unexpected signature authorizing "${authorized}"`);
75
+ }
76
+ }
77
+ BundlerErrors.UnexpectedSignature = UnexpectedSignature;
56
78
  })(BundlerErrors || (exports.BundlerErrors = BundlerErrors = {}));
79
+ /**
80
+ * Thrown when `buildTx` receives more than one requirement signature of the same kind.
81
+ *
82
+ * A bundled path consumes at most one permit and one authorization signature; passing several of
83
+ * the same kind is ambiguous and would silently drop all but the first, so it is rejected instead.
84
+ *
85
+ * @example
86
+ * ```ts
87
+ * import { AmbiguousRequirementSignaturesError } from "@morpho-org/morpho-sdk";
88
+ *
89
+ * if (error instanceof AmbiguousRequirementSignaturesError) {
90
+ * // Pass a single permit (and at most one authorization) signature to buildTx.
91
+ * }
92
+ * ```
93
+ */
94
+ class AmbiguousRequirementSignaturesError extends Error {
95
+ /**
96
+ * @param kind - The over-supplied signature kind (`"permit"` or `"authorization"`).
97
+ * @param count - How many signatures of that kind were received.
98
+ */
99
+ constructor(kind, count) {
100
+ super(`Expected at most one ${kind} signature but received ${count}. Pass a single ${kind} signature to buildTx.`);
101
+ }
102
+ }
103
+ exports.AmbiguousRequirementSignaturesError = AmbiguousRequirementSignaturesError;
104
+ /**
105
+ * Thrown when `buildTx` receives a requirement signature of a kind the operation does not consume
106
+ * (for example an authorization signature on a plain supply path). Surfacing it prevents a signed
107
+ * authorization or permit from being silently ignored.
108
+ *
109
+ * @example
110
+ * ```ts
111
+ * import { UnexpectedRequirementSignatureError } from "@morpho-org/morpho-sdk";
112
+ *
113
+ * if (error instanceof UnexpectedRequirementSignatureError) {
114
+ * // Remove the signature this operation does not use from the buildTx array.
115
+ * }
116
+ * ```
117
+ */
118
+ class UnexpectedRequirementSignatureError extends Error {
119
+ /**
120
+ * @param kind - The unexpected signature kind (`"permit"` or `"authorization"`).
121
+ */
122
+ constructor(kind) {
123
+ super(`Received a ${kind} signature that this operation does not consume. Remove it from the buildTx signatures array.`);
124
+ }
125
+ }
126
+ exports.UnexpectedRequirementSignatureError = UnexpectedRequirementSignatureError;
57
127
  /** Thrown when an asset amount is required to be positive but is zero or negative. */
58
128
  class NonPositiveAssetAmountError extends Error {
59
129
  constructor(origin) {
@@ -103,6 +173,21 @@ class ApprovalAmountLessThanSpendAmountError extends Error {
103
173
  }
104
174
  }
105
175
  exports.ApprovalAmountLessThanSpendAmountError = ApprovalAmountLessThanSpendAmountError;
176
+ /** Thrown when a requirement encoder targets an unsupported spender. */
177
+ class UnsupportedErc20ApprovalSpenderError extends Error {
178
+ constructor(params) {
179
+ const supported = (params.supportedSpenders ?? [
180
+ params.generalAdapter1,
181
+ params.permit2,
182
+ params.midnight,
183
+ params.midnightBundles,
184
+ ])
185
+ .filter((address) => address != null)
186
+ .join('", "');
187
+ super(`Requirement spender "${params.spender}" is not supported on chain "${params.chainId}". Use "${supported}".`);
188
+ }
189
+ }
190
+ exports.UnsupportedErc20ApprovalSpenderError = UnsupportedErc20ApprovalSpenderError;
106
191
  /** Thrown when a slippage tolerance is negative. */
107
192
  class NegativeSlippageToleranceError extends Error {
108
193
  constructor(slippageTolerance) {
@@ -134,14 +219,14 @@ exports.EmptyDeallocationsError = EmptyDeallocationsError;
134
219
  /** Thrown when a deposit's amount differs from the amount the supplied permit / permit2 signature was issued for. */
135
220
  class DepositAmountMismatchError extends Error {
136
221
  constructor(depositAmount, signatureAmount) {
137
- super(`Deposit amount ${depositAmount} does not match requirement signature amount ${signatureAmount}`);
222
+ super(`Deposit amount "${depositAmount}" does not match requirement signature amount "${signatureAmount}"`);
138
223
  }
139
224
  }
140
225
  exports.DepositAmountMismatchError = DepositAmountMismatchError;
141
226
  /** Thrown when a deposit's asset differs from the asset the supplied permit / permit2 signature was issued for. */
142
227
  class DepositAssetMismatchError extends Error {
143
228
  constructor(depositAsset, signatureAsset) {
144
- super(`Deposit asset ${depositAsset} does not match requirement signature asset ${signatureAsset}`);
229
+ super(`Deposit asset "${depositAsset}" does not match requirement signature asset "${signatureAsset}"`);
145
230
  }
146
231
  }
147
232
  exports.DepositAssetMismatchError = DepositAssetMismatchError;
@@ -273,20 +358,41 @@ class UnsortedReallocationWithdrawalsError extends Error {
273
358
  }
274
359
  }
275
360
  exports.UnsortedReallocationWithdrawalsError = UnsortedReallocationWithdrawalsError;
276
- /** Thrown when a market repay's `transferAmount` is zero or negative. */
361
+ /**
362
+ * Thrown when a market repay's `transferAmount` is zero or negative.
363
+ *
364
+ * @deprecated No longer thrown. The repay action layer no longer validates `transferAmount`
365
+ * directly (assets mode uses {@link NonPositiveRepayAmountError}; shares mode allows a zero
366
+ * ERC-20 transfer for fully-native repays). Retained as exported API for back-compat; slated
367
+ * for removal in a future major.
368
+ */
277
369
  class NonPositiveTransferAmountError extends Error {
278
370
  constructor(market) {
279
371
  super(`Transfer amount must be positive for market: ${market}`);
280
372
  }
281
373
  }
282
374
  exports.NonPositiveTransferAmountError = NonPositiveTransferAmountError;
283
- /** Thrown when a market repay in assets mode has `transferAmount !== assets` (asset-mode requires exact transfer). */
375
+ /**
376
+ * Thrown when a market repay in assets mode has `transferAmount !== amount + nativeAmount` — the
377
+ * pre-resolved ERC-20 pull plus the wrapped native must equal the assets repaid, so the bundle
378
+ * neither strands over-pulled loan tokens on `GeneralAdapter1` nor under-funds the repay.
379
+ */
284
380
  class TransferAmountNotEqualToAssetsError extends Error {
285
381
  constructor(params) {
286
- super(`Transfer amount ${params.transferAmount} is not equal to repay assets ${params.assets} for market: ${params.market}`);
382
+ super(`Transfer amount ${params.transferAmount} is not equal to repay assets ${params.assets} for market: ${params.market}. In assets mode, transferAmount must equal amount + nativeAmount.`);
287
383
  }
288
384
  }
289
385
  exports.TransferAmountNotEqualToAssetsError = TransferAmountNotEqualToAssetsError;
386
+ /**
387
+ * Thrown when a shares-mode repay's `nativeAmount` exceeds `transferAmount`, which
388
+ * would make the ERC-20 amount to pull (`transferAmount − nativeAmount`) negative.
389
+ */
390
+ class NativeAmountExceedsTransferAmountError extends Error {
391
+ constructor(params) {
392
+ super(`Native amount ${params.nativeAmount} exceeds transfer amount ${params.transferAmount} for market: ${params.market}. Reduce nativeAmount to at most transferAmount.`);
393
+ }
394
+ }
395
+ exports.NativeAmountExceedsTransferAmountError = NativeAmountExceedsTransferAmountError;
290
396
  /** Thrown when a market repay specifies both `assets` and `shares` as non-zero (modes are mutually exclusive). */
291
397
  class MutuallyExclusiveRepayAmountsError extends Error {
292
398
  constructor(market) {
@@ -1,3 +1,4 @@
1
- export type { BigIntish, ChainMetadata, CollateralAllocation, Eip712Field, Erc20AllowanceRecipient, Failable, Fetchable, InputMarketParams, IPermit2Allowance, Loadable, MarketId, MaxBorrowOptions, MaxPositionCapacities, MaxWithdrawCollateralOptions, Pending, Permit2Allowance, } from "@morpho-org/blue-sdk";
1
+ export type { BigIntish, CollateralAllocation, Eip712Field, Erc20AllowanceRecipient, Failable, Fetchable, InputMarketParams, IPermit2Allowance, Loadable, MarketId, MaxBorrowOptions, MaxPositionCapacities, MaxWithdrawCollateralOptions, Pending, Permit2Allowance, } from "@morpho-org/blue-sdk";
2
2
  export type { DeploylessFetchParameters, FetchParameters, } from "@morpho-org/blue-sdk-viem";
3
+ export type { ChainMetadata } from "@morpho-org/morpho-ts";
3
4
  export * from "./types/index.js";
@@ -1,9 +1,9 @@
1
1
  export type { CapacityLimit, RoundingDirection } from "@morpho-org/blue-sdk";
2
2
  export { AdaptiveCurveIrmLib, CapacityLimitReason, MarketUtils, MathLib, SharesMath, VaultUtils, } from "@morpho-org/blue-sdk";
3
- export { decodeBytes32String, getAuthorizationTypedData, getDaiPermitTypedData, getPermit2PermitTypedData, getPermit2TransferFromTypedData, getPermitTypedData, optionalBoolean, readContractRestructured, restructure, safeGetAddress, safeParseNumber, safeParseUnits, } from "@morpho-org/blue-sdk-viem";
3
+ export { decodeBytes32String, getAuthorizationTypedData, getPermit2PermitTypedData, getPermit2TransferFromTypedData, getPermitTypedData, optionalBoolean, readContractRestructured, restructure, safeGetAddress, safeParseNumber, safeParseUnits, } from "@morpho-org/blue-sdk-viem";
4
4
  export type { ArrayElementType, DeepPartial, DottedKeys, FieldType, PartialDottedKeys, WithId, WithIndex, } from "@morpho-org/morpho-ts";
5
5
  export { bigIntComparator, createGetValue, createHasValue, deepFreeze, entries, filterDefined, fromEntries, getLast, getLastDefined, getSubdomainBaseUrl, getValue, hasValue, isDefined, isNotNull, isNotUndefined, keys, mergeEntries, retryPromiseLinearBackoff, Time, transformValue, values, } from "@morpho-org/morpho-ts";
6
6
  export { computeReallocations } from "./helpers/computeReallocations.js";
7
7
  export { addTransactionMetadata } from "./helpers/metadata.js";
8
8
  export { computeMaxRepaySharePrice, computeMinBorrowSharePrice, } from "./helpers/slippage.js";
9
- export { validateAccrualPosition, validateChainId, validateNativeAsset, validatePositionHealth, validatePositionHealthAfterWithdraw, validateReallocations, validateRepayAmount, validateRepayParams, validateRepayShares, validateSlippageTolerance, validateUserAddress, } from "./helpers/validate.js";
9
+ export { validateAccrualPosition, validateChainId, validateNativeAsset, validatePositionHealth, validatePositionHealthAfterWithdraw, validateReallocations, validateRepayAmount, validateRepayShares, validateSlippageTolerance, validateUserAddress, } from "./helpers/validate.js";