@morpho-org/morpho-sdk 9.0.0 → 9.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +3 -1
- package/lib/cjs/actions/blue/borrow.d.ts +1 -0
- package/lib/cjs/actions/blue/borrow.js +1 -0
- package/lib/cjs/actions/blue/refinance.d.ts +1 -0
- package/lib/cjs/actions/blue/refinance.js +3 -0
- package/lib/cjs/actions/blue/repay.d.ts +1 -0
- package/lib/cjs/actions/blue/repay.js +1 -0
- package/lib/cjs/actions/blue/repayWithdrawCollateral.d.ts +1 -0
- package/lib/cjs/actions/blue/repayWithdrawCollateral.js +2 -0
- package/lib/cjs/actions/blue/supply.d.ts +1 -0
- package/lib/cjs/actions/blue/supply.js +2 -0
- package/lib/cjs/actions/blue/supplyCollateral.d.ts +1 -0
- package/lib/cjs/actions/blue/supplyCollateral.js +1 -0
- package/lib/cjs/actions/blue/supplyCollateralBorrow.d.ts +1 -0
- package/lib/cjs/actions/blue/supplyCollateralBorrow.js +2 -0
- package/lib/cjs/actions/blue/withdraw.d.ts +1 -0
- package/lib/cjs/actions/blue/withdraw.js +2 -0
- package/lib/cjs/actions/blue/withdrawCollateral.d.ts +1 -0
- package/lib/cjs/actions/blue/withdrawCollateral.js +1 -0
- package/lib/cjs/actions/midnight/takeLend.d.ts +1 -0
- package/lib/cjs/actions/midnight/takeLend.js +1 -0
- package/lib/cjs/actions/midnight/takeRepayWithdrawCollateral.d.ts +1 -0
- package/lib/cjs/actions/midnight/takeRepayWithdrawCollateral.js +1 -0
- package/lib/cjs/blue/errors.d.ts +1 -1
- package/lib/cjs/blue/errors.js +2 -1
- package/lib/cjs/client/morphoViemExtension.d.ts +1 -1
- package/lib/cjs/client/morphoViemExtension.js +1 -7
- package/lib/cjs/entities/blue/blue.d.ts +43 -7
- package/lib/cjs/entities/blue/blue.js +27 -3
- package/lib/cjs/entities/midnight/midnight.d.ts +14 -6
- package/lib/cjs/entities/midnight/midnight.js +14 -6
- package/lib/cjs/entities/midnight/types.d.ts +9 -2
- package/lib/cjs/entities/vaultV2/vaultV2.d.ts +3 -1
- package/lib/cjs/entities/vaultV2/vaultV2.js +8 -5
- package/lib/cjs/entities/vaultV2BlueReallocationData.d.ts +40 -13
- package/lib/cjs/entities/vaultV2BlueReallocationData.js +207 -70
- package/lib/cjs/errors.d.ts +1 -1
- package/lib/cjs/errors.js +3 -2
- package/lib/cjs/helpers/validate.d.ts +11 -1
- package/lib/cjs/helpers/validate.js +17 -1
- package/lib/cjs/helpers/validateTakeableOffers.d.ts +4 -2
- package/lib/cjs/helpers/validateTakeableOffers.js +12 -1
- package/lib/cjs/types/error.d.ts +10 -1
- package/lib/cjs/types/error.js +13 -2
- package/lib/cjs/types/sharedLiquidity.d.ts +27 -11
- package/lib/esm/actions/blue/borrow.d.ts +1 -0
- package/lib/esm/actions/blue/borrow.js +1 -0
- package/lib/esm/actions/blue/refinance.d.ts +1 -0
- package/lib/esm/actions/blue/refinance.js +4 -1
- package/lib/esm/actions/blue/repay.d.ts +1 -0
- package/lib/esm/actions/blue/repay.js +1 -0
- package/lib/esm/actions/blue/repayWithdrawCollateral.d.ts +1 -0
- package/lib/esm/actions/blue/repayWithdrawCollateral.js +3 -1
- package/lib/esm/actions/blue/supply.d.ts +1 -0
- package/lib/esm/actions/blue/supply.js +3 -1
- package/lib/esm/actions/blue/supplyCollateral.d.ts +1 -0
- package/lib/esm/actions/blue/supplyCollateral.js +1 -0
- package/lib/esm/actions/blue/supplyCollateralBorrow.d.ts +1 -0
- package/lib/esm/actions/blue/supplyCollateralBorrow.js +3 -1
- package/lib/esm/actions/blue/withdraw.d.ts +1 -0
- package/lib/esm/actions/blue/withdraw.js +3 -1
- package/lib/esm/actions/blue/withdrawCollateral.d.ts +1 -0
- package/lib/esm/actions/blue/withdrawCollateral.js +1 -0
- package/lib/esm/actions/midnight/takeLend.d.ts +1 -0
- package/lib/esm/actions/midnight/takeLend.js +1 -0
- package/lib/esm/actions/midnight/takeRepayWithdrawCollateral.d.ts +1 -0
- package/lib/esm/actions/midnight/takeRepayWithdrawCollateral.js +1 -0
- package/lib/esm/blue/errors.d.ts +1 -1
- package/lib/esm/blue/errors.js +1 -1
- package/lib/esm/client/morphoViemExtension.d.ts +1 -1
- package/lib/esm/client/morphoViemExtension.js +1 -7
- package/lib/esm/entities/blue/blue.d.ts +43 -7
- package/lib/esm/entities/blue/blue.js +27 -3
- package/lib/esm/entities/midnight/midnight.d.ts +14 -6
- package/lib/esm/entities/midnight/midnight.js +14 -6
- package/lib/esm/entities/midnight/types.d.ts +9 -2
- package/lib/esm/entities/vaultV2/vaultV2.d.ts +3 -1
- package/lib/esm/entities/vaultV2/vaultV2.js +9 -6
- package/lib/esm/entities/vaultV2BlueReallocationData.d.ts +40 -13
- package/lib/esm/entities/vaultV2BlueReallocationData.js +208 -71
- package/lib/esm/errors.d.ts +1 -1
- package/lib/esm/errors.js +1 -1
- package/lib/esm/helpers/validate.d.ts +11 -1
- package/lib/esm/helpers/validate.js +15 -0
- package/lib/esm/helpers/validateTakeableOffers.d.ts +4 -2
- package/lib/esm/helpers/validateTakeableOffers.js +13 -2
- package/lib/esm/types/error.d.ts +10 -1
- package/lib/esm/types/error.js +11 -1
- package/lib/esm/types/sharedLiquidity.d.ts +27 -11
- package/package.json +4 -4
package/README.md
CHANGED
|
@@ -58,7 +58,9 @@ BlueBundlesV1, and the remaining rows identify their destination.
|
|
|
58
58
|
supplies it in the same transaction.
|
|
59
59
|
|
|
60
60
|
`makeWithdraw` publishes reduce-only sell offers for lend limit exits. `makeRepay` publishes
|
|
61
|
-
reduce-only buy offers for borrow limit exits
|
|
61
|
+
reduce-only buy offers for borrow limit exits; its `loanAssets` input only sets the
|
|
62
|
+
minimum Midnight allowance that `getRequirements()` checks (the approval it returns is
|
|
63
|
+
unlimited), while the signed offer caps bound fills.
|
|
62
64
|
Both preserve the supplied offer tree and use `midnightCancelAndMake`; neither executes a fill
|
|
63
65
|
or withdraws collateral during publication. Send their approval/authorization requirements first,
|
|
64
66
|
then call `buildTx()` without a separate root signature.
|
|
@@ -50,6 +50,7 @@ export interface BlueBorrowParams {
|
|
|
50
50
|
* @param params.metadata - Optional transaction metadata.
|
|
51
51
|
* @returns A deep-frozen `Readonly<Transaction<BlueBorrowAction>>` whose calldata invokes the
|
|
52
52
|
* combined BlueBundlesV1 entrypoint with a zero collateral leg.
|
|
53
|
+
* @throws {MarketIdMismatchError} when `marketParams.id` does not hash from its tuple fields.
|
|
53
54
|
* @throws {NegativeInputError} when an amount, LTV, fee, or reallocation penalty is negative.
|
|
54
55
|
* @throws {NonPositiveInputError} when the borrow, deadline, or reallocation amount is not positive.
|
|
55
56
|
* @throws {InputExceedsMaxError} when a fee, reallocation amount, or penalty exceeds its bound.
|
|
@@ -23,6 +23,7 @@ const supplyCollateralBorrow_js_1 = require("./supplyCollateralBorrow.js");
|
|
|
23
23
|
* @param params.metadata - Optional transaction metadata.
|
|
24
24
|
* @returns A deep-frozen `Readonly<Transaction<BlueBorrowAction>>` whose calldata invokes the
|
|
25
25
|
* combined BlueBundlesV1 entrypoint with a zero collateral leg.
|
|
26
|
+
* @throws {MarketIdMismatchError} when `marketParams.id` does not hash from its tuple fields.
|
|
26
27
|
* @throws {NegativeInputError} when an amount, LTV, fee, or reallocation penalty is negative.
|
|
27
28
|
* @throws {NonPositiveInputError} when the borrow, deadline, or reallocation amount is not positive.
|
|
28
29
|
* @throws {InputExceedsMaxError} when a fee, reallocation amount, or penalty exceeds its bound.
|
|
@@ -56,6 +56,7 @@ export interface BlueRefinanceParams {
|
|
|
56
56
|
* @param params.metadata - Optional transaction metadata.
|
|
57
57
|
* @returns A deep-frozen `Readonly<Transaction<BlueRefinanceAction>>` whose
|
|
58
58
|
* `to` address is BlueBundlesV1 and whose `action` records the normalized migration inputs.
|
|
59
|
+
* @throws {MarketIdMismatchError} when either market's `id` does not hash from its tuple fields.
|
|
59
60
|
* @throws {RefinanceSameMarketError} when source and destination IDs match.
|
|
60
61
|
* @throws {RefinanceTokenMismatchError} when their loan or collateral tokens differ.
|
|
61
62
|
* @throws {NegativeInputError} when `maxLtv`, a referral fee, or a reallocation penalty is negative.
|
|
@@ -29,6 +29,7 @@ const common_js_1 = require("./common.js");
|
|
|
29
29
|
* @param params.metadata - Optional transaction metadata.
|
|
30
30
|
* @returns A deep-frozen `Readonly<Transaction<BlueRefinanceAction>>` whose
|
|
31
31
|
* `to` address is BlueBundlesV1 and whose `action` records the normalized migration inputs.
|
|
32
|
+
* @throws {MarketIdMismatchError} when either market's `id` does not hash from its tuple fields.
|
|
32
33
|
* @throws {RefinanceSameMarketError} when source and destination IDs match.
|
|
33
34
|
* @throws {RefinanceTokenMismatchError} when their loan or collateral tokens differ.
|
|
34
35
|
* @throws {NegativeInputError} when `maxLtv`, a referral fee, or a reallocation penalty is negative.
|
|
@@ -67,6 +68,8 @@ const common_js_1 = require("./common.js");
|
|
|
67
68
|
*/
|
|
68
69
|
const blueRefinance = (params) => {
|
|
69
70
|
const { chainId, sourceMarketParams, destinationMarketParams } = params.market;
|
|
71
|
+
(0, validate_js_1.validateMarketParamsId)(sourceMarketParams);
|
|
72
|
+
(0, validate_js_1.validateMarketParamsId)(destinationMarketParams);
|
|
70
73
|
const { userAddress, maxLtv, authorizationSignature } = params.args;
|
|
71
74
|
if (sourceMarketParams.id === destinationMarketParams.id) {
|
|
72
75
|
throw new index_js_1.RefinanceSameMarketError(sourceMarketParams.id);
|
|
@@ -53,6 +53,7 @@ export interface BlueRepayParams {
|
|
|
53
53
|
* @param params.metadata - Optional transaction metadata.
|
|
54
54
|
* @returns A deep-frozen `Readonly<Transaction<BlueRepayAction>>` whose calldata invokes the
|
|
55
55
|
* combined BlueBundlesV1 entrypoint with a zero collateral-withdrawal leg.
|
|
56
|
+
* @throws {MarketIdMismatchError} when `marketParams.id` does not hash from its tuple fields.
|
|
56
57
|
* @throws {NegativeInputError} when an amount or fee is negative.
|
|
57
58
|
* @throws {MutuallyExclusiveRepayAmountsError} when assets and shares are both nonzero.
|
|
58
59
|
* @throws {NonPositiveInputError} when repayment, funding, or deadline is not positive.
|
|
@@ -25,6 +25,7 @@ const repayWithdrawCollateral_js_1 = require("./repayWithdrawCollateral.js");
|
|
|
25
25
|
* @param params.metadata - Optional transaction metadata.
|
|
26
26
|
* @returns A deep-frozen `Readonly<Transaction<BlueRepayAction>>` whose calldata invokes the
|
|
27
27
|
* combined BlueBundlesV1 entrypoint with a zero collateral-withdrawal leg.
|
|
28
|
+
* @throws {MarketIdMismatchError} when `marketParams.id` does not hash from its tuple fields.
|
|
28
29
|
* @throws {NegativeInputError} when an amount or fee is negative.
|
|
29
30
|
* @throws {MutuallyExclusiveRepayAmountsError} when assets and shares are both nonzero.
|
|
30
31
|
* @throws {NonPositiveInputError} when repayment, funding, or deadline is not positive.
|
|
@@ -63,6 +63,7 @@ export interface BlueRepayWithdrawCollateralParams {
|
|
|
63
63
|
* @param params.metadata - Optional transaction metadata.
|
|
64
64
|
* @returns A deep-frozen `Readonly<Transaction<BlueRepayWithdrawCollateralAction>>`
|
|
65
65
|
* whose `to` address is BlueBundlesV1 and whose `action` records the normalized inputs.
|
|
66
|
+
* @throws {MarketIdMismatchError} when `marketParams.id` does not hash from its tuple fields.
|
|
66
67
|
* @throws {NegativeInputError} when an amount, `maxLtv`, native value, or fee is negative.
|
|
67
68
|
* @throws {MutuallyExclusiveRepayAmountsError} when assets and shares are both nonzero.
|
|
68
69
|
* @throws {NonPositiveInputError} when both operation legs are zero, repay funding is absent, or the deadline is invalid.
|
|
@@ -31,6 +31,7 @@ const common_js_1 = require("./common.js");
|
|
|
31
31
|
* @param params.metadata - Optional transaction metadata.
|
|
32
32
|
* @returns A deep-frozen `Readonly<Transaction<BlueRepayWithdrawCollateralAction>>`
|
|
33
33
|
* whose `to` address is BlueBundlesV1 and whose `action` records the normalized inputs.
|
|
34
|
+
* @throws {MarketIdMismatchError} when `marketParams.id` does not hash from its tuple fields.
|
|
34
35
|
* @throws {NegativeInputError} when an amount, `maxLtv`, native value, or fee is negative.
|
|
35
36
|
* @throws {MutuallyExclusiveRepayAmountsError} when assets and shares are both nonzero.
|
|
36
37
|
* @throws {NonPositiveInputError} when both operation legs are zero, repay funding is absent, or the deadline is invalid.
|
|
@@ -73,6 +74,7 @@ const common_js_1 = require("./common.js");
|
|
|
73
74
|
*/
|
|
74
75
|
const blueRepayWithdrawCollateral = (params) => {
|
|
75
76
|
const { chainId, marketParams } = params.market;
|
|
77
|
+
(0, validate_js_1.validateMarketParamsId)(marketParams);
|
|
76
78
|
const { userAddress, repayAssets, repayShares, maxRepayAssets, collateralAssets, maxLtv, requirementSignature, authorizationSignature, } = params.args;
|
|
77
79
|
for (const [field, value] of [
|
|
78
80
|
["repayAssets", repayAssets],
|
|
@@ -47,6 +47,7 @@ export interface BlueSupplyParams {
|
|
|
47
47
|
* @param params.metadata - Optional transaction metadata.
|
|
48
48
|
* @returns A deep-frozen `Readonly<Transaction<BlueSupplyAction>>` whose `to` address is
|
|
49
49
|
* BlueBundlesV1 and whose `action` records the normalized supply inputs.
|
|
50
|
+
* @throws {MarketIdMismatchError} when `marketParams.id` does not hash from its tuple fields.
|
|
50
51
|
* @throws {NonPositiveInputError} when `assets` or `deadline` is not positive.
|
|
51
52
|
* @throws {NegativeInputError} when `nativeAmount` or `referralFeePct` is negative.
|
|
52
53
|
* @throws {InputExceedsMaxError} when `assets` exceeds `uint256` or `referralFeePct` is at least WAD.
|
|
@@ -26,6 +26,7 @@ const common_js_2 = require("./common.js");
|
|
|
26
26
|
* @param params.metadata - Optional transaction metadata.
|
|
27
27
|
* @returns A deep-frozen `Readonly<Transaction<BlueSupplyAction>>` whose `to` address is
|
|
28
28
|
* BlueBundlesV1 and whose `action` records the normalized supply inputs.
|
|
29
|
+
* @throws {MarketIdMismatchError} when `marketParams.id` does not hash from its tuple fields.
|
|
29
30
|
* @throws {NonPositiveInputError} when `assets` or `deadline` is not positive.
|
|
30
31
|
* @throws {NegativeInputError} when `nativeAmount` or `referralFeePct` is negative.
|
|
31
32
|
* @throws {InputExceedsMaxError} when `assets` exceeds `uint256` or `referralFeePct` is at least WAD.
|
|
@@ -62,6 +63,7 @@ const common_js_2 = require("./common.js");
|
|
|
62
63
|
*/
|
|
63
64
|
const blueSupply = (params) => {
|
|
64
65
|
const { chainId, marketParams } = params.market;
|
|
66
|
+
(0, validate_js_1.validateMarketParamsId)(marketParams);
|
|
65
67
|
const { assets, userAddress, requirementSignature } = params.args;
|
|
66
68
|
if (assets <= 0n) {
|
|
67
69
|
throw new index_js_1.NonPositiveInputError("assets", assets);
|
|
@@ -47,6 +47,7 @@ export interface BlueSupplyCollateralParams {
|
|
|
47
47
|
* @param params.metadata - Optional transaction metadata.
|
|
48
48
|
* @returns A deep-frozen `Readonly<Transaction<BlueSupplyCollateralAction>>` whose calldata
|
|
49
49
|
* invokes the combined BlueBundlesV1 entrypoint with a zero borrow leg.
|
|
50
|
+
* @throws {MarketIdMismatchError} when `marketParams.id` does not hash from its tuple fields.
|
|
50
51
|
* @throws {NegativeInputError} when an amount or fee is negative.
|
|
51
52
|
* @throws {NonPositiveInputError} when collateral or deadline is not positive.
|
|
52
53
|
* @throws {NativeFundingAmountMismatchError} when native funding is partial or mixed.
|
|
@@ -23,6 +23,7 @@ const supplyCollateralBorrow_js_1 = require("./supplyCollateralBorrow.js");
|
|
|
23
23
|
* @param params.metadata - Optional transaction metadata.
|
|
24
24
|
* @returns A deep-frozen `Readonly<Transaction<BlueSupplyCollateralAction>>` whose calldata
|
|
25
25
|
* invokes the combined BlueBundlesV1 entrypoint with a zero borrow leg.
|
|
26
|
+
* @throws {MarketIdMismatchError} when `marketParams.id` does not hash from its tuple fields.
|
|
26
27
|
* @throws {NegativeInputError} when an amount or fee is negative.
|
|
27
28
|
* @throws {NonPositiveInputError} when collateral or deadline is not positive.
|
|
28
29
|
* @throws {NativeFundingAmountMismatchError} when native funding is partial or mixed.
|
|
@@ -59,6 +59,7 @@ export interface BlueSupplyCollateralBorrowParams {
|
|
|
59
59
|
* @param params.metadata - Optional transaction metadata.
|
|
60
60
|
* @returns A deep-frozen `Readonly<Transaction<BlueSupplyCollateralBorrowAction>>`
|
|
61
61
|
* whose `to` address is BlueBundlesV1 and whose `action` records the normalized inputs.
|
|
62
|
+
* @throws {MarketIdMismatchError} when `marketParams.id` does not hash from its tuple fields.
|
|
62
63
|
* @throws {NegativeInputError} when an amount, `maxLtv`, native value, or fee is negative.
|
|
63
64
|
* @throws {NonPositiveInputError} when both operation legs are zero, the deadline is not positive,
|
|
64
65
|
* or a reallocation amount is not positive.
|
|
@@ -30,6 +30,7 @@ const common_js_2 = require("./common.js");
|
|
|
30
30
|
* @param params.metadata - Optional transaction metadata.
|
|
31
31
|
* @returns A deep-frozen `Readonly<Transaction<BlueSupplyCollateralBorrowAction>>`
|
|
32
32
|
* whose `to` address is BlueBundlesV1 and whose `action` records the normalized inputs.
|
|
33
|
+
* @throws {MarketIdMismatchError} when `marketParams.id` does not hash from its tuple fields.
|
|
33
34
|
* @throws {NegativeInputError} when an amount, `maxLtv`, native value, or fee is negative.
|
|
34
35
|
* @throws {NonPositiveInputError} when both operation legs are zero, the deadline is not positive,
|
|
35
36
|
* or a reallocation amount is not positive.
|
|
@@ -76,6 +77,7 @@ const common_js_2 = require("./common.js");
|
|
|
76
77
|
*/
|
|
77
78
|
const blueSupplyCollateralBorrow = (params) => {
|
|
78
79
|
const { chainId, marketParams } = params.market;
|
|
80
|
+
(0, validate_js_1.validateMarketParamsId)(marketParams);
|
|
79
81
|
const { userAddress, collateralAssets, borrowAssets, maxLtv, requirementSignature, authorizationSignature, } = params.args;
|
|
80
82
|
for (const [field, value] of [
|
|
81
83
|
["collateralAssets", collateralAssets],
|
|
@@ -51,6 +51,7 @@ export interface BlueWithdrawParams {
|
|
|
51
51
|
* @param params.metadata - Optional transaction metadata.
|
|
52
52
|
* @returns A deep-frozen `Readonly<Transaction<BlueWithdrawAction>>` whose `to` address is
|
|
53
53
|
* BlueBundlesV1 and whose `action` records the normalized withdrawal inputs.
|
|
54
|
+
* @throws {MarketIdMismatchError} when `marketParams.id` does not hash from its tuple fields.
|
|
54
55
|
* @throws {NegativeInputError} when an amount, fee, or reallocation penalty is negative.
|
|
55
56
|
* @throws {MutuallyExclusiveWithdrawAmountsError} when assets and shares are both nonzero.
|
|
56
57
|
* @throws {NonPositiveInputError} when neither mode, no valid deadline, or a non-positive
|
|
@@ -28,6 +28,7 @@ const common_js_2 = require("./common.js");
|
|
|
28
28
|
* @param params.metadata - Optional transaction metadata.
|
|
29
29
|
* @returns A deep-frozen `Readonly<Transaction<BlueWithdrawAction>>` whose `to` address is
|
|
30
30
|
* BlueBundlesV1 and whose `action` records the normalized withdrawal inputs.
|
|
31
|
+
* @throws {MarketIdMismatchError} when `marketParams.id` does not hash from its tuple fields.
|
|
31
32
|
* @throws {NegativeInputError} when an amount, fee, or reallocation penalty is negative.
|
|
32
33
|
* @throws {MutuallyExclusiveWithdrawAmountsError} when assets and shares are both nonzero.
|
|
33
34
|
* @throws {NonPositiveInputError} when neither mode, no valid deadline, or a non-positive
|
|
@@ -66,6 +67,7 @@ const common_js_2 = require("./common.js");
|
|
|
66
67
|
*/
|
|
67
68
|
const blueWithdraw = (params) => {
|
|
68
69
|
const { chainId, marketParams } = params.market;
|
|
70
|
+
(0, validate_js_1.validateMarketParamsId)(marketParams);
|
|
69
71
|
const { userAddress, withdrawAssets, withdrawShares, authorizationSignature, } = params.args;
|
|
70
72
|
(0, validate_js_1.validateUint256Field)("withdrawAssets", withdrawAssets);
|
|
71
73
|
(0, validate_js_1.validateUint256Field)("withdrawShares", withdrawShares);
|
|
@@ -47,6 +47,7 @@ export interface BlueWithdrawCollateralParams {
|
|
|
47
47
|
* @param params.metadata - Optional transaction metadata.
|
|
48
48
|
* @returns A deep-frozen `Readonly<Transaction<BlueWithdrawCollateralAction>>` whose calldata
|
|
49
49
|
* invokes the combined BlueBundlesV1 entrypoint with a zero repay leg.
|
|
50
|
+
* @throws {MarketIdMismatchError} when `marketParams.id` does not hash from its tuple fields.
|
|
50
51
|
* @throws {NegativeInputError} when collateral, LTV, or fee is negative.
|
|
51
52
|
* @throws {NonPositiveInputError} when collateral or deadline is not positive.
|
|
52
53
|
* @throws {InputExceedsMaxError} when the referral fee is at least WAD.
|
|
@@ -22,6 +22,7 @@ const repayWithdrawCollateral_js_1 = require("./repayWithdrawCollateral.js");
|
|
|
22
22
|
* @param params.metadata - Optional transaction metadata.
|
|
23
23
|
* @returns A deep-frozen `Readonly<Transaction<BlueWithdrawCollateralAction>>` whose calldata
|
|
24
24
|
* invokes the combined BlueBundlesV1 entrypoint with a zero repay leg.
|
|
25
|
+
* @throws {MarketIdMismatchError} when `marketParams.id` does not hash from its tuple fields.
|
|
25
26
|
* @throws {NegativeInputError} when collateral, LTV, or fee is negative.
|
|
26
27
|
* @throws {NonPositiveInputError} when collateral or deadline is not positive.
|
|
27
28
|
* @throws {InputExceedsMaxError} when the referral fee is at least WAD.
|
|
@@ -51,6 +51,7 @@ export interface MidnightTakeLendParams extends MidnightReferralFeeParams {
|
|
|
51
51
|
* @throws {EmptyMidnightTakeableOffersError} when no offers are provided.
|
|
52
52
|
* @throws {MidnightOfferSideMismatchError} when any offer is not borrow-side.
|
|
53
53
|
* @throws {MidnightTakeableOfferMarketMismatchError} when any offer belongs to another market.
|
|
54
|
+
* @throws {MidnightTakeableOfferZeroSellerReceiverError} when any offer routes seller proceeds to the zero address.
|
|
54
55
|
* @throws {NonPositiveInputError} when the target amount, `minUnits`, `maxBuyerAssets` or `deadline` is not positive.
|
|
55
56
|
* @throws {NegativeInputError} when a takeable offer cap, `maxContinuousFee`,
|
|
56
57
|
* `referralFeePct` or `nativeAmount` is negative.
|
|
@@ -43,6 +43,7 @@ const index_js_2 = require("../../types/index.js");
|
|
|
43
43
|
* @throws {EmptyMidnightTakeableOffersError} when no offers are provided.
|
|
44
44
|
* @throws {MidnightOfferSideMismatchError} when any offer is not borrow-side.
|
|
45
45
|
* @throws {MidnightTakeableOfferMarketMismatchError} when any offer belongs to another market.
|
|
46
|
+
* @throws {MidnightTakeableOfferZeroSellerReceiverError} when any offer routes seller proceeds to the zero address.
|
|
46
47
|
* @throws {NonPositiveInputError} when the target amount, `minUnits`, `maxBuyerAssets` or `deadline` is not positive.
|
|
47
48
|
* @throws {NegativeInputError} when a takeable offer cap, `maxContinuousFee`,
|
|
48
49
|
* `referralFeePct` or `nativeAmount` is negative.
|
|
@@ -70,6 +70,7 @@ export interface MidnightTakeRepayWithdrawCollateralParams extends MidnightRefer
|
|
|
70
70
|
* @throws {EmptyMidnightTakeableOffersError} when no offers are provided.
|
|
71
71
|
* @throws {MidnightOfferSideMismatchError} when any offer is not borrow-side.
|
|
72
72
|
* @throws {MidnightTakeableOfferMarketMismatchError} when any offer belongs to another market.
|
|
73
|
+
* @throws {MidnightTakeableOfferZeroSellerReceiverError} when any offer routes seller proceeds to the zero address.
|
|
73
74
|
* @throws {UnknownCollateralIndexError} when a withdrawal targets a collateral index not configured on the market.
|
|
74
75
|
* @throws {NonPositiveInputError} when the target amount, `minUnits`, `maxBuyerAssets`, a
|
|
75
76
|
* withdrawal amount or `deadline` is not positive.
|
|
@@ -55,6 +55,7 @@ const index_js_2 = require("../../types/index.js");
|
|
|
55
55
|
* @throws {EmptyMidnightTakeableOffersError} when no offers are provided.
|
|
56
56
|
* @throws {MidnightOfferSideMismatchError} when any offer is not borrow-side.
|
|
57
57
|
* @throws {MidnightTakeableOfferMarketMismatchError} when any offer belongs to another market.
|
|
58
|
+
* @throws {MidnightTakeableOfferZeroSellerReceiverError} when any offer routes seller proceeds to the zero address.
|
|
58
59
|
* @throws {UnknownCollateralIndexError} when a withdrawal targets a collateral index not configured on the market.
|
|
59
60
|
* @throws {NonPositiveInputError} when the target amount, `minUnits`, `maxBuyerAssets`, a
|
|
60
61
|
* withdrawal amount or `deadline` is not positive.
|
package/lib/cjs/blue/errors.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
export { BlueErrors, DivisionByZeroError, IncompleteChainRegistryError, InvalidAddressError, InvalidBitLengthError, InvalidMarketParamsError, RegistryValueAlreadyRegisteredError, UnknownAddressError, UnknownDataError, UnknownFactory, UnknownMarketAllocationError, UnknownMarketParamsError, UnknownOfFactory, UnknownTokenError, UnknownTokenPriceError, UnknownVaultConfigError, UnsupportedChainIdError, UnsupportedMarketIrmError,
|
|
2
2
|
/** @deprecated Pre-liquidation support is deprecated and will be removed in the next major. */
|
|
3
3
|
UnsupportedPreLiquidationParamsError, UnsupportedVaultV2AdapterError, VaultV2Errors, } from "@morpho-org/blue-sdk";
|
|
4
|
-
export { getUnsupportedVaultV2Adapter, InvalidNumberError, InvalidPermitDomainChainIdError, InvalidPermitDomainVerifyingContractError, isUnknownOfFactoryError, MalformedTokenMetadataError, MarketParamsIdMismatchError, MissingPermitDomainNameError, NonTupleReturnValueError, UnknownAbiFunctionError, UnnamedAbiOutputsError, UnsupportedPermitDomainExtensionsError, } from "@morpho-org/blue-sdk-viem";
|
|
4
|
+
export { getUnsupportedVaultV2Adapter, InvalidNumberError, InvalidPermitDomainChainIdError, InvalidPermitDomainVerifyingContractError, isUnknownOfFactoryError, MalformedTokenMetadataError, MarketParamsIdMismatchError, MissingPermitDomainNameError, NonTupleReturnValueError, Permit2ExpirationOutOfRangeError, UnknownAbiFunctionError, UnnamedAbiOutputsError, UnsupportedPermitDomainExtensionsError, } from "@morpho-org/blue-sdk-viem";
|
package/lib/cjs/blue/errors.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.UnsupportedPermitDomainExtensionsError = exports.UnnamedAbiOutputsError = exports.UnknownAbiFunctionError = exports.NonTupleReturnValueError = exports.MissingPermitDomainNameError = exports.MarketParamsIdMismatchError = exports.MalformedTokenMetadataError = exports.isUnknownOfFactoryError = exports.InvalidPermitDomainVerifyingContractError = exports.InvalidPermitDomainChainIdError = exports.InvalidNumberError = exports.getUnsupportedVaultV2Adapter = exports.VaultV2Errors = exports.UnsupportedVaultV2AdapterError = exports.UnsupportedPreLiquidationParamsError = exports.UnsupportedMarketIrmError = exports.UnsupportedChainIdError = exports.UnknownVaultConfigError = exports.UnknownTokenPriceError = exports.UnknownTokenError = exports.UnknownOfFactory = exports.UnknownMarketParamsError = exports.UnknownMarketAllocationError = exports.UnknownFactory = exports.UnknownDataError = exports.UnknownAddressError = exports.RegistryValueAlreadyRegisteredError = exports.InvalidMarketParamsError = exports.InvalidBitLengthError = exports.InvalidAddressError = exports.IncompleteChainRegistryError = exports.DivisionByZeroError = exports.BlueErrors = void 0;
|
|
3
|
+
exports.UnsupportedPermitDomainExtensionsError = exports.UnnamedAbiOutputsError = exports.UnknownAbiFunctionError = exports.Permit2ExpirationOutOfRangeError = exports.NonTupleReturnValueError = exports.MissingPermitDomainNameError = exports.MarketParamsIdMismatchError = exports.MalformedTokenMetadataError = exports.isUnknownOfFactoryError = exports.InvalidPermitDomainVerifyingContractError = exports.InvalidPermitDomainChainIdError = exports.InvalidNumberError = exports.getUnsupportedVaultV2Adapter = exports.VaultV2Errors = exports.UnsupportedVaultV2AdapterError = exports.UnsupportedPreLiquidationParamsError = exports.UnsupportedMarketIrmError = exports.UnsupportedChainIdError = exports.UnknownVaultConfigError = exports.UnknownTokenPriceError = exports.UnknownTokenError = exports.UnknownOfFactory = exports.UnknownMarketParamsError = exports.UnknownMarketAllocationError = exports.UnknownFactory = exports.UnknownDataError = exports.UnknownAddressError = exports.RegistryValueAlreadyRegisteredError = exports.InvalidMarketParamsError = exports.InvalidBitLengthError = exports.InvalidAddressError = exports.IncompleteChainRegistryError = exports.DivisionByZeroError = exports.BlueErrors = void 0;
|
|
4
4
|
var blue_sdk_1 = require("@morpho-org/blue-sdk");
|
|
5
5
|
Object.defineProperty(exports, "BlueErrors", { enumerable: true, get: function () { return blue_sdk_1.BlueErrors; } });
|
|
6
6
|
Object.defineProperty(exports, "DivisionByZeroError", { enumerable: true, get: function () { return blue_sdk_1.DivisionByZeroError; } });
|
|
@@ -34,6 +34,7 @@ Object.defineProperty(exports, "MalformedTokenMetadataError", { enumerable: true
|
|
|
34
34
|
Object.defineProperty(exports, "MarketParamsIdMismatchError", { enumerable: true, get: function () { return blue_sdk_viem_1.MarketParamsIdMismatchError; } });
|
|
35
35
|
Object.defineProperty(exports, "MissingPermitDomainNameError", { enumerable: true, get: function () { return blue_sdk_viem_1.MissingPermitDomainNameError; } });
|
|
36
36
|
Object.defineProperty(exports, "NonTupleReturnValueError", { enumerable: true, get: function () { return blue_sdk_viem_1.NonTupleReturnValueError; } });
|
|
37
|
+
Object.defineProperty(exports, "Permit2ExpirationOutOfRangeError", { enumerable: true, get: function () { return blue_sdk_viem_1.Permit2ExpirationOutOfRangeError; } });
|
|
37
38
|
Object.defineProperty(exports, "UnknownAbiFunctionError", { enumerable: true, get: function () { return blue_sdk_viem_1.UnknownAbiFunctionError; } });
|
|
38
39
|
Object.defineProperty(exports, "UnnamedAbiOutputsError", { enumerable: true, get: function () { return blue_sdk_viem_1.UnnamedAbiOutputsError; } });
|
|
39
40
|
Object.defineProperty(exports, "UnsupportedPermitDomainExtensionsError", { enumerable: true, get: function () { return blue_sdk_viem_1.UnsupportedPermitDomainExtensionsError; } });
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { Client } from "viem";
|
|
2
|
-
import {
|
|
2
|
+
import type { Metadata, MorphoClientType } from "../types/index.js";
|
|
3
3
|
/**
|
|
4
4
|
* Returns a viem `extend(...)` function that adds a stateless `morpho` namespace to a viem client.
|
|
5
5
|
* The namespace rides on top of the same client (one transport / chain / account) and exposes the
|
|
@@ -1,10 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.morphoViemExtension = morphoViemExtension;
|
|
4
|
-
const blue_sdk_1 = require("@morpho-org/blue-sdk");
|
|
5
4
|
const morpho_ts_1 = require("@morpho-org/morpho-ts");
|
|
6
5
|
const index_js_1 = require("../entities/index.js");
|
|
7
|
-
const index_js_2 = require("../types/index.js");
|
|
8
6
|
/**
|
|
9
7
|
* Builds the stateless `morpho` namespace exposed on an extended viem client. Wraps the supplied
|
|
10
8
|
* viem `Client` plus a frozen options bag and exposes factory methods for the protocol entities.
|
|
@@ -30,11 +28,7 @@ function createMorphoNamespace(viemClient, options) {
|
|
|
30
28
|
return new index_js_1.MorphoVaultV2(namespace, vault, chainId);
|
|
31
29
|
},
|
|
32
30
|
blue(marketParams, chainId) {
|
|
33
|
-
|
|
34
|
-
// Can happen with one-time/hardcoded/agent-written possibly inconsistent input market params.
|
|
35
|
-
if (marketParams.id !== derivedId) {
|
|
36
|
-
throw new index_js_2.MarketIdMismatchError(marketParams.id, derivedId);
|
|
37
|
-
}
|
|
31
|
+
// The constructor rejects one-time/hardcoded/agent-written market params whose id does not hash from the tuple.
|
|
38
32
|
return new index_js_1.MorphoBlue(namespace, marketParams, chainId);
|
|
39
33
|
},
|
|
40
34
|
midnight(chainId) {
|
|
@@ -9,6 +9,10 @@ type VaultV2BlueReallocationsParams = {
|
|
|
9
9
|
readonly operation?: {
|
|
10
10
|
readonly type: "borrow" | "withdraw";
|
|
11
11
|
readonly amount: bigint;
|
|
12
|
+
} | {
|
|
13
|
+
readonly type: "refinance";
|
|
14
|
+
readonly amount: bigint;
|
|
15
|
+
readonly referralFeePct?: bigint;
|
|
12
16
|
};
|
|
13
17
|
};
|
|
14
18
|
};
|
|
@@ -764,7 +768,7 @@ export interface BlueActions {
|
|
|
764
768
|
* `getRequirements()` when the RPC reports another chain via `eth_chainId`.
|
|
765
769
|
* @throws {UnsupportedBlueMarketIrmError} when positive source or destination debt requires an unsupported IRM projection.
|
|
766
770
|
* @throws {MissingAccrualPositionError} when either position snapshot is absent at runtime.
|
|
767
|
-
* @throws {MarketIdMismatchError} when a position snapshot belongs to another market.
|
|
771
|
+
* @throws {MarketIdMismatchError} when `destination.marketParams.id` does not hash from its tuple fields, or a position snapshot belongs to another market.
|
|
768
772
|
* @throws {AccrualPositionUserMismatchError} when a position snapshot belongs to another user.
|
|
769
773
|
* @throws {RefinanceSameMarketError} when source and destination IDs match.
|
|
770
774
|
* @throws {RefinanceTokenMismatchError} when their loan or collateral tokens differ.
|
|
@@ -842,10 +846,13 @@ export interface BlueActions {
|
|
|
842
846
|
*
|
|
843
847
|
* Reads the target Morpho Blue market, each Vault V2 accrual tree, and each
|
|
844
848
|
* vault's BluePublicAllocator permissions and allocation caps at one block.
|
|
849
|
+
* The snapshot keeps the fetched block's timestamp as its default planning time.
|
|
845
850
|
*
|
|
846
851
|
* @param params.vaultAddresses - Vault V2 addresses to inspect for market or idle liquidity.
|
|
847
852
|
* @param params.block.number - Block number used for every RPC read.
|
|
848
|
-
* @param params.block.timestamp - Timestamp
|
|
853
|
+
* @param params.block.timestamp - Timestamp of the fetched block. Stored on the snapshot and used as the
|
|
854
|
+
* planning timestamp when `options.timestamp` is omitted, never earlier than the latest market/vault
|
|
855
|
+
* `lastUpdate`. An explicit `options.timestamp` is used as given.
|
|
849
856
|
* @returns A `VaultV2BlueReallocationData` snapshot ready for {@link getVaultV2BlueReallocations}.
|
|
850
857
|
* @throws {ChainIdMismatchError} when the client declares another chain or its RPC reports another
|
|
851
858
|
* chain via `eth_chainId`.
|
|
@@ -878,14 +885,23 @@ export interface BlueActions {
|
|
|
878
885
|
* persist across every leg of a plan. Operation plans keep
|
|
879
886
|
* `allocatorCapHeadroom` (1% of the cap by default) free under each target
|
|
880
887
|
* BluePublicAllocator cap unless the operation shortfall needs it.
|
|
888
|
+
* For `refinance`, compute the plan on the destination-market handle (for
|
|
889
|
+
* example, `client.morpho.blue(destination.marketParams, chainId)`), not the
|
|
890
|
+
* source-market handle. Pass the source position's `borrowAssets` accrued to
|
|
891
|
+
* `max(now, source.lastUpdate, destination.lastUpdate) + 2h` as
|
|
892
|
+
* `operation.amount`; the optional `operation.referralFeePct` is WAD-scaled.
|
|
893
|
+
* The planner includes the referral fee and its own planned allocator-leg
|
|
894
|
+
* penalties in destination debt. Refinance never uses vaults with a 100%
|
|
895
|
+
* penalty.
|
|
881
896
|
*
|
|
882
897
|
* @param params.reallocationData - State returned by {@link getVaultV2BlueReallocationData}.
|
|
883
898
|
* @param params.options - Optional allocator discovery controls and operation to support.
|
|
884
899
|
* @returns Action-ready reallocations and their post-simulation state.
|
|
885
900
|
* @throws {ChainIdMismatchError} when `reallocationData` belongs to another chain.
|
|
886
901
|
* @throws {UnsupportedBlueMarketIrmError} when a market with positive debt uses an unsupported IRM.
|
|
887
|
-
* @throws {NegativeInputError} when the cap-accrual buffer, allocator cap headroom, utilization,
|
|
902
|
+
* @throws {NegativeInputError} when the cap-accrual buffer, allocator cap headroom, utilization, penalty limit, or referral-fee percentage is negative.
|
|
888
903
|
* @throws {InputExceedsMaxError} when the allocator cap headroom, a utilization, or a penalty limit exceeds WAD.
|
|
904
|
+
* @throws {ReferralFeePctExceededError} when the referral-fee percentage is at least WAD.
|
|
889
905
|
* @throws {NonPositiveInputError} when an enabled operation amount is not positive.
|
|
890
906
|
* @throws {UnknownReallocationMarketError} when a required market is absent.
|
|
891
907
|
* @throws {UnknownReallocationVaultError} when configured vault state is absent.
|
|
@@ -895,7 +911,7 @@ export interface BlueActions {
|
|
|
895
911
|
* @throws {UnknownReallocationAllocationError} when required allocation state is absent.
|
|
896
912
|
* @throws {ReallocationAdapterSupplySharesUnderflowError} when an inconsistent adapter snapshot underflows during the final transition.
|
|
897
913
|
* @throws {ReallocationAllocationUnderflowError} when an inconsistent allocation snapshot underflows during the final transition.
|
|
898
|
-
* @throws {InsufficientSharedLiquidityError} when selected liquidity cannot cover the shortfall.
|
|
914
|
+
* @throws {InsufficientSharedLiquidityError} when selected liquidity cannot cover the shortfall and, for refinance, its planned allocator penalties.
|
|
899
915
|
* @throws {ReallocationWithdrawExceedsMarketSupplyError} when a withdrawal exceeds market supply.
|
|
900
916
|
* @example
|
|
901
917
|
* ```ts
|
|
@@ -915,6 +931,14 @@ export declare class MorphoBlue implements BlueActions {
|
|
|
915
931
|
private readonly client;
|
|
916
932
|
readonly marketParams: MarketParams;
|
|
917
933
|
private readonly chainId;
|
|
934
|
+
/**
|
|
935
|
+
* Binds `client` to the market described by `marketParams` on `chainId`.
|
|
936
|
+
*
|
|
937
|
+
* @param client - Morpho client used for reads and requirement lookups.
|
|
938
|
+
* @param marketParams - Market params whose `id` must hash from their five tuple fields.
|
|
939
|
+
* @param chainId - Chain the market lives on.
|
|
940
|
+
* @throws {MarketIdMismatchError} when `marketParams.id` does not hash from its tuple fields.
|
|
941
|
+
*/
|
|
918
942
|
constructor(client: MorphoClientType, marketParams: MarketParams, chainId: number);
|
|
919
943
|
private validateDeadline;
|
|
920
944
|
private validateWriteCommon;
|
|
@@ -1059,10 +1083,13 @@ export declare class MorphoBlue implements BlueActions {
|
|
|
1059
1083
|
*
|
|
1060
1084
|
* Reads the target Morpho Blue market, each Vault V2 accrual tree, and each
|
|
1061
1085
|
* vault's BluePublicAllocator permissions and allocation caps at one block.
|
|
1086
|
+
* The snapshot keeps the fetched block's timestamp as its default planning time.
|
|
1062
1087
|
*
|
|
1063
1088
|
* @param params.vaultAddresses - Vault V2 addresses to inspect for market or idle liquidity.
|
|
1064
1089
|
* @param params.block.number - Block number used for every RPC read.
|
|
1065
|
-
* @param params.block.timestamp - Timestamp
|
|
1090
|
+
* @param params.block.timestamp - Timestamp of the fetched block. Stored on the snapshot and used as the
|
|
1091
|
+
* planning timestamp when `options.timestamp` is omitted, never earlier than the latest market/vault
|
|
1092
|
+
* `lastUpdate`. An explicit `options.timestamp` is used as given.
|
|
1066
1093
|
* @returns A `VaultV2BlueReallocationData` snapshot ready for {@link getVaultV2BlueReallocations}.
|
|
1067
1094
|
* @throws {ChainIdMismatchError} when the client declares another chain or its RPC reports another
|
|
1068
1095
|
* chain via `eth_chainId`.
|
|
@@ -1114,14 +1141,23 @@ export declare class MorphoBlue implements BlueActions {
|
|
|
1114
1141
|
* persist across every leg of a plan. Operation plans keep
|
|
1115
1142
|
* `allocatorCapHeadroom` (1% of the cap by default) free under each target
|
|
1116
1143
|
* BluePublicAllocator cap unless the operation shortfall needs it.
|
|
1144
|
+
* For `refinance`, compute the plan on the destination-market handle (for
|
|
1145
|
+
* example, `client.morpho.blue(destination.marketParams, chainId)`), not the
|
|
1146
|
+
* source-market handle. Pass the source position's `borrowAssets` accrued to
|
|
1147
|
+
* `max(now, source.lastUpdate, destination.lastUpdate) + 2h` as
|
|
1148
|
+
* `operation.amount`; the optional `operation.referralFeePct` is WAD-scaled.
|
|
1149
|
+
* The planner includes the referral fee and its own planned allocator-leg
|
|
1150
|
+
* penalties in destination debt. Refinance never uses vaults with a 100%
|
|
1151
|
+
* penalty.
|
|
1117
1152
|
*
|
|
1118
1153
|
* @param params.reallocationData - State returned by {@link getVaultV2BlueReallocationData}.
|
|
1119
1154
|
* @param params.options - Optional allocator discovery controls and operation to support.
|
|
1120
1155
|
* @returns Action-ready reallocations and their post-simulation state.
|
|
1121
1156
|
* @throws {ChainIdMismatchError} when `reallocationData` belongs to another chain.
|
|
1122
1157
|
* @throws {UnsupportedBlueMarketIrmError} when a market with positive debt uses an unsupported IRM.
|
|
1123
|
-
* @throws {NegativeInputError} when the cap-accrual buffer, allocator cap headroom, utilization,
|
|
1158
|
+
* @throws {NegativeInputError} when the cap-accrual buffer, allocator cap headroom, utilization, penalty limit, or referral-fee percentage is negative.
|
|
1124
1159
|
* @throws {InputExceedsMaxError} when the allocator cap headroom, a utilization, or a penalty limit exceeds WAD.
|
|
1160
|
+
* @throws {ReferralFeePctExceededError} when the referral-fee percentage is at least WAD.
|
|
1125
1161
|
* @throws {NonPositiveInputError} when an enabled operation amount is not positive.
|
|
1126
1162
|
* @throws {UnknownReallocationMarketError} when a required market is absent.
|
|
1127
1163
|
* @throws {UnknownReallocationVaultError} when configured vault state is absent.
|
|
@@ -1131,7 +1167,7 @@ export declare class MorphoBlue implements BlueActions {
|
|
|
1131
1167
|
* @throws {UnknownReallocationAllocationError} when required allocation state is absent.
|
|
1132
1168
|
* @throws {ReallocationAdapterSupplySharesUnderflowError} when an inconsistent adapter snapshot underflows during the final transition.
|
|
1133
1169
|
* @throws {ReallocationAllocationUnderflowError} when an inconsistent allocation snapshot underflows during the final transition.
|
|
1134
|
-
* @throws {InsufficientSharedLiquidityError} when selected liquidity cannot cover the shortfall.
|
|
1170
|
+
* @throws {InsufficientSharedLiquidityError} when selected liquidity cannot cover the shortfall and, for refinance, its planned allocator penalties.
|
|
1135
1171
|
* @throws {ReallocationWithdrawExceedsMarketSupplyError} when a withdrawal exceeds market supply.
|
|
1136
1172
|
* @example
|
|
1137
1173
|
* ```ts
|
|
@@ -9,6 +9,7 @@ const common_js_1 = require("../../actions/blue/common.js");
|
|
|
9
9
|
const index_js_1 = require("../../actions/index.js");
|
|
10
10
|
const validateClientChainId_js_1 = require("../../actions/requirements/validateClientChainId.js");
|
|
11
11
|
const index_js_2 = require("../../helpers/index.js");
|
|
12
|
+
const validate_js_1 = require("../../helpers/validate.js");
|
|
12
13
|
const index_js_3 = require("../../types/index.js");
|
|
13
14
|
const assertContractCode_js_1 = require("../requirements/assertContractCode.js");
|
|
14
15
|
const index_js_4 = require("../requirements/index.js");
|
|
@@ -18,11 +19,20 @@ class MorphoBlue {
|
|
|
18
19
|
client;
|
|
19
20
|
marketParams;
|
|
20
21
|
chainId;
|
|
22
|
+
/**
|
|
23
|
+
* Binds `client` to the market described by `marketParams` on `chainId`.
|
|
24
|
+
*
|
|
25
|
+
* @param client - Morpho client used for reads and requirement lookups.
|
|
26
|
+
* @param marketParams - Market params whose `id` must hash from their five tuple fields.
|
|
27
|
+
* @param chainId - Chain the market lives on.
|
|
28
|
+
* @throws {MarketIdMismatchError} when `marketParams.id` does not hash from its tuple fields.
|
|
29
|
+
*/
|
|
21
30
|
// biome-ignore lint/complexity/useMaxParams: TODO refactor to ≤2 params
|
|
22
31
|
constructor(client, marketParams, chainId) {
|
|
23
32
|
this.client = client;
|
|
24
33
|
this.marketParams = marketParams;
|
|
25
34
|
this.chainId = chainId;
|
|
35
|
+
(0, validate_js_1.validateMarketParamsId)(marketParams);
|
|
26
36
|
}
|
|
27
37
|
validateDeadline(deadline, now = morpho_ts_1.Time.timestamp()) {
|
|
28
38
|
if (deadline <= now) {
|
|
@@ -640,6 +650,7 @@ class MorphoBlue {
|
|
|
640
650
|
refinance(params) {
|
|
641
651
|
const { userAddress, positionData, destination, deadline, referralFeeRecipient, } = params;
|
|
642
652
|
this.validateWriteCommon(params);
|
|
653
|
+
(0, validate_js_1.validateMarketParamsId)(destination.marketParams);
|
|
643
654
|
// `validateWriteCommon` returns void, so default an omitted `referralFeePct` to `0n`
|
|
644
655
|
// here, matching the pure action's normalization.
|
|
645
656
|
const referralFeePct = params.referralFeePct ?? 0n;
|
|
@@ -723,10 +734,13 @@ class MorphoBlue {
|
|
|
723
734
|
*
|
|
724
735
|
* Reads the target Morpho Blue market, each Vault V2 accrual tree, and each
|
|
725
736
|
* vault's BluePublicAllocator permissions and allocation caps at one block.
|
|
737
|
+
* The snapshot keeps the fetched block's timestamp as its default planning time.
|
|
726
738
|
*
|
|
727
739
|
* @param params.vaultAddresses - Vault V2 addresses to inspect for market or idle liquidity.
|
|
728
740
|
* @param params.block.number - Block number used for every RPC read.
|
|
729
|
-
* @param params.block.timestamp - Timestamp
|
|
741
|
+
* @param params.block.timestamp - Timestamp of the fetched block. Stored on the snapshot and used as the
|
|
742
|
+
* planning timestamp when `options.timestamp` is omitted, never earlier than the latest market/vault
|
|
743
|
+
* `lastUpdate`. An explicit `options.timestamp` is used as given.
|
|
730
744
|
* @returns A `VaultV2BlueReallocationData` snapshot ready for {@link getVaultV2BlueReallocations}.
|
|
731
745
|
* @throws {ChainIdMismatchError} when the client declares another chain or its RPC reports another
|
|
732
746
|
* chain via `eth_chainId`.
|
|
@@ -782,6 +796,7 @@ class MorphoBlue {
|
|
|
782
796
|
]);
|
|
783
797
|
return new vaultV2BlueReallocationData_js_1.VaultV2BlueReallocationData({
|
|
784
798
|
chainId: this.chainId,
|
|
799
|
+
timestamp: block.timestamp,
|
|
785
800
|
markets: { [targetMarket.id]: targetMarket },
|
|
786
801
|
vaults: Object.fromEntries(vaultEntries.map(({ vault }) => [vault.address, vault])),
|
|
787
802
|
allocations: Object.fromEntries(vaultEntries.map(({ publicAllocatorData, vault }) => [
|
|
@@ -812,14 +827,23 @@ class MorphoBlue {
|
|
|
812
827
|
* persist across every leg of a plan. Operation plans keep
|
|
813
828
|
* `allocatorCapHeadroom` (1% of the cap by default) free under each target
|
|
814
829
|
* BluePublicAllocator cap unless the operation shortfall needs it.
|
|
830
|
+
* For `refinance`, compute the plan on the destination-market handle (for
|
|
831
|
+
* example, `client.morpho.blue(destination.marketParams, chainId)`), not the
|
|
832
|
+
* source-market handle. Pass the source position's `borrowAssets` accrued to
|
|
833
|
+
* `max(now, source.lastUpdate, destination.lastUpdate) + 2h` as
|
|
834
|
+
* `operation.amount`; the optional `operation.referralFeePct` is WAD-scaled.
|
|
835
|
+
* The planner includes the referral fee and its own planned allocator-leg
|
|
836
|
+
* penalties in destination debt. Refinance never uses vaults with a 100%
|
|
837
|
+
* penalty.
|
|
815
838
|
*
|
|
816
839
|
* @param params.reallocationData - State returned by {@link getVaultV2BlueReallocationData}.
|
|
817
840
|
* @param params.options - Optional allocator discovery controls and operation to support.
|
|
818
841
|
* @returns Action-ready reallocations and their post-simulation state.
|
|
819
842
|
* @throws {ChainIdMismatchError} when `reallocationData` belongs to another chain.
|
|
820
843
|
* @throws {UnsupportedBlueMarketIrmError} when a market with positive debt uses an unsupported IRM.
|
|
821
|
-
* @throws {NegativeInputError} when the cap-accrual buffer, allocator cap headroom, utilization,
|
|
844
|
+
* @throws {NegativeInputError} when the cap-accrual buffer, allocator cap headroom, utilization, penalty limit, or referral-fee percentage is negative.
|
|
822
845
|
* @throws {InputExceedsMaxError} when the allocator cap headroom, a utilization, or a penalty limit exceeds WAD.
|
|
846
|
+
* @throws {ReferralFeePctExceededError} when the referral-fee percentage is at least WAD.
|
|
823
847
|
* @throws {NonPositiveInputError} when an enabled operation amount is not positive.
|
|
824
848
|
* @throws {UnknownReallocationMarketError} when a required market is absent.
|
|
825
849
|
* @throws {UnknownReallocationVaultError} when configured vault state is absent.
|
|
@@ -829,7 +853,7 @@ class MorphoBlue {
|
|
|
829
853
|
* @throws {UnknownReallocationAllocationError} when required allocation state is absent.
|
|
830
854
|
* @throws {ReallocationAdapterSupplySharesUnderflowError} when an inconsistent adapter snapshot underflows during the final transition.
|
|
831
855
|
* @throws {ReallocationAllocationUnderflowError} when an inconsistent allocation snapshot underflows during the final transition.
|
|
832
|
-
* @throws {InsufficientSharedLiquidityError} when selected liquidity cannot cover the shortfall.
|
|
856
|
+
* @throws {InsufficientSharedLiquidityError} when selected liquidity cannot cover the shortfall and, for refinance, its planned allocator penalties.
|
|
833
857
|
* @throws {ReallocationWithdrawExceedsMarketSupplyError} when a withdrawal exceeds market supply.
|
|
834
858
|
* @example
|
|
835
859
|
* ```ts
|