@morpho-org/morpho-sdk 4.2.0 → 5.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (191) hide show
  1. package/README.md +16 -16
  2. package/lib/cjs/actions/blue/borrow.d.ts +12 -2
  3. package/lib/cjs/actions/blue/borrow.js +7 -1
  4. package/lib/cjs/actions/blue/buildAssetFundingActions.d.ts +47 -0
  5. package/lib/cjs/actions/blue/buildAssetFundingActions.js +63 -0
  6. package/lib/cjs/actions/blue/refinance.d.ts +13 -3
  7. package/lib/cjs/actions/blue/refinance.js +8 -2
  8. package/lib/cjs/actions/blue/repay.d.ts +44 -43
  9. package/lib/cjs/actions/blue/repay.js +70 -59
  10. package/lib/cjs/actions/blue/repayWithdrawCollateral.d.ts +50 -41
  11. package/lib/cjs/actions/blue/repayWithdrawCollateral.js +75 -54
  12. package/lib/cjs/actions/blue/resolveRepayFunding.d.ts +69 -0
  13. package/lib/cjs/actions/blue/resolveRepayFunding.js +82 -0
  14. package/lib/cjs/actions/blue/supply.d.ts +8 -8
  15. package/lib/cjs/actions/blue/supply.js +11 -35
  16. package/lib/cjs/actions/blue/supplyCollateral.d.ts +9 -9
  17. package/lib/cjs/actions/blue/supplyCollateral.js +12 -36
  18. package/lib/cjs/actions/blue/supplyCollateralBorrow.d.ts +19 -7
  19. package/lib/cjs/actions/blue/supplyCollateralBorrow.js +17 -32
  20. package/lib/cjs/actions/blue/withdraw.d.ts +10 -2
  21. package/lib/cjs/actions/blue/withdraw.js +7 -1
  22. package/lib/cjs/actions/index.d.ts +1 -0
  23. package/lib/cjs/actions/index.js +1 -0
  24. package/lib/cjs/actions/requirements/blue/getBlueAuthorizationRequirement.d.ts +49 -0
  25. package/lib/cjs/actions/requirements/blue/getBlueAuthorizationRequirement.js +111 -0
  26. package/lib/cjs/actions/requirements/blue/index.d.ts +1 -0
  27. package/lib/cjs/actions/requirements/blue/index.js +17 -0
  28. package/lib/cjs/actions/requirements/encode/encodeBlueSignatureAuthorization.d.ts +55 -0
  29. package/lib/cjs/actions/requirements/encode/encodeBlueSignatureAuthorization.js +89 -0
  30. package/lib/cjs/actions/requirements/encode/encodeErc20Approval.d.ts +6 -5
  31. package/lib/cjs/actions/requirements/encode/encodeErc20Approval.js +17 -5
  32. package/lib/cjs/actions/requirements/encode/encodeErc20Permit.d.ts +9 -7
  33. package/lib/cjs/actions/requirements/encode/encodeErc20Permit.js +18 -4
  34. package/lib/cjs/actions/requirements/encode/{encodeErc20Permit2.d.ts → encodeErc20Permit2Approve.d.ts} +11 -13
  35. package/lib/cjs/actions/requirements/encode/{encodeErc20Permit2.js → encodeErc20Permit2Approve.js} +10 -14
  36. package/lib/cjs/actions/requirements/encode/index.d.ts +2 -1
  37. package/lib/cjs/actions/requirements/encode/index.js +2 -1
  38. package/lib/cjs/actions/requirements/{getRequirements.d.ts → generalAdapter/getGeneralAdapterRequirements.d.ts} +34 -20
  39. package/lib/cjs/actions/requirements/generalAdapter/getGeneralAdapterRequirements.js +151 -0
  40. package/lib/{esm/actions/requirements/getRequirementsPermit.d.ts → cjs/actions/requirements/generalAdapter/getGeneralAdapterRequirementsPermit.d.ts} +6 -14
  41. package/lib/cjs/actions/requirements/generalAdapter/getGeneralAdapterRequirementsPermit.js +50 -0
  42. package/lib/cjs/actions/requirements/generalAdapter/getGeneralAdapterRequirementsPermit2.d.ts +57 -0
  43. package/lib/cjs/actions/requirements/generalAdapter/getGeneralAdapterRequirementsPermit2.js +74 -0
  44. package/lib/cjs/actions/requirements/generalAdapter/index.d.ts +3 -0
  45. package/lib/cjs/actions/requirements/generalAdapter/index.js +19 -0
  46. package/lib/cjs/actions/requirements/getRequirementsApproval.d.ts +3 -2
  47. package/lib/cjs/actions/requirements/getRequirementsApproval.js +3 -2
  48. package/lib/cjs/actions/requirements/index.d.ts +2 -5
  49. package/lib/cjs/actions/requirements/index.js +2 -5
  50. package/lib/cjs/actions/signatures/getBlueAuthorizationAction.d.ts +29 -0
  51. package/lib/cjs/actions/signatures/getBlueAuthorizationAction.js +48 -0
  52. package/lib/{esm/actions/requirements/getRequirementsAction.d.ts → cjs/actions/signatures/getTokenRequirementActions.d.ts} +17 -17
  53. package/lib/cjs/actions/{requirements/getRequirementsAction.js → signatures/getTokenRequirementActions.js} +26 -13
  54. package/lib/cjs/actions/signatures/index.d.ts +2 -0
  55. package/lib/cjs/actions/signatures/index.js +18 -0
  56. package/lib/cjs/actions/vaultV1/deposit.d.ts +6 -8
  57. package/lib/cjs/actions/vaultV1/deposit.js +11 -21
  58. package/lib/cjs/actions/vaultV1/migrateToV2.d.ts +6 -6
  59. package/lib/cjs/actions/vaultV1/migrateToV2.js +12 -20
  60. package/lib/cjs/actions/vaultV2/deposit.d.ts +6 -8
  61. package/lib/cjs/actions/vaultV2/deposit.js +11 -21
  62. package/lib/cjs/addresses.d.ts +2 -2
  63. package/lib/cjs/addresses.js +2 -1
  64. package/lib/cjs/bundler/actions.d.ts +44 -4
  65. package/lib/cjs/bundler/actions.js +75 -2
  66. package/lib/cjs/bundler/types.d.ts +6 -0
  67. package/lib/cjs/constants.d.ts +2 -2
  68. package/lib/cjs/constants.js +3 -3
  69. package/lib/cjs/entities/blue/blue.d.ts +58 -33
  70. package/lib/cjs/entities/blue/blue.js +309 -189
  71. package/lib/cjs/entities/reallocationData.d.ts +0 -44
  72. package/lib/cjs/entities/reallocationData.js +3 -50
  73. package/lib/cjs/entities/vaultV1/vaultV1.d.ts +9 -9
  74. package/lib/cjs/entities/vaultV1/vaultV1.js +44 -34
  75. package/lib/cjs/entities/vaultV2/vaultV2.d.ts +6 -6
  76. package/lib/cjs/entities/vaultV2/vaultV2.js +21 -16
  77. package/lib/cjs/errors.d.ts +3 -2
  78. package/lib/cjs/errors.js +5 -2
  79. package/lib/cjs/helpers/index.d.ts +1 -1
  80. package/lib/cjs/helpers/index.js +1 -2
  81. package/lib/cjs/helpers/validate.d.ts +2 -20
  82. package/lib/cjs/helpers/validate.js +2 -39
  83. package/lib/cjs/types/action.d.ts +164 -12
  84. package/lib/cjs/types/action.js +79 -5
  85. package/lib/cjs/types/error.d.ts +97 -2
  86. package/lib/cjs/types/error.js +113 -7
  87. package/lib/cjs/types.d.ts +2 -1
  88. package/lib/cjs/utils.d.ts +2 -2
  89. package/lib/cjs/utils.js +2 -4
  90. package/lib/esm/actions/blue/borrow.d.ts +12 -2
  91. package/lib/esm/actions/blue/borrow.js +7 -1
  92. package/lib/esm/actions/blue/buildAssetFundingActions.d.ts +47 -0
  93. package/lib/esm/actions/blue/buildAssetFundingActions.js +59 -0
  94. package/lib/esm/actions/blue/refinance.d.ts +13 -3
  95. package/lib/esm/actions/blue/refinance.js +8 -2
  96. package/lib/esm/actions/blue/repay.d.ts +44 -43
  97. package/lib/esm/actions/blue/repay.js +71 -60
  98. package/lib/esm/actions/blue/repayWithdrawCollateral.d.ts +50 -41
  99. package/lib/esm/actions/blue/repayWithdrawCollateral.js +76 -55
  100. package/lib/esm/actions/blue/resolveRepayFunding.d.ts +69 -0
  101. package/lib/esm/actions/blue/resolveRepayFunding.js +78 -0
  102. package/lib/esm/actions/blue/supply.d.ts +8 -8
  103. package/lib/esm/actions/blue/supply.js +12 -36
  104. package/lib/esm/actions/blue/supplyCollateral.d.ts +9 -9
  105. package/lib/esm/actions/blue/supplyCollateral.js +13 -37
  106. package/lib/esm/actions/blue/supplyCollateralBorrow.d.ts +19 -7
  107. package/lib/esm/actions/blue/supplyCollateralBorrow.js +18 -33
  108. package/lib/esm/actions/blue/withdraw.d.ts +10 -2
  109. package/lib/esm/actions/blue/withdraw.js +7 -1
  110. package/lib/esm/actions/index.d.ts +1 -0
  111. package/lib/esm/actions/index.js +1 -0
  112. package/lib/esm/actions/requirements/blue/getBlueAuthorizationRequirement.d.ts +49 -0
  113. package/lib/esm/actions/requirements/blue/getBlueAuthorizationRequirement.js +107 -0
  114. package/lib/esm/actions/requirements/blue/index.d.ts +1 -0
  115. package/lib/esm/actions/requirements/blue/index.js +1 -0
  116. package/lib/esm/actions/requirements/encode/encodeBlueSignatureAuthorization.d.ts +55 -0
  117. package/lib/esm/actions/requirements/encode/encodeBlueSignatureAuthorization.js +85 -0
  118. package/lib/esm/actions/requirements/encode/encodeErc20Approval.d.ts +6 -5
  119. package/lib/esm/actions/requirements/encode/encodeErc20Approval.js +19 -7
  120. package/lib/esm/actions/requirements/encode/encodeErc20Permit.d.ts +9 -7
  121. package/lib/esm/actions/requirements/encode/encodeErc20Permit.js +20 -6
  122. package/lib/esm/actions/requirements/encode/{encodeErc20Permit2.d.ts → encodeErc20Permit2Approve.d.ts} +11 -13
  123. package/lib/esm/actions/requirements/encode/{encodeErc20Permit2.js → encodeErc20Permit2Approve.js} +8 -12
  124. package/lib/esm/actions/requirements/encode/index.d.ts +2 -1
  125. package/lib/esm/actions/requirements/encode/index.js +2 -1
  126. package/lib/esm/actions/requirements/{getRequirements.d.ts → generalAdapter/getGeneralAdapterRequirements.d.ts} +34 -20
  127. package/lib/esm/actions/requirements/generalAdapter/getGeneralAdapterRequirements.js +147 -0
  128. package/lib/{cjs/actions/requirements/getRequirementsPermit.d.ts → esm/actions/requirements/generalAdapter/getGeneralAdapterRequirementsPermit.d.ts} +6 -14
  129. package/lib/esm/actions/requirements/generalAdapter/getGeneralAdapterRequirementsPermit.js +46 -0
  130. package/lib/esm/actions/requirements/generalAdapter/getGeneralAdapterRequirementsPermit2.d.ts +57 -0
  131. package/lib/esm/actions/requirements/generalAdapter/getGeneralAdapterRequirementsPermit2.js +70 -0
  132. package/lib/esm/actions/requirements/generalAdapter/index.d.ts +3 -0
  133. package/lib/esm/actions/requirements/generalAdapter/index.js +3 -0
  134. package/lib/esm/actions/requirements/getRequirementsApproval.d.ts +3 -2
  135. package/lib/esm/actions/requirements/getRequirementsApproval.js +3 -2
  136. package/lib/esm/actions/requirements/index.d.ts +2 -5
  137. package/lib/esm/actions/requirements/index.js +2 -5
  138. package/lib/esm/actions/signatures/getBlueAuthorizationAction.d.ts +29 -0
  139. package/lib/esm/actions/signatures/getBlueAuthorizationAction.js +44 -0
  140. package/lib/{cjs/actions/requirements/getRequirementsAction.d.ts → esm/actions/signatures/getTokenRequirementActions.d.ts} +17 -17
  141. package/lib/esm/actions/{requirements/getRequirementsAction.js → signatures/getTokenRequirementActions.js} +24 -11
  142. package/lib/esm/actions/signatures/index.d.ts +2 -0
  143. package/lib/esm/actions/signatures/index.js +2 -0
  144. package/lib/esm/actions/vaultV1/deposit.d.ts +6 -8
  145. package/lib/esm/actions/vaultV1/deposit.js +11 -21
  146. package/lib/esm/actions/vaultV1/migrateToV2.d.ts +6 -6
  147. package/lib/esm/actions/vaultV1/migrateToV2.js +12 -20
  148. package/lib/esm/actions/vaultV2/deposit.d.ts +6 -8
  149. package/lib/esm/actions/vaultV2/deposit.js +11 -21
  150. package/lib/esm/addresses.d.ts +2 -2
  151. package/lib/esm/addresses.js +1 -1
  152. package/lib/esm/bundler/actions.d.ts +44 -4
  153. package/lib/esm/bundler/actions.js +77 -4
  154. package/lib/esm/bundler/types.d.ts +6 -0
  155. package/lib/esm/constants.d.ts +2 -2
  156. package/lib/esm/constants.js +2 -2
  157. package/lib/esm/entities/blue/blue.d.ts +58 -33
  158. package/lib/esm/entities/blue/blue.js +311 -191
  159. package/lib/esm/entities/reallocationData.d.ts +0 -44
  160. package/lib/esm/entities/reallocationData.js +2 -49
  161. package/lib/esm/entities/vaultV1/vaultV1.d.ts +9 -9
  162. package/lib/esm/entities/vaultV1/vaultV1.js +46 -36
  163. package/lib/esm/entities/vaultV2/vaultV2.d.ts +6 -6
  164. package/lib/esm/entities/vaultV2/vaultV2.js +23 -18
  165. package/lib/esm/errors.d.ts +3 -2
  166. package/lib/esm/errors.js +2 -1
  167. package/lib/esm/helpers/index.d.ts +1 -1
  168. package/lib/esm/helpers/index.js +1 -1
  169. package/lib/esm/helpers/validate.d.ts +2 -20
  170. package/lib/esm/helpers/validate.js +2 -38
  171. package/lib/esm/types/action.d.ts +164 -12
  172. package/lib/esm/types/action.js +75 -4
  173. package/lib/esm/types/error.d.ts +97 -2
  174. package/lib/esm/types/error.js +107 -5
  175. package/lib/esm/types.d.ts +2 -1
  176. package/lib/esm/utils.d.ts +2 -2
  177. package/lib/esm/utils.js +2 -2
  178. package/package.json +22 -21
  179. package/lib/cjs/actions/requirements/getMorphoAuthorizationRequirement.d.ts +0 -37
  180. package/lib/cjs/actions/requirements/getMorphoAuthorizationRequirement.js +0 -71
  181. package/lib/cjs/actions/requirements/getRequirements.js +0 -112
  182. package/lib/cjs/actions/requirements/getRequirementsPermit.js +0 -57
  183. package/lib/cjs/actions/requirements/getRequirementsPermit2.d.ts +0 -63
  184. package/lib/cjs/actions/requirements/getRequirementsPermit2.js +0 -85
  185. package/lib/esm/actions/requirements/getMorphoAuthorizationRequirement.d.ts +0 -37
  186. package/lib/esm/actions/requirements/getMorphoAuthorizationRequirement.js +0 -67
  187. package/lib/esm/actions/requirements/getRequirements.js +0 -108
  188. package/lib/esm/actions/requirements/getRequirementsPermit.js +0 -53
  189. package/lib/esm/actions/requirements/getRequirementsPermit2.d.ts +0 -63
  190. package/lib/esm/actions/requirements/getRequirementsPermit2.js +0 -81
  191. package/src/index.ts +0 -4
