@morpho-org/morpho-sdk 10.0.0-next.0 → 10.0.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 +104 -12
- package/lib/cjs/abis.d.ts +1 -1
- package/lib/cjs/abis.js +1 -5
- package/lib/cjs/actions/blue/common.js +4 -2
- package/lib/cjs/actions/blue/withdrawBuyCallback.js +2 -1
- package/lib/cjs/actions/bundles/common.js +20 -14
- package/lib/cjs/actions/bundles/resolveBundlesTokenRequirements.js +2 -1
- package/lib/cjs/actions/midnight/cancelOffers.js +2 -1
- package/lib/cjs/actions/midnight/supplyCollateralBatch.js +4 -2
- package/lib/cjs/actions/midnight/supplyCollateralTakeBorrow.js +2 -1
- package/lib/cjs/actions/midnight/takeBorrow.js +2 -1
- package/lib/cjs/actions/midnight/takeLend.js +2 -1
- package/lib/cjs/actions/midnight/takeRepayWithdrawCollateral.js +2 -1
- package/lib/cjs/actions/midnight/takeWithdraw.js +2 -1
- package/lib/cjs/actions/midnight/withdrawCollateralBatch.js +4 -2
- package/lib/cjs/actions/requirements/encode/encodeErc20Permit2SignatureTransfer.js +2 -11
- package/lib/cjs/actions/requirements/midnight/getMidnightApprovalRequirements.js +2 -1
- package/lib/cjs/actions/requirements/midnight/getMidnightAuthorizationRequirement.js +2 -1
- package/lib/cjs/actions/vaultV1/inKindRedeem.js +6 -3
- package/lib/cjs/actions/vaultV1/migrateToV2.js +1 -1
- package/lib/cjs/actions/vaultV2/forceWithdraw.js +4 -2
- package/lib/cjs/actions/vaultV2/inKindRedeem.js +4 -2
- package/lib/cjs/blue/abis.d.ts +1 -1
- package/lib/cjs/blue/abis.js +1 -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.js +8 -4
- package/lib/cjs/entities/index.d.ts +4 -4
- package/lib/cjs/entities/index.js +1 -3
- package/lib/cjs/entities/midnight/deadline.js +2 -1
- package/lib/cjs/entities/midnight/midnight.js +14 -7
- package/lib/cjs/entities/midnight/publication.js +73 -44
- package/lib/cjs/entities/requirements/assertContractCode.js +4 -2
- package/lib/cjs/entities/requirements/getBundlesTokenRequirements.js +9 -13
- package/lib/cjs/entities/requirements/getErc2612Permit.js +10 -5
- package/lib/cjs/entities/requirements/getVaultBundlesSharesRequirements.d.ts +2 -0
- package/lib/cjs/entities/requirements/getVaultBundlesSharesRequirements.js +7 -1
- package/lib/cjs/entities/requirements/getVaultV1InKindRedeemRequirements.d.ts +21 -0
- package/lib/cjs/entities/requirements/getVaultV1InKindRedeemRequirements.js +111 -0
- package/lib/cjs/entities/requirements/getVaultV2ForceWithdrawRequirements.d.ts +20 -0
- package/lib/cjs/entities/requirements/getVaultV2ForceWithdrawRequirements.js +76 -0
- package/lib/cjs/entities/requirements/getVaultV2InKindRedeemRequirements.d.ts +21 -0
- package/lib/cjs/entities/requirements/getVaultV2InKindRedeemRequirements.js +93 -0
- package/lib/cjs/entities/vaultV1/inKindRedeemQuote.d.ts +25 -0
- package/lib/cjs/entities/vaultV1/inKindRedeemQuote.js +85 -0
- package/lib/cjs/entities/vaultV1/migrateToV2Quote.d.ts +20 -0
- package/lib/cjs/entities/vaultV1/migrateToV2Quote.js +37 -0
- package/lib/cjs/entities/vaultV1/vaultV1.js +51 -181
- package/lib/cjs/entities/vaultV2/forceWithdrawQuote.d.ts +25 -0
- package/lib/cjs/entities/vaultV2/forceWithdrawQuote.js +189 -0
- package/lib/cjs/entities/vaultV2/inKindRedeemQuote.d.ts +28 -0
- package/lib/cjs/entities/vaultV2/inKindRedeemQuote.js +110 -0
- package/lib/cjs/entities/vaultV2/vaultV2.d.ts +8 -34
- package/lib/cjs/entities/vaultV2/vaultV2.js +62 -429
- package/lib/cjs/entities/vaultV2BlueReallocationData.d.ts +2 -3
- package/lib/cjs/entities/vaultV2BlueReallocationData.js +346 -234
- package/lib/cjs/errors.d.ts +4 -4
- package/lib/cjs/errors.js +6 -7
- package/lib/cjs/fetch.d.ts +2 -2
- package/lib/cjs/fetch.js +1 -3
- package/lib/cjs/helpers/deadShares.js +34 -19
- package/lib/cjs/helpers/encodeMidnightCalldata.js +4 -2
- package/lib/cjs/helpers/metadata.js +12 -6
- package/lib/cjs/helpers/previewVaultV2ForceWithdraw.js +10 -5
- package/lib/cjs/helpers/previewVaultV2InKindRedeem.js +6 -3
- package/lib/cjs/helpers/utilization.js +10 -5
- package/lib/cjs/helpers/validate.js +12 -6
- package/lib/cjs/helpers/validateMidnightBounds.js +2 -1
- package/lib/cjs/helpers/validateMidnightCollateralBatch.js +2 -1
- package/lib/cjs/helpers/validateMidnightPublication.js +4 -2
- package/lib/cjs/helpers/validateMidnightTakeFeasibility.js +44 -22
- package/lib/cjs/helpers/validatePositiveInput.js +2 -1
- package/lib/cjs/helpers/validateTakeableOffers.js +2 -1
- package/lib/cjs/helpers/vaultV2ForceWithdrawPlan.js +14 -7
- package/lib/cjs/index.d.ts +2 -2
- package/lib/cjs/index.js +10 -1
- package/lib/cjs/midnight/errors.d.ts +1 -2
- package/lib/cjs/midnight/errors.js +4 -5
- package/lib/cjs/transactionPlan/approval.js +12 -1
- package/lib/cjs/transactionPlan/deposit.d.ts +22 -0
- package/lib/cjs/transactionPlan/deposit.js +139 -0
- package/lib/cjs/transactionPlan/error.d.ts +10 -8
- package/lib/cjs/transactionPlan/error.js +10 -8
- package/lib/cjs/transactionPlan/getTokenPermit.js +2 -1
- package/lib/cjs/transactionPlan/index.d.ts +18 -0
- package/lib/cjs/transactionPlan/index.js +23 -5
- package/lib/cjs/transactionPlan/intent.d.ts +3 -3
- package/lib/cjs/transactionPlan/intent.js +14 -7
- package/lib/cjs/transactionPlan/permit.d.ts +1 -1
- package/lib/cjs/transactionPlan/permit.js +86 -20
- package/lib/cjs/transactionPlan/plan.d.ts +16 -6
- package/lib/cjs/transactionPlan/plan.js +72 -22
- package/lib/cjs/transactionPlan/redeem.d.ts +18 -0
- package/lib/cjs/transactionPlan/redeem.js +63 -0
- package/lib/cjs/transactionPlan/requirements.d.ts +4 -3
- package/lib/cjs/transactionPlan/requirements.js +12 -6
- package/lib/cjs/transactionPlan/serde.d.ts +2 -2
- package/lib/cjs/transactionPlan/serde.js +41 -15
- package/lib/cjs/transactionPlan/shareSpending.d.ts +18 -0
- package/lib/cjs/transactionPlan/shareSpending.js +50 -0
- package/lib/cjs/transactionPlan/types.d.ts +117 -11
- package/lib/cjs/transactionPlan/validateActions.js +11 -1
- package/lib/cjs/transactionPlan/validation.js +6 -3
- package/lib/cjs/transactionPlan/vaultv1/deposit.d.ts +93 -0
- package/lib/cjs/transactionPlan/vaultv1/deposit.js +94 -0
- package/lib/cjs/transactionPlan/vaultv1/inKindRedeem.d.ts +96 -0
- package/lib/cjs/transactionPlan/vaultv1/inKindRedeem.js +203 -0
- package/lib/cjs/transactionPlan/vaultv1/migrateToV2.d.ts +94 -0
- package/lib/cjs/transactionPlan/vaultv1/migrateToV2.js +217 -0
- package/lib/cjs/transactionPlan/vaultv1/redeem.d.ts +69 -0
- package/lib/cjs/transactionPlan/vaultv1/redeem.js +78 -0
- package/lib/cjs/transactionPlan/vaultv1/withdraw.d.ts +77 -0
- package/lib/cjs/transactionPlan/vaultv1/withdraw.js +88 -0
- package/lib/cjs/transactionPlan/vaultv2/deposit.d.ts +14 -31
- package/lib/cjs/transactionPlan/vaultv2/deposit.js +15 -141
- package/lib/cjs/transactionPlan/vaultv2/forceRedeem.d.ts +74 -0
- package/lib/cjs/transactionPlan/vaultv2/forceRedeem.js +155 -0
- package/lib/cjs/transactionPlan/vaultv2/forceWithdraw.d.ts +98 -0
- package/lib/cjs/transactionPlan/vaultv2/forceWithdraw.js +206 -0
- package/lib/cjs/transactionPlan/vaultv2/inKindRedeem.d.ts +113 -0
- package/lib/cjs/transactionPlan/vaultv2/inKindRedeem.js +206 -0
- package/lib/cjs/transactionPlan/vaultv2/redeem.d.ts +84 -0
- package/lib/cjs/transactionPlan/vaultv2/redeem.js +86 -0
- package/lib/cjs/transactionPlan/vaultv2/withdraw.d.ts +14 -27
- package/lib/cjs/transactionPlan/vaultv2/withdraw.js +17 -124
- package/lib/cjs/transactionPlan/version.js +2 -1
- package/lib/cjs/transactionPlan/withdraw.d.ts +18 -0
- package/lib/cjs/transactionPlan/withdraw.js +94 -0
- package/lib/cjs/types/action.js +16 -8
- package/lib/cjs/types/error.d.ts +8 -1
- package/lib/cjs/types/error.js +10 -1
- package/lib/cjs/utils.d.ts +2 -2
- package/lib/cjs/utils.js +2 -4
- package/lib/cjs/version.d.ts +1 -1
- package/lib/cjs/version.js +1 -1
- package/lib/esm/abis.d.ts +1 -1
- package/lib/esm/abis.js +1 -1
- package/lib/esm/actions/blue/common.js +4 -2
- package/lib/esm/actions/blue/withdrawBuyCallback.js +2 -1
- package/lib/esm/actions/bundles/common.js +20 -14
- package/lib/esm/actions/bundles/resolveBundlesTokenRequirements.js +2 -1
- package/lib/esm/actions/midnight/cancelOffers.js +2 -1
- package/lib/esm/actions/midnight/supplyCollateralBatch.js +4 -2
- package/lib/esm/actions/midnight/supplyCollateralTakeBorrow.js +2 -1
- package/lib/esm/actions/midnight/takeBorrow.js +2 -1
- package/lib/esm/actions/midnight/takeLend.js +2 -1
- package/lib/esm/actions/midnight/takeRepayWithdrawCollateral.js +2 -1
- package/lib/esm/actions/midnight/takeWithdraw.js +2 -1
- package/lib/esm/actions/midnight/withdrawCollateralBatch.js +4 -2
- package/lib/esm/actions/requirements/encode/encodeErc20Permit2SignatureTransfer.js +4 -13
- package/lib/esm/actions/requirements/midnight/getMidnightApprovalRequirements.js +2 -1
- package/lib/esm/actions/requirements/midnight/getMidnightAuthorizationRequirement.js +2 -1
- package/lib/esm/actions/vaultV1/inKindRedeem.js +6 -3
- package/lib/esm/actions/vaultV1/migrateToV2.js +1 -1
- package/lib/esm/actions/vaultV2/forceWithdraw.js +4 -2
- package/lib/esm/actions/vaultV2/inKindRedeem.js +4 -2
- package/lib/esm/blue/abis.d.ts +1 -1
- package/lib/esm/blue/abis.js +1 -1
- package/lib/esm/blue/entities.d.ts +4 -4
- package/lib/esm/blue/entities.js +2 -2
- package/lib/esm/blue/errors.d.ts +2 -2
- package/lib/esm/blue/errors.js +2 -2
- package/lib/esm/blue/fetch.d.ts +2 -2
- package/lib/esm/blue/fetch.js +2 -2
- package/lib/esm/blue/utils.d.ts +1 -1
- package/lib/esm/blue/utils.js +1 -1
- package/lib/esm/entities/blue/blue.js +8 -4
- package/lib/esm/entities/index.d.ts +4 -4
- package/lib/esm/entities/index.js +2 -2
- package/lib/esm/entities/midnight/deadline.js +2 -1
- package/lib/esm/entities/midnight/midnight.js +14 -7
- package/lib/esm/entities/midnight/publication.js +73 -44
- package/lib/esm/entities/requirements/assertContractCode.js +4 -2
- package/lib/esm/entities/requirements/getBundlesTokenRequirements.js +10 -14
- package/lib/esm/entities/requirements/getErc2612Permit.js +10 -5
- package/lib/esm/entities/requirements/getVaultBundlesSharesRequirements.d.ts +2 -0
- package/lib/esm/entities/requirements/getVaultBundlesSharesRequirements.js +7 -1
- package/lib/esm/entities/requirements/getVaultV1InKindRedeemRequirements.d.ts +21 -0
- package/lib/esm/entities/requirements/getVaultV1InKindRedeemRequirements.js +108 -0
- package/lib/esm/entities/requirements/getVaultV2ForceWithdrawRequirements.d.ts +20 -0
- package/lib/esm/entities/requirements/getVaultV2ForceWithdrawRequirements.js +73 -0
- package/lib/esm/entities/requirements/getVaultV2InKindRedeemRequirements.d.ts +21 -0
- package/lib/esm/entities/requirements/getVaultV2InKindRedeemRequirements.js +90 -0
- package/lib/esm/entities/vaultV1/inKindRedeemQuote.d.ts +25 -0
- package/lib/esm/entities/vaultV1/inKindRedeemQuote.js +82 -0
- package/lib/esm/entities/vaultV1/migrateToV2Quote.d.ts +20 -0
- package/lib/esm/entities/vaultV1/migrateToV2Quote.js +34 -0
- package/lib/esm/entities/vaultV1/vaultV1.js +57 -187
- package/lib/esm/entities/vaultV2/forceWithdrawQuote.d.ts +25 -0
- package/lib/esm/entities/vaultV2/forceWithdrawQuote.js +186 -0
- package/lib/esm/entities/vaultV2/inKindRedeemQuote.d.ts +28 -0
- package/lib/esm/entities/vaultV2/inKindRedeemQuote.js +107 -0
- package/lib/esm/entities/vaultV2/vaultV2.d.ts +8 -34
- package/lib/esm/entities/vaultV2/vaultV2.js +70 -437
- package/lib/esm/entities/vaultV2BlueReallocationData.d.ts +2 -3
- package/lib/esm/entities/vaultV2BlueReallocationData.js +346 -234
- package/lib/esm/errors.d.ts +4 -4
- package/lib/esm/errors.js +4 -4
- package/lib/esm/fetch.d.ts +2 -2
- package/lib/esm/fetch.js +2 -2
- package/lib/esm/helpers/deadShares.js +35 -20
- package/lib/esm/helpers/encodeMidnightCalldata.js +4 -2
- package/lib/esm/helpers/metadata.js +12 -6
- package/lib/esm/helpers/previewVaultV2ForceWithdraw.js +10 -5
- package/lib/esm/helpers/previewVaultV2InKindRedeem.js +6 -3
- package/lib/esm/helpers/utilization.js +10 -5
- package/lib/esm/helpers/validate.js +12 -6
- package/lib/esm/helpers/validateMidnightBounds.js +2 -1
- package/lib/esm/helpers/validateMidnightCollateralBatch.js +2 -1
- package/lib/esm/helpers/validateMidnightPublication.js +4 -2
- package/lib/esm/helpers/validateMidnightTakeFeasibility.js +44 -22
- package/lib/esm/helpers/validatePositiveInput.js +2 -1
- package/lib/esm/helpers/validateTakeableOffers.js +2 -1
- package/lib/esm/helpers/vaultV2ForceWithdrawPlan.js +14 -7
- package/lib/esm/index.d.ts +2 -2
- package/lib/esm/index.js +1 -1
- package/lib/esm/midnight/errors.d.ts +1 -2
- package/lib/esm/midnight/errors.js +1 -2
- package/lib/esm/transactionPlan/approval.js +13 -2
- package/lib/esm/transactionPlan/deposit.d.ts +22 -0
- package/lib/esm/transactionPlan/deposit.js +135 -0
- package/lib/esm/transactionPlan/error.d.ts +10 -8
- package/lib/esm/transactionPlan/error.js +10 -8
- package/lib/esm/transactionPlan/getTokenPermit.js +2 -1
- package/lib/esm/transactionPlan/index.d.ts +18 -0
- package/lib/esm/transactionPlan/index.js +9 -0
- package/lib/esm/transactionPlan/intent.d.ts +3 -3
- package/lib/esm/transactionPlan/intent.js +14 -7
- package/lib/esm/transactionPlan/permit.d.ts +1 -1
- package/lib/esm/transactionPlan/permit.js +86 -20
- package/lib/esm/transactionPlan/plan.d.ts +16 -6
- package/lib/esm/transactionPlan/plan.js +68 -18
- package/lib/esm/transactionPlan/redeem.d.ts +18 -0
- package/lib/esm/transactionPlan/redeem.js +59 -0
- package/lib/esm/transactionPlan/requirements.d.ts +4 -3
- package/lib/esm/transactionPlan/requirements.js +12 -6
- package/lib/esm/transactionPlan/serde.d.ts +2 -2
- package/lib/esm/transactionPlan/serde.js +41 -15
- package/lib/esm/transactionPlan/shareSpending.d.ts +18 -0
- package/lib/esm/transactionPlan/shareSpending.js +47 -0
- package/lib/esm/transactionPlan/types.d.ts +117 -11
- package/lib/esm/transactionPlan/validateActions.js +11 -1
- package/lib/esm/transactionPlan/validation.js +6 -3
- package/lib/esm/transactionPlan/vaultv1/deposit.d.ts +93 -0
- package/lib/esm/transactionPlan/vaultv1/deposit.js +90 -0
- package/lib/esm/transactionPlan/vaultv1/inKindRedeem.d.ts +96 -0
- package/lib/esm/transactionPlan/vaultv1/inKindRedeem.js +198 -0
- package/lib/esm/transactionPlan/vaultv1/migrateToV2.d.ts +94 -0
- package/lib/esm/transactionPlan/vaultv1/migrateToV2.js +212 -0
- package/lib/esm/transactionPlan/vaultv1/redeem.d.ts +69 -0
- package/lib/esm/transactionPlan/vaultv1/redeem.js +74 -0
- package/lib/esm/transactionPlan/vaultv1/withdraw.d.ts +77 -0
- package/lib/esm/transactionPlan/vaultv1/withdraw.js +84 -0
- package/lib/esm/transactionPlan/vaultv2/deposit.d.ts +14 -31
- package/lib/esm/transactionPlan/vaultv2/deposit.js +17 -142
- package/lib/esm/transactionPlan/vaultv2/forceRedeem.d.ts +74 -0
- package/lib/esm/transactionPlan/vaultv2/forceRedeem.js +150 -0
- package/lib/esm/transactionPlan/vaultv2/forceWithdraw.d.ts +98 -0
- package/lib/esm/transactionPlan/vaultv2/forceWithdraw.js +201 -0
- package/lib/esm/transactionPlan/vaultv2/inKindRedeem.d.ts +113 -0
- package/lib/esm/transactionPlan/vaultv2/inKindRedeem.js +201 -0
- package/lib/esm/transactionPlan/vaultv2/redeem.d.ts +84 -0
- package/lib/esm/transactionPlan/vaultv2/redeem.js +82 -0
- package/lib/esm/transactionPlan/vaultv2/withdraw.d.ts +14 -27
- package/lib/esm/transactionPlan/vaultv2/withdraw.js +19 -125
- package/lib/esm/transactionPlan/version.js +2 -1
- package/lib/esm/transactionPlan/withdraw.d.ts +18 -0
- package/lib/esm/transactionPlan/withdraw.js +90 -0
- package/lib/esm/types/action.js +16 -8
- package/lib/esm/types/error.d.ts +8 -1
- package/lib/esm/types/error.js +10 -1
- package/lib/esm/utils.d.ts +2 -2
- package/lib/esm/utils.js +2 -2
- package/lib/esm/version.d.ts +1 -1
- package/lib/esm/version.js +1 -1
- package/package.json +15 -15
|
@@ -8,8 +8,9 @@ import { MidnightMarketLiquidationCursorNotEnabledError, MidnightMarketLltvNotEn
|
|
|
8
8
|
// Midnight.sol `touchMarket` rejects markets maturing more than 100 years after creation.
|
|
9
9
|
const MAX_TIME_TO_MATURITY = 100n * 365n * 86400n;
|
|
10
10
|
function requirePublicationState(value) {
|
|
11
|
-
if (value === undefined)
|
|
11
|
+
if (value === undefined) {
|
|
12
12
|
throw new UnknownDataError("Missing Midnight publication state.");
|
|
13
|
+
}
|
|
13
14
|
return value;
|
|
14
15
|
}
|
|
15
16
|
/** @internal */
|
|
@@ -215,21 +216,65 @@ export async function fetchMidnightMakerOfferStates(params) {
|
|
|
215
216
|
const blockNumber = params.blockNumber ?? (await getBlockNumber(params.client));
|
|
216
217
|
const block = await getBlock(params.client, { blockNumber });
|
|
217
218
|
const midnight = getChainAddress(params.chainId, "midnight");
|
|
219
|
+
const targets = collectPublicationReadTargets(params.tree);
|
|
220
|
+
const { collaterals } = targets;
|
|
221
|
+
const values = await readPublicationContractState({
|
|
222
|
+
client: params.client,
|
|
223
|
+
midnight,
|
|
224
|
+
blockNumber,
|
|
225
|
+
targets,
|
|
226
|
+
});
|
|
227
|
+
const { marketById, consumedByGroup, positionByOwner, collateralStateByMarket, } = indexPublicationContractState({ targets, values });
|
|
228
|
+
const codeByOracle = new Map(await Promise.all([...new Set(collaterals.map(({ oracleKey }) => oracleKey))].map(async (oracleKey) => [
|
|
229
|
+
oracleKey,
|
|
230
|
+
await getCode(params.client, {
|
|
231
|
+
address: requirePublicationState(collaterals.find(({ oracleKey: key }) => key === oracleKey)).collateral.oracle,
|
|
232
|
+
blockNumber,
|
|
233
|
+
}),
|
|
234
|
+
])));
|
|
235
|
+
const states = params.tree.offers.map((offer) => {
|
|
236
|
+
const id = MarketUtils.toId(offer.market);
|
|
237
|
+
const market = requirePublicationState(marketById.get(id.toLowerCase()));
|
|
238
|
+
const groupKey = `${offer.maker.toLowerCase()}:${offer.group.toLowerCase()}`;
|
|
239
|
+
const owner = requirePublicationState(positionByOwner.get(`${id.toLowerCase()}:${offer.maker.toLowerCase()}`));
|
|
240
|
+
const uncreated = market.tickSpacing === 0;
|
|
241
|
+
const collateralStates = uncreated
|
|
242
|
+
? requirePublicationState(collateralStateByMarket.get(id.toLowerCase()))
|
|
243
|
+
: [];
|
|
244
|
+
return {
|
|
245
|
+
consumed: requirePublicationState(consumedByGroup.get(groupKey)),
|
|
246
|
+
tickSpacing: market.tickSpacing,
|
|
247
|
+
continuousFee: BigInt(market.continuousFee),
|
|
248
|
+
credit: owner.credit,
|
|
249
|
+
debt: owner.debt,
|
|
250
|
+
market,
|
|
251
|
+
lltvEnabled: collateralStates.map(({ lltvEnabled }) => lltvEnabled),
|
|
252
|
+
liquidationCursorEnabled: collateralStates.map(({ liquidationCursorEnabled }) => liquidationCursorEnabled),
|
|
253
|
+
oracleHasCode: uncreated
|
|
254
|
+
? offerMarketParams(offer).collateralParams.map((collateral) => codeByOracle.get(collateral.oracle.toLowerCase()) !== undefined &&
|
|
255
|
+
codeByOracle.get(collateral.oracle.toLowerCase()) !== "0x")
|
|
256
|
+
: [],
|
|
257
|
+
};
|
|
258
|
+
});
|
|
259
|
+
return { states, now: block.timestamp };
|
|
260
|
+
}
|
|
261
|
+
/** Deduplicates the market, group, owner and collateral reads for a maker tree. @internal */
|
|
262
|
+
function collectPublicationReadTargets(tree) {
|
|
218
263
|
const markets = [
|
|
219
|
-
...new Map(
|
|
264
|
+
...new Map(tree.offers.map((offer) => {
|
|
220
265
|
const market = MarketParams.from(offerMarketParams(offer));
|
|
221
266
|
const id = MarketUtils.toId(market);
|
|
222
267
|
return [id.toLowerCase(), { id, market }];
|
|
223
268
|
})).values(),
|
|
224
269
|
];
|
|
225
270
|
const groups = [
|
|
226
|
-
...new Map(
|
|
271
|
+
...new Map(tree.offers.map((offer) => [
|
|
227
272
|
`${offer.maker.toLowerCase()}:${offer.group.toLowerCase()}`,
|
|
228
273
|
{ maker: offer.maker, group: offer.group },
|
|
229
274
|
])).values(),
|
|
230
275
|
];
|
|
231
276
|
const owners = [
|
|
232
|
-
...new Map(
|
|
277
|
+
...new Map(tree.offers.map((offer) => {
|
|
233
278
|
const id = MarketUtils.toId(offer.market);
|
|
234
279
|
return [
|
|
235
280
|
`${id.toLowerCase()}:${offer.maker.toLowerCase()}`,
|
|
@@ -248,50 +293,55 @@ export async function fetchMidnightMakerOfferStates(params) {
|
|
|
248
293
|
market.loanToken,
|
|
249
294
|
])).values(),
|
|
250
295
|
];
|
|
251
|
-
|
|
252
|
-
|
|
296
|
+
return { markets, groups, owners, collaterals, defaultFeeTokens };
|
|
297
|
+
}
|
|
298
|
+
/** Reads contract state concurrently at the pinned publication block. @internal */
|
|
299
|
+
async function readPublicationContractState({ client, midnight, blockNumber, targets, }) {
|
|
300
|
+
const { markets, groups, owners, collaterals, defaultFeeTokens } = targets;
|
|
301
|
+
return Promise.all([
|
|
302
|
+
Promise.all(markets.map(({ id }) => readContract(client, {
|
|
253
303
|
address: midnight,
|
|
254
304
|
abi: midnightAbi,
|
|
255
305
|
functionName: "marketState",
|
|
256
306
|
args: [id],
|
|
257
307
|
blockNumber,
|
|
258
308
|
}))),
|
|
259
|
-
Promise.all(groups.map(({ maker, group }) => readContract(
|
|
309
|
+
Promise.all(groups.map(({ maker, group }) => readContract(client, {
|
|
260
310
|
address: midnight,
|
|
261
311
|
abi: midnightAbi,
|
|
262
312
|
functionName: "consumed",
|
|
263
313
|
args: [maker, group],
|
|
264
314
|
blockNumber,
|
|
265
315
|
}))),
|
|
266
|
-
Promise.all(owners.map(({ id, maker }) => readContract(
|
|
316
|
+
Promise.all(owners.map(({ id, maker }) => readContract(client, {
|
|
267
317
|
address: midnight,
|
|
268
318
|
abi: midnightAbi,
|
|
269
319
|
functionName: "credit",
|
|
270
320
|
args: [id, maker],
|
|
271
321
|
blockNumber,
|
|
272
322
|
}))),
|
|
273
|
-
Promise.all(owners.map(({ id, maker }) => readContract(
|
|
323
|
+
Promise.all(owners.map(({ id, maker }) => readContract(client, {
|
|
274
324
|
address: midnight,
|
|
275
325
|
abi: midnightAbi,
|
|
276
326
|
functionName: "debt",
|
|
277
327
|
args: [id, maker],
|
|
278
328
|
blockNumber,
|
|
279
329
|
}))),
|
|
280
|
-
Promise.all(defaultFeeTokens.map((loanToken) => readContract(
|
|
330
|
+
Promise.all(defaultFeeTokens.map((loanToken) => readContract(client, {
|
|
281
331
|
address: midnight,
|
|
282
332
|
abi: midnightAbi,
|
|
283
333
|
functionName: "defaultContinuousFee",
|
|
284
334
|
args: [loanToken],
|
|
285
335
|
blockNumber,
|
|
286
336
|
}))),
|
|
287
|
-
Promise.all(collaterals.map(({ collateral }) => readContract(
|
|
337
|
+
Promise.all(collaterals.map(({ collateral }) => readContract(client, {
|
|
288
338
|
address: midnight,
|
|
289
339
|
abi: midnightAbi,
|
|
290
340
|
functionName: "isLltvEnabled",
|
|
291
341
|
args: [collateral.lltv],
|
|
292
342
|
blockNumber,
|
|
293
343
|
}))),
|
|
294
|
-
Promise.all(collaterals.map(({ collateral }) => readContract(
|
|
344
|
+
Promise.all(collaterals.map(({ collateral }) => readContract(client, {
|
|
295
345
|
address: midnight,
|
|
296
346
|
abi: midnightAbi,
|
|
297
347
|
functionName: "isLiquidationCursorEnabled",
|
|
@@ -299,6 +349,11 @@ export async function fetchMidnightMakerOfferStates(params) {
|
|
|
299
349
|
blockNumber,
|
|
300
350
|
}))),
|
|
301
351
|
]);
|
|
352
|
+
}
|
|
353
|
+
/** Indexes validated contract results for per-offer publication state. @internal */
|
|
354
|
+
function indexPublicationContractState({ targets, values, }) {
|
|
355
|
+
const { markets, groups, owners, collaterals, defaultFeeTokens } = targets;
|
|
356
|
+
const [marketStates, consumedValues, creditValues, debtValues, defaultFees, lltvEnabledByCollateral, liquidationCursorEnabledByCollateral,] = values;
|
|
302
357
|
const defaultFeeByLoanToken = new Map(defaultFeeTokens.map((loanToken, index) => [
|
|
303
358
|
loanToken.toLowerCase(),
|
|
304
359
|
requirePublicationState(defaultFees[index]),
|
|
@@ -344,38 +399,12 @@ export async function fetchMidnightMakerOfferStates(params) {
|
|
|
344
399
|
id.toLowerCase(),
|
|
345
400
|
market.collateralParams.map((_, index) => requirePublicationState(collateralStateByKey.get(`${id.toLowerCase()}:${index}`))),
|
|
346
401
|
]));
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
])));
|
|
354
|
-
const states = params.tree.offers.map((offer) => {
|
|
355
|
-
const id = MarketUtils.toId(offer.market);
|
|
356
|
-
const market = requirePublicationState(marketById.get(id.toLowerCase()));
|
|
357
|
-
const groupKey = `${offer.maker.toLowerCase()}:${offer.group.toLowerCase()}`;
|
|
358
|
-
const owner = requirePublicationState(positionByOwner.get(`${id.toLowerCase()}:${offer.maker.toLowerCase()}`));
|
|
359
|
-
const uncreated = market.tickSpacing === 0;
|
|
360
|
-
const collateralStates = uncreated
|
|
361
|
-
? requirePublicationState(collateralStateByMarket.get(id.toLowerCase()))
|
|
362
|
-
: [];
|
|
363
|
-
return {
|
|
364
|
-
consumed: requirePublicationState(consumedByGroup.get(groupKey)),
|
|
365
|
-
tickSpacing: market.tickSpacing,
|
|
366
|
-
continuousFee: BigInt(market.continuousFee),
|
|
367
|
-
credit: owner.credit,
|
|
368
|
-
debt: owner.debt,
|
|
369
|
-
market,
|
|
370
|
-
lltvEnabled: collateralStates.map(({ lltvEnabled }) => lltvEnabled),
|
|
371
|
-
liquidationCursorEnabled: collateralStates.map(({ liquidationCursorEnabled }) => liquidationCursorEnabled),
|
|
372
|
-
oracleHasCode: uncreated
|
|
373
|
-
? offerMarketParams(offer).collateralParams.map((collateral) => codeByOracle.get(collateral.oracle.toLowerCase()) !== undefined &&
|
|
374
|
-
codeByOracle.get(collateral.oracle.toLowerCase()) !== "0x")
|
|
375
|
-
: [],
|
|
376
|
-
};
|
|
377
|
-
});
|
|
378
|
-
return { states, now: block.timestamp };
|
|
402
|
+
return {
|
|
403
|
+
marketById,
|
|
404
|
+
consumedByGroup,
|
|
405
|
+
positionByOwner,
|
|
406
|
+
collateralStateByMarket,
|
|
407
|
+
};
|
|
379
408
|
}
|
|
380
409
|
/**
|
|
381
410
|
* Rejects offers with callbacks that the selected maker flow cannot execute.
|
|
@@ -49,8 +49,9 @@ export const assertContractCode = async (client, params) => {
|
|
|
49
49
|
export const assertRegistryTargetsHaveCode = async (client, chainId, targets) => {
|
|
50
50
|
const seen = new Set();
|
|
51
51
|
for (const target of targets) {
|
|
52
|
-
if (seen.has(target.address))
|
|
52
|
+
if (seen.has(target.address)) {
|
|
53
53
|
continue;
|
|
54
|
+
}
|
|
54
55
|
seen.add(target.address);
|
|
55
56
|
try {
|
|
56
57
|
await assertContractCode(client, {
|
|
@@ -60,8 +61,9 @@ export const assertRegistryTargetsHaveCode = async (client, chainId, targets) =>
|
|
|
60
61
|
});
|
|
61
62
|
}
|
|
62
63
|
catch (error) {
|
|
63
|
-
if (!(error instanceof MissingContractCodeError))
|
|
64
|
+
if (!(error instanceof MissingContractCodeError)) {
|
|
64
65
|
throw error;
|
|
66
|
+
}
|
|
65
67
|
try {
|
|
66
68
|
await validateClientChainId(client, chainId);
|
|
67
69
|
}
|
|
@@ -5,7 +5,8 @@ import { readContract } from "viem/actions";
|
|
|
5
5
|
import { resolveBundlesTokenRequirements } from "../../actions/bundles/index.js";
|
|
6
6
|
import { validateClientChainId } from "../../actions/requirements/validateClientChainId.js";
|
|
7
7
|
import { validateChainId, validateRequirementSpender, } from "../../helpers/index.js";
|
|
8
|
-
import {
|
|
8
|
+
import { validateDeadline } from "../../helpers/validate.js";
|
|
9
|
+
import { ExpiredDeadlineError, InputExceedsMaxError, NegativeInputError, } from "../../types/index.js";
|
|
9
10
|
import { getErc2612Permit } from "./getErc2612Permit.js";
|
|
10
11
|
/**
|
|
11
12
|
* Resolves direct approval or ERC-2612 prerequisites for a registered fixed bundles contract.
|
|
@@ -93,16 +94,8 @@ export const getBundlesTokenRequirements = async (viemClient, params) => {
|
|
|
93
94
|
max: maxUint256,
|
|
94
95
|
});
|
|
95
96
|
}
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
}
|
|
99
|
-
if (params.deadline > maxUint256) {
|
|
100
|
-
throw new InputExceedsMaxError({
|
|
101
|
-
field: "deadline",
|
|
102
|
-
value: params.deadline,
|
|
103
|
-
max: maxUint256,
|
|
104
|
-
});
|
|
105
|
-
}
|
|
97
|
+
// Reject deadlines outside the positive uint256 range before reading state.
|
|
98
|
+
validateDeadline(params.deadline);
|
|
106
99
|
// Reject an already-expired deadline before the RPC reads so a direct caller of this resolver
|
|
107
100
|
// never signs a permit for a supply the BlueBundlesV1 call would revert. The entity validates
|
|
108
101
|
// this too, but the exported resolver must guard its own callers.
|
|
@@ -110,8 +103,9 @@ export const getBundlesTokenRequirements = async (viemClient, params) => {
|
|
|
110
103
|
if (params.deadline <= timestamp) {
|
|
111
104
|
throw new ExpiredDeadlineError(params.deadline, timestamp);
|
|
112
105
|
}
|
|
113
|
-
if (params.amount === 0n)
|
|
106
|
+
if (params.amount === 0n) {
|
|
114
107
|
return [];
|
|
108
|
+
}
|
|
115
109
|
await validateClientChainId(viemClient, params.chainId);
|
|
116
110
|
const allowance = await readContract(viemClient, {
|
|
117
111
|
abi: erc20Abi,
|
|
@@ -119,8 +113,9 @@ export const getBundlesTokenRequirements = async (viemClient, params) => {
|
|
|
119
113
|
functionName: "allowance",
|
|
120
114
|
args: [params.owner, params.spender],
|
|
121
115
|
});
|
|
122
|
-
if (allowance >= params.amount)
|
|
116
|
+
if (allowance >= params.amount) {
|
|
123
117
|
return [];
|
|
118
|
+
}
|
|
124
119
|
const { dai } = getChainAddresses(params.chainId);
|
|
125
120
|
const isDai = params.supportSignature &&
|
|
126
121
|
isDefined(dai) &&
|
|
@@ -136,8 +131,9 @@ export const getBundlesTokenRequirements = async (viemClient, params) => {
|
|
|
136
131
|
now: timestamp,
|
|
137
132
|
supportDeployless: params.supportDeployless,
|
|
138
133
|
});
|
|
139
|
-
if (isDefined(permit))
|
|
134
|
+
if (isDefined(permit)) {
|
|
140
135
|
return [permit];
|
|
136
|
+
}
|
|
141
137
|
}
|
|
142
138
|
return resolveBundlesTokenRequirements({
|
|
143
139
|
token: params.token,
|
|
@@ -14,10 +14,12 @@ export async function getErc2612Permit(viemClient, params) {
|
|
|
14
14
|
functionName: "nonces",
|
|
15
15
|
args: [params.owner],
|
|
16
16
|
}).catch((error) => {
|
|
17
|
-
if (isTransportError(error))
|
|
17
|
+
if (isTransportError(error)) {
|
|
18
18
|
throw error;
|
|
19
|
-
|
|
19
|
+
}
|
|
20
|
+
if (isContractRevertError(error) || isUndecodableResultError(error)) {
|
|
20
21
|
return undefined;
|
|
22
|
+
}
|
|
21
23
|
throw error;
|
|
22
24
|
});
|
|
23
25
|
if (isDefined(nonce)) {
|
|
@@ -38,10 +40,12 @@ export async function getErc2612Permit(viemClient, params) {
|
|
|
38
40
|
address: params.token,
|
|
39
41
|
functionName: "DOMAIN_SEPARATOR",
|
|
40
42
|
}).catch((error) => {
|
|
41
|
-
if (isTransportError(error))
|
|
43
|
+
if (isTransportError(error)) {
|
|
42
44
|
throw error;
|
|
43
|
-
|
|
45
|
+
}
|
|
46
|
+
if (isContractRevertError(error) || isUndecodableResultError(error)) {
|
|
44
47
|
return undefined;
|
|
48
|
+
}
|
|
45
49
|
throw error;
|
|
46
50
|
});
|
|
47
51
|
const domain = permit.action.typedData.domain ?? {};
|
|
@@ -49,8 +53,9 @@ export async function getErc2612Permit(viemClient, params) {
|
|
|
49
53
|
hashDomain({
|
|
50
54
|
domain,
|
|
51
55
|
types: { EIP712Domain: getTypesForEIP712Domain({ domain }) },
|
|
52
|
-
}).toLowerCase())
|
|
56
|
+
}).toLowerCase()) {
|
|
53
57
|
return permit;
|
|
58
|
+
}
|
|
54
59
|
}
|
|
55
60
|
}
|
|
56
61
|
return undefined;
|
|
@@ -16,6 +16,8 @@ import { type ERC20ApprovalAction, type PermitRequirementSignature, type Referen
|
|
|
16
16
|
* @throws {ChainIdMismatchError} when the client declares, or its RPC reports via `eth_chainId`,
|
|
17
17
|
* another chain than `params.chainId`.
|
|
18
18
|
* @throws {ExpiredDeadlineError} when the bundles deadline has elapsed.
|
|
19
|
+
* @throws {NonPositiveInputError} when the deadline is not positive.
|
|
20
|
+
* @throws {InputExceedsMaxError} when the deadline exceeds `maxUint256`.
|
|
19
21
|
* @throws {viem.BaseError} when an allowance, permit nonce, or `eth_chainId` read fails.
|
|
20
22
|
*/
|
|
21
23
|
export declare const getVaultBundlesSharesRequirements: (viemClient: Client, params: {
|
|
@@ -5,6 +5,7 @@ import { readContract } from "viem/actions";
|
|
|
5
5
|
import { encodeErc20Approval, encodeVaultSharesPermit, } from "../../actions/index.js";
|
|
6
6
|
import { validateClientChainId } from "../../actions/requirements/validateClientChainId.js";
|
|
7
7
|
import { validateChainId } from "../../helpers/index.js";
|
|
8
|
+
import { validateDeadline } from "../../helpers/validate.js";
|
|
8
9
|
import { ExpiredDeadlineError, } from "../../types/index.js";
|
|
9
10
|
/**
|
|
10
11
|
* Resolves the vault-share approval or ERC-2612 requirement for a VaultBundlesV1 exit.
|
|
@@ -21,10 +22,14 @@ import { ExpiredDeadlineError, } from "../../types/index.js";
|
|
|
21
22
|
* @throws {ChainIdMismatchError} when the client declares, or its RPC reports via `eth_chainId`,
|
|
22
23
|
* another chain than `params.chainId`.
|
|
23
24
|
* @throws {ExpiredDeadlineError} when the bundles deadline has elapsed.
|
|
25
|
+
* @throws {NonPositiveInputError} when the deadline is not positive.
|
|
26
|
+
* @throws {InputExceedsMaxError} when the deadline exceeds `maxUint256`.
|
|
24
27
|
* @throws {viem.BaseError} when an allowance, permit nonce, or `eth_chainId` read fails.
|
|
25
28
|
*/
|
|
26
29
|
export const getVaultBundlesSharesRequirements = async (viemClient, params) => {
|
|
27
30
|
validateChainId(viemClient.chain?.id, params.chainId);
|
|
31
|
+
// Reject deadlines outside the positive uint256 range before reading state.
|
|
32
|
+
validateDeadline(params.deadline);
|
|
28
33
|
const now = params.now ?? Time.timestamp();
|
|
29
34
|
if (params.deadline <= now) {
|
|
30
35
|
throw new ExpiredDeadlineError(params.deadline, now);
|
|
@@ -38,8 +43,9 @@ export const getVaultBundlesSharesRequirements = async (viemClient, params) => {
|
|
|
38
43
|
functionName: "allowance",
|
|
39
44
|
args: [params.owner, spender],
|
|
40
45
|
});
|
|
41
|
-
if (allowance >= params.requiredShareAllowance)
|
|
46
|
+
if (allowance >= params.requiredShareAllowance) {
|
|
42
47
|
return [];
|
|
48
|
+
}
|
|
43
49
|
if (params.supportSignature) {
|
|
44
50
|
const nonce = await readContract(viemClient, {
|
|
45
51
|
address: params.vaultData.address,
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { AccrualVault } from "@morpho-org/blue-sdk";
|
|
2
|
+
import type { Client } from "viem";
|
|
3
|
+
import { type Address } from "viem";
|
|
4
|
+
import { type ActionRequirement, type ReferenceTimestampParams } from "../../types/index.js";
|
|
5
|
+
/**
|
|
6
|
+
* @internal Resolves exit preflight reads and share authorization without an entity handle.
|
|
7
|
+
* @param client - Client serving the requested chain.
|
|
8
|
+
* @param params - Snapshot and fixed quote used for authorization.
|
|
9
|
+
* @param params.now - See {@link ReferenceTimestampParams.now}.
|
|
10
|
+
* @returns Share approvals or permit requirements.
|
|
11
|
+
*/
|
|
12
|
+
export declare function getVaultV1InKindRedeemRequirements(client: Client, params: ReferenceTimestampParams & {
|
|
13
|
+
readonly vaultData: AccrualVault;
|
|
14
|
+
readonly vault: Address;
|
|
15
|
+
readonly userAddress: Address;
|
|
16
|
+
readonly chainId: number;
|
|
17
|
+
readonly deadline: bigint;
|
|
18
|
+
readonly requiredShareAllowance: bigint;
|
|
19
|
+
readonly supportSignature: boolean;
|
|
20
|
+
readonly amount: bigint;
|
|
21
|
+
}): Promise<readonly ActionRequirement[]>;
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
import { blueAbi, erc2612Abi, metaMorphoAbi } from "@morpho-org/blue-sdk-viem";
|
|
2
|
+
import { getChainAddress, Time } from "@morpho-org/morpho-ts";
|
|
3
|
+
import { erc20Abi, isAddressEqual, maxUint256 } from "viem";
|
|
4
|
+
import { readContract } from "viem/actions";
|
|
5
|
+
import { encodeErc20Approval, encodeVaultSharesPermit, } from "../../actions/index.js";
|
|
6
|
+
import { validateClientChainId } from "../../actions/requirements/validateClientChainId.js";
|
|
7
|
+
import { ExpiredDeadlineError, InsufficientBlueBalanceForInKindRedeemError, VaultIsBlueFeeRecipientError, VaultMorphoMismatchError, } from "../../types/index.js";
|
|
8
|
+
import { assertRegistryTargetsHaveCode } from "./assertContractCode.js";
|
|
9
|
+
/**
|
|
10
|
+
* @internal Resolves exit preflight reads and share authorization without an entity handle.
|
|
11
|
+
* @param client - Client serving the requested chain.
|
|
12
|
+
* @param params - Snapshot and fixed quote used for authorization.
|
|
13
|
+
* @param params.now - See {@link ReferenceTimestampParams.now}.
|
|
14
|
+
* @returns Share approvals or permit requirements.
|
|
15
|
+
*/
|
|
16
|
+
export async function getVaultV1InKindRedeemRequirements(client, params) {
|
|
17
|
+
const { vaultData, vault, userAddress, chainId, deadline, requiredShareAllowance, supportSignature, amount, } = params;
|
|
18
|
+
const vaultExitBundlesV1 = getChainAddress(chainId, "bundles.vaultExitBundlesV1");
|
|
19
|
+
const blue = getChainAddress(chainId, "blue");
|
|
20
|
+
const requirementsTimestamp = params.now ?? Time.timestamp();
|
|
21
|
+
if (deadline <= requirementsTimestamp) {
|
|
22
|
+
throw new ExpiredDeadlineError(deadline, requirementsTimestamp);
|
|
23
|
+
}
|
|
24
|
+
await validateClientChainId(client, chainId);
|
|
25
|
+
await assertRegistryTargetsHaveCode(client, chainId, [
|
|
26
|
+
{
|
|
27
|
+
role: "bundles.vaultExitBundlesV1",
|
|
28
|
+
address: getChainAddress(chainId, "bundles.vaultExitBundlesV1"),
|
|
29
|
+
},
|
|
30
|
+
{ role: "blue", address: getChainAddress(chainId, "blue") },
|
|
31
|
+
]);
|
|
32
|
+
const [allowance, nonce, blueBalance, morpho, blueFeeRecipient] = await Promise.all([
|
|
33
|
+
readContract(client, {
|
|
34
|
+
address: vault,
|
|
35
|
+
abi: erc20Abi,
|
|
36
|
+
functionName: "allowance",
|
|
37
|
+
args: [userAddress, vaultExitBundlesV1],
|
|
38
|
+
}),
|
|
39
|
+
readContract(client, {
|
|
40
|
+
address: vault,
|
|
41
|
+
abi: erc2612Abi,
|
|
42
|
+
functionName: "nonces",
|
|
43
|
+
args: [userAddress],
|
|
44
|
+
}),
|
|
45
|
+
readContract(client, {
|
|
46
|
+
address: vaultData.asset,
|
|
47
|
+
abi: erc20Abi,
|
|
48
|
+
functionName: "balanceOf",
|
|
49
|
+
args: [blue],
|
|
50
|
+
}),
|
|
51
|
+
readContract(client, {
|
|
52
|
+
address: vault,
|
|
53
|
+
abi: metaMorphoAbi,
|
|
54
|
+
functionName: "MORPHO",
|
|
55
|
+
}),
|
|
56
|
+
// feeRecipient() is trusted as returned by the RPC. See THREAT_MODEL.md, RPC.
|
|
57
|
+
readContract(client, {
|
|
58
|
+
address: blue,
|
|
59
|
+
abi: blueAbi,
|
|
60
|
+
functionName: "feeRecipient",
|
|
61
|
+
}),
|
|
62
|
+
]);
|
|
63
|
+
if (!isAddressEqual(morpho, blue)) {
|
|
64
|
+
throw new VaultMorphoMismatchError({
|
|
65
|
+
vault: vault,
|
|
66
|
+
expected: blue,
|
|
67
|
+
actual: morpho,
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
// Reject this unsupported configuration before authorizing vault shares:
|
|
71
|
+
// VaultExitBundlesV1 omits newly accrued Morpho fee shares when estimating the
|
|
72
|
+
// vault position, so its callback can exhaust marketParamsList and panic on-chain.
|
|
73
|
+
if (isAddressEqual(blueFeeRecipient, vault)) {
|
|
74
|
+
throw new VaultIsBlueFeeRecipientError(vault, blue);
|
|
75
|
+
}
|
|
76
|
+
if (blueBalance < amount) {
|
|
77
|
+
throw new InsufficientBlueBalanceForInKindRedeemError({
|
|
78
|
+
asset: vaultData.asset,
|
|
79
|
+
available: blueBalance,
|
|
80
|
+
required: amount,
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
if (allowance >= requiredShareAllowance) {
|
|
84
|
+
return [];
|
|
85
|
+
}
|
|
86
|
+
if (supportSignature) {
|
|
87
|
+
return [
|
|
88
|
+
encodeVaultSharesPermit({
|
|
89
|
+
now: params.now,
|
|
90
|
+
vault: vaultData,
|
|
91
|
+
version: "vaultV1",
|
|
92
|
+
spender: vaultExitBundlesV1,
|
|
93
|
+
owner: userAddress,
|
|
94
|
+
chainId: chainId,
|
|
95
|
+
nonce,
|
|
96
|
+
deadline,
|
|
97
|
+
}),
|
|
98
|
+
];
|
|
99
|
+
}
|
|
100
|
+
return [
|
|
101
|
+
encodeErc20Approval({
|
|
102
|
+
token: vault,
|
|
103
|
+
spender: vaultExitBundlesV1,
|
|
104
|
+
amount: maxUint256,
|
|
105
|
+
chainId: chainId,
|
|
106
|
+
}),
|
|
107
|
+
];
|
|
108
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { AccrualVaultV2 } from "@morpho-org/blue-sdk";
|
|
2
|
+
import type { Client } from "viem";
|
|
3
|
+
import { type Address } from "viem";
|
|
4
|
+
import { type ActionRequirement, type ReferenceTimestampParams } from "../../types/index.js";
|
|
5
|
+
/**
|
|
6
|
+
* @internal Resolves exit preflight reads and share authorization without an entity handle.
|
|
7
|
+
* @param client - Client serving the requested chain.
|
|
8
|
+
* @param params - Snapshot and fixed quote used for authorization.
|
|
9
|
+
* @param params.now - See {@link ReferenceTimestampParams.now}.
|
|
10
|
+
* @returns Share approvals or permit requirements.
|
|
11
|
+
*/
|
|
12
|
+
export declare function getVaultV2ForceWithdrawRequirements(client: Client, params: {
|
|
13
|
+
readonly vaultData: AccrualVaultV2;
|
|
14
|
+
readonly vault: Address;
|
|
15
|
+
readonly userAddress: Address;
|
|
16
|
+
readonly chainId: number;
|
|
17
|
+
readonly deadline: bigint;
|
|
18
|
+
readonly requiredShareAllowance: bigint;
|
|
19
|
+
readonly supportSignature: boolean;
|
|
20
|
+
} & ReferenceTimestampParams): Promise<readonly ActionRequirement[]>;
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import { erc2612Abi } from "@morpho-org/blue-sdk-viem";
|
|
2
|
+
import { getChainAddress, Time } from "@morpho-org/morpho-ts";
|
|
3
|
+
import { erc20Abi, maxUint256 } from "viem";
|
|
4
|
+
import { readContract } from "viem/actions";
|
|
5
|
+
import { encodeErc20Approval, encodeVaultSharesPermit, } from "../../actions/index.js";
|
|
6
|
+
import { validateClientChainId } from "../../actions/requirements/validateClientChainId.js";
|
|
7
|
+
import { ExpiredDeadlineError, } from "../../types/index.js";
|
|
8
|
+
import { assertRegistryTargetsHaveCode } from "./assertContractCode.js";
|
|
9
|
+
/**
|
|
10
|
+
* @internal Resolves exit preflight reads and share authorization without an entity handle.
|
|
11
|
+
* @param client - Client serving the requested chain.
|
|
12
|
+
* @param params - Snapshot and fixed quote used for authorization.
|
|
13
|
+
* @param params.now - See {@link ReferenceTimestampParams.now}.
|
|
14
|
+
* @returns Share approvals or permit requirements.
|
|
15
|
+
*/
|
|
16
|
+
export async function getVaultV2ForceWithdrawRequirements(client, params) {
|
|
17
|
+
const { vaultData, vault, userAddress, chainId, deadline, requiredShareAllowance, supportSignature, } = params;
|
|
18
|
+
const vaultExitBundlesV1 = getChainAddress(chainId, "bundles.vaultExitBundlesV1");
|
|
19
|
+
const requirementsTimestamp = params.now ?? Time.timestamp();
|
|
20
|
+
if (deadline <= requirementsTimestamp) {
|
|
21
|
+
throw new ExpiredDeadlineError(deadline, requirementsTimestamp);
|
|
22
|
+
}
|
|
23
|
+
await validateClientChainId(client, chainId);
|
|
24
|
+
await assertRegistryTargetsHaveCode(client, chainId, [
|
|
25
|
+
{
|
|
26
|
+
role: "bundles.vaultExitBundlesV1",
|
|
27
|
+
address: getChainAddress(chainId, "bundles.vaultExitBundlesV1"),
|
|
28
|
+
},
|
|
29
|
+
]);
|
|
30
|
+
// Vault gates are intentionally left to the final transaction: the receive-assets gate may
|
|
31
|
+
// inspect VaultExitBundlesV1's transient `initiator`, and a send-shares gate is arbitrary
|
|
32
|
+
// external code re-evaluated after each intermediate penalty burn, so neither is
|
|
33
|
+
// execution-equivalent from a standalone read. Unlike in-kind redemption, this exit never
|
|
34
|
+
// supplies into Morpho Blue, so no Blue token-balance check is needed.
|
|
35
|
+
const [allowance, nonce] = await Promise.all([
|
|
36
|
+
readContract(client, {
|
|
37
|
+
address: vault,
|
|
38
|
+
abi: erc20Abi,
|
|
39
|
+
functionName: "allowance",
|
|
40
|
+
args: [userAddress, vaultExitBundlesV1],
|
|
41
|
+
}),
|
|
42
|
+
readContract(client, {
|
|
43
|
+
address: vault,
|
|
44
|
+
abi: erc2612Abi,
|
|
45
|
+
functionName: "nonces",
|
|
46
|
+
args: [userAddress],
|
|
47
|
+
}),
|
|
48
|
+
]);
|
|
49
|
+
if (allowance >= requiredShareAllowance) {
|
|
50
|
+
return [];
|
|
51
|
+
}
|
|
52
|
+
if (supportSignature) {
|
|
53
|
+
const requirement = encodeVaultSharesPermit({
|
|
54
|
+
now: params.now,
|
|
55
|
+
vault: vaultData,
|
|
56
|
+
version: "vaultV2",
|
|
57
|
+
spender: vaultExitBundlesV1,
|
|
58
|
+
owner: userAddress,
|
|
59
|
+
chainId: chainId,
|
|
60
|
+
nonce,
|
|
61
|
+
deadline,
|
|
62
|
+
});
|
|
63
|
+
return [requirement];
|
|
64
|
+
}
|
|
65
|
+
return [
|
|
66
|
+
encodeErc20Approval({
|
|
67
|
+
token: vault,
|
|
68
|
+
spender: vaultExitBundlesV1,
|
|
69
|
+
amount: maxUint256,
|
|
70
|
+
chainId: chainId,
|
|
71
|
+
}),
|
|
72
|
+
];
|
|
73
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { AccrualVaultV2 } from "@morpho-org/blue-sdk";
|
|
2
|
+
import type { Client } from "viem";
|
|
3
|
+
import { type Address } from "viem";
|
|
4
|
+
import { type ActionRequirement, type ReferenceTimestampParams } from "../../types/index.js";
|
|
5
|
+
/**
|
|
6
|
+
* @internal Resolves exit preflight reads and share authorization without an entity handle.
|
|
7
|
+
* @param client - Client serving the requested chain.
|
|
8
|
+
* @param params - Snapshot and fixed quote used for authorization.
|
|
9
|
+
* @param params.now - See {@link ReferenceTimestampParams.now}.
|
|
10
|
+
* @returns Share approvals or permit requirements.
|
|
11
|
+
*/
|
|
12
|
+
export declare function getVaultV2InKindRedeemRequirements(client: Client, params: ReferenceTimestampParams & {
|
|
13
|
+
readonly vaultData: AccrualVaultV2;
|
|
14
|
+
readonly vault: Address;
|
|
15
|
+
readonly userAddress: Address;
|
|
16
|
+
readonly chainId: number;
|
|
17
|
+
readonly deadline: bigint;
|
|
18
|
+
readonly requiredShareAllowance: bigint;
|
|
19
|
+
readonly supportSignature: boolean;
|
|
20
|
+
readonly peak: bigint;
|
|
21
|
+
}): Promise<readonly ActionRequirement[]>;
|