@morpho-org/morpho-sdk 4.1.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 +12 -12
  68. package/lib/cjs/entities/reallocationData.js +19 -19
  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 +12 -12
  150. package/lib/esm/entities/reallocationData.js +18 -18
  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
@@ -2,9 +2,9 @@ import { AccrualPosition, DEFAULT_SLIPPAGE_TOLERANCE, MathLib, } from "@morpho-o
2
2
  import { fetchAccrualPosition, fetchMarket, fetchPosition, fetchVault, fetchVaultMarketConfig, } from "@morpho-org/blue-sdk-viem";
3
3
  import { Time } from "@morpho-org/morpho-ts";
4
4
  import { isAddressEqual } from "viem";
5
- import { blueBorrow, blueRefinance, blueRepay, blueRepayWithdrawCollateral, blueSupply, blueSupplyCollateral, blueSupplyCollateralBorrow, blueWithdraw, blueWithdrawCollateral, getMorphoAuthorizationRequirement, getRequirements, } from "../../actions/index.js";
5
+ import { blueBorrow, blueRefinance, blueRepay, blueRepayWithdrawCollateral, blueSupply, blueSupplyCollateral, blueSupplyCollateralBorrow, blueWithdraw, blueWithdrawCollateral, getBlueAuthorizationRequirement, getGeneralAdapterRequirements, } from "../../actions/index.js";
6
6
  import { computeMaxRepaySharePrice, computeMaxSupplySharePrice, computeMinBorrowSharePrice, computeMinWithdrawSharePrice, computeReallocations, validateAccrualPosition, validateChainId, validateNativeAsset, validatePositionHealth, validatePositionHealthAfterWithdraw, validateRepayAmount, validateRepayShares, validateSlippageTolerance, validateWithdrawAmount, validateWithdrawShares, } from "../../helpers/index.js";
7
- import { BorrowAmountAndSharesExclusiveError, MarketIdMismatchError, MissingAccrualPositionError, MutuallyExclusiveRepayAmountsError, MutuallyExclusiveWithdrawAmountsError, NegativeBorrowSharesError, NegativeNativeAmountError, NegativeSupplyAmountError, NonPositiveAssetAmountError, NonPositiveBorrowAmountError, NonPositiveRepayAmountError, NonPositiveWithdrawAmountError, NonPositiveWithdrawCollateralAmountError, RefinanceExceedsBorrowAssetsError, RefinanceExceedsBorrowSharesError, RefinanceExceedsCollateralError, RefinanceSameMarketError, RefinanceTokenMismatchError, WithdrawExceedsCollateralError, ZeroCollateralAmountError, ZeroSupplyAmountError, } from "../../types/index.js";
7
+ import { BorrowAmountAndSharesExclusiveError, MarketIdMismatchError, MissingAccrualPositionError, MutuallyExclusiveRepayAmountsError, MutuallyExclusiveWithdrawAmountsError, NegativeBorrowSharesError, NegativeNativeAmountError, NegativeSupplyAmountError, NonPositiveAssetAmountError, NonPositiveBorrowAmountError, NonPositiveRepayAmountError, NonPositiveWithdrawAmountError, NonPositiveWithdrawCollateralAmountError, RefinanceExceedsBorrowAssetsError, RefinanceExceedsBorrowSharesError, RefinanceExceedsCollateralError, RefinanceSameMarketError, RefinanceTokenMismatchError, selectRequirementSignatures, WithdrawExceedsCollateralError, ZeroCollateralAmountError, ZeroSupplyAmountError, } from "../../types/index.js";
8
8
  import { ReallocationData } from "../reallocationData.js";
9
9
  export class MorphoBlue {
10
10
  client;
@@ -57,7 +57,7 @@ export class MorphoBlue {
57
57
  slippageTolerance,
58
58
  });
