@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
@@ -200,8 +200,8 @@ export const validateRepayShares = (params) => {
200
200
  }
201
201
  };
202
202
  /**
203
- * Validates the common repay input parameters shared by `marketV1Repay`
204
- * and `marketV1RepayWithdrawCollateral`.
203
+ * Validates the common repay input parameters shared by `blueRepay`
204
+ * and `blueRepayWithdrawCollateral`.
205
205
  *
206
206
  * @param params - Validation parameters.
207
207
  * @param params.assets - Repay assets amount (0n when repaying by shares).
@@ -81,7 +81,7 @@ export interface VaultV1MigrateToV2Action extends BaseAction<"vaultV1MigrateToV2
81
81
  recipient: Address;
82
82
  }> {
83
83
  }
84
- export interface MarketV1SupplyAction extends BaseAction<"marketV1Supply", {
84
+ export interface BlueSupplyAction extends BaseAction<"blueSupply", {
85
85
  market: Hex;
86
86
  amount: bigint;
87
87
  onBehalf: Address;
@@ -89,7 +89,7 @@ export interface MarketV1SupplyAction extends BaseAction<"marketV1Supply", {
89
89
  nativeAmount?: bigint;
90
90
  }> {
91
91
  }
92
- export interface MarketV1WithdrawAction extends BaseAction<"marketV1Withdraw", {
92
+ export interface BlueWithdrawAction extends BaseAction<"blueWithdraw", {
93
93
  market: Hex;
94
94
  assets: bigint;
95
95
  shares: bigint;
@@ -98,14 +98,14 @@ export interface MarketV1WithdrawAction extends BaseAction<"marketV1Withdraw", {
98
98
  reallocationFee: bigint;
99
99
  }> {
100
100
  }
101
- export interface MarketV1SupplyCollateralAction extends BaseAction<"marketV1SupplyCollateral", {
101
+ export interface BlueSupplyCollateralAction extends BaseAction<"blueSupplyCollateral", {
102
102
  market: Hex;
103
103
  amount: bigint;
104
104
  onBehalf: Address;
105
105
  nativeAmount?: bigint;
106
106
  }> {
107
107
  }
108
- export interface MarketV1BorrowAction extends BaseAction<"marketV1Borrow", {
108
+ export interface BlueBorrowAction extends BaseAction<"blueBorrow", {
109
109
  market: Hex;
110
110
  amount: bigint;
111
111
  receiver: Address;
@@ -113,7 +113,7 @@ export interface MarketV1BorrowAction extends BaseAction<"marketV1Borrow", {
113
113
  reallocationFee: bigint;
114
114
  }> {
115
115
  }
116
- export interface MarketV1SupplyCollateralBorrowAction extends BaseAction<"marketV1SupplyCollateralBorrow", {
116
+ export interface BlueSupplyCollateralBorrowAction extends BaseAction<"blueSupplyCollateralBorrow", {
117
117
  market: Hex;
118
118
  collateralAmount: bigint;
119
119
  borrowAmount: bigint;
@@ -124,7 +124,7 @@ export interface MarketV1SupplyCollateralBorrowAction extends BaseAction<"market
124
124
  reallocationFee: bigint;
125
125
  }> {
126
126
  }
127
- export interface MarketV1RepayAction extends BaseAction<"marketV1Repay", {
127
+ export interface BlueRepayAction extends BaseAction<"blueRepay", {
128
128
  market: Hex;
129
129
  assets: bigint;
130
130
  shares: bigint;
@@ -134,14 +134,14 @@ export interface MarketV1RepayAction extends BaseAction<"marketV1Repay", {
134
134
  maxSharePrice: bigint;
135
135
  }> {
136
136
  }
137
- export interface MarketV1WithdrawCollateralAction extends BaseAction<"marketV1WithdrawCollateral", {
137
+ export interface BlueWithdrawCollateralAction extends BaseAction<"blueWithdrawCollateral", {
138
138
  market: Hex;
139
139
  amount: bigint;
140
140
  onBehalf: Address;
141
141
  receiver: Address;
142
142
  }> {
143
143
  }
144
- export interface MarketV1RepayWithdrawCollateralAction extends BaseAction<"marketV1RepayWithdrawCollateral", {
144
+ export interface BlueRepayWithdrawCollateralAction extends BaseAction<"blueRepayWithdrawCollateral", {
145
145
  market: Hex;
146
146
  repayAssets: bigint;
147
147
  repayShares: bigint;
@@ -152,7 +152,7 @@ export interface MarketV1RepayWithdrawCollateralAction extends BaseAction<"marke
152
152
  receiver: Address;
153
153
  }> {
154
154
  }
155
- export interface MarketV1RefinanceAction extends BaseAction<"marketV1Refinance", {
155
+ export interface BlueRefinanceAction extends BaseAction<"blueRefinance", {
156
156
  readonly sourceMarket: Hex;
157
157
  readonly targetMarket: Hex;
158
158
  readonly collateralAmount: bigint;
@@ -185,7 +185,7 @@ export interface MorphoAuthorizationAction extends BaseAction<"morphoAuthorizati
185
185
  isAuthorized: boolean;
186
186
  }> {
187
187
  }
188
- export type TransactionAction = ERC20ApprovalAction | VaultV2DepositAction | VaultV2WithdrawAction | VaultV2RedeemAction | VaultV2ForceWithdrawAction | VaultV2ForceRedeemAction | VaultV1DepositAction | VaultV1WithdrawAction | VaultV1RedeemAction | VaultV1MigrateToV2Action | MarketV1SupplyAction | MarketV1WithdrawAction | MarketV1SupplyCollateralAction | MarketV1BorrowAction | MarketV1SupplyCollateralBorrowAction | MarketV1RepayAction | MarketV1WithdrawCollateralAction | MarketV1RepayWithdrawCollateralAction | MarketV1RefinanceAction | MorphoAuthorizationAction;
188
+ export type TransactionAction = ERC20ApprovalAction | VaultV2DepositAction | VaultV2WithdrawAction | VaultV2RedeemAction | VaultV2ForceWithdrawAction | VaultV2ForceRedeemAction | VaultV1DepositAction | VaultV1WithdrawAction | VaultV1RedeemAction | VaultV1MigrateToV2Action | BlueSupplyAction | BlueWithdrawAction | BlueSupplyCollateralAction | BlueBorrowAction | BlueSupplyCollateralBorrowAction | BlueRepayAction | BlueWithdrawCollateralAction | BlueRepayWithdrawCollateralAction | BlueRefinanceAction | MorphoAuthorizationAction;
189
189
  export interface Transaction<TAction extends BaseAction = TransactionAction> {
190
190
  readonly to: Address;
191
191
  readonly value: bigint;
@@ -1,10 +1,11 @@
1
1
  import type { MarketParams } from "@morpho-org/blue-sdk";
2
2
  import type { Address, Client } from "viem";
3
- import type { MarketV1Actions, VaultV1Actions, VaultV2Actions } from "../actions/index.js";
3
+ import type { BlueActions, VaultV1Actions, VaultV2Actions } from "../actions/index.js";
4
4
  import type { Metadata } from "./index.js";
5
5
  /**
6
- * Structural contract every concrete `MorphoClient` implementation satisfies. Carries the viem
7
- * client, the resolved options bag, and the three entity-factory methods the SDK exposes.
6
+ * Structural contract the `morpho` namespace satisfies — the object exposed under `client.morpho`
7
+ * once a viem client is extended with {@link morphoViemExtension}. Carries the viem client, the
8
+ * resolved options bag, and the three entity-factory methods the SDK exposes.
8
9
  */
