@morpho-org/bundler-sdk-viem 2.3.0-next.0 → 3.0.0-next.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/BundlerAction.d.ts +177 -107
- package/lib/BundlerAction.js +1036 -403
- package/lib/abis.d.ts +3062 -0
- package/lib/abis.js +2095 -0
- package/lib/actions.d.ts +0 -1
- package/lib/actions.js +92 -163
- package/lib/errors.d.ts +4 -1
- package/lib/errors.js +6 -0
- package/lib/operations.js +67 -58
- package/lib/types/actions.d.ts +73 -27
- package/package.json +10 -10
package/lib/BundlerAction.js
CHANGED
|
@@ -1,177 +1,207 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { aaveV2MigrationAdapterAbi, aaveV3MigrationAdapterAbi, aaveV3OptimizerMigrationAdapterAbi, bundler3Abi, compoundV2MigrationAdapterAbi, compoundV3MigrationAdapterAbi, coreAdapterAbi, erc20WrapperAdapterAbi, ethereumGeneralAdapter1Abi, generalAdapter1Abi, universalRewardsDistributorAbi, } from "./abis.js";
|
|
2
|
+
import { getChainAddresses, } from "@morpho-org/blue-sdk";
|
|
3
|
+
import { blueAbi, erc2612Abi, permit2Abi, publicAllocatorAbi, } from "@morpho-org/blue-sdk-viem";
|
|
4
|
+
import { encodeAbiParameters, encodeFunctionData, keccak256, maxUint256, parseSignature, toFunctionSelector, zeroHash, } from "viem";
|
|
3
5
|
import { BundlerErrors } from "./errors.js";
|
|
6
|
+
const reenterSelectorHash = keccak256(toFunctionSelector(bundler3Abi.find((item) => item.type === "function" && item.name === "reenter")));
|
|
4
7
|
/**
|
|
5
8
|
* Namespace to easily encode calls to the Bundler contract, using ethers.
|
|
6
9
|
*/
|
|
7
10
|
export var BundlerAction;
|
|
8
11
|
(function (BundlerAction) {
|
|
9
|
-
function
|
|
12
|
+
function encodeBundle(chainId, actions) {
|
|
13
|
+
const { bundler3: { bundler3, generalAdapter1 }, } = getChainAddresses(chainId);
|
|
14
|
+
let value = 0n;
|
|
15
|
+
let generalAdapter1Value = 0n;
|
|
16
|
+
for (const { type, args } of actions) {
|
|
17
|
+
if (type !== "nativeTransfer")
|
|
18
|
+
continue;
|
|
19
|
+
const [owner, recipient, amount] = args;
|
|
20
|
+
if (owner !== bundler3 &&
|
|
21
|
+
owner !== generalAdapter1 &&
|
|
22
|
+
(recipient === bundler3 || recipient === generalAdapter1))
|
|
23
|
+
value += amount;
|
|
24
|
+
if (owner !== generalAdapter1 && recipient === generalAdapter1)
|
|
25
|
+
generalAdapter1Value += amount;
|
|
26
|
+
}
|
|
27
|
+
const encodedActions = actions.flatMap(BundlerAction.encode.bind(null, chainId));
|
|
28
|
+
if (generalAdapter1Value > 0n)
|
|
29
|
+
encodedActions.unshift({
|
|
30
|
+
to: generalAdapter1,
|
|
31
|
+
value: generalAdapter1Value,
|
|
32
|
+
data: "0x",
|
|
33
|
+
skipRevert: false,
|
|
34
|
+
callbackHash: zeroHash,
|
|
35
|
+
});
|
|
36
|
+
return {
|
|
37
|
+
to: bundler3,
|
|
38
|
+
value,
|
|
39
|
+
data: encodeFunctionData({
|
|
40
|
+
abi: bundler3Abi,
|
|
41
|
+
functionName: "multicall",
|
|
42
|
+
args: [encodedActions],
|
|
43
|
+
}),
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
BundlerAction.encodeBundle = encodeBundle;
|
|
47
|
+
function encode(chainId, { type, args }) {
|
|
10
48
|
switch (type) {
|
|
11
49
|
/* ERC20 */
|
|
12
50
|
case "nativeTransfer": {
|
|
13
|
-
return BundlerAction.nativeTransfer(...args);
|
|
51
|
+
return BundlerAction.nativeTransfer(chainId, ...args);
|
|
14
52
|
}
|
|
15
53
|
case "erc20Transfer": {
|
|
16
|
-
return BundlerAction.erc20Transfer(...args);
|
|
54
|
+
return BundlerAction.erc20Transfer(chainId, ...args);
|
|
17
55
|
}
|
|
18
56
|
case "erc20TransferFrom": {
|
|
19
|
-
return BundlerAction.erc20TransferFrom(...args);
|
|
57
|
+
return BundlerAction.erc20TransferFrom(chainId, ...args);
|
|
20
58
|
}
|
|
21
59
|
/* ERC20Wrapper */
|
|
22
60
|
case "erc20WrapperDepositFor": {
|
|
23
|
-
return BundlerAction.erc20WrapperDepositFor(...args);
|
|
61
|
+
return BundlerAction.erc20WrapperDepositFor(chainId, ...args);
|
|
24
62
|
}
|
|
25
63
|
case "erc20WrapperWithdrawTo": {
|
|
26
|
-
return BundlerAction.erc20WrapperWithdrawTo(...args);
|
|
64
|
+
return BundlerAction.erc20WrapperWithdrawTo(chainId, ...args);
|
|
27
65
|
}
|
|
28
66
|
/* Permit */
|
|
29
67
|
case "permit": {
|
|
30
|
-
const [asset, amount, deadline, signature, skipRevert
|
|
68
|
+
const [sender, asset, amount, deadline, signature, spender, skipRevert,] = args;
|
|
31
69
|
if (signature == null)
|
|
32
70
|
throw new BundlerErrors.MissingSignature();
|
|
33
|
-
return BundlerAction.permit(asset, amount, deadline, signature, skipRevert);
|
|
71
|
+
return BundlerAction.permit(chainId, sender, asset, amount, deadline, signature, spender, skipRevert);
|
|
34
72
|
}
|
|
35
73
|
case "permitDai": {
|
|
36
|
-
const [nonce, expiry, allowed, signature, skipRevert
|
|
74
|
+
const [sender, nonce, expiry, allowed, signature, spender, skipRevert] = args;
|
|
37
75
|
if (signature == null)
|
|
38
76
|
throw new BundlerErrors.MissingSignature();
|
|
39
|
-
return BundlerAction.permitDai(nonce, expiry, allowed, signature, skipRevert);
|
|
77
|
+
return BundlerAction.permitDai(chainId, sender, nonce, expiry, allowed, signature, spender, skipRevert);
|
|
40
78
|
}
|
|
41
79
|
/* Permit2 */
|
|
42
80
|
case "approve2": {
|
|
43
|
-
const [permitSingle, signature, skipRevert
|
|
81
|
+
const [sender, permitSingle, signature, skipRevert] = args;
|
|
44
82
|
if (signature == null)
|
|
45
83
|
throw new BundlerErrors.MissingSignature();
|
|
46
|
-
return BundlerAction.approve2(permitSingle, signature, skipRevert);
|
|
84
|
+
return BundlerAction.approve2(chainId, sender, permitSingle, signature, skipRevert);
|
|
47
85
|
}
|
|
48
86
|
case "transferFrom2": {
|
|
49
|
-
return BundlerAction.transferFrom2(...args);
|
|
87
|
+
return BundlerAction.transferFrom2(chainId, ...args);
|
|
50
88
|
}
|
|
51
89
|
/* ERC4626 */
|
|
52
90
|
case "erc4626Mint": {
|
|
53
|
-
return BundlerAction.erc4626Mint(...args);
|
|
91
|
+
return BundlerAction.erc4626Mint(chainId, ...args);
|
|
54
92
|
}
|
|
55
93
|
case "erc4626Deposit": {
|
|
56
|
-
return BundlerAction.erc4626Deposit(...args);
|
|
94
|
+
return BundlerAction.erc4626Deposit(chainId, ...args);
|
|
57
95
|
}
|
|
58
96
|
case "erc4626Withdraw": {
|
|
59
|
-
return BundlerAction.erc4626Withdraw(...args);
|
|
97
|
+
return BundlerAction.erc4626Withdraw(chainId, ...args);
|
|
60
98
|
}
|
|
61
99
|
case "erc4626Redeem": {
|
|
62
|
-
return BundlerAction.erc4626Redeem(...args);
|
|
100
|
+
return BundlerAction.erc4626Redeem(chainId, ...args);
|
|
63
101
|
}
|
|
64
102
|
/* Morpho */
|
|
65
103
|
case "morphoSetAuthorizationWithSig": {
|
|
66
|
-
const [authorization, signature, skipRevert
|
|
104
|
+
const [authorization, signature, skipRevert] = args;
|
|
67
105
|
if (signature == null)
|
|
68
106
|
throw new BundlerErrors.MissingSignature();
|
|
69
|
-
return BundlerAction.morphoSetAuthorizationWithSig(authorization, signature, skipRevert);
|
|
107
|
+
return BundlerAction.morphoSetAuthorizationWithSig(chainId, authorization, signature, skipRevert);
|
|
70
108
|
}
|
|
71
109
|
case "morphoSupply": {
|
|
72
110
|
const [market, assets, shares, slippageAmount, onBehalf, onMorphoSupply,] = args;
|
|
73
|
-
return BundlerAction.morphoSupply(market, assets, shares, slippageAmount, onBehalf, onMorphoSupply.
|
|
111
|
+
return BundlerAction.morphoSupply(chainId, market, assets, shares, slippageAmount, onBehalf, onMorphoSupply.flatMap(BundlerAction.encode.bind(null, chainId)));
|
|
74
112
|
}
|
|
75
113
|
case "morphoSupplyCollateral": {
|
|
76
114
|
const [market, amount, onBehalf, onMorphoSupplyCollateral] = args;
|
|
77
|
-
return BundlerAction.morphoSupplyCollateral(market, amount, onBehalf, onMorphoSupplyCollateral.
|
|
115
|
+
return BundlerAction.morphoSupplyCollateral(chainId, market, amount, onBehalf, onMorphoSupplyCollateral.flatMap(BundlerAction.encode.bind(null, chainId)));
|
|
78
116
|
}
|
|
79
117
|
case "morphoBorrow": {
|
|
80
|
-
|
|
81
|
-
return BundlerAction.morphoBorrow(market, assets, shares, slippageAmount, receiver);
|
|
118
|
+
return BundlerAction.morphoBorrow(chainId, ...args);
|
|
82
119
|
}
|
|
83
120
|
case "morphoRepay": {
|
|
84
121
|
const [market, assets, shares, slippageAmount, onBehalf, onMorphoRepay,] = args;
|
|
85
|
-
return BundlerAction.morphoRepay(market, assets, shares, slippageAmount, onBehalf, onMorphoRepay.
|
|
122
|
+
return BundlerAction.morphoRepay(chainId, market, assets, shares, slippageAmount, onBehalf, onMorphoRepay.flatMap(BundlerAction.encode.bind(null, chainId)));
|
|
86
123
|
}
|
|
87
124
|
case "morphoWithdraw": {
|
|
88
|
-
|
|
89
|
-
return BundlerAction.morphoWithdraw(market, assets, shares, slippageAmount, receiver);
|
|
125
|
+
return BundlerAction.morphoWithdraw(chainId, ...args);
|
|
90
126
|
}
|
|
91
127
|
case "morphoWithdrawCollateral": {
|
|
92
|
-
|
|
93
|
-
return BundlerAction.morphoWithdrawCollateral(market, amount, receiver);
|
|
128
|
+
return BundlerAction.morphoWithdrawCollateral(chainId, ...args);
|
|
94
129
|
}
|
|
95
|
-
/*
|
|
130
|
+
/* PublicAllocator */
|
|
96
131
|
case "reallocateTo": {
|
|
97
|
-
|
|
98
|
-
return BundlerAction.metaMorphoReallocateTo(publicAllocator, vault, value, withdrawals, supplyMarket);
|
|
132
|
+
return BundlerAction.publicAllocatorReallocateTo(chainId, ...args);
|
|
99
133
|
}
|
|
100
134
|
/* Universal Rewards Distributor */
|
|
101
135
|
case "urdClaim": {
|
|
102
|
-
|
|
103
|
-
return BundlerAction.urdClaim(distributor, account, reward, amount, proof, skipRevert);
|
|
136
|
+
return BundlerAction.urdClaim(...args);
|
|
104
137
|
}
|
|
105
138
|
/* Wrapped Native */
|
|
106
139
|
case "wrapNative": {
|
|
107
|
-
return BundlerAction.wrapNative(...args);
|
|
140
|
+
return BundlerAction.wrapNative(chainId, ...args);
|
|
108
141
|
}
|
|
109
142
|
case "unwrapNative": {
|
|
110
|
-
return BundlerAction.unwrapNative(...args);
|
|
143
|
+
return BundlerAction.unwrapNative(chainId, ...args);
|
|
111
144
|
}
|
|
112
145
|
/* stETH */
|
|
113
146
|
case "stakeEth": {
|
|
114
|
-
return BundlerAction.stakeEth(...args);
|
|
147
|
+
return BundlerAction.stakeEth(chainId, ...args);
|
|
115
148
|
}
|
|
116
149
|
/* Wrapped stETH */
|
|
117
150
|
case "wrapStEth": {
|
|
118
|
-
return BundlerAction.wrapStEth(...args);
|
|
151
|
+
return BundlerAction.wrapStEth(chainId, ...args);
|
|
119
152
|
}
|
|
120
153
|
case "unwrapStEth": {
|
|
121
|
-
return BundlerAction.unwrapStEth(...args);
|
|
154
|
+
return BundlerAction.unwrapStEth(chainId, ...args);
|
|
122
155
|
}
|
|
123
156
|
/* AaveV2 */
|
|
124
157
|
case "aaveV2Repay": {
|
|
125
|
-
|
|
126
|
-
return BundlerAction.aaveV2Repay(asset, amount, rateMode);
|
|
158
|
+
return BundlerAction.aaveV2Repay(chainId, ...args);
|
|
127
159
|
}
|
|
128
160
|
case "aaveV2Withdraw": {
|
|
129
|
-
return BundlerAction.aaveV2Withdraw(...args);
|
|
161
|
+
return BundlerAction.aaveV2Withdraw(chainId, ...args);
|
|
130
162
|
}
|
|
131
163
|
/* AaveV3 */
|
|
132
164
|
case "aaveV3Repay": {
|
|
133
|
-
|
|
134
|
-
return BundlerAction.aaveV3Repay(asset, amount, rateMode);
|
|
165
|
+
return BundlerAction.aaveV3Repay(chainId, ...args);
|
|
135
166
|
}
|
|
136
167
|
case "aaveV3Withdraw": {
|
|
137
|
-
return BundlerAction.aaveV3Withdraw(...args);
|
|
168
|
+
return BundlerAction.aaveV3Withdraw(chainId, ...args);
|
|
138
169
|
}
|
|
139
170
|
/* AaveV3 Optimizer */
|
|
140
171
|
case "aaveV3OptimizerRepay": {
|
|
141
|
-
return BundlerAction.aaveV3OptimizerRepay(...args);
|
|
172
|
+
return BundlerAction.aaveV3OptimizerRepay(chainId, ...args);
|
|
142
173
|
}
|
|
143
174
|
case "aaveV3OptimizerWithdraw": {
|
|
144
|
-
|
|
145
|
-
return BundlerAction.aaveV3OptimizerWithdraw(underlying, amount, maxIterations);
|
|
175
|
+
return BundlerAction.aaveV3OptimizerWithdraw(chainId, ...args);
|
|
146
176
|
}
|
|
147
177
|
case "aaveV3OptimizerWithdrawCollateral": {
|
|
148
|
-
return BundlerAction.aaveV3OptimizerWithdrawCollateral(...args);
|
|
178
|
+
return BundlerAction.aaveV3OptimizerWithdrawCollateral(chainId, ...args);
|
|
149
179
|
}
|
|
150
180
|
case "aaveV3OptimizerApproveManagerWithSig": {
|
|
151
|
-
const [isApproved, nonce, deadline, signature, skipRevert
|
|
181
|
+
const [owner, isApproved, nonce, deadline, signature, manager, skipRevert,] = args;
|
|
152
182
|
if (signature == null)
|
|
153
183
|
throw new BundlerErrors.MissingSignature();
|
|
154
|
-
return BundlerAction.aaveV3OptimizerApproveManagerWithSig(isApproved, nonce, deadline, signature, skipRevert);
|
|
184
|
+
return BundlerAction.aaveV3OptimizerApproveManagerWithSig(chainId, owner, isApproved, nonce, deadline, signature, manager, skipRevert);
|
|
155
185
|
}
|
|
156
186
|
/* CompoundV2 */
|
|
157
187
|
case "compoundV2Repay": {
|
|
158
|
-
return BundlerAction.compoundV2Repay(...args);
|
|
188
|
+
return BundlerAction.compoundV2Repay(chainId, ...args);
|
|
159
189
|
}
|
|
160
190
|
case "compoundV2Redeem": {
|
|
161
|
-
return BundlerAction.compoundV2Redeem(...args);
|
|
191
|
+
return BundlerAction.compoundV2Redeem(chainId, ...args);
|
|
162
192
|
}
|
|
163
193
|
/* CompoundV3 */
|
|
164
194
|
case "compoundV3Repay": {
|
|
165
|
-
return BundlerAction.compoundV3Repay(...args);
|
|
195
|
+
return BundlerAction.compoundV3Repay(chainId, ...args);
|
|
166
196
|
}
|
|
167
197
|
case "compoundV3WithdrawFrom": {
|
|
168
|
-
return BundlerAction.compoundV3WithdrawFrom(...args);
|
|
198
|
+
return BundlerAction.compoundV3WithdrawFrom(chainId, ...args);
|
|
169
199
|
}
|
|
170
200
|
case "compoundV3AllowBySig": {
|
|
171
|
-
const [instance, isAllowed, nonce, expiry, signature, skipRevert
|
|
201
|
+
const [instance, owner, isAllowed, nonce, expiry, signature, manager, skipRevert,] = args;
|
|
172
202
|
if (signature == null)
|
|
173
203
|
throw new BundlerErrors.MissingSignature();
|
|
174
|
-
return BundlerAction.compoundV3AllowBySig(instance, isAllowed, nonce, expiry, signature, skipRevert);
|
|
204
|
+
return BundlerAction.compoundV3AllowBySig(chainId, instance, owner, isAllowed, nonce, expiry, signature, manager, skipRevert);
|
|
175
205
|
}
|
|
176
206
|
}
|
|
177
207
|
throw Error(`unhandled action encoding: ${type}`);
|
|
@@ -179,215 +209,458 @@ export var BundlerAction;
|
|
|
179
209
|
BundlerAction.encode = encode;
|
|
180
210
|
/* ERC20 */
|
|
181
211
|
/**
|
|
182
|
-
* Encodes a call to the
|
|
212
|
+
* Encodes a call to the Adapter to transfer native tokens (ETH on ethereum, MATIC on polygon, etc).
|
|
213
|
+
* @param chainId The chain id for which to encode the call.
|
|
214
|
+
* @param owner The owner of native tokens.
|
|
183
215
|
* @param recipient The address to send native tokens to.
|
|
184
216
|
* @param amount The amount of native tokens to send (in wei).
|
|
185
217
|
*/
|
|
186
|
-
function nativeTransfer(recipient, amount) {
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
218
|
+
function nativeTransfer(chainId, owner, recipient, amount) {
|
|
219
|
+
const { bundler3: { bundler3, generalAdapter1 }, } = getChainAddresses(chainId);
|
|
220
|
+
if (recipient === bundler3)
|
|
221
|
+
return [];
|
|
222
|
+
if (owner === generalAdapter1)
|
|
223
|
+
return [
|
|
224
|
+
{
|
|
225
|
+
to: generalAdapter1,
|
|
226
|
+
data: encodeFunctionData({
|
|
227
|
+
abi: coreAdapterAbi,
|
|
228
|
+
functionName: "nativeTransfer",
|
|
229
|
+
args: [recipient, amount],
|
|
230
|
+
}),
|
|
231
|
+
value: 0n,
|
|
232
|
+
skipRevert: false,
|
|
233
|
+
callbackHash: zeroHash,
|
|
234
|
+
},
|
|
235
|
+
];
|
|
236
|
+
return [
|
|
237
|
+
{
|
|
238
|
+
to: recipient,
|
|
239
|
+
data: "0x",
|
|
240
|
+
value: amount,
|
|
241
|
+
skipRevert: false,
|
|
242
|
+
callbackHash: zeroHash,
|
|
243
|
+
},
|
|
244
|
+
];
|
|
192
245
|
}
|
|
193
246
|
BundlerAction.nativeTransfer = nativeTransfer;
|
|
194
247
|
/**
|
|
195
|
-
* Encodes a call to the
|
|
248
|
+
* Encodes a call to the Adapter to transfer ERC20 tokens.
|
|
249
|
+
* @param chainId The chain id for which to encode the call.
|
|
196
250
|
* @param asset The address of the ERC20 token to transfer.
|
|
197
251
|
* @param recipient The address to send tokens to.
|
|
198
252
|
* @param amount The amount of tokens to send.
|
|
199
253
|
*/
|
|
200
|
-
function erc20Transfer(asset, recipient, amount) {
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
254
|
+
function erc20Transfer(chainId, asset, recipient, amount) {
|
|
255
|
+
const { bundler3: { generalAdapter1 }, } = getChainAddresses(chainId);
|
|
256
|
+
return [
|
|
257
|
+
{
|
|
258
|
+
to: generalAdapter1,
|
|
259
|
+
data: encodeFunctionData({
|
|
260
|
+
abi: coreAdapterAbi,
|
|
261
|
+
functionName: "erc20Transfer",
|
|
262
|
+
args: [asset, recipient, amount],
|
|
263
|
+
}),
|
|
264
|
+
value: 0n,
|
|
265
|
+
skipRevert: false,
|
|
266
|
+
callbackHash: zeroHash,
|
|
267
|
+
},
|
|
268
|
+
];
|
|
206
269
|
}
|
|
207
270
|
BundlerAction.erc20Transfer = erc20Transfer;
|
|
208
271
|
/**
|
|
209
|
-
* Encodes a call to the
|
|
272
|
+
* Encodes a call to the Adapter to transfer ERC20 tokens from the sender to the Bundler.
|
|
273
|
+
* @param chainId The chain id for which to encode the call.
|
|
210
274
|
* @param asset The address of the ERC20 token to transfer.
|
|
211
275
|
* @param amount The amount of tokens to send.
|
|
276
|
+
* @param recipient The recipient of ERC20 tokens. Defaults to the chain's bundler3 general adapter.
|
|
212
277
|
*/
|
|
213
|
-
function erc20TransferFrom(asset, amount) {
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
278
|
+
function erc20TransferFrom(chainId, asset, amount, recipient) {
|
|
279
|
+
const { bundler3: { generalAdapter1 }, } = getChainAddresses(chainId);
|
|
280
|
+
recipient ??= generalAdapter1;
|
|
281
|
+
return [
|
|
282
|
+
{
|
|
283
|
+
to: generalAdapter1,
|
|
284
|
+
data: encodeFunctionData({
|
|
285
|
+
abi: generalAdapter1Abi,
|
|
286
|
+
functionName: "erc20TransferFrom",
|
|
287
|
+
args: [asset, recipient, amount],
|
|
288
|
+
}),
|
|
289
|
+
value: 0n,
|
|
290
|
+
skipRevert: false,
|
|
291
|
+
callbackHash: zeroHash,
|
|
292
|
+
},
|
|
293
|
+
];
|
|
219
294
|
}
|
|
220
295
|
BundlerAction.erc20TransferFrom = erc20TransferFrom;
|
|
221
296
|
/* Permit */
|
|
222
297
|
/**
|
|
223
|
-
* Encodes a call to the
|
|
298
|
+
* Encodes a call to the Adapter to permit an ERC20 token.
|
|
299
|
+
* @param chainId The chain id for which to encode the call.
|
|
300
|
+
* @param owner The address which owns the tokens.
|
|
224
301
|
* @param asset The address of the ERC20 token to permit.
|
|
225
302
|
* @param amount The amount of tokens to permit.
|
|
226
303
|
* @param deadline The timestamp until which the signature is valid.
|
|
227
304
|
* @param signature The Ethers signature to permit the tokens.
|
|
305
|
+
* @param spender The address allowed to spend the tokens.
|
|
228
306
|
* @param skipRevert Whether to allow the permit to revert without making the whole multicall revert.
|
|
229
307
|
*/
|
|
230
|
-
function permit(asset, amount, deadline, signature, skipRevert) {
|
|
308
|
+
function permit(chainId, owner, asset, amount, deadline, signature, spender, skipRevert = true) {
|
|
309
|
+
const { bundler3: { generalAdapter1 }, } = getChainAddresses(chainId);
|
|
231
310
|
const { r, s, yParity } = parseSignature(signature);
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
311
|
+
spender ??= generalAdapter1;
|
|
312
|
+
return [
|
|
313
|
+
{
|
|
314
|
+
to: asset,
|
|
315
|
+
data: encodeFunctionData({
|
|
316
|
+
abi: erc2612Abi,
|
|
317
|
+
functionName: "permit",
|
|
318
|
+
args: [owner, spender, amount, deadline, yParity + 27, r, s],
|
|
319
|
+
}),
|
|
320
|
+
value: 0n,
|
|
321
|
+
skipRevert,
|
|
322
|
+
callbackHash: zeroHash,
|
|
323
|
+
},
|
|
324
|
+
];
|
|
237
325
|
}
|
|
238
326
|
BundlerAction.permit = permit;
|
|
239
327
|
/**
|
|
240
|
-
* Encodes a call to the
|
|
328
|
+
* Encodes a call to the Adapter to permit DAI.
|
|
329
|
+
* @param chainId The chain id for which to encode the call.
|
|
330
|
+
* @param owner The address which owns the tokens.
|
|
241
331
|
* @param nonce The permit nonce used.
|
|
242
332
|
* @param expiry The timestamp until which the signature is valid.
|
|
243
333
|
* @param allowed The amount of DAI to permit.
|
|
244
334
|
* @param signature The Ethers signature to permit the tokens.
|
|
335
|
+
* @param spender The address allowed to spend the tokens.
|
|
245
336
|
* @param skipRevert Whether to allow the permit to revert without making the whole multicall revert.
|
|
246
337
|
*/
|
|
247
|
-
function permitDai(nonce, expiry, allowed, signature, skipRevert) {
|
|
338
|
+
function permitDai(chainId, owner, nonce, expiry, allowed, signature, spender, skipRevert = true) {
|
|
339
|
+
const { dai, bundler3: { generalAdapter1 }, } = getChainAddresses(chainId);
|
|
340
|
+
if (dai == null)
|
|
341
|
+
throw new BundlerErrors.UnexpectedAction("permitDai", chainId);
|
|
342
|
+
spender ??= generalAdapter1;
|
|
248
343
|
const { r, s, yParity } = parseSignature(signature);
|
|
249
|
-
return
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
344
|
+
return [
|
|
345
|
+
{
|
|
346
|
+
to: dai,
|
|
347
|
+
data: encodeFunctionData({
|
|
348
|
+
abi: [
|
|
349
|
+
{
|
|
350
|
+
constant: false,
|
|
351
|
+
inputs: [
|
|
352
|
+
{ name: "holder", type: "address" },
|
|
353
|
+
{ name: "spender", type: "address" },
|
|
354
|
+
{ name: "nonce", type: "uint256" },
|
|
355
|
+
{ name: "expiry", type: "uint256" },
|
|
356
|
+
{ name: "allowed", type: "bool" },
|
|
357
|
+
{ name: "v", type: "uint8" },
|
|
358
|
+
{ name: "r", type: "bytes32" },
|
|
359
|
+
{ name: "s", type: "bytes32" },
|
|
360
|
+
],
|
|
361
|
+
name: "permit",
|
|
362
|
+
outputs: [],
|
|
363
|
+
payable: false,
|
|
364
|
+
stateMutability: "nonpayable",
|
|
365
|
+
type: "function",
|
|
366
|
+
},
|
|
367
|
+
],
|
|
368
|
+
functionName: "permit",
|
|
369
|
+
args: [owner, spender, nonce, expiry, allowed, yParity + 27, r, s],
|
|
370
|
+
}),
|
|
371
|
+
value: 0n,
|
|
372
|
+
skipRevert,
|
|
373
|
+
callbackHash: zeroHash,
|
|
374
|
+
},
|
|
375
|
+
];
|
|
254
376
|
}
|
|
255
377
|
BundlerAction.permitDai = permitDai;
|
|
256
378
|
/* Permit2 */
|
|
257
379
|
/**
|
|
258
|
-
* Encodes a call to the
|
|
380
|
+
* Encodes a call to the Adapter to permit ERC20 tokens via Permit2.
|
|
381
|
+
* @param chainId The chain id for which to encode the call.
|
|
382
|
+
* @param owner The owner of ERC20 tokens.
|
|
259
383
|
* @param permitSingle The permit details to submit to Permit2.
|
|
260
384
|
* @param signature The Ethers signature to permit the tokens.
|
|
261
385
|
* @param skipRevert Whether to allow the permit to revert without making the whole multicall revert.
|
|
262
386
|
*/
|
|
263
|
-
function approve2(permitSingle, signature, skipRevert) {
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
387
|
+
function approve2(chainId, owner, permitSingle, signature, skipRevert = true) {
|
|
388
|
+
const { permit2 } = getChainAddresses(chainId);
|
|
389
|
+
if (permit2 == null)
|
|
390
|
+
throw new BundlerErrors.UnexpectedAction("approve2", chainId);
|
|
391
|
+
return [
|
|
392
|
+
{
|
|
393
|
+
to: permit2,
|
|
394
|
+
data: encodeFunctionData({
|
|
395
|
+
abi: permit2Abi,
|
|
396
|
+
functionName: "permit",
|
|
397
|
+
args: [owner, permitSingle, signature],
|
|
398
|
+
}),
|
|
399
|
+
value: 0n,
|
|
400
|
+
skipRevert,
|
|
401
|
+
callbackHash: zeroHash,
|
|
402
|
+
},
|
|
403
|
+
];
|
|
269
404
|
}
|
|
270
405
|
BundlerAction.approve2 = approve2;
|
|
271
406
|
/**
|
|
272
|
-
* Encodes a call to the
|
|
407
|
+
* Encodes a call to the Adapter to transfer ERC20 tokens via Permit2 from the sender to the Bundler.
|
|
408
|
+
* @param chainId The chain id for which to encode the call.
|
|
273
409
|
* @param asset The address of the ERC20 token to transfer.
|
|
410
|
+
* @param owner The owner of ERC20 tokens.
|
|
274
411
|
* @param amount The amount of tokens to send.
|
|
412
|
+
* @param recipient The recipient of ERC20 tokens. Defaults to the chain's bundler3 general adapter.
|
|
275
413
|
*/
|
|
276
|
-
function transferFrom2(asset, amount) {
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
414
|
+
function transferFrom2(chainId, asset, owner, amount, recipient) {
|
|
415
|
+
const { permit2, bundler3: { generalAdapter1 }, } = getChainAddresses(chainId);
|
|
416
|
+
if (permit2 == null)
|
|
417
|
+
throw new BundlerErrors.UnexpectedAction("transferFrom2", chainId);
|
|
418
|
+
recipient ??= generalAdapter1;
|
|
419
|
+
return [
|
|
420
|
+
{
|
|
421
|
+
to: permit2,
|
|
422
|
+
data: encodeFunctionData({
|
|
423
|
+
abi: permit2Abi,
|
|
424
|
+
functionName: "transferFrom",
|
|
425
|
+
// TODO: batch all permit2 transfers via transferFrom(AllowanceTransferDetails[] calldata)
|
|
426
|
+
args: [owner, recipient, amount, asset],
|
|
427
|
+
}),
|
|
428
|
+
value: 0n,
|
|
429
|
+
skipRevert: false,
|
|
430
|
+
callbackHash: zeroHash,
|
|
431
|
+
},
|
|
432
|
+
];
|
|
282
433
|
}
|
|
283
434
|
BundlerAction.transferFrom2 = transferFrom2;
|
|
284
435
|
/* ERC20 Wrapper */
|
|
285
436
|
/**
|
|
286
|
-
* Encodes a call to the
|
|
437
|
+
* Encodes a call to the Adapter to wrap ERC20 tokens via the provided ERC20Wrapper.
|
|
438
|
+
* @param chainId The chain id for which to encode the call.
|
|
287
439
|
* @param wrapper The address of the ERC20 wrapper token.
|
|
440
|
+
* @param underlying The address of the underlying ERC20 token.
|
|
288
441
|
* @param amount The amount of tokens to send.
|
|
289
442
|
*/
|
|
290
|
-
function erc20WrapperDepositFor(wrapper, amount) {
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
443
|
+
function erc20WrapperDepositFor(chainId, wrapper, underlying, amount) {
|
|
444
|
+
const { bundler3: { generalAdapter1, erc20WrapperAdapter }, } = getChainAddresses(chainId);
|
|
445
|
+
if (erc20WrapperAdapter == null)
|
|
446
|
+
throw new BundlerErrors.UnexpectedAction("erc20WrapperDepositFor", chainId);
|
|
447
|
+
return [
|
|
448
|
+
{
|
|
449
|
+
to: generalAdapter1,
|
|
450
|
+
data: encodeFunctionData({
|
|
451
|
+
abi: generalAdapter1Abi,
|
|
452
|
+
functionName: "erc20Transfer",
|
|
453
|
+
args: [underlying, erc20WrapperAdapter, maxUint256],
|
|
454
|
+
}),
|
|
455
|
+
value: 0n,
|
|
456
|
+
skipRevert: false,
|
|
457
|
+
callbackHash: zeroHash,
|
|
458
|
+
},
|
|
459
|
+
{
|
|
460
|
+
to: erc20WrapperAdapter,
|
|
461
|
+
data: encodeFunctionData({
|
|
462
|
+
abi: erc20WrapperAdapterAbi,
|
|
463
|
+
functionName: "erc20WrapperDepositFor",
|
|
464
|
+
args: [wrapper, amount],
|
|
465
|
+
}),
|
|
466
|
+
value: 0n,
|
|
467
|
+
skipRevert: false,
|
|
468
|
+
callbackHash: zeroHash,
|
|
469
|
+
},
|
|
470
|
+
{
|
|
471
|
+
to: erc20WrapperAdapter,
|
|
472
|
+
data: encodeFunctionData({
|
|
473
|
+
abi: erc20WrapperAdapterAbi,
|
|
474
|
+
functionName: "erc20Transfer",
|
|
475
|
+
args: [underlying, generalAdapter1, maxUint256],
|
|
476
|
+
}),
|
|
477
|
+
value: 0n,
|
|
478
|
+
skipRevert: false,
|
|
479
|
+
callbackHash: zeroHash,
|
|
480
|
+
},
|
|
481
|
+
];
|
|
296
482
|
}
|
|
297
483
|
BundlerAction.erc20WrapperDepositFor = erc20WrapperDepositFor;
|
|
298
484
|
/**
|
|
299
|
-
* Encodes a call to the
|
|
485
|
+
* Encodes a call to the Adapter to unwrap ERC20 tokens from the provided ERC20Wrapper.
|
|
486
|
+
* @param chainId The chain id for which to encode the call.
|
|
300
487
|
* @param wrapper The address of the ERC20 wrapper token.
|
|
301
488
|
* @param account The address to send the underlying ERC20 tokens.
|
|
302
489
|
* @param amount The amount of tokens to send.
|
|
303
490
|
*/
|
|
304
|
-
function erc20WrapperWithdrawTo(wrapper,
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
491
|
+
function erc20WrapperWithdrawTo(chainId, wrapper, receiver, amount) {
|
|
492
|
+
const { bundler3: { generalAdapter1, erc20WrapperAdapter }, } = getChainAddresses(chainId);
|
|
493
|
+
if (erc20WrapperAdapter == null)
|
|
494
|
+
throw new BundlerErrors.UnexpectedAction("erc20WrapperWithdrawTo", chainId);
|
|
495
|
+
return [
|
|
496
|
+
{
|
|
497
|
+
to: generalAdapter1,
|
|
498
|
+
data: encodeFunctionData({
|
|
499
|
+
abi: generalAdapter1Abi,
|
|
500
|
+
functionName: "erc20Transfer",
|
|
501
|
+
args: [wrapper, erc20WrapperAdapter, maxUint256],
|
|
502
|
+
}),
|
|
503
|
+
value: 0n,
|
|
504
|
+
skipRevert: false,
|
|
505
|
+
callbackHash: zeroHash,
|
|
506
|
+
},
|
|
507
|
+
{
|
|
508
|
+
to: erc20WrapperAdapter,
|
|
509
|
+
data: encodeFunctionData({
|
|
510
|
+
abi: erc20WrapperAdapterAbi,
|
|
511
|
+
functionName: "erc20WrapperWithdrawTo",
|
|
512
|
+
args: [wrapper, receiver, amount],
|
|
513
|
+
}),
|
|
514
|
+
value: 0n,
|
|
515
|
+
skipRevert: false,
|
|
516
|
+
callbackHash: zeroHash,
|
|
517
|
+
},
|
|
518
|
+
{
|
|
519
|
+
to: erc20WrapperAdapter,
|
|
520
|
+
data: encodeFunctionData({
|
|
521
|
+
abi: erc20WrapperAdapterAbi,
|
|
522
|
+
functionName: "erc20Transfer",
|
|
523
|
+
args: [wrapper, generalAdapter1, maxUint256],
|
|
524
|
+
}),
|
|
525
|
+
value: 0n,
|
|
526
|
+
skipRevert: false,
|
|
527
|
+
callbackHash: zeroHash,
|
|
528
|
+
},
|
|
529
|
+
];
|
|
310
530
|
}
|
|
311
531
|
BundlerAction.erc20WrapperWithdrawTo = erc20WrapperWithdrawTo;
|
|
312
532
|
/* ERC4626 */
|
|
313
533
|
/**
|
|
314
|
-
* Encodes a call to the
|
|
534
|
+
* Encodes a call to the Adapter to mint shares of the provided ERC4626 vault.
|
|
535
|
+
* @param chainId The chain id for which to encode the call.
|
|
315
536
|
* @param erc4626 The address of the ERC4626 vault.
|
|
316
537
|
* @param shares The amount of shares to mint.
|
|
317
|
-
* @param
|
|
538
|
+
* @param maxSharePrice The maximum amount of assets to pay to get 1 share (scaled by RAY).
|
|
318
539
|
* @param receiver The address to send the shares to.
|
|
319
540
|
*/
|
|
320
|
-
function erc4626Mint(erc4626, shares,
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
541
|
+
function erc4626Mint(chainId, erc4626, shares, maxSharePrice, receiver) {
|
|
542
|
+
const { bundler3: { generalAdapter1 }, } = getChainAddresses(chainId);
|
|
543
|
+
return [
|
|
544
|
+
{
|
|
545
|
+
to: generalAdapter1,
|
|
546
|
+
data: encodeFunctionData({
|
|
547
|
+
abi: generalAdapter1Abi,
|
|
548
|
+
functionName: "erc4626Mint",
|
|
549
|
+
args: [erc4626, shares, maxSharePrice, receiver],
|
|
550
|
+
}),
|
|
551
|
+
value: 0n,
|
|
552
|
+
skipRevert: false,
|
|
553
|
+
callbackHash: zeroHash,
|
|
554
|
+
},
|
|
555
|
+
];
|
|
326
556
|
}
|
|
327
557
|
BundlerAction.erc4626Mint = erc4626Mint;
|
|
328
558
|
/**
|
|
329
|
-
* Encodes a call to the
|
|
559
|
+
* Encodes a call to the Adapter to deposit assets into the provided ERC4626 vault.
|
|
560
|
+
* @param chainId The chain id for which to encode the call.
|
|
330
561
|
* @param erc4626 The address of the ERC4626 vault.
|
|
331
562
|
* @param assets The amount of assets to deposit.
|
|
332
|
-
* @param
|
|
563
|
+
* @param maxSharePrice The maximum amount of assets to pay to get 1 share (scaled by RAY).
|
|
333
564
|
* @param receiver The address to send the shares to.
|
|
334
565
|
*/
|
|
335
|
-
function erc4626Deposit(erc4626, assets,
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
566
|
+
function erc4626Deposit(chainId, erc4626, assets, maxSharePrice, receiver) {
|
|
567
|
+
const { bundler3: { generalAdapter1 }, } = getChainAddresses(chainId);
|
|
568
|
+
return [
|
|
569
|
+
{
|
|
570
|
+
to: generalAdapter1,
|
|
571
|
+
data: encodeFunctionData({
|
|
572
|
+
abi: generalAdapter1Abi,
|
|
573
|
+
functionName: "erc4626Deposit",
|
|
574
|
+
args: [erc4626, assets, maxSharePrice, receiver],
|
|
575
|
+
}),
|
|
576
|
+
value: 0n,
|
|
577
|
+
skipRevert: false,
|
|
578
|
+
callbackHash: zeroHash,
|
|
579
|
+
},
|
|
580
|
+
];
|
|
341
581
|
}
|
|
342
582
|
BundlerAction.erc4626Deposit = erc4626Deposit;
|
|
343
583
|
/**
|
|
344
|
-
* Encodes a call to the
|
|
584
|
+
* Encodes a call to the Adapter to withdraw assets from the provided ERC4626 vault.
|
|
585
|
+
* @param chainId The chain id for which to encode the call.
|
|
345
586
|
* @param erc4626 The address of the ERC4626 vault.
|
|
346
587
|
* @param assets The amount of assets to withdraw.
|
|
347
|
-
* @param
|
|
588
|
+
* @param minSharePrice The minimum number of assets to receive per share (scaled by RAY).
|
|
348
589
|
* @param receiver The address to send the assets to.
|
|
590
|
+
* @param owner The address on behalf of which the assets are withdrawn.
|
|
349
591
|
*/
|
|
350
|
-
function erc4626Withdraw(erc4626, assets,
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
592
|
+
function erc4626Withdraw(chainId, erc4626, assets, minSharePrice, receiver, owner) {
|
|
593
|
+
const { bundler3: { generalAdapter1 }, } = getChainAddresses(chainId);
|
|
594
|
+
return [
|
|
595
|
+
{
|
|
596
|
+
to: generalAdapter1,
|
|
597
|
+
data: encodeFunctionData({
|
|
598
|
+
abi: generalAdapter1Abi,
|
|
599
|
+
functionName: "erc4626Withdraw",
|
|
600
|
+
args: [erc4626, assets, minSharePrice, receiver, owner],
|
|
601
|
+
}),
|
|
602
|
+
value: 0n,
|
|
603
|
+
skipRevert: false,
|
|
604
|
+
callbackHash: zeroHash,
|
|
605
|
+
},
|
|
606
|
+
];
|
|
356
607
|
}
|
|
357
608
|
BundlerAction.erc4626Withdraw = erc4626Withdraw;
|
|
358
609
|
/**
|
|
359
|
-
* Encodes a call to the
|
|
610
|
+
* Encodes a call to the Adapter to redeem shares from the provided ERC4626 vault.
|
|
611
|
+
* @param chainId The chain id for which to encode the call.
|
|
360
612
|
* @param erc4626 The address of the ERC4626 vault.
|
|
361
613
|
* @param shares The amount of shares to redeem.
|
|
362
|
-
* @param
|
|
614
|
+
* @param minSharePrice The minimum number of assets to receive per share (scaled by RAY).
|
|
363
615
|
* @param receiver The address to send the assets to.
|
|
616
|
+
* @param owner The address on behalf of which the assets are withdrawn.
|
|
364
617
|
*/
|
|
365
|
-
function erc4626Redeem(erc4626, shares,
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
618
|
+
function erc4626Redeem(chainId, erc4626, shares, minSharePrice, receiver, owner) {
|
|
619
|
+
const { bundler3: { generalAdapter1 }, } = getChainAddresses(chainId);
|
|
620
|
+
return [
|
|
621
|
+
{
|
|
622
|
+
to: generalAdapter1,
|
|
623
|
+
data: encodeFunctionData({
|
|
624
|
+
abi: generalAdapter1Abi,
|
|
625
|
+
functionName: "erc4626Redeem",
|
|
626
|
+
args: [erc4626, shares, minSharePrice, receiver, owner],
|
|
627
|
+
}),
|
|
628
|
+
value: 0n,
|
|
629
|
+
skipRevert: false,
|
|
630
|
+
callbackHash: zeroHash,
|
|
631
|
+
},
|
|
632
|
+
];
|
|
371
633
|
}
|
|
372
634
|
BundlerAction.erc4626Redeem = erc4626Redeem;
|
|
373
635
|
/* Morpho */
|
|
374
636
|
/**
|
|
375
|
-
* Encodes a call to the
|
|
637
|
+
* Encodes a call to the Adapter to authorize an account on Morpho Blue.
|
|
638
|
+
* @param chainId The chain id for which to encode the call.
|
|
376
639
|
* @param authorization The authorization details to submit to Morpho Blue.
|
|
377
640
|
* @param signature The Ethers signature to authorize the account.
|
|
378
641
|
* @param skipRevert Whether to allow the authorization call to revert without making the whole multicall revert.
|
|
379
642
|
*/
|
|
380
|
-
function morphoSetAuthorizationWithSig(authorization, signature, skipRevert) {
|
|
643
|
+
function morphoSetAuthorizationWithSig(chainId, authorization, signature, skipRevert = true) {
|
|
644
|
+
const { morpho } = getChainAddresses(chainId);
|
|
381
645
|
const { r, s, yParity } = parseSignature(signature);
|
|
382
|
-
return
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
646
|
+
return [
|
|
647
|
+
{
|
|
648
|
+
to: morpho,
|
|
649
|
+
data: encodeFunctionData({
|
|
650
|
+
abi: blueAbi,
|
|
651
|
+
functionName: "setAuthorizationWithSig",
|
|
652
|
+
args: [authorization, { v: yParity + 27, r, s }],
|
|
653
|
+
}),
|
|
654
|
+
value: 0n,
|
|
655
|
+
skipRevert,
|
|
656
|
+
callbackHash: zeroHash,
|
|
657
|
+
},
|
|
658
|
+
];
|
|
387
659
|
}
|
|
388
660
|
BundlerAction.morphoSetAuthorizationWithSig = morphoSetAuthorizationWithSig;
|
|
389
661
|
/**
|
|
390
|
-
* Encodes a call to the
|
|
662
|
+
* Encodes a call to the Adapter to supply to a Morpho Blue market.
|
|
663
|
+
* @param chainId The chain id for which to encode the call.
|
|
391
664
|
* @param market The market params to supply to.
|
|
392
665
|
* @param assets The amount of assets to supply.
|
|
393
666
|
* @param shares The amount of supply shares to mint.
|
|
@@ -395,59 +668,85 @@ export var BundlerAction;
|
|
|
395
668
|
* @param onBehalf The address to supply on behalf of.
|
|
396
669
|
* @param callbackCalls The array of calls to execute inside Morpho Blue's `onMorphoSupply` callback.
|
|
397
670
|
*/
|
|
398
|
-
function morphoSupply(market, assets, shares, slippageAmount, onBehalf, callbackCalls) {
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
671
|
+
function morphoSupply(chainId, market, assets, shares, slippageAmount, onBehalf, callbackCalls) {
|
|
672
|
+
const { bundler3: { generalAdapter1 }, } = getChainAddresses(chainId);
|
|
673
|
+
const reenter = callbackCalls.length > 0;
|
|
674
|
+
const reenterData = reenter
|
|
675
|
+
? encodeAbiParameters(bundler3Abi.find((item) => item.name === "reenter").inputs, [callbackCalls])
|
|
676
|
+
: "0x";
|
|
677
|
+
return [
|
|
678
|
+
{
|
|
679
|
+
to: generalAdapter1,
|
|
680
|
+
data: encodeFunctionData({
|
|
681
|
+
abi: generalAdapter1Abi,
|
|
682
|
+
functionName: "morphoSupply",
|
|
683
|
+
args: [market, assets, shares, slippageAmount, onBehalf, reenterData],
|
|
684
|
+
}),
|
|
685
|
+
value: 0n,
|
|
686
|
+
skipRevert: false,
|
|
687
|
+
callbackHash: reenter ? keccak256(reenterData) : zeroHash,
|
|
688
|
+
},
|
|
689
|
+
];
|
|
411
690
|
}
|
|
412
691
|
BundlerAction.morphoSupply = morphoSupply;
|
|
413
692
|
/**
|
|
414
|
-
* Encodes a call to the
|
|
693
|
+
* Encodes a call to the Adapter to supply collateral to a Morpho Blue market.
|
|
694
|
+
* @param chainId The chain id for which to encode the call.
|
|
415
695
|
* @param market The market params to supply to.
|
|
416
696
|
* @param assets The amount of assets to supply.
|
|
417
697
|
* @param onBehalf The address to supply on behalf of.
|
|
418
698
|
* @param callbackCalls The array of calls to execute inside Morpho Blue's `onMorphoSupplyCollateral` callback.
|
|
419
699
|
*/
|
|
420
|
-
function morphoSupplyCollateral(market, assets, onBehalf, callbackCalls) {
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
700
|
+
function morphoSupplyCollateral(chainId, market, assets, onBehalf, callbackCalls) {
|
|
701
|
+
const { bundler3: { generalAdapter1 }, } = getChainAddresses(chainId);
|
|
702
|
+
const reenter = callbackCalls.length > 0;
|
|
703
|
+
const reenterData = reenter
|
|
704
|
+
? encodeAbiParameters(bundler3Abi.find((item) => item.name === "reenter").inputs, [callbackCalls])
|
|
705
|
+
: "0x";
|
|
706
|
+
return [
|
|
707
|
+
{
|
|
708
|
+
to: generalAdapter1,
|
|
709
|
+
data: encodeFunctionData({
|
|
710
|
+
abi: generalAdapter1Abi,
|
|
711
|
+
functionName: "morphoSupplyCollateral",
|
|
712
|
+
args: [market, assets, onBehalf, reenterData],
|
|
713
|
+
}),
|
|
714
|
+
value: 0n,
|
|
715
|
+
skipRevert: false,
|
|
716
|
+
callbackHash: reenter ? keccak256(reenterData) : zeroHash,
|
|
717
|
+
},
|
|
718
|
+
];
|
|
431
719
|
}
|
|
432
720
|
BundlerAction.morphoSupplyCollateral = morphoSupplyCollateral;
|
|
433
721
|
/**
|
|
434
|
-
* Encodes a call to the
|
|
722
|
+
* Encodes a call to the Adapter to borrow from a Morpho Blue market.
|
|
723
|
+
* @param chainId The chain id for which to encode the call.
|
|
435
724
|
* @param market The market params to borrow from.
|
|
436
725
|
* @param assets The amount of assets to borrow.
|
|
437
726
|
* @param shares The amount of borrow shares to mint.
|
|
438
727
|
* @param slippageAmount The minimum (resp. maximum) amount of assets (resp. borrow shares) to borrow (resp. mint) (protects the sender from unexpected slippage).
|
|
439
728
|
* @param receiver The address to send borrowed tokens to.
|
|
440
729
|
*/
|
|
441
|
-
function morphoBorrow(market, assets, shares, slippageAmount, receiver) {
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
730
|
+
function morphoBorrow(chainId, market, assets, shares, slippageAmount, receiver) {
|
|
731
|
+
const { bundler3: { generalAdapter1 }, } = getChainAddresses(chainId);
|
|
732
|
+
return [
|
|
733
|
+
{
|
|
734
|
+
to: generalAdapter1,
|
|
735
|
+
data: encodeFunctionData({
|
|
736
|
+
abi: generalAdapter1Abi,
|
|
737
|
+
functionName: "morphoBorrow",
|
|
738
|
+
args: [market, assets, shares, slippageAmount, receiver],
|
|
739
|
+
}),
|
|
740
|
+
value: 0n,
|
|
741
|
+
skipRevert: false,
|
|
742
|
+
callbackHash: zeroHash,
|
|
743
|
+
},
|
|
744
|
+
];
|
|
447
745
|
}
|
|
448
746
|
BundlerAction.morphoBorrow = morphoBorrow;
|
|
449
747
|
/**
|
|
450
|
-
* Encodes a call to the
|
|
748
|
+
* Encodes a call to the Adapter to repay to a Morpho Blue market.
|
|
749
|
+
* @param chainId The chain id for which to encode the call.
|
|
451
750
|
* @param market The market params to repay to.
|
|
452
751
|
* @param assets The amount of assets to repay.
|
|
453
752
|
* @param shares The amount of borrow shares to redeem.
|
|
@@ -455,88 +754,138 @@ export var BundlerAction;
|
|
|
455
754
|
* @param onBehalf The address to repay on behalf of.
|
|
456
755
|
* @param callbackCalls The array of calls to execute inside Morpho Blue's `onMorphoSupply` callback.
|
|
457
756
|
*/
|
|
458
|
-
function morphoRepay(market, assets, shares, slippageAmount, onBehalf, callbackCalls) {
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
757
|
+
function morphoRepay(chainId, market, assets, shares, slippageAmount, onBehalf, callbackCalls) {
|
|
758
|
+
const { bundler3: { generalAdapter1 }, } = getChainAddresses(chainId);
|
|
759
|
+
const reenter = callbackCalls.length > 0;
|
|
760
|
+
const reenterData = reenter
|
|
761
|
+
? encodeAbiParameters(bundler3Abi.find((item) => item.name === "reenter").inputs, [callbackCalls])
|
|
762
|
+
: "0x";
|
|
763
|
+
return [
|
|
764
|
+
{
|
|
765
|
+
to: generalAdapter1,
|
|
766
|
+
data: encodeFunctionData({
|
|
767
|
+
abi: generalAdapter1Abi,
|
|
768
|
+
functionName: "morphoRepay",
|
|
769
|
+
args: [market, assets, shares, slippageAmount, onBehalf, reenterData],
|
|
770
|
+
}),
|
|
771
|
+
value: 0n,
|
|
772
|
+
skipRevert: false,
|
|
773
|
+
callbackHash: reenter ? keccak256(reenterData) : zeroHash,
|
|
774
|
+
},
|
|
775
|
+
];
|
|
471
776
|
}
|
|
472
777
|
BundlerAction.morphoRepay = morphoRepay;
|
|
473
778
|
/**
|
|
474
|
-
* Encodes a call to the
|
|
779
|
+
* Encodes a call to the Adapter to withdraw from a Morpho Blue market.
|
|
780
|
+
* @param chainId The chain id for which to encode the call.
|
|
475
781
|
* @param market The market params to withdraw from.
|
|
476
782
|
* @param assets The amount of assets to withdraw.
|
|
477
783
|
* @param shares The amount of supply shares to redeem.
|
|
478
784
|
* @param slippageAmount The minimum (resp. maximum) amount of assets (resp. supply shares) to withdraw (resp. redeem) (protects the sender from unexpected slippage).
|
|
479
785
|
* @param receiver The address to send withdrawn tokens to.
|
|
480
786
|
*/
|
|
481
|
-
function morphoWithdraw(market, assets, shares, slippageAmount, receiver) {
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
787
|
+
function morphoWithdraw(chainId, market, assets, shares, slippageAmount, receiver) {
|
|
788
|
+
const { bundler3: { generalAdapter1 }, } = getChainAddresses(chainId);
|
|
789
|
+
return [
|
|
790
|
+
{
|
|
791
|
+
to: generalAdapter1,
|
|
792
|
+
data: encodeFunctionData({
|
|
793
|
+
abi: generalAdapter1Abi,
|
|
794
|
+
functionName: "morphoWithdraw",
|
|
795
|
+
args: [market, assets, shares, slippageAmount, receiver],
|
|
796
|
+
}),
|
|
797
|
+
value: 0n,
|
|
798
|
+
skipRevert: false,
|
|
799
|
+
callbackHash: zeroHash,
|
|
800
|
+
},
|
|
801
|
+
];
|
|
487
802
|
}
|
|
488
803
|
BundlerAction.morphoWithdraw = morphoWithdraw;
|
|
489
804
|
/**
|
|
490
|
-
* Encodes a call to the
|
|
805
|
+
* Encodes a call to the Adapter to withdraw collateral from a Morpho Blue market.
|
|
806
|
+
* @param chainId The chain id for which to encode the call.
|
|
491
807
|
* @param market The market params to withdraw from.
|
|
492
808
|
* @param assets The amount of assets to withdraw.
|
|
493
809
|
* @param receiver The address to send withdrawn tokens to.
|
|
494
810
|
*/
|
|
495
|
-
function morphoWithdrawCollateral(market, assets, receiver) {
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
811
|
+
function morphoWithdrawCollateral(chainId, market, assets, receiver) {
|
|
812
|
+
const { bundler3: { generalAdapter1 }, } = getChainAddresses(chainId);
|
|
813
|
+
return [
|
|
814
|
+
{
|
|
815
|
+
to: generalAdapter1,
|
|
816
|
+
data: encodeFunctionData({
|
|
817
|
+
abi: generalAdapter1Abi,
|
|
818
|
+
functionName: "morphoWithdrawCollateral",
|
|
819
|
+
args: [market, assets, receiver],
|
|
820
|
+
}),
|
|
821
|
+
value: 0n,
|
|
822
|
+
skipRevert: false,
|
|
823
|
+
callbackHash: zeroHash,
|
|
824
|
+
},
|
|
825
|
+
];
|
|
501
826
|
}
|
|
502
827
|
BundlerAction.morphoWithdrawCollateral = morphoWithdrawCollateral;
|
|
503
828
|
/**
|
|
504
|
-
* Encodes a call to the
|
|
829
|
+
* Encodes a call to the Adapter to flash loan from Morpho Blue.
|
|
830
|
+
* @param chainId The chain id for which to encode the call.
|
|
505
831
|
* @param asset The address of the ERC20 token to flash loan.
|
|
506
832
|
* @param amount The amount of tokens to flash loan.
|
|
507
833
|
* @param callbackCalls The array of calls to execute inside Morpho Blue's `onMorphoFlashLoan` callback.
|
|
508
834
|
*/
|
|
509
|
-
function morphoFlashLoan(asset, amount, callbackCalls) {
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
835
|
+
function morphoFlashLoan(chainId, asset, amount, callbackCalls) {
|
|
836
|
+
const { bundler3: { generalAdapter1 }, } = getChainAddresses(chainId);
|
|
837
|
+
return [
|
|
838
|
+
{
|
|
839
|
+
to: generalAdapter1,
|
|
840
|
+
data: encodeFunctionData({
|
|
841
|
+
abi: generalAdapter1Abi,
|
|
842
|
+
functionName: "morphoFlashLoan",
|
|
843
|
+
args: [
|
|
844
|
+
asset,
|
|
845
|
+
amount,
|
|
846
|
+
encodeFunctionData({
|
|
847
|
+
abi: bundler3Abi,
|
|
848
|
+
functionName: "reenter",
|
|
849
|
+
args: [callbackCalls],
|
|
850
|
+
}),
|
|
851
|
+
],
|
|
852
|
+
}),
|
|
853
|
+
value: 0n,
|
|
854
|
+
skipRevert: false,
|
|
855
|
+
callbackHash: keccak256(`${generalAdapter1}${reenterSelectorHash}`),
|
|
856
|
+
},
|
|
857
|
+
];
|
|
519
858
|
}
|
|
520
859
|
BundlerAction.morphoFlashLoan = morphoFlashLoan;
|
|
521
860
|
/**
|
|
522
|
-
* Encodes a call to the
|
|
523
|
-
* @param
|
|
861
|
+
* Encodes a call to the Adapter to trigger a public reallocation on the PublicAllocator.
|
|
862
|
+
* @param chainId The chain id for which to encode the call.
|
|
524
863
|
* @param vault The vault to reallocate.
|
|
525
|
-
* @param
|
|
864
|
+
* @param fee The vault public reallocation fee.
|
|
526
865
|
* @param withdrawals The array of withdrawals to perform, before supplying everything to the supply market.
|
|
527
866
|
* @param supplyMarketParams The market params to reallocate to.
|
|
528
867
|
*/
|
|
529
|
-
function
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
868
|
+
function publicAllocatorReallocateTo(chainId, vault, fee, withdrawals, supplyMarketParams) {
|
|
869
|
+
const { publicAllocator } = getChainAddresses(chainId);
|
|
870
|
+
return [
|
|
871
|
+
{
|
|
872
|
+
to: publicAllocator,
|
|
873
|
+
data: encodeFunctionData({
|
|
874
|
+
abi: publicAllocatorAbi,
|
|
875
|
+
functionName: "reallocateTo",
|
|
876
|
+
args: [vault, withdrawals, supplyMarketParams],
|
|
877
|
+
}),
|
|
878
|
+
value: fee,
|
|
879
|
+
skipRevert: false,
|
|
880
|
+
callbackHash: zeroHash,
|
|
881
|
+
},
|
|
882
|
+
];
|
|
535
883
|
}
|
|
536
|
-
BundlerAction.
|
|
884
|
+
BundlerAction.publicAllocatorReallocateTo = publicAllocatorReallocateTo;
|
|
537
885
|
/* Universal Rewards Distributor */
|
|
538
886
|
/**
|
|
539
|
-
* Encodes a call to the
|
|
887
|
+
* Encodes a call to the Adapter to claim rewards from the Universal Rewards Distributor.
|
|
888
|
+
* @param chainId The chain id for which to encode the call.
|
|
540
889
|
* @param distributor The address of the distributor to claim rewards from.
|
|
541
890
|
* @param account The address to claim rewards for.
|
|
542
891
|
* @param reward The address of the reward token to claim.
|
|
@@ -544,292 +893,576 @@ export var BundlerAction;
|
|
|
544
893
|
* @param proof The Merkle proof to claim the rewards.
|
|
545
894
|
* @param skipRevert Whether to allow the claim to revert without making the whole multicall revert.
|
|
546
895
|
*/
|
|
547
|
-
function urdClaim(distributor, account, reward, amount, proof, skipRevert) {
|
|
548
|
-
return
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
896
|
+
function urdClaim(distributor, account, reward, amount, proof, skipRevert = true) {
|
|
897
|
+
return [
|
|
898
|
+
{
|
|
899
|
+
to: distributor,
|
|
900
|
+
data: encodeFunctionData({
|
|
901
|
+
abi: universalRewardsDistributorAbi,
|
|
902
|
+
functionName: "claim",
|
|
903
|
+
args: [account, reward, amount, proof],
|
|
904
|
+
}),
|
|
905
|
+
value: 0n,
|
|
906
|
+
skipRevert,
|
|
907
|
+
callbackHash: zeroHash,
|
|
908
|
+
},
|
|
909
|
+
];
|
|
553
910
|
}
|
|
554
911
|
BundlerAction.urdClaim = urdClaim;
|
|
555
912
|
/* Wrapped Native */
|
|
556
913
|
/**
|
|
557
|
-
* Encodes a call to the
|
|
914
|
+
* Encodes a call to the Adapter to wrap native tokens (ETH to WETH on ethereum, MATIC to WMATIC on polygon, etc).
|
|
915
|
+
* @param chainId The chain id for which to encode the call.
|
|
558
916
|
* @param amount The amount of native tokens to wrap (in wei).
|
|
917
|
+
* @param recipient The address to send tokens to. Defaults to the chain's bundler3 general adapter.
|
|
559
918
|
*/
|
|
560
|
-
function wrapNative(amount) {
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
919
|
+
function wrapNative(chainId, amount, recipient) {
|
|
920
|
+
const { bundler3: { generalAdapter1 }, } = getChainAddresses(chainId);
|
|
921
|
+
recipient ??= generalAdapter1;
|
|
922
|
+
return [
|
|
923
|
+
{
|
|
924
|
+
to: generalAdapter1,
|
|
925
|
+
data: encodeFunctionData({
|
|
926
|
+
abi: generalAdapter1Abi,
|
|
927
|
+
functionName: "wrapNative",
|
|
928
|
+
args: [amount, recipient],
|
|
929
|
+
}),
|
|
930
|
+
value: 0n,
|
|
931
|
+
skipRevert: false,
|
|
932
|
+
callbackHash: zeroHash,
|
|
933
|
+
},
|
|
934
|
+
];
|
|
566
935
|
}
|
|
567
936
|
BundlerAction.wrapNative = wrapNative;
|
|
568
937
|
/**
|
|
569
|
-
* Encodes a call to the
|
|
938
|
+
* Encodes a call to the Adapter to unwrap native tokens (WETH to ETH on ethereum, WMATIC to MATIC on polygon, etc).
|
|
939
|
+
* @param chainId The chain id for which to encode the call.
|
|
570
940
|
* @param amount The amount of native tokens to unwrap (in wei).
|
|
941
|
+
* @param recipient The address to send tokens to. Defaults to the chain's bundler3 general adapter.
|
|
571
942
|
*/
|
|
572
|
-
function unwrapNative(amount) {
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
943
|
+
function unwrapNative(chainId, amount, recipient) {
|
|
944
|
+
const { bundler3: { generalAdapter1 }, } = getChainAddresses(chainId);
|
|
945
|
+
recipient ??= generalAdapter1;
|
|
946
|
+
return [
|
|
947
|
+
{
|
|
948
|
+
to: generalAdapter1,
|
|
949
|
+
data: encodeFunctionData({
|
|
950
|
+
abi: generalAdapter1Abi,
|
|
951
|
+
functionName: "unwrapNative",
|
|
952
|
+
args: [amount, recipient],
|
|
953
|
+
}),
|
|
954
|
+
value: 0n,
|
|
955
|
+
skipRevert: false,
|
|
956
|
+
callbackHash: zeroHash,
|
|
957
|
+
},
|
|
958
|
+
];
|
|
578
959
|
}
|
|
579
960
|
BundlerAction.unwrapNative = unwrapNative;
|
|
580
961
|
/* stETH */
|
|
581
962
|
/**
|
|
582
|
-
* Encodes a call to the
|
|
963
|
+
* Encodes a call to the Adapter to stake native tokens using Lido (ETH to stETH on ethereum).
|
|
964
|
+
* @param chainId The chain id for which to encode the call.
|
|
583
965
|
* @param amount The amount of native tokens to stake (in wei).
|
|
584
|
-
* @param
|
|
966
|
+
* @param maxSharePrice The maximum amount of wei to pay for minting 1 share (scaled by RAY).
|
|
585
967
|
* @param referral The referral address to use.
|
|
968
|
+
* @param recipient The address to send stETH to. Defaults to the chain's bundler3 general adapter.
|
|
586
969
|
*/
|
|
587
|
-
function stakeEth(amount,
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
970
|
+
function stakeEth(chainId, amount, maxSharePrice, referral, recipient) {
|
|
971
|
+
const { bundler3: { generalAdapter1 }, } = getChainAddresses(chainId);
|
|
972
|
+
recipient ??= generalAdapter1;
|
|
973
|
+
return [
|
|
974
|
+
{
|
|
975
|
+
to: generalAdapter1,
|
|
976
|
+
data: encodeFunctionData({
|
|
977
|
+
abi: ethereumGeneralAdapter1Abi,
|
|
978
|
+
functionName: "stakeEth",
|
|
979
|
+
args: [amount, maxSharePrice, referral, recipient],
|
|
980
|
+
}),
|
|
981
|
+
value: 0n,
|
|
982
|
+
skipRevert: false,
|
|
983
|
+
callbackHash: zeroHash,
|
|
984
|
+
},
|
|
985
|
+
];
|
|
593
986
|
}
|
|
594
987
|
BundlerAction.stakeEth = stakeEth;
|
|
595
988
|
/* Wrapped stETH */
|
|
596
989
|
/**
|
|
597
|
-
* Encodes a call to the
|
|
990
|
+
* Encodes a call to the Adapter to wrap stETH (stETH to wstETH on ethereum).
|
|
991
|
+
* @param chainId The chain id for which to encode the call.
|
|
598
992
|
* @param amount The amount of stETH to wrap (in wei).
|
|
993
|
+
* @param recipient The address to send wstETH to. Defaults to the chain's bundler3 general adapter.
|
|
599
994
|
*/
|
|
600
|
-
function wrapStEth(amount) {
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
995
|
+
function wrapStEth(chainId, amount, recipient) {
|
|
996
|
+
const { bundler3: { generalAdapter1 }, } = getChainAddresses(chainId);
|
|
997
|
+
recipient ??= generalAdapter1;
|
|
998
|
+
return [
|
|
999
|
+
{
|
|
1000
|
+
to: generalAdapter1,
|
|
1001
|
+
data: encodeFunctionData({
|
|
1002
|
+
abi: ethereumGeneralAdapter1Abi,
|
|
1003
|
+
functionName: "wrapStEth",
|
|
1004
|
+
args: [amount, recipient],
|
|
1005
|
+
}),
|
|
1006
|
+
value: 0n,
|
|
1007
|
+
skipRevert: false,
|
|
1008
|
+
callbackHash: zeroHash,
|
|
1009
|
+
},
|
|
1010
|
+
];
|
|
606
1011
|
}
|
|
607
1012
|
BundlerAction.wrapStEth = wrapStEth;
|
|
608
1013
|
/**
|
|
609
|
-
* Encodes a call to the
|
|
1014
|
+
* Encodes a call to the Adapter to unwrap wstETH (wstETH to stETH on ethereum).
|
|
1015
|
+
* @param chainId The chain id for which to encode the call.
|
|
610
1016
|
* @param amount The amount of wstETH to unwrap (in wei).
|
|
1017
|
+
* @param recipient The address to send stETH to. Defaults to the chain's bundler3 general adapter.
|
|
611
1018
|
*/
|
|
612
|
-
function unwrapStEth(amount) {
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
1019
|
+
function unwrapStEth(chainId, amount, recipient) {
|
|
1020
|
+
const { bundler3: { generalAdapter1 }, } = getChainAddresses(chainId);
|
|
1021
|
+
recipient ??= generalAdapter1;
|
|
1022
|
+
return [
|
|
1023
|
+
{
|
|
1024
|
+
to: generalAdapter1,
|
|
1025
|
+
data: encodeFunctionData({
|
|
1026
|
+
abi: ethereumGeneralAdapter1Abi,
|
|
1027
|
+
functionName: "unwrapStEth",
|
|
1028
|
+
args: [amount, recipient],
|
|
1029
|
+
}),
|
|
1030
|
+
value: 0n,
|
|
1031
|
+
skipRevert: false,
|
|
1032
|
+
callbackHash: zeroHash,
|
|
1033
|
+
},
|
|
1034
|
+
];
|
|
618
1035
|
}
|
|
619
1036
|
BundlerAction.unwrapStEth = unwrapStEth;
|
|
620
1037
|
/* AaveV2 */
|
|
621
1038
|
/**
|
|
622
|
-
*
|
|
623
|
-
*
|
|
1039
|
+
* Encodes a call to the Adapter to repay a debt on AaveV2.
|
|
1040
|
+
* @param chainId The chain id for which to encode the call.
|
|
624
1041
|
* @param asset The debt asset to repay.
|
|
625
1042
|
* @param amount The amount of debt to repay.
|
|
1043
|
+
* @param onBehalf The address on behalf of which to repay.
|
|
626
1044
|
* @param rateMode The interest rate mode used by the debt to repay.
|
|
627
1045
|
*/
|
|
628
|
-
function aaveV2Repay(asset, amount, rateMode) {
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
1046
|
+
function aaveV2Repay(chainId, asset, amount, onBehalf, rateMode = 1n) {
|
|
1047
|
+
const { bundler3: { aaveV2MigrationAdapter }, } = getChainAddresses(chainId);
|
|
1048
|
+
if (aaveV2MigrationAdapter == null)
|
|
1049
|
+
throw new BundlerErrors.UnexpectedAction("aaveV2Repay", chainId);
|
|
1050
|
+
return [
|
|
1051
|
+
{
|
|
1052
|
+
to: aaveV2MigrationAdapter,
|
|
1053
|
+
data: encodeFunctionData({
|
|
1054
|
+
abi: aaveV2MigrationAdapterAbi,
|
|
1055
|
+
functionName: "aaveV2Repay",
|
|
1056
|
+
args: [asset, amount, rateMode, onBehalf],
|
|
1057
|
+
}),
|
|
1058
|
+
value: 0n,
|
|
1059
|
+
skipRevert: false,
|
|
1060
|
+
callbackHash: zeroHash,
|
|
1061
|
+
},
|
|
1062
|
+
];
|
|
634
1063
|
}
|
|
635
1064
|
BundlerAction.aaveV2Repay = aaveV2Repay;
|
|
636
1065
|
/**
|
|
637
|
-
*
|
|
638
|
-
*
|
|
1066
|
+
* Encodes a call to the Adapter to withdrawn from AaveV2.
|
|
1067
|
+
* @param chainId The chain id for which to encode the call.
|
|
639
1068
|
* @param asset The asset to withdraw.
|
|
640
1069
|
* @param amount The amount of asset to withdraw.
|
|
1070
|
+
* @param recipient The recipient of ERC20 tokens. Defaults to the chain's bundler3 general adapter.
|
|
641
1071
|
*/
|
|
642
|
-
function aaveV2Withdraw(asset, amount) {
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
1072
|
+
function aaveV2Withdraw(chainId, asset, amount, recipient) {
|
|
1073
|
+
const { bundler3: { aaveV2MigrationAdapter }, } = getChainAddresses(chainId);
|
|
1074
|
+
if (aaveV2MigrationAdapter == null)
|
|
1075
|
+
throw new BundlerErrors.UnexpectedAction("aaveV2Withdraw", chainId);
|
|
1076
|
+
recipient ??= aaveV2MigrationAdapter;
|
|
1077
|
+
return [
|
|
1078
|
+
{
|
|
1079
|
+
to: aaveV2MigrationAdapter,
|
|
1080
|
+
data: encodeFunctionData({
|
|
1081
|
+
abi: aaveV2MigrationAdapterAbi,
|
|
1082
|
+
functionName: "aaveV2Withdraw",
|
|
1083
|
+
args: [asset, amount, recipient],
|
|
1084
|
+
}),
|
|
1085
|
+
value: 0n,
|
|
1086
|
+
skipRevert: false,
|
|
1087
|
+
callbackHash: zeroHash,
|
|
1088
|
+
},
|
|
1089
|
+
];
|
|
648
1090
|
}
|
|
649
1091
|
BundlerAction.aaveV2Withdraw = aaveV2Withdraw;
|
|
650
1092
|
/* AaveV3 */
|
|
651
1093
|
/**
|
|
652
|
-
*
|
|
653
|
-
*
|
|
1094
|
+
* Encodes a call to the Adapter to repay a debt on AaveV3.
|
|
1095
|
+
* @param chainId The chain id for which to encode the call.
|
|
654
1096
|
* @param asset The debt asset to repay.
|
|
655
1097
|
* @param amount The amount of debt to repay.
|
|
1098
|
+
* @param onBehalf The address on behalf of which to repay.
|
|
656
1099
|
* @param rateMode The interest rate mode used by the debt to repay.
|
|
657
1100
|
*/
|
|
658
|
-
function aaveV3Repay(asset, amount, rateMode) {
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
1101
|
+
function aaveV3Repay(chainId, asset, amount, onBehalf, rateMode = 1n) {
|
|
1102
|
+
const { bundler3: { aaveV3CoreMigrationAdapter }, // TODO: choose between core & prime
|
|
1103
|
+
} = getChainAddresses(chainId);
|
|
1104
|
+
if (aaveV3CoreMigrationAdapter == null)
|
|
1105
|
+
throw new BundlerErrors.UnexpectedAction("aaveV3Repay", chainId);
|
|
1106
|
+
return [
|
|
1107
|
+
{
|
|
1108
|
+
to: aaveV3CoreMigrationAdapter,
|
|
1109
|
+
data: encodeFunctionData({
|
|
1110
|
+
abi: aaveV3MigrationAdapterAbi,
|
|
1111
|
+
functionName: "aaveV3Repay",
|
|
1112
|
+
args: [asset, amount, rateMode, onBehalf],
|
|
1113
|
+
}),
|
|
1114
|
+
value: 0n,
|
|
1115
|
+
skipRevert: false,
|
|
1116
|
+
callbackHash: zeroHash,
|
|
1117
|
+
},
|
|
1118
|
+
];
|
|
664
1119
|
}
|
|
665
1120
|
BundlerAction.aaveV3Repay = aaveV3Repay;
|
|
666
1121
|
/**
|
|
667
|
-
*
|
|
668
|
-
*
|
|
1122
|
+
* Encodes a call to the Adapter to withdrawn from AaveV3.
|
|
1123
|
+
* @param chainId The chain id for which to encode the call.
|
|
669
1124
|
* @param asset The asset to withdraw.
|
|
670
1125
|
* @param amount The amount of asset to withdraw.
|
|
1126
|
+
* @param recipient The recipient of ERC20 tokens. Defaults to the chain's bundler3 general adapter.
|
|
671
1127
|
*/
|
|
672
|
-
function aaveV3Withdraw(asset, amount) {
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
1128
|
+
function aaveV3Withdraw(chainId, asset, amount, recipient) {
|
|
1129
|
+
const { bundler3: { aaveV3CoreMigrationAdapter }, // TODO: choose between core & prime
|
|
1130
|
+
} = getChainAddresses(chainId);
|
|
1131
|
+
if (aaveV3CoreMigrationAdapter == null)
|
|
1132
|
+
throw new BundlerErrors.UnexpectedAction("aaveV3Withdraw", chainId);
|
|
1133
|
+
recipient ??= aaveV3CoreMigrationAdapter;
|
|
1134
|
+
return [
|
|
1135
|
+
{
|
|
1136
|
+
to: aaveV3CoreMigrationAdapter,
|
|
1137
|
+
data: encodeFunctionData({
|
|
1138
|
+
abi: aaveV3MigrationAdapterAbi,
|
|
1139
|
+
functionName: "aaveV3Withdraw",
|
|
1140
|
+
args: [asset, amount, recipient],
|
|
1141
|
+
}),
|
|
1142
|
+
value: 0n,
|
|
1143
|
+
skipRevert: false,
|
|
1144
|
+
callbackHash: zeroHash,
|
|
1145
|
+
},
|
|
1146
|
+
];
|
|
678
1147
|
}
|
|
679
1148
|
BundlerAction.aaveV3Withdraw = aaveV3Withdraw;
|
|
680
1149
|
/* AaveV3 Optimizer */
|
|
681
1150
|
/**
|
|
682
|
-
*
|
|
683
|
-
*
|
|
1151
|
+
* Encodes a call to the Adapter to repay a debt on Morpho's AaveV3Optimizer.
|
|
1152
|
+
* @param chainId The chain id for which to encode the call.
|
|
684
1153
|
* @param underlying The underlying debt asset to repay.
|
|
685
1154
|
* @param amount The amount of debt to repay.
|
|
686
|
-
* @param
|
|
1155
|
+
* @param onBehalf The address on behalf of which to repay.
|
|
687
1156
|
*/
|
|
688
|
-
function aaveV3OptimizerRepay(underlying, amount) {
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
1157
|
+
function aaveV3OptimizerRepay(chainId, underlying, amount, onBehalf) {
|
|
1158
|
+
const { bundler3: { aaveV3OptimizerMigrationAdapter }, } = getChainAddresses(chainId);
|
|
1159
|
+
if (aaveV3OptimizerMigrationAdapter == null)
|
|
1160
|
+
throw new BundlerErrors.UnexpectedAction("aaveV3OptimizerRepay", chainId);
|
|
1161
|
+
return [
|
|
1162
|
+
{
|
|
1163
|
+
to: aaveV3OptimizerMigrationAdapter,
|
|
1164
|
+
data: encodeFunctionData({
|
|
1165
|
+
abi: aaveV3OptimizerMigrationAdapterAbi,
|
|
1166
|
+
functionName: "aaveV3OptimizerRepay",
|
|
1167
|
+
args: [underlying, amount, onBehalf],
|
|
1168
|
+
}),
|
|
1169
|
+
value: 0n,
|
|
1170
|
+
skipRevert: false,
|
|
1171
|
+
callbackHash: zeroHash,
|
|
1172
|
+
},
|
|
1173
|
+
];
|
|
694
1174
|
}
|
|
695
1175
|
BundlerAction.aaveV3OptimizerRepay = aaveV3OptimizerRepay;
|
|
696
1176
|
/**
|
|
697
|
-
*
|
|
698
|
-
*
|
|
1177
|
+
* Encodes a call to the Adapter to withdraw from Morpho's AaveV3Optimizer.
|
|
1178
|
+
* @param chainId The chain id for which to encode the call.
|
|
699
1179
|
* @param underlying The underlying asset to withdraw.
|
|
700
1180
|
* @param amount The amount to withdraw.
|
|
701
1181
|
* @param maxIterations The maximum amount of iterations to use for the withdrawal.
|
|
1182
|
+
* @param recipient The recipient of ERC20 tokens. Defaults to the chain's bundler3 general adapter.
|
|
702
1183
|
*/
|
|
703
|
-
function aaveV3OptimizerWithdraw(underlying, amount, maxIterations) {
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
1184
|
+
function aaveV3OptimizerWithdraw(chainId, underlying, amount, maxIterations, recipient) {
|
|
1185
|
+
const { bundler3: { aaveV3OptimizerMigrationAdapter }, } = getChainAddresses(chainId);
|
|
1186
|
+
if (aaveV3OptimizerMigrationAdapter == null)
|
|
1187
|
+
throw new BundlerErrors.UnexpectedAction("aaveV3OptimizerWithdraw", chainId);
|
|
1188
|
+
recipient ??= aaveV3OptimizerMigrationAdapter;
|
|
1189
|
+
return [
|
|
1190
|
+
{
|
|
1191
|
+
to: aaveV3OptimizerMigrationAdapter,
|
|
1192
|
+
data: encodeFunctionData({
|
|
1193
|
+
abi: aaveV3OptimizerMigrationAdapterAbi,
|
|
1194
|
+
functionName: "aaveV3OptimizerWithdraw",
|
|
1195
|
+
args: [underlying, amount, maxIterations, recipient],
|
|
1196
|
+
}),
|
|
1197
|
+
value: 0n,
|
|
1198
|
+
skipRevert: false,
|
|
1199
|
+
callbackHash: zeroHash,
|
|
1200
|
+
},
|
|
1201
|
+
];
|
|
709
1202
|
}
|
|
710
1203
|
BundlerAction.aaveV3OptimizerWithdraw = aaveV3OptimizerWithdraw;
|
|
711
1204
|
/**
|
|
712
|
-
*
|
|
713
|
-
*
|
|
1205
|
+
* Encodes a call to the Adapter to withdraw collateral from Morpho's AaveV3Optimizer.
|
|
1206
|
+
* @param chainId The chain id for which to encode the call.
|
|
714
1207
|
* @param underlying The underlying asset to withdraw.
|
|
715
1208
|
* @param amount The amount to withdraw.
|
|
1209
|
+
* @param recipient The recipient of ERC20 tokens. Defaults to the chain's bundler3 general adapter.
|
|
716
1210
|
*/
|
|
717
|
-
function aaveV3OptimizerWithdrawCollateral(underlying, amount) {
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
1211
|
+
function aaveV3OptimizerWithdrawCollateral(chainId, underlying, amount, recipient) {
|
|
1212
|
+
const { bundler3: { aaveV3OptimizerMigrationAdapter }, } = getChainAddresses(chainId);
|
|
1213
|
+
if (aaveV3OptimizerMigrationAdapter == null)
|
|
1214
|
+
throw new BundlerErrors.UnexpectedAction("aaveV3OptimizerWithdrawCollateral", chainId);
|
|
1215
|
+
recipient ??= aaveV3OptimizerMigrationAdapter;
|
|
1216
|
+
return [
|
|
1217
|
+
{
|
|
1218
|
+
to: aaveV3OptimizerMigrationAdapter,
|
|
1219
|
+
data: encodeFunctionData({
|
|
1220
|
+
abi: aaveV3OptimizerMigrationAdapterAbi,
|
|
1221
|
+
functionName: "aaveV3OptimizerWithdrawCollateral",
|
|
1222
|
+
args: [underlying, amount, recipient],
|
|
1223
|
+
}),
|
|
1224
|
+
value: 0n,
|
|
1225
|
+
skipRevert: false,
|
|
1226
|
+
callbackHash: zeroHash,
|
|
1227
|
+
},
|
|
1228
|
+
];
|
|
723
1229
|
}
|
|
724
1230
|
BundlerAction.aaveV3OptimizerWithdrawCollateral = aaveV3OptimizerWithdrawCollateral;
|
|
725
1231
|
/**
|
|
726
|
-
*
|
|
727
|
-
*
|
|
1232
|
+
* Encodes a call to the Adapter to approve the Bundler as the sender's manager on Morpho's AaveV3Optimizer.
|
|
1233
|
+
* @param chainId The chain id for which to encode the call.
|
|
1234
|
+
* @param owner The owner of the AaveV3Optimizer position.
|
|
728
1235
|
* @param isApproved Whether the manager is approved.
|
|
729
1236
|
* @param nonce The nonce used to sign.
|
|
730
1237
|
* @param deadline The timestamp until which the signature is valid.
|
|
731
1238
|
* @param signature The Ethers signature to submit.
|
|
1239
|
+
* @param manager The address of the manager to approve. Defaults to the chain's bundler3 AaveV3OptimizerMigrationAdapter.
|
|
732
1240
|
* @param skipRevert Whether to allow the signature to revert without making the whole multicall revert.
|
|
733
1241
|
*/
|
|
734
|
-
function aaveV3OptimizerApproveManagerWithSig(isApproved, nonce, deadline, signature, skipRevert) {
|
|
1242
|
+
function aaveV3OptimizerApproveManagerWithSig(chainId, owner, isApproved, nonce, deadline, signature, manager, skipRevert = true) {
|
|
1243
|
+
const { aaveV3Optimizer, bundler3: { aaveV3OptimizerMigrationAdapter }, } = getChainAddresses(chainId);
|
|
1244
|
+
if (aaveV3Optimizer == null || aaveV3OptimizerMigrationAdapter == null)
|
|
1245
|
+
throw new BundlerErrors.UnexpectedAction("aaveV3OptimizerApproveManagerWithSig", chainId);
|
|
1246
|
+
manager ??= aaveV3OptimizerMigrationAdapter;
|
|
735
1247
|
const { r, s, yParity } = parseSignature(signature);
|
|
736
|
-
return
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
1248
|
+
return [
|
|
1249
|
+
{
|
|
1250
|
+
to: aaveV3Optimizer,
|
|
1251
|
+
data: encodeFunctionData({
|
|
1252
|
+
abi: [
|
|
1253
|
+
{
|
|
1254
|
+
inputs: [
|
|
1255
|
+
{ name: "delegator", type: "address" },
|
|
1256
|
+
{ name: "manager", type: "address" },
|
|
1257
|
+
{ name: "isAllowed", type: "bool" },
|
|
1258
|
+
{ name: "nonce", type: "uint256" },
|
|
1259
|
+
{ name: "deadline", type: "uint256" },
|
|
1260
|
+
{
|
|
1261
|
+
components: [
|
|
1262
|
+
{ name: "v", type: "uint8" },
|
|
1263
|
+
{ name: "r", type: "bytes32" },
|
|
1264
|
+
{ name: "s", type: "bytes32" },
|
|
1265
|
+
],
|
|
1266
|
+
internalType: "struct Types.Signature",
|
|
1267
|
+
name: "signature",
|
|
1268
|
+
type: "tuple",
|
|
1269
|
+
},
|
|
1270
|
+
],
|
|
1271
|
+
name: "approveManagerWithSig",
|
|
1272
|
+
outputs: [],
|
|
1273
|
+
stateMutability: "nonpayable",
|
|
1274
|
+
type: "function",
|
|
1275
|
+
},
|
|
1276
|
+
],
|
|
1277
|
+
functionName: "approveManagerWithSig",
|
|
1278
|
+
args: [
|
|
1279
|
+
owner,
|
|
1280
|
+
manager,
|
|
1281
|
+
isApproved,
|
|
1282
|
+
nonce,
|
|
1283
|
+
deadline,
|
|
1284
|
+
{ v: yParity + 27, r, s },
|
|
1285
|
+
],
|
|
1286
|
+
}),
|
|
1287
|
+
value: 0n,
|
|
744
1288
|
skipRevert,
|
|
745
|
-
|
|
746
|
-
|
|
1289
|
+
callbackHash: zeroHash,
|
|
1290
|
+
},
|
|
1291
|
+
];
|
|
747
1292
|
}
|
|
748
1293
|
BundlerAction.aaveV3OptimizerApproveManagerWithSig = aaveV3OptimizerApproveManagerWithSig;
|
|
749
1294
|
/* CompoundV2 */
|
|
750
1295
|
/**
|
|
751
|
-
*
|
|
752
|
-
*
|
|
1296
|
+
* Encodes a call to the Adapter to repay a debt on CompoundV2.
|
|
1297
|
+
* @param chainId The chain id for which to encode the call.
|
|
753
1298
|
* @param cToken The cToken on which to repay the debt.
|
|
754
1299
|
* @param amount The amount of debt to repay.
|
|
1300
|
+
* @param recipient The recipient of ERC20 tokens. Defaults to the chain's bundler3 general adapter.
|
|
755
1301
|
*/
|
|
756
|
-
function compoundV2Repay(cToken, amount) {
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
1302
|
+
function compoundV2Repay(chainId, cToken, amount, recipient) {
|
|
1303
|
+
const { cEth, bundler3: { compoundV2MigrationAdapter }, } = getChainAddresses(chainId);
|
|
1304
|
+
if (cEth == null || compoundV2MigrationAdapter == null)
|
|
1305
|
+
throw new BundlerErrors.UnexpectedAction("compoundV2Repay", chainId);
|
|
1306
|
+
const isEth = cToken === cEth;
|
|
1307
|
+
recipient ??= compoundV2MigrationAdapter;
|
|
1308
|
+
return [
|
|
1309
|
+
{
|
|
1310
|
+
to: compoundV2MigrationAdapter,
|
|
1311
|
+
data: isEth
|
|
1312
|
+
? encodeFunctionData({
|
|
1313
|
+
abi: compoundV2MigrationAdapterAbi,
|
|
1314
|
+
functionName: "compoundV2RepayEth",
|
|
1315
|
+
args: [amount, recipient],
|
|
1316
|
+
})
|
|
1317
|
+
: encodeFunctionData({
|
|
1318
|
+
abi: compoundV2MigrationAdapterAbi,
|
|
1319
|
+
functionName: "compoundV2RepayErc20",
|
|
1320
|
+
args: [cToken, amount, recipient],
|
|
1321
|
+
}),
|
|
1322
|
+
value: isEth ? amount : 0n,
|
|
1323
|
+
skipRevert: false,
|
|
1324
|
+
callbackHash: zeroHash,
|
|
1325
|
+
},
|
|
1326
|
+
];
|
|
762
1327
|
}
|
|
763
1328
|
BundlerAction.compoundV2Repay = compoundV2Repay;
|
|
764
1329
|
/**
|
|
765
|
-
*
|
|
766
|
-
*
|
|
1330
|
+
* Encodes a call to the Adapter to withdraw collateral from CompoundV2.
|
|
1331
|
+
* @param chainId The chain id for which to encode the call.
|
|
767
1332
|
* @param cToken The cToken on which to withdraw.
|
|
768
1333
|
* @param amount The amount to withdraw.
|
|
1334
|
+
* @param recipient The recipient of ERC20 tokens. Defaults to the chain's bundler3 general adapter.
|
|
769
1335
|
*/
|
|
770
|
-
function compoundV2Redeem(cToken, amount) {
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
1336
|
+
function compoundV2Redeem(chainId, cToken, amount, recipient) {
|
|
1337
|
+
const { cEth, bundler3: { compoundV2MigrationAdapter }, } = getChainAddresses(chainId);
|
|
1338
|
+
if (cEth == null || compoundV2MigrationAdapter == null)
|
|
1339
|
+
throw new BundlerErrors.UnexpectedAction("compoundV2Repay", chainId);
|
|
1340
|
+
const isEth = cToken === cEth;
|
|
1341
|
+
recipient ??= compoundV2MigrationAdapter;
|
|
1342
|
+
return [
|
|
1343
|
+
{
|
|
1344
|
+
to: compoundV2MigrationAdapter,
|
|
1345
|
+
data: isEth
|
|
1346
|
+
? encodeFunctionData({
|
|
1347
|
+
abi: compoundV2MigrationAdapterAbi,
|
|
1348
|
+
functionName: "compoundV2RedeemEth",
|
|
1349
|
+
args: [amount, recipient],
|
|
1350
|
+
})
|
|
1351
|
+
: encodeFunctionData({
|
|
1352
|
+
abi: compoundV2MigrationAdapterAbi,
|
|
1353
|
+
functionName: "compoundV2RedeemErc20",
|
|
1354
|
+
args: [cToken, amount, recipient],
|
|
1355
|
+
}),
|
|
1356
|
+
value: 0n,
|
|
1357
|
+
skipRevert: false,
|
|
1358
|
+
callbackHash: zeroHash,
|
|
1359
|
+
},
|
|
1360
|
+
];
|
|
776
1361
|
}
|
|
777
1362
|
BundlerAction.compoundV2Redeem = compoundV2Redeem;
|
|
778
1363
|
/* CompoundV3 */
|
|
779
1364
|
/**
|
|
780
|
-
*
|
|
781
|
-
*
|
|
1365
|
+
* Encodes a call to the Adapter to repay a debt on CompoundV3.
|
|
1366
|
+
* @param chainId The chain id for which to encode the call.
|
|
782
1367
|
* @param instance The CompoundV3 instance on which to repay the debt.
|
|
783
1368
|
* @param amount The amount of debt to repay.
|
|
1369
|
+
* @param onBehalf The address on behalf of which to repay.
|
|
784
1370
|
*/
|
|
785
|
-
function compoundV3Repay(instance, amount) {
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
1371
|
+
function compoundV3Repay(chainId, instance, amount, onBehalf) {
|
|
1372
|
+
const { bundler3: { compoundV3MigrationAdapter }, } = getChainAddresses(chainId);
|
|
1373
|
+
if (compoundV3MigrationAdapter == null)
|
|
1374
|
+
throw new BundlerErrors.UnexpectedAction("compoundV3Repay", chainId);
|
|
1375
|
+
return [
|
|
1376
|
+
{
|
|
1377
|
+
to: compoundV3MigrationAdapter,
|
|
1378
|
+
data: encodeFunctionData({
|
|
1379
|
+
abi: compoundV3MigrationAdapterAbi,
|
|
1380
|
+
functionName: "compoundV3Repay",
|
|
1381
|
+
args: [instance, amount, onBehalf],
|
|
1382
|
+
}),
|
|
1383
|
+
value: 0n,
|
|
1384
|
+
skipRevert: false,
|
|
1385
|
+
callbackHash: zeroHash,
|
|
1386
|
+
},
|
|
1387
|
+
];
|
|
791
1388
|
}
|
|
792
1389
|
BundlerAction.compoundV3Repay = compoundV3Repay;
|
|
793
1390
|
/**
|
|
794
|
-
*
|
|
795
|
-
*
|
|
1391
|
+
* Encodes a call to the Adapter to withdraw collateral from CompoundV3.
|
|
1392
|
+
* @param chainId The chain id for which to encode the call.
|
|
796
1393
|
* @param instance The CompoundV3 instance on which to withdraw.
|
|
1394
|
+
* @param asset The asset to withdraw.
|
|
797
1395
|
* @param amount The amount to withdraw.
|
|
1396
|
+
* @param recipient The recipient of ERC20 tokens. Defaults to the chain's bundler3 general adapter.
|
|
798
1397
|
*/
|
|
799
|
-
function compoundV3WithdrawFrom(instance, asset, amount) {
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
1398
|
+
function compoundV3WithdrawFrom(chainId, instance, asset, amount, recipient) {
|
|
1399
|
+
const { bundler3: { compoundV3MigrationAdapter }, } = getChainAddresses(chainId);
|
|
1400
|
+
if (compoundV3MigrationAdapter == null)
|
|
1401
|
+
throw new BundlerErrors.UnexpectedAction("compoundV3WithdrawFrom", chainId);
|
|
1402
|
+
recipient ??= compoundV3MigrationAdapter;
|
|
1403
|
+
return [
|
|
1404
|
+
{
|
|
1405
|
+
to: compoundV3MigrationAdapter,
|
|
1406
|
+
data: encodeFunctionData({
|
|
1407
|
+
abi: compoundV3MigrationAdapterAbi,
|
|
1408
|
+
functionName: "compoundV3WithdrawFrom",
|
|
1409
|
+
args: [instance, asset, amount, recipient],
|
|
1410
|
+
}),
|
|
1411
|
+
value: 0n,
|
|
1412
|
+
skipRevert: false,
|
|
1413
|
+
callbackHash: zeroHash,
|
|
1414
|
+
},
|
|
1415
|
+
];
|
|
805
1416
|
}
|
|
806
1417
|
BundlerAction.compoundV3WithdrawFrom = compoundV3WithdrawFrom;
|
|
807
1418
|
/**
|
|
808
|
-
*
|
|
809
|
-
*
|
|
1419
|
+
* Encodes a call to the Adapter to allow the Bundler to act on the sender's position on CompoundV3.
|
|
1420
|
+
* @param chainId The chain id for which to encode the call.
|
|
810
1421
|
* @param instance The CompoundV3 instance on which to submit the signature.
|
|
1422
|
+
* @param owner The owner of the CompoundV3 position.
|
|
811
1423
|
* @param isAllowed Whether the manager is allowed.
|
|
812
1424
|
* @param nonce The nonce used to sign.
|
|
813
1425
|
* @param expiry The timestamp until which the signature is valid.
|
|
814
1426
|
* @param signature The Ethers signature to submit.
|
|
1427
|
+
* @param manager The address of the manager to approve. Defaults to the chain's bundler3 CompoundV3MigrationAdapter.
|
|
815
1428
|
* @param skipRevert Whether to allow the signature to revert without making the whole multicall revert.
|
|
816
1429
|
*/
|
|
817
|
-
function compoundV3AllowBySig(instance, isAllowed, nonce, expiry, signature, skipRevert) {
|
|
1430
|
+
function compoundV3AllowBySig(chainId, instance, owner, isAllowed, nonce, expiry, signature, manager, skipRevert = true) {
|
|
1431
|
+
const { bundler3: { compoundV3MigrationAdapter }, } = getChainAddresses(chainId);
|
|
1432
|
+
if (compoundV3MigrationAdapter == null)
|
|
1433
|
+
throw new BundlerErrors.UnexpectedAction("compoundV3AllowBySig", chainId);
|
|
818
1434
|
const { r, s, yParity } = parseSignature(signature);
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
1435
|
+
manager ??= compoundV3MigrationAdapter;
|
|
1436
|
+
return [
|
|
1437
|
+
{
|
|
1438
|
+
to: instance,
|
|
1439
|
+
data: encodeFunctionData({
|
|
1440
|
+
abi: [
|
|
1441
|
+
{
|
|
1442
|
+
inputs: [
|
|
1443
|
+
{ name: "owner", type: "address" },
|
|
1444
|
+
{ name: "manager", type: "address" },
|
|
1445
|
+
{ name: "isAllowed_", type: "bool" },
|
|
1446
|
+
{ name: "nonce", type: "uint256" },
|
|
1447
|
+
{ name: "expiry", type: "uint256" },
|
|
1448
|
+
{ name: "v", type: "uint8" },
|
|
1449
|
+
{ name: "r", type: "bytes32" },
|
|
1450
|
+
{ name: "s", type: "bytes32" },
|
|
1451
|
+
],
|
|
1452
|
+
name: "allowBySig",
|
|
1453
|
+
outputs: [],
|
|
1454
|
+
stateMutability: "nonpayable",
|
|
1455
|
+
type: "function",
|
|
1456
|
+
},
|
|
1457
|
+
],
|
|
1458
|
+
functionName: "allowBySig",
|
|
1459
|
+
args: [owner, manager, isAllowed, nonce, expiry, yParity + 27, r, s],
|
|
1460
|
+
}),
|
|
1461
|
+
value: 0n,
|
|
830
1462
|
skipRevert,
|
|
831
|
-
|
|
832
|
-
|
|
1463
|
+
callbackHash: zeroHash,
|
|
1464
|
+
},
|
|
1465
|
+
];
|
|
833
1466
|
}
|
|
834
1467
|
BundlerAction.compoundV3AllowBySig = compoundV3AllowBySig;
|
|
835
1468
|
})(BundlerAction || (BundlerAction = {}));
|