@morpho-org/morpho-sdk 1.0.1 → 1.2.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/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 -7
- package/lib/{types → cjs/types}/error.js +47 -7
- 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 +33 -56
- 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 -85
- 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,273 @@
|
|
|
1
|
+
import { getChainAddresses, MathLib, ORACLE_PRICE_SCALE, } from "@morpho-org/blue-sdk";
|
|
2
|
+
import { isDefined } from "@morpho-org/morpho-ts";
|
|
3
|
+
import { isAddressEqual } from "viem";
|
|
4
|
+
import { AccrualPositionUserMismatchError, AddressMismatchError, BorrowExceedsSafeLtvError, ChainIdMismatchError, ChainWNativeMissingError, EmptyReallocationWithdrawalsError, ExcessiveSlippageToleranceError, MarketIdMismatchError, MissingClientPropertyError, MissingMarketPriceError, MutuallyExclusiveRepayAmountsError, NativeAmountOnNonWNativeCollateralError, NegativeReallocationFeeError, NegativeSlippageToleranceError, NonPositiveReallocationAmountError, NonPositiveRepayAmountError, NonPositiveRepayMaxSharePriceError, NonPositiveTransferAmountError, ReallocationWithdrawalOnTargetMarketError, RepayExceedsDebtError, RepaySharesExceedDebtError, TransferAmountNotEqualToAssetsError, UnsortedReallocationWithdrawalsError, WithdrawExceedsCollateralError, WithdrawMakesPositionUnhealthyError, } from "../types/index.js";
|
|
5
|
+
import { DEFAULT_LLTV_BUFFER, MAX_SLIPPAGE_TOLERANCE } from "./constant.js";
|
|
6
|
+
/**
|
|
7
|
+
* Validates that the client has a connected account AND that it matches
|
|
8
|
+
* the provided user address.
|
|
9
|
+
*
|
|
10
|
+
* Enforces the builder = executor invariant: `userAddress` MUST equal the
|
|
11
|
+
* connected client account. Some bundle actions (e.g. `erc20TransferFrom`,
|
|
12
|
+
* `morphoWithdrawCollateral`) act implicitly on the initiator rather than
|
|
13
|
+
* on `userAddress`, so a divergence can produce mixed-account bundles.
|
|
14
|
+
*
|
|
15
|
+
* Throws {@link MissingClientPropertyError} if the client has no account.
|
|
16
|
+
* Throws {@link AddressMismatchError} if the client account differs from
|
|
17
|
+
* `userAddress`.
|
|
18
|
+
*
|
|
19
|
+
* @param clientAccountAddress - The client's account address; if undefined,
|
|
20
|
+
* `MissingClientPropertyError` is thrown.
|
|
21
|
+
* @param userAddress - The user address provided by the caller.
|
|
22
|
+
*/
|
|
23
|
+
export const validateUserAddress = (clientAccountAddress, userAddress) => {
|
|
24
|
+
if (clientAccountAddress === undefined) {
|
|
25
|
+
throw new MissingClientPropertyError("account");
|
|
26
|
+
}
|
|
27
|
+
if (!isAddressEqual(clientAccountAddress, userAddress)) {
|
|
28
|
+
throw new AddressMismatchError(clientAccountAddress, userAddress);
|
|
29
|
+
}
|
|
30
|
+
};
|
|
31
|
+
/**
|
|
32
|
+
* Validates that the accrual position belongs to the expected market and user.
|
|
33
|
+
* Throws {@link MarketIdMismatchError} if the position's market ID
|
|
34
|
+
* does not match the expected market.
|
|
35
|
+
* Throws {@link AccrualPositionUserMismatchError} if the position's user
|
|
36
|
+
* does not match the expected user.
|
|
37
|
+
*
|
|
38
|
+
* @param params - Validation parameters.
|
|
39
|
+
* @param params.positionData - The accrual position to validate.
|
|
40
|
+
* @param params.expectedMarketId - The market ID the position must belong to.
|
|
41
|
+
* @param params.expectedUser - The user address the position must belong to.
|
|
42
|
+
*/
|
|
43
|
+
export const validateAccrualPosition = (params) => {
|
|
44
|
+
const { positionData, expectedMarketId, expectedUser } = params;
|
|
45
|
+
if (positionData.marketId !== expectedMarketId) {
|
|
46
|
+
throw new MarketIdMismatchError(positionData.marketId, expectedMarketId);
|
|
47
|
+
}
|
|
48
|
+
if (!isAddressEqual(positionData.user, expectedUser)) {
|
|
49
|
+
throw new AccrualPositionUserMismatchError(positionData.user, expectedUser);
|
|
50
|
+
}
|
|
51
|
+
};
|
|
52
|
+
/**
|
|
53
|
+
* Validates that the resulting position stays within the safe LTV threshold
|
|
54
|
+
* (LLTV minus buffer) after supplying additional collateral and borrowing.
|
|
55
|
+
*
|
|
56
|
+
* @param params - Validation parameters.
|
|
57
|
+
* @param params.positionData - The current accrual position with market data.
|
|
58
|
+
* @param params.additionalCollateral - Amount of collateral being added.
|
|
59
|
+
* @param params.borrowAmount - Amount being borrowed.
|
|
60
|
+
* @param params.marketId - The market identifier (for error messages).
|
|
61
|
+
* @param params.lltv - The market's liquidation LTV.
|
|
62
|
+
*/
|
|
63
|
+
export const validatePositionHealth = (params) => {
|
|
64
|
+
const { positionData, additionalCollateral, borrowAmount, marketId, lltv } = params;
|
|
65
|
+
const { price } = positionData.market;
|
|
66
|
+
if (!price) {
|
|
67
|
+
throw new MissingMarketPriceError(marketId);
|
|
68
|
+
}
|
|
69
|
+
const totalCollateralAfter = positionData.collateral + additionalCollateral;
|
|
70
|
+
const collateralValueAfter = MathLib.mulDivDown(totalCollateralAfter, price, ORACLE_PRICE_SCALE);
|
|
71
|
+
const effectiveLltv = lltv > DEFAULT_LLTV_BUFFER ? lltv - DEFAULT_LLTV_BUFFER : 0n;
|
|
72
|
+
const maxSafeBorrowAfter = MathLib.wMulDown(collateralValueAfter, effectiveLltv);
|
|
73
|
+
const totalBorrowAfter = positionData.borrowAssets + borrowAmount + 1n; // +1 to account for share-to-asset rounding (happens when the borrow amount doesn't divide evenly into shares)
|
|
74
|
+
if (totalBorrowAfter > maxSafeBorrowAfter) {
|
|
75
|
+
const maxSafeAdditionalBorrow = MathLib.zeroFloorSub(maxSafeBorrowAfter, positionData.borrowAssets);
|
|
76
|
+
throw new BorrowExceedsSafeLtvError(borrowAmount, maxSafeAdditionalBorrow);
|
|
77
|
+
}
|
|
78
|
+
};
|
|
79
|
+
/**
|
|
80
|
+
* Validates that the viem client chain ID matches the expected chain ID.
|
|
81
|
+
* Throws {@link ChainIdMismatchError} if they differ.
|
|
82
|
+
*
|
|
83
|
+
* @param clientChainId - Chain ID reported by the viem client (may be undefined).
|
|
84
|
+
* @param expectedChainId - Chain ID expected by the entity or action.
|
|
85
|
+
*/
|
|
86
|
+
export const validateChainId = (clientChainId, expectedChainId) => {
|
|
87
|
+
if (clientChainId !== expectedChainId) {
|
|
88
|
+
throw new ChainIdMismatchError(clientChainId, expectedChainId);
|
|
89
|
+
}
|
|
90
|
+
};
|
|
91
|
+
/**
|
|
92
|
+
* Validates that the given collateral token is the chain's wrapped native token.
|
|
93
|
+
* Throws {@link ChainWNativeMissingError} if wNative is not configured for the chain.
|
|
94
|
+
* Throws {@link NativeAmountOnNonWNativeCollateralError} if collateral is not wNative.
|
|
95
|
+
*
|
|
96
|
+
* @param chainId - The chain to look up wNative on.
|
|
97
|
+
* @param collateralToken - The market's collateral token address.
|
|
98
|
+
*/
|
|
99
|
+
export const validateNativeCollateral = (chainId, collateralToken) => {
|
|
100
|
+
const { wNative } = getChainAddresses(chainId);
|
|
101
|
+
if (!isDefined(wNative)) {
|
|
102
|
+
throw new ChainWNativeMissingError(chainId);
|
|
103
|
+
}
|
|
104
|
+
if (!isAddressEqual(collateralToken, wNative)) {
|
|
105
|
+
throw new NativeAmountOnNonWNativeCollateralError(collateralToken, wNative);
|
|
106
|
+
}
|
|
107
|
+
};
|
|
108
|
+
/**
|
|
109
|
+
* Validates that the resulting position stays within the safe LTV threshold
|
|
110
|
+
* (LLTV minus buffer) after withdrawing collateral.
|
|
111
|
+
*
|
|
112
|
+
* @param params - Validation parameters.
|
|
113
|
+
* @param params.positionData - The current accrual position with market data.
|
|
114
|
+
* @param params.withdrawAmount - Amount of collateral being withdrawn.
|
|
115
|
+
* @param params.lltv - The market's liquidation LTV.
|
|
116
|
+
* @param params.marketId - The market identifier (for error messages).
|
|
117
|
+
*/
|
|
118
|
+
export const validatePositionHealthAfterWithdraw = (params) => {
|
|
119
|
+
const { positionData, withdrawAmount, lltv, marketId } = params;
|
|
120
|
+
if (positionData.marketId !== marketId) {
|
|
121
|
+
throw new MarketIdMismatchError(positionData.marketId, marketId);
|
|
122
|
+
}
|
|
123
|
+
if (withdrawAmount > positionData.collateral) {
|
|
124
|
+
throw new WithdrawExceedsCollateralError({
|
|
125
|
+
withdrawAmount,
|
|
126
|
+
available: positionData.collateral,
|
|
127
|
+
market: marketId,
|
|
128
|
+
});
|
|
129
|
+
}
|
|
130
|
+
// No debt means position is always healthy — oracle price not needed.
|
|
131
|
+
if (positionData.borrowAssets === 0n) {
|
|
132
|
+
return;
|
|
133
|
+
}
|
|
134
|
+
const { price } = positionData.market;
|
|
135
|
+
if (!price) {
|
|
136
|
+
throw new MissingMarketPriceError(positionData.marketId);
|
|
137
|
+
}
|
|
138
|
+
const collateralAfter = positionData.collateral - withdrawAmount;
|
|
139
|
+
const collateralValueAfter = MathLib.mulDivDown(collateralAfter, price, ORACLE_PRICE_SCALE);
|
|
140
|
+
const effectiveLltv = lltv > DEFAULT_LLTV_BUFFER ? lltv - DEFAULT_LLTV_BUFFER : 0n;
|
|
141
|
+
const maxSafeBorrowAfter = MathLib.wMulDown(collateralValueAfter, effectiveLltv);
|
|
142
|
+
if (positionData.borrowAssets > maxSafeBorrowAfter) {
|
|
143
|
+
throw new WithdrawMakesPositionUnhealthyError({
|
|
144
|
+
withdrawAmount,
|
|
145
|
+
borrowAssets: positionData.borrowAssets,
|
|
146
|
+
maxSafeBorrow: maxSafeBorrowAfter,
|
|
147
|
+
});
|
|
148
|
+
}
|
|
149
|
+
};
|
|
150
|
+
/**
|
|
151
|
+
* Validates that the repay amount assets does not exceed the outstanding debt.
|
|
152
|
+
*
|
|
153
|
+
* @param params - Validation parameters.
|
|
154
|
+
* @param params.positionData - The current accrual position.
|
|
155
|
+
* @param params.repayAssets - The amount of assets to repay.
|
|
156
|
+
* @param params.marketId - The market identifier (for error messages).
|
|
157
|
+
*/
|
|
158
|
+
export const validateRepayAmount = (params) => {
|
|
159
|
+
const { positionData, repayAssets, marketId } = params;
|
|
160
|
+
if (repayAssets > positionData.borrowAssets) {
|
|
161
|
+
throw new RepayExceedsDebtError({
|
|
162
|
+
repayAmount: repayAssets,
|
|
163
|
+
debt: positionData.borrowAssets,
|
|
164
|
+
market: marketId,
|
|
165
|
+
});
|
|
166
|
+
}
|
|
167
|
+
};
|
|
168
|
+
/**
|
|
169
|
+
* Validates that the repay shares do not exceed the outstanding borrow shares.
|
|
170
|
+
*
|
|
171
|
+
* @param params - Validation parameters.
|
|
172
|
+
* @param params.positionData - The current accrual position.
|
|
173
|
+
* @param params.repayShares - The amount of shares to repay.
|
|
174
|
+
* @param params.marketId - The market identifier (for error messages).
|
|
175
|
+
*/
|
|
176
|
+
export const validateRepayShares = (params) => {
|
|
177
|
+
const { positionData, repayShares, marketId } = params;
|
|
178
|
+
if (repayShares > positionData.borrowShares) {
|
|
179
|
+
throw new RepaySharesExceedDebtError({
|
|
180
|
+
repayShares,
|
|
181
|
+
borrowShares: positionData.borrowShares,
|
|
182
|
+
market: marketId,
|
|
183
|
+
});
|
|
184
|
+
}
|
|
185
|
+
};
|
|
186
|
+
/**
|
|
187
|
+
* Validates the common repay input parameters shared by `marketV1Repay`
|
|
188
|
+
* and `marketV1RepayWithdrawCollateral`.
|
|
189
|
+
*
|
|
190
|
+
* @param params - Validation parameters.
|
|
191
|
+
* @param params.assets - Repay assets amount (0n when repaying by shares).
|
|
192
|
+
* @param params.shares - Repay shares amount (0n when repaying by assets).
|
|
193
|
+
* @param params.transferAmount - ERC20 amount to transfer to GeneralAdapter1.
|
|
194
|
+
* @param params.maxSharePrice - Maximum repay share price (in ray). Must be positive.
|
|
195
|
+
* @param params.marketId - The market identifier (for error messages).
|
|
196
|
+
*/
|
|
197
|
+
export const validateRepayParams = (params) => {
|
|
198
|
+
const { assets, shares, transferAmount, maxSharePrice, marketId } = params;
|
|
199
|
+
if (maxSharePrice <= 0n) {
|
|
200
|
+
throw new NonPositiveRepayMaxSharePriceError(marketId);
|
|
201
|
+
}
|
|
202
|
+
if (assets < 0n || shares < 0n) {
|
|
203
|
+
throw new NonPositiveRepayAmountError(marketId);
|
|
204
|
+
}
|
|
205
|
+
if (assets > 0n && shares > 0n) {
|
|
206
|
+
throw new MutuallyExclusiveRepayAmountsError(marketId);
|
|
207
|
+
}
|
|
208
|
+
if (assets === 0n && shares === 0n) {
|
|
209
|
+
throw new NonPositiveRepayAmountError(marketId);
|
|
210
|
+
}
|
|
211
|
+
if (transferAmount <= 0n) {
|
|
212
|
+
throw new NonPositiveTransferAmountError(marketId);
|
|
213
|
+
}
|
|
214
|
+
if (assets > 0n && transferAmount !== assets) {
|
|
215
|
+
throw new TransferAmountNotEqualToAssetsError({
|
|
216
|
+
transferAmount,
|
|
217
|
+
assets,
|
|
218
|
+
market: marketId,
|
|
219
|
+
});
|
|
220
|
+
}
|
|
221
|
+
};
|
|
222
|
+
/**
|
|
223
|
+
* Validates that vault reallocations are well-formed.
|
|
224
|
+
*
|
|
225
|
+
* Enforces the following invariants for each {@link VaultReallocation}:
|
|
226
|
+
* - `fee` must be non-negative.
|
|
227
|
+
* - `withdrawals` must be non-empty.
|
|
228
|
+
* - Every withdrawal `amount` must be strictly positive.
|
|
229
|
+
* - No withdrawal may target `targetMarketId` (the borrow market).
|
|
230
|
+
* - Withdrawal market IDs must be strictly ascending (required by `PublicAllocator.reallocateTo`).
|
|
231
|
+
*
|
|
232
|
+
* @param reallocations - The reallocations to validate.
|
|
233
|
+
* @param targetMarketId - The ID of the market being borrowed from. No withdrawal may reference this market.
|
|
234
|
+
*/
|
|
235
|
+
export const validateReallocations = (reallocations, targetMarketId) => {
|
|
236
|
+
for (const r of reallocations) {
|
|
237
|
+
if (r.fee < 0n) {
|
|
238
|
+
throw new NegativeReallocationFeeError(r.vault);
|
|
239
|
+
}
|
|
240
|
+
if (r.withdrawals.length === 0) {
|
|
241
|
+
throw new EmptyReallocationWithdrawalsError(r.vault);
|
|
242
|
+
}
|
|
243
|
+
let prevId;
|
|
244
|
+
for (const w of r.withdrawals) {
|
|
245
|
+
if (w.amount <= 0n) {
|
|
246
|
+
throw new NonPositiveReallocationAmountError(r.vault, w.marketParams.id);
|
|
247
|
+
}
|
|
248
|
+
if (w.marketParams.id === targetMarketId) {
|
|
249
|
+
throw new ReallocationWithdrawalOnTargetMarketError(r.vault, w.marketParams.id);
|
|
250
|
+
}
|
|
251
|
+
if (prevId !== undefined && w.marketParams.id <= prevId) {
|
|
252
|
+
throw new UnsortedReallocationWithdrawalsError(r.vault, w.marketParams.id);
|
|
253
|
+
}
|
|
254
|
+
prevId = w.marketParams.id;
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
};
|
|
258
|
+
/**
|
|
259
|
+
* Validates that a slippage tolerance is within an acceptable range.
|
|
260
|
+
*
|
|
261
|
+
* Throws {@link NegativeSlippageToleranceError} if negative.
|
|
262
|
+
* Throws {@link ExcessiveSlippageToleranceError} if greater than {@link MAX_SLIPPAGE_TOLERANCE}.
|
|
263
|
+
*
|
|
264
|
+
* @param slippageTolerance - The slippage tolerance in WAD.
|
|
265
|
+
*/
|
|
266
|
+
export const validateSlippageTolerance = (slippageTolerance) => {
|
|
267
|
+
if (slippageTolerance < 0n) {
|
|
268
|
+
throw new NegativeSlippageToleranceError(slippageTolerance);
|
|
269
|
+
}
|
|
270
|
+
if (slippageTolerance > MAX_SLIPPAGE_TOLERANCE) {
|
|
271
|
+
throw new ExcessiveSlippageToleranceError(slippageTolerance);
|
|
272
|
+
}
|
|
273
|
+
};
|
package/lib/esm/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"type":"module"}
|
|
@@ -0,0 +1,216 @@
|
|
|
1
|
+
import type { Address, Client, Hex } from "viem";
|
|
2
|
+
import type { Deallocation } from "./deallocation.js";
|
|
3
|
+
export interface BaseAction<TType extends string = string, TArgs extends Record<string, unknown> = Record<string, unknown>> {
|
|
4
|
+
readonly type: TType;
|
|
5
|
+
readonly args: TArgs;
|
|
6
|
+
}
|
|
7
|
+
export interface ERC20ApprovalAction extends BaseAction<"erc20Approval", {
|
|
8
|
+
spender: Address;
|
|
9
|
+
amount: bigint;
|
|
10
|
+
}> {
|
|
11
|
+
}
|
|
12
|
+
export interface ERC20PermitAction {
|
|
13
|
+
sign: (client: Client, userAddress: Address) => Promise<Hex>;
|
|
14
|
+
}
|
|
15
|
+
export interface VaultV2DepositAction extends BaseAction<"vaultV2Deposit", {
|
|
16
|
+
vault: Address;
|
|
17
|
+
amount: bigint;
|
|
18
|
+
maxSharePrice: bigint;
|
|
19
|
+
recipient: Address;
|
|
20
|
+
nativeAmount?: bigint;
|
|
21
|
+
}> {
|
|
22
|
+
}
|
|
23
|
+
export interface VaultV2WithdrawAction extends BaseAction<"vaultV2Withdraw", {
|
|
24
|
+
vault: Address;
|
|
25
|
+
amount: bigint;
|
|
26
|
+
recipient: Address;
|
|
27
|
+
}> {
|
|
28
|
+
}
|
|
29
|
+
export interface VaultV2RedeemAction extends BaseAction<"vaultV2Redeem", {
|
|
30
|
+
vault: Address;
|
|
31
|
+
shares: bigint;
|
|
32
|
+
recipient: Address;
|
|
33
|
+
}> {
|
|
34
|
+
}
|
|
35
|
+
export interface VaultV2ForceWithdrawAction extends BaseAction<"vaultV2ForceWithdraw", {
|
|
36
|
+
vault: Address;
|
|
37
|
+
deallocations: readonly Deallocation[];
|
|
38
|
+
withdraw: {
|
|
39
|
+
amount: bigint;
|
|
40
|
+
recipient: Address;
|
|
41
|
+
};
|
|
42
|
+
onBehalf: Address;
|
|
43
|
+
}> {
|
|
44
|
+
}
|
|
45
|
+
export interface VaultV2ForceRedeemAction extends BaseAction<"vaultV2ForceRedeem", {
|
|
46
|
+
vault: Address;
|
|
47
|
+
deallocations: readonly Deallocation[];
|
|
48
|
+
redeem: {
|
|
49
|
+
shares: bigint;
|
|
50
|
+
recipient: Address;
|
|
51
|
+
};
|
|
52
|
+
onBehalf: Address;
|
|
53
|
+
}> {
|
|
54
|
+
}
|
|
55
|
+
export interface VaultV1DepositAction extends BaseAction<"vaultV1Deposit", {
|
|
56
|
+
vault: Address;
|
|
57
|
+
amount: bigint;
|
|
58
|
+
maxSharePrice: bigint;
|
|
59
|
+
recipient: Address;
|
|
60
|
+
nativeAmount?: bigint;
|
|
61
|
+
}> {
|
|
62
|
+
}
|
|
63
|
+
export interface VaultV1WithdrawAction extends BaseAction<"vaultV1Withdraw", {
|
|
64
|
+
vault: Address;
|
|
65
|
+
amount: bigint;
|
|
66
|
+
recipient: Address;
|
|
67
|
+
}> {
|
|
68
|
+
}
|
|
69
|
+
export interface VaultV1RedeemAction extends BaseAction<"vaultV1Redeem", {
|
|
70
|
+
vault: Address;
|
|
71
|
+
shares: bigint;
|
|
72
|
+
recipient: Address;
|
|
73
|
+
}> {
|
|
74
|
+
}
|
|
75
|
+
export interface VaultV1MigrateToV2Action extends BaseAction<"vaultV1MigrateToV2", {
|
|
76
|
+
sourceVault: Address;
|
|
77
|
+
targetVault: Address;
|
|
78
|
+
shares: bigint;
|
|
79
|
+
minSharePriceVaultV1: bigint;
|
|
80
|
+
maxSharePriceVaultV2: bigint;
|
|
81
|
+
recipient: Address;
|
|
82
|
+
}> {
|
|
83
|
+
}
|
|
84
|
+
export interface MarketV1SupplyCollateralAction extends BaseAction<"marketV1SupplyCollateral", {
|
|
85
|
+
market: Hex;
|
|
86
|
+
amount: bigint;
|
|
87
|
+
onBehalf: Address;
|
|
88
|
+
nativeAmount?: bigint;
|
|
89
|
+
}> {
|
|
90
|
+
}
|
|
91
|
+
export interface MarketV1BorrowAction extends BaseAction<"marketV1Borrow", {
|
|
92
|
+
market: Hex;
|
|
93
|
+
amount: bigint;
|
|
94
|
+
receiver: Address;
|
|
95
|
+
minSharePrice: bigint;
|
|
96
|
+
reallocationFee: bigint;
|
|
97
|
+
}> {
|
|
98
|
+
}
|
|
99
|
+
export interface MarketV1SupplyCollateralBorrowAction extends BaseAction<"marketV1SupplyCollateralBorrow", {
|
|
100
|
+
market: Hex;
|
|
101
|
+
collateralAmount: bigint;
|
|
102
|
+
borrowAmount: bigint;
|
|
103
|
+
minSharePrice: bigint;
|
|
104
|
+
onBehalf: Address;
|
|
105
|
+
receiver: Address;
|
|
106
|
+
nativeAmount?: bigint;
|
|
107
|
+
reallocationFee: bigint;
|
|
108
|
+
}> {
|
|
109
|
+
}
|
|
110
|
+
export interface MarketV1RepayAction extends BaseAction<"marketV1Repay", {
|
|
111
|
+
market: Hex;
|
|
112
|
+
assets: bigint;
|
|
113
|
+
shares: bigint;
|
|
114
|
+
transferAmount: bigint;
|
|
115
|
+
onBehalf: Address;
|
|
116
|
+
receiver: Address;
|
|
117
|
+
maxSharePrice: bigint;
|
|
118
|
+
}> {
|
|
119
|
+
}
|
|
120
|
+
export interface MarketV1WithdrawCollateralAction extends BaseAction<"marketV1WithdrawCollateral", {
|
|
121
|
+
market: Hex;
|
|
122
|
+
amount: bigint;
|
|
123
|
+
onBehalf: Address;
|
|
124
|
+
receiver: Address;
|
|
125
|
+
}> {
|
|
126
|
+
}
|
|
127
|
+
export interface MarketV1RepayWithdrawCollateralAction extends BaseAction<"marketV1RepayWithdrawCollateral", {
|
|
128
|
+
market: Hex;
|
|
129
|
+
repayAssets: bigint;
|
|
130
|
+
repayShares: bigint;
|
|
131
|
+
transferAmount: bigint;
|
|
132
|
+
withdrawAmount: bigint;
|
|
133
|
+
maxSharePrice: bigint;
|
|
134
|
+
onBehalf: Address;
|
|
135
|
+
receiver: Address;
|
|
136
|
+
}> {
|
|
137
|
+
}
|
|
138
|
+
/**
|
|
139
|
+
* Enforces that exactly one repay amount source is provided.
|
|
140
|
+
*
|
|
141
|
+
* - `assets`: partial repay by exact asset amount.
|
|
142
|
+
* - `shares`: full repay by exact share count (guarantees full debt repayment
|
|
143
|
+
* regardless of interest accrued between tx construction and execution).
|
|
144
|
+
*/
|
|
145
|
+
export type RepayAmountArgs = {
|
|
146
|
+
assets: bigint;
|
|
147
|
+
} | {
|
|
148
|
+
shares: bigint;
|
|
149
|
+
};
|
|
150
|
+
export interface MorphoAuthorizationAction extends BaseAction<"morphoAuthorization", {
|
|
151
|
+
authorized: Address;
|
|
152
|
+
isAuthorized: boolean;
|
|
153
|
+
}> {
|
|
154
|
+
}
|
|
155
|
+
export type TransactionAction = ERC20ApprovalAction | VaultV2DepositAction | VaultV2WithdrawAction | VaultV2RedeemAction | VaultV2ForceWithdrawAction | VaultV2ForceRedeemAction | VaultV1DepositAction | VaultV1WithdrawAction | VaultV1RedeemAction | VaultV1MigrateToV2Action | MarketV1SupplyCollateralAction | MarketV1BorrowAction | MarketV1SupplyCollateralBorrowAction | MarketV1RepayAction | MarketV1WithdrawCollateralAction | MarketV1RepayWithdrawCollateralAction | MorphoAuthorizationAction;
|
|
156
|
+
export interface Transaction<TAction extends BaseAction = TransactionAction> {
|
|
157
|
+
readonly to: Address;
|
|
158
|
+
readonly value: bigint;
|
|
159
|
+
readonly data: Hex;
|
|
160
|
+
readonly action: TAction;
|
|
161
|
+
}
|
|
162
|
+
/**
|
|
163
|
+
* Enforces that at least one deposit amount source is provided.
|
|
164
|
+
*
|
|
165
|
+
* - `amount` alone: standard ERC20 deposit.
|
|
166
|
+
* - `nativeAmount` alone: pure native-wrap deposit (vault asset must be wNative).
|
|
167
|
+
* - Both: mixed deposit (ERC20 transfer + native wrap).
|
|
168
|
+
*/
|
|
169
|
+
export type DepositAmountArgs = {
|
|
170
|
+
amount: bigint;
|
|
171
|
+
nativeAmount?: bigint;
|
|
172
|
+
} | {
|
|
173
|
+
nativeAmount: bigint;
|
|
174
|
+
amount?: bigint;
|
|
175
|
+
};
|
|
176
|
+
export interface PermitArgs {
|
|
177
|
+
owner: Address;
|
|
178
|
+
nonce: bigint;
|
|
179
|
+
asset: Address;
|
|
180
|
+
signature: Hex;
|
|
181
|
+
amount: bigint;
|
|
182
|
+
deadline: bigint;
|
|
183
|
+
}
|
|
184
|
+
export interface Permit2Args {
|
|
185
|
+
owner: Address;
|
|
186
|
+
nonce: bigint;
|
|
187
|
+
asset: Address;
|
|
188
|
+
signature: Hex;
|
|
189
|
+
amount: bigint;
|
|
190
|
+
deadline: bigint;
|
|
191
|
+
expiration: bigint;
|
|
192
|
+
}
|
|
193
|
+
export interface Requirement {
|
|
194
|
+
sign: (client: Client, userAddress: Address) => Promise<RequirementSignature>;
|
|
195
|
+
action: PermitAction | Permit2Action;
|
|
196
|
+
}
|
|
197
|
+
export interface PermitAction extends BaseAction<"permit", {
|
|
198
|
+
spender: Address;
|
|
199
|
+
amount: bigint;
|
|
200
|
+
deadline: bigint;
|
|
201
|
+
}> {
|
|
202
|
+
}
|
|
203
|
+
export interface Permit2Action extends BaseAction<"permit2", {
|
|
204
|
+
spender: Address;
|
|
205
|
+
amount: bigint;
|
|
206
|
+
deadline: bigint;
|
|
207
|
+
expiration: bigint;
|
|
208
|
+
}> {
|
|
209
|
+
}
|
|
210
|
+
export interface RequirementSignature {
|
|
211
|
+
args: PermitArgs | Permit2Args;
|
|
212
|
+
action: PermitAction | Permit2Action;
|
|
213
|
+
}
|
|
214
|
+
export declare function isRequirementApproval(requirement: Transaction<ERC20ApprovalAction> | Transaction<MorphoAuthorizationAction> | Requirement | undefined): requirement is Transaction<ERC20ApprovalAction>;
|
|
215
|
+
export declare function isRequirementAuthorization(requirement: Transaction<ERC20ApprovalAction> | Transaction<MorphoAuthorizationAction> | Requirement | undefined): requirement is Transaction<MorphoAuthorizationAction>;
|
|
216
|
+
export declare function isRequirementSignature(requirement: Transaction<ERC20ApprovalAction> | Transaction<MorphoAuthorizationAction> | Requirement | undefined): requirement is Requirement;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
export function isRequirementApproval(requirement) {
|
|
2
|
+
return (requirement !== undefined &&
|
|
3
|
+
"to" in requirement &&
|
|
4
|
+
"value" in requirement &&
|
|
5
|
+
"data" in requirement &&
|
|
6
|
+
"action" in requirement &&
|
|
7
|
+
requirement.action.type === "erc20Approval");
|
|
8
|
+
}
|
|
9
|
+
export function isRequirementAuthorization(requirement) {
|
|
10
|
+
return (requirement !== undefined &&
|
|
11
|
+
"to" in requirement &&
|
|
12
|
+
"value" in requirement &&
|
|
13
|
+
"data" in requirement &&
|
|
14
|
+
"action" in requirement &&
|
|
15
|
+
requirement.action.type === "morphoAuthorization");
|
|
16
|
+
}
|
|
17
|
+
export function isRequirementSignature(requirement) {
|
|
18
|
+
return (requirement !== undefined &&
|
|
19
|
+
"sign" in requirement &&
|
|
20
|
+
typeof requirement.sign === "function");
|
|
21
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { MarketParams } from "@morpho-org/blue-sdk";
|
|
2
|
+
import type { Address, Client } from "viem";
|
|
3
|
+
import type { MarketV1Actions, VaultV1Actions, VaultV2Actions } from "../entities/index.js";
|
|
4
|
+
import type { Metadata } from "./index.js";
|
|
5
|
+
/**
|
|
6
|
+
* Structural contract every concrete `MorphoClient` implementation satisfies. Carries the viem
|
|
7
|
+
* client, the resolved options bag, and the three entity-factory methods the SDK exposes.
|
|
8
|
+
*/
|
|
9
|
+
export interface MorphoClientType {
|
|
10
|
+
readonly viemClient: Client;
|
|
11
|
+
readonly options: {
|
|
12
|
+
readonly supportSignature: boolean;
|
|
13
|
+
readonly supportDeployless?: boolean;
|
|
14
|
+
readonly metadata?: Metadata;
|
|
15
|
+
};
|
|
16
|
+
vaultV1: (vault: Address, chainId: number) => VaultV1Actions;
|
|
17
|
+
vaultV2: (vault: Address, chainId: number) => VaultV2Actions;
|
|
18
|
+
marketV1: (marketParams: MarketParams, chainId: number) => MarketV1Actions;
|
|
19
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { MarketParams } from "@morpho-org/blue-sdk";
|
|
2
|
+
import type { Address } from "viem";
|
|
3
|
+
/**
|
|
4
|
+
* A single deallocation entry for a `forceDeallocate` call.
|
|
5
|
+
*
|
|
6
|
+
* - When `marketParams` is provided, the adapter is treated as a Morpho Market V1 adapter
|
|
7
|
+
* and `data` is ABI-encoded from the given `MarketParams`.
|
|
8
|
+
* - When `marketParams` is omitted, empty bytes are passed as `data` (suitable for adapters
|
|
9
|
+
* such as Vault V1 that do not require market identification).
|
|
10
|
+
*/
|
|
11
|
+
export interface Deallocation {
|
|
12
|
+
readonly adapter: Address;
|
|
13
|
+
readonly marketParams?: MarketParams;
|
|
14
|
+
readonly amount: bigint;
|
|
15
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|