@morpho-org/morpho-sdk 6.0.0-next.1 → 6.0.0-next.3
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 +199 -34
- package/README.md +23 -15
- package/lib/cjs/abis.d.ts +3 -2829
- package/lib/cjs/abis.js +1 -1938
- package/lib/cjs/actions/blue/borrow.d.ts +3 -2
- package/lib/cjs/actions/blue/borrow.js +3 -2
- package/lib/cjs/actions/blue/common.js +6 -35
- package/lib/cjs/actions/blue/refinance.d.ts +2 -2
- package/lib/cjs/actions/blue/refinance.js +2 -2
- package/lib/cjs/actions/blue/repay.d.ts +1 -1
- package/lib/cjs/actions/blue/repay.js +1 -1
- package/lib/cjs/actions/blue/repayWithdrawCollateral.d.ts +2 -2
- package/lib/cjs/actions/blue/repayWithdrawCollateral.js +2 -2
- package/lib/cjs/actions/blue/supply.d.ts +2 -2
- package/lib/cjs/actions/blue/supply.js +4 -9
- package/lib/cjs/actions/blue/supplyCollateral.d.ts +2 -2
- package/lib/cjs/actions/blue/supplyCollateral.js +2 -2
- package/lib/cjs/actions/blue/supplyCollateralBorrow.d.ts +3 -2
- package/lib/cjs/actions/blue/supplyCollateralBorrow.js +3 -2
- package/lib/cjs/actions/blue/withdraw.d.ts +3 -3
- package/lib/cjs/actions/blue/withdraw.js +3 -3
- package/lib/cjs/actions/blue/withdrawCollateral.d.ts +2 -2
- package/lib/cjs/actions/blue/withdrawCollateral.js +2 -2
- package/lib/cjs/actions/bundles/common.d.ts +38 -4
- package/lib/cjs/actions/bundles/common.js +91 -35
- package/lib/cjs/actions/index.d.ts +0 -1
- package/lib/cjs/actions/index.js +0 -1
- package/lib/cjs/actions/requirements/blue/getBlueAuthorizationRequirement.d.ts +9 -8
- package/lib/cjs/actions/requirements/blue/getBlueAuthorizationRequirement.js +17 -26
- package/lib/cjs/actions/requirements/blue/index.d.ts +0 -1
- package/lib/cjs/actions/requirements/blue/index.js +0 -1
- package/lib/cjs/actions/requirements/encode/encodeBlueSignatureAuthorization.d.ts +20 -14
- package/lib/cjs/actions/requirements/encode/encodeBlueSignatureAuthorization.js +24 -25
- package/lib/cjs/actions/requirements/encode/encodeErc20Approval.d.ts +4 -4
- package/lib/cjs/actions/requirements/encode/encodeErc20Approval.js +4 -5
- package/lib/cjs/actions/requirements/encode/encodeErc20Permit.d.ts +21 -12
- package/lib/cjs/actions/requirements/encode/encodeErc20Permit.js +39 -38
- package/lib/cjs/actions/requirements/encode/encodeErc20Permit2SignatureTransfer.d.ts +4 -2
- package/lib/cjs/actions/requirements/encode/encodeErc20Permit2SignatureTransfer.js +14 -9
- package/lib/cjs/actions/requirements/encode/encodeVaultSharesPermit.d.ts +9 -6
- package/lib/cjs/actions/requirements/encode/encodeVaultSharesPermit.js +22 -17
- package/lib/cjs/actions/requirements/encode/index.d.ts +0 -1
- package/lib/cjs/actions/requirements/encode/index.js +0 -1
- package/lib/cjs/actions/requirements/getRequirementsApproval.d.ts +5 -6
- package/lib/cjs/actions/requirements/getRequirementsApproval.js +5 -6
- package/lib/cjs/actions/requirements/index.d.ts +0 -1
- package/lib/cjs/actions/requirements/index.js +0 -1
- package/lib/cjs/actions/vaultV1/deposit.d.ts +1 -2
- package/lib/cjs/actions/vaultV1/deposit.js +1 -2
- package/lib/cjs/actions/vaultV1/inKindRedeem.d.ts +6 -4
- package/lib/cjs/actions/vaultV1/inKindRedeem.js +12 -8
- package/lib/cjs/actions/vaultV2/deposit.d.ts +1 -2
- package/lib/cjs/actions/vaultV2/deposit.js +1 -2
- 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 +6 -4
- package/lib/cjs/actions/vaultV2/inKindRedeem.js +12 -8
- package/lib/cjs/augment.d.ts +0 -1
- package/lib/cjs/augment.js +0 -1
- package/lib/cjs/blue/abis.d.ts +1 -1
- package/lib/cjs/blue/abis.js +1 -5
- package/lib/cjs/blue/entities.d.ts +2 -2
- package/lib/cjs/blue/entities.js +1 -2
- package/lib/cjs/blue/errors.d.ts +1 -1
- package/lib/cjs/blue/errors.js +2 -1
- package/lib/cjs/blue/fetch.d.ts +1 -1
- package/lib/cjs/blue/fetch.js +1 -2
- package/lib/cjs/blue/types.d.ts +2 -4
- package/lib/cjs/blue/utils.d.ts +1 -3
- package/lib/cjs/blue/utils.js +1 -3
- package/lib/cjs/client/morphoViemExtension.d.ts +1 -1
- package/lib/cjs/client/morphoViemExtension.js +1 -1
- package/lib/cjs/constants.d.ts +3 -37
- package/lib/cjs/constants.js +1 -39
- package/lib/cjs/entities/blue/blue.d.ts +38 -264
- package/lib/cjs/entities/blue/blue.js +2 -203
- package/lib/cjs/entities/index.d.ts +3 -60
- package/lib/cjs/entities/index.js +1 -20
- package/lib/cjs/entities/midnight/midnight.js +20 -24
- package/lib/cjs/entities/requirements/getBundlesTokenRequirements.d.ts +7 -6
- package/lib/cjs/entities/requirements/getBundlesTokenRequirements.js +19 -14
- package/lib/cjs/{actions/requirements/blue → entities/requirements}/getUnusedPermit2Nonce.js +3 -3
- package/lib/cjs/entities/requirements/index.d.ts +1 -0
- package/lib/cjs/entities/requirements/index.js +1 -0
- package/lib/cjs/entities/vaultV1/vaultV1.d.ts +18 -6
- package/lib/cjs/entities/vaultV1/vaultV1.js +25 -8
- package/lib/cjs/entities/vaultV2/vaultV2.d.ts +154 -35
- package/lib/cjs/entities/vaultV2/vaultV2.js +249 -23
- package/lib/cjs/entities/vaultV2BlueReallocationData.d.ts +8 -1
- package/lib/cjs/entities/vaultV2BlueReallocationData.js +50 -34
- package/lib/cjs/errors.d.ts +2 -46
- package/lib/cjs/errors.js +2 -46
- package/lib/cjs/fetch.d.ts +1 -15
- package/lib/cjs/fetch.js +1 -16
- package/lib/cjs/helpers/constant.d.ts +0 -2
- package/lib/cjs/helpers/constant.js +0 -2
- package/lib/cjs/helpers/index.d.ts +4 -3
- package/lib/cjs/helpers/index.js +10 -9
- 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/slippage.d.ts +34 -90
- package/lib/cjs/helpers/slippage.js +52 -137
- package/lib/cjs/helpers/utilization.d.ts +12 -10
- package/lib/cjs/helpers/utilization.js +27 -12
- package/lib/cjs/helpers/validate.d.ts +66 -32
- package/lib/cjs/helpers/validate.js +84 -57
- package/lib/cjs/helpers/validateRequirementSpender.d.ts +1 -1
- package/lib/cjs/helpers/validateRequirementSpender.js +1 -3
- package/lib/cjs/helpers/vaultV2ForceWithdrawPlan.d.ts +274 -0
- package/lib/cjs/helpers/vaultV2ForceWithdrawPlan.js +369 -0
- package/lib/cjs/types/action.d.ts +102 -68
- package/lib/cjs/types/action.js +11 -4
- package/lib/cjs/types/error.d.ts +332 -385
- package/lib/cjs/types/error.js +369 -412
- package/lib/cjs/types/sharedLiquidity.d.ts +1 -117
- package/lib/cjs/types.d.ts +2 -18
- package/lib/cjs/utils.d.ts +8 -35
- package/lib/cjs/utils.js +11 -36
- package/lib/esm/abis.d.ts +3 -2829
- package/lib/esm/abis.js +3 -1935
- package/lib/esm/actions/blue/borrow.d.ts +3 -2
- package/lib/esm/actions/blue/borrow.js +3 -2
- package/lib/esm/actions/blue/common.js +8 -37
- package/lib/esm/actions/blue/refinance.d.ts +2 -2
- package/lib/esm/actions/blue/refinance.js +2 -2
- package/lib/esm/actions/blue/repay.d.ts +1 -1
- package/lib/esm/actions/blue/repay.js +1 -1
- package/lib/esm/actions/blue/repayWithdrawCollateral.d.ts +2 -2
- package/lib/esm/actions/blue/repayWithdrawCollateral.js +2 -2
- package/lib/esm/actions/blue/supply.d.ts +2 -2
- package/lib/esm/actions/blue/supply.js +6 -11
- package/lib/esm/actions/blue/supplyCollateral.d.ts +2 -2
- package/lib/esm/actions/blue/supplyCollateral.js +2 -2
- package/lib/esm/actions/blue/supplyCollateralBorrow.d.ts +3 -2
- package/lib/esm/actions/blue/supplyCollateralBorrow.js +3 -2
- package/lib/esm/actions/blue/withdraw.d.ts +3 -3
- package/lib/esm/actions/blue/withdraw.js +3 -3
- package/lib/esm/actions/blue/withdrawCollateral.d.ts +2 -2
- package/lib/esm/actions/blue/withdrawCollateral.js +2 -2
- package/lib/esm/actions/bundles/common.d.ts +38 -4
- package/lib/esm/actions/bundles/common.js +91 -36
- package/lib/esm/actions/index.d.ts +0 -1
- package/lib/esm/actions/index.js +0 -1
- package/lib/esm/actions/requirements/blue/getBlueAuthorizationRequirement.d.ts +9 -8
- package/lib/esm/actions/requirements/blue/getBlueAuthorizationRequirement.js +20 -29
- package/lib/esm/actions/requirements/blue/index.d.ts +0 -1
- package/lib/esm/actions/requirements/blue/index.js +0 -1
- package/lib/esm/actions/requirements/encode/encodeBlueSignatureAuthorization.d.ts +20 -14
- package/lib/esm/actions/requirements/encode/encodeBlueSignatureAuthorization.js +25 -26
- package/lib/esm/actions/requirements/encode/encodeErc20Approval.d.ts +4 -4
- package/lib/esm/actions/requirements/encode/encodeErc20Approval.js +4 -5
- package/lib/esm/actions/requirements/encode/encodeErc20Permit.d.ts +21 -12
- package/lib/esm/actions/requirements/encode/encodeErc20Permit.js +40 -39
- package/lib/esm/actions/requirements/encode/encodeErc20Permit2SignatureTransfer.d.ts +4 -2
- package/lib/esm/actions/requirements/encode/encodeErc20Permit2SignatureTransfer.js +14 -9
- package/lib/esm/actions/requirements/encode/encodeVaultSharesPermit.d.ts +9 -6
- package/lib/esm/actions/requirements/encode/encodeVaultSharesPermit.js +22 -17
- package/lib/esm/actions/requirements/encode/index.d.ts +0 -1
- package/lib/esm/actions/requirements/encode/index.js +0 -1
- package/lib/esm/actions/requirements/getRequirementsApproval.d.ts +5 -6
- package/lib/esm/actions/requirements/getRequirementsApproval.js +5 -6
- package/lib/esm/actions/requirements/index.d.ts +0 -1
- package/lib/esm/actions/requirements/index.js +0 -1
- package/lib/esm/actions/vaultV1/deposit.d.ts +1 -2
- package/lib/esm/actions/vaultV1/deposit.js +1 -2
- package/lib/esm/actions/vaultV1/inKindRedeem.d.ts +6 -4
- package/lib/esm/actions/vaultV1/inKindRedeem.js +12 -8
- package/lib/esm/actions/vaultV2/deposit.d.ts +1 -2
- package/lib/esm/actions/vaultV2/deposit.js +1 -2
- 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 +6 -4
- package/lib/esm/actions/vaultV2/inKindRedeem.js +12 -8
- package/lib/esm/augment.d.ts +0 -1
- package/lib/esm/augment.js +0 -1
- package/lib/esm/blue/abis.d.ts +1 -1
- package/lib/esm/blue/abis.js +1 -1
- package/lib/esm/blue/entities.d.ts +2 -2
- package/lib/esm/blue/entities.js +1 -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 +1 -1
- package/lib/esm/blue/fetch.js +1 -1
- package/lib/esm/blue/types.d.ts +2 -4
- package/lib/esm/blue/utils.d.ts +1 -3
- package/lib/esm/blue/utils.js +1 -3
- package/lib/esm/client/morphoViemExtension.d.ts +1 -1
- package/lib/esm/client/morphoViemExtension.js +1 -1
- package/lib/esm/constants.d.ts +3 -37
- package/lib/esm/constants.js +3 -37
- package/lib/esm/entities/blue/blue.d.ts +38 -264
- package/lib/esm/entities/blue/blue.js +5 -206
- package/lib/esm/entities/index.d.ts +3 -60
- package/lib/esm/entities/index.js +1 -16
- package/lib/esm/entities/midnight/midnight.js +20 -24
- package/lib/esm/entities/requirements/getBundlesTokenRequirements.d.ts +7 -6
- package/lib/esm/entities/requirements/getBundlesTokenRequirements.js +20 -15
- package/lib/esm/{actions/requirements/blue → entities/requirements}/getUnusedPermit2Nonce.js +3 -3
- package/lib/esm/entities/requirements/index.d.ts +1 -0
- package/lib/esm/entities/requirements/index.js +1 -0
- package/lib/esm/entities/vaultV1/vaultV1.d.ts +18 -6
- package/lib/esm/entities/vaultV1/vaultV1.js +29 -12
- package/lib/esm/entities/vaultV2/vaultV2.d.ts +154 -35
- package/lib/esm/entities/vaultV2/vaultV2.js +256 -30
- package/lib/esm/entities/vaultV2BlueReallocationData.d.ts +8 -1
- package/lib/esm/entities/vaultV2BlueReallocationData.js +48 -32
- package/lib/esm/errors.d.ts +2 -46
- package/lib/esm/errors.js +2 -46
- package/lib/esm/fetch.d.ts +1 -15
- package/lib/esm/fetch.js +1 -15
- package/lib/esm/helpers/constant.d.ts +0 -2
- package/lib/esm/helpers/constant.js +0 -2
- package/lib/esm/helpers/index.d.ts +4 -3
- package/lib/esm/helpers/index.js +4 -3
- 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/slippage.d.ts +34 -90
- package/lib/esm/helpers/slippage.js +52 -134
- package/lib/esm/helpers/utilization.d.ts +12 -10
- package/lib/esm/helpers/utilization.js +26 -11
- package/lib/esm/helpers/validate.d.ts +66 -32
- package/lib/esm/helpers/validate.js +83 -57
- package/lib/esm/helpers/validateRequirementSpender.d.ts +1 -1
- package/lib/esm/helpers/validateRequirementSpender.js +1 -3
- package/lib/esm/helpers/vaultV2ForceWithdrawPlan.d.ts +274 -0
- package/lib/esm/helpers/vaultV2ForceWithdrawPlan.js +362 -0
- package/lib/esm/types/action.d.ts +102 -68
- package/lib/esm/types/action.js +12 -5
- package/lib/esm/types/error.d.ts +332 -385
- package/lib/esm/types/error.js +355 -392
- package/lib/esm/types/sharedLiquidity.d.ts +1 -117
- package/lib/esm/types.d.ts +2 -18
- package/lib/esm/utils.d.ts +8 -35
- package/lib/esm/utils.js +7 -34
- package/package.json +7 -15
- package/lib/cjs/actions/requirements/encode/encodeErc20Permit2Approve.d.ts +0 -42
- package/lib/cjs/actions/requirements/encode/encodeErc20Permit2Approve.js +0 -83
- package/lib/cjs/actions/requirements/generalAdapter/getGeneralAdapterRequirements.d.ts +0 -88
- package/lib/cjs/actions/requirements/generalAdapter/getGeneralAdapterRequirements.js +0 -151
- package/lib/cjs/actions/requirements/generalAdapter/getGeneralAdapterRequirementsPermit.d.ts +0 -37
- package/lib/cjs/actions/requirements/generalAdapter/getGeneralAdapterRequirementsPermit.js +0 -50
- package/lib/cjs/actions/requirements/generalAdapter/getGeneralAdapterRequirementsPermit2.d.ts +0 -57
- package/lib/cjs/actions/requirements/generalAdapter/getGeneralAdapterRequirementsPermit2.js +0 -74
- package/lib/cjs/actions/requirements/generalAdapter/index.d.ts +0 -3
- package/lib/cjs/actions/requirements/generalAdapter/index.js +0 -19
- package/lib/cjs/actions/signatures/getBlueAuthorizationAction.d.ts +0 -29
- package/lib/cjs/actions/signatures/getBlueAuthorizationAction.js +0 -48
- package/lib/cjs/actions/signatures/getTokenRequirementActions.d.ts +0 -58
- package/lib/cjs/actions/signatures/getTokenRequirementActions.js +0 -119
- package/lib/cjs/actions/signatures/getVaultExitBundlesV1PermitStruct.d.ts +0 -44
- package/lib/cjs/actions/signatures/getVaultExitBundlesV1PermitStruct.js +0 -43
- package/lib/cjs/actions/signatures/index.d.ts +0 -3
- package/lib/cjs/actions/signatures/index.js +0 -19
- package/lib/cjs/augment/VaultMarketPublicAllocatorConfig.d.ts +0 -8
- package/lib/cjs/augment/VaultMarketPublicAllocatorConfig.js +0 -8
- package/lib/cjs/bundler/actions.d.ts +0 -797
- package/lib/cjs/bundler/actions.js +0 -1371
- package/lib/cjs/bundler/index.d.ts +0 -2
- package/lib/cjs/bundler/index.js +0 -18
- package/lib/cjs/bundler/types.d.ts +0 -235
- package/lib/cjs/bundler/types.js +0 -2
- package/lib/cjs/entities/vaultV1ReallocationData.d.ts +0 -326
- package/lib/cjs/entities/vaultV1ReallocationData.js +0 -542
- package/lib/cjs/helpers/computeVaultV1Reallocations.d.ts +0 -78
- package/lib/cjs/helpers/computeVaultV1Reallocations.js +0 -243
- package/lib/esm/actions/requirements/encode/encodeErc20Permit2Approve.d.ts +0 -42
- package/lib/esm/actions/requirements/encode/encodeErc20Permit2Approve.js +0 -79
- package/lib/esm/actions/requirements/generalAdapter/getGeneralAdapterRequirements.d.ts +0 -88
- package/lib/esm/actions/requirements/generalAdapter/getGeneralAdapterRequirements.js +0 -147
- package/lib/esm/actions/requirements/generalAdapter/getGeneralAdapterRequirementsPermit.d.ts +0 -37
- package/lib/esm/actions/requirements/generalAdapter/getGeneralAdapterRequirementsPermit.js +0 -46
- package/lib/esm/actions/requirements/generalAdapter/getGeneralAdapterRequirementsPermit2.d.ts +0 -57
- package/lib/esm/actions/requirements/generalAdapter/getGeneralAdapterRequirementsPermit2.js +0 -70
- package/lib/esm/actions/requirements/generalAdapter/index.d.ts +0 -3
- package/lib/esm/actions/requirements/generalAdapter/index.js +0 -3
- package/lib/esm/actions/signatures/getBlueAuthorizationAction.d.ts +0 -29
- package/lib/esm/actions/signatures/getBlueAuthorizationAction.js +0 -44
- package/lib/esm/actions/signatures/getTokenRequirementActions.d.ts +0 -58
- package/lib/esm/actions/signatures/getTokenRequirementActions.js +0 -115
- package/lib/esm/actions/signatures/getVaultExitBundlesV1PermitStruct.d.ts +0 -44
- package/lib/esm/actions/signatures/getVaultExitBundlesV1PermitStruct.js +0 -39
- package/lib/esm/actions/signatures/index.d.ts +0 -3
- package/lib/esm/actions/signatures/index.js +0 -3
- package/lib/esm/augment/VaultMarketPublicAllocatorConfig.d.ts +0 -8
- package/lib/esm/augment/VaultMarketPublicAllocatorConfig.js +0 -5
- package/lib/esm/bundler/actions.d.ts +0 -797
- package/lib/esm/bundler/actions.js +0 -1368
- package/lib/esm/bundler/index.d.ts +0 -2
- package/lib/esm/bundler/index.js +0 -2
- package/lib/esm/bundler/types.d.ts +0 -235
- package/lib/esm/bundler/types.js +0 -1
- package/lib/esm/entities/vaultV1ReallocationData.d.ts +0 -326
- package/lib/esm/entities/vaultV1ReallocationData.js +0 -544
- package/lib/esm/helpers/computeVaultV1Reallocations.d.ts +0 -78
- package/lib/esm/helpers/computeVaultV1Reallocations.js +0 -239
- /package/lib/cjs/{actions/requirements/blue → entities/requirements}/getUnusedPermit2Nonce.d.ts +0 -0
- /package/lib/esm/{actions/requirements/blue → entities/requirements}/getUnusedPermit2Nonce.d.ts +0 -0
|
@@ -1,13 +1,12 @@
|
|
|
1
1
|
import { MathLib, } from "@morpho-org/blue-sdk";
|
|
2
|
-
import { fetchAccrualPosition, fetchAccrualVaultV2, fetchMarket,
|
|
2
|
+
import { fetchAccrualPosition, fetchAccrualVaultV2, fetchMarket, fetchVaultV2BluePublicAllocatorData, } from "@morpho-org/blue-sdk-viem";
|
|
3
3
|
import { getChainAddress, Time } from "@morpho-org/morpho-ts";
|
|
4
|
-
import {
|
|
4
|
+
import { isAddressEqual, maxUint256 } from "viem";
|
|
5
5
|
import { getBlueBundlesV1PenaltyAssets, getBlueBundlesV1PublicAllocations, getBlueBundlesV1ReferralFeeAssets, normalizeBlueBundlesV1CommonParams, selectBlueBundlesV1RequirementSignatures, validateBlueBundlesV1NativeFunding, } from "../../actions/blue/common.js";
|
|
6
6
|
import { blueBorrow, blueRefinance, blueRepay, blueRepayWithdrawCollateral, blueSupply, blueSupplyCollateral, blueSupplyCollateralBorrow, blueWithdraw, blueWithdrawCollateral, getBlueAuthorizationRequirement, } from "../../actions/index.js";
|
|
7
|
-
import {
|
|
7
|
+
import { DEFAULT_LLTV_BUFFER, validateAccrualPosition, validateChainId, validatePositionHealth, validatePositionHealthAfterWithdraw, validateRepayAmount, validateRepayShares, validateWithdrawAmount, validateWithdrawShares, } from "../../helpers/index.js";
|
|
8
8
|
import { ExpiredDeadlineError, InputExceedsMaxError, MaxRepayAssetsBelowRepayAssetsError, MissingAccrualPositionError, MutuallyExclusiveRepayAmountsError, MutuallyExclusiveWithdrawAmountsError, NegativeInputError, NonPositiveInputError, ReallocationsRequireBorrowError, RefinanceSameMarketError, RefinanceTokenMismatchError, } from "../../types/index.js";
|
|
9
9
|
import { getBundlesTokenRequirements } from "../requirements/index.js";
|
|
10
|
-
import { VaultV1ReallocationData } from "../vaultV1ReallocationData.js";
|
|
11
10
|
import { VaultV2BlueReallocationData } from "../vaultV2BlueReallocationData.js";
|
|
12
11
|
export class MorphoBlue {
|
|
13
12
|
client;
|
|
@@ -78,7 +77,6 @@ export class MorphoBlue {
|
|
|
78
77
|
validateChainId(this.client.viemClient.chain?.id, this.chainId);
|
|
79
78
|
return fetchMarket(this.marketParams.id, this.client.viemClient, {
|
|
80
79
|
...parameters,
|
|
81
|
-
chainId: this.chainId,
|
|
82
80
|
deployless: this.client.options.supportDeployless,
|
|
83
81
|
});
|
|
84
82
|
}
|
|
@@ -87,7 +85,6 @@ export class MorphoBlue {
|
|
|
87
85
|
return fetchAccrualPosition(userAddress, this.marketParams.id, this.client.viemClient, {
|
|
88
86
|
...parameters,
|
|
89
87
|
deployless: this.client.options.supportDeployless,
|
|
90
|
-
chainId: this.chainId,
|
|
91
88
|
});
|
|
92
89
|
}
|
|
93
90
|
/** {@inheritDoc BlueActions.supply} */
|
|
@@ -438,14 +435,7 @@ export class MorphoBlue {
|
|
|
438
435
|
? this.getTokenRequirements({
|
|
439
436
|
token: this.marketParams.loanToken,
|
|
440
437
|
amount: maxRepayAssets,
|
|
441
|
-
|
|
442
|
-
// the token's reusable cap. Checksum the key so a differently-cased loan token
|
|
443
|
-
// (common from subgraphs/APIs) resolves that cap instead of falling back to
|
|
444
|
-
// maxUint256, which UNI/ONDO/COMP/FLUID reject.
|
|
445
|
-
approvalAmount: requirementsParams?.approvalAmount ??
|
|
446
|
-
(saturatedRepay
|
|
447
|
-
? (MAX_TOKEN_APPROVALS[this.chainId]?.[getAddress(this.marketParams.loanToken)] ?? maxUint256)
|
|
448
|
-
: undefined),
|
|
438
|
+
approvalAmount: requirementsParams?.approvalAmount,
|
|
449
439
|
userAddress,
|
|
450
440
|
deadline,
|
|
451
441
|
useSimplePermit: requirementsParams?.useSimplePermit,
|
|
@@ -659,120 +649,6 @@ export class MorphoBlue {
|
|
|
659
649
|
},
|
|
660
650
|
};
|
|
661
651
|
}
|
|
662
|
-
/**
|
|
663
|
-
* Fetches all on-chain inputs needed to compute public allocator reallocations.
|
|
664
|
-
*
|
|
665
|
-
* @param params.vaultAddresses - Vaults to inspect for source-market liquidity.
|
|
666
|
-
* @param params.block.number - Block number used for every RPC read.
|
|
667
|
-
* @param params.block.timestamp - Timestamp corresponding to the fetched block.
|
|
668
|
-
* @returns Reallocation data ready for {@link getVaultV1Reallocations}.
|
|
669
|
-
* @throws {ChainIdMismatchError} when the client chain does not match this market.
|
|
670
|
-
* @deprecated Vault V1 shared-liquidity planning will be removed in the next major. Use
|
|
671
|
-
* {@link getVaultV2BlueReallocationData}.
|
|
672
|
-
* @example
|
|
673
|
-
* ```ts
|
|
674
|
-
* import { markets, vaults } from "@morpho-org/morpho-test";
|
|
675
|
-
* import { createPublicClient, http } from "viem";
|
|
676
|
-
* import { mainnet } from "viem/chains";
|
|
677
|
-
* import { morphoViemExtension } from "@morpho-org/morpho-sdk";
|
|
678
|
-
* import type { VaultV1ReallocationData } from "@morpho-org/morpho-sdk/entities";
|
|
679
|
-
*
|
|
680
|
-
* const client = createPublicClient({ chain: mainnet, transport: http() })
|
|
681
|
-
* .extend(morphoViemExtension());
|
|
682
|
-
* const market = client.morpho.blue(markets[mainnet.id].usdc_wbtc, mainnet.id);
|
|
683
|
-
* const block = await client.getBlock();
|
|
684
|
-
* const data: VaultV1ReallocationData = await market.getVaultV1ReallocationData({
|
|
685
|
-
* vaultAddresses: [vaults[mainnet.id].steakUsdc.address],
|
|
686
|
-
* block,
|
|
687
|
-
* });
|
|
688
|
-
* ```
|
|
689
|
-
*/
|
|
690
|
-
async getVaultV1ReallocationData({ vaultAddresses, block, }) {
|
|
691
|
-
validateChainId(this.client.viemClient.chain?.id, this.chainId);
|
|
692
|
-
const client = this.client.viemClient;
|
|
693
|
-
const fetchParams = {
|
|
694
|
-
blockNumber: block.number,
|
|
695
|
-
chainId: this.chainId,
|
|
696
|
-
deployless: this.client.options.supportDeployless,
|
|
697
|
-
};
|
|
698
|
-
const targetMarketId = this.marketParams.id;
|
|
699
|
-
// Phase 1: Fetch the target market and all vaults at `block.number` in
|
|
700
|
-
// parallel so every row of the resulting state comes from the same epoch
|
|
701
|
-
// and the planner never trusts a caller-owned target-market snapshot.
|
|
702
|
-
const [targetMarket, vaults] = await Promise.all([
|
|
703
|
-
fetchMarket(targetMarketId, client, fetchParams),
|
|
704
|
-
Promise.all(vaultAddresses.map((addr) => fetchVault(addr, client, fetchParams))),
|
|
705
|
-
]);
|
|
706
|
-
const allMarketIds = new Set([targetMarketId]);
|
|
707
|
-
const vaultMarketPairs = [];
|
|
708
|
-
for (const vault of vaults) {
|
|
709
|
-
// Always include target market pair so its config/position is fetched
|
|
710
|
-
// even when the target market is only in the vault's supplyQueue.
|
|
711
|
-
vaultMarketPairs.push({ vault: vault.address, marketId: targetMarketId });
|
|
712
|
-
for (const mid of vault.withdrawQueue) {
|
|
713
|
-
allMarketIds.add(mid);
|
|
714
|
-
if (mid !== targetMarketId) {
|
|
715
|
-
vaultMarketPairs.push({ vault: vault.address, marketId: mid });
|
|
716
|
-
}
|
|
717
|
-
}
|
|
718
|
-
}
|
|
719
|
-
// Phase 2: Fetch all source markets, vault configs, and positions in parallel.
|
|
720
|
-
const sourceMarketIds = [...allMarketIds].filter((mid) => mid !== targetMarketId);
|
|
721
|
-
const [markets, configs, positions] = await Promise.all([
|
|
722
|
-
Promise.all(sourceMarketIds.map((mid) => fetchMarket(mid, client, fetchParams))),
|
|
723
|
-
Promise.all(vaultMarketPairs.map(({ vault, marketId: mid }) => fetchVaultMarketConfig(vault, mid, client, fetchParams).then((config) => ({ vault, mid, config })))),
|
|
724
|
-
Promise.all(vaultMarketPairs.map(({ vault, marketId: mid }) => fetchPosition(vault, mid, client, fetchParams).then((position) => ({
|
|
725
|
-
vault,
|
|
726
|
-
mid,
|
|
727
|
-
position,
|
|
728
|
-
})))),
|
|
729
|
-
]);
|
|
730
|
-
// Assemble records for VaultV1ReallocationData.
|
|
731
|
-
const marketsRecord = {
|
|
732
|
-
[targetMarketId]: targetMarket,
|
|
733
|
-
};
|
|
734
|
-
for (const m of markets) {
|
|
735
|
-
marketsRecord[m.id] = m;
|
|
736
|
-
}
|
|
737
|
-
const vaultsRecord = {};
|
|
738
|
-
for (const v of vaults) {
|
|
739
|
-
vaultsRecord[v.address] = v;
|
|
740
|
-
}
|
|
741
|
-
const vaultMarketConfigsRecord = {};
|
|
742
|
-
for (const { vault, mid, config } of configs) {
|
|
743
|
-
(vaultMarketConfigsRecord[vault] ??= {})[mid] = config;
|
|
744
|
-
}
|
|
745
|
-
const positionsRecord = {};
|
|
746
|
-
for (const { vault, mid, position } of positions) {
|
|
747
|
-
(positionsRecord[vault] ??= {})[mid] = position;
|
|
748
|
-
}
|
|
749
|
-
return new VaultV1ReallocationData({
|
|
750
|
-
chainId: this.chainId,
|
|
751
|
-
markets: marketsRecord,
|
|
752
|
-
vaults: vaultsRecord,
|
|
753
|
-
vaultMarketConfigs: vaultMarketConfigsRecord,
|
|
754
|
-
positions: positionsRecord,
|
|
755
|
-
});
|
|
756
|
-
}
|
|
757
|
-
/**
|
|
758
|
-
* Fetches Vault V1 PublicAllocator state using the deprecated unversioned name.
|
|
759
|
-
*
|
|
760
|
-
* @param params.vaultAddresses - Addresses of MetaMorpho vaults that allocate to this market.
|
|
761
|
-
* @param params.block.number - Block number used for every RPC read.
|
|
762
|
-
* @param params.block.timestamp - Timestamp corresponding to the fetched block.
|
|
763
|
-
* @returns A `VaultV1ReallocationData` snapshot populated from one block.
|
|
764
|
-
* @throws {ChainIdMismatchError} when the client chain does not match this market.
|
|
765
|
-
* @deprecated Vault V1 shared-liquidity planning will be removed in the next major. Use
|
|
766
|
-
* {@link getVaultV2BlueReallocationData}.
|
|
767
|
-
* @example
|
|
768
|
-
* ```ts
|
|
769
|
-
* const data = await market.getReallocationData({ vaultAddresses, block });
|
|
770
|
-
* // Equivalent to market.getVaultV1ReallocationData({ vaultAddresses, block }).
|
|
771
|
-
* ```
|
|
772
|
-
*/
|
|
773
|
-
getReallocationData(params) {
|
|
774
|
-
return this.getVaultV1ReallocationData(params);
|
|
775
|
-
}
|
|
776
652
|
/**
|
|
777
653
|
* Fetches Vault V2 BluePublicAllocator state for this target market.
|
|
778
654
|
*
|
|
@@ -851,84 +727,6 @@ export class MorphoBlue {
|
|
|
851
727
|
])),
|
|
852
728
|
});
|
|
853
729
|
}
|
|
854
|
-
/**
|
|
855
|
-
* Computes Vault V1 PublicAllocator reallocations for this market.
|
|
856
|
-
*
|
|
857
|
-
* Pass `{ borrowAmount }` for a borrow (legacy alias, equivalent to `{ operation: "borrow", amount }`)
|
|
858
|
-
* or `{ operation, amount }` for a borrow or loan-asset withdraw.
|
|
859
|
-
*
|
|
860
|
-
* @param params - Reallocation computation parameters.
|
|
861
|
-
* @param params.reallocationData - State returned by {@link getVaultV1ReallocationData}.
|
|
862
|
-
* @param params.operation - The operation driving the reallocation (`"borrow"` or `"withdraw"`).
|
|
863
|
-
* @param params.amount - The borrow or withdraw amount used to compute the post-state utilization.
|
|
864
|
-
* @param params.borrowAmount - {@deprecated Pass `{ operation: "borrow", amount }` instead.}
|
|
865
|
-
* @param params.options - Optional allocator and utilization options.
|
|
866
|
-
* @returns Vault V1 reallocations for explicit low-level Bundler3 composition.
|
|
867
|
-
* @throws {ChainIdMismatchError} when `reallocationData` belongs to a different chain than this market.
|
|
868
|
-
* @throws {InsufficientSharedLiquidityError} when shared liquidity cannot cover the operation's absolute shortfall on the target market.
|
|
869
|
-
* @throws {ReallocationWithdrawExceedsMarketSupplyError} when `operation === "withdraw"` and `amount` exceeds the target market's `totalSupplyAssets`.
|
|
870
|
-
* @throws {MissingPublicAllocatorConfigError} when a selected vault is missing its public allocator config.
|
|
871
|
-
* @throws {UnknownReallocationMarketError} when the target market is absent from the reallocation data.
|
|
872
|
-
* @deprecated Vault V1 shared-liquidity planning will be removed in the next major. Use
|
|
873
|
-
* {@link getVaultV2BlueReallocations}.
|
|
874
|
-
* @example
|
|
875
|
-
* ```ts
|
|
876
|
-
* const reallocations = market.getVaultV1Reallocations({
|
|
877
|
-
* reallocationData,
|
|
878
|
-
* operation: "borrow",
|
|
879
|
-
* amount: 1_000_000n,
|
|
880
|
-
* });
|
|
881
|
-
* ```
|
|
882
|
-
*/
|
|
883
|
-
getVaultV1Reallocations(params) {
|
|
884
|
-
validateChainId(params.reallocationData.chainId, this.chainId);
|
|
885
|
-
const marketId = this.marketParams.id;
|
|
886
|
-
const options = { enabled: true, ...params.options };
|
|
887
|
-
if (params.borrowAmount !== undefined) {
|
|
888
|
-
return computeVaultV1Reallocations({
|
|
889
|
-
reallocationData: params.reallocationData,
|
|
890
|
-
marketId,
|
|
891
|
-
operation: "borrow",
|
|
892
|
-
amount: params.borrowAmount,
|
|
893
|
-
options,
|
|
894
|
-
});
|
|
895
|
-
}
|
|
896
|
-
return computeVaultV1Reallocations({
|
|
897
|
-
reallocationData: params.reallocationData,
|
|
898
|
-
marketId,
|
|
899
|
-
operation: params.operation,
|
|
900
|
-
amount: params.amount,
|
|
901
|
-
options,
|
|
902
|
-
});
|
|
903
|
-
}
|
|
904
|
-
/**
|
|
905
|
-
* Computes Vault V1 PublicAllocator reallocations using the deprecated unversioned name.
|
|
906
|
-
*
|
|
907
|
-
* @param params.reallocationData - State returned by {@link getVaultV1ReallocationData}.
|
|
908
|
-
* @param params.operation - The operation driving the reallocation (`"borrow"` or `"withdraw"`).
|
|
909
|
-
* @param params.amount - The borrow or withdraw amount used to compute post-state utilization.
|
|
910
|
-
* @param params.borrowAmount - Deprecated borrow amount alias.
|
|
911
|
-
* @param params.options - Optional allocator and utilization options.
|
|
912
|
-
* @returns Vault V1 reallocations for explicit low-level Bundler3 composition.
|
|
913
|
-
* @throws {ChainIdMismatchError} when `reallocationData` belongs to another chain.
|
|
914
|
-
* @throws {InsufficientSharedLiquidityError} when shared liquidity cannot cover the operation.
|
|
915
|
-
* @throws {ReallocationWithdrawExceedsMarketSupplyError} when a withdrawal exceeds market supply.
|
|
916
|
-
* @throws {MissingPublicAllocatorConfigError} when a selected vault lacks allocator state.
|
|
917
|
-
* @throws {UnknownReallocationMarketError} when the target market is absent.
|
|
918
|
-
* @deprecated Vault V1 shared-liquidity planning will be removed in the next major. Use
|
|
919
|
-
* {@link getVaultV2BlueReallocations}.
|
|
920
|
-
* @example
|
|
921
|
-
* ```ts
|
|
922
|
-
* const reallocations = market.getReallocations({
|
|
923
|
-
* reallocationData,
|
|
924
|
-
* operation: "borrow",
|
|
925
|
-
* amount: 1_000_000n,
|
|
926
|
-
* });
|
|
927
|
-
* ```
|
|
928
|
-
*/
|
|
929
|
-
getReallocations(params) {
|
|
930
|
-
return this.getVaultV1Reallocations(params);
|
|
931
|
-
}
|
|
932
730
|
/**
|
|
933
731
|
* Computes Vault V2 BluePublicAllocator reallocations for this market.
|
|
934
732
|
*
|
|
@@ -936,6 +734,7 @@ export class MorphoBlue {
|
|
|
936
734
|
* @param params.options - Optional allocator discovery controls and operation to support.
|
|
937
735
|
* @returns Action-ready reallocations and their post-simulation state.
|
|
938
736
|
* @throws {ChainIdMismatchError} when `reallocationData` belongs to another chain.
|
|
737
|
+
* @throws {UnsupportedBlueMarketIrmError} when a market with positive debt uses an unsupported IRM.
|
|
939
738
|
* @throws {NegativeInputError} when a utilization or penalty limit is negative.
|
|
940
739
|
* @throws {InputExceedsMaxError} when a utilization or penalty limit exceeds WAD.
|
|
941
740
|
* @throws {NonPositiveInputError} when an enabled operation amount is not positive.
|
|
@@ -1,69 +1,12 @@
|
|
|
1
|
-
export type { IAccrualPosition as IBlueAccrualPosition,
|
|
2
|
-
|
|
3
|
-
IAccrualPosition, IAccrualVault, IAccrualVaultV2, IAccrualVaultV2Adapter, IAccrualVaultV2MorphoMarketV1Adapter, IAccrualVaultV2MorphoMarketV1AdapterV2, IAccrualVaultV2MorphoVaultV1Adapter, IAssetBalances, IEip5267Domain, IHolding, IMarket as IBlueMarket,
|
|
4
|
-
/** @deprecated Use `IBlueMarket` or the raw Blue subpath. */
|
|
5
|
-
IMarket, IMarketParams as IBlueMarketParams,
|
|
6
|
-
/** @deprecated Use `IBlueMarketParams` or the raw Blue subpath. */
|
|
7
|
-
IMarketParams, IPosition as IBluePosition,
|
|
8
|
-
/** @deprecated Use `IBluePosition` or the raw Blue subpath. */
|
|
9
|
-
IPosition, IPreLiquidationParams as IBluePreLiquidationParams,
|
|
10
|
-
/** @deprecated Use `IBluePreLiquidationParams` or the raw Blue subpath. */
|
|
11
|
-
IPreLiquidationParams, IPreLiquidationPosition as IBluePreLiquidationPosition,
|
|
12
|
-
/** @deprecated Use `IBluePreLiquidationPosition` or the raw Blue subpath. */
|
|
13
|
-
IPreLiquidationPosition, IToken, IVault, IVaultConfig, IVaultMarketAllocation, IVaultMarketConfig, IVaultMarketPublicAllocatorConfig, IVaultToken, IVaultUser, IVaultV2, IVaultV2Adapter, IVaultV2Allocation, IVaultV2BlueMarketPublicAllocatorConfig, IVaultV2BluePublicAllocatorConfig, IVaultV2MorphoMarketV1Adapter, IVaultV2MorphoMarketV1AdapterV2, IVaultV2MorphoVaultV1Adapter, PeripheralBalance, PeripheralBalanceType, VaultPublicAllocatorConfig, } from "@morpho-org/blue-sdk";
|
|
14
|
-
export { AccrualPosition as BlueAccrualPosition,
|
|
15
|
-
/** @deprecated Use `BlueAccrualPosition` or the raw Blue subpath. */
|
|
16
|
-
AccrualPosition, AccrualVault, AccrualVaultV2, AccrualVaultV2MorphoMarketV1Adapter, AccrualVaultV2MorphoMarketV1AdapterV2, AccrualVaultV2MorphoVaultV1Adapter, AssetBalances, ConstantWrappedToken, Eip5267Domain, ExchangeRateWrappedToken, Holding, Market as BlueMarket,
|
|
17
|
-
/** @deprecated Use `BlueMarket` or the raw Blue subpath. */
|
|
18
|
-
Market, MarketParams as BlueMarketParams,
|
|
19
|
-
/** @deprecated Use `BlueMarketParams` or the raw Blue subpath. */
|
|
20
|
-
MarketParams, Position as BluePosition,
|
|
21
|
-
/** @deprecated Use `BluePosition` or the raw Blue subpath. */
|
|
22
|
-
Position, PreLiquidationParams as BluePreLiquidationParams,
|
|
23
|
-
/** @deprecated Use `BluePreLiquidationParams` or the raw Blue subpath. */
|
|
24
|
-
PreLiquidationParams, PreLiquidationPosition as BluePreLiquidationPosition,
|
|
25
|
-
/** @deprecated Use `BluePreLiquidationPosition` or the raw Blue subpath. */
|
|
26
|
-
PreLiquidationPosition, Token, User as BlueUser,
|
|
27
|
-
/** @deprecated Use `BlueUser` or the raw Blue subpath. */
|
|
28
|
-
User, Vault, VaultConfig, VaultMarketAllocation, VaultMarketConfig, VaultMarketPublicAllocatorConfig, VaultToken, VaultUser, VaultV2, VaultV2Adapter, VaultV2BlueMarketPublicAllocatorConfig, VaultV2BluePublicAllocatorConfig, VaultV2MorphoMarketV1Adapter, VaultV2MorphoMarketV1AdapterV2, VaultV2MorphoVaultV1Adapter, WrappedToken, } from "@morpho-org/blue-sdk";
|
|
1
|
+
export type { IAccrualPosition as IBlueAccrualPosition, IAccrualVault, IAccrualVaultV2, IAccrualVaultV2Adapter, IAccrualVaultV2MorphoMarketV1Adapter, IAccrualVaultV2MorphoMarketV1AdapterV2, IAccrualVaultV2MorphoVaultV1Adapter, IAssetBalances, IEip5267Domain, IHolding, IMarket as IBlueMarket, IMarketParams as IBlueMarketParams, IPosition as IBluePosition, IPreLiquidationParams as IBluePreLiquidationParams, IPreLiquidationPosition as IBluePreLiquidationPosition, IToken, IVault, IVaultConfig, IVaultMarketAllocation, IVaultMarketConfig, IVaultToken, IVaultUser, IVaultV2, IVaultV2Adapter, IVaultV2Allocation, IVaultV2BlueMarketPublicAllocatorConfig, IVaultV2BluePublicAllocatorConfig, IVaultV2MorphoMarketV1Adapter, IVaultV2MorphoMarketV1AdapterV2, IVaultV2MorphoVaultV1Adapter, PeripheralBalance, PeripheralBalanceType, } from "@morpho-org/blue-sdk";
|
|
2
|
+
export { AccrualPosition as BlueAccrualPosition, AccrualVault, AccrualVaultV2, AccrualVaultV2MorphoMarketV1Adapter, AccrualVaultV2MorphoMarketV1AdapterV2, AccrualVaultV2MorphoVaultV1Adapter, AssetBalances, ConstantWrappedToken, Eip5267Domain, ExchangeRateWrappedToken, Holding, Market as BlueMarket, MarketParams as BlueMarketParams, Position as BluePosition, PreLiquidationParams as BluePreLiquidationParams, PreLiquidationPosition as BluePreLiquidationPosition, Token, User as BlueUser, Vault, VaultConfig, VaultMarketAllocation, VaultMarketConfig, VaultToken, VaultUser, VaultV2, VaultV2Adapter, VaultV2BlueMarketPublicAllocatorConfig, VaultV2BluePublicAllocatorConfig, VaultV2MorphoMarketV1Adapter, VaultV2MorphoMarketV1AdapterV2, VaultV2MorphoVaultV1Adapter, WrappedToken, } from "@morpho-org/blue-sdk";
|
|
29
3
|
export type { BuildOfferParams as MidnightBuildOfferParams, CollateralParams as MidnightCollateralParams, GroupInput as MidnightGroupInput, IAccrualPosition as IMidnightAccrualPosition, ICollateralParams as IMidnightCollateralParams, IGroup as IMidnightGroup, IMarket as IMidnightMarket, IMarketParams as IMidnightMarketParams, IOffer as IMidnightOffer, IPosition as IMidnightPosition, MarketInput as MidnightMarketInput, OfferStruct as MidnightOfferStruct, RatifierTreeInput as MidnightRatifierTreeInput, SettlementFeeCbps as MidnightSettlementFeeCbps, TreeCreateParams as MidnightTreeCreateParams, TreeDescriptor as MidnightTreeDescriptor, TreeInput as MidnightTreeInput, TreeLike as MidnightTreeLike, TreeMempoolValidateParams as MidnightTreeMempoolValidateParams, TreeMempoolValidateRatification as MidnightTreeMempoolValidateRatification, TreeProof as MidnightTreeProof, } from "@morpho-org/midnight-sdk";
|
|
30
4
|
export { AccrualPosition as MidnightAccrualPosition, Group as MidnightGroup, Market as MidnightMarket, MarketParams as MidnightMarketParams, Offer as MidnightOffer, Position as MidnightPosition, Tree as MidnightTree, } from "@morpho-org/midnight-sdk";
|
|
31
5
|
export type { BlueActions, BlueTokenRequirementsParams, } from "./blue/index.js";
|
|
32
6
|
export { MorphoBlue } from "./blue/index.js";
|
|
33
|
-
export type { GetOffersDataParams as MidnightGetOffersDataParams,
|
|
34
|
-
/** @deprecated Use `MidnightGetOffersDataParams`. */
|
|
35
|
-
GetOffersDataParams, GetPositionDataParams as MidnightGetPositionDataParams,
|
|
36
|
-
/** @deprecated Use `MidnightGetPositionDataParams`. */
|
|
37
|
-
GetPositionDataParams, MakeLendParams as MidnightMakeLendParams,
|
|
38
|
-
/** @deprecated Use `MidnightMakeLendParams`. */
|
|
39
|
-
MakeLendParams, MakeOffersOutput as MidnightMakeOffersOutput,
|
|
40
|
-
/** @deprecated Use `MidnightMakeOffersOutput`. */
|
|
41
|
-
MakeOffersOutput, MakeOffersParams as MidnightMakeOffersParams,
|
|
42
|
-
/** @deprecated Use `MidnightMakeOffersParams`. */
|
|
43
|
-
MakeOffersParams, MarketActionParams as MidnightMarketActionParams,
|
|
44
|
-
/** @deprecated Use `MidnightMarketActionParams`. */
|
|
45
|
-
MarketActionParams, OffersData as MidnightOffersData,
|
|
46
|
-
/** @deprecated Use `MidnightOffersData`. */
|
|
47
|
-
OffersData, OfferValidationParams as MidnightOfferValidationParams,
|
|
48
|
-
/** @deprecated Use `MidnightOfferValidationParams`. */
|
|
49
|
-
OfferValidationParams, RedeemParams as MidnightRedeemParams,
|
|
50
|
-
/** @deprecated Use `MidnightRedeemParams`. */
|
|
51
|
-
RedeemParams, RepayWithdrawCollateralParams as MidnightRepayWithdrawCollateralParams,
|
|
52
|
-
/** @deprecated Use `MidnightRepayWithdrawCollateralParams`. */
|
|
53
|
-
RepayWithdrawCollateralParams, SupplyCollateralMakeBorrowParams as MidnightSupplyCollateralMakeBorrowParams,
|
|
54
|
-
/** @deprecated Use `MidnightSupplyCollateralMakeBorrowParams`. */
|
|
55
|
-
SupplyCollateralMakeBorrowParams, SupplyCollateralParams as MidnightSupplyCollateralParams,
|
|
56
|
-
/** @deprecated Use `MidnightSupplyCollateralParams`. */
|
|
57
|
-
SupplyCollateralParams, SupplyCollateralTakeBorrowParams as MidnightSupplyCollateralTakeBorrowParams,
|
|
58
|
-
/** @deprecated Use `MidnightSupplyCollateralTakeBorrowParams`. */
|
|
59
|
-
SupplyCollateralTakeBorrowParams, TakeBorrowParams as MidnightTakeBorrowParams,
|
|
60
|
-
/** @deprecated Use `MidnightTakeBorrowParams`. */
|
|
61
|
-
TakeBorrowParams, TakeLendParams as MidnightTakeLendParams,
|
|
62
|
-
/** @deprecated Use `MidnightTakeLendParams`. */
|
|
63
|
-
TakeLendParams, } from "./midnight/index.js";
|
|
7
|
+
export type { GetOffersDataParams as MidnightGetOffersDataParams, GetPositionDataParams as MidnightGetPositionDataParams, MakeLendParams as MidnightMakeLendParams, MakeOffersOutput as MidnightMakeOffersOutput, MakeOffersParams as MidnightMakeOffersParams, MarketActionParams as MidnightMarketActionParams, OffersData as MidnightOffersData, OfferValidationParams as MidnightOfferValidationParams, RedeemParams as MidnightRedeemParams, RepayWithdrawCollateralParams as MidnightRepayWithdrawCollateralParams, SupplyCollateralMakeBorrowParams as MidnightSupplyCollateralMakeBorrowParams, SupplyCollateralParams as MidnightSupplyCollateralParams, SupplyCollateralTakeBorrowParams as MidnightSupplyCollateralTakeBorrowParams, TakeBorrowParams as MidnightTakeBorrowParams, TakeLendParams as MidnightTakeLendParams, } from "./midnight/index.js";
|
|
64
8
|
export { type MidnightActionOutput, type MidnightActionSignatures, type MidnightActions, MorphoMidnight, } from "./midnight/index.js";
|
|
65
9
|
export * from "./requirements/index.js";
|
|
66
10
|
export { MorphoVaultV1 } from "./vaultV1/index.js";
|
|
67
|
-
export { type InputReallocationData, type InputVaultV1ReallocationData, ReallocationData, VaultV1ReallocationData, } from "./vaultV1ReallocationData.js";
|
|
68
11
|
export { MorphoVaultV2 } from "./vaultV2/index.js";
|
|
69
12
|
export { type InputVaultV2BlueReallocationData, VaultV2BlueReallocationData, } from "./vaultV2BlueReallocationData.js";
|
|
@@ -1,23 +1,8 @@
|
|
|
1
|
-
export { AccrualPosition as BlueAccrualPosition,
|
|
2
|
-
/** @deprecated Use `BlueAccrualPosition` or the raw Blue subpath. */
|
|
3
|
-
AccrualPosition, AccrualVault, AccrualVaultV2, AccrualVaultV2MorphoMarketV1Adapter, AccrualVaultV2MorphoMarketV1AdapterV2, AccrualVaultV2MorphoVaultV1Adapter, AssetBalances, ConstantWrappedToken, Eip5267Domain, ExchangeRateWrappedToken, Holding, Market as BlueMarket,
|
|
4
|
-
/** @deprecated Use `BlueMarket` or the raw Blue subpath. */
|
|
5
|
-
Market, MarketParams as BlueMarketParams,
|
|
6
|
-
/** @deprecated Use `BlueMarketParams` or the raw Blue subpath. */
|
|
7
|
-
MarketParams, Position as BluePosition,
|
|
8
|
-
/** @deprecated Use `BluePosition` or the raw Blue subpath. */
|
|
9
|
-
Position, PreLiquidationParams as BluePreLiquidationParams,
|
|
10
|
-
/** @deprecated Use `BluePreLiquidationParams` or the raw Blue subpath. */
|
|
11
|
-
PreLiquidationParams, PreLiquidationPosition as BluePreLiquidationPosition,
|
|
12
|
-
/** @deprecated Use `BluePreLiquidationPosition` or the raw Blue subpath. */
|
|
13
|
-
PreLiquidationPosition, Token, User as BlueUser,
|
|
14
|
-
/** @deprecated Use `BlueUser` or the raw Blue subpath. */
|
|
15
|
-
User, Vault, VaultConfig, VaultMarketAllocation, VaultMarketConfig, VaultMarketPublicAllocatorConfig, VaultToken, VaultUser, VaultV2, VaultV2Adapter, VaultV2BlueMarketPublicAllocatorConfig, VaultV2BluePublicAllocatorConfig, VaultV2MorphoMarketV1Adapter, VaultV2MorphoMarketV1AdapterV2, VaultV2MorphoVaultV1Adapter, WrappedToken, } from "@morpho-org/blue-sdk";
|
|
1
|
+
export { AccrualPosition as BlueAccrualPosition, AccrualVault, AccrualVaultV2, AccrualVaultV2MorphoMarketV1Adapter, AccrualVaultV2MorphoMarketV1AdapterV2, AccrualVaultV2MorphoVaultV1Adapter, AssetBalances, ConstantWrappedToken, Eip5267Domain, ExchangeRateWrappedToken, Holding, Market as BlueMarket, MarketParams as BlueMarketParams, Position as BluePosition, PreLiquidationParams as BluePreLiquidationParams, PreLiquidationPosition as BluePreLiquidationPosition, Token, User as BlueUser, Vault, VaultConfig, VaultMarketAllocation, VaultMarketConfig, VaultToken, VaultUser, VaultV2, VaultV2Adapter, VaultV2BlueMarketPublicAllocatorConfig, VaultV2BluePublicAllocatorConfig, VaultV2MorphoMarketV1Adapter, VaultV2MorphoMarketV1AdapterV2, VaultV2MorphoVaultV1Adapter, WrappedToken, } from "@morpho-org/blue-sdk";
|
|
16
2
|
export { AccrualPosition as MidnightAccrualPosition, Group as MidnightGroup, Market as MidnightMarket, MarketParams as MidnightMarketParams, Offer as MidnightOffer, Position as MidnightPosition, Tree as MidnightTree, } from "@morpho-org/midnight-sdk";
|
|
17
3
|
export { MorphoBlue } from "./blue/index.js";
|
|
18
4
|
export { MorphoMidnight, } from "./midnight/index.js";
|
|
19
5
|
export * from "./requirements/index.js";
|
|
20
6
|
export { MorphoVaultV1 } from "./vaultV1/index.js";
|
|
21
|
-
export { ReallocationData, VaultV1ReallocationData, } from "./vaultV1ReallocationData.js";
|
|
22
7
|
export { MorphoVaultV2 } from "./vaultV2/index.js";
|
|
23
8
|
export { VaultV2BlueReallocationData, } from "./vaultV2BlueReallocationData.js";
|
|
@@ -547,7 +547,6 @@ export class MorphoMidnight {
|
|
|
547
547
|
}
|
|
548
548
|
});
|
|
549
549
|
const midnight = getChainAddress(this.chainId, "midnight");
|
|
550
|
-
const signedPayloads = new Map();
|
|
551
550
|
return {
|
|
552
551
|
groups: data.groups,
|
|
553
552
|
root: data.tree.root,
|
|
@@ -564,14 +563,12 @@ export class MorphoMidnight {
|
|
|
564
563
|
})));
|
|
565
564
|
requirements.push(...(await this.getRatifierRequirements({
|
|
566
565
|
offersData: data,
|
|
567
|
-
signedPayloads,
|
|
568
566
|
})));
|
|
569
567
|
return requirements;
|
|
570
568
|
},
|
|
571
569
|
buildTx: (signatures) => this.buildSubmitOffersTx({
|
|
572
570
|
offersData: data,
|
|
573
571
|
signatures,
|
|
574
|
-
signedPayloads,
|
|
575
572
|
}),
|
|
576
573
|
};
|
|
577
574
|
}
|
|
@@ -602,7 +599,6 @@ export class MorphoMidnight {
|
|
|
602
599
|
validation: params.validation,
|
|
603
600
|
});
|
|
604
601
|
validateOfferSides(data.tree.offers, false);
|
|
605
|
-
const signedPayloads = new Map();
|
|
606
602
|
return {
|
|
607
603
|
groups: data.groups,
|
|
608
604
|
root: data.tree.root,
|
|
@@ -610,13 +606,11 @@ export class MorphoMidnight {
|
|
|
610
606
|
getRequirements: async () => {
|
|
611
607
|
return await this.getRatifierRequirements({
|
|
612
608
|
offersData: data,
|
|
613
|
-
signedPayloads,
|
|
614
609
|
});
|
|
615
610
|
},
|
|
616
611
|
buildTx: (signatures) => this.buildSubmitOffersTx({
|
|
617
612
|
offersData: data,
|
|
618
613
|
signatures,
|
|
619
|
-
signedPayloads,
|
|
620
614
|
}),
|
|
621
615
|
};
|
|
622
616
|
}
|
|
@@ -674,7 +668,6 @@ export class MorphoMidnight {
|
|
|
674
668
|
}
|
|
675
669
|
}
|
|
676
670
|
const midnight = getChainAddress(this.chainId, "midnight");
|
|
677
|
-
const signedPayloads = new Map();
|
|
678
671
|
return {
|
|
679
672
|
groups: data.groups,
|
|
680
673
|
root: data.tree.root,
|
|
@@ -699,7 +692,6 @@ export class MorphoMidnight {
|
|
|
699
692
|
}),
|
|
700
693
|
...(await this.getRatifierRequirements({
|
|
701
694
|
offersData: data,
|
|
702
|
-
signedPayloads,
|
|
703
695
|
})),
|
|
704
696
|
];
|
|
705
697
|
return requirements;
|
|
@@ -707,7 +699,6 @@ export class MorphoMidnight {
|
|
|
707
699
|
buildTx: (signatures) => this.buildSubmitOffersTx({
|
|
708
700
|
offersData: data,
|
|
709
701
|
signatures,
|
|
710
|
-
signedPayloads,
|
|
711
702
|
}),
|
|
712
703
|
};
|
|
713
704
|
}
|
|
@@ -907,6 +898,18 @@ export class MorphoMidnight {
|
|
|
907
898
|
requirements.push(authorization);
|
|
908
899
|
if (data.ratifierType === "ecrecover") {
|
|
909
900
|
const chainId = this.chainId;
|
|
901
|
+
// The offer-tree EIP-712 payload is signed over the tree, not the signer, so it is fully
|
|
902
|
+
// determined at build time and stored on the action for external signing.
|
|
903
|
+
const treeTypedData = EcrecoverRatifierUtils.typedData({
|
|
904
|
+
tree: data.tree,
|
|
905
|
+
chainId,
|
|
906
|
+
});
|
|
907
|
+
const typedData = deepFreeze({
|
|
908
|
+
domain: treeTypedData.domain,
|
|
909
|
+
types: treeTypedData.types,
|
|
910
|
+
primaryType: treeTypedData.primaryType,
|
|
911
|
+
message: treeTypedData.message,
|
|
912
|
+
});
|
|
910
913
|
const action = {
|
|
911
914
|
type: "midnightOfferRootSignature",
|
|
912
915
|
args: {
|
|
@@ -914,32 +917,23 @@ export class MorphoMidnight {
|
|
|
914
917
|
ratifier: data.ratifier,
|
|
915
918
|
offers: data.tree.offers.length,
|
|
916
919
|
},
|
|
920
|
+
typedData,
|
|
917
921
|
};
|
|
918
922
|
requirements.push({
|
|
919
923
|
action,
|
|
920
924
|
async sign(client, userAddress) {
|
|
921
|
-
const typedData = EcrecoverRatifierUtils.typedData({
|
|
922
|
-
tree: data.tree,
|
|
923
|
-
chainId,
|
|
924
|
-
});
|
|
925
|
-
const typedDataDefinition = {
|
|
926
|
-
domain: typedData.domain,
|
|
927
|
-
types: typedData.types,
|
|
928
|
-
primaryType: typedData.primaryType,
|
|
929
|
-
message: typedData.message,
|
|
930
|
-
};
|
|
931
925
|
const signature = await signAndVerifyTypedData({
|
|
932
926
|
client,
|
|
933
927
|
userAddress,
|
|
934
|
-
typedData
|
|
928
|
+
typedData,
|
|
935
929
|
});
|
|
930
|
+
// Derive the ratification payload `buildTx()` submits.
|
|
936
931
|
const items = await EcrecoverRatifierUtils.ratify({
|
|
937
932
|
tree: data.tree,
|
|
938
933
|
account: userAddress,
|
|
939
934
|
signature,
|
|
940
935
|
});
|
|
941
936
|
const payload = await Payload.encode(items);
|
|
942
|
-
params.signedPayloads.set(signature.toLowerCase(), payload);
|
|
943
937
|
return deepFreeze({
|
|
944
938
|
args: {
|
|
945
939
|
owner: userAddress,
|
|
@@ -1007,11 +1001,13 @@ export class MorphoMidnight {
|
|
|
1007
1001
|
actualOffers: signature.action.args.offers,
|
|
1008
1002
|
});
|
|
1009
1003
|
}
|
|
1010
|
-
|
|
1011
|
-
|
|
1004
|
+
// The payload is carried on the signature the caller hands to buildTx, so
|
|
1005
|
+
// a prepared offer-root requirement can be signed on one instance and
|
|
1006
|
+
// submitted from another without sharing in-memory state.
|
|
1007
|
+
if (signature.args.payload == null) {
|
|
1012
1008
|
throw new UnpreparedMidnightOfferRootSignatureError();
|
|
1013
1009
|
}
|
|
1014
|
-
payload =
|
|
1010
|
+
payload = signature.args.payload;
|
|
1015
1011
|
}
|
|
1016
1012
|
else {
|
|
1017
1013
|
selectRequirementSignatures(collectedSignatures, {});
|
|
@@ -22,7 +22,7 @@ export interface GetBundlesTokenRequirementsParams {
|
|
|
22
22
|
readonly supportDeployless?: boolean;
|
|
23
23
|
/** Prefer ERC-2612 when the token exposes a compatible nonce. */
|
|
24
24
|
readonly useSimplePermit?: boolean;
|
|
25
|
-
/** Explicit unused
|
|
25
|
+
/** Explicit unused uint256 nonce; defaults to the lowest unused nonce found via getUnusedPermit2Nonce. */
|
|
26
26
|
readonly permit2Nonce?: bigint;
|
|
27
27
|
}
|
|
28
28
|
/**
|
|
@@ -31,8 +31,8 @@ export interface GetBundlesTokenRequirementsParams {
|
|
|
31
31
|
*
|
|
32
32
|
* Reads only the allowance and nonce state required by the selected path. Permit2 keeps the
|
|
33
33
|
* ERC-20 allowance on canonical Permit2 while the one-time signed transfer names the bundles contract
|
|
34
|
-
* as spender.
|
|
35
|
-
*
|
|
34
|
+
* as spender. The resolver picks the lowest unused unordered nonce by default; concurrent flows for
|
|
35
|
+
* the same owner should pass explicit nonces.
|
|
36
36
|
*
|
|
37
37
|
* @param viemClient - Connected viem client used for allowance and nonce reads.
|
|
38
38
|
* @param params - Token requirement parameters.
|
|
@@ -46,7 +46,8 @@ export interface GetBundlesTokenRequirementsParams {
|
|
|
46
46
|
* @param params.supportSignature - Whether ERC-2612 or Permit2 signatures may be requested.
|
|
47
47
|
* @param params.supportDeployless - Whether ERC-2612 metadata reads may use deployless calls.
|
|
48
48
|
* @param params.useSimplePermit - Prefer ERC-2612 when its nonce probe succeeds.
|
|
49
|
-
* @param params.permit2Nonce - Explicit unused uint256 nonce
|
|
49
|
+
* @param params.permit2Nonce - Explicit unused uint256 nonce; defaults to the lowest unused nonce
|
|
50
|
+
* found via {@link getUnusedPermit2Nonce}.
|
|
50
51
|
* @returns Ordered deep-frozen approval transactions and/or signable token requirements.
|
|
51
52
|
* @throws {ChainIdMismatchError} when the connected client targets another chain.
|
|
52
53
|
* @throws {NegativeInputError} when `amount` or `permit2Nonce` is negative.
|
|
@@ -55,7 +56,8 @@ export interface GetBundlesTokenRequirementsParams {
|
|
|
55
56
|
* @throws {UnsupportedChainIdError} when the chain is absent from the address registry.
|
|
56
57
|
* @throws {UnsupportedErc20ApprovalSpenderError} when `spender` is not the chain's registered
|
|
57
58
|
* BlueBundlesV1 or VaultBundlesV1 deployment, including for a zero-amount request.
|
|
58
|
-
* @throws {
|
|
59
|
+
* @throws {NoUnusedPermit2NonceError} when every Permit2 nonce for the owner is consumed and none
|
|
60
|
+
* was passed explicitly.
|
|
59
61
|
* @throws {Permit2SignatureTransferNonceAlreadyUsedError} when `permit2Nonce` is already consumed.
|
|
60
62
|
* @throws {InputExceedsMaxError} when `amount`, `deadline`, or `permit2Nonce` exceeds uint256.
|
|
61
63
|
* @throws {ApprovalAmountLessThanSpendAmountError} when `approvalAmount` is below `amount`.
|
|
@@ -79,7 +81,6 @@ export interface GetBundlesTokenRequirementsParams {
|
|
|
79
81
|
* chainId: mainnet.id,
|
|
80
82
|
* deadline: 1_900_000_000n,
|
|
81
83
|
* supportSignature: true,
|
|
82
|
-
* permit2Nonce: 42n,
|
|
83
84
|
* });
|
|
84
85
|
* // requirements contains approvals and/or signable bundles token requirements.
|
|
85
86
|
* ```
|
|
@@ -6,15 +6,16 @@ import { readContract } from "viem/actions";
|
|
|
6
6
|
import { resolveBundlesTokenRequirements } from "../../actions/bundles/index.js";
|
|
7
7
|
import { encodeErc20Permit } from "../../actions/requirements/encode/encodeErc20Permit.js";
|
|
8
8
|
import { validateChainId, validateRequirementSpender, } from "../../helpers/index.js";
|
|
9
|
-
import { ApprovalAmountLessThanSpendAmountError, ExpiredDeadlineError, InputExceedsMaxError,
|
|
9
|
+
import { ApprovalAmountLessThanSpendAmountError, ExpiredDeadlineError, InputExceedsMaxError, NegativeInputError, NonPositiveInputError, } from "../../types/index.js";
|
|
10
|
+
import { getUnusedPermit2Nonce } from "./getUnusedPermit2Nonce.js";
|
|
10
11
|
/**
|
|
11
12
|
* Resolves direct approval, ERC-2612, or Permit2 SignatureTransfer prerequisites for
|
|
12
13
|
* a registered fixed bundles contract.
|
|
13
14
|
*
|
|
14
15
|
* Reads only the allowance and nonce state required by the selected path. Permit2 keeps the
|
|
15
16
|
* ERC-20 allowance on canonical Permit2 while the one-time signed transfer names the bundles contract
|
|
16
|
-
* as spender.
|
|
17
|
-
*
|
|
17
|
+
* as spender. The resolver picks the lowest unused unordered nonce by default; concurrent flows for
|
|
18
|
+
* the same owner should pass explicit nonces.
|
|
18
19
|
*
|
|
19
20
|
* @param viemClient - Connected viem client used for allowance and nonce reads.
|
|
20
21
|
* @param params - Token requirement parameters.
|
|
@@ -28,7 +29,8 @@ import { ApprovalAmountLessThanSpendAmountError, ExpiredDeadlineError, InputExce
|
|
|
28
29
|
* @param params.supportSignature - Whether ERC-2612 or Permit2 signatures may be requested.
|
|
29
30
|
* @param params.supportDeployless - Whether ERC-2612 metadata reads may use deployless calls.
|
|
30
31
|
* @param params.useSimplePermit - Prefer ERC-2612 when its nonce probe succeeds.
|
|
31
|
-
* @param params.permit2Nonce - Explicit unused uint256 nonce
|
|
32
|
+
* @param params.permit2Nonce - Explicit unused uint256 nonce; defaults to the lowest unused nonce
|
|
33
|
+
* found via {@link getUnusedPermit2Nonce}.
|
|
32
34
|
* @returns Ordered deep-frozen approval transactions and/or signable token requirements.
|
|
33
35
|
* @throws {ChainIdMismatchError} when the connected client targets another chain.
|
|
34
36
|
* @throws {NegativeInputError} when `amount` or `permit2Nonce` is negative.
|
|
@@ -37,7 +39,8 @@ import { ApprovalAmountLessThanSpendAmountError, ExpiredDeadlineError, InputExce
|
|
|
37
39
|
* @throws {UnsupportedChainIdError} when the chain is absent from the address registry.
|
|
38
40
|
* @throws {UnsupportedErc20ApprovalSpenderError} when `spender` is not the chain's registered
|
|
39
41
|
* BlueBundlesV1 or VaultBundlesV1 deployment, including for a zero-amount request.
|
|
40
|
-
* @throws {
|
|
42
|
+
* @throws {NoUnusedPermit2NonceError} when every Permit2 nonce for the owner is consumed and none
|
|
43
|
+
* was passed explicitly.
|
|
41
44
|
* @throws {Permit2SignatureTransferNonceAlreadyUsedError} when `permit2Nonce` is already consumed.
|
|
42
45
|
* @throws {InputExceedsMaxError} when `amount`, `deadline`, or `permit2Nonce` exceeds uint256.
|
|
43
46
|
* @throws {ApprovalAmountLessThanSpendAmountError} when `approvalAmount` is below `amount`.
|
|
@@ -61,7 +64,6 @@ import { ApprovalAmountLessThanSpendAmountError, ExpiredDeadlineError, InputExce
|
|
|
61
64
|
* chainId: mainnet.id,
|
|
62
65
|
* deadline: 1_900_000_000n,
|
|
63
66
|
* supportSignature: true,
|
|
64
|
-
* permit2Nonce: 42n,
|
|
65
67
|
* });
|
|
66
68
|
* // requirements contains approvals and/or signable bundles token requirements.
|
|
67
69
|
* ```
|
|
@@ -118,6 +120,7 @@ export const getBundlesTokenRequirements = async (viemClient, params) => {
|
|
|
118
120
|
return [
|
|
119
121
|
await encodeErc20Permit(viemClient, {
|
|
120
122
|
token: params.token,
|
|
123
|
+
owner: params.owner,
|
|
121
124
|
spender: params.spender,
|
|
122
125
|
amount: params.amount,
|
|
123
126
|
chainId: params.chainId,
|
|
@@ -129,20 +132,22 @@ export const getBundlesTokenRequirements = async (viemClient, params) => {
|
|
|
129
132
|
}
|
|
130
133
|
}
|
|
131
134
|
if (permit2 != null) {
|
|
132
|
-
|
|
133
|
-
|
|
135
|
+
const permit2Nonce = params.permit2Nonce ??
|
|
136
|
+
(await getUnusedPermit2Nonce(viemClient, {
|
|
137
|
+
owner: params.owner,
|
|
138
|
+
chainId: params.chainId,
|
|
139
|
+
}));
|
|
140
|
+
if (permit2Nonce < 0n) {
|
|
141
|
+
throw new NegativeInputError("permit2Nonce", permit2Nonce);
|
|
134
142
|
}
|
|
135
|
-
if (
|
|
136
|
-
throw new NegativeInputError("permit2Nonce", params.permit2Nonce);
|
|
137
|
-
}
|
|
138
|
-
if (params.permit2Nonce > maxUint256) {
|
|
143
|
+
if (permit2Nonce > maxUint256) {
|
|
139
144
|
throw new InputExceedsMaxError({
|
|
140
145
|
field: "permit2Nonce",
|
|
141
|
-
value:
|
|
146
|
+
value: permit2Nonce,
|
|
142
147
|
max: maxUint256,
|
|
143
148
|
});
|
|
144
149
|
}
|
|
145
|
-
const wordPosition =
|
|
150
|
+
const wordPosition = permit2Nonce >> 8n;
|
|
146
151
|
const [allowance, nonceBitmap] = await Promise.all([
|
|
147
152
|
readContract(viemClient, {
|
|
148
153
|
abi: erc20Abi,
|
|
@@ -167,7 +172,7 @@ export const getBundlesTokenRequirements = async (viemClient, params) => {
|
|
|
167
172
|
state: {
|
|
168
173
|
type: "permit2SignatureTransfer",
|
|
169
174
|
permit2Allowance: allowance,
|
|
170
|
-
permit2Nonce
|
|
175
|
+
permit2Nonce,
|
|
171
176
|
nonceBitmap,
|
|
172
177
|
},
|
|
173
178
|
});
|