@morpho-org/bundler-sdk-viem 3.2.0-next.2 → 3.2.0-next.3
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.d.ts +0 -3
- package/lib/actions.js +6 -18
- package/lib/operations.js +4 -6
- package/package.json +6 -6
package/lib/actions.d.ts
CHANGED
|
@@ -1,9 +1,6 @@
|
|
|
1
|
-
import { type Address } from "viem";
|
|
2
1
|
import { type MaybeDraft, type SimulationState } from "@morpho-org/simulation-sdk";
|
|
3
2
|
import { ActionBundle, ActionBundleRequirements } from "./ActionBundle.js";
|
|
4
3
|
import type { Action, BundlerOperation, TransactionRequirement } from "./types/index.js";
|
|
5
|
-
export declare const APPROVE_ONLY_ONCE_TOKENS: Partial<Record<number, Address[]>>;
|
|
6
|
-
export declare const MAX_TOKEN_APPROVALS: Partial<Record<number, Record<Address, bigint>>>;
|
|
7
4
|
export declare const encodeOperation: (operation: BundlerOperation, dataBefore: MaybeDraft<SimulationState>, supportsSignature?: boolean, index?: number) => {
|
|
8
5
|
dataAfter: MaybeDraft<SimulationState>;
|
|
9
6
|
actions: Action[];
|
package/lib/actions.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.encodeOperation =
|
|
3
|
+
exports.encodeOperation = void 0;
|
|
4
4
|
exports.encodeBundle = encodeBundle;
|
|
5
5
|
const viem_1 = require("viem");
|
|
6
6
|
const blue_sdk_1 = require("@morpho-org/blue-sdk");
|
|
@@ -10,23 +10,12 @@ 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
|
-
exports.APPROVE_ONLY_ONCE_TOKENS = {
|
|
14
|
-
[blue_sdk_1.ChainId.EthMainnet]: [
|
|
15
|
-
"0xdAC17F958D2ee523a2206206994597C13D831ec7", // USDT
|
|
16
|
-
"0xD533a949740bb3306d119CC777fa900bA034cd52", // CRV
|
|
17
|
-
],
|
|
18
|
-
};
|
|
19
|
-
exports.MAX_TOKEN_APPROVALS = {
|
|
20
|
-
[blue_sdk_1.ChainId.EthMainnet]: {
|
|
21
|
-
"0x1f9840a85d5aF5bf1D1762F925BDADdC4201F984": blue_sdk_1.MathLib.maxUint(96), // UNI --> see https://github.com/Uniswap/governance/blob/eabd8c71ad01f61fb54ed6945162021ee419998e/contracts/Uni.sol#L154
|
|
22
|
-
},
|
|
23
|
-
};
|
|
24
13
|
const encodeErc20Approval = (token, sender, spender, amount, data) => {
|
|
25
14
|
const { chainId } = data;
|
|
26
15
|
const { morpho, bundler3: { generalAdapter1 }, permit2, } = (0, blue_sdk_1.getChainAddresses)(chainId);
|
|
27
|
-
amount = blue_sdk_1.MathLib.min(amount,
|
|
16
|
+
amount = blue_sdk_1.MathLib.min(amount, simulation_sdk_1.MAX_TOKEN_APPROVALS[chainId]?.[token] ?? viem_1.maxUint256);
|
|
28
17
|
const txRequirements = [];
|
|
29
|
-
if (
|
|
18
|
+
if (simulation_sdk_1.APPROVE_ONLY_ONCE_TOKENS[chainId]?.includes(token)) {
|
|
30
19
|
const contract = spender === morpho
|
|
31
20
|
? "morpho"
|
|
32
21
|
: spender === generalAdapter1
|
|
@@ -69,7 +58,6 @@ const encodeErc20Approval = (token, sender, spender, amount, data) => {
|
|
|
69
58
|
};
|
|
70
59
|
const encodeOperation = (operation, dataBefore, supportsSignature = true, index = 0) => {
|
|
71
60
|
const { chainId } = dataBefore;
|
|
72
|
-
const deadline = morpho_ts_1.Time.timestamp() + morpho_ts_1.Time.s.from.h(24n);
|
|
73
61
|
const { morpho, bundler3: { bundler3, generalAdapter1, paraswapAdapter }, permit2, wNative, dai, wstEth, stEth, } = (0, blue_sdk_1.getChainAddresses)(chainId);
|
|
74
62
|
const actions = [];
|
|
75
63
|
const requirements = new ActionBundle_js_1.ActionBundleRequirements();
|
|
@@ -100,7 +88,7 @@ const encodeOperation = (operation, dataBefore, supportsSignature = true, index
|
|
|
100
88
|
const { sender } = operation;
|
|
101
89
|
switch (operation.type) {
|
|
102
90
|
case "Blue_SetAuthorization": {
|
|
103
|
-
const { owner, isAuthorized, authorized } = operation.args;
|
|
91
|
+
const { owner, isAuthorized, authorized, deadline = dataBefore.block.timestamp + morpho_ts_1.Time.s.from.h(2n), } = operation.args;
|
|
104
92
|
// Never authorize bundler3 otherwise the signature can be used independently.
|
|
105
93
|
if (authorized === bundler3)
|
|
106
94
|
throw new errors_js_1.BundlerErrors.UnexpectedSignature(authorized);
|
|
@@ -169,7 +157,7 @@ const encodeOperation = (operation, dataBefore, supportsSignature = true, index
|
|
|
169
157
|
// Native token cannot be permitted.
|
|
170
158
|
if (operation.address === blue_sdk_1.NATIVE_ADDRESS)
|
|
171
159
|
break;
|
|
172
|
-
const { amount, spender, nonce } = operation.args;
|
|
160
|
+
const { amount, spender, nonce, deadline = dataBefore.block.timestamp + morpho_ts_1.Time.s.from.h(2n), } = operation.args;
|
|
173
161
|
// Never permit any other address than the GeneralAdapter1 otherwise
|
|
174
162
|
// the signature can be used independently.
|
|
175
163
|
if (spender !== generalAdapter1)
|
|
@@ -257,7 +245,7 @@ const encodeOperation = (operation, dataBefore, supportsSignature = true, index
|
|
|
257
245
|
// Native token cannot be permitted.
|
|
258
246
|
if (operation.address === blue_sdk_1.NATIVE_ADDRESS)
|
|
259
247
|
break;
|
|
260
|
-
const { amount, expiration, nonce } = operation.args;
|
|
248
|
+
const { amount, expiration, nonce, deadline = dataBefore.block.timestamp + morpho_ts_1.Time.s.from.h(2n), } = operation.args;
|
|
261
249
|
if (supportsSignature) {
|
|
262
250
|
const action = {
|
|
263
251
|
type: "approve2",
|
package/lib/operations.js
CHANGED
|
@@ -651,13 +651,11 @@ const simulateRequiredTokenAmounts = (operations, data) => {
|
|
|
651
651
|
});
|
|
652
652
|
// Simulate the operations to calculate the required token amounts.
|
|
653
653
|
const steps = (0, simulation_sdk_1.simulateOperations)(operations, virtualBundlerData);
|
|
654
|
-
return (0, morpho_ts_1.entries)((0, morpho_ts_1.getLast)(steps).holdings[generalAdapter1] ?? {})
|
|
655
|
-
.map(([token, holding]) => ({
|
|
656
|
-
token,
|
|
654
|
+
return ((0, morpho_ts_1.entries)((0, morpho_ts_1.getLast)(steps).holdings[generalAdapter1] ?? {})
|
|
657
655
|
// Safe cast because the holding was transformed to a VirtualHolding.
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
.filter(({ required }) => required > 0n);
|
|
656
|
+
.filter((entry) => entry[1] != null)
|
|
657
|
+
.map(([token, { required }]) => ({ token, required }))
|
|
658
|
+
.filter(({ required }) => required > 0n));
|
|
661
659
|
};
|
|
662
660
|
exports.simulateRequiredTokenAmounts = simulateRequiredTokenAmounts;
|
|
663
661
|
const getSimulatedBundlerOperation = (operation, { slippage } = {}) => {
|
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.0-next.
|
|
4
|
+
"version": "3.2.0-next.3",
|
|
5
5
|
"author": "Morpho Association <contact@morpho.org>",
|
|
6
6
|
"contributors": [
|
|
7
7
|
"Rubilmax <rmilon@gmail.com>"
|
|
@@ -19,10 +19,10 @@
|
|
|
19
19
|
],
|
|
20
20
|
"peerDependencies": {
|
|
21
21
|
"viem": "^2.0.0",
|
|
22
|
+
"@morpho-org/blue-sdk": "^4.0.0-next.3",
|
|
22
23
|
"@morpho-org/blue-sdk-viem": "^3.1.1",
|
|
23
24
|
"@morpho-org/morpho-ts": "^2.3.0",
|
|
24
|
-
"@morpho-org/
|
|
25
|
-
"@morpho-org/simulation-sdk": "^3.1.0-next.1"
|
|
25
|
+
"@morpho-org/simulation-sdk": "^3.1.0-next.2"
|
|
26
26
|
},
|
|
27
27
|
"devDependencies": {
|
|
28
28
|
"@tanstack/query-core": "^5.62.16",
|
|
@@ -34,11 +34,11 @@
|
|
|
34
34
|
"typescript": "^5.7.2",
|
|
35
35
|
"viem": "^2.23.0",
|
|
36
36
|
"vitest": "^3.0.5",
|
|
37
|
-
"@morpho-org/blue-sdk": "^
|
|
37
|
+
"@morpho-org/blue-sdk-viem": "^3.1.1",
|
|
38
|
+
"@morpho-org/blue-sdk": "^4.0.0-next.3",
|
|
38
39
|
"@morpho-org/morpho-test": "^2.3.0",
|
|
39
40
|
"@morpho-org/morpho-ts": "^2.3.0",
|
|
40
|
-
"@morpho-org/simulation-sdk": "^3.1.0-next.
|
|
41
|
-
"@morpho-org/blue-sdk-viem": "^3.1.1",
|
|
41
|
+
"@morpho-org/simulation-sdk": "^3.1.0-next.2",
|
|
42
42
|
"@morpho-org/simulation-sdk-wagmi": "^3.0.1",
|
|
43
43
|
"@morpho-org/test": "^2.1.3",
|
|
44
44
|
"@morpho-org/test-wagmi": "^2.0.4"
|