@morpho-org/bundler-sdk-viem 1.12.4

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.
@@ -0,0 +1,836 @@
1
+ import { aaveV2MigrationBundlerAbi, aaveV3MigrationBundlerAbi, aaveV3OptimizerMigrationBundlerAbi, compoundV2MigrationBundlerAbi, compoundV3MigrationBundlerAbi, erc20WrapperBundlerAbi, erc4626BundlerAbi, ethereumPermitBundlerAbi, morphoBundlerAbi, permit2BundlerAbi, permitBundlerAbi, stEthBundlerAbi, transferBundlerAbi, urdBundlerAbi, wNativeBundlerAbi, } from "./abis.js";
2
+ import { encodeAbiParameters, encodeFunctionData, parseSignature, } from "viem";
3
+ import { BundlerErrors } from "./errors.js";
4
+ /**
5
+ * Namespace to easily encode calls to the Bundler contract, using ethers.
6
+ */
7
+ export var BundlerAction;
8
+ (function (BundlerAction) {
9
+ function encode({ type, args }) {
10
+ switch (type) {
11
+ /* ERC20 */
12
+ case "nativeTransfer": {
13
+ return BundlerAction.nativeTransfer(...args);
14
+ }
15
+ case "erc20Transfer": {
16
+ return BundlerAction.erc20Transfer(...args);
17
+ }
18
+ case "erc20TransferFrom": {
19
+ return BundlerAction.erc20TransferFrom(...args);
20
+ }
21
+ /* ERC20Wrapper */
22
+ case "erc20WrapperDepositFor": {
23
+ return BundlerAction.erc20WrapperDepositFor(...args);
24
+ }
25
+ case "erc20WrapperWithdrawTo": {
26
+ return BundlerAction.erc20WrapperWithdrawTo(...args);
27
+ }
28
+ /* Permit */
29
+ case "permit": {
30
+ const [asset, amount, deadline, signature, skipRevert = true] = args;
31
+ if (signature === null)
32
+ throw new BundlerErrors.MissingSignature();
33
+ return BundlerAction.permit(asset, amount, deadline, signature, skipRevert);
34
+ }
35
+ case "permitDai": {
36
+ const [nonce, expiry, allowed, signature, skipRevert = true] = args;
37
+ if (signature === null)
38
+ throw new BundlerErrors.MissingSignature();
39
+ return BundlerAction.permitDai(nonce, expiry, allowed, signature, skipRevert);
40
+ }
41
+ /* Permit2 */
42
+ case "approve2": {
43
+ const [permitSingle, signature, skipRevert = true] = args;
44
+ if (signature === null)
45
+ throw new BundlerErrors.MissingSignature();
46
+ return BundlerAction.approve2(permitSingle, signature, skipRevert);
47
+ }
48
+ case "transferFrom2": {
49
+ return BundlerAction.transferFrom2(...args);
50
+ }
51
+ /* ERC4626 */
52
+ case "erc4626Mint": {
53
+ return BundlerAction.erc4626Mint(...args);
54
+ }
55
+ case "erc4626Deposit": {
56
+ return BundlerAction.erc4626Deposit(...args);
57
+ }
58
+ case "erc4626Withdraw": {
59
+ return BundlerAction.erc4626Withdraw(...args);
60
+ }
61
+ case "erc4626Redeem": {
62
+ return BundlerAction.erc4626Redeem(...args);
63
+ }
64
+ /* Morpho */
65
+ case "morphoSetAuthorizationWithSig": {
66
+ const [authorization, signature, skipRevert = true] = args;
67
+ if (signature === null)
68
+ throw new BundlerErrors.MissingSignature();
69
+ return BundlerAction.morphoSetAuthorizationWithSig(authorization, signature, skipRevert);
70
+ }
71
+ case "morphoSupply": {
72
+ const [market, assets, shares, slippageAmount, onBehalf, onMorphoSupply,] = args;
73
+ return BundlerAction.morphoSupply(market, assets, shares, slippageAmount, onBehalf, onMorphoSupply.map(BundlerAction.encode));
74
+ }
75
+ case "morphoSupplyCollateral": {
76
+ const [market, amount, onBehalf, onMorphoSupplyCollateral] = args;
77
+ return BundlerAction.morphoSupplyCollateral(market, amount, onBehalf, onMorphoSupplyCollateral.map(BundlerAction.encode));
78
+ }
79
+ case "morphoBorrow": {
80
+ const [market, assets, shares, slippageAmount, receiver] = args;
81
+ return BundlerAction.morphoBorrow(market, assets, shares, slippageAmount, receiver);
82
+ }
83
+ case "morphoRepay": {
84
+ const [market, assets, shares, slippageAmount, onBehalf, onMorphoRepay,] = args;
85
+ return BundlerAction.morphoRepay(market, assets, shares, slippageAmount, onBehalf, onMorphoRepay.map(BundlerAction.encode));
86
+ }
87
+ case "morphoWithdraw": {
88
+ const [market, assets, shares, slippageAmount, receiver] = args;
89
+ return BundlerAction.morphoWithdraw(market, assets, shares, slippageAmount, receiver);
90
+ }
91
+ case "morphoWithdrawCollateral": {
92
+ const [market, amount, receiver] = args;
93
+ return BundlerAction.morphoWithdrawCollateral(market, amount, receiver);
94
+ }
95
+ /* MetaMorpho */
96
+ case "reallocateTo": {
97
+ const [publicAllocator, vault, value, withdrawals, supplyMarket] = args;
98
+ return BundlerAction.metaMorphoReallocateTo(publicAllocator, vault, value, withdrawals, supplyMarket);
99
+ }
100
+ /* Universal Rewards Distributor */
101
+ case "urdClaim": {
102
+ const [distributor, account, reward, amount, proof, skipRevert = true] = args;
103
+ return BundlerAction.urdClaim(distributor, account, reward, amount, proof, skipRevert);
104
+ }
105
+ /* Wrapped Native */
106
+ case "wrapNative": {
107
+ return BundlerAction.wrapNative(...args);
108
+ }
109
+ case "unwrapNative": {
110
+ return BundlerAction.unwrapNative(...args);
111
+ }
112
+ /* stETH */
113
+ case "stakeEth": {
114
+ return BundlerAction.stakeEth(...args);
115
+ }
116
+ /* Wrapped stETH */
117
+ case "wrapStEth": {
118
+ return BundlerAction.wrapStEth(...args);
119
+ }
120
+ case "unwrapStEth": {
121
+ return BundlerAction.unwrapStEth(...args);
122
+ }
123
+ /* AaveV2 */
124
+ case "aaveV2Repay": {
125
+ const [asset, amount, rateMode = 1n] = args;
126
+ return BundlerAction.aaveV2Repay(asset, amount, rateMode);
127
+ }
128
+ case "aaveV2Withdraw": {
129
+ return BundlerAction.aaveV2Withdraw(...args);
130
+ }
131
+ /* AaveV3 */
132
+ case "aaveV3Repay": {
133
+ const [asset, amount, rateMode = 1n] = args;
134
+ return BundlerAction.aaveV3Repay(asset, amount, rateMode);
135
+ }
136
+ case "aaveV3Withdraw": {
137
+ return BundlerAction.aaveV3Withdraw(...args);
138
+ }
139
+ /* AaveV3 Optimizer */
140
+ case "aaveV3OptimizerRepay": {
141
+ return BundlerAction.aaveV3OptimizerRepay(...args);
142
+ }
143
+ case "aaveV3OptimizerWithdraw": {
144
+ const [underlying, amount, maxIterations = 4n] = args;
145
+ return BundlerAction.aaveV3OptimizerWithdraw(underlying, amount, maxIterations);
146
+ }
147
+ case "aaveV3OptimizerWithdrawCollateral": {
148
+ return BundlerAction.aaveV3OptimizerWithdrawCollateral(...args);
149
+ }
150
+ case "aaveV3OptimizerApproveManagerWithSig": {
151
+ const [isApproved, nonce, deadline, signature, skipRevert = true] = args;
152
+ if (signature === null)
153
+ throw new BundlerErrors.MissingSignature();
154
+ return BundlerAction.aaveV3OptimizerApproveManagerWithSig(isApproved, nonce, deadline, signature, skipRevert);
155
+ }
156
+ /* CompoundV2 */
157
+ case "compoundV2Repay": {
158
+ return BundlerAction.compoundV2Repay(...args);
159
+ }
160
+ case "compoundV2Redeem": {
161
+ return BundlerAction.compoundV2Redeem(...args);
162
+ }
163
+ /* CompoundV3 */
164
+ case "compoundV3Repay": {
165
+ return BundlerAction.compoundV3Repay(...args);
166
+ }
167
+ case "compoundV3WithdrawFrom": {
168
+ return BundlerAction.compoundV3WithdrawFrom(...args);
169
+ }
170
+ case "compoundV3AllowBySig": {
171
+ const [instance, isAllowed, nonce, expiry, signature, skipRevert = true,] = args;
172
+ if (signature === null)
173
+ throw new BundlerErrors.MissingSignature();
174
+ return BundlerAction.compoundV3AllowBySig(instance, isAllowed, nonce, expiry, signature, skipRevert);
175
+ }
176
+ }
177
+ throw Error(`unhandled action encoding: ${type}`);
178
+ }
179
+ BundlerAction.encode = encode;
180
+ /* ERC20 */
181
+ /**
182
+ * Encodes a call to the Bundler to transfer native tokens (ETH on ethereum, MATIC on polygon, etc).
183
+ * @param recipient The address to send native tokens to.
184
+ * @param amount The amount of native tokens to send (in wei).
185
+ */
186
+ function nativeTransfer(recipient, amount) {
187
+ return encodeFunctionData({
188
+ abi: transferBundlerAbi,
189
+ functionName: "nativeTransfer",
190
+ args: [recipient, amount],
191
+ });
192
+ }
193
+ BundlerAction.nativeTransfer = nativeTransfer;
194
+ /**
195
+ * Encodes a call to the Bundler to transfer ERC20 tokens.
196
+ * @param asset The address of the ERC20 token to transfer.
197
+ * @param recipient The address to send tokens to.
198
+ * @param amount The amount of tokens to send.
199
+ */
200
+ function erc20Transfer(asset, recipient, amount) {
201
+ return encodeFunctionData({
202
+ abi: transferBundlerAbi,
203
+ functionName: "erc20Transfer",
204
+ args: [asset, recipient, amount],
205
+ });
206
+ }
207
+ BundlerAction.erc20Transfer = erc20Transfer;
208
+ /**
209
+ * Encodes a call to the Bundler to transfer ERC20 tokens from the sender to the Bundler.
210
+ * @param asset The address of the ERC20 token to transfer.
211
+ * @param amount The amount of tokens to send.
212
+ */
213
+ function erc20TransferFrom(asset, amount) {
214
+ return encodeFunctionData({
215
+ abi: transferBundlerAbi,
216
+ functionName: "erc20TransferFrom",
217
+ args: [asset, amount],
218
+ });
219
+ }
220
+ BundlerAction.erc20TransferFrom = erc20TransferFrom;
221
+ /* Permit */
222
+ /**
223
+ * Encodes a call to the Bundler to permit an ERC20 token.
224
+ * @param asset The address of the ERC20 token to permit.
225
+ * @param amount The amount of tokens to permit.
226
+ * @param deadline The timestamp until which the signature is valid.
227
+ * @param signature The Ethers signature to permit the tokens.
228
+ * @param skipRevert Whether to allow the permit to revert without making the whole multicall revert.
229
+ */
230
+ function permit(asset, amount, deadline, signature, skipRevert) {
231
+ const { r, s, yParity } = parseSignature(signature);
232
+ return encodeFunctionData({
233
+ abi: permitBundlerAbi,
234
+ functionName: "permit",
235
+ args: [asset, amount, deadline, yParity + 27, r, s, skipRevert],
236
+ });
237
+ }
238
+ BundlerAction.permit = permit;
239
+ /**
240
+ * Encodes a call to the Bundler to permit DAI.
241
+ * @param nonce The permit nonce used.
242
+ * @param expiry The timestamp until which the signature is valid.
243
+ * @param allowed The amount of DAI to permit.
244
+ * @param signature The Ethers signature to permit the tokens.
245
+ * @param skipRevert Whether to allow the permit to revert without making the whole multicall revert.
246
+ */
247
+ function permitDai(nonce, expiry, allowed, signature, skipRevert) {
248
+ const { r, s, yParity } = parseSignature(signature);
249
+ return encodeFunctionData({
250
+ abi: ethereumPermitBundlerAbi,
251
+ functionName: "permitDai",
252
+ args: [nonce, expiry, allowed, yParity + 27, r, s, skipRevert],
253
+ });
254
+ }
255
+ BundlerAction.permitDai = permitDai;
256
+ /* Permit2 */
257
+ /**
258
+ * Encodes a call to the Bundler to permit ERC20 tokens via Permit2.
259
+ * @param permitSingle The permit details to submit to Permit2.
260
+ * @param signature The Ethers signature to permit the tokens.
261
+ * @param skipRevert Whether to allow the permit to revert without making the whole multicall revert.
262
+ */
263
+ function approve2(permitSingle, signature, skipRevert) {
264
+ return encodeFunctionData({
265
+ abi: permit2BundlerAbi,
266
+ functionName: "approve2",
267
+ args: [permitSingle, signature, skipRevert],
268
+ });
269
+ }
270
+ BundlerAction.approve2 = approve2;
271
+ /**
272
+ * Encodes a call to the Bundler to transfer ERC20 tokens via Permit2 from the sender to the Bundler.
273
+ * @param asset The address of the ERC20 token to transfer.
274
+ * @param amount The amount of tokens to send.
275
+ */
276
+ function transferFrom2(asset, amount) {
277
+ return encodeFunctionData({
278
+ abi: permit2BundlerAbi,
279
+ functionName: "transferFrom2",
280
+ args: [asset, amount],
281
+ });
282
+ }
283
+ BundlerAction.transferFrom2 = transferFrom2;
284
+ /* ERC20 Wrapper */
285
+ /**
286
+ * Encodes a call to the Bundler to wrap ERC20 tokens via the provided ERC20Wrapper.
287
+ * @param wrapper The address of the ERC20 wrapper token.
288
+ * @param amount The amount of tokens to send.
289
+ */
290
+ function erc20WrapperDepositFor(wrapper, amount) {
291
+ return encodeFunctionData({
292
+ abi: erc20WrapperBundlerAbi,
293
+ functionName: "erc20WrapperDepositFor",
294
+ args: [wrapper, amount],
295
+ });
296
+ }
297
+ BundlerAction.erc20WrapperDepositFor = erc20WrapperDepositFor;
298
+ /**
299
+ * Encodes a call to the Bundler to unwrap ERC20 tokens from the provided ERC20Wrapper.
300
+ * @param wrapper The address of the ERC20 wrapper token.
301
+ * @param account The address to send the underlying ERC20 tokens.
302
+ * @param amount The amount of tokens to send.
303
+ */
304
+ function erc20WrapperWithdrawTo(wrapper, account, amount) {
305
+ return encodeFunctionData({
306
+ abi: erc20WrapperBundlerAbi,
307
+ functionName: "erc20WrapperWithdrawTo",
308
+ args: [wrapper, account, amount],
309
+ });
310
+ }
311
+ BundlerAction.erc20WrapperWithdrawTo = erc20WrapperWithdrawTo;
312
+ /* ERC4626 */
313
+ /**
314
+ * Encodes a call to the Bundler to mint shares of the provided ERC4626 vault.
315
+ * @param erc4626 The address of the ERC4626 vault.
316
+ * @param shares The amount of shares to mint.
317
+ * @param maxAssets The maximum amount of assets to deposit (protects the sender from unexpected slippage).
318
+ * @param receiver The address to send the shares to.
319
+ */
320
+ function erc4626Mint(erc4626, shares, maxAssets, receiver) {
321
+ return encodeFunctionData({
322
+ abi: erc4626BundlerAbi,
323
+ functionName: "erc4626Mint",
324
+ args: [erc4626, shares, maxAssets, receiver],
325
+ });
326
+ }
327
+ BundlerAction.erc4626Mint = erc4626Mint;
328
+ /**
329
+ * Encodes a call to the Bundler to deposit assets into the provided ERC4626 vault.
330
+ * @param erc4626 The address of the ERC4626 vault.
331
+ * @param assets The amount of assets to deposit.
332
+ * @param minShares The minimum amount of shares to mint (protects the sender from unexpected slippage).
333
+ * @param receiver The address to send the shares to.
334
+ */
335
+ function erc4626Deposit(erc4626, assets, minShares, receiver) {
336
+ return encodeFunctionData({
337
+ abi: erc4626BundlerAbi,
338
+ functionName: "erc4626Deposit",
339
+ args: [erc4626, assets, minShares, receiver],
340
+ });
341
+ }
342
+ BundlerAction.erc4626Deposit = erc4626Deposit;
343
+ /**
344
+ * Encodes a call to the Bundler to withdraw assets from the provided ERC4626 vault.
345
+ * @param erc4626 The address of the ERC4626 vault.
346
+ * @param assets The amount of assets to withdraw.
347
+ * @param maxShares The maximum amount of shares to redeem (protects the sender from unexpected slippage).
348
+ * @param receiver The address to send the assets to.
349
+ */
350
+ function erc4626Withdraw(erc4626, assets, maxShares, receiver, owner) {
351
+ return encodeFunctionData({
352
+ abi: erc4626BundlerAbi,
353
+ functionName: "erc4626Withdraw",
354
+ args: [erc4626, assets, maxShares, receiver, owner],
355
+ });
356
+ }
357
+ BundlerAction.erc4626Withdraw = erc4626Withdraw;
358
+ /**
359
+ * Encodes a call to the Bundler to redeem shares from the provided ERC4626 vault.
360
+ * @param erc4626 The address of the ERC4626 vault.
361
+ * @param shares The amount of shares to redeem.
362
+ * @param minAssets The minimum amount of assets to withdraw (protects the sender from unexpected slippage).
363
+ * @param receiver The address to send the assets to.
364
+ */
365
+ function erc4626Redeem(erc4626, shares, minAssets, receiver, owner) {
366
+ return encodeFunctionData({
367
+ abi: erc4626BundlerAbi,
368
+ functionName: "erc4626Redeem",
369
+ args: [erc4626, shares, minAssets, receiver, owner],
370
+ });
371
+ }
372
+ BundlerAction.erc4626Redeem = erc4626Redeem;
373
+ /* Morpho */
374
+ /**
375
+ * Encodes a call to the Bundler to authorize an account on Morpho Blue.
376
+ * @param authorization The authorization details to submit to Morpho Blue.
377
+ * @param signature The Ethers signature to authorize the account.
378
+ * @param skipRevert Whether to allow the authorization call to revert without making the whole multicall revert.
379
+ */
380
+ function morphoSetAuthorizationWithSig(authorization, signature, skipRevert) {
381
+ const { r, s, yParity } = parseSignature(signature);
382
+ return encodeFunctionData({
383
+ abi: morphoBundlerAbi,
384
+ functionName: "morphoSetAuthorizationWithSig",
385
+ args: [authorization, { v: yParity + 27, r, s }, skipRevert],
386
+ });
387
+ }
388
+ BundlerAction.morphoSetAuthorizationWithSig = morphoSetAuthorizationWithSig;
389
+ /**
390
+ * Encodes a call to the Bundler to supply to a Morpho Blue market.
391
+ * @param market The market params to supply to.
392
+ * @param assets The amount of assets to supply.
393
+ * @param shares The amount of supply shares to mint.
394
+ * @param slippageAmount The maximum (resp. minimum) amount of assets (resp. supply shares) to supply (resp. mint) (protects the sender from unexpected slippage).
395
+ * @param onBehalf The address to supply on behalf of.
396
+ * @param callbackCalls The array of calls to execute inside Morpho Blue's `onMorphoSupply` callback.
397
+ */
398
+ function morphoSupply(market, assets, shares, slippageAmount, onBehalf, callbackCalls) {
399
+ return encodeFunctionData({
400
+ abi: morphoBundlerAbi,
401
+ functionName: "morphoSupply",
402
+ args: [
403
+ market,
404
+ assets,
405
+ shares,
406
+ slippageAmount,
407
+ onBehalf,
408
+ encodeAbiParameters([{ type: "bytes[]" }], [callbackCalls]),
409
+ ],
410
+ });
411
+ }
412
+ BundlerAction.morphoSupply = morphoSupply;
413
+ /**
414
+ * Encodes a call to the Bundler to supply collateral to a Morpho Blue market.
415
+ * @param market The market params to supply to.
416
+ * @param assets The amount of assets to supply.
417
+ * @param onBehalf The address to supply on behalf of.
418
+ * @param callbackCalls The array of calls to execute inside Morpho Blue's `onMorphoSupplyCollateral` callback.
419
+ */
420
+ function morphoSupplyCollateral(market, assets, onBehalf, callbackCalls) {
421
+ return encodeFunctionData({
422
+ abi: morphoBundlerAbi,
423
+ functionName: "morphoSupplyCollateral",
424
+ args: [
425
+ market,
426
+ assets,
427
+ onBehalf,
428
+ encodeAbiParameters([{ type: "bytes[]" }], [callbackCalls]),
429
+ ],
430
+ });
431
+ }
432
+ BundlerAction.morphoSupplyCollateral = morphoSupplyCollateral;
433
+ /**
434
+ * Encodes a call to the Bundler to borrow from a Morpho Blue market.
435
+ * @param market The market params to borrow from.
436
+ * @param assets The amount of assets to borrow.
437
+ * @param shares The amount of borrow shares to mint.
438
+ * @param slippageAmount The minimum (resp. maximum) amount of assets (resp. borrow shares) to borrow (resp. mint) (protects the sender from unexpected slippage).
439
+ * @param receiver The address to send borrowed tokens to.
440
+ */
441
+ function morphoBorrow(market, assets, shares, slippageAmount, receiver) {
442
+ return encodeFunctionData({
443
+ abi: morphoBundlerAbi,
444
+ functionName: "morphoBorrow",
445
+ args: [market, assets, shares, slippageAmount, receiver],
446
+ });
447
+ }
448
+ BundlerAction.morphoBorrow = morphoBorrow;
449
+ /**
450
+ * Encodes a call to the Bundler to repay to a Morpho Blue market.
451
+ * @param market The market params to repay to.
452
+ * @param assets The amount of assets to repay.
453
+ * @param shares The amount of borrow shares to redeem.
454
+ * @param slippageAmount The maximum (resp. minimum) amount of assets (resp. borrow shares) to repay (resp. redeem) (protects the sender from unexpected slippage).
455
+ * @param onBehalf The address to repay on behalf of.
456
+ * @param callbackCalls The array of calls to execute inside Morpho Blue's `onMorphoSupply` callback.
457
+ */
458
+ function morphoRepay(market, assets, shares, slippageAmount, onBehalf, callbackCalls) {
459
+ return encodeFunctionData({
460
+ abi: morphoBundlerAbi,
461
+ functionName: "morphoRepay",
462
+ args: [
463
+ market,
464
+ assets,
465
+ shares,
466
+ slippageAmount,
467
+ onBehalf,
468
+ encodeAbiParameters([{ type: "bytes[]" }], [callbackCalls]),
469
+ ],
470
+ });
471
+ }
472
+ BundlerAction.morphoRepay = morphoRepay;
473
+ /**
474
+ * Encodes a call to the Bundler to withdraw from a Morpho Blue market.
475
+ * @param market The market params to withdraw from.
476
+ * @param assets The amount of assets to withdraw.
477
+ * @param shares The amount of supply shares to redeem.
478
+ * @param slippageAmount The minimum (resp. maximum) amount of assets (resp. supply shares) to withdraw (resp. redeem) (protects the sender from unexpected slippage).
479
+ * @param receiver The address to send withdrawn tokens to.
480
+ */
481
+ function morphoWithdraw(market, assets, shares, slippageAmount, receiver) {
482
+ return encodeFunctionData({
483
+ abi: morphoBundlerAbi,
484
+ functionName: "morphoWithdraw",
485
+ args: [market, assets, shares, slippageAmount, receiver],
486
+ });
487
+ }
488
+ BundlerAction.morphoWithdraw = morphoWithdraw;
489
+ /**
490
+ * Encodes a call to the Bundler to withdraw collateral from a Morpho Blue market.
491
+ * @param market The market params to withdraw from.
492
+ * @param assets The amount of assets to withdraw.
493
+ * @param receiver The address to send withdrawn tokens to.
494
+ */
495
+ function morphoWithdrawCollateral(market, assets, receiver) {
496
+ return encodeFunctionData({
497
+ abi: morphoBundlerAbi,
498
+ functionName: "morphoWithdrawCollateral",
499
+ args: [market, assets, receiver],
500
+ });
501
+ }
502
+ BundlerAction.morphoWithdrawCollateral = morphoWithdrawCollateral;
503
+ /**
504
+ * Encodes a call to the Bundler to flash loan from Morpho Blue.
505
+ * @param asset The address of the ERC20 token to flash loan.
506
+ * @param amount The amount of tokens to flash loan.
507
+ * @param callbackCalls The array of calls to execute inside Morpho Blue's `onMorphoFlashLoan` callback.
508
+ */
509
+ function morphoFlashLoan(asset, amount, callbackCalls) {
510
+ return encodeFunctionData({
511
+ abi: morphoBundlerAbi,
512
+ functionName: "morphoFlashLoan",
513
+ args: [
514
+ asset,
515
+ amount,
516
+ encodeAbiParameters([{ type: "bytes[]" }], [callbackCalls]),
517
+ ],
518
+ });
519
+ }
520
+ BundlerAction.morphoFlashLoan = morphoFlashLoan;
521
+ /**
522
+ * Encodes a call to the Bundler to trigger a public reallocation on the PublicAllocator.
523
+ * @param publicAllocator The address of the PublicAllocator to use.
524
+ * @param vault The vault to reallocate.
525
+ * @param value The value of the call. Can be used to pay the vault reallocation fees.
526
+ * @param withdrawals The array of withdrawals to perform, before supplying everything to the supply market.
527
+ * @param supplyMarketParams The market params to reallocate to.
528
+ */
529
+ function metaMorphoReallocateTo(publicAllocator, vault, value, withdrawals, supplyMarketParams) {
530
+ return encodeFunctionData({
531
+ abi: morphoBundlerAbi,
532
+ functionName: "reallocateTo",
533
+ args: [publicAllocator, vault, value, withdrawals, supplyMarketParams],
534
+ });
535
+ }
536
+ BundlerAction.metaMorphoReallocateTo = metaMorphoReallocateTo;
537
+ /* Universal Rewards Distributor */
538
+ /**
539
+ * Encodes a call to the Bundler to claim rewards from the Universal Rewards Distributor.
540
+ * @param distributor The address of the distributor to claim rewards from.
541
+ * @param account The address to claim rewards for.
542
+ * @param reward The address of the reward token to claim.
543
+ * @param amount The amount of rewards to claim.
544
+ * @param proof The Merkle proof to claim the rewards.
545
+ * @param skipRevert Whether to allow the claim to revert without making the whole multicall revert.
546
+ */
547
+ function urdClaim(distributor, account, reward, amount, proof, skipRevert) {
548
+ return encodeFunctionData({
549
+ abi: urdBundlerAbi,
550
+ functionName: "urdClaim",
551
+ args: [distributor, account, reward, amount, proof, skipRevert],
552
+ });
553
+ }
554
+ BundlerAction.urdClaim = urdClaim;
555
+ /* Wrapped Native */
556
+ /**
557
+ * Encodes a call to the Bundler to wrap native tokens (ETH to WETH on ethereum, MATIC to WMATIC on polygon, etc).
558
+ * @param amount The amount of native tokens to wrap (in wei).
559
+ */
560
+ function wrapNative(amount) {
561
+ return encodeFunctionData({
562
+ abi: wNativeBundlerAbi,
563
+ functionName: "wrapNative",
564
+ args: [amount],
565
+ });
566
+ }
567
+ BundlerAction.wrapNative = wrapNative;
568
+ /**
569
+ * Encodes a call to the Bundler to unwrap native tokens (WETH to ETH on ethereum, WMATIC to MATIC on polygon, etc).
570
+ * @param amount The amount of native tokens to unwrap (in wei).
571
+ */
572
+ function unwrapNative(amount) {
573
+ return encodeFunctionData({
574
+ abi: wNativeBundlerAbi,
575
+ functionName: "unwrapNative",
576
+ args: [amount],
577
+ });
578
+ }
579
+ BundlerAction.unwrapNative = unwrapNative;
580
+ /* stETH */
581
+ /**
582
+ * Encodes a call to the Bundler to stake native tokens using Lido (ETH to stETH on ethereum).
583
+ * @param amount The amount of native tokens to stake (in wei).
584
+ * @param minShares The minimum amount of shares to mint (protects the sender from unexpected slippage).
585
+ * @param referral The referral address to use.
586
+ */
587
+ function stakeEth(amount, minShares, referral) {
588
+ return encodeFunctionData({
589
+ abi: stEthBundlerAbi,
590
+ functionName: "stakeEth",
591
+ args: [amount, minShares, referral],
592
+ });
593
+ }
594
+ BundlerAction.stakeEth = stakeEth;
595
+ /* Wrapped stETH */
596
+ /**
597
+ * Encodes a call to the Bundler to wrap stETH (stETH to wstETH on ethereum).
598
+ * @param amount The amount of stETH to wrap (in wei).
599
+ */
600
+ function wrapStEth(amount) {
601
+ return encodeFunctionData({
602
+ abi: stEthBundlerAbi,
603
+ functionName: "wrapStEth",
604
+ args: [amount],
605
+ });
606
+ }
607
+ BundlerAction.wrapStEth = wrapStEth;
608
+ /**
609
+ * Encodes a call to the Bundler to unwrap wstETH (wstETH to stETH on ethereum).
610
+ * @param amount The amount of wstETH to unwrap (in wei).
611
+ */
612
+ function unwrapStEth(amount) {
613
+ return encodeFunctionData({
614
+ abi: stEthBundlerAbi,
615
+ functionName: "unwrapStEth",
616
+ args: [amount],
617
+ });
618
+ }
619
+ BundlerAction.unwrapStEth = unwrapStEth;
620
+ /* AaveV2 */
621
+ /**
622
+ * ! Only available on AaveV2MigrationBundler instances (not the main Bundler contract!).
623
+ * Encodes a call to the Bundler to repay a debt on AaveV2.
624
+ * @param asset The debt asset to repay.
625
+ * @param amount The amount of debt to repay.
626
+ * @param rateMode The interest rate mode used by the debt to repay.
627
+ */
628
+ function aaveV2Repay(asset, amount, rateMode) {
629
+ return encodeFunctionData({
630
+ abi: aaveV2MigrationBundlerAbi,
631
+ functionName: "aaveV2Repay",
632
+ args: [asset, amount, rateMode],
633
+ });
634
+ }
635
+ BundlerAction.aaveV2Repay = aaveV2Repay;
636
+ /**
637
+ * ! Only available on AaveV2MigrationBundler instances (not the main Bundler contract!).
638
+ * Encodes a call to the Bundler to withdrawn from AaveV2.
639
+ * @param asset The asset to withdraw.
640
+ * @param amount The amount of asset to withdraw.
641
+ */
642
+ function aaveV2Withdraw(asset, amount) {
643
+ return encodeFunctionData({
644
+ abi: aaveV2MigrationBundlerAbi,
645
+ functionName: "aaveV2Withdraw",
646
+ args: [asset, amount],
647
+ });
648
+ }
649
+ BundlerAction.aaveV2Withdraw = aaveV2Withdraw;
650
+ /* AaveV3 */
651
+ /**
652
+ * ! Only available on AaveV3MigrationBundler instances (not the main Bundler contract!).
653
+ * Encodes a call to the Bundler to repay a debt on AaveV3.
654
+ * @param asset The debt asset to repay.
655
+ * @param amount The amount of debt to repay.
656
+ * @param rateMode The interest rate mode used by the debt to repay.
657
+ */
658
+ function aaveV3Repay(asset, amount, rateMode) {
659
+ return encodeFunctionData({
660
+ abi: aaveV3MigrationBundlerAbi,
661
+ functionName: "aaveV3Repay",
662
+ args: [asset, amount, rateMode],
663
+ });
664
+ }
665
+ BundlerAction.aaveV3Repay = aaveV3Repay;
666
+ /**
667
+ * ! Only available on AaveV3MigrationBundler instances (not the main Bundler contract!).
668
+ * Encodes a call to the Bundler to withdrawn from AaveV3.
669
+ * @param asset The asset to withdraw.
670
+ * @param amount The amount of asset to withdraw.
671
+ */
672
+ function aaveV3Withdraw(asset, amount) {
673
+ return encodeFunctionData({
674
+ abi: aaveV3MigrationBundlerAbi,
675
+ functionName: "aaveV3Withdraw",
676
+ args: [asset, amount],
677
+ });
678
+ }
679
+ BundlerAction.aaveV3Withdraw = aaveV3Withdraw;
680
+ /* AaveV3 Optimizer */
681
+ /**
682
+ * ! Only available on AaveV3OptimizerMigrationBundler instances (not the main Bundler contract!).
683
+ * Encodes a call to the Bundler to repay a debt on Morpho's AaveV3Optimizer.
684
+ * @param underlying The underlying debt asset to repay.
685
+ * @param amount The amount of debt to repay.
686
+ * @param maxIterations The maximum amount of iterations to use for the repayment.
687
+ */
688
+ function aaveV3OptimizerRepay(underlying, amount) {
689
+ return encodeFunctionData({
690
+ abi: aaveV3OptimizerMigrationBundlerAbi,
691
+ functionName: "aaveV3OptimizerRepay",
692
+ args: [underlying, amount],
693
+ });
694
+ }
695
+ BundlerAction.aaveV3OptimizerRepay = aaveV3OptimizerRepay;
696
+ /**
697
+ * ! Only available on AaveV3OptimizerMigrationBundler instances (not the main Bundler contract!).
698
+ * Encodes a call to the Bundler to withdraw from Morpho's AaveV3Optimizer.
699
+ * @param underlying The underlying asset to withdraw.
700
+ * @param amount The amount to withdraw.
701
+ * @param maxIterations The maximum amount of iterations to use for the withdrawal.
702
+ */
703
+ function aaveV3OptimizerWithdraw(underlying, amount, maxIterations) {
704
+ return encodeFunctionData({
705
+ abi: aaveV3OptimizerMigrationBundlerAbi,
706
+ functionName: "aaveV3OptimizerWithdraw",
707
+ args: [underlying, amount, maxIterations],
708
+ });
709
+ }
710
+ BundlerAction.aaveV3OptimizerWithdraw = aaveV3OptimizerWithdraw;
711
+ /**
712
+ * ! Only available on AaveV3OptimizerMigrationBundler instances (not the main Bundler contract!).
713
+ * Encodes a call to the Bundler to withdraw collateral from Morpho's AaveV3Optimizer.
714
+ * @param underlying The underlying asset to withdraw.
715
+ * @param amount The amount to withdraw.
716
+ */
717
+ function aaveV3OptimizerWithdrawCollateral(underlying, amount) {
718
+ return encodeFunctionData({
719
+ abi: aaveV3OptimizerMigrationBundlerAbi,
720
+ functionName: "aaveV3OptimizerWithdrawCollateral",
721
+ args: [underlying, amount],
722
+ });
723
+ }
724
+ BundlerAction.aaveV3OptimizerWithdrawCollateral = aaveV3OptimizerWithdrawCollateral;
725
+ /**
726
+ * ! Only available on AaveV3OptimizerMigrationBundler instances (not the main Bundler contract!).
727
+ * Encodes a call to the Bundler to approve the Bundler as the sender's manager on Morpho's AaveV3Optimizer.
728
+ * @param isApproved Whether the manager is approved.
729
+ * @param nonce The nonce used to sign.
730
+ * @param deadline The timestamp until which the signature is valid.
731
+ * @param signature The Ethers signature to submit.
732
+ * @param skipRevert Whether to allow the signature to revert without making the whole multicall revert.
733
+ */
734
+ function aaveV3OptimizerApproveManagerWithSig(isApproved, nonce, deadline, signature, skipRevert) {
735
+ const { r, s, yParity } = parseSignature(signature);
736
+ return encodeFunctionData({
737
+ abi: aaveV3OptimizerMigrationBundlerAbi,
738
+ functionName: "aaveV3OptimizerApproveManagerWithSig",
739
+ args: [
740
+ isApproved,
741
+ nonce,
742
+ deadline,
743
+ { v: yParity + 27, r, s },
744
+ skipRevert,
745
+ ],
746
+ });
747
+ }
748
+ BundlerAction.aaveV3OptimizerApproveManagerWithSig = aaveV3OptimizerApproveManagerWithSig;
749
+ /* CompoundV2 */
750
+ /**
751
+ * ! Only available on CompoundV2MigrationBundler instances (not the main Bundler contract!).
752
+ * Encodes a call to the Bundler to repay a debt on CompoundV2.
753
+ * @param cToken The cToken on which to repay the debt.
754
+ * @param amount The amount of debt to repay.
755
+ */
756
+ function compoundV2Repay(cToken, amount) {
757
+ return encodeFunctionData({
758
+ abi: compoundV2MigrationBundlerAbi,
759
+ functionName: "compoundV2Repay",
760
+ args: [cToken, amount],
761
+ });
762
+ }
763
+ BundlerAction.compoundV2Repay = compoundV2Repay;
764
+ /**
765
+ * ! Only available on CompoundV2MigrationBundler instances (not the main Bundler contract!).
766
+ * Encodes a call to the Bundler to withdraw collateral from CompoundV2.
767
+ * @param cToken The cToken on which to withdraw.
768
+ * @param amount The amount to withdraw.
769
+ */
770
+ function compoundV2Redeem(cToken, amount) {
771
+ return encodeFunctionData({
772
+ abi: compoundV2MigrationBundlerAbi,
773
+ functionName: "compoundV2Redeem",
774
+ args: [cToken, amount],
775
+ });
776
+ }
777
+ BundlerAction.compoundV2Redeem = compoundV2Redeem;
778
+ /* CompoundV3 */
779
+ /**
780
+ * ! Only available on CompoundV3MigrationBundler instances (not the main Bundler contract!).
781
+ * Encodes a call to the Bundler to repay a debt on CompoundV3.
782
+ * @param instance The CompoundV3 instance on which to repay the debt.
783
+ * @param amount The amount of debt to repay.
784
+ */
785
+ function compoundV3Repay(instance, amount) {
786
+ return encodeFunctionData({
787
+ abi: compoundV3MigrationBundlerAbi,
788
+ functionName: "compoundV3Repay",
789
+ args: [instance, amount],
790
+ });
791
+ }
792
+ BundlerAction.compoundV3Repay = compoundV3Repay;
793
+ /**
794
+ * ! Only available on CompoundV3MigrationBundler instances (not the main Bundler contract!).
795
+ * Encodes a call to the Bundler to withdraw collateral from CompoundV3.
796
+ * @param instance The CompoundV3 instance on which to withdraw.
797
+ * @param amount The amount to withdraw.
798
+ */
799
+ function compoundV3WithdrawFrom(instance, asset, amount) {
800
+ return encodeFunctionData({
801
+ abi: compoundV3MigrationBundlerAbi,
802
+ functionName: "compoundV3WithdrawFrom",
803
+ args: [instance, asset, amount],
804
+ });
805
+ }
806
+ BundlerAction.compoundV3WithdrawFrom = compoundV3WithdrawFrom;
807
+ /**
808
+ * ! Only available on CompoundV3MigrationBundler instances (not the main Bundler contract!).
809
+ * Encodes a call to the Bundler to allow the Bundler to act on the sender's position on CompoundV3.
810
+ * @param instance The CompoundV3 instance on which to submit the signature.
811
+ * @param isAllowed Whether the manager is allowed.
812
+ * @param nonce The nonce used to sign.
813
+ * @param expiry The timestamp until which the signature is valid.
814
+ * @param signature The Ethers signature to submit.
815
+ * @param skipRevert Whether to allow the signature to revert without making the whole multicall revert.
816
+ */
817
+ function compoundV3AllowBySig(instance, isAllowed, nonce, expiry, signature, skipRevert) {
818
+ const { r, s, yParity } = parseSignature(signature);
819
+ return encodeFunctionData({
820
+ abi: compoundV3MigrationBundlerAbi,
821
+ functionName: "compoundV3AllowBySig",
822
+ args: [
823
+ instance,
824
+ isAllowed,
825
+ nonce,
826
+ expiry,
827
+ yParity + 27,
828
+ r,
829
+ s,
830
+ skipRevert,
831
+ ],
832
+ });
833
+ }
834
+ BundlerAction.compoundV3AllowBySig = compoundV3AllowBySig;
835
+ })(BundlerAction || (BundlerAction = {}));
836
+ export default BundlerAction;