@gearbox-protocol/sdk 16.0.0-next.26 → 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/index.js +2 -0
- package/dist/cjs/onchain/accounts/intents/index.js +2 -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/index.js +2 -0
- 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/cjs/rewards/rewards/api.js +15 -7
- package/dist/cjs/sdk/prepare/PrepareApi.js +7 -0
- package/dist/cjs/sdk/prepare/withdrawable-collaterals.js +23 -0
- package/dist/esm/model/index.js +2 -2
- package/dist/esm/model/previews.js +23 -1
- package/dist/esm/onchain/accounts/index.js +2 -1
- package/dist/esm/onchain/accounts/intents/index.js +2 -1
- 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/index.js +2 -1
- package/dist/esm/onchain/positions/PositionsService.js +79 -0
- 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/validate/checkOperation.js +13 -9
- package/dist/esm/rewards/rewards/api.js +16 -8
- package/dist/esm/sdk/prepare/PrepareApi.js +7 -0
- package/dist/esm/sdk/prepare/withdrawable-collaterals.js +22 -0
- package/dist/types/model/index.d.ts +2 -2
- package/dist/types/model/previews.d.ts +202 -76
- package/dist/types/onchain/accounts/index.d.ts +2 -1
- package/dist/types/onchain/accounts/intents/index.d.ts +2 -1
- 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/accounts/intents/utils/index.d.ts +1 -1
- package/dist/types/onchain/index.d.ts +2 -1
- 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/dist/types/rewards/rewards/api.d.ts +12 -6
- package/dist/types/rewards/rewards/merkl-api.d.ts +6 -0
- package/dist/types/sdk/prepare/PrepareApi.d.ts +5 -0
- package/dist/types/sdk/prepare/types.d.ts +18 -1
- package/dist/types/sdk/prepare/withdrawable-collaterals.d.ts +11 -0
- 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
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;
|
|
@@ -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;
|
|
@@ -37,10 +37,7 @@ async function getMerklRewards({ sdk, account, reportError, apiKey }) {
|
|
|
37
37
|
const key = `${pool}_${rewardTokenAddress}`;
|
|
38
38
|
const seen = claimable.get(key);
|
|
39
39
|
if (seen) {
|
|
40
|
-
|
|
41
|
-
...seen,
|
|
42
|
-
amount: seen.amount + amount
|
|
43
|
-
});
|
|
40
|
+
seen.value += amount;
|
|
44
41
|
continue;
|
|
45
42
|
}
|
|
46
43
|
const poolToken = sdk.tokensMeta.getToken(pool);
|
|
@@ -49,12 +46,23 @@ async function getMerklRewards({ sdk, account, reportError, apiKey }) {
|
|
|
49
46
|
chainId: sdk.chainId,
|
|
50
47
|
pool,
|
|
51
48
|
poolToken,
|
|
52
|
-
|
|
53
|
-
amount
|
|
49
|
+
token: toRewardToken(sdk, rewardTokenAddress, reward.token),
|
|
50
|
+
value: amount,
|
|
51
|
+
price: reward.token.price
|
|
54
52
|
});
|
|
55
53
|
}
|
|
56
54
|
}
|
|
57
|
-
return [...claimable.values()];
|
|
55
|
+
return [...claimable.values()].map(toReward);
|
|
56
|
+
}
|
|
57
|
+
function toReward({ price, token, value, ...rest }) {
|
|
58
|
+
return {
|
|
59
|
+
...rest,
|
|
60
|
+
amount: {
|
|
61
|
+
token,
|
|
62
|
+
value,
|
|
63
|
+
valueUsd: price === void 0 ? null : Number((0, viem.formatUnits)(value, token.decimals)) * price
|
|
64
|
+
}
|
|
65
|
+
};
|
|
58
66
|
}
|
|
59
67
|
/**
|
|
60
68
|
* A campaign's incentive token is not protocol collateral, so the registry
|
|
@@ -6,6 +6,7 @@ const require_onchain_validation_token = require("../../onchain/validation/token
|
|
|
6
6
|
const require_onchain_accounts_intents_utils_credit_account_slice = require("../../onchain/accounts/intents/utils/credit-account-slice.js");
|
|
7
7
|
const require_onchain_accounts_intents_index = require("../../onchain/accounts/intents/index.js");
|
|
8
8
|
require("../../onchain/index.js");
|
|
9
|
+
const require_sdk_prepare_withdrawable_collaterals = require("./withdrawable-collaterals.js");
|
|
9
10
|
//#region src/sdk/prepare/PrepareApi.ts
|
|
10
11
|
/**
|
|
11
12
|
* {@inheritDoc IOpportunitiesPrepare}
|
|
@@ -269,6 +270,12 @@ var PrepareApi = class extends require_onchain_base_MultichainConstruct.Multicha
|
|
|
269
270
|
});
|
|
270
271
|
}
|
|
271
272
|
/**
|
|
273
|
+
* {@inheritDoc IOpportunitiesPrepare.withdrawableCollaterals}
|
|
274
|
+
**/
|
|
275
|
+
withdrawableCollaterals(position) {
|
|
276
|
+
return require_sdk_prepare_withdrawable_collaterals.withdrawableCollaterals(this.sdk.chain(position.chainId), position);
|
|
277
|
+
}
|
|
278
|
+
/**
|
|
272
279
|
* {@inheritDoc IOpportunitiesPrepare.maxWithdrawCollateral}
|
|
273
280
|
**/
|
|
274
281
|
async maxWithdrawCollateral(position, token, targetHF) {
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
const require_onchain_accounts_intents_utils_pick_token = require("../../onchain/accounts/intents/utils/pick-token.js");
|
|
3
|
+
require("../../onchain/index.js");
|
|
4
|
+
//#region src/sdk/prepare/withdrawable-collaterals.ts
|
|
5
|
+
/**
|
|
6
|
+
* {@inheritDoc IOpportunitiesPrepare.withdrawableCollaterals}
|
|
7
|
+
**/
|
|
8
|
+
function withdrawableCollaterals(sdk, position) {
|
|
9
|
+
return position.collaterals.filter((c) => !require_onchain_accounts_intents_utils_pick_token.isPhantomToken(sdk, c.collateral.token.address)).sort(byValueThenAddress);
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Most valuable first. Address breaks a tie so the order is stable: two
|
|
13
|
+
* collaterals can share a value — a pair of unpriced ones share `null` — and a
|
|
14
|
+
* picker that seeds its default from the first row would otherwise change it
|
|
15
|
+
* between reads.
|
|
16
|
+
*/
|
|
17
|
+
function byValueThenAddress(a, b) {
|
|
18
|
+
const byValue = (b.collateral.valueUsd ?? 0) - (a.collateral.valueUsd ?? 0);
|
|
19
|
+
if (byValue !== 0) return byValue;
|
|
20
|
+
return a.collateral.token.address < b.collateral.token.address ? -1 : 1;
|
|
21
|
+
}
|
|
22
|
+
//#endregion
|
|
23
|
+
exports.withdrawableCollaterals = withdrawableCollaterals;
|
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 };
|
|
@@ -5,6 +5,7 @@ import { CreditAccountCompressorV310Contract } from "./credit-account-compressor
|
|
|
5
5
|
import { CreditAccountCompressor } from "./credit-account-compressor/CreditAccountCompressor.js";
|
|
6
6
|
import "./credit-account-compressor/index.js";
|
|
7
7
|
import { CreditAccountsServiceV310 } from "./CreditAccountsServiceV310.js";
|
|
8
|
+
import { isPhantomToken } from "./intents/utils/pick-token.js";
|
|
8
9
|
import { borrowable } from "./intents/guards.js";
|
|
9
10
|
import { fetchCreditAccountSlice, toCreditAccountSlice } from "./intents/utils/credit-account-slice.js";
|
|
10
11
|
import { calcDefaultQuota, calcQuotaUpdate, calcRecommendedQuota, roundUpQuota } from "./quota-utils.js";
|
|
@@ -26,4 +27,4 @@ import { toWithdrawalStatus } from "./withdrawal-compressor/types.js";
|
|
|
26
27
|
import { WithdrawalCompressorV313Contract } from "./withdrawal-compressor/WithdrawalCompressorV313Contract.js";
|
|
27
28
|
import { createWithdrawalCompressor } from "./withdrawal-compressor/createWithdrawalCompressor.js";
|
|
28
29
|
import "./withdrawal-compressor/index.js";
|
|
29
|
-
export { AbstractWithdrawalCompressorContract, AccountBotsService, CreditAccountCompressor, CreditAccountCompressorV310Contract, CreditAccountOperationsService, CreditAccountsServiceV310, DELAYED_INTENT_TYPES, DELAYED_INTENT_VERSION, InvalidDelayedIntentError, LIQUIDATION_APPROVAL_BUFFER, LIQUIDATION_COMPRESSOR_V313_ADDRESS, LiquidationsService, MultichainLiquidationsService, PeripheryCompressorV310Contract, RedemptionLoggerV310Contract, WithdrawalCompressorV310Contract, WithdrawalCompressorV311Contract, WithdrawalCompressorV313Contract, borrowable, calcDefaultQuota, calcQuotaUpdate, calcRecommendedQuota, createRedemptionLogger, createWithdrawalCompressor, decodeDelayedIntent, encodeDelayedIntent, fetchCreditAccountSlice, getWithdrawalCompressorAddress, iCreditAccountAbi, roundUpQuota, toClaimableWithdrawal, toCreditAccountSlice, toPendingWithdrawal, toRequestableWithdrawal, toWithdrawalStatus };
|
|
30
|
+
export { AbstractWithdrawalCompressorContract, AccountBotsService, CreditAccountCompressor, CreditAccountCompressorV310Contract, CreditAccountOperationsService, CreditAccountsServiceV310, DELAYED_INTENT_TYPES, DELAYED_INTENT_VERSION, InvalidDelayedIntentError, LIQUIDATION_APPROVAL_BUFFER, LIQUIDATION_COMPRESSOR_V313_ADDRESS, LiquidationsService, MultichainLiquidationsService, PeripheryCompressorV310Contract, RedemptionLoggerV310Contract, WithdrawalCompressorV310Contract, WithdrawalCompressorV311Contract, WithdrawalCompressorV313Contract, borrowable, calcDefaultQuota, calcQuotaUpdate, calcRecommendedQuota, createRedemptionLogger, createWithdrawalCompressor, decodeDelayedIntent, encodeDelayedIntent, fetchCreditAccountSlice, getWithdrawalCompressorAddress, iCreditAccountAbi, isPhantomToken, roundUpQuota, toClaimableWithdrawal, toCreditAccountSlice, toPendingWithdrawal, toRequestableWithdrawal, toWithdrawalStatus };
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { SDKConstruct } from "../../base/SDKConstruct.js";
|
|
2
2
|
import { MIN_HF_LIMITED } from "../../validation/checks.js";
|
|
3
3
|
import { IntentPreviewError, refuse } from "../../validation/refusal.js";
|
|
4
|
+
import { isPhantomToken } from "./utils/pick-token.js";
|
|
4
5
|
import { assertMarketOperable, borrowable } from "./guards.js";
|
|
5
6
|
import { calcLeverageBand } from "./leverage-band.js";
|
|
6
7
|
import { maxProportionalWithdrawal } from "./math.js";
|
|
@@ -314,4 +315,4 @@ function isUnroutable(e) {
|
|
|
314
315
|
return false;
|
|
315
316
|
}
|
|
316
317
|
//#endregion
|
|
317
|
-
export { CreditAccountOperationsService, borrowable, fetchCreditAccountSlice, toCreditAccountSlice };
|
|
318
|
+
export { CreditAccountOperationsService, borrowable, fetchCreditAccountSlice, isPhantomToken, toCreditAccountSlice };
|
|
@@ -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. */
|