@morpho-org/morpho-sdk 4.2.0 → 5.1.1
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 +16 -16
- package/lib/cjs/actions/blue/borrow.d.ts +12 -2
- package/lib/cjs/actions/blue/borrow.js +7 -1
- package/lib/cjs/actions/blue/buildAssetFundingActions.d.ts +47 -0
- package/lib/cjs/actions/blue/buildAssetFundingActions.js +63 -0
- 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 +44 -43
- package/lib/cjs/actions/blue/repay.js +70 -59
- package/lib/cjs/actions/blue/repayWithdrawCollateral.d.ts +50 -41
- package/lib/cjs/actions/blue/repayWithdrawCollateral.js +75 -54
- package/lib/cjs/actions/blue/resolveRepayFunding.d.ts +69 -0
- package/lib/cjs/actions/blue/resolveRepayFunding.js +82 -0
- package/lib/cjs/actions/blue/supply.d.ts +8 -8
- package/lib/cjs/actions/blue/supply.js +11 -35
- package/lib/cjs/actions/blue/supplyCollateral.d.ts +9 -9
- package/lib/cjs/actions/blue/supplyCollateral.js +12 -36
- package/lib/cjs/actions/blue/supplyCollateralBorrow.d.ts +19 -7
- package/lib/cjs/actions/blue/supplyCollateralBorrow.js +17 -32
- 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 +309 -189
- 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/index.d.ts +1 -1
- package/lib/cjs/helpers/index.js +1 -2
- package/lib/cjs/helpers/validate.d.ts +2 -20
- package/lib/cjs/helpers/validate.js +2 -39
- package/lib/cjs/types/action.d.ts +164 -12
- package/lib/cjs/types/action.js +79 -5
- package/lib/cjs/types/error.d.ts +97 -2
- package/lib/cjs/types/error.js +113 -7
- package/lib/cjs/types.d.ts +2 -1
- package/lib/cjs/utils.d.ts +2 -2
- package/lib/cjs/utils.js +2 -4
- package/lib/esm/actions/blue/borrow.d.ts +12 -2
- package/lib/esm/actions/blue/borrow.js +7 -1
- package/lib/esm/actions/blue/buildAssetFundingActions.d.ts +47 -0
- package/lib/esm/actions/blue/buildAssetFundingActions.js +59 -0
- 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 +44 -43
- package/lib/esm/actions/blue/repay.js +71 -60
- package/lib/esm/actions/blue/repayWithdrawCollateral.d.ts +50 -41
- package/lib/esm/actions/blue/repayWithdrawCollateral.js +76 -55
- package/lib/esm/actions/blue/resolveRepayFunding.d.ts +69 -0
- package/lib/esm/actions/blue/resolveRepayFunding.js +78 -0
- package/lib/esm/actions/blue/supply.d.ts +8 -8
- package/lib/esm/actions/blue/supply.js +12 -36
- package/lib/esm/actions/blue/supplyCollateral.d.ts +9 -9
- package/lib/esm/actions/blue/supplyCollateral.js +13 -37
- package/lib/esm/actions/blue/supplyCollateralBorrow.d.ts +19 -7
- package/lib/esm/actions/blue/supplyCollateralBorrow.js +18 -33
- 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 +311 -191
- 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/index.d.ts +1 -1
- package/lib/esm/helpers/index.js +1 -1
- package/lib/esm/helpers/validate.d.ts +2 -20
- package/lib/esm/helpers/validate.js +2 -38
- package/lib/esm/types/action.d.ts +164 -12
- package/lib/esm/types/action.js +75 -4
- package/lib/esm/types/error.d.ts +97 -2
- package/lib/esm/types/error.js +107 -5
- package/lib/esm/types.d.ts +2 -1
- package/lib/esm/utils.d.ts +2 -2
- package/lib/esm/utils.js +2 -2
- package/package.json +22 -21
- 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
- package/src/index.ts +0 -4
|
@@ -60,7 +60,7 @@ class MorphoBlue {
|
|
|
60
60
|
slippageTolerance,
|
|
61
61
|
});
|
|
62
62
|
return {
|
|
63
|
-
getRequirements: (params) => (0, index_js_1.
|
|
63
|
+
getRequirements: (params) => (0, index_js_1.getGeneralAdapterRequirements)(this.client.viemClient, {
|
|
64
64
|
address: this.marketParams.loanToken,
|
|
65
65
|
chainId: this.chainId,
|
|
66
66
|
supportSignature: this.client.options.supportSignature,
|
|
@@ -68,17 +68,22 @@ class MorphoBlue {
|
|
|
68
68
|
useSimplePermit: params?.useSimplePermit,
|
|
69
69
|
args: { amount, from: userAddress },
|
|
70
70
|
}),
|
|
71
|
-
buildTx: (
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
71
|
+
buildTx: (signatures) => {
|
|
72
|
+
const { permit } = (0, index_js_3.selectRequirementSignatures)(signatures, {
|
|
73
|
+
permit: true,
|
|
74
|
+
});
|
|
75
|
+
return (0, index_js_1.blueSupply)({
|
|
76
|
+
market: { chainId: this.chainId, marketParams: this.marketParams },
|
|
77
|
+
args: {
|
|
78
|
+
amount,
|
|
79
|
+
nativeAmount,
|
|
80
|
+
onBehalf: userAddress,
|
|
81
|
+
maxSharePrice,
|
|
82
|
+
requirementSignature: permit,
|
|
83
|
+
},
|
|
84
|
+
metadata: this.client.options.metadata,
|
|
85
|
+
});
|
|
86
|
+
},
|
|
82
87
|
};
|
|
83
88
|
}
|
|
84
89
|
withdraw(params) {
|
|
@@ -129,24 +134,31 @@ class MorphoBlue {
|
|
|
129
134
|
});
|
|
130
135
|
return {
|
|
131
136
|
getRequirements: async () => {
|
|
132
|
-
const authTx = await (0, index_js_1.
|
|
137
|
+
const authTx = await (0, index_js_1.getBlueAuthorizationRequirement)({
|
|
133
138
|
viemClient: this.client.viemClient,
|
|
134
139
|
chainId: this.chainId,
|
|
135
140
|
userAddress,
|
|
141
|
+
supportSignature: this.client.options.supportSignature,
|
|
136
142
|
});
|
|
137
143
|
return authTx ? [authTx] : [];
|
|
138
144
|
},
|
|
139
|
-
buildTx: () =>
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
145
|
+
buildTx: (signatures) => {
|
|
146
|
+
const { authorization } = (0, index_js_3.selectRequirementSignatures)(signatures, {
|
|
147
|
+
authorization: true,
|
|
148
|
+
});
|
|
149
|
+
return (0, index_js_1.blueWithdraw)({
|
|
150
|
+
market: { chainId: this.chainId, marketParams: this.marketParams },
|
|
151
|
+
args: {
|
|
152
|
+
assets,
|
|
153
|
+
shares,
|
|
154
|
+
receiver,
|
|
155
|
+
minSharePrice,
|
|
156
|
+
reallocations,
|
|
157
|
+
authorizationSignature: authorization,
|
|
158
|
+
},
|
|
159
|
+
metadata: this.client.options.metadata,
|
|
160
|
+
});
|
|
161
|
+
},
|
|
150
162
|
};
|
|
151
163
|
}
|
|
152
164
|
supplyCollateral({ amount = 0n, userAddress, nativeAmount, }) {
|
|
@@ -165,7 +177,7 @@ class MorphoBlue {
|
|
|
165
177
|
(0, index_js_2.validateNativeAsset)(this.chainId, this.marketParams.collateralToken);
|
|
166
178
|
}
|
|
167
179
|
return {
|
|
168
|
-
getRequirements: (params) => (0, index_js_1.
|
|
180
|
+
getRequirements: (params) => (0, index_js_1.getGeneralAdapterRequirements)(this.client.viemClient, {
|
|
169
181
|
address: this.marketParams.collateralToken,
|
|
170
182
|
chainId: this.chainId,
|
|
171
183
|
supportSignature: this.client.options.supportSignature,
|
|
@@ -173,19 +185,24 @@ class MorphoBlue {
|
|
|
173
185
|
useSimplePermit: params?.useSimplePermit,
|
|
174
186
|
args: { amount, from: userAddress },
|
|
175
187
|
}),
|
|
176
|
-
buildTx: (
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
188
|
+
buildTx: (signatures) => {
|
|
189
|
+
const { permit } = (0, index_js_3.selectRequirementSignatures)(signatures, {
|
|
190
|
+
permit: true,
|
|
191
|
+
});
|
|
192
|
+
return (0, index_js_1.blueSupplyCollateral)({
|
|
193
|
+
market: {
|
|
194
|
+
chainId: this.chainId,
|
|
195
|
+
marketParams: this.marketParams,
|
|
196
|
+
},
|
|
197
|
+
args: {
|
|
198
|
+
amount,
|
|
199
|
+
nativeAmount,
|
|
200
|
+
onBehalf: userAddress,
|
|
201
|
+
requirementSignature: permit,
|
|
202
|
+
},
|
|
203
|
+
metadata: this.client.options.metadata,
|
|
204
|
+
});
|
|
205
|
+
},
|
|
189
206
|
};
|
|
190
207
|
}
|
|
191
208
|
borrow({ amount, userAddress, positionData, slippageTolerance = blue_sdk_1.DEFAULT_SLIPPAGE_TOLERANCE, reallocations, }) {
|
|
@@ -216,44 +233,44 @@ class MorphoBlue {
|
|
|
216
233
|
});
|
|
217
234
|
return {
|
|
218
235
|
getRequirements: async () => {
|
|
219
|
-
const authTx = await (0, index_js_1.
|
|
236
|
+
const authTx = await (0, index_js_1.getBlueAuthorizationRequirement)({
|
|
220
237
|
viemClient: this.client.viemClient,
|
|
221
238
|
chainId: this.chainId,
|
|
222
239
|
userAddress,
|
|
240
|
+
supportSignature: this.client.options.supportSignature,
|
|
223
241
|
});
|
|
224
242
|
return authTx ? [authTx] : [];
|
|
225
243
|
},
|
|
226
|
-
buildTx: () =>
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
244
|
+
buildTx: (signatures) => {
|
|
245
|
+
const { authorization } = (0, index_js_3.selectRequirementSignatures)(signatures, {
|
|
246
|
+
authorization: true,
|
|
247
|
+
});
|
|
248
|
+
return (0, index_js_1.blueBorrow)({
|
|
249
|
+
market: {
|
|
250
|
+
chainId: this.chainId,
|
|
251
|
+
marketParams: this.marketParams,
|
|
252
|
+
},
|
|
253
|
+
args: {
|
|
254
|
+
amount,
|
|
255
|
+
receiver: userAddress,
|
|
256
|
+
minSharePrice,
|
|
257
|
+
reallocations,
|
|
258
|
+
authorizationSignature: authorization,
|
|
259
|
+
},
|
|
260
|
+
metadata: this.client.options.metadata,
|
|
261
|
+
});
|
|
262
|
+
},
|
|
239
263
|
};
|
|
240
264
|
}
|
|
241
265
|
repay(params) {
|
|
242
266
|
(0, index_js_2.validateChainId)(this.client.viemClient.chain?.id, this.chainId);
|
|
243
267
|
const { userAddress, positionData, slippageTolerance = blue_sdk_1.DEFAULT_SLIPPAGE_TOLERANCE, } = params;
|
|
244
|
-
if ("
|
|
268
|
+
if ("amount" in params && "shares" in params) {
|
|
245
269
|
throw new index_js_3.MutuallyExclusiveRepayAmountsError(this.marketParams.id);
|
|
246
270
|
}
|
|
247
|
-
const
|
|
248
|
-
if (
|
|
249
|
-
|
|
250
|
-
throw new index_js_3.NonPositiveRepayAmountError(this.marketParams.id);
|
|
251
|
-
}
|
|
252
|
-
}
|
|
253
|
-
else {
|
|
254
|
-
if (params.assets <= 0n) {
|
|
255
|
-
throw new index_js_3.NonPositiveRepayAmountError(this.marketParams.id);
|
|
256
|
-
}
|
|
271
|
+
const nativeAmount = params.nativeAmount ?? 0n;
|
|
272
|
+
if (nativeAmount < 0n) {
|
|
273
|
+
throw new index_js_3.NegativeNativeAmountError(nativeAmount);
|
|
257
274
|
}
|
|
258
275
|
(0, index_js_2.validateSlippageTolerance)(slippageTolerance);
|
|
259
276
|
if (!positionData) {
|
|
@@ -264,67 +281,116 @@ class MorphoBlue {
|
|
|
264
281
|
expectedMarketId: this.marketParams.id,
|
|
265
282
|
expectedUser: userAddress,
|
|
266
283
|
});
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
284
|
+
if (nativeAmount > 0n) {
|
|
285
|
+
(0, index_js_2.validateNativeAsset)(this.chainId, this.marketParams.loanToken);
|
|
286
|
+
}
|
|
287
|
+
let repayAssets;
|
|
288
|
+
let repayShares;
|
|
289
|
+
let erc20Amount;
|
|
270
290
|
let marketForRepay;
|
|
271
|
-
if (
|
|
291
|
+
if ("shares" in params) {
|
|
292
|
+
const shares = params.shares;
|
|
293
|
+
if (shares <= 0n) {
|
|
294
|
+
throw new index_js_3.NonPositiveRepayAmountError(this.marketParams.id);
|
|
295
|
+
}
|
|
272
296
|
(0, index_js_2.validateRepayShares)({
|
|
273
297
|
positionData,
|
|
274
|
-
repayShares:
|
|
298
|
+
repayShares: shares,
|
|
275
299
|
marketId: this.marketParams.id,
|
|
276
300
|
});
|
|
277
|
-
|
|
278
|
-
|
|
301
|
+
repayAssets = 0n;
|
|
302
|
+
repayShares = shares;
|
|
279
303
|
// 2h forward accrual upper-bounds the on-chain repay price; bundle
|
|
280
304
|
// skims residual back to the receiver.
|
|
281
305
|
const accrualTimestamp = blue_sdk_1.MathLib.max(morpho_ts_1.Time.timestamp(), positionData.market.lastUpdate) +
|
|
282
306
|
morpho_ts_1.Time.s.from.h(2n);
|
|
283
307
|
marketForRepay = positionData.market.accrueInterest(accrualTimestamp);
|
|
284
|
-
|
|
308
|
+
const borrowAssets = marketForRepay.toBorrowAssets(shares, "Up");
|
|
309
|
+
// Native funds part of the transfer; the ERC-20 pulled is the remainder.
|
|
310
|
+
if (nativeAmount > borrowAssets) {
|
|
311
|
+
throw new index_js_3.NativeAmountExceedsTransferAmountError({
|
|
312
|
+
nativeAmount,
|
|
313
|
+
transferAmount: borrowAssets,
|
|
314
|
+
market: this.marketParams.id,
|
|
315
|
+
});
|
|
316
|
+
}
|
|
317
|
+
erc20Amount = borrowAssets - nativeAmount;
|
|
285
318
|
}
|
|
286
319
|
else {
|
|
320
|
+
// Assets mode is additive, like supply: repaid = amount + nativeAmount.
|
|
321
|
+
const amount = params.amount ?? 0n;
|
|
322
|
+
// Reject a negative ERC-20 amount before it can be masked by nativeAmount
|
|
323
|
+
// in the sum below (a negative amount would otherwise yield a negative
|
|
324
|
+
// erc20Amount and a negative approval in getRequirements).
|
|
325
|
+
if (amount < 0n) {
|
|
326
|
+
throw new index_js_3.NonPositiveRepayAmountError(this.marketParams.id);
|
|
327
|
+
}
|
|
328
|
+
repayAssets = amount + nativeAmount;
|
|
329
|
+
if (repayAssets <= 0n) {
|
|
330
|
+
throw new index_js_3.NonPositiveRepayAmountError(this.marketParams.id);
|
|
331
|
+
}
|
|
287
332
|
(0, index_js_2.validateRepayAmount)({
|
|
288
333
|
positionData,
|
|
289
|
-
repayAssets
|
|
334
|
+
repayAssets,
|
|
290
335
|
marketId: this.marketParams.id,
|
|
291
336
|
});
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
transferAmount = params.assets;
|
|
337
|
+
repayShares = 0n;
|
|
338
|
+
erc20Amount = amount;
|
|
295
339
|
marketForRepay = positionData.market;
|
|
296
340
|
}
|
|
297
341
|
const maxSharePrice = (0, index_js_2.computeMaxRepaySharePrice)({
|
|
298
|
-
repayAssets
|
|
299
|
-
repayShares
|
|
342
|
+
repayAssets,
|
|
343
|
+
repayShares,
|
|
300
344
|
market: marketForRepay,
|
|
301
345
|
slippageTolerance,
|
|
302
346
|
});
|
|
303
347
|
return {
|
|
304
|
-
getRequirements: (reqParams) =>
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
args: { amount: transferAmount, from: userAddress },
|
|
311
|
-
}),
|
|
312
|
-
buildTx: (requirementSignature) => (0, index_js_1.blueRepay)({
|
|
313
|
-
market: {
|
|
348
|
+
getRequirements: (reqParams) => {
|
|
349
|
+
// Fully native repay pulls no ERC-20, so it needs no approval/permit.
|
|
350
|
+
if (erc20Amount === 0n)
|
|
351
|
+
return Promise.resolve([]);
|
|
352
|
+
return (0, index_js_1.getGeneralAdapterRequirements)(this.client.viemClient, {
|
|
353
|
+
address: this.marketParams.loanToken,
|
|
314
354
|
chainId: this.chainId,
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
355
|
+
supportSignature: this.client.options.supportSignature,
|
|
356
|
+
supportDeployless: this.client.options.supportDeployless,
|
|
357
|
+
useSimplePermit: reqParams?.useSimplePermit,
|
|
358
|
+
args: { amount: erc20Amount, from: userAddress },
|
|
359
|
+
});
|
|
360
|
+
},
|
|
361
|
+
buildTx: (signatures) => {
|
|
362
|
+
const { permit } = (0, index_js_3.selectRequirementSignatures)(signatures, {
|
|
363
|
+
permit: true,
|
|
364
|
+
});
|
|
365
|
+
return (0, index_js_1.blueRepay)({
|
|
366
|
+
market: {
|
|
367
|
+
chainId: this.chainId,
|
|
368
|
+
marketParams: this.marketParams,
|
|
369
|
+
},
|
|
370
|
+
// Shares mode: repay `shares`, ERC-20 to pull = `erc20Amount`.
|
|
371
|
+
// Assets mode: repay `repayAssets` (= amount + native), pull `erc20Amount`.
|
|
372
|
+
args: repayShares > 0n
|
|
373
|
+
? {
|
|
374
|
+
shares: repayShares,
|
|
375
|
+
transferAmount: erc20Amount,
|
|
376
|
+
nativeAmount,
|
|
377
|
+
onBehalf: userAddress,
|
|
378
|
+
receiver: userAddress,
|
|
379
|
+
maxSharePrice,
|
|
380
|
+
requirementSignature: permit,
|
|
381
|
+
}
|
|
382
|
+
: {
|
|
383
|
+
amount: erc20Amount,
|
|
384
|
+
transferAmount: repayAssets,
|
|
385
|
+
nativeAmount,
|
|
386
|
+
onBehalf: userAddress,
|
|
387
|
+
receiver: userAddress,
|
|
388
|
+
maxSharePrice,
|
|
389
|
+
requirementSignature: permit,
|
|
390
|
+
},
|
|
391
|
+
metadata: this.client.options.metadata,
|
|
392
|
+
});
|
|
393
|
+
},
|
|
328
394
|
};
|
|
329
395
|
}
|
|
330
396
|
withdrawCollateral({ userAddress, amount, positionData, }) {
|
|
@@ -371,19 +437,12 @@ class MorphoBlue {
|
|
|
371
437
|
repayWithdrawCollateral(params) {
|
|
372
438
|
(0, index_js_2.validateChainId)(this.client.viemClient.chain?.id, this.chainId);
|
|
373
439
|
const { userAddress, withdrawAmount, positionData, slippageTolerance = blue_sdk_1.DEFAULT_SLIPPAGE_TOLERANCE, } = params;
|
|
374
|
-
if ("
|
|
440
|
+
if ("amount" in params && "shares" in params) {
|
|
375
441
|
throw new index_js_3.MutuallyExclusiveRepayAmountsError(this.marketParams.id);
|
|
376
442
|
}
|
|
377
|
-
const
|
|
378
|
-
if (
|
|
379
|
-
|
|
380
|
-
throw new index_js_3.NonPositiveRepayAmountError(this.marketParams.id);
|
|
381
|
-
}
|
|
382
|
-
}
|
|
383
|
-
else {
|
|
384
|
-
if (params.assets <= 0n) {
|
|
385
|
-
throw new index_js_3.NonPositiveRepayAmountError(this.marketParams.id);
|
|
386
|
-
}
|
|
443
|
+
const nativeAmount = params.nativeAmount ?? 0n;
|
|
444
|
+
if (nativeAmount < 0n) {
|
|
445
|
+
throw new index_js_3.NegativeNativeAmountError(nativeAmount);
|
|
387
446
|
}
|
|
388
447
|
if (withdrawAmount <= 0n) {
|
|
389
448
|
throw new index_js_3.NonPositiveWithdrawCollateralAmountError(this.marketParams.id);
|
|
@@ -397,34 +456,61 @@ class MorphoBlue {
|
|
|
397
456
|
expectedMarketId: this.marketParams.id,
|
|
398
457
|
expectedUser: userAddress,
|
|
399
458
|
});
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
459
|
+
if (nativeAmount > 0n) {
|
|
460
|
+
(0, index_js_2.validateNativeAsset)(this.chainId, this.marketParams.loanToken);
|
|
461
|
+
}
|
|
462
|
+
let repayAssets;
|
|
463
|
+
let repayShares;
|
|
464
|
+
let erc20Amount;
|
|
403
465
|
let marketForRepay;
|
|
404
466
|
// 2h forward accrual upper-bounds the on-chain repay price (shares
|
|
405
467
|
// mode) and the post-repay health check; bundle skims residual back.
|
|
406
468
|
const accrualTimestamp = blue_sdk_1.MathLib.max(morpho_ts_1.Time.timestamp(), positionData.market.lastUpdate) +
|
|
407
469
|
morpho_ts_1.Time.s.from.h(2n);
|
|
408
|
-
if (
|
|
470
|
+
if ("shares" in params) {
|
|
471
|
+
const shares = params.shares;
|
|
472
|
+
if (shares <= 0n) {
|
|
473
|
+
throw new index_js_3.NonPositiveRepayAmountError(this.marketParams.id);
|
|
474
|
+
}
|
|
409
475
|
(0, index_js_2.validateRepayShares)({
|
|
410
476
|
positionData,
|
|
411
|
-
repayShares:
|
|
477
|
+
repayShares: shares,
|
|
412
478
|
marketId: this.marketParams.id,
|
|
413
479
|
});
|
|
414
|
-
|
|
415
|
-
|
|
480
|
+
repayAssets = 0n;
|
|
481
|
+
repayShares = shares;
|
|
416
482
|
marketForRepay = positionData.market.accrueInterest(accrualTimestamp);
|
|
417
|
-
|
|
483
|
+
const borrowAssets = marketForRepay.toBorrowAssets(shares, "Up");
|
|
484
|
+
// Native funds part of the transfer; the ERC-20 pulled is the remainder.
|
|
485
|
+
if (nativeAmount > borrowAssets) {
|
|
486
|
+
throw new index_js_3.NativeAmountExceedsTransferAmountError({
|
|
487
|
+
nativeAmount,
|
|
488
|
+
transferAmount: borrowAssets,
|
|
489
|
+
market: this.marketParams.id,
|
|
490
|
+
});
|
|
491
|
+
}
|
|
492
|
+
erc20Amount = borrowAssets - nativeAmount;
|
|
418
493
|
}
|
|
419
494
|
else {
|
|
495
|
+
// Assets mode is additive, like supply: repaid = amount + nativeAmount.
|
|
496
|
+
const amount = params.amount ?? 0n;
|
|
497
|
+
// Reject a negative ERC-20 amount before it can be masked by nativeAmount
|
|
498
|
+
// in the sum below (a negative amount would otherwise yield a negative
|
|
499
|
+
// erc20Amount and a negative approval in getRequirements).
|
|
500
|
+
if (amount < 0n) {
|
|
501
|
+
throw new index_js_3.NonPositiveRepayAmountError(this.marketParams.id);
|
|
502
|
+
}
|
|
503
|
+
repayAssets = amount + nativeAmount;
|
|
504
|
+
if (repayAssets <= 0n) {
|
|
505
|
+
throw new index_js_3.NonPositiveRepayAmountError(this.marketParams.id);
|
|
506
|
+
}
|
|
420
507
|
(0, index_js_2.validateRepayAmount)({
|
|
421
508
|
positionData,
|
|
422
|
-
repayAssets
|
|
509
|
+
repayAssets,
|
|
423
510
|
marketId: this.marketParams.id,
|
|
424
511
|
});
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
transferAmount = params.assets;
|
|
512
|
+
repayShares = 0n;
|
|
513
|
+
erc20Amount = amount;
|
|
428
514
|
marketForRepay = positionData.market;
|
|
429
515
|
}
|
|
430
516
|
if (withdrawAmount > positionData.collateral) {
|
|
@@ -434,7 +520,7 @@ class MorphoBlue {
|
|
|
434
520
|
market: positionData.marketId,
|
|
435
521
|
});
|
|
436
522
|
}
|
|
437
|
-
const { position: positionAfterRepay } = positionData.repay(
|
|
523
|
+
const { position: positionAfterRepay } = positionData.repay(repayAssets, repayShares, accrualTimestamp);
|
|
438
524
|
(0, index_js_2.validatePositionHealthAfterWithdraw)({
|
|
439
525
|
positionData: positionAfterRepay,
|
|
440
526
|
withdrawAmount,
|
|
@@ -442,47 +528,69 @@ class MorphoBlue {
|
|
|
442
528
|
marketId: this.marketParams.id,
|
|
443
529
|
});
|
|
444
530
|
const maxSharePrice = (0, index_js_2.computeMaxRepaySharePrice)({
|
|
445
|
-
repayAssets
|
|
446
|
-
repayShares
|
|
531
|
+
repayAssets,
|
|
532
|
+
repayShares,
|
|
447
533
|
market: marketForRepay,
|
|
448
534
|
slippageTolerance,
|
|
449
535
|
});
|
|
450
536
|
return {
|
|
451
537
|
getRequirements: async (reqParams) => {
|
|
452
538
|
const [erc20Requirements, authTx] = await Promise.all([
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
539
|
+
// Fully native repay pulls no ERC-20, so it needs no approval/permit.
|
|
540
|
+
erc20Amount === 0n
|
|
541
|
+
? Promise.resolve([])
|
|
542
|
+
: (0, index_js_1.getGeneralAdapterRequirements)(this.client.viemClient, {
|
|
543
|
+
address: this.marketParams.loanToken,
|
|
544
|
+
chainId: this.chainId,
|
|
545
|
+
supportSignature: this.client.options.supportSignature,
|
|
546
|
+
supportDeployless: this.client.options.supportDeployless,
|
|
547
|
+
useSimplePermit: reqParams?.useSimplePermit,
|
|
548
|
+
args: { amount: erc20Amount, from: userAddress },
|
|
549
|
+
}),
|
|
550
|
+
(0, index_js_1.getBlueAuthorizationRequirement)({
|
|
462
551
|
viemClient: this.client.viemClient,
|
|
463
552
|
chainId: this.chainId,
|
|
464
553
|
userAddress,
|
|
554
|
+
supportSignature: this.client.options.supportSignature,
|
|
465
555
|
}),
|
|
466
556
|
]);
|
|
467
557
|
return [...erc20Requirements, ...(authTx ? [authTx] : [])];
|
|
468
558
|
},
|
|
469
|
-
buildTx: (
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
shares
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
559
|
+
buildTx: (signatures) => {
|
|
560
|
+
const { permit, authorization } = (0, index_js_3.selectRequirementSignatures)(signatures, { permit: true, authorization: true });
|
|
561
|
+
return (0, index_js_1.blueRepayWithdrawCollateral)({
|
|
562
|
+
market: {
|
|
563
|
+
chainId: this.chainId,
|
|
564
|
+
marketParams: this.marketParams,
|
|
565
|
+
},
|
|
566
|
+
// Shares mode: repay `shares`, ERC-20 to pull = `erc20Amount`.
|
|
567
|
+
// Assets mode: repay `repayAssets` (= amount + native), pull `erc20Amount`.
|
|
568
|
+
args: repayShares > 0n
|
|
569
|
+
? {
|
|
570
|
+
shares: repayShares,
|
|
571
|
+
transferAmount: erc20Amount,
|
|
572
|
+
nativeAmount,
|
|
573
|
+
withdrawAmount,
|
|
574
|
+
onBehalf: userAddress,
|
|
575
|
+
receiver: userAddress,
|
|
576
|
+
maxSharePrice,
|
|
577
|
+
requirementSignature: permit,
|
|
578
|
+
authorizationSignature: authorization,
|
|
579
|
+
}
|
|
580
|
+
: {
|
|
581
|
+
amount: erc20Amount,
|
|
582
|
+
transferAmount: repayAssets,
|
|
583
|
+
nativeAmount,
|
|
584
|
+
withdrawAmount,
|
|
585
|
+
onBehalf: userAddress,
|
|
586
|
+
receiver: userAddress,
|
|
587
|
+
maxSharePrice,
|
|
588
|
+
requirementSignature: permit,
|
|
589
|
+
authorizationSignature: authorization,
|
|
590
|
+
},
|
|
591
|
+
metadata: this.client.options.metadata,
|
|
592
|
+
});
|
|
593
|
+
},
|
|
486
594
|
};
|
|
487
595
|
}
|
|
488
596
|
supplyCollateralBorrow({ amount = 0n, userAddress, positionData, borrowAmount, nativeAmount, slippageTolerance = blue_sdk_1.DEFAULT_SLIPPAGE_TOLERANCE, reallocations, }) {
|
|
@@ -527,7 +635,7 @@ class MorphoBlue {
|
|
|
527
635
|
return {
|
|
528
636
|
getRequirements: async (params) => {
|
|
529
637
|
const [erc20Requirements, authTx] = await Promise.all([
|
|
530
|
-
(0, index_js_1.
|
|
638
|
+
(0, index_js_1.getGeneralAdapterRequirements)(this.client.viemClient, {
|
|
531
639
|
address: this.marketParams.collateralToken,
|
|
532
640
|
chainId: this.chainId,
|
|
533
641
|
supportSignature: this.client.options.supportSignature,
|
|
@@ -535,31 +643,36 @@ class MorphoBlue {
|
|
|
535
643
|
useSimplePermit: params?.useSimplePermit,
|
|
536
644
|
args: { amount, from: userAddress },
|
|
537
645
|
}),
|
|
538
|
-
(0, index_js_1.
|
|
646
|
+
(0, index_js_1.getBlueAuthorizationRequirement)({
|
|
539
647
|
viemClient: this.client.viemClient,
|
|
540
648
|
chainId: this.chainId,
|
|
541
649
|
userAddress,
|
|
650
|
+
supportSignature: this.client.options.supportSignature,
|
|
542
651
|
}),
|
|
543
652
|
]);
|
|
544
653
|
return [...erc20Requirements, ...(authTx ? [authTx] : [])];
|
|
545
654
|
},
|
|
546
|
-
buildTx: (
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
655
|
+
buildTx: (signatures) => {
|
|
656
|
+
const { permit, authorization } = (0, index_js_3.selectRequirementSignatures)(signatures, { permit: true, authorization: true });
|
|
657
|
+
return (0, index_js_1.blueSupplyCollateralBorrow)({
|
|
658
|
+
market: {
|
|
659
|
+
chainId: this.chainId,
|
|
660
|
+
marketParams: this.marketParams,
|
|
661
|
+
},
|
|
662
|
+
args: {
|
|
663
|
+
amount,
|
|
664
|
+
nativeAmount,
|
|
665
|
+
borrowAmount,
|
|
666
|
+
onBehalf: userAddress,
|
|
667
|
+
receiver: userAddress,
|
|
668
|
+
minSharePrice,
|
|
669
|
+
requirementSignature: permit,
|
|
670
|
+
authorizationSignature: authorization,
|
|
671
|
+
reallocations,
|
|
672
|
+
},
|
|
673
|
+
metadata: this.client.options.metadata,
|
|
674
|
+
});
|
|
675
|
+
},
|
|
563
676
|
};
|
|
564
677
|
}
|
|
565
678
|
refinance({ userAddress, positionData, target, collateralAmount, borrowAssets, borrowShares, slippageTolerance = blue_sdk_1.DEFAULT_SLIPPAGE_TOLERANCE, targetReallocations, }) {
|
|
@@ -693,30 +806,37 @@ class MorphoBlue {
|
|
|
693
806
|
: 0n;
|
|
694
807
|
return {
|
|
695
808
|
getRequirements: async () => {
|
|
696
|
-
const authTx = await (0, index_js_1.
|
|
809
|
+
const authTx = await (0, index_js_1.getBlueAuthorizationRequirement)({
|
|
697
810
|
viemClient: this.client.viemClient,
|
|
698
811
|
chainId: this.chainId,
|
|
699
812
|
userAddress,
|
|
813
|
+
supportSignature: this.client.options.supportSignature,
|
|
700
814
|
});
|
|
701
815
|
return authTx ? [authTx] : [];
|
|
702
816
|
},
|
|
703
|
-
buildTx: () =>
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
817
|
+
buildTx: (signatures) => {
|
|
818
|
+
const { authorization } = (0, index_js_3.selectRequirementSignatures)(signatures, {
|
|
819
|
+
authorization: true,
|
|
820
|
+
});
|
|
821
|
+
return (0, index_js_1.blueRefinance)({
|
|
822
|
+
source: {
|
|
823
|
+
chainId: this.chainId,
|
|
824
|
+
marketParams: this.marketParams,
|
|
825
|
+
},
|
|
826
|
+
target: { marketParams: target.marketParams },
|
|
827
|
+
args: {
|
|
828
|
+
user: userAddress,
|
|
829
|
+
collateralAmount,
|
|
830
|
+
borrowAssets: borrowAssetsAdjusted,
|
|
831
|
+
borrowShares: requestedShares,
|
|
832
|
+
minBorrowSharePrice,
|
|
833
|
+
maxRepaySharePrice,
|
|
834
|
+
targetReallocations,
|
|
835
|
+
authorizationSignature: authorization,
|
|
836
|
+
},
|
|
837
|
+
metadata: this.client.options.metadata,
|
|
838
|
+
});
|
|
839
|
+
},
|
|
720
840
|
};
|
|
721
841
|
}
|
|
722
842
|
/**
|