@morpho-org/morpho-sdk 1.1.0 → 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 -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 +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 -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
|
@@ -1,276 +1,322 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.NegativeMinSharePriceError = exports.VaultAssetMismatchError = exports.NonPositiveMinBorrowSharePriceError = exports.MissingPublicAllocatorConfigError = exports.RepaySharesExceedDebtError = exports.InvalidSignatureError = exports.RepayExceedsDebtError = exports.ShareDivideByZeroError = exports.WithdrawMakesPositionUnhealthyError = exports.WithdrawExceedsCollateralError = exports.NonPositiveWithdrawCollateralAmountError = exports.NonPositiveRepayMaxSharePriceError = exports.NonPositiveRepayAmountError = exports.MutuallyExclusiveRepayAmountsError = exports.TransferAmountNotEqualToAssetsError = exports.NonPositiveTransferAmountError = exports.UnsortedReallocationWithdrawalsError = exports.ReallocationWithdrawalOnTargetMarketError = exports.NonPositiveReallocationAmountError = exports.EmptyReallocationWithdrawalsError = exports.NegativeReallocationFeeError = exports.AccrualPositionUserMismatchError = exports.MarketIdMismatchError = exports.MissingMarketPriceError = exports.BorrowExceedsSafeLtvError = exports.NativeAmountOnNonWNativeCollateralError = exports.ZeroCollateralAmountError = exports.NonPositiveBorrowAmountError = exports.VaultAddressMismatchError = exports.ZeroDepositAmountError = exports.NegativeNativeAmountError = exports.ChainWNativeMissingError = exports.NativeAmountOnNonWNativeVaultError = exports.DepositAssetMismatchError = exports.DepositAmountMismatchError = exports.EmptyDeallocationsError = exports.ExcessiveSlippageToleranceError = exports.MissingAccrualPositionError = exports.NegativeSlippageToleranceError = exports.ApprovalAmountLessThanSpendAmountError = exports.MissingClientPropertyError = exports.ChainIdMismatchError = exports.AddressMismatchError = exports.NonPositiveMaxSharePriceError = exports.NonPositiveSharesAmountError = exports.NonPositiveAssetAmountError = void 0;
|
|
4
|
+
/** Thrown when an asset amount is required to be positive but is zero or negative. */
|
|
4
5
|
class NonPositiveAssetAmountError extends Error {
|
|
5
6
|
constructor(origin) {
|
|
6
7
|
super(`Asset amount must be positive for address ${origin}`);
|
|
7
8
|
}
|
|
8
9
|
}
|
|
9
10
|
exports.NonPositiveAssetAmountError = NonPositiveAssetAmountError;
|
|
11
|
+
/** Thrown when a shares amount is required to be positive but is zero or negative. */
|
|
10
12
|
class NonPositiveSharesAmountError extends Error {
|
|
11
13
|
constructor(vault) {
|
|
12
14
|
super(`Shares amount must be positive for address: ${vault}`);
|
|
13
15
|
}
|
|
14
16
|
}
|
|
15
17
|
exports.NonPositiveSharesAmountError = NonPositiveSharesAmountError;
|
|
18
|
+
/** Thrown when a vault deposit's `maxSharePrice` slippage bound is zero or negative. */
|
|
16
19
|
class NonPositiveMaxSharePriceError extends Error {
|
|
17
20
|
constructor(vault) {
|
|
18
21
|
super(`Max share price must be positive for vault: ${vault}`);
|
|
19
22
|
}
|
|
20
23
|
}
|
|
21
24
|
exports.NonPositiveMaxSharePriceError = NonPositiveMaxSharePriceError;
|
|
25
|
+
/** Thrown when a viem client's account address does not match the address required by the call. */
|
|
22
26
|
class AddressMismatchError extends Error {
|
|
23
27
|
constructor(clientAddress, argsAddress) {
|
|
24
28
|
super(`Address mismatch between client: ${clientAddress} and args: ${argsAddress}`);
|
|
25
29
|
}
|
|
26
30
|
}
|
|
27
31
|
exports.AddressMismatchError = AddressMismatchError;
|
|
32
|
+
/** Thrown when a viem client's chain id does not match the chain id required by the call. */
|
|
28
33
|
class ChainIdMismatchError extends Error {
|
|
29
34
|
constructor(clientChainId, argsChainId) {
|
|
30
35
|
super(`Chain ID mismatch between client: ${clientChainId} and args: ${argsChainId}`);
|
|
31
36
|
}
|
|
32
37
|
}
|
|
33
38
|
exports.ChainIdMismatchError = ChainIdMismatchError;
|
|
39
|
+
/** Thrown when the viem client is missing a property the call requires (e.g. `account.address`). */
|
|
34
40
|
class MissingClientPropertyError extends Error {
|
|
35
41
|
constructor(property) {
|
|
36
42
|
super(`A required ${property} is missing from the client.`);
|
|
37
43
|
}
|
|
38
44
|
}
|
|
39
45
|
exports.MissingClientPropertyError = MissingClientPropertyError;
|
|
46
|
+
/** Thrown when an approval amount is smaller than the spend amount it must cover. */
|
|
40
47
|
class ApprovalAmountLessThanSpendAmountError extends Error {
|
|
41
48
|
constructor() {
|
|
42
49
|
super("Approval amount is less than spend amount");
|
|
43
50
|
}
|
|
44
51
|
}
|
|
45
52
|
exports.ApprovalAmountLessThanSpendAmountError = ApprovalAmountLessThanSpendAmountError;
|
|
53
|
+
/** Thrown when a slippage tolerance is negative. */
|
|
46
54
|
class NegativeSlippageToleranceError extends Error {
|
|
47
55
|
constructor(slippageTolerance) {
|
|
48
56
|
super(`Slippage tolerance ${slippageTolerance} must not be negative`);
|
|
49
57
|
}
|
|
50
58
|
}
|
|
51
59
|
exports.NegativeSlippageToleranceError = NegativeSlippageToleranceError;
|
|
60
|
+
/** Thrown when a Morpho accrual position is missing for a market the call needs to read. */
|
|
52
61
|
class MissingAccrualPositionError extends Error {
|
|
53
62
|
constructor(market) {
|
|
54
63
|
super(`Accrual position is missing for market: ${market}`);
|
|
55
64
|
}
|
|
56
65
|
}
|
|
57
66
|
exports.MissingAccrualPositionError = MissingAccrualPositionError;
|
|
67
|
+
/** Thrown when a slippage tolerance exceeds `MAX_SLIPPAGE_TOLERANCE` (10%). */
|
|
58
68
|
class ExcessiveSlippageToleranceError extends Error {
|
|
59
69
|
constructor(slippageTolerance) {
|
|
60
70
|
super(`Slippage tolerance ${slippageTolerance} exceeds maximum allowed (10%)`);
|
|
61
71
|
}
|
|
62
72
|
}
|
|
63
73
|
exports.ExcessiveSlippageToleranceError = ExcessiveSlippageToleranceError;
|
|
74
|
+
/** Thrown when a VaultV2 force-withdraw or force-redeem call has no deallocations to perform. */
|
|
64
75
|
class EmptyDeallocationsError extends Error {
|
|
65
76
|
constructor(vault) {
|
|
66
77
|
super(`Deallocations list cannot be empty for vault: ${vault}`);
|
|
67
78
|
}
|
|
68
79
|
}
|
|
69
80
|
exports.EmptyDeallocationsError = EmptyDeallocationsError;
|
|
81
|
+
/** Thrown when a deposit's amount differs from the amount the supplied permit / permit2 signature was issued for. */
|
|
70
82
|
class DepositAmountMismatchError extends Error {
|
|
71
83
|
constructor(depositAmount, signatureAmount) {
|
|
72
84
|
super(`Deposit amount ${depositAmount} does not match requirement signature amount ${signatureAmount}`);
|
|
73
85
|
}
|
|
74
86
|
}
|
|
75
87
|
exports.DepositAmountMismatchError = DepositAmountMismatchError;
|
|
88
|
+
/** Thrown when a deposit's asset differs from the asset the supplied permit / permit2 signature was issued for. */
|
|
76
89
|
class DepositAssetMismatchError extends Error {
|
|
77
90
|
constructor(depositAsset, signatureAsset) {
|
|
78
91
|
super(`Deposit asset ${depositAsset} does not match requirement signature asset ${signatureAsset}`);
|
|
79
92
|
}
|
|
80
93
|
}
|
|
81
94
|
exports.DepositAssetMismatchError = DepositAssetMismatchError;
|
|
95
|
+
/** Thrown when a vault deposit uses `nativeAmount` but the vault asset is not the chain's wNative. */
|
|
82
96
|
class NativeAmountOnNonWNativeVaultError extends Error {
|
|
83
97
|
constructor(vaultAsset, wNative) {
|
|
84
98
|
super(`Cannot use nativeAmount: vault asset ${vaultAsset} is not the wrapped native token ${wNative}`);
|
|
85
99
|
}
|
|
86
100
|
}
|
|
87
101
|
exports.NativeAmountOnNonWNativeVaultError = NativeAmountOnNonWNativeVaultError;
|
|
102
|
+
/** Thrown when a `nativeAmount` is supplied but the chain has no configured wNative address. */
|
|
88
103
|
class ChainWNativeMissingError extends Error {
|
|
89
104
|
constructor(chainId) {
|
|
90
105
|
super(`Chain ${chainId} does not have a configured wrapped native token (wNative)`);
|
|
91
106
|
}
|
|
92
107
|
}
|
|
93
108
|
exports.ChainWNativeMissingError = ChainWNativeMissingError;
|
|
109
|
+
/** Thrown when `nativeAmount` is negative. */
|
|
94
110
|
class NegativeNativeAmountError extends Error {
|
|
95
111
|
constructor(nativeAmount) {
|
|
96
112
|
super(`Native amount must not be negative, got ${nativeAmount}`);
|
|
97
113
|
}
|
|
98
114
|
}
|
|
99
115
|
exports.NegativeNativeAmountError = NegativeNativeAmountError;
|
|
116
|
+
/** Thrown when both `amount` and `nativeAmount` resolve to zero on a vault deposit. */
|
|
100
117
|
class ZeroDepositAmountError extends Error {
|
|
101
118
|
constructor(vault) {
|
|
102
119
|
super(`Total deposit amount must be positive for vault: ${vault}. Both amount and nativeAmount are zero.`);
|
|
103
120
|
}
|
|
104
121
|
}
|
|
105
122
|
exports.ZeroDepositAmountError = ZeroDepositAmountError;
|
|
123
|
+
/** Thrown when a vault entity's address does not match the vault address embedded in the call's args. */
|
|
106
124
|
class VaultAddressMismatchError extends Error {
|
|
107
125
|
constructor(vaultAddress, argsVaultAddress) {
|
|
108
126
|
super(`Vault address mismatch between vault: ${vaultAddress} and args: ${argsVaultAddress}`);
|
|
109
127
|
}
|
|
110
128
|
}
|
|
111
129
|
exports.VaultAddressMismatchError = VaultAddressMismatchError;
|
|
130
|
+
/** Thrown when a market borrow amount is zero or negative. */
|
|
112
131
|
class NonPositiveBorrowAmountError extends Error {
|
|
113
132
|
constructor(market) {
|
|
114
133
|
super(`Borrow amount must be positive for market: ${market}`);
|
|
115
134
|
}
|
|
116
135
|
}
|
|
117
136
|
exports.NonPositiveBorrowAmountError = NonPositiveBorrowAmountError;
|
|
137
|
+
/** Thrown when both `amount` and `nativeAmount` resolve to zero on a market collateral supply. */
|
|
118
138
|
class ZeroCollateralAmountError extends Error {
|
|
119
139
|
constructor(market) {
|
|
120
140
|
super(`Total collateral amount must be positive for market: ${market}. Both amount and nativeAmount are zero.`);
|
|
121
141
|
}
|
|
122
142
|
}
|
|
123
143
|
exports.ZeroCollateralAmountError = ZeroCollateralAmountError;
|
|
144
|
+
/** Thrown when a collateral supply uses `nativeAmount` but the collateral token is not the chain's wNative. */
|
|
124
145
|
class NativeAmountOnNonWNativeCollateralError extends Error {
|
|
125
146
|
constructor(collateralToken, wNative) {
|
|
126
147
|
super(`Cannot use nativeAmount: collateral token ${collateralToken} is not the wrapped native token ${wNative}`);
|
|
127
148
|
}
|
|
128
149
|
}
|
|
129
150
|
exports.NativeAmountOnNonWNativeCollateralError = NativeAmountOnNonWNativeCollateralError;
|
|
151
|
+
/** Thrown when a borrow exceeds the LLTV-buffered safe maximum for the position. */
|
|
130
152
|
class BorrowExceedsSafeLtvError extends Error {
|
|
131
153
|
constructor(borrowAmount, maxSafeBorrow) {
|
|
132
154
|
super(`Borrow amount ${borrowAmount} exceeds safe maximum ${maxSafeBorrow} (LLTV minus buffer). Reduce borrow or increase collateral.`);
|
|
133
155
|
}
|
|
134
156
|
}
|
|
135
157
|
exports.BorrowExceedsSafeLtvError = BorrowExceedsSafeLtvError;
|
|
158
|
+
/** Thrown when the market's oracle price is unavailable and position health cannot be validated. */
|
|
136
159
|
class MissingMarketPriceError extends Error {
|
|
137
160
|
constructor(market) {
|
|
138
161
|
super(`Oracle price unavailable for market ${market}. Cannot validate position health.`);
|
|
139
162
|
}
|
|
140
163
|
}
|
|
141
164
|
exports.MissingMarketPriceError = MissingMarketPriceError;
|
|
165
|
+
/** Thrown when a `MarketParams.id` does not match the expected market id derived from the other fields. */
|
|
142
166
|
class MarketIdMismatchError extends Error {
|
|
143
167
|
constructor(marketId, expectedMarketId) {
|
|
144
168
|
super(`Market ${marketId} does not match expected market ${expectedMarketId}`);
|
|
145
169
|
}
|
|
146
170
|
}
|
|
147
171
|
exports.MarketIdMismatchError = MarketIdMismatchError;
|
|
172
|
+
/** Thrown when an accrual position belongs to a different user than the one expected by the call. */
|
|
148
173
|
class AccrualPositionUserMismatchError extends Error {
|
|
149
174
|
constructor(positionUser, expectedUser) {
|
|
150
175
|
super(`Accrual position user ${positionUser} does not match expected user ${expectedUser}`);
|
|
151
176
|
}
|
|
152
177
|
}
|
|
153
178
|
exports.AccrualPositionUserMismatchError = AccrualPositionUserMismatchError;
|
|
179
|
+
/** Thrown when a reallocation's fee is negative. */
|
|
154
180
|
class NegativeReallocationFeeError extends Error {
|
|
155
181
|
constructor(vault) {
|
|
156
182
|
super(`Reallocation fee must not be negative for vault: ${vault}`);
|
|
157
183
|
}
|
|
158
184
|
}
|
|
159
185
|
exports.NegativeReallocationFeeError = NegativeReallocationFeeError;
|
|
186
|
+
/** Thrown when a reallocation has no withdrawals. */
|
|
160
187
|
class EmptyReallocationWithdrawalsError extends Error {
|
|
161
188
|
constructor(vault) {
|
|
162
189
|
super(`Reallocation withdrawals list cannot be empty for vault: ${vault}`);
|
|
163
190
|
}
|
|
164
191
|
}
|
|
165
192
|
exports.EmptyReallocationWithdrawalsError = EmptyReallocationWithdrawalsError;
|
|
193
|
+
/** Thrown when a reallocation withdrawal amount is zero or negative. */
|
|
166
194
|
class NonPositiveReallocationAmountError extends Error {
|
|
167
195
|
constructor(vault, market) {
|
|
168
196
|
super(`Reallocation withdrawal amount must be positive for vault ${vault} on market ${market}`);
|
|
169
197
|
}
|
|
170
198
|
}
|
|
171
199
|
exports.NonPositiveReallocationAmountError = NonPositiveReallocationAmountError;
|
|
200
|
+
/** Thrown when a reallocation withdrawal references the borrow target market (which would be a no-op or self-deal). */
|
|
172
201
|
class ReallocationWithdrawalOnTargetMarketError extends Error {
|
|
173
202
|
constructor(vault, marketId) {
|
|
174
203
|
super(`Reallocation withdrawal cannot include the borrow target market ${marketId} for vault ${vault}.`);
|
|
175
204
|
}
|
|
176
205
|
}
|
|
177
206
|
exports.ReallocationWithdrawalOnTargetMarketError = ReallocationWithdrawalOnTargetMarketError;
|
|
207
|
+
/** Thrown when reallocation withdrawals within a vault are not strictly sorted by market id. */
|
|
178
208
|
class UnsortedReallocationWithdrawalsError extends Error {
|
|
179
209
|
constructor(vault, marketId) {
|
|
180
210
|
super(`Reallocation withdrawals must be strictly sorted by market ID for vault ${vault}. Market ${marketId} is out of order.`);
|
|
181
211
|
}
|
|
182
212
|
}
|
|
183
213
|
exports.UnsortedReallocationWithdrawalsError = UnsortedReallocationWithdrawalsError;
|
|
214
|
+
/** Thrown when a market repay's `transferAmount` is zero or negative. */
|
|
184
215
|
class NonPositiveTransferAmountError extends Error {
|
|
185
216
|
constructor(market) {
|
|
186
217
|
super(`Transfer amount must be positive for market: ${market}`);
|
|
187
218
|
}
|
|
188
219
|
}
|
|
189
220
|
exports.NonPositiveTransferAmountError = NonPositiveTransferAmountError;
|
|
221
|
+
/** Thrown when a market repay in assets mode has `transferAmount !== assets` (asset-mode requires exact transfer). */
|
|
190
222
|
class TransferAmountNotEqualToAssetsError extends Error {
|
|
191
223
|
constructor(params) {
|
|
192
224
|
super(`Transfer amount ${params.transferAmount} is not equal to repay assets ${params.assets} for market: ${params.market}`);
|
|
193
225
|
}
|
|
194
226
|
}
|
|
195
227
|
exports.TransferAmountNotEqualToAssetsError = TransferAmountNotEqualToAssetsError;
|
|
228
|
+
/** Thrown when a market repay specifies both `assets` and `shares` as non-zero (modes are mutually exclusive). */
|
|
196
229
|
class MutuallyExclusiveRepayAmountsError extends Error {
|
|
197
230
|
constructor(market) {
|
|
198
231
|
super(`Exactly one of assets or shares must be non-zero for market: ${market}. Both were provided.`);
|
|
199
232
|
}
|
|
200
233
|
}
|
|
201
234
|
exports.MutuallyExclusiveRepayAmountsError = MutuallyExclusiveRepayAmountsError;
|
|
235
|
+
/** Thrown when a market repay has non-positive amounts: both `assets` and `shares` are zero, or either is negative. */
|
|
202
236
|
class NonPositiveRepayAmountError extends Error {
|
|
203
237
|
constructor(market) {
|
|
204
238
|
super(`Repay amount must be positive for market: ${market}`);
|
|
205
239
|
}
|
|
206
240
|
}
|
|
207
241
|
exports.NonPositiveRepayAmountError = NonPositiveRepayAmountError;
|
|
242
|
+
/** Thrown when a market repay's `maxSharePrice` slippage bound is zero or negative. */
|
|
208
243
|
class NonPositiveRepayMaxSharePriceError extends Error {
|
|
209
244
|
constructor(market) {
|
|
210
245
|
super(`Max share price must be positive for market: ${market}`);
|
|
211
246
|
}
|
|
212
247
|
}
|
|
213
248
|
exports.NonPositiveRepayMaxSharePriceError = NonPositiveRepayMaxSharePriceError;
|
|
249
|
+
/** Thrown when a market `withdrawCollateral` amount is zero or negative. */
|
|
214
250
|
class NonPositiveWithdrawCollateralAmountError extends Error {
|
|
215
251
|
constructor(market) {
|
|
216
252
|
super(`Withdraw collateral amount must be positive for market: ${market}`);
|
|
217
253
|
}
|
|
218
254
|
}
|
|
219
255
|
exports.NonPositiveWithdrawCollateralAmountError = NonPositiveWithdrawCollateralAmountError;
|
|
256
|
+
/** Thrown when a withdraw amount exceeds the position's available collateral. */
|
|
220
257
|
class WithdrawExceedsCollateralError extends Error {
|
|
221
258
|
constructor(params) {
|
|
222
259
|
super(`Withdraw amount ${params.withdrawAmount} exceeds available collateral ${params.available} for market: ${params.market}`);
|
|
223
260
|
}
|
|
224
261
|
}
|
|
225
262
|
exports.WithdrawExceedsCollateralError = WithdrawExceedsCollateralError;
|
|
263
|
+
/** Thrown when a collateral withdrawal would leave the borrower's position above the LLTV-buffered safe maximum. */
|
|
226
264
|
class WithdrawMakesPositionUnhealthyError extends Error {
|
|
227
265
|
constructor(params) {
|
|
228
266
|
super(`Withdrawing ${params.withdrawAmount} collateral would make position unhealthy. Max safe borrow after withdrawal: ${params.maxSafeBorrow}. Actual Borrow assets: ${params.borrowAssets}.`);
|
|
229
267
|
}
|
|
230
268
|
}
|
|
231
269
|
exports.WithdrawMakesPositionUnhealthyError = WithdrawMakesPositionUnhealthyError;
|
|
270
|
+
/** Thrown when a share-amount conversion would divide by zero (the market has no shares of the relevant kind). */
|
|
232
271
|
class ShareDivideByZeroError extends Error {
|
|
233
272
|
constructor(market) {
|
|
234
273
|
super(`Share divide by zero error for market: ${market}`);
|
|
235
274
|
}
|
|
236
275
|
}
|
|
237
276
|
exports.ShareDivideByZeroError = ShareDivideByZeroError;
|
|
277
|
+
/** Thrown when a repay amount in assets exceeds the borrower's outstanding debt. */
|
|
238
278
|
class RepayExceedsDebtError extends Error {
|
|
239
279
|
constructor(params) {
|
|
240
280
|
super(`Repay amount ${params.repayAmount} exceeds outstanding debt ${params.debt} for market: ${params.market}`);
|
|
241
281
|
}
|
|
242
282
|
}
|
|
243
283
|
exports.RepayExceedsDebtError = RepayExceedsDebtError;
|
|
284
|
+
/** Thrown when EIP-712 signature verification fails (the signed data does not match the expected signer). */
|
|
244
285
|
class InvalidSignatureError extends Error {
|
|
245
286
|
constructor() {
|
|
246
287
|
super("Signature verification failed: the signed data does not match the expected signer address");
|
|
247
288
|
}
|
|
248
289
|
}
|
|
249
290
|
exports.InvalidSignatureError = InvalidSignatureError;
|
|
291
|
+
/** Thrown when a repay in shares mode supplies more shares than the borrower owes. */
|
|
250
292
|
class RepaySharesExceedDebtError extends Error {
|
|
251
293
|
constructor(params) {
|
|
252
294
|
super(`Repay shares ${params.repayShares} exceed outstanding borrow shares ${params.borrowShares} for market: ${params.market}`);
|
|
253
295
|
}
|
|
254
296
|
}
|
|
255
297
|
exports.RepaySharesExceedDebtError = RepaySharesExceedDebtError;
|
|
298
|
+
/** Thrown when a vault selected for reallocation has no configured `PublicAllocator`. */
|
|
256
299
|
class MissingPublicAllocatorConfigError extends Error {
|
|
257
300
|
constructor(vault) {
|
|
258
301
|
super(`Vault ${vault} has no public allocator configured but was selected for reallocation`);
|
|
259
302
|
}
|
|
260
303
|
}
|
|
261
304
|
exports.MissingPublicAllocatorConfigError = MissingPublicAllocatorConfigError;
|
|
305
|
+
/** Thrown when a market borrow's `minSharePrice` slippage bound is negative. */
|
|
262
306
|
class NonPositiveMinBorrowSharePriceError extends Error {
|
|
263
307
|
constructor(market) {
|
|
264
308
|
super(`Min share price must be non-negative for market: ${market}`);
|
|
265
309
|
}
|
|
266
310
|
}
|
|
267
311
|
exports.NonPositiveMinBorrowSharePriceError = NonPositiveMinBorrowSharePriceError;
|
|
312
|
+
/** Thrown when a vault migration's source vault asset differs from the target vault asset. */
|
|
268
313
|
class VaultAssetMismatchError extends Error {
|
|
269
314
|
constructor(sourceAsset, targetAsset) {
|
|
270
315
|
super(`Source vault asset ${sourceAsset} does not match target vault asset ${targetAsset}`);
|
|
271
316
|
}
|
|
272
317
|
}
|
|
273
318
|
exports.VaultAssetMismatchError = VaultAssetMismatchError;
|
|
319
|
+
/** Thrown when a vault redeem's `minSharePrice` slippage bound is negative. */
|
|
274
320
|
class NegativeMinSharePriceError extends Error {
|
|
275
321
|
constructor(vault) {
|
|
276
322
|
super(`Min share price must be non-negative for vault: ${vault}`);
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./action.js"), exports);
|
|
18
|
+
__exportStar(require("./client.js"), exports);
|
|
19
|
+
__exportStar(require("./deallocation.js"), exports);
|
|
20
|
+
__exportStar(require("./entity.js"), exports);
|
|
21
|
+
__exportStar(require("./error.js"), exports);
|
|
22
|
+
__exportStar(require("./metadata.js"), exports);
|
|
23
|
+
__exportStar(require("./sharedLiquidity.js"), exports);
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import type { MarketParams } from "@morpho-org/blue-sdk";
|
|
2
|
+
import type { Address } from "viem";
|
|
3
|
+
import { type MarketV1BorrowAction, type Metadata, type Transaction, type VaultReallocation } from "../../types/index.js";
|
|
4
|
+
/** Parameters for {@link marketV1Borrow}. */
|
|
5
|
+
export interface MarketV1BorrowParams {
|
|
6
|
+
market: {
|
|
7
|
+
readonly chainId: number;
|
|
8
|
+
readonly marketParams: MarketParams;
|
|
9
|
+
};
|
|
10
|
+
args: {
|
|
11
|
+
amount: bigint;
|
|
12
|
+
receiver: Address;
|
|
13
|
+
/** Minimum borrow share price (in ray). Protects against share price manipulation. */
|
|
14
|
+
minSharePrice: bigint;
|
|
15
|
+
/** Vault reallocations to execute before borrowing (computed by entity). */
|
|
16
|
+
reallocations?: readonly VaultReallocation[];
|
|
17
|
+
};
|
|
18
|
+
metadata?: Metadata;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Prepares a borrow transaction for a Morpho Blue market.
|
|
22
|
+
*
|
|
23
|
+
* Routed through bundler3 via `morphoBorrow`. The bundler uses the transaction initiator as
|
|
24
|
+
* `onBehalf`. Uses `minSharePrice` to protect against share price manipulation between
|
|
25
|
+
* transaction construction and execution.
|
|
26
|
+
*
|
|
27
|
+
* When `reallocations` are provided, `reallocateTo` actions are prepended to the bundle, moving
|
|
28
|
+
* liquidity from other markets via the PublicAllocator before borrowing. Reallocation fees
|
|
29
|
+
* accumulate in `tx.value`.
|
|
30
|
+
*
|
|
31
|
+
* @param params.market.chainId - The chain the market lives on.
|
|
32
|
+
* @param params.market.marketParams - Market params (loanToken, collateralToken, oracle, irm, lltv).
|
|
33
|
+
* @param params.args.amount - Loan asset amount to borrow, in the loan token's smallest unit.
|
|
34
|
+
* @param params.args.receiver - Address that receives the borrowed assets.
|
|
35
|
+
* @param params.args.minSharePrice - Minimum borrow share price (in ray). Slippage protection.
|
|
36
|
+
* @param params.args.reallocations - Optional vault reallocations to execute before borrowing,
|
|
37
|
+
* computed by the entity layer.
|
|
38
|
+
* @param params.metadata - Optional analytics metadata attached to the bundle.
|
|
39
|
+
* @returns A deep-frozen `Transaction<MarketV1BorrowAction>` with `to`, `value`, `data`, and the
|
|
40
|
+
* typed `action` discriminator the simulation layer consumes.
|
|
41
|
+
* @throws {NonPositiveBorrowAmountError} when `amount <= 0n`.
|
|
42
|
+
* @throws {NonPositiveMinBorrowSharePriceError} when `minSharePrice < 0n` (negative; zero is
|
|
43
|
+
* allowed despite the class name).
|
|
44
|
+
* @throws {NegativeReallocationFeeError} from `buildReallocationActions` when
|
|
45
|
+
* `reallocations` is non-empty and any `reallocation.fee < 0n`.
|
|
46
|
+
* @throws {EmptyReallocationWithdrawalsError} from `buildReallocationActions` when any
|
|
47
|
+
* `reallocation.withdrawals` is empty.
|
|
48
|
+
* @throws {NonPositiveReallocationAmountError} from `buildReallocationActions` when any
|
|
49
|
+
* `reallocation.withdrawals[i].amount <= 0n`.
|
|
50
|
+
* @throws {ReallocationWithdrawalOnTargetMarketError} from `buildReallocationActions` when any
|
|
51
|
+
* reallocation withdrawal references the target market.
|
|
52
|
+
* @throws {UnsortedReallocationWithdrawalsError} from `buildReallocationActions` when
|
|
53
|
+
* reallocation withdrawals are not strictly sorted by market id.
|
|
54
|
+
* @example
|
|
55
|
+
* ```ts
|
|
56
|
+
* import { marketV1Borrow } from "@morpho-org/morpho-sdk";
|
|
57
|
+
*
|
|
58
|
+
* const tx = marketV1Borrow({
|
|
59
|
+
* market: { chainId: 1, marketParams },
|
|
60
|
+
* args: {
|
|
61
|
+
* amount: 1_000_000n,
|
|
62
|
+
* receiver: borrower,
|
|
63
|
+
* minSharePrice: 0n, // disables slippage protection — production code should compute via `computeMinBorrowSharePrice` from market state + slippage tolerance
|
|
64
|
+
* },
|
|
65
|
+
* });
|
|
66
|
+
* // tx satisfies Readonly<Transaction<MarketV1BorrowAction>>
|
|
67
|
+
* ```
|
|
68
|
+
*/
|
|
69
|
+
export declare const marketV1Borrow: ({ market: { chainId, marketParams }, args: { amount, receiver, minSharePrice, reallocations }, metadata, }: MarketV1BorrowParams) => Readonly<Transaction<MarketV1BorrowAction>>;
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
import { BundlerAction } from "@morpho-org/bundler-sdk-viem";
|
|
2
|
+
import { deepFreeze } from "@morpho-org/morpho-ts";
|
|
3
|
+
import { addTransactionMetadata } from "../../helpers/index.js";
|
|
4
|
+
import { NonPositiveBorrowAmountError, NonPositiveMinBorrowSharePriceError, } from "../../types/index.js";
|
|
5
|
+
import { buildReallocationActions } from "./buildReallocationActions.js";
|
|
6
|
+
/**
|
|
7
|
+
* Prepares a borrow transaction for a Morpho Blue market.
|
|
8
|
+
*
|
|
9
|
+
* Routed through bundler3 via `morphoBorrow`. The bundler uses the transaction initiator as
|
|
10
|
+
* `onBehalf`. Uses `minSharePrice` to protect against share price manipulation between
|
|
11
|
+
* transaction construction and execution.
|
|
12
|
+
*
|
|
13
|
+
* When `reallocations` are provided, `reallocateTo` actions are prepended to the bundle, moving
|
|
14
|
+
* liquidity from other markets via the PublicAllocator before borrowing. Reallocation fees
|
|
15
|
+
* accumulate in `tx.value`.
|
|
16
|
+
*
|
|
17
|
+
* @param params.market.chainId - The chain the market lives on.
|
|
18
|
+
* @param params.market.marketParams - Market params (loanToken, collateralToken, oracle, irm, lltv).
|
|
19
|
+
* @param params.args.amount - Loan asset amount to borrow, in the loan token's smallest unit.
|
|
20
|
+
* @param params.args.receiver - Address that receives the borrowed assets.
|
|
21
|
+
* @param params.args.minSharePrice - Minimum borrow share price (in ray). Slippage protection.
|
|
22
|
+
* @param params.args.reallocations - Optional vault reallocations to execute before borrowing,
|
|
23
|
+
* computed by the entity layer.
|
|
24
|
+
* @param params.metadata - Optional analytics metadata attached to the bundle.
|
|
25
|
+
* @returns A deep-frozen `Transaction<MarketV1BorrowAction>` with `to`, `value`, `data`, and the
|
|
26
|
+
* typed `action` discriminator the simulation layer consumes.
|
|
27
|
+
* @throws {NonPositiveBorrowAmountError} when `amount <= 0n`.
|
|
28
|
+
* @throws {NonPositiveMinBorrowSharePriceError} when `minSharePrice < 0n` (negative; zero is
|
|
29
|
+
* allowed despite the class name).
|
|
30
|
+
* @throws {NegativeReallocationFeeError} from `buildReallocationActions` when
|
|
31
|
+
* `reallocations` is non-empty and any `reallocation.fee < 0n`.
|
|
32
|
+
* @throws {EmptyReallocationWithdrawalsError} from `buildReallocationActions` when any
|
|
33
|
+
* `reallocation.withdrawals` is empty.
|
|
34
|
+
* @throws {NonPositiveReallocationAmountError} from `buildReallocationActions` when any
|
|
35
|
+
* `reallocation.withdrawals[i].amount <= 0n`.
|
|
36
|
+
* @throws {ReallocationWithdrawalOnTargetMarketError} from `buildReallocationActions` when any
|
|
37
|
+
* reallocation withdrawal references the target market.
|
|
38
|
+
* @throws {UnsortedReallocationWithdrawalsError} from `buildReallocationActions` when
|
|
39
|
+
* reallocation withdrawals are not strictly sorted by market id.
|
|
40
|
+
* @example
|
|
41
|
+
* ```ts
|
|
42
|
+
* import { marketV1Borrow } from "@morpho-org/morpho-sdk";
|
|
43
|
+
*
|
|
44
|
+
* const tx = marketV1Borrow({
|
|
45
|
+
* market: { chainId: 1, marketParams },
|
|
46
|
+
* args: {
|
|
47
|
+
* amount: 1_000_000n,
|
|
48
|
+
* receiver: borrower,
|
|
49
|
+
* minSharePrice: 0n, // disables slippage protection — production code should compute via `computeMinBorrowSharePrice` from market state + slippage tolerance
|
|
50
|
+
* },
|
|
51
|
+
* });
|
|
52
|
+
* // tx satisfies Readonly<Transaction<MarketV1BorrowAction>>
|
|
53
|
+
* ```
|
|
54
|
+
*/
|
|
55
|
+
export const marketV1Borrow = ({ market: { chainId, marketParams }, args: { amount, receiver, minSharePrice, reallocations }, metadata, }) => {
|
|
56
|
+
if (amount <= 0n) {
|
|
57
|
+
throw new NonPositiveBorrowAmountError(marketParams.id);
|
|
58
|
+
}
|
|
59
|
+
if (minSharePrice < 0n) {
|
|
60
|
+
throw new NonPositiveMinBorrowSharePriceError(marketParams.id);
|
|
61
|
+
}
|
|
62
|
+
const actions = [];
|
|
63
|
+
let reallocationFee = 0n;
|
|
64
|
+
if (reallocations && reallocations.length > 0) {
|
|
65
|
+
const result = buildReallocationActions(reallocations, marketParams);
|
|
66
|
+
actions.push(...result.actions);
|
|
67
|
+
reallocationFee = result.fee;
|
|
68
|
+
}
|
|
69
|
+
actions.push({
|
|
70
|
+
type: "morphoBorrow",
|
|
71
|
+
args: [marketParams, amount, 0n, minSharePrice, receiver, false],
|
|
72
|
+
});
|
|
73
|
+
let tx = {
|
|
74
|
+
...BundlerAction.encodeBundle(chainId, actions),
|
|
75
|
+
value: reallocationFee,
|
|
76
|
+
};
|
|
77
|
+
if (metadata) {
|
|
78
|
+
tx = addTransactionMetadata(tx, metadata);
|
|
79
|
+
}
|
|
80
|
+
return deepFreeze({
|
|
81
|
+
...tx,
|
|
82
|
+
action: {
|
|
83
|
+
type: "marketV1Borrow",
|
|
84
|
+
args: {
|
|
85
|
+
market: marketParams.id,
|
|
86
|
+
amount,
|
|
87
|
+
receiver,
|
|
88
|
+
minSharePrice,
|
|
89
|
+
reallocationFee,
|
|
90
|
+
},
|
|
91
|
+
},
|
|
92
|
+
});
|
|
93
|
+
};
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import type { MarketParams } from "@morpho-org/blue-sdk";
|
|
2
|
+
import type { Action } from "@morpho-org/bundler-sdk-viem";
|
|
3
|
+
import type { VaultReallocation } from "../../types/index.js";
|
|
4
|
+
/**
|
|
5
|
+
* Builds reallocation bundler actions and computes the total fee.
|
|
6
|
+
*
|
|
7
|
+
* Validates the reallocations, then encodes each as a `reallocateTo` action against the target
|
|
8
|
+
* market. Returns `{ actions: [], fee: 0n }` for an empty input — callers gate on
|
|
9
|
+
* `reallocations.length > 0` and skip the call entirely in that case. Internal helper —
|
|
10
|
+
* consumed only by `marketV1Borrow` and `marketV1SupplyCollateralBorrow`; not re-exported on the
|
|
11
|
+
* public surface.
|
|
12
|
+
*
|
|
13
|
+
* @param reallocations - The vault reallocations to encode.
|
|
14
|
+
* @param targetMarketParams - The target market params the freed liquidity is destined for.
|
|
15
|
+
* @returns The encoded `reallocateTo` actions and the summed reallocation fee (in native, used
|
|
16
|
+
* as `tx.value` in the parent bundle).
|
|
17
|
+
* @throws {NegativeReallocationFeeError} when any reallocation fee is negative.
|
|
18
|
+
* @throws {EmptyReallocationWithdrawalsError} when any reallocation has no withdrawals.
|
|
19
|
+
* @throws {NonPositiveReallocationAmountError} when any withdrawal amount is non-positive.
|
|
20
|
+
* @throws {ReallocationWithdrawalOnTargetMarketError} when a withdrawal references the target market.
|
|
21
|
+
* @throws {UnsortedReallocationWithdrawalsError} when withdrawals within a reallocation are not
|
|
22
|
+
* strictly sorted by market id.
|
|
23
|
+
* @internal
|
|
24
|
+
*/
|
|
25
|
+
export declare const buildReallocationActions: (reallocations: readonly VaultReallocation[], targetMarketParams: MarketParams) => {
|
|
26
|
+
readonly actions: Action[];
|
|
27
|
+
readonly fee: bigint;
|
|
28
|
+
};
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { validateReallocations } from "../../helpers/index.js";
|
|
2
|
+
/**
|
|
3
|
+
* Builds reallocation bundler actions and computes the total fee.
|
|
4
|
+
*
|
|
5
|
+
* Validates the reallocations, then encodes each as a `reallocateTo` action against the target
|
|
6
|
+
* market. Returns `{ actions: [], fee: 0n }` for an empty input — callers gate on
|
|
7
|
+
* `reallocations.length > 0` and skip the call entirely in that case. Internal helper —
|
|
8
|
+
* consumed only by `marketV1Borrow` and `marketV1SupplyCollateralBorrow`; not re-exported on the
|
|
9
|
+
* public surface.
|
|
10
|
+
*
|
|
11
|
+
* @param reallocations - The vault reallocations to encode.
|
|
12
|
+
* @param targetMarketParams - The target market params the freed liquidity is destined for.
|
|
13
|
+
* @returns The encoded `reallocateTo` actions and the summed reallocation fee (in native, used
|
|
14
|
+
* as `tx.value` in the parent bundle).
|
|
15
|
+
* @throws {NegativeReallocationFeeError} when any reallocation fee is negative.
|
|
16
|
+
* @throws {EmptyReallocationWithdrawalsError} when any reallocation has no withdrawals.
|
|
17
|
+
* @throws {NonPositiveReallocationAmountError} when any withdrawal amount is non-positive.
|
|
18
|
+
* @throws {ReallocationWithdrawalOnTargetMarketError} when a withdrawal references the target market.
|
|
19
|
+
* @throws {UnsortedReallocationWithdrawalsError} when withdrawals within a reallocation are not
|
|
20
|
+
* strictly sorted by market id.
|
|
21
|
+
* @internal
|
|
22
|
+
*/
|
|
23
|
+
export const buildReallocationActions = (reallocations, targetMarketParams) => {
|
|
24
|
+
validateReallocations(reallocations, targetMarketParams.id);
|
|
25
|
+
const fee = reallocations.reduce((sum, r) => sum + r.fee, 0n);
|
|
26
|
+
const actions = [];
|
|
27
|
+
for (const r of reallocations) {
|
|
28
|
+
actions.push({
|
|
29
|
+
type: "reallocateTo",
|
|
30
|
+
args: [
|
|
31
|
+
r.vault,
|
|
32
|
+
r.fee,
|
|
33
|
+
r.withdrawals.map((w) => ({
|
|
34
|
+
marketParams: w.marketParams,
|
|
35
|
+
amount: w.amount,
|
|
36
|
+
})),
|
|
37
|
+
targetMarketParams,
|
|
38
|
+
false,
|
|
39
|
+
],
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
return { actions, fee };
|
|
43
|
+
};
|