@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,81 +1,85 @@
|
|
|
1
1
|
import type { MarketParams } from "@morpho-org/blue-sdk";
|
|
2
2
|
import type { Address } from "viem";
|
|
3
|
-
import {
|
|
3
|
+
import type { AuthorizationRequirementSignature, BlueBorrowAction, Metadata, Transaction, VaultV2BlueReallocation } from "../../types/index.js";
|
|
4
4
|
/** Parameters for {@link blueBorrow}. */
|
|
5
5
|
export interface BlueBorrowParams {
|
|
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
|
-
reallocations
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
11
|
+
/** Direct BlueBundlesV1 borrow arguments. */
|
|
12
|
+
readonly args: {
|
|
13
|
+
/** User whose debt position is increased. */
|
|
14
|
+
readonly userAddress: Address;
|
|
15
|
+
/** Gross loan assets borrowed before penalties and referral fees. */
|
|
16
|
+
readonly borrowAssets: bigint;
|
|
17
|
+
/** Maximum post-operation LTV enforced by BlueBundlesV1. */
|
|
18
|
+
readonly maxLtv: bigint;
|
|
19
|
+
/** Optional validated Vault V2 BluePublicAllocator reallocations. */
|
|
20
|
+
readonly reallocations?: Iterable<VaultV2BlueReallocation>;
|
|
21
|
+
/** Final call deadline in Unix seconds. */
|
|
22
|
+
readonly deadline: bigint;
|
|
23
|
+
/** Optional WAD-scaled referral fee, strictly below 100%. */
|
|
24
|
+
readonly referralFeePct?: bigint;
|
|
25
|
+
/** Recipient required when `referralFeePct` is positive. */
|
|
26
|
+
readonly referralFeeRecipient?: Address;
|
|
27
|
+
/** Optional Morpho authorization signature for BlueBundlesV1. */
|
|
28
|
+
readonly authorizationSignature?: AuthorizationRequirementSignature;
|
|
25
29
|
};
|
|
26
|
-
metadata
|
|
30
|
+
/** Optional transaction metadata suffix. */
|
|
31
|
+
readonly metadata?: Metadata;
|
|
27
32
|
}
|
|
28
33
|
/**
|
|
29
|
-
*
|
|
34
|
+
* Encodes a pure borrow through BlueBundlesV1.
|
|
30
35
|
*
|
|
31
|
-
*
|
|
32
|
-
*
|
|
33
|
-
* transaction construction and execution.
|
|
36
|
+
* Delegates to {@link blueSupplyCollateralBorrow} with a zero collateral leg. Vault V2 allocator
|
|
37
|
+
* penalties and referral fees reduce the assets received, and no Bundler3 action is encoded.
|
|
34
38
|
*
|
|
35
|
-
*
|
|
36
|
-
*
|
|
37
|
-
*
|
|
38
|
-
*
|
|
39
|
-
*
|
|
40
|
-
* @param params.
|
|
41
|
-
* @param params.
|
|
42
|
-
* @param params.args.
|
|
43
|
-
* @param params.args.
|
|
44
|
-
* @param params.args.
|
|
45
|
-
* @param params.args.
|
|
46
|
-
*
|
|
47
|
-
* @
|
|
48
|
-
*
|
|
49
|
-
* @
|
|
50
|
-
* @
|
|
51
|
-
*
|
|
52
|
-
* @throws {
|
|
53
|
-
*
|
|
54
|
-
* @throws {
|
|
55
|
-
* @throws {InconsistentReallocationPenaltyError} when
|
|
56
|
-
* @throws {
|
|
57
|
-
* @throws {
|
|
58
|
-
* @throws {
|
|
59
|
-
* @throws {
|
|
60
|
-
* @throws {
|
|
61
|
-
* @throws {
|
|
62
|
-
* @throws {ReallocationWithdrawalOnTargetMarketError} when any reallocation withdrawal references
|
|
63
|
-
* the target market.
|
|
64
|
-
* @throws {UnsortedReallocationWithdrawalsError} when reallocation withdrawals are not strictly
|
|
65
|
-
* sorted by market id.
|
|
39
|
+
* @param params - Borrow encoding parameters.
|
|
40
|
+
* @param params.market.chainId - Chain containing BlueBundlesV1.
|
|
41
|
+
* @param params.market.marketParams - Scoped Morpho Blue market parameters.
|
|
42
|
+
* @param params.args.userAddress - User whose debt position is increased.
|
|
43
|
+
* @param params.args.borrowAssets - Gross loan assets borrowed.
|
|
44
|
+
* @param params.args.maxLtv - Maximum post-operation LTV.
|
|
45
|
+
* @param params.args.reallocations - Vault V2 reallocations executed before borrowing.
|
|
46
|
+
* @param params.args.deadline - Final call deadline in Unix seconds.
|
|
47
|
+
* @param params.args.referralFeePct - Optional WAD-scaled referral fee.
|
|
48
|
+
* @param params.args.referralFeeRecipient - Recipient required for a positive fee.
|
|
49
|
+
* @param params.args.authorizationSignature - Optional Blue authorization signature.
|
|
50
|
+
* @param params.metadata - Optional transaction metadata.
|
|
51
|
+
* @returns A deep-frozen `Readonly<Transaction<BlueBorrowAction>>` whose calldata invokes the
|
|
52
|
+
* combined BlueBundlesV1 entrypoint with a zero collateral leg.
|
|
53
|
+
* @throws {NegativeInputError} when an amount, LTV, fee, or reallocation penalty is negative.
|
|
54
|
+
* @throws {NonPositiveInputError} when the borrow, deadline, or reallocation amount is not positive.
|
|
55
|
+
* @throws {InputExceedsMaxError} when a fee, reallocation amount, or penalty exceeds its bound.
|
|
56
|
+
* @throws {MissingReferralFeeRecipientError} when a positive fee has no recipient.
|
|
57
|
+
* @throws {InvalidReallocationAddressError} when a vault or adapter address is malformed.
|
|
58
|
+
* @throws {InvalidReallocationSourceTypeError} when a reallocation source is malformed.
|
|
59
|
+
* @throws {InconsistentReallocationPenaltyError} when one vault uses different penalties.
|
|
60
|
+
* @throws {ReallocationWithdrawalOnTargetMarketError} when a source is the target market.
|
|
61
|
+
* @throws {ReallocationLoanTokenMismatchError} when a source market uses another loan token.
|
|
62
|
+
* @throws {DepositOwnerMismatchError} when the signed authorization owner differs from `userAddress`.
|
|
63
|
+
* @throws {BlueBundlesV1RequirementSignatureMismatchError} when authorization cannot be bound safely.
|
|
64
|
+
* @throws {UnsupportedChainIdError} when the chain is absent from the registry.
|
|
65
|
+
* @throws {UnknownAddressError} when BlueBundlesV1 is not registered.
|
|
66
66
|
* @example
|
|
67
67
|
* ```ts
|
|
68
|
+
* import { markets } from "@morpho-org/morpho-test";
|
|
68
69
|
* import { blueBorrow } from "@morpho-org/morpho-sdk";
|
|
70
|
+
* import { zeroAddress } from "viem";
|
|
71
|
+
* import { mainnet } from "viem/chains";
|
|
69
72
|
*
|
|
70
73
|
* const tx = blueBorrow({
|
|
71
|
-
* market: { chainId:
|
|
74
|
+
* market: { chainId: mainnet.id, marketParams: markets[mainnet.id].usdc_wbtc },
|
|
72
75
|
* args: {
|
|
73
|
-
*
|
|
74
|
-
*
|
|
75
|
-
*
|
|
76
|
+
* userAddress: zeroAddress,
|
|
77
|
+
* borrowAssets: 1_000_000n,
|
|
78
|
+
* maxLtv: 850000000000000000n,
|
|
79
|
+
* deadline: 1_900_000_000n,
|
|
76
80
|
* },
|
|
77
81
|
* });
|
|
78
82
|
* // tx satisfies Readonly<Transaction<BlueBorrowAction>>
|
|
79
83
|
* ```
|
|
80
84
|
*/
|
|
81
|
-
export declare const blueBorrow: (
|
|
85
|
+
export declare const blueBorrow: (params: BlueBorrowParams) => Readonly<Transaction<BlueBorrowAction>>;
|
|
@@ -2,102 +2,70 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.blueBorrow = void 0;
|
|
4
4
|
const morpho_ts_1 = require("@morpho-org/morpho-ts");
|
|
5
|
-
const
|
|
6
|
-
const index_js_2 = require("../../helpers/index.js");
|
|
7
|
-
const index_js_3 = require("../../types/index.js");
|
|
8
|
-
const getBlueAuthorizationAction_js_1 = require("../signatures/getBlueAuthorizationAction.js");
|
|
9
|
-
const buildReallocationActions_js_1 = require("./buildReallocationActions.js");
|
|
5
|
+
const supplyCollateralBorrow_js_1 = require("./supplyCollateralBorrow.js");
|
|
10
6
|
/**
|
|
11
|
-
*
|
|
7
|
+
* Encodes a pure borrow through BlueBundlesV1.
|
|
12
8
|
*
|
|
13
|
-
*
|
|
14
|
-
*
|
|
15
|
-
* transaction construction and execution.
|
|
9
|
+
* Delegates to {@link blueSupplyCollateralBorrow} with a zero collateral leg. Vault V2 allocator
|
|
10
|
+
* penalties and referral fees reduce the assets received, and no Bundler3 action is encoded.
|
|
16
11
|
*
|
|
17
|
-
*
|
|
18
|
-
*
|
|
19
|
-
*
|
|
20
|
-
*
|
|
21
|
-
*
|
|
22
|
-
* @param params.
|
|
23
|
-
* @param params.
|
|
24
|
-
* @param params.args.
|
|
25
|
-
* @param params.args.
|
|
26
|
-
* @param params.args.
|
|
27
|
-
* @param params.args.
|
|
28
|
-
*
|
|
29
|
-
* @
|
|
30
|
-
*
|
|
31
|
-
* @
|
|
32
|
-
* @
|
|
33
|
-
*
|
|
34
|
-
* @throws {
|
|
35
|
-
*
|
|
36
|
-
* @throws {
|
|
37
|
-
* @throws {InconsistentReallocationPenaltyError} when
|
|
38
|
-
* @throws {
|
|
39
|
-
* @throws {
|
|
40
|
-
* @throws {
|
|
41
|
-
* @throws {
|
|
42
|
-
* @throws {
|
|
43
|
-
* @throws {
|
|
44
|
-
* @throws {ReallocationWithdrawalOnTargetMarketError} when any reallocation withdrawal references
|
|
45
|
-
* the target market.
|
|
46
|
-
* @throws {UnsortedReallocationWithdrawalsError} when reallocation withdrawals are not strictly
|
|
47
|
-
* sorted by market id.
|
|
12
|
+
* @param params - Borrow 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 debt position is increased.
|
|
16
|
+
* @param params.args.borrowAssets - Gross loan assets borrowed.
|
|
17
|
+
* @param params.args.maxLtv - Maximum post-operation LTV.
|
|
18
|
+
* @param params.args.reallocations - Vault V2 reallocations executed before borrowing.
|
|
19
|
+
* @param params.args.deadline - Final call deadline in Unix seconds.
|
|
20
|
+
* @param params.args.referralFeePct - Optional WAD-scaled referral fee.
|
|
21
|
+
* @param params.args.referralFeeRecipient - Recipient required for a positive fee.
|
|
22
|
+
* @param params.args.authorizationSignature - Optional Blue authorization signature.
|
|
23
|
+
* @param params.metadata - Optional transaction metadata.
|
|
24
|
+
* @returns A deep-frozen `Readonly<Transaction<BlueBorrowAction>>` whose calldata invokes the
|
|
25
|
+
* combined BlueBundlesV1 entrypoint with a zero collateral leg.
|
|
26
|
+
* @throws {NegativeInputError} when an amount, LTV, fee, or reallocation penalty is negative.
|
|
27
|
+
* @throws {NonPositiveInputError} when the borrow, deadline, or reallocation amount is not positive.
|
|
28
|
+
* @throws {InputExceedsMaxError} when a fee, reallocation amount, or penalty exceeds its bound.
|
|
29
|
+
* @throws {MissingReferralFeeRecipientError} when a positive fee has no recipient.
|
|
30
|
+
* @throws {InvalidReallocationAddressError} when a vault or adapter address is malformed.
|
|
31
|
+
* @throws {InvalidReallocationSourceTypeError} when a reallocation source is malformed.
|
|
32
|
+
* @throws {InconsistentReallocationPenaltyError} when one vault uses different penalties.
|
|
33
|
+
* @throws {ReallocationWithdrawalOnTargetMarketError} when a source is the target market.
|
|
34
|
+
* @throws {ReallocationLoanTokenMismatchError} when a source market uses another loan token.
|
|
35
|
+
* @throws {DepositOwnerMismatchError} when the signed authorization owner differs from `userAddress`.
|
|
36
|
+
* @throws {BlueBundlesV1RequirementSignatureMismatchError} when authorization cannot be bound safely.
|
|
37
|
+
* @throws {UnsupportedChainIdError} when the chain is absent from the registry.
|
|
38
|
+
* @throws {UnknownAddressError} when BlueBundlesV1 is not registered.
|
|
48
39
|
* @example
|
|
49
40
|
* ```ts
|
|
41
|
+
* import { markets } from "@morpho-org/morpho-test";
|
|
50
42
|
* import { blueBorrow } from "@morpho-org/morpho-sdk";
|
|
43
|
+
* import { zeroAddress } from "viem";
|
|
44
|
+
* import { mainnet } from "viem/chains";
|
|
51
45
|
*
|
|
52
46
|
* const tx = blueBorrow({
|
|
53
|
-
* market: { chainId:
|
|
47
|
+
* market: { chainId: mainnet.id, marketParams: markets[mainnet.id].usdc_wbtc },
|
|
54
48
|
* args: {
|
|
55
|
-
*
|
|
56
|
-
*
|
|
57
|
-
*
|
|
49
|
+
* userAddress: zeroAddress,
|
|
50
|
+
* borrowAssets: 1_000_000n,
|
|
51
|
+
* maxLtv: 850000000000000000n,
|
|
52
|
+
* deadline: 1_900_000_000n,
|
|
58
53
|
* },
|
|
59
54
|
* });
|
|
60
55
|
* // tx satisfies Readonly<Transaction<BlueBorrowAction>>
|
|
61
56
|
* ```
|
|
62
57
|
*/
|
|
63
|
-
const blueBorrow = (
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
const actions = [];
|
|
71
|
-
if (authorizationSignature) {
|
|
72
|
-
actions.push((0, getBlueAuthorizationAction_js_1.getBlueAuthorizationAction)(chainId, authorizationSignature));
|
|
73
|
-
}
|
|
74
|
-
const { actions: reallocationActions, fee: reallocationFee, penaltyAssets: reallocationPenaltyAssets, } = (0, buildReallocationActions_js_1.buildBlueReallocationActions)({
|
|
75
|
-
chainId,
|
|
76
|
-
reallocations,
|
|
77
|
-
targetMarketParams: marketParams,
|
|
78
|
-
});
|
|
79
|
-
actions.push(...reallocationActions);
|
|
80
|
-
actions.push({
|
|
81
|
-
type: "morphoBorrow",
|
|
82
|
-
args: [marketParams, amount, 0n, minSharePrice, receiver, false],
|
|
58
|
+
const blueBorrow = (params) => {
|
|
59
|
+
const transaction = (0, supplyCollateralBorrow_js_1.blueSupplyCollateralBorrow)({
|
|
60
|
+
...params,
|
|
61
|
+
args: {
|
|
62
|
+
...params.args,
|
|
63
|
+
collateralAssets: 0n,
|
|
64
|
+
},
|
|
83
65
|
});
|
|
84
|
-
let tx = index_js_1.BundlerAction.encodeBundle(chainId, actions);
|
|
85
|
-
if (metadata) {
|
|
86
|
-
tx = (0, index_js_2.addTransactionMetadata)(tx, metadata);
|
|
87
|
-
}
|
|
88
66
|
return (0, morpho_ts_1.deepFreeze)({
|
|
89
|
-
...
|
|
90
|
-
action: {
|
|
91
|
-
type: "blueBorrow",
|
|
92
|
-
args: {
|
|
93
|
-
market: marketParams.id,
|
|
94
|
-
amount,
|
|
95
|
-
receiver,
|
|
96
|
-
minSharePrice,
|
|
97
|
-
reallocationFee,
|
|
98
|
-
reallocationPenaltyAssets,
|
|
99
|
-
},
|
|
100
|
-
},
|
|
67
|
+
...transaction,
|
|
68
|
+
action: { ...transaction.action, type: "blueBorrow" },
|
|
101
69
|
});
|
|
102
70
|
};
|
|
103
71
|
exports.blueBorrow = blueBorrow;
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import { MarketParams } from "@morpho-org/blue-sdk";
|
|
2
|
+
import { type Address, type Hex } from "viem";
|
|
3
|
+
import { type AuthorizationRequirementSignature, type BaseAction, type BlueBundlesV1TokenRequirementSignature, type Metadata, type RequirementSignature, type TokenRequirementSignature, type Transaction, type VaultV2BlueReallocation } from "../../types/index.js";
|
|
4
|
+
/** @internal */
|
|
5
|
+
export interface BlueBundlesV1CommonParams {
|
|
6
|
+
chainId: number;
|
|
7
|
+
userAddress: Address;
|
|
8
|
+
deadline: bigint;
|
|
9
|
+
referralFeePct?: bigint;
|
|
10
|
+
referralFeeRecipient?: Address;
|
|
11
|
+
metadata?: Metadata;
|
|
12
|
+
}
|
|
13
|
+
/** @internal */
|
|
14
|
+
export interface NormalizedBlueBundlesV1CommonParams {
|
|
15
|
+
referralFeePct: bigint;
|
|
16
|
+
referralFeeRecipient: Address;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* BlueBundlesV1 token-permit discriminator carried in the encoded permit struct: `none` (0) skips
|
|
20
|
+
* the pull, `erc2612` (1) is an ERC-2612 permit, `permit2TransferFrom` (2) is a Permit2
|
|
21
|
+
* SignatureTransfer. Named so a transposed literal can't silently route a permit to the wrong branch.
|
|
22
|
+
* @internal
|
|
23
|
+
*/
|
|
24
|
+
declare const BLUE_BUNDLES_V1_TOKEN_PERMIT_KIND: {
|
|
25
|
+
readonly none: 0;
|
|
26
|
+
readonly erc2612: 1;
|
|
27
|
+
readonly permit2TransferFrom: 2;
|
|
28
|
+
};
|
|
29
|
+
interface BlueBundlesV1TokenPermit {
|
|
30
|
+
kind: (typeof BLUE_BUNDLES_V1_TOKEN_PERMIT_KIND)[keyof typeof BLUE_BUNDLES_V1_TOKEN_PERMIT_KIND];
|
|
31
|
+
data: Hex;
|
|
32
|
+
}
|
|
33
|
+
interface BlueBundlesV1SignedAuthorization {
|
|
34
|
+
signature: {
|
|
35
|
+
v: number;
|
|
36
|
+
r: Hex;
|
|
37
|
+
s: Hex;
|
|
38
|
+
};
|
|
39
|
+
nonce: bigint;
|
|
40
|
+
deadline: bigint;
|
|
41
|
+
}
|
|
42
|
+
/** @internal */
|
|
43
|
+
export declare const normalizeBlueBundlesV1CommonParams: (params: BlueBundlesV1CommonParams) => NormalizedBlueBundlesV1CommonParams;
|
|
44
|
+
/** @internal */
|
|
45
|
+
export declare const validateBlueBundlesV1NativeFunding: (params: {
|
|
46
|
+
chainId: number;
|
|
47
|
+
token: Address;
|
|
48
|
+
fundedAmount: bigint;
|
|
49
|
+
nativeAmount?: bigint;
|
|
50
|
+
requirementSignature?: BlueBundlesV1TokenRequirementSignature;
|
|
51
|
+
}) => bigint;
|
|
52
|
+
/** @internal */
|
|
53
|
+
export declare const getBlueBundlesV1TokenPermit: (params: {
|
|
54
|
+
chainId: number;
|
|
55
|
+
userAddress: Address;
|
|
56
|
+
token: Address;
|
|
57
|
+
amount: bigint;
|
|
58
|
+
requirementSignature?: TokenRequirementSignature;
|
|
59
|
+
}) => BlueBundlesV1TokenPermit;
|
|
60
|
+
/** @internal */
|
|
61
|
+
export declare const getBlueBundlesV1SignedAuthorization: (params: {
|
|
62
|
+
chainId: number;
|
|
63
|
+
userAddress: Address;
|
|
64
|
+
authorizationSignature?: AuthorizationRequirementSignature;
|
|
65
|
+
}) => BlueBundlesV1SignedAuthorization;
|
|
66
|
+
/** @internal */
|
|
67
|
+
export declare const getBlueBundlesV1PublicAllocations: (reallocations: readonly VaultV2BlueReallocation[], targetMarketParams: MarketParams) => {
|
|
68
|
+
vault: `0x${string}`;
|
|
69
|
+
adapter: `0x${string}`;
|
|
70
|
+
marketParams: MarketParams;
|
|
71
|
+
fromIdle: boolean;
|
|
72
|
+
sourceAdapter: `0x${string}`;
|
|
73
|
+
sourceMarketParams: MarketParams;
|
|
74
|
+
assets: bigint;
|
|
75
|
+
penalty: bigint;
|
|
76
|
+
}[];
|
|
77
|
+
/** @internal */
|
|
78
|
+
export declare const getBlueBundlesV1PenaltyAssets: (reallocations: readonly {
|
|
79
|
+
assets: bigint;
|
|
80
|
+
penalty: bigint;
|
|
81
|
+
}[]) => bigint;
|
|
82
|
+
/** @internal */
|
|
83
|
+
export declare const getBlueBundlesV1ReferralFeeAssets: (assets: bigint, referralFeePct: bigint) => bigint;
|
|
84
|
+
/** @internal */
|
|
85
|
+
export declare const selectBlueBundlesV1RequirementSignatures: (signatures: readonly RequirementSignature[] | undefined, accepts: {
|
|
86
|
+
token?: boolean;
|
|
87
|
+
authorization?: boolean;
|
|
88
|
+
}) => {
|
|
89
|
+
token?: BlueBundlesV1TokenRequirementSignature;
|
|
90
|
+
authorization?: AuthorizationRequirementSignature;
|
|
91
|
+
};
|
|
92
|
+
/** @internal */
|
|
93
|
+
export declare const finalizeBlueBundlesV1Transaction: <TAction extends BaseAction>(params: {
|
|
94
|
+
common: BlueBundlesV1CommonParams;
|
|
95
|
+
value: bigint;
|
|
96
|
+
data: Hex;
|
|
97
|
+
action: TAction;
|
|
98
|
+
}) => Readonly<Transaction<TAction>>;
|
|
99
|
+
export {};
|