@morpho-org/morpho-sdk 6.5.0 → 7.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (167) hide show
  1. package/MIGRATION-v6-to-v7.md +291 -0
  2. package/README.md +26 -12
  3. package/lib/cjs/abis.d.ts +1 -1
  4. package/lib/cjs/abis.js +3 -2
  5. package/lib/cjs/actions/bundles/common.d.ts +9 -5
  6. package/lib/cjs/actions/bundles/common.js +22 -13
  7. package/lib/cjs/actions/midnight/authorization.d.ts +3 -2
  8. package/lib/cjs/actions/midnight/authorization.js +3 -2
  9. package/lib/cjs/actions/midnight/cancelAndMake.d.ts +153 -0
  10. package/lib/cjs/actions/midnight/cancelAndMake.js +292 -0
  11. package/lib/cjs/actions/midnight/index.d.ts +3 -3
  12. package/lib/cjs/actions/midnight/index.js +3 -3
  13. package/lib/cjs/actions/midnight/repayWithdrawCollateral.d.ts +40 -23
  14. package/lib/cjs/actions/midnight/repayWithdrawCollateral.js +105 -69
  15. package/lib/cjs/actions/midnight/supplyCollateralTakeBorrow.d.ts +52 -27
  16. package/lib/cjs/actions/midnight/supplyCollateralTakeBorrow.js +128 -71
  17. package/lib/cjs/actions/midnight/takeBorrow.d.ts +40 -28
  18. package/lib/cjs/actions/midnight/takeBorrow.js +95 -54
  19. package/lib/cjs/actions/midnight/takeLend.d.ts +51 -27
  20. package/lib/cjs/actions/midnight/takeLend.js +111 -54
  21. package/lib/cjs/actions/midnight/takeRepayWithdrawCollateral.d.ts +97 -0
  22. package/lib/cjs/actions/midnight/takeRepayWithdrawCollateral.js +201 -0
  23. package/lib/cjs/actions/midnight/takeWithdraw.d.ts +69 -0
  24. package/lib/cjs/actions/midnight/takeWithdraw.js +153 -0
  25. package/lib/cjs/actions/midnight/types.d.ts +7 -26
  26. package/lib/cjs/actions/midnight/types.js +0 -13
  27. package/lib/cjs/actions/requirements/encode/encodeErc20Approval.d.ts +2 -1
  28. package/lib/cjs/actions/requirements/encode/encodeErc20Approval.js +3 -2
  29. package/lib/cjs/actions/requirements/encode/encodeErc20Permit.d.ts +4 -4
  30. package/lib/cjs/actions/requirements/encode/encodeErc20Permit.js +5 -5
  31. package/lib/cjs/actions/requirements/getRequirementsApproval.d.ts +2 -2
  32. package/lib/cjs/actions/requirements/getRequirementsApproval.js +2 -2
  33. package/lib/cjs/actions/requirements/midnight/getMidnightApprovalRequirements.d.ts +24 -8
  34. package/lib/cjs/actions/requirements/midnight/getMidnightApprovalRequirements.js +24 -13
  35. package/lib/cjs/actions/requirements/midnight/getMidnightAuthorizationRequirement.d.ts +11 -7
  36. package/lib/cjs/actions/requirements/midnight/getMidnightAuthorizationRequirement.js +11 -7
  37. package/lib/cjs/actions/requirements/midnight/index.d.ts +0 -1
  38. package/lib/cjs/actions/requirements/midnight/index.js +0 -1
  39. package/lib/cjs/constants.d.ts +1 -1
  40. package/lib/cjs/constants.js +3 -1
  41. package/lib/cjs/entities/blue/blue.d.ts +10 -6
  42. package/lib/cjs/entities/blue/blue.js +5 -3
  43. package/lib/cjs/entities/index.d.ts +2 -2
  44. package/lib/cjs/entities/midnight/midnight.d.ts +582 -108
  45. package/lib/cjs/entities/midnight/midnight.js +981 -509
  46. package/lib/cjs/entities/midnight/types.d.ts +142 -60
  47. package/lib/cjs/entities/vaultV1/vaultV1.d.ts +2 -1
  48. package/lib/cjs/entities/vaultV1/vaultV1.js +1 -0
  49. package/lib/cjs/entities/vaultV2/vaultV2.d.ts +2 -1
  50. package/lib/cjs/entities/vaultV2/vaultV2.js +1 -0
  51. package/lib/cjs/entities/vaultV2BlueReallocationData.d.ts +11 -3
  52. package/lib/cjs/entities/vaultV2BlueReallocationData.js +119 -43
  53. package/lib/cjs/helpers/callback.d.ts +54 -0
  54. package/lib/cjs/helpers/callback.js +73 -0
  55. package/lib/cjs/helpers/constant.d.ts +10 -0
  56. package/lib/cjs/helpers/constant.js +11 -1
  57. package/lib/cjs/helpers/index.d.ts +3 -2
  58. package/lib/cjs/helpers/index.js +7 -1
  59. package/lib/cjs/helpers/signAndVerifyTypedData.d.ts +3 -3
  60. package/lib/cjs/helpers/signAndVerifyTypedData.js +3 -3
  61. package/lib/cjs/helpers/utilization.d.ts +13 -0
  62. package/lib/cjs/helpers/utilization.js +26 -1
  63. package/lib/cjs/helpers/validate.d.ts +43 -2
  64. package/lib/cjs/helpers/validate.js +60 -3
  65. package/lib/cjs/helpers/validateMidnightAuthorizationTarget.d.ts +1 -1
  66. package/lib/cjs/helpers/validateMidnightAuthorizationTarget.js +3 -7
  67. package/lib/cjs/helpers/validateRequirementSpender.d.ts +3 -3
  68. package/lib/cjs/helpers/validateRequirementSpender.js +4 -5
  69. package/lib/cjs/midnight/abis.d.ts +1 -1
  70. package/lib/cjs/midnight/abis.js +3 -2
  71. package/lib/cjs/midnight/types.d.ts +1 -1
  72. package/lib/cjs/types/action.d.ts +117 -89
  73. package/lib/cjs/types/action.js +1 -19
  74. package/lib/cjs/types/error.d.ts +126 -40
  75. package/lib/cjs/types/error.js +154 -49
  76. package/lib/cjs/types/sharedLiquidity.d.ts +17 -0
  77. package/lib/esm/abis.d.ts +1 -1
  78. package/lib/esm/abis.js +1 -1
  79. package/lib/esm/actions/bundles/common.d.ts +9 -5
  80. package/lib/esm/actions/bundles/common.js +22 -13
  81. package/lib/esm/actions/midnight/authorization.d.ts +3 -2
  82. package/lib/esm/actions/midnight/authorization.js +3 -2
  83. package/lib/esm/actions/midnight/cancelAndMake.d.ts +153 -0
  84. package/lib/esm/actions/midnight/cancelAndMake.js +288 -0
  85. package/lib/esm/actions/midnight/index.d.ts +3 -3
  86. package/lib/esm/actions/midnight/index.js +3 -3
  87. package/lib/esm/actions/midnight/repayWithdrawCollateral.d.ts +40 -23
  88. package/lib/esm/actions/midnight/repayWithdrawCollateral.js +108 -72
  89. package/lib/esm/actions/midnight/supplyCollateralTakeBorrow.d.ts +52 -27
  90. package/lib/esm/actions/midnight/supplyCollateralTakeBorrow.js +131 -74
  91. package/lib/esm/actions/midnight/takeBorrow.d.ts +40 -28
  92. package/lib/esm/actions/midnight/takeBorrow.js +98 -57
  93. package/lib/esm/actions/midnight/takeLend.d.ts +51 -27
  94. package/lib/esm/actions/midnight/takeLend.js +114 -57
  95. package/lib/esm/actions/midnight/takeRepayWithdrawCollateral.d.ts +97 -0
  96. package/lib/esm/actions/midnight/takeRepayWithdrawCollateral.js +197 -0
  97. package/lib/esm/actions/midnight/takeWithdraw.d.ts +69 -0
  98. package/lib/esm/actions/midnight/takeWithdraw.js +149 -0
  99. package/lib/esm/actions/midnight/types.d.ts +7 -26
  100. package/lib/esm/actions/midnight/types.js +1 -12
  101. package/lib/esm/actions/requirements/encode/encodeErc20Approval.d.ts +2 -1
  102. package/lib/esm/actions/requirements/encode/encodeErc20Approval.js +3 -2
  103. package/lib/esm/actions/requirements/encode/encodeErc20Permit.d.ts +4 -4
  104. package/lib/esm/actions/requirements/encode/encodeErc20Permit.js +5 -5
  105. package/lib/esm/actions/requirements/getRequirementsApproval.d.ts +2 -2
  106. package/lib/esm/actions/requirements/getRequirementsApproval.js +2 -2
  107. package/lib/esm/actions/requirements/midnight/getMidnightApprovalRequirements.d.ts +24 -8
  108. package/lib/esm/actions/requirements/midnight/getMidnightApprovalRequirements.js +25 -14
  109. package/lib/esm/actions/requirements/midnight/getMidnightAuthorizationRequirement.d.ts +11 -7
  110. package/lib/esm/actions/requirements/midnight/getMidnightAuthorizationRequirement.js +11 -7
  111. package/lib/esm/actions/requirements/midnight/index.d.ts +0 -1
  112. package/lib/esm/actions/requirements/midnight/index.js +0 -1
  113. package/lib/esm/constants.d.ts +1 -1
  114. package/lib/esm/constants.js +1 -1
  115. package/lib/esm/entities/blue/blue.d.ts +10 -6
  116. package/lib/esm/entities/blue/blue.js +5 -3
  117. package/lib/esm/entities/index.d.ts +2 -2
  118. package/lib/esm/entities/midnight/midnight.d.ts +582 -108
  119. package/lib/esm/entities/midnight/midnight.js +987 -515
  120. package/lib/esm/entities/midnight/types.d.ts +142 -60
  121. package/lib/esm/entities/vaultV1/vaultV1.d.ts +2 -1
  122. package/lib/esm/entities/vaultV1/vaultV1.js +1 -0
  123. package/lib/esm/entities/vaultV2/vaultV2.d.ts +2 -1
  124. package/lib/esm/entities/vaultV2/vaultV2.js +1 -0
  125. package/lib/esm/entities/vaultV2BlueReallocationData.d.ts +11 -3
  126. package/lib/esm/entities/vaultV2BlueReallocationData.js +120 -44
  127. package/lib/esm/helpers/callback.d.ts +54 -0
  128. package/lib/esm/helpers/callback.js +68 -0
  129. package/lib/esm/helpers/constant.d.ts +10 -0
  130. package/lib/esm/helpers/constant.js +10 -0
  131. package/lib/esm/helpers/index.d.ts +3 -2
  132. package/lib/esm/helpers/index.js +3 -2
  133. package/lib/esm/helpers/signAndVerifyTypedData.d.ts +3 -3
  134. package/lib/esm/helpers/signAndVerifyTypedData.js +3 -3
  135. package/lib/esm/helpers/utilization.d.ts +13 -0
  136. package/lib/esm/helpers/utilization.js +25 -1
  137. package/lib/esm/helpers/validate.d.ts +43 -2
  138. package/lib/esm/helpers/validate.js +58 -2
  139. package/lib/esm/helpers/validateMidnightAuthorizationTarget.d.ts +1 -1
  140. package/lib/esm/helpers/validateMidnightAuthorizationTarget.js +3 -7
  141. package/lib/esm/helpers/validateRequirementSpender.d.ts +3 -3
  142. package/lib/esm/helpers/validateRequirementSpender.js +4 -5
  143. package/lib/esm/midnight/abis.d.ts +1 -1
  144. package/lib/esm/midnight/abis.js +1 -1
  145. package/lib/esm/midnight/types.d.ts +1 -1
  146. package/lib/esm/types/action.d.ts +117 -89
  147. package/lib/esm/types/action.js +1 -18
  148. package/lib/esm/types/error.d.ts +126 -40
  149. package/lib/esm/types/error.js +135 -38
  150. package/lib/esm/types/sharedLiquidity.d.ts +17 -0
  151. package/package.json +9 -8
  152. package/lib/cjs/actions/midnight/cancelOffer.d.ts +0 -38
  153. package/lib/cjs/actions/midnight/cancelOffer.js +0 -73
  154. package/lib/cjs/actions/midnight/mempoolSubmitOffers.d.ts +0 -52
  155. package/lib/cjs/actions/midnight/mempoolSubmitOffers.js +0 -72
  156. package/lib/cjs/actions/midnight/setterRatifierRatifyRoot.d.ts +0 -40
  157. package/lib/cjs/actions/midnight/setterRatifierRatifyRoot.js +0 -59
  158. package/lib/cjs/actions/requirements/midnight/getSetterRatifierRatifyRootRequirement.d.ts +0 -42
  159. package/lib/cjs/actions/requirements/midnight/getSetterRatifierRatifyRootRequirement.js +0 -70
  160. package/lib/esm/actions/midnight/cancelOffer.d.ts +0 -38
  161. package/lib/esm/actions/midnight/cancelOffer.js +0 -69
  162. package/lib/esm/actions/midnight/mempoolSubmitOffers.d.ts +0 -52
  163. package/lib/esm/actions/midnight/mempoolSubmitOffers.js +0 -68
  164. package/lib/esm/actions/midnight/setterRatifierRatifyRoot.d.ts +0 -40
  165. package/lib/esm/actions/midnight/setterRatifierRatifyRoot.js +0 -55
  166. package/lib/esm/actions/requirements/midnight/getSetterRatifierRatifyRootRequirement.d.ts +0 -42
  167. package/lib/esm/actions/requirements/midnight/getSetterRatifierRatifyRootRequirement.js +0 -66
