@gearbox-protocol/sdk 15.1.0-next.5 → 15.1.0-next.7
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/common-utils/utils/apy/get-single-quota-borrow-rate.js +2 -0
- package/dist/cjs/common-utils/utils/creditAccount/calc-health-factor.js +24 -22
- package/dist/cjs/common-utils/utils/creditAccount/calc-quota-borrow-rate.js +2 -0
- package/dist/cjs/common-utils/utils/creditAccount/get-time-to-liquidation.js +5 -4
- package/dist/cjs/common-utils/utils/creditAccount/liquidation-price.js +21 -11
- package/dist/cjs/model/index.js +1 -0
- package/dist/cjs/model/positions.schema.js +13 -0
- package/dist/cjs/preview/preview/CreditAccountState.js +14 -1
- package/dist/cjs/preview/preview/buildDelayedPreview.js +16 -6
- package/dist/cjs/preview/preview/previewAdjustCreditAccount.js +9 -2
- package/dist/cjs/preview/preview/previewOpenCreditAccount.js +11 -3
- package/dist/cjs/preview/preview/previewOperation.js +1 -1
- package/dist/cjs/sdk/accounts/CreditAccountsServiceV310.js +0 -6
- package/dist/cjs/sdk/accounts/credit-account-compressor/CreditAccountCompressor.js +2 -90
- package/dist/cjs/sdk/accounts/intents/testing/sdk-mock.js +31 -4
- package/dist/cjs/sdk/accounts/intents/utils/adjust-state-to-snapshot.js +18 -0
- package/dist/cjs/sdk/accounts/intents/utils/index.js +2 -0
- package/dist/cjs/sdk/accounts/liquidations/LiquidationsService.js +0 -3
- package/dist/cjs/sdk/index.js +21 -5
- package/dist/cjs/sdk/market/credit/CreditManagerV310Contract.js +1 -12
- package/dist/cjs/sdk/market/credit/CreditSuite.js +17 -26
- package/dist/cjs/sdk/market/credit/index.js +3 -0
- package/dist/cjs/sdk/market/credit/isStrategyCollateral.js +50 -0
- package/dist/cjs/sdk/market/index.js +17 -0
- package/dist/cjs/sdk/market/math.js +57 -44
- package/dist/cjs/sdk/market/oracle/PriceOracleBaseContract.js +10 -3
- package/dist/cjs/sdk/market/pool/PoolV310Contract.js +1 -1
- package/dist/cjs/sdk/opportunities/index.js +0 -13
- package/dist/cjs/sdk/positions/PositionsService.js +206 -1
- package/dist/cjs/sdk/positions/calcBorrowRate.js +43 -0
- package/dist/cjs/sdk/positions/calcHealthFactor.js +44 -0
- package/dist/cjs/sdk/positions/calcLiquidationPrice.js +23 -0
- package/dist/cjs/sdk/positions/calcLiquidationPriceForTarget.js +30 -0
- package/dist/cjs/sdk/positions/calcTimeToLiquidationMs.js +18 -0
- package/dist/cjs/sdk/positions/index.js +12 -1
- package/dist/cjs/sdk/positions/types.js +31 -0
- package/dist/esm/common-utils/utils/apy/get-single-quota-borrow-rate.js +2 -0
- package/dist/esm/common-utils/utils/creditAccount/calc-health-factor.js +24 -22
- package/dist/esm/common-utils/utils/creditAccount/calc-quota-borrow-rate.js +2 -0
- package/dist/esm/common-utils/utils/creditAccount/get-time-to-liquidation.js +5 -4
- package/dist/esm/common-utils/utils/creditAccount/liquidation-price.js +21 -11
- 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/positions.schema.js +14 -2
- package/dist/esm/plugins/adapters/contracts/ERC4626AdapterContract.js +1 -1
- package/dist/esm/preview/preview/CreditAccountState.js +14 -1
- package/dist/esm/preview/preview/buildDelayedPreview.js +16 -6
- package/dist/esm/preview/preview/previewAdjustCreditAccount.js +9 -2
- package/dist/esm/preview/preview/previewOpenCreditAccount.js +11 -3
- package/dist/esm/preview/preview/previewOperation.js +1 -1
- package/dist/esm/preview/simulate/simulatePoolOperation.js +1 -1
- package/dist/esm/preview/trace/extractTransfers.js +1 -1
- package/dist/esm/sdk/accounts/CreditAccountsServiceV310.js +2 -8
- package/dist/esm/sdk/accounts/credit-account-compressor/CreditAccountCompressor.js +2 -90
- package/dist/esm/sdk/accounts/intents/testing/sdk-mock.js +31 -4
- package/dist/esm/sdk/accounts/intents/utils/adjust-state-to-snapshot.js +17 -0
- package/dist/esm/sdk/accounts/intents/utils/index.js +2 -1
- package/dist/esm/sdk/accounts/liquidations/LiquidationsService.js +1 -4
- package/dist/esm/sdk/accounts/withdrawal-compressor/RedemptionLoggerV310Contract.js +1 -1
- package/dist/esm/sdk/accounts/withdrawal-compressor/WithdrawalCompressorV310Contract.js +1 -1
- package/dist/esm/sdk/accounts/withdrawal-compressor/WithdrawalCompressorV311Contract.js +1 -1
- package/dist/esm/sdk/accounts/withdrawal-compressor/WithdrawalCompressorV313Contract.js +1 -1
- package/dist/esm/sdk/base/TokensMeta.js +3 -3
- package/dist/esm/sdk/chain/detectNetwork.js +1 -1
- package/dist/esm/sdk/core/createAddressProvider.js +1 -1
- package/dist/esm/sdk/index.js +9 -2
- package/dist/esm/sdk/market/credit/CreditFacadeV310BaseContract.js +1 -1
- package/dist/esm/sdk/market/credit/CreditManagerV310Contract.js +2 -13
- package/dist/esm/sdk/market/credit/CreditSuite.js +18 -27
- package/dist/esm/sdk/market/credit/index.js +2 -1
- package/dist/esm/sdk/market/credit/isStrategyCollateral.js +48 -0
- package/dist/esm/sdk/market/index.js +3 -1
- package/dist/esm/sdk/market/math.js +52 -40
- package/dist/esm/sdk/market/oracle/PriceOracleBaseContract.js +10 -3
- package/dist/esm/sdk/market/pool/PoolV310Contract.js +3 -3
- package/dist/esm/sdk/market/zapper/IETHZapperContract.js +1 -1
- package/dist/esm/sdk/market/zapper/ZapperContract.js +1 -1
- package/dist/esm/sdk/opportunities/index.js +1 -2
- package/dist/esm/sdk/pools/PoolService.js +1 -1
- package/dist/esm/sdk/positions/PositionsService.js +206 -1
- package/dist/esm/sdk/positions/calcBorrowRate.js +42 -0
- package/dist/esm/sdk/positions/calcHealthFactor.js +43 -0
- package/dist/esm/sdk/positions/calcLiquidationPrice.js +22 -0
- package/dist/esm/sdk/positions/calcLiquidationPriceForTarget.js +29 -0
- package/dist/esm/sdk/positions/calcTimeToLiquidationMs.js +17 -0
- package/dist/esm/sdk/positions/index.js +7 -2
- package/dist/esm/sdk/positions/types.js +31 -1
- package/dist/esm/sdk/utils/viem/simulateWithPriceUpdates.js +1 -1
- package/dist/types/common-utils/utils/apy/get-single-quota-borrow-rate.d.ts +2 -0
- package/dist/types/common-utils/utils/creditAccount/calc-health-factor.d.ts +3 -0
- package/dist/types/common-utils/utils/creditAccount/calc-quota-borrow-rate.d.ts +2 -0
- package/dist/types/common-utils/utils/creditAccount/get-time-to-liquidation.d.ts +3 -0
- package/dist/types/common-utils/utils/creditAccount/liquidation-price.d.ts +3 -0
- package/dist/types/model/index.d.ts +3 -3
- package/dist/types/model/opportunities.d.ts +9 -9
- package/dist/types/model/positions.d.ts +87 -4
- package/dist/types/model/positions.schema.d.ts +26 -1
- package/dist/types/preview/preview/CreditAccountState.d.ts +6 -0
- package/dist/types/preview/preview/buildDelayedPreview.d.ts +5 -1
- package/dist/types/preview/preview/types.d.ts +4 -2
- package/dist/types/sdk/accounts/CreditAccountsServiceV310.d.ts +1 -7
- package/dist/types/sdk/accounts/credit-account-compressor/CreditAccountCompressor.d.ts +3 -12
- package/dist/types/sdk/accounts/credit-account-compressor/index.d.ts +2 -2
- package/dist/types/sdk/accounts/credit-account-compressor/types.d.ts +1 -19
- package/dist/types/sdk/accounts/index.d.ts +2 -2
- package/dist/types/sdk/accounts/intents/testing/sdk-mock.d.ts +6 -0
- package/dist/types/sdk/accounts/intents/utils/adjust-state-to-snapshot.d.ts +13 -0
- package/dist/types/sdk/accounts/intents/utils/index.d.ts +2 -1
- package/dist/types/sdk/accounts/types.d.ts +1 -12
- package/dist/types/sdk/index.d.ts +10 -4
- package/dist/types/sdk/market/credit/CreditManagerV310Contract.d.ts +0 -4
- package/dist/types/sdk/market/credit/CreditSuite.d.ts +2 -16
- package/dist/types/sdk/market/credit/index.d.ts +2 -1
- package/dist/types/sdk/market/credit/isStrategyCollateral.d.ts +74 -0
- package/dist/types/sdk/market/credit/types.d.ts +2 -9
- package/dist/types/sdk/market/index.d.ts +3 -1
- package/dist/types/sdk/market/math.d.ts +44 -34
- package/dist/types/sdk/market/oracle/PriceOracleBaseContract.d.ts +4 -0
- package/dist/types/sdk/market/oracle/types.d.ts +8 -0
- package/dist/types/sdk/opportunities/index.d.ts +1 -2
- package/dist/types/sdk/positions/PositionsService.d.ts +31 -2
- package/dist/types/sdk/positions/calcBorrowRate.d.ts +40 -0
- package/dist/types/sdk/positions/calcHealthFactor.d.ts +45 -0
- package/dist/types/sdk/positions/calcLiquidationPrice.d.ts +12 -0
- package/dist/types/sdk/positions/calcLiquidationPriceForTarget.d.ts +43 -0
- package/dist/types/sdk/positions/calcTimeToLiquidationMs.d.ts +15 -0
- package/dist/types/sdk/positions/index.d.ts +7 -2
- package/dist/types/sdk/positions/types.d.ts +58 -1
- package/package.json +1 -1
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import { Address } from "viem";
|
|
2
|
+
//#region src/sdk/market/credit/isStrategyCollateral.d.ts
|
|
3
|
+
/**
|
|
4
|
+
* Withdrawal and redemption phantom tokens that can never be acquired as a
|
|
5
|
+
* strategy target. Other `PHANTOM_TOKEN::*` types (Convex, Infrared, staking
|
|
6
|
+
* rewards) can.
|
|
7
|
+
*/
|
|
8
|
+
declare const NON_STRATEGY_PHANTOM_TOKEN_TYPES: readonly ["PHANTOM_TOKEN::INFINIFI_UNWIND", "PHANTOM_TOKEN::MELLOW_WITHDRAWAL", "PHANTOM_TOKEN::MIDAS_REDEMPTION", "PHANTOM_TOKEN::SECURITIZE_RD", "PHANTOM_TOKEN::UPSHIFT_WITHDRAW"];
|
|
9
|
+
/**
|
|
10
|
+
* Inputs of {@link isStrategyCollateral}, all resolved against the credit
|
|
11
|
+
* manager, market, and token metadata by the caller.
|
|
12
|
+
*/
|
|
13
|
+
interface IsStrategyCollateralProps {
|
|
14
|
+
/**
|
|
15
|
+
* Candidate collateral token.
|
|
16
|
+
**/
|
|
17
|
+
token: Address;
|
|
18
|
+
/**
|
|
19
|
+
* Credit manager underlying (debt asset).
|
|
20
|
+
**/
|
|
21
|
+
underlying: Address;
|
|
22
|
+
/**
|
|
23
|
+
* Token the market's underlying wraps (same as `underlying` on non-RWA
|
|
24
|
+
* markets).
|
|
25
|
+
*/
|
|
26
|
+
unwrappedUnderlying: Address;
|
|
27
|
+
/**
|
|
28
|
+
* Liquidation threshold of the token in this credit manager, in bps.
|
|
29
|
+
**/
|
|
30
|
+
liquidationThreshold: number;
|
|
31
|
+
/**
|
|
32
|
+
* Gearbox contract type of the token (e.g. `"PHANTOM_TOKEN::CONVEX"`).
|
|
33
|
+
* Optional — plain tokens have none.
|
|
34
|
+
*/
|
|
35
|
+
contractType?: string;
|
|
36
|
+
/**
|
|
37
|
+
* Whether the token itself is expired (e.g. a matured Pendle PT). Optional
|
|
38
|
+
* — treated as not expired when absent.
|
|
39
|
+
*/
|
|
40
|
+
isExpired?: boolean;
|
|
41
|
+
/**
|
|
42
|
+
* Latest main oracle price for the token in USD (8 decimals), `undefined`
|
|
43
|
+
* when there is no feed. A failed answer is `0` — PriceFeedCompressor
|
|
44
|
+
* guarantees `price == 0` when `success == false`.
|
|
45
|
+
*/
|
|
46
|
+
mainPrice?: bigint;
|
|
47
|
+
/**
|
|
48
|
+
* Whether the market still accepts quota for the token.
|
|
49
|
+
**/
|
|
50
|
+
hasActiveQuota: boolean;
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Whether a collateral token can be the target of a leveraged strategy.
|
|
54
|
+
*
|
|
55
|
+
* A token qualifies when it
|
|
56
|
+
*
|
|
57
|
+
* - has a liquidation threshold above `0` and below `100%`, and is not the
|
|
58
|
+
* suite's underlying — borrowing an asset against itself is not a position,
|
|
59
|
+
* and an LT of `0` or at least `100%` would mean unbounded leverage;
|
|
60
|
+
* - is not the token the market's underlying wraps, which for an RWA market
|
|
61
|
+
* is the same exposure as the underlying itself (also rejected when
|
|
62
|
+
* `contractType` starts with `"RWA_UNDERLYING::"`);
|
|
63
|
+
* - is not a withdrawal or redemption phantom token listed in
|
|
64
|
+
* {@link NON_STRATEGY_PHANTOM_TOKEN_TYPES} — those only ever appear as the
|
|
65
|
+
* intermediate step of a withdrawal and cannot be acquired;
|
|
66
|
+
* - is not an expired token, e.g. a matured Pendle PT;
|
|
67
|
+
* - has a non-zero main price in the market's oracle — a zero or missing
|
|
68
|
+
* answer (e.g. a failed or zero price feed) means the position cannot be
|
|
69
|
+
* valued;
|
|
70
|
+
* - the market still accepts quota for.
|
|
71
|
+
*/
|
|
72
|
+
declare function isStrategyCollateral({ token, underlying, unwrappedUnderlying, liquidationThreshold, contractType, isExpired, mainPrice, hasActiveQuota }: IsStrategyCollateralProps): boolean;
|
|
73
|
+
//#endregion
|
|
74
|
+
export { IsStrategyCollateralProps, NON_STRATEGY_PHANTOM_TOKEN_TYPES, isStrategyCollateral };
|
|
@@ -127,21 +127,14 @@ interface ICreditManagerContract extends IBaseContract {
|
|
|
127
127
|
* List of collateral tokens
|
|
128
128
|
*/
|
|
129
129
|
collateralTokens: Address[];
|
|
130
|
-
/**
|
|
131
|
-
* Collateral tokens a leveraged position can be built around: the underlying
|
|
132
|
-
* is excluded, because borrowing an asset against itself is not a position,
|
|
133
|
-
* and so is anything whose liquidation threshold is `0` or at least `100%`,
|
|
134
|
-
* which would mean unbounded leverage.
|
|
135
|
-
*/
|
|
136
|
-
readonly leverageableCollaterals: Address[];
|
|
137
130
|
/**
|
|
138
131
|
* Percentage of liquidated account value in bps paid to the liquidator
|
|
139
132
|
* (i.e. `100% - liquidationDiscount`).
|
|
140
133
|
*/
|
|
141
134
|
readonly liquidationPremium: Bps;
|
|
142
135
|
/**
|
|
143
|
-
* Highest leverage a collateral's liquidation threshold allows
|
|
144
|
-
* `1 / (1
|
|
136
|
+
* Highest total-value leverage a collateral's liquidation threshold allows:
|
|
137
|
+
* `(1 − 0.05) / (1 − lt)`.
|
|
145
138
|
*
|
|
146
139
|
* @param collateral - Collateral token address.
|
|
147
140
|
* @throws If the credit manager does not value the token.
|
|
@@ -56,6 +56,7 @@ import { MarketSuite, StrategyRef } from "./MarketSuite.js";
|
|
|
56
56
|
import { CreditSuite } from "./credit/CreditSuite.js";
|
|
57
57
|
import { dominantCollateral, mustGetDominantCollateral } from "./credit/dominantCollateral.js";
|
|
58
58
|
import { ExpectedBalanceDeltasProps, ExpectedOutput, expectedBalanceDeltas } from "./credit/expectedBalanceDeltas.js";
|
|
59
|
+
import { IsStrategyCollateralProps, NON_STRATEGY_PHANTOM_TOKEN_TYPES, isStrategyCollateral } from "./credit/isStrategyCollateral.js";
|
|
59
60
|
import "./credit/index.js";
|
|
60
61
|
import { CompressorZapperData, ZapperData } from "./types.js";
|
|
61
62
|
import { IZapperContract, ParsedZapperDeposit, ParsedZapperOperation, ParsedZapperRedeem } from "./zapper/types.js";
|
|
@@ -66,4 +67,5 @@ import { IERC20ZapperContract } from "./zapper/IERC20ZapperContract.js";
|
|
|
66
67
|
import { IETHZapperContract } from "./zapper/IETHZapperContract.js";
|
|
67
68
|
import "./zapper/index.js";
|
|
68
69
|
import { MarketRegister, MarketRegistryState, MarketRegistryStateHuman } from "./MarketRegister.js";
|
|
69
|
-
|
|
70
|
+
import { MAX_LEVERAGE_BUFFER_BPS, OptimalRepaidAmountProps, PARTIAL_LIQUIDATION_BUFFER_BPS, calcAdditionalBorrowApy, calcBorrowApy, calcMaxLeverage, calcPositionLeverage, calcUtilization, healthFactorBps, minSeizedAmount, optimalHFForPartialLiquidation, optimalRepaidAmount, rayToBps, usdToNumber } from "./math.js";
|
|
71
|
+
export { AbstractLPPriceFeedContract, AbstractPriceFeedContract, BalanceDelta, BalancerStablePriceFeedContract, BalancerWeightedPriceFeedContract, BoundedPriceFeedContract, CompositePriceFeedContract, CompressorZapperData, CreditAccountTokenQuota, CreditConfiguratorV310Contract, type abi as CreditFacadeV310Abi, abi as creditFacadeV310Abi, CreditFacadeV310BaseContract, CreditFacadeV310Contract, CreditManagerV310Contract, CreditSuite, CurveCryptoPriceFeedContract, CurveStablePriceFeedContract, CurveUSDPriceFeedContract, DStokenData, Erc4626PriceFeedContract, ExpectedBalanceDeltasProps, ExpectedOutput, ExternalPriceFeedContract, type FetchRedstonePayloadsOptions, GaugeContract, GaugeParams, GetOpenAccountRequirementsProps, IAdapterContract, ICreditConfiguratorContract, ICreditFacadeContract, ICreditManagerContract, IERC20ZapperContract, IETHZapperContract, IInterestRateModelContract, IPoolContract, IPriceFeedContract, IPriceOracleContract, IRWAFactory, IRateKeeperContract, IUpdatablePriceFeedContract, IZapperContract, InterestRateModelType, IsStrategyCollateralProps, LatestUpdate, LinearInterestRateModelContract, LiquidationFees, MAX_LEVERAGE_BUFFER_BPS, MarketRegister, MarketRegistryState, MarketRegistryStateHuman, MarketSuite, MellowLRTPriceFeedContract, MidasLiquidatorContract, NON_STRATEGY_PHANTOM_TOKEN_TYPES, OptimalRepaidAmountProps, PARTIAL_LIQUIDATION_BUFFER_BPS, PHANTOM_TOKEN_MIDAS_REDEMPTION, PHANTOM_TOKEN_SECURITIZE_REDEMPTION, ParsedZapperDeposit, ParsedZapperOperation, ParsedZapperRedeem, PartialLiquidationParams, PartialPriceFeedInitError, PartialPriceFeedTreeNode, PendleTWAPPTPriceFeed, PlaceholderAdapterContract, PlaceholderAdapterContractOptions, PoolQuotaKeeperContract, PoolSuite, PoolV310Contract, PrepareUpdateQuotasProps, PriceFeedConstructorArgs, PriceFeedContractType, PriceFeedRef, PriceFeedRegister, PriceFeedRegisterHooks, PriceFeedRegisterOptions, PriceFeedUsageType, PriceFeedsForAccountOptions, PriceFeedsForTokensOptions, PriceOracleV310Contract, PriceUpdate, PythPriceFeed, RWACompressorCall, RWACompressorInvestorData, RWACompressorResponse, RWAFactoryData, RWAFactoryStateHuman, RWAFactoryType, RWAInvestorData, RWAMissingOpenAccountRequirements, RWAOpenAccountRequirements, RWAOperationArgs, RWARegistry, RWAState, RWAStateHuman, RWAUnderlyingData, RWA_FACTORY_SECURITIZE, RWA_FACTORY_TYPES, RWA_LIQUIDATOR_MIDAS, RWA_LIQUIDATOR_SECURITIZE, RampEvent, RateKeeperType, RedstonePriceFeedContract, SECURITIZE_REGISTER_VAULT_TYPES, SecuritizeCreditAccountData, SecuritizeInvestorData, SecuritizeLiquidatorContract, SecuritizeMissingOpenAccountRequirements, SecuritizeOpenAccountRequirements, SecuritizeOperationArgs, SecuritizeRWAFactory, SecuritizeRWAFactoryStateHuman, SecuritizeRegisterMessage, SecuritizeRegisterVaultMessage, SecuritizeSignature, StrategyRef, type TimestampedCalldata, UnsupportedZapperFunctionError, UpdatePriceFeedsResult, WstETHPriceFeedContract, YearnPriceFeedContract, ZapperContract, ZapperData, ZeroPriceFeedContract, calcAdditionalBorrowApy, calcBorrowApy, calcMaxLeverage, calcPositionLeverage, calcUtilization, createAdapter, createPriceOracle, createZapper, dominantCollateral, expectedBalanceDeltas, fetchRedstonePayloads, getRawPriceUpdates, healthFactorBps, isLPPriceFeed, isRWAFactory, isStrategyCollateral, isUpdatablePriceFeed, minSeizedAmount, mustGetDominantCollateral, optimalHFForPartialLiquidation, optimalRepaidAmount, rayToBps, usdToNumber };
|
|
@@ -7,7 +7,8 @@ import "../../model/index.js";
|
|
|
7
7
|
*
|
|
8
8
|
* @example
|
|
9
9
|
* ```ts
|
|
10
|
-
*
|
|
10
|
+
* // ray: 5% (0.05 × 10²⁷)
|
|
11
|
+
* rayToBps(50_000_000_000_000_000_000_000_000n) // 500 bps = 5%
|
|
11
12
|
* ```
|
|
12
13
|
**/
|
|
13
14
|
declare function rayToBps(ray: bigint): Bps;
|
|
@@ -16,6 +17,7 @@ declare function rayToBps(ray: bigint): Bps;
|
|
|
16
17
|
*
|
|
17
18
|
* @example
|
|
18
19
|
* ```ts
|
|
20
|
+
* // usd: $1500.50 in 8-decimal fixed point
|
|
19
21
|
* usdToNumber(150_050_000_000n) // 1500.5
|
|
20
22
|
* ```
|
|
21
23
|
**/
|
|
@@ -26,78 +28,86 @@ declare function usdToNumber(usd: bigint): number;
|
|
|
26
28
|
*
|
|
27
29
|
* @example
|
|
28
30
|
* ```ts
|
|
29
|
-
*
|
|
31
|
+
* // borrowed: 750, total: 1000
|
|
32
|
+
* calcUtilization(750n, 1000n) // 750 / 1000 = 7500 bps = 75%
|
|
30
33
|
* ```
|
|
31
34
|
**/
|
|
32
|
-
declare function
|
|
35
|
+
declare function calcUtilization(borrowed: bigint, total: bigint): Bps;
|
|
33
36
|
/**
|
|
34
|
-
* Annual cost of debt for a credit manager, in basis points:
|
|
35
|
-
*
|
|
37
|
+
* Annual cost of debt for a credit manager, in basis points:
|
|
38
|
+
* `baseInterestRate × (1 + feeInterest)` — the pool's base rate plus the
|
|
39
|
+
* protocol's cut of the accrued interest.
|
|
36
40
|
*
|
|
37
41
|
* @param baseInterestRate - Pool base rate in ray.
|
|
38
42
|
* @param feeInterest - Credit manager interest fee in basis points.
|
|
39
43
|
*
|
|
40
44
|
* @example
|
|
41
45
|
* ```ts
|
|
42
|
-
* // 5%
|
|
43
|
-
*
|
|
46
|
+
* // baseInterestRate: 5% in ray, feeInterest: 5000 bps = 50%
|
|
47
|
+
* calcBorrowApy(50_000_000_000_000_000_000_000_000n, 5000) // 5% × 1.5 = 750 bps = 7.5%
|
|
44
48
|
* ```
|
|
45
49
|
**/
|
|
46
|
-
declare function
|
|
50
|
+
declare function calcBorrowApy(baseInterestRate: bigint, feeInterest: number): Bps;
|
|
47
51
|
/**
|
|
48
|
-
*
|
|
49
|
-
*
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
52
|
+
* 5% safety margin subtracted from 100% in {@link calcMaxLeverage}, so a
|
|
53
|
+
* maxed position opens with HF slightly above 1.
|
|
54
|
+
**/
|
|
55
|
+
declare const MAX_LEVERAGE_BUFFER_BPS = 500;
|
|
56
|
+
/**
|
|
57
|
+
* Highest total-value leverage a liquidation threshold allows:
|
|
58
|
+
* `(100% − buffer) / (100% − liquidationThreshold)`. At HF = 1, debt is
|
|
59
|
+
* `liquidationThreshold × totalValue`, leaving `1 − liquidationThreshold` of
|
|
60
|
+
* equity per unit of exposure; the {@link MAX_LEVERAGE_BUFFER_BPS} buffer
|
|
61
|
+
* keeps the maxed position slightly away from that boundary.
|
|
53
62
|
*
|
|
54
63
|
* @example
|
|
55
64
|
* ```ts
|
|
56
|
-
*
|
|
57
|
-
*
|
|
65
|
+
* // liquidationThreshold: 9000 bps = 90%
|
|
66
|
+
* calcMaxLeverage(9000) // (1 − 0.05) / (1 − 0.9) = 9.5x total exposure
|
|
58
67
|
* ```
|
|
59
68
|
**/
|
|
60
|
-
declare function
|
|
69
|
+
declare function calcMaxLeverage(liquidationThreshold: Bps): Leverage;
|
|
61
70
|
/**
|
|
62
71
|
* Converts a credit account's health factor from the 18-decimal fixed point the
|
|
63
72
|
* contracts store to basis points.
|
|
64
73
|
*
|
|
65
|
-
*
|
|
74
|
+
* Accounts with no debt store `MAX_UINT256` on-chain; for those this
|
|
75
|
+
* returns `0`.
|
|
66
76
|
*
|
|
67
77
|
* @example
|
|
68
78
|
* ```ts
|
|
69
|
-
*
|
|
79
|
+
* // healthFactor: 1.25 in 18-decimal fixed point
|
|
80
|
+
* healthFactorBps(1_250_000_000_000_000_000n) // 12500 bps = 1.25
|
|
70
81
|
* ```
|
|
71
82
|
**/
|
|
72
83
|
declare function healthFactorBps(healthFactor: bigint): Bps;
|
|
73
84
|
/**
|
|
74
|
-
*
|
|
75
|
-
*
|
|
76
|
-
*
|
|
77
|
-
* Returns `0` for a position that carries no debt and for one that is
|
|
78
|
-
* underwater, where there is no equity to lever.
|
|
85
|
+
* Total-value leverage of an open position:
|
|
86
|
+
* `totalValue / (totalValue − totalDebt)`. `1` when unleveraged, `0` when
|
|
87
|
+
* underwater.
|
|
79
88
|
*
|
|
80
|
-
* @param
|
|
81
|
-
* @param
|
|
89
|
+
* @param totalValue - Total value of the position.
|
|
90
|
+
* @param totalDebt - Debt principal plus accrued interest and fees, same token.
|
|
82
91
|
*
|
|
83
92
|
* @example
|
|
84
93
|
* ```ts
|
|
85
|
-
*
|
|
94
|
+
* // totalValue: 100k, totalDebt: 80k → equity: 100k − 80k = 20k
|
|
95
|
+
* calcPositionLeverage(100_000n, 80_000n) // 100k / 20k = 5x
|
|
86
96
|
* ```
|
|
87
97
|
**/
|
|
88
|
-
declare function
|
|
98
|
+
declare function calcPositionLeverage(totalValue: bigint, totalDebt: bigint): Leverage;
|
|
89
99
|
/**
|
|
90
|
-
* Annual quota cost
|
|
91
|
-
*
|
|
92
|
-
*
|
|
100
|
+
* Annual quota cost on equity, in basis points:
|
|
101
|
+
* `quotaRate × (1 + feeInterest) × leverage`. Quota accrues on the whole
|
|
102
|
+
* quoted position, and the DAO takes `feeInterest` of it as with base interest.
|
|
93
103
|
*
|
|
94
104
|
* @example
|
|
95
105
|
* ```ts
|
|
96
|
-
* // 2
|
|
97
|
-
*
|
|
106
|
+
* // quotaRate: 200 bps = 2%, feeInterest: 2500 bps = 25%, leverage: 9.5x
|
|
107
|
+
* calcAdditionalBorrowApy(200, 2500, 9.5) // 2% × 1.25 × 9.5 = 2375 bps = 23.75%
|
|
98
108
|
* ```
|
|
99
109
|
**/
|
|
100
|
-
declare function
|
|
110
|
+
declare function calcAdditionalBorrowApy(quotaRate: Bps, feeInterest: Bps, leverage: Leverage): Bps;
|
|
101
111
|
/**
|
|
102
112
|
* {@link PERCENTAGE_FACTOR} less a 0.1% safety buffer.
|
|
103
113
|
*
|
|
@@ -158,4 +168,4 @@ declare function optimalRepaidAmount({ totalDebt, twvUnderlying, minDebt, optima
|
|
|
158
168
|
**/
|
|
159
169
|
declare function optimalHFForPartialLiquidation(borrowRate: bigint): bigint;
|
|
160
170
|
//#endregion
|
|
161
|
-
export { OptimalRepaidAmountProps, PARTIAL_LIQUIDATION_BUFFER_BPS,
|
|
171
|
+
export { MAX_LEVERAGE_BUFFER_BPS, OptimalRepaidAmountProps, PARTIAL_LIQUIDATION_BUFFER_BPS, calcAdditionalBorrowApy, calcBorrowApy, calcMaxLeverage, calcPositionLeverage, calcUtilization, healthFactorBps, minSeizedAmount, optimalHFForPartialLiquidation, optimalRepaidAmount, rayToBps, usdToNumber };
|
|
@@ -92,6 +92,10 @@ declare abstract class PriceOracleBaseContract<abi extends Abi | readonly unknow
|
|
|
92
92
|
* {@inheritDoc IPriceOracleContract.convertFromUSD}
|
|
93
93
|
**/
|
|
94
94
|
convertFromUSD(to: Address, amount: bigint, reserve?: boolean): bigint;
|
|
95
|
+
/**
|
|
96
|
+
* {@inheritDoc IPriceOracleContract.safeConvertToUSD}
|
|
97
|
+
**/
|
|
98
|
+
safeConvertToUSD(token: Address, amount: bigint): bigint | null;
|
|
95
99
|
/**
|
|
96
100
|
* {@inheritDoc IPriceOracleContract.safeUsdValue}
|
|
97
101
|
**/
|
|
@@ -134,6 +134,14 @@ interface IPriceOracleContract extends IBaseContract {
|
|
|
134
134
|
* @param reserve - Use reserve feeds instead of main.
|
|
135
135
|
**/
|
|
136
136
|
convertToUSD: (from: Address, amount: bigint, reserve?: boolean) => bigint;
|
|
137
|
+
/**
|
|
138
|
+
* Like {@link convertToUSD}, but returns `null` instead of throwing when
|
|
139
|
+
* the token cannot be priced (missing or unsuccessful feed).
|
|
140
|
+
*
|
|
141
|
+
* @param token - Token address.
|
|
142
|
+
* @param amount - Amount in token decimals.
|
|
143
|
+
**/
|
|
144
|
+
safeConvertToUSD: (token: Address, amount: bigint) => bigint | null;
|
|
137
145
|
/**
|
|
138
146
|
* Converts a USD amount to a token amount using latest known prices.
|
|
139
147
|
* @param to - Token address.
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { OptimalRepaidAmountProps, PARTIAL_LIQUIDATION_BUFFER_BPS, additionalBorrowApyBps, borrowApyBps, healthFactorBps, maxLeverage, minSeizedAmount, optimalHFForPartialLiquidation, optimalRepaidAmount, positionLeverage, rayToBps, usdToNumber, utilizationBps } from "../market/math.js";
|
|
2
1
|
import { MultichainOpportunitiesService } from "./MultichainOpportunitiesService.js";
|
|
3
2
|
import { OpportunitiesService } from "./OpportunitiesService.js";
|
|
4
|
-
export { MultichainOpportunitiesService, OpportunitiesService
|
|
3
|
+
export { MultichainOpportunitiesService, OpportunitiesService };
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Bps } from "../../model/primitives.js";
|
|
2
|
+
import { BorrowRateBreakdown, Position, StrategyPosition } from "../../model/positions.js";
|
|
2
3
|
import "../../model/index.js";
|
|
3
|
-
import { ListPositionsProps } from "./types.js";
|
|
4
|
+
import { AccountSnapshot, ListPositionsProps, ListStrategyPositionsProps } from "./types.js";
|
|
4
5
|
import { SDKConstruct } from "../base/SDKConstruct.js";
|
|
5
6
|
import "../base/index.js";
|
|
6
7
|
//#region src/sdk/positions/PositionsService.d.ts
|
|
@@ -10,6 +11,7 @@ import "../base/index.js";
|
|
|
10
11
|
* took over by liquidating.
|
|
11
12
|
**/
|
|
12
13
|
declare class PositionsService extends SDKConstruct {
|
|
14
|
+
#private;
|
|
13
15
|
/**
|
|
14
16
|
* Every position of a wallet on this chain, optionally narrowed by
|
|
15
17
|
* {@link PositionFilter} (see {@link matchesPositionFilter} for what each
|
|
@@ -17,6 +19,33 @@ declare class PositionsService extends SDKConstruct {
|
|
|
17
19
|
* the call rather than the SDK's loaded snapshot.
|
|
18
20
|
**/
|
|
19
21
|
list(props: ListPositionsProps): Promise<Position[]>;
|
|
22
|
+
/**
|
|
23
|
+
* Describes all credit accounts of a wallet as strategy positions.
|
|
24
|
+
*
|
|
25
|
+
* @param props - {@link ListStrategyPositionsProps}
|
|
26
|
+
**/
|
|
27
|
+
listStrategyPositions(props: ListStrategyPositionsProps): Promise<StrategyPosition[]>;
|
|
28
|
+
/**
|
|
29
|
+
* Health factor of an account state, in basis points (`10000` = 1.0).
|
|
30
|
+
**/
|
|
31
|
+
healthFactor(snapshot: AccountSnapshot): Bps;
|
|
32
|
+
/**
|
|
33
|
+
* Cost of an account state's debt, broken down into the pool's base rate
|
|
34
|
+
* and per-token quota rates.
|
|
35
|
+
**/
|
|
36
|
+
borrowRate(snapshot: AccountSnapshot): BorrowRateBreakdown;
|
|
37
|
+
/**
|
|
38
|
+
* Estimated milliseconds until the account's health factor decays to
|
|
39
|
+
* `10000` under its current borrow rate, or `null` when the debt carries
|
|
40
|
+
* no rate (or the account is already liquidatable).
|
|
41
|
+
**/
|
|
42
|
+
timeToLiquidation(snapshot: AccountSnapshot): bigint | null;
|
|
43
|
+
/**
|
|
44
|
+
* Price of the single non-underlying collateral at which the account
|
|
45
|
+
* becomes liquidatable, or `null` when the account holds zero or several
|
|
46
|
+
* non-underlying assets.
|
|
47
|
+
**/
|
|
48
|
+
liquidationPrice(snapshot: AccountSnapshot): bigint | null;
|
|
20
49
|
}
|
|
21
50
|
//#endregion
|
|
22
51
|
export { PositionsService };
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { Bps } from "../../model/primitives.js";
|
|
2
|
+
import { BorrowRateBreakdown } from "../../model/positions.js";
|
|
3
|
+
import "../../model/index.js";
|
|
4
|
+
import { AccountSnapshot } from "./types.js";
|
|
5
|
+
import { Address } from "viem";
|
|
6
|
+
//#region src/sdk/positions/calcBorrowRate.d.ts
|
|
7
|
+
/**
|
|
8
|
+
* Inputs of {@link calcBorrowRate}.
|
|
9
|
+
**/
|
|
10
|
+
interface CalcBorrowRateProps {
|
|
11
|
+
snapshot: AccountSnapshot;
|
|
12
|
+
/**
|
|
13
|
+
* Pool base interest rate in ray.
|
|
14
|
+
**/
|
|
15
|
+
baseInterestRate: bigint;
|
|
16
|
+
/**
|
|
17
|
+
* Credit manager interest fee in basis points.
|
|
18
|
+
**/
|
|
19
|
+
feeInterest: number;
|
|
20
|
+
/**
|
|
21
|
+
* Active quota rates in basis points. Missing keys are treated as inactive
|
|
22
|
+
* (zero contribution), but a per-token entry is still reported.
|
|
23
|
+
**/
|
|
24
|
+
quotaRates: Record<Address, Bps>;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Cost of an account state's debt, broken down into the pool's base rate and
|
|
28
|
+
* per-token quota rates.
|
|
29
|
+
*
|
|
30
|
+
* The base rate is the market's current borrow APY (the pool's base rate plus
|
|
31
|
+
* the credit manager's interest fee) — the same value `borrowApy` reports on
|
|
32
|
+
* a position; it is not recomputed for the projected pool liquidity. Quota
|
|
33
|
+
* contributions are `quotaBalance * quotaRate` with the interest fee on top,
|
|
34
|
+
* normalized against the total value (`total`, `quotas`) and against the
|
|
35
|
+
* debt (`totalOnDebt`, the rate the debt itself grows at). Formulas are in
|
|
36
|
+
* parity with the frontend's `BorrowRateUtils`.
|
|
37
|
+
**/
|
|
38
|
+
declare function calcBorrowRate(props: CalcBorrowRateProps): BorrowRateBreakdown;
|
|
39
|
+
//#endregion
|
|
40
|
+
export { CalcBorrowRateProps, calcBorrowRate };
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { Bps } from "../../model/primitives.js";
|
|
2
|
+
import "../../model/index.js";
|
|
3
|
+
import { AccountSnapshot } from "./types.js";
|
|
4
|
+
import { Address } from "viem";
|
|
5
|
+
//#region src/sdk/positions/calcHealthFactor.d.ts
|
|
6
|
+
/**
|
|
7
|
+
* Inputs of {@link calcHealthFactor}.
|
|
8
|
+
**/
|
|
9
|
+
interface CalcHealthFactorProps {
|
|
10
|
+
snapshot: AccountSnapshot;
|
|
11
|
+
/**
|
|
12
|
+
* Market underlying. Debt and quota balances are valued in this token.
|
|
13
|
+
**/
|
|
14
|
+
underlying: Address;
|
|
15
|
+
/**
|
|
16
|
+
* Token decimals. Missing keys default to 18.
|
|
17
|
+
**/
|
|
18
|
+
decimals: Record<Address, number>;
|
|
19
|
+
/**
|
|
20
|
+
* Oracle prices in 8-decimal (`PRICE_DECIMALS`) fixed point. A missing key
|
|
21
|
+
* is an unpriceable token and contributes nothing.
|
|
22
|
+
**/
|
|
23
|
+
prices: Record<Address, bigint>;
|
|
24
|
+
/**
|
|
25
|
+
* Liquidation thresholds in basis points. Missing keys are treated as 0.
|
|
26
|
+
**/
|
|
27
|
+
liquidationThresholds: Record<Address, Bps>;
|
|
28
|
+
/**
|
|
29
|
+
* Whether each token's quota is currently active. Missing keys are inactive.
|
|
30
|
+
**/
|
|
31
|
+
activeQuotas: Record<Address, boolean>;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Health factor of an account state, in basis points (`10000` = 1.0).
|
|
35
|
+
*
|
|
36
|
+
* Collateral is valued under liquidation thresholds, with quoted tokens
|
|
37
|
+
* capped by their quota, and compared against the debt's value. An account
|
|
38
|
+
* with no debt reports `65535` (`MAX_UINT16`), the contract's own sentinel
|
|
39
|
+
* scaled down. Formulas are in parity with the legacy `calcHealthFactor`.
|
|
40
|
+
* Tokens with no price in {@link CalcHealthFactorProps.prices} contribute
|
|
41
|
+
* nothing.
|
|
42
|
+
**/
|
|
43
|
+
declare function calcHealthFactor(props: CalcHealthFactorProps): Bps;
|
|
44
|
+
//#endregion
|
|
45
|
+
export { CalcHealthFactorProps, calcHealthFactor };
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { CalcLiquidationPriceProps } from "./calcLiquidationPriceForTarget.js";
|
|
2
|
+
//#region src/sdk/positions/calcLiquidationPrice.d.ts
|
|
3
|
+
/**
|
|
4
|
+
* Liquidation price of an account state's target collateral, in the oracle's
|
|
5
|
+
* 8-decimal (`PRICE_DECIMALS`) fixed point.
|
|
6
|
+
*
|
|
7
|
+
* As the frontend does, a liquidation price only exists when the account
|
|
8
|
+
* holds exactly one non-dust non-underlying asset; otherwise `null`.
|
|
9
|
+
**/
|
|
10
|
+
declare function calcLiquidationPrice(props: CalcLiquidationPriceProps): bigint | null;
|
|
11
|
+
//#endregion
|
|
12
|
+
export { calcLiquidationPrice };
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { Bps } from "../../model/primitives.js";
|
|
2
|
+
import "../../model/index.js";
|
|
3
|
+
import { AccountSnapshot } from "./types.js";
|
|
4
|
+
import { Address } from "viem";
|
|
5
|
+
//#region src/sdk/positions/calcLiquidationPriceForTarget.d.ts
|
|
6
|
+
/**
|
|
7
|
+
* Shared market-side inputs of a liquidation-price calculation.
|
|
8
|
+
**/
|
|
9
|
+
interface CalcLiquidationPriceProps {
|
|
10
|
+
snapshot: AccountSnapshot;
|
|
11
|
+
/**
|
|
12
|
+
* Market underlying. Its balance under its LT is subtracted from the debt.
|
|
13
|
+
**/
|
|
14
|
+
underlying: Address;
|
|
15
|
+
/**
|
|
16
|
+
* Token decimals. Missing keys default to 18.
|
|
17
|
+
**/
|
|
18
|
+
decimals: Record<Address, number>;
|
|
19
|
+
/**
|
|
20
|
+
* Liquidation thresholds in basis points. Missing keys are treated as 0.
|
|
21
|
+
**/
|
|
22
|
+
liquidationThresholds: Record<Address, Bps>;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Inputs of {@link calcLiquidationPriceForTarget}.
|
|
26
|
+
**/
|
|
27
|
+
interface CalcLiquidationPriceForTargetProps extends CalcLiquidationPriceProps {
|
|
28
|
+
/**
|
|
29
|
+
* Collateral token whose liquidation price to compute.
|
|
30
|
+
**/
|
|
31
|
+
targetToken: Address;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Liquidation price of an explicitly named collateral token, in
|
|
35
|
+
* `PRICE_DECIMALS` fixed point; `0n` when the account holds none of it or the
|
|
36
|
+
* token has no liquidation threshold. Formula is in parity with the legacy
|
|
37
|
+
* `liquidationPrice`: the effective debt (debt less the underlying balance's
|
|
38
|
+
* contribution under its threshold) over the threshold-weighted target
|
|
39
|
+
* balance.
|
|
40
|
+
**/
|
|
41
|
+
declare function calcLiquidationPriceForTarget(props: CalcLiquidationPriceForTargetProps): bigint;
|
|
42
|
+
//#endregion
|
|
43
|
+
export { CalcLiquidationPriceForTargetProps, CalcLiquidationPriceProps, calcLiquidationPriceForTarget };
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { Bps } from "../../model/primitives.js";
|
|
2
|
+
import "../../model/index.js";
|
|
3
|
+
//#region src/sdk/positions/calcTimeToLiquidationMs.d.ts
|
|
4
|
+
/**
|
|
5
|
+
* Estimated milliseconds until `healthFactorBps` decays to `10000` (1.0)
|
|
6
|
+
* while the debt grows at `totalBorrowRateOnDebt` (basis points relative to
|
|
7
|
+
* the debt, as {@link BorrowRateBreakdown.totalOnDebt} reports it).
|
|
8
|
+
*
|
|
9
|
+
* `null` when the account is already at or under the liquidation threshold,
|
|
10
|
+
* or when the debt carries no borrow rate at all. Formula is in parity with
|
|
11
|
+
* the legacy `getTimeToLiquidation`.
|
|
12
|
+
**/
|
|
13
|
+
declare function calcTimeToLiquidationMs(healthFactorBps: Bps, totalBorrowRateOnDebt: bigint): bigint | null;
|
|
14
|
+
//#endregion
|
|
15
|
+
export { calcTimeToLiquidationMs };
|
|
@@ -1,4 +1,9 @@
|
|
|
1
|
-
import { ListPositionsProps, ListPositionsPropsBase } from "./types.js";
|
|
1
|
+
import { AccountSnapshot, ListPositionsProps, ListPositionsPropsBase, ListStrategyPositionsProps, accountSnapshotFromCreditAccountData } from "./types.js";
|
|
2
|
+
import { CalcBorrowRateProps, calcBorrowRate } from "./calcBorrowRate.js";
|
|
3
|
+
import { CalcHealthFactorProps, calcHealthFactor } from "./calcHealthFactor.js";
|
|
4
|
+
import { CalcLiquidationPriceForTargetProps, CalcLiquidationPriceProps, calcLiquidationPriceForTarget } from "./calcLiquidationPriceForTarget.js";
|
|
5
|
+
import { calcLiquidationPrice } from "./calcLiquidationPrice.js";
|
|
6
|
+
import { calcTimeToLiquidationMs } from "./calcTimeToLiquidationMs.js";
|
|
2
7
|
import { MultichainPositionsService } from "./MultichainPositionsService.js";
|
|
3
8
|
import { PositionsService } from "./PositionsService.js";
|
|
4
|
-
export { ListPositionsProps, ListPositionsPropsBase, MultichainPositionsService, PositionsService };
|
|
9
|
+
export { AccountSnapshot, CalcBorrowRateProps, CalcHealthFactorProps, CalcLiquidationPriceForTargetProps, CalcLiquidationPriceProps, ListPositionsProps, ListPositionsPropsBase, ListStrategyPositionsProps, MultichainPositionsService, PositionsService, accountSnapshotFromCreditAccountData, calcBorrowRate, calcHealthFactor, calcLiquidationPrice, calcLiquidationPriceForTarget, calcTimeToLiquidationMs };
|
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import { WithBlock } from "../types/multichain.js";
|
|
2
|
+
import { Asset, CreditAccountData } from "../base/types.js";
|
|
2
3
|
import { PositionFilter } from "../../model/positions.js";
|
|
3
4
|
import "../../model/index.js";
|
|
4
5
|
import "../types/index.js";
|
|
6
|
+
import "../base/index.js";
|
|
5
7
|
import { Address } from "viem";
|
|
6
8
|
//#region src/sdk/positions/types.d.ts
|
|
7
9
|
/**
|
|
@@ -30,5 +32,60 @@ interface ListPositionsPropsBase {
|
|
|
30
32
|
* {@link MultichainPositionsService.list}.
|
|
31
33
|
**/
|
|
32
34
|
type ListPositionsProps<Multichain extends boolean = false> = ListPositionsPropsBase & WithBlock<Multichain>;
|
|
35
|
+
/**
|
|
36
|
+
* Props for {@link PositionsService.listStrategyPositions}.
|
|
37
|
+
**/
|
|
38
|
+
interface ListStrategyPositionsProps {
|
|
39
|
+
/**
|
|
40
|
+
* Wallet whose credit accounts to describe. RWA accounts are resolved from
|
|
41
|
+
* the investor EOA, see {@link ICreditAccountsService.getBorrowerCreditAccounts}.
|
|
42
|
+
**/
|
|
43
|
+
owner: Address;
|
|
44
|
+
/**
|
|
45
|
+
* Whether to include accounts that carry no debt.
|
|
46
|
+
**/
|
|
47
|
+
includeZeroDebt: boolean;
|
|
48
|
+
/**
|
|
49
|
+
* Block to read at. Defaults to the latest block.
|
|
50
|
+
**/
|
|
51
|
+
blockNumber?: bigint;
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* The one input every position-metric function takes: a credit account's
|
|
55
|
+
* state — its credit manager, token balances, quota holdings, total debt and
|
|
56
|
+
* total value in the market's underlying — actual or projected.
|
|
57
|
+
*
|
|
58
|
+
* Everything else (decimals, prices, liquidation thresholds, quota rates,
|
|
59
|
+
* the pool's base rate) is supplied at the calculation site.
|
|
60
|
+
**/
|
|
61
|
+
interface AccountSnapshot {
|
|
62
|
+
/**
|
|
63
|
+
* Credit manager the account is (or will be) opened in.
|
|
64
|
+
**/
|
|
65
|
+
creditManager: Address;
|
|
66
|
+
/**
|
|
67
|
+
* Token balances of the account.
|
|
68
|
+
**/
|
|
69
|
+
assets: Asset[];
|
|
70
|
+
/**
|
|
71
|
+
* Quota holdings of the account: quota balances are denominated in the
|
|
72
|
+
* market's underlying.
|
|
73
|
+
**/
|
|
74
|
+
quotas: Asset[];
|
|
75
|
+
/**
|
|
76
|
+
* Debt principal plus accrued interest and fees, in underlying.
|
|
77
|
+
**/
|
|
78
|
+
totalDebt: bigint;
|
|
79
|
+
/**
|
|
80
|
+
* Total account value in underlying.
|
|
81
|
+
**/
|
|
82
|
+
totalValue: bigint;
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Builds an {@link AccountSnapshot} from on-chain credit account data: the
|
|
86
|
+
* enabled, above-dust tokens become assets and quotas, and `totalDebt` is
|
|
87
|
+
* principal plus accrued interest and fees.
|
|
88
|
+
**/
|
|
89
|
+
declare function accountSnapshotFromCreditAccountData(ca: CreditAccountData): AccountSnapshot;
|
|
33
90
|
//#endregion
|
|
34
|
-
export { ListPositionsProps, ListPositionsPropsBase };
|
|
91
|
+
export { AccountSnapshot, ListPositionsProps, ListPositionsPropsBase, ListStrategyPositionsProps, accountSnapshotFromCreditAccountData };
|