@morpho-org/morpho-sdk 4.2.0 → 5.0.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 (178) hide show
  1. package/README.md +12 -12
  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/refinance.d.ts +13 -3
  5. package/lib/cjs/actions/blue/refinance.js +8 -2
  6. package/lib/cjs/actions/blue/repay.d.ts +6 -5
  7. package/lib/cjs/actions/blue/repay.js +10 -18
  8. package/lib/cjs/actions/blue/repayWithdrawCollateral.d.ts +15 -6
  9. package/lib/cjs/actions/blue/repayWithdrawCollateral.js +16 -18
  10. package/lib/cjs/actions/blue/supply.d.ts +7 -7
  11. package/lib/cjs/actions/blue/supply.js +10 -20
  12. package/lib/cjs/actions/blue/supplyCollateral.d.ts +8 -8
  13. package/lib/cjs/actions/blue/supplyCollateral.js +11 -21
  14. package/lib/cjs/actions/blue/supplyCollateralBorrow.d.ts +18 -6
  15. package/lib/cjs/actions/blue/supplyCollateralBorrow.js +17 -19
  16. package/lib/cjs/actions/blue/withdraw.d.ts +10 -2
  17. package/lib/cjs/actions/blue/withdraw.js +7 -1
  18. package/lib/cjs/actions/index.d.ts +1 -0
  19. package/lib/cjs/actions/index.js +1 -0
  20. package/lib/cjs/actions/requirements/blue/getBlueAuthorizationRequirement.d.ts +49 -0
  21. package/lib/cjs/actions/requirements/blue/getBlueAuthorizationRequirement.js +111 -0
  22. package/lib/cjs/actions/requirements/blue/index.d.ts +1 -0
  23. package/lib/cjs/actions/requirements/blue/index.js +17 -0
  24. package/lib/cjs/actions/requirements/encode/encodeBlueSignatureAuthorization.d.ts +55 -0
  25. package/lib/cjs/actions/requirements/encode/encodeBlueSignatureAuthorization.js +89 -0
  26. package/lib/cjs/actions/requirements/encode/encodeErc20Approval.d.ts +6 -5
  27. package/lib/cjs/actions/requirements/encode/encodeErc20Approval.js +17 -5
  28. package/lib/cjs/actions/requirements/encode/encodeErc20Permit.d.ts +9 -7
  29. package/lib/cjs/actions/requirements/encode/encodeErc20Permit.js +18 -4
  30. package/lib/cjs/actions/requirements/encode/{encodeErc20Permit2.d.ts → encodeErc20Permit2Approve.d.ts} +11 -13
  31. package/lib/cjs/actions/requirements/encode/{encodeErc20Permit2.js → encodeErc20Permit2Approve.js} +10 -14
  32. package/lib/cjs/actions/requirements/encode/index.d.ts +2 -1
  33. package/lib/cjs/actions/requirements/encode/index.js +2 -1
  34. package/lib/cjs/actions/requirements/{getRequirements.d.ts → generalAdapter/getGeneralAdapterRequirements.d.ts} +34 -20
  35. package/lib/cjs/actions/requirements/generalAdapter/getGeneralAdapterRequirements.js +151 -0
  36. package/lib/{esm/actions/requirements/getRequirementsPermit.d.ts → cjs/actions/requirements/generalAdapter/getGeneralAdapterRequirementsPermit.d.ts} +6 -14
  37. package/lib/cjs/actions/requirements/generalAdapter/getGeneralAdapterRequirementsPermit.js +50 -0
  38. package/lib/cjs/actions/requirements/generalAdapter/getGeneralAdapterRequirementsPermit2.d.ts +57 -0
  39. package/lib/cjs/actions/requirements/generalAdapter/getGeneralAdapterRequirementsPermit2.js +74 -0
  40. package/lib/cjs/actions/requirements/generalAdapter/index.d.ts +3 -0
  41. package/lib/cjs/actions/requirements/generalAdapter/index.js +19 -0
  42. package/lib/cjs/actions/requirements/getRequirementsApproval.d.ts +3 -2
  43. package/lib/cjs/actions/requirements/getRequirementsApproval.js +3 -2
  44. package/lib/cjs/actions/requirements/index.d.ts +2 -5
  45. package/lib/cjs/actions/requirements/index.js +2 -5
  46. package/lib/cjs/actions/signatures/getBlueAuthorizationAction.d.ts +29 -0
  47. package/lib/cjs/actions/signatures/getBlueAuthorizationAction.js +48 -0
  48. package/lib/{esm/actions/requirements/getRequirementsAction.d.ts → cjs/actions/signatures/getTokenRequirementActions.d.ts} +17 -17
  49. package/lib/cjs/actions/{requirements/getRequirementsAction.js → signatures/getTokenRequirementActions.js} +26 -13
  50. package/lib/cjs/actions/signatures/index.d.ts +2 -0
  51. package/lib/cjs/actions/signatures/index.js +18 -0
  52. package/lib/cjs/actions/vaultV1/deposit.d.ts +6 -8
  53. package/lib/cjs/actions/vaultV1/deposit.js +11 -21
  54. package/lib/cjs/actions/vaultV1/migrateToV2.d.ts +6 -6
  55. package/lib/cjs/actions/vaultV1/migrateToV2.js +12 -20
  56. package/lib/cjs/actions/vaultV2/deposit.d.ts +6 -8
  57. package/lib/cjs/actions/vaultV2/deposit.js +11 -21
  58. package/lib/cjs/addresses.d.ts +2 -2
  59. package/lib/cjs/addresses.js +2 -1
  60. package/lib/cjs/bundler/actions.d.ts +44 -4
  61. package/lib/cjs/bundler/actions.js +75 -2
  62. package/lib/cjs/bundler/types.d.ts +6 -0
  63. package/lib/cjs/constants.d.ts +2 -2
  64. package/lib/cjs/constants.js +3 -3
  65. package/lib/cjs/entities/blue/blue.d.ts +58 -33
  66. package/lib/cjs/entities/blue/blue.js +171 -125
  67. package/lib/cjs/entities/reallocationData.d.ts +0 -44
  68. package/lib/cjs/entities/reallocationData.js +3 -50
  69. package/lib/cjs/entities/vaultV1/vaultV1.d.ts +9 -9
  70. package/lib/cjs/entities/vaultV1/vaultV1.js +44 -34
  71. package/lib/cjs/entities/vaultV2/vaultV2.d.ts +6 -6
  72. package/lib/cjs/entities/vaultV2/vaultV2.js +21 -16
  73. package/lib/cjs/errors.d.ts +3 -2
  74. package/lib/cjs/errors.js +5 -2
  75. package/lib/cjs/helpers/validate.d.ts +2 -2
  76. package/lib/cjs/helpers/validate.js +1 -1
  77. package/lib/cjs/types/action.d.ts +113 -9
  78. package/lib/cjs/types/action.js +79 -5
  79. package/lib/cjs/types/error.d.ts +73 -0
  80. package/lib/cjs/types/error.js +89 -4
  81. package/lib/cjs/types.d.ts +2 -1
  82. package/lib/cjs/utils.d.ts +1 -1
  83. package/lib/cjs/utils.js +2 -3
  84. package/lib/esm/actions/blue/borrow.d.ts +12 -2
  85. package/lib/esm/actions/blue/borrow.js +7 -1
  86. package/lib/esm/actions/blue/refinance.d.ts +13 -3
  87. package/lib/esm/actions/blue/refinance.js +8 -2
  88. package/lib/esm/actions/blue/repay.d.ts +6 -5
  89. package/lib/esm/actions/blue/repay.js +10 -18
  90. package/lib/esm/actions/blue/repayWithdrawCollateral.d.ts +15 -6
  91. package/lib/esm/actions/blue/repayWithdrawCollateral.js +16 -18
  92. package/lib/esm/actions/blue/supply.d.ts +7 -7
  93. package/lib/esm/actions/blue/supply.js +10 -20
  94. package/lib/esm/actions/blue/supplyCollateral.d.ts +8 -8
  95. package/lib/esm/actions/blue/supplyCollateral.js +11 -21
  96. package/lib/esm/actions/blue/supplyCollateralBorrow.d.ts +18 -6
  97. package/lib/esm/actions/blue/supplyCollateralBorrow.js +17 -19
  98. package/lib/esm/actions/blue/withdraw.d.ts +10 -2
  99. package/lib/esm/actions/blue/withdraw.js +7 -1
  100. package/lib/esm/actions/index.d.ts +1 -0
  101. package/lib/esm/actions/index.js +1 -0
  102. package/lib/esm/actions/requirements/blue/getBlueAuthorizationRequirement.d.ts +49 -0
  103. package/lib/esm/actions/requirements/blue/getBlueAuthorizationRequirement.js +107 -0
  104. package/lib/esm/actions/requirements/blue/index.d.ts +1 -0
  105. package/lib/esm/actions/requirements/blue/index.js +1 -0
  106. package/lib/esm/actions/requirements/encode/encodeBlueSignatureAuthorization.d.ts +55 -0
  107. package/lib/esm/actions/requirements/encode/encodeBlueSignatureAuthorization.js +85 -0
  108. package/lib/esm/actions/requirements/encode/encodeErc20Approval.d.ts +6 -5
  109. package/lib/esm/actions/requirements/encode/encodeErc20Approval.js +19 -7
  110. package/lib/esm/actions/requirements/encode/encodeErc20Permit.d.ts +9 -7
  111. package/lib/esm/actions/requirements/encode/encodeErc20Permit.js +20 -6
  112. package/lib/esm/actions/requirements/encode/{encodeErc20Permit2.d.ts → encodeErc20Permit2Approve.d.ts} +11 -13
  113. package/lib/esm/actions/requirements/encode/{encodeErc20Permit2.js → encodeErc20Permit2Approve.js} +8 -12
  114. package/lib/esm/actions/requirements/encode/index.d.ts +2 -1
  115. package/lib/esm/actions/requirements/encode/index.js +2 -1
  116. package/lib/esm/actions/requirements/{getRequirements.d.ts → generalAdapter/getGeneralAdapterRequirements.d.ts} +34 -20
  117. package/lib/esm/actions/requirements/generalAdapter/getGeneralAdapterRequirements.js +147 -0
  118. package/lib/{cjs/actions/requirements/getRequirementsPermit.d.ts → esm/actions/requirements/generalAdapter/getGeneralAdapterRequirementsPermit.d.ts} +6 -14
  119. package/lib/esm/actions/requirements/generalAdapter/getGeneralAdapterRequirementsPermit.js +46 -0
  120. package/lib/esm/actions/requirements/generalAdapter/getGeneralAdapterRequirementsPermit2.d.ts +57 -0
  121. package/lib/esm/actions/requirements/generalAdapter/getGeneralAdapterRequirementsPermit2.js +70 -0
  122. package/lib/esm/actions/requirements/generalAdapter/index.d.ts +3 -0
  123. package/lib/esm/actions/requirements/generalAdapter/index.js +3 -0
  124. package/lib/esm/actions/requirements/getRequirementsApproval.d.ts +3 -2
  125. package/lib/esm/actions/requirements/getRequirementsApproval.js +3 -2
  126. package/lib/esm/actions/requirements/index.d.ts +2 -5
  127. package/lib/esm/actions/requirements/index.js +2 -5
  128. package/lib/esm/actions/signatures/getBlueAuthorizationAction.d.ts +29 -0
  129. package/lib/esm/actions/signatures/getBlueAuthorizationAction.js +44 -0
  130. package/lib/{cjs/actions/requirements/getRequirementsAction.d.ts → esm/actions/signatures/getTokenRequirementActions.d.ts} +17 -17
  131. package/lib/esm/actions/{requirements/getRequirementsAction.js → signatures/getTokenRequirementActions.js} +24 -11
  132. package/lib/esm/actions/signatures/index.d.ts +2 -0
  133. package/lib/esm/actions/signatures/index.js +2 -0
  134. package/lib/esm/actions/vaultV1/deposit.d.ts +6 -8
  135. package/lib/esm/actions/vaultV1/deposit.js +11 -21
  136. package/lib/esm/actions/vaultV1/migrateToV2.d.ts +6 -6
  137. package/lib/esm/actions/vaultV1/migrateToV2.js +12 -20
  138. package/lib/esm/actions/vaultV2/deposit.d.ts +6 -8
  139. package/lib/esm/actions/vaultV2/deposit.js +11 -21
  140. package/lib/esm/addresses.d.ts +2 -2
  141. package/lib/esm/addresses.js +1 -1
  142. package/lib/esm/bundler/actions.d.ts +44 -4
  143. package/lib/esm/bundler/actions.js +77 -4
  144. package/lib/esm/bundler/types.d.ts +6 -0
  145. package/lib/esm/constants.d.ts +2 -2
  146. package/lib/esm/constants.js +2 -2
  147. package/lib/esm/entities/blue/blue.d.ts +58 -33
  148. package/lib/esm/entities/blue/blue.js +173 -127
  149. package/lib/esm/entities/reallocationData.d.ts +0 -44
  150. package/lib/esm/entities/reallocationData.js +2 -49
  151. package/lib/esm/entities/vaultV1/vaultV1.d.ts +9 -9
  152. package/lib/esm/entities/vaultV1/vaultV1.js +46 -36
  153. package/lib/esm/entities/vaultV2/vaultV2.d.ts +6 -6
  154. package/lib/esm/entities/vaultV2/vaultV2.js +23 -18
  155. package/lib/esm/errors.d.ts +3 -2
  156. package/lib/esm/errors.js +2 -1
  157. package/lib/esm/helpers/validate.d.ts +2 -2
  158. package/lib/esm/helpers/validate.js +1 -1
  159. package/lib/esm/types/action.d.ts +113 -9
  160. package/lib/esm/types/action.js +75 -4
  161. package/lib/esm/types/error.d.ts +73 -0
  162. package/lib/esm/types/error.js +84 -2
  163. package/lib/esm/types.d.ts +2 -1
  164. package/lib/esm/utils.d.ts +1 -1
  165. package/lib/esm/utils.js +1 -1
  166. package/package.json +6 -6
  167. package/lib/cjs/actions/requirements/getMorphoAuthorizationRequirement.d.ts +0 -37
  168. package/lib/cjs/actions/requirements/getMorphoAuthorizationRequirement.js +0 -71
  169. package/lib/cjs/actions/requirements/getRequirements.js +0 -112
  170. package/lib/cjs/actions/requirements/getRequirementsPermit.js +0 -57
  171. package/lib/cjs/actions/requirements/getRequirementsPermit2.d.ts +0 -63
  172. package/lib/cjs/actions/requirements/getRequirementsPermit2.js +0 -85
  173. package/lib/esm/actions/requirements/getMorphoAuthorizationRequirement.d.ts +0 -37
  174. package/lib/esm/actions/requirements/getMorphoAuthorizationRequirement.js +0 -67
  175. package/lib/esm/actions/requirements/getRequirements.js +0 -108
  176. package/lib/esm/actions/requirements/getRequirementsPermit.js +0 -53
  177. package/lib/esm/actions/requirements/getRequirementsPermit2.d.ts +0 -63
  178. package/lib/esm/actions/requirements/getRequirementsPermit2.js +0 -81