package/README.md CHANGED
@@ -45,13 +45,13 @@ pnpm add @morpho-org/morpho-sdk
45
45
 
46
46
  Every action that touches a user's tokens or positions returns two things:
47
47
 
48
- - `buildTx(signature?)` — builds the final viem `Transaction` object.
48
+ - `buildTx(signatures?)` — builds the final viem `Transaction` object. Takes an optional array of collected `RequirementSignature`s (permit / Permit2 and/or Morpho authorization).
49
49
  - `getRequirements()` — returns the list of on-chain pre-requisites that must be satisfied first.
50
50
 
51
51
  Typical requirements:
52
52
 
53
53
  - **ERC-20 approval** — the user must approve the bundler (or Morpho directly) to pull tokens. Returned as a standard `approve` transaction the consumer sends first.
54
- - **Permit / Permit2 signature** — off-chain approvals that go into `buildTx` as a `signature` argument, avoiding the extra approval tx. Enabled via `morphoViemExtension({ supportSignature: true })`.
54
+ - **Permit / Permit2 signature** — off-chain approvals that go into `buildTx` in the `signatures` array, avoiding the extra approval tx. Enabled via `morphoViemExtension({ supportSignature: true })`.
55
55
  - **Morpho authorization** — `borrow`, `supplyCollateralBorrow`, and `repayWithdrawCollateral` require the user to authorize `GeneralAdapter1` on the Morpho contract once (`setAuthorization`). The SDK returns this as an extra transaction if it's missing.
