@morpho-org/morpho-sdk 2.0.0 → 3.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 (202) hide show
  1. package/lib/cjs/abis.d.ts +2816 -0
  2. package/lib/cjs/abis.js +1951 -0
  3. package/lib/cjs/actions/index.d.ts +3 -0
  4. package/lib/cjs/actions/marketV1/borrow.js +7 -10
  5. package/lib/cjs/actions/marketV1/buildReallocationActions.d.ts +2 -3
  6. package/lib/cjs/actions/marketV1/buildReallocationActions.js +1 -2
  7. package/lib/cjs/actions/marketV1/repay.d.ts +2 -0
  8. package/lib/cjs/actions/marketV1/repay.js +7 -8
  9. package/lib/cjs/actions/marketV1/repayWithdrawCollateral.d.ts +2 -0
  10. package/lib/cjs/actions/marketV1/repayWithdrawCollateral.js +9 -10
  11. package/lib/cjs/actions/marketV1/supplyCollateral.d.ts +2 -0
  12. package/lib/cjs/actions/marketV1/supplyCollateral.js +11 -12
  13. package/lib/cjs/actions/marketV1/supplyCollateralBorrow.d.ts +2 -0
  14. package/lib/cjs/actions/marketV1/supplyCollateralBorrow.js +13 -14
  15. package/lib/cjs/actions/requirements/encode/encodeErc20Approval.js +2 -2
  16. package/lib/cjs/actions/requirements/getRequirementsAction.d.ts +28 -4
  17. package/lib/cjs/actions/requirements/getRequirementsAction.js +28 -4
  18. package/lib/cjs/actions/requirements/getRequirementsApproval.js +2 -2
  19. package/lib/cjs/actions/requirements/index.d.ts +1 -0
  20. package/lib/cjs/actions/requirements/index.js +1 -0
  21. package/lib/cjs/actions/vaultV1/deposit.d.ts +2 -0
  22. package/lib/cjs/actions/vaultV1/deposit.js +13 -14
  23. package/lib/cjs/actions/vaultV1/migrateToV2.d.ts +2 -0
  24. package/lib/cjs/actions/vaultV1/migrateToV2.js +11 -9
  25. package/lib/cjs/actions/vaultV2/deposit.d.ts +2 -0
  26. package/lib/cjs/actions/vaultV2/deposit.js +13 -14
  27. package/lib/cjs/addresses.d.ts +2 -0
  28. package/lib/cjs/addresses.js +18 -0
  29. package/lib/cjs/augment/AccrualPosition.d.ts +9 -0
  30. package/lib/cjs/augment/AccrualPosition.js +8 -0
  31. package/lib/cjs/augment/AccrualVault.d.ts +8 -0
  32. package/lib/cjs/augment/AccrualVault.js +7 -0
  33. package/lib/cjs/augment/Holding.d.ts +8 -0
  34. package/lib/cjs/augment/Holding.js +7 -0
  35. package/lib/cjs/augment/Market.d.ts +8 -0
  36. package/lib/cjs/augment/Market.js +7 -0
  37. package/lib/cjs/augment/MarketParams.d.ts +8 -0
  38. package/lib/cjs/augment/MarketParams.js +7 -0
  39. package/lib/cjs/augment/Position.d.ts +8 -0
  40. package/lib/cjs/augment/Position.js +7 -0
  41. package/lib/cjs/augment/Token.d.ts +8 -0
  42. package/lib/cjs/augment/Token.js +7 -0
  43. package/lib/cjs/augment/User.d.ts +8 -0
  44. package/lib/cjs/augment/User.js +7 -0
  45. package/lib/cjs/augment/Vault.d.ts +8 -0
  46. package/lib/cjs/augment/Vault.js +7 -0
  47. package/lib/cjs/augment/VaultConfig.d.ts +8 -0
  48. package/lib/cjs/augment/VaultConfig.js +7 -0
  49. package/lib/cjs/augment/VaultMarketAllocation.d.ts +8 -0
  50. package/lib/cjs/augment/VaultMarketAllocation.js +7 -0
  51. package/lib/cjs/augment/VaultMarketConfig.d.ts +8 -0
  52. package/lib/cjs/augment/VaultMarketConfig.js +7 -0
  53. package/lib/cjs/augment/VaultMarketPublicAllocatorConfig.d.ts +8 -0
  54. package/lib/cjs/augment/VaultMarketPublicAllocatorConfig.js +8 -0
  55. package/lib/cjs/augment/VaultUser.d.ts +8 -0
  56. package/lib/cjs/augment/VaultUser.js +7 -0
  57. package/lib/cjs/augment.d.ts +14 -0
  58. package/lib/cjs/augment.js +16 -0
  59. package/lib/cjs/bundler/actions.d.ts +555 -0
  60. package/lib/cjs/bundler/actions.js +953 -0
  61. package/lib/cjs/bundler/index.d.ts +2 -0
  62. package/lib/cjs/bundler/index.js +18 -0
  63. package/lib/cjs/bundler/types.d.ts +181 -0
  64. package/lib/cjs/bundler/types.js +2 -0
  65. package/lib/cjs/constants.d.ts +3 -0
  66. package/lib/cjs/constants.js +32 -0
  67. package/lib/cjs/entities/index.d.ts +6 -3
  68. package/lib/cjs/entities/index.js +41 -17
  69. package/lib/cjs/entities/marketV1/marketV1.d.ts +45 -11
  70. package/lib/cjs/entities/marketV1/marketV1.js +45 -23
  71. package/lib/cjs/entities/reallocationData.d.ts +193 -0
  72. package/lib/cjs/entities/reallocationData.js +406 -0
  73. package/lib/cjs/entities/vaultV1/vaultV1.js +6 -2
  74. package/lib/cjs/entities/vaultV2/vaultV2.js +6 -1
  75. package/lib/cjs/errors.d.ts +2 -0
  76. package/lib/cjs/errors.js +18 -0
  77. package/lib/cjs/fetch.d.ts +1 -0
  78. package/lib/cjs/fetch.js +30 -0
  79. package/lib/cjs/format.d.ts +2 -0
  80. package/lib/cjs/format.js +22 -0
  81. package/lib/cjs/helpers/computeReallocations.d.ts +48 -8
  82. package/lib/cjs/helpers/computeReallocations.js +120 -32
  83. package/lib/cjs/helpers/constant.d.ts +17 -0
  84. package/lib/cjs/helpers/constant.js +30 -1
  85. package/lib/cjs/helpers/index.d.ts +1 -0
  86. package/lib/cjs/helpers/index.js +9 -1
  87. package/lib/cjs/helpers/metadata.d.ts +10 -0
  88. package/lib/cjs/helpers/metadata.js +20 -1
  89. package/lib/cjs/helpers/validate.d.ts +2 -0
  90. package/lib/cjs/helpers/validate.js +14 -2
  91. package/lib/cjs/index.d.ts +0 -1
  92. package/lib/cjs/index.js +0 -1
  93. package/lib/cjs/types/client.d.ts +1 -1
  94. package/lib/cjs/types/error.d.ts +91 -1
  95. package/lib/cjs/types/error.js +126 -1
  96. package/lib/cjs/types/sharedLiquidity.d.ts +43 -3
  97. package/lib/cjs/types.d.ts +3 -0
  98. package/lib/cjs/types.js +17 -0
  99. package/lib/cjs/utils.d.ts +9 -0
  100. package/lib/cjs/utils.js +65 -0
  101. package/lib/esm/abis.d.ts +2816 -0
  102. package/lib/esm/abis.js +1922 -0
  103. package/lib/esm/actions/index.d.ts +3 -0
  104. package/lib/esm/actions/marketV1/borrow.js +2 -5
  105. package/lib/esm/actions/marketV1/buildReallocationActions.d.ts +2 -3
  106. package/lib/esm/actions/marketV1/buildReallocationActions.js +1 -2
  107. package/lib/esm/actions/marketV1/repay.d.ts +2 -0
  108. package/lib/esm/actions/marketV1/repay.js +4 -5
  109. package/lib/esm/actions/marketV1/repayWithdrawCollateral.d.ts +2 -0
  110. package/lib/esm/actions/marketV1/repayWithdrawCollateral.js +4 -5
  111. package/lib/esm/actions/marketV1/supplyCollateral.d.ts +2 -0
  112. package/lib/esm/actions/marketV1/supplyCollateral.js +4 -5
  113. package/lib/esm/actions/marketV1/supplyCollateralBorrow.d.ts +2 -0
  114. package/lib/esm/actions/marketV1/supplyCollateralBorrow.js +4 -5
  115. package/lib/esm/actions/requirements/encode/encodeErc20Approval.js +1 -1
  116. package/lib/esm/actions/requirements/getRequirementsAction.d.ts +28 -4
  117. package/lib/esm/actions/requirements/getRequirementsAction.js +29 -5
  118. package/lib/esm/actions/requirements/getRequirementsApproval.js +1 -1
  119. package/lib/esm/actions/requirements/index.d.ts +1 -0
  120. package/lib/esm/actions/requirements/index.js +1 -0
  121. package/lib/esm/actions/vaultV1/deposit.d.ts +2 -0
  122. package/lib/esm/actions/vaultV1/deposit.js +3 -4
  123. package/lib/esm/actions/vaultV1/migrateToV2.d.ts +2 -0
  124. package/lib/esm/actions/vaultV1/migrateToV2.js +3 -1
  125. package/lib/esm/actions/vaultV2/deposit.d.ts +2 -0
  126. package/lib/esm/actions/vaultV2/deposit.js +3 -4
  127. package/lib/esm/addresses.d.ts +2 -0
  128. package/lib/esm/addresses.js +1 -0
  129. package/lib/esm/augment/AccrualPosition.d.ts +9 -0
  130. package/lib/esm/augment/AccrualPosition.js +5 -0
  131. package/lib/esm/augment/AccrualVault.d.ts +8 -0
  132. package/lib/esm/augment/AccrualVault.js +4 -0
  133. package/lib/esm/augment/Holding.d.ts +8 -0
  134. package/lib/esm/augment/Holding.js +4 -0
  135. package/lib/esm/augment/Market.d.ts +8 -0
  136. package/lib/esm/augment/Market.js +4 -0
  137. package/lib/esm/augment/MarketParams.d.ts +8 -0
  138. package/lib/esm/augment/MarketParams.js +4 -0
  139. package/lib/esm/augment/Position.d.ts +8 -0
  140. package/lib/esm/augment/Position.js +4 -0
  141. package/lib/esm/augment/Token.d.ts +8 -0
  142. package/lib/esm/augment/Token.js +4 -0
  143. package/lib/esm/augment/User.d.ts +8 -0
  144. package/lib/esm/augment/User.js +4 -0
  145. package/lib/esm/augment/Vault.d.ts +8 -0
  146. package/lib/esm/augment/Vault.js +4 -0
  147. package/lib/esm/augment/VaultConfig.d.ts +8 -0
  148. package/lib/esm/augment/VaultConfig.js +4 -0
  149. package/lib/esm/augment/VaultMarketAllocation.d.ts +8 -0
  150. package/lib/esm/augment/VaultMarketAllocation.js +4 -0
  151. package/lib/esm/augment/VaultMarketConfig.d.ts +8 -0
  152. package/lib/esm/augment/VaultMarketConfig.js +4 -0
  153. package/lib/esm/augment/VaultMarketPublicAllocatorConfig.d.ts +8 -0
  154. package/lib/esm/augment/VaultMarketPublicAllocatorConfig.js +5 -0
  155. package/lib/esm/augment/VaultUser.d.ts +8 -0
  156. package/lib/esm/augment/VaultUser.js +4 -0
  157. package/lib/esm/augment.d.ts +14 -0
  158. package/lib/esm/augment.js +14 -0
  159. package/lib/esm/bundler/actions.d.ts +555 -0
  160. package/lib/esm/bundler/actions.js +950 -0
  161. package/lib/esm/bundler/index.d.ts +2 -0
  162. package/lib/esm/bundler/index.js +2 -0
  163. package/lib/esm/bundler/types.d.ts +181 -0
  164. package/lib/esm/bundler/types.js +1 -0
  165. package/lib/esm/constants.d.ts +3 -0
  166. package/lib/esm/constants.js +3 -0
  167. package/lib/esm/entities/index.d.ts +6 -3
  168. package/lib/esm/entities/index.js +5 -3
  169. package/lib/esm/entities/marketV1/marketV1.d.ts +45 -11
  170. package/lib/esm/entities/marketV1/marketV1.js +46 -24
  171. package/lib/esm/entities/reallocationData.d.ts +193 -0
  172. package/lib/esm/entities/reallocationData.js +402 -0
  173. package/lib/esm/entities/vaultV1/vaultV1.js +6 -2
  174. package/lib/esm/entities/vaultV2/vaultV2.js +6 -1
  175. package/lib/esm/errors.d.ts +2 -0
  176. package/lib/esm/errors.js +1 -0
  177. package/lib/esm/fetch.d.ts +1 -0
  178. package/lib/esm/fetch.js +1 -0
  179. package/lib/esm/format.d.ts +2 -0
  180. package/lib/esm/format.js +1 -0
  181. package/lib/esm/helpers/computeReallocations.d.ts +48 -8
  182. package/lib/esm/helpers/computeReallocations.js +119 -31
  183. package/lib/esm/helpers/constant.d.ts +17 -0
  184. package/lib/esm/helpers/constant.js +30 -1
  185. package/lib/esm/helpers/index.d.ts +1 -0
  186. package/lib/esm/helpers/index.js +1 -0
  187. package/lib/esm/helpers/metadata.d.ts +10 -0
  188. package/lib/esm/helpers/metadata.js +20 -1
  189. package/lib/esm/helpers/validate.d.ts +2 -0
  190. package/lib/esm/helpers/validate.js +12 -1
  191. package/lib/esm/index.d.ts +0 -1
  192. package/lib/esm/index.js +0 -1
  193. package/lib/esm/types/client.d.ts +1 -1
  194. package/lib/esm/types/error.d.ts +91 -1
  195. package/lib/esm/types/error.js +118 -0
  196. package/lib/esm/types/sharedLiquidity.d.ts +43 -3
  197. package/lib/esm/types.d.ts +3 -0
  198. package/lib/esm/types.js +1 -0
  199. package/lib/esm/utils.d.ts +9 -0
  200. package/lib/esm/utils.js +7 -0
  201. package/package.json +121 -14
  202. package/src/index.ts +0 -1