59
59
  return {
60
- getRequirements: (params) => getRequirements(this.client.viemClient, {
60
+ getRequirements: (params) => getGeneralAdapterRequirements(this.client.viemClient, {
61
61
  address: this.marketParams.loanToken,
62
62
  chainId: this.chainId,
63
63
  supportSignature: this.client.options.supportSignature,
@@ -65,17 +65,22 @@ export class MorphoBlue {
65
65
  useSimplePermit: params?.useSimplePermit,
66
66
  args: { amount, from: userAddress },
67
67
  }),
68
- buildTx: (requirementSignature) => blueSupply({
69
- market: { chainId: this.chainId, marketParams: this.marketParams },
70
- args: {
71
- amount,
72
- nativeAmount,
73
- onBehalf: userAddress,
74
- maxSharePrice,
75
- requirementSignature,
76
- },
77
- metadata: this.client.options.metadata,
78
- }),
68
+ buildTx: (signatures) => {
69
+ const { permit } = selectRequirementSignatures(signatures, {
70
+ permit: true,
71
+ });
72
+ return blueSupply({
73
+ market: { chainId: this.chainId, marketParams: this.marketParams },
74
+ args: {
75
+ amount,
76
+ nativeAmount,
77
+ onBehalf: userAddress,
78
+ maxSharePrice,
79
+ requirementSignature: permit,
80
+ },
81
+ metadata: this.client.options.metadata,
82
+ });
83
+ },
79
84
  };
80
85
  }
81
86
  withdraw(params) {
@@ -126,24 +131,31 @@ export class MorphoBlue {
126
131
  });
127
132
  return {
128
133
  getRequirements: async () => {
129
- const authTx = await getMorphoAuthorizationRequirement({
134
+ const authTx = await getBlueAuthorizationRequirement({
130
135
  viemClient: this.client.viemClient,
131
136
  chainId: this.chainId,
132
137
  userAddress,
138
+ supportSignature: this.client.options.supportSignature,
133
139
  });
134
140
  return authTx ? [authTx] : [];
135
141
  },
136
- buildTx: () => blueWithdraw({
137
- market: { chainId: this.chainId, marketParams: this.marketParams },
138
- args: {
139
- assets,
140
- shares,
141
- receiver,
142
- minSharePrice,
143
- reallocations,
144
- },
145
- metadata: this.client.options.metadata,
146
- }),
142
+ buildTx: (signatures) => {
143
+ const { authorization } = selectRequirementSignatures(signatures, {
144
+ authorization: true,
145
+ });
146
+ return blueWithdraw({
147
+ market: { chainId: this.chainId, marketParams: this.marketParams },
148
+ args: {
149
+ assets,
150
+ shares,
151
+ receiver,
152
+ minSharePrice,
153
+ reallocations,
154
+ authorizationSignature: authorization,
155
+ },
156
+ metadata: this.client.options.metadata,
157
+ });
158
+ },
147
159
  };
148
160
  }
149
161
  supplyCollateral({ amount = 0n, userAddress, nativeAmount, }) {
@@ -162,7 +174,7 @@ export class MorphoBlue {
162
174
  validateNativeAsset(this.chainId, this.marketParams.collateralToken);
163
175
  }
164
176
  return {
165
- getRequirements: (params) => getRequirements(this.client.viemClient, {
177
+ getRequirements: (params) => getGeneralAdapterRequirements(this.client.viemClient, {
166
178
  address: this.marketParams.collateralToken,
167
179
  chainId: this.chainId,
168
180
  supportSignature: this.client.options.supportSignature,
@@ -170,19 +182,24 @@ export class MorphoBlue {
170
182
  useSimplePermit: params?.useSimplePermit,
171
183
  args: { amount, from: userAddress },
172
184
  }),
173
- buildTx: (requirementSignature) => blueSupplyCollateral({
174
- market: {
175
- chainId: this.chainId,
176
- marketParams: this.marketParams,
177
- },
178
- args: {
179
- amount,
180
- nativeAmount,
181
- onBehalf: userAddress,
182
- requirementSignature,
183
- },
184
- metadata: this.client.options.metadata,
185
- }),
185
+ buildTx: (signatures) => {
186
+ const { permit } = selectRequirementSignatures(signatures, {
187
+ permit: true,
188
+ });
189
+ return blueSupplyCollateral({
190
+ market: {
191
+ chainId: this.chainId,
192
+ marketParams: this.marketParams,
193
+ },
194
+ args: {
195
+ amount,
196
+ nativeAmount,
197
+ onBehalf: userAddress,
198
+ requirementSignature: permit,
199
+ },
200
+ metadata: this.client.options.metadata,
201
+ });
202
+ },
186
203
  };
187
204
  }
188
205
  borrow({ amount, userAddress, positionData, slippageTolerance = DEFAULT_SLIPPAGE_TOLERANCE, reallocations, }) {
@@ -213,26 +230,33 @@ export class MorphoBlue {
213
230
  });
214
231
  return {
215
232
  getRequirements: async () => {
216
- const authTx = await getMorphoAuthorizationRequirement({
233
+ const authTx = await getBlueAuthorizationRequirement({
217
234
  viemClient: this.client.viemClient,
218
235
  chainId: this.chainId,
219
236
  userAddress,
237
+ supportSignature: this.client.options.supportSignature,
220
238
  });
221
239
  return authTx ? [authTx] : [];
222
240
  },
223
- buildTx: () => blueBorrow({
224
- market: {
225
- chainId: this.chainId,
226
- marketParams: this.marketParams,
227
- },
228
- args: {
229
- amount,
230
- receiver: userAddress,
231
- minSharePrice,
232
- reallocations,
233
- },
234
- metadata: this.client.options.metadata,
235
- }),
241
+ buildTx: (signatures) => {
242
+ const { authorization } = selectRequirementSignatures(signatures, {
243
+ authorization: true,
244
+ });
245
+ return blueBorrow({
246
+ market: {
247
+ chainId: this.chainId,
248
+ marketParams: this.marketParams,
249
+ },
250
+ args: {
251
+ amount,
252
+ receiver: userAddress,
253
+ minSharePrice,
254
+ reallocations,
255
+ authorizationSignature: authorization,
256
+ },
257
+ metadata: this.client.options.metadata,
258
+ });
259
+ },
236
260
  };
237
261
  }
238
262
  repay(params) {
@@ -298,7 +322,7 @@ export class MorphoBlue {
298
322
  slippageTolerance,
299
323
  });
300
324
  return {
301
- getRequirements: (reqParams) => getRequirements(this.client.viemClient, {
325
+ getRequirements: (reqParams) => getGeneralAdapterRequirements(this.client.viemClient, {
302
326
  address: this.marketParams.loanToken,
303
327
  chainId: this.chainId,
304
328
  supportSignature: this.client.options.supportSignature,
@@ -306,22 +330,27 @@ export class MorphoBlue {
306
330
  useSimplePermit: reqParams?.useSimplePermit,
307
331
  args: { amount: transferAmount, from: userAddress },
308
332
  }),
309
- buildTx: (requirementSignature) => blueRepay({
310
- market: {
311
- chainId: this.chainId,
312
- marketParams: this.marketParams,
313
- },
314
- args: {
315
- assets,
316
- shares,
317
- transferAmount,
318
- onBehalf: userAddress,
319
- receiver: userAddress,
320
- maxSharePrice,
321
- requirementSignature,
322
- },
323
- metadata: this.client.options.metadata,
324
- }),
333
+ buildTx: (signatures) => {
334
+ const { permit } = selectRequirementSignatures(signatures, {
335
+ permit: true,
336
+ });
337
+ return blueRepay({
338
+ market: {
339
+ chainId: this.chainId,
340
+ marketParams: this.marketParams,
341
+ },
342
+ args: {
343
+ assets,
344
+ shares,
345
+ transferAmount,
346
+ onBehalf: userAddress,
347
+ receiver: userAddress,
348
+ maxSharePrice,
349
+ requirementSignature: permit,
350
+ },
351
+ metadata: this.client.options.metadata,
352
+ });
353
+ },
325
354
  };
326
355
  }
327
356
  withdrawCollateral({ userAddress, amount, positionData, }) {
@@ -447,7 +476,7 @@ export class MorphoBlue {
447
476
  return {
448
477
  getRequirements: async (reqParams) => {
449
478
  const [erc20Requirements, authTx] = await Promise.all([
450
- getRequirements(this.client.viemClient, {
479
+ getGeneralAdapterRequirements(this.client.viemClient, {
451
480
  address: this.marketParams.loanToken,
452
481
  chainId: this.chainId,
453
482
  supportSignature: this.client.options.supportSignature,
@@ -455,31 +484,36 @@ export class MorphoBlue {
455
484
  useSimplePermit: reqParams?.useSimplePermit,
456
485
  args: { amount: transferAmount, from: userAddress },
457
486
  }),
458
- getMorphoAuthorizationRequirement({
487
+ getBlueAuthorizationRequirement({
459
488
  viemClient: this.client.viemClient,
460
489
  chainId: this.chainId,
461
490
  userAddress,
491
+ supportSignature: this.client.options.supportSignature,
462
492
  }),
463
493
  ]);
464
494
  return [...erc20Requirements, ...(authTx ? [authTx] : [])];
465
495
  },
466
- buildTx: (requirementSignature) => blueRepayWithdrawCollateral({
467
- market: {
468
- chainId: this.chainId,
469
- marketParams: this.marketParams,
470
- },
471
- args: {
472
- assets,
473
- shares,
474
- transferAmount,
475
- withdrawAmount,
476
- onBehalf: userAddress,
477
- receiver: userAddress,
478
- maxSharePrice,
479
- requirementSignature,
480
- },
481
- metadata: this.client.options.metadata,
482
- }),
496
+ buildTx: (signatures) => {
497
+ const { permit, authorization } = selectRequirementSignatures(signatures, { permit: true, authorization: true });
498
+ return blueRepayWithdrawCollateral({
499
+ market: {
500
+ chainId: this.chainId,
501
+ marketParams: this.marketParams,
502
+ },
503
+ args: {
504
+ assets,
505
+ shares,
506
+ transferAmount,
507
+ withdrawAmount,
508
+ onBehalf: userAddress,
509
+ receiver: userAddress,
510
+ maxSharePrice,
511
+ requirementSignature: permit,
512
+ authorizationSignature: authorization,
513
+ },
514
+ metadata: this.client.options.metadata,
515
+ });
516
+ },
483
517
  };
484
518
  }
485
519
  supplyCollateralBorrow({ amount = 0n, userAddress, positionData, borrowAmount, nativeAmount, slippageTolerance = DEFAULT_SLIPPAGE_TOLERANCE, reallocations, }) {
@@ -524,7 +558,7 @@ export class MorphoBlue {
524
558
  return {
525
559
  getRequirements: async (params) => {
526
560
  const [erc20Requirements, authTx] = await Promise.all([
527
- getRequirements(this.client.viemClient, {
561
+ getGeneralAdapterRequirements(this.client.viemClient, {
528
562
  address: this.marketParams.collateralToken,
529
563
  chainId: this.chainId,
530
564
  supportSignature: this.client.options.supportSignature,
@@ -532,31 +566,36 @@ export class MorphoBlue {
532
566
  useSimplePermit: params?.useSimplePermit,
533
567
  args: { amount, from: userAddress },
534
568
  }),
535
- getMorphoAuthorizationRequirement({
569
+ getBlueAuthorizationRequirement({
536
570
  viemClient: this.client.viemClient,
537
571
  chainId: this.chainId,
538
572
  userAddress,
573
+ supportSignature: this.client.options.supportSignature,
539
574
  }),
540
575
  ]);
541
576
  return [...erc20Requirements, ...(authTx ? [authTx] : [])];
542
577
  },
543
- buildTx: (requirementSignature) => blueSupplyCollateralBorrow({
544
- market: {
545
- chainId: this.chainId,
546
- marketParams: this.marketParams,
547
- },
548
- args: {
549
- amount,
550
- nativeAmount,
551
- borrowAmount,
552
- onBehalf: userAddress,
553
- receiver: userAddress,
554
- minSharePrice,
555
- requirementSignature,
556
- reallocations,
557
- },
558
- metadata: this.client.options.metadata,
559
- }),
578
+ buildTx: (signatures) => {
579
+ const { permit, authorization } = selectRequirementSignatures(signatures, { permit: true, authorization: true });
580
+ return blueSupplyCollateralBorrow({
581
+ market: {
582
+ chainId: this.chainId,
583
+ marketParams: this.marketParams,
584
+ },
585
+ args: {
586
+ amount,
587
+ nativeAmount,
588
+ borrowAmount,
589
+ onBehalf: userAddress,
590
+ receiver: userAddress,
591
+ minSharePrice,
592
+ requirementSignature: permit,
593
+ authorizationSignature: authorization,
594
+ reallocations,
595
+ },
596
+ metadata: this.client.options.metadata,
597
+ });
598
+ },
560
599
  };
561
600
  }
562
601
  refinance({ userAddress, positionData, target, collateralAmount, borrowAssets, borrowShares, slippageTolerance = DEFAULT_SLIPPAGE_TOLERANCE, targetReallocations, }) {
@@ -690,30 +729,37 @@ export class MorphoBlue {
690
729
  : 0n;
691
730
  return {
692
731
  getRequirements: async () => {
693
- const authTx = await getMorphoAuthorizationRequirement({
732
+ const authTx = await getBlueAuthorizationRequirement({
694
733
  viemClient: this.client.viemClient,
695
734
  chainId: this.chainId,
696
735
  userAddress,
736
+ supportSignature: this.client.options.supportSignature,
697
737
  });
698
738
  return authTx ? [authTx] : [];
699
739
  },
700
- buildTx: () => blueRefinance({
701
- source: {
702
- chainId: this.chainId,
703
- marketParams: this.marketParams,
704
- },
705
- target: { marketParams: target.marketParams },
706
- args: {
707
- user: userAddress,
708
- collateralAmount,
709
- borrowAssets: borrowAssetsAdjusted,
710
- borrowShares: requestedShares,
711
- minBorrowSharePrice,
712
- maxRepaySharePrice,
713
- targetReallocations,
714
- },
715
- metadata: this.client.options.metadata,
716
- }),
740
+ buildTx: (signatures) => {
741
+ const { authorization } = selectRequirementSignatures(signatures, {
742
+ authorization: true,
743
+ });
744
+ return blueRefinance({
745
+ source: {
746
+ chainId: this.chainId,
747
+ marketParams: this.marketParams,
748
+ },
749
+ target: { marketParams: target.marketParams },
750
+ args: {
751
+ user: userAddress,
752
+ collateralAmount,
753
+ borrowAssets: borrowAssetsAdjusted,
754
+ borrowShares: requestedShares,
755
+ minBorrowSharePrice,
756
+ maxRepaySharePrice,
757
+ targetReallocations,
758
+ authorizationSignature: authorization,
759
+ },
760
+ metadata: this.client.options.metadata,
761
+ });
762
+ },
717
763
  };
718
764
  }
719
765
  /**
@@ -200,28 +200,28 @@ export declare class ReallocationData implements InputReallocationData {
200
200
  */
201
201
  getPublicReallocationLiquidity(marketId: MarketId, options?: PublicAllocatorOptions): bigint;
202
202
  /**
203
- * Computes the liquidity available to bring `marketId` to `targetUtilization`,
203
+ * Computes the liquidity available to bring `marketId` to `utilization`,
204
204
  * counting the public-allocator liquidity reallocatable into it.
205
205
  *
206
206
  * Returns the max borrow `x` keeping post-borrow utilization
207
- * `(borrow + x) / (supply + L) ≤ targetUtilization`, where `L` is the
207
+ * `(borrow + x) / (supply + L) ≤ utilization`, where `L` is the
208
208
  * reallocatable liquidity added to the market's supply — equivalently
209
- * `getBorrowToUtilization({ supply + L, borrow }, targetUtilization)`. Below
210
- * the target this is the market's own borrow headroom plus `targetUtilization · L`;
209
+ * `getBorrowToUtilization({ supply + L, borrow }, utilization)`. Below
210
+ * `utilization` this is the market's own borrow headroom plus `utilization · L`;
211
211
  * reallocated supply also raises the supply denominator, so only that scaled
212
212
  * share backs further borrow.
213
213
  *
214
214
  * Read-only metric — never throws on insufficiency:
215
215
  * - returns only the market's own borrow headroom when
216
- * `supplyTargetUtilization > targetUtilization` (reallocation would not
217
- * trigger at that target);
218
- * - returns `0n` when the market is already at or above the target and `L` is
219
- * too small to bring it back under.
216
+ * `supplyTargetUtilization > utilization` (reallocation would not
217
+ * trigger at that utilization);
218
+ * - returns `0n` when the market is already at or above `utilization` and `L`
219
+ * is too small to bring it back under.
220
220
  *
221
221
  * @param marketId - Target market to borrow from.
222
- * @param targetUtilization - Utilization to bring the market to, scaled by WAD. Defaults to {@link DEFAULT_SUPPLY_TARGET_UTILIZATION}.
222
+ * @param utilization - Utilization to bring the market to, scaled by WAD. Defaults to {@link DEFAULT_SUPPLY_TARGET_UTILIZATION}.
223
223
  * @param options - Optional reallocation options (supply target utilization trigger, timestamp, withdrawal caps).
224
- * @returns Available liquidity to the target utilization in loan-token units; `0n` when none is available.
224
+ * @returns Available liquidity to the given utilization in loan-token units; `0n` when none is available.
225
225
  * @throws {@link UnknownReallocationMarketError} when the target market is absent.
226
226
  * @example
227
227
  * ```ts
@@ -245,14 +245,14 @@ export declare class ReallocationData implements InputReallocationData {
245
245
  *
246
246
  * // Max borrow keeping utilization at or below 90%, counting shared liquidity.
247
247
  * const available: bigint =
248
- * reallocationData.getAvailableLiquidityToTargetUtilization(
248
+ * reallocationData.getAvailableLiquidityToUtilization(
249
249
  * marketParams.id,
250
250
  * parseEther("0.9"),
251
251
  * { timestamp: block.timestamp },
252
252
  * );
253
253
  * ```
254
254
  */
255
- getAvailableLiquidityToTargetUtilization(marketId: MarketId, targetUtilization?: bigint, options?: ReallocationComputeOptions): bigint;
255
+ getAvailableLiquidityToUtilization(marketId: MarketId, utilization?: bigint, options?: ReallocationComputeOptions): bigint;
256
256
  /**
257
257
  * Gets the largest currently valid source-market withdrawal for a vault.
258
258
  *
@@ -1,5 +1,5 @@
1
- import { _try, AccrualPosition, Market, MarketUtils, MathLib, Position, UnknownDataError, Vault, VaultMarketConfig, VaultMarketPublicAllocatorConfig, } from "@morpho-org/blue-sdk";
2
- import { bigIntComparator } from "@morpho-org/morpho-ts";
1
+ import { AccrualPosition, Market, MarketUtils, MathLib, Position, UnknownDataError, Vault, VaultMarketConfig, VaultMarketPublicAllocatorConfig, } from "@morpho-org/blue-sdk";
2
+ import { _try, bigIntComparator } from "@morpho-org/morpho-ts";
3
3
  import { DEFAULT_SUPPLY_TARGET_UTILIZATION, DEFAULT_WITHDRAWAL_TARGET_UTILIZATION, } from "../helpers/constant.js";
4
4
  import { getSupplyTargetUtilization } from "../helpers/utilization.js";
5
5
  import { DisabledReallocationMarketError, MissingPublicAllocatorConfigError, UnknownReallocationMarketError, UnknownReallocationPositionError, UnknownReallocationVaultError, UnknownReallocationVaultMarketConfigError, } from "../types/index.js";
@@ -345,28 +345,28 @@ export class ReallocationData {
345
345
  return withdrawals.reduce((total, { assets }) => total + assets, 0n);
346
346
  }
347
347
  /**
348
- * Computes the liquidity available to bring `marketId` to `targetUtilization`,
348
+ * Computes the liquidity available to bring `marketId` to `utilization`,
349
349
  * counting the public-allocator liquidity reallocatable into it.
350
350
  *
351
351
  * Returns the max borrow `x` keeping post-borrow utilization
352
- * `(borrow + x) / (supply + L) ≤ targetUtilization`, where `L` is the
352
+ * `(borrow + x) / (supply + L) ≤ utilization`, where `L` is the
353
353
  * reallocatable liquidity added to the market's supply — equivalently
354
- * `getBorrowToUtilization({ supply + L, borrow }, targetUtilization)`. Below
355
- * the target this is the market's own borrow headroom plus `targetUtilization · L`;
354
+ * `getBorrowToUtilization({ supply + L, borrow }, utilization)`. Below
355
+ * `utilization` this is the market's own borrow headroom plus `utilization · L`;
356
356
  * reallocated supply also raises the supply denominator, so only that scaled
357
357
  * share backs further borrow.
358
358
  *
359
359
  * Read-only metric — never throws on insufficiency:
360
360
  * - returns only the market's own borrow headroom when
361
- * `supplyTargetUtilization > targetUtilization` (reallocation would not
362
- * trigger at that target);
363
- * - returns `0n` when the market is already at or above the target and `L` is
364
- * too small to bring it back under.
361
+ * `supplyTargetUtilization > utilization` (reallocation would not
362
+ * trigger at that utilization);
363
+ * - returns `0n` when the market is already at or above `utilization` and `L`
364
+ * is too small to bring it back under.
365
365
  *
366
366
  * @param marketId - Target market to borrow from.
367
- * @param targetUtilization - Utilization to bring the market to, scaled by WAD. Defaults to {@link DEFAULT_SUPPLY_TARGET_UTILIZATION}.
367
+ * @param utilization - Utilization to bring the market to, scaled by WAD. Defaults to {@link DEFAULT_SUPPLY_TARGET_UTILIZATION}.
368
368
  * @param options - Optional reallocation options (supply target utilization trigger, timestamp, withdrawal caps).
369
- * @returns Available liquidity to the target utilization in loan-token units; `0n` when none is available.
369
+ * @returns Available liquidity to the given utilization in loan-token units; `0n` when none is available.
370
370
  * @throws {@link UnknownReallocationMarketError} when the target market is absent.
371
371
  * @example
372
372
  * ```ts
@@ -390,26 +390,26 @@ export class ReallocationData {
390
390
  *
391
391
  * // Max borrow keeping utilization at or below 90%, counting shared liquidity.
392
392
  * const available: bigint =
393
- * reallocationData.getAvailableLiquidityToTargetUtilization(
393
+ * reallocationData.getAvailableLiquidityToUtilization(
394
394
  * marketParams.id,
395
395
  * parseEther("0.9"),
396
396
  * { timestamp: block.timestamp },
397
397
  * );
398
398
  * ```
399
399
  */
400
- // biome-ignore lint/complexity/useMaxParams: (marketId, targetUtilization, options) is the metric's public API
401
- getAvailableLiquidityToTargetUtilization(marketId, targetUtilization = DEFAULT_SUPPLY_TARGET_UTILIZATION, options) {
400
+ // biome-ignore lint/complexity/useMaxParams: (marketId, utilization, options) is the metric's public API
401
+ getAvailableLiquidityToUtilization(marketId, utilization = DEFAULT_SUPPLY_TARGET_UTILIZATION, options) {
402
402
  const market = this.getMarket(marketId).accrueInterest(options?.timestamp);
403
403
  // Below the allocator's trigger, no reallocation happens: own headroom only.
404
404
  const supplyTargetUtilization = getSupplyTargetUtilization(marketId, options);
405
- if (supplyTargetUtilization > targetUtilization)
406
- return market.getBorrowToUtilization(targetUtilization);
405
+ if (supplyTargetUtilization > utilization)
406
+ return market.getBorrowToUtilization(utilization);
407
407
  // Borrow-to-target on the post-reallocation supply; clamps to 0n above target.
408
408
  const availableLiquidity = this.getPublicReallocationLiquidity(marketId, options);
409
409
  return MarketUtils.getBorrowToUtilization({
410
410
  totalSupplyAssets: market.totalSupplyAssets + availableLiquidity,
411
411
  totalBorrowAssets: market.totalBorrowAssets,
412
- }, targetUtilization);
412
+ }, utilization);
413
413
  }
414
414
  /**
415
415
  * Gets the largest currently valid source-market withdrawal for a vault.
@@ -2,7 +2,7 @@ import { type AccrualVault, type AccrualVaultV2 } from "@morpho-org/blue-sdk";
2
2
  import { fetchAccrualVault } from "@morpho-org/blue-sdk-viem";
3
3
  import { type Address } from "viem";
4
4
  import type { FetchParameters } from "../../types/data.js";
5
- import { type DepositAmountArgs, type ERC20ApprovalAction, type MorphoClientType, type Requirement, type RequirementSignature, type Transaction, type VaultV1DepositAction, type VaultV1MigrateToV2Action, type VaultV1RedeemAction, type VaultV1WithdrawAction } from "../../types/index.js";
5
+ import { type DepositAmountArgs, type ERC20ApprovalAction, type MorphoClientType, type PermitRequirementSignature, type Requirement, type RequirementSignature, type Transaction, type VaultV1DepositAction, type VaultV1MigrateToV2Action, type VaultV1RedeemAction, type VaultV1WithdrawAction } from "../../types/index.js";
6
6
  export interface VaultV1Actions {
7
7
  /**
8
8
  * Fetches the latest vault data with accrued interest.
@@ -30,10 +30,10 @@ export interface VaultV1Actions {
30
30
  vaultData: AccrualVault;
31
31
  slippageTolerance?: bigint;
32
32
  } & DepositAmountArgs) => {
33
- buildTx: (requirementSignature?: RequirementSignature) => Readonly<Transaction<VaultV1DepositAction>>;
33
+ buildTx: (signatures?: readonly RequirementSignature[]) => Readonly<Transaction<VaultV1DepositAction>>;
34
34
  getRequirements: (params?: {
35
35
  useSimplePermit?: boolean;
36
- }) => Promise<(Readonly<Transaction<ERC20ApprovalAction>> | Requirement)[]>;
36
+ }) => Promise<(Readonly<Transaction<ERC20ApprovalAction>> | Requirement<PermitRequirementSignature>)[]>;
37
37
  };
38
38
  /**
39
39
  * Prepares a withdraw from a VaultV1 (MetaMorpho) contract.
@@ -84,8 +84,8 @@ export interface VaultV1Actions {
84
84
  shares: bigint;
85
85
  slippageTolerance?: bigint;
86
86
  }) => {
87
- buildTx: (requirementSignature?: RequirementSignature) => Readonly<Transaction<VaultV1MigrateToV2Action>>;
88
- getRequirements: () => Promise<(Readonly<Transaction<ERC20ApprovalAction>> | Requirement)[]>;
87
+ buildTx: (signatures?: readonly RequirementSignature[]) => Readonly<Transaction<VaultV1MigrateToV2Action>>;
88
+ getRequirements: () => Promise<(Readonly<Transaction<ERC20ApprovalAction>> | Requirement<PermitRequirementSignature>)[]>;
89
89
  };
90
90
  }
91
91
  export declare class MorphoVaultV1 implements VaultV1Actions {
@@ -101,8 +101,8 @@ export declare class MorphoVaultV1 implements VaultV1Actions {
101
101
  } & DepositAmountArgs): {
102
102
  getRequirements: (params?: {
103
103
  useSimplePermit?: boolean;
104
- }) => Promise<(Requirement | Readonly<Transaction<ERC20ApprovalAction>>)[]>;
105
- buildTx: (requirementSignature?: RequirementSignature) => Readonly<Transaction<VaultV1DepositAction>>;
104
+ }) => Promise<(import("../../types/action.js").Bundler3TokenSignatureRequirement | Readonly<Transaction<ERC20ApprovalAction>>)[]>;
105
+ buildTx: (signatures?: readonly RequirementSignature[]) => Readonly<Transaction<VaultV1DepositAction>>;
106
106
  };
107
107
  withdraw({ amount, userAddress }: {
108
108
  amount: bigint;
@@ -123,7 +123,7 @@ export declare class MorphoVaultV1 implements VaultV1Actions {
123
123
  shares: bigint;
124
124
  slippageTolerance?: bigint;
125
125
  }): {
126
- getRequirements: () => Promise<(Requirement | Readonly<Transaction<ERC20ApprovalAction>>)[]>;
127
- buildTx: (requirementSignature?: RequirementSignature) => Readonly<Transaction<VaultV1MigrateToV2Action>>;
126
+ getRequirements: () => Promise<(import("../../types/action.js").Bundler3TokenSignatureRequirement | Readonly<Transaction<ERC20ApprovalAction>>)[]>;
127
+ buildTx: (signatures?: readonly RequirementSignature[]) => Readonly<Transaction<VaultV1MigrateToV2Action>>;
128
128
  };
129
129
  }