@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,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";
File without changes
File without changes
File without changes
File without changes