@@ -0,0 +1,953 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.BundlerAction = void 0;
4
+ const blue_sdk_1 = require("@morpho-org/blue-sdk");
5
+ const blue_sdk_viem_1 = require("@morpho-org/blue-sdk-viem");
6
+ const viem_1 = require("viem");
7
+ const abis_js_1 = require("../abis.js");
8
+ const error_js_1 = require("../types/error.js");
9
+ const reenterAbiInputs = abis_js_1.bundler3Abi.find((item) => item.type === "function" && item.name === "reenter").inputs;
10
+ const encodeCallbackCalls = (callbackCalls) => {
11
+ const reenter = callbackCalls.length > 0;
12
+ const reenterData = reenter
13
+ ? (0, viem_1.encodeAbiParameters)(reenterAbiInputs, [callbackCalls])
14
+ : "0x";
15
+ return {
16
+ callbackHash: reenter ? (0, viem_1.keccak256)(reenterData) : viem_1.zeroHash,
17
+ reenterData,
18
+ };
19
+ };
20
+ const addBundlerPrefund = (state, amount) => ({
21
+ value: state.value + amount,
22
+ availableBundlerValue: state.availableBundlerValue + amount,
23
+ });
24
+ const consumeCallValue = (state, call) => {
25
+ if (call.value > state.availableBundlerValue) {
26
+ return {
27
+ value: state.value + call.value - state.availableBundlerValue,
28
+ availableBundlerValue: 0n,
29
+ };
30
+ }
31
+ return {
32
+ value: state.value,
33
+ availableBundlerValue: state.availableBundlerValue - call.value,
34
+ };
35
+ };
36
+ /**
37
+ * Encodes the Bundler3 action subset used by `morpho-sdk` transaction builders.
38
+ *
39
+ * @remarks
40
+ * The namespace covers only the Bundler3 actions required by `morpho-sdk`.
41
+ * It does not expose operation population or simulation helpers from
42
+ * `@morpho-org/bundler-sdk-viem`.
43
+ */
44
+ var BundlerAction;
45
+ (function (BundlerAction) {
46
+ /**
47
+ * Encodes a list of Bundler3 actions into a single Bundler3 multicall
48
+ * transaction request.
49
+ *
50
+ * @remarks
51
+ * This is a low-level encoding helper, not a safe bundle constructor. It
52
+ * does not validate that native-token pre-funding is fully consumed or that
53
+ * pre-funding actions are ordered before the value-carrying calls they fund.
54
+ *
55
+ * When custom actions include `nativeTransfer(externalOwner, bundler3,
56
+ * amount)`, no inner Bundler3 call is emitted for that transfer. Consumers
57
+ * must ensure those pre-funding actions precede their downstream consumers
58
+ * and leave no residual pre-funded native token; otherwise `tx.value` can be
59
+ * over-counted or native token can remain stranded on Bundler3. The
60
+ * high-level `morpho-sdk` action builders construct actions in that order,
61
+ * but this invariant is not checked at runtime by `encodeBundle`.
62
+ *
63
+ * @param chainId - Chain where the bundle will execute.
64
+ * @param actions - Ordered Bundler3 actions to encode.
65
+ * @returns Transaction target, calldata, and native value required by the
66
+ * bundle.
67
+ * @throws {BundlerErrors.MissingSignature} when a signature action is unsigned.
68
+ * @throws {BundlerErrors.UnexpectedAction} when an action is unavailable on the chain.
69
+ *
70
+ * @example
71
+ * ```ts
72
+ * import { getChainAddresses } from "@morpho-org/blue-sdk";
73
+ * import { BundlerAction } from "@morpho-org/morpho-sdk/bundler";
74
+ *
75
+ * const { generalAdapter1 } = getChainAddresses(1).bundler3;
76
+ * const sender = "0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045";
77
+ *
78
+ * const tx = BundlerAction.encodeBundle(1, [
79
+ * {
80
+ * type: "nativeTransfer",
81
+ * args: [sender, generalAdapter1, 1_000000000000000000n],
82
+ * },
83
+ * ]);
84
+ * ```
85
+ */
86
+ function encodeBundle(chainId, actions) {
87
+ const { bundler3: { bundler3 }, } = (0, blue_sdk_1.getChainAddresses)(chainId);
88
+ let valueState = {
89
+ value: 0n,
90
+ availableBundlerValue: 0n,
91
+ };
92
+ const encodedActions = [];
93
+ for (const action of actions) {
94
+ const encodedAction = encodeBundleAction({ chainId, action, valueState });
95
+ encodedActions.push(...encodedAction.calls);
96
+ valueState = encodedAction.valueState;
97
+ }
98
+ return {
99
+ to: bundler3,
100
+ value: valueState.value,
101
+ data: (0, viem_1.encodeFunctionData)({
102
+ abi: abis_js_1.bundler3Abi,
103
+ functionName: "multicall",
104
+ args: [encodedActions],
105
+ }),
106
+ };
107
+ }
108
+ BundlerAction.encodeBundle = encodeBundle;
109
+ /**
110
+ * Encodes a single supported Bundler3 action into one or more low-level
111
+ * Bundler3 calls.
112
+ *
113
+ * @param chainId - Chain where the action will execute.
114
+ * @param action - Bundler3 action to encode.
115
+ * @returns Encoded Bundler3 calls.
116
+ * @throws {BundlerErrors.MissingSignature} when a signature action is unsigned.
117
+ * @throws {BundlerErrors.UnexpectedAction} when the action is unavailable on the chain.
118
+ *
119
+ * @example
120
+ * ```ts
121
+ * import { BundlerAction } from "@morpho-org/morpho-sdk/bundler";
122
+ *
123
+ * const recipient = "0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045";
124
+ *
125
+ * const calls = BundlerAction.encode(1, {
126
+ * type: "wrapNative",
127
+ * args: [1_000000000000000000n, recipient],
128
+ * });
129
+ * ```
130
+ */
131
+ function encode(chainId, action) {
132
+ const { type, args } = action;
133
+ switch (type) {
134
+ case "nativeTransfer": {
135
+ return BundlerAction.nativeTransfer(chainId, ...args);
136
+ }
137
+ case "erc20Transfer": {
138
+ return BundlerAction.erc20Transfer(...args);
139
+ }
140
+ case "erc20TransferFrom": {
141
+ return BundlerAction.erc20TransferFrom(chainId, ...args);
142
+ }
143
+ case "permit": {
144
+ const [sender, asset, amount, deadline, signature, skipRevert] = args;
145
+ if (signature == null)
146
+ throw new error_js_1.BundlerErrors.MissingSignature();
147
+ return BundlerAction.permit(chainId, sender, asset, amount, deadline, signature, skipRevert);
148
+ }
149
+ case "approve2": {
150
+ const [sender, permitSingle, signature, skipRevert] = args;
151
+ if (signature == null)
152
+ throw new error_js_1.BundlerErrors.MissingSignature();
153
+ return BundlerAction.approve2(chainId, sender, permitSingle, signature, skipRevert);
154
+ }
155
+ case "transferFrom2": {
156
+ return BundlerAction.transferFrom2(chainId, ...args);
157
+ }
158
+ case "erc4626Deposit": {
159
+ return BundlerAction.erc4626Deposit(chainId, ...args);
160
+ }
161
+ case "erc4626Redeem": {
162
+ return BundlerAction.erc4626Redeem(chainId, ...args);
163
+ }
164
+ case "morphoSupplyCollateral": {
165
+ const [market, amount, onBehalf, onMorphoSupplyCollateral, skipRevert] = args;
166
+ return BundlerAction.morphoSupplyCollateral(chainId, market, amount, onBehalf, onMorphoSupplyCollateral.flatMap(BundlerAction.encode.bind(null, chainId)), skipRevert);
167
+ }
168
+ case "morphoBorrow": {
169
+ return BundlerAction.morphoBorrow(chainId, ...args);
170
+ }
171
+ case "morphoRepay": {
172
+ const [market, assets, shares, slippageAmount, onBehalf, onMorphoRepay, skipRevert,] = args;
173
+ return BundlerAction.morphoRepay(chainId, market, assets, shares, slippageAmount, onBehalf, onMorphoRepay.flatMap(BundlerAction.encode.bind(null, chainId)), skipRevert);
174
+ }
175
+ case "morphoWithdrawCollateral": {
176
+ return BundlerAction.morphoWithdrawCollateral(chainId, ...args);
177
+ }
178
+ case "reallocateTo": {
179
+ return BundlerAction.publicAllocatorReallocateTo(chainId, ...args);
180
+ }
181
+ case "wrapNative": {
182
+ return BundlerAction.wrapNative(chainId, ...args);
183
+ }
184
+ }
185
+ }
186
+ BundlerAction.encode = encode;
187
+ function encodeBundleAction({ chainId, action, valueState, }) {
188
+ const { bundler3: { bundler3, generalAdapter1 }, } = (0, blue_sdk_1.getChainAddresses)(chainId);
189
+ let nextValueState = valueState;
190
+ if (action.type === "nativeTransfer") {
191
+ const [owner, recipient, amount] = action.args;
192
+ // A transfer into Bundler3 emits no inner call; it pre-funds later
193
+ // value-carrying calls in the same multicall or callback reentry.
194
+ if (!(0, viem_1.isAddressEqual)(owner, bundler3) &&
195
+ !(0, viem_1.isAddressEqual)(owner, generalAdapter1) &&
196
+ (0, viem_1.isAddressEqual)(recipient, bundler3)) {
197
+ nextValueState = addBundlerPrefund(nextValueState, amount);
198
+ }
199
+ }
200
+ const calls = BundlerAction.encode(chainId, action);
201
+ for (const call of calls) {
202
+ nextValueState = consumeCallValue(nextValueState, call);
203
+ }
204
+ if (action.type === "morphoSupplyCollateral") {
205
+ const [, , , onMorphoSupplyCollateral] = action.args;
206
+ for (const callbackAction of onMorphoSupplyCollateral) {
207
+ const encodedCallback = encodeBundleAction({
208
+ chainId,
209
+ action: callbackAction,
210
+ valueState: nextValueState,
211
+ });
212
+ nextValueState = encodedCallback.valueState;
213
+ }
214
+ }
215
+ if (action.type === "morphoRepay") {
216
+ const [, , , , , onMorphoRepay] = action.args;
217
+ for (const callbackAction of onMorphoRepay) {
218
+ const encodedCallback = encodeBundleAction({
219
+ chainId,
220
+ action: callbackAction,
221
+ valueState: nextValueState,
222
+ });
223
+ nextValueState = encodedCallback.valueState;
224
+ }
225
+ }
226
+ return { calls, valueState: nextValueState };
227
+ }
228
+ /**
229
+ * Encodes a native-token transfer for Bundler3 execution.
230
+ *
231
+ * @remarks
232
+ * Transfers to Bundler3 are treated as bundle pre-funding and emit no inner
233
+ * call. Transfers whose `owner` is GeneralAdapter1 are encoded as
234
+ * `GeneralAdapter1.nativeTransfer(recipient, amount)` and always use
235
+ * `skipRevert: false`; the caller-supplied `skipRevert` argument applies
236
+ * only to direct native transfers from other owners.
237
+ *
238
+ * @param chainId - Chain where the action will execute.
239
+ * @param owner - Current native-token owner in the bundle.
240
+ * @param recipient - Native-token recipient.
241
+ * @param amount - Native-token amount in wei.
242
+ * @param skipRevert - Whether Bundler3 should tolerate a revert.
243
+ * @returns Encoded Bundler3 calls.
244
+ *
245
+ * @example
246
+ * ```ts
247
+ * import { BundlerAction } from "@morpho-org/morpho-sdk/bundler";
248
+ *
249
+ * const sender = "0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045";
250
+ * const recipient = "0xfB6916095ca1df60bB79Ce92cE3Ea74c37c5d359";
251
+ *
252
+ * const calls = BundlerAction.nativeTransfer(
253
+ * 1,
254
+ * sender,
255
+ * recipient,
256
+ * 1_000000000000000000n,
257
+ * );
258
+ * ```
259
+ */
260
+ // biome-ignore lint/complexity/useMaxParams: TODO refactor to ≤2 params
261
+ function nativeTransfer(chainId, owner, recipient, amount, skipRevert = false) {
262
+ const { bundler3: { bundler3, generalAdapter1 }, } = (0, blue_sdk_1.getChainAddresses)(chainId);
263
+ if ((0, viem_1.isAddressEqual)(recipient, bundler3))
264
+ return [];
265
+ if ((0, viem_1.isAddressEqual)(owner, generalAdapter1)) {
266
+ return [
267
+ {
268
+ to: generalAdapter1,
269
+ data: (0, viem_1.encodeFunctionData)({
270
+ abi: abis_js_1.coreAdapterAbi,
271
+ functionName: "nativeTransfer",
272
+ args: [recipient, amount],
273
+ }),
274
+ value: 0n,
275
+ skipRevert: false,
276
+ callbackHash: viem_1.zeroHash,
277
+ },
278
+ ];
279
+ }
280
+ return [
281
+ {
282
+ to: recipient,
283
+ data: "0x",
284
+ value: amount,
285
+ skipRevert,
286
+ callbackHash: viem_1.zeroHash,
287
+ },
288
+ ];
289
+ }
290
+ BundlerAction.nativeTransfer = nativeTransfer;
291
+ /**
292
+ * Encodes an ERC20 transfer from the given adapter.
293
+ *
294
+ * @param asset - ERC20 token to transfer.
295
+ * @param recipient - Recipient of the transferred tokens.
296
+ * @param amount - Token amount to transfer.
297
+ * @param adapter - Adapter that currently holds the tokens.
298
+ * @param skipRevert - Whether Bundler3 should tolerate a revert.
299
+ * @returns Encoded Bundler3 calls.
300
+ *
301
+ * @example
302
+ * ```ts
303
+ * import { getChainAddresses } from "@morpho-org/blue-sdk";
304
+ * import { BundlerAction } from "@morpho-org/morpho-sdk/bundler";
305
+ *
306
+ * const adapter = getChainAddresses(1).bundler3.generalAdapter1;
307
+ * const asset = "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48";
308
+ * const recipient = "0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045";
309
+ *
310
+ * const calls = BundlerAction.erc20Transfer(
311
+ * asset,
312
+ * recipient,
313
+ * 100n,
314
+ * adapter,
315
+ * );
316
+ * ```
317
+ */
318
+ // biome-ignore lint/complexity/useMaxParams: TODO refactor to ≤2 params
319
+ function erc20Transfer(asset, recipient, amount, adapter, skipRevert = false) {
320
+ return [
321
+ {
322
+ to: adapter,
323
+ data: (0, viem_1.encodeFunctionData)({
324
+ abi: abis_js_1.coreAdapterAbi,
325
+ functionName: "erc20Transfer",
326
+ args: [asset, recipient, amount],
327
+ }),
328
+ value: 0n,
329
+ skipRevert,
330
+ callbackHash: viem_1.zeroHash,
331
+ },
332
+ ];
333
+ }
334
+ BundlerAction.erc20Transfer = erc20Transfer;
335
+ /**
336
+ * Encodes a GeneralAdapter1 ERC20 `transferFrom`.
337
+ *
338
+ * @param chainId - Chain where the action will execute.
339
+ * @param asset - ERC20 token to transfer.
340
+ * @param amount - Token amount to transfer.
341
+ * @param recipient - Recipient of the transferred tokens.
342
+ * @param skipRevert - Whether Bundler3 should tolerate a revert.
343
+ * @returns Encoded Bundler3 calls.
344
+ *
345
+ * @example
346
+ * ```ts
347
+ * import { BundlerAction } from "@morpho-org/morpho-sdk/bundler";
348
+ *
349
+ * const asset = "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48";
350
+ * const recipient = "0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045";
351
+ *
352
+ * const calls = BundlerAction.erc20TransferFrom(
353
+ * 1,
354
+ * asset,
355
+ * 100n,
356
+ * recipient,
357
+ * );
358
+ * ```
359
+ */
360
+ // biome-ignore lint/complexity/useMaxParams: TODO refactor to ≤2 params
361
+ function erc20TransferFrom(chainId, asset, amount, recipient, skipRevert = false) {
362
+ const { bundler3: { generalAdapter1 }, } = (0, blue_sdk_1.getChainAddresses)(chainId);
363
+ return [
364
+ {
365
+ to: generalAdapter1,
366
+ data: (0, viem_1.encodeFunctionData)({
367
+ abi: abis_js_1.generalAdapter1Abi,
368
+ functionName: "erc20TransferFrom",
369
+ args: [asset, recipient, amount],
370
+ }),
371
+ value: 0n,
372
+ skipRevert,
373
+ callbackHash: viem_1.zeroHash,
374
+ },
375
+ ];
376
+ }
377
+ BundlerAction.erc20TransferFrom = erc20TransferFrom;
378
+ /**
379
+ * Encodes an ERC20 permit for GeneralAdapter1 spending.
380
+ *
381
+ * @param chainId - Chain where the action will execute.
382
+ * @param owner - Token owner signing the permit.
383
+ * @param asset - ERC20 token being permitted.
384
+ * @param amount - Allowance amount.
385
+ * @param deadline - Permit deadline timestamp.
386
+ * @param signature - Owner signature.
387
+ * @param skipRevert - Whether Bundler3 should tolerate a revert.
388
+ * @returns Encoded Bundler3 calls.
389
+ *
390
+ * @example
391
+ * ```ts
392
+ * import { BundlerAction } from "@morpho-org/morpho-sdk/bundler";
393
+ *
394
+ * const owner = "0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045";
395
+ * const asset = "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48";
396
+ * const signature =
397
+ * "0x111111111111111111111111111111111111111111111111111111111111111122222222222222222222222222222222222222222222222222222222222222221b";
398
+ *
399
+ * const calls = BundlerAction.permit(
400
+ * 1,
401
+ * owner,
402
+ * asset,
403
+ * 100n,
404
+ * 1_900_000_000n,
405
+ * signature,
406
+ * );
407
+ * ```
408
+ */
409
+ // biome-ignore lint/complexity/useMaxParams: TODO refactor to ≤2 params
410
+ function permit(chainId, owner, asset, amount, deadline, signature, skipRevert = true) {
411
+ const { bundler3: { generalAdapter1 }, } = (0, blue_sdk_1.getChainAddresses)(chainId);
412
+ const { r, s, yParity } = (0, viem_1.parseSignature)(signature);
413
+ return [
414
+ {
415
+ to: asset,
416
+ data: (0, viem_1.encodeFunctionData)({
417
+ abi: blue_sdk_viem_1.erc2612Abi,
418
+ functionName: "permit",
419
+ args: [owner, generalAdapter1, amount, deadline, yParity + 27, r, s],
420
+ }),
421
+ value: 0n,
422
+ skipRevert,
423
+ callbackHash: viem_1.zeroHash,
424
+ },
425
+ ];
426
+ }
427
+ BundlerAction.permit = permit;
428
+ /**
429
+ * Encodes a Permit2 approval for GeneralAdapter1 spending.
430
+ *
431
+ * @param chainId - Chain where the action will execute.
432
+ * @param owner - Token owner signing the Permit2 payload.
433
+ * @param permitSingle - Permit2 allowance payload.
434
+ * @param signature - Owner signature.
435
+ * @param skipRevert - Whether Bundler3 should tolerate a revert.
436
+ * @returns Encoded Bundler3 calls.
437
+ * @throws {BundlerErrors.UnexpectedAction} when Permit2 is unavailable on the chain.
438
+ *
439
+ * @example
440
+ * ```ts
441
+ * import { BundlerAction } from "@morpho-org/morpho-sdk/bundler";
442
+ *
443
+ * const owner = "0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045";
444
+ * const token = "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48";
445
+ * const signature =
446
+ * "0x111111111111111111111111111111111111111111111111111111111111111122222222222222222222222222222222222222222222222222222222222222221b";
447
+ *
448
+ * const calls = BundlerAction.approve2(
449
+ * 1,
450
+ * owner,
451
+ * {
452
+ * details: {
453
+ * token,
454
+ * amount: 100n,
455
+ * expiration: 1_900_000_000,
456
+ * nonce: 0,
457
+ * },
458
+ * sigDeadline: 1_900_000_000n,
459
+ * },
460
+ * signature,
461
+ * );
462
+ * ```
463
+ */
464
+ // biome-ignore lint/complexity/useMaxParams: TODO refactor to ≤2 params
465
+ function approve2(chainId, owner, permitSingle, signature, skipRevert = true) {
466
+ const { permit2, bundler3: { generalAdapter1 }, } = (0, blue_sdk_1.getChainAddresses)(chainId);
467
+ if (permit2 == null) {
468
+ throw new error_js_1.BundlerErrors.UnexpectedAction("approve2", chainId);
469
+ }
470
+ return [
471
+ {
472
+ to: permit2,
473
+ data: (0, viem_1.encodeFunctionData)({
474
+ abi: blue_sdk_viem_1.permit2Abi,
475
+ functionName: "permit",
476
+ args: [
477
+ owner,
478
+ {
479
+ ...permitSingle,
480
+ spender: generalAdapter1,
481
+ },
482
+ signature,
483
+ ],
484
+ }),
485
+ value: 0n,
486
+ skipRevert,
487
+ callbackHash: viem_1.zeroHash,
488
+ },
489
+ ];
490
+ }
491
+ BundlerAction.approve2 = approve2;
492
+ /**
493
+ * Encodes a GeneralAdapter1 Permit2 transfer.
494
+ *
495
+ * @param chainId - Chain where the action will execute.
496
+ * @param asset - ERC20 token to transfer through Permit2.
497
+ * @param amount - Token amount to transfer.
498
+ * @param recipient - Recipient of the transferred tokens.
499
+ * @param skipRevert - Whether Bundler3 should tolerate a revert.
500
+ * @returns Encoded Bundler3 calls.
501
+ *
502
+ * @example
503
+ * ```ts
504
+ * import { BundlerAction } from "@morpho-org/morpho-sdk/bundler";
505
+ *
506
+ * const asset = "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48";
507
+ * const recipient = "0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045";
508
+ *
509
+ * const calls = BundlerAction.transferFrom2(
510
+ * 1,
511
+ * asset,
512
+ * 100n,
513
+ * recipient,
514
+ * );
515
+ * ```
516
+ */
517
+ // biome-ignore lint/complexity/useMaxParams: TODO refactor to ≤2 params
518
+ function transferFrom2(chainId, asset, amount, recipient, skipRevert = false) {
519
+ const { bundler3: { generalAdapter1 }, } = (0, blue_sdk_1.getChainAddresses)(chainId);
520
+ return [
521
+ {
522
+ to: generalAdapter1,
523
+ data: (0, viem_1.encodeFunctionData)({
524
+ abi: abis_js_1.generalAdapter1Abi,
525
+ functionName: "permit2TransferFrom",
526
+ args: [asset, recipient, amount],
527
+ }),
528
+ value: 0n,
529
+ skipRevert,
530
+ callbackHash: viem_1.zeroHash,
531
+ },
532
+ ];
533
+ }
534
+ BundlerAction.transferFrom2 = transferFrom2;
535
+ /**
536
+ * Encodes a GeneralAdapter1 ERC4626 deposit.
537
+ *
538
+ * @param chainId - Chain where the action will execute.
539
+ * @param erc4626 - ERC4626 vault address.
540
+ * @param assets - Asset amount to deposit.
541
+ * @param maxSharePrice - Maximum accepted share price in RAY.
542
+ * @param receiver - Recipient of minted vault shares.
543
+ * @param skipRevert - Whether Bundler3 should tolerate a revert.
544
+ * @returns Encoded Bundler3 calls.
545
+ *
546
+ * @example
547
+ * ```ts
548
+ * import { BundlerAction } from "@morpho-org/morpho-sdk/bundler";
549
+ *
550
+ * const vault = "0x186514400e52270cef3D80e1c6F8d10A75d47344";
551
+ * const recipient = "0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045";
552
+ *
553
+ * const calls = BundlerAction.erc4626Deposit(
554
+ * 1,
555
+ * vault,
556
+ * 100n,
557
+ * 1_000000000000000000000000000n,
558
+ * recipient,
559
+ * );
560
+ * ```
561
+ */
562
+ // biome-ignore lint/complexity/useMaxParams: TODO refactor to ≤2 params
563
+ function erc4626Deposit(chainId, erc4626, assets, maxSharePrice, receiver, skipRevert = false) {
564
+ const { bundler3: { generalAdapter1 }, } = (0, blue_sdk_1.getChainAddresses)(chainId);
565
+ return [
566
+ {
567
+ to: generalAdapter1,
568
+ data: (0, viem_1.encodeFunctionData)({
569
+ abi: abis_js_1.generalAdapter1Abi,
570
+ functionName: "erc4626Deposit",
571
+ args: [erc4626, assets, maxSharePrice, receiver],
572
+ }),
573
+ value: 0n,
574
+ skipRevert,
575
+ callbackHash: viem_1.zeroHash,
576
+ },
577
+ ];
578
+ }
579
+ BundlerAction.erc4626Deposit = erc4626Deposit;
580
+ /**
581
+ * Encodes a GeneralAdapter1 ERC4626 redeem.
582
+ *
583
+ * @param chainId - Chain where the action will execute.
584
+ * @param erc4626 - ERC4626 vault address.
585
+ * @param shares - Share amount to redeem.
586
+ * @param minSharePrice - Minimum accepted share price in RAY.
587
+ * @param receiver - Recipient of redeemed assets.
588
+ * @param owner - Owner of the shares being redeemed.
589
+ * @param skipRevert - Whether Bundler3 should tolerate a revert.
590
+ * @returns Encoded Bundler3 calls.
591
+ *
592
+ * @example
593
+ * ```ts
594
+ * import { BundlerAction } from "@morpho-org/morpho-sdk/bundler";
595
+ *
596
+ * const vault = "0x186514400e52270cef3D80e1c6F8d10A75d47344";
597
+ * const recipient = "0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045";
598
+ * const owner = recipient;
599
+ *
600
+ * const calls = BundlerAction.erc4626Redeem(
601
+ * 1,
602
+ * vault,
603
+ * 100n,
604
+ * 900000000000000000000000000n,
605
+ * recipient,
606
+ * owner,
607
+ * );
608
+ * ```
609
+ */
610
+ // biome-ignore lint/complexity/useMaxParams: TODO refactor to ≤2 params
611
+ function erc4626Redeem(chainId, erc4626, shares, minSharePrice, receiver, owner, skipRevert = false) {
612
+ const { bundler3: { generalAdapter1 }, } = (0, blue_sdk_1.getChainAddresses)(chainId);
613
+ return [
614
+ {
615
+ to: generalAdapter1,
616
+ data: (0, viem_1.encodeFunctionData)({
617
+ abi: abis_js_1.generalAdapter1Abi,
618
+ functionName: "erc4626Redeem",
619
+ args: [erc4626, shares, minSharePrice, receiver, owner],
620
+ }),
621
+ value: 0n,
622
+ skipRevert,
623
+ callbackHash: viem_1.zeroHash,
624
+ },
625
+ ];
626
+ }
627
+ BundlerAction.erc4626Redeem = erc4626Redeem;
628
+ /**
629
+ * Encodes a GeneralAdapter1 Morpho Blue supply-collateral call.
630
+ *
631
+ * @param chainId - Chain where the action will execute.
632
+ * @param market - Morpho Blue market parameters.
633
+ * @param assets - Collateral asset amount to supply.
634
+ * @param onBehalf - Account receiving the collateral position.
635
+ * @param callbackCalls - Calls executed in Morpho's callback.
636
+ * @param skipRevert - Whether Bundler3 should tolerate a revert.
637
+ * @returns Encoded Bundler3 calls.
638
+ *
639
+ * @example
640
+ * ```ts
641
+ * import { BundlerAction } from "@morpho-org/morpho-sdk/bundler";
642
+ *
643
+ * const loanToken = "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48";
644
+ * const collateralToken = "0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2";
645
+ * const oracle = "0x5f4eC3Df9cbd43714FE2740f5E3616155c5b8419";
646
+ * const irm = "0x870aC11D48B15DB9a138Cf899d20F13F79Ba00BC";
647
+ * const onBehalf = "0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045";
648
+ * const marketParams = {
649
+ * loanToken,
650
+ * collateralToken,
651
+ * oracle,
652
+ * irm,
653
+ * lltv: 860_000000000000000000n,
654
+ * };
655
+ *
656
+ * const calls = BundlerAction.morphoSupplyCollateral(
657
+ * 1,
658
+ * marketParams,
659
+ * 100n,
660
+ * onBehalf,
661
+ * [],
662
+ * );
663
+ * ```
664
+ */
665
+ // biome-ignore lint/complexity/useMaxParams: TODO refactor to ≤2 params
666
+ function morphoSupplyCollateral(chainId, market, assets, onBehalf, callbackCalls, skipRevert = false) {
667
+ const { bundler3: { generalAdapter1 }, } = (0, blue_sdk_1.getChainAddresses)(chainId);
668
+ const { callbackHash, reenterData } = encodeCallbackCalls(callbackCalls);
669
+ return [
670
+ {
671
+ to: generalAdapter1,
672
+ data: (0, viem_1.encodeFunctionData)({
673
+ abi: abis_js_1.generalAdapter1Abi,
674
+ functionName: "morphoSupplyCollateral",
675
+ args: [market, assets, onBehalf, reenterData],
676
+ }),
677
+ value: 0n,
678
+ skipRevert,
679
+ callbackHash,
680
+ },
681
+ ];
682
+ }
683
+ BundlerAction.morphoSupplyCollateral = morphoSupplyCollateral;
684
+ /**
685
+ * Encodes a GeneralAdapter1 Morpho Blue borrow call.
686
+ *
687
+ * @param chainId - Chain where the action will execute.
688
+ * @param market - Morpho Blue market parameters.
689
+ * @param assets - Borrow asset amount.
690
+ * @param shares - Borrow share amount.
691
+ * @param slippageAmount - Slippage guard amount.
692
+ * @param receiver - Recipient of borrowed assets.
693
+ * @param skipRevert - Whether Bundler3 should tolerate a revert.
694
+ * @returns Encoded Bundler3 calls.
695
+ *
696
+ * @example
697
+ * ```ts
698
+ * import { BundlerAction } from "@morpho-org/morpho-sdk/bundler";
699
+ *
700
+ * const loanToken = "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48";
701
+ * const collateralToken = "0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2";
702
+ * const oracle = "0x5f4eC3Df9cbd43714FE2740f5E3616155c5b8419";
703
+ * const irm = "0x870aC11D48B15DB9a138Cf899d20F13F79Ba00BC";
704
+ * const receiver = "0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045";
705
+ * const marketParams = {
706
+ * loanToken,
707
+ * collateralToken,
708
+ * oracle,
709
+ * irm,
710
+ * lltv: 860_000000000000000000n,
711
+ * };
712
+ *
713
+ * const calls = BundlerAction.morphoBorrow(
714
+ * 1,
715
+ * marketParams,
716
+ * 100n,
717
+ * 0n,
718
+ * 1_000000000000000000000000000n,
719
+ * receiver,
720
+ * );
721
+ * ```
722
+ */
723
+ // biome-ignore lint/complexity/useMaxParams: TODO refactor to ≤2 params
724
+ function morphoBorrow(chainId, market, assets, shares, slippageAmount, receiver, skipRevert = false) {
725
+ const { bundler3: { generalAdapter1 }, } = (0, blue_sdk_1.getChainAddresses)(chainId);
726
+ return [
727
+ {
728
+ to: generalAdapter1,
729
+ data: (0, viem_1.encodeFunctionData)({
730
+ abi: abis_js_1.generalAdapter1Abi,
731
+ functionName: "morphoBorrow",
732
+ args: [market, assets, shares, slippageAmount, receiver],
733
+ }),
734
+ value: 0n,
735
+ skipRevert,
736
+ callbackHash: viem_1.zeroHash,
737
+ },
738
+ ];
739
+ }
740
+ BundlerAction.morphoBorrow = morphoBorrow;
741
+ /**
742
+ * Encodes a GeneralAdapter1 Morpho Blue repay call.
743
+ *
744
+ * @param chainId - Chain where the action will execute.
745
+ * @param market - Morpho Blue market parameters.
746
+ * @param assets - Repay asset amount.
747
+ * @param shares - Repay share amount.
748
+ * @param slippageAmount - Slippage guard amount.
749
+ * @param onBehalf - Account whose borrow is repaid.
750
+ * @param callbackCalls - Calls executed in Morpho's callback.
751
+ * @param skipRevert - Whether Bundler3 should tolerate a revert.
752
+ * @returns Encoded Bundler3 calls.
753
+ *
754
+ * @example
755
+ * ```ts
756
+ * import { BundlerAction } from "@morpho-org/morpho-sdk/bundler";
757
+ *
758
+ * const loanToken = "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48";
759
+ * const collateralToken = "0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2";
760
+ * const oracle = "0x5f4eC3Df9cbd43714FE2740f5E3616155c5b8419";
761
+ * const irm = "0x870aC11D48B15DB9a138Cf899d20F13F79Ba00BC";
762
+ * const onBehalf = "0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045";
763
+ * const marketParams = {
764
+ * loanToken,
765
+ * collateralToken,
766
+ * oracle,
767
+ * irm,
768
+ * lltv: 860_000000000000000000n,
769
+ * };
770
+ *
771
+ * const calls = BundlerAction.morphoRepay(
772
+ * 1,
773
+ * marketParams,
774
+ * 100n,
775
+ * 0n,
776
+ * 1_000000000000000000000000000n,
777
+ * onBehalf,
778
+ * [],
779
+ * );
780
+ * ```
781
+ */
782
+ // biome-ignore lint/complexity/useMaxParams: TODO refactor to ≤2 params
783
+ function morphoRepay(chainId, market, assets, shares, slippageAmount, onBehalf, callbackCalls, skipRevert = false) {
784
+ const { bundler3: { generalAdapter1 }, } = (0, blue_sdk_1.getChainAddresses)(chainId);
785
+ const { callbackHash, reenterData } = encodeCallbackCalls(callbackCalls);
786
+ return [
787
+ {
788
+ to: generalAdapter1,
789
+ data: (0, viem_1.encodeFunctionData)({
790
+ abi: abis_js_1.generalAdapter1Abi,
791
+ functionName: "morphoRepay",
792
+ args: [market, assets, shares, slippageAmount, onBehalf, reenterData],
793
+ }),
794
+ value: 0n,
795
+ skipRevert,
796
+ callbackHash,
797
+ },
798
+ ];
799
+ }
800
+ BundlerAction.morphoRepay = morphoRepay;
801
+ /**
802
+ * Encodes a GeneralAdapter1 Morpho Blue withdraw-collateral call.
803
+ *
804
+ * @param chainId - Chain where the action will execute.
805
+ * @param market - Morpho Blue market parameters.
806
+ * @param assets - Collateral asset amount to withdraw.
807
+ * @param receiver - Recipient of withdrawn collateral.
808
+ * @param skipRevert - Whether Bundler3 should tolerate a revert.
809
+ * @returns Encoded Bundler3 calls.
810
+ *
811
+ * @example
812
+ * ```ts
813
+ * import { BundlerAction } from "@morpho-org/morpho-sdk/bundler";
814
+ *
815
+ * const loanToken = "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48";
816
+ * const collateralToken = "0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2";
817
+ * const oracle = "0x5f4eC3Df9cbd43714FE2740f5E3616155c5b8419";
818
+ * const irm = "0x870aC11D48B15DB9a138Cf899d20F13F79Ba00BC";
819
+ * const receiver = "0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045";
820
+ * const marketParams = {
821
+ * loanToken,
822
+ * collateralToken,
823
+ * oracle,
824
+ * irm,
825
+ * lltv: 860_000000000000000000n,
826
+ * };
827
+ *
828
+ * const calls = BundlerAction.morphoWithdrawCollateral(
829
+ * 1,
830
+ * marketParams,
831
+ * 100n,
832
+ * receiver,
833
+ * );
834
+ * ```
835
+ */
836
+ // biome-ignore lint/complexity/useMaxParams: TODO refactor to ≤2 params
837
+ function morphoWithdrawCollateral(chainId, market, assets, receiver, skipRevert = false) {
838
+ const { bundler3: { generalAdapter1 }, } = (0, blue_sdk_1.getChainAddresses)(chainId);
839
+ return [
840
+ {
841
+ to: generalAdapter1,
842
+ data: (0, viem_1.encodeFunctionData)({
843
+ abi: abis_js_1.generalAdapter1Abi,
844
+ functionName: "morphoWithdrawCollateral",
845
+ args: [market, assets, receiver],
846
+ }),
847
+ value: 0n,
848
+ skipRevert,
849
+ callbackHash: viem_1.zeroHash,
850
+ },
851
+ ];
852
+ }
853
+ BundlerAction.morphoWithdrawCollateral = morphoWithdrawCollateral;
854
+ /**
855
+ * Encodes a PublicAllocator reallocation call.
856
+ *
857
+ * @param chainId - Chain where the action will execute.
858
+ * @param vault - Vault to reallocate.
859
+ * @param fee - Public allocator fee.
860
+ * @param withdrawals - Market withdrawals performed before supply.
861
+ * @param supplyMarketParams - Target supply market parameters.
862
+ * @param skipRevert - Whether Bundler3 should tolerate a revert.
863
+ * @returns Encoded Bundler3 calls.
864
+ * @throws {BundlerErrors.UnexpectedAction} when the PublicAllocator is unavailable on the chain.
865
+ *
866
+ * @example
867
+ * ```ts
868
+ * import { BundlerAction } from "@morpho-org/morpho-sdk/bundler";
869
+ *
870
+ * const loanToken = "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48";
871
+ * const collateralToken = "0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2";
872
+ * const oracle = "0x5f4eC3Df9cbd43714FE2740f5E3616155c5b8419";
873
+ * const irm = "0x870aC11D48B15DB9a138Cf899d20F13F79Ba00BC";
874
+ * const vault = "0x186514400e52270cef3D80e1c6F8d10A75d47344";
875
+ * const marketParams = {
876
+ * loanToken,
877
+ * collateralToken,
878
+ * oracle,
879
+ * irm,
880
+ * lltv: 860_000000000000000000n,
881
+ * };
882
+ *
883
+ * const calls = BundlerAction.publicAllocatorReallocateTo(
884
+ * 1,
885
+ * vault,
886
+ * 0n,
887
+ * [{ marketParams, amount: 100n }],
888
+ * marketParams,
889
+ * );
890
+ * ```
891
+ */
892
+ // biome-ignore lint/complexity/useMaxParams: TODO refactor to ≤2 params
893
+ function publicAllocatorReallocateTo(chainId, vault, fee, withdrawals, supplyMarketParams, skipRevert = false) {
894
+ const { publicAllocator } = (0, blue_sdk_1.getChainAddresses)(chainId);
895
+ if (publicAllocator == null) {
896
+ throw new error_js_1.BundlerErrors.UnexpectedAction("reallocateTo", chainId);
897
+ }
898
+ return [
899
+ {
900
+ to: publicAllocator,
901
+ data: (0, viem_1.encodeFunctionData)({
902
+ abi: blue_sdk_viem_1.publicAllocatorAbi,
903
+ functionName: "reallocateTo",
904
+ args: [vault, withdrawals, supplyMarketParams],
905
+ }),
906
+ value: fee,
907
+ skipRevert,
908
+ callbackHash: viem_1.zeroHash,
909
+ },
910
+ ];
911
+ }
912
+ BundlerAction.publicAllocatorReallocateTo = publicAllocatorReallocateTo;
913
+ /**
914
+ * Encodes a GeneralAdapter1 native-token wrap call.
915
+ *
916
+ * @param chainId - Chain where the action will execute.
917
+ * @param amount - Native-token amount to wrap.
918
+ * @param recipient - Recipient of wrapped native tokens.
919
+ * @param skipRevert - Whether Bundler3 should tolerate a revert.
920
+ * @returns Encoded Bundler3 calls.
921
+ *
922
+ * @example
923
+ * ```ts
924
+ * import { BundlerAction } from "@morpho-org/morpho-sdk/bundler";
925
+ *
926
+ * const recipient = "0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045";
927
+ *
928
+ * const calls = BundlerAction.wrapNative(
929
+ * 1,
930
+ * 1_000000000000000000n,
931
+ * recipient,
932
+ * );
933
+ * ```
934
+ */
935
+ // biome-ignore lint/complexity/useMaxParams: TODO refactor to ≤2 params
936
+ function wrapNative(chainId, amount, recipient, skipRevert = false) {
937
+ const { bundler3: { generalAdapter1 }, } = (0, blue_sdk_1.getChainAddresses)(chainId);
938
+ return [
939
+ {
940
+ to: generalAdapter1,
941
+ data: (0, viem_1.encodeFunctionData)({
942
+ abi: abis_js_1.generalAdapter1Abi,
943
+ functionName: "wrapNative",
944
+ args: [amount, recipient],
945
+ }),
946
+ value: 0n,
947
+ skipRevert,
948
+ callbackHash: viem_1.zeroHash,
949
+ },
950
+ ];
951
+ }
952
+ BundlerAction.wrapNative = wrapNative;
953
+ })(BundlerAction || (exports.BundlerAction = BundlerAction = {}));