56
56
 
57
57
  Usage pattern:
@@ -66,12 +66,12 @@ const requirements = await getRequirements();
66
66
 
67
67
  // Consumer satisfies each requirement (send tx / sign permit), collects the signature,
68
68
  // then calls buildTx to get the final transaction:
69
- const tx = buildTx(permitSignature);
69
+ const tx = buildTx([permitSignature]);
70
70
  ```
71
71
 
72
72
  ### Integration invariant — builder = signer
73
73
 
74
- **`userAddress` MUST equal the account that ends up signing/executing the tx.** Critical for `repayWithdrawCollateral`, whose bundle mixes explicit `onBehalf` (repay) with implicit `msg.sender` (transfer-from + withdraw) — see [BUNDLER3.md](./BUNDLER3.md#other-pitfalls). Transaction builders do not validate this at build time, so callers MUST keep `userAddress` aligned with the signing account themselves. The signature requirements (`encodeErc20Permit` / `encodeErc20Permit2`) take a `WalletClient` and enforce the invariant at `sign()` time via `validateUserAddress`, rejecting any `sign(client, userAddress)` where `client.account.address !== userAddress` with `MissingClientPropertyError` / `AddressMismatchError`.
74
+ **`userAddress` MUST equal the account that ends up signing/executing the tx.** Critical for `repayWithdrawCollateral`, whose bundle mixes explicit `onBehalf` (repay) with implicit `msg.sender` (transfer-from + withdraw) — see [BUNDLER3.md](./BUNDLER3.md#other-pitfalls). Transaction builders do not validate this at build time, so callers MUST keep `userAddress` aligned with the signing account themselves. The signature requirements (`encodeErc20Permit` / `encodeErc20Permit2Approve`) take a `WalletClient` and enforce the invariant at `sign()` time via `validateUserAddress`, rejecting any `sign(client, userAddress)` where `client.account.address !== userAddress` with `MissingClientPropertyError` / `AddressMismatchError`.
75
75
 
76
76
  | Entity | Action | Route | Why |
77
77
  | ------------ | ------------------------ | ------------------------- | --------------------------------------------------------------------------------------------------- |
@@ -114,7 +114,7 @@ const { buildTx, getRequirements } = await vault.deposit({
114
114
  });
115
115
 
116
116
  const requirements = await getRequirements();
117
- const tx = buildTx(requirementSignature);
117
+ const tx = buildTx([requirementSignature]);
118
118
  ```
119
119
 
120
120
  ##### Deposit with native token wrapping
@@ -199,7 +199,7 @@ const { buildTx, getRequirements } = await vault.deposit({
199
199
  });
200
200
 
201
201
  const requirements = await getRequirements();
