@morpho-org/morpho-sdk 10.4.0 → 10.5.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/lib/cjs/actions/blue/common.js +12 -3
- package/lib/cjs/actions/midnight/supplyCollateralTakeBorrow.js +16 -11
- package/lib/cjs/actions/midnight/takeBorrow.js +14 -8
- package/lib/cjs/actions/midnight/takeLend.js +15 -9
- package/lib/cjs/actions/midnight/takeRepayWithdrawCollateral.js +19 -13
- package/lib/cjs/actions/midnight/takeWithdraw.js +14 -8
- package/lib/cjs/constants.d.ts +1 -1
- package/lib/cjs/constants.js +3 -2
- package/lib/cjs/entities/midnight/midnight.d.ts +106 -103
- package/lib/cjs/entities/midnight/midnight.js +120 -101
- package/lib/cjs/entities/vaultV1/vaultV1.js +0 -1
- package/lib/cjs/entities/vaultV2/vaultV2.js +0 -1
- package/lib/cjs/helpers/constant.d.ts +7 -0
- package/lib/cjs/helpers/constant.js +8 -1
- package/lib/cjs/helpers/index.d.ts +1 -1
- package/lib/cjs/helpers/index.js +2 -1
- package/lib/cjs/helpers/validate.d.ts +25 -1
- package/lib/cjs/helpers/validate.js +25 -1
- package/lib/cjs/transactionPlan/assemble.d.ts +24 -0
- package/lib/cjs/transactionPlan/assemble.js +25 -0
- package/lib/cjs/transactionPlan/blue/borrow.js +14 -64
- package/lib/cjs/transactionPlan/blue/refinance.js +9 -11
- package/lib/cjs/transactionPlan/blue/repay.js +10 -24
- package/lib/cjs/transactionPlan/blue/repayWithdrawCollateral.js +49 -45
- package/lib/cjs/transactionPlan/blue/stored.d.ts +26 -0
- package/lib/cjs/transactionPlan/blue/stored.js +87 -0
- package/lib/cjs/transactionPlan/blue/supply.js +7 -22
- package/lib/cjs/transactionPlan/blue/supplyCollateral.d.ts +1 -1
- package/lib/cjs/transactionPlan/blue/supplyCollateral.js +10 -15
- package/lib/cjs/transactionPlan/blue/supplyCollateralBorrow.js +14 -64
- package/lib/cjs/transactionPlan/blue/withdraw.d.ts +2 -3
- package/lib/cjs/transactionPlan/blue/withdraw.js +67 -79
- package/lib/cjs/transactionPlan/blue/withdrawCollateral.d.ts +2 -3
- package/lib/cjs/transactionPlan/blue/withdrawCollateral.js +31 -30
- package/lib/cjs/transactionPlan/deposit.js +4 -7
- package/lib/cjs/transactionPlan/intent.d.ts +1 -1
- package/lib/cjs/transactionPlan/midnight/makeBorrow.d.ts +1 -1
- package/lib/cjs/transactionPlan/midnight/makeBorrow.js +1 -1
- package/lib/cjs/transactionPlan/midnight/makeLend.d.ts +1 -1
- package/lib/cjs/transactionPlan/midnight/makeLend.js +1 -1
- package/lib/cjs/transactionPlan/midnight/makeRepay.d.ts +1 -1
- package/lib/cjs/transactionPlan/midnight/makeRepay.js +1 -1
- package/lib/cjs/transactionPlan/midnight/repayWithdrawCollateral.d.ts +1 -1
- package/lib/cjs/transactionPlan/midnight/repayWithdrawCollateral.js +1 -1
- package/lib/cjs/transactionPlan/midnight/supplyBlueMakeLend.d.ts +1 -1
- package/lib/cjs/transactionPlan/midnight/supplyBlueMakeLend.js +1 -1
- package/lib/cjs/transactionPlan/midnight/supplyCollateral.d.ts +1 -1
- package/lib/cjs/transactionPlan/midnight/supplyCollateral.js +1 -1
- package/lib/cjs/transactionPlan/midnight/supplyCollateralBatch.d.ts +1 -1
- package/lib/cjs/transactionPlan/midnight/supplyCollateralBatch.js +1 -1
- package/lib/cjs/transactionPlan/midnight/supplyCollateralMakeBorrow.d.ts +1 -1
- package/lib/cjs/transactionPlan/midnight/supplyCollateralMakeBorrow.js +1 -1
- package/lib/cjs/transactionPlan/midnight/supplyCollateralWithNative.d.ts +1 -1
- package/lib/cjs/transactionPlan/midnight/supplyCollateralWithNative.js +1 -1
- package/lib/cjs/transactionPlan/midnight/takeBorrow.d.ts +6 -2
- package/lib/cjs/transactionPlan/midnight/takeBorrow.js +10 -4
- package/lib/cjs/transactionPlan/midnight/takeRepayWithdrawCollateral.d.ts +1 -1
- package/lib/cjs/transactionPlan/midnight/takeRepayWithdrawCollateral.js +1 -1
- package/lib/cjs/transactionPlan/midnight/takeWithdraw.d.ts +1 -1
- package/lib/cjs/transactionPlan/midnight/takeWithdraw.js +1 -1
- package/lib/cjs/transactionPlan/permit.d.ts +15 -2
- package/lib/cjs/transactionPlan/permit.js +26 -68
- package/lib/cjs/transactionPlan/plan.d.ts +51 -1
- package/lib/cjs/transactionPlan/plan.js +56 -13
- package/lib/cjs/transactionPlan/redeem.js +4 -7
- package/lib/cjs/transactionPlan/types.d.ts +4 -3
- package/lib/cjs/transactionPlan/vaultBinding.d.ts +29 -0
- package/lib/cjs/transactionPlan/vaultBinding.js +69 -0
- package/lib/cjs/transactionPlan/vaultRequirements.d.ts +20 -0
- package/lib/cjs/transactionPlan/vaultRequirements.js +37 -0
- package/lib/cjs/transactionPlan/vaultv1/deposit.d.ts +1 -1
- package/lib/cjs/transactionPlan/vaultv1/deposit.js +2 -13
- package/lib/cjs/transactionPlan/vaultv1/inKindRedeem.d.ts +2 -2
- package/lib/cjs/transactionPlan/vaultv1/inKindRedeem.js +10 -41
- package/lib/cjs/transactionPlan/vaultv1/migrateToV2.d.ts +1 -1
- package/lib/cjs/transactionPlan/vaultv1/migrateToV2.js +6 -18
- package/lib/cjs/transactionPlan/vaultv1/redeem.js +1 -12
- package/lib/cjs/transactionPlan/vaultv1/withdraw.d.ts +1 -1
- package/lib/cjs/transactionPlan/vaultv1/withdraw.js +2 -13
- package/lib/cjs/transactionPlan/vaultv2/deposit.d.ts +1 -1
- package/lib/cjs/transactionPlan/vaultv2/deposit.js +2 -13
- package/lib/cjs/transactionPlan/vaultv2/forceRedeem.d.ts +1 -1
- package/lib/cjs/transactionPlan/vaultv2/forceRedeem.js +4 -7
- package/lib/cjs/transactionPlan/vaultv2/forceWithdraw.d.ts +2 -2
- package/lib/cjs/transactionPlan/vaultv2/forceWithdraw.js +12 -42
- package/lib/cjs/transactionPlan/vaultv2/inKindRedeem.d.ts +2 -2
- package/lib/cjs/transactionPlan/vaultv2/inKindRedeem.js +10 -41
- package/lib/cjs/transactionPlan/vaultv2/redeem.d.ts +1 -1
- package/lib/cjs/transactionPlan/vaultv2/redeem.js +2 -13
- package/lib/cjs/transactionPlan/vaultv2/withdraw.d.ts +1 -1
- package/lib/cjs/transactionPlan/vaultv2/withdraw.js +2 -13
- package/lib/cjs/transactionPlan/withdraw.js +4 -7
- package/lib/cjs/types/error.d.ts +27 -1
- package/lib/cjs/types/error.js +32 -3
- package/lib/cjs/version.d.ts +1 -1
- package/lib/cjs/version.js +1 -1
- package/lib/esm/actions/blue/common.js +13 -4
- package/lib/esm/actions/midnight/supplyCollateralTakeBorrow.js +16 -11
- package/lib/esm/actions/midnight/takeBorrow.js +14 -8
- package/lib/esm/actions/midnight/takeLend.js +15 -9
- package/lib/esm/actions/midnight/takeRepayWithdrawCollateral.js +19 -13
- package/lib/esm/actions/midnight/takeWithdraw.js +14 -8
- package/lib/esm/constants.d.ts +1 -1
- package/lib/esm/constants.js +1 -1
- package/lib/esm/entities/midnight/midnight.d.ts +106 -103
- package/lib/esm/entities/midnight/midnight.js +120 -101
- package/lib/esm/entities/vaultV1/vaultV1.js +0 -1
- package/lib/esm/entities/vaultV2/vaultV2.js +0 -1
- package/lib/esm/helpers/constant.d.ts +7 -0
- package/lib/esm/helpers/constant.js +7 -0
- package/lib/esm/helpers/index.d.ts +1 -1
- package/lib/esm/helpers/index.js +1 -1
- package/lib/esm/helpers/validate.d.ts +25 -1
- package/lib/esm/helpers/validate.js +25 -2
- package/lib/esm/transactionPlan/assemble.d.ts +24 -0
- package/lib/esm/transactionPlan/assemble.js +21 -0
- package/lib/esm/transactionPlan/blue/borrow.js +15 -65
- package/lib/esm/transactionPlan/blue/refinance.js +10 -12
- package/lib/esm/transactionPlan/blue/repay.js +11 -25
- package/lib/esm/transactionPlan/blue/repayWithdrawCollateral.js +50 -46
- package/lib/esm/transactionPlan/blue/stored.d.ts +26 -0
- package/lib/esm/transactionPlan/blue/stored.js +80 -0
- package/lib/esm/transactionPlan/blue/supply.js +7 -22
- package/lib/esm/transactionPlan/blue/supplyCollateral.d.ts +1 -1
- package/lib/esm/transactionPlan/blue/supplyCollateral.js +10 -15
- package/lib/esm/transactionPlan/blue/supplyCollateralBorrow.js +15 -65
- package/lib/esm/transactionPlan/blue/withdraw.d.ts +2 -3
- package/lib/esm/transactionPlan/blue/withdraw.js +70 -82
- package/lib/esm/transactionPlan/blue/withdrawCollateral.d.ts +2 -3
- package/lib/esm/transactionPlan/blue/withdrawCollateral.js +32 -31
- package/lib/esm/transactionPlan/deposit.js +5 -8
- package/lib/esm/transactionPlan/intent.d.ts +1 -1
- package/lib/esm/transactionPlan/midnight/makeBorrow.d.ts +1 -1
- package/lib/esm/transactionPlan/midnight/makeBorrow.js +1 -1
- package/lib/esm/transactionPlan/midnight/makeLend.d.ts +1 -1
- package/lib/esm/transactionPlan/midnight/makeLend.js +1 -1
- package/lib/esm/transactionPlan/midnight/makeRepay.d.ts +1 -1
- package/lib/esm/transactionPlan/midnight/makeRepay.js +1 -1
- package/lib/esm/transactionPlan/midnight/repayWithdrawCollateral.d.ts +1 -1
- package/lib/esm/transactionPlan/midnight/repayWithdrawCollateral.js +1 -1
- package/lib/esm/transactionPlan/midnight/supplyBlueMakeLend.d.ts +1 -1
- package/lib/esm/transactionPlan/midnight/supplyBlueMakeLend.js +1 -1
- package/lib/esm/transactionPlan/midnight/supplyCollateral.d.ts +1 -1
- package/lib/esm/transactionPlan/midnight/supplyCollateral.js +1 -1
- package/lib/esm/transactionPlan/midnight/supplyCollateralBatch.d.ts +1 -1
- package/lib/esm/transactionPlan/midnight/supplyCollateralBatch.js +1 -1
- package/lib/esm/transactionPlan/midnight/supplyCollateralMakeBorrow.d.ts +1 -1
- package/lib/esm/transactionPlan/midnight/supplyCollateralMakeBorrow.js +1 -1
- package/lib/esm/transactionPlan/midnight/supplyCollateralWithNative.d.ts +1 -1
- package/lib/esm/transactionPlan/midnight/supplyCollateralWithNative.js +1 -1
- package/lib/esm/transactionPlan/midnight/takeBorrow.d.ts +6 -2
- package/lib/esm/transactionPlan/midnight/takeBorrow.js +11 -5
- package/lib/esm/transactionPlan/midnight/takeRepayWithdrawCollateral.d.ts +1 -1
- package/lib/esm/transactionPlan/midnight/takeRepayWithdrawCollateral.js +1 -1
- package/lib/esm/transactionPlan/midnight/takeWithdraw.d.ts +1 -1
- package/lib/esm/transactionPlan/midnight/takeWithdraw.js +1 -1
- package/lib/esm/transactionPlan/permit.d.ts +15 -2
- package/lib/esm/transactionPlan/permit.js +25 -68
- package/lib/esm/transactionPlan/plan.d.ts +51 -1
- package/lib/esm/transactionPlan/plan.js +55 -13
- package/lib/esm/transactionPlan/redeem.js +5 -8
- package/lib/esm/transactionPlan/types.d.ts +4 -3
- package/lib/esm/transactionPlan/vaultBinding.d.ts +29 -0
- package/lib/esm/transactionPlan/vaultBinding.js +65 -0
- package/lib/esm/transactionPlan/vaultRequirements.d.ts +20 -0
- package/lib/esm/transactionPlan/vaultRequirements.js +34 -0
- package/lib/esm/transactionPlan/vaultv1/deposit.d.ts +1 -1
- package/lib/esm/transactionPlan/vaultv1/deposit.js +3 -14
- package/lib/esm/transactionPlan/vaultv1/inKindRedeem.d.ts +2 -2
- package/lib/esm/transactionPlan/vaultv1/inKindRedeem.js +12 -43
- package/lib/esm/transactionPlan/vaultv1/migrateToV2.d.ts +1 -1
- package/lib/esm/transactionPlan/vaultv1/migrateToV2.js +9 -21
- package/lib/esm/transactionPlan/vaultv1/redeem.js +2 -13
- package/lib/esm/transactionPlan/vaultv1/withdraw.d.ts +1 -1
- package/lib/esm/transactionPlan/vaultv1/withdraw.js +3 -14
- package/lib/esm/transactionPlan/vaultv2/deposit.d.ts +1 -1
- package/lib/esm/transactionPlan/vaultv2/deposit.js +3 -14
- package/lib/esm/transactionPlan/vaultv2/forceRedeem.d.ts +1 -1
- package/lib/esm/transactionPlan/vaultv2/forceRedeem.js +5 -8
- package/lib/esm/transactionPlan/vaultv2/forceWithdraw.d.ts +2 -2
- package/lib/esm/transactionPlan/vaultv2/forceWithdraw.js +15 -45
- package/lib/esm/transactionPlan/vaultv2/inKindRedeem.d.ts +2 -2
- package/lib/esm/transactionPlan/vaultv2/inKindRedeem.js +12 -43
- package/lib/esm/transactionPlan/vaultv2/redeem.d.ts +1 -1
- package/lib/esm/transactionPlan/vaultv2/redeem.js +3 -14
- package/lib/esm/transactionPlan/vaultv2/withdraw.d.ts +1 -1
- package/lib/esm/transactionPlan/vaultv2/withdraw.js +3 -14
- package/lib/esm/transactionPlan/withdraw.js +5 -8
- package/lib/esm/types/error.d.ts +27 -1
- package/lib/esm/types/error.js +30 -2
- package/lib/esm/version.d.ts +1 -1
- package/lib/esm/version.js +1 -1
- package/package.json +3 -3
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.validateWithdrawShares = exports.validateWithdrawAmount = exports.validateSlippageTolerance = exports.validateVaultV2BlueReallocations = exports.validateRepayShares = exports.validateRepayAmount = exports.validatePositionHealthAfterWithdraw = exports.validateNativeVaultAsset = exports.validateMidnightNativeAmount = exports.validateNativeAsset = exports.validateChainId = exports.validatePositionHealth = exports.validateMidnightRepayWithdrawCollateralPosition = exports.validateMidnightWithdrawHealth = exports.validateMidnightBorrowHealth = exports.getMidnightMaxSafeDebt = exports.validateAccrualPosition = exports.validateMidnightMarketChainId = exports.validateReferralFee = exports.validateDeadline = exports.validateMarketParamsId = exports.validateUint256Field = void 0;
|
|
3
|
+
exports.validateWithdrawShares = exports.validateWithdrawAmount = exports.validateSlippageTolerance = exports.validateVaultV2BlueReallocations = exports.validateRepayShares = exports.validateRepayAmount = exports.validatePositionHealthAfterWithdraw = exports.validateNativeVaultAsset = exports.validateMidnightNativeAmount = exports.validateNativeAsset = exports.validateChainId = exports.validatePositionHealth = exports.validateMidnightRepayWithdrawCollateralPosition = exports.validateMidnightWithdrawHealth = exports.validateMidnightBorrowMaturity = exports.validateMidnightBorrowHealth = exports.getMidnightMaxSafeDebt = exports.validateAccrualPosition = exports.validateMidnightMarketChainId = exports.validateReferralFee = exports.validateDeadline = exports.validateMarketParamsId = exports.validateUint256Field = void 0;
|
|
4
4
|
exports.validateReferenceTime = validateReferenceTime;
|
|
5
5
|
exports.validateVaultDepositDeadline = validateVaultDepositDeadline;
|
|
6
6
|
exports.validateUserAddress = validateUserAddress;
|
|
@@ -337,6 +337,30 @@ const validateMidnightBorrowHealth = (params) => {
|
|
|
337
337
|
}
|
|
338
338
|
};
|
|
339
339
|
exports.validateMidnightBorrowHealth = validateMidnightBorrowHealth;
|
|
340
|
+
/**
|
|
341
|
+
* @internal Rejects a Midnight borrow that could execute less than
|
|
342
|
+
* `MIDNIGHT_MIN_BORROW_TIME_TO_MATURITY` before the market's maturity, when unpaid debt becomes
|
|
343
|
+
* liquidatable. The sell is not reduce-only, so any units beyond the credit left at execution open
|
|
344
|
+
* debt; credit covering the target when the borrow is prepared does not exempt it. Once `now` is
|
|
345
|
+
* past maturity the protocol rejects new debt, so the check does not apply, matching the
|
|
346
|
+
* post-maturity credit cap in `validateMidnightTakeFeasibility`.
|
|
347
|
+
* Used by the entity and TransactionPlan borrow flows.
|
|
348
|
+
*/
|
|
349
|
+
const validateMidnightBorrowMaturity = (params) => {
|
|
350
|
+
const { maturity } = params.marketData.params;
|
|
351
|
+
if (params.now > maturity) {
|
|
352
|
+
return;
|
|
353
|
+
}
|
|
354
|
+
const latestDeadline = maturity - constant_js_1.MIDNIGHT_MIN_BORROW_TIME_TO_MATURITY;
|
|
355
|
+
if (params.deadline > latestDeadline) {
|
|
356
|
+
throw new index_js_1.MidnightBorrowTooCloseToMaturityError({
|
|
357
|
+
deadline: params.deadline,
|
|
358
|
+
maturity,
|
|
359
|
+
latestDeadline,
|
|
360
|
+
});
|
|
361
|
+
}
|
|
362
|
+
};
|
|
363
|
+
exports.validateMidnightBorrowMaturity = validateMidnightBorrowMaturity;
|
|
340
364
|
/**
|
|
341
365
|
* @internal Rejects a Midnight collateral withdrawal whose post-operation debt exceeds the remaining
|
|
342
366
|
* collateral's capacity at LLTV minus `DEFAULT_LLTV_BUFFER`, with the same check and error as the
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { Address } from "viem";
|
|
2
|
+
import type { Intent } from "./intent.js";
|
|
3
|
+
import type { TransactionPlan } from "./types.js";
|
|
4
|
+
/**
|
|
5
|
+
* @internal The stored plan header: version, chain, account, expiry, and the calldata origin when
|
|
6
|
+
* the intent has one.
|
|
7
|
+
*/
|
|
8
|
+
export declare function planHeader({ chainId, account }: {
|
|
9
|
+
readonly chainId: number;
|
|
10
|
+
readonly account: Address;
|
|
11
|
+
}, { expiresAt, calldataOrigin }: Pick<Intent, "expiresAt" | "calldataOrigin">): {
|
|
12
|
+
readonly version: 2;
|
|
13
|
+
readonly chainId: number;
|
|
14
|
+
readonly account: `0x${string}`;
|
|
15
|
+
readonly expiresAt: number;
|
|
16
|
+
readonly calldataOrigin?: `0x${string}` | undefined;
|
|
17
|
+
};
|
|
18
|
+
/**
|
|
19
|
+
* @internal Deeply freezes a prepared plan. `detach` copies it first, so no object the caller
|
|
20
|
+
* passed in is frozen or shared with the plan.
|
|
21
|
+
*/
|
|
22
|
+
export declare function freezePlan(plan: TransactionPlan, { detach }: {
|
|
23
|
+
readonly detach: boolean;
|
|
24
|
+
}): TransactionPlan;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.planHeader = planHeader;
|
|
4
|
+
exports.freezePlan = freezePlan;
|
|
5
|
+
const morpho_ts_1 = require("@morpho-org/morpho-ts");
|
|
6
|
+
/**
|
|
7
|
+
* @internal The stored plan header: version, chain, account, expiry, and the calldata origin when
|
|
8
|
+
* the intent has one.
|
|
9
|
+
*/
|
|
10
|
+
function planHeader({ chainId, account }, { expiresAt, calldataOrigin }) {
|
|
11
|
+
return {
|
|
12
|
+
version: 2,
|
|
13
|
+
chainId,
|
|
14
|
+
account,
|
|
15
|
+
expiresAt,
|
|
16
|
+
...(calldataOrigin && { calldataOrigin }),
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* @internal Deeply freezes a prepared plan. `detach` copies it first, so no object the caller
|
|
21
|
+
* passed in is frozen or shared with the plan.
|
|
22
|
+
*/
|
|
23
|
+
function freezePlan(plan, { detach }) {
|
|
24
|
+
return (0, morpho_ts_1.deepFreeze)(detach ? structuredClone(plan) : plan);
|
|
25
|
+
}
|
|
@@ -9,9 +9,11 @@ const common_js_1 = require("../../actions/bundles/common.js");
|
|
|
9
9
|
const getBlueBundlesV1QuoteTimestamp_js_1 = require("../../helpers/getBlueBundlesV1QuoteTimestamp.js");
|
|
10
10
|
const index_js_1 = require("../../helpers/index.js");
|
|
11
11
|
const validate_js_1 = require("../../helpers/validate.js");
|
|
12
|
+
const assemble_js_1 = require("../assemble.js");
|
|
12
13
|
const error_js_1 = require("../error.js");
|
|
13
14
|
const validation_js_1 = require("../validation.js");
|
|
14
15
|
const prepare_js_1 = require("./prepare.js");
|
|
16
|
+
const stored_js_1 = require("./stored.js");
|
|
15
17
|
/**
|
|
16
18
|
* Prepares a BlueBundlesV1 borrow against existing collateral. No token allowance is needed.
|
|
17
19
|
* Health uses the expiry, floored at max(now, lastUpdate), like the entity handle.
|
|
@@ -123,12 +125,8 @@ async function prepareBlueBorrow(client, { chainId, account, marketId, marketDat
|
|
|
123
125
|
reason: "expected prepared borrow inputs",
|
|
124
126
|
});
|
|
125
127
|
}
|
|
126
|
-
return (0,
|
|
127
|
-
|
|
128
|
-
account: inputs.account,
|
|
129
|
-
chainId: inputs.chainId,
|
|
130
|
-
expiresAt: intent.expiresAt,
|
|
131
|
-
...(intent.calldataOrigin && { calldataOrigin: intent.calldataOrigin }),
|
|
128
|
+
return (0, assemble_js_1.freezePlan)({
|
|
129
|
+
...(0, assemble_js_1.planHeader)({ chainId: inputs.chainId, account: inputs.account }, intent),
|
|
132
130
|
steps: [
|
|
133
131
|
...steps,
|
|
134
132
|
{
|
|
@@ -140,14 +138,14 @@ async function prepareBlueBorrow(client, { chainId, account, marketId, marketDat
|
|
|
140
138
|
...inputs,
|
|
141
139
|
authorizationNonce: signatureRequests.find((request) => request.id === morphoAuthorizationRequestId)?.args.nonce ?? 0n,
|
|
142
140
|
},
|
|
143
|
-
signatureRequestIds:
|
|
144
|
-
|
|
145
|
-
|
|
141
|
+
signatureRequestIds: (0, stored_js_1.signatureRoles)({
|
|
142
|
+
morphoAuthorization: morphoAuthorizationRequestId,
|
|
143
|
+
}),
|
|
146
144
|
},
|
|
147
145
|
},
|
|
148
146
|
],
|
|
149
147
|
signatureRequests,
|
|
150
|
-
})
|
|
148
|
+
}, { detach: true });
|
|
151
149
|
}
|
|
152
150
|
/** @internal Encodes a prepared borrow without state reads or signing. */
|
|
153
151
|
function buildBlueBorrow(action, requests) {
|
|
@@ -190,26 +188,6 @@ function buildBlueBorrow(action, requests) {
|
|
|
190
188
|
},
|
|
191
189
|
});
|
|
192
190
|
}
|
|
193
|
-
function validateMarket(value, path) {
|
|
194
|
-
const market = (0, validation_js_1.getPlanObject)(value, path);
|
|
195
|
-
(0, validation_js_1.validatePlanFields)(market, {
|
|
196
|
-
path,
|
|
197
|
-
fields: {
|
|
198
|
-
id: "hex",
|
|
199
|
-
loanToken: "address",
|
|
200
|
-
collateralToken: "address",
|
|
201
|
-
oracle: "address",
|
|
202
|
-
irm: "address",
|
|
203
|
-
lltv: "uint256 bigint",
|
|
204
|
-
},
|
|
205
|
-
});
|
|
206
|
-
if (typeof market.id !== "string" || market.id.length !== 66) {
|
|
207
|
-
throw new error_js_1.InvalidTransactionPlanError({
|
|
208
|
-
path: `${path}.id`,
|
|
209
|
-
reason: "expected a 32-byte market ID",
|
|
210
|
-
});
|
|
211
|
-
}
|
|
212
|
-
}
|
|
213
191
|
/** @internal Validates the stored borrow recipe, including each allocator input. */
|
|
214
192
|
function validateBorrowPlanAction(action, path) {
|
|
215
193
|
const inputs = (0, validation_js_1.getPlanObject)(action.inputs, `${path}.inputs`);
|
|
@@ -220,47 +198,19 @@ function validateBorrowPlanAction(action, path) {
|
|
|
220
198
|
borrowAssets: "uint256 bigint",
|
|
221
199
|
authorizationNonce: "uint256 bigint",
|
|
222
200
|
maxLtv: "uint256 bigint",
|
|
223
|
-
|
|
224
|
-
referralFeePct: "uint256 bigint",
|
|
225
|
-
referralFeeRecipient: "address",
|
|
201
|
+
...stored_js_1.BUNDLES_COMMON_FIELDS,
|
|
226
202
|
reallocations: "array",
|
|
227
203
|
},
|
|
228
204
|
});
|
|
229
|
-
|
|
205
|
+
(0, stored_js_1.validateStoredBlueMarket)(inputs.marketParams, `${path}.inputs.marketParams`);
|
|
230
206
|
if (inputs.maxPenalty !== undefined) {
|
|
231
207
|
(0, validation_js_1.validatePlanField)(inputs.maxPenalty, {
|
|
232
208
|
path: `${path}.inputs.maxPenalty`,
|
|
233
209
|
type: "uint256 bigint",
|
|
234
210
|
});
|
|
235
211
|
}
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
path: entryPath,
|
|
241
|
-
fields: {
|
|
242
|
-
vault: "address",
|
|
243
|
-
assets: "uint256 bigint",
|
|
244
|
-
penalty: "uint256 bigint",
|
|
245
|
-
},
|
|
246
|
-
});
|
|
247
|
-
(0, validation_js_1.validatePlanFields)((0, validation_js_1.getPlanObject)(entry.to, `${entryPath}.to`), {
|
|
248
|
-
path: `${entryPath}.to`,
|
|
249
|
-
fields: { adapter: "address" },
|
|
250
|
-
});
|
|
251
|
-
const from = (0, validation_js_1.getPlanObject)(entry.from, `${entryPath}.from`);
|
|
252
|
-
if (from.type !== "market" && from.type !== "idle") {
|
|
253
|
-
throw new error_js_1.InvalidTransactionPlanError({
|
|
254
|
-
path: `${entryPath}.from.type`,
|
|
255
|
-
reason: "expected market or idle",
|
|
256
|
-
});
|
|
257
|
-
}
|
|
258
|
-
if (from.type === "market") {
|
|
259
|
-
(0, validation_js_1.validatePlanFields)(from, {
|
|
260
|
-
path: `${entryPath}.from`,
|
|
261
|
-
fields: { adapter: "address" },
|
|
262
|
-
});
|
|
263
|
-
validateMarket(from.marketParams, `${entryPath}.from.marketParams`);
|
|
264
|
-
}
|
|
265
|
-
}
|
|
212
|
+
(0, stored_js_1.validateStoredReallocations)(inputs.reallocations, {
|
|
213
|
+
path: `${path}.inputs.reallocations`,
|
|
214
|
+
marketParams: stored_js_1.validateStoredBlueMarket,
|
|
215
|
+
});
|
|
266
216
|
}
|
|
@@ -10,10 +10,12 @@ const refinance_js_1 = require("../../actions/blue/refinance.js");
|
|
|
10
10
|
const refinanceValidation_js_1 = require("../../actions/blue/refinanceValidation.js");
|
|
11
11
|
const index_js_1 = require("../../helpers/index.js");
|
|
12
12
|
const parse_js_1 = require("../../helpers/parse.js");
|
|
13
|
+
const assemble_js_1 = require("../assemble.js");
|
|
13
14
|
const error_js_1 = require("../error.js");
|
|
14
15
|
const validation_js_1 = require("../validation.js");
|
|
15
16
|
const prepare_js_1 = require("./prepare.js");
|
|
16
17
|
const refinanceValidation_js_2 = require("./refinanceValidation.js");
|
|
18
|
+
const stored_js_1 = require("./stored.js");
|
|
17
19
|
/**
|
|
18
20
|
* Prepares a full Blue borrow-position migration. Fetch both market and position snapshots at the
|
|
19
21
|
* same block and pass that block's timestamp as `now`. Penalties and fees increase destination debt;
|
|
@@ -157,20 +159,18 @@ async function prepareBlueRefinance(client, params) {
|
|
|
157
159
|
...(maxPenalty !== undefined && { maxPenalty }),
|
|
158
160
|
...(request && { authorizationNonce: request.args.nonce }),
|
|
159
161
|
},
|
|
160
|
-
signatureRequestIds:
|
|
162
|
+
signatureRequestIds: (0, stored_js_1.signatureRoles)({
|
|
163
|
+
morphoAuthorization: request?.id,
|
|
164
|
+
}),
|
|
161
165
|
};
|
|
162
|
-
return (0,
|
|
163
|
-
|
|
164
|
-
account,
|
|
165
|
-
chainId,
|
|
166
|
-
expiresAt: intent.expiresAt,
|
|
167
|
-
...(intent.calldataOrigin && { calldataOrigin: intent.calldataOrigin }),
|
|
166
|
+
return (0, assemble_js_1.freezePlan)({
|
|
167
|
+
...(0, assemble_js_1.planHeader)({ chainId, account }, intent),
|
|
168
168
|
steps: [
|
|
169
169
|
...steps,
|
|
170
170
|
{ id, label: "Refinance Blue borrow position", action },
|
|
171
171
|
],
|
|
172
172
|
signatureRequests,
|
|
173
|
-
})
|
|
173
|
+
}, { detach: true });
|
|
174
174
|
}
|
|
175
175
|
function validatePlanMarketParams(value, path) {
|
|
176
176
|
const params = (0, validation_js_1.getPlanObject)(value, path);
|
|
@@ -246,9 +246,7 @@ function validateRefinancePlanAction(action, path) {
|
|
|
246
246
|
path: `${path}.inputs`,
|
|
247
247
|
fields: {
|
|
248
248
|
maxLtv: "uint256 bigint",
|
|
249
|
-
|
|
250
|
-
referralFeePct: "uint256 bigint",
|
|
251
|
-
referralFeeRecipient: "address",
|
|
249
|
+
...stored_js_1.BUNDLES_COMMON_FIELDS,
|
|
252
250
|
reallocations: "array",
|
|
253
251
|
},
|
|
254
252
|
});
|
|
@@ -14,10 +14,12 @@ const parse_js_1 = require("../../helpers/parse.js");
|
|
|
14
14
|
const quoteBlueRepay_js_1 = require("../../helpers/quoteBlueRepay.js");
|
|
15
15
|
const validate_js_1 = require("../../helpers/validate.js");
|
|
16
16
|
const index_js_1 = require("../../types/index.js");
|
|
17
|
+
const assemble_js_1 = require("../assemble.js");
|
|
17
18
|
const error_js_1 = require("../error.js");
|
|
18
19
|
const permit_js_1 = require("../permit.js");
|
|
19
20
|
const validation_js_1 = require("../validation.js");
|
|
20
21
|
const prepare_js_1 = require("./prepare.js");
|
|
22
|
+
const stored_js_1 = require("./stored.js");
|
|
21
23
|
/**
|
|
22
24
|
* Prepares an asset, share, or full Blue repayment through BlueBundlesV1, never Permit2.
|
|
23
25
|
* Share quotes accrue the supplied position to expiry, at most two hours from the reference time.
|
|
@@ -139,12 +141,8 @@ async function prepareBlueRepay(client, { chainId, account, marketId, marketData
|
|
|
139
141
|
reason: "expected resolved repayment inputs",
|
|
140
142
|
});
|
|
141
143
|
}
|
|
142
|
-
return (0,
|
|
143
|
-
|
|
144
|
-
chainId: params.chainId,
|
|
145
|
-
account: params.account,
|
|
146
|
-
expiresAt: resolvedIntent.expiresAt,
|
|
147
|
-
calldataOrigin: resolvedIntent.calldataOrigin,
|
|
144
|
+
return (0, assemble_js_1.freezePlan)({
|
|
145
|
+
...(0, assemble_js_1.planHeader)({ chainId: params.chainId, account: params.account }, resolvedIntent),
|
|
148
146
|
steps: [
|
|
149
147
|
...steps,
|
|
150
148
|
{
|
|
@@ -153,14 +151,14 @@ async function prepareBlueRepay(client, { chainId, account, marketId, marketData
|
|
|
153
151
|
action: {
|
|
154
152
|
type: "blueRepay",
|
|
155
153
|
inputs,
|
|
156
|
-
signatureRequestIds:
|
|
157
|
-
|
|
158
|
-
|
|
154
|
+
signatureRequestIds: (0, stored_js_1.signatureRoles)({
|
|
155
|
+
tokenPermit: signatureRequests[0]?.id,
|
|
156
|
+
}),
|
|
159
157
|
},
|
|
160
158
|
},
|
|
161
159
|
],
|
|
162
160
|
signatureRequests,
|
|
163
|
-
})
|
|
161
|
+
}, { detach: true });
|
|
164
162
|
}
|
|
165
163
|
/** @internal Checks a repayment permit against the fixed token pull. */
|
|
166
164
|
function validateBlueRepayPermit(request, action) {
|
|
@@ -203,9 +201,7 @@ function validateBlueRepayPlanAction(action, path) {
|
|
|
203
201
|
repayAssets: "uint256 bigint",
|
|
204
202
|
repayShares: "uint256 bigint",
|
|
205
203
|
maxRepayAssets: "uint256 bigint",
|
|
206
|
-
|
|
207
|
-
referralFeePct: "uint256 bigint",
|
|
208
|
-
referralFeeRecipient: "address",
|
|
204
|
+
...stored_js_1.BUNDLES_COMMON_FIELDS,
|
|
209
205
|
},
|
|
210
206
|
});
|
|
211
207
|
if (inputs.nativeAssets !== undefined) {
|
|
@@ -214,16 +210,6 @@ function validateBlueRepayPlanAction(action, path) {
|
|
|
214
210
|
fields: { nativeAssets: "uint256 bigint" },
|
|
215
211
|
});
|
|
216
212
|
}
|
|
217
|
-
|
|
218
|
-
(0, validation_js_1.validatePlanFields)(market, {
|
|
219
|
-
path: `${path}.inputs.marketParams`,
|
|
220
|
-
fields: {
|
|
221
|
-
loanToken: "address",
|
|
222
|
-
collateralToken: "address",
|
|
223
|
-
oracle: "address",
|
|
224
|
-
irm: "address",
|
|
225
|
-
lltv: "uint256 bigint",
|
|
226
|
-
},
|
|
227
|
-
});
|
|
213
|
+
(0, stored_js_1.validateStoredBlueMarketParams)(inputs.marketParams, `${path}.inputs.marketParams`);
|
|
228
214
|
(0, validation_js_1.getPlanObject)(action.signatureRequestIds, `${path}.signatureRequestIds`);
|
|
229
215
|
}
|
|
@@ -15,11 +15,13 @@ const index_js_1 = require("../../helpers/index.js");
|
|
|
15
15
|
const parse_js_1 = require("../../helpers/parse.js");
|
|
16
16
|
const quoteBlueRepay_js_1 = require("../../helpers/quoteBlueRepay.js");
|
|
17
17
|
const index_js_2 = require("../../types/index.js");
|
|
18
|
+
const assemble_js_1 = require("../assemble.js");
|
|
18
19
|
const error_js_1 = require("../error.js");
|
|
19
20
|
const permit_js_1 = require("../permit.js");
|
|
20
21
|
const validation_js_1 = require("../validation.js");
|
|
21
22
|
const authorization_js_1 = require("./authorization.js");
|
|
22
23
|
const prepare_js_1 = require("./prepare.js");
|
|
24
|
+
const stored_js_1 = require("./stored.js");
|
|
23
25
|
/**
|
|
24
26
|
* Prepares one BlueBundlesV1 repayment and collateral withdrawal from caller-fetched snapshots.
|
|
25
27
|
* Withdrawal health uses the expiry floored at max(now, lastUpdate); expiries more than
|
|
@@ -79,23 +81,24 @@ const prepare_js_1 = require("./prepare.js");
|
|
|
79
81
|
*/
|
|
80
82
|
async function prepareBlueRepayWithdrawCollateral(client, params) {
|
|
81
83
|
const id = "blueRepayWithdrawCollateral";
|
|
82
|
-
const
|
|
84
|
+
const captured = captureRepayWithdrawInputs(params);
|
|
85
|
+
const { chainId, account, marketId, marketData, now } = captured;
|
|
83
86
|
let inputs;
|
|
84
|
-
const prepared = await (0, prepare_js_1.prepareBlue)({ client, params:
|
|
85
|
-
const marketParams =
|
|
87
|
+
const prepared = await (0, prepare_js_1.prepareBlue)({ client, params: captured }, (intent) => {
|
|
88
|
+
const marketParams = marketData.market.params;
|
|
86
89
|
// Reject chain and referral mismatches before deriving a repayment quote.
|
|
87
|
-
(0, index_js_1.validateChainId)(client.chain?.id,
|
|
90
|
+
(0, index_js_1.validateChainId)(client.chain?.id, chainId);
|
|
88
91
|
const common = (0, common_js_1.parseBlueBundlesV1Common)({
|
|
89
|
-
chainId
|
|
90
|
-
userAddress:
|
|
92
|
+
chainId,
|
|
93
|
+
userAddress: account,
|
|
91
94
|
deadline: intent.deadline,
|
|
92
95
|
referralFeePct: intent.referralFeePct,
|
|
93
96
|
referralFeeRecipient: intent.referralFeeRecipient,
|
|
94
97
|
});
|
|
95
|
-
const { repayAssets, repayShares, collateralAssets, hasRepay } = getRepayWithdrawAmounts(params);
|
|
98
|
+
const { repayAssets, repayShares, collateralAssets, hasRepay } = getRepayWithdrawAmounts(params, marketId);
|
|
96
99
|
const quoteParams = {
|
|
97
|
-
positionData: getMatchingPosition(
|
|
98
|
-
marketId
|
|
100
|
+
positionData: getMatchingPosition(captured),
|
|
101
|
+
marketId,
|
|
99
102
|
repayAssets,
|
|
100
103
|
repayShares,
|
|
101
104
|
deadline: intent.deadline,
|
|
@@ -106,7 +109,7 @@ async function prepareBlueRepayWithdrawCollateral(client, params) {
|
|
|
106
109
|
const maxRepayAssets = expectedRepayAssets +
|
|
107
110
|
(0, common_js_1.getBlueBundlesV1ReferralFeeAssets)(expectedRepayAssets, common.referralFeePct);
|
|
108
111
|
const nativeValue = (0, parse_js_1.parseNativeFunding)({
|
|
109
|
-
chainId
|
|
112
|
+
chainId,
|
|
110
113
|
token: marketParams.loanToken,
|
|
111
114
|
fundedAmount: maxRepayAssets,
|
|
112
115
|
nativeAmount: params.funding?.type === "native" ? maxRepayAssets : undefined,
|
|
@@ -121,13 +124,13 @@ async function prepareBlueRepayWithdrawCollateral(client, params) {
|
|
|
121
124
|
positionData: postRepayPosition,
|
|
122
125
|
withdrawAmount: collateralAssets,
|
|
123
126
|
lltv: marketParams.lltv,
|
|
124
|
-
marketId
|
|
127
|
+
marketId,
|
|
125
128
|
});
|
|
126
129
|
}
|
|
127
130
|
const tx = (0, repayWithdrawCollateral_js_1.blueRepayWithdrawCollateral)({
|
|
128
|
-
market: { chainId
|
|
131
|
+
market: { chainId, marketParams },
|
|
129
132
|
args: {
|
|
130
|
-
userAddress:
|
|
133
|
+
userAddress: account,
|
|
131
134
|
repayAssets,
|
|
132
135
|
repayShares,
|
|
133
136
|
maxRepayAssets,
|
|
@@ -143,8 +146,8 @@ async function prepareBlueRepayWithdrawCollateral(client, params) {
|
|
|
143
146
|
inputs = {
|
|
144
147
|
...args,
|
|
145
148
|
...(nativeAmount !== undefined && { nativeAssets: nativeAmount }),
|
|
146
|
-
chainId
|
|
147
|
-
account
|
|
149
|
+
chainId,
|
|
150
|
+
account,
|
|
148
151
|
marketParams: {
|
|
149
152
|
loanToken: marketParams.loanToken,
|
|
150
153
|
collateralToken: marketParams.collateralToken,
|
|
@@ -161,27 +164,20 @@ async function prepareBlueRepayWithdrawCollateral(client, params) {
|
|
|
161
164
|
needsAuthorization: args.collateralAssets > 0n,
|
|
162
165
|
};
|
|
163
166
|
});
|
|
164
|
-
await (0, validateClientChainId_js_1.validateClientChainId)(client,
|
|
167
|
+
await (0, validateClientChainId_js_1.validateClientChainId)(client, chainId);
|
|
165
168
|
if (inputs === undefined) {
|
|
166
169
|
throw new error_js_1.IncompleteTransactionPlanError(id);
|
|
167
170
|
}
|
|
168
|
-
const signatureRequestIds =
|
|
169
|
-
.
|
|
170
|
-
.
|
|
171
|
-
|
|
172
|
-
signatureRequestIds.morphoAuthorization =
|
|
173
|
-
prepared.morphoAuthorizationRequestId;
|
|
174
|
-
}
|
|
171
|
+
const signatureRequestIds = (0, stored_js_1.signatureRoles)({
|
|
172
|
+
tokenPermit: prepared.signatureRequests.find((request) => request.kind === "permit")?.id,
|
|
173
|
+
morphoAuthorization: prepared.morphoAuthorizationRequestId,
|
|
174
|
+
});
|
|
175
175
|
const authorization = prepared.signatureRequests.find((request) => request.kind === "morphoAuthorization");
|
|
176
176
|
if (authorization !== undefined) {
|
|
177
177
|
inputs = { ...inputs, authorizationNonce: authorization.args.nonce };
|
|
178
178
|
}
|
|
179
|
-
return (0,
|
|
180
|
-
|
|
181
|
-
chainId: params.chainId,
|
|
182
|
-
account: params.account,
|
|
183
|
-
expiresAt: prepared.intent.expiresAt,
|
|
184
|
-
calldataOrigin: prepared.intent.calldataOrigin,
|
|
179
|
+
return (0, assemble_js_1.freezePlan)({
|
|
180
|
+
...(0, assemble_js_1.planHeader)({ chainId, account }, prepared.intent),
|
|
185
181
|
steps: [
|
|
186
182
|
...prepared.steps,
|
|
187
183
|
{
|
|
@@ -191,7 +187,7 @@ async function prepareBlueRepayWithdrawCollateral(client, params) {
|
|
|
191
187
|
},
|
|
192
188
|
],
|
|
193
189
|
signatureRequests: prepared.signatureRequests,
|
|
194
|
-
})
|
|
190
|
+
}, { detach: true });
|
|
195
191
|
}
|
|
196
192
|
function getRepayWithdrawLabel(inputs) {
|
|
197
193
|
if (inputs.collateralAssets === 0n) {
|
|
@@ -212,6 +208,25 @@ const MARKET_STATE_FIELDS = [
|
|
|
212
208
|
"price",
|
|
213
209
|
"rateAtTarget",
|
|
214
210
|
];
|
|
211
|
+
function captureRepayWithdrawInputs(params) {
|
|
212
|
+
const { chainId, account, marketId, marketData, positionData } = params;
|
|
213
|
+
return {
|
|
214
|
+
chainId,
|
|
215
|
+
account,
|
|
216
|
+
marketId,
|
|
217
|
+
marketData: { chainId: marketData.chainId, market: marketData.market },
|
|
218
|
+
positionData: {
|
|
219
|
+
chainId: positionData.chainId,
|
|
220
|
+
position: positionData.position,
|
|
221
|
+
},
|
|
222
|
+
now: params.now ?? morpho_ts_1.Time.timestamp(),
|
|
223
|
+
expiresAt: params.expiresAt,
|
|
224
|
+
supportSignature: params.supportSignature,
|
|
225
|
+
referralFee: params.referralFee,
|
|
226
|
+
calldataOrigin: params.calldataOrigin,
|
|
227
|
+
deployless: params.deployless,
|
|
228
|
+
};
|
|
229
|
+
}
|
|
215
230
|
function getMatchingPosition(params) {
|
|
216
231
|
const { position } = params.positionData;
|
|
217
232
|
const positionMarket = position.market;
|
|
@@ -253,8 +268,8 @@ function quoteWithdrawal(quoteParams, collateralAssets) {
|
|
|
253
268
|
}),
|
|
254
269
|
});
|
|
255
270
|
}
|
|
256
|
-
function getRepayWithdrawAmounts(params) {
|
|
257
|
-
const { collateralAssets
|
|
271
|
+
function getRepayWithdrawAmounts(params, marketId) {
|
|
272
|
+
const { collateralAssets } = params;
|
|
258
273
|
const repayAssets = params.repayAssets ?? 0n;
|
|
259
274
|
const repayShares = params.repayShares ?? 0n;
|
|
260
275
|
if (repayAssets < 0n) {
|
|
@@ -368,9 +383,7 @@ function validateRepayWithdrawCollateralPlanAction(action, path) {
|
|
|
368
383
|
maxRepayAssets: "uint256 bigint",
|
|
369
384
|
collateralAssets: "uint256 bigint",
|
|
370
385
|
maxLtv: "uint256 bigint",
|
|
371
|
-
|
|
372
|
-
referralFeePct: "uint256 bigint",
|
|
373
|
-
referralFeeRecipient: "address",
|
|
386
|
+
...stored_js_1.BUNDLES_COMMON_FIELDS,
|
|
374
387
|
},
|
|
375
388
|
});
|
|
376
389
|
if (inputs.repayAssets > 0n &&
|
|
@@ -386,16 +399,7 @@ function validateRepayWithdrawCollateralPlanAction(action, path) {
|
|
|
386
399
|
fields: { nativeAssets: "uint256 bigint" },
|
|
387
400
|
});
|
|
388
401
|
}
|
|
389
|
-
(0,
|
|
390
|
-
path: `${path}.inputs.marketParams`,
|
|
391
|
-
fields: {
|
|
392
|
-
loanToken: "address",
|
|
393
|
-
collateralToken: "address",
|
|
394
|
-
oracle: "address",
|
|
395
|
-
irm: "address",
|
|
396
|
-
lltv: "uint256 bigint",
|
|
397
|
-
},
|
|
398
|
-
});
|
|
402
|
+
(0, stored_js_1.validateStoredBlueMarketParams)(inputs.marketParams, `${path}.inputs.marketParams`);
|
|
399
403
|
const ids = (0, validation_js_1.getPlanObject)(action.signatureRequestIds, `${path}.signatureRequestIds`);
|
|
400
404
|
if (inputs.authorizationNonce !== undefined ||
|
|
401
405
|
ids.morphoAuthorization !== undefined) {
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/** @internal The stored BlueBundlesV1 deadline and referral fields, in their validation order. */
|
|
2
|
+
export declare const BUNDLES_COMMON_FIELDS: {
|
|
3
|
+
readonly deadline: "uint256 bigint";
|
|
4
|
+
readonly referralFeePct: "uint256 bigint";
|
|
5
|
+
readonly referralFeeRecipient: "address";
|
|
6
|
+
};
|
|
7
|
+
/** @internal Validates a stored five-field Blue market tuple at `path`. */
|
|
8
|
+
export declare function validateStoredBlueMarketParams(value: unknown, path: string): void;
|
|
9
|
+
/** @internal Validates a stored Blue market tuple that also carries its 32-byte market ID. */
|
|
10
|
+
export declare function validateStoredBlueMarket(value: unknown, path: string): void;
|
|
11
|
+
/**
|
|
12
|
+
* @internal Validates stored Vault V2 reallocations at `path`, checking each source market tuple
|
|
13
|
+
* with `marketParams`.
|
|
14
|
+
*/
|
|
15
|
+
export declare function validateStoredReallocations(reallocations: readonly unknown[], { path, marketParams, }: {
|
|
16
|
+
readonly path: string;
|
|
17
|
+
readonly marketParams: (value: unknown, path: string) => void;
|
|
18
|
+
}): void;
|
|
19
|
+
/** @internal Builds an action's role map with only the roles that reference a request, in argument order. */
|
|
20
|
+
export declare function signatureRoles({ tokenPermit, morphoAuthorization, }: {
|
|
21
|
+
readonly tokenPermit?: string;
|
|
22
|
+
readonly morphoAuthorization?: string;
|
|
23
|
+
}): {
|
|
24
|
+
tokenPermit?: string | undefined;
|
|
25
|
+
morphoAuthorization?: string | undefined;
|
|
26
|
+
};
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.BUNDLES_COMMON_FIELDS = void 0;
|
|
4
|
+
exports.validateStoredBlueMarketParams = validateStoredBlueMarketParams;
|
|
5
|
+
exports.validateStoredBlueMarket = validateStoredBlueMarket;
|
|
6
|
+
exports.validateStoredReallocations = validateStoredReallocations;
|
|
7
|
+
exports.signatureRoles = signatureRoles;
|
|
8
|
+
const error_js_1 = require("../error.js");
|
|
9
|
+
const validation_js_1 = require("../validation.js");
|
|
10
|
+
/** @internal The stored BlueBundlesV1 deadline and referral fields, in their validation order. */
|
|
11
|
+
exports.BUNDLES_COMMON_FIELDS = {
|
|
12
|
+
deadline: "uint256 bigint",
|
|
13
|
+
referralFeePct: "uint256 bigint",
|
|
14
|
+
referralFeeRecipient: "address",
|
|
15
|
+
};
|
|
16
|
+
const MARKET_PARAMS_FIELDS = {
|
|
17
|
+
loanToken: "address",
|
|
18
|
+
collateralToken: "address",
|
|
19
|
+
oracle: "address",
|
|
20
|
+
irm: "address",
|
|
21
|
+
lltv: "uint256 bigint",
|
|
22
|
+
};
|
|
23
|
+
/** @internal Validates a stored five-field Blue market tuple at `path`. */
|
|
24
|
+
function validateStoredBlueMarketParams(value, path) {
|
|
25
|
+
(0, validation_js_1.validatePlanFields)((0, validation_js_1.getPlanObject)(value, path), {
|
|
26
|
+
path,
|
|
27
|
+
fields: MARKET_PARAMS_FIELDS,
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
/** @internal Validates a stored Blue market tuple that also carries its 32-byte market ID. */
|
|
31
|
+
function validateStoredBlueMarket(value, path) {
|
|
32
|
+
const market = (0, validation_js_1.getPlanObject)(value, path);
|
|
33
|
+
(0, validation_js_1.validatePlanFields)(market, {
|
|
34
|
+
path,
|
|
35
|
+
fields: { id: "hex", ...MARKET_PARAMS_FIELDS },
|
|
36
|
+
});
|
|
37
|
+
if (typeof market.id !== "string" || market.id.length !== 66) {
|
|
38
|
+
throw new error_js_1.InvalidTransactionPlanError({
|
|
39
|
+
path: `${path}.id`,
|
|
40
|
+
reason: "expected a 32-byte market ID",
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* @internal Validates stored Vault V2 reallocations at `path`, checking each source market tuple
|
|
46
|
+
* with `marketParams`.
|
|
47
|
+
*/
|
|
48
|
+
function validateStoredReallocations(reallocations, { path, marketParams, }) {
|
|
49
|
+
for (const [index, value] of reallocations.entries()) {
|
|
50
|
+
const entryPath = `${path}[${index}]`;
|
|
51
|
+
const entry = (0, validation_js_1.getPlanObject)(value, entryPath);
|
|
52
|
+
(0, validation_js_1.validatePlanFields)(entry, {
|
|
53
|
+
path: entryPath,
|
|
54
|
+
fields: {
|
|
55
|
+
vault: "address",
|
|
56
|
+
assets: "uint256 bigint",
|
|
57
|
+
penalty: "uint256 bigint",
|
|
58
|
+
},
|
|
59
|
+
});
|
|
60
|
+
(0, validation_js_1.validatePlanFields)((0, validation_js_1.getPlanObject)(entry.to, `${entryPath}.to`), {
|
|
61
|
+
path: `${entryPath}.to`,
|
|
62
|
+
fields: { adapter: "address" },
|
|
63
|
+
});
|
|
64
|
+
const from = (0, validation_js_1.getPlanObject)(entry.from, `${entryPath}.from`);
|
|
65
|
+
if (from.type === "idle") {
|
|
66
|
+
continue;
|
|
67
|
+
}
|
|
68
|
+
if (from.type !== "market") {
|
|
69
|
+
throw new error_js_1.InvalidTransactionPlanError({
|
|
70
|
+
path: `${entryPath}.from.type`,
|
|
71
|
+
reason: "expected market or idle",
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
(0, validation_js_1.validatePlanFields)(from, {
|
|
75
|
+
path: `${entryPath}.from`,
|
|
76
|
+
fields: { adapter: "address" },
|
|
77
|
+
});
|
|
78
|
+
marketParams(from.marketParams, `${entryPath}.from.marketParams`);
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
/** @internal Builds an action's role map with only the roles that reference a request, in argument order. */
|
|
82
|
+
function signatureRoles({ tokenPermit, morphoAuthorization, }) {
|
|
83
|
+
return {
|
|
84
|
+
...(tokenPermit !== undefined && { tokenPermit }),
|
|
85
|
+
...(morphoAuthorization !== undefined && { morphoAuthorization }),
|
|
86
|
+
};
|
|
87
|
+
}
|