@morpho-org/morpho-sdk 5.2.0 → 5.3.1
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 +99 -80
- 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 +101 -82
- 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 +11 -2
|
@@ -2,7 +2,11 @@ import { APPROVE_ONLY_ONCE_TOKENS } from "../../helpers/constant.js";
|
|
|
2
2
|
import { ApprovalAmountLessThanSpendAmountError, } from "../../types/index.js";
|
|
3
3
|
import { encodeErc20Approval } from "./encode/encodeErc20Approval.js";
|
|
4
4
|
/**
|
|
5
|
-
* Computes classic ERC-20 approval transactions for
|
|
5
|
+
* Computes classic ERC-20 approval transactions for a supported SDK spender, given the existing
|
|
6
|
+
* allowance.
|
|
7
|
+
*
|
|
8
|
+
* The spender is validated by {@link encodeErc20Approval}. Supported spenders are the chain's
|
|
9
|
+
* GeneralAdapter1, Permit2, Midnight, and MidnightBundles addresses when configured.
|
|
6
10
|
*
|
|
7
11
|
* Returns an empty array when the allowance already covers `spendAmount`. When the token is in
|
|
8
12
|
* `APPROVE_ONLY_ONCE_TOKENS` (e.g. USDT) and the existing allowance is non-zero, prepends a
|
|
@@ -10,16 +14,18 @@ import { encodeErc20Approval } from "./encode/encodeErc20Approval.js";
|
|
|
10
14
|
* before re-approving.
|
|
11
15
|
*
|
|
12
16
|
* @param params.address - ERC-20 token address.
|
|
13
|
-
* @param params.chainId - The chain the
|
|
17
|
+
* @param params.chainId - The chain the transaction targets, used to resolve supported spenders
|
|
18
|
+
* and token approval caps.
|
|
14
19
|
* @param params.args.spendAmount - The amount the bundle will actually pull.
|
|
15
20
|
* @param params.args.approvalAmount - The amount to approve (often equal to `spendAmount`, but
|
|
16
21
|
* may be `MAX_UINT_160` for Permit2 prerequisites).
|
|
17
|
-
* @param params.args.spender - Address that will be granted the approval. Must be GeneralAdapter1
|
|
22
|
+
* @param params.args.spender - Address that will be granted the approval. Must be GeneralAdapter1,
|
|
23
|
+
* Permit2, Midnight, or MidnightBundles for `chainId`.
|
|
18
24
|
* @param params.allowances - The user's current allowance of `address` for `spender`.
|
|
19
25
|
* @returns Up to two deep-frozen `Transaction<ERC20ApprovalAction>` entries: an optional reset
|
|
20
26
|
* followed by the new approval. Empty when no approval is needed.
|
|
21
27
|
* @throws {ApprovalAmountLessThanSpendAmountError} when `approvalAmount < spendAmount`.
|
|
22
|
-
* @throws {UnsupportedErc20ApprovalSpenderError} when `spender` is not
|
|
28
|
+
* @throws {UnsupportedErc20ApprovalSpenderError} when `spender` is not a supported SDK spender for `chainId`.
|
|
23
29
|
* @example
|
|
24
30
|
* ```ts
|
|
25
31
|
* import { getRequirementsApproval } from "@morpho-org/morpho-sdk";
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import type { Address, Client } from "viem";
|
|
2
|
+
import { type ERC20ApprovalAction, type Transaction } from "../../../types/index.js";
|
|
3
|
+
/** Parameters for {@link getMidnightApprovalRequirements}. */
|
|
4
|
+
export interface GetMidnightApprovalRequirementsParams {
|
|
5
|
+
readonly viemClient: Client;
|
|
6
|
+
readonly chainId: number;
|
|
7
|
+
readonly token: Address;
|
|
8
|
+
readonly owner: Address;
|
|
9
|
+
readonly spender: Address;
|
|
10
|
+
readonly amount: bigint;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Resolves classic ERC20 approval requirements for a Midnight spender.
|
|
14
|
+
*
|
|
15
|
+
* Entity flows call this from `getRequirements()`. Direct low-level consumers
|
|
16
|
+
* should call it before encoding a Midnight action that lets `Midnight` or
|
|
17
|
+
* `MidnightBundles` pull ERC20 tokens from the user.
|
|
18
|
+
*
|
|
19
|
+
* @param params.viemClient - Viem client used to read ERC20 allowance.
|
|
20
|
+
* @param params.chainId - Chain id expected by the viem client.
|
|
21
|
+
* @param params.token - ERC20 token that may need approval.
|
|
22
|
+
* @param params.owner - Token owner.
|
|
23
|
+
* @param params.spender - Midnight spender that will pull tokens.
|
|
24
|
+
* @param params.amount - Token amount the spender must be able to pull.
|
|
25
|
+
* @returns Approval transactions required for `spender` to pull `amount`.
|
|
26
|
+
* @throws {ChainIdMismatchError} when the viem client is connected to another chain.
|
|
27
|
+
* @throws {NegativeInputError} when `amount < 0n`.
|
|
28
|
+
* @throws {UnsupportedErc20ApprovalSpenderError} when `spender` is not the chain's Midnight or MidnightBundles deployment.
|
|
29
|
+
* @example
|
|
30
|
+
* ```ts
|
|
31
|
+
* import {
|
|
32
|
+
* getMidnightApprovalRequirements,
|
|
33
|
+
* midnightTakeLend,
|
|
34
|
+
* } from "@morpho-org/morpho-sdk";
|
|
35
|
+
*
|
|
36
|
+
* const approvals = await getMidnightApprovalRequirements({
|
|
37
|
+
* viemClient: client,
|
|
38
|
+
* chainId: 8453,
|
|
39
|
+
* token: loanToken,
|
|
40
|
+
* owner: user,
|
|
41
|
+
* spender: midnightBundles,
|
|
42
|
+
* amount: 1_000_000n,
|
|
43
|
+
* });
|
|
44
|
+
* if (approvals.length === 0) {
|
|
45
|
+
* const tx = midnightTakeLend(takeParams);
|
|
46
|
+
* }
|
|
47
|
+
* ```
|
|
48
|
+
*/
|
|
49
|
+
export declare const getMidnightApprovalRequirements: (params: GetMidnightApprovalRequirementsParams) => Promise<readonly Readonly<Transaction<ERC20ApprovalAction>>[]>;
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import { erc20Abi } from "viem";
|
|
2
|
+
import { readContract } from "viem/actions";
|
|
3
|
+
import { validateChainId, validateRequirementSpender, } from "../../../helpers/index.js";
|
|
4
|
+
import { NegativeInputError, } from "../../../types/index.js";
|
|
5
|
+
import { getRequirementsApproval } from "../getRequirementsApproval.js";
|
|
6
|
+
/**
|
|
7
|
+
* Resolves classic ERC20 approval requirements for a Midnight spender.
|
|
8
|
+
*
|
|
9
|
+
* Entity flows call this from `getRequirements()`. Direct low-level consumers
|
|
10
|
+
* should call it before encoding a Midnight action that lets `Midnight` or
|
|
11
|
+
* `MidnightBundles` pull ERC20 tokens from the user.
|
|
12
|
+
*
|
|
13
|
+
* @param params.viemClient - Viem client used to read ERC20 allowance.
|
|
14
|
+
* @param params.chainId - Chain id expected by the viem client.
|
|
15
|
+
* @param params.token - ERC20 token that may need approval.
|
|
16
|
+
* @param params.owner - Token owner.
|
|
17
|
+
* @param params.spender - Midnight spender that will pull tokens.
|
|
18
|
+
* @param params.amount - Token amount the spender must be able to pull.
|
|
19
|
+
* @returns Approval transactions required for `spender` to pull `amount`.
|
|
20
|
+
* @throws {ChainIdMismatchError} when the viem client is connected to another chain.
|
|
21
|
+
* @throws {NegativeInputError} when `amount < 0n`.
|
|
22
|
+
* @throws {UnsupportedErc20ApprovalSpenderError} when `spender` is not the chain's Midnight or MidnightBundles deployment.
|
|
23
|
+
* @example
|
|
24
|
+
* ```ts
|
|
25
|
+
* import {
|
|
26
|
+
* getMidnightApprovalRequirements,
|
|
27
|
+
* midnightTakeLend,
|
|
28
|
+
* } from "@morpho-org/morpho-sdk";
|
|
29
|
+
*
|
|
30
|
+
* const approvals = await getMidnightApprovalRequirements({
|
|
31
|
+
* viemClient: client,
|
|
32
|
+
* chainId: 8453,
|
|
33
|
+
* token: loanToken,
|
|
34
|
+
* owner: user,
|
|
35
|
+
* spender: midnightBundles,
|
|
36
|
+
* amount: 1_000_000n,
|
|
37
|
+
* });
|
|
38
|
+
* if (approvals.length === 0) {
|
|
39
|
+
* const tx = midnightTakeLend(takeParams);
|
|
40
|
+
* }
|
|
41
|
+
* ```
|
|
42
|
+
*/
|
|
43
|
+
export const getMidnightApprovalRequirements = async (params) => {
|
|
44
|
+
validateChainId(params.viemClient.chain?.id, params.chainId);
|
|
45
|
+
if (params.amount < 0n) {
|
|
46
|
+
throw new NegativeInputError("amount", params.amount);
|
|
47
|
+
}
|
|
48
|
+
// Validate the target even when no approval transaction needs to be encoded.
|
|
49
|
+
validateRequirementSpender({
|
|
50
|
+
chainId: params.chainId,
|
|
51
|
+
spender: params.spender,
|
|
52
|
+
allowed: ["midnight", "midnightBundles"],
|
|
53
|
+
});
|
|
54
|
+
if (params.amount === 0n)
|
|
55
|
+
return [];
|
|
56
|
+
const allowance = await readContract(params.viemClient, {
|
|
57
|
+
address: params.token,
|
|
58
|
+
abi: erc20Abi,
|
|
59
|
+
functionName: "allowance",
|
|
60
|
+
args: [params.owner, params.spender],
|
|
61
|
+
});
|
|
62
|
+
return getRequirementsApproval({
|
|
63
|
+
address: params.token,
|
|
64
|
+
chainId: params.chainId,
|
|
65
|
+
args: {
|
|
66
|
+
spender: params.spender,
|
|
67
|
+
spendAmount: params.amount,
|
|
68
|
+
approvalAmount: params.amount,
|
|
69
|
+
},
|
|
70
|
+
allowances: allowance,
|
|
71
|
+
});
|
|
72
|
+
};
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { type Address, type Client } from "viem";
|
|
2
|
+
import type { MidnightAuthorizationAction, Transaction } from "../../../types/index.js";
|
|
3
|
+
/** Parameters for {@link getMidnightAuthorizationRequirement}. */
|
|
4
|
+
export interface GetMidnightAuthorizationRequirementParams {
|
|
5
|
+
readonly viemClient: Client;
|
|
6
|
+
readonly chainId: number;
|
|
7
|
+
readonly owner: Address;
|
|
8
|
+
readonly authorized: Address;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Resolves the Midnight authorization transaction for a ratifier or bundle spender.
|
|
12
|
+
*
|
|
13
|
+
* Call before actions that rely on `Midnight.isAuthorized(owner, authorized)`,
|
|
14
|
+
* such as bundle takes or Ecrecover offer-root ratification. Entity flows call
|
|
15
|
+
* this from `getRequirements()` and omit the transaction when authorization is
|
|
16
|
+
* already set.
|
|
17
|
+
*
|
|
18
|
+
* @param params.viemClient - Viem client used to read `Midnight.isAuthorized`.
|
|
19
|
+
* @param params.chainId - Chain id expected by the viem client.
|
|
20
|
+
* @param params.owner - Account granting authorization.
|
|
21
|
+
* @param params.authorized - Spender or ratifier that needs authorization.
|
|
22
|
+
* @returns Authorization transaction, or `null` when already authorized.
|
|
23
|
+
* @throws {ChainIdMismatchError} when the viem client is connected to another chain.
|
|
24
|
+
* @throws {UnsupportedMidnightAuthorizationTargetError} when `authorized` is not a supported bundle or ratifier address.
|
|
25
|
+
* @example
|
|
26
|
+
* ```ts
|
|
27
|
+
* import { getMidnightAuthorizationRequirement } from "@morpho-org/morpho-sdk";
|
|
28
|
+
*
|
|
29
|
+
* const tx = await getMidnightAuthorizationRequirement({
|
|
30
|
+
* viemClient: client,
|
|
31
|
+
* chainId: 8453,
|
|
32
|
+
* owner: user,
|
|
33
|
+
* authorized: midnightBundles,
|
|
34
|
+
* });
|
|
35
|
+
* if (tx) {
|
|
36
|
+
* await walletClient.sendTransaction({
|
|
37
|
+
* to: tx.to,
|
|
38
|
+
* data: tx.data,
|
|
39
|
+
* value: tx.value,
|
|
40
|
+
* });
|
|
41
|
+
* }
|
|
42
|
+
* ```
|
|
43
|
+
*/
|
|
44
|
+
export declare const getMidnightAuthorizationRequirement: (params: GetMidnightAuthorizationRequirementParams) => Promise<Readonly<Transaction<MidnightAuthorizationAction>> | null>;
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import { midnightAbi } from "@morpho-org/midnight-sdk";
|
|
2
|
+
import { deepFreeze, getChainAddress } from "@morpho-org/morpho-ts";
|
|
3
|
+
import { encodeFunctionData } from "viem";
|
|
4
|
+
import { readContract } from "viem/actions";
|
|
5
|
+
import { validateChainId } from "../../../helpers/index.js";
|
|
6
|
+
import { validateMidnightAuthorizationTarget } from "../../../helpers/validateMidnightAuthorizationTarget.js";
|
|
7
|
+
/**
|
|
8
|
+
* Resolves the Midnight authorization transaction for a ratifier or bundle spender.
|
|
9
|
+
*
|
|
10
|
+
* Call before actions that rely on `Midnight.isAuthorized(owner, authorized)`,
|
|
11
|
+
* such as bundle takes or Ecrecover offer-root ratification. Entity flows call
|
|
12
|
+
* this from `getRequirements()` and omit the transaction when authorization is
|
|
13
|
+
* already set.
|
|
14
|
+
*
|
|
15
|
+
* @param params.viemClient - Viem client used to read `Midnight.isAuthorized`.
|
|
16
|
+
* @param params.chainId - Chain id expected by the viem client.
|
|
17
|
+
* @param params.owner - Account granting authorization.
|
|
18
|
+
* @param params.authorized - Spender or ratifier that needs authorization.
|
|
19
|
+
* @returns Authorization transaction, or `null` when already authorized.
|
|
20
|
+
* @throws {ChainIdMismatchError} when the viem client is connected to another chain.
|
|
21
|
+
* @throws {UnsupportedMidnightAuthorizationTargetError} when `authorized` is not a supported bundle or ratifier address.
|
|
22
|
+
* @example
|
|
23
|
+
* ```ts
|
|
24
|
+
* import { getMidnightAuthorizationRequirement } from "@morpho-org/morpho-sdk";
|
|
25
|
+
*
|
|
26
|
+
* const tx = await getMidnightAuthorizationRequirement({
|
|
27
|
+
* viemClient: client,
|
|
28
|
+
* chainId: 8453,
|
|
29
|
+
* owner: user,
|
|
30
|
+
* authorized: midnightBundles,
|
|
31
|
+
* });
|
|
32
|
+
* if (tx) {
|
|
33
|
+
* await walletClient.sendTransaction({
|
|
34
|
+
* to: tx.to,
|
|
35
|
+
* data: tx.data,
|
|
36
|
+
* value: tx.value,
|
|
37
|
+
* });
|
|
38
|
+
* }
|
|
39
|
+
* ```
|
|
40
|
+
*/
|
|
41
|
+
export const getMidnightAuthorizationRequirement = async (params) => {
|
|
42
|
+
validateChainId(params.viemClient.chain?.id, params.chainId);
|
|
43
|
+
// Reject unknown operators before reading authorization state.
|
|
44
|
+
validateMidnightAuthorizationTarget({
|
|
45
|
+
chainId: params.chainId,
|
|
46
|
+
authorized: params.authorized,
|
|
47
|
+
});
|
|
48
|
+
const midnight = getChainAddress(params.chainId, "midnight");
|
|
49
|
+
const isAuthorized = await readContract(params.viemClient, {
|
|
50
|
+
address: midnight,
|
|
51
|
+
abi: midnightAbi,
|
|
52
|
+
functionName: "isAuthorized",
|
|
53
|
+
args: [params.owner, params.authorized],
|
|
54
|
+
});
|
|
55
|
+
if (isAuthorized)
|
|
56
|
+
return null;
|
|
57
|
+
return deepFreeze({
|
|
58
|
+
to: midnight,
|
|
59
|
+
value: 0n,
|
|
60
|
+
data: encodeFunctionData({
|
|
61
|
+
abi: midnightAbi,
|
|
62
|
+
functionName: "setIsAuthorized",
|
|
63
|
+
args: [params.authorized, true, params.owner],
|
|
64
|
+
}),
|
|
65
|
+
action: {
|
|
66
|
+
type: "midnightAuthorization",
|
|
67
|
+
args: {
|
|
68
|
+
authorized: params.authorized,
|
|
69
|
+
isAuthorized: true,
|
|
70
|
+
onBehalf: params.owner,
|
|
71
|
+
},
|
|
72
|
+
},
|
|
73
|
+
});
|
|
74
|
+
};
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { type Address, type Client, type Hex } from "viem";
|
|
2
|
+
import type { SetterRatifierRatifyRootAction, Transaction } from "../../../types/index.js";
|
|
3
|
+
/** Parameters for {@link getSetterRatifierRatifyRootRequirement}. */
|
|
4
|
+
export interface GetSetterRatifierRatifyRootRequirementParams {
|
|
5
|
+
readonly viemClient: Client;
|
|
6
|
+
readonly chainId: number;
|
|
7
|
+
readonly maker: Address;
|
|
8
|
+
readonly root: Hex;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Resolves the SetterRatifier root approval transaction for a maker offer tree.
|
|
12
|
+
*
|
|
13
|
+
* Call after building a Setter-ratified tree and before encoding/submitting its
|
|
14
|
+
* payload. Entity make-offer flows call this from `getRequirements()` and omit
|
|
15
|
+
* the transaction when the maker has already approved the root.
|
|
16
|
+
*
|
|
17
|
+
* @param params.viemClient - Viem client used to read root approval state.
|
|
18
|
+
* @param params.chainId - Chain id expected by the viem client.
|
|
19
|
+
* @param params.maker - Maker whose root approval is checked.
|
|
20
|
+
* @param params.root - Offer-tree root that must be approved.
|
|
21
|
+
* @returns Ratify-root transaction, or `null` when the root is already ratified.
|
|
22
|
+
* @throws {ChainIdMismatchError} when the viem client is connected to another chain.
|
|
23
|
+
* @example
|
|
24
|
+
* ```ts
|
|
25
|
+
* import { getSetterRatifierRatifyRootRequirement } from "@morpho-org/morpho-sdk";
|
|
26
|
+
*
|
|
27
|
+
* const tx = await getSetterRatifierRatifyRootRequirement({
|
|
28
|
+
* viemClient: client,
|
|
29
|
+
* chainId: 8453,
|
|
30
|
+
* maker: user,
|
|
31
|
+
* root,
|
|
32
|
+
* });
|
|
33
|
+
* if (tx) {
|
|
34
|
+
* await walletClient.sendTransaction({
|
|
35
|
+
* to: tx.to,
|
|
36
|
+
* data: tx.data,
|
|
37
|
+
* value: tx.value,
|
|
38
|
+
* });
|
|
39
|
+
* }
|
|
40
|
+
* ```
|
|
41
|
+
*/
|
|
42
|
+
export declare const getSetterRatifierRatifyRootRequirement: (params: GetSetterRatifierRatifyRootRequirementParams) => Promise<Readonly<Transaction<SetterRatifierRatifyRootAction>> | null>;
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { setterRatifierAbi } from "@morpho-org/midnight-sdk";
|
|
2
|
+
import { deepFreeze, getChainAddress } from "@morpho-org/morpho-ts";
|
|
3
|
+
import { encodeFunctionData } from "viem";
|
|
4
|
+
import { readContract } from "viem/actions";
|
|
5
|
+
import { validateChainId } from "../../../helpers/index.js";
|
|
6
|
+
/**
|
|
7
|
+
* Resolves the SetterRatifier root approval transaction for a maker offer tree.
|
|
8
|
+
*
|
|
9
|
+
* Call after building a Setter-ratified tree and before encoding/submitting its
|
|
10
|
+
* payload. Entity make-offer flows call this from `getRequirements()` and omit
|
|
11
|
+
* the transaction when the maker has already approved the root.
|
|
12
|
+
*
|
|
13
|
+
* @param params.viemClient - Viem client used to read root approval state.
|
|
14
|
+
* @param params.chainId - Chain id expected by the viem client.
|
|
15
|
+
* @param params.maker - Maker whose root approval is checked.
|
|
16
|
+
* @param params.root - Offer-tree root that must be approved.
|
|
17
|
+
* @returns Ratify-root transaction, or `null` when the root is already ratified.
|
|
18
|
+
* @throws {ChainIdMismatchError} when the viem client is connected to another chain.
|
|
19
|
+
* @example
|
|
20
|
+
* ```ts
|
|
21
|
+
* import { getSetterRatifierRatifyRootRequirement } from "@morpho-org/morpho-sdk";
|
|
22
|
+
*
|
|
23
|
+
* const tx = await getSetterRatifierRatifyRootRequirement({
|
|
24
|
+
* viemClient: client,
|
|
25
|
+
* chainId: 8453,
|
|
26
|
+
* maker: user,
|
|
27
|
+
* root,
|
|
28
|
+
* });
|
|
29
|
+
* if (tx) {
|
|
30
|
+
* await walletClient.sendTransaction({
|
|
31
|
+
* to: tx.to,
|
|
32
|
+
* data: tx.data,
|
|
33
|
+
* value: tx.value,
|
|
34
|
+
* });
|
|
35
|
+
* }
|
|
36
|
+
* ```
|
|
37
|
+
*/
|
|
38
|
+
export const getSetterRatifierRatifyRootRequirement = async (params) => {
|
|
39
|
+
validateChainId(params.viemClient.chain?.id, params.chainId);
|
|
40
|
+
const setterRatifier = getChainAddress(params.chainId, "setterRatifier");
|
|
41
|
+
const isRootRatified = await readContract(params.viemClient, {
|
|
42
|
+
address: setterRatifier,
|
|
43
|
+
abi: setterRatifierAbi,
|
|
44
|
+
functionName: "isRootRatified",
|
|
45
|
+
args: [params.maker, params.root],
|
|
46
|
+
});
|
|
47
|
+
if (isRootRatified)
|
|
48
|
+
return null;
|
|
49
|
+
return deepFreeze({
|
|
50
|
+
to: setterRatifier,
|
|
51
|
+
value: 0n,
|
|
52
|
+
data: encodeFunctionData({
|
|
53
|
+
abi: setterRatifierAbi,
|
|
54
|
+
functionName: "setIsRootRatified",
|
|
55
|
+
args: [params.maker, params.root, true],
|
|
56
|
+
}),
|
|
57
|
+
action: {
|
|
58
|
+
type: "setterRatifierRatifyRoot",
|
|
59
|
+
args: {
|
|
60
|
+
maker: params.maker,
|
|
61
|
+
root: params.root,
|
|
62
|
+
isRootRatified: true,
|
|
63
|
+
},
|
|
64
|
+
},
|
|
65
|
+
});
|
|
66
|
+
};
|
|
@@ -39,9 +39,9 @@ export interface VaultV1DepositParams {
|
|
|
39
39
|
* @param params.metadata - Optional analytics metadata attached to the bundle.
|
|
40
40
|
* @returns A deep-frozen `Transaction<VaultV1DepositAction>` with `to`, `value`, `data`, and the
|
|
41
41
|
* typed `action` discriminator the simulation layer consumes.
|
|
42
|
-
* @throws {
|
|
43
|
-
* @throws {
|
|
44
|
-
*
|
|
42
|
+
* @throws {NegativeInputError} when `amount < 0n` or `nativeAmount < 0n`.
|
|
43
|
+
* @throws {NonPositiveInputError} when `maxSharePrice <= 0n`, or when both `amount` and
|
|
44
|
+
* `nativeAmount` resolve to zero.
|
|
45
45
|
* @throws {ChainWNativeMissingError} when `nativeAmount` is provided but the chain has no
|
|
46
46
|
* configured wNative.
|
|
47
47
|
* @throws {NativeAmountOnNonWNativeVaultError} when `nativeAmount` is provided but the vault
|
|
@@ -53,7 +53,6 @@ export interface VaultV1DepositParams {
|
|
|
53
53
|
* `requirementSignature` is provided and the signed amount differs from `args.amount`.
|
|
54
54
|
* @throws {Permit2ExpirationMissingError} from `getTokenRequirementActions` when `amount > 0n` and a
|
|
55
55
|
* Permit2 requirement signature is missing its expiration.
|
|
56
|
-
* @throws {ZeroDepositAmountError} when both `amount` and `nativeAmount` resolve to zero.
|
|
57
56
|
* @example
|
|
58
57
|
* ```ts
|
|
59
58
|
* import { vaultV1Deposit } from "@morpho-org/morpho-sdk";
|
|
@@ -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 VaultV1 (MetaMorpho) 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<VaultV1DepositAction>` 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 { vaultV1Deposit } from "@morpho-org/morpho-sdk";
|
|
@@ -62,16 +61,16 @@ import { getTokenRequirementActions } from "../signatures/getTokenRequirementAct
|
|
|
62
61
|
*/
|
|
63
62
|
export const vaultV1Deposit = ({ 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 vaultV1Deposit = ({ 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",
|
|
@@ -56,9 +56,8 @@ export interface VaultV1MigrateToV2Params {
|
|
|
56
56
|
* @returns A deep-frozen `Transaction<VaultV1MigrateToV2Action>` with `to`, `value`, `data`, and
|
|
57
57
|
* the typed `action` discriminator the simulation layer consumes.
|
|
58
58
|
* @throws {VaultAssetMismatchError} when `targetAsset` differs from `vault.asset`.
|
|
59
|
-
* @throws {
|
|
60
|
-
* @throws {
|
|
61
|
-
* @throws {NonPositiveMaxSharePriceError} when `maxSharePriceVaultV2 <= 0n`.
|
|
59
|
+
* @throws {NonPositiveInputError} when `shares <= 0n` or `maxSharePriceVaultV2 <= 0n`.
|
|
60
|
+
* @throws {NegativeInputError} when `minSharePriceVaultV1 < 0n`.
|
|
62
61
|
* @throws {DepositAssetMismatchError} from `getTokenRequirementActions` when `requirementSignature`
|
|
63
62
|
* is provided and the signed asset differs from `vault.address` (the V1 share token).
|
|
64
63
|
* @throws {DepositAmountMismatchError} from `getTokenRequirementActions` when `requirementSignature`
|
|
@@ -3,7 +3,7 @@ import { deepFreeze } from "@morpho-org/morpho-ts";
|
|
|
3
3
|
import { isAddressEqual, maxUint256 } from "viem";
|
|
4
4
|
import { BundlerAction } from "../../bundler/index.js";
|
|
5
5
|
import { addTransactionMetadata } from "../../helpers/index.js";
|
|
6
|
-
import {
|
|
6
|
+
import { NegativeInputError, NonPositiveInputError, VaultAssetMismatchError, } from "../../types/index.js";
|
|
7
7
|
import { getTokenRequirementActions } from "../signatures/getTokenRequirementActions.js";
|
|
8
8
|
/**
|
|
9
9
|
* Prepares an atomic full-migration transaction from VaultV1 to VaultV2.
|
|
@@ -36,9 +36,8 @@ import { getTokenRequirementActions } from "../signatures/getTokenRequirementAct
|
|
|
36
36
|
* @returns A deep-frozen `Transaction<VaultV1MigrateToV2Action>` with `to`, `value`, `data`, and
|
|
37
37
|
* the typed `action` discriminator the simulation layer consumes.
|
|
38
38
|
* @throws {VaultAssetMismatchError} when `targetAsset` differs from `vault.asset`.
|
|
39
|
-
* @throws {
|
|
40
|
-
* @throws {
|
|
41
|
-
* @throws {NonPositiveMaxSharePriceError} when `maxSharePriceVaultV2 <= 0n`.
|
|
39
|
+
* @throws {NonPositiveInputError} when `shares <= 0n` or `maxSharePriceVaultV2 <= 0n`.
|
|
40
|
+
* @throws {NegativeInputError} when `minSharePriceVaultV1 < 0n`.
|
|
42
41
|
* @throws {DepositAssetMismatchError} from `getTokenRequirementActions` when `requirementSignature`
|
|
43
42
|
* is provided and the signed asset differs from `vault.address` (the V1 share token).
|
|
44
43
|
* @throws {DepositAmountMismatchError} from `getTokenRequirementActions` when `requirementSignature`
|
|
@@ -70,13 +69,13 @@ export const vaultV1MigrateToV2 = ({ vault: { chainId, address: sourceVault, ass
|
|
|
70
69
|
throw new VaultAssetMismatchError(sourceAsset, targetAsset);
|
|
71
70
|
}
|
|
72
71
|
if (shares <= 0n) {
|
|
73
|
-
throw new
|
|
72
|
+
throw new NonPositiveInputError("shares", shares);
|
|
74
73
|
}
|
|
75
74
|
if (minSharePriceVaultV1 < 0n) {
|
|
76
|
-
throw new
|
|
75
|
+
throw new NegativeInputError("minSharePriceVaultV1", minSharePriceVaultV1);
|
|
77
76
|
}
|
|
78
77
|
if (maxSharePriceVaultV2 <= 0n) {
|
|
79
|
-
throw new
|
|
78
|
+
throw new NonPositiveInputError("maxSharePriceVaultV2", maxSharePriceVaultV2);
|
|
80
79
|
}
|
|
81
80
|
const { bundler3: { generalAdapter1 }, } = getChainAddresses(chainId);
|
|
82
81
|
const actions = [];
|
|
@@ -24,7 +24,7 @@ export interface VaultV1RedeemParams {
|
|
|
24
24
|
* @param params.metadata - Optional analytics metadata attached to the transaction.
|
|
25
25
|
* @returns A deep-frozen `Transaction<VaultV1RedeemAction>` with `to`, `value`, `data`, and the
|
|
26
26
|
* typed `action` discriminator the simulation layer consumes.
|
|
27
|
-
* @throws {
|
|
27
|
+
* @throws {NonPositiveInputError} when `shares <= 0n`.
|
|
28
28
|
* @example
|
|
29
29
|
* ```ts
|
|
30
30
|
* import { vaultV1Redeem } from "@morpho-org/morpho-sdk";
|
|
@@ -2,7 +2,7 @@ import { metaMorphoAbi } 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 VaultV1 (MetaMorpho) contract.
|
|
8
8
|
*
|
|
@@ -15,7 +15,7 @@ import { NonPositiveSharesAmountError, } from "../../types/index.js";
|
|
|
15
15
|
* @param params.metadata - Optional analytics metadata attached to the transaction.
|
|
16
16
|
* @returns A deep-frozen `Transaction<VaultV1RedeemAction>` with `to`, `value`, `data`, and the
|
|
17
17
|
* typed `action` discriminator the simulation layer consumes.
|
|
18
|
-
* @throws {
|
|
18
|
+
* @throws {NonPositiveInputError} when `shares <= 0n`.
|
|
19
19
|
* @example
|
|
20
20
|
* ```ts
|
|
21
21
|
* import { vaultV1Redeem } from "@morpho-org/morpho-sdk";
|
|
@@ -29,7 +29,7 @@ import { NonPositiveSharesAmountError, } from "../../types/index.js";
|
|
|
29
29
|
*/
|
|
30
30
|
export const vaultV1Redeem = ({ vault: { address: vaultAddress }, args: { shares, recipient, onBehalf }, metadata, }) => {
|
|
31
31
|
if (shares <= 0n) {
|
|
32
|
-
throw new
|
|
32
|
+
throw new NonPositiveInputError("shares", shares);
|
|
33
33
|
}
|
|
34
34
|
let tx = {
|
|
35
35
|
to: vaultAddress,
|
|
@@ -24,7 +24,7 @@ export interface VaultV1WithdrawParams {
|
|
|
24
24
|
* @param params.metadata - Optional analytics metadata attached to the transaction.
|
|
25
25
|
* @returns A deep-frozen `Transaction<VaultV1WithdrawAction>` with `to`, `value`, `data`, and the
|
|
26
26
|
* typed `action` discriminator the simulation layer consumes.
|
|
27
|
-
* @throws {
|
|
27
|
+
* @throws {NonPositiveInputError} when `amount <= 0n`.
|
|
28
28
|
* @example
|
|
29
29
|
* ```ts
|
|
30
30
|
* import { vaultV1Withdraw } from "@morpho-org/morpho-sdk";
|
|
@@ -2,7 +2,7 @@ import { metaMorphoAbi } 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 VaultV1 (MetaMorpho) contract.
|
|
8
8
|
*
|
|
@@ -15,7 +15,7 @@ import { NonPositiveAssetAmountError, } from "../../types/index.js";
|
|
|
15
15
|
* @param params.metadata - Optional analytics metadata attached to the transaction.
|
|
16
16
|
* @returns A deep-frozen `Transaction<VaultV1WithdrawAction>` with `to`, `value`, `data`, and the
|
|
17
17
|
* typed `action` discriminator the simulation layer consumes.
|
|
18
|
-
* @throws {
|
|
18
|
+
* @throws {NonPositiveInputError} when `amount <= 0n`.
|
|
19
19
|
* @example
|
|
20
20
|
* ```ts
|
|
21
21
|
* import { vaultV1Withdraw } from "@morpho-org/morpho-sdk";
|
|
@@ -29,7 +29,7 @@ import { NonPositiveAssetAmountError, } from "../../types/index.js";
|
|
|
29
29
|
*/
|
|
30
30
|
export const vaultV1Withdraw = ({ vault: { address: vaultAddress }, args: { amount, recipient, onBehalf }, metadata, }) => {
|
|
31
31
|
if (amount <= 0n) {
|
|
32
|
-
throw new
|
|
32
|
+
throw new NonPositiveInputError("amount", amount);
|
|
33
33
|
}
|
|
34
34
|
let tx = {
|
|
35
35
|
to: vaultAddress,
|
|
@@ -39,9 +39,9 @@ export interface VaultV2DepositParams {
|
|
|
39
39
|
* @param params.metadata - Optional analytics metadata attached to the bundle.
|
|
40
40
|
* @returns A deep-frozen `Transaction<VaultV2DepositAction>` with `to`, `value`, `data`, and the
|
|
41
41
|
* typed `action` discriminator the simulation layer consumes.
|
|
42
|
-
* @throws {
|
|
43
|
-
* @throws {
|
|
44
|
-
*
|
|
42
|
+
* @throws {NegativeInputError} when `amount < 0n` or `nativeAmount < 0n`.
|
|
43
|
+
* @throws {NonPositiveInputError} when `maxSharePrice <= 0n`, or when both `amount` and
|
|
44
|
+
* `nativeAmount` resolve to zero.
|
|
45
45
|
* @throws {ChainWNativeMissingError} when `nativeAmount` is provided but the chain has no
|
|
46
46
|
* configured wNative.
|
|
47
47
|
* @throws {NativeAmountOnNonWNativeVaultError} when `nativeAmount` is provided but the vault
|
|
@@ -53,7 +53,6 @@ export interface VaultV2DepositParams {
|
|
|
53
53
|
* `requirementSignature` is provided and the signed amount differs from `args.amount`.
|
|
54
54
|
* @throws {Permit2ExpirationMissingError} from `getTokenRequirementActions` when `amount > 0n` and a
|
|
55
55
|
* Permit2 requirement signature is missing its expiration.
|
|
56
|
-
* @throws {ZeroDepositAmountError} when both `amount` and `nativeAmount` resolve to zero.
|
|
57
56
|
* @example
|
|
58
57
|
* ```ts
|
|
59
58
|
* import { vaultV2Deposit } from "@morpho-org/morpho-sdk";
|