@morpho-org/morpho-sdk 10.0.1 → 10.1.0-next.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 +31 -10
- package/lib/cjs/abis.d.ts +1 -1
- package/lib/cjs/abis.js +5 -1
- package/lib/cjs/actions/blue/refinance.d.ts +1 -1
- package/lib/cjs/actions/blue/refinance.js +3 -8
- package/lib/cjs/actions/blue/refinanceValidation.d.ts +19 -0
- package/lib/cjs/actions/blue/refinanceValidation.js +46 -0
- package/lib/cjs/actions/requirements/encode/encodeErc20Approval.d.ts +1 -1
- package/lib/cjs/actions/requirements/encode/encodeErc20Approval.js +3 -7
- package/lib/cjs/actions/requirements/encode/encodeErc20Permit.d.ts +1 -1
- package/lib/cjs/actions/requirements/encode/encodeErc20Permit.js +4 -20
- package/lib/cjs/actions/requirements/getRequirementsApproval.js +7 -21
- package/lib/cjs/actions/requirements/validateClientChainId.d.ts +1 -26
- package/lib/cjs/actions/requirements/validateClientChainId.js +2 -31
- package/lib/cjs/actions/vaultV2/forceRedeem.d.ts +2 -1
- package/lib/cjs/actions/vaultV2/forceRedeem.js +20 -2
- package/lib/cjs/blue/abis.d.ts +1 -1
- package/lib/cjs/blue/abis.js +5 -1
- package/lib/cjs/blue/entities.d.ts +4 -4
- package/lib/cjs/blue/entities.js +3 -1
- package/lib/cjs/blue/errors.d.ts +2 -2
- package/lib/cjs/blue/errors.js +5 -1
- package/lib/cjs/blue/fetch.d.ts +2 -2
- package/lib/cjs/blue/fetch.js +3 -1
- package/lib/cjs/blue/utils.d.ts +1 -1
- package/lib/cjs/blue/utils.js +2 -1
- package/lib/cjs/entities/blue/blue.js +24 -55
- package/lib/cjs/entities/index.d.ts +4 -4
- package/lib/cjs/entities/index.js +3 -1
- package/lib/cjs/entities/requirements/getErc2612Permit.d.ts +2 -5
- package/lib/cjs/entities/requirements/getErc2612Permit.js +9 -58
- package/lib/cjs/entities/vaultV2/vaultV2.d.ts +34 -8
- package/lib/cjs/entities/vaultV2/vaultV2.js +39 -1
- package/lib/cjs/entities/vaultV2BlueReallocationData.d.ts +3 -2
- package/lib/cjs/entities/vaultV2BlueReallocationData.js +6 -2
- package/lib/cjs/errors.d.ts +4 -4
- package/lib/cjs/errors.js +7 -5
- package/lib/cjs/fetch.d.ts +2 -2
- package/lib/cjs/fetch.js +3 -1
- package/lib/cjs/helpers/deadShares.js +3 -0
- package/lib/cjs/helpers/quoteBlueRepay.d.ts +16 -0
- package/lib/cjs/helpers/quoteBlueRepay.js +46 -0
- package/lib/cjs/helpers/tokenApproval.d.ts +14 -0
- package/lib/cjs/helpers/tokenApproval.js +20 -0
- package/lib/cjs/helpers/validate.d.ts +1 -1
- package/lib/cjs/helpers/validate.js +2 -2
- package/lib/cjs/index.d.ts +2 -2
- package/lib/cjs/index.js +13 -1
- package/lib/cjs/midnight/errors.d.ts +2 -1
- package/lib/cjs/midnight/errors.js +5 -4
- package/lib/cjs/reads/readErc2612Permit.d.ts +22 -0
- package/lib/cjs/reads/readErc2612Permit.js +77 -0
- package/lib/cjs/reads/validateClientChainId.d.ts +26 -0
- package/lib/cjs/reads/validateClientChainId.js +34 -0
- package/lib/cjs/transactionPlan/blue/authorization.d.ts +23 -0
- package/lib/cjs/transactionPlan/blue/authorization.js +128 -0
- package/lib/cjs/transactionPlan/blue/borrow.d.ts +80 -0
- package/lib/cjs/transactionPlan/blue/borrow.js +248 -0
- package/lib/cjs/transactionPlan/blue/prepare.d.ts +102 -0
- package/lib/cjs/transactionPlan/blue/prepare.js +191 -0
- package/lib/cjs/transactionPlan/blue/refinance.d.ts +93 -0
- package/lib/cjs/transactionPlan/blue/refinance.js +281 -0
- package/lib/cjs/transactionPlan/blue/refinanceValidation.d.ts +11 -0
- package/lib/cjs/transactionPlan/blue/refinanceValidation.js +20 -0
- package/lib/cjs/transactionPlan/blue/repay.d.ts +80 -0
- package/lib/cjs/transactionPlan/blue/repay.js +229 -0
- package/lib/cjs/transactionPlan/blue/repayWithdrawCollateral.d.ts +98 -0
- package/lib/cjs/transactionPlan/blue/repayWithdrawCollateral.js +379 -0
- package/lib/cjs/transactionPlan/blue/supply.d.ts +181 -0
- package/lib/cjs/transactionPlan/blue/supply.js +238 -0
- package/lib/cjs/transactionPlan/blue/supplyCollateral.d.ts +97 -0
- package/lib/cjs/transactionPlan/blue/supplyCollateral.js +231 -0
- package/lib/cjs/transactionPlan/blue/supplyCollateralBorrow.d.ts +102 -0
- package/lib/cjs/transactionPlan/blue/supplyCollateralBorrow.js +395 -0
- package/lib/cjs/transactionPlan/blue/withdraw.d.ts +136 -0
- package/lib/cjs/transactionPlan/blue/withdraw.js +340 -0
- package/lib/cjs/transactionPlan/blue/withdrawCollateral.d.ts +123 -0
- package/lib/cjs/transactionPlan/blue/withdrawCollateral.js +246 -0
- package/lib/cjs/transactionPlan/deposit.js +8 -19
- package/lib/cjs/transactionPlan/error.d.ts +50 -0
- package/lib/cjs/transactionPlan/error.js +60 -1
- package/lib/cjs/transactionPlan/getTokenPermit.d.ts +17 -8
- package/lib/cjs/transactionPlan/getTokenPermit.js +35 -7
- package/lib/cjs/transactionPlan/index.d.ts +21 -1
- package/lib/cjs/transactionPlan/index.js +27 -5
- package/lib/cjs/transactionPlan/intent.d.ts +2 -2
- package/lib/cjs/transactionPlan/intent.js +8 -4
- package/lib/cjs/transactionPlan/permit.d.ts +16 -2
- package/lib/cjs/transactionPlan/permit.js +77 -45
- package/lib/cjs/transactionPlan/plan.d.ts +67 -12
- package/lib/cjs/transactionPlan/plan.js +284 -50
- package/lib/cjs/transactionPlan/requirements.d.ts +14 -5
- package/lib/cjs/transactionPlan/requirements.js +30 -12
- package/lib/cjs/transactionPlan/serde.d.ts +7 -4
- package/lib/cjs/transactionPlan/serde.js +80 -61
- package/lib/cjs/transactionPlan/types.d.ts +141 -13
- package/lib/cjs/transactionPlan/validateActions.js +11 -1
- package/lib/cjs/transactionPlan/validation.d.ts +8 -0
- package/lib/cjs/transactionPlan/validation.js +90 -0
- package/lib/cjs/transactionPlan/vaultv1/deposit.d.ts +1 -0
- package/lib/cjs/transactionPlan/vaultv1/deposit.js +1 -0
- package/lib/cjs/transactionPlan/vaultv1/inKindRedeem.d.ts +1 -0
- package/lib/cjs/transactionPlan/vaultv1/inKindRedeem.js +1 -0
- package/lib/cjs/transactionPlan/vaultv1/migrateToV2.d.ts +1 -0
- package/lib/cjs/transactionPlan/vaultv1/migrateToV2.js +1 -0
- package/lib/cjs/transactionPlan/vaultv1/redeem.d.ts +1 -0
- package/lib/cjs/transactionPlan/vaultv1/redeem.js +1 -0
- package/lib/cjs/transactionPlan/vaultv1/withdraw.d.ts +1 -0
- package/lib/cjs/transactionPlan/vaultv1/withdraw.js +1 -0
- package/lib/cjs/transactionPlan/vaultv2/deposit.d.ts +1 -0
- package/lib/cjs/transactionPlan/vaultv2/deposit.js +1 -0
- package/lib/cjs/transactionPlan/vaultv2/forceRedeem.d.ts +1 -0
- package/lib/cjs/transactionPlan/vaultv2/forceRedeem.js +1 -0
- package/lib/cjs/transactionPlan/vaultv2/forceWithdraw.d.ts +1 -0
- package/lib/cjs/transactionPlan/vaultv2/forceWithdraw.js +1 -0
- package/lib/cjs/transactionPlan/vaultv2/inKindRedeem.d.ts +1 -0
- package/lib/cjs/transactionPlan/vaultv2/inKindRedeem.js +1 -0
- package/lib/cjs/transactionPlan/vaultv2/redeem.d.ts +1 -0
- package/lib/cjs/transactionPlan/vaultv2/redeem.js +1 -0
- package/lib/cjs/transactionPlan/vaultv2/withdraw.d.ts +1 -0
- package/lib/cjs/transactionPlan/vaultv2/withdraw.js +1 -0
- package/lib/cjs/utils.d.ts +2 -2
- package/lib/cjs/utils.js +4 -2
- package/lib/cjs/version.d.ts +1 -1
- package/lib/cjs/version.js +1 -1
- package/lib/esm/abis.d.ts +1 -1
- package/lib/esm/abis.js +1 -1
- package/lib/esm/actions/blue/refinance.d.ts +1 -1
- package/lib/esm/actions/blue/refinance.js +4 -9
- package/lib/esm/actions/blue/refinanceValidation.d.ts +19 -0
- package/lib/esm/actions/blue/refinanceValidation.js +41 -0
- package/lib/esm/actions/requirements/encode/encodeErc20Approval.d.ts +1 -1
- package/lib/esm/actions/requirements/encode/encodeErc20Approval.js +4 -8
- package/lib/esm/actions/requirements/encode/encodeErc20Permit.d.ts +1 -1
- package/lib/esm/actions/requirements/encode/encodeErc20Permit.js +5 -21
- package/lib/esm/actions/requirements/getRequirementsApproval.js +7 -21
- package/lib/esm/actions/requirements/validateClientChainId.d.ts +1 -26
- package/lib/esm/actions/requirements/validateClientChainId.js +1 -30
- package/lib/esm/actions/vaultV2/forceRedeem.d.ts +2 -1
- package/lib/esm/actions/vaultV2/forceRedeem.js +20 -2
- package/lib/esm/blue/abis.d.ts +1 -1
- package/lib/esm/blue/abis.js +1 -1
- package/lib/esm/blue/entities.d.ts +4 -4
- package/lib/esm/blue/entities.js +2 -2
- package/lib/esm/blue/errors.d.ts +2 -2
- package/lib/esm/blue/errors.js +2 -2
- package/lib/esm/blue/fetch.d.ts +2 -2
- package/lib/esm/blue/fetch.js +2 -2
- package/lib/esm/blue/utils.d.ts +1 -1
- package/lib/esm/blue/utils.js +1 -1
- package/lib/esm/entities/blue/blue.js +26 -57
- package/lib/esm/entities/index.d.ts +4 -4
- package/lib/esm/entities/index.js +2 -2
- package/lib/esm/entities/requirements/getErc2612Permit.d.ts +2 -5
- package/lib/esm/entities/requirements/getErc2612Permit.js +9 -58
- package/lib/esm/entities/vaultV2/vaultV2.d.ts +34 -8
- package/lib/esm/entities/vaultV2/vaultV2.js +40 -2
- package/lib/esm/entities/vaultV2BlueReallocationData.d.ts +3 -2
- package/lib/esm/entities/vaultV2BlueReallocationData.js +6 -2
- package/lib/esm/errors.d.ts +4 -4
- package/lib/esm/errors.js +4 -4
- package/lib/esm/fetch.d.ts +2 -2
- package/lib/esm/fetch.js +2 -2
- package/lib/esm/helpers/deadShares.js +4 -1
- package/lib/esm/helpers/quoteBlueRepay.d.ts +16 -0
- package/lib/esm/helpers/quoteBlueRepay.js +42 -0
- package/lib/esm/helpers/tokenApproval.d.ts +14 -0
- package/lib/esm/helpers/tokenApproval.js +16 -0
- package/lib/esm/helpers/validate.d.ts +1 -1
- package/lib/esm/helpers/validate.js +3 -3
- package/lib/esm/index.d.ts +2 -2
- package/lib/esm/index.js +1 -1
- package/lib/esm/midnight/errors.d.ts +2 -1
- package/lib/esm/midnight/errors.js +2 -1
- package/lib/esm/reads/readErc2612Permit.d.ts +22 -0
- package/lib/esm/reads/readErc2612Permit.js +73 -0
- package/lib/esm/reads/validateClientChainId.d.ts +26 -0
- package/lib/esm/reads/validateClientChainId.js +30 -0
- package/lib/esm/transactionPlan/blue/authorization.d.ts +23 -0
- package/lib/esm/transactionPlan/blue/authorization.js +122 -0
- package/lib/esm/transactionPlan/blue/borrow.d.ts +80 -0
- package/lib/esm/transactionPlan/blue/borrow.js +243 -0
- package/lib/esm/transactionPlan/blue/prepare.d.ts +102 -0
- package/lib/esm/transactionPlan/blue/prepare.js +187 -0
- package/lib/esm/transactionPlan/blue/refinance.d.ts +93 -0
- package/lib/esm/transactionPlan/blue/refinance.js +276 -0
- package/lib/esm/transactionPlan/blue/refinanceValidation.d.ts +11 -0
- package/lib/esm/transactionPlan/blue/refinanceValidation.js +17 -0
- package/lib/esm/transactionPlan/blue/repay.d.ts +80 -0
- package/lib/esm/transactionPlan/blue/repay.js +223 -0
- package/lib/esm/transactionPlan/blue/repayWithdrawCollateral.d.ts +98 -0
- package/lib/esm/transactionPlan/blue/repayWithdrawCollateral.js +373 -0
- package/lib/esm/transactionPlan/blue/supply.d.ts +181 -0
- package/lib/esm/transactionPlan/blue/supply.js +232 -0
- package/lib/esm/transactionPlan/blue/supplyCollateral.d.ts +97 -0
- package/lib/esm/transactionPlan/blue/supplyCollateral.js +225 -0
- package/lib/esm/transactionPlan/blue/supplyCollateralBorrow.d.ts +102 -0
- package/lib/esm/transactionPlan/blue/supplyCollateralBorrow.js +389 -0
- package/lib/esm/transactionPlan/blue/withdraw.d.ts +136 -0
- package/lib/esm/transactionPlan/blue/withdraw.js +334 -0
- package/lib/esm/transactionPlan/blue/withdrawCollateral.d.ts +123 -0
- package/lib/esm/transactionPlan/blue/withdrawCollateral.js +240 -0
- package/lib/esm/transactionPlan/deposit.js +9 -20
- package/lib/esm/transactionPlan/error.d.ts +50 -0
- package/lib/esm/transactionPlan/error.js +57 -0
- package/lib/esm/transactionPlan/getTokenPermit.d.ts +17 -8
- package/lib/esm/transactionPlan/getTokenPermit.js +35 -7
- package/lib/esm/transactionPlan/index.d.ts +21 -1
- package/lib/esm/transactionPlan/index.js +11 -1
- package/lib/esm/transactionPlan/intent.d.ts +2 -2
- package/lib/esm/transactionPlan/intent.js +8 -4
- package/lib/esm/transactionPlan/permit.d.ts +16 -2
- package/lib/esm/transactionPlan/permit.js +76 -44
- package/lib/esm/transactionPlan/plan.d.ts +67 -12
- package/lib/esm/transactionPlan/plan.js +279 -46
- package/lib/esm/transactionPlan/requirements.d.ts +14 -5
- package/lib/esm/transactionPlan/requirements.js +30 -12
- package/lib/esm/transactionPlan/serde.d.ts +7 -4
- package/lib/esm/transactionPlan/serde.js +73 -54
- package/lib/esm/transactionPlan/types.d.ts +141 -13
- package/lib/esm/transactionPlan/validateActions.js +11 -1
- package/lib/esm/transactionPlan/validation.d.ts +8 -0
- package/lib/esm/transactionPlan/validation.js +88 -1
- package/lib/esm/transactionPlan/vaultv1/deposit.d.ts +1 -0
- package/lib/esm/transactionPlan/vaultv1/deposit.js +1 -0
- package/lib/esm/transactionPlan/vaultv1/inKindRedeem.d.ts +1 -0
- package/lib/esm/transactionPlan/vaultv1/inKindRedeem.js +1 -0
- package/lib/esm/transactionPlan/vaultv1/migrateToV2.d.ts +1 -0
- package/lib/esm/transactionPlan/vaultv1/migrateToV2.js +1 -0
- package/lib/esm/transactionPlan/vaultv1/redeem.d.ts +1 -0
- package/lib/esm/transactionPlan/vaultv1/redeem.js +1 -0
- package/lib/esm/transactionPlan/vaultv1/withdraw.d.ts +1 -0
- package/lib/esm/transactionPlan/vaultv1/withdraw.js +1 -0
- package/lib/esm/transactionPlan/vaultv2/deposit.d.ts +1 -0
- package/lib/esm/transactionPlan/vaultv2/deposit.js +1 -0
- package/lib/esm/transactionPlan/vaultv2/forceRedeem.d.ts +1 -0
- package/lib/esm/transactionPlan/vaultv2/forceRedeem.js +1 -0
- package/lib/esm/transactionPlan/vaultv2/forceWithdraw.d.ts +1 -0
- package/lib/esm/transactionPlan/vaultv2/forceWithdraw.js +1 -0
- package/lib/esm/transactionPlan/vaultv2/inKindRedeem.d.ts +1 -0
- package/lib/esm/transactionPlan/vaultv2/inKindRedeem.js +1 -0
- package/lib/esm/transactionPlan/vaultv2/redeem.d.ts +1 -0
- package/lib/esm/transactionPlan/vaultv2/redeem.js +1 -0
- package/lib/esm/transactionPlan/vaultv2/withdraw.d.ts +1 -0
- package/lib/esm/transactionPlan/vaultv2/withdraw.js +1 -0
- package/lib/esm/utils.d.ts +2 -2
- package/lib/esm/utils.js +2 -2
- package/lib/esm/version.d.ts +1 -1
- package/lib/esm/version.js +1 -1
- package/package.json +7 -7
|
@@ -0,0 +1,229 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.prepareBlueRepay = prepareBlueRepay;
|
|
4
|
+
exports.validateBlueRepayPermit = validateBlueRepayPermit;
|
|
5
|
+
exports.buildBlueRepay = buildBlueRepay;
|
|
6
|
+
exports.validateBlueRepayPlanAction = validateBlueRepayPlanAction;
|
|
7
|
+
const blue_sdk_1 = require("@morpho-org/blue-sdk");
|
|
8
|
+
const morpho_ts_1 = require("@morpho-org/morpho-ts");
|
|
9
|
+
const viem_1 = require("viem");
|
|
10
|
+
const common_js_1 = require("../../actions/blue/common.js");
|
|
11
|
+
const repay_js_1 = require("../../actions/blue/repay.js");
|
|
12
|
+
const validateClientChainId_js_1 = require("../../actions/requirements/validateClientChainId.js");
|
|
13
|
+
const quoteBlueRepay_js_1 = require("../../helpers/quoteBlueRepay.js");
|
|
14
|
+
const validate_js_1 = require("../../helpers/validate.js");
|
|
15
|
+
const index_js_1 = require("../../types/index.js");
|
|
16
|
+
const error_js_1 = require("../error.js");
|
|
17
|
+
const permit_js_1 = require("../permit.js");
|
|
18
|
+
const validation_js_1 = require("../validation.js");
|
|
19
|
+
const prepare_js_1 = require("./prepare.js");
|
|
20
|
+
/**
|
|
21
|
+
* Prepares an asset, share, or full Blue repayment through BlueBundlesV1, never Permit2.
|
|
22
|
+
* Share quotes accrue the supplied position to expiry, at most two hours from the reference time.
|
|
23
|
+
* @param client - Viem client used only for token allowance and permit reads.
|
|
24
|
+
* @param params - Repayment intent and caller-fetched snapshots. Native funding is exclusive and requires wNative.
|
|
25
|
+
* @returns A static plan containing any token prerequisite followed by repayment.
|
|
26
|
+
* @throws {ZeroAccountError} If `account` is the zero address.
|
|
27
|
+
* @throws {NonIntegerInputError} If `expiresAt` or `referralFee.bps` is not a safe integer.
|
|
28
|
+
* @throws {NonPositiveInputError} If expiry, repayment, or derived funding is not positive.
|
|
29
|
+
* @throws {ExpiredDeadlineError} If expiry is at or before `now`.
|
|
30
|
+
* @throws {NegativeInputError} If `referralFee.bps` is negative.
|
|
31
|
+
* @throws {InputExceedsMaxError} If a share-mode expiry exceeds the quote horizon, the referral fee exceeds 10,000 bps, or an encoded amount exceeds uint256.
|
|
32
|
+
* @throws {InvalidCalldataOriginError} If attribution bytes are empty, malformed, or have an odd number of hex digits.
|
|
33
|
+
* @throws {BlueSnapshotChainMismatchError} If either snapshot describes another chain.
|
|
34
|
+
* @throws {MarketIdMismatchError} If either snapshot's market ID disagrees with `marketId` or its market tuple.
|
|
35
|
+
* @throws {AccrualPositionUserMismatchError} If the position belongs to another account.
|
|
36
|
+
* @throws {ReferralFeePctExceededError} If the referral fee equals 10,000 bps; the normalized fee must be below WAD.
|
|
37
|
+
* @throws {ReferralFeeRecipientMissingError} If a positive referral fee has no recipient or a zero recipient.
|
|
38
|
+
* @throws {RepayExceedsDebtError} If an asset repayment exceeds the snapshot's borrow assets.
|
|
39
|
+
* @throws {RepaySharesExceedDebtError} If a non-saturated share repayment exceeds the snapshot's borrow shares.
|
|
40
|
+
* @throws {UnsupportedMarketIrmError} If interest accrual requires an unsupported IRM without a supplied rate at target.
|
|
41
|
+
* @throws {ChainWNativeMissingError} If native funding is requested on a chain without registered wNative.
|
|
42
|
+
* @throws {NativeAmountOnNonWNativeAssetError} If native funding targets a loan token other than wNative.
|
|
43
|
+
* @throws {ChainIdMismatchError} If the client's declared or served chain differs from the repayment chain.
|
|
44
|
+
* @throws {MissingContractCodeError} If registered BlueBundlesV1 or Morpho has no deployed code.
|
|
45
|
+
* @throws {UnsupportedChainIdError} If the chain is absent from the address registry.
|
|
46
|
+
* @throws {UnknownAddressError} If a required contract address is not registered.
|
|
47
|
+
* @throws {viem.BaseError} If an RPC read or ABI encoding fails.
|
|
48
|
+
* @example
|
|
49
|
+
* ```ts
|
|
50
|
+
* import { prepareBlueRepay, type BlueRepayPlanParams } from "@morpho-org/morpho-sdk";
|
|
51
|
+
* import type { Client } from "viem";
|
|
52
|
+
* const prepare = (client: Client, params: BlueRepayPlanParams) => prepareBlueRepay(client, params);
|
|
53
|
+
* ```
|
|
54
|
+
* @experimental TransactionPlan is in beta; breaking changes may ship in minor releases.
|
|
55
|
+
*/
|
|
56
|
+
async function prepareBlueRepay(client, { chainId, account, marketId, marketData, positionData, mode, funding, expiresAt, referralFee, supportSignature, calldataOrigin, deployless, now = morpho_ts_1.Time.timestamp(), }) {
|
|
57
|
+
const params = {
|
|
58
|
+
chainId,
|
|
59
|
+
account,
|
|
60
|
+
marketId,
|
|
61
|
+
marketData,
|
|
62
|
+
positionData,
|
|
63
|
+
mode,
|
|
64
|
+
funding,
|
|
65
|
+
expiresAt,
|
|
66
|
+
referralFee,
|
|
67
|
+
supportSignature,
|
|
68
|
+
calldataOrigin,
|
|
69
|
+
deployless,
|
|
70
|
+
now,
|
|
71
|
+
};
|
|
72
|
+
let inputs;
|
|
73
|
+
const { intent: resolvedIntent, steps, signatureRequests, } = await (0, prepare_js_1.prepareBlue)({ client, params }, (intent) => {
|
|
74
|
+
const { referralFeePct, referralFeeRecipient } = (0, validate_js_1.validateReferralFee)(intent);
|
|
75
|
+
const position = new blue_sdk_1.AccrualPosition(params.positionData.position, params.positionData.position.market);
|
|
76
|
+
const repayAssets = params.mode.type === "assets" ? params.mode.amount : 0n;
|
|
77
|
+
let repayShares = 0n;
|
|
78
|
+
if (params.mode.type === "full") {
|
|
79
|
+
repayShares = viem_1.maxUint256;
|
|
80
|
+
}
|
|
81
|
+
if (params.mode.type === "shares") {
|
|
82
|
+
repayShares = params.mode.amount;
|
|
83
|
+
}
|
|
84
|
+
if (params.mode.type !== "full" && params.mode.amount <= 0n) {
|
|
85
|
+
throw new index_js_1.NonPositiveInputError("amount", params.mode.amount);
|
|
86
|
+
}
|
|
87
|
+
const expectedRepayAssets = (0, quoteBlueRepay_js_1.quoteBlueRepayFunding)({
|
|
88
|
+
positionData: position,
|
|
89
|
+
marketId: params.marketId,
|
|
90
|
+
repayAssets,
|
|
91
|
+
repayShares,
|
|
92
|
+
deadline: intent.deadline,
|
|
93
|
+
now,
|
|
94
|
+
});
|
|
95
|
+
const maxRepayAssets = expectedRepayAssets +
|
|
96
|
+
(0, common_js_1.getBlueBundlesV1ReferralFeeAssets)(expectedRepayAssets, referralFeePct);
|
|
97
|
+
const nativeAmount = params.funding?.type === "native" ? maxRepayAssets : undefined;
|
|
98
|
+
const { loanToken, collateralToken, oracle, irm, lltv } = params.marketData.market.params;
|
|
99
|
+
inputs = {
|
|
100
|
+
chainId: params.chainId,
|
|
101
|
+
account: params.account,
|
|
102
|
+
marketParams: { loanToken, collateralToken, oracle, irm, lltv },
|
|
103
|
+
repayAssets,
|
|
104
|
+
repayShares,
|
|
105
|
+
maxRepayAssets,
|
|
106
|
+
nativeAssets: nativeAmount,
|
|
107
|
+
deadline: intent.deadline,
|
|
108
|
+
referralFeePct,
|
|
109
|
+
referralFeeRecipient,
|
|
110
|
+
};
|
|
111
|
+
// Validate the derived funding and operation before any allowance read.
|
|
112
|
+
(0, repay_js_1.blueRepay)({
|
|
113
|
+
market: {
|
|
114
|
+
chainId: inputs.chainId,
|
|
115
|
+
marketParams: new blue_sdk_1.MarketParams(inputs.marketParams),
|
|
116
|
+
},
|
|
117
|
+
args: { ...inputs, nativeAmount, userAddress: inputs.account },
|
|
118
|
+
});
|
|
119
|
+
const native = (0, common_js_1.validateBlueBundlesV1NativeFunding)({
|
|
120
|
+
chainId: inputs.chainId,
|
|
121
|
+
token: inputs.marketParams.loanToken,
|
|
122
|
+
fundedAmount: maxRepayAssets,
|
|
123
|
+
nativeAmount,
|
|
124
|
+
});
|
|
125
|
+
return {
|
|
126
|
+
id: "blueRepay",
|
|
127
|
+
...(native === 0n && {
|
|
128
|
+
tokenPull: {
|
|
129
|
+
token: inputs.marketParams.loanToken,
|
|
130
|
+
amount: maxRepayAssets,
|
|
131
|
+
},
|
|
132
|
+
}),
|
|
133
|
+
};
|
|
134
|
+
});
|
|
135
|
+
await (0, validateClientChainId_js_1.validateClientChainId)(client, params.chainId);
|
|
136
|
+
if (inputs === undefined) {
|
|
137
|
+
throw new error_js_1.InvalidTransactionPlanError({
|
|
138
|
+
path: "inputs",
|
|
139
|
+
reason: "expected resolved repayment inputs",
|
|
140
|
+
});
|
|
141
|
+
}
|
|
142
|
+
return (0, morpho_ts_1.deepFreeze)(structuredClone({
|
|
143
|
+
version: 2,
|
|
144
|
+
chainId: params.chainId,
|
|
145
|
+
account: params.account,
|
|
146
|
+
expiresAt: resolvedIntent.expiresAt,
|
|
147
|
+
calldataOrigin: resolvedIntent.calldataOrigin,
|
|
148
|
+
steps: [
|
|
149
|
+
...steps,
|
|
150
|
+
{
|
|
151
|
+
id: "blueRepay",
|
|
152
|
+
label: "Repay Blue debt",
|
|
153
|
+
action: {
|
|
154
|
+
type: "blueRepay",
|
|
155
|
+
inputs,
|
|
156
|
+
signatureRequestIds: signatureRequests.length
|
|
157
|
+
? { tokenPermit: signatureRequests[0]?.id }
|
|
158
|
+
: {},
|
|
159
|
+
},
|
|
160
|
+
},
|
|
161
|
+
],
|
|
162
|
+
signatureRequests,
|
|
163
|
+
}));
|
|
164
|
+
}
|
|
165
|
+
/** @internal Checks a repayment permit against the fixed token pull. */
|
|
166
|
+
function validateBlueRepayPermit(request, action) {
|
|
167
|
+
if (action.signatureRequestIds.tokenPermit !== request.id) {
|
|
168
|
+
throw new error_js_1.TransactionPlanSignatureMismatchError(request.id, "reference");
|
|
169
|
+
}
|
|
170
|
+
(0, permit_js_1.validateTokenPermitRequest)(request, {
|
|
171
|
+
chainId: action.inputs.chainId,
|
|
172
|
+
account: action.inputs.account,
|
|
173
|
+
deadline: action.inputs.deadline,
|
|
174
|
+
bundler: "bundles.blueBundlesV1",
|
|
175
|
+
asset: action.inputs.marketParams.loanToken,
|
|
176
|
+
amount: action.inputs.maxRepayAssets,
|
|
177
|
+
exact: true,
|
|
178
|
+
});
|
|
179
|
+
}
|
|
180
|
+
/** @internal Encodes a stored repayment using only fixed inputs and referenced signatures. */
|
|
181
|
+
function buildBlueRepay(action, requests) {
|
|
182
|
+
const { chainId, account, marketParams, nativeAssets, ...args } = action.inputs;
|
|
183
|
+
return (0, repay_js_1.blueRepay)({
|
|
184
|
+
market: { chainId, marketParams: new blue_sdk_1.MarketParams(marketParams) },
|
|
185
|
+
args: {
|
|
186
|
+
...args,
|
|
187
|
+
nativeAmount: nativeAssets,
|
|
188
|
+
userAddress: account,
|
|
189
|
+
requirementSignature: (0, permit_js_1.getVaultPermit)(requests, {
|
|
190
|
+
id: action.signatureRequestIds.tokenPermit,
|
|
191
|
+
asset: marketParams.loanToken,
|
|
192
|
+
owner: account,
|
|
193
|
+
}),
|
|
194
|
+
},
|
|
195
|
+
});
|
|
196
|
+
}
|
|
197
|
+
/** @internal Validates the stored repayment's structural fields. */
|
|
198
|
+
function validateBlueRepayPlanAction(action, path) {
|
|
199
|
+
const inputs = (0, validation_js_1.getPlanObject)(action.inputs, `${path}.inputs`);
|
|
200
|
+
(0, validation_js_1.validatePlanFields)(inputs, {
|
|
201
|
+
path: `${path}.inputs`,
|
|
202
|
+
fields: {
|
|
203
|
+
repayAssets: "uint256 bigint",
|
|
204
|
+
repayShares: "uint256 bigint",
|
|
205
|
+
maxRepayAssets: "uint256 bigint",
|
|
206
|
+
deadline: "uint256 bigint",
|
|
207
|
+
referralFeePct: "uint256 bigint",
|
|
208
|
+
referralFeeRecipient: "address",
|
|
209
|
+
},
|
|
210
|
+
});
|
|
211
|
+
if (inputs.nativeAssets !== undefined) {
|
|
212
|
+
(0, validation_js_1.validatePlanFields)(inputs, {
|
|
213
|
+
path: `${path}.inputs`,
|
|
214
|
+
fields: { nativeAssets: "uint256 bigint" },
|
|
215
|
+
});
|
|
216
|
+
}
|
|
217
|
+
const market = (0, validation_js_1.getPlanObject)(inputs.marketParams, `${path}.inputs.marketParams`);
|
|
218
|
+
(0, validation_js_1.validatePlanFields)(market, {
|
|
219
|
+
path: `${path}.inputs.marketParams`,
|
|
220
|
+
fields: {
|
|
221
|
+
loanToken: "address",
|
|
222
|
+
collateralToken: "address",
|
|
223
|
+
oracle: "address",
|
|
224
|
+
irm: "address",
|
|
225
|
+
lltv: "uint256 bigint",
|
|
226
|
+
},
|
|
227
|
+
});
|
|
228
|
+
(0, validation_js_1.getPlanObject)(action.signatureRequestIds, `${path}.signatureRequestIds`);
|
|
229
|
+
}
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import { type MarketId } from "@morpho-org/blue-sdk";
|
|
2
|
+
import { type Client } from "viem";
|
|
3
|
+
import type { Funding, IntentParams } from "../intent.js";
|
|
4
|
+
import type { Action, SignatureRequest, TransactionPlan } from "../types.js";
|
|
5
|
+
import { type BlueMarketSnapshot, type BluePositionSnapshot } from "./prepare.js";
|
|
6
|
+
/**
|
|
7
|
+
* Repayment and collateral withdrawal intent. Set `repayShares` to `maxUint256` for full repayment.
|
|
8
|
+
* Native funding wraps the computed repayment cap; omitted funding uses the loan-token balance.
|
|
9
|
+
* @example
|
|
10
|
+
* ```ts
|
|
11
|
+
* import type { BlueRepayWithdrawCollateralPlanParams } from "@morpho-org/morpho-sdk";
|
|
12
|
+
* const native = (params: BlueRepayWithdrawCollateralPlanParams) =>
|
|
13
|
+
* ({ ...params, funding: { type: "native" as const } });
|
|
14
|
+
* ```
|
|
15
|
+
* @experimental TransactionPlan is in beta; breaking changes may ship in minor releases.
|
|
16
|
+
*/
|
|
17
|
+
export type BlueRepayWithdrawCollateralPlanParams = IntentParams & {
|
|
18
|
+
readonly marketId: MarketId;
|
|
19
|
+
readonly marketData: BlueMarketSnapshot;
|
|
20
|
+
readonly positionData: BluePositionSnapshot;
|
|
21
|
+
readonly collateralAssets: bigint;
|
|
22
|
+
/** Defaults to ERC-20; native funding is available only for wNative loan tokens. */
|
|
23
|
+
readonly funding?: Funding;
|
|
24
|
+
readonly now?: bigint;
|
|
25
|
+
} & ({
|
|
26
|
+
readonly repayAssets: bigint;
|
|
27
|
+
readonly repayShares?: never;
|
|
28
|
+
} | {
|
|
29
|
+
readonly repayShares: bigint;
|
|
30
|
+
readonly repayAssets?: never;
|
|
31
|
+
});
|
|
32
|
+
/**
|
|
33
|
+
* Prepares one BlueBundlesV1 repayment and collateral withdrawal from caller-fetched snapshots.
|
|
34
|
+
* Full repayment uses `repayShares: maxUint256`; `funding: { type: "native" }` funds the computed cap.
|
|
35
|
+
* Signatures are embedded in the operation; direct approvals and authorization precede it.
|
|
36
|
+
* @param client - Viem client used only for prerequisite reads.
|
|
37
|
+
* @param params - Intent, position and market snapshots from the same chain and account. Read
|
|
38
|
+
* both snapshots at one block, or use the market embedded in the position snapshot as below.
|
|
39
|
+
* @returns A static plan; collect its pending signatures before building transactions.
|
|
40
|
+
* @throws {BlueSnapshotChainMismatchError} when a market or position snapshot names another chain.
|
|
41
|
+
* @throws {MarketIdMismatchError} when a snapshot's market ID differs from `marketId` or its tuple.
|
|
42
|
+
* @throws {AccrualPositionUserMismatchError} when the position belongs to another account.
|
|
43
|
+
* @throws {BlueSnapshotStateMismatchError} when the market snapshot's state differs from the
|
|
44
|
+
* market embedded in the position snapshot.
|
|
45
|
+
* @throws {ZeroAccountError} when `account` is the zero address.
|
|
46
|
+
* @throws {NonIntegerInputError} when `expiresAt` or `referralFee.bps` is not a safe integer.
|
|
47
|
+
* @throws {InvalidCalldataOriginError} when `calldataOrigin` is empty or malformed hex bytes.
|
|
48
|
+
* @throws {ExpiredDeadlineError} when `expiresAt` is at or before the reference timestamp.
|
|
49
|
+
* @throws {NegativeInputError} when an amount or referral fee is negative.
|
|
50
|
+
* @throws {NonPositiveInputError} when the expiry is not positive, both operation legs are zero,
|
|
51
|
+
* a repay leg has no positive funding cap, or native funding is set without a repay leg.
|
|
52
|
+
* @throws {InputExceedsMaxError} when a value exceeds uint256, referral basis points exceed
|
|
53
|
+
* 10,000, or a share-mode expiry exceeds the two-hour funding quote horizon.
|
|
54
|
+
* @throws {ReferralFeePctExceededError} when referral basis points equal 10,000.
|
|
55
|
+
* @throws {ReferralFeeRecipientMissingError} when a positive fee has no non-zero recipient.
|
|
56
|
+
* @throws {ChainIdMismatchError} when the client declares, or its RPC reports, another chain.
|
|
57
|
+
* @throws {UnsupportedChainIdError} when the chain is absent from the address registry.
|
|
58
|
+
* @throws {UnknownAddressError} when a required contract is not registered on the chain.
|
|
59
|
+
* @throws {UnsupportedBlueMarketIrmError} when debt projection requires an unsupported IRM.
|
|
60
|
+
* @throws {MutuallyExclusiveRepayAmountsError} when both repayment amounts are non-zero at runtime.
|
|
61
|
+
* @throws {RepayExceedsDebtError} when exact repayment assets exceed the position's debt.
|
|
62
|
+
* @throws {RepaySharesExceedDebtError} when non-saturated repayment shares exceed borrow shares.
|
|
63
|
+
* @throws {WithdrawExceedsCollateralError} when the requested withdrawal exceeds collateral.
|
|
64
|
+
* @throws {MissingMarketPriceError} when withdrawal health cannot be checked without a price.
|
|
65
|
+
* @throws {WithdrawMakesPositionUnhealthyError} when the post-repay withdrawal exceeds buffered LLTV.
|
|
66
|
+
* @throws {ChainWNativeMissingError} when native funding is requested on a chain without wNative.
|
|
67
|
+
* @throws {NativeAmountOnNonWNativeAssetError} when native funding targets a loan token other than wNative.
|
|
68
|
+
* @throws {UnknownTokenError} when permit metadata has no usable token decimals.
|
|
69
|
+
* @throws {MalformedTokenMetadataError} when token metadata returns malformed non-empty data.
|
|
70
|
+
* @throws {UnexpectedRequirementSignatureError} when a signable prerequisite has no bigint nonce.
|
|
71
|
+
* @throws {TransactionPlanSignatureMismatchError} when a permit request disagrees with the exact token pull.
|
|
72
|
+
* @throws {MissingContractCodeError} when BlueBundlesV1 or Morpho Blue has no deployed code.
|
|
73
|
+
* @throws {IncompleteTransactionPlanError} when no operation inputs were resolved during preparation.
|
|
74
|
+
* @throws {viem.BaseError} when an allowance, nonce, metadata, authorization, chain ID or bytecode read fails.
|
|
75
|
+
* @example
|
|
76
|
+
* ```ts
|
|
77
|
+
* import { prepareBlueRepayWithdrawCollateral, type BlueRepayWithdrawCollateralPlanParams } from "@morpho-org/morpho-sdk";
|
|
78
|
+
* import type { Client } from "viem";
|
|
79
|
+
* type AssetsParams = Extract<BlueRepayWithdrawCollateralPlanParams, { readonly repayAssets: bigint }>;
|
|
80
|
+
* const prepare = (client: Client, params: Omit<AssetsParams, "marketData">) =>
|
|
81
|
+
* prepareBlueRepayWithdrawCollateral(client, {
|
|
82
|
+
* ...params,
|
|
83
|
+
* marketData: { chainId: params.chainId, market: params.positionData.position.market },
|
|
84
|
+
* });
|
|
85
|
+
* ```
|
|
86
|
+
* @experimental TransactionPlan is in beta; breaking changes may ship in minor releases.
|
|
87
|
+
*/
|
|
88
|
+
export declare function prepareBlueRepayWithdrawCollateral(client: Client, params: BlueRepayWithdrawCollateralPlanParams): Promise<TransactionPlan>;
|
|
89
|
+
/** @internal Checks signature bindings for the combined operation. */
|
|
90
|
+
export declare function validateRepayWithdrawCollateralRequest(request: SignatureRequest, action: Extract<Action, {
|
|
91
|
+
type: "blueRepayWithdrawCollateral";
|
|
92
|
+
}>): void;
|
|
93
|
+
/** @internal Builds without a client, snapshot, or mutable preparation state. */
|
|
94
|
+
export declare function buildBlueRepayWithdrawCollateral(action: Extract<Action, {
|
|
95
|
+
type: "blueRepayWithdrawCollateral";
|
|
96
|
+
}>, requests: readonly SignatureRequest[]): Readonly<import("../../index.js").Transaction<import("../../index.js").BlueRepayWithdrawCollateralAction>>;
|
|
97
|
+
/** @internal Validates stored combined-operation input shapes. */
|
|
98
|
+
export declare function validateRepayWithdrawCollateralPlanAction(action: Record<string, unknown>, path: string): void;
|