@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,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
- }
@@ -1,158 +0,0 @@
1
- import { MarketUtils } from "@morpho-org/blue-sdk";
2
- import { MorphoMarketV1, MorphoVaultV1, MorphoVaultV2, } from "../entities/index.js";
3
- import { MarketIdMismatchError, } from "../types/index.js";
4
- /**
5
- * Stateless entry point of the SDK. Wraps a viem `Client` plus a frozen options bag and exposes
6
- * factory methods for the protocol entities.
7
- *
8
- * Holds no state beyond configuration: no cache, no `init()`, no warm-up. Each factory call
9
- * (`vaultV1`, `vaultV2`, `marketV1`) returns a fresh entity bound to this client.
10
- *
11
- * @deprecated Use {@link morphoViemExtension} instead. Extending your viem client keeps a single
12
- * transport / chain / account on the integrator side and exposes the same factories under
13
- * `client.morpho`, so reads and writes share one client. `MorphoClient` will be removed in the
14
- * next major release.
15
- *
16
- * @example
17
- * ```ts
18
- * // Before — wrapping a viem client in MorphoClient:
19
- * import { createPublicClient, http } from "viem";
20
- * import { mainnet } from "viem/chains";
21
- * import { MorphoClient } from "@morpho-org/morpho-sdk";
22
- *
23
- * const publicClient = createPublicClient({ chain: mainnet, transport: http() });
24
- * const morpho = new MorphoClient(publicClient);
25
- *
26
- * const vault = morpho.vaultV1(vaultAddress, 1);
27
- * const vaultData = await vault.getData();
28
- * ```
29
- *
30
- * @example
31
- * ```ts
32
- * // After — extend the public client directly:
33
- * import { createPublicClient, http } from "viem";
34
- * import { mainnet } from "viem/chains";
35
- * import { morphoViemExtension } from "@morpho-org/morpho-sdk";
36
- *
37
- * const client = createPublicClient({ chain: mainnet, transport: http() }).extend(
38
- * morphoViemExtension(),
39
- * );
40
- *
41
- * // Native viem reads and Morpho factories share the same client:
42
- * const block = await client.getBlockNumber();
43
- * const vault = client.morpho.vaultV1(vaultAddress, 1);
44
- * const vaultData = await vault.getData();
45
- * ```
46
- */
47
- export class MorphoClient {
48
- viemClient;
49
- _options;
50
- /** SDK-wide options resolved from the constructor's `_options` argument. */
51
- options;
52
- /**
53
- * @param viemClient - Connected viem `Client`. Public reads use it as-is; signature flows use
54
- * it as a `WalletClient` and require `account` to be set.
55
- * @param _options - SDK-wide options.
56
- * @param _options.supportSignature - Whether the integrator can collect EIP-712 signatures for
57
- * permit / permit2. Defaults to `false` (classic approvals only).
58
- * @param _options.supportDeployless - Whether entity fetchers may use deployless multicall.
59
- * @param _options.metadata - Optional analytics metadata applied to every transaction this
60
- * client builds.
61
- * @deprecated Prefer {@link morphoViemExtension} so the SDK rides on top of a viem client the
62
- * integrator already owns (public or wallet). Will be removed in the next major release.
63
- * @example
64
- * ```ts
65
- * import { createPublicClient, http } from "viem";
66
- * import { mainnet } from "viem/chains";
67
- * import { morphoViemExtension } from "@morpho-org/morpho-sdk";
68
- *
69
- * const client = createPublicClient({ chain: mainnet, transport: http() }).extend(
70
- * morphoViemExtension({ supportSignature: true }),
71
- * );
72
- *
73
- * const vault = client.morpho.vaultV1(vaultAddress, 1);
74
- * ```
75
- */
76
- constructor(viemClient, _options) {
77
- this.viemClient = viemClient;
78
- this._options = _options;
79
- this.options = {
80
- ..._options,
81
- supportSignature: _options?.supportSignature ?? false,
82
- supportDeployless: _options?.supportDeployless,
83
- };
84
- }
85
- /**
86
- * Returns a `MorphoVaultV1` (MetaMorpho) entity bound to this client.
87
- *
88
- * @param vault - VaultV1 address.
89
- * @param chainId - Chain the vault lives on.
90
- * @returns A fresh `MorphoVaultV1` entity.
91
- * @example
92
- * ```ts
93
- * const vault = client.vaultV1(vaultAddress, 1);
94
- * const vaultData = await vault.getData();
95
- * const { buildTx } = vault.deposit({
96
- * amount: 1_000_000n,
97
- * userAddress: depositor,
98
- * vaultData,
99
- * });
100
- * const tx = buildTx();
101
- * ```
102
- */
103
- vaultV1(vault, chainId) {
104
- return new MorphoVaultV1(this, vault, chainId);
105
- }
106
- /**
107
- * Returns a `MorphoVaultV2` entity bound to this client.
108
- *
109
- * @param vault - VaultV2 address.
110
- * @param chainId - Chain the vault lives on.
111
- * @returns A fresh `MorphoVaultV2` entity.
112
- * @example
113
- * ```ts
114
- * const vault = client.vaultV2(vaultAddress, 1);
115
- * const vaultData = await vault.getData();
116
- * const { buildTx } = vault.deposit({
117
- * amount: 1_000_000n,
118
- * userAddress: depositor,
119
- * vaultData,
120
- * });
121
- * const tx = buildTx();
122
- * ```
123
- */
124
- vaultV2(vault, chainId) {
125
- return new MorphoVaultV2(this, vault, chainId);
126
- }
127
- /**
128
- * Returns a `MorphoMarketV1` entity bound to this client. Validates that the supplied
129
- * `marketParams.id` matches the hash of the other params, so a hand-rolled or agent-written
130
- * `MarketParams` cannot point at the wrong market silently.
131
- *
132
- * @param marketParams - Market params (`loanToken`, `collateralToken`, `oracle`, `irm`, `lltv`,
133
- * `id`).
134
- * @param chainId - Chain the market lives on.
135
- * @returns A fresh `MorphoMarketV1` entity.
136
- * @throws {MarketIdMismatchError} when `marketParams.id` does not equal the hash derived from
137
- * the other fields.
138
- * @example
139
- * ```ts
140
- * const market = client.marketV1(marketParams, 1);
141
- * const positionData = await market.getPositionData(borrower);
142
- * const { buildTx } = market.borrow({
143
- * userAddress: borrower,
144
- * amount: 1_000_000n,
145
- * positionData,
146
- * });
147
- * const tx = buildTx();
148
- * ```
149
- */
150
- marketV1(marketParams, chainId) {
151
- const derivedId = MarketUtils.getMarketId(marketParams);
152
- // Can happen with one-time/hardcoded/agent-written possibly inconsistent input market params.
153
- if (marketParams.id !== derivedId) {
154
- throw new MarketIdMismatchError(marketParams.id, derivedId);
155
- }
156
- return new MorphoMarketV1(this, marketParams, chainId);
157
- }
158
- }
@@ -1 +0,0 @@
1
- export * from "./marketV1.js";
@@ -1 +0,0 @@
1
- export * from "./marketV1.js";