@morpho-org/morpho-sdk 10.0.1 → 10.1.0-next.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 (250) hide show
  1. package/README.md +31 -10
  2. package/lib/cjs/abis.d.ts +1 -1
  3. package/lib/cjs/abis.js +5 -1
  4. package/lib/cjs/actions/blue/refinance.d.ts +1 -1
  5. package/lib/cjs/actions/blue/refinance.js +3 -8
  6. package/lib/cjs/actions/blue/refinanceValidation.d.ts +19 -0
  7. package/lib/cjs/actions/blue/refinanceValidation.js +46 -0
  8. package/lib/cjs/actions/requirements/encode/encodeErc20Approval.d.ts +1 -1
  9. package/lib/cjs/actions/requirements/encode/encodeErc20Approval.js +3 -7
  10. package/lib/cjs/actions/requirements/encode/encodeErc20Permit.d.ts +1 -1
  11. package/lib/cjs/actions/requirements/encode/encodeErc20Permit.js +4 -20
  12. package/lib/cjs/actions/requirements/getRequirementsApproval.js +7 -21
  13. package/lib/cjs/actions/requirements/validateClientChainId.d.ts +1 -26
  14. package/lib/cjs/actions/requirements/validateClientChainId.js +2 -31
  15. package/lib/cjs/actions/vaultV2/forceRedeem.d.ts +2 -1
  16. package/lib/cjs/actions/vaultV2/forceRedeem.js +20 -2
  17. package/lib/cjs/blue/abis.d.ts +1 -1
  18. package/lib/cjs/blue/abis.js +5 -1
  19. package/lib/cjs/blue/entities.d.ts +4 -4
  20. package/lib/cjs/blue/entities.js +3 -1
  21. package/lib/cjs/blue/errors.d.ts +2 -2
  22. package/lib/cjs/blue/errors.js +5 -1
  23. package/lib/cjs/blue/fetch.d.ts +2 -2
  24. package/lib/cjs/blue/fetch.js +3 -1
  25. package/lib/cjs/blue/utils.d.ts +1 -1
  26. package/lib/cjs/blue/utils.js +2 -1
  27. package/lib/cjs/entities/blue/blue.js +24 -55
  28. package/lib/cjs/entities/index.d.ts +4 -4
  29. package/lib/cjs/entities/index.js +3 -1
  30. package/lib/cjs/entities/requirements/getErc2612Permit.d.ts +2 -5
  31. package/lib/cjs/entities/requirements/getErc2612Permit.js +9 -58
  32. package/lib/cjs/entities/vaultV2/vaultV2.d.ts +34 -8
  33. package/lib/cjs/entities/vaultV2/vaultV2.js +39 -1
  34. package/lib/cjs/entities/vaultV2BlueReallocationData.d.ts +3 -2
  35. package/lib/cjs/entities/vaultV2BlueReallocationData.js +6 -2
  36. package/lib/cjs/errors.d.ts +4 -4
  37. package/lib/cjs/errors.js +7 -5
  38. package/lib/cjs/fetch.d.ts +2 -2
  39. package/lib/cjs/fetch.js +3 -1
  40. package/lib/cjs/helpers/deadShares.js +3 -0
  41. package/lib/cjs/helpers/quoteBlueRepay.d.ts +16 -0
  42. package/lib/cjs/helpers/quoteBlueRepay.js +46 -0
  43. package/lib/cjs/helpers/tokenApproval.d.ts +14 -0
  44. package/lib/cjs/helpers/tokenApproval.js +20 -0
  45. package/lib/cjs/helpers/validate.d.ts +1 -1
  46. package/lib/cjs/helpers/validate.js +2 -2
  47. package/lib/cjs/index.d.ts +2 -2
  48. package/lib/cjs/index.js +13 -1
  49. package/lib/cjs/midnight/errors.d.ts +2 -1
  50. package/lib/cjs/midnight/errors.js +5 -4
  51. package/lib/cjs/reads/readErc2612Permit.d.ts +22 -0
  52. package/lib/cjs/reads/readErc2612Permit.js +77 -0
  53. package/lib/cjs/reads/validateClientChainId.d.ts +26 -0
  54. package/lib/cjs/reads/validateClientChainId.js +34 -0
  55. package/lib/cjs/transactionPlan/blue/authorization.d.ts +23 -0
  56. package/lib/cjs/transactionPlan/blue/authorization.js +128 -0
  57. package/lib/cjs/transactionPlan/blue/borrow.d.ts +80 -0
  58. package/lib/cjs/transactionPlan/blue/borrow.js +248 -0
  59. package/lib/cjs/transactionPlan/blue/prepare.d.ts +102 -0
  60. package/lib/cjs/transactionPlan/blue/prepare.js +191 -0
  61. package/lib/cjs/transactionPlan/blue/refinance.d.ts +93 -0
  62. package/lib/cjs/transactionPlan/blue/refinance.js +281 -0
  63. package/lib/cjs/transactionPlan/blue/refinanceValidation.d.ts +11 -0
  64. package/lib/cjs/transactionPlan/blue/refinanceValidation.js +20 -0
  65. package/lib/cjs/transactionPlan/blue/repay.d.ts +80 -0
  66. package/lib/cjs/transactionPlan/blue/repay.js +229 -0
  67. package/lib/cjs/transactionPlan/blue/repayWithdrawCollateral.d.ts +98 -0
  68. package/lib/cjs/transactionPlan/blue/repayWithdrawCollateral.js +379 -0
  69. package/lib/cjs/transactionPlan/blue/supply.d.ts +181 -0
  70. package/lib/cjs/transactionPlan/blue/supply.js +238 -0
  71. package/lib/cjs/transactionPlan/blue/supplyCollateral.d.ts +97 -0
  72. package/lib/cjs/transactionPlan/blue/supplyCollateral.js +231 -0
  73. package/lib/cjs/transactionPlan/blue/supplyCollateralBorrow.d.ts +102 -0
  74. package/lib/cjs/transactionPlan/blue/supplyCollateralBorrow.js +395 -0
  75. package/lib/cjs/transactionPlan/blue/withdraw.d.ts +136 -0
  76. package/lib/cjs/transactionPlan/blue/withdraw.js +340 -0
  77. package/lib/cjs/transactionPlan/blue/withdrawCollateral.d.ts +123 -0
  78. package/lib/cjs/transactionPlan/blue/withdrawCollateral.js +246 -0
  79. package/lib/cjs/transactionPlan/deposit.js +8 -19
  80. package/lib/cjs/transactionPlan/error.d.ts +50 -0
  81. package/lib/cjs/transactionPlan/error.js +60 -1
  82. package/lib/cjs/transactionPlan/getTokenPermit.d.ts +17 -8
  83. package/lib/cjs/transactionPlan/getTokenPermit.js +35 -7
  84. package/lib/cjs/transactionPlan/index.d.ts +21 -1
  85. package/lib/cjs/transactionPlan/index.js +27 -5
  86. package/lib/cjs/transactionPlan/intent.d.ts +2 -2
  87. package/lib/cjs/transactionPlan/intent.js +8 -4
  88. package/lib/cjs/transactionPlan/permit.d.ts +16 -2
  89. package/lib/cjs/transactionPlan/permit.js +77 -45
  90. package/lib/cjs/transactionPlan/plan.d.ts +67 -12
  91. package/lib/cjs/transactionPlan/plan.js +284 -50
  92. package/lib/cjs/transactionPlan/requirements.d.ts +14 -5
  93. package/lib/cjs/transactionPlan/requirements.js +30 -12
  94. package/lib/cjs/transactionPlan/serde.d.ts +7 -4
  95. package/lib/cjs/transactionPlan/serde.js +80 -61
  96. package/lib/cjs/transactionPlan/types.d.ts +141 -13
  97. package/lib/cjs/transactionPlan/validateActions.js +11 -1
  98. package/lib/cjs/transactionPlan/validation.d.ts +8 -0
  99. package/lib/cjs/transactionPlan/validation.js +90 -0
  100. package/lib/cjs/transactionPlan/vaultv1/deposit.d.ts +1 -0
  101. package/lib/cjs/transactionPlan/vaultv1/deposit.js +1 -0
  102. package/lib/cjs/transactionPlan/vaultv1/inKindRedeem.d.ts +1 -0
  103. package/lib/cjs/transactionPlan/vaultv1/inKindRedeem.js +1 -0
  104. package/lib/cjs/transactionPlan/vaultv1/migrateToV2.d.ts +1 -0
  105. package/lib/cjs/transactionPlan/vaultv1/migrateToV2.js +1 -0
  106. package/lib/cjs/transactionPlan/vaultv1/redeem.d.ts +1 -0
  107. package/lib/cjs/transactionPlan/vaultv1/redeem.js +1 -0
  108. package/lib/cjs/transactionPlan/vaultv1/withdraw.d.ts +1 -0
  109. package/lib/cjs/transactionPlan/vaultv1/withdraw.js +1 -0
  110. package/lib/cjs/transactionPlan/vaultv2/deposit.d.ts +1 -0
  111. package/lib/cjs/transactionPlan/vaultv2/deposit.js +1 -0
  112. package/lib/cjs/transactionPlan/vaultv2/forceRedeem.d.ts +1 -0
  113. package/lib/cjs/transactionPlan/vaultv2/forceRedeem.js +1 -0
  114. package/lib/cjs/transactionPlan/vaultv2/forceWithdraw.d.ts +1 -0
  115. package/lib/cjs/transactionPlan/vaultv2/forceWithdraw.js +1 -0
  116. package/lib/cjs/transactionPlan/vaultv2/inKindRedeem.d.ts +1 -0
  117. package/lib/cjs/transactionPlan/vaultv2/inKindRedeem.js +1 -0
  118. package/lib/cjs/transactionPlan/vaultv2/redeem.d.ts +1 -0
  119. package/lib/cjs/transactionPlan/vaultv2/redeem.js +1 -0
  120. package/lib/cjs/transactionPlan/vaultv2/withdraw.d.ts +1 -0
  121. package/lib/cjs/transactionPlan/vaultv2/withdraw.js +1 -0
  122. package/lib/cjs/utils.d.ts +2 -2
  123. package/lib/cjs/utils.js +4 -2
  124. package/lib/cjs/version.d.ts +1 -1
  125. package/lib/cjs/version.js +1 -1
  126. package/lib/esm/abis.d.ts +1 -1
  127. package/lib/esm/abis.js +1 -1
  128. package/lib/esm/actions/blue/refinance.d.ts +1 -1
  129. package/lib/esm/actions/blue/refinance.js +4 -9
  130. package/lib/esm/actions/blue/refinanceValidation.d.ts +19 -0
  131. package/lib/esm/actions/blue/refinanceValidation.js +41 -0
  132. package/lib/esm/actions/requirements/encode/encodeErc20Approval.d.ts +1 -1
  133. package/lib/esm/actions/requirements/encode/encodeErc20Approval.js +4 -8
  134. package/lib/esm/actions/requirements/encode/encodeErc20Permit.d.ts +1 -1
  135. package/lib/esm/actions/requirements/encode/encodeErc20Permit.js +5 -21
  136. package/lib/esm/actions/requirements/getRequirementsApproval.js +7 -21
  137. package/lib/esm/actions/requirements/validateClientChainId.d.ts +1 -26
  138. package/lib/esm/actions/requirements/validateClientChainId.js +1 -30
  139. package/lib/esm/actions/vaultV2/forceRedeem.d.ts +2 -1
  140. package/lib/esm/actions/vaultV2/forceRedeem.js +20 -2
  141. package/lib/esm/blue/abis.d.ts +1 -1
  142. package/lib/esm/blue/abis.js +1 -1
  143. package/lib/esm/blue/entities.d.ts +4 -4
  144. package/lib/esm/blue/entities.js +2 -2
  145. package/lib/esm/blue/errors.d.ts +2 -2
  146. package/lib/esm/blue/errors.js +2 -2
  147. package/lib/esm/blue/fetch.d.ts +2 -2
  148. package/lib/esm/blue/fetch.js +2 -2
  149. package/lib/esm/blue/utils.d.ts +1 -1
  150. package/lib/esm/blue/utils.js +1 -1
  151. package/lib/esm/entities/blue/blue.js +26 -57
  152. package/lib/esm/entities/index.d.ts +4 -4
  153. package/lib/esm/entities/index.js +2 -2
  154. package/lib/esm/entities/requirements/getErc2612Permit.d.ts +2 -5
  155. package/lib/esm/entities/requirements/getErc2612Permit.js +9 -58
  156. package/lib/esm/entities/vaultV2/vaultV2.d.ts +34 -8
  157. package/lib/esm/entities/vaultV2/vaultV2.js +40 -2
  158. package/lib/esm/entities/vaultV2BlueReallocationData.d.ts +3 -2
  159. package/lib/esm/entities/vaultV2BlueReallocationData.js +6 -2
  160. package/lib/esm/errors.d.ts +4 -4
  161. package/lib/esm/errors.js +4 -4
  162. package/lib/esm/fetch.d.ts +2 -2
  163. package/lib/esm/fetch.js +2 -2
  164. package/lib/esm/helpers/deadShares.js +4 -1
  165. package/lib/esm/helpers/quoteBlueRepay.d.ts +16 -0
  166. package/lib/esm/helpers/quoteBlueRepay.js +42 -0
  167. package/lib/esm/helpers/tokenApproval.d.ts +14 -0
  168. package/lib/esm/helpers/tokenApproval.js +16 -0
  169. package/lib/esm/helpers/validate.d.ts +1 -1
  170. package/lib/esm/helpers/validate.js +3 -3
  171. package/lib/esm/index.d.ts +2 -2
  172. package/lib/esm/index.js +1 -1
  173. package/lib/esm/midnight/errors.d.ts +2 -1
  174. package/lib/esm/midnight/errors.js +2 -1
  175. package/lib/esm/reads/readErc2612Permit.d.ts +22 -0
  176. package/lib/esm/reads/readErc2612Permit.js +73 -0
  177. package/lib/esm/reads/validateClientChainId.d.ts +26 -0
  178. package/lib/esm/reads/validateClientChainId.js +30 -0
  179. package/lib/esm/transactionPlan/blue/authorization.d.ts +23 -0
  180. package/lib/esm/transactionPlan/blue/authorization.js +122 -0
  181. package/lib/esm/transactionPlan/blue/borrow.d.ts +80 -0
  182. package/lib/esm/transactionPlan/blue/borrow.js +243 -0
  183. package/lib/esm/transactionPlan/blue/prepare.d.ts +102 -0
  184. package/lib/esm/transactionPlan/blue/prepare.js +187 -0
  185. package/lib/esm/transactionPlan/blue/refinance.d.ts +93 -0
  186. package/lib/esm/transactionPlan/blue/refinance.js +276 -0
  187. package/lib/esm/transactionPlan/blue/refinanceValidation.d.ts +11 -0
  188. package/lib/esm/transactionPlan/blue/refinanceValidation.js +17 -0
  189. package/lib/esm/transactionPlan/blue/repay.d.ts +80 -0
  190. package/lib/esm/transactionPlan/blue/repay.js +223 -0
  191. package/lib/esm/transactionPlan/blue/repayWithdrawCollateral.d.ts +98 -0
  192. package/lib/esm/transactionPlan/blue/repayWithdrawCollateral.js +373 -0
  193. package/lib/esm/transactionPlan/blue/supply.d.ts +181 -0
  194. package/lib/esm/transactionPlan/blue/supply.js +232 -0
  195. package/lib/esm/transactionPlan/blue/supplyCollateral.d.ts +97 -0
  196. package/lib/esm/transactionPlan/blue/supplyCollateral.js +225 -0
  197. package/lib/esm/transactionPlan/blue/supplyCollateralBorrow.d.ts +102 -0
  198. package/lib/esm/transactionPlan/blue/supplyCollateralBorrow.js +389 -0
  199. package/lib/esm/transactionPlan/blue/withdraw.d.ts +136 -0
  200. package/lib/esm/transactionPlan/blue/withdraw.js +334 -0
  201. package/lib/esm/transactionPlan/blue/withdrawCollateral.d.ts +123 -0
  202. package/lib/esm/transactionPlan/blue/withdrawCollateral.js +240 -0
  203. package/lib/esm/transactionPlan/deposit.js +9 -20
  204. package/lib/esm/transactionPlan/error.d.ts +50 -0
  205. package/lib/esm/transactionPlan/error.js +57 -0
  206. package/lib/esm/transactionPlan/getTokenPermit.d.ts +17 -8
  207. package/lib/esm/transactionPlan/getTokenPermit.js +35 -7
  208. package/lib/esm/transactionPlan/index.d.ts +21 -1
  209. package/lib/esm/transactionPlan/index.js +11 -1
  210. package/lib/esm/transactionPlan/intent.d.ts +2 -2
  211. package/lib/esm/transactionPlan/intent.js +8 -4
  212. package/lib/esm/transactionPlan/permit.d.ts +16 -2
  213. package/lib/esm/transactionPlan/permit.js +76 -44
  214. package/lib/esm/transactionPlan/plan.d.ts +67 -12
  215. package/lib/esm/transactionPlan/plan.js +279 -46
  216. package/lib/esm/transactionPlan/requirements.d.ts +14 -5
  217. package/lib/esm/transactionPlan/requirements.js +30 -12
  218. package/lib/esm/transactionPlan/serde.d.ts +7 -4
  219. package/lib/esm/transactionPlan/serde.js +73 -54
  220. package/lib/esm/transactionPlan/types.d.ts +141 -13
  221. package/lib/esm/transactionPlan/validateActions.js +11 -1
  222. package/lib/esm/transactionPlan/validation.d.ts +8 -0
  223. package/lib/esm/transactionPlan/validation.js +88 -1
  224. package/lib/esm/transactionPlan/vaultv1/deposit.d.ts +1 -0
  225. package/lib/esm/transactionPlan/vaultv1/deposit.js +1 -0
  226. package/lib/esm/transactionPlan/vaultv1/inKindRedeem.d.ts +1 -0
  227. package/lib/esm/transactionPlan/vaultv1/inKindRedeem.js +1 -0
  228. package/lib/esm/transactionPlan/vaultv1/migrateToV2.d.ts +1 -0
  229. package/lib/esm/transactionPlan/vaultv1/migrateToV2.js +1 -0
  230. package/lib/esm/transactionPlan/vaultv1/redeem.d.ts +1 -0
  231. package/lib/esm/transactionPlan/vaultv1/redeem.js +1 -0
  232. package/lib/esm/transactionPlan/vaultv1/withdraw.d.ts +1 -0
  233. package/lib/esm/transactionPlan/vaultv1/withdraw.js +1 -0
  234. package/lib/esm/transactionPlan/vaultv2/deposit.d.ts +1 -0
  235. package/lib/esm/transactionPlan/vaultv2/deposit.js +1 -0
  236. package/lib/esm/transactionPlan/vaultv2/forceRedeem.d.ts +1 -0
  237. package/lib/esm/transactionPlan/vaultv2/forceRedeem.js +1 -0
  238. package/lib/esm/transactionPlan/vaultv2/forceWithdraw.d.ts +1 -0
  239. package/lib/esm/transactionPlan/vaultv2/forceWithdraw.js +1 -0
  240. package/lib/esm/transactionPlan/vaultv2/inKindRedeem.d.ts +1 -0
  241. package/lib/esm/transactionPlan/vaultv2/inKindRedeem.js +1 -0
  242. package/lib/esm/transactionPlan/vaultv2/redeem.d.ts +1 -0
  243. package/lib/esm/transactionPlan/vaultv2/redeem.js +1 -0
  244. package/lib/esm/transactionPlan/vaultv2/withdraw.d.ts +1 -0
  245. package/lib/esm/transactionPlan/vaultv2/withdraw.js +1 -0
  246. package/lib/esm/utils.d.ts +2 -2
  247. package/lib/esm/utils.js +2 -2
  248. package/lib/esm/version.d.ts +1 -1
  249. package/lib/esm/version.js +1 -1
  250. package/package.json +7 -7
