@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,97 +1,121 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import { buildAssetFundingActions } from "./buildAssetFundingActions.js";
|
|
1
|
+
import { encodeFunctionData, maxUint256 } from "viem";
|
|
2
|
+
import { blueBundlesV1Abi } from "../../abis.js";
|
|
3
|
+
import { InputExceedsMaxError, NonPositiveInputError, } from "../../types/index.js";
|
|
4
|
+
import { finalizeBlueBundlesV1Transaction, getBlueBundlesV1TokenPermit, normalizeBlueBundlesV1CommonParams, validateBlueBundlesV1NativeFunding, } from "./common.js";
|
|
6
5
|
/**
|
|
7
|
-
*
|
|
6
|
+
* Encodes a direct BlueBundlesV1 loan-asset supply transaction.
|
|
8
7
|
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
* wNative for that path. Uses `maxSharePrice` to protect against share-price inflation between
|
|
12
|
-
* transaction construction and execution.
|
|
8
|
+
* `assets` is the gross funded amount; BlueBundlesV1 deducts the referral fee before supplying.
|
|
9
|
+
* This route has no Bundler3 share-price bound or `slippageTolerance` input.
|
|
13
10
|
*
|
|
14
|
-
*
|
|
15
|
-
*
|
|
16
|
-
* @param params.market.
|
|
17
|
-
* @param params.
|
|
18
|
-
* @param params.args.
|
|
19
|
-
*
|
|
20
|
-
* @param params.args.
|
|
21
|
-
* @param params.args.
|
|
22
|
-
*
|
|
23
|
-
* @param params.args.
|
|
24
|
-
*
|
|
25
|
-
* @
|
|
26
|
-
*
|
|
27
|
-
* @
|
|
28
|
-
*
|
|
29
|
-
* @throws {
|
|
30
|
-
* @throws {
|
|
31
|
-
* @throws {
|
|
32
|
-
* @throws {
|
|
33
|
-
*
|
|
34
|
-
* @throws {
|
|
35
|
-
*
|
|
36
|
-
* @throws {
|
|
37
|
-
*
|
|
11
|
+
* @param params - Supply encoding parameters.
|
|
12
|
+
* @param params.market.chainId - Chain containing the BlueBundlesV1 deployment.
|
|
13
|
+
* @param params.market.marketParams - Scoped Morpho Blue market parameters.
|
|
14
|
+
* @param params.args.userAddress - User funding and receiving the position.
|
|
15
|
+
* @param params.args.assets - Gross loan-token funding amount.
|
|
16
|
+
* @param params.args.nativeAmount - Exclusive native funding; must equal `assets`.
|
|
17
|
+
* @param params.args.deadline - Final call deadline in Unix seconds.
|
|
18
|
+
* @param params.args.referralFeePct - Optional WAD-scaled fee below 100%.
|
|
19
|
+
* @param params.args.referralFeeRecipient - Recipient required for a positive fee.
|
|
20
|
+
* @param params.args.requirementSignature - Optional ERC-2612 or Permit2 SignatureTransfer result.
|
|
21
|
+
* @param params.metadata - Optional transaction metadata.
|
|
22
|
+
* @returns A deep-frozen `Readonly<Transaction<BlueSupplyAction>>` whose `to` address is
|
|
23
|
+
* BlueBundlesV1 and whose `action` records the normalized supply inputs.
|
|
24
|
+
* @throws {NonPositiveInputError} when `assets` or `deadline` is not positive.
|
|
25
|
+
* @throws {NegativeInputError} when `nativeAmount` or `referralFeePct` is negative.
|
|
26
|
+
* @throws {InputExceedsMaxError} when `assets` exceeds `uint256` or `referralFeePct` is at least WAD.
|
|
27
|
+
* @throws {MissingReferralFeeRecipientError} when a positive fee has no recipient.
|
|
28
|
+
* @throws {NativeFundingAmountMismatchError} when native funding does not equal `assets`.
|
|
29
|
+
* @throws {ChainWNativeMissingError} when native funding is requested on a chain without wNative.
|
|
30
|
+
* @throws {NativeAmountOnNonWNativeAssetError} when native funding targets another token.
|
|
31
|
+
* @throws {UnexpectedRequirementSignatureError} when native funding also supplies a token signature.
|
|
32
|
+
* @throws {DepositOwnerMismatchError} when the signed owner differs from `userAddress`.
|
|
33
|
+
* @throws {DepositAssetMismatchError} when the signed asset differs from the loan token.
|
|
34
|
+
* @throws {DepositAmountMismatchError} when the signed amount differs from `assets`.
|
|
35
|
+
* @throws {DepositSpenderMismatchError} when the signed spender is not BlueBundlesV1.
|
|
36
|
+
* @throws {BlueBundlesV1RequirementSignatureMismatchError} when the signature kind or encoding is invalid.
|
|
37
|
+
* @throws {UnsupportedChainIdError} when the chain is absent from the address registry.
|
|
38
|
+
* @throws {UnknownAddressError} when BlueBundlesV1 is not registered.
|
|
38
39
|
* @example
|
|
39
40
|
* ```ts
|
|
41
|
+
* import { markets } from "@morpho-org/morpho-test";
|
|
40
42
|
* import { blueSupply } from "@morpho-org/morpho-sdk";
|
|
43
|
+
* import { zeroAddress } from "viem";
|
|
44
|
+
* import { mainnet } from "viem/chains";
|
|
41
45
|
*
|
|
46
|
+
* const marketParams = markets[mainnet.id].usdc_wbtc;
|
|
42
47
|
* const tx = blueSupply({
|
|
43
|
-
* market: { chainId:
|
|
48
|
+
* market: { chainId: mainnet.id, marketParams },
|
|
44
49
|
* args: {
|
|
45
|
-
*
|
|
46
|
-
*
|
|
47
|
-
*
|
|
50
|
+
* userAddress: zeroAddress,
|
|
51
|
+
* assets: 1_000_000n,
|
|
52
|
+
* deadline: 1_900_000_000n,
|
|
48
53
|
* },
|
|
49
54
|
* });
|
|
50
55
|
* // tx satisfies Readonly<Transaction<BlueSupplyAction>>
|
|
51
56
|
* ```
|
|
52
57
|
*/
|
|
53
|
-
export const blueSupply = (
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
throw new NegativeInputError("nativeAmount", nativeAmount);
|
|
59
|
-
}
|
|
60
|
-
if (maxSharePrice < 0n) {
|
|
61
|
-
throw new NegativeInputError("maxSharePrice", maxSharePrice);
|
|
58
|
+
export const blueSupply = (params) => {
|
|
59
|
+
const { chainId, marketParams } = params.market;
|
|
60
|
+
const { assets, userAddress, requirementSignature } = params.args;
|
|
61
|
+
if (assets <= 0n) {
|
|
62
|
+
throw new NonPositiveInputError("assets", assets);
|
|
62
63
|
}
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
64
|
+
if (assets > maxUint256) {
|
|
65
|
+
throw new InputExceedsMaxError({
|
|
66
|
+
field: "assets",
|
|
67
|
+
value: assets,
|
|
68
|
+
max: maxUint256,
|
|
69
|
+
});
|
|
66
70
|
}
|
|
67
|
-
const
|
|
71
|
+
const common = {
|
|
72
|
+
chainId,
|
|
73
|
+
userAddress,
|
|
74
|
+
deadline: params.args.deadline,
|
|
75
|
+
referralFeePct: params.args.referralFeePct,
|
|
76
|
+
referralFeeRecipient: params.args.referralFeeRecipient,
|
|
77
|
+
metadata: params.metadata,
|
|
78
|
+
};
|
|
79
|
+
const { referralFeePct, referralFeeRecipient } = normalizeBlueBundlesV1CommonParams(common);
|
|
80
|
+
const value = validateBlueBundlesV1NativeFunding({
|
|
68
81
|
chainId,
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
nativeAmount: nativeAmount
|
|
82
|
+
token: marketParams.loanToken,
|
|
83
|
+
fundedAmount: assets,
|
|
84
|
+
nativeAmount: params.args.nativeAmount,
|
|
72
85
|
requirementSignature,
|
|
73
86
|
});
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
87
|
+
const tokenPermit = getBlueBundlesV1TokenPermit({
|
|
88
|
+
chainId,
|
|
89
|
+
userAddress,
|
|
90
|
+
token: marketParams.loanToken,
|
|
91
|
+
amount: assets,
|
|
92
|
+
requirementSignature,
|
|
77
93
|
});
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
value
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
94
|
+
return finalizeBlueBundlesV1Transaction({
|
|
95
|
+
common,
|
|
96
|
+
value,
|
|
97
|
+
data: encodeFunctionData({
|
|
98
|
+
abi: blueBundlesV1Abi,
|
|
99
|
+
functionName: "blueBundlesV1Supply",
|
|
100
|
+
args: [
|
|
101
|
+
marketParams,
|
|
102
|
+
assets,
|
|
103
|
+
tokenPermit,
|
|
104
|
+
referralFeePct,
|
|
105
|
+
referralFeeRecipient,
|
|
106
|
+
params.args.deadline,
|
|
107
|
+
],
|
|
108
|
+
}),
|
|
87
109
|
action: {
|
|
88
110
|
type: "blueSupply",
|
|
89
111
|
args: {
|
|
90
112
|
market: marketParams.id,
|
|
91
|
-
|
|
92
|
-
onBehalf,
|
|
93
|
-
|
|
94
|
-
|
|
113
|
+
assets,
|
|
114
|
+
onBehalf: userAddress,
|
|
115
|
+
nativeAmount: value > 0n ? value : undefined,
|
|
116
|
+
referralFeePct,
|
|
117
|
+
referralFeeRecipient,
|
|
118
|
+
deadline: params.args.deadline,
|
|
95
119
|
},
|
|
96
120
|
},
|
|
97
121
|
});
|
|
@@ -1,60 +1,83 @@
|
|
|
1
1
|
import type { MarketParams } from "@morpho-org/blue-sdk";
|
|
2
|
-
import type
|
|
3
|
-
import {
|
|
2
|
+
import { type Address } from "viem";
|
|
3
|
+
import type { BlueBundlesV1TokenRequirementSignature, BlueSupplyCollateralAction, Metadata, Transaction } from "../../types/index.js";
|
|
4
4
|
/** Parameters for {@link blueSupplyCollateral}. */
|
|
5
5
|
export interface BlueSupplyCollateralParams {
|
|
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
|
-
|
|
11
|
+
/** Direct BlueBundlesV1 collateral-supply arguments. */
|
|
12
|
+
readonly args: {
|
|
13
|
+
/** User whose collateral position is credited. */
|
|
14
|
+
readonly userAddress: Address;
|
|
15
|
+
/** Gross collateral assets supplied. */
|
|
16
|
+
readonly collateralAssets: bigint;
|
|
17
|
+
/** Full native collateral funding; must equal `collateralAssets`. */
|
|
18
|
+
readonly nativeAmount?: bigint;
|
|
19
|
+
/** Final call deadline in Unix seconds. */
|
|
20
|
+
readonly deadline: bigint;
|
|
21
|
+
/** Optional WAD-scaled referral fee, strictly below 100%. */
|
|
22
|
+
readonly referralFeePct?: bigint;
|
|
23
|
+
/** Recipient required when `referralFeePct` is positive. */
|
|
24
|
+
readonly referralFeeRecipient?: Address;
|
|
25
|
+
/** Optional collateral ERC-2612 or Permit2 SignatureTransfer result. */
|
|
26
|
+
readonly requirementSignature?: BlueBundlesV1TokenRequirementSignature;
|
|
15
27
|
};
|
|
16
|
-
metadata
|
|
28
|
+
/** Optional transaction metadata suffix. */
|
|
29
|
+
readonly metadata?: Metadata;
|
|
17
30
|
}
|
|
18
31
|
/**
|
|
19
|
-
*
|
|
32
|
+
* Encodes a pure collateral supply through BlueBundlesV1.
|
|
20
33
|
*
|
|
21
|
-
*
|
|
22
|
-
*
|
|
23
|
-
* the chain's wNative for that path.
|
|
34
|
+
* Delegates to {@link blueSupplyCollateralBorrow} with a zero borrow leg and an unrestricted LTV
|
|
35
|
+
* cap. Native funding is exclusive with ERC-20 funding and no Bundler3 action is encoded.
|
|
24
36
|
*
|
|
25
|
-
*
|
|
26
|
-
*
|
|
27
|
-
* @param params.market.
|
|
28
|
-
* @param params.
|
|
29
|
-
* @param params.args.
|
|
30
|
-
*
|
|
31
|
-
* @param params.args.
|
|
32
|
-
* @param params.args.
|
|
33
|
-
* @param params.args.
|
|
34
|
-
*
|
|
35
|
-
* @param params.metadata - Optional
|
|
36
|
-
* @returns A deep-frozen `Transaction<BlueSupplyCollateralAction
|
|
37
|
-
*
|
|
38
|
-
* @throws {NegativeInputError} when
|
|
39
|
-
* @throws {NonPositiveInputError} when
|
|
40
|
-
* @throws {
|
|
41
|
-
* @throws {
|
|
42
|
-
*
|
|
43
|
-
* @throws {
|
|
44
|
-
*
|
|
45
|
-
* @throws {
|
|
46
|
-
*
|
|
47
|
-
* @throws {
|
|
48
|
-
*
|
|
37
|
+
* @param params - Collateral-supply encoding parameters.
|
|
38
|
+
* @param params.market.chainId - Chain containing BlueBundlesV1.
|
|
39
|
+
* @param params.market.marketParams - Scoped Morpho Blue market parameters.
|
|
40
|
+
* @param params.args.userAddress - User whose collateral position is credited.
|
|
41
|
+
* @param params.args.collateralAssets - Gross collateral assets supplied.
|
|
42
|
+
* @param params.args.nativeAmount - Exclusive native collateral funding.
|
|
43
|
+
* @param params.args.deadline - Final call deadline in Unix seconds.
|
|
44
|
+
* @param params.args.referralFeePct - Optional WAD-scaled referral fee.
|
|
45
|
+
* @param params.args.referralFeeRecipient - Recipient required for a positive fee.
|
|
46
|
+
* @param params.args.requirementSignature - Optional collateral-token signature.
|
|
47
|
+
* @param params.metadata - Optional transaction metadata.
|
|
48
|
+
* @returns A deep-frozen `Readonly<Transaction<BlueSupplyCollateralAction>>` whose calldata
|
|
49
|
+
* invokes the combined BlueBundlesV1 entrypoint with a zero borrow leg.
|
|
50
|
+
* @throws {NegativeInputError} when an amount or fee is negative.
|
|
51
|
+
* @throws {NonPositiveInputError} when collateral or deadline is not positive.
|
|
52
|
+
* @throws {NativeFundingAmountMismatchError} when native funding is partial or mixed.
|
|
53
|
+
* @throws {ChainWNativeMissingError} when native funding is requested without a registered wNative.
|
|
54
|
+
* @throws {NativeAmountOnNonWNativeAssetError} when native funding targets another collateral token.
|
|
55
|
+
* @throws {UnexpectedRequirementSignatureError} when native funding also supplies a token signature.
|
|
56
|
+
* @throws {DepositOwnerMismatchError} when the signed owner differs from `userAddress`.
|
|
57
|
+
* @throws {DepositAssetMismatchError} when the signed asset differs from the collateral token.
|
|
58
|
+
* @throws {DepositAmountMismatchError} when the signed amount differs from `collateralAssets`.
|
|
59
|
+
* @throws {DepositSpenderMismatchError} when the signed spender is not BlueBundlesV1.
|
|
60
|
+
* @throws {BlueBundlesV1RequirementSignatureMismatchError} when a signature cannot be encoded safely.
|
|
61
|
+
* @throws {InputExceedsMaxError} when the referral fee is at least WAD.
|
|
62
|
+
* @throws {MissingReferralFeeRecipientError} when a positive fee has no recipient.
|
|
63
|
+
* @throws {UnsupportedChainIdError} when the chain is absent from the registry.
|
|
64
|
+
* @throws {UnknownAddressError} when BlueBundlesV1 is not registered.
|
|
49
65
|
* @example
|
|
50
66
|
* ```ts
|
|
67
|
+
* import { markets } from "@morpho-org/morpho-test";
|
|
51
68
|
* import { blueSupplyCollateral } from "@morpho-org/morpho-sdk";
|
|
69
|
+
* import { zeroAddress } from "viem";
|
|
70
|
+
* import { mainnet } from "viem/chains";
|
|
52
71
|
*
|
|
53
72
|
* const tx = blueSupplyCollateral({
|
|
54
|
-
* market: { chainId:
|
|
55
|
-
* args: {
|
|
73
|
+
* market: { chainId: mainnet.id, marketParams: markets[mainnet.id].usdc_wbtc },
|
|
74
|
+
* args: {
|
|
75
|
+
* userAddress: zeroAddress,
|
|
76
|
+
* collateralAssets: 1_000_000_000_000_000_000n,
|
|
77
|
+
* deadline: 1_900_000_000n,
|
|
78
|
+
* },
|
|
56
79
|
* });
|
|
57
80
|
* // tx satisfies Readonly<Transaction<BlueSupplyCollateralAction>>
|
|
58
81
|
* ```
|
|
59
82
|
*/
|
|
60
|
-
export declare const blueSupplyCollateral: (
|
|
83
|
+
export declare const blueSupplyCollateral: (params: BlueSupplyCollateralParams) => Readonly<Transaction<BlueSupplyCollateralAction>>;
|
|
@@ -1,86 +1,69 @@
|
|
|
1
1
|
import { deepFreeze } from "@morpho-org/morpho-ts";
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import { NegativeInputError, NonPositiveInputError, } from "../../types/index.js";
|
|
5
|
-
import { buildAssetFundingActions } from "./buildAssetFundingActions.js";
|
|
2
|
+
import { maxUint256 } from "viem";
|
|
3
|
+
import { blueSupplyCollateralBorrow } from "./supplyCollateralBorrow.js";
|
|
6
4
|
/**
|
|
7
|
-
*
|
|
5
|
+
* Encodes a pure collateral supply through BlueBundlesV1.
|
|
8
6
|
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
* the chain's wNative for that path.
|
|
7
|
+
* Delegates to {@link blueSupplyCollateralBorrow} with a zero borrow leg and an unrestricted LTV
|
|
8
|
+
* cap. Native funding is exclusive with ERC-20 funding and no Bundler3 action is encoded.
|
|
12
9
|
*
|
|
13
|
-
*
|
|
14
|
-
*
|
|
15
|
-
* @param params.market.
|
|
16
|
-
* @param params.
|
|
17
|
-
* @param params.args.
|
|
18
|
-
*
|
|
19
|
-
* @param params.args.
|
|
20
|
-
* @param params.args.
|
|
21
|
-
* @param params.args.
|
|
22
|
-
*
|
|
23
|
-
* @param params.metadata - Optional
|
|
24
|
-
* @returns A deep-frozen `Transaction<BlueSupplyCollateralAction
|
|
25
|
-
*
|
|
26
|
-
* @throws {NegativeInputError} when
|
|
27
|
-
* @throws {NonPositiveInputError} when
|
|
28
|
-
* @throws {
|
|
29
|
-
* @throws {
|
|
30
|
-
*
|
|
31
|
-
* @throws {
|
|
32
|
-
*
|
|
33
|
-
* @throws {
|
|
34
|
-
*
|
|
35
|
-
* @throws {
|
|
36
|
-
*
|
|
10
|
+
* @param params - Collateral-supply encoding parameters.
|
|
11
|
+
* @param params.market.chainId - Chain containing BlueBundlesV1.
|
|
12
|
+
* @param params.market.marketParams - Scoped Morpho Blue market parameters.
|
|
13
|
+
* @param params.args.userAddress - User whose collateral position is credited.
|
|
14
|
+
* @param params.args.collateralAssets - Gross collateral assets supplied.
|
|
15
|
+
* @param params.args.nativeAmount - Exclusive native collateral funding.
|
|
16
|
+
* @param params.args.deadline - Final call deadline in Unix seconds.
|
|
17
|
+
* @param params.args.referralFeePct - Optional WAD-scaled referral fee.
|
|
18
|
+
* @param params.args.referralFeeRecipient - Recipient required for a positive fee.
|
|
19
|
+
* @param params.args.requirementSignature - Optional collateral-token signature.
|
|
20
|
+
* @param params.metadata - Optional transaction metadata.
|
|
21
|
+
* @returns A deep-frozen `Readonly<Transaction<BlueSupplyCollateralAction>>` whose calldata
|
|
22
|
+
* invokes the combined BlueBundlesV1 entrypoint with a zero borrow leg.
|
|
23
|
+
* @throws {NegativeInputError} when an amount or fee is negative.
|
|
24
|
+
* @throws {NonPositiveInputError} when collateral or deadline is not positive.
|
|
25
|
+
* @throws {NativeFundingAmountMismatchError} when native funding is partial or mixed.
|
|
26
|
+
* @throws {ChainWNativeMissingError} when native funding is requested without a registered wNative.
|
|
27
|
+
* @throws {NativeAmountOnNonWNativeAssetError} when native funding targets another collateral token.
|
|
28
|
+
* @throws {UnexpectedRequirementSignatureError} when native funding also supplies a token signature.
|
|
29
|
+
* @throws {DepositOwnerMismatchError} when the signed owner differs from `userAddress`.
|
|
30
|
+
* @throws {DepositAssetMismatchError} when the signed asset differs from the collateral token.
|
|
31
|
+
* @throws {DepositAmountMismatchError} when the signed amount differs from `collateralAssets`.
|
|
32
|
+
* @throws {DepositSpenderMismatchError} when the signed spender is not BlueBundlesV1.
|
|
33
|
+
* @throws {BlueBundlesV1RequirementSignatureMismatchError} when a signature cannot be encoded safely.
|
|
34
|
+
* @throws {InputExceedsMaxError} when the referral fee is at least WAD.
|
|
35
|
+
* @throws {MissingReferralFeeRecipientError} when a positive fee has no recipient.
|
|
36
|
+
* @throws {UnsupportedChainIdError} when the chain is absent from the registry.
|
|
37
|
+
* @throws {UnknownAddressError} when BlueBundlesV1 is not registered.
|
|
37
38
|
* @example
|
|
38
39
|
* ```ts
|
|
40
|
+
* import { markets } from "@morpho-org/morpho-test";
|
|
39
41
|
* import { blueSupplyCollateral } from "@morpho-org/morpho-sdk";
|
|
42
|
+
* import { zeroAddress } from "viem";
|
|
43
|
+
* import { mainnet } from "viem/chains";
|
|
40
44
|
*
|
|
41
45
|
* const tx = blueSupplyCollateral({
|
|
42
|
-
* market: { chainId:
|
|
43
|
-
* args: {
|
|
46
|
+
* market: { chainId: mainnet.id, marketParams: markets[mainnet.id].usdc_wbtc },
|
|
47
|
+
* args: {
|
|
48
|
+
* userAddress: zeroAddress,
|
|
49
|
+
* collateralAssets: 1_000_000_000_000_000_000n,
|
|
50
|
+
* deadline: 1_900_000_000n,
|
|
51
|
+
* },
|
|
44
52
|
* });
|
|
45
53
|
* // tx satisfies Readonly<Transaction<BlueSupplyCollateralAction>>
|
|
46
54
|
* ```
|
|
47
55
|
*/
|
|
48
|
-
export const blueSupplyCollateral = (
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
if (totalCollateral === 0n) {
|
|
57
|
-
throw new NonPositiveInputError("totalCollateral", totalCollateral);
|
|
58
|
-
}
|
|
59
|
-
const actions = buildAssetFundingActions({
|
|
60
|
-
chainId,
|
|
61
|
-
asset: marketParams.collateralToken,
|
|
62
|
-
erc20Amount: amount,
|
|
63
|
-
nativeAmount: nativeAmount ?? 0n,
|
|
64
|
-
requirementSignature,
|
|
65
|
-
});
|
|
66
|
-
actions.push({
|
|
67
|
-
type: "morphoSupplyCollateral",
|
|
68
|
-
args: [marketParams, totalCollateral, onBehalf, [], false],
|
|
56
|
+
export const blueSupplyCollateral = (params) => {
|
|
57
|
+
const transaction = blueSupplyCollateralBorrow({
|
|
58
|
+
...params,
|
|
59
|
+
args: {
|
|
60
|
+
...params.args,
|
|
61
|
+
borrowAssets: 0n,
|
|
62
|
+
maxLtv: maxUint256,
|
|
63
|
+
},
|
|
69
64
|
});
|
|
70
|
-
let tx = BundlerAction.encodeBundle(chainId, actions);
|
|
71
|
-
if (metadata) {
|
|
72
|
-
tx = addTransactionMetadata(tx, metadata);
|
|
73
|
-
}
|
|
74
65
|
return deepFreeze({
|
|
75
|
-
...
|
|
76
|
-
action: {
|
|
77
|
-
type: "blueSupplyCollateral",
|
|
78
|
-
args: {
|
|
79
|
-
market: marketParams.id,
|
|
80
|
-
amount: totalCollateral,
|
|
81
|
-
onBehalf,
|
|
82
|
-
nativeAmount,
|
|
83
|
-
},
|
|
84
|
-
},
|
|
66
|
+
...transaction,
|
|
67
|
+
action: { ...transaction.action, type: "blueSupplyCollateral" },
|
|
85
68
|
});
|
|
86
69
|
};
|