@morpho-org/bundler-sdk-viem 3.2.1 → 3.2.2
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/actions.js +4 -32
- package/lib/operations.js +26 -2
- package/package.json +2 -2
package/lib/actions.js
CHANGED
|
@@ -10,38 +10,10 @@ const blue_sdk_viem_1 = require("@morpho-org/blue-sdk-viem");
|
|
|
10
10
|
const actions_1 = require("viem/actions");
|
|
11
11
|
const ActionBundle_js_1 = require("./ActionBundle.js");
|
|
12
12
|
const errors_js_1 = require("./errors.js");
|
|
13
|
-
const encodeErc20Approval = (token,
|
|
13
|
+
const encodeErc20Approval = (token, spender, amount, data) => {
|
|
14
14
|
const { chainId } = data;
|
|
15
|
-
const { morpho, bundler3: { generalAdapter1 }, permit2, } = (0, blue_sdk_1.getChainAddresses)(chainId);
|
|
16
15
|
amount = blue_sdk_1.MathLib.min(amount, simulation_sdk_1.MAX_TOKEN_APPROVALS[chainId]?.[token] ?? viem_1.maxUint256);
|
|
17
16
|
const txRequirements = [];
|
|
18
|
-
if (simulation_sdk_1.APPROVE_ONLY_ONCE_TOKENS[chainId]?.includes(token)) {
|
|
19
|
-
const contract = spender === morpho
|
|
20
|
-
? "morpho"
|
|
21
|
-
: spender === generalAdapter1
|
|
22
|
-
? "bundler3.generalAdapter1"
|
|
23
|
-
: spender === permit2
|
|
24
|
-
? "permit2"
|
|
25
|
-
: undefined;
|
|
26
|
-
const currentAllowance = contract != null
|
|
27
|
-
? data.getHolding(sender, token).erc20Allowances[contract]
|
|
28
|
-
: data.vaults[spender]?.asset === token
|
|
29
|
-
? data.getVaultUser(spender, sender).allowance
|
|
30
|
-
: 0n;
|
|
31
|
-
if (currentAllowance !== 0n)
|
|
32
|
-
txRequirements.push({
|
|
33
|
-
type: "erc20Approve",
|
|
34
|
-
args: [token, spender, 0n],
|
|
35
|
-
tx: {
|
|
36
|
-
to: token,
|
|
37
|
-
data: (0, viem_1.encodeFunctionData)({
|
|
38
|
-
abi: viem_1.erc20Abi,
|
|
39
|
-
functionName: "approve",
|
|
40
|
-
args: [spender, 0n],
|
|
41
|
-
}),
|
|
42
|
-
},
|
|
43
|
-
});
|
|
44
|
-
}
|
|
45
17
|
txRequirements.push({
|
|
46
18
|
type: "erc20Approve",
|
|
47
19
|
args: [token, spender, amount],
|
|
@@ -150,7 +122,7 @@ const encodeOperation = (operation, dataBefore, supportsSignature = true, index
|
|
|
150
122
|
// Signatures are not supported, skip Permit2 approval.
|
|
151
123
|
if (!supportsSignature && spender === permit2)
|
|
152
124
|
break;
|
|
153
|
-
requirements.txs.push(...encodeErc20Approval(operation.address,
|
|
125
|
+
requirements.txs.push(...encodeErc20Approval(operation.address, spender, amount, dataBefore));
|
|
154
126
|
break;
|
|
155
127
|
}
|
|
156
128
|
case "Erc20_Permit": {
|
|
@@ -238,7 +210,7 @@ const encodeOperation = (operation, dataBefore, supportsSignature = true, index
|
|
|
238
210
|
break;
|
|
239
211
|
}
|
|
240
212
|
// Simple permit is not supported, fallback to standard approval.
|
|
241
|
-
requirements.txs.push(...encodeErc20Approval(operation.address,
|
|
213
|
+
requirements.txs.push(...encodeErc20Approval(operation.address, spender, amount, dataBefore));
|
|
242
214
|
break;
|
|
243
215
|
}
|
|
244
216
|
case "Erc20_Permit2": {
|
|
@@ -297,7 +269,7 @@ const encodeOperation = (operation, dataBefore, supportsSignature = true, index
|
|
|
297
269
|
break;
|
|
298
270
|
}
|
|
299
271
|
// Signatures are not supported, fallback to standard approval.
|
|
300
|
-
requirements.txs.push(...encodeErc20Approval(operation.address,
|
|
272
|
+
requirements.txs.push(...encodeErc20Approval(operation.address, generalAdapter1, amount, dataBefore));
|
|
301
273
|
break;
|
|
302
274
|
}
|
|
303
275
|
case "Erc20_Transfer": {
|
package/lib/operations.js
CHANGED
|
@@ -61,7 +61,18 @@ const populateInputTransfer = ({ address, args: { amount, from } }, data, { hasS
|
|
|
61
61
|
nonce: erc2612Nonce,
|
|
62
62
|
},
|
|
63
63
|
});
|
|
64
|
-
else if (useSimpleTransfer)
|
|
64
|
+
else if (useSimpleTransfer) {
|
|
65
|
+
if (simulation_sdk_1.APPROVE_ONLY_ONCE_TOKENS[data.chainId]?.includes(address) &&
|
|
66
|
+
erc20Allowances["bundler3.generalAdapter1"] > 0n)
|
|
67
|
+
operations.push({
|
|
68
|
+
type: "Erc20_Approve",
|
|
69
|
+
sender: from,
|
|
70
|
+
address,
|
|
71
|
+
args: {
|
|
72
|
+
amount: 0n,
|
|
73
|
+
spender: generalAdapter1,
|
|
74
|
+
},
|
|
75
|
+
});
|
|
65
76
|
operations.push({
|
|
66
77
|
type: "Erc20_Approve",
|
|
67
78
|
sender: from,
|
|
@@ -71,6 +82,7 @@ const populateInputTransfer = ({ address, args: { amount, from } }, data, { hasS
|
|
|
71
82
|
spender: generalAdapter1,
|
|
72
83
|
},
|
|
73
84
|
});
|
|
85
|
+
}
|
|
74
86
|
if (useSimplePermit || useSimpleTransfer)
|
|
75
87
|
operations.push({
|
|
76
88
|
type: "Erc20_Transfer",
|
|
@@ -84,7 +96,18 @@ const populateInputTransfer = ({ address, args: { amount, from } }, data, { hasS
|
|
|
84
96
|
});
|
|
85
97
|
// Simple permit is not supported: fallback to Permit2.
|
|
86
98
|
else {
|
|
87
|
-
if (erc20Allowances.permit2 < amount)
|
|
99
|
+
if (erc20Allowances.permit2 < amount) {
|
|
100
|
+
if (simulation_sdk_1.APPROVE_ONLY_ONCE_TOKENS[data.chainId]?.includes(address) &&
|
|
101
|
+
erc20Allowances.permit2 > 0n)
|
|
102
|
+
operations.push({
|
|
103
|
+
type: "Erc20_Approve",
|
|
104
|
+
sender: from,
|
|
105
|
+
address,
|
|
106
|
+
args: {
|
|
107
|
+
amount: 0n,
|
|
108
|
+
spender: permit2,
|
|
109
|
+
},
|
|
110
|
+
});
|
|
88
111
|
operations.push({
|
|
89
112
|
type: "Erc20_Approve",
|
|
90
113
|
sender: from,
|
|
@@ -94,6 +117,7 @@ const populateInputTransfer = ({ address, args: { amount, from } }, data, { hasS
|
|
|
94
117
|
spender: permit2,
|
|
95
118
|
},
|
|
96
119
|
});
|
|
120
|
+
}
|
|
97
121
|
if (permit2BundlerAllowance.amount < amount ||
|
|
98
122
|
permit2BundlerAllowance.expiration < data.block.timestamp)
|
|
99
123
|
operations.push({
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@morpho-org/bundler-sdk-viem",
|
|
3
3
|
"description": "Viem-based extension of `@morpho-org/simulation-sdk` that exports utilities to transform simple interactions on Morpho (such as `Blue_Borrow`) and Morpho Vaults (such as `MetaMorpho_Deposit`) into the required bundles (with ERC20 approvals, transfers, etc) to submit to the bundler onchain.",
|
|
4
|
-
"version": "3.2.
|
|
4
|
+
"version": "3.2.2",
|
|
5
5
|
"author": "Morpho Association <contact@morpho.org>",
|
|
6
6
|
"contributors": [
|
|
7
7
|
"Rubilmax <rmilon@gmail.com>"
|
|
@@ -39,8 +39,8 @@
|
|
|
39
39
|
"@morpho-org/morpho-test": "^2.3.0",
|
|
40
40
|
"@morpho-org/morpho-ts": "^2.4.0",
|
|
41
41
|
"@morpho-org/simulation-sdk": "^3.1.1",
|
|
42
|
-
"@morpho-org/test-wagmi": "^2.0.4",
|
|
43
42
|
"@morpho-org/simulation-sdk-wagmi": "^3.0.2",
|
|
43
|
+
"@morpho-org/test-wagmi": "^2.0.4",
|
|
44
44
|
"@morpho-org/test": "^2.1.4"
|
|
45
45
|
},
|
|
46
46
|
"scripts": {
|