@morpho-org/bundler-sdk-viem 3.0.0-next.6 → 3.0.0-next.8

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.
@@ -1,9 +1,9 @@
1
1
  import { aaveV2MigrationAdapterAbi, aaveV3MigrationAdapterAbi, aaveV3OptimizerMigrationAdapterAbi, bundler3Abi, compoundV2MigrationAdapterAbi, compoundV3MigrationAdapterAbi, coreAdapterAbi, erc20WrapperAdapterAbi, ethereumGeneralAdapter1Abi, generalAdapter1Abi, universalRewardsDistributorAbi, } from "./abis.js";
2
2
  import { getChainAddresses, } from "@morpho-org/blue-sdk";
3
3
  import { blueAbi, erc2612Abi, permit2Abi, publicAllocatorAbi, } from "@morpho-org/blue-sdk-viem";
4
- import { encodeAbiParameters, encodeFunctionData, keccak256, maxUint256, parseSignature, toFunctionSelector, zeroHash, } from "viem";
4
+ import { encodeAbiParameters, encodeFunctionData, keccak256, maxUint256, parseSignature, zeroHash, } from "viem";
5
5
  import { BundlerErrors } from "./errors.js";
6
- const reenterSelectorHash = keccak256(toFunctionSelector(bundler3Abi.find((item) => item.type === "function" && item.name === "reenter")));
6
+ const reenterAbiInputs = bundler3Abi.find((item) => item.name === "reenter").inputs;
7
7
  /**
8
8
  * Namespace to easily encode calls to the Bundler contract, using viem.
9
9
  */
@@ -673,7 +673,7 @@ export var BundlerAction;
673
673
  const { bundler3: { generalAdapter1 }, } = getChainAddresses(chainId);
674
674
  const reenter = callbackCalls.length > 0;
675
675
  const reenterData = reenter
676
- ? encodeAbiParameters(bundler3Abi.find((item) => item.name === "reenter").inputs, [callbackCalls])
676
+ ? encodeAbiParameters(reenterAbiInputs, [callbackCalls])
677
677
  : "0x";
