@morpho-org/morpho-sdk 6.0.0-next.0 → 6.0.0-next.2
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/MIGRATION-v5-to-v6.md +329 -15
- package/README.md +93 -47
- package/lib/cjs/abis.d.ts +227 -2
- package/lib/cjs/abis.js +156 -3
- package/lib/cjs/actions/blue/borrow.d.ts +1 -1
- package/lib/cjs/actions/blue/borrow.js +1 -1
- package/lib/cjs/actions/blue/common.d.ts +6 -19
- package/lib/cjs/actions/blue/common.js +28 -162
- package/lib/cjs/actions/blue/refinance.d.ts +1 -1
- package/lib/cjs/actions/blue/refinance.js +1 -1
- package/lib/cjs/actions/blue/repay.d.ts +3 -3
- package/lib/cjs/actions/blue/repay.js +1 -1
- package/lib/cjs/actions/blue/repayWithdrawCollateral.d.ts +3 -3
- package/lib/cjs/actions/blue/repayWithdrawCollateral.js +1 -1
- package/lib/cjs/actions/blue/supply.d.ts +3 -3
- package/lib/cjs/actions/blue/supply.js +3 -8
- package/lib/cjs/actions/blue/supplyCollateral.d.ts +3 -3
- package/lib/cjs/actions/blue/supplyCollateral.js +1 -1
- package/lib/cjs/actions/blue/supplyCollateralBorrow.d.ts +3 -3
- package/lib/cjs/actions/blue/supplyCollateralBorrow.js +1 -1
- package/lib/cjs/actions/blue/withdraw.d.ts +1 -1
- package/lib/cjs/actions/blue/withdraw.js +1 -1
- package/lib/cjs/actions/blue/withdrawCollateral.d.ts +1 -1
- package/lib/cjs/actions/blue/withdrawCollateral.js +1 -1
- package/lib/cjs/actions/bundles/common.d.ts +230 -0
- package/lib/cjs/actions/bundles/common.js +507 -0
- package/lib/cjs/actions/bundles/index.d.ts +3 -0
- package/lib/cjs/actions/bundles/index.js +23 -0
- package/lib/cjs/actions/bundles/resolveBundlesTokenRequirements.d.ts +76 -0
- package/lib/cjs/actions/bundles/resolveBundlesTokenRequirements.js +125 -0
- package/lib/cjs/actions/index.d.ts +1 -0
- package/lib/cjs/actions/index.js +1 -0
- package/lib/cjs/actions/midnight/supplyCollateralTakeBorrow.d.ts +2 -2
- package/lib/cjs/actions/midnight/supplyCollateralTakeBorrow.js +2 -2
- package/lib/cjs/actions/midnight/takeBorrow.d.ts +2 -2
- package/lib/cjs/actions/midnight/takeBorrow.js +2 -2
- package/lib/cjs/actions/midnight/takeLend.d.ts +2 -2
- package/lib/cjs/actions/midnight/takeLend.js +2 -2
- package/lib/cjs/actions/requirements/blue/getBlueAuthorizationRequirement.d.ts +3 -0
- package/lib/cjs/actions/requirements/blue/getBlueAuthorizationRequirement.js +6 -10
- package/lib/cjs/actions/requirements/blue/index.d.ts +0 -2
- package/lib/cjs/actions/requirements/blue/index.js +0 -2
- package/lib/cjs/actions/requirements/encode/encodeBlueSignatureAuthorization.d.ts +15 -8
- package/lib/cjs/actions/requirements/encode/encodeBlueSignatureAuthorization.js +21 -21
- package/lib/cjs/actions/requirements/encode/encodeErc20Approval.d.ts +1 -1
- package/lib/cjs/actions/requirements/encode/encodeErc20Approval.js +2 -1
- package/lib/cjs/actions/requirements/encode/encodeErc20Permit.d.ts +19 -10
- package/lib/cjs/actions/requirements/encode/encodeErc20Permit.js +43 -31
- package/lib/cjs/actions/requirements/encode/encodeErc20Permit2Approve.d.ts +4 -2
- package/lib/cjs/actions/requirements/encode/encodeErc20Permit2Approve.js +15 -10
- package/lib/{esm/actions/requirements/encode/encodeErc20Permit2TransferFrom.d.ts → cjs/actions/requirements/encode/encodeErc20Permit2SignatureTransfer.d.ts} +16 -14
- package/lib/cjs/actions/requirements/encode/{encodeErc20Permit2TransferFrom.js → encodeErc20Permit2SignatureTransfer.js} +27 -22
- package/lib/cjs/actions/requirements/encode/encodeVaultSharesPermit.d.ts +12 -9
- package/lib/cjs/actions/requirements/encode/encodeVaultSharesPermit.js +27 -21
- package/lib/cjs/actions/requirements/encode/index.d.ts +1 -1
- package/lib/cjs/actions/requirements/encode/index.js +1 -1
- package/lib/cjs/actions/requirements/generalAdapter/getGeneralAdapterRequirements.js +1 -0
- package/lib/cjs/actions/requirements/generalAdapter/getGeneralAdapterRequirementsPermit.d.ts +4 -1
- package/lib/cjs/actions/requirements/generalAdapter/getGeneralAdapterRequirementsPermit.js +5 -2
- package/lib/cjs/actions/requirements/getRequirementsApproval.d.ts +4 -3
- package/lib/cjs/actions/requirements/getRequirementsApproval.js +4 -3
- package/lib/cjs/actions/signatures/getTokenRequirementActions.js +2 -2
- package/lib/cjs/actions/signatures/getVaultExitBundlesV1PermitStruct.d.ts +28 -30
- package/lib/cjs/actions/signatures/getVaultExitBundlesV1PermitStruct.js +20 -66
- package/lib/cjs/actions/vaultV1/deposit.d.ts +73 -57
- package/lib/cjs/actions/vaultV1/deposit.js +110 -109
- package/lib/cjs/actions/vaultV1/inKindRedeem.d.ts +1 -0
- package/lib/cjs/actions/vaultV1/inKindRedeem.js +3 -2
- package/lib/cjs/actions/vaultV1/migrateToV2.d.ts +43 -66
- package/lib/cjs/actions/vaultV1/migrateToV2.js +91 -104
- package/lib/cjs/actions/vaultV1/redeem.d.ts +30 -23
- package/lib/cjs/actions/vaultV1/redeem.js +56 -33
- package/lib/cjs/actions/vaultV1/withdraw.d.ts +58 -24
- package/lib/cjs/actions/vaultV1/withdraw.js +86 -34
- package/lib/cjs/actions/vaultV2/deposit.d.ts +74 -57
- package/lib/cjs/actions/vaultV2/deposit.js +111 -109
- package/lib/cjs/actions/vaultV2/forceWithdraw.d.ts +58 -39
- package/lib/cjs/actions/vaultV2/forceWithdraw.js +87 -60
- package/lib/cjs/actions/vaultV2/inKindRedeem.d.ts +1 -0
- package/lib/cjs/actions/vaultV2/inKindRedeem.js +3 -2
- package/lib/cjs/actions/vaultV2/redeem.d.ts +30 -24
- package/lib/cjs/actions/vaultV2/redeem.js +56 -34
- package/lib/cjs/actions/vaultV2/withdraw.d.ts +58 -25
- package/lib/cjs/actions/vaultV2/withdraw.js +86 -35
- package/lib/cjs/augment/VaultMarketPublicAllocatorConfig.d.ts +4 -1
- package/lib/cjs/blue/abis.d.ts +5 -1
- package/lib/cjs/blue/abis.js +2 -0
- package/lib/cjs/blue/entities.d.ts +8 -2
- package/lib/cjs/blue/entities.js +1 -0
- package/lib/cjs/blue/errors.d.ts +1 -1
- package/lib/cjs/blue/errors.js +2 -1
- package/lib/cjs/blue/fetch.d.ts +3 -1
- package/lib/cjs/blue/fetch.js +1 -0
- package/lib/cjs/entities/blue/blue.d.ts +29 -20
- package/lib/cjs/entities/blue/blue.js +6 -1
- package/lib/cjs/entities/index.d.ts +9 -2
- package/lib/cjs/entities/index.js +16 -0
- package/lib/cjs/entities/midnight/midnight.d.ts +2 -2
- package/lib/cjs/entities/midnight/midnight.js +20 -24
- package/lib/cjs/{actions/requirements/blue/getBlueBundlesV1TokenRequirements.d.ts → entities/requirements/getBundlesTokenRequirements.d.ts} +27 -19
- package/lib/cjs/{actions/requirements/blue/getBlueBundlesV1TokenRequirements.js → entities/requirements/getBundlesTokenRequirements.js} +76 -75
- package/lib/{esm/actions/requirements/blue → cjs/entities/requirements}/getUnusedPermit2Nonce.d.ts +1 -1
- package/lib/cjs/{actions/requirements/blue → entities/requirements}/getUnusedPermit2Nonce.js +4 -4
- package/lib/cjs/entities/requirements/getVaultBundlesSharesRequirements.d.ts +28 -0
- package/lib/cjs/entities/requirements/getVaultBundlesSharesRequirements.js +74 -0
- package/lib/cjs/entities/requirements/index.d.ts +2 -0
- package/lib/cjs/entities/requirements/index.js +18 -0
- package/lib/cjs/entities/vaultV1/vaultV1.d.ts +356 -101
- package/lib/cjs/entities/vaultV1/vaultV1.js +334 -120
- package/lib/cjs/entities/vaultV1ReallocationData.d.ts +6 -0
- package/lib/cjs/entities/vaultV1ReallocationData.js +20 -5
- package/lib/cjs/entities/vaultV2/vaultV2.d.ts +359 -100
- package/lib/cjs/entities/vaultV2/vaultV2.js +448 -93
- package/lib/cjs/entities/vaultV2BlueReallocationData.d.ts +8 -1
- package/lib/cjs/entities/vaultV2BlueReallocationData.js +46 -13
- package/lib/cjs/errors.d.ts +1 -1
- package/lib/cjs/errors.js +3 -2
- package/lib/cjs/fetch.d.ts +3 -1
- package/lib/cjs/fetch.js +1 -0
- package/lib/cjs/helpers/computeVaultV1Reallocations.d.ts +2 -0
- package/lib/cjs/helpers/computeVaultV1Reallocations.js +2 -0
- package/lib/cjs/helpers/index.d.ts +4 -1
- package/lib/cjs/helpers/index.js +14 -1
- package/lib/cjs/helpers/metadata.d.ts +3 -5
- package/lib/cjs/helpers/metadata.js +4 -6
- package/lib/cjs/helpers/previewVaultV2ForceWithdraw.d.ts +107 -0
- package/lib/cjs/helpers/previewVaultV2ForceWithdraw.js +164 -0
- package/lib/cjs/helpers/previewVaultV2InKindRedeem.d.ts +1 -0
- package/lib/cjs/helpers/previewVaultV2InKindRedeem.js +2 -0
- package/lib/cjs/helpers/referralFee.d.ts +21 -0
- package/lib/cjs/helpers/referralFee.js +35 -0
- package/lib/cjs/helpers/slippage.d.ts +136 -1
- package/lib/cjs/helpers/slippage.js +188 -0
- package/lib/cjs/helpers/validate.d.ts +67 -8
- package/lib/cjs/helpers/validate.js +94 -9
- package/lib/cjs/helpers/validateRequirementSpender.d.ts +1 -1
- package/lib/cjs/helpers/validateRequirementSpender.js +1 -0
- package/lib/cjs/helpers/vaultV2ForceWithdrawPlan.d.ts +274 -0
- package/lib/cjs/helpers/vaultV2ForceWithdrawPlan.js +369 -0
- package/lib/cjs/index.d.ts +1 -0
- package/lib/cjs/index.js +1 -0
- package/lib/cjs/types/action.d.ts +273 -82
- package/lib/cjs/types/action.js +12 -12
- package/lib/cjs/types/error.d.ts +349 -23
- package/lib/cjs/types/error.js +393 -39
- package/lib/cjs/types/sharedLiquidity.d.ts +2 -2
- package/lib/cjs/utils.d.ts +3 -1
- package/lib/cjs/utils.js +10 -1
- package/lib/esm/abis.d.ts +227 -2
- package/lib/esm/abis.js +157 -2
- package/lib/esm/actions/blue/borrow.d.ts +1 -1
- package/lib/esm/actions/blue/borrow.js +1 -1
- package/lib/esm/actions/blue/common.d.ts +6 -19
- package/lib/esm/actions/blue/common.js +30 -164
- package/lib/esm/actions/blue/refinance.d.ts +1 -1
- package/lib/esm/actions/blue/refinance.js +1 -1
- package/lib/esm/actions/blue/repay.d.ts +3 -3
- package/lib/esm/actions/blue/repay.js +1 -1
- package/lib/esm/actions/blue/repayWithdrawCollateral.d.ts +3 -3
- package/lib/esm/actions/blue/repayWithdrawCollateral.js +1 -1
- package/lib/esm/actions/blue/supply.d.ts +3 -3
- package/lib/esm/actions/blue/supply.js +5 -10
- package/lib/esm/actions/blue/supplyCollateral.d.ts +3 -3
- package/lib/esm/actions/blue/supplyCollateral.js +1 -1
- package/lib/esm/actions/blue/supplyCollateralBorrow.d.ts +3 -3
- package/lib/esm/actions/blue/supplyCollateralBorrow.js +1 -1
- package/lib/esm/actions/blue/withdraw.d.ts +1 -1
- package/lib/esm/actions/blue/withdraw.js +1 -1
- package/lib/esm/actions/blue/withdrawCollateral.d.ts +1 -1
- package/lib/esm/actions/blue/withdrawCollateral.js +1 -1
- package/lib/esm/actions/bundles/common.d.ts +230 -0
- package/lib/esm/actions/bundles/common.js +494 -0
- package/lib/esm/actions/bundles/index.d.ts +3 -0
- package/lib/esm/actions/bundles/index.js +2 -0
- package/lib/esm/actions/bundles/resolveBundlesTokenRequirements.d.ts +76 -0
- package/lib/esm/actions/bundles/resolveBundlesTokenRequirements.js +121 -0
- package/lib/esm/actions/index.d.ts +1 -0
- package/lib/esm/actions/index.js +1 -0
- package/lib/esm/actions/midnight/supplyCollateralTakeBorrow.d.ts +2 -2
- package/lib/esm/actions/midnight/supplyCollateralTakeBorrow.js +2 -2
- package/lib/esm/actions/midnight/takeBorrow.d.ts +2 -2
- package/lib/esm/actions/midnight/takeBorrow.js +2 -2
- package/lib/esm/actions/midnight/takeLend.d.ts +2 -2
- package/lib/esm/actions/midnight/takeLend.js +2 -2
- package/lib/esm/actions/requirements/blue/getBlueAuthorizationRequirement.d.ts +3 -0
- package/lib/esm/actions/requirements/blue/getBlueAuthorizationRequirement.js +8 -12
- package/lib/esm/actions/requirements/blue/index.d.ts +0 -2
- package/lib/esm/actions/requirements/blue/index.js +0 -2
- package/lib/esm/actions/requirements/encode/encodeBlueSignatureAuthorization.d.ts +15 -8
- package/lib/esm/actions/requirements/encode/encodeBlueSignatureAuthorization.js +22 -22
- package/lib/esm/actions/requirements/encode/encodeErc20Approval.d.ts +1 -1
- package/lib/esm/actions/requirements/encode/encodeErc20Approval.js +2 -1
- package/lib/esm/actions/requirements/encode/encodeErc20Permit.d.ts +19 -10
- package/lib/esm/actions/requirements/encode/encodeErc20Permit.js +44 -32
- package/lib/esm/actions/requirements/encode/encodeErc20Permit2Approve.d.ts +4 -2
- package/lib/esm/actions/requirements/encode/encodeErc20Permit2Approve.js +15 -10
- package/lib/{cjs/actions/requirements/encode/encodeErc20Permit2TransferFrom.d.ts → esm/actions/requirements/encode/encodeErc20Permit2SignatureTransfer.d.ts} +16 -14
- package/lib/esm/actions/requirements/encode/{encodeErc20Permit2TransferFrom.js → encodeErc20Permit2SignatureTransfer.js} +25 -20
- package/lib/esm/actions/requirements/encode/encodeVaultSharesPermit.d.ts +12 -9
- package/lib/esm/actions/requirements/encode/encodeVaultSharesPermit.js +27 -21
- package/lib/esm/actions/requirements/encode/index.d.ts +1 -1
- package/lib/esm/actions/requirements/encode/index.js +1 -1
- package/lib/esm/actions/requirements/generalAdapter/getGeneralAdapterRequirements.js +1 -0
- package/lib/esm/actions/requirements/generalAdapter/getGeneralAdapterRequirementsPermit.d.ts +4 -1
- package/lib/esm/actions/requirements/generalAdapter/getGeneralAdapterRequirementsPermit.js +5 -2
- package/lib/esm/actions/requirements/getRequirementsApproval.d.ts +4 -3
- package/lib/esm/actions/requirements/getRequirementsApproval.js +4 -3
- package/lib/esm/actions/signatures/getTokenRequirementActions.js +3 -3
- package/lib/esm/actions/signatures/getVaultExitBundlesV1PermitStruct.d.ts +28 -30
- package/lib/esm/actions/signatures/getVaultExitBundlesV1PermitStruct.js +21 -67
- package/lib/esm/actions/vaultV1/deposit.d.ts +73 -57
- package/lib/esm/actions/vaultV1/deposit.js +112 -111
- package/lib/esm/actions/vaultV1/inKindRedeem.d.ts +1 -0
- package/lib/esm/actions/vaultV1/inKindRedeem.js +3 -2
- package/lib/esm/actions/vaultV1/migrateToV2.d.ts +43 -66
- package/lib/esm/actions/vaultV1/migrateToV2.js +93 -106
- package/lib/esm/actions/vaultV1/redeem.d.ts +30 -23
- package/lib/esm/actions/vaultV1/redeem.js +56 -33
- package/lib/esm/actions/vaultV1/withdraw.d.ts +58 -24
- package/lib/esm/actions/vaultV1/withdraw.js +86 -34
- package/lib/esm/actions/vaultV2/deposit.d.ts +74 -57
- package/lib/esm/actions/vaultV2/deposit.js +113 -111
- package/lib/esm/actions/vaultV2/forceWithdraw.d.ts +58 -39
- package/lib/esm/actions/vaultV2/forceWithdraw.js +89 -62
- package/lib/esm/actions/vaultV2/inKindRedeem.d.ts +1 -0
- package/lib/esm/actions/vaultV2/inKindRedeem.js +3 -2
- package/lib/esm/actions/vaultV2/redeem.d.ts +30 -24
- package/lib/esm/actions/vaultV2/redeem.js +56 -34
- package/lib/esm/actions/vaultV2/withdraw.d.ts +58 -25
- package/lib/esm/actions/vaultV2/withdraw.js +86 -35
- package/lib/esm/augment/VaultMarketPublicAllocatorConfig.d.ts +4 -1
- package/lib/esm/augment/VaultMarketPublicAllocatorConfig.js +3 -1
- package/lib/esm/blue/abis.d.ts +5 -1
- package/lib/esm/blue/abis.js +5 -1
- package/lib/esm/blue/entities.d.ts +8 -2
- package/lib/esm/blue/entities.js +3 -1
- package/lib/esm/blue/errors.d.ts +1 -1
- package/lib/esm/blue/errors.js +1 -1
- package/lib/esm/blue/fetch.d.ts +3 -1
- package/lib/esm/blue/fetch.js +3 -1
- package/lib/esm/entities/blue/blue.d.ts +29 -20
- package/lib/esm/entities/blue/blue.js +7 -2
- package/lib/esm/entities/index.d.ts +9 -2
- package/lib/esm/entities/index.js +4 -1
- package/lib/esm/entities/midnight/midnight.d.ts +2 -2
- package/lib/esm/entities/midnight/midnight.js +20 -24
- package/lib/esm/{actions/requirements/blue/getBlueBundlesV1TokenRequirements.d.ts → entities/requirements/getBundlesTokenRequirements.d.ts} +27 -19
- package/lib/esm/{actions/requirements/blue/getBlueBundlesV1TokenRequirements.js → entities/requirements/getBundlesTokenRequirements.js} +67 -66
- package/lib/{cjs/actions/requirements/blue → esm/entities/requirements}/getUnusedPermit2Nonce.d.ts +1 -1
- package/lib/esm/{actions/requirements/blue → entities/requirements}/getUnusedPermit2Nonce.js +4 -4
- package/lib/esm/entities/requirements/getVaultBundlesSharesRequirements.d.ts +28 -0
- package/lib/esm/entities/requirements/getVaultBundlesSharesRequirements.js +70 -0
- package/lib/esm/entities/requirements/index.d.ts +2 -0
- package/lib/esm/entities/requirements/index.js +2 -0
- package/lib/esm/entities/vaultV1/vaultV1.d.ts +356 -101
- package/lib/esm/entities/vaultV1/vaultV1.js +338 -124
- package/lib/esm/entities/vaultV1ReallocationData.d.ts +6 -0
- package/lib/esm/entities/vaultV1ReallocationData.js +20 -5
- package/lib/esm/entities/vaultV2/vaultV2.d.ts +359 -100
- package/lib/esm/entities/vaultV2/vaultV2.js +452 -97
- package/lib/esm/entities/vaultV2BlueReallocationData.d.ts +8 -1
- package/lib/esm/entities/vaultV2BlueReallocationData.js +46 -13
- package/lib/esm/errors.d.ts +1 -1
- package/lib/esm/errors.js +1 -1
- package/lib/esm/fetch.d.ts +3 -1
- package/lib/esm/fetch.js +3 -1
- package/lib/esm/helpers/computeVaultV1Reallocations.d.ts +2 -0
- package/lib/esm/helpers/computeVaultV1Reallocations.js +2 -0
- package/lib/esm/helpers/index.d.ts +4 -1
- package/lib/esm/helpers/index.js +4 -1
- package/lib/esm/helpers/metadata.d.ts +3 -5
- package/lib/esm/helpers/metadata.js +4 -6
- package/lib/esm/helpers/previewVaultV2ForceWithdraw.d.ts +107 -0
- package/lib/esm/helpers/previewVaultV2ForceWithdraw.js +161 -0
- package/lib/esm/helpers/previewVaultV2InKindRedeem.d.ts +1 -0
- package/lib/esm/helpers/previewVaultV2InKindRedeem.js +2 -0
- package/lib/esm/helpers/referralFee.d.ts +21 -0
- package/lib/esm/helpers/referralFee.js +31 -0
- package/lib/esm/helpers/slippage.d.ts +136 -1
- package/lib/esm/helpers/slippage.js +186 -2
- package/lib/esm/helpers/validate.d.ts +67 -8
- package/lib/esm/helpers/validate.js +92 -10
- package/lib/esm/helpers/validateRequirementSpender.d.ts +1 -1
- package/lib/esm/helpers/validateRequirementSpender.js +1 -0
- package/lib/esm/helpers/vaultV2ForceWithdrawPlan.d.ts +274 -0
- package/lib/esm/helpers/vaultV2ForceWithdrawPlan.js +362 -0
- package/lib/esm/index.d.ts +1 -0
- package/lib/esm/index.js +1 -0
- package/lib/esm/types/action.d.ts +273 -82
- package/lib/esm/types/action.js +11 -11
- package/lib/esm/types/error.d.ts +349 -23
- package/lib/esm/types/error.js +377 -31
- package/lib/esm/types/sharedLiquidity.d.ts +2 -2
- package/lib/esm/utils.d.ts +3 -1
- package/lib/esm/utils.js +3 -1
- package/package.json +7 -7
|
@@ -1,24 +1,11 @@
|
|
|
1
1
|
import { MarketParams, MathLib, VaultV2BluePublicAllocatorConfigUtils, } from "@morpho-org/blue-sdk";
|
|
2
2
|
import { deepFreeze, getChainAddress } from "@morpho-org/morpho-ts";
|
|
3
|
-
import {
|
|
3
|
+
import { isAddressEqual, zeroAddress, zeroHash, } from "viem";
|
|
4
4
|
import { addTransactionMetadata, validateNativeAsset, } from "../../helpers/index.js";
|
|
5
5
|
import { validateVaultV2BlueReallocations } from "../../helpers/validate.js";
|
|
6
|
-
import { AmbiguousRequirementSignaturesError,
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
* the pull, `erc2612` (1) is an ERC-2612 permit, `permit2TransferFrom` (2) is a Permit2
|
|
10
|
-
* SignatureTransfer. Named so a transposed literal can't silently route a permit to the wrong branch.
|
|
11
|
-
* @internal
|
|
12
|
-
*/
|
|
13
|
-
const BLUE_BUNDLES_V1_TOKEN_PERMIT_KIND = {
|
|
14
|
-
none: 0,
|
|
15
|
-
erc2612: 1,
|
|
16
|
-
permit2TransferFrom: 2,
|
|
17
|
-
};
|
|
18
|
-
const EMPTY_TOKEN_PERMIT = {
|
|
19
|
-
kind: BLUE_BUNDLES_V1_TOKEN_PERMIT_KIND.none,
|
|
20
|
-
data: "0x",
|
|
21
|
-
};
|
|
6
|
+
import { AmbiguousRequirementSignaturesError, BundlesRequirementSignatureMismatchError, DepositOwnerMismatchError, NativeFundingAmountMismatchError, NegativeInputError, ReallocationLoanTokenMismatchError, selectRequirementSignatures, UnexpectedRequirementSignatureError, } from "../../types/index.js";
|
|
7
|
+
import { normalizeBundlesCommonParams, normalizeBundlesSignature, } from "../bundles/common.js";
|
|
8
|
+
import { getBundlesTokenPermit, } from "../bundles/index.js";
|
|
22
9
|
const EMPTY_SIGNED_AUTHORIZATION = {
|
|
23
10
|
signature: { v: 0, r: zeroHash, s: zeroHash },
|
|
24
11
|
nonce: 0n,
|
|
@@ -26,35 +13,10 @@ const EMPTY_SIGNED_AUTHORIZATION = {
|
|
|
26
13
|
};
|
|
27
14
|
/** @internal */
|
|
28
15
|
export const normalizeBlueBundlesV1CommonParams = (params) => {
|
|
29
|
-
|
|
30
|
-
throw new NonPositiveInputError("deadline", params.deadline);
|
|
31
|
-
}
|
|
32
|
-
if (params.deadline > maxUint256) {
|
|
33
|
-
throw new InputExceedsMaxError({
|
|
34
|
-
field: "deadline",
|
|
35
|
-
value: params.deadline,
|
|
36
|
-
max: maxUint256,
|
|
37
|
-
});
|
|
38
|
-
}
|
|
39
|
-
const referralFeePct = params.referralFeePct ?? 0n;
|
|
40
|
-
if (referralFeePct < 0n) {
|
|
41
|
-
throw new NegativeInputError("referralFeePct", referralFeePct);
|
|
42
|
-
}
|
|
43
|
-
if (referralFeePct >= MathLib.WAD) {
|
|
44
|
-
throw new InputExceedsMaxError({
|
|
45
|
-
field: "referralFeePct",
|
|
46
|
-
value: referralFeePct,
|
|
47
|
-
max: MathLib.WAD - 1n,
|
|
48
|
-
});
|
|
49
|
-
}
|
|
50
|
-
if (referralFeePct > 0n &&
|
|
51
|
-
(params.referralFeeRecipient == null ||
|
|
52
|
-
isAddressEqual(params.referralFeeRecipient, zeroAddress))) {
|
|
53
|
-
throw new MissingReferralFeeRecipientError();
|
|
54
|
-
}
|
|
16
|
+
const normalized = normalizeBundlesCommonParams(params);
|
|
55
17
|
return {
|
|
56
|
-
referralFeePct,
|
|
57
|
-
referralFeeRecipient:
|
|
18
|
+
referralFeePct: normalized.referralFeePct,
|
|
19
|
+
referralFeeRecipient: normalized.referralFeeRecipient,
|
|
58
20
|
};
|
|
59
21
|
};
|
|
60
22
|
/** @internal */
|
|
@@ -76,88 +38,13 @@ export const validateBlueBundlesV1NativeFunding = (params) => {
|
|
|
76
38
|
};
|
|
77
39
|
/** @internal */
|
|
78
40
|
export const getBlueBundlesV1TokenPermit = (params) => {
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
}
|
|
86
|
-
if (!isAddressEqual(requirementSignature.args.asset, params.token)) {
|
|
87
|
-
throw new DepositAssetMismatchError(params.token, requirementSignature.args.asset);
|
|
88
|
-
}
|
|
89
|
-
if (requirementSignature.args.amount !== params.amount) {
|
|
90
|
-
throw new DepositAmountMismatchError(params.amount, requirementSignature.args.amount);
|
|
91
|
-
}
|
|
92
|
-
if (!isAddressEqual(requirementSignature.action.args.spender, spender)) {
|
|
93
|
-
throw new DepositSpenderMismatchError(spender, requirementSignature.action.args.spender);
|
|
94
|
-
}
|
|
95
|
-
if (requirementSignature.action.args.amount !== params.amount) {
|
|
96
|
-
throw new DepositAmountMismatchError(params.amount, requirementSignature.action.args.amount);
|
|
97
|
-
}
|
|
98
|
-
if (requirementSignature.action.args.deadline !==
|
|
99
|
-
requirementSignature.args.deadline) {
|
|
100
|
-
throw new BlueBundlesV1RequirementSignatureMismatchError({
|
|
101
|
-
field: "deadline",
|
|
102
|
-
expected: String(requirementSignature.args.deadline),
|
|
103
|
-
actual: String(requirementSignature.action.args.deadline),
|
|
104
|
-
});
|
|
105
|
-
}
|
|
106
|
-
if (requirementSignature.action.type === "permit2TransferFrom") {
|
|
107
|
-
return {
|
|
108
|
-
kind: BLUE_BUNDLES_V1_TOKEN_PERMIT_KIND.permit2TransferFrom,
|
|
109
|
-
data: encodeAbiParameters([
|
|
110
|
-
{ type: "uint256", name: "nonce" },
|
|
111
|
-
{ type: "uint256", name: "deadline" },
|
|
112
|
-
{ type: "bytes", name: "signature" },
|
|
113
|
-
], [
|
|
114
|
-
requirementSignature.args.nonce,
|
|
115
|
-
requirementSignature.args.deadline,
|
|
116
|
-
requirementSignature.args.signature,
|
|
117
|
-
]),
|
|
118
|
-
};
|
|
119
|
-
}
|
|
120
|
-
if (requirementSignature.action.type !== "permit") {
|
|
121
|
-
throw new BlueBundlesV1RequirementSignatureMismatchError({
|
|
122
|
-
field: "type",
|
|
123
|
-
expected: "permit or permit2TransferFrom",
|
|
124
|
-
actual: requirementSignature.action.type,
|
|
125
|
-
});
|
|
126
|
-
}
|
|
127
|
-
const serializedSignature = requirementSignature.args.signature;
|
|
128
|
-
let parsed;
|
|
129
|
-
try {
|
|
130
|
-
parsed =
|
|
131
|
-
size(serializedSignature) === 64
|
|
132
|
-
? compactSignatureToSignature(parseCompactSignature(serializedSignature))
|
|
133
|
-
: parseSignature(serializedSignature);
|
|
134
|
-
}
|
|
135
|
-
catch (cause) {
|
|
136
|
-
throw new BlueBundlesV1RequirementSignatureMismatchError({
|
|
137
|
-
field: "signature",
|
|
138
|
-
expected: "a 64-byte compact or 65-byte serialized ECDSA signature",
|
|
139
|
-
actual: serializedSignature,
|
|
140
|
-
cause,
|
|
141
|
-
});
|
|
142
|
-
}
|
|
143
|
-
const v = parsed.v ??
|
|
144
|
-
(parsed.yParity == null ? undefined : BigInt(parsed.yParity + 27));
|
|
145
|
-
if (v == null) {
|
|
146
|
-
throw new BlueBundlesV1RequirementSignatureMismatchError({
|
|
147
|
-
field: "signature",
|
|
148
|
-
expected: "a signature containing v or yParity",
|
|
149
|
-
actual: serializedSignature,
|
|
150
|
-
});
|
|
151
|
-
}
|
|
152
|
-
return {
|
|
153
|
-
kind: BLUE_BUNDLES_V1_TOKEN_PERMIT_KIND.erc2612,
|
|
154
|
-
data: encodeAbiParameters([
|
|
155
|
-
{ type: "uint256", name: "deadline" },
|
|
156
|
-
{ type: "uint8", name: "v" },
|
|
157
|
-
{ type: "bytes32", name: "r" },
|
|
158
|
-
{ type: "bytes32", name: "s" },
|
|
159
|
-
], [requirementSignature.args.deadline, Number(v), parsed.r, parsed.s]),
|
|
160
|
-
};
|
|
41
|
+
return getBundlesTokenPermit({
|
|
42
|
+
userAddress: params.userAddress,
|
|
43
|
+
token: params.token,
|
|
44
|
+
spender: getChainAddress(params.chainId, "bundles.blueBundlesV1"),
|
|
45
|
+
amount: params.amount,
|
|
46
|
+
requirementSignature: params.requirementSignature,
|
|
47
|
+
});
|
|
161
48
|
};
|
|
162
49
|
/** @internal */
|
|
163
50
|
export const getBlueBundlesV1SignedAuthorization = (params) => {
|
|
@@ -169,28 +56,28 @@ export const getBlueBundlesV1SignedAuthorization = (params) => {
|
|
|
169
56
|
throw new DepositOwnerMismatchError(params.userAddress, authorizationSignature.args.owner);
|
|
170
57
|
}
|
|
171
58
|
if (!isAddressEqual(authorizationSignature.args.authorized, authorized)) {
|
|
172
|
-
throw new
|
|
59
|
+
throw new BundlesRequirementSignatureMismatchError({
|
|
173
60
|
field: "authorized",
|
|
174
61
|
expected: authorized,
|
|
175
62
|
actual: authorizationSignature.args.authorized,
|
|
176
63
|
});
|
|
177
64
|
}
|
|
178
65
|
if (!isAddressEqual(authorizationSignature.action.args.authorized, authorized)) {
|
|
179
|
-
throw new
|
|
66
|
+
throw new BundlesRequirementSignatureMismatchError({
|
|
180
67
|
field: "authorized",
|
|
181
68
|
expected: authorized,
|
|
182
69
|
actual: authorizationSignature.action.args.authorized,
|
|
183
70
|
});
|
|
184
71
|
}
|
|
185
72
|
if (!authorizationSignature.args.isAuthorized) {
|
|
186
|
-
throw new
|
|
73
|
+
throw new BundlesRequirementSignatureMismatchError({
|
|
187
74
|
field: "isAuthorized",
|
|
188
75
|
expected: "true",
|
|
189
76
|
actual: String(authorizationSignature.args.isAuthorized),
|
|
190
77
|
});
|
|
191
78
|
}
|
|
192
79
|
if (!authorizationSignature.action.args.isAuthorized) {
|
|
193
|
-
throw new
|
|
80
|
+
throw new BundlesRequirementSignatureMismatchError({
|
|
194
81
|
field: "isAuthorized",
|
|
195
82
|
expected: "true",
|
|
196
83
|
actual: String(authorizationSignature.action.args.isAuthorized),
|
|
@@ -198,39 +85,18 @@ export const getBlueBundlesV1SignedAuthorization = (params) => {
|
|
|
198
85
|
}
|
|
199
86
|
if (authorizationSignature.action.args.deadline !==
|
|
200
87
|
authorizationSignature.args.deadline) {
|
|
201
|
-
throw new
|
|
88
|
+
throw new BundlesRequirementSignatureMismatchError({
|
|
202
89
|
field: "deadline",
|
|
203
90
|
expected: String(authorizationSignature.args.deadline),
|
|
204
91
|
actual: String(authorizationSignature.action.args.deadline),
|
|
205
92
|
});
|
|
206
93
|
}
|
|
207
|
-
const
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
size(serializedSignature) === 64
|
|
212
|
-
? compactSignatureToSignature(parseCompactSignature(serializedSignature))
|
|
213
|
-
: parseSignature(serializedSignature);
|
|
214
|
-
}
|
|
215
|
-
catch (cause) {
|
|
216
|
-
throw new BlueBundlesV1RequirementSignatureMismatchError({
|
|
217
|
-
field: "signature",
|
|
218
|
-
expected: "a 64-byte compact or 65-byte serialized ECDSA signature",
|
|
219
|
-
actual: serializedSignature,
|
|
220
|
-
cause,
|
|
221
|
-
});
|
|
222
|
-
}
|
|
223
|
-
const v = parsed.v ??
|
|
224
|
-
(parsed.yParity == null ? undefined : BigInt(parsed.yParity + 27));
|
|
225
|
-
if (v == null) {
|
|
226
|
-
throw new BlueBundlesV1RequirementSignatureMismatchError({
|
|
227
|
-
field: "signature",
|
|
228
|
-
expected: "a signature containing v or yParity",
|
|
229
|
-
actual: serializedSignature,
|
|
230
|
-
});
|
|
231
|
-
}
|
|
94
|
+
const signature = normalizeBundlesSignature(authorizationSignature.args.signature, (details) => new BundlesRequirementSignatureMismatchError({
|
|
95
|
+
field: "signature",
|
|
96
|
+
...details,
|
|
97
|
+
}));
|
|
232
98
|
return {
|
|
233
|
-
signature
|
|
99
|
+
signature,
|
|
234
100
|
nonce: authorizationSignature.args.nonce,
|
|
235
101
|
deadline: authorizationSignature.args.deadline,
|
|
236
102
|
};
|
|
@@ -271,24 +137,24 @@ export const getBlueBundlesV1ReferralFeeAssets = (assets, referralFeePct) => ref
|
|
|
271
137
|
: MathLib.mulDivDown(assets, referralFeePct, MathLib.WAD - referralFeePct);
|
|
272
138
|
/** @internal */
|
|
273
139
|
export const selectBlueBundlesV1RequirementSignatures = (signatures, accepts) => {
|
|
274
|
-
const { permit,
|
|
140
|
+
const { permit, permit2SignatureTransfer, authorization } = selectRequirementSignatures(signatures, {
|
|
275
141
|
permit: accepts.token,
|
|
276
|
-
|
|
142
|
+
permit2SignatureTransfer: accepts.token,
|
|
277
143
|
authorization: accepts.authorization,
|
|
278
144
|
});
|
|
279
145
|
if (permit?.action.type === "permit2") {
|
|
280
|
-
throw new
|
|
146
|
+
throw new BundlesRequirementSignatureMismatchError({
|
|
281
147
|
field: "type",
|
|
282
|
-
expected: "permit or
|
|
148
|
+
expected: "permit or permit2SignatureTransfer",
|
|
283
149
|
actual: permit.action.type,
|
|
284
150
|
});
|
|
285
151
|
}
|
|
286
|
-
if (permit != null &&
|
|
152
|
+
if (permit != null && permit2SignatureTransfer != null) {
|
|
287
153
|
throw new AmbiguousRequirementSignaturesError("permit", 2);
|
|
288
154
|
}
|
|
289
155
|
return {
|
|
290
156
|
token: permit ??
|
|
291
|
-
|
|
157
|
+
permit2SignatureTransfer,
|
|
292
158
|
authorization,
|
|
293
159
|
};
|
|
294
160
|
};
|
|
@@ -69,7 +69,7 @@ export interface BlueRefinanceParams {
|
|
|
69
69
|
* @throws {ReallocationWithdrawalOnTargetMarketError} when a source is the destination market.
|
|
70
70
|
* @throws {ReallocationLoanTokenMismatchError} when a source market uses another loan token.
|
|
71
71
|
* @throws {DepositOwnerMismatchError} when the signed authorization owner differs from `userAddress`.
|
|
72
|
-
* @throws {
|
|
72
|
+
* @throws {BundlesRequirementSignatureMismatchError} when authorization cannot be bound safely.
|
|
73
73
|
* @throws {UnsupportedChainIdError} when the chain is absent from the registry.
|
|
74
74
|
* @throws {UnknownAddressError} when BlueBundlesV1 is not registered.
|
|
75
75
|
* @example
|
|
@@ -39,7 +39,7 @@ import { finalizeBlueBundlesV1Transaction, getBlueBundlesV1PenaltyAssets, getBlu
|
|
|
39
39
|
* @throws {ReallocationWithdrawalOnTargetMarketError} when a source is the destination market.
|
|
40
40
|
* @throws {ReallocationLoanTokenMismatchError} when a source market uses another loan token.
|
|
41
41
|
* @throws {DepositOwnerMismatchError} when the signed authorization owner differs from `userAddress`.
|
|
42
|
-
* @throws {
|
|
42
|
+
* @throws {BundlesRequirementSignatureMismatchError} when authorization cannot be bound safely.
|
|
43
43
|
* @throws {UnsupportedChainIdError} when the chain is absent from the registry.
|
|
44
44
|
* @throws {UnknownAddressError} when BlueBundlesV1 is not registered.
|
|
45
45
|
* @example
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { MarketParams } from "@morpho-org/blue-sdk";
|
|
2
2
|
import { type Address } from "viem";
|
|
3
|
-
import type {
|
|
3
|
+
import type { BlueRepayAction, BundlesTokenRequirementSignature, Metadata, Transaction } from "../../types/index.js";
|
|
4
4
|
/** Parameters for {@link blueRepay}. */
|
|
5
5
|
export interface BlueRepayParams {
|
|
6
6
|
/** Chain and scoped Morpho Blue market. */
|
|
@@ -27,7 +27,7 @@ export interface BlueRepayParams {
|
|
|
27
27
|
/** Recipient required when `referralFeePct` is positive. */
|
|
28
28
|
readonly referralFeeRecipient?: Address;
|
|
29
29
|
/** Optional loan-token ERC-2612 or Permit2 SignatureTransfer result. */
|
|
30
|
-
readonly requirementSignature?:
|
|
30
|
+
readonly requirementSignature?: BundlesTokenRequirementSignature;
|
|
31
31
|
};
|
|
32
32
|
/** Optional transaction metadata suffix. */
|
|
33
33
|
readonly metadata?: Metadata;
|
|
@@ -65,7 +65,7 @@ export interface BlueRepayParams {
|
|
|
65
65
|
* @throws {DepositAssetMismatchError} when the signed asset differs from the loan token.
|
|
66
66
|
* @throws {DepositAmountMismatchError} when the signed amount differs from `maxRepayAssets`.
|
|
67
67
|
* @throws {DepositSpenderMismatchError} when the signed spender is not BlueBundlesV1.
|
|
68
|
-
* @throws {
|
|
68
|
+
* @throws {BundlesRequirementSignatureMismatchError} when a signature cannot be encoded safely.
|
|
69
69
|
* @throws {InputExceedsMaxError} when the referral fee is at least WAD.
|
|
70
70
|
* @throws {MissingReferralFeeRecipientError} when a positive fee has no recipient.
|
|
71
71
|
* @throws {UnsupportedChainIdError} when the chain is absent from the registry.
|
|
@@ -34,7 +34,7 @@ import { blueRepayWithdrawCollateral } from "./repayWithdrawCollateral.js";
|
|
|
34
34
|
* @throws {DepositAssetMismatchError} when the signed asset differs from the loan token.
|
|
35
35
|
* @throws {DepositAmountMismatchError} when the signed amount differs from `maxRepayAssets`.
|
|
36
36
|
* @throws {DepositSpenderMismatchError} when the signed spender is not BlueBundlesV1.
|
|
37
|
-
* @throws {
|
|
37
|
+
* @throws {BundlesRequirementSignatureMismatchError} when a signature cannot be encoded safely.
|
|
38
38
|
* @throws {InputExceedsMaxError} when the referral fee is at least WAD.
|
|
39
39
|
* @throws {MissingReferralFeeRecipientError} when a positive fee has no recipient.
|
|
40
40
|
* @throws {UnsupportedChainIdError} when the chain is absent from the registry.
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { MarketParams } from "@morpho-org/blue-sdk";
|
|
2
2
|
import { type Address } from "viem";
|
|
3
|
-
import { type AuthorizationRequirementSignature, type
|
|
3
|
+
import { type AuthorizationRequirementSignature, type BlueRepayWithdrawCollateralAction, type BundlesTokenRequirementSignature, type Metadata, type Transaction } from "../../types/index.js";
|
|
4
4
|
/** Parameters for {@link blueRepayWithdrawCollateral}. */
|
|
5
5
|
export interface BlueRepayWithdrawCollateralParams {
|
|
6
6
|
/** Chain and scoped Morpho Blue market. */
|
|
@@ -31,7 +31,7 @@ export interface BlueRepayWithdrawCollateralParams {
|
|
|
31
31
|
/** Recipient required when `referralFeePct` is positive. */
|
|
32
32
|
readonly referralFeeRecipient?: Address;
|
|
33
33
|
/** Optional loan-token ERC-2612 or Permit2 SignatureTransfer result. */
|
|
34
|
-
readonly requirementSignature?:
|
|
34
|
+
readonly requirementSignature?: BundlesTokenRequirementSignature;
|
|
35
35
|
/** Optional Morpho authorization signature for BlueBundlesV1. */
|
|
36
36
|
readonly authorizationSignature?: AuthorizationRequirementSignature;
|
|
37
37
|
};
|
|
@@ -77,7 +77,7 @@ export interface BlueRepayWithdrawCollateralParams {
|
|
|
77
77
|
* @throws {DepositAssetMismatchError} when the signed asset differs from the loan token.
|
|
78
78
|
* @throws {DepositAmountMismatchError} when the signed amount differs from `maxRepayAssets`.
|
|
79
79
|
* @throws {DepositSpenderMismatchError} when the signed spender is not BlueBundlesV1.
|
|
80
|
-
* @throws {
|
|
80
|
+
* @throws {BundlesRequirementSignatureMismatchError} when a signature cannot be bound safely.
|
|
81
81
|
* @throws {UnsupportedChainIdError} when the chain is absent from the registry.
|
|
82
82
|
* @throws {UnknownAddressError} when BlueBundlesV1 is not registered.
|
|
83
83
|
* @example
|
|
@@ -42,7 +42,7 @@ import { finalizeBlueBundlesV1Transaction, getBlueBundlesV1ReferralFeeAssets, ge
|
|
|
42
42
|
* @throws {DepositAssetMismatchError} when the signed asset differs from the loan token.
|
|
43
43
|
* @throws {DepositAmountMismatchError} when the signed amount differs from `maxRepayAssets`.
|
|
44
44
|
* @throws {DepositSpenderMismatchError} when the signed spender is not BlueBundlesV1.
|
|
45
|
-
* @throws {
|
|
45
|
+
* @throws {BundlesRequirementSignatureMismatchError} when a signature cannot be bound safely.
|
|
46
46
|
* @throws {UnsupportedChainIdError} when the chain is absent from the registry.
|
|
47
47
|
* @throws {UnknownAddressError} when BlueBundlesV1 is not registered.
|
|
48
48
|
* @example
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { MarketParams } from "@morpho-org/blue-sdk";
|
|
2
2
|
import { type Address } from "viem";
|
|
3
|
-
import type {
|
|
3
|
+
import type { BlueSupplyAction, BundlesTokenRequirementSignature, Metadata, Transaction } from "../../types/index.js";
|
|
4
4
|
/** Parameters for {@link blueSupply}. */
|
|
5
5
|
export interface BlueSupplyParams {
|
|
6
6
|
/** Chain and scoped Morpho Blue market. */
|
|
@@ -23,7 +23,7 @@ export interface BlueSupplyParams {
|
|
|
23
23
|
/** Recipient required when `referralFeePct` is positive. */
|
|
24
24
|
readonly referralFeeRecipient?: Address;
|
|
25
25
|
/** Optional ERC-2612 or Permit2 SignatureTransfer requirement result. */
|
|
26
|
-
readonly requirementSignature?:
|
|
26
|
+
readonly requirementSignature?: BundlesTokenRequirementSignature;
|
|
27
27
|
};
|
|
28
28
|
/** Optional transaction metadata suffix. */
|
|
29
29
|
readonly metadata?: Metadata;
|
|
@@ -59,7 +59,7 @@ export interface BlueSupplyParams {
|
|
|
59
59
|
* @throws {DepositAssetMismatchError} when the signed asset differs from the loan token.
|
|
60
60
|
* @throws {DepositAmountMismatchError} when the signed amount differs from `assets`.
|
|
61
61
|
* @throws {DepositSpenderMismatchError} when the signed spender is not BlueBundlesV1.
|
|
62
|
-
* @throws {
|
|
62
|
+
* @throws {BundlesRequirementSignatureMismatchError} when the signature kind or encoding is invalid.
|
|
63
63
|
* @throws {UnsupportedChainIdError} when the chain is absent from the address registry.
|
|
64
64
|
* @throws {UnknownAddressError} when BlueBundlesV1 is not registered.
|
|
65
65
|
* @example
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import { encodeFunctionData
|
|
1
|
+
import { encodeFunctionData } from "viem";
|
|
2
2
|
import { blueBundlesV1Abi } from "../../abis.js";
|
|
3
|
-
import {
|
|
3
|
+
import { validateUint256Field } from "../../helpers/validate.js";
|
|
4
|
+
import { NonPositiveInputError } from "../../types/index.js";
|
|
4
5
|
import { finalizeBlueBundlesV1Transaction, getBlueBundlesV1TokenPermit, normalizeBlueBundlesV1CommonParams, validateBlueBundlesV1NativeFunding, } from "./common.js";
|
|
5
6
|
/**
|
|
6
7
|
* Encodes a direct BlueBundlesV1 loan-asset supply transaction.
|
|
@@ -33,7 +34,7 @@ import { finalizeBlueBundlesV1Transaction, getBlueBundlesV1TokenPermit, normaliz
|
|
|
33
34
|
* @throws {DepositAssetMismatchError} when the signed asset differs from the loan token.
|
|
34
35
|
* @throws {DepositAmountMismatchError} when the signed amount differs from `assets`.
|
|
35
36
|
* @throws {DepositSpenderMismatchError} when the signed spender is not BlueBundlesV1.
|
|
36
|
-
* @throws {
|
|
37
|
+
* @throws {BundlesRequirementSignatureMismatchError} when the signature kind or encoding is invalid.
|
|
37
38
|
* @throws {UnsupportedChainIdError} when the chain is absent from the address registry.
|
|
38
39
|
* @throws {UnknownAddressError} when BlueBundlesV1 is not registered.
|
|
39
40
|
* @example
|
|
@@ -61,13 +62,7 @@ export const blueSupply = (params) => {
|
|
|
61
62
|
if (assets <= 0n) {
|
|
62
63
|
throw new NonPositiveInputError("assets", assets);
|
|
63
64
|
}
|
|
64
|
-
|
|
65
|
-
throw new InputExceedsMaxError({
|
|
66
|
-
field: "assets",
|
|
67
|
-
value: assets,
|
|
68
|
-
max: maxUint256,
|
|
69
|
-
});
|
|
70
|
-
}
|
|
65
|
+
validateUint256Field("assets", assets);
|
|
71
66
|
const common = {
|
|
72
67
|
chainId,
|
|
73
68
|
userAddress,
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { MarketParams } from "@morpho-org/blue-sdk";
|
|
2
2
|
import { type Address } from "viem";
|
|
3
|
-
import type {
|
|
3
|
+
import type { BlueSupplyCollateralAction, BundlesTokenRequirementSignature, Metadata, Transaction } from "../../types/index.js";
|
|
4
4
|
/** Parameters for {@link blueSupplyCollateral}. */
|
|
5
5
|
export interface BlueSupplyCollateralParams {
|
|
6
6
|
/** Chain and scoped Morpho Blue market. */
|
|
@@ -23,7 +23,7 @@ export interface BlueSupplyCollateralParams {
|
|
|
23
23
|
/** Recipient required when `referralFeePct` is positive. */
|
|
24
24
|
readonly referralFeeRecipient?: Address;
|
|
25
25
|
/** Optional collateral ERC-2612 or Permit2 SignatureTransfer result. */
|
|
26
|
-
readonly requirementSignature?:
|
|
26
|
+
readonly requirementSignature?: BundlesTokenRequirementSignature;
|
|
27
27
|
};
|
|
28
28
|
/** Optional transaction metadata suffix. */
|
|
29
29
|
readonly metadata?: Metadata;
|
|
@@ -57,7 +57,7 @@ export interface BlueSupplyCollateralParams {
|
|
|
57
57
|
* @throws {DepositAssetMismatchError} when the signed asset differs from the collateral token.
|
|
58
58
|
* @throws {DepositAmountMismatchError} when the signed amount differs from `collateralAssets`.
|
|
59
59
|
* @throws {DepositSpenderMismatchError} when the signed spender is not BlueBundlesV1.
|
|
60
|
-
* @throws {
|
|
60
|
+
* @throws {BundlesRequirementSignatureMismatchError} when a signature cannot be encoded safely.
|
|
61
61
|
* @throws {InputExceedsMaxError} when the referral fee is at least WAD.
|
|
62
62
|
* @throws {MissingReferralFeeRecipientError} when a positive fee has no recipient.
|
|
63
63
|
* @throws {UnsupportedChainIdError} when the chain is absent from the registry.
|
|
@@ -30,7 +30,7 @@ import { blueSupplyCollateralBorrow } from "./supplyCollateralBorrow.js";
|
|
|
30
30
|
* @throws {DepositAssetMismatchError} when the signed asset differs from the collateral token.
|
|
31
31
|
* @throws {DepositAmountMismatchError} when the signed amount differs from `collateralAssets`.
|
|
32
32
|
* @throws {DepositSpenderMismatchError} when the signed spender is not BlueBundlesV1.
|
|
33
|
-
* @throws {
|
|
33
|
+
* @throws {BundlesRequirementSignatureMismatchError} when a signature cannot be encoded safely.
|
|
34
34
|
* @throws {InputExceedsMaxError} when the referral fee is at least WAD.
|
|
35
35
|
* @throws {MissingReferralFeeRecipientError} when a positive fee has no recipient.
|
|
36
36
|
* @throws {UnsupportedChainIdError} when the chain is absent from the registry.
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { MarketParams } from "@morpho-org/blue-sdk";
|
|
2
2
|
import { type Address } from "viem";
|
|
3
|
-
import { type AuthorizationRequirementSignature, type
|
|
3
|
+
import { type AuthorizationRequirementSignature, type BlueSupplyCollateralBorrowAction, type BundlesTokenRequirementSignature, type Metadata, type Transaction, type VaultV2BlueReallocation } from "../../types/index.js";
|
|
4
4
|
/** Parameters for {@link blueSupplyCollateralBorrow}. */
|
|
5
5
|
export interface BlueSupplyCollateralBorrowParams {
|
|
6
6
|
/** Chain and scoped Morpho Blue market. */
|
|
@@ -29,7 +29,7 @@ export interface BlueSupplyCollateralBorrowParams {
|
|
|
29
29
|
/** Recipient required when `referralFeePct` is positive. */
|
|
30
30
|
readonly referralFeeRecipient?: Address;
|
|
31
31
|
/** Optional collateral ERC-2612 or Permit2 SignatureTransfer result. */
|
|
32
|
-
readonly requirementSignature?:
|
|
32
|
+
readonly requirementSignature?: BundlesTokenRequirementSignature;
|
|
33
33
|
/** Optional Morpho authorization signature for BlueBundlesV1. */
|
|
34
34
|
readonly authorizationSignature?: AuthorizationRequirementSignature;
|
|
35
35
|
};
|
|
@@ -78,7 +78,7 @@ export interface BlueSupplyCollateralBorrowParams {
|
|
|
78
78
|
* @throws {DepositAssetMismatchError} when the signed asset differs from the collateral token.
|
|
79
79
|
* @throws {DepositAmountMismatchError} when the signed amount differs from `collateralAssets`.
|
|
80
80
|
* @throws {DepositSpenderMismatchError} when the signed spender is not BlueBundlesV1.
|
|
81
|
-
* @throws {
|
|
81
|
+
* @throws {BundlesRequirementSignatureMismatchError} when a signature cannot be bound safely.
|
|
82
82
|
* @throws {UnsupportedChainIdError} when the chain is absent from the registry.
|
|
83
83
|
* @throws {UnknownAddressError} when BlueBundlesV1 is not registered.
|
|
84
84
|
* @example
|
|
@@ -45,7 +45,7 @@ import { finalizeBlueBundlesV1Transaction, getBlueBundlesV1PenaltyAssets, getBlu
|
|
|
45
45
|
* @throws {DepositAssetMismatchError} when the signed asset differs from the collateral token.
|
|
46
46
|
* @throws {DepositAmountMismatchError} when the signed amount differs from `collateralAssets`.
|
|
47
47
|
* @throws {DepositSpenderMismatchError} when the signed spender is not BlueBundlesV1.
|
|
48
|
-
* @throws {
|
|
48
|
+
* @throws {BundlesRequirementSignatureMismatchError} when a signature cannot be bound safely.
|
|
49
49
|
* @throws {UnsupportedChainIdError} when the chain is absent from the registry.
|
|
50
50
|
* @throws {UnknownAddressError} when BlueBundlesV1 is not registered.
|
|
51
51
|
* @example
|
|
@@ -64,7 +64,7 @@ export interface BlueWithdrawParams {
|
|
|
64
64
|
* @throws {ReallocationWithdrawalOnTargetMarketError} when a source is the target market.
|
|
65
65
|
* @throws {ReallocationLoanTokenMismatchError} when a source market uses another loan token.
|
|
66
66
|
* @throws {DepositOwnerMismatchError} when the signed authorization owner differs from `userAddress`.
|
|
67
|
-
* @throws {
|
|
67
|
+
* @throws {BundlesRequirementSignatureMismatchError} when authorization cannot be bound safely.
|
|
68
68
|
* @throws {UnsupportedChainIdError} when the chain is absent from the registry.
|
|
69
69
|
* @throws {UnknownAddressError} when BlueBundlesV1 is not registered.
|
|
70
70
|
* @example
|
|
@@ -37,7 +37,7 @@ import { finalizeBlueBundlesV1Transaction, getBlueBundlesV1PenaltyAssets, getBlu
|
|
|
37
37
|
* @throws {ReallocationWithdrawalOnTargetMarketError} when a source is the target market.
|
|
38
38
|
* @throws {ReallocationLoanTokenMismatchError} when a source market uses another loan token.
|
|
39
39
|
* @throws {DepositOwnerMismatchError} when the signed authorization owner differs from `userAddress`.
|
|
40
|
-
* @throws {
|
|
40
|
+
* @throws {BundlesRequirementSignatureMismatchError} when authorization cannot be bound safely.
|
|
41
41
|
* @throws {UnsupportedChainIdError} when the chain is absent from the registry.
|
|
42
42
|
* @throws {UnknownAddressError} when BlueBundlesV1 is not registered.
|
|
43
43
|
* @example
|
|
@@ -52,7 +52,7 @@ export interface BlueWithdrawCollateralParams {
|
|
|
52
52
|
* @throws {InputExceedsMaxError} when the referral fee is at least WAD.
|
|
53
53
|
* @throws {MissingReferralFeeRecipientError} when a positive fee has no recipient.
|
|
54
54
|
* @throws {DepositOwnerMismatchError} when the signed authorization owner differs from `userAddress`.
|
|
55
|
-
* @throws {
|
|
55
|
+
* @throws {BundlesRequirementSignatureMismatchError} when authorization cannot be bound safely.
|
|
56
56
|
* @throws {UnsupportedChainIdError} when the chain is absent from the registry.
|
|
57
57
|
* @throws {UnknownAddressError} when BlueBundlesV1 is not registered.
|
|
58
58
|
* @example
|
|
@@ -24,7 +24,7 @@ import { blueRepayWithdrawCollateral } from "./repayWithdrawCollateral.js";
|
|
|
24
24
|
* @throws {InputExceedsMaxError} when the referral fee is at least WAD.
|
|
25
25
|
* @throws {MissingReferralFeeRecipientError} when a positive fee has no recipient.
|
|
26
26
|
* @throws {DepositOwnerMismatchError} when the signed authorization owner differs from `userAddress`.
|
|
27
|
-
* @throws {
|
|
27
|
+
* @throws {BundlesRequirementSignatureMismatchError} when authorization cannot be bound safely.
|
|
28
28
|
* @throws {UnsupportedChainIdError} when the chain is absent from the registry.
|
|
29
29
|
* @throws {UnknownAddressError} when BlueBundlesV1 is not registered.
|
|
30
30
|
* @example
|