@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/lib/cjs/utils.js CHANGED
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.validateRepayAmount = exports.validateReallocations = exports.validatePositionHealthAfterWithdraw = exports.validatePositionHealth = exports.validateNativeAsset = exports.validateChainId = exports.validateAccrualPosition = exports.computeMinBorrowSharePrice = exports.computeMaxRepaySharePrice = exports.addTransactionMetadata = exports.computeReallocations = exports.values = exports.transformValue = exports.Time = exports.retryPromiseLinearBackoff = exports.mergeEntries = exports.keys = exports.isNotUndefined = exports.isNotNull = exports.isDefined = exports.hasValue = exports.getValue = exports.getSubdomainBaseUrl = exports.getLastDefined = exports.getLast = exports.fromEntries = exports.filterDefined = exports.entries = exports.deepFreeze = exports.createHasValue = exports.createGetValue = exports.bigIntComparator = exports.safeParseUnits = exports.safeParseNumber = exports.safeGetAddress = exports.restructure = exports.readContractRestructured = exports.optionalBoolean = exports.getPermitTypedData = exports.getPermit2TransferFromTypedData = exports.getPermit2PermitTypedData = exports.getDaiPermitTypedData = exports.getAuthorizationTypedData = exports.decodeBytes32String = exports.VaultUtils = exports.SharesMath = exports.MathLib = exports.MarketUtils = exports.CapacityLimitReason = exports.AdaptiveCurveIrmLib = void 0;
4
- exports.validateUserAddress = exports.validateSlippageTolerance = exports.validateRepayShares = exports.validateRepayParams = void 0;
3
+ exports.validateRepayShares = exports.validateRepayAmount = exports.validateReallocations = exports.validatePositionHealthAfterWithdraw = exports.validatePositionHealth = exports.validateNativeAsset = exports.validateChainId = exports.validateAccrualPosition = exports.computeMinBorrowSharePrice = exports.computeMaxRepaySharePrice = exports.addTransactionMetadata = exports.computeReallocations = exports.values = exports.transformValue = exports.Time = exports.retryPromiseLinearBackoff = exports.mergeEntries = exports.keys = exports.isNotUndefined = exports.isNotNull = exports.isDefined = exports.hasValue = exports.getValue = exports.getSubdomainBaseUrl = exports.getLastDefined = exports.getLast = exports.fromEntries = exports.filterDefined = exports.entries = exports.deepFreeze = exports.createHasValue = exports.createGetValue = exports.bigIntComparator = exports.safeParseUnits = exports.safeParseNumber = exports.safeGetAddress = exports.restructure = exports.readContractRestructured = exports.optionalBoolean = exports.getPermitTypedData = exports.getPermit2TransferFromTypedData = exports.getPermit2PermitTypedData = exports.getAuthorizationTypedData = exports.decodeBytes32String = exports.VaultUtils = exports.SharesMath = exports.MathLib = exports.MarketUtils = exports.CapacityLimitReason = exports.AdaptiveCurveIrmLib = void 0;
4
+ exports.validateUserAddress = exports.validateSlippageTolerance = void 0;
5
5
  var blue_sdk_1 = require("@morpho-org/blue-sdk");
6
6
  Object.defineProperty(exports, "AdaptiveCurveIrmLib", { enumerable: true, get: function () { return blue_sdk_1.AdaptiveCurveIrmLib; } });
7
7
  Object.defineProperty(exports, "CapacityLimitReason", { enumerable: true, get: function () { return blue_sdk_1.CapacityLimitReason; } });
