@crypticdot/defituna-api 4.0.0 → 4.0.2

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.
package/dist/index.mjs DELETED
@@ -1,1548 +0,0 @@
1
- var __defProp = Object.defineProperty;
2
- var __export = (target, all) => {
3
- for (var name in all)
4
- __defProp(target, name, { get: all[name], enumerable: true });
5
- };
6
-
7
- // src/client/client.ts
8
- import camelcaseKeys from "camelcase-keys";
9
- import snakecaseKeys from "snakecase-keys";
10
-
11
- // src/client/schemas.ts
12
- var schemas_exports = {};
13
- __export(schemas_exports, {
14
- AmountWithUsdSchema: () => AmountWithUsdSchema,
15
- AmountWithoutUsdSchema: () => AmountWithoutUsdSchema,
16
- CloseSpotPositionQuote: () => CloseSpotPositionQuote,
17
- DecreaseSpotPositionQuote: () => DecreaseSpotPositionQuote,
18
- FeesStatsGroup: () => FeesStatsGroup,
19
- IncreaseSpotPositionQuote: () => IncreaseSpotPositionQuote,
20
- LendingPosition: () => LendingPosition,
21
- LendingPositionNotification: () => LendingPositionNotification,
22
- LimitOrder: () => LimitOrder,
23
- LimitOrderQuoteByInput: () => LimitOrderQuoteByInput,
24
- LimitOrderQuoteByOutput: () => LimitOrderQuoteByOutput,
25
- LimitOrderState: () => LimitOrderState,
26
- LimitOrderStateSchema: () => LimitOrderStateSchema,
27
- LpPositionAutoCompound: () => LpPositionAutoCompound,
28
- LpPositionAutoCompoundSchema: () => LpPositionAutoCompoundSchema,
29
- LpPositionLimitOrderSwap: () => LpPositionLimitOrderSwap,
30
- LpPositionLimitOrderSwapSchema: () => LpPositionLimitOrderSwapSchema,
31
- LpPositionRebalance: () => LpPositionRebalance,
32
- LpPositionRebalanceSchema: () => LpPositionRebalanceSchema,
33
- LpPositionsActionType: () => LpPositionsActionType,
34
- LpPositionsActionTypeSchema: () => LpPositionsActionTypeSchema,
35
- Market: () => Market,
36
- Mint: () => Mint,
37
- NotificationAction: () => NotificationAction,
38
- NotificationActionSchema: () => NotificationActionSchema,
39
- NotificationEntity: () => NotificationEntity,
40
- NotificationEntitySchema: () => NotificationEntitySchema,
41
- OrderBook: () => OrderBook,
42
- OrderBookEntry: () => OrderBookEntry,
43
- OrderBookNotification: () => OrderBookNotification,
44
- OrderBookNotificationMeta: () => OrderBookNotificationMeta,
45
- OrderHistoryEntry: () => OrderHistoryEntry,
46
- OrderHistoryEntryNotification: () => OrderHistoryEntryNotification,
47
- OrderHistoryOrderType: () => OrderHistoryOrderType,
48
- OrderHistoryOrderTypeSchema: () => OrderHistoryOrderTypeSchema,
49
- OrderHistoryStatus: () => OrderHistoryStatus,
50
- OrderHistoryStatusSchema: () => OrderHistoryStatusSchema,
51
- OrderHistoryUIDirection: () => OrderHistoryUIDirection,
52
- OrderHistoryUIDirectionSchema: () => OrderHistoryUIDirectionSchema,
53
- PaginationMeta: () => PaginationMeta,
54
- Pool: () => Pool,
55
- PoolPriceCandle: () => PoolPriceCandle,
56
- PoolProvider: () => PoolProvider,
57
- PoolProviderSchema: () => PoolProviderSchema,
58
- PoolSnapshot: () => PoolSnapshot,
59
- PoolSubscriptionTopic: () => PoolSubscriptionTopic,
60
- PoolSubscriptionTopicSchema: () => PoolSubscriptionTopicSchema,
61
- PoolSwap: () => PoolSwap,
62
- PoolSwapNotification: () => PoolSwapNotification,
63
- PoolTicks: () => PoolTicks,
64
- StakingLeaderboardPage: () => StakingLeaderboardPage,
65
- StakingLeaderboardPosition: () => StakingLeaderboardPosition,
66
- StakingPosition: () => StakingPosition,
67
- StakingPositionHistoryAction: () => StakingPositionHistoryAction,
68
- StakingPositionHistoryActionType: () => StakingPositionHistoryActionType,
69
- StakingPositionHistoryActionTypeSchema: () => StakingPositionHistoryActionTypeSchema,
70
- StakingPositionNotification: () => StakingPositionNotification,
71
- StakingRevenueStatsGroup: () => StakingRevenueStatsGroup,
72
- StakingTreasury: () => StakingTreasury,
73
- StateSnapshot: () => StateSnapshot,
74
- StateSnapshotNotification: () => StateSnapshotNotification,
75
- SwapQuoteByInput: () => SwapQuoteByInput,
76
- SwapQuoteByOutput: () => SwapQuoteByOutput,
77
- Tick: () => Tick,
78
- TokenOraclePrice: () => TokenOraclePrice,
79
- TokensPnlSchema: () => TokensPnlSchema,
80
- TradableAmount: () => TradableAmount,
81
- TradeHistoryAction: () => TradeHistoryAction,
82
- TradeHistoryActionSchema: () => TradeHistoryActionSchema,
83
- TradeHistoryEntry: () => TradeHistoryEntry,
84
- TradeHistoryEntryNotification: () => TradeHistoryEntryNotification,
85
- TradeHistoryUIDirection: () => TradeHistoryUIDirection,
86
- TradeHistoryUIDirectionSchema: () => TradeHistoryUIDirectionSchema,
87
- TunaLpPositionAction: () => TunaLpPositionAction,
88
- TunaLpPositionActionClose: () => TunaLpPositionActionClose,
89
- TunaLpPositionActionCollectAndCompoundFees: () => TunaLpPositionActionCollectAndCompoundFees,
90
- TunaLpPositionActionCollectFees: () => TunaLpPositionActionCollectFees,
91
- TunaLpPositionActionDecreaseLiquidity: () => TunaLpPositionActionDecreaseLiquidity,
92
- TunaLpPositionActionIncreaseLiquidity: () => TunaLpPositionActionIncreaseLiquidity,
93
- TunaLpPositionActionLiquidate: () => TunaLpPositionActionLiquidate,
94
- TunaLpPositionActionOpen: () => TunaLpPositionActionOpen,
95
- TunaLpPositionActionParametersUpdate: () => TunaLpPositionActionParametersUpdate,
96
- TunaLpPositionActionRepayDebt: () => TunaLpPositionActionRepayDebt,
97
- TunaLpPositionAutoCompounding: () => TunaLpPositionAutoCompounding,
98
- TunaLpPositionAutoCompoundingSchema: () => TunaLpPositionAutoCompoundingSchema,
99
- TunaLpPositionDtoSchema: () => TunaLpPositionDtoSchema,
100
- TunaLpPositionFlagsSchema: () => TunaLpPositionFlagsSchema,
101
- TunaLpPositionHistorical: () => TunaLpPositionHistorical,
102
- TunaLpPositionParameters: () => TunaLpPositionParameters,
103
- TunaLpPositionTokenPrices: () => TunaLpPositionTokenPrices,
104
- TunaLpPositionTransfer: () => TunaLpPositionTransfer,
105
- TunaLpPositionValue: () => TunaLpPositionValue,
106
- TunaPositionLegacy: () => TunaPositionLegacy,
107
- TunaPositionPoolSchema: () => TunaPositionPoolSchema,
108
- TunaPositionPoolToken: () => TunaPositionPoolToken,
109
- TunaPositionPoolTokenSchema: () => TunaPositionPoolTokenSchema,
110
- TunaPositionState: () => TunaPositionState,
111
- TunaPositionStateSchema: () => TunaPositionStateSchema,
112
- TunaPositionTokenPnlSchema: () => TunaPositionTokenPnlSchema,
113
- TunaSpotPosition: () => TunaSpotPosition,
114
- TunaSpotPositionState: () => TunaSpotPositionState,
115
- TunaSpotPositionStateSchema: () => TunaSpotPositionStateSchema,
116
- UpdateStreamSubscriptionResult: () => UpdateStreamSubscriptionResult,
117
- UsdPnlSchema: () => UsdPnlSchema,
118
- Vault: () => Vault,
119
- VaultHistoricalStats: () => VaultHistoricalStats,
120
- WalletSubscriptionTopic: () => WalletSubscriptionTopic,
121
- WalletSubscriptionTopicSchema: () => WalletSubscriptionTopicSchema
122
- });
123
- import { z as z9 } from "zod";
124
-
125
- // src/client/schemas/basic.ts
126
- import { z } from "zod";
127
- var AmountWithUsdSchema = z.object({
128
- amount: z.coerce.bigint(),
129
- usd: z.number()
130
- });
131
- var AmountWithoutUsdSchema = z.object({
132
- amount: z.coerce.bigint()
133
- });
134
- var TokensPnlSchema = z.object({
135
- amount: z.coerce.bigint(),
136
- rate: z.number()
137
- });
138
- var UsdPnlSchema = z.object({
139
- amount: z.number(),
140
- rate: z.number()
141
- });
142
- var PoolProvider = {
143
- ORCA: "orca",
144
- FUSION: "fusion"
145
- };
146
- var PoolProviderSchema = z.enum([PoolProvider.ORCA, ...Object.values(PoolProvider)]);
147
-
148
- // src/client/schemas/order_book.ts
149
- import z2 from "zod";
150
- var OrderBookEntry = z2.object({
151
- concentratedAmount: z2.coerce.bigint(),
152
- concentratedAmountQuote: z2.coerce.bigint(),
153
- concentratedTotal: z2.coerce.bigint(),
154
- concentratedTotalQuote: z2.coerce.bigint(),
155
- limitAmount: z2.coerce.bigint(),
156
- limitAmountQuote: z2.coerce.bigint(),
157
- limitTotal: z2.coerce.bigint(),
158
- limitTotalQuote: z2.coerce.bigint(),
159
- price: z2.number(),
160
- askSide: z2.boolean()
161
- });
162
- var OrderBook = z2.object({
163
- entries: OrderBookEntry.array(),
164
- poolPrice: z2.number()
165
- });
166
-
167
- // src/client/schemas/state_snapshot.ts
168
- import z8 from "zod";
169
-
170
- // src/client/schemas/limit_orders.ts
171
- import { z as z5 } from "zod";
172
-
173
- // src/client/schemas/mint.ts
174
- import { z as z3 } from "zod";
175
- var Mint = z3.object({
176
- mint: z3.string(),
177
- symbol: z3.string(),
178
- name: z3.string(),
179
- logo: z3.string(),
180
- decimals: z3.number()
181
- });
182
-
183
- // src/client/schemas/positions_shared.ts
184
- import z4 from "zod";
185
- var TunaPositionPoolSchema = z4.object({
186
- addr: z4.string(),
187
- price: z4.number(),
188
- tickSpacing: z4.number()
189
- });
190
- var TunaPositionPoolToken = {
191
- A: "a",
192
- B: "b"
193
- };
194
- var TunaPositionPoolTokenSchema = z4.enum(Object.values(TunaPositionPoolToken));
195
-
196
- // src/client/schemas/limit_orders.ts
197
- var LimitOrderState = {
198
- OPEN: "open",
199
- PARTIALLY_FILLED: "partially_filled",
200
- FILLED: "filled",
201
- COMPLETE: "complete",
202
- CANCELLED: "cancelled"
203
- };
204
- var LimitOrderStateSchema = z5.enum([LimitOrderState.OPEN, ...Object.values(LimitOrderState)]);
205
- var LimitOrder = z5.object({
206
- address: z5.string(),
207
- orderMint: z5.string(),
208
- mintA: Mint,
209
- mintB: Mint,
210
- pool: TunaPositionPoolSchema,
211
- state: LimitOrderStateSchema,
212
- aToB: z5.boolean(),
213
- tickIndex: z5.number(),
214
- fillRatio: z5.number(),
215
- openTxSignature: z5.string(),
216
- closeTxSignature: z5.nullable(z5.string()),
217
- amountIn: AmountWithUsdSchema,
218
- amountOut: AmountWithUsdSchema,
219
- openedAt: z5.coerce.date(),
220
- closedAt: z5.nullable(z5.coerce.date())
221
- });
222
-
223
- // src/client/schemas/lp_positions.ts
224
- import z6 from "zod";
225
- var LpPositionLimitOrderSwap = {
226
- NO_SWAP: "no_swap",
227
- SWAP_TO_TOKEN_A: "swap_to_token_a",
228
- SWAP_TO_TOKEN_B: "swap_to_token_b"
229
- };
230
- var LpPositionAutoCompound = {
231
- NO_AUTO_COMPOUND: "no_auto_compound",
232
- AUTO_COMPOUND: "auto_compound",
233
- AUTO_COMPOUND_WITH_LEVERAGE: "auto_compound_with_leverage"
234
- };
235
- var LpPositionRebalance = {
236
- NO_REBALANCE: "no_rebalance",
237
- AUTO_REBALANCE: "auto_rebalance"
238
- };
239
- var LpPositionsActionType = {
240
- OPEN_POSITION: "open_position",
241
- CLOSE_POSITION: "close_position",
242
- INCREASE_LIQUIDITY: "increase_liquidity",
243
- DECREASE_LIQUIDITY: "decrease_liquidity",
244
- REPAY_DEBT: "repay_debt",
245
- LIQUIDATE: "liquidate",
246
- EXECUTE_LIMIT_ORDER: "execute_limit_order",
247
- COLLECT_FEES: "collect_fees",
248
- COLLECT_REWARDS: "collect_rewards",
249
- COLLECT_AND_COMPOUND_FEES: "collect_and_compound_fees",
250
- REBALANCE_POSITION: "rebalance_position",
251
- SET_LIMIT_ORDERS: "set_limit_orders",
252
- SET_FLAGS: "set_flags",
253
- SET_REBALANCE_THRESHOLD: "set_rebalance_threshold"
254
- };
255
- var LpPositionLimitOrderSwapSchema = z6.enum(Object.values(LpPositionLimitOrderSwap));
256
- var LpPositionAutoCompoundSchema = z6.enum(Object.values(LpPositionAutoCompound));
257
- var LpPositionRebalanceSchema = z6.enum(Object.values(LpPositionRebalance));
258
- var LpPositionsActionTypeSchema = z6.enum(Object.values(LpPositionsActionType));
259
- var TunaPositionState = {
260
- OPEN: "open",
261
- LIQUIDATED: "liquidated",
262
- CLOSED_BY_LIMIT_ORDER: "closed_by_limit_order",
263
- CLOSED: "closed"
264
- };
265
- var TunaPositionStateSchema = z6.enum([TunaPositionState.OPEN, ...Object.values(TunaPositionState)]);
266
- var TunaLpPositionAutoCompounding = {
267
- WITH_LEVERAGE: "with_leverage",
268
- WITHOUT_LEVERAGE: "without_leverage"
269
- };
270
- var TunaLpPositionAutoCompoundingSchema = z6.enum(
271
- Object.values(TunaLpPositionAutoCompounding)
272
- );
273
- var TunaPositionTokenPnlSchema = z6.object({
274
- amount: z6.coerce.bigint(),
275
- bps: z6.number()
276
- });
277
- var TunaLpPositionFlagsSchema = z6.object({
278
- lowerLimitOrderSwapToToken: z6.nullable(TunaPositionPoolTokenSchema),
279
- upperLimitOrderSwapToToken: z6.nullable(TunaPositionPoolTokenSchema),
280
- autoCompounding: z6.nullable(TunaLpPositionAutoCompoundingSchema),
281
- autoRebalancing: z6.boolean()
282
- });
283
- var TunaLpPositionDtoSchema = z6.object({
284
- address: z6.string(),
285
- authority: z6.string(),
286
- version: z6.number(),
287
- state: TunaPositionStateSchema,
288
- positionMint: z6.string(),
289
- liquidity: z6.coerce.bigint(),
290
- tickLowerIndex: z6.number(),
291
- tickUpperIndex: z6.number(),
292
- lowerLimitOrderPrice: z6.number(),
293
- upperLimitOrderPrice: z6.number(),
294
- entryPrice: z6.number(),
295
- flags: TunaLpPositionFlagsSchema,
296
- mintA: Mint,
297
- mintB: Mint,
298
- pool: TunaPositionPoolSchema,
299
- marketMaker: PoolProviderSchema,
300
- depositedCollateralA: AmountWithUsdSchema,
301
- depositedCollateralB: AmountWithUsdSchema,
302
- leverage: z6.number(),
303
- maxLeverage: z6.number(),
304
- liquidationPriceLower: z6.number(),
305
- liquidationPriceUpper: z6.number(),
306
- initialDebtA: AmountWithUsdSchema,
307
- initialDebtB: AmountWithUsdSchema,
308
- currentDebtA: AmountWithUsdSchema,
309
- currentDebtB: AmountWithUsdSchema,
310
- leftoversA: AmountWithUsdSchema,
311
- leftoversB: AmountWithUsdSchema,
312
- yieldA: AmountWithUsdSchema,
313
- yieldB: AmountWithUsdSchema,
314
- compoundedYieldA: AmountWithUsdSchema,
315
- compoundedYieldB: AmountWithUsdSchema,
316
- totalA: AmountWithUsdSchema,
317
- totalB: AmountWithUsdSchema,
318
- pnlA: TokensPnlSchema,
319
- pnlB: TokensPnlSchema,
320
- pnlUsd: UsdPnlSchema,
321
- openedAt: z6.coerce.date(),
322
- closedAt: z6.nullable(z6.coerce.date())
323
- });
324
- var TunaLpPositionHistorical = z6.object({
325
- positionAddress: z6.string(),
326
- authority: z6.string(),
327
- pool: z6.string(),
328
- state: TunaPositionStateSchema,
329
- lowerPrice: z6.number(),
330
- upperPrice: z6.number(),
331
- lowerLimitOrder: z6.number().nullable(),
332
- upperLimitOrder: z6.number().nullable(),
333
- marketMaker: PoolProviderSchema,
334
- openedAt: z6.coerce.date(),
335
- closedAt: z6.coerce.date().nullable(),
336
- totalValueUsd: z6.number(),
337
- leverage: z6.number(),
338
- initialLeverage: z6.number(),
339
- totalDepositUsd: z6.number(),
340
- totalWithdrawnUsd: z6.number(),
341
- feesSumUsd: z6.number(),
342
- closedPnlSumUsd: z6.number(),
343
- entryPrice: z6.number(),
344
- exitPrice: z6.number().nullable()
345
- });
346
- var TunaPositionLegacy = z6.object({
347
- address: z6.string(),
348
- authority: z6.string(),
349
- version: z6.number(),
350
- state: TunaPositionStateSchema,
351
- positionMint: z6.string(),
352
- liquidity: z6.coerce.bigint(),
353
- tickLowerIndex: z6.number(),
354
- tickUpperIndex: z6.number(),
355
- entrySqrtPrice: z6.coerce.bigint(),
356
- lowerLimitOrderSqrtPrice: z6.coerce.bigint(),
357
- upperLimitOrderSqrtPrice: z6.coerce.bigint(),
358
- flags: z6.number(),
359
- pool: z6.string(),
360
- poolSqrtPrice: z6.coerce.bigint(),
361
- depositedCollateralA: AmountWithoutUsdSchema,
362
- depositedCollateralB: AmountWithoutUsdSchema,
363
- depositedCollateralUsd: z6.object({
364
- amount: z6.number()
365
- }),
366
- loanFundsA: AmountWithUsdSchema,
367
- loanFundsB: AmountWithUsdSchema,
368
- currentLoanA: AmountWithUsdSchema,
369
- currentLoanB: AmountWithUsdSchema,
370
- leftoversA: AmountWithUsdSchema,
371
- leftoversB: AmountWithUsdSchema,
372
- yieldA: AmountWithUsdSchema,
373
- yieldB: AmountWithUsdSchema,
374
- compoundedYieldA: AmountWithUsdSchema,
375
- compoundedYieldB: AmountWithUsdSchema,
376
- totalA: AmountWithUsdSchema,
377
- totalB: AmountWithUsdSchema,
378
- pnlA: TokensPnlSchema,
379
- pnlB: TokensPnlSchema,
380
- pnlUsd: UsdPnlSchema,
381
- openedAt: z6.coerce.date(),
382
- updatedAtSlot: z6.coerce.bigint(),
383
- closedAt: z6.nullable(z6.coerce.date())
384
- });
385
- var TunaLpPositionParameters = z6.object({
386
- lowerPrice: z6.number(),
387
- upperPrice: z6.number(),
388
- lowerLimitOrder: z6.number().nullable(),
389
- upperLimitOrder: z6.number().nullable(),
390
- lowerLimitOrderSwap: LpPositionLimitOrderSwapSchema,
391
- upperLimitOrderSwap: LpPositionLimitOrderSwapSchema,
392
- autoCompound: LpPositionAutoCompoundSchema,
393
- rebalance: LpPositionRebalanceSchema,
394
- rebalanceThresholdTicks: z6.number()
395
- });
396
- var TunaLpPositionValue = z6.object({
397
- totalValueA: z6.number(),
398
- totalValueB: z6.number(),
399
- totalValueUsd: z6.number(),
400
- loanFundsA: z6.number(),
401
- loanFundsB: z6.number(),
402
- loanFundsUsd: z6.number(),
403
- leverage: z6.number()
404
- });
405
- var TunaLpPositionTransfer = z6.object({
406
- amountA: z6.number(),
407
- amountB: z6.number(),
408
- amountUsd: z6.number()
409
- });
410
- var TunaLpPositionTokenPrices = z6.object({
411
- tokenPriceA: z6.number(),
412
- tokenPriceB: z6.number()
413
- });
414
- var TunaLpPositionActionOpen = z6.object({
415
- parameters: TunaLpPositionParameters
416
- });
417
- var TunaLpPositionActionClose = z6.object({
418
- toOwner: TunaLpPositionTransfer.nullable(),
419
- prices: TunaLpPositionTokenPrices.nullable()
420
- });
421
- var TunaLpPositionActionIncreaseLiquidity = z6.object({
422
- fromPosition: TunaLpPositionValue.nullable(),
423
- toPosition: TunaLpPositionValue,
424
- fromOwner: TunaLpPositionTransfer,
425
- fromLending: TunaLpPositionTransfer,
426
- protocolFees: TunaLpPositionTransfer,
427
- prices: TunaLpPositionTokenPrices
428
- });
429
- var TunaLpPositionActionDecreaseLiquidity = z6.object({
430
- withdrawPercent: z6.number(),
431
- closedPnlUsd: z6.number(),
432
- fromPosition: TunaLpPositionValue,
433
- toPosition: TunaLpPositionValue.nullable(),
434
- toOwner: TunaLpPositionTransfer,
435
- toLending: TunaLpPositionTransfer,
436
- collectedFees: TunaLpPositionTransfer,
437
- prices: TunaLpPositionTokenPrices
438
- });
439
- var TunaLpPositionActionLiquidate = z6.object({
440
- withdrawPercent: z6.number(),
441
- fromPosition: TunaLpPositionValue,
442
- toLending: TunaLpPositionTransfer,
443
- protocolFees: TunaLpPositionTransfer,
444
- prices: TunaLpPositionTokenPrices
445
- });
446
- var TunaLpPositionActionRepayDebt = z6.object({
447
- fromPosition: TunaLpPositionValue,
448
- toPosition: TunaLpPositionValue,
449
- fromOwner: TunaLpPositionTransfer,
450
- toLending: TunaLpPositionTransfer,
451
- prices: TunaLpPositionTokenPrices
452
- });
453
- var TunaLpPositionActionCollectFees = z6.object({
454
- closedPnlUsd: z6.number(),
455
- position: TunaLpPositionValue,
456
- collectedFees: TunaLpPositionTransfer,
457
- toOwner: TunaLpPositionTransfer,
458
- prices: TunaLpPositionTokenPrices
459
- });
460
- var TunaLpPositionActionCollectAndCompoundFees = z6.object({
461
- fromPosition: TunaLpPositionValue,
462
- toPosition: TunaLpPositionValue,
463
- collectedFees: TunaLpPositionTransfer,
464
- fromLending: TunaLpPositionTransfer,
465
- protocolFees: TunaLpPositionTransfer,
466
- prices: TunaLpPositionTokenPrices
467
- });
468
- var TunaLpPositionActionParametersUpdate = z6.object({
469
- fromParameters: TunaLpPositionParameters,
470
- toParameters: TunaLpPositionParameters
471
- });
472
- var TunaLpPositionAction = z6.object({
473
- action: LpPositionsActionTypeSchema,
474
- txSignature: z6.string(),
475
- txTimestamp: z6.coerce.date(),
476
- data: z6.object({
477
- /** defined for: IncreaseLiquidity, DecreaseLiquidity, Liquidate, ExecuteLimitOrder, RepayDebt, CollectAndCompoundFees */
478
- fromPosition: TunaLpPositionValue.optional().nullable(),
479
- /** defined for: IncreaseLiquidity, DecreaseLiquidity, Liquidate, ExecuteLimitOrder, RepayDebt, CollectAndCompoundFees */
480
- toPosition: TunaLpPositionValue.optional().nullable(),
481
- /** defined for: CollectFees */
482
- position: TunaLpPositionValue.optional().nullable(),
483
- /** defined for: IncreaseLiquidity, RepayDebt */
484
- fromOwner: TunaLpPositionTransfer.optional(),
485
- /** defined for: DecreaseLiquidity, CollectFees, ClosePosition; nullable for: ClosePosition */
486
- toOwner: TunaLpPositionTransfer.optional().nullable(),
487
- /** defined for: IncreaseLiquidity, CollectAndCompoundFees */
488
- fromLending: TunaLpPositionTransfer.optional(),
489
- /** defined for: DecreaseLiquidity, Liquidate, ExecuteLimitOrder, RepayDebt */
490
- toLending: TunaLpPositionTransfer.optional(),
491
- /** defined for: CollectFees, CollectAndCompoundFees */
492
- collectedFees: TunaLpPositionTransfer.optional(),
493
- /** defined for: IncreaseLiquidity, Liquidate, ExecuteLimitOrder, CollectAndCompoundFees */
494
- protocolFees: TunaLpPositionTransfer.optional(),
495
- /** defined for: IncreaseLiquidity, DecreaseLiquidity, Liquidate, ExecuteLimitOrder, RepayDebt, CollectFees, CollectAndCompoundFees, ClosePosition; nullable for: ClosePosition */
496
- prices: TunaLpPositionTokenPrices.optional().nullable(),
497
- /** defined for: OpenPosition */
498
- parameters: TunaLpPositionParameters.optional(),
499
- /** defined for: ParametersUpdate */
500
- fromParameters: TunaLpPositionParameters.optional(),
501
- /** defined for: ParametersUpdate */
502
- toParameters: TunaLpPositionParameters.optional(),
503
- /** defined for: DecreaseLiquidity */
504
- withdrawPercent: z6.number().optional(),
505
- /** defined for: DecreaseLiquidity, CollectFees */
506
- closedPnlUsd: z6.number().optional()
507
- })
508
- });
509
-
510
- // src/client/schemas/spot_positions.ts
511
- import { z as z7 } from "zod";
512
- var TunaSpotPositionState = {
513
- OPEN: "open",
514
- CLOSED: "closed"
515
- };
516
- var TunaSpotPositionStateSchema = z7.enum([
517
- TunaSpotPositionState.OPEN,
518
- ...Object.values(TunaSpotPositionState)
519
- ]);
520
- var TunaSpotPosition = z7.object({
521
- address: z7.string(),
522
- authority: z7.string(),
523
- version: z7.number(),
524
- state: TunaSpotPositionStateSchema,
525
- lowerLimitOrderPrice: z7.number(),
526
- upperLimitOrderPrice: z7.number(),
527
- entryPrice: z7.number(),
528
- mintA: Mint,
529
- mintB: Mint,
530
- pool: TunaPositionPoolSchema,
531
- positionToken: TunaPositionPoolTokenSchema,
532
- collateralToken: TunaPositionPoolTokenSchema,
533
- marketMaker: PoolProviderSchema,
534
- depositedCollateral: AmountWithUsdSchema,
535
- initialDebt: AmountWithUsdSchema,
536
- currentDebt: AmountWithUsdSchema,
537
- total: AmountWithUsdSchema,
538
- leverage: z7.number(),
539
- maxLeverage: z7.number(),
540
- liquidationPrice: z7.number(),
541
- pnlUsd: UsdPnlSchema,
542
- openedAt: z7.coerce.date(),
543
- closedAt: z7.nullable(z7.coerce.date())
544
- });
545
- var IncreaseSpotPositionQuote = z7.object({
546
- /** Required collateral amount */
547
- collateralAmount: z7.coerce.bigint(),
548
- /** Required amount to borrow */
549
- borrowAmount: z7.coerce.bigint(),
550
- /** Estimated position size in the position token. */
551
- estimatedAmount: z7.coerce.bigint(),
552
- /** Swap input amount. */
553
- swapInputAmount: z7.coerce.bigint(),
554
- /** Minimum swap output amount according to the provided slippage. */
555
- minSwapOutputAmount: z7.coerce.bigint(),
556
- /** Protocol fee in token A */
557
- protocolFeeA: z7.coerce.bigint(),
558
- /** Protocol fee in token B */
559
- protocolFeeB: z7.coerce.bigint(),
560
- /** Price impact in percents */
561
- priceImpact: z7.number(),
562
- /** Liquidation price */
563
- liquidationPrice: z7.number()
564
- });
565
- var DecreaseSpotPositionQuote = z7.object({
566
- /** Confirmed position decrease percentage (100% = 1.0) */
567
- decreasePercent: z7.number(),
568
- /** The maximum acceptable swap input amount for position decrease according to the provided slippage
569
- * (if collateral_token == position_token) OR the minimum swap output amount (if collateral_token != position_token).
570
- */
571
- requiredSwapAmount: z7.coerce.bigint(),
572
- /** Estimated total amount of the adjusted position */
573
- estimatedAmount: z7.coerce.bigint(),
574
- /** Estimated amount of the withdrawn collateral */
575
- estimatedWithdrawnCollateral: z7.coerce.bigint(),
576
- /** Price impact in percents */
577
- priceImpact: z7.number(),
578
- /** Liquidation price */
579
- liquidationPrice: z7.number()
580
- });
581
- var CloseSpotPositionQuote = z7.object({
582
- /** Position decrease percentage */
583
- decreasePercent: z7.number(),
584
- /** The maximum acceptable swap input amount for position decrease according to the provided slippage
585
- * (if collateral_token == position_token) OR the minimum swap output amount (if collateral_token != position_token).
586
- */
587
- requiredSwapAmount: z7.coerce.bigint(),
588
- /** Estimated amount of the withdrawn collateral */
589
- estimatedWithdrawnCollateral: z7.coerce.bigint(),
590
- /** Price impact in percents */
591
- priceImpact: z7.number()
592
- });
593
-
594
- // src/client/schemas/state_snapshot.ts
595
- var PoolSnapshot = z8.object({
596
- liquidity: z8.coerce.bigint(),
597
- tickCurrentIndex: z8.number(),
598
- price: z8.number(),
599
- sqrtPrice: z8.number(),
600
- tvl: z8.number(),
601
- priceChange24H: z8.number(),
602
- volume24H: z8.number(),
603
- fees24H: z8.number(),
604
- borrowedFundsA: AmountWithUsdSchema,
605
- borrowedFundsB: AmountWithUsdSchema,
606
- borrowLimitA: AmountWithUsdSchema,
607
- borrowLimitB: AmountWithUsdSchema
608
- });
609
- var StateSnapshot = z8.object({
610
- slot: z8.coerce.bigint(),
611
- blockTime: z8.coerce.date(),
612
- pools: z8.optional(z8.record(z8.string(), PoolSnapshot)),
613
- tunaSpotPositions: z8.optional(z8.array(TunaSpotPosition)),
614
- tunaLpPositions: z8.optional(z8.array(TunaLpPositionDtoSchema)),
615
- fusionLimitOrders: z8.optional(z8.array(LimitOrder)),
616
- orderBooks: z8.optional(z8.record(z8.string(), OrderBook))
617
- });
618
-
619
- // src/client/schemas.ts
620
- var NotificationEntity = {
621
- POOL_SWAP: "pool_swap",
622
- POOL_PRICE: "pool_price",
623
- ORDER_BOOK: "order_book",
624
- TUNA_POSITION: "tuna_position",
625
- TUNA_SPOT_POSITION: "tuna_spot_position",
626
- LENDING_POSITION: "lending_position",
627
- STAKING_POSITION: "staking_position",
628
- FUSION_LIMIT_ORDER: "fusion_limit_order",
629
- TRADE_HISTORY_ENTRY: "trade_history_entry",
630
- ORDER_HISTORY_ENTRY: "order_history_entry",
631
- STATE_SNAPSHOT: "state_snapshot"
632
- };
633
- var NotificationAction = {
634
- CREATE: "create",
635
- UPDATE: "update"
636
- };
637
- var TradeHistoryAction = {
638
- SWAP: "swap",
639
- LIMIT_ORDER_FILL: "limit_order_fill",
640
- POSITION_INCREASE: "position_increase",
641
- POSITION_DECREASE: "position_decrease",
642
- TAKE_PROFIT: "take_profit",
643
- STOP_LOSS: "stop_loss",
644
- LIQUIDATION: "liquidation"
645
- };
646
- var TradeHistoryUIDirection = {
647
- BUY: "buy",
648
- SELL: "sell",
649
- OPEN_LONG: "open_long",
650
- CLOSE_LONG: "close_long",
651
- OPEN_SHORT: "open_short",
652
- CLOSE_SHORT: "close_short"
653
- };
654
- var OrderHistoryOrderType = {
655
- MARKET: "market",
656
- LIMIT: "limit",
657
- TAKE_PROFIT_MARKET: "take_profit_market",
658
- STOP_LOSS_MARKET: "stop_loss_market",
659
- LIQUIDATION_MARKET: "liquidation_market"
660
- };
661
- var OrderHistoryStatus = {
662
- OPEN: "open",
663
- PARTIALLY_FILLED: "partially_filled",
664
- FILLED: "filled",
665
- CANCELLED: "cancelled",
666
- CLAIMED: "claimed",
667
- REJECTED: "rejected"
668
- };
669
- var OrderHistoryUIDirection = {
670
- BUY: "buy",
671
- SELL: "sell",
672
- LONG: "long",
673
- SHORT: "short"
674
- };
675
- var StakingPositionHistoryActionType = {
676
- STAKE: "stake",
677
- UNSTAKE: "unstake",
678
- WITHDRAW: "withdraw",
679
- CLAIM_REWARDS: "claim_rewards",
680
- COMPOUND_REWARDS: "compound_rewards"
681
- };
682
- var PoolSubscriptionTopic = {
683
- ORDER_BOOK: "order_book",
684
- POOL: "pool",
685
- POOL_SWAPS: "pool_swaps"
686
- };
687
- var WalletSubscriptionTopic = {
688
- TUNA_POSITIONS: "tuna_positions",
689
- TUNA_SPOT_POSITIONS: "tuna_spot_positions",
690
- LENDING_POSITIONS: "lending_positions",
691
- FUSION_LIMIT_ORDERS: "fusion_limit_orders",
692
- STAKING_POSITION: "staking_position",
693
- TRADE_HISTORY: "trade_history",
694
- ORDER_HISTORY: "order_history"
695
- };
696
- var NotificationEntitySchema = z9.enum([NotificationEntity.POOL_SWAP, ...Object.values(NotificationEntity)]);
697
- var NotificationActionSchema = z9.enum([NotificationAction.CREATE, ...Object.values(NotificationAction)]);
698
- var TradeHistoryActionSchema = z9.enum([TradeHistoryAction.SWAP, ...Object.values(TradeHistoryAction)]);
699
- var TradeHistoryUIDirectionSchema = z9.enum([
700
- TradeHistoryUIDirection.BUY,
701
- ...Object.values(TradeHistoryUIDirection)
702
- ]);
703
- var OrderHistoryOrderTypeSchema = z9.enum([
704
- OrderHistoryOrderType.MARKET,
705
- ...Object.values(OrderHistoryOrderType)
706
- ]);
707
- var OrderHistoryStatusSchema = z9.enum([OrderHistoryStatus.OPEN, ...Object.values(OrderHistoryStatus)]);
708
- var OrderHistoryUIDirectionSchema = z9.enum([
709
- OrderHistoryUIDirection.BUY,
710
- ...Object.values(OrderHistoryUIDirection)
711
- ]);
712
- var StakingPositionHistoryActionTypeSchema = z9.enum([
713
- StakingPositionHistoryActionType.STAKE,
714
- ...Object.values(StakingPositionHistoryActionType)
715
- ]);
716
- var PoolSubscriptionTopicSchema = z9.enum([
717
- PoolSubscriptionTopic.ORDER_BOOK,
718
- ...Object.values(PoolSubscriptionTopic)
719
- ]);
720
- var WalletSubscriptionTopicSchema = z9.enum([
721
- WalletSubscriptionTopic.TUNA_POSITIONS,
722
- ...Object.values(WalletSubscriptionTopic)
723
- ]);
724
- var PaginationMeta = z9.object({
725
- total: z9.number()
726
- });
727
- var Market = z9.object({
728
- address: z9.string(),
729
- addressLookupTable: z9.string(),
730
- poolAddress: z9.string(),
731
- poolFeeRate: z9.number(),
732
- provider: PoolProviderSchema,
733
- maxLeverage: z9.number(),
734
- maxSwapSlippage: z9.number(),
735
- protocolFee: z9.number(),
736
- rebalanceProtocolFee: z9.number(),
737
- protocolFeeOnCollateral: z9.number(),
738
- liquidationFee: z9.number(),
739
- liquidationThreshold: z9.number(),
740
- oraclePriceDeviationThreshold: z9.number(),
741
- maxSpotPositionSizeA: AmountWithUsdSchema,
742
- maxSpotPositionSizeB: AmountWithUsdSchema,
743
- borrowedFundsA: AmountWithUsdSchema,
744
- borrowedFundsB: AmountWithUsdSchema,
745
- availableBorrowA: AmountWithUsdSchema,
746
- availableBorrowB: AmountWithUsdSchema,
747
- borrowLimitA: AmountWithUsdSchema,
748
- borrowLimitB: AmountWithUsdSchema,
749
- disabled: z9.boolean(),
750
- createdAt: z9.coerce.date()
751
- });
752
- var TokenOraclePrice = z9.object({
753
- mint: z9.string(),
754
- price: z9.coerce.bigint(),
755
- decimals: z9.number(),
756
- time: z9.coerce.date()
757
- });
758
- var Vault = z9.object({
759
- address: z9.string(),
760
- mint: z9.string(),
761
- depositedFunds: AmountWithUsdSchema,
762
- borrowedFunds: AmountWithUsdSchema,
763
- supplyLimit: AmountWithUsdSchema,
764
- borrowedShares: z9.coerce.bigint(),
765
- depositedShares: z9.coerce.bigint(),
766
- supplyApy: z9.number(),
767
- borrowApy: z9.number(),
768
- interestRate: z9.coerce.bigint(),
769
- utilization: z9.number(),
770
- pythOracleFeedId: z9.string(),
771
- pythOraclePriceUpdate: z9.string()
772
- });
773
- var VaultHistoricalStats = z9.object({
774
- date: z9.preprocess((val, ctx) => {
775
- if (typeof val === "string") {
776
- const [year, month, day] = val.split("-").map(Number);
777
- return new Date(year, month - 1, day);
778
- }
779
- ctx.addIssue({
780
- code: "custom",
781
- message: "Not a valid date string"
782
- });
783
- return z9.NEVER;
784
- }, z9.date()),
785
- supply: AmountWithUsdSchema,
786
- borrow: AmountWithUsdSchema,
787
- supplyApy: z9.number(),
788
- borrowApr: z9.number()
789
- });
790
- var Pool = z9.object({
791
- address: z9.string(),
792
- provider: PoolProviderSchema,
793
- tokenAMint: z9.string(),
794
- tokenBMint: z9.string(),
795
- tokenAVault: z9.string(),
796
- tokenBVault: z9.string(),
797
- tvlUsdc: z9.coerce.number(),
798
- priceChange24H: z9.number(),
799
- tickSpacing: z9.number(),
800
- feeRate: z9.number(),
801
- olpFeeRate: z9.nullable(z9.number()),
802
- protocolFeeRate: z9.number(),
803
- liquidity: z9.coerce.bigint(),
804
- sqrtPrice: z9.coerce.bigint(),
805
- tickCurrentIndex: z9.number(),
806
- stats: z9.object({
807
- "24h": z9.object({
808
- volume: z9.coerce.number(),
809
- fees: z9.coerce.number(),
810
- rewards: z9.coerce.number(),
811
- yieldOverTvl: z9.coerce.number()
812
- }),
813
- "7d": z9.object({
814
- volume: z9.coerce.number(),
815
- fees: z9.coerce.number(),
816
- rewards: z9.coerce.number(),
817
- yieldOverTvl: z9.coerce.number()
818
- }),
819
- "30d": z9.object({
820
- volume: z9.coerce.number(),
821
- fees: z9.coerce.number(),
822
- rewards: z9.coerce.number(),
823
- yieldOverTvl: z9.coerce.number()
824
- })
825
- })
826
- });
827
- var Tick = z9.object({
828
- index: z9.number(),
829
- liquidity: z9.coerce.bigint()
830
- });
831
- var PoolTicks = z9.object({
832
- tickSpacing: z9.number(),
833
- ticks: Tick.array()
834
- });
835
- var LendingPosition = z9.object({
836
- address: z9.string(),
837
- authority: z9.string(),
838
- mint: z9.string(),
839
- vault: z9.string(),
840
- shares: z9.coerce.bigint(),
841
- funds: AmountWithUsdSchema,
842
- earned: AmountWithUsdSchema
843
- });
844
- var PoolSwap = z9.object({
845
- id: z9.string(),
846
- amountIn: z9.coerce.bigint(),
847
- amountOut: z9.coerce.bigint(),
848
- amountUsd: z9.number(),
849
- aToB: z9.boolean(),
850
- pool: z9.string(),
851
- time: z9.coerce.date()
852
- });
853
- var TradeHistoryEntry = z9.object({
854
- // Internal entry ID
855
- id: z9.string(),
856
- pool: z9.string(),
857
- authority: z9.string(),
858
- aToB: z9.boolean(),
859
- // Trade action which created entry
860
- action: TradeHistoryActionSchema,
861
- // Trade direction formatted for ui display
862
- uiDirection: TradeHistoryUIDirectionSchema,
863
- // Trade price formatted for ui display
864
- uiPrice: z9.number(),
865
- baseToken: AmountWithUsdSchema,
866
- quoteToken: AmountWithUsdSchema,
867
- fee: AmountWithUsdSchema,
868
- pnl: z9.nullable(
869
- z9.object({
870
- usd: z9.number(),
871
- bps: z9.number()
872
- })
873
- ),
874
- txSignature: z9.nullable(z9.string()),
875
- positionAddress: z9.nullable(z9.string()),
876
- slot: z9.coerce.bigint(),
877
- ts: z9.coerce.date()
878
- });
879
- var OrderHistoryEntry = z9.object({
880
- // Internal entry ID
881
- id: z9.string(),
882
- pool: z9.string(),
883
- authority: z9.string(),
884
- orderType: OrderHistoryOrderTypeSchema,
885
- isReduceOnly: z9.nullable(z9.boolean()),
886
- aToB: z9.boolean(),
887
- uiDirection: OrderHistoryUIDirectionSchema,
888
- uiPrice: z9.nullable(z9.number()),
889
- uiExecutionPrice: z9.nullable(z9.number()),
890
- status: OrderHistoryStatusSchema,
891
- baseToken: AmountWithUsdSchema,
892
- quoteToken: AmountWithUsdSchema,
893
- baseTokenConsumedAmount: z9.nullable(AmountWithUsdSchema),
894
- quoteTokenFilledAmount: z9.nullable(AmountWithUsdSchema),
895
- txSignature: z9.nullable(z9.string()),
896
- positionAddress: z9.nullable(z9.string()),
897
- slot: z9.coerce.bigint(),
898
- ts: z9.coerce.date()
899
- });
900
- var StakingTreasury = z9.object({
901
- address: z9.string(),
902
- stakedTokenMint: z9.string(),
903
- rewardTokenMint: z9.string(),
904
- apy: z9.number(),
905
- uniqueStakers: z9.number(),
906
- totalStaked: AmountWithUsdSchema,
907
- totalReward: AmountWithUsdSchema,
908
- unstakeCooldownSeconds: z9.number(),
909
- isStakingEnabled: z9.boolean(),
910
- isUnstakingEnabled: z9.boolean(),
911
- isWithdrawEnabled: z9.boolean()
912
- });
913
- var StakingPosition = z9.object({
914
- address: z9.string(),
915
- owner: z9.string(),
916
- staked: AmountWithUsdSchema,
917
- unstaked: AmountWithUsdSchema,
918
- claimedReward: AmountWithUsdSchema,
919
- unclaimedReward: AmountWithUsdSchema,
920
- rank: z9.nullable(z9.number()),
921
- vesting: z9.object({
922
- locked: AmountWithUsdSchema,
923
- unlocked: AmountWithUsdSchema,
924
- unlockRate: z9.coerce.bigint(),
925
- unlockEverySeconds: z9.number(),
926
- unlockCliffSeconds: z9.number(),
927
- lockedAt: z9.nullable(z9.coerce.date())
928
- }),
929
- lastUnstakedAt: z9.nullable(z9.coerce.date()),
930
- withdrawAvailableAt: z9.nullable(z9.coerce.date())
931
- });
932
- var StakingLeaderboardPosition = z9.object({
933
- rank: z9.number(),
934
- address: z9.string(),
935
- owner: z9.string(),
936
- staked: AmountWithUsdSchema
937
- });
938
- var StakingLeaderboardPage = z9.object({
939
- data: StakingLeaderboardPosition.array(),
940
- meta: PaginationMeta
941
- });
942
- var StakingPositionHistoryAction = z9.object({
943
- position: z9.string(),
944
- action: StakingPositionHistoryActionTypeSchema,
945
- txSignature: z9.string(),
946
- amount: z9.coerce.bigint(),
947
- time: z9.coerce.date()
948
- });
949
- var PoolPriceCandle = z9.object({
950
- time: z9.number(),
951
- open: z9.number(),
952
- close: z9.number(),
953
- high: z9.number(),
954
- low: z9.number(),
955
- volume: z9.number()
956
- });
957
- var FeesStatsGroup = z9.object({
958
- time: z9.coerce.date(),
959
- addLiquidityFees: z9.number(),
960
- limitOrderFees: z9.number(),
961
- yieldCompoundingFees: z9.number(),
962
- liquidationFees: z9.number(),
963
- totalLiquidationsNetworkFees: z9.number(),
964
- totalLimitOrdersNetworkFees: z9.number(),
965
- totalYieldCompoundingNetworkFees: z9.number(),
966
- failedNetworkFees: z9.number(),
967
- processedNetworkFees: z9.number(),
968
- totalCollectedFees: z9.number(),
969
- totalNetworkFees: z9.number(),
970
- jitoLiquidationFees: z9.number(),
971
- jitoLimitOrderFees: z9.number(),
972
- jitoYieldCompoundingFees: z9.number(),
973
- runningAddLiquidityFees: z9.number(),
974
- runningLimitOrderFees: z9.number(),
975
- runningYieldCompoundingFees: z9.number(),
976
- runningLiquidationFees: z9.number(),
977
- runningTotalLiquidationsNetworkFees: z9.number(),
978
- runningTotalLimitOrdersNetworkFees: z9.number(),
979
- runningTotalYieldCompoundingNetworkFees: z9.number(),
980
- runningFailedNetworkFees: z9.number(),
981
- runningProcessedNetworkFees: z9.number(),
982
- runningJitoLiquidationFees: z9.number(),
983
- runningJitoLimitOrderFees: z9.number(),
984
- runningJitoYieldCompoundingFees: z9.number(),
985
- runningTotalCollectedFees: z9.number(),
986
- runningTotalNetworkFees: z9.number()
987
- });
988
- var StakingRevenueStatsGroup = z9.object({
989
- time: z9.coerce.date(),
990
- totalDepositsUsd: z9.number(),
991
- totalDepositsSol: z9.coerce.bigint(),
992
- runningTotalDepositsUsd: z9.number(),
993
- runningTotalDepositsSol: z9.coerce.bigint()
994
- });
995
- var SwapQuoteByInput = z9.object({
996
- estimatedAmountOut: z9.coerce.bigint(),
997
- minAmountOut: z9.coerce.bigint(),
998
- feeAmount: z9.coerce.bigint(),
999
- feeUsd: z9.number(),
1000
- /** Price impact in percents */
1001
- priceImpact: z9.number()
1002
- });
1003
- var SwapQuoteByOutput = z9.object({
1004
- estimatedAmountIn: z9.coerce.bigint(),
1005
- maxAmountIn: z9.coerce.bigint(),
1006
- feeAmount: z9.coerce.bigint(),
1007
- feeUsd: z9.number(),
1008
- /** Price impact in percents */
1009
- priceImpact: z9.number()
1010
- });
1011
- var LimitOrderQuoteByInput = z9.object({
1012
- amountOut: z9.coerce.bigint()
1013
- });
1014
- var LimitOrderQuoteByOutput = z9.object({
1015
- amountIn: z9.coerce.bigint()
1016
- });
1017
- var TradableAmount = AmountWithUsdSchema;
1018
- var UpdateStreamSubscriptionResult = z9.object({
1019
- status: z9.string()
1020
- });
1021
- var createNotificationSchema = (dataSchema, metaSchema) => z9.object({
1022
- entity: NotificationEntitySchema,
1023
- action: NotificationActionSchema,
1024
- data: dataSchema,
1025
- id: z9.string(),
1026
- authority: z9.nullish(z9.string()),
1027
- ...metaSchema ? { meta: metaSchema } : { meta: z9.undefined().nullable() }
1028
- });
1029
- var OrderBookNotificationMeta = z9.object({
1030
- pool: z9.string(),
1031
- priceStep: z9.number(),
1032
- inverted: z9.boolean()
1033
- });
1034
- var PoolSwapNotification = createNotificationSchema(PoolSwap);
1035
- var OrderBookNotification = createNotificationSchema(OrderBook, OrderBookNotificationMeta);
1036
- var LendingPositionNotification = createNotificationSchema(LendingPosition);
1037
- var TradeHistoryEntryNotification = createNotificationSchema(TradeHistoryEntry);
1038
- var OrderHistoryEntryNotification = createNotificationSchema(OrderHistoryEntry);
1039
- var StakingPositionNotification = createNotificationSchema(StakingPosition);
1040
- var StateSnapshotNotification = createNotificationSchema(StateSnapshot);
1041
-
1042
- // src/client/client.ts
1043
- var DEFAULT_TIMEOUT = 5e3;
1044
- var DEFAULT_HTTP_RETRIES = 3;
1045
- var ProviderFilter = /* @__PURE__ */ ((ProviderFilter2) => {
1046
- ProviderFilter2["ORCA"] = "orca";
1047
- ProviderFilter2["FUSION"] = "fusion";
1048
- ProviderFilter2["ALL"] = "all";
1049
- return ProviderFilter2;
1050
- })(ProviderFilter || {});
1051
- var TunaApiClient = class {
1052
- get baseURL() {
1053
- return this._baseURL;
1054
- }
1055
- get timeout() {
1056
- return this._timeout;
1057
- }
1058
- get httpRetries() {
1059
- return this._httpRetries;
1060
- }
1061
- get headers() {
1062
- return this._headers;
1063
- }
1064
- constructor(baseURL, config) {
1065
- this._baseURL = baseURL;
1066
- this._timeout = config?.timeout ?? DEFAULT_TIMEOUT;
1067
- this._httpRetries = config?.httpRetries ?? DEFAULT_HTTP_RETRIES;
1068
- this._headers = config?.headers ?? {};
1069
- }
1070
- setConfig(config) {
1071
- if (config.baseURL) {
1072
- this._baseURL = config.baseURL;
1073
- }
1074
- this._timeout = config?.timeout ?? DEFAULT_TIMEOUT;
1075
- this._httpRetries = config?.httpRetries ?? DEFAULT_HTTP_RETRIES;
1076
- this._headers = config?.headers ?? {};
1077
- }
1078
- async httpRequest(url, schema, options, retries = this.httpRetries, backoff = 100 + Math.floor(Math.random() * 100)) {
1079
- try {
1080
- const controller = new AbortController();
1081
- const abort = setTimeout(() => {
1082
- controller.abort();
1083
- }, this.timeout);
1084
- const signal = options?.signal || controller.signal;
1085
- const response = await fetch(url, {
1086
- ...options,
1087
- signal,
1088
- headers: { "Content-Type": "application/json", ...this.headers, ...options?.headers }
1089
- });
1090
- clearTimeout(abort);
1091
- if (!response.ok) {
1092
- const errorBody = await response.json();
1093
- throw errorBody;
1094
- }
1095
- const data = await response.json();
1096
- const transformed = camelcaseKeys(data, { deep: true, exclude: ["24h", "7d", "30d"] });
1097
- if (options?.parseRoot) {
1098
- return schema.parse(transformed);
1099
- }
1100
- return schema.parse(transformed.data);
1101
- } catch (error) {
1102
- if (retries > 0 && !(error instanceof Error && error.name === "AbortError")) {
1103
- await new Promise((resolve) => setTimeout(resolve, backoff));
1104
- return this.httpRequest(url, schema, options, retries - 1, backoff * 2);
1105
- }
1106
- throw error;
1107
- }
1108
- }
1109
- /* Endpoints */
1110
- async getMints() {
1111
- const url = this.buildURL("mints");
1112
- return await this.httpRequest(url, Mint.array());
1113
- }
1114
- async getMint(mintAddress) {
1115
- const url = this.buildURL(`mints/${mintAddress}`);
1116
- return await this.httpRequest(url, Mint);
1117
- }
1118
- async getMarkets() {
1119
- const url = this.buildURL("markets");
1120
- return await this.httpRequest(url, Market.array());
1121
- }
1122
- async getMarket(marketAddress) {
1123
- const url = this.buildURL(`markets/${marketAddress}`);
1124
- return await this.httpRequest(url, Market);
1125
- }
1126
- async getOraclePrices() {
1127
- const url = this.buildURL("oracle-prices");
1128
- return await this.httpRequest(url, TokenOraclePrice.array());
1129
- }
1130
- async getOraclePrice(mintAddress) {
1131
- const url = this.buildURL(`oracle-prices/${mintAddress}`);
1132
- return await this.httpRequest(url, TokenOraclePrice);
1133
- }
1134
- async getVaults() {
1135
- const url = this.buildURL("vaults");
1136
- return await this.httpRequest(url, Vault.array());
1137
- }
1138
- async getVault(vaultAddress) {
1139
- const url = this.buildURL(`vaults/${vaultAddress}`);
1140
- return await this.httpRequest(url, Vault);
1141
- }
1142
- /**
1143
- * Returns vault historical data for selected time interval.
1144
- *
1145
- * Example usage: getVaultHistory('H3ifgix98vzi3yCPbmZDLTheeTRf2jykXx8FpY5L7Sfd', '2025-03-10', '2025-04-10')
1146
- */
1147
- async getVaultHistory(vaultAddress, from, to) {
1148
- const url = this.appendUrlSearchParams(this.buildURL(`vaults/${vaultAddress}/history`), {
1149
- from: from.toISOString().slice(0, 10),
1150
- to: to.toISOString().slice(0, 10)
1151
- });
1152
- return await this.httpRequest(url, VaultHistoricalStats.array());
1153
- }
1154
- async getPools(providerFilter) {
1155
- const url = this.appendUrlSearchParams(this.buildURL("pools"), {
1156
- provider: providerFilter && providerFilter !== "all" /* ALL */ ? providerFilter : void 0
1157
- });
1158
- return await this.httpRequest(url, Pool.array());
1159
- }
1160
- async getPool(address) {
1161
- const url = this.buildURL(`pools/${address}`);
1162
- return await this.httpRequest(url, Pool);
1163
- }
1164
- async getPoolTicks(poolAddress) {
1165
- const url = this.buildURL(`pools/${poolAddress}/ticks`);
1166
- return await this.httpRequest(url, PoolTicks);
1167
- }
1168
- async getPoolSwaps(poolAddress) {
1169
- const url = this.buildURL(`pools/${poolAddress}/swaps`);
1170
- return await this.httpRequest(url, PoolSwap.array());
1171
- }
1172
- async getPoolOrderBook(poolAddress, priceStep, inverted) {
1173
- const url = this.appendUrlSearchParams(this.buildURL(`pools/${poolAddress}/order-book`), {
1174
- price_step: priceStep,
1175
- inverted: inverted || void 0
1176
- });
1177
- return await this.httpRequest(url, OrderBook);
1178
- }
1179
- async getPoolPriceCandles(poolAddress, options) {
1180
- const { from, to, interval, candles } = options;
1181
- const url = this.appendUrlSearchParams(this.buildURL(`pools/${poolAddress}/candles`), {
1182
- from: from.toISOString(),
1183
- to: to.toISOString(),
1184
- candles,
1185
- interval
1186
- });
1187
- return await this.httpRequest(url, PoolPriceCandle.array());
1188
- }
1189
- async getStakingTreasury() {
1190
- const url = this.buildURL(`staking/treasury`);
1191
- return await this.httpRequest(url, StakingTreasury);
1192
- }
1193
- async getStakingLeaderboard(page, pageSize, search) {
1194
- const url = this.appendUrlSearchParams(this.buildURL(`staking/leaderboard`), {
1195
- page,
1196
- page_size: pageSize,
1197
- search: search || void 0
1198
- });
1199
- return await this.httpRequest(url, StakingLeaderboardPage, { parseRoot: true });
1200
- }
1201
- async getUserLendingPositions(userAddress) {
1202
- const url = this.buildURL(`users/${userAddress}/lending-positions`);
1203
- return await this.httpRequest(url, LendingPosition.array());
1204
- }
1205
- async getUserLendingPositionByAddress(userAddress, lendingPositionAddress) {
1206
- const url = this.buildURL(`users/${userAddress}/lending-positions/${lendingPositionAddress}`);
1207
- return await this.httpRequest(url, LendingPosition);
1208
- }
1209
- async getUserTunaPositions(userAddress) {
1210
- const url = this.buildURL(`users/${userAddress}/tuna-positions`);
1211
- return await this.httpRequest(url, TunaLpPositionDtoSchema.array());
1212
- }
1213
- async getUserTunaPositionByAddress(userAddress, tunaPositionAddress) {
1214
- const url = this.buildURL(`users/${userAddress}/tuna-positions/${tunaPositionAddress}`);
1215
- return await this.httpRequest(url, TunaLpPositionDtoSchema);
1216
- }
1217
- async getUserLpPositions(userAddress, options) {
1218
- const query = {};
1219
- if (options) {
1220
- if (options.filter) {
1221
- query.filter = options.filter;
1222
- }
1223
- if (options.afterPosition) {
1224
- query.after_position = options.afterPosition;
1225
- }
1226
- if (options.openedAt) {
1227
- if (options.openedAt.from) {
1228
- query.opened_at_min = options.openedAt.from.toISOString();
1229
- }
1230
- if (options.openedAt.to) {
1231
- query.opened_at_max = options.openedAt.to.toISOString();
1232
- }
1233
- }
1234
- if (options.closedAt) {
1235
- if (options.closedAt.from) {
1236
- query.closed_at_min = options.closedAt.from.toISOString();
1237
- }
1238
- if (options.closedAt.to) {
1239
- query.closed_at_max = options.closedAt.to.toISOString();
1240
- }
1241
- }
1242
- }
1243
- const url = this.appendUrlSearchParams(this.buildURL(`users/${userAddress}/lp-positions`), query);
1244
- return await this.httpRequest(url, TunaLpPositionHistorical.array());
1245
- }
1246
- async getUserLpPositionActions(userAddress, positionAddress) {
1247
- const url = this.buildURL(`users/${userAddress}/lp-positions/${positionAddress}/actions`);
1248
- return await this.httpRequest(url, TunaLpPositionAction.array());
1249
- }
1250
- async getUserTunaSpotPositions(userAddress) {
1251
- const url = this.buildURL(`users/${userAddress}/spot-positions`);
1252
- return await this.httpRequest(url, TunaSpotPosition.array());
1253
- }
1254
- async getUserTunaSpotPositionByAddress(userAddress, tunaSpotPositionAddress) {
1255
- const url = this.buildURL(`users/${userAddress}/spot-positions/${tunaSpotPositionAddress}`);
1256
- return await this.httpRequest(url, TunaSpotPosition);
1257
- }
1258
- async getUserLimitOrders(userAddress, options) {
1259
- const query = {};
1260
- if (options) {
1261
- if (options.pool?.length) {
1262
- query.pool = options.pool.join(",");
1263
- }
1264
- if (options.status?.length) {
1265
- query.status = options.status.join(",");
1266
- }
1267
- if (options.openedAt?.from) {
1268
- query.opened_at_from = options.openedAt.from.toISOString();
1269
- }
1270
- if (options.openedAt?.to) {
1271
- query.opened_at_from = options.openedAt.to.toISOString();
1272
- }
1273
- if (options.limit) {
1274
- query.limit = options.limit;
1275
- }
1276
- if (options.cursor) {
1277
- query.cursor = options.cursor;
1278
- }
1279
- if (options.desc !== void 0) {
1280
- query.desc = options.desc;
1281
- }
1282
- }
1283
- const url = this.appendUrlSearchParams(this.buildURL(`users/${userAddress}/limit-orders`), query);
1284
- return await this.httpRequest(url, LimitOrder.array());
1285
- }
1286
- async getUserLimitOrderByAddress(userAddress, limitOrderAddress) {
1287
- const url = this.buildURL(`users/${userAddress}/limit-orders/${limitOrderAddress}`);
1288
- return await this.httpRequest(url, LimitOrder);
1289
- }
1290
- async getUserTradeHistory(userAddress, options) {
1291
- const query = {};
1292
- if (options) {
1293
- if (options.pool?.length) {
1294
- query.pool = options.pool.join(",");
1295
- }
1296
- if (options.action?.length) {
1297
- query.action = options.action.join(",");
1298
- }
1299
- if (options.uiDirection?.length) {
1300
- query.ui_direction = options.uiDirection.join(",");
1301
- }
1302
- if (options.limit) {
1303
- query.limit = options.limit;
1304
- }
1305
- if (options.cursor) {
1306
- query.cursor = options.cursor;
1307
- }
1308
- if (options.desc !== void 0) {
1309
- query.desc = options.desc;
1310
- }
1311
- }
1312
- const url = this.appendUrlSearchParams(this.buildURL(`users/${userAddress}/trade-history`), query);
1313
- return await this.httpRequest(url, TradeHistoryEntry.array());
1314
- }
1315
- async getUserOrderHistory(userAddress, options) {
1316
- const query = {};
1317
- if (options) {
1318
- if (options.pool?.length) {
1319
- query.pool = options.pool.join(",");
1320
- }
1321
- if (options.orderType?.length) {
1322
- query.order_type = options.orderType.join(",");
1323
- }
1324
- if (options.uiDiretion?.length) {
1325
- query.ui_direction = options.uiDiretion.join(",");
1326
- }
1327
- if (options.limit) {
1328
- query.limit = options.limit;
1329
- }
1330
- if (options.cursor) {
1331
- query.cursor = options.cursor;
1332
- }
1333
- if (options.desc !== void 0) {
1334
- query.desc = options.desc;
1335
- }
1336
- }
1337
- const url = this.appendUrlSearchParams(this.buildURL(`users/${userAddress}/order-history`), query);
1338
- return await this.httpRequest(url, OrderHistoryEntry.array());
1339
- }
1340
- async getUserStakingPosition(userAddress) {
1341
- const url = this.buildURL(`users/${userAddress}/staking-position`);
1342
- return await this.httpRequest(url, StakingPosition);
1343
- }
1344
- async getUserStakingPositionHistory(userAddress) {
1345
- const url = this.buildURL(`users/${userAddress}/staking-position/history`);
1346
- return await this.httpRequest(url, StakingPositionHistoryAction.array());
1347
- }
1348
- async getFeesStats(from, to, interval) {
1349
- const url = this.appendUrlSearchParams(this.buildURL(`stats/fees`), {
1350
- from: from.toISOString(),
1351
- to: to.toISOString(),
1352
- interval
1353
- });
1354
- return await this.httpRequest(url, FeesStatsGroup.array());
1355
- }
1356
- async getStakingRevenueStats(from, to) {
1357
- const url = this.appendUrlSearchParams(this.buildURL(`stats/staking/revenue`), {
1358
- from: from.toISOString().split("T")[0],
1359
- to: to.toISOString().split("T")[0]
1360
- });
1361
- return await this.httpRequest(url, StakingRevenueStatsGroup.array());
1362
- }
1363
- async getLimitOrderQuoteByInput(args, config) {
1364
- const { pool, amountIn, aToB, tickIndex } = args;
1365
- const query = {
1366
- pool,
1367
- amount_in: amountIn.toString(),
1368
- a_to_b: aToB,
1369
- tick_index: tickIndex
1370
- };
1371
- const url = this.appendUrlSearchParams(this.buildURL(`quotes/limit-order-by-input`), query);
1372
- return await this.httpRequest(url, LimitOrderQuoteByInput, {
1373
- signal: config?.abortSignal
1374
- });
1375
- }
1376
- async getLimitOrderQuoteByOutput(args, config) {
1377
- const { pool, amountOut, aToB, tickIndex } = args;
1378
- const query = {
1379
- pool,
1380
- amount_out: amountOut.toString(),
1381
- a_to_b: aToB,
1382
- tick_index: tickIndex
1383
- };
1384
- const url = this.appendUrlSearchParams(this.buildURL(`quotes/limit-order-by-output`), query);
1385
- return await this.httpRequest(url, LimitOrderQuoteByOutput, {
1386
- signal: config?.abortSignal
1387
- });
1388
- }
1389
- async getSwapQuoteByInput(args, config) {
1390
- const { pool, amountIn, aToB, slippageToleranceBps } = args;
1391
- const query = {
1392
- pool,
1393
- amount_in: amountIn.toString(),
1394
- a_to_b: aToB
1395
- };
1396
- if (slippageToleranceBps) {
1397
- query.slippage_tolerance = slippageToleranceBps;
1398
- }
1399
- const url = this.appendUrlSearchParams(this.buildURL(`quotes/swap-by-input`), query);
1400
- return await this.httpRequest(url, SwapQuoteByInput, {
1401
- signal: config?.abortSignal
1402
- });
1403
- }
1404
- async getSwapQuoteByOutput(args, config) {
1405
- const { pool, amountOut, aToB, slippageToleranceBps } = args;
1406
- const query = {
1407
- pool,
1408
- amount_out: amountOut.toString(),
1409
- a_to_b: aToB
1410
- };
1411
- if (slippageToleranceBps) {
1412
- query.slippage_tolerance = slippageToleranceBps;
1413
- }
1414
- const url = this.appendUrlSearchParams(this.buildURL(`quotes/swap-by-output`), query);
1415
- return await this.httpRequest(url, SwapQuoteByOutput, {
1416
- signal: config?.abortSignal
1417
- });
1418
- }
1419
- async getIncreaseSpotPositionQuote(args, config) {
1420
- const {
1421
- market,
1422
- increaseAmount,
1423
- collateralToken,
1424
- positionToken,
1425
- leverage,
1426
- positionAmount,
1427
- positionDebt,
1428
- slippageTolerance
1429
- } = args;
1430
- const query = {
1431
- market,
1432
- increase_amount: increaseAmount.toString(),
1433
- collateral_token: collateralToken,
1434
- position_token: positionToken,
1435
- leverage
1436
- };
1437
- if (slippageTolerance) {
1438
- query.slippage_tolerance = slippageTolerance;
1439
- }
1440
- if (positionAmount) {
1441
- query.position_amount = positionAmount.toString();
1442
- }
1443
- if (positionDebt) {
1444
- query.position_debt = positionDebt.toString();
1445
- }
1446
- const url = this.appendUrlSearchParams(this.buildURL(`quotes/increase-spot-position`), query);
1447
- return await this.httpRequest(url, IncreaseSpotPositionQuote, {
1448
- signal: config?.abortSignal
1449
- });
1450
- }
1451
- async getDecreaseSpotPositionQuote(args, config) {
1452
- const {
1453
- market,
1454
- decreaseAmount,
1455
- collateralToken,
1456
- positionToken,
1457
- leverage,
1458
- positionAmount,
1459
- positionDebt,
1460
- slippageTolerance
1461
- } = args;
1462
- const query = {
1463
- market,
1464
- decrease_amount: decreaseAmount.toString(),
1465
- collateral_token: collateralToken,
1466
- position_token: positionToken,
1467
- leverage,
1468
- position_amount: positionAmount.toString(),
1469
- position_debt: positionDebt.toString()
1470
- };
1471
- if (slippageTolerance) {
1472
- query.slippage_tolerance = slippageTolerance;
1473
- }
1474
- const url = this.appendUrlSearchParams(this.buildURL(`quotes/decrease-spot-position`), query);
1475
- return await this.httpRequest(url, DecreaseSpotPositionQuote, {
1476
- signal: config?.abortSignal
1477
- });
1478
- }
1479
- async getCloseSpotPositionQuote(args, config) {
1480
- const { market, decreasePercent, collateralToken, positionToken, positionAmount, positionDebt, slippageTolerance } = args;
1481
- const query = {
1482
- market,
1483
- decrease_percent: decreasePercent,
1484
- collateral_token: collateralToken,
1485
- position_token: positionToken,
1486
- position_amount: positionAmount.toString(),
1487
- position_debt: positionDebt.toString()
1488
- };
1489
- if (slippageTolerance) {
1490
- query.slippage_tolerance = slippageTolerance;
1491
- }
1492
- const url = this.appendUrlSearchParams(this.buildURL(`quotes/close-spot-position`), query);
1493
- return await this.httpRequest(url, CloseSpotPositionQuote, {
1494
- signal: config?.abortSignal
1495
- });
1496
- }
1497
- async getTradableAmount(args, config) {
1498
- const { market, collateralToken, positionToken, availableBalance, leverage, positionAmount, increase } = args;
1499
- const url = this.appendUrlSearchParams(this.buildURL(`quotes/tradable-amount`), {
1500
- market,
1501
- collateral_token: collateralToken,
1502
- position_token: positionToken,
1503
- available_balance: availableBalance.toString(),
1504
- leverage,
1505
- position_amount: positionAmount.toString(),
1506
- increase
1507
- });
1508
- return await this.httpRequest(url, TradableAmount, {
1509
- signal: config?.abortSignal
1510
- });
1511
- }
1512
- async getUpdatesStream() {
1513
- const url = this.buildURL(`streams/sse`);
1514
- return new EventSource(url);
1515
- }
1516
- async updateStreamSubscription(streamId, subscription) {
1517
- const url = this.buildURL(`streams/${streamId}/subscription`);
1518
- const body = JSON.stringify(snakecaseKeys(subscription, { deep: true }));
1519
- return await this.httpRequest(url, UpdateStreamSubscriptionResult, { method: "PUT", body });
1520
- }
1521
- /* Utility functions */
1522
- buildURL(endpoint) {
1523
- return `${this.baseURL}${this.baseURL.endsWith("/") ? "" : "/"}v1/${endpoint}`;
1524
- }
1525
- appendUrlSearchParams(url, params) {
1526
- const urlSearchParams = new URLSearchParams();
1527
- Object.entries(params).forEach(([key, value]) => {
1528
- if (value !== void 0) {
1529
- urlSearchParams.append(key, String(value));
1530
- }
1531
- });
1532
- if (urlSearchParams.size > 0) {
1533
- return `${url}?${urlSearchParams.toString()}`;
1534
- }
1535
- return url;
1536
- }
1537
- };
1538
- export {
1539
- NotificationAction,
1540
- NotificationEntity,
1541
- PoolProvider,
1542
- PoolSubscriptionTopic,
1543
- ProviderFilter,
1544
- TunaApiClient,
1545
- TunaPositionState,
1546
- WalletSubscriptionTopic,
1547
- schemas_exports as schemas
1548
- };