@gearbox-protocol/sdk 15.1.0-next.6 → 15.1.0-next.8

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 (147) 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/charts.js +147 -0
  7. package/dist/cjs/model/charts.schema.js +240 -0
  8. package/dist/cjs/model/index.js +28 -22
  9. package/dist/cjs/model/liquidations.schema.js +1 -1
  10. package/dist/cjs/model/opportunities.schema.js +1 -1
  11. package/dist/cjs/model/positions.schema.js +15 -2
  12. package/dist/cjs/new-sdk/opportunities/OpportunitiesNamespace.js +2 -6
  13. package/dist/cjs/new-sdk/positions/PositionsNamespace.js +2 -6
  14. package/dist/cjs/new-sdk/utils/index.js +0 -1
  15. package/dist/cjs/offchain/AbstractOffchainNamespace.js +10 -7
  16. package/dist/cjs/offchain/opportunities/OffchainOpportunities.js +4 -8
  17. package/dist/cjs/offchain/positions/OffchainPositions.js +8 -11
  18. package/dist/cjs/preview/preview/CreditAccountState.js +14 -1
  19. package/dist/cjs/preview/preview/buildDelayedPreview.js +16 -6
  20. package/dist/cjs/preview/preview/previewAdjustCreditAccount.js +9 -2
  21. package/dist/cjs/preview/preview/previewOpenCreditAccount.js +11 -3
  22. package/dist/cjs/preview/preview/previewOperation.js +1 -1
  23. package/dist/cjs/sdk/accounts/CreditAccountsServiceV310.js +0 -6
  24. package/dist/cjs/sdk/accounts/credit-account-compressor/CreditAccountCompressor.js +2 -90
  25. package/dist/cjs/sdk/accounts/intents/testing/sdk-mock.js +31 -4
  26. package/dist/cjs/sdk/accounts/intents/utils/adjust-state-to-snapshot.js +18 -0
  27. package/dist/cjs/sdk/accounts/intents/utils/index.js +2 -0
  28. package/dist/cjs/sdk/accounts/liquidations/LiquidationsService.js +0 -3
  29. package/dist/cjs/sdk/index.js +12 -0
  30. package/dist/cjs/sdk/market/oracle/PriceOracleBaseContract.js +10 -3
  31. package/dist/cjs/sdk/positions/PositionsService.js +206 -1
  32. package/dist/cjs/sdk/positions/calcBorrowRate.js +43 -0
  33. package/dist/cjs/sdk/positions/calcHealthFactor.js +44 -0
  34. package/dist/cjs/sdk/positions/calcLiquidationPrice.js +23 -0
  35. package/dist/cjs/sdk/positions/calcLiquidationPriceForTarget.js +30 -0
  36. package/dist/cjs/sdk/positions/calcTimeToLiquidationMs.js +18 -0
  37. package/dist/cjs/sdk/positions/index.js +12 -1
  38. package/dist/cjs/sdk/positions/types.js +31 -0
  39. package/dist/esm/common-utils/utils/apy/get-single-quota-borrow-rate.js +2 -0
  40. package/dist/esm/common-utils/utils/creditAccount/calc-health-factor.js +24 -22
  41. package/dist/esm/common-utils/utils/creditAccount/calc-quota-borrow-rate.js +2 -0
  42. package/dist/esm/common-utils/utils/creditAccount/get-time-to-liquidation.js +5 -4
  43. package/dist/esm/common-utils/utils/creditAccount/liquidation-price.js +21 -11
  44. package/dist/esm/dev/AccountOpener.js +1 -1
  45. package/dist/esm/dev/withdrawalUtils.js +1 -1
  46. package/dist/esm/model/charts.js +140 -0
  47. package/dist/esm/model/charts.schema.js +226 -0
  48. package/dist/esm/model/index.js +7 -7
  49. package/dist/esm/model/liquidations.schema.js +1 -1
  50. package/dist/esm/model/opportunities.schema.js +1 -1
  51. package/dist/esm/model/positions.schema.js +16 -4
  52. package/dist/esm/new-sdk/opportunities/OpportunitiesNamespace.js +2 -6
  53. package/dist/esm/new-sdk/positions/PositionsNamespace.js +2 -6
  54. package/dist/esm/new-sdk/utils/index.js +0 -1
  55. package/dist/esm/offchain/AbstractOffchainNamespace.js +10 -7
  56. package/dist/esm/offchain/opportunities/OffchainOpportunities.js +4 -8
  57. package/dist/esm/offchain/positions/OffchainPositions.js +8 -11
  58. package/dist/esm/plugins/adapters/contracts/ERC4626AdapterContract.js +1 -1
  59. package/dist/esm/preview/preview/CreditAccountState.js +14 -1
  60. package/dist/esm/preview/preview/buildDelayedPreview.js +16 -6
  61. package/dist/esm/preview/preview/previewAdjustCreditAccount.js +9 -2
  62. package/dist/esm/preview/preview/previewOpenCreditAccount.js +11 -3
  63. package/dist/esm/preview/preview/previewOperation.js +1 -1
  64. package/dist/esm/preview/simulate/simulatePoolOperation.js +1 -1
  65. package/dist/esm/preview/trace/extractTransfers.js +1 -1
  66. package/dist/esm/sdk/accounts/CreditAccountsServiceV310.js +2 -8
  67. package/dist/esm/sdk/accounts/credit-account-compressor/CreditAccountCompressor.js +2 -90
  68. package/dist/esm/sdk/accounts/intents/testing/sdk-mock.js +31 -4
  69. package/dist/esm/sdk/accounts/intents/utils/adjust-state-to-snapshot.js +17 -0
  70. package/dist/esm/sdk/accounts/intents/utils/index.js +2 -1
  71. package/dist/esm/sdk/accounts/liquidations/LiquidationsService.js +1 -4
  72. package/dist/esm/sdk/accounts/withdrawal-compressor/RedemptionLoggerV310Contract.js +1 -1
  73. package/dist/esm/sdk/accounts/withdrawal-compressor/WithdrawalCompressorV310Contract.js +1 -1
  74. package/dist/esm/sdk/accounts/withdrawal-compressor/WithdrawalCompressorV311Contract.js +1 -1
  75. package/dist/esm/sdk/accounts/withdrawal-compressor/WithdrawalCompressorV313Contract.js +1 -1
  76. package/dist/esm/sdk/base/TokensMeta.js +3 -3
  77. package/dist/esm/sdk/chain/detectNetwork.js +1 -1
  78. package/dist/esm/sdk/core/createAddressProvider.js +1 -1
  79. package/dist/esm/sdk/index.js +7 -1
  80. package/dist/esm/sdk/market/credit/CreditFacadeV310BaseContract.js +1 -1
  81. package/dist/esm/sdk/market/oracle/PriceOracleBaseContract.js +10 -3
  82. package/dist/esm/sdk/market/pool/PoolV310Contract.js +1 -1
  83. package/dist/esm/sdk/market/zapper/IETHZapperContract.js +1 -1
  84. package/dist/esm/sdk/market/zapper/ZapperContract.js +1 -1
  85. package/dist/esm/sdk/pools/PoolService.js +1 -1
  86. package/dist/esm/sdk/positions/PositionsService.js +206 -1
  87. package/dist/esm/sdk/positions/calcBorrowRate.js +42 -0
  88. package/dist/esm/sdk/positions/calcHealthFactor.js +43 -0
  89. package/dist/esm/sdk/positions/calcLiquidationPrice.js +22 -0
  90. package/dist/esm/sdk/positions/calcLiquidationPriceForTarget.js +29 -0
  91. package/dist/esm/sdk/positions/calcTimeToLiquidationMs.js +17 -0
  92. package/dist/esm/sdk/positions/index.js +7 -2
  93. package/dist/esm/sdk/positions/types.js +31 -1
  94. package/dist/esm/sdk/utils/viem/simulateWithPriceUpdates.js +1 -1
  95. package/dist/types/common-utils/utils/apy/get-single-quota-borrow-rate.d.ts +2 -0
  96. package/dist/types/common-utils/utils/creditAccount/calc-health-factor.d.ts +3 -0
  97. package/dist/types/common-utils/utils/creditAccount/calc-quota-borrow-rate.d.ts +2 -0
  98. package/dist/types/common-utils/utils/creditAccount/get-time-to-liquidation.d.ts +3 -0
  99. package/dist/types/common-utils/utils/creditAccount/liquidation-price.d.ts +3 -0
  100. package/dist/types/model/charts.d.ts +349 -0
  101. package/dist/types/model/charts.schema.d.ts +364 -0
  102. package/dist/types/model/index.d.ts +6 -6
  103. package/dist/types/model/positions.d.ts +85 -2
  104. package/dist/types/model/positions.schema.d.ts +26 -1
  105. package/dist/types/new-sdk/index.d.ts +1 -2
  106. package/dist/types/new-sdk/opportunities/OpportunitiesNamespace.d.ts +4 -5
  107. package/dist/types/new-sdk/opportunities/types.d.ts +9 -7
  108. package/dist/types/new-sdk/positions/PositionsNamespace.d.ts +4 -5
  109. package/dist/types/new-sdk/positions/types.d.ts +9 -9
  110. package/dist/types/new-sdk/utils/index.d.ts +1 -2
  111. package/dist/types/offchain/AbstractOffchainNamespace.d.ts +5 -21
  112. package/dist/types/offchain/index.d.ts +2 -2
  113. package/dist/types/offchain/opportunities/OffchainOpportunities.d.ts +8 -4
  114. package/dist/types/offchain/positions/OffchainPositions.d.ts +11 -5
  115. package/dist/types/preview/preview/CreditAccountState.d.ts +6 -0
  116. package/dist/types/preview/preview/buildDelayedPreview.d.ts +5 -1
  117. package/dist/types/preview/preview/types.d.ts +4 -2
  118. package/dist/types/sdk/accounts/CreditAccountsServiceV310.d.ts +1 -7
  119. package/dist/types/sdk/accounts/credit-account-compressor/CreditAccountCompressor.d.ts +3 -12
  120. package/dist/types/sdk/accounts/credit-account-compressor/index.d.ts +2 -2
  121. package/dist/types/sdk/accounts/credit-account-compressor/types.d.ts +1 -19
  122. package/dist/types/sdk/accounts/index.d.ts +2 -2
  123. package/dist/types/sdk/accounts/intents/testing/sdk-mock.d.ts +6 -0
  124. package/dist/types/sdk/accounts/intents/utils/adjust-state-to-snapshot.d.ts +13 -0
  125. package/dist/types/sdk/accounts/intents/utils/index.d.ts +2 -1
  126. package/dist/types/sdk/accounts/types.d.ts +1 -12
  127. package/dist/types/sdk/index.d.ts +8 -3
  128. package/dist/types/sdk/market/oracle/PriceOracleBaseContract.d.ts +4 -0
  129. package/dist/types/sdk/market/oracle/types.d.ts +8 -0
  130. package/dist/types/sdk/positions/PositionsService.d.ts +31 -2
  131. package/dist/types/sdk/positions/calcBorrowRate.d.ts +40 -0
  132. package/dist/types/sdk/positions/calcHealthFactor.d.ts +45 -0
  133. package/dist/types/sdk/positions/calcLiquidationPrice.d.ts +12 -0
  134. package/dist/types/sdk/positions/calcLiquidationPriceForTarget.d.ts +43 -0
  135. package/dist/types/sdk/positions/calcTimeToLiquidationMs.d.ts +15 -0
  136. package/dist/types/sdk/positions/index.d.ts +7 -2
  137. package/dist/types/sdk/positions/types.d.ts +58 -1
  138. package/package.json +1 -1
  139. package/dist/cjs/model/history.js +0 -53
  140. package/dist/cjs/model/history.schema.js +0 -128
  141. package/dist/cjs/new-sdk/utils/history.js +0 -1
  142. package/dist/esm/model/history.js +0 -49
  143. package/dist/esm/model/history.schema.js +0 -116
  144. package/dist/esm/new-sdk/utils/history.js +0 -1
  145. package/dist/types/model/history.d.ts +0 -153
  146. package/dist/types/model/history.schema.d.ts +0 -95
  147. package/dist/types/new-sdk/utils/history.d.ts +0 -18
@@ -1,6 +1,7 @@
1
- import { Position } from "../../model/positions.js";
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 };
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.8",
4
4
  "description": "Gearbox SDK",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -1,53 +0,0 @@
1
- Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
- //#region src/model/history.ts
3
- /**
4
- * Every {@link PoolHistoryMetric}, for callers that enumerate them.
5
- **/
6
- const POOL_HISTORY_METRICS = [
7
- "depositApy",
8
- "borrowApy",
9
- "dieselRate",
10
- "supplied",
11
- "borrowed",
12
- "availableLiquidity"
13
- ];
14
- /**
15
- * Every {@link StrategyHistoryMetric}, for callers that enumerate them.
16
- **/
17
- const STRATEGY_HISTORY_METRICS = [
18
- "netApy",
19
- "borrowApy",
20
- "collateralApy",
21
- "tvl",
22
- "collateralPrice",
23
- "collateralUsdPrice",
24
- "underlyingUsdPrice"
25
- ];
26
- /**
27
- * Every {@link PoolPositionHistoryMetric}, for callers that enumerate them.
28
- **/
29
- const POOL_POSITION_HISTORY_METRICS = [
30
- "depositApy",
31
- "borrowApy",
32
- "dieselRate",
33
- "supplied",
34
- "borrowed",
35
- "availableLiquidity"
36
- ];
37
- /**
38
- * Every {@link StrategyPositionHistoryMetric}, for callers that enumerate them.
39
- **/
40
- const STRATEGY_POSITION_HISTORY_METRICS = [
41
- "netApy",
42
- "borrowApy",
43
- "collateralApy",
44
- "tvl",
45
- "collateralPrice",
46
- "collateralUsdPrice",
47
- "underlyingUsdPrice"
48
- ];
49
- //#endregion
50
- exports.POOL_HISTORY_METRICS = POOL_HISTORY_METRICS;
51
- exports.POOL_POSITION_HISTORY_METRICS = POOL_POSITION_HISTORY_METRICS;
52
- exports.STRATEGY_HISTORY_METRICS = STRATEGY_HISTORY_METRICS;
53
- exports.STRATEGY_POSITION_HISTORY_METRICS = STRATEGY_POSITION_HISTORY_METRICS;
@@ -1,128 +0,0 @@
1
- Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
- const require_model_primitives_schema = require("./primitives.schema.js");
3
- const require_model_opportunities_schema = require("./opportunities.schema.js");
4
- const require_model_positions_schema = require("./positions.schema.js");
5
- let zod_v4 = require("zod/v4");
6
- //#region src/model/history.schema.ts
7
- /**
8
- * Runtime schemas for {@link ./history.js}, see the note in
9
- * `primitives.schema.ts` on why they are written by hand.
10
- **/
11
- /**
12
- * {@link HistoryRange}
13
- **/
14
- const historyRangeSchema = zod_v4.z.union([
15
- zod_v4.z.literal("1d"),
16
- zod_v4.z.literal("1w"),
17
- zod_v4.z.literal("1m"),
18
- zod_v4.z.literal("1y"),
19
- zod_v4.z.literal("max")
20
- ]);
21
- /**
22
- * {@link PoolHistoryMetric}
23
- **/
24
- const poolHistoryMetricSchema = zod_v4.z.union([
25
- zod_v4.z.literal("depositApy"),
26
- zod_v4.z.literal("borrowApy"),
27
- zod_v4.z.literal("dieselRate"),
28
- zod_v4.z.literal("supplied"),
29
- zod_v4.z.literal("borrowed"),
30
- zod_v4.z.literal("availableLiquidity")
31
- ]);
32
- /**
33
- * {@link StrategyHistoryMetric}
34
- **/
35
- const strategyHistoryMetricSchema = zod_v4.z.union([
36
- zod_v4.z.literal("netApy"),
37
- zod_v4.z.literal("borrowApy"),
38
- zod_v4.z.literal("collateralApy"),
39
- zod_v4.z.literal("tvl"),
40
- zod_v4.z.literal("collateralPrice"),
41
- zod_v4.z.literal("collateralUsdPrice"),
42
- zod_v4.z.literal("underlyingUsdPrice")
43
- ]);
44
- /**
45
- * {@link PoolPositionHistoryMetric}
46
- **/
47
- const poolPositionHistoryMetricSchema = zod_v4.z.union([
48
- zod_v4.z.literal("depositApy"),
49
- zod_v4.z.literal("borrowApy"),
50
- zod_v4.z.literal("dieselRate"),
51
- zod_v4.z.literal("supplied"),
52
- zod_v4.z.literal("borrowed"),
53
- zod_v4.z.literal("availableLiquidity")
54
- ]);
55
- /**
56
- * {@link StrategyPositionHistoryMetric}
57
- **/
58
- const strategyPositionHistoryMetricSchema = zod_v4.z.union([
59
- zod_v4.z.literal("netApy"),
60
- zod_v4.z.literal("borrowApy"),
61
- zod_v4.z.literal("collateralApy"),
62
- zod_v4.z.literal("tvl"),
63
- zod_v4.z.literal("collateralPrice"),
64
- zod_v4.z.literal("collateralUsdPrice"),
65
- zod_v4.z.literal("underlyingUsdPrice")
66
- ]);
67
- /**
68
- * {@link PositionHistoryMetric}
69
- **/
70
- const positionHistoryMetricSchema = zod_v4.z.union([poolPositionHistoryMetricSchema, strategyPositionHistoryMetricSchema]);
71
- /**
72
- * {@link HistoryMetric}
73
- **/
74
- const historyMetricSchema = zod_v4.z.union([
75
- poolHistoryMetricSchema,
76
- strategyHistoryMetricSchema,
77
- positionHistoryMetricSchema
78
- ]);
79
- /**
80
- * {@link HistoryPoint}
81
- **/
82
- const historyPointSchema = zod_v4.z.object({
83
- timestamp: require_model_primitives_schema.timestampSchema,
84
- value: zod_v4.z.number()
85
- });
86
- /**
87
- * {@link HistoryChartMetadata}
88
- *
89
- * TODO: empty until the backend specifies the payload.
90
- **/
91
- const historyChartMetadataSchema = zod_v4.z.object({});
92
- /**
93
- * {@link HistorySeries}
94
- **/
95
- const historySeriesSchema = zod_v4.z.object({
96
- metric: historyMetricSchema,
97
- points: zod_v4.z.array(historyPointSchema),
98
- metadata: historyChartMetadataSchema
99
- });
100
- /**
101
- * {@link OpportunityHistoryQuery}
102
- **/
103
- const opportunityHistoryQuerySchema = zod_v4.z.object({
104
- opportunity: require_model_opportunities_schema.opportunityKeySchema,
105
- range: historyRangeSchema,
106
- metric: historyMetricSchema
107
- });
108
- /**
109
- * {@link PositionHistoryQuery}
110
- **/
111
- const positionHistoryQuerySchema = zod_v4.z.object({
112
- position: require_model_positions_schema.positionKeySchema,
113
- range: historyRangeSchema,
114
- metric: positionHistoryMetricSchema
115
- });
116
- //#endregion
117
- exports.historyChartMetadataSchema = historyChartMetadataSchema;
118
- exports.historyMetricSchema = historyMetricSchema;
119
- exports.historyPointSchema = historyPointSchema;
120
- exports.historyRangeSchema = historyRangeSchema;
121
- exports.historySeriesSchema = historySeriesSchema;
122
- exports.opportunityHistoryQuerySchema = opportunityHistoryQuerySchema;
123
- exports.poolHistoryMetricSchema = poolHistoryMetricSchema;
124
- exports.poolPositionHistoryMetricSchema = poolPositionHistoryMetricSchema;
125
- exports.positionHistoryMetricSchema = positionHistoryMetricSchema;
126
- exports.positionHistoryQuerySchema = positionHistoryQuerySchema;
127
- exports.strategyHistoryMetricSchema = strategyHistoryMetricSchema;
128
- exports.strategyPositionHistoryMetricSchema = strategyPositionHistoryMetricSchema;
@@ -1 +0,0 @@
1
- Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
@@ -1,49 +0,0 @@
1
- //#region src/model/history.ts
2
- /**
3
- * Every {@link PoolHistoryMetric}, for callers that enumerate them.
4
- **/
5
- const POOL_HISTORY_METRICS = [
6
- "depositApy",
7
- "borrowApy",
8
- "dieselRate",
9
- "supplied",
10
- "borrowed",
11
- "availableLiquidity"
12
- ];
13
- /**
14
- * Every {@link StrategyHistoryMetric}, for callers that enumerate them.
15
- **/
16
- const STRATEGY_HISTORY_METRICS = [
17
- "netApy",
18
- "borrowApy",
19
- "collateralApy",
20
- "tvl",
21
- "collateralPrice",
22
- "collateralUsdPrice",
23
- "underlyingUsdPrice"
24
- ];
25
- /**
26
- * Every {@link PoolPositionHistoryMetric}, for callers that enumerate them.
27
- **/
28
- const POOL_POSITION_HISTORY_METRICS = [
29
- "depositApy",
30
- "borrowApy",
31
- "dieselRate",
32
- "supplied",
33
- "borrowed",
34
- "availableLiquidity"
35
- ];
36
- /**
37
- * Every {@link StrategyPositionHistoryMetric}, for callers that enumerate them.
38
- **/
39
- const STRATEGY_POSITION_HISTORY_METRICS = [
40
- "netApy",
41
- "borrowApy",
42
- "collateralApy",
43
- "tvl",
44
- "collateralPrice",
45
- "collateralUsdPrice",
46
- "underlyingUsdPrice"
47
- ];
48
- //#endregion
49
- export { POOL_HISTORY_METRICS, POOL_POSITION_HISTORY_METRICS, STRATEGY_HISTORY_METRICS, STRATEGY_POSITION_HISTORY_METRICS };
@@ -1,116 +0,0 @@
1
- import { timestampSchema } from "./primitives.schema.js";
2
- import { opportunityKeySchema } from "./opportunities.schema.js";
3
- import { positionKeySchema } from "./positions.schema.js";
4
- import { z } from "zod/v4";
5
- //#region src/model/history.schema.ts
6
- /**
7
- * Runtime schemas for {@link ./history.js}, see the note in
8
- * `primitives.schema.ts` on why they are written by hand.
9
- **/
10
- /**
11
- * {@link HistoryRange}
12
- **/
13
- const historyRangeSchema = z.union([
14
- z.literal("1d"),
15
- z.literal("1w"),
16
- z.literal("1m"),
17
- z.literal("1y"),
18
- z.literal("max")
19
- ]);
20
- /**
21
- * {@link PoolHistoryMetric}
22
- **/
23
- const poolHistoryMetricSchema = z.union([
24
- z.literal("depositApy"),
25
- z.literal("borrowApy"),
26
- z.literal("dieselRate"),
27
- z.literal("supplied"),
28
- z.literal("borrowed"),
29
- z.literal("availableLiquidity")
30
- ]);
31
- /**
32
- * {@link StrategyHistoryMetric}
33
- **/
34
- const strategyHistoryMetricSchema = z.union([
35
- z.literal("netApy"),
36
- z.literal("borrowApy"),
37
- z.literal("collateralApy"),
38
- z.literal("tvl"),
39
- z.literal("collateralPrice"),
40
- z.literal("collateralUsdPrice"),
41
- z.literal("underlyingUsdPrice")
42
- ]);
43
- /**
44
- * {@link PoolPositionHistoryMetric}
45
- **/
46
- const poolPositionHistoryMetricSchema = z.union([
47
- z.literal("depositApy"),
48
- z.literal("borrowApy"),
49
- z.literal("dieselRate"),
50
- z.literal("supplied"),
51
- z.literal("borrowed"),
52
- z.literal("availableLiquidity")
53
- ]);
54
- /**
55
- * {@link StrategyPositionHistoryMetric}
56
- **/
57
- const strategyPositionHistoryMetricSchema = z.union([
58
- z.literal("netApy"),
59
- z.literal("borrowApy"),
60
- z.literal("collateralApy"),
61
- z.literal("tvl"),
62
- z.literal("collateralPrice"),
63
- z.literal("collateralUsdPrice"),
64
- z.literal("underlyingUsdPrice")
65
- ]);
66
- /**
67
- * {@link PositionHistoryMetric}
68
- **/
69
- const positionHistoryMetricSchema = z.union([poolPositionHistoryMetricSchema, strategyPositionHistoryMetricSchema]);
70
- /**
71
- * {@link HistoryMetric}
72
- **/
73
- const historyMetricSchema = z.union([
74
- poolHistoryMetricSchema,
75
- strategyHistoryMetricSchema,
76
- positionHistoryMetricSchema
77
- ]);
78
- /**
79
- * {@link HistoryPoint}
80
- **/
81
- const historyPointSchema = z.object({
82
- timestamp: timestampSchema,
83
- value: z.number()
84
- });
85
- /**
86
- * {@link HistoryChartMetadata}
87
- *
88
- * TODO: empty until the backend specifies the payload.
89
- **/
90
- const historyChartMetadataSchema = z.object({});
91
- /**
92
- * {@link HistorySeries}
93
- **/
94
- const historySeriesSchema = z.object({
95
- metric: historyMetricSchema,
96
- points: z.array(historyPointSchema),
97
- metadata: historyChartMetadataSchema
98
- });
99
- /**
100
- * {@link OpportunityHistoryQuery}
101
- **/
102
- const opportunityHistoryQuerySchema = z.object({
103
- opportunity: opportunityKeySchema,
104
- range: historyRangeSchema,
105
- metric: historyMetricSchema
106
- });
107
- /**
108
- * {@link PositionHistoryQuery}
109
- **/
110
- const positionHistoryQuerySchema = z.object({
111
- position: positionKeySchema,
112
- range: historyRangeSchema,
113
- metric: positionHistoryMetricSchema
114
- });
115
- //#endregion
116
- export { historyChartMetadataSchema, historyMetricSchema, historyPointSchema, historyRangeSchema, historySeriesSchema, opportunityHistoryQuerySchema, poolHistoryMetricSchema, poolPositionHistoryMetricSchema, positionHistoryMetricSchema, positionHistoryQuerySchema, strategyHistoryMetricSchema, strategyPositionHistoryMetricSchema };
@@ -1 +0,0 @@
1
- export {};