@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
|
@@ -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, {});
|
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
import { type Address, type Client } from "viem";
|
|
2
|
-
import { type
|
|
3
|
-
/** Parameters for {@link
|
|
4
|
-
export interface
|
|
2
|
+
import { type BundlesTokenSignatureRequirement, type ERC20ApprovalAction, type Transaction } from "../../types/index.js";
|
|
3
|
+
/** Parameters for {@link getBundlesTokenRequirements}. */
|
|
4
|
+
export interface GetBundlesTokenRequirementsParams {
|
|
5
5
|
/** ERC-20 token funded by the operation. */
|
|
6
6
|
readonly token: Address;
|
|
7
|
-
/**
|
|
7
|
+
/** Registered fixed bundles contract that pulls the token. */
|
|
8
|
+
readonly spender: Address;
|
|
9
|
+
/** Exact amount the bundles contract will pull. */
|
|
8
10
|
readonly amount: bigint;
|
|
9
11
|
/** Classic approval amount; defaults to the exact pull amount. */
|
|
10
12
|
readonly approvalAmount?: bigint;
|
|
@@ -20,22 +22,23 @@ export interface GetBlueBundlesV1TokenRequirementsParams {
|
|
|
20
22
|
readonly supportDeployless?: boolean;
|
|
21
23
|
/** Prefer ERC-2612 when the token exposes a compatible nonce. */
|
|
22
24
|
readonly useSimplePermit?: boolean;
|
|
23
|
-
/** Explicit unused
|
|
25
|
+
/** Explicit unused uint256 nonce; defaults to the lowest unused nonce found via getUnusedPermit2Nonce. */
|
|
24
26
|
readonly permit2Nonce?: bigint;
|
|
25
27
|
}
|
|
26
28
|
/**
|
|
27
29
|
* Resolves direct approval, ERC-2612, or Permit2 SignatureTransfer prerequisites for
|
|
28
|
-
*
|
|
30
|
+
* a registered fixed bundles contract.
|
|
29
31
|
*
|
|
30
32
|
* Reads only the allowance and nonce state required by the selected path. Permit2 keeps the
|
|
31
|
-
* ERC-20 allowance on canonical Permit2 while the one-time signed transfer names
|
|
32
|
-
* as spender.
|
|
33
|
-
*
|
|
33
|
+
* ERC-20 allowance on canonical Permit2 while the one-time signed transfer names the bundles contract
|
|
34
|
+
* as spender. The resolver picks the lowest unused unordered nonce by default; concurrent flows for
|
|
35
|
+
* the same owner should pass explicit nonces.
|
|
34
36
|
*
|
|
35
37
|
* @param viemClient - Connected viem client used for allowance and nonce reads.
|
|
36
38
|
* @param params - Token requirement parameters.
|
|
37
39
|
* @param params.token - ERC-20 token funded by the operation.
|
|
38
|
-
* @param params.
|
|
40
|
+
* @param params.spender - Registered fixed bundles contract that pulls the token.
|
|
41
|
+
* @param params.amount - Exact amount the contract will pull; zero returns no requirements.
|
|
39
42
|
* @param params.approvalAmount - Classic approval amount; defaults to `amount` and is ignored by signature paths.
|
|
40
43
|
* @param params.owner - Account funding the operation.
|
|
41
44
|
* @param params.chainId - Target chain id; must match the client chain.
|
|
@@ -43,16 +46,19 @@ export interface GetBlueBundlesV1TokenRequirementsParams {
|
|
|
43
46
|
* @param params.supportSignature - Whether ERC-2612 or Permit2 signatures may be requested.
|
|
44
47
|
* @param params.supportDeployless - Whether ERC-2612 metadata reads may use deployless calls.
|
|
45
48
|
* @param params.useSimplePermit - Prefer ERC-2612 when its nonce probe succeeds.
|
|
46
|
-
* @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}.
|
|
47
51
|
* @returns Ordered deep-frozen approval transactions and/or signable token requirements.
|
|
48
52
|
* @throws {ChainIdMismatchError} when the connected client targets another chain.
|
|
49
53
|
* @throws {NegativeInputError} when `amount` or `permit2Nonce` is negative.
|
|
50
54
|
* @throws {NonPositiveInputError} when `deadline` is not positive.
|
|
51
55
|
* @throws {ExpiredDeadlineError} when `deadline` is positive but not in the future.
|
|
52
56
|
* @throws {UnsupportedChainIdError} when the chain is absent from the address registry.
|
|
53
|
-
* @throws {
|
|
54
|
-
*
|
|
55
|
-
* @throws {
|
|
57
|
+
* @throws {UnsupportedErc20ApprovalSpenderError} when `spender` is not the chain's registered
|
|
58
|
+
* BlueBundlesV1 or VaultBundlesV1 deployment, including for a zero-amount request.
|
|
59
|
+
* @throws {NoUnusedPermit2NonceError} when every Permit2 nonce for the owner is consumed and none
|
|
60
|
+
* was passed explicitly.
|
|
61
|
+
* @throws {Permit2SignatureTransferNonceAlreadyUsedError} when `permit2Nonce` is already consumed.
|
|
56
62
|
* @throws {InputExceedsMaxError} when `amount`, `deadline`, or `permit2Nonce` exceeds uint256.
|
|
57
63
|
* @throws {ApprovalAmountLessThanSpendAmountError} when `approvalAmount` is below `amount`.
|
|
58
64
|
* @throws {viem.BaseError} when a required allowance, Permit2 nonce-bitmap, or ERC-2612 metadata
|
|
@@ -60,21 +66,23 @@ export interface GetBlueBundlesV1TokenRequirementsParams {
|
|
|
60
66
|
* @example
|
|
61
67
|
* ```ts
|
|
62
68
|
* import { addressesRegistry } from "@morpho-org/blue-sdk";
|
|
69
|
+
* import { getChainAddress } from "@morpho-org/morpho-ts";
|
|
63
70
|
* import { createPublicClient, http, zeroAddress } from "viem";
|
|
64
71
|
* import { mainnet } from "viem/chains";
|
|
65
|
-
* import {
|
|
72
|
+
* import { getBundlesTokenRequirements } from "@morpho-org/morpho-sdk";
|
|
66
73
|
*
|
|
67
74
|
* const client = createPublicClient({ chain: mainnet, transport: http() });
|
|
68
|
-
* const
|
|
75
|
+
* const vaultBundlesV1 = getChainAddress(mainnet.id, "bundles.vaultBundlesV1");
|
|
76
|
+
* const requirements = await getBundlesTokenRequirements(client, {
|
|
69
77
|
* token: addressesRegistry[mainnet.id].usdc,
|
|
78
|
+
* spender: vaultBundlesV1,
|
|
70
79
|
* amount: 1_000_000n,
|
|
71
80
|
* owner: zeroAddress,
|
|
72
81
|
* chainId: mainnet.id,
|
|
73
82
|
* deadline: 1_900_000_000n,
|
|
74
83
|
* supportSignature: true,
|
|
75
|
-
* permit2Nonce: 42n,
|
|
76
84
|
* });
|
|
77
|
-
* // requirements contains approvals and/or signable
|
|
85
|
+
* // requirements contains approvals and/or signable bundles token requirements.
|
|
78
86
|
* ```
|
|
79
87
|
*/
|
|
80
|
-
export declare const
|
|
88
|
+
export declare const getBundlesTokenRequirements: (viemClient: Client, params: GetBundlesTokenRequirementsParams) => Promise<readonly (Readonly<Transaction<ERC20ApprovalAction>> | BundlesTokenSignatureRequirement)[]>;
|
|
@@ -1,26 +1,27 @@
|
|
|
1
1
|
import { getChainAddresses } from "@morpho-org/blue-sdk";
|
|
2
2
|
import { erc2612Abi, permit2Abi } from "@morpho-org/blue-sdk-viem";
|
|
3
|
-
import {
|
|
3
|
+
import { isDefined, Time } from "@morpho-org/morpho-ts";
|
|
4
4
|
import { erc20Abi, isAddressEqual, maxUint256, } from "viem";
|
|
5
5
|
import { readContract } from "viem/actions";
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
6
|
+
import { resolveBundlesTokenRequirements } from "../../actions/bundles/index.js";
|
|
7
|
+
import { encodeErc20Permit } from "../../actions/requirements/encode/encodeErc20Permit.js";
|
|
8
|
+
import { validateChainId, validateRequirementSpender, } from "../../helpers/index.js";
|
|
9
|
+
import { ApprovalAmountLessThanSpendAmountError, ExpiredDeadlineError, InputExceedsMaxError, NegativeInputError, NonPositiveInputError, } from "../../types/index.js";
|
|
10
|
+
import { getUnusedPermit2Nonce } from "./getUnusedPermit2Nonce.js";
|
|
11
11
|
/**
|
|
12
12
|
* Resolves direct approval, ERC-2612, or Permit2 SignatureTransfer prerequisites for
|
|
13
|
-
*
|
|
13
|
+
* a registered fixed bundles contract.
|
|
14
14
|
*
|
|
15
15
|
* Reads only the allowance and nonce state required by the selected path. Permit2 keeps the
|
|
16
|
-
* ERC-20 allowance on canonical Permit2 while the one-time signed transfer names
|
|
17
|
-
* as spender.
|
|
18
|
-
*
|
|
16
|
+
* ERC-20 allowance on canonical Permit2 while the one-time signed transfer names the bundles contract
|
|
17
|
+
* as spender. The resolver picks the lowest unused unordered nonce by default; concurrent flows for
|
|
18
|
+
* the same owner should pass explicit nonces.
|
|
19
19
|
*
|
|
20
20
|
* @param viemClient - Connected viem client used for allowance and nonce reads.
|
|
21
21
|
* @param params - Token requirement parameters.
|
|
22
22
|
* @param params.token - ERC-20 token funded by the operation.
|
|
23
|
-
* @param params.
|
|
23
|
+
* @param params.spender - Registered fixed bundles contract that pulls the token.
|
|
24
|
+
* @param params.amount - Exact amount the contract will pull; zero returns no requirements.
|
|
24
25
|
* @param params.approvalAmount - Classic approval amount; defaults to `amount` and is ignored by signature paths.
|
|
25
26
|
* @param params.owner - Account funding the operation.
|
|
26
27
|
* @param params.chainId - Target chain id; must match the client chain.
|
|
@@ -28,16 +29,19 @@ import { getRequirementsApproval } from "../getRequirementsApproval.js";
|
|
|
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.
|
|
35
37
|
* @throws {NonPositiveInputError} when `deadline` is not positive.
|
|
36
38
|
* @throws {ExpiredDeadlineError} when `deadline` is positive but not in the future.
|
|
37
39
|
* @throws {UnsupportedChainIdError} when the chain is absent from the address registry.
|
|
38
|
-
* @throws {
|
|
39
|
-
*
|
|
40
|
-
* @throws {
|
|
40
|
+
* @throws {UnsupportedErc20ApprovalSpenderError} when `spender` is not the chain's registered
|
|
41
|
+
* BlueBundlesV1 or VaultBundlesV1 deployment, including for a zero-amount request.
|
|
42
|
+
* @throws {NoUnusedPermit2NonceError} when every Permit2 nonce for the owner is consumed and none
|
|
43
|
+
* was passed explicitly.
|
|
44
|
+
* @throws {Permit2SignatureTransferNonceAlreadyUsedError} when `permit2Nonce` is already consumed.
|
|
41
45
|
* @throws {InputExceedsMaxError} when `amount`, `deadline`, or `permit2Nonce` exceeds uint256.
|
|
42
46
|
* @throws {ApprovalAmountLessThanSpendAmountError} when `approvalAmount` is below `amount`.
|
|
43
47
|
* @throws {viem.BaseError} when a required allowance, Permit2 nonce-bitmap, or ERC-2612 metadata
|
|
@@ -45,25 +49,32 @@ import { getRequirementsApproval } from "../getRequirementsApproval.js";
|
|
|
45
49
|
* @example
|
|
46
50
|
* ```ts
|
|
47
51
|
* import { addressesRegistry } from "@morpho-org/blue-sdk";
|
|
52
|
+
* import { getChainAddress } from "@morpho-org/morpho-ts";
|
|
48
53
|
* import { createPublicClient, http, zeroAddress } from "viem";
|
|
49
54
|
* import { mainnet } from "viem/chains";
|
|
50
|
-
* import {
|
|
55
|
+
* import { getBundlesTokenRequirements } from "@morpho-org/morpho-sdk";
|
|
51
56
|
*
|
|
52
57
|
* const client = createPublicClient({ chain: mainnet, transport: http() });
|
|
53
|
-
* const
|
|
58
|
+
* const vaultBundlesV1 = getChainAddress(mainnet.id, "bundles.vaultBundlesV1");
|
|
59
|
+
* const requirements = await getBundlesTokenRequirements(client, {
|
|
54
60
|
* token: addressesRegistry[mainnet.id].usdc,
|
|
61
|
+
* spender: vaultBundlesV1,
|
|
55
62
|
* amount: 1_000_000n,
|
|
56
63
|
* owner: zeroAddress,
|
|
57
64
|
* chainId: mainnet.id,
|
|
58
65
|
* deadline: 1_900_000_000n,
|
|
59
66
|
* supportSignature: true,
|
|
60
|
-
* permit2Nonce: 42n,
|
|
61
67
|
* });
|
|
62
|
-
* // requirements contains approvals and/or signable
|
|
68
|
+
* // requirements contains approvals and/or signable bundles token requirements.
|
|
63
69
|
* ```
|
|
64
70
|
*/
|
|
65
|
-
export const
|
|
71
|
+
export const getBundlesTokenRequirements = async (viemClient, params) => {
|
|
66
72
|
validateChainId(viemClient.chain?.id, params.chainId);
|
|
73
|
+
validateRequirementSpender({
|
|
74
|
+
chainId: params.chainId,
|
|
75
|
+
spender: params.spender,
|
|
76
|
+
allowed: ["blueBundlesV1", "vaultBundlesV1"],
|
|
77
|
+
});
|
|
67
78
|
if (params.amount < 0n) {
|
|
68
79
|
throw new NegativeInputError("amount", params.amount);
|
|
69
80
|
}
|
|
@@ -95,7 +106,6 @@ export const getBlueBundlesV1TokenRequirements = async (viemClient, params) => {
|
|
|
95
106
|
}
|
|
96
107
|
if (params.amount === 0n)
|
|
97
108
|
return [];
|
|
98
|
-
const blueBundlesV1 = getChainAddress(params.chainId, "bundles.blueBundlesV1");
|
|
99
109
|
const { permit2, dai } = getChainAddresses(params.chainId);
|
|
100
110
|
if (params.supportSignature) {
|
|
101
111
|
const isDai = isDefined(dai) && isAddressEqual(params.token, dai);
|
|
@@ -110,7 +120,8 @@ export const getBlueBundlesV1TokenRequirements = async (viemClient, params) => {
|
|
|
110
120
|
return [
|
|
111
121
|
await encodeErc20Permit(viemClient, {
|
|
112
122
|
token: params.token,
|
|
113
|
-
|
|
123
|
+
owner: params.owner,
|
|
124
|
+
spender: params.spender,
|
|
114
125
|
amount: params.amount,
|
|
115
126
|
chainId: params.chainId,
|
|
116
127
|
nonce,
|
|
@@ -121,21 +132,22 @@ export const getBlueBundlesV1TokenRequirements = async (viemClient, params) => {
|
|
|
121
132
|
}
|
|
122
133
|
}
|
|
123
134
|
if (permit2 != null) {
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
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);
|
|
129
142
|
}
|
|
130
|
-
if (
|
|
143
|
+
if (permit2Nonce > maxUint256) {
|
|
131
144
|
throw new InputExceedsMaxError({
|
|
132
145
|
field: "permit2Nonce",
|
|
133
|
-
value:
|
|
146
|
+
value: permit2Nonce,
|
|
134
147
|
max: maxUint256,
|
|
135
148
|
});
|
|
136
149
|
}
|
|
137
|
-
const wordPosition =
|
|
138
|
-
const bitPosition = params.permit2Nonce & 255n;
|
|
150
|
+
const wordPosition = permit2Nonce >> 8n;
|
|
139
151
|
const [allowance, nonceBitmap] = await Promise.all([
|
|
140
152
|
readContract(viemClient, {
|
|
141
153
|
abi: erc20Abi,
|
|
@@ -150,29 +162,20 @@ export const getBlueBundlesV1TokenRequirements = async (viemClient, params) => {
|
|
|
150
162
|
args: [params.owner, wordPosition],
|
|
151
163
|
}),
|
|
152
164
|
]);
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
encodeErc20Permit2TransferFrom({
|
|
168
|
-
token: params.token,
|
|
169
|
-
spender: blueBundlesV1,
|
|
170
|
-
amount: params.amount,
|
|
171
|
-
chainId: params.chainId,
|
|
172
|
-
nonce: params.permit2Nonce,
|
|
173
|
-
deadline: params.deadline,
|
|
174
|
-
}),
|
|
175
|
-
];
|
|
165
|
+
return resolveBundlesTokenRequirements({
|
|
166
|
+
token: params.token,
|
|
167
|
+
spender: params.spender,
|
|
168
|
+
owner: params.owner,
|
|
169
|
+
chainId: params.chainId,
|
|
170
|
+
amount: params.amount,
|
|
171
|
+
deadline: params.deadline,
|
|
172
|
+
state: {
|
|
173
|
+
type: "permit2SignatureTransfer",
|
|
174
|
+
permit2Allowance: allowance,
|
|
175
|
+
permit2Nonce,
|
|
176
|
+
nonceBitmap,
|
|
177
|
+
},
|
|
178
|
+
});
|
|
176
179
|
}
|
|
177
180
|
}
|
|
178
181
|
const approvalAmount = params.approvalAmount ?? params.amount;
|
|
@@ -183,21 +186,19 @@ export const getBlueBundlesV1TokenRequirements = async (viemClient, params) => {
|
|
|
183
186
|
abi: erc20Abi,
|
|
184
187
|
address: params.token,
|
|
185
188
|
functionName: "allowance",
|
|
186
|
-
args: [params.owner,
|
|
189
|
+
args: [params.owner, params.spender],
|
|
187
190
|
});
|
|
188
|
-
return
|
|
189
|
-
|
|
191
|
+
return resolveBundlesTokenRequirements({
|
|
192
|
+
token: params.token,
|
|
193
|
+
spender: params.spender,
|
|
194
|
+
owner: params.owner,
|
|
190
195
|
chainId: params.chainId,
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
// redundant approval — and a zero-reset on approve-only-once tokens like
|
|
197
|
-
// USDT — when the current allowance already covers the pull.
|
|
198
|
-
spendAmount: params.amount,
|
|
196
|
+
amount: params.amount,
|
|
197
|
+
deadline: params.deadline,
|
|
198
|
+
state: {
|
|
199
|
+
type: "approval",
|
|
200
|
+
allowance,
|
|
199
201
|
approvalAmount,
|
|
200
202
|
},
|
|
201
|
-
allowances: allowance,
|
|
202
203
|
});
|
|
203
204
|
};
|
package/lib/{cjs/actions/requirements/blue → esm/entities/requirements}/getUnusedPermit2Nonce.d.ts
RENAMED
|
@@ -10,7 +10,7 @@ export interface GetUnusedPermit2NonceParams {
|
|
|
10
10
|
}
|
|
11
11
|
/**
|
|
12
12
|
* Finds the lowest unused Permit2 unordered nonce for `owner`, ready to pass as `permit2Nonce` to
|
|
13
|
-
* {@link
|
|
13
|
+
* {@link getBundlesTokenRequirements} or as `nonce` to {@link encodeErc20Permit2SignatureTransfer}.
|
|
14
14
|
*
|
|
15
15
|
* Permit2 SignatureTransfer consumes an unordered 256-bit nonce; a nonce is free when its bit in
|
|
16
16
|
* `nonceBitmap(owner, word)` is unset. This scans consecutive bitmap words starting at `startNonce`
|
package/lib/esm/{actions/requirements/blue → entities/requirements}/getUnusedPermit2Nonce.js
RENAMED
|
@@ -2,14 +2,14 @@ import { permit2Abi } from "@morpho-org/blue-sdk-viem";
|
|
|
2
2
|
import { getChainAddress } from "@morpho-org/morpho-ts";
|
|
3
3
|
import { maxUint256 } from "viem";
|
|
4
4
|
import { readContract } from "viem/actions";
|
|
5
|
-
import { validateChainId } from "
|
|
6
|
-
import { validateUint256Field } from "
|
|
7
|
-
import { NoUnusedPermit2NonceError } from "
|
|
5
|
+
import { validateChainId } from "../../helpers/index.js";
|
|
6
|
+
import { validateUint256Field } from "../../helpers/validate.js";
|
|
7
|
+
import { NoUnusedPermit2NonceError } from "../../types/index.js";
|
|
8
8
|
/** Highest Permit2 nonce-bitmap word index; each word covers 256 unordered nonces. */
|
|
9
9
|
const MAX_PERMIT2_NONCE_WORD = maxUint256 >> 8n;
|
|
10
10
|
/**
|
|
11
11
|
* Finds the lowest unused Permit2 unordered nonce for `owner`, ready to pass as `permit2Nonce` to
|
|
12
|
-
* {@link
|
|
12
|
+
* {@link getBundlesTokenRequirements} or as `nonce` to {@link encodeErc20Permit2SignatureTransfer}.
|
|
13
13
|
*
|
|
14
14
|
* Permit2 SignatureTransfer consumes an unordered 256-bit nonce; a nonce is free when its bit in
|
|
15
15
|
* `nonceBitmap(owner, word)` is unset. This scans consecutive bitmap words starting at `startNonce`
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import type { Token } from "@morpho-org/blue-sdk";
|
|
2
|
+
import type { Address, Client } from "viem";
|
|
3
|
+
import { type ActionRequirement } from "../../types/index.js";
|
|
4
|
+
/**
|
|
5
|
+
* Resolves the exact vault-share approval or ERC-2612 requirement for a VaultBundlesV1 exit.
|
|
6
|
+
*
|
|
7
|
+
* The exit burns however many shares the vault prices at execution time, so the share allowance is
|
|
8
|
+
* the only cap on that burn. A leftover allowance above `requiredShareAllowance` therefore does not
|
|
9
|
+
* satisfy the requirement: it is replaced by an approval or permit for exactly the computed cap.
|
|
10
|
+
*
|
|
11
|
+
* @internal
|
|
12
|
+
*
|
|
13
|
+
* @param viemClient - Client used to read the current share allowance and permit nonce.
|
|
14
|
+
* @param params - Vault snapshot, owner, exact allowance, and deadline values.
|
|
15
|
+
* @returns No requirement when the allowance already equals `requiredShareAllowance`, otherwise one
|
|
16
|
+
* permit or approval that sets it to exactly that cap.
|
|
17
|
+
* @throws {ExpiredDeadlineError} when the bundles deadline has elapsed.
|
|
18
|
+
* @throws {viem.BaseError} when an allowance or nonce read fails.
|
|
19
|
+
*/
|
|
20
|
+
export declare const getVaultBundlesSharesRequirements: (viemClient: Client, params: {
|
|
21
|
+
readonly vaultData: Token;
|
|
22
|
+
readonly version: "vaultV1" | "vaultV2";
|
|
23
|
+
readonly owner: Address;
|
|
24
|
+
readonly chainId: number;
|
|
25
|
+
readonly requiredShareAllowance: bigint;
|
|
26
|
+
readonly deadline: bigint;
|
|
27
|
+
readonly supportSignature: boolean;
|
|
28
|
+
}) => Promise<readonly ActionRequirement[]>;
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { erc2612Abi } from "@morpho-org/blue-sdk-viem";
|
|
2
|
+
import { getChainAddress, Time } from "@morpho-org/morpho-ts";
|
|
3
|
+
import { erc20Abi } from "viem";
|
|
4
|
+
import { readContract } from "viem/actions";
|
|
5
|
+
import { encodeErc20Approval, encodeVaultSharesPermit, } from "../../actions/index.js";
|
|
6
|
+
import { validateChainId } from "../../helpers/index.js";
|
|
7
|
+
import { ExpiredDeadlineError, } from "../../types/index.js";
|
|
8
|
+
/**
|
|
9
|
+
* Resolves the exact vault-share approval or ERC-2612 requirement for a VaultBundlesV1 exit.
|
|
10
|
+
*
|
|
11
|
+
* The exit burns however many shares the vault prices at execution time, so the share allowance is
|
|
12
|
+
* the only cap on that burn. A leftover allowance above `requiredShareAllowance` therefore does not
|
|
13
|
+
* satisfy the requirement: it is replaced by an approval or permit for exactly the computed cap.
|
|
14
|
+
*
|
|
15
|
+
* @internal
|
|
16
|
+
*
|
|
17
|
+
* @param viemClient - Client used to read the current share allowance and permit nonce.
|
|
18
|
+
* @param params - Vault snapshot, owner, exact allowance, and deadline values.
|
|
19
|
+
* @returns No requirement when the allowance already equals `requiredShareAllowance`, otherwise one
|
|
20
|
+
* permit or approval that sets it to exactly that cap.
|
|
21
|
+
* @throws {ExpiredDeadlineError} when the bundles deadline has elapsed.
|
|
22
|
+
* @throws {viem.BaseError} when an allowance or nonce read fails.
|
|
23
|
+
*/
|
|
24
|
+
export const getVaultBundlesSharesRequirements = async (viemClient, params) => {
|
|
25
|
+
validateChainId(viemClient.chain?.id, params.chainId);
|
|
26
|
+
const now = Time.timestamp();
|
|
27
|
+
if (params.deadline <= now) {
|
|
28
|
+
throw new ExpiredDeadlineError(params.deadline, now);
|
|
29
|
+
}
|
|
30
|
+
const spender = getChainAddress(params.chainId, "bundles.vaultBundlesV1");
|
|
31
|
+
const allowance = await readContract(viemClient, {
|
|
32
|
+
address: params.vaultData.address,
|
|
33
|
+
abi: erc20Abi,
|
|
34
|
+
functionName: "allowance",
|
|
35
|
+
args: [params.owner, spender],
|
|
36
|
+
});
|
|
37
|
+
// Asset-mode withdrawals carry no onchain share cap, so the allowance itself is the cap. A
|
|
38
|
+
// larger leftover allowance would let a share-price loss burn past `requiredShareAllowance`,
|
|
39
|
+
// so only an exact match skips the approval or permit that resets it to the computed cap.
|
|
40
|
+
if (allowance === params.requiredShareAllowance)
|
|
41
|
+
return [];
|
|
42
|
+
if (params.supportSignature) {
|
|
43
|
+
const nonce = await readContract(viemClient, {
|
|
44
|
+
address: params.vaultData.address,
|
|
45
|
+
abi: erc2612Abi,
|
|
46
|
+
functionName: "nonces",
|
|
47
|
+
args: [params.owner],
|
|
48
|
+
});
|
|
49
|
+
return [
|
|
50
|
+
encodeVaultSharesPermit({
|
|
51
|
+
vault: params.vaultData,
|
|
52
|
+
version: params.version,
|
|
53
|
+
spender,
|
|
54
|
+
owner: params.owner,
|
|
55
|
+
chainId: params.chainId,
|
|
56
|
+
nonce,
|
|
57
|
+
amount: params.requiredShareAllowance,
|
|
58
|
+
deadline: params.deadline,
|
|
59
|
+
}),
|
|
60
|
+
];
|
|
61
|
+
}
|
|
62
|
+
return [
|
|
63
|
+
encodeErc20Approval({
|
|
64
|
+
token: params.vaultData.address,
|
|
65
|
+
spender,
|
|
66
|
+
amount: params.requiredShareAllowance,
|
|
67
|
+
chainId: params.chainId,
|
|
68
|
+
}),
|
|
69
|
+
];
|
|
70
|
+
};
|