@morpho-org/morpho-sdk 6.0.0-next.2 → 6.0.0-next.3
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/MIGRATION-v5-to-v6.md +83 -29
- package/README.md +9 -7
- package/lib/cjs/abis.d.ts +3 -2844
- package/lib/cjs/abis.js +1 -1951
- package/lib/cjs/actions/blue/borrow.d.ts +3 -2
- package/lib/cjs/actions/blue/borrow.js +3 -2
- package/lib/cjs/actions/blue/common.js +1 -9
- package/lib/cjs/actions/blue/refinance.d.ts +2 -2
- package/lib/cjs/actions/blue/refinance.js +2 -2
- package/lib/cjs/actions/blue/repay.d.ts +1 -1
- package/lib/cjs/actions/blue/repay.js +1 -1
- package/lib/cjs/actions/blue/repayWithdrawCollateral.d.ts +2 -2
- package/lib/cjs/actions/blue/repayWithdrawCollateral.js +2 -2
- package/lib/cjs/actions/blue/supply.d.ts +2 -2
- package/lib/cjs/actions/blue/supply.js +2 -2
- package/lib/cjs/actions/blue/supplyCollateral.d.ts +2 -2
- package/lib/cjs/actions/blue/supplyCollateral.js +2 -2
- package/lib/cjs/actions/blue/supplyCollateralBorrow.d.ts +3 -2
- package/lib/cjs/actions/blue/supplyCollateralBorrow.js +3 -2
- package/lib/cjs/actions/blue/withdraw.d.ts +3 -3
- package/lib/cjs/actions/blue/withdraw.js +3 -3
- package/lib/cjs/actions/blue/withdrawCollateral.d.ts +2 -2
- package/lib/cjs/actions/blue/withdrawCollateral.js +2 -2
- package/lib/cjs/actions/bundles/common.d.ts +6 -2
- package/lib/cjs/actions/bundles/common.js +23 -5
- package/lib/cjs/actions/index.d.ts +0 -1
- package/lib/cjs/actions/index.js +0 -1
- package/lib/cjs/actions/requirements/blue/getBlueAuthorizationRequirement.d.ts +6 -8
- package/lib/cjs/actions/requirements/blue/getBlueAuthorizationRequirement.js +11 -16
- package/lib/cjs/actions/requirements/encode/encodeBlueSignatureAuthorization.d.ts +5 -6
- package/lib/cjs/actions/requirements/encode/encodeBlueSignatureAuthorization.js +4 -5
- package/lib/cjs/actions/requirements/encode/encodeErc20Approval.d.ts +4 -4
- package/lib/cjs/actions/requirements/encode/encodeErc20Approval.js +4 -5
- package/lib/cjs/actions/requirements/encode/encodeErc20Permit.d.ts +5 -5
- package/lib/cjs/actions/requirements/encode/encodeErc20Permit.js +6 -11
- package/lib/cjs/actions/requirements/encode/index.d.ts +0 -1
- package/lib/cjs/actions/requirements/encode/index.js +0 -1
- package/lib/cjs/actions/requirements/getRequirementsApproval.d.ts +5 -6
- package/lib/cjs/actions/requirements/getRequirementsApproval.js +5 -6
- package/lib/cjs/actions/requirements/index.d.ts +0 -1
- package/lib/cjs/actions/requirements/index.js +0 -1
- package/lib/cjs/actions/vaultV1/deposit.d.ts +1 -2
- package/lib/cjs/actions/vaultV1/deposit.js +1 -2
- package/lib/cjs/actions/vaultV1/inKindRedeem.d.ts +6 -5
- package/lib/cjs/actions/vaultV1/inKindRedeem.js +10 -7
- package/lib/cjs/actions/vaultV2/deposit.d.ts +1 -2
- package/lib/cjs/actions/vaultV2/deposit.js +1 -2
- package/lib/cjs/actions/vaultV2/forceWithdraw.d.ts +1 -1
- package/lib/cjs/actions/vaultV2/forceWithdraw.js +3 -3
- package/lib/cjs/actions/vaultV2/inKindRedeem.d.ts +6 -5
- package/lib/cjs/actions/vaultV2/inKindRedeem.js +10 -7
- package/lib/cjs/augment.d.ts +0 -1
- package/lib/cjs/augment.js +0 -1
- package/lib/cjs/blue/abis.d.ts +1 -5
- package/lib/cjs/blue/abis.js +1 -7
- package/lib/cjs/blue/entities.d.ts +2 -8
- package/lib/cjs/blue/entities.js +1 -3
- package/lib/cjs/blue/fetch.d.ts +1 -3
- package/lib/cjs/blue/fetch.js +1 -3
- package/lib/cjs/blue/types.d.ts +2 -4
- package/lib/cjs/blue/utils.d.ts +1 -3
- package/lib/cjs/blue/utils.js +1 -3
- package/lib/cjs/client/morphoViemExtension.d.ts +1 -1
- package/lib/cjs/client/morphoViemExtension.js +1 -1
- package/lib/cjs/constants.d.ts +3 -37
- package/lib/cjs/constants.js +1 -39
- package/lib/cjs/entities/blue/blue.d.ts +30 -265
- package/lib/cjs/entities/blue/blue.js +1 -205
- package/lib/cjs/entities/index.d.ts +3 -66
- package/lib/cjs/entities/index.js +1 -21
- package/lib/cjs/entities/vaultV1/vaultV1.d.ts +9 -2
- package/lib/cjs/entities/vaultV1/vaultV1.js +12 -7
- package/lib/cjs/entities/vaultV2/vaultV2.d.ts +22 -9
- package/lib/cjs/entities/vaultV2/vaultV2.js +28 -15
- package/lib/cjs/entities/vaultV2BlueReallocationData.js +4 -21
- package/lib/cjs/errors.d.ts +2 -46
- package/lib/cjs/errors.js +1 -46
- package/lib/cjs/fetch.d.ts +1 -17
- package/lib/cjs/fetch.js +1 -17
- package/lib/cjs/helpers/constant.d.ts +0 -2
- package/lib/cjs/helpers/constant.js +0 -2
- package/lib/cjs/helpers/index.d.ts +2 -3
- package/lib/cjs/helpers/index.js +1 -9
- package/lib/cjs/helpers/slippage.d.ts +1 -103
- package/lib/cjs/helpers/slippage.js +0 -150
- package/lib/cjs/helpers/utilization.d.ts +12 -10
- package/lib/cjs/helpers/utilization.js +27 -12
- package/lib/cjs/helpers/validate.d.ts +1 -24
- package/lib/cjs/helpers/validate.js +2 -49
- package/lib/cjs/helpers/validateRequirementSpender.d.ts +1 -1
- package/lib/cjs/helpers/validateRequirementSpender.js +1 -3
- package/lib/cjs/types/action.d.ts +17 -65
- package/lib/cjs/types/action.js +11 -4
- package/lib/cjs/types/error.d.ts +50 -381
- package/lib/cjs/types/error.js +64 -395
- package/lib/cjs/types/sharedLiquidity.d.ts +1 -117
- package/lib/cjs/types.d.ts +2 -18
- package/lib/cjs/utils.d.ts +6 -35
- package/lib/cjs/utils.js +2 -36
- package/lib/esm/abis.d.ts +3 -2844
- package/lib/esm/abis.js +3 -1950
- package/lib/esm/actions/blue/borrow.d.ts +3 -2
- package/lib/esm/actions/blue/borrow.js +3 -2
- package/lib/esm/actions/blue/common.js +1 -9
- package/lib/esm/actions/blue/refinance.d.ts +2 -2
- package/lib/esm/actions/blue/refinance.js +2 -2
- package/lib/esm/actions/blue/repay.d.ts +1 -1
- package/lib/esm/actions/blue/repay.js +1 -1
- package/lib/esm/actions/blue/repayWithdrawCollateral.d.ts +2 -2
- package/lib/esm/actions/blue/repayWithdrawCollateral.js +2 -2
- package/lib/esm/actions/blue/supply.d.ts +2 -2
- package/lib/esm/actions/blue/supply.js +2 -2
- package/lib/esm/actions/blue/supplyCollateral.d.ts +2 -2
- package/lib/esm/actions/blue/supplyCollateral.js +2 -2
- package/lib/esm/actions/blue/supplyCollateralBorrow.d.ts +3 -2
- package/lib/esm/actions/blue/supplyCollateralBorrow.js +3 -2
- package/lib/esm/actions/blue/withdraw.d.ts +3 -3
- package/lib/esm/actions/blue/withdraw.js +3 -3
- package/lib/esm/actions/blue/withdrawCollateral.d.ts +2 -2
- package/lib/esm/actions/blue/withdrawCollateral.js +2 -2
- package/lib/esm/actions/bundles/common.d.ts +6 -2
- package/lib/esm/actions/bundles/common.js +24 -6
- package/lib/esm/actions/index.d.ts +0 -1
- package/lib/esm/actions/index.js +0 -1
- package/lib/esm/actions/requirements/blue/getBlueAuthorizationRequirement.d.ts +6 -8
- package/lib/esm/actions/requirements/blue/getBlueAuthorizationRequirement.js +12 -17
- package/lib/esm/actions/requirements/encode/encodeBlueSignatureAuthorization.d.ts +5 -6
- package/lib/esm/actions/requirements/encode/encodeBlueSignatureAuthorization.js +4 -5
- package/lib/esm/actions/requirements/encode/encodeErc20Approval.d.ts +4 -4
- package/lib/esm/actions/requirements/encode/encodeErc20Approval.js +4 -5
- package/lib/esm/actions/requirements/encode/encodeErc20Permit.d.ts +5 -5
- package/lib/esm/actions/requirements/encode/encodeErc20Permit.js +6 -11
- package/lib/esm/actions/requirements/encode/index.d.ts +0 -1
- package/lib/esm/actions/requirements/encode/index.js +0 -1
- package/lib/esm/actions/requirements/getRequirementsApproval.d.ts +5 -6
- package/lib/esm/actions/requirements/getRequirementsApproval.js +5 -6
- package/lib/esm/actions/requirements/index.d.ts +0 -1
- package/lib/esm/actions/requirements/index.js +0 -1
- package/lib/esm/actions/vaultV1/deposit.d.ts +1 -2
- package/lib/esm/actions/vaultV1/deposit.js +1 -2
- package/lib/esm/actions/vaultV1/inKindRedeem.d.ts +6 -5
- package/lib/esm/actions/vaultV1/inKindRedeem.js +10 -7
- package/lib/esm/actions/vaultV2/deposit.d.ts +1 -2
- package/lib/esm/actions/vaultV2/deposit.js +1 -2
- package/lib/esm/actions/vaultV2/forceWithdraw.d.ts +1 -1
- package/lib/esm/actions/vaultV2/forceWithdraw.js +3 -3
- package/lib/esm/actions/vaultV2/inKindRedeem.d.ts +6 -5
- package/lib/esm/actions/vaultV2/inKindRedeem.js +10 -7
- package/lib/esm/augment.d.ts +0 -1
- package/lib/esm/augment.js +0 -1
- package/lib/esm/blue/abis.d.ts +1 -5
- package/lib/esm/blue/abis.js +1 -5
- package/lib/esm/blue/entities.d.ts +2 -8
- package/lib/esm/blue/entities.js +1 -3
- package/lib/esm/blue/fetch.d.ts +1 -3
- package/lib/esm/blue/fetch.js +1 -3
- package/lib/esm/blue/types.d.ts +2 -4
- package/lib/esm/blue/utils.d.ts +1 -3
- package/lib/esm/blue/utils.js +1 -3
- package/lib/esm/client/morphoViemExtension.d.ts +1 -1
- package/lib/esm/client/morphoViemExtension.js +1 -1
- package/lib/esm/constants.d.ts +3 -37
- package/lib/esm/constants.js +3 -37
- package/lib/esm/entities/blue/blue.d.ts +30 -265
- package/lib/esm/entities/blue/blue.js +4 -208
- package/lib/esm/entities/index.d.ts +3 -66
- package/lib/esm/entities/index.js +1 -18
- package/lib/esm/entities/vaultV1/vaultV1.d.ts +9 -2
- package/lib/esm/entities/vaultV1/vaultV1.js +15 -10
- package/lib/esm/entities/vaultV2/vaultV2.d.ts +22 -9
- package/lib/esm/entities/vaultV2/vaultV2.js +32 -19
- package/lib/esm/entities/vaultV2BlueReallocationData.js +2 -19
- package/lib/esm/errors.d.ts +2 -46
- package/lib/esm/errors.js +2 -46
- package/lib/esm/fetch.d.ts +1 -17
- package/lib/esm/fetch.js +1 -17
- package/lib/esm/helpers/constant.d.ts +0 -2
- package/lib/esm/helpers/constant.js +0 -2
- package/lib/esm/helpers/index.d.ts +2 -3
- package/lib/esm/helpers/index.js +2 -3
- package/lib/esm/helpers/slippage.d.ts +1 -103
- package/lib/esm/helpers/slippage.js +1 -147
- package/lib/esm/helpers/utilization.d.ts +12 -10
- package/lib/esm/helpers/utilization.js +26 -11
- package/lib/esm/helpers/validate.d.ts +1 -24
- package/lib/esm/helpers/validate.js +2 -48
- package/lib/esm/helpers/validateRequirementSpender.d.ts +1 -1
- package/lib/esm/helpers/validateRequirementSpender.js +1 -3
- package/lib/esm/types/action.d.ts +17 -65
- package/lib/esm/types/action.js +12 -5
- package/lib/esm/types/error.d.ts +50 -381
- package/lib/esm/types/error.js +58 -377
- package/lib/esm/types/sharedLiquidity.d.ts +1 -117
- package/lib/esm/types.d.ts +2 -18
- package/lib/esm/utils.d.ts +6 -35
- package/lib/esm/utils.js +5 -34
- package/package.json +5 -13
- package/lib/cjs/actions/requirements/encode/encodeErc20Permit2Approve.d.ts +0 -44
- package/lib/cjs/actions/requirements/encode/encodeErc20Permit2Approve.js +0 -88
- package/lib/cjs/actions/requirements/generalAdapter/getGeneralAdapterRequirements.d.ts +0 -88
- package/lib/cjs/actions/requirements/generalAdapter/getGeneralAdapterRequirements.js +0 -152
- package/lib/cjs/actions/requirements/generalAdapter/getGeneralAdapterRequirementsPermit.d.ts +0 -40
- package/lib/cjs/actions/requirements/generalAdapter/getGeneralAdapterRequirementsPermit.js +0 -53
- package/lib/cjs/actions/requirements/generalAdapter/getGeneralAdapterRequirementsPermit2.d.ts +0 -57
- package/lib/cjs/actions/requirements/generalAdapter/getGeneralAdapterRequirementsPermit2.js +0 -74
- package/lib/cjs/actions/requirements/generalAdapter/index.d.ts +0 -3
- package/lib/cjs/actions/requirements/generalAdapter/index.js +0 -19
- package/lib/cjs/actions/signatures/getBlueAuthorizationAction.d.ts +0 -29
- package/lib/cjs/actions/signatures/getBlueAuthorizationAction.js +0 -48
- package/lib/cjs/actions/signatures/getTokenRequirementActions.d.ts +0 -58
- package/lib/cjs/actions/signatures/getTokenRequirementActions.js +0 -119
- package/lib/cjs/actions/signatures/getVaultExitBundlesV1PermitStruct.d.ts +0 -50
- package/lib/cjs/actions/signatures/getVaultExitBundlesV1PermitStruct.js +0 -45
- package/lib/cjs/actions/signatures/index.d.ts +0 -3
- package/lib/cjs/actions/signatures/index.js +0 -19
- package/lib/cjs/augment/VaultMarketPublicAllocatorConfig.d.ts +0 -11
- package/lib/cjs/augment/VaultMarketPublicAllocatorConfig.js +0 -8
- package/lib/cjs/bundler/actions.d.ts +0 -797
- package/lib/cjs/bundler/actions.js +0 -1371
- package/lib/cjs/bundler/index.d.ts +0 -2
- package/lib/cjs/bundler/index.js +0 -18
- package/lib/cjs/bundler/types.d.ts +0 -235
- package/lib/cjs/bundler/types.js +0 -2
- package/lib/cjs/entities/vaultV1ReallocationData.d.ts +0 -332
- package/lib/cjs/entities/vaultV1ReallocationData.js +0 -557
- package/lib/cjs/helpers/computeVaultV1Reallocations.d.ts +0 -80
- package/lib/cjs/helpers/computeVaultV1Reallocations.js +0 -245
- package/lib/esm/actions/requirements/encode/encodeErc20Permit2Approve.d.ts +0 -44
- package/lib/esm/actions/requirements/encode/encodeErc20Permit2Approve.js +0 -84
- package/lib/esm/actions/requirements/generalAdapter/getGeneralAdapterRequirements.d.ts +0 -88
- package/lib/esm/actions/requirements/generalAdapter/getGeneralAdapterRequirements.js +0 -148
- package/lib/esm/actions/requirements/generalAdapter/getGeneralAdapterRequirementsPermit.d.ts +0 -40
- package/lib/esm/actions/requirements/generalAdapter/getGeneralAdapterRequirementsPermit.js +0 -49
- package/lib/esm/actions/requirements/generalAdapter/getGeneralAdapterRequirementsPermit2.d.ts +0 -57
- package/lib/esm/actions/requirements/generalAdapter/getGeneralAdapterRequirementsPermit2.js +0 -70
- package/lib/esm/actions/requirements/generalAdapter/index.d.ts +0 -3
- package/lib/esm/actions/requirements/generalAdapter/index.js +0 -3
- package/lib/esm/actions/signatures/getBlueAuthorizationAction.d.ts +0 -29
- package/lib/esm/actions/signatures/getBlueAuthorizationAction.js +0 -44
- package/lib/esm/actions/signatures/getTokenRequirementActions.d.ts +0 -58
- package/lib/esm/actions/signatures/getTokenRequirementActions.js +0 -115
- package/lib/esm/actions/signatures/getVaultExitBundlesV1PermitStruct.d.ts +0 -50
- package/lib/esm/actions/signatures/getVaultExitBundlesV1PermitStruct.js +0 -41
- package/lib/esm/actions/signatures/index.d.ts +0 -3
- package/lib/esm/actions/signatures/index.js +0 -3
- package/lib/esm/augment/VaultMarketPublicAllocatorConfig.d.ts +0 -11
- package/lib/esm/augment/VaultMarketPublicAllocatorConfig.js +0 -7
- package/lib/esm/bundler/actions.d.ts +0 -797
- package/lib/esm/bundler/actions.js +0 -1368
- package/lib/esm/bundler/index.d.ts +0 -2
- package/lib/esm/bundler/index.js +0 -2
- package/lib/esm/bundler/types.d.ts +0 -235
- package/lib/esm/bundler/types.js +0 -1
- package/lib/esm/entities/vaultV1ReallocationData.d.ts +0 -332
- package/lib/esm/entities/vaultV1ReallocationData.js +0 -559
- package/lib/esm/helpers/computeVaultV1Reallocations.d.ts +0 -80
- package/lib/esm/helpers/computeVaultV1Reallocations.js +0 -241
|
@@ -1,111 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.computeVaultMaxShareAllowance = exports.computeVaultMaxSharePrice = void 0;
|
|
4
|
-
exports.computeMinBorrowSharePrice = computeMinBorrowSharePrice;
|
|
5
|
-
exports.computeMaxRepaySharePrice = computeMaxRepaySharePrice;
|
|
6
|
-
exports.computeMaxSupplySharePrice = computeMaxSupplySharePrice;
|
|
7
4
|
exports.computeMinForceWithdrawSharePrice = computeMinForceWithdrawSharePrice;
|
|
8
|
-
exports.computeMinWithdrawSharePrice = computeMinWithdrawSharePrice;
|
|
9
5
|
const blue_sdk_1 = require("@morpho-org/blue-sdk");
|
|
10
6
|
const index_js_1 = require("../types/index.js");
|
|
11
7
|
const constant_js_1 = require("./constant.js");
|
|
12
8
|
const validate_js_1 = require("./validate.js");
|
|
13
|
-
/**
|
|
14
|
-
* Computes the minimum borrow share price (in RAY, 1e27) for slippage protection.
|
|
15
|
-
*
|
|
16
|
-
* Mirrors the on-chain check in GeneralAdapter1's `morphoBorrow`:
|
|
17
|
-
* ```solidity
|
|
18
|
-
* require(borrowedAssets.rDivDown(borrowedShares) >= minSharePriceE27)
|
|
19
|
-
* ```
|
|
20
|
-
*
|
|
21
|
-
* @param params - Computation parameters.
|
|
22
|
-
* @param params.borrowAmount - The amount of assets to borrow.
|
|
23
|
-
* @param params.market - The market to compute the minimum borrow share price for.
|
|
24
|
-
* @param params.slippageTolerance - Slippage tolerance in WAD (e.g. 0.003e18 = 0.3%).
|
|
25
|
-
* @returns minSharePriceE27 in RAY scale (1e27).
|
|
26
|
-
*/
|
|
27
|
-
function computeMinBorrowSharePrice(params) {
|
|
28
|
-
const { borrowAmount, market, slippageTolerance } = params;
|
|
29
|
-
if (slippageTolerance >= blue_sdk_1.MathLib.WAD) {
|
|
30
|
-
throw new index_js_1.ExcessiveSlippageToleranceError(slippageTolerance);
|
|
31
|
-
}
|
|
32
|
-
const expectedShares = market.toBorrowShares(borrowAmount, "Up");
|
|
33
|
-
if (expectedShares === 0n) {
|
|
34
|
-
throw new index_js_1.ShareDivideByZeroError(market.params.id);
|
|
35
|
-
}
|
|
36
|
-
return blue_sdk_1.MathLib.mulDivDown(borrowAmount, blue_sdk_1.MathLib.wToRay(blue_sdk_1.MathLib.WAD - slippageTolerance), expectedShares);
|
|
37
|
-
}
|
|
38
|
-
/**
|
|
39
|
-
* Computes the maximum repay share price (in RAY, 1e27) for slippage protection.
|
|
40
|
-
*
|
|
41
|
-
* Supports both repay-by-assets and repay-by-shares paths:
|
|
42
|
-
* - By assets: derives expected shares from the repay amount via `toBorrowShares("Down")`.
|
|
43
|
-
* - By shares: derives expected assets from the shares via `toBorrowAssets("Up")`.
|
|
44
|
-
*
|
|
45
|
-
* Direction is opposite of borrow's `minSharePrice`:
|
|
46
|
-
* - Borrow uses `(WAD - slippage)` → lower bound (protects borrower from getting fewer assets per share).
|
|
47
|
-
* - Repay uses `(WAD + slippage)` → upper bound (protects repayer from paying too many assets per share).
|
|
48
|
-
*
|
|
49
|
-
* Capped at {@link MAX_ABSOLUTE_SHARE_PRICE} to prevent absurd values.
|
|
50
|
-
*
|
|
51
|
-
* @param params - Computation parameters.
|
|
52
|
-
* @param params.repayAssets - The amount of assets to repay (0n when repaying by shares).
|
|
53
|
-
* @param params.repayShares - The amount of shares to repay (0n when repaying by assets).
|
|
54
|
-
* @param params.market - The market to compute the maximum repay share price for.
|
|
55
|
-
* @param params.slippageTolerance - Slippage tolerance in WAD (e.g. 0.003e18 = 0.3%).
|
|
56
|
-
* @returns maxSharePriceE27 in RAY scale (1e27).
|
|
57
|
-
*/
|
|
58
|
-
function computeMaxRepaySharePrice(params) {
|
|
59
|
-
const { repayAssets, repayShares, market, slippageTolerance } = params;
|
|
60
|
-
if (slippageTolerance >= blue_sdk_1.MathLib.WAD) {
|
|
61
|
-
throw new index_js_1.ExcessiveSlippageToleranceError(slippageTolerance);
|
|
62
|
-
}
|
|
63
|
-
let assets;
|
|
64
|
-
let shares;
|
|
65
|
-
if (repayShares > 0n) {
|
|
66
|
-
assets = market.toBorrowAssets(repayShares, "Up");
|
|
67
|
-
shares = repayShares;
|
|
68
|
-
}
|
|
69
|
-
else {
|
|
70
|
-
assets = repayAssets;
|
|
71
|
-
shares = market.toBorrowShares(repayAssets, "Down");
|
|
72
|
-
}
|
|
73
|
-
if (shares === 0n) {
|
|
74
|
-
throw new index_js_1.ShareDivideByZeroError(market.params.id);
|
|
75
|
-
}
|
|
76
|
-
const maxSharePrice = blue_sdk_1.MathLib.mulDivUp(assets, blue_sdk_1.MathLib.wToRay(blue_sdk_1.MathLib.WAD + slippageTolerance), shares);
|
|
77
|
-
return blue_sdk_1.MathLib.min(maxSharePrice, constant_js_1.MAX_ABSOLUTE_SHARE_PRICE);
|
|
78
|
-
}
|
|
79
|
-
/**
|
|
80
|
-
* Computes the maximum supply share price (in RAY, 1e27) for slippage protection.
|
|
81
|
-
*
|
|
82
|
-
* Mirrors the on-chain check in GeneralAdapter1's `morphoSupply`:
|
|
83
|
-
* ```solidity
|
|
84
|
-
* require(suppliedAssets.rDivUp(suppliedShares) <= maxSharePriceE27)
|
|
85
|
-
* ```
|
|
86
|
-
*
|
|
87
|
-
* Caps at {@link MAX_ABSOLUTE_SHARE_PRICE} to prevent absurd values on extreme markets.
|
|
88
|
-
*
|
|
89
|
-
* @param params - Computation parameters.
|
|
90
|
-
* @param params.supplyAssets - The amount of loan assets to supply.
|
|
91
|
-
* @param params.market - The market to compute the maximum supply share price for.
|
|
92
|
-
* @param params.slippageTolerance - Slippage tolerance in WAD (e.g. `0.003e18` = 0.3%).
|
|
93
|
-
* @returns `maxSharePriceE27` in RAY scale (1e27).
|
|
94
|
-
* @throws {ExcessiveSlippageToleranceError} when `slippageTolerance >= WAD`.
|
|
95
|
-
* @throws {ShareDivideByZeroError} when expected shares round down to zero.
|
|
96
|
-
*/
|
|
97
|
-
function computeMaxSupplySharePrice(params) {
|
|
98
|
-
const { supplyAssets, market, slippageTolerance } = params;
|
|
99
|
-
if (slippageTolerance >= blue_sdk_1.MathLib.WAD) {
|
|
100
|
-
throw new index_js_1.ExcessiveSlippageToleranceError(slippageTolerance);
|
|
101
|
-
}
|
|
102
|
-
const expectedShares = market.toSupplyShares(supplyAssets, "Down");
|
|
103
|
-
if (expectedShares === 0n) {
|
|
104
|
-
throw new index_js_1.ShareDivideByZeroError(market.params.id);
|
|
105
|
-
}
|
|
106
|
-
const maxSharePrice = blue_sdk_1.MathLib.mulDivUp(supplyAssets, blue_sdk_1.MathLib.wToRay(blue_sdk_1.MathLib.WAD + slippageTolerance), expectedShares);
|
|
107
|
-
return blue_sdk_1.MathLib.min(maxSharePrice, constant_js_1.MAX_ABSOLUTE_SHARE_PRICE);
|
|
108
|
-
}
|
|
109
9
|
/**
|
|
110
10
|
* Computes the minimum Vault V2 force-withdraw share price (in RAY, 1e27) for slippage protection.
|
|
111
11
|
*
|
|
@@ -170,56 +70,6 @@ function computeMinForceWithdrawSharePrice(params) {
|
|
|
170
70
|
}
|
|
171
71
|
return minSharePriceE27;
|
|
172
72
|
}
|
|
173
|
-
/**
|
|
174
|
-
* Computes the minimum withdraw share price (in RAY, 1e27) for slippage protection.
|
|
175
|
-
*
|
|
176
|
-
* Mirrors the on-chain check in GeneralAdapter1's `morphoWithdraw`:
|
|
177
|
-
* ```solidity
|
|
178
|
-
* require(withdrawnAssets.rDivDown(withdrawnShares) >= minSharePriceE27)
|
|
179
|
-
* ```
|
|
180
|
-
*
|
|
181
|
-
* Supports both assets and shares modes:
|
|
182
|
-
* - By assets: derives expected shares via `toSupplyShares("Up")` (upper bound, protects the
|
|
183
|
-
* withdrawer against over-burning shares).
|
|
184
|
-
* - By shares: derives expected assets via `toSupplyAssets("Down")` (lower bound, the on-chain
|
|
185
|
-
* amount paid out).
|
|
186
|
-
*
|
|
187
|
-
* Direction is opposite of supply's `maxSharePrice`:
|
|
188
|
-
* - Supply uses `(WAD + slippage)` → upper bound (anti-inflation).
|
|
189
|
-
* - Withdraw uses `(WAD − slippage)` → lower bound (protects withdrawer from receiving too few
|
|
190
|
-
* assets per share burned).
|
|
191
|
-
*
|
|
192
|
-
* @param params - Computation parameters.
|
|
193
|
-
* @param params.withdrawAssets - The amount of assets to withdraw (`0n` when withdrawing by shares).
|
|
194
|
-
* @param params.withdrawShares - The amount of shares to withdraw (`0n` when withdrawing by assets).
|
|
195
|
-
* @param params.market - The market to compute the minimum withdraw share price for.
|
|
196
|
-
* @param params.slippageTolerance - Slippage tolerance in WAD (e.g. `0.003e18` = 0.3%).
|
|
197
|
-
* @returns `minSharePriceE27` in RAY scale (1e27).
|
|
198
|
-
* @throws {ExcessiveSlippageToleranceError} when `slippageTolerance >= WAD`.
|
|
199
|
-
* @throws {ShareDivideByZeroError} when expected shares round down to zero.
|
|
200
|
-
*/
|
|
201
|
-
function computeMinWithdrawSharePrice(params) {
|
|
202
|
-
const { withdrawAssets, withdrawShares, market, slippageTolerance } = params;
|
|
203
|
-
if (slippageTolerance >= blue_sdk_1.MathLib.WAD) {
|
|
204
|
-
throw new index_js_1.ExcessiveSlippageToleranceError(slippageTolerance);
|
|
205
|
-
}
|
|
206
|
-
let assets;
|
|
207
|
-
let shares;
|
|
208
|
-
if (withdrawShares > 0n) {
|
|
209
|
-
assets = market.toSupplyAssets(withdrawShares, "Down");
|
|
210
|
-
shares = withdrawShares;
|
|
211
|
-
}
|
|
212
|
-
else {
|
|
213
|
-
assets = withdrawAssets;
|
|
214
|
-
shares = market.toSupplyShares(withdrawAssets, "Up");
|
|
215
|
-
}
|
|
216
|
-
// Dust shares can round to `assets === 0n` here, which would make
|
|
217
|
-
// `minSharePriceE27 = 0` and silently nullify the on-chain slippage cap.
|
|
218
|
-
if (shares === 0n || assets === 0n) {
|
|
219
|
-
throw new index_js_1.ShareDivideByZeroError(market.params.id);
|
|
220
|
-
}
|
|
221
|
-
return blue_sdk_1.MathLib.mulDivDown(assets, blue_sdk_1.MathLib.wToRay(blue_sdk_1.MathLib.WAD - slippageTolerance), shares);
|
|
222
|
-
}
|
|
223
73
|
/**
|
|
224
74
|
* Computes the RAY-scaled maximum share price for a VaultBundlesV1 deposit leg.
|
|
225
75
|
*
|
|
@@ -1,12 +1,14 @@
|
|
|
1
|
-
import type { MarketId } from "@morpho-org/blue-sdk";
|
|
2
|
-
import type { ReallocationComputeOptions } from "../types/index.js";
|
|
3
1
|
/**
|
|
4
|
-
* Resolves
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
* @
|
|
9
|
-
* @
|
|
10
|
-
* @
|
|
2
|
+
* Resolves and validates a source withdrawal utilization ceiling.
|
|
3
|
+
* @internal
|
|
4
|
+
* @param value - Optional WAD-scaled utilization ceiling.
|
|
5
|
+
* @param field - Option name reported in validation errors.
|
|
6
|
+
* @returns A ceiling between zero and WAD, defaulting to the shared withdrawal target.
|
|
7
|
+
* @throws {NegativeInputError} when the ceiling is negative.
|
|
8
|
+
* @throws {InputExceedsMaxError} when the ceiling exceeds WAD.
|
|
9
|
+
* @example
|
|
10
|
+
* ```ts
|
|
11
|
+
* const ceiling = resolveMaxWithdrawalUtilization(undefined);
|
|
12
|
+
* ```
|
|
11
13
|
*/
|
|
12
|
-
export declare const
|
|
14
|
+
export declare const resolveMaxWithdrawalUtilization: (value: bigint | undefined, field?: "maxWithdrawalUtilization" | "defaultMaxWithdrawalUtilization") => bigint;
|
|
@@ -1,17 +1,32 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.resolveMaxWithdrawalUtilization = void 0;
|
|
4
|
+
const blue_sdk_1 = require("@morpho-org/blue-sdk");
|
|
5
|
+
const index_js_1 = require("../types/index.js");
|
|
4
6
|
const constant_js_1 = require("./constant.js");
|
|
5
7
|
/**
|
|
6
|
-
* Resolves
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
* @
|
|
11
|
-
* @
|
|
12
|
-
* @
|
|
8
|
+
* Resolves and validates a source withdrawal utilization ceiling.
|
|
9
|
+
* @internal
|
|
10
|
+
* @param value - Optional WAD-scaled utilization ceiling.
|
|
11
|
+
* @param field - Option name reported in validation errors.
|
|
12
|
+
* @returns A ceiling between zero and WAD, defaulting to the shared withdrawal target.
|
|
13
|
+
* @throws {NegativeInputError} when the ceiling is negative.
|
|
14
|
+
* @throws {InputExceedsMaxError} when the ceiling exceeds WAD.
|
|
15
|
+
* @example
|
|
16
|
+
* ```ts
|
|
17
|
+
* const ceiling = resolveMaxWithdrawalUtilization(undefined);
|
|
18
|
+
* ```
|
|
13
19
|
*/
|
|
14
|
-
const
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
20
|
+
const resolveMaxWithdrawalUtilization = (value, field = "maxWithdrawalUtilization") => {
|
|
21
|
+
const utilization = value ?? constant_js_1.DEFAULT_WITHDRAWAL_TARGET_UTILIZATION;
|
|
22
|
+
if (utilization < 0n)
|
|
23
|
+
throw new index_js_1.NegativeInputError(field, utilization);
|
|
24
|
+
if (utilization > blue_sdk_1.MathLib.WAD)
|
|
25
|
+
throw new index_js_1.InputExceedsMaxError({
|
|
26
|
+
field,
|
|
27
|
+
value: utilization,
|
|
28
|
+
max: blue_sdk_1.MathLib.WAD,
|
|
29
|
+
});
|
|
30
|
+
return utilization;
|
|
31
|
+
};
|
|
32
|
+
exports.resolveMaxWithdrawalUtilization = resolveMaxWithdrawalUtilization;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { type AccrualPosition, type MarketId } from "@morpho-org/blue-sdk";
|
|
2
2
|
import type { MarketInput as MidnightMarketInput } from "@morpho-org/midnight-sdk";
|
|
3
3
|
import { type Address } from "viem";
|
|
4
|
-
import { type
|
|
4
|
+
import { type VaultV2BlueReallocation } from "../types/index.js";
|
|
5
5
|
/** @internal */
|
|
6
6
|
export declare const compareMarketIds: (idA: MarketId, idB: MarketId) => -1 | 0 | 1;
|
|
7
7
|
/**
|
|
@@ -209,29 +209,6 @@ export declare const validateRepayShares: (params: {
|
|
|
209
209
|
repayShares: bigint;
|
|
210
210
|
marketId: MarketId;
|
|
211
211
|
}) => void;
|
|
212
|
-
/**
|
|
213
|
-
* Validates that Vault V1 PublicAllocator reallocations are well-formed.
|
|
214
|
-
*
|
|
215
|
-
* @param reallocations - Vault V1 reallocations to validate.
|
|
216
|
-
* @param targetMarketId - The operation's target market ID.
|
|
217
|
-
* @returns Nothing when every reallocation is valid.
|
|
218
|
-
* @throws {NegativeInputError} when a reallocation fee is negative.
|
|
219
|
-
* @throws {EmptyReallocationWithdrawalsError} when a reallocation has no withdrawals.
|
|
220
|
-
* @throws {NonPositiveInputError} when a withdrawal amount is non-positive.
|
|
221
|
-
* @throws {ReallocationWithdrawalOnTargetMarketError} when a withdrawal references the target market.
|
|
222
|
-
* @throws {UnsortedReallocationWithdrawalsError} when withdrawals are not strictly market-id sorted.
|
|
223
|
-
* @deprecated Vault V1 PublicAllocator validation will be removed in the next major. Use Vault V2
|
|
224
|
-
* reallocations for new integrations.
|
|
225
|
-
* @example
|
|
226
|
-
* ```ts
|
|
227
|
-
* import type { BlueMarketId } from "@morpho-org/morpho-sdk/types";
|
|
228
|
-
* import { validateReallocations } from "@morpho-org/morpho-sdk";
|
|
229
|
-
* import { zeroHash } from "viem";
|
|
230
|
-
*
|
|
231
|
-
* const result: void = validateReallocations([], zeroHash as BlueMarketId);
|
|
232
|
-
* ```
|
|
233
|
-
*/
|
|
234
|
-
export declare const validateReallocations: (reallocations: Iterable<VaultV1Reallocation>, targetMarketId: MarketId) => void;
|
|
235
212
|
/** @internal */
|
|
236
213
|
export declare const validateVaultV2BlueReallocations: (reallocations: Iterable<VaultV2BlueReallocation>, targetMarketId: MarketId) => void;
|
|
237
214
|
/**
|
|
@@ -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.
|
|
3
|
+
exports.validateWithdrawShares = exports.validateWithdrawAmount = exports.validateSlippageTolerance = exports.validateVaultV2BlueReallocations = exports.validateRepayShares = exports.validateRepayAmount = exports.validatePositionHealthAfterWithdraw = exports.validateNativeVaultAsset = exports.validateNativeAsset = exports.validateChainId = exports.validatePositionHealth = exports.validateAccrualPosition = exports.validateMidnightMarketChainId = exports.validateReferralFee = exports.validateDeadline = exports.validateUint256Field = exports.compareMarketIds = void 0;
|
|
4
4
|
exports.validateUserAddress = validateUserAddress;
|
|
5
5
|
const blue_sdk_1 = require("@morpho-org/blue-sdk");
|
|
6
6
|
const morpho_ts_1 = require("@morpho-org/morpho-ts");
|
|
@@ -335,53 +335,6 @@ const validateRepayShares = (params) => {
|
|
|
335
335
|
}
|
|
336
336
|
};
|
|
337
337
|
exports.validateRepayShares = validateRepayShares;
|
|
338
|
-
/**
|
|
339
|
-
* Validates that Vault V1 PublicAllocator reallocations are well-formed.
|
|
340
|
-
*
|
|
341
|
-
* @param reallocations - Vault V1 reallocations to validate.
|
|
342
|
-
* @param targetMarketId - The operation's target market ID.
|
|
343
|
-
* @returns Nothing when every reallocation is valid.
|
|
344
|
-
* @throws {NegativeInputError} when a reallocation fee is negative.
|
|
345
|
-
* @throws {EmptyReallocationWithdrawalsError} when a reallocation has no withdrawals.
|
|
346
|
-
* @throws {NonPositiveInputError} when a withdrawal amount is non-positive.
|
|
347
|
-
* @throws {ReallocationWithdrawalOnTargetMarketError} when a withdrawal references the target market.
|
|
348
|
-
* @throws {UnsortedReallocationWithdrawalsError} when withdrawals are not strictly market-id sorted.
|
|
349
|
-
* @deprecated Vault V1 PublicAllocator validation will be removed in the next major. Use Vault V2
|
|
350
|
-
* reallocations for new integrations.
|
|
351
|
-
* @example
|
|
352
|
-
* ```ts
|
|
353
|
-
* import type { BlueMarketId } from "@morpho-org/morpho-sdk/types";
|
|
354
|
-
* import { validateReallocations } from "@morpho-org/morpho-sdk";
|
|
355
|
-
* import { zeroHash } from "viem";
|
|
356
|
-
*
|
|
357
|
-
* const result: void = validateReallocations([], zeroHash as BlueMarketId);
|
|
358
|
-
* ```
|
|
359
|
-
*/
|
|
360
|
-
const validateReallocations = (reallocations, targetMarketId) => {
|
|
361
|
-
for (const reallocation of reallocations) {
|
|
362
|
-
if (reallocation.fee < 0n) {
|
|
363
|
-
throw new index_js_1.NegativeInputError("reallocation.fee", reallocation.fee);
|
|
364
|
-
}
|
|
365
|
-
if (reallocation.withdrawals.length === 0) {
|
|
366
|
-
throw new index_js_1.EmptyReallocationWithdrawalsError(reallocation.vault);
|
|
367
|
-
}
|
|
368
|
-
let previousMarketId;
|
|
369
|
-
for (const withdrawal of reallocation.withdrawals) {
|
|
370
|
-
if (withdrawal.amount <= 0n) {
|
|
371
|
-
throw new index_js_1.NonPositiveInputError(`reallocation.withdrawals[${withdrawal.marketParams.id}].amount`, withdrawal.amount);
|
|
372
|
-
}
|
|
373
|
-
if (withdrawal.marketParams.id === targetMarketId) {
|
|
374
|
-
throw new index_js_1.ReallocationWithdrawalOnTargetMarketError(reallocation.vault, withdrawal.marketParams.id);
|
|
375
|
-
}
|
|
376
|
-
if (previousMarketId !== undefined &&
|
|
377
|
-
(0, exports.compareMarketIds)(withdrawal.marketParams.id, previousMarketId) <= 0) {
|
|
378
|
-
throw new index_js_1.UnsortedReallocationWithdrawalsError(reallocation.vault, withdrawal.marketParams.id);
|
|
379
|
-
}
|
|
380
|
-
previousMarketId = withdrawal.marketParams.id;
|
|
381
|
-
}
|
|
382
|
-
}
|
|
383
|
-
};
|
|
384
|
-
exports.validateReallocations = validateReallocations;
|
|
385
338
|
/** @internal */
|
|
386
339
|
const validateVaultV2BlueReallocations = (reallocations, targetMarketId) => {
|
|
387
340
|
const penaltyByVault = new Map();
|
|
@@ -393,7 +346,7 @@ const validateVaultV2BlueReallocations = (reallocations, targetMarketId) => {
|
|
|
393
346
|
reallocation === null ||
|
|
394
347
|
"withdrawals" in reallocation ||
|
|
395
348
|
"fee" in reallocation) {
|
|
396
|
-
throw new index_js_1.
|
|
349
|
+
throw new index_js_1.InvalidVaultV2BlueReallocationShapeError();
|
|
397
350
|
}
|
|
398
351
|
if (typeof reallocation.vault !== "string" ||
|
|
399
352
|
!(0, viem_1.isAddress)(reallocation.vault)) {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { type Address } from "@morpho-org/blue-sdk";
|
|
2
2
|
/** Supported spender slots that can be validated against the chain address registry. */
|
|
3
|
-
export type RequirementSpenderKey = "
|
|
3
|
+
export type RequirementSpenderKey = "permit2" | "midnight" | "midnightBundles" | "vaultExitBundlesV1" | "vaultBundlesV1" | "blueBundlesV1";
|
|
4
4
|
/**
|
|
5
5
|
* Validates that a requirement encoder spender matches one of the allowed chain addresses.
|
|
6
6
|
*
|
|
@@ -27,9 +27,8 @@ const index_js_1 = require("../types/index.js");
|
|
|
27
27
|
* ```
|
|
28
28
|
*/
|
|
29
29
|
const validateRequirementSpender = (params) => {
|
|
30
|
-
const { permit2, midnight, midnightBundles,
|
|
30
|
+
const { permit2, midnight, midnightBundles, bundles } = (0, blue_sdk_1.getChainAddresses)(params.chainId);
|
|
31
31
|
const addresses = {
|
|
32
|
-
generalAdapter1,
|
|
33
32
|
permit2,
|
|
34
33
|
midnight,
|
|
35
34
|
midnightBundles,
|
|
@@ -42,7 +41,6 @@ const validateRequirementSpender = (params) => {
|
|
|
42
41
|
throw new index_js_1.UnsupportedErc20ApprovalSpenderError({
|
|
43
42
|
spender: params.spender,
|
|
44
43
|
chainId: params.chainId,
|
|
45
|
-
generalAdapter1,
|
|
46
44
|
permit2,
|
|
47
45
|
midnight,
|
|
48
46
|
midnightBundles,
|
|
@@ -417,20 +417,6 @@ export interface Transaction<TAction extends BaseAction = TransactionAction> {
|
|
|
417
417
|
readonly data: Hex;
|
|
418
418
|
readonly action: TAction;
|
|
419
419
|
}
|
|
420
|
-
/**
|
|
421
|
-
* Enforces that at least one deposit amount source is provided.
|
|
422
|
-
*
|
|
423
|
-
* - `amount` alone: standard ERC20 deposit.
|
|
424
|
-
* - `nativeAmount` alone: pure native-wrap deposit (vault asset must be wNative).
|
|
425
|
-
* - Both: mixed deposit (ERC20 transfer + native wrap).
|
|
426
|
-
*/
|
|
427
|
-
export type DepositAmountArgs = {
|
|
428
|
-
amount: bigint;
|
|
429
|
-
nativeAmount?: bigint;
|
|
430
|
-
} | {
|
|
431
|
-
nativeAmount: bigint;
|
|
432
|
-
amount?: bigint;
|
|
433
|
-
};
|
|
434
420
|
/** Mutually exclusive ERC-20 or native funding accepted by fixed bundles entrypoints. */
|
|
435
421
|
export type BundlesFundingArgs = {
|
|
436
422
|
readonly amount: bigint;
|
|
@@ -458,8 +444,7 @@ export type VaultV1MigrateToV2AmountArgs = {
|
|
|
458
444
|
* Holds the pre-resolved arguments for an ERC-2612 `permit`: the signed approval
|
|
459
445
|
* of `amount` of `asset` from `owner` to the permitted spender, bounded by the
|
|
460
446
|
* `deadline` timestamp and consuming the given `nonce`. The associated
|
|
461
|
-
* {@link PermitAction} identifies the permitted
|
|
462
|
-
* contracts and the GeneralAdapter1 periphery.
|
|
447
|
+
* {@link PermitAction} identifies the permitted fixed-bundle contract.
|
|
463
448
|
*/
|
|
464
449
|
export interface PermitArgs {
|
|
465
450
|
readonly owner: Address;
|
|
@@ -469,25 +454,10 @@ export interface PermitArgs {
|
|
|
469
454
|
readonly amount: bigint;
|
|
470
455
|
readonly deadline: bigint;
|
|
471
456
|
}
|
|
472
|
-
/**
|
|
473
|
-
* Holds the pre-resolved arguments for a Permit2 `permit` bundler call. It
|
|
474
|
-
* mirrors {@link PermitArgs} but adds the Permit2 allowance `expiration` (when
|
|
475
|
-
* the on-chain allowance lapses) alongside the signature `deadline` (by when the
|
|
476
|
-
* signature must be submitted).
|
|
477
|
-
*/
|
|
478
|
-
export interface Permit2Args {
|
|
479
|
-
readonly owner: Address;
|
|
480
|
-
readonly nonce: bigint;
|
|
481
|
-
readonly asset: Address;
|
|
482
|
-
readonly signature: Hex;
|
|
483
|
-
readonly amount: bigint;
|
|
484
|
-
readonly deadline: bigint;
|
|
485
|
-
readonly expiration: bigint;
|
|
486
|
-
}
|
|
487
457
|
/**
|
|
488
458
|
* Signed Morpho Blue authorization payload produced when an integrator opts into offchain
|
|
489
|
-
* signatures (`supportSignature: true`).
|
|
490
|
-
*
|
|
459
|
+
* signatures (`supportSignature: true`). BlueBundlesV1 encodes it into its
|
|
460
|
+
* signed-authorization struct.
|
|
491
461
|
*/
|
|
492
462
|
export interface AuthorizationSignatureArgs {
|
|
493
463
|
/** Account granting the authorization (the position owner). */
|
|
@@ -527,15 +497,6 @@ export interface PermitAction extends BaseAction<"permit", {
|
|
|
527
497
|
*/
|
|
528
498
|
readonly typedData?: RequirementTypedData;
|
|
529
499
|
}
|
|
530
|
-
export interface Permit2Action extends BaseAction<"permit2", {
|
|
531
|
-
spender: Address;
|
|
532
|
-
amount: bigint;
|
|
533
|
-
deadline: bigint;
|
|
534
|
-
expiration: bigint;
|
|
535
|
-
}> {
|
|
536
|
-
/** EIP-712 payload to sign for this Permit2 AllowanceTransfer. See {@link PermitAction.typedData}. */
|
|
537
|
-
readonly typedData?: RequirementTypedData;
|
|
538
|
-
}
|
|
539
500
|
/** Signable Permit2 SignatureTransfer requirement for a fixed bundles token pull. */
|
|
540
501
|
export interface Permit2SignatureTransferAction extends BaseAction<"permit2SignatureTransfer", {
|
|
541
502
|
readonly spender: Address;
|
|
@@ -547,8 +508,7 @@ export interface Permit2SignatureTransferAction extends BaseAction<"permit2Signa
|
|
|
547
508
|
readonly typedData?: RequirementTypedData;
|
|
548
509
|
}
|
|
549
510
|
/**
|
|
550
|
-
* Signable Morpho authorization requirement
|
|
551
|
-
* GeneralAdapter1 for Bundler3 flows or BlueBundlesV1 for direct Blue writes.
|
|
511
|
+
* Signable Morpho authorization requirement for direct BlueBundlesV1 writes.
|
|
552
512
|
*/
|
|
553
513
|
export interface AuthorizationAction extends BaseAction<"authorization", {
|
|
554
514
|
authorized: Address;
|
|
@@ -575,27 +535,22 @@ export interface MidnightOfferRootSignatureAction extends BaseAction<"midnightOf
|
|
|
575
535
|
readonly typedData?: RequirementTypedData;
|
|
576
536
|
}
|
|
577
537
|
/** Action metadata supported by signature requirements. */
|
|
578
|
-
export type SignatureRequirementAction = PermitAction |
|
|
538
|
+
export type SignatureRequirementAction = PermitAction | Permit2SignatureTransferAction | AuthorizationAction | MidnightOfferRootSignatureAction;
|
|
579
539
|
/** Argument payloads returned by signature requirements. */
|
|
580
|
-
export type RequirementSignatureArgs = PermitArgs |
|
|
540
|
+
export type RequirementSignatureArgs = PermitArgs | AuthorizationSignatureArgs | MidnightOfferRootSignatureArgs;
|
|
581
541
|
/** A signed ERC-2612 permit requirement. */
|
|
582
542
|
export interface Erc2612RequirementSignature {
|
|
583
543
|
readonly args: Readonly<PermitArgs>;
|
|
584
544
|
readonly action: PermitAction;
|
|
585
545
|
}
|
|
586
|
-
/** A signed
|
|
587
|
-
export
|
|
588
|
-
readonly args: Readonly<Permit2Args>;
|
|
589
|
-
readonly action: Permit2Action;
|
|
590
|
-
}
|
|
591
|
-
/** A signed ERC-2612 permit or Permit2 AllowanceTransfer requirement. */
|
|
592
|
-
export type PermitRequirementSignature = Erc2612RequirementSignature | Permit2AllowanceRequirementSignature;
|
|
546
|
+
/** A signed ERC-2612 permit requirement accepted by vault-share bundle calls. */
|
|
547
|
+
export type PermitRequirementSignature = Erc2612RequirementSignature;
|
|
593
548
|
/** A signed Permit2 SignatureTransfer requirement used by fixed bundles contracts. */
|
|
594
549
|
export interface Permit2SignatureTransferRequirementSignature {
|
|
595
550
|
readonly args: Readonly<PermitArgs>;
|
|
596
551
|
readonly action: Permit2SignatureTransferAction;
|
|
597
552
|
}
|
|
598
|
-
/** A signed Morpho authorization consumed by
|
|
553
|
+
/** A signed Morpho authorization consumed by a direct BlueBundlesV1 call. */
|
|
599
554
|
export interface AuthorizationRequirementSignature {
|
|
600
555
|
readonly args: AuthorizationSignatureArgs;
|
|
601
556
|
readonly action: AuthorizationAction;
|
|
@@ -607,7 +562,7 @@ export interface MidnightOfferRootSignature {
|
|
|
607
562
|
}
|
|
608
563
|
/**
|
|
609
564
|
* The deep-frozen output of `Requirement.sign()`. Discriminated on `action.type`:
|
|
610
|
-
* `"permit"`
|
|
565
|
+
* `"permit"` carries token-approval args, `"permit2SignatureTransfer"` carries a
|
|
611
566
|
* bundles SignatureTransfer, `"authorization"` carries the signed Morpho authorization,
|
|
612
567
|
* and Midnight adds `"midnightOfferRootSignature"`.
|
|
613
568
|
*/
|
|
@@ -644,20 +599,16 @@ export interface Requirement<TSignatureOrAction extends RequirementSignature | S
|
|
|
644
599
|
readonly typedData: RequirementTypedData;
|
|
645
600
|
};
|
|
646
601
|
}
|
|
647
|
-
/** Bundler3 token signature requirement. */
|
|
648
|
-
export type Bundler3TokenSignatureRequirement = Requirement<PermitRequirementSignature>;
|
|
649
602
|
/** ERC-2612 or Permit2 SignatureTransfer requirement consumed by a fixed bundles contract. */
|
|
650
603
|
export type BundlesTokenSignatureRequirement = Requirement<BundlesTokenRequirementSignature>;
|
|
651
604
|
/** Midnight Ecrecover offer-root signature requirement. */
|
|
652
605
|
export type MidnightOfferRootRequirement = Requirement<MidnightOfferRootSignatureAction, MidnightOfferRootSignatureArgs>;
|
|
653
606
|
/** Any token signature requirement supported by an SDK transaction route. */
|
|
654
|
-
export type TokenSignatureRequirement =
|
|
655
|
-
/** Bundler3 token signature result. */
|
|
656
|
-
export type Bundler3TokenRequirementSignature = PermitRequirementSignature;
|
|
607
|
+
export type TokenSignatureRequirement = BundlesTokenSignatureRequirement;
|
|
657
608
|
/** Token signature result consumed by a fixed bundles contract. */
|
|
658
609
|
export type BundlesTokenRequirementSignature = Erc2612RequirementSignature | Permit2SignatureTransferRequirementSignature;
|
|
659
610
|
/** Any token signature result supported by an SDK transaction route. */
|
|
660
|
-
export type TokenRequirementSignature =
|
|
611
|
+
export type TokenRequirementSignature = BundlesTokenRequirementSignature;
|
|
661
612
|
/** Any signature result returned by an action-output signature requirement. */
|
|
662
613
|
export type AnyRequirementSignature = TokenRequirementSignature | AuthorizationRequirementSignature | MidnightOfferRootSignature;
|
|
663
614
|
/** Any signature requirement returned by an entity action output. */
|
|
@@ -689,10 +640,10 @@ export declare function isRequirementSignature<T extends RequirementSignature =
|
|
|
689
640
|
export declare function isRequirementSignature(requirement: CallRequirement | Requirement | undefined): requirement is Requirement;
|
|
690
641
|
export declare function isRequirementSignature(requirement: ActionRequirement | undefined): requirement is SignatureRequirement;
|
|
691
642
|
/**
|
|
692
|
-
* Narrows a {@link RequirementSignature} to
|
|
643
|
+
* Narrows a {@link RequirementSignature} to an ERC-2612 permit signature.
|
|
693
644
|
*
|
|
694
645
|
* @param signature - The signed requirement to test.
|
|
695
|
-
* @returns `true` when `signature.action.type` is `"permit"
|
|
646
|
+
* @returns `true` when `signature.action.type` is `"permit"`.
|
|
696
647
|
*/
|
|
697
648
|
export declare function isPermitSignature(signature: RequirementSignature): signature is PermitRequirementSignature;
|
|
698
649
|
/**
|
|
@@ -728,7 +679,7 @@ export declare function isAuthorizationSignature(signature: RequirementSignature
|
|
|
728
679
|
export declare function isMidnightOfferRootSignature(signature: RequirementSignature): signature is MidnightOfferRootSignature;
|
|
729
680
|
/** The typed requirement-signature slots a transaction builder consumes, split from a `buildTx` array. */
|
|
730
681
|
export interface SelectedRequirementSignatures {
|
|
731
|
-
/** The single ERC-2612
|
|
682
|
+
/** The single ERC-2612 signature, when present. */
|
|
732
683
|
readonly permit?: PermitRequirementSignature;
|
|
733
684
|
/** The single Permit2 SignatureTransfer signature, when present. */
|
|
734
685
|
readonly permit2SignatureTransfer?: Permit2SignatureTransferRequirementSignature;
|
|
@@ -748,12 +699,13 @@ export interface SelectedRequirementSignatures {
|
|
|
748
699
|
*
|
|
749
700
|
* @param signatures - The signatures passed to `buildTx`.
|
|
750
701
|
* @param accepts - Which signature kinds this operation consumes.
|
|
751
|
-
* @param accepts.permit - Whether an ERC-2612
|
|
702
|
+
* @param accepts.permit - Whether an ERC-2612 signature is consumed.
|
|
752
703
|
* @param accepts.permit2SignatureTransfer - Whether a Permit2 SignatureTransfer is consumed.
|
|
753
704
|
* @param accepts.authorization - Whether a Morpho authorization signature is consumed.
|
|
754
705
|
* @param accepts.midnightOfferRoot - Whether a Midnight offer-root signature is consumed.
|
|
755
706
|
* @returns The accepted signature in each typed slot, when present.
|
|
756
707
|
* @throws {AmbiguousRequirementSignaturesError} when more than one signature of an accepted kind is present.
|
|
708
|
+
* @throws {UnsupportedRequirementSignatureError} when a signature has an unsupported action type.
|
|
757
709
|
* @throws {UnexpectedRequirementSignatureError} when a signature of a kind the operation does not consume is present.
|
|
758
710
|
* @example
|
|
759
711
|
* ```ts
|
package/lib/cjs/types/action.js
CHANGED
|
@@ -42,13 +42,13 @@ function isRequirementSignature(requirement) {
|
|
|
42
42
|
typeof requirement.sign === "function");
|
|
43
43
|
}
|
|
44
44
|
/**
|
|
45
|
-
* Narrows a {@link RequirementSignature} to
|
|
45
|
+
* Narrows a {@link RequirementSignature} to an ERC-2612 permit signature.
|
|
46
46
|
*
|
|
47
47
|
* @param signature - The signed requirement to test.
|
|
48
|
-
* @returns `true` when `signature.action.type` is `"permit"
|
|
48
|
+
* @returns `true` when `signature.action.type` is `"permit"`.
|
|
49
49
|
*/
|
|
50
50
|
function isPermitSignature(signature) {
|
|
51
|
-
return
|
|
51
|
+
return signature.action.type === "permit";
|
|
52
52
|
}
|
|
53
53
|
/**
|
|
54
54
|
* Narrows a {@link RequirementSignature} to a Permit2 SignatureTransfer result.
|
|
@@ -98,12 +98,13 @@ function isMidnightOfferRootSignature(signature) {
|
|
|
98
98
|
*
|
|
99
99
|
* @param signatures - The signatures passed to `buildTx`.
|
|
100
100
|
* @param accepts - Which signature kinds this operation consumes.
|
|
101
|
-
* @param accepts.permit - Whether an ERC-2612
|
|
101
|
+
* @param accepts.permit - Whether an ERC-2612 signature is consumed.
|
|
102
102
|
* @param accepts.permit2SignatureTransfer - Whether a Permit2 SignatureTransfer is consumed.
|
|
103
103
|
* @param accepts.authorization - Whether a Morpho authorization signature is consumed.
|
|
104
104
|
* @param accepts.midnightOfferRoot - Whether a Midnight offer-root signature is consumed.
|
|
105
105
|
* @returns The accepted signature in each typed slot, when present.
|
|
106
106
|
* @throws {AmbiguousRequirementSignaturesError} when more than one signature of an accepted kind is present.
|
|
107
|
+
* @throws {UnsupportedRequirementSignatureError} when a signature has an unsupported action type.
|
|
107
108
|
* @throws {UnexpectedRequirementSignatureError} when a signature of a kind the operation does not consume is present.
|
|
108
109
|
* @example
|
|
109
110
|
* ```ts
|
|
@@ -122,6 +123,12 @@ function selectRequirementSignatures(signatures, accepts) {
|
|
|
122
123
|
const permit2Transfers = signatures.filter(isPermit2SignatureTransferSignature);
|
|
123
124
|
const authorizations = signatures.filter(isAuthorizationSignature);
|
|
124
125
|
const midnightOfferRoots = signatures.filter(isMidnightOfferRootSignature);
|
|
126
|
+
const unsupported = signatures.find((signature) => !isPermitSignature(signature) &&
|
|
127
|
+
!isPermit2SignatureTransferSignature(signature) &&
|
|
128
|
+
!isAuthorizationSignature(signature) &&
|
|
129
|
+
!isMidnightOfferRootSignature(signature));
|
|
130
|
+
if (unsupported != null)
|
|
131
|
+
throw new error_js_1.UnsupportedRequirementSignatureError(unsupported.action.type);
|
|
125
132
|
if (!accepts.permit && permits.length > 0)
|
|
126
133
|
throw new error_js_1.UnexpectedRequirementSignatureError("permit");
|
|
127
134
|
if (!accepts.permit2SignatureTransfer && permit2Transfers.length > 0)
|