@morpho-org/morpho-sdk 3.2.0 → 4.1.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 +19 -16
  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/{esm/actions/marketV1 → cjs/actions/blue}/refinance.d.ts +8 -8
  7. package/lib/cjs/actions/{marketV1 → blue}/refinance.js +8 -8
  8. package/lib/{esm/actions/marketV1 → cjs/actions/blue}/repay.d.ts +8 -8
  9. package/lib/cjs/actions/{marketV1 → blue}/repay.js +8 -8
  10. package/lib/{esm/actions/marketV1 → cjs/actions/blue}/repayWithdrawCollateral.d.ts +8 -8
  11. package/lib/cjs/actions/{marketV1 → blue}/repayWithdrawCollateral.js +8 -8
  12. package/lib/cjs/actions/{marketV1 → blue}/supply.d.ts +8 -8
  13. package/lib/cjs/actions/{marketV1 → blue}/supply.js +8 -8
  14. package/lib/cjs/actions/{marketV1 → blue}/supplyCollateral.d.ts +8 -8
  15. package/lib/cjs/actions/{marketV1 → blue}/supplyCollateral.js +8 -8
  16. package/lib/{esm/actions/marketV1 → cjs/actions/blue}/supplyCollateralBorrow.d.ts +8 -8
  17. package/lib/cjs/actions/{marketV1 → blue}/supplyCollateralBorrow.js +8 -8
  18. package/lib/{esm/actions/marketV1 → cjs/actions/blue}/withdraw.d.ts +11 -11
  19. package/lib/cjs/actions/{marketV1 → blue}/withdraw.js +10 -10
  20. package/lib/{esm/actions/marketV1 → cjs/actions/blue}/withdrawCollateral.d.ts +8 -8
  21. package/lib/cjs/actions/{marketV1 → blue}/withdrawCollateral.js +8 -8
  22. package/lib/cjs/actions/index.d.ts +2 -2
  23. package/lib/cjs/actions/index.js +1 -1
  24. package/lib/cjs/actions/requirements/getMorphoAuthorizationRequirement.d.ts +1 -1
  25. package/lib/cjs/actions/requirements/getMorphoAuthorizationRequirement.js +1 -1
  26. package/lib/cjs/client/index.d.ts +0 -1
  27. package/lib/cjs/client/index.js +0 -1
  28. package/lib/cjs/client/morphoViemExtension.d.ts +17 -11
  29. package/lib/cjs/client/morphoViemExtension.js +55 -10
  30. package/lib/cjs/entities/{marketV1/marketV1.d.ts → blue/blue.d.ts} +22 -22
  31. package/lib/cjs/entities/{marketV1/marketV1.js → blue/blue.js} +12 -12
  32. package/lib/cjs/entities/blue/index.d.ts +1 -0
  33. package/lib/cjs/entities/{marketV1 → blue}/index.js +1 -1
  34. package/lib/cjs/entities/index.d.ts +1 -1
  35. package/lib/cjs/entities/index.js +3 -3
  36. package/lib/cjs/entities/reallocationData.d.ts +96 -2
  37. package/lib/cjs/entities/reallocationData.js +112 -1
  38. package/lib/cjs/entities/vaultV2/vaultV2.js +1 -1
  39. package/lib/cjs/helpers/computeReallocations.d.ts +1 -1
  40. package/lib/cjs/helpers/computeReallocations.js +3 -5
  41. package/lib/cjs/helpers/utilization.d.ts +12 -0
  42. package/lib/cjs/helpers/utilization.js +17 -0
  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 +10 -10
  46. package/lib/cjs/types/client.d.ts +5 -4
  47. package/lib/esm/actions/{marketV1 → blue}/borrow.d.ts +8 -8
  48. package/lib/esm/actions/{marketV1 → blue}/borrow.js +6 -6
  49. package/lib/{cjs/actions/marketV1 → esm/actions/blue}/buildReallocationActions.d.ts +1 -1
  50. package/lib/esm/actions/{marketV1 → blue}/buildReallocationActions.js +1 -1
  51. package/lib/{cjs/actions/marketV1 → esm/actions/blue}/refinance.d.ts +8 -8
  52. package/lib/esm/actions/{marketV1 → blue}/refinance.js +6 -6
  53. package/lib/{cjs/actions/marketV1 → esm/actions/blue}/repay.d.ts +8 -8
  54. package/lib/esm/actions/{marketV1 → blue}/repay.js +6 -6
  55. package/lib/{cjs/actions/marketV1 → esm/actions/blue}/repayWithdrawCollateral.d.ts +8 -8
  56. package/lib/esm/actions/{marketV1 → blue}/repayWithdrawCollateral.js +6 -6
  57. package/lib/esm/actions/{marketV1 → blue}/supply.d.ts +8 -8
  58. package/lib/esm/actions/{marketV1 → blue}/supply.js +6 -6
  59. package/lib/esm/actions/{marketV1 → blue}/supplyCollateral.d.ts +8 -8
  60. package/lib/esm/actions/{marketV1 → blue}/supplyCollateral.js +6 -6
  61. package/lib/{cjs/actions/marketV1 → esm/actions/blue}/supplyCollateralBorrow.d.ts +8 -8
  62. package/lib/esm/actions/{marketV1 → blue}/supplyCollateralBorrow.js +6 -6
  63. package/lib/{cjs/actions/marketV1 → esm/actions/blue}/withdraw.d.ts +11 -11
  64. package/lib/esm/actions/{marketV1 → blue}/withdraw.js +8 -8
  65. package/lib/{cjs/actions/marketV1 → esm/actions/blue}/withdrawCollateral.d.ts +8 -8
  66. package/lib/esm/actions/{marketV1 → blue}/withdrawCollateral.js +6 -6
  67. package/lib/esm/actions/index.d.ts +2 -2
  68. package/lib/esm/actions/index.js +1 -1
  69. package/lib/esm/actions/requirements/getMorphoAuthorizationRequirement.d.ts +1 -1
  70. package/lib/esm/actions/requirements/getMorphoAuthorizationRequirement.js +1 -1
  71. package/lib/esm/client/index.d.ts +0 -1
  72. package/lib/esm/client/index.js +0 -1
  73. package/lib/esm/client/morphoViemExtension.d.ts +17 -11
  74. package/lib/esm/client/morphoViemExtension.js +55 -10
  75. package/lib/esm/entities/{marketV1/marketV1.d.ts → blue/blue.d.ts} +22 -22
  76. package/lib/esm/entities/{marketV1/marketV1.js → blue/blue.js} +11 -11
  77. package/lib/esm/entities/blue/index.d.ts +1 -0
  78. package/lib/esm/entities/blue/index.js +1 -0
  79. package/lib/esm/entities/index.d.ts +1 -1
  80. package/lib/esm/entities/index.js +1 -1
  81. package/lib/esm/entities/reallocationData.d.ts +96 -2
  82. package/lib/esm/entities/reallocationData.js +114 -3
  83. package/lib/esm/entities/vaultV2/vaultV2.js +1 -1
  84. package/lib/esm/helpers/computeReallocations.d.ts +1 -1
  85. package/lib/esm/helpers/computeReallocations.js +3 -5
  86. package/lib/esm/helpers/utilization.d.ts +12 -0
  87. package/lib/esm/helpers/utilization.js +13 -0
  88. package/lib/esm/helpers/validate.d.ts +2 -2
  89. package/lib/esm/helpers/validate.js +2 -2
  90. package/lib/esm/types/action.d.ts +10 -10
  91. package/lib/esm/types/client.d.ts +5 -4
  92. package/package.json +5 -5
  93. package/lib/cjs/client/morphoClient.d.ts +0 -152
  94. package/lib/cjs/client/morphoClient.js +0 -162
  95. package/lib/cjs/entities/marketV1/index.d.ts +0 -1
  96. package/lib/esm/client/morphoClient.d.ts +0 -152
  97. package/lib/esm/client/morphoClient.js +0 -158
  98. package/lib/esm/entities/marketV1/index.d.ts +0 -1
  99. package/lib/esm/entities/marketV1/index.js +0 -1
  100. /package/lib/cjs/actions/{marketV1 → blue}/index.d.ts +0 -0
  101. /package/lib/cjs/actions/{marketV1 → blue}/index.js +0 -0
  102. /package/lib/esm/actions/{marketV1 → blue}/index.d.ts +0 -0
  103. /package/lib/esm/actions/{marketV1 → blue}/index.js +0 -0
