@gearbox-protocol/sdk 15.1.0-next.6 → 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.
Files changed (106) hide show
  1. package/dist/cjs/common-utils/utils/apy/get-single-quota-borrow-rate.js +2 -0
  2. package/dist/cjs/common-utils/utils/creditAccount/calc-health-factor.js +24 -22
  3. package/dist/cjs/common-utils/utils/creditAccount/calc-quota-borrow-rate.js +2 -0
  4. package/dist/cjs/common-utils/utils/creditAccount/get-time-to-liquidation.js +5 -4
  5. package/dist/cjs/common-utils/utils/creditAccount/liquidation-price.js +21 -11
  6. package/dist/cjs/model/index.js +1 -0
  7. package/dist/cjs/model/positions.schema.js +13 -0
  8. package/dist/cjs/preview/preview/CreditAccountState.js +14 -1
  9. package/dist/cjs/preview/preview/buildDelayedPreview.js +16 -6
  10. package/dist/cjs/preview/preview/previewAdjustCreditAccount.js +9 -2
  11. package/dist/cjs/preview/preview/previewOpenCreditAccount.js +11 -3
  12. package/dist/cjs/preview/preview/previewOperation.js +1 -1
  13. package/dist/cjs/sdk/accounts/CreditAccountsServiceV310.js +0 -6
  14. package/dist/cjs/sdk/accounts/credit-account-compressor/CreditAccountCompressor.js +2 -90
  15. package/dist/cjs/sdk/accounts/intents/testing/sdk-mock.js +31 -4
  16. package/dist/cjs/sdk/accounts/intents/utils/adjust-state-to-snapshot.js +18 -0
  17. package/dist/cjs/sdk/accounts/intents/utils/index.js +2 -0
  18. package/dist/cjs/sdk/accounts/liquidations/LiquidationsService.js +0 -3
  19. package/dist/cjs/sdk/index.js +12 -0
  20. package/dist/cjs/sdk/market/oracle/PriceOracleBaseContract.js +10 -3
  21. package/dist/cjs/sdk/positions/PositionsService.js +206 -1
  22. package/dist/cjs/sdk/positions/calcBorrowRate.js +43 -0
  23. package/dist/cjs/sdk/positions/calcHealthFactor.js +44 -0
  24. package/dist/cjs/sdk/positions/calcLiquidationPrice.js +23 -0
  25. package/dist/cjs/sdk/positions/calcLiquidationPriceForTarget.js +30 -0
  26. package/dist/cjs/sdk/positions/calcTimeToLiquidationMs.js +18 -0
  27. package/dist/cjs/sdk/positions/index.js +12 -1
  28. package/dist/cjs/sdk/positions/types.js +31 -0
  29. package/dist/esm/common-utils/utils/apy/get-single-quota-borrow-rate.js +2 -0
  30. package/dist/esm/common-utils/utils/creditAccount/calc-health-factor.js +24 -22
  31. package/dist/esm/common-utils/utils/creditAccount/calc-quota-borrow-rate.js +2 -0
  32. package/dist/esm/common-utils/utils/creditAccount/get-time-to-liquidation.js +5 -4
  33. package/dist/esm/common-utils/utils/creditAccount/liquidation-price.js +21 -11
  34. package/dist/esm/dev/AccountOpener.js +1 -1
  35. package/dist/esm/dev/withdrawalUtils.js +1 -1
  36. package/dist/esm/model/index.js +2 -2
  37. package/dist/esm/model/positions.schema.js +14 -2
  38. package/dist/esm/plugins/adapters/contracts/ERC4626AdapterContract.js +1 -1
  39. package/dist/esm/preview/preview/CreditAccountState.js +14 -1
  40. package/dist/esm/preview/preview/buildDelayedPreview.js +16 -6
  41. package/dist/esm/preview/preview/previewAdjustCreditAccount.js +9 -2
  42. package/dist/esm/preview/preview/previewOpenCreditAccount.js +11 -3
  43. package/dist/esm/preview/preview/previewOperation.js +1 -1
  44. package/dist/esm/preview/simulate/simulatePoolOperation.js +1 -1
  45. package/dist/esm/preview/trace/extractTransfers.js +1 -1
  46. package/dist/esm/sdk/accounts/CreditAccountsServiceV310.js +2 -8
  47. package/dist/esm/sdk/accounts/credit-account-compressor/CreditAccountCompressor.js +2 -90
  48. package/dist/esm/sdk/accounts/intents/testing/sdk-mock.js +31 -4
  49. package/dist/esm/sdk/accounts/intents/utils/adjust-state-to-snapshot.js +17 -0
  50. package/dist/esm/sdk/accounts/intents/utils/index.js +2 -1
  51. package/dist/esm/sdk/accounts/liquidations/LiquidationsService.js +1 -4
  52. package/dist/esm/sdk/accounts/withdrawal-compressor/RedemptionLoggerV310Contract.js +1 -1
  53. package/dist/esm/sdk/accounts/withdrawal-compressor/WithdrawalCompressorV310Contract.js +1 -1
  54. package/dist/esm/sdk/accounts/withdrawal-compressor/WithdrawalCompressorV311Contract.js +1 -1
  55. package/dist/esm/sdk/accounts/withdrawal-compressor/WithdrawalCompressorV313Contract.js +1 -1
  56. package/dist/esm/sdk/base/TokensMeta.js +3 -3
  57. package/dist/esm/sdk/chain/detectNetwork.js +1 -1
  58. package/dist/esm/sdk/core/createAddressProvider.js +1 -1
  59. package/dist/esm/sdk/index.js +7 -1
  60. package/dist/esm/sdk/market/credit/CreditFacadeV310BaseContract.js +1 -1
  61. package/dist/esm/sdk/market/oracle/PriceOracleBaseContract.js +10 -3
  62. package/dist/esm/sdk/market/pool/PoolV310Contract.js +1 -1
  63. package/dist/esm/sdk/market/zapper/IETHZapperContract.js +1 -1
  64. package/dist/esm/sdk/market/zapper/ZapperContract.js +1 -1
  65. package/dist/esm/sdk/pools/PoolService.js +1 -1
  66. package/dist/esm/sdk/positions/PositionsService.js +206 -1
  67. package/dist/esm/sdk/positions/calcBorrowRate.js +42 -0
  68. package/dist/esm/sdk/positions/calcHealthFactor.js +43 -0
  69. package/dist/esm/sdk/positions/calcLiquidationPrice.js +22 -0
  70. package/dist/esm/sdk/positions/calcLiquidationPriceForTarget.js +29 -0
  71. package/dist/esm/sdk/positions/calcTimeToLiquidationMs.js +17 -0
  72. package/dist/esm/sdk/positions/index.js +7 -2
  73. package/dist/esm/sdk/positions/types.js +31 -1
  74. package/dist/esm/sdk/utils/viem/simulateWithPriceUpdates.js +1 -1
  75. package/dist/types/common-utils/utils/apy/get-single-quota-borrow-rate.d.ts +2 -0
  76. package/dist/types/common-utils/utils/creditAccount/calc-health-factor.d.ts +3 -0
  77. package/dist/types/common-utils/utils/creditAccount/calc-quota-borrow-rate.d.ts +2 -0
  78. package/dist/types/common-utils/utils/creditAccount/get-time-to-liquidation.d.ts +3 -0
  79. package/dist/types/common-utils/utils/creditAccount/liquidation-price.d.ts +3 -0
  80. package/dist/types/model/index.d.ts +3 -3
  81. package/dist/types/model/positions.d.ts +84 -1
  82. package/dist/types/model/positions.schema.d.ts +26 -1
  83. package/dist/types/preview/preview/CreditAccountState.d.ts +6 -0
  84. package/dist/types/preview/preview/buildDelayedPreview.d.ts +5 -1
  85. package/dist/types/preview/preview/types.d.ts +4 -2
  86. package/dist/types/sdk/accounts/CreditAccountsServiceV310.d.ts +1 -7
  87. package/dist/types/sdk/accounts/credit-account-compressor/CreditAccountCompressor.d.ts +3 -12
  88. package/dist/types/sdk/accounts/credit-account-compressor/index.d.ts +2 -2
  89. package/dist/types/sdk/accounts/credit-account-compressor/types.d.ts +1 -19
  90. package/dist/types/sdk/accounts/index.d.ts +2 -2
  91. package/dist/types/sdk/accounts/intents/testing/sdk-mock.d.ts +6 -0
  92. package/dist/types/sdk/accounts/intents/utils/adjust-state-to-snapshot.d.ts +13 -0
  93. package/dist/types/sdk/accounts/intents/utils/index.d.ts +2 -1
  94. package/dist/types/sdk/accounts/types.d.ts +1 -12
  95. package/dist/types/sdk/index.d.ts +8 -3
  96. package/dist/types/sdk/market/oracle/PriceOracleBaseContract.d.ts +4 -0
  97. package/dist/types/sdk/market/oracle/types.d.ts +8 -0
  98. package/dist/types/sdk/positions/PositionsService.d.ts +31 -2
  99. package/dist/types/sdk/positions/calcBorrowRate.d.ts +40 -0
  100. package/dist/types/sdk/positions/calcHealthFactor.d.ts +45 -0
  101. package/dist/types/sdk/positions/calcLiquidationPrice.d.ts +12 -0
  102. package/dist/types/sdk/positions/calcLiquidationPriceForTarget.d.ts +43 -0
  103. package/dist/types/sdk/positions/calcTimeToLiquidationMs.d.ts +15 -0
  104. package/dist/types/sdk/positions/index.d.ts +7 -2
  105. package/dist/types/sdk/positions/types.d.ts +58 -1
  106. package/package.json +1 -1
@@ -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 };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gearbox-protocol/sdk",
3
- "version": "15.1.0-next.6",
3
+ "version": "15.1.0-next.7",
4
4
  "description": "Gearbox SDK",
5
5
  "license": "MIT",
6
6
  "repository": {