@morpho-org/morpho-sdk 5.8.0 → 6.0.0-next.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/MIGRATION-v5-to-v6.md +201 -0
- package/README.md +62 -40
- package/lib/cjs/abis.d.ts +543 -0
- package/lib/cjs/abis.js +738 -0
- package/lib/cjs/actions/blue/borrow.d.ts +62 -58
- package/lib/cjs/actions/blue/borrow.js +48 -80
- package/lib/cjs/actions/blue/common.d.ts +99 -0
- package/lib/cjs/actions/blue/common.js +318 -0
- package/lib/cjs/actions/blue/refinance.d.ts +72 -107
- package/lib/cjs/actions/blue/refinance.js +97 -197
- package/lib/cjs/actions/blue/repay.d.ts +72 -68
- package/lib/cjs/actions/blue/repay.js +56 -118
- package/lib/cjs/actions/blue/repayWithdrawCollateral.d.ts +85 -90
- package/lib/cjs/actions/blue/repayWithdrawCollateral.js +148 -137
- package/lib/cjs/actions/blue/supply.d.ts +62 -45
- package/lib/cjs/actions/blue/supply.js +94 -70
- package/lib/cjs/actions/blue/supplyCollateral.d.ts +63 -40
- package/lib/cjs/actions/blue/supplyCollateral.js +52 -69
- package/lib/cjs/actions/blue/supplyCollateralBorrow.d.ts +82 -86
- package/lib/cjs/actions/blue/supplyCollateralBorrow.js +133 -119
- package/lib/cjs/actions/blue/withdraw.d.ts +68 -78
- package/lib/cjs/actions/blue/withdraw.js +101 -97
- package/lib/cjs/actions/blue/withdrawCollateral.d.ts +56 -28
- package/lib/cjs/actions/blue/withdrawCollateral.js +45 -50
- package/lib/cjs/actions/index.d.ts +1 -1
- package/lib/cjs/actions/requirements/blue/getBlueAuthorizationRequirement.d.ts +29 -17
- package/lib/cjs/actions/requirements/blue/getBlueAuthorizationRequirement.js +60 -19
- package/lib/cjs/actions/requirements/blue/getBlueBundlesV1TokenRequirements.d.ts +80 -0
- package/lib/cjs/actions/requirements/blue/getBlueBundlesV1TokenRequirements.js +207 -0
- package/lib/cjs/actions/requirements/blue/getUnusedPermit2Nonce.d.ts +48 -0
- package/lib/cjs/actions/requirements/blue/getUnusedPermit2Nonce.js +72 -0
- package/lib/cjs/actions/requirements/blue/index.d.ts +2 -0
- package/lib/cjs/actions/requirements/blue/index.js +2 -0
- package/lib/cjs/actions/requirements/encode/encodeBlueSignatureAuthorization.d.ts +10 -7
- package/lib/cjs/actions/requirements/encode/encodeBlueSignatureAuthorization.js +30 -5
- package/lib/cjs/actions/requirements/encode/encodeErc20Approval.d.ts +2 -1
- package/lib/cjs/actions/requirements/encode/encodeErc20Approval.js +7 -2
- package/lib/cjs/actions/requirements/encode/encodeErc20Permit.d.ts +16 -7
- package/lib/cjs/actions/requirements/encode/encodeErc20Permit.js +33 -6
- package/lib/cjs/actions/requirements/encode/encodeErc20Permit2TransferFrom.d.ts +61 -0
- package/lib/cjs/actions/requirements/encode/encodeErc20Permit2TransferFrom.js +123 -0
- package/lib/cjs/actions/requirements/encode/index.d.ts +1 -0
- package/lib/cjs/actions/requirements/encode/index.js +1 -0
- package/lib/cjs/actions/requirements/generalAdapter/getGeneralAdapterRequirementsPermit.d.ts +1 -1
- package/lib/cjs/actions/requirements/getRequirementsApproval.d.ts +5 -4
- package/lib/cjs/actions/requirements/getRequirementsApproval.js +5 -4
- package/lib/cjs/actions/signatures/getTokenRequirementActions.d.ts +1 -0
- package/lib/cjs/actions/signatures/getTokenRequirementActions.js +4 -0
- package/lib/cjs/blue/types.d.ts +3 -1
- package/lib/cjs/blue/utils.d.ts +3 -1
- package/lib/cjs/blue/utils.js +1 -0
- package/lib/cjs/bundler/actions.d.ts +6 -4
- package/lib/cjs/bundler/actions.js +6 -4
- package/lib/cjs/bundler/types.d.ts +10 -1
- package/lib/cjs/client/morphoViemExtension.d.ts +2 -1
- package/lib/cjs/client/morphoViemExtension.js +2 -1
- package/lib/cjs/entities/blue/blue.d.ts +817 -360
- package/lib/cjs/entities/blue/blue.js +455 -698
- package/lib/cjs/entities/index.d.ts +1 -0
- package/lib/cjs/entities/vaultV1/vaultV1.js +4 -12
- package/lib/cjs/entities/vaultV1ReallocationData.d.ts +18 -3
- package/lib/cjs/entities/vaultV1ReallocationData.js +11 -1
- package/lib/cjs/entities/vaultV2/vaultV2.js +6 -18
- package/lib/cjs/helpers/computeVaultV1Reallocations.d.ts +7 -10
- package/lib/cjs/helpers/computeVaultV1Reallocations.js +7 -10
- package/lib/cjs/helpers/validate.d.ts +16 -23
- package/lib/cjs/helpers/validate.js +32 -48
- package/lib/cjs/helpers/validateRequirementSpender.d.ts +2 -1
- package/lib/cjs/helpers/validateRequirementSpender.js +2 -0
- package/lib/cjs/types/action.d.ts +146 -162
- package/lib/cjs/types/action.js +29 -2
- package/lib/cjs/types/client.d.ts +9 -0
- package/lib/cjs/types/error.d.ts +173 -18
- package/lib/cjs/types/error.js +230 -25
- package/lib/cjs/types/sharedLiquidity.d.ts +20 -4
- package/lib/cjs/types.d.ts +3 -1
- package/lib/cjs/utils.d.ts +3 -1
- package/lib/cjs/utils.js +1 -0
- package/lib/esm/abis.d.ts +543 -0
- package/lib/esm/abis.js +737 -0
- package/lib/esm/actions/blue/borrow.d.ts +62 -58
- package/lib/esm/actions/blue/borrow.js +48 -80
- package/lib/esm/actions/blue/common.d.ts +99 -0
- package/lib/esm/actions/blue/common.js +306 -0
- package/lib/esm/actions/blue/refinance.d.ts +72 -107
- package/lib/esm/actions/blue/refinance.js +98 -198
- package/lib/esm/actions/blue/repay.d.ts +72 -68
- package/lib/esm/actions/blue/repay.js +56 -118
- package/lib/esm/actions/blue/repayWithdrawCollateral.d.ts +85 -90
- package/lib/esm/actions/blue/repayWithdrawCollateral.js +149 -138
- package/lib/esm/actions/blue/supply.d.ts +62 -45
- package/lib/esm/actions/blue/supply.js +94 -70
- package/lib/esm/actions/blue/supplyCollateral.d.ts +63 -40
- package/lib/esm/actions/blue/supplyCollateral.js +52 -69
- package/lib/esm/actions/blue/supplyCollateralBorrow.d.ts +82 -86
- package/lib/esm/actions/blue/supplyCollateralBorrow.js +134 -120
- package/lib/esm/actions/blue/withdraw.d.ts +68 -78
- package/lib/esm/actions/blue/withdraw.js +100 -96
- package/lib/esm/actions/blue/withdrawCollateral.d.ts +56 -28
- package/lib/esm/actions/blue/withdrawCollateral.js +45 -50
- package/lib/esm/actions/index.d.ts +1 -1
- package/lib/esm/actions/requirements/blue/getBlueAuthorizationRequirement.d.ts +29 -17
- package/lib/esm/actions/requirements/blue/getBlueAuthorizationRequirement.js +63 -22
- package/lib/esm/actions/requirements/blue/getBlueBundlesV1TokenRequirements.d.ts +80 -0
- package/lib/esm/actions/requirements/blue/getBlueBundlesV1TokenRequirements.js +203 -0
- package/lib/esm/actions/requirements/blue/getUnusedPermit2Nonce.d.ts +48 -0
- package/lib/esm/actions/requirements/blue/getUnusedPermit2Nonce.js +68 -0
- package/lib/esm/actions/requirements/blue/index.d.ts +2 -0
- package/lib/esm/actions/requirements/blue/index.js +2 -0
- package/lib/esm/actions/requirements/encode/encodeBlueSignatureAuthorization.d.ts +10 -7
- package/lib/esm/actions/requirements/encode/encodeBlueSignatureAuthorization.js +31 -6
- package/lib/esm/actions/requirements/encode/encodeErc20Approval.d.ts +2 -1
- package/lib/esm/actions/requirements/encode/encodeErc20Approval.js +8 -3
- package/lib/esm/actions/requirements/encode/encodeErc20Permit.d.ts +16 -7
- package/lib/esm/actions/requirements/encode/encodeErc20Permit.js +34 -7
- package/lib/esm/actions/requirements/encode/encodeErc20Permit2TransferFrom.d.ts +61 -0
- package/lib/esm/actions/requirements/encode/encodeErc20Permit2TransferFrom.js +119 -0
- package/lib/esm/actions/requirements/encode/index.d.ts +1 -0
- package/lib/esm/actions/requirements/encode/index.js +1 -0
- package/lib/esm/actions/requirements/generalAdapter/getGeneralAdapterRequirementsPermit.d.ts +1 -1
- package/lib/esm/actions/requirements/getRequirementsApproval.d.ts +5 -4
- package/lib/esm/actions/requirements/getRequirementsApproval.js +5 -4
- package/lib/esm/actions/signatures/getTokenRequirementActions.d.ts +1 -0
- package/lib/esm/actions/signatures/getTokenRequirementActions.js +5 -1
- package/lib/esm/blue/types.d.ts +3 -1
- package/lib/esm/blue/utils.d.ts +3 -1
- package/lib/esm/blue/utils.js +3 -1
- package/lib/esm/bundler/actions.d.ts +6 -4
- package/lib/esm/bundler/actions.js +6 -4
- package/lib/esm/bundler/types.d.ts +10 -1
- package/lib/esm/client/morphoViemExtension.d.ts +2 -1
- package/lib/esm/client/morphoViemExtension.js +2 -1
- package/lib/esm/entities/blue/blue.d.ts +817 -360
- package/lib/esm/entities/blue/blue.js +461 -704
- package/lib/esm/entities/index.d.ts +1 -0
- package/lib/esm/entities/vaultV1/vaultV1.js +4 -12
- package/lib/esm/entities/vaultV1ReallocationData.d.ts +18 -3
- package/lib/esm/entities/vaultV1ReallocationData.js +13 -2
- package/lib/esm/entities/vaultV2/vaultV2.js +7 -19
- package/lib/esm/helpers/computeVaultV1Reallocations.d.ts +7 -10
- package/lib/esm/helpers/computeVaultV1Reallocations.js +7 -10
- package/lib/esm/helpers/validate.d.ts +16 -23
- package/lib/esm/helpers/validate.js +32 -48
- package/lib/esm/helpers/validateRequirementSpender.d.ts +2 -1
- package/lib/esm/helpers/validateRequirementSpender.js +2 -0
- package/lib/esm/types/action.d.ts +146 -162
- package/lib/esm/types/action.js +28 -2
- package/lib/esm/types/client.d.ts +9 -0
- package/lib/esm/types/error.d.ts +173 -18
- package/lib/esm/types/error.js +216 -21
- package/lib/esm/types/sharedLiquidity.d.ts +20 -4
- package/lib/esm/types.d.ts +3 -1
- package/lib/esm/utils.d.ts +3 -1
- package/lib/esm/utils.js +3 -1
- package/package.json +7 -6
- package/lib/cjs/actions/blue/buildAssetFundingActions.d.ts +0 -47
- package/lib/cjs/actions/blue/buildAssetFundingActions.js +0 -63
- package/lib/cjs/actions/blue/buildReallocationActions.d.ts +0 -69
- package/lib/cjs/actions/blue/buildReallocationActions.js +0 -141
- package/lib/cjs/actions/blue/resolveRepayFunding.d.ts +0 -66
- package/lib/cjs/actions/blue/resolveRepayFunding.js +0 -85
- package/lib/esm/actions/blue/buildAssetFundingActions.d.ts +0 -47
- package/lib/esm/actions/blue/buildAssetFundingActions.js +0 -59
- package/lib/esm/actions/blue/buildReallocationActions.d.ts +0 -69
- package/lib/esm/actions/blue/buildReallocationActions.js +0 -135
- package/lib/esm/actions/blue/resolveRepayFunding.d.ts +0 -66
- package/lib/esm/actions/blue/resolveRepayFunding.js +0 -81
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { AccrualPosition, type Market, type MarketParams } from "@morpho-org/blue-sdk";
|
|
1
|
+
import { type AccrualPosition, type Market, type MarketParams } from "@morpho-org/blue-sdk";
|
|
2
2
|
import { type Address } from "viem";
|
|
3
3
|
import type { FetchParameters } from "../../types/data.js";
|
|
4
|
-
import { type
|
|
4
|
+
import { type ActionOutput, type ActionRequirement, type AssetsOrSharesArgs, type BlueBorrowAction, type BlueRefinanceAction, type BlueRepayAction, type BlueRepayWithdrawCollateralAction, type BlueSupplyAction, type BlueSupplyCollateralAction, type BlueSupplyCollateralBorrowAction, type BlueWithdrawAction, type BlueWithdrawCollateralAction, type MorphoClientType, type ReallocationComputeOptions, type RequirementSignature, type VaultV1Reallocation, type VaultV2BluePublicAllocatorOptions, type VaultV2BlueReallocation } from "../../types/index.js";
|
|
5
5
|
import { VaultV1ReallocationData } from "../vaultV1ReallocationData.js";
|
|
6
6
|
import { VaultV2BlueReallocationData } from "../vaultV2BlueReallocationData.js";
|
|
7
7
|
type VaultV1ReallocationsParams = {
|
|
@@ -26,6 +26,18 @@ type VaultV2BlueReallocationsParams = {
|
|
|
26
26
|
};
|
|
27
27
|
};
|
|
28
28
|
};
|
|
29
|
+
/** Options for resolving token-backed BlueBundlesV1 approval or signature prerequisites. */
|
|
30
|
+
export interface BlueTokenRequirementsParams {
|
|
31
|
+
/** Prefer ERC-2612 when the funded token exposes a compatible nonce. */
|
|
32
|
+
readonly useSimplePermit?: boolean;
|
|
33
|
+
/** Explicit unused Permit2 SignatureTransfer unordered nonce. */
|
|
34
|
+
readonly permit2Nonce?: bigint;
|
|
35
|
+
/**
|
|
36
|
+
* Classic ERC-20 allowance to set when an approval is needed, enabling a reusable approval (for
|
|
37
|
+
* example `maxUint256`). Defaults to the exact pulled amount. Ignored by signature paths.
|
|
38
|
+
*/
|
|
39
|
+
readonly approvalAmount?: bigint;
|
|
40
|
+
}
|
|
29
41
|
export interface BlueActions {
|
|
30
42
|
/**
|
|
31
43
|
* Fetches the latest market data with accrued interest.
|
|
@@ -43,312 +55,715 @@ export interface BlueActions {
|
|
|
43
55
|
*/
|
|
44
56
|
getPositionData: (userAddress: Address, parameters?: FetchParameters) => Promise<AccrualPosition>;
|
|
45
57
|
/**
|
|
46
|
-
* Prepares a
|
|
58
|
+
* Prepares a direct BlueBundlesV1 collateral supply.
|
|
47
59
|
*
|
|
48
|
-
*
|
|
49
|
-
* `
|
|
50
|
-
*
|
|
60
|
+
* This is the single-operation form of {@link BlueActions.supplyCollateralBorrow}; it supplies
|
|
61
|
+
* `collateralAssets` and fixes the inactive borrow leg to zero. Token requirements target
|
|
62
|
+
* BlueBundlesV1 unless the collateral is funded exclusively with the chain's native asset.
|
|
51
63
|
*
|
|
52
|
-
* @param params -
|
|
53
|
-
* @
|
|
64
|
+
* @param params.userAddress - User funding and receiving the collateral position.
|
|
65
|
+
* @param params.collateralAssets - Gross collateral assets supplied.
|
|
66
|
+
* @param params.nativeAmount - Optional full native funding equal to `collateralAssets`.
|
|
67
|
+
* @param params.deadline - Final call deadline in Unix seconds.
|
|
68
|
+
* @param params.referralFeePct - Optional WAD-scaled referral fee below 100%.
|
|
69
|
+
* @param params.referralFeeRecipient - Recipient required for a positive fee.
|
|
70
|
+
* @returns Lazy token prerequisite resolution and a synchronous deep-frozen transaction.
|
|
71
|
+
* @throws {ChainIdMismatchError} when the client targets another chain.
|
|
72
|
+
* @throws {ExpiredDeadlineError} when the deadline is stale.
|
|
73
|
+
* @throws {NonPositiveInputError} when `collateralAssets` is not positive.
|
|
74
|
+
* @throws {NegativeInputError} when collateral, native funding, or the referral fee is negative.
|
|
75
|
+
* @throws {NativeFundingAmountMismatchError} when native funding is partial or mixed.
|
|
76
|
+
* @throws {ChainWNativeMissingError} when native funding is requested without registered wNative.
|
|
77
|
+
* @throws {NativeAmountOnNonWNativeAssetError} when native funding targets another token.
|
|
78
|
+
* @throws {InputExceedsMaxError} when the referral fee is at least WAD.
|
|
79
|
+
* @throws {MissingReferralFeeRecipientError} when a positive fee has no recipient.
|
|
80
|
+
* @throws {MissingPermit2TransferFromNonceError} from `getRequirements()` when Permit2 is selected without a nonce.
|
|
81
|
+
* @throws {Permit2TransferFromNonceAlreadyUsedError} from `getRequirements()` when the explicit Permit2 nonce is consumed.
|
|
82
|
+
* @throws {AmbiguousRequirementSignaturesError} from `buildTx()` when multiple token signatures are supplied.
|
|
83
|
+
* @throws {UnexpectedRequirementSignatureError} from `buildTx()` when an unsupported signature is supplied.
|
|
84
|
+
* @throws {DepositOwnerMismatchError} from `buildTx()` when the signed owner differs from `userAddress`.
|
|
85
|
+
* @throws {DepositAssetMismatchError} from `buildTx()` when the signed asset differs from the collateral token.
|
|
86
|
+
* @throws {DepositAmountMismatchError} from `buildTx()` when the signed amount differs from `collateralAssets`.
|
|
87
|
+
* @throws {DepositSpenderMismatchError} from `buildTx()` when the signed spender is not BlueBundlesV1.
|
|
88
|
+
* @throws {BlueBundlesV1RequirementSignatureMismatchError} from `buildTx()` when a signature cannot be encoded safely.
|
|
89
|
+
* @throws {UnsupportedChainIdError} when the chain is absent from the address registry.
|
|
90
|
+
* @throws {UnknownAddressError} when BlueBundlesV1 is not registered.
|
|
91
|
+
* @throws {viem.BaseError} from `getRequirements()` when an allowance, nonce, or token metadata read fails.
|
|
92
|
+
* @example
|
|
93
|
+
* ```ts
|
|
94
|
+
* import { markets } from "@morpho-org/morpho-test";
|
|
95
|
+
* import { createPublicClient, http, zeroAddress } from "viem";
|
|
96
|
+
* import { mainnet } from "viem/chains";
|
|
97
|
+
* import { morphoViemExtension } from "@morpho-org/morpho-sdk";
|
|
98
|
+
*
|
|
99
|
+
* const client = createPublicClient({ chain: mainnet, transport: http() })
|
|
100
|
+
* .extend(morphoViemExtension());
|
|
101
|
+
* const market = client.morpho.blue(markets[mainnet.id].usdc_wbtc, mainnet.id);
|
|
102
|
+
* const action = market.supplyCollateral({
|
|
103
|
+
* userAddress: zeroAddress,
|
|
104
|
+
* collateralAssets: 10n ** 18n,
|
|
105
|
+
* deadline: 1_900_000_000n,
|
|
106
|
+
* });
|
|
107
|
+
* const requirements = await action.getRequirements();
|
|
108
|
+
* const tx = action.buildTx();
|
|
109
|
+
* ```
|
|
54
110
|
*/
|
|
55
111
|
supplyCollateral: (params: {
|
|
56
|
-
userAddress: Address;
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
* a token is known to be incompatible despite passing the SDK's shallow nonce probe.
|
|
64
|
-
*/
|
|
65
|
-
useSimplePermit?: boolean;
|
|
66
|
-
}) => Promise<(Readonly<Transaction<ERC20ApprovalAction>> | Requirement<PermitRequirementSignature>)[]>;
|
|
67
|
-
};
|
|
112
|
+
readonly userAddress: Address;
|
|
113
|
+
readonly collateralAssets: bigint;
|
|
114
|
+
readonly nativeAmount?: bigint;
|
|
115
|
+
readonly deadline: bigint;
|
|
116
|
+
readonly referralFeePct?: bigint;
|
|
117
|
+
readonly referralFeeRecipient?: Address;
|
|
118
|
+
}) => ActionOutput<BlueSupplyCollateralAction, readonly RequirementSignature[], BlueTokenRequirementsParams>;
|
|
68
119
|
/**
|
|
69
|
-
* Prepares a loan-asset supply
|
|
120
|
+
* Prepares a direct BlueBundlesV1 loan-asset supply.
|
|
70
121
|
*
|
|
71
|
-
*
|
|
72
|
-
*
|
|
73
|
-
*
|
|
74
|
-
*
|
|
75
|
-
*
|
|
122
|
+
* `getRequirements()` reads only the loan-token allowance and selected ERC-2612 or Permit2
|
|
123
|
+
* nonce state. Direct approvals and ERC-2612 name BlueBundlesV1 as spender; Permit2 keeps its
|
|
124
|
+
* ERC-20 approval on canonical Permit2. Native funding is exclusive and skips token requirements.
|
|
125
|
+
* The referral fee is deducted from the gross `assets` supplied. This route exposes no Bundler3
|
|
126
|
+
* share-price bound or `slippageTolerance`.
|
|
76
127
|
*
|
|
77
|
-
*
|
|
128
|
+
* @param params.userAddress - User funding and receiving the supply position.
|
|
129
|
+
* @param params.assets - Gross loan-token assets funded before the referral fee.
|
|
130
|
+
* @param params.nativeAmount - Optional full native funding; must equal `assets` and requires wNative.
|
|
131
|
+
* @param params.deadline - Final call deadline in Unix seconds.
|
|
132
|
+
* @param params.referralFeePct - Optional WAD-scaled referral fee below 100%.
|
|
133
|
+
* @param params.referralFeeRecipient - Recipient required for a positive fee.
|
|
134
|
+
* @returns Lazy prerequisite resolution and a synchronous deep-frozen transaction builder.
|
|
135
|
+
* @throws {ChainIdMismatchError} when the client targets another chain.
|
|
136
|
+
* @throws {ExpiredDeadlineError} when the deadline is not in the future at creation or requirement resolution.
|
|
137
|
+
* @throws {NonPositiveInputError} when `assets` is not positive.
|
|
138
|
+
* @throws {NegativeInputError} when native funding or the referral fee is negative, or from `getRequirements()` when an explicit `permit2Nonce` is negative.
|
|
139
|
+
* @throws {NativeFundingAmountMismatchError} when native funding is partial or mixed.
|
|
140
|
+
* @throws {ChainWNativeMissingError} when native funding is requested on a chain without wNative.
|
|
141
|
+
* @throws {NativeAmountOnNonWNativeAssetError} when native funding targets another token.
|
|
142
|
+
* @throws {InputExceedsMaxError} when `assets` or `deadline` exceeds `uint256`, when the referral fee is at least WAD, or from `getRequirements()` when an explicit `permit2Nonce` exceeds `uint256`.
|
|
143
|
+
* @throws {MissingReferralFeeRecipientError} when a positive fee has no recipient.
|
|
144
|
+
* @throws {MissingPermit2TransferFromNonceError} from `getRequirements()` when Permit2 is selected without an explicit nonce.
|
|
145
|
+
* @throws {Permit2TransferFromNonceAlreadyUsedError} from `getRequirements()` when the explicit Permit2 nonce is consumed.
|
|
146
|
+
* @throws {ApprovalAmountLessThanSpendAmountError} from `getRequirements()` when a classic `approvalAmount` is below the funded `assets`.
|
|
147
|
+
* @throws {AmbiguousRequirementSignaturesError} from `buildTx()` when multiple token signatures are supplied.
|
|
148
|
+
* @throws {UnexpectedRequirementSignatureError} from `buildTx()` when the route cannot consume a supplied signature.
|
|
149
|
+
* @throws {DepositOwnerMismatchError} from `buildTx()` when the signed owner differs from `userAddress`.
|
|
150
|
+
* @throws {DepositAssetMismatchError} from `buildTx()` when the signed asset differs from the loan token.
|
|
151
|
+
* @throws {DepositAmountMismatchError} from `buildTx()` when the signed amount differs from `assets`.
|
|
152
|
+
* @throws {DepositSpenderMismatchError} from `buildTx()` when the signed spender is not BlueBundlesV1.
|
|
153
|
+
* @throws {BlueBundlesV1RequirementSignatureMismatchError} from `buildTx()` when a signature cannot be encoded safely.
|
|
154
|
+
* @throws {UnsupportedChainIdError} when the chain is absent from the address registry.
|
|
155
|
+
* @throws {UnknownAddressError} when BlueBundlesV1 is not registered.
|
|
156
|
+
* @throws {viem.BaseError} from `getRequirements()` when a required allowance, nonce, or token metadata read fails.
|
|
157
|
+
* @example
|
|
158
|
+
* ```ts
|
|
159
|
+
* import { markets } from "@morpho-org/morpho-test";
|
|
160
|
+
* import { createPublicClient, http, zeroAddress } from "viem";
|
|
161
|
+
* import { mainnet } from "viem/chains";
|
|
162
|
+
* import { morphoViemExtension } from "@morpho-org/morpho-sdk";
|
|
78
163
|
*
|
|
79
|
-
*
|
|
80
|
-
*
|
|
164
|
+
* const userAddress = zeroAddress;
|
|
165
|
+
* const client = createPublicClient({ chain: mainnet, transport: http() })
|
|
166
|
+
* .extend(morphoViemExtension());
|
|
167
|
+
* const market = client.morpho.blue(markets[mainnet.id].usdc_wbtc, mainnet.id);
|
|
168
|
+
* const action = market.supply({
|
|
169
|
+
* userAddress,
|
|
170
|
+
* assets: 1_000_000n,
|
|
171
|
+
* deadline: BigInt(Math.floor(Date.now() / 1_000) + 3_600),
|
|
172
|
+
* });
|
|
173
|
+
* const requirements = await action.getRequirements();
|
|
174
|
+
* const tx = action.buildTx();
|
|
175
|
+
* // tx satisfies Readonly<Transaction<BlueSupplyAction>>
|
|
176
|
+
* ```
|
|
81
177
|
*/
|
|
82
178
|
supply: (params: {
|
|
83
|
-
userAddress: Address;
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
* Prefer the ERC-2612 simple-permit path when the SDK detects support.
|
|
91
|
-
* Leave unset or set to `false` to force the Permit2/classic approval fallback when
|
|
92
|
-
* a token is known to be incompatible despite passing the SDK's shallow nonce probe.
|
|
93
|
-
*/
|
|
94
|
-
useSimplePermit?: boolean;
|
|
95
|
-
}) => Promise<(Readonly<Transaction<ERC20ApprovalAction>> | Requirement<PermitRequirementSignature>)[]>;
|
|
96
|
-
};
|
|
179
|
+
readonly userAddress: Address;
|
|
180
|
+
readonly assets: bigint;
|
|
181
|
+
readonly nativeAmount?: bigint;
|
|
182
|
+
readonly deadline: bigint;
|
|
183
|
+
readonly referralFeePct?: bigint;
|
|
184
|
+
readonly referralFeeRecipient?: Address;
|
|
185
|
+
}) => ActionOutput<BlueSupplyAction, readonly RequirementSignature[], BlueTokenRequirementsParams>;
|
|
97
186
|
/**
|
|
98
|
-
* Prepares a loan-asset
|
|
99
|
-
*
|
|
100
|
-
* Routed through bundler3 via `morphoWithdraw`. Supports two modes via {@link AssetsOrSharesArgs}:
|
|
101
|
-
* - **By assets** (`{ assets }`): withdraws an exact asset amount.
|
|
102
|
-
* - **By shares** (`{ shares }`): burns an exact share count (full close, immune to interest accrual).
|
|
103
|
-
*
|
|
104
|
-
* Computes `minSharePrice` from market supply state and `slippageTolerance`.
|
|
187
|
+
* Prepares a direct BlueBundlesV1 loan-asset withdrawal by assets or shares.
|
|
105
188
|
*
|
|
106
|
-
*
|
|
107
|
-
*
|
|
108
|
-
*
|
|
189
|
+
* `getRequirements()` reads Morpho authorization state for BlueBundlesV1. Optional reallocations
|
|
190
|
+
* are Vault V2-only; their penalties and the referral fee reduce withdrawal proceeds. Shares
|
|
191
|
+
* mode has neither a saturated full-close sentinel nor an onchain minimum-assets guarantee.
|
|
192
|
+
* This route exposes no Bundler3 share-price bound or `slippageTolerance`.
|
|
109
193
|
*
|
|
110
|
-
*
|
|
111
|
-
*
|
|
112
|
-
*
|
|
113
|
-
*
|
|
114
|
-
*
|
|
194
|
+
* @param params.userAddress - User whose supply position is withdrawn.
|
|
195
|
+
* @param params.positionData - Pre-fetched position used for ownership and balance validation.
|
|
196
|
+
* @param params.assets - Exact assets withdrawn, exclusive with `shares`.
|
|
197
|
+
* @param params.shares - Exact shares burned, exclusive with `assets`.
|
|
198
|
+
* @param params.reallocations - Optional Vault V2 reallocations executed before withdrawal.
|
|
199
|
+
* @param params.deadline - Final call deadline in Unix seconds.
|
|
200
|
+
* @param params.referralFeePct - Optional WAD-scaled referral fee below 100%.
|
|
201
|
+
* @param params.referralFeeRecipient - Recipient required for a positive fee.
|
|
202
|
+
* @returns Lazy authorization resolution and a synchronous deep-frozen transaction builder.
|
|
203
|
+
* @throws {ChainIdMismatchError} when the client targets another chain.
|
|
204
|
+
* @throws {ExpiredDeadlineError} when the deadline is stale.
|
|
205
|
+
* @throws {MissingAccrualPositionError} when no position snapshot is provided at runtime.
|
|
206
|
+
* @throws {MarketIdMismatchError} when `positionData` belongs to another market.
|
|
207
|
+
* @throws {AccrualPositionUserMismatchError} when `positionData` belongs to another user.
|
|
208
|
+
* @throws {NegativeInputError} when an amount, referral fee, or reallocation penalty is negative.
|
|
209
|
+
* @throws {NonPositiveInputError} when no withdrawal mode or positive reallocation amount is provided.
|
|
210
|
+
* @throws {MutuallyExclusiveWithdrawAmountsError} when assets and shares are both nonzero.
|
|
211
|
+
* @throws {WithdrawExceedsSupplyError} when assets exceed the supplied balance.
|
|
212
|
+
* @throws {WithdrawSharesExceedSupplyError} when shares exceed the owned balance.
|
|
213
|
+
* @throws {InputExceedsMaxError} when a fee or reallocation exceeds its ABI bound.
|
|
214
|
+
* @throws {MissingReferralFeeRecipientError} when a positive fee has no recipient.
|
|
215
|
+
* @throws {InvalidReallocationAddressError} when a vault or adapter address is malformed.
|
|
216
|
+
* @throws {InvalidReallocationShapeError} when a reallocation entry is not a valid Vault V2 reallocation.
|
|
217
|
+
* @throws {InvalidReallocationSourceTypeError} when a reallocation source is malformed.
|
|
218
|
+
* @throws {InconsistentReallocationPenaltyError} when one vault uses different penalties.
|
|
219
|
+
* @throws {ReallocationWithdrawalOnTargetMarketError} when a source is the target market.
|
|
220
|
+
* @throws {ReallocationLoanTokenMismatchError} when a source uses another loan token.
|
|
221
|
+
* @throws {AmbiguousRequirementSignaturesError} from `buildTx()` when multiple authorization signatures are supplied.
|
|
222
|
+
* @throws {UnexpectedRequirementSignatureError} from `buildTx()` when a non-authorization signature is supplied.
|
|
223
|
+
* @throws {DepositOwnerMismatchError} from `buildTx()` when the signed owner differs from `userAddress`.
|
|
224
|
+
* @throws {BlueBundlesV1RequirementSignatureMismatchError} from `buildTx()` when authorization cannot be encoded safely.
|
|
225
|
+
* @throws {UnsupportedChainIdError} when the chain is absent from the address registry.
|
|
226
|
+
* @throws {UnknownAddressError} when BlueBundlesV1 is not registered.
|
|
227
|
+
* @throws {viem.BaseError} from `getRequirements()` when authorization reads fail.
|
|
228
|
+
* @example
|
|
229
|
+
* ```ts
|
|
230
|
+
* import { AccrualPosition } from "@morpho-org/blue-sdk";
|
|
231
|
+
* import { markets } from "@morpho-org/morpho-test";
|
|
232
|
+
* import { createPublicClient, http, zeroAddress } from "viem";
|
|
233
|
+
* import { mainnet } from "viem/chains";
|
|
234
|
+
* import { morphoViemExtension } from "@morpho-org/morpho-sdk";
|
|
115
235
|
*
|
|
116
|
-
*
|
|
117
|
-
*
|
|
118
|
-
*
|
|
119
|
-
*
|
|
120
|
-
*
|
|
121
|
-
*
|
|
122
|
-
*
|
|
123
|
-
*
|
|
124
|
-
*
|
|
236
|
+
* const userAddress = zeroAddress;
|
|
237
|
+
* const client = createPublicClient({ chain: mainnet, transport: http() })
|
|
238
|
+
* .extend(morphoViemExtension());
|
|
239
|
+
* const market = client.morpho.blue(markets[mainnet.id].usdc_wbtc, mainnet.id);
|
|
240
|
+
* const positionData = new AccrualPosition(
|
|
241
|
+
* { user: userAddress, supplyShares: 1n, borrowShares: 0n, collateral: 0n },
|
|
242
|
+
* await market.getMarketData(),
|
|
243
|
+
* );
|
|
244
|
+
* const action = market.withdraw({
|
|
245
|
+
* userAddress,
|
|
246
|
+
* positionData,
|
|
247
|
+
* shares: 1n,
|
|
248
|
+
* deadline: BigInt(Math.floor(Date.now() / 1_000) + 3_600),
|
|
249
|
+
* });
|
|
250
|
+
* const requirements = await action.getRequirements();
|
|
251
|
+
* const tx = action.buildTx();
|
|
252
|
+
* // tx satisfies Readonly<Transaction<BlueWithdrawAction>>
|
|
253
|
+
* ```
|
|
125
254
|
*/
|
|
126
255
|
withdraw: (params: {
|
|
127
|
-
userAddress: Address;
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
getRequirements: () => Promise<(Readonly<Transaction<ERC20ApprovalAction>> | Readonly<Transaction<BlueAuthorizationAction>> | Requirement)[]>;
|
|
135
|
-
};
|
|
256
|
+
readonly userAddress: Address;
|
|
257
|
+
readonly positionData: AccrualPosition;
|
|
258
|
+
readonly reallocations?: Iterable<VaultV2BlueReallocation>;
|
|
259
|
+
readonly deadline: bigint;
|
|
260
|
+
readonly referralFeePct?: bigint;
|
|
261
|
+
readonly referralFeeRecipient?: Address;
|
|
262
|
+
} & AssetsOrSharesArgs) => ActionOutput<BlueWithdrawAction, readonly RequirementSignature[], undefined>;
|
|
136
263
|
/**
|
|
137
|
-
* Prepares a borrow
|
|
138
|
-
*
|
|
139
|
-
*
|
|
140
|
-
*
|
|
141
|
-
*
|
|
142
|
-
*
|
|
143
|
-
*
|
|
144
|
-
*
|
|
145
|
-
*
|
|
146
|
-
*
|
|
147
|
-
*
|
|
148
|
-
*
|
|
149
|
-
*
|
|
150
|
-
*
|
|
151
|
-
*
|
|
152
|
-
* @
|
|
153
|
-
* @
|
|
154
|
-
* @throws {
|
|
155
|
-
* @throws {
|
|
156
|
-
* @throws {
|
|
157
|
-
* @throws {
|
|
158
|
-
* @throws {
|
|
159
|
-
* @throws {
|
|
160
|
-
* @throws {
|
|
264
|
+
* Prepares a direct BlueBundlesV1 loan-asset borrow.
|
|
265
|
+
*
|
|
266
|
+
* This is the single-operation form of {@link BlueActions.supplyCollateralBorrow}; it borrows
|
|
267
|
+
* `borrowAssets` and fixes the inactive collateral-supply leg to zero. The pre-fetched position
|
|
268
|
+
* is forward-accrued for the buffered LLTV check.
|
|
269
|
+
*
|
|
270
|
+
* @param params.userAddress - User whose debt position changes.
|
|
271
|
+
* @param params.borrowAssets - Gross loan assets borrowed before penalties and referral fees.
|
|
272
|
+
* @param params.positionData - Pre-fetched position used for the health check.
|
|
273
|
+
* @param params.reallocations - Optional Vault V2 reallocations before borrowing.
|
|
274
|
+
* @param params.deadline - Final call deadline in Unix seconds.
|
|
275
|
+
* @param params.referralFeePct - Optional WAD-scaled referral fee below 100%.
|
|
276
|
+
* @param params.referralFeeRecipient - Recipient required for a positive fee.
|
|
277
|
+
* @returns Lazy Blue authorization resolution and a synchronous deep-frozen transaction.
|
|
278
|
+
* @throws {ChainIdMismatchError} when the client targets another chain.
|
|
279
|
+
* @throws {ExpiredDeadlineError} when the deadline is stale.
|
|
280
|
+
* @throws {MissingAccrualPositionError} when no position snapshot is provided.
|
|
281
|
+
* @throws {MarketIdMismatchError} when `positionData` belongs to another market.
|
|
282
|
+
* @throws {AccrualPositionUserMismatchError} when `positionData` belongs to another user.
|
|
283
|
+
* @throws {MissingMarketPriceError} when the health check has no oracle price.
|
|
284
|
+
* @throws {BorrowExceedsSafeLtvError} when the resulting position exceeds buffered LLTV.
|
|
285
|
+
* @throws {NonPositiveInputError} when `borrowAssets` is not positive.
|
|
286
|
+
* @throws {NegativeInputError} when the borrow, fee, or a reallocation value is negative.
|
|
287
|
+
* @throws {InputExceedsMaxError} when a fee, penalty, or reallocation exceeds its bound.
|
|
288
|
+
* @throws {MissingReferralFeeRecipientError} when a positive fee has no recipient.
|
|
289
|
+
* @throws {InvalidReallocationAddressError} when a vault or adapter address is malformed.
|
|
290
|
+
* @throws {InvalidReallocationShapeError} when a reallocation entry is not a valid Vault V2 reallocation.
|
|
291
|
+
* @throws {InvalidReallocationSourceTypeError} when a reallocation source is malformed.
|
|
292
|
+
* @throws {InconsistentReallocationPenaltyError} when one vault uses different penalties.
|
|
293
|
+
* @throws {ReallocationWithdrawalOnTargetMarketError} when a source is the target market.
|
|
294
|
+
* @throws {ReallocationLoanTokenMismatchError} when a source uses another loan token.
|
|
295
|
+
* @throws {AmbiguousRequirementSignaturesError} from `buildTx()` when multiple authorization signatures are supplied.
|
|
296
|
+
* @throws {UnexpectedRequirementSignatureError} from `buildTx()` when a token signature is supplied.
|
|
297
|
+
* @throws {DepositOwnerMismatchError} from `buildTx()` when the signed owner differs from `userAddress`.
|
|
298
|
+
* @throws {BlueBundlesV1RequirementSignatureMismatchError} from `buildTx()` when authorization cannot be encoded safely.
|
|
299
|
+
* @throws {UnsupportedChainIdError} when the chain is absent from the address registry.
|
|
300
|
+
* @throws {UnknownAddressError} when BlueBundlesV1 is not registered.
|
|
301
|
+
* @throws {viem.BaseError} from `getRequirements()` when authorization reads fail.
|
|
302
|
+
* @example
|
|
303
|
+
* ```ts
|
|
304
|
+
* import { AccrualPosition } from "@morpho-org/blue-sdk";
|
|
305
|
+
* import { markets } from "@morpho-org/morpho-test";
|
|
306
|
+
* import { createPublicClient, http, zeroAddress } from "viem";
|
|
307
|
+
* import { mainnet } from "viem/chains";
|
|
308
|
+
* import { morphoViemExtension } from "@morpho-org/morpho-sdk";
|
|
309
|
+
*
|
|
310
|
+
* const client = createPublicClient({ chain: mainnet, transport: http() })
|
|
311
|
+
* .extend(morphoViemExtension());
|
|
312
|
+
* const market = client.morpho.blue(markets[mainnet.id].usdc_wbtc, mainnet.id);
|
|
313
|
+
* const userAddress = zeroAddress;
|
|
314
|
+
* const positionData = new AccrualPosition(
|
|
315
|
+
* { user: userAddress, supplyShares: 0n, borrowShares: 0n, collateral: 10n ** 18n },
|
|
316
|
+
* await market.getMarketData(),
|
|
317
|
+
* );
|
|
318
|
+
* const action = market.borrow({
|
|
319
|
+
* userAddress,
|
|
320
|
+
* borrowAssets: 1_000_000n,
|
|
321
|
+
* positionData,
|
|
322
|
+
* deadline: 1_900_000_000n,
|
|
323
|
+
* });
|
|
324
|
+
* const requirements = await action.getRequirements();
|
|
325
|
+
* const tx = action.buildTx();
|
|
326
|
+
* ```
|
|
161
327
|
*/
|
|
162
328
|
borrow: (params: {
|
|
163
|
-
userAddress: Address;
|
|
164
|
-
|
|
165
|
-
positionData: AccrualPosition;
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
};
|
|
329
|
+
readonly userAddress: Address;
|
|
330
|
+
readonly borrowAssets: bigint;
|
|
331
|
+
readonly positionData: AccrualPosition;
|
|
332
|
+
readonly reallocations?: Iterable<VaultV2BlueReallocation>;
|
|
333
|
+
readonly deadline: bigint;
|
|
334
|
+
readonly referralFeePct?: bigint;
|
|
335
|
+
readonly referralFeeRecipient?: Address;
|
|
336
|
+
}) => ActionOutput<BlueBorrowAction, readonly RequirementSignature[], undefined>;
|
|
172
337
|
/**
|
|
173
|
-
* Prepares a
|
|
174
|
-
*
|
|
175
|
-
* Routed through bundler3 via GeneralAdapter1.
|
|
176
|
-
* Supports two modes via {@link RepayAmountArgs}:
|
|
177
|
-
* - **By assets** (`{ amount }`): repays an exact asset amount (partial repay).
|
|
178
|
-
* - **By shares** (`{ shares }`): repays exact shares (full repay, immune to interest accrual).
|
|
179
|
-
*
|
|
180
|
-
* Computes `maxSharePrice` from market borrow state and `slippageTolerance`.
|
|
338
|
+
* Prepares a direct BlueBundlesV1 loan-asset repayment.
|
|
181
339
|
*
|
|
182
|
-
*
|
|
183
|
-
*
|
|
340
|
+
* This is the single-operation form of {@link BlueActions.repayWithdrawCollateral}; it repays
|
|
341
|
+
* exact assets or shares and fixes the inactive collateral-withdrawal leg to zero. A saturated
|
|
342
|
+
* `repayShares = maxUint256` closes the live debt using a bounded, refundable funding cap.
|
|
184
343
|
*
|
|
185
|
-
*
|
|
344
|
+
* @param params.userAddress - User whose debt position changes.
|
|
345
|
+
* @param params.positionData - Pre-fetched position used to validate and quote repayment.
|
|
346
|
+
* @param params.repayAssets - Exact assets repaid, exclusive with `repayShares`.
|
|
347
|
+
* @param params.repayShares - Exact shares, or `maxUint256` for a full repay.
|
|
348
|
+
* @param params.nativeAmount - Optional full native funding equal to the derived repayment cap.
|
|
349
|
+
* @param params.deadline - Final call deadline in Unix seconds.
|
|
350
|
+
* @param params.referralFeePct - Optional WAD-scaled referral fee below 100%.
|
|
351
|
+
* @param params.referralFeeRecipient - Recipient required for a positive fee.
|
|
352
|
+
* @returns Lazy token prerequisite resolution and a synchronous deep-frozen transaction.
|
|
353
|
+
* @throws {ChainIdMismatchError} when the client targets another chain.
|
|
354
|
+
* @throws {ExpiredDeadlineError} when the deadline is stale.
|
|
355
|
+
* @throws {MissingAccrualPositionError} when no position snapshot is provided.
|
|
356
|
+
* @throws {MarketIdMismatchError} when `positionData` belongs to another market.
|
|
357
|
+
* @throws {AccrualPositionUserMismatchError} when `positionData` belongs to another user.
|
|
358
|
+
* @throws {NegativeInputError} when an amount, native funding, or referral fee is negative.
|
|
359
|
+
* @throws {NonPositiveInputError} when no positive repayment is provided.
|
|
360
|
+
* @throws {MutuallyExclusiveRepayAmountsError} when assets and shares are both nonzero.
|
|
361
|
+
* @throws {RepayExceedsDebtError} when an exact asset repay exceeds current debt.
|
|
362
|
+
* @throws {RepaySharesExceedDebtError} when non-saturated shares exceed current debt shares.
|
|
363
|
+
* @throws {InputExceedsMaxError} when a fee is out of bounds or a share quote deadline is too far away.
|
|
364
|
+
* @throws {MaxRepayAssetsBelowRepayAssetsError} when a signed share cap no longer covers the fresh quote.
|
|
365
|
+
* @throws {MissingReferralFeeRecipientError} when a positive fee has no recipient.
|
|
366
|
+
* @throws {NativeFundingAmountMismatchError} when native funding is partial or mixed.
|
|
367
|
+
* @throws {ChainWNativeMissingError} when native funding is requested on a chain without wNative.
|
|
368
|
+
* @throws {NativeAmountOnNonWNativeAssetError} when native funding targets another token.
|
|
369
|
+
* @throws {MissingPermit2TransferFromNonceError} from `getRequirements()` when Permit2 is selected without a nonce.
|
|
370
|
+
* @throws {Permit2TransferFromNonceAlreadyUsedError} from `getRequirements()` when the explicit Permit2 nonce is consumed.
|
|
371
|
+
* @throws {AmbiguousRequirementSignaturesError} from `buildTx()` when multiple token signatures are supplied.
|
|
372
|
+
* @throws {UnexpectedRequirementSignatureError} from `buildTx()` when an authorization signature is supplied.
|
|
373
|
+
* @throws {DepositOwnerMismatchError} from `buildTx()` when the signed owner differs from `userAddress`.
|
|
374
|
+
* @throws {DepositAssetMismatchError} from `buildTx()` when the signed asset differs from the loan token.
|
|
375
|
+
* @throws {DepositAmountMismatchError} from `buildTx()` when the signed amount differs from the derived funding cap.
|
|
376
|
+
* @throws {DepositSpenderMismatchError} from `buildTx()` when the signed spender is not BlueBundlesV1.
|
|
377
|
+
* @throws {BlueBundlesV1RequirementSignatureMismatchError} from `buildTx()` when a signature cannot be encoded safely.
|
|
378
|
+
* @throws {UnsupportedChainIdError} when the chain is absent from the address registry.
|
|
379
|
+
* @throws {UnknownAddressError} when BlueBundlesV1 is not registered.
|
|
380
|
+
* @throws {viem.BaseError} from `getRequirements()` when an allowance, nonce, or token metadata read fails.
|
|
381
|
+
* @example
|
|
382
|
+
* ```ts
|
|
383
|
+
* import { AccrualPosition } from "@morpho-org/blue-sdk";
|
|
384
|
+
* import { markets } from "@morpho-org/morpho-test";
|
|
385
|
+
* import { createPublicClient, http, maxUint256, zeroAddress } from "viem";
|
|
386
|
+
* import { mainnet } from "viem/chains";
|
|
387
|
+
* import { morphoViemExtension } from "@morpho-org/morpho-sdk";
|
|
186
388
|
*
|
|
187
|
-
*
|
|
188
|
-
*
|
|
389
|
+
* const client = createPublicClient({ chain: mainnet, transport: http() })
|
|
390
|
+
* .extend(morphoViemExtension());
|
|
391
|
+
* const market = client.morpho.blue(markets[mainnet.id].usdc_wbtc, mainnet.id);
|
|
392
|
+
* const userAddress = zeroAddress;
|
|
393
|
+
* const positionData = new AccrualPosition(
|
|
394
|
+
* { user: userAddress, supplyShares: 0n, borrowShares: 1n, collateral: 10n ** 18n },
|
|
395
|
+
* await market.getMarketData(),
|
|
396
|
+
* );
|
|
397
|
+
* const action = market.repay({
|
|
398
|
+
* userAddress,
|
|
399
|
+
* positionData,
|
|
400
|
+
* repayShares: maxUint256,
|
|
401
|
+
* deadline: 1_900_000_000n,
|
|
402
|
+
* });
|
|
403
|
+
* const requirements = await action.getRequirements();
|
|
404
|
+
* const tx = action.buildTx();
|
|
405
|
+
* ```
|
|
189
406
|
*/
|
|
190
407
|
repay: (params: {
|
|
191
|
-
userAddress: Address;
|
|
192
|
-
positionData: AccrualPosition;
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
};
|
|
408
|
+
readonly userAddress: Address;
|
|
409
|
+
readonly positionData: AccrualPosition;
|
|
410
|
+
readonly nativeAmount?: bigint;
|
|
411
|
+
readonly deadline: bigint;
|
|
412
|
+
readonly referralFeePct?: bigint;
|
|
413
|
+
readonly referralFeeRecipient?: Address;
|
|
414
|
+
} & ({
|
|
415
|
+
readonly repayAssets: bigint;
|
|
416
|
+
readonly repayShares?: never;
|
|
417
|
+
} | {
|
|
418
|
+
readonly repayShares: bigint;
|
|
419
|
+
readonly repayAssets?: never;
|
|
420
|
+
})) => ActionOutput<BlueRepayAction, readonly RequirementSignature[], BlueTokenRequirementsParams>;
|
|
205
421
|
/**
|
|
206
|
-
* Prepares a
|
|
207
|
-
*
|
|
208
|
-
* Direct call to `morpho.withdrawCollateral()` — no bundler, no GeneralAdapter1.
|
|
209
|
-
* The caller (`msg.sender`) must be `onBehalf`.
|
|
210
|
-
* Validates position health after withdrawal using the LLTV buffer.
|
|
422
|
+
* Prepares a direct BlueBundlesV1 collateral withdrawal.
|
|
211
423
|
*
|
|
212
|
-
*
|
|
213
|
-
*
|
|
424
|
+
* This is the single-operation form of {@link BlueActions.repayWithdrawCollateral}; it withdraws
|
|
425
|
+
* `collateralAssets` and fixes both inactive repayment fields to zero. The pre-fetched position
|
|
426
|
+
* is forward-accrued before applying the buffered LLTV health check.
|
|
214
427
|
*
|
|
215
|
-
*
|
|
428
|
+
* @param params.userAddress - User whose collateral position changes.
|
|
429
|
+
* @param params.positionData - Pre-fetched position used for balance and health validation.
|
|
430
|
+
* @param params.collateralAssets - Collateral assets withdrawn.
|
|
431
|
+
* @param params.deadline - Final call deadline in Unix seconds.
|
|
432
|
+
* @param params.referralFeePct - Optional WAD-scaled referral fee below 100%.
|
|
433
|
+
* @param params.referralFeeRecipient - Recipient required for a positive fee.
|
|
434
|
+
* @returns Lazy Blue authorization resolution and a synchronous deep-frozen transaction.
|
|
435
|
+
* @throws {ChainIdMismatchError} when the client targets another chain.
|
|
436
|
+
* @throws {ExpiredDeadlineError} when the deadline is stale.
|
|
437
|
+
* @throws {MissingAccrualPositionError} when no position snapshot is provided.
|
|
438
|
+
* @throws {MarketIdMismatchError} when `positionData` belongs to another market.
|
|
439
|
+
* @throws {AccrualPositionUserMismatchError} when `positionData` belongs to another user.
|
|
440
|
+
* @throws {WithdrawExceedsCollateralError} when the withdrawal exceeds the position collateral.
|
|
441
|
+
* @throws {MissingMarketPriceError} when the health check has no oracle price.
|
|
442
|
+
* @throws {WithdrawMakesPositionUnhealthyError} when the result exceeds buffered LLTV.
|
|
443
|
+
* @throws {NonPositiveInputError} when `collateralAssets` is not positive.
|
|
444
|
+
* @throws {NegativeInputError} when collateral or the referral fee is negative.
|
|
445
|
+
* @throws {InputExceedsMaxError} when the referral fee is at least WAD.
|
|
446
|
+
* @throws {MissingReferralFeeRecipientError} when a positive fee has no recipient.
|
|
447
|
+
* @throws {AmbiguousRequirementSignaturesError} from `buildTx()` when multiple authorization signatures are supplied.
|
|
448
|
+
* @throws {UnexpectedRequirementSignatureError} from `buildTx()` when a token signature is supplied.
|
|
449
|
+
* @throws {DepositOwnerMismatchError} from `buildTx()` when the signed owner differs from `userAddress`.
|
|
450
|
+
* @throws {BlueBundlesV1RequirementSignatureMismatchError} from `buildTx()` when authorization cannot be encoded safely.
|
|
451
|
+
* @throws {UnsupportedChainIdError} when the chain is absent from the address registry.
|
|
452
|
+
* @throws {UnknownAddressError} when BlueBundlesV1 is not registered.
|
|
453
|
+
* @throws {viem.BaseError} from `getRequirements()` when authorization reads fail.
|
|
454
|
+
* @example
|
|
455
|
+
* ```ts
|
|
456
|
+
* import { AccrualPosition } from "@morpho-org/blue-sdk";
|
|
457
|
+
* import { markets } from "@morpho-org/morpho-test";
|
|
458
|
+
* import { createPublicClient, http, zeroAddress } from "viem";
|
|
459
|
+
* import { mainnet } from "viem/chains";
|
|
460
|
+
* import { morphoViemExtension } from "@morpho-org/morpho-sdk";
|
|
216
461
|
*
|
|
217
|
-
*
|
|
218
|
-
*
|
|
462
|
+
* const client = createPublicClient({ chain: mainnet, transport: http() })
|
|
463
|
+
* .extend(morphoViemExtension());
|
|
464
|
+
* const market = client.morpho.blue(markets[mainnet.id].usdc_wbtc, mainnet.id);
|
|
465
|
+
* const userAddress = zeroAddress;
|
|
466
|
+
* const positionData = new AccrualPosition(
|
|
467
|
+
* { user: userAddress, supplyShares: 0n, borrowShares: 0n, collateral: 10n ** 18n },
|
|
468
|
+
* await market.getMarketData(),
|
|
469
|
+
* );
|
|
470
|
+
* const action = market.withdrawCollateral({
|
|
471
|
+
* userAddress,
|
|
472
|
+
* positionData,
|
|
473
|
+
* collateralAssets: 10n ** 17n,
|
|
474
|
+
* deadline: 1_900_000_000n,
|
|
475
|
+
* });
|
|
476
|
+
* const requirements = await action.getRequirements();
|
|
477
|
+
* const tx = action.buildTx();
|
|
478
|
+
* ```
|
|
219
479
|
*/
|
|
220
480
|
withdrawCollateral: (params: {
|
|
221
|
-
userAddress: Address;
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
481
|
+
readonly userAddress: Address;
|
|
482
|
+
readonly positionData: AccrualPosition;
|
|
483
|
+
readonly collateralAssets: bigint;
|
|
484
|
+
readonly deadline: bigint;
|
|
485
|
+
readonly referralFeePct?: bigint;
|
|
486
|
+
readonly referralFeeRecipient?: Address;
|
|
487
|
+
}) => ActionOutput<BlueWithdrawCollateralAction, readonly RequirementSignature[], undefined>;
|
|
227
488
|
/**
|
|
228
|
-
* Prepares
|
|
489
|
+
* Prepares a direct BlueBundlesV1 repay, collateral withdrawal, or atomic combination.
|
|
229
490
|
*
|
|
230
|
-
*
|
|
231
|
-
*
|
|
232
|
-
*
|
|
491
|
+
* Repayment accepts exact assets or shares. `repayShares = maxUint256` requests the contract's
|
|
492
|
+
* saturated full close; the entity derives `maxRepayAssets` from debt projected through the
|
|
493
|
+
* requested deadline plus the referral fee, and the contract refunds unused funding. A
|
|
494
|
+
* previously signed share-mode cap remains valid when it still covers the fresh derived minimum.
|
|
495
|
+
* Saturated full-repay requirements use the token's reusable maximum allowance when signatures
|
|
496
|
+
* are disabled, while the transaction itself remains bounded by the derived cap.
|
|
497
|
+
* Share-mode deadlines cannot exceed the two-hour quote horizon. Blue authorization is required
|
|
498
|
+
* only for collateral withdrawal. Pure repay uses `maxLtv = maxUint256`; withdrawals use buffered
|
|
499
|
+
* LLTV. No Bundler3 share-price or `slippageTolerance` input exists.
|
|
233
500
|
*
|
|
234
|
-
*
|
|
235
|
-
*
|
|
236
|
-
*
|
|
237
|
-
*
|
|
238
|
-
*
|
|
501
|
+
* @param params.userAddress - User whose debt and collateral position changes.
|
|
502
|
+
* @param params.positionData - Pre-fetched position used for repayment and health validation.
|
|
503
|
+
* @param params.repayAssets - Exact assets repaid, exclusive with `repayShares`.
|
|
504
|
+
* @param params.repayShares - Exact shares, or `maxUint256` for full repay.
|
|
505
|
+
* @param params.collateralAssets - Collateral withdrawn, or zero for pure repay.
|
|
506
|
+
* @param params.nativeAmount - Optional full native funding; must equal derived `maxRepayAssets`.
|
|
507
|
+
* @param params.deadline - Final call deadline in Unix seconds; share mode is limited to the two-hour funding quote horizon.
|
|
508
|
+
* @param params.referralFeePct - Optional WAD-scaled referral fee below 100%.
|
|
509
|
+
* @param params.referralFeeRecipient - Recipient required for a positive fee.
|
|
510
|
+
* @returns Lazy funding/authorization resolution and a synchronous deep-frozen transaction builder.
|
|
511
|
+
* @throws {ChainIdMismatchError} when the client targets another chain.
|
|
512
|
+
* @throws {MissingAccrualPositionError} when no position snapshot is provided at runtime.
|
|
513
|
+
* @throws {MarketIdMismatchError} when `positionData` belongs to another market.
|
|
514
|
+
* @throws {AccrualPositionUserMismatchError} when `positionData` belongs to another user.
|
|
515
|
+
* @throws {NegativeInputError} when an amount, native funding, or referral fee is negative.
|
|
516
|
+
* @throws {NonPositiveInputError} when no operation leg is provided.
|
|
517
|
+
* @throws {MutuallyExclusiveRepayAmountsError} when assets and shares are both nonzero.
|
|
518
|
+
* @throws {RepayExceedsDebtError} when an exact asset repay exceeds current debt.
|
|
519
|
+
* @throws {RepaySharesExceedDebtError} when non-saturated shares exceed current debt shares.
|
|
520
|
+
* @throws {WithdrawExceedsCollateralError} when collateral withdrawal exceeds the position.
|
|
521
|
+
* @throws {MissingMarketPriceError} when withdrawal health cannot be validated without an oracle price.
|
|
522
|
+
* @throws {WithdrawMakesPositionUnhealthyError} when the post-repay withdrawal exceeds buffered LLTV.
|
|
523
|
+
* @throws {ExpiredDeadlineError} when the deadline is stale.
|
|
524
|
+
* @throws {InputExceedsMaxError} when the referral fee is at least WAD or a share-mode deadline exceeds the funding quote horizon.
|
|
525
|
+
* @throws {MaxRepayAssetsBelowRepayAssetsError} from `buildTx()` when a previously signed share-mode cap no longer covers the fresh derived minimum.
|
|
526
|
+
* @throws {MissingReferralFeeRecipientError} when a positive fee has no recipient.
|
|
527
|
+
* @throws {NativeFundingAmountMismatchError} when native funding is partial or mixed.
|
|
528
|
+
* @throws {ChainWNativeMissingError} when native funding is requested on a chain without wNative.
|
|
529
|
+
* @throws {NativeAmountOnNonWNativeAssetError} when native funding targets another token.
|
|
530
|
+
* @throws {MissingPermit2TransferFromNonceError} from `getRequirements()` when Permit2 is selected without an explicit nonce.
|
|
531
|
+
* @throws {Permit2TransferFromNonceAlreadyUsedError} from `getRequirements()` when the explicit Permit2 nonce is consumed.
|
|
532
|
+
* @throws {AmbiguousRequirementSignaturesError} from `buildTx()` when multiple signatures of one kind are supplied.
|
|
533
|
+
* @throws {UnexpectedRequirementSignatureError} from `buildTx()` when an inactive leg cannot consume a supplied signature.
|
|
534
|
+
* @throws {DepositOwnerMismatchError} from `buildTx()` when a signed owner differs from `userAddress`.
|
|
535
|
+
* @throws {DepositAssetMismatchError} from `buildTx()` when the signed asset differs from the loan token.
|
|
536
|
+
* @throws {DepositAmountMismatchError} from `buildTx()` when the signed amount differs from the derived funding cap.
|
|
537
|
+
* @throws {DepositSpenderMismatchError} from `buildTx()` when the signed spender is not BlueBundlesV1.
|
|
538
|
+
* @throws {BlueBundlesV1RequirementSignatureMismatchError} from `buildTx()` when a signature cannot be encoded safely.
|
|
539
|
+
* @throws {UnsupportedChainIdError} when the chain is absent from the address registry.
|
|
540
|
+
* @throws {UnknownAddressError} when BlueBundlesV1 is not registered.
|
|
541
|
+
* @throws {viem.BaseError} from `getRequirements()` when a required allowance, nonce, token metadata, or authorization read fails.
|
|
542
|
+
* @example
|
|
543
|
+
* ```ts
|
|
544
|
+
* import { AccrualPosition } from "@morpho-org/blue-sdk";
|
|
545
|
+
* import { markets } from "@morpho-org/morpho-test";
|
|
546
|
+
* import { createPublicClient, http, maxUint256, zeroAddress } from "viem";
|
|
547
|
+
* import { mainnet } from "viem/chains";
|
|
548
|
+
* import { morphoViemExtension } from "@morpho-org/morpho-sdk";
|
|
239
549
|
*
|
|
240
|
-
*
|
|
241
|
-
*
|
|
550
|
+
* const userAddress = zeroAddress;
|
|
551
|
+
* const client = createPublicClient({ chain: mainnet, transport: http() })
|
|
552
|
+
* .extend(morphoViemExtension());
|
|
553
|
+
* const market = client.morpho.blue(markets[mainnet.id].usdc_wbtc, mainnet.id);
|
|
554
|
+
* const positionData = new AccrualPosition(
|
|
555
|
+
* { user: userAddress, supplyShares: 0n, borrowShares: 1n, collateral: 100_000_000n },
|
|
556
|
+
* await market.getMarketData(),
|
|
557
|
+
* );
|
|
558
|
+
* const action = market.repayWithdrawCollateral({
|
|
559
|
+
* userAddress,
|
|
560
|
+
* positionData,
|
|
561
|
+
* repayShares: maxUint256,
|
|
562
|
+
* collateralAssets: 1n,
|
|
563
|
+
* deadline: BigInt(Math.floor(Date.now() / 1_000) + 3_600),
|
|
564
|
+
* });
|
|
565
|
+
* const requirements = await action.getRequirements(); // Satisfy these first.
|
|
566
|
+
* const tx = action.buildTx(); // For a client configured with supportSignature: false.
|
|
567
|
+
* // tx satisfies Readonly<Transaction<BlueRepayWithdrawCollateralAction>>
|
|
568
|
+
* ```
|
|
242
569
|
*/
|
|
243
570
|
repayWithdrawCollateral: (params: {
|
|
244
|
-
userAddress: Address;
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
571
|
+
readonly userAddress: Address;
|
|
572
|
+
readonly positionData: AccrualPosition;
|
|
573
|
+
readonly collateralAssets: bigint;
|
|
574
|
+
readonly nativeAmount?: bigint;
|
|
575
|
+
readonly deadline: bigint;
|
|
576
|
+
readonly referralFeePct?: bigint;
|
|
577
|
+
readonly referralFeeRecipient?: Address;
|
|
578
|
+
} & ({
|
|
579
|
+
readonly repayAssets: bigint;
|
|
580
|
+
readonly repayShares?: never;
|
|
581
|
+
} | {
|
|
582
|
+
readonly repayShares: bigint;
|
|
583
|
+
readonly repayAssets?: never;
|
|
584
|
+
} | {
|
|
585
|
+
readonly repayAssets?: undefined;
|
|
586
|
+
readonly repayShares?: undefined;
|
|
587
|
+
})) => ActionOutput<BlueRepayWithdrawCollateralAction, readonly RequirementSignature[], BlueTokenRequirementsParams>;
|
|
259
588
|
/**
|
|
260
|
-
* Prepares
|
|
261
|
-
*
|
|
262
|
-
*
|
|
263
|
-
*
|
|
264
|
-
*
|
|
265
|
-
*
|
|
266
|
-
*
|
|
267
|
-
*
|
|
268
|
-
*
|
|
269
|
-
*
|
|
270
|
-
* -
|
|
271
|
-
* -
|
|
272
|
-
*
|
|
273
|
-
*
|
|
274
|
-
*
|
|
275
|
-
*
|
|
276
|
-
* @param params -
|
|
277
|
-
* @returns
|
|
278
|
-
* @throws {
|
|
279
|
-
* @throws {
|
|
280
|
-
* @throws {
|
|
281
|
-
* @throws {
|
|
282
|
-
* @throws {
|
|
283
|
-
* @throws {
|
|
284
|
-
* @throws {
|
|
589
|
+
* Prepares a direct BlueBundlesV1 collateral supply, borrow, or atomic combination.
|
|
590
|
+
*
|
|
591
|
+
* At least one leg must be positive. A borrow requires `positionData` and Blue authorization;
|
|
592
|
+
* collateral funding requires token approval/signature unless it is exclusively native. Vault V2
|
|
593
|
+
* reallocations are accepted only with a borrow. Penalties and referral fees reduce borrow
|
|
594
|
+
* proceeds. The entity uses `maxUint256` for a pure collateral supply and buffered LLTV otherwise.
|
|
595
|
+
* No Bundler3 share-price or `slippageTolerance` input exists.
|
|
596
|
+
*
|
|
597
|
+
* @param params.userAddress - User whose collateral and debt position changes.
|
|
598
|
+
* @param params.collateralAssets - Gross collateral supplied, or zero for pure borrow.
|
|
599
|
+
* @param params.borrowAssets - Loan assets borrowed, or zero for pure collateral supply.
|
|
600
|
+
* @param params.positionData - Pre-fetched position; required when `borrowAssets` is positive.
|
|
601
|
+
* @param params.nativeAmount - Optional full native collateral funding; must equal `collateralAssets`.
|
|
602
|
+
* @param params.reallocations - Optional Vault V2 reallocations; valid only for a borrow.
|
|
603
|
+
* @param params.deadline - Final call deadline in Unix seconds.
|
|
604
|
+
* @param params.referralFeePct - Optional WAD-scaled referral fee below 100%.
|
|
605
|
+
* @param params.referralFeeRecipient - Recipient required for a positive fee.
|
|
606
|
+
* @returns Lazy funding/authorization resolution and a synchronous deep-frozen transaction builder.
|
|
607
|
+
* @throws {ChainIdMismatchError} when the client targets another chain.
|
|
608
|
+
* @throws {MissingAccrualPositionError} when a borrow has no position snapshot.
|
|
609
|
+
* @throws {MarketIdMismatchError} when `positionData` belongs to another market.
|
|
610
|
+
* @throws {AccrualPositionUserMismatchError} when `positionData` belongs to another user.
|
|
611
|
+
* @throws {MissingMarketPriceError} when a borrow cannot be validated without an oracle price.
|
|
612
|
+
* @throws {BorrowExceedsSafeLtvError} when the resulting debt exceeds buffered LLTV.
|
|
613
|
+
* @throws {ReallocationsRequireBorrowError} when reallocations accompany no borrow.
|
|
614
|
+
* @throws {ExpiredDeadlineError} when the deadline is stale.
|
|
615
|
+
* @throws {NegativeInputError} when an amount, native funding, referral fee, or reallocation penalty is negative.
|
|
616
|
+
* @throws {NonPositiveInputError} when both legs or a reallocation amount is not positive.
|
|
617
|
+
* @throws {NativeFundingAmountMismatchError} when native funding is partial or mixed.
|
|
618
|
+
* @throws {ChainWNativeMissingError} when native funding is requested on a chain without wNative.
|
|
619
|
+
* @throws {NativeAmountOnNonWNativeAssetError} when native funding targets another token.
|
|
620
|
+
* @throws {InputExceedsMaxError} when a fee or reallocation exceeds its ABI bound.
|
|
621
|
+
* @throws {MissingReferralFeeRecipientError} when a positive fee has no recipient.
|
|
622
|
+
* @throws {InvalidReallocationAddressError} when a vault or adapter address is malformed.
|
|
623
|
+
* @throws {InvalidReallocationShapeError} when a reallocation entry is not a valid Vault V2 reallocation.
|
|
624
|
+
* @throws {InvalidReallocationSourceTypeError} when a reallocation source is malformed.
|
|
625
|
+
* @throws {InconsistentReallocationPenaltyError} when one vault uses different penalties.
|
|
626
|
+
* @throws {ReallocationWithdrawalOnTargetMarketError} when a source is the target market.
|
|
627
|
+
* @throws {ReallocationLoanTokenMismatchError} when a source uses another loan token.
|
|
628
|
+
* @throws {MissingPermit2TransferFromNonceError} from `getRequirements()` when Permit2 is selected without an explicit nonce.
|
|
629
|
+
* @throws {Permit2TransferFromNonceAlreadyUsedError} from `getRequirements()` when the explicit Permit2 nonce is consumed.
|
|
630
|
+
* @throws {AmbiguousRequirementSignaturesError} from `buildTx()` when multiple signatures of one kind are supplied.
|
|
631
|
+
* @throws {UnexpectedRequirementSignatureError} from `buildTx()` when an inactive leg cannot consume a supplied signature.
|
|
632
|
+
* @throws {DepositOwnerMismatchError} from `buildTx()` when a signed owner differs from `userAddress`.
|
|
633
|
+
* @throws {DepositAssetMismatchError} from `buildTx()` when the signed asset differs from the collateral token.
|
|
634
|
+
* @throws {DepositAmountMismatchError} from `buildTx()` when the signed amount differs from `collateralAssets`.
|
|
635
|
+
* @throws {DepositSpenderMismatchError} from `buildTx()` when the signed spender is not BlueBundlesV1.
|
|
636
|
+
* @throws {BlueBundlesV1RequirementSignatureMismatchError} from `buildTx()` when a signature cannot be encoded safely.
|
|
637
|
+
* @throws {UnsupportedChainIdError} when the chain is absent from the address registry.
|
|
638
|
+
* @throws {UnknownAddressError} when BlueBundlesV1 is not registered.
|
|
639
|
+
* @throws {viem.BaseError} from `getRequirements()` when a required allowance, nonce, token metadata, or authorization read fails.
|
|
640
|
+
* @example
|
|
641
|
+
* ```ts
|
|
642
|
+
* import { markets } from "@morpho-org/morpho-test";
|
|
643
|
+
* import { createPublicClient, http, zeroAddress } from "viem";
|
|
644
|
+
* import { mainnet } from "viem/chains";
|
|
645
|
+
* import { morphoViemExtension } from "@morpho-org/morpho-sdk";
|
|
646
|
+
*
|
|
647
|
+
* const userAddress = zeroAddress;
|
|
648
|
+
* const client = createPublicClient({ chain: mainnet, transport: http() })
|
|
649
|
+
* .extend(morphoViemExtension());
|
|
650
|
+
* const market = client.morpho.blue(markets[mainnet.id].usdc_wbtc, mainnet.id);
|
|
651
|
+
* const positionData = await market.getPositionData(userAddress);
|
|
652
|
+
* const action = market.supplyCollateralBorrow({
|
|
653
|
+
* userAddress,
|
|
654
|
+
* positionData,
|
|
655
|
+
* collateralAssets: 100_000_000n,
|
|
656
|
+
* borrowAssets: 1_000_000n,
|
|
657
|
+
* deadline: BigInt(Math.floor(Date.now() / 1_000) + 3_600),
|
|
658
|
+
* });
|
|
659
|
+
* const requirements = await action.getRequirements(); // Satisfy these first.
|
|
660
|
+
* const tx = action.buildTx(); // For a client configured with supportSignature: false.
|
|
661
|
+
* // tx satisfies Readonly<Transaction<BlueSupplyCollateralBorrowAction>>
|
|
662
|
+
* ```
|
|
285
663
|
*/
|
|
286
664
|
supplyCollateralBorrow: (params: {
|
|
287
|
-
userAddress: Address;
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
* Leave unset or set to `false` to force the Permit2/classic approval fallback when
|
|
298
|
-
* a token is known to be incompatible despite passing the SDK's shallow nonce probe.
|
|
299
|
-
*/
|
|
300
|
-
useSimplePermit?: boolean;
|
|
301
|
-
}) => Promise<(Readonly<Transaction<ERC20ApprovalAction>> | Readonly<Transaction<BlueAuthorizationAction>> | Requirement)[]>;
|
|
302
|
-
};
|
|
665
|
+
readonly userAddress: Address;
|
|
666
|
+
readonly collateralAssets: bigint;
|
|
667
|
+
readonly borrowAssets: bigint;
|
|
668
|
+
readonly positionData?: AccrualPosition;
|
|
669
|
+
readonly nativeAmount?: bigint;
|
|
670
|
+
readonly reallocations?: Iterable<VaultV2BlueReallocation>;
|
|
671
|
+
readonly deadline: bigint;
|
|
672
|
+
readonly referralFeePct?: bigint;
|
|
673
|
+
readonly referralFeeRecipient?: Address;
|
|
674
|
+
}) => ActionOutput<BlueSupplyCollateralBorrowAction, readonly RequirementSignature[], BlueTokenRequirementsParams>;
|
|
303
675
|
/**
|
|
304
|
-
* Prepares
|
|
305
|
-
*
|
|
306
|
-
*
|
|
307
|
-
*
|
|
308
|
-
* both
|
|
309
|
-
*
|
|
310
|
-
*
|
|
311
|
-
*
|
|
312
|
-
* to
|
|
313
|
-
*
|
|
314
|
-
*
|
|
315
|
-
*
|
|
316
|
-
*
|
|
317
|
-
*
|
|
318
|
-
* @param params.
|
|
319
|
-
* @param params.
|
|
320
|
-
* @param params.
|
|
321
|
-
* @param params.
|
|
322
|
-
* @
|
|
323
|
-
* @
|
|
324
|
-
* @
|
|
325
|
-
* @
|
|
326
|
-
* @
|
|
327
|
-
* @
|
|
328
|
-
* @throws {
|
|
329
|
-
* @throws {
|
|
330
|
-
* @throws {
|
|
331
|
-
* @throws {
|
|
332
|
-
* @throws {
|
|
333
|
-
* @throws {
|
|
334
|
-
* @throws {
|
|
676
|
+
* Prepares a direct BlueBundlesV1 full borrow-position migration.
|
|
677
|
+
*
|
|
678
|
+
* The scoped market is the source. BlueBundlesV1 reads the live source debt/collateral at
|
|
679
|
+
* execution and extends the destination position; zero live debt reverts. The markets must share
|
|
680
|
+
* both tokens. Referral fees and Vault V2 reallocation penalties increase destination debt, whose
|
|
681
|
+
* complete position is checked against buffered LLTV. Partial and collateral-only migration are
|
|
682
|
+
* unsupported.
|
|
683
|
+
*
|
|
684
|
+
* @param params.userAddress - Intended owner used to validate both snapshots and resolve Morpho
|
|
685
|
+
* authorization. It must also send the transaction: the builder cannot enforce this alignment
|
|
686
|
+
* because this field is not encoded and BlueBundlesV1 always migrates `msg.sender`.
|
|
687
|
+
* @param params.positionData - Pre-fetched source position with nonzero debt.
|
|
688
|
+
* @param params.destination.marketParams - Distinct destination market with matching tokens.
|
|
689
|
+
* @param params.destination.positionData - User's pre-fetched destination position.
|
|
690
|
+
* @param params.reallocations - Optional Vault V2 reallocations into the destination.
|
|
691
|
+
* @param params.deadline - Final call deadline in Unix seconds.
|
|
692
|
+
* @param params.referralFeePct - Optional WAD-scaled referral fee below 100%.
|
|
693
|
+
* @param params.referralFeeRecipient - Recipient required for a positive fee.
|
|
694
|
+
* @returns Lazy Blue authorization resolution and a synchronous deep-frozen transaction builder.
|
|
695
|
+
* @throws {ChainIdMismatchError} when the client targets another chain.
|
|
696
|
+
* @throws {MissingAccrualPositionError} when either position snapshot is absent at runtime.
|
|
697
|
+
* @throws {MarketIdMismatchError} when a position snapshot belongs to another market.
|
|
698
|
+
* @throws {AccrualPositionUserMismatchError} when a position snapshot belongs to another user.
|
|
699
|
+
* @throws {RefinanceSameMarketError} when source and destination IDs match.
|
|
700
|
+
* @throws {RefinanceTokenMismatchError} when their loan or collateral tokens differ.
|
|
701
|
+
* @throws {NegativeInputError} when a referral fee or reallocation penalty is negative.
|
|
702
|
+
* @throws {NonPositiveInputError} when the source has no borrow shares or a reallocation amount is not positive.
|
|
703
|
+
* @throws {MissingMarketPriceError} when destination health cannot be validated without an oracle price.
|
|
704
|
+
* @throws {BorrowExceedsSafeLtvError} when the complete destination exceeds buffered LLTV.
|
|
705
|
+
* @throws {ExpiredDeadlineError} when the deadline is stale.
|
|
706
|
+
* @throws {InputExceedsMaxError} when a fee or reallocation exceeds its ABI bound.
|
|
707
|
+
* @throws {MissingReferralFeeRecipientError} when a positive fee has no recipient.
|
|
708
|
+
* @throws {InvalidReallocationAddressError} when a vault or adapter address is malformed.
|
|
709
|
+
* @throws {InvalidReallocationShapeError} when a reallocation entry is not a valid Vault V2 reallocation.
|
|
710
|
+
* @throws {InvalidReallocationSourceTypeError} when a reallocation source is malformed.
|
|
711
|
+
* @throws {InconsistentReallocationPenaltyError} when one vault uses different penalties.
|
|
712
|
+
* @throws {ReallocationWithdrawalOnTargetMarketError} when a source is the destination market.
|
|
713
|
+
* @throws {ReallocationLoanTokenMismatchError} when a source uses another loan token.
|
|
714
|
+
* @throws {AmbiguousRequirementSignaturesError} from `buildTx()` when multiple authorization signatures are supplied.
|
|
715
|
+
* @throws {UnexpectedRequirementSignatureError} from `buildTx()` when a non-authorization signature is supplied.
|
|
716
|
+
* @throws {DepositOwnerMismatchError} from `buildTx()` when the signed owner differs from `userAddress`.
|
|
717
|
+
* @throws {BlueBundlesV1RequirementSignatureMismatchError} from `buildTx()` when authorization cannot be encoded safely.
|
|
718
|
+
* @throws {UnsupportedChainIdError} when the chain is absent from the address registry.
|
|
719
|
+
* @throws {UnknownAddressError} when BlueBundlesV1 is not registered.
|
|
720
|
+
* @throws {viem.BaseError} from `getRequirements()` when authorization reads fail.
|
|
721
|
+
* @example
|
|
722
|
+
* ```ts
|
|
723
|
+
* import { AccrualPosition } from "@morpho-org/blue-sdk";
|
|
724
|
+
* import { markets } from "@morpho-org/morpho-test";
|
|
725
|
+
* import { createPublicClient, http, zeroAddress } from "viem";
|
|
726
|
+
* import { mainnet } from "viem/chains";
|
|
727
|
+
* import { morphoViemExtension } from "@morpho-org/morpho-sdk";
|
|
728
|
+
*
|
|
729
|
+
* const userAddress = zeroAddress;
|
|
730
|
+
* const client = createPublicClient({ chain: mainnet, transport: http() })
|
|
731
|
+
* .extend(morphoViemExtension());
|
|
732
|
+
* const sourceParams = markets[mainnet.id].eth_wstEth_2;
|
|
733
|
+
* const destinationParams = markets[mainnet.id].eth_wstEth;
|
|
734
|
+
* const market = client.morpho.blue(sourceParams, mainnet.id);
|
|
735
|
+
* const destinationMarket = client.morpho.blue(destinationParams, mainnet.id);
|
|
736
|
+
* const source = new AccrualPosition(
|
|
737
|
+
* { user: userAddress, supplyShares: 0n, borrowShares: 1n, collateral: 10n ** 18n },
|
|
738
|
+
* await market.getMarketData(),
|
|
739
|
+
* );
|
|
740
|
+
* const destination = new AccrualPosition(
|
|
741
|
+
* { user: userAddress, supplyShares: 0n, borrowShares: 0n, collateral: 0n },
|
|
742
|
+
* await destinationMarket.getMarketData(),
|
|
743
|
+
* );
|
|
744
|
+
* const action = market.refinance({
|
|
745
|
+
* userAddress,
|
|
746
|
+
* positionData: source,
|
|
747
|
+
* destination: { marketParams: destinationParams, positionData: destination },
|
|
748
|
+
* deadline: BigInt(Math.floor(Date.now() / 1_000) + 3_600),
|
|
749
|
+
* });
|
|
750
|
+
* const requirements = await action.getRequirements(); // Satisfy these first.
|
|
751
|
+
* const tx = action.buildTx(); // For a client configured with supportSignature: false.
|
|
752
|
+
* // tx satisfies Readonly<Transaction<BlueRefinanceAction>>
|
|
753
|
+
* ```
|
|
335
754
|
*/
|
|
336
755
|
refinance: (params: {
|
|
337
|
-
userAddress: Address;
|
|
338
|
-
positionData: AccrualPosition;
|
|
339
|
-
|
|
340
|
-
marketParams: MarketParams;
|
|
341
|
-
positionData: AccrualPosition;
|
|
756
|
+
readonly userAddress: Address;
|
|
757
|
+
readonly positionData: AccrualPosition;
|
|
758
|
+
readonly destination: {
|
|
759
|
+
readonly marketParams: MarketParams;
|
|
760
|
+
readonly positionData: AccrualPosition;
|
|
342
761
|
};
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
}) => {
|
|
349
|
-
buildTx: (signatures?: readonly RequirementSignature[]) => Readonly<Transaction<BlueRefinanceAction>>;
|
|
350
|
-
getRequirements: () => Promise<(Readonly<Transaction<ERC20ApprovalAction>> | Readonly<Transaction<BlueAuthorizationAction>> | Requirement)[]>;
|
|
351
|
-
};
|
|
762
|
+
readonly reallocations?: Iterable<VaultV2BlueReallocation>;
|
|
763
|
+
readonly deadline: bigint;
|
|
764
|
+
readonly referralFeePct?: bigint;
|
|
765
|
+
readonly referralFeeRecipient?: Address;
|
|
766
|
+
}) => ActionOutput<BlueRefinanceAction, readonly RequirementSignature[], undefined>;
|
|
352
767
|
/**
|
|
353
768
|
* Fetches all on-chain data needed to construct a {@link VaultV1ReallocationData}
|
|
354
769
|
* for computing vault reallocations via the public allocator.
|
|
@@ -359,9 +774,8 @@ export interface BlueActions {
|
|
|
359
774
|
* inject unnecessary `reallocateTo` actions (and their PublicAllocator
|
|
360
775
|
* fees) into the resulting bundle.
|
|
361
776
|
*
|
|
362
|
-
* The returned
|
|
363
|
-
*
|
|
364
|
-
* `supplyCollateralBorrow()`.
|
|
777
|
+
* The returned data can be passed to {@link getVaultV1Reallocations} for explicit low-level
|
|
778
|
+
* Bundler3 composition.
|
|
365
779
|
*
|
|
366
780
|
* **Stale data reverts on-chain (fail-safe).**
|
|
367
781
|
*
|
|
@@ -369,6 +783,8 @@ export interface BlueActions {
|
|
|
369
783
|
* @param params.block - The block to fetch data at (number and timestamp).
|
|
370
784
|
* @returns A VaultV1ReallocationData instance populated with all required data.
|
|
371
785
|
* @throws {ChainIdMismatchError} when the client chain does not match this market.
|
|
786
|
+
* @deprecated Vault V1 shared-liquidity planning will be removed in the next major. Use
|
|
787
|
+
* {@link getVaultV2BlueReallocationData}.
|
|
372
788
|
*/
|
|
373
789
|
getVaultV1ReallocationData: (params: {
|
|
374
790
|
vaultAddresses: readonly Address[];
|
|
@@ -385,7 +801,9 @@ export interface BlueActions {
|
|
|
385
801
|
* @param params.block.timestamp - Timestamp corresponding to the fetched block.
|
|
386
802
|
* @returns A `VaultV1ReallocationData` snapshot populated from one block.
|
|
387
803
|
* @throws {ChainIdMismatchError} when the client chain does not match this market.
|
|
388
|
-
* @deprecated Use {@link getVaultV1ReallocationData}
|
|
804
|
+
* @deprecated Use {@link getVaultV1ReallocationData} for deprecated low-level Bundler3
|
|
805
|
+
* planning. Vault V1 shared-liquidity planning will be removed in the next major; use
|
|
806
|
+
* {@link getVaultV2BlueReallocationData} for high-level Blue writes.
|
|
389
807
|
*/
|
|
390
808
|
getReallocationData: (params: {
|
|
391
809
|
vaultAddresses: readonly Address[];
|
|
@@ -437,13 +855,14 @@ export interface BlueActions {
|
|
|
437
855
|
* @param params.options - Optional reallocation computation options
|
|
438
856
|
* (timestamp, utilization targets, reallocatable vaults filter, etc.).
|
|
439
857
|
* Pass the fetched block timestamp to compute reallocations at the same block.
|
|
440
|
-
* @returns
|
|
441
|
-
* or `withdraw()`. Empty array if no reallocation is needed.
|
|
858
|
+
* @returns Vault V1 reallocations for explicit low-level Bundler3 composition.
|
|
442
859
|
* @throws {ChainIdMismatchError} when `reallocationData` belongs to a different chain than this market.
|
|
443
860
|
* @throws {InsufficientSharedLiquidityError} when shared liquidity cannot cover the operation's absolute shortfall on the target market — preventing fee-bearing reallocations from being attached to a call that would still revert onchain.
|
|
444
861
|
* @throws {ReallocationWithdrawExceedsMarketSupplyError} when a withdrawal exceeds the target market supply.
|
|
445
862
|
* @throws {MissingPublicAllocatorConfigError} when a selected vault is missing its public allocator config.
|
|
446
863
|
* @throws {UnknownReallocationMarketError} when the target market is absent from the reallocation data.
|
|
864
|
+
* @deprecated Vault V1 shared-liquidity planning will be removed in the next major. Use
|
|
865
|
+
* {@link getVaultV2BlueReallocations}.
|
|
447
866
|
* @example
|
|
448
867
|
* ```ts
|
|
449
868
|
* const reallocations = market.getVaultV1Reallocations({
|
|
@@ -462,13 +881,14 @@ export interface BlueActions {
|
|
|
462
881
|
* @param params.amount - The borrow or withdraw amount used to compute post-state utilization.
|
|
463
882
|
* @param params.borrowAmount - Deprecated borrow amount alias.
|
|
464
883
|
* @param params.options - Optional allocator and utilization options.
|
|
465
|
-
* @returns Vault V1 reallocations
|
|
884
|
+
* @returns Vault V1 reallocations for explicit low-level Bundler3 composition.
|
|
466
885
|
* @throws {ChainIdMismatchError} when `reallocationData` belongs to another chain.
|
|
467
886
|
* @throws {InsufficientSharedLiquidityError} when shared liquidity cannot cover the operation.
|
|
468
887
|
* @throws {ReallocationWithdrawExceedsMarketSupplyError} when a withdrawal exceeds market supply.
|
|
469
888
|
* @throws {MissingPublicAllocatorConfigError} when a selected vault lacks allocator state.
|
|
470
889
|
* @throws {UnknownReallocationMarketError} when the target market is absent.
|
|
471
|
-
* @deprecated
|
|
890
|
+
* @deprecated Vault V1 shared-liquidity planning will be removed in the next major. Use
|
|
891
|
+
* {@link getVaultV2BlueReallocations}.
|
|
472
892
|
* @example
|
|
473
893
|
* ```ts
|
|
474
894
|
* const reallocations = market.getReallocations({
|
|
@@ -517,102 +937,133 @@ export declare class MorphoBlue implements BlueActions {
|
|
|
517
937
|
readonly marketParams: MarketParams;
|
|
518
938
|
private readonly chainId;
|
|
519
939
|
constructor(client: MorphoClientType, marketParams: MarketParams, chainId: number);
|
|
520
|
-
private
|
|
940
|
+
private validateDeadline;
|
|
941
|
+
private validateWriteCommon;
|
|
942
|
+
private getMaxLtv;
|
|
943
|
+
private getBlueBundlesV1QuoteTimestamp;
|
|
944
|
+
private getTokenRequirements;
|
|
945
|
+
private getAuthorizationRequirements;
|
|
521
946
|
getMarketData(parameters?: FetchParameters): Promise<Market>;
|
|
522
947
|
getPositionData(userAddress: Address, parameters?: FetchParameters): Promise<AccrualPosition>;
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
948
|
+
/** {@inheritDoc BlueActions.supply} */
|
|
949
|
+
supply(params: {
|
|
950
|
+
readonly userAddress: Address;
|
|
951
|
+
readonly assets: bigint;
|
|
952
|
+
readonly nativeAmount?: bigint;
|
|
953
|
+
readonly deadline: bigint;
|
|
954
|
+
readonly referralFeePct?: bigint;
|
|
955
|
+
readonly referralFeeRecipient?: Address;
|
|
956
|
+
}): {
|
|
957
|
+
getRequirements: (requirementsParams?: BlueTokenRequirementsParams) => Promise<readonly ActionRequirement[]>;
|
|
958
|
+
buildTx: (signatures?: readonly RequirementSignature[]) => Readonly<import("../../index.js").Transaction<BlueSupplyAction>>;
|
|
532
959
|
};
|
|
960
|
+
/** {@inheritDoc BlueActions.withdraw} */
|
|
533
961
|
withdraw(params: {
|
|
534
|
-
userAddress: Address;
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
962
|
+
readonly userAddress: Address;
|
|
963
|
+
readonly positionData: AccrualPosition;
|
|
964
|
+
readonly reallocations?: Iterable<VaultV2BlueReallocation>;
|
|
965
|
+
readonly deadline: bigint;
|
|
966
|
+
readonly referralFeePct?: bigint;
|
|
967
|
+
readonly referralFeeRecipient?: Address;
|
|
539
968
|
} & AssetsOrSharesArgs): {
|
|
540
|
-
getRequirements: () => Promise<
|
|
541
|
-
buildTx: (signatures?: readonly RequirementSignature[]) => Readonly<Transaction<BlueWithdrawAction>>;
|
|
542
|
-
};
|
|
543
|
-
supplyCollateral({ amount, userAddress, nativeAmount, }: {
|
|
544
|
-
userAddress: Address;
|
|
545
|
-
} & DepositAmountArgs): {
|
|
546
|
-
getRequirements: (params?: {
|
|
547
|
-
useSimplePermit?: boolean;
|
|
548
|
-
}) => Promise<(import("../../index.js").Bundler3TokenSignatureRequirement | Readonly<Transaction<ERC20ApprovalAction>>)[]>;
|
|
549
|
-
buildTx: (signatures?: readonly RequirementSignature[]) => Readonly<Transaction<BlueSupplyCollateralAction>>;
|
|
550
|
-
};
|
|
551
|
-
borrow({ amount, userAddress, positionData, slippageTolerance, reallocations, }: {
|
|
552
|
-
amount: bigint;
|
|
553
|
-
userAddress: Address;
|
|
554
|
-
positionData: AccrualPosition;
|
|
555
|
-
slippageTolerance?: bigint;
|
|
556
|
-
reallocations?: BlueReallocationPlan;
|
|
557
|
-
}): {
|
|
558
|
-
getRequirements: () => Promise<(import("../../index.js").Bundler3TokenSignatureRequirement | Readonly<Transaction<BlueAuthorizationAction>> | Readonly<Transaction<ERC20ApprovalAction>> | Requirement<import("../../index.js").AuthorizationRequirementSignature, undefined>)[]>;
|
|
559
|
-
buildTx: (signatures?: readonly RequirementSignature[]) => Readonly<Transaction<BlueBorrowAction>>;
|
|
969
|
+
getRequirements: () => Promise<readonly ActionRequirement[]>;
|
|
970
|
+
buildTx: (signatures?: readonly RequirementSignature[]) => Readonly<import("../../index.js").Transaction<BlueWithdrawAction>>;
|
|
560
971
|
};
|
|
972
|
+
/** {@inheritDoc BlueActions.supplyCollateral} */
|
|
973
|
+
supplyCollateral(params: {
|
|
974
|
+
readonly userAddress: Address;
|
|
975
|
+
readonly collateralAssets: bigint;
|
|
976
|
+
readonly nativeAmount?: bigint;
|
|
977
|
+
readonly deadline: bigint;
|
|
978
|
+
readonly referralFeePct?: bigint;
|
|
979
|
+
readonly referralFeeRecipient?: Address;
|
|
980
|
+
}): ActionOutput<BlueSupplyCollateralAction, readonly RequirementSignature[], BlueTokenRequirementsParams>;
|
|
981
|
+
/** {@inheritDoc BlueActions.borrow} */
|
|
982
|
+
borrow(params: {
|
|
983
|
+
readonly userAddress: Address;
|
|
984
|
+
readonly borrowAssets: bigint;
|
|
985
|
+
readonly positionData: AccrualPosition;
|
|
986
|
+
readonly reallocations?: Iterable<VaultV2BlueReallocation>;
|
|
987
|
+
readonly deadline: bigint;
|
|
988
|
+
readonly referralFeePct?: bigint;
|
|
989
|
+
readonly referralFeeRecipient?: Address;
|
|
990
|
+
}): ActionOutput<BlueBorrowAction, readonly RequirementSignature[], undefined>;
|
|
991
|
+
/** {@inheritDoc BlueActions.repay} */
|
|
561
992
|
repay(params: {
|
|
562
|
-
userAddress: Address;
|
|
563
|
-
positionData: AccrualPosition;
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
}
|
|
576
|
-
|
|
577
|
-
|
|
993
|
+
readonly userAddress: Address;
|
|
994
|
+
readonly positionData: AccrualPosition;
|
|
995
|
+
readonly nativeAmount?: bigint;
|
|
996
|
+
readonly deadline: bigint;
|
|
997
|
+
readonly referralFeePct?: bigint;
|
|
998
|
+
readonly referralFeeRecipient?: Address;
|
|
999
|
+
} & ({
|
|
1000
|
+
readonly repayAssets: bigint;
|
|
1001
|
+
readonly repayShares?: never;
|
|
1002
|
+
} | {
|
|
1003
|
+
readonly repayShares: bigint;
|
|
1004
|
+
readonly repayAssets?: never;
|
|
1005
|
+
})): ActionOutput<BlueRepayAction, readonly RequirementSignature[], BlueTokenRequirementsParams>;
|
|
1006
|
+
/** {@inheritDoc BlueActions.withdrawCollateral} */
|
|
1007
|
+
withdrawCollateral(params: {
|
|
1008
|
+
readonly userAddress: Address;
|
|
1009
|
+
readonly positionData: AccrualPosition;
|
|
1010
|
+
readonly collateralAssets: bigint;
|
|
1011
|
+
readonly deadline: bigint;
|
|
1012
|
+
readonly referralFeePct?: bigint;
|
|
1013
|
+
readonly referralFeeRecipient?: Address;
|
|
1014
|
+
}): ActionOutput<BlueWithdrawCollateralAction, readonly RequirementSignature[], undefined>;
|
|
1015
|
+
/** {@inheritDoc BlueActions.repayWithdrawCollateral} */
|
|
578
1016
|
repayWithdrawCollateral(params: {
|
|
579
|
-
userAddress: Address;
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
1017
|
+
readonly userAddress: Address;
|
|
1018
|
+
readonly positionData: AccrualPosition;
|
|
1019
|
+
readonly collateralAssets: bigint;
|
|
1020
|
+
readonly nativeAmount?: bigint;
|
|
1021
|
+
readonly deadline: bigint;
|
|
1022
|
+
readonly referralFeePct?: bigint;
|
|
1023
|
+
readonly referralFeeRecipient?: Address;
|
|
1024
|
+
} & ({
|
|
1025
|
+
readonly repayAssets: bigint;
|
|
1026
|
+
readonly repayShares?: never;
|
|
1027
|
+
} | {
|
|
1028
|
+
readonly repayShares: bigint;
|
|
1029
|
+
readonly repayAssets?: never;
|
|
1030
|
+
} | {
|
|
1031
|
+
readonly repayAssets?: undefined;
|
|
1032
|
+
readonly repayShares?: undefined;
|
|
1033
|
+
})): {
|
|
1034
|
+
getRequirements: (requirementsParams?: BlueTokenRequirementsParams) => Promise<readonly ActionRequirement[]>;
|
|
1035
|
+
buildTx: (signatures?: readonly RequirementSignature[]) => Readonly<import("../../index.js").Transaction<BlueRepayWithdrawCollateralAction>>;
|
|
588
1036
|
};
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
1037
|
+
/** {@inheritDoc BlueActions.supplyCollateralBorrow} */
|
|
1038
|
+
supplyCollateralBorrow(params: {
|
|
1039
|
+
readonly userAddress: Address;
|
|
1040
|
+
readonly collateralAssets: bigint;
|
|
1041
|
+
readonly borrowAssets: bigint;
|
|
1042
|
+
readonly positionData?: AccrualPosition;
|
|
1043
|
+
readonly nativeAmount?: bigint;
|
|
1044
|
+
readonly reallocations?: Iterable<VaultV2BlueReallocation>;
|
|
1045
|
+
readonly deadline: bigint;
|
|
1046
|
+
readonly referralFeePct?: bigint;
|
|
1047
|
+
readonly referralFeeRecipient?: Address;
|
|
1048
|
+
}): {
|
|
1049
|
+
getRequirements: (requirementsParams?: BlueTokenRequirementsParams) => Promise<readonly ActionRequirement[]>;
|
|
1050
|
+
buildTx: (signatures?: readonly RequirementSignature[]) => Readonly<import("../../index.js").Transaction<BlueSupplyCollateralBorrowAction>>;
|
|
600
1051
|
};
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
1052
|
+
/** {@inheritDoc BlueActions.refinance} */
|
|
1053
|
+
refinance(params: {
|
|
1054
|
+
readonly userAddress: Address;
|
|
1055
|
+
readonly positionData: AccrualPosition;
|
|
1056
|
+
readonly destination: {
|
|
1057
|
+
readonly marketParams: MarketParams;
|
|
1058
|
+
readonly positionData: AccrualPosition;
|
|
607
1059
|
};
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
targetReallocations?: BlueReallocationPlan;
|
|
1060
|
+
readonly reallocations?: Iterable<VaultV2BlueReallocation>;
|
|
1061
|
+
readonly deadline: bigint;
|
|
1062
|
+
readonly referralFeePct?: bigint;
|
|
1063
|
+
readonly referralFeeRecipient?: Address;
|
|
613
1064
|
}): {
|
|
614
|
-
getRequirements: () => Promise<
|
|
615
|
-
buildTx: (signatures?: readonly RequirementSignature[]) => Readonly<Transaction<BlueRefinanceAction>>;
|
|
1065
|
+
getRequirements: () => Promise<readonly ActionRequirement[]>;
|
|
1066
|
+
buildTx: (signatures?: readonly RequirementSignature[]) => Readonly<import("../../index.js").Transaction<BlueRefinanceAction>>;
|
|
616
1067
|
};
|
|
617
1068
|
/**
|
|
618
1069
|
* Fetches all on-chain inputs needed to compute public allocator reallocations.
|
|
@@ -622,6 +1073,8 @@ export declare class MorphoBlue implements BlueActions {
|
|
|
622
1073
|
* @param params.block.timestamp - Timestamp corresponding to the fetched block.
|
|
623
1074
|
* @returns Reallocation data ready for {@link getVaultV1Reallocations}.
|
|
624
1075
|
* @throws {ChainIdMismatchError} when the client chain does not match this market.
|
|
1076
|
+
* @deprecated Vault V1 shared-liquidity planning will be removed in the next major. Use
|
|
1077
|
+
* {@link getVaultV2BlueReallocationData}.
|
|
625
1078
|
* @example
|
|
626
1079
|
* ```ts
|
|
627
1080
|
* import { markets, vaults } from "@morpho-org/morpho-test";
|
|
@@ -655,7 +1108,8 @@ export declare class MorphoBlue implements BlueActions {
|
|
|
655
1108
|
* @param params.block.timestamp - Timestamp corresponding to the fetched block.
|
|
656
1109
|
* @returns A `VaultV1ReallocationData` snapshot populated from one block.
|
|
657
1110
|
* @throws {ChainIdMismatchError} when the client chain does not match this market.
|
|
658
|
-
* @deprecated
|
|
1111
|
+
* @deprecated Vault V1 shared-liquidity planning will be removed in the next major. Use
|
|
1112
|
+
* {@link getVaultV2BlueReallocationData}.
|
|
659
1113
|
* @example
|
|
660
1114
|
* ```ts
|
|
661
1115
|
* const data = await market.getReallocationData({ vaultAddresses, block });
|
|
@@ -725,12 +1179,14 @@ export declare class MorphoBlue implements BlueActions {
|
|
|
725
1179
|
* @param params.amount - The borrow or withdraw amount used to compute the post-state utilization.
|
|
726
1180
|
* @param params.borrowAmount - {@deprecated Pass `{ operation: "borrow", amount }` instead.}
|
|
727
1181
|
* @param params.options - Optional allocator and utilization options.
|
|
728
|
-
* @returns Vault reallocations
|
|
1182
|
+
* @returns Vault V1 reallocations for explicit low-level Bundler3 composition.
|
|
729
1183
|
* @throws {ChainIdMismatchError} when `reallocationData` belongs to a different chain than this market.
|
|
730
1184
|
* @throws {InsufficientSharedLiquidityError} when shared liquidity cannot cover the operation's absolute shortfall on the target market.
|
|
731
1185
|
* @throws {ReallocationWithdrawExceedsMarketSupplyError} when `operation === "withdraw"` and `amount` exceeds the target market's `totalSupplyAssets`.
|
|
732
1186
|
* @throws {MissingPublicAllocatorConfigError} when a selected vault is missing its public allocator config.
|
|
733
1187
|
* @throws {UnknownReallocationMarketError} when the target market is absent from the reallocation data.
|
|
1188
|
+
* @deprecated Vault V1 shared-liquidity planning will be removed in the next major. Use
|
|
1189
|
+
* {@link getVaultV2BlueReallocations}.
|
|
734
1190
|
* @example
|
|
735
1191
|
* ```ts
|
|
736
1192
|
* const reallocations = market.getVaultV1Reallocations({
|
|
@@ -749,13 +1205,14 @@ export declare class MorphoBlue implements BlueActions {
|
|
|
749
1205
|
* @param params.amount - The borrow or withdraw amount used to compute post-state utilization.
|
|
750
1206
|
* @param params.borrowAmount - Deprecated borrow amount alias.
|
|
751
1207
|
* @param params.options - Optional allocator and utilization options.
|
|
752
|
-
* @returns Vault V1 reallocations
|
|
1208
|
+
* @returns Vault V1 reallocations for explicit low-level Bundler3 composition.
|
|
753
1209
|
* @throws {ChainIdMismatchError} when `reallocationData` belongs to another chain.
|
|
754
1210
|
* @throws {InsufficientSharedLiquidityError} when shared liquidity cannot cover the operation.
|
|
755
1211
|
* @throws {ReallocationWithdrawExceedsMarketSupplyError} when a withdrawal exceeds market supply.
|
|
756
1212
|
* @throws {MissingPublicAllocatorConfigError} when a selected vault lacks allocator state.
|
|
757
1213
|
* @throws {UnknownReallocationMarketError} when the target market is absent.
|
|
758
|
-
* @deprecated
|
|
1214
|
+
* @deprecated Vault V1 shared-liquidity planning will be removed in the next major. Use
|
|
1215
|
+
* {@link getVaultV2BlueReallocations}.
|
|
759
1216
|
* @example
|
|
760
1217
|
* ```ts
|
|
761
1218
|
* const reallocations = market.getReallocations({
|