@morpho-org/morpho-sdk 4.2.0 → 5.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +16 -16
- package/lib/cjs/actions/blue/borrow.d.ts +12 -2
- package/lib/cjs/actions/blue/borrow.js +7 -1
- package/lib/cjs/actions/blue/buildAssetFundingActions.d.ts +47 -0
- package/lib/cjs/actions/blue/buildAssetFundingActions.js +63 -0
- package/lib/cjs/actions/blue/refinance.d.ts +13 -3
- package/lib/cjs/actions/blue/refinance.js +8 -2
- package/lib/cjs/actions/blue/repay.d.ts +44 -43
- package/lib/cjs/actions/blue/repay.js +70 -59
- package/lib/cjs/actions/blue/repayWithdrawCollateral.d.ts +50 -41
- package/lib/cjs/actions/blue/repayWithdrawCollateral.js +75 -54
- package/lib/cjs/actions/blue/resolveRepayFunding.d.ts +69 -0
- package/lib/cjs/actions/blue/resolveRepayFunding.js +82 -0
- package/lib/cjs/actions/blue/supply.d.ts +8 -8
- package/lib/cjs/actions/blue/supply.js +11 -35
- package/lib/cjs/actions/blue/supplyCollateral.d.ts +9 -9
- package/lib/cjs/actions/blue/supplyCollateral.js +12 -36
- package/lib/cjs/actions/blue/supplyCollateralBorrow.d.ts +19 -7
- package/lib/cjs/actions/blue/supplyCollateralBorrow.js +17 -32
- package/lib/cjs/actions/blue/withdraw.d.ts +10 -2
- package/lib/cjs/actions/blue/withdraw.js +7 -1
- package/lib/cjs/actions/index.d.ts +1 -0
- package/lib/cjs/actions/index.js +1 -0
- package/lib/cjs/actions/requirements/blue/getBlueAuthorizationRequirement.d.ts +49 -0
- package/lib/cjs/actions/requirements/blue/getBlueAuthorizationRequirement.js +111 -0
- package/lib/cjs/actions/requirements/blue/index.d.ts +1 -0
- package/lib/cjs/actions/requirements/blue/index.js +17 -0
- package/lib/cjs/actions/requirements/encode/encodeBlueSignatureAuthorization.d.ts +55 -0
- package/lib/cjs/actions/requirements/encode/encodeBlueSignatureAuthorization.js +89 -0
- package/lib/cjs/actions/requirements/encode/encodeErc20Approval.d.ts +6 -5
- package/lib/cjs/actions/requirements/encode/encodeErc20Approval.js +17 -5
- package/lib/cjs/actions/requirements/encode/encodeErc20Permit.d.ts +9 -7
- package/lib/cjs/actions/requirements/encode/encodeErc20Permit.js +18 -4
- package/lib/cjs/actions/requirements/encode/{encodeErc20Permit2.d.ts → encodeErc20Permit2Approve.d.ts} +11 -13
- package/lib/cjs/actions/requirements/encode/{encodeErc20Permit2.js → encodeErc20Permit2Approve.js} +10 -14
- package/lib/cjs/actions/requirements/encode/index.d.ts +2 -1
- package/lib/cjs/actions/requirements/encode/index.js +2 -1
- package/lib/cjs/actions/requirements/{getRequirements.d.ts → generalAdapter/getGeneralAdapterRequirements.d.ts} +34 -20
- package/lib/cjs/actions/requirements/generalAdapter/getGeneralAdapterRequirements.js +151 -0
- package/lib/{esm/actions/requirements/getRequirementsPermit.d.ts → cjs/actions/requirements/generalAdapter/getGeneralAdapterRequirementsPermit.d.ts} +6 -14
- package/lib/cjs/actions/requirements/generalAdapter/getGeneralAdapterRequirementsPermit.js +50 -0
- package/lib/cjs/actions/requirements/generalAdapter/getGeneralAdapterRequirementsPermit2.d.ts +57 -0
- package/lib/cjs/actions/requirements/generalAdapter/getGeneralAdapterRequirementsPermit2.js +74 -0
- package/lib/cjs/actions/requirements/generalAdapter/index.d.ts +3 -0
- package/lib/cjs/actions/requirements/generalAdapter/index.js +19 -0
- package/lib/cjs/actions/requirements/getRequirementsApproval.d.ts +3 -2
- package/lib/cjs/actions/requirements/getRequirementsApproval.js +3 -2
- package/lib/cjs/actions/requirements/index.d.ts +2 -5
- package/lib/cjs/actions/requirements/index.js +2 -5
- package/lib/cjs/actions/signatures/getBlueAuthorizationAction.d.ts +29 -0
- package/lib/cjs/actions/signatures/getBlueAuthorizationAction.js +48 -0
- package/lib/{esm/actions/requirements/getRequirementsAction.d.ts → cjs/actions/signatures/getTokenRequirementActions.d.ts} +17 -17
- package/lib/cjs/actions/{requirements/getRequirementsAction.js → signatures/getTokenRequirementActions.js} +26 -13
- package/lib/cjs/actions/signatures/index.d.ts +2 -0
- package/lib/cjs/actions/signatures/index.js +18 -0
- package/lib/cjs/actions/vaultV1/deposit.d.ts +6 -8
- package/lib/cjs/actions/vaultV1/deposit.js +11 -21
- package/lib/cjs/actions/vaultV1/migrateToV2.d.ts +6 -6
- package/lib/cjs/actions/vaultV1/migrateToV2.js +12 -20
- package/lib/cjs/actions/vaultV2/deposit.d.ts +6 -8
- package/lib/cjs/actions/vaultV2/deposit.js +11 -21
- package/lib/cjs/addresses.d.ts +2 -2
- package/lib/cjs/addresses.js +2 -1
- package/lib/cjs/bundler/actions.d.ts +44 -4
- package/lib/cjs/bundler/actions.js +75 -2
- package/lib/cjs/bundler/types.d.ts +6 -0
- package/lib/cjs/constants.d.ts +2 -2
- package/lib/cjs/constants.js +3 -3
- package/lib/cjs/entities/blue/blue.d.ts +58 -33
- package/lib/cjs/entities/blue/blue.js +309 -189
- package/lib/cjs/entities/reallocationData.d.ts +0 -44
- package/lib/cjs/entities/reallocationData.js +3 -50
- package/lib/cjs/entities/vaultV1/vaultV1.d.ts +9 -9
- package/lib/cjs/entities/vaultV1/vaultV1.js +44 -34
- package/lib/cjs/entities/vaultV2/vaultV2.d.ts +6 -6
- package/lib/cjs/entities/vaultV2/vaultV2.js +21 -16
- package/lib/cjs/errors.d.ts +3 -2
- package/lib/cjs/errors.js +5 -2
- package/lib/cjs/helpers/index.d.ts +1 -1
- package/lib/cjs/helpers/index.js +1 -2
- package/lib/cjs/helpers/validate.d.ts +2 -20
- package/lib/cjs/helpers/validate.js +2 -39
- package/lib/cjs/types/action.d.ts +164 -12
- package/lib/cjs/types/action.js +79 -5
- package/lib/cjs/types/error.d.ts +97 -2
- package/lib/cjs/types/error.js +113 -7
- package/lib/cjs/types.d.ts +2 -1
- package/lib/cjs/utils.d.ts +2 -2
- package/lib/cjs/utils.js +2 -4
- package/lib/esm/actions/blue/borrow.d.ts +12 -2
- package/lib/esm/actions/blue/borrow.js +7 -1
- package/lib/esm/actions/blue/buildAssetFundingActions.d.ts +47 -0
- package/lib/esm/actions/blue/buildAssetFundingActions.js +59 -0
- package/lib/esm/actions/blue/refinance.d.ts +13 -3
- package/lib/esm/actions/blue/refinance.js +8 -2
- package/lib/esm/actions/blue/repay.d.ts +44 -43
- package/lib/esm/actions/blue/repay.js +71 -60
- package/lib/esm/actions/blue/repayWithdrawCollateral.d.ts +50 -41
- package/lib/esm/actions/blue/repayWithdrawCollateral.js +76 -55
- package/lib/esm/actions/blue/resolveRepayFunding.d.ts +69 -0
- package/lib/esm/actions/blue/resolveRepayFunding.js +78 -0
- package/lib/esm/actions/blue/supply.d.ts +8 -8
- package/lib/esm/actions/blue/supply.js +12 -36
- package/lib/esm/actions/blue/supplyCollateral.d.ts +9 -9
- package/lib/esm/actions/blue/supplyCollateral.js +13 -37
- package/lib/esm/actions/blue/supplyCollateralBorrow.d.ts +19 -7
- package/lib/esm/actions/blue/supplyCollateralBorrow.js +18 -33
- package/lib/esm/actions/blue/withdraw.d.ts +10 -2
- package/lib/esm/actions/blue/withdraw.js +7 -1
- package/lib/esm/actions/index.d.ts +1 -0
- package/lib/esm/actions/index.js +1 -0
- package/lib/esm/actions/requirements/blue/getBlueAuthorizationRequirement.d.ts +49 -0
- package/lib/esm/actions/requirements/blue/getBlueAuthorizationRequirement.js +107 -0
- package/lib/esm/actions/requirements/blue/index.d.ts +1 -0
- package/lib/esm/actions/requirements/blue/index.js +1 -0
- package/lib/esm/actions/requirements/encode/encodeBlueSignatureAuthorization.d.ts +55 -0
- package/lib/esm/actions/requirements/encode/encodeBlueSignatureAuthorization.js +85 -0
- package/lib/esm/actions/requirements/encode/encodeErc20Approval.d.ts +6 -5
- package/lib/esm/actions/requirements/encode/encodeErc20Approval.js +19 -7
- package/lib/esm/actions/requirements/encode/encodeErc20Permit.d.ts +9 -7
- package/lib/esm/actions/requirements/encode/encodeErc20Permit.js +20 -6
- package/lib/esm/actions/requirements/encode/{encodeErc20Permit2.d.ts → encodeErc20Permit2Approve.d.ts} +11 -13
- package/lib/esm/actions/requirements/encode/{encodeErc20Permit2.js → encodeErc20Permit2Approve.js} +8 -12
- package/lib/esm/actions/requirements/encode/index.d.ts +2 -1
- package/lib/esm/actions/requirements/encode/index.js +2 -1
- package/lib/esm/actions/requirements/{getRequirements.d.ts → generalAdapter/getGeneralAdapterRequirements.d.ts} +34 -20
- package/lib/esm/actions/requirements/generalAdapter/getGeneralAdapterRequirements.js +147 -0
- package/lib/{cjs/actions/requirements/getRequirementsPermit.d.ts → esm/actions/requirements/generalAdapter/getGeneralAdapterRequirementsPermit.d.ts} +6 -14
- package/lib/esm/actions/requirements/generalAdapter/getGeneralAdapterRequirementsPermit.js +46 -0
- package/lib/esm/actions/requirements/generalAdapter/getGeneralAdapterRequirementsPermit2.d.ts +57 -0
- package/lib/esm/actions/requirements/generalAdapter/getGeneralAdapterRequirementsPermit2.js +70 -0
- package/lib/esm/actions/requirements/generalAdapter/index.d.ts +3 -0
- package/lib/esm/actions/requirements/generalAdapter/index.js +3 -0
- package/lib/esm/actions/requirements/getRequirementsApproval.d.ts +3 -2
- package/lib/esm/actions/requirements/getRequirementsApproval.js +3 -2
- package/lib/esm/actions/requirements/index.d.ts +2 -5
- package/lib/esm/actions/requirements/index.js +2 -5
- package/lib/esm/actions/signatures/getBlueAuthorizationAction.d.ts +29 -0
- package/lib/esm/actions/signatures/getBlueAuthorizationAction.js +44 -0
- package/lib/{cjs/actions/requirements/getRequirementsAction.d.ts → esm/actions/signatures/getTokenRequirementActions.d.ts} +17 -17
- package/lib/esm/actions/{requirements/getRequirementsAction.js → signatures/getTokenRequirementActions.js} +24 -11
- package/lib/esm/actions/signatures/index.d.ts +2 -0
- package/lib/esm/actions/signatures/index.js +2 -0
- package/lib/esm/actions/vaultV1/deposit.d.ts +6 -8
- package/lib/esm/actions/vaultV1/deposit.js +11 -21
- package/lib/esm/actions/vaultV1/migrateToV2.d.ts +6 -6
- package/lib/esm/actions/vaultV1/migrateToV2.js +12 -20
- package/lib/esm/actions/vaultV2/deposit.d.ts +6 -8
- package/lib/esm/actions/vaultV2/deposit.js +11 -21
- package/lib/esm/addresses.d.ts +2 -2
- package/lib/esm/addresses.js +1 -1
- package/lib/esm/bundler/actions.d.ts +44 -4
- package/lib/esm/bundler/actions.js +77 -4
- package/lib/esm/bundler/types.d.ts +6 -0
- package/lib/esm/constants.d.ts +2 -2
- package/lib/esm/constants.js +2 -2
- package/lib/esm/entities/blue/blue.d.ts +58 -33
- package/lib/esm/entities/blue/blue.js +311 -191
- package/lib/esm/entities/reallocationData.d.ts +0 -44
- package/lib/esm/entities/reallocationData.js +2 -49
- package/lib/esm/entities/vaultV1/vaultV1.d.ts +9 -9
- package/lib/esm/entities/vaultV1/vaultV1.js +46 -36
- package/lib/esm/entities/vaultV2/vaultV2.d.ts +6 -6
- package/lib/esm/entities/vaultV2/vaultV2.js +23 -18
- package/lib/esm/errors.d.ts +3 -2
- package/lib/esm/errors.js +2 -1
- package/lib/esm/helpers/index.d.ts +1 -1
- package/lib/esm/helpers/index.js +1 -1
- package/lib/esm/helpers/validate.d.ts +2 -20
- package/lib/esm/helpers/validate.js +2 -38
- package/lib/esm/types/action.d.ts +164 -12
- package/lib/esm/types/action.js +75 -4
- package/lib/esm/types/error.d.ts +97 -2
- package/lib/esm/types/error.js +107 -5
- package/lib/esm/types.d.ts +2 -1
- package/lib/esm/utils.d.ts +2 -2
- package/lib/esm/utils.js +2 -2
- package/package.json +22 -21
- package/lib/cjs/actions/requirements/getMorphoAuthorizationRequirement.d.ts +0 -37
- package/lib/cjs/actions/requirements/getMorphoAuthorizationRequirement.js +0 -71
- package/lib/cjs/actions/requirements/getRequirements.js +0 -112
- package/lib/cjs/actions/requirements/getRequirementsPermit.js +0 -57
- package/lib/cjs/actions/requirements/getRequirementsPermit2.d.ts +0 -63
- package/lib/cjs/actions/requirements/getRequirementsPermit2.js +0 -85
- package/lib/esm/actions/requirements/getMorphoAuthorizationRequirement.d.ts +0 -37
- package/lib/esm/actions/requirements/getMorphoAuthorizationRequirement.js +0 -67
- package/lib/esm/actions/requirements/getRequirements.js +0 -108
- package/lib/esm/actions/requirements/getRequirementsPermit.js +0 -53
- package/lib/esm/actions/requirements/getRequirementsPermit2.d.ts +0 -63
- package/lib/esm/actions/requirements/getRequirementsPermit2.js +0 -81
- package/src/index.ts +0 -4
|
@@ -253,50 +253,6 @@ export declare class ReallocationData implements InputReallocationData {
|
|
|
253
253
|
* ```
|
|
254
254
|
*/
|
|
255
255
|
getAvailableLiquidityToUtilization(marketId: MarketId, utilization?: bigint, options?: ReallocationComputeOptions): bigint;
|
|
256
|
-
/**
|
|
257
|
-
* Computes the liquidity available to bring `marketId` to `utilization`,
|
|
258
|
-
* counting the public-allocator liquidity reallocatable into it.
|
|
259
|
-
*
|
|
260
|
-
* @deprecated Renamed to {@link getAvailableLiquidityToUtilization} — the
|
|
261
|
-
* `target` wording wrongly implied a market's configured supply-target
|
|
262
|
-
* utilization, whereas the argument is an arbitrary utilization ceiling.
|
|
263
|
-
* Delegates to the new method; will be removed in the next major.
|
|
264
|
-
*
|
|
265
|
-
* @param marketId - Target market to borrow from.
|
|
266
|
-
* @param targetUtilization - Utilization to bring the market to, scaled by WAD. Defaults to {@link DEFAULT_SUPPLY_TARGET_UTILIZATION}.
|
|
267
|
-
* @param options - Optional reallocation options (supply target utilization trigger, timestamp, withdrawal caps).
|
|
268
|
-
* @returns Available liquidity to the given utilization in loan-token units; `0n` when none is available.
|
|
269
|
-
* @throws {@link UnknownReallocationMarketError} when the target market is absent.
|
|
270
|
-
* @example
|
|
271
|
-
* ```ts
|
|
272
|
-
* import { createPublicClient, http, parseEther } from "viem";
|
|
273
|
-
* import { mainnet } from "viem/chains";
|
|
274
|
-
* import { markets, vaults } from "@morpho-org/morpho-test";
|
|
275
|
-
* import { morphoViemExtension } from "@morpho-org/morpho-sdk";
|
|
276
|
-
*
|
|
277
|
-
* const client = createPublicClient({
|
|
278
|
-
* chain: mainnet,
|
|
279
|
-
* transport: http(),
|
|
280
|
-
* }).extend(morphoViemExtension());
|
|
281
|
-
*
|
|
282
|
-
* const marketParams = markets[mainnet.id].usdc_wbtc;
|
|
283
|
-
* const market = client.morpho.blue(marketParams, mainnet.id);
|
|
284
|
-
* const block = await client.getBlock();
|
|
285
|
-
* const reallocationData = await market.getReallocationData({
|
|
286
|
-
* vaultAddresses: [vaults[mainnet.id].steakUsdc.address],
|
|
287
|
-
* block: { number: block.number, timestamp: block.timestamp },
|
|
288
|
-
* });
|
|
289
|
-
*
|
|
290
|
-
* // Deprecated: prefer reallocationData.getAvailableLiquidityToUtilization.
|
|
291
|
-
* const available: bigint =
|
|
292
|
-
* reallocationData.getAvailableLiquidityToTargetUtilization(
|
|
293
|
-
* marketParams.id,
|
|
294
|
-
* parseEther("0.9"),
|
|
295
|
-
* { timestamp: block.timestamp },
|
|
296
|
-
* );
|
|
297
|
-
* ```
|
|
298
|
-
*/
|
|
299
|
-
getAvailableLiquidityToTargetUtilization(marketId: MarketId, targetUtilization?: bigint, options?: ReallocationComputeOptions): bigint;
|
|
300
256
|
/**
|
|
301
257
|
* Gets the largest currently valid source-market withdrawal for a vault.
|
|
302
258
|
*
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { bigIntComparator } from "@morpho-org/morpho-ts";
|
|
1
|
+
import { AccrualPosition, Market, MarketUtils, MathLib, Position, UnknownDataError, Vault, VaultMarketConfig, VaultMarketPublicAllocatorConfig, } from "@morpho-org/blue-sdk";
|
|
2
|
+
import { _try, bigIntComparator } from "@morpho-org/morpho-ts";
|
|
3
3
|
import { DEFAULT_SUPPLY_TARGET_UTILIZATION, DEFAULT_WITHDRAWAL_TARGET_UTILIZATION, } from "../helpers/constant.js";
|
|
4
4
|
import { getSupplyTargetUtilization } from "../helpers/utilization.js";
|
|
5
5
|
import { DisabledReallocationMarketError, MissingPublicAllocatorConfigError, UnknownReallocationMarketError, UnknownReallocationPositionError, UnknownReallocationVaultError, UnknownReallocationVaultMarketConfigError, } from "../types/index.js";
|
|
@@ -411,53 +411,6 @@ export class ReallocationData {
|
|
|
411
411
|
totalBorrowAssets: market.totalBorrowAssets,
|
|
412
412
|
}, utilization);
|
|
413
413
|
}
|
|
414
|
-
/**
|
|
415
|
-
* Computes the liquidity available to bring `marketId` to `utilization`,
|
|
416
|
-
* counting the public-allocator liquidity reallocatable into it.
|
|
417
|
-
*
|
|
418
|
-
* @deprecated Renamed to {@link getAvailableLiquidityToUtilization} — the
|
|
419
|
-
* `target` wording wrongly implied a market's configured supply-target
|
|
420
|
-
* utilization, whereas the argument is an arbitrary utilization ceiling.
|
|
421
|
-
* Delegates to the new method; will be removed in the next major.
|
|
422
|
-
*
|
|
423
|
-
* @param marketId - Target market to borrow from.
|
|
424
|
-
* @param targetUtilization - Utilization to bring the market to, scaled by WAD. Defaults to {@link DEFAULT_SUPPLY_TARGET_UTILIZATION}.
|
|
425
|
-
* @param options - Optional reallocation options (supply target utilization trigger, timestamp, withdrawal caps).
|
|
426
|
-
* @returns Available liquidity to the given utilization in loan-token units; `0n` when none is available.
|
|
427
|
-
* @throws {@link UnknownReallocationMarketError} when the target market is absent.
|
|
428
|
-
* @example
|
|
429
|
-
* ```ts
|
|
430
|
-
* import { createPublicClient, http, parseEther } from "viem";
|
|
431
|
-
* import { mainnet } from "viem/chains";
|
|
432
|
-
* import { markets, vaults } from "@morpho-org/morpho-test";
|
|
433
|
-
* import { morphoViemExtension } from "@morpho-org/morpho-sdk";
|
|
434
|
-
*
|
|
435
|
-
* const client = createPublicClient({
|
|
436
|
-
* chain: mainnet,
|
|
437
|
-
* transport: http(),
|
|
438
|
-
* }).extend(morphoViemExtension());
|
|
439
|
-
*
|
|
440
|
-
* const marketParams = markets[mainnet.id].usdc_wbtc;
|
|
441
|
-
* const market = client.morpho.blue(marketParams, mainnet.id);
|
|
442
|
-
* const block = await client.getBlock();
|
|
443
|
-
* const reallocationData = await market.getReallocationData({
|
|
444
|
-
* vaultAddresses: [vaults[mainnet.id].steakUsdc.address],
|
|
445
|
-
* block: { number: block.number, timestamp: block.timestamp },
|
|
446
|
-
* });
|
|
447
|
-
*
|
|
448
|
-
* // Deprecated: prefer reallocationData.getAvailableLiquidityToUtilization.
|
|
449
|
-
* const available: bigint =
|
|
450
|
-
* reallocationData.getAvailableLiquidityToTargetUtilization(
|
|
451
|
-
* marketParams.id,
|
|
452
|
-
* parseEther("0.9"),
|
|
453
|
-
* { timestamp: block.timestamp },
|
|
454
|
-
* );
|
|
455
|
-
* ```
|
|
456
|
-
*/
|
|
457
|
-
// biome-ignore lint/complexity/useMaxParams: (marketId, targetUtilization, options) is the metric's public API
|
|
458
|
-
getAvailableLiquidityToTargetUtilization(marketId, targetUtilization = DEFAULT_SUPPLY_TARGET_UTILIZATION, options) {
|
|
459
|
-
return this.getAvailableLiquidityToUtilization(marketId, targetUtilization, options);
|
|
460
|
-
}
|
|
461
414
|
/**
|
|
462
415
|
* Gets the largest currently valid source-market withdrawal for a vault.
|
|
463
416
|
*
|
|
@@ -2,7 +2,7 @@ import { type AccrualVault, type AccrualVaultV2 } from "@morpho-org/blue-sdk";
|
|
|
2
2
|
import { fetchAccrualVault } from "@morpho-org/blue-sdk-viem";
|
|
3
3
|
import { type Address } from "viem";
|
|
4
4
|
import type { FetchParameters } from "../../types/data.js";
|
|
5
|
-
import { type DepositAmountArgs, type ERC20ApprovalAction, type MorphoClientType, type Requirement, type RequirementSignature, type Transaction, type VaultV1DepositAction, type VaultV1MigrateToV2Action, type VaultV1RedeemAction, type VaultV1WithdrawAction } from "../../types/index.js";
|
|
5
|
+
import { type DepositAmountArgs, type ERC20ApprovalAction, type MorphoClientType, type PermitRequirementSignature, type Requirement, type RequirementSignature, type Transaction, type VaultV1DepositAction, type VaultV1MigrateToV2Action, type VaultV1RedeemAction, type VaultV1WithdrawAction } from "../../types/index.js";
|
|
6
6
|
export interface VaultV1Actions {
|
|
7
7
|
/**
|
|
8
8
|
* Fetches the latest vault data with accrued interest.
|
|
@@ -30,10 +30,10 @@ export interface VaultV1Actions {
|
|
|
30
30
|
vaultData: AccrualVault;
|
|
31
31
|
slippageTolerance?: bigint;
|
|
32
32
|
} & DepositAmountArgs) => {
|
|
33
|
-
buildTx: (
|
|
33
|
+
buildTx: (signatures?: readonly RequirementSignature[]) => Readonly<Transaction<VaultV1DepositAction>>;
|
|
34
34
|
getRequirements: (params?: {
|
|
35
35
|
useSimplePermit?: boolean;
|
|
36
|
-
}) => Promise<(Readonly<Transaction<ERC20ApprovalAction>> | Requirement)[]>;
|
|
36
|
+
}) => Promise<(Readonly<Transaction<ERC20ApprovalAction>> | Requirement<PermitRequirementSignature>)[]>;
|
|
37
37
|
};
|
|
38
38
|
/**
|
|
39
39
|
* Prepares a withdraw from a VaultV1 (MetaMorpho) contract.
|
|
@@ -84,8 +84,8 @@ export interface VaultV1Actions {
|
|
|
84
84
|
shares: bigint;
|
|
85
85
|
slippageTolerance?: bigint;
|
|
86
86
|
}) => {
|
|
87
|
-
buildTx: (
|
|
88
|
-
getRequirements: () => Promise<(Readonly<Transaction<ERC20ApprovalAction>> | Requirement)[]>;
|
|
87
|
+
buildTx: (signatures?: readonly RequirementSignature[]) => Readonly<Transaction<VaultV1MigrateToV2Action>>;
|
|
88
|
+
getRequirements: () => Promise<(Readonly<Transaction<ERC20ApprovalAction>> | Requirement<PermitRequirementSignature>)[]>;
|
|
89
89
|
};
|
|
90
90
|
}
|
|
91
91
|
export declare class MorphoVaultV1 implements VaultV1Actions {
|
|
@@ -101,8 +101,8 @@ export declare class MorphoVaultV1 implements VaultV1Actions {
|
|
|
101
101
|
} & DepositAmountArgs): {
|
|
102
102
|
getRequirements: (params?: {
|
|
103
103
|
useSimplePermit?: boolean;
|
|
104
|
-
}) => Promise<(
|
|
105
|
-
buildTx: (
|
|
104
|
+
}) => Promise<(import("../../types/action.js").Bundler3TokenSignatureRequirement | Readonly<Transaction<ERC20ApprovalAction>>)[]>;
|
|
105
|
+
buildTx: (signatures?: readonly RequirementSignature[]) => Readonly<Transaction<VaultV1DepositAction>>;
|
|
106
106
|
};
|
|
107
107
|
withdraw({ amount, userAddress }: {
|
|
108
108
|
amount: bigint;
|
|
@@ -123,7 +123,7 @@ export declare class MorphoVaultV1 implements VaultV1Actions {
|
|
|
123
123
|
shares: bigint;
|
|
124
124
|
slippageTolerance?: bigint;
|
|
125
125
|
}): {
|
|
126
|
-
getRequirements: () => Promise<(
|
|
127
|
-
buildTx: (
|
|
126
|
+
getRequirements: () => Promise<(import("../../types/action.js").Bundler3TokenSignatureRequirement | Readonly<Transaction<ERC20ApprovalAction>>)[]>;
|
|
127
|
+
buildTx: (signatures?: readonly RequirementSignature[]) => Readonly<Transaction<VaultV1MigrateToV2Action>>;
|
|
128
128
|
};
|
|
129
129
|
}
|
|
@@ -2,10 +2,10 @@ import { DEFAULT_SLIPPAGE_TOLERANCE, getChainAddresses, MathLib, } from "@morpho
|
|
|
2
2
|
import { fetchAccrualVault } from "@morpho-org/blue-sdk-viem";
|
|
3
3
|
import { Time } from "@morpho-org/morpho-ts";
|
|
4
4
|
import { isAddressEqual } from "viem";
|
|
5
|
-
import {
|
|
5
|
+
import { getGeneralAdapterRequirements, vaultV1Deposit, vaultV1MigrateToV2, vaultV1Redeem, vaultV1Withdraw, } from "../../actions/index.js";
|
|
6
6
|
import { MAX_ABSOLUTE_SHARE_PRICE, MAX_SLIPPAGE_TOLERANCE, } from "../../helpers/constant.js";
|
|
7
7
|
import { validateChainId } from "../../helpers/index.js";
|
|
8
|
-
import { ChainIdMismatchError, ChainWNativeMissingError, ExcessiveSlippageToleranceError, NativeAmountOnNonWNativeVaultError, NegativeNativeAmountError, NegativeSlippageToleranceError, NonPositiveAssetAmountError, NonPositiveSharesAmountError, VaultAddressMismatchError, VaultAssetMismatchError, } from "../../types/index.js";
|
|
8
|
+
import { ChainIdMismatchError, ChainWNativeMissingError, ExcessiveSlippageToleranceError, NativeAmountOnNonWNativeVaultError, NegativeNativeAmountError, NegativeSlippageToleranceError, NonPositiveAssetAmountError, NonPositiveSharesAmountError, selectRequirementSignatures, VaultAddressMismatchError, VaultAssetMismatchError, } from "../../types/index.js";
|
|
9
9
|
export class MorphoVaultV1 {
|
|
10
10
|
client;
|
|
11
11
|
vault;
|
|
@@ -65,7 +65,7 @@ export class MorphoVaultV1 {
|
|
|
65
65
|
}
|
|
66
66
|
const maxSharePrice = MathLib.min(MathLib.mulDivUp(totalAssets, MathLib.wToRay(MathLib.WAD + slippageTolerance), shares), MAX_ABSOLUTE_SHARE_PRICE);
|
|
67
67
|
return {
|
|
68
|
-
getRequirements:
|
|
68
|
+
getRequirements: (params) => getGeneralAdapterRequirements(this.client.viemClient, {
|
|
69
69
|
address: vaultData.asset,
|
|
70
70
|
chainId: this.chainId,
|
|
71
71
|
supportSignature: this.client.options.supportSignature,
|
|
@@ -76,21 +76,26 @@ export class MorphoVaultV1 {
|
|
|
76
76
|
from: userAddress,
|
|
77
77
|
},
|
|
78
78
|
}),
|
|
79
|
-
buildTx: (
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
79
|
+
buildTx: (signatures) => {
|
|
80
|
+
const { permit } = selectRequirementSignatures(signatures, {
|
|
81
|
+
permit: true,
|
|
82
|
+
});
|
|
83
|
+
return vaultV1Deposit({
|
|
84
|
+
vault: {
|
|
85
|
+
chainId: this.chainId,
|
|
86
|
+
address: this.vault,
|
|
87
|
+
asset: vaultData.asset,
|
|
88
|
+
},
|
|
89
|
+
args: {
|
|
90
|
+
amount,
|
|
91
|
+
maxSharePrice,
|
|
92
|
+
recipient: userAddress,
|
|
93
|
+
requirementSignature: permit,
|
|
94
|
+
nativeAmount,
|
|
95
|
+
},
|
|
96
|
+
metadata: this.client.options.metadata,
|
|
97
|
+
});
|
|
98
|
+
},
|
|
94
99
|
};
|
|
95
100
|
}
|
|
96
101
|
withdraw({ amount, userAddress }) {
|
|
@@ -155,7 +160,7 @@ export class MorphoVaultV1 {
|
|
|
155
160
|
}
|
|
156
161
|
const maxSharePriceVaultV2 = MathLib.min(MathLib.mulDivUp(v1RefAssets, MathLib.wToRay(MathLib.WAD + slippageTolerance), v2RefShares), MAX_ABSOLUTE_SHARE_PRICE);
|
|
157
162
|
return {
|
|
158
|
-
getRequirements:
|
|
163
|
+
getRequirements: () => getGeneralAdapterRequirements(this.client.viemClient, {
|
|
159
164
|
address: this.vault,
|
|
160
165
|
chainId: this.chainId,
|
|
161
166
|
supportSignature: this.client.options.supportSignature,
|
|
@@ -167,23 +172,28 @@ export class MorphoVaultV1 {
|
|
|
167
172
|
from: userAddress,
|
|
168
173
|
},
|
|
169
174
|
}),
|
|
170
|
-
buildTx: (
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
175
|
+
buildTx: (signatures) => {
|
|
176
|
+
const { permit } = selectRequirementSignatures(signatures, {
|
|
177
|
+
permit: true,
|
|
178
|
+
});
|
|
179
|
+
return vaultV1MigrateToV2({
|
|
180
|
+
vault: {
|
|
181
|
+
chainId: this.chainId,
|
|
182
|
+
address: this.vault,
|
|
183
|
+
asset: sourceVault.asset,
|
|
184
|
+
},
|
|
185
|
+
args: {
|
|
186
|
+
targetVault: targetVault.address,
|
|
187
|
+
targetAsset: targetVault.asset,
|
|
188
|
+
shares,
|
|
189
|
+
minSharePriceVaultV1,
|
|
190
|
+
maxSharePriceVaultV2,
|
|
191
|
+
recipient: userAddress,
|
|
192
|
+
requirementSignature: permit,
|
|
193
|
+
},
|
|
194
|
+
metadata: this.client.options.metadata,
|
|
195
|
+
});
|
|
196
|
+
},
|
|
187
197
|
};
|
|
188
198
|
}
|
|
189
199
|
}
|
|
@@ -2,7 +2,7 @@ import { type AccrualVaultV2 } from "@morpho-org/blue-sdk";
|
|
|
2
2
|
import { fetchAccrualVaultV2 } from "@morpho-org/blue-sdk-viem";
|
|
3
3
|
import { type Address } from "viem";
|
|
4
4
|
import type { FetchParameters } from "../../types/data.js";
|
|
5
|
-
import { type Deallocation, type DepositAmountArgs, type ERC20ApprovalAction, type MorphoClientType, type Requirement, type RequirementSignature, type Transaction, type VaultV2DepositAction, type VaultV2ForceRedeemAction, type VaultV2ForceWithdrawAction, type VaultV2RedeemAction, type VaultV2WithdrawAction } from "../../types/index.js";
|
|
5
|
+
import { type Deallocation, type DepositAmountArgs, type ERC20ApprovalAction, type MorphoClientType, type PermitRequirementSignature, type Requirement, type RequirementSignature, type Transaction, type VaultV2DepositAction, type VaultV2ForceRedeemAction, type VaultV2ForceWithdrawAction, type VaultV2RedeemAction, type VaultV2WithdrawAction } from "../../types/index.js";
|
|
6
6
|
export interface VaultV2Actions {
|
|
7
7
|
/**
|
|
8
8
|
* Fetches the latest vault data.
|
|
@@ -29,17 +29,17 @@ export interface VaultV2Actions {
|
|
|
29
29
|
* @param {bigint} [params.nativeAmount] - Amount of native token to wrap into wNative. Vault asset must be wNative.
|
|
30
30
|
* @returns {Object} The result object.
|
|
31
31
|
* @returns {Readonly<Transaction<VaultV2DepositAction>>} returns.tx The prepared deposit transaction.
|
|
32
|
-
* @returns {Promise<(Readonly<Transaction<ERC20ApprovalAction>> | Requirement)[]>} returns.getRequirements The function for retrieving all required approval transactions.
|
|
32
|
+
* @returns {Promise<(Readonly<Transaction<ERC20ApprovalAction>> | Requirement<PermitRequirementSignature>)[]>} returns.getRequirements The function for retrieving all required approval transactions.
|
|
33
33
|
*/
|
|
34
34
|
deposit: (params: {
|
|
35
35
|
userAddress: Address;
|
|
36
36
|
vaultData: AccrualVaultV2;
|
|
37
37
|
slippageTolerance?: bigint;
|
|
38
38
|
} & DepositAmountArgs) => {
|
|
39
|
-
buildTx: (
|
|
39
|
+
buildTx: (signatures?: readonly RequirementSignature[]) => Readonly<Transaction<VaultV2DepositAction>>;
|
|
40
40
|
getRequirements: (params?: {
|
|
41
41
|
useSimplePermit?: boolean;
|
|
42
|
-
}) => Promise<(Readonly<Transaction<ERC20ApprovalAction>> | Requirement)[]>;
|
|
42
|
+
}) => Promise<(Readonly<Transaction<ERC20ApprovalAction>> | Requirement<PermitRequirementSignature>)[]>;
|
|
43
43
|
};
|
|
44
44
|
/**
|
|
45
45
|
* Prepares a withdraw transaction for the VaultV2 contract.
|
|
@@ -144,8 +144,8 @@ export declare class MorphoVaultV2 implements VaultV2Actions {
|
|
|
144
144
|
} & DepositAmountArgs): {
|
|
145
145
|
getRequirements: (params?: {
|
|
146
146
|
useSimplePermit?: boolean;
|
|
147
|
-
}) => Promise<(
|
|
148
|
-
buildTx: (
|
|
147
|
+
}) => Promise<(import("../../types/action.js").Bundler3TokenSignatureRequirement | Readonly<Transaction<ERC20ApprovalAction>>)[]>;
|
|
148
|
+
buildTx: (signatures?: readonly RequirementSignature[]) => Readonly<Transaction<VaultV2DepositAction>>;
|
|
149
149
|
};
|
|
150
150
|
withdraw({ amount, userAddress }: {
|
|
151
151
|
amount: bigint;
|
|
@@ -2,9 +2,9 @@ import { DEFAULT_SLIPPAGE_TOLERANCE, getChainAddresses, MathLib, } from "@morpho
|
|
|
2
2
|
import { fetchAccrualVaultV2 } from "@morpho-org/blue-sdk-viem";
|
|
3
3
|
import { Time } from "@morpho-org/morpho-ts";
|
|
4
4
|
import { isAddressEqual } from "viem";
|
|
5
|
-
import {
|
|
5
|
+
import { getGeneralAdapterRequirements, vaultV2Deposit, vaultV2ForceRedeem, vaultV2ForceWithdraw, vaultV2Redeem, vaultV2Withdraw, } from "../../actions/index.js";
|
|
6
6
|
import { MAX_SLIPPAGE_TOLERANCE } from "../../helpers/constant.js";
|
|
7
|
-
import { ChainIdMismatchError, ChainWNativeMissingError, ExcessiveSlippageToleranceError, NativeAmountOnNonWNativeVaultError, NegativeNativeAmountError, NegativeSlippageToleranceError, NonPositiveAssetAmountError, NonPositiveSharesAmountError, VaultAddressMismatchError, } from "../../types/index.js";
|
|
7
|
+
import { ChainIdMismatchError, ChainWNativeMissingError, ExcessiveSlippageToleranceError, NativeAmountOnNonWNativeVaultError, NegativeNativeAmountError, NegativeSlippageToleranceError, NonPositiveAssetAmountError, NonPositiveSharesAmountError, selectRequirementSignatures, VaultAddressMismatchError, } from "../../types/index.js";
|
|
8
8
|
export class MorphoVaultV2 {
|
|
9
9
|
client;
|
|
10
10
|
vault;
|
|
@@ -68,7 +68,7 @@ export class MorphoVaultV2 {
|
|
|
68
68
|
}
|
|
69
69
|
const maxSharePrice = MathLib.min(MathLib.mulDivUp(totalAssets, MathLib.wToRay(MathLib.WAD + slippageTolerance), shares), MathLib.RAY * 100n);
|
|
70
70
|
return {
|
|
71
|
-
getRequirements:
|
|
71
|
+
getRequirements: (params) => getGeneralAdapterRequirements(this.client.viemClient, {
|
|
72
72
|
address: vaultData.asset,
|
|
73
73
|
chainId: this.chainId,
|
|
74
74
|
supportSignature: this.client.options.supportSignature,
|
|
@@ -79,21 +79,26 @@ export class MorphoVaultV2 {
|
|
|
79
79
|
from: userAddress,
|
|
80
80
|
},
|
|
81
81
|
}),
|
|
82
|
-
buildTx: (
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
82
|
+
buildTx: (signatures) => {
|
|
83
|
+
const { permit } = selectRequirementSignatures(signatures, {
|
|
84
|
+
permit: true,
|
|
85
|
+
});
|
|
86
|
+
return vaultV2Deposit({
|
|
87
|
+
vault: {
|
|
88
|
+
chainId: this.chainId,
|
|
89
|
+
address: this.vault,
|
|
90
|
+
asset: vaultData.asset,
|
|
91
|
+
},
|
|
92
|
+
args: {
|
|
93
|
+
amount,
|
|
94
|
+
maxSharePrice,
|
|
95
|
+
recipient: userAddress,
|
|
96
|
+
requirementSignature: permit,
|
|
97
|
+
nativeAmount,
|
|
98
|
+
},
|
|
99
|
+
metadata: this.client.options.metadata,
|
|
100
|
+
});
|
|
101
|
+
},
|
|
97
102
|
};
|
|
98
103
|
}
|
|
99
104
|
withdraw({ amount, userAddress }) {
|
package/lib/esm/errors.d.ts
CHANGED
|
@@ -1,2 +1,3 @@
|
|
|
1
|
-
export
|
|
2
|
-
export {
|
|
1
|
+
export { BlueErrors, IncompleteChainRegistryError, InvalidMarketParamsError, UnknownAddressError, UnknownDataError, UnknownFactory, UnknownMarketParamsError, UnknownOfFactory, UnknownTokenError, UnknownTokenPriceError, UnknownVaultConfigError, UnsupportedChainIdError, UnsupportedPreLiquidationParamsError, UnsupportedVaultV2AdapterError, VaultV2Errors, } from "@morpho-org/blue-sdk";
|
|
2
|
+
export type { ErrorClass } from "@morpho-org/morpho-ts";
|
|
3
|
+
export { _try } from "@morpho-org/morpho-ts";
|
package/lib/esm/errors.js
CHANGED
|
@@ -1 +1,2 @@
|
|
|
1
|
-
export {
|
|
1
|
+
export { BlueErrors, IncompleteChainRegistryError, InvalidMarketParamsError, UnknownAddressError, UnknownDataError, UnknownFactory, UnknownMarketParamsError, UnknownOfFactory, UnknownTokenError, UnknownTokenPriceError, UnknownVaultConfigError, UnsupportedChainIdError, UnsupportedPreLiquidationParamsError, UnsupportedVaultV2AdapterError, VaultV2Errors, } from "@morpho-org/blue-sdk";
|
|
2
|
+
export { _try } from "@morpho-org/morpho-ts";
|
|
@@ -2,4 +2,4 @@ export { computeReallocations } from "./computeReallocations.js";
|
|
|
2
2
|
export { APPROVE_ONLY_ONCE_TOKENS, DEFAULT_LLTV_BUFFER, DEFAULT_SUPPLY_TARGET_UTILIZATION, DEFAULT_WITHDRAWAL_TARGET_UTILIZATION, MAX_ABSOLUTE_SHARE_PRICE, MAX_SLIPPAGE_TOLERANCE, MAX_TOKEN_APPROVALS, } from "./constant.js";
|
|
3
3
|
export { addTransactionMetadata } from "./metadata.js";
|
|
4
4
|
export { computeMaxRepaySharePrice, computeMaxSupplySharePrice, computeMinBorrowSharePrice, computeMinWithdrawSharePrice, } from "./slippage.js";
|
|
5
|
-
export { validateAccrualPosition, validateChainId, validateNativeAsset, validatePositionHealth, validatePositionHealthAfterWithdraw, validateReallocations, validateRepayAmount,
|
|
5
|
+
export { validateAccrualPosition, validateChainId, validateNativeAsset, validatePositionHealth, validatePositionHealthAfterWithdraw, validateReallocations, validateRepayAmount, validateRepayShares, validateSlippageTolerance, validateUserAddress, validateWithdrawAmount, validateWithdrawShares, } from "./validate.js";
|
package/lib/esm/helpers/index.js
CHANGED
|
@@ -2,4 +2,4 @@ export { computeReallocations } from "./computeReallocations.js";
|
|
|
2
2
|
export { APPROVE_ONLY_ONCE_TOKENS, DEFAULT_LLTV_BUFFER, DEFAULT_SUPPLY_TARGET_UTILIZATION, DEFAULT_WITHDRAWAL_TARGET_UTILIZATION, MAX_ABSOLUTE_SHARE_PRICE, MAX_SLIPPAGE_TOLERANCE, MAX_TOKEN_APPROVALS, } from "./constant.js";
|
|
3
3
|
export { addTransactionMetadata } from "./metadata.js";
|
|
4
4
|
export { computeMaxRepaySharePrice, computeMaxSupplySharePrice, computeMinBorrowSharePrice, computeMinWithdrawSharePrice, } from "./slippage.js";
|
|
5
|
-
export { validateAccrualPosition, validateChainId, validateNativeAsset, validatePositionHealth, validatePositionHealthAfterWithdraw, validateReallocations, validateRepayAmount,
|
|
5
|
+
export { validateAccrualPosition, validateChainId, validateNativeAsset, validatePositionHealth, validatePositionHealthAfterWithdraw, validateReallocations, validateRepayAmount, validateRepayShares, validateSlippageTolerance, validateUserAddress, validateWithdrawAmount, validateWithdrawShares, } from "./validate.js";
|
|
@@ -2,13 +2,13 @@ import { type AccrualPosition, type MarketId } from "@morpho-org/blue-sdk";
|
|
|
2
2
|
import { type Address } from "viem";
|
|
3
3
|
import { type VaultReallocation } from "../types/index.js";
|
|
4
4
|
/** @internal */
|
|
5
|
-
export declare const compareMarketIds: (idA: MarketId, idB: MarketId) =>
|
|
5
|
+
export declare const compareMarketIds: (idA: MarketId, idB: MarketId) => 1 | 0 | -1;
|
|
6
6
|
/**
|
|
7
7
|
* Asserts that the client has a connected account AND that it matches
|
|
8
8
|
* the provided user address.
|
|
9
9
|
*
|
|
10
10
|
* Used internally by the signature requirements (`encodeErc20Permit`,
|
|
11
|
-
* `
|
|
11
|
+
* `encodeErc20Permit2Approve`) to enforce builder = signer at `sign()` time:
|
|
12
12
|
* the signing flow is the only path where an account/address mismatch
|
|
13
13
|
* is a real security concern (rather than just an integrator footgun).
|
|
14
14
|
*
|
|
@@ -121,24 +121,6 @@ export declare const validateRepayShares: (params: {
|
|
|
121
121
|
repayShares: bigint;
|
|
122
122
|
marketId: MarketId;
|
|
123
123
|
}) => void;
|
|
124
|
-
/**
|
|
125
|
-
* Validates the common repay input parameters shared by `blueRepay`
|
|
126
|
-
* and `blueRepayWithdrawCollateral`.
|
|
127
|
-
*
|
|
128
|
-
* @param params - Validation parameters.
|
|
129
|
-
* @param params.assets - Repay assets amount (0n when repaying by shares).
|
|
130
|
-
* @param params.shares - Repay shares amount (0n when repaying by assets).
|
|
131
|
-
* @param params.transferAmount - ERC20 amount to transfer to GeneralAdapter1.
|
|
132
|
-
* @param params.maxSharePrice - Maximum repay share price (in ray). Must be positive.
|
|
133
|
-
* @param params.marketId - The market identifier (for error messages).
|
|
134
|
-
*/
|
|
135
|
-
export declare const validateRepayParams: (params: {
|
|
136
|
-
assets: bigint;
|
|
137
|
-
shares: bigint;
|
|
138
|
-
transferAmount: bigint;
|
|
139
|
-
maxSharePrice: bigint;
|
|
140
|
-
marketId: MarketId;
|
|
141
|
-
}) => void;
|
|
142
124
|
/**
|
|
143
125
|
* Validates that vault reallocations are well-formed.
|
|
144
126
|
*
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { getChainAddresses, MathLib, ORACLE_PRICE_SCALE, } from "@morpho-org/blue-sdk";
|
|
2
2
|
import { isDefined } from "@morpho-org/morpho-ts";
|
|
3
3
|
import { isAddressEqual } from "viem";
|
|
4
|
-
import { AccrualPositionUserMismatchError, AddressMismatchError, BorrowExceedsSafeLtvError, ChainIdMismatchError, ChainWNativeMissingError, EmptyReallocationWithdrawalsError, ExcessiveSlippageToleranceError, MarketIdMismatchError, MissingClientPropertyError, MissingMarketPriceError,
|
|
4
|
+
import { AccrualPositionUserMismatchError, AddressMismatchError, BorrowExceedsSafeLtvError, ChainIdMismatchError, ChainWNativeMissingError, EmptyReallocationWithdrawalsError, ExcessiveSlippageToleranceError, MarketIdMismatchError, MissingClientPropertyError, MissingMarketPriceError, NativeAmountOnNonWNativeAssetError, NegativeReallocationFeeError, NegativeSlippageToleranceError, NonPositiveReallocationAmountError, ReallocationWithdrawalOnTargetMarketError, RepayExceedsDebtError, RepaySharesExceedDebtError, UnsortedReallocationWithdrawalsError, WithdrawExceedsCollateralError, WithdrawExceedsSupplyError, WithdrawMakesPositionUnhealthyError, WithdrawSharesExceedSupplyError, } from "../types/index.js";
|
|
5
5
|
import { DEFAULT_LLTV_BUFFER, MAX_SLIPPAGE_TOLERANCE } from "./constant.js";
|
|
6
6
|
/** @internal */
|
|
7
7
|
export const compareMarketIds = (idA, idB) => {
|
|
@@ -18,7 +18,7 @@ export const compareMarketIds = (idA, idB) => {
|
|
|
18
18
|
* the provided user address.
|
|
19
19
|
*
|
|
20
20
|
* Used internally by the signature requirements (`encodeErc20Permit`,
|
|
21
|
-
* `
|
|
21
|
+
* `encodeErc20Permit2Approve`) to enforce builder = signer at `sign()` time:
|
|
22
22
|
* the signing flow is the only path where an account/address mismatch
|
|
23
23
|
* is a real security concern (rather than just an integrator footgun).
|
|
24
24
|
*
|
|
@@ -199,42 +199,6 @@ export const validateRepayShares = (params) => {
|
|
|
199
199
|
});
|
|
200
200
|
}
|
|
201
201
|
};
|
|
202
|
-
/**
|
|
203
|
-
* Validates the common repay input parameters shared by `blueRepay`
|
|
204
|
-
* and `blueRepayWithdrawCollateral`.
|
|
205
|
-
*
|
|
206
|
-
* @param params - Validation parameters.
|
|
207
|
-
* @param params.assets - Repay assets amount (0n when repaying by shares).
|
|
208
|
-
* @param params.shares - Repay shares amount (0n when repaying by assets).
|
|
209
|
-
* @param params.transferAmount - ERC20 amount to transfer to GeneralAdapter1.
|
|
210
|
-
* @param params.maxSharePrice - Maximum repay share price (in ray). Must be positive.
|
|
211
|
-
* @param params.marketId - The market identifier (for error messages).
|
|
212
|
-
*/
|
|
213
|
-
export const validateRepayParams = (params) => {
|
|
214
|
-
const { assets, shares, transferAmount, maxSharePrice, marketId } = params;
|
|
215
|
-
if (maxSharePrice <= 0n) {
|
|
216
|
-
throw new NonPositiveRepayMaxSharePriceError(marketId);
|
|
217
|
-
}
|
|
218
|
-
if (assets < 0n || shares < 0n) {
|
|
219
|
-
throw new NonPositiveRepayAmountError(marketId);
|
|
220
|
-
}
|
|
221
|
-
if (assets > 0n && shares > 0n) {
|
|
222
|
-
throw new MutuallyExclusiveRepayAmountsError(marketId);
|
|
223
|
-
}
|
|
224
|
-
if (assets === 0n && shares === 0n) {
|
|
225
|
-
throw new NonPositiveRepayAmountError(marketId);
|
|
226
|
-
}
|
|
227
|
-
if (transferAmount <= 0n) {
|
|
228
|
-
throw new NonPositiveTransferAmountError(marketId);
|
|
229
|
-
}
|
|
230
|
-
if (assets > 0n && transferAmount !== assets) {
|
|
231
|
-
throw new TransferAmountNotEqualToAssetsError({
|
|
232
|
-
transferAmount,
|
|
233
|
-
assets,
|
|
234
|
-
market: marketId,
|
|
235
|
-
});
|
|
236
|
-
}
|
|
237
|
-
};
|
|
238
202
|
/**
|
|
239
203
|
* Validates that vault reallocations are well-formed.
|
|
240
204
|
*
|