@strkfarm/sdk 2.0.0-dev.34 → 2.0.0-dev.36

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 (51) hide show
  1. package/dist/cli.js +2 -2
  2. package/dist/cli.mjs +2 -2
  3. package/dist/index.browser.global.js +16173 -24081
  4. package/dist/index.browser.mjs +8572 -16661
  5. package/dist/index.d.ts +600 -2666
  6. package/dist/index.js +8660 -16784
  7. package/dist/index.mjs +8585 -16674
  8. package/package.json +3 -3
  9. package/src/data/redeem-request-nft.abi.json +752 -0
  10. package/src/data/universal-vault.abi.json +8 -7
  11. package/src/dataTypes/bignumber.browser.ts +5 -1
  12. package/src/dataTypes/bignumber.node.ts +5 -0
  13. package/src/global.ts +21 -1
  14. package/src/interfaces/common.tsx +39 -4
  15. package/src/modules/avnu.ts +19 -10
  16. package/src/modules/index.ts +1 -1
  17. package/src/strategies/base-strategy.ts +92 -8
  18. package/src/strategies/constants.ts +8 -3
  19. package/src/strategies/ekubo-cl-vault.tsx +150 -16
  20. package/src/strategies/factory.ts +21 -1
  21. package/src/strategies/index.ts +2 -6
  22. package/src/strategies/registry.ts +28 -5
  23. package/src/strategies/sensei.ts +29 -13
  24. package/src/strategies/svk-strategy.ts +29 -4
  25. package/src/strategies/token-boosted-xstrk-carry-strategy.tsx +1057 -0
  26. package/src/strategies/universal-adapters/adapter-utils.ts +2 -0
  27. package/src/strategies/universal-adapters/avnu-adapter.ts +19 -10
  28. package/src/strategies/universal-adapters/index.ts +1 -2
  29. package/src/strategies/universal-adapters/svk-troves-adapter.ts +160 -13
  30. package/src/strategies/universal-adapters/vesu-modify-position-adapter.ts +91 -42
  31. package/src/strategies/universal-adapters/vesu-multiply-adapter.ts +75 -52
  32. package/src/strategies/universal-adapters/vesu-position-common.ts +38 -31
  33. package/src/strategies/universal-lst-muliplier-strategy.tsx +222 -269
  34. package/src/strategies/universal-strategy.tsx +166 -105
  35. package/src/strategies/vesu-rebalance.tsx +3 -6
  36. package/src/strategies/yoloVault.ts +1084 -0
  37. package/src/utils/health-factor-math.ts +29 -0
  38. package/src/modules/ExtendedWrapperSDk/index.ts +0 -62
  39. package/src/modules/ExtendedWrapperSDk/types.ts +0 -334
  40. package/src/modules/ExtendedWrapperSDk/wrapper.ts +0 -611
  41. package/src/strategies/universal-adapters/extended-adapter.ts +0 -835
  42. package/src/strategies/universal-adapters/usdc<>usdce-adapter.ts +0 -200
  43. package/src/strategies/vesu-extended-strategy/services/executionService.ts +0 -2233
  44. package/src/strategies/vesu-extended-strategy/services/extended-vesu-state-manager.ts +0 -4254
  45. package/src/strategies/vesu-extended-strategy/services/ltv-imbalance-rebalance-math.ts +0 -783
  46. package/src/strategies/vesu-extended-strategy/services/operationService.ts +0 -56
  47. package/src/strategies/vesu-extended-strategy/types/transaction-metadata.ts +0 -88
  48. package/src/strategies/vesu-extended-strategy/utils/config.runtime.ts +0 -78
  49. package/src/strategies/vesu-extended-strategy/utils/constants.ts +0 -48
  50. package/src/strategies/vesu-extended-strategy/utils/helper.ts +0 -528
  51. package/src/strategies/vesu-extended-strategy/vesu-extended-strategy.tsx +0 -1014
@@ -89,4 +89,33 @@ export class HealthFactorMath {
89
89
  logger.verbose(`HealthFactorMath: Max debt amount: ${debtAmount.toNumber()}, numerator: ${numerator.toNumber()}, denominator: ${denominator}`);
90
90
  return new Web3Number(debtAmount.toString(), debtTokenInfo.decimals);
91
91
  }
92
+
93
+ static calculateDebtReductionAmountForWithdrawal = (
94
+ debtAmount: Web3Number,
95
+ collateralAmount: Web3Number,
96
+ maxLtv: number,
97
+ targetHF: number,
98
+ withdrawalAmount: Web3Number,
99
+ collateralPrice: number,
100
+ debtPrice: number,
101
+ collateralTokenInfo: TokenInfo,
102
+ debtTokenInfo: TokenInfo,
103
+ ) => {
104
+ const idealLTV = maxLtv / targetHF;
105
+ // formulae
106
+ // dDebt is change is debt.
107
+ // (current debt - dDebt) * debtPrice / (current collateral - withdrawAmount - (dDebt * debtPrice / collPrice)) = idealLTV
108
+ // (current debt - dDebt) * debtPrice = idealLTV * (current collateral - withdrawAmount) - (idealLTV * dDebt * debtPrice / collPrice))
109
+ // dDebt * (idealLTV * debtPrice / collPrice - debtPrice) = idealLTV * (current collateral - withdrawAmount) - current debt * debtPrice
110
+ // dDebt = (idealLTV * (current collateral - withdrawAmount) - current debt * debtPrice) / (idealLTV * debtPrice / collPrice - debtPrice)
111
+ const _dDebt = (collateralAmount.minus(withdrawalAmount).multipliedBy(idealLTV).minus(debtAmount.multipliedBy(debtPrice)).dividedBy((idealLTV * debtPrice / collateralPrice) - debtPrice));
112
+ const dDebt = Web3Number.fromWei(_dDebt.toWei(), debtTokenInfo.decimals);
113
+ if (dDebt.lessThan(0)) {
114
+ return { deltadebtAmountUnits: null };
115
+ }
116
+ if (dDebt.greaterThan(debtAmount)) {
117
+ return { deltadebtAmountUnits: debtAmount };
118
+ }
119
+ return { deltadebtAmountUnits: dDebt};
120
+ }
92
121
  }
@@ -1,62 +0,0 @@
1
- /**
2
- * Extended Exchange TypeScript SDK
3
- *
4
- * A comprehensive TypeScript wrapper for the Extended Exchange trading API.
5
- * Provides type-safe access to all trading operations including orders, positions,
6
- * balances, markets, and asset operations.
7
- *
8
- * @example
9
- * ```typescript
10
- * import { ExtendedWrapper } from './ts';
11
- *
12
- * const client = new ExtendedWrapper({
13
- * baseUrl: 'http://localhost:8000',
14
- * apiKey: 'your-api-key'
15
- * });
16
- *
17
- * // Create a buy order
18
- * const order = await client.createBuyOrder('BTC-USD', '0.1', '50000');
19
- *
20
- * // Get positions
21
- * const positions = await client.getPositions();
22
- *
23
- * // Get balance
24
- * const balance = await client.getHoldings();
25
- * ```
26
- */
27
-
28
- export { ExtendedWrapper } from "./wrapper";
29
- export { default } from "./wrapper";
30
-
31
- // Export all types
32
- export * from "./types";
33
-
34
- // Re-export commonly used types for convenience
35
- export type {
36
- CreateOrderRequest,
37
- WithdrawRequest,
38
- SignedWithdrawRequest,
39
- CancelOrderRequest,
40
- PlacedOrder,
41
- OpenOrder,
42
- Position,
43
- Balance,
44
- Market,
45
- MarketStats,
46
- AssetOperation,
47
- ExtendedApiResponse,
48
- ExtendedWrapperConfig,
49
- } from "./types";
50
-
51
- // Re-export enums for convenience
52
- export {
53
- OrderSide,
54
- TimeInForce,
55
- OrderType,
56
- OrderStatus,
57
- OrderStatusReason,
58
- PositionSide,
59
- ExitType,
60
- AssetOperationType,
61
- AssetOperationStatus,
62
- } from "./types";
@@ -1,334 +0,0 @@
1
- /**
2
- * TypeScript type definitions for Extended Exchange API
3
- * Based on Python SDK models from x10.perpetual
4
- */
5
-
6
- // Enums
7
- export enum OrderSide {
8
- BUY = "BUY",
9
- SELL = "SELL",
10
- }
11
-
12
- export enum TimeInForce {
13
- GTT = "GTT",
14
- IOC = "IOC",
15
- FOK = "FOK",
16
- }
17
-
18
- export enum OrderType {
19
- LIMIT = "LIMIT",
20
- CONDITIONAL = "CONDITIONAL",
21
- MARKET = "MARKET",
22
- TPSL = "TPSL",
23
- }
24
-
25
- export enum OrderStatus {
26
- UNKNOWN = "UNKNOWN",
27
- NEW = "NEW",
28
- UNTRIGGERED = "UNTRIGGERED",
29
- PARTIALLY_FILLED = "PARTIALLY_FILLED",
30
- FILLED = "FILLED",
31
- CANCELLED = "CANCELLED",
32
- EXPIRED = "EXPIRED",
33
- REJECTED = "REJECTED",
34
- }
35
-
36
- export enum OrderStatusReason {
37
- UNKNOWN = "UNKNOWN",
38
- NONE = "NONE",
39
- UNKNOWN_MARKET = "UNKNOWN_MARKET",
40
- DISABLED_MARKET = "DISABLED_MARKET",
41
- NOT_ENOUGH_FUNDS = "NOT_ENOUGH_FUNDS",
42
- NO_LIQUIDITY = "NO_LIQUIDITY",
43
- INVALID_FEE = "INVALID_FEE",
44
- INVALID_QTY = "INVALID_QTY",
45
- INVALID_PRICE = "INVALID_PRICE",
46
- INVALID_VALUE = "INVALID_VALUE",
47
- UNKNOWN_ACCOUNT = "UNKNOWN_ACCOUNT",
48
- SELF_TRADE_PROTECTION = "SELF_TRADE_PROTECTION",
49
- POST_ONLY_FAILED = "POST_ONLY_FAILED",
50
- REDUCE_ONLY_FAILED = "REDUCE_ONLY_FAILED",
51
- INVALID_EXPIRE_TIME = "INVALID_EXPIRE_TIME",
52
- POSITION_TPSL_CONFLICT = "POSITION_TPSL_CONFLICT",
53
- INVALID_LEVERAGE = "INVALID_LEVERAGE",
54
- PREV_ORDER_NOT_FOUND = "PREV_ORDER_NOT_FOUND",
55
- PREV_ORDER_TRIGGERED = "PREV_ORDER_TRIGGERED",
56
- TPSL_OTHER_SIDE_FILLED = "TPSL_OTHER_SIDE_FILLED",
57
- PREV_ORDER_CONFLICT = "PREV_ORDER_CONFLICT",
58
- ORDER_REPLACED = "ORDER_REPLACED",
59
- POST_ONLY_MODE = "POST_ONLY_MODE",
60
- REDUCE_ONLY_MODE = "REDUCE_ONLY_MODE",
61
- TRADING_OFF_MODE = "TRADING_OFF_MODE",
62
- }
63
-
64
- export enum PositionSide {
65
- LONG = "LONG",
66
- SHORT = "SHORT",
67
- }
68
-
69
- export enum ExitType {
70
- TRADE = "TRADE",
71
- LIQUIDATION = "LIQUIDATION",
72
- ADL = "ADL",
73
- }
74
-
75
- export enum AssetOperationType {
76
- DEPOSIT = "DEPOSIT",
77
- WITHDRAWAL = "WITHDRAWAL",
78
- TRANSFER = "TRANSFER",
79
- }
80
-
81
- export enum AssetOperationStatus {
82
- CREATED = "CREATED",
83
- IN_PROGRESS = "IN_PROGRESS",
84
- COMPLETED = "COMPLETED",
85
- REJECTED = "REJECTED",
86
- }
87
-
88
- // Base types
89
- export interface SettlementSignature {
90
- r: string;
91
- s: string;
92
- }
93
-
94
- export interface StarkSettlement {
95
- signature: SettlementSignature;
96
- stark_key: string;
97
- collateral_position: string;
98
- }
99
-
100
- export interface StarkDebuggingOrderAmounts {
101
- collateral_amount: string;
102
- fee_amount: string;
103
- synthetic_amount: string;
104
- }
105
-
106
- // Order types
107
- export interface PlacedOrder {
108
- id: number;
109
- external_id: string;
110
- }
111
-
112
- export interface OpenOrder {
113
- id: number;
114
- account_id: number;
115
- external_id: string;
116
- market: string;
117
- type: OrderType;
118
- side: OrderSide;
119
- status: OrderStatus;
120
- status_reason?: OrderStatusReason;
121
- price: string;
122
- average_price?: string;
123
- qty: string;
124
- filled_qty?: string;
125
- reduce_only: boolean;
126
- post_only: boolean;
127
- payed_fee?: string;
128
- created_time: number;
129
- updated_time: number;
130
- expiry_time?: number;
131
- }
132
-
133
- // Position types
134
- export interface Position {
135
- id: number;
136
- accountId: number;
137
- market: string;
138
- side: PositionSide;
139
- leverage: string;
140
- size: string;
141
- value: string;
142
- openPrice: string;
143
- markPrice: string;
144
- liquidationPrice?: string;
145
- unrealisedPnl: string;
146
- realisedPnl: string;
147
- tpPrice?: string;
148
- slPrice?: string;
149
- adl?: number;
150
- createdAt: number;
151
- updatedAt: number;
152
- }
153
-
154
- export interface PositionHistory {
155
- id: number;
156
- account_id: number;
157
- market: string;
158
- side: PositionSide;
159
- leverage: string;
160
- size: string;
161
- open_price: string;
162
- exit_type?: ExitType;
163
- exit_price?: string;
164
- realised_pnl: string;
165
- created_time: number;
166
- closed_time?: number;
167
- }
168
-
169
- // Balance types
170
- export interface Balance {
171
- collateral_name: string;
172
- balance: string;
173
- equity: string;
174
- availableForTrade: string;
175
- availableForWithdrawal: string;
176
- unrealisedPnl: string;
177
- initialMargin: string;
178
- marginRatio: string;
179
- updatedTime: number;
180
- }
181
-
182
- // Market types
183
- export interface RiskFactorConfig {
184
- upper_bound: string;
185
- risk_factor: string;
186
- }
187
-
188
- export interface MarketStats {
189
- daily_volume: string;
190
- daily_volume_base: string;
191
- daily_price_change: string;
192
- daily_low: string;
193
- daily_high: string;
194
- last_price: string;
195
- ask_price: string;
196
- bid_price: string;
197
- mark_price: string;
198
- index_price: string;
199
- funding_rate: string;
200
- next_funding_rate: number;
201
- open_interest: string;
202
- open_interest_base: string;
203
- }
204
-
205
- export interface TradingConfig {
206
- min_order_size: string;
207
- min_order_size_change: string;
208
- min_price_change: string;
209
- max_market_order_value: string;
210
- max_limit_order_value: string;
211
- max_position_value: string;
212
- max_leverage: string;
213
- max_num_orders: number;
214
- limit_price_cap: string;
215
- limit_price_floor: string;
216
- risk_factor_config: RiskFactorConfig[];
217
- }
218
-
219
- export interface L2Config {
220
- type: string;
221
- collateral_id: string;
222
- collateral_resolution: number;
223
- synthetic_id: string;
224
- synthetic_resolution: number;
225
- }
226
-
227
- export interface Market {
228
- name: string;
229
- asset_name: string;
230
- asset_precision: number;
231
- collateral_asset_name: string;
232
- collateral_asset_precision: number;
233
- active: boolean;
234
- market_stats: MarketStats;
235
- trading_config: TradingConfig;
236
- l2_config: L2Config;
237
- }
238
-
239
- // Asset operation types
240
- export interface AssetOperation {
241
- id: string;
242
- type: AssetOperationType;
243
- status: AssetOperationStatus;
244
- amount: string;
245
- asset: string;
246
- created_time: number;
247
- updated_time: number;
248
- description?: string;
249
- transactionHash?:string;
250
- }
251
-
252
- // Request types
253
- export interface CreateOrderRequest {
254
- market_name: string;
255
- amount: string;
256
- price: string;
257
- side: OrderSide;
258
- post_only?: boolean;
259
- reduce_only?: boolean;
260
- previous_order_id?: number;
261
- external_id?: string;
262
- time_in_force?: TimeInForce;
263
- }
264
-
265
- export interface WithdrawRequest {
266
- amount: string;
267
- asset?: string;
268
- }
269
-
270
- export interface SignedWithdrawRequest {
271
- recipient: string;
272
- position_id: number;
273
- amount: number;
274
- expiration: number;
275
- salt: number;
276
- }
277
-
278
- export interface CancelOrderRequest {
279
- order_id: number;
280
- }
281
-
282
- // Response wrapper type
283
- export interface ApiResponse<T> {
284
- success: boolean;
285
- message: string;
286
- data: T;
287
- }
288
-
289
- // Extended API response wrapper (matches Python WrappedApiResponse)
290
- export interface ExtendedApiResponse<T> {
291
- status: 'OK' | 'ERROR';
292
- message: string;
293
- data: T;
294
- }
295
-
296
- // Configuration types
297
- export interface ExtendedWrapperConfig {
298
- readUrl: string;
299
- writeUrl: string;
300
- apiKey?: string;
301
- timeout?: number;
302
- retries?: number;
303
- }
304
-
305
- export interface UpdateLeverageRequest {
306
- leverage: string;
307
- market: string;
308
- }
309
-
310
- export interface FundingRate {
311
- m: string;
312
- f:string;
313
- t:number;
314
- }
315
-
316
- export interface FundingPayment {
317
- id: number;
318
- accountId?: number;
319
- account_id?: number;
320
- market: string;
321
- positionId?: number;
322
- position_id?: number;
323
- side: PositionSide;
324
- size: string;
325
- value: string;
326
- markPrice?: string;
327
- mark_price?: string;
328
- fundingFee?: string;
329
- funding_fee?: string;
330
- fundingRate?: string;
331
- funding_rate?: string;
332
- paidTime?: number;
333
- paid_time?: number;
334
- }