@morpho-org/morpho-sdk 5.2.0 → 5.3.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 +46 -2
- package/lib/cjs/abis.d.ts +1 -0
- package/lib/cjs/abis.js +6 -1
- package/lib/cjs/actions/blue/borrow.d.ts +3 -7
- package/lib/cjs/actions/blue/borrow.js +5 -9
- package/lib/cjs/actions/blue/buildReallocationActions.d.ts +3 -4
- package/lib/cjs/actions/blue/buildReallocationActions.js +3 -4
- package/lib/cjs/actions/blue/refinance.d.ts +4 -8
- package/lib/cjs/actions/blue/refinance.js +10 -14
- package/lib/cjs/actions/blue/repay.d.ts +2 -5
- package/lib/cjs/actions/blue/repay.js +2 -5
- package/lib/cjs/actions/blue/repayWithdrawCollateral.d.ts +3 -6
- package/lib/cjs/actions/blue/repayWithdrawCollateral.js +4 -7
- package/lib/cjs/actions/blue/resolveRepayFunding.d.ts +2 -5
- package/lib/cjs/actions/blue/resolveRepayFunding.js +15 -12
- package/lib/cjs/actions/blue/supply.d.ts +2 -4
- package/lib/cjs/actions/blue/supply.js +6 -8
- package/lib/cjs/actions/blue/supplyCollateral.d.ts +2 -3
- package/lib/cjs/actions/blue/supplyCollateral.js +5 -6
- package/lib/cjs/actions/blue/supplyCollateralBorrow.d.ts +4 -9
- package/lib/cjs/actions/blue/supplyCollateralBorrow.js +9 -14
- package/lib/cjs/actions/blue/withdraw.d.ts +9 -7
- package/lib/cjs/actions/blue/withdraw.js +18 -10
- package/lib/cjs/actions/blue/withdrawCollateral.d.ts +1 -1
- package/lib/cjs/actions/blue/withdrawCollateral.js +2 -2
- package/lib/cjs/actions/index.d.ts +2 -0
- package/lib/cjs/actions/index.js +1 -0
- package/lib/cjs/actions/midnight/authorization.d.ts +37 -0
- package/lib/cjs/actions/midnight/authorization.js +69 -0
- package/lib/cjs/actions/midnight/cancelOffer.d.ts +38 -0
- package/lib/cjs/actions/midnight/cancelOffer.js +73 -0
- package/lib/cjs/actions/midnight/index.d.ts +11 -0
- package/lib/cjs/actions/midnight/index.js +27 -0
- package/lib/cjs/actions/midnight/mempoolSubmitOffers.d.ts +52 -0
- package/lib/cjs/actions/midnight/mempoolSubmitOffers.js +72 -0
- package/lib/cjs/actions/midnight/redeem.d.ts +43 -0
- package/lib/cjs/actions/midnight/redeem.js +79 -0
- package/lib/cjs/actions/midnight/repayWithdrawCollateral.d.ts +53 -0
- package/lib/cjs/actions/midnight/repayWithdrawCollateral.js +121 -0
- package/lib/cjs/actions/midnight/setterRatifierRatifyRoot.d.ts +40 -0
- package/lib/cjs/actions/midnight/setterRatifierRatifyRoot.js +59 -0
- package/lib/cjs/actions/midnight/supplyCollateral.d.ts +45 -0
- package/lib/cjs/actions/midnight/supplyCollateral.js +83 -0
- package/lib/cjs/actions/midnight/supplyCollateralTakeBorrow.d.ts +51 -0
- package/lib/cjs/actions/midnight/supplyCollateralTakeBorrow.js +128 -0
- package/lib/cjs/actions/midnight/takeBorrow.d.ts +57 -0
- package/lib/cjs/actions/midnight/takeBorrow.js +110 -0
- package/lib/cjs/actions/midnight/takeLend.d.ts +57 -0
- package/lib/cjs/actions/midnight/takeLend.js +110 -0
- package/lib/cjs/actions/midnight/types.d.ts +39 -0
- package/lib/cjs/actions/midnight/types.js +15 -0
- package/lib/cjs/actions/requirements/encode/encodeBlueSignatureAuthorization.d.ts +1 -1
- package/lib/cjs/actions/requirements/encode/encodeBlueSignatureAuthorization.js +5 -16
- package/lib/cjs/actions/requirements/encode/encodeErc20Approval.d.ts +5 -4
- package/lib/cjs/actions/requirements/encode/encodeErc20Approval.js +10 -14
- package/lib/cjs/actions/requirements/encode/encodeErc20Permit.d.ts +2 -2
- package/lib/cjs/actions/requirements/encode/encodeErc20Permit.js +11 -28
- package/lib/cjs/actions/requirements/encode/encodeErc20Permit2Approve.d.ts +1 -1
- package/lib/cjs/actions/requirements/encode/encodeErc20Permit2Approve.js +5 -17
- package/lib/cjs/actions/requirements/generalAdapter/getGeneralAdapterRequirementsPermit.d.ts +1 -1
- package/lib/cjs/actions/requirements/getRequirementsApproval.d.ts +10 -4
- package/lib/cjs/actions/requirements/getRequirementsApproval.js +10 -4
- package/lib/cjs/actions/requirements/index.d.ts +1 -0
- package/lib/cjs/actions/requirements/index.js +1 -0
- package/lib/cjs/actions/requirements/midnight/getMidnightApprovalRequirements.d.ts +49 -0
- package/lib/cjs/actions/requirements/midnight/getMidnightApprovalRequirements.js +76 -0
- package/lib/cjs/actions/requirements/midnight/getMidnightAuthorizationRequirement.d.ts +44 -0
- package/lib/cjs/actions/requirements/midnight/getMidnightAuthorizationRequirement.js +78 -0
- package/lib/cjs/actions/requirements/midnight/getSetterRatifierRatifyRootRequirement.d.ts +42 -0
- package/lib/cjs/actions/requirements/midnight/getSetterRatifierRatifyRootRequirement.js +70 -0
- package/lib/cjs/actions/requirements/midnight/index.d.ts +3 -0
- package/lib/cjs/actions/requirements/midnight/index.js +19 -0
- package/lib/cjs/actions/vaultV1/deposit.d.ts +3 -4
- package/lib/cjs/actions/vaultV1/deposit.js +7 -8
- package/lib/cjs/actions/vaultV1/migrateToV2.d.ts +2 -3
- package/lib/cjs/actions/vaultV1/migrateToV2.js +5 -6
- package/lib/cjs/actions/vaultV1/redeem.d.ts +1 -1
- package/lib/cjs/actions/vaultV1/redeem.js +2 -2
- package/lib/cjs/actions/vaultV1/withdraw.d.ts +1 -1
- package/lib/cjs/actions/vaultV1/withdraw.js +2 -2
- package/lib/cjs/actions/vaultV2/deposit.d.ts +3 -4
- package/lib/cjs/actions/vaultV2/deposit.js +7 -8
- package/lib/cjs/actions/vaultV2/forceRedeem.d.ts +2 -3
- package/lib/cjs/actions/vaultV2/forceRedeem.js +3 -4
- package/lib/cjs/actions/vaultV2/forceWithdraw.d.ts +1 -1
- package/lib/cjs/actions/vaultV2/forceWithdraw.js +2 -2
- package/lib/cjs/actions/vaultV2/redeem.d.ts +1 -1
- package/lib/cjs/actions/vaultV2/redeem.js +2 -2
- package/lib/cjs/actions/vaultV2/withdraw.d.ts +1 -1
- package/lib/cjs/actions/vaultV2/withdraw.js +2 -2
- package/lib/cjs/client/morphoViemExtension.d.ts +1 -1
- package/lib/cjs/client/morphoViemExtension.js +5 -2
- package/lib/cjs/constants.d.ts +1 -0
- package/lib/cjs/constants.js +15 -1
- package/lib/cjs/entities/blue/blue.d.ts +5 -5
- package/lib/cjs/entities/blue/blue.js +93 -68
- package/lib/cjs/entities/index.d.ts +1 -0
- package/lib/cjs/entities/index.js +15 -0
- package/lib/cjs/entities/midnight/index.d.ts +2 -0
- package/lib/cjs/entities/midnight/index.js +18 -0
- package/lib/cjs/entities/midnight/midnight.d.ts +402 -0
- package/lib/cjs/entities/midnight/midnight.js +1036 -0
- package/lib/cjs/entities/midnight/types.d.ts +164 -0
- package/lib/cjs/entities/midnight/types.js +2 -0
- package/lib/cjs/entities/vaultV1/vaultV1.js +10 -17
- package/lib/cjs/entities/vaultV2/vaultV2.js +19 -21
- package/lib/cjs/errors.d.ts +1 -0
- package/lib/cjs/errors.js +17 -1
- package/lib/cjs/helpers/encodeDeallocation.d.ts +1 -0
- package/lib/cjs/helpers/encodeDeallocation.js +2 -1
- package/lib/cjs/helpers/index.d.ts +4 -1
- package/lib/cjs/helpers/index.js +8 -1
- package/lib/cjs/helpers/signAndVerifyTypedData.d.ts +34 -0
- package/lib/cjs/helpers/signAndVerifyTypedData.js +58 -0
- package/lib/cjs/helpers/validate.d.ts +40 -1
- package/lib/cjs/helpers/validate.js +47 -5
- package/lib/cjs/helpers/validateMidnightAuthorizationTarget.d.ts +15 -0
- package/lib/cjs/helpers/validateMidnightAuthorizationTarget.js +32 -0
- package/lib/cjs/helpers/validateMidnightMarket.d.ts +10 -0
- package/lib/cjs/helpers/validateMidnightMarket.js +24 -0
- package/lib/cjs/helpers/validateOfferSides.d.ts +21 -0
- package/lib/cjs/helpers/validateOfferSides.js +36 -0
- package/lib/cjs/helpers/validateRequirementSpender.d.ts +29 -0
- package/lib/cjs/helpers/validateRequirementSpender.js +49 -0
- package/lib/cjs/helpers/validateTakeableOffers.d.ts +18 -0
- package/lib/cjs/helpers/validateTakeableOffers.js +35 -0
- package/lib/cjs/midnight-api.d.ts +1 -0
- package/lib/cjs/midnight-api.js +17 -0
- package/lib/cjs/types/action.d.ts +189 -23
- package/lib/cjs/types/action.js +27 -7
- package/lib/cjs/types/client.d.ts +3 -2
- package/lib/cjs/types/error.d.ts +288 -119
- package/lib/cjs/types/error.js +259 -180
- package/lib/cjs/utils.d.ts +1 -0
- package/lib/cjs/utils.js +12 -2
- package/lib/esm/abis.d.ts +1 -0
- package/lib/esm/abis.js +1 -0
- package/lib/esm/actions/blue/borrow.d.ts +3 -7
- package/lib/esm/actions/blue/borrow.js +6 -10
- package/lib/esm/actions/blue/buildReallocationActions.d.ts +3 -4
- package/lib/esm/actions/blue/buildReallocationActions.js +3 -4
- package/lib/esm/actions/blue/refinance.d.ts +4 -8
- package/lib/esm/actions/blue/refinance.js +11 -15
- package/lib/esm/actions/blue/repay.d.ts +2 -5
- package/lib/esm/actions/blue/repay.js +2 -5
- package/lib/esm/actions/blue/repayWithdrawCollateral.d.ts +3 -6
- package/lib/esm/actions/blue/repayWithdrawCollateral.js +5 -8
- package/lib/esm/actions/blue/resolveRepayFunding.d.ts +2 -5
- package/lib/esm/actions/blue/resolveRepayFunding.js +16 -13
- package/lib/esm/actions/blue/supply.d.ts +2 -4
- package/lib/esm/actions/blue/supply.js +7 -9
- package/lib/esm/actions/blue/supplyCollateral.d.ts +2 -3
- package/lib/esm/actions/blue/supplyCollateral.js +6 -7
- package/lib/esm/actions/blue/supplyCollateralBorrow.d.ts +4 -9
- package/lib/esm/actions/blue/supplyCollateralBorrow.js +10 -15
- package/lib/esm/actions/blue/withdraw.d.ts +9 -7
- package/lib/esm/actions/blue/withdraw.js +19 -11
- package/lib/esm/actions/blue/withdrawCollateral.d.ts +1 -1
- package/lib/esm/actions/blue/withdrawCollateral.js +3 -3
- package/lib/esm/actions/index.d.ts +2 -0
- package/lib/esm/actions/index.js +1 -0
- package/lib/esm/actions/midnight/authorization.d.ts +37 -0
- package/lib/esm/actions/midnight/authorization.js +65 -0
- package/lib/esm/actions/midnight/cancelOffer.d.ts +38 -0
- package/lib/esm/actions/midnight/cancelOffer.js +69 -0
- package/lib/esm/actions/midnight/index.d.ts +11 -0
- package/lib/esm/actions/midnight/index.js +11 -0
- package/lib/esm/actions/midnight/mempoolSubmitOffers.d.ts +52 -0
- package/lib/esm/actions/midnight/mempoolSubmitOffers.js +68 -0
- package/lib/esm/actions/midnight/redeem.d.ts +43 -0
- package/lib/esm/actions/midnight/redeem.js +75 -0
- package/lib/esm/actions/midnight/repayWithdrawCollateral.d.ts +53 -0
- package/lib/esm/actions/midnight/repayWithdrawCollateral.js +117 -0
- package/lib/esm/actions/midnight/setterRatifierRatifyRoot.d.ts +40 -0
- package/lib/esm/actions/midnight/setterRatifierRatifyRoot.js +55 -0
- package/lib/esm/actions/midnight/supplyCollateral.d.ts +45 -0
- package/lib/esm/actions/midnight/supplyCollateral.js +79 -0
- package/lib/esm/actions/midnight/supplyCollateralTakeBorrow.d.ts +51 -0
- package/lib/esm/actions/midnight/supplyCollateralTakeBorrow.js +124 -0
- package/lib/esm/actions/midnight/takeBorrow.d.ts +57 -0
- package/lib/esm/actions/midnight/takeBorrow.js +106 -0
- package/lib/esm/actions/midnight/takeLend.d.ts +57 -0
- package/lib/esm/actions/midnight/takeLend.js +106 -0
- package/lib/esm/actions/midnight/types.d.ts +39 -0
- package/lib/esm/actions/midnight/types.js +12 -0
- package/lib/esm/actions/requirements/encode/encodeBlueSignatureAuthorization.d.ts +1 -1
- package/lib/esm/actions/requirements/encode/encodeBlueSignatureAuthorization.js +6 -17
- package/lib/esm/actions/requirements/encode/encodeErc20Approval.d.ts +5 -4
- package/lib/esm/actions/requirements/encode/encodeErc20Approval.js +12 -16
- package/lib/esm/actions/requirements/encode/encodeErc20Permit.d.ts +2 -2
- package/lib/esm/actions/requirements/encode/encodeErc20Permit.js +12 -29
- package/lib/esm/actions/requirements/encode/encodeErc20Permit2Approve.d.ts +1 -1
- package/lib/esm/actions/requirements/encode/encodeErc20Permit2Approve.js +5 -17
- package/lib/esm/actions/requirements/generalAdapter/getGeneralAdapterRequirementsPermit.d.ts +1 -1
- package/lib/esm/actions/requirements/getRequirementsApproval.d.ts +10 -4
- package/lib/esm/actions/requirements/getRequirementsApproval.js +10 -4
- package/lib/esm/actions/requirements/index.d.ts +1 -0
- package/lib/esm/actions/requirements/index.js +1 -0
- package/lib/esm/actions/requirements/midnight/getMidnightApprovalRequirements.d.ts +49 -0
- package/lib/esm/actions/requirements/midnight/getMidnightApprovalRequirements.js +72 -0
- package/lib/esm/actions/requirements/midnight/getMidnightAuthorizationRequirement.d.ts +44 -0
- package/lib/esm/actions/requirements/midnight/getMidnightAuthorizationRequirement.js +74 -0
- package/lib/esm/actions/requirements/midnight/getSetterRatifierRatifyRootRequirement.d.ts +42 -0
- package/lib/esm/actions/requirements/midnight/getSetterRatifierRatifyRootRequirement.js +66 -0
- package/lib/esm/actions/requirements/midnight/index.d.ts +3 -0
- package/lib/esm/actions/requirements/midnight/index.js +3 -0
- package/lib/esm/actions/vaultV1/deposit.d.ts +3 -4
- package/lib/esm/actions/vaultV1/deposit.js +8 -9
- package/lib/esm/actions/vaultV1/migrateToV2.d.ts +2 -3
- package/lib/esm/actions/vaultV1/migrateToV2.js +6 -7
- package/lib/esm/actions/vaultV1/redeem.d.ts +1 -1
- package/lib/esm/actions/vaultV1/redeem.js +3 -3
- package/lib/esm/actions/vaultV1/withdraw.d.ts +1 -1
- package/lib/esm/actions/vaultV1/withdraw.js +3 -3
- package/lib/esm/actions/vaultV2/deposit.d.ts +3 -4
- package/lib/esm/actions/vaultV2/deposit.js +8 -9
- package/lib/esm/actions/vaultV2/forceRedeem.d.ts +2 -3
- package/lib/esm/actions/vaultV2/forceRedeem.js +4 -5
- package/lib/esm/actions/vaultV2/forceWithdraw.d.ts +1 -1
- package/lib/esm/actions/vaultV2/forceWithdraw.js +3 -3
- package/lib/esm/actions/vaultV2/redeem.d.ts +1 -1
- package/lib/esm/actions/vaultV2/redeem.js +3 -3
- package/lib/esm/actions/vaultV2/withdraw.d.ts +1 -1
- package/lib/esm/actions/vaultV2/withdraw.js +3 -3
- package/lib/esm/client/morphoViemExtension.d.ts +1 -1
- package/lib/esm/client/morphoViemExtension.js +6 -3
- package/lib/esm/constants.d.ts +1 -0
- package/lib/esm/constants.js +1 -0
- package/lib/esm/entities/blue/blue.d.ts +5 -5
- package/lib/esm/entities/blue/blue.js +95 -70
- package/lib/esm/entities/index.d.ts +1 -0
- package/lib/esm/entities/index.js +1 -0
- package/lib/esm/entities/midnight/index.d.ts +2 -0
- package/lib/esm/entities/midnight/index.js +2 -0
- package/lib/esm/entities/midnight/midnight.d.ts +402 -0
- package/lib/esm/entities/midnight/midnight.js +1032 -0
- package/lib/esm/entities/midnight/types.d.ts +164 -0
- package/lib/esm/entities/midnight/types.js +1 -0
- package/lib/esm/entities/vaultV1/vaultV1.js +13 -20
- package/lib/esm/entities/vaultV2/vaultV2.js +9 -11
- package/lib/esm/errors.d.ts +1 -0
- package/lib/esm/errors.js +1 -0
- package/lib/esm/helpers/encodeDeallocation.d.ts +1 -0
- package/lib/esm/helpers/encodeDeallocation.js +3 -2
- package/lib/esm/helpers/index.d.ts +4 -1
- package/lib/esm/helpers/index.js +4 -1
- package/lib/esm/helpers/signAndVerifyTypedData.d.ts +34 -0
- package/lib/esm/helpers/signAndVerifyTypedData.js +54 -0
- package/lib/esm/helpers/validate.d.ts +40 -1
- package/lib/esm/helpers/validate.js +46 -5
- package/lib/esm/helpers/validateMidnightAuthorizationTarget.d.ts +15 -0
- package/lib/esm/helpers/validateMidnightAuthorizationTarget.js +28 -0
- package/lib/esm/helpers/validateMidnightMarket.d.ts +10 -0
- package/lib/esm/helpers/validateMidnightMarket.js +20 -0
- package/lib/esm/helpers/validateOfferSides.d.ts +21 -0
- package/lib/esm/helpers/validateOfferSides.js +32 -0
- package/lib/esm/helpers/validateRequirementSpender.d.ts +29 -0
- package/lib/esm/helpers/validateRequirementSpender.js +45 -0
- package/lib/esm/helpers/validateTakeableOffers.d.ts +18 -0
- package/lib/esm/helpers/validateTakeableOffers.js +31 -0
- package/lib/esm/midnight-api.d.ts +1 -0
- package/lib/esm/midnight-api.js +1 -0
- package/lib/esm/types/action.d.ts +189 -23
- package/lib/esm/types/action.js +26 -7
- package/lib/esm/types/client.d.ts +3 -2
- package/lib/esm/types/error.d.ts +288 -119
- package/lib/esm/types/error.js +232 -154
- package/lib/esm/utils.d.ts +1 -0
- package/lib/esm/utils.js +1 -0
- package/package.json +12 -3
|
@@ -3,7 +3,7 @@ import { deepFreeze, isDefined } from "@morpho-org/morpho-ts";
|
|
|
3
3
|
import { isAddressEqual } from "viem";
|
|
4
4
|
import { BundlerAction } from "../../bundler/index.js";
|
|
5
5
|
import { addTransactionMetadata } from "../../helpers/index.js";
|
|
6
|
-
import { ChainWNativeMissingError, NativeAmountOnNonWNativeVaultError,
|
|
6
|
+
import { ChainWNativeMissingError, NativeAmountOnNonWNativeVaultError, NegativeInputError, NonPositiveInputError, } from "../../types/index.js";
|
|
7
7
|
import { getTokenRequirementActions } from "../signatures/getTokenRequirementActions.js";
|
|
8
8
|
/**
|
|
9
9
|
* Prepares a deposit transaction for a VaultV2 contract.
|
|
@@ -30,9 +30,9 @@ import { getTokenRequirementActions } from "../signatures/getTokenRequirementAct
|
|
|
30
30
|
* @param params.metadata - Optional analytics metadata attached to the bundle.
|
|
31
31
|
* @returns A deep-frozen `Transaction<VaultV2DepositAction>` with `to`, `value`, `data`, and the
|
|
32
32
|
* typed `action` discriminator the simulation layer consumes.
|
|
33
|
-
* @throws {
|
|
34
|
-
* @throws {
|
|
35
|
-
*
|
|
33
|
+
* @throws {NegativeInputError} when `amount < 0n` or `nativeAmount < 0n`.
|
|
34
|
+
* @throws {NonPositiveInputError} when `maxSharePrice <= 0n`, or when both `amount` and
|
|
35
|
+
* `nativeAmount` resolve to zero.
|
|
36
36
|
* @throws {ChainWNativeMissingError} when `nativeAmount` is provided but the chain has no
|
|
37
37
|
* configured wNative.
|
|
38
38
|
* @throws {NativeAmountOnNonWNativeVaultError} when `nativeAmount` is provided but the vault
|
|
@@ -44,7 +44,6 @@ import { getTokenRequirementActions } from "../signatures/getTokenRequirementAct
|
|
|
44
44
|
* `requirementSignature` is provided and the signed amount differs from `args.amount`.
|
|
45
45
|
* @throws {Permit2ExpirationMissingError} from `getTokenRequirementActions` when `amount > 0n` and a
|
|
46
46
|
* Permit2 requirement signature is missing its expiration.
|
|
47
|
-
* @throws {ZeroDepositAmountError} when both `amount` and `nativeAmount` resolve to zero.
|
|
48
47
|
* @example
|
|
49
48
|
* ```ts
|
|
50
49
|
* import { vaultV2Deposit } from "@morpho-org/morpho-sdk";
|
|
@@ -62,16 +61,16 @@ import { getTokenRequirementActions } from "../signatures/getTokenRequirementAct
|
|
|
62
61
|
*/
|
|
63
62
|
export const vaultV2Deposit = ({ vault: { chainId, address: vaultAddress, asset }, args: { amount = 0n, maxSharePrice, recipient, requirementSignature, nativeAmount, }, metadata, }) => {
|
|
64
63
|
if (amount < 0n) {
|
|
65
|
-
throw new
|
|
64
|
+
throw new NegativeInputError("amount", amount);
|
|
66
65
|
}
|
|
67
66
|
if (maxSharePrice <= 0n) {
|
|
68
|
-
throw new
|
|
67
|
+
throw new NonPositiveInputError("maxSharePrice", maxSharePrice);
|
|
69
68
|
}
|
|
70
69
|
const actions = [];
|
|
71
70
|
const { bundler3: { generalAdapter1, bundler3 }, wNative, } = getChainAddresses(chainId);
|
|
72
71
|
if (nativeAmount) {
|
|
73
72
|
if (nativeAmount < 0n) {
|
|
74
|
-
throw new
|
|
73
|
+
throw new NegativeInputError("nativeAmount", nativeAmount);
|
|
75
74
|
}
|
|
76
75
|
if (!isDefined(wNative)) {
|
|
77
76
|
throw new ChainWNativeMissingError(chainId);
|
|
@@ -99,7 +98,7 @@ export const vaultV2Deposit = ({ vault: { chainId, address: vaultAddress, asset
|
|
|
99
98
|
}
|
|
100
99
|
const totalAssets = amount + (nativeAmount ?? 0n);
|
|
101
100
|
if (totalAssets === 0n) {
|
|
102
|
-
throw new
|
|
101
|
+
throw new NonPositiveInputError("totalAssets", totalAssets);
|
|
103
102
|
}
|
|
104
103
|
actions.push({
|
|
105
104
|
type: "erc4626Deposit",
|
|
@@ -42,9 +42,8 @@ export interface VaultV2ForceRedeemParams {
|
|
|
42
42
|
* @returns A deep-frozen `Transaction<VaultV2ForceRedeemAction>` with `to`, `value`, `data`, and
|
|
43
43
|
* the typed `action` discriminator the simulation layer consumes.
|
|
44
44
|
* @throws {EmptyDeallocationsError} when `deallocations` is empty.
|
|
45
|
-
* @throws {
|
|
46
|
-
*
|
|
47
|
-
* `encodeForceDeallocateCall`).
|
|
45
|
+
* @throws {NonPositiveInputError} when `redeem.shares <= 0n` or any deallocation amount is
|
|
46
|
+
* non-positive.
|
|
48
47
|
* @example
|
|
49
48
|
* ```ts
|
|
50
49
|
* import { vaultV2ForceRedeem } from "@morpho-org/morpho-sdk";
|
|
@@ -3,7 +3,7 @@ import { deepFreeze } from "@morpho-org/morpho-ts";
|
|
|
3
3
|
import { encodeFunctionData } from "viem";
|
|
4
4
|
import { encodeForceDeallocateCall } from "../../helpers/encodeDeallocation.js";
|
|
5
5
|
import { addTransactionMetadata } from "../../helpers/index.js";
|
|
6
|
-
import { EmptyDeallocationsError,
|
|
6
|
+
import { EmptyDeallocationsError, NonPositiveInputError, } from "../../types/index.js";
|
|
7
7
|
/**
|
|
8
8
|
* Prepares a force-redeem transaction for a VaultV2 contract via the vault's native `multicall`.
|
|
9
9
|
*
|
|
@@ -31,9 +31,8 @@ import { EmptyDeallocationsError, NonPositiveSharesAmountError, } from "../../ty
|
|
|
31
31
|
* @returns A deep-frozen `Transaction<VaultV2ForceRedeemAction>` with `to`, `value`, `data`, and
|
|
32
32
|
* the typed `action` discriminator the simulation layer consumes.
|
|
33
33
|
* @throws {EmptyDeallocationsError} when `deallocations` is empty.
|
|
34
|
-
* @throws {
|
|
35
|
-
*
|
|
36
|
-
* `encodeForceDeallocateCall`).
|
|
34
|
+
* @throws {NonPositiveInputError} when `redeem.shares <= 0n` or any deallocation amount is
|
|
35
|
+
* non-positive.
|
|
37
36
|
* @example
|
|
38
37
|
* ```ts
|
|
39
38
|
* import { vaultV2ForceRedeem } from "@morpho-org/morpho-sdk";
|
|
@@ -54,7 +53,7 @@ export const vaultV2ForceRedeem = ({ vault: { address: vaultAddress }, args: { d
|
|
|
54
53
|
throw new EmptyDeallocationsError(vaultAddress);
|
|
55
54
|
}
|
|
56
55
|
if (redeem.shares <= 0n) {
|
|
57
|
-
throw new
|
|
56
|
+
throw new NonPositiveInputError("redeem.shares", redeem.shares);
|
|
58
57
|
}
|
|
59
58
|
const calls = [];
|
|
60
59
|
for (const deallocation of deallocations) {
|
|
@@ -38,7 +38,7 @@ export interface VaultV2ForceWithdrawParams {
|
|
|
38
38
|
* @returns A deep-frozen `Transaction<VaultV2ForceWithdrawAction>` with `to`, `value`, `data`,
|
|
39
39
|
* and the typed `action` discriminator the simulation layer consumes.
|
|
40
40
|
* @throws {EmptyDeallocationsError} when `deallocations` is empty.
|
|
41
|
-
* @throws {
|
|
41
|
+
* @throws {NonPositiveInputError} when `withdraw.amount <= 0n`, or when any
|
|
42
42
|
* `deallocations[i].amount <= 0n` (raised by `encodeForceDeallocateCall`).
|
|
43
43
|
* @example
|
|
44
44
|
* ```ts
|
|
@@ -3,7 +3,7 @@ import { deepFreeze } from "@morpho-org/morpho-ts";
|
|
|
3
3
|
import { encodeFunctionData } from "viem";
|
|
4
4
|
import { encodeForceDeallocateCall } from "../../helpers/encodeDeallocation.js";
|
|
5
5
|
import { addTransactionMetadata } from "../../helpers/index.js";
|
|
6
|
-
import { EmptyDeallocationsError,
|
|
6
|
+
import { EmptyDeallocationsError, NonPositiveInputError, } from "../../types/index.js";
|
|
7
7
|
/**
|
|
8
8
|
* Prepares a force-withdraw transaction for a VaultV2 contract via the vault's native `multicall`.
|
|
9
9
|
*
|
|
@@ -27,7 +27,7 @@ import { EmptyDeallocationsError, NonPositiveAssetAmountError, } from "../../typ
|
|
|
27
27
|
* @returns A deep-frozen `Transaction<VaultV2ForceWithdrawAction>` with `to`, `value`, `data`,
|
|
28
28
|
* and the typed `action` discriminator the simulation layer consumes.
|
|
29
29
|
* @throws {EmptyDeallocationsError} when `deallocations` is empty.
|
|
30
|
-
* @throws {
|
|
30
|
+
* @throws {NonPositiveInputError} when `withdraw.amount <= 0n`, or when any
|
|
31
31
|
* `deallocations[i].amount <= 0n` (raised by `encodeForceDeallocateCall`).
|
|
32
32
|
* @example
|
|
33
33
|
* ```ts
|
|
@@ -50,7 +50,7 @@ export const vaultV2ForceWithdraw = ({ vault: { address: vaultAddress }, args: {
|
|
|
50
50
|
}
|
|
51
51
|
const { amount: withdrawAmount, recipient: withdrawRecipient } = withdraw;
|
|
52
52
|
if (withdrawAmount <= 0n) {
|
|
53
|
-
throw new
|
|
53
|
+
throw new NonPositiveInputError("withdraw.amount", withdrawAmount);
|
|
54
54
|
}
|
|
55
55
|
const calls = [];
|
|
56
56
|
for (const deallocation of deallocations) {
|
|
@@ -25,7 +25,7 @@ export interface VaultV2RedeemParams {
|
|
|
25
25
|
* @param params.metadata - Optional analytics metadata attached to the transaction.
|
|
26
26
|
* @returns A deep-frozen `Transaction<VaultV2RedeemAction>` with `to`, `value`, `data`, and the
|
|
27
27
|
* typed `action` discriminator the simulation layer consumes.
|
|
28
|
-
* @throws {
|
|
28
|
+
* @throws {NonPositiveInputError} when `shares <= 0n`.
|
|
29
29
|
* @example
|
|
30
30
|
* ```ts
|
|
31
31
|
* import { vaultV2Redeem } from "@morpho-org/morpho-sdk";
|
|
@@ -2,7 +2,7 @@ import { vaultV2Abi } from "@morpho-org/blue-sdk-viem";
|
|
|
2
2
|
import { deepFreeze } from "@morpho-org/morpho-ts";
|
|
3
3
|
import { encodeFunctionData } from "viem";
|
|
4
4
|
import { addTransactionMetadata } from "../../helpers/index.js";
|
|
5
|
-
import {
|
|
5
|
+
import { NonPositiveInputError, } from "../../types/index.js";
|
|
6
6
|
/**
|
|
7
7
|
* Prepares a redeem transaction for a VaultV2 contract.
|
|
8
8
|
*
|
|
@@ -16,7 +16,7 @@ import { NonPositiveSharesAmountError, } from "../../types/index.js";
|
|
|
16
16
|
* @param params.metadata - Optional analytics metadata attached to the transaction.
|
|
17
17
|
* @returns A deep-frozen `Transaction<VaultV2RedeemAction>` with `to`, `value`, `data`, and the
|
|
18
18
|
* typed `action` discriminator the simulation layer consumes.
|
|
19
|
-
* @throws {
|
|
19
|
+
* @throws {NonPositiveInputError} when `shares <= 0n`.
|
|
20
20
|
* @example
|
|
21
21
|
* ```ts
|
|
22
22
|
* import { vaultV2Redeem } from "@morpho-org/morpho-sdk";
|
|
@@ -30,7 +30,7 @@ import { NonPositiveSharesAmountError, } from "../../types/index.js";
|
|
|
30
30
|
*/
|
|
31
31
|
export const vaultV2Redeem = ({ vault: { address: vaultAddress }, args: { shares, recipient, onBehalf }, metadata, }) => {
|
|
32
32
|
if (shares <= 0n) {
|
|
33
|
-
throw new
|
|
33
|
+
throw new NonPositiveInputError("shares", shares);
|
|
34
34
|
}
|
|
35
35
|
let tx = {
|
|
36
36
|
to: vaultAddress,
|
|
@@ -25,7 +25,7 @@ export interface VaultV2WithdrawParams {
|
|
|
25
25
|
* @param params.metadata - Optional analytics metadata attached to the transaction.
|
|
26
26
|
* @returns A deep-frozen `Transaction<VaultV2WithdrawAction>` with `to`, `value`, `data`, and the
|
|
27
27
|
* typed `action` discriminator the simulation layer consumes.
|
|
28
|
-
* @throws {
|
|
28
|
+
* @throws {NonPositiveInputError} when `amount <= 0n`.
|
|
29
29
|
* @example
|
|
30
30
|
* ```ts
|
|
31
31
|
* import { vaultV2Withdraw } from "@morpho-org/morpho-sdk";
|
|
@@ -2,7 +2,7 @@ import { vaultV2Abi } from "@morpho-org/blue-sdk-viem";
|
|
|
2
2
|
import { deepFreeze } from "@morpho-org/morpho-ts";
|
|
3
3
|
import { encodeFunctionData } from "viem";
|
|
4
4
|
import { addTransactionMetadata } from "../../helpers/index.js";
|
|
5
|
-
import {
|
|
5
|
+
import { NonPositiveInputError, } from "../../types/index.js";
|
|
6
6
|
/**
|
|
7
7
|
* Prepares a withdraw transaction for a VaultV2 contract.
|
|
8
8
|
*
|
|
@@ -16,7 +16,7 @@ import { NonPositiveAssetAmountError, } from "../../types/index.js";
|
|
|
16
16
|
* @param params.metadata - Optional analytics metadata attached to the transaction.
|
|
17
17
|
* @returns A deep-frozen `Transaction<VaultV2WithdrawAction>` with `to`, `value`, `data`, and the
|
|
18
18
|
* typed `action` discriminator the simulation layer consumes.
|
|
19
|
-
* @throws {
|
|
19
|
+
* @throws {NonPositiveInputError} when `amount <= 0n`.
|
|
20
20
|
* @example
|
|
21
21
|
* ```ts
|
|
22
22
|
* import { vaultV2Withdraw } from "@morpho-org/morpho-sdk";
|
|
@@ -30,7 +30,7 @@ import { NonPositiveAssetAmountError, } from "../../types/index.js";
|
|
|
30
30
|
*/
|
|
31
31
|
export const vaultV2Withdraw = ({ vault: { address: vaultAddress }, args: { amount, recipient, onBehalf }, metadata, }) => {
|
|
32
32
|
if (amount <= 0n) {
|
|
33
|
-
throw new
|
|
33
|
+
throw new NonPositiveInputError("amount", amount);
|
|
34
34
|
}
|
|
35
35
|
let tx = {
|
|
36
36
|
to: vaultAddress,
|
|
@@ -6,7 +6,7 @@ import { type Metadata, type MorphoClientType } from "../types/index.js";
|
|
|
6
6
|
* protocol entity factories under `client.morpho`, so reads and writes share one client.
|
|
7
7
|
*
|
|
8
8
|
* Holds no state beyond configuration: no cache, no `init()`, no warm-up. Each factory call
|
|
9
|
-
* (`client.morpho.vaultV1`, `vaultV2`, `blue`) returns a fresh entity bound to the client.
|
|
9
|
+
* (`client.morpho.vaultV1`, `vaultV2`, `blue`, `midnight`) returns a fresh entity bound to the client.
|
|
10
10
|
*
|
|
11
11
|
* @param _options - Optional SDK-wide options forwarded to the `morpho` namespace.
|
|
12
12
|
* @param _options.metadata - Optional analytics metadata applied to every transaction the
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import { MarketUtils } from "@morpho-org/blue-sdk";
|
|
2
2
|
import { deepFreeze } from "@morpho-org/morpho-ts";
|
|
3
|
-
import { MorphoBlue, MorphoVaultV1, MorphoVaultV2 } from "../entities/index.js";
|
|
3
|
+
import { MorphoBlue, MorphoMidnight, MorphoVaultV1, MorphoVaultV2, } from "../entities/index.js";
|
|
4
4
|
import { MarketIdMismatchError, } from "../types/index.js";
|
|
5
5
|
/**
|
|
6
6
|
* Builds the stateless `morpho` namespace exposed on an extended viem client. Wraps the supplied
|
|
7
7
|
* viem `Client` plus a frozen options bag and exposes factory methods for the protocol entities.
|
|
8
8
|
*
|
|
9
9
|
* Holds no state beyond configuration: no cache, no `init()`, no warm-up. Each factory call
|
|
10
|
-
* (`vaultV1`, `vaultV2`, `blue`) returns a fresh entity bound to this client.
|
|
10
|
+
* (`vaultV1`, `vaultV2`, `blue`, `midnight`) returns a fresh entity bound to this client.
|
|
11
11
|
*
|
|
12
12
|
* @internal
|
|
13
13
|
*/
|
|
@@ -34,6 +34,9 @@ function createMorphoNamespace(viemClient, options) {
|
|
|
34
34
|
}
|
|
35
35
|
return new MorphoBlue(namespace, marketParams, chainId);
|
|
36
36
|
},
|
|
37
|
+
midnight(chainId) {
|
|
38
|
+
return new MorphoMidnight(namespace, chainId);
|
|
39
|
+
},
|
|
37
40
|
};
|
|
38
41
|
return namespace;
|
|
39
42
|
}
|
|
@@ -43,7 +46,7 @@ function createMorphoNamespace(viemClient, options) {
|
|
|
43
46
|
* protocol entity factories under `client.morpho`, so reads and writes share one client.
|
|
44
47
|
*
|
|
45
48
|
* Holds no state beyond configuration: no cache, no `init()`, no warm-up. Each factory call
|
|
46
|
-
* (`client.morpho.vaultV1`, `vaultV2`, `blue`) returns a fresh entity bound to the client.
|
|
49
|
+
* (`client.morpho.vaultV1`, `vaultV2`, `blue`, `midnight`) returns a fresh entity bound to the client.
|
|
47
50
|
*
|
|
48
51
|
* @param _options - Optional SDK-wide options forwarded to the `morpho` namespace.
|
|
49
52
|
* @param _options.metadata - Optional analytics metadata applied to every transaction the
|
package/lib/esm/constants.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
1
|
export { DEFAULT_SLIPPAGE_TOLERANCE, EIP_712_FIELDS, isMarketId, LIQUIDATION_CURSOR, MAX_LIQUIDATION_INCENTIVE_FACTOR, ORACLE_PRICE_SCALE, SECONDS_PER_YEAR, TransactionType, } from "@morpho-org/blue-sdk";
|
|
2
|
+
export { CBP, COLLATERAL_PARAMS_TYPEHASH, DEFAULT_TICK_SPACING, EIP712_DOMAIN_TYPEHASH, MARKET_TYPEHASH, MAX_COLLATERALS, MAX_COLLATERALS_PER_BORROWER, MAX_CONTINUOUS_FEE, MAX_SETTLEMENT_FEES, MAX_TICK, OFFER_TYPEHASH, PRICE_ROUNDING_STEP, SETTLEMENT_FEE_BREAKPOINTS, } from "@morpho-org/midnight-sdk";
|
|
2
3
|
export { BLUE_API_BASE_URL, BLUE_API_GRAPHQL_URL, CDN_BASE_URL, ChainId, ChainUtils, DOCS_BASE_URL, MORPHO_DOMAIN, OPTIMIZERS_API_BASE_URL, OPTIMIZERS_BASE_URL, REWARDS_BASE_URL, ZERO_ADDRESS, } from "@morpho-org/morpho-ts";
|
|
3
4
|
export { APPROVE_ONLY_ONCE_TOKENS, DEFAULT_LLTV_BUFFER, DEFAULT_SUPPLY_TARGET_UTILIZATION, DEFAULT_WITHDRAWAL_TARGET_UTILIZATION, MAX_ABSOLUTE_SHARE_PRICE, MAX_SLIPPAGE_TOLERANCE, MAX_TOKEN_APPROVALS, } from "./helpers/constant.js";
|
package/lib/esm/constants.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
1
|
export { DEFAULT_SLIPPAGE_TOLERANCE, EIP_712_FIELDS, isMarketId, LIQUIDATION_CURSOR, MAX_LIQUIDATION_INCENTIVE_FACTOR, ORACLE_PRICE_SCALE, SECONDS_PER_YEAR, TransactionType, } from "@morpho-org/blue-sdk";
|
|
2
|
+
export { CBP, COLLATERAL_PARAMS_TYPEHASH, DEFAULT_TICK_SPACING, EIP712_DOMAIN_TYPEHASH, MARKET_TYPEHASH, MAX_COLLATERALS, MAX_COLLATERALS_PER_BORROWER, MAX_CONTINUOUS_FEE, MAX_SETTLEMENT_FEES, MAX_TICK, OFFER_TYPEHASH, PRICE_ROUNDING_STEP, SETTLEMENT_FEE_BREAKPOINTS, } from "@morpho-org/midnight-sdk";
|
|
2
3
|
export { BLUE_API_BASE_URL, BLUE_API_GRAPHQL_URL, CDN_BASE_URL, ChainId, ChainUtils, DOCS_BASE_URL, MORPHO_DOMAIN, OPTIMIZERS_API_BASE_URL, OPTIMIZERS_BASE_URL, REWARDS_BASE_URL, ZERO_ADDRESS, } from "@morpho-org/morpho-ts";
|
|
3
4
|
export { APPROVE_ONLY_ONCE_TOKENS, DEFAULT_LLTV_BUFFER, DEFAULT_SUPPLY_TARGET_UTILIZATION, DEFAULT_WITHDRAWAL_TARGET_UTILIZATION, MAX_ABSOLUTE_SHARE_PRICE, MAX_SLIPPAGE_TOLERANCE, MAX_TOKEN_APPROVALS, } from "./helpers/constant.js";
|
|
@@ -382,7 +382,7 @@ export declare class MorphoBlue implements BlueActions {
|
|
|
382
382
|
slippageTolerance?: bigint;
|
|
383
383
|
reallocations?: readonly VaultReallocation[];
|
|
384
384
|
} & AssetsOrSharesArgs): {
|
|
385
|
-
getRequirements: () => Promise<(
|
|
385
|
+
getRequirements: () => Promise<(Requirement<import("../../types/action.js").AuthorizationRequirementSignature, undefined> | Readonly<Transaction<BlueAuthorizationAction>>)[]>;
|
|
386
386
|
buildTx: (signatures?: readonly RequirementSignature[]) => Readonly<Transaction<BlueWithdrawAction>>;
|
|
387
387
|
};
|
|
388
388
|
supplyCollateral({ amount, userAddress, nativeAmount, }: {
|
|
@@ -400,7 +400,7 @@ export declare class MorphoBlue implements BlueActions {
|
|
|
400
400
|
slippageTolerance?: bigint;
|
|
401
401
|
reallocations?: readonly VaultReallocation[];
|
|
402
402
|
}): {
|
|
403
|
-
getRequirements: () => Promise<(
|
|
403
|
+
getRequirements: () => Promise<(Requirement<import("../../types/action.js").AuthorizationRequirementSignature, undefined> | Readonly<Transaction<BlueAuthorizationAction>>)[]>;
|
|
404
404
|
buildTx: (signatures?: readonly RequirementSignature[]) => Readonly<Transaction<BlueBorrowAction>>;
|
|
405
405
|
};
|
|
406
406
|
repay(params: {
|
|
@@ -428,7 +428,7 @@ export declare class MorphoBlue implements BlueActions {
|
|
|
428
428
|
} & RepayAmountArgs): {
|
|
429
429
|
getRequirements: (reqParams?: {
|
|
430
430
|
useSimplePermit?: boolean;
|
|
431
|
-
}) => Promise<(import("../../types/action.js").Bundler3TokenSignatureRequirement |
|
|
431
|
+
}) => Promise<(import("../../types/action.js").Bundler3TokenSignatureRequirement | Requirement<import("../../types/action.js").AuthorizationRequirementSignature, undefined> | Readonly<Transaction<ERC20ApprovalAction>> | Readonly<Transaction<BlueAuthorizationAction>>)[]>;
|
|
432
432
|
buildTx: (signatures?: readonly RequirementSignature[]) => Readonly<Transaction<BlueRepayWithdrawCollateralAction>>;
|
|
433
433
|
};
|
|
434
434
|
supplyCollateralBorrow({ amount, userAddress, positionData, borrowAmount, nativeAmount, slippageTolerance, reallocations, }: {
|
|
@@ -440,7 +440,7 @@ export declare class MorphoBlue implements BlueActions {
|
|
|
440
440
|
} & DepositAmountArgs): {
|
|
441
441
|
getRequirements: (params?: {
|
|
442
442
|
useSimplePermit?: boolean;
|
|
443
|
-
}) => Promise<(import("../../types/action.js").Bundler3TokenSignatureRequirement |
|
|
443
|
+
}) => Promise<(import("../../types/action.js").Bundler3TokenSignatureRequirement | Requirement<import("../../types/action.js").AuthorizationRequirementSignature, undefined> | Readonly<Transaction<ERC20ApprovalAction>> | Readonly<Transaction<BlueAuthorizationAction>>)[]>;
|
|
444
444
|
buildTx: (signatures?: readonly RequirementSignature[]) => Readonly<Transaction<BlueSupplyCollateralBorrowAction>>;
|
|
445
445
|
};
|
|
446
446
|
refinance({ userAddress, positionData, target, collateralAmount, borrowAssets, borrowShares, slippageTolerance, targetReallocations, }: {
|
|
@@ -456,7 +456,7 @@ export declare class MorphoBlue implements BlueActions {
|
|
|
456
456
|
slippageTolerance?: bigint;
|
|
457
457
|
targetReallocations?: readonly VaultReallocation[];
|
|
458
458
|
}): {
|
|
459
|
-
getRequirements: () => Promise<(
|
|
459
|
+
getRequirements: () => Promise<(Requirement<import("../../types/action.js").AuthorizationRequirementSignature, undefined> | Readonly<Transaction<BlueAuthorizationAction>>)[]>;
|
|
460
460
|
buildTx: (signatures?: readonly RequirementSignature[]) => Readonly<Transaction<BlueRefinanceAction>>;
|
|
461
461
|
};
|
|
462
462
|
/**
|
|
@@ -3,8 +3,8 @@ import { fetchAccrualPosition, fetchMarket, fetchPosition, fetchVault, fetchVaul
|
|
|
3
3
|
import { Time } from "@morpho-org/morpho-ts";
|
|
4
4
|
import { isAddressEqual } from "viem";
|
|
5
5
|
import { blueBorrow, blueRefinance, blueRepay, blueRepayWithdrawCollateral, blueSupply, blueSupplyCollateral, blueSupplyCollateralBorrow, blueWithdraw, blueWithdrawCollateral, getBlueAuthorizationRequirement, getGeneralAdapterRequirements, } from "../../actions/index.js";
|
|
6
|
-
import { computeMaxRepaySharePrice, computeMaxSupplySharePrice, computeMinBorrowSharePrice, computeMinWithdrawSharePrice, computeReallocations, validateAccrualPosition, validateChainId, validateNativeAsset, validatePositionHealth, validatePositionHealthAfterWithdraw, validateRepayAmount, validateRepayShares, validateSlippageTolerance, validateWithdrawAmount, validateWithdrawShares, } from "../../helpers/index.js";
|
|
7
|
-
import { BorrowAmountAndSharesExclusiveError, MarketIdMismatchError, MissingAccrualPositionError, MutuallyExclusiveRepayAmountsError, MutuallyExclusiveWithdrawAmountsError,
|
|
6
|
+
import { computeMaxRepaySharePrice, computeMaxSupplySharePrice, computeMinBorrowSharePrice, computeMinWithdrawSharePrice, computeReallocations, validateAccrualPosition, validateChainId, validateNativeAsset, validatePositionHealth, validatePositionHealthAfterWithdraw, validateReallocations, validateRepayAmount, validateRepayShares, validateSlippageTolerance, validateWithdrawAmount, validateWithdrawShares, } from "../../helpers/index.js";
|
|
7
|
+
import { BorrowAmountAndSharesExclusiveError, MarketIdMismatchError, MissingAccrualPositionError, MutuallyExclusiveRepayAmountsError, MutuallyExclusiveWithdrawAmountsError, NegativeInputError, NonPositiveInputError, RefinanceExceedsBorrowAssetsError, RefinanceExceedsBorrowSharesError, RefinanceExceedsCollateralError, RefinanceSameMarketError, RefinanceTokenMismatchError, selectRequirementSignatures, WithdrawExceedsCollateralError, } from "../../types/index.js";
|
|
8
8
|
import { ReallocationData } from "../reallocationData.js";
|
|
9
9
|
export class MorphoBlue {
|
|
10
10
|
client;
|
|
@@ -35,14 +35,14 @@ export class MorphoBlue {
|
|
|
35
35
|
supply({ amount = 0n, userAddress, nativeAmount, marketData, slippageTolerance = DEFAULT_SLIPPAGE_TOLERANCE, }) {
|
|
36
36
|
validateChainId(this.client.viemClient.chain?.id, this.chainId);
|
|
37
37
|
if (amount < 0n) {
|
|
38
|
-
throw new
|
|
38
|
+
throw new NegativeInputError("amount", amount);
|
|
39
39
|
}
|
|
40
40
|
if (nativeAmount !== undefined && nativeAmount < 0n) {
|
|
41
|
-
throw new
|
|
41
|
+
throw new NegativeInputError("nativeAmount", nativeAmount);
|
|
42
42
|
}
|
|
43
43
|
const totalAssets = amount + (nativeAmount ?? 0n);
|
|
44
44
|
if (totalAssets === 0n) {
|
|
45
|
-
throw new
|
|
45
|
+
throw new NonPositiveInputError("totalAssets", totalAssets);
|
|
46
46
|
}
|
|
47
47
|
if (marketData.id !== this.marketParams.id) {
|
|
48
48
|
throw new MarketIdMismatchError(marketData.id, this.marketParams.id);
|
|
@@ -97,10 +97,19 @@ export class MorphoBlue {
|
|
|
97
97
|
if (assets !== 0n && shares !== 0n) {
|
|
98
98
|
throw new MutuallyExclusiveWithdrawAmountsError(this.marketParams.id);
|
|
99
99
|
}
|
|
100
|
-
if (assets < 0n
|
|
101
|
-
throw new
|
|
100
|
+
if (assets < 0n) {
|
|
101
|
+
throw new NegativeInputError("assets", assets);
|
|
102
|
+
}
|
|
103
|
+
if (shares < 0n) {
|
|
104
|
+
throw new NegativeInputError("shares", shares);
|
|
105
|
+
}
|
|
106
|
+
if (assets === 0n && shares === 0n) {
|
|
107
|
+
throw new NonPositiveInputError("assets or shares", 0n);
|
|
102
108
|
}
|
|
103
109
|
validateSlippageTolerance(slippageTolerance);
|
|
110
|
+
if (reallocations) {
|
|
111
|
+
validateReallocations(reallocations, this.marketParams.id);
|
|
112
|
+
}
|
|
104
113
|
if (!positionData) {
|
|
105
114
|
throw new MissingAccrualPositionError(this.marketParams.id);
|
|
106
115
|
}
|
|
@@ -161,14 +170,14 @@ export class MorphoBlue {
|
|
|
161
170
|
supplyCollateral({ amount = 0n, userAddress, nativeAmount, }) {
|
|
162
171
|
validateChainId(this.client.viemClient.chain?.id, this.chainId);
|
|
163
172
|
if (amount < 0n) {
|
|
164
|
-
throw new
|
|
173
|
+
throw new NegativeInputError("amount", amount);
|
|
165
174
|
}
|
|
166
175
|
if (nativeAmount !== undefined && nativeAmount < 0n) {
|
|
167
|
-
throw new
|
|
176
|
+
throw new NegativeInputError("nativeAmount", nativeAmount);
|
|
168
177
|
}
|
|
169
178
|
const totalCollateral = amount + (nativeAmount ?? 0n);
|
|
170
179
|
if (totalCollateral === 0n) {
|
|
171
|
-
throw new
|
|
180
|
+
throw new NonPositiveInputError("totalCollateral", totalCollateral);
|
|
172
181
|
}
|
|
173
182
|
if (nativeAmount !== undefined && nativeAmount > 0n) {
|
|
174
183
|
validateNativeAsset(this.chainId, this.marketParams.collateralToken);
|
|
@@ -205,9 +214,12 @@ export class MorphoBlue {
|
|
|
205
214
|
borrow({ amount, userAddress, positionData, slippageTolerance = DEFAULT_SLIPPAGE_TOLERANCE, reallocations, }) {
|
|
206
215
|
validateChainId(this.client.viemClient.chain?.id, this.chainId);
|
|
207
216
|
if (amount <= 0n) {
|
|
208
|
-
throw new
|
|
217
|
+
throw new NonPositiveInputError("amount", amount);
|
|
209
218
|
}
|
|
210
219
|
validateSlippageTolerance(slippageTolerance);
|
|
220
|
+
if (reallocations) {
|
|
221
|
+
validateReallocations(reallocations, this.marketParams.id);
|
|
222
|
+
}
|
|
211
223
|
if (!positionData) {
|
|
212
224
|
throw new MissingAccrualPositionError(this.marketParams.id);
|
|
213
225
|
}
|
|
@@ -262,12 +274,30 @@ export class MorphoBlue {
|
|
|
262
274
|
repay(params) {
|
|
263
275
|
validateChainId(this.client.viemClient.chain?.id, this.chainId);
|
|
264
276
|
const { userAddress, positionData, slippageTolerance = DEFAULT_SLIPPAGE_TOLERANCE, } = params;
|
|
265
|
-
if ("amount" in params && "shares" in params) {
|
|
266
|
-
throw new MutuallyExclusiveRepayAmountsError(this.marketParams.id);
|
|
267
|
-
}
|
|
268
277
|
const nativeAmount = params.nativeAmount ?? 0n;
|
|
269
278
|
if (nativeAmount < 0n) {
|
|
270
|
-
throw new
|
|
279
|
+
throw new NegativeInputError("nativeAmount", nativeAmount);
|
|
280
|
+
}
|
|
281
|
+
const amount = ("amount" in params ? params.amount : undefined) ?? 0n;
|
|
282
|
+
const shares = ("shares" in params ? params.shares : undefined) ?? 0n;
|
|
283
|
+
if (amount < 0n) {
|
|
284
|
+
throw new NegativeInputError("amount", amount);
|
|
285
|
+
}
|
|
286
|
+
if (shares < 0n) {
|
|
287
|
+
throw new NegativeInputError("shares", shares);
|
|
288
|
+
}
|
|
289
|
+
if (amount > 0n && shares > 0n) {
|
|
290
|
+
throw new MutuallyExclusiveRepayAmountsError(this.marketParams.id);
|
|
291
|
+
}
|
|
292
|
+
if ("shares" in params) {
|
|
293
|
+
if (shares === 0n) {
|
|
294
|
+
throw new NonPositiveInputError("shares", shares);
|
|
295
|
+
}
|
|
296
|
+
}
|
|
297
|
+
else {
|
|
298
|
+
if (amount + nativeAmount <= 0n) {
|
|
299
|
+
throw new NonPositiveInputError("amount + nativeAmount", amount + nativeAmount);
|
|
300
|
+
}
|
|
271
301
|
}
|
|
272
302
|
validateSlippageTolerance(slippageTolerance);
|
|
273
303
|
if (!positionData) {
|
|
@@ -286,10 +316,6 @@ export class MorphoBlue {
|
|
|
286
316
|
let erc20Amount;
|
|
287
317
|
let marketForRepay;
|
|
288
318
|
if ("shares" in params) {
|
|
289
|
-
const shares = params.shares;
|
|
290
|
-
if (shares <= 0n) {
|
|
291
|
-
throw new NonPositiveRepayAmountError(this.marketParams.id);
|
|
292
|
-
}
|
|
293
319
|
validateRepayShares({
|
|
294
320
|
positionData,
|
|
295
321
|
repayShares: shares,
|
|
@@ -312,17 +338,7 @@ export class MorphoBlue {
|
|
|
312
338
|
}
|
|
313
339
|
else {
|
|
314
340
|
// Assets mode is additive, like supply: repaid = amount + nativeAmount.
|
|
315
|
-
const amount = params.amount ?? 0n;
|
|
316
|
-
// Reject a negative ERC-20 amount before it can be masked by nativeAmount
|
|
317
|
-
// in the sum below (a negative amount would otherwise yield a negative
|
|
318
|
-
// erc20Amount and a negative approval in getRequirements).
|
|
319
|
-
if (amount < 0n) {
|
|
320
|
-
throw new NonPositiveRepayAmountError(this.marketParams.id);
|
|
321
|
-
}
|
|
322
341
|
repayAssets = amount + nativeAmount;
|
|
323
|
-
if (repayAssets <= 0n) {
|
|
324
|
-
throw new NonPositiveRepayAmountError(this.marketParams.id);
|
|
325
|
-
}
|
|
326
342
|
validateRepayAmount({
|
|
327
343
|
positionData,
|
|
328
344
|
repayAssets,
|
|
@@ -390,7 +406,7 @@ export class MorphoBlue {
|
|
|
390
406
|
withdrawCollateral({ userAddress, amount, positionData, }) {
|
|
391
407
|
validateChainId(this.client.viemClient.chain?.id, this.chainId);
|
|
392
408
|
if (amount <= 0n) {
|
|
393
|
-
throw new
|
|
409
|
+
throw new NonPositiveInputError("amount", amount);
|
|
394
410
|
}
|
|
395
411
|
if (!positionData) {
|
|
396
412
|
throw new MissingAccrualPositionError(this.marketParams.id);
|
|
@@ -431,15 +447,33 @@ export class MorphoBlue {
|
|
|
431
447
|
repayWithdrawCollateral(params) {
|
|
432
448
|
validateChainId(this.client.viemClient.chain?.id, this.chainId);
|
|
433
449
|
const { userAddress, withdrawAmount, positionData, slippageTolerance = DEFAULT_SLIPPAGE_TOLERANCE, } = params;
|
|
434
|
-
if ("amount" in params && "shares" in params) {
|
|
435
|
-
throw new MutuallyExclusiveRepayAmountsError(this.marketParams.id);
|
|
436
|
-
}
|
|
437
450
|
const nativeAmount = params.nativeAmount ?? 0n;
|
|
438
451
|
if (nativeAmount < 0n) {
|
|
439
|
-
throw new
|
|
452
|
+
throw new NegativeInputError("nativeAmount", nativeAmount);
|
|
453
|
+
}
|
|
454
|
+
const amount = ("amount" in params ? params.amount : undefined) ?? 0n;
|
|
455
|
+
const shares = ("shares" in params ? params.shares : undefined) ?? 0n;
|
|
456
|
+
if (amount < 0n) {
|
|
457
|
+
throw new NegativeInputError("amount", amount);
|
|
458
|
+
}
|
|
459
|
+
if (shares < 0n) {
|
|
460
|
+
throw new NegativeInputError("shares", shares);
|
|
461
|
+
}
|
|
462
|
+
if (amount > 0n && shares > 0n) {
|
|
463
|
+
throw new MutuallyExclusiveRepayAmountsError(this.marketParams.id);
|
|
464
|
+
}
|
|
465
|
+
if ("shares" in params) {
|
|
466
|
+
if (shares === 0n) {
|
|
467
|
+
throw new NonPositiveInputError("shares", shares);
|
|
468
|
+
}
|
|
469
|
+
}
|
|
470
|
+
else {
|
|
471
|
+
if (amount + nativeAmount <= 0n) {
|
|
472
|
+
throw new NonPositiveInputError("amount + nativeAmount", amount + nativeAmount);
|
|
473
|
+
}
|
|
440
474
|
}
|
|
441
475
|
if (withdrawAmount <= 0n) {
|
|
442
|
-
throw new
|
|
476
|
+
throw new NonPositiveInputError("withdrawAmount", withdrawAmount);
|
|
443
477
|
}
|
|
444
478
|
validateSlippageTolerance(slippageTolerance);
|
|
445
479
|
if (!positionData) {
|
|
@@ -462,10 +496,6 @@ export class MorphoBlue {
|
|
|
462
496
|
const accrualTimestamp = MathLib.max(Time.timestamp(), positionData.market.lastUpdate) +
|
|
463
497
|
Time.s.from.h(2n);
|
|
464
498
|
if ("shares" in params) {
|
|
465
|
-
const shares = params.shares;
|
|
466
|
-
if (shares <= 0n) {
|
|
467
|
-
throw new NonPositiveRepayAmountError(this.marketParams.id);
|
|
468
|
-
}
|
|
469
499
|
validateRepayShares({
|
|
470
500
|
positionData,
|
|
471
501
|
repayShares: shares,
|
|
@@ -484,17 +514,7 @@ export class MorphoBlue {
|
|
|
484
514
|
}
|
|
485
515
|
else {
|
|
486
516
|
// Assets mode is additive, like supply: repaid = amount + nativeAmount.
|
|
487
|
-
const amount = params.amount ?? 0n;
|
|
488
|
-
// Reject a negative ERC-20 amount before it can be masked by nativeAmount
|
|
489
|
-
// in the sum below (a negative amount would otherwise yield a negative
|
|
490
|
-
// erc20Amount and a negative approval in getRequirements).
|
|
491
|
-
if (amount < 0n) {
|
|
492
|
-
throw new NonPositiveRepayAmountError(this.marketParams.id);
|
|
493
|
-
}
|
|
494
517
|
repayAssets = amount + nativeAmount;
|
|
495
|
-
if (repayAssets <= 0n) {
|
|
496
|
-
throw new NonPositiveRepayAmountError(this.marketParams.id);
|
|
497
|
-
}
|
|
498
518
|
validateRepayAmount({
|
|
499
519
|
positionData,
|
|
500
520
|
repayAssets,
|
|
@@ -587,13 +607,21 @@ export class MorphoBlue {
|
|
|
587
607
|
supplyCollateralBorrow({ amount = 0n, userAddress, positionData, borrowAmount, nativeAmount, slippageTolerance = DEFAULT_SLIPPAGE_TOLERANCE, reallocations, }) {
|
|
588
608
|
validateChainId(this.client.viemClient.chain?.id, this.chainId);
|
|
589
609
|
if (amount < 0n) {
|
|
590
|
-
throw new
|
|
610
|
+
throw new NegativeInputError("amount", amount);
|
|
591
611
|
}
|
|
592
612
|
if (nativeAmount !== undefined && nativeAmount < 0n) {
|
|
593
|
-
throw new
|
|
613
|
+
throw new NegativeInputError("nativeAmount", nativeAmount);
|
|
594
614
|
}
|
|
595
615
|
if (borrowAmount <= 0n) {
|
|
596
|
-
throw new
|
|
616
|
+
throw new NonPositiveInputError("borrowAmount", borrowAmount);
|
|
617
|
+
}
|
|
618
|
+
const totalCollateral = amount + (nativeAmount ?? 0n);
|
|
619
|
+
if (totalCollateral === 0n) {
|
|
620
|
+
throw new NonPositiveInputError("totalCollateral", totalCollateral);
|
|
621
|
+
}
|
|
622
|
+
validateSlippageTolerance(slippageTolerance);
|
|
623
|
+
if (reallocations) {
|
|
624
|
+
validateReallocations(reallocations, this.marketParams.id);
|
|
597
625
|
}
|
|
598
626
|
if (!positionData) {
|
|
599
627
|
throw new MissingAccrualPositionError(this.marketParams.id);
|
|
@@ -603,11 +631,6 @@ export class MorphoBlue {
|
|
|
603
631
|
expectedMarketId: this.marketParams.id,
|
|
604
632
|
expectedUser: userAddress,
|
|
605
633
|
});
|
|
606
|
-
const totalCollateral = amount + (nativeAmount ?? 0n);
|
|
607
|
-
if (totalCollateral === 0n) {
|
|
608
|
-
throw new ZeroCollateralAmountError(this.marketParams.id);
|
|
609
|
-
}
|
|
610
|
-
validateSlippageTolerance(slippageTolerance);
|
|
611
634
|
if (nativeAmount !== undefined && nativeAmount > 0n) {
|
|
612
635
|
validateNativeAsset(this.chainId, this.marketParams.collateralToken);
|
|
613
636
|
}
|
|
@@ -670,7 +693,21 @@ export class MorphoBlue {
|
|
|
670
693
|
validateChainId(this.client.viemClient.chain?.id, this.chainId);
|
|
671
694
|
validateSlippageTolerance(slippageTolerance);
|
|
672
695
|
if (collateralAmount <= 0n) {
|
|
673
|
-
throw new
|
|
696
|
+
throw new NonPositiveInputError("collateralAmount", collateralAmount);
|
|
697
|
+
}
|
|
698
|
+
const requestedAssets = borrowAssets ?? 0n;
|
|
699
|
+
const requestedShares = borrowShares ?? 0n;
|
|
700
|
+
if (requestedAssets < 0n) {
|
|
701
|
+
throw new NegativeInputError("borrowAssets", requestedAssets);
|
|
702
|
+
}
|
|
703
|
+
if (requestedShares < 0n) {
|
|
704
|
+
throw new NegativeInputError("borrowShares", requestedShares);
|
|
705
|
+
}
|
|
706
|
+
if (requestedAssets > 0n && requestedShares > 0n) {
|
|
707
|
+
throw new BorrowAmountAndSharesExclusiveError(this.marketParams.id);
|
|
708
|
+
}
|
|
709
|
+
if (targetReallocations) {
|
|
710
|
+
validateReallocations(targetReallocations, target.marketParams.id);
|
|
674
711
|
}
|
|
675
712
|
if (!positionData) {
|
|
676
713
|
throw new MissingAccrualPositionError(this.marketParams.id);
|
|
@@ -692,18 +729,6 @@ export class MorphoBlue {
|
|
|
692
729
|
expectedMarketId: target.marketParams.id,
|
|
693
730
|
expectedUser: userAddress,
|
|
694
731
|
});
|
|
695
|
-
const requestedAssets = borrowAssets ?? 0n;
|
|
696
|
-
const requestedShares = borrowShares ?? 0n;
|
|
697
|
-
// Reject negative debt up front; otherwise it slips past the `> 0n` mode checks and only fails at buildTx().
|
|
698
|
-
if (requestedAssets < 0n) {
|
|
699
|
-
throw new NonPositiveAssetAmountError(this.marketParams.loanToken);
|
|
700
|
-
}
|
|
701
|
-
if (requestedShares < 0n) {
|
|
702
|
-
throw new NegativeBorrowSharesError(this.marketParams.id);
|
|
703
|
-
}
|
|
704
|
-
if (requestedAssets > 0n && requestedShares > 0n) {
|
|
705
|
-
throw new BorrowAmountAndSharesExclusiveError(this.marketParams.id);
|
|
706
|
-
}
|
|
707
732
|
const sharesMode = requestedShares > 0n;
|
|
708
733
|
const shouldMigrateBorrow = requestedAssets > 0n || sharesMode;
|
|
709
734
|
if (collateralAmount > positionData.collateral) {
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
export type { IAccrualPosition, IAccrualVault, IAccrualVaultV2, IAccrualVaultV2Adapter, IAccrualVaultV2MorphoMarketV1Adapter, IAccrualVaultV2MorphoMarketV1AdapterV2, IAccrualVaultV2MorphoVaultV1Adapter, IAssetBalances, IEip5267Domain, IHolding, IMarket, IMarketParams, IPosition, IPreLiquidationParams, IPreLiquidationPosition, IToken, IVault, IVaultConfig, IVaultMarketAllocation, IVaultMarketConfig, IVaultMarketPublicAllocatorConfig, IVaultToken, IVaultUser, IVaultV2, IVaultV2Adapter, IVaultV2Allocation, IVaultV2MorphoMarketV1Adapter, IVaultV2MorphoMarketV1AdapterV2, IVaultV2MorphoVaultV1Adapter, PeripheralBalance, PeripheralBalanceType, VaultPublicAllocatorConfig, } from "@morpho-org/blue-sdk";
|
|
2
2
|
export { AccrualPosition, AccrualVault, AccrualVaultV2, AccrualVaultV2MorphoMarketV1Adapter, AccrualVaultV2MorphoMarketV1AdapterV2, AccrualVaultV2MorphoVaultV1Adapter, AssetBalances, ConstantWrappedToken, Eip5267Domain, ExchangeRateWrappedToken, Holding, Market, MarketParams, Position, PreLiquidationParams, PreLiquidationPosition, Token, User, Vault, VaultConfig, VaultMarketAllocation, VaultMarketConfig, VaultMarketPublicAllocatorConfig, VaultToken, VaultUser, VaultV2, VaultV2Adapter, VaultV2MorphoMarketV1Adapter, VaultV2MorphoMarketV1AdapterV2, VaultV2MorphoVaultV1Adapter, WrappedToken, } from "@morpho-org/blue-sdk";
|
|
3
3
|
export { MorphoBlue } from "./blue/index.js";
|
|
4
|
+
export * from "./midnight/index.js";
|
|
4
5
|
export { type InputReallocationData, ReallocationData, } from "./reallocationData.js";
|
|
5
6
|
export { MorphoVaultV1 } from "./vaultV1/index.js";
|
|
6
7
|
export { MorphoVaultV2 } from "./vaultV2/index.js";
|