@morpho-org/morpho-sdk 5.9.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 +58 -40
- package/lib/cjs/actions/blue/borrow.d.ts +62 -61
- 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 -112
- package/lib/cjs/actions/blue/refinance.js +97 -199
- 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 -90
- package/lib/cjs/actions/blue/supplyCollateralBorrow.js +133 -120
- package/lib/cjs/actions/blue/withdraw.d.ts +68 -79
- 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/bundler/actions.d.ts +4 -4
- package/lib/cjs/bundler/actions.js +4 -4
- 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 +806 -374
- package/lib/cjs/entities/blue/blue.js +447 -696
- package/lib/cjs/entities/index.d.ts +1 -0
- package/lib/cjs/helpers/computeVaultV1Reallocations.d.ts +3 -9
- package/lib/cjs/helpers/computeVaultV1Reallocations.js +3 -9
- package/lib/cjs/helpers/validate.d.ts +14 -23
- package/lib/cjs/helpers/validate.js +30 -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 +141 -14
- package/lib/cjs/types/error.js +198 -21
- package/lib/cjs/types/sharedLiquidity.d.ts +0 -7
- package/lib/esm/actions/blue/borrow.d.ts +62 -61
- 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 -112
- package/lib/esm/actions/blue/refinance.js +98 -200
- 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 -90
- package/lib/esm/actions/blue/supplyCollateralBorrow.js +134 -121
- package/lib/esm/actions/blue/withdraw.d.ts +68 -79
- 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/bundler/actions.d.ts +4 -4
- package/lib/esm/bundler/actions.js +4 -4
- 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 +806 -374
- package/lib/esm/entities/blue/blue.js +453 -702
- package/lib/esm/entities/index.d.ts +1 -0
- package/lib/esm/helpers/computeVaultV1Reallocations.d.ts +3 -9
- package/lib/esm/helpers/computeVaultV1Reallocations.js +3 -9
- package/lib/esm/helpers/validate.d.ts +14 -23
- package/lib/esm/helpers/validate.js +30 -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 +141 -14
- package/lib/esm/types/error.js +184 -17
- package/lib/esm/types/sharedLiquidity.d.ts +0 -7
- package/package.json +4 -3
- 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,325 +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.
|
|
63
|
+
*
|
|
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";
|
|
51
98
|
*
|
|
52
|
-
*
|
|
53
|
-
*
|
|
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
|
-
*
|
|
101
|
-
* -
|
|
102
|
-
*
|
|
103
|
-
*
|
|
104
|
-
*
|
|
105
|
-
*
|
|
106
|
-
*
|
|
107
|
-
*
|
|
108
|
-
*
|
|
109
|
-
*
|
|
110
|
-
*
|
|
111
|
-
*
|
|
112
|
-
*
|
|
113
|
-
*
|
|
114
|
-
*
|
|
115
|
-
*
|
|
116
|
-
*
|
|
117
|
-
*
|
|
118
|
-
* @
|
|
119
|
-
* @
|
|
120
|
-
* @throws {
|
|
121
|
-
* @throws {
|
|
122
|
-
* @throws {
|
|
123
|
-
* @throws {
|
|
124
|
-
* @throws {
|
|
125
|
-
* @throws {
|
|
126
|
-
* @throws {
|
|
187
|
+
* Prepares a direct BlueBundlesV1 loan-asset withdrawal by assets or shares.
|
|
188
|
+
*
|
|
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`.
|
|
193
|
+
*
|
|
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";
|
|
235
|
+
*
|
|
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
|
+
* ```
|
|
127
254
|
*/
|
|
128
255
|
withdraw: (params: {
|
|
129
|
-
userAddress: Address;
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
} & AssetsOrSharesArgs) =>
|
|
136
|
-
buildTx: (signatures?: readonly RequirementSignature[]) => Readonly<Transaction<BlueWithdrawAction>>;
|
|
137
|
-
getRequirements: () => Promise<(Readonly<Transaction<ERC20ApprovalAction>> | Readonly<Transaction<BlueAuthorizationAction>> | Requirement)[]>;
|
|
138
|
-
};
|
|
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>;
|
|
139
263
|
/**
|
|
140
|
-
* Prepares a borrow
|
|
141
|
-
*
|
|
142
|
-
*
|
|
143
|
-
*
|
|
144
|
-
*
|
|
145
|
-
*
|
|
146
|
-
*
|
|
147
|
-
*
|
|
148
|
-
*
|
|
149
|
-
*
|
|
150
|
-
*
|
|
151
|
-
*
|
|
152
|
-
*
|
|
153
|
-
*
|
|
154
|
-
*
|
|
155
|
-
*
|
|
156
|
-
*
|
|
157
|
-
* @
|
|
158
|
-
* @
|
|
159
|
-
* @throws {
|
|
160
|
-
* @throws {
|
|
161
|
-
* @throws {
|
|
162
|
-
* @throws {
|
|
163
|
-
* @throws {
|
|
164
|
-
* @throws {
|
|
165
|
-
* @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
|
+
* ```
|
|
166
327
|
*/
|
|
167
328
|
borrow: (params: {
|
|
168
|
-
userAddress: Address;
|
|
169
|
-
|
|
170
|
-
positionData: AccrualPosition;
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
getRequirements: () => Promise<(Readonly<Transaction<ERC20ApprovalAction>> | Readonly<Transaction<BlueAuthorizationAction>> | Requirement)[]>;
|
|
177
|
-
};
|
|
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>;
|
|
178
337
|
/**
|
|
179
|
-
* Prepares a
|
|
180
|
-
*
|
|
181
|
-
* Routed through bundler3 via GeneralAdapter1.
|
|
182
|
-
* Supports two modes via {@link RepayAmountArgs}:
|
|
183
|
-
* - **By assets** (`{ amount }`): repays an exact asset amount (partial repay).
|
|
184
|
-
* - **By shares** (`{ shares }`): repays exact shares (full repay, immune to interest accrual).
|
|
338
|
+
* Prepares a direct BlueBundlesV1 loan-asset repayment.
|
|
185
339
|
*
|
|
186
|
-
*
|
|
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.
|
|
187
343
|
*
|
|
188
|
-
*
|
|
189
|
-
*
|
|
190
|
-
*
|
|
191
|
-
*
|
|
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";
|
|
192
388
|
*
|
|
193
|
-
*
|
|
194
|
-
*
|
|
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
|
+
* ```
|
|
195
406
|
*/
|
|
196
407
|
repay: (params: {
|
|
197
|
-
userAddress: Address;
|
|
198
|
-
positionData: AccrualPosition;
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
};
|
|
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>;
|
|
211
421
|
/**
|
|
212
|
-
* Prepares a
|
|
422
|
+
* Prepares a direct BlueBundlesV1 collateral withdrawal.
|
|
213
423
|
*
|
|
214
|
-
*
|
|
215
|
-
*
|
|
216
|
-
*
|
|
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.
|
|
217
427
|
*
|
|
218
|
-
*
|
|
219
|
-
*
|
|
220
|
-
*
|
|
221
|
-
*
|
|
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";
|
|
222
461
|
*
|
|
223
|
-
*
|
|
224
|
-
*
|
|
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
|
+
* ```
|
|
225
479
|
*/
|
|
226
480
|
withdrawCollateral: (params: {
|
|
227
|
-
userAddress: Address;
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
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>;
|
|
233
488
|
/**
|
|
234
|
-
* Prepares
|
|
235
|
-
*
|
|
236
|
-
* Routed through bundler3. Bundle order: repay FIRST, then withdraw.
|
|
237
|
-
* Validates combined position health: simulates the repay, then checks
|
|
238
|
-
* that the resulting position can sustain the collateral withdrawal.
|
|
489
|
+
* Prepares a direct BlueBundlesV1 repay, collateral withdrawal, or atomic combination.
|
|
239
490
|
*
|
|
240
|
-
* `
|
|
241
|
-
*
|
|
242
|
-
*
|
|
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.
|
|
243
500
|
*
|
|
244
|
-
*
|
|
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";
|
|
245
549
|
*
|
|
246
|
-
*
|
|
247
|
-
*
|
|
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
|
+
* ```
|
|
248
569
|
*/
|
|
249
570
|
repayWithdrawCollateral: (params: {
|
|
250
|
-
userAddress: Address;
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
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>;
|
|
265
588
|
/**
|
|
266
|
-
* Prepares
|
|
267
|
-
*
|
|
268
|
-
*
|
|
269
|
-
*
|
|
270
|
-
*
|
|
271
|
-
*
|
|
272
|
-
*
|
|
273
|
-
*
|
|
274
|
-
*
|
|
275
|
-
*
|
|
276
|
-
*
|
|
277
|
-
* `
|
|
278
|
-
*
|
|
279
|
-
* -
|
|
280
|
-
*
|
|
281
|
-
*
|
|
282
|
-
*
|
|
283
|
-
*
|
|
284
|
-
* @
|
|
285
|
-
* @
|
|
286
|
-
* @throws {
|
|
287
|
-
* @throws {
|
|
288
|
-
* @throws {
|
|
289
|
-
* @throws {
|
|
290
|
-
* @throws {
|
|
291
|
-
* @throws {
|
|
292
|
-
* @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
|
+
* ```
|
|
293
663
|
*/
|
|
294
664
|
supplyCollateralBorrow: (params: {
|
|
295
|
-
userAddress: Address;
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
reallocations?:
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
* Prefer the ERC-2612 simple-permit path when the SDK detects support.
|
|
306
|
-
* Leave unset or set to `false` to force the Permit2/classic approval fallback when
|
|
307
|
-
* a token is known to be incompatible despite passing the SDK's shallow nonce probe.
|
|
308
|
-
*/
|
|
309
|
-
useSimplePermit?: boolean;
|
|
310
|
-
}) => Promise<(Readonly<Transaction<ERC20ApprovalAction>> | Readonly<Transaction<BlueAuthorizationAction>> | Requirement)[]>;
|
|
311
|
-
};
|
|
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>;
|
|
312
675
|
/**
|
|
313
|
-
* Prepares
|
|
314
|
-
*
|
|
315
|
-
*
|
|
316
|
-
*
|
|
317
|
-
* both
|
|
318
|
-
*
|
|
319
|
-
*
|
|
320
|
-
*
|
|
321
|
-
* to
|
|
322
|
-
*
|
|
323
|
-
*
|
|
324
|
-
*
|
|
325
|
-
*
|
|
326
|
-
*
|
|
327
|
-
*
|
|
328
|
-
*
|
|
329
|
-
* @param params.
|
|
330
|
-
* @param params.
|
|
331
|
-
* @
|
|
332
|
-
* @
|
|
333
|
-
* @
|
|
334
|
-
* @
|
|
335
|
-
* @
|
|
336
|
-
* @
|
|
337
|
-
* @
|
|
338
|
-
*
|
|
339
|
-
* @
|
|
340
|
-
* @throws {
|
|
341
|
-
* @throws {
|
|
342
|
-
* @throws {
|
|
343
|
-
* @throws {
|
|
344
|
-
* @throws {
|
|
345
|
-
* @throws {
|
|
346
|
-
* @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
|
+
* ```
|
|
347
754
|
*/
|
|
348
755
|
refinance: (params: {
|
|
349
|
-
userAddress: Address;
|
|
350
|
-
positionData: AccrualPosition;
|
|
351
|
-
|
|
352
|
-
marketParams: MarketParams;
|
|
353
|
-
positionData: AccrualPosition;
|
|
756
|
+
readonly userAddress: Address;
|
|
757
|
+
readonly positionData: AccrualPosition;
|
|
758
|
+
readonly destination: {
|
|
759
|
+
readonly marketParams: MarketParams;
|
|
760
|
+
readonly positionData: AccrualPosition;
|
|
354
761
|
};
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
targetReallocations?: BlueReallocationPlan;
|
|
361
|
-
}) => {
|
|
362
|
-
buildTx: (signatures?: readonly RequirementSignature[]) => Readonly<Transaction<BlueRefinanceAction>>;
|
|
363
|
-
getRequirements: () => Promise<(Readonly<Transaction<ERC20ApprovalAction>> | Readonly<Transaction<BlueAuthorizationAction>> | Requirement)[]>;
|
|
364
|
-
};
|
|
762
|
+
readonly reallocations?: Iterable<VaultV2BlueReallocation>;
|
|
763
|
+
readonly deadline: bigint;
|
|
764
|
+
readonly referralFeePct?: bigint;
|
|
765
|
+
readonly referralFeeRecipient?: Address;
|
|
766
|
+
}) => ActionOutput<BlueRefinanceAction, readonly RequirementSignature[], undefined>;
|
|
365
767
|
/**
|
|
366
768
|
* Fetches all on-chain data needed to construct a {@link VaultV1ReallocationData}
|
|
367
769
|
* for computing vault reallocations via the public allocator.
|
|
@@ -372,9 +774,8 @@ export interface BlueActions {
|
|
|
372
774
|
* inject unnecessary `reallocateTo` actions (and their PublicAllocator
|
|
373
775
|
* fees) into the resulting bundle.
|
|
374
776
|
*
|
|
375
|
-
* The returned
|
|
376
|
-
*
|
|
377
|
-
* `supplyCollateralBorrow()`.
|
|
777
|
+
* The returned data can be passed to {@link getVaultV1Reallocations} for explicit low-level
|
|
778
|
+
* Bundler3 composition.
|
|
378
779
|
*
|
|
379
780
|
* **Stale data reverts on-chain (fail-safe).**
|
|
380
781
|
*
|
|
@@ -400,8 +801,9 @@ export interface BlueActions {
|
|
|
400
801
|
* @param params.block.timestamp - Timestamp corresponding to the fetched block.
|
|
401
802
|
* @returns A `VaultV1ReallocationData` snapshot populated from one block.
|
|
402
803
|
* @throws {ChainIdMismatchError} when the client chain does not match this market.
|
|
403
|
-
* @deprecated
|
|
404
|
-
*
|
|
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.
|
|
405
807
|
*/
|
|
406
808
|
getReallocationData: (params: {
|
|
407
809
|
vaultAddresses: readonly Address[];
|
|
@@ -453,8 +855,7 @@ export interface BlueActions {
|
|
|
453
855
|
* @param params.options - Optional reallocation computation options
|
|
454
856
|
* (timestamp, utilization targets, reallocatable vaults filter, etc.).
|
|
455
857
|
* Pass the fetched block timestamp to compute reallocations at the same block.
|
|
456
|
-
* @returns
|
|
457
|
-
* or `withdraw()`. Empty array if no reallocation is needed.
|
|
858
|
+
* @returns Vault V1 reallocations for explicit low-level Bundler3 composition.
|
|
458
859
|
* @throws {ChainIdMismatchError} when `reallocationData` belongs to a different chain than this market.
|
|
459
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.
|
|
460
861
|
* @throws {ReallocationWithdrawExceedsMarketSupplyError} when a withdrawal exceeds the target market supply.
|
|
@@ -480,7 +881,7 @@ export interface BlueActions {
|
|
|
480
881
|
* @param params.amount - The borrow or withdraw amount used to compute post-state utilization.
|
|
481
882
|
* @param params.borrowAmount - Deprecated borrow amount alias.
|
|
482
883
|
* @param params.options - Optional allocator and utilization options.
|
|
483
|
-
* @returns Vault V1 reallocations
|
|
884
|
+
* @returns Vault V1 reallocations for explicit low-level Bundler3 composition.
|
|
484
885
|
* @throws {ChainIdMismatchError} when `reallocationData` belongs to another chain.
|
|
485
886
|
* @throws {InsufficientSharedLiquidityError} when shared liquidity cannot cover the operation.
|
|
486
887
|
* @throws {ReallocationWithdrawExceedsMarketSupplyError} when a withdrawal exceeds market supply.
|
|
@@ -536,102 +937,133 @@ export declare class MorphoBlue implements BlueActions {
|
|
|
536
937
|
readonly marketParams: MarketParams;
|
|
537
938
|
private readonly chainId;
|
|
538
939
|
constructor(client: MorphoClientType, marketParams: MarketParams, chainId: number);
|
|
539
|
-
private
|
|
940
|
+
private validateDeadline;
|
|
941
|
+
private validateWriteCommon;
|
|
942
|
+
private getMaxLtv;
|
|
943
|
+
private getBlueBundlesV1QuoteTimestamp;
|
|
944
|
+
private getTokenRequirements;
|
|
945
|
+
private getAuthorizationRequirements;
|
|
540
946
|
getMarketData(parameters?: FetchParameters): Promise<Market>;
|
|
541
947
|
getPositionData(userAddress: Address, parameters?: FetchParameters): Promise<AccrualPosition>;
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
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("../../types/action.js").Transaction<BlueSupplyAction>>;
|
|
551
959
|
};
|
|
960
|
+
/** {@inheritDoc BlueActions.withdraw} */
|
|
552
961
|
withdraw(params: {
|
|
553
|
-
userAddress: Address;
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
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;
|
|
558
968
|
} & AssetsOrSharesArgs): {
|
|
559
|
-
getRequirements: () => Promise<
|
|
560
|
-
buildTx: (signatures?: readonly RequirementSignature[]) => Readonly<Transaction<BlueWithdrawAction>>;
|
|
561
|
-
};
|
|
562
|
-
supplyCollateral({ amount, userAddress, nativeAmount, }: {
|
|
563
|
-
userAddress: Address;
|
|
564
|
-
} & DepositAmountArgs): {
|
|
565
|
-
getRequirements: (params?: {
|
|
566
|
-
useSimplePermit?: boolean;
|
|
567
|
-
}) => Promise<(import("../../types/action.js").Bundler3TokenSignatureRequirement | Readonly<Transaction<ERC20ApprovalAction>>)[]>;
|
|
568
|
-
buildTx: (signatures?: readonly RequirementSignature[]) => Readonly<Transaction<BlueSupplyCollateralAction>>;
|
|
569
|
-
};
|
|
570
|
-
borrow({ amount, userAddress, positionData, slippageTolerance, reallocations, }: {
|
|
571
|
-
amount: bigint;
|
|
572
|
-
userAddress: Address;
|
|
573
|
-
positionData: AccrualPosition;
|
|
574
|
-
slippageTolerance?: bigint;
|
|
575
|
-
reallocations?: BlueReallocationPlan;
|
|
576
|
-
}): {
|
|
577
|
-
getRequirements: () => Promise<(import("../../types/action.js").Bundler3TokenSignatureRequirement | Readonly<Transaction<BlueAuthorizationAction>> | Readonly<Transaction<ERC20ApprovalAction>> | Requirement<import("../../types/action.js").AuthorizationRequirementSignature, undefined>)[]>;
|
|
578
|
-
buildTx: (signatures?: readonly RequirementSignature[]) => Readonly<Transaction<BlueBorrowAction>>;
|
|
969
|
+
getRequirements: () => Promise<readonly ActionRequirement[]>;
|
|
970
|
+
buildTx: (signatures?: readonly RequirementSignature[]) => Readonly<import("../../types/action.js").Transaction<BlueWithdrawAction>>;
|
|
579
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} */
|
|
580
992
|
repay(params: {
|
|
581
|
-
userAddress: Address;
|
|
582
|
-
positionData: AccrualPosition;
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
}
|
|
595
|
-
|
|
596
|
-
|
|
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} */
|
|
597
1016
|
repayWithdrawCollateral(params: {
|
|
598
|
-
userAddress: Address;
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
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("../../types/action.js").Transaction<BlueRepayWithdrawCollateralAction>>;
|
|
607
1036
|
};
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
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("../../types/action.js").Transaction<BlueSupplyCollateralBorrowAction>>;
|
|
619
1051
|
};
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
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;
|
|
626
1059
|
};
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
targetReallocations?: BlueReallocationPlan;
|
|
1060
|
+
readonly reallocations?: Iterable<VaultV2BlueReallocation>;
|
|
1061
|
+
readonly deadline: bigint;
|
|
1062
|
+
readonly referralFeePct?: bigint;
|
|
1063
|
+
readonly referralFeeRecipient?: Address;
|
|
632
1064
|
}): {
|
|
633
|
-
getRequirements: () => Promise<
|
|
634
|
-
buildTx: (signatures?: readonly RequirementSignature[]) => Readonly<Transaction<BlueRefinanceAction>>;
|
|
1065
|
+
getRequirements: () => Promise<readonly ActionRequirement[]>;
|
|
1066
|
+
buildTx: (signatures?: readonly RequirementSignature[]) => Readonly<import("../../types/action.js").Transaction<BlueRefinanceAction>>;
|
|
635
1067
|
};
|
|
636
1068
|
/**
|
|
637
1069
|
* Fetches all on-chain inputs needed to compute public allocator reallocations.
|
|
@@ -747,7 +1179,7 @@ export declare class MorphoBlue implements BlueActions {
|
|
|
747
1179
|
* @param params.amount - The borrow or withdraw amount used to compute the post-state utilization.
|
|
748
1180
|
* @param params.borrowAmount - {@deprecated Pass `{ operation: "borrow", amount }` instead.}
|
|
749
1181
|
* @param params.options - Optional allocator and utilization options.
|
|
750
|
-
* @returns Vault reallocations
|
|
1182
|
+
* @returns Vault V1 reallocations for explicit low-level Bundler3 composition.
|
|
751
1183
|
* @throws {ChainIdMismatchError} when `reallocationData` belongs to a different chain than this market.
|
|
752
1184
|
* @throws {InsufficientSharedLiquidityError} when shared liquidity cannot cover the operation's absolute shortfall on the target market.
|
|
753
1185
|
* @throws {ReallocationWithdrawExceedsMarketSupplyError} when `operation === "withdraw"` and `amount` exceeds the target market's `totalSupplyAssets`.
|
|
@@ -773,7 +1205,7 @@ export declare class MorphoBlue implements BlueActions {
|
|
|
773
1205
|
* @param params.amount - The borrow or withdraw amount used to compute post-state utilization.
|
|
774
1206
|
* @param params.borrowAmount - Deprecated borrow amount alias.
|
|
775
1207
|
* @param params.options - Optional allocator and utilization options.
|
|
776
|
-
* @returns Vault V1 reallocations
|
|
1208
|
+
* @returns Vault V1 reallocations for explicit low-level Bundler3 composition.
|
|
777
1209
|
* @throws {ChainIdMismatchError} when `reallocationData` belongs to another chain.
|
|
778
1210
|
* @throws {InsufficientSharedLiquidityError} when shared liquidity cannot cover the operation.
|
|
779
1211
|
* @throws {ReallocationWithdrawExceedsMarketSupplyError} when a withdrawal exceeds market supply.
|