@@ -12,7 +12,6 @@ Object.defineProperty(exports, "VaultUtils", { enumerable: true, get: function (
12
12
  var blue_sdk_viem_1 = require("@morpho-org/blue-sdk-viem");
13
13
  Object.defineProperty(exports, "decodeBytes32String", { enumerable: true, get: function () { return blue_sdk_viem_1.decodeBytes32String; } });
14
14
  Object.defineProperty(exports, "getAuthorizationTypedData", { enumerable: true, get: function () { return blue_sdk_viem_1.getAuthorizationTypedData; } });
15
- Object.defineProperty(exports, "getDaiPermitTypedData", { enumerable: true, get: function () { return blue_sdk_viem_1.getDaiPermitTypedData; } });
16
15
  Object.defineProperty(exports, "getPermit2PermitTypedData", { enumerable: true, get: function () { return blue_sdk_viem_1.getPermit2PermitTypedData; } });
17
16
  Object.defineProperty(exports, "getPermit2TransferFromTypedData", { enumerable: true, get: function () { return blue_sdk_viem_1.getPermit2TransferFromTypedData; } });
18
17
  Object.defineProperty(exports, "getPermitTypedData", { enumerable: true, get: function () { return blue_sdk_viem_1.getPermitTypedData; } });
@@ -59,7 +58,6 @@ Object.defineProperty(exports, "validatePositionHealth", { enumerable: true, get
59
58
  Object.defineProperty(exports, "validatePositionHealthAfterWithdraw", { enumerable: true, get: function () { return validate_js_1.validatePositionHealthAfterWithdraw; } });
60
59
  Object.defineProperty(exports, "validateReallocations", { enumerable: true, get: function () { return validate_js_1.validateReallocations; } });
61
60
  Object.defineProperty(exports, "validateRepayAmount", { enumerable: true, get: function () { return validate_js_1.validateRepayAmount; } });
62
- Object.defineProperty(exports, "validateRepayParams", { enumerable: true, get: function () { return validate_js_1.validateRepayParams; } });
63
61
  Object.defineProperty(exports, "validateRepayShares", { enumerable: true, get: function () { return validate_js_1.validateRepayShares; } });
64
62
  Object.defineProperty(exports, "validateSlippageTolerance", { enumerable: true, get: function () { return validate_js_1.validateSlippageTolerance; } });
65
63
  Object.defineProperty(exports, "validateUserAddress", { enumerable: true, get: function () { return validate_js_1.validateUserAddress; } });
@@ -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>>;
@@ -2,6 +2,7 @@ import { deepFreeze } from "@morpho-org/morpho-ts";
2
2
  import { BundlerAction } from "../../bundler/index.js";
3
3
  import { addTransactionMetadata } from "../../helpers/index.js";
4
4
  import { NonPositiveBorrowAmountError, NonPositiveMinBorrowSharePriceError, } from "../../types/index.js";
5
+ import { getBlueAuthorizationAction } from "../signatures/getBlueAuthorizationAction.js";
5
6
  import { buildReallocationActions } from "./buildReallocationActions.js";
6
7
  /**
7
8
  * Prepares a borrow transaction for a Morpho Blue market.
@@ -21,6 +22,8 @@ import { buildReallocationActions } from "./buildReallocationActions.js";
21
22
  * @param params.args.minSharePrice - Minimum borrow share price (in ray). Slippage protection.
22
23
  * @param params.args.reallocations - Optional vault reallocations to execute before borrowing,
23
24
  * computed by the entity layer.
25
+ * @param params.args.authorizationSignature - Optional signed Morpho authorization; when present,
26
+ * a `setAuthorizationWithSig` call is prepended to the bundle.
24
27
  * @param params.metadata - Optional analytics metadata attached to the bundle.
25
28
  * @returns A deep-frozen `Transaction<BlueBorrowAction>` with `to`, `value`, `data`, and the
26
29
  * typed `action` discriminator the simulation layer consumes.
@@ -52,7 +55,7 @@ import { buildReallocationActions } from "./buildReallocationActions.js";
52
55
  * // tx satisfies Readonly<Transaction<BlueBorrowAction>>
53
56
  * ```
54
57
  */
55
- export const blueBorrow = ({ market: { chainId, marketParams }, args: { amount, receiver, minSharePrice, reallocations }, metadata, }) => {
58
+ export const blueBorrow = ({ market: { chainId, marketParams }, args: { amount, receiver, minSharePrice, reallocations, authorizationSignature, }, metadata, }) => {
56
59
  if (amount <= 0n) {
57
60
  throw new NonPositiveBorrowAmountError(marketParams.id);
58
61
  }
@@ -61,6 +64,9 @@ export const blueBorrow = ({ market: { chainId, marketParams }, args: { amount,
61
64
  }
62
65
  const actions = [];
63
66
  let reallocationFee = 0n;
67
+ if (authorizationSignature) {
68
+ actions.push(getBlueAuthorizationAction(chainId, authorizationSignature));
69
+ }
64
70
  if (reallocations && reallocations.length > 0) {
65
71
  const result = buildReallocationActions(reallocations, marketParams);
66
72
  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,59 @@
1
+ import { getChainAddresses } from "@morpho-org/blue-sdk";
2
+ import { validateNativeAsset } from "../../helpers/index.js";
3
+ import { getTokenRequirementActions } from "../signatures/getTokenRequirementActions.js";
4
+ /**
5
+ * Builds the shared asset-funding actions — native wrapping followed by the ERC-20 pull — that move
6
+ * `asset` into `GeneralAdapter1` before a bundled Morpho operation (`blueSupply`,
7
+ * `blueSupplyCollateral`, `blueSupplyCollateralBorrow`, `blueRepay`, `blueRepayWithdrawCollateral`).
8
+ *
9
+ * Encode-only and synchronous: returns a fresh `Action[]` (never mutates its inputs, mirroring
10
+ * `buildReallocationActions`) and reads no on-chain state. When `nativeAmount > 0n`, validates
11
+ * `asset` is the chain's wNative and emits `nativeTransfer → wrapNative`. When `erc20Amount > 0n`,
12
+ * pulls the ERC-20 via a signed permit/permit2 (`requirementSignature`) or a plain
13
+ * `erc20TransferFrom` — `getTokenRequirementActions` emits the latter itself when no signature is
14
+ * supplied. A fully-native funding emits no ERC-20 action; funding nothing returns `[]`.
15
+ *
16
+ * Single source of truth for the native-wrap + ERC-20-pull composition every bundled Blue funding
17
+ * path depends on — a fix here applies to all of them instead of risking a silent divergence
18
+ * between copies.
19
+ *
20
+ * @param params - See {@link BuildAssetFundingActionsParams}.
21
+ * @returns The `nativeTransfer`/`wrapNative`/pull actions, in bundle order (empty when nothing is
22
+ * funded).
23
+ * @throws {ChainWNativeMissingError} when `nativeAmount > 0n` but the chain has no configured wNative.
24
+ * @throws {NativeAmountOnNonWNativeAssetError} when `nativeAmount > 0n` but `asset` is not the
25
+ * chain's wNative.
26
+ * @throws {DepositAssetMismatchError} from `getTokenRequirementActions` when `requirementSignature` is
27
+ * provided and the signed asset differs from `asset`.
28
+ * @throws {DepositAmountMismatchError} from `getTokenRequirementActions` when `requirementSignature` is
29
+ * provided and the signed amount differs from `erc20Amount`.
30
+ * @throws {Permit2ExpirationMissingError} from `getTokenRequirementActions` when a Permit2 requirement
31
+ * signature is missing its expiration.
32
+ * @internal
33
+ */
34
+ export const buildAssetFundingActions = ({ chainId, asset, erc20Amount, nativeAmount, requirementSignature, }) => {
35
+ const { bundler3: { generalAdapter1, bundler3 }, } = getChainAddresses(chainId);
36
+ const actions = [];
37
+ // Wrap native into wNative before pulling the ERC-20 remainder.
38
+ if (nativeAmount > 0n) {
39
+ validateNativeAsset(chainId, asset);
40
+ actions.push({
41
+ type: "nativeTransfer",
42
+ args: [bundler3, generalAdapter1, nativeAmount, false],
43
+ }, {
44
+ type: "wrapNative",
45
+ args: [nativeAmount, generalAdapter1, false],
46
+ });
47
+ }
48
+ // Pull the ERC-20 portion (0 on a fully native funding). getTokenRequirementActions emits a plain
49
+ // erc20TransferFrom itself when no permit/permit2 signature is supplied.
50
+ if (erc20Amount > 0n) {
51
+ actions.push(...getTokenRequirementActions({
52
+ asset,
53
+ amount: erc20Amount,
54
+ recipient: generalAdapter1,
55
+ requirementSignature,
56
+ }));
57
+ }
58
+ return actions;
59
+ };
@@ -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>>;
@@ -4,6 +4,7 @@ import { isAddressEqual, maxUint256 } from "viem";
4
4
  import { BundlerAction } from "../../bundler/index.js";
5
5
  import { addTransactionMetadata } from "../../helpers/index.js";
6
6
  import { NegativeBorrowSharesError, NegativeMaxRepaySharePriceError, NonPositiveAssetAmountError, NonPositiveMinBorrowSharePriceError, NonPositiveRepayMaxSharePriceError, RefinanceSameMarketError, RefinanceSharesMissingBorrowAssetsError, RefinanceTokenMismatchError, ZeroCollateralAmountError, } from "../../types/index.js";
7
+ import { getBlueAuthorizationAction } from "../signatures/getBlueAuthorizationAction.js";
7
8
  import { buildReallocationActions } from "./buildReallocationActions.js";
8
9
  /**
9
10
  * Prepares an atomic refinance migrating a Morpho Blue position to another market on the same
@@ -39,7 +40,7 @@ import { buildReallocationActions } from "./buildReallocationActions.js";
39
40
  * then an `erc20Transfer` skims any residual to the user if that repay is skipped.
40
41
  * - **Collat-only** (both zero/omitted): only collateral is migrated; borrow/repay legs omitted.
41
42
  *
42
- * Prerequisite: GA1 must be authorized on Morpho — the entity's `getRequirements()` returns the
43
+ * Prerequisite: GA1 must be authorized on Blue — the entity's `getRequirements()` returns the
43
44
  * `setAuthorization` transaction when needed.
44
45
  *
45
46
  * @param params.source.chainId - The chain both markets live on.
@@ -52,6 +53,8 @@ import { buildReallocationActions } from "./buildReallocationActions.js";
52
53
  * @param params.args.minBorrowSharePrice - Minimum borrow share price (ray) on the target.
53
54
  * @param params.args.maxRepaySharePrice - Maximum repay share price (ray) on the source.
54
55
  * @param params.args.targetReallocations - PublicAllocator reallocations into the target, run before the supply leg.
56
+ * @param params.args.authorizationSignature - Optional signed Morpho authorization; when present,
57
+ * a `setAuthorizationWithSig` call is prepended to the bundle.
55
58
  * @param params.metadata - Optional analytics metadata appended to `tx.data`.
56
59
  * @returns A deep-frozen `Transaction<BlueRefinanceAction>`.
57
60
  * @remarks `borrowAssets` and `borrowShares` describe different markets (target borrow vs. source
@@ -89,7 +92,7 @@ import { buildReallocationActions } from "./buildReallocationActions.js";
89
92
  * // tx satisfies Readonly<Transaction<BlueRefinanceAction>>
90
93
  * ```
91
94
  */
92
- export const blueRefinance = ({ source: { chainId, marketParams: sourceParams }, target: { marketParams: targetParams }, args: { user, collateralAmount, borrowAssets = 0n, borrowShares = 0n, minBorrowSharePrice, maxRepaySharePrice, targetReallocations, }, metadata, }) => {
95
+ export const blueRefinance = ({ source: { chainId, marketParams: sourceParams }, target: { marketParams: targetParams }, args: { user, collateralAmount, borrowAssets = 0n, borrowShares = 0n, minBorrowSharePrice, maxRepaySharePrice, targetReallocations, authorizationSignature, }, metadata, }) => {
93
96
  if (collateralAmount <= 0n) {
94
97
  throw new ZeroCollateralAmountError(sourceParams.id);
95
98
  }
@@ -181,6 +184,9 @@ export const blueRefinance = ({ source: { chainId, marketParams: sourceParams },
181
184
  });
182
185
  const actions = [];
183
186
  let reallocationFee = 0n;
187
+ if (authorizationSignature) {
188
+ actions.push(getBlueAuthorizationAction(chainId, authorizationSignature));
189
+ }
184
190
  if (targetReallocations && targetReallocations.length > 0) {
185
191
  const result = buildReallocationActions(targetReallocations, targetParams);
186
192
  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>>;