@@ -4,10 +4,24 @@ import type { Action, SignatureRequest } from "./types.js";
4
4
  /** @internal Validates the stored ERC-2612 request shape without verifying its signature. */
5
5
  export declare function validatePermitPlanRequest(request: Record<string, unknown>, path: string): void;
6
6
  /** @internal Checks a permit's signing payload against its referencing action and encoding arguments. */
7
- export declare function validateSignatureRequest(request: SignatureRequest, action: Action): void;
7
+ export declare function validateVaultPermitRequest(request: SignatureRequest, action: Action): void;
8
+ /** @internal Binds the signing payload and encoding arguments to a registered bundle's token pull. */
9
+ export declare function validateTokenPermitRequest(request: Extract<SignatureRequest, {
10
+ kind: "permit";
11
+ }>, pull: {
12
+ readonly chainId: number;
13
+ readonly account: Address;
14
+ readonly deadline: bigint | undefined;
15
+ readonly bundler: "bundles.vaultBundlesV1" | "bundles.vaultExitBundlesV1" | "bundles.blueBundlesV1";
16
+ readonly asset: Address;
17
+ readonly amount: bigint | undefined;
18
+ readonly exact: boolean;
19
+ }): void;
8
20
  /** @internal Rebuilds a token permit from the action's account/asset and its resolved signature requests. */