@@ -1,8 +1,8 @@
1
1
  import { type MarketParams } from "@morpho-org/blue-sdk";
2
2
  import type { Address } from "viem";
3
- import { type DepositAmountArgs, type MarketV1SupplyCollateralAction, type Metadata, type RequirementSignature, type Transaction } from "../../types/index.js";
4
- /** Parameters for {@link marketV1SupplyCollateral}. */
5
- export interface MarketV1SupplyCollateralParams {
3
+ import { type BlueSupplyCollateralAction, type DepositAmountArgs, type Metadata, type RequirementSignature, type Transaction } from "../../types/index.js";
4
+ /** Parameters for {@link blueSupplyCollateral}. */
5
+ export interface BlueSupplyCollateralParams {
6
6
  market: {
7
7
  readonly chainId: number;
8
8
  readonly marketParams: MarketParams;
@@ -33,7 +33,7 @@ export interface MarketV1SupplyCollateralParams {
33
33
  * @param params.args.nativeAmount - Optional amount of native token to wrap into wNative for the
34
34
  * supply. Requires the collateral token to be the chain's wNative.
35
35
  * @param params.metadata - Optional analytics metadata attached to the bundle.
36
- * @returns A deep-frozen `Transaction<MarketV1SupplyCollateralAction>` with `to`, `value`, `data`,
36
+ * @returns A deep-frozen `Transaction<BlueSupplyCollateralAction>` with `to`, `value`, `data`,
37
37
  * and the typed `action` discriminator the simulation layer consumes.
38
38
  * @throws {NonPositiveAssetAmountError} when `amount < 0n`.
39
39
  * @throws {NegativeNativeAmountError} when `nativeAmount < 0n`.
@@ -49,13 +49,13 @@ export interface MarketV1SupplyCollateralParams {
49
49
  * signature is missing its expiration.
50
50
  * @example
51
51
  * ```ts
52
- * import { marketV1SupplyCollateral } from "@morpho-org/morpho-sdk";
52
+ * import { blueSupplyCollateral } from "@morpho-org/morpho-sdk";
53
53
  *
54
- * const tx = marketV1SupplyCollateral({
54
+ * const tx = blueSupplyCollateral({
55
55
  * market: { chainId: 1, marketParams },
56
56
  * args: { amount: 1_000_000_000_000_000_000n, onBehalf },
57
57
  * });
58
- * // tx satisfies Readonly<Transaction<MarketV1SupplyCollateralAction>>
58
+ * // tx satisfies Readonly<Transaction<BlueSupplyCollateralAction>>
59
59
  * ```
60
60
  */
61
- export declare const marketV1SupplyCollateral: ({ market: { chainId, marketParams }, args: { amount, onBehalf, requirementSignature, nativeAmount }, metadata, }: MarketV1SupplyCollateralParams) => Readonly<Transaction<MarketV1SupplyCollateralAction>>;
61
+ export declare const blueSupplyCollateral: ({ market: { chainId, marketParams }, args: { amount, onBehalf, requirementSignature, nativeAmount }, metadata, }: BlueSupplyCollateralParams) => Readonly<Transaction<BlueSupplyCollateralAction>>;
@@ -24,7 +24,7 @@ import { getRequirementsAction } from "../requirements/getRequirementsAction.js"
24
24
  * @param params.args.nativeAmount - Optional amount of native token to wrap into wNative for the
25
25
  * supply. Requires the collateral token to be the chain's wNative.
26
26
  * @param params.metadata - Optional analytics metadata attached to the bundle.
27
- * @returns A deep-frozen `Transaction<MarketV1SupplyCollateralAction>` with `to`, `value`, `data`,
27
+ * @returns A deep-frozen `Transaction<BlueSupplyCollateralAction>` with `to`, `value`, `data`,
28
28
  * and the typed `action` discriminator the simulation layer consumes.
29
29
  * @throws {NonPositiveAssetAmountError} when `amount < 0n`.
30
30
  * @throws {NegativeNativeAmountError} when `nativeAmount < 0n`.
@@ -40,16 +40,16 @@ import { getRequirementsAction } from "../requirements/getRequirementsAction.js"
40
40
  * signature is missing its expiration.
41
41
  * @example
42
42
  * ```ts
43
- * import { marketV1SupplyCollateral } from "@morpho-org/morpho-sdk";
43
+ * import { blueSupplyCollateral } from "@morpho-org/morpho-sdk";
44
44
  *
45
- * const tx = marketV1SupplyCollateral({
45
+ * const tx = blueSupplyCollateral({
46
46
  * market: { chainId: 1, marketParams },
47
47
  * args: { amount: 1_000_000_000_000_000_000n, onBehalf },
48
48
  * });
49
- * // tx satisfies Readonly<Transaction<MarketV1SupplyCollateralAction>>
49
+ * // tx satisfies Readonly<Transaction<BlueSupplyCollateralAction>>
50
50
  * ```
51
51
  */
52
- export const marketV1SupplyCollateral = ({ market: { chainId, marketParams }, args: { amount = 0n, onBehalf, requirementSignature, nativeAmount }, metadata, }) => {
52
+ export const blueSupplyCollateral = ({ market: { chainId, marketParams }, args: { amount = 0n, onBehalf, requirementSignature, nativeAmount }, metadata, }) => {
53
53
  if (amount < 0n) {
54
54
  throw new NonPositiveAssetAmountError(marketParams.collateralToken);
55
55
  }
@@ -99,7 +99,7 @@ export const marketV1SupplyCollateral = ({ market: { chainId, marketParams }, ar
99
99
  return deepFreeze({
100
100
  ...tx,
101
101
  action: {
102
- type: "marketV1SupplyCollateral",
102
+ type: "blueSupplyCollateral",
103
103
  args: {
104
104
  market: marketParams.id,
105
105
  amount: totalCollateral,
@@ -1,8 +1,8 @@
1
1
  import { type MarketParams } from "@morpho-org/blue-sdk";
2
2
  import type { Address } from "viem";
3
- import { type DepositAmountArgs, type MarketV1SupplyCollateralBorrowAction, type Metadata, type RequirementSignature, type Transaction, type VaultReallocation } from "../../types/index.js";
4
- /** Parameters for {@link marketV1SupplyCollateralBorrow}. */
5
- export interface MarketV1SupplyCollateralBorrowParams {
3
+ import { type BlueSupplyCollateralBorrowAction, type DepositAmountArgs, type Metadata, type RequirementSignature, type Transaction, type VaultReallocation } from "../../types/index.js";
4
+ /** Parameters for {@link blueSupplyCollateralBorrow}. */
5
+ export interface BlueSupplyCollateralBorrowParams {
6
6
  market: {
7
7
  readonly chainId: number;
8
8
  readonly marketParams: MarketParams;
@@ -47,7 +47,7 @@ export interface MarketV1SupplyCollateralBorrowParams {
47
47
  * @param params.args.reallocations - Optional vault reallocations to execute between the supply
48
48
  * and borrow legs, computed by the entity layer.
49
49
  * @param params.metadata - Optional analytics metadata attached to the bundle.
50
- * @returns A deep-frozen `Transaction<MarketV1SupplyCollateralBorrowAction>` with `to`, `value`,
50
+ * @returns A deep-frozen `Transaction<BlueSupplyCollateralBorrowAction>` with `to`, `value`,
51
51
  * `data`, and the typed `action` discriminator the simulation layer consumes.
52
52
  * @throws {NonPositiveAssetAmountError} when `amount < 0n`.
53
53
  * @throws {NegativeNativeAmountError} when `nativeAmount < 0n`.
@@ -75,9 +75,9 @@ export interface MarketV1SupplyCollateralBorrowParams {
75
75
  * reallocation withdrawals are not strictly sorted by market id.
76
76
  * @example
77
77
  * ```ts
78
- * import { marketV1SupplyCollateralBorrow } from "@morpho-org/morpho-sdk";
78
+ * import { blueSupplyCollateralBorrow } from "@morpho-org/morpho-sdk";
79
79
  *
80
- * const tx = marketV1SupplyCollateralBorrow({
80
+ * const tx = blueSupplyCollateralBorrow({
81
81
  * market: { chainId: 1, marketParams },
82
82
  * args: {
83
83
  * amount: 1_000_000_000_000_000_000n,
@@ -87,7 +87,7 @@ export interface MarketV1SupplyCollateralBorrowParams {
87
87
  * minSharePrice: 0n, // disables slippage protection — production code should compute via `computeMinBorrowSharePrice` from market state + slippage tolerance
88
88
  * },
89
89
  * });
90
- * // tx satisfies Readonly<Transaction<MarketV1SupplyCollateralBorrowAction>>
90
+ * // tx satisfies Readonly<Transaction<BlueSupplyCollateralBorrowAction>>
91
91
  * ```
92
92
  */
93
- export declare const marketV1SupplyCollateralBorrow: ({ market: { chainId, marketParams }, args: { amount, borrowAmount, onBehalf, receiver, minSharePrice, requirementSignature, nativeAmount, reallocations, }, metadata, }: MarketV1SupplyCollateralBorrowParams) => Readonly<Transaction<MarketV1SupplyCollateralBorrowAction>>;
93
+ export declare const blueSupplyCollateralBorrow: ({ market: { chainId, marketParams }, args: { amount, borrowAmount, onBehalf, receiver, minSharePrice, requirementSignature, nativeAmount, reallocations, }, metadata, }: BlueSupplyCollateralBorrowParams) => Readonly<Transaction<BlueSupplyCollateralBorrowAction>>;
@@ -33,7 +33,7 @@ import { buildReallocationActions } from "./buildReallocationActions.js";
33
33
  * @param params.args.reallocations - Optional vault reallocations to execute between the supply
34
34
  * and borrow legs, computed by the entity layer.
35
35
  * @param params.metadata - Optional analytics metadata attached to the bundle.
36
- * @returns A deep-frozen `Transaction<MarketV1SupplyCollateralBorrowAction>` with `to`, `value`,
36
+ * @returns A deep-frozen `Transaction<BlueSupplyCollateralBorrowAction>` with `to`, `value`,
37
37
  * `data`, and the typed `action` discriminator the simulation layer consumes.
38
38
  * @throws {NonPositiveAssetAmountError} when `amount < 0n`.
39
39
  * @throws {NegativeNativeAmountError} when `nativeAmount < 0n`.
@@ -61,9 +61,9 @@ import { buildReallocationActions } from "./buildReallocationActions.js";
61
61
  * reallocation withdrawals are not strictly sorted by market id.
62
62
  * @example
63
63
  * ```ts
64
- * import { marketV1SupplyCollateralBorrow } from "@morpho-org/morpho-sdk";
64
+ * import { blueSupplyCollateralBorrow } from "@morpho-org/morpho-sdk";
65
65
  *
66
- * const tx = marketV1SupplyCollateralBorrow({
66
+ * const tx = blueSupplyCollateralBorrow({
67
67
  * market: { chainId: 1, marketParams },
68
68
  * args: {
69
69
  * amount: 1_000_000_000_000_000_000n,
@@ -73,10 +73,10 @@ import { buildReallocationActions } from "./buildReallocationActions.js";
73
73
  * minSharePrice: 0n, // disables slippage protection — production code should compute via `computeMinBorrowSharePrice` from market state + slippage tolerance
74
74
  * },
75
75
  * });
76
- * // tx satisfies Readonly<Transaction<MarketV1SupplyCollateralBorrowAction>>
76
+ * // tx satisfies Readonly<Transaction<BlueSupplyCollateralBorrowAction>>
77
77
  * ```
78
78
  */
79
- export const marketV1SupplyCollateralBorrow = ({ market: { chainId, marketParams }, args: { amount = 0n, borrowAmount, onBehalf, receiver, minSharePrice, requirementSignature, nativeAmount, reallocations, }, metadata, }) => {
79
+ export const blueSupplyCollateralBorrow = ({ market: { chainId, marketParams }, args: { amount = 0n, borrowAmount, onBehalf, receiver, minSharePrice, requirementSignature, nativeAmount, reallocations, }, metadata, }) => {
80
80
  if (amount < 0n) {
81
81
  throw new NonPositiveAssetAmountError(marketParams.collateralToken);
82
82
  }
@@ -142,7 +142,7 @@ export const marketV1SupplyCollateralBorrow = ({ market: { chainId, marketParams
142
142
  return deepFreeze({
143
143
  ...tx,
144
144
  action: {
145
- type: "marketV1SupplyCollateralBorrow",
145
+ type: "blueSupplyCollateralBorrow",
146
146
  args: {
147
147
  market: marketParams.id,
148
148
  collateralAmount: totalCollateral,
@@ -1,8 +1,8 @@
1
1
  import type { MarketParams } from "@morpho-org/blue-sdk";
2
2
  import type { Address } from "viem";
3
- import { type MarketV1WithdrawAction, type Metadata, type Transaction, type VaultReallocation } from "../../types/index.js";
4
- /** Parameters for {@link marketV1Withdraw}. */
5
- export interface MarketV1WithdrawParams {
3
+ import { type BlueWithdrawAction, type Metadata, type Transaction, type VaultReallocation } from "../../types/index.js";
4
+ /** Parameters for {@link blueWithdraw}. */
5
+ export interface BlueWithdrawParams {
6
6
  market: {
7
7
  readonly chainId: number;
8
8
  readonly marketParams: MarketParams;
@@ -18,7 +18,7 @@ export interface MarketV1WithdrawParams {
18
18
  minSharePrice: bigint;
19
19
  /**
20
20
  * Vault reallocations to execute before withdrawing. Compute via
21
- * `MorphoMarketV1.getReallocations({ operation: "withdraw", amount })` or directly via
21
+ * `MorphoBlue.getReallocations({ operation: "withdraw", amount })` or directly via
22
22
  * `computeReallocations({ operation: "withdraw", amount, ... })`.
23
23
  */
24
24
  reallocations?: readonly VaultReallocation[];
@@ -40,7 +40,7 @@ export interface MarketV1WithdrawParams {
40
40
  * computed on-chain directly to `receiver`; no skim is required.
41
41
  *
42
42
  * The withdraw is performed on behalf of the transaction initiator (signer) — there is no
43
- * separate `onBehalf` field; mirror `marketV1Borrow`. The entity layer keeps `receiver` aligned
43
+ * separate `onBehalf` field; mirror `blueBorrow`. The entity layer keeps `receiver` aligned
44
44
  * with the user when none is provided. Requires the user to have authorized `GeneralAdapter1`
45
45
  * on Morpho.
46
46
  *
@@ -54,21 +54,21 @@ export interface MarketV1WithdrawParams {
54
54
  * @param params.args.reallocations - Optional vault reallocations to execute before withdrawing,
55
55
  * computed by the entity layer.
56
56
  * @param params.metadata - Optional analytics metadata attached to the bundle.
57
- * @returns A deep-frozen `Transaction<MarketV1WithdrawAction>` with `to`, `value`, `data`, and
57
+ * @returns A deep-frozen `Transaction<BlueWithdrawAction>` with `to`, `value`, `data`, and
58
58
  * the typed `action` discriminator the simulation layer consumes.
59
59
  * @throws {NonPositiveWithdrawAmountError} when both `assets` and `shares` are zero, or either is negative.
60
60
  * @throws {MutuallyExclusiveWithdrawAmountsError} when both `assets` and `shares` are non-zero.
61
61
  * @throws {NegativeWithdrawMinSharePriceError} when `minSharePrice < 0n` (zero is allowed despite
62
- * the class name — pattern preserved for symmetry with `marketV1Borrow`).
62
+ * the class name — pattern preserved for symmetry with `blueBorrow`).
63
63
  * @throws Reallocation errors from `buildReallocationActions` when `reallocations` is malformed
64
64
  * (see its JSDoc: `NegativeReallocationFeeError`, `EmptyReallocationWithdrawalsError`,
65
65
  * `NonPositiveReallocationAmountError`, `ReallocationWithdrawalOnTargetMarketError`,
66
66
  * `UnsortedReallocationWithdrawalsError`).
67
67
  * @example
68
68
  * ```ts
69
- * import { marketV1Withdraw } from "@morpho-org/morpho-sdk";
69
+ * import { blueWithdraw } from "@morpho-org/morpho-sdk";
70
70
  *
71
- * const tx = marketV1Withdraw({
71
+ * const tx = blueWithdraw({
72
72
  * market: { chainId: 1, marketParams },
73
73
  * args: {
74
74
  * assets: 1_000_000_000n,
@@ -77,7 +77,7 @@ export interface MarketV1WithdrawParams {
77
77
  * minSharePrice: 0n, // disables slippage protection — production code should compute via `computeMinWithdrawSharePrice` from market state + slippage tolerance
78
78
  * },
79
79
  * });
80
- * // tx satisfies Readonly<Transaction<MarketV1WithdrawAction>>
80
+ * // tx satisfies Readonly<Transaction<BlueWithdrawAction>>
81
81
  * ```
82
82
  */
83
- export declare const marketV1Withdraw: ({ market: { chainId, marketParams }, args: { assets, shares, receiver, minSharePrice, reallocations }, metadata, }: MarketV1WithdrawParams) => Readonly<Transaction<MarketV1WithdrawAction>>;
83
+ export declare const blueWithdraw: ({ market: { chainId, marketParams }, args: { assets, shares, receiver, minSharePrice, reallocations }, metadata, }: BlueWithdrawParams) => Readonly<Transaction<BlueWithdrawAction>>;
@@ -18,7 +18,7 @@ import { buildReallocationActions } from "./buildReallocationActions.js";
18
18
  * computed on-chain directly to `receiver`; no skim is required.
19
19
  *
20
20
  * The withdraw is performed on behalf of the transaction initiator (signer) — there is no
21
- * separate `onBehalf` field; mirror `marketV1Borrow`. The entity layer keeps `receiver` aligned
21
+ * separate `onBehalf` field; mirror `blueBorrow`. The entity layer keeps `receiver` aligned
22
22
  * with the user when none is provided. Requires the user to have authorized `GeneralAdapter1`
23
23
  * on Morpho.
24
24
  *
@@ -32,21 +32,21 @@ import { buildReallocationActions } from "./buildReallocationActions.js";
32
32
  * @param params.args.reallocations - Optional vault reallocations to execute before withdrawing,
33
33
  * computed by the entity layer.
34
34
  * @param params.metadata - Optional analytics metadata attached to the bundle.
35
- * @returns A deep-frozen `Transaction<MarketV1WithdrawAction>` with `to`, `value`, `data`, and
35
+ * @returns A deep-frozen `Transaction<BlueWithdrawAction>` with `to`, `value`, `data`, and
36
36
  * the typed `action` discriminator the simulation layer consumes.
37
37
  * @throws {NonPositiveWithdrawAmountError} when both `assets` and `shares` are zero, or either is negative.
38
38
  * @throws {MutuallyExclusiveWithdrawAmountsError} when both `assets` and `shares` are non-zero.
39
39
  * @throws {NegativeWithdrawMinSharePriceError} when `minSharePrice < 0n` (zero is allowed despite
40
- * the class name — pattern preserved for symmetry with `marketV1Borrow`).
40
+ * the class name — pattern preserved for symmetry with `blueBorrow`).
41
41
  * @throws Reallocation errors from `buildReallocationActions` when `reallocations` is malformed
42
42
  * (see its JSDoc: `NegativeReallocationFeeError`, `EmptyReallocationWithdrawalsError`,
43
43
  * `NonPositiveReallocationAmountError`, `ReallocationWithdrawalOnTargetMarketError`,
44
44
  * `UnsortedReallocationWithdrawalsError`).
45
45
  * @example
46
46
  * ```ts
47
- * import { marketV1Withdraw } from "@morpho-org/morpho-sdk";
47
+ * import { blueWithdraw } from "@morpho-org/morpho-sdk";
48
48
  *
49
- * const tx = marketV1Withdraw({
49
+ * const tx = blueWithdraw({
50
50
  * market: { chainId: 1, marketParams },
51
51
  * args: {
52
52
  * assets: 1_000_000_000n,
@@ -55,10 +55,10 @@ import { buildReallocationActions } from "./buildReallocationActions.js";
55
55
  * minSharePrice: 0n, // disables slippage protection — production code should compute via `computeMinWithdrawSharePrice` from market state + slippage tolerance
56
56
  * },
57
57
  * });
58
- * // tx satisfies Readonly<Transaction<MarketV1WithdrawAction>>
58
+ * // tx satisfies Readonly<Transaction<BlueWithdrawAction>>
59
59
  * ```
60
60
  */
61
- export const marketV1Withdraw = ({ market: { chainId, marketParams }, args: { assets, shares, receiver, minSharePrice, reallocations }, metadata, }) => {
61
+ export const blueWithdraw = ({ market: { chainId, marketParams }, args: { assets, shares, receiver, minSharePrice, reallocations }, metadata, }) => {
62
62
  // Mutual exclusion is detected on "both values present" (either non-zero),
63
63
  // before sign checks — otherwise `{ assets: -1n, shares: 5n }` would be
64
64
  // misreported as a positivity error rather than the actual mode conflict.
@@ -92,7 +92,7 @@ export const marketV1Withdraw = ({ market: { chainId, marketParams }, args: { as
92
92
  return deepFreeze({
93
93
  ...tx,
94
94
  action: {
95
- type: "marketV1Withdraw",
95
+ type: "blueWithdraw",
96
96
  args: {
97
97
  market: marketParams.id,
98
98
  assets,
@@ -1,8 +1,8 @@
1
1
  import { type MarketParams } from "@morpho-org/blue-sdk";
2
2
  import { type Address } from "viem";
3
- import { type MarketV1WithdrawCollateralAction, type Metadata, type Transaction } from "../../types/index.js";
4
- /** Parameters for {@link marketV1WithdrawCollateral}. */
5
- export interface MarketV1WithdrawCollateralParams {
3
+ import { type BlueWithdrawCollateralAction, type Metadata, type Transaction } from "../../types/index.js";
4
+ /** Parameters for {@link blueWithdrawCollateral}. */
5
+ export interface BlueWithdrawCollateralParams {
6
6
  market: {
7
7
  readonly chainId: number;
8
8
  readonly marketParams: MarketParams;
@@ -28,14 +28,14 @@ export interface MarketV1WithdrawCollateralParams {
28
28
  * @param params.args.onBehalf - Address whose Morpho position the collateral is withdrawn from.
29
29
  * @param params.args.receiver - Address that receives the withdrawn collateral.
30
30
  * @param params.metadata - Optional analytics metadata attached to the transaction.
31
- * @returns A deep-frozen `Transaction<MarketV1WithdrawCollateralAction>` with `to`, `value`,
31
+ * @returns A deep-frozen `Transaction<BlueWithdrawCollateralAction>` with `to`, `value`,
32
32
  * `data`, and the typed `action` discriminator the simulation layer consumes.
33
33
  * @throws {NonPositiveWithdrawCollateralAmountError} when `amount <= 0n`.
34
34
  * @example
35
35
  * ```ts
36
- * import { marketV1WithdrawCollateral } from "@morpho-org/morpho-sdk";
36
+ * import { blueWithdrawCollateral } from "@morpho-org/morpho-sdk";
37
37
  *
38
- * const tx = marketV1WithdrawCollateral({
38
+ * const tx = blueWithdrawCollateral({
39
39
  * market: { chainId: 1, marketParams },
40
40
  * args: {
41
41
  * amount: 1_000_000_000_000_000_000n,
@@ -43,7 +43,7 @@ export interface MarketV1WithdrawCollateralParams {
43
43
  * receiver: borrower,
44
44
  * },
45
45
  * });
46
- * // tx satisfies Readonly<Transaction<MarketV1WithdrawCollateralAction>>
46
+ * // tx satisfies Readonly<Transaction<BlueWithdrawCollateralAction>>
47
47
  * ```
48
48
  */
49
- export declare const marketV1WithdrawCollateral: ({ market: { chainId, marketParams }, args: { amount, onBehalf, receiver }, metadata, }: MarketV1WithdrawCollateralParams) => Readonly<Transaction<MarketV1WithdrawCollateralAction>>;
49
+ export declare const blueWithdrawCollateral: ({ market: { chainId, marketParams }, args: { amount, onBehalf, receiver }, metadata, }: BlueWithdrawCollateralParams) => Readonly<Transaction<BlueWithdrawCollateralAction>>;
@@ -18,14 +18,14 @@ import { NonPositiveWithdrawCollateralAmountError, } from "../../types/index.js"
18
18
  * @param params.args.onBehalf - Address whose Morpho position the collateral is withdrawn from.
19
19
  * @param params.args.receiver - Address that receives the withdrawn collateral.
20
20
  * @param params.metadata - Optional analytics metadata attached to the transaction.
21
- * @returns A deep-frozen `Transaction<MarketV1WithdrawCollateralAction>` with `to`, `value`,
21
+ * @returns A deep-frozen `Transaction<BlueWithdrawCollateralAction>` with `to`, `value`,
22
22
  * `data`, and the typed `action` discriminator the simulation layer consumes.
23
23
  * @throws {NonPositiveWithdrawCollateralAmountError} when `amount <= 0n`.
24
24
  * @example
25
25
  * ```ts
26
- * import { marketV1WithdrawCollateral } from "@morpho-org/morpho-sdk";
26
+ * import { blueWithdrawCollateral } from "@morpho-org/morpho-sdk";
27
27
  *
28
- * const tx = marketV1WithdrawCollateral({
28
+ * const tx = blueWithdrawCollateral({
29
29
  * market: { chainId: 1, marketParams },
30
30
  * args: {
31
31
  * amount: 1_000_000_000_000_000_000n,
@@ -33,10 +33,10 @@ import { NonPositiveWithdrawCollateralAmountError, } from "../../types/index.js"
33
33
  * receiver: borrower,
34
34
  * },
35
35
  * });
36
- * // tx satisfies Readonly<Transaction<MarketV1WithdrawCollateralAction>>
36
+ * // tx satisfies Readonly<Transaction<BlueWithdrawCollateralAction>>
37
37
  * ```
38
38
  */
39
- export const marketV1WithdrawCollateral = ({ market: { chainId, marketParams }, args: { amount, onBehalf, receiver }, metadata, }) => {
39
+ export const blueWithdrawCollateral = ({ market: { chainId, marketParams }, args: { amount, onBehalf, receiver }, metadata, }) => {
40
40
  if (amount <= 0n) {
41
41
  throw new NonPositiveWithdrawCollateralAmountError(marketParams.id);
42
42
  }
@@ -56,7 +56,7 @@ export const marketV1WithdrawCollateral = ({ market: { chainId, marketParams },
56
56
  return deepFreeze({
57
57
  ...tx,
58
58
  action: {
59
- type: "marketV1WithdrawCollateral",
59
+ type: "blueWithdrawCollateral",
60
60
  args: {
61
61
  market: marketParams.id,
62
62
  amount,
@@ -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";
@@ -1,4 +1,4 @@
1
- export * from "./marketV1/index.js";
1
+ export * from "./blue/index.js";
2
2
  export * from "./requirements/index.js";
3
3
  export * from "./vaultV1/index.js";
4
4
  export * from "./vaultV2/index.js";
@@ -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`.
@@ -8,7 +8,7 @@ import { ChainIdMismatchError, } from "../../types/index.js";
8
8
  * the `setAuthorization(generalAdapter1, true)` transaction when it does.
9
9
  *
10
10
  * Reads `Morpho.isAuthorized(userAddress, generalAdapter1)` on the target chain. Required before
11
- * any bundled MarketV1 path that operates on behalf of the user (`borrow`,
11
+ * any bundled Blue path that operates on behalf of the user (`borrow`,
12
12
  * `supplyCollateralBorrow`, `repayWithdrawCollateral`).
13
13
  *
14
14
  * @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";
@@ -1,2 +1 @@
1
- export * from "./morphoClient.js";
2
1
  export * from "./morphoViemExtension.js";
@@ -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,20 +1,61 @@
1
- import { MorphoClient } from "./morphoClient.js";
1
+ import { MarketUtils } from "@morpho-org/blue-sdk";
2
+ import { deepFreeze } from "@morpho-org/morpho-ts";
3
+ import { MorphoBlue, MorphoVaultV1, MorphoVaultV2 } from "../entities/index.js";
4
+ import { MarketIdMismatchError, } from "../types/index.js";
2
5
  /**
3
- * Returns a viem `extend(...)` function that adds a `morpho` namespace to a viem client. The
4
- * namespace exposes a `MorphoClient` instance built from the same client and the supplied
5
- * options.
6
+ * Builds the stateless `morpho` namespace exposed on an extended viem client. Wraps the supplied
7
+ * viem `Client` plus a frozen options bag and exposes factory methods for the protocol entities.
6
8
  *
7
- * @param _options - Optional SDK-wide options forwarded to the inner `MorphoClient`.
9
+ * Holds no state beyond configuration: no cache, no `init()`, no warm-up. Each factory call
10
+ * (`vaultV1`, `vaultV2`, `blue`) returns a fresh entity bound to this client.
11
+ *
12
+ * @internal
13
+ */
14
+ function createMorphoNamespace(viemClient, options) {
15
+ const namespace = {
16
+ viemClient,
17
+ options: deepFreeze({
18
+ ...options,
19
+ metadata: options?.metadata === undefined ? undefined : { ...options.metadata },
20
+ supportSignature: options?.supportSignature ?? false,
21
+ supportDeployless: options?.supportDeployless,
22
+ }),
23
+ vaultV1(vault, chainId) {
24
+ return new MorphoVaultV1(namespace, vault, chainId);
25
+ },
26
+ vaultV2(vault, chainId) {
27
+ return new MorphoVaultV2(namespace, vault, chainId);
28
+ },
29
+ blue(marketParams, chainId) {
30
+ const derivedId = MarketUtils.getMarketId(marketParams);
31
+ // Can happen with one-time/hardcoded/agent-written possibly inconsistent input market params.
32
+ if (marketParams.id !== derivedId) {
33
+ throw new MarketIdMismatchError(marketParams.id, derivedId);
34
+ }
35
+ return new MorphoBlue(namespace, marketParams, chainId);
36
+ },
37
+ };
38
+ return namespace;
39
+ }
40
+ /**
41
+ * Returns a viem `extend(...)` function that adds a stateless `morpho` namespace to a viem client.
42
+ * The namespace rides on top of the same client (one transport / chain / account) and exposes the
43
+ * protocol entity factories under `client.morpho`, so reads and writes share one client.
44
+ *
45
+ * Holds no state beyond configuration: no cache, no `init()`, no warm-up. Each factory call
46
+ * (`client.morpho.vaultV1`, `vaultV2`, `blue`) returns a fresh entity bound to the client.
47
+ *
48
+ * @param _options - Optional SDK-wide options forwarded to the `morpho` namespace.
8
49
  * @param _options.metadata - Optional analytics metadata applied to every transaction the
9
- * resulting `MorphoClient` builds.
50
+ * `morpho` namespace builds.
10
51
  * @param _options.supportSignature - Whether the integrator can collect EIP-712 signatures for
11
- * permit / permit2.
52
+ * permit / permit2. Defaults to `false` (classic approvals only).
12
53
  * @param _options.supportDeployless - Whether entity fetchers may use deployless multicall.
13
54
  * @returns A viem extension function — `client.extend(morphoViemExtension(...))` adds
14
55
  * `client.morpho`.
15
56
  * @example
16
57
  * ```ts
17
- * import { createWalletClient, http } from "viem";
58
+ * import { createWalletClient, http, publicActions } from "viem";
18
59
  * import { mainnet } from "viem/chains";
19
60
  * import { morphoViemExtension } from "@morpho-org/morpho-sdk";
20
61
  *
@@ -22,8 +63,12 @@ import { MorphoClient } from "./morphoClient.js";
22
63
  * chain: mainnet,
23
64
  * transport: http(),
24
65
  * account: user,
25
- * }).extend(morphoViemExtension({ supportSignature: true }));
66
+ * })
67
+ * .extend(publicActions)
68
+ * .extend(morphoViemExtension({ supportSignature: true }));
26
69
  *
70
+ * // Native viem reads and Morpho factories share the same client:
71
+ * const block = await client.getBlockNumber();
27
72
  * const vault = client.morpho.vaultV1(vaultAddress, 1);
28
73
  * const vaultData = await vault.getData();
29
74
  * const { buildTx } = vault.deposit({
@@ -37,7 +82,7 @@ import { MorphoClient } from "./morphoClient.js";
37
82
  export function morphoViemExtension(_options) {
38
83
  return (client) => {
39
84
  return {
40
- morpho: new MorphoClient(client, _options),
85
+ morpho: createMorphoNamespace(client, _options),
41
86
  };
42
87
  };
43
88
  }