@gearbox-protocol/sdk 16.0.0-next.27 → 16.0.0-next.28
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 +4 -18
- package/dist/cjs/onchain/accounts/intents/realize.js +77 -50
- package/dist/cjs/onchain/accounts/intents/testing/market.js +1 -0
- package/dist/cjs/onchain/accounts/intents/testing/sdk-mock.js +13 -5
- package/dist/cjs/onchain/positions/PositionsService.js +79 -0
- package/dist/cjs/preview/index.js +6 -6
- package/dist/cjs/preview/preview/{buildDelayedPreview.js → buildDelayedStrategyVerify.js} +6 -25
- 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} +3 -3
- 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 +10 -10
- package/dist/cjs/preview/validate/checkOperation.js +13 -9
- package/dist/esm/dev/AccountOpener.js +1 -1
- package/dist/esm/dev/withdrawalUtils.js +1 -1
- package/dist/esm/model/index.js +2 -2
- package/dist/esm/model/previews.js +23 -1
- package/dist/esm/onchain/accounts/CreditAccountsServiceV310.js +2 -2
- package/dist/esm/onchain/accounts/intents/open-strategy.js +4 -18
- package/dist/esm/onchain/accounts/intents/realize.js +77 -50
- package/dist/esm/onchain/accounts/intents/testing/market.js +1 -0
- package/dist/esm/onchain/accounts/intents/testing/sdk-mock.js +13 -5
- package/dist/esm/onchain/accounts/liquidations/LiquidationsService.js +1 -1
- package/dist/esm/onchain/accounts/withdrawal-compressor/RedemptionLoggerV310Contract.js +1 -1
- package/dist/esm/onchain/accounts/withdrawal-compressor/WithdrawalCompressorV310Contract.js +1 -1
- package/dist/esm/onchain/accounts/withdrawal-compressor/WithdrawalCompressorV311Contract.js +1 -1
- package/dist/esm/onchain/accounts/withdrawal-compressor/WithdrawalCompressorV313Contract.js +1 -1
- package/dist/esm/onchain/base/TokensMeta.js +3 -3
- package/dist/esm/onchain/core/createAddressProvider.js +1 -1
- package/dist/esm/onchain/market/adapters/contracts/AccountMigratorAdapterContract.js +1 -1
- package/dist/esm/onchain/market/adapters/contracts/ERC4626AdapterContract.js +1 -1
- package/dist/esm/onchain/market/credit/CreditFacadeV310BaseContract.js +1 -1
- package/dist/esm/onchain/market/pool/PoolV310Contract.js +1 -1
- package/dist/esm/onchain/market/zapper/IETHZapperContract.js +1 -1
- package/dist/esm/onchain/market/zapper/ZapperContract.js +1 -1
- package/dist/esm/onchain/positions/PositionsService.js +79 -0
- package/dist/esm/onchain/utils/viem/simulateWithPriceUpdates.js +1 -1
- package/dist/esm/preview/index.js +4 -4
- package/dist/esm/preview/preview/{buildDelayedPreview.js → buildDelayedStrategyVerify.js} +7 -26
- 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} +3 -3
- 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 +10 -10
- package/dist/esm/preview/simulate/simulatePoolOperation.js +1 -1
- package/dist/esm/preview/trace/extractTransfers.js +1 -1
- 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 +202 -76
- package/dist/types/onchain/accounts/intents/open-strategy.d.ts +1 -7
- package/dist/types/onchain/accounts/intents/testing/market.d.ts +1 -0
- package/dist/types/onchain/accounts/intents/testing/sdk-mock.d.ts +7 -0
- package/dist/types/onchain/positions/PositionsService.d.ts +30 -0
- 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
|
@@ -5,8 +5,8 @@ require("../../onchain/index.js");
|
|
|
5
5
|
const require_preview_preview_detectCloseOrRepay = require("./detectCloseOrRepay.js");
|
|
6
6
|
const require_preview_preview_replayMulticall = require("./replayMulticall.js");
|
|
7
7
|
const require_preview_preview_unwrapNativeCollateral = require("./unwrapNativeCollateral.js");
|
|
8
|
-
//#region src/preview/preview/
|
|
9
|
-
async function
|
|
8
|
+
//#region src/preview/preview/previewExitOrRepayStrategyVerify.ts
|
|
9
|
+
async function previewExitOrRepayStrategyVerify(input, operation, permanent, options) {
|
|
10
10
|
const { sdk } = input;
|
|
11
11
|
const market = sdk.marketRegister.findByCreditManager(operation.creditManager);
|
|
12
12
|
const exitTokens = [market.underlying];
|
|
@@ -63,4 +63,4 @@ function previewRepayCreditAccount(input, operation, permanent, replay) {
|
|
|
63
63
|
};
|
|
64
64
|
}
|
|
65
65
|
//#endregion
|
|
66
|
-
exports.
|
|
66
|
+
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;
|
|
@@ -2,16 +2,16 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
|
2
2
|
const require_preview_parse_parseOperationCalldata = require("../parse/parseOperationCalldata.js");
|
|
3
3
|
const require_preview_parse_types = require("../parse/types.js");
|
|
4
4
|
require("../parse/index.js");
|
|
5
|
-
const
|
|
5
|
+
const require_preview_preview_buildDelayedStrategyVerify = require("./buildDelayedStrategyVerify.js");
|
|
6
6
|
const require_preview_preview_detectCloseOrRepay = require("./detectCloseOrRepay.js");
|
|
7
7
|
const require_preview_preview_detectDelayedClaim = require("./detectDelayedClaim.js");
|
|
8
8
|
const require_preview_preview_detectDelayedOperation = require("./detectDelayedOperation.js");
|
|
9
9
|
const require_preview_preview_errors = require("./errors.js");
|
|
10
10
|
const require_preview_preview_replayMulticall = require("./replayMulticall.js");
|
|
11
|
-
const
|
|
12
|
-
const
|
|
13
|
-
const
|
|
14
|
-
const
|
|
11
|
+
const require_preview_preview_previewAdjustStrategyVerify = require("./previewAdjustStrategyVerify.js");
|
|
12
|
+
const require_preview_preview_previewExitOrRepayStrategyVerify = require("./previewExitOrRepayStrategyVerify.js");
|
|
13
|
+
const require_preview_preview_previewLpVerify = require("./previewLpVerify.js");
|
|
14
|
+
const require_preview_preview_previewOpenStrategyVerify = require("./previewOpenStrategyVerify.js");
|
|
15
15
|
//#region src/preview/preview/previewOperation.ts
|
|
16
16
|
/**
|
|
17
17
|
* Previews a raw operation calldata: decodes it into a typed operation and
|
|
@@ -19,11 +19,11 @@ const require_preview_preview_previewPoolOperation = require("./previewPoolOpera
|
|
|
19
19
|
*/
|
|
20
20
|
async function previewOperation(input, options) {
|
|
21
21
|
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
|
|
22
|
+
if (require_preview_parse_types.isPoolOperation(operation)) return require_preview_preview_previewLpVerify.previewLpVerify(input, operation, options);
|
|
23
|
+
if (operation.operation === "OpenCreditAccount" || operation.operation === "RWAOpenCreditAccount") return require_preview_preview_previewOpenStrategyVerify.previewOpenStrategyVerify(input, operation);
|
|
24
24
|
if (operation.operation === "CloseCreditAccount") {
|
|
25
25
|
const resolved = await resolveCreditAccount(input, operation, options);
|
|
26
|
-
const preview = await
|
|
26
|
+
const preview = await require_preview_preview_previewExitOrRepayStrategyVerify.previewExitOrRepayStrategyVerify(input, operation, true, resolved);
|
|
27
27
|
preview.intent = await require_preview_preview_detectDelayedClaim.resolveDelayedClaimIntent(input.sdk, operation.multicall, options?.blockNumber);
|
|
28
28
|
return preview;
|
|
29
29
|
}
|
|
@@ -53,7 +53,7 @@ async function resolveCreditAccount(input, operation, options) {
|
|
|
53
53
|
*/
|
|
54
54
|
async function previewMulticallOperation(input, operation, options) {
|
|
55
55
|
const { sdk } = input;
|
|
56
|
-
const instantPreview = require_preview_preview_detectCloseOrRepay.isCloseOrRepay(operation.multicall) ? await
|
|
56
|
+
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
57
|
const delayed = require_preview_preview_detectDelayedOperation.detectDelayedOperation(sdk, operation.multicall);
|
|
58
58
|
if (!delayed) {
|
|
59
59
|
instantPreview.intent = await require_preview_preview_detectDelayedClaim.resolveDelayedClaimIntent(sdk, operation.multicall, options?.blockNumber);
|
|
@@ -71,7 +71,7 @@ async function previewMulticallOperation(input, operation, options) {
|
|
|
71
71
|
name: sdk.marketRegister.findCreditManager(operation.creditManager).name,
|
|
72
72
|
intent: delayed.intent,
|
|
73
73
|
instantPreview,
|
|
74
|
-
delayedPreview:
|
|
74
|
+
delayedPreview: require_preview_preview_buildDelayedStrategyVerify.buildDelayedStrategyVerify(after.account, before, delayed, convert, receivedToken, sdk)
|
|
75
75
|
};
|
|
76
76
|
}
|
|
77
77
|
//#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;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { iCreditFacadeV310Abi } from "../abi/310/generated.js";
|
|
2
1
|
import { ierc20Abi } from "../abi/iERC20.js";
|
|
2
|
+
import { iCreditFacadeV310Abi } from "../abi/310/generated.js";
|
|
3
3
|
import { AddressMap } from "../onchain/utils/AddressMap.js";
|
|
4
4
|
import { AddressSet } from "../onchain/utils/AddressSet.js";
|
|
5
5
|
import { AssetsMap } from "../onchain/utils/AssetsMap.js";
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
+
import { iWithdrawalCompressorV313Abi } from "../abi/IWithdrawalCompressorV313.js";
|
|
1
2
|
import { getNetworkType } from "../onchain/chain/chains.js";
|
|
2
3
|
import { getWithdrawalCompressorAddress } from "../onchain/accounts/withdrawal-compressor/addresses.js";
|
|
3
|
-
import { iWithdrawalCompressorV313Abi } from "../abi/IWithdrawalCompressorV313.js";
|
|
4
4
|
import "../onchain/index.js";
|
|
5
5
|
import { iMidasDataFeedAbi, iMidasRedemptionVaultAbi, midasGatewayAbi, midasRedeemerAbi, midasRedemptionVaultPhantomTokenAbi, securitizeRedeemerAbi, securitizeRedemptionGatewayAbi, securitizeRedemptionPhantomTokenAbi } from "./withdrawalAbi.js";
|
|
6
6
|
import { erc20Abi, hexToString, parseAbi, parseEther } from "viem";
|
package/dist/esm/model/index.js
CHANGED
|
@@ -15,8 +15,8 @@ import { matchesOpportunityFilter, opportunityId, poolOpportunityId, strategyOpp
|
|
|
15
15
|
import { apyBreakdownSchema, opportunityBaseSchema, opportunityDetailSchema, opportunityFilterQueryParamsSchema, opportunityFilterQuerySchema, opportunityFilterSchema, opportunityKeySchema, opportunityKindSchema, opportunitySchema, opportunityTotalsSchema, pointRewardsSchema, pointsProgramSchema, poolOpportunityDetailSchema, poolOpportunityKeySchema, poolOpportunitySchema, priceFeedDataSchema, priceFeedSummarySchema, quotaAssetSchema, rateCurvePointSchema, rateCurveSchema, rewardsSchema, strategyOpportunityDetailSchema, strategyOpportunityKeySchema, strategyOpportunitySchema, tokenRewardsSchema } from "./opportunities.schema.js";
|
|
16
16
|
import { STRATEGY_POSITION_COLLATERAL_ERROR, liquidationPositionId, matchesPositionFilter, poolPositionId, positionId, strategyPositionId } from "./positions.js";
|
|
17
17
|
import { borrowRateBreakdownSchema, pnlBreakdownSchema, pointsProgramPnLSchema, pointsRewardsPnLSchema, poolPositionKeySchema, poolPositionSchema, positionCollateralSchema, positionFilterQueryParamsSchema, positionFilterQuerySchema, positionFilterSchema, positionKeySchema, positionKindSchema, positionSchema, positionTransactionKindSchema, positionTransactionSchema, positionsTotalsSchema, rewardsPnLSchema, strategyPositionKeySchema, strategyPositionSchema, tokenQuotaRateSchema, tokenRewardsPnLSchema } from "./positions.schema.js";
|
|
18
|
-
import { ERROR_ADAPTER_CALL_OUTSIDE_BRACKET, ERROR_INVALID_TRANSACTION_VALUE, ERROR_MALFORMED_BRACKET, ERROR_NON_ADAPTER_CALL_IN_BRACKET, ERROR_UNPREVIEWABLE_ADAPTER_CALL, ERROR_UNPRICEABLE_TOKEN, ERROR_UNSUPPORTED_OUT_OF_BRACKET_CALL } from "./previews.js";
|
|
18
|
+
import { ERROR_ADAPTER_CALL_OUTSIDE_BRACKET, ERROR_INVALID_TRANSACTION_VALUE, ERROR_MALFORMED_BRACKET, ERROR_NON_ADAPTER_CALL_IN_BRACKET, ERROR_UNPREVIEWABLE_ADAPTER_CALL, ERROR_UNPRICEABLE_TOKEN, ERROR_UNSUPPORTED_OUT_OF_BRACKET_CALL, asEstimated } from "./previews.js";
|
|
19
19
|
import "./primitives.js";
|
|
20
20
|
import "./response.js";
|
|
21
21
|
import { chainFailedSchema, chainMetadataSchema, chainSucceededSchema, dataSourceSchema, responseMetadataSchema, responseSchema } from "./response.schema.js";
|
|
22
|
-
export { CHART_METRIC_UNITS, CHART_RANGES, CHART_UNAVAILABLE_CODES, ERROR_ADAPTER_CALL_OUTSIDE_BRACKET, ERROR_INVALID_TRANSACTION_VALUE, ERROR_MALFORMED_BRACKET, ERROR_NON_ADAPTER_CALL_IN_BRACKET, ERROR_UNPREVIEWABLE_ADAPTER_CALL, ERROR_UNPRICEABLE_TOKEN, ERROR_UNSUPPORTED_OUT_OF_BRACKET_CALL, FILTER_ALL, POOL_OPPORTUNITY_CHART_METRICS, POOL_POSITION_CHART_METRICS, STRATEGY_OPPORTUNITY_CHART_METRICS, STRATEGY_POSITION_CHART_METRICS, STRATEGY_POSITION_COLLATERAL_ERROR, amountSchema, apyBreakdownSchema, assetTypeSchema, backendPreferred, booleanParamSchema, borrowRateBreakdownSchema, bpsSchema, chainFailedSchema, chainIdSchema, chainMetadataSchema, chainSucceededSchema, chartBundleSchemaFor, chartDenominationSchema, chartMetricSchema, chartQueryCodec, chartQueryParamsSchema, chartQuerySchema, chartRangeSchema, chartSeriesSchema, chartValueSchema, chartWindowSchema, compareTagOf, curatorNameSchema, curatorSchema, dataSourceSchema, delayedReceivedAssetSchema, encodeFlag, filterAllSchema, filterable, instantReceivedAssetSchema, isFilterSet, leverageSchema, liquidatableAccountFilterSchema, liquidatableAccountSchema, liquidationApprovalSchema, liquidationDetailsSchema, liquidationPositionId, liquidationPositionSchema, matchesLiquidatableAccountFilter, matchesOpportunityFilter, matchesPositionFilter, noticeKindSchema, noticeSchema, offchainOnly, onchainOnly, opportunityBaseSchema, opportunityDetailSchema, opportunityFilterQueryParamsSchema, opportunityFilterQuerySchema, opportunityFilterSchema, opportunityId, opportunityKeySchema, opportunityKindSchema, opportunitySchema, opportunityTotalsSchema, pnlBreakdownSchema, pointRewardsSchema, pointsProgramPnLSchema, pointsProgramSchema, pointsRewardsPnLSchema, poolOpportunityChartMetricSchema, poolOpportunityDetailSchema, poolOpportunityId, poolOpportunityKeySchema, poolOpportunitySchema, poolPositionChartMetricSchema, poolPositionId, poolPositionKeySchema, poolPositionSchema, positionCollateralSchema, positionFilterQueryParamsSchema, positionFilterQuerySchema, positionFilterSchema, positionId, positionKeySchema, positionKindSchema, positionSchema, positionTransactionKindSchema, positionTransactionSchema, positionsTotalsSchema, priceFeedDataSchema, priceFeedSummarySchema, quotaAssetSchema, rateCurvePointSchema, rateCurveSchema, receivedAssetSchema, responseMetadataSchema, responseSchema, rewardsPnLSchema, rewardsSchema, strategyOpportunityChartMetricSchema, strategyOpportunityDetailSchema, strategyOpportunityId, strategyOpportunityKeySchema, strategyOpportunitySchema, strategyPositionChartMetricSchema, strategyPositionId, strategyPositionKeySchema, strategyPositionSchema, timestampSchema, tokenAmountSchema, tokenQuotaRateSchema, tokenRewardsPnLSchema, tokenRewardsSchema, tokenSchema, tolerance, txCallSchema, underlyingTokenSchema };
|
|
22
|
+
export { CHART_METRIC_UNITS, CHART_RANGES, CHART_UNAVAILABLE_CODES, ERROR_ADAPTER_CALL_OUTSIDE_BRACKET, ERROR_INVALID_TRANSACTION_VALUE, ERROR_MALFORMED_BRACKET, ERROR_NON_ADAPTER_CALL_IN_BRACKET, ERROR_UNPREVIEWABLE_ADAPTER_CALL, ERROR_UNPRICEABLE_TOKEN, ERROR_UNSUPPORTED_OUT_OF_BRACKET_CALL, FILTER_ALL, POOL_OPPORTUNITY_CHART_METRICS, POOL_POSITION_CHART_METRICS, STRATEGY_OPPORTUNITY_CHART_METRICS, STRATEGY_POSITION_CHART_METRICS, STRATEGY_POSITION_COLLATERAL_ERROR, amountSchema, apyBreakdownSchema, asEstimated, assetTypeSchema, backendPreferred, booleanParamSchema, borrowRateBreakdownSchema, bpsSchema, chainFailedSchema, chainIdSchema, chainMetadataSchema, chainSucceededSchema, chartBundleSchemaFor, chartDenominationSchema, chartMetricSchema, chartQueryCodec, chartQueryParamsSchema, chartQuerySchema, chartRangeSchema, chartSeriesSchema, chartValueSchema, chartWindowSchema, compareTagOf, curatorNameSchema, curatorSchema, dataSourceSchema, delayedReceivedAssetSchema, encodeFlag, filterAllSchema, filterable, instantReceivedAssetSchema, isFilterSet, leverageSchema, liquidatableAccountFilterSchema, liquidatableAccountSchema, liquidationApprovalSchema, liquidationDetailsSchema, liquidationPositionId, liquidationPositionSchema, matchesLiquidatableAccountFilter, matchesOpportunityFilter, matchesPositionFilter, noticeKindSchema, noticeSchema, offchainOnly, onchainOnly, opportunityBaseSchema, opportunityDetailSchema, opportunityFilterQueryParamsSchema, opportunityFilterQuerySchema, opportunityFilterSchema, opportunityId, opportunityKeySchema, opportunityKindSchema, opportunitySchema, opportunityTotalsSchema, pnlBreakdownSchema, pointRewardsSchema, pointsProgramPnLSchema, pointsProgramSchema, pointsRewardsPnLSchema, poolOpportunityChartMetricSchema, poolOpportunityDetailSchema, poolOpportunityId, poolOpportunityKeySchema, poolOpportunitySchema, poolPositionChartMetricSchema, poolPositionId, poolPositionKeySchema, poolPositionSchema, positionCollateralSchema, positionFilterQueryParamsSchema, positionFilterQuerySchema, positionFilterSchema, positionId, positionKeySchema, positionKindSchema, positionSchema, positionTransactionKindSchema, positionTransactionSchema, positionsTotalsSchema, priceFeedDataSchema, priceFeedSummarySchema, quotaAssetSchema, rateCurvePointSchema, rateCurveSchema, receivedAssetSchema, responseMetadataSchema, responseSchema, rewardsPnLSchema, rewardsSchema, strategyOpportunityChartMetricSchema, strategyOpportunityDetailSchema, strategyOpportunityId, strategyOpportunityKeySchema, strategyOpportunitySchema, strategyPositionChartMetricSchema, strategyPositionId, strategyPositionKeySchema, strategyPositionSchema, timestampSchema, tokenAmountSchema, tokenQuotaRateSchema, tokenRewardsPnLSchema, tokenRewardsSchema, tokenSchema, tolerance, txCallSchema, underlyingTokenSchema };
|
|
@@ -32,5 +32,27 @@ const ERROR_UNSUPPORTED_OUT_OF_BRACKET_CALL = 1005;
|
|
|
32
32
|
const ERROR_INVALID_TRANSACTION_VALUE = 1006;
|
|
33
33
|
/** A token in the preview could not be priced by the oracle */
|
|
34
34
|
const ERROR_UNPRICEABLE_TOKEN = 2001;
|
|
35
|
+
/**
|
|
36
|
+
* Renames a projection's routed fields, for a caller that built one from floor
|
|
37
|
+
* balances.
|
|
38
|
+
*
|
|
39
|
+
* Lives beside the type so the two cannot drift: a field added to
|
|
40
|
+
* {@link RoutedField} fails to compile until it is renamed here too.
|
|
41
|
+
**/
|
|
42
|
+
function asEstimated(p) {
|
|
43
|
+
const { totalValue, netValue, assets, healthFactor, safeHealthFactor, borrowRate, timeToLiquidation, liquidationPrice, leverage, ...settled } = p;
|
|
44
|
+
return {
|
|
45
|
+
...settled,
|
|
46
|
+
estTotalValue: totalValue,
|
|
47
|
+
estNetValue: netValue,
|
|
48
|
+
estAssets: assets,
|
|
49
|
+
estHealthFactor: healthFactor,
|
|
50
|
+
estSafeHealthFactor: safeHealthFactor,
|
|
51
|
+
estBorrowRate: borrowRate,
|
|
52
|
+
estTimeToLiquidation: timeToLiquidation,
|
|
53
|
+
estLiquidationPrice: liquidationPrice,
|
|
54
|
+
estLeverage: leverage
|
|
55
|
+
};
|
|
56
|
+
}
|
|
35
57
|
//#endregion
|
|
36
|
-
export { ERROR_ADAPTER_CALL_OUTSIDE_BRACKET, ERROR_INVALID_TRANSACTION_VALUE, ERROR_MALFORMED_BRACKET, ERROR_NON_ADAPTER_CALL_IN_BRACKET, ERROR_UNPREVIEWABLE_ADAPTER_CALL, ERROR_UNPRICEABLE_TOKEN, ERROR_UNSUPPORTED_OUT_OF_BRACKET_CALL };
|
|
58
|
+
export { ERROR_ADAPTER_CALL_OUTSIDE_BRACKET, ERROR_INVALID_TRANSACTION_VALUE, ERROR_MALFORMED_BRACKET, ERROR_NON_ADAPTER_CALL_IN_BRACKET, ERROR_UNPREVIEWABLE_ADAPTER_CALL, ERROR_UNPRICEABLE_TOKEN, ERROR_UNSUPPORTED_OUT_OF_BRACKET_CALL, asEstimated };
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { iBaseRewardPoolAbi } from "../../abi/iBaseRewardPool.js";
|
|
2
|
+
import { ierc4626AdapterAbi } from "../../abi/ierc4626Adapter.js";
|
|
1
3
|
import { AP_REWARDS_COMPRESSOR } from "../constants/address-provider.js";
|
|
2
4
|
import { ADDRESS_0X0 } from "../constants/addresses.js";
|
|
3
5
|
import { MAX_UINT256 } from "../constants/math.js";
|
|
@@ -8,8 +10,6 @@ import "../base/index.js";
|
|
|
8
10
|
import { AccountBotsService } from "./bots/AccountBotsService.js";
|
|
9
11
|
import "./bots/index.js";
|
|
10
12
|
import { rewardsCompressorAbi } from "../../abi/compressors/rewardsCompressor.js";
|
|
11
|
-
import { iBaseRewardPoolAbi } from "../../abi/iBaseRewardPool.js";
|
|
12
|
-
import { ierc4626AdapterAbi } from "../../abi/ierc4626Adapter.js";
|
|
13
13
|
import { expectedBalanceDeltas } from "../market/credit/expectedBalanceDeltas.js";
|
|
14
14
|
import "../market/index.js";
|
|
15
15
|
import { CreditAccountCompressor } from "./credit-account-compressor/CreditAccountCompressor.js";
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { calcPositionLeverage } from "../../market/math.js";
|
|
2
1
|
import { IntentPreviewError } from "../../validation/refusal.js";
|
|
3
2
|
import { assertCanBorrow, assertCollateralised, assertGrowthAllowed, assertMarketOperable, assertQuotaHeadroom } from "./guards.js";
|
|
4
3
|
import { assertDebtInBand, assertLeverageAtLeastOne, debtForLeverage } from "./math.js";
|
|
@@ -85,34 +84,21 @@ async function previewOpenStrategy(props) {
|
|
|
85
84
|
totalDebt: debt,
|
|
86
85
|
totalValue: margin + debt
|
|
87
86
|
};
|
|
88
|
-
const
|
|
89
|
-
|
|
90
|
-
healthFactor: sdk.positions.healthFactor(snapshot),
|
|
91
|
-
safeHealthFactor: sdk.positions.healthFactor(snapshot, { safePrices: true }),
|
|
92
|
-
borrowRate: sdk.positions.borrowRate(snapshot, projectedPool),
|
|
93
|
-
timeToLiquidation: sdk.positions.timeToLiquidation(snapshot, projectedPool),
|
|
94
|
-
liquidationPrice: sdk.positions.liquidationPrice(snapshot)
|
|
95
|
-
};
|
|
96
|
-
assertCollateralised(metrics.healthFactor, false);
|
|
87
|
+
const { assets: _assets, quotas: _quotas, ...projection } = sdk.positions.projection(snapshot, { availableLiquidityChange: -debt });
|
|
88
|
+
assertCollateralised(projection.healthFactor, false);
|
|
97
89
|
const priceImpact = await collectPriceImpact(leg.probe ? [leg.probe] : [], {
|
|
98
90
|
totalValue: margin + debt,
|
|
99
91
|
netValue: margin,
|
|
100
92
|
toUnderlying: (from, amount) => convert(from, underlying, amount)
|
|
101
93
|
});
|
|
102
94
|
return {
|
|
103
|
-
|
|
104
|
-
name: suite.name,
|
|
105
|
-
totalDebt: market.toUnderlyingAmount(debt),
|
|
106
|
-
netValue: market.toUnderlyingAmount(margin),
|
|
107
|
-
totalValue: market.toUnderlyingAmount(margin + debt),
|
|
108
|
-
leverage: calcPositionLeverage(margin + debt, debt),
|
|
95
|
+
...projection,
|
|
109
96
|
priceImpact,
|
|
110
97
|
averageAssets: averageAssets.map(priced),
|
|
111
98
|
minAssets: minAssets.map(priced),
|
|
112
99
|
averageQuota,
|
|
113
100
|
minQuota,
|
|
114
|
-
calls: [...leg.calls]
|
|
115
|
-
...metrics
|
|
101
|
+
calls: [...leg.calls]
|
|
116
102
|
};
|
|
117
103
|
}
|
|
118
104
|
/** Collateral plus the borrowed underlying, folded into one balance per token. */
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { calcPositionLeverage } from "../../market/math.js";
|
|
2
1
|
import { IntentPreviewError } from "../../validation/refusal.js";
|
|
3
2
|
import { toToken, toTokenAmount } from "../../validation/token.js";
|
|
4
3
|
import { eq, toTargetDecimals } from "./utils/common.js";
|
|
@@ -32,16 +31,36 @@ async function realize(steps, props) {
|
|
|
32
31
|
const market = sdk.marketRegister.findByCreditManager(creditAccount.creditManager);
|
|
33
32
|
const price = (from, to, amount) => market.priceOracle.safeConvert(from, to, amount) ?? 0n;
|
|
34
33
|
const suite = sdk.marketRegister.findCreditManager(creditAccount.creditManager);
|
|
35
|
-
const
|
|
34
|
+
const start = {
|
|
36
35
|
initialAssets: creditAccount.tokens,
|
|
37
36
|
underlying,
|
|
38
37
|
debt: creditAccount.totalDebt,
|
|
39
38
|
convert: price
|
|
40
|
-
}
|
|
39
|
+
};
|
|
40
|
+
/**
|
|
41
|
+
* The floor: every routed leg counted at the amount it guarantees. This is
|
|
42
|
+
* what the calls are built from — a repayment may only spend underlying the
|
|
43
|
+
* route promises to have raised — and what the guards are answered on, since
|
|
44
|
+
* a floor that does not clear the facade's bar is a transaction that can
|
|
45
|
+
* revert.
|
|
46
|
+
*/
|
|
47
|
+
const ledger = new OperationLedger(start);
|
|
48
|
+
/**
|
|
49
|
+
* The same walk with every routed leg counted at the amount the pathfinder
|
|
50
|
+
* expects to return. Nothing is built from it: it is where the position
|
|
51
|
+
* actually lands, so it is what the reported state is read off.
|
|
52
|
+
*/
|
|
53
|
+
const expected = new OperationLedger(start);
|
|
41
54
|
const operations = [];
|
|
42
|
-
|
|
55
|
+
/**
|
|
56
|
+
* @param asExpected - The operation as the expected branch sees it, for the
|
|
57
|
+
* legs where the two differ. Defaults to the operation itself, which is the
|
|
58
|
+
* case for everything whose amount the calldata fixes.
|
|
59
|
+
*/
|
|
60
|
+
const push = (op, asExpected = op) => {
|
|
43
61
|
operations.push(op);
|
|
44
62
|
ledger.apply(op);
|
|
63
|
+
expected.apply(asExpected);
|
|
45
64
|
};
|
|
46
65
|
/** One per routed leg, each already awaiting its quote; folded after the guards. */
|
|
47
66
|
const probes = [];
|
|
@@ -137,13 +156,17 @@ async function realize(steps, props) {
|
|
|
137
156
|
keep: held - amount
|
|
138
157
|
});
|
|
139
158
|
if (leg.probe) probes.push(leg.probe);
|
|
140
|
-
|
|
159
|
+
const swap = buildSwapOperation({
|
|
141
160
|
tokenIn: step.from,
|
|
142
161
|
amountIn: amount,
|
|
143
162
|
tokenOut: step.to,
|
|
144
163
|
amountOut: leg.minAmount,
|
|
145
164
|
calls: leg.calls
|
|
146
|
-
})
|
|
165
|
+
});
|
|
166
|
+
push(swap, {
|
|
167
|
+
...swap,
|
|
168
|
+
amountOut: leg.amount
|
|
169
|
+
});
|
|
147
170
|
raised = leg.minAmount;
|
|
148
171
|
break;
|
|
149
172
|
}
|
|
@@ -154,12 +177,22 @@ async function realize(steps, props) {
|
|
|
154
177
|
if (balances.length > 0) {
|
|
155
178
|
const leg = await paths.closeAll({ balances });
|
|
156
179
|
if (leg.probe) probes.push(leg.probe);
|
|
157
|
-
if (leg.calls.length > 0 || leg.minAmount > 0n)
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
180
|
+
if (leg.calls.length > 0 || leg.minAmount > 0n) {
|
|
181
|
+
const sale = buildCloseSwapOperation({
|
|
182
|
+
from: balances,
|
|
183
|
+
tokenOut: underlying,
|
|
184
|
+
amountOut: leg.minAmount,
|
|
185
|
+
calls: leg.calls
|
|
186
|
+
});
|
|
187
|
+
push(sale, {
|
|
188
|
+
...sale,
|
|
189
|
+
from: balances.map((a) => ({
|
|
190
|
+
token: a.token,
|
|
191
|
+
balance: expected.balanceOf(a.token)
|
|
192
|
+
})),
|
|
193
|
+
amountOut: leg.amount
|
|
194
|
+
});
|
|
195
|
+
}
|
|
163
196
|
}
|
|
164
197
|
raised = ledger.balanceOf(underlying);
|
|
165
198
|
break;
|
|
@@ -225,24 +258,32 @@ async function realize(steps, props) {
|
|
|
225
258
|
creditAccount,
|
|
226
259
|
sdk
|
|
227
260
|
}));
|
|
228
|
-
for (const { token, balance } of ledger.snapshot().assets)
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
261
|
+
for (const { token, balance } of ledger.snapshot().assets) {
|
|
262
|
+
const payout = buildWithdrawCollateralOperation({
|
|
263
|
+
token,
|
|
264
|
+
amount: balance,
|
|
265
|
+
to: step.to,
|
|
266
|
+
all: true,
|
|
267
|
+
creditAccount,
|
|
268
|
+
sdk
|
|
269
|
+
});
|
|
270
|
+
push(payout, {
|
|
271
|
+
...payout,
|
|
272
|
+
amount: expected.balanceOf(token)
|
|
273
|
+
});
|
|
274
|
+
}
|
|
236
275
|
break;
|
|
237
276
|
}
|
|
238
277
|
}
|
|
239
|
-
const
|
|
278
|
+
const floor = ledger.snapshot();
|
|
279
|
+
const { assets, debt } = floor;
|
|
280
|
+
const projected = expected.snapshot();
|
|
240
281
|
assertGrowthAllowed({
|
|
241
282
|
sdk,
|
|
242
283
|
suite,
|
|
243
284
|
market,
|
|
244
285
|
before: creditAccount.tokens,
|
|
245
|
-
after: assets
|
|
286
|
+
after: projected.assets
|
|
246
287
|
});
|
|
247
288
|
const quotas = cleared ?? getQuotasForUpdate({
|
|
248
289
|
assetsBefore: creditAccount.tokens,
|
|
@@ -264,42 +305,28 @@ async function realize(steps, props) {
|
|
|
264
305
|
}));
|
|
265
306
|
}
|
|
266
307
|
const quotasAfter = quotasAfterUpdate(creditAccount.tokens, quotas.desiredQuota);
|
|
308
|
+
const quoted = Object.values(quotasAfter);
|
|
267
309
|
const snapshot = {
|
|
268
310
|
creditManager: creditAccount.creditManager,
|
|
269
|
-
assets,
|
|
270
|
-
quotas:
|
|
311
|
+
assets: projected.assets,
|
|
312
|
+
quotas: quoted,
|
|
271
313
|
totalDebt: debt,
|
|
272
|
-
totalValue
|
|
273
|
-
};
|
|
274
|
-
const projectedPool = { availableLiquidityChange: creditAccount.totalDebt - debt };
|
|
275
|
-
const metrics = {
|
|
276
|
-
healthFactor: sdk.positions.healthFactor(snapshot),
|
|
277
|
-
safeHealthFactor: paysOut ? sdk.positions.healthFactor(snapshot, { safePrices: true }) : void 0,
|
|
278
|
-
borrowRate: sdk.positions.borrowRate(snapshot, projectedPool),
|
|
279
|
-
timeToLiquidation: sdk.positions.timeToLiquidation(snapshot, projectedPool),
|
|
280
|
-
liquidationPrice: sdk.positions.liquidationPrice(snapshot)
|
|
314
|
+
totalValue: projected.totalValue
|
|
281
315
|
};
|
|
282
|
-
|
|
316
|
+
const projection = sdk.positions.projection(snapshot, { availableLiquidityChange: creditAccount.totalDebt - debt });
|
|
317
|
+
assertCollateralised(sdk.positions.healthFactor({
|
|
318
|
+
...snapshot,
|
|
319
|
+
assets,
|
|
320
|
+
totalValue: floor.totalValue
|
|
321
|
+
}, { safePrices: paysOut }), paysOut);
|
|
283
322
|
const priceImpact = await collectPriceImpact(probes, {
|
|
284
|
-
totalValue,
|
|
285
|
-
netValue: totalValue - debt,
|
|
323
|
+
totalValue: projected.totalValue,
|
|
324
|
+
netValue: projected.totalValue - debt,
|
|
286
325
|
toUnderlying: (from, amount) => price(from, underlying, amount)
|
|
287
326
|
});
|
|
288
|
-
const oracle = market.priceOracle;
|
|
289
327
|
const state = {
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
totalValue: market.toUnderlyingAmount(totalValue),
|
|
293
|
-
totalDebt: market.toUnderlyingAmount(debt),
|
|
294
|
-
netValue: market.toUnderlyingAmount(totalValue - debt),
|
|
295
|
-
leverage: calcPositionLeverage(totalValue, debt),
|
|
296
|
-
assets: assets.map((a) => oracle.toTokenAmount(a.token, a.balance)),
|
|
297
|
-
quotas: Object.values(quotasAfter).map((q) => ({
|
|
298
|
-
token: sdk.tokensMeta.mustGetToken(q.token),
|
|
299
|
-
...oracle.toAmount(underlying, q.balance)
|
|
300
|
-
})),
|
|
301
|
-
priceImpact,
|
|
302
|
-
...metrics
|
|
328
|
+
...projection,
|
|
329
|
+
priceImpact
|
|
303
330
|
};
|
|
304
331
|
return {
|
|
305
332
|
operations,
|
|
@@ -96,6 +96,7 @@ function buildMarketSdk(extras) {
|
|
|
96
96
|
creditFacade: CREDIT_FACADE,
|
|
97
97
|
underlying: UND,
|
|
98
98
|
routeQuote: extras?.routeQuote,
|
|
99
|
+
routeFloor: extras?.routeFloor,
|
|
99
100
|
rwaAssets: extras?.rwaAssets,
|
|
100
101
|
phantoms: extras?.phantoms,
|
|
101
102
|
creditAccounts: extras?.creditAccounts,
|
|
@@ -155,6 +155,8 @@ function buildMockSdk(args) {
|
|
|
155
155
|
};
|
|
156
156
|
const market = {
|
|
157
157
|
toUnderlyingAmount,
|
|
158
|
+
/** {@inheritDoc MarketSuite.underlying} */
|
|
159
|
+
underlying: args.underlying,
|
|
158
160
|
priceOracle: {
|
|
159
161
|
convert,
|
|
160
162
|
safeConvert,
|
|
@@ -238,10 +240,12 @@ function buildMockSdk(args) {
|
|
|
238
240
|
};
|
|
239
241
|
/** Linear unless the case says otherwise — see `routeQuote`. */
|
|
240
242
|
const quote = args.routeQuote ?? ((amount) => amount);
|
|
243
|
+
/** Slippage-free unless the case says otherwise — see `routeFloor`. */
|
|
244
|
+
const floor = args.routeFloor ?? ((amount) => amount);
|
|
241
245
|
const router = {
|
|
242
246
|
findOneTokenPath: vi.fn(async ({ amount, tokenIn, tokenOut }) => ({
|
|
243
247
|
amount: quote(amount),
|
|
244
|
-
minAmount: quote(amount),
|
|
248
|
+
minAmount: floor(quote(amount)),
|
|
245
249
|
calls: routeCalls(tokenIn, tokenOut)
|
|
246
250
|
})),
|
|
247
251
|
findManyToOnePath: vi.fn(async ({ expectedBalances, leftoverBalances, target }) => {
|
|
@@ -249,7 +253,7 @@ function buildMockSdk(args) {
|
|
|
249
253
|
const tokenIn = expectedBalances[0]?.token ?? target;
|
|
250
254
|
return {
|
|
251
255
|
amount: quote(spent),
|
|
252
|
-
minAmount: quote(spent),
|
|
256
|
+
minAmount: floor(quote(spent)),
|
|
253
257
|
calls: routeCalls(tokenIn, target)
|
|
254
258
|
};
|
|
255
259
|
}),
|
|
@@ -270,11 +274,15 @@ function buildMockSdk(args) {
|
|
|
270
274
|
amount += convert(token, targetLc, spend);
|
|
271
275
|
}
|
|
272
276
|
balances[targetLc] = (balances[targetLc] ?? 0n) + amount;
|
|
277
|
+
const untouched = (balances[targetLc] ?? 0n) - amount;
|
|
273
278
|
return {
|
|
274
279
|
amount,
|
|
275
|
-
minAmount: amount,
|
|
280
|
+
minAmount: floor(amount),
|
|
276
281
|
balances,
|
|
277
|
-
minBalances: {
|
|
282
|
+
minBalances: {
|
|
283
|
+
...balances,
|
|
284
|
+
[targetLc]: untouched + floor(amount)
|
|
285
|
+
},
|
|
278
286
|
calls: [MOCK_ROUTER_CALL]
|
|
279
287
|
};
|
|
280
288
|
}),
|
|
@@ -284,7 +292,7 @@ function buildMockSdk(args) {
|
|
|
284
292
|
const amount = sold.reduce((acc, a) => acc + convert(a.token, underlying, a.balance), 0n);
|
|
285
293
|
return {
|
|
286
294
|
amount,
|
|
287
|
-
minAmount: amount,
|
|
295
|
+
minAmount: floor(amount),
|
|
288
296
|
underlyingBalance: amount,
|
|
289
297
|
calls: sold.length === 0 ? [] : [MOCK_CLOSE_CALL]
|
|
290
298
|
};
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { iLiquidationCompressorV313Abi } from "../../../abi/ILiquidationCompressorV313.js";
|
|
1
2
|
import { AddressSet } from "../../utils/AddressSet.js";
|
|
2
3
|
import { bytes32ToString } from "../../utils/bytes32ToString.js";
|
|
3
4
|
import { ADDRESS_0X0 } from "../../constants/addresses.js";
|
|
@@ -19,7 +20,6 @@ import { SecuritizeLiquidatorContract } from "../../market/rwa/securitize/Securi
|
|
|
19
20
|
import "../../market/rwa/securitize/index.js";
|
|
20
21
|
import "../../market/index.js";
|
|
21
22
|
import { LIQUIDATION_APPROVAL_BUFFER, LIQUIDATION_COMPRESSOR_V313_ADDRESS } from "./constants.js";
|
|
22
|
-
import { iLiquidationCompressorV313Abi } from "../../../abi/ILiquidationCompressorV313.js";
|
|
23
23
|
//#region src/onchain/accounts/liquidations/LiquidationsService.ts
|
|
24
24
|
/**
|
|
25
25
|
* Service for discovering liquidatable credit accounts and previewing manual
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
+
import { iRedemptionLoggerV310Abi } from "../../../abi/iRedemptionLoggerV310.js";
|
|
1
2
|
import { BaseContract } from "../../base/BaseContract.js";
|
|
2
3
|
import "../../base/index.js";
|
|
3
4
|
import { decodeDelayedIntent } from "./intent-codec.js";
|
|
4
|
-
import { iRedemptionLoggerV310Abi } from "../../../abi/iRedemptionLoggerV310.js";
|
|
5
5
|
import { InvalidDelayedIntentError } from "./errors.js";
|
|
6
6
|
//#region src/onchain/accounts/withdrawal-compressor/RedemptionLoggerV310Contract.ts
|
|
7
7
|
const abi = iRedemptionLoggerV310Abi;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { AbstractWithdrawalCompressorContract } from "./AbstractWithdrawalCompressorContract.js";
|
|
2
1
|
import { iWithdrawalCompressorV310Abi } from "../../../abi/IWithdrawalCompressorV310.js";
|
|
2
|
+
import { AbstractWithdrawalCompressorContract } from "./AbstractWithdrawalCompressorContract.js";
|
|
3
3
|
//#region src/onchain/accounts/withdrawal-compressor/WithdrawalCompressorV310Contract.ts
|
|
4
4
|
const abi = iWithdrawalCompressorV310Abi;
|
|
5
5
|
/**
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { AbstractWithdrawalCompressorContract } from "./AbstractWithdrawalCompressorContract.js";
|
|
2
1
|
import { iWithdrawalCompressorV311Abi } from "../../../abi/IWithdrawalCompressorV311.js";
|
|
2
|
+
import { AbstractWithdrawalCompressorContract } from "./AbstractWithdrawalCompressorContract.js";
|
|
3
3
|
//#region src/onchain/accounts/withdrawal-compressor/WithdrawalCompressorV311Contract.ts
|
|
4
4
|
const abi = iWithdrawalCompressorV311Abi;
|
|
5
5
|
/**
|