@morpho-org/morpho-sdk 6.0.0-next.0 → 6.0.0-next.1
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 +206 -3
- package/README.md +81 -41
- package/lib/cjs/abis.d.ts +210 -0
- package/lib/cjs/abis.js +142 -2
- package/lib/cjs/actions/blue/borrow.d.ts +1 -1
- package/lib/cjs/actions/blue/borrow.js +1 -1
- package/lib/cjs/actions/blue/common.d.ts +6 -19
- package/lib/cjs/actions/blue/common.js +25 -138
- package/lib/cjs/actions/blue/refinance.d.ts +1 -1
- package/lib/cjs/actions/blue/refinance.js +1 -1
- package/lib/cjs/actions/blue/repay.d.ts +3 -3
- package/lib/cjs/actions/blue/repay.js +1 -1
- package/lib/cjs/actions/blue/repayWithdrawCollateral.d.ts +3 -3
- package/lib/cjs/actions/blue/repayWithdrawCollateral.js +1 -1
- package/lib/cjs/actions/blue/supply.d.ts +3 -3
- package/lib/cjs/actions/blue/supply.js +1 -1
- package/lib/cjs/actions/blue/supplyCollateral.d.ts +3 -3
- package/lib/cjs/actions/blue/supplyCollateral.js +1 -1
- package/lib/cjs/actions/blue/supplyCollateralBorrow.d.ts +3 -3
- package/lib/cjs/actions/blue/supplyCollateralBorrow.js +1 -1
- package/lib/cjs/actions/blue/withdraw.d.ts +1 -1
- package/lib/cjs/actions/blue/withdraw.js +1 -1
- package/lib/cjs/actions/blue/withdrawCollateral.d.ts +1 -1
- package/lib/cjs/actions/blue/withdrawCollateral.js +1 -1
- package/lib/cjs/actions/bundles/common.d.ts +200 -0
- package/lib/cjs/actions/bundles/common.js +469 -0
- package/lib/cjs/actions/bundles/index.d.ts +3 -0
- package/lib/cjs/actions/bundles/index.js +23 -0
- package/lib/cjs/actions/bundles/resolveBundlesTokenRequirements.d.ts +76 -0
- package/lib/cjs/actions/bundles/resolveBundlesTokenRequirements.js +125 -0
- package/lib/cjs/actions/index.d.ts +1 -0
- package/lib/cjs/actions/index.js +1 -0
- package/lib/cjs/actions/midnight/supplyCollateralTakeBorrow.d.ts +2 -2
- package/lib/cjs/actions/midnight/supplyCollateralTakeBorrow.js +2 -2
- package/lib/cjs/actions/midnight/takeBorrow.d.ts +2 -2
- package/lib/cjs/actions/midnight/takeBorrow.js +2 -2
- package/lib/cjs/actions/midnight/takeLend.d.ts +2 -2
- package/lib/cjs/actions/midnight/takeLend.js +2 -2
- package/lib/cjs/actions/requirements/blue/getUnusedPermit2Nonce.d.ts +1 -1
- package/lib/cjs/actions/requirements/blue/getUnusedPermit2Nonce.js +1 -1
- package/lib/cjs/actions/requirements/blue/index.d.ts +0 -1
- package/lib/cjs/actions/requirements/blue/index.js +0 -1
- package/lib/cjs/actions/requirements/encode/encodeBlueSignatureAuthorization.js +1 -1
- package/lib/cjs/actions/requirements/encode/encodeErc20Approval.d.ts +1 -1
- package/lib/cjs/actions/requirements/encode/encodeErc20Approval.js +2 -1
- package/lib/cjs/actions/requirements/encode/encodeErc20Permit.d.ts +3 -3
- package/lib/cjs/actions/requirements/encode/encodeErc20Permit.js +10 -4
- package/lib/{esm/actions/requirements/encode/encodeErc20Permit2TransferFrom.d.ts → cjs/actions/requirements/encode/encodeErc20Permit2SignatureTransfer.d.ts} +12 -12
- package/lib/cjs/actions/requirements/encode/{encodeErc20Permit2TransferFrom.js → encodeErc20Permit2SignatureTransfer.js} +13 -13
- package/lib/cjs/actions/requirements/encode/encodeVaultSharesPermit.d.ts +4 -4
- package/lib/cjs/actions/requirements/encode/encodeVaultSharesPermit.js +6 -5
- package/lib/cjs/actions/requirements/encode/index.d.ts +1 -1
- package/lib/cjs/actions/requirements/encode/index.js +1 -1
- package/lib/cjs/actions/requirements/getRequirementsApproval.d.ts +4 -3
- package/lib/cjs/actions/requirements/getRequirementsApproval.js +4 -3
- package/lib/cjs/actions/signatures/getTokenRequirementActions.js +2 -2
- package/lib/cjs/actions/signatures/getVaultExitBundlesV1PermitStruct.d.ts +22 -30
- package/lib/cjs/actions/signatures/getVaultExitBundlesV1PermitStruct.js +18 -66
- package/lib/cjs/actions/vaultV1/deposit.d.ts +73 -57
- package/lib/cjs/actions/vaultV1/deposit.js +110 -109
- package/lib/cjs/actions/vaultV1/migrateToV2.d.ts +43 -66
- package/lib/cjs/actions/vaultV1/migrateToV2.js +91 -104
- package/lib/cjs/actions/vaultV1/redeem.d.ts +30 -23
- package/lib/cjs/actions/vaultV1/redeem.js +56 -33
- package/lib/cjs/actions/vaultV1/withdraw.d.ts +58 -24
- package/lib/cjs/actions/vaultV1/withdraw.js +86 -34
- package/lib/cjs/actions/vaultV2/deposit.d.ts +74 -57
- package/lib/cjs/actions/vaultV2/deposit.js +111 -109
- package/lib/cjs/actions/vaultV2/redeem.d.ts +30 -24
- package/lib/cjs/actions/vaultV2/redeem.js +56 -34
- package/lib/cjs/actions/vaultV2/withdraw.d.ts +58 -25
- package/lib/cjs/actions/vaultV2/withdraw.js +86 -35
- package/lib/cjs/entities/blue/blue.d.ts +19 -19
- package/lib/cjs/entities/blue/blue.js +3 -1
- package/lib/cjs/entities/index.d.ts +1 -0
- package/lib/cjs/entities/index.js +15 -0
- package/lib/cjs/entities/midnight/midnight.d.ts +2 -2
- package/lib/cjs/{actions/requirements/blue/getBlueBundlesV1TokenRequirements.d.ts → entities/requirements/getBundlesTokenRequirements.d.ts} +21 -14
- package/lib/cjs/{actions/requirements/blue/getBlueBundlesV1TokenRequirements.js → entities/requirements/getBundlesTokenRequirements.js} +61 -65
- package/lib/cjs/entities/requirements/getVaultBundlesSharesRequirements.d.ts +28 -0
- package/lib/cjs/entities/requirements/getVaultBundlesSharesRequirements.js +74 -0
- package/lib/cjs/entities/requirements/index.d.ts +1 -0
- package/lib/cjs/entities/requirements/index.js +17 -0
- package/lib/cjs/entities/vaultV1/vaultV1.d.ts +348 -98
- package/lib/cjs/entities/vaultV1/vaultV1.js +322 -120
- package/lib/cjs/entities/vaultV2/vaultV2.d.ts +221 -68
- package/lib/cjs/entities/vaultV2/vaultV2.js +219 -77
- package/lib/cjs/helpers/index.d.ts +2 -1
- package/lib/cjs/helpers/index.js +5 -1
- package/lib/cjs/helpers/referralFee.d.ts +21 -0
- package/lib/cjs/helpers/referralFee.js +35 -0
- package/lib/cjs/helpers/slippage.d.ts +90 -1
- package/lib/cjs/helpers/slippage.js +123 -0
- package/lib/cjs/helpers/validate.d.ts +2 -0
- package/lib/cjs/helpers/validate.js +12 -1
- package/lib/cjs/helpers/validateRequirementSpender.d.ts +1 -1
- package/lib/cjs/helpers/validateRequirementSpender.js +1 -0
- package/lib/cjs/index.d.ts +1 -0
- package/lib/cjs/index.js +1 -0
- package/lib/cjs/types/action.d.ts +179 -70
- package/lib/cjs/types/action.js +12 -12
- package/lib/cjs/types/error.d.ts +62 -14
- package/lib/cjs/types/error.js +88 -22
- package/lib/esm/abis.d.ts +210 -0
- package/lib/esm/abis.js +140 -0
- package/lib/esm/actions/blue/borrow.d.ts +1 -1
- package/lib/esm/actions/blue/borrow.js +1 -1
- package/lib/esm/actions/blue/common.d.ts +6 -19
- package/lib/esm/actions/blue/common.js +27 -140
- package/lib/esm/actions/blue/refinance.d.ts +1 -1
- package/lib/esm/actions/blue/refinance.js +1 -1
- package/lib/esm/actions/blue/repay.d.ts +3 -3
- package/lib/esm/actions/blue/repay.js +1 -1
- package/lib/esm/actions/blue/repayWithdrawCollateral.d.ts +3 -3
- package/lib/esm/actions/blue/repayWithdrawCollateral.js +1 -1
- package/lib/esm/actions/blue/supply.d.ts +3 -3
- package/lib/esm/actions/blue/supply.js +1 -1
- package/lib/esm/actions/blue/supplyCollateral.d.ts +3 -3
- package/lib/esm/actions/blue/supplyCollateral.js +1 -1
- package/lib/esm/actions/blue/supplyCollateralBorrow.d.ts +3 -3
- package/lib/esm/actions/blue/supplyCollateralBorrow.js +1 -1
- package/lib/esm/actions/blue/withdraw.d.ts +1 -1
- package/lib/esm/actions/blue/withdraw.js +1 -1
- package/lib/esm/actions/blue/withdrawCollateral.d.ts +1 -1
- package/lib/esm/actions/blue/withdrawCollateral.js +1 -1
- package/lib/esm/actions/bundles/common.d.ts +200 -0
- package/lib/esm/actions/bundles/common.js +457 -0
- package/lib/esm/actions/bundles/index.d.ts +3 -0
- package/lib/esm/actions/bundles/index.js +2 -0
- package/lib/esm/actions/bundles/resolveBundlesTokenRequirements.d.ts +76 -0
- package/lib/esm/actions/bundles/resolveBundlesTokenRequirements.js +121 -0
- package/lib/esm/actions/index.d.ts +1 -0
- package/lib/esm/actions/index.js +1 -0
- package/lib/esm/actions/midnight/supplyCollateralTakeBorrow.d.ts +2 -2
- package/lib/esm/actions/midnight/supplyCollateralTakeBorrow.js +2 -2
- package/lib/esm/actions/midnight/takeBorrow.d.ts +2 -2
- package/lib/esm/actions/midnight/takeBorrow.js +2 -2
- package/lib/esm/actions/midnight/takeLend.d.ts +2 -2
- package/lib/esm/actions/midnight/takeLend.js +2 -2
- package/lib/esm/actions/requirements/blue/getUnusedPermit2Nonce.d.ts +1 -1
- package/lib/esm/actions/requirements/blue/getUnusedPermit2Nonce.js +1 -1
- package/lib/esm/actions/requirements/blue/index.d.ts +0 -1
- package/lib/esm/actions/requirements/blue/index.js +0 -1
- package/lib/esm/actions/requirements/encode/encodeBlueSignatureAuthorization.js +1 -1
- package/lib/esm/actions/requirements/encode/encodeErc20Approval.d.ts +1 -1
- package/lib/esm/actions/requirements/encode/encodeErc20Approval.js +2 -1
- package/lib/esm/actions/requirements/encode/encodeErc20Permit.d.ts +3 -3
- package/lib/esm/actions/requirements/encode/encodeErc20Permit.js +10 -4
- package/lib/{cjs/actions/requirements/encode/encodeErc20Permit2TransferFrom.d.ts → esm/actions/requirements/encode/encodeErc20Permit2SignatureTransfer.d.ts} +12 -12
- package/lib/esm/actions/requirements/encode/{encodeErc20Permit2TransferFrom.js → encodeErc20Permit2SignatureTransfer.js} +11 -11
- package/lib/esm/actions/requirements/encode/encodeVaultSharesPermit.d.ts +4 -4
- package/lib/esm/actions/requirements/encode/encodeVaultSharesPermit.js +6 -5
- package/lib/esm/actions/requirements/encode/index.d.ts +1 -1
- package/lib/esm/actions/requirements/encode/index.js +1 -1
- package/lib/esm/actions/requirements/getRequirementsApproval.d.ts +4 -3
- package/lib/esm/actions/requirements/getRequirementsApproval.js +4 -3
- package/lib/esm/actions/signatures/getTokenRequirementActions.js +3 -3
- package/lib/esm/actions/signatures/getVaultExitBundlesV1PermitStruct.d.ts +22 -30
- package/lib/esm/actions/signatures/getVaultExitBundlesV1PermitStruct.js +19 -67
- package/lib/esm/actions/vaultV1/deposit.d.ts +73 -57
- package/lib/esm/actions/vaultV1/deposit.js +112 -111
- package/lib/esm/actions/vaultV1/migrateToV2.d.ts +43 -66
- package/lib/esm/actions/vaultV1/migrateToV2.js +93 -106
- package/lib/esm/actions/vaultV1/redeem.d.ts +30 -23
- package/lib/esm/actions/vaultV1/redeem.js +56 -33
- package/lib/esm/actions/vaultV1/withdraw.d.ts +58 -24
- package/lib/esm/actions/vaultV1/withdraw.js +86 -34
- package/lib/esm/actions/vaultV2/deposit.d.ts +74 -57
- package/lib/esm/actions/vaultV2/deposit.js +113 -111
- package/lib/esm/actions/vaultV2/redeem.d.ts +30 -24
- package/lib/esm/actions/vaultV2/redeem.js +56 -34
- package/lib/esm/actions/vaultV2/withdraw.d.ts +58 -25
- package/lib/esm/actions/vaultV2/withdraw.js +86 -35
- package/lib/esm/entities/blue/blue.d.ts +19 -19
- package/lib/esm/entities/blue/blue.js +4 -2
- package/lib/esm/entities/index.d.ts +1 -0
- package/lib/esm/entities/index.js +1 -0
- package/lib/esm/entities/midnight/midnight.d.ts +2 -2
- package/lib/esm/{actions/requirements/blue/getBlueBundlesV1TokenRequirements.d.ts → entities/requirements/getBundlesTokenRequirements.d.ts} +21 -14
- package/lib/esm/{actions/requirements/blue/getBlueBundlesV1TokenRequirements.js → entities/requirements/getBundlesTokenRequirements.js} +51 -55
- package/lib/esm/entities/requirements/getVaultBundlesSharesRequirements.d.ts +28 -0
- package/lib/esm/entities/requirements/getVaultBundlesSharesRequirements.js +70 -0
- package/lib/esm/entities/requirements/index.d.ts +1 -0
- package/lib/esm/entities/requirements/index.js +1 -0
- package/lib/esm/entities/vaultV1/vaultV1.d.ts +348 -98
- package/lib/esm/entities/vaultV1/vaultV1.js +326 -124
- package/lib/esm/entities/vaultV2/vaultV2.d.ts +221 -68
- package/lib/esm/entities/vaultV2/vaultV2.js +222 -80
- package/lib/esm/helpers/index.d.ts +2 -1
- package/lib/esm/helpers/index.js +2 -1
- package/lib/esm/helpers/referralFee.d.ts +21 -0
- package/lib/esm/helpers/referralFee.js +31 -0
- package/lib/esm/helpers/slippage.d.ts +90 -1
- package/lib/esm/helpers/slippage.js +122 -2
- package/lib/esm/helpers/validate.d.ts +2 -0
- package/lib/esm/helpers/validate.js +11 -1
- package/lib/esm/helpers/validateRequirementSpender.d.ts +1 -1
- package/lib/esm/helpers/validateRequirementSpender.js +1 -0
- package/lib/esm/index.d.ts +1 -0
- package/lib/esm/index.js +1 -0
- package/lib/esm/types/action.d.ts +179 -70
- package/lib/esm/types/action.js +11 -11
- package/lib/esm/types/error.d.ts +62 -14
- package/lib/esm/types/error.js +80 -16
- package/package.json +3 -3
|
@@ -6,9 +6,13 @@ const blue_sdk_viem_1 = require("@morpho-org/blue-sdk-viem");
|
|
|
6
6
|
const morpho_ts_1 = require("@morpho-org/morpho-ts");
|
|
7
7
|
const viem_1 = require("viem");
|
|
8
8
|
const actions_1 = require("viem/actions");
|
|
9
|
+
const common_js_1 = require("../../actions/bundles/common.js");
|
|
9
10
|
const index_js_1 = require("../../actions/index.js");
|
|
10
11
|
const index_js_2 = require("../../helpers/index.js");
|
|
12
|
+
const validate_js_1 = require("../../helpers/validate.js");
|
|
11
13
|
const index_js_3 = require("../../types/index.js");
|
|
14
|
+
const getVaultBundlesSharesRequirements_js_1 = require("../requirements/getVaultBundlesSharesRequirements.js");
|
|
15
|
+
const index_js_4 = require("../requirements/index.js");
|
|
12
16
|
class MorphoVaultV2 {
|
|
13
17
|
client;
|
|
14
18
|
vault;
|
|
@@ -30,104 +34,242 @@ class MorphoVaultV2 {
|
|
|
30
34
|
deployless: this.client.options.supportDeployless,
|
|
31
35
|
});
|
|
32
36
|
}
|
|
33
|
-
|
|
37
|
+
/** {@inheritDoc VaultV2Actions.deposit} */
|
|
38
|
+
deposit(params) {
|
|
39
|
+
const { userAddress, vaultData } = params;
|
|
40
|
+
const { asset: vaultAsset } = vaultData;
|
|
34
41
|
(0, index_js_2.validateChainId)(this.client.viemClient.chain?.id, this.chainId);
|
|
35
42
|
if (!(0, viem_1.isAddressEqual)(vaultData.address, this.vault)) {
|
|
36
43
|
throw new index_js_3.VaultAddressMismatchError(this.vault, vaultData.address);
|
|
37
44
|
}
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
if (!(0, viem_1.isAddressEqual)(vaultData.asset, wNative)) {
|
|
54
|
-
throw new index_js_3.NativeAmountOnNonWNativeVaultError(vaultData.asset, wNative);
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
const totalAssets = amount + (nativeAmount ?? 0n);
|
|
58
|
-
if (totalAssets === 0n) {
|
|
59
|
-
throw new index_js_3.NonPositiveInputError("totalAssets", totalAssets);
|
|
60
|
-
}
|
|
61
|
-
// Accrue interest forward to bound the on-chain share price at execution.
|
|
62
|
-
// Mirrors blue repay's 2h forward-accrual buffer.
|
|
63
|
-
const accrualTimestamp = blue_sdk_1.MathLib.max(morpho_ts_1.Time.timestamp(), vaultData.lastUpdate) + morpho_ts_1.Time.s.from.h(2n);
|
|
64
|
-
const { vault: accruedVault } = vaultData.accrueInterest(accrualTimestamp);
|
|
65
|
-
const shares = accruedVault.toShares(totalAssets);
|
|
66
|
-
if (shares <= 0n) {
|
|
67
|
-
throw new index_js_3.NonPositiveInputError("shares", shares);
|
|
45
|
+
const createdAt = morpho_ts_1.Time.timestamp();
|
|
46
|
+
const deadline = params.deadline ?? createdAt + morpho_ts_1.Time.s.from.h(2n);
|
|
47
|
+
if (deadline <= createdAt)
|
|
48
|
+
throw new index_js_3.ExpiredDeadlineError(deadline, createdAt);
|
|
49
|
+
const common = (0, common_js_1.normalizeBundlesCommonParams)({
|
|
50
|
+
deadline,
|
|
51
|
+
referralFeePct: params.referralFeePct,
|
|
52
|
+
referralFeeRecipient: params.referralFeeRecipient,
|
|
53
|
+
});
|
|
54
|
+
const funding = (0, common_js_1.resolveBundlesFunding)(params);
|
|
55
|
+
// Reject overflow before share-price math or native-only prerequisite resolution.
|
|
56
|
+
(0, validate_js_1.validateUint256Field)(funding.value > 0n ? "nativeAmount" : "amount", funding.assets);
|
|
57
|
+
if (funding.value > 0n) {
|
|
58
|
+
// The native path must target the chain's registered wrapped-native asset.
|
|
59
|
+
(0, validate_js_1.validateNativeVaultAsset)(this.chainId, vaultAsset);
|
|
68
60
|
}
|
|
69
|
-
const
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
61
|
+
const referralFeeAssets = (0, common_js_1.getBundlesReferralFeeAssets)(funding.assets, common.referralFeePct);
|
|
62
|
+
const maxSharePrice = (0, index_js_2.computeVaultMaxSharePrice)({
|
|
63
|
+
vaultData,
|
|
64
|
+
deadline,
|
|
65
|
+
assets: funding.assets - referralFeeAssets,
|
|
66
|
+
slippageTolerance: params.slippageTolerance ?? blue_sdk_1.DEFAULT_SLIPPAGE_TOLERANCE,
|
|
67
|
+
});
|
|
68
|
+
const spender = (0, morpho_ts_1.getChainAddress)(this.chainId, "bundles.vaultBundlesV1");
|
|
69
|
+
let pendingRequirements;
|
|
70
|
+
let expectedRequirement;
|
|
71
|
+
return Object.freeze({
|
|
72
|
+
getRequirements: async (requirementOptions) => {
|
|
73
|
+
const now = morpho_ts_1.Time.timestamp();
|
|
74
|
+
if (deadline <= now)
|
|
75
|
+
throw new index_js_3.ExpiredDeadlineError(deadline, now);
|
|
76
|
+
if (pendingRequirements != null)
|
|
77
|
+
return await pendingRequirements;
|
|
78
|
+
// Memoize the in-flight promise, not just its result: concurrent callers
|
|
79
|
+
// requesting different routes would otherwise both resolve requirements and
|
|
80
|
+
// the slower one would overwrite `expectedRequirement`, making `buildTx()`
|
|
81
|
+
// reject the signature returned by the other call.
|
|
82
|
+
const pending = (async () => {
|
|
83
|
+
const requirements = funding.value > 0n
|
|
84
|
+
? []
|
|
85
|
+
: await (0, index_js_4.getBundlesTokenRequirements)(this.client.viemClient, {
|
|
86
|
+
token: vaultAsset,
|
|
87
|
+
spender,
|
|
88
|
+
amount: funding.assets,
|
|
89
|
+
owner: userAddress,
|
|
90
|
+
chainId: this.chainId,
|
|
91
|
+
deadline,
|
|
92
|
+
supportSignature: this.client.options.supportSignature,
|
|
93
|
+
supportDeployless: this.client.options.supportDeployless,
|
|
94
|
+
useSimplePermit: requirementOptions?.useSimplePermit,
|
|
95
|
+
permit2Nonce: requirementOptions?.permit2Nonce,
|
|
96
|
+
});
|
|
97
|
+
const signatureRequirement = requirements.find(index_js_3.isRequirementSignature);
|
|
98
|
+
expectedRequirement =
|
|
99
|
+
signatureRequirement?.action.type === "permit" ||
|
|
100
|
+
signatureRequirement?.action.type === "permit2SignatureTransfer"
|
|
101
|
+
? signatureRequirement.action
|
|
102
|
+
: undefined;
|
|
103
|
+
return requirements;
|
|
104
|
+
})();
|
|
105
|
+
pendingRequirements = pending;
|
|
106
|
+
try {
|
|
107
|
+
return await pending;
|
|
108
|
+
}
|
|
109
|
+
finally {
|
|
110
|
+
// Later calls must re-read live allowances/nonces and honor their own options.
|
|
111
|
+
if (pendingRequirements === pending)
|
|
112
|
+
pendingRequirements = undefined;
|
|
113
|
+
}
|
|
114
|
+
},
|
|
82
115
|
buildTx: (signatures) => {
|
|
83
|
-
const
|
|
84
|
-
permit: true,
|
|
85
|
-
});
|
|
116
|
+
const requirementSignature = (0, common_js_1.selectBundlesTokenRequirementSignature)(signatures, expectedRequirement);
|
|
86
117
|
return (0, index_js_1.vaultV2Deposit)({
|
|
87
118
|
vault: {
|
|
88
119
|
chainId: this.chainId,
|
|
89
120
|
address: this.vault,
|
|
90
|
-
asset:
|
|
121
|
+
asset: vaultAsset,
|
|
91
122
|
},
|
|
92
123
|
args: {
|
|
93
|
-
|
|
124
|
+
...(funding.value > 0n
|
|
125
|
+
? { nativeAmount: funding.assets }
|
|
126
|
+
: { amount: funding.assets }),
|
|
94
127
|
maxSharePrice,
|
|
95
|
-
|
|
96
|
-
requirementSignature
|
|
97
|
-
|
|
128
|
+
userAddress,
|
|
129
|
+
requirementSignature,
|
|
130
|
+
referralFeePct: common.referralFeePct,
|
|
131
|
+
referralFeeRecipient: common.referralFeeRecipient,
|
|
132
|
+
deadline,
|
|
98
133
|
},
|
|
99
134
|
metadata: this.client.options.metadata,
|
|
100
135
|
});
|
|
101
136
|
},
|
|
102
|
-
};
|
|
137
|
+
});
|
|
103
138
|
}
|
|
104
|
-
withdraw(
|
|
139
|
+
withdraw(params) {
|
|
140
|
+
const { amount, userAddress } = params;
|
|
105
141
|
(0, index_js_2.validateChainId)(this.client.viemClient.chain?.id, this.chainId);
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
142
|
+
if (amount <= 0n)
|
|
143
|
+
throw new index_js_3.NonPositiveInputError("amount", amount);
|
|
144
|
+
// Reject values outside the ABI range before resolving any requirements.
|
|
145
|
+
(0, validate_js_1.validateUint256Field)("amount", amount);
|
|
146
|
+
const createdAt = morpho_ts_1.Time.timestamp();
|
|
147
|
+
const deadline = params.deadline ?? createdAt + morpho_ts_1.Time.s.from.h(2n);
|
|
148
|
+
if (deadline <= createdAt)
|
|
149
|
+
throw new index_js_3.ExpiredDeadlineError(deadline, createdAt);
|
|
150
|
+
const common = (0, common_js_1.normalizeBundlesCommonParams)({
|
|
151
|
+
deadline,
|
|
152
|
+
referralFeePct: params.referralFeePct,
|
|
153
|
+
referralFeeRecipient: params.referralFeeRecipient,
|
|
154
|
+
});
|
|
155
|
+
const slippageTolerance = params.slippageTolerance ?? blue_sdk_1.DEFAULT_SLIPPAGE_TOLERANCE;
|
|
156
|
+
(0, index_js_2.validateSlippageTolerance)(slippageTolerance);
|
|
157
|
+
// Fail eagerly if VaultBundlesV1 is unavailable; only validation is needed here.
|
|
158
|
+
(0, morpho_ts_1.getChainAddress)(this.chainId, "bundles.vaultBundlesV1");
|
|
159
|
+
let requiredShareAllowance;
|
|
160
|
+
let vaultSnapshot;
|
|
161
|
+
let expectedRequirement;
|
|
162
|
+
return Object.freeze({
|
|
163
|
+
getRequirements: async () => {
|
|
164
|
+
const now = morpho_ts_1.Time.timestamp();
|
|
165
|
+
if (deadline <= now)
|
|
166
|
+
throw new index_js_3.ExpiredDeadlineError(deadline, now);
|
|
167
|
+
// Re-read the live share allowance on every call instead of caching the resolved
|
|
168
|
+
// requirements: the allowance is the sole cap on the burn, so a caller that executed the
|
|
169
|
+
// returned approval must see it satisfied on the next call, and an allowance revoked or
|
|
170
|
+
// raised afterwards must resurface as an outstanding requirement. Only the vault snapshot
|
|
171
|
+
// and the cap derived from it are pinned, so re-reading cannot move the cap this handle
|
|
172
|
+
// already committed to; the snapshot is used for immutable identity and permit-domain
|
|
173
|
+
// fields only.
|
|
174
|
+
const vaultData = (vaultSnapshot ??= await this.getData());
|
|
175
|
+
requiredShareAllowance ??= (0, index_js_2.computeVaultMaxShareAllowance)({
|
|
176
|
+
vaultData,
|
|
177
|
+
deadline,
|
|
178
|
+
assets: amount,
|
|
179
|
+
slippageTolerance,
|
|
180
|
+
});
|
|
181
|
+
const requirements = await (0, getVaultBundlesSharesRequirements_js_1.getVaultBundlesSharesRequirements)(this.client.viemClient, {
|
|
182
|
+
vaultData,
|
|
183
|
+
version: "vaultV2",
|
|
184
|
+
owner: userAddress,
|
|
185
|
+
chainId: this.chainId,
|
|
186
|
+
requiredShareAllowance,
|
|
187
|
+
deadline,
|
|
188
|
+
supportSignature: this.client.options.supportSignature,
|
|
189
|
+
});
|
|
190
|
+
const signatureRequirement = requirements.find(index_js_3.isRequirementSignature);
|
|
191
|
+
if (signatureRequirement?.action.type === "permit") {
|
|
192
|
+
expectedRequirement = signatureRequirement.action;
|
|
193
|
+
}
|
|
194
|
+
return requirements;
|
|
195
|
+
},
|
|
196
|
+
buildTx: (signatures) => {
|
|
197
|
+
const permit = (0, common_js_1.selectBundlesSharesRequirementSignature)(signatures, {
|
|
198
|
+
requiredShareAllowance,
|
|
199
|
+
expectedRequirement,
|
|
200
|
+
});
|
|
201
|
+
return (0, index_js_1.vaultV2Withdraw)({
|
|
202
|
+
vault: { chainId: this.chainId, address: this.vault },
|
|
203
|
+
args: {
|
|
204
|
+
amount,
|
|
205
|
+
userAddress,
|
|
206
|
+
requirementSignature: permit,
|
|
207
|
+
referralFeePct: common.referralFeePct,
|
|
208
|
+
referralFeeRecipient: common.referralFeeRecipient,
|
|
209
|
+
deadline,
|
|
210
|
+
},
|
|
211
|
+
metadata: this.client.options.metadata,
|
|
212
|
+
});
|
|
213
|
+
},
|
|
214
|
+
});
|
|
117
215
|
}
|
|
118
|
-
|
|
216
|
+
/** {@inheritDoc VaultV2Actions.redeem} */
|
|
217
|
+
redeem(params) {
|
|
119
218
|
(0, index_js_2.validateChainId)(this.client.viemClient.chain?.id, this.chainId);
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
219
|
+
const { shares, userAddress } = params;
|
|
220
|
+
if (shares <= 0n)
|
|
221
|
+
throw new index_js_3.NonPositiveInputError("shares", shares);
|
|
222
|
+
const createdAt = morpho_ts_1.Time.timestamp();
|
|
223
|
+
const deadline = params.deadline ?? createdAt + morpho_ts_1.Time.s.from.h(2n);
|
|
224
|
+
if (deadline <= createdAt)
|
|
225
|
+
throw new index_js_3.ExpiredDeadlineError(deadline, createdAt);
|
|
226
|
+
const common = (0, common_js_1.normalizeBundlesCommonParams)({
|
|
227
|
+
deadline,
|
|
228
|
+
referralFeePct: params.referralFeePct,
|
|
229
|
+
referralFeeRecipient: params.referralFeeRecipient,
|
|
230
|
+
});
|
|
231
|
+
(0, morpho_ts_1.getChainAddress)(this.chainId, "bundles.vaultBundlesV1");
|
|
232
|
+
let expectedRequirement;
|
|
233
|
+
return Object.freeze({
|
|
234
|
+
getRequirements: async () => {
|
|
235
|
+
const now = morpho_ts_1.Time.timestamp();
|
|
236
|
+
if (deadline <= now)
|
|
237
|
+
throw new index_js_3.ExpiredDeadlineError(deadline, now);
|
|
238
|
+
const requirements = await (0, getVaultBundlesSharesRequirements_js_1.getVaultBundlesSharesRequirements)(this.client.viemClient, {
|
|
239
|
+
vaultData: await this.getData(),
|
|
240
|
+
version: "vaultV2",
|
|
241
|
+
owner: userAddress,
|
|
242
|
+
chainId: this.chainId,
|
|
243
|
+
requiredShareAllowance: shares,
|
|
244
|
+
deadline,
|
|
245
|
+
supportSignature: this.client.options.supportSignature,
|
|
246
|
+
});
|
|
247
|
+
const signatureRequirement = requirements.find(index_js_3.isRequirementSignature);
|
|
248
|
+
expectedRequirement =
|
|
249
|
+
signatureRequirement?.action.type === "permit"
|
|
250
|
+
? signatureRequirement.action
|
|
251
|
+
: undefined;
|
|
252
|
+
return requirements;
|
|
253
|
+
},
|
|
254
|
+
buildTx: (signatures) => {
|
|
255
|
+
const permit = (0, common_js_1.selectBundlesSharesRequirementSignature)(signatures, {
|
|
256
|
+
requiredShareAllowance: shares,
|
|
257
|
+
expectedRequirement,
|
|
258
|
+
});
|
|
259
|
+
return (0, index_js_1.vaultV2Redeem)({
|
|
260
|
+
vault: { chainId: this.chainId, address: this.vault },
|
|
261
|
+
args: {
|
|
262
|
+
shares,
|
|
263
|
+
userAddress,
|
|
264
|
+
requirementSignature: permit,
|
|
265
|
+
referralFeePct: common.referralFeePct,
|
|
266
|
+
referralFeeRecipient: common.referralFeeRecipient,
|
|
267
|
+
deadline,
|
|
268
|
+
},
|
|
269
|
+
metadata: this.client.options.metadata,
|
|
270
|
+
});
|
|
271
|
+
},
|
|
272
|
+
});
|
|
131
273
|
}
|
|
132
274
|
/** {@inheritDoc VaultV2Actions.inKindRedeem} */
|
|
133
275
|
inKindRedeem({ amount, marketParamsList, vaultData, userAddress, adapter: adapterOverride, deadline: deadlineOverride, }) {
|
|
@@ -2,8 +2,9 @@ export { computeReallocations, computeVaultV1Reallocations, } from "./computeVau
|
|
|
2
2
|
export { APPROVE_ONLY_ONCE_TOKENS, DEFAULT_LLTV_BUFFER, DEFAULT_MAX_REALLOCATION_PENALTY, DEFAULT_SUPPLY_TARGET_UTILIZATION, DEFAULT_WITHDRAWAL_TARGET_UTILIZATION, MAX_ABSOLUTE_SHARE_PRICE, MAX_REALLOCATION_PENALTY, MAX_SLIPPAGE_TOLERANCE, MAX_TOKEN_APPROVALS, } from "./constant.js";
|
|
3
3
|
export { addTransactionMetadata } from "./metadata.js";
|
|
4
4
|
export { type PreviewVaultV2InKindRedeemParams, previewVaultV2InKindRedeem, type VaultV2InKindRedeemMarketPreview, } from "./previewVaultV2InKindRedeem.js";
|
|
5
|
+
export { grossFromNetAssets } from "./referralFee.js";
|
|
5
6
|
export { signAndVerifyTypedData } from "./signAndVerifyTypedData.js";
|
|
6
|
-
export { computeMaxRepaySharePrice, computeMaxSupplySharePrice, computeMinBorrowSharePrice, computeMinWithdrawSharePrice, } from "./slippage.js";
|
|
7
|
+
export { computeMaxRepaySharePrice, computeMaxSupplySharePrice, computeMinBorrowSharePrice, computeMinWithdrawSharePrice, computeVaultMaxShareAllowance, computeVaultMaxSharePrice, } from "./slippage.js";
|
|
7
8
|
export { validateAccrualPosition, validateChainId, validateMidnightMarketChainId, validateNativeAsset, validatePositionHealth, validatePositionHealthAfterWithdraw, validateReallocations, validateRepayAmount, validateRepayShares, validateSlippageTolerance, validateUserAddress, validateWithdrawAmount, validateWithdrawShares, } from "./validate.js";
|
|
8
9
|
export { validateOfferSides } from "./validateOfferSides.js";
|
|
9
10
|
export { type RequirementSpenderKey, validateRequirementSpender, } from "./validateRequirementSpender.js";
|
package/lib/cjs/helpers/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.validateRequirementSpender = exports.validateOfferSides = exports.validateWithdrawShares = exports.validateWithdrawAmount = exports.validateUserAddress = exports.validateSlippageTolerance = exports.validateRepayShares = exports.validateRepayAmount = exports.validateReallocations = exports.validatePositionHealthAfterWithdraw = exports.validatePositionHealth = exports.validateNativeAsset = exports.validateMidnightMarketChainId = exports.validateChainId = exports.validateAccrualPosition = exports.computeMinWithdrawSharePrice = exports.computeMinBorrowSharePrice = exports.computeMaxSupplySharePrice = exports.computeMaxRepaySharePrice = exports.signAndVerifyTypedData = exports.previewVaultV2InKindRedeem = exports.addTransactionMetadata = exports.MAX_TOKEN_APPROVALS = exports.MAX_SLIPPAGE_TOLERANCE = exports.MAX_REALLOCATION_PENALTY = exports.MAX_ABSOLUTE_SHARE_PRICE = exports.DEFAULT_WITHDRAWAL_TARGET_UTILIZATION = exports.DEFAULT_SUPPLY_TARGET_UTILIZATION = exports.DEFAULT_MAX_REALLOCATION_PENALTY = exports.DEFAULT_LLTV_BUFFER = exports.APPROVE_ONLY_ONCE_TOKENS = exports.computeVaultV1Reallocations = exports.computeReallocations = void 0;
|
|
3
|
+
exports.validateRequirementSpender = exports.validateOfferSides = exports.validateWithdrawShares = exports.validateWithdrawAmount = exports.validateUserAddress = exports.validateSlippageTolerance = exports.validateRepayShares = exports.validateRepayAmount = exports.validateReallocations = exports.validatePositionHealthAfterWithdraw = exports.validatePositionHealth = exports.validateNativeAsset = exports.validateMidnightMarketChainId = exports.validateChainId = exports.validateAccrualPosition = exports.computeVaultMaxSharePrice = exports.computeVaultMaxShareAllowance = exports.computeMinWithdrawSharePrice = exports.computeMinBorrowSharePrice = exports.computeMaxSupplySharePrice = exports.computeMaxRepaySharePrice = exports.signAndVerifyTypedData = exports.grossFromNetAssets = exports.previewVaultV2InKindRedeem = exports.addTransactionMetadata = exports.MAX_TOKEN_APPROVALS = exports.MAX_SLIPPAGE_TOLERANCE = exports.MAX_REALLOCATION_PENALTY = exports.MAX_ABSOLUTE_SHARE_PRICE = exports.DEFAULT_WITHDRAWAL_TARGET_UTILIZATION = exports.DEFAULT_SUPPLY_TARGET_UTILIZATION = exports.DEFAULT_MAX_REALLOCATION_PENALTY = exports.DEFAULT_LLTV_BUFFER = exports.APPROVE_ONLY_ONCE_TOKENS = exports.computeVaultV1Reallocations = exports.computeReallocations = void 0;
|
|
4
4
|
var computeVaultV1Reallocations_js_1 = require("./computeVaultV1Reallocations.js");
|
|
5
5
|
Object.defineProperty(exports, "computeReallocations", { enumerable: true, get: function () { return computeVaultV1Reallocations_js_1.computeReallocations; } });
|
|
6
6
|
Object.defineProperty(exports, "computeVaultV1Reallocations", { enumerable: true, get: function () { return computeVaultV1Reallocations_js_1.computeVaultV1Reallocations; } });
|
|
@@ -18,6 +18,8 @@ var metadata_js_1 = require("./metadata.js");
|
|
|
18
18
|
Object.defineProperty(exports, "addTransactionMetadata", { enumerable: true, get: function () { return metadata_js_1.addTransactionMetadata; } });
|
|
19
19
|
var previewVaultV2InKindRedeem_js_1 = require("./previewVaultV2InKindRedeem.js");
|
|
20
20
|
Object.defineProperty(exports, "previewVaultV2InKindRedeem", { enumerable: true, get: function () { return previewVaultV2InKindRedeem_js_1.previewVaultV2InKindRedeem; } });
|
|
21
|
+
var referralFee_js_1 = require("./referralFee.js");
|
|
22
|
+
Object.defineProperty(exports, "grossFromNetAssets", { enumerable: true, get: function () { return referralFee_js_1.grossFromNetAssets; } });
|
|
21
23
|
var signAndVerifyTypedData_js_1 = require("./signAndVerifyTypedData.js");
|
|
22
24
|
Object.defineProperty(exports, "signAndVerifyTypedData", { enumerable: true, get: function () { return signAndVerifyTypedData_js_1.signAndVerifyTypedData; } });
|
|
23
25
|
var slippage_js_1 = require("./slippage.js");
|
|
@@ -25,6 +27,8 @@ Object.defineProperty(exports, "computeMaxRepaySharePrice", { enumerable: true,
|
|
|
25
27
|
Object.defineProperty(exports, "computeMaxSupplySharePrice", { enumerable: true, get: function () { return slippage_js_1.computeMaxSupplySharePrice; } });
|
|
26
28
|
Object.defineProperty(exports, "computeMinBorrowSharePrice", { enumerable: true, get: function () { return slippage_js_1.computeMinBorrowSharePrice; } });
|
|
27
29
|
Object.defineProperty(exports, "computeMinWithdrawSharePrice", { enumerable: true, get: function () { return slippage_js_1.computeMinWithdrawSharePrice; } });
|
|
30
|
+
Object.defineProperty(exports, "computeVaultMaxShareAllowance", { enumerable: true, get: function () { return slippage_js_1.computeVaultMaxShareAllowance; } });
|
|
31
|
+
Object.defineProperty(exports, "computeVaultMaxSharePrice", { enumerable: true, get: function () { return slippage_js_1.computeVaultMaxSharePrice; } });
|
|
28
32
|
var validate_js_1 = require("./validate.js");
|
|
29
33
|
Object.defineProperty(exports, "validateAccrualPosition", { enumerable: true, get: function () { return validate_js_1.validateAccrualPosition; } });
|
|
30
34
|
Object.defineProperty(exports, "validateChainId", { enumerable: true, get: function () { return validate_js_1.validateChainId; } });
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Computes the gross amount whose post-referral-fee proceeds equal `netAssets` exactly.
|
|
3
|
+
*
|
|
4
|
+
* @param params - Net target and WAD-scaled referral fee.
|
|
5
|
+
* @param params.netAssets - Required proceeds after the fee, in the asset's smallest unit.
|
|
6
|
+
* @param params.referralFeePct - Referral fee fraction scaled by WAD (`1e18`); must be below WAD.
|
|
7
|
+
* @returns The gross asset amount to pass to a bundles entrypoint.
|
|
8
|
+
* @throws {NegativeInputError} when `netAssets` or `referralFeePct` is negative.
|
|
9
|
+
* @throws {ReferralFeePctExceededError} when `referralFeePct >= WAD`.
|
|
10
|
+
* @example
|
|
11
|
+
* ```ts
|
|
12
|
+
* import { grossFromNetAssets } from "@morpho-org/morpho-sdk";
|
|
13
|
+
*
|
|
14
|
+
* const gross = grossFromNetAssets({ netAssets: 990n, referralFeePct: 10_000000000000000n });
|
|
15
|
+
* // gross satisfies bigint
|
|
16
|
+
* ```
|
|
17
|
+
*/
|
|
18
|
+
export declare const grossFromNetAssets: (params: {
|
|
19
|
+
readonly netAssets: bigint;
|
|
20
|
+
readonly referralFeePct: bigint;
|
|
21
|
+
}) => bigint;
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.grossFromNetAssets = void 0;
|
|
4
|
+
const blue_sdk_1 = require("@morpho-org/blue-sdk");
|
|
5
|
+
const index_js_1 = require("../types/index.js");
|
|
6
|
+
/**
|
|
7
|
+
* Computes the gross amount whose post-referral-fee proceeds equal `netAssets` exactly.
|
|
8
|
+
*
|
|
9
|
+
* @param params - Net target and WAD-scaled referral fee.
|
|
10
|
+
* @param params.netAssets - Required proceeds after the fee, in the asset's smallest unit.
|
|
11
|
+
* @param params.referralFeePct - Referral fee fraction scaled by WAD (`1e18`); must be below WAD.
|
|
12
|
+
* @returns The gross asset amount to pass to a bundles entrypoint.
|
|
13
|
+
* @throws {NegativeInputError} when `netAssets` or `referralFeePct` is negative.
|
|
14
|
+
* @throws {ReferralFeePctExceededError} when `referralFeePct >= WAD`.
|
|
15
|
+
* @example
|
|
16
|
+
* ```ts
|
|
17
|
+
* import { grossFromNetAssets } from "@morpho-org/morpho-sdk";
|
|
18
|
+
*
|
|
19
|
+
* const gross = grossFromNetAssets({ netAssets: 990n, referralFeePct: 10_000000000000000n });
|
|
20
|
+
* // gross satisfies bigint
|
|
21
|
+
* ```
|
|
22
|
+
*/
|
|
23
|
+
const grossFromNetAssets = (params) => {
|
|
24
|
+
if (params.netAssets < 0n) {
|
|
25
|
+
throw new index_js_1.NegativeInputError("netAssets", params.netAssets);
|
|
26
|
+
}
|
|
27
|
+
if (params.referralFeePct < 0n) {
|
|
28
|
+
throw new index_js_1.NegativeInputError("referralFeePct", params.referralFeePct);
|
|
29
|
+
}
|
|
30
|
+
if (params.referralFeePct >= blue_sdk_1.MathLib.WAD) {
|
|
31
|
+
throw new index_js_1.ReferralFeePctExceededError(params.referralFeePct);
|
|
32
|
+
}
|
|
33
|
+
return blue_sdk_1.MathLib.mulDivDown(params.netAssets, blue_sdk_1.MathLib.WAD, blue_sdk_1.MathLib.WAD - params.referralFeePct);
|
|
34
|
+
};
|
|
35
|
+
exports.grossFromNetAssets = grossFromNetAssets;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { type Market } from "@morpho-org/blue-sdk";
|
|
1
|
+
import { type AccrualVault, AccrualVaultV2, type Market } from "@morpho-org/blue-sdk";
|
|
2
2
|
/**
|
|
3
3
|
* Computes the minimum borrow share price (in RAY, 1e27) for slippage protection.
|
|
4
4
|
*
|
|
@@ -101,3 +101,92 @@ export declare function computeMinWithdrawSharePrice(params: {
|
|
|
101
101
|
market: Market;
|
|
102
102
|
slippageTolerance: bigint;
|
|
103
103
|
}): bigint;
|
|
104
|
+
/**
|
|
105
|
+
* Computes the RAY-scaled maximum share price for a VaultBundlesV1 deposit leg.
|
|
106
|
+
*
|
|
107
|
+
* Previews shares on both the supplied Vault V1 or Vault V2 snapshot and its deadline-accrued
|
|
108
|
+
* counterpart, dividing by the smaller of the two so the bound covers the highest price the
|
|
109
|
+
* bundle may execute at. Shares are previewed rounding down, mirroring the ERC-4626 `deposit()`
|
|
110
|
+
* shares the on-chain `maxSharePrice` check divides by.
|
|
111
|
+
*
|
|
112
|
+
* @param params - Vault snapshot, bundles execution deadline, net assets, and slippage.
|
|
113
|
+
* @param params.vaultData - Hydrated Vault V1 `AccrualVault` or Vault V2 `AccrualVaultV2` snapshot.
|
|
114
|
+
* @param params.deadline - Bundle execution deadline as a Unix timestamp in seconds, used for accrual.
|
|
115
|
+
* @param params.assets - Net assets deposited after referral fees, in the underlying token's smallest unit.
|
|
116
|
+
* @param params.slippageTolerance - Accepted share-price increase as a WAD-scaled fraction (`1e18` = 100%).
|
|
117
|
+
* @returns The capped maximum share price enforced by VaultBundlesV1.
|
|
118
|
+
* @throws {NonPositiveInputError} when `assets` or the previewed shares are not positive.
|
|
119
|
+
* @throws {NegativeInputError} when `slippageTolerance` is negative.
|
|
120
|
+
* @throws {ExcessiveSlippageToleranceError} when `slippageTolerance` exceeds the SDK maximum.
|
|
121
|
+
* @example
|
|
122
|
+
* ```ts
|
|
123
|
+
* import { fetchAccrualVault } from "@morpho-org/blue-sdk-viem";
|
|
124
|
+
* import { computeVaultMaxSharePrice } from "@morpho-org/morpho-sdk";
|
|
125
|
+
* import { createPublicClient, http } from "viem";
|
|
126
|
+
* import { mainnet } from "viem/chains";
|
|
127
|
+
*
|
|
128
|
+
* const client = createPublicClient({ chain: mainnet, transport: http() });
|
|
129
|
+
* const vaultData = await fetchAccrualVault(
|
|
130
|
+
* "0xBEEF01735c132Ada46AA9aA4c54623cAA92A64CB",
|
|
131
|
+
* client,
|
|
132
|
+
* );
|
|
133
|
+
* const { timestamp } = await client.getBlock();
|
|
134
|
+
* const maxSharePrice = computeVaultMaxSharePrice({
|
|
135
|
+
* vaultData,
|
|
136
|
+
* deadline: timestamp + 7_200n,
|
|
137
|
+
* assets: 1_000_000n,
|
|
138
|
+
* slippageTolerance: 500_000_000_000_000n,
|
|
139
|
+
* });
|
|
140
|
+
* // maxSharePrice satisfies bigint
|
|
141
|
+
* ```
|
|
142
|
+
*/
|
|
143
|
+
export declare const computeVaultMaxSharePrice: (params: {
|
|
144
|
+
readonly vaultData: AccrualVault | AccrualVaultV2;
|
|
145
|
+
readonly deadline: bigint;
|
|
146
|
+
readonly assets: bigint;
|
|
147
|
+
readonly slippageTolerance: bigint;
|
|
148
|
+
}) => bigint;
|
|
149
|
+
/**
|
|
150
|
+
* Computes the exact vault-share authorization cap for an asset-denominated exit.
|
|
151
|
+
*
|
|
152
|
+
* The cap covers both the current and deadline-accrued preview. Vault V2 and MetaMorpho 1.0 divide
|
|
153
|
+
* by `1 - slippageTolerance`, rounding up, to cover a share-price decline before inclusion;
|
|
154
|
+
* MetaMorpho 1.1's `lostAssets` clamp keeps that preview upper-bounded without widening it.
|
|
155
|
+
*
|
|
156
|
+
* @param params - Vault snapshot, execution deadline, asset amount, and WAD-scaled slippage.
|
|
157
|
+
* @param params.vaultData - Hydrated Vault V1 `AccrualVault` or Vault V2 `AccrualVaultV2` snapshot.
|
|
158
|
+
* @param params.deadline - Bundle execution deadline as a Unix timestamp in seconds, used for accrual.
|
|
159
|
+
* @param params.assets - Assets withdrawn from the vault, in the underlying token's smallest unit.
|
|
160
|
+
* @param params.slippageTolerance - Accepted share-price decline as a WAD-scaled fraction (`1e18` = 100%).
|
|
161
|
+
* @returns The maximum shares the prepared operation may burn.
|
|
162
|
+
* @throws {NonPositiveInputError} when `assets` or the computed share cap is not positive.
|
|
163
|
+
* @throws {NegativeInputError} when `slippageTolerance` is negative.
|
|
164
|
+
* @throws {ExcessiveSlippageToleranceError} when `slippageTolerance` exceeds the SDK maximum.
|
|
165
|
+
* @example
|
|
166
|
+
* ```ts
|
|
167
|
+
* import { fetchAccrualVault } from "@morpho-org/blue-sdk-viem";
|
|
168
|
+
* import { computeVaultMaxShareAllowance } from "@morpho-org/morpho-sdk";
|
|
169
|
+
* import { createPublicClient, http } from "viem";
|
|
170
|
+
* import { mainnet } from "viem/chains";
|
|
171
|
+
*
|
|
172
|
+
* const client = createPublicClient({ chain: mainnet, transport: http() });
|
|
173
|
+
* const vaultData = await fetchAccrualVault(
|
|
174
|
+
* "0xBEEF01735c132Ada46AA9aA4c54623cAA92A64CB",
|
|
175
|
+
* client,
|
|
176
|
+
* );
|
|
177
|
+
* const { timestamp } = await client.getBlock();
|
|
178
|
+
* const shares = computeVaultMaxShareAllowance({
|
|
179
|
+
* vaultData,
|
|
180
|
+
* deadline: timestamp + 7_200n,
|
|
181
|
+
* assets: 1_000_000n,
|
|
182
|
+
* slippageTolerance: 500_000_000_000_000n,
|
|
183
|
+
* });
|
|
184
|
+
* // shares is the exact allowance or permit value for the prepared exit.
|
|
185
|
+
* ```
|
|
186
|
+
*/
|
|
187
|
+
export declare const computeVaultMaxShareAllowance: (params: {
|
|
188
|
+
readonly vaultData: AccrualVault | AccrualVaultV2;
|
|
189
|
+
readonly deadline: bigint;
|
|
190
|
+
readonly assets: bigint;
|
|
191
|
+
readonly slippageTolerance: bigint;
|
|
192
|
+
}) => bigint;
|