@@ -1,6 +1,6 @@
1
1
  import { type MarketParams } from "@morpho-org/blue-sdk";
2
2
  import { type Address } from "viem";
3
- import { type BlueRepayWithdrawCollateralAction, type Metadata, type RequirementSignature, type Transaction } from "../../types/index.js";
3
+ import { type AuthorizationRequirementSignature, type BlueRepayWithdrawCollateralAction, type Metadata, type PermitRequirementSignature, type Transaction } from "../../types/index.js";
4
4
  /** Parameters for {@link blueRepayWithdrawCollateral}. */
5
5
  export interface BlueRepayWithdrawCollateralParams {
6
6
  market: {
@@ -27,7 +27,14 @@ export interface BlueRepayWithdrawCollateralParams {
27
27
  receiver: Address;
28
28
  /** Maximum repay share price (in ray). Protects against share price manipulation. */
29
29
  maxSharePrice: bigint;
30
- requirementSignature?: RequirementSignature;
30
+ /** Optional pre-signed permit/permit2 approval for the loan-token transfer. */
31
+ requirementSignature?: PermitRequirementSignature;
32
+ /**
33
+ * Optional signed Morpho authorization. When provided, a `setAuthorizationWithSig` call is
34
+ * prepended to the bundle so GeneralAdapter1 is authorized in-bundle instead of via a
35
+ * standalone `setAuthorization` transaction.
36
+ */
37
+ authorizationSignature?: AuthorizationRequirementSignature;
31
38
  };
32
39
  metadata?: Metadata;
33
40
  }
@@ -67,6 +74,8 @@ export interface BlueRepayWithdrawCollateralParams {
67
74
  * protection.
68
75
  * @param params.args.requirementSignature - Optional pre-signed permit/permit2 approval for the
69
76
  * loan-token transfer.
77
+ * @param params.args.authorizationSignature - Optional signed Morpho authorization; when present,
78
+ * a `setAuthorizationWithSig` call is prepended to the bundle.
70
79
  * @param params.metadata - Optional analytics metadata attached to the bundle.
71
80
  * @returns A deep-frozen `Transaction<BlueRepayWithdrawCollateralAction>` with `to`,
72
81
  * `value`, `data`, and the typed `action` discriminator the simulation layer consumes.
@@ -77,11 +86,11 @@ export interface BlueRepayWithdrawCollateralParams {
77
86
  * @throws {NonPositiveTransferAmountError} when `transferAmount <= 0n`.
78
87
  * @throws {TransferAmountNotEqualToAssetsError} when in assets mode and `transferAmount !== assets`.
79
88
  * @throws {NonPositiveWithdrawCollateralAmountError} when `withdrawAmount <= 0n`.
80
- * @throws {DepositAssetMismatchError} from `getRequirementsAction` when `requirementSignature`
89
+ * @throws {DepositAssetMismatchError} from `getTokenRequirementActions` when `requirementSignature`
81
90
  * is provided and the signed asset differs from `marketParams.loanToken`.
82
- * @throws {DepositAmountMismatchError} from `getRequirementsAction` when `requirementSignature`
91
+ * @throws {DepositAmountMismatchError} from `getTokenRequirementActions` when `requirementSignature`
83
92
  * is provided and the signed amount differs from `args.transferAmount`.
84
- * @throws {Permit2ExpirationMissingError} from `getRequirementsAction` when a Permit2 requirement
93
+ * @throws {Permit2ExpirationMissingError} from `getTokenRequirementActions` when a Permit2 requirement
85
94
  * signature is missing its expiration.
86
95
  * @example
87
96
  * ```ts
@@ -102,4 +111,4 @@ export interface BlueRepayWithdrawCollateralParams {
102
111
  * // tx satisfies Readonly<Transaction<BlueRepayWithdrawCollateralAction>>
103
112
  * ```
104
113
  */
105
- export declare const blueRepayWithdrawCollateral: ({ market: { chainId, marketParams }, args: { assets, shares, transferAmount, withdrawAmount, onBehalf, receiver, maxSharePrice, requirementSignature, }, metadata, }: BlueRepayWithdrawCollateralParams) => Readonly<Transaction<BlueRepayWithdrawCollateralAction>>;
114
+ export declare const blueRepayWithdrawCollateral: ({ market: { chainId, marketParams }, args: { assets, shares, transferAmount, withdrawAmount, onBehalf, receiver, maxSharePrice, requirementSignature, authorizationSignature, }, metadata, }: BlueRepayWithdrawCollateralParams) => Readonly<Transaction<BlueRepayWithdrawCollateralAction>>;
@@ -4,7 +4,8 @@ import { maxUint256 } from "viem";
4
4
  import { BundlerAction } from "../../bundler/index.js";
5
5
  import { addTransactionMetadata, validateRepayParams, } from "../../helpers/index.js";
6
6
  import { NonPositiveWithdrawCollateralAmountError, } from "../../types/index.js";
7
- import { getRequirementsAction } from "../requirements/getRequirementsAction.js";
7
+ import { getBlueAuthorizationAction } from "../signatures/getBlueAuthorizationAction.js";
8
+ import { getTokenRequirementActions } from "../signatures/getTokenRequirementActions.js";
8
9
  /**
9
10
  * Prepares an atomic repay-and-withdraw-collateral transaction for a Morpho Blue market.
10
11
  *
@@ -41,6 +42,8 @@ import { getRequirementsAction } from "../requirements/getRequirementsAction.js"
41
42
  * protection.
42
43
  * @param params.args.requirementSignature - Optional pre-signed permit/permit2 approval for the
43
44
  * loan-token transfer.
45
+ * @param params.args.authorizationSignature - Optional signed Morpho authorization; when present,
46
+ * a `setAuthorizationWithSig` call is prepended to the bundle.
44
47
  * @param params.metadata - Optional analytics metadata attached to the bundle.
45
48
  * @returns A deep-frozen `Transaction<BlueRepayWithdrawCollateralAction>` with `to`,
46
49
  * `value`, `data`, and the typed `action` discriminator the simulation layer consumes.
@@ -51,11 +54,11 @@ import { getRequirementsAction } from "../requirements/getRequirementsAction.js"
51
54
  * @throws {NonPositiveTransferAmountError} when `transferAmount <= 0n`.
52
55
  * @throws {TransferAmountNotEqualToAssetsError} when in assets mode and `transferAmount !== assets`.
53
56
  * @throws {NonPositiveWithdrawCollateralAmountError} when `withdrawAmount <= 0n`.
54
- * @throws {DepositAssetMismatchError} from `getRequirementsAction` when `requirementSignature`
57
+ * @throws {DepositAssetMismatchError} from `getTokenRequirementActions` when `requirementSignature`
55
58
  * is provided and the signed asset differs from `marketParams.loanToken`.
56
- * @throws {DepositAmountMismatchError} from `getRequirementsAction` when `requirementSignature`
59
+ * @throws {DepositAmountMismatchError} from `getTokenRequirementActions` when `requirementSignature`
57
60
  * is provided and the signed amount differs from `args.transferAmount`.
58
- * @throws {Permit2ExpirationMissingError} from `getRequirementsAction` when a Permit2 requirement
61
+ * @throws {Permit2ExpirationMissingError} from `getTokenRequirementActions` when a Permit2 requirement
59
62
  * signature is missing its expiration.
60
63
  * @example
61
64
  * ```ts
@@ -76,7 +79,7 @@ import { getRequirementsAction } from "../requirements/getRequirementsAction.js"
76
79
  * // tx satisfies Readonly<Transaction<BlueRepayWithdrawCollateralAction>>
77
80
  * ```
78
81
  */
79
- export const blueRepayWithdrawCollateral = ({ market: { chainId, marketParams }, args: { assets, shares, transferAmount, withdrawAmount, onBehalf, receiver, maxSharePrice, requirementSignature, }, metadata, }) => {
82
+ export const blueRepayWithdrawCollateral = ({ market: { chainId, marketParams }, args: { assets, shares, transferAmount, withdrawAmount, onBehalf, receiver, maxSharePrice, requirementSignature, authorizationSignature, }, metadata, }) => {
80
83
  validateRepayParams({
81
84
  assets,
82
85
  shares,
@@ -89,20 +92,15 @@ export const blueRepayWithdrawCollateral = ({ market: { chainId, marketParams },
89
92
  }
90
93
  const { bundler3: { generalAdapter1 }, } = getChainAddresses(chainId);
91
94
  const actions = [];
92
- if (requirementSignature) {
93
- actions.push(...getRequirementsAction({
94
- asset: marketParams.loanToken,
95
- amount: transferAmount,
96
- recipient: generalAdapter1,
97
- requirementSignature,
98
- }));
99
- }
100
- else {
101
- actions.push({
102
- type: "erc20TransferFrom",
103
- args: [marketParams.loanToken, transferAmount, generalAdapter1, false],
104
- });
95
+ if (authorizationSignature) {
96
+ actions.push(getBlueAuthorizationAction(chainId, authorizationSignature));
105
97
  }
98
+ actions.push(...getTokenRequirementActions({
99
+ asset: marketParams.loanToken,
100
+ amount: transferAmount,
101
+ recipient: generalAdapter1,
102
+ requirementSignature,
103
+ }));
106
104
  // REPAY FIRST — reduces debt before withdrawing collateral
107
105
  actions.push({
108
106
  type: "morphoRepay",
@@ -1,6 +1,6 @@
1
1
  import { type MarketParams } from "@morpho-org/blue-sdk";
2
2
  import type { Address } from "viem";
3
- import { type BlueSupplyAction, type DepositAmountArgs, type Metadata, type RequirementSignature, type Transaction } from "../../types/index.js";
3
+ import { type BlueSupplyAction, type DepositAmountArgs, type Metadata, type PermitRequirementSignature, type Transaction } from "../../types/index.js";
4
4
  /** Parameters for {@link blueSupply}. */
5
5
  export interface BlueSupplyParams {
6
6
  market: {
@@ -8,10 +8,12 @@ export interface BlueSupplyParams {
8
8
  readonly marketParams: MarketParams;
9
9
  };
10
10
  args: DepositAmountArgs & {
11
+ /** Address whose Morpho supply position is credited. */
11
12
  onBehalf: Address;
12
13
  /** Maximum supply share price (in ray). Slippage protection against inflation attacks. */
13
14
  maxSharePrice: bigint;
14
- requirementSignature?: RequirementSignature;
15
+ /** Optional pre-signed permit/permit2 approval for the loan-token transfer. */
16
+ requirementSignature?: PermitRequirementSignature;
15
17
  };
16
18
  metadata?: Metadata;
17
19
  }
@@ -34,9 +36,7 @@ export interface BlueSupplyParams {
34
36
  * protection.
35
37
  * @param params.args.nativeAmount - Optional amount of native token to wrap into wNative for the
36
38
  * supply. Requires the loan token to be the chain's wNative.
37
- * @param params.args.requirementSignature - Optional pre-signed permit/permit2 approval. When
38
- * absent, the bundle uses a plain `erc20TransferFrom` and assumes the user has already
39
- * approved `GeneralAdapter1`.
39
+ * @param params.args.requirementSignature - Optional pre-signed permit/permit2 approval.
40
40
  * @param params.metadata - Optional analytics metadata attached to the bundle.
41
41
  * @returns A deep-frozen `Transaction<BlueSupplyAction>` with `to`, `value`, `data`, and the
42
42
  * typed `action` discriminator the simulation layer consumes.
@@ -47,9 +47,9 @@ export interface BlueSupplyParams {
47
47
  * @throws {ChainWNativeMissingError} when `nativeAmount > 0n` but the chain has no configured wNative.
48
48
  * @throws {NativeAmountOnNonWNativeAssetError} when `nativeAmount > 0n` but the loan token is not
49
49
  * the chain's wNative.
50
- * @throws {DepositAssetMismatchError} from `getRequirementsAction` when `requirementSignature`
50
+ * @throws {DepositAssetMismatchError} from `getTokenRequirementActions` when `requirementSignature`
51
51
  * is provided and the signed asset differs from `marketParams.loanToken`.
52
- * @throws {DepositAmountMismatchError} from `getRequirementsAction` when `requirementSignature`
52
+ * @throws {DepositAmountMismatchError} from `getTokenRequirementActions` when `requirementSignature`
53
53
  * is provided and the signed amount differs from `args.amount`.
54
54
  * @example
55
55
  * ```ts
@@ -3,7 +3,7 @@ import { deepFreeze } from "@morpho-org/morpho-ts";
3
3
  import { BundlerAction } from "../../bundler/index.js";
4
4
  import { addTransactionMetadata, validateNativeAsset, } from "../../helpers/index.js";
5
5
  import { NegativeNativeAmountError, NegativeSupplyAmountError, NegativeSupplyMaxSharePriceError, ZeroSupplyAmountError, } from "../../types/index.js";
6
- import { getRequirementsAction } from "../requirements/getRequirementsAction.js";
6
+ import { getTokenRequirementActions } from "../signatures/getTokenRequirementActions.js";
7
7
  /**
8
8
  * Prepares a loan-asset supply transaction for a Morpho Blue market.
9
9
  *
@@ -23,9 +23,7 @@ import { getRequirementsAction } from "../requirements/getRequirementsAction.js"
23
23
  * protection.
24
24
  * @param params.args.nativeAmount - Optional amount of native token to wrap into wNative for the
25
25
  * supply. Requires the loan token to be the chain's wNative.
26
- * @param params.args.requirementSignature - Optional pre-signed permit/permit2 approval. When
27
- * absent, the bundle uses a plain `erc20TransferFrom` and assumes the user has already
28
- * approved `GeneralAdapter1`.
26
+ * @param params.args.requirementSignature - Optional pre-signed permit/permit2 approval.
29
27
  * @param params.metadata - Optional analytics metadata attached to the bundle.
30
28
  * @returns A deep-frozen `Transaction<BlueSupplyAction>` with `to`, `value`, `data`, and the
31
29
  * typed `action` discriminator the simulation layer consumes.
@@ -36,9 +34,9 @@ import { getRequirementsAction } from "../requirements/getRequirementsAction.js"
36
34
  * @throws {ChainWNativeMissingError} when `nativeAmount > 0n` but the chain has no configured wNative.
37
35
  * @throws {NativeAmountOnNonWNativeAssetError} when `nativeAmount > 0n` but the loan token is not
38
36
  * the chain's wNative.
39
- * @throws {DepositAssetMismatchError} from `getRequirementsAction` when `requirementSignature`
37
+ * @throws {DepositAssetMismatchError} from `getTokenRequirementActions` when `requirementSignature`
40
38
  * is provided and the signed asset differs from `marketParams.loanToken`.
41
- * @throws {DepositAmountMismatchError} from `getRequirementsAction` when `requirementSignature`
39
+ * @throws {DepositAmountMismatchError} from `getTokenRequirementActions` when `requirementSignature`
42
40
  * is provided and the signed amount differs from `args.amount`.
43
41
  * @example
44
42
  * ```ts
@@ -82,20 +80,12 @@ export const blueSupply = ({ market: { chainId, marketParams }, args: { amount =
82
80
  });
83
81
  }
84
82
  if (amount > 0n) {
85
- if (requirementSignature) {
86
- actions.push(...getRequirementsAction({
87
- asset: marketParams.loanToken,
88
- amount,
89
- recipient: generalAdapter1,
90
- requirementSignature,
91
- }));
92
- }
93
- else {
94
- actions.push({
95
- type: "erc20TransferFrom",
96
- args: [marketParams.loanToken, amount, generalAdapter1, false],
97
- });
98
- }
83
+ actions.push(...getTokenRequirementActions({
84
+ asset: marketParams.loanToken,
85
+ amount,
86
+ recipient: generalAdapter1,
87
+ requirementSignature,
88
+ }));
99
89
  }
100
90
  actions.push({
101
91
  type: "morphoSupply",
@@ -1,6 +1,6 @@
1
1
  import { type MarketParams } from "@morpho-org/blue-sdk";
2
2
  import type { Address } from "viem";
3
- import { type BlueSupplyCollateralAction, type DepositAmountArgs, type Metadata, type RequirementSignature, type Transaction } from "../../types/index.js";
3
+ import { type BlueSupplyCollateralAction, type DepositAmountArgs, type Metadata, type PermitRequirementSignature, type Transaction } from "../../types/index.js";
4
4
  /** Parameters for {@link blueSupplyCollateral}. */
5
5
  export interface BlueSupplyCollateralParams {
6
6
  market: {
@@ -8,8 +8,10 @@ export interface BlueSupplyCollateralParams {
8
8
  readonly marketParams: MarketParams;
9
9
  };
10
10
  args: DepositAmountArgs & {
11
+ /** Address whose Morpho collateral position is credited. */
11
12
  onBehalf: Address;
12
- requirementSignature?: RequirementSignature;
13
+ /** Optional pre-signed permit/permit2 approval for the collateral transfer. */
14
+ requirementSignature?: PermitRequirementSignature;
13
15
  };
14
16
  metadata?: Metadata;
15
17
  }
@@ -27,9 +29,7 @@ export interface BlueSupplyCollateralParams {
27
29
  * @param params.args.amount - Amount of ERC-20 collateral to supply. At least one of `amount` or
28
30
  * `nativeAmount` must be positive. Defaults to `0n`.
29
31
  * @param params.args.onBehalf - Address whose Morpho position is credited with the collateral.
30
- * @param params.args.requirementSignature - Optional pre-signed permit/permit2 approval. When
31
- * absent, the bundle uses a plain `erc20TransferFrom` and assumes the user has already
32
- * approved `GeneralAdapter1`.
32
+ * @param params.args.requirementSignature - Optional pre-signed permit/permit2 approval.
33
33
  * @param params.args.nativeAmount - Optional amount of native token to wrap into wNative for the
34
34
  * supply. Requires the collateral token to be the chain's wNative.
35
35
  * @param params.metadata - Optional analytics metadata attached to the bundle.
@@ -41,11 +41,11 @@ export interface BlueSupplyCollateralParams {
41
41
  * @throws {ChainWNativeMissingError} when `nativeAmount > 0n` but the chain has no configured wNative.
42
42
  * @throws {NativeAmountOnNonWNativeAssetError} when `nativeAmount > 0n` but the collateral
43
43
  * token is not the chain's wNative.
44
- * @throws {DepositAssetMismatchError} from `getRequirementsAction` when `requirementSignature`
44
+ * @throws {DepositAssetMismatchError} from `getTokenRequirementActions` when `requirementSignature`
45
45
  * is provided and the signed asset differs from `marketParams.collateralToken`.
46
- * @throws {DepositAmountMismatchError} from `getRequirementsAction` when `requirementSignature`
46
+ * @throws {DepositAmountMismatchError} from `getTokenRequirementActions` when `requirementSignature`
47
47
  * is provided and the signed amount differs from `args.amount`.
48
- * @throws {Permit2ExpirationMissingError} from `getRequirementsAction` when a Permit2 requirement
48
+ * @throws {Permit2ExpirationMissingError} from `getTokenRequirementActions` when a Permit2 requirement
49
49
  * signature is missing its expiration.
50
50
  * @example
51
51
  * ```ts
@@ -3,7 +3,7 @@ import { deepFreeze } from "@morpho-org/morpho-ts";
3
3
  import { BundlerAction } from "../../bundler/index.js";
4
4
  import { addTransactionMetadata, validateNativeAsset, } from "../../helpers/index.js";
5
5
  import { NegativeNativeAmountError, NonPositiveAssetAmountError, ZeroCollateralAmountError, } from "../../types/index.js";
6
- import { getRequirementsAction } from "../requirements/getRequirementsAction.js";
6
+ import { getTokenRequirementActions } from "../signatures/getTokenRequirementActions.js";
7
7
  /**
8
8
  * Prepares a supply-collateral transaction for a Morpho Blue market.
9
9
  *
@@ -18,9 +18,7 @@ import { getRequirementsAction } from "../requirements/getRequirementsAction.js"
18
18
  * @param params.args.amount - Amount of ERC-20 collateral to supply. At least one of `amount` or
19
19
  * `nativeAmount` must be positive. Defaults to `0n`.
20
20
  * @param params.args.onBehalf - Address whose Morpho position is credited with the collateral.
21
- * @param params.args.requirementSignature - Optional pre-signed permit/permit2 approval. When
22
- * absent, the bundle uses a plain `erc20TransferFrom` and assumes the user has already
23
- * approved `GeneralAdapter1`.
21
+ * @param params.args.requirementSignature - Optional pre-signed permit/permit2 approval.
24
22
  * @param params.args.nativeAmount - Optional amount of native token to wrap into wNative for the
25
23
  * supply. Requires the collateral token to be the chain's wNative.
26
24
  * @param params.metadata - Optional analytics metadata attached to the bundle.
@@ -32,11 +30,11 @@ import { getRequirementsAction } from "../requirements/getRequirementsAction.js"
32
30
  * @throws {ChainWNativeMissingError} when `nativeAmount > 0n` but the chain has no configured wNative.
33
31
  * @throws {NativeAmountOnNonWNativeAssetError} when `nativeAmount > 0n` but the collateral
34
32
  * token is not the chain's wNative.
35
- * @throws {DepositAssetMismatchError} from `getRequirementsAction` when `requirementSignature`
33
+ * @throws {DepositAssetMismatchError} from `getTokenRequirementActions` when `requirementSignature`
36
34
  * is provided and the signed asset differs from `marketParams.collateralToken`.
37
- * @throws {DepositAmountMismatchError} from `getRequirementsAction` when `requirementSignature`
35
+ * @throws {DepositAmountMismatchError} from `getTokenRequirementActions` when `requirementSignature`
38
36
  * is provided and the signed amount differs from `args.amount`.
39
- * @throws {Permit2ExpirationMissingError} from `getRequirementsAction` when a Permit2 requirement
37
+ * @throws {Permit2ExpirationMissingError} from `getTokenRequirementActions` when a Permit2 requirement
40
38
  * signature is missing its expiration.
41
39
  * @example
42
40
  * ```ts
@@ -73,20 +71,12 @@ export const blueSupplyCollateral = ({ market: { chainId, marketParams }, args:
73
71
  });
74
72
  }
75
73
  if (amount > 0n) {
76
- if (requirementSignature) {
77
- actions.push(...getRequirementsAction({
78
- asset: marketParams.collateralToken,
79
- amount,
80
- recipient: generalAdapter1,
81
- requirementSignature,
82
- }));
83
- }
84
- else {
85
- actions.push({
86
- type: "erc20TransferFrom",
87
- args: [marketParams.collateralToken, amount, generalAdapter1, false],
88
- });
89
- }
74
+ actions.push(...getTokenRequirementActions({
75
+ asset: marketParams.collateralToken,
76
+ amount,
77
+ recipient: generalAdapter1,
78
+ requirementSignature,
79
+ }));
90
80
  }
91
81
  actions.push({
92
82
  type: "morphoSupplyCollateral",
@@ -1,6 +1,6 @@
1
1
  import { type MarketParams } from "@morpho-org/blue-sdk";
2
2
  import type { Address } from "viem";
3
- import { type BlueSupplyCollateralBorrowAction, type DepositAmountArgs, type Metadata, type RequirementSignature, type Transaction, type VaultReallocation } from "../../types/index.js";
3
+ import { type AuthorizationRequirementSignature, type BlueSupplyCollateralBorrowAction, type DepositAmountArgs, type Metadata, type PermitRequirementSignature, type Transaction, type VaultReallocation } from "../../types/index.js";
4
4
  /** Parameters for {@link blueSupplyCollateralBorrow}. */
5
5
  export interface BlueSupplyCollateralBorrowParams {
6
6
  market: {
@@ -8,14 +8,24 @@ export interface BlueSupplyCollateralBorrowParams {
8
8
  readonly marketParams: MarketParams;
9
9
  };
10
10
  args: DepositAmountArgs & {
11
+ /** Amount of loan asset to borrow after the collateral is supplied. */
11
12
  borrowAmount: bigint;
13
+ /** Address whose Morpho collateral and borrow positions are credited. */
12
14
  onBehalf: Address;
15
+ /** Address that receives the borrowed assets. */
13
16
  receiver: Address;
14
17
  /** Minimum borrow share price (in ray). Protects against share price manipulation. */
15
18
  minSharePrice: bigint;
16
- requirementSignature?: RequirementSignature;
19
+ /** Optional pre-signed permit/permit2 approval for the collateral transfer. */
20
+ requirementSignature?: PermitRequirementSignature;
17
21
  /** Vault reallocations to execute before borrowing (computed by entity). */
18
22
  reallocations?: readonly VaultReallocation[];
23
+ /**
24
+ * Optional signed Morpho authorization. When provided, a `setAuthorizationWithSig` call is
25
+ * prepended to the bundle so GeneralAdapter1 is authorized in-bundle instead of via a
26
+ * standalone `setAuthorization` transaction.
27
+ */
28
+ authorizationSignature?: AuthorizationRequirementSignature;
19
29
  };
20
30
  metadata?: Metadata;
21
31
  }
@@ -46,6 +56,8 @@ export interface BlueSupplyCollateralBorrowParams {
46
56
  * collateral supply. Requires the collateral token to be the chain's wNative.
47
57
  * @param params.args.reallocations - Optional vault reallocations to execute between the supply
48
58
  * and borrow legs, computed by the entity layer.
59
+ * @param params.args.authorizationSignature - Optional signed Morpho authorization; when present,
60
+ * a `setAuthorizationWithSig` call is prepended to the bundle.
49
61
  * @param params.metadata - Optional analytics metadata attached to the bundle.
50
62
  * @returns A deep-frozen `Transaction<BlueSupplyCollateralBorrowAction>` with `to`, `value`,
51
63
  * `data`, and the typed `action` discriminator the simulation layer consumes.
@@ -57,11 +69,11 @@ export interface BlueSupplyCollateralBorrowParams {
57
69
  * @throws {ChainWNativeMissingError} when `nativeAmount > 0n` but the chain has no configured wNative.
58
70
  * @throws {NativeAmountOnNonWNativeAssetError} when `nativeAmount > 0n` but the collateral
59
71
  * token is not the chain's wNative.
60
- * @throws {DepositAssetMismatchError} from `getRequirementsAction` when `requirementSignature`
72
+ * @throws {DepositAssetMismatchError} from `getTokenRequirementActions` when `requirementSignature`
61
73
  * is provided and the signed asset differs from `marketParams.collateralToken`.
62
- * @throws {DepositAmountMismatchError} from `getRequirementsAction` when `requirementSignature`
74
+ * @throws {DepositAmountMismatchError} from `getTokenRequirementActions` when `requirementSignature`
63
75
  * is provided and the signed amount differs from `args.amount`.
64
- * @throws {Permit2ExpirationMissingError} from `getRequirementsAction` when a Permit2 requirement
76
+ * @throws {Permit2ExpirationMissingError} from `getTokenRequirementActions` when a Permit2 requirement
65
77
  * signature is missing its expiration.
66
78
  * @throws {NegativeReallocationFeeError} from `buildReallocationActions` when
67
79
  * `reallocations` is non-empty and any `reallocation.fee < 0n`.
@@ -90,4 +102,4 @@ export interface BlueSupplyCollateralBorrowParams {
90
102
  * // tx satisfies Readonly<Transaction<BlueSupplyCollateralBorrowAction>>
91
103
  * ```
92
104
  */
93
- export declare const blueSupplyCollateralBorrow: ({ market: { chainId, marketParams }, args: { amount, borrowAmount, onBehalf, receiver, minSharePrice, requirementSignature, nativeAmount, reallocations, }, metadata, }: BlueSupplyCollateralBorrowParams) => Readonly<Transaction<BlueSupplyCollateralBorrowAction>>;
105
+ export declare const blueSupplyCollateralBorrow: ({ market: { chainId, marketParams }, args: { amount, borrowAmount, onBehalf, receiver, minSharePrice, requirementSignature, nativeAmount, reallocations, authorizationSignature, }, metadata, }: BlueSupplyCollateralBorrowParams) => Readonly<Transaction<BlueSupplyCollateralBorrowAction>>;
@@ -3,7 +3,8 @@ import { deepFreeze } from "@morpho-org/morpho-ts";
3
3
  import { BundlerAction } from "../../bundler/index.js";
4
4
  import { addTransactionMetadata, validateNativeAsset, } from "../../helpers/index.js";
5
5
  import { NegativeNativeAmountError, NonPositiveAssetAmountError, NonPositiveBorrowAmountError, NonPositiveMinBorrowSharePriceError, ZeroCollateralAmountError, } from "../../types/index.js";
6
- import { getRequirementsAction } from "../requirements/getRequirementsAction.js";
6
+ import { getBlueAuthorizationAction } from "../signatures/getBlueAuthorizationAction.js";
7
+ import { getTokenRequirementActions } from "../signatures/getTokenRequirementActions.js";
7
8
  import { buildReallocationActions } from "./buildReallocationActions.js";
8
9
  /**
9
10
  * Prepares an atomic supply-collateral-and-borrow transaction for a Morpho Blue market.
@@ -32,6 +33,8 @@ import { buildReallocationActions } from "./buildReallocationActions.js";
32
33
  * collateral supply. Requires the collateral token to be the chain's wNative.
33
34
  * @param params.args.reallocations - Optional vault reallocations to execute between the supply
34
35
  * and borrow legs, computed by the entity layer.
36
+ * @param params.args.authorizationSignature - Optional signed Morpho authorization; when present,
37
+ * a `setAuthorizationWithSig` call is prepended to the bundle.
35
38
  * @param params.metadata - Optional analytics metadata attached to the bundle.
36
39
  * @returns A deep-frozen `Transaction<BlueSupplyCollateralBorrowAction>` with `to`, `value`,
37
40
  * `data`, and the typed `action` discriminator the simulation layer consumes.
@@ -43,11 +46,11 @@ import { buildReallocationActions } from "./buildReallocationActions.js";
43
46
  * @throws {ChainWNativeMissingError} when `nativeAmount > 0n` but the chain has no configured wNative.
44
47
  * @throws {NativeAmountOnNonWNativeAssetError} when `nativeAmount > 0n` but the collateral
45
48
  * token is not the chain's wNative.
46
- * @throws {DepositAssetMismatchError} from `getRequirementsAction` when `requirementSignature`
49
+ * @throws {DepositAssetMismatchError} from `getTokenRequirementActions` when `requirementSignature`
47
50
  * is provided and the signed asset differs from `marketParams.collateralToken`.
48
- * @throws {DepositAmountMismatchError} from `getRequirementsAction` when `requirementSignature`
51
+ * @throws {DepositAmountMismatchError} from `getTokenRequirementActions` when `requirementSignature`
49
52
  * is provided and the signed amount differs from `args.amount`.
50
- * @throws {Permit2ExpirationMissingError} from `getRequirementsAction` when a Permit2 requirement
53
+ * @throws {Permit2ExpirationMissingError} from `getTokenRequirementActions` when a Permit2 requirement
51
54
  * signature is missing its expiration.
52
55
  * @throws {NegativeReallocationFeeError} from `buildReallocationActions` when
53
56
  * `reallocations` is non-empty and any `reallocation.fee < 0n`.
@@ -76,7 +79,7 @@ import { buildReallocationActions } from "./buildReallocationActions.js";
76
79
  * // tx satisfies Readonly<Transaction<BlueSupplyCollateralBorrowAction>>
77
80
  * ```
78
81
  */
79
- export const blueSupplyCollateralBorrow = ({ market: { chainId, marketParams }, args: { amount = 0n, borrowAmount, onBehalf, receiver, minSharePrice, requirementSignature, nativeAmount, reallocations, }, metadata, }) => {
82
+ export const blueSupplyCollateralBorrow = ({ market: { chainId, marketParams }, args: { amount = 0n, borrowAmount, onBehalf, receiver, minSharePrice, requirementSignature, nativeAmount, reallocations, authorizationSignature, }, metadata, }) => {
80
83
  if (amount < 0n) {
81
84
  throw new NonPositiveAssetAmountError(marketParams.collateralToken);
82
85
  }
@@ -95,6 +98,9 @@ export const blueSupplyCollateralBorrow = ({ market: { chainId, marketParams },
95
98
  }
96
99
  const { bundler3: { generalAdapter1, bundler3 }, } = getChainAddresses(chainId);
97
100
  const actions = [];
101
+ if (authorizationSignature) {
102
+ actions.push(getBlueAuthorizationAction(chainId, authorizationSignature));
103
+ }
98
104
  if (nativeAmount !== undefined && nativeAmount > 0n) {
99
105
  validateNativeAsset(chainId, marketParams.collateralToken);
100
106
  actions.push({
@@ -106,20 +112,12 @@ export const blueSupplyCollateralBorrow = ({ market: { chainId, marketParams },
106
112
  });
107
113
  }
108
114
  if (amount > 0n) {
109
- if (requirementSignature) {
110
- actions.push(...getRequirementsAction({
111
- asset: marketParams.collateralToken,
112
- amount,
113
- recipient: generalAdapter1,
114
- requirementSignature,
115
- }));
116
- }
117
- else {
118
- actions.push({
119
- type: "erc20TransferFrom",
120
- args: [marketParams.collateralToken, amount, generalAdapter1, false],
121
- });
122
- }
115
+ actions.push(...getTokenRequirementActions({
116
+ asset: marketParams.collateralToken,
117
+ amount,
118
+ recipient: generalAdapter1,
119
+ requirementSignature,
120
+ }));
123
121
  }
124
122
  actions.push({
125
123
  type: "morphoSupplyCollateral",
@@ -1,6 +1,6 @@
1
1
  import type { MarketParams } from "@morpho-org/blue-sdk";
2
2
  import type { Address } from "viem";
3
- import { type BlueWithdrawAction, type Metadata, type Transaction, type VaultReallocation } from "../../types/index.js";
3
+ import { type AuthorizationRequirementSignature, type BlueWithdrawAction, type Metadata, type Transaction, type VaultReallocation } from "../../types/index.js";
4
4
  /** Parameters for {@link blueWithdraw}. */
5
5
  export interface BlueWithdrawParams {
6
6
  market: {
@@ -22,6 +22,12 @@ export interface BlueWithdrawParams {
22
22
  * `computeReallocations({ operation: "withdraw", amount, ... })`.
23
23
  */
24
24
  reallocations?: readonly VaultReallocation[];
25
+ /**
26
+ * Optional signed Morpho authorization. When provided, a `setAuthorizationWithSig` call is
27
+ * prepended to the bundle so GeneralAdapter1 is authorized in-bundle instead of via a
28
+ * standalone `setAuthorization` transaction.
29
+ */
30
+ authorizationSignature?: AuthorizationRequirementSignature;
25
31
  };
26
32
  metadata?: Metadata;
27
33
  }
@@ -53,6 +59,8 @@ export interface BlueWithdrawParams {
53
59
  * protection.
54
60
  * @param params.args.reallocations - Optional vault reallocations to execute before withdrawing,
55
61
  * computed by the entity layer.
62
+ * @param params.args.authorizationSignature - Optional signed Morpho authorization; when present,
63
+ * a `setAuthorizationWithSig` call is prepended to the bundle.
56
64
  * @param params.metadata - Optional analytics metadata attached to the bundle.
57
65
  * @returns A deep-frozen `Transaction<BlueWithdrawAction>` with `to`, `value`, `data`, and
58
66
  * the typed `action` discriminator the simulation layer consumes.
@@ -80,4 +88,4 @@ export interface BlueWithdrawParams {
80
88
  * // tx satisfies Readonly<Transaction<BlueWithdrawAction>>
81
89
  * ```
82
90
  */
83
- export declare const blueWithdraw: ({ market: { chainId, marketParams }, args: { assets, shares, receiver, minSharePrice, reallocations }, metadata, }: BlueWithdrawParams) => Readonly<Transaction<BlueWithdrawAction>>;
91
+ export declare const blueWithdraw: ({ market: { chainId, marketParams }, args: { assets, shares, receiver, minSharePrice, reallocations, authorizationSignature, }, metadata, }: BlueWithdrawParams) => Readonly<Transaction<BlueWithdrawAction>>;
@@ -2,6 +2,7 @@ import { deepFreeze } from "@morpho-org/morpho-ts";
2
2
  import { BundlerAction } from "../../bundler/index.js";
3
3
  import { addTransactionMetadata } from "../../helpers/index.js";
4
4
  import { MutuallyExclusiveWithdrawAmountsError, NegativeWithdrawMinSharePriceError, NonPositiveWithdrawAmountError, } from "../../types/index.js";
5
+ import { getBlueAuthorizationAction } from "../signatures/getBlueAuthorizationAction.js";
5
6
  import { buildReallocationActions } from "./buildReallocationActions.js";
6
7
  /**
7
8
  * Prepares a loan-asset withdraw transaction for a Morpho Blue market.
@@ -31,6 +32,8 @@ import { buildReallocationActions } from "./buildReallocationActions.js";
31
32
  * protection.
32
33
  * @param params.args.reallocations - Optional vault reallocations to execute before withdrawing,
33
34
  * computed by the entity layer.
35
+ * @param params.args.authorizationSignature - Optional signed Morpho authorization; when present,
36
+ * a `setAuthorizationWithSig` call is prepended to the bundle.
34
37
  * @param params.metadata - Optional analytics metadata attached to the bundle.
35
38
  * @returns A deep-frozen `Transaction<BlueWithdrawAction>` with `to`, `value`, `data`, and
36
39
  * the typed `action` discriminator the simulation layer consumes.
@@ -58,7 +61,7 @@ import { buildReallocationActions } from "./buildReallocationActions.js";
58
61
  * // tx satisfies Readonly<Transaction<BlueWithdrawAction>>
59
62
  * ```
60
63
  */
61
- export const blueWithdraw = ({ market: { chainId, marketParams }, args: { assets, shares, receiver, minSharePrice, reallocations }, metadata, }) => {
64
+ export const blueWithdraw = ({ market: { chainId, marketParams }, args: { assets, shares, receiver, minSharePrice, reallocations, authorizationSignature, }, metadata, }) => {
62
65
  // Mutual exclusion is detected on "both values present" (either non-zero),
63
66
  // before sign checks — otherwise `{ assets: -1n, shares: 5n }` would be
64
67
  // misreported as a positivity error rather than the actual mode conflict.
@@ -73,6 +76,9 @@ export const blueWithdraw = ({ market: { chainId, marketParams }, args: { assets
73
76
  }
74
77
  const actions = [];
75
78
  let reallocationFee = 0n;
79
+ if (authorizationSignature) {
80
+ actions.push(getBlueAuthorizationAction(chainId, authorizationSignature));
81
+ }
76
82
  if (reallocations && reallocations.length > 0) {
77
83
  const result = buildReallocationActions(reallocations, marketParams);
78
84
  actions.push(...result.actions);
@@ -3,5 +3,6 @@ export type { VaultV1Actions } from "../entities/vaultV1/index.js";
3
3
  export type { VaultV2Actions } from "../entities/vaultV2/index.js";
4
4
  export * from "./blue/index.js";
5
5
  export * from "./requirements/index.js";
6
+ export * from "./signatures/index.js";
6
7
  export * from "./vaultV1/index.js";
7
8
  export * from "./vaultV2/index.js";
@@ -1,4 +1,5 @@
1
1
  export * from "./blue/index.js";
2
2
  export * from "./requirements/index.js";
3
+ export * from "./signatures/index.js";
3
4
  export * from "./vaultV1/index.js";
4
5
  export * from "./vaultV2/index.js";
@@ -0,0 +1,49 @@
1
+ import type { Client } from "viem";
2
+ import { type Address } from "viem";
3
+ import { type AuthorizationRequirementSignature, type BlueAuthorizationAction, type Requirement, type Transaction } from "../../../types/index.js";
4
+ /**
5
+ * Resolves whether `GeneralAdapter1` needs Blue authorization for the given user, and returns
6
+ * the requirement to satisfy it when it does.
7
+ *
8
+ * Reads `Morpho.isAuthorized(userAddress, generalAdapter1)` on the target chain. Required before
9
+ * any bundled Blue path that operates on behalf of the user (`borrow`, `withdraw`,
10
+ * `supplyCollateralBorrow`, `repayWithdrawCollateral`, `refinance`).
11
+ *
12
+ * - When `supportSignature` is falsy (default), returns the
13
+ * `setAuthorization(generalAdapter1, true)` transaction the user submits before the bundle.
14
+ * - When `supportSignature` is `true`, reads the user's Morpho `nonce` and returns a signable
15
+ * `Requirement`; the signed authorization is folded into the bundle via
16
+ * `setAuthorizationWithSig`, removing the standalone transaction.
17
+ *
18
+ * @param params.viemClient - Connected viem `Client` whose `chain.id` matches `params.chainId`.
19
+ * @param params.chainId - Target chain id (used to resolve Morpho and `GeneralAdapter1`).
20
+ * @param params.userAddress - The user that must authorize `GeneralAdapter1`.
21
+ * @param params.supportSignature - When `true`, return a signable `Requirement` instead of a
22
+ * transaction so authorization can be bundled via `setAuthorizationWithSig`.
23
+ * @returns A deep-frozen `Transaction<BlueAuthorizationAction>`, a signable authorization
24
+ * `Requirement` (when `supportSignature` is `true`), or `null` when authorization is already in
25
+ * place.
26
+ * @throws {ChainIdMismatchError} when `viemClient.chain?.id !== params.chainId`.
27
+ * @example
28
+ * ```ts
29
+ * import { createPublicClient, http } from "viem";
30
+ * import { mainnet } from "viem/chains";
31
+ * import { getBlueAuthorizationRequirement } from "@morpho-org/morpho-sdk";
32
+ *
33
+ * const client = createPublicClient({ chain: mainnet, transport: http() });
34
+ * const requirement = await getBlueAuthorizationRequirement({
35
+ * viemClient: client,
36
+ * chainId: 1,
37
+ * userAddress: borrower,
38
+ * supportSignature: true,
39
+ * });
40
+ * // requirement is null when already authorized, a Requirement when supportSignature is true,
41
+ * // otherwise Readonly<Transaction<BlueAuthorizationAction>>
42
+ * ```
43
+ */
44
+ export declare const getBlueAuthorizationRequirement: (params: {
45
+ viemClient: Client;
46
+ chainId: number;
47
+ userAddress: Address;
48
+ supportSignature?: boolean;
49
+ }) => Promise<Readonly<Transaction<BlueAuthorizationAction>> | Requirement<AuthorizationRequirementSignature> | null>;