@morpho-org/morpho-sdk 8.2.0 → 9.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/MIGRATION-v8-to-v9.md +54 -0
- package/README.md +14 -8
- package/lib/cjs/actions/bundles/common.d.ts +4 -7
- package/lib/cjs/actions/bundles/common.js +8 -14
- package/lib/cjs/actions/bundles/resolveBundlesTokenRequirements.d.ts +1 -5
- package/lib/cjs/actions/bundles/resolveBundlesTokenRequirements.js +1 -8
- package/lib/cjs/actions/midnight/authorization.d.ts +3 -1
- package/lib/cjs/actions/midnight/authorization.js +11 -1
- package/lib/cjs/actions/midnight/cancelAndMake.d.ts +2 -0
- package/lib/cjs/actions/midnight/cancelAndMake.js +10 -2
- package/lib/cjs/actions/midnight/redeem.d.ts +4 -1
- package/lib/cjs/actions/midnight/redeem.js +13 -3
- package/lib/cjs/actions/midnight/repayWithdrawCollateral.d.ts +1 -0
- package/lib/cjs/actions/midnight/repayWithdrawCollateral.js +7 -3
- package/lib/cjs/actions/midnight/supplyCollateral.d.ts +5 -1
- package/lib/cjs/actions/midnight/supplyCollateral.js +14 -3
- package/lib/cjs/actions/midnight/supplyCollateralTakeBorrow.d.ts +3 -1
- package/lib/cjs/actions/midnight/supplyCollateralTakeBorrow.js +9 -3
- package/lib/cjs/actions/midnight/takeBorrow.d.ts +3 -1
- package/lib/cjs/actions/midnight/takeBorrow.js +9 -3
- package/lib/cjs/actions/midnight/takeLend.d.ts +1 -0
- package/lib/cjs/actions/midnight/takeLend.js +7 -2
- package/lib/cjs/actions/midnight/takeRepayWithdrawCollateral.d.ts +1 -0
- package/lib/cjs/actions/midnight/takeRepayWithdrawCollateral.js +8 -2
- package/lib/cjs/actions/midnight/takeWithdraw.d.ts +3 -1
- package/lib/cjs/actions/midnight/takeWithdraw.js +10 -3
- package/lib/cjs/actions/requirements/encode/encodeVaultSharesPermit.d.ts +1 -5
- package/lib/cjs/actions/requirements/encode/encodeVaultSharesPermit.js +5 -7
- package/lib/cjs/actions/requirements/getRequirementsApproval.d.ts +7 -11
- package/lib/cjs/actions/requirements/getRequirementsApproval.js +8 -15
- package/lib/cjs/actions/requirements/midnight/getMidnightApprovalRequirements.d.ts +5 -10
- package/lib/cjs/actions/requirements/midnight/getMidnightApprovalRequirements.js +11 -8
- package/lib/cjs/actions/requirements/midnight/getMidnightAuthorizationRequirement.d.ts +2 -0
- package/lib/cjs/actions/requirements/midnight/getMidnightAuthorizationRequirement.js +5 -0
- package/lib/cjs/actions/vaultV1/inKindRedeem.d.ts +1 -1
- package/lib/cjs/actions/vaultV1/inKindRedeem.js +1 -1
- package/lib/cjs/actions/vaultV1/withdraw.d.ts +4 -4
- package/lib/cjs/actions/vaultV1/withdraw.js +4 -4
- package/lib/cjs/actions/vaultV2/forceWithdraw.d.ts +1 -1
- package/lib/cjs/actions/vaultV2/forceWithdraw.js +1 -1
- package/lib/cjs/actions/vaultV2/inKindRedeem.d.ts +1 -1
- package/lib/cjs/actions/vaultV2/inKindRedeem.js +1 -1
- package/lib/cjs/actions/vaultV2/withdraw.d.ts +4 -4
- package/lib/cjs/actions/vaultV2/withdraw.js +4 -4
- package/lib/cjs/entities/blue/blue.d.ts +2 -12
- package/lib/cjs/entities/blue/blue.js +0 -4
- package/lib/cjs/entities/midnight/midnight.d.ts +58 -17
- package/lib/cjs/entities/midnight/midnight.js +133 -52
- package/lib/cjs/entities/midnight/types.d.ts +2 -9
- package/lib/cjs/entities/requirements/getBundlesTokenRequirements.d.ts +0 -4
- package/lib/cjs/entities/requirements/getBundlesTokenRequirements.js +0 -7
- package/lib/cjs/entities/requirements/getVaultBundlesSharesRequirements.d.ts +5 -14
- package/lib/cjs/entities/requirements/getVaultBundlesSharesRequirements.js +8 -20
- package/lib/cjs/entities/vaultV1/vaultV1.d.ts +40 -37
- package/lib/cjs/entities/vaultV1/vaultV1.js +5 -34
- package/lib/cjs/entities/vaultV2/vaultV2.d.ts +36 -34
- package/lib/cjs/entities/vaultV2/vaultV2.js +8 -34
- package/lib/cjs/helpers/encodeMidnightCalldata.d.ts +48 -0
- package/lib/cjs/helpers/encodeMidnightCalldata.js +74 -0
- package/lib/cjs/helpers/slippage.d.ts +9 -25
- package/lib/cjs/helpers/slippage.js +10 -27
- package/lib/cjs/helpers/validate.d.ts +1 -0
- package/lib/cjs/helpers/validate.js +5 -0
- package/lib/cjs/helpers/validateMidnightAccount.d.ts +34 -0
- package/lib/cjs/helpers/validateMidnightAccount.js +47 -0
- package/lib/cjs/helpers/validateMidnightAuthorizationTarget.d.ts +1 -0
- package/lib/cjs/helpers/validateMidnightAuthorizationTarget.js +4 -0
- package/lib/cjs/helpers/validateMidnightMarket.d.ts +2 -0
- package/lib/cjs/helpers/validateMidnightMarket.js +5 -0
- package/lib/cjs/helpers/validateMidnightPublication.d.ts +11 -0
- package/lib/cjs/helpers/validateMidnightPublication.js +12 -1
- package/lib/cjs/helpers/validateMidnightReceiver.d.ts +1 -0
- package/lib/cjs/helpers/validateMidnightReceiver.js +8 -0
- package/lib/cjs/helpers/validateTakeableOffers.d.ts +2 -1
- package/lib/cjs/helpers/validateTakeableOffers.js +4 -3
- package/lib/cjs/types/action.d.ts +3 -1
- package/lib/cjs/types/error.d.ts +64 -5
- package/lib/cjs/types/error.js +152 -10
- package/lib/esm/actions/bundles/common.d.ts +4 -7
- package/lib/esm/actions/bundles/common.js +8 -14
- package/lib/esm/actions/bundles/resolveBundlesTokenRequirements.d.ts +1 -5
- package/lib/esm/actions/bundles/resolveBundlesTokenRequirements.js +2 -9
- package/lib/esm/actions/midnight/authorization.d.ts +3 -1
- package/lib/esm/actions/midnight/authorization.js +12 -2
- package/lib/esm/actions/midnight/cancelAndMake.d.ts +2 -0
- package/lib/esm/actions/midnight/cancelAndMake.js +11 -3
- package/lib/esm/actions/midnight/redeem.d.ts +4 -1
- package/lib/esm/actions/midnight/redeem.js +15 -5
- package/lib/esm/actions/midnight/repayWithdrawCollateral.d.ts +1 -0
- package/lib/esm/actions/midnight/repayWithdrawCollateral.js +8 -4
- package/lib/esm/actions/midnight/supplyCollateral.d.ts +5 -1
- package/lib/esm/actions/midnight/supplyCollateral.js +16 -5
- package/lib/esm/actions/midnight/supplyCollateralTakeBorrow.d.ts +3 -1
- package/lib/esm/actions/midnight/supplyCollateralTakeBorrow.js +10 -4
- package/lib/esm/actions/midnight/takeBorrow.d.ts +3 -1
- package/lib/esm/actions/midnight/takeBorrow.js +10 -4
- package/lib/esm/actions/midnight/takeLend.d.ts +1 -0
- package/lib/esm/actions/midnight/takeLend.js +8 -3
- package/lib/esm/actions/midnight/takeRepayWithdrawCollateral.d.ts +1 -0
- package/lib/esm/actions/midnight/takeRepayWithdrawCollateral.js +9 -3
- package/lib/esm/actions/midnight/takeWithdraw.d.ts +3 -1
- package/lib/esm/actions/midnight/takeWithdraw.js +11 -4
- package/lib/esm/actions/requirements/encode/encodeVaultSharesPermit.d.ts +1 -5
- package/lib/esm/actions/requirements/encode/encodeVaultSharesPermit.js +6 -8
- package/lib/esm/actions/requirements/getRequirementsApproval.d.ts +7 -11
- package/lib/esm/actions/requirements/getRequirementsApproval.js +9 -16
- package/lib/esm/actions/requirements/midnight/getMidnightApprovalRequirements.d.ts +5 -10
- package/lib/esm/actions/requirements/midnight/getMidnightApprovalRequirements.js +12 -9
- package/lib/esm/actions/requirements/midnight/getMidnightAuthorizationRequirement.d.ts +2 -0
- package/lib/esm/actions/requirements/midnight/getMidnightAuthorizationRequirement.js +5 -0
- package/lib/esm/actions/vaultV1/inKindRedeem.d.ts +1 -1
- package/lib/esm/actions/vaultV1/inKindRedeem.js +1 -1
- package/lib/esm/actions/vaultV1/withdraw.d.ts +4 -4
- package/lib/esm/actions/vaultV1/withdraw.js +4 -4
- package/lib/esm/actions/vaultV2/forceWithdraw.d.ts +1 -1
- package/lib/esm/actions/vaultV2/forceWithdraw.js +1 -1
- package/lib/esm/actions/vaultV2/inKindRedeem.d.ts +1 -1
- package/lib/esm/actions/vaultV2/inKindRedeem.js +1 -1
- package/lib/esm/actions/vaultV2/withdraw.d.ts +4 -4
- package/lib/esm/actions/vaultV2/withdraw.js +4 -4
- package/lib/esm/entities/blue/blue.d.ts +2 -12
- package/lib/esm/entities/blue/blue.js +0 -4
- package/lib/esm/entities/midnight/midnight.d.ts +58 -17
- package/lib/esm/entities/midnight/midnight.js +134 -53
- package/lib/esm/entities/midnight/types.d.ts +2 -9
- package/lib/esm/entities/requirements/getBundlesTokenRequirements.d.ts +0 -4
- package/lib/esm/entities/requirements/getBundlesTokenRequirements.js +1 -8
- package/lib/esm/entities/requirements/getVaultBundlesSharesRequirements.d.ts +5 -14
- package/lib/esm/entities/requirements/getVaultBundlesSharesRequirements.js +9 -21
- package/lib/esm/entities/vaultV1/vaultV1.d.ts +40 -37
- package/lib/esm/entities/vaultV1/vaultV1.js +6 -35
- package/lib/esm/entities/vaultV2/vaultV2.d.ts +36 -34
- package/lib/esm/entities/vaultV2/vaultV2.js +8 -34
- package/lib/esm/helpers/encodeMidnightCalldata.d.ts +48 -0
- package/lib/esm/helpers/encodeMidnightCalldata.js +69 -0
- package/lib/esm/helpers/slippage.d.ts +9 -25
- package/lib/esm/helpers/slippage.js +9 -25
- package/lib/esm/helpers/validate.d.ts +1 -0
- package/lib/esm/helpers/validate.js +5 -0
- package/lib/esm/helpers/validateMidnightAccount.d.ts +34 -0
- package/lib/esm/helpers/validateMidnightAccount.js +43 -0
- package/lib/esm/helpers/validateMidnightAuthorizationTarget.d.ts +1 -0
- package/lib/esm/helpers/validateMidnightAuthorizationTarget.js +4 -0
- package/lib/esm/helpers/validateMidnightMarket.d.ts +2 -0
- package/lib/esm/helpers/validateMidnightMarket.js +5 -0
- package/lib/esm/helpers/validateMidnightPublication.d.ts +11 -0
- package/lib/esm/helpers/validateMidnightPublication.js +10 -0
- package/lib/esm/helpers/validateMidnightReceiver.d.ts +1 -0
- package/lib/esm/helpers/validateMidnightReceiver.js +8 -0
- package/lib/esm/helpers/validateTakeableOffers.d.ts +2 -1
- package/lib/esm/helpers/validateTakeableOffers.js +4 -3
- package/lib/esm/types/action.d.ts +3 -1
- package/lib/esm/types/error.d.ts +64 -5
- package/lib/esm/types/error.js +146 -6
- package/package.json +6 -5
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.validateTakeableOffers = void 0;
|
|
4
|
-
const midnight_sdk_1 = require("@morpho-org/midnight-sdk");
|
|
5
4
|
const index_js_1 = require("../types/index.js");
|
|
5
|
+
const encodeMidnightCalldata_js_1 = require("./encodeMidnightCalldata.js");
|
|
6
6
|
const validateOfferSides_js_1 = require("./validateOfferSides.js");
|
|
7
7
|
/**
|
|
8
8
|
* Validates the pure invariants shared by Midnight take entity and action layers.
|
|
@@ -12,16 +12,17 @@ const validateOfferSides_js_1 = require("./validateOfferSides.js");
|
|
|
12
12
|
* @throws {EmptyMidnightTakeableOffersError} when no offers are provided.
|
|
13
13
|
* @throws {MidnightOfferSideMismatchError} when an offer has the wrong maker side.
|
|
14
14
|
* @throws {MidnightTakeableOfferMarketMismatchError} when an offer belongs to another market.
|
|
15
|
+
* @throws {MidnightCalldataEncodingError} when a market cannot be ABI-encoded.
|
|
15
16
|
* @internal
|
|
16
17
|
*/
|
|
17
18
|
const validateTakeableOffers = (params) => {
|
|
18
19
|
if (params.takeableOffers.length === 0) {
|
|
19
20
|
throw new index_js_1.EmptyMidnightTakeableOffersError();
|
|
20
21
|
}
|
|
21
|
-
const marketId =
|
|
22
|
+
const marketId = (0, encodeMidnightCalldata_js_1.encodeMidnightMarketId)(params.market);
|
|
22
23
|
(0, validateOfferSides_js_1.validateOfferSides)(params.takeableOffers.map((take) => take.offer), params.expectedBuy);
|
|
23
24
|
for (const [index, take] of params.takeableOffers.entries()) {
|
|
24
|
-
const actualMarketId =
|
|
25
|
+
const actualMarketId = (0, encodeMidnightCalldata_js_1.encodeMidnightMarketId)(take.offer.market);
|
|
25
26
|
if (actualMarketId.toLowerCase() !== marketId.toLowerCase()) {
|
|
26
27
|
throw new index_js_1.MidnightTakeableOfferMarketMismatchError({
|
|
27
28
|
index,
|
|
@@ -37,7 +37,7 @@ export type MidnightBuyTarget = {
|
|
|
37
37
|
*/
|
|
38
38
|
export type MidnightSellTarget = {
|
|
39
39
|
readonly type: "assets";
|
|
40
|
-
/**
|
|
40
|
+
/** Exact loan assets paid to `receiver`; any referral fee is sold on top of this amount. */
|
|
41
41
|
readonly assets: bigint;
|
|
42
42
|
readonly maxUnits: bigint;
|
|
43
43
|
} | {
|
|
@@ -491,6 +491,8 @@ export interface MidnightCancelAndMakeAction extends BaseAction<"midnightCancelA
|
|
|
491
491
|
readonly cancellations: readonly MidnightGroupCancellation[];
|
|
492
492
|
readonly collateralSupplies: readonly MidnightCollateralTransfer[];
|
|
493
493
|
readonly blueSupply?: MidnightBlueSupply;
|
|
494
|
+
/** Native ETH wrapped into wNative to fund this bundle. */
|
|
495
|
+
readonly nativeAmount?: bigint;
|
|
494
496
|
readonly deadline: bigint;
|
|
495
497
|
}> {
|
|
496
498
|
}
|
package/lib/cjs/types/error.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { type MarketId, UnknownDataError } from "@morpho-org/blue-sdk";
|
|
2
2
|
import type { AddressLabel } from "@morpho-org/morpho-ts";
|
|
3
|
-
import type { Address, Hash, Hex } from "viem";
|
|
3
|
+
import type { Address, BaseError, Hash, Hex } from "viem";
|
|
4
4
|
/**
|
|
5
5
|
* Thrown when a morpho-sdk input that must be non-negative is negative.
|
|
6
6
|
*
|
|
@@ -713,10 +713,6 @@ export declare class CryptoUnavailableError extends Error {
|
|
|
713
713
|
export declare class MissingClientPropertyError extends Error {
|
|
714
714
|
constructor(property: string);
|
|
715
715
|
}
|
|
716
|
-
/** Thrown when an approval amount is smaller than the spend amount it must cover. */
|
|
717
|
-
export declare class ApprovalAmountLessThanSpendAmountError extends Error {
|
|
718
|
-
constructor();
|
|
719
|
-
}
|
|
720
716
|
/** Thrown when a requirement encoder targets an unsupported spender. */
|
|
721
717
|
export declare class UnsupportedErc20ApprovalSpenderError extends Error {
|
|
722
718
|
constructor(params: {
|
|
@@ -1220,6 +1216,14 @@ export declare class MidnightZeroReceiverError extends Error {
|
|
|
1220
1216
|
*/
|
|
1221
1217
|
constructor(field: "receiver" | "collateralReceiver");
|
|
1222
1218
|
}
|
|
1219
|
+
/** Thrown when a Midnight flow uses the zero address as the account it acts for. */
|
|
1220
|
+
export declare class MidnightZeroOnBehalfError extends Error {
|
|
1221
|
+
readonly field: "onBehalf";
|
|
1222
|
+
/**
|
|
1223
|
+
* @param field - Account field containing the zero address.
|
|
1224
|
+
*/
|
|
1225
|
+
constructor(field: "onBehalf");
|
|
1226
|
+
}
|
|
1223
1227
|
/**
|
|
1224
1228
|
* Thrown when a Midnight receiver is a Midnight protocol or market token contract that cannot
|
|
1225
1229
|
* forward received assets.
|
|
@@ -1488,3 +1492,58 @@ export declare class MissingContractCodeError extends Error {
|
|
|
1488
1492
|
*/
|
|
1489
1493
|
constructor(address: Address, chainId: number, role: AddressLabel);
|
|
1490
1494
|
}
|
|
1495
|
+
/**
|
|
1496
|
+
* Thrown when a Midnight flow is prepared for the zero address. Midnight would revert
|
|
1497
|
+
* `Unauthorized()`, and requirements resolved for the zero address can never be sent.
|
|
1498
|
+
*
|
|
1499
|
+
* @example
|
|
1500
|
+
* ```ts
|
|
1501
|
+
* import { MidnightZeroAccountError } from "@morpho-org/morpho-sdk";
|
|
1502
|
+
*
|
|
1503
|
+
* const error = new MidnightZeroAccountError("accountAddress");
|
|
1504
|
+
* // error.field === "accountAddress"
|
|
1505
|
+
* ```
|
|
1506
|
+
*/
|
|
1507
|
+
export declare class MidnightZeroAccountError extends Error {
|
|
1508
|
+
readonly field: "accountAddress" | "owner";
|
|
1509
|
+
/**
|
|
1510
|
+
* @param field - Account field containing the zero address: `accountAddress` for an entity
|
|
1511
|
+
* method, `owner` for a requirement helper. A zero `onBehalf` on a direct Midnight call throws
|
|
1512
|
+
* {@link MidnightZeroOnBehalfError} instead.
|
|
1513
|
+
*/
|
|
1514
|
+
constructor(field: "accountAddress" | "owner");
|
|
1515
|
+
}
|
|
1516
|
+
/**
|
|
1517
|
+
* Thrown when a Midnight builder or `MorphoMidnight` method cannot ABI-encode its calldata,
|
|
1518
|
+
* offer tree or market id, for example a `bytes32` field that is not 32 bytes, an integer
|
|
1519
|
+
* outside its Solidity type or a malformed address. Wraps the viem error as `cause`.
|
|
1520
|
+
*
|
|
1521
|
+
* @example
|
|
1522
|
+
* ```ts
|
|
1523
|
+
* import { MidnightCalldataEncodingError } from "@morpho-org/morpho-sdk";
|
|
1524
|
+
* import { BaseError } from "viem";
|
|
1525
|
+
*
|
|
1526
|
+
* const error = new MidnightCalldataEncodingError(
|
|
1527
|
+
* "midnightBundlesV2CancelAndMake",
|
|
1528
|
+
* new BaseError("bad bytes32"),
|
|
1529
|
+
* );
|
|
1530
|
+
* // error.input === "midnightBundlesV2CancelAndMake"
|
|
1531
|
+
* ```
|
|
1532
|
+
*/
|
|
1533
|
+
export declare class MidnightCalldataEncodingError extends Error {
|
|
1534
|
+
readonly input: string;
|
|
1535
|
+
readonly cause: BaseError;
|
|
1536
|
+
/**
|
|
1537
|
+
* @param input - Input that could not be encoded: the contract function whose calldata
|
|
1538
|
+
* failed, `"offers"` for offer-tree hashing, `"marketId"` for market-id hashing, or the name
|
|
1539
|
+
* of the malformed address input, such as `"accountAddress"`, `"onBehalf"`, `"owner"`,
|
|
1540
|
+
* `"receiver"`, `"collateralReceiver"`, `"referralFeeRecipient"`, `"market.midnight"`,
|
|
1541
|
+
* `"authorized"`, `"publication.ratifier"`, `"loanToken"`, `"market.loanToken"`,
|
|
1542
|
+
* `"market.collateralParams[i].token"`, `"positionData.user"`, `"spender"` or `"token"` (a token
|
|
1543
|
+
* pulled with native funding, or the token checked by
|
|
1544
|
+
* `getMidnightApprovalRequirements`). `"blueMarket"` reports the Blue market encoding in
|
|
1545
|
+
* `supplyBlueMakeLend`: a malformed address or an out-of-range `lltv`.
|
|
1546
|
+
* @param cause - viem encoding error.
|
|
1547
|
+
*/
|
|
1548
|
+
constructor(input: string, cause: BaseError);
|
|
1549
|
+
}
|