@gearbox-protocol/sdk 17.10.1-next.1 → 17.10.1-next.3
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/onchain/accounts/intents/index.js +4 -5
- package/dist/cjs/onchain/accounts/intents/leverage-band.js +49 -8
- package/dist/cjs/onchain/accounts/intents/tail.js +1 -1
- package/dist/cjs/onchain/accounts/intents/withdraw-limits.js +1 -1
- package/dist/cjs/onchain/validation/checks/checkCollateralised.js +3 -1
- package/dist/cjs/sdk/prepare/PrepareApi.js +3 -2
- package/dist/esm/dev/AccountOpener.js +1 -1
- package/dist/esm/dev/withdrawalUtils.js +1 -1
- package/dist/esm/history/trace/extractTransfers.js +1 -1
- package/dist/esm/onchain/accounts/CreditAccountsServiceV310.js +2 -2
- package/dist/esm/onchain/accounts/intents/index.js +4 -5
- package/dist/esm/onchain/accounts/intents/leverage-band.js +50 -9
- package/dist/esm/onchain/accounts/intents/tail.js +1 -1
- package/dist/esm/onchain/accounts/intents/withdraw-limits.js +1 -1
- 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/rwa/createDegenNFT.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/preview/preview/previewPoolPositionOperation.js +2 -2
- package/dist/esm/onchain/utils/viem/simulateWithPriceUpdates.js +1 -1
- package/dist/esm/onchain/validation/checks/checkCollateralised.js +3 -1
- package/dist/esm/sdk/prepare/PrepareApi.js +3 -2
- package/dist/types/onchain/accounts/intents/index.d.ts +2 -3
- package/dist/types/onchain/accounts/intents/leverage-band.d.ts +8 -6
- package/dist/types/sdk/prepare/PrepareApi.d.ts +1 -1
- package/dist/types/sdk/prepare/types.d.ts +3 -4
- package/package.json +1 -1
|
@@ -11,13 +11,13 @@ const require_onchain_accounts_intents_utils_pick_token = require("./utils/pick-
|
|
|
11
11
|
const require_onchain_accounts_intents_guards = require("./guards.js");
|
|
12
12
|
const require_onchain_accounts_intents_utils_credit_account_slice = require("./utils/credit-account-slice.js");
|
|
13
13
|
const require_onchain_accounts_intents_borrow = require("./borrow.js");
|
|
14
|
+
const require_onchain_accounts_intents_strategyLimits = require("./strategyLimits.js");
|
|
15
|
+
const require_onchain_accounts_intents_view = require("./view.js");
|
|
14
16
|
const require_onchain_accounts_intents_leverage_band = require("./leverage-band.js");
|
|
15
17
|
const require_onchain_accounts_intents_maxBorrow = require("./maxBorrow.js");
|
|
16
18
|
const require_onchain_accounts_intents_maxWithdrawCollateral = require("./maxWithdrawCollateral.js");
|
|
17
|
-
const require_onchain_accounts_intents_strategyLimits = require("./strategyLimits.js");
|
|
18
19
|
const require_onchain_accounts_intents_open_strategy = require("./open-strategy.js");
|
|
19
20
|
const require_onchain_accounts_intents_plan = require("./plan.js");
|
|
20
|
-
const require_onchain_accounts_intents_view = require("./view.js");
|
|
21
21
|
const require_onchain_accounts_intents_withdraw_limits = require("./withdraw-limits.js");
|
|
22
22
|
const require_onchain_accounts_intents_realize = require("./realize.js");
|
|
23
23
|
const require_onchain_accounts_intents_tail = require("./tail.js");
|
|
@@ -124,9 +124,8 @@ var CreditAccountOperationsService = class extends require_onchain_base_SDKConst
|
|
|
124
124
|
* given deposit reaches is decided by the debt it implies and by the
|
|
125
125
|
* `debtLimits` the market puts that debt in — the range a leverage slider should offer.
|
|
126
126
|
*
|
|
127
|
-
*
|
|
128
|
-
*
|
|
129
|
-
* holds. Nothing is fetched, so a form can ask on every keystroke.
|
|
127
|
+
* Nothing is fetched: opening uses the supplied collateral, while adjust
|
|
128
|
+
* uses a supplied account slice, so a form can ask on every keystroke.
|
|
130
129
|
*
|
|
131
130
|
* @param props - The manager, the SDK holding its market, what stands
|
|
132
131
|
* behind the position, and optionally the health factor the ceiling should
|
|
@@ -2,6 +2,8 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
|
2
2
|
const require_onchain_utils_bigint_math = require("../../utils/bigint-math.js");
|
|
3
3
|
const require_onchain_constants_math = require("../../constants/math.js");
|
|
4
4
|
const require_onchain_accounts_intents_utils_common = require("./utils/common.js");
|
|
5
|
+
const require_onchain_accounts_intents_strategyLimits = require("./strategyLimits.js");
|
|
6
|
+
const require_onchain_accounts_intents_view = require("./view.js");
|
|
5
7
|
//#region src/onchain/accounts/intents/leverage-band.ts
|
|
6
8
|
/**
|
|
7
9
|
* The leverages this market will actually fund for a position of this size.
|
|
@@ -16,8 +18,8 @@ const require_onchain_accounts_intents_utils_common = require("./utils/common.js
|
|
|
16
18
|
* rounds **up** so the leverage it names really does clear `minDebt`, and the
|
|
17
19
|
* ceiling rounds **down** so it really does stay under the borrow limit.
|
|
18
20
|
*
|
|
19
|
-
* Nothing here is fetched or simulated —
|
|
20
|
-
* so a form can call this on each keystroke.
|
|
21
|
+
* Nothing here is fetched or simulated — adjust state comes from the supplied
|
|
22
|
+
* position and the attached market, so a form can call this on each keystroke.
|
|
21
23
|
*
|
|
22
24
|
* @param props - {@link LeverageBandProps}
|
|
23
25
|
* @returns The band, or `undefined` when there is nothing to offer: an
|
|
@@ -30,13 +32,53 @@ const require_onchain_accounts_intents_utils_common = require("./utils/common.js
|
|
|
30
32
|
* calcLeverageBand({ sdk, creditManager, collateral }) // { min: 1.1, max: 9 }
|
|
31
33
|
* ```
|
|
32
34
|
**/
|
|
33
|
-
function calcLeverageBand({ sdk, creditManager, collateral, targetHF }) {
|
|
35
|
+
function calcLeverageBand({ sdk, creditManager, collateral, targetHF, position }) {
|
|
34
36
|
const found = require_onchain_accounts_intents_utils_common.resolveCreditManager(sdk, creditManager);
|
|
35
37
|
if (!found) return;
|
|
36
38
|
const { suite, market } = found;
|
|
37
|
-
const
|
|
38
|
-
if (!
|
|
39
|
+
const strategy = suite.strategy;
|
|
40
|
+
if (!strategy) return;
|
|
41
|
+
const target = strategy.targetCollateral;
|
|
39
42
|
const ceiling = suite.creditManager.maxLeverage(target, targetHF);
|
|
43
|
+
if (position) {
|
|
44
|
+
if (!require_onchain_accounts_intents_utils_common.eq(position.creditManager, creditManager)) throw new Error("credit account belongs to a different credit manager");
|
|
45
|
+
const creditAccount = {
|
|
46
|
+
creditAccount: position.creditAccount,
|
|
47
|
+
creditManager: position.creditManager,
|
|
48
|
+
creditFacade: suite.creditFacade.address,
|
|
49
|
+
underlying: position.underlyingToken.address,
|
|
50
|
+
enabledTokensMask: 0n,
|
|
51
|
+
totalDebtUSD: 0n,
|
|
52
|
+
totalDebt: position.totalDebt.value,
|
|
53
|
+
tokens: position.collaterals.map(({ collateral, quota }) => ({
|
|
54
|
+
token: collateral.token.address,
|
|
55
|
+
mask: 0n,
|
|
56
|
+
balance: collateral.value,
|
|
57
|
+
quota: quota.value,
|
|
58
|
+
success: true
|
|
59
|
+
}))
|
|
60
|
+
};
|
|
61
|
+
const view = {
|
|
62
|
+
...require_onchain_accounts_intents_view.accountView(creditAccount, sdk),
|
|
63
|
+
collateral: position.totalValue.value - position.totalDebt.value
|
|
64
|
+
};
|
|
65
|
+
const { leverageLimits, quotaLimits } = require_onchain_accounts_intents_strategyLimits.strategyLimits({
|
|
66
|
+
type: "ADJUST_LEVERAGE",
|
|
67
|
+
suite,
|
|
68
|
+
view,
|
|
69
|
+
initialQuotas: creditAccount.tokens,
|
|
70
|
+
token: target,
|
|
71
|
+
targetLeverage: require_onchain_constants_math.LEVERAGE_DECIMALS,
|
|
72
|
+
quotaReserve: void 0
|
|
73
|
+
});
|
|
74
|
+
if (!leverageLimits) return void 0;
|
|
75
|
+
const min = Number(leverageLimits.min) / Number(require_onchain_constants_math.LEVERAGE_DECIMALS);
|
|
76
|
+
const max = Math.min(ceiling, Number(require_onchain_utils_bigint_math.BigIntMath.min(leverageLimits.max, quotaLimits?.leverageMax ?? leverageLimits.max)) / Number(require_onchain_constants_math.LEVERAGE_DECIMALS));
|
|
77
|
+
return min > max ? void 0 : {
|
|
78
|
+
min,
|
|
79
|
+
max
|
|
80
|
+
};
|
|
81
|
+
}
|
|
40
82
|
const underlying = market.pool.underlying;
|
|
41
83
|
const convert = (from, to, amount) => market.priceOracle.safeConvert(from, to, amount).value;
|
|
42
84
|
const netValue = collateral.reduce((acc, a) => acc + convert(a.token, underlying, a.balance), 0n);
|
|
@@ -44,9 +86,8 @@ function calcLeverageBand({ sdk, creditManager, collateral, targetHF }) {
|
|
|
44
86
|
min: 1,
|
|
45
87
|
max: ceiling
|
|
46
88
|
};
|
|
47
|
-
const { minDebt
|
|
48
|
-
const
|
|
49
|
-
const borrowLimit = available === void 0 ? maxDebt : require_onchain_utils_bigint_math.BigIntMath.min(maxDebt, available);
|
|
89
|
+
const { minDebt } = suite.creditFacade;
|
|
90
|
+
const borrowLimit = strategy.maxBorrowAmount().amount.value;
|
|
50
91
|
const floor = require_onchain_utils_bigint_math.BigIntMath.ceilDiv(require_onchain_constants_math.LEVERAGE_DECIMALS * minDebt, netValue);
|
|
51
92
|
const roof = require_onchain_utils_bigint_math.BigIntMath.ceilDiv(require_onchain_constants_math.LEVERAGE_DECIMALS * (borrowLimit + 1n), netValue) - 1n;
|
|
52
93
|
const min = 1 + Number(floor) / Number(require_onchain_constants_math.LEVERAGE_DECIMALS);
|
|
@@ -6,9 +6,9 @@ const require_onchain_validation_helpers_token = require("../../validation/helpe
|
|
|
6
6
|
const require_onchain_validation_raise = require("../../validation/raise.js");
|
|
7
7
|
const require_onchain_accounts_intents_utils_common = require("./utils/common.js");
|
|
8
8
|
const require_onchain_accounts_intents_utils_router_path = require("./utils/router-path.js");
|
|
9
|
+
const require_onchain_accounts_intents_view = require("./view.js");
|
|
9
10
|
const require_onchain_accounts_intents_plan = require("./plan.js");
|
|
10
11
|
const require_onchain_accounts_intents_operations = require("./operations.js");
|
|
11
|
-
const require_onchain_accounts_intents_view = require("./view.js");
|
|
12
12
|
const require_onchain_accounts_intents_realize = require("./realize.js");
|
|
13
13
|
//#region src/onchain/accounts/intents/tail.ts
|
|
14
14
|
/**
|
|
@@ -5,8 +5,8 @@ require("../../validation/helpers/health-factor-limits.js");
|
|
|
5
5
|
require("../../validation/index.js");
|
|
6
6
|
const require_onchain_accounts_intents_utils_common = require("./utils/common.js");
|
|
7
7
|
const require_onchain_accounts_intents_math = require("./math.js");
|
|
8
|
-
const require_onchain_accounts_intents_collateral_valuation = require("./collateral-valuation.js");
|
|
9
8
|
const require_onchain_accounts_intents_view = require("./view.js");
|
|
9
|
+
const require_onchain_accounts_intents_collateral_valuation = require("./collateral-valuation.js");
|
|
10
10
|
//#region src/onchain/accounts/intents/withdraw-limits.ts
|
|
11
11
|
/**
|
|
12
12
|
* Every limit a `WITHDRAW` answers to, in underlying units.
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
2
|
const require_model_errors_operation_errors = require("../../../model/errors/operation-errors.js");
|
|
3
3
|
require("../../../model/index.js");
|
|
4
|
+
require("../helpers/health-factor-limits.js");
|
|
5
|
+
require("../helpers/index.js");
|
|
4
6
|
//#region src/onchain/validation/checks/checkCollateralised.ts
|
|
5
7
|
/**
|
|
6
8
|
* The account against its debt, at whichever threshold the caller holds it to.
|
|
@@ -15,7 +17,7 @@ function checkCollateralised(args) {
|
|
|
15
17
|
healthFactorThreshold,
|
|
16
18
|
safePrices
|
|
17
19
|
})];
|
|
18
|
-
if (healthFactor >= healthFactorThreshold || improvesFrom !== void 0 && healthFactor > improvesFrom) return [];
|
|
20
|
+
if (healthFactor >= healthFactorThreshold || improvesFrom !== void 0 && healthFactor >= 1e4 && healthFactor > improvesFrom) return [];
|
|
19
21
|
return [require_model_errors_operation_errors.insufficientCollateral({
|
|
20
22
|
healthFactor,
|
|
21
23
|
healthFactorThreshold,
|
|
@@ -374,13 +374,14 @@ var PrepareApi = class extends require_onchain_base_MultichainConstruct.Multicha
|
|
|
374
374
|
/**
|
|
375
375
|
* {@inheritDoc IOpportunitiesPrepare.leverageBand}
|
|
376
376
|
**/
|
|
377
|
-
leverageBand(strategy, collateral, targetHF) {
|
|
377
|
+
leverageBand(strategy, collateral, targetHF, position) {
|
|
378
378
|
const sdk = this.sdk.chain(strategy.chainId);
|
|
379
379
|
return service(sdk).leverageBand({
|
|
380
380
|
sdk,
|
|
381
381
|
creditManager: strategy.creditManager,
|
|
382
382
|
collateral,
|
|
383
|
-
targetHF
|
|
383
|
+
targetHF,
|
|
384
|
+
position
|
|
384
385
|
});
|
|
385
386
|
}
|
|
386
387
|
/**
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { ierc20Abi } from "../abi/iERC20.js";
|
|
2
1
|
import { iCreditFacadeV310Abi } from "../abi/310/generated.js";
|
|
2
|
+
import { ierc20Abi } from "../abi/iERC20.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";
|
|
2
1
|
import { getNetworkType } from "../onchain/chain/chains.js";
|
|
3
2
|
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";
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { ierc20Abi } from "../../abi/iERC20.js";
|
|
2
1
|
import { iCreditFacadeV310Abi } from "../../abi/310/generated.js";
|
|
2
|
+
import { ierc20Abi } from "../../abi/iERC20.js";
|
|
3
3
|
import { AddressMap } from "../../onchain/utils/AddressMap.js";
|
|
4
4
|
import "../../onchain/index.js";
|
|
5
5
|
import { UnexpectedFacadeEventOrderError } from "./errors.js";
|
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
import { iBaseRewardPoolAbi } from "../../abi/iBaseRewardPool.js";
|
|
2
|
-
import { ierc4626AdapterAbi } from "../../abi/ierc4626Adapter.js";
|
|
3
1
|
import { AP_REWARDS_COMPRESSOR } from "../constants/address-provider.js";
|
|
4
2
|
import { ADDRESS_0X0 } from "../constants/addresses.js";
|
|
5
3
|
import { MAX_UINT256 } from "../constants/math.js";
|
|
@@ -10,6 +8,8 @@ import "../base/index.js";
|
|
|
10
8
|
import { AccountBotsService } from "./bots/AccountBotsService.js";
|
|
11
9
|
import "./bots/index.js";
|
|
12
10
|
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";
|
|
@@ -10,13 +10,13 @@ import { isPhantomToken } from "./utils/pick-token.js";
|
|
|
10
10
|
import { assertMarketOperable } from "./guards.js";
|
|
11
11
|
import { fetchCreditAccountSlice, toCreditAccountSlice } from "./utils/credit-account-slice.js";
|
|
12
12
|
import { buildBorrowState } from "./borrow.js";
|
|
13
|
+
import { strategyLimits } from "./strategyLimits.js";
|
|
14
|
+
import { accountView } from "./view.js";
|
|
13
15
|
import { calcLeverageBand } from "./leverage-band.js";
|
|
14
16
|
import { maxBorrow } from "./maxBorrow.js";
|
|
15
17
|
import { maxWithdrawCollateral } from "./maxWithdrawCollateral.js";
|
|
16
|
-
import { strategyLimits } from "./strategyLimits.js";
|
|
17
18
|
import { buildOpenStrategyState } from "./open-strategy.js";
|
|
18
19
|
import { planAddCollateral, planAdjustLeverage, planAdjustLeverageDelayed, planDeposit, planRepay, planWithdraw, planWithdrawAsset, planWithdrawDelayed } from "./plan.js";
|
|
19
|
-
import { accountView } from "./view.js";
|
|
20
20
|
import { withdrawLimits } from "./withdraw-limits.js";
|
|
21
21
|
import { realize } from "./realize.js";
|
|
22
22
|
import { planTail, projectTail } from "./tail.js";
|
|
@@ -123,9 +123,8 @@ var CreditAccountOperationsService = class extends SDKConstruct {
|
|
|
123
123
|
* given deposit reaches is decided by the debt it implies and by the
|
|
124
124
|
* `debtLimits` the market puts that debt in — the range a leverage slider should offer.
|
|
125
125
|
*
|
|
126
|
-
*
|
|
127
|
-
*
|
|
128
|
-
* holds. Nothing is fetched, so a form can ask on every keystroke.
|
|
126
|
+
* Nothing is fetched: opening uses the supplied collateral, while adjust
|
|
127
|
+
* uses a supplied account slice, so a form can ask on every keystroke.
|
|
129
128
|
*
|
|
130
129
|
* @param props - The manager, the SDK holding its market, what stands
|
|
131
130
|
* behind the position, and optionally the health factor the ceiling should
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { BigIntMath } from "../../utils/bigint-math.js";
|
|
2
2
|
import { LEVERAGE_DECIMALS } from "../../constants/math.js";
|
|
3
|
-
import { resolveCreditManager } from "./utils/common.js";
|
|
3
|
+
import { eq, resolveCreditManager } from "./utils/common.js";
|
|
4
|
+
import { strategyLimits } from "./strategyLimits.js";
|
|
5
|
+
import { accountView } from "./view.js";
|
|
4
6
|
//#region src/onchain/accounts/intents/leverage-band.ts
|
|
5
7
|
/**
|
|
6
8
|
* The leverages this market will actually fund for a position of this size.
|
|
@@ -15,8 +17,8 @@ import { resolveCreditManager } from "./utils/common.js";
|
|
|
15
17
|
* rounds **up** so the leverage it names really does clear `minDebt`, and the
|
|
16
18
|
* ceiling rounds **down** so it really does stay under the borrow limit.
|
|
17
19
|
*
|
|
18
|
-
* Nothing here is fetched or simulated —
|
|
19
|
-
* so a form can call this on each keystroke.
|
|
20
|
+
* Nothing here is fetched or simulated — adjust state comes from the supplied
|
|
21
|
+
* position and the attached market, so a form can call this on each keystroke.
|
|
20
22
|
*
|
|
21
23
|
* @param props - {@link LeverageBandProps}
|
|
22
24
|
* @returns The band, or `undefined` when there is nothing to offer: an
|
|
@@ -29,13 +31,53 @@ import { resolveCreditManager } from "./utils/common.js";
|
|
|
29
31
|
* calcLeverageBand({ sdk, creditManager, collateral }) // { min: 1.1, max: 9 }
|
|
30
32
|
* ```
|
|
31
33
|
**/
|
|
32
|
-
function calcLeverageBand({ sdk, creditManager, collateral, targetHF }) {
|
|
34
|
+
function calcLeverageBand({ sdk, creditManager, collateral, targetHF, position }) {
|
|
33
35
|
const found = resolveCreditManager(sdk, creditManager);
|
|
34
36
|
if (!found) return;
|
|
35
37
|
const { suite, market } = found;
|
|
36
|
-
const
|
|
37
|
-
if (!
|
|
38
|
+
const strategy = suite.strategy;
|
|
39
|
+
if (!strategy) return;
|
|
40
|
+
const target = strategy.targetCollateral;
|
|
38
41
|
const ceiling = suite.creditManager.maxLeverage(target, targetHF);
|
|
42
|
+
if (position) {
|
|
43
|
+
if (!eq(position.creditManager, creditManager)) throw new Error("credit account belongs to a different credit manager");
|
|
44
|
+
const creditAccount = {
|
|
45
|
+
creditAccount: position.creditAccount,
|
|
46
|
+
creditManager: position.creditManager,
|
|
47
|
+
creditFacade: suite.creditFacade.address,
|
|
48
|
+
underlying: position.underlyingToken.address,
|
|
49
|
+
enabledTokensMask: 0n,
|
|
50
|
+
totalDebtUSD: 0n,
|
|
51
|
+
totalDebt: position.totalDebt.value,
|
|
52
|
+
tokens: position.collaterals.map(({ collateral, quota }) => ({
|
|
53
|
+
token: collateral.token.address,
|
|
54
|
+
mask: 0n,
|
|
55
|
+
balance: collateral.value,
|
|
56
|
+
quota: quota.value,
|
|
57
|
+
success: true
|
|
58
|
+
}))
|
|
59
|
+
};
|
|
60
|
+
const view = {
|
|
61
|
+
...accountView(creditAccount, sdk),
|
|
62
|
+
collateral: position.totalValue.value - position.totalDebt.value
|
|
63
|
+
};
|
|
64
|
+
const { leverageLimits, quotaLimits } = strategyLimits({
|
|
65
|
+
type: "ADJUST_LEVERAGE",
|
|
66
|
+
suite,
|
|
67
|
+
view,
|
|
68
|
+
initialQuotas: creditAccount.tokens,
|
|
69
|
+
token: target,
|
|
70
|
+
targetLeverage: LEVERAGE_DECIMALS,
|
|
71
|
+
quotaReserve: void 0
|
|
72
|
+
});
|
|
73
|
+
if (!leverageLimits) return void 0;
|
|
74
|
+
const min = Number(leverageLimits.min) / Number(LEVERAGE_DECIMALS);
|
|
75
|
+
const max = Math.min(ceiling, Number(BigIntMath.min(leverageLimits.max, quotaLimits?.leverageMax ?? leverageLimits.max)) / Number(LEVERAGE_DECIMALS));
|
|
76
|
+
return min > max ? void 0 : {
|
|
77
|
+
min,
|
|
78
|
+
max
|
|
79
|
+
};
|
|
80
|
+
}
|
|
39
81
|
const underlying = market.pool.underlying;
|
|
40
82
|
const convert = (from, to, amount) => market.priceOracle.safeConvert(from, to, amount).value;
|
|
41
83
|
const netValue = collateral.reduce((acc, a) => acc + convert(a.token, underlying, a.balance), 0n);
|
|
@@ -43,9 +85,8 @@ function calcLeverageBand({ sdk, creditManager, collateral, targetHF }) {
|
|
|
43
85
|
min: 1,
|
|
44
86
|
max: ceiling
|
|
45
87
|
};
|
|
46
|
-
const { minDebt
|
|
47
|
-
const
|
|
48
|
-
const borrowLimit = available === void 0 ? maxDebt : BigIntMath.min(maxDebt, available);
|
|
88
|
+
const { minDebt } = suite.creditFacade;
|
|
89
|
+
const borrowLimit = strategy.maxBorrowAmount().amount.value;
|
|
49
90
|
const floor = BigIntMath.ceilDiv(LEVERAGE_DECIMALS * minDebt, netValue);
|
|
50
91
|
const roof = BigIntMath.ceilDiv(LEVERAGE_DECIMALS * (borrowLimit + 1n), netValue) - 1n;
|
|
51
92
|
const min = 1 + Number(floor) / Number(LEVERAGE_DECIMALS);
|
|
@@ -5,9 +5,9 @@ import { toTokenAmount } from "../../validation/helpers/token.js";
|
|
|
5
5
|
import { IntentPreviewError } from "../../validation/raise.js";
|
|
6
6
|
import { toTargetDecimals } from "./utils/common.js";
|
|
7
7
|
import { createOraclePaths } from "./utils/router-path.js";
|
|
8
|
+
import { accountView } from "./view.js";
|
|
8
9
|
import { planFinishClaimOnly, planFinishCloseAccount, planFinishDecreaseLeverage, planFinishWithdraw } from "./plan.js";
|
|
9
10
|
import { instantOutput } from "./operations.js";
|
|
10
|
-
import { accountView } from "./view.js";
|
|
11
11
|
import { realize } from "./realize.js";
|
|
12
12
|
//#region src/onchain/accounts/intents/tail.ts
|
|
13
13
|
/**
|
|
@@ -4,8 +4,8 @@ import "../../validation/helpers/health-factor-limits.js";
|
|
|
4
4
|
import "../../validation/index.js";
|
|
5
5
|
import { eq } from "./utils/common.js";
|
|
6
6
|
import { maxProportionalWithdrawal } from "./math.js";
|
|
7
|
-
import { collateralValuation } from "./collateral-valuation.js";
|
|
8
7
|
import { accountView } from "./view.js";
|
|
8
|
+
import { collateralValuation } from "./collateral-valuation.js";
|
|
9
9
|
//#region src/onchain/accounts/intents/withdraw-limits.ts
|
|
10
10
|
/**
|
|
11
11
|
* Every limit a `WITHDRAW` answers to, in underlying units.
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { iLiquidationCompressorV313Abi } from "../../../abi/ILiquidationCompressorV313.js";
|
|
2
1
|
import { AddressSet } from "../../utils/AddressSet.js";
|
|
3
2
|
import { bytes32ToString } from "../../utils/bytes32ToString.js";
|
|
4
3
|
import { ADDRESS_0X0 } from "../../constants/addresses.js";
|
|
@@ -20,6 +19,7 @@ import { SecuritizeLiquidatorContract } from "../../market/rwa/securitize/Securi
|
|
|
20
19
|
import "../../market/rwa/securitize/index.js";
|
|
21
20
|
import "../../market/index.js";
|
|
22
21
|
import { LIQUIDATION_APPROVAL_BUFFER, LIQUIDATION_COMPRESSOR_V313_ADDRESS } from "./constants.js";
|
|
22
|
+
import { iLiquidationCompressorV313Abi } from "../../../abi/ILiquidationCompressorV313.js";
|
|
23
23
|
import { skipLiquidatableAccount } from "./skipLiquidatableAccount.js";
|
|
24
24
|
//#region src/onchain/accounts/liquidations/LiquidationsService.ts
|
|
25
25
|
/**
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { iRedemptionLoggerV310Abi } from "../../../abi/iRedemptionLoggerV310.js";
|
|
2
1
|
import { BaseContract } from "../../base/BaseContract.js";
|
|
3
2
|
import "../../base/index.js";
|
|
4
3
|
import { sdkErr, sdkOk } from "../../../model/result.js";
|
|
5
4
|
import "../../../model/index.js";
|
|
6
5
|
import { decodeDelayedIntent } from "./intent-codec.js";
|
|
6
|
+
import { iRedemptionLoggerV310Abi } from "../../../abi/iRedemptionLoggerV310.js";
|
|
7
7
|
//#region src/onchain/accounts/withdrawal-compressor/RedemptionLoggerV310Contract.ts
|
|
8
8
|
const abi = iRedemptionLoggerV310Abi;
|
|
9
9
|
/**
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { iWithdrawalCompressorV310Abi } from "../../../abi/IWithdrawalCompressorV310.js";
|
|
2
1
|
import { AbstractWithdrawalCompressorContract } from "./AbstractWithdrawalCompressorContract.js";
|
|
2
|
+
import { iWithdrawalCompressorV310Abi } from "../../../abi/IWithdrawalCompressorV310.js";
|
|
3
3
|
//#region src/onchain/accounts/withdrawal-compressor/WithdrawalCompressorV310Contract.ts
|
|
4
4
|
const abi = iWithdrawalCompressorV310Abi;
|
|
5
5
|
/**
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { iWithdrawalCompressorV311Abi } from "../../../abi/IWithdrawalCompressorV311.js";
|
|
2
1
|
import { AbstractWithdrawalCompressorContract } from "./AbstractWithdrawalCompressorContract.js";
|
|
2
|
+
import { iWithdrawalCompressorV311Abi } from "../../../abi/IWithdrawalCompressorV311.js";
|
|
3
3
|
//#region src/onchain/accounts/withdrawal-compressor/WithdrawalCompressorV311Contract.ts
|
|
4
4
|
const abi = iWithdrawalCompressorV311Abi;
|
|
5
5
|
/**
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { iWithdrawalCompressorV313Abi } from "../../../abi/IWithdrawalCompressorV313.js";
|
|
2
1
|
import { encodeDelayedIntent } from "./intent-codec.js";
|
|
3
2
|
import { AbstractWithdrawalCompressorContract, iCreditAccountAbi, toClaimableWithdrawal, toPendingWithdrawal, toRequestableWithdrawal } from "./AbstractWithdrawalCompressorContract.js";
|
|
3
|
+
import { iWithdrawalCompressorV313Abi } from "../../../abi/IWithdrawalCompressorV313.js";
|
|
4
4
|
import { toWithdrawalStatus } from "./types.js";
|
|
5
5
|
//#region src/onchain/accounts/withdrawal-compressor/WithdrawalCompressorV313Contract.ts
|
|
6
6
|
const abi = iWithdrawalCompressorV313Abi;
|
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import { iExpirableAbi } from "../../abi/iExpirable.js";
|
|
2
|
-
import { iStateSerializerAbi } from "../../abi/iStateSerializer.js";
|
|
3
|
-
import { iVersionAbi } from "../../abi/iVersion.js";
|
|
4
1
|
import { AddressMap } from "../utils/AddressMap.js";
|
|
5
2
|
import { AddressSet } from "../utils/AddressSet.js";
|
|
6
3
|
import { bytes32ToString } from "../utils/bytes32ToString.js";
|
|
7
4
|
import { getAssetType } from "../chain/chains.js";
|
|
8
5
|
import { formatBN } from "../utils/formatter.js";
|
|
9
6
|
import "../utils/index.js";
|
|
7
|
+
import { iExpirableAbi } from "../../abi/iExpirable.js";
|
|
8
|
+
import { iStateSerializerAbi } from "../../abi/iStateSerializer.js";
|
|
9
|
+
import { iVersionAbi } from "../../abi/iVersion.js";
|
|
10
10
|
import { SdkRWADataNotLoadedError } from "../core/errors.js";
|
|
11
11
|
import { executeMulticallBatches } from "../utils/viem/executeMulticallBatches.js";
|
|
12
12
|
//#region src/onchain/base/TokensMeta.ts
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { iVersionAbi } from "../../abi/iVersion.js";
|
|
2
1
|
import "../constants/address-provider.js";
|
|
3
2
|
import { isV310 } from "../constants/versions.js";
|
|
4
3
|
import "../constants/index.js";
|
|
5
4
|
import { hexEq } from "../utils/hex.js";
|
|
5
|
+
import { iVersionAbi } from "../../abi/iVersion.js";
|
|
6
6
|
import { AddressProviderV310Contract } from "./AddressProviderV310Contract.js";
|
|
7
7
|
//#region src/onchain/core/createAddressProvider.ts
|
|
8
8
|
const OVERRIDE_ADDRESSES = {};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { accountMigratorAbi } from "../../../../abi/AccountMigrator.js";
|
|
2
1
|
import { AbstractAdapterContract } from "./AbstractAdapter.js";
|
|
2
|
+
import { accountMigratorAbi } from "../../../../abi/AccountMigrator.js";
|
|
3
3
|
//#region src/onchain/market/adapters/contracts/AccountMigratorAdapterContract.ts
|
|
4
4
|
const abi = accountMigratorAbi;
|
|
5
5
|
const protocolAbi = accountMigratorAbi;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { ierc4626AdapterAbi } from "../../../../abi/ierc4626Adapter.js";
|
|
2
1
|
import { MissingSerializedParamsError } from "../../../base/errors.js";
|
|
3
2
|
import "../../../base/index.js";
|
|
3
|
+
import { ierc4626AdapterAbi } from "../../../../abi/ierc4626Adapter.js";
|
|
4
4
|
import { iERC4626Abi } from "../abi/targetContractAbi.js";
|
|
5
5
|
import { fnSigToName, swapFromTransfers } from "../transferHelpers.js";
|
|
6
6
|
import { AbstractAdapterContract } from "./AbstractAdapter.js";
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { iPausableAbi } from "../../../abi/iPausable.js";
|
|
2
1
|
import { iCreditFacadeMulticallV310Abi, iCreditFacadeV310Abi } from "../../../abi/310/generated.js";
|
|
3
2
|
import { BaseContract } from "../../base/BaseContract.js";
|
|
4
3
|
import "../../base/index.js";
|
|
4
|
+
import { iPausableAbi } from "../../../abi/iPausable.js";
|
|
5
5
|
//#region src/onchain/market/credit/CreditFacadeV310BaseContract.ts
|
|
6
6
|
const abi = [
|
|
7
7
|
...iCreditFacadeV310Abi,
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { iPausableAbi } from "../../../abi/iPausable.js";
|
|
2
1
|
import { iPoolV310Abi } from "../../../abi/310/generated.js";
|
|
3
2
|
import { AddressMap } from "../../utils/AddressMap.js";
|
|
4
3
|
import { RAY } from "../../constants/math.js";
|
|
@@ -8,6 +7,7 @@ import "../../utils/index.js";
|
|
|
8
7
|
import { SdkRWADataNotLoadedError } from "../../core/errors.js";
|
|
9
8
|
import { BaseContract } from "../../base/BaseContract.js";
|
|
10
9
|
import "../../base/index.js";
|
|
10
|
+
import { iPausableAbi } from "../../../abi/iPausable.js";
|
|
11
11
|
//#region src/onchain/market/pool/PoolV310Contract.ts
|
|
12
12
|
const abi = [...iPoolV310Abi, ...iPausableAbi];
|
|
13
13
|
var PoolV310Contract = class extends BaseContract {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { iVersionAbi } from "../../../abi/iVersion.js";
|
|
2
1
|
import { bytes32ToString } from "../../utils/bytes32ToString.js";
|
|
3
2
|
import "../../utils/index.js";
|
|
3
|
+
import { iVersionAbi } from "../../../abi/iVersion.js";
|
|
4
4
|
import { iMidasDegenNFTAbi } from "../../../abi/rwa/iMidasDegenNFT.js";
|
|
5
5
|
import { DEGEN_NFT_MIDAS } from "./midas/constants.js";
|
|
6
6
|
import { MidasDegenNFT } from "./midas/MidasDegenNFT.js";
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { iethZapperAbi } from "../../../abi/iETHZapper.js";
|
|
2
1
|
import { ZapperContract } from "./ZapperContract.js";
|
|
2
|
+
import { iethZapperAbi } from "../../../abi/iETHZapper.js";
|
|
3
3
|
//#region src/onchain/market/zapper/IETHZapperContract.ts
|
|
4
4
|
const abi = iethZapperAbi;
|
|
5
5
|
var IETHZapperContract = class extends ZapperContract {
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { iZapperAbi } from "../../../abi/iZapper.js";
|
|
2
1
|
import { BaseContract } from "../../base/BaseContract.js";
|
|
3
2
|
import "../../base/index.js";
|
|
4
3
|
import { sdkErr, sdkOk } from "../../../model/result.js";
|
|
5
4
|
import "../../../model/index.js";
|
|
5
|
+
import { iZapperAbi } from "../../../abi/iZapper.js";
|
|
6
6
|
//#region src/onchain/market/zapper/ZapperContract.ts
|
|
7
7
|
/**
|
|
8
8
|
* Base contract for every Gearbox zapper. Specialized zappers (e.g.
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { ierc20Abi } from "../../../abi/iERC20.js";
|
|
2
|
-
import { iZapperAbi } from "../../../abi/iZapper.js";
|
|
3
1
|
import { iPoolV310Abi } from "../../../abi/310/generated.js";
|
|
2
|
+
import { ierc20Abi } from "../../../abi/iERC20.js";
|
|
4
3
|
import { sdkErr, sdkOk } from "../../../model/result.js";
|
|
5
4
|
import "../../../model/index.js";
|
|
5
|
+
import { iZapperAbi } from "../../../abi/iZapper.js";
|
|
6
6
|
//#region src/onchain/preview/preview/previewPoolPositionOperation.ts
|
|
7
7
|
function previewRead(operation) {
|
|
8
8
|
switch (operation.operation) {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { errorAbis } from "../../../abi/errors.js";
|
|
2
|
-
import { iUpdatablePriceFeedAbi } from "../../../abi/iUpdatablePriceFeed.js";
|
|
3
2
|
import { generateCastTraceCall } from "./cast.js";
|
|
3
|
+
import { iUpdatablePriceFeedAbi } from "../../../abi/iUpdatablePriceFeed.js";
|
|
4
4
|
import { simulateMulticall } from "./simulateMulticall.js";
|
|
5
5
|
import { BaseError, CallExecutionError, ContractFunctionRevertedError, decodeFunctionData, decodeFunctionResult, encodeFunctionData, parseAbi } from "viem";
|
|
6
6
|
import { getAction, parseAccount } from "viem/utils";
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { insufficientCollateral } from "../../../model/errors/operation-errors.js";
|
|
2
2
|
import "../../../model/index.js";
|
|
3
|
+
import "../helpers/health-factor-limits.js";
|
|
4
|
+
import "../helpers/index.js";
|
|
3
5
|
//#region src/onchain/validation/checks/checkCollateralised.ts
|
|
4
6
|
/**
|
|
5
7
|
* The account against its debt, at whichever threshold the caller holds it to.
|
|
@@ -14,7 +16,7 @@ function checkCollateralised(args) {
|
|
|
14
16
|
healthFactorThreshold,
|
|
15
17
|
safePrices
|
|
16
18
|
})];
|
|
17
|
-
if (healthFactor >= healthFactorThreshold || improvesFrom !== void 0 && healthFactor > improvesFrom) return [];
|
|
19
|
+
if (healthFactor >= healthFactorThreshold || improvesFrom !== void 0 && healthFactor >= 1e4 && healthFactor > improvesFrom) return [];
|
|
18
20
|
return [insufficientCollateral({
|
|
19
21
|
healthFactor,
|
|
20
22
|
healthFactorThreshold,
|
|
@@ -373,13 +373,14 @@ var PrepareApi = class extends MultichainConstruct {
|
|
|
373
373
|
/**
|
|
374
374
|
* {@inheritDoc IOpportunitiesPrepare.leverageBand}
|
|
375
375
|
**/
|
|
376
|
-
leverageBand(strategy, collateral, targetHF) {
|
|
376
|
+
leverageBand(strategy, collateral, targetHF, position) {
|
|
377
377
|
const sdk = this.sdk.chain(strategy.chainId);
|
|
378
378
|
return service(sdk).leverageBand({
|
|
379
379
|
sdk,
|
|
380
380
|
creditManager: strategy.creditManager,
|
|
381
381
|
collateral,
|
|
382
|
-
targetHF
|
|
382
|
+
targetHF,
|
|
383
|
+
position
|
|
383
384
|
});
|
|
384
385
|
}
|
|
385
386
|
/**
|
|
@@ -111,9 +111,8 @@ declare class CreditAccountOperationsService extends SDKConstruct {
|
|
|
111
111
|
* given deposit reaches is decided by the debt it implies and by the
|
|
112
112
|
* `debtLimits` the market puts that debt in — the range a leverage slider should offer.
|
|
113
113
|
*
|
|
114
|
-
*
|
|
115
|
-
*
|
|
116
|
-
* holds. Nothing is fetched, so a form can ask on every keystroke.
|
|
114
|
+
* Nothing is fetched: opening uses the supplied collateral, while adjust
|
|
115
|
+
* uses a supplied account slice, so a form can ask on every keystroke.
|
|
117
116
|
*
|
|
118
117
|
* @param props - The manager, the SDK holding its market, what stands
|
|
119
118
|
* behind the position, and optionally the health factor the ceiling should
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { Bps, Leverage } from "../../../model/primitives.js";
|
|
2
|
+
import { StrategyPosition } from "../../../model/positions.js";
|
|
2
3
|
import "../../../model/index.js";
|
|
3
4
|
import { Asset } from "../../base/types.js";
|
|
4
5
|
import { OnchainSDK } from "../../OnchainSDK.js";
|
|
@@ -15,9 +16,8 @@ interface LeverageBandProps {
|
|
|
15
16
|
/** Credit manager the position lives in; every limit is read off it. */
|
|
16
17
|
readonly creditManager: Address;
|
|
17
18
|
/**
|
|
18
|
-
*
|
|
19
|
-
*
|
|
20
|
-
* underlying here, so a caller hands over amounts and no exchange rates.
|
|
19
|
+
* Tokens deposited when opening a position. Ignored when `account` selects
|
|
20
|
+
* adjust mode, because that mode derives own funds from the account slice.
|
|
21
21
|
**/
|
|
22
22
|
readonly collateral: readonly Asset[];
|
|
23
23
|
/**
|
|
@@ -25,6 +25,8 @@ interface LeverageBandProps {
|
|
|
25
25
|
* points. Omitted keeps `calcMaxLeverage` on its flat buffer.
|
|
26
26
|
**/
|
|
27
27
|
readonly targetHF?: Bps;
|
|
28
|
+
/** Existing position; when present, its debt and quotas define an adjust band. */
|
|
29
|
+
readonly position?: StrategyPosition;
|
|
28
30
|
}
|
|
29
31
|
/**
|
|
30
32
|
* The leverages this market will actually fund for a position of this size.
|
|
@@ -39,8 +41,8 @@ interface LeverageBandProps {
|
|
|
39
41
|
* rounds **up** so the leverage it names really does clear `minDebt`, and the
|
|
40
42
|
* ceiling rounds **down** so it really does stay under the borrow limit.
|
|
41
43
|
*
|
|
42
|
-
* Nothing here is fetched or simulated —
|
|
43
|
-
* so a form can call this on each keystroke.
|
|
44
|
+
* Nothing here is fetched or simulated — adjust state comes from the supplied
|
|
45
|
+
* position and the attached market, so a form can call this on each keystroke.
|
|
44
46
|
*
|
|
45
47
|
* @param props - {@link LeverageBandProps}
|
|
46
48
|
* @returns The band, or `undefined` when there is nothing to offer: an
|
|
@@ -53,6 +55,6 @@ interface LeverageBandProps {
|
|
|
53
55
|
* calcLeverageBand({ sdk, creditManager, collateral }) // { min: 1.1, max: 9 }
|
|
54
56
|
* ```
|
|
55
57
|
**/
|
|
56
|
-
declare function calcLeverageBand({ sdk, creditManager, collateral, targetHF }: LeverageBandProps): LeverageBand | undefined;
|
|
58
|
+
declare function calcLeverageBand({ sdk, creditManager, collateral, targetHF, position }: LeverageBandProps): LeverageBand | undefined;
|
|
57
59
|
//#endregion
|
|
58
60
|
export { LeverageBand, LeverageBandProps, calcLeverageBand };
|
|
@@ -113,7 +113,7 @@ declare class PrepareApi extends MultichainConstruct implements IOpportunitiesPr
|
|
|
113
113
|
/**
|
|
114
114
|
* {@inheritDoc IOpportunitiesPrepare.leverageBand}
|
|
115
115
|
**/
|
|
116
|
-
leverageBand(strategy: StrategyInput, collateral: readonly Asset[], targetHF?: Bps): LeverageBand | undefined;
|
|
116
|
+
leverageBand(strategy: StrategyInput, collateral: readonly Asset[], targetHF?: Bps, position?: StrategyPosition): LeverageBand | undefined;
|
|
117
117
|
/**
|
|
118
118
|
* {@inheritDoc IOpportunitiesPrepare.withdrawableCollaterals}
|
|
119
119
|
**/
|
|
@@ -742,16 +742,15 @@ interface IOpportunitiesPrepare {
|
|
|
742
742
|
*
|
|
743
743
|
* Synchronous, unlike the ceilings above it: those read the account from the
|
|
744
744
|
* chain, this one only needs loaded market state, so a form can ask on every
|
|
745
|
-
* keystroke.
|
|
746
|
-
*
|
|
747
|
-
* value in the underlying.
|
|
745
|
+
* keystroke. Opening values `collateral`; passing `position` selects adjust
|
|
746
|
+
* mode, which derives own funds, debt and quota state from that position.
|
|
748
747
|
*
|
|
749
748
|
* Nothing at all when the market has no range to offer: a deposit too small
|
|
750
749
|
* to carry `minDebt` at any leverage the threshold allows, or a manager with
|
|
751
750
|
* no borrowing room left. Not the same answer as "every leverage works", and
|
|
752
751
|
* a caller must not mark a range for it.
|
|
753
752
|
**/
|
|
754
|
-
leverageBand(strategy: StrategyInput, collateral: readonly Asset[], targetHF?: Bps): LeverageBand | undefined;
|
|
753
|
+
leverageBand(strategy: StrategyInput, collateral: readonly Asset[], targetHF?: Bps, position?: StrategyPosition): LeverageBand | undefined;
|
|
755
754
|
/**
|
|
756
755
|
* The collaterals an account can actually take out, most valuable first —
|
|
757
756
|
* what a withdraw-collateral picker offers.
|