@gearbox-protocol/sdk 16.0.0-next.27 → 16.0.0-next.29
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/dist/cjs/model/index.js +1 -0
- package/dist/cjs/model/previews.js +23 -0
- package/dist/cjs/onchain/accounts/intents/open-strategy.js +5 -18
- package/dist/cjs/onchain/accounts/intents/realize.js +77 -49
- package/dist/cjs/onchain/accounts/intents/testing/market.js +1 -0
- package/dist/cjs/onchain/accounts/intents/testing/sdk-mock.js +28 -5
- package/dist/cjs/onchain/index.js +6 -0
- package/dist/cjs/onchain/market/credit/creditOperationMarket.js +32 -0
- package/dist/cjs/onchain/market/credit/index.js +3 -0
- package/dist/cjs/onchain/market/index.js +5 -0
- package/dist/cjs/onchain/market/oracle/collateralPriceInUnderlying.js +27 -0
- package/dist/cjs/onchain/market/oracle/index.js +2 -0
- package/dist/cjs/onchain/positions/PositionsService.js +94 -0
- package/dist/cjs/onchain/positions/calcLiquidationPrice.js +14 -4
- package/dist/cjs/onchain/positions/index.js +1 -0
- package/dist/cjs/preview/index.js +6 -6
- package/dist/cjs/preview/preview/{buildDelayedPreview.js → buildDelayedStrategyVerify.js} +8 -27
- package/dist/cjs/preview/preview/index.js +6 -6
- package/dist/cjs/preview/preview/{previewAdjustCreditAccount.js → previewAdjustStrategyVerify.js} +6 -24
- package/dist/cjs/preview/preview/{previewCloseOrRepayCreditAccount.js → previewExitOrRepayStrategyVerify.js} +6 -7
- package/dist/cjs/preview/preview/{previewPoolOperation.js → previewLpVerify.js} +3 -3
- package/dist/cjs/preview/preview/{previewOpenCreditAccount.js → previewOpenStrategyVerify.js} +6 -26
- package/dist/cjs/preview/preview/previewOperation.js +13 -12
- package/dist/cjs/preview/validate/checkOperation.js +13 -9
- package/dist/esm/model/index.js +2 -2
- package/dist/esm/model/previews.js +23 -1
- package/dist/esm/onchain/accounts/intents/open-strategy.js +5 -18
- package/dist/esm/onchain/accounts/intents/realize.js +77 -49
- package/dist/esm/onchain/accounts/intents/testing/market.js +1 -0
- package/dist/esm/onchain/accounts/intents/testing/sdk-mock.js +27 -6
- package/dist/esm/onchain/index.js +4 -2
- package/dist/esm/onchain/market/credit/creditOperationMarket.js +30 -0
- package/dist/esm/onchain/market/credit/index.js +2 -1
- package/dist/esm/onchain/market/index.js +3 -1
- package/dist/esm/onchain/market/oracle/collateralPriceInUnderlying.js +26 -0
- package/dist/esm/onchain/market/oracle/index.js +2 -1
- package/dist/esm/onchain/positions/PositionsService.js +95 -1
- package/dist/esm/onchain/positions/calcLiquidationPrice.js +14 -5
- package/dist/esm/onchain/positions/index.js +2 -2
- package/dist/esm/preview/index.js +4 -4
- package/dist/esm/preview/preview/{buildDelayedPreview.js → buildDelayedStrategyVerify.js} +9 -28
- package/dist/esm/preview/preview/index.js +4 -4
- package/dist/esm/preview/preview/{previewAdjustCreditAccount.js → previewAdjustStrategyVerify.js} +7 -25
- package/dist/esm/preview/preview/{previewCloseOrRepayCreditAccount.js → previewExitOrRepayStrategyVerify.js} +6 -7
- package/dist/esm/preview/preview/{previewPoolOperation.js → previewLpVerify.js} +3 -3
- package/dist/esm/preview/preview/{previewOpenCreditAccount.js → previewOpenStrategyVerify.js} +7 -27
- package/dist/esm/preview/preview/previewOperation.js +13 -12
- package/dist/esm/preview/validate/checkOperation.js +13 -9
- package/dist/types/model/index.d.ts +2 -2
- package/dist/types/model/previews.d.ts +222 -97
- package/dist/types/onchain/accounts/intents/open-strategy.d.ts +13 -7
- package/dist/types/onchain/accounts/intents/testing/market.d.ts +1 -0
- package/dist/types/onchain/accounts/intents/testing/sdk-mock.d.ts +18 -0
- package/dist/types/onchain/accounts/intents/types.d.ts +12 -0
- package/dist/types/onchain/index.d.ts +4 -2
- package/dist/types/onchain/market/credit/creditOperationMarket.d.ts +23 -0
- package/dist/types/onchain/market/credit/index.d.ts +2 -1
- package/dist/types/onchain/market/index.d.ts +3 -1
- package/dist/types/onchain/market/oracle/collateralPriceInUnderlying.d.ts +19 -0
- package/dist/types/onchain/market/oracle/index.d.ts +2 -1
- package/dist/types/onchain/positions/PositionsService.d.ts +38 -0
- package/dist/types/onchain/positions/calcLiquidationPrice.d.ts +10 -1
- package/dist/types/onchain/positions/index.d.ts +2 -2
- package/dist/types/preview/index.d.ts +5 -5
- package/dist/types/preview/preview/{buildDelayedPreview.d.ts → buildDelayedStrategyVerify.d.ts} +4 -4
- package/dist/types/preview/preview/index.d.ts +4 -4
- package/dist/types/preview/preview/{previewAdjustCreditAccount.d.ts → previewAdjustStrategyVerify.d.ts} +4 -4
- package/dist/types/preview/preview/{previewCloseOrRepayCreditAccount.d.ts → previewExitOrRepayStrategyVerify.d.ts} +4 -4
- package/dist/types/preview/preview/previewLpVerify.d.ts +11 -0
- package/dist/types/preview/preview/previewOpenStrategyVerify.d.ts +12 -0
- package/dist/types/preview/validate/checkOperation.d.ts +12 -4
- package/dist/types/preview/validate/index.d.ts +2 -2
- package/package.json +1 -1
- package/dist/types/preview/preview/previewOpenCreditAccount.d.ts +0 -12
- package/dist/types/preview/preview/previewPoolOperation.d.ts +0 -11
|
@@ -8,9 +8,11 @@ const require_onchain_base_SDKConstruct = require("../base/SDKConstruct.js");
|
|
|
8
8
|
require("../base/index.js");
|
|
9
9
|
const require_onchain_market_math = require("../market/math.js");
|
|
10
10
|
const require_onchain_market_strategyName = require("../market/strategyName.js");
|
|
11
|
+
const require_onchain_market_credit_creditOperationMarket = require("../market/credit/creditOperationMarket.js");
|
|
11
12
|
const require_model_filters = require("../../model/filters.js");
|
|
12
13
|
const require_model_positions = require("../../model/positions.js");
|
|
13
14
|
require("../../model/index.js");
|
|
15
|
+
const require_onchain_market_oracle_collateralPriceInUnderlying = require("../market/oracle/collateralPriceInUnderlying.js");
|
|
14
16
|
const require_onchain_market_pool_math = require("../market/pool/math.js");
|
|
15
17
|
const require_onchain_positions_calcBorrowRate = require("./calcBorrowRate.js");
|
|
16
18
|
const require_onchain_positions_calcHealthFactor = require("./calcHealthFactor.js");
|
|
@@ -164,6 +166,98 @@ var PositionsService = class extends require_onchain_base_SDKConstruct.SDKConstr
|
|
|
164
166
|
});
|
|
165
167
|
}
|
|
166
168
|
/**
|
|
169
|
+
* What the collateral {@link liquidationPrice} is quoted for costs in the
|
|
170
|
+
* market underlying right now, in the same `PRICE_DECIMALS` fixed point —
|
|
171
|
+
* the pair a form shows beside the liquidation price. `null` under exactly
|
|
172
|
+
* the conditions that leave the liquidation price `null`, plus an oracle
|
|
173
|
+
* that cannot answer for either side.
|
|
174
|
+
**/
|
|
175
|
+
currentPrice(snapshot) {
|
|
176
|
+
const market = this.sdk.marketRegister.findByCreditManager(snapshot.creditManager);
|
|
177
|
+
const underlying = market.pool.underlying;
|
|
178
|
+
const collateral = require_onchain_positions_calcLiquidationPrice.soleNonUnderlyingCollateral(snapshot, underlying);
|
|
179
|
+
if (!collateral) return null;
|
|
180
|
+
return require_onchain_market_oracle_collateralPriceInUnderlying.collateralPriceInUnderlying(market.priceOracle, collateral, underlying);
|
|
181
|
+
}
|
|
182
|
+
/**
|
|
183
|
+
* Every derived number of an account state at once — the whole
|
|
184
|
+
* {@link AccountMetrics} half of a projection.
|
|
185
|
+
*
|
|
186
|
+
* This is what both halves of the SDK fill their answers from: `prepare`, for
|
|
187
|
+
* a state it walked an intent into, and `preview`, for one it replayed out of
|
|
188
|
+
* calldata. One snapshot in, one set of metrics out, so the two descriptions
|
|
189
|
+
* of the same operation cannot disagree because one of them grew its own
|
|
190
|
+
* formula.
|
|
191
|
+
*
|
|
192
|
+
* Identical to the four methods above field for field, and cheaper than
|
|
193
|
+
* calling them one by one: the market data is collected once, and the health
|
|
194
|
+
* factor and borrow rate the time to liquidation decays at are the very ones
|
|
195
|
+
* reported beside it.
|
|
196
|
+
**/
|
|
197
|
+
metrics(snapshot, options) {
|
|
198
|
+
const data = this.#marketData(snapshot);
|
|
199
|
+
const factor = (safePrices) => require_onchain_positions_calcHealthFactor.calcHealthFactor({
|
|
200
|
+
snapshot,
|
|
201
|
+
underlying: data.underlying,
|
|
202
|
+
decimals: data.decimals,
|
|
203
|
+
prices: data.prices,
|
|
204
|
+
reservePrices: data.reservePrices,
|
|
205
|
+
safePrices,
|
|
206
|
+
liquidationThresholds: data.liquidationThresholds,
|
|
207
|
+
activeQuotas: data.activeQuotas
|
|
208
|
+
});
|
|
209
|
+
const healthFactor = factor(false);
|
|
210
|
+
const borrowRate = require_onchain_positions_calcBorrowRate.calcBorrowRate({
|
|
211
|
+
snapshot,
|
|
212
|
+
baseInterestRate: this.#baseInterestRate(snapshot, data, options),
|
|
213
|
+
feeInterest: data.feeInterest,
|
|
214
|
+
quotaRates: data.quotaRates,
|
|
215
|
+
resolveToken: (address) => this.sdk.tokensMeta.mustGetToken(address)
|
|
216
|
+
});
|
|
217
|
+
return {
|
|
218
|
+
healthFactor,
|
|
219
|
+
safeHealthFactor: factor(true),
|
|
220
|
+
borrowRate,
|
|
221
|
+
timeToLiquidation: require_onchain_positions_calcTimeToLiquidationMs.calcTimeToLiquidationMs(healthFactor, BigInt(borrowRate.totalOnDebt)),
|
|
222
|
+
liquidationPrice: require_onchain_positions_calcLiquidationPrice.calcLiquidationPrice({
|
|
223
|
+
snapshot,
|
|
224
|
+
underlying: data.underlying,
|
|
225
|
+
decimals: data.decimals,
|
|
226
|
+
liquidationThresholds: data.liquidationThresholds
|
|
227
|
+
}),
|
|
228
|
+
leverage: require_onchain_market_math.calcPositionLeverage(snapshot.totalValue, snapshot.totalDebt)
|
|
229
|
+
};
|
|
230
|
+
}
|
|
231
|
+
/**
|
|
232
|
+
* A projected account state as both halves of the SDK report it: the holdings
|
|
233
|
+
* priced and named, and the metrics of {@link PositionsService.metrics}.
|
|
234
|
+
*
|
|
235
|
+
* The snapshot is taken at its word — what it lists is what comes back, so a
|
|
236
|
+
* caller that drops dust before the walk reports an account without it, and
|
|
237
|
+
* one that keeps wei reports them. That is the whole of the policy left to
|
|
238
|
+
* the caller; everything downstream of the balances is decided here.
|
|
239
|
+
*
|
|
240
|
+
* @param options - The operation's effect on the pool, for the rate the
|
|
241
|
+
* metrics are quoted at, see {@link ProjectedPoolOptions}.
|
|
242
|
+
**/
|
|
243
|
+
projection(snapshot, options) {
|
|
244
|
+
const { creditManager, totalValue, totalDebt } = snapshot;
|
|
245
|
+
const market = this.sdk.marketRegister.findByCreditManager(creditManager);
|
|
246
|
+
const { priceOracle } = market;
|
|
247
|
+
return {
|
|
248
|
+
...require_onchain_market_credit_creditOperationMarket.creditOperationMarket(this.sdk.marketRegister.findCreditManager(creditManager)),
|
|
249
|
+
totalValue: market.toUnderlyingAmount(totalValue),
|
|
250
|
+
totalDebt: market.toUnderlyingAmount(totalDebt),
|
|
251
|
+
netValue: market.toUnderlyingAmount(totalValue - totalDebt),
|
|
252
|
+
assets: snapshot.assets.map((a) => priceOracle.toTokenAmount(a.token, a.balance)),
|
|
253
|
+
quotas: snapshot.quotas.map((q) => ({
|
|
254
|
+
token: this.sdk.tokensMeta.mustGetToken(q.token),
|
|
255
|
+
...priceOracle.toAmount(market.underlying, q.balance)
|
|
256
|
+
})),
|
|
257
|
+
...this.metrics(snapshot, options)
|
|
258
|
+
};
|
|
259
|
+
}
|
|
260
|
+
/**
|
|
167
261
|
* Builds one strategy position from an account snapshot.
|
|
168
262
|
*
|
|
169
263
|
* @param withdrawals - Delayed withdrawals of the account, keyed by the
|
|
@@ -11,13 +11,23 @@ let viem = require("viem");
|
|
|
11
11
|
* holds exactly one non-dust non-underlying asset; otherwise `null`.
|
|
12
12
|
**/
|
|
13
13
|
function calcLiquidationPrice(props) {
|
|
14
|
-
const
|
|
15
|
-
|
|
16
|
-
if (targets.length !== 1) return null;
|
|
14
|
+
const targetToken = soleNonUnderlyingCollateral(props.snapshot, props.underlying);
|
|
15
|
+
if (!targetToken) return null;
|
|
17
16
|
return require_onchain_positions_calcLiquidationPriceForTarget.calcLiquidationPriceForTarget({
|
|
18
17
|
...props,
|
|
19
|
-
targetToken
|
|
18
|
+
targetToken
|
|
20
19
|
});
|
|
21
20
|
}
|
|
21
|
+
/**
|
|
22
|
+
* The one collateral a liquidation price — and the current price beside it —
|
|
23
|
+
* can be quoted for: the account's single non-dust, non-underlying asset.
|
|
24
|
+
* `null` when it holds none or several, which is the case neither figure
|
|
25
|
+
* exists for.
|
|
26
|
+
**/
|
|
27
|
+
function soleNonUnderlyingCollateral(snapshot, underlying) {
|
|
28
|
+
const targets = snapshot.assets.filter((a) => a.balance > 10n && !(0, viem.isAddressEqual)(a.token, underlying));
|
|
29
|
+
return targets.length === 1 ? targets[0].token : null;
|
|
30
|
+
}
|
|
22
31
|
//#endregion
|
|
23
32
|
exports.calcLiquidationPrice = calcLiquidationPrice;
|
|
33
|
+
exports.soleNonUnderlyingCollateral = soleNonUnderlyingCollateral;
|
|
@@ -15,3 +15,4 @@ exports.calcHealthFactor = require_onchain_positions_calcHealthFactor.calcHealth
|
|
|
15
15
|
exports.calcLiquidationPrice = require_onchain_positions_calcLiquidationPrice.calcLiquidationPrice;
|
|
16
16
|
exports.calcLiquidationPriceForTarget = require_onchain_positions_calcLiquidationPriceForTarget.calcLiquidationPriceForTarget;
|
|
17
17
|
exports.calcTimeToLiquidationMs = require_onchain_positions_calcTimeToLiquidationMs.calcTimeToLiquidationMs;
|
|
18
|
+
exports.soleNonUnderlyingCollateral = require_onchain_positions_calcLiquidationPrice.soleNonUnderlyingCollateral;
|
|
@@ -20,7 +20,7 @@ const require_preview_prerequisites_BalancePrerequisite = require("./prerequisit
|
|
|
20
20
|
const require_preview_prerequisites_RWAOpenRequirementsPrerequisite = require("./prerequisites/RWAOpenRequirementsPrerequisite.js");
|
|
21
21
|
const require_preview_prerequisites_checkPrerequisites = require("./prerequisites/checkPrerequisites.js");
|
|
22
22
|
require("./prerequisites/index.js");
|
|
23
|
-
const
|
|
23
|
+
const require_preview_preview_buildDelayedStrategyVerify = require("./preview/buildDelayedStrategyVerify.js");
|
|
24
24
|
const require_preview_preview_CreditAccountState = require("./preview/CreditAccountState.js");
|
|
25
25
|
const require_preview_preview_detectCloseOrRepay = require("./preview/detectCloseOrRepay.js");
|
|
26
26
|
const require_preview_preview_detectDelayedClaim = require("./preview/detectDelayedClaim.js");
|
|
@@ -28,8 +28,8 @@ const require_preview_preview_detectDelayedOperation = require("./preview/detect
|
|
|
28
28
|
const require_preview_preview_errors = require("./preview/errors.js");
|
|
29
29
|
const require_preview_preview_replayInnerOperations = require("./preview/replayInnerOperations.js");
|
|
30
30
|
const require_preview_preview_replayMulticall = require("./preview/replayMulticall.js");
|
|
31
|
-
const
|
|
32
|
-
const
|
|
31
|
+
const require_preview_preview_previewAdjustStrategyVerify = require("./preview/previewAdjustStrategyVerify.js");
|
|
32
|
+
const require_preview_preview_previewExitOrRepayStrategyVerify = require("./preview/previewExitOrRepayStrategyVerify.js");
|
|
33
33
|
const require_preview_preview_previewOperation = require("./preview/previewOperation.js");
|
|
34
34
|
require("./preview/index.js");
|
|
35
35
|
require("./types.js");
|
|
@@ -51,7 +51,7 @@ exports.UnsupportedPoolFunctionError = require_preview_parse_errors.UnsupportedP
|
|
|
51
51
|
exports.UnsupportedTargetError = require_preview_parse_errors.UnsupportedTargetError;
|
|
52
52
|
exports.UnsupportedZapperFunctionError = require_onchain_market_zapper_errors.UnsupportedZapperFunctionError;
|
|
53
53
|
exports.WithdrawCollateralAlignmentError = require_preview_trace_errors.WithdrawCollateralAlignmentError;
|
|
54
|
-
exports.
|
|
54
|
+
exports.buildDelayedStrategyVerify = require_preview_preview_buildDelayedStrategyVerify.buildDelayedStrategyVerify;
|
|
55
55
|
exports.checkOperation = require_preview_validate_checkOperation.checkOperation;
|
|
56
56
|
exports.checkPrerequisites = require_preview_prerequisites_checkPrerequisites.checkPrerequisites;
|
|
57
57
|
exports.checkSimulation = require_preview_validate_checkSimulation.checkSimulation;
|
|
@@ -72,8 +72,8 @@ exports.parseFacadeOperationCalldata = require_preview_parse_parseFacadeOperatio
|
|
|
72
72
|
exports.parseOperationCalldata = require_preview_parse_parseOperationCalldata.parseOperationCalldata;
|
|
73
73
|
exports.parsePoolOperationCalldata = require_preview_parse_parsePoolOperationCalldata.parsePoolOperationCalldata;
|
|
74
74
|
exports.parseRWAFactoryOperationCalldata = require_preview_parse_parseRWAFactoryOperationCalldata.parseRWAFactoryOperationCalldata;
|
|
75
|
-
exports.
|
|
76
|
-
exports.
|
|
75
|
+
exports.previewAdjustStrategyVerify = require_preview_preview_previewAdjustStrategyVerify.previewAdjustStrategyVerify;
|
|
76
|
+
exports.previewExitOrRepayStrategyVerify = require_preview_preview_previewExitOrRepayStrategyVerify.previewExitOrRepayStrategyVerify;
|
|
77
77
|
exports.previewOperation = require_preview_preview_previewOperation.previewOperation;
|
|
78
78
|
exports.quotaCountIssue = require_preview_validate_checkOperation.quotaCountIssue;
|
|
79
79
|
exports.raise = require_onchain_validation_refusal.raise;
|
|
@@ -2,12 +2,12 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
|
2
2
|
const require_onchain_utils_AssetsMap = require("../../onchain/utils/AssetsMap.js");
|
|
3
3
|
const require_onchain_utils_bigint_math = require("../../onchain/utils/bigint-math.js");
|
|
4
4
|
const require_onchain_constants_math = require("../../onchain/constants/math.js");
|
|
5
|
-
const
|
|
5
|
+
const require_onchain_market_credit_creditOperationMarket = require("../../onchain/market/credit/creditOperationMarket.js");
|
|
6
6
|
const require_model_previews = require("../../model/previews.js");
|
|
7
7
|
require("../../model/index.js");
|
|
8
8
|
require("../../onchain/index.js");
|
|
9
9
|
let viem = require("viem");
|
|
10
|
-
//#region src/preview/preview/
|
|
10
|
+
//#region src/preview/preview/buildDelayedStrategyVerify.ts
|
|
11
11
|
/**
|
|
12
12
|
* Builds the best-effort preview of the account state after the detected
|
|
13
13
|
* delayed withdrawal is claimed and its intent (if any) is resumed:
|
|
@@ -30,7 +30,7 @@ let viem = require("viem");
|
|
|
30
30
|
* @param sdk - Market data source for the position metrics of the resulting
|
|
31
31
|
* state; read synchronously, no network access.
|
|
32
32
|
*/
|
|
33
|
-
function
|
|
33
|
+
function buildDelayedStrategyVerify(afterInstant, before, detected, convert, receivedToken, sdk) {
|
|
34
34
|
const { request, intent } = detected;
|
|
35
35
|
const post = afterInstant.clone();
|
|
36
36
|
const converter = makeSafeConverter(convert);
|
|
@@ -167,49 +167,30 @@ function buildClosePreview(post, converter, receivedToken, sdk) {
|
|
|
167
167
|
return {
|
|
168
168
|
operation: "CloseCreditAccount",
|
|
169
169
|
permanent: false,
|
|
170
|
-
|
|
171
|
-
name: sdk.marketRegister.findCreditManager(post.creditManager).name,
|
|
170
|
+
...require_onchain_market_credit_creditOperationMarket.creditOperationMarket(sdk.marketRegister.findCreditManager(post.creditManager)),
|
|
172
171
|
creditAccount: post.creditAccount,
|
|
173
172
|
receivedAmount: oracle.toTokenAmount(receivedToken, require_onchain_utils_bigint_math.BigIntMath.max(totalValue - post.totalDebt, 0n)),
|
|
174
173
|
error: converter.error
|
|
175
174
|
};
|
|
176
175
|
}
|
|
177
176
|
function buildAdjustPreview(post, before, collateralWithdrawn, converter, sdk) {
|
|
178
|
-
const
|
|
179
|
-
const assets = post.balances.toAssets(require_onchain_constants_math.DUST_THRESHOLD);
|
|
180
|
-
const quotas = post.quotas.toAssets(0n);
|
|
181
|
-
const snap = post.toSnapshot(totalValue);
|
|
177
|
+
const snap = post.toSnapshot(totalValueInUnderlying(post, converter.convert, require_onchain_constants_math.DUST_THRESHOLD));
|
|
182
178
|
const market = sdk.marketRegister.findByCreditManager(post.creditManager);
|
|
183
179
|
const oracle = market.priceOracle;
|
|
184
180
|
return {
|
|
185
181
|
operation: "AdjustCreditAccount",
|
|
186
|
-
|
|
187
|
-
name: sdk.marketRegister.findCreditManager(post.creditManager).name,
|
|
182
|
+
...require_model_previews.asEstimated(sdk.positions.projection(snap, { availableLiquidityChange: before.totalDebt - post.totalDebt })),
|
|
188
183
|
creditAccount: post.creditAccount,
|
|
189
184
|
collateralAdded: [],
|
|
190
185
|
collateralWithdrawn: collateralWithdrawn.toAssets().map((a) => oracle.toTokenAmount(a.token, a.balance)),
|
|
191
|
-
totalValue: market.toUnderlyingAmount(totalValue),
|
|
192
|
-
totalDebt: market.toUnderlyingAmount(post.totalDebt),
|
|
193
|
-
netValue: market.toUnderlyingAmount(totalValue - post.totalDebt),
|
|
194
186
|
totalDebtChange: market.toUnderlyingAmount(post.totalDebt - before.totalDebt),
|
|
195
|
-
quotas: quotas.map((q) => ({
|
|
196
|
-
token: sdk.tokensMeta.mustGetToken(q.token),
|
|
197
|
-
...oracle.toAmount(market.underlying, q.balance)
|
|
198
|
-
})),
|
|
199
187
|
quotasChange: post.quotas.difference(before.quotas).toAssets().map((q) => ({
|
|
200
188
|
token: sdk.tokensMeta.mustGetToken(q.token),
|
|
201
189
|
...oracle.toAmount(market.underlying, q.balance)
|
|
202
190
|
})),
|
|
203
|
-
assets: assets.map((a) => oracle.toTokenAmount(a.token, a.balance)),
|
|
204
191
|
assetsChange: post.balances.difference(before.balances).toAssets(require_onchain_constants_math.DUST_THRESHOLD).map((a) => oracle.toTokenAmount(a.token, a.balance)),
|
|
205
|
-
error: converter.error
|
|
206
|
-
healthFactor: sdk.positions.healthFactor(snap),
|
|
207
|
-
safeHealthFactor: sdk.positions.healthFactor(snap, { safePrices: true }),
|
|
208
|
-
borrowRate: sdk.positions.borrowRate(snap, { availableLiquidityChange: before.totalDebt - post.totalDebt }),
|
|
209
|
-
timeToLiquidation: sdk.positions.timeToLiquidation(snap, { availableLiquidityChange: before.totalDebt - post.totalDebt }),
|
|
210
|
-
liquidationPrice: sdk.positions.liquidationPrice(snap),
|
|
211
|
-
leverage: require_onchain_market_math.calcPositionLeverage(totalValue, post.totalDebt)
|
|
192
|
+
error: converter.error
|
|
212
193
|
};
|
|
213
194
|
}
|
|
214
195
|
//#endregion
|
|
215
|
-
exports.
|
|
196
|
+
exports.buildDelayedStrategyVerify = buildDelayedStrategyVerify;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
-
const
|
|
2
|
+
const require_preview_preview_buildDelayedStrategyVerify = require("./buildDelayedStrategyVerify.js");
|
|
3
3
|
const require_preview_preview_CreditAccountState = require("./CreditAccountState.js");
|
|
4
4
|
const require_preview_preview_detectCloseOrRepay = require("./detectCloseOrRepay.js");
|
|
5
5
|
const require_preview_preview_detectDelayedClaim = require("./detectDelayedClaim.js");
|
|
@@ -7,19 +7,19 @@ const require_preview_preview_detectDelayedOperation = require("./detectDelayedO
|
|
|
7
7
|
const require_preview_preview_errors = require("./errors.js");
|
|
8
8
|
const require_preview_preview_replayInnerOperations = require("./replayInnerOperations.js");
|
|
9
9
|
const require_preview_preview_replayMulticall = require("./replayMulticall.js");
|
|
10
|
-
const
|
|
11
|
-
const
|
|
10
|
+
const require_preview_preview_previewAdjustStrategyVerify = require("./previewAdjustStrategyVerify.js");
|
|
11
|
+
const require_preview_preview_previewExitOrRepayStrategyVerify = require("./previewExitOrRepayStrategyVerify.js");
|
|
12
12
|
const require_preview_preview_previewOperation = require("./previewOperation.js");
|
|
13
13
|
exports.CreditAccountState = require_preview_preview_CreditAccountState.CreditAccountState;
|
|
14
14
|
exports.UnsupportedOperationError = require_preview_preview_errors.UnsupportedOperationError;
|
|
15
|
-
exports.
|
|
15
|
+
exports.buildDelayedStrategyVerify = require_preview_preview_buildDelayedStrategyVerify.buildDelayedStrategyVerify;
|
|
16
16
|
exports.classifyCloseOrRepay = require_preview_preview_detectCloseOrRepay.classifyCloseOrRepay;
|
|
17
17
|
exports.detectDelayedClaim = require_preview_preview_detectDelayedClaim.detectDelayedClaim;
|
|
18
18
|
exports.detectDelayedOperation = require_preview_preview_detectDelayedOperation.detectDelayedOperation;
|
|
19
19
|
exports.isCloseOrRepay = require_preview_preview_detectCloseOrRepay.isCloseOrRepay;
|
|
20
20
|
exports.makeReplayState = require_preview_preview_replayInnerOperations.makeReplayState;
|
|
21
|
-
exports.
|
|
22
|
-
exports.
|
|
21
|
+
exports.previewAdjustStrategyVerify = require_preview_preview_previewAdjustStrategyVerify.previewAdjustStrategyVerify;
|
|
22
|
+
exports.previewExitOrRepayStrategyVerify = require_preview_preview_previewExitOrRepayStrategyVerify.previewExitOrRepayStrategyVerify;
|
|
23
23
|
exports.previewOperation = require_preview_preview_previewOperation.previewOperation;
|
|
24
24
|
exports.replayInnerOperations = require_preview_preview_replayInnerOperations.replayInnerOperations;
|
|
25
25
|
exports.replayMulticall = require_preview_preview_replayMulticall.replayMulticall;
|
package/dist/cjs/preview/preview/{previewAdjustCreditAccount.js → previewAdjustStrategyVerify.js}
RENAMED
|
@@ -1,13 +1,12 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
2
|
const require_onchain_constants_address_provider = require("../../onchain/constants/address-provider.js");
|
|
3
3
|
const require_onchain_constants_math = require("../../onchain/constants/math.js");
|
|
4
|
-
const require_onchain_market_math = require("../../onchain/market/math.js");
|
|
5
4
|
const require_model_previews = require("../../model/previews.js");
|
|
6
5
|
require("../../model/index.js");
|
|
7
6
|
require("../../onchain/index.js");
|
|
8
7
|
const require_preview_preview_replayMulticall = require("./replayMulticall.js");
|
|
9
8
|
const require_preview_preview_unwrapNativeCollateral = require("./unwrapNativeCollateral.js");
|
|
10
|
-
//#region src/preview/preview/
|
|
9
|
+
//#region src/preview/preview/previewAdjustStrategyVerify.ts
|
|
11
10
|
/**
|
|
12
11
|
* Previews a `multicall`/`botMulticall` operation on an existing credit
|
|
13
12
|
* account: threads the multicall through {@link replayMulticall} over the
|
|
@@ -15,7 +14,7 @@ const require_preview_preview_unwrapNativeCollateral = require("./unwrapNativeCo
|
|
|
15
14
|
* minimal guaranteed post-state alongside the changes relative to the
|
|
16
15
|
* pre-state.
|
|
17
16
|
*/
|
|
18
|
-
async function
|
|
17
|
+
async function previewAdjustStrategyVerify(input, operation, options) {
|
|
19
18
|
const { sdk, value = 0n } = input;
|
|
20
19
|
const market = sdk.marketRegister.findByCreditManager(operation.creditManager);
|
|
21
20
|
const oracle = market.priceOracle;
|
|
@@ -24,10 +23,8 @@ async function previewAdjustCreditAccount(input, operation, options) {
|
|
|
24
23
|
let error = replayError;
|
|
25
24
|
const { assets: collateralAdded, error: unwrapError } = require_preview_preview_unwrapNativeCollateral.unwrapNativeCollateral(after.collateralAdded.toAssets(), value, sdk.addressProvider.getAddress(require_onchain_constants_address_provider.AP_WETH_TOKEN, 0));
|
|
26
25
|
error ??= unwrapError;
|
|
27
|
-
const assets = account.balances.toAssets(require_onchain_constants_math.DUST_THRESHOLD);
|
|
28
|
-
const quotas = account.quotas.toAssets(0n);
|
|
29
26
|
const assetsChange = account.balances.difference(before.balances).toAssets(require_onchain_constants_math.DUST_THRESHOLD);
|
|
30
|
-
const totalValue =
|
|
27
|
+
const totalValue = account.balances.toAssets(require_onchain_constants_math.DUST_THRESHOLD).reduce((acc, { token, balance }) => {
|
|
31
28
|
try {
|
|
32
29
|
return acc + oracle.convert(token, market.underlying, balance);
|
|
33
30
|
} catch {
|
|
@@ -41,33 +38,18 @@ async function previewAdjustCreditAccount(input, operation, options) {
|
|
|
41
38
|
const snap = account.toSnapshot(totalValue);
|
|
42
39
|
return {
|
|
43
40
|
operation: "AdjustCreditAccount",
|
|
44
|
-
|
|
45
|
-
name: sdk.marketRegister.findCreditManager(operation.creditManager).name,
|
|
41
|
+
...require_model_previews.asEstimated(sdk.positions.projection(snap, { availableLiquidityChange: before.totalDebt - account.totalDebt })),
|
|
46
42
|
creditAccount: operation.creditAccount,
|
|
47
43
|
collateralAdded: collateralAdded.map((a) => oracle.toTokenAmount(a.token, a.balance)),
|
|
48
44
|
collateralWithdrawn: after.collateralWithdrawn.toAssets().map((a) => oracle.toTokenAmount(a.token, a.balance)),
|
|
49
|
-
totalValue: market.toUnderlyingAmount(totalValue),
|
|
50
|
-
totalDebt: market.toUnderlyingAmount(account.totalDebt),
|
|
51
|
-
netValue: market.toUnderlyingAmount(totalValue - account.totalDebt),
|
|
52
45
|
totalDebtChange: market.toUnderlyingAmount(account.totalDebt - before.totalDebt),
|
|
53
|
-
quotas: quotas.map((q) => ({
|
|
54
|
-
token: sdk.tokensMeta.mustGetToken(q.token),
|
|
55
|
-
...oracle.toAmount(market.underlying, q.balance)
|
|
56
|
-
})),
|
|
57
46
|
quotasChange: account.quotas.difference(before.quotas).toAssets().map((q) => ({
|
|
58
47
|
token: sdk.tokensMeta.mustGetToken(q.token),
|
|
59
48
|
...oracle.toAmount(market.underlying, q.balance)
|
|
60
49
|
})),
|
|
61
|
-
assets: assets.map((a) => oracle.toTokenAmount(a.token, a.balance)),
|
|
62
50
|
assetsChange: assetsChange.map((a) => oracle.toTokenAmount(a.token, a.balance)),
|
|
63
|
-
error
|
|
64
|
-
healthFactor: sdk.positions.healthFactor(snap),
|
|
65
|
-
safeHealthFactor: sdk.positions.healthFactor(snap, { safePrices: true }),
|
|
66
|
-
borrowRate: sdk.positions.borrowRate(snap, { availableLiquidityChange: before.totalDebt - account.totalDebt }),
|
|
67
|
-
timeToLiquidation: sdk.positions.timeToLiquidation(snap, { availableLiquidityChange: before.totalDebt - account.totalDebt }),
|
|
68
|
-
liquidationPrice: sdk.positions.liquidationPrice(snap),
|
|
69
|
-
leverage: require_onchain_market_math.calcPositionLeverage(totalValue, account.totalDebt)
|
|
51
|
+
error
|
|
70
52
|
};
|
|
71
53
|
}
|
|
72
54
|
//#endregion
|
|
73
|
-
exports.
|
|
55
|
+
exports.previewAdjustStrategyVerify = previewAdjustStrategyVerify;
|
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
2
|
const require_onchain_constants_address_provider = require("../../onchain/constants/address-provider.js");
|
|
3
3
|
require("../../onchain/constants/math.js");
|
|
4
|
+
const require_onchain_market_credit_creditOperationMarket = require("../../onchain/market/credit/creditOperationMarket.js");
|
|
4
5
|
require("../../onchain/index.js");
|
|
5
6
|
const require_preview_preview_detectCloseOrRepay = require("./detectCloseOrRepay.js");
|
|
6
7
|
const require_preview_preview_replayMulticall = require("./replayMulticall.js");
|
|
7
8
|
const require_preview_preview_unwrapNativeCollateral = require("./unwrapNativeCollateral.js");
|
|
8
|
-
//#region src/preview/preview/
|
|
9
|
-
async function
|
|
9
|
+
//#region src/preview/preview/previewExitOrRepayStrategyVerify.ts
|
|
10
|
+
async function previewExitOrRepayStrategyVerify(input, operation, permanent, options) {
|
|
10
11
|
const { sdk } = input;
|
|
11
12
|
const market = sdk.marketRegister.findByCreditManager(operation.creditManager);
|
|
12
13
|
const exitTokens = [market.underlying];
|
|
@@ -32,8 +33,7 @@ function previewCloseCreditAccount(input, operation, permanent, replay) {
|
|
|
32
33
|
return {
|
|
33
34
|
operation: "CloseCreditAccount",
|
|
34
35
|
permanent,
|
|
35
|
-
|
|
36
|
-
name: sdk.marketRegister.findCreditManager(operation.creditManager).name,
|
|
36
|
+
...require_onchain_market_credit_creditOperationMarket.creditOperationMarket(sdk.marketRegister.findCreditManager(operation.creditManager)),
|
|
37
37
|
creditAccount: operation.creditAccount,
|
|
38
38
|
receivedAmount: market.priceOracle.toTokenAmount(receivedToken, after.collateralWithdrawn.getOrZero(receivedToken)),
|
|
39
39
|
error
|
|
@@ -53,8 +53,7 @@ function previewRepayCreditAccount(input, operation, permanent, replay) {
|
|
|
53
53
|
return {
|
|
54
54
|
operation: "RepayCreditAccount",
|
|
55
55
|
permanent,
|
|
56
|
-
|
|
57
|
-
name: sdk.marketRegister.findCreditManager(operation.creditManager).name,
|
|
56
|
+
...require_onchain_market_credit_creditOperationMarket.creditOperationMarket(sdk.marketRegister.findCreditManager(operation.creditManager)),
|
|
58
57
|
creditAccount: operation.creditAccount,
|
|
59
58
|
collateralAdded: collateralAdded.map((a) => market.priceOracle.toTokenAmount(a.token, a.balance)),
|
|
60
59
|
debtRepaid: market.toUnderlyingAmount(before.totalDebt - after.account.totalDebt),
|
|
@@ -63,4 +62,4 @@ function previewRepayCreditAccount(input, operation, permanent, replay) {
|
|
|
63
62
|
};
|
|
64
63
|
}
|
|
65
64
|
//#endregion
|
|
66
|
-
exports.
|
|
65
|
+
exports.previewExitOrRepayStrategyVerify = previewExitOrRepayStrategyVerify;
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
2
|
const require_preview_simulate_simulatePoolOperation = require("../simulate/simulatePoolOperation.js");
|
|
3
3
|
require("../simulate/index.js");
|
|
4
|
-
//#region src/preview/preview/
|
|
5
|
-
async function
|
|
4
|
+
//#region src/preview/preview/previewLpVerify.ts
|
|
5
|
+
async function previewLpVerify(input, operation, options) {
|
|
6
6
|
const { sdk, to, calldata } = input;
|
|
7
7
|
const { tokenIn, tokenOut } = operation;
|
|
8
8
|
const market = sdk.marketRegister.findByPool(operation.pool);
|
|
@@ -22,4 +22,4 @@ async function previewPoolOperation(input, operation, options) {
|
|
|
22
22
|
};
|
|
23
23
|
}
|
|
24
24
|
//#endregion
|
|
25
|
-
exports.
|
|
25
|
+
exports.previewLpVerify = previewLpVerify;
|
package/dist/cjs/preview/preview/{previewOpenCreditAccount.js → previewOpenStrategyVerify.js}
RENAMED
|
@@ -1,15 +1,13 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
2
|
const require_onchain_constants_address_provider = require("../../onchain/constants/address-provider.js");
|
|
3
|
-
const require_onchain_constants_math = require("../../onchain/constants/math.js");
|
|
4
|
-
const require_onchain_market_math = require("../../onchain/market/math.js");
|
|
5
3
|
const require_model_previews = require("../../model/previews.js");
|
|
6
4
|
require("../../model/index.js");
|
|
7
5
|
require("../../onchain/index.js");
|
|
8
6
|
const require_preview_preview_CreditAccountState = require("./CreditAccountState.js");
|
|
9
7
|
const require_preview_preview_replayInnerOperations = require("./replayInnerOperations.js");
|
|
10
8
|
const require_preview_preview_unwrapNativeCollateral = require("./unwrapNativeCollateral.js");
|
|
11
|
-
//#region src/preview/preview/
|
|
12
|
-
async function
|
|
9
|
+
//#region src/preview/preview/previewOpenStrategyVerify.ts
|
|
10
|
+
async function previewOpenStrategyVerify(input, operation) {
|
|
13
11
|
const { sdk, value = 0n } = input;
|
|
14
12
|
const market = sdk.marketRegister.findByCreditManager(operation.creditManager);
|
|
15
13
|
const oracle = market.priceOracle;
|
|
@@ -30,32 +28,14 @@ async function previewOpenCreditAccount(input, operation) {
|
|
|
30
28
|
});
|
|
31
29
|
const { assets: collateral, error: unwrapError } = require_preview_preview_unwrapNativeCollateral.unwrapNativeCollateral(state.collateralAdded.toAssets(), value, sdk.addressProvider.getAddress(require_onchain_constants_address_provider.AP_WETH_TOKEN, 0));
|
|
32
30
|
error ??= unwrapError ?? priceError;
|
|
33
|
-
const
|
|
34
|
-
const quotas = account.quotas.toAssets(0n);
|
|
35
|
-
const totalValue = netValue + account.totalDebt;
|
|
36
|
-
const snap = account.toSnapshot(totalValue);
|
|
31
|
+
const snap = account.toSnapshot(netValue + account.totalDebt);
|
|
37
32
|
const targetAsset = inferTargetAsset(operation.multicall, account.balances);
|
|
38
33
|
return {
|
|
39
34
|
operation: operation.operation,
|
|
40
|
-
|
|
41
|
-
name: sdk.marketRegister.findCreditManager(operation.creditManager).name,
|
|
35
|
+
...require_model_previews.asEstimated(sdk.positions.projection(snap, { availableLiquidityChange: -account.totalDebt })),
|
|
42
36
|
targetCollateral: targetAsset ? oracle.toTokenAmount(targetAsset.token, targetAsset.balance) : void 0,
|
|
43
37
|
collateralAdded: collateral.map((a) => oracle.toTokenAmount(a.token, a.balance)),
|
|
44
|
-
|
|
45
|
-
totalValue: market.toUnderlyingAmount(totalValue),
|
|
46
|
-
totalDebt: market.toUnderlyingAmount(account.totalDebt),
|
|
47
|
-
quotas: quotas.map((q) => ({
|
|
48
|
-
token: sdk.tokensMeta.mustGetToken(q.token),
|
|
49
|
-
...oracle.toAmount(market.underlying, q.balance)
|
|
50
|
-
})),
|
|
51
|
-
assets: assets.map((a) => oracle.toTokenAmount(a.token, a.balance)),
|
|
52
|
-
error,
|
|
53
|
-
healthFactor: sdk.positions.healthFactor(snap),
|
|
54
|
-
safeHealthFactor: sdk.positions.healthFactor(snap, { safePrices: true }),
|
|
55
|
-
borrowRate: sdk.positions.borrowRate(snap, { availableLiquidityChange: -account.totalDebt }),
|
|
56
|
-
timeToLiquidation: sdk.positions.timeToLiquidation(snap, { availableLiquidityChange: -account.totalDebt }),
|
|
57
|
-
liquidationPrice: sdk.positions.liquidationPrice(snap),
|
|
58
|
-
leverage: require_onchain_market_math.calcPositionLeverage(totalValue, account.totalDebt)
|
|
38
|
+
error
|
|
59
39
|
};
|
|
60
40
|
}
|
|
61
41
|
/**
|
|
@@ -73,4 +53,4 @@ function inferTargetAsset(multicall, balances) {
|
|
|
73
53
|
}
|
|
74
54
|
}
|
|
75
55
|
//#endregion
|
|
76
|
-
exports.
|
|
56
|
+
exports.previewOpenStrategyVerify = previewOpenStrategyVerify;
|
|
@@ -1,17 +1,19 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
const require_onchain_market_credit_creditOperationMarket = require("../../onchain/market/credit/creditOperationMarket.js");
|
|
3
|
+
require("../../onchain/index.js");
|
|
2
4
|
const require_preview_parse_parseOperationCalldata = require("../parse/parseOperationCalldata.js");
|
|
3
5
|
const require_preview_parse_types = require("../parse/types.js");
|
|
4
6
|
require("../parse/index.js");
|
|
5
|
-
const
|
|
7
|
+
const require_preview_preview_buildDelayedStrategyVerify = require("./buildDelayedStrategyVerify.js");
|
|
6
8
|
const require_preview_preview_detectCloseOrRepay = require("./detectCloseOrRepay.js");
|
|
7
9
|
const require_preview_preview_detectDelayedClaim = require("./detectDelayedClaim.js");
|
|
8
10
|
const require_preview_preview_detectDelayedOperation = require("./detectDelayedOperation.js");
|
|
9
11
|
const require_preview_preview_errors = require("./errors.js");
|
|
10
12
|
const require_preview_preview_replayMulticall = require("./replayMulticall.js");
|
|
11
|
-
const
|
|
12
|
-
const
|
|
13
|
-
const
|
|
14
|
-
const
|
|
13
|
+
const require_preview_preview_previewAdjustStrategyVerify = require("./previewAdjustStrategyVerify.js");
|
|
14
|
+
const require_preview_preview_previewExitOrRepayStrategyVerify = require("./previewExitOrRepayStrategyVerify.js");
|
|
15
|
+
const require_preview_preview_previewLpVerify = require("./previewLpVerify.js");
|
|
16
|
+
const require_preview_preview_previewOpenStrategyVerify = require("./previewOpenStrategyVerify.js");
|
|
15
17
|
//#region src/preview/preview/previewOperation.ts
|
|
16
18
|
/**
|
|
17
19
|
* Previews a raw operation calldata: decodes it into a typed operation and
|
|
@@ -19,11 +21,11 @@ const require_preview_preview_previewPoolOperation = require("./previewPoolOpera
|
|
|
19
21
|
*/
|
|
20
22
|
async function previewOperation(input, options) {
|
|
21
23
|
const operation = require_preview_parse_parseOperationCalldata.parseOperationCalldata(input);
|
|
22
|
-
if (require_preview_parse_types.isPoolOperation(operation)) return
|
|
23
|
-
if (operation.operation === "OpenCreditAccount" || operation.operation === "RWAOpenCreditAccount") return
|
|
24
|
+
if (require_preview_parse_types.isPoolOperation(operation)) return require_preview_preview_previewLpVerify.previewLpVerify(input, operation, options);
|
|
25
|
+
if (operation.operation === "OpenCreditAccount" || operation.operation === "RWAOpenCreditAccount") return require_preview_preview_previewOpenStrategyVerify.previewOpenStrategyVerify(input, operation);
|
|
24
26
|
if (operation.operation === "CloseCreditAccount") {
|
|
25
27
|
const resolved = await resolveCreditAccount(input, operation, options);
|
|
26
|
-
const preview = await
|
|
28
|
+
const preview = await require_preview_preview_previewExitOrRepayStrategyVerify.previewExitOrRepayStrategyVerify(input, operation, true, resolved);
|
|
27
29
|
preview.intent = await require_preview_preview_detectDelayedClaim.resolveDelayedClaimIntent(input.sdk, operation.multicall, options?.blockNumber);
|
|
28
30
|
return preview;
|
|
29
31
|
}
|
|
@@ -53,7 +55,7 @@ async function resolveCreditAccount(input, operation, options) {
|
|
|
53
55
|
*/
|
|
54
56
|
async function previewMulticallOperation(input, operation, options) {
|
|
55
57
|
const { sdk } = input;
|
|
56
|
-
const instantPreview = require_preview_preview_detectCloseOrRepay.isCloseOrRepay(operation.multicall) ? await
|
|
58
|
+
const instantPreview = require_preview_preview_detectCloseOrRepay.isCloseOrRepay(operation.multicall) ? await require_preview_preview_previewExitOrRepayStrategyVerify.previewExitOrRepayStrategyVerify(input, operation, false, options) : await require_preview_preview_previewAdjustStrategyVerify.previewAdjustStrategyVerify(input, operation, options);
|
|
57
59
|
const delayed = require_preview_preview_detectDelayedOperation.detectDelayedOperation(sdk, operation.multicall);
|
|
58
60
|
if (!delayed) {
|
|
59
61
|
instantPreview.intent = await require_preview_preview_detectDelayedClaim.resolveDelayedClaimIntent(sdk, operation.multicall, options?.blockNumber);
|
|
@@ -67,11 +69,10 @@ async function previewMulticallOperation(input, operation, options) {
|
|
|
67
69
|
return {
|
|
68
70
|
operation: "DelayedCreditAccountOperation",
|
|
69
71
|
creditAccount: operation.creditAccount,
|
|
70
|
-
|
|
71
|
-
name: sdk.marketRegister.findCreditManager(operation.creditManager).name,
|
|
72
|
+
...require_onchain_market_credit_creditOperationMarket.creditOperationMarket(sdk.marketRegister.findCreditManager(operation.creditManager)),
|
|
72
73
|
intent: delayed.intent,
|
|
73
74
|
instantPreview,
|
|
74
|
-
delayedPreview:
|
|
75
|
+
delayedPreview: require_preview_preview_buildDelayedStrategyVerify.buildDelayedStrategyVerify(after.account, before, delayed, convert, receivedToken, sdk)
|
|
75
76
|
};
|
|
76
77
|
}
|
|
77
78
|
//#endregion
|
|
@@ -72,7 +72,11 @@ function creditIssues(sdk, preview, options) {
|
|
|
72
72
|
maxDebt: suite.creditFacade.maxDebt,
|
|
73
73
|
underlying,
|
|
74
74
|
allowZero: !isOpening
|
|
75
|
-
}) || borrowIssue(suite, preview, underlying) || forbiddenIssue(suite, preview) || quotaCountIssue(suite, preview) || quotaIssue(market, preview, underlying) || collateralIssue(
|
|
75
|
+
}) || borrowIssue(suite, preview, underlying) || forbiddenIssue(suite, preview) || quotaCountIssue(suite, preview) || quotaIssue(market, preview, underlying) || collateralIssue({
|
|
76
|
+
totalDebt: preview.totalDebt,
|
|
77
|
+
healthFactor: preview.estHealthFactor,
|
|
78
|
+
safeHealthFactor: preview.estSafeHealthFactor
|
|
79
|
+
}, options) || fundingIssue(options, preview.collateralAdded);
|
|
76
80
|
}
|
|
77
81
|
/**
|
|
78
82
|
* A bar that reads nothing but the projected account, so a parsed transaction
|
|
@@ -83,9 +87,9 @@ function creditIssues(sdk, preview, options) {
|
|
|
83
87
|
* need an operation's *delta* between them, and the caller acts on the first
|
|
84
88
|
* issue reported.
|
|
85
89
|
*/
|
|
86
|
-
function quotaCountIssue(suite,
|
|
90
|
+
function quotaCountIssue(suite, account) {
|
|
87
91
|
return require_onchain_validation_checks.checkQuotaCount({
|
|
88
|
-
count:
|
|
92
|
+
count: account.quotas.filter((q) => q.value > 0n).length,
|
|
89
93
|
max: suite.creditManager.maxEnabledTokens
|
|
90
94
|
});
|
|
91
95
|
}
|
|
@@ -119,16 +123,16 @@ function borrowIssue(suite, preview, underlying) {
|
|
|
119
123
|
*
|
|
120
124
|
* {@inheritDoc quotaCountIssue}
|
|
121
125
|
*/
|
|
122
|
-
function collateralIssue(
|
|
126
|
+
function collateralIssue(account, options) {
|
|
123
127
|
const { minHealthFactor, minSafeHealthFactor, currentHealthFactor } = options;
|
|
124
|
-
if (
|
|
128
|
+
if (account.totalDebt.value === 0n) return null;
|
|
125
129
|
return (minHealthFactor === void 0 ? null : require_onchain_validation_checks.checkCollateralised({
|
|
126
|
-
healthFactor:
|
|
130
|
+
healthFactor: account.healthFactor,
|
|
127
131
|
required: minHealthFactor,
|
|
128
132
|
safePrices: false,
|
|
129
133
|
improvesFrom: currentHealthFactor
|
|
130
|
-
})) || (minSafeHealthFactor === void 0
|
|
131
|
-
healthFactor:
|
|
134
|
+
})) || (minSafeHealthFactor === void 0 ? null : require_onchain_validation_checks.checkCollateralised({
|
|
135
|
+
healthFactor: account.safeHealthFactor,
|
|
132
136
|
required: minSafeHealthFactor,
|
|
133
137
|
safePrices: true
|
|
134
138
|
}));
|
|
@@ -148,7 +152,7 @@ function fundingIssue(options, puts) {
|
|
|
148
152
|
return null;
|
|
149
153
|
}
|
|
150
154
|
function forbiddenIssue(suite, preview) {
|
|
151
|
-
const obtained = preview.operation === "AdjustCreditAccount" ? preview.assetsChange : preview.
|
|
155
|
+
const obtained = preview.operation === "AdjustCreditAccount" ? preview.assetsChange : preview.estAssets;
|
|
152
156
|
const forbidden = suite.forbiddenTokens;
|
|
153
157
|
for (const asset of obtained) {
|
|
154
158
|
if (asset.value <= 0n) continue;
|