@gearbox-protocol/sdk 15.1.0-next.5 → 15.1.0-next.6
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/sdk/accounts/credit-account-compressor/CreditAccountCompressor.js +2 -2
- package/dist/cjs/sdk/index.js +9 -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/pool/PoolV310Contract.js +1 -1
- package/dist/cjs/sdk/opportunities/index.js +0 -13
- package/dist/esm/sdk/accounts/credit-account-compressor/CreditAccountCompressor.js +3 -3
- package/dist/esm/sdk/index.js +3 -2
- 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/pool/PoolV310Contract.js +2 -2
- package/dist/esm/sdk/opportunities/index.js +1 -2
- package/dist/types/model/opportunities.d.ts +9 -9
- package/dist/types/model/positions.d.ts +3 -3
- package/dist/types/sdk/index.d.ts +3 -2
- 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/opportunities/index.d.ts +1 -2
- package/package.json +1 -1
|
@@ -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 };
|
|
@@ -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 };
|