@morpho-org/bundler-sdk-viem 3.0.0-next.7 → 3.0.0-next.9

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
@@ -91,13 +91,13 @@ export const encodeOperation = (operation, dataBefore, supportsSignature = true,
91
91
  const { sender, address } = operation;
92
92
  switch (operation.type) {
93
93
  case "Blue_SetAuthorization": {
94
- const { owner } = operation.args;
94
+ const { owner, isAuthorized, authorized } = operation.args;
95
95
  if (supportsSignature) {
96
96
  const ownerData = dataBefore.getUser(owner);
97
97
  const authorization = {
98
98
  authorizer: owner,
99
- authorized: generalAdapter1,
100
- isAuthorized: true,
99
+ authorized,
100
+ isAuthorized,
101
101
  deadline,
102
102
  nonce: ownerData.morphoNonce,
103
103
  };
@@ -130,13 +130,13 @@ export const encodeOperation = (operation, dataBefore, supportsSignature = true,
130
130
  // Signatures are not supported, fallback to standard approval.
131
131
  requirements.txs.push({
132
132
  type: "morphoSetAuthorization",
133
- args: [generalAdapter1, true],
133
+ args: [authorized, isAuthorized],
134
134
  tx: {
135
135
  to: morpho,
136
136
  data: encodeFunctionData({
137
137
  abi: blueAbi,
138
138
  functionName: "setAuthorization",
139
- args: [generalAdapter1, true],
139
+ args: [authorized, isAuthorized],
140
140
  }),
141
141
  },
142
142
  });
package/lib/operations.js CHANGED
@@ -179,7 +179,8 @@ export const populateSubBundle = (inputOperation, data, options = {}) => {
179
179
  address: morpho,
180
180
  args: {
181
181
  owner: sender,
182
- isBundlerAuthorized: true,
182
+ isAuthorized: true,
183
+ authorized: generalAdapter1,
183
184
  },
184
185
  });
185
186
  // Reallocate liquidity if necessary.
@@ -21,7 +21,7 @@ export type CallbackBundlerOperations = {
21
21
  [OperationType in CallbackBundlerOperationType]: WithOperationArgs<OperationType, BundlerOperationArgs>;
22
22
  };
23
23
  export type CallbackBundlerOperation = CallbackBundlerOperations[CallbackBundlerOperationType];
24
- export declare const BLUE_INPUT_OPERATIONS: readonly ["Blue_Borrow", "Blue_Repay", "Blue_Supply", "Blue_SupplyCollateral", "Blue_Withdraw", "Blue_WithdrawCollateral"];
24
+ export declare const BLUE_INPUT_OPERATIONS: readonly ["Blue_Borrow", "Blue_Repay", "Blue_Supply", "Blue_SupplyCollateral", "Blue_Withdraw", "Blue_WithdrawCollateral", "Blue_SetAuthorization"];
25
25
  export type BlueInputBundlerOperationType = (typeof BLUE_INPUT_OPERATIONS)[number];
26
26
  export interface BlueInputBundlerOperationArgs extends Omit<OperationArgs, (typeof CALLBACK_OPERATIONS)[number]> {
27
27
  Blue_SupplyCollateral: Omit<BlueOperationArgs["Blue_SupplyCollateral"], "callback"> & {
@@ -24,6 +24,7 @@ export const BLUE_INPUT_OPERATIONS = [
24
24
  "Blue_SupplyCollateral",
25
25
  "Blue_Withdraw",
26
26
  "Blue_WithdrawCollateral",
27
+ "Blue_SetAuthorization",
27
28
  ];
28
29
  export const METAMORPHO_INPUT_OPERATIONS = [
29
30
  "MetaMorpho_Deposit",
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.7",
4
+ "version": "3.0.0-next.9",
5
5
  "author": "Morpho Association <contact@morpho.org>",
6
6
  "contributors": [
7
7
  "Rubilmax <rmilon@gmail.com>"
@@ -20,10 +20,10 @@
20
20
  ],
21
21
  "peerDependencies": {
22
22
  "viem": "^2.0.0",
23
- "@morpho-org/blue-sdk": "^2.3.2",
24
- "@morpho-org/blue-sdk-viem": "^2.2.2",
23
+ "@morpho-org/blue-sdk": "^3.0.0-next.13",
24
+ "@morpho-org/simulation-sdk": "^3.0.0-next.4",
25
25
  "@morpho-org/morpho-ts": "^2.2.0",
26
- "@morpho-org/simulation-sdk": "^2.1.4"
26
+ "@morpho-org/blue-sdk-viem": "^2.2.2"
27
27
  },
28
28
  "devDependencies": {
29
29
  "@tanstack/query-core": "^5.62.16",
@@ -35,14 +35,14 @@
35
35
  "typescript": "^5.7.2",
36
36
  "viem": "^2.23.0",
37
37
  "vitest": "^3.0.5",
38
+ "@morpho-org/blue-sdk": "^3.0.0-next.13",
38
39
  "@morpho-org/blue-sdk-viem": "^2.2.2",
39
- "@morpho-org/morpho-test": "^2.2.1",
40
- "@morpho-org/blue-sdk": "^2.3.2",
41
40
  "@morpho-org/morpho-ts": "^2.2.0",
42
- "@morpho-org/simulation-sdk": "^2.1.4",
41
+ "@morpho-org/simulation-sdk": "^3.0.0-next.4",
42
+ "@morpho-org/morpho-test": "^2.2.1",
43
+ "@morpho-org/test": "^2.0.6",
43
44
  "@morpho-org/simulation-sdk-wagmi": "^2.0.5",
44
- "@morpho-org/test-wagmi": "^2.0.4",
45
- "@morpho-org/test": "^2.0.6"
45
+ "@morpho-org/test-wagmi": "^2.0.4"
46
46
  },
47
47
  "scripts": {
48
48
  "prepublish": "$npm_execpath build",