@morpho-org/morpho-sdk 5.2.0 → 5.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +46 -2
- package/lib/cjs/abis.d.ts +1 -0
- package/lib/cjs/abis.js +6 -1
- package/lib/cjs/actions/blue/borrow.d.ts +3 -7
- package/lib/cjs/actions/blue/borrow.js +5 -9
- package/lib/cjs/actions/blue/buildReallocationActions.d.ts +3 -4
- package/lib/cjs/actions/blue/buildReallocationActions.js +3 -4
- package/lib/cjs/actions/blue/refinance.d.ts +4 -8
- package/lib/cjs/actions/blue/refinance.js +10 -14
- package/lib/cjs/actions/blue/repay.d.ts +2 -5
- package/lib/cjs/actions/blue/repay.js +2 -5
- package/lib/cjs/actions/blue/repayWithdrawCollateral.d.ts +3 -6
- package/lib/cjs/actions/blue/repayWithdrawCollateral.js +4 -7
- package/lib/cjs/actions/blue/resolveRepayFunding.d.ts +2 -5
- package/lib/cjs/actions/blue/resolveRepayFunding.js +15 -12
- package/lib/cjs/actions/blue/supply.d.ts +2 -4
- package/lib/cjs/actions/blue/supply.js +6 -8
- package/lib/cjs/actions/blue/supplyCollateral.d.ts +2 -3
- package/lib/cjs/actions/blue/supplyCollateral.js +5 -6
- package/lib/cjs/actions/blue/supplyCollateralBorrow.d.ts +4 -9
- package/lib/cjs/actions/blue/supplyCollateralBorrow.js +9 -14
- package/lib/cjs/actions/blue/withdraw.d.ts +9 -7
- package/lib/cjs/actions/blue/withdraw.js +18 -10
- package/lib/cjs/actions/blue/withdrawCollateral.d.ts +1 -1
- package/lib/cjs/actions/blue/withdrawCollateral.js +2 -2
- package/lib/cjs/actions/index.d.ts +2 -0
- package/lib/cjs/actions/index.js +1 -0
- package/lib/cjs/actions/midnight/authorization.d.ts +37 -0
- package/lib/cjs/actions/midnight/authorization.js +69 -0
- package/lib/cjs/actions/midnight/cancelOffer.d.ts +38 -0
- package/lib/cjs/actions/midnight/cancelOffer.js +73 -0
- package/lib/cjs/actions/midnight/index.d.ts +11 -0
- package/lib/cjs/actions/midnight/index.js +27 -0
- package/lib/cjs/actions/midnight/mempoolSubmitOffers.d.ts +52 -0
- package/lib/cjs/actions/midnight/mempoolSubmitOffers.js +72 -0
- package/lib/cjs/actions/midnight/redeem.d.ts +43 -0
- package/lib/cjs/actions/midnight/redeem.js +79 -0
- package/lib/cjs/actions/midnight/repayWithdrawCollateral.d.ts +53 -0
- package/lib/cjs/actions/midnight/repayWithdrawCollateral.js +121 -0
- package/lib/cjs/actions/midnight/setterRatifierRatifyRoot.d.ts +40 -0
- package/lib/cjs/actions/midnight/setterRatifierRatifyRoot.js +59 -0
- package/lib/cjs/actions/midnight/supplyCollateral.d.ts +45 -0
- package/lib/cjs/actions/midnight/supplyCollateral.js +83 -0
- package/lib/cjs/actions/midnight/supplyCollateralTakeBorrow.d.ts +51 -0
- package/lib/cjs/actions/midnight/supplyCollateralTakeBorrow.js +128 -0
- package/lib/cjs/actions/midnight/takeBorrow.d.ts +57 -0
- package/lib/cjs/actions/midnight/takeBorrow.js +110 -0
- package/lib/cjs/actions/midnight/takeLend.d.ts +57 -0
- package/lib/cjs/actions/midnight/takeLend.js +110 -0
- package/lib/cjs/actions/midnight/types.d.ts +39 -0
- package/lib/cjs/actions/midnight/types.js +15 -0
- package/lib/cjs/actions/requirements/encode/encodeBlueSignatureAuthorization.d.ts +1 -1
- package/lib/cjs/actions/requirements/encode/encodeBlueSignatureAuthorization.js +5 -16
- package/lib/cjs/actions/requirements/encode/encodeErc20Approval.d.ts +5 -4
- package/lib/cjs/actions/requirements/encode/encodeErc20Approval.js +10 -14
- package/lib/cjs/actions/requirements/encode/encodeErc20Permit.d.ts +2 -2
- package/lib/cjs/actions/requirements/encode/encodeErc20Permit.js +11 -28
- package/lib/cjs/actions/requirements/encode/encodeErc20Permit2Approve.d.ts +1 -1
- package/lib/cjs/actions/requirements/encode/encodeErc20Permit2Approve.js +5 -17
- package/lib/cjs/actions/requirements/generalAdapter/getGeneralAdapterRequirementsPermit.d.ts +1 -1
- package/lib/cjs/actions/requirements/getRequirementsApproval.d.ts +10 -4
- package/lib/cjs/actions/requirements/getRequirementsApproval.js +10 -4
- package/lib/cjs/actions/requirements/index.d.ts +1 -0
- package/lib/cjs/actions/requirements/index.js +1 -0
- package/lib/cjs/actions/requirements/midnight/getMidnightApprovalRequirements.d.ts +49 -0
- package/lib/cjs/actions/requirements/midnight/getMidnightApprovalRequirements.js +76 -0
- package/lib/cjs/actions/requirements/midnight/getMidnightAuthorizationRequirement.d.ts +44 -0
- package/lib/cjs/actions/requirements/midnight/getMidnightAuthorizationRequirement.js +78 -0
- package/lib/cjs/actions/requirements/midnight/getSetterRatifierRatifyRootRequirement.d.ts +42 -0
- package/lib/cjs/actions/requirements/midnight/getSetterRatifierRatifyRootRequirement.js +70 -0
- package/lib/cjs/actions/requirements/midnight/index.d.ts +3 -0
- package/lib/cjs/actions/requirements/midnight/index.js +19 -0
- package/lib/cjs/actions/vaultV1/deposit.d.ts +3 -4
- package/lib/cjs/actions/vaultV1/deposit.js +7 -8
- package/lib/cjs/actions/vaultV1/migrateToV2.d.ts +2 -3
- package/lib/cjs/actions/vaultV1/migrateToV2.js +5 -6
- package/lib/cjs/actions/vaultV1/redeem.d.ts +1 -1
- package/lib/cjs/actions/vaultV1/redeem.js +2 -2
- package/lib/cjs/actions/vaultV1/withdraw.d.ts +1 -1
- package/lib/cjs/actions/vaultV1/withdraw.js +2 -2
- package/lib/cjs/actions/vaultV2/deposit.d.ts +3 -4
- package/lib/cjs/actions/vaultV2/deposit.js +7 -8
- package/lib/cjs/actions/vaultV2/forceRedeem.d.ts +2 -3
- package/lib/cjs/actions/vaultV2/forceRedeem.js +3 -4
- package/lib/cjs/actions/vaultV2/forceWithdraw.d.ts +1 -1
- package/lib/cjs/actions/vaultV2/forceWithdraw.js +2 -2
- package/lib/cjs/actions/vaultV2/redeem.d.ts +1 -1
- package/lib/cjs/actions/vaultV2/redeem.js +2 -2
- package/lib/cjs/actions/vaultV2/withdraw.d.ts +1 -1
- package/lib/cjs/actions/vaultV2/withdraw.js +2 -2
- package/lib/cjs/client/morphoViemExtension.d.ts +1 -1
- package/lib/cjs/client/morphoViemExtension.js +5 -2
- package/lib/cjs/constants.d.ts +1 -0
- package/lib/cjs/constants.js +15 -1
- package/lib/cjs/entities/blue/blue.d.ts +5 -5
- package/lib/cjs/entities/blue/blue.js +99 -80
- package/lib/cjs/entities/index.d.ts +1 -0
- package/lib/cjs/entities/index.js +15 -0
- package/lib/cjs/entities/midnight/index.d.ts +2 -0
- package/lib/cjs/entities/midnight/index.js +18 -0
- package/lib/cjs/entities/midnight/midnight.d.ts +402 -0
- package/lib/cjs/entities/midnight/midnight.js +1036 -0
- package/lib/cjs/entities/midnight/types.d.ts +164 -0
- package/lib/cjs/entities/midnight/types.js +2 -0
- package/lib/cjs/entities/vaultV1/vaultV1.js +10 -17
- package/lib/cjs/entities/vaultV2/vaultV2.js +19 -21
- package/lib/cjs/errors.d.ts +1 -0
- package/lib/cjs/errors.js +17 -1
- package/lib/cjs/helpers/encodeDeallocation.d.ts +1 -0
- package/lib/cjs/helpers/encodeDeallocation.js +2 -1
- package/lib/cjs/helpers/index.d.ts +4 -1
- package/lib/cjs/helpers/index.js +8 -1
- package/lib/cjs/helpers/signAndVerifyTypedData.d.ts +34 -0
- package/lib/cjs/helpers/signAndVerifyTypedData.js +58 -0
- package/lib/cjs/helpers/validate.d.ts +40 -1
- package/lib/cjs/helpers/validate.js +47 -5
- package/lib/cjs/helpers/validateMidnightAuthorizationTarget.d.ts +15 -0
- package/lib/cjs/helpers/validateMidnightAuthorizationTarget.js +32 -0
- package/lib/cjs/helpers/validateMidnightMarket.d.ts +10 -0
- package/lib/cjs/helpers/validateMidnightMarket.js +24 -0
- package/lib/cjs/helpers/validateOfferSides.d.ts +21 -0
- package/lib/cjs/helpers/validateOfferSides.js +36 -0
- package/lib/cjs/helpers/validateRequirementSpender.d.ts +29 -0
- package/lib/cjs/helpers/validateRequirementSpender.js +49 -0
- package/lib/cjs/helpers/validateTakeableOffers.d.ts +18 -0
- package/lib/cjs/helpers/validateTakeableOffers.js +35 -0
- package/lib/cjs/midnight-api.d.ts +1 -0
- package/lib/cjs/midnight-api.js +17 -0
- package/lib/cjs/types/action.d.ts +189 -23
- package/lib/cjs/types/action.js +27 -7
- package/lib/cjs/types/client.d.ts +3 -2
- package/lib/cjs/types/error.d.ts +288 -119
- package/lib/cjs/types/error.js +259 -180
- package/lib/cjs/utils.d.ts +1 -0
- package/lib/cjs/utils.js +12 -2
- package/lib/esm/abis.d.ts +1 -0
- package/lib/esm/abis.js +1 -0
- package/lib/esm/actions/blue/borrow.d.ts +3 -7
- package/lib/esm/actions/blue/borrow.js +6 -10
- package/lib/esm/actions/blue/buildReallocationActions.d.ts +3 -4
- package/lib/esm/actions/blue/buildReallocationActions.js +3 -4
- package/lib/esm/actions/blue/refinance.d.ts +4 -8
- package/lib/esm/actions/blue/refinance.js +11 -15
- package/lib/esm/actions/blue/repay.d.ts +2 -5
- package/lib/esm/actions/blue/repay.js +2 -5
- package/lib/esm/actions/blue/repayWithdrawCollateral.d.ts +3 -6
- package/lib/esm/actions/blue/repayWithdrawCollateral.js +5 -8
- package/lib/esm/actions/blue/resolveRepayFunding.d.ts +2 -5
- package/lib/esm/actions/blue/resolveRepayFunding.js +16 -13
- package/lib/esm/actions/blue/supply.d.ts +2 -4
- package/lib/esm/actions/blue/supply.js +7 -9
- package/lib/esm/actions/blue/supplyCollateral.d.ts +2 -3
- package/lib/esm/actions/blue/supplyCollateral.js +6 -7
- package/lib/esm/actions/blue/supplyCollateralBorrow.d.ts +4 -9
- package/lib/esm/actions/blue/supplyCollateralBorrow.js +10 -15
- package/lib/esm/actions/blue/withdraw.d.ts +9 -7
- package/lib/esm/actions/blue/withdraw.js +19 -11
- package/lib/esm/actions/blue/withdrawCollateral.d.ts +1 -1
- package/lib/esm/actions/blue/withdrawCollateral.js +3 -3
- package/lib/esm/actions/index.d.ts +2 -0
- package/lib/esm/actions/index.js +1 -0
- package/lib/esm/actions/midnight/authorization.d.ts +37 -0
- package/lib/esm/actions/midnight/authorization.js +65 -0
- package/lib/esm/actions/midnight/cancelOffer.d.ts +38 -0
- package/lib/esm/actions/midnight/cancelOffer.js +69 -0
- package/lib/esm/actions/midnight/index.d.ts +11 -0
- package/lib/esm/actions/midnight/index.js +11 -0
- package/lib/esm/actions/midnight/mempoolSubmitOffers.d.ts +52 -0
- package/lib/esm/actions/midnight/mempoolSubmitOffers.js +68 -0
- package/lib/esm/actions/midnight/redeem.d.ts +43 -0
- package/lib/esm/actions/midnight/redeem.js +75 -0
- package/lib/esm/actions/midnight/repayWithdrawCollateral.d.ts +53 -0
- package/lib/esm/actions/midnight/repayWithdrawCollateral.js +117 -0
- package/lib/esm/actions/midnight/setterRatifierRatifyRoot.d.ts +40 -0
- package/lib/esm/actions/midnight/setterRatifierRatifyRoot.js +55 -0
- package/lib/esm/actions/midnight/supplyCollateral.d.ts +45 -0
- package/lib/esm/actions/midnight/supplyCollateral.js +79 -0
- package/lib/esm/actions/midnight/supplyCollateralTakeBorrow.d.ts +51 -0
- package/lib/esm/actions/midnight/supplyCollateralTakeBorrow.js +124 -0
- package/lib/esm/actions/midnight/takeBorrow.d.ts +57 -0
- package/lib/esm/actions/midnight/takeBorrow.js +106 -0
- package/lib/esm/actions/midnight/takeLend.d.ts +57 -0
- package/lib/esm/actions/midnight/takeLend.js +106 -0
- package/lib/esm/actions/midnight/types.d.ts +39 -0
- package/lib/esm/actions/midnight/types.js +12 -0
- package/lib/esm/actions/requirements/encode/encodeBlueSignatureAuthorization.d.ts +1 -1
- package/lib/esm/actions/requirements/encode/encodeBlueSignatureAuthorization.js +6 -17
- package/lib/esm/actions/requirements/encode/encodeErc20Approval.d.ts +5 -4
- package/lib/esm/actions/requirements/encode/encodeErc20Approval.js +12 -16
- package/lib/esm/actions/requirements/encode/encodeErc20Permit.d.ts +2 -2
- package/lib/esm/actions/requirements/encode/encodeErc20Permit.js +12 -29
- package/lib/esm/actions/requirements/encode/encodeErc20Permit2Approve.d.ts +1 -1
- package/lib/esm/actions/requirements/encode/encodeErc20Permit2Approve.js +5 -17
- package/lib/esm/actions/requirements/generalAdapter/getGeneralAdapterRequirementsPermit.d.ts +1 -1
- package/lib/esm/actions/requirements/getRequirementsApproval.d.ts +10 -4
- package/lib/esm/actions/requirements/getRequirementsApproval.js +10 -4
- package/lib/esm/actions/requirements/index.d.ts +1 -0
- package/lib/esm/actions/requirements/index.js +1 -0
- package/lib/esm/actions/requirements/midnight/getMidnightApprovalRequirements.d.ts +49 -0
- package/lib/esm/actions/requirements/midnight/getMidnightApprovalRequirements.js +72 -0
- package/lib/esm/actions/requirements/midnight/getMidnightAuthorizationRequirement.d.ts +44 -0
- package/lib/esm/actions/requirements/midnight/getMidnightAuthorizationRequirement.js +74 -0
- package/lib/esm/actions/requirements/midnight/getSetterRatifierRatifyRootRequirement.d.ts +42 -0
- package/lib/esm/actions/requirements/midnight/getSetterRatifierRatifyRootRequirement.js +66 -0
- package/lib/esm/actions/requirements/midnight/index.d.ts +3 -0
- package/lib/esm/actions/requirements/midnight/index.js +3 -0
- package/lib/esm/actions/vaultV1/deposit.d.ts +3 -4
- package/lib/esm/actions/vaultV1/deposit.js +8 -9
- package/lib/esm/actions/vaultV1/migrateToV2.d.ts +2 -3
- package/lib/esm/actions/vaultV1/migrateToV2.js +6 -7
- package/lib/esm/actions/vaultV1/redeem.d.ts +1 -1
- package/lib/esm/actions/vaultV1/redeem.js +3 -3
- package/lib/esm/actions/vaultV1/withdraw.d.ts +1 -1
- package/lib/esm/actions/vaultV1/withdraw.js +3 -3
- package/lib/esm/actions/vaultV2/deposit.d.ts +3 -4
- package/lib/esm/actions/vaultV2/deposit.js +8 -9
- package/lib/esm/actions/vaultV2/forceRedeem.d.ts +2 -3
- package/lib/esm/actions/vaultV2/forceRedeem.js +4 -5
- package/lib/esm/actions/vaultV2/forceWithdraw.d.ts +1 -1
- package/lib/esm/actions/vaultV2/forceWithdraw.js +3 -3
- package/lib/esm/actions/vaultV2/redeem.d.ts +1 -1
- package/lib/esm/actions/vaultV2/redeem.js +3 -3
- package/lib/esm/actions/vaultV2/withdraw.d.ts +1 -1
- package/lib/esm/actions/vaultV2/withdraw.js +3 -3
- package/lib/esm/client/morphoViemExtension.d.ts +1 -1
- package/lib/esm/client/morphoViemExtension.js +6 -3
- package/lib/esm/constants.d.ts +1 -0
- package/lib/esm/constants.js +1 -0
- package/lib/esm/entities/blue/blue.d.ts +5 -5
- package/lib/esm/entities/blue/blue.js +101 -82
- package/lib/esm/entities/index.d.ts +1 -0
- package/lib/esm/entities/index.js +1 -0
- package/lib/esm/entities/midnight/index.d.ts +2 -0
- package/lib/esm/entities/midnight/index.js +2 -0
- package/lib/esm/entities/midnight/midnight.d.ts +402 -0
- package/lib/esm/entities/midnight/midnight.js +1032 -0
- package/lib/esm/entities/midnight/types.d.ts +164 -0
- package/lib/esm/entities/midnight/types.js +1 -0
- package/lib/esm/entities/vaultV1/vaultV1.js +13 -20
- package/lib/esm/entities/vaultV2/vaultV2.js +9 -11
- package/lib/esm/errors.d.ts +1 -0
- package/lib/esm/errors.js +1 -0
- package/lib/esm/helpers/encodeDeallocation.d.ts +1 -0
- package/lib/esm/helpers/encodeDeallocation.js +3 -2
- package/lib/esm/helpers/index.d.ts +4 -1
- package/lib/esm/helpers/index.js +4 -1
- package/lib/esm/helpers/signAndVerifyTypedData.d.ts +34 -0
- package/lib/esm/helpers/signAndVerifyTypedData.js +54 -0
- package/lib/esm/helpers/validate.d.ts +40 -1
- package/lib/esm/helpers/validate.js +46 -5
- package/lib/esm/helpers/validateMidnightAuthorizationTarget.d.ts +15 -0
- package/lib/esm/helpers/validateMidnightAuthorizationTarget.js +28 -0
- package/lib/esm/helpers/validateMidnightMarket.d.ts +10 -0
- package/lib/esm/helpers/validateMidnightMarket.js +20 -0
- package/lib/esm/helpers/validateOfferSides.d.ts +21 -0
- package/lib/esm/helpers/validateOfferSides.js +32 -0
- package/lib/esm/helpers/validateRequirementSpender.d.ts +29 -0
- package/lib/esm/helpers/validateRequirementSpender.js +45 -0
- package/lib/esm/helpers/validateTakeableOffers.d.ts +18 -0
- package/lib/esm/helpers/validateTakeableOffers.js +31 -0
- package/lib/esm/midnight-api.d.ts +1 -0
- package/lib/esm/midnight-api.js +1 -0
- package/lib/esm/types/action.d.ts +189 -23
- package/lib/esm/types/action.js +26 -7
- package/lib/esm/types/client.d.ts +3 -2
- package/lib/esm/types/error.d.ts +288 -119
- package/lib/esm/types/error.js +232 -154
- package/lib/esm/utils.d.ts +1 -0
- package/lib/esm/utils.js +1 -0
- package/package.json +11 -2
package/lib/esm/abis.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
export { marketParamsAbi } from "@morpho-org/blue-sdk";
|
|
2
2
|
export { adaptiveCurveIrmAbi, blueAbi, blueOracleAbi, erc2612Abi, erc5267Abi, metaMorphoAbi, metaMorphoFactoryAbi, morphoMarketV1AdapterAbi, morphoMarketV1AdapterFactoryAbi, morphoMarketV1AdapterV2Abi, morphoMarketV1AdapterV2FactoryAbi, morphoVaultV1AdapterAbi, morphoVaultV1AdapterFactoryAbi, permissionedErc20WrapperAbi, permit2Abi, preLiquidationAbi, preLiquidationFactoryAbi, publicAllocatorAbi, vaultV1AdapterAbi, vaultV1AdapterFactoryAbi, vaultV2Abi, vaultV2FactoryAbi, whitelistControllerAggregatorV2Abi, wrappedBackedTokenAbi, wstEthAbi, } from "@morpho-org/blue-sdk-viem";
|
|
3
|
+
export { ecrecoverRatifierAbi, midnightAbi, midnightBundlesAbi, setterRatifierAbi, } from "@morpho-org/midnight-sdk";
|
|
3
4
|
/** ABI for the Bundler3 multicall contract. */
|
|
4
5
|
export declare const bundler3Abi: readonly [{
|
|
5
6
|
readonly type: "function";
|
package/lib/esm/abis.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
export { marketParamsAbi } from "@morpho-org/blue-sdk";
|
|
2
2
|
export { adaptiveCurveIrmAbi, blueAbi, blueOracleAbi, erc2612Abi, erc5267Abi, metaMorphoAbi, metaMorphoFactoryAbi, morphoMarketV1AdapterAbi, morphoMarketV1AdapterFactoryAbi, morphoMarketV1AdapterV2Abi, morphoMarketV1AdapterV2FactoryAbi, morphoVaultV1AdapterAbi, morphoVaultV1AdapterFactoryAbi, permissionedErc20WrapperAbi, permit2Abi, preLiquidationAbi, preLiquidationFactoryAbi, publicAllocatorAbi, vaultV1AdapterAbi, vaultV1AdapterFactoryAbi, vaultV2Abi, vaultV2FactoryAbi, whitelistControllerAggregatorV2Abi, wrappedBackedTokenAbi, wstEthAbi, } from "@morpho-org/blue-sdk-viem";
|
|
3
|
+
export { ecrecoverRatifierAbi, midnightAbi, midnightBundlesAbi, setterRatifierAbi, } from "@morpho-org/midnight-sdk";
|
|
3
4
|
/** ABI for the Bundler3 multicall contract. */
|
|
4
5
|
export const bundler3Abi = [
|
|
5
6
|
{
|
|
@@ -48,15 +48,11 @@ export interface BlueBorrowParams {
|
|
|
48
48
|
* @param params.metadata - Optional analytics metadata attached to the bundle.
|
|
49
49
|
* @returns A deep-frozen `Transaction<BlueBorrowAction>` with `to`, `value`, `data`, and the
|
|
50
50
|
* typed `action` discriminator the simulation layer consumes.
|
|
51
|
-
* @throws {
|
|
52
|
-
*
|
|
53
|
-
*
|
|
54
|
-
* @throws {NegativeReallocationFeeError} from `buildReallocationActions` when
|
|
55
|
-
* `reallocations` is non-empty and any `reallocation.fee < 0n`.
|
|
51
|
+
* @throws {NonPositiveInputError} when `amount <= 0n` or any reallocation withdrawal amount
|
|
52
|
+
* is non-positive.
|
|
53
|
+
* @throws {NegativeInputError} when `minSharePrice < 0n` or any reallocation fee is negative.
|
|
56
54
|
* @throws {EmptyReallocationWithdrawalsError} from `buildReallocationActions` when any
|
|
57
55
|
* `reallocation.withdrawals` is empty.
|
|
58
|
-
* @throws {NonPositiveReallocationAmountError} from `buildReallocationActions` when any
|
|
59
|
-
* `reallocation.withdrawals[i].amount <= 0n`.
|
|
60
56
|
* @throws {ReallocationWithdrawalOnTargetMarketError} from `buildReallocationActions` when any
|
|
61
57
|
* reallocation withdrawal references the target market.
|
|
62
58
|
* @throws {UnsortedReallocationWithdrawalsError} from `buildReallocationActions` when
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { deepFreeze } from "@morpho-org/morpho-ts";
|
|
2
2
|
import { BundlerAction } from "../../bundler/index.js";
|
|
3
3
|
import { addTransactionMetadata } from "../../helpers/index.js";
|
|
4
|
-
import {
|
|
4
|
+
import { NegativeInputError, NonPositiveInputError, } from "../../types/index.js";
|
|
5
5
|
import { getBlueAuthorizationAction } from "../signatures/getBlueAuthorizationAction.js";
|
|
6
6
|
import { buildReallocationActions } from "./buildReallocationActions.js";
|
|
7
7
|
/**
|
|
@@ -27,15 +27,11 @@ import { buildReallocationActions } from "./buildReallocationActions.js";
|
|
|
27
27
|
* @param params.metadata - Optional analytics metadata attached to the bundle.
|
|
28
28
|
* @returns A deep-frozen `Transaction<BlueBorrowAction>` with `to`, `value`, `data`, and the
|
|
29
29
|
* typed `action` discriminator the simulation layer consumes.
|
|
30
|
-
* @throws {
|
|
31
|
-
*
|
|
32
|
-
*
|
|
33
|
-
* @throws {NegativeReallocationFeeError} from `buildReallocationActions` when
|
|
34
|
-
* `reallocations` is non-empty and any `reallocation.fee < 0n`.
|
|
30
|
+
* @throws {NonPositiveInputError} when `amount <= 0n` or any reallocation withdrawal amount
|
|
31
|
+
* is non-positive.
|
|
32
|
+
* @throws {NegativeInputError} when `minSharePrice < 0n` or any reallocation fee is negative.
|
|
35
33
|
* @throws {EmptyReallocationWithdrawalsError} from `buildReallocationActions` when any
|
|
36
34
|
* `reallocation.withdrawals` is empty.
|
|
37
|
-
* @throws {NonPositiveReallocationAmountError} from `buildReallocationActions` when any
|
|
38
|
-
* `reallocation.withdrawals[i].amount <= 0n`.
|
|
39
35
|
* @throws {ReallocationWithdrawalOnTargetMarketError} from `buildReallocationActions` when any
|
|
40
36
|
* reallocation withdrawal references the target market.
|
|
41
37
|
* @throws {UnsortedReallocationWithdrawalsError} from `buildReallocationActions` when
|
|
@@ -57,10 +53,10 @@ import { buildReallocationActions } from "./buildReallocationActions.js";
|
|
|
57
53
|
*/
|
|
58
54
|
export const blueBorrow = ({ market: { chainId, marketParams }, args: { amount, receiver, minSharePrice, reallocations, authorizationSignature, }, metadata, }) => {
|
|
59
55
|
if (amount <= 0n) {
|
|
60
|
-
throw new
|
|
56
|
+
throw new NonPositiveInputError("amount", amount);
|
|
61
57
|
}
|
|
62
58
|
if (minSharePrice < 0n) {
|
|
63
|
-
throw new
|
|
59
|
+
throw new NegativeInputError("minSharePrice", minSharePrice);
|
|
64
60
|
}
|
|
65
61
|
const actions = [];
|
|
66
62
|
let reallocationFee = 0n;
|
|
@@ -7,15 +7,14 @@ import type { VaultReallocation } from "../../types/index.js";
|
|
|
7
7
|
* Validates the reallocations, then encodes each as a `reallocateTo` action against the target
|
|
8
8
|
* market. Returns `{ actions: [], fee: 0n }` for an empty input — callers gate on
|
|
9
9
|
* `reallocations.length > 0` and skip the call entirely in that case. Internal helper —
|
|
10
|
-
* consumed
|
|
11
|
-
* public surface.
|
|
10
|
+
* consumed by the Blue actions that accept reallocations; not re-exported on the public surface.
|
|
12
11
|
*
|
|
13
12
|
* @param reallocations - The vault reallocations to encode.
|
|
14
13
|
* @param targetMarketParams - The target market params the freed liquidity is destined for.
|
|
15
14
|
* @returns The encoded `reallocateTo` actions and the summed reallocation fee in native tokens.
|
|
16
|
-
* @throws {
|
|
15
|
+
* @throws {NegativeInputError} when any reallocation fee is negative.
|
|
17
16
|
* @throws {EmptyReallocationWithdrawalsError} when any reallocation has no withdrawals.
|
|
18
|
-
* @throws {
|
|
17
|
+
* @throws {NonPositiveInputError} when any withdrawal amount is non-positive.
|
|
19
18
|
* @throws {ReallocationWithdrawalOnTargetMarketError} when a withdrawal references the target market.
|
|
20
19
|
* @throws {UnsortedReallocationWithdrawalsError} when withdrawals within a reallocation are not
|
|
21
20
|
* strictly sorted by market id.
|
|
@@ -5,15 +5,14 @@ import { validateReallocations } from "../../helpers/index.js";
|
|
|
5
5
|
* Validates the reallocations, then encodes each as a `reallocateTo` action against the target
|
|
6
6
|
* market. Returns `{ actions: [], fee: 0n }` for an empty input — callers gate on
|
|
7
7
|
* `reallocations.length > 0` and skip the call entirely in that case. Internal helper —
|
|
8
|
-
* consumed
|
|
9
|
-
* public surface.
|
|
8
|
+
* consumed by the Blue actions that accept reallocations; not re-exported on the public surface.
|
|
10
9
|
*
|
|
11
10
|
* @param reallocations - The vault reallocations to encode.
|
|
12
11
|
* @param targetMarketParams - The target market params the freed liquidity is destined for.
|
|
13
12
|
* @returns The encoded `reallocateTo` actions and the summed reallocation fee in native tokens.
|
|
14
|
-
* @throws {
|
|
13
|
+
* @throws {NegativeInputError} when any reallocation fee is negative.
|
|
15
14
|
* @throws {EmptyReallocationWithdrawalsError} when any reallocation has no withdrawals.
|
|
16
|
-
* @throws {
|
|
15
|
+
* @throws {NonPositiveInputError} when any withdrawal amount is non-positive.
|
|
17
16
|
* @throws {ReallocationWithdrawalOnTargetMarketError} when a withdrawal references the target market.
|
|
18
17
|
* @throws {UnsortedReallocationWithdrawalsError} when withdrawals within a reallocation are not
|
|
19
18
|
* strictly sorted by market id.
|
|
@@ -91,18 +91,14 @@ export interface BlueRefinanceParams {
|
|
|
91
91
|
* @returns A deep-frozen `Transaction<BlueRefinanceAction>`.
|
|
92
92
|
* @remarks `borrowAssets` and `borrowShares` describe different markets (target borrow vs. source
|
|
93
93
|
* repay); in shares mode the entity passes both. Caller-facing mutual exclusivity is enforced at the entity layer.
|
|
94
|
-
* @throws {
|
|
95
|
-
*
|
|
96
|
-
* @throws {
|
|
97
|
-
*
|
|
98
|
-
* @throws {NegativeMaxRepaySharePriceError} when `maxRepaySharePrice < 0n`.
|
|
94
|
+
* @throws {NonPositiveInputError} when `collateralAmount <= 0n`, a repay leg has a non-positive
|
|
95
|
+
* `maxRepaySharePrice`, or any reallocation withdrawal amount is non-positive.
|
|
96
|
+
* @throws {NegativeInputError} when `borrowAssets`, `borrowShares`, `minBorrowSharePrice`,
|
|
97
|
+
* `maxRepaySharePrice`, or any reallocation fee is negative.
|
|
99
98
|
* @throws {RefinanceSameMarketError} when source and target market ids are equal.
|
|
100
99
|
* @throws {RefinanceTokenMismatchError} when source and target do not share both tokens.
|
|
101
100
|
* @throws {RefinanceSharesMissingBorrowAssetsError} when `borrowShares > 0n` but `borrowAssets` is omitted or non-positive.
|
|
102
|
-
* @throws {NonPositiveRepayMaxSharePriceError} when a repay leg is encoded and `maxRepaySharePrice <= 0n`.
|
|
103
|
-
* @throws {NegativeReallocationFeeError} when any `reallocation.fee < 0n`.
|
|
104
101
|
* @throws {EmptyReallocationWithdrawalsError} when any `reallocation.withdrawals` is empty.
|
|
105
|
-
* @throws {NonPositiveReallocationAmountError} when any `reallocation.withdrawals[i].amount <= 0n`.
|
|
106
102
|
* @throws {ReallocationWithdrawalOnTargetMarketError} when a reallocation withdrawal references the target market.
|
|
107
103
|
* @throws {UnsortedReallocationWithdrawalsError} when reallocation withdrawals are not strictly sorted by market id.
|
|
108
104
|
* @example
|
|
@@ -3,7 +3,7 @@ import { deepFreeze } from "@morpho-org/morpho-ts";
|
|
|
3
3
|
import { isAddressEqual, maxUint256 } from "viem";
|
|
4
4
|
import { BundlerAction } from "../../bundler/index.js";
|
|
5
5
|
import { addTransactionMetadata } from "../../helpers/index.js";
|
|
6
|
-
import {
|
|
6
|
+
import { NegativeInputError, NonPositiveInputError, RefinanceSameMarketError, RefinanceSharesMissingBorrowAssetsError, RefinanceTokenMismatchError, } from "../../types/index.js";
|
|
7
7
|
import { getBlueAuthorizationAction } from "../signatures/getBlueAuthorizationAction.js";
|
|
8
8
|
import { buildReallocationActions } from "./buildReallocationActions.js";
|
|
9
9
|
/**
|
|
@@ -59,18 +59,14 @@ import { buildReallocationActions } from "./buildReallocationActions.js";
|
|
|
59
59
|
* @returns A deep-frozen `Transaction<BlueRefinanceAction>`.
|
|
60
60
|
* @remarks `borrowAssets` and `borrowShares` describe different markets (target borrow vs. source
|
|
61
61
|
* repay); in shares mode the entity passes both. Caller-facing mutual exclusivity is enforced at the entity layer.
|
|
62
|
-
* @throws {
|
|
63
|
-
*
|
|
64
|
-
* @throws {
|
|
65
|
-
*
|
|
66
|
-
* @throws {NegativeMaxRepaySharePriceError} when `maxRepaySharePrice < 0n`.
|
|
62
|
+
* @throws {NonPositiveInputError} when `collateralAmount <= 0n`, a repay leg has a non-positive
|
|
63
|
+
* `maxRepaySharePrice`, or any reallocation withdrawal amount is non-positive.
|
|
64
|
+
* @throws {NegativeInputError} when `borrowAssets`, `borrowShares`, `minBorrowSharePrice`,
|
|
65
|
+
* `maxRepaySharePrice`, or any reallocation fee is negative.
|
|
67
66
|
* @throws {RefinanceSameMarketError} when source and target market ids are equal.
|
|
68
67
|
* @throws {RefinanceTokenMismatchError} when source and target do not share both tokens.
|
|
69
68
|
* @throws {RefinanceSharesMissingBorrowAssetsError} when `borrowShares > 0n` but `borrowAssets` is omitted or non-positive.
|
|
70
|
-
* @throws {NonPositiveRepayMaxSharePriceError} when a repay leg is encoded and `maxRepaySharePrice <= 0n`.
|
|
71
|
-
* @throws {NegativeReallocationFeeError} when any `reallocation.fee < 0n`.
|
|
72
69
|
* @throws {EmptyReallocationWithdrawalsError} when any `reallocation.withdrawals` is empty.
|
|
73
|
-
* @throws {NonPositiveReallocationAmountError} when any `reallocation.withdrawals[i].amount <= 0n`.
|
|
74
70
|
* @throws {ReallocationWithdrawalOnTargetMarketError} when a reallocation withdrawal references the target market.
|
|
75
71
|
* @throws {UnsortedReallocationWithdrawalsError} when reallocation withdrawals are not strictly sorted by market id.
|
|
76
72
|
* @example
|
|
@@ -94,19 +90,19 @@ import { buildReallocationActions } from "./buildReallocationActions.js";
|
|
|
94
90
|
*/
|
|
95
91
|
export const blueRefinance = ({ source: { chainId, marketParams: sourceParams }, target: { marketParams: targetParams }, args: { user, collateralAmount, borrowAssets = 0n, borrowShares = 0n, minBorrowSharePrice, maxRepaySharePrice, targetReallocations, authorizationSignature, }, metadata, }) => {
|
|
96
92
|
if (collateralAmount <= 0n) {
|
|
97
|
-
throw new
|
|
93
|
+
throw new NonPositiveInputError("collateralAmount", collateralAmount);
|
|
98
94
|
}
|
|
99
95
|
if (borrowAssets < 0n) {
|
|
100
|
-
throw new
|
|
96
|
+
throw new NegativeInputError("borrowAssets", borrowAssets);
|
|
101
97
|
}
|
|
102
98
|
if (borrowShares < 0n) {
|
|
103
|
-
throw new
|
|
99
|
+
throw new NegativeInputError("borrowShares", borrowShares);
|
|
104
100
|
}
|
|
105
101
|
if (minBorrowSharePrice < 0n) {
|
|
106
|
-
throw new
|
|
102
|
+
throw new NegativeInputError("minBorrowSharePrice", minBorrowSharePrice);
|
|
107
103
|
}
|
|
108
104
|
if (maxRepaySharePrice < 0n) {
|
|
109
|
-
throw new
|
|
105
|
+
throw new NegativeInputError("maxRepaySharePrice", maxRepaySharePrice);
|
|
110
106
|
}
|
|
111
107
|
if (sourceParams.id === targetParams.id) {
|
|
112
108
|
throw new RefinanceSameMarketError(sourceParams.id);
|
|
@@ -124,7 +120,7 @@ export const blueRefinance = ({ source: { chainId, marketParams: sourceParams },
|
|
|
124
120
|
}
|
|
125
121
|
// A repay leg with maxRepaySharePrice = 0n always reverts; require a positive cap when debt is migrated.
|
|
126
122
|
if (shouldMigrateBorrow && maxRepaySharePrice <= 0n) {
|
|
127
|
-
throw new
|
|
123
|
+
throw new NonPositiveInputError("maxRepaySharePrice", maxRepaySharePrice);
|
|
128
124
|
}
|
|
129
125
|
const callback = [];
|
|
130
126
|
if (shouldMigrateBorrow) {
|
|
@@ -53,14 +53,11 @@ export interface BlueRepayParams {
|
|
|
53
53
|
* @param params.metadata - Optional analytics metadata attached to the bundle.
|
|
54
54
|
* @returns A deep-frozen `Transaction<BlueRepayAction>` with `to`, `value` (= `nativeAmount`),
|
|
55
55
|
* `data`, and the typed `action` discriminator the simulation layer consumes.
|
|
56
|
-
* @throws {
|
|
57
|
-
* @throws {
|
|
56
|
+
* @throws {NonPositiveInputError} when `maxSharePrice <= 0n` or the total funding is zero.
|
|
57
|
+
* @throws {NegativeInputError} when `amount`, `shares`, `nativeAmount`, or `transferAmount` is negative.
|
|
58
58
|
* @throws {MutuallyExclusiveRepayAmountsError} when both `amount` and `shares` are `> 0n`.
|
|
59
59
|
* @throws {TransferAmountNotEqualToAssetsError} when in assets mode and
|
|
60
60
|
* `transferAmount !== amount + nativeAmount`.
|
|
61
|
-
* @throws {NonPositiveRepayAmountError} when `amount` or `shares` is negative, when in assets mode
|
|
62
|
-
* and `transferAmount <= 0n`, or when in shares mode and `transferAmount` is negative or the total
|
|
63
|
-
* funding (`transferAmount + nativeAmount`) is `<= 0n`.
|
|
64
61
|
* @throws {ChainWNativeMissingError} when `nativeAmount > 0n` but the chain has no configured wNative.
|
|
65
62
|
* @throws {NativeAmountOnNonWNativeAssetError} when `nativeAmount > 0n` but the loan token is not
|
|
66
63
|
* the chain's wNative.
|
|
@@ -39,14 +39,11 @@ import { resolveRepayFunding } from "./resolveRepayFunding.js";
|
|
|
39
39
|
* @param params.metadata - Optional analytics metadata attached to the bundle.
|
|
40
40
|
* @returns A deep-frozen `Transaction<BlueRepayAction>` with `to`, `value` (= `nativeAmount`),
|
|
41
41
|
* `data`, and the typed `action` discriminator the simulation layer consumes.
|
|
42
|
-
* @throws {
|
|
43
|
-
* @throws {
|
|
42
|
+
* @throws {NonPositiveInputError} when `maxSharePrice <= 0n` or the total funding is zero.
|
|
43
|
+
* @throws {NegativeInputError} when `amount`, `shares`, `nativeAmount`, or `transferAmount` is negative.
|
|
44
44
|
* @throws {MutuallyExclusiveRepayAmountsError} when both `amount` and `shares` are `> 0n`.
|
|
45
45
|
* @throws {TransferAmountNotEqualToAssetsError} when in assets mode and
|
|
46
46
|
* `transferAmount !== amount + nativeAmount`.
|
|
47
|
-
* @throws {NonPositiveRepayAmountError} when `amount` or `shares` is negative, when in assets mode
|
|
48
|
-
* and `transferAmount <= 0n`, or when in shares mode and `transferAmount` is negative or the total
|
|
49
|
-
* funding (`transferAmount + nativeAmount`) is `<= 0n`.
|
|
50
47
|
* @throws {ChainWNativeMissingError} when `nativeAmount > 0n` but the chain has no configured wNative.
|
|
51
48
|
* @throws {NativeAmountOnNonWNativeAssetError} when `nativeAmount > 0n` but the loan token is not
|
|
52
49
|
* the chain's wNative.
|
|
@@ -74,15 +74,12 @@ export interface BlueRepayWithdrawCollateralParams {
|
|
|
74
74
|
* @param params.metadata - Optional analytics metadata attached to the bundle.
|
|
75
75
|
* @returns A deep-frozen `Transaction<BlueRepayWithdrawCollateralAction>` with `to`,
|
|
76
76
|
* `value` (= `nativeAmount`), `data`, and the typed `action` discriminator the simulation layer consumes.
|
|
77
|
-
* @throws {
|
|
78
|
-
*
|
|
77
|
+
* @throws {NonPositiveInputError} when `maxSharePrice <= 0n`, the total funding is zero, or
|
|
78
|
+
* `withdrawAmount <= 0n`.
|
|
79
|
+
* @throws {NegativeInputError} when `amount`, `shares`, `nativeAmount`, or `transferAmount` is negative.
|
|
79
80
|
* @throws {MutuallyExclusiveRepayAmountsError} when both `amount` and `shares` are `> 0n`.
|
|
80
81
|
* @throws {TransferAmountNotEqualToAssetsError} when in assets mode and
|
|
81
82
|
* `transferAmount !== amount + nativeAmount`.
|
|
82
|
-
* @throws {NonPositiveRepayAmountError} when `amount` or `shares` is negative, when in assets mode
|
|
83
|
-
* and `transferAmount <= 0n`, or when in shares mode and `transferAmount` is negative or the total
|
|
84
|
-
* funding (`transferAmount + nativeAmount`) is `<= 0n`.
|
|
85
|
-
* @throws {NonPositiveWithdrawCollateralAmountError} when `withdrawAmount <= 0n`.
|
|
86
83
|
* @throws {ChainWNativeMissingError} when `nativeAmount > 0n` but the chain has no configured wNative.
|
|
87
84
|
* @throws {NativeAmountOnNonWNativeAssetError} when `nativeAmount > 0n` but the loan token is not
|
|
88
85
|
* the chain's wNative.
|
|
@@ -3,7 +3,7 @@ import { deepFreeze } from "@morpho-org/morpho-ts";
|
|
|
3
3
|
import { maxUint256 } from "viem";
|
|
4
4
|
import { BundlerAction } from "../../bundler/index.js";
|
|
5
5
|
import { addTransactionMetadata } from "../../helpers/index.js";
|
|
6
|
-
import {
|
|
6
|
+
import { NonPositiveInputError, } from "../../types/index.js";
|
|
7
7
|
import { getBlueAuthorizationAction } from "../signatures/getBlueAuthorizationAction.js";
|
|
8
8
|
import { buildAssetFundingActions } from "./buildAssetFundingActions.js";
|
|
9
9
|
import { resolveRepayFunding } from "./resolveRepayFunding.js";
|
|
@@ -54,15 +54,12 @@ import { resolveRepayFunding } from "./resolveRepayFunding.js";
|
|
|
54
54
|
* @param params.metadata - Optional analytics metadata attached to the bundle.
|
|
55
55
|
* @returns A deep-frozen `Transaction<BlueRepayWithdrawCollateralAction>` with `to`,
|
|
56
56
|
* `value` (= `nativeAmount`), `data`, and the typed `action` discriminator the simulation layer consumes.
|
|
57
|
-
* @throws {
|
|
58
|
-
*
|
|
57
|
+
* @throws {NonPositiveInputError} when `maxSharePrice <= 0n`, the total funding is zero, or
|
|
58
|
+
* `withdrawAmount <= 0n`.
|
|
59
|
+
* @throws {NegativeInputError} when `amount`, `shares`, `nativeAmount`, or `transferAmount` is negative.
|
|
59
60
|
* @throws {MutuallyExclusiveRepayAmountsError} when both `amount` and `shares` are `> 0n`.
|
|
60
61
|
* @throws {TransferAmountNotEqualToAssetsError} when in assets mode and
|
|
61
62
|
* `transferAmount !== amount + nativeAmount`.
|
|
62
|
-
* @throws {NonPositiveRepayAmountError} when `amount` or `shares` is negative, when in assets mode
|
|
63
|
-
* and `transferAmount <= 0n`, or when in shares mode and `transferAmount` is negative or the total
|
|
64
|
-
* funding (`transferAmount + nativeAmount`) is `<= 0n`.
|
|
65
|
-
* @throws {NonPositiveWithdrawCollateralAmountError} when `withdrawAmount <= 0n`.
|
|
66
63
|
* @throws {ChainWNativeMissingError} when `nativeAmount > 0n` but the chain has no configured wNative.
|
|
67
64
|
* @throws {NativeAmountOnNonWNativeAssetError} when `nativeAmount > 0n` but the loan token is not
|
|
68
65
|
* the chain's wNative.
|
|
@@ -95,7 +92,7 @@ export const blueRepayWithdrawCollateral = ({ market: { chainId, marketParams },
|
|
|
95
92
|
const { amount = 0n, shares = 0n, nativeAmount = 0n, transferAmount, withdrawAmount, onBehalf, receiver, maxSharePrice, requirementSignature, authorizationSignature, } = args;
|
|
96
93
|
const { isSharesMode, repayAssets, repayShares, erc20Amount } = resolveRepayFunding({ amount, shares, nativeAmount, transferAmount, maxSharePrice }, marketParams.id);
|
|
97
94
|
if (withdrawAmount <= 0n) {
|
|
98
|
-
throw new
|
|
95
|
+
throw new NonPositiveInputError("withdrawAmount", withdrawAmount);
|
|
99
96
|
}
|
|
100
97
|
const { bundler3: { generalAdapter1 }, } = getChainAddresses(chainId);
|
|
101
98
|
const actions = [];
|
|
@@ -56,11 +56,8 @@ export interface RepayFunding {
|
|
|
56
56
|
* @param marketId - Market id used to tag the thrown errors.
|
|
57
57
|
* @returns `{ isSharesMode, repayAssets, repayShares, erc20Amount }` — the mode discriminator and the
|
|
58
58
|
* amounts the repay builders assemble the bundle from.
|
|
59
|
-
* @throws {
|
|
60
|
-
* @throws {
|
|
61
|
-
* @throws {NonPositiveRepayAmountError} when `amount` or `shares` is negative, when in assets mode and
|
|
62
|
-
* the repaid assets are `<= 0n`, or when in shares mode and `transferAmount` is negative or the total
|
|
63
|
-
* funding (`transferAmount + nativeAmount`) is `<= 0n`.
|
|
59
|
+
* @throws {NonPositiveInputError} when `maxSharePrice <= 0n` or total repay funding is zero.
|
|
60
|
+
* @throws {NegativeInputError} when `amount`, `shares`, `nativeAmount`, or `transferAmount` is negative.
|
|
64
61
|
* @throws {MutuallyExclusiveRepayAmountsError} when both `amount` and `shares` are `> 0n`.
|
|
65
62
|
* @throws {TransferAmountNotEqualToAssetsError} when in assets mode and
|
|
66
63
|
* `transferAmount !== amount + nativeAmount`.
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { MutuallyExclusiveRepayAmountsError,
|
|
1
|
+
import { MutuallyExclusiveRepayAmountsError, NegativeInputError, NonPositiveInputError, TransferAmountNotEqualToAssetsError, } from "../../types/index.js";
|
|
2
2
|
/**
|
|
3
3
|
* Resolves and validates the repay funding envelope shared by `blueRepay` and
|
|
4
4
|
* `blueRepayWithdrawCollateral`.
|
|
@@ -21,11 +21,8 @@ import { MutuallyExclusiveRepayAmountsError, NegativeNativeAmountError, NonPosit
|
|
|
21
21
|
* @param marketId - Market id used to tag the thrown errors.
|
|
22
22
|
* @returns `{ isSharesMode, repayAssets, repayShares, erc20Amount }` — the mode discriminator and the
|
|
23
23
|
* amounts the repay builders assemble the bundle from.
|
|
24
|
-
* @throws {
|
|
25
|
-
* @throws {
|
|
26
|
-
* @throws {NonPositiveRepayAmountError} when `amount` or `shares` is negative, when in assets mode and
|
|
27
|
-
* the repaid assets are `<= 0n`, or when in shares mode and `transferAmount` is negative or the total
|
|
28
|
-
* funding (`transferAmount + nativeAmount`) is `<= 0n`.
|
|
24
|
+
* @throws {NonPositiveInputError} when `maxSharePrice <= 0n` or total repay funding is zero.
|
|
25
|
+
* @throws {NegativeInputError} when `amount`, `shares`, `nativeAmount`, or `transferAmount` is negative.
|
|
29
26
|
* @throws {MutuallyExclusiveRepayAmountsError} when both `amount` and `shares` are `> 0n`.
|
|
30
27
|
* @throws {TransferAmountNotEqualToAssetsError} when in assets mode and
|
|
31
28
|
* `transferAmount !== amount + nativeAmount`.
|
|
@@ -33,13 +30,16 @@ import { MutuallyExclusiveRepayAmountsError, NegativeNativeAmountError, NonPosit
|
|
|
33
30
|
*/
|
|
34
31
|
export const resolveRepayFunding = ({ amount, shares, nativeAmount, transferAmount, maxSharePrice, }, marketId) => {
|
|
35
32
|
if (maxSharePrice <= 0n) {
|
|
36
|
-
throw new
|
|
33
|
+
throw new NonPositiveInputError("maxSharePrice", maxSharePrice);
|
|
37
34
|
}
|
|
38
35
|
if (nativeAmount < 0n) {
|
|
39
|
-
throw new
|
|
36
|
+
throw new NegativeInputError("nativeAmount", nativeAmount);
|
|
40
37
|
}
|
|
41
|
-
if (amount < 0n
|
|
42
|
-
throw new
|
|
38
|
+
if (amount < 0n) {
|
|
39
|
+
throw new NegativeInputError("amount", amount);
|
|
40
|
+
}
|
|
41
|
+
if (shares < 0n) {
|
|
42
|
+
throw new NegativeInputError("shares", shares);
|
|
43
43
|
}
|
|
44
44
|
if (amount > 0n && shares > 0n) {
|
|
45
45
|
throw new MutuallyExclusiveRepayAmountsError(marketId);
|
|
@@ -58,8 +58,11 @@ export const resolveRepayFunding = ({ amount, shares, nativeAmount, transferAmou
|
|
|
58
58
|
// ERC-20 (0 on a fully-native repay) and wraps `nativeAmount`; the bundle must
|
|
59
59
|
// fund the repay with a non-negative transfer and a positive total.
|
|
60
60
|
if (isSharesMode) {
|
|
61
|
-
if (transferAmount < 0n
|
|
62
|
-
throw new
|
|
61
|
+
if (transferAmount < 0n) {
|
|
62
|
+
throw new NegativeInputError("transferAmount", transferAmount);
|
|
63
|
+
}
|
|
64
|
+
if (transferAmount + nativeAmount <= 0n) {
|
|
65
|
+
throw new NonPositiveInputError("transferAmount + nativeAmount", transferAmount + nativeAmount);
|
|
63
66
|
}
|
|
64
67
|
}
|
|
65
68
|
else {
|
|
@@ -71,7 +74,7 @@ export const resolveRepayFunding = ({ amount, shares, nativeAmount, transferAmou
|
|
|
71
74
|
});
|
|
72
75
|
}
|
|
73
76
|
if (repayAssets <= 0n) {
|
|
74
|
-
throw new
|
|
77
|
+
throw new NonPositiveInputError("amount + nativeAmount", repayAssets);
|
|
75
78
|
}
|
|
76
79
|
}
|
|
77
80
|
return { isSharesMode, repayAssets, repayShares, erc20Amount };
|
|
@@ -40,10 +40,8 @@ export interface BlueSupplyParams {
|
|
|
40
40
|
* @param params.metadata - Optional analytics metadata attached to the bundle.
|
|
41
41
|
* @returns A deep-frozen `Transaction<BlueSupplyAction>` with `to`, `value`, `data`, and the
|
|
42
42
|
* typed `action` discriminator the simulation layer consumes.
|
|
43
|
-
* @throws {
|
|
44
|
-
* @throws {
|
|
45
|
-
* @throws {ZeroSupplyAmountError} when both `amount` and `nativeAmount` resolve to zero.
|
|
46
|
-
* @throws {NegativeSupplyMaxSharePriceError} when `maxSharePrice < 0n`.
|
|
43
|
+
* @throws {NegativeInputError} when `amount`, `nativeAmount`, or `maxSharePrice` is negative.
|
|
44
|
+
* @throws {NonPositiveInputError} when both `amount` and `nativeAmount` resolve to zero.
|
|
47
45
|
* @throws {ChainWNativeMissingError} when `nativeAmount > 0n` but the chain has no configured wNative.
|
|
48
46
|
* @throws {NativeAmountOnNonWNativeAssetError} when `nativeAmount > 0n` but the loan token is not
|
|
49
47
|
* the chain's wNative.
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { deepFreeze } from "@morpho-org/morpho-ts";
|
|
2
2
|
import { BundlerAction } from "../../bundler/index.js";
|
|
3
3
|
import { addTransactionMetadata } from "../../helpers/index.js";
|
|
4
|
-
import {
|
|
4
|
+
import { NegativeInputError, NonPositiveInputError, } from "../../types/index.js";
|
|
5
5
|
import { buildAssetFundingActions } from "./buildAssetFundingActions.js";
|
|
6
6
|
/**
|
|
7
7
|
* Prepares a loan-asset supply transaction for a Morpho Blue market.
|
|
@@ -26,10 +26,8 @@ import { buildAssetFundingActions } from "./buildAssetFundingActions.js";
|
|
|
26
26
|
* @param params.metadata - Optional analytics metadata attached to the bundle.
|
|
27
27
|
* @returns A deep-frozen `Transaction<BlueSupplyAction>` with `to`, `value`, `data`, and the
|
|
28
28
|
* typed `action` discriminator the simulation layer consumes.
|
|
29
|
-
* @throws {
|
|
30
|
-
* @throws {
|
|
31
|
-
* @throws {ZeroSupplyAmountError} when both `amount` and `nativeAmount` resolve to zero.
|
|
32
|
-
* @throws {NegativeSupplyMaxSharePriceError} when `maxSharePrice < 0n`.
|
|
29
|
+
* @throws {NegativeInputError} when `amount`, `nativeAmount`, or `maxSharePrice` is negative.
|
|
30
|
+
* @throws {NonPositiveInputError} when both `amount` and `nativeAmount` resolve to zero.
|
|
33
31
|
* @throws {ChainWNativeMissingError} when `nativeAmount > 0n` but the chain has no configured wNative.
|
|
34
32
|
* @throws {NativeAmountOnNonWNativeAssetError} when `nativeAmount > 0n` but the loan token is not
|
|
35
33
|
* the chain's wNative.
|
|
@@ -54,17 +52,17 @@ import { buildAssetFundingActions } from "./buildAssetFundingActions.js";
|
|
|
54
52
|
*/
|
|
55
53
|
export const blueSupply = ({ market: { chainId, marketParams }, args: { amount = 0n, onBehalf, maxSharePrice, requirementSignature, nativeAmount, }, metadata, }) => {
|
|
56
54
|
if (amount < 0n) {
|
|
57
|
-
throw new
|
|
55
|
+
throw new NegativeInputError("amount", amount);
|
|
58
56
|
}
|
|
59
57
|
if (nativeAmount !== undefined && nativeAmount < 0n) {
|
|
60
|
-
throw new
|
|
58
|
+
throw new NegativeInputError("nativeAmount", nativeAmount);
|
|
61
59
|
}
|
|
62
60
|
if (maxSharePrice < 0n) {
|
|
63
|
-
throw new
|
|
61
|
+
throw new NegativeInputError("maxSharePrice", maxSharePrice);
|
|
64
62
|
}
|
|
65
63
|
const totalAssets = amount + (nativeAmount ?? 0n);
|
|
66
64
|
if (totalAssets === 0n) {
|
|
67
|
-
throw new
|
|
65
|
+
throw new NonPositiveInputError("totalAssets", totalAssets);
|
|
68
66
|
}
|
|
69
67
|
const actions = buildAssetFundingActions({
|
|
70
68
|
chainId,
|
|
@@ -35,9 +35,8 @@ export interface BlueSupplyCollateralParams {
|
|
|
35
35
|
* @param params.metadata - Optional analytics metadata attached to the bundle.
|
|
36
36
|
* @returns A deep-frozen `Transaction<BlueSupplyCollateralAction>` with `to`, `value`, `data`,
|
|
37
37
|
* and the typed `action` discriminator the simulation layer consumes.
|
|
38
|
-
* @throws {
|
|
39
|
-
* @throws {
|
|
40
|
-
* @throws {ZeroCollateralAmountError} when both `amount` and `nativeAmount` resolve to zero.
|
|
38
|
+
* @throws {NegativeInputError} when `amount < 0n` or `nativeAmount < 0n`.
|
|
39
|
+
* @throws {NonPositiveInputError} when both `amount` and `nativeAmount` resolve to zero.
|
|
41
40
|
* @throws {ChainWNativeMissingError} when `nativeAmount > 0n` but the chain has no configured wNative.
|
|
42
41
|
* @throws {NativeAmountOnNonWNativeAssetError} when `nativeAmount > 0n` but the collateral
|
|
43
42
|
* token is not the chain's wNative.
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { deepFreeze } from "@morpho-org/morpho-ts";
|
|
2
2
|
import { BundlerAction } from "../../bundler/index.js";
|
|
3
3
|
import { addTransactionMetadata } from "../../helpers/index.js";
|
|
4
|
-
import {
|
|
4
|
+
import { NegativeInputError, NonPositiveInputError, } from "../../types/index.js";
|
|
5
5
|
import { buildAssetFundingActions } from "./buildAssetFundingActions.js";
|
|
6
6
|
/**
|
|
7
7
|
* Prepares a supply-collateral transaction for a Morpho Blue market.
|
|
@@ -23,9 +23,8 @@ import { buildAssetFundingActions } from "./buildAssetFundingActions.js";
|
|
|
23
23
|
* @param params.metadata - Optional analytics metadata attached to the bundle.
|
|
24
24
|
* @returns A deep-frozen `Transaction<BlueSupplyCollateralAction>` with `to`, `value`, `data`,
|
|
25
25
|
* and the typed `action` discriminator the simulation layer consumes.
|
|
26
|
-
* @throws {
|
|
27
|
-
* @throws {
|
|
28
|
-
* @throws {ZeroCollateralAmountError} when both `amount` and `nativeAmount` resolve to zero.
|
|
26
|
+
* @throws {NegativeInputError} when `amount < 0n` or `nativeAmount < 0n`.
|
|
27
|
+
* @throws {NonPositiveInputError} when both `amount` and `nativeAmount` resolve to zero.
|
|
29
28
|
* @throws {ChainWNativeMissingError} when `nativeAmount > 0n` but the chain has no configured wNative.
|
|
30
29
|
* @throws {NativeAmountOnNonWNativeAssetError} when `nativeAmount > 0n` but the collateral
|
|
31
30
|
* token is not the chain's wNative.
|
|
@@ -48,14 +47,14 @@ import { buildAssetFundingActions } from "./buildAssetFundingActions.js";
|
|
|
48
47
|
*/
|
|
49
48
|
export const blueSupplyCollateral = ({ market: { chainId, marketParams }, args: { amount = 0n, onBehalf, requirementSignature, nativeAmount }, metadata, }) => {
|
|
50
49
|
if (amount < 0n) {
|
|
51
|
-
throw new
|
|
50
|
+
throw new NegativeInputError("amount", amount);
|
|
52
51
|
}
|
|
53
52
|
if (nativeAmount !== undefined && nativeAmount < 0n) {
|
|
54
|
-
throw new
|
|
53
|
+
throw new NegativeInputError("nativeAmount", nativeAmount);
|
|
55
54
|
}
|
|
56
55
|
const totalCollateral = amount + (nativeAmount ?? 0n);
|
|
57
56
|
if (totalCollateral === 0n) {
|
|
58
|
-
throw new
|
|
57
|
+
throw new NonPositiveInputError("totalCollateral", totalCollateral);
|
|
59
58
|
}
|
|
60
59
|
const actions = buildAssetFundingActions({
|
|
61
60
|
chainId,
|
|
@@ -61,11 +61,10 @@ export interface BlueSupplyCollateralBorrowParams {
|
|
|
61
61
|
* @param params.metadata - Optional analytics metadata attached to the bundle.
|
|
62
62
|
* @returns A deep-frozen `Transaction<BlueSupplyCollateralBorrowAction>` with `to`, `value`,
|
|
63
63
|
* `data`, and the typed `action` discriminator the simulation layer consumes.
|
|
64
|
-
* @throws {
|
|
65
|
-
*
|
|
66
|
-
* @throws {
|
|
67
|
-
*
|
|
68
|
-
* @throws {ZeroCollateralAmountError} when both `amount` and `nativeAmount` resolve to zero.
|
|
64
|
+
* @throws {NegativeInputError} when `amount`, `nativeAmount`, `minSharePrice`, or any reallocation
|
|
65
|
+
* fee is negative.
|
|
66
|
+
* @throws {NonPositiveInputError} when `borrowAmount <= 0n`, both collateral amounts resolve to
|
|
67
|
+
* zero, or any reallocation withdrawal amount is non-positive.
|
|
69
68
|
* @throws {ChainWNativeMissingError} when `nativeAmount > 0n` but the chain has no configured wNative.
|
|
70
69
|
* @throws {NativeAmountOnNonWNativeAssetError} when `nativeAmount > 0n` but the collateral
|
|
71
70
|
* token is not the chain's wNative.
|
|
@@ -75,12 +74,8 @@ export interface BlueSupplyCollateralBorrowParams {
|
|
|
75
74
|
* is provided and the signed amount differs from `args.amount`.
|
|
76
75
|
* @throws {Permit2ExpirationMissingError} from `getTokenRequirementActions` when a Permit2 requirement
|
|
77
76
|
* signature is missing its expiration.
|
|
78
|
-
* @throws {NegativeReallocationFeeError} from `buildReallocationActions` when
|
|
79
|
-
* `reallocations` is non-empty and any `reallocation.fee < 0n`.
|
|
80
77
|
* @throws {EmptyReallocationWithdrawalsError} from `buildReallocationActions` when any
|
|
81
78
|
* `reallocation.withdrawals` is empty.
|
|
82
|
-
* @throws {NonPositiveReallocationAmountError} from `buildReallocationActions` when any
|
|
83
|
-
* `reallocation.withdrawals[i].amount <= 0n`.
|
|
84
79
|
* @throws {ReallocationWithdrawalOnTargetMarketError} from `buildReallocationActions` when any
|
|
85
80
|
* reallocation withdrawal references the target market.
|
|
86
81
|
* @throws {UnsortedReallocationWithdrawalsError} from `buildReallocationActions` when
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { deepFreeze } from "@morpho-org/morpho-ts";
|
|
2
2
|
import { BundlerAction } from "../../bundler/index.js";
|
|
3
3
|
import { addTransactionMetadata } from "../../helpers/index.js";
|
|
4
|
-
import {
|
|
4
|
+
import { NegativeInputError, NonPositiveInputError, } from "../../types/index.js";
|
|
5
5
|
import { getBlueAuthorizationAction } from "../signatures/getBlueAuthorizationAction.js";
|
|
6
6
|
import { buildAssetFundingActions } from "./buildAssetFundingActions.js";
|
|
7
7
|
import { buildReallocationActions } from "./buildReallocationActions.js";
|
|
@@ -37,11 +37,10 @@ import { buildReallocationActions } from "./buildReallocationActions.js";
|
|
|
37
37
|
* @param params.metadata - Optional analytics metadata attached to the bundle.
|
|
38
38
|
* @returns A deep-frozen `Transaction<BlueSupplyCollateralBorrowAction>` with `to`, `value`,
|
|
39
39
|
* `data`, and the typed `action` discriminator the simulation layer consumes.
|
|
40
|
-
* @throws {
|
|
41
|
-
*
|
|
42
|
-
* @throws {
|
|
43
|
-
*
|
|
44
|
-
* @throws {ZeroCollateralAmountError} when both `amount` and `nativeAmount` resolve to zero.
|
|
40
|
+
* @throws {NegativeInputError} when `amount`, `nativeAmount`, `minSharePrice`, or any reallocation
|
|
41
|
+
* fee is negative.
|
|
42
|
+
* @throws {NonPositiveInputError} when `borrowAmount <= 0n`, both collateral amounts resolve to
|
|
43
|
+
* zero, or any reallocation withdrawal amount is non-positive.
|
|
45
44
|
* @throws {ChainWNativeMissingError} when `nativeAmount > 0n` but the chain has no configured wNative.
|
|
46
45
|
* @throws {NativeAmountOnNonWNativeAssetError} when `nativeAmount > 0n` but the collateral
|
|
47
46
|
* token is not the chain's wNative.
|
|
@@ -51,12 +50,8 @@ import { buildReallocationActions } from "./buildReallocationActions.js";
|
|
|
51
50
|
* is provided and the signed amount differs from `args.amount`.
|
|
52
51
|
* @throws {Permit2ExpirationMissingError} from `getTokenRequirementActions` when a Permit2 requirement
|
|
53
52
|
* signature is missing its expiration.
|
|
54
|
-
* @throws {NegativeReallocationFeeError} from `buildReallocationActions` when
|
|
55
|
-
* `reallocations` is non-empty and any `reallocation.fee < 0n`.
|
|
56
53
|
* @throws {EmptyReallocationWithdrawalsError} from `buildReallocationActions` when any
|
|
57
54
|
* `reallocation.withdrawals` is empty.
|
|
58
|
-
* @throws {NonPositiveReallocationAmountError} from `buildReallocationActions` when any
|
|
59
|
-
* `reallocation.withdrawals[i].amount <= 0n`.
|
|
60
55
|
* @throws {ReallocationWithdrawalOnTargetMarketError} from `buildReallocationActions` when any
|
|
61
56
|
* reallocation withdrawal references the target market.
|
|
62
57
|
* @throws {UnsortedReallocationWithdrawalsError} from `buildReallocationActions` when
|
|
@@ -80,20 +75,20 @@ import { buildReallocationActions } from "./buildReallocationActions.js";
|
|
|
80
75
|
*/
|
|
81
76
|
export const blueSupplyCollateralBorrow = ({ market: { chainId, marketParams }, args: { amount = 0n, borrowAmount, onBehalf, receiver, minSharePrice, requirementSignature, nativeAmount, reallocations, authorizationSignature, }, metadata, }) => {
|
|
82
77
|
if (amount < 0n) {
|
|
83
|
-
throw new
|
|
78
|
+
throw new NegativeInputError("amount", amount);
|
|
84
79
|
}
|
|
85
80
|
if (nativeAmount !== undefined && nativeAmount < 0n) {
|
|
86
|
-
throw new
|
|
81
|
+
throw new NegativeInputError("nativeAmount", nativeAmount);
|
|
87
82
|
}
|
|
88
83
|
if (borrowAmount <= 0n) {
|
|
89
|
-
throw new
|
|
84
|
+
throw new NonPositiveInputError("borrowAmount", borrowAmount);
|
|
90
85
|
}
|
|
91
86
|
if (minSharePrice < 0n) {
|
|
92
|
-
throw new
|
|
87
|
+
throw new NegativeInputError("minSharePrice", minSharePrice);
|
|
93
88
|
}
|
|
94
89
|
const totalCollateral = amount + (nativeAmount ?? 0n);
|
|
95
90
|
if (totalCollateral === 0n) {
|
|
96
|
-
throw new
|
|
91
|
+
throw new NonPositiveInputError("totalCollateral", totalCollateral);
|
|
97
92
|
}
|
|
98
93
|
const actions = [];
|
|
99
94
|
if (authorizationSignature) {
|