@morpho-org/morpho-sdk 1.2.1 → 2.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.
- package/README.md +12 -11
- package/lib/cjs/actions/marketV1/repay.js +1 -1
- package/lib/cjs/actions/marketV1/repayWithdrawCollateral.js +1 -1
- package/lib/cjs/actions/marketV1/supplyCollateral.js +1 -1
- package/lib/cjs/actions/marketV1/supplyCollateralBorrow.js +1 -1
- package/lib/cjs/actions/requirements/encode/encodeErc20Permit.js +4 -7
- package/lib/cjs/actions/requirements/encode/encodeErc20Permit2.js +4 -7
- package/lib/cjs/actions/requirements/getRequirementsAction.d.ts +5 -5
- package/lib/cjs/actions/requirements/getRequirementsAction.js +6 -8
- package/lib/cjs/actions/vaultV1/deposit.js +1 -1
- package/lib/cjs/actions/vaultV1/migrateToV2.js +1 -1
- package/lib/cjs/actions/vaultV2/deposit.js +1 -1
- package/lib/cjs/actions/vaultV2/forceWithdraw.js +5 -4
- package/lib/cjs/client/morphoClient.d.ts +48 -9
- package/lib/cjs/client/morphoClient.js +48 -9
- package/lib/cjs/client/morphoViemExtension.d.ts +2 -2
- package/lib/cjs/client/morphoViemExtension.js +2 -2
- package/lib/cjs/entities/marketV1/marketV1.js +0 -6
- package/lib/cjs/entities/vaultV1/vaultV1.d.ts +6 -6
- package/lib/cjs/entities/vaultV1/vaultV1.js +8 -9
- package/lib/cjs/entities/vaultV2/vaultV2.d.ts +5 -5
- package/lib/cjs/entities/vaultV2/vaultV2.js +8 -8
- package/lib/cjs/helpers/computeReallocations.d.ts +1 -0
- package/lib/cjs/helpers/computeReallocations.js +15 -0
- package/lib/cjs/helpers/validate.d.ts +10 -6
- package/lib/cjs/helpers/validate.js +13 -9
- package/lib/cjs/types/action.d.ts +3 -3
- package/lib/cjs/types/error.d.ts +20 -0
- package/lib/cjs/types/error.js +16 -1
- package/lib/esm/actions/marketV1/repay.js +1 -1
- package/lib/esm/actions/marketV1/repayWithdrawCollateral.js +1 -1
- package/lib/esm/actions/marketV1/supplyCollateral.js +1 -1
- package/lib/esm/actions/marketV1/supplyCollateralBorrow.js +1 -1
- package/lib/esm/actions/requirements/encode/encodeErc20Permit.js +5 -8
- package/lib/esm/actions/requirements/encode/encodeErc20Permit2.js +5 -8
- package/lib/esm/actions/requirements/getRequirementsAction.d.ts +5 -5
- package/lib/esm/actions/requirements/getRequirementsAction.js +6 -8
- package/lib/esm/actions/vaultV1/deposit.js +1 -1
- package/lib/esm/actions/vaultV1/migrateToV2.js +1 -1
- package/lib/esm/actions/vaultV2/deposit.js +1 -1
- package/lib/esm/actions/vaultV2/forceWithdraw.js +5 -4
- package/lib/esm/client/morphoClient.d.ts +48 -9
- package/lib/esm/client/morphoClient.js +48 -9
- package/lib/esm/client/morphoViemExtension.d.ts +2 -2
- package/lib/esm/client/morphoViemExtension.js +2 -2
- package/lib/esm/entities/marketV1/marketV1.js +1 -7
- package/lib/esm/entities/vaultV1/vaultV1.d.ts +6 -6
- package/lib/esm/entities/vaultV1/vaultV1.js +9 -10
- package/lib/esm/entities/vaultV2/vaultV2.d.ts +5 -5
- package/lib/esm/entities/vaultV2/vaultV2.js +8 -8
- package/lib/esm/helpers/computeReallocations.d.ts +1 -0
- package/lib/esm/helpers/computeReallocations.js +16 -1
- package/lib/esm/helpers/validate.d.ts +10 -6
- package/lib/esm/helpers/validate.js +11 -7
- package/lib/esm/types/action.d.ts +3 -3
- package/lib/esm/types/error.d.ts +20 -0
- package/lib/esm/types/error.js +14 -0
- package/package.json +11 -11
|
@@ -4,13 +4,17 @@ import { isAddressEqual } from "viem";
|
|
|
4
4
|
import { AccrualPositionUserMismatchError, AddressMismatchError, BorrowExceedsSafeLtvError, ChainIdMismatchError, ChainWNativeMissingError, EmptyReallocationWithdrawalsError, ExcessiveSlippageToleranceError, MarketIdMismatchError, MissingClientPropertyError, MissingMarketPriceError, MutuallyExclusiveRepayAmountsError, NativeAmountOnNonWNativeCollateralError, NegativeReallocationFeeError, NegativeSlippageToleranceError, NonPositiveReallocationAmountError, NonPositiveRepayAmountError, NonPositiveRepayMaxSharePriceError, NonPositiveTransferAmountError, ReallocationWithdrawalOnTargetMarketError, RepayExceedsDebtError, RepaySharesExceedDebtError, TransferAmountNotEqualToAssetsError, UnsortedReallocationWithdrawalsError, WithdrawExceedsCollateralError, WithdrawMakesPositionUnhealthyError, } from "../types/index.js";
|
|
5
5
|
import { DEFAULT_LLTV_BUFFER, MAX_SLIPPAGE_TOLERANCE } from "./constant.js";
|
|
6
6
|
/**
|
|
7
|
-
*
|
|
7
|
+
* Asserts that the client has a connected account AND that it matches
|
|
8
8
|
* the provided user address.
|
|
9
9
|
*
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
*
|
|
13
|
-
*
|
|
10
|
+
* Used internally by the signature requirements (`encodeErc20Permit`,
|
|
11
|
+
* `encodeErc20Permit2`) to enforce builder = signer at `sign()` time:
|
|
12
|
+
* the signing flow is the only path where an account/address mismatch
|
|
13
|
+
* is a real security concern (rather than just an integrator footgun).
|
|
14
|
+
*
|
|
15
|
+
* Transaction builders no longer call this helper — callers are
|
|
16
|
+
* responsible for keeping `userAddress` aligned with the signing account
|
|
17
|
+
* at the builder layer.
|
|
14
18
|
*
|
|
15
19
|
* Throws {@link MissingClientPropertyError} if the client has no account.
|
|
16
20
|
* Throws {@link AddressMismatchError} if the client account differs from
|
|
@@ -20,14 +24,14 @@ import { DEFAULT_LLTV_BUFFER, MAX_SLIPPAGE_TOLERANCE } from "./constant.js";
|
|
|
20
24
|
* `MissingClientPropertyError` is thrown.
|
|
21
25
|
* @param userAddress - The user address provided by the caller.
|
|
22
26
|
*/
|
|
23
|
-
export
|
|
27
|
+
export function validateUserAddress(clientAccountAddress, userAddress) {
|
|
24
28
|
if (clientAccountAddress === undefined) {
|
|
25
29
|
throw new MissingClientPropertyError("account");
|
|
26
30
|
}
|
|
27
31
|
if (!isAddressEqual(clientAccountAddress, userAddress)) {
|
|
28
32
|
throw new AddressMismatchError(clientAccountAddress, userAddress);
|
|
29
33
|
}
|
|
30
|
-
}
|
|
34
|
+
}
|
|
31
35
|
/**
|
|
32
36
|
* Validates that the accrual position belongs to the expected market and user.
|
|
33
37
|
* Throws {@link MarketIdMismatchError} if the position's market ID
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { Address,
|
|
1
|
+
import type { Address, Hex, WalletClient } from "viem";
|
|
2
2
|
import type { Deallocation } from "./deallocation.js";
|
|
3
3
|
export interface BaseAction<TType extends string = string, TArgs extends Record<string, unknown> = Record<string, unknown>> {
|
|
4
4
|
readonly type: TType;
|
|
@@ -10,7 +10,7 @@ export interface ERC20ApprovalAction extends BaseAction<"erc20Approval", {
|
|
|
10
10
|
}> {
|
|
11
11
|
}
|
|
12
12
|
export interface ERC20PermitAction {
|
|
13
|
-
sign: (client:
|
|
13
|
+
sign: (client: WalletClient, userAddress: Address) => Promise<Hex>;
|
|
14
14
|
}
|
|
15
15
|
export interface VaultV2DepositAction extends BaseAction<"vaultV2Deposit", {
|
|
16
16
|
vault: Address;
|
|
@@ -191,7 +191,7 @@ export interface Permit2Args {
|
|
|
191
191
|
expiration: bigint;
|
|
192
192
|
}
|
|
193
193
|
export interface Requirement {
|
|
194
|
-
sign: (client:
|
|
194
|
+
sign: (client: WalletClient, userAddress: Address) => Promise<RequirementSignature>;
|
|
195
195
|
action: PermitAction | Permit2Action;
|
|
196
196
|
}
|
|
197
197
|
export interface PermitAction extends BaseAction<"permit", {
|
package/lib/esm/types/error.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { MarketId } from "@morpho-org/blue-sdk";
|
|
1
2
|
import type { Address } from "viem";
|
|
2
3
|
/** Thrown when an asset amount is required to be positive but is zero or negative. */
|
|
3
4
|
export declare class NonPositiveAssetAmountError extends Error {
|
|
@@ -191,6 +192,25 @@ export declare class RepaySharesExceedDebtError extends Error {
|
|
|
191
192
|
export declare class MissingPublicAllocatorConfigError extends Error {
|
|
192
193
|
constructor(vault: string);
|
|
193
194
|
}
|
|
195
|
+
/**
|
|
196
|
+
* Thrown when shared liquidity selected by `computeReallocations` cannot cover
|
|
197
|
+
* the absolute borrow shortfall on the target market — the resulting
|
|
198
|
+
* `morphoBorrow` would still revert onchain.
|
|
199
|
+
*
|
|
200
|
+
* Pattern-match on the class and inspect `params` to surface the gap to users.
|
|
201
|
+
*/
|
|
202
|
+
export declare class InsufficientSharedLiquidityError extends Error {
|
|
203
|
+
readonly params: {
|
|
204
|
+
readonly marketId: MarketId;
|
|
205
|
+
readonly shortfall: bigint;
|
|
206
|
+
readonly available: bigint;
|
|
207
|
+
};
|
|
208
|
+
constructor(params: {
|
|
209
|
+
readonly marketId: MarketId;
|
|
210
|
+
readonly shortfall: bigint;
|
|
211
|
+
readonly available: bigint;
|
|
212
|
+
});
|
|
213
|
+
}
|
|
194
214
|
/** Thrown when a market borrow's `minSharePrice` slippage bound is negative. */
|
|
195
215
|
export declare class NonPositiveMinBorrowSharePriceError extends Error {
|
|
196
216
|
constructor(market: string);
|
package/lib/esm/types/error.js
CHANGED
|
@@ -256,6 +256,20 @@ export class MissingPublicAllocatorConfigError extends Error {
|
|
|
256
256
|
super(`Vault ${vault} has no public allocator configured but was selected for reallocation`);
|
|
257
257
|
}
|
|
258
258
|
}
|
|
259
|
+
/**
|
|
260
|
+
* Thrown when shared liquidity selected by `computeReallocations` cannot cover
|
|
261
|
+
* the absolute borrow shortfall on the target market — the resulting
|
|
262
|
+
* `morphoBorrow` would still revert onchain.
|
|
263
|
+
*
|
|
264
|
+
* Pattern-match on the class and inspect `params` to surface the gap to users.
|
|
265
|
+
*/
|
|
266
|
+
export class InsufficientSharedLiquidityError extends Error {
|
|
267
|
+
params;
|
|
268
|
+
constructor(params) {
|
|
269
|
+
super(`Shared liquidity is insufficient to cover the borrow on market ${params.marketId}: shortfall "${params.shortfall}", available "${params.available}". Reduce the borrow amount or wait for additional vault liquidity.`);
|
|
270
|
+
this.params = params;
|
|
271
|
+
}
|
|
272
|
+
}
|
|
259
273
|
/** Thrown when a market borrow's `minSharePrice` slippage bound is negative. */
|
|
260
274
|
export class NonPositiveMinBorrowSharePriceError extends Error {
|
|
261
275
|
constructor(market) {
|
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": "
|
|
4
|
+
"version": "2.0.0",
|
|
5
5
|
"author": "Morpho Association <contact@morpho.org>",
|
|
6
6
|
"contributors": [
|
|
7
7
|
"Foulks-Plb <https://x.com/FoulkPlb>"
|
|
@@ -19,22 +19,22 @@
|
|
|
19
19
|
"lib"
|
|
20
20
|
],
|
|
21
21
|
"dependencies": {
|
|
22
|
-
"zod": "^4.
|
|
23
|
-
"@morpho-org/blue-sdk": "^5.23.
|
|
24
|
-
"@morpho-org/blue-sdk-viem": "^4.6.5",
|
|
22
|
+
"zod": "^4.4.3",
|
|
23
|
+
"@morpho-org/blue-sdk": "^5.23.3",
|
|
25
24
|
"@morpho-org/bundler-sdk-viem": "^4.3.3",
|
|
26
|
-
"@morpho-org/
|
|
27
|
-
"@morpho-org/
|
|
25
|
+
"@morpho-org/morpho-ts": "^2.5.1",
|
|
26
|
+
"@morpho-org/simulation-sdk": "^3.4.4",
|
|
27
|
+
"@morpho-org/blue-sdk-viem": "^4.6.6"
|
|
28
28
|
},
|
|
29
29
|
"peerDependencies": {
|
|
30
30
|
"viem": "^2.0.0"
|
|
31
31
|
},
|
|
32
32
|
"devDependencies": {
|
|
33
|
-
"dotenv": "^
|
|
34
|
-
"typescript": "^
|
|
35
|
-
"viem": "^2.
|
|
36
|
-
"vitest": "^4.1.
|
|
37
|
-
"@morpho-org/test": "^2.7.
|
|
33
|
+
"dotenv": "^17.4.2",
|
|
34
|
+
"typescript": "^6.0.3",
|
|
35
|
+
"viem": "^2.49.3",
|
|
36
|
+
"vitest": "^4.1.6",
|
|
37
|
+
"@morpho-org/test": "^2.7.3"
|
|
38
38
|
},
|
|
39
39
|
"scripts": {
|
|
40
40
|
"prepublish": "$npm_execpath build",
|