202
- const tx = buildTx(requirementSignature);
202
+ const tx = buildTx([requirementSignature]);
203
203
  ```
204
204
 
205
205
  #### Withdraw
@@ -240,7 +240,7 @@ const { buildTx, getRequirements } = sourceVault.migrateToV2({
240
240
  });
241
241
 
242
242
  const requirements = await getRequirements();
243
- const tx = buildTx(requirementSignature);
243
+ const tx = buildTx([requirementSignature]);
244
244
  ```
245
245
 
246
246
  ### Blue
@@ -275,7 +275,7 @@ const { buildTx, getRequirements } = market.supply({
275
275
  });
276
276
 
277
277
  const requirements = await getRequirements();
278
- const tx = buildTx(requirementSignature);
278
+ const tx = buildTx([requirementSignature]);
279
279
  ```
280
280
 
281
281
  ##### Supply with native token wrapping
@@ -301,7 +301,7 @@ const { buildTx, getRequirements } = market.supplyCollateral({
301
301
  });
302
302
 
303
303
  const requirements = await getRequirements();
304
- const tx = buildTx(requirementSignature);
304
+ const tx = buildTx([requirementSignature]);
305
305
  ```
306
306
 
307
307
  #### Borrow
@@ -332,19 +332,19 @@ const { buildTx, getRequirements } = market.supplyCollateralBorrow({
332
332
  });
333
333
 
334
334
  const requirements = await getRequirements();
335
- const tx = buildTx(requirementSignature);
335
+ const tx = buildTx([requirementSignature]);
336
336
  ```
337
337
 
338
338
  #### Repay
339
339
 
340
- Two modes depending on whether the caller specifies `assets` (partial repay) or `shares` (full repay, immune to interest accrual between quote and inclusion):
340
+ Two modes depending on whether the caller specifies `amount` (partial repay) or `shares` (full repay, immune to interest accrual between quote and inclusion). Optionally attach `nativeAmount` to fund the repay by wrapping native ETH (loan token must be the chain's wNative):
341
341
 
342
342
  ```typescript
343
343
  const positionData = await market.getPositionData("0xUser...");
344
344
 
345
- // Partial repay — by assets
345
+ // Partial repay — by amount
346
346
  const { buildTx, getRequirements } = market.repay({
347
- assets: 250000000000000000n,
347
+ amount: 250000000000000000n,
348
348
  userAddress: "0xUser...",
349
349
  positionData,
350
350
  });
@@ -357,7 +357,7 @@ const { buildTx, getRequirements } = market.repay({
357
357
  });
358
358
 
359
359
  const requirements = await getRequirements();
360
- const tx = buildTx(requirementSignature);
360
+ const tx = buildTx([requirementSignature]);
361
361
  ```
362
362
 
363
363
  Repay does **not** require Morpho authorization (it only requires a loan token approval for `GeneralAdapter1`).
@@ -411,14 +411,14 @@ Direct call to `morpho.withdrawCollateral()` — no bundler, no `GeneralAdapter1
411
411
  const positionData = await market.getPositionData("0xUser...");
412
412
 
413
413
  const { buildTx, getRequirements } = market.repayWithdrawCollateral({
414
- assets: 250000000000000000n, // or shares: ...
414
+ amount: 250000000000000000n, // or shares: ...
415
415
  withdrawAmount: 500000000000000000n,
416
416
  userAddress: "0xUser...",
417
417
  positionData,
418
418
  });
419
419
 
420
420
  const requirements = await getRequirements();
421
- const tx = buildTx(requirementSignature);
421
+ const tx = buildTx([requirementSignature]);
422
422
  ```
423
423
 
424
424
  Atomically bundles repay → withdraw collateral via bundler3. Bundle order is critical: repay runs first to reduce debt, then withdraw. Requires both a loan token approval (for repay) and a Morpho authorization (for withdraw). The SDK validates combined position health by simulating the repay before checking withdrawal safety.
@@ -1,6 +1,6 @@
1
1
  import type { MarketParams } from "@morpho-org/blue-sdk";
2
2
  import type { Address } from "viem";
3
- import { type BlueBorrowAction, type Metadata, type Transaction, type VaultReallocation } from "../../types/index.js";
3
+ import { type AuthorizationRequirementSignature, type BlueBorrowAction, type Metadata, type Transaction, type VaultReallocation } from "../../types/index.js";
4
4
  /** Parameters for {@link blueBorrow}. */
5
5
  export interface BlueBorrowParams {
6
6
  market: {
@@ -8,12 +8,20 @@ export interface BlueBorrowParams {
8
8
  readonly marketParams: MarketParams;
9
9
  };
10
10
  args: {
11
+ /** Amount of loan asset to borrow. */
11
12
  amount: bigint;
13
+ /** Address that receives the borrowed assets. */
12
14
  receiver: Address;
13
15
  /** Minimum borrow share price (in ray). Protects against share price manipulation. */
14
16
  minSharePrice: bigint;
15
17
  /** Vault reallocations to execute before borrowing (computed by entity). */
16
18
  reallocations?: readonly VaultReallocation[];
19
+ /**
20
+ * Optional signed Morpho authorization. When provided, a `setAuthorizationWithSig` call is
21
+ * prepended to the bundle so GeneralAdapter1 is authorized in-bundle instead of via a
22
+ * standalone `setAuthorization` transaction.
23
+ */
24
+ authorizationSignature?: AuthorizationRequirementSignature;
17
25
  };
18
26
  metadata?: Metadata;
19
27
  }
@@ -35,6 +43,8 @@ export interface BlueBorrowParams {
35
43
  * @param params.args.minSharePrice - Minimum borrow share price (in ray). Slippage protection.
36
44
  * @param params.args.reallocations - Optional vault reallocations to execute before borrowing,
37
45
  * computed by the entity layer.
46
+ * @param params.args.authorizationSignature - Optional signed Morpho authorization; when present,
47
+ * a `setAuthorizationWithSig` call is prepended to the bundle.
38
48
  * @param params.metadata - Optional analytics metadata attached to the bundle.
39
49
  * @returns A deep-frozen `Transaction<BlueBorrowAction>` with `to`, `value`, `data`, and the
40
50
  * typed `action` discriminator the simulation layer consumes.
@@ -66,4 +76,4 @@ export interface BlueBorrowParams {
66
76
  * // tx satisfies Readonly<Transaction<BlueBorrowAction>>
67
77
  * ```
68
78
  */
69
- export declare const blueBorrow: ({ market: { chainId, marketParams }, args: { amount, receiver, minSharePrice, reallocations }, metadata, }: BlueBorrowParams) => Readonly<Transaction<BlueBorrowAction>>;
79
+ export declare const blueBorrow: ({ market: { chainId, marketParams }, args: { amount, receiver, minSharePrice, reallocations, authorizationSignature, }, metadata, }: BlueBorrowParams) => Readonly<Transaction<BlueBorrowAction>>;
@@ -5,6 +5,7 @@ const morpho_ts_1 = require("@morpho-org/morpho-ts");
5
5
  const index_js_1 = require("../../bundler/index.js");
