@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,379 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.prepareBlueRepayWithdrawCollateral = prepareBlueRepayWithdrawCollateral;
|
|
4
|
+
exports.validateRepayWithdrawCollateralRequest = validateRepayWithdrawCollateralRequest;
|
|
5
|
+
exports.buildBlueRepayWithdrawCollateral = buildBlueRepayWithdrawCollateral;
|
|
6
|
+
exports.validateRepayWithdrawCollateralPlanAction = validateRepayWithdrawCollateralPlanAction;
|
|
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 repayWithdrawCollateral_js_1 = require("../../actions/blue/repayWithdrawCollateral.js");
|
|
12
|
+
const validateClientChainId_js_1 = require("../../actions/requirements/validateClientChainId.js");
|
|
13
|
+
const index_js_1 = require("../../helpers/index.js");
|
|
14
|
+
const quoteBlueRepay_js_1 = require("../../helpers/quoteBlueRepay.js");
|
|
15
|
+
const index_js_2 = 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 authorization_js_1 = require("./authorization.js");
|
|
20
|
+
const prepare_js_1 = require("./prepare.js");
|
|
21
|
+
/**
|
|
22
|
+
* Prepares one BlueBundlesV1 repayment and collateral withdrawal from caller-fetched snapshots.
|
|
23
|
+
* Full repayment uses `repayShares: maxUint256`; `funding: { type: "native" }` funds the computed cap.
|
|
24
|
+
* Signatures are embedded in the operation; direct approvals and authorization precede it.
|
|
25
|
+
* @param client - Viem client used only for prerequisite reads.
|
|
26
|
+
* @param params - Intent, position and market snapshots from the same chain and account. Read
|
|
27
|
+
* both snapshots at one block, or use the market embedded in the position snapshot as below.
|
|
28
|
+
* @returns A static plan; collect its pending signatures before building transactions.
|
|
29
|
+
* @throws {BlueSnapshotChainMismatchError} when a market or position snapshot names another chain.
|
|
30
|
+
* @throws {MarketIdMismatchError} when a snapshot's market ID differs from `marketId` or its tuple.
|
|
31
|
+
* @throws {AccrualPositionUserMismatchError} when the position belongs to another account.
|
|
32
|
+
* @throws {BlueSnapshotStateMismatchError} when the market snapshot's state differs from the
|
|
33
|
+
* market embedded in the position snapshot.
|
|
34
|
+
* @throws {ZeroAccountError} when `account` is the zero address.
|
|
35
|
+
* @throws {NonIntegerInputError} when `expiresAt` or `referralFee.bps` is not a safe integer.
|
|
36
|
+
* @throws {InvalidCalldataOriginError} when `calldataOrigin` is empty or malformed hex bytes.
|
|
37
|
+
* @throws {ExpiredDeadlineError} when `expiresAt` is at or before the reference timestamp.
|
|
38
|
+
* @throws {NegativeInputError} when an amount or referral fee is negative.
|
|
39
|
+
* @throws {NonPositiveInputError} when the expiry is not positive, both operation legs are zero,
|
|
40
|
+
* a repay leg has no positive funding cap, or native funding is set without a repay leg.
|
|
41
|
+
* @throws {InputExceedsMaxError} when a value exceeds uint256, referral basis points exceed
|
|
42
|
+
* 10,000, or a share-mode expiry exceeds the two-hour funding quote horizon.
|
|
43
|
+
* @throws {ReferralFeePctExceededError} when referral basis points equal 10,000.
|
|
44
|
+
* @throws {ReferralFeeRecipientMissingError} when a positive fee has no non-zero recipient.
|
|
45
|
+
* @throws {ChainIdMismatchError} when the client declares, or its RPC reports, another chain.
|
|
46
|
+
* @throws {UnsupportedChainIdError} when the chain is absent from the address registry.
|
|
47
|
+
* @throws {UnknownAddressError} when a required contract is not registered on the chain.
|
|
48
|
+
* @throws {UnsupportedBlueMarketIrmError} when debt projection requires an unsupported IRM.
|
|
49
|
+
* @throws {MutuallyExclusiveRepayAmountsError} when both repayment amounts are non-zero at runtime.
|
|
50
|
+
* @throws {RepayExceedsDebtError} when exact repayment assets exceed the position's debt.
|
|
51
|
+
* @throws {RepaySharesExceedDebtError} when non-saturated repayment shares exceed borrow shares.
|
|
52
|
+
* @throws {WithdrawExceedsCollateralError} when the requested withdrawal exceeds collateral.
|
|
53
|
+
* @throws {MissingMarketPriceError} when withdrawal health cannot be checked without a price.
|
|
54
|
+
* @throws {WithdrawMakesPositionUnhealthyError} when the post-repay withdrawal exceeds buffered LLTV.
|
|
55
|
+
* @throws {ChainWNativeMissingError} when native funding is requested on a chain without wNative.
|
|
56
|
+
* @throws {NativeAmountOnNonWNativeAssetError} when native funding targets a loan token other than wNative.
|
|
57
|
+
* @throws {UnknownTokenError} when permit metadata has no usable token decimals.
|
|
58
|
+
* @throws {MalformedTokenMetadataError} when token metadata returns malformed non-empty data.
|
|
59
|
+
* @throws {UnexpectedRequirementSignatureError} when a signable prerequisite has no bigint nonce.
|
|
60
|
+
* @throws {TransactionPlanSignatureMismatchError} when a permit request disagrees with the exact token pull.
|
|
61
|
+
* @throws {MissingContractCodeError} when BlueBundlesV1 or Morpho Blue has no deployed code.
|
|
62
|
+
* @throws {IncompleteTransactionPlanError} when no operation inputs were resolved during preparation.
|
|
63
|
+
* @throws {viem.BaseError} when an allowance, nonce, metadata, authorization, chain ID or bytecode read fails.
|
|
64
|
+
* @example
|
|
65
|
+
* ```ts
|
|
66
|
+
* import { prepareBlueRepayWithdrawCollateral, type BlueRepayWithdrawCollateralPlanParams } from "@morpho-org/morpho-sdk";
|
|
67
|
+
* import type { Client } from "viem";
|
|
68
|
+
* type AssetsParams = Extract<BlueRepayWithdrawCollateralPlanParams, { readonly repayAssets: bigint }>;
|
|
69
|
+
* const prepare = (client: Client, params: Omit<AssetsParams, "marketData">) =>
|
|
70
|
+
* prepareBlueRepayWithdrawCollateral(client, {
|
|
71
|
+
* ...params,
|
|
72
|
+
* marketData: { chainId: params.chainId, market: params.positionData.position.market },
|
|
73
|
+
* });
|
|
74
|
+
* ```
|
|
75
|
+
* @experimental TransactionPlan is in beta; breaking changes may ship in minor releases.
|
|
76
|
+
*/
|
|
77
|
+
async function prepareBlueRepayWithdrawCollateral(client, params) {
|
|
78
|
+
const id = "blueRepayWithdrawCollateral";
|
|
79
|
+
const now = params.now ?? morpho_ts_1.Time.timestamp();
|
|
80
|
+
let inputs;
|
|
81
|
+
const prepared = await (0, prepare_js_1.prepareBlue)({ client, params: { ...params, now } }, (intent) => {
|
|
82
|
+
const marketParams = params.marketData.market.params;
|
|
83
|
+
// Reject chain and referral mismatches before deriving a repayment quote.
|
|
84
|
+
(0, index_js_1.validateChainId)(client.chain?.id, params.chainId);
|
|
85
|
+
const common = (0, common_js_1.normalizeBlueBundlesV1CommonParams)({
|
|
86
|
+
chainId: params.chainId,
|
|
87
|
+
userAddress: params.account,
|
|
88
|
+
deadline: intent.deadline,
|
|
89
|
+
referralFeePct: intent.referralFeePct,
|
|
90
|
+
referralFeeRecipient: intent.referralFeeRecipient,
|
|
91
|
+
});
|
|
92
|
+
const { repayAssets, repayShares, collateralAssets, hasRepay } = getRepayWithdrawAmounts(params);
|
|
93
|
+
const quoteParams = {
|
|
94
|
+
positionData: getMatchingPosition(params),
|
|
95
|
+
marketId: params.marketId,
|
|
96
|
+
repayAssets,
|
|
97
|
+
repayShares,
|
|
98
|
+
deadline: intent.deadline,
|
|
99
|
+
now,
|
|
100
|
+
};
|
|
101
|
+
const healthQuote = collateralAssets > 0n ? (0, quoteBlueRepay_js_1.quoteBlueRepay)(quoteParams) : undefined;
|
|
102
|
+
const expectedRepayAssets = healthQuote?.expectedRepayAssets ?? (0, quoteBlueRepay_js_1.quoteBlueRepayFunding)(quoteParams);
|
|
103
|
+
const maxRepayAssets = expectedRepayAssets +
|
|
104
|
+
(0, common_js_1.getBlueBundlesV1ReferralFeeAssets)(expectedRepayAssets, common.referralFeePct);
|
|
105
|
+
const nativeValue = (0, common_js_1.validateBlueBundlesV1NativeFunding)({
|
|
106
|
+
chainId: params.chainId,
|
|
107
|
+
token: marketParams.loanToken,
|
|
108
|
+
fundedAmount: maxRepayAssets,
|
|
109
|
+
nativeAmount: params.funding?.type === "native" ? maxRepayAssets : undefined,
|
|
110
|
+
});
|
|
111
|
+
if (healthQuote !== undefined) {
|
|
112
|
+
const { accruedPosition, simulatedRepayShares } = healthQuote;
|
|
113
|
+
const postRepayPosition = hasRepay
|
|
114
|
+
? accruedPosition.repay(repayAssets, simulatedRepayShares).position
|
|
115
|
+
: accruedPosition;
|
|
116
|
+
// Reject withdrawals that leave debt above the buffered LLTV.
|
|
117
|
+
(0, index_js_1.validatePositionHealthAfterWithdraw)({
|
|
118
|
+
positionData: postRepayPosition,
|
|
119
|
+
withdrawAmount: collateralAssets,
|
|
120
|
+
lltv: marketParams.lltv,
|
|
121
|
+
marketId: params.marketData.market.id,
|
|
122
|
+
});
|
|
123
|
+
}
|
|
124
|
+
const tx = (0, repayWithdrawCollateral_js_1.blueRepayWithdrawCollateral)({
|
|
125
|
+
market: { chainId: params.chainId, marketParams },
|
|
126
|
+
args: {
|
|
127
|
+
userAddress: params.account,
|
|
128
|
+
repayAssets,
|
|
129
|
+
repayShares,
|
|
130
|
+
maxRepayAssets,
|
|
131
|
+
collateralAssets,
|
|
132
|
+
maxLtv: collateralAssets > 0n
|
|
133
|
+
? blue_sdk_1.MathLib.zeroFloorSub(marketParams.lltv, index_js_1.DEFAULT_LLTV_BUFFER)
|
|
134
|
+
: viem_1.maxUint256,
|
|
135
|
+
nativeAmount: nativeValue > 0n ? nativeValue : undefined,
|
|
136
|
+
deadline: intent.deadline,
|
|
137
|
+
...common,
|
|
138
|
+
},
|
|
139
|
+
});
|
|
140
|
+
const { market: _market, onBehalf: _onBehalf, referralFeeAssets: _fee, nativeAmount, ...args } = tx.action.args;
|
|
141
|
+
inputs = {
|
|
142
|
+
...args,
|
|
143
|
+
...(nativeAmount !== undefined && { nativeAssets: nativeAmount }),
|
|
144
|
+
chainId: params.chainId,
|
|
145
|
+
account: params.account,
|
|
146
|
+
marketParams: {
|
|
147
|
+
loanToken: marketParams.loanToken,
|
|
148
|
+
collateralToken: marketParams.collateralToken,
|
|
149
|
+
oracle: marketParams.oracle,
|
|
150
|
+
irm: marketParams.irm,
|
|
151
|
+
lltv: marketParams.lltv,
|
|
152
|
+
},
|
|
153
|
+
};
|
|
154
|
+
return {
|
|
155
|
+
id,
|
|
156
|
+
tokenPull: args.maxRepayAssets > 0n && !nativeAmount
|
|
157
|
+
? { token: marketParams.loanToken, amount: args.maxRepayAssets }
|
|
158
|
+
: undefined,
|
|
159
|
+
needsAuthorization: args.collateralAssets > 0n,
|
|
160
|
+
};
|
|
161
|
+
});
|
|
162
|
+
await (0, validateClientChainId_js_1.validateClientChainId)(client, params.chainId);
|
|
163
|
+
if (inputs === undefined) {
|
|
164
|
+
throw new error_js_1.IncompleteTransactionPlanError(id);
|
|
165
|
+
}
|
|
166
|
+
const signatureRequestIds = Object.fromEntries(prepared.signatureRequests
|
|
167
|
+
.filter((request) => request.kind === "permit")
|
|
168
|
+
.map((request) => ["tokenPermit", request.id]));
|
|
169
|
+
if (prepared.morphoAuthorizationRequestId !== undefined) {
|
|
170
|
+
signatureRequestIds.morphoAuthorization =
|
|
171
|
+
prepared.morphoAuthorizationRequestId;
|
|
172
|
+
}
|
|
173
|
+
const authorization = prepared.signatureRequests.find((request) => request.kind === "morphoAuthorization");
|
|
174
|
+
if (authorization !== undefined) {
|
|
175
|
+
inputs = { ...inputs, authorizationNonce: authorization.args.nonce };
|
|
176
|
+
}
|
|
177
|
+
return (0, morpho_ts_1.deepFreeze)(structuredClone({
|
|
178
|
+
version: 2,
|
|
179
|
+
chainId: params.chainId,
|
|
180
|
+
account: params.account,
|
|
181
|
+
expiresAt: prepared.intent.expiresAt,
|
|
182
|
+
calldataOrigin: prepared.intent.calldataOrigin,
|
|
183
|
+
steps: [
|
|
184
|
+
...prepared.steps,
|
|
185
|
+
{
|
|
186
|
+
id,
|
|
187
|
+
label: getRepayWithdrawLabel(inputs),
|
|
188
|
+
action: { type: id, inputs, signatureRequestIds },
|
|
189
|
+
},
|
|
190
|
+
],
|
|
191
|
+
signatureRequests: prepared.signatureRequests,
|
|
192
|
+
}));
|
|
193
|
+
}
|
|
194
|
+
function getRepayWithdrawLabel(inputs) {
|
|
195
|
+
if (inputs.collateralAssets === 0n) {
|
|
196
|
+
return "Repay Blue debt";
|
|
197
|
+
}
|
|
198
|
+
if (inputs.repayAssets === 0n && inputs.repayShares === 0n) {
|
|
199
|
+
return "Withdraw Blue collateral";
|
|
200
|
+
}
|
|
201
|
+
return "Repay and withdraw collateral";
|
|
202
|
+
}
|
|
203
|
+
const MARKET_STATE_FIELDS = [
|
|
204
|
+
"totalSupplyAssets",
|
|
205
|
+
"totalSupplyShares",
|
|
206
|
+
"totalBorrowAssets",
|
|
207
|
+
"totalBorrowShares",
|
|
208
|
+
"lastUpdate",
|
|
209
|
+
"fee",
|
|
210
|
+
"price",
|
|
211
|
+
"rateAtTarget",
|
|
212
|
+
];
|
|
213
|
+
function getMatchingPosition(params) {
|
|
214
|
+
const { position } = params.positionData;
|
|
215
|
+
const positionMarket = position.market;
|
|
216
|
+
const { market } = params.marketData;
|
|
217
|
+
for (const field of MARKET_STATE_FIELDS) {
|
|
218
|
+
if (positionMarket[field] !== market[field]) {
|
|
219
|
+
throw new error_js_1.BlueSnapshotStateMismatchError({
|
|
220
|
+
field,
|
|
221
|
+
positionValue: positionMarket[field],
|
|
222
|
+
marketValue: market[field],
|
|
223
|
+
});
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
return new blue_sdk_1.AccrualPosition(position, positionMarket);
|
|
227
|
+
}
|
|
228
|
+
function getRepayWithdrawAmounts(params) {
|
|
229
|
+
const { collateralAssets, marketId } = params;
|
|
230
|
+
const repayAssets = params.repayAssets ?? 0n;
|
|
231
|
+
const repayShares = params.repayShares ?? 0n;
|
|
232
|
+
if (repayAssets < 0n) {
|
|
233
|
+
throw new index_js_2.NegativeInputError("repayAssets", repayAssets);
|
|
234
|
+
}
|
|
235
|
+
if (repayShares < 0n) {
|
|
236
|
+
throw new index_js_2.NegativeInputError("repayShares", repayShares);
|
|
237
|
+
}
|
|
238
|
+
if (collateralAssets < 0n) {
|
|
239
|
+
throw new index_js_2.NegativeInputError("collateralAssets", collateralAssets);
|
|
240
|
+
}
|
|
241
|
+
if (repayAssets > 0n && repayShares > 0n) {
|
|
242
|
+
throw new index_js_2.MutuallyExclusiveRepayAmountsError(marketId);
|
|
243
|
+
}
|
|
244
|
+
const hasRepay = repayAssets > 0n || repayShares > 0n;
|
|
245
|
+
if (!hasRepay && params.funding?.type === "native") {
|
|
246
|
+
throw new index_js_2.NonPositiveInputError("repayAssets or repayShares", 0n);
|
|
247
|
+
}
|
|
248
|
+
if (!hasRepay && collateralAssets === 0n) {
|
|
249
|
+
throw new index_js_2.NonPositiveInputError("repayAssets, repayShares, or collateralAssets", 0n);
|
|
250
|
+
}
|
|
251
|
+
return { repayAssets, repayShares, collateralAssets, hasRepay };
|
|
252
|
+
}
|
|
253
|
+
/** @internal Checks signature bindings for the combined operation. */
|
|
254
|
+
function validateRepayWithdrawCollateralRequest(request, action) {
|
|
255
|
+
const { chainId, account, deadline, marketParams, maxRepayAssets } = action.inputs;
|
|
256
|
+
if (request.kind === "permit" &&
|
|
257
|
+
action.signatureRequestIds.tokenPermit === request.id) {
|
|
258
|
+
if ((action.inputs.nativeAssets ?? 0n) > 0n ||
|
|
259
|
+
(action.inputs.repayAssets === 0n && action.inputs.repayShares === 0n) ||
|
|
260
|
+
maxRepayAssets === 0n) {
|
|
261
|
+
throw new error_js_1.TransactionPlanSignatureMismatchError(request.id, "reference");
|
|
262
|
+
}
|
|
263
|
+
// Reject a permit that does not authorize this exact token pull.
|
|
264
|
+
(0, permit_js_1.validateTokenPermitRequest)(request, {
|
|
265
|
+
chainId,
|
|
266
|
+
account,
|
|
267
|
+
deadline,
|
|
268
|
+
bundler: "bundles.blueBundlesV1",
|
|
269
|
+
asset: marketParams.loanToken,
|
|
270
|
+
amount: maxRepayAssets,
|
|
271
|
+
exact: true,
|
|
272
|
+
});
|
|
273
|
+
return;
|
|
274
|
+
}
|
|
275
|
+
if (request.kind === "morphoAuthorization" &&
|
|
276
|
+
action.signatureRequestIds.morphoAuthorization === request.id &&
|
|
277
|
+
action.inputs.collateralAssets > 0n &&
|
|
278
|
+
action.inputs.authorizationNonce !== undefined) {
|
|
279
|
+
// Reject an authorization that does not grant this account's bundle access.
|
|
280
|
+
(0, authorization_js_1.validateMorphoAuthorizationRequest)(request, {
|
|
281
|
+
chainId,
|
|
282
|
+
account,
|
|
283
|
+
deadline,
|
|
284
|
+
nonce: action.inputs.authorizationNonce,
|
|
285
|
+
});
|
|
286
|
+
return;
|
|
287
|
+
}
|
|
288
|
+
throw new error_js_1.TransactionPlanSignatureMismatchError(request.id, "reference");
|
|
289
|
+
}
|
|
290
|
+
/** @internal Builds without a client, snapshot, or mutable preparation state. */
|
|
291
|
+
function buildBlueRepayWithdrawCollateral(action, requests) {
|
|
292
|
+
const { chainId, account, marketParams, nativeAssets, authorizationNonce: _authorizationNonce, ...args } = action.inputs;
|
|
293
|
+
const requirementSignature = (0, permit_js_1.getVaultPermit)(requests, {
|
|
294
|
+
id: action.signatureRequestIds.tokenPermit,
|
|
295
|
+
asset: marketParams.loanToken,
|
|
296
|
+
owner: account,
|
|
297
|
+
});
|
|
298
|
+
let authorizationSignature;
|
|
299
|
+
const id = action.signatureRequestIds.morphoAuthorization;
|
|
300
|
+
if (id !== undefined) {
|
|
301
|
+
const request = requests.find((candidate) => candidate.id === id);
|
|
302
|
+
if (request?.signature === undefined) {
|
|
303
|
+
throw new error_js_1.IncompleteTransactionPlanError(id);
|
|
304
|
+
}
|
|
305
|
+
if (request.kind !== "morphoAuthorization") {
|
|
306
|
+
throw new error_js_1.TransactionPlanSignatureMismatchError(id, "reference");
|
|
307
|
+
}
|
|
308
|
+
authorizationSignature = {
|
|
309
|
+
action: {
|
|
310
|
+
type: "authorization",
|
|
311
|
+
args: { ...request.args, isAuthorized: true },
|
|
312
|
+
typedData: request.typedData,
|
|
313
|
+
},
|
|
314
|
+
args: {
|
|
315
|
+
...request.args,
|
|
316
|
+
isAuthorized: true,
|
|
317
|
+
signature: request.signature,
|
|
318
|
+
},
|
|
319
|
+
};
|
|
320
|
+
}
|
|
321
|
+
return (0, repayWithdrawCollateral_js_1.blueRepayWithdrawCollateral)({
|
|
322
|
+
market: { chainId, marketParams: new blue_sdk_1.MarketParams(marketParams) },
|
|
323
|
+
args: {
|
|
324
|
+
...args,
|
|
325
|
+
nativeAmount: nativeAssets,
|
|
326
|
+
userAddress: account,
|
|
327
|
+
requirementSignature,
|
|
328
|
+
authorizationSignature,
|
|
329
|
+
},
|
|
330
|
+
});
|
|
331
|
+
}
|
|
332
|
+
/** @internal Validates stored combined-operation input shapes. */
|
|
333
|
+
function validateRepayWithdrawCollateralPlanAction(action, path) {
|
|
334
|
+
const inputs = (0, validation_js_1.getPlanObject)(action.inputs, `${path}.inputs`);
|
|
335
|
+
(0, validation_js_1.validatePlanFields)(inputs, {
|
|
336
|
+
path: `${path}.inputs`,
|
|
337
|
+
fields: {
|
|
338
|
+
repayAssets: "uint256 bigint",
|
|
339
|
+
repayShares: "uint256 bigint",
|
|
340
|
+
maxRepayAssets: "uint256 bigint",
|
|
341
|
+
collateralAssets: "uint256 bigint",
|
|
342
|
+
maxLtv: "uint256 bigint",
|
|
343
|
+
deadline: "uint256 bigint",
|
|
344
|
+
referralFeePct: "uint256 bigint",
|
|
345
|
+
referralFeeRecipient: "address",
|
|
346
|
+
},
|
|
347
|
+
});
|
|
348
|
+
if (inputs.repayAssets > 0n &&
|
|
349
|
+
inputs.repayShares > 0n) {
|
|
350
|
+
throw new error_js_1.InvalidTransactionPlanError({
|
|
351
|
+
path: `${path}.inputs`,
|
|
352
|
+
reason: "repayAssets and repayShares are mutually exclusive",
|
|
353
|
+
});
|
|
354
|
+
}
|
|
355
|
+
if (inputs.nativeAssets !== undefined) {
|
|
356
|
+
(0, validation_js_1.validatePlanFields)(inputs, {
|
|
357
|
+
path: `${path}.inputs`,
|
|
358
|
+
fields: { nativeAssets: "uint256 bigint" },
|
|
359
|
+
});
|
|
360
|
+
}
|
|
361
|
+
(0, validation_js_1.validatePlanFields)((0, validation_js_1.getPlanObject)(inputs.marketParams, `${path}.inputs.marketParams`), {
|
|
362
|
+
path: `${path}.inputs.marketParams`,
|
|
363
|
+
fields: {
|
|
364
|
+
loanToken: "address",
|
|
365
|
+
collateralToken: "address",
|
|
366
|
+
oracle: "address",
|
|
367
|
+
irm: "address",
|
|
368
|
+
lltv: "uint256 bigint",
|
|
369
|
+
},
|
|
370
|
+
});
|
|
371
|
+
const ids = (0, validation_js_1.getPlanObject)(action.signatureRequestIds, `${path}.signatureRequestIds`);
|
|
372
|
+
if (inputs.authorizationNonce !== undefined ||
|
|
373
|
+
ids.morphoAuthorization !== undefined) {
|
|
374
|
+
(0, validation_js_1.validatePlanFields)(inputs, {
|
|
375
|
+
path: `${path}.inputs`,
|
|
376
|
+
fields: { authorizationNonce: "uint256 bigint" },
|
|
377
|
+
});
|
|
378
|
+
}
|
|
379
|
+
}
|
|
@@ -0,0 +1,181 @@
|
|
|
1
|
+
import { type MarketId } from "@morpho-org/blue-sdk";
|
|
2
|
+
import type { Client } from "viem";
|
|
3
|
+
import type { ReferenceTimestampParams } from "../../types/index.js";
|
|
4
|
+
import type { Funding, IntentParams } from "../intent.js";
|
|
5
|
+
import type { Action, SignatureRequest, TransactionPlan } from "../types.js";
|
|
6
|
+
import { type BlueMarketSnapshot } from "./prepare.js";
|
|
7
|
+
/**
|
|
8
|
+
* Intent for supplying gross loan assets to a Blue market. The snapshot is validated but not stored.
|
|
9
|
+
* @example
|
|
10
|
+
* ```ts
|
|
11
|
+
* import { MarketParams } from "@morpho-org/morpho-sdk/blue/entities";
|
|
12
|
+
* import { fetchMarket } from "@morpho-org/morpho-sdk/blue/fetch";
|
|
13
|
+
* import {
|
|
14
|
+
* applySignatures, buildTransactions, getPendingSignatureRequests,
|
|
15
|
+
* prepareBlueSupply, type BlueSupplyPlanParams,
|
|
16
|
+
* } from "@morpho-org/morpho-sdk";
|
|
17
|
+
* import {
|
|
18
|
+
* createPublicClient, createWalletClient, custom, http, type EIP1193Provider,
|
|
19
|
+
* } from "viem";
|
|
20
|
+
* import { mainnet } from "viem/chains";
|
|
21
|
+
*
|
|
22
|
+
* // Run in a browser with an injected wallet connected to Ethereum mainnet.
|
|
23
|
+
* const { ethereum } = window as Window & { ethereum?: EIP1193Provider };
|
|
24
|
+
* if (!ethereum) throw new Error("Install an Ethereum wallet to continue.");
|
|
25
|
+
* const walletClient = createWalletClient({
|
|
26
|
+
* chain: mainnet, transport: custom(ethereum),
|
|
27
|
+
* });
|
|
28
|
+
* const [account] = await walletClient.requestAddresses();
|
|
29
|
+
* if (!account) throw new Error("Connect a wallet before preparing supply.");
|
|
30
|
+
* const publicClient = createPublicClient({
|
|
31
|
+
* chain: mainnet, transport: http(),
|
|
32
|
+
* });
|
|
33
|
+
* // cbBTC collateral / USDC loan market on Ethereum.
|
|
34
|
+
* const marketParams = new MarketParams({
|
|
35
|
+
* loanToken: "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48",
|
|
36
|
+
* collateralToken: "0xcbB7C0000aB88B473b1f5aFd9ef808440eed33Bf",
|
|
37
|
+
* oracle: "0xA6D6950c9F177F1De7f7757FB33539e3Ec60182a",
|
|
38
|
+
* irm: "0x870aC11D48B15DB9a138Cf899d20F13F79Ba00BC",
|
|
39
|
+
* lltv: 860_000_000_000_000_000n,
|
|
40
|
+
* });
|
|
41
|
+
* const block = await publicClient.getBlock();
|
|
42
|
+
* const market = await fetchMarket(marketParams.id, publicClient, {
|
|
43
|
+
* blockNumber: block.number,
|
|
44
|
+
* });
|
|
45
|
+
* const params: BlueSupplyPlanParams = {
|
|
46
|
+
* chainId: mainnet.id,
|
|
47
|
+
* account,
|
|
48
|
+
* marketId: market.id,
|
|
49
|
+
* marketData: { chainId: mainnet.id, market },
|
|
50
|
+
* assets: 1_000_000n, // Supply 1 USDC, before any referral fee.
|
|
51
|
+
* funding: { type: "erc20" },
|
|
52
|
+
* supportSignature: true,
|
|
53
|
+
* now: block.timestamp,
|
|
54
|
+
* expiresAt: Number(block.timestamp + 1_200n),
|
|
55
|
+
* };
|
|
56
|
+
* const plan = await prepareBlueSupply(publicClient, params);
|
|
57
|
+
* const signatures = await Promise.all(
|
|
58
|
+
* getPendingSignatureRequests(plan).map(async (request) => ({
|
|
59
|
+
* id: request.id,
|
|
60
|
+
* signature: await walletClient.signTypedData({
|
|
61
|
+
* ...request.typedData, account,
|
|
62
|
+
* }),
|
|
63
|
+
* })),
|
|
64
|
+
* );
|
|
65
|
+
* const signedPlan = applySignatures(plan, signatures);
|
|
66
|
+
* const transactions = buildTransactions(signedPlan);
|
|
67
|
+
* // transactions: readonly Readonly<Transaction>[].
|
|
68
|
+
* // An optional ERC-20 approval precedes the BlueBundlesV1 supply transaction;
|
|
69
|
+
* // an ERC-2612 permit is embedded in supply instead. No Permit2 is used.
|
|
70
|
+
* // Simulate, then send each { to, data, value } in order from account on mainnet.
|
|
71
|
+
* ```
|
|
72
|
+
* @experimental TransactionPlan is in beta; breaking changes may ship in minor releases.
|
|
73
|
+
*/
|
|
74
|
+
export interface BlueSupplyPlanParams extends IntentParams, ReferenceTimestampParams {
|
|
75
|
+
readonly marketId: MarketId;
|
|
76
|
+
readonly marketData: BlueMarketSnapshot;
|
|
77
|
+
/** Positive gross loan-token amount, before referral fees. */
|
|
78
|
+
readonly assets: bigint;
|
|
79
|
+
/** Defaults to ERC-20; native funding requires wNative and stores `nativeAssets = assets`. */
|
|
80
|
+
readonly funding?: Funding;
|
|
81
|
+
}
|
|
82
|
+
/** @internal Validates the stored supply recipe without requiring class instances. */
|
|
83
|
+
export declare function validateBlueSupplyPlanAction(action: Record<string, unknown>, path: string): void;
|
|
84
|
+
/**
|
|
85
|
+
* Prepares a static BlueBundlesV1 supply plan from a caller-fetched market snapshot.
|
|
86
|
+
* Insufficient allowance produces an unlimited direct approval, or an exact ERC-2612 permit
|
|
87
|
+
* when supported and requested. Native funding requires wNative and produces no token prerequisite.
|
|
88
|
+
* No Permit2 or Morpho authorization is requested. Only signatures are added before building.
|
|
89
|
+
* @param client - Viem client for the intent chain, used for prerequisite and deployment reads.
|
|
90
|
+
* @param params - Account, chain, snapshot, gross assets and shared funding/fee/expiry intent.
|
|
91
|
+
* @returns A frozen plan with funding prerequisites followed by the supply transaction.
|
|
92
|
+
* @throws {ZeroAccountError} when `account` is the zero address.
|
|
93
|
+
* @throws {NonIntegerInputError} when `expiresAt` or `referralFee.bps` is not a safe integer.
|
|
94
|
+
* @throws {NonPositiveInputError} when `expiresAt`, `assets` or the deadline is not positive.
|
|
95
|
+
* @throws {ExpiredDeadlineError} when `expiresAt` is at or before `now` (device clock when `now` is omitted).
|
|
96
|
+
* @throws {NegativeInputError} when `referralFee.bps` is negative.
|
|
97
|
+
* @throws {InputExceedsMaxError} when `referralFee.bps` exceeds 10,000 or `assets` exceeds uint256.
|
|
98
|
+
* @throws {InvalidCalldataOriginError} when `calldataOrigin` is empty, malformed or has an odd number of hex digits.
|
|
99
|
+
* @throws {ReferralFeePctExceededError} when `referralFee.bps` equals 10,000; the normalized fee must be below WAD.
|
|
100
|
+
* @throws {ReferralFeeRecipientMissingError} when a positive referral fee has no recipient or a zero recipient.
|
|
101
|
+
* @throws {MarketIdMismatchError} When the snapshot describes another market.
|
|
102
|
+
* @throws {BlueSnapshotChainMismatchError} When the snapshot describes another chain.
|
|
103
|
+
* @throws {NativeAmountOnNonWNativeAssetError} When native funding targets another token.
|
|
104
|
+
* @throws {ChainIdMismatchError} When the client targets another chain.
|
|
105
|
+
* @throws {MissingContractCodeError} When BlueBundlesV1 or Morpho is not deployed.
|
|
106
|
+
* @example
|
|
107
|
+
* ```ts
|
|
108
|
+
* import { MarketParams } from "@morpho-org/morpho-sdk/blue/entities";
|
|
109
|
+
* import { fetchMarket } from "@morpho-org/morpho-sdk/blue/fetch";
|
|
110
|
+
* import {
|
|
111
|
+
* applySignatures, buildTransactions, getPendingSignatureRequests,
|
|
112
|
+
* prepareBlueSupply, type BlueSupplyPlanParams,
|
|
113
|
+
* } from "@morpho-org/morpho-sdk";
|
|
114
|
+
* import {
|
|
115
|
+
* createPublicClient, createWalletClient, custom, http, type EIP1193Provider,
|
|
116
|
+
* } from "viem";
|
|
117
|
+
* import { mainnet } from "viem/chains";
|
|
118
|
+
*
|
|
119
|
+
* // Run in a browser with an injected wallet connected to Ethereum mainnet.
|
|
120
|
+
* const { ethereum } = window as Window & { ethereum?: EIP1193Provider };
|
|
121
|
+
* if (!ethereum) throw new Error("Install an Ethereum wallet to continue.");
|
|
122
|
+
* const walletClient = createWalletClient({
|
|
123
|
+
* chain: mainnet, transport: custom(ethereum),
|
|
124
|
+
* });
|
|
125
|
+
* const [account] = await walletClient.requestAddresses();
|
|
126
|
+
* if (!account) throw new Error("Connect a wallet before preparing supply.");
|
|
127
|
+
* const publicClient = createPublicClient({
|
|
128
|
+
* chain: mainnet, transport: http(),
|
|
129
|
+
* });
|
|
130
|
+
* // cbBTC collateral / USDC loan market on Ethereum.
|
|
131
|
+
* const marketParams = new MarketParams({
|
|
132
|
+
* loanToken: "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48",
|
|
133
|
+
* collateralToken: "0xcbB7C0000aB88B473b1f5aFd9ef808440eed33Bf",
|
|
134
|
+
* oracle: "0xA6D6950c9F177F1De7f7757FB33539e3Ec60182a",
|
|
135
|
+
* irm: "0x870aC11D48B15DB9a138Cf899d20F13F79Ba00BC",
|
|
136
|
+
* lltv: 860_000_000_000_000_000n,
|
|
137
|
+
* });
|
|
138
|
+
* const block = await publicClient.getBlock();
|
|
139
|
+
* const market = await fetchMarket(marketParams.id, publicClient, {
|
|
140
|
+
* blockNumber: block.number,
|
|
141
|
+
* });
|
|
142
|
+
* const params: BlueSupplyPlanParams = {
|
|
143
|
+
* chainId: mainnet.id,
|
|
144
|
+
* account,
|
|
145
|
+
* marketId: market.id,
|
|
146
|
+
* marketData: { chainId: mainnet.id, market },
|
|
147
|
+
* assets: 1_000_000n, // Supply 1 USDC, before any referral fee.
|
|
148
|
+
* funding: { type: "erc20" },
|
|
149
|
+
* supportSignature: true,
|
|
150
|
+
* now: block.timestamp,
|
|
151
|
+
* expiresAt: Number(block.timestamp + 1_200n),
|
|
152
|
+
* };
|
|
153
|
+
* const plan = await prepareBlueSupply(publicClient, params);
|
|
154
|
+
* const signatures = await Promise.all(
|
|
155
|
+
* getPendingSignatureRequests(plan).map(async (request) => ({
|
|
156
|
+
* id: request.id,
|
|
157
|
+
* signature: await walletClient.signTypedData({
|
|
158
|
+
* ...request.typedData, account,
|
|
159
|
+
* }),
|
|
160
|
+
* })),
|
|
161
|
+
* );
|
|
162
|
+
* const signedPlan = applySignatures(plan, signatures);
|
|
163
|
+
* const transactions = buildTransactions(signedPlan);
|
|
164
|
+
* // transactions: readonly Readonly<Transaction>[].
|
|
165
|
+
* // An optional ERC-20 approval precedes the BlueBundlesV1 supply transaction;
|
|
166
|
+
* // an ERC-2612 permit is embedded in supply instead. No Permit2 is used.
|
|
167
|
+
* // Simulate, then send each { to, data, value } in order from account on mainnet.
|
|
168
|
+
* ```
|
|
169
|
+
* @experimental TransactionPlan is in beta; breaking changes may ship in minor releases.
|
|
170
|
+
*/
|
|
171
|
+
export declare function prepareBlueSupply(client: Client, params: BlueSupplyPlanParams): Promise<TransactionPlan>;
|
|
172
|
+
/** @internal Binds an exact token permit to this supply's pull. */
|
|
173
|
+
export declare function validateBlueSupplyPermitRequest(request: Extract<SignatureRequest, {
|
|
174
|
+
kind: "permit";
|
|
175
|
+
}>, action: Extract<Action, {
|
|
176
|
+
type: "blueSupply";
|
|
177
|
+
}>): void;
|
|
178
|
+
/** @internal Encodes supply from stored inputs and resolved signatures without a client. */
|
|
179
|
+
export declare function buildBlueSupply(action: Extract<Action, {
|
|
180
|
+
type: "blueSupply";
|
|
181
|
+
}>, requests: readonly SignatureRequest[]): Readonly<import("../../index.js").Transaction<import("../../index.js").BlueSupplyAction>>;
|