678
678
  return [
679
679
  {
@@ -702,7 +702,7 @@ export var BundlerAction;
702
702
  const { bundler3: { generalAdapter1 }, } = getChainAddresses(chainId);
703
703
  const reenter = callbackCalls.length > 0;
704
704
  const reenterData = reenter
705
- ? encodeAbiParameters(bundler3Abi.find((item) => item.name === "reenter").inputs, [callbackCalls])
705
+ ? encodeAbiParameters(reenterAbiInputs, [callbackCalls])
706
706
  : "0x";
707
707
  return [
708
708
  {
@@ -759,7 +759,7 @@ export var BundlerAction;
759
759
  const { bundler3: { generalAdapter1 }, } = getChainAddresses(chainId);
760
760
  const reenter = callbackCalls.length > 0;
761
761
  const reenterData = reenter
762
- ? encodeAbiParameters(bundler3Abi.find((item) => item.name === "reenter").inputs, [callbackCalls])
762
+ ? encodeAbiParameters(reenterAbiInputs, [callbackCalls])
763
763
  : "0x";
764
764
  return [
765
765
  {
@@ -835,6 +835,10 @@ export var BundlerAction;
835
835
  */
836
836
  function morphoFlashLoan(chainId, asset, amount, callbackCalls) {
837
837
  const { bundler3: { generalAdapter1 }, } = getChainAddresses(chainId);
838
+ const reenter = callbackCalls.length > 0;
839
+ const reenterData = reenter
840
+ ? encodeAbiParameters(reenterAbiInputs, [callbackCalls])
841
+ : "0x";
838
842
  return [
839
843
  {
840
844
  to: generalAdapter1,
@@ -853,7 +857,7 @@ export var BundlerAction;
853
857
  }),
854
858
  value: 0n,
855
859
  skipRevert: false,
856
- callbackHash: keccak256(`${generalAdapter1}${reenterSelectorHash}`),
860
+ callbackHash: reenter ? keccak256(reenterData) : zeroHash,
857
861
  },
858
862
  ];
859
863
  }
package/lib/actions.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import { encodeFunctionData, erc20Abi, maxUint256, verifyTypedData, zeroAddress, } from "viem";
2
- import { ChainId, MathLib, NATIVE_ADDRESS, convexWrapperTokens, erc20WrapperTokens, getChainAddresses, getUnwrappedToken, } from "@morpho-org/blue-sdk";
2
+ import { ChainId, DEFAULT_SLIPPAGE_TOLERANCE, MathLib, NATIVE_ADDRESS, convexWrapperTokens, erc20WrapperTokens, getChainAddresses, getUnwrappedToken, } from "@morpho-org/blue-sdk";
3
3
  import { Time, getValue } from "@morpho-org/morpho-ts";
4
4
  import { getCurrent, simulateOperation, } from "@morpho-org/simulation-sdk";
5
5
  import { blueAbi, getAuthorizationTypedData, getDaiPermitTypedData, getPermit2PermitTypedData, getPermitTypedData, } from "@morpho-org/blue-sdk-viem";
@@ -389,7 +389,7 @@ export const encodeOperation = (operation, dataBefore, supportsSignature = true,
389
389
  break;
390
390
  }
391
391
  case "Blue_Supply": {
392
- const { id, assets = 0n, shares = 0n, onBehalf, slippage = 0n, } = operation.args;
392
+ const { id, assets = 0n, shares = 0n, onBehalf, slippage = DEFAULT_SLIPPAGE_TOLERANCE, } = operation.args;
393
393
  const market = dataBefore.getMarket(id);
394
394
  const maxSharePrice = market.toSupplyAssets(MathLib.wToRay(MathLib.WAD + slippage));
395
395
  actions.push({
@@ -406,7 +406,7 @@ export const encodeOperation = (operation, dataBefore, supportsSignature = true,
406
406
  break;
407
407
  }
408
408
  case "Blue_Withdraw": {
409
- const { id, assets = 0n, shares = 0n, receiver, slippage = 0n, } = operation.args;
409
+ const { id, assets = 0n, shares = 0n, receiver, slippage = DEFAULT_SLIPPAGE_TOLERANCE, } = operation.args;
410
410
  const market = dataBefore.getMarket(id);
411
411
  const minSharePrice = market.toSupplyAssets(MathLib.wToRay(MathLib.WAD - slippage));
412
412
  actions.push({
@@ -416,7 +416,7 @@ export const encodeOperation = (operation, dataBefore, supportsSignature = true,
416
416
  break;
417
417
  }
418
418
  case "Blue_Borrow": {
419
- const { id, assets = 0n, shares = 0n, receiver, slippage = 0n, } = operation.args;
419
+ const { id, assets = 0n, shares = 0n, receiver, slippage = DEFAULT_SLIPPAGE_TOLERANCE, } = operation.args;
420
420
  const market = dataBefore.getMarket(id);
421
421
  const minSharePrice = market.toBorrowAssets(MathLib.wToRay(MathLib.WAD - slippage));
422
422
  actions.push({
@@ -426,7 +426,7 @@ export const encodeOperation = (operation, dataBefore, supportsSignature = true,
426
426
  break;
427
427
  }
428
428
  case "Blue_Repay": {
429
- const { id, assets = 0n, shares = 0n, onBehalf, slippage = 0n, } = operation.args;
429
+ const { id, assets = 0n, shares = 0n, onBehalf, slippage = DEFAULT_SLIPPAGE_TOLERANCE, } = operation.args;
430
430
  const market = dataBefore.getMarket(id);
431
431
  const maxSharePrice = market.toBorrowAssets(MathLib.wToRay(MathLib.WAD + slippage));
432
432
  actions.push({
@@ -471,7 +471,7 @@ export const encodeOperation = (operation, dataBefore, supportsSignature = true,
471
471
  break;
472
472
  }
473
473
  case "MetaMorpho_Deposit": {
474
- const { assets = 0n, shares = 0n, owner, slippage = 0n } = operation.args;
474
+ const { assets = 0n, shares = 0n, owner, slippage = DEFAULT_SLIPPAGE_TOLERANCE, } = operation.args;
475
475
  const vault = dataBefore.getVault(address);
476
476
  const maxSharePrice = vault.toAssets(MathLib.wToRay(MathLib.WAD + slippage));
477
477
  if (shares === 0n)
@@ -487,7 +487,7 @@ export const encodeOperation = (operation, dataBefore, supportsSignature = true,
487
487
  break;
488
488
  }
489
489
  case "MetaMorpho_Withdraw": {
490
- const { assets = 0n, shares = 0n, owner, receiver, slippage = 0n, } = operation.args;
490
+ const { assets = 0n, shares = 0n, owner, receiver, slippage = DEFAULT_SLIPPAGE_TOLERANCE, } = operation.args;
491
491
  const vault = dataBefore.getVault(address);
492
492
  const minSharePrice = vault.toAssets(MathLib.wToRay(MathLib.WAD - slippage));
493
493
  if (assets > 0n)
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.0.0-next.6",
4
+ "version": "3.0.0-next.8",
5
5
  "author": "Morpho Association <contact@morpho.org>",
6
6
  "contributors": [
7
7
  "Rubilmax <rmilon@gmail.com>"
@@ -21,8 +21,8 @@
21
21
  "peerDependencies": {
22
22
  "viem": "^2.0.0",
23
23
  "@morpho-org/blue-sdk": "^2.3.2",
24
- "@morpho-org/morpho-ts": "^2.1.0",
25
24
  "@morpho-org/blue-sdk-viem": "^2.2.2",
25
+ "@morpho-org/morpho-ts": "^2.2.0",
26
26
  "@morpho-org/simulation-sdk": "^2.1.4"
27
27
  },
28
28
  "devDependencies": {
@@ -37,12 +37,12 @@
37
37
  "vitest": "^3.0.5",
38
38
  "@morpho-org/blue-sdk": "^2.3.2",
39
39
  "@morpho-org/blue-sdk-viem": "^2.2.2",
40
- "@morpho-org/morpho-test": "^2.3.0-next.1",
40
+ "@morpho-org/morpho-ts": "^2.2.0",
41
+ "@morpho-org/morpho-test": "^2.2.1",
41
42
  "@morpho-org/simulation-sdk": "^2.1.4",
42
- "@morpho-org/morpho-ts": "^2.1.0",
43
43
  "@morpho-org/simulation-sdk-wagmi": "^2.0.5",
44
- "@morpho-org/test": "^2.0.6",
45
- "@morpho-org/test-wagmi": "^2.0.4"
44
+ "@morpho-org/test-wagmi": "^2.0.4",
45
+ "@morpho-org/test": "^2.0.6"
46
46
  },
47
47
  "scripts": {
48
48
  "prepublish": "$npm_execpath build",