6
6
  const index_js_2 = require("../../helpers/index.js");
7
7
  const index_js_3 = require("../../types/index.js");
8
+ const getBlueAuthorizationAction_js_1 = require("../signatures/getBlueAuthorizationAction.js");
8
9
  const buildReallocationActions_js_1 = require("./buildReallocationActions.js");
9
10
  /**
10
11
  * Prepares a borrow transaction for a Morpho Blue market.
@@ -24,6 +25,8 @@ const buildReallocationActions_js_1 = require("./buildReallocationActions.js");
24
25
  * @param params.args.minSharePrice - Minimum borrow share price (in ray). Slippage protection.
25
26
  * @param params.args.reallocations - Optional vault reallocations to execute before borrowing,
26
27
  * computed by the entity layer.
28
+ * @param params.args.authorizationSignature - Optional signed Morpho authorization; when present,
29
+ * a `setAuthorizationWithSig` call is prepended to the bundle.
27
30
  * @param params.metadata - Optional analytics metadata attached to the bundle.
28
31
  * @returns A deep-frozen `Transaction<BlueBorrowAction>` with `to`, `value`, `data`, and the
29
32
  * typed `action` discriminator the simulation layer consumes.
@@ -55,7 +58,7 @@ const buildReallocationActions_js_1 = require("./buildReallocationActions.js");
55
58
  * // tx satisfies Readonly<Transaction<BlueBorrowAction>>
56
59
  * ```
57
60
  */
