@morpho-org/morpho-sdk 4.2.0 → 5.0.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/README.md +12 -12
- package/lib/cjs/actions/blue/borrow.d.ts +12 -2
- package/lib/cjs/actions/blue/borrow.js +7 -1
- package/lib/cjs/actions/blue/refinance.d.ts +13 -3
- package/lib/cjs/actions/blue/refinance.js +8 -2
- package/lib/cjs/actions/blue/repay.d.ts +6 -5
- package/lib/cjs/actions/blue/repay.js +10 -18
- package/lib/cjs/actions/blue/repayWithdrawCollateral.d.ts +15 -6
- package/lib/cjs/actions/blue/repayWithdrawCollateral.js +16 -18
- package/lib/cjs/actions/blue/supply.d.ts +7 -7
- package/lib/cjs/actions/blue/supply.js +10 -20
- package/lib/cjs/actions/blue/supplyCollateral.d.ts +8 -8
- package/lib/cjs/actions/blue/supplyCollateral.js +11 -21
- package/lib/cjs/actions/blue/supplyCollateralBorrow.d.ts +18 -6
- package/lib/cjs/actions/blue/supplyCollateralBorrow.js +17 -19
- package/lib/cjs/actions/blue/withdraw.d.ts +10 -2
- package/lib/cjs/actions/blue/withdraw.js +7 -1
- package/lib/cjs/actions/index.d.ts +1 -0
- package/lib/cjs/actions/index.js +1 -0
- package/lib/cjs/actions/requirements/blue/getBlueAuthorizationRequirement.d.ts +49 -0
- package/lib/cjs/actions/requirements/blue/getBlueAuthorizationRequirement.js +111 -0
- package/lib/cjs/actions/requirements/blue/index.d.ts +1 -0
- package/lib/cjs/actions/requirements/blue/index.js +17 -0
- package/lib/cjs/actions/requirements/encode/encodeBlueSignatureAuthorization.d.ts +55 -0
- package/lib/cjs/actions/requirements/encode/encodeBlueSignatureAuthorization.js +89 -0
- package/lib/cjs/actions/requirements/encode/encodeErc20Approval.d.ts +6 -5
- package/lib/cjs/actions/requirements/encode/encodeErc20Approval.js +17 -5
- package/lib/cjs/actions/requirements/encode/encodeErc20Permit.d.ts +9 -7
- package/lib/cjs/actions/requirements/encode/encodeErc20Permit.js +18 -4
- package/lib/cjs/actions/requirements/encode/{encodeErc20Permit2.d.ts → encodeErc20Permit2Approve.d.ts} +11 -13
- package/lib/cjs/actions/requirements/encode/{encodeErc20Permit2.js → encodeErc20Permit2Approve.js} +10 -14
- package/lib/cjs/actions/requirements/encode/index.d.ts +2 -1
- package/lib/cjs/actions/requirements/encode/index.js +2 -1
- package/lib/cjs/actions/requirements/{getRequirements.d.ts → generalAdapter/getGeneralAdapterRequirements.d.ts} +34 -20
- package/lib/cjs/actions/requirements/generalAdapter/getGeneralAdapterRequirements.js +151 -0
- package/lib/{esm/actions/requirements/getRequirementsPermit.d.ts → cjs/actions/requirements/generalAdapter/getGeneralAdapterRequirementsPermit.d.ts} +6 -14
- package/lib/cjs/actions/requirements/generalAdapter/getGeneralAdapterRequirementsPermit.js +50 -0
- package/lib/cjs/actions/requirements/generalAdapter/getGeneralAdapterRequirementsPermit2.d.ts +57 -0
- package/lib/cjs/actions/requirements/generalAdapter/getGeneralAdapterRequirementsPermit2.js +74 -0
- package/lib/cjs/actions/requirements/generalAdapter/index.d.ts +3 -0
- package/lib/cjs/actions/requirements/generalAdapter/index.js +19 -0
- package/lib/cjs/actions/requirements/getRequirementsApproval.d.ts +3 -2
- package/lib/cjs/actions/requirements/getRequirementsApproval.js +3 -2
- package/lib/cjs/actions/requirements/index.d.ts +2 -5
- package/lib/cjs/actions/requirements/index.js +2 -5
- package/lib/cjs/actions/signatures/getBlueAuthorizationAction.d.ts +29 -0
- package/lib/cjs/actions/signatures/getBlueAuthorizationAction.js +48 -0
- package/lib/{esm/actions/requirements/getRequirementsAction.d.ts → cjs/actions/signatures/getTokenRequirementActions.d.ts} +17 -17
- package/lib/cjs/actions/{requirements/getRequirementsAction.js → signatures/getTokenRequirementActions.js} +26 -13
- package/lib/cjs/actions/signatures/index.d.ts +2 -0
- package/lib/cjs/actions/signatures/index.js +18 -0
- package/lib/cjs/actions/vaultV1/deposit.d.ts +6 -8
- package/lib/cjs/actions/vaultV1/deposit.js +11 -21
- package/lib/cjs/actions/vaultV1/migrateToV2.d.ts +6 -6
- package/lib/cjs/actions/vaultV1/migrateToV2.js +12 -20
- package/lib/cjs/actions/vaultV2/deposit.d.ts +6 -8
- package/lib/cjs/actions/vaultV2/deposit.js +11 -21
- package/lib/cjs/addresses.d.ts +2 -2
- package/lib/cjs/addresses.js +2 -1
- package/lib/cjs/bundler/actions.d.ts +44 -4
- package/lib/cjs/bundler/actions.js +75 -2
- package/lib/cjs/bundler/types.d.ts +6 -0
- package/lib/cjs/constants.d.ts +2 -2
- package/lib/cjs/constants.js +3 -3
- package/lib/cjs/entities/blue/blue.d.ts +58 -33
- package/lib/cjs/entities/blue/blue.js +171 -125
- package/lib/cjs/entities/reallocationData.d.ts +0 -44
- package/lib/cjs/entities/reallocationData.js +3 -50
- package/lib/cjs/entities/vaultV1/vaultV1.d.ts +9 -9
- package/lib/cjs/entities/vaultV1/vaultV1.js +44 -34
- package/lib/cjs/entities/vaultV2/vaultV2.d.ts +6 -6
- package/lib/cjs/entities/vaultV2/vaultV2.js +21 -16
- package/lib/cjs/errors.d.ts +3 -2
- package/lib/cjs/errors.js +5 -2
- package/lib/cjs/helpers/validate.d.ts +2 -2
- package/lib/cjs/helpers/validate.js +1 -1
- package/lib/cjs/types/action.d.ts +113 -9
- package/lib/cjs/types/action.js +79 -5
- package/lib/cjs/types/error.d.ts +73 -0
- package/lib/cjs/types/error.js +89 -4
- package/lib/cjs/types.d.ts +2 -1
- package/lib/cjs/utils.d.ts +1 -1
- package/lib/cjs/utils.js +2 -3
- package/lib/esm/actions/blue/borrow.d.ts +12 -2
- package/lib/esm/actions/blue/borrow.js +7 -1
- package/lib/esm/actions/blue/refinance.d.ts +13 -3
- package/lib/esm/actions/blue/refinance.js +8 -2
- package/lib/esm/actions/blue/repay.d.ts +6 -5
- package/lib/esm/actions/blue/repay.js +10 -18
- package/lib/esm/actions/blue/repayWithdrawCollateral.d.ts +15 -6
- package/lib/esm/actions/blue/repayWithdrawCollateral.js +16 -18
- package/lib/esm/actions/blue/supply.d.ts +7 -7
- package/lib/esm/actions/blue/supply.js +10 -20
- package/lib/esm/actions/blue/supplyCollateral.d.ts +8 -8
- package/lib/esm/actions/blue/supplyCollateral.js +11 -21
- package/lib/esm/actions/blue/supplyCollateralBorrow.d.ts +18 -6
- package/lib/esm/actions/blue/supplyCollateralBorrow.js +17 -19
- package/lib/esm/actions/blue/withdraw.d.ts +10 -2
- package/lib/esm/actions/blue/withdraw.js +7 -1
- package/lib/esm/actions/index.d.ts +1 -0
- package/lib/esm/actions/index.js +1 -0
- package/lib/esm/actions/requirements/blue/getBlueAuthorizationRequirement.d.ts +49 -0
- package/lib/esm/actions/requirements/blue/getBlueAuthorizationRequirement.js +107 -0
- package/lib/esm/actions/requirements/blue/index.d.ts +1 -0
- package/lib/esm/actions/requirements/blue/index.js +1 -0
- package/lib/esm/actions/requirements/encode/encodeBlueSignatureAuthorization.d.ts +55 -0
- package/lib/esm/actions/requirements/encode/encodeBlueSignatureAuthorization.js +85 -0
- package/lib/esm/actions/requirements/encode/encodeErc20Approval.d.ts +6 -5
- package/lib/esm/actions/requirements/encode/encodeErc20Approval.js +19 -7
- package/lib/esm/actions/requirements/encode/encodeErc20Permit.d.ts +9 -7
- package/lib/esm/actions/requirements/encode/encodeErc20Permit.js +20 -6
- package/lib/esm/actions/requirements/encode/{encodeErc20Permit2.d.ts → encodeErc20Permit2Approve.d.ts} +11 -13
- package/lib/esm/actions/requirements/encode/{encodeErc20Permit2.js → encodeErc20Permit2Approve.js} +8 -12
- package/lib/esm/actions/requirements/encode/index.d.ts +2 -1
- package/lib/esm/actions/requirements/encode/index.js +2 -1
- package/lib/esm/actions/requirements/{getRequirements.d.ts → generalAdapter/getGeneralAdapterRequirements.d.ts} +34 -20
- package/lib/esm/actions/requirements/generalAdapter/getGeneralAdapterRequirements.js +147 -0
- package/lib/{cjs/actions/requirements/getRequirementsPermit.d.ts → esm/actions/requirements/generalAdapter/getGeneralAdapterRequirementsPermit.d.ts} +6 -14
- package/lib/esm/actions/requirements/generalAdapter/getGeneralAdapterRequirementsPermit.js +46 -0
- package/lib/esm/actions/requirements/generalAdapter/getGeneralAdapterRequirementsPermit2.d.ts +57 -0
- package/lib/esm/actions/requirements/generalAdapter/getGeneralAdapterRequirementsPermit2.js +70 -0
- package/lib/esm/actions/requirements/generalAdapter/index.d.ts +3 -0
- package/lib/esm/actions/requirements/generalAdapter/index.js +3 -0
- package/lib/esm/actions/requirements/getRequirementsApproval.d.ts +3 -2
- package/lib/esm/actions/requirements/getRequirementsApproval.js +3 -2
- package/lib/esm/actions/requirements/index.d.ts +2 -5
- package/lib/esm/actions/requirements/index.js +2 -5
- package/lib/esm/actions/signatures/getBlueAuthorizationAction.d.ts +29 -0
- package/lib/esm/actions/signatures/getBlueAuthorizationAction.js +44 -0
- package/lib/{cjs/actions/requirements/getRequirementsAction.d.ts → esm/actions/signatures/getTokenRequirementActions.d.ts} +17 -17
- package/lib/esm/actions/{requirements/getRequirementsAction.js → signatures/getTokenRequirementActions.js} +24 -11
- package/lib/esm/actions/signatures/index.d.ts +2 -0
- package/lib/esm/actions/signatures/index.js +2 -0
- package/lib/esm/actions/vaultV1/deposit.d.ts +6 -8
- package/lib/esm/actions/vaultV1/deposit.js +11 -21
- package/lib/esm/actions/vaultV1/migrateToV2.d.ts +6 -6
- package/lib/esm/actions/vaultV1/migrateToV2.js +12 -20
- package/lib/esm/actions/vaultV2/deposit.d.ts +6 -8
- package/lib/esm/actions/vaultV2/deposit.js +11 -21
- package/lib/esm/addresses.d.ts +2 -2
- package/lib/esm/addresses.js +1 -1
- package/lib/esm/bundler/actions.d.ts +44 -4
- package/lib/esm/bundler/actions.js +77 -4
- package/lib/esm/bundler/types.d.ts +6 -0
- package/lib/esm/constants.d.ts +2 -2
- package/lib/esm/constants.js +2 -2
- package/lib/esm/entities/blue/blue.d.ts +58 -33
- package/lib/esm/entities/blue/blue.js +173 -127
- package/lib/esm/entities/reallocationData.d.ts +0 -44
- package/lib/esm/entities/reallocationData.js +2 -49
- package/lib/esm/entities/vaultV1/vaultV1.d.ts +9 -9
- package/lib/esm/entities/vaultV1/vaultV1.js +46 -36
- package/lib/esm/entities/vaultV2/vaultV2.d.ts +6 -6
- package/lib/esm/entities/vaultV2/vaultV2.js +23 -18
- package/lib/esm/errors.d.ts +3 -2
- package/lib/esm/errors.js +2 -1
- package/lib/esm/helpers/validate.d.ts +2 -2
- package/lib/esm/helpers/validate.js +1 -1
- package/lib/esm/types/action.d.ts +113 -9
- package/lib/esm/types/action.js +75 -4
- package/lib/esm/types/error.d.ts +73 -0
- package/lib/esm/types/error.js +84 -2
- package/lib/esm/types.d.ts +2 -1
- package/lib/esm/utils.d.ts +1 -1
- package/lib/esm/utils.js +1 -1
- package/package.json +6 -6
- package/lib/cjs/actions/requirements/getMorphoAuthorizationRequirement.d.ts +0 -37
- package/lib/cjs/actions/requirements/getMorphoAuthorizationRequirement.js +0 -71
- package/lib/cjs/actions/requirements/getRequirements.js +0 -112
- package/lib/cjs/actions/requirements/getRequirementsPermit.js +0 -57
- package/lib/cjs/actions/requirements/getRequirementsPermit2.d.ts +0 -63
- package/lib/cjs/actions/requirements/getRequirementsPermit2.js +0 -85
- package/lib/esm/actions/requirements/getMorphoAuthorizationRequirement.d.ts +0 -37
- package/lib/esm/actions/requirements/getMorphoAuthorizationRequirement.js +0 -67
- package/lib/esm/actions/requirements/getRequirements.js +0 -108
- package/lib/esm/actions/requirements/getRequirementsPermit.js +0 -53
- package/lib/esm/actions/requirements/getRequirementsPermit2.d.ts +0 -63
- package/lib/esm/actions/requirements/getRequirementsPermit2.js +0 -81
|
@@ -2,9 +2,9 @@ import { AccrualPosition, DEFAULT_SLIPPAGE_TOLERANCE, MathLib, } from "@morpho-o
|
|
|
2
2
|
import { fetchAccrualPosition, fetchMarket, fetchPosition, fetchVault, fetchVaultMarketConfig, } from "@morpho-org/blue-sdk-viem";
|
|
3
3
|
import { Time } from "@morpho-org/morpho-ts";
|
|
4
4
|
import { isAddressEqual } from "viem";
|
|
5
|
-
import { blueBorrow, blueRefinance, blueRepay, blueRepayWithdrawCollateral, blueSupply, blueSupplyCollateral, blueSupplyCollateralBorrow, blueWithdraw, blueWithdrawCollateral,
|
|
5
|
+
import { blueBorrow, blueRefinance, blueRepay, blueRepayWithdrawCollateral, blueSupply, blueSupplyCollateral, blueSupplyCollateralBorrow, blueWithdraw, blueWithdrawCollateral, getBlueAuthorizationRequirement, getGeneralAdapterRequirements, } from "../../actions/index.js";
|
|
6
6
|
import { computeMaxRepaySharePrice, computeMaxSupplySharePrice, computeMinBorrowSharePrice, computeMinWithdrawSharePrice, computeReallocations, validateAccrualPosition, validateChainId, validateNativeAsset, validatePositionHealth, validatePositionHealthAfterWithdraw, validateRepayAmount, validateRepayShares, validateSlippageTolerance, validateWithdrawAmount, validateWithdrawShares, } from "../../helpers/index.js";
|
|
7
|
-
import { BorrowAmountAndSharesExclusiveError, MarketIdMismatchError, MissingAccrualPositionError, MutuallyExclusiveRepayAmountsError, MutuallyExclusiveWithdrawAmountsError, NegativeBorrowSharesError, NegativeNativeAmountError, NegativeSupplyAmountError, NonPositiveAssetAmountError, NonPositiveBorrowAmountError, NonPositiveRepayAmountError, NonPositiveWithdrawAmountError, NonPositiveWithdrawCollateralAmountError, RefinanceExceedsBorrowAssetsError, RefinanceExceedsBorrowSharesError, RefinanceExceedsCollateralError, RefinanceSameMarketError, RefinanceTokenMismatchError, WithdrawExceedsCollateralError, ZeroCollateralAmountError, ZeroSupplyAmountError, } from "../../types/index.js";
|
|
7
|
+
import { BorrowAmountAndSharesExclusiveError, MarketIdMismatchError, MissingAccrualPositionError, MutuallyExclusiveRepayAmountsError, MutuallyExclusiveWithdrawAmountsError, NegativeBorrowSharesError, NegativeNativeAmountError, NegativeSupplyAmountError, NonPositiveAssetAmountError, NonPositiveBorrowAmountError, NonPositiveRepayAmountError, NonPositiveWithdrawAmountError, NonPositiveWithdrawCollateralAmountError, RefinanceExceedsBorrowAssetsError, RefinanceExceedsBorrowSharesError, RefinanceExceedsCollateralError, RefinanceSameMarketError, RefinanceTokenMismatchError, selectRequirementSignatures, WithdrawExceedsCollateralError, ZeroCollateralAmountError, ZeroSupplyAmountError, } from "../../types/index.js";
|
|
8
8
|
import { ReallocationData } from "../reallocationData.js";
|
|
9
9
|
export class MorphoBlue {
|
|
10
10
|
client;
|
|
@@ -57,7 +57,7 @@ export class MorphoBlue {
|
|
|
57
57
|
slippageTolerance,
|
|
58
58
|
});
|
|
59
59
|
return {
|
|
60
|
-
getRequirements: (params) =>
|
|
60
|
+
getRequirements: (params) => getGeneralAdapterRequirements(this.client.viemClient, {
|
|
61
61
|
address: this.marketParams.loanToken,
|
|
62
62
|
chainId: this.chainId,
|
|
63
63
|
supportSignature: this.client.options.supportSignature,
|
|
@@ -65,17 +65,22 @@ export class MorphoBlue {
|
|
|
65
65
|
useSimplePermit: params?.useSimplePermit,
|
|
66
66
|
args: { amount, from: userAddress },
|
|
67
67
|
}),
|
|
68
|
-
buildTx: (
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
68
|
+
buildTx: (signatures) => {
|
|
69
|
+
const { permit } = selectRequirementSignatures(signatures, {
|
|
70
|
+
permit: true,
|
|
71
|
+
});
|
|
72
|
+
return blueSupply({
|
|
73
|
+
market: { chainId: this.chainId, marketParams: this.marketParams },
|
|
74
|
+
args: {
|
|
75
|
+
amount,
|
|
76
|
+
nativeAmount,
|
|
77
|
+
onBehalf: userAddress,
|
|
78
|
+
maxSharePrice,
|
|
79
|
+
requirementSignature: permit,
|
|
80
|
+
},
|
|
81
|
+
metadata: this.client.options.metadata,
|
|
82
|
+
});
|
|
83
|
+
},
|
|
79
84
|
};
|
|
80
85
|
}
|
|
81
86
|
withdraw(params) {
|
|
@@ -126,24 +131,31 @@ export class MorphoBlue {
|
|
|
126
131
|
});
|
|
127
132
|
return {
|
|
128
133
|
getRequirements: async () => {
|
|
129
|
-
const authTx = await
|
|
134
|
+
const authTx = await getBlueAuthorizationRequirement({
|
|
130
135
|
viemClient: this.client.viemClient,
|
|
131
136
|
chainId: this.chainId,
|
|
132
137
|
userAddress,
|
|
138
|
+
supportSignature: this.client.options.supportSignature,
|
|
133
139
|
});
|
|
134
140
|
return authTx ? [authTx] : [];
|
|
135
141
|
},
|
|
136
|
-
buildTx: () =>
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
142
|
+
buildTx: (signatures) => {
|
|
143
|
+
const { authorization } = selectRequirementSignatures(signatures, {
|
|
144
|
+
authorization: true,
|
|
145
|
+
});
|
|
146
|
+
return blueWithdraw({
|
|
147
|
+
market: { chainId: this.chainId, marketParams: this.marketParams },
|
|
148
|
+
args: {
|
|
149
|
+
assets,
|
|
150
|
+
shares,
|
|
151
|
+
receiver,
|
|
152
|
+
minSharePrice,
|
|
153
|
+
reallocations,
|
|
154
|
+
authorizationSignature: authorization,
|
|
155
|
+
},
|
|
156
|
+
metadata: this.client.options.metadata,
|
|
157
|
+
});
|
|
158
|
+
},
|
|
147
159
|
};
|
|
148
160
|
}
|
|
149
161
|
supplyCollateral({ amount = 0n, userAddress, nativeAmount, }) {
|
|
@@ -162,7 +174,7 @@ export class MorphoBlue {
|
|
|
162
174
|
validateNativeAsset(this.chainId, this.marketParams.collateralToken);
|
|
163
175
|
}
|
|
164
176
|
return {
|
|
165
|
-
getRequirements: (params) =>
|
|
177
|
+
getRequirements: (params) => getGeneralAdapterRequirements(this.client.viemClient, {
|
|
166
178
|
address: this.marketParams.collateralToken,
|
|
167
179
|
chainId: this.chainId,
|
|
168
180
|
supportSignature: this.client.options.supportSignature,
|
|
@@ -170,19 +182,24 @@ export class MorphoBlue {
|
|
|
170
182
|
useSimplePermit: params?.useSimplePermit,
|
|
171
183
|
args: { amount, from: userAddress },
|
|
172
184
|
}),
|
|
173
|
-
buildTx: (
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
185
|
+
buildTx: (signatures) => {
|
|
186
|
+
const { permit } = selectRequirementSignatures(signatures, {
|
|
187
|
+
permit: true,
|
|
188
|
+
});
|
|
189
|
+
return blueSupplyCollateral({
|
|
190
|
+
market: {
|
|
191
|
+
chainId: this.chainId,
|
|
192
|
+
marketParams: this.marketParams,
|
|
193
|
+
},
|
|
194
|
+
args: {
|
|
195
|
+
amount,
|
|
196
|
+
nativeAmount,
|
|
197
|
+
onBehalf: userAddress,
|
|
198
|
+
requirementSignature: permit,
|
|
199
|
+
},
|
|
200
|
+
metadata: this.client.options.metadata,
|
|
201
|
+
});
|
|
202
|
+
},
|
|
186
203
|
};
|
|
187
204
|
}
|
|
188
205
|
borrow({ amount, userAddress, positionData, slippageTolerance = DEFAULT_SLIPPAGE_TOLERANCE, reallocations, }) {
|
|
@@ -213,26 +230,33 @@ export class MorphoBlue {
|
|
|
213
230
|
});
|
|
214
231
|
return {
|
|
215
232
|
getRequirements: async () => {
|
|
216
|
-
const authTx = await
|
|
233
|
+
const authTx = await getBlueAuthorizationRequirement({
|
|
217
234
|
viemClient: this.client.viemClient,
|
|
218
235
|
chainId: this.chainId,
|
|
219
236
|
userAddress,
|
|
237
|
+
supportSignature: this.client.options.supportSignature,
|
|
220
238
|
});
|
|
221
239
|
return authTx ? [authTx] : [];
|
|
222
240
|
},
|
|
223
|
-
buildTx: () =>
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
241
|
+
buildTx: (signatures) => {
|
|
242
|
+
const { authorization } = selectRequirementSignatures(signatures, {
|
|
243
|
+
authorization: true,
|
|
244
|
+
});
|
|
245
|
+
return blueBorrow({
|
|
246
|
+
market: {
|
|
247
|
+
chainId: this.chainId,
|
|
248
|
+
marketParams: this.marketParams,
|
|
249
|
+
},
|
|
250
|
+
args: {
|
|
251
|
+
amount,
|
|
252
|
+
receiver: userAddress,
|
|
253
|
+
minSharePrice,
|
|
254
|
+
reallocations,
|
|
255
|
+
authorizationSignature: authorization,
|
|
256
|
+
},
|
|
257
|
+
metadata: this.client.options.metadata,
|
|
258
|
+
});
|
|
259
|
+
},
|
|
236
260
|
};
|
|
237
261
|
}
|
|
238
262
|
repay(params) {
|
|
@@ -298,7 +322,7 @@ export class MorphoBlue {
|
|
|
298
322
|
slippageTolerance,
|
|
299
323
|
});
|
|
300
324
|
return {
|
|
301
|
-
getRequirements: (reqParams) =>
|
|
325
|
+
getRequirements: (reqParams) => getGeneralAdapterRequirements(this.client.viemClient, {
|
|
302
326
|
address: this.marketParams.loanToken,
|
|
303
327
|
chainId: this.chainId,
|
|
304
328
|
supportSignature: this.client.options.supportSignature,
|
|
@@ -306,22 +330,27 @@ export class MorphoBlue {
|
|
|
306
330
|
useSimplePermit: reqParams?.useSimplePermit,
|
|
307
331
|
args: { amount: transferAmount, from: userAddress },
|
|
308
332
|
}),
|
|
309
|
-
buildTx: (
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
333
|
+
buildTx: (signatures) => {
|
|
334
|
+
const { permit } = selectRequirementSignatures(signatures, {
|
|
335
|
+
permit: true,
|
|
336
|
+
});
|
|
337
|
+
return blueRepay({
|
|
338
|
+
market: {
|
|
339
|
+
chainId: this.chainId,
|
|
340
|
+
marketParams: this.marketParams,
|
|
341
|
+
},
|
|
342
|
+
args: {
|
|
343
|
+
assets,
|
|
344
|
+
shares,
|
|
345
|
+
transferAmount,
|
|
346
|
+
onBehalf: userAddress,
|
|
347
|
+
receiver: userAddress,
|
|
348
|
+
maxSharePrice,
|
|
349
|
+
requirementSignature: permit,
|
|
350
|
+
},
|
|
351
|
+
metadata: this.client.options.metadata,
|
|
352
|
+
});
|
|
353
|
+
},
|
|
325
354
|
};
|
|
326
355
|
}
|
|
327
356
|
withdrawCollateral({ userAddress, amount, positionData, }) {
|
|
@@ -447,7 +476,7 @@ export class MorphoBlue {
|
|
|
447
476
|
return {
|
|
448
477
|
getRequirements: async (reqParams) => {
|
|
449
478
|
const [erc20Requirements, authTx] = await Promise.all([
|
|
450
|
-
|
|
479
|
+
getGeneralAdapterRequirements(this.client.viemClient, {
|
|
451
480
|
address: this.marketParams.loanToken,
|
|
452
481
|
chainId: this.chainId,
|
|
453
482
|
supportSignature: this.client.options.supportSignature,
|
|
@@ -455,31 +484,36 @@ export class MorphoBlue {
|
|
|
455
484
|
useSimplePermit: reqParams?.useSimplePermit,
|
|
456
485
|
args: { amount: transferAmount, from: userAddress },
|
|
457
486
|
}),
|
|
458
|
-
|
|
487
|
+
getBlueAuthorizationRequirement({
|
|
459
488
|
viemClient: this.client.viemClient,
|
|
460
489
|
chainId: this.chainId,
|
|
461
490
|
userAddress,
|
|
491
|
+
supportSignature: this.client.options.supportSignature,
|
|
462
492
|
}),
|
|
463
493
|
]);
|
|
464
494
|
return [...erc20Requirements, ...(authTx ? [authTx] : [])];
|
|
465
495
|
},
|
|
466
|
-
buildTx: (
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
496
|
+
buildTx: (signatures) => {
|
|
497
|
+
const { permit, authorization } = selectRequirementSignatures(signatures, { permit: true, authorization: true });
|
|
498
|
+
return blueRepayWithdrawCollateral({
|
|
499
|
+
market: {
|
|
500
|
+
chainId: this.chainId,
|
|
501
|
+
marketParams: this.marketParams,
|
|
502
|
+
},
|
|
503
|
+
args: {
|
|
504
|
+
assets,
|
|
505
|
+
shares,
|
|
506
|
+
transferAmount,
|
|
507
|
+
withdrawAmount,
|
|
508
|
+
onBehalf: userAddress,
|
|
509
|
+
receiver: userAddress,
|
|
510
|
+
maxSharePrice,
|
|
511
|
+
requirementSignature: permit,
|
|
512
|
+
authorizationSignature: authorization,
|
|
513
|
+
},
|
|
514
|
+
metadata: this.client.options.metadata,
|
|
515
|
+
});
|
|
516
|
+
},
|
|
483
517
|
};
|
|
484
518
|
}
|
|
485
519
|
supplyCollateralBorrow({ amount = 0n, userAddress, positionData, borrowAmount, nativeAmount, slippageTolerance = DEFAULT_SLIPPAGE_TOLERANCE, reallocations, }) {
|
|
@@ -524,7 +558,7 @@ export class MorphoBlue {
|
|
|
524
558
|
return {
|
|
525
559
|
getRequirements: async (params) => {
|
|
526
560
|
const [erc20Requirements, authTx] = await Promise.all([
|
|
527
|
-
|
|
561
|
+
getGeneralAdapterRequirements(this.client.viemClient, {
|
|
528
562
|
address: this.marketParams.collateralToken,
|
|
529
563
|
chainId: this.chainId,
|
|
530
564
|
supportSignature: this.client.options.supportSignature,
|
|
@@ -532,31 +566,36 @@ export class MorphoBlue {
|
|
|
532
566
|
useSimplePermit: params?.useSimplePermit,
|
|
533
567
|
args: { amount, from: userAddress },
|
|
534
568
|
}),
|
|
535
|
-
|
|
569
|
+
getBlueAuthorizationRequirement({
|
|
536
570
|
viemClient: this.client.viemClient,
|
|
537
571
|
chainId: this.chainId,
|
|
538
572
|
userAddress,
|
|
573
|
+
supportSignature: this.client.options.supportSignature,
|
|
539
574
|
}),
|
|
540
575
|
]);
|
|
541
576
|
return [...erc20Requirements, ...(authTx ? [authTx] : [])];
|
|
542
577
|
},
|
|
543
|
-
buildTx: (
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
578
|
+
buildTx: (signatures) => {
|
|
579
|
+
const { permit, authorization } = selectRequirementSignatures(signatures, { permit: true, authorization: true });
|
|
580
|
+
return blueSupplyCollateralBorrow({
|
|
581
|
+
market: {
|
|
582
|
+
chainId: this.chainId,
|
|
583
|
+
marketParams: this.marketParams,
|
|
584
|
+
},
|
|
585
|
+
args: {
|
|
586
|
+
amount,
|
|
587
|
+
nativeAmount,
|
|
588
|
+
borrowAmount,
|
|
589
|
+
onBehalf: userAddress,
|
|
590
|
+
receiver: userAddress,
|
|
591
|
+
minSharePrice,
|
|
592
|
+
requirementSignature: permit,
|
|
593
|
+
authorizationSignature: authorization,
|
|
594
|
+
reallocations,
|
|
595
|
+
},
|
|
596
|
+
metadata: this.client.options.metadata,
|
|
597
|
+
});
|
|
598
|
+
},
|
|
560
599
|
};
|
|
561
600
|
}
|
|
562
601
|
refinance({ userAddress, positionData, target, collateralAmount, borrowAssets, borrowShares, slippageTolerance = DEFAULT_SLIPPAGE_TOLERANCE, targetReallocations, }) {
|
|
@@ -690,30 +729,37 @@ export class MorphoBlue {
|
|
|
690
729
|
: 0n;
|
|
691
730
|
return {
|
|
692
731
|
getRequirements: async () => {
|
|
693
|
-
const authTx = await
|
|
732
|
+
const authTx = await getBlueAuthorizationRequirement({
|
|
694
733
|
viemClient: this.client.viemClient,
|
|
695
734
|
chainId: this.chainId,
|
|
696
735
|
userAddress,
|
|
736
|
+
supportSignature: this.client.options.supportSignature,
|
|
697
737
|
});
|
|
698
738
|
return authTx ? [authTx] : [];
|
|
699
739
|
},
|
|
700
|
-
buildTx: () =>
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
740
|
+
buildTx: (signatures) => {
|
|
741
|
+
const { authorization } = selectRequirementSignatures(signatures, {
|
|
742
|
+
authorization: true,
|
|
743
|
+
});
|
|
744
|
+
return blueRefinance({
|
|
745
|
+
source: {
|
|
746
|
+
chainId: this.chainId,
|
|
747
|
+
marketParams: this.marketParams,
|
|
748
|
+
},
|
|
749
|
+
target: { marketParams: target.marketParams },
|
|
750
|
+
args: {
|
|
751
|
+
user: userAddress,
|
|
752
|
+
collateralAmount,
|
|
753
|
+
borrowAssets: borrowAssetsAdjusted,
|
|
754
|
+
borrowShares: requestedShares,
|
|
755
|
+
minBorrowSharePrice,
|
|
756
|
+
maxRepaySharePrice,
|
|
757
|
+
targetReallocations,
|
|
758
|
+
authorizationSignature: authorization,
|
|
759
|
+
},
|
|
760
|
+
metadata: this.client.options.metadata,
|
|
761
|
+
});
|
|
762
|
+
},
|
|
717
763
|
};
|
|
718
764
|
}
|
|
719
765
|
/**
|
|
@@ -253,50 +253,6 @@ export declare class ReallocationData implements InputReallocationData {
|
|
|
253
253
|
* ```
|
|
254
254
|
*/
|
|
255
255
|
getAvailableLiquidityToUtilization(marketId: MarketId, utilization?: bigint, options?: ReallocationComputeOptions): bigint;
|
|
256
|
-
/**
|
|
257
|
-
* Computes the liquidity available to bring `marketId` to `utilization`,
|
|
258
|
-
* counting the public-allocator liquidity reallocatable into it.
|
|
259
|
-
*
|
|
260
|
-
* @deprecated Renamed to {@link getAvailableLiquidityToUtilization} — the
|
|
261
|
-
* `target` wording wrongly implied a market's configured supply-target
|
|
262
|
-
* utilization, whereas the argument is an arbitrary utilization ceiling.
|
|
263
|
-
* Delegates to the new method; will be removed in the next major.
|
|
264
|
-
*
|
|
265
|
-
* @param marketId - Target market to borrow from.
|
|
266
|
-
* @param targetUtilization - Utilization to bring the market to, scaled by WAD. Defaults to {@link DEFAULT_SUPPLY_TARGET_UTILIZATION}.
|
|
267
|
-
* @param options - Optional reallocation options (supply target utilization trigger, timestamp, withdrawal caps).
|
|
268
|
-
* @returns Available liquidity to the given utilization in loan-token units; `0n` when none is available.
|
|
269
|
-
* @throws {@link UnknownReallocationMarketError} when the target market is absent.
|
|
270
|
-
* @example
|
|
271
|
-
* ```ts
|
|
272
|
-
* import { createPublicClient, http, parseEther } from "viem";
|
|
273
|
-
* import { mainnet } from "viem/chains";
|
|
274
|
-
* import { markets, vaults } from "@morpho-org/morpho-test";
|
|
275
|
-
* import { morphoViemExtension } from "@morpho-org/morpho-sdk";
|
|
276
|
-
*
|
|
277
|
-
* const client = createPublicClient({
|
|
278
|
-
* chain: mainnet,
|
|
279
|
-
* transport: http(),
|
|
280
|
-
* }).extend(morphoViemExtension());
|
|
281
|
-
*
|
|
282
|
-
* const marketParams = markets[mainnet.id].usdc_wbtc;
|
|
283
|
-
* const market = client.morpho.blue(marketParams, mainnet.id);
|
|
284
|
-
* const block = await client.getBlock();
|
|
285
|
-
* const reallocationData = await market.getReallocationData({
|
|
286
|
-
* vaultAddresses: [vaults[mainnet.id].steakUsdc.address],
|
|
287
|
-
* block: { number: block.number, timestamp: block.timestamp },
|
|
288
|
-
* });
|
|
289
|
-
*
|
|
290
|
-
* // Deprecated: prefer reallocationData.getAvailableLiquidityToUtilization.
|
|
291
|
-
* const available: bigint =
|
|
292
|
-
* reallocationData.getAvailableLiquidityToTargetUtilization(
|
|
293
|
-
* marketParams.id,
|
|
294
|
-
* parseEther("0.9"),
|
|
295
|
-
* { timestamp: block.timestamp },
|
|
296
|
-
* );
|
|
297
|
-
* ```
|
|
298
|
-
*/
|
|
299
|
-
getAvailableLiquidityToTargetUtilization(marketId: MarketId, targetUtilization?: bigint, options?: ReallocationComputeOptions): bigint;
|
|
300
256
|
/**
|
|
301
257
|
* Gets the largest currently valid source-market withdrawal for a vault.
|
|
302
258
|
*
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { bigIntComparator } from "@morpho-org/morpho-ts";
|
|
1
|
+
import { AccrualPosition, Market, MarketUtils, MathLib, Position, UnknownDataError, Vault, VaultMarketConfig, VaultMarketPublicAllocatorConfig, } from "@morpho-org/blue-sdk";
|
|
2
|
+
import { _try, bigIntComparator } from "@morpho-org/morpho-ts";
|
|
3
3
|
import { DEFAULT_SUPPLY_TARGET_UTILIZATION, DEFAULT_WITHDRAWAL_TARGET_UTILIZATION, } from "../helpers/constant.js";
|
|
4
4
|
import { getSupplyTargetUtilization } from "../helpers/utilization.js";
|
|
5
5
|
import { DisabledReallocationMarketError, MissingPublicAllocatorConfigError, UnknownReallocationMarketError, UnknownReallocationPositionError, UnknownReallocationVaultError, UnknownReallocationVaultMarketConfigError, } from "../types/index.js";
|
|
@@ -411,53 +411,6 @@ export class ReallocationData {
|
|
|
411
411
|
totalBorrowAssets: market.totalBorrowAssets,
|
|
412
412
|
}, utilization);
|
|
413
413
|
}
|
|
414
|
-
/**
|
|
415
|
-
* Computes the liquidity available to bring `marketId` to `utilization`,
|
|
416
|
-
* counting the public-allocator liquidity reallocatable into it.
|
|
417
|
-
*
|
|
418
|
-
* @deprecated Renamed to {@link getAvailableLiquidityToUtilization} — the
|
|
419
|
-
* `target` wording wrongly implied a market's configured supply-target
|
|
420
|
-
* utilization, whereas the argument is an arbitrary utilization ceiling.
|
|
421
|
-
* Delegates to the new method; will be removed in the next major.
|
|
422
|
-
*
|
|
423
|
-
* @param marketId - Target market to borrow from.
|
|
424
|
-
* @param targetUtilization - Utilization to bring the market to, scaled by WAD. Defaults to {@link DEFAULT_SUPPLY_TARGET_UTILIZATION}.
|
|
425
|
-
* @param options - Optional reallocation options (supply target utilization trigger, timestamp, withdrawal caps).
|
|
426
|
-
* @returns Available liquidity to the given utilization in loan-token units; `0n` when none is available.
|
|
427
|
-
* @throws {@link UnknownReallocationMarketError} when the target market is absent.
|
|
428
|
-
* @example
|
|
429
|
-
* ```ts
|
|
430
|
-
* import { createPublicClient, http, parseEther } from "viem";
|
|
431
|
-
* import { mainnet } from "viem/chains";
|
|
432
|
-
* import { markets, vaults } from "@morpho-org/morpho-test";
|
|
433
|
-
* import { morphoViemExtension } from "@morpho-org/morpho-sdk";
|
|
434
|
-
*
|
|
435
|
-
* const client = createPublicClient({
|
|
436
|
-
* chain: mainnet,
|
|
437
|
-
* transport: http(),
|
|
438
|
-
* }).extend(morphoViemExtension());
|
|
439
|
-
*
|
|
440
|
-
* const marketParams = markets[mainnet.id].usdc_wbtc;
|
|
441
|
-
* const market = client.morpho.blue(marketParams, mainnet.id);
|
|
442
|
-
* const block = await client.getBlock();
|
|
443
|
-
* const reallocationData = await market.getReallocationData({
|
|
444
|
-
* vaultAddresses: [vaults[mainnet.id].steakUsdc.address],
|
|
445
|
-
* block: { number: block.number, timestamp: block.timestamp },
|
|
446
|
-
* });
|
|
447
|
-
*
|
|
448
|
-
* // Deprecated: prefer reallocationData.getAvailableLiquidityToUtilization.
|
|
449
|
-
* const available: bigint =
|
|
450
|
-
* reallocationData.getAvailableLiquidityToTargetUtilization(
|
|
451
|
-
* marketParams.id,
|
|
452
|
-
* parseEther("0.9"),
|
|
453
|
-
* { timestamp: block.timestamp },
|
|
454
|
-
* );
|
|
455
|
-
* ```
|
|
456
|
-
*/
|
|
457
|
-
// biome-ignore lint/complexity/useMaxParams: (marketId, targetUtilization, options) is the metric's public API
|
|
458
|
-
getAvailableLiquidityToTargetUtilization(marketId, targetUtilization = DEFAULT_SUPPLY_TARGET_UTILIZATION, options) {
|
|
459
|
-
return this.getAvailableLiquidityToUtilization(marketId, targetUtilization, options);
|
|
460
|
-
}
|
|
461
414
|
/**
|
|
462
415
|
* Gets the largest currently valid source-market withdrawal for a vault.
|
|
463
416
|
*
|
|
@@ -2,7 +2,7 @@ import { type AccrualVault, type AccrualVaultV2 } from "@morpho-org/blue-sdk";
|
|
|
2
2
|
import { fetchAccrualVault } from "@morpho-org/blue-sdk-viem";
|
|
3
3
|
import { type Address } from "viem";
|
|
4
4
|
import type { FetchParameters } from "../../types/data.js";
|
|
5
|
-
import { type DepositAmountArgs, type ERC20ApprovalAction, type MorphoClientType, type Requirement, type RequirementSignature, type Transaction, type VaultV1DepositAction, type VaultV1MigrateToV2Action, type VaultV1RedeemAction, type VaultV1WithdrawAction } from "../../types/index.js";
|
|
5
|
+
import { type DepositAmountArgs, type ERC20ApprovalAction, type MorphoClientType, type PermitRequirementSignature, type Requirement, type RequirementSignature, type Transaction, type VaultV1DepositAction, type VaultV1MigrateToV2Action, type VaultV1RedeemAction, type VaultV1WithdrawAction } from "../../types/index.js";
|
|
6
6
|
export interface VaultV1Actions {
|
|
7
7
|
/**
|
|
8
8
|
* Fetches the latest vault data with accrued interest.
|
|
@@ -30,10 +30,10 @@ export interface VaultV1Actions {
|
|
|
30
30
|
vaultData: AccrualVault;
|
|
31
31
|
slippageTolerance?: bigint;
|
|
32
32
|
} & DepositAmountArgs) => {
|
|
33
|
-
buildTx: (
|
|
33
|
+
buildTx: (signatures?: readonly RequirementSignature[]) => Readonly<Transaction<VaultV1DepositAction>>;
|
|
34
34
|
getRequirements: (params?: {
|
|
35
35
|
useSimplePermit?: boolean;
|
|
36
|
-
}) => Promise<(Readonly<Transaction<ERC20ApprovalAction>> | Requirement)[]>;
|
|
36
|
+
}) => Promise<(Readonly<Transaction<ERC20ApprovalAction>> | Requirement<PermitRequirementSignature>)[]>;
|
|
37
37
|
};
|
|
38
38
|
/**
|
|
39
39
|
* Prepares a withdraw from a VaultV1 (MetaMorpho) contract.
|
|
@@ -84,8 +84,8 @@ export interface VaultV1Actions {
|
|
|
84
84
|
shares: bigint;
|
|
85
85
|
slippageTolerance?: bigint;
|
|
86
86
|
}) => {
|
|
87
|
-
buildTx: (
|
|
88
|
-
getRequirements: () => Promise<(Readonly<Transaction<ERC20ApprovalAction>> | Requirement)[]>;
|
|
87
|
+
buildTx: (signatures?: readonly RequirementSignature[]) => Readonly<Transaction<VaultV1MigrateToV2Action>>;
|
|
88
|
+
getRequirements: () => Promise<(Readonly<Transaction<ERC20ApprovalAction>> | Requirement<PermitRequirementSignature>)[]>;
|
|
89
89
|
};
|
|
90
90
|
}
|
|
91
91
|
export declare class MorphoVaultV1 implements VaultV1Actions {
|
|
@@ -101,8 +101,8 @@ export declare class MorphoVaultV1 implements VaultV1Actions {
|
|
|
101
101
|
} & DepositAmountArgs): {
|
|
102
102
|
getRequirements: (params?: {
|
|
103
103
|
useSimplePermit?: boolean;
|
|
104
|
-
}) => Promise<(
|
|
105
|
-
buildTx: (
|
|
104
|
+
}) => Promise<(import("../../types/action.js").Bundler3TokenSignatureRequirement | Readonly<Transaction<ERC20ApprovalAction>>)[]>;
|
|
105
|
+
buildTx: (signatures?: readonly RequirementSignature[]) => Readonly<Transaction<VaultV1DepositAction>>;
|
|
106
106
|
};
|
|
107
107
|
withdraw({ amount, userAddress }: {
|
|
108
108
|
amount: bigint;
|
|
@@ -123,7 +123,7 @@ export declare class MorphoVaultV1 implements VaultV1Actions {
|
|
|
123
123
|
shares: bigint;
|
|
124
124
|
slippageTolerance?: bigint;
|
|
125
125
|
}): {
|
|
126
|
-
getRequirements: () => Promise<(
|
|
127
|
-
buildTx: (
|
|
126
|
+
getRequirements: () => Promise<(import("../../types/action.js").Bundler3TokenSignatureRequirement | Readonly<Transaction<ERC20ApprovalAction>>)[]>;
|
|
127
|
+
buildTx: (signatures?: readonly RequirementSignature[]) => Readonly<Transaction<VaultV1MigrateToV2Action>>;
|
|
128
128
|
};
|
|
129
129
|
}
|