@morpho-org/morpho-sdk 9.3.0-next.0 → 9.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +6 -4
- package/lib/cjs/abis.d.ts +2 -2
- package/lib/cjs/abis.js +4 -5
- package/lib/cjs/actions/blue/index.d.ts +1 -0
- package/lib/cjs/actions/blue/index.js +1 -0
- package/lib/cjs/actions/blue/withdrawBuyCallback.d.ts +60 -0
- package/lib/cjs/actions/blue/withdrawBuyCallback.js +79 -0
- package/lib/cjs/blue/abis.d.ts +1 -1
- package/lib/cjs/blue/abis.js +3 -5
- package/lib/cjs/blue/entities.d.ts +4 -4
- package/lib/cjs/blue/entities.js +1 -3
- package/lib/cjs/blue/errors.d.ts +2 -2
- package/lib/cjs/blue/errors.js +1 -5
- package/lib/cjs/blue/fetch.d.ts +2 -2
- package/lib/cjs/blue/fetch.js +1 -3
- package/lib/cjs/blue/utils.d.ts +1 -1
- package/lib/cjs/blue/utils.js +1 -2
- package/lib/cjs/entities/blue/blue.d.ts +85 -9
- package/lib/cjs/entities/blue/blue.js +85 -3
- package/lib/cjs/entities/index.d.ts +4 -4
- package/lib/cjs/entities/index.js +1 -3
- package/lib/cjs/entities/midnight/midnight.d.ts +1 -2
- package/lib/cjs/entities/midnight/midnight.js +4 -5
- package/lib/cjs/entities/requirements/getBundlesTokenRequirements.d.ts +5 -4
- package/lib/cjs/entities/requirements/getBundlesTokenRequirements.js +15 -12
- package/lib/cjs/entities/vaultV1/vaultV1.d.ts +0 -8
- package/lib/cjs/entities/vaultV1/vaultV1.js +0 -4
- package/lib/cjs/entities/vaultV2/vaultV2.d.ts +9 -37
- package/lib/cjs/entities/vaultV2/vaultV2.js +1 -36
- package/lib/cjs/entities/vaultV2BlueReallocationData.d.ts +3 -5
- package/lib/cjs/entities/vaultV2BlueReallocationData.js +3 -9
- package/lib/cjs/errors.d.ts +4 -4
- package/lib/cjs/errors.js +7 -10
- package/lib/cjs/fetch.d.ts +2 -2
- package/lib/cjs/fetch.js +1 -3
- package/lib/cjs/helpers/deadShares.d.ts +5 -4
- package/lib/cjs/helpers/deadShares.js +5 -6
- package/lib/cjs/midnight/abis.d.ts +1 -1
- package/lib/cjs/midnight/abis.js +2 -1
- package/lib/cjs/midnight/errors.d.ts +1 -2
- package/lib/cjs/midnight/errors.js +4 -5
- package/lib/cjs/types/action.d.ts +15 -1
- package/lib/cjs/types/error.d.ts +35 -6
- package/lib/cjs/types/error.js +42 -7
- package/lib/cjs/utils.d.ts +2 -2
- package/lib/cjs/utils.js +2 -4
- package/lib/esm/abis.d.ts +2 -2
- package/lib/esm/abis.js +2 -2
- package/lib/esm/actions/blue/index.d.ts +1 -0
- package/lib/esm/actions/blue/index.js +1 -0
- package/lib/esm/actions/blue/withdrawBuyCallback.d.ts +60 -0
- package/lib/esm/actions/blue/withdrawBuyCallback.js +75 -0
- package/lib/esm/blue/abis.d.ts +1 -1
- package/lib/esm/blue/abis.js +1 -1
- package/lib/esm/blue/entities.d.ts +4 -4
- package/lib/esm/blue/entities.js +2 -2
- package/lib/esm/blue/errors.d.ts +2 -2
- package/lib/esm/blue/errors.js +2 -2
- package/lib/esm/blue/fetch.d.ts +2 -2
- package/lib/esm/blue/fetch.js +2 -2
- package/lib/esm/blue/utils.d.ts +1 -1
- package/lib/esm/blue/utils.js +1 -1
- package/lib/esm/entities/blue/blue.d.ts +85 -9
- package/lib/esm/entities/blue/blue.js +87 -5
- package/lib/esm/entities/index.d.ts +4 -4
- package/lib/esm/entities/index.js +2 -2
- package/lib/esm/entities/midnight/midnight.d.ts +1 -2
- package/lib/esm/entities/midnight/midnight.js +5 -6
- package/lib/esm/entities/requirements/getBundlesTokenRequirements.d.ts +5 -4
- package/lib/esm/entities/requirements/getBundlesTokenRequirements.js +15 -12
- package/lib/esm/entities/vaultV1/vaultV1.d.ts +0 -8
- package/lib/esm/entities/vaultV1/vaultV1.js +0 -4
- package/lib/esm/entities/vaultV2/vaultV2.d.ts +9 -37
- package/lib/esm/entities/vaultV2/vaultV2.js +1 -36
- package/lib/esm/entities/vaultV2BlueReallocationData.d.ts +3 -5
- package/lib/esm/entities/vaultV2BlueReallocationData.js +3 -9
- package/lib/esm/errors.d.ts +4 -4
- package/lib/esm/errors.js +4 -4
- package/lib/esm/fetch.d.ts +2 -2
- package/lib/esm/fetch.js +2 -2
- package/lib/esm/helpers/deadShares.d.ts +5 -4
- package/lib/esm/helpers/deadShares.js +6 -7
- package/lib/esm/midnight/abis.d.ts +1 -1
- package/lib/esm/midnight/abis.js +1 -1
- package/lib/esm/midnight/errors.d.ts +1 -2
- package/lib/esm/midnight/errors.js +1 -2
- package/lib/esm/types/action.d.ts +15 -1
- package/lib/esm/types/error.d.ts +35 -6
- package/lib/esm/types/error.js +36 -6
- package/lib/esm/utils.d.ts +2 -2
- package/lib/esm/utils.js +2 -2
- package/package.json +6 -6
|
@@ -6,10 +6,10 @@ 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 abis_js_1 = require("../../abis.js");
|
|
9
10
|
const common_js_1 = require("../../actions/blue/common.js");
|
|
10
11
|
const index_js_1 = require("../../actions/index.js");
|
|
11
12
|
const validateClientChainId_js_1 = require("../../actions/requirements/validateClientChainId.js");
|
|
12
|
-
const deadShares_js_1 = require("../../helpers/deadShares.js");
|
|
13
13
|
const index_js_2 = require("../../helpers/index.js");
|
|
14
14
|
const validate_js_1 = require("../../helpers/validate.js");
|
|
15
15
|
const index_js_3 = require("../../types/index.js");
|
|
@@ -144,8 +144,6 @@ class MorphoBlue {
|
|
|
144
144
|
if (params.marketData.id !== this.marketParams.id) {
|
|
145
145
|
throw new index_js_3.MarketIdMismatchError(params.marketData.id, this.marketParams.id);
|
|
146
146
|
}
|
|
147
|
-
// Throws when the market lacks a sufficient dead deposit; nothing to return.
|
|
148
|
-
(0, deadShares_js_1.validateBlueMarketDeadShares)(params.marketData);
|
|
149
147
|
}
|
|
150
148
|
return {
|
|
151
149
|
getRequirements: (requirementsParams) => {
|
|
@@ -269,6 +267,90 @@ class MorphoBlue {
|
|
|
269
267
|
},
|
|
270
268
|
};
|
|
271
269
|
}
|
|
270
|
+
/** {@inheritDoc BlueActions.withdrawBuyCallback} */
|
|
271
|
+
withdrawBuyCallback(params) {
|
|
272
|
+
const { userAddress, callbackAddress, positionData } = params;
|
|
273
|
+
(0, index_js_2.validateChainId)(this.client.viemClient.chain?.id, this.chainId);
|
|
274
|
+
if (positionData == null) {
|
|
275
|
+
throw new index_js_3.MissingAccrualPositionError(this.marketParams.id);
|
|
276
|
+
}
|
|
277
|
+
(0, index_js_2.validateAccrualPosition)({
|
|
278
|
+
positionData,
|
|
279
|
+
expectedMarketId: this.marketParams.id,
|
|
280
|
+
expectedUser: callbackAddress,
|
|
281
|
+
});
|
|
282
|
+
const shares = positionData.supplyShares;
|
|
283
|
+
if (shares === 0n) {
|
|
284
|
+
throw new index_js_3.EmptyBlueSupplyPositionError({
|
|
285
|
+
market: this.marketParams.id,
|
|
286
|
+
user: callbackAddress,
|
|
287
|
+
});
|
|
288
|
+
}
|
|
289
|
+
const assets = positionData.supplyAssets;
|
|
290
|
+
const liquidity = positionData.market.liquidity;
|
|
291
|
+
if (assets > liquidity) {
|
|
292
|
+
throw new index_js_3.InsufficientBlueLiquidityError({
|
|
293
|
+
market: this.marketParams.id,
|
|
294
|
+
assets,
|
|
295
|
+
liquidity,
|
|
296
|
+
});
|
|
297
|
+
}
|
|
298
|
+
const blue = (0, morpho_ts_1.getChainAddress)(this.chainId, "blue");
|
|
299
|
+
const factory = (0, morpho_ts_1.getChainAddress)(this.chainId, "midnightBlueBuyCallbackFactory");
|
|
300
|
+
const tx = (0, index_js_1.blueWithdrawBuyCallback)({
|
|
301
|
+
market: { chainId: this.chainId, marketParams: this.marketParams },
|
|
302
|
+
args: { callbackAddress, userAddress, shares },
|
|
303
|
+
metadata: this.client.options.metadata,
|
|
304
|
+
});
|
|
305
|
+
return {
|
|
306
|
+
getRequirements: async () => {
|
|
307
|
+
const viemClient = this.client.viemClient;
|
|
308
|
+
await (0, validateClientChainId_js_1.validateClientChainId)(viemClient, this.chainId);
|
|
309
|
+
await (0, assertContractCode_js_1.assertRegistryTargetsHaveCode)(viemClient, this.chainId, [
|
|
310
|
+
{ role: "blue", address: blue },
|
|
311
|
+
{ role: "midnightBlueBuyCallbackFactory", address: factory },
|
|
312
|
+
]);
|
|
313
|
+
// Check the factory first: OWNER() on an arbitrary address can revert or lie.
|
|
314
|
+
const isBlueBuyCallback = await (0, actions_1.readContract)(viemClient, {
|
|
315
|
+
address: factory,
|
|
316
|
+
abi: abis_js_1.midnightBlueBuyCallbackFactoryAbi,
|
|
317
|
+
functionName: "isBlueBuyCallback",
|
|
318
|
+
args: [callbackAddress],
|
|
319
|
+
});
|
|
320
|
+
if (!isBlueBuyCallback) {
|
|
321
|
+
throw new index_js_3.NotBlueBuyCallbackError(callbackAddress);
|
|
322
|
+
}
|
|
323
|
+
const [owner, isAuthorized] = await Promise.all([
|
|
324
|
+
(0, actions_1.readContract)(viemClient, {
|
|
325
|
+
address: callbackAddress,
|
|
326
|
+
abi: abis_js_1.midnightBlueBuyCallbackAbi,
|
|
327
|
+
functionName: "OWNER",
|
|
328
|
+
}),
|
|
329
|
+
(0, actions_1.readContract)(viemClient, {
|
|
330
|
+
address: blue,
|
|
331
|
+
abi: abis_js_1.blueAbi,
|
|
332
|
+
functionName: "isAuthorized",
|
|
333
|
+
args: [callbackAddress, userAddress],
|
|
334
|
+
}),
|
|
335
|
+
]);
|
|
336
|
+
if (!(0, viem_1.isAddressEqual)(owner, userAddress)) {
|
|
337
|
+
throw new index_js_3.BlueBuyCallbackOwnerMismatchError({
|
|
338
|
+
callback: callbackAddress,
|
|
339
|
+
owner,
|
|
340
|
+
userAddress,
|
|
341
|
+
});
|
|
342
|
+
}
|
|
343
|
+
if (!isAuthorized) {
|
|
344
|
+
throw new index_js_3.BlueBuyCallbackUnauthorizedError({
|
|
345
|
+
callback: callbackAddress,
|
|
346
|
+
userAddress,
|
|
347
|
+
});
|
|
348
|
+
}
|
|
349
|
+
return [];
|
|
350
|
+
},
|
|
351
|
+
buildTx: () => tx,
|
|
352
|
+
};
|
|
353
|
+
}
|
|
272
354
|
/** {@inheritDoc BlueActions.supplyCollateral} */
|
|
273
355
|
supplyCollateral(params) {
|
|
274
356
|
const { userAddress, collateralAssets, nativeAmount, deadline, referralFeePct, referralFeeRecipient, } = params;
|
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
export type { IAccrualPosition as IBlueAccrualPosition, IAccrualVault, IAccrualVaultV2, IAccrualVaultV2Adapter,
|
|
1
|
+
export type { IAccrualPosition as IBlueAccrualPosition, IAccrualVault, IAccrualVaultV2, IAccrualVaultV2Adapter, IAccrualVaultV2MorphoMarketV1Adapter, IAccrualVaultV2MorphoMarketV1AdapterV2, IAccrualVaultV2MorphoVaultV1Adapter, IAssetBalances, IEip5267Domain, IHolding, IMarket as IBlueMarket, IMarketParams as IBlueMarketParams, IPosition as IBluePosition,
|
|
2
2
|
/** @deprecated Pre-liquidation support is deprecated and will be removed in the next major. */
|
|
3
3
|
IPreLiquidationParams as IBluePreLiquidationParams,
|
|
4
4
|
/** @deprecated Pre-liquidation support is deprecated and will be removed in the next major. */
|
|
5
|
-
IPreLiquidationPosition as IBluePreLiquidationPosition, IToken, IVault, IVaultConfig, IVaultMarketAllocation, IVaultMarketConfig, IVaultToken, IVaultUser, IVaultV2, IVaultV2Adapter, IVaultV2Allocation, IVaultV2BlueMarketPublicAllocatorConfig, IVaultV2BluePublicAllocatorConfig,
|
|
6
|
-
export { AccrualPosition as BlueAccrualPosition, AccrualVault, AccrualVaultV2,
|
|
5
|
+
IPreLiquidationPosition as IBluePreLiquidationPosition, IToken, IVault, IVaultConfig, IVaultMarketAllocation, IVaultMarketConfig, IVaultToken, IVaultUser, IVaultV2, IVaultV2Adapter, IVaultV2Allocation, IVaultV2BlueMarketPublicAllocatorConfig, IVaultV2BluePublicAllocatorConfig, IVaultV2MorphoMarketV1Adapter, IVaultV2MorphoMarketV1AdapterV2, IVaultV2MorphoVaultV1Adapter, PeripheralBalance, PeripheralBalanceType, } from "@morpho-org/blue-sdk";
|
|
6
|
+
export { AccrualPosition as BlueAccrualPosition, AccrualVault, AccrualVaultV2, AccrualVaultV2MorphoMarketV1Adapter, AccrualVaultV2MorphoMarketV1AdapterV2, AccrualVaultV2MorphoVaultV1Adapter, AssetBalances, ConstantWrappedToken, Eip5267Domain, ExchangeRateWrappedToken, Holding, Market as BlueMarket, MarketParams as BlueMarketParams, Position as BluePosition,
|
|
7
7
|
/** @deprecated Pre-liquidation support is deprecated and will be removed in the next major. */
|
|
8
8
|
PreLiquidationParams as BluePreLiquidationParams,
|
|
9
9
|
/** @deprecated Pre-liquidation support is deprecated and will be removed in the next major. */
|
|
10
|
-
PreLiquidationPosition as BluePreLiquidationPosition, Token, User as BlueUser, Vault, VaultConfig, VaultMarketAllocation, VaultMarketConfig, VaultToken, VaultUser, VaultV2, VaultV2Adapter, VaultV2BlueMarketPublicAllocatorConfig, VaultV2BluePublicAllocatorConfig,
|
|
10
|
+
PreLiquidationPosition as BluePreLiquidationPosition, Token, User as BlueUser, Vault, VaultConfig, VaultMarketAllocation, VaultMarketConfig, VaultToken, VaultUser, VaultV2, VaultV2Adapter, VaultV2BlueMarketPublicAllocatorConfig, VaultV2BluePublicAllocatorConfig, VaultV2MorphoMarketV1Adapter, VaultV2MorphoMarketV1AdapterV2, VaultV2MorphoVaultV1Adapter, WrappedToken, } from "@morpho-org/blue-sdk";
|
|
11
11
|
export type { AnyTree as MidnightAnyTree, AnyTreeSnapshot as MidnightAnyTreeSnapshot, BuildOfferParams as MidnightBuildOfferParams, CollateralParams as MidnightCollateralParams, EcrecoverTreeCreateRequest as MidnightEcrecoverTreeCreateRequest, GroupInput as MidnightGroupInput, IAccrualPosition as IMidnightAccrualPosition, ICollateralParams as IMidnightCollateralParams, IGroup as IMidnightGroup, IMarket as IMidnightMarket, IMarketParams as IMidnightMarketParams, IOffer as IMidnightOffer, IPosition as IMidnightPosition, MarketInput as MidnightMarketInput, OfferStruct as MidnightOfferStruct, PriceRatifierV1TreeCreateRequest as MidnightPriceRatifierV1TreeCreateRequest, RateRatifierV1TreeCreateRequest as MidnightRateRatifierV1TreeCreateRequest, RatifierKind as MidnightRatifierKind, RatifierTreeInput as MidnightRatifierTreeInput, RatifierTypes as MidnightRatifierTypes, SetterTreeCreateRequest as MidnightSetterTreeCreateRequest, SettlementFeeCbps as MidnightSettlementFeeCbps, TreeCreateParams as MidnightTreeCreateParams, TreeCreateRequest as MidnightTreeCreateRequest, TreeData as MidnightTreeData, TreeDescriptor as MidnightTreeDescriptor, TreeEntry as MidnightTreeEntry, TreeInput as MidnightTreeInput, TreeLike as MidnightTreeLike, TreeMempoolValidateParams as MidnightTreeMempoolValidateParams, TreeMempoolValidateRatification as MidnightTreeMempoolValidateRatification, TreeProof as MidnightTreeProof, TreeSnapshot as MidnightTreeSnapshot, TypedRatifierTreeInput as MidnightTypedRatifierTreeInput, TypedTreeMempoolValidateParams as MidnightTypedTreeMempoolValidateParams, } from "@morpho-org/midnight-sdk";
|
|
12
12
|
export { AccrualPosition as MidnightAccrualPosition, Group as MidnightGroup, Market as MidnightMarket, MarketParams as MidnightMarketParams, Offer as MidnightOffer, Position as MidnightPosition, Tree as MidnightTree, } from "@morpho-org/midnight-sdk";
|
|
13
13
|
export type { BlueActions, BlueTokenRequirementsParams, } from "./blue/index.js";
|
|
@@ -14,12 +14,11 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
14
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
exports.VaultV2BlueReallocationData = exports.MorphoVaultV2 = exports.MorphoVaultV1 = exports.MorphoMidnight = exports.MorphoBlue = exports.MidnightTree = exports.MidnightPosition = exports.MidnightOffer = exports.MidnightMarketParams = exports.MidnightMarket = exports.MidnightGroup = exports.MidnightAccrualPosition = exports.WrappedToken = exports.VaultV2MorphoVaultV1Adapter = exports.VaultV2MorphoMarketV1AdapterV2 = exports.VaultV2MorphoMarketV1Adapter = exports.
|
|
17
|
+
exports.VaultV2BlueReallocationData = exports.MorphoVaultV2 = exports.MorphoVaultV1 = exports.MorphoMidnight = exports.MorphoBlue = exports.MidnightTree = exports.MidnightPosition = exports.MidnightOffer = exports.MidnightMarketParams = exports.MidnightMarket = exports.MidnightGroup = exports.MidnightAccrualPosition = exports.WrappedToken = exports.VaultV2MorphoVaultV1Adapter = exports.VaultV2MorphoMarketV1AdapterV2 = exports.VaultV2MorphoMarketV1Adapter = exports.VaultV2BluePublicAllocatorConfig = exports.VaultV2BlueMarketPublicAllocatorConfig = exports.VaultV2Adapter = exports.VaultV2 = exports.VaultUser = exports.VaultToken = exports.VaultMarketConfig = exports.VaultMarketAllocation = exports.VaultConfig = exports.Vault = exports.BlueUser = exports.Token = exports.BluePreLiquidationPosition = exports.BluePreLiquidationParams = exports.BluePosition = exports.BlueMarketParams = exports.BlueMarket = exports.Holding = exports.ExchangeRateWrappedToken = exports.Eip5267Domain = exports.ConstantWrappedToken = exports.AssetBalances = exports.AccrualVaultV2MorphoVaultV1Adapter = exports.AccrualVaultV2MorphoMarketV1AdapterV2 = exports.AccrualVaultV2MorphoMarketV1Adapter = exports.AccrualVaultV2 = exports.AccrualVault = exports.BlueAccrualPosition = void 0;
|
|
18
18
|
var blue_sdk_1 = require("@morpho-org/blue-sdk");
|
|
19
19
|
Object.defineProperty(exports, "BlueAccrualPosition", { enumerable: true, get: function () { return blue_sdk_1.AccrualPosition; } });
|
|
20
20
|
Object.defineProperty(exports, "AccrualVault", { enumerable: true, get: function () { return blue_sdk_1.AccrualVault; } });
|
|
21
21
|
Object.defineProperty(exports, "AccrualVaultV2", { enumerable: true, get: function () { return blue_sdk_1.AccrualVaultV2; } });
|
|
22
|
-
Object.defineProperty(exports, "AccrualVaultV2MidnightAdapter", { enumerable: true, get: function () { return blue_sdk_1.AccrualVaultV2MidnightAdapter; } });
|
|
23
22
|
Object.defineProperty(exports, "AccrualVaultV2MorphoMarketV1Adapter", { enumerable: true, get: function () { return blue_sdk_1.AccrualVaultV2MorphoMarketV1Adapter; } });
|
|
24
23
|
Object.defineProperty(exports, "AccrualVaultV2MorphoMarketV1AdapterV2", { enumerable: true, get: function () { return blue_sdk_1.AccrualVaultV2MorphoMarketV1AdapterV2; } });
|
|
25
24
|
Object.defineProperty(exports, "AccrualVaultV2MorphoVaultV1Adapter", { enumerable: true, get: function () { return blue_sdk_1.AccrualVaultV2MorphoVaultV1Adapter; } });
|
|
@@ -47,7 +46,6 @@ Object.defineProperty(exports, "VaultV2", { enumerable: true, get: function () {
|
|
|
47
46
|
Object.defineProperty(exports, "VaultV2Adapter", { enumerable: true, get: function () { return blue_sdk_1.VaultV2Adapter; } });
|
|
48
47
|
Object.defineProperty(exports, "VaultV2BlueMarketPublicAllocatorConfig", { enumerable: true, get: function () { return blue_sdk_1.VaultV2BlueMarketPublicAllocatorConfig; } });
|
|
49
48
|
Object.defineProperty(exports, "VaultV2BluePublicAllocatorConfig", { enumerable: true, get: function () { return blue_sdk_1.VaultV2BluePublicAllocatorConfig; } });
|
|
50
|
-
Object.defineProperty(exports, "VaultV2MidnightAdapter", { enumerable: true, get: function () { return blue_sdk_1.VaultV2MidnightAdapter; } });
|
|
51
49
|
Object.defineProperty(exports, "VaultV2MorphoMarketV1Adapter", { enumerable: true, get: function () { return blue_sdk_1.VaultV2MorphoMarketV1Adapter; } });
|
|
52
50
|
Object.defineProperty(exports, "VaultV2MorphoMarketV1AdapterV2", { enumerable: true, get: function () { return blue_sdk_1.VaultV2MorphoMarketV1AdapterV2; } });
|
|
53
51
|
Object.defineProperty(exports, "VaultV2MorphoVaultV1Adapter", { enumerable: true, get: function () { return blue_sdk_1.VaultV2MorphoVaultV1Adapter; } });
|
|
@@ -894,8 +894,7 @@ export declare class MorphoMidnight {
|
|
|
894
894
|
* @throws {MidnightMarketLiquidationCursorNotEnabledError} when an uncreated market uses a disabled liquidation cursor.
|
|
895
895
|
* @throws {MidnightMarketOracleWithoutCodeError} when an uncreated market's oracle has no code.
|
|
896
896
|
* @throws {viem.BaseError} when a pinned block, contract, or oracle-code read fails.
|
|
897
|
-
* @throws {
|
|
898
|
-
* @throws {InsufficientDeadSharesError} when `blueMarket` holds fewer than `MIN_DEAD_SHARES` supply shares at `DEAD_ADDRESS`.
|
|
897
|
+
* @throws {EmptyBlueParkingMarketError} when `blueMarket` has no supply shares.
|
|
899
898
|
* @throws {ZeroBlueParkingSharesError} when `assetsToPark` would mint no supply shares at the current share price (checked at preparation time only).
|
|
900
899
|
* @throws {MidnightReplacementGroupCancelledError} when a published group is also cancelled.
|
|
901
900
|
* @throws {InvalidMidnightHexInputError} when a cancellation group or `callbackSalt` is not 32-byte hex.
|
|
@@ -11,7 +11,6 @@ const index_js_2 = require("../../actions/requirements/index.js");
|
|
|
11
11
|
const validateClientChainId_js_1 = require("../../actions/requirements/validateClientChainId.js");
|
|
12
12
|
const callback_js_1 = require("../../helpers/callback.js");
|
|
13
13
|
const constant_js_1 = require("../../helpers/constant.js");
|
|
14
|
-
const deadShares_js_1 = require("../../helpers/deadShares.js");
|
|
15
14
|
const encodeMidnightCalldata_js_1 = require("../../helpers/encodeMidnightCalldata.js");
|
|
16
15
|
const index_js_3 = require("../../helpers/index.js");
|
|
17
16
|
const validateMidnightAccount_js_1 = require("../../helpers/validateMidnightAccount.js");
|
|
@@ -1530,8 +1529,7 @@ class MorphoMidnight {
|
|
|
1530
1529
|
* @throws {MidnightMarketLiquidationCursorNotEnabledError} when an uncreated market uses a disabled liquidation cursor.
|
|
1531
1530
|
* @throws {MidnightMarketOracleWithoutCodeError} when an uncreated market's oracle has no code.
|
|
1532
1531
|
* @throws {viem.BaseError} when a pinned block, contract, or oracle-code read fails.
|
|
1533
|
-
* @throws {
|
|
1534
|
-
* @throws {InsufficientDeadSharesError} when `blueMarket` holds fewer than `MIN_DEAD_SHARES` supply shares at `DEAD_ADDRESS`.
|
|
1532
|
+
* @throws {EmptyBlueParkingMarketError} when `blueMarket` has no supply shares.
|
|
1535
1533
|
* @throws {ZeroBlueParkingSharesError} when `assetsToPark` would mint no supply shares at the current share price (checked at preparation time only).
|
|
1536
1534
|
* @throws {MidnightReplacementGroupCancelledError} when a published group is also cancelled.
|
|
1537
1535
|
* @throws {InvalidMidnightHexInputError} when a cancellation group or `callbackSalt` is not 32-byte hex.
|
|
@@ -1587,8 +1585,9 @@ class MorphoMidnight {
|
|
|
1587
1585
|
}),
|
|
1588
1586
|
]);
|
|
1589
1587
|
const market = (0, morpho_ts_1._try)(() => fetched.accrueInterest(blue_sdk_1.MathLib.max(morpho_ts_1.Time.timestamp(), fetched.lastUpdate)), blue_sdk_1.UnsupportedMarketIrmError) ?? fetched;
|
|
1590
|
-
|
|
1591
|
-
|
|
1588
|
+
if (market.totalSupplyShares === 0n) {
|
|
1589
|
+
throw new index_js_4.EmptyBlueParkingMarketError({ marketId: blueMarketId });
|
|
1590
|
+
}
|
|
1592
1591
|
if (market.toSupplyShares(params.assetsToPark, "Down") === 0n) {
|
|
1593
1592
|
throw new index_js_4.ZeroBlueParkingSharesError({
|
|
1594
1593
|
marketId: blueMarketId,
|
|
@@ -29,10 +29,11 @@ export interface GetBundlesTokenRequirementsParams {
|
|
|
29
29
|
* Resolves direct approval, ERC-2612, or Permit2 SignatureTransfer prerequisites for
|
|
30
30
|
* a registered fixed bundles contract.
|
|
31
31
|
*
|
|
32
|
-
*
|
|
33
|
-
*
|
|
34
|
-
*
|
|
35
|
-
* the
|
|
32
|
+
* Returns no requirements when the direct bundles allowance covers the amount, even when
|
|
33
|
+
* signatures are supported. Otherwise reads only the state required by the selected path.
|
|
34
|
+
* Permit2 keeps the ERC-20 allowance on canonical Permit2 while the one-time signed transfer
|
|
35
|
+
* names the bundles contract as spender. The resolver picks the lowest unused unordered nonce
|
|
36
|
+
* by default; concurrent flows for the same owner should pass explicit nonces.
|
|
36
37
|
*
|
|
37
38
|
* @param viemClient - Connected viem client used for allowance and nonce reads.
|
|
38
39
|
* @param params - Token requirement parameters.
|
|
@@ -16,10 +16,11 @@ const getUnusedPermit2Nonce_js_1 = require("./getUnusedPermit2Nonce.js");
|
|
|
16
16
|
* Resolves direct approval, ERC-2612, or Permit2 SignatureTransfer prerequisites for
|
|
17
17
|
* a registered fixed bundles contract.
|
|
18
18
|
*
|
|
19
|
-
*
|
|
20
|
-
*
|
|
21
|
-
*
|
|
22
|
-
* the
|
|
19
|
+
* Returns no requirements when the direct bundles allowance covers the amount, even when
|
|
20
|
+
* signatures are supported. Otherwise reads only the state required by the selected path.
|
|
21
|
+
* Permit2 keeps the ERC-20 allowance on canonical Permit2 while the one-time signed transfer
|
|
22
|
+
* names the bundles contract as spender. The resolver picks the lowest unused unordered nonce
|
|
23
|
+
* by default; concurrent flows for the same owner should pass explicit nonces.
|
|
23
24
|
*
|
|
24
25
|
* @param viemClient - Connected viem client used for allowance and nonce reads.
|
|
25
26
|
* @param params - Token requirement parameters.
|
|
@@ -122,6 +123,14 @@ const getBundlesTokenRequirements = async (viemClient, params) => {
|
|
|
122
123
|
if (params.amount === 0n)
|
|
123
124
|
return [];
|
|
124
125
|
await (0, validateClientChainId_js_1.validateClientChainId)(viemClient, params.chainId);
|
|
126
|
+
const allowance = await (0, actions_1.readContract)(viemClient, {
|
|
127
|
+
abi: viem_1.erc20Abi,
|
|
128
|
+
address: params.token,
|
|
129
|
+
functionName: "allowance",
|
|
130
|
+
args: [params.owner, params.spender],
|
|
131
|
+
});
|
|
132
|
+
if (allowance >= params.amount)
|
|
133
|
+
return [];
|
|
125
134
|
const { permit2, dai } = (0, blue_sdk_1.getChainAddresses)(params.chainId);
|
|
126
135
|
if (params.supportSignature) {
|
|
127
136
|
const isDai = (0, morpho_ts_1.isDefined)(dai) && (0, viem_1.isAddressEqual)(params.token, dai);
|
|
@@ -174,7 +183,7 @@ const getBundlesTokenRequirements = async (viemClient, params) => {
|
|
|
174
183
|
});
|
|
175
184
|
}
|
|
176
185
|
const wordPosition = permit2Nonce >> 8n;
|
|
177
|
-
const [
|
|
186
|
+
const [permit2Allowance, nonceBitmap] = await Promise.all([
|
|
178
187
|
(0, actions_1.readContract)(viemClient, {
|
|
179
188
|
abi: viem_1.erc20Abi,
|
|
180
189
|
address: params.token,
|
|
@@ -198,19 +207,13 @@ const getBundlesTokenRequirements = async (viemClient, params) => {
|
|
|
198
207
|
now: timestamp,
|
|
199
208
|
state: {
|
|
200
209
|
type: "permit2SignatureTransfer",
|
|
201
|
-
permit2Allowance
|
|
210
|
+
permit2Allowance,
|
|
202
211
|
permit2Nonce,
|
|
203
212
|
nonceBitmap,
|
|
204
213
|
},
|
|
205
214
|
});
|
|
206
215
|
}
|
|
207
216
|
}
|
|
208
|
-
const allowance = await (0, actions_1.readContract)(viemClient, {
|
|
209
|
-
abi: viem_1.erc20Abi,
|
|
210
|
-
address: params.token,
|
|
211
|
-
functionName: "allowance",
|
|
212
|
-
args: [params.owner, params.spender],
|
|
213
|
-
});
|
|
214
217
|
return (0, index_js_1.resolveBundlesTokenRequirements)({
|
|
215
218
|
token: params.token,
|
|
216
219
|
spender: params.spender,
|
|
@@ -104,10 +104,6 @@ export interface VaultV1Actions {
|
|
|
104
104
|
* const tx = action.buildTx(); // For a client configured with supportSignature: false.
|
|
105
105
|
* // tx satisfies Readonly<Transaction<VaultV1DepositAction>>
|
|
106
106
|
* ```
|
|
107
|
-
* @throws {MissingDeadSharesDataError} when `vaultData` lacks the dead-share, cap or adapter data
|
|
108
|
-
* the dead-deposit check needs, such as a hand-built or API-sourced snapshot.
|
|
109
|
-
* @throws {InsufficientDeadSharesError} when the vault, or a market or vault it can allocate to,
|
|
110
|
-
* holds less than the required dead deposit.
|
|
111
107
|
*/
|
|
112
108
|
deposit: (params: {
|
|
113
109
|
readonly userAddress: Address;
|
|
@@ -461,10 +457,6 @@ export interface VaultV1Actions {
|
|
|
461
457
|
* const tx = migration.buildTx(signatures);
|
|
462
458
|
* // tx satisfies Readonly<Transaction<VaultV1MigrateToV2Action>>
|
|
463
459
|
* ```
|
|
464
|
-
* @throws {MissingDeadSharesDataError} when `targetVault` lacks the dead-share, cap or adapter data
|
|
465
|
-
* the dead-deposit check needs. The source Vault V1 is not checked.
|
|
466
|
-
* @throws {InsufficientDeadSharesError} when `targetVault`, or a market or vault it can allocate
|
|
467
|
-
* to, holds less than the required dead deposit.
|
|
468
460
|
*/
|
|
469
461
|
migrateToV2: (params: {
|
|
470
462
|
readonly userAddress: Address;
|
|
@@ -9,7 +9,6 @@ const actions_1 = require("viem/actions");
|
|
|
9
9
|
const common_js_1 = require("../../actions/bundles/common.js");
|
|
10
10
|
const index_js_1 = require("../../actions/index.js");
|
|
11
11
|
const validateClientChainId_js_1 = require("../../actions/requirements/validateClientChainId.js");
|
|
12
|
-
const deadShares_js_1 = require("../../helpers/deadShares.js");
|
|
13
12
|
const index_js_2 = require("../../helpers/index.js");
|
|
14
13
|
const validate_js_1 = require("../../helpers/validate.js");
|
|
15
14
|
const index_js_3 = require("../../types/index.js");
|
|
@@ -79,8 +78,6 @@ class MorphoVaultV1 {
|
|
|
79
78
|
// The native path must target the chain's registered wrapped-native asset.
|
|
80
79
|
(0, validate_js_1.validateNativeVaultAsset)(this.chainId, vaultAsset);
|
|
81
80
|
}
|
|
82
|
-
// Throws when the vault, or a market it can allocate to, lacks a sufficient dead deposit.
|
|
83
|
-
(0, deadShares_js_1.validateVaultV1DeadShares)(vaultData);
|
|
84
81
|
const referralFeeAssets = (0, common_js_1.getBundlesReferralFeeAssets)(funding.assets, common.referralFeePct);
|
|
85
82
|
const maxSharePrice = (0, index_js_2.computeVaultMaxSharePrice)({
|
|
86
83
|
vaultData,
|
|
@@ -476,7 +473,6 @@ class MorphoVaultV1 {
|
|
|
476
473
|
referralFeeRecipient: params.referralFeeRecipient,
|
|
477
474
|
});
|
|
478
475
|
// Only the destination receives a deposit; the source vault is an exit.
|
|
479
|
-
(0, deadShares_js_1.validateVaultV2DeadShares)(params.targetVault);
|
|
480
476
|
// V1 redeem accrues market interest and performance fees before converting shares.
|
|
481
477
|
const grossAssets = assets ??
|
|
482
478
|
params.sourceVault
|
|
@@ -69,9 +69,8 @@ export interface VaultV2Actions {
|
|
|
69
69
|
* owner is consumed and none was passed explicitly.
|
|
70
70
|
* @throws {Permit2SignatureTransferNonceAlreadyUsedError} from `getRequirements()` when the
|
|
71
71
|
* explicit Permit2 nonce is consumed.
|
|
72
|
-
* @throws {InputExceedsMaxError} when funding or the deadline exceeds uint256,
|
|
73
|
-
*
|
|
74
|
-
* fits and `max` is `0n`), or from `getRequirements()` when the Permit2 nonce exceeds uint256.
|
|
72
|
+
* @throws {InputExceedsMaxError} when funding or the deadline exceeds uint256, or from
|
|
73
|
+
* `getRequirements()` when the Permit2 nonce exceeds uint256.
|
|
75
74
|
* @throws {AmbiguousRequirementSignaturesError} from `buildTx()` when multiple token signatures are supplied.
|
|
76
75
|
* @throws {UnexpectedRequirementSignatureError} from `buildTx()` when an unsupported signature is supplied.
|
|
77
76
|
* @throws {BundlesPermitMismatchError} from `buildTx()` when the signature's spender, amount or
|
|
@@ -111,10 +110,6 @@ export interface VaultV2Actions {
|
|
|
111
110
|
* const tx = action.buildTx(); // For a client configured with supportSignature: false.
|
|
112
111
|
* // tx satisfies Readonly<Transaction<VaultV2DepositAction>>
|
|
113
112
|
* ```
|
|
114
|
-
* @throws {MissingDeadSharesDataError} when `vaultData` lacks the dead-share, cap or adapter data
|
|
115
|
-
* the dead-deposit check needs, such as a hand-built or API-sourced snapshot.
|
|
116
|
-
* @throws {InsufficientDeadSharesError} when the vault, or a market or vault it can allocate to,
|
|
117
|
-
* holds less than the required dead deposit.
|
|
118
113
|
*/
|
|
119
114
|
deposit: (params: {
|
|
120
115
|
readonly userAddress: Address;
|
|
@@ -157,9 +152,7 @@ export interface VaultV2Actions {
|
|
|
157
152
|
* @throws {NonPositiveInputError} when `amount` or the computed required share amount is not positive.
|
|
158
153
|
* @throws {ExpiredDeadlineError} when `deadline` is not in the future at handle creation or
|
|
159
154
|
* at any `getRequirements()` call.
|
|
160
|
-
* @throws {InputExceedsMaxError} when `amount` or `deadline` exceeds uint256 at handle creation
|
|
161
|
-
* or when the vault's liquidity adapter is a Midnight adapter and `amount` exceeds the vault's
|
|
162
|
-
* idle assets.
|
|
155
|
+
* @throws {InputExceedsMaxError} when `amount` or `deadline` exceeds uint256 at handle creation.
|
|
163
156
|
* @throws {NegativeInputError} when `referralFeePct` or `slippageTolerance` is negative.
|
|
164
157
|
* @throws {ReferralFeePctExceededError} when `referralFeePct` is at least WAD.
|
|
165
158
|
* @throws {ReferralFeeRecipientMissingError} when a positive referral fee has no nonzero recipient.
|
|
@@ -225,24 +218,7 @@ export interface VaultV2Actions {
|
|
|
225
218
|
* @throws {NonPositiveInputError} when `shares` is not positive.
|
|
226
219
|
* @throws {ExpiredDeadlineError} when `deadline` is not in the future at handle creation or
|
|
227
220
|
* requirement resolution.
|
|
228
|
-
* @throws {InputExceedsMaxError} when `shares` or `deadline` exceeds uint256
|
|
229
|
-
* `getRequirements()` when the vault's liquidity adapter is a Midnight adapter and `shares`
|
|
230
|
-
* are worth more than the vault's idle assets.
|
|
231
|
-
* @throws {UnknownBlueFactory} from `getRequirements()` when the configured chain has no VaultV2 factory.
|
|
232
|
-
* @throws {UnknownBlueOfFactory} from `getRequirements()` when the vault is not a VaultV2 from the
|
|
233
|
-
* configured factory.
|
|
234
|
-
* @throws {UnsupportedBlueVaultV2AdapterError} from `getRequirements()` when the vault or one of its
|
|
235
|
-
* adapters uses an unsupported adapter class.
|
|
236
|
-
* @throws {UnsupportedBlueMarketIrmError} from `getRequirements()` when the vault's liquidity adapter
|
|
237
|
-
* is a Midnight adapter and accrual projects an underlying market with positive debt that uses an
|
|
238
|
-
* unsupported IRM.
|
|
239
|
-
* @throws {UnknownBlueMarketAllocationError} from `getRequirements()` when the vault's liquidity
|
|
240
|
-
* adapter is a Midnight adapter and accrual meets a nested Vault V1 withdraw queue market without
|
|
241
|
-
* allocation data.
|
|
242
|
-
* @throws {InvalidMidnightPositionLossFactorError} from `getRequirements()` when the vault's liquidity
|
|
243
|
-
* adapter is a Midnight adapter and accrual meets a market loss factor below a position's.
|
|
244
|
-
* @throws {InvalidMidnightPositionAccrualStateError} from `getRequirements()` when the vault's
|
|
245
|
-
* liquidity adapter is a Midnight adapter and accrual meets invalid Midnight position inputs.
|
|
221
|
+
* @throws {InputExceedsMaxError} when `shares` or `deadline` exceeds uint256.
|
|
246
222
|
* @throws {NegativeInputError} when `referralFeePct` is negative.
|
|
247
223
|
* @throws {ReferralFeePctExceededError} when `referralFeePct` is not below WAD.
|
|
248
224
|
* @throws {ReferralFeeRecipientMissingError} when a positive fee has no non-zero recipient.
|
|
@@ -250,7 +226,7 @@ export interface VaultV2Actions {
|
|
|
250
226
|
* @throws {UnknownAddressError} when VaultBundlesV1 is not registered on the target chain.
|
|
251
227
|
* @throws {MissingContractCodeError} from `getRequirements()` when a fixed bundles or protocol
|
|
252
228
|
* contract has no code at its registered address.
|
|
253
|
-
* @throws {viem.BaseError} from `getRequirements()` when
|
|
229
|
+
* @throws {viem.BaseError} from `getRequirements()` when an allowance, nonce, `eth_chainId`, or
|
|
254
230
|
* `eth_getCode` read fails.
|
|
255
231
|
* @throws {UnknownTokenError} from `getRequirements()` when the share token fetched by
|
|
256
232
|
* `getData()` has unusable decimals.
|
|
@@ -328,11 +304,9 @@ export interface VaultV2Actions {
|
|
|
328
304
|
* @throws {InputExceedsMaxError} when `deadline` exceeds `uint256`.
|
|
329
305
|
* @throws {ExpiredDeadlineError} when `deadline` is not in the future at handle creation or
|
|
330
306
|
* requirement resolution.
|
|
331
|
-
* @throws {VaultV2SingleAdapterRequiredError} when the vault does not have one adapter
|
|
332
|
-
* a vault that mixes Blue and Midnight adapters.
|
|
307
|
+
* @throws {VaultV2SingleAdapterRequiredError} when the vault does not have one adapter.
|
|
333
308
|
* @throws {AdapterNotPartOfVaultError} when `adapter` is not the vault's adapter.
|
|
334
|
-
* @throws {VaultV2UnsupportedExitAdapterError} when the adapter is not a MorphoMarketV1AdapterV2
|
|
335
|
-
* including a Midnight adapter.
|
|
309
|
+
* @throws {VaultV2UnsupportedExitAdapterError} when the adapter is not a MorphoMarketV1AdapterV2.
|
|
336
310
|
* @throws {InKindRedeemCoverageError} when the deduplicated list cannot cover the exit.
|
|
337
311
|
* @throws {UnsupportedChainIdError} when no address registry exists for the target chain.
|
|
338
312
|
* @throws {UnknownAddressError} when VaultExitBundlesV1 is not registered on the target chain.
|
|
@@ -457,11 +431,9 @@ export interface VaultV2Actions {
|
|
|
457
431
|
* @throws {ExpiredDeadlineError} when `deadline` is not in the future at handle creation or
|
|
458
432
|
* requirement resolution.
|
|
459
433
|
* @throws {ExcessiveSlippageToleranceError} when `slippageTolerance` exceeds the SDK maximum.
|
|
460
|
-
* @throws {VaultV2SingleAdapterRequiredError} when the vault does not have exactly one adapter
|
|
461
|
-
* including a vault that mixes Blue and Midnight adapters.
|
|
434
|
+
* @throws {VaultV2SingleAdapterRequiredError} when the vault does not have exactly one adapter.
|
|
462
435
|
* @throws {AdapterNotPartOfVaultError} when `adapter` is not the vault's adapter.
|
|
463
|
-
* @throws {VaultV2UnsupportedExitAdapterError} when the adapter is not a MorphoMarketV1AdapterV2
|
|
464
|
-
* including a Midnight adapter.
|
|
436
|
+
* @throws {VaultV2UnsupportedExitAdapterError} when the adapter is not a MorphoMarketV1AdapterV2.
|
|
465
437
|
* @throws {VaultV2UnsupportedLiquidityAdapterError} when the vault routes liquidity through
|
|
466
438
|
* another adapter.
|
|
467
439
|
* @throws {VaultV2UndecodableLiquidityDataError} when the vault's `liquidityData` does not decode
|
|
@@ -9,7 +9,6 @@ const actions_1 = require("viem/actions");
|
|
|
9
9
|
const common_js_1 = require("../../actions/bundles/common.js");
|
|
10
10
|
const index_js_1 = require("../../actions/index.js");
|
|
11
11
|
const validateClientChainId_js_1 = require("../../actions/requirements/validateClientChainId.js");
|
|
12
|
-
const deadShares_js_1 = require("../../helpers/deadShares.js");
|
|
13
12
|
const index_js_2 = require("../../helpers/index.js");
|
|
14
13
|
const validate_js_1 = require("../../helpers/validate.js");
|
|
15
14
|
const index_js_3 = require("../../types/index.js");
|
|
@@ -19,11 +18,6 @@ const index_js_4 = require("../requirements/index.js");
|
|
|
19
18
|
// Maximum accepted deadline horizon; the on-chain management fee is capped at 5%/yr so the
|
|
20
19
|
// accrual model stays well-defined inside it.
|
|
21
20
|
const VAULT_V2_FEE_PROJECTION_HORIZON = morpho_ts_1.Time.s.from.y(1n);
|
|
22
|
-
/**
|
|
23
|
-
* Midnight adapters revert vault-initiated `allocate` and `deallocate` (`SelfAllocationOnly`), so a
|
|
24
|
-
* vault routing liquidity through one accepts no deposit and serves exits from idle assets only.
|
|
25
|
-
*/
|
|
26
|
-
const isMidnightLiquidityAdapter = (vaultData) => vaultData.accrualLiquidityAdapter?.type === "VaultV2MidnightAdapter";
|
|
27
21
|
/** Binds a viem client to a Vault V2 vault's action builders. */
|
|
28
22
|
class MorphoVaultV2 {
|
|
29
23
|
client;
|
|
@@ -87,15 +81,6 @@ class MorphoVaultV2 {
|
|
|
87
81
|
// The native path must target the chain's registered wrapped-native asset.
|
|
88
82
|
(0, validate_js_1.validateNativeVaultAsset)(this.chainId, vaultAsset);
|
|
89
83
|
}
|
|
90
|
-
if (isMidnightLiquidityAdapter(vaultData)) {
|
|
91
|
-
throw new index_js_3.InputExceedsMaxError({
|
|
92
|
-
field: funding.value > 0n ? "nativeAmount" : "amount",
|
|
93
|
-
value: funding.assets,
|
|
94
|
-
max: 0n,
|
|
95
|
-
});
|
|
96
|
-
}
|
|
97
|
-
// Throws when the vault, or a market it can allocate to, lacks a sufficient dead deposit.
|
|
98
|
-
(0, deadShares_js_1.validateVaultV2DeadShares)(vaultData);
|
|
99
84
|
const referralFeeAssets = (0, common_js_1.getBundlesReferralFeeAssets)(funding.assets, common.referralFeePct);
|
|
100
85
|
const maxSharePrice = (0, index_js_2.computeVaultMaxSharePrice)({
|
|
101
86
|
vaultData,
|
|
@@ -179,14 +164,6 @@ class MorphoVaultV2 {
|
|
|
179
164
|
throw new index_js_3.NonPositiveInputError("amount", amount);
|
|
180
165
|
// Reject values outside the ABI range before resolving any requirements.
|
|
181
166
|
(0, validate_js_1.validateUint256Field)("amount", amount);
|
|
182
|
-
if (isMidnightLiquidityAdapter(vaultData) &&
|
|
183
|
-
amount > vaultData.assetBalance) {
|
|
184
|
-
throw new index_js_3.InputExceedsMaxError({
|
|
185
|
-
field: "amount",
|
|
186
|
-
value: amount,
|
|
187
|
-
max: vaultData.assetBalance,
|
|
188
|
-
});
|
|
189
|
-
}
|
|
190
167
|
const createdAt = morpho_ts_1.Time.timestamp();
|
|
191
168
|
const deadline = params.deadline ?? createdAt + morpho_ts_1.Time.s.from.h(2n);
|
|
192
169
|
if (deadline <= createdAt)
|
|
@@ -267,20 +244,8 @@ class MorphoVaultV2 {
|
|
|
267
244
|
if (deadline <= now)
|
|
268
245
|
throw new index_js_3.ExpiredDeadlineError(deadline, now);
|
|
269
246
|
await this.assertWriteTargets(["bundles.vaultBundlesV1"]);
|
|
270
|
-
const vaultData = await this.getData();
|
|
271
|
-
if (isMidnightLiquidityAdapter(vaultData)) {
|
|
272
|
-
// Onchain redeem accrues interest before converting shares to assets.
|
|
273
|
-
const { vault: accrued } = vaultData.accrueInterest(now);
|
|
274
|
-
if (accrued.toAssets(shares) > accrued.assetBalance) {
|
|
275
|
-
throw new index_js_3.InputExceedsMaxError({
|
|
276
|
-
field: "shares",
|
|
277
|
-
value: shares,
|
|
278
|
-
max: accrued.toShares(accrued.assetBalance),
|
|
279
|
-
});
|
|
280
|
-
}
|
|
281
|
-
}
|
|
282
247
|
return (0, getVaultBundlesSharesRequirements_js_1.getVaultBundlesSharesRequirements)(this.client.viemClient, {
|
|
283
|
-
vaultData,
|
|
248
|
+
vaultData: await this.getData(),
|
|
284
249
|
version: "vaultV2",
|
|
285
250
|
owner: userAddress,
|
|
286
251
|
chainId: this.chainId,
|
|
@@ -56,9 +56,8 @@ export interface InputVaultV2BlueReallocationData {
|
|
|
56
56
|
/**
|
|
57
57
|
* Immutable-by-convention state container for Vault V2 BluePublicAllocator simulations.
|
|
58
58
|
*
|
|
59
|
-
* Constructor inputs are cloned
|
|
60
|
-
*
|
|
61
|
-
* reallocation returns a new instance. Planning keeps the transaction-scoped `firstTotalAssets`
|
|
59
|
+
* Constructor inputs are cloned. Every simulated reallocation returns a new
|
|
60
|
+
* instance. Planning keeps the transaction-scoped `firstTotalAssets`
|
|
62
61
|
* denominator outside the durable snapshot while applying reallocations in
|
|
63
62
|
* contract order. Penalty donations update simulated vault accounting but are
|
|
64
63
|
* excluded from same-plan idle liquidity so round-up dust cannot create
|
|
@@ -132,8 +131,7 @@ export declare class VaultV2BlueReallocationData implements InputVaultV2BlueReal
|
|
|
132
131
|
/**
|
|
133
132
|
* Clones the complete simulation snapshot.
|
|
134
133
|
*
|
|
135
|
-
* @returns A deep clone of this simulation state.
|
|
136
|
-
* shared by reference and must be treated as read-only.
|
|
134
|
+
* @returns A deep clone of this simulation state.
|
|
137
135
|
* @example
|
|
138
136
|
* ```ts
|
|
139
137
|
* import { markets } from "@morpho-org/morpho-test";
|
|
@@ -90,10 +90,6 @@ const cloneAccrualVault = (vault, markets) => new blue_sdk_1.AccrualVault({
|
|
|
90
90
|
position: clonePosition(position, markets),
|
|
91
91
|
})));
|
|
92
92
|
const cloneAdapter = (adapter, markets) => {
|
|
93
|
-
// BluePublicAllocator never moves Midnight liquidity, and reallocation never mutates a Midnight
|
|
94
|
-
// adapter, so its read-only snapshot is shared as-is.
|
|
95
|
-
if (adapter.type === "VaultV2MidnightAdapter")
|
|
96
|
-
return adapter;
|
|
97
93
|
const base = {
|
|
98
94
|
address: adapter.address,
|
|
99
95
|
parentVault: adapter.parentVault,
|
|
@@ -141,9 +137,8 @@ const cloneVault = (vault, { markets, adapterKeysToClone, }) => {
|
|
|
141
137
|
/**
|
|
142
138
|
* Immutable-by-convention state container for Vault V2 BluePublicAllocator simulations.
|
|
143
139
|
*
|
|
144
|
-
* Constructor inputs are cloned
|
|
145
|
-
*
|
|
146
|
-
* reallocation returns a new instance. Planning keeps the transaction-scoped `firstTotalAssets`
|
|
140
|
+
* Constructor inputs are cloned. Every simulated reallocation returns a new
|
|
141
|
+
* instance. Planning keeps the transaction-scoped `firstTotalAssets`
|
|
147
142
|
* denominator outside the durable snapshot while applying reallocations in
|
|
148
143
|
* contract order. Penalty donations update simulated vault accounting but are
|
|
149
144
|
* excluded from same-plan idle liquidity so round-up dust cannot create
|
|
@@ -287,8 +282,7 @@ class VaultV2BlueReallocationData {
|
|
|
287
282
|
/**
|
|
288
283
|
* Clones the complete simulation snapshot.
|
|
289
284
|
*
|
|
290
|
-
* @returns A deep clone of this simulation state.
|
|
291
|
-
* shared by reference and must be treated as read-only.
|
|
285
|
+
* @returns A deep clone of this simulation state.
|
|
292
286
|
* @example
|
|
293
287
|
* ```ts
|
|
294
288
|
* import { markets } from "@morpho-org/morpho-test";
|
package/lib/cjs/errors.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
export { BlueErrors, IncompleteChainRegistryError, InvalidMarketParamsError as InvalidBlueMarketParamsError,
|
|
1
|
+
export { BlueErrors, IncompleteChainRegistryError, InvalidMarketParamsError as InvalidBlueMarketParamsError, UnknownAddressError, UnknownDataError as UnknownBlueDataError, UnknownFactory as UnknownBlueFactory, UnknownMarketAllocationError as UnknownBlueMarketAllocationError, UnknownMarketParamsError as UnknownBlueMarketParamsError, UnknownOfFactory as UnknownBlueOfFactory, UnknownTokenError as UnknownBlueTokenError, UnknownTokenPriceError as UnknownBlueTokenPriceError, UnknownVaultConfigError as UnknownBlueVaultConfigError, UnsupportedChainIdError, UnsupportedMarketIrmError as UnsupportedBlueMarketIrmError,
|
|
2
2
|
/** @deprecated Pre-liquidation support is deprecated and will be removed in the next major. */
|
|
3
3
|
UnsupportedPreLiquidationParamsError as UnsupportedBluePreLiquidationParamsError, UnsupportedVaultV2AdapterError as UnsupportedBlueVaultV2AdapterError, VaultV2Errors, } from "@morpho-org/blue-sdk";
|
|
4
|
-
export { getUnsupportedVaultV2Adapter as getBlueUnsupportedVaultV2Adapter, InvalidNumberError, InvalidPermitDomainChainIdError, InvalidPermitDomainVerifyingContractError, isUnknownOfFactoryError as isBlueUnknownOfFactoryError, MalformedTokenMetadataError, MarketParamsIdMismatchError as BlueMarketParamsIdMismatchError, MissingPermitDomainNameError, NonTupleReturnValueError, Permit2ExpirationOutOfRangeError, UnknownAbiFunctionError, UnnamedAbiOutputsError,
|
|
5
|
-
export { ChainIdMismatchError as MidnightChainIdMismatchError, InvalidEcrecoverSignatureVError as InvalidMidnightEcrecoverSignatureVError, InvalidMarketParameterError as InvalidMidnightMarketParameterError, InvalidMidnightApiQuoteTargetError, InvalidMidnightApiResponseError, InvalidOfferGroupError as InvalidMidnightOfferGroupError, InvalidOfferParameterError as InvalidMidnightOfferParameterError, InvalidRateRatifierV1RateError as InvalidMidnightRateRatifierV1RateError, InvalidRateRatifierV1TickError as InvalidMidnightRateRatifierV1TickError, InvalidRateRatifierV1TimeError as InvalidMidnightRateRatifierV1TimeError, InvalidRatifierV1AddressError as InvalidMidnightRatifierV1AddressError, InvalidTickSpacingError as InvalidMidnightTickSpacingError, InvalidTreeError as InvalidMidnightTreeError, InvalidTreeHeightError as InvalidMidnightTreeHeightError, InvalidTypedDataSignatureError as InvalidMidnightTypedDataSignatureError, MidnightApiError, MidnightMempoolValidationError, PayloadDecodeError as MidnightPayloadDecodeError, PriceGreaterThanOneError as MidnightPriceGreaterThanOneError, RateRatifierV1BoundOverflowError as MidnightRateRatifierV1BoundOverflowError, RatifierV1TakerNotAllowedError as MidnightRatifierV1TakerNotAllowedError, SettlementFeeExceedsPriceError as MidnightSettlementFeeExceedsPriceError, TickOutOfRangeError as MidnightTickOutOfRangeError, UnknownCollateralIndexError as UnknownMidnightCollateralIndexError, } from "@morpho-org/midnight-sdk";
|
|
4
|
+
export { getUnsupportedVaultV2Adapter as getBlueUnsupportedVaultV2Adapter, InvalidNumberError, InvalidPermitDomainChainIdError, InvalidPermitDomainVerifyingContractError, isUnknownOfFactoryError as isBlueUnknownOfFactoryError, MalformedTokenMetadataError, MarketParamsIdMismatchError as BlueMarketParamsIdMismatchError, MissingPermitDomainNameError, NonTupleReturnValueError, Permit2ExpirationOutOfRangeError, UnknownAbiFunctionError, UnnamedAbiOutputsError, UnsupportedPermitDomainExtensionsError, } from "@morpho-org/blue-sdk-viem";
|
|
5
|
+
export { ChainIdMismatchError as MidnightChainIdMismatchError, InvalidEcrecoverSignatureVError as InvalidMidnightEcrecoverSignatureVError, InvalidMarketParameterError as InvalidMidnightMarketParameterError, InvalidMidnightApiQuoteTargetError, InvalidMidnightApiResponseError, InvalidOfferGroupError as InvalidMidnightOfferGroupError, InvalidOfferParameterError as InvalidMidnightOfferParameterError, InvalidPositionAccrualStateError as InvalidMidnightPositionAccrualStateError, InvalidPositionAccrualTimestampError as InvalidMidnightPositionAccrualTimestampError, InvalidPositionLossFactorError as InvalidMidnightPositionLossFactorError, InvalidRateRatifierV1RateError as InvalidMidnightRateRatifierV1RateError, InvalidRateRatifierV1TickError as InvalidMidnightRateRatifierV1TickError, InvalidRateRatifierV1TimeError as InvalidMidnightRateRatifierV1TimeError, InvalidRatifierV1AddressError as InvalidMidnightRatifierV1AddressError, InvalidTickSpacingError as InvalidMidnightTickSpacingError, InvalidTreeError as InvalidMidnightTreeError, InvalidTreeHeightError as InvalidMidnightTreeHeightError, InvalidTypedDataSignatureError as InvalidMidnightTypedDataSignatureError, MidnightApiError, MidnightMempoolValidationError, PayloadDecodeError as MidnightPayloadDecodeError, PriceGreaterThanOneError as MidnightPriceGreaterThanOneError, RateRatifierV1BoundOverflowError as MidnightRateRatifierV1BoundOverflowError, RatifierV1TakerNotAllowedError as MidnightRatifierV1TakerNotAllowedError, SettlementFeeExceedsPriceError as MidnightSettlementFeeExceedsPriceError, TickOutOfRangeError as MidnightTickOutOfRangeError, UnknownCollateralIndexError as UnknownMidnightCollateralIndexError, } from "@morpho-org/midnight-sdk";
|
|
6
6
|
export type { ErrorClass } from "@morpho-org/morpho-ts";
|
|
7
|
-
export { _try, DivisionByZeroError, InvalidAddressError, InvalidBitLengthError,
|
|
7
|
+
export { _try, DivisionByZeroError, InvalidAddressError, InvalidBitLengthError, NegativeValueError, RegistryValueAlreadyRegisteredError, RetriesExhaustedError, RetryStoppedError, } from "@morpho-org/morpho-ts";
|