58
- const blueBorrow = ({ market: { chainId, marketParams }, args: { amount, receiver, minSharePrice, reallocations }, metadata, }) => {
61
+ const blueBorrow = ({ market: { chainId, marketParams }, args: { amount, receiver, minSharePrice, reallocations, authorizationSignature, }, metadata, }) => {
59
62
  if (amount <= 0n) {
60
63
  throw new index_js_3.NonPositiveBorrowAmountError(marketParams.id);
61
64
  }
@@ -64,6 +67,9 @@ const blueBorrow = ({ market: { chainId, marketParams }, args: { amount, receive
64
67
  }
65
68
  const actions = [];
66
69
  let reallocationFee = 0n;
70
+ if (authorizationSignature) {
71
+ actions.push((0, getBlueAuthorizationAction_js_1.getBlueAuthorizationAction)(chainId, authorizationSignature));
72
+ }
67
73
  if (reallocations && reallocations.length > 0) {
68
74
  const result = (0, buildReallocationActions_js_1.buildReallocationActions)(reallocations, marketParams);
69
75
  actions.push(...result.actions);
@@ -0,0 +1,47 @@
1
+ import type { Address } from "viem";
2
+ import type { Action } from "../../bundler/index.js";
3
+ import type { PermitRequirementSignature } from "../../types/index.js";
4
+ /** Parameters for {@link buildAssetFundingActions}. */
5
+ export interface BuildAssetFundingActionsParams {
6
+ /** Chain the operation runs on — resolves adapter addresses and validates wNative. */
7
+ readonly chainId: number;
8
+ /** Asset wrapped and/or pulled into `GeneralAdapter1` (loan token, collateral token, …). */
9
+ readonly asset: Address;
10
+ /** ERC-20 amount of `asset` to pull from the payer (`0n` on a fully-native funding). */
11
+ readonly erc20Amount: bigint;
12
+ /** Native ETH to wrap into wNative before the pull (`0n` when not wrapping). */
13
+ readonly nativeAmount: bigint;
14
+ /** Optional pre-signed permit/permit2 approval for the ERC-20 pull. */
15
+ readonly requirementSignature?: PermitRequirementSignature;
16
+ }
17
+ /**
18
+ * Builds the shared asset-funding actions — native wrapping followed by the ERC-20 pull — that move
19
+ * `asset` into `GeneralAdapter1` before a bundled Morpho operation (`blueSupply`,
20
+ * `blueSupplyCollateral`, `blueSupplyCollateralBorrow`, `blueRepay`, `blueRepayWithdrawCollateral`).
21
+ *
22
+ * Encode-only and synchronous: returns a fresh `Action[]` (never mutates its inputs, mirroring
23
+ * `buildReallocationActions`) and reads no on-chain state. When `nativeAmount > 0n`, validates
24
+ * `asset` is the chain's wNative and emits `nativeTransfer → wrapNative`. When `erc20Amount > 0n`,
25
+ * pulls the ERC-20 via a signed permit/permit2 (`requirementSignature`) or a plain
26
+ * `erc20TransferFrom` — `getTokenRequirementActions` emits the latter itself when no signature is
27
+ * supplied. A fully-native funding emits no ERC-20 action; funding nothing returns `[]`.
28
+ *
29
+ * Single source of truth for the native-wrap + ERC-20-pull composition every bundled Blue funding
30
+ * path depends on — a fix here applies to all of them instead of risking a silent divergence
31
+ * between copies.
32
+ *
33
+ * @param params - See {@link BuildAssetFundingActionsParams}.
34
+ * @returns The `nativeTransfer`/`wrapNative`/pull actions, in bundle order (empty when nothing is
35
+ * funded).
36
+ * @throws {ChainWNativeMissingError} when `nativeAmount > 0n` but the chain has no configured wNative.
37
+ * @throws {NativeAmountOnNonWNativeAssetError} when `nativeAmount > 0n` but `asset` is not the
38
+ * chain's wNative.
39
+ * @throws {DepositAssetMismatchError} from `getTokenRequirementActions` when `requirementSignature` is
40
+ * provided and the signed asset differs from `asset`.
41
+ * @throws {DepositAmountMismatchError} from `getTokenRequirementActions` when `requirementSignature` is
42
+ * provided and the signed amount differs from `erc20Amount`.
43
+ * @throws {Permit2ExpirationMissingError} from `getTokenRequirementActions` when a Permit2 requirement
44
+ * signature is missing its expiration.
45
+ * @internal
46
+ */
47
+ export declare const buildAssetFundingActions: ({ chainId, asset, erc20Amount, nativeAmount, requirementSignature, }: BuildAssetFundingActionsParams) => Action[];
@@ -0,0 +1,63 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.buildAssetFundingActions = void 0;
4
+ const blue_sdk_1 = require("@morpho-org/blue-sdk");
5
+ const index_js_1 = require("../../helpers/index.js");
6
+ const getTokenRequirementActions_js_1 = require("../signatures/getTokenRequirementActions.js");
7
+ /**
8
+ * Builds the shared asset-funding actions — native wrapping followed by the ERC-20 pull — that move
9
+ * `asset` into `GeneralAdapter1` before a bundled Morpho operation (`blueSupply`,
10
+ * `blueSupplyCollateral`, `blueSupplyCollateralBorrow`, `blueRepay`, `blueRepayWithdrawCollateral`).
11
+ *
12
+ * Encode-only and synchronous: returns a fresh `Action[]` (never mutates its inputs, mirroring
13
+ * `buildReallocationActions`) and reads no on-chain state. When `nativeAmount > 0n`, validates
14
+ * `asset` is the chain's wNative and emits `nativeTransfer → wrapNative`. When `erc20Amount > 0n`,
15
+ * pulls the ERC-20 via a signed permit/permit2 (`requirementSignature`) or a plain
16
+ * `erc20TransferFrom` — `getTokenRequirementActions` emits the latter itself when no signature is
17
+ * supplied. A fully-native funding emits no ERC-20 action; funding nothing returns `[]`.
18
+ *
19
+ * Single source of truth for the native-wrap + ERC-20-pull composition every bundled Blue funding
20
+ * path depends on — a fix here applies to all of them instead of risking a silent divergence
21
+ * between copies.
22
+ *
23
+ * @param params - See {@link BuildAssetFundingActionsParams}.
24
+ * @returns The `nativeTransfer`/`wrapNative`/pull actions, in bundle order (empty when nothing is
25
+ * funded).
26
+ * @throws {ChainWNativeMissingError} when `nativeAmount > 0n` but the chain has no configured wNative.
27
+ * @throws {NativeAmountOnNonWNativeAssetError} when `nativeAmount > 0n` but `asset` is not the
28
+ * chain's wNative.
29
+ * @throws {DepositAssetMismatchError} from `getTokenRequirementActions` when `requirementSignature` is
30
+ * provided and the signed asset differs from `asset`.
31
+ * @throws {DepositAmountMismatchError} from `getTokenRequirementActions` when `requirementSignature` is
32
+ * provided and the signed amount differs from `erc20Amount`.
33
+ * @throws {Permit2ExpirationMissingError} from `getTokenRequirementActions` when a Permit2 requirement
34
+ * signature is missing its expiration.
35
+ * @internal
36
+ */
37
+ const buildAssetFundingActions = ({ chainId, asset, erc20Amount, nativeAmount, requirementSignature, }) => {
38
+ const { bundler3: { generalAdapter1, bundler3 }, } = (0, blue_sdk_1.getChainAddresses)(chainId);
39
+ const actions = [];
40
+ // Wrap native into wNative before pulling the ERC-20 remainder.
41
+ if (nativeAmount > 0n) {
42
+ (0, index_js_1.validateNativeAsset)(chainId, asset);
43
+ actions.push({
44
+ type: "nativeTransfer",
45
+ args: [bundler3, generalAdapter1, nativeAmount, false],
46
+ }, {
47
+ type: "wrapNative",
48
+ args: [nativeAmount, generalAdapter1, false],
49
+ });
50
+ }
51
+ // Pull the ERC-20 portion (0 on a fully native funding). getTokenRequirementActions emits a plain
52
+ // erc20TransferFrom itself when no permit/permit2 signature is supplied.
53
+ if (erc20Amount > 0n) {
54
+ actions.push(...(0, getTokenRequirementActions_js_1.getTokenRequirementActions)({
55
+ asset,
56
+ amount: erc20Amount,
57
+ recipient: generalAdapter1,
58
+ requirementSignature,
59
+ }));
60
+ }
61
+ return actions;
62
+ };
63
+ exports.buildAssetFundingActions = buildAssetFundingActions;
@@ -1,6 +1,6 @@
1
1
  import { type MarketParams } from "@morpho-org/blue-sdk";
2
2
  import { type Address } from "viem";
3
- import { type BlueRefinanceAction, type Metadata, type Transaction, type VaultReallocation } from "../../types/index.js";
3
+ import { type AuthorizationRequirementSignature, type BlueRefinanceAction, type Metadata, type Transaction, type VaultReallocation } from "../../types/index.js";
4
4
  /** Parameters for {@link blueRefinance}. */
5
5
  export interface BlueRefinanceParams {
6
6
  source: {
@@ -11,7 +11,9 @@ export interface BlueRefinanceParams {
11
11
  readonly marketParams: MarketParams;
12
12
  };
13
13
  args: {
14
+ /** Address whose position is refinanced from the source to the target market. */
14
15
  user: Address;
16
+ /** Amount of collateral moved from the source market to the target market. */
15
17
  collateralAmount: bigint;
16
18
  /**
17
19
  * Loan assets to borrow on the target. Assets mode: the exact borrow (exclusive with
@@ -27,6 +29,12 @@ export interface BlueRefinanceParams {
27
29
  maxRepaySharePrice: bigint;
28
30
  /** PublicAllocator reallocations into the target market, run before the bundle. Fees add to `tx.value`. */
29
31
  targetReallocations?: readonly VaultReallocation[];
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;
30
38
  };
31
39
  metadata?: Metadata;
32
40
  }
@@ -64,7 +72,7 @@ export interface BlueRefinanceParams {
64
72
  * then an `erc20Transfer` skims any residual to the user if that repay is skipped.
65
73
  * - **Collat-only** (both zero/omitted): only collateral is migrated; borrow/repay legs omitted.
66
74
  *
67
- * Prerequisite: GA1 must be authorized on Morpho — the entity's `getRequirements()` returns the
75
+ * Prerequisite: GA1 must be authorized on Blue — the entity's `getRequirements()` returns the
68
76
  * `setAuthorization` transaction when needed.
69
77
  *
70
78
  * @param params.source.chainId - The chain both markets live on.
@@ -77,6 +85,8 @@ export interface BlueRefinanceParams {
77
85
  * @param params.args.minBorrowSharePrice - Minimum borrow share price (ray) on the target.
78
86
  * @param params.args.maxRepaySharePrice - Maximum repay share price (ray) on the source.
79
87
  * @param params.args.targetReallocations - PublicAllocator reallocations into the target, run before the supply leg.
88
+ * @param params.args.authorizationSignature - Optional signed Morpho authorization; when present,
89
+ * a `setAuthorizationWithSig` call is prepended to the bundle.
80
90
  * @param params.metadata - Optional analytics metadata appended to `tx.data`.
81
91
  * @returns A deep-frozen `Transaction<BlueRefinanceAction>`.
82
92
  * @remarks `borrowAssets` and `borrowShares` describe different markets (target borrow vs. source
@@ -114,4 +124,4 @@ export interface BlueRefinanceParams {
114
124
  * // tx satisfies Readonly<Transaction<BlueRefinanceAction>>
115
125
  * ```
116
126
  */
117
- export declare const blueRefinance: ({ source: { chainId, marketParams: sourceParams }, target: { marketParams: targetParams }, args: { user, collateralAmount, borrowAssets, borrowShares, minBorrowSharePrice, maxRepaySharePrice, targetReallocations, }, metadata, }: BlueRefinanceParams) => Readonly<Transaction<BlueRefinanceAction>>;
127
+ export declare const blueRefinance: ({ source: { chainId, marketParams: sourceParams }, target: { marketParams: targetParams }, args: { user, collateralAmount, borrowAssets, borrowShares, minBorrowSharePrice, maxRepaySharePrice, targetReallocations, authorizationSignature, }, metadata, }: BlueRefinanceParams) => Readonly<Transaction<BlueRefinanceAction>>;
@@ -7,6 +7,7 @@ const viem_1 = require("viem");
7
7
  const index_js_1 = require("../../bundler/index.js");
8
8
  const index_js_2 = require("../../helpers/index.js");
9
9
  const index_js_3 = require("../../types/index.js");
10
+ const getBlueAuthorizationAction_js_1 = require("../signatures/getBlueAuthorizationAction.js");
10
11
  const buildReallocationActions_js_1 = require("./buildReallocationActions.js");
11
12
  /**
12
13
  * Prepares an atomic refinance migrating a Morpho Blue position to another market on the same
@@ -42,7 +43,7 @@ const buildReallocationActions_js_1 = require("./buildReallocationActions.js");
42
43
  * then an `erc20Transfer` skims any residual to the user if that repay is skipped.
43
44
  * - **Collat-only** (both zero/omitted): only collateral is migrated; borrow/repay legs omitted.
44
45
  *
45
- * Prerequisite: GA1 must be authorized on Morpho — the entity's `getRequirements()` returns the
46
+ * Prerequisite: GA1 must be authorized on Blue — the entity's `getRequirements()` returns the
46
47
  * `setAuthorization` transaction when needed.
47
48
  *
48
49
  * @param params.source.chainId - The chain both markets live on.
@@ -55,6 +56,8 @@ const buildReallocationActions_js_1 = require("./buildReallocationActions.js");
55
56
  * @param params.args.minBorrowSharePrice - Minimum borrow share price (ray) on the target.
56
57
  * @param params.args.maxRepaySharePrice - Maximum repay share price (ray) on the source.
57
58
  * @param params.args.targetReallocations - PublicAllocator reallocations into the target, run before the supply leg.
59
+ * @param params.args.authorizationSignature - Optional signed Morpho authorization; when present,
60
+ * a `setAuthorizationWithSig` call is prepended to the bundle.
58
61
  * @param params.metadata - Optional analytics metadata appended to `tx.data`.
59
62
  * @returns A deep-frozen `Transaction<BlueRefinanceAction>`.
60
63
  * @remarks `borrowAssets` and `borrowShares` describe different markets (target borrow vs. source
@@ -92,7 +95,7 @@ const buildReallocationActions_js_1 = require("./buildReallocationActions.js");
92
95
  * // tx satisfies Readonly<Transaction<BlueRefinanceAction>>
93
96
  * ```
94
97
  */
95
- const blueRefinance = ({ source: { chainId, marketParams: sourceParams }, target: { marketParams: targetParams }, args: { user, collateralAmount, borrowAssets = 0n, borrowShares = 0n, minBorrowSharePrice, maxRepaySharePrice, targetReallocations, }, metadata, }) => {
98
+ const blueRefinance = ({ source: { chainId, marketParams: sourceParams }, target: { marketParams: targetParams }, args: { user, collateralAmount, borrowAssets = 0n, borrowShares = 0n, minBorrowSharePrice, maxRepaySharePrice, targetReallocations, authorizationSignature, }, metadata, }) => {
96
99
  if (collateralAmount <= 0n) {
97
100
  throw new index_js_3.ZeroCollateralAmountError(sourceParams.id);
98
101
  }
@@ -184,6 +187,9 @@ const blueRefinance = ({ source: { chainId, marketParams: sourceParams }, target
184
187
  });
185
188
  const actions = [];
186
189
  let reallocationFee = 0n;
190
+ if (authorizationSignature) {
191
+ actions.push((0, getBlueAuthorizationAction_js_1.getBlueAuthorizationAction)(chainId, authorizationSignature));
192
+ }
187
193
  if (targetReallocations && targetReallocations.length > 0) {
188
194
  const result = (0, buildReallocationActions_js_1.buildReallocationActions)(targetReallocations, targetParams);
189
195
  actions.push(...result.actions);
@@ -1,54 +1,49 @@
1
1
  import { type MarketParams } from "@morpho-org/blue-sdk";
2
2
  import { type Address } from "viem";
3
- import type { BlueRepayAction, Metadata, RequirementSignature, Transaction } from "../../types/index.js";
3
+ import type { BlueRepayAction, Metadata, PermitRequirementSignature, RepayActionAmountArgs, Transaction } from "../../types/index.js";
4
4
  /** Parameters for {@link blueRepay}. */
5
5
  export interface BlueRepayParams {
6
6
  market: {
7
7
  readonly chainId: number;
8
8
  readonly marketParams: MarketParams;
9
9
  };
10
- args: {
11
- /** Repay assets amount (0n when repaying by shares). */
12
- assets: bigint;
13
- /** Repay shares amount (0n when repaying by assets). */
14
- shares: bigint;
15
- /**
16
- * ERC-20 amount to pull into `GeneralAdapter1`. In assets mode, must equal `assets`
17
- * exactly (`TransferAmountNotEqualToAssetsError` fires otherwise). In shares mode, an
18
- * upper-bound estimate to absorb share-price drift; residual is skimmed back to `receiver`.
19
- */
20
- transferAmount: bigint;
10
+ args: RepayActionAmountArgs & {
21
11
  /** Address whose debt is being repaid. */
22
12
  onBehalf: Address;
23
13
  /** Receives residual loan tokens in shares mode. */
24
14
  receiver: Address;
25
15
  /** Maximum repay share price (in ray). Protects against share price manipulation. */
26
16
  maxSharePrice: bigint;
27
- requirementSignature?: RequirementSignature;
17
+ /** Optional pre-signed permit/permit2 approval for the loan-token transfer. */
18
+ requirementSignature?: PermitRequirementSignature;
28
19
  };
29
20
  metadata?: Metadata;
30
21
  }
31
22
  /**
32
23
  * Prepares a repay transaction for a Morpho Blue market.
33
24
  *
34
- * Routed through bundler3 via `GeneralAdapter1`. Supports two modes:
25
+ * Routed through bundler3 via `GeneralAdapter1`. All amount arithmetic is done upstream (see
26
+ * `MorphoBlue.repay`); this builder just assembles the bundle from the pre-resolved
27
+ * {@link RepayActionAmountArgs}. The mode is discriminated on `shares`, plus optional native wrapping
28
+ * (when `nativeAmount > 0`, native ETH is wrapped via `GeneralAdapter1.wrapNative()` before the
29
+ * repay; the loan token must be the chain's wNative):
35
30
  *
36
- * - **By assets** (`assets > 0, shares = 0`): repays an exact asset amount.
37
- * - **By shares** (`assets = 0, shares > 0`): repays exact shares (full repay), with
38
- * `transferAmount` set to an upper-bound asset estimate; residual loan tokens are skimmed back
39
- * to `receiver` after the call.
31
+ * - **assets mode** (`shares` unset/`0n`): repays `transferAmount` assets (`= amount + nativeAmount`,
32
+ * additive like `blueSupply`), pulling `amount` ERC-20 and wrapping `nativeAmount`. No residual.
33
+ * - **shares mode** (`shares > 0n`): repays exact shares (full repay), pulling `transferAmount`
34
+ * ERC-20 (already net of native) and wrapping `nativeAmount`. Residual loan tokens are skimmed
35
+ * back to `receiver` after the call.
40
36
  *
41
- * Exactly one of `assets` / `shares` must be non-zero. Uses `maxSharePrice` to protect against
42
- * share price manipulation between transaction construction and execution.
37
+ * Uses `maxSharePrice` to protect against share price manipulation between construction and execution.
43
38
  *
44
39
  * @param params.market.chainId - The chain the market lives on.
45
40
  * @param params.market.marketParams - Market params (loanToken, collateralToken, oracle, irm, lltv).
46
- * @param params.args.assets - Repay amount in loan-token assets. Set to `0n` when repaying by shares.
47
- * @param params.args.shares - Repay amount in borrow shares. Set to `0n` when repaying by assets.
48
- * @param params.args.transferAmount - ERC-20 amount to pull into `GeneralAdapter1`. In assets
49
- * mode, must equal `assets` exactly (`TransferAmountNotEqualToAssetsError` fires otherwise).
50
- * In shares mode, this is an upper-bound estimate to absorb share-price drift; residual loan
51
- * tokens are skimmed back to `receiver`.
41
+ * @param params.args.amount - (assets mode) ERC-20 loan tokens pulled from the payer. Defaults to `0n`.
42
+ * @param params.args.shares - (shares mode) Repay amount in borrow shares. Discriminates the mode.
43
+ * @param params.args.transferAmount - Loan tokens routed into `GeneralAdapter1`: assets mode = the
44
+ * total repaid (`amount + nativeAmount`); shares mode = the ERC-20 pulled (net of native).
45
+ * @param params.args.nativeAmount - Optional native token to wrap into wNative to fund the repay.
46
+ * Requires the loan token to be the chain's wNative.
52
47
  * @param params.args.onBehalf - Address whose Morpho debt is being repaid.
53
48
  * @param params.args.receiver - Address that receives residual loan tokens in shares mode.
54
49
  * @param params.args.maxSharePrice - Maximum acceptable repay share price (in ray). Slippage
@@ -56,36 +51,42 @@ export interface BlueRepayParams {
56
51
  * @param params.args.requirementSignature - Optional pre-signed permit/permit2 approval for the
57
52
  * loan-token transfer.
58
53
  * @param params.metadata - Optional analytics metadata attached to the bundle.
59
- * @returns A deep-frozen `Transaction<BlueRepayAction>` with `to`, `value`, `data`, and the
60
- * typed `action` discriminator the simulation layer consumes.
54
+ * @returns A deep-frozen `Transaction<BlueRepayAction>` with `to`, `value` (= `nativeAmount`),
55
+ * `data`, and the typed `action` discriminator the simulation layer consumes.
61
56
  * @throws {NonPositiveRepayMaxSharePriceError} when `maxSharePrice <= 0n`.
62
- * @throws {NonPositiveRepayAmountError} when either `assets` or `shares` is negative, or when
63
- * both are zero.
64
- * @throws {MutuallyExclusiveRepayAmountsError} when both `assets` and `shares` are non-zero.
65
- * @throws {NonPositiveTransferAmountError} when `transferAmount <= 0n`.
66
- * @throws {TransferAmountNotEqualToAssetsError} when in assets mode and `transferAmount !== assets`.
67
- * @throws {DepositAssetMismatchError} from `getRequirementsAction` when `requirementSignature`
57
+ * @throws {NegativeNativeAmountError} when `nativeAmount < 0n`.
58
+ * @throws {MutuallyExclusiveRepayAmountsError} when both `amount` and `shares` are `> 0n`.
59
+ * @throws {TransferAmountNotEqualToAssetsError} when in assets mode and
60
+ * `transferAmount !== amount + nativeAmount`.
61
+ * @throws {NonPositiveRepayAmountError} when `amount` or `shares` is negative, when in assets mode
62
+ * and `transferAmount <= 0n`, or when in shares mode and `transferAmount` is negative or the total
63
+ * funding (`transferAmount + nativeAmount`) is `<= 0n`.
64
+ * @throws {ChainWNativeMissingError} when `nativeAmount > 0n` but the chain has no configured wNative.
65
+ * @throws {NativeAmountOnNonWNativeAssetError} when `nativeAmount > 0n` but the loan token is not
66
+ * the chain's wNative.
67
+ * @throws {DepositAssetMismatchError} from `getTokenRequirementActions` when `requirementSignature`
68
68
  * is provided and the signed asset differs from `marketParams.loanToken`.
69
- * @throws {DepositAmountMismatchError} from `getRequirementsAction` when `requirementSignature`
70
- * is provided and the signed amount differs from `args.transferAmount`.
71
- * @throws {Permit2ExpirationMissingError} from `getRequirementsAction` when a Permit2 requirement
69
+ * @throws {DepositAmountMismatchError} from `getTokenRequirementActions` when `requirementSignature`
70
+ * is provided and the signed amount differs from the ERC-20 amount pulled.
71
+ * @throws {Permit2ExpirationMissingError} from `getTokenRequirementActions` when a Permit2 requirement
72
72
  * signature is missing its expiration.
73
73
  * @example
74
74
  * ```ts
75
75
  * import { blueRepay } from "@morpho-org/morpho-sdk";
76
76
  *
77
+ * // Repay 0.5 loan-asset units, 0.2 of them funded by wrapping native ETH.
77
78
  * const tx = blueRepay({
78
- * market: { chainId: 1, marketParams },
79
+ * market: { chainId: 1, marketParams }, // marketParams.loanToken === wNative
79
80
  * args: {
80
- * assets: 500_000_000n,
81
- * shares: 0n,
82
- * transferAmount: 500_000_000n,
81
+ * amount: 300_000_000_000_000_000n, // ERC-20 part
82
+ * nativeAmount: 200_000_000_000_000_000n, // wrapped ETH part
83
+ * transferAmount: 500_000_000_000_000_000n, // total repaid = amount + nativeAmount
83
84
  * onBehalf: borrower,
84
85
  * receiver: borrower,
85
86
  * maxSharePrice: 1_010_000_000_000_000_000_000_000_000n, // RAY-scaled, 1.01x
86
87
  * },
87
88
  * });
88
- * // tx satisfies Readonly<Transaction<BlueRepayAction>>
89
+ * // tx.value === 200_000_000_000_000_000n
89
90
  * ```
90
91
  */
91
- export declare const blueRepay: ({ market: { chainId, marketParams }, args: { assets, shares, transferAmount, onBehalf, receiver, maxSharePrice, requirementSignature, }, metadata, }: BlueRepayParams) => Readonly<Transaction<BlueRepayAction>>;
92
+ export declare const blueRepay: ({ market: { chainId, marketParams }, args, metadata, }: BlueRepayParams) => Readonly<Transaction<BlueRepayAction>>;