@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
package/lib/cjs/fetch.js
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.fetchMidnightRatifierInfo = exports.fetchMidnightPosition = exports.fetchMidnightMarketParams = exports.fetchMidnightMarket = exports.fetchMidnightAccrualPosition = exports.fetchVaultV2MorphoVaultV1Adapter = exports.fetchVaultV2MorphoMarketV1AdapterV2 = exports.fetchVaultV2MorphoMarketV1Adapter = exports.fetchVaultV2BluePublicAllocatorData = exports.fetchVaultV2BluePublicAllocatorConfig = exports.fetchVaultV2BlueMarketPublicAllocatorConfig = exports.fetchVaultV2Adapter = exports.fetchVaultV2 = exports.fetchVaultUser = exports.fetchVaultMarketConfig = exports.fetchVaultMarketAllocation = exports.fetchVaultConfig = exports.fetchVault = exports.fetchBlueUser = exports.fetchToken = exports.fetchBluePreLiquidationPosition = exports.fetchBluePreLiquidationParams = exports.fetchBluePosition = exports.fetchBlueMarketParams = exports.fetchBlueMarket = exports.fetchHolding = exports.fetchAccrualVaultV2MorphoVaultV1Adapter = exports.fetchAccrualVaultV2MorphoMarketV1AdapterV2 = exports.fetchAccrualVaultV2MorphoMarketV1Adapter = exports.fetchAccrualVaultV2Adapter = exports.fetchAccrualVaultV2 = exports.fetchAccrualVault = exports.fetchBlueAccrualPosition = void 0;
|
|
3
|
+
exports.fetchMidnightRatifierInfo = exports.fetchMidnightPosition = exports.fetchMidnightMarketParams = exports.fetchMidnightMarket = exports.fetchMidnightAccrualPosition = exports.fetchVaultV2MorphoVaultV1Adapter = exports.fetchVaultV2MorphoMarketV1AdapterV2 = exports.fetchVaultV2MorphoMarketV1Adapter = exports.fetchVaultV2MidnightAdapter = exports.fetchVaultV2BluePublicAllocatorData = exports.fetchVaultV2BluePublicAllocatorConfig = exports.fetchVaultV2BlueMarketPublicAllocatorConfig = exports.fetchVaultV2Adapter = exports.fetchVaultV2 = exports.fetchVaultUser = exports.fetchVaultMarketConfig = exports.fetchVaultMarketAllocation = exports.fetchVaultConfig = exports.fetchVault = exports.fetchBlueUser = exports.fetchToken = exports.fetchBluePreLiquidationPosition = exports.fetchBluePreLiquidationParams = exports.fetchBluePosition = exports.fetchBlueMarketParams = exports.fetchBlueMarket = exports.fetchHolding = exports.fetchAccrualVaultV2MorphoVaultV1Adapter = exports.fetchAccrualVaultV2MorphoMarketV1AdapterV2 = exports.fetchAccrualVaultV2MorphoMarketV1Adapter = exports.fetchAccrualVaultV2MidnightAdapter = exports.fetchAccrualVaultV2Adapter = exports.fetchAccrualVaultV2 = exports.fetchAccrualVault = exports.fetchBlueAccrualPosition = void 0;
|
|
4
4
|
var blue_sdk_viem_1 = require("@morpho-org/blue-sdk-viem");
|
|
5
5
|
Object.defineProperty(exports, "fetchBlueAccrualPosition", { enumerable: true, get: function () { return blue_sdk_viem_1.fetchAccrualPosition; } });
|
|
6
6
|
Object.defineProperty(exports, "fetchAccrualVault", { enumerable: true, get: function () { return blue_sdk_viem_1.fetchAccrualVault; } });
|
|
7
7
|
Object.defineProperty(exports, "fetchAccrualVaultV2", { enumerable: true, get: function () { return blue_sdk_viem_1.fetchAccrualVaultV2; } });
|
|
8
8
|
Object.defineProperty(exports, "fetchAccrualVaultV2Adapter", { enumerable: true, get: function () { return blue_sdk_viem_1.fetchAccrualVaultV2Adapter; } });
|
|
9
|
+
Object.defineProperty(exports, "fetchAccrualVaultV2MidnightAdapter", { enumerable: true, get: function () { return blue_sdk_viem_1.fetchAccrualVaultV2MidnightAdapter; } });
|
|
9
10
|
Object.defineProperty(exports, "fetchAccrualVaultV2MorphoMarketV1Adapter", { enumerable: true, get: function () { return blue_sdk_viem_1.fetchAccrualVaultV2MorphoMarketV1Adapter; } });
|
|
10
11
|
Object.defineProperty(exports, "fetchAccrualVaultV2MorphoMarketV1AdapterV2", { enumerable: true, get: function () { return blue_sdk_viem_1.fetchAccrualVaultV2MorphoMarketV1AdapterV2; } });
|
|
11
12
|
Object.defineProperty(exports, "fetchAccrualVaultV2MorphoVaultV1Adapter", { enumerable: true, get: function () { return blue_sdk_viem_1.fetchAccrualVaultV2MorphoVaultV1Adapter; } });
|
|
@@ -29,6 +30,7 @@ Object.defineProperty(exports, "fetchVaultV2Adapter", { enumerable: true, get: f
|
|
|
29
30
|
Object.defineProperty(exports, "fetchVaultV2BlueMarketPublicAllocatorConfig", { enumerable: true, get: function () { return blue_sdk_viem_1.fetchVaultV2BlueMarketPublicAllocatorConfig; } });
|
|
30
31
|
Object.defineProperty(exports, "fetchVaultV2BluePublicAllocatorConfig", { enumerable: true, get: function () { return blue_sdk_viem_1.fetchVaultV2BluePublicAllocatorConfig; } });
|
|
31
32
|
Object.defineProperty(exports, "fetchVaultV2BluePublicAllocatorData", { enumerable: true, get: function () { return blue_sdk_viem_1.fetchVaultV2BluePublicAllocatorData; } });
|
|
33
|
+
Object.defineProperty(exports, "fetchVaultV2MidnightAdapter", { enumerable: true, get: function () { return blue_sdk_viem_1.fetchVaultV2MidnightAdapter; } });
|
|
32
34
|
Object.defineProperty(exports, "fetchVaultV2MorphoMarketV1Adapter", { enumerable: true, get: function () { return blue_sdk_viem_1.fetchVaultV2MorphoMarketV1Adapter; } });
|
|
33
35
|
Object.defineProperty(exports, "fetchVaultV2MorphoMarketV1AdapterV2", { enumerable: true, get: function () { return blue_sdk_viem_1.fetchVaultV2MorphoMarketV1AdapterV2; } });
|
|
34
36
|
Object.defineProperty(exports, "fetchVaultV2MorphoVaultV1Adapter", { enumerable: true, get: function () { return blue_sdk_viem_1.fetchVaultV2MorphoVaultV1Adapter; } });
|
|
@@ -193,6 +193,9 @@ function getDeadSharesAbsoluteCap(id, { absoluteCaps, entity, adapter, }) {
|
|
|
193
193
|
}
|
|
194
194
|
/** Checks the currently allocated positions of one supported adapter. @internal */
|
|
195
195
|
function assertAdapterDeadShares(adapter, { absoluteCaps, entity, }) {
|
|
196
|
+
if (adapter instanceof blue_sdk_1.AccrualVaultV2MidnightAdapter) {
|
|
197
|
+
return;
|
|
198
|
+
}
|
|
196
199
|
if (adapter instanceof blue_sdk_1.AccrualVaultV2MorphoVaultV1Adapter) {
|
|
197
200
|
const id = blue_sdk_1.VaultV2MorphoVaultV1Adapter.adapterCapId(adapter.address);
|
|
198
201
|
if (getDeadSharesAbsoluteCap(id, {
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { type AccrualPosition, type MarketId } from "@morpho-org/blue-sdk";
|
|
2
|
+
/** @internal Quotes repayment funding without projecting a position for health checks. */
|
|
3
|
+
export declare function quoteBlueRepayFunding(params: Parameters<typeof quoteBlueRepay>[0]): bigint;
|
|
4
|
+
/** @internal Quotes Blue repayment funding and the position used for withdrawal health checks. */
|
|
5
|
+
export declare function quoteBlueRepay({ positionData, marketId, repayAssets, repayShares, deadline, now, }: {
|
|
6
|
+
readonly positionData: AccrualPosition;
|
|
7
|
+
readonly marketId: MarketId;
|
|
8
|
+
readonly repayAssets: bigint;
|
|
9
|
+
readonly repayShares: bigint;
|
|
10
|
+
readonly deadline: bigint;
|
|
11
|
+
readonly now: bigint;
|
|
12
|
+
}): {
|
|
13
|
+
simulatedRepayShares: bigint;
|
|
14
|
+
accruedPosition: AccrualPosition;
|
|
15
|
+
expectedRepayAssets: bigint;
|
|
16
|
+
};
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.quoteBlueRepayFunding = quoteBlueRepayFunding;
|
|
4
|
+
exports.quoteBlueRepay = quoteBlueRepay;
|
|
5
|
+
const blue_sdk_1 = require("@morpho-org/blue-sdk");
|
|
6
|
+
const morpho_ts_1 = require("@morpho-org/morpho-ts");
|
|
7
|
+
const viem_1 = require("viem");
|
|
8
|
+
const error_js_1 = require("../types/error.js");
|
|
9
|
+
const validate_js_1 = require("./validate.js");
|
|
10
|
+
/** @internal Quotes repayment funding without projecting a position for health checks. */
|
|
11
|
+
function quoteBlueRepayFunding(params) {
|
|
12
|
+
if (params.repayShares > 0n) {
|
|
13
|
+
return quoteBlueRepay(params).expectedRepayAssets;
|
|
14
|
+
}
|
|
15
|
+
if (params.repayAssets > 0n) {
|
|
16
|
+
(0, validate_js_1.validateRepayAmount)(params);
|
|
17
|
+
}
|
|
18
|
+
return params.repayAssets;
|
|
19
|
+
}
|
|
20
|
+
/** @internal Quotes Blue repayment funding and the position used for withdrawal health checks. */
|
|
21
|
+
function quoteBlueRepay({ positionData, marketId, repayAssets, repayShares, deadline, now, }) {
|
|
22
|
+
const saturatedRepay = repayShares === viem_1.maxUint256;
|
|
23
|
+
const simulatedRepayShares = saturatedRepay
|
|
24
|
+
? positionData.borrowShares
|
|
25
|
+
: repayShares;
|
|
26
|
+
if (repayAssets > 0n) {
|
|
27
|
+
(0, validate_js_1.validateRepayAmount)({ positionData, repayAssets, marketId });
|
|
28
|
+
}
|
|
29
|
+
else if (repayShares > 0n && !saturatedRepay) {
|
|
30
|
+
(0, validate_js_1.validateRepayShares)({ positionData, repayShares, marketId });
|
|
31
|
+
}
|
|
32
|
+
const quoteHorizon = blue_sdk_1.MathLib.max(now, positionData.market.lastUpdate) + morpho_ts_1.Time.s.from.h(2n);
|
|
33
|
+
if (repayShares > 0n && deadline > quoteHorizon) {
|
|
34
|
+
throw new error_js_1.InputExceedsMaxError({
|
|
35
|
+
field: "deadline",
|
|
36
|
+
value: deadline,
|
|
37
|
+
max: quoteHorizon,
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
const accrualTimestamp = repayShares > 0n ? deadline : quoteHorizon;
|
|
41
|
+
const accruedPosition = positionData.accrueInterest(accrualTimestamp);
|
|
42
|
+
const expectedRepayAssets = repayAssets <= 0n && repayShares > 0n
|
|
43
|
+
? accruedPosition.market.toBorrowAssets(simulatedRepayShares, "Up")
|
|
44
|
+
: repayAssets;
|
|
45
|
+
return { simulatedRepayShares, accruedPosition, expectedRepayAssets };
|
|
46
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { type Address } from "@morpho-org/blue-sdk";
|
|
2
|
+
/** @internal Returns the requested approval amounts in execution order. */
|
|
3
|
+
export declare function getTokenApprovalAmounts({ token, chainId, allowance, spendAmount, }: {
|
|
4
|
+
readonly token: Address;
|
|
5
|
+
readonly chainId: number;
|
|
6
|
+
readonly allowance: bigint;
|
|
7
|
+
readonly spendAmount: bigint;
|
|
8
|
+
}): readonly bigint[];
|
|
9
|
+
/** @internal Caps a requested approval at the token's supported maximum. */
|
|
10
|
+
export declare function capTokenApproval({ token, chainId, amount, }: {
|
|
11
|
+
readonly token: Address;
|
|
12
|
+
readonly chainId: number;
|
|
13
|
+
readonly amount: bigint;
|
|
14
|
+
}): bigint;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getTokenApprovalAmounts = getTokenApprovalAmounts;
|
|
4
|
+
exports.capTokenApproval = capTokenApproval;
|
|
5
|
+
const blue_sdk_1 = require("@morpho-org/blue-sdk");
|
|
6
|
+
const viem_1 = require("viem");
|
|
7
|
+
const constant_js_1 = require("./constant.js");
|
|
8
|
+
/** @internal Returns the requested approval amounts in execution order. */
|
|
9
|
+
function getTokenApprovalAmounts({ token, chainId, allowance, spendAmount, }) {
|
|
10
|
+
if (allowance >= spendAmount) {
|
|
11
|
+
return [];
|
|
12
|
+
}
|
|
13
|
+
const needsReset = allowance > 0n &&
|
|
14
|
+
constant_js_1.APPROVE_ONLY_ONCE_TOKENS[chainId]?.some((address) => (0, viem_1.isAddressEqual)(token, address));
|
|
15
|
+
return needsReset ? [0n, viem_1.maxUint256] : [viem_1.maxUint256];
|
|
16
|
+
}
|
|
17
|
+
/** @internal Caps a requested approval at the token's supported maximum. */
|
|
18
|
+
function capTokenApproval({ token, chainId, amount, }) {
|
|
19
|
+
return blue_sdk_1.MathLib.min(amount, constant_js_1.MAX_TOKEN_APPROVALS[chainId]?.[(0, viem_1.getAddress)(token)] ?? viem_1.maxUint256);
|
|
20
|
+
}
|
|
@@ -336,7 +336,7 @@ export declare const validateNativeVaultAsset: (chainId: number, vaultAsset: Add
|
|
|
336
336
|
* @param params.lltv - The market's liquidation LTV.
|
|
337
337
|
* @param params.marketId - The market identifier (for error messages).
|
|
338
338
|
* @returns `void` when the post-withdraw position stays within the safe LTV threshold.
|
|
339
|
-
* @throws {MarketIdMismatchError} when
|
|
339
|
+
* @throws {MarketIdMismatchError} when the two market IDs differ beyond hex casing.
|
|
340
340
|
* @throws {WithdrawExceedsCollateralError} when `withdrawAmount` exceeds the position's collateral.
|
|
341
341
|
* @throws {MissingMarketPriceError} when the position carries debt but the market has no oracle price.
|
|
342
342
|
* @throws {WithdrawMakesPositionUnhealthyError} when the remaining collateral cannot cover the debt
|
|
@@ -472,7 +472,7 @@ exports.validateNativeVaultAsset = validateNativeVaultAsset;
|
|
|
472
472
|
* @param params.lltv - The market's liquidation LTV.
|
|
473
473
|
* @param params.marketId - The market identifier (for error messages).
|
|
474
474
|
* @returns `void` when the post-withdraw position stays within the safe LTV threshold.
|
|
475
|
-
* @throws {MarketIdMismatchError} when
|
|
475
|
+
* @throws {MarketIdMismatchError} when the two market IDs differ beyond hex casing.
|
|
476
476
|
* @throws {WithdrawExceedsCollateralError} when `withdrawAmount` exceeds the position's collateral.
|
|
477
477
|
* @throws {MissingMarketPriceError} when the position carries debt but the market has no oracle price.
|
|
478
478
|
* @throws {WithdrawMakesPositionUnhealthyError} when the remaining collateral cannot cover the debt
|
|
@@ -499,7 +499,7 @@ exports.validateNativeVaultAsset = validateNativeVaultAsset;
|
|
|
499
499
|
*/
|
|
500
500
|
const validatePositionHealthAfterWithdraw = (params) => {
|
|
501
501
|
const { positionData, withdrawAmount, lltv, marketId } = params;
|
|
502
|
-
if (positionData.marketId
|
|
502
|
+
if (!(0, morpho_ts_1.isHexEqual)(positionData.marketId, marketId)) {
|
|
503
503
|
throw new index_js_1.MarketIdMismatchError(positionData.marketId, marketId);
|
|
504
504
|
}
|
|
505
505
|
if (withdrawAmount > positionData.collateral) {
|
package/lib/cjs/index.d.ts
CHANGED
|
@@ -3,7 +3,7 @@ export { validateClientChainId } from "./actions/requirements/validateClientChai
|
|
|
3
3
|
export * from "./client/index.js";
|
|
4
4
|
export * from "./entities/requirements/index.js";
|
|
5
5
|
export * from "./helpers/index.js";
|
|
6
|
-
export type { Action, Funding, IntentParams, ReferralFee, SignatureRequest, Step, TransactionPlan, VaultV1DepositPlanParams, VaultV1InKindRedeemPlanParams, VaultV1MigrateToV2PlanParams, VaultV1RedeemPlanParams, VaultV1WithdrawPlanParams, VaultV2DepositPlanParams, VaultV2ForceRedeemPlanParams, VaultV2ForceWithdrawPlanParams, VaultV2InKindRedeemPlanParams, VaultV2RedeemPlanParams, VaultV2WithdrawPlanParams, } from "./transactionPlan/index.js";
|
|
7
|
-
export { applySignatures, buildTransaction, buildTransactions, getPendingSignatureRequests, IncompleteTransactionPlanError, InvalidCalldataOriginError, InvalidTransactionPlanError, NonIntegerInputError, parseTransactionPlan, prepareVaultV1Deposit, prepareVaultV1InKindRedeem, prepareVaultV1MigrateToV2, prepareVaultV1Redeem, prepareVaultV1Withdraw, prepareVaultV2Deposit, prepareVaultV2ForceRedeem, prepareVaultV2ForceWithdraw, prepareVaultV2InKindRedeem, prepareVaultV2Redeem, prepareVaultV2Withdraw, serializeTransactionPlan, TransactionPlanSignatureMismatchError, UnsupportedTransactionPlanActionError, UnsupportedTransactionPlanVersionError, ZeroAccountError, } from "./transactionPlan/index.js";
|
|
6
|
+
export type { Action, BlueBorrowPlanParams, BlueMarketSnapshot, BluePositionSnapshot, BlueRefinancePlanParams, BlueRepayPlanParams, BlueRepayWithdrawCollateralPlanParams, BlueSupplyCollateralBorrowPlanParams, BlueSupplyCollateralPlanParams, BlueSupplyPlanParams, BlueWithdrawCollateralPlanParams, BlueWithdrawPlanParams, Funding, IntentParams, ReferralFee, SignatureRequest, Step, TransactionPlan, VaultV1DepositPlanParams, VaultV1InKindRedeemPlanParams, VaultV1MigrateToV2PlanParams, VaultV1RedeemPlanParams, VaultV1WithdrawPlanParams, VaultV2DepositPlanParams, VaultV2ForceRedeemPlanParams, VaultV2ForceWithdrawPlanParams, VaultV2InKindRedeemPlanParams, VaultV2RedeemPlanParams, VaultV2WithdrawPlanParams, } from "./transactionPlan/index.js";
|
|
7
|
+
export { applySignatures, BlueSnapshotChainMismatchError, BlueSnapshotStateMismatchError, buildTransaction, buildTransactions, getPendingSignatureRequests, IncompleteTransactionPlanError, InvalidCalldataOriginError, InvalidTransactionPlanError, NonIntegerInputError, parseTransactionPlan, prepareBlueBorrow, prepareBlueRefinance, prepareBlueRepay, prepareBlueRepayWithdrawCollateral, prepareBlueSupply, prepareBlueSupplyCollateral, prepareBlueSupplyCollateralBorrow, prepareBlueWithdraw, prepareBlueWithdrawCollateral, prepareVaultV1Deposit, prepareVaultV1InKindRedeem, prepareVaultV1MigrateToV2, prepareVaultV1Redeem, prepareVaultV1Withdraw, prepareVaultV2Deposit, prepareVaultV2ForceRedeem, prepareVaultV2ForceWithdraw, prepareVaultV2InKindRedeem, prepareVaultV2Redeem, prepareVaultV2Withdraw, serializeTransactionPlan, TransactionPlanSignatureMismatchError, UnsupportedTransactionPlanActionError, UnsupportedTransactionPlanVersionError, validateBlueMarketSnapshot, ZeroAccountError, } from "./transactionPlan/index.js";
|
|
8
8
|
export * from "./types/index.js";
|
|
9
9
|
export { version } from "./version.js";
|
package/lib/cjs/index.js
CHANGED
|
@@ -14,7 +14,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
14
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
exports.version = exports.ZeroAccountError = exports.UnsupportedTransactionPlanVersionError = exports.UnsupportedTransactionPlanActionError = exports.TransactionPlanSignatureMismatchError = exports.serializeTransactionPlan = exports.prepareVaultV2Withdraw = exports.prepareVaultV2Redeem = exports.prepareVaultV2InKindRedeem = exports.prepareVaultV2ForceWithdraw = exports.prepareVaultV2ForceRedeem = exports.prepareVaultV2Deposit = exports.prepareVaultV1Withdraw = exports.prepareVaultV1Redeem = exports.prepareVaultV1MigrateToV2 = exports.prepareVaultV1InKindRedeem = exports.prepareVaultV1Deposit = exports.parseTransactionPlan = exports.NonIntegerInputError = exports.InvalidTransactionPlanError = exports.InvalidCalldataOriginError = exports.IncompleteTransactionPlanError = exports.getPendingSignatureRequests = exports.buildTransactions = exports.buildTransaction = exports.applySignatures = exports.validateClientChainId = void 0;
|
|
17
|
+
exports.version = exports.ZeroAccountError = exports.validateBlueMarketSnapshot = exports.UnsupportedTransactionPlanVersionError = exports.UnsupportedTransactionPlanActionError = exports.TransactionPlanSignatureMismatchError = exports.serializeTransactionPlan = exports.prepareVaultV2Withdraw = exports.prepareVaultV2Redeem = exports.prepareVaultV2InKindRedeem = exports.prepareVaultV2ForceWithdraw = exports.prepareVaultV2ForceRedeem = exports.prepareVaultV2Deposit = exports.prepareVaultV1Withdraw = exports.prepareVaultV1Redeem = exports.prepareVaultV1MigrateToV2 = exports.prepareVaultV1InKindRedeem = exports.prepareVaultV1Deposit = exports.prepareBlueWithdrawCollateral = exports.prepareBlueWithdraw = exports.prepareBlueSupplyCollateralBorrow = exports.prepareBlueSupplyCollateral = exports.prepareBlueSupply = exports.prepareBlueRepayWithdrawCollateral = exports.prepareBlueRepay = exports.prepareBlueRefinance = exports.prepareBlueBorrow = exports.parseTransactionPlan = exports.NonIntegerInputError = exports.InvalidTransactionPlanError = exports.InvalidCalldataOriginError = exports.IncompleteTransactionPlanError = exports.getPendingSignatureRequests = exports.buildTransactions = exports.buildTransaction = exports.BlueSnapshotStateMismatchError = exports.BlueSnapshotChainMismatchError = exports.applySignatures = exports.validateClientChainId = void 0;
|
|
18
18
|
__exportStar(require("./actions/index.js"), exports);
|
|
19
19
|
var validateClientChainId_js_1 = require("./actions/requirements/validateClientChainId.js");
|
|
20
20
|
Object.defineProperty(exports, "validateClientChainId", { enumerable: true, get: function () { return validateClientChainId_js_1.validateClientChainId; } });
|
|
@@ -23,6 +23,8 @@ __exportStar(require("./entities/requirements/index.js"), exports);
|
|
|
23
23
|
__exportStar(require("./helpers/index.js"), exports);
|
|
24
24
|
var index_js_1 = require("./transactionPlan/index.js");
|
|
25
25
|
Object.defineProperty(exports, "applySignatures", { enumerable: true, get: function () { return index_js_1.applySignatures; } });
|
|
26
|
+
Object.defineProperty(exports, "BlueSnapshotChainMismatchError", { enumerable: true, get: function () { return index_js_1.BlueSnapshotChainMismatchError; } });
|
|
27
|
+
Object.defineProperty(exports, "BlueSnapshotStateMismatchError", { enumerable: true, get: function () { return index_js_1.BlueSnapshotStateMismatchError; } });
|
|
26
28
|
Object.defineProperty(exports, "buildTransaction", { enumerable: true, get: function () { return index_js_1.buildTransaction; } });
|
|
27
29
|
Object.defineProperty(exports, "buildTransactions", { enumerable: true, get: function () { return index_js_1.buildTransactions; } });
|
|
28
30
|
Object.defineProperty(exports, "getPendingSignatureRequests", { enumerable: true, get: function () { return index_js_1.getPendingSignatureRequests; } });
|
|
@@ -31,6 +33,15 @@ Object.defineProperty(exports, "InvalidCalldataOriginError", { enumerable: true,
|
|
|
31
33
|
Object.defineProperty(exports, "InvalidTransactionPlanError", { enumerable: true, get: function () { return index_js_1.InvalidTransactionPlanError; } });
|
|
32
34
|
Object.defineProperty(exports, "NonIntegerInputError", { enumerable: true, get: function () { return index_js_1.NonIntegerInputError; } });
|
|
33
35
|
Object.defineProperty(exports, "parseTransactionPlan", { enumerable: true, get: function () { return index_js_1.parseTransactionPlan; } });
|
|
36
|
+
Object.defineProperty(exports, "prepareBlueBorrow", { enumerable: true, get: function () { return index_js_1.prepareBlueBorrow; } });
|
|
37
|
+
Object.defineProperty(exports, "prepareBlueRefinance", { enumerable: true, get: function () { return index_js_1.prepareBlueRefinance; } });
|
|
38
|
+
Object.defineProperty(exports, "prepareBlueRepay", { enumerable: true, get: function () { return index_js_1.prepareBlueRepay; } });
|
|
39
|
+
Object.defineProperty(exports, "prepareBlueRepayWithdrawCollateral", { enumerable: true, get: function () { return index_js_1.prepareBlueRepayWithdrawCollateral; } });
|
|
40
|
+
Object.defineProperty(exports, "prepareBlueSupply", { enumerable: true, get: function () { return index_js_1.prepareBlueSupply; } });
|
|
41
|
+
Object.defineProperty(exports, "prepareBlueSupplyCollateral", { enumerable: true, get: function () { return index_js_1.prepareBlueSupplyCollateral; } });
|
|
42
|
+
Object.defineProperty(exports, "prepareBlueSupplyCollateralBorrow", { enumerable: true, get: function () { return index_js_1.prepareBlueSupplyCollateralBorrow; } });
|
|
43
|
+
Object.defineProperty(exports, "prepareBlueWithdraw", { enumerable: true, get: function () { return index_js_1.prepareBlueWithdraw; } });
|
|
44
|
+
Object.defineProperty(exports, "prepareBlueWithdrawCollateral", { enumerable: true, get: function () { return index_js_1.prepareBlueWithdrawCollateral; } });
|
|
34
45
|
Object.defineProperty(exports, "prepareVaultV1Deposit", { enumerable: true, get: function () { return index_js_1.prepareVaultV1Deposit; } });
|
|
35
46
|
Object.defineProperty(exports, "prepareVaultV1InKindRedeem", { enumerable: true, get: function () { return index_js_1.prepareVaultV1InKindRedeem; } });
|
|
36
47
|
Object.defineProperty(exports, "prepareVaultV1MigrateToV2", { enumerable: true, get: function () { return index_js_1.prepareVaultV1MigrateToV2; } });
|
|
@@ -46,6 +57,7 @@ Object.defineProperty(exports, "serializeTransactionPlan", { enumerable: true, g
|
|
|
46
57
|
Object.defineProperty(exports, "TransactionPlanSignatureMismatchError", { enumerable: true, get: function () { return index_js_1.TransactionPlanSignatureMismatchError; } });
|
|
47
58
|
Object.defineProperty(exports, "UnsupportedTransactionPlanActionError", { enumerable: true, get: function () { return index_js_1.UnsupportedTransactionPlanActionError; } });
|
|
48
59
|
Object.defineProperty(exports, "UnsupportedTransactionPlanVersionError", { enumerable: true, get: function () { return index_js_1.UnsupportedTransactionPlanVersionError; } });
|
|
60
|
+
Object.defineProperty(exports, "validateBlueMarketSnapshot", { enumerable: true, get: function () { return index_js_1.validateBlueMarketSnapshot; } });
|
|
49
61
|
Object.defineProperty(exports, "ZeroAccountError", { enumerable: true, get: function () { return index_js_1.ZeroAccountError; } });
|
|
50
62
|
__exportStar(require("./types/index.js"), exports);
|
|
51
63
|
var version_js_1 = require("./version.js");
|
|
@@ -1 +1,2 @@
|
|
|
1
|
-
export { ChainIdMismatchError, InvalidEcrecoverSignatureError, InvalidEcrecoverSignatureVError, InvalidMarketParameterError, InvalidMidnightApiQuoteTargetError, InvalidMidnightApiResponseError, InvalidOfferGroupError, InvalidOfferParameterError,
|
|
1
|
+
export { ChainIdMismatchError, InvalidEcrecoverSignatureError, InvalidEcrecoverSignatureVError, InvalidMarketParameterError, InvalidMidnightApiQuoteTargetError, InvalidMidnightApiResponseError, InvalidOfferGroupError, InvalidOfferParameterError, InvalidRateRatifierV1RateError, InvalidRateRatifierV1TickError, InvalidRateRatifierV1TimeError, InvalidRatifierV1AddressError, InvalidTickSpacingError, InvalidTreeError, InvalidTreeHeightError, InvalidTypedDataSignatureError, MidnightApiError, MidnightMempoolValidationError, PayloadDecodeError, PriceGreaterThanOneError, RateRatifierV1BoundOverflowError, RatifierV1TakerNotAllowedError, SettlementFeeExceedsPriceError, TickOutOfRangeError, UnknownCollateralIndexError, } from "@morpho-org/midnight-sdk";
|
|
2
|
+
export { InvalidPositionAccrualStateError, InvalidPositionAccrualTimestampError, InvalidPositionLossFactorError, } from "@morpho-org/morpho-ts";
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.UnknownCollateralIndexError = exports.TickOutOfRangeError = exports.SettlementFeeExceedsPriceError = exports.RatifierV1TakerNotAllowedError = exports.RateRatifierV1BoundOverflowError = exports.PriceGreaterThanOneError = exports.PayloadDecodeError = exports.MidnightMempoolValidationError = exports.MidnightApiError = exports.InvalidTypedDataSignatureError = exports.InvalidTreeHeightError = exports.InvalidTreeError = exports.InvalidTickSpacingError = exports.InvalidRatifierV1AddressError = exports.InvalidRateRatifierV1TimeError = exports.InvalidRateRatifierV1TickError = exports.InvalidRateRatifierV1RateError = exports.
|
|
3
|
+
exports.InvalidPositionLossFactorError = exports.InvalidPositionAccrualTimestampError = exports.InvalidPositionAccrualStateError = exports.UnknownCollateralIndexError = exports.TickOutOfRangeError = exports.SettlementFeeExceedsPriceError = exports.RatifierV1TakerNotAllowedError = exports.RateRatifierV1BoundOverflowError = exports.PriceGreaterThanOneError = exports.PayloadDecodeError = exports.MidnightMempoolValidationError = exports.MidnightApiError = exports.InvalidTypedDataSignatureError = exports.InvalidTreeHeightError = exports.InvalidTreeError = exports.InvalidTickSpacingError = exports.InvalidRatifierV1AddressError = exports.InvalidRateRatifierV1TimeError = exports.InvalidRateRatifierV1TickError = exports.InvalidRateRatifierV1RateError = exports.InvalidOfferParameterError = exports.InvalidOfferGroupError = exports.InvalidMidnightApiResponseError = exports.InvalidMidnightApiQuoteTargetError = exports.InvalidMarketParameterError = exports.InvalidEcrecoverSignatureVError = exports.InvalidEcrecoverSignatureError = exports.ChainIdMismatchError = void 0;
|
|
4
4
|
var midnight_sdk_1 = require("@morpho-org/midnight-sdk");
|
|
5
5
|
Object.defineProperty(exports, "ChainIdMismatchError", { enumerable: true, get: function () { return midnight_sdk_1.ChainIdMismatchError; } });
|
|
6
6
|
Object.defineProperty(exports, "InvalidEcrecoverSignatureError", { enumerable: true, get: function () { return midnight_sdk_1.InvalidEcrecoverSignatureError; } });
|
|
@@ -10,9 +10,6 @@ Object.defineProperty(exports, "InvalidMidnightApiQuoteTargetError", { enumerabl
|
|
|
10
10
|
Object.defineProperty(exports, "InvalidMidnightApiResponseError", { enumerable: true, get: function () { return midnight_sdk_1.InvalidMidnightApiResponseError; } });
|
|
11
11
|
Object.defineProperty(exports, "InvalidOfferGroupError", { enumerable: true, get: function () { return midnight_sdk_1.InvalidOfferGroupError; } });
|
|
12
12
|
Object.defineProperty(exports, "InvalidOfferParameterError", { enumerable: true, get: function () { return midnight_sdk_1.InvalidOfferParameterError; } });
|
|
13
|
-
Object.defineProperty(exports, "InvalidPositionAccrualStateError", { enumerable: true, get: function () { return midnight_sdk_1.InvalidPositionAccrualStateError; } });
|
|
14
|
-
Object.defineProperty(exports, "InvalidPositionAccrualTimestampError", { enumerable: true, get: function () { return midnight_sdk_1.InvalidPositionAccrualTimestampError; } });
|
|
15
|
-
Object.defineProperty(exports, "InvalidPositionLossFactorError", { enumerable: true, get: function () { return midnight_sdk_1.InvalidPositionLossFactorError; } });
|
|
16
13
|
Object.defineProperty(exports, "InvalidRateRatifierV1RateError", { enumerable: true, get: function () { return midnight_sdk_1.InvalidRateRatifierV1RateError; } });
|
|
17
14
|
Object.defineProperty(exports, "InvalidRateRatifierV1TickError", { enumerable: true, get: function () { return midnight_sdk_1.InvalidRateRatifierV1TickError; } });
|
|
18
15
|
Object.defineProperty(exports, "InvalidRateRatifierV1TimeError", { enumerable: true, get: function () { return midnight_sdk_1.InvalidRateRatifierV1TimeError; } });
|
|
@@ -30,3 +27,7 @@ Object.defineProperty(exports, "RatifierV1TakerNotAllowedError", { enumerable: t
|
|
|
30
27
|
Object.defineProperty(exports, "SettlementFeeExceedsPriceError", { enumerable: true, get: function () { return midnight_sdk_1.SettlementFeeExceedsPriceError; } });
|
|
31
28
|
Object.defineProperty(exports, "TickOutOfRangeError", { enumerable: true, get: function () { return midnight_sdk_1.TickOutOfRangeError; } });
|
|
32
29
|
Object.defineProperty(exports, "UnknownCollateralIndexError", { enumerable: true, get: function () { return midnight_sdk_1.UnknownCollateralIndexError; } });
|
|
30
|
+
var morpho_ts_1 = require("@morpho-org/morpho-ts");
|
|
31
|
+
Object.defineProperty(exports, "InvalidPositionAccrualStateError", { enumerable: true, get: function () { return morpho_ts_1.InvalidPositionAccrualStateError; } });
|
|
32
|
+
Object.defineProperty(exports, "InvalidPositionAccrualTimestampError", { enumerable: true, get: function () { return morpho_ts_1.InvalidPositionAccrualTimestampError; } });
|
|
33
|
+
Object.defineProperty(exports, "InvalidPositionLossFactorError", { enumerable: true, get: function () { return morpho_ts_1.InvalidPositionLossFactorError; } });
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { type Address, type Client, type TypedDataDomain } from "viem";
|
|
2
|
+
interface PermitInputs {
|
|
3
|
+
readonly chainId: number;
|
|
4
|
+
readonly spender: Address;
|
|
5
|
+
readonly deadline?: bigint;
|
|
6
|
+
readonly now: bigint;
|
|
7
|
+
}
|
|
8
|
+
/** @internal Validates permit inputs and the transport chain before token metadata reads. */
|
|
9
|
+
export declare function validateErc2612Permit(client: Client, params: PermitInputs): Promise<bigint>;
|
|
10
|
+
/**
|
|
11
|
+
* @internal Reads the owner nonce and checks the resolved signing domain against the token.
|
|
12
|
+
* Returns undefined for an unsupported permit, while RPC transport failures propagate.
|
|
13
|
+
*/
|
|
14
|
+
export declare function readErc2612Permit<T>(client: Client, { token, owner, resolve, }: {
|
|
15
|
+
readonly token: Address;
|
|
16
|
+
readonly owner: Address;
|
|
17
|
+
readonly resolve: (nonce: bigint) => Promise<{
|
|
18
|
+
readonly domain?: TypedDataDomain;
|
|
19
|
+
readonly result: T;
|
|
20
|
+
}>;
|
|
21
|
+
}): Promise<T | undefined>;
|
|
22
|
+
export {};
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.validateErc2612Permit = validateErc2612Permit;
|
|
4
|
+
exports.readErc2612Permit = readErc2612Permit;
|
|
5
|
+
const blue_sdk_viem_1 = require("@morpho-org/blue-sdk-viem");
|
|
6
|
+
const morpho_ts_1 = require("@morpho-org/morpho-ts");
|
|
7
|
+
const viem_1 = require("viem");
|
|
8
|
+
const actions_1 = require("viem/actions");
|
|
9
|
+
const validate_js_1 = require("../helpers/validate.js");
|
|
10
|
+
const validateRequirementSpender_js_1 = require("../helpers/validateRequirementSpender.js");
|
|
11
|
+
const index_js_1 = require("../types/index.js");
|
|
12
|
+
const validateClientChainId_js_1 = require("./validateClientChainId.js");
|
|
13
|
+
function validatePermitInputs(clientChainId, { chainId, spender, deadline, now }) {
|
|
14
|
+
(0, validate_js_1.validateChainId)(clientChainId, chainId);
|
|
15
|
+
(0, validateRequirementSpender_js_1.validateRequirementSpender)({
|
|
16
|
+
chainId,
|
|
17
|
+
spender,
|
|
18
|
+
allowed: ["vaultBundlesV1", "blueBundlesV1"],
|
|
19
|
+
});
|
|
20
|
+
if (deadline == null) {
|
|
21
|
+
return now + morpho_ts_1.Time.s.from.h(2n);
|
|
22
|
+
}
|
|
23
|
+
(0, validate_js_1.validateDeadline)(deadline);
|
|
24
|
+
if (deadline <= now) {
|
|
25
|
+
throw new index_js_1.ExpiredDeadlineError(deadline, now);
|
|
26
|
+
}
|
|
27
|
+
return deadline;
|
|
28
|
+
}
|
|
29
|
+
/** @internal Validates permit inputs and the transport chain before token metadata reads. */
|
|
30
|
+
async function validateErc2612Permit(client, params) {
|
|
31
|
+
const deadline = validatePermitInputs(client.chain?.id, params);
|
|
32
|
+
await (0, validateClientChainId_js_1.validateClientChainId)(client, params.chainId);
|
|
33
|
+
return deadline;
|
|
34
|
+
}
|
|
35
|
+
function unsupportedPermitRead(error) {
|
|
36
|
+
if (!(0, blue_sdk_viem_1.isTransportError)(error) &&
|
|
37
|
+
((0, blue_sdk_viem_1.isContractRevertError)(error) || (0, blue_sdk_viem_1.isUndecodableResultError)(error))) {
|
|
38
|
+
return undefined;
|
|
39
|
+
}
|
|
40
|
+
throw error;
|
|
41
|
+
}
|
|
42
|
+
function matchesPermitDomainSeparator(domain, separator) {
|
|
43
|
+
return (separator.toLowerCase() ===
|
|
44
|
+
(0, viem_1.hashDomain)({
|
|
45
|
+
domain,
|
|
46
|
+
types: { EIP712Domain: (0, viem_1.getTypesForEIP712Domain)({ domain }) },
|
|
47
|
+
}).toLowerCase());
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* @internal Reads the owner nonce and checks the resolved signing domain against the token.
|
|
51
|
+
* Returns undefined for an unsupported permit, while RPC transport failures propagate.
|
|
52
|
+
*/
|
|
53
|
+
async function readErc2612Permit(client, { token, owner, resolve, }) {
|
|
54
|
+
const nonce = await (0, actions_1.readContract)(client, {
|
|
55
|
+
abi: blue_sdk_viem_1.erc2612Abi,
|
|
56
|
+
address: token,
|
|
57
|
+
functionName: "nonces",
|
|
58
|
+
args: [owner],
|
|
59
|
+
}).catch(unsupportedPermitRead);
|
|
60
|
+
if (nonce === undefined) {
|
|
61
|
+
return undefined;
|
|
62
|
+
}
|
|
63
|
+
const permit = await (0, morpho_ts_1._try)(() => resolve(nonce), blue_sdk_viem_1.MissingPermitDomainNameError, blue_sdk_viem_1.InvalidPermitDomainChainIdError, blue_sdk_viem_1.InvalidPermitDomainVerifyingContractError, blue_sdk_viem_1.UnsupportedPermitDomainExtensionsError);
|
|
64
|
+
if (permit === undefined) {
|
|
65
|
+
return undefined;
|
|
66
|
+
}
|
|
67
|
+
const separator = await (0, actions_1.readContract)(client, {
|
|
68
|
+
abi: blue_sdk_viem_1.erc2612Abi,
|
|
69
|
+
address: token,
|
|
70
|
+
functionName: "DOMAIN_SEPARATOR",
|
|
71
|
+
}).catch(unsupportedPermitRead);
|
|
72
|
+
if (separator === undefined ||
|
|
73
|
+
!matchesPermitDomainSeparator(permit.domain ?? {}, separator)) {
|
|
74
|
+
return undefined;
|
|
75
|
+
}
|
|
76
|
+
return permit.result;
|
|
77
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import type { Client } from "viem";
|
|
2
|
+
/**
|
|
3
|
+
* Validates both the chain the viem client declares and the chain its transport serves.
|
|
4
|
+
*
|
|
5
|
+
* Sends one `eth_chainId` request per call; the result is never cached, so every flow observes the
|
|
6
|
+
* endpoint it actually reads from. An honest RPC connected to another chain fails here, before any
|
|
7
|
+
* state read. A provider that lies about `eth_chainId` is not detected (see THREAT_MODEL.md, RPC).
|
|
8
|
+
*
|
|
9
|
+
* @param client - Viem client whose declared chain and transport are checked.
|
|
10
|
+
* @param expectedChainId - Chain ID expected by the entity or action.
|
|
11
|
+
* @returns Resolves only when both the declared and the observed chain IDs equal
|
|
12
|
+
* `expectedChainId`.
|
|
13
|
+
* @throws {ChainIdMismatchError} when the declared or the observed chain ID differs from
|
|
14
|
+
* `expectedChainId`.
|
|
15
|
+
* @throws {viem.BaseError} when the `eth_chainId` request fails.
|
|
16
|
+
* @example
|
|
17
|
+
* ```ts
|
|
18
|
+
* import { createPublicClient, http } from "viem";
|
|
19
|
+
* import { mainnet } from "viem/chains";
|
|
20
|
+
* import { validateClientChainId } from "@morpho-org/morpho-sdk";
|
|
21
|
+
*
|
|
22
|
+
* const client = createPublicClient({ chain: mainnet, transport: http() });
|
|
23
|
+
* await validateClientChainId(client, mainnet.id);
|
|
24
|
+
* ```
|
|
25
|
+
*/
|
|
26
|
+
export declare const validateClientChainId: (client: Client, expectedChainId: number) => Promise<void>;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.validateClientChainId = void 0;
|
|
4
|
+
const actions_1 = require("viem/actions");
|
|
5
|
+
const validate_js_1 = require("../helpers/validate.js");
|
|
6
|
+
/**
|
|
7
|
+
* Validates both the chain the viem client declares and the chain its transport serves.
|
|
8
|
+
*
|
|
9
|
+
* Sends one `eth_chainId` request per call; the result is never cached, so every flow observes the
|
|
10
|
+
* endpoint it actually reads from. An honest RPC connected to another chain fails here, before any
|
|
11
|
+
* state read. A provider that lies about `eth_chainId` is not detected (see THREAT_MODEL.md, RPC).
|
|
12
|
+
*
|
|
13
|
+
* @param client - Viem client whose declared chain and transport are checked.
|
|
14
|
+
* @param expectedChainId - Chain ID expected by the entity or action.
|
|
15
|
+
* @returns Resolves only when both the declared and the observed chain IDs equal
|
|
16
|
+
* `expectedChainId`.
|
|
17
|
+
* @throws {ChainIdMismatchError} when the declared or the observed chain ID differs from
|
|
18
|
+
* `expectedChainId`.
|
|
19
|
+
* @throws {viem.BaseError} when the `eth_chainId` request fails.
|
|
20
|
+
* @example
|
|
21
|
+
* ```ts
|
|
22
|
+
* import { createPublicClient, http } from "viem";
|
|
23
|
+
* import { mainnet } from "viem/chains";
|
|
24
|
+
* import { validateClientChainId } from "@morpho-org/morpho-sdk";
|
|
25
|
+
*
|
|
26
|
+
* const client = createPublicClient({ chain: mainnet, transport: http() });
|
|
27
|
+
* await validateClientChainId(client, mainnet.id);
|
|
28
|
+
* ```
|
|
29
|
+
*/
|
|
30
|
+
const validateClientChainId = async (client, expectedChainId) => {
|
|
31
|
+
(0, validate_js_1.validateChainId)(client.chain?.id, expectedChainId);
|
|
32
|
+
(0, validate_js_1.validateChainId)(await (0, actions_1.getChainId)(client), expectedChainId);
|
|
33
|
+
};
|
|
34
|
+
exports.validateClientChainId = validateClientChainId;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { type Address } from "viem";
|
|
2
|
+
import type { BlueAuthorizationAction, Transaction } from "../../types/index.js";
|
|
3
|
+
import type { Action, SignatureRequest } from "../types.js";
|
|
4
|
+
type AuthorizationRequest = Extract<SignatureRequest, {
|
|
5
|
+
kind: "morphoAuthorization";
|
|
6
|
+
}>;
|
|
7
|
+
interface AuthorizationBinding {
|
|
8
|
+
readonly chainId: number;
|
|
9
|
+
readonly account: Address;
|
|
10
|
+
readonly nonce: bigint;
|
|
11
|
+
readonly deadline: bigint;
|
|
12
|
+
}
|
|
13
|
+
/** @internal Binds the canonical Morpho grant to the prepared action and registered BlueBundlesV1. */
|
|
14
|
+
export declare function validateMorphoAuthorizationRequest(request: AuthorizationRequest, { chainId, account, nonce, deadline }: AuthorizationBinding): void;
|
|
15
|
+
/** @internal Encodes the standalone authorization prerequisite. */
|
|
16
|
+
export declare function buildMorphoAuthorization(action: Extract<Action, {
|
|
17
|
+
type: "morphoAuthorization";
|
|
18
|
+
}>): Transaction<BlueAuthorizationAction>;
|
|
19
|
+
/** @internal Rejects signature references on the standalone authorization step. */
|
|
20
|
+
export declare function validateMorphoAuthorizationPlanAction(action: Record<string, unknown>, path: string): void;
|
|
21
|
+
/** @internal Validates the stored authorization request shape without verifying its signature. */
|
|
22
|
+
export declare function validateMorphoAuthorizationPlanRequest(request: Record<string, unknown>, path: string): void;
|
|
23
|
+
export {};
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.validateMorphoAuthorizationRequest = validateMorphoAuthorizationRequest;
|
|
4
|
+
exports.buildMorphoAuthorization = buildMorphoAuthorization;
|
|
5
|
+
exports.validateMorphoAuthorizationPlanAction = validateMorphoAuthorizationPlanAction;
|
|
6
|
+
exports.validateMorphoAuthorizationPlanRequest = validateMorphoAuthorizationPlanRequest;
|
|
7
|
+
const blue_sdk_1 = require("@morpho-org/blue-sdk");
|
|
8
|
+
const blue_sdk_viem_1 = require("@morpho-org/blue-sdk-viem");
|
|
9
|
+
const morpho_ts_1 = require("@morpho-org/morpho-ts");
|
|
10
|
+
const viem_1 = require("viem");
|
|
11
|
+
const error_js_1 = require("../error.js");
|
|
12
|
+
const validation_js_1 = require("../validation.js");
|
|
13
|
+
/** @internal Binds the canonical Morpho grant to the prepared action and registered BlueBundlesV1. */
|
|
14
|
+
function validateMorphoAuthorizationRequest(request, { chainId, account, nonce, deadline }) {
|
|
15
|
+
const authorized = (0, morpho_ts_1.getChainAddress)(chainId, "bundles.blueBundlesV1");
|
|
16
|
+
const expected = (0, blue_sdk_viem_1.getAuthorizationTypedData)({ authorizer: account, authorized, isAuthorized: true, nonce, deadline }, chainId);
|
|
17
|
+
const { domain, message, types, primaryType } = request.typedData;
|
|
18
|
+
const fields = types?.Authorization;
|
|
19
|
+
const checks = [
|
|
20
|
+
["domain.chainId", domain?.chainId === chainId],
|
|
21
|
+
[
|
|
22
|
+
"domain.verifyingContract",
|
|
23
|
+
(0, validation_js_1.matchesAddress)(domain?.verifyingContract, (0, blue_sdk_1.getChainAddresses)(chainId).blue),
|
|
24
|
+
],
|
|
25
|
+
[
|
|
26
|
+
"domain",
|
|
27
|
+
domain?.name === undefined &&
|
|
28
|
+
domain?.version === undefined &&
|
|
29
|
+
domain?.salt === undefined,
|
|
30
|
+
],
|
|
31
|
+
["primaryType", primaryType === expected.primaryType],
|
|
32
|
+
[
|
|
33
|
+
"types",
|
|
34
|
+
Array.isArray(fields) &&
|
|
35
|
+
Object.keys(types).length === 1 &&
|
|
36
|
+
fields.length === expected.types.Authorization.length &&
|
|
37
|
+
expected.types.Authorization.every((field, index) => field.name === fields[index]?.name &&
|
|
38
|
+
field.type === fields[index]?.type),
|
|
39
|
+
],
|
|
40
|
+
["message.authorizer", (0, validation_js_1.matchesAddress)(message?.authorizer, account)],
|
|
41
|
+
["args.owner", (0, validation_js_1.matchesAddress)(request.args.owner, account)],
|
|
42
|
+
["message.authorized", (0, validation_js_1.matchesAddress)(message?.authorized, authorized)],
|
|
43
|
+
["args.authorized", (0, validation_js_1.matchesAddress)(request.args.authorized, authorized)],
|
|
44
|
+
["message.isAuthorized", message?.isAuthorized === true],
|
|
45
|
+
["message.nonce", message?.nonce === nonce],
|
|
46
|
+
["args.nonce", request.args.nonce === nonce],
|
|
47
|
+
["message.deadline", message?.deadline === deadline],
|
|
48
|
+
["args.deadline", request.args.deadline === deadline],
|
|
49
|
+
];
|
|
50
|
+
const mismatch = checks.find(([, matches]) => !matches);
|
|
51
|
+
if (mismatch) {
|
|
52
|
+
throw new error_js_1.TransactionPlanSignatureMismatchError(request.id, mismatch[0]);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
/** @internal Encodes the standalone authorization prerequisite. */
|
|
56
|
+
function buildMorphoAuthorization(action) {
|
|
57
|
+
const { chainId } = action.inputs;
|
|
58
|
+
const to = (0, blue_sdk_1.getChainAddresses)(chainId).blue;
|
|
59
|
+
const authorized = (0, morpho_ts_1.getChainAddress)(chainId, "bundles.blueBundlesV1");
|
|
60
|
+
const args = { authorized, isAuthorized: true };
|
|
61
|
+
const data = (0, viem_1.encodeFunctionData)({
|
|
62
|
+
abi: blue_sdk_viem_1.blueAbi,
|
|
63
|
+
functionName: "setAuthorization",
|
|
64
|
+
args: [authorized, true],
|
|
65
|
+
});
|
|
66
|
+
return { to, value: 0n, data, action: { type: "blueAuthorization", args } };
|
|
67
|
+
}
|
|
68
|
+
/** @internal Rejects signature references on the standalone authorization step. */
|
|
69
|
+
function validateMorphoAuthorizationPlanAction(action, path) {
|
|
70
|
+
if (action.signatureRequestIds !== undefined) {
|
|
71
|
+
throw new error_js_1.InvalidTransactionPlanError({
|
|
72
|
+
path: `${path}.signatureRequestIds`,
|
|
73
|
+
reason: "standalone Morpho authorization does not consume signatures",
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
/** @internal Validates the stored authorization request shape without verifying its signature. */
|
|
78
|
+
function validateMorphoAuthorizationPlanRequest(request, path) {
|
|
79
|
+
const args = (0, validation_js_1.getPlanObject)(request.args, `${path}.args`);
|
|
80
|
+
(0, validation_js_1.validatePlanFields)(args, {
|
|
81
|
+
path: `${path}.args`,
|
|
82
|
+
fields: {
|
|
83
|
+
owner: "address",
|
|
84
|
+
authorized: "address",
|
|
85
|
+
nonce: "uint256 bigint",
|
|
86
|
+
deadline: "uint256 bigint",
|
|
87
|
+
},
|
|
88
|
+
});
|
|
89
|
+
const typedData = (0, validation_js_1.getPlanObject)(request.typedData, `${path}.typedData`);
|
|
90
|
+
if (typedData.primaryType !== "Authorization") {
|
|
91
|
+
throw new error_js_1.InvalidTransactionPlanError({
|
|
92
|
+
path: `${path}.typedData.primaryType`,
|
|
93
|
+
reason: "expected Authorization",
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
const types = (0, validation_js_1.getPlanObject)(typedData.types, `${path}.typedData.types`);
|
|
97
|
+
(0, validation_js_1.validatePlanField)(types.Authorization, {
|
|
98
|
+
path: `${path}.typedData.types.Authorization`,
|
|
99
|
+
type: "array",
|
|
100
|
+
});
|
|
101
|
+
const domain = (0, validation_js_1.getPlanObject)(typedData.domain, `${path}.typedData.domain`);
|
|
102
|
+
(0, validation_js_1.validatePlanFields)(domain, {
|
|
103
|
+
path: `${path}.typedData.domain`,
|
|
104
|
+
fields: { chainId: "positive safe integer", verifyingContract: "address" },
|
|
105
|
+
});
|
|
106
|
+
const message = (0, validation_js_1.getPlanObject)(typedData.message, `${path}.typedData.message`);
|
|
107
|
+
if (message.isAuthorized !== true) {
|
|
108
|
+
throw new error_js_1.InvalidTransactionPlanError({
|
|
109
|
+
path: `${path}.typedData.message.isAuthorized`,
|
|
110
|
+
reason: "expected true",
|
|
111
|
+
});
|
|
112
|
+
}
|
|
113
|
+
(0, validation_js_1.validatePlanFields)(message, {
|
|
114
|
+
path: `${path}.typedData.message`,
|
|
115
|
+
fields: {
|
|
116
|
+
authorizer: "address",
|
|
117
|
+
authorized: "address",
|
|
118
|
+
nonce: "uint256 bigint",
|
|
119
|
+
deadline: "uint256 bigint",
|
|
120
|
+
},
|
|
121
|
+
});
|
|
122
|
+
if (request.signature !== undefined) {
|
|
123
|
+
(0, validation_js_1.validatePlanField)(request.signature, {
|
|
124
|
+
path: `${path}.signature`,
|
|
125
|
+
type: "hex",
|
|
126
|
+
});
|
|
127
|
+
}
|
|
128
|
+
}
|