@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,137 +1,75 @@
|
|
|
1
|
-
import { getChainAddresses } from "@morpho-org/blue-sdk";
|
|
2
1
|
import { deepFreeze } from "@morpho-org/morpho-ts";
|
|
3
2
|
import { maxUint256 } from "viem";
|
|
4
|
-
import {
|
|
5
|
-
import { addTransactionMetadata } from "../../helpers/index.js";
|
|
6
|
-
import { buildAssetFundingActions } from "./buildAssetFundingActions.js";
|
|
7
|
-
import { resolveRepayFunding } from "./resolveRepayFunding.js";
|
|
3
|
+
import { blueRepayWithdrawCollateral } from "./repayWithdrawCollateral.js";
|
|
8
4
|
/**
|
|
9
|
-
*
|
|
5
|
+
* Encodes a pure repayment through BlueBundlesV1.
|
|
10
6
|
*
|
|
11
|
-
*
|
|
12
|
-
*
|
|
13
|
-
* {@link RepayActionAmountArgs}. The mode is discriminated on `shares`, plus optional native wrapping
|
|
14
|
-
* (when `nativeAmount > 0`, native ETH is wrapped via `GeneralAdapter1.wrapNative()` before the
|
|
15
|
-
* repay; the loan token must be the chain's wNative):
|
|
7
|
+
* Delegates to {@link blueRepayWithdrawCollateral} with a zero collateral-withdrawal leg and an
|
|
8
|
+
* unrestricted LTV cap. BlueBundlesV1 refunds unused `maxRepayAssets` funding.
|
|
16
9
|
*
|
|
17
|
-
*
|
|
18
|
-
*
|
|
19
|
-
*
|
|
20
|
-
*
|
|
21
|
-
*
|
|
22
|
-
*
|
|
23
|
-
*
|
|
24
|
-
*
|
|
25
|
-
* @param params.
|
|
26
|
-
* @param params.
|
|
27
|
-
* @param params.args.
|
|
28
|
-
* @param params.args.
|
|
29
|
-
* @param params.
|
|
30
|
-
*
|
|
31
|
-
*
|
|
32
|
-
*
|
|
33
|
-
* @
|
|
34
|
-
* @
|
|
35
|
-
* @
|
|
36
|
-
*
|
|
37
|
-
* @
|
|
38
|
-
*
|
|
39
|
-
* @
|
|
40
|
-
* @
|
|
41
|
-
*
|
|
42
|
-
* @throws {
|
|
43
|
-
* @throws {
|
|
44
|
-
* @throws {
|
|
45
|
-
* @throws {
|
|
46
|
-
*
|
|
47
|
-
* @throws {
|
|
48
|
-
* @throws {
|
|
49
|
-
* the chain's wNative.
|
|
50
|
-
* @throws {DepositAssetMismatchError} from `getTokenRequirementActions` when `requirementSignature`
|
|
51
|
-
* is provided and the signed asset differs from `marketParams.loanToken`.
|
|
52
|
-
* @throws {DepositAmountMismatchError} from `getTokenRequirementActions` when `requirementSignature`
|
|
53
|
-
* is provided and the signed amount differs from the ERC-20 amount pulled.
|
|
54
|
-
* @throws {Permit2ExpirationMissingError} from `getTokenRequirementActions` when a Permit2 requirement
|
|
55
|
-
* signature is missing its expiration.
|
|
10
|
+
* @param params - Repay encoding parameters.
|
|
11
|
+
* @param params.market.chainId - Chain containing BlueBundlesV1.
|
|
12
|
+
* @param params.market.marketParams - Scoped Morpho Blue market parameters.
|
|
13
|
+
* @param params.args.userAddress - User whose debt is repaid.
|
|
14
|
+
* @param params.args.repayAssets - Exact assets repaid, exclusive with shares.
|
|
15
|
+
* @param params.args.repayShares - Exact shares or `maxUint256` for full repay.
|
|
16
|
+
* @param params.args.maxRepayAssets - Gross repayment and fee funding cap.
|
|
17
|
+
* @param params.args.nativeAmount - Exclusive native repay funding.
|
|
18
|
+
* @param params.args.deadline - Final call deadline in Unix seconds.
|
|
19
|
+
* @param params.args.referralFeePct - Optional WAD-scaled referral fee.
|
|
20
|
+
* @param params.args.referralFeeRecipient - Recipient required for a positive fee.
|
|
21
|
+
* @param params.args.requirementSignature - Optional loan-token signature.
|
|
22
|
+
* @param params.metadata - Optional transaction metadata.
|
|
23
|
+
* @returns A deep-frozen `Readonly<Transaction<BlueRepayAction>>` whose calldata invokes the
|
|
24
|
+
* combined BlueBundlesV1 entrypoint with a zero collateral-withdrawal leg.
|
|
25
|
+
* @throws {NegativeInputError} when an amount or fee is negative.
|
|
26
|
+
* @throws {MutuallyExclusiveRepayAmountsError} when assets and shares are both nonzero.
|
|
27
|
+
* @throws {NonPositiveInputError} when repayment, funding, or deadline is not positive.
|
|
28
|
+
* @throws {MaxRepayAssetsBelowRepayAssetsError} when funding cannot cover repayment and fees.
|
|
29
|
+
* @throws {NativeFundingAmountMismatchError} when native funding is partial or mixed.
|
|
30
|
+
* @throws {ChainWNativeMissingError} when native funding is requested without a registered wNative.
|
|
31
|
+
* @throws {NativeAmountOnNonWNativeAssetError} when native funding targets another loan token.
|
|
32
|
+
* @throws {UnexpectedRequirementSignatureError} when native funding also supplies a token signature.
|
|
33
|
+
* @throws {DepositOwnerMismatchError} when the signed owner differs from `userAddress`.
|
|
34
|
+
* @throws {DepositAssetMismatchError} when the signed asset differs from the loan token.
|
|
35
|
+
* @throws {DepositAmountMismatchError} when the signed amount differs from `maxRepayAssets`.
|
|
36
|
+
* @throws {DepositSpenderMismatchError} when the signed spender is not BlueBundlesV1.
|
|
37
|
+
* @throws {BlueBundlesV1RequirementSignatureMismatchError} when a signature cannot be encoded safely.
|
|
38
|
+
* @throws {InputExceedsMaxError} when the referral fee is at least WAD.
|
|
39
|
+
* @throws {MissingReferralFeeRecipientError} when a positive fee has no recipient.
|
|
40
|
+
* @throws {UnsupportedChainIdError} when the chain is absent from the registry.
|
|
41
|
+
* @throws {UnknownAddressError} when BlueBundlesV1 is not registered.
|
|
56
42
|
* @example
|
|
57
43
|
* ```ts
|
|
44
|
+
* import { markets } from "@morpho-org/morpho-test";
|
|
58
45
|
* import { blueRepay } from "@morpho-org/morpho-sdk";
|
|
46
|
+
* import { zeroAddress } from "viem";
|
|
47
|
+
* import { mainnet } from "viem/chains";
|
|
59
48
|
*
|
|
60
|
-
* // Repay 0.5 loan-asset units, 0.2 of them funded by wrapping native ETH.
|
|
61
49
|
* const tx = blueRepay({
|
|
62
|
-
* market: { chainId:
|
|
50
|
+
* market: { chainId: mainnet.id, marketParams: markets[mainnet.id].usdc_wbtc },
|
|
63
51
|
* args: {
|
|
64
|
-
*
|
|
65
|
-
*
|
|
66
|
-
*
|
|
67
|
-
*
|
|
68
|
-
*
|
|
69
|
-
* maxSharePrice: 1_010_000_000_000_000_000_000_000_000n, // RAY-scaled, 1.01x
|
|
52
|
+
* userAddress: zeroAddress,
|
|
53
|
+
* repayAssets: 1_000_000n,
|
|
54
|
+
* repayShares: 0n,
|
|
55
|
+
* maxRepayAssets: 1_000_000n,
|
|
56
|
+
* deadline: 1_900_000_000n,
|
|
70
57
|
* },
|
|
71
58
|
* });
|
|
72
|
-
* // tx
|
|
59
|
+
* // tx satisfies Readonly<Transaction<BlueRepayAction>>
|
|
73
60
|
* ```
|
|
74
61
|
*/
|
|
75
|
-
export const blueRepay = (
|
|
76
|
-
const
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
nativeAmount,
|
|
84
|
-
requirementSignature,
|
|
85
|
-
});
|
|
86
|
-
actions.push({
|
|
87
|
-
type: "morphoRepay",
|
|
88
|
-
args: [
|
|
89
|
-
marketParams,
|
|
90
|
-
repayAssets,
|
|
91
|
-
repayShares,
|
|
92
|
-
maxSharePrice,
|
|
93
|
-
onBehalf,
|
|
94
|
-
[],
|
|
95
|
-
false,
|
|
96
|
-
],
|
|
62
|
+
export const blueRepay = (params) => {
|
|
63
|
+
const transaction = blueRepayWithdrawCollateral({
|
|
64
|
+
...params,
|
|
65
|
+
args: {
|
|
66
|
+
...params.args,
|
|
67
|
+
collateralAssets: 0n,
|
|
68
|
+
maxLtv: maxUint256,
|
|
69
|
+
},
|
|
97
70
|
});
|
|
98
|
-
// Skim residual loan tokens back to the payer when repaying by shares.
|
|
99
|
-
// In shares mode, transferAmount is an upper-bound estimate; morphoRepay
|
|
100
|
-
// consumes only the exact amount needed, leaving a residual in the adapter.
|
|
101
|
-
if (isSharesMode) {
|
|
102
|
-
actions.push({
|
|
103
|
-
type: "erc20Transfer",
|
|
104
|
-
args: [
|
|
105
|
-
marketParams.loanToken,
|
|
106
|
-
receiver,
|
|
107
|
-
maxUint256,
|
|
108
|
-
generalAdapter1,
|
|
109
|
-
false,
|
|
110
|
-
],
|
|
111
|
-
});
|
|
112
|
-
}
|
|
113
|
-
let tx = {
|
|
114
|
-
...BundlerAction.encodeBundle(chainId, actions),
|
|
115
|
-
value: nativeAmount,
|
|
116
|
-
};
|
|
117
|
-
if (metadata) {
|
|
118
|
-
tx = addTransactionMetadata(tx, metadata);
|
|
119
|
-
}
|
|
120
71
|
return deepFreeze({
|
|
121
|
-
...
|
|
122
|
-
action: {
|
|
123
|
-
type: "blueRepay",
|
|
124
|
-
args: {
|
|
125
|
-
market: marketParams.id,
|
|
126
|
-
assets: repayAssets,
|
|
127
|
-
shares: repayShares,
|
|
128
|
-
// Total loan tokens routed to the adapter: ERC-20 pulled + native wrapped.
|
|
129
|
-
transferAmount: erc20Amount + nativeAmount,
|
|
130
|
-
onBehalf,
|
|
131
|
-
receiver,
|
|
132
|
-
maxSharePrice,
|
|
133
|
-
nativeAmount: nativeAmount > 0n ? nativeAmount : undefined,
|
|
134
|
-
},
|
|
135
|
-
},
|
|
72
|
+
...transaction,
|
|
73
|
+
action: { ...transaction.action, type: "blueRepay" },
|
|
136
74
|
});
|
|
137
75
|
};
|
|
@@ -1,111 +1,106 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type { MarketParams } from "@morpho-org/blue-sdk";
|
|
2
2
|
import { type Address } from "viem";
|
|
3
|
-
import { type AuthorizationRequirementSignature, type
|
|
3
|
+
import { type AuthorizationRequirementSignature, type BlueBundlesV1TokenRequirementSignature, type BlueRepayWithdrawCollateralAction, type Metadata, type Transaction } from "../../types/index.js";
|
|
4
4
|
/** Parameters for {@link blueRepayWithdrawCollateral}. */
|
|
5
5
|
export interface BlueRepayWithdrawCollateralParams {
|
|
6
|
-
market
|
|
6
|
+
/** Chain and scoped Morpho Blue market. */
|
|
7
|
+
readonly market: {
|
|
7
8
|
readonly chainId: number;
|
|
8
9
|
readonly marketParams: MarketParams;
|
|
9
10
|
};
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
11
|
+
/** Direct BlueBundlesV1 combined-operation arguments. */
|
|
12
|
+
readonly args: {
|
|
13
|
+
/** User whose debt and collateral position is changed. */
|
|
14
|
+
readonly userAddress: Address;
|
|
15
|
+
/** Exact assets repaid, exclusive with `repayShares`. */
|
|
16
|
+
readonly repayAssets: bigint;
|
|
17
|
+
/** Exact shares repaid; use `maxUint256` for a saturated full repay. */
|
|
18
|
+
readonly repayShares: bigint;
|
|
19
|
+
/** Maximum gross loan-token funding, including referral fees. */
|
|
20
|
+
readonly maxRepayAssets: bigint;
|
|
21
|
+
/** Collateral assets withdrawn; zero selects a pure repay. */
|
|
22
|
+
readonly collateralAssets: bigint;
|
|
23
|
+
/** Maximum post-operation LTV enforced by BlueBundlesV1. */
|
|
24
|
+
readonly maxLtv: bigint;
|
|
25
|
+
/** Full native repay funding; must equal `maxRepayAssets`. */
|
|
26
|
+
readonly nativeAmount?: bigint;
|
|
27
|
+
/** Final call deadline in Unix seconds. */
|
|
28
|
+
readonly deadline: bigint;
|
|
29
|
+
/** Optional WAD-scaled referral fee, strictly below 100%. */
|
|
30
|
+
readonly referralFeePct?: bigint;
|
|
31
|
+
/** Recipient required when `referralFeePct` is positive. */
|
|
32
|
+
readonly referralFeeRecipient?: Address;
|
|
33
|
+
/** Optional loan-token ERC-2612 or Permit2 SignatureTransfer result. */
|
|
34
|
+
readonly requirementSignature?: BlueBundlesV1TokenRequirementSignature;
|
|
35
|
+
/** Optional Morpho authorization signature for BlueBundlesV1. */
|
|
36
|
+
readonly authorizationSignature?: AuthorizationRequirementSignature;
|
|
27
37
|
};
|
|
28
|
-
metadata
|
|
38
|
+
/** Optional transaction metadata suffix. */
|
|
39
|
+
readonly metadata?: Metadata;
|
|
29
40
|
}
|
|
30
41
|
/**
|
|
31
|
-
*
|
|
42
|
+
* Encodes a direct BlueBundlesV1 repay and/or collateral-withdrawal transaction.
|
|
32
43
|
*
|
|
33
|
-
*
|
|
44
|
+
* `maxRepayAssets` funds the live repayment plus fee and BlueBundlesV1 refunds the unused amount.
|
|
45
|
+
* A saturated `repayShares = maxUint256` closes the live remaining debt. This route has no
|
|
46
|
+
* Bundler3 share-price bound or `slippageTolerance` input.
|
|
34
47
|
*
|
|
35
|
-
*
|
|
36
|
-
*
|
|
37
|
-
*
|
|
38
|
-
*
|
|
39
|
-
*
|
|
40
|
-
*
|
|
41
|
-
*
|
|
42
|
-
*
|
|
43
|
-
*
|
|
44
|
-
*
|
|
45
|
-
*
|
|
46
|
-
*
|
|
47
|
-
*
|
|
48
|
-
*
|
|
49
|
-
*
|
|
50
|
-
*
|
|
51
|
-
*
|
|
52
|
-
* `
|
|
53
|
-
* `
|
|
54
|
-
*
|
|
55
|
-
* @
|
|
56
|
-
* @
|
|
57
|
-
* @
|
|
58
|
-
* @
|
|
59
|
-
* @
|
|
60
|
-
*
|
|
61
|
-
* @
|
|
62
|
-
*
|
|
63
|
-
* @
|
|
64
|
-
*
|
|
65
|
-
* @
|
|
66
|
-
* @
|
|
67
|
-
*
|
|
68
|
-
* @
|
|
69
|
-
*
|
|
70
|
-
* @param params.args.requirementSignature - Optional pre-signed permit/permit2 approval for the
|
|
71
|
-
* loan-token transfer.
|
|
72
|
-
* @param params.args.authorizationSignature - Optional signed Morpho authorization; when present,
|
|
73
|
-
* a `setAuthorizationWithSig` call is prepended to the bundle.
|
|
74
|
-
* @param params.metadata - Optional analytics metadata attached to the bundle.
|
|
75
|
-
* @returns A deep-frozen `Transaction<BlueRepayWithdrawCollateralAction>` with `to`,
|
|
76
|
-
* `value` (= `nativeAmount`), `data`, and the typed `action` discriminator the simulation layer consumes.
|
|
77
|
-
* @throws {NonPositiveInputError} when `maxSharePrice <= 0n`, the total funding is zero, or
|
|
78
|
-
* `withdrawAmount <= 0n`.
|
|
79
|
-
* @throws {NegativeInputError} when `amount`, `shares`, `nativeAmount`, or `transferAmount` is negative.
|
|
80
|
-
* @throws {MutuallyExclusiveRepayAmountsError} when both `amount` and `shares` are `> 0n`.
|
|
81
|
-
* @throws {TransferAmountNotEqualToAssetsError} when in assets mode and
|
|
82
|
-
* `transferAmount !== amount + nativeAmount`.
|
|
83
|
-
* @throws {ChainWNativeMissingError} when `nativeAmount > 0n` but the chain has no configured wNative.
|
|
84
|
-
* @throws {NativeAmountOnNonWNativeAssetError} when `nativeAmount > 0n` but the loan token is not
|
|
85
|
-
* the chain's wNative.
|
|
86
|
-
* @throws {DepositAssetMismatchError} from `getTokenRequirementActions` when `requirementSignature`
|
|
87
|
-
* is provided and the signed asset differs from `marketParams.loanToken`.
|
|
88
|
-
* @throws {DepositAmountMismatchError} from `getTokenRequirementActions` when `requirementSignature`
|
|
89
|
-
* is provided and the signed amount differs from the ERC-20 amount pulled.
|
|
90
|
-
* @throws {Permit2ExpirationMissingError} from `getTokenRequirementActions` when a Permit2 requirement
|
|
91
|
-
* signature is missing its expiration.
|
|
48
|
+
* @param params - Combined-operation encoding parameters.
|
|
49
|
+
* @param params.market.chainId - Chain containing BlueBundlesV1.
|
|
50
|
+
* @param params.market.marketParams - Scoped Morpho Blue market parameters.
|
|
51
|
+
* @param params.args.userAddress - User whose position is changed.
|
|
52
|
+
* @param params.args.repayAssets - Exact assets repaid, exclusive with shares.
|
|
53
|
+
* @param params.args.repayShares - Exact shares or `maxUint256` for full repay.
|
|
54
|
+
* @param params.args.maxRepayAssets - Gross repayment and fee funding cap.
|
|
55
|
+
* @param params.args.collateralAssets - Collateral withdrawn, or zero.
|
|
56
|
+
* @param params.args.maxLtv - Maximum post-operation LTV.
|
|
57
|
+
* @param params.args.nativeAmount - Exclusive native repay funding.
|
|
58
|
+
* @param params.args.deadline - Final call deadline in Unix seconds.
|
|
59
|
+
* @param params.args.referralFeePct - Optional WAD-scaled fee below 100%.
|
|
60
|
+
* @param params.args.referralFeeRecipient - Recipient required for a positive fee.
|
|
61
|
+
* @param params.args.requirementSignature - Optional loan-token signature.
|
|
62
|
+
* @param params.args.authorizationSignature - Optional Blue authorization signature.
|
|
63
|
+
* @param params.metadata - Optional transaction metadata.
|
|
64
|
+
* @returns A deep-frozen `Readonly<Transaction<BlueRepayWithdrawCollateralAction>>`
|
|
65
|
+
* whose `to` address is BlueBundlesV1 and whose `action` records the normalized inputs.
|
|
66
|
+
* @throws {NegativeInputError} when an amount, `maxLtv`, native value, or fee is negative.
|
|
67
|
+
* @throws {MutuallyExclusiveRepayAmountsError} when assets and shares are both nonzero.
|
|
68
|
+
* @throws {NonPositiveInputError} when both operation legs are zero, repay funding is absent, or the deadline is invalid.
|
|
69
|
+
* @throws {MaxRepayAssetsBelowRepayAssetsError} when exact-asset funding cannot cover the repayment and referral fee.
|
|
70
|
+
* @throws {InputExceedsMaxError} when the referral fee is at least WAD.
|
|
71
|
+
* @throws {MissingReferralFeeRecipientError} when a positive fee has no recipient.
|
|
72
|
+
* @throws {NativeFundingAmountMismatchError} when native funding is partial or mixed.
|
|
73
|
+
* @throws {ChainWNativeMissingError} when native funding is requested on a chain without wNative.
|
|
74
|
+
* @throws {NativeAmountOnNonWNativeAssetError} when native funding targets another token.
|
|
75
|
+
* @throws {UnexpectedRequirementSignatureError} when a signature is supplied for an inactive leg.
|
|
76
|
+
* @throws {DepositOwnerMismatchError} when a signed owner differs from `userAddress`.
|
|
77
|
+
* @throws {DepositAssetMismatchError} when the signed asset differs from the loan token.
|
|
78
|
+
* @throws {DepositAmountMismatchError} when the signed amount differs from `maxRepayAssets`.
|
|
79
|
+
* @throws {DepositSpenderMismatchError} when the signed spender is not BlueBundlesV1.
|
|
80
|
+
* @throws {BlueBundlesV1RequirementSignatureMismatchError} when a signature cannot be bound safely.
|
|
81
|
+
* @throws {UnsupportedChainIdError} when the chain is absent from the registry.
|
|
82
|
+
* @throws {UnknownAddressError} when BlueBundlesV1 is not registered.
|
|
92
83
|
* @example
|
|
93
84
|
* ```ts
|
|
85
|
+
* import { markets } from "@morpho-org/morpho-test";
|
|
94
86
|
* import { blueRepayWithdrawCollateral } from "@morpho-org/morpho-sdk";
|
|
87
|
+
* import { maxUint256, zeroAddress } from "viem";
|
|
88
|
+
* import { mainnet } from "viem/chains";
|
|
95
89
|
*
|
|
90
|
+
* const marketParams = markets[mainnet.id].usdc_wbtc;
|
|
96
91
|
* const tx = blueRepayWithdrawCollateral({
|
|
97
|
-
* market: { chainId:
|
|
92
|
+
* market: { chainId: mainnet.id, marketParams },
|
|
98
93
|
* args: {
|
|
99
|
-
*
|
|
100
|
-
*
|
|
101
|
-
*
|
|
102
|
-
*
|
|
103
|
-
*
|
|
104
|
-
*
|
|
105
|
-
*
|
|
94
|
+
* userAddress: zeroAddress,
|
|
95
|
+
* repayAssets: 1_000_000n,
|
|
96
|
+
* repayShares: 0n,
|
|
97
|
+
* maxRepayAssets: 1_000_000n,
|
|
98
|
+
* collateralAssets: 0n,
|
|
99
|
+
* maxLtv: maxUint256,
|
|
100
|
+
* deadline: 1_900_000_000n,
|
|
106
101
|
* },
|
|
107
102
|
* });
|
|
108
|
-
* // tx
|
|
103
|
+
* // tx satisfies Readonly<Transaction<BlueRepayWithdrawCollateralAction>>
|
|
109
104
|
* ```
|
|
110
105
|
*/
|
|
111
|
-
export declare const blueRepayWithdrawCollateral: (
|
|
106
|
+
export declare const blueRepayWithdrawCollateral: (params: BlueRepayWithdrawCollateralParams) => Readonly<Transaction<BlueRepayWithdrawCollateralAction>>;
|