@morpho-org/bundler-sdk-viem 3.0.0-next.3 → 3.0.0-next.4

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.
@@ -0,0 +1,35 @@
1
+ import type { SimulationResult } from "@morpho-org/simulation-sdk";
2
+ import type { Account, Address, Chain, Client, Hex, Transport } from "viem";
3
+ import type { Action, SignatureRequirement, TransactionRequirement } from "./types/index.js";
4
+ export declare class ActionBundleRequirements<TR extends {
5
+ tx: {
6
+ to: Address;
7
+ data: Hex;
8
+ };
9
+ } = TransactionRequirement, SR extends SignatureRequirement = SignatureRequirement> {
10
+ readonly txs: TR[];
11
+ readonly signatures: SR[];
12
+ constructor(txs?: TR[], signatures?: SR[]);
13
+ sign(client: Client<Transport, Chain | undefined, Account>): Promise<Hex[]>;
14
+ sign(client: Client, account: Account): Promise<Hex[]>;
15
+ }
16
+ export declare class ActionBundle<TR extends {
17
+ tx: {
18
+ to: Address;
19
+ data: Hex;
20
+ };
21
+ } = TransactionRequirement, SR extends SignatureRequirement = SignatureRequirement> {
22
+ readonly steps: SimulationResult;
23
+ readonly actions: Action[];
24
+ readonly requirements: ActionBundleRequirements<TR, SR>;
25
+ constructor(steps: SimulationResult, actions?: Action[], requirements?: ActionBundleRequirements<TR, SR>);
26
+ tx(): {
27
+ to: `0x${string}`;
28
+ value: bigint;
29
+ data: `0x${string}`;
30
+ };
31
+ txs(): {
32
+ to: Address;
33
+ data: Hex;
34
+ }[];
35
+ }
@@ -0,0 +1,28 @@
1
+ import { BundlerAction } from "./BundlerAction.js";
2
+ export class ActionBundleRequirements {
3
+ txs;
4
+ signatures;
5
+ constructor(txs = [], signatures = []) {
6
+ this.txs = txs;
7
+ this.signatures = signatures;
8
+ }
9
+ sign(client, account = client.account) {
10
+ return Promise.all(this.signatures.map((requirement) => requirement.sign(client, account)));
11
+ }
12
+ }
13
+ export class ActionBundle {
14
+ steps;
15
+ actions;
16
+ requirements;
17
+ constructor(steps, actions = [], requirements = new ActionBundleRequirements()) {
18
+ this.steps = steps;
19
+ this.actions = actions;
20
+ this.requirements = requirements;
21
+ }
22
+ tx() {
23
+ return BundlerAction.encodeBundle(this.steps[0].chainId, this.actions);
24
+ }
25
+ txs() {
26
+ return this.requirements.txs.map(({ tx }) => tx).concat([this.tx()]);
27
+ }
28
+ }
@@ -9,7 +9,7 @@ export interface BundlerCall {
9
9
  callbackHash: Hex;
10
10
  }
11
11
  /**
12
- * Namespace to easily encode calls to the Bundler contract, using ethers.
12
+ * Namespace to easily encode calls to the Bundler contract, using viem.
13
13
  */
14
14
  export declare namespace BundlerAction {
15
15
  function encodeBundle(chainId: ChainId, actions: Action[]): {
@@ -388,4 +388,3 @@ export declare namespace BundlerAction {
388
388
  */
389
389
  function compoundV3AllowBySig(chainId: ChainId, instance: Address, owner: Address, isAllowed: boolean, nonce: bigint, expiry: bigint, signature: Hex, manager?: Address, skipRevert?: boolean): BundlerCall[];
390
390
  }
391
- export default BundlerAction;
@@ -5,7 +5,7 @@ import { encodeAbiParameters, encodeFunctionData, keccak256, maxUint256, parseSi
5
5
  import { BundlerErrors } from "./errors.js";
6
6
  const reenterSelectorHash = keccak256(toFunctionSelector(bundler3Abi.find((item) => item.type === "function" && item.name === "reenter")));
7
7
  /**
8
- * Namespace to easily encode calls to the Bundler contract, using ethers.
8
+ * Namespace to easily encode calls to the Bundler contract, using viem.
9
9
  */
10
10
  export var BundlerAction;
11
11
  (function (BundlerAction) {
@@ -1465,4 +1465,3 @@ export var BundlerAction;
1465
1465
  }
1466
1466
  BundlerAction.compoundV3AllowBySig = compoundV3AllowBySig;
1467
1467
  })(BundlerAction || (BundlerAction = {}));
1468
- export default BundlerAction;
package/lib/actions.d.ts CHANGED
@@ -1,14 +1,12 @@
1
1
  import { type Address } from "viem";
2
2
  import { type MaybeDraft, type SimulationState } from "@morpho-org/simulation-sdk";
3
- import type { Action, ActionBundle, BundlerOperation, TransactionRequirement } from "./types/index.js";
3
+ import { ActionBundle, ActionBundleRequirements } from "./ActionBundle.js";
4
+ import type { Action, BundlerOperation, TransactionRequirement } from "./types/index.js";
4
5
  export declare const APPROVE_ONLY_ONCE_TOKENS: Partial<Record<number, Address[]>>;
5
6
  export declare const MAX_TOKEN_APPROVALS: Partial<Record<number, Record<Address, bigint>>>;
6
7
  export declare const encodeOperation: (operation: BundlerOperation, dataBefore: MaybeDraft<SimulationState>, supportsSignature?: boolean, index?: number) => {
7
8
  dataAfter: MaybeDraft<SimulationState>;
8
9
  actions: Action[];
9
- requirements: {
10
- signatures: import("./types/actions.js").SignatureRequirement[];
11
- txs: TransactionRequirement[];
12
- };
10
+ requirements: ActionBundleRequirements<TransactionRequirement, import("./types/actions.js").SignatureRequirement>;
13
11
  };
14
- export declare function encodeBundle(operations: BundlerOperation[], startData: MaybeDraft<SimulationState>, supportsSignature?: boolean): ActionBundle;
12
+ export declare function encodeBundle(operations: BundlerOperation[], startData: MaybeDraft<SimulationState>, supportsSignature?: boolean): ActionBundle<TransactionRequirement, import("./types/actions.js").SignatureRequirement>;
package/lib/actions.js CHANGED
@@ -4,7 +4,7 @@ import { Time, getValue } from "@morpho-org/morpho-ts";
4
4
  import { simulateOperation, } from "@morpho-org/simulation-sdk";
5
5
  import { blueAbi, getAuthorizationTypedData, getDaiPermitTypedData, getPermit2PermitTypedData, getPermitTypedData, } from "@morpho-org/blue-sdk-viem";
6
6
  import { signTypedData } from "viem/actions";
7
- import BundlerAction from "./BundlerAction.js";
7
+ import { ActionBundle, ActionBundleRequirements } from "./ActionBundle.js";
8
8
  export const APPROVE_ONLY_ONCE_TOKENS = {
9
9
  [ChainId.EthMainnet]: [
10
10
  "0xdAC17F958D2ee523a2206206994597C13D831ec7", // USDT
@@ -67,10 +67,7 @@ export const encodeOperation = (operation, dataBefore, supportsSignature = true,
67
67
  const deadline = Time.timestamp() + Time.s.from.h(24n);
68
68
  const { morpho, bundler3: { bundler3, generalAdapter1 }, permit2, wNative, dai, wstEth, stEth, } = getChainAddresses(chainId);
69
69
  const actions = [];
70
- const requirements = {
71
- signatures: [],
72
- txs: [],
73
- };
70
+ const requirements = new ActionBundleRequirements();
74
71
  let callbackBundle;
75
72
  const callback = getValue(operation.args, "callback");
76
73
  const simulatedOperation = {
@@ -531,24 +528,13 @@ export const encodeOperation = (operation, dataBefore, supportsSignature = true,
531
528
  };
532
529
  };
533
530
  export function encodeBundle(operations, startData, supportsSignature = true) {
534
- const { chainId } = startData;
535
- const actions = [];
536
- const requirements = {
537
- signatures: [],
538
- txs: [],
539
- };
540
- const steps = [startData];
531
+ const bundle = new ActionBundle([startData]);
541
532
  for (let index = 0; index < operations.length; ++index) {
542
- const bundle = encodeOperation(operations[index], steps[index], supportsSignature, index);
543
- steps.push(bundle.dataAfter);
544
- actions.push(...bundle.actions);
545
- requirements.signatures.push(...bundle.requirements.signatures);
546
- requirements.txs.push(...bundle.requirements.txs);
533
+ const { dataAfter, actions, requirements } = encodeOperation(operations[index], bundle.steps[index], supportsSignature, index);
534
+ bundle.steps.push(dataAfter);
535
+ bundle.actions.push(...actions);
536
+ bundle.requirements.signatures.push(...requirements.signatures);
537
+ bundle.requirements.txs.push(...requirements.txs);
547
538
  }
548
- return {
549
- steps,
550
- actions,
551
- requirements,
552
- tx: () => BundlerAction.encodeBundle(chainId, actions),
553
- };
539
+ return bundle;
554
540
  }
@@ -0,0 +1,12 @@
1
+ import type { SimulationState } from "@morpho-org/simulation-sdk";
2
+ import type { Address } from "viem";
3
+ import { type BundlingOptions } from "./operations.js";
4
+ import type { InputBundlerOperation } from "./types/index.js";
5
+ export declare const setupBundle: (inputOperations: InputBundlerOperation[], startData: SimulationState, receiver: Address, { supportsSignature, unwrapTokens, unwrapSlippage, ...options }?: BundlingOptions & {
6
+ supportsSignature?: boolean;
7
+ unwrapTokens?: Set<Address>;
8
+ unwrapSlippage?: bigint;
9
+ }) => {
10
+ operations: import("./types/operations.js").BundlerOperation[];
11
+ bundle: import("./ActionBundle.js").ActionBundle<import("./types/actions.js").TransactionRequirement, import("./types/actions.js").SignatureRequirement>;
12
+ };
package/lib/bundle.js ADDED
@@ -0,0 +1,11 @@
1
+ import { encodeBundle } from "./actions.js";
2
+ import { finalizeBundle, populateBundle, } from "./operations.js";
3
+ export const setupBundle = (inputOperations, startData, receiver, { supportsSignature, unwrapTokens, unwrapSlippage, ...options } = {}) => {
4
+ let { operations } = populateBundle(inputOperations, startData, options);
5
+ operations = finalizeBundle(operations, startData, receiver, unwrapTokens, unwrapSlippage);
6
+ const bundle = encodeBundle(operations, startData, supportsSignature);
7
+ return {
8
+ operations,
9
+ bundle,
10
+ };
11
+ };
package/lib/index.d.ts CHANGED
@@ -3,3 +3,5 @@ export * from "./operations.js";
3
3
  export * from "./errors.js";
4
4
  export * from "./types/index.js";
5
5
  export * from "./BundlerAction.js";
6
+ export * from "./bundle.js";
7
+ export * from "./ActionBundle.js";
package/lib/index.js CHANGED
@@ -3,3 +3,5 @@ export * from "./operations.js";
3
3
  export * from "./errors.js";
4
4
  export * from "./types/index.js";
5
5
  export * from "./BundlerAction.js";
6
+ export * from "./bundle.js";
7
+ export * from "./ActionBundle.js";
@@ -1,6 +1,5 @@
1
1
  import type { Account, Chain, Client, Hex, TransactionRequest, Transport } from "viem";
2
2
  import type { Address, InputMarketParams } from "@morpho-org/blue-sdk";
3
- import type { SimulationResult } from "@morpho-org/simulation-sdk";
4
3
  export interface Authorization {
5
4
  authorizer: Address;
6
5
  authorized: Address;
@@ -267,15 +266,3 @@ export interface SignatureRequirement {
267
266
  action: Action;
268
267
  sign: SignatureRequirementFunction;
269
268
  }
270
- export interface ActionBundle {
271
- steps: SimulationResult;
272
- actions: Action[];
273
- requirements: {
274
- signatures: SignatureRequirement[];
275
- txs: TransactionRequirement[];
276
- };
277
- tx: () => TransactionRequest & {
278
- to: Address;
279
- data: Hex;
280
- };
281
- }
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.3",
4
+ "version": "3.0.0-next.4",
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": "^3.0.0-next.5",
24
- "@morpho-org/blue-sdk-viem": "^3.0.0-next.2",
25
- "@morpho-org/simulation-sdk": "^3.0.0-next.2",
26
- "@morpho-org/morpho-ts": "^2.2.0-next.0"
23
+ "@morpho-org/blue-sdk": "^2.3.1",
24
+ "@morpho-org/blue-sdk-viem": "^2.2.2",
25
+ "@morpho-org/morpho-ts": "^2.1.0",
26
+ "@morpho-org/simulation-sdk": "^2.1.3"
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.5",
39
- "@morpho-org/blue-sdk-viem": "^3.0.0-next.2",
40
- "@morpho-org/morpho-test": "^2.3.0-next.0",
41
- "@morpho-org/simulation-sdk": "^3.0.0-next.2",
42
- "@morpho-org/morpho-ts": "^2.2.0-next.0",
38
+ "@morpho-org/morpho-ts": "^2.1.0",
39
+ "@morpho-org/blue-sdk": "^2.3.1",
40
+ "@morpho-org/blue-sdk-viem": "^2.2.2",
41
+ "@morpho-org/morpho-test": "^2.2.1",
42
+ "@morpho-org/simulation-sdk": "^2.1.3",
43
+ "@morpho-org/simulation-sdk-wagmi": "^2.0.5",
43
44
  "@morpho-org/test": "^2.0.6",
44
- "@morpho-org/test-wagmi": "^2.0.4",
45
- "@morpho-org/simulation-sdk-wagmi": "^3.0.0-next.1"
45
+ "@morpho-org/test-wagmi": "^2.0.4"
46
46
  },
47
47
  "scripts": {
48
48
  "prepublish": "$npm_execpath build",