@morpho-org/morpho-sdk 3.1.1 → 4.0.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 (103) hide show
  1. package/README.md +63 -13
  2. package/lib/cjs/actions/{marketV1 → blue}/borrow.d.ts +8 -8
  3. package/lib/cjs/actions/{marketV1 → blue}/borrow.js +8 -8
  4. package/lib/{esm/actions/marketV1 → cjs/actions/blue}/buildReallocationActions.d.ts +1 -1
  5. package/lib/cjs/actions/{marketV1 → blue}/buildReallocationActions.js +1 -1
  6. package/lib/cjs/actions/{marketV1 → blue}/index.d.ts +1 -0
  7. package/lib/cjs/actions/{marketV1 → blue}/index.js +1 -0
  8. package/lib/cjs/actions/blue/refinance.d.ts +117 -0
  9. package/lib/cjs/actions/blue/refinance.js +218 -0
  10. package/lib/{esm/actions/marketV1 → cjs/actions/blue}/repay.d.ts +8 -8
  11. package/lib/cjs/actions/{marketV1 → blue}/repay.js +8 -8
  12. package/lib/{esm/actions/marketV1 → cjs/actions/blue}/repayWithdrawCollateral.d.ts +8 -8
  13. package/lib/cjs/actions/{marketV1 → blue}/repayWithdrawCollateral.js +8 -8
  14. package/lib/{esm/actions/marketV1 → cjs/actions/blue}/supply.d.ts +8 -8
  15. package/lib/cjs/actions/{marketV1 → blue}/supply.js +8 -8
  16. package/lib/cjs/actions/{marketV1 → blue}/supplyCollateral.d.ts +8 -8
  17. package/lib/cjs/actions/{marketV1 → blue}/supplyCollateral.js +8 -8
  18. package/lib/{esm/actions/marketV1 → cjs/actions/blue}/supplyCollateralBorrow.d.ts +8 -8
  19. package/lib/cjs/actions/{marketV1 → blue}/supplyCollateralBorrow.js +8 -8
  20. package/lib/{esm/actions/marketV1 → cjs/actions/blue}/withdraw.d.ts +11 -11
  21. package/lib/cjs/actions/{marketV1 → blue}/withdraw.js +10 -10
  22. package/lib/{esm/actions/marketV1 → cjs/actions/blue}/withdrawCollateral.d.ts +8 -8
  23. package/lib/cjs/actions/{marketV1 → blue}/withdrawCollateral.js +8 -8
  24. package/lib/cjs/actions/index.d.ts +2 -2
  25. package/lib/cjs/actions/index.js +1 -1
  26. package/lib/cjs/actions/requirements/getMorphoAuthorizationRequirement.d.ts +1 -1
  27. package/lib/cjs/actions/requirements/getMorphoAuthorizationRequirement.js +1 -1
  28. package/lib/cjs/client/index.d.ts +0 -1
  29. package/lib/cjs/client/index.js +0 -1
  30. package/lib/cjs/client/morphoViemExtension.d.ts +17 -11
  31. package/lib/cjs/client/morphoViemExtension.js +55 -10
  32. package/lib/cjs/entities/{marketV1/marketV1.d.ts → blue/blue.d.ts} +76 -21
  33. package/lib/cjs/entities/{marketV1/marketV1.js → blue/blue.js} +169 -11
  34. package/lib/cjs/entities/blue/index.d.ts +1 -0
  35. package/lib/cjs/entities/{marketV1 → blue}/index.js +1 -1
  36. package/lib/cjs/entities/index.d.ts +1 -1
  37. package/lib/cjs/entities/index.js +3 -3
  38. package/lib/cjs/entities/reallocationData.d.ts +1 -1
  39. package/lib/cjs/entities/reallocationData.js +1 -1
  40. package/lib/cjs/entities/vaultV2/vaultV2.js +1 -1
  41. package/lib/cjs/helpers/computeReallocations.d.ts +1 -1
  42. package/lib/cjs/helpers/computeReallocations.js +1 -1
  43. package/lib/cjs/helpers/validate.d.ts +2 -2
  44. package/lib/cjs/helpers/validate.js +2 -2
  45. package/lib/cjs/types/action.d.ts +21 -9
  46. package/lib/cjs/types/client.d.ts +5 -4
  47. package/lib/cjs/types/error.d.ts +57 -0
  48. package/lib/cjs/types/error.js +82 -1
  49. package/lib/esm/actions/{marketV1 → blue}/borrow.d.ts +8 -8
  50. package/lib/esm/actions/{marketV1 → blue}/borrow.js +6 -6
  51. package/lib/{cjs/actions/marketV1 → esm/actions/blue}/buildReallocationActions.d.ts +1 -1
  52. package/lib/esm/actions/{marketV1 → blue}/buildReallocationActions.js +1 -1
  53. package/lib/esm/actions/{marketV1 → blue}/index.d.ts +1 -0
  54. package/lib/esm/actions/{marketV1 → blue}/index.js +1 -0
  55. package/lib/esm/actions/blue/refinance.d.ts +117 -0
  56. package/lib/esm/actions/blue/refinance.js +214 -0
  57. package/lib/{cjs/actions/marketV1 → esm/actions/blue}/repay.d.ts +8 -8
  58. package/lib/esm/actions/{marketV1 → blue}/repay.js +6 -6
  59. package/lib/{cjs/actions/marketV1 → esm/actions/blue}/repayWithdrawCollateral.d.ts +8 -8
  60. package/lib/esm/actions/{marketV1 → blue}/repayWithdrawCollateral.js +6 -6
  61. package/lib/{cjs/actions/marketV1 → esm/actions/blue}/supply.d.ts +8 -8
  62. package/lib/esm/actions/{marketV1 → blue}/supply.js +6 -6
  63. package/lib/esm/actions/{marketV1 → blue}/supplyCollateral.d.ts +8 -8
  64. package/lib/esm/actions/{marketV1 → blue}/supplyCollateral.js +6 -6
  65. package/lib/{cjs/actions/marketV1 → esm/actions/blue}/supplyCollateralBorrow.d.ts +8 -8
  66. package/lib/esm/actions/{marketV1 → blue}/supplyCollateralBorrow.js +6 -6
  67. package/lib/{cjs/actions/marketV1 → esm/actions/blue}/withdraw.d.ts +11 -11
  68. package/lib/esm/actions/{marketV1 → blue}/withdraw.js +8 -8
  69. package/lib/{cjs/actions/marketV1 → esm/actions/blue}/withdrawCollateral.d.ts +8 -8
  70. package/lib/esm/actions/{marketV1 → blue}/withdrawCollateral.js +6 -6
  71. package/lib/esm/actions/index.d.ts +2 -2
  72. package/lib/esm/actions/index.js +1 -1
  73. package/lib/esm/actions/requirements/getMorphoAuthorizationRequirement.d.ts +1 -1
  74. package/lib/esm/actions/requirements/getMorphoAuthorizationRequirement.js +1 -1
  75. package/lib/esm/client/index.d.ts +0 -1
  76. package/lib/esm/client/index.js +0 -1
  77. package/lib/esm/client/morphoViemExtension.d.ts +17 -11
  78. package/lib/esm/client/morphoViemExtension.js +55 -10
  79. package/lib/esm/entities/{marketV1/marketV1.d.ts → blue/blue.d.ts} +76 -21
  80. package/lib/esm/entities/{marketV1/marketV1.js → blue/blue.js} +170 -12
  81. package/lib/esm/entities/blue/index.d.ts +1 -0
  82. package/lib/esm/entities/blue/index.js +1 -0
  83. package/lib/esm/entities/index.d.ts +1 -1
  84. package/lib/esm/entities/index.js +1 -1
  85. package/lib/esm/entities/reallocationData.d.ts +1 -1
  86. package/lib/esm/entities/reallocationData.js +1 -1
  87. package/lib/esm/entities/vaultV2/vaultV2.js +1 -1
  88. package/lib/esm/helpers/computeReallocations.d.ts +1 -1
  89. package/lib/esm/helpers/computeReallocations.js +1 -1
  90. package/lib/esm/helpers/validate.d.ts +2 -2
  91. package/lib/esm/helpers/validate.js +2 -2
  92. package/lib/esm/types/action.d.ts +21 -9
  93. package/lib/esm/types/client.d.ts +5 -4
  94. package/lib/esm/types/error.d.ts +57 -0
  95. package/lib/esm/types/error.js +72 -0
  96. package/package.json +6 -6
  97. package/lib/cjs/client/morphoClient.d.ts +0 -152
  98. package/lib/cjs/client/morphoClient.js +0 -162
  99. package/lib/cjs/entities/marketV1/index.d.ts +0 -1
  100. package/lib/esm/client/morphoClient.d.ts +0 -152
  101. package/lib/esm/client/morphoClient.js +0 -158
  102. package/lib/esm/entities/marketV1/index.d.ts +0 -1
  103. package/lib/esm/entities/marketV1/index.js +0 -1
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.marketV1WithdrawCollateral = void 0;
3
+ exports.blueWithdrawCollateral = void 0;
4
4
  const blue_sdk_1 = require("@morpho-org/blue-sdk");
