@morpho-org/morpho-sdk 6.0.0-next.1 → 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 +127 -16
- package/README.md +17 -11
- package/lib/cjs/abis.d.ts +17 -2
- package/lib/cjs/abis.js +14 -1
- package/lib/cjs/actions/blue/common.js +5 -26
- package/lib/cjs/actions/blue/supply.js +2 -7
- package/lib/cjs/actions/bundles/common.d.ts +32 -2
- package/lib/cjs/actions/bundles/common.js +68 -30
- 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 -1
- package/lib/cjs/actions/requirements/blue/index.js +0 -1
- package/lib/cjs/actions/requirements/encode/encodeBlueSignatureAuthorization.d.ts +15 -8
- package/lib/cjs/actions/requirements/encode/encodeBlueSignatureAuthorization.js +20 -20
- package/lib/cjs/actions/requirements/encode/encodeErc20Permit.d.ts +16 -7
- package/lib/cjs/actions/requirements/encode/encodeErc20Permit.js +33 -27
- package/lib/cjs/actions/requirements/encode/encodeErc20Permit2Approve.d.ts +4 -2
- package/lib/cjs/actions/requirements/encode/encodeErc20Permit2Approve.js +15 -10
- 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/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/signatures/getVaultExitBundlesV1PermitStruct.d.ts +6 -0
- package/lib/cjs/actions/signatures/getVaultExitBundlesV1PermitStruct.js +2 -0
- package/lib/cjs/actions/vaultV1/inKindRedeem.d.ts +1 -0
- package/lib/cjs/actions/vaultV1/inKindRedeem.js +3 -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 +1 -0
- package/lib/cjs/actions/vaultV2/inKindRedeem.js +3 -2
- 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 +15 -6
- package/lib/cjs/entities/blue/blue.js +3 -0
- package/lib/cjs/entities/index.d.ts +8 -2
- package/lib/cjs/entities/index.js +1 -0
- 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 +10 -5
- package/lib/cjs/entities/vaultV1/vaultV1.js +13 -1
- 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 +140 -34
- package/lib/cjs/entities/vaultV2/vaultV2.js +229 -16
- 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 +3 -1
- package/lib/cjs/helpers/index.js +10 -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/slippage.d.ts +46 -0
- package/lib/cjs/helpers/slippage.js +65 -0
- package/lib/cjs/helpers/validate.d.ts +65 -8
- package/lib/cjs/helpers/validate.js +83 -9
- package/lib/cjs/helpers/vaultV2ForceWithdrawPlan.d.ts +274 -0
- package/lib/cjs/helpers/vaultV2ForceWithdrawPlan.js +369 -0
- package/lib/cjs/types/action.d.ts +95 -13
- package/lib/cjs/types/error.d.ts +290 -12
- package/lib/cjs/types/error.js +312 -24
- 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 +17 -2
- package/lib/esm/abis.js +17 -2
- package/lib/esm/actions/blue/common.js +7 -28
- package/lib/esm/actions/blue/supply.js +4 -9
- package/lib/esm/actions/bundles/common.d.ts +32 -2
- package/lib/esm/actions/bundles/common.js +68 -31
- 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 -1
- package/lib/esm/actions/requirements/blue/index.js +0 -1
- package/lib/esm/actions/requirements/encode/encodeBlueSignatureAuthorization.d.ts +15 -8
- package/lib/esm/actions/requirements/encode/encodeBlueSignatureAuthorization.js +21 -21
- package/lib/esm/actions/requirements/encode/encodeErc20Permit.d.ts +16 -7
- package/lib/esm/actions/requirements/encode/encodeErc20Permit.js +34 -28
- package/lib/esm/actions/requirements/encode/encodeErc20Permit2Approve.d.ts +4 -2
- package/lib/esm/actions/requirements/encode/encodeErc20Permit2Approve.js +15 -10
- 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/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/signatures/getVaultExitBundlesV1PermitStruct.d.ts +6 -0
- package/lib/esm/actions/signatures/getVaultExitBundlesV1PermitStruct.js +2 -0
- package/lib/esm/actions/vaultV1/inKindRedeem.d.ts +1 -0
- package/lib/esm/actions/vaultV1/inKindRedeem.js +3 -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 +1 -0
- package/lib/esm/actions/vaultV2/inKindRedeem.js +3 -2
- 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 +15 -6
- package/lib/esm/entities/blue/blue.js +3 -0
- package/lib/esm/entities/index.d.ts +8 -2
- package/lib/esm/entities/index.js +3 -1
- 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 +10 -5
- package/lib/esm/entities/vaultV1/vaultV1.js +14 -2
- 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 +140 -34
- package/lib/esm/entities/vaultV2/vaultV2.js +234 -21
- 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 +3 -1
- package/lib/esm/helpers/index.js +3 -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/slippage.d.ts +46 -0
- package/lib/esm/helpers/slippage.js +65 -1
- package/lib/esm/helpers/validate.d.ts +65 -8
- package/lib/esm/helpers/validate.js +82 -10
- package/lib/esm/helpers/vaultV2ForceWithdrawPlan.d.ts +274 -0
- package/lib/esm/helpers/vaultV2ForceWithdrawPlan.js +362 -0
- package/lib/esm/types/action.d.ts +95 -13
- package/lib/esm/types/error.d.ts +290 -12
- package/lib/esm/types/error.js +301 -19
- 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
- /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
|
@@ -10,7 +10,11 @@ IPosition, IPreLiquidationParams as IBluePreLiquidationParams,
|
|
|
10
10
|
/** @deprecated Use `IBluePreLiquidationParams` or the raw Blue subpath. */
|
|
11
11
|
IPreLiquidationParams, IPreLiquidationPosition as IBluePreLiquidationPosition,
|
|
12
12
|
/** @deprecated Use `IBluePreLiquidationPosition` or the raw Blue subpath. */
|
|
13
|
-
IPreLiquidationPosition, IToken, IVault, IVaultConfig, IVaultMarketAllocation, IVaultMarketConfig,
|
|
13
|
+
IPreLiquidationPosition, IToken, IVault, IVaultConfig, IVaultMarketAllocation, IVaultMarketConfig,
|
|
14
|
+
/** @deprecated Vault V1 PublicAllocator support will be removed in the next major. Use `IVaultV2BlueMarketPublicAllocatorConfig`. */
|
|
15
|
+
IVaultMarketPublicAllocatorConfig, IVaultToken, IVaultUser, IVaultV2, IVaultV2Adapter, IVaultV2Allocation, IVaultV2BlueMarketPublicAllocatorConfig, IVaultV2BluePublicAllocatorConfig, IVaultV2MorphoMarketV1Adapter, IVaultV2MorphoMarketV1AdapterV2, IVaultV2MorphoVaultV1Adapter, PeripheralBalance, PeripheralBalanceType,
|
|
16
|
+
/** @deprecated Vault V1 PublicAllocator support will be removed in the next major. Use `IVaultV2BluePublicAllocatorConfig`. */
|
|
17
|
+
VaultPublicAllocatorConfig, } from "@morpho-org/blue-sdk";
|
|
14
18
|
export { AccrualPosition as BlueAccrualPosition,
|
|
15
19
|
/** @deprecated Use `BlueAccrualPosition` or the raw Blue subpath. */
|
|
16
20
|
AccrualPosition, AccrualVault, AccrualVaultV2, AccrualVaultV2MorphoMarketV1Adapter, AccrualVaultV2MorphoMarketV1AdapterV2, AccrualVaultV2MorphoVaultV1Adapter, AssetBalances, ConstantWrappedToken, Eip5267Domain, ExchangeRateWrappedToken, Holding, Market as BlueMarket,
|
|
@@ -25,7 +29,9 @@ PreLiquidationParams, PreLiquidationPosition as BluePreLiquidationPosition,
|
|
|
25
29
|
/** @deprecated Use `BluePreLiquidationPosition` or the raw Blue subpath. */
|
|
26
30
|
PreLiquidationPosition, Token, User as BlueUser,
|
|
27
31
|
/** @deprecated Use `BlueUser` or the raw Blue subpath. */
|
|
28
|
-
User, Vault, VaultConfig, VaultMarketAllocation, VaultMarketConfig,
|
|
32
|
+
User, Vault, VaultConfig, VaultMarketAllocation, VaultMarketConfig,
|
|
33
|
+
/** @deprecated Vault V1 PublicAllocator support will be removed in the next major. Use `VaultV2BlueMarketPublicAllocatorConfig`. */
|
|
34
|
+
VaultMarketPublicAllocatorConfig, VaultToken, VaultUser, VaultV2, VaultV2Adapter, VaultV2BlueMarketPublicAllocatorConfig, VaultV2BluePublicAllocatorConfig, VaultV2MorphoMarketV1Adapter, VaultV2MorphoMarketV1AdapterV2, VaultV2MorphoVaultV1Adapter, WrappedToken, } from "@morpho-org/blue-sdk";
|
|
29
35
|
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
36
|
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
37
|
export type { BlueActions, BlueTokenRequirementsParams, } from "./blue/index.js";
|
|
@@ -12,7 +12,9 @@ PreLiquidationParams, PreLiquidationPosition as BluePreLiquidationPosition,
|
|
|
12
12
|
/** @deprecated Use `BluePreLiquidationPosition` or the raw Blue subpath. */
|
|
13
13
|
PreLiquidationPosition, Token, User as BlueUser,
|
|
14
14
|
/** @deprecated Use `BlueUser` or the raw Blue subpath. */
|
|
15
|
-
User, Vault, VaultConfig, VaultMarketAllocation, VaultMarketConfig,
|
|
15
|
+
User, Vault, VaultConfig, VaultMarketAllocation, VaultMarketConfig,
|
|
16
|
+
/** @deprecated Vault V1 PublicAllocator support will be removed in the next major. Use `VaultV2BlueMarketPublicAllocatorConfig`. */
|
|
17
|
+
VaultMarketPublicAllocatorConfig, VaultToken, VaultUser, VaultV2, VaultV2Adapter, VaultV2BlueMarketPublicAllocatorConfig, VaultV2BluePublicAllocatorConfig, VaultV2MorphoMarketV1Adapter, VaultV2MorphoMarketV1AdapterV2, VaultV2MorphoVaultV1Adapter, WrappedToken, } from "@morpho-org/blue-sdk";
|
|
16
18
|
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
19
|
export { MorphoBlue } from "./blue/index.js";
|
|
18
20
|
export { MorphoMidnight, } from "./midnight/index.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
|
});
|
package/lib/esm/{actions/requirements/blue → entities/requirements}/getUnusedPermit2Nonce.js
RENAMED
|
@@ -2,9 +2,9 @@ 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
|
/**
|
|
@@ -5,10 +5,10 @@ import type { FetchParameters } from "../../types/data.js";
|
|
|
5
5
|
import { type ActionOutput, type ActionRequirement, type BundlesFundingArgs, type BundlesTokenRequirementsOptions, type MorphoClientType, type RequirementSignature, type VaultV1DepositAction, type VaultV1InKindRedeemAction, type VaultV1MigrateToV2Action, type VaultV1MigrateToV2AmountArgs, type VaultV1RedeemAction, type VaultV1WithdrawAction } from "../../types/index.js";
|
|
6
6
|
export interface VaultV1Actions {
|
|
7
7
|
/**
|
|
8
|
-
* Fetches
|
|
8
|
+
* Fetches direct onchain vault and allocation state without applying virtual interest.
|
|
9
9
|
*
|
|
10
10
|
* @param {FetchParameters} [parameters] - Optional fetch parameters (block number, state overrides, etc.).
|
|
11
|
-
* @returns {Promise<Awaited<ReturnType<typeof fetchAccrualVault>>>} The
|
|
11
|
+
* @returns {Promise<Awaited<ReturnType<typeof fetchAccrualVault>>>} The requested vault state.
|
|
12
12
|
*/
|
|
13
13
|
getData: (parameters?: FetchParameters) => Promise<Awaited<ReturnType<typeof fetchAccrualVault>>>;
|
|
14
14
|
/**
|
|
@@ -46,8 +46,8 @@ export interface VaultV1Actions {
|
|
|
46
46
|
* @throws {ReferralFeeRecipientMissingError} when a positive referral fee has no recipient.
|
|
47
47
|
* @throws {ChainWNativeMissingError} when native funding is requested on a chain without wNative.
|
|
48
48
|
* @throws {NativeAmountOnNonWNativeVaultError} when native funding targets a non-wNative vault.
|
|
49
|
-
* @throws {
|
|
50
|
-
*
|
|
49
|
+
* @throws {NoUnusedPermit2NonceError} from `getRequirements()` when every Permit2 nonce for the
|
|
50
|
+
* owner is consumed and none was passed explicitly.
|
|
51
51
|
* @throws {Permit2SignatureTransferNonceAlreadyUsedError} from `getRequirements()` when the
|
|
52
52
|
* explicit Permit2 nonce is consumed.
|
|
53
53
|
* @throws {InputExceedsMaxError} when funding or the deadline exceeds uint256, or from
|
|
@@ -249,9 +249,11 @@ export interface VaultV1Actions {
|
|
|
249
249
|
* @param params.deadline - Optional shared permit/bundle deadline; defaults to two hours from now.
|
|
250
250
|
* @returns Lazy prerequisite resolution and a synchronous transaction builder.
|
|
251
251
|
* @throws {ChainIdMismatchError} when the client and entity target different chains.
|
|
252
|
+
* @throws {UnsupportedBlueMarketIrmError} when an allocated market with positive debt uses an unsupported IRM.
|
|
252
253
|
* @throws {VaultAddressMismatchError} when `vaultData` belongs to another vault.
|
|
253
|
-
* @throws {NonPositiveInputError} when `amount` is not positive.
|
|
254
|
+
* @throws {NonPositiveInputError} when `amount` or `deadline` is not positive.
|
|
254
255
|
* @throws {EmptyMarketParamsListError} when the market list is empty.
|
|
256
|
+
* @throws {InputExceedsMaxError} when `deadline` exceeds `uint256`.
|
|
255
257
|
* @throws {ExpiredDeadlineError} when `deadline` is not in the future at handle creation or
|
|
256
258
|
* requirement resolution.
|
|
257
259
|
* @throws {InKindRedeemCoverageError} when the ordered list cannot cover `amount` without
|
|
@@ -326,6 +328,8 @@ export interface VaultV1Actions {
|
|
|
326
328
|
* `getRequirements()` re-reads the live share allowance on every call, so a requirement
|
|
327
329
|
* satisfied between calls stops being reported, while the derived source share cap stays
|
|
328
330
|
* pinned to the supplied snapshot.
|
|
331
|
+
* @throws {UnknownBlueMarketAllocationError} when a source withdraw-queue market has no allocation snapshot.
|
|
332
|
+
* @throws {UnsupportedBlueMarketIrmError} when required interest projection encounters an unsupported IRM.
|
|
329
333
|
* @throws {ChainIdMismatchError} when the connected client targets another chain.
|
|
330
334
|
* @throws {VaultAddressMismatchError} when `sourceVault` belongs to another vault.
|
|
331
335
|
* @throws {VaultAssetMismatchError} when the source and destination vault assets differ.
|
|
@@ -442,6 +446,7 @@ export declare class MorphoVaultV1 implements VaultV1Actions {
|
|
|
442
446
|
readonly userAddress: Address;
|
|
443
447
|
readonly deadline?: bigint;
|
|
444
448
|
}): ActionOutput<VaultV1InKindRedeemAction, readonly RequirementSignature[], undefined>;
|
|
449
|
+
/** {@inheritDoc VaultV1Actions.migrateToV2} */
|
|
445
450
|
migrateToV2(params: {
|
|
446
451
|
readonly userAddress: Address;
|
|
447
452
|
readonly sourceVault: AccrualVault;
|
|
@@ -6,7 +6,7 @@ import { multicall } from "viem/actions";
|
|
|
6
6
|
import { getBundlesReferralFeeAssets, normalizeBundlesCommonParams, resolveBundlesFunding, selectBundlesSharesRequirementSignature, selectBundlesTokenRequirementSignature, } from "../../actions/bundles/common.js";
|
|
7
7
|
import { encodeErc20Approval, encodeVaultSharesPermit, vaultV1Deposit, vaultV1InKindRedeem, vaultV1MigrateToV2, vaultV1Redeem, vaultV1Withdraw, } from "../../actions/index.js";
|
|
8
8
|
import { computeVaultMaxShareAllowance, computeVaultMaxSharePrice, validateChainId, validateSlippageTolerance, } from "../../helpers/index.js";
|
|
9
|
-
import { validateNativeVaultAsset, validateUint256Field, } from "../../helpers/validate.js";
|
|
9
|
+
import { validateDeadline, validateNativeVaultAsset, validateUint256Field, } from "../../helpers/validate.js";
|
|
10
10
|
import { AmountAndSharesExclusiveError, ChainIdMismatchError, EmptyMarketParamsListError, ExpiredDeadlineError, InKindRedeemCoverageError, InsufficientBlueBalanceForInKindRedeemError, isRequirementSignature, NonPositiveInputError, SameVaultMigrationError, selectRequirementSignatures, VaultAddressMismatchError, VaultAssetMismatchError, VaultIsBlueFeeRecipientError, VaultMorphoMismatchError, } from "../../types/index.js";
|
|
11
11
|
import { getVaultBundlesSharesRequirements } from "../requirements/getVaultBundlesSharesRequirements.js";
|
|
12
12
|
import { getBundlesTokenRequirements } from "../requirements/index.js";
|
|
@@ -287,6 +287,9 @@ export class MorphoVaultV1 {
|
|
|
287
287
|
}));
|
|
288
288
|
const now = Time.timestamp();
|
|
289
289
|
const deadline = deadlineOverride ?? now + Time.s.from.h(2n);
|
|
290
|
+
// Reject the same bounds the action enforces, before `getRequirements()` can walk the caller
|
|
291
|
+
// through a vault-share approval or an EIP-712 permit for a deadline `buildTx()` cannot encode.
|
|
292
|
+
validateDeadline(deadline);
|
|
290
293
|
if (deadline <= now)
|
|
291
294
|
throw new ExpiredDeadlineError(deadline, now);
|
|
292
295
|
const vaultExitBundlesV1 = getChainAddress(this.chainId, "bundles.vaultExitBundlesV1");
|
|
@@ -301,6 +304,8 @@ export class MorphoVaultV1 {
|
|
|
301
304
|
const allocation = vaultData.allocations.get(marketId);
|
|
302
305
|
if (allocation?.config.enabled !== true)
|
|
303
306
|
continue;
|
|
307
|
+
if (allocation.position.supplyShares === 0n)
|
|
308
|
+
continue;
|
|
304
309
|
const market = allocation.position.market.accrueInterest(now);
|
|
305
310
|
const available = market.toSupplyAssets(allocation.position.supplyShares);
|
|
306
311
|
const assigned = assignedByMarket.get(marketId) ?? 0n;
|
|
@@ -430,6 +435,7 @@ export class MorphoVaultV1 {
|
|
|
430
435
|
},
|
|
431
436
|
};
|
|
432
437
|
}
|
|
438
|
+
/** {@inheritDoc VaultV1Actions.migrateToV2} */
|
|
433
439
|
migrateToV2(params) {
|
|
434
440
|
validateChainId(this.client.viemClient.chain?.id, this.chainId);
|
|
435
441
|
if (!isAddressEqual(params.sourceVault.address, this.vault)) {
|
|
@@ -461,7 +467,13 @@ export class MorphoVaultV1 {
|
|
|
461
467
|
referralFeePct: params.referralFeePct,
|
|
462
468
|
referralFeeRecipient: params.referralFeeRecipient,
|
|
463
469
|
});
|
|
464
|
-
|
|
470
|
+
// V1 redeem accrues market interest and performance fees before converting shares.
|
|
471
|
+
const grossAssets = assets ??
|
|
472
|
+
params.sourceVault
|
|
473
|
+
.accrueInterest(params.sourceVault.allocations
|
|
474
|
+
.values()
|
|
475
|
+
.reduce((timestamp, { position }) => MathLib.max(timestamp, position.market.lastUpdate), createdAt))
|
|
476
|
+
.toAssets(shares ?? 0n, "Down");
|
|
465
477
|
const referralFeeAssets = getBundlesReferralFeeAssets(grossAssets, common.referralFeePct);
|
|
466
478
|
const maxSharePriceVaultV2 = computeVaultMaxSharePrice({
|
|
467
479
|
vaultData: params.targetVault,
|
|
@@ -130,10 +130,13 @@ export declare class VaultV1ReallocationData implements InputVaultV1Reallocation
|
|
|
130
130
|
* Returned `data` normalizes `vault.publicAllocatorConfig.accruedFee` to the
|
|
131
131
|
* on-chain `reallocateTo` fee semantics: one fee charge per vault with at
|
|
132
132
|
* least one computed withdrawal.
|
|
133
|
+
* Sources with zero allocator withdrawal capacity and destinations with no deposit capacity
|
|
134
|
+
* are skipped before projecting source interest.
|
|
133
135
|
*
|
|
134
136
|
* @param marketId - Target market to supply with shared liquidity.
|
|
135
137
|
* @param options - Optional allocator discovery options.
|
|
136
138
|
* @returns Computed source-market withdrawals and the post-reallocation state.
|
|
139
|
+
* @throws {UnsupportedBlueMarketIrmError} when a market with positive debt uses an unsupported IRM.
|
|
137
140
|
* @throws {@link UnknownReallocationMarketError} when the target market is absent.
|
|
138
141
|
* @deprecated Vault V1 shared-liquidity planning will be removed in the next major. Use
|
|
139
142
|
* `VaultV2BlueReallocationData.computeVaultV2BlueReallocations`.
|
|
@@ -179,6 +182,7 @@ export declare class VaultV1ReallocationData implements InputVaultV1Reallocation
|
|
|
179
182
|
* @param marketId - Target market to supply with shared liquidity.
|
|
180
183
|
* @param options - Optional allocator discovery options.
|
|
181
184
|
* @returns Computed source-market withdrawals and the post-reallocation state.
|
|
185
|
+
* @throws {UnsupportedBlueMarketIrmError} when a market with positive debt uses an unsupported IRM.
|
|
182
186
|
* @throws {@link UnknownReallocationMarketError} when the target market is absent.
|
|
183
187
|
* @deprecated Vault V1 shared-liquidity planning will be removed in the next major. Use
|
|
184
188
|
* `VaultV2BlueReallocationData.computeVaultV2BlueReallocations`.
|
|
@@ -199,6 +203,7 @@ export declare class VaultV1ReallocationData implements InputVaultV1Reallocation
|
|
|
199
203
|
* @param marketId - Target market that would receive the liquidity.
|
|
200
204
|
* @param options - Optional allocator discovery options.
|
|
201
205
|
* @returns Total reallocatable assets in loan-token units; `0n` when none is available.
|
|
206
|
+
* @throws {UnsupportedBlueMarketIrmError} when a market with positive debt uses an unsupported IRM.
|
|
202
207
|
* @throws {@link UnknownReallocationMarketError} when the target market is absent.
|
|
203
208
|
* @deprecated Vault V1 shared-liquidity metrics will be removed in the next major. Use
|
|
204
209
|
* `VaultV2BlueReallocationData.getPublicReallocationLiquidity`.
|
|
@@ -252,6 +257,7 @@ export declare class VaultV1ReallocationData implements InputVaultV1Reallocation
|
|
|
252
257
|
* @param utilization - Utilization to bring the market to, scaled by WAD. Defaults to {@link DEFAULT_SUPPLY_TARGET_UTILIZATION}.
|
|
253
258
|
* @param options - Optional reallocation options (supply target utilization trigger, timestamp, withdrawal caps).
|
|
254
259
|
* @returns Available liquidity to the given utilization in loan-token units; `0n` when none is available.
|
|
260
|
+
* @throws {UnsupportedBlueMarketIrmError} when a market with positive debt uses an unsupported IRM.
|
|
255
261
|
* @throws {@link UnknownReallocationMarketError} when the target market is absent.
|
|
256
262
|
* @deprecated Vault V1 shared-liquidity metrics will be removed in the next major. Use
|
|
257
263
|
* `VaultV2BlueReallocationData.getAvailableLiquidityToUtilization`.
|
|
@@ -210,10 +210,13 @@ export class VaultV1ReallocationData {
|
|
|
210
210
|
* Returned `data` normalizes `vault.publicAllocatorConfig.accruedFee` to the
|
|
211
211
|
* on-chain `reallocateTo` fee semantics: one fee charge per vault with at
|
|
212
212
|
* least one computed withdrawal.
|
|
213
|
+
* Sources with zero allocator withdrawal capacity and destinations with no deposit capacity
|
|
214
|
+
* are skipped before projecting source interest.
|
|
213
215
|
*
|
|
214
216
|
* @param marketId - Target market to supply with shared liquidity.
|
|
215
217
|
* @param options - Optional allocator discovery options.
|
|
216
218
|
* @returns Computed source-market withdrawals and the post-reallocation state.
|
|
219
|
+
* @throws {UnsupportedBlueMarketIrmError} when a market with positive debt uses an unsupported IRM.
|
|
217
220
|
* @throws {@link UnknownReallocationMarketError} when the target market is absent.
|
|
218
221
|
* @deprecated Vault V1 shared-liquidity planning will be removed in the next major. Use
|
|
219
222
|
* `VaultV2BlueReallocationData.computeVaultV2BlueReallocations`.
|
|
@@ -311,6 +314,7 @@ export class VaultV1ReallocationData {
|
|
|
311
314
|
* @param marketId - Target market to supply with shared liquidity.
|
|
312
315
|
* @param options - Optional allocator discovery options.
|
|
313
316
|
* @returns Computed source-market withdrawals and the post-reallocation state.
|
|
317
|
+
* @throws {UnsupportedBlueMarketIrmError} when a market with positive debt uses an unsupported IRM.
|
|
314
318
|
* @throws {@link UnknownReallocationMarketError} when the target market is absent.
|
|
315
319
|
* @deprecated Vault V1 shared-liquidity planning will be removed in the next major. Use
|
|
316
320
|
* `VaultV2BlueReallocationData.computeVaultV2BlueReallocations`.
|
|
@@ -330,6 +334,7 @@ export class VaultV1ReallocationData {
|
|
|
330
334
|
* @param marketId - Target market that would receive the liquidity.
|
|
331
335
|
* @param options - Optional allocator discovery options.
|
|
332
336
|
* @returns Total reallocatable assets in loan-token units; `0n` when none is available.
|
|
337
|
+
* @throws {UnsupportedBlueMarketIrmError} when a market with positive debt uses an unsupported IRM.
|
|
333
338
|
* @throws {@link UnknownReallocationMarketError} when the target market is absent.
|
|
334
339
|
* @deprecated Vault V1 shared-liquidity metrics will be removed in the next major. Use
|
|
335
340
|
* `VaultV2BlueReallocationData.getPublicReallocationLiquidity`.
|
|
@@ -386,6 +391,7 @@ export class VaultV1ReallocationData {
|
|
|
386
391
|
* @param utilization - Utilization to bring the market to, scaled by WAD. Defaults to {@link DEFAULT_SUPPLY_TARGET_UTILIZATION}.
|
|
387
392
|
* @param options - Optional reallocation options (supply target utilization trigger, timestamp, withdrawal caps).
|
|
388
393
|
* @returns Available liquidity to the given utilization in loan-token units; `0n` when none is available.
|
|
394
|
+
* @throws {UnsupportedBlueMarketIrmError} when a market with positive debt uses an unsupported IRM.
|
|
389
395
|
* @throws {@link UnknownReallocationMarketError} when the target market is absent.
|
|
390
396
|
* @deprecated Vault V1 shared-liquidity metrics will be removed in the next major. Use
|
|
391
397
|
* `VaultV2BlueReallocationData.getAvailableLiquidityToUtilization`.
|
|
@@ -443,25 +449,34 @@ export class VaultV1ReallocationData {
|
|
|
443
449
|
getLargestVaultWithdrawal({ vault, marketId, withdrawals, defaultMaxWithdrawalUtilization, maxWithdrawalUtilization, timestamp, }) {
|
|
444
450
|
return _try(() => {
|
|
445
451
|
const { cap, pendingCap, publicAllocatorConfig } = this.getVaultMarketConfig(vault, marketId);
|
|
452
|
+
const maxIn = publicAllocatorConfig?.maxIn ?? 0n;
|
|
446
453
|
const validCap = pendingCap.validAt >= timestamp
|
|
447
454
|
? MathLib.min(pendingCap.value, cap)
|
|
448
455
|
: cap;
|
|
456
|
+
if (maxIn === 0n || validCap === 0n)
|
|
457
|
+
return { vault };
|
|
449
458
|
const suppliable = MathLib.zeroFloorSub(validCap, this.getAccrualPosition(vault, marketId).accrueInterest(timestamp)
|
|
450
459
|
.supplyAssets);
|
|
460
|
+
if (suppliable === 0n)
|
|
461
|
+
return { vault };
|
|
451
462
|
const marketWithdrawals = this.getVault(vault)
|
|
452
463
|
.withdrawQueue.filter((srcMarketId) => srcMarketId !== marketId &&
|
|
453
464
|
!withdrawals.some((withdrawal) => withdrawal.id === srcMarketId && withdrawal.vault === vault))
|
|
454
465
|
.map((srcMarketId) => {
|
|
455
466
|
const withdrawal = _try(() => {
|
|
456
|
-
const srcPosition = this.getAccrualPosition(vault, srcMarketId).accrueInterest(timestamp);
|
|
457
|
-
const targetUtilizationLiquidity = srcPosition.market.getWithdrawToUtilization(maxWithdrawalUtilization[srcMarketId] ??
|
|
458
|
-
defaultMaxWithdrawalUtilization);
|
|
459
467
|
const srcConfig = this.getVaultMarketConfig(vault, srcMarketId);
|
|
460
|
-
|
|
468
|
+
const maxOut = srcConfig.publicAllocatorConfig?.maxOut ?? 0n;
|
|
469
|
+
if (!srcConfig.enabled || maxOut === 0n)
|
|
470
|
+
return { id: srcMarketId, assets: 0n };
|
|
471
|
+
const rawSrcPosition = this.getAccrualPosition(vault, srcMarketId);
|
|
472
|
+
if (rawSrcPosition.supplyShares === 0n)
|
|
461
473
|
return { id: srcMarketId, assets: 0n };
|
|
474
|
+
const srcPosition = rawSrcPosition.accrueInterest(timestamp);
|
|
475
|
+
const targetUtilizationLiquidity = srcPosition.market.getWithdrawToUtilization(maxWithdrawalUtilization[srcMarketId] ??
|
|
476
|
+
defaultMaxWithdrawalUtilization);
|
|
462
477
|
return {
|
|
463
478
|
id: srcMarketId,
|
|
464
|
-
assets: MathLib.min(srcPosition.supplyAssets, targetUtilizationLiquidity, suppliable,
|
|
479
|
+
assets: MathLib.min(srcPosition.supplyAssets, targetUtilizationLiquidity, suppliable, maxIn, maxOut),
|
|
465
480
|
};
|
|
466
481
|
}, UnknownDataError);
|
|
467
482
|
return withdrawal ?? { id: srcMarketId, assets: 0n };
|