@morpho-org/morpho-sdk 1.1.0 → 1.2.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/LICENSE +2 -2
- package/README.md +31 -33
- package/lib/cjs/actions/index.d.ts +4 -0
- package/lib/{actions → cjs/actions}/index.js +4 -4
- package/lib/cjs/actions/marketV1/borrow.d.ts +69 -0
- package/lib/cjs/actions/marketV1/borrow.js +97 -0
- package/lib/cjs/actions/marketV1/buildReallocationActions.d.ts +28 -0
- package/lib/cjs/actions/marketV1/buildReallocationActions.js +47 -0
- package/lib/cjs/actions/marketV1/index.d.ts +6 -0
- package/lib/{actions → cjs/actions}/marketV1/index.js +6 -6
- package/lib/cjs/actions/marketV1/repay.d.ts +89 -0
- package/lib/cjs/actions/marketV1/repay.js +134 -0
- package/lib/cjs/actions/marketV1/repayWithdrawCollateral.d.ts +103 -0
- package/lib/cjs/actions/marketV1/repayWithdrawCollateral.js +155 -0
- package/lib/cjs/actions/marketV1/supplyCollateral.d.ts +59 -0
- package/lib/cjs/actions/marketV1/supplyCollateral.js +116 -0
- package/lib/cjs/actions/marketV1/supplyCollateralBorrow.d.ts +91 -0
- package/lib/cjs/actions/marketV1/supplyCollateralBorrow.js +163 -0
- package/lib/cjs/actions/marketV1/withdrawCollateral.d.ts +49 -0
- package/lib/cjs/actions/marketV1/withdrawCollateral.js +72 -0
- package/lib/cjs/actions/requirements/encode/encodeErc20Approval.d.ts +36 -0
- package/lib/{actions → cjs/actions}/requirements/encode/encodeErc20Approval.js +25 -0
- package/lib/cjs/actions/requirements/encode/encodeErc20Permit.d.ts +52 -0
- package/lib/cjs/actions/requirements/encode/encodeErc20Permit.js +108 -0
- package/lib/cjs/actions/requirements/encode/encodeErc20Permit2.d.ts +44 -0
- package/lib/{actions → cjs/actions}/requirements/encode/encodeErc20Permit2.js +36 -4
- package/lib/cjs/actions/requirements/encode/index.d.ts +3 -0
- package/lib/{actions → cjs/actions}/requirements/encode/index.js +3 -3
- package/lib/cjs/actions/requirements/getMorphoAuthorizationRequirement.d.ts +37 -0
- package/lib/cjs/actions/requirements/getMorphoAuthorizationRequirement.js +71 -0
- package/lib/cjs/actions/requirements/getRequirements.d.ts +74 -0
- package/lib/cjs/actions/requirements/getRequirements.js +112 -0
- package/lib/cjs/actions/requirements/getRequirementsAction.d.ts +33 -0
- package/lib/{actions → cjs/actions}/requirements/getRequirementsAction.js +20 -4
- package/lib/cjs/actions/requirements/getRequirementsApproval.d.ts +43 -0
- package/lib/cjs/actions/requirements/getRequirementsApproval.js +63 -0
- package/lib/cjs/actions/requirements/getRequirementsPermit.d.ts +45 -0
- package/lib/cjs/actions/requirements/getRequirementsPermit.js +57 -0
- package/lib/cjs/actions/requirements/getRequirementsPermit2.d.ts +63 -0
- package/lib/cjs/actions/requirements/getRequirementsPermit2.js +85 -0
- package/lib/cjs/actions/requirements/index.d.ts +6 -0
- package/lib/{actions → cjs/actions}/requirements/index.js +6 -6
- package/lib/cjs/actions/vaultV1/deposit.d.ts +72 -0
- package/lib/cjs/actions/vaultV1/deposit.js +146 -0
- package/lib/cjs/actions/vaultV1/index.d.ts +4 -0
- package/lib/{actions → cjs/actions}/vaultV1/index.js +4 -4
- package/lib/cjs/actions/vaultV1/migrateToV2.d.ts +84 -0
- package/lib/cjs/actions/vaultV1/migrateToV2.js +143 -0
- package/lib/cjs/actions/vaultV1/redeem.d.ts +39 -0
- package/lib/cjs/actions/vaultV1/redeem.js +57 -0
- package/lib/cjs/actions/vaultV1/withdraw.d.ts +39 -0
- package/lib/cjs/actions/vaultV1/withdraw.js +57 -0
- package/lib/cjs/actions/vaultV2/deposit.d.ts +72 -0
- package/lib/cjs/actions/vaultV2/deposit.js +146 -0
- package/lib/cjs/actions/vaultV2/forceRedeem.d.ts +63 -0
- package/lib/cjs/actions/vaultV2/forceRedeem.js +99 -0
- package/lib/cjs/actions/vaultV2/forceWithdraw.d.ts +58 -0
- package/lib/cjs/actions/vaultV2/forceWithdraw.js +94 -0
- package/lib/cjs/actions/vaultV2/index.d.ts +5 -0
- package/lib/{actions → cjs/actions}/vaultV2/index.js +5 -5
- package/lib/cjs/actions/vaultV2/redeem.d.ts +40 -0
- package/lib/cjs/actions/vaultV2/redeem.js +58 -0
- package/lib/cjs/actions/vaultV2/withdraw.d.ts +40 -0
- package/lib/cjs/actions/vaultV2/withdraw.js +58 -0
- package/lib/cjs/client/index.d.ts +2 -0
- package/lib/{client → cjs/client}/index.js +2 -2
- package/lib/cjs/client/morphoClient.d.ts +113 -0
- package/lib/cjs/client/morphoClient.js +123 -0
- package/lib/cjs/client/morphoViemExtension.d.ts +45 -0
- package/lib/cjs/client/morphoViemExtension.js +46 -0
- package/lib/cjs/entities/index.d.ts +3 -0
- package/lib/{entities → cjs/entities}/index.js +3 -3
- package/lib/cjs/entities/marketV1/index.d.ts +1 -0
- package/lib/{entities/vaultV1 → cjs/entities/marketV1}/index.js +1 -1
- package/lib/{entities → cjs/entities}/marketV1/marketV1.d.ts +9 -6
- package/lib/{entities → cjs/entities}/marketV1/marketV1.js +89 -87
- package/lib/cjs/entities/vaultV1/index.d.ts +1 -0
- package/lib/{entities/marketV1 → cjs/entities/vaultV1}/index.js +1 -1
- package/lib/{entities → cjs/entities}/vaultV1/vaultV1.d.ts +4 -8
- package/lib/{entities → cjs/entities}/vaultV1/vaultV1.js +39 -35
- package/lib/cjs/entities/vaultV2/index.d.ts +1 -0
- package/lib/{entities → cjs/entities}/vaultV2/index.js +1 -1
- package/lib/{entities → cjs/entities}/vaultV2/vaultV2.d.ts +2 -2
- package/lib/{entities → cjs/entities}/vaultV2/vaultV2.js +25 -24
- package/lib/{helpers → cjs/helpers}/computeReallocations.d.ts +1 -1
- package/lib/{helpers → cjs/helpers}/computeReallocations.js +2 -2
- package/lib/{helpers → cjs/helpers}/encodeDeallocation.d.ts +1 -1
- package/lib/{helpers → cjs/helpers}/encodeDeallocation.js +2 -2
- package/lib/{helpers → cjs/helpers}/index.d.ts +4 -4
- package/lib/{helpers → cjs/helpers}/index.js +19 -19
- package/lib/{helpers → cjs/helpers}/metadata.d.ts +1 -1
- package/lib/{helpers → cjs/helpers}/slippage.js +7 -7
- package/lib/{helpers → cjs/helpers}/validate.d.ts +1 -1
- package/lib/{helpers → cjs/helpers}/validate.js +33 -33
- package/lib/cjs/index.d.ts +5 -0
- package/lib/cjs/index.js +21 -0
- package/lib/cjs/package.json +1 -0
- package/lib/{types → cjs/types}/action.d.ts +1 -1
- package/lib/{types → cjs/types}/client.d.ts +6 -2
- package/lib/{types → cjs/types}/error.d.ts +46 -0
- package/lib/{types → cjs/types}/error.js +46 -0
- package/lib/cjs/types/index.d.ts +7 -0
- package/lib/cjs/types/index.js +23 -0
- package/lib/esm/actions/index.d.ts +4 -0
- package/lib/esm/actions/index.js +4 -0
- package/lib/esm/actions/marketV1/borrow.d.ts +69 -0
- package/lib/esm/actions/marketV1/borrow.js +93 -0
- package/lib/esm/actions/marketV1/buildReallocationActions.d.ts +28 -0
- package/lib/esm/actions/marketV1/buildReallocationActions.js +43 -0
- package/lib/esm/actions/marketV1/index.d.ts +6 -0
- package/lib/esm/actions/marketV1/index.js +6 -0
- package/lib/esm/actions/marketV1/repay.d.ts +89 -0
- package/lib/esm/actions/marketV1/repay.js +130 -0
- package/lib/esm/actions/marketV1/repayWithdrawCollateral.d.ts +103 -0
- package/lib/esm/actions/marketV1/repayWithdrawCollateral.js +151 -0
- package/lib/esm/actions/marketV1/supplyCollateral.d.ts +59 -0
- package/lib/esm/actions/marketV1/supplyCollateral.js +112 -0
- package/lib/esm/actions/marketV1/supplyCollateralBorrow.d.ts +91 -0
- package/lib/esm/actions/marketV1/supplyCollateralBorrow.js +159 -0
- package/lib/esm/actions/marketV1/withdrawCollateral.d.ts +49 -0
- package/lib/esm/actions/marketV1/withdrawCollateral.js +68 -0
- package/lib/esm/actions/requirements/encode/encodeErc20Approval.d.ts +36 -0
- package/lib/esm/actions/requirements/encode/encodeErc20Approval.js +46 -0
- package/lib/esm/actions/requirements/encode/encodeErc20Permit.d.ts +52 -0
- package/lib/esm/actions/requirements/encode/encodeErc20Permit.js +104 -0
- package/lib/esm/actions/requirements/encode/encodeErc20Permit2.d.ts +44 -0
- package/lib/esm/actions/requirements/encode/encodeErc20Permit2.js +98 -0
- package/lib/esm/actions/requirements/encode/index.d.ts +3 -0
- package/lib/esm/actions/requirements/encode/index.js +3 -0
- package/lib/esm/actions/requirements/getMorphoAuthorizationRequirement.d.ts +37 -0
- package/lib/esm/actions/requirements/getMorphoAuthorizationRequirement.js +67 -0
- package/lib/esm/actions/requirements/getRequirements.d.ts +74 -0
- package/lib/esm/actions/requirements/getRequirements.js +108 -0
- package/lib/esm/actions/requirements/getRequirementsAction.d.ts +33 -0
- package/lib/esm/actions/requirements/getRequirementsAction.js +76 -0
- package/lib/esm/actions/requirements/getRequirementsApproval.d.ts +43 -0
- package/lib/esm/actions/requirements/getRequirementsApproval.js +59 -0
- package/lib/esm/actions/requirements/getRequirementsPermit.d.ts +45 -0
- package/lib/esm/actions/requirements/getRequirementsPermit.js +53 -0
- package/lib/esm/actions/requirements/getRequirementsPermit2.d.ts +63 -0
- package/lib/esm/actions/requirements/getRequirementsPermit2.js +81 -0
- package/lib/esm/actions/requirements/index.d.ts +6 -0
- package/lib/esm/actions/requirements/index.js +6 -0
- package/lib/esm/actions/vaultV1/deposit.d.ts +72 -0
- package/lib/esm/actions/vaultV1/deposit.js +142 -0
- package/lib/esm/actions/vaultV1/index.d.ts +4 -0
- package/lib/esm/actions/vaultV1/index.js +4 -0
- package/lib/esm/actions/vaultV1/migrateToV2.d.ts +84 -0
- package/lib/esm/actions/vaultV1/migrateToV2.js +139 -0
- package/lib/esm/actions/vaultV1/redeem.d.ts +39 -0
- package/lib/esm/actions/vaultV1/redeem.js +53 -0
- package/lib/esm/actions/vaultV1/withdraw.d.ts +39 -0
- package/lib/esm/actions/vaultV1/withdraw.js +53 -0
- package/lib/esm/actions/vaultV2/deposit.d.ts +72 -0
- package/lib/esm/actions/vaultV2/deposit.js +142 -0
- package/lib/esm/actions/vaultV2/forceRedeem.d.ts +63 -0
- package/lib/esm/actions/vaultV2/forceRedeem.js +95 -0
- package/lib/esm/actions/vaultV2/forceWithdraw.d.ts +58 -0
- package/lib/esm/actions/vaultV2/forceWithdraw.js +90 -0
- package/lib/esm/actions/vaultV2/index.d.ts +5 -0
- package/lib/esm/actions/vaultV2/index.js +5 -0
- package/lib/esm/actions/vaultV2/redeem.d.ts +40 -0
- package/lib/esm/actions/vaultV2/redeem.js +54 -0
- package/lib/esm/actions/vaultV2/withdraw.d.ts +40 -0
- package/lib/esm/actions/vaultV2/withdraw.js +54 -0
- package/lib/esm/client/index.d.ts +2 -0
- package/lib/esm/client/index.js +2 -0
- package/lib/esm/client/morphoClient.d.ts +113 -0
- package/lib/esm/client/morphoClient.js +119 -0
- package/lib/esm/client/morphoViemExtension.d.ts +45 -0
- package/lib/esm/client/morphoViemExtension.js +43 -0
- package/lib/esm/entities/index.d.ts +3 -0
- package/lib/esm/entities/index.js +3 -0
- package/lib/esm/entities/marketV1/index.d.ts +1 -0
- package/lib/esm/entities/marketV1/index.js +1 -0
- package/lib/esm/entities/marketV1/marketV1.d.ts +293 -0
- package/lib/esm/entities/marketV1/marketV1.js +529 -0
- package/lib/esm/entities/vaultV1/index.d.ts +1 -0
- package/lib/esm/entities/vaultV1/index.js +1 -0
- package/lib/esm/entities/vaultV1/vaultV1.d.ts +129 -0
- package/lib/esm/entities/vaultV1/vaultV1.js +186 -0
- package/lib/esm/entities/vaultV2/index.d.ts +1 -0
- package/lib/esm/entities/vaultV2/index.js +1 -0
- package/lib/esm/entities/vaultV2/vaultV2.d.ts +180 -0
- package/lib/esm/entities/vaultV2/vaultV2.js +164 -0
- package/lib/esm/helpers/computeReallocations.d.ts +23 -0
- package/lib/esm/helpers/computeReallocations.js +94 -0
- package/lib/esm/helpers/constant.d.ts +6 -0
- package/lib/esm/helpers/constant.js +7 -0
- package/lib/esm/helpers/encodeDeallocation.d.ts +10 -0
- package/lib/esm/helpers/encodeDeallocation.js +34 -0
- package/lib/esm/helpers/index.d.ts +4 -0
- package/lib/esm/helpers/index.js +4 -0
- package/lib/esm/helpers/metadata.d.ts +33 -0
- package/lib/esm/helpers/metadata.js +46 -0
- package/lib/esm/helpers/slippage.d.ts +46 -0
- package/lib/esm/helpers/slippage.js +69 -0
- package/lib/esm/helpers/validate.d.ts +156 -0
- package/lib/esm/helpers/validate.js +273 -0
- package/lib/esm/index.d.ts +5 -0
- package/lib/esm/index.js +5 -0
- package/lib/esm/package.json +1 -0
- package/lib/esm/types/action.d.ts +216 -0
- package/lib/esm/types/action.js +21 -0
- package/lib/esm/types/client.d.ts +19 -0
- package/lib/esm/types/client.js +1 -0
- package/lib/esm/types/data.d.ts +2 -0
- package/lib/esm/types/data.js +1 -0
- package/lib/esm/types/deallocation.d.ts +15 -0
- package/lib/esm/types/deallocation.js +1 -0
- package/lib/esm/types/entity.d.ts +5 -0
- package/lib/esm/types/entity.js +1 -0
- package/lib/esm/types/error.d.ts +205 -0
- package/lib/esm/types/error.js +276 -0
- package/lib/esm/types/index.d.ts +7 -0
- package/lib/esm/types/index.js +7 -0
- package/lib/esm/types/metadata.d.ts +4 -0
- package/lib/esm/types/metadata.js +1 -0
- package/lib/esm/types/sharedLiquidity.d.ts +41 -0
- package/lib/esm/types/sharedLiquidity.js +1 -0
- package/package.json +29 -54
- package/src/index.ts +5 -0
- package/lib/actions/index.d.ts +0 -4
- package/lib/actions/marketV1/borrow.d.ts +0 -34
- package/lib/actions/marketV1/borrow.js +0 -62
- package/lib/actions/marketV1/buildReallocationActions.d.ts +0 -17
- package/lib/actions/marketV1/buildReallocationActions.js +0 -36
- package/lib/actions/marketV1/index.d.ts +0 -6
- package/lib/actions/marketV1/repay.d.ts +0 -44
- package/lib/actions/marketV1/repay.js +0 -93
- package/lib/actions/marketV1/repayWithdrawCollateral.d.ts +0 -51
- package/lib/actions/marketV1/repayWithdrawCollateral.js +0 -108
- package/lib/actions/marketV1/supplyCollateral.d.ts +0 -28
- package/lib/actions/marketV1/supplyCollateral.js +0 -85
- package/lib/actions/marketV1/supplyCollateralBorrow.d.ts +0 -37
- package/lib/actions/marketV1/supplyCollateralBorrow.js +0 -109
- package/lib/actions/marketV1/withdrawCollateral.d.ts +0 -28
- package/lib/actions/marketV1/withdrawCollateral.js +0 -51
- package/lib/actions/requirements/encode/encodeErc20Approval.d.ts +0 -10
- package/lib/actions/requirements/encode/encodeErc20Permit.d.ts +0 -13
- package/lib/actions/requirements/encode/encodeErc20Permit.js +0 -70
- package/lib/actions/requirements/encode/encodeErc20Permit2.d.ts +0 -11
- package/lib/actions/requirements/encode/index.d.ts +0 -3
- package/lib/actions/requirements/getMorphoAuthorizationRequirement.d.ts +0 -21
- package/lib/actions/requirements/getMorphoAuthorizationRequirement.js +0 -55
- package/lib/actions/requirements/getRequirements.d.ts +0 -42
- package/lib/actions/requirements/getRequirements.js +0 -80
- package/lib/actions/requirements/getRequirementsAction.d.ts +0 -17
- package/lib/actions/requirements/getRequirementsApproval.d.ts +0 -31
- package/lib/actions/requirements/getRequirementsApproval.js +0 -51
- package/lib/actions/requirements/getRequirementsPermit.d.ts +0 -28
- package/lib/actions/requirements/getRequirementsPermit.js +0 -40
- package/lib/actions/requirements/getRequirementsPermit2.d.ts +0 -37
- package/lib/actions/requirements/getRequirementsPermit2.js +0 -59
- package/lib/actions/requirements/index.d.ts +0 -6
- package/lib/actions/vaultV1/deposit.d.ts +0 -41
- package/lib/actions/vaultV1/deposit.js +0 -116
- package/lib/actions/vaultV1/index.d.ts +0 -4
- package/lib/actions/vaultV1/migrateToV2.d.ts +0 -50
- package/lib/actions/vaultV1/migrateToV2.js +0 -108
- package/lib/actions/vaultV1/redeem.d.ts +0 -29
- package/lib/actions/vaultV1/redeem.js +0 -48
- package/lib/actions/vaultV1/withdraw.d.ts +0 -29
- package/lib/actions/vaultV1/withdraw.js +0 -48
- package/lib/actions/vaultV2/deposit.d.ts +0 -41
- package/lib/actions/vaultV2/deposit.js +0 -116
- package/lib/actions/vaultV2/forceRedeem.d.ts +0 -48
- package/lib/actions/vaultV2/forceRedeem.js +0 -85
- package/lib/actions/vaultV2/forceWithdraw.d.ts +0 -40
- package/lib/actions/vaultV2/forceWithdraw.js +0 -77
- package/lib/actions/vaultV2/index.d.ts +0 -5
- package/lib/actions/vaultV2/redeem.d.ts +0 -32
- package/lib/actions/vaultV2/redeem.js +0 -51
- package/lib/actions/vaultV2/withdraw.d.ts +0 -32
- package/lib/actions/vaultV2/withdraw.js +0 -51
- package/lib/client/index.d.ts +0 -2
- package/lib/client/morphoClient.d.ts +0 -25
- package/lib/client/morphoClient.js +0 -28
- package/lib/client/morphoViemExtension.d.ts +0 -39
- package/lib/client/morphoViemExtension.js +0 -40
- package/lib/entities/index.d.ts +0 -3
- package/lib/entities/marketV1/index.d.ts +0 -1
- package/lib/entities/vaultV1/index.d.ts +0 -1
- package/lib/entities/vaultV2/index.d.ts +0 -1
- package/lib/index.d.ts +0 -5
- package/lib/index.js +0 -21
- package/lib/types/index.d.ts +0 -7
- package/lib/types/index.js +0 -23
- /package/lib/{helpers → cjs/helpers}/constant.d.ts +0 -0
- /package/lib/{helpers → cjs/helpers}/constant.js +0 -0
- /package/lib/{helpers → cjs/helpers}/metadata.js +0 -0
- /package/lib/{helpers → cjs/helpers}/slippage.d.ts +0 -0
- /package/lib/{types → cjs/types}/action.js +0 -0
- /package/lib/{types → cjs/types}/client.js +0 -0
- /package/lib/{types → cjs/types}/data.d.ts +0 -0
- /package/lib/{types → cjs/types}/data.js +0 -0
- /package/lib/{types → cjs/types}/deallocation.d.ts +0 -0
- /package/lib/{types → cjs/types}/deallocation.js +0 -0
- /package/lib/{types → cjs/types}/entity.d.ts +0 -0
- /package/lib/{types → cjs/types}/entity.js +0 -0
- /package/lib/{types → cjs/types}/metadata.d.ts +0 -0
- /package/lib/{types → cjs/types}/metadata.js +0 -0
- /package/lib/{types → cjs/types}/sharedLiquidity.d.ts +0 -0
- /package/lib/{types → cjs/types}/sharedLiquidity.js +0 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./marketV1.js";
|
|
@@ -14,4 +14,4 @@ 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
|
-
__exportStar(require("./
|
|
17
|
+
__exportStar(require("./marketV1.js"), exports);
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { type AccrualPosition, type Market, type MarketParams } from "@morpho-org/blue-sdk";
|
|
2
2
|
import { type MinimalBlock, SimulationState } from "@morpho-org/simulation-sdk";
|
|
3
3
|
import type { Address } from "viem";
|
|
4
|
-
import
|
|
5
|
-
import type
|
|
4
|
+
import type { FetchParameters } from "../../types/data.js";
|
|
5
|
+
import { type DepositAmountArgs, type ERC20ApprovalAction, type MarketV1BorrowAction, type MarketV1RepayAction, type MarketV1RepayWithdrawCollateralAction, type MarketV1SupplyCollateralAction, type MarketV1SupplyCollateralBorrowAction, type MarketV1WithdrawCollateralAction, type MorphoAuthorizationAction, type MorphoClientType, type ReallocationComputeOptions, type RepayAmountArgs, type Requirement, type RequirementSignature, type Transaction, type VaultReallocation } from "../../types/index.js";
|
|
6
6
|
export interface MarketV1Actions {
|
|
7
7
|
/**
|
|
8
8
|
* Fetches the latest market data with accrued interest.
|
|
@@ -176,6 +176,12 @@ export interface MarketV1Actions {
|
|
|
176
176
|
* Fetches all on-chain data needed to construct a {@link SimulationState}
|
|
177
177
|
* for computing vault reallocations via the public allocator.
|
|
178
178
|
*
|
|
179
|
+
* The target market is refetched internally at `block.number` so the
|
|
180
|
+
* reallocation planner always sees a snapshot from the same block as the
|
|
181
|
+
* source vaults. A caller-owned market would let stale or adversarial data
|
|
182
|
+
* inject unnecessary `reallocateTo` actions (and their PublicAllocator
|
|
183
|
+
* fees) into the resulting bundle.
|
|
184
|
+
*
|
|
179
185
|
* The returned simulation state can be passed to {@link getReallocations}
|
|
180
186
|
* to compute the `VaultReallocation[]` array for `borrow()` or
|
|
181
187
|
* `supplyCollateralBorrow()`.
|
|
@@ -183,13 +189,11 @@ export interface MarketV1Actions {
|
|
|
183
189
|
* **Stale data reverts on-chain (fail-safe).**
|
|
184
190
|
*
|
|
185
191
|
* @param params.vaultAddresses - Addresses of MetaMorpho vaults that allocate to this market.
|
|
186
|
-
* @param params.market - The target market data (from {@link getPositionData} or {@link getMarketData}).
|
|
187
192
|
* @param params.block - The block to fetch data at (number and timestamp).
|
|
188
193
|
* @returns A SimulationState populated with all required data.
|
|
189
194
|
*/
|
|
190
195
|
getReallocationData: (params: {
|
|
191
196
|
vaultAddresses: readonly Address[];
|
|
192
|
-
market: Market;
|
|
193
197
|
block: MinimalBlock;
|
|
194
198
|
}) => Promise<SimulationState>;
|
|
195
199
|
/**
|
|
@@ -277,9 +281,8 @@ export declare class MorphoMarketV1 implements MarketV1Actions {
|
|
|
277
281
|
}) => Promise<(Requirement | Readonly<Transaction<ERC20ApprovalAction>> | Readonly<Transaction<MorphoAuthorizationAction>>)[]>;
|
|
278
282
|
buildTx: (requirementSignature?: RequirementSignature) => Readonly<Transaction<MarketV1SupplyCollateralBorrowAction>>;
|
|
279
283
|
};
|
|
280
|
-
getReallocationData({ vaultAddresses,
|
|
284
|
+
getReallocationData({ vaultAddresses, block, }: {
|
|
281
285
|
vaultAddresses: readonly Address[];
|
|
282
|
-
market: Market;
|
|
283
286
|
block: MinimalBlock;
|
|
284
287
|
}): Promise<SimulationState>;
|
|
285
288
|
getReallocations({ reallocationData, borrowAmount, options, }: {
|
|
@@ -5,20 +5,21 @@ const blue_sdk_1 = require("@morpho-org/blue-sdk");
|
|
|
5
5
|
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 simulation_sdk_1 = require("@morpho-org/simulation-sdk");
|
|
8
|
-
const
|
|
9
|
-
const
|
|
10
|
-
const
|
|
8
|
+
const index_js_1 = require("../../actions/index.js");
|
|
9
|
+
const index_js_2 = require("../../helpers/index.js");
|
|
10
|
+
const index_js_3 = require("../../types/index.js");
|
|
11
11
|
class MorphoMarketV1 {
|
|
12
12
|
client;
|
|
13
13
|
marketParams;
|
|
14
14
|
chainId;
|
|
15
|
+
// biome-ignore lint/complexity/useMaxParams: TODO refactor to ≤2 params
|
|
15
16
|
constructor(client, marketParams, chainId) {
|
|
16
17
|
this.client = client;
|
|
17
18
|
this.marketParams = marketParams;
|
|
18
19
|
this.chainId = chainId;
|
|
19
20
|
}
|
|
20
21
|
async getMarketData(parameters) {
|
|
21
|
-
(0,
|
|
22
|
+
(0, index_js_2.validateChainId)(this.client.viemClient.chain?.id, this.chainId);
|
|
22
23
|
return (0, blue_sdk_viem_1.fetchMarket)(this.marketParams.id, this.client.viemClient, {
|
|
23
24
|
...parameters,
|
|
24
25
|
chainId: this.chainId,
|
|
@@ -26,7 +27,7 @@ class MorphoMarketV1 {
|
|
|
26
27
|
});
|
|
27
28
|
}
|
|
28
29
|
async getPositionData(userAddress, parameters) {
|
|
29
|
-
(0,
|
|
30
|
+
(0, index_js_2.validateChainId)(this.client.viemClient.chain?.id, this.chainId);
|
|
30
31
|
return (0, blue_sdk_viem_1.fetchAccrualPosition)(userAddress, this.marketParams.id, this.client.viemClient, {
|
|
31
32
|
...parameters,
|
|
32
33
|
deployless: this.client.options.supportDeployless,
|
|
@@ -34,23 +35,23 @@ class MorphoMarketV1 {
|
|
|
34
35
|
});
|
|
35
36
|
}
|
|
36
37
|
supplyCollateral({ amount = 0n, userAddress, nativeAmount, }) {
|
|
37
|
-
(0,
|
|
38
|
-
(0,
|
|
38
|
+
(0, index_js_2.validateChainId)(this.client.viemClient.chain?.id, this.chainId);
|
|
39
|
+
(0, index_js_2.validateUserAddress)(this.client.viemClient.account?.address, userAddress);
|
|
39
40
|
if (amount < 0n) {
|
|
40
|
-
throw new
|
|
41
|
+
throw new index_js_3.NonPositiveAssetAmountError(this.marketParams.collateralToken);
|
|
41
42
|
}
|
|
42
43
|
if (nativeAmount !== undefined && nativeAmount < 0n) {
|
|
43
|
-
throw new
|
|
44
|
+
throw new index_js_3.NegativeNativeAmountError(nativeAmount);
|
|
44
45
|
}
|
|
45
46
|
const totalCollateral = amount + (nativeAmount ?? 0n);
|
|
46
47
|
if (totalCollateral === 0n) {
|
|
47
|
-
throw new
|
|
48
|
+
throw new index_js_3.ZeroCollateralAmountError(this.marketParams.id);
|
|
48
49
|
}
|
|
49
50
|
if (nativeAmount !== undefined && nativeAmount > 0n) {
|
|
50
|
-
(0,
|
|
51
|
+
(0, index_js_2.validateNativeCollateral)(this.chainId, this.marketParams.collateralToken);
|
|
51
52
|
}
|
|
52
53
|
return {
|
|
53
|
-
getRequirements: (params) => (0,
|
|
54
|
+
getRequirements: (params) => (0, index_js_1.getRequirements)(this.client.viemClient, {
|
|
54
55
|
address: this.marketParams.collateralToken,
|
|
55
56
|
chainId: this.chainId,
|
|
56
57
|
supportSignature: this.client.options.supportSignature,
|
|
@@ -58,7 +59,7 @@ class MorphoMarketV1 {
|
|
|
58
59
|
useSimplePermit: params?.useSimplePermit,
|
|
59
60
|
args: { amount, from: userAddress },
|
|
60
61
|
}),
|
|
61
|
-
buildTx: (requirementSignature) => (0,
|
|
62
|
+
buildTx: (requirementSignature) => (0, index_js_1.marketV1SupplyCollateral)({
|
|
62
63
|
market: {
|
|
63
64
|
chainId: this.chainId,
|
|
64
65
|
marketParams: this.marketParams,
|
|
@@ -74,42 +75,42 @@ class MorphoMarketV1 {
|
|
|
74
75
|
};
|
|
75
76
|
}
|
|
76
77
|
borrow({ amount, userAddress, positionData, slippageTolerance = blue_sdk_1.DEFAULT_SLIPPAGE_TOLERANCE, reallocations, }) {
|
|
77
|
-
(0,
|
|
78
|
-
(0,
|
|
78
|
+
(0, index_js_2.validateChainId)(this.client.viemClient.chain?.id, this.chainId);
|
|
79
|
+
(0, index_js_2.validateUserAddress)(this.client.viemClient.account?.address, userAddress);
|
|
79
80
|
if (amount <= 0n) {
|
|
80
|
-
throw new
|
|
81
|
+
throw new index_js_3.NonPositiveBorrowAmountError(this.marketParams.id);
|
|
81
82
|
}
|
|
82
|
-
(0,
|
|
83
|
+
(0, index_js_2.validateSlippageTolerance)(slippageTolerance);
|
|
83
84
|
if (!positionData) {
|
|
84
|
-
throw new
|
|
85
|
+
throw new index_js_3.MissingAccrualPositionError(this.marketParams.id);
|
|
85
86
|
}
|
|
86
|
-
(0,
|
|
87
|
+
(0, index_js_2.validateAccrualPosition)({
|
|
87
88
|
positionData,
|
|
88
89
|
expectedMarketId: this.marketParams.id,
|
|
89
90
|
expectedUser: userAddress,
|
|
90
91
|
});
|
|
91
|
-
(0,
|
|
92
|
+
(0, index_js_2.validatePositionHealth)({
|
|
92
93
|
positionData,
|
|
93
94
|
additionalCollateral: 0n,
|
|
94
95
|
borrowAmount: amount,
|
|
95
96
|
marketId: this.marketParams.id,
|
|
96
97
|
lltv: this.marketParams.lltv,
|
|
97
98
|
});
|
|
98
|
-
const minSharePrice = (0,
|
|
99
|
+
const minSharePrice = (0, index_js_2.computeMinBorrowSharePrice)({
|
|
99
100
|
borrowAmount: amount,
|
|
100
101
|
market: positionData.market,
|
|
101
102
|
slippageTolerance,
|
|
102
103
|
});
|
|
103
104
|
return {
|
|
104
105
|
getRequirements: async () => {
|
|
105
|
-
const authTx = await (0,
|
|
106
|
+
const authTx = await (0, index_js_1.getMorphoAuthorizationRequirement)({
|
|
106
107
|
viemClient: this.client.viemClient,
|
|
107
108
|
chainId: this.chainId,
|
|
108
109
|
userAddress,
|
|
109
110
|
});
|
|
110
111
|
return authTx ? [authTx] : [];
|
|
111
112
|
},
|
|
112
|
-
buildTx: () => (0,
|
|
113
|
+
buildTx: () => (0, index_js_1.marketV1Borrow)({
|
|
113
114
|
market: {
|
|
114
115
|
chainId: this.chainId,
|
|
115
116
|
marketParams: this.marketParams,
|
|
@@ -125,28 +126,28 @@ class MorphoMarketV1 {
|
|
|
125
126
|
};
|
|
126
127
|
}
|
|
127
128
|
repay(params) {
|
|
128
|
-
(0,
|
|
129
|
-
(0,
|
|
129
|
+
(0, index_js_2.validateChainId)(this.client.viemClient.chain?.id, this.chainId);
|
|
130
|
+
(0, index_js_2.validateUserAddress)(this.client.viemClient.account?.address, params.userAddress);
|
|
130
131
|
const { userAddress, positionData, slippageTolerance = blue_sdk_1.DEFAULT_SLIPPAGE_TOLERANCE, } = params;
|
|
131
132
|
if ("assets" in params && "shares" in params) {
|
|
132
|
-
throw new
|
|
133
|
+
throw new index_js_3.MutuallyExclusiveRepayAmountsError(this.marketParams.id);
|
|
133
134
|
}
|
|
134
135
|
const isSharesMode = "shares" in params;
|
|
135
136
|
if (isSharesMode) {
|
|
136
137
|
if (params.shares <= 0n) {
|
|
137
|
-
throw new
|
|
138
|
+
throw new index_js_3.NonPositiveRepayAmountError(this.marketParams.id);
|
|
138
139
|
}
|
|
139
140
|
}
|
|
140
141
|
else {
|
|
141
142
|
if (params.assets <= 0n) {
|
|
142
|
-
throw new
|
|
143
|
+
throw new index_js_3.NonPositiveRepayAmountError(this.marketParams.id);
|
|
143
144
|
}
|
|
144
145
|
}
|
|
145
|
-
(0,
|
|
146
|
+
(0, index_js_2.validateSlippageTolerance)(slippageTolerance);
|
|
146
147
|
if (!positionData) {
|
|
147
|
-
throw new
|
|
148
|
+
throw new index_js_3.MissingAccrualPositionError(this.marketParams.id);
|
|
148
149
|
}
|
|
149
|
-
(0,
|
|
150
|
+
(0, index_js_2.validateAccrualPosition)({
|
|
150
151
|
positionData,
|
|
151
152
|
expectedMarketId: this.marketParams.id,
|
|
152
153
|
expectedUser: userAddress,
|
|
@@ -155,7 +156,7 @@ class MorphoMarketV1 {
|
|
|
155
156
|
let shares;
|
|
156
157
|
let transferAmount;
|
|
157
158
|
if (isSharesMode) {
|
|
158
|
-
(0,
|
|
159
|
+
(0, index_js_2.validateRepayShares)({
|
|
159
160
|
positionData,
|
|
160
161
|
repayShares: params.shares,
|
|
161
162
|
marketId: this.marketParams.id,
|
|
@@ -168,7 +169,7 @@ class MorphoMarketV1 {
|
|
|
168
169
|
transferAmount = blue_sdk_1.MathLib.wMulUp(baseTransferAmount, blue_sdk_1.MathLib.WAD + slippageTolerance);
|
|
169
170
|
}
|
|
170
171
|
else {
|
|
171
|
-
(0,
|
|
172
|
+
(0, index_js_2.validateRepayAmount)({
|
|
172
173
|
positionData,
|
|
173
174
|
repayAssets: params.assets,
|
|
174
175
|
marketId: this.marketParams.id,
|
|
@@ -177,14 +178,14 @@ class MorphoMarketV1 {
|
|
|
177
178
|
shares = 0n;
|
|
178
179
|
transferAmount = params.assets;
|
|
179
180
|
}
|
|
180
|
-
const maxSharePrice = (0,
|
|
181
|
+
const maxSharePrice = (0, index_js_2.computeMaxRepaySharePrice)({
|
|
181
182
|
repayAssets: assets,
|
|
182
183
|
repayShares: shares,
|
|
183
184
|
market: positionData.market,
|
|
184
185
|
slippageTolerance,
|
|
185
186
|
});
|
|
186
187
|
return {
|
|
187
|
-
getRequirements: (reqParams) => (0,
|
|
188
|
+
getRequirements: (reqParams) => (0, index_js_1.getRequirements)(this.client.viemClient, {
|
|
188
189
|
address: this.marketParams.loanToken,
|
|
189
190
|
chainId: this.chainId,
|
|
190
191
|
supportSignature: this.client.options.supportSignature,
|
|
@@ -192,7 +193,7 @@ class MorphoMarketV1 {
|
|
|
192
193
|
useSimplePermit: reqParams?.useSimplePermit,
|
|
193
194
|
args: { amount: transferAmount, from: userAddress },
|
|
194
195
|
}),
|
|
195
|
-
buildTx: (requirementSignature) => (0,
|
|
196
|
+
buildTx: (requirementSignature) => (0, index_js_1.marketV1Repay)({
|
|
196
197
|
market: {
|
|
197
198
|
chainId: this.chainId,
|
|
198
199
|
marketParams: this.marketParams,
|
|
@@ -211,34 +212,34 @@ class MorphoMarketV1 {
|
|
|
211
212
|
};
|
|
212
213
|
}
|
|
213
214
|
withdrawCollateral({ userAddress, amount, positionData, }) {
|
|
214
|
-
(0,
|
|
215
|
-
(0,
|
|
215
|
+
(0, index_js_2.validateChainId)(this.client.viemClient.chain?.id, this.chainId);
|
|
216
|
+
(0, index_js_2.validateUserAddress)(this.client.viemClient.account?.address, userAddress);
|
|
216
217
|
if (amount <= 0n) {
|
|
217
|
-
throw new
|
|
218
|
+
throw new index_js_3.NonPositiveWithdrawCollateralAmountError(this.marketParams.id);
|
|
218
219
|
}
|
|
219
220
|
if (!positionData) {
|
|
220
|
-
throw new
|
|
221
|
+
throw new index_js_3.MissingAccrualPositionError(this.marketParams.id);
|
|
221
222
|
}
|
|
222
|
-
(0,
|
|
223
|
+
(0, index_js_2.validateAccrualPosition)({
|
|
223
224
|
positionData,
|
|
224
225
|
expectedMarketId: this.marketParams.id,
|
|
225
226
|
expectedUser: userAddress,
|
|
226
227
|
});
|
|
227
228
|
if (amount > positionData.collateral) {
|
|
228
|
-
throw new
|
|
229
|
+
throw new index_js_3.WithdrawExceedsCollateralError({
|
|
229
230
|
withdrawAmount: amount,
|
|
230
231
|
available: positionData.collateral,
|
|
231
232
|
market: positionData.marketId,
|
|
232
233
|
});
|
|
233
234
|
}
|
|
234
|
-
(0,
|
|
235
|
+
(0, index_js_2.validatePositionHealthAfterWithdraw)({
|
|
235
236
|
positionData,
|
|
236
237
|
withdrawAmount: amount,
|
|
237
238
|
lltv: this.marketParams.lltv,
|
|
238
239
|
marketId: this.marketParams.id,
|
|
239
240
|
});
|
|
240
241
|
return {
|
|
241
|
-
buildTx: () => (0,
|
|
242
|
+
buildTx: () => (0, index_js_1.marketV1WithdrawCollateral)({
|
|
242
243
|
market: {
|
|
243
244
|
chainId: this.chainId,
|
|
244
245
|
marketParams: this.marketParams,
|
|
@@ -253,31 +254,31 @@ class MorphoMarketV1 {
|
|
|
253
254
|
};
|
|
254
255
|
}
|
|
255
256
|
repayWithdrawCollateral(params) {
|
|
256
|
-
(0,
|
|
257
|
-
(0,
|
|
257
|
+
(0, index_js_2.validateChainId)(this.client.viemClient.chain?.id, this.chainId);
|
|
258
|
+
(0, index_js_2.validateUserAddress)(this.client.viemClient.account?.address, params.userAddress);
|
|
258
259
|
const { userAddress, withdrawAmount, positionData, slippageTolerance = blue_sdk_1.DEFAULT_SLIPPAGE_TOLERANCE, } = params;
|
|
259
260
|
if ("assets" in params && "shares" in params) {
|
|
260
|
-
throw new
|
|
261
|
+
throw new index_js_3.MutuallyExclusiveRepayAmountsError(this.marketParams.id);
|
|
261
262
|
}
|
|
262
263
|
const isSharesMode = "shares" in params;
|
|
263
264
|
if (isSharesMode) {
|
|
264
265
|
if (params.shares <= 0n) {
|
|
265
|
-
throw new
|
|
266
|
+
throw new index_js_3.NonPositiveRepayAmountError(this.marketParams.id);
|
|
266
267
|
}
|
|
267
268
|
}
|
|
268
269
|
else {
|
|
269
270
|
if (params.assets <= 0n) {
|
|
270
|
-
throw new
|
|
271
|
+
throw new index_js_3.NonPositiveRepayAmountError(this.marketParams.id);
|
|
271
272
|
}
|
|
272
273
|
}
|
|
273
274
|
if (withdrawAmount <= 0n) {
|
|
274
|
-
throw new
|
|
275
|
+
throw new index_js_3.NonPositiveWithdrawCollateralAmountError(this.marketParams.id);
|
|
275
276
|
}
|
|
276
|
-
(0,
|
|
277
|
+
(0, index_js_2.validateSlippageTolerance)(slippageTolerance);
|
|
277
278
|
if (!positionData) {
|
|
278
|
-
throw new
|
|
279
|
+
throw new index_js_3.MissingAccrualPositionError(this.marketParams.id);
|
|
279
280
|
}
|
|
280
|
-
(0,
|
|
281
|
+
(0, index_js_2.validateAccrualPosition)({
|
|
281
282
|
positionData,
|
|
282
283
|
expectedMarketId: this.marketParams.id,
|
|
283
284
|
expectedUser: userAddress,
|
|
@@ -286,7 +287,7 @@ class MorphoMarketV1 {
|
|
|
286
287
|
let shares;
|
|
287
288
|
let transferAmount;
|
|
288
289
|
if (isSharesMode) {
|
|
289
|
-
(0,
|
|
290
|
+
(0, index_js_2.validateRepayShares)({
|
|
290
291
|
positionData,
|
|
291
292
|
repayShares: params.shares,
|
|
292
293
|
marketId: this.marketParams.id,
|
|
@@ -297,7 +298,7 @@ class MorphoMarketV1 {
|
|
|
297
298
|
transferAmount = blue_sdk_1.MathLib.wMulUp(baseTransferAmount, blue_sdk_1.MathLib.WAD + slippageTolerance);
|
|
298
299
|
}
|
|
299
300
|
else {
|
|
300
|
-
(0,
|
|
301
|
+
(0, index_js_2.validateRepayAmount)({
|
|
301
302
|
positionData,
|
|
302
303
|
repayAssets: params.assets,
|
|
303
304
|
marketId: this.marketParams.id,
|
|
@@ -307,7 +308,7 @@ class MorphoMarketV1 {
|
|
|
307
308
|
transferAmount = params.assets;
|
|
308
309
|
}
|
|
309
310
|
if (withdrawAmount > positionData.collateral) {
|
|
310
|
-
throw new
|
|
311
|
+
throw new index_js_3.WithdrawExceedsCollateralError({
|
|
311
312
|
withdrawAmount,
|
|
312
313
|
available: positionData.collateral,
|
|
313
314
|
market: positionData.marketId,
|
|
@@ -317,13 +318,13 @@ class MorphoMarketV1 {
|
|
|
317
318
|
const accrualTimestamp = blue_sdk_1.MathLib.max(morpho_ts_1.Time.timestamp(), positionData.market.lastUpdate) +
|
|
318
319
|
morpho_ts_1.Time.s.from.min(10n);
|
|
319
320
|
const { position: positionAfterRepay } = positionData.repay(assets, shares, accrualTimestamp);
|
|
320
|
-
(0,
|
|
321
|
+
(0, index_js_2.validatePositionHealthAfterWithdraw)({
|
|
321
322
|
positionData: positionAfterRepay,
|
|
322
323
|
withdrawAmount,
|
|
323
324
|
lltv: this.marketParams.lltv,
|
|
324
325
|
marketId: this.marketParams.id,
|
|
325
326
|
});
|
|
326
|
-
const maxSharePrice = (0,
|
|
327
|
+
const maxSharePrice = (0, index_js_2.computeMaxRepaySharePrice)({
|
|
327
328
|
repayAssets: assets,
|
|
328
329
|
repayShares: shares,
|
|
329
330
|
market: positionData.market,
|
|
@@ -332,7 +333,7 @@ class MorphoMarketV1 {
|
|
|
332
333
|
return {
|
|
333
334
|
getRequirements: async (reqParams) => {
|
|
334
335
|
const [erc20Requirements, authTx] = await Promise.all([
|
|
335
|
-
(0,
|
|
336
|
+
(0, index_js_1.getRequirements)(this.client.viemClient, {
|
|
336
337
|
address: this.marketParams.loanToken,
|
|
337
338
|
chainId: this.chainId,
|
|
338
339
|
supportSignature: this.client.options.supportSignature,
|
|
@@ -340,7 +341,7 @@ class MorphoMarketV1 {
|
|
|
340
341
|
useSimplePermit: reqParams?.useSimplePermit,
|
|
341
342
|
args: { amount: transferAmount, from: userAddress },
|
|
342
343
|
}),
|
|
343
|
-
(0,
|
|
344
|
+
(0, index_js_1.getMorphoAuthorizationRequirement)({
|
|
344
345
|
viemClient: this.client.viemClient,
|
|
345
346
|
chainId: this.chainId,
|
|
346
347
|
userAddress,
|
|
@@ -348,7 +349,7 @@ class MorphoMarketV1 {
|
|
|
348
349
|
]);
|
|
349
350
|
return [...erc20Requirements, ...(authTx ? [authTx] : [])];
|
|
350
351
|
},
|
|
351
|
-
buildTx: (requirementSignature) => (0,
|
|
352
|
+
buildTx: (requirementSignature) => (0, index_js_1.marketV1RepayWithdrawCollateral)({
|
|
352
353
|
market: {
|
|
353
354
|
chainId: this.chainId,
|
|
354
355
|
marketParams: this.marketParams,
|
|
@@ -368,41 +369,41 @@ class MorphoMarketV1 {
|
|
|
368
369
|
};
|
|
369
370
|
}
|
|
370
371
|
supplyCollateralBorrow({ amount = 0n, userAddress, positionData, borrowAmount, nativeAmount, slippageTolerance = blue_sdk_1.DEFAULT_SLIPPAGE_TOLERANCE, reallocations, }) {
|
|
371
|
-
(0,
|
|
372
|
-
(0,
|
|
372
|
+
(0, index_js_2.validateChainId)(this.client.viemClient.chain?.id, this.chainId);
|
|
373
|
+
(0, index_js_2.validateUserAddress)(this.client.viemClient.account?.address, userAddress);
|
|
373
374
|
if (amount < 0n) {
|
|
374
|
-
throw new
|
|
375
|
+
throw new index_js_3.NonPositiveAssetAmountError(this.marketParams.collateralToken);
|
|
375
376
|
}
|
|
376
377
|
if (nativeAmount !== undefined && nativeAmount < 0n) {
|
|
377
|
-
throw new
|
|
378
|
+
throw new index_js_3.NegativeNativeAmountError(nativeAmount);
|
|
378
379
|
}
|
|
379
380
|
if (borrowAmount <= 0n) {
|
|
380
|
-
throw new
|
|
381
|
+
throw new index_js_3.NonPositiveBorrowAmountError(this.marketParams.id);
|
|
381
382
|
}
|
|
382
383
|
if (!positionData) {
|
|
383
|
-
throw new
|
|
384
|
+
throw new index_js_3.MissingAccrualPositionError(this.marketParams.id);
|
|
384
385
|
}
|
|
385
|
-
(0,
|
|
386
|
+
(0, index_js_2.validateAccrualPosition)({
|
|
386
387
|
positionData,
|
|
387
388
|
expectedMarketId: this.marketParams.id,
|
|
388
389
|
expectedUser: userAddress,
|
|
389
390
|
});
|
|
390
391
|
const totalCollateral = amount + (nativeAmount ?? 0n);
|
|
391
392
|
if (totalCollateral === 0n) {
|
|
392
|
-
throw new
|
|
393
|
+
throw new index_js_3.ZeroCollateralAmountError(this.marketParams.id);
|
|
393
394
|
}
|
|
394
|
-
(0,
|
|
395
|
+
(0, index_js_2.validateSlippageTolerance)(slippageTolerance);
|
|
395
396
|
if (nativeAmount !== undefined && nativeAmount > 0n) {
|
|
396
|
-
(0,
|
|
397
|
+
(0, index_js_2.validateNativeCollateral)(this.chainId, this.marketParams.collateralToken);
|
|
397
398
|
}
|
|
398
|
-
(0,
|
|
399
|
+
(0, index_js_2.validatePositionHealth)({
|
|
399
400
|
positionData,
|
|
400
401
|
additionalCollateral: totalCollateral,
|
|
401
402
|
borrowAmount,
|
|
402
403
|
marketId: this.marketParams.id,
|
|
403
404
|
lltv: this.marketParams.lltv,
|
|
404
405
|
});
|
|
405
|
-
const minSharePrice = (0,
|
|
406
|
+
const minSharePrice = (0, index_js_2.computeMinBorrowSharePrice)({
|
|
406
407
|
borrowAmount,
|
|
407
408
|
market: positionData.market,
|
|
408
409
|
slippageTolerance,
|
|
@@ -410,7 +411,7 @@ class MorphoMarketV1 {
|
|
|
410
411
|
return {
|
|
411
412
|
getRequirements: async (params) => {
|
|
412
413
|
const [erc20Requirements, authTx] = await Promise.all([
|
|
413
|
-
(0,
|
|
414
|
+
(0, index_js_1.getRequirements)(this.client.viemClient, {
|
|
414
415
|
address: this.marketParams.collateralToken,
|
|
415
416
|
chainId: this.chainId,
|
|
416
417
|
supportSignature: this.client.options.supportSignature,
|
|
@@ -418,7 +419,7 @@ class MorphoMarketV1 {
|
|
|
418
419
|
useSimplePermit: params?.useSimplePermit,
|
|
419
420
|
args: { amount, from: userAddress },
|
|
420
421
|
}),
|
|
421
|
-
(0,
|
|
422
|
+
(0, index_js_1.getMorphoAuthorizationRequirement)({
|
|
422
423
|
viemClient: this.client.viemClient,
|
|
423
424
|
chainId: this.chainId,
|
|
424
425
|
userAddress,
|
|
@@ -426,7 +427,7 @@ class MorphoMarketV1 {
|
|
|
426
427
|
]);
|
|
427
428
|
return [...erc20Requirements, ...(authTx ? [authTx] : [])];
|
|
428
429
|
},
|
|
429
|
-
buildTx: (requirementSignature) => (0,
|
|
430
|
+
buildTx: (requirementSignature) => (0, index_js_1.marketV1SupplyCollateralBorrow)({
|
|
430
431
|
market: {
|
|
431
432
|
chainId: this.chainId,
|
|
432
433
|
marketParams: this.marketParams,
|
|
@@ -445,21 +446,22 @@ class MorphoMarketV1 {
|
|
|
445
446
|
}),
|
|
446
447
|
};
|
|
447
448
|
}
|
|
448
|
-
async getReallocationData({ vaultAddresses,
|
|
449
|
-
(0,
|
|
450
|
-
if (market.id !== this.marketParams.id) {
|
|
451
|
-
throw new types_1.MarketIdMismatchError(market.id, this.marketParams.id);
|
|
452
|
-
}
|
|
449
|
+
async getReallocationData({ vaultAddresses, block, }) {
|
|
450
|
+
(0, index_js_2.validateChainId)(this.client.viemClient.chain?.id, this.chainId);
|
|
453
451
|
const client = this.client.viemClient;
|
|
454
452
|
const fetchParams = {
|
|
455
453
|
blockNumber: block.number,
|
|
456
454
|
chainId: this.chainId,
|
|
457
455
|
deployless: this.client.options.supportDeployless,
|
|
458
456
|
};
|
|
459
|
-
// Phase 1: Fetch all vaults in parallel to get their withdrawQueues.
|
|
460
|
-
const vaults = await Promise.all(vaultAddresses.map((addr) => (0, blue_sdk_viem_1.fetchVault)(addr, client, fetchParams)));
|
|
461
|
-
// Collect unique market IDs from all vault withdrawQueues + target market.
|
|
462
457
|
const targetMarketId = this.marketParams.id;
|
|
458
|
+
// Phase 1: Fetch the target market and all vaults at `block.number` in
|
|
459
|
+
// parallel so every row of the resulting state comes from the same epoch
|
|
460
|
+
// and the planner never trusts a caller-owned target-market snapshot.
|
|
461
|
+
const [targetMarket, vaults] = await Promise.all([
|
|
462
|
+
(0, blue_sdk_viem_1.fetchMarket)(targetMarketId, client, fetchParams),
|
|
463
|
+
Promise.all(vaultAddresses.map((addr) => (0, blue_sdk_viem_1.fetchVault)(addr, client, fetchParams))),
|
|
464
|
+
]);
|
|
463
465
|
const allMarketIds = new Set([targetMarketId]);
|
|
464
466
|
const vaultMarketPairs = [];
|
|
465
467
|
for (const vault of vaults) {
|
|
@@ -475,7 +477,7 @@ class MorphoMarketV1 {
|
|
|
475
477
|
}
|
|
476
478
|
// Phase 2: Fetch all source markets, vault configs, and positions in parallel.
|
|
477
479
|
const sourceMarketIds = [...allMarketIds].filter((mid) => mid !== targetMarketId);
|
|
478
|
-
const loanToken =
|
|
480
|
+
const loanToken = targetMarket.params.loanToken;
|
|
479
481
|
const [markets, configs, positions, holdings] = await Promise.all([
|
|
480
482
|
Promise.all(sourceMarketIds.map((mid) => (0, blue_sdk_viem_1.fetchMarket)(mid, client, fetchParams))),
|
|
481
483
|
Promise.all(vaultMarketPairs.map(({ vault, marketId: mid }) => (0, blue_sdk_viem_1.fetchVaultMarketConfig)(vault, mid, client, fetchParams).then((config) => ({ vault, mid, config })))),
|
|
@@ -488,7 +490,7 @@ class MorphoMarketV1 {
|
|
|
488
490
|
]);
|
|
489
491
|
// Assemble records for SimulationState.
|
|
490
492
|
const marketsRecord = {
|
|
491
|
-
[targetMarketId]:
|
|
493
|
+
[targetMarketId]: targetMarket,
|
|
492
494
|
};
|
|
493
495
|
for (const m of markets) {
|
|
494
496
|
marketsRecord[m.id] = m;
|
|
@@ -520,7 +522,7 @@ class MorphoMarketV1 {
|
|
|
520
522
|
});
|
|
521
523
|
}
|
|
522
524
|
getReallocations({ reallocationData, borrowAmount, options, }) {
|
|
523
|
-
return (0,
|
|
525
|
+
return (0, index_js_2.computeReallocations)({
|
|
524
526
|
reallocationData,
|
|
525
527
|
marketId: this.marketParams.id,
|
|
526
528
|
borrowAmount,
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./vaultV1.js";
|
|
@@ -14,4 +14,4 @@ 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
|
-
__exportStar(require("./
|
|
17
|
+
__exportStar(require("./vaultV1.js"), exports);
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
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
|
-
import
|
|
5
|
-
import type
|
|
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";
|
|
6
6
|
export interface VaultV1Actions {
|
|
7
7
|
/**
|
|
8
8
|
* Fetches the latest vault data with accrued interest.
|
|
@@ -85,9 +85,7 @@ export interface VaultV1Actions {
|
|
|
85
85
|
slippageTolerance?: bigint;
|
|
86
86
|
}) => {
|
|
87
87
|
buildTx: (requirementSignature?: RequirementSignature) => Readonly<Transaction<VaultV1MigrateToV2Action>>;
|
|
88
|
-
getRequirements: (
|
|
89
|
-
useSimplePermit?: boolean;
|
|
90
|
-
}) => Promise<(Readonly<Transaction<ERC20ApprovalAction>> | Requirement)[]>;
|
|
88
|
+
getRequirements: () => Promise<(Readonly<Transaction<ERC20ApprovalAction>> | Requirement)[]>;
|
|
91
89
|
};
|
|
92
90
|
}
|
|
93
91
|
export declare class MorphoVaultV1 implements VaultV1Actions {
|
|
@@ -125,9 +123,7 @@ export declare class MorphoVaultV1 implements VaultV1Actions {
|
|
|
125
123
|
shares: bigint;
|
|
126
124
|
slippageTolerance?: bigint;
|
|
127
125
|
}): {
|
|
128
|
-
getRequirements: (
|
|
129
|
-
useSimplePermit?: boolean;
|
|
130
|
-
}) => Promise<(Requirement | Readonly<Transaction<ERC20ApprovalAction>>)[]>;
|
|
126
|
+
getRequirements: () => Promise<(Requirement | Readonly<Transaction<ERC20ApprovalAction>>)[]>;
|
|
131
127
|
buildTx: (requirementSignature?: RequirementSignature) => Readonly<Transaction<VaultV1MigrateToV2Action>>;
|
|
132
128
|
};
|
|
133
129
|
}
|