@morpho-org/morpho-sdk 5.8.0 → 6.0.0-next.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/MIGRATION-v5-to-v6.md +201 -0
- package/README.md +62 -40
- package/lib/cjs/abis.d.ts +543 -0
- package/lib/cjs/abis.js +738 -0
- package/lib/cjs/actions/blue/borrow.d.ts +62 -58
- package/lib/cjs/actions/blue/borrow.js +48 -80
- package/lib/cjs/actions/blue/common.d.ts +99 -0
- package/lib/cjs/actions/blue/common.js +318 -0
- package/lib/cjs/actions/blue/refinance.d.ts +72 -107
- package/lib/cjs/actions/blue/refinance.js +97 -197
- package/lib/cjs/actions/blue/repay.d.ts +72 -68
- package/lib/cjs/actions/blue/repay.js +56 -118
- package/lib/cjs/actions/blue/repayWithdrawCollateral.d.ts +85 -90
- package/lib/cjs/actions/blue/repayWithdrawCollateral.js +148 -137
- package/lib/cjs/actions/blue/supply.d.ts +62 -45
- package/lib/cjs/actions/blue/supply.js +94 -70
- package/lib/cjs/actions/blue/supplyCollateral.d.ts +63 -40
- package/lib/cjs/actions/blue/supplyCollateral.js +52 -69
- package/lib/cjs/actions/blue/supplyCollateralBorrow.d.ts +82 -86
- package/lib/cjs/actions/blue/supplyCollateralBorrow.js +133 -119
- package/lib/cjs/actions/blue/withdraw.d.ts +68 -78
- package/lib/cjs/actions/blue/withdraw.js +101 -97
- package/lib/cjs/actions/blue/withdrawCollateral.d.ts +56 -28
- package/lib/cjs/actions/blue/withdrawCollateral.js +45 -50
- package/lib/cjs/actions/index.d.ts +1 -1
- package/lib/cjs/actions/requirements/blue/getBlueAuthorizationRequirement.d.ts +29 -17
- package/lib/cjs/actions/requirements/blue/getBlueAuthorizationRequirement.js +60 -19
- package/lib/cjs/actions/requirements/blue/getBlueBundlesV1TokenRequirements.d.ts +80 -0
- package/lib/cjs/actions/requirements/blue/getBlueBundlesV1TokenRequirements.js +207 -0
- package/lib/cjs/actions/requirements/blue/getUnusedPermit2Nonce.d.ts +48 -0
- package/lib/cjs/actions/requirements/blue/getUnusedPermit2Nonce.js +72 -0
- package/lib/cjs/actions/requirements/blue/index.d.ts +2 -0
- package/lib/cjs/actions/requirements/blue/index.js +2 -0
- package/lib/cjs/actions/requirements/encode/encodeBlueSignatureAuthorization.d.ts +10 -7
- package/lib/cjs/actions/requirements/encode/encodeBlueSignatureAuthorization.js +30 -5
- package/lib/cjs/actions/requirements/encode/encodeErc20Approval.d.ts +2 -1
- package/lib/cjs/actions/requirements/encode/encodeErc20Approval.js +7 -2
- package/lib/cjs/actions/requirements/encode/encodeErc20Permit.d.ts +16 -7
- package/lib/cjs/actions/requirements/encode/encodeErc20Permit.js +33 -6
- package/lib/cjs/actions/requirements/encode/encodeErc20Permit2TransferFrom.d.ts +61 -0
- package/lib/cjs/actions/requirements/encode/encodeErc20Permit2TransferFrom.js +123 -0
- package/lib/cjs/actions/requirements/encode/index.d.ts +1 -0
- package/lib/cjs/actions/requirements/encode/index.js +1 -0
- package/lib/cjs/actions/requirements/generalAdapter/getGeneralAdapterRequirementsPermit.d.ts +1 -1
- package/lib/cjs/actions/requirements/getRequirementsApproval.d.ts +5 -4
- package/lib/cjs/actions/requirements/getRequirementsApproval.js +5 -4
- package/lib/cjs/actions/signatures/getTokenRequirementActions.d.ts +1 -0
- package/lib/cjs/actions/signatures/getTokenRequirementActions.js +4 -0
- package/lib/cjs/blue/types.d.ts +3 -1
- package/lib/cjs/blue/utils.d.ts +3 -1
- package/lib/cjs/blue/utils.js +1 -0
- package/lib/cjs/bundler/actions.d.ts +6 -4
- package/lib/cjs/bundler/actions.js +6 -4
- package/lib/cjs/bundler/types.d.ts +10 -1
- package/lib/cjs/client/morphoViemExtension.d.ts +2 -1
- package/lib/cjs/client/morphoViemExtension.js +2 -1
- package/lib/cjs/entities/blue/blue.d.ts +817 -360
- package/lib/cjs/entities/blue/blue.js +455 -698
- package/lib/cjs/entities/index.d.ts +1 -0
- package/lib/cjs/entities/vaultV1/vaultV1.js +4 -12
- package/lib/cjs/entities/vaultV1ReallocationData.d.ts +18 -3
- package/lib/cjs/entities/vaultV1ReallocationData.js +11 -1
- package/lib/cjs/entities/vaultV2/vaultV2.js +6 -18
- package/lib/cjs/helpers/computeVaultV1Reallocations.d.ts +7 -10
- package/lib/cjs/helpers/computeVaultV1Reallocations.js +7 -10
- package/lib/cjs/helpers/validate.d.ts +16 -23
- package/lib/cjs/helpers/validate.js +32 -48
- package/lib/cjs/helpers/validateRequirementSpender.d.ts +2 -1
- package/lib/cjs/helpers/validateRequirementSpender.js +2 -0
- package/lib/cjs/types/action.d.ts +146 -162
- package/lib/cjs/types/action.js +29 -2
- package/lib/cjs/types/client.d.ts +9 -0
- package/lib/cjs/types/error.d.ts +173 -18
- package/lib/cjs/types/error.js +230 -25
- package/lib/cjs/types/sharedLiquidity.d.ts +20 -4
- package/lib/cjs/types.d.ts +3 -1
- package/lib/cjs/utils.d.ts +3 -1
- package/lib/cjs/utils.js +1 -0
- package/lib/esm/abis.d.ts +543 -0
- package/lib/esm/abis.js +737 -0
- package/lib/esm/actions/blue/borrow.d.ts +62 -58
- package/lib/esm/actions/blue/borrow.js +48 -80
- package/lib/esm/actions/blue/common.d.ts +99 -0
- package/lib/esm/actions/blue/common.js +306 -0
- package/lib/esm/actions/blue/refinance.d.ts +72 -107
- package/lib/esm/actions/blue/refinance.js +98 -198
- package/lib/esm/actions/blue/repay.d.ts +72 -68
- package/lib/esm/actions/blue/repay.js +56 -118
- package/lib/esm/actions/blue/repayWithdrawCollateral.d.ts +85 -90
- package/lib/esm/actions/blue/repayWithdrawCollateral.js +149 -138
- package/lib/esm/actions/blue/supply.d.ts +62 -45
- package/lib/esm/actions/blue/supply.js +94 -70
- package/lib/esm/actions/blue/supplyCollateral.d.ts +63 -40
- package/lib/esm/actions/blue/supplyCollateral.js +52 -69
- package/lib/esm/actions/blue/supplyCollateralBorrow.d.ts +82 -86
- package/lib/esm/actions/blue/supplyCollateralBorrow.js +134 -120
- package/lib/esm/actions/blue/withdraw.d.ts +68 -78
- package/lib/esm/actions/blue/withdraw.js +100 -96
- package/lib/esm/actions/blue/withdrawCollateral.d.ts +56 -28
- package/lib/esm/actions/blue/withdrawCollateral.js +45 -50
- package/lib/esm/actions/index.d.ts +1 -1
- package/lib/esm/actions/requirements/blue/getBlueAuthorizationRequirement.d.ts +29 -17
- package/lib/esm/actions/requirements/blue/getBlueAuthorizationRequirement.js +63 -22
- package/lib/esm/actions/requirements/blue/getBlueBundlesV1TokenRequirements.d.ts +80 -0
- package/lib/esm/actions/requirements/blue/getBlueBundlesV1TokenRequirements.js +203 -0
- package/lib/esm/actions/requirements/blue/getUnusedPermit2Nonce.d.ts +48 -0
- package/lib/esm/actions/requirements/blue/getUnusedPermit2Nonce.js +68 -0
- package/lib/esm/actions/requirements/blue/index.d.ts +2 -0
- package/lib/esm/actions/requirements/blue/index.js +2 -0
- package/lib/esm/actions/requirements/encode/encodeBlueSignatureAuthorization.d.ts +10 -7
- package/lib/esm/actions/requirements/encode/encodeBlueSignatureAuthorization.js +31 -6
- package/lib/esm/actions/requirements/encode/encodeErc20Approval.d.ts +2 -1
- package/lib/esm/actions/requirements/encode/encodeErc20Approval.js +8 -3
- package/lib/esm/actions/requirements/encode/encodeErc20Permit.d.ts +16 -7
- package/lib/esm/actions/requirements/encode/encodeErc20Permit.js +34 -7
- package/lib/esm/actions/requirements/encode/encodeErc20Permit2TransferFrom.d.ts +61 -0
- package/lib/esm/actions/requirements/encode/encodeErc20Permit2TransferFrom.js +119 -0
- package/lib/esm/actions/requirements/encode/index.d.ts +1 -0
- package/lib/esm/actions/requirements/encode/index.js +1 -0
- package/lib/esm/actions/requirements/generalAdapter/getGeneralAdapterRequirementsPermit.d.ts +1 -1
- package/lib/esm/actions/requirements/getRequirementsApproval.d.ts +5 -4
- package/lib/esm/actions/requirements/getRequirementsApproval.js +5 -4
- package/lib/esm/actions/signatures/getTokenRequirementActions.d.ts +1 -0
- package/lib/esm/actions/signatures/getTokenRequirementActions.js +5 -1
- package/lib/esm/blue/types.d.ts +3 -1
- package/lib/esm/blue/utils.d.ts +3 -1
- package/lib/esm/blue/utils.js +3 -1
- package/lib/esm/bundler/actions.d.ts +6 -4
- package/lib/esm/bundler/actions.js +6 -4
- package/lib/esm/bundler/types.d.ts +10 -1
- package/lib/esm/client/morphoViemExtension.d.ts +2 -1
- package/lib/esm/client/morphoViemExtension.js +2 -1
- package/lib/esm/entities/blue/blue.d.ts +817 -360
- package/lib/esm/entities/blue/blue.js +461 -704
- package/lib/esm/entities/index.d.ts +1 -0
- package/lib/esm/entities/vaultV1/vaultV1.js +4 -12
- package/lib/esm/entities/vaultV1ReallocationData.d.ts +18 -3
- package/lib/esm/entities/vaultV1ReallocationData.js +13 -2
- package/lib/esm/entities/vaultV2/vaultV2.js +7 -19
- package/lib/esm/helpers/computeVaultV1Reallocations.d.ts +7 -10
- package/lib/esm/helpers/computeVaultV1Reallocations.js +7 -10
- package/lib/esm/helpers/validate.d.ts +16 -23
- package/lib/esm/helpers/validate.js +32 -48
- package/lib/esm/helpers/validateRequirementSpender.d.ts +2 -1
- package/lib/esm/helpers/validateRequirementSpender.js +2 -0
- package/lib/esm/types/action.d.ts +146 -162
- package/lib/esm/types/action.js +28 -2
- package/lib/esm/types/client.d.ts +9 -0
- package/lib/esm/types/error.d.ts +173 -18
- package/lib/esm/types/error.js +216 -21
- package/lib/esm/types/sharedLiquidity.d.ts +20 -4
- package/lib/esm/types.d.ts +3 -1
- package/lib/esm/utils.d.ts +3 -1
- package/lib/esm/utils.js +3 -1
- package/package.json +7 -6
- package/lib/cjs/actions/blue/buildAssetFundingActions.d.ts +0 -47
- package/lib/cjs/actions/blue/buildAssetFundingActions.js +0 -63
- package/lib/cjs/actions/blue/buildReallocationActions.d.ts +0 -69
- package/lib/cjs/actions/blue/buildReallocationActions.js +0 -141
- package/lib/cjs/actions/blue/resolveRepayFunding.d.ts +0 -66
- package/lib/cjs/actions/blue/resolveRepayFunding.js +0 -85
- package/lib/esm/actions/blue/buildAssetFundingActions.d.ts +0 -47
- package/lib/esm/actions/blue/buildAssetFundingActions.js +0 -59
- package/lib/esm/actions/blue/buildReallocationActions.d.ts +0 -69
- package/lib/esm/actions/blue/buildReallocationActions.js +0 -135
- package/lib/esm/actions/blue/resolveRepayFunding.d.ts +0 -66
- package/lib/esm/actions/blue/resolveRepayFunding.js +0 -81
|
@@ -1,109 +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
|
-
reallocations
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
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;
|
|
29
35
|
};
|
|
30
|
-
metadata
|
|
36
|
+
/** Optional transaction metadata suffix. */
|
|
37
|
+
readonly metadata?: Metadata;
|
|
31
38
|
}
|
|
32
39
|
/**
|
|
33
|
-
*
|
|
40
|
+
* Encodes a direct BlueBundlesV1 collateral supply and/or borrow transaction.
|
|
34
41
|
*
|
|
35
|
-
*
|
|
36
|
-
*
|
|
37
|
-
* never both. When `nativeAmount > 0`, native ETH is wrapped via
|
|
38
|
-
* `GeneralAdapter1.wrapNative()` before the supply leg. V1 fees add to
|
|
39
|
-
* `tx.value`; V2 penalties are paid in the target loan token and donated to the vaults. When the
|
|
40
|
-
* collateral and loan tokens match, one combined pull funds both collateral and penalties through
|
|
41
|
-
* `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.
|
|
42
44
|
*
|
|
43
|
-
*
|
|
44
|
-
*
|
|
45
|
-
*
|
|
46
|
-
*
|
|
47
|
-
*
|
|
48
|
-
*
|
|
49
|
-
* @param params.
|
|
50
|
-
* @param params.
|
|
51
|
-
* @param params.args.
|
|
52
|
-
*
|
|
53
|
-
* @param params.args.
|
|
54
|
-
* @param params.args.
|
|
55
|
-
* @param params.args.
|
|
56
|
-
* @param params.args.
|
|
57
|
-
* @param params.
|
|
58
|
-
*
|
|
59
|
-
*
|
|
60
|
-
*
|
|
61
|
-
* @
|
|
62
|
-
*
|
|
63
|
-
* @
|
|
64
|
-
*
|
|
65
|
-
* @
|
|
66
|
-
* @
|
|
67
|
-
*
|
|
68
|
-
* @throws {
|
|
69
|
-
*
|
|
70
|
-
* @throws {
|
|
71
|
-
*
|
|
72
|
-
* @throws {
|
|
73
|
-
* @throws {
|
|
74
|
-
* @throws {
|
|
75
|
-
* @throws {
|
|
76
|
-
* @throws {
|
|
77
|
-
* @throws {
|
|
78
|
-
* @throws {
|
|
79
|
-
* @throws {
|
|
80
|
-
*
|
|
81
|
-
* @throws {
|
|
82
|
-
* is provided and the signed asset differs from `marketParams.collateralToken`.
|
|
83
|
-
* @throws {DepositAmountMismatchError} from `getTokenRequirementActions` when `requirementSignature`
|
|
84
|
-
* is provided and the signed amount differs from the total ERC-20 funding amount.
|
|
85
|
-
* @throws {Permit2ExpirationMissingError} from `getTokenRequirementActions` when a Permit2 requirement
|
|
86
|
-
* signature is missing its expiration.
|
|
87
|
-
* @throws {EmptyReallocationWithdrawalsError} when any `reallocation.withdrawals` is empty.
|
|
88
|
-
* @throws {ReallocationWithdrawalOnTargetMarketError} when any reallocation withdrawal references
|
|
89
|
-
* the target market.
|
|
90
|
-
* @throws {UnsortedReallocationWithdrawalsError} when reallocation withdrawals are not strictly
|
|
91
|
-
* 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.
|
|
92
84
|
* @example
|
|
93
85
|
* ```ts
|
|
86
|
+
* import { markets } from "@morpho-org/morpho-test";
|
|
94
87
|
* import { blueSupplyCollateralBorrow } from "@morpho-org/morpho-sdk";
|
|
88
|
+
* import { maxUint256, zeroAddress } from "viem";
|
|
89
|
+
* import { mainnet } from "viem/chains";
|
|
95
90
|
*
|
|
91
|
+
* const marketParams = markets[mainnet.id].usdc_wbtc;
|
|
96
92
|
* const tx = blueSupplyCollateralBorrow({
|
|
97
|
-
* market: { chainId:
|
|
93
|
+
* market: { chainId: mainnet.id, marketParams },
|
|
98
94
|
* args: {
|
|
99
|
-
*
|
|
100
|
-
*
|
|
101
|
-
*
|
|
102
|
-
*
|
|
103
|
-
*
|
|
95
|
+
* userAddress: zeroAddress,
|
|
96
|
+
* collateralAssets: 1_000_000_000_000_000_000n,
|
|
97
|
+
* borrowAssets: 0n,
|
|
98
|
+
* maxLtv: maxUint256,
|
|
99
|
+
* deadline: 1_900_000_000n,
|
|
104
100
|
* },
|
|
105
101
|
* });
|
|
106
102
|
* // tx satisfies Readonly<Transaction<BlueSupplyCollateralBorrowAction>>
|
|
107
103
|
* ```
|
|
108
104
|
*/
|
|
109
|
-
export declare const blueSupplyCollateralBorrow: (
|
|
105
|
+
export declare const blueSupplyCollateralBorrow: (params: BlueSupplyCollateralBorrowParams) => Readonly<Transaction<BlueSupplyCollateralBorrowAction>>;
|
|
@@ -1,153 +1,167 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import { getBlueAuthorizationAction } from "../signatures/getBlueAuthorizationAction.js";
|
|
7
|
-
import { buildAssetFundingActions } from "./buildAssetFundingActions.js";
|
|
8
|
-
import { buildBlueReallocationActions } from "./buildReallocationActions.js";
|
|
1
|
+
import { encodeFunctionData } from "viem";
|
|
2
|
+
import { blueBundlesV1Abi } from "../../abis.js";
|
|
3
|
+
import { validateUint256Field } from "../../helpers/validate.js";
|
|
4
|
+
import { InputExceedsMaxError, NonPositiveInputError, ReallocationsRequireBorrowError, UnexpectedRequirementSignatureError, } from "../../types/index.js";
|
|
5
|
+
import { finalizeBlueBundlesV1Transaction, getBlueBundlesV1PenaltyAssets, getBlueBundlesV1PublicAllocations, getBlueBundlesV1SignedAuthorization, getBlueBundlesV1TokenPermit, normalizeBlueBundlesV1CommonParams, validateBlueBundlesV1NativeFunding, } from "./common.js";
|
|
9
6
|
/**
|
|
10
|
-
*
|
|
7
|
+
* Encodes a direct BlueBundlesV1 collateral supply and/or borrow transaction.
|
|
11
8
|
*
|
|
12
|
-
*
|
|
13
|
-
*
|
|
14
|
-
* never both. When `nativeAmount > 0`, native ETH is wrapped via
|
|
15
|
-
* `GeneralAdapter1.wrapNative()` before the supply leg. V1 fees add to
|
|
16
|
-
* `tx.value`; V2 penalties are paid in the target loan token and donated to the vaults. When the
|
|
17
|
-
* collateral and loan tokens match, one combined pull funds both collateral and penalties through
|
|
18
|
-
* `GeneralAdapter1`.
|
|
9
|
+
* Reallocations are Vault V2-only and require a borrow leg. Penalties and referral fees reduce
|
|
10
|
+
* borrow proceeds. This route has no Bundler3 share-price bound or `slippageTolerance` input.
|
|
19
11
|
*
|
|
20
|
-
*
|
|
21
|
-
*
|
|
22
|
-
*
|
|
23
|
-
*
|
|
24
|
-
*
|
|
25
|
-
*
|
|
26
|
-
* @param params.
|
|
27
|
-
* @param params.
|
|
28
|
-
* @param params.args.
|
|
29
|
-
*
|
|
30
|
-
* @param params.args.
|
|
31
|
-
* @param params.args.
|
|
32
|
-
* @param params.args.
|
|
33
|
-
* @param params.args.
|
|
34
|
-
* @param params.
|
|
35
|
-
*
|
|
36
|
-
*
|
|
37
|
-
*
|
|
38
|
-
* @
|
|
39
|
-
*
|
|
40
|
-
* @
|
|
41
|
-
*
|
|
42
|
-
* @
|
|
43
|
-
* @
|
|
44
|
-
*
|
|
45
|
-
* @throws {
|
|
46
|
-
*
|
|
47
|
-
* @throws {
|
|
48
|
-
*
|
|
49
|
-
* @throws {
|
|
50
|
-
* @throws {
|
|
51
|
-
* @throws {
|
|
52
|
-
* @throws {
|
|
53
|
-
* @throws {
|
|
54
|
-
* @throws {
|
|
55
|
-
* @throws {
|
|
56
|
-
* @throws {
|
|
57
|
-
*
|
|
58
|
-
* @throws {
|
|
59
|
-
* is provided and the signed asset differs from `marketParams.collateralToken`.
|
|
60
|
-
* @throws {DepositAmountMismatchError} from `getTokenRequirementActions` when `requirementSignature`
|
|
61
|
-
* is provided and the signed amount differs from the total ERC-20 funding amount.
|
|
62
|
-
* @throws {Permit2ExpirationMissingError} from `getTokenRequirementActions` when a Permit2 requirement
|
|
63
|
-
* signature is missing its expiration.
|
|
64
|
-
* @throws {EmptyReallocationWithdrawalsError} when any `reallocation.withdrawals` is empty.
|
|
65
|
-
* @throws {ReallocationWithdrawalOnTargetMarketError} when any reallocation withdrawal references
|
|
66
|
-
* the target market.
|
|
67
|
-
* @throws {UnsortedReallocationWithdrawalsError} when reallocation withdrawals are not strictly
|
|
68
|
-
* sorted by market id.
|
|
12
|
+
* @param params - Combined-operation encoding parameters.
|
|
13
|
+
* @param params.market.chainId - Chain containing BlueBundlesV1.
|
|
14
|
+
* @param params.market.marketParams - Scoped Morpho Blue market parameters.
|
|
15
|
+
* @param params.args.userAddress - User whose position is changed.
|
|
16
|
+
* @param params.args.collateralAssets - Gross collateral supplied, or zero.
|
|
17
|
+
* @param params.args.borrowAssets - Loan assets borrowed, or zero.
|
|
18
|
+
* @param params.args.maxLtv - Maximum post-operation LTV.
|
|
19
|
+
* @param params.args.nativeAmount - Exclusive native collateral funding.
|
|
20
|
+
* @param params.args.reallocations - Vault V2 reallocations executed before borrowing.
|
|
21
|
+
* @param params.args.deadline - Final call deadline in Unix seconds.
|
|
22
|
+
* @param params.args.referralFeePct - Optional WAD-scaled fee below 100%.
|
|
23
|
+
* @param params.args.referralFeeRecipient - Recipient required for a positive fee.
|
|
24
|
+
* @param params.args.requirementSignature - Optional collateral token signature.
|
|
25
|
+
* @param params.args.authorizationSignature - Optional Blue authorization signature.
|
|
26
|
+
* @param params.metadata - Optional transaction metadata.
|
|
27
|
+
* @returns A deep-frozen `Readonly<Transaction<BlueSupplyCollateralBorrowAction>>`
|
|
28
|
+
* whose `to` address is BlueBundlesV1 and whose `action` records the normalized inputs.
|
|
29
|
+
* @throws {NegativeInputError} when an amount, `maxLtv`, native value, or fee is negative.
|
|
30
|
+
* @throws {NonPositiveInputError} when both operation legs are zero, the deadline is not positive,
|
|
31
|
+
* or a reallocation amount is not positive.
|
|
32
|
+
* @throws {ReallocationsRequireBorrowError} when reallocations accompany no borrow.
|
|
33
|
+
* @throws {InputExceedsMaxError} when a fee, reallocation amount, or penalty exceeds its ABI bound.
|
|
34
|
+
* @throws {MissingReferralFeeRecipientError} when a positive fee has no recipient.
|
|
35
|
+
* @throws {InvalidReallocationAddressError} when a vault or adapter address is malformed.
|
|
36
|
+
* @throws {InvalidReallocationSourceTypeError} when a reallocation source is malformed.
|
|
37
|
+
* @throws {InconsistentReallocationPenaltyError} when one vault uses different penalties.
|
|
38
|
+
* @throws {ReallocationWithdrawalOnTargetMarketError} when a source is the target market.
|
|
39
|
+
* @throws {ReallocationLoanTokenMismatchError} when a source market uses another loan token.
|
|
40
|
+
* @throws {NativeFundingAmountMismatchError} when native funding is partial or mixed.
|
|
41
|
+
* @throws {ChainWNativeMissingError} when native funding is requested on a chain without wNative.
|
|
42
|
+
* @throws {NativeAmountOnNonWNativeAssetError} when native funding targets another token.
|
|
43
|
+
* @throws {UnexpectedRequirementSignatureError} when a signature is supplied for an inactive leg.
|
|
44
|
+
* @throws {DepositOwnerMismatchError} when a signed owner differs from `userAddress`.
|
|
45
|
+
* @throws {DepositAssetMismatchError} when the signed asset differs from the collateral token.
|
|
46
|
+
* @throws {DepositAmountMismatchError} when the signed amount differs from `collateralAssets`.
|
|
47
|
+
* @throws {DepositSpenderMismatchError} when the signed spender is not BlueBundlesV1.
|
|
48
|
+
* @throws {BlueBundlesV1RequirementSignatureMismatchError} when a signature cannot be bound safely.
|
|
49
|
+
* @throws {UnsupportedChainIdError} when the chain is absent from the registry.
|
|
50
|
+
* @throws {UnknownAddressError} when BlueBundlesV1 is not registered.
|
|
69
51
|
* @example
|
|
70
52
|
* ```ts
|
|
53
|
+
* import { markets } from "@morpho-org/morpho-test";
|
|
71
54
|
* import { blueSupplyCollateralBorrow } from "@morpho-org/morpho-sdk";
|
|
55
|
+
* import { maxUint256, zeroAddress } from "viem";
|
|
56
|
+
* import { mainnet } from "viem/chains";
|
|
72
57
|
*
|
|
58
|
+
* const marketParams = markets[mainnet.id].usdc_wbtc;
|
|
73
59
|
* const tx = blueSupplyCollateralBorrow({
|
|
74
|
-
* market: { chainId:
|
|
60
|
+
* market: { chainId: mainnet.id, marketParams },
|
|
75
61
|
* args: {
|
|
76
|
-
*
|
|
77
|
-
*
|
|
78
|
-
*
|
|
79
|
-
*
|
|
80
|
-
*
|
|
62
|
+
* userAddress: zeroAddress,
|
|
63
|
+
* collateralAssets: 1_000_000_000_000_000_000n,
|
|
64
|
+
* borrowAssets: 0n,
|
|
65
|
+
* maxLtv: maxUint256,
|
|
66
|
+
* deadline: 1_900_000_000n,
|
|
81
67
|
* },
|
|
82
68
|
* });
|
|
83
69
|
* // tx satisfies Readonly<Transaction<BlueSupplyCollateralBorrowAction>>
|
|
84
70
|
* ```
|
|
85
71
|
*/
|
|
86
|
-
export const blueSupplyCollateralBorrow = (
|
|
87
|
-
|
|
88
|
-
|
|
72
|
+
export const blueSupplyCollateralBorrow = (params) => {
|
|
73
|
+
const { chainId, marketParams } = params.market;
|
|
74
|
+
const { userAddress, collateralAssets, borrowAssets, maxLtv, requirementSignature, authorizationSignature, } = params.args;
|
|
75
|
+
for (const [field, value] of [
|
|
76
|
+
["collateralAssets", collateralAssets],
|
|
77
|
+
["borrowAssets", borrowAssets],
|
|
78
|
+
["maxLtv", maxLtv],
|
|
79
|
+
]) {
|
|
80
|
+
validateUint256Field(field, value);
|
|
89
81
|
}
|
|
90
|
-
if (
|
|
91
|
-
throw new
|
|
82
|
+
if (collateralAssets === 0n && borrowAssets === 0n) {
|
|
83
|
+
throw new NonPositiveInputError("collateralAssets or borrowAssets", 0n);
|
|
92
84
|
}
|
|
93
|
-
|
|
94
|
-
|
|
85
|
+
const reallocations = [...(params.args.reallocations ?? [])];
|
|
86
|
+
if (borrowAssets === 0n && reallocations.length > 0) {
|
|
87
|
+
throw new ReallocationsRequireBorrowError();
|
|
95
88
|
}
|
|
96
|
-
if (
|
|
97
|
-
throw new
|
|
89
|
+
if (collateralAssets === 0n && requirementSignature != null) {
|
|
90
|
+
throw new UnexpectedRequirementSignatureError(requirementSignature.action.type);
|
|
98
91
|
}
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
throw new NonPositiveInputError("totalCollateral", totalCollateral);
|
|
92
|
+
if (borrowAssets === 0n && authorizationSignature != null) {
|
|
93
|
+
throw new UnexpectedRequirementSignatureError("authorization");
|
|
102
94
|
}
|
|
103
|
-
const
|
|
104
|
-
|
|
95
|
+
const common = {
|
|
96
|
+
chainId,
|
|
97
|
+
userAddress,
|
|
98
|
+
deadline: params.args.deadline,
|
|
99
|
+
referralFeePct: params.args.referralFeePct,
|
|
100
|
+
referralFeeRecipient: params.args.referralFeeRecipient,
|
|
101
|
+
metadata: params.metadata,
|
|
102
|
+
};
|
|
103
|
+
const { referralFeePct, referralFeeRecipient } = normalizeBlueBundlesV1CommonParams(common);
|
|
104
|
+
const value = validateBlueBundlesV1NativeFunding({
|
|
105
105
|
chainId,
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
: "initiator",
|
|
106
|
+
token: marketParams.collateralToken,
|
|
107
|
+
fundedAmount: collateralAssets,
|
|
108
|
+
nativeAmount: params.args.nativeAmount,
|
|
109
|
+
requirementSignature,
|
|
111
110
|
});
|
|
112
|
-
const
|
|
113
|
-
const actions = [];
|
|
114
|
-
if (authorizationSignature) {
|
|
115
|
-
actions.push(getBlueAuthorizationAction(chainId, authorizationSignature));
|
|
116
|
-
}
|
|
117
|
-
actions.push(...buildAssetFundingActions({
|
|
111
|
+
const collateralPermit = getBlueBundlesV1TokenPermit({
|
|
118
112
|
chainId,
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
113
|
+
userAddress,
|
|
114
|
+
token: marketParams.collateralToken,
|
|
115
|
+
amount: collateralAssets,
|
|
122
116
|
requirementSignature,
|
|
123
|
-
}));
|
|
124
|
-
actions.push({
|
|
125
|
-
type: "morphoSupplyCollateral",
|
|
126
|
-
args: [marketParams, totalCollateral, onBehalf, [], false],
|
|
127
117
|
});
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
118
|
+
const signedAuthorization = getBlueBundlesV1SignedAuthorization({
|
|
119
|
+
chainId,
|
|
120
|
+
userAddress,
|
|
121
|
+
authorizationSignature,
|
|
132
122
|
});
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
123
|
+
const publicAllocations = getBlueBundlesV1PublicAllocations(reallocations, marketParams);
|
|
124
|
+
const reallocationPenaltyAssets = getBlueBundlesV1PenaltyAssets(publicAllocations);
|
|
125
|
+
if (reallocationPenaltyAssets > borrowAssets) {
|
|
126
|
+
throw new InputExceedsMaxError({
|
|
127
|
+
field: "reallocationPenaltyAssets",
|
|
128
|
+
value: reallocationPenaltyAssets,
|
|
129
|
+
max: borrowAssets,
|
|
130
|
+
});
|
|
136
131
|
}
|
|
137
|
-
return
|
|
138
|
-
|
|
132
|
+
return finalizeBlueBundlesV1Transaction({
|
|
133
|
+
common,
|
|
134
|
+
value,
|
|
135
|
+
data: encodeFunctionData({
|
|
136
|
+
abi: blueBundlesV1Abi,
|
|
137
|
+
functionName: "blueBundlesV1SupplyCollateralAndBorrow",
|
|
138
|
+
args: [
|
|
139
|
+
marketParams,
|
|
140
|
+
collateralAssets,
|
|
141
|
+
borrowAssets,
|
|
142
|
+
maxLtv,
|
|
143
|
+
collateralPermit,
|
|
144
|
+
signedAuthorization,
|
|
145
|
+
publicAllocations,
|
|
146
|
+
referralFeePct,
|
|
147
|
+
referralFeeRecipient,
|
|
148
|
+
params.args.deadline,
|
|
149
|
+
],
|
|
150
|
+
}),
|
|
139
151
|
action: {
|
|
140
152
|
type: "blueSupplyCollateralBorrow",
|
|
141
153
|
args: {
|
|
142
154
|
market: marketParams.id,
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
onBehalf,
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
155
|
+
collateralAssets,
|
|
156
|
+
borrowAssets,
|
|
157
|
+
maxLtv,
|
|
158
|
+
onBehalf: userAddress,
|
|
159
|
+
nativeAmount: value > 0n ? value : undefined,
|
|
160
|
+
reallocations: publicAllocations.length,
|
|
161
|
+
reallocationPenaltyAssets,
|
|
162
|
+
referralFeePct,
|
|
163
|
+
referralFeeRecipient,
|
|
164
|
+
deadline: params.args.deadline,
|
|
151
165
|
},
|
|
152
166
|
},
|
|
153
167
|
});
|