9
10
  export interface MorphoClientType {
10
11
  readonly viemClient: Client;
@@ -15,5 +16,5 @@ export interface MorphoClientType {
15
16
  };
16
17
  vaultV1: (vault: Address, chainId: number) => VaultV1Actions;
17
18
  vaultV2: (vault: Address, chainId: number) => VaultV2Actions;
18
- marketV1: (marketParams: MarketParams, chainId: number) => MarketV1Actions;
19
+ blue: (marketParams: MarketParams, chainId: number) => BlueActions;
19
20
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@morpho-org/morpho-sdk",
3
3
  "description": "Abstraction layer for Morpho's complexity.",
4
- "version": "3.2.0",
4
+ "version": "4.1.0",
5
5
  "author": "Morpho Association <contact@morpho.org>",
6
6
  "contributors": [
7
7
  "Foulks-Plb <https://x.com/FoulkPlb>"
@@ -137,9 +137,9 @@
137
137
  ],
138
138
  "dependencies": {
139
139
  "zod": "^4.4.3",
140
- "@morpho-org/blue-sdk": "^6.1.0",
140
+ "@morpho-org/blue-sdk": "^6.2.0",
141
141
  "@morpho-org/morpho-ts": "^2.6.0",
142
- "@morpho-org/blue-sdk-viem": "^5.1.0"
142
+ "@morpho-org/blue-sdk-viem": "^5.1.1"
143
143
  },
144
144
  "peerDependencies": {
145
145
  "viem": "^2.0.0"
@@ -148,8 +148,8 @@
148
148
  "dotenv": "^17.4.2",
149
149
  "fast-check": "^4.8.0",
150
150
  "typescript": "^6.0.3",
151
- "viem": "^2.50.4",
152
- "vitest": "^4.1.7",
151
+ "viem": "2.52.2",
152
+ "vitest": "^4.1.8",
153
153
  "@morpho-org/bundler-sdk-viem": "^5.0.3",
154
154
  "@morpho-org/simulation-sdk": "^4.0.3",
155
155
  "@morpho-org/test": "^2.8.1"
@@ -1,152 +0,0 @@
1
- import { type MarketParams } from "@morpho-org/blue-sdk";
2
- import type { Address, Client } from "viem";
3
- import { MorphoMarketV1, MorphoVaultV1, MorphoVaultV2 } from "../entities/index.js";
4
- import { type Metadata, type MorphoClientType } from "../types/index.js";
5
- /**
6
- * Stateless entry point of the SDK. Wraps a viem `Client` plus a frozen options bag and exposes
7
- * factory methods for the protocol entities.
8
- *
9
- * Holds no state beyond configuration: no cache, no `init()`, no warm-up. Each factory call
10
- * (`vaultV1`, `vaultV2`, `marketV1`) returns a fresh entity bound to this client.
11
- *
12
- * @deprecated Use {@link morphoViemExtension} instead. Extending your viem client keeps a single
13
- * transport / chain / account on the integrator side and exposes the same factories under
14
- * `client.morpho`, so reads and writes share one client. `MorphoClient` will be removed in the
15
- * next major release.
16
- *
17
- * @example
18
- * ```ts
19
- * // Before — wrapping a viem client in MorphoClient:
20
- * import { createPublicClient, http } from "viem";
21
- * import { mainnet } from "viem/chains";
22
- * import { MorphoClient } from "@morpho-org/morpho-sdk";
23
- *
24
- * const publicClient = createPublicClient({ chain: mainnet, transport: http() });
25
- * const morpho = new MorphoClient(publicClient);
26
- *
27
- * const vault = morpho.vaultV1(vaultAddress, 1);
28
- * const vaultData = await vault.getData();
29
- * ```
30
- *
31
- * @example
32
- * ```ts
33
- * // After — extend the public client directly:
34
- * import { createPublicClient, http } from "viem";
35
- * import { mainnet } from "viem/chains";
36
- * import { morphoViemExtension } from "@morpho-org/morpho-sdk";
37
- *
38
- * const client = createPublicClient({ chain: mainnet, transport: http() }).extend(
39
- * morphoViemExtension(),
40
- * );
41
- *
42
- * // Native viem reads and Morpho factories share the same client:
43
- * const block = await client.getBlockNumber();
44
- * const vault = client.morpho.vaultV1(vaultAddress, 1);
45
- * const vaultData = await vault.getData();
46
- * ```
47
- */
48
- export declare class MorphoClient implements MorphoClientType {
49
- readonly viemClient: Client;
50
- readonly _options?: {
51
- readonly supportSignature?: boolean;
52
- readonly supportDeployless?: boolean;
53
- readonly metadata?: Metadata;
54
- } | undefined;
55
- /** SDK-wide options resolved from the constructor's `_options` argument. */
56
- readonly options: {
57
- readonly supportSignature: boolean;
58
- readonly supportDeployless?: boolean;
59
- readonly metadata?: Metadata;
60
- };
61
- /**
62
- * @param viemClient - Connected viem `Client`. Public reads use it as-is; signature flows use
63
- * it as a `WalletClient` and require `account` to be set.
64
- * @param _options - SDK-wide options.
65
- * @param _options.supportSignature - Whether the integrator can collect EIP-712 signatures for
66
- * permit / permit2. Defaults to `false` (classic approvals only).
67
- * @param _options.supportDeployless - Whether entity fetchers may use deployless multicall.
68
- * @param _options.metadata - Optional analytics metadata applied to every transaction this
69
- * client builds.
70
- * @deprecated Prefer {@link morphoViemExtension} so the SDK rides on top of a viem client the
71
- * integrator already owns (public or wallet). Will be removed in the next major release.
72
- * @example
73
- * ```ts
74
- * import { createPublicClient, http } from "viem";
75
- * import { mainnet } from "viem/chains";
76
- * import { morphoViemExtension } from "@morpho-org/morpho-sdk";
77
- *
78
- * const client = createPublicClient({ chain: mainnet, transport: http() }).extend(
79
- * morphoViemExtension({ supportSignature: true }),
80
- * );
81
- *
82
- * const vault = client.morpho.vaultV1(vaultAddress, 1);
83
- * ```
84
- */
85
- constructor(viemClient: Client, _options?: {
86
- readonly supportSignature?: boolean;
87
- readonly supportDeployless?: boolean;
88
- readonly metadata?: Metadata;
89
- } | undefined);
90
- /**
91
- * Returns a `MorphoVaultV1` (MetaMorpho) entity bound to this client.
92
- *
93
- * @param vault - VaultV1 address.
94
- * @param chainId - Chain the vault lives on.
95
- * @returns A fresh `MorphoVaultV1` entity.
96
- * @example
97
- * ```ts
98
- * const vault = client.vaultV1(vaultAddress, 1);
99
- * const vaultData = await vault.getData();
100
- * const { buildTx } = vault.deposit({
101
- * amount: 1_000_000n,
102
- * userAddress: depositor,
103
- * vaultData,
104
- * });
105
- * const tx = buildTx();
106
- * ```
107
- */
108
- vaultV1(vault: Address, chainId: number): MorphoVaultV1;
109
- /**
110
- * Returns a `MorphoVaultV2` entity bound to this client.
111
- *
112
- * @param vault - VaultV2 address.
113
- * @param chainId - Chain the vault lives on.
114
- * @returns A fresh `MorphoVaultV2` entity.
115
- * @example
116
- * ```ts
117
- * const vault = client.vaultV2(vaultAddress, 1);
118
- * const vaultData = await vault.getData();
119
- * const { buildTx } = vault.deposit({
120
- * amount: 1_000_000n,
121
- * userAddress: depositor,
122
- * vaultData,
123
- * });
124
- * const tx = buildTx();
125
- * ```
126
- */
127
- vaultV2(vault: Address, chainId: number): MorphoVaultV2;
128
- /**
129
- * Returns a `MorphoMarketV1` entity bound to this client. Validates that the supplied
130
- * `marketParams.id` matches the hash of the other params, so a hand-rolled or agent-written
131
- * `MarketParams` cannot point at the wrong market silently.
132
- *
133
- * @param marketParams - Market params (`loanToken`, `collateralToken`, `oracle`, `irm`, `lltv`,
134
- * `id`).
135
- * @param chainId - Chain the market lives on.
136
- * @returns A fresh `MorphoMarketV1` entity.
137
- * @throws {MarketIdMismatchError} when `marketParams.id` does not equal the hash derived from
138
- * the other fields.
139
- * @example
140
- * ```ts
141
- * const market = client.marketV1(marketParams, 1);
142
- * const positionData = await market.getPositionData(borrower);
143
- * const { buildTx } = market.borrow({
144
- * userAddress: borrower,
145
- * amount: 1_000_000n,
146
- * positionData,
147
- * });
148
- * const tx = buildTx();
149
- * ```
150
- */
151
- marketV1(marketParams: MarketParams, chainId: number): MorphoMarketV1;
152
- }
@@ -1,162 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.MorphoClient = void 0;
4
- const blue_sdk_1 = require("@morpho-org/blue-sdk");
5
- const index_js_1 = require("../entities/index.js");
6
- const index_js_2 = require("../types/index.js");
7
- /**
8
- * Stateless entry point of the SDK. Wraps a viem `Client` plus a frozen options bag and exposes
9
- * factory methods for the protocol entities.
10
- *
11
- * Holds no state beyond configuration: no cache, no `init()`, no warm-up. Each factory call
12
- * (`vaultV1`, `vaultV2`, `marketV1`) returns a fresh entity bound to this client.
13
- *
14
- * @deprecated Use {@link morphoViemExtension} instead. Extending your viem client keeps a single
15
- * transport / chain / account on the integrator side and exposes the same factories under
16
- * `client.morpho`, so reads and writes share one client. `MorphoClient` will be removed in the
17
- * next major release.
18
- *
19
- * @example
20
- * ```ts
21
- * // Before — wrapping a viem client in MorphoClient:
22
- * import { createPublicClient, http } from "viem";
23
- * import { mainnet } from "viem/chains";
24
- * import { MorphoClient } from "@morpho-org/morpho-sdk";
25
- *
26
- * const publicClient = createPublicClient({ chain: mainnet, transport: http() });
27
- * const morpho = new MorphoClient(publicClient);
28
- *
29
- * const vault = morpho.vaultV1(vaultAddress, 1);
30
- * const vaultData = await vault.getData();
31
- * ```
32
- *
33
- * @example
34
- * ```ts
35
- * // After — extend the public client directly:
36
- * import { createPublicClient, http } from "viem";
37
- * import { mainnet } from "viem/chains";
38
- * import { morphoViemExtension } from "@morpho-org/morpho-sdk";
39
- *
40
- * const client = createPublicClient({ chain: mainnet, transport: http() }).extend(
41
- * morphoViemExtension(),
42
- * );
43
- *
44
- * // Native viem reads and Morpho factories share the same client:
45
- * const block = await client.getBlockNumber();
46
- * const vault = client.morpho.vaultV1(vaultAddress, 1);
47
- * const vaultData = await vault.getData();
48
- * ```
49
- */
50
- class MorphoClient {
51
- viemClient;
52
- _options;
53
- /** SDK-wide options resolved from the constructor's `_options` argument. */
54
- options;
55
- /**
56
- * @param viemClient - Connected viem `Client`. Public reads use it as-is; signature flows use
57
- * it as a `WalletClient` and require `account` to be set.
58
- * @param _options - SDK-wide options.
59
- * @param _options.supportSignature - Whether the integrator can collect EIP-712 signatures for
60
- * permit / permit2. Defaults to `false` (classic approvals only).
61
- * @param _options.supportDeployless - Whether entity fetchers may use deployless multicall.
62
- * @param _options.metadata - Optional analytics metadata applied to every transaction this
63
- * client builds.
64
- * @deprecated Prefer {@link morphoViemExtension} so the SDK rides on top of a viem client the
65
- * integrator already owns (public or wallet). Will be removed in the next major release.
66
- * @example
67
- * ```ts
68
- * import { createPublicClient, http } from "viem";
69
- * import { mainnet } from "viem/chains";
70
- * import { morphoViemExtension } from "@morpho-org/morpho-sdk";
71
- *
72
- * const client = createPublicClient({ chain: mainnet, transport: http() }).extend(
73
- * morphoViemExtension({ supportSignature: true }),
74
- * );
75
- *
76
- * const vault = client.morpho.vaultV1(vaultAddress, 1);
77
- * ```
78
- */
79
- constructor(viemClient, _options) {
80
- this.viemClient = viemClient;
81
- this._options = _options;
82
- this.options = {
83
- ..._options,
84
- supportSignature: _options?.supportSignature ?? false,
85
- supportDeployless: _options?.supportDeployless,
86
- };
87
- }
88
- /**
89
- * Returns a `MorphoVaultV1` (MetaMorpho) entity bound to this client.
90
- *
91
- * @param vault - VaultV1 address.
92
- * @param chainId - Chain the vault lives on.
93
- * @returns A fresh `MorphoVaultV1` entity.
94
- * @example
95
- * ```ts
96
- * const vault = client.vaultV1(vaultAddress, 1);
97
- * const vaultData = await vault.getData();
98
- * const { buildTx } = vault.deposit({
99
- * amount: 1_000_000n,
100
- * userAddress: depositor,
101
- * vaultData,
102
- * });
103
- * const tx = buildTx();
104
- * ```
105
- */
106
- vaultV1(vault, chainId) {
107
- return new index_js_1.MorphoVaultV1(this, vault, chainId);
108
- }
109
- /**
110
- * Returns a `MorphoVaultV2` entity bound to this client.
111
- *
112
- * @param vault - VaultV2 address.
113
- * @param chainId - Chain the vault lives on.
114
- * @returns A fresh `MorphoVaultV2` entity.
115
- * @example
116
- * ```ts
117
- * const vault = client.vaultV2(vaultAddress, 1);
118
- * const vaultData = await vault.getData();
119
- * const { buildTx } = vault.deposit({
120
- * amount: 1_000_000n,
121
- * userAddress: depositor,
122
- * vaultData,
123
- * });
124
- * const tx = buildTx();
125
- * ```
126
- */
127
- vaultV2(vault, chainId) {
128
- return new index_js_1.MorphoVaultV2(this, vault, chainId);
129
- }
130
- /**
131
- * Returns a `MorphoMarketV1` entity bound to this client. Validates that the supplied
132
- * `marketParams.id` matches the hash of the other params, so a hand-rolled or agent-written
133
- * `MarketParams` cannot point at the wrong market silently.
134
- *
135
- * @param marketParams - Market params (`loanToken`, `collateralToken`, `oracle`, `irm`, `lltv`,
136
- * `id`).
137
- * @param chainId - Chain the market lives on.
138
- * @returns A fresh `MorphoMarketV1` entity.
139
- * @throws {MarketIdMismatchError} when `marketParams.id` does not equal the hash derived from
140
- * the other fields.
141
- * @example
142
- * ```ts
143
- * const market = client.marketV1(marketParams, 1);
144
- * const positionData = await market.getPositionData(borrower);
145
- * const { buildTx } = market.borrow({
146
- * userAddress: borrower,
147
- * amount: 1_000_000n,
148
- * positionData,
149
- * });
150
- * const tx = buildTx();
151
- * ```
152
- */
153
- marketV1(marketParams, chainId) {
154
- const derivedId = blue_sdk_1.MarketUtils.getMarketId(marketParams);
155
- // Can happen with one-time/hardcoded/agent-written possibly inconsistent input market params.
156
- if (marketParams.id !== derivedId) {
157
- throw new index_js_2.MarketIdMismatchError(marketParams.id, derivedId);
158
- }
159
- return new index_js_1.MorphoMarketV1(this, marketParams, chainId);
160
- }
161
- }
162
- exports.MorphoClient = MorphoClient;
@@ -1 +0,0 @@
1
- export * from "./marketV1.js";
@@ -1,152 +0,0 @@
1
- import { type MarketParams } from "@morpho-org/blue-sdk";
2
- import type { Address, Client } from "viem";
3
- import { MorphoMarketV1, MorphoVaultV1, MorphoVaultV2 } from "../entities/index.js";
4
- import { type Metadata, type MorphoClientType } from "../types/index.js";
5
- /**
6
- * Stateless entry point of the SDK. Wraps a viem `Client` plus a frozen options bag and exposes
7
- * factory methods for the protocol entities.
8
- *
9
- * Holds no state beyond configuration: no cache, no `init()`, no warm-up. Each factory call
10
- * (`vaultV1`, `vaultV2`, `marketV1`) returns a fresh entity bound to this client.
11
- *
12
- * @deprecated Use {@link morphoViemExtension} instead. Extending your viem client keeps a single
13
- * transport / chain / account on the integrator side and exposes the same factories under
14
- * `client.morpho`, so reads and writes share one client. `MorphoClient` will be removed in the
15
- * next major release.
16
- *
17
- * @example
18
- * ```ts
19
- * // Before — wrapping a viem client in MorphoClient:
20
- * import { createPublicClient, http } from "viem";
21
- * import { mainnet } from "viem/chains";
22
- * import { MorphoClient } from "@morpho-org/morpho-sdk";
23
- *
24
- * const publicClient = createPublicClient({ chain: mainnet, transport: http() });
25
- * const morpho = new MorphoClient(publicClient);
26
- *
27
- * const vault = morpho.vaultV1(vaultAddress, 1);
28
- * const vaultData = await vault.getData();
29
- * ```
30
- *
31
- * @example
32
- * ```ts
33
- * // After — extend the public client directly:
34
- * import { createPublicClient, http } from "viem";
35
- * import { mainnet } from "viem/chains";
36
- * import { morphoViemExtension } from "@morpho-org/morpho-sdk";
37
- *
38
- * const client = createPublicClient({ chain: mainnet, transport: http() }).extend(
39
- * morphoViemExtension(),
40
- * );
41
- *
42
- * // Native viem reads and Morpho factories share the same client:
43
- * const block = await client.getBlockNumber();
44
- * const vault = client.morpho.vaultV1(vaultAddress, 1);
45
- * const vaultData = await vault.getData();
46
- * ```
47
- */
48
- export declare class MorphoClient implements MorphoClientType {
49
- readonly viemClient: Client;
50
- readonly _options?: {
51
- readonly supportSignature?: boolean;
52
- readonly supportDeployless?: boolean;
53
- readonly metadata?: Metadata;
54
- } | undefined;
55
- /** SDK-wide options resolved from the constructor's `_options` argument. */
56
- readonly options: {
57
- readonly supportSignature: boolean;
58
- readonly supportDeployless?: boolean;
59
- readonly metadata?: Metadata;
60
- };
61
- /**
62
- * @param viemClient - Connected viem `Client`. Public reads use it as-is; signature flows use
63
- * it as a `WalletClient` and require `account` to be set.
64
- * @param _options - SDK-wide options.
65
- * @param _options.supportSignature - Whether the integrator can collect EIP-712 signatures for
66
- * permit / permit2. Defaults to `false` (classic approvals only).
67
- * @param _options.supportDeployless - Whether entity fetchers may use deployless multicall.
68
- * @param _options.metadata - Optional analytics metadata applied to every transaction this
69
- * client builds.
70
- * @deprecated Prefer {@link morphoViemExtension} so the SDK rides on top of a viem client the
71
- * integrator already owns (public or wallet). Will be removed in the next major release.
72
- * @example
73
- * ```ts
74
- * import { createPublicClient, http } from "viem";
75
- * import { mainnet } from "viem/chains";
76
- * import { morphoViemExtension } from "@morpho-org/morpho-sdk";
77
- *
78
- * const client = createPublicClient({ chain: mainnet, transport: http() }).extend(
79
- * morphoViemExtension({ supportSignature: true }),
80
- * );
81
- *
82
- * const vault = client.morpho.vaultV1(vaultAddress, 1);
83
- * ```
84
- */
85
- constructor(viemClient: Client, _options?: {
86
- readonly supportSignature?: boolean;
87
- readonly supportDeployless?: boolean;
88
- readonly metadata?: Metadata;
89
- } | undefined);
90
- /**
91
- * Returns a `MorphoVaultV1` (MetaMorpho) entity bound to this client.
92
- *
93
- * @param vault - VaultV1 address.
94
- * @param chainId - Chain the vault lives on.
95
- * @returns A fresh `MorphoVaultV1` entity.
96
- * @example
97
- * ```ts
98
- * const vault = client.vaultV1(vaultAddress, 1);
99
- * const vaultData = await vault.getData();
100
- * const { buildTx } = vault.deposit({
101
- * amount: 1_000_000n,
102
- * userAddress: depositor,
103
- * vaultData,
104
- * });
105
- * const tx = buildTx();
106
- * ```
107
- */
108
- vaultV1(vault: Address, chainId: number): MorphoVaultV1;
109
- /**
110
- * Returns a `MorphoVaultV2` entity bound to this client.
111
- *
112
- * @param vault - VaultV2 address.
113
- * @param chainId - Chain the vault lives on.
114
- * @returns A fresh `MorphoVaultV2` entity.
115
- * @example
116
- * ```ts
117
- * const vault = client.vaultV2(vaultAddress, 1);
118
- * const vaultData = await vault.getData();
119
- * const { buildTx } = vault.deposit({
120
- * amount: 1_000_000n,
121
- * userAddress: depositor,
122
- * vaultData,
123
- * });
124
- * const tx = buildTx();
125
- * ```
126
- */
127
- vaultV2(vault: Address, chainId: number): MorphoVaultV2;
128
- /**
129
- * Returns a `MorphoMarketV1` entity bound to this client. Validates that the supplied
130
- * `marketParams.id` matches the hash of the other params, so a hand-rolled or agent-written
131
- * `MarketParams` cannot point at the wrong market silently.
132
- *
133
- * @param marketParams - Market params (`loanToken`, `collateralToken`, `oracle`, `irm`, `lltv`,
134
- * `id`).
135
- * @param chainId - Chain the market lives on.
136
- * @returns A fresh `MorphoMarketV1` entity.
137
- * @throws {MarketIdMismatchError} when `marketParams.id` does not equal the hash derived from
138
- * the other fields.
139
- * @example
140
- * ```ts
141
- * const market = client.marketV1(marketParams, 1);
142
- * const positionData = await market.getPositionData(borrower);
143
- * const { buildTx } = market.borrow({
144
- * userAddress: borrower,
145
- * amount: 1_000_000n,
146
- * positionData,
147
- * });
148
- * const tx = buildTx();
149
- * ```
150
- */
151
- marketV1(marketParams: MarketParams, chainId: number): MorphoMarketV1;
152
- }