@morpho-org/bundler-sdk-viem 3.0.0-next.12 → 3.0.0-next.14

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.
@@ -88,7 +88,7 @@ export declare namespace BundlerAction {
88
88
  * @param recipient The recipient of ERC20 tokens. Defaults to the chain's bundler3 general adapter.
89
89
  * @param skipRevert Whether to allow the transfer to revert without making the whole bundler revert. Defaults to false.
90
90
  */
91
- function transferFrom2(chainId: ChainId, asset: Address, owner: Address, amount: bigint, recipient?: Address, skipRevert?: boolean): BundlerCall[];
91
+ function transferFrom2(chainId: ChainId, asset: Address, amount: bigint, recipient?: Address, skipRevert?: boolean): BundlerCall[];
92
92
  /**
93
93
  * Encodes a call to the Adapter to wrap ERC20 tokens via the provided ERC20Wrapper.
94
94
  * @param chainId The chain id for which to encode the call.
@@ -379,7 +379,7 @@ export var BundlerAction;
379
379
  * @param skipRevert Whether to allow the permit to revert without making the whole bundle revert. Defaults to true.
380
380
  */
381
381
  function approve2(chainId, owner, permitSingle, signature, skipRevert = true) {
382
- const { permit2 } = getChainAddresses(chainId);
382
+ const { permit2, bundler3: { generalAdapter1 }, } = getChainAddresses(chainId);
383
383
  if (permit2 == null)
384
384
  throw new BundlerErrors.UnexpectedAction("approve2", chainId);
385
385
  return [
@@ -388,7 +388,16 @@ export var BundlerAction;
388
388
  data: encodeFunctionData({
389
389
  abi: permit2Abi,
390
390
  functionName: "permit",
391
- args: [owner, permitSingle, signature],
391
+ args: [
392
+ owner,
393
+ {
394
+ ...permitSingle,
395
+ // Never permit any other address than the GeneralAdapter1 otherwise
396
+ // the signature can be extracted and used independently.
397
+ spender: generalAdapter1,
398
+ },
399
+ signature,
400
+ ],
392
401
  }),
393
402
  value: 0n,
394
403
  skipRevert,
@@ -406,19 +415,16 @@ export var BundlerAction;
406
415
  * @param recipient The recipient of ERC20 tokens. Defaults to the chain's bundler3 general adapter.
407
416
  * @param skipRevert Whether to allow the transfer to revert without making the whole bundler revert. Defaults to false.
408
417
  */
409
- function transferFrom2(chainId, asset, owner, amount, recipient, skipRevert = false) {
410
- const { permit2, bundler3: { generalAdapter1 }, } = getChainAddresses(chainId);
411
- if (permit2 == null)
412
- throw new BundlerErrors.UnexpectedAction("transferFrom2", chainId);
418
+ function transferFrom2(chainId, asset, amount, recipient, skipRevert = false) {
419
+ const { bundler3: { generalAdapter1 }, } = getChainAddresses(chainId);
413
420
  recipient ??= generalAdapter1;
414
421
  return [
415
422
  {
416
- to: permit2,
423
+ to: generalAdapter1,
417
424
  data: encodeFunctionData({
418
- abi: permit2Abi,
419
- functionName: "transferFrom",
420
- // TODO: batch all permit2 transfers via transferFrom(AllowanceTransferDetails[] calldata)
421
- args: [owner, recipient, amount, asset],
425
+ abi: generalAdapter1Abi,
426
+ functionName: "permit2TransferFrom",
427
+ args: [asset, recipient, amount],
422
428
  }),
423
429
  value: 0n,
424
430
  skipRevert,
package/lib/actions.js CHANGED
@@ -65,7 +65,7 @@ const encodeErc20Approval = (token, sender, spender, amount, data) => {
65
65
  export const encodeOperation = (operation, dataBefore, supportsSignature = true, index = 0) => {
66
66
  const { chainId } = dataBefore;
67
67
  const deadline = Time.timestamp() + Time.s.from.h(24n);
68
- const { morpho, bundler3: { bundler3, generalAdapter1 }, permit2, wNative, dai, wstEth, stEth, } = getChainAddresses(chainId);
68
+ const { morpho, bundler3: { generalAdapter1 }, permit2, wNative, dai, wstEth, stEth, } = getChainAddresses(chainId);
69
69
  const actions = [];
70
70
  const requirements = new ActionBundleRequirements();
71
71
  let callbackBundle;
@@ -255,7 +255,6 @@ export const encodeOperation = (operation, dataBefore, supportsSignature = true,
255
255
  nonce: Number(nonce),
256
256
  expiration: Number(expiration),
257
257
  },
258
- spender: bundler3,
259
258
  sigDeadline: deadline,
260
259
  },
261
260
  null,
@@ -266,12 +265,14 @@ export const encodeOperation = (operation, dataBefore, supportsSignature = true,
266
265
  requirements.signatures.push({
267
266
  action,
268
267
  async sign(client, account = client.account) {
269
- const { details, spender, sigDeadline } = action.args[1];
268
+ const { details, sigDeadline } = action.args[1];
270
269
  let signature = action.args[2];
271
270
  if (signature != null)
272
271
  return signature; // action is already signed
273
272
  const typedData = getPermit2PermitTypedData({
274
- spender,
273
+ // Never permit any other address than the GeneralAdapter1 otherwise
274
+ // the signature can be used independently.
275
+ spender: generalAdapter1,
275
276
  allowance: details.amount,
276
277
  erc20: details.token,
277
278
  nonce: details.nonce,
@@ -320,11 +321,11 @@ export const encodeOperation = (operation, dataBefore, supportsSignature = true,
320
321
  break;
321
322
  }
322
323
  case "Erc20_Transfer2": {
323
- const { amount, from, to } = operation.args;
324
+ const { amount, to } = operation.args;
324
325
  if (supportsSignature) {
325
326
  actions.push({
326
327
  type: "transferFrom2",
327
- args: [address, from, amount, to, operation.skipRevert],
328
+ args: [address, amount, to, operation.skipRevert],
328
329
  });
329
330
  break;
330
331
  }
@@ -413,7 +414,7 @@ export const encodeOperation = (operation, dataBefore, supportsSignature = true,
413
414
  }
414
415
  case "Blue_Supply": {
415
416
  const { id, assets = 0n, shares = 0n, onBehalf, slippage = DEFAULT_SLIPPAGE_TOLERANCE, } = operation.args;
416
- const market = dataBefore.getMarket(id);
417
+ const market = dataAfter.getMarket(id);
417
418
  const maxSharePrice = market.toSupplyAssets(MathLib.wToRay(MathLib.WAD + slippage));
418
419
  actions.push({
419
420
  type: "morphoSupply",
@@ -431,7 +432,7 @@ export const encodeOperation = (operation, dataBefore, supportsSignature = true,
431
432
  }
432
433
  case "Blue_Withdraw": {
433
434
  const { id, assets = 0n, shares = 0n, receiver, slippage = DEFAULT_SLIPPAGE_TOLERANCE, } = operation.args;
434
- const market = dataBefore.getMarket(id);
435
+ const market = dataAfter.getMarket(id);
435
436
  const minSharePrice = market.toSupplyAssets(MathLib.wToRay(MathLib.WAD - slippage));
436
437
  actions.push({
437
438
  type: "morphoWithdraw",
@@ -448,7 +449,7 @@ export const encodeOperation = (operation, dataBefore, supportsSignature = true,
448
449
  }
449
450
  case "Blue_Borrow": {
450
451
  const { id, assets = 0n, shares = 0n, receiver, slippage = DEFAULT_SLIPPAGE_TOLERANCE, } = operation.args;
451
- const market = dataBefore.getMarket(id);
452
+ const market = dataAfter.getMarket(id);
452
453
  const minSharePrice = market.toBorrowAssets(MathLib.wToRay(MathLib.WAD - slippage));
453
454
  actions.push({
454
455
  type: "morphoBorrow",
@@ -465,7 +466,7 @@ export const encodeOperation = (operation, dataBefore, supportsSignature = true,
465
466
  }
466
467
  case "Blue_Repay": {
467
468
  const { id, assets = 0n, shares = 0n, onBehalf, slippage = DEFAULT_SLIPPAGE_TOLERANCE, } = operation.args;
468
- const market = dataBefore.getMarket(id);
469
+ const market = dataAfter.getMarket(id);
469
470
  const maxSharePrice = market.toBorrowAssets(MathLib.wToRay(MathLib.WAD + slippage));
470
471
  actions.push({
471
472
  type: "morphoRepay",
@@ -522,7 +523,7 @@ export const encodeOperation = (operation, dataBefore, supportsSignature = true,
522
523
  }
523
524
  case "MetaMorpho_Deposit": {
524
525
  const { assets = 0n, shares = 0n, owner, slippage = DEFAULT_SLIPPAGE_TOLERANCE, } = operation.args;
525
- const vault = dataBefore.getVault(address);
526
+ const vault = dataAfter.getVault(address);
526
527
  const maxSharePrice = vault.toAssets(MathLib.wToRay(MathLib.WAD + slippage));
527
528
  if (shares === 0n)
528
529
  actions.push({
@@ -538,7 +539,7 @@ export const encodeOperation = (operation, dataBefore, supportsSignature = true,
538
539
  }
539
540
  case "MetaMorpho_Withdraw": {
540
541
  const { assets = 0n, shares = 0n, owner, receiver, slippage = DEFAULT_SLIPPAGE_TOLERANCE, } = operation.args;
541
- const vault = dataBefore.getVault(address);
542
+ const vault = dataAfter.getVault(address);
542
543
  const minSharePrice = vault.toAssets(MathLib.wToRay(MathLib.WAD - slippage));
543
544
  if (assets > 0n)
544
545
  actions.push({
package/lib/operations.js CHANGED
@@ -8,7 +8,7 @@ import { BundlerErrors } from "./errors.js";
8
8
  */
9
9
  export const DEFAULT_SUPPLY_TARGET_UTILIZATION = 905000000000000000n;
10
10
  export const populateInputTransfer = ({ address, args: { amount, from } }, data, { hasSimplePermit = false } = {}) => {
11
- const { bundler3: { bundler3, generalAdapter1 }, permit2, } = getChainAddresses(data.chainId);
11
+ const { bundler3: { generalAdapter1 }, permit2, } = getChainAddresses(data.chainId);
12
12
  // If native token, it is expected to be sent along as call value.
13
13
  if (address === NATIVE_ADDRESS)
14
14
  return [
@@ -105,7 +105,7 @@ export const populateInputTransfer = ({ address, args: { amount, from } }, data,
105
105
  });
106
106
  operations.push({
107
107
  type: "Erc20_Transfer2",
108
- sender: bundler3,
108
+ sender: generalAdapter1,
109
109
  address,
110
110
  args: {
111
111
  amount,
@@ -19,7 +19,6 @@ export interface Permit2PermitSingleDetails {
19
19
  }
20
20
  export interface Permit2PermitSingle {
21
21
  details: Permit2PermitSingleDetails;
22
- spender: Address;
23
22
  sigDeadline: bigint;
24
23
  }
25
24
  export interface ActionArgs {
@@ -80,7 +79,6 @@ export interface ActionArgs {
80
79
  ];
81
80
  transferFrom2: [
82
81
  asset: Address,
83
- owner: Address,
84
82
  amount: bigint,
85
83
  recipient?: Address,
86
84
  skipRevert?: boolean
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.12",
4
+ "version": "3.0.0-next.14",
5
5
  "author": "Morpho Association <contact@morpho.org>",
6
6
  "contributors": [
7
7
  "Rubilmax <rmilon@gmail.com>"
@@ -21,9 +21,9 @@
21
21
  "peerDependencies": {
22
22
  "viem": "^2.0.0",
23
23
  "@morpho-org/blue-sdk": "^2.3.2",
24
- "@morpho-org/blue-sdk-viem": "^2.2.2",
25
- "@morpho-org/morpho-ts": "^2.2.0",
26
- "@morpho-org/simulation-sdk": "^2.1.4"
24
+ "@morpho-org/blue-sdk-viem": "^3.0.0-next.6",
25
+ "@morpho-org/simulation-sdk": "^2.1.4",
26
+ "@morpho-org/morpho-ts": "^2.2.0"
27
27
  },
28
28
  "devDependencies": {
29
29
  "@tanstack/query-core": "^5.62.16",
@@ -35,13 +35,13 @@
35
35
  "typescript": "^5.7.2",
36
36
  "viem": "^2.23.0",
37
37
  "vitest": "^3.0.5",
38
+ "@morpho-org/blue-sdk-viem": "^3.0.0-next.6",
38
39
  "@morpho-org/blue-sdk": "^2.3.2",
39
- "@morpho-org/blue-sdk-viem": "^2.2.2",
40
- "@morpho-org/morpho-ts": "^2.2.0",
41
40
  "@morpho-org/morpho-test": "^2.2.1",
41
+ "@morpho-org/morpho-ts": "^2.2.0",
42
42
  "@morpho-org/simulation-sdk": "^2.1.4",
43
43
  "@morpho-org/simulation-sdk-wagmi": "^2.0.5",
44
- "@morpho-org/test": "^2.1.0",
44
+ "@morpho-org/test": "^2.1.1",
45
45
  "@morpho-org/test-wagmi": "^2.0.4"
46
46
  },
47
47
  "scripts": {