9
- export declare function getVaultPermit(requests: readonly SignatureRequest[], { id, asset, owner, }: {
21
+ export declare function getSignedTokenPermit(requests: readonly SignatureRequest[], { id, asset, owner, }: {
10
22
  readonly id: string | undefined;
11
23
  readonly asset: Address;
12
24
  readonly owner: Address;
13
25
  }): Erc2612RequirementSignature | undefined;
26
+ /** @internal Alias for existing Vault V2 plan builders. */
27
+ export { getSignedTokenPermit as getVaultPermit };
@@ -1,8 +1,12 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.validatePermitPlanRequest = validatePermitPlanRequest;
4
- exports.validateSignatureRequest = validateSignatureRequest;
5
- exports.getVaultPermit = getVaultPermit;
4
+ exports.validateVaultPermitRequest = validateVaultPermitRequest;
5
+ exports.validateTokenPermitRequest = validateTokenPermitRequest;
6
+ exports.getSignedTokenPermit = getSignedTokenPermit;
7
+ exports.getVaultPermit = getSignedTokenPermit;
8
+ const blue_sdk_1 = require("@morpho-org/blue-sdk");
9
+ const blue_sdk_viem_1 = require("@morpho-org/blue-sdk-viem");
6
10
  const morpho_ts_1 = require("@morpho-org/morpho-ts");
7
11
  const viem_1 = require("viem");
8
12
  const error_js_1 = require("./error.js");
@@ -78,114 +82,139 @@ function validatePermitPlanRequest(request, path) {
78
82
  }
79
83
  }
80
84
  /** @internal Checks a permit's signing payload against its referencing action and encoding arguments. */
81
- function validateSignatureRequest(request, action) {
82
- const { chainId, account } = action.inputs;
83
- const { domain, message, primaryType } = request.typedData;
85
+ function validateVaultPermitRequest(request, action) {
86
+ if (request.kind !== "permit") {
87
+ throw new error_js_1.TransactionPlanSignatureMismatchError(request.id, "reference");
88
+ }
84
89
  let spenderKey;
85
90
  let asset;
86
- let amountMatches;
91
+ let amount;
92
+ let exact = false;
87
93
  switch (action.type) {
88
- case "vaultV2ForceRedeem":
89
- throw new error_js_1.TransactionPlanSignatureMismatchError(request.id, "reference");
90
- case "erc20Approval":
91
- throw new error_js_1.TransactionPlanSignatureMismatchError(request.id, "reference");
92
94
  case "vaultV2Deposit":
93
95
  spenderKey = "bundles.vaultBundlesV1";
94
96
  asset = action.inputs.asset;
95
- amountMatches = request.args.amount === action.inputs.assets;
97
+ amount = action.inputs.assets;
98
+ exact = true;
96
99
  break;
97
100
  case "vaultV1Deposit":
98
101
  spenderKey = "bundles.vaultBundlesV1";
99
102
  asset = action.inputs.asset;
100
- amountMatches = request.args.amount === action.inputs.assets;
103
+ amount = action.inputs.assets;
104
+ exact = true;
101
105
  break;
102
106
  case "vaultV1Withdraw":
103
107
  spenderKey = "bundles.vaultBundlesV1";
104
108
  asset = action.inputs.vault;
105
- amountMatches =
106
- request.args.amount >= action.inputs.requiredShareAllowance;
109
+ amount = action.inputs.requiredShareAllowance;
107
110
  break;
108
111
  case "vaultV2Withdraw":
109
112
  spenderKey = "bundles.vaultBundlesV1";
110
113
  asset = action.inputs.vault;
111
- amountMatches =
112
- request.args.amount >= action.inputs.requiredShareAllowance;
114
+ amount = action.inputs.requiredShareAllowance;
113
115
  break;
114
116
  case "vaultV2Redeem":
115
117
  spenderKey = "bundles.vaultBundlesV1";
116
118
  asset = action.inputs.vault;
117
- amountMatches = request.args.amount >= action.inputs.shares;
119
+ amount = action.inputs.shares;
118
120
  break;
119
121
  case "vaultV1Redeem":
120
122
  spenderKey = "bundles.vaultBundlesV1";
121
123
  asset = action.inputs.vault;
122
- amountMatches = request.args.amount >= action.inputs.shares;
124
+ amount = action.inputs.shares;
123
125
  break;
124
126
  case "vaultV2ForceWithdraw":
125
127
  spenderKey = "bundles.vaultExitBundlesV1";
126
128
  asset = action.inputs.vault;
127
- amountMatches = request.args.amount === viem_1.maxUint256;
129
+ amount = viem_1.maxUint256;
130
+ exact = true;
128
131
  break;
129
132
  case "vaultV1MigrateToV2":
130
133
  spenderKey = "bundles.vaultBundlesV1";
131
134
  asset = action.inputs.sourceVault;
132
- amountMatches =
133
- request.args.amount >= action.inputs.requiredShareAllowance;
135
+ amount = action.inputs.requiredShareAllowance;
134
136
  break;
135
137
  case "vaultV2InKindRedeem":
136
138
  spenderKey = "bundles.vaultExitBundlesV1";
137
139
  asset = action.inputs.vault;
138
- amountMatches = request.args.amount === viem_1.maxUint256;
140
+ amount = viem_1.maxUint256;
141
+ exact = true;
139
142
  break;
140
143
  case "vaultV1InKindRedeem":
141
144
  spenderKey = "bundles.vaultExitBundlesV1";
142
145
  asset = action.inputs.vault;
143
- amountMatches = request.args.amount === viem_1.maxUint256;
146
+ amount = viem_1.maxUint256;
147
+ exact = true;
144
148
  break;
145
- default: {
146
- const _exhaustive = action;
149
+ default:
147
150
  throw new error_js_1.TransactionPlanSignatureMismatchError(request.id, "reference");
148
- }
149
151
  }
150
152
  if (action.signatureRequestIds.tokenPermit !== request.id) {
151
153
  throw new error_js_1.TransactionPlanSignatureMismatchError(request.id, "reference");
152
154
  }
153
- const spender = (0, morpho_ts_1.getChainAddress)(chainId, spenderKey);
155
+ validateTokenPermitRequest(request, {
156
+ chainId: action.inputs.chainId,
157
+ account: action.inputs.account,
158
+ deadline: action.inputs.deadline,
159
+ bundler: spenderKey,
160
+ asset,
161
+ amount,
162
+ exact,
163
+ });
164
+ }
165
+ /** @internal Binds the signing payload and encoding arguments to a registered bundle's token pull. */
166
+ function validateTokenPermitRequest(request, pull) {
167
+ const { chainId, account, asset, amount, exact } = pull;
168
+ const { domain, message, types, primaryType } = request.typedData;
169
+ const spender = (0, morpho_ts_1.getChainAddress)(chainId, pull.bundler);
154
170
  const checks = [
155
171
  ["domain.chainId", domain?.chainId === chainId],
156
172
  [
157
173
  "domain.verifyingContract",
158
- typeof domain?.verifyingContract === "string" &&
159
- domain.verifyingContract.toLowerCase() === asset.toLowerCase(),
160
- ],
161
- [
162
- "message.owner",
163
- typeof message?.owner === "string" &&
164
- message.owner.toLowerCase() === account.toLowerCase(),
165
- ],
166
- [
167
- "message.spender",
168
- typeof message?.spender === "string" &&
169
- message.spender.toLowerCase() === spender.toLowerCase(),
174
+ (0, validation_js_1.matchesAddress)(domain?.verifyingContract, asset),
170
175
  ],
176
+ ["message.owner", (0, validation_js_1.matchesAddress)(message?.owner, account)],
177
+ ["message.spender", (0, validation_js_1.matchesAddress)(message?.spender, spender)],
178
+ ["args.spender", (0, validation_js_1.matchesAddress)(request.args.spender, spender)],
179
+ ["message.value", message?.value === request.args.amount],
171
180
  [
172
- "args.spender",
173
- typeof request.args.spender === "string" &&
174
- request.args.spender.toLowerCase() === spender.toLowerCase(),
181
+ "value",
182
+ exact
183
+ ? request.args.amount === amount
184
+ : amount !== undefined && request.args.amount >= amount,
175
185
  ],
176
- ["message.value", message?.value === request.args.amount],
177
- ["value", amountMatches],
178
186
  ["message.nonce", message?.nonce === request.args.nonce],
179
187
  ["message.deadline", message?.deadline === request.args.deadline],
180
188
  ["primaryType", primaryType === "Permit"],
189
+ [
190
+ "args.deadline",
191
+ pull.deadline === undefined || request.args.deadline === pull.deadline,
192
+ ],
181
193
  ];
182
194
  const mismatch = checks.find(([, matches]) => !matches);
183
195
  if (mismatch) {
184
196
  throw new error_js_1.TransactionPlanSignatureMismatchError(request.id, mismatch[0]);
185
197
  }
198
+ const expected = (0, blue_sdk_viem_1.getPermitTypedData)({
199
+ erc20: new blue_sdk_1.Token({ address: asset, name: domain?.name ?? "" }),
200
+ owner: account,
201
+ spender,
202
+ allowance: request.args.amount,
203
+ nonce: request.args.nonce,
204
+ deadline: request.args.deadline,
205
+ }, chainId).types.Permit;
206
+ const fields = types?.Permit;
207
+ if (!Array.isArray(fields) ||
208
+ Object.keys(types).length !== 1 ||
209
+ fields.length !== expected.length ||
210
+ !expected.every(({ name, type }, index) => fields[index]?.name === name &&
211
+ fields[index]?.type === type &&
212
+ Object.keys(fields[index]).length === 2)) {
213
+ throw new error_js_1.TransactionPlanSignatureMismatchError(request.id, "types");
214
+ }
186
215
  }
187
216
  /** @internal Rebuilds a token permit from the action's account/asset and its resolved signature requests. */
188
- function getVaultPermit(requests, { id, asset, owner, }) {
217
+ function getSignedTokenPermit(requests, { id, asset, owner, }) {
189
218
  if (id === undefined) {
190
219
  return undefined;
191
220
  }
@@ -193,6 +222,9 @@ function getVaultPermit(requests, { id, asset, owner, }) {
193
222
  if (request?.signature === undefined) {
194
223
  throw new error_js_1.IncompleteTransactionPlanError(id);
195
224
  }
225
+ if (request.kind !== "permit") {
226
+ throw new error_js_1.TransactionPlanSignatureMismatchError(id, "reference");
227
+ }
196
228
  return {
197
229
  action: {
198
230
  type: request.kind,
@@ -5,11 +5,13 @@ import type { SignatureRequest, Step, TransactionPlan } from "./types.js";
5
5
  * @experimental TransactionPlan is in beta; breaking changes may ship in minor releases.
6
6
  * Validates every request against its actions, verifies supplied ECDSA signatures synchronously,
7
7
  * and attaches serialized signatures by request ID. No client or RPC is used; the EIP-712 domain
8
- * binds the signature to its chain. Only low-s compact or serialized ECDSA permits are supported.
8
+ * binds the signature to its chain. Only low-s compact or serialized ECDSA signatures are supported.
9
9
  * Contract wallets should use `supportSignature: false` for direct approvals: deployed bundles
10
10
  * consume ECDSA `v/r/s`, not arbitrary ERC-1271 or ERC-6492 signatures.
11
11
  * Stored inputs remain trusted; verification does not establish the integrator's intent or protect
12
- * a plan changed afterwards. Builders do not reverify signatures in restored plans.
12
+ * unsigned fields from tampering. Stored signatures are reverified offline at parse, inspection and build.
13
+ * Permits bind owner, token, spender, value, nonce, deadline and chain; Morpho authorizations bind
14
+ * owner, authorized address, nonce, deadline and chain, not operation amounts, markets or referral fees/recipients.
13
15
  * @param plan - Plan to update without mutating its requests or steps.
14
16
  * @param signatures - Compact or serialized ECDSA signatures, each naming a unique existing request ID.
15
17
  * @returns A new plan sharing steps and unpatched requests; omitted IDs are preserved. Empty input validates all requests and returns the original plan.
@@ -17,7 +19,8 @@ import type { SignatureRequest, Step, TransactionPlan } from "./types.js";
17
19
  * @throws {UnsupportedTransactionPlanActionError} If any plan step names an unsupported action type, before reading requests or updates.
18
20
  * @throws {TransactionPlanSignatureMismatchError} If a request disagrees with its actions, an ID is unknown, or an input ID is duplicated (`field: "duplicate"`).
19
21
  * @throws {BundlesPermitMismatchError} If a supplied signature cannot be parsed by the bundle permit builders.
20
- * @throws {InvalidSignatureError} If a signature has high s, cannot recover a public key, or does not match the permit owner and typed data.
22
+ * @throws {InvalidTransactionPlanError} If the plan header, action context, IDs or deadlines are inconsistent.
23
+ * @throws {InvalidSignatureError} If a signature has high s, cannot recover a public key, or does not match the request owner and typed data.
21
24
  * @example
22
25
  * ```ts
23
26
  * import { applySignatures, type TransactionPlan } from "@morpho-org/morpho-sdk";
@@ -30,16 +33,22 @@ export declare function applySignatures(plan: TransactionPlan, signatures: reado
30
33
  readonly id: string;
31
34
  readonly signature: Hex;
32
35
  }[]): TransactionPlan;
36
+ /** @internal Verifies and normalizes a signature offline after the request has been validated against its action. */
37
+ export declare function verifyPlanSignature(request: SignatureRequest, signature: Hex): Hex;
33
38
  /**
34
39
  * @experimental TransactionPlan is in beta; breaking changes may ship in minor releases.
35
- * Lists pending signature requests once per request ID after checking each against every referencing action.
40
+ * Lists pending signature requests once per request ID and validates them against their referencing actions.
41
+ * Signed requests are also checked and their signers recovered offline.
36
42
  * Sign each request's typed data with your wallet stack, then verify and attach the results with
37
43
  * {@link applySignatures}.
38
44
  * @param plan - Plan to inspect without changing it.
39
45
  * @returns Pending requests in first-reference order, each carrying its `id`, `kind` and validated `typedData`. Dangling IDs are omitted. The SDK never signs.
46
+ * @throws {InvalidTransactionPlanError} If the plan header, action context, IDs or deadlines are inconsistent.
47
+ * @throws {InvalidSignatureError} If a stored signature has high s, cannot recover a public key or does not match the request owner.
48
+ * @throws {BundlesPermitMismatchError} If a stored signature cannot be parsed as a compact or serialized ECDSA signature.
40
49
  * @throws {UnsupportedTransactionPlanVersionError} If the plan version is unsupported, including empty plans.
41
50
  * @throws {UnsupportedTransactionPlanActionError} If any plan step names an unsupported action type, before reading requests.
42
- * @throws {TransactionPlanSignatureMismatchError} If a pending permit disagrees with its action or arguments, including the action deadline, or any request has no referencing step.
51
+ * @throws {TransactionPlanSignatureMismatchError} If a pending request or Morpho authorization disagrees with its action or arguments, or any request has no referencing step.
43
52
  * @example
44
53
  * ```ts
45
54
  * import { getPendingSignatureRequests, type TransactionPlan } from "@morpho-org/morpho-sdk";
@@ -54,23 +63,47 @@ export declare function getPendingSignatureRequests(plan: TransactionPlan): read
54
63
  * Plans are trusted as given, whether restored or supplied directly. Signature checks establish
55
64
  * only request/action consistency; they do not validate stored fees, recipients, share-price bounds,
56
65
  * vaults or amounts against the intended operation. Integrators must protect stored plans from tampering.
57
- * This builder does not verify signature ownership; use {@link applySignatures} to verify and attach signatures.
66
+ * Stored signatures are verified offline. Permits bind owner, token, spender, value, nonce, deadline
67
+ * and chain; Morpho authorizations bind owner, authorized address, nonce, deadline and chain,
68
+ * not operation amounts, market parameters or referral fees/recipients. Protect those unsigned fields.
58
69
  * @param plan - Plan supplying referenced signature requests and the calldata origin; chain and account come from the action inputs.
59
70
  * @param step - Recipe to encode; missing signatures on unrelated supported steps do not block it.
60
71
  * @returns A frozen `{ to, data, value, action }`, ready to simulate or submit. `data` ends with the plan's `calldataOrigin` when one was set.
72
+ * @throws {InvalidTransactionPlanError} If the plan header, action context, IDs or deadlines are inconsistent.
73
+ * @throws {InvalidSignatureError} If a stored signature has high s, cannot recover a public key or does not match the request owner.
61
74
  * @throws {UnsupportedTransactionPlanVersionError} If the plan version is unsupported.
62
75
  * @throws {UnsupportedTransactionPlanActionError} If any plan step or the selected step names an unsupported action type.
63
76
  * @throws {UnsupportedErc20ApprovalSpenderError} If an approval names an unregistered spender.
64
77
  * @throws {SameVaultMigrationError} If a migration's source and destination vaults are identical.
65
78
  * @throws {AmountAndSharesExclusiveError} If a migration supplies both `assets` and `shares`, or neither.
66
- * @throws {NonPositiveInputError} If a deposit, withdrawal or migration amount, a deposit or migration destination share-price bound, a deadline, force-redeem shares or deallocation amount is not positive.
79
+ * @throws {NonPositiveInputError} If a deposit, withdrawal or migration amount, a deposit or migration destination share-price bound, a Blue collateral amount, a deadline, force-redeem shares or deallocation amount is not positive.
80
+ * @throws {MarketIdMismatchError} If a Blue collateral step's market ID doesn't match its market parameters.
81
+ * @throws {NativeAmountOnNonWNativeAssetError} If a native-funded Blue collateral step targets a token other than wNative.
82
+ * @throws {ChainWNativeMissingError} If a native-funded Blue collateral step targets a chain without registered wNative.
67
83
  * @throws {EmptyDeallocationsError} If a force-redeem step has no deallocations.
68
84
  * @throws {EmptyMarketParamsListError} If a Vault V1 in-kind redemption step has no markets.
69
85
  * @throws {ReferralFeePctExceededError} If the action's referral fee is at least WAD.
70
86
  * @throws {ReferralFeeRecipientMissingError} If a positive referral fee has no nonzero recipient.
71
87
  * @throws {IncompleteTransactionPlanError} If a referenced signature request or its signature is missing.
72
- * @throws {TransactionPlanSignatureMismatchError} If a referenced permit disagrees with the step's action or its encoding arguments.
73
- * @throws {BundlesPermitMismatchError} If a signed permit's spender, amount or deadline doesn't match the step.
88
+ * @throws {TransactionPlanSignatureMismatchError} If a referenced request disagrees with the step's action or its encoding arguments.
89
+ * @throws {BundlesPermitMismatchError} If a stored signature cannot be parsed or a signed permit's encoding arguments do not match the step.
90
+ * @throws {MarketIdMismatchError} If a Blue market ID differs from its parameter tuple.
91
+ * @throws {NegativeInputError} If a Blue amount, native value, LTV bound or referral fee is negative.
92
+ * @throws {InputExceedsMaxError} If a Blue amount, bound or deadline exceeds uint256, or withdrawal-only funding is nonzero.
93
+ * @throws {MutuallyExclusiveRepayAmountsError} If a Blue repayment specifies both nonzero assets and shares.
94
+ * @throws {MaxRepayAssetsBelowRepayAssetsError} If exact-asset funding cannot cover repayment plus referral fees.
95
+ * @throws {NativeFundingAmountMismatchError} If Blue native funding does not equal the full repayment cap.
96
+ * @throws {ChainWNativeMissingError} If native funding targets a chain without wNative.
97
+ * @throws {NativeAmountOnNonWNativeAssetError} If native funding targets a loan token other than wNative.
98
+ * @throws {UnexpectedRequirementSignatureError} If a Blue signature targets an inactive leg or native-funded token pull.
99
+ * @throws {DepositOwnerMismatchError} If a Blue signature belongs to another account.
100
+ * @throws {DepositAssetMismatchError} If a token signature names another loan token.
101
+ * @throws {DepositAmountMismatchError} If a token signature does not cover the repayment cap.
102
+ * @throws {DepositSpenderMismatchError} If a token signature names another spender.
103
+ * @throws {UnsupportedRequirementSignatureError} If a token signature has an unsupported action type.
104
+ * @throws {BundlesRequirementSignatureMismatchError} If a Blue signature cannot be bound or parsed safely.
105
+ * @throws {UnsupportedChainIdError} If a Blue action's chain is absent from the registry.
106
+ * @throws {UnknownAddressError} If BlueBundlesV1 is not registered on the action's chain.
74
107
  * @example
75
108
  * ```ts
76
109
  * import { buildTransaction, parseTransactionPlan } from "@morpho-org/morpho-sdk";
@@ -86,19 +119,41 @@ export declare function buildTransaction(plan: TransactionPlan, step: Step): Rea
86
119
  * Builds every step of the plan in order.
87
120
  * @param plan - Plan whose referenced signature requests all carry a signature.
88
121
  * @returns Frozen SDK transactions in step order; discriminate on `action.type` for per-step handling.
122
+ * @throws {InvalidTransactionPlanError} If the plan header, action context, IDs or deadlines are inconsistent.
123
+ * @throws {InvalidSignatureError} If a stored signature has high s, cannot recover a public key or does not match the request owner.
89
124
  * @throws {UnsupportedTransactionPlanVersionError} If the plan version is unsupported, including empty plans.
90
125
  * @throws {UnsupportedTransactionPlanActionError} If any plan step names an unsupported action type, before reading requests.
91
126
  * @throws {UnsupportedErc20ApprovalSpenderError} If an approval names an unregistered spender.
92
127
  * @throws {SameVaultMigrationError} If a migration's source and destination vaults are identical.
93
128
  * @throws {AmountAndSharesExclusiveError} If a migration supplies both `assets` and `shares`, or neither.
94
- * @throws {NonPositiveInputError} If a deposit, withdrawal or migration amount, a deposit or migration destination share-price bound, a deadline, force-redeem shares or deallocation amount is not positive.
129
+ * @throws {NonPositiveInputError} If a deposit, withdrawal or migration amount, a deposit or migration destination share-price bound, a Blue collateral amount, a deadline, force-redeem shares or deallocation amount is not positive.
130
+ * @throws {MarketIdMismatchError} If a Blue collateral step's market ID doesn't match its market parameters.
131
+ * @throws {NativeAmountOnNonWNativeAssetError} If a native-funded Blue collateral step targets a token other than wNative.
132
+ * @throws {ChainWNativeMissingError} If a native-funded Blue collateral step targets a chain without registered wNative.
95
133
  * @throws {EmptyDeallocationsError} If a force-redeem step has no deallocations.
96
134
  * @throws {EmptyMarketParamsListError} If a Vault V1 in-kind redemption step has no markets.
97
135
  * @throws {ReferralFeePctExceededError} If an action's referral fee is at least WAD.
98
136
  * @throws {ReferralFeeRecipientMissingError} If a positive referral fee has no nonzero recipient.
99
137
  * @throws {IncompleteTransactionPlanError} If any step references a signature request or signature that is missing.
100
- * @throws {TransactionPlanSignatureMismatchError} If a referenced permit disagrees with its action or encoding arguments.
101
- * @throws {BundlesPermitMismatchError} If a signed permit's spender, amount or deadline doesn't match the step.
138
+ * @throws {TransactionPlanSignatureMismatchError} If a referenced request disagrees with its action or encoding arguments.
139
+ * @throws {BundlesPermitMismatchError} If a stored signature cannot be parsed or a signed permit's encoding arguments do not match the step.
140
+ * @throws {MarketIdMismatchError} If a Blue market ID differs from its parameter tuple.
141
+ * @throws {NegativeInputError} If a Blue amount, native value, LTV bound or referral fee is negative.
142
+ * @throws {InputExceedsMaxError} If a Blue amount, bound or deadline exceeds uint256, or withdrawal-only funding is nonzero.
143
+ * @throws {MutuallyExclusiveRepayAmountsError} If a Blue repayment specifies both nonzero assets and shares.
144
+ * @throws {MaxRepayAssetsBelowRepayAssetsError} If exact-asset funding cannot cover repayment plus referral fees.
145
+ * @throws {NativeFundingAmountMismatchError} If Blue native funding does not equal the full repayment cap.
146
+ * @throws {ChainWNativeMissingError} If native funding targets a chain without wNative.
147
+ * @throws {NativeAmountOnNonWNativeAssetError} If native funding targets a loan token other than wNative.
148
+ * @throws {UnexpectedRequirementSignatureError} If a Blue signature targets an inactive leg or native-funded token pull.
149
+ * @throws {DepositOwnerMismatchError} If a Blue signature belongs to another account.
150
+ * @throws {DepositAssetMismatchError} If a token signature names another loan token.
151
+ * @throws {DepositAmountMismatchError} If a token signature does not cover the repayment cap.
152
+ * @throws {DepositSpenderMismatchError} If a token signature names another spender.
153
+ * @throws {UnsupportedRequirementSignatureError} If a token signature has an unsupported action type.
154
+ * @throws {BundlesRequirementSignatureMismatchError} If a Blue signature cannot be bound or parsed safely.
155
+ * @throws {UnsupportedChainIdError} If a Blue action's chain is absent from the registry.
156
+ * @throws {UnknownAddressError} If BlueBundlesV1 is not registered on the action's chain.
102
157
  * @example
103
158
  * ```ts
104
159
  * import { buildTransactions, type TransactionPlan } from "@morpho-org/morpho-sdk";