@@ -5,100 +5,137 @@ const midnight_sdk_1 = require("@morpho-org/midnight-sdk");
5
5
  const morpho_ts_1 = require("@morpho-org/morpho-ts");
6
6
  const viem_1 = require("viem");
7
7
  const index_js_1 = require("../../helpers/index.js");
8
+ const validate_js_1 = require("../../helpers/validate.js");
8
9
  const validateMidnightMarket_js_1 = require("../../helpers/validateMidnightMarket.js");
9
10
  const index_js_2 = require("../../types/index.js");
10
- const types_js_1 = require("./types.js");
11
11
  /**
12
- * Encodes a Midnight bundle that repays debt, withdraws collateral, or both.
12
+ * Encodes a reduce-only `MidnightBundlesV2` buy with no offers, so the sender's debt is repaid
13
+ * directly, then collateral is withdrawn to `collateralReceiver`. An `assets` repay uses the
14
+ * assets-target entrypoint with `minUnits = assets` (a direct repay counts one unit per asset); a
15
+ * `full` repay uses the units-target entrypoint with `targetUnits = maxUint256`.
13
16
  *
14
- * Prefer `client.morpho.midnight(chainId).repayWithdrawCollateral(...)` in app
15
- * flows so loan-token approval and Midnight authorization requirements are
16
- * resolved first. Use this low-level builder only when those requirements and
17
- * collateral-index checks are already handled by the caller.
17
+ * Prefer `client.morpho.midnight(chainId).repayWithdrawCollateral(...)` in app flows so the
18
+ * loan-token approval and Midnight authorization requirements are resolved first.
18
19
  *
19
- * @param params.chainId - Chain id used to resolve `MidnightBundles`.
20
+ * @param params.chainId - Chain id used to resolve `MidnightBundlesV2`.
20
21
  * @param params.market - Midnight market whose position is updated.
21
- * @param params.repayAssets - Loan assets repaid; may be zero when only withdrawing collateral.
22
- * @param params.withdrawCollateralAssets - Collateral assets withdrawn; may be zero when only repaying.
23
- * @param params.onBehalf - Position owner.
24
- * @param params.collateralIndex - Optional collateral index for withdrawal; defaults to `0n`.
22
+ * @param params.repay - `{ type: "assets", assets }` (`0n` to only withdraw) or `{ type: "full", maxBuyerAssets }`.
23
+ * @param params.nativeAmount - Optional native ETH sent as `value`; the bundle wraps it into the
24
+ * chain's wNative and transfers it to `msg.sender` before pulling. It may cover part or all of the
25
+ * maximum wNative amount this call can pull, but not more. Any wrapped native not pulled stays in
26
+ * the sender's wallet as wNative. The wNative approval to `MidnightBundlesV2` is still required
27
+ * for the full pulled amount.
28
+ * @param params.collateralWithdrawals - Collateral withdrawals; `assets: maxUint256` withdraws the full balance.
29
+ * @param params.collateralReceiver - Recipient of the withdrawn collateral.
25
30
  * @param params.deadline - Bundle execution deadline timestamp; pass `maxUint256` explicitly for no expiry.
26
31
  * @param params.metadata - Optional analytics metadata appended to calldata.
27
- * @returns A deep-frozen `Transaction<MidnightRepayWithdrawCollateralAction>` targeting `MidnightBundles`.
28
- * @throws {NegativeInputError} when any amount, collateral index, or deadline is negative.
29
- * @throws {NonPositiveInputError} when both repay and withdrawal amounts are zero.
32
+ * @returns A deep-frozen `Transaction<MidnightRepayWithdrawCollateralAction>` targeting `MidnightBundlesV2`.
33
+ * @throws {NegativeInputError} when `repay.assets` or `nativeAmount` is negative.
34
+ * @throws {NonPositiveInputError} when nothing is repaid or withdrawn, a withdrawal amount is zero, `repay.maxBuyerAssets` is zero, or `deadline` is not positive.
35
+ * @throws {InputExceedsMaxError} when `repay.assets` or `repay.maxBuyerAssets` is at least `maxUint256`, a withdrawal amount or `deadline` exceeds uint256, or `nativeAmount` exceeds the maximum wNative pull, including zero for a withdraw-only call.
36
+ * @throws {ChainWNativeMissingError} when wNative is not configured for the chain.
37
+ * @throws {NativeAmountOnNonWNativeAssetError} when `market.loanToken` is not wNative.
38
+ * @throws {UnknownAddressError} when the chain has no `midnightBundlesV2` deployment.
30
39
  * @throws {ChainIdMismatchError} when the market targets another chain.
31
40
  * @throws {MidnightMarketAddressMismatchError} when the market targets another Midnight deployment.
32
- * @throws {UnknownCollateralIndexError} when a positive withdrawal targets an unconfigured collateral index.
41
+ * @throws {UnknownCollateralIndexError} when a withdrawal targets an unconfigured collateral index.
33
42
  * @example
34
43
  * ```ts
35
44
  * import { maxUint256 } from "viem";
36
45
  * import { midnightRepayWithdrawCollateral } from "@morpho-org/morpho-sdk";
37
46
  *
47
+ * // Close the position: repay all debt, then withdraw all collateral at index 0.
38
48
  * const tx = midnightRepayWithdrawCollateral({
39
49
  * chainId: 8453,
40
50
  * market: marketData.params,
41
- * repayAssets: 1_000_000n,
42
- * withdrawCollateralAssets: 0n,
43
- * onBehalf: user,
51
+ * repay: { type: "full", maxBuyerAssets: 1_010_000n },
52
+ * collateralWithdrawals: [{ collateralIndex: 0n, assets: maxUint256 }],
53
+ * collateralReceiver: user,
44
54
  * deadline: maxUint256,
45
55
  * });
46
56
  * ```
47
57
  */
48
58
  const midnightRepayWithdrawCollateral = (params) => {
49
- if (params.repayAssets < 0n) {
50
- throw new index_js_2.NegativeInputError("repayAssets", params.repayAssets);
51
- }
52
- if (params.withdrawCollateralAssets < 0n) {
53
- throw new index_js_2.NegativeInputError("withdrawCollateralAssets", params.withdrawCollateralAssets);
59
+ const { repay } = params;
60
+ if (repay.type === "assets" &&
61
+ repay.assets === 0n &&
62
+ params.collateralWithdrawals.length === 0) {
63
+ throw new index_js_2.NonPositiveInputError("repay or withdraw amount", 0n);
54
64
  }
55
- if (params.deadline < 0n) {
56
- throw new index_js_2.NegativeInputError("deadline", params.deadline);
65
+ if (repay.type === "full") {
66
+ if (repay.maxBuyerAssets <= 0n) {
67
+ throw new index_js_2.NonPositiveInputError("repay.maxBuyerAssets", repay.maxBuyerAssets);
68
+ }
69
+ if (repay.maxBuyerAssets >= viem_1.maxUint256) {
70
+ throw new index_js_2.InputExceedsMaxError({
71
+ field: "repay.maxBuyerAssets",
72
+ value: repay.maxBuyerAssets,
73
+ max: viem_1.maxUint256 - 1n,
74
+ });
75
+ }
57
76
  }
58
- const collateralWithdrawals = params.withdrawCollateralAssets > 0n
59
- ? [
60
- {
61
- collateralIndex: params.collateralIndex ?? 0n,
62
- assets: params.withdrawCollateralAssets,
63
- },
64
- ]
65
- : [];
66
- for (const [index, withdrawal] of collateralWithdrawals.entries()) {
67
- if (withdrawal.collateralIndex < 0n) {
68
- throw new index_js_2.NegativeInputError(`collateralWithdrawals[${index}].collateralIndex`, withdrawal.collateralIndex);
77
+ (0, validateMidnightMarket_js_1.validateMidnightMarket)({ market: params.market, chainId: params.chainId });
78
+ for (const [index, { collateralIndex, assets },] of params.collateralWithdrawals.entries()) {
79
+ if (assets <= 0n) {
80
+ throw new index_js_2.NonPositiveInputError(`collateralWithdrawals[${index}].assets`, assets);
69
81
  }
82
+ (0, validate_js_1.validateUint256Field)(`collateralWithdrawals[${index}].assets`, assets);
83
+ // Throws UnknownCollateralIndexError when the index is not configured on the market.
84
+ midnight_sdk_1.MarketUtils.getCollateralByIndex(params.market, collateralIndex);
70
85
  }
71
- if (params.repayAssets === 0n &&
72
- collateralWithdrawals.every((withdrawal) => withdrawal.assets === 0n)) {
73
- throw new index_js_2.NonPositiveInputError("repay or withdraw amount", 0n);
86
+ if (repay.type === "assets") {
87
+ (0, validate_js_1.validateUint256Field)("repay.assets", repay.assets);
88
+ // An assets repay has no "whole debt" sentinel; use `{ type: "full" }` for that.
89
+ if (repay.assets === viem_1.maxUint256) {
90
+ throw new index_js_2.InputExceedsMaxError({
91
+ field: "repay.assets",
92
+ value: repay.assets,
93
+ max: viem_1.maxUint256 - 1n,
94
+ });
95
+ }
74
96
  }
75
- // Reject markets from another chain deployment before encoding the bundle.
76
- (0, validateMidnightMarket_js_1.validateMidnightMarket)({ market: params.market, chainId: params.chainId });
77
- const marketId = midnight_sdk_1.MarketUtils.toId(params.market);
97
+ (0, validate_js_1.validateDeadline)(params.deadline);
78
98
  const market = midnight_sdk_1.MarketUtils.toStruct(params.market);
79
- for (const withdrawal of collateralWithdrawals) {
80
- // Validate that every withdrawal targets a configured collateral.
81
- midnight_sdk_1.MarketUtils.getCollateralByIndex(market, withdrawal.collateralIndex);
82
- }
83
- const midnightBundles = (0, morpho_ts_1.getChainAddress)(params.chainId, "midnightBundles");
99
+ const nativeFunding = (0, validate_js_1.validateMidnightNativeAmount)({
100
+ chainId: params.chainId,
101
+ nativeAmount: params.nativeAmount,
102
+ pulls: [
103
+ {
104
+ token: market.loanToken,
105
+ assets: repay.type === "assets" ? repay.assets : repay.maxBuyerAssets,
106
+ },
107
+ ],
108
+ });
109
+ const args = [
110
+ true, // reduceOnly
111
+ true, // repayEnabled
112
+ [], // offerFills
113
+ params.collateralWithdrawals.map(({ collateralIndex, assets }) => ({
114
+ collateralIndex,
115
+ assets,
116
+ })), // collateralWithdrawals
117
+ params.collateralReceiver, // collateralReceiver
118
+ 0n, // referralFeePct
119
+ viem_1.zeroAddress, // referralFeeRecipient
120
+ // MidnightBundlesV2 checks maxContinuousFee only per offer fill; there are none here.
121
+ 0n, // maxContinuousFee
122
+ params.deadline, // deadline
123
+ nativeFunding.wrappedNative, // wrappedNative
124
+ ];
84
125
  let tx = {
85
- to: midnightBundles,
86
- value: 0n,
87
- data: (0, viem_1.encodeFunctionData)({
88
- abi: midnight_sdk_1.midnightBundlesAbi,
89
- functionName: "midnightBundlesV1RepayAndWithdrawCollateral",
90
- args: [
91
- market,
92
- params.repayAssets,
93
- params.onBehalf,
94
- { kind: types_js_1.PermitKind.None, data: "0x" },
95
- collateralWithdrawals,
96
- params.onBehalf,
97
- 0n,
98
- viem_1.zeroAddress,
99
- params.deadline,
100
- ],
101
- }),
126
+ to: (0, morpho_ts_1.getChainAddress)(params.chainId, "midnightBundlesV2"),
127
+ value: nativeFunding.value,
128
+ data: repay.type === "assets"
129
+ ? (0, viem_1.encodeFunctionData)({
130
+ abi: midnight_sdk_1.midnightBundlesV2Abi,
131
+ functionName: "midnightBundlesV2BuyWithAssetsTargetAndWithdrawCollateral",
132
+ args: [market, repay.assets, repay.assets, ...args],
133
+ })
134
+ : (0, viem_1.encodeFunctionData)({
135
+ abi: midnight_sdk_1.midnightBundlesV2Abi,
136
+ functionName: "midnightBundlesV2BuyWithUnitsTargetAndWithdrawCollateral",
137
+ args: [market, viem_1.maxUint256, repay.maxBuyerAssets, ...args],
138
+ }),
102
139
  };
103
140
  if (params.metadata) {
104
141
  tx = (0, index_js_1.addTransactionMetadata)(tx, params.metadata);
@@ -108,11 +145,10 @@ const midnightRepayWithdrawCollateral = (params) => {
108
145
  action: {
109
146
  type: "midnightRepayWithdrawCollateral",
110
147
  args: {
111
- market: marketId,
112
- repayAssets: params.repayAssets,
113
- collateralWithdrawals: collateralWithdrawals.length,
114
- onBehalf: params.onBehalf,
115
- collateralReceiver: params.onBehalf,
148
+ market: midnight_sdk_1.MarketUtils.toId(params.market),
149
+ repay: { ...repay },
150
+ collateralWithdrawals: params.collateralWithdrawals.map(({ collateralIndex, assets }) => ({ collateralIndex, assets })),
151
+ collateralReceiver: params.collateralReceiver,
116
152
  deadline: params.deadline,
117
153
  },
118
154
  },
@@ -1,50 +1,75 @@
1
- import { type MidnightSupplyCollateralTakeBorrowAction, type Transaction } from "../../types/index.js";
1
+ import { type MidnightCollateralTransfer, type MidnightSupplyCollateralTakeBorrowAction, type Transaction } from "../../types/index.js";
2
2
  import type { MidnightTakeBorrowParams } from "./takeBorrow.js";
3
3
  /** Parameters for encoding a collateral supply followed by a Midnight borrow take. */
4
4
  export interface MidnightSupplyCollateralTakeBorrowParams extends MidnightTakeBorrowParams {
5
- readonly collateralAssets: bigint;
6
- readonly collateralIndex?: bigint;
5
+ /** Collateral pulled from `msg.sender` and supplied before taking offers; must not be empty. */
6
+ readonly collateralSupplies: readonly MidnightCollateralTransfer[];
7
+ /**
8
+ * Optional native ETH sent as `value`; the bundle wraps it into the chain's wNative and transfers
9
+ * it to `msg.sender` before pulling. It may cover part or all of the maximum wNative amount this
10
+ * call can pull, but not more. Any wrapped native not pulled stays in the sender's wallet as
11
+ * wNative. The wNative approval to `MidnightBundlesV2` is still required for the full pulled amount.
12
+ */
13
+ readonly nativeAmount?: bigint;
7
14
  }
8
15
  /**
9
- * Encodes a Midnight bundle that supplies collateral and borrows in one call.
16
+ * Encodes a `MidnightBundlesV2` sell that supplies collateral and borrows from lend-side offers
17
+ * for `msg.sender` in one call.
10
18
  *
11
- * Prefer `client.morpho.midnight(chainId).supplyCollateralTakeBorrow(...)` in
12
- * app flows so collateral approval and Midnight authorization requirements are
13
- * resolved before building the bundle. Use this low-level builder only after
14
- * market data and API takeable offers are already available.
19
+ * Like `midnightTakeBorrow`, the sender's existing credit is withdrawn before offers are taken.
20
+ * Prefer `client.morpho.midnight(chainId).supplyCollateralTakeBorrow(...)` in app flows so
21
+ * collateral approvals and the `MidnightBundlesV2` authorization are resolved first.
15
22
  *
16
- * @param params.chainId - Chain id used to resolve `MidnightBundles`.
23
+ * @param params.chainId - Chain id used to resolve `MidnightBundlesV2`.
17
24
  * @param params.market - Midnight market traded by every takeable offer.
18
- * @param params.loanAssets - Loan assets the borrower receives.
19
- * @param params.maxUnits - Maximum debt units accepted from the bundle quote.
20
- * @param params.taker - Borrower address executing the bundle.
21
- * @param params.deadline - Bundle execution deadline timestamp; pass `maxUint256` explicitly for no expiry.
25
+ * @param params.target - `{ type: "assets", assets, maxUnits }` or `{ type: "units", units, minSellerAssets }`.
26
+ * @param params.receiver - Recipient of the borrowed loan assets.
27
+ * @param params.collateralSupplies - Collateral index and assets per supply; must not be empty.
28
+ * @param params.nativeAmount - Optional native ETH sent as `value`; the bundle wraps it into the
29
+ * chain's wNative and transfers it to `msg.sender` before pulling. It may cover part or all of the
30
+ * maximum wNative amount this call can pull, but not more. Any wrapped native not pulled stays in
31
+ * the sender's wallet as wNative. The wNative approval to `MidnightBundlesV2` is still required
32
+ * for the full pulled amount.
22
33
  * @param params.takeableOffers - ABI-ready lend-side offers returned by the Midnight API.
23
- * @param params.collateralAssets - Collateral assets supplied before taking offers.
24
- * @param params.collateralIndex - Optional collateral index; defaults to `0n`.
25
- * @returns A deep-frozen `Transaction<MidnightSupplyCollateralTakeBorrowAction>` targeting `MidnightBundles`.
26
- * @throws {NonPositiveInputError} when collateral assets, loan assets, or `maxUnits` are non-positive.
27
- * @throws {NegativeInputError} when `deadline` is negative.
34
+ * @param params.deadline - Bounded bundle execution deadline timestamp.
35
+ * @param params.referralFeePct - Optional WAD-scaled referral fee taken from the received assets.
36
+ * @param params.referralFeeRecipient - Referral fee recipient; required with a positive fee.
37
+ * @param params.metadata - Optional analytics metadata appended to calldata.
38
+ * @returns A deep-frozen `Transaction<MidnightSupplyCollateralTakeBorrowAction>` targeting `MidnightBundlesV2`.
39
+ * @throws {UnsupportedChainIdError} when the chain is absent from the address registry.
40
+ * @throws {UnknownAddressError} when the chain has no `midnightBundlesV2` deployment.
41
+ * @throws {ChainIdMismatchError} when the market targets another chain.
42
+ * @throws {MidnightMarketAddressMismatchError} when the market targets another Midnight deployment.
43
+ * @throws {EmptyMidnightCollateralSuppliesError} when no collateral supply is provided.
44
+ * @throws {UnknownCollateralIndexError} when a collateral index is not configured on the market.
28
45
  * @throws {EmptyMidnightTakeableOffersError} when no offers are provided.
29
46
  * @throws {MidnightOfferSideMismatchError} when any offer is not lend-side.
30
47
  * @throws {MidnightTakeableOfferMarketMismatchError} when any offer belongs to another market.
31
- * @throws {ChainIdMismatchError} when the market targets another chain.
32
- * @throws {MidnightMarketAddressMismatchError} when the market targets another Midnight deployment.
33
- * @throws {UnknownCollateralIndexError} when `collateralIndex` is not configured on the market.
48
+ * @throws {NonPositiveInputError} when a supply amount, the target amount, `maxUnits`, `minSellerAssets` or `deadline` is not positive.
49
+ * @throws {NegativeInputError} when `referralFeePct` or `nativeAmount` is negative.
50
+ * @throws {InputExceedsMaxError} when a `collateralSupplies[].assets` amount, `target.assets`,
51
+ * `target.maxUnits`, `target.units`, `target.minSellerAssets` or `deadline` exceeds `uint256`, or
52
+ * `nativeAmount` exceeds the maximum wNative collateral amount this call can pull.
53
+ * @throws {ChainWNativeMissingError} when wNative is not configured for the chain.
54
+ * @throws {NativeAmountOnNonWNativeAssetError} when no collateral pull uses wNative.
55
+ * @throws {UnboundedMidnightTakeInputError} when `target.units`, `target.maxUnits` or
56
+ * `deadline` is `maxUint256`.
57
+ * @throws {MidnightZeroReceiverError} when `receiver` is the zero address.
58
+ * @throws {ReferralFeePctExceededError} when `referralFeePct` is not below WAD.
59
+ * @throws {ReferralFeeRecipientMissingError} when a positive referral fee has no recipient.
34
60
  * @example
35
61
  * ```ts
36
- * import { maxUint256 } from "viem";
62
+ * import { Time } from "@morpho-org/morpho-ts";
37
63
  * import { midnightSupplyCollateralTakeBorrow } from "@morpho-org/morpho-sdk";
38
64
  *
39
65
  * const tx = midnightSupplyCollateralTakeBorrow({
40
66
  * chainId: 8453,
41
67
  * market: marketData.params,
42
- * collateralAssets: 2_000_000n,
43
- * loanAssets: 1_000_000n,
44
- * maxUnits: 1_100_000n,
45
- * taker: borrower,
68
+ * target: { type: "assets", assets: 1_000_000n, maxUnits: 1_100_000n },
69
+ * receiver: borrower,
70
+ * collateralSupplies: [{ collateralIndex: 0n, assets: 2_000_000n }],
46
71
  * takeableOffers: quote.data.takeableOffers,
47
- * deadline: maxUint256,
72
+ * deadline: Time.timestamp() + 600n,
48
73
  * });
49
74
  * ```
50
75
  */
@@ -5,104 +5,162 @@ const midnight_sdk_1 = require("@morpho-org/midnight-sdk");
5
5
  const morpho_ts_1 = require("@morpho-org/morpho-ts");
6
6
  const viem_1 = require("viem");
7
7
  const index_js_1 = require("../../helpers/index.js");
8
+ const validate_js_1 = require("../../helpers/validate.js");
8
9
  const validateMidnightMarket_js_1 = require("../../helpers/validateMidnightMarket.js");
9
10
  const validateTakeableOffers_js_1 = require("../../helpers/validateTakeableOffers.js");
10
11
  const index_js_2 = require("../../types/index.js");
11
- const types_js_1 = require("./types.js");
12
12
  /**
13
- * Encodes a Midnight bundle that supplies collateral and borrows in one call.
13
+ * Encodes a `MidnightBundlesV2` sell that supplies collateral and borrows from lend-side offers
14
+ * for `msg.sender` in one call.
14
15
  *
15
- * Prefer `client.morpho.midnight(chainId).supplyCollateralTakeBorrow(...)` in
16
- * app flows so collateral approval and Midnight authorization requirements are
17
- * resolved before building the bundle. Use this low-level builder only after
18
- * market data and API takeable offers are already available.
16
+ * Like `midnightTakeBorrow`, the sender's existing credit is withdrawn before offers are taken.
17
+ * Prefer `client.morpho.midnight(chainId).supplyCollateralTakeBorrow(...)` in app flows so
18
+ * collateral approvals and the `MidnightBundlesV2` authorization are resolved first.
19
19
  *
20
- * @param params.chainId - Chain id used to resolve `MidnightBundles`.
20
+ * @param params.chainId - Chain id used to resolve `MidnightBundlesV2`.
21
21
  * @param params.market - Midnight market traded by every takeable offer.
22
- * @param params.loanAssets - Loan assets the borrower receives.
23
- * @param params.maxUnits - Maximum debt units accepted from the bundle quote.
24
- * @param params.taker - Borrower address executing the bundle.
25
- * @param params.deadline - Bundle execution deadline timestamp; pass `maxUint256` explicitly for no expiry.
22
+ * @param params.target - `{ type: "assets", assets, maxUnits }` or `{ type: "units", units, minSellerAssets }`.
23
+ * @param params.receiver - Recipient of the borrowed loan assets.
24
+ * @param params.collateralSupplies - Collateral index and assets per supply; must not be empty.
25
+ * @param params.nativeAmount - Optional native ETH sent as `value`; the bundle wraps it into the
26
+ * chain's wNative and transfers it to `msg.sender` before pulling. It may cover part or all of the
27
+ * maximum wNative amount this call can pull, but not more. Any wrapped native not pulled stays in
28
+ * the sender's wallet as wNative. The wNative approval to `MidnightBundlesV2` is still required
29
+ * for the full pulled amount.
26
30
  * @param params.takeableOffers - ABI-ready lend-side offers returned by the Midnight API.
27
- * @param params.collateralAssets - Collateral assets supplied before taking offers.
28
- * @param params.collateralIndex - Optional collateral index; defaults to `0n`.
29
- * @returns A deep-frozen `Transaction<MidnightSupplyCollateralTakeBorrowAction>` targeting `MidnightBundles`.
30
- * @throws {NonPositiveInputError} when collateral assets, loan assets, or `maxUnits` are non-positive.
31
- * @throws {NegativeInputError} when `deadline` is negative.
31
+ * @param params.deadline - Bounded bundle execution deadline timestamp.
32
+ * @param params.referralFeePct - Optional WAD-scaled referral fee taken from the received assets.
33
+ * @param params.referralFeeRecipient - Referral fee recipient; required with a positive fee.
34
+ * @param params.metadata - Optional analytics metadata appended to calldata.
35
+ * @returns A deep-frozen `Transaction<MidnightSupplyCollateralTakeBorrowAction>` targeting `MidnightBundlesV2`.
36
+ * @throws {UnsupportedChainIdError} when the chain is absent from the address registry.
37
+ * @throws {UnknownAddressError} when the chain has no `midnightBundlesV2` deployment.
38
+ * @throws {ChainIdMismatchError} when the market targets another chain.
39
+ * @throws {MidnightMarketAddressMismatchError} when the market targets another Midnight deployment.
40
+ * @throws {EmptyMidnightCollateralSuppliesError} when no collateral supply is provided.
41
+ * @throws {UnknownCollateralIndexError} when a collateral index is not configured on the market.
32
42
  * @throws {EmptyMidnightTakeableOffersError} when no offers are provided.
33
43
  * @throws {MidnightOfferSideMismatchError} when any offer is not lend-side.
34
44
  * @throws {MidnightTakeableOfferMarketMismatchError} when any offer belongs to another market.
35
- * @throws {ChainIdMismatchError} when the market targets another chain.
36
- * @throws {MidnightMarketAddressMismatchError} when the market targets another Midnight deployment.
37
- * @throws {UnknownCollateralIndexError} when `collateralIndex` is not configured on the market.
45
+ * @throws {NonPositiveInputError} when a supply amount, the target amount, `maxUnits`, `minSellerAssets` or `deadline` is not positive.
46
+ * @throws {NegativeInputError} when `referralFeePct` or `nativeAmount` is negative.
47
+ * @throws {InputExceedsMaxError} when a `collateralSupplies[].assets` amount, `target.assets`,
48
+ * `target.maxUnits`, `target.units`, `target.minSellerAssets` or `deadline` exceeds `uint256`, or
49
+ * `nativeAmount` exceeds the maximum wNative collateral amount this call can pull.
50
+ * @throws {ChainWNativeMissingError} when wNative is not configured for the chain.
51
+ * @throws {NativeAmountOnNonWNativeAssetError} when no collateral pull uses wNative.
52
+ * @throws {UnboundedMidnightTakeInputError} when `target.units`, `target.maxUnits` or
53
+ * `deadline` is `maxUint256`.
54
+ * @throws {MidnightZeroReceiverError} when `receiver` is the zero address.
55
+ * @throws {ReferralFeePctExceededError} when `referralFeePct` is not below WAD.
56
+ * @throws {ReferralFeeRecipientMissingError} when a positive referral fee has no recipient.
38
57
  * @example
39
58
  * ```ts
40
- * import { maxUint256 } from "viem";
59
+ * import { Time } from "@morpho-org/morpho-ts";
41
60
  * import { midnightSupplyCollateralTakeBorrow } from "@morpho-org/morpho-sdk";
42
61
  *
43
62
  * const tx = midnightSupplyCollateralTakeBorrow({
44
63
  * chainId: 8453,
45
64
  * market: marketData.params,
46
- * collateralAssets: 2_000_000n,
47
- * loanAssets: 1_000_000n,
48
- * maxUnits: 1_100_000n,
49
- * taker: borrower,
65
+ * target: { type: "assets", assets: 1_000_000n, maxUnits: 1_100_000n },
66
+ * receiver: borrower,
67
+ * collateralSupplies: [{ collateralIndex: 0n, assets: 2_000_000n }],
50
68
  * takeableOffers: quote.data.takeableOffers,
51
- * deadline: maxUint256,
69
+ * deadline: Time.timestamp() + 600n,
52
70
  * });
53
71
  * ```
54
72
  */
55
73
  const midnightSupplyCollateralTakeBorrow = (params) => {
56
- if (params.collateralAssets <= 0n) {
57
- throw new index_js_2.NonPositiveInputError("collateralAssets", params.collateralAssets);
58
- }
59
- if (params.loanAssets <= 0n) {
60
- throw new index_js_2.NonPositiveInputError("loanAssets", params.loanAssets);
61
- }
62
- if (params.maxUnits <= 0n) {
63
- throw new index_js_2.NonPositiveInputError("maxUnits", params.maxUnits);
74
+ // Reject markets from another chain deployment before checking offers against them.
75
+ (0, validateMidnightMarket_js_1.validateMidnightMarket)({ market: params.market, chainId: params.chainId });
76
+ if (params.collateralSupplies.length === 0) {
77
+ throw new index_js_2.EmptyMidnightCollateralSuppliesError();
64
78
  }
65
- if (params.deadline < 0n) {
66
- throw new index_js_2.NegativeInputError("deadline", params.deadline);
79
+ for (const [index, { collateralIndex, assets },] of params.collateralSupplies.entries()) {
80
+ if (assets <= 0n) {
81
+ throw new index_js_2.NonPositiveInputError(`collateralSupplies[${index}].assets`, assets);
82
+ }
83
+ (0, validate_js_1.validateUint256Field)(`collateralSupplies[${index}].assets`, assets);
84
+ // Throws UnknownCollateralIndexError when the index is not configured on the market.
85
+ midnight_sdk_1.MarketUtils.getCollateralByIndex(params.market, collateralIndex);
67
86
  }
68
- // Reject markets from another chain deployment before encoding the bundle.
69
- (0, validateMidnightMarket_js_1.validateMidnightMarket)({ market: params.market, chainId: params.chainId });
70
87
  const marketId = (0, validateTakeableOffers_js_1.validateTakeableOffers)({
71
88
  market: params.market,
72
89
  takeableOffers: params.takeableOffers,
73
90
  expectedBuy: true,
74
91
  });
75
- const midnightBundles = (0, morpho_ts_1.getChainAddress)(params.chainId, "midnightBundles");
76
- const collateralIndex = params.collateralIndex ?? 0n;
77
- // Validate that the collateral index is configured before encoding the bundle.
78
- midnight_sdk_1.MarketUtils.getCollateralByIndex(params.market, collateralIndex);
79
- const collateralSupplies = [
80
- {
92
+ if ((0, viem_1.isAddressEqual)(params.receiver, viem_1.zeroAddress)) {
93
+ throw new index_js_2.MidnightZeroReceiverError("receiver");
94
+ }
95
+ const { target } = params;
96
+ if (target.type === "assets") {
97
+ if (target.assets <= 0n) {
98
+ throw new index_js_2.NonPositiveInputError("target.assets", target.assets);
99
+ }
100
+ if (target.maxUnits === viem_1.maxUint256) {
101
+ throw new index_js_2.UnboundedMidnightTakeInputError("target.maxUnits");
102
+ }
103
+ if (target.maxUnits <= 0n) {
104
+ throw new index_js_2.NonPositiveInputError("target.maxUnits", target.maxUnits);
105
+ }
106
+ (0, validate_js_1.validateUint256Field)("target.assets", target.assets);
107
+ (0, validate_js_1.validateUint256Field)("target.maxUnits", target.maxUnits);
108
+ }
109
+ else {
110
+ if (target.units === viem_1.maxUint256) {
111
+ throw new index_js_2.UnboundedMidnightTakeInputError("target.units");
112
+ }
113
+ if (target.units <= 0n) {
114
+ throw new index_js_2.NonPositiveInputError("target.units", target.units);
115
+ }
116
+ if (target.minSellerAssets <= 0n) {
117
+ throw new index_js_2.NonPositiveInputError("target.minSellerAssets", target.minSellerAssets);
118
+ }
119
+ (0, validate_js_1.validateUint256Field)("target.units", target.units);
120
+ (0, validate_js_1.validateUint256Field)("target.minSellerAssets", target.minSellerAssets);
121
+ }
122
+ if (params.deadline === viem_1.maxUint256) {
123
+ throw new index_js_2.UnboundedMidnightTakeInputError("deadline");
124
+ }
125
+ (0, validate_js_1.validateDeadline)(params.deadline);
126
+ const { referralFeePct, referralFeeRecipient } = (0, validate_js_1.validateReferralFee)(params);
127
+ const nativeFunding = (0, validate_js_1.validateMidnightNativeAmount)({
128
+ chainId: params.chainId,
129
+ nativeAmount: params.nativeAmount,
130
+ pulls: params.collateralSupplies.map(({ collateralIndex, assets }) => ({
131
+ token: midnight_sdk_1.MarketUtils.getCollateralByIndex(params.market, collateralIndex)
132
+ .token,
133
+ assets,
134
+ })),
135
+ });
136
+ const market = midnight_sdk_1.MarketUtils.toStruct(params.market);
137
+ const args = [
138
+ false, // reduceOnly
139
+ params.receiver, // receiver
140
+ params.collateralSupplies.map(({ collateralIndex, assets }) => ({
81
141
  collateralIndex,
82
- assets: params.collateralAssets,
83
- permit: { kind: types_js_1.PermitKind.None, data: "0x" },
84
- },
142
+ assets,
143
+ })), // collateralSupplies
144
+ params.takeableOffers, // offerFills
145
+ referralFeePct, // referralFeePct
146
+ referralFeeRecipient, // referralFeeRecipient
147
+ params.deadline, // deadline
148
+ nativeFunding.wrappedNative, // wrappedNative
85
149
  ];
86
150
  let tx = {
87
- to: midnightBundles,
88
- value: 0n,
89
- data: (0, viem_1.encodeFunctionData)({
90
- abi: midnight_sdk_1.midnightBundlesAbi,
91
- functionName: "midnightBundlesV1SupplyCollateralAndSellWithAssetsTarget",
92
- args: [
93
- params.loanAssets,
94
- params.maxUnits,
95
- params.taker,
96
- false,
97
- params.taker,
98
- collateralSupplies,
99
- params.takeableOffers,
100
- 0n,
101
- viem_1.zeroAddress,
102
- viem_1.maxUint256,
103
- params.deadline,
104
- ],
105
- }),
151
+ to: (0, morpho_ts_1.getChainAddress)(params.chainId, "midnightBundlesV2"),
152
+ value: nativeFunding.value,
153
+ data: target.type === "assets"
154
+ ? (0, viem_1.encodeFunctionData)({
155
+ abi: midnight_sdk_1.midnightBundlesV2Abi,
156
+ functionName: "midnightBundlesV2SupplyCollateralAndSellWithAssetsTarget",
157
+ args: [market, target.assets, target.maxUnits, ...args],
158
+ })
159
+ : (0, viem_1.encodeFunctionData)({
160
+ abi: midnight_sdk_1.midnightBundlesV2Abi,
161
+ functionName: "midnightBundlesV2SupplyCollateralAndSellWithUnitsTarget",
162
+ args: [market, target.units, target.minSellerAssets, ...args],
163
+ }),
106
164
  };
107
165
  if (params.metadata) {
108
166
  tx = (0, index_js_1.addTransactionMetadata)(tx, params.metadata);
@@ -113,14 +171,13 @@ const midnightSupplyCollateralTakeBorrow = (params) => {
113
171
  type: "midnightSupplyCollateralTakeBorrow",
114
172
  args: {
115
173
  market: marketId,
116
- collateralAssets: params.collateralAssets,
117
- loanAssets: params.loanAssets,
118
- maxUnits: params.maxUnits,
119
- taker: params.taker,
120
- receiver: params.taker,
121
- collateralSupplies: collateralSupplies.length,
174
+ target: { ...params.target },
175
+ receiver: params.receiver,
176
+ collateralSupplies: params.collateralSupplies.map(({ collateralIndex, assets }) => ({ collateralIndex, assets })),
122
177
  takeableOffers: params.takeableOffers.length,
123
178
  deadline: params.deadline,
179
+ referralFeePct,
180
+ referralFeeRecipient,
124
181
  },
125
182
  },
126
183
  });