@morpho-org/bundler-sdk-viem 3.1.0 → 3.1.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/BundlerAction.js +1 -9
- package/lib/operations.js +27 -19
- package/package.json +9 -9
package/lib/BundlerAction.js
CHANGED
|
@@ -906,15 +906,7 @@ var BundlerAction;
|
|
|
906
906
|
data: (0, viem_1.encodeFunctionData)({
|
|
907
907
|
abi: abis_js_1.generalAdapter1Abi,
|
|
908
908
|
functionName: "morphoFlashLoan",
|
|
909
|
-
args: [
|
|
910
|
-
asset,
|
|
911
|
-
amount,
|
|
912
|
-
(0, viem_1.encodeFunctionData)({
|
|
913
|
-
abi: abis_js_1.bundler3Abi,
|
|
914
|
-
functionName: "reenter",
|
|
915
|
-
args: [callbackCalls],
|
|
916
|
-
}),
|
|
917
|
-
],
|
|
909
|
+
args: [asset, amount, reenterData],
|
|
918
910
|
}),
|
|
919
911
|
value: 0n,
|
|
920
912
|
skipRevert,
|
package/lib/operations.js
CHANGED
|
@@ -596,33 +596,41 @@ const populateBundle = (inputOperations, data, options) => {
|
|
|
596
596
|
return { operations, steps };
|
|
597
597
|
};
|
|
598
598
|
exports.populateBundle = populateBundle;
|
|
599
|
+
class VirtualHolding extends blue_sdk_1.Holding {
|
|
600
|
+
required = 0n;
|
|
601
|
+
get balance() {
|
|
602
|
+
return this._balance;
|
|
603
|
+
}
|
|
604
|
+
set balance(value) {
|
|
605
|
+
if (value < 0n) {
|
|
606
|
+
this.required += -value;
|
|
607
|
+
this._balance = 0n;
|
|
608
|
+
}
|
|
609
|
+
else
|
|
610
|
+
this._balance = value;
|
|
611
|
+
}
|
|
612
|
+
}
|
|
599
613
|
const simulateRequiredTokenAmounts = (operations, data) => {
|
|
600
614
|
const { bundler3: { generalAdapter1 }, } = (0, blue_sdk_1.getChainAddresses)(data.chainId);
|
|
601
615
|
const virtualBundlerData = (0, simulation_sdk_1.produceImmutable)(data, (draft) => {
|
|
602
|
-
|
|
603
|
-
|
|
616
|
+
const bundlerHoldings = draft.holdings[generalAdapter1];
|
|
617
|
+
if (bundlerHoldings == null)
|
|
618
|
+
return;
|
|
619
|
+
(0, morpho_ts_1.entries)(bundlerHoldings).map(([token, holding]) => {
|
|
620
|
+
if (holding == null)
|
|
604
621
|
return;
|
|
605
|
-
|
|
606
|
-
bundlerTokenData.balance += blue_sdk_1.MathLib.MAX_UINT_160;
|
|
622
|
+
bundlerHoldings[token] = new VirtualHolding(holding);
|
|
607
623
|
});
|
|
608
624
|
});
|
|
625
|
+
// Simulate the operations to calculate the required token amounts.
|
|
609
626
|
const steps = (0, simulation_sdk_1.simulateOperations)(operations, virtualBundlerData);
|
|
610
|
-
|
|
627
|
+
return (0, morpho_ts_1.entries)((0, morpho_ts_1.getLast)(steps).holdings[generalAdapter1] ?? {})
|
|
628
|
+
.map(([token, holding]) => ({
|
|
611
629
|
token,
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
// | | |=> MAX_UINT_160 - (3 * MAX_UINT_160 + z) < 0
|
|
617
|
-
// | |=> MAX_UINT_160 - (2 * MAX_UINT_160 - y) < 0
|
|
618
|
-
// |=> MAX_UINT_160 - (MAX_UINT_160 - y - x) > 0
|
|
619
|
-
blue_sdk_1.MathLib.MAX_UINT_160 -
|
|
620
|
-
(step.holdings[generalAdapter1]?.[token]?.balance ?? 0n))
|
|
621
|
-
.sort((0, morpho_ts_1.bigIntComparator)((required) => required,
|
|
622
|
-
// Take the highest required amount among all operations.
|
|
623
|
-
"desc"))[0],
|
|
624
|
-
}));
|
|
625
|
-
return bundlerTokenDiffs.filter(({ required }) => required > 0n);
|
|
630
|
+
// Safe cast because the holding was transformed to a VirtualHolding.
|
|
631
|
+
required: holding.required,
|
|
632
|
+
}))
|
|
633
|
+
.filter(({ required }) => required > 0n);
|
|
626
634
|
};
|
|
627
635
|
exports.simulateRequiredTokenAmounts = simulateRequiredTokenAmounts;
|
|
628
636
|
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.1.
|
|
4
|
+
"version": "3.1.2",
|
|
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": "^3.0.
|
|
23
|
-
"@morpho-org/
|
|
24
|
-
"@morpho-org/
|
|
25
|
-
"@morpho-org/
|
|
22
|
+
"@morpho-org/blue-sdk": "^3.0.6",
|
|
23
|
+
"@morpho-org/blue-sdk-viem": "^3.0.0",
|
|
24
|
+
"@morpho-org/simulation-sdk": "^3.0.1",
|
|
25
|
+
"@morpho-org/morpho-ts": "^2.3.0"
|
|
26
26
|
},
|
|
27
27
|
"devDependencies": {
|
|
28
28
|
"@tanstack/query-core": "^5.62.16",
|
|
@@ -34,12 +34,12 @@
|
|
|
34
34
|
"typescript": "^5.7.2",
|
|
35
35
|
"viem": "^2.23.0",
|
|
36
36
|
"vitest": "^3.0.5",
|
|
37
|
-
"@morpho-org/blue-sdk": "^3.0.
|
|
37
|
+
"@morpho-org/blue-sdk": "^3.0.6",
|
|
38
38
|
"@morpho-org/blue-sdk-viem": "^3.0.0",
|
|
39
|
-
"@morpho-org/morpho-test": "^2.3.0",
|
|
40
39
|
"@morpho-org/morpho-ts": "^2.3.0",
|
|
41
|
-
"@morpho-org/
|
|
42
|
-
"@morpho-org/simulation-sdk
|
|
40
|
+
"@morpho-org/morpho-test": "^2.3.0",
|
|
41
|
+
"@morpho-org/simulation-sdk": "^3.0.1",
|
|
42
|
+
"@morpho-org/simulation-sdk-wagmi": "^3.0.1",
|
|
43
43
|
"@morpho-org/test-wagmi": "^2.0.4",
|
|
44
44
|
"@morpho-org/test": "^2.1.3"
|
|
45
45
|
},
|