@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,113 +1,105 @@
|
|
|
1
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 BlueSupplyCollateralBorrowAction, type Metadata, type Transaction, type VaultV2BlueReallocation } from "../../types/index.js";
|
|
4
4
|
/** Parameters for {@link blueSupplyCollateralBorrow}. */
|
|
5
5
|
export interface BlueSupplyCollateralBorrowParams {
|
|
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
|
-
/**
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
11
|
+
/** Direct BlueBundlesV1 combined-operation arguments. */
|
|
12
|
+
readonly args: {
|
|
13
|
+
/** User whose collateral and debt position is changed. */
|
|
14
|
+
readonly userAddress: Address;
|
|
15
|
+
/** Gross collateral supplied; zero selects a pure borrow. */
|
|
16
|
+
readonly collateralAssets: bigint;
|
|
17
|
+
/** Loan assets borrowed; zero selects a pure collateral supply. */
|
|
18
|
+
readonly borrowAssets: bigint;
|
|
19
|
+
/** Maximum post-operation LTV enforced by BlueBundlesV1. */
|
|
20
|
+
readonly maxLtv: bigint;
|
|
21
|
+
/** Full native collateral funding; must equal `collateralAssets`. */
|
|
22
|
+
readonly nativeAmount?: bigint;
|
|
23
|
+
/** Optional validated Vault V2 BluePublicAllocator reallocations. */
|
|
24
|
+
readonly reallocations?: Iterable<VaultV2BlueReallocation>;
|
|
25
|
+
/** Final call deadline in Unix seconds. */
|
|
26
|
+
readonly deadline: bigint;
|
|
27
|
+
/** Optional WAD-scaled referral fee, strictly below 100%. */
|
|
28
|
+
readonly referralFeePct?: bigint;
|
|
29
|
+
/** Recipient required when `referralFeePct` is positive. */
|
|
30
|
+
readonly referralFeeRecipient?: Address;
|
|
31
|
+
/** Optional collateral ERC-2612 or Permit2 SignatureTransfer result. */
|
|
32
|
+
readonly requirementSignature?: BlueBundlesV1TokenRequirementSignature;
|
|
33
|
+
/** Optional Morpho authorization signature for BlueBundlesV1. */
|
|
34
|
+
readonly authorizationSignature?: AuthorizationRequirementSignature;
|
|
32
35
|
};
|
|
33
|
-
metadata
|
|
36
|
+
/** Optional transaction metadata suffix. */
|
|
37
|
+
readonly metadata?: Metadata;
|
|
34
38
|
}
|
|
35
39
|
/**
|
|
36
|
-
*
|
|
40
|
+
* Encodes a direct BlueBundlesV1 collateral supply and/or borrow transaction.
|
|
37
41
|
*
|
|
38
|
-
*
|
|
39
|
-
*
|
|
40
|
-
* never both. When `nativeAmount > 0`, native ETH is wrapped via
|
|
41
|
-
* `GeneralAdapter1.wrapNative()` before the supply leg. V1 fees add to
|
|
42
|
-
* `tx.value`; V2 penalties are paid in the target loan token and donated to the vaults. When the
|
|
43
|
-
* collateral and loan tokens match, one combined pull funds both collateral and penalties through
|
|
44
|
-
* `GeneralAdapter1`.
|
|
42
|
+
* Reallocations are Vault V2-only and require a borrow leg. Penalties and referral fees reduce
|
|
43
|
+
* borrow proceeds. This route has no Bundler3 share-price bound or `slippageTolerance` input.
|
|
45
44
|
*
|
|
46
|
-
*
|
|
47
|
-
*
|
|
48
|
-
*
|
|
49
|
-
*
|
|
50
|
-
*
|
|
51
|
-
*
|
|
52
|
-
* @param params.
|
|
53
|
-
* @param params.
|
|
54
|
-
* @param params.args.
|
|
55
|
-
*
|
|
56
|
-
* @param params.args.
|
|
57
|
-
* @param params.args.
|
|
58
|
-
* @param params.args.
|
|
59
|
-
* @param params.args.
|
|
60
|
-
* @param params.
|
|
61
|
-
*
|
|
62
|
-
*
|
|
63
|
-
*
|
|
64
|
-
* @
|
|
65
|
-
*
|
|
66
|
-
*
|
|
67
|
-
* @
|
|
68
|
-
*
|
|
69
|
-
* @
|
|
70
|
-
* @
|
|
71
|
-
*
|
|
72
|
-
* @throws {
|
|
73
|
-
*
|
|
74
|
-
* @throws {
|
|
75
|
-
*
|
|
76
|
-
* @throws {
|
|
77
|
-
* @throws {
|
|
78
|
-
* @throws {
|
|
79
|
-
* @throws {
|
|
80
|
-
* @throws {
|
|
81
|
-
* @throws {
|
|
82
|
-
* @throws {
|
|
83
|
-
* @throws {
|
|
84
|
-
*
|
|
85
|
-
* @throws {DepositAssetMismatchError} from `getTokenRequirementActions` when `requirementSignature`
|
|
86
|
-
* is provided and the signed asset differs from `marketParams.collateralToken`.
|
|
87
|
-
* @throws {DepositAmountMismatchError} from `getTokenRequirementActions` when `requirementSignature`
|
|
88
|
-
* is provided and the signed amount differs from the total ERC-20 funding amount.
|
|
89
|
-
* @throws {Permit2ExpirationMissingError} from `getTokenRequirementActions` when a Permit2 requirement
|
|
90
|
-
* signature is missing its expiration.
|
|
91
|
-
* @throws {EmptyReallocationWithdrawalsError} when any `reallocation.withdrawals` is empty.
|
|
92
|
-
* @throws {ReallocationWithdrawalOnTargetMarketError} when any reallocation withdrawal references
|
|
93
|
-
* the target market.
|
|
94
|
-
* @throws {UnsortedReallocationWithdrawalsError} when reallocation withdrawals are not strictly
|
|
95
|
-
* sorted by market id.
|
|
45
|
+
* @param params - Combined-operation encoding parameters.
|
|
46
|
+
* @param params.market.chainId - Chain containing BlueBundlesV1.
|
|
47
|
+
* @param params.market.marketParams - Scoped Morpho Blue market parameters.
|
|
48
|
+
* @param params.args.userAddress - User whose position is changed.
|
|
49
|
+
* @param params.args.collateralAssets - Gross collateral supplied, or zero.
|
|
50
|
+
* @param params.args.borrowAssets - Loan assets borrowed, or zero.
|
|
51
|
+
* @param params.args.maxLtv - Maximum post-operation LTV.
|
|
52
|
+
* @param params.args.nativeAmount - Exclusive native collateral funding.
|
|
53
|
+
* @param params.args.reallocations - Vault V2 reallocations executed before borrowing.
|
|
54
|
+
* @param params.args.deadline - Final call deadline in Unix seconds.
|
|
55
|
+
* @param params.args.referralFeePct - Optional WAD-scaled fee below 100%.
|
|
56
|
+
* @param params.args.referralFeeRecipient - Recipient required for a positive fee.
|
|
57
|
+
* @param params.args.requirementSignature - Optional collateral token signature.
|
|
58
|
+
* @param params.args.authorizationSignature - Optional Blue authorization signature.
|
|
59
|
+
* @param params.metadata - Optional transaction metadata.
|
|
60
|
+
* @returns A deep-frozen `Readonly<Transaction<BlueSupplyCollateralBorrowAction>>`
|
|
61
|
+
* whose `to` address is BlueBundlesV1 and whose `action` records the normalized inputs.
|
|
62
|
+
* @throws {NegativeInputError} when an amount, `maxLtv`, native value, or fee is negative.
|
|
63
|
+
* @throws {NonPositiveInputError} when both operation legs are zero, the deadline is not positive,
|
|
64
|
+
* or a reallocation amount is not positive.
|
|
65
|
+
* @throws {ReallocationsRequireBorrowError} when reallocations accompany no borrow.
|
|
66
|
+
* @throws {InputExceedsMaxError} when a fee, reallocation amount, or penalty exceeds its ABI bound.
|
|
67
|
+
* @throws {MissingReferralFeeRecipientError} when a positive fee has no recipient.
|
|
68
|
+
* @throws {InvalidReallocationAddressError} when a vault or adapter address is malformed.
|
|
69
|
+
* @throws {InvalidReallocationSourceTypeError} when a reallocation source is malformed.
|
|
70
|
+
* @throws {InconsistentReallocationPenaltyError} when one vault uses different penalties.
|
|
71
|
+
* @throws {ReallocationWithdrawalOnTargetMarketError} when a source is the target market.
|
|
72
|
+
* @throws {ReallocationLoanTokenMismatchError} when a source market uses another loan token.
|
|
73
|
+
* @throws {NativeFundingAmountMismatchError} when native funding is partial or mixed.
|
|
74
|
+
* @throws {ChainWNativeMissingError} when native funding is requested on a chain without wNative.
|
|
75
|
+
* @throws {NativeAmountOnNonWNativeAssetError} when native funding targets another token.
|
|
76
|
+
* @throws {UnexpectedRequirementSignatureError} when a signature is supplied for an inactive leg.
|
|
77
|
+
* @throws {DepositOwnerMismatchError} when a signed owner differs from `userAddress`.
|
|
78
|
+
* @throws {DepositAssetMismatchError} when the signed asset differs from the collateral token.
|
|
79
|
+
* @throws {DepositAmountMismatchError} when the signed amount differs from `collateralAssets`.
|
|
80
|
+
* @throws {DepositSpenderMismatchError} when the signed spender is not BlueBundlesV1.
|
|
81
|
+
* @throws {BlueBundlesV1RequirementSignatureMismatchError} when a signature cannot be bound safely.
|
|
82
|
+
* @throws {UnsupportedChainIdError} when the chain is absent from the registry.
|
|
83
|
+
* @throws {UnknownAddressError} when BlueBundlesV1 is not registered.
|
|
96
84
|
* @example
|
|
97
85
|
* ```ts
|
|
86
|
+
* import { markets } from "@morpho-org/morpho-test";
|
|
98
87
|
* import { blueSupplyCollateralBorrow } from "@morpho-org/morpho-sdk";
|
|
88
|
+
* import { maxUint256, zeroAddress } from "viem";
|
|
89
|
+
* import { mainnet } from "viem/chains";
|
|
99
90
|
*
|
|
91
|
+
* const marketParams = markets[mainnet.id].usdc_wbtc;
|
|
100
92
|
* const tx = blueSupplyCollateralBorrow({
|
|
101
|
-
* market: { chainId:
|
|
93
|
+
* market: { chainId: mainnet.id, marketParams },
|
|
102
94
|
* args: {
|
|
103
|
-
*
|
|
104
|
-
*
|
|
105
|
-
*
|
|
106
|
-
*
|
|
107
|
-
*
|
|
95
|
+
* userAddress: zeroAddress,
|
|
96
|
+
* collateralAssets: 1_000_000_000_000_000_000n,
|
|
97
|
+
* borrowAssets: 0n,
|
|
98
|
+
* maxLtv: maxUint256,
|
|
99
|
+
* deadline: 1_900_000_000n,
|
|
108
100
|
* },
|
|
109
101
|
* });
|
|
110
102
|
* // tx satisfies Readonly<Transaction<BlueSupplyCollateralBorrowAction>>
|
|
111
103
|
* ```
|
|
112
104
|
*/
|
|
113
|
-
export declare const blueSupplyCollateralBorrow: (
|
|
105
|
+
export declare const blueSupplyCollateralBorrow: (params: BlueSupplyCollateralBorrowParams) => Readonly<Transaction<BlueSupplyCollateralBorrowAction>>;
|
|
@@ -1,157 +1,170 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.blueSupplyCollateralBorrow = void 0;
|
|
4
|
-
const morpho_ts_1 = require("@morpho-org/morpho-ts");
|
|
5
4
|
const viem_1 = require("viem");
|
|
6
|
-
const
|
|
7
|
-
const
|
|
8
|
-
const
|
|
9
|
-
const
|
|
10
|
-
const buildAssetFundingActions_js_1 = require("./buildAssetFundingActions.js");
|
|
11
|
-
const buildReallocationActions_js_1 = require("./buildReallocationActions.js");
|
|
5
|
+
const abis_js_1 = require("../../abis.js");
|
|
6
|
+
const validate_js_1 = require("../../helpers/validate.js");
|
|
7
|
+
const index_js_1 = require("../../types/index.js");
|
|
8
|
+
const common_js_1 = require("./common.js");
|
|
12
9
|
/**
|
|
13
|
-
*
|
|
10
|
+
* Encodes a direct BlueBundlesV1 collateral supply and/or borrow transaction.
|
|
14
11
|
*
|
|
15
|
-
*
|
|
16
|
-
*
|
|
17
|
-
* never both. When `nativeAmount > 0`, native ETH is wrapped via
|
|
18
|
-
* `GeneralAdapter1.wrapNative()` before the supply leg. V1 fees add to
|
|
19
|
-
* `tx.value`; V2 penalties are paid in the target loan token and donated to the vaults. When the
|
|
20
|
-
* collateral and loan tokens match, one combined pull funds both collateral and penalties through
|
|
21
|
-
* `GeneralAdapter1`.
|
|
12
|
+
* Reallocations are Vault V2-only and require a borrow leg. Penalties and referral fees reduce
|
|
13
|
+
* borrow proceeds. This route has no Bundler3 share-price bound or `slippageTolerance` input.
|
|
22
14
|
*
|
|
23
|
-
*
|
|
24
|
-
*
|
|
25
|
-
*
|
|
26
|
-
*
|
|
27
|
-
*
|
|
28
|
-
*
|
|
29
|
-
* @param params.
|
|
30
|
-
* @param params.
|
|
31
|
-
* @param params.args.
|
|
32
|
-
*
|
|
33
|
-
* @param params.args.
|
|
34
|
-
* @param params.args.
|
|
35
|
-
* @param params.args.
|
|
36
|
-
* @param params.args.
|
|
37
|
-
* @param params.
|
|
38
|
-
*
|
|
39
|
-
*
|
|
40
|
-
*
|
|
41
|
-
* @
|
|
42
|
-
*
|
|
43
|
-
*
|
|
44
|
-
* @
|
|
45
|
-
*
|
|
46
|
-
* @
|
|
47
|
-
* @
|
|
48
|
-
*
|
|
49
|
-
* @throws {
|
|
50
|
-
*
|
|
51
|
-
* @throws {
|
|
52
|
-
*
|
|
53
|
-
* @throws {
|
|
54
|
-
* @throws {
|
|
55
|
-
* @throws {
|
|
56
|
-
* @throws {
|
|
57
|
-
* @throws {
|
|
58
|
-
* @throws {
|
|
59
|
-
* @throws {
|
|
60
|
-
* @throws {
|
|
61
|
-
*
|
|
62
|
-
* @throws {DepositAssetMismatchError} from `getTokenRequirementActions` when `requirementSignature`
|
|
63
|
-
* is provided and the signed asset differs from `marketParams.collateralToken`.
|
|
64
|
-
* @throws {DepositAmountMismatchError} from `getTokenRequirementActions` when `requirementSignature`
|
|
65
|
-
* is provided and the signed amount differs from the total ERC-20 funding amount.
|
|
66
|
-
* @throws {Permit2ExpirationMissingError} from `getTokenRequirementActions` when a Permit2 requirement
|
|
67
|
-
* signature is missing its expiration.
|
|
68
|
-
* @throws {EmptyReallocationWithdrawalsError} when any `reallocation.withdrawals` is empty.
|
|
69
|
-
* @throws {ReallocationWithdrawalOnTargetMarketError} when any reallocation withdrawal references
|
|
70
|
-
* the target market.
|
|
71
|
-
* @throws {UnsortedReallocationWithdrawalsError} when reallocation withdrawals are not strictly
|
|
72
|
-
* sorted by market id.
|
|
15
|
+
* @param params - Combined-operation encoding parameters.
|
|
16
|
+
* @param params.market.chainId - Chain containing BlueBundlesV1.
|
|
17
|
+
* @param params.market.marketParams - Scoped Morpho Blue market parameters.
|
|
18
|
+
* @param params.args.userAddress - User whose position is changed.
|
|
19
|
+
* @param params.args.collateralAssets - Gross collateral supplied, or zero.
|
|
20
|
+
* @param params.args.borrowAssets - Loan assets borrowed, or zero.
|
|
21
|
+
* @param params.args.maxLtv - Maximum post-operation LTV.
|
|
22
|
+
* @param params.args.nativeAmount - Exclusive native collateral funding.
|
|
23
|
+
* @param params.args.reallocations - Vault V2 reallocations executed before borrowing.
|
|
24
|
+
* @param params.args.deadline - Final call deadline in Unix seconds.
|
|
25
|
+
* @param params.args.referralFeePct - Optional WAD-scaled fee below 100%.
|
|
26
|
+
* @param params.args.referralFeeRecipient - Recipient required for a positive fee.
|
|
27
|
+
* @param params.args.requirementSignature - Optional collateral token signature.
|
|
28
|
+
* @param params.args.authorizationSignature - Optional Blue authorization signature.
|
|
29
|
+
* @param params.metadata - Optional transaction metadata.
|
|
30
|
+
* @returns A deep-frozen `Readonly<Transaction<BlueSupplyCollateralBorrowAction>>`
|
|
31
|
+
* whose `to` address is BlueBundlesV1 and whose `action` records the normalized inputs.
|
|
32
|
+
* @throws {NegativeInputError} when an amount, `maxLtv`, native value, or fee is negative.
|
|
33
|
+
* @throws {NonPositiveInputError} when both operation legs are zero, the deadline is not positive,
|
|
34
|
+
* or a reallocation amount is not positive.
|
|
35
|
+
* @throws {ReallocationsRequireBorrowError} when reallocations accompany no borrow.
|
|
36
|
+
* @throws {InputExceedsMaxError} when a fee, reallocation amount, or penalty exceeds its ABI bound.
|
|
37
|
+
* @throws {MissingReferralFeeRecipientError} when a positive fee has no recipient.
|
|
38
|
+
* @throws {InvalidReallocationAddressError} when a vault or adapter address is malformed.
|
|
39
|
+
* @throws {InvalidReallocationSourceTypeError} when a reallocation source is malformed.
|
|
40
|
+
* @throws {InconsistentReallocationPenaltyError} when one vault uses different penalties.
|
|
41
|
+
* @throws {ReallocationWithdrawalOnTargetMarketError} when a source is the target market.
|
|
42
|
+
* @throws {ReallocationLoanTokenMismatchError} when a source market uses another loan token.
|
|
43
|
+
* @throws {NativeFundingAmountMismatchError} when native funding is partial or mixed.
|
|
44
|
+
* @throws {ChainWNativeMissingError} when native funding is requested on a chain without wNative.
|
|
45
|
+
* @throws {NativeAmountOnNonWNativeAssetError} when native funding targets another token.
|
|
46
|
+
* @throws {UnexpectedRequirementSignatureError} when a signature is supplied for an inactive leg.
|
|
47
|
+
* @throws {DepositOwnerMismatchError} when a signed owner differs from `userAddress`.
|
|
48
|
+
* @throws {DepositAssetMismatchError} when the signed asset differs from the collateral token.
|
|
49
|
+
* @throws {DepositAmountMismatchError} when the signed amount differs from `collateralAssets`.
|
|
50
|
+
* @throws {DepositSpenderMismatchError} when the signed spender is not BlueBundlesV1.
|
|
51
|
+
* @throws {BlueBundlesV1RequirementSignatureMismatchError} when a signature cannot be bound safely.
|
|
52
|
+
* @throws {UnsupportedChainIdError} when the chain is absent from the registry.
|
|
53
|
+
* @throws {UnknownAddressError} when BlueBundlesV1 is not registered.
|
|
73
54
|
* @example
|
|
74
55
|
* ```ts
|
|
56
|
+
* import { markets } from "@morpho-org/morpho-test";
|
|
75
57
|
* import { blueSupplyCollateralBorrow } from "@morpho-org/morpho-sdk";
|
|
58
|
+
* import { maxUint256, zeroAddress } from "viem";
|
|
59
|
+
* import { mainnet } from "viem/chains";
|
|
76
60
|
*
|
|
61
|
+
* const marketParams = markets[mainnet.id].usdc_wbtc;
|
|
77
62
|
* const tx = blueSupplyCollateralBorrow({
|
|
78
|
-
* market: { chainId:
|
|
63
|
+
* market: { chainId: mainnet.id, marketParams },
|
|
79
64
|
* args: {
|
|
80
|
-
*
|
|
81
|
-
*
|
|
82
|
-
*
|
|
83
|
-
*
|
|
84
|
-
*
|
|
65
|
+
* userAddress: zeroAddress,
|
|
66
|
+
* collateralAssets: 1_000_000_000_000_000_000n,
|
|
67
|
+
* borrowAssets: 0n,
|
|
68
|
+
* maxLtv: maxUint256,
|
|
69
|
+
* deadline: 1_900_000_000n,
|
|
85
70
|
* },
|
|
86
71
|
* });
|
|
87
72
|
* // tx satisfies Readonly<Transaction<BlueSupplyCollateralBorrowAction>>
|
|
88
73
|
* ```
|
|
89
74
|
*/
|
|
90
|
-
const blueSupplyCollateralBorrow = (
|
|
91
|
-
|
|
92
|
-
|
|
75
|
+
const blueSupplyCollateralBorrow = (params) => {
|
|
76
|
+
const { chainId, marketParams } = params.market;
|
|
77
|
+
const { userAddress, collateralAssets, borrowAssets, maxLtv, requirementSignature, authorizationSignature, } = params.args;
|
|
78
|
+
for (const [field, value] of [
|
|
79
|
+
["collateralAssets", collateralAssets],
|
|
80
|
+
["borrowAssets", borrowAssets],
|
|
81
|
+
["maxLtv", maxLtv],
|
|
82
|
+
]) {
|
|
83
|
+
(0, validate_js_1.validateUint256Field)(field, value);
|
|
93
84
|
}
|
|
94
|
-
if (
|
|
95
|
-
throw new
|
|
85
|
+
if (collateralAssets === 0n && borrowAssets === 0n) {
|
|
86
|
+
throw new index_js_1.NonPositiveInputError("collateralAssets or borrowAssets", 0n);
|
|
96
87
|
}
|
|
97
|
-
|
|
98
|
-
|
|
88
|
+
const reallocations = [...(params.args.reallocations ?? [])];
|
|
89
|
+
if (borrowAssets === 0n && reallocations.length > 0) {
|
|
90
|
+
throw new index_js_1.ReallocationsRequireBorrowError();
|
|
99
91
|
}
|
|
100
|
-
if (
|
|
101
|
-
throw new
|
|
92
|
+
if (collateralAssets === 0n && requirementSignature != null) {
|
|
93
|
+
throw new index_js_1.UnexpectedRequirementSignatureError(requirementSignature.action.type);
|
|
102
94
|
}
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
throw new index_js_3.NonPositiveInputError("totalCollateral", totalCollateral);
|
|
95
|
+
if (borrowAssets === 0n && authorizationSignature != null) {
|
|
96
|
+
throw new index_js_1.UnexpectedRequirementSignatureError("authorization");
|
|
106
97
|
}
|
|
107
|
-
const
|
|
108
|
-
|
|
98
|
+
const common = {
|
|
99
|
+
chainId,
|
|
100
|
+
userAddress,
|
|
101
|
+
deadline: params.args.deadline,
|
|
102
|
+
referralFeePct: params.args.referralFeePct,
|
|
103
|
+
referralFeeRecipient: params.args.referralFeeRecipient,
|
|
104
|
+
metadata: params.metadata,
|
|
105
|
+
};
|
|
106
|
+
const { referralFeePct, referralFeeRecipient } = (0, common_js_1.normalizeBlueBundlesV1CommonParams)(common);
|
|
107
|
+
const value = (0, common_js_1.validateBlueBundlesV1NativeFunding)({
|
|
109
108
|
chainId,
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
: "initiator",
|
|
109
|
+
token: marketParams.collateralToken,
|
|
110
|
+
fundedAmount: collateralAssets,
|
|
111
|
+
nativeAmount: params.args.nativeAmount,
|
|
112
|
+
requirementSignature,
|
|
115
113
|
});
|
|
116
|
-
const
|
|
117
|
-
const actions = [];
|
|
118
|
-
if (authorizationSignature) {
|
|
119
|
-
actions.push((0, getBlueAuthorizationAction_js_1.getBlueAuthorizationAction)(chainId, authorizationSignature));
|
|
120
|
-
}
|
|
121
|
-
actions.push(...(0, buildAssetFundingActions_js_1.buildAssetFundingActions)({
|
|
114
|
+
const collateralPermit = (0, common_js_1.getBlueBundlesV1TokenPermit)({
|
|
122
115
|
chainId,
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
116
|
+
userAddress,
|
|
117
|
+
token: marketParams.collateralToken,
|
|
118
|
+
amount: collateralAssets,
|
|
126
119
|
requirementSignature,
|
|
127
|
-
}));
|
|
128
|
-
actions.push({
|
|
129
|
-
type: "morphoSupplyCollateral",
|
|
130
|
-
args: [marketParams, totalCollateral, onBehalf, [], false],
|
|
131
120
|
});
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
121
|
+
const signedAuthorization = (0, common_js_1.getBlueBundlesV1SignedAuthorization)({
|
|
122
|
+
chainId,
|
|
123
|
+
userAddress,
|
|
124
|
+
authorizationSignature,
|
|
136
125
|
});
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
126
|
+
const publicAllocations = (0, common_js_1.getBlueBundlesV1PublicAllocations)(reallocations, marketParams);
|
|
127
|
+
const reallocationPenaltyAssets = (0, common_js_1.getBlueBundlesV1PenaltyAssets)(publicAllocations);
|
|
128
|
+
if (reallocationPenaltyAssets > borrowAssets) {
|
|
129
|
+
throw new index_js_1.InputExceedsMaxError({
|
|
130
|
+
field: "reallocationPenaltyAssets",
|
|
131
|
+
value: reallocationPenaltyAssets,
|
|
132
|
+
max: borrowAssets,
|
|
133
|
+
});
|
|
140
134
|
}
|
|
141
|
-
return (0,
|
|
142
|
-
|
|
135
|
+
return (0, common_js_1.finalizeBlueBundlesV1Transaction)({
|
|
136
|
+
common,
|
|
137
|
+
value,
|
|
138
|
+
data: (0, viem_1.encodeFunctionData)({
|
|
139
|
+
abi: abis_js_1.blueBundlesV1Abi,
|
|
140
|
+
functionName: "blueBundlesV1SupplyCollateralAndBorrow",
|
|
141
|
+
args: [
|
|
142
|
+
marketParams,
|
|
143
|
+
collateralAssets,
|
|
144
|
+
borrowAssets,
|
|
145
|
+
maxLtv,
|
|
146
|
+
collateralPermit,
|
|
147
|
+
signedAuthorization,
|
|
148
|
+
publicAllocations,
|
|
149
|
+
referralFeePct,
|
|
150
|
+
referralFeeRecipient,
|
|
151
|
+
params.args.deadline,
|
|
152
|
+
],
|
|
153
|
+
}),
|
|
143
154
|
action: {
|
|
144
155
|
type: "blueSupplyCollateralBorrow",
|
|
145
156
|
args: {
|
|
146
157
|
market: marketParams.id,
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
onBehalf,
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
158
|
+
collateralAssets,
|
|
159
|
+
borrowAssets,
|
|
160
|
+
maxLtv,
|
|
161
|
+
onBehalf: userAddress,
|
|
162
|
+
nativeAmount: value > 0n ? value : undefined,
|
|
163
|
+
reallocations: publicAllocations.length,
|
|
164
|
+
reallocationPenaltyAssets,
|
|
165
|
+
referralFeePct,
|
|
166
|
+
referralFeeRecipient,
|
|
167
|
+
deadline: params.args.deadline,
|
|
155
168
|
},
|
|
156
169
|
},
|
|
157
170
|
});
|