@morpho-org/bundler-sdk-viem 4.1.4 → 4.3.0

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.
Files changed (48) hide show
  1. package/lib/{actions.js → cjs/actions.js} +3 -0
  2. package/lib/cjs/package.json +1 -0
  3. package/lib/esm/ActionBundle.d.ts +37 -0
  4. package/lib/esm/ActionBundle.js +35 -0
  5. package/lib/esm/BundlerAction.d.ts +470 -0
  6. package/lib/esm/BundlerAction.js +1657 -0
  7. package/lib/esm/abis.d.ts +3014 -0
  8. package/lib/esm/abis.js +2047 -0
  9. package/lib/esm/actions.d.ts +10 -0
  10. package/lib/esm/actions.js +793 -0
  11. package/lib/esm/bundle.d.ts +12 -0
  12. package/lib/esm/bundle.js +11 -0
  13. package/lib/esm/errors.d.ts +30 -0
  14. package/lib/esm/errors.js +54 -0
  15. package/lib/esm/index.d.ts +8 -0
  16. package/lib/esm/index.js +8 -0
  17. package/lib/esm/operations.d.ts +78 -0
  18. package/lib/esm/operations.js +800 -0
  19. package/lib/esm/package.json +1 -0
  20. package/lib/esm/types/actions.d.ts +355 -0
  21. package/lib/esm/types/actions.js +1 -0
  22. package/lib/esm/types/index.d.ts +2 -0
  23. package/lib/esm/types/index.js +2 -0
  24. package/lib/esm/types/operations.d.ts +86 -0
  25. package/lib/esm/types/operations.js +55 -0
  26. package/package.json +25 -16
  27. package/src/index.ts +8 -0
  28. /package/lib/{ActionBundle.d.ts → cjs/ActionBundle.d.ts} +0 -0
  29. /package/lib/{ActionBundle.js → cjs/ActionBundle.js} +0 -0
  30. /package/lib/{BundlerAction.d.ts → cjs/BundlerAction.d.ts} +0 -0
  31. /package/lib/{BundlerAction.js → cjs/BundlerAction.js} +0 -0
  32. /package/lib/{abis.d.ts → cjs/abis.d.ts} +0 -0
  33. /package/lib/{abis.js → cjs/abis.js} +0 -0
  34. /package/lib/{actions.d.ts → cjs/actions.d.ts} +0 -0
  35. /package/lib/{bundle.d.ts → cjs/bundle.d.ts} +0 -0
  36. /package/lib/{bundle.js → cjs/bundle.js} +0 -0
  37. /package/lib/{errors.d.ts → cjs/errors.d.ts} +0 -0
  38. /package/lib/{errors.js → cjs/errors.js} +0 -0
  39. /package/lib/{index.d.ts → cjs/index.d.ts} +0 -0
  40. /package/lib/{index.js → cjs/index.js} +0 -0
  41. /package/lib/{operations.d.ts → cjs/operations.d.ts} +0 -0
  42. /package/lib/{operations.js → cjs/operations.js} +0 -0
  43. /package/lib/{types → cjs/types}/actions.d.ts +0 -0
  44. /package/lib/{types → cjs/types}/actions.js +0 -0
  45. /package/lib/{types → cjs/types}/index.d.ts +0 -0
  46. /package/lib/{types → cjs/types}/index.js +0 -0
  47. /package/lib/{types → cjs/types}/operations.d.ts +0 -0
  48. /package/lib/{types → cjs/types}/operations.js +0 -0
@@ -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
+ };
@@ -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
+ };
@@ -0,0 +1,30 @@
1
+ import type { OperationType, SimulationResult } from "@morpho-org/simulation-sdk";
2
+ import type { Address } from "viem";
3
+ import type { ActionType, InputBundlerOperation } from "./types/index.js";
4
+ export declare namespace BundlerErrors {
5
+ class Bundle extends Error {
6
+ readonly error: Error;
7
+ readonly index: number;
8
+ readonly inputOperation: InputBundlerOperation;
9
+ readonly steps: SimulationResult;
10
+ constructor(error: Error, index: number, inputOperation: InputBundlerOperation, steps: SimulationResult);
11
+ }
12
+ class MissingSignature extends Error {
13
+ constructor();
14
+ }
15
+ class MissingSwapData extends Error {
16
+ constructor();
17
+ }
18
+ class UnexpectedAction extends Error {
19
+ constructor(type: ActionType, chainId: number);
20
+ }
21
+ class UnexpectedSignature extends Error {
22
+ constructor(spender: Address);
23
+ }
24
+ class MissingSkimHandler extends Error {
25
+ constructor(type: OperationType);
26
+ }
27
+ class UnskimedToken extends Error {
28
+ constructor(token: Address);
29
+ }
30
+ }
@@ -0,0 +1,54 @@
1
+ export var BundlerErrors;
2
+ (function (BundlerErrors) {
3
+ class Bundle extends Error {
4
+ error;
5
+ index;
6
+ inputOperation;
7
+ steps;
8
+ constructor(error, index, inputOperation, steps) {
9
+ super(error.message);
10
+ this.error = error;
11
+ this.index = index;
12
+ this.inputOperation = inputOperation;
13
+ this.steps = steps;
14
+ this.stack = error.stack;
15
+ }
16
+ }
17
+ BundlerErrors.Bundle = Bundle;
18
+ class MissingSignature extends Error {
19
+ constructor() {
20
+ super(`missing signature`);
21
+ }
22
+ }
23
+ BundlerErrors.MissingSignature = MissingSignature;
24
+ class MissingSwapData extends Error {
25
+ constructor() {
26
+ super(`missing swap data`);
27
+ }
28
+ }
29
+ BundlerErrors.MissingSwapData = MissingSwapData;
30
+ class UnexpectedAction extends Error {
31
+ constructor(type, chainId) {
32
+ super(`unexpected action "${type}" on chain "${chainId}"`);
33
+ }
34
+ }
35
+ BundlerErrors.UnexpectedAction = UnexpectedAction;
36
+ class UnexpectedSignature extends Error {
37
+ constructor(spender) {
38
+ super(`unexpected signature consumer "${spender}"`);
39
+ }
40
+ }
41
+ BundlerErrors.UnexpectedSignature = UnexpectedSignature;
42
+ class MissingSkimHandler extends Error {
43
+ constructor(type) {
44
+ super(`missing skim handler for operation "${type}"`);
45
+ }
46
+ }
47
+ BundlerErrors.MissingSkimHandler = MissingSkimHandler;
48
+ class UnskimedToken extends Error {
49
+ constructor(token) {
50
+ super(`missing final skim for token "${token}"`);
51
+ }
52
+ }
53
+ BundlerErrors.UnskimedToken = UnskimedToken;
54
+ })(BundlerErrors || (BundlerErrors = {}));
@@ -0,0 +1,8 @@
1
+ export * from "./actions.js";
2
+ export * from "./operations.js";
3
+ export * from "./errors.js";
4
+ export * from "./types/index.js";
5
+ export * from "./BundlerAction.js";
6
+ export * from "./bundle.js";
7
+ export * from "./ActionBundle.js";
8
+ export * from "./abis.js";
@@ -0,0 +1,8 @@
1
+ export * from "./actions.js";
2
+ export * from "./operations.js";
3
+ export * from "./errors.js";
4
+ export * from "./types/index.js";
5
+ export * from "./BundlerAction.js";
6
+ export * from "./bundle.js";
7
+ export * from "./ActionBundle.js";
8
+ export * from "./abis.js";
@@ -0,0 +1,78 @@
1
+ import { type Address, type MarketId } from "@morpho-org/blue-sdk";
2
+ import { type MaybeDraft, type Operation, type Operations, type PublicAllocatorOptions, type SimulationResult, type SimulationState } from "@morpho-org/simulation-sdk";
3
+ import type { BundlerOperation, CallbackBundlerOperation, InputBundlerOperation } from "./types/index.js";
4
+ /**
5
+ * The default target utilization above which the shared liquidity algorithm is triggered (scaled by WAD).
6
+ */
7
+ export declare const DEFAULT_SUPPLY_TARGET_UTILIZATION = 905000000000000000n;
8
+ export interface BundlingOptions {
9
+ withSimplePermit?: Set<Address>;
10
+ publicAllocatorOptions?: PublicAllocatorOptions & {
11
+ /**
12
+ * The target utilization of each market above which the shared liquidity algorithm is triggered (scaled by WAD).
13
+ */
14
+ supplyTargetUtilization?: Record<MarketId, bigint | undefined>;
15
+ /**
16
+ * The default target utilization above which the shared liquidity algorithm is triggered (scaled by WAD).
17
+ * @default 90.5%
18
+ */
19
+ defaultSupplyTargetUtilization?: bigint;
20
+ };
21
+ getRequirementOperations?: (requiredTokenAmounts: {
22
+ token: Address;
23
+ required: bigint;
24
+ }[]) => BundlerOperation[];
25
+ }
26
+ export declare const populateInputTransfer: ({ address, args: { amount, from } }: Operations["Erc20_Transfer"], data: MaybeDraft<SimulationState>, { hasSimplePermit }?: {
27
+ hasSimplePermit?: boolean;
28
+ }) => Exclude<BundlerOperation, CallbackBundlerOperation>[];
29
+ /**
30
+ * Simulates the input operation on the given simulation data with args tweaked so the bundler operates on behalf of the sender.
31
+ * Then, populates a bundle of operations made of:
32
+ * - required approvals to the bundler
33
+ * - required input transfers to the bundler
34
+ * - required token wrapping
35
+ * - the given operation
36
+ * @param inputOperation The input operation to populate a bundle for.
37
+ * @param data The simulation data to determine the required steps of the bundle to populate. If the provided simulation data is the result of a simulation
38
+ * of an already populated bundle, the `Transfer` and `Wrap` operation are only populated if required.
39
+ * @param wrapSlippage The slippage simulated during wraps. Should never be 0.
40
+ * @return The bundle of operations to optimize and skim before being encoded.
41
+ */
42
+ export declare const populateSubBundle: (inputOperation: InputBundlerOperation, data: MaybeDraft<SimulationState>, options?: BundlingOptions) => BundlerOperation[];
43
+ /**
44
+ * Merges unnecessary duplicate `Erc20_Approve`, `Erc20_Transfer` and `Erc20_Wrap`.
45
+ * Also redirects `Blue_Borrow|Withdraw|WithdrawCollateral` & `MetaMorpho_Withdraw` operations from the bundler to the receiver,
46
+ * as long as the tokens received (possibly ERC4626 shares) are not used afterwards in the bundle.
47
+ * For all the other remaining tokens, appends `Erc20_Transfer` operations to the bundle, from the bundler to the receiver.
48
+ * @param operations The bundle to optimize.
49
+ * @param startData The start data from which to simulate th bundle.
50
+ * @param receiver The receiver of skimmed tokens.
51
+ * @param unwrapTokens The set of tokens to unwrap before transferring to the receiver.
52
+ * @param unwrapSlippage The slippage simulated during unwraps. Should never be 0.
53
+ * @return The optimized bundle.
54
+ */
55
+ export declare const finalizeBundle: (operations: BundlerOperation[], startData: SimulationState, receiver: Address, unwrapTokens?: Set<`0x${string}`>, unwrapSlippage?: bigint) => BundlerOperation[];
56
+ export declare const populateBundle: (inputOperations: InputBundlerOperation[], data: MaybeDraft<SimulationState>, options?: BundlingOptions) => {
57
+ operations: BundlerOperation[];
58
+ steps: SimulationResult;
59
+ };
60
+ export declare const simulateRequiredTokenAmounts: (operations: Operation[], data: MaybeDraft<SimulationState>) => {
61
+ token: `0x${string}`;
62
+ required: bigint;
63
+ }[];
64
+ export declare const getSimulatedBundlerOperation: (operation: Omit<BundlerOperation, "sender">, { slippage }?: {
65
+ slippage?: bigint;
66
+ }) => Operation;
67
+ export declare const handleBundlerOperation: (options?: {
68
+ slippage?: bigint;
69
+ }) => (operation: BundlerOperation, startData: MaybeDraft<SimulationState>, index?: number) => MaybeDraft<SimulationState>;
70
+ export declare const handleBundlerOperations: (operations: BundlerOperation[], startData: MaybeDraft<SimulationState>, options?: {
71
+ slippage?: bigint;
72
+ }) => SimulationResult;
73
+ export declare const simulateBundlerOperation: (options?: {
74
+ slippage?: bigint;
75
+ }) => (operation: BundlerOperation, startData: MaybeDraft<SimulationState>, index?: number) => MaybeDraft<SimulationState>;
76
+ export declare const simulateBundlerOperations: (operations: BundlerOperation[], startData: MaybeDraft<SimulationState>, options?: {
77
+ slippage?: bigint;
78
+ }) => SimulationResult;