@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,246 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.prepareBlueWithdrawCollateral = prepareBlueWithdrawCollateral;
|
|
4
|
+
exports.validateBlueWithdrawCollateralAuthorizationRequest = validateBlueWithdrawCollateralAuthorizationRequest;
|
|
5
|
+
exports.buildBlueWithdrawCollateral = buildBlueWithdrawCollateral;
|
|
6
|
+
exports.validateBlueWithdrawCollateralPlanAction = validateBlueWithdrawCollateralPlanAction;
|
|
7
|
+
const blue_sdk_1 = require("@morpho-org/blue-sdk");
|
|
8
|
+
const morpho_ts_1 = require("@morpho-org/morpho-ts");
|
|
9
|
+
const withdrawCollateral_js_1 = require("../../actions/blue/withdrawCollateral.js");
|
|
10
|
+
const common_js_1 = require("../../actions/bundles/common.js");
|
|
11
|
+
const constant_js_1 = require("../../helpers/constant.js");
|
|
12
|
+
const validate_js_1 = require("../../helpers/validate.js");
|
|
13
|
+
const index_js_1 = require("../../types/index.js");
|
|
14
|
+
const error_js_1 = require("../error.js");
|
|
15
|
+
const validation_js_1 = require("../validation.js");
|
|
16
|
+
const authorization_js_1 = require("./authorization.js");
|
|
17
|
+
const prepare_js_1 = require("./prepare.js");
|
|
18
|
+
/**
|
|
19
|
+
* Prepares a BlueBundlesV1 collateral withdrawal with direct or inline signed Morpho authorization.
|
|
20
|
+
* Health is checked with the same two-hour accrual horizon and LLTV buffer as the entity handle.
|
|
21
|
+
* No token allowance or Permit2 prerequisite is read or produced.
|
|
22
|
+
* @param client - Viem client used for registered contract-code and Morpho authorization reads.
|
|
23
|
+
* @param params - Intent and matching market and account position snapshots.
|
|
24
|
+
* @param params.chainId - Chain containing the market and registered BlueBundlesV1 contract.
|
|
25
|
+
* @param params.account - Non-zero owner of the collateral position, authorization signer and transaction sender.
|
|
26
|
+
* @param params.marketId - Market ID that both snapshots and their parameter tuples must describe.
|
|
27
|
+
* @param params.marketData.chainId - Chain from which the market snapshot was fetched; must equal `chainId`.
|
|
28
|
+
* @param params.marketData.market - Caller-fetched `Market` providing the market tuple and LLTV.
|
|
29
|
+
* @param params.positionData.chainId - Chain from which the position snapshot was fetched; must equal `chainId`.
|
|
30
|
+
* @param params.positionData.position - Caller-fetched `AccrualPosition` for `account` and `marketId`, used for the two-hour accrued health check.
|
|
31
|
+
* @param params.collateralAssets - Positive collateral withdrawal in token base units, not exceeding the position's collateral.
|
|
32
|
+
* @param params.referralFee.bps - Optional integer referral fee in basis points; defaults to zero and must be below 10,000.
|
|
33
|
+
* @param params.referralFee.recipient - Non-zero fee recipient required when the optional fee is positive.
|
|
34
|
+
* @param params.supportSignature - Optional Morpho authorization signature preference, defaulting to `false`; otherwise prepares a direct authorization transaction when needed.
|
|
35
|
+
* @param params.now - Optional reference timestamp in Unix seconds, normally the latest block timestamp; defaults to the device clock.
|
|
36
|
+
* @param params.expiresAt - Optional safe-integer Unix expiry later than `now`; defaults to `now + 2h` and governs every deadline.
|
|
37
|
+
* @param params.calldataOrigin - Optional non-empty, even-length hex bytes appended verbatim to every built transaction.
|
|
38
|
+
* @param params.deployless - Optional shared intent field; unused because this operation reads no token metadata or allowances.
|
|
39
|
+
* @returns A deep-frozen, data-only `TransactionPlan` with chain, account, expiry, withdrawal step,
|
|
40
|
+
* and any preceding Morpho authorization step and signature request. The caller signs; the SDK never does.
|
|
41
|
+
* @throws {BlueSnapshotChainMismatchError} when either snapshot's chain differs from `chainId`.
|
|
42
|
+
* @throws {MarketIdMismatchError} when either snapshot describes another market or a market ID does not hash from its tuple.
|
|
43
|
+
* @throws {AccrualPositionUserMismatchError} when the position belongs to another account.
|
|
44
|
+
* @throws {ZeroAccountError} when `account` is the zero address.
|
|
45
|
+
* @throws {NonIntegerInputError} when `expiresAt` or `referralFee.bps` is not a safe integer.
|
|
46
|
+
* @throws {NonPositiveInputError} when `expiresAt` or `collateralAssets` is not positive.
|
|
47
|
+
* @throws {ExpiredDeadlineError} when `expiresAt` is at or before `now`.
|
|
48
|
+
* @throws {NegativeInputError} when `referralFee.bps` is negative.
|
|
49
|
+
* @throws {InputExceedsMaxError} when `referralFee.bps` exceeds 10,000 or `collateralAssets` exceeds uint256.
|
|
50
|
+
* @throws {InvalidCalldataOriginError} when `calldataOrigin` is empty, malformed or has an odd number of hex digits.
|
|
51
|
+
* @throws {ReferralFeePctExceededError} when `referralFee.bps` equals 10,000.
|
|
52
|
+
* @throws {ReferralFeeRecipientMissingError} when a positive referral fee has no non-zero recipient.
|
|
53
|
+
* @throws {UnsupportedMarketIrmError} when projecting an indebted position requires an unsupported IRM without rate data.
|
|
54
|
+
* @throws {WithdrawExceedsCollateralError} when `collateralAssets` exceeds the position's collateral.
|
|
55
|
+
* @throws {MissingMarketPriceError} when the position carries debt but its market price is missing or zero.
|
|
56
|
+
* @throws {WithdrawMakesPositionUnhealthyError} when the accrued remaining position would breach LLTV minus the default buffer.
|
|
57
|
+
* @throws {UnsupportedChainIdError} when the chain is absent from the address registry.
|
|
58
|
+
* @throws {UnknownAddressError} when Morpho or BlueBundlesV1 is not registered on the target chain.
|
|
59
|
+
* @throws {MissingContractCodeError} when Morpho or BlueBundlesV1 has no deployed bytecode on the endpoint's chain.
|
|
60
|
+
* @throws {ChainIdMismatchError} when the client declares or its RPC reports another chain.
|
|
61
|
+
* @throws {viem.BaseError} when a contract-code, chain ID, authorization or nonce RPC read fails.
|
|
62
|
+
* @example
|
|
63
|
+
* ```ts
|
|
64
|
+
* import assert from "node:assert/strict";
|
|
65
|
+
* import { markets } from "@morpho-org/morpho-test";
|
|
66
|
+
* import { fetchAccrualPosition } from "@morpho-org/morpho-sdk/blue/fetch";
|
|
67
|
+
* import {
|
|
68
|
+
* applySignatures, buildTransactions, getPendingSignatureRequests,
|
|
69
|
+
* prepareBlueWithdrawCollateral,
|
|
70
|
+
* } from "@morpho-org/morpho-sdk";
|
|
71
|
+
* import { createPublicClient, createWalletClient, custom, type EIP1193Provider, http } from "viem";
|
|
72
|
+
* import { mainnet } from "viem/chains";
|
|
73
|
+
*
|
|
74
|
+
* const client = createPublicClient({ chain: mainnet, transport: http() });
|
|
75
|
+
* const { ethereum } = window as Window & { ethereum?: EIP1193Provider };
|
|
76
|
+
* if (!ethereum) throw new Error("Install an Ethereum wallet to continue.");
|
|
77
|
+
* const wallet = createWalletClient({ chain: mainnet, transport: custom(ethereum) });
|
|
78
|
+
* const [account] = await wallet.requestAddresses();
|
|
79
|
+
* assert(account, "Connect a wallet holding collateral in this market.");
|
|
80
|
+
* const market = markets[mainnet.id].usdc_wbtc;
|
|
81
|
+
* const position = await fetchAccrualPosition(account, market.id, client);
|
|
82
|
+
* const plan = await prepareBlueWithdrawCollateral(client, {
|
|
83
|
+
* chainId: mainnet.id, account, marketId: market.id,
|
|
84
|
+
* marketData: { chainId: mainnet.id, market: position.market },
|
|
85
|
+
* positionData: { chainId: mainnet.id, position },
|
|
86
|
+
* collateralAssets: 1_000_000n, supportSignature: true,
|
|
87
|
+
* now: (await client.getBlock()).timestamp,
|
|
88
|
+
* });
|
|
89
|
+
* // plan satisfies TransactionPlan; no token approval or Permit2 request is included.
|
|
90
|
+
* const signatures = await Promise.all(getPendingSignatureRequests(plan).map(
|
|
91
|
+
* async ({ id, typedData }) => ({ id, signature: await wallet.signTypedData({ ...typedData, account }) }),
|
|
92
|
+
* ));
|
|
93
|
+
* const transactions = buildTransactions(applySignatures(plan, signatures));
|
|
94
|
+
* // transactions satisfies readonly Readonly<Transaction>[]; submit them in order from account.
|
|
95
|
+
* ```
|
|
96
|
+
* @experimental TransactionPlan is in beta; breaking changes may ship in minor releases.
|
|
97
|
+
*/
|
|
98
|
+
async function prepareBlueWithdrawCollateral(client, params) {
|
|
99
|
+
const now = params.now ?? morpho_ts_1.Time.timestamp();
|
|
100
|
+
const { chainId, account, collateralAssets, marketId } = params;
|
|
101
|
+
const { loanToken, collateralToken, oracle, irm, lltv } = params.marketData.market.params;
|
|
102
|
+
const marketParams = { loanToken, collateralToken, oracle, irm, lltv };
|
|
103
|
+
const { intent, steps, signatureRequests, morphoAuthorizationRequestId } = await (0, prepare_js_1.prepareBlue)({ client, params: { ...params, now } }, (resolvedIntent) => {
|
|
104
|
+
// Reject invalid fees and deadlines before authorization reads.
|
|
105
|
+
(0, common_js_1.normalizeBundlesCommonParams)(resolvedIntent);
|
|
106
|
+
if (collateralAssets <= 0n) {
|
|
107
|
+
throw new index_js_1.NonPositiveInputError("collateralAssets", collateralAssets);
|
|
108
|
+
}
|
|
109
|
+
// Reject amounts outside the ABI range before reading authorization state.
|
|
110
|
+
(0, validate_js_1.validateUint256Field)("collateralAssets", collateralAssets);
|
|
111
|
+
const position = params.positionData.position;
|
|
112
|
+
// Validate health against the same accrual horizon used by the existing handle.
|
|
113
|
+
(0, validate_js_1.validatePositionHealthAfterWithdraw)({
|
|
114
|
+
positionData: position.borrowShares === 0n
|
|
115
|
+
? new blue_sdk_1.AccrualPosition(position, position.market)
|
|
116
|
+
: position.accrueInterest(blue_sdk_1.MathLib.max(now, position.market.lastUpdate) +
|
|
117
|
+
morpho_ts_1.Time.s.from.h(2n)),
|
|
118
|
+
withdrawAmount: collateralAssets,
|
|
119
|
+
lltv,
|
|
120
|
+
marketId,
|
|
121
|
+
});
|
|
122
|
+
return { id: "blueWithdrawCollateral", needsAuthorization: true };
|
|
123
|
+
});
|
|
124
|
+
return (0, morpho_ts_1.deepFreeze)({
|
|
125
|
+
version: 2,
|
|
126
|
+
chainId,
|
|
127
|
+
account,
|
|
128
|
+
expiresAt: intent.expiresAt,
|
|
129
|
+
...(intent.calldataOrigin && { calldataOrigin: intent.calldataOrigin }),
|
|
130
|
+
steps: [
|
|
131
|
+
...steps,
|
|
132
|
+
{
|
|
133
|
+
id: "blueWithdrawCollateral",
|
|
134
|
+
label: "Withdraw Blue collateral",
|
|
135
|
+
action: {
|
|
136
|
+
type: "blueWithdrawCollateral",
|
|
137
|
+
signatureRequestIds: morphoAuthorizationRequestId === undefined
|
|
138
|
+
? {}
|
|
139
|
+
: { morphoAuthorization: morphoAuthorizationRequestId },
|
|
140
|
+
inputs: {
|
|
141
|
+
chainId,
|
|
142
|
+
account,
|
|
143
|
+
collateralAssets,
|
|
144
|
+
...(morphoAuthorizationRequestId === undefined
|
|
145
|
+
? {}
|
|
146
|
+
: {
|
|
147
|
+
authorizationNonce: signatureRequests.find(({ id }) => id === morphoAuthorizationRequestId)?.args.nonce,
|
|
148
|
+
}),
|
|
149
|
+
marketParams,
|
|
150
|
+
maxLtv: blue_sdk_1.MathLib.zeroFloorSub(lltv, constant_js_1.DEFAULT_LLTV_BUFFER),
|
|
151
|
+
...(0, common_js_1.normalizeBundlesCommonParams)(intent),
|
|
152
|
+
},
|
|
153
|
+
},
|
|
154
|
+
},
|
|
155
|
+
],
|
|
156
|
+
signatureRequests,
|
|
157
|
+
});
|
|
158
|
+
}
|
|
159
|
+
/** @internal Binds an inline authorization to the collateral withdrawal that consumes it. */
|
|
160
|
+
function validateBlueWithdrawCollateralAuthorizationRequest(request, action) {
|
|
161
|
+
if (action.signatureRequestIds.morphoAuthorization !== request.id ||
|
|
162
|
+
action.inputs.authorizationNonce === undefined) {
|
|
163
|
+
throw new error_js_1.TransactionPlanSignatureMismatchError(request.id, "reference");
|
|
164
|
+
}
|
|
165
|
+
// Pin the signature to the prepared collateral withdrawal's nonce and deadline.
|
|
166
|
+
(0, authorization_js_1.validateMorphoAuthorizationRequest)(request, {
|
|
167
|
+
...action.inputs,
|
|
168
|
+
nonce: action.inputs.authorizationNonce,
|
|
169
|
+
});
|
|
170
|
+
}
|
|
171
|
+
/** @internal Encodes the self-contained collateral withdrawal recipe. */
|
|
172
|
+
function buildBlueWithdrawCollateral(action, requests) {
|
|
173
|
+
const { chainId, account, marketParams, authorizationNonce: _authorizationNonce, ...args } = action.inputs;
|
|
174
|
+
const id = action.signatureRequestIds.morphoAuthorization;
|
|
175
|
+
const request = id === undefined
|
|
176
|
+
? undefined
|
|
177
|
+
: requests.find((candidate) => candidate.id === id);
|
|
178
|
+
if (id !== undefined &&
|
|
179
|
+
(request?.kind !== "morphoAuthorization" || request.signature === undefined)) {
|
|
180
|
+
throw new error_js_1.IncompleteTransactionPlanError(id);
|
|
181
|
+
}
|
|
182
|
+
if (request?.kind === "morphoAuthorization") {
|
|
183
|
+
validateBlueWithdrawCollateralAuthorizationRequest(request, action);
|
|
184
|
+
}
|
|
185
|
+
return (0, withdrawCollateral_js_1.blueWithdrawCollateral)({
|
|
186
|
+
market: { chainId, marketParams: new blue_sdk_1.MarketParams(marketParams) },
|
|
187
|
+
args: {
|
|
188
|
+
...args,
|
|
189
|
+
userAddress: account,
|
|
190
|
+
authorizationSignature: request?.kind === "morphoAuthorization" &&
|
|
191
|
+
request.signature !== undefined
|
|
192
|
+
? {
|
|
193
|
+
action: {
|
|
194
|
+
type: "authorization",
|
|
195
|
+
args: {
|
|
196
|
+
authorized: request.args.authorized,
|
|
197
|
+
isAuthorized: true,
|
|
198
|
+
deadline: request.args.deadline,
|
|
199
|
+
},
|
|
200
|
+
typedData: request.typedData,
|
|
201
|
+
},
|
|
202
|
+
args: {
|
|
203
|
+
...request.args,
|
|
204
|
+
isAuthorized: true,
|
|
205
|
+
signature: request.signature,
|
|
206
|
+
},
|
|
207
|
+
}
|
|
208
|
+
: undefined,
|
|
209
|
+
},
|
|
210
|
+
});
|
|
211
|
+
}
|
|
212
|
+
/** @internal Validates the stored collateral withdrawal's structural inputs. */
|
|
213
|
+
function validateBlueWithdrawCollateralPlanAction(action, path) {
|
|
214
|
+
const inputs = (0, validation_js_1.getPlanObject)(action.inputs, `${path}.inputs`);
|
|
215
|
+
const ids = (0, validation_js_1.getPlanObject)(action.signatureRequestIds, `${path}.signatureRequestIds`);
|
|
216
|
+
if (ids.morphoAuthorization !== undefined) {
|
|
217
|
+
(0, validation_js_1.validatePlanField)(ids.morphoAuthorization, {
|
|
218
|
+
path: `${path}.signatureRequestIds.morphoAuthorization`,
|
|
219
|
+
type: "string",
|
|
220
|
+
});
|
|
221
|
+
(0, validation_js_1.validatePlanField)(inputs.authorizationNonce, {
|
|
222
|
+
path: `${path}.inputs.authorizationNonce`,
|
|
223
|
+
type: "uint256 bigint",
|
|
224
|
+
});
|
|
225
|
+
}
|
|
226
|
+
(0, validation_js_1.validatePlanFields)(inputs, {
|
|
227
|
+
path: `${path}.inputs`,
|
|
228
|
+
fields: {
|
|
229
|
+
collateralAssets: "uint256 bigint",
|
|
230
|
+
maxLtv: "uint256 bigint",
|
|
231
|
+
deadline: "uint256 bigint",
|
|
232
|
+
referralFeePct: "uint256 bigint",
|
|
233
|
+
referralFeeRecipient: "address",
|
|
234
|
+
},
|
|
235
|
+
});
|
|
236
|
+
(0, validation_js_1.validatePlanFields)((0, validation_js_1.getPlanObject)(inputs.marketParams, `${path}.inputs.marketParams`), {
|
|
237
|
+
path: `${path}.inputs.marketParams`,
|
|
238
|
+
fields: {
|
|
239
|
+
loanToken: "address",
|
|
240
|
+
collateralToken: "address",
|
|
241
|
+
oracle: "address",
|
|
242
|
+
irm: "address",
|
|
243
|
+
lltv: "uint256 bigint",
|
|
244
|
+
},
|
|
245
|
+
});
|
|
246
|
+
}
|
|
@@ -70,9 +70,10 @@ async function prepareVaultDeposit(client, params) {
|
|
|
70
70
|
const now = params.now ?? morpho_ts_1.Time.timestamp();
|
|
71
71
|
const { intent, native, common, asset, maxSharePrice } = resolveDepositInputs(params, now);
|
|
72
72
|
const spender = (0, morpho_ts_1.getChainAddress)(chainId, "bundles.vaultBundlesV1");
|
|
73
|
+
const tokenPermitRequestId = `${params.type}:tokenPermit`;
|
|
73
74
|
const [requirements] = await Promise.all([
|
|
74
75
|
(0, validateClientChainId_js_1.validateClientChainId)(client, chainId).then(() => native
|
|
75
|
-
?
|
|
76
|
+
? undefined
|
|
76
77
|
: (0, requirements_js_1.getTokenRequirements)(client, {
|
|
77
78
|
token: asset,
|
|
78
79
|
spender,
|
|
@@ -83,29 +84,17 @@ async function prepareVaultDeposit(client, params) {
|
|
|
83
84
|
now,
|
|
84
85
|
supportSignature: intent.supportSignature,
|
|
85
86
|
deployless: intent.deployless,
|
|
87
|
+
permitId: tokenPermitRequestId,
|
|
88
|
+
approvalId: (index) => index === 0
|
|
89
|
+
? `${params.type}:approval`
|
|
90
|
+
: `${params.type}:approval:${index + 1}`,
|
|
86
91
|
})),
|
|
87
92
|
(0, assertContractCode_js_1.assertRegistryTargetsHaveCode)(client, chainId, [
|
|
88
93
|
{ role: "bundles.vaultBundlesV1", address: spender },
|
|
89
94
|
]),
|
|
90
95
|
]);
|
|
91
|
-
const approvals = [];
|
|
92
|
-
const signatureRequests = [];
|
|
93
|
-
const tokenPermitRequestId = `${params.type}:tokenPermit`;
|
|
94
|
-
for (const requirement of requirements) {
|
|
95
|
-
if ("sign" in requirement) {
|
|
96
|
-
signatureRequests.push((0, requirements_js_1.buildPermitSignatureRequest)(requirement, tokenPermitRequestId));
|
|
97
|
-
}
|
|
98
|
-
else {
|
|
99
|
-
approvals.push((0, requirements_js_1.buildApprovalStep)(requirement, {
|
|
100
|
-
id: approvals.length === 0
|
|
101
|
-
? `${params.type}:approval`
|
|
102
|
-
: `${params.type}:approval:${approvals.length + 1}`,
|
|
103
|
-
chainId,
|
|
104
|
-
account,
|
|
105
|
-
denomination: "assets",
|
|
106
|
-
}));
|
|
107
|
-
}
|
|
108
|
-
}
|
|
96
|
+
const approvals = requirements?.approvals ?? [];
|
|
97
|
+
const signatureRequests = requirements?.permit === undefined ? [] : [requirements.permit];
|
|
109
98
|
return (0, morpho_ts_1.deepFreeze)(structuredClone({
|
|
110
99
|
version: 2,
|
|
111
100
|
account,
|
|
@@ -1,4 +1,54 @@
|
|
|
1
1
|
import type { Address } from "viem";
|
|
2
|
+
/**
|
|
3
|
+
* @experimental TransactionPlan is in beta; breaking changes may ship in minor releases.
|
|
4
|
+
* A caller-provided Blue market or position snapshot was read on a different chain.
|
|
5
|
+
* @example
|
|
6
|
+
* ```ts
|
|
7
|
+
* import { BlueSnapshotChainMismatchError } from "@morpho-org/morpho-sdk";
|
|
8
|
+
* const error = new BlueSnapshotChainMismatchError(8453, 1);
|
|
9
|
+
* ```
|
|
10
|
+
*/
|
|
11
|
+
export declare class BlueSnapshotChainMismatchError extends Error {
|
|
12
|
+
readonly snapshotChainId: number;
|
|
13
|
+
readonly chainId: number;
|
|
14
|
+
/**
|
|
15
|
+
* @param snapshotChainId - Chain the snapshot was read from.
|
|
16
|
+
* @param chainId - Chain the operation targets.
|
|
17
|
+
*/
|
|
18
|
+
constructor(snapshotChainId: number, chainId: number);
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* @experimental TransactionPlan is in beta; breaking changes may ship in minor releases.
|
|
22
|
+
* A caller-provided Blue market snapshot describes a different market state than the market
|
|
23
|
+
* embedded in the position snapshot, so quotes and health checks would mix two states.
|
|
24
|
+
* @example
|
|
25
|
+
* ```ts
|
|
26
|
+
* import { BlueSnapshotStateMismatchError } from "@morpho-org/morpho-sdk";
|
|
27
|
+
* const error = new BlueSnapshotStateMismatchError({
|
|
28
|
+
* field: "totalBorrowAssets",
|
|
29
|
+
* positionValue: 100n,
|
|
30
|
+
* marketValue: 200n,
|
|
31
|
+
* });
|
|
32
|
+
* ```
|
|
33
|
+
*/
|
|
34
|
+
export declare class BlueSnapshotStateMismatchError extends Error {
|
|
35
|
+
/** Market state field that differs between the snapshots. */
|
|
36
|
+
readonly field: string;
|
|
37
|
+
/** Value in the market embedded in the position snapshot. */
|
|
38
|
+
readonly positionValue: bigint | undefined;
|
|
39
|
+
/** Value in the market snapshot. */
|
|
40
|
+
readonly marketValue: bigint | undefined;
|
|
41
|
+
/**
|
|
42
|
+
* @param params.field - Market state field that differs between the snapshots.
|
|
43
|
+
* @param params.positionValue - Value in the market embedded in the position snapshot.
|
|
44
|
+
* @param params.marketValue - Value in the market snapshot.
|
|
45
|
+
*/
|
|
46
|
+
constructor({ field, positionValue, marketValue, }: {
|
|
47
|
+
readonly field: string;
|
|
48
|
+
readonly positionValue: bigint | undefined;
|
|
49
|
+
readonly marketValue: bigint | undefined;
|
|
50
|
+
});
|
|
51
|
+
}
|
|
2
52
|
/**
|
|
3
53
|
* @experimental TransactionPlan is in beta; breaking changes may ship in minor releases.
|
|
4
54
|
* Thrown when an operation's account is the zero address.
|
|
@@ -1,6 +1,65 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.NonIntegerInputError = exports.InvalidCalldataOriginError = exports.TransactionPlanSignatureMismatchError = exports.IncompleteTransactionPlanError = exports.InvalidTransactionPlanError = exports.UnsupportedTransactionPlanActionError = exports.UnsupportedTransactionPlanVersionError = exports.ZeroAccountError = void 0;
|
|
3
|
+
exports.NonIntegerInputError = exports.InvalidCalldataOriginError = exports.TransactionPlanSignatureMismatchError = exports.IncompleteTransactionPlanError = exports.InvalidTransactionPlanError = exports.UnsupportedTransactionPlanActionError = exports.UnsupportedTransactionPlanVersionError = exports.ZeroAccountError = exports.BlueSnapshotStateMismatchError = exports.BlueSnapshotChainMismatchError = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* @experimental TransactionPlan is in beta; breaking changes may ship in minor releases.
|
|
6
|
+
* A caller-provided Blue market or position snapshot was read on a different chain.
|
|
7
|
+
* @example
|
|
8
|
+
* ```ts
|
|
9
|
+
* import { BlueSnapshotChainMismatchError } from "@morpho-org/morpho-sdk";
|
|
10
|
+
* const error = new BlueSnapshotChainMismatchError(8453, 1);
|
|
11
|
+
* ```
|
|
12
|
+
*/
|
|
13
|
+
class BlueSnapshotChainMismatchError extends Error {
|
|
14
|
+
snapshotChainId;
|
|
15
|
+
chainId;
|
|
16
|
+
/**
|
|
17
|
+
* @param snapshotChainId - Chain the snapshot was read from.
|
|
18
|
+
* @param chainId - Chain the operation targets.
|
|
19
|
+
*/
|
|
20
|
+
constructor(snapshotChainId, chainId) {
|
|
21
|
+
super(`Expected a Blue snapshot on chain "${chainId}", got "${snapshotChainId}". Fetch the snapshot on the operation chain.`);
|
|
22
|
+
this.snapshotChainId = snapshotChainId;
|
|
23
|
+
this.chainId = chainId;
|
|
24
|
+
this.name = "BlueSnapshotChainMismatchError";
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
exports.BlueSnapshotChainMismatchError = BlueSnapshotChainMismatchError;
|
|
28
|
+
/**
|
|
29
|
+
* @experimental TransactionPlan is in beta; breaking changes may ship in minor releases.
|
|
30
|
+
* A caller-provided Blue market snapshot describes a different market state than the market
|
|
31
|
+
* embedded in the position snapshot, so quotes and health checks would mix two states.
|
|
32
|
+
* @example
|
|
33
|
+
* ```ts
|
|
34
|
+
* import { BlueSnapshotStateMismatchError } from "@morpho-org/morpho-sdk";
|
|
35
|
+
* const error = new BlueSnapshotStateMismatchError({
|
|
36
|
+
* field: "totalBorrowAssets",
|
|
37
|
+
* positionValue: 100n,
|
|
38
|
+
* marketValue: 200n,
|
|
39
|
+
* });
|
|
40
|
+
* ```
|
|
41
|
+
*/
|
|
42
|
+
class BlueSnapshotStateMismatchError extends Error {
|
|
43
|
+
/** Market state field that differs between the snapshots. */
|
|
44
|
+
field;
|
|
45
|
+
/** Value in the market embedded in the position snapshot. */
|
|
46
|
+
positionValue;
|
|
47
|
+
/** Value in the market snapshot. */
|
|
48
|
+
marketValue;
|
|
49
|
+
/**
|
|
50
|
+
* @param params.field - Market state field that differs between the snapshots.
|
|
51
|
+
* @param params.positionValue - Value in the market embedded in the position snapshot.
|
|
52
|
+
* @param params.marketValue - Value in the market snapshot.
|
|
53
|
+
*/
|
|
54
|
+
constructor({ field, positionValue, marketValue, }) {
|
|
55
|
+
super(`Expected market snapshot ${field} "${positionValue}" from the position snapshot, got "${marketValue}". Fetch the market and position snapshots from the same market state.`);
|
|
56
|
+
this.field = field;
|
|
57
|
+
this.positionValue = positionValue;
|
|
58
|
+
this.marketValue = marketValue;
|
|
59
|
+
this.name = "BlueSnapshotStateMismatchError";
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
exports.BlueSnapshotStateMismatchError = BlueSnapshotStateMismatchError;
|
|
4
63
|
/**
|
|
5
64
|
* @experimental TransactionPlan is in beta; breaking changes may ship in minor releases.
|
|
6
65
|
* Thrown when an operation's account is the zero address.
|
|
@@ -1,11 +1,20 @@
|
|
|
1
|
-
import { type Client } from "viem";
|
|
2
|
-
import type {
|
|
3
|
-
import type { Erc2612RequirementSignature, Requirement } from "../types/index.js";
|
|
1
|
+
import { type Address, type Client } from "viem";
|
|
2
|
+
import type { SignatureRequest } from "./types.js";
|
|
4
3
|
/**
|
|
5
|
-
* @internal
|
|
6
|
-
*
|
|
7
|
-
*
|
|
4
|
+
* @internal Prepares an unsigned ERC-2612 request when the nonce and domain are usable.
|
|
5
|
+
* DAI's nonstandard permit is excluded; failed contract probes fall back to approval, but
|
|
6
|
+
* transport failures propagate.
|
|
8
7
|
*/
|
|
9
|
-
export declare function getTokenPermit(client: Client, params:
|
|
8
|
+
export declare function getTokenPermit(client: Client, params: {
|
|
9
|
+
readonly id: string;
|
|
10
|
+
readonly token: Address;
|
|
11
|
+
readonly spender: Address;
|
|
12
|
+
readonly amount: bigint;
|
|
13
|
+
readonly owner: Address;
|
|
14
|
+
readonly chainId: number;
|
|
15
|
+
readonly deadline: bigint;
|
|
10
16
|
readonly now: bigint;
|
|
11
|
-
|
|
17
|
+
readonly supportDeployless: boolean | undefined;
|
|
18
|
+
}): Promise<Extract<SignatureRequest, {
|
|
19
|
+
kind: "permit";
|
|
20
|
+
}> | undefined>;
|
|
@@ -2,18 +2,46 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.getTokenPermit = getTokenPermit;
|
|
4
4
|
const blue_sdk_1 = require("@morpho-org/blue-sdk");
|
|
5
|
+
const blue_sdk_viem_1 = require("@morpho-org/blue-sdk-viem");
|
|
5
6
|
const morpho_ts_1 = require("@morpho-org/morpho-ts");
|
|
6
7
|
const viem_1 = require("viem");
|
|
7
|
-
const
|
|
8
|
+
const readErc2612Permit_js_1 = require("../reads/readErc2612Permit.js");
|
|
8
9
|
/**
|
|
9
|
-
* @internal
|
|
10
|
-
*
|
|
11
|
-
*
|
|
10
|
+
* @internal Prepares an unsigned ERC-2612 request when the nonce and domain are usable.
|
|
11
|
+
* DAI's nonstandard permit is excluded; failed contract probes fall back to approval, but
|
|
12
|
+
* transport failures propagate.
|
|
12
13
|
*/
|
|
13
14
|
async function getTokenPermit(client, params) {
|
|
14
|
-
const {
|
|
15
|
-
|
|
15
|
+
const { id, token, spender, amount, owner, chainId, supportDeployless } = params;
|
|
16
|
+
const { dai } = (0, blue_sdk_1.getChainAddresses)(chainId);
|
|
17
|
+
if ((0, morpho_ts_1.isDefined)(dai) && (0, viem_1.isAddressEqual)(token, dai)) {
|
|
16
18
|
return undefined;
|
|
17
19
|
}
|
|
18
|
-
return (0,
|
|
20
|
+
return (0, readErc2612Permit_js_1.readErc2612Permit)(client, {
|
|
21
|
+
token,
|
|
22
|
+
owner,
|
|
23
|
+
resolve: async (nonce) => {
|
|
24
|
+
const deadline = await (0, readErc2612Permit_js_1.validateErc2612Permit)(client, params);
|
|
25
|
+
const typedData = (0, blue_sdk_viem_1.getPermitTypedData)({
|
|
26
|
+
erc20: await (0, blue_sdk_viem_1.fetchToken)(token, client, {
|
|
27
|
+
deployless: supportDeployless,
|
|
28
|
+
}),
|
|
29
|
+
owner,
|
|
30
|
+
spender,
|
|
31
|
+
allowance: amount,
|
|
32
|
+
nonce,
|
|
33
|
+
deadline,
|
|
34
|
+
}, chainId);
|
|
35
|
+
const domain = { ...typedData.domain };
|
|
36
|
+
return {
|
|
37
|
+
domain,
|
|
38
|
+
result: {
|
|
39
|
+
id,
|
|
40
|
+
kind: "permit",
|
|
41
|
+
typedData: { ...typedData, domain },
|
|
42
|
+
args: { spender, amount, deadline, nonce },
|
|
43
|
+
},
|
|
44
|
+
};
|
|
45
|
+
},
|
|
46
|
+
});
|
|
19
47
|
}
|
|
@@ -1,4 +1,24 @@
|
|
|
1
|
-
export {
|
|
1
|
+
export type { BlueBorrowPlanParams } from "./blue/borrow.js";
|
|
2
|
+
export { prepareBlueBorrow } from "./blue/borrow.js";
|
|
3
|
+
export type { BlueMarketSnapshot, BluePositionSnapshot, } from "./blue/prepare.js";
|
|
4
|
+
export { validateBlueMarketSnapshot } from "./blue/prepare.js";
|
|
5
|
+
export type { BlueRefinancePlanParams } from "./blue/refinance.js";
|
|
6
|
+
export { prepareBlueRefinance } from "./blue/refinance.js";
|
|
7
|
+
export type { BlueRepayPlanParams } from "./blue/repay.js";
|
|
8
|
+
export { prepareBlueRepay } from "./blue/repay.js";
|
|
9
|
+
export type { BlueRepayWithdrawCollateralPlanParams } from "./blue/repayWithdrawCollateral.js";
|
|
10
|
+
export { prepareBlueRepayWithdrawCollateral } from "./blue/repayWithdrawCollateral.js";
|
|
11
|
+
export type { BlueSupplyPlanParams } from "./blue/supply.js";
|
|
12
|
+
export { prepareBlueSupply } from "./blue/supply.js";
|
|
13
|
+
export type { BlueSupplyCollateralPlanParams } from "./blue/supplyCollateral.js";
|
|
14
|
+
export { prepareBlueSupplyCollateral } from "./blue/supplyCollateral.js";
|
|
15
|
+
export type { BlueSupplyCollateralBorrowPlanParams } from "./blue/supplyCollateralBorrow.js";
|
|
16
|
+
export { prepareBlueSupplyCollateralBorrow } from "./blue/supplyCollateralBorrow.js";
|
|
17
|
+
export type { BlueWithdrawPlanParams } from "./blue/withdraw.js";
|
|
18
|
+
export { prepareBlueWithdraw } from "./blue/withdraw.js";
|
|
19
|
+
export type { BlueWithdrawCollateralPlanParams } from "./blue/withdrawCollateral.js";
|
|
20
|
+
export { prepareBlueWithdrawCollateral } from "./blue/withdrawCollateral.js";
|
|
21
|
+
export { BlueSnapshotChainMismatchError, BlueSnapshotStateMismatchError, IncompleteTransactionPlanError, InvalidCalldataOriginError, InvalidTransactionPlanError, NonIntegerInputError, TransactionPlanSignatureMismatchError, UnsupportedTransactionPlanActionError, UnsupportedTransactionPlanVersionError, ZeroAccountError, } from "./error.js";
|
|
2
22
|
export type { Funding, IntentParams, ReferralFee, } from "./intent.js";
|
|
3
23
|
export { applySignatures, buildTransaction, buildTransactions, getPendingSignatureRequests, } from "./plan.js";
|
|
4
24
|
export { parseTransactionPlan, serializeTransactionPlan } from "./serde.js";
|
|
@@ -1,7 +1,29 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.prepareVaultV2Withdraw = exports.prepareVaultV2Redeem = exports.prepareVaultV2InKindRedeem = exports.prepareVaultV2ForceWithdraw = exports.prepareVaultV2ForceRedeem = exports.prepareVaultV2Deposit = exports.prepareVaultV1Withdraw = exports.prepareVaultV1Redeem = exports.prepareVaultV1MigrateToV2 = exports.prepareVaultV1InKindRedeem = exports.prepareVaultV1Deposit = exports.serializeTransactionPlan = exports.parseTransactionPlan = exports.getPendingSignatureRequests = exports.buildTransactions = exports.buildTransaction = exports.applySignatures = exports.ZeroAccountError = exports.UnsupportedTransactionPlanVersionError = exports.UnsupportedTransactionPlanActionError = exports.TransactionPlanSignatureMismatchError = exports.NonIntegerInputError = exports.InvalidTransactionPlanError = exports.InvalidCalldataOriginError = exports.IncompleteTransactionPlanError = void 0;
|
|
3
|
+
exports.prepareVaultV2Withdraw = exports.prepareVaultV2Redeem = exports.prepareVaultV2InKindRedeem = exports.prepareVaultV2ForceWithdraw = exports.prepareVaultV2ForceRedeem = exports.prepareVaultV2Deposit = exports.prepareVaultV1Withdraw = exports.prepareVaultV1Redeem = exports.prepareVaultV1MigrateToV2 = exports.prepareVaultV1InKindRedeem = exports.prepareVaultV1Deposit = exports.serializeTransactionPlan = exports.parseTransactionPlan = exports.getPendingSignatureRequests = exports.buildTransactions = exports.buildTransaction = exports.applySignatures = exports.ZeroAccountError = exports.UnsupportedTransactionPlanVersionError = exports.UnsupportedTransactionPlanActionError = exports.TransactionPlanSignatureMismatchError = exports.NonIntegerInputError = exports.InvalidTransactionPlanError = exports.InvalidCalldataOriginError = exports.IncompleteTransactionPlanError = exports.BlueSnapshotStateMismatchError = exports.BlueSnapshotChainMismatchError = exports.prepareBlueWithdrawCollateral = exports.prepareBlueWithdraw = exports.prepareBlueSupplyCollateralBorrow = exports.prepareBlueSupplyCollateral = exports.prepareBlueSupply = exports.prepareBlueRepayWithdrawCollateral = exports.prepareBlueRepay = exports.prepareBlueRefinance = exports.validateBlueMarketSnapshot = exports.prepareBlueBorrow = void 0;
|
|
4
|
+
var borrow_js_1 = require("./blue/borrow.js");
|
|
5
|
+
Object.defineProperty(exports, "prepareBlueBorrow", { enumerable: true, get: function () { return borrow_js_1.prepareBlueBorrow; } });
|
|
6
|
+
var prepare_js_1 = require("./blue/prepare.js");
|
|
7
|
+
Object.defineProperty(exports, "validateBlueMarketSnapshot", { enumerable: true, get: function () { return prepare_js_1.validateBlueMarketSnapshot; } });
|
|
8
|
+
var refinance_js_1 = require("./blue/refinance.js");
|
|
9
|
+
Object.defineProperty(exports, "prepareBlueRefinance", { enumerable: true, get: function () { return refinance_js_1.prepareBlueRefinance; } });
|
|
10
|
+
var repay_js_1 = require("./blue/repay.js");
|
|
11
|
+
Object.defineProperty(exports, "prepareBlueRepay", { enumerable: true, get: function () { return repay_js_1.prepareBlueRepay; } });
|
|
12
|
+
var repayWithdrawCollateral_js_1 = require("./blue/repayWithdrawCollateral.js");
|
|
13
|
+
Object.defineProperty(exports, "prepareBlueRepayWithdrawCollateral", { enumerable: true, get: function () { return repayWithdrawCollateral_js_1.prepareBlueRepayWithdrawCollateral; } });
|
|
14
|
+
var supply_js_1 = require("./blue/supply.js");
|
|
15
|
+
Object.defineProperty(exports, "prepareBlueSupply", { enumerable: true, get: function () { return supply_js_1.prepareBlueSupply; } });
|
|
16
|
+
var supplyCollateral_js_1 = require("./blue/supplyCollateral.js");
|
|
17
|
+
Object.defineProperty(exports, "prepareBlueSupplyCollateral", { enumerable: true, get: function () { return supplyCollateral_js_1.prepareBlueSupplyCollateral; } });
|
|
18
|
+
var supplyCollateralBorrow_js_1 = require("./blue/supplyCollateralBorrow.js");
|
|
19
|
+
Object.defineProperty(exports, "prepareBlueSupplyCollateralBorrow", { enumerable: true, get: function () { return supplyCollateralBorrow_js_1.prepareBlueSupplyCollateralBorrow; } });
|
|
20
|
+
var withdraw_js_1 = require("./blue/withdraw.js");
|
|
21
|
+
Object.defineProperty(exports, "prepareBlueWithdraw", { enumerable: true, get: function () { return withdraw_js_1.prepareBlueWithdraw; } });
|
|
22
|
+
var withdrawCollateral_js_1 = require("./blue/withdrawCollateral.js");
|
|
23
|
+
Object.defineProperty(exports, "prepareBlueWithdrawCollateral", { enumerable: true, get: function () { return withdrawCollateral_js_1.prepareBlueWithdrawCollateral; } });
|
|
4
24
|
var error_js_1 = require("./error.js");
|
|
25
|
+
Object.defineProperty(exports, "BlueSnapshotChainMismatchError", { enumerable: true, get: function () { return error_js_1.BlueSnapshotChainMismatchError; } });
|
|
26
|
+
Object.defineProperty(exports, "BlueSnapshotStateMismatchError", { enumerable: true, get: function () { return error_js_1.BlueSnapshotStateMismatchError; } });
|
|
5
27
|
Object.defineProperty(exports, "IncompleteTransactionPlanError", { enumerable: true, get: function () { return error_js_1.IncompleteTransactionPlanError; } });
|
|
6
28
|
Object.defineProperty(exports, "InvalidCalldataOriginError", { enumerable: true, get: function () { return error_js_1.InvalidCalldataOriginError; } });
|
|
7
29
|
Object.defineProperty(exports, "InvalidTransactionPlanError", { enumerable: true, get: function () { return error_js_1.InvalidTransactionPlanError; } });
|
|
@@ -26,8 +48,8 @@ var migrateToV2_js_1 = require("./vaultv1/migrateToV2.js");
|
|
|
26
48
|
Object.defineProperty(exports, "prepareVaultV1MigrateToV2", { enumerable: true, get: function () { return migrateToV2_js_1.prepareVaultV1MigrateToV2; } });
|
|
27
49
|
var redeem_js_1 = require("./vaultv1/redeem.js");
|
|
28
50
|
Object.defineProperty(exports, "prepareVaultV1Redeem", { enumerable: true, get: function () { return redeem_js_1.prepareVaultV1Redeem; } });
|
|
29
|
-
var
|
|
30
|
-
Object.defineProperty(exports, "prepareVaultV1Withdraw", { enumerable: true, get: function () { return
|
|
51
|
+
var withdraw_js_2 = require("./vaultv1/withdraw.js");
|
|
52
|
+
Object.defineProperty(exports, "prepareVaultV1Withdraw", { enumerable: true, get: function () { return withdraw_js_2.prepareVaultV1Withdraw; } });
|
|
31
53
|
var deposit_js_2 = require("./vaultv2/deposit.js");
|
|
32
54
|
Object.defineProperty(exports, "prepareVaultV2Deposit", { enumerable: true, get: function () { return deposit_js_2.prepareVaultV2Deposit; } });
|
|
33
55
|
var forceRedeem_js_1 = require("./vaultv2/forceRedeem.js");
|
|
@@ -38,5 +60,5 @@ var inKindRedeem_js_2 = require("./vaultv2/inKindRedeem.js");
|
|
|
38
60
|
Object.defineProperty(exports, "prepareVaultV2InKindRedeem", { enumerable: true, get: function () { return inKindRedeem_js_2.prepareVaultV2InKindRedeem; } });
|
|
39
61
|
var redeem_js_2 = require("./vaultv2/redeem.js");
|
|
40
62
|
Object.defineProperty(exports, "prepareVaultV2Redeem", { enumerable: true, get: function () { return redeem_js_2.prepareVaultV2Redeem; } });
|
|
41
|
-
var
|
|
42
|
-
Object.defineProperty(exports, "prepareVaultV2Withdraw", { enumerable: true, get: function () { return
|
|
63
|
+
var withdraw_js_3 = require("./vaultv2/withdraw.js");
|
|
64
|
+
Object.defineProperty(exports, "prepareVaultV2Withdraw", { enumerable: true, get: function () { return withdraw_js_3.prepareVaultV2Withdraw; } });
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { type Address, type Hex } from "viem";
|
|
2
2
|
/**
|
|
3
3
|
* @experimental TransactionPlan is in beta; breaking changes may ship in minor releases.
|
|
4
|
-
* Which balance
|
|
4
|
+
* Which balance funds an operation: the ERC-20 token, or native currency the bundle wraps.
|
|
5
5
|
*/
|
|
6
6
|
export type Funding = {
|
|
7
7
|
readonly type: "erc20";
|
|
@@ -29,7 +29,7 @@ export interface IntentParams {
|
|
|
29
29
|
readonly supportSignature?: boolean;
|
|
30
30
|
/** Unix seconds. Defaults to two hours from now. */
|
|
31
31
|
readonly expiresAt?: number;
|
|
32
|
-
/** Optional attribution bytes appended verbatim to every built transaction's calldata. */
|
|
32
|
+
/** Optional attribution bytes (at most 1 MiB) appended verbatim to every built transaction's calldata. */
|
|
33
33
|
readonly calldataOrigin?: Hex;
|
|
34
34
|
/** Whether token metadata reads for permits may use deployless aggregation. */
|
|
35
35
|
readonly deployless?: boolean;
|
|
@@ -5,6 +5,7 @@ const morpho_ts_1 = require("@morpho-org/morpho-ts");
|
|
|
5
5
|
const viem_1 = require("viem");
|
|
6
6
|
const index_js_1 = require("../types/index.js");
|
|
7
7
|
const error_js_1 = require("./error.js");
|
|
8
|
+
const validation_js_1 = require("./validation.js");
|
|
8
9
|
const BASIS_POINTS = 10000n;
|
|
9
10
|
const WAD_PER_BASIS_POINT = morpho_ts_1.MathLib.WAD / BASIS_POINTS;
|
|
10
11
|
function toSafeInteger(field, value) {
|
|
@@ -21,6 +22,7 @@ function resolveIntent(params, now) {
|
|
|
21
22
|
if (params.account === viem_1.zeroAddress) {
|
|
22
23
|
throw new error_js_1.ZeroAccountError(params.account);
|
|
23
24
|
}
|
|
25
|
+
(0, validation_js_1.validatePlanField)(params.account, { path: "$.account", type: "address" });
|
|
24
26
|
const expiresAt = params.expiresAt ?? Number(now + morpho_ts_1.Time.s.from.h(2n));
|
|
25
27
|
const deadline = toSafeInteger("expiresAt", expiresAt);
|
|
26
28
|
if (deadline <= 0n) {
|
|
@@ -43,11 +45,13 @@ function resolveIntent(params, now) {
|
|
|
43
45
|
});
|
|
44
46
|
}
|
|
45
47
|
const { calldataOrigin } = params;
|
|
46
|
-
if (calldataOrigin !== undefined
|
|
47
|
-
(!(0, viem_1.isHex)(calldataOrigin, { strict: true }) ||
|
|
48
|
+
if (calldataOrigin !== undefined) {
|
|
49
|
+
if (!(0, viem_1.isHex)(calldataOrigin, { strict: true }) ||
|
|
48
50
|
calldataOrigin.length <= 2 ||
|
|
49
|
-
calldataOrigin.length % 2 !== 0)
|
|
50
|
-
|
|
51
|
+
calldataOrigin.length % 2 !== 0) {
|
|
52
|
+
throw new error_js_1.InvalidCalldataOriginError(calldataOrigin);
|
|
53
|
+
}
|
|
54
|
+
(0, validation_js_1.validateCalldataOriginLength)(calldataOrigin);
|
|
51
55
|
}
|
|
52
56
|
return {
|
|
53
57
|
expiresAt: Number(deadline),
|