@gearbox-protocol/sdk 14.12.0-next.67 → 14.12.0-next.69

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 (53) hide show
  1. package/dist/cjs/model/index.js +13 -0
  2. package/dist/cjs/model/liquidations.schema.js +3 -1
  3. package/dist/cjs/model/opportunities.schema.js +10 -7
  4. package/dist/cjs/model/positions.schema.js +120 -0
  5. package/dist/cjs/sdk/accounts/liquidations/LiquidationsService.js +19 -8
  6. package/dist/cjs/sdk/market/MarketSuite.js +8 -12
  7. package/dist/cjs/sdk/market/credit/CreditSuite.js +4 -14
  8. package/dist/cjs/sdk/opportunities/OpportunitiesService.js +8 -63
  9. package/dist/cjs/sdk/router/RouterV310Contract.js +34 -0
  10. package/dist/esm/dev/AccountOpener.js +1 -1
  11. package/dist/esm/dev/withdrawalUtils.js +1 -1
  12. package/dist/esm/model/index.js +3 -1
  13. package/dist/esm/model/liquidations.schema.js +3 -1
  14. package/dist/esm/model/opportunities.schema.js +10 -7
  15. package/dist/esm/model/positions.schema.js +109 -0
  16. package/dist/esm/preview/simulate/simulatePoolOperation.js +1 -1
  17. package/dist/esm/preview/trace/extractTransfers.js +1 -1
  18. package/dist/esm/sdk/accounts/CreditAccountsServiceV310.js +2 -2
  19. package/dist/esm/sdk/accounts/liquidations/LiquidationsService.js +20 -9
  20. package/dist/esm/sdk/accounts/withdrawal-compressor/RedemptionLoggerV310Contract.js +1 -1
  21. package/dist/esm/sdk/accounts/withdrawal-compressor/WithdrawalCompressorV310Contract.js +1 -1
  22. package/dist/esm/sdk/accounts/withdrawal-compressor/WithdrawalCompressorV311Contract.js +1 -1
  23. package/dist/esm/sdk/accounts/withdrawal-compressor/WithdrawalCompressorV313Contract.js +1 -1
  24. package/dist/esm/sdk/base/TokensMeta.js +2 -2
  25. package/dist/esm/sdk/chain/detectNetwork.js +1 -1
  26. package/dist/esm/sdk/core/createAddressProvider.js +1 -1
  27. package/dist/esm/sdk/market/MarketSuite.js +8 -12
  28. package/dist/esm/sdk/market/credit/CreditFacadeV310BaseContract.js +1 -1
  29. package/dist/esm/sdk/market/credit/CreditSuite.js +5 -15
  30. package/dist/esm/sdk/market/pool/PoolV310Contract.js +1 -1
  31. package/dist/esm/sdk/market/zapper/IETHZapperContract.js +1 -1
  32. package/dist/esm/sdk/market/zapper/ZapperContract.js +1 -1
  33. package/dist/esm/sdk/opportunities/OpportunitiesService.js +8 -63
  34. package/dist/esm/sdk/pools/PoolService.js +1 -1
  35. package/dist/esm/sdk/router/RouterV310Contract.js +34 -0
  36. package/dist/esm/sdk/utils/viem/simulateWithPriceUpdates.js +1 -1
  37. package/dist/types/model/index.d.ts +3 -1
  38. package/dist/types/model/liquidations.d.ts +9 -1
  39. package/dist/types/model/liquidations.schema.d.ts +5 -3
  40. package/dist/types/model/opportunities.d.ts +70 -29
  41. package/dist/types/model/opportunities.schema.d.ts +220 -249
  42. package/dist/types/model/positions.d.ts +239 -3
  43. package/dist/types/model/positions.schema.d.ts +701 -0
  44. package/dist/types/model/primitives.d.ts +3 -2
  45. package/dist/types/sdk/index.d.ts +3 -3
  46. package/dist/types/sdk/market/MarketSuite.d.ts +4 -15
  47. package/dist/types/sdk/market/credit/CreditSuite.d.ts +3 -7
  48. package/dist/types/sdk/market/index.d.ts +2 -2
  49. package/dist/types/sdk/opportunities/OpportunitiesService.d.ts +6 -11
  50. package/dist/types/sdk/router/RouterV310Contract.d.ts +5 -1
  51. package/dist/types/sdk/router/index.d.ts +2 -2
  52. package/dist/types/sdk/router/types.d.ts +35 -1
  53. package/package.json +1 -1
@@ -1,11 +1,247 @@
1
- import { ChainId } from "./primitives.js";
1
+ import { AssetType, Bps, ChainId, Leverage, Token, TokenAmount } from "./primitives.js";
2
+ import { ApyBreakdown, PointsProgram } from "./opportunities.js";
3
+ import { DelayedReceivedAsset, LiquidationPosition } from "./liquidations.js";
4
+ import { Address } from "viem";
2
5
  //#region src/model/positions.d.ts
6
+ /**
7
+ * Discriminator of the three kinds of position a wallet can hold.
8
+ *
9
+ * - `"pool"` — pool shares earning the supply rate.
10
+ * - `"strategy"` — an open credit account.
11
+ * - `"liquidation"` — a delayed withdrawal a liquidator took ownership of,
12
+ * see {@link LiquidationPosition}.
13
+ **/
14
+ type PositionKind = "pool" | "strategy" | "liquidation";
15
+ /**
16
+ * Earnings paid out in a token, as an amount rather than a rate.
17
+ **/
18
+ interface TokenRewardsPnL extends TokenAmount {
19
+ kind: "token";
20
+ }
21
+ /**
22
+ * A points program together with how many points the position has accrued in
23
+ * it. The program itself is described by {@link PointsProgram}.
24
+ **/
25
+ interface PointsProgramPnL extends PointsProgram {
26
+ /**
27
+ * Points accrued so far. Points have no price, so this is a plain count
28
+ * rather than an {@link Amount}.
29
+ *
30
+ * @example `12500.5`
31
+ **/
32
+ value: number;
33
+ }
34
+ /**
35
+ * Earnings accrued as points rather than tokens.
36
+ **/
37
+ interface PointsRewardsPnL {
38
+ kind: "point";
39
+ /**
40
+ * Programs the position has accrued points in.
41
+ **/
42
+ points: PointsProgramPnL[];
43
+ }
44
+ /**
45
+ * Any earnings stream of a position, as accrued amounts.
46
+ **/
47
+ type RewardsPnL = TokenRewardsPnL | PointsRewardsPnL;
48
+ /**
49
+ * What a position has earned since it was opened, split the same way
50
+ * {@link ApyBreakdown} splits the rates that produced it.
51
+ *
52
+ * Every field needs the position's history, so the whole group is off-chain
53
+ * only, see {@link PoolPosition.pnl} and {@link StrategyPosition.pnl}.
54
+ **/
55
+ interface PnlBreakdown {
56
+ /**
57
+ * The part the protocol itself generated: organic interest plus price moves,
58
+ * denominated in the underlying.
59
+ **/
60
+ organic: TokenAmount;
61
+ /**
62
+ * Everything combined, including the value of {@link rewards} that has a
63
+ * price. Denominated in the underlying.
64
+ **/
65
+ total: TokenAmount;
66
+ /**
67
+ * Incentives earned on top of {@link organic}, plus any points programs that
68
+ * carry no value at all.
69
+ **/
70
+ rewards: RewardsPnL[];
71
+ }
72
+ /**
73
+ * One collateral token of a credit account: what the account holds of it, what
74
+ * it pays quota on, and what it has on its way out.
75
+ **/
76
+ interface PositionCollateral {
77
+ /**
78
+ * Amount of the token the account holds. Phantom tokens are reported as-is,
79
+ * i.e. as the phantom token rather than as the asset it redeems into.
80
+ **/
81
+ collateral: TokenAmount;
82
+ /**
83
+ * Quota bought for {@link collateral}, denominated in the market's
84
+ * underlying rather than in the collateral token.
85
+ **/
86
+ quota: TokenAmount;
87
+ /**
88
+ * Delayed withdrawals of this collateral, denominated in the asset the
89
+ * phantom token redeems into. Empty when nothing is on its way out.
90
+ **/
91
+ withdrawals: DelayedReceivedAsset[];
92
+ }
93
+ /**
94
+ * Pool shares held by a wallet.
95
+ **/
96
+ interface PoolPosition {
97
+ /**
98
+ * Discriminates this position from the other kinds a wallet can hold.
99
+ **/
100
+ kind: "pool";
101
+ /**
102
+ * Human-readable name for the row, the pool's own name.
103
+ *
104
+ * @example `"USDC Pool"`
105
+ **/
106
+ name: string;
107
+ /**
108
+ * Chain the pool lives on.
109
+ **/
110
+ chainId: ChainId;
111
+ /**
112
+ * Address of the ERC-4626 pool contract.
113
+ **/
114
+ pool: Address;
115
+ /**
116
+ * Underlying the held shares are worth at the current share rate, i.e.
117
+ * `pool.convertToAssets(pool.balanceOf(wallet))`.
118
+ **/
119
+ netValue: TokenAmount;
120
+ /**
121
+ * Rate the position is currently earning. Its
122
+ * {@link ApyBreakdown.organicApy} is the pool's own supply rate, so this
123
+ * group is present in `onchain` mode too, with only that part filled.
124
+ **/
125
+ apy: ApyBreakdown;
126
+ /**
127
+ * What the position has earned so far.
128
+ *
129
+ * @mode offchain
130
+ **/
131
+ pnl?: PnlBreakdown;
132
+ }
133
+ /**
134
+ * An open credit account of a wallet.
135
+ **/
136
+ interface StrategyPosition {
137
+ /**
138
+ * Discriminates this position from the other kinds a wallet can hold.
139
+ **/
140
+ kind: "strategy";
141
+ /**
142
+ * Human-readable strategy name, e.g. `"wstETH / WETH"`.
143
+ **/
144
+ name: string;
145
+ /**
146
+ * Chain the account lives on.
147
+ **/
148
+ chainId: ChainId;
149
+ /**
150
+ * Credit manager the account is opened in.
151
+ **/
152
+ creditManager: Address;
153
+ /**
154
+ * Credit account address.
155
+ **/
156
+ creditAccount: Address;
157
+ /**
158
+ * The account's dominant non-underlying collateral at the session's opening
159
+ * block (greatest opening-block USD value) — the asset the position was
160
+ * initially leveraged into. `null` when the opening snapshot holds only the
161
+ * underlying.
162
+ **/
163
+ targetCollateral: Token | null;
164
+ /**
165
+ * Debt/equity ratio: `totalDebt / equity` (`equity = totalValue −
166
+ * totalDebt`). `0` = unleveraged; `0` if underwater. Same notation as the
167
+ * opportunity `maxLeverage`, and bounded by it.
168
+ **/
169
+ leverage: Leverage;
170
+ /**
171
+ * Annual cost of the borrowed underlying, in basis points, including the
172
+ * protocol's interest fee: the pool's base rate scaled by the credit
173
+ * manager's `feeInterest`.
174
+ *
175
+ * @example `520` for 5.2% APY
176
+ **/
177
+ borrowApy: Bps;
178
+ /**
179
+ * Net rate the whole position is currently earning, i.e. the collateral's
180
+ * yield at this {@link leverage} minus the cost of the debt carrying it.
181
+ *
182
+ * Absent in `onchain` mode: its collateral yield term is.
183
+ *
184
+ * @mode offchain
185
+ **/
186
+ netApy?: ApyBreakdown;
187
+ /**
188
+ * Debt principal plus accrued interest and fees.
189
+ **/
190
+ totalDebt: TokenAmount;
191
+ /**
192
+ * Total account value: every collateral it holds, denominated in the
193
+ * market's underlying.
194
+ **/
195
+ totalValue: TokenAmount;
196
+ /**
197
+ * Health factor in basis points: below `10000` the account is liquidatable.
198
+ *
199
+ * @example `12500` for a health factor of 1.25
200
+ **/
201
+ healthFactor: Bps;
202
+ /**
203
+ * What the position has earned so far.
204
+ *
205
+ * @mode offchain
206
+ **/
207
+ pnl?: PnlBreakdown;
208
+ /**
209
+ * Every collateral token the account holds, with its quota and pending
210
+ * withdrawals.
211
+ **/
212
+ collaterals: PositionCollateral[];
213
+ }
214
+ /**
215
+ * A row of the positions list: anything a wallet holds in the protocol.
216
+ **/
217
+ type Position = PoolPosition | StrategyPosition | LiquidationPosition;
218
+ /**
219
+ * Optional narrowing of a positions list.
220
+ *
221
+ * Every criterion is optional and an omitted one matches any value, so an empty
222
+ * filter is the same as no filter at all. Criteria combine with AND.
223
+ **/
3
224
  interface PositionFilter {
225
+ /**
226
+ * Keep only positions of this kind.
227
+ **/
228
+ kind?: PositionKind;
229
+ /**
230
+ * Keep only credit accounts that carry no debt, or only the ones that do.
231
+ * Applicable only to {@link StrategyPosition}
232
+ **/
4
233
  isZeroDebt?: boolean;
5
234
  /**
6
- * Keep only opportunities on these chains.
235
+ * Keep only positions on these chains.
7
236
  **/
8
237
  chainIds?: ChainId[];
238
+ /**
239
+ * Keep only positions whose underlying is of this class, which for an RWA
240
+ * market means the class of the token its wrapper holds.
241
+ *
242
+ * Not applicable to {@link LiquidationPosition}
243
+ **/
244
+ underlyingType?: AssetType;
9
245
  }
10
246
  //#endregion
11
- export { PositionFilter };
247
+ export { PnlBreakdown, PointsProgramPnL, PointsRewardsPnL, PoolPosition, Position, PositionCollateral, PositionFilter, PositionKind, RewardsPnL, StrategyPosition, TokenRewardsPnL };