@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,10 +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
|
-
const constant_js_1 = require("../../helpers/constant.js");
|
|
11
11
|
const index_js_2 = require("../../helpers/index.js");
|
|
12
|
+
const validate_js_1 = require("../../helpers/validate.js");
|
|
12
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");
|
|
13
16
|
class MorphoVaultV1 {
|
|
14
17
|
client;
|
|
15
18
|
vault;
|
|
@@ -31,100 +34,242 @@ class MorphoVaultV1 {
|
|
|
31
34
|
deployless: this.client.options.supportDeployless,
|
|
32
35
|
});
|
|
33
36
|
}
|
|
34
|
-
|
|
37
|
+
/** {@inheritDoc VaultV1Actions.deposit} */
|
|
38
|
+
deposit(params) {
|
|
39
|
+
const { userAddress, vaultData } = params;
|
|
40
|
+
const { asset: vaultAsset } = vaultData;
|
|
35
41
|
(0, index_js_2.validateChainId)(this.client.viemClient.chain?.id, this.chainId);
|
|
36
42
|
if (!(0, viem_1.isAddressEqual)(vaultData.address, this.vault)) {
|
|
37
43
|
throw new index_js_3.VaultAddressMismatchError(this.vault, vaultData.address);
|
|
38
44
|
}
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
if (!(0, viem_1.isAddressEqual)(vaultData.asset, wNative)) {
|
|
55
|
-
throw new index_js_3.NativeAmountOnNonWNativeVaultError(vaultData.asset, wNative);
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
const totalAssets = amount + (nativeAmount ?? 0n);
|
|
59
|
-
if (totalAssets === 0n) {
|
|
60
|
-
throw new index_js_3.NonPositiveInputError("totalAssets", totalAssets);
|
|
61
|
-
}
|
|
62
|
-
const shares = vaultData.toShares(totalAssets);
|
|
63
|
-
if (shares <= 0n) {
|
|
64
|
-
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);
|
|
65
60
|
}
|
|
66
|
-
const
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
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
|
+
},
|
|
79
115
|
buildTx: (signatures) => {
|
|
80
|
-
const
|
|
81
|
-
permit: true,
|
|
82
|
-
});
|
|
116
|
+
const requirementSignature = (0, common_js_1.selectBundlesTokenRequirementSignature)(signatures, expectedRequirement);
|
|
83
117
|
return (0, index_js_1.vaultV1Deposit)({
|
|
84
118
|
vault: {
|
|
85
119
|
chainId: this.chainId,
|
|
86
120
|
address: this.vault,
|
|
87
|
-
asset:
|
|
121
|
+
asset: vaultAsset,
|
|
88
122
|
},
|
|
89
123
|
args: {
|
|
90
|
-
|
|
124
|
+
...(funding.value > 0n
|
|
125
|
+
? { nativeAmount: funding.assets }
|
|
126
|
+
: { amount: funding.assets }),
|
|
91
127
|
maxSharePrice,
|
|
92
|
-
|
|
93
|
-
requirementSignature
|
|
94
|
-
|
|
128
|
+
userAddress,
|
|
129
|
+
requirementSignature,
|
|
130
|
+
referralFeePct: common.referralFeePct,
|
|
131
|
+
referralFeeRecipient: common.referralFeeRecipient,
|
|
132
|
+
deadline,
|
|
95
133
|
},
|
|
96
134
|
metadata: this.client.options.metadata,
|
|
97
135
|
});
|
|
98
136
|
},
|
|
99
|
-
};
|
|
137
|
+
});
|
|
100
138
|
}
|
|
101
|
-
withdraw(
|
|
139
|
+
withdraw(params) {
|
|
140
|
+
const { amount, userAddress } = params;
|
|
102
141
|
(0, index_js_2.validateChainId)(this.client.viemClient.chain?.id, this.chainId);
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
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: "vaultV1",
|
|
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.vaultV1Withdraw)({
|
|
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
|
+
});
|
|
114
215
|
}
|
|
115
|
-
|
|
216
|
+
/** {@inheritDoc VaultV1Actions.redeem} */
|
|
217
|
+
redeem(params) {
|
|
116
218
|
(0, index_js_2.validateChainId)(this.client.viemClient.chain?.id, this.chainId);
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
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: "vaultV1",
|
|
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.vaultV1Redeem)({
|
|
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
|
+
});
|
|
128
273
|
}
|
|
129
274
|
/** {@inheritDoc VaultV1Actions.inKindRedeem} */
|
|
130
275
|
inKindRedeem({ amount, marketParamsList, vaultData, userAddress, deadline: deadlineOverride, }) {
|
|
@@ -180,11 +325,12 @@ class MorphoVaultV1 {
|
|
|
180
325
|
maxExitAssets: covered,
|
|
181
326
|
});
|
|
182
327
|
}
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
.
|
|
328
|
+
const requiredShareAllowance = (0, index_js_2.computeVaultMaxShareAllowance)({
|
|
329
|
+
vaultData,
|
|
330
|
+
deadline: now,
|
|
331
|
+
assets: amount,
|
|
332
|
+
slippageTolerance: blue_sdk_1.DEFAULT_SLIPPAGE_TOLERANCE,
|
|
333
|
+
});
|
|
188
334
|
return {
|
|
189
335
|
getRequirements: async () => {
|
|
190
336
|
const requirementsTimestamp = morpho_ts_1.Time.timestamp();
|
|
@@ -287,66 +433,122 @@ class MorphoVaultV1 {
|
|
|
287
433
|
},
|
|
288
434
|
};
|
|
289
435
|
}
|
|
290
|
-
migrateToV2(
|
|
436
|
+
migrateToV2(params) {
|
|
291
437
|
(0, index_js_2.validateChainId)(this.client.viemClient.chain?.id, this.chainId);
|
|
292
|
-
if (!(0, viem_1.isAddressEqual)(sourceVault.address, this.vault)) {
|
|
293
|
-
throw new index_js_3.VaultAddressMismatchError(this.vault, sourceVault.address);
|
|
438
|
+
if (!(0, viem_1.isAddressEqual)(params.sourceVault.address, this.vault)) {
|
|
439
|
+
throw new index_js_3.VaultAddressMismatchError(this.vault, params.sourceVault.address);
|
|
294
440
|
}
|
|
295
|
-
if (!(0, viem_1.isAddressEqual)(sourceVault.asset, targetVault.asset)) {
|
|
296
|
-
throw new index_js_3.VaultAssetMismatchError(sourceVault.asset, targetVault.asset);
|
|
441
|
+
if (!(0, viem_1.isAddressEqual)(params.sourceVault.asset, params.targetVault.asset)) {
|
|
442
|
+
throw new index_js_3.VaultAssetMismatchError(params.sourceVault.asset, params.targetVault.asset);
|
|
297
443
|
}
|
|
298
|
-
if (
|
|
299
|
-
throw new index_js_3.
|
|
444
|
+
if ((0, viem_1.isAddressEqual)(this.vault, params.targetVault.address)) {
|
|
445
|
+
throw new index_js_3.SameVaultMigrationError(this.vault);
|
|
300
446
|
}
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
// Compute maxSharePriceVaultV2 for V2 deposit (slippage upward).
|
|
306
|
-
// Accrue VaultV2 interest forward to bound the on-chain share price at execution.
|
|
307
|
-
const targetAccrualTimestamp = blue_sdk_1.MathLib.max(morpho_ts_1.Time.timestamp(), targetVault.lastUpdate) + morpho_ts_1.Time.s.from.h(2n);
|
|
308
|
-
const { vault: accruedTargetVault } = targetVault.accrueInterest(targetAccrualTimestamp);
|
|
309
|
-
const v2RefShares = accruedTargetVault.toShares(v1RefAssets);
|
|
310
|
-
if (v2RefShares <= 0n) {
|
|
311
|
-
throw new index_js_3.NonPositiveInputError("targetVaultShares", v2RefShares);
|
|
447
|
+
const assets = "assets" in params ? params.assets : undefined;
|
|
448
|
+
const shares = "shares" in params ? params.shares : undefined;
|
|
449
|
+
if ((assets == null) === (shares == null)) {
|
|
450
|
+
throw new index_js_3.AmountAndSharesExclusiveError();
|
|
312
451
|
}
|
|
313
|
-
const
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
452
|
+
const selectedAmount = assets ?? shares ?? 0n;
|
|
453
|
+
if (selectedAmount <= 0n) {
|
|
454
|
+
throw new index_js_3.NonPositiveInputError(assets != null ? "assets" : "shares", selectedAmount);
|
|
455
|
+
}
|
|
456
|
+
const slippageTolerance = params.slippageTolerance ?? blue_sdk_1.DEFAULT_SLIPPAGE_TOLERANCE;
|
|
457
|
+
(0, index_js_2.validateSlippageTolerance)(slippageTolerance);
|
|
458
|
+
const createdAt = morpho_ts_1.Time.timestamp();
|
|
459
|
+
const deadline = params.deadline ?? createdAt + morpho_ts_1.Time.s.from.h(2n);
|
|
460
|
+
if (deadline <= createdAt)
|
|
461
|
+
throw new index_js_3.ExpiredDeadlineError(deadline, createdAt);
|
|
462
|
+
const common = (0, common_js_1.normalizeBundlesCommonParams)({
|
|
463
|
+
deadline,
|
|
464
|
+
referralFeePct: params.referralFeePct,
|
|
465
|
+
referralFeeRecipient: params.referralFeeRecipient,
|
|
466
|
+
});
|
|
467
|
+
const grossAssets = assets ?? params.sourceVault.toAssets(shares ?? 0n, "Down");
|
|
468
|
+
const referralFeeAssets = (0, common_js_1.getBundlesReferralFeeAssets)(grossAssets, common.referralFeePct);
|
|
469
|
+
const maxSharePriceVaultV2 = (0, index_js_2.computeVaultMaxSharePrice)({
|
|
470
|
+
vaultData: params.targetVault,
|
|
471
|
+
deadline,
|
|
472
|
+
assets: grossAssets - referralFeeAssets,
|
|
473
|
+
slippageTolerance,
|
|
474
|
+
});
|
|
475
|
+
const requiredShareAllowance = shares ??
|
|
476
|
+
(0, index_js_2.computeVaultMaxShareAllowance)({
|
|
477
|
+
vaultData: params.sourceVault,
|
|
478
|
+
deadline,
|
|
479
|
+
assets: assets ?? 0n,
|
|
480
|
+
slippageTolerance,
|
|
481
|
+
});
|
|
482
|
+
(0, morpho_ts_1.getChainAddress)(this.chainId, "bundles.vaultBundlesV1");
|
|
483
|
+
const { userAddress } = params;
|
|
484
|
+
const sourceAsset = params.sourceVault.asset;
|
|
485
|
+
const targetAddress = params.targetVault.address;
|
|
486
|
+
const targetAsset = params.targetVault.asset;
|
|
487
|
+
const domain = params.sourceVault.eip5267Domain;
|
|
488
|
+
const sourceToken = new blue_sdk_1.Token({
|
|
489
|
+
address: params.sourceVault.address,
|
|
490
|
+
name: params.sourceVault.name,
|
|
491
|
+
eip5267Domain: domain == null
|
|
492
|
+
? undefined
|
|
493
|
+
: new blue_sdk_1.Eip5267Domain({
|
|
494
|
+
...domain,
|
|
495
|
+
extensions: [...domain.extensions],
|
|
496
|
+
}),
|
|
497
|
+
});
|
|
498
|
+
let expectedRequirement;
|
|
499
|
+
return Object.freeze({
|
|
500
|
+
getRequirements: async () => {
|
|
501
|
+
const now = morpho_ts_1.Time.timestamp();
|
|
502
|
+
if (deadline <= now)
|
|
503
|
+
throw new index_js_3.ExpiredDeadlineError(deadline, now);
|
|
504
|
+
// Re-read the live share allowance on every call instead of caching the resolved
|
|
505
|
+
// requirements: in assets mode the calldata carries no share limit, so the allowance is
|
|
506
|
+
// the sole cap on the burn. A caller that executed the returned approval must see it
|
|
507
|
+
// satisfied on the next call, and an allowance revoked or raised afterwards must resurface
|
|
508
|
+
// as an outstanding requirement. The pinned snapshot and the cap derived from it stay
|
|
509
|
+
// fixed, so re-reading cannot move the cap this handle already committed to.
|
|
510
|
+
const requirements = await (0, getVaultBundlesSharesRequirements_js_1.getVaultBundlesSharesRequirements)(this.client.viemClient, {
|
|
511
|
+
vaultData: sourceToken,
|
|
512
|
+
version: "vaultV1",
|
|
513
|
+
owner: userAddress,
|
|
514
|
+
chainId: this.chainId,
|
|
515
|
+
requiredShareAllowance,
|
|
516
|
+
deadline,
|
|
517
|
+
supportSignature: this.client.options.supportSignature,
|
|
518
|
+
});
|
|
519
|
+
const signatureRequirement = requirements.find(index_js_3.isRequirementSignature);
|
|
520
|
+
expectedRequirement =
|
|
521
|
+
signatureRequirement?.action.type === "permit"
|
|
522
|
+
? signatureRequirement.action
|
|
523
|
+
: undefined;
|
|
524
|
+
return requirements;
|
|
525
|
+
},
|
|
327
526
|
buildTx: (signatures) => {
|
|
328
|
-
const
|
|
329
|
-
|
|
527
|
+
const permit = (0, common_js_1.selectBundlesSharesRequirementSignature)(signatures, {
|
|
528
|
+
requiredShareAllowance,
|
|
529
|
+
expectedRequirement,
|
|
330
530
|
});
|
|
331
531
|
return (0, index_js_1.vaultV1MigrateToV2)({
|
|
332
532
|
vault: {
|
|
333
533
|
chainId: this.chainId,
|
|
334
534
|
address: this.vault,
|
|
335
|
-
asset:
|
|
535
|
+
asset: sourceAsset,
|
|
336
536
|
},
|
|
337
537
|
args: {
|
|
338
|
-
targetVault:
|
|
339
|
-
targetAsset
|
|
340
|
-
shares,
|
|
341
|
-
minSharePriceVaultV1,
|
|
538
|
+
targetVault: targetAddress,
|
|
539
|
+
targetAsset,
|
|
540
|
+
...(assets != null ? { assets } : { shares: shares ?? 0n }),
|
|
342
541
|
maxSharePriceVaultV2,
|
|
343
|
-
|
|
542
|
+
userAddress,
|
|
344
543
|
requirementSignature: permit,
|
|
544
|
+
referralFeePct: common.referralFeePct,
|
|
545
|
+
referralFeeRecipient: common.referralFeeRecipient,
|
|
546
|
+
deadline,
|
|
345
547
|
},
|
|
346
548
|
metadata: this.client.options.metadata,
|
|
347
549
|
});
|
|
348
550
|
},
|
|
349
|
-
};
|
|
551
|
+
});
|
|
350
552
|
}
|
|
351
553
|
}
|
|
352
554
|
exports.MorphoVaultV1 = MorphoVaultV1;
|