5
5
  const blue_sdk_viem_1 = require("@morpho-org/blue-sdk-viem");
6
6
  const morpho_ts_1 = require("@morpho-org/morpho-ts");
@@ -21,14 +21,14 @@ const index_js_2 = require("../../types/index.js");
21
21
  * @param params.args.onBehalf - Address whose Morpho position the collateral is withdrawn from.
22
22
  * @param params.args.receiver - Address that receives the withdrawn collateral.
23
23
  * @param params.metadata - Optional analytics metadata attached to the transaction.
24
- * @returns A deep-frozen `Transaction<MarketV1WithdrawCollateralAction>` with `to`, `value`,
24
+ * @returns A deep-frozen `Transaction<BlueWithdrawCollateralAction>` with `to`, `value`,
25
25
  * `data`, and the typed `action` discriminator the simulation layer consumes.
26
26
  * @throws {NonPositiveWithdrawCollateralAmountError} when `amount <= 0n`.
27
27
  * @example
28
28
  * ```ts
29
- * import { marketV1WithdrawCollateral } from "@morpho-org/morpho-sdk";
29
+ * import { blueWithdrawCollateral } from "@morpho-org/morpho-sdk";
30
30
  *
31
- * const tx = marketV1WithdrawCollateral({
31
+ * const tx = blueWithdrawCollateral({
32
32
  * market: { chainId: 1, marketParams },
33
33
  * args: {
34
34
  * amount: 1_000_000_000_000_000_000n,
@@ -36,10 +36,10 @@ const index_js_2 = require("../../types/index.js");
36
36
  * receiver: borrower,
37
37
  * },
38
38
  * });
39
- * // tx satisfies Readonly<Transaction<MarketV1WithdrawCollateralAction>>
39
+ * // tx satisfies Readonly<Transaction<BlueWithdrawCollateralAction>>
40
40
  * ```
41
41
  */
42
- const marketV1WithdrawCollateral = ({ market: { chainId, marketParams }, args: { amount, onBehalf, receiver }, metadata, }) => {
42
+ const blueWithdrawCollateral = ({ market: { chainId, marketParams }, args: { amount, onBehalf, receiver }, metadata, }) => {
43
43
  if (amount <= 0n) {
44
44
  throw new index_js_2.NonPositiveWithdrawCollateralAmountError(marketParams.id);
45
45
  }
@@ -59,7 +59,7 @@ const marketV1WithdrawCollateral = ({ market: { chainId, marketParams }, args: {
59
59
  return (0, morpho_ts_1.deepFreeze)({
60
60
  ...tx,
61
61
  action: {
62
- type: "marketV1WithdrawCollateral",
62
+ type: "blueWithdrawCollateral",
63
63
  args: {
64
64
  market: marketParams.id,
65
65
  amount,
@@ -69,4 +69,4 @@ const marketV1WithdrawCollateral = ({ market: { chainId, marketParams }, args: {
69
69
  },
70
70
  });
71
71
  };
72
- exports.marketV1WithdrawCollateral = marketV1WithdrawCollateral;
72
+ exports.blueWithdrawCollateral = blueWithdrawCollateral;
@@ -1,7 +1,7 @@
1
- export type { MarketV1Actions } from "../entities/marketV1/index.js";
1
+ export type { BlueActions } from "../entities/blue/index.js";
2
2
  export type { VaultV1Actions } from "../entities/vaultV1/index.js";
3
3
  export type { VaultV2Actions } from "../entities/vaultV2/index.js";
4
- export * from "./marketV1/index.js";
4
+ export * from "./blue/index.js";
5
5
  export * from "./requirements/index.js";
6
6
  export * from "./vaultV1/index.js";
7
7
  export * from "./vaultV2/index.js";
@@ -14,7 +14,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
14
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
- __exportStar(require("./marketV1/index.js"), exports);
17
+ __exportStar(require("./blue/index.js"), exports);
18
18
  __exportStar(require("./requirements/index.js"), exports);
19
19
  __exportStar(require("./vaultV1/index.js"), exports);
20
20
  __exportStar(require("./vaultV2/index.js"), exports);
@@ -6,7 +6,7 @@ import { type MorphoAuthorizationAction, type Transaction } from "../../types/in
6
6
  * the `setAuthorization(generalAdapter1, true)` transaction when it does.
7
7
  *
8
8
  * Reads `Morpho.isAuthorized(userAddress, generalAdapter1)` on the target chain. Required before
9
- * any bundled MarketV1 path that operates on behalf of the user (`borrow`,
9
+ * any bundled Blue path that operates on behalf of the user (`borrow`,
10
10
  * `supplyCollateralBorrow`, `repayWithdrawCollateral`).
11
11
  *
12
12
  * @param params.viemClient - Connected viem `Client` whose `chain.id` matches `params.chainId`.
@@ -11,7 +11,7 @@ const index_js_1 = require("../../types/index.js");
11
11
  * the `setAuthorization(generalAdapter1, true)` transaction when it does.
12
12
  *
13
13
  * Reads `Morpho.isAuthorized(userAddress, generalAdapter1)` on the target chain. Required before
14
- * any bundled MarketV1 path that operates on behalf of the user (`borrow`,
14
+ * any bundled Blue path that operates on behalf of the user (`borrow`,
15
15
  * `supplyCollateralBorrow`, `repayWithdrawCollateral`).
16
16
  *
17
17
  * @param params.viemClient - Connected viem `Client` whose `chain.id` matches `params.chainId`.
@@ -1,2 +1 @@
1
- export * from "./morphoClient.js";
2
1
  export * from "./morphoViemExtension.js";
@@ -14,5 +14,4 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
14
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
- __exportStar(require("./morphoClient.js"), exports);
18
17
  __exportStar(require("./morphoViemExtension.js"), exports);
@@ -1,22 +1,24 @@
1
1
  import type { Client } from "viem";
2
- import type { Metadata } from "../types/index.js";
3
- import { MorphoClient } from "./morphoClient.js";
2
+ import { type Metadata, type MorphoClientType } from "../types/index.js";
4
3
  /**
5
- * Returns a viem `extend(...)` function that adds a `morpho` namespace to a viem client. The
6
- * namespace exposes a `MorphoClient` instance built from the same client and the supplied
7
- * options.
4
+ * Returns a viem `extend(...)` function that adds a stateless `morpho` namespace to a viem client.
5
+ * The namespace rides on top of the same client (one transport / chain / account) and exposes the
6
+ * protocol entity factories under `client.morpho`, so reads and writes share one client.
8
7
  *
9
- * @param _options - Optional SDK-wide options forwarded to the inner `MorphoClient`.
8
+ * Holds no state beyond configuration: no cache, no `init()`, no warm-up. Each factory call
9
+ * (`client.morpho.vaultV1`, `vaultV2`, `blue`) returns a fresh entity bound to the client.
10
+ *
11
+ * @param _options - Optional SDK-wide options forwarded to the `morpho` namespace.
10
12
  * @param _options.metadata - Optional analytics metadata applied to every transaction the
11
- * resulting `MorphoClient` builds.
13
+ * `morpho` namespace builds.
12
14
  * @param _options.supportSignature - Whether the integrator can collect EIP-712 signatures for
13
- * permit / permit2.
15
+ * permit / permit2. Defaults to `false` (classic approvals only).
14
16
  * @param _options.supportDeployless - Whether entity fetchers may use deployless multicall.
15
17
  * @returns A viem extension function — `client.extend(morphoViemExtension(...))` adds
16
18
  * `client.morpho`.
17
19
  * @example
18
20
  * ```ts
19
- * import { createWalletClient, http } from "viem";
21
+ * import { createWalletClient, http, publicActions } from "viem";
20
22
  * import { mainnet } from "viem/chains";
21
23
  * import { morphoViemExtension } from "@morpho-org/morpho-sdk";
22
24
  *
@@ -24,8 +26,12 @@ import { MorphoClient } from "./morphoClient.js";
24
26
  * chain: mainnet,
25
27
  * transport: http(),
26
28
  * account: user,
27
- * }).extend(morphoViemExtension({ supportSignature: true }));
29
+ * })
30
+ * .extend(publicActions)
31
+ * .extend(morphoViemExtension({ supportSignature: true }));
28
32
  *
33
+ * // Native viem reads and Morpho factories share the same client:
34
+ * const block = await client.getBlockNumber();
29
35
  * const vault = client.morpho.vaultV1(vaultAddress, 1);
30
36
  * const vaultData = await vault.getData();
31
37
  * const { buildTx } = vault.deposit({
@@ -41,5 +47,5 @@ export declare function morphoViemExtension(_options?: {
41
47
  readonly supportSignature?: boolean;
42
48
  readonly supportDeployless?: boolean;
43
49
  }): <TClient extends Client>(client: TClient) => {
44
- morpho: MorphoClient;
50
+ morpho: MorphoClientType;
45
51
  };
@@ -1,23 +1,64 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.morphoViemExtension = morphoViemExtension;
4
- const morphoClient_js_1 = require("./morphoClient.js");
4
+ const blue_sdk_1 = require("@morpho-org/blue-sdk");
5
+ const morpho_ts_1 = require("@morpho-org/morpho-ts");
6
+ const index_js_1 = require("../entities/index.js");
7
+ const index_js_2 = require("../types/index.js");
5
8
  /**
6
- * Returns a viem `extend(...)` function that adds a `morpho` namespace to a viem client. The
7
- * namespace exposes a `MorphoClient` instance built from the same client and the supplied
8
- * options.
9
+ * Builds the stateless `morpho` namespace exposed on an extended viem client. Wraps the supplied
10
+ * viem `Client` plus a frozen options bag and exposes factory methods for the protocol entities.
9
11
  *
10
- * @param _options - Optional SDK-wide options forwarded to the inner `MorphoClient`.
12
+ * Holds no state beyond configuration: no cache, no `init()`, no warm-up. Each factory call
13
+ * (`vaultV1`, `vaultV2`, `blue`) returns a fresh entity bound to this client.
14
+ *
15
+ * @internal
16
+ */
17
+ function createMorphoNamespace(viemClient, options) {
18
+ const namespace = {
19
+ viemClient,
20
+ options: (0, morpho_ts_1.deepFreeze)({
21
+ ...options,
22
+ metadata: options?.metadata === undefined ? undefined : { ...options.metadata },
23
+ supportSignature: options?.supportSignature ?? false,
24
+ supportDeployless: options?.supportDeployless,
25
+ }),
26
+ vaultV1(vault, chainId) {
27
+ return new index_js_1.MorphoVaultV1(namespace, vault, chainId);
28
+ },
29
+ vaultV2(vault, chainId) {
30
+ return new index_js_1.MorphoVaultV2(namespace, vault, chainId);
31
+ },
32
+ blue(marketParams, chainId) {
33
+ const derivedId = blue_sdk_1.MarketUtils.getMarketId(marketParams);
34
+ // Can happen with one-time/hardcoded/agent-written possibly inconsistent input market params.
35
+ if (marketParams.id !== derivedId) {
36
+ throw new index_js_2.MarketIdMismatchError(marketParams.id, derivedId);
37
+ }
38
+ return new index_js_1.MorphoBlue(namespace, marketParams, chainId);
39
+ },
40
+ };
41
+ return namespace;
42
+ }
43
+ /**
44
+ * Returns a viem `extend(...)` function that adds a stateless `morpho` namespace to a viem client.
45
+ * The namespace rides on top of the same client (one transport / chain / account) and exposes the
46
+ * protocol entity factories under `client.morpho`, so reads and writes share one client.
47
+ *
48
+ * Holds no state beyond configuration: no cache, no `init()`, no warm-up. Each factory call
49
+ * (`client.morpho.vaultV1`, `vaultV2`, `blue`) returns a fresh entity bound to the client.
50
+ *
51
+ * @param _options - Optional SDK-wide options forwarded to the `morpho` namespace.
11
52
  * @param _options.metadata - Optional analytics metadata applied to every transaction the
12
- * resulting `MorphoClient` builds.
53
+ * `morpho` namespace builds.
13
54
  * @param _options.supportSignature - Whether the integrator can collect EIP-712 signatures for
14
- * permit / permit2.
55
+ * permit / permit2. Defaults to `false` (classic approvals only).
15
56
  * @param _options.supportDeployless - Whether entity fetchers may use deployless multicall.
16
57
  * @returns A viem extension function — `client.extend(morphoViemExtension(...))` adds
17
58
  * `client.morpho`.
18
59
  * @example
19
60
  * ```ts
20
- * import { createWalletClient, http } from "viem";
61
+ * import { createWalletClient, http, publicActions } from "viem";
21
62
  * import { mainnet } from "viem/chains";
22
63
  * import { morphoViemExtension } from "@morpho-org/morpho-sdk";
23
64
  *
@@ -25,8 +66,12 @@ const morphoClient_js_1 = require("./morphoClient.js");
25
66
  * chain: mainnet,
26
67
  * transport: http(),
27
68
  * account: user,
28
- * }).extend(morphoViemExtension({ supportSignature: true }));
69
+ * })
70
+ * .extend(publicActions)
71
+ * .extend(morphoViemExtension({ supportSignature: true }));
29
72
  *
73
+ * // Native viem reads and Morpho factories share the same client:
74
+ * const block = await client.getBlockNumber();
30
75
  * const vault = client.morpho.vaultV1(vaultAddress, 1);
31
76
  * const vaultData = await vault.getData();
32
77
  * const { buildTx } = vault.deposit({
@@ -40,7 +85,7 @@ const morphoClient_js_1 = require("./morphoClient.js");
40
85
  function morphoViemExtension(_options) {
41
86
  return (client) => {
42
87
  return {
43
- morpho: new morphoClient_js_1.MorphoClient(client, _options),
88
+ morpho: createMorphoNamespace(client, _options),
44
89
  };
45
90
  };
46
91
  }
@@ -1,9 +1,9 @@
1
- import { type AccrualPosition, type Market, type MarketParams } from "@morpho-org/blue-sdk";
2
- import type { Address } from "viem";
1
+ import { AccrualPosition, type Market, type MarketParams } from "@morpho-org/blue-sdk";
2
+ import { type Address } from "viem";
3
3
  import type { FetchParameters } from "../../types/data.js";
4
- import { type AssetsOrSharesArgs, type DepositAmountArgs, type ERC20ApprovalAction, type MarketV1BorrowAction, type MarketV1RepayAction, type MarketV1RepayWithdrawCollateralAction, type MarketV1SupplyAction, type MarketV1SupplyCollateralAction, type MarketV1SupplyCollateralBorrowAction, type MarketV1WithdrawAction, type MarketV1WithdrawCollateralAction, type MorphoAuthorizationAction, type MorphoClientType, type ReallocationComputeOptions, type RepayAmountArgs, type Requirement, type RequirementSignature, type Transaction, type VaultReallocation } from "../../types/index.js";
4
+ import { type AssetsOrSharesArgs, type BlueBorrowAction, type BlueRefinanceAction, type BlueRepayAction, type BlueRepayWithdrawCollateralAction, type BlueSupplyAction, type BlueSupplyCollateralAction, type BlueSupplyCollateralBorrowAction, type BlueWithdrawAction, type BlueWithdrawCollateralAction, type DepositAmountArgs, type ERC20ApprovalAction, type MorphoAuthorizationAction, type MorphoClientType, type ReallocationComputeOptions, type RepayAmountArgs, type Requirement, type RequirementSignature, type Transaction, type VaultReallocation } from "../../types/index.js";
5
5
  import { ReallocationData } from "../reallocationData.js";
6
- export interface MarketV1Actions {
6
+ export interface BlueActions {
7
7
  /**
8
8
  * Fetches the latest market data with accrued interest.
9
9
  *
@@ -32,7 +32,7 @@ export interface MarketV1Actions {
32
32
  supplyCollateral: (params: {
33
33
  userAddress: Address;
34
34
  } & DepositAmountArgs) => {
35
- buildTx: (requirementSignature?: RequirementSignature) => Readonly<Transaction<MarketV1SupplyCollateralAction>>;
35
+ buildTx: (requirementSignature?: RequirementSignature) => Readonly<Transaction<BlueSupplyCollateralAction>>;
36
36
  getRequirements: (params?: {
37
37
  useSimplePermit?: boolean;
38
38
  }) => Promise<(Readonly<Transaction<ERC20ApprovalAction>> | Requirement)[]>;
@@ -55,7 +55,7 @@ export interface MarketV1Actions {
55
55
  marketData: Market;
56
56
  slippageTolerance?: bigint;
57
57
  } & DepositAmountArgs) => {
58
- buildTx: (requirementSignature?: RequirementSignature) => Readonly<Transaction<MarketV1SupplyAction>>;
58
+ buildTx: (requirementSignature?: RequirementSignature) => Readonly<Transaction<BlueSupplyAction>>;
59
59
  getRequirements: (params?: {
60
60
  useSimplePermit?: boolean;
61
61
  }) => Promise<(Readonly<Transaction<ERC20ApprovalAction>> | Requirement)[]>;
@@ -89,7 +89,7 @@ export interface MarketV1Actions {
89
89
  slippageTolerance?: bigint;
90
90
  reallocations?: readonly VaultReallocation[];
91
91
  } & AssetsOrSharesArgs) => {
92
- buildTx: () => Readonly<Transaction<MarketV1WithdrawAction>>;
92
+ buildTx: () => Readonly<Transaction<BlueWithdrawAction>>;
93
93
  getRequirements: () => Promise<Readonly<Transaction<MorphoAuthorizationAction>>[]>;
94
94
  };
95
95
  /**
@@ -117,7 +117,7 @@ export interface MarketV1Actions {
117
117
  slippageTolerance?: bigint;
118
118
  reallocations?: readonly VaultReallocation[];
119
119
  }) => {
120
- buildTx: () => Readonly<Transaction<MarketV1BorrowAction>>;
120
+ buildTx: () => Readonly<Transaction<BlueBorrowAction>>;
121
121
  getRequirements: () => Promise<Readonly<Transaction<MorphoAuthorizationAction>>[]>;
122
122
  };
123
123
  /**
@@ -143,7 +143,7 @@ export interface MarketV1Actions {
143
143
  positionData: AccrualPosition;
144
144
  slippageTolerance?: bigint;
145
145
  } & RepayAmountArgs) => {
146
- buildTx: (requirementSignature?: RequirementSignature) => Readonly<Transaction<MarketV1RepayAction>>;
146
+ buildTx: (requirementSignature?: RequirementSignature) => Readonly<Transaction<BlueRepayAction>>;
147
147
  getRequirements: (params?: {
148
148
  useSimplePermit?: boolean;
149
149
  }) => Promise<(Readonly<Transaction<ERC20ApprovalAction>> | Requirement)[]>;
@@ -168,7 +168,7 @@ export interface MarketV1Actions {
168
168
  amount: bigint;
169
169
  positionData: AccrualPosition;
170
170
  }) => {
171
- buildTx: () => Readonly<Transaction<MarketV1WithdrawCollateralAction>>;
171
+ buildTx: () => Readonly<Transaction<BlueWithdrawCollateralAction>>;
172
172
  };
173
173
  /**
174
174
  * Prepares an atomic repay-and-withdraw-collateral transaction.
@@ -192,7 +192,7 @@ export interface MarketV1Actions {
192
192
  positionData: AccrualPosition;
193
193
  slippageTolerance?: bigint;
194
194
  } & RepayAmountArgs) => {
195
- buildTx: (requirementSignature?: RequirementSignature) => Readonly<Transaction<MarketV1RepayWithdrawCollateralAction>>;
195
+ buildTx: (requirementSignature?: RequirementSignature) => Readonly<Transaction<BlueRepayWithdrawCollateralAction>>;
196
196
  getRequirements: (params?: {
197
197
  useSimplePermit?: boolean;
198
198
  }) => Promise<(Readonly<Transaction<ERC20ApprovalAction>> | Readonly<Transaction<MorphoAuthorizationAction>> | Requirement)[]>;
@@ -222,11 +222,50 @@ export interface MarketV1Actions {
222
222
  slippageTolerance?: bigint;
223
223
  reallocations?: readonly VaultReallocation[];
224
224
  } & DepositAmountArgs) => {
225
- buildTx: (requirementSignature?: RequirementSignature) => Readonly<Transaction<MarketV1SupplyCollateralBorrowAction>>;
225
+ buildTx: (requirementSignature?: RequirementSignature) => Readonly<Transaction<BlueSupplyCollateralBorrowAction>>;
226
226
  getRequirements: (params?: {
227
227
  useSimplePermit?: boolean;
228
228
  }) => Promise<(Readonly<Transaction<ERC20ApprovalAction>> | Readonly<Transaction<MorphoAuthorizationAction>> | Requirement)[]>;
229
229
  };
230
+ /**
231
+ * Prepares an atomic refinance migrating this market's position to another Morpho Blue market
232
+ * that shares the same loan and collateral tokens. See {@link blueRefinance} for the bundle.
233
+ *
234
+ * Validates ownership, token/id match, that amounts do not exceed the source position, and that
235
+ * both the residual source and the aggregate target position stay within LLTV − buffer. Both
236
+ * markets are forward-accrued to `now`; in shares mode the target borrow is overshot by
237
+ * `slippageTolerance` and the callback sweeps the residual.
238
+ *
239
+ * `getRequirements` returns `morpho.setAuthorization(generalAdapter1, true)` when GA1 is not yet
240
+ * authorized (a single global authorization covers both markets).
241
+ *
242
+ * @param params.userAddress - Position owner on both markets.
243
+ * @param params.positionData - Pre-fetched source-market accrual position.
244
+ * @param params.target.marketParams - Target market params.
245
+ * @param params.target.positionData - Pre-fetched target-market accrual position (zero-position if none).
246
+ * @param params.collateralAmount - Amount of collateral to migrate from source to target.
247
+ * @param params.borrowAssets - Loan assets to repay on source; exclusive with `borrowShares`.
248
+ * @param params.borrowShares - Borrow shares to repay on source; exclusive with `borrowAssets`.
249
+ * @param params.slippageTolerance - WAD slippage tolerance. Defaults to `DEFAULT_SLIPPAGE_TOLERANCE`.
250
+ * @param params.targetReallocations - PublicAllocator reallocations into the target market.
251
+ * @returns Object with `buildTx` and `getRequirements`.
252
+ */
253
+ refinance: (params: {
254
+ userAddress: Address;
255
+ positionData: AccrualPosition;
256
+ target: {
257
+ marketParams: MarketParams;
258
+ positionData: AccrualPosition;
259
+ };
260
+ collateralAmount: bigint;
261
+ borrowAssets?: bigint;
262
+ borrowShares?: bigint;
263
+ slippageTolerance?: bigint;
264
+ targetReallocations?: readonly VaultReallocation[];
265
+ }) => {
266
+ buildTx: () => Readonly<Transaction<BlueRefinanceAction>>;
267
+ getRequirements: () => Promise<Readonly<Transaction<MorphoAuthorizationAction>>[]>;
268
+ };
230
269
  /**
231
270
  * Fetches all on-chain data needed to construct a {@link ReallocationData}
232
271
  * for computing vault reallocations via the public allocator.
@@ -294,7 +333,7 @@ export interface MarketV1Actions {
294
333
  amount?: never;
295
334
  })) => readonly VaultReallocation[];
296
335
  }
297
- export declare class MorphoMarketV1 implements MarketV1Actions {
336
+ export declare class MorphoBlue implements BlueActions {
298
337
  private readonly client;
299
338
  readonly marketParams: MarketParams;
300
339
  private readonly chainId;
@@ -309,7 +348,7 @@ export declare class MorphoMarketV1 implements MarketV1Actions {
309
348
  getRequirements: (params?: {
310
349
  useSimplePermit?: boolean;
311
350
  }) => Promise<(Requirement | Readonly<Transaction<ERC20ApprovalAction>>)[]>;
312
- buildTx: (requirementSignature?: RequirementSignature) => Readonly<Transaction<MarketV1SupplyAction>>;
351
+ buildTx: (requirementSignature?: RequirementSignature) => Readonly<Transaction<BlueSupplyAction>>;
313
352
  };
314
353
  withdraw(params: {
315
354
  userAddress: Address;
@@ -319,7 +358,7 @@ export declare class MorphoMarketV1 implements MarketV1Actions {
319
358
  reallocations?: readonly VaultReallocation[];
320
359
  } & AssetsOrSharesArgs): {
321
360
  getRequirements: () => Promise<Readonly<Transaction<MorphoAuthorizationAction>>[]>;
322
- buildTx: () => Readonly<Transaction<MarketV1WithdrawAction>>;
361
+ buildTx: () => Readonly<Transaction<BlueWithdrawAction>>;
323
362
  };
324
363
  supplyCollateral({ amount, userAddress, nativeAmount, }: {
325
364
  userAddress: Address;
@@ -327,7 +366,7 @@ export declare class MorphoMarketV1 implements MarketV1Actions {
327
366
  getRequirements: (params?: {
328
367
  useSimplePermit?: boolean;
329
368
  }) => Promise<(Requirement | Readonly<Transaction<ERC20ApprovalAction>>)[]>;
330
- buildTx: (requirementSignature?: RequirementSignature) => Readonly<Transaction<MarketV1SupplyCollateralAction>>;
369
+ buildTx: (requirementSignature?: RequirementSignature) => Readonly<Transaction<BlueSupplyCollateralAction>>;
331
370
  };
332
371
  borrow({ amount, userAddress, positionData, slippageTolerance, reallocations, }: {
333
372
  amount: bigint;
@@ -337,7 +376,7 @@ export declare class MorphoMarketV1 implements MarketV1Actions {
337
376
  reallocations?: readonly VaultReallocation[];
338
377
  }): {
339
378
  getRequirements: () => Promise<Readonly<Transaction<MorphoAuthorizationAction>>[]>;
340
- buildTx: () => Readonly<Transaction<MarketV1BorrowAction>>;
379
+ buildTx: () => Readonly<Transaction<BlueBorrowAction>>;
341
380
  };
342
381
  repay(params: {
343
382
  userAddress: Address;
@@ -347,14 +386,14 @@ export declare class MorphoMarketV1 implements MarketV1Actions {
347
386
  getRequirements: (reqParams?: {
348
387
  useSimplePermit?: boolean;
349
388
  }) => Promise<(Requirement | Readonly<Transaction<ERC20ApprovalAction>>)[]>;
350
- buildTx: (requirementSignature?: RequirementSignature) => Readonly<Transaction<MarketV1RepayAction>>;
389
+ buildTx: (requirementSignature?: RequirementSignature) => Readonly<Transaction<BlueRepayAction>>;
351
390
  };
352
391
  withdrawCollateral({ userAddress, amount, positionData, }: {
353
392
  userAddress: Address;
354
393
  amount: bigint;
355
394
  positionData: AccrualPosition;
356
395
  }): {
357
- buildTx: () => Readonly<Transaction<MarketV1WithdrawCollateralAction>>;
396
+ buildTx: () => Readonly<Transaction<BlueWithdrawCollateralAction>>;
358
397
  };
359
398
  repayWithdrawCollateral(params: {
360
399
  userAddress: Address;
@@ -365,7 +404,7 @@ export declare class MorphoMarketV1 implements MarketV1Actions {
365
404
  getRequirements: (reqParams?: {
366
405
  useSimplePermit?: boolean;
367
406
  }) => Promise<(Requirement | Readonly<Transaction<ERC20ApprovalAction>> | Readonly<Transaction<MorphoAuthorizationAction>>)[]>;
368
- buildTx: (requirementSignature?: RequirementSignature) => Readonly<Transaction<MarketV1RepayWithdrawCollateralAction>>;
407
+ buildTx: (requirementSignature?: RequirementSignature) => Readonly<Transaction<BlueRepayWithdrawCollateralAction>>;
369
408
  };
370
409
  supplyCollateralBorrow({ amount, userAddress, positionData, borrowAmount, nativeAmount, slippageTolerance, reallocations, }: {
371
410
  userAddress: Address;
@@ -377,7 +416,23 @@ export declare class MorphoMarketV1 implements MarketV1Actions {
377
416
  getRequirements: (params?: {
378
417
  useSimplePermit?: boolean;
379
418
  }) => Promise<(Requirement | Readonly<Transaction<ERC20ApprovalAction>> | Readonly<Transaction<MorphoAuthorizationAction>>)[]>;
380
- buildTx: (requirementSignature?: RequirementSignature) => Readonly<Transaction<MarketV1SupplyCollateralBorrowAction>>;
419
+ buildTx: (requirementSignature?: RequirementSignature) => Readonly<Transaction<BlueSupplyCollateralBorrowAction>>;
420
+ };
421
+ refinance({ userAddress, positionData, target, collateralAmount, borrowAssets, borrowShares, slippageTolerance, targetReallocations, }: {
422
+ userAddress: Address;
423
+ positionData: AccrualPosition;
424
+ target: {
425
+ marketParams: MarketParams;
426
+ positionData: AccrualPosition;
427
+ };
428
+ collateralAmount: bigint;
429
+ borrowAssets?: bigint;
430
+ borrowShares?: bigint;
431
+ slippageTolerance?: bigint;
432
+ targetReallocations?: readonly VaultReallocation[];
433
+ }): {
434
+ getRequirements: () => Promise<Readonly<Transaction<MorphoAuthorizationAction>>[]>;
435
+ buildTx: () => Readonly<Transaction<BlueRefinanceAction>>;
381
436
  };
382
437
  /**
383
438
  * Fetches all on-chain inputs needed to compute public allocator reallocations.