@strkfarm/sdk 2.0.0-dev.4 → 2.0.0-dev.40

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 (77) hide show
  1. package/dist/cli.js +190 -36
  2. package/dist/cli.mjs +188 -34
  3. package/dist/index.browser.global.js +116018 -90768
  4. package/dist/index.browser.mjs +12769 -10876
  5. package/dist/index.d.ts +2222 -1947
  6. package/dist/index.js +13171 -11077
  7. package/dist/index.mjs +13076 -11004
  8. package/package.json +3 -3
  9. package/src/data/avnu.abi.json +840 -0
  10. package/src/data/ekubo-price-fethcer.abi.json +265 -0
  11. package/src/data/redeem-request-nft.abi.json +752 -0
  12. package/src/data/universal-vault.abi.json +8 -7
  13. package/src/dataTypes/_bignumber.ts +13 -4
  14. package/src/dataTypes/bignumber.browser.ts +10 -1
  15. package/src/dataTypes/bignumber.node.ts +10 -1
  16. package/src/dataTypes/index.ts +3 -2
  17. package/src/dataTypes/mynumber.ts +141 -0
  18. package/src/global.ts +96 -41
  19. package/src/index.browser.ts +2 -1
  20. package/src/interfaces/common.tsx +212 -5
  21. package/src/modules/apollo-client-config.ts +28 -0
  22. package/src/modules/avnu.ts +21 -12
  23. package/src/modules/ekubo-pricer.ts +79 -0
  24. package/src/modules/ekubo-quoter.ts +48 -30
  25. package/src/modules/erc20.ts +17 -0
  26. package/src/modules/harvests.ts +43 -29
  27. package/src/modules/index.ts +1 -1
  28. package/src/modules/pragma.ts +23 -8
  29. package/src/modules/pricer-from-api.ts +156 -15
  30. package/src/modules/pricer-lst.ts +1 -1
  31. package/src/modules/pricer.ts +40 -4
  32. package/src/modules/pricerBase.ts +2 -1
  33. package/src/node/deployer.ts +36 -1
  34. package/src/node/pricer-redis.ts +2 -1
  35. package/src/strategies/base-strategy.ts +168 -16
  36. package/src/strategies/constants.ts +8 -3
  37. package/src/strategies/ekubo-cl-vault.tsx +1044 -351
  38. package/src/strategies/factory.ts +199 -0
  39. package/src/strategies/index.ts +5 -3
  40. package/src/strategies/registry.ts +262 -0
  41. package/src/strategies/sensei.ts +353 -9
  42. package/src/strategies/svk-strategy.ts +125 -30
  43. package/src/strategies/token-boosted-xstrk-carry-strategy.tsx +1225 -0
  44. package/src/strategies/types.ts +4 -0
  45. package/src/strategies/universal-adapters/adapter-utils.ts +4 -1
  46. package/src/strategies/universal-adapters/avnu-adapter.ts +196 -272
  47. package/src/strategies/universal-adapters/baseAdapter.ts +263 -251
  48. package/src/strategies/universal-adapters/common-adapter.ts +206 -203
  49. package/src/strategies/universal-adapters/index.ts +10 -8
  50. package/src/strategies/universal-adapters/svk-troves-adapter.ts +511 -0
  51. package/src/strategies/universal-adapters/token-transfer-adapter.ts +200 -0
  52. package/src/strategies/universal-adapters/vesu-adapter.ts +120 -82
  53. package/src/strategies/universal-adapters/vesu-modify-position-adapter.ts +525 -0
  54. package/src/strategies/universal-adapters/vesu-multiply-adapter.ts +1098 -712
  55. package/src/strategies/universal-adapters/vesu-position-common.ts +258 -0
  56. package/src/strategies/universal-adapters/vesu-supply-only-adapter.ts +18 -3
  57. package/src/strategies/universal-lst-muliplier-strategy.tsx +551 -405
  58. package/src/strategies/universal-strategy.tsx +1487 -1173
  59. package/src/strategies/vesu-rebalance.tsx +252 -152
  60. package/src/strategies/yoloVault.ts +1084 -0
  61. package/src/utils/cacheClass.ts +11 -2
  62. package/src/utils/health-factor-math.ts +33 -1
  63. package/src/utils/index.ts +3 -1
  64. package/src/utils/logger.browser.ts +22 -4
  65. package/src/utils/logger.node.ts +259 -24
  66. package/src/utils/starknet-call-parser.ts +1036 -0
  67. package/src/utils/strategy-utils.ts +61 -0
  68. package/src/modules/ExtendedWrapperSDk/index.ts +0 -62
  69. package/src/modules/ExtendedWrapperSDk/types.ts +0 -311
  70. package/src/modules/ExtendedWrapperSDk/wrapper.ts +0 -395
  71. package/src/strategies/universal-adapters/extended-adapter.ts +0 -661
  72. package/src/strategies/universal-adapters/unused-balance-adapter.ts +0 -109
  73. package/src/strategies/vesu-extended-strategy/services/operationService.ts +0 -34
  74. package/src/strategies/vesu-extended-strategy/utils/config.runtime.ts +0 -77
  75. package/src/strategies/vesu-extended-strategy/utils/constants.ts +0 -49
  76. package/src/strategies/vesu-extended-strategy/utils/helper.ts +0 -372
  77. package/src/strategies/vesu-extended-strategy/vesu-extended-strategy.tsx +0 -1140
@@ -0,0 +1,61 @@
1
+ import { SingleTokenInfo, DualTokenInfo } from "../strategies/base-strategy";
2
+ import { BaseStrategy } from "../strategies/base-strategy";
3
+ import { AmountsInfo, StrategyCapabilities, TokenInfo } from "@/interfaces";
4
+ import { ContractAddr, Web3Number } from "@/dataTypes";
5
+ import { gql } from "@apollo/client";
6
+ import apolloClient from "@/modules/apollo-client";
7
+ import { num } from "starknet";
8
+ import { logger } from "./logger";
9
+
10
+ /**
11
+ * Convert SDK TVL info (SingleTokenInfo or DualTokenInfo) to client AmountsInfo format
12
+ */
13
+ export function toAmountsInfo(tvlInfo: SingleTokenInfo | DualTokenInfo): Omit<
14
+ AmountsInfo,
15
+ "amounts"
16
+ > & {
17
+ amounts: Array<{
18
+ amount: Web3Number;
19
+ tokenInfo: TokenInfo;
20
+ }>;
21
+ } {
22
+ if ("token0" in tvlInfo) {
23
+ // Dual token
24
+ return {
25
+ usdValue: tvlInfo.usdValue,
26
+ amounts: [tvlInfo.token0, tvlInfo.token1]
27
+ };
28
+ } else {
29
+ // Single token
30
+ return {
31
+ usdValue: tvlInfo.usdValue,
32
+ amounts: [tvlInfo]
33
+ };
34
+ }
35
+ }
36
+
37
+ /**
38
+ * Detect what capabilities a strategy instance has
39
+ */
40
+ export function detectCapabilities(
41
+ strategy: BaseStrategy<any, any>
42
+ ): StrategyCapabilities {
43
+ return {
44
+ hasMatchInputAmounts:
45
+ typeof (strategy as any).matchInputAmounts === "function",
46
+ hasNetAPY: typeof (strategy as any).netAPY === "function",
47
+ hasGetInvestmentFlows:
48
+ typeof (strategy as any).getInvestmentFlows === "function",
49
+ hasGetPendingRewards: typeof strategy.getPendingRewards === "function",
50
+ hasHarvest: typeof (strategy as any).harvest === "function",
51
+ hasRebalance: typeof (strategy as any).getRebalanceCall === "function"
52
+ };
53
+ }
54
+
55
+ /**
56
+ * Check if a strategy is a dual-token strategy
57
+ */
58
+ export function isDualTokenStrategy(strategy: BaseStrategy<any, any>): boolean {
59
+ // Check if strategy has matchInputAmounts (dual token strategies have this)
60
+ return typeof (strategy as any).matchInputAmounts === "function";
61
+ }
@@ -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,311 +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
- PENDING = "PENDING",
83
- COMPLETED = "COMPLETED",
84
- FAILED = "FAILED",
85
- }
86
-
87
- // Base types
88
- export interface SettlementSignature {
89
- r: string;
90
- s: string;
91
- }
92
-
93
- export interface StarkSettlement {
94
- signature: SettlementSignature;
95
- stark_key: string;
96
- collateral_position: string;
97
- }
98
-
99
- export interface StarkDebuggingOrderAmounts {
100
- collateral_amount: string;
101
- fee_amount: string;
102
- synthetic_amount: string;
103
- }
104
-
105
- // Order types
106
- export interface PlacedOrder {
107
- id: number;
108
- external_id: string;
109
- }
110
-
111
- export interface OpenOrder {
112
- id: number;
113
- account_id: number;
114
- external_id: string;
115
- market: string;
116
- type: OrderType;
117
- side: OrderSide;
118
- status: OrderStatus;
119
- status_reason?: OrderStatusReason;
120
- price: string;
121
- average_price?: string;
122
- qty: string;
123
- filled_qty?: string;
124
- reduce_only: boolean;
125
- post_only: boolean;
126
- payed_fee?: string;
127
- created_time: number;
128
- updated_time: number;
129
- expiry_time?: number;
130
- }
131
-
132
- // Position types
133
- export interface Position {
134
- id: number;
135
- accountId: number;
136
- market: string;
137
- side: PositionSide;
138
- leverage: string;
139
- size: string;
140
- value: string;
141
- openPrice: string;
142
- markPrice: string;
143
- liquidationPrice?: string;
144
- unrealisedPnl: string;
145
- realisedPnl: string;
146
- tpPrice?: string;
147
- slPrice?: string;
148
- adl?: number;
149
- createdAt: number;
150
- updatedAt: number;
151
- }
152
-
153
- export interface PositionHistory {
154
- id: number;
155
- account_id: number;
156
- market: string;
157
- side: PositionSide;
158
- leverage: string;
159
- size: string;
160
- open_price: string;
161
- exit_type?: ExitType;
162
- exit_price?: string;
163
- realised_pnl: string;
164
- created_time: number;
165
- closed_time?: number;
166
- }
167
-
168
- // Balance types
169
- export interface Balance {
170
- collateral_name: string;
171
- balance: string;
172
- equity: string;
173
- availableForTrade: string;
174
- availableForWithdrawal: string;
175
- unrealisedPnl: string;
176
- initialMargin: string;
177
- marginRatio: string;
178
- updatedTime: number;
179
- }
180
-
181
- // Market types
182
- export interface RiskFactorConfig {
183
- upper_bound: string;
184
- risk_factor: string;
185
- }
186
-
187
- export interface MarketStats {
188
- daily_volume: string;
189
- daily_volume_base: string;
190
- daily_price_change: string;
191
- daily_low: string;
192
- daily_high: string;
193
- last_price: string;
194
- ask_price: string;
195
- bid_price: string;
196
- mark_price: string;
197
- index_price: string;
198
- funding_rate: string;
199
- next_funding_rate: number;
200
- open_interest: string;
201
- open_interest_base: string;
202
- }
203
-
204
- export interface TradingConfig {
205
- min_order_size: string;
206
- min_order_size_change: string;
207
- min_price_change: string;
208
- max_market_order_value: string;
209
- max_limit_order_value: string;
210
- max_position_value: string;
211
- max_leverage: string;
212
- max_num_orders: number;
213
- limit_price_cap: string;
214
- limit_price_floor: string;
215
- risk_factor_config: RiskFactorConfig[];
216
- }
217
-
218
- export interface L2Config {
219
- type: string;
220
- collateral_id: string;
221
- collateral_resolution: number;
222
- synthetic_id: string;
223
- synthetic_resolution: number;
224
- }
225
-
226
- export interface Market {
227
- name: string;
228
- asset_name: string;
229
- asset_precision: number;
230
- collateral_asset_name: string;
231
- collateral_asset_precision: number;
232
- active: boolean;
233
- market_stats: MarketStats;
234
- trading_config: TradingConfig;
235
- l2_config: L2Config;
236
- }
237
-
238
- // Asset operation types
239
- export interface AssetOperation {
240
- id: number;
241
- type: AssetOperationType;
242
- status: AssetOperationStatus;
243
- amount: string;
244
- asset: string;
245
- created_time: number;
246
- updated_time: number;
247
- description?: string;
248
- transactionHash?:string;
249
- }
250
-
251
- // Request types
252
- export interface CreateOrderRequest {
253
- market_name: string;
254
- amount: string;
255
- price: string;
256
- side: OrderSide;
257
- post_only?: boolean;
258
- previous_order_id?: number;
259
- external_id?: string;
260
- time_in_force?: TimeInForce;
261
- }
262
-
263
- export interface WithdrawRequest {
264
- amount: string;
265
- asset?: string;
266
- }
267
-
268
- export interface SignedWithdrawRequest {
269
- recipient: string;
270
- position_id: number;
271
- amount: number;
272
- expiration: number;
273
- salt: number;
274
- }
275
-
276
- export interface CancelOrderRequest {
277
- order_id: number;
278
- }
279
-
280
- // Response wrapper type
281
- export interface ApiResponse<T> {
282
- success: boolean;
283
- message: string;
284
- data: T;
285
- }
286
-
287
- // Extended API response wrapper (matches Python WrappedApiResponse)
288
- export interface ExtendedApiResponse<T> {
289
- status: 'OK' | 'ERROR';
290
- message: string;
291
- data: T;
292
- }
293
-
294
- // Configuration types
295
- export interface ExtendedWrapperConfig {
296
- baseUrl: string;
297
- apiKey?: string;
298
- timeout?: number;
299
- retries?: number;
300
- }
301
-
302
- export interface UpdateLeverageRequest {
303
- leverage: string;
304
- market: string;
305
- }
306
-
307
- export interface FundingRate {
308
- m: string;
309
- f:string;
310
- t:number;
311
- }