@crypticdot/defituna-api 1.1.55 → 1.2.0

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.js CHANGED
@@ -90,6 +90,10 @@ __export(schemas_exports, {
90
90
  TunaPositionNotification: () => TunaPositionNotification,
91
91
  TunaPositionState: () => TunaPositionState,
92
92
  TunaPositionStateSchema: () => TunaPositionStateSchema,
93
+ TunaSpotPosition: () => TunaSpotPosition,
94
+ TunaSpotPositionNotification: () => TunaSpotPositionNotification,
95
+ TunaSpotPositionState: () => TunaSpotPositionState,
96
+ TunaSpotPositionStateSchema: () => TunaSpotPositionStateSchema,
93
97
  UpdateStreamSubscriptionResult: () => UpdateStreamSubscriptionResult,
94
98
  Vault: () => Vault,
95
99
  VaultHistoricalStats: () => VaultHistoricalStats,
@@ -135,6 +139,10 @@ var TunaPositionState = {
135
139
  CLOSED_BY_LIMIT_ORDER: "closed_by_limit_order",
136
140
  CLOSED: "closed"
137
141
  };
142
+ var TunaSpotPositionState = {
143
+ OPEN: "open",
144
+ CLOSED: "closed"
145
+ };
138
146
  var LimitOrderState = {
139
147
  OPEN: "open",
140
148
  PARTIALLY_FILLED: "partially_filled",
@@ -156,6 +164,7 @@ var PoolSubscriptionTopic = {
156
164
  };
157
165
  var WalletSubscriptionTopic = {
158
166
  TUNA_POSITIONS: "tuna_positions",
167
+ TUNA_SPOT_POSITIONS: "tuna_spot_positions",
159
168
  LENDING_POSITIONS: "lending_positions",
160
169
  FUSION_LIMIT_ORDERS: "fusion_limit_orders",
161
170
  STAKING_POSITION: "staking_position"
@@ -164,6 +173,10 @@ var NotificationEntitySchema = import_zod.z.enum([NotificationEntity.POOL_SWAP,
164
173
  var NotificationActionSchema = import_zod.z.enum([NotificationAction.CREATE, ...Object.values(NotificationAction)]);
165
174
  var PoolProviderSchema = import_zod.z.enum([PoolProvider.ORCA, ...Object.values(PoolProvider)]);
166
175
  var TunaPositionStateSchema = import_zod.z.enum([TunaPositionState.OPEN, ...Object.values(TunaPositionState)]);
176
+ var TunaSpotPositionStateSchema = import_zod.z.enum([
177
+ TunaSpotPositionState.OPEN,
178
+ ...Object.values(TunaSpotPositionState)
179
+ ]);
167
180
  var LimitOrderStateSchema = import_zod.z.enum([LimitOrderState.OPEN, ...Object.values(LimitOrderState)]);
168
181
  var StakingPositionHistoryActionTypeSchema = import_zod.z.enum([
169
182
  StakingPositionHistoryActionType.STAKE,
@@ -353,6 +366,30 @@ var TunaPosition = import_zod.z.object({
353
366
  updatedAtSlot: import_zod.z.coerce.bigint(),
354
367
  closedAt: import_zod.z.nullable(import_zod.z.coerce.date())
355
368
  });
369
+ var TunaSpotPosition = import_zod.z.object({
370
+ address: import_zod.z.string(),
371
+ authority: import_zod.z.string(),
372
+ version: import_zod.z.number(),
373
+ state: TunaSpotPositionStateSchema,
374
+ entrySqrtPrice: import_zod.z.coerce.bigint(),
375
+ lowerLimitOrderSqrtPrice: import_zod.z.coerce.bigint(),
376
+ upperLimitOrderSqrtPrice: import_zod.z.coerce.bigint(),
377
+ flags: import_zod.z.number(),
378
+ pool: import_zod.z.string(),
379
+ poolSqrtPrice: import_zod.z.coerce.bigint(),
380
+ collateralToken: import_zod.z.string(),
381
+ borrowToken: import_zod.z.string(),
382
+ positionToken: import_zod.z.string(),
383
+ collateral: amountWithUsd,
384
+ loanFunds: amountWithUsd,
385
+ currentLoan: amountWithUsd,
386
+ total: amountWithUsd,
387
+ pnlUsd: usdPnl,
388
+ openedAt: import_zod.z.coerce.date(),
389
+ openedAtSlot: import_zod.z.coerce.bigint(),
390
+ updatedAtSlot: import_zod.z.coerce.bigint(),
391
+ closedAt: import_zod.z.nullable(import_zod.z.coerce.date())
392
+ });
356
393
  var PoolSwap = import_zod.z.object({
357
394
  id: import_zod.z.string(),
358
395
  amountIn: import_zod.z.coerce.bigint(),
@@ -514,6 +551,7 @@ var PoolSwapNotification = createNotificationSchema(PoolSwap);
514
551
  var PoolPriceUpdateNotification = createNotificationSchema(PoolPriceUpdate);
515
552
  var OrderBookNotification = createNotificationSchema(OrderBook, OrderBookNotificationMeta);
516
553
  var TunaPositionNotification = createNotificationSchema(TunaPosition);
554
+ var TunaSpotPositionNotification = createNotificationSchema(TunaSpotPosition);
517
555
  var LendingPositionNotification = createNotificationSchema(LendingPosition);
518
556
  var LimitOrderNotification = createNotificationSchema(LimitOrder);
519
557
  var StakingPositionNotification = createNotificationSchema(StakingPosition);
@@ -588,35 +626,35 @@ var TunaApiClient = class {
588
626
  /* Endpoints */
589
627
  async getMints() {
590
628
  const url = this.buildURL("mints");
591
- return await this.httpRequest(url.toString(), Mint.array());
629
+ return await this.httpRequest(url, Mint.array());
592
630
  }
593
631
  async getMint(mintAddress) {
594
632
  const url = this.buildURL(`mints/${mintAddress}`);
595
- return await this.httpRequest(url.toString(), Mint);
633
+ return await this.httpRequest(url, Mint);
596
634
  }
597
635
  async getMarkets() {
598
636
  const url = this.buildURL("markets");
599
- return await this.httpRequest(url.toString(), Market.array());
637
+ return await this.httpRequest(url, Market.array());
600
638
  }
601
639
  async getMarket(marketAddress) {
602
640
  const url = this.buildURL(`markets/${marketAddress}`);
603
- return await this.httpRequest(url.toString(), Market);
641
+ return await this.httpRequest(url, Market);
604
642
  }
605
643
  async getOraclePrices() {
606
644
  const url = this.buildURL("oracle-prices");
607
- return await this.httpRequest(url.toString(), TokenOraclePrice.array());
645
+ return await this.httpRequest(url, TokenOraclePrice.array());
608
646
  }
609
647
  async getOraclePrice(mintAddress) {
610
648
  const url = this.buildURL(`oracle-prices/${mintAddress}`);
611
- return await this.httpRequest(url.toString(), TokenOraclePrice);
649
+ return await this.httpRequest(url, TokenOraclePrice);
612
650
  }
613
651
  async getVaults() {
614
652
  const url = this.buildURL("vaults");
615
- return await this.httpRequest(url.toString(), Vault.array());
653
+ return await this.httpRequest(url, Vault.array());
616
654
  }
617
655
  async getVault(vaultAddress) {
618
656
  const url = this.buildURL(`vaults/${vaultAddress}`);
619
- return await this.httpRequest(url.toString(), Vault);
657
+ return await this.httpRequest(url, Vault);
620
658
  }
621
659
  /**
622
660
  * Returns vault historical data for selected time interval.
@@ -624,137 +662,140 @@ var TunaApiClient = class {
624
662
  * Example usage: getVaultHistory('H3ifgix98vzi3yCPbmZDLTheeTRf2jykXx8FpY5L7Sfd', '2025-03-10', '2025-04-10')
625
663
  */
626
664
  async getVaultHistory(vaultAddress, from, to) {
627
- const url = this.buildURL(`vaults/${vaultAddress}/history`);
628
- this.appendUrlSearchParams(url, { from: from.toISOString().slice(0, 10), to: to.toISOString().slice(0, 10) });
629
- return await this.httpRequest(url.toString(), VaultHistoricalStats.array());
665
+ const url = this.appendUrlSearchParams(this.buildURL(`vaults/${vaultAddress}/history`), {
666
+ from: from.toISOString().slice(0, 10),
667
+ to: to.toISOString().slice(0, 10)
668
+ });
669
+ return await this.httpRequest(url, VaultHistoricalStats.array());
630
670
  }
631
671
  async getPools(providerFilter) {
632
- const url = this.buildURL("pools");
633
- if (providerFilter && providerFilter !== "all" /* ALL */) {
634
- this.appendUrlSearchParams(url, { provider: providerFilter });
635
- }
636
- return await this.httpRequest(url.toString(), Pool.array());
672
+ const url = this.appendUrlSearchParams(this.buildURL("pools"), {
673
+ provider: providerFilter && providerFilter !== "all" /* ALL */ ? providerFilter : void 0
674
+ });
675
+ return await this.httpRequest(url, Pool.array());
637
676
  }
638
677
  async getPool(address) {
639
678
  const url = this.buildURL(`pools/${address}`);
640
- return await this.httpRequest(url.toString(), Pool);
679
+ return await this.httpRequest(url, Pool);
641
680
  }
642
681
  async getPoolTicks(poolAddress) {
643
682
  const url = this.buildURL(`pools/${poolAddress}/ticks`);
644
- return await this.httpRequest(url.toString(), PoolTicks);
683
+ return await this.httpRequest(url, PoolTicks);
645
684
  }
646
685
  async getPoolSwaps(poolAddress) {
647
686
  const url = this.buildURL(`pools/${poolAddress}/swaps`);
648
- return await this.httpRequest(url.toString(), PoolSwap.array());
687
+ return await this.httpRequest(url, PoolSwap.array());
649
688
  }
650
689
  async getPoolOrderBook(poolAddress, priceStep, inverted) {
651
- const url = this.buildURL(`pools/${poolAddress}/order-book`);
652
- this.appendUrlSearchParams(url, { price_step: priceStep.toString() });
653
- if (inverted) {
654
- this.appendUrlSearchParams(url, { inverted: inverted.toString() });
655
- }
656
- return await this.httpRequest(url.toString(), OrderBook);
690
+ const url = this.appendUrlSearchParams(this.buildURL(`pools/${poolAddress}/order-book`), {
691
+ price_step: priceStep,
692
+ inverted: inverted || void 0
693
+ });
694
+ return await this.httpRequest(url, OrderBook);
657
695
  }
658
696
  async getPoolPriceCandles(poolAddress, options) {
659
697
  const { from, to, interval, candles } = options;
660
- const url = this.buildURL(`pools/${poolAddress}/candles`);
661
- this.appendUrlSearchParams(url, {
698
+ const url = this.appendUrlSearchParams(this.buildURL(`pools/${poolAddress}/candles`), {
662
699
  from: from.toISOString(),
663
700
  to: to.toISOString(),
664
- candles: candles.toString(),
701
+ candles,
665
702
  interval
666
703
  });
667
- return await this.httpRequest(url.toString(), PoolPriceCandle.array());
704
+ return await this.httpRequest(url, PoolPriceCandle.array());
668
705
  }
669
706
  async getStakingTreasury() {
670
707
  const url = this.buildURL(`staking/treasury`);
671
- return await this.httpRequest(url.toString(), StakingTreasury);
708
+ return await this.httpRequest(url, StakingTreasury);
672
709
  }
673
710
  async getStakingLeaderboard(page, pageSize, search) {
674
- const url = this.buildURL(`staking/leaderboard`);
675
- this.appendUrlSearchParams(url, {
676
- page: page.toString(),
677
- page_size: pageSize.toString(),
678
- ...search ? { search } : {}
711
+ const url = this.appendUrlSearchParams(this.buildURL(`staking/leaderboard`), {
712
+ page,
713
+ page_size: pageSize,
714
+ search: search || void 0
679
715
  });
680
- return await this.httpRequest(url.toString(), StakingLeaderboardPage, { parseRoot: true });
716
+ return await this.httpRequest(url, StakingLeaderboardPage, { parseRoot: true });
681
717
  }
682
718
  async getUserLendingPositions(userAddress) {
683
719
  const url = this.buildURL(`users/${userAddress}/lending-positions`);
684
- return await this.httpRequest(url.toString(), LendingPosition.array());
720
+ return await this.httpRequest(url, LendingPosition.array());
685
721
  }
686
722
  async getUserLendingPositionByAddress(userAddress, lendingPositionAddress) {
687
723
  const url = this.buildURL(`users/${userAddress}/lending-positions/${lendingPositionAddress}`);
688
- return await this.httpRequest(url.toString(), LendingPosition);
724
+ return await this.httpRequest(url, LendingPosition);
689
725
  }
690
726
  async getUserTunaPositions(userAddress) {
691
727
  const url = this.buildURL(`users/${userAddress}/tuna-positions`);
692
- return await this.httpRequest(url.toString(), TunaPosition.array());
728
+ return await this.httpRequest(url, TunaPosition.array());
693
729
  }
694
730
  async getUserTunaPositionByAddress(userAddress, tunaPositionAddress) {
695
731
  const url = this.buildURL(`users/${userAddress}/tuna-positions/${tunaPositionAddress}`);
696
- return await this.httpRequest(url.toString(), TunaPosition);
732
+ return await this.httpRequest(url, TunaPosition);
733
+ }
734
+ async getUserTunaSpotPositions(userAddress) {
735
+ const url = this.buildURL(`users/${userAddress}/spot-positions`);
736
+ return await this.httpRequest(url, TunaSpotPosition.array());
737
+ }
738
+ async getUserTunaSpotPositionByAddress(userAddress, tunaSpotPositionAddress) {
739
+ const url = this.buildURL(`users/${userAddress}/spot-positions/${tunaSpotPositionAddress}`);
740
+ return await this.httpRequest(url, TunaSpotPosition);
697
741
  }
698
742
  async getUserLimitOrders(userAddress, poolFilter) {
699
- const url = this.buildURL(`users/${userAddress}/limit-orders`);
700
- if (poolFilter) {
701
- this.appendUrlSearchParams(url, { pool: poolFilter });
702
- }
703
- return await this.httpRequest(url.toString(), LimitOrder.array());
743
+ const url = this.appendUrlSearchParams(this.buildURL(`users/${userAddress}/limit-orders`), {
744
+ pool: poolFilter || void 0
745
+ });
746
+ return await this.httpRequest(url, LimitOrder.array());
704
747
  }
705
748
  async getUserLimitOrderByAddress(userAddress, limitOrderAddress) {
706
749
  const url = this.buildURL(`users/${userAddress}/limit-orders/${limitOrderAddress}`);
707
- return await this.httpRequest(url.toString(), LimitOrder);
750
+ return await this.httpRequest(url, LimitOrder);
708
751
  }
709
752
  async getUserStakingPosition(userAddress) {
710
753
  const url = this.buildURL(`users/${userAddress}/staking-position`);
711
- return await this.httpRequest(url.toString(), StakingPosition);
754
+ return await this.httpRequest(url, StakingPosition);
712
755
  }
713
756
  async getUserStakingPositionHistory(userAddress) {
714
757
  const url = this.buildURL(`users/${userAddress}/staking-position/history`);
715
- return await this.httpRequest(url.toString(), StakingPositionHistoryAction.array());
758
+ return await this.httpRequest(url, StakingPositionHistoryAction.array());
716
759
  }
717
760
  async getFeesStats(from, to, interval) {
718
- const url = this.buildURL(`stats/fees`);
719
- this.appendUrlSearchParams(url, {
761
+ const url = this.appendUrlSearchParams(this.buildURL(`stats/fees`), {
720
762
  from: from.toISOString(),
721
763
  to: to.toISOString(),
722
764
  interval
723
765
  });
724
- return await this.httpRequest(url.toString(), FeesStatsGroup.array());
766
+ return await this.httpRequest(url, FeesStatsGroup.array());
725
767
  }
726
768
  async getStakingRevenueStats(from, to) {
727
- const url = this.buildURL(`stats/staking/revenue`);
728
- this.appendUrlSearchParams(url, {
769
+ const url = this.appendUrlSearchParams(this.buildURL(`stats/staking/revenue`), {
729
770
  from: from.toISOString().split("T")[0],
730
771
  to: to.toISOString().split("T")[0]
731
772
  });
732
- return await this.httpRequest(url.toString(), StakingRevenueStatsGroup.array());
773
+ return await this.httpRequest(url, StakingRevenueStatsGroup.array());
733
774
  }
734
775
  async getUpdatesStream() {
735
776
  const url = this.buildURL(`streams/sse`);
736
- return new EventSource(url.toString());
777
+ return new EventSource(url);
737
778
  }
738
779
  async updateStreamSubscription(streamId, subscription) {
739
780
  const url = this.buildURL(`streams/${streamId}/subscription`);
740
781
  const body = JSON.stringify((0, import_snakecase_keys.default)(subscription, { deep: true }));
741
- return await this.httpRequest(url.toString(), UpdateStreamSubscriptionResult, { method: "PUT", body });
782
+ return await this.httpRequest(url, UpdateStreamSubscriptionResult, { method: "PUT", body });
742
783
  }
743
784
  /* Utility functions */
744
785
  buildURL(endpoint) {
745
- return new URL(
746
- `./v1/${endpoint}`,
747
- // We ensure the `baseURL` ends with a `/` so that URL doesn't resolve the
748
- // path relative to the parent.
749
- `${this.baseURL}${this.baseURL.endsWith("/") ? "" : "/"}`
750
- );
786
+ return `${this.baseURL}${this.baseURL.endsWith("/") ? "" : "/"}v1/${endpoint}`;
751
787
  }
752
788
  appendUrlSearchParams(url, params) {
789
+ const urlSearchParams = new URLSearchParams();
753
790
  Object.entries(params).forEach(([key, value]) => {
754
791
  if (value !== void 0) {
755
- url.searchParams.append(key, String(value));
792
+ urlSearchParams.append(key, String(value));
756
793
  }
757
794
  });
795
+ if (urlSearchParams.size > 0) {
796
+ return `${url}?${urlSearchParams.toString()}`;
797
+ }
798
+ return url;
758
799
  }
759
800
  };
760
801
  // Annotate the CommonJS export names for ESM import in node:
package/dist/index.mjs CHANGED
@@ -55,6 +55,10 @@ __export(schemas_exports, {
55
55
  TunaPositionNotification: () => TunaPositionNotification,
56
56
  TunaPositionState: () => TunaPositionState,
57
57
  TunaPositionStateSchema: () => TunaPositionStateSchema,
58
+ TunaSpotPosition: () => TunaSpotPosition,
59
+ TunaSpotPositionNotification: () => TunaSpotPositionNotification,
60
+ TunaSpotPositionState: () => TunaSpotPositionState,
61
+ TunaSpotPositionStateSchema: () => TunaSpotPositionStateSchema,
58
62
  UpdateStreamSubscriptionResult: () => UpdateStreamSubscriptionResult,
59
63
  Vault: () => Vault,
60
64
  VaultHistoricalStats: () => VaultHistoricalStats,
@@ -100,6 +104,10 @@ var TunaPositionState = {
100
104
  CLOSED_BY_LIMIT_ORDER: "closed_by_limit_order",
101
105
  CLOSED: "closed"
102
106
  };
107
+ var TunaSpotPositionState = {
108
+ OPEN: "open",
109
+ CLOSED: "closed"
110
+ };
103
111
  var LimitOrderState = {
104
112
  OPEN: "open",
105
113
  PARTIALLY_FILLED: "partially_filled",
@@ -121,6 +129,7 @@ var PoolSubscriptionTopic = {
121
129
  };
122
130
  var WalletSubscriptionTopic = {
123
131
  TUNA_POSITIONS: "tuna_positions",
132
+ TUNA_SPOT_POSITIONS: "tuna_spot_positions",
124
133
  LENDING_POSITIONS: "lending_positions",
125
134
  FUSION_LIMIT_ORDERS: "fusion_limit_orders",
126
135
  STAKING_POSITION: "staking_position"
@@ -129,6 +138,10 @@ var NotificationEntitySchema = z.enum([NotificationEntity.POOL_SWAP, ...Object.v
129
138
  var NotificationActionSchema = z.enum([NotificationAction.CREATE, ...Object.values(NotificationAction)]);
130
139
  var PoolProviderSchema = z.enum([PoolProvider.ORCA, ...Object.values(PoolProvider)]);
131
140
  var TunaPositionStateSchema = z.enum([TunaPositionState.OPEN, ...Object.values(TunaPositionState)]);
141
+ var TunaSpotPositionStateSchema = z.enum([
142
+ TunaSpotPositionState.OPEN,
143
+ ...Object.values(TunaSpotPositionState)
144
+ ]);
132
145
  var LimitOrderStateSchema = z.enum([LimitOrderState.OPEN, ...Object.values(LimitOrderState)]);
133
146
  var StakingPositionHistoryActionTypeSchema = z.enum([
134
147
  StakingPositionHistoryActionType.STAKE,
@@ -318,6 +331,30 @@ var TunaPosition = z.object({
318
331
  updatedAtSlot: z.coerce.bigint(),
319
332
  closedAt: z.nullable(z.coerce.date())
320
333
  });
334
+ var TunaSpotPosition = z.object({
335
+ address: z.string(),
336
+ authority: z.string(),
337
+ version: z.number(),
338
+ state: TunaSpotPositionStateSchema,
339
+ entrySqrtPrice: z.coerce.bigint(),
340
+ lowerLimitOrderSqrtPrice: z.coerce.bigint(),
341
+ upperLimitOrderSqrtPrice: z.coerce.bigint(),
342
+ flags: z.number(),
343
+ pool: z.string(),
344
+ poolSqrtPrice: z.coerce.bigint(),
345
+ collateralToken: z.string(),
346
+ borrowToken: z.string(),
347
+ positionToken: z.string(),
348
+ collateral: amountWithUsd,
349
+ loanFunds: amountWithUsd,
350
+ currentLoan: amountWithUsd,
351
+ total: amountWithUsd,
352
+ pnlUsd: usdPnl,
353
+ openedAt: z.coerce.date(),
354
+ openedAtSlot: z.coerce.bigint(),
355
+ updatedAtSlot: z.coerce.bigint(),
356
+ closedAt: z.nullable(z.coerce.date())
357
+ });
321
358
  var PoolSwap = z.object({
322
359
  id: z.string(),
323
360
  amountIn: z.coerce.bigint(),
@@ -479,6 +516,7 @@ var PoolSwapNotification = createNotificationSchema(PoolSwap);
479
516
  var PoolPriceUpdateNotification = createNotificationSchema(PoolPriceUpdate);
480
517
  var OrderBookNotification = createNotificationSchema(OrderBook, OrderBookNotificationMeta);
481
518
  var TunaPositionNotification = createNotificationSchema(TunaPosition);
519
+ var TunaSpotPositionNotification = createNotificationSchema(TunaSpotPosition);
482
520
  var LendingPositionNotification = createNotificationSchema(LendingPosition);
483
521
  var LimitOrderNotification = createNotificationSchema(LimitOrder);
484
522
  var StakingPositionNotification = createNotificationSchema(StakingPosition);
@@ -553,35 +591,35 @@ var TunaApiClient = class {
553
591
  /* Endpoints */
554
592
  async getMints() {
555
593
  const url = this.buildURL("mints");
556
- return await this.httpRequest(url.toString(), Mint.array());
594
+ return await this.httpRequest(url, Mint.array());
557
595
  }
558
596
  async getMint(mintAddress) {
559
597
  const url = this.buildURL(`mints/${mintAddress}`);
560
- return await this.httpRequest(url.toString(), Mint);
598
+ return await this.httpRequest(url, Mint);
561
599
  }
562
600
  async getMarkets() {
563
601
  const url = this.buildURL("markets");
564
- return await this.httpRequest(url.toString(), Market.array());
602
+ return await this.httpRequest(url, Market.array());
565
603
  }
566
604
  async getMarket(marketAddress) {
567
605
  const url = this.buildURL(`markets/${marketAddress}`);
568
- return await this.httpRequest(url.toString(), Market);
606
+ return await this.httpRequest(url, Market);
569
607
  }
570
608
  async getOraclePrices() {
571
609
  const url = this.buildURL("oracle-prices");
572
- return await this.httpRequest(url.toString(), TokenOraclePrice.array());
610
+ return await this.httpRequest(url, TokenOraclePrice.array());
573
611
  }
574
612
  async getOraclePrice(mintAddress) {
575
613
  const url = this.buildURL(`oracle-prices/${mintAddress}`);
576
- return await this.httpRequest(url.toString(), TokenOraclePrice);
614
+ return await this.httpRequest(url, TokenOraclePrice);
577
615
  }
578
616
  async getVaults() {
579
617
  const url = this.buildURL("vaults");
580
- return await this.httpRequest(url.toString(), Vault.array());
618
+ return await this.httpRequest(url, Vault.array());
581
619
  }
582
620
  async getVault(vaultAddress) {
583
621
  const url = this.buildURL(`vaults/${vaultAddress}`);
584
- return await this.httpRequest(url.toString(), Vault);
622
+ return await this.httpRequest(url, Vault);
585
623
  }
586
624
  /**
587
625
  * Returns vault historical data for selected time interval.
@@ -589,137 +627,140 @@ var TunaApiClient = class {
589
627
  * Example usage: getVaultHistory('H3ifgix98vzi3yCPbmZDLTheeTRf2jykXx8FpY5L7Sfd', '2025-03-10', '2025-04-10')
590
628
  */
591
629
  async getVaultHistory(vaultAddress, from, to) {
592
- const url = this.buildURL(`vaults/${vaultAddress}/history`);
593
- this.appendUrlSearchParams(url, { from: from.toISOString().slice(0, 10), to: to.toISOString().slice(0, 10) });
594
- return await this.httpRequest(url.toString(), VaultHistoricalStats.array());
630
+ const url = this.appendUrlSearchParams(this.buildURL(`vaults/${vaultAddress}/history`), {
631
+ from: from.toISOString().slice(0, 10),
632
+ to: to.toISOString().slice(0, 10)
633
+ });
634
+ return await this.httpRequest(url, VaultHistoricalStats.array());
595
635
  }
596
636
  async getPools(providerFilter) {
597
- const url = this.buildURL("pools");
598
- if (providerFilter && providerFilter !== "all" /* ALL */) {
599
- this.appendUrlSearchParams(url, { provider: providerFilter });
600
- }
601
- return await this.httpRequest(url.toString(), Pool.array());
637
+ const url = this.appendUrlSearchParams(this.buildURL("pools"), {
638
+ provider: providerFilter && providerFilter !== "all" /* ALL */ ? providerFilter : void 0
639
+ });
640
+ return await this.httpRequest(url, Pool.array());
602
641
  }
603
642
  async getPool(address) {
604
643
  const url = this.buildURL(`pools/${address}`);
605
- return await this.httpRequest(url.toString(), Pool);
644
+ return await this.httpRequest(url, Pool);
606
645
  }
607
646
  async getPoolTicks(poolAddress) {
608
647
  const url = this.buildURL(`pools/${poolAddress}/ticks`);
609
- return await this.httpRequest(url.toString(), PoolTicks);
648
+ return await this.httpRequest(url, PoolTicks);
610
649
  }
611
650
  async getPoolSwaps(poolAddress) {
612
651
  const url = this.buildURL(`pools/${poolAddress}/swaps`);
613
- return await this.httpRequest(url.toString(), PoolSwap.array());
652
+ return await this.httpRequest(url, PoolSwap.array());
614
653
  }
615
654
  async getPoolOrderBook(poolAddress, priceStep, inverted) {
616
- const url = this.buildURL(`pools/${poolAddress}/order-book`);
617
- this.appendUrlSearchParams(url, { price_step: priceStep.toString() });
618
- if (inverted) {
619
- this.appendUrlSearchParams(url, { inverted: inverted.toString() });
620
- }
621
- return await this.httpRequest(url.toString(), OrderBook);
655
+ const url = this.appendUrlSearchParams(this.buildURL(`pools/${poolAddress}/order-book`), {
656
+ price_step: priceStep,
657
+ inverted: inverted || void 0
658
+ });
659
+ return await this.httpRequest(url, OrderBook);
622
660
  }
623
661
  async getPoolPriceCandles(poolAddress, options) {
624
662
  const { from, to, interval, candles } = options;
625
- const url = this.buildURL(`pools/${poolAddress}/candles`);
626
- this.appendUrlSearchParams(url, {
663
+ const url = this.appendUrlSearchParams(this.buildURL(`pools/${poolAddress}/candles`), {
627
664
  from: from.toISOString(),
628
665
  to: to.toISOString(),
629
- candles: candles.toString(),
666
+ candles,
630
667
  interval
631
668
  });
632
- return await this.httpRequest(url.toString(), PoolPriceCandle.array());
669
+ return await this.httpRequest(url, PoolPriceCandle.array());
633
670
  }
634
671
  async getStakingTreasury() {
635
672
  const url = this.buildURL(`staking/treasury`);
636
- return await this.httpRequest(url.toString(), StakingTreasury);
673
+ return await this.httpRequest(url, StakingTreasury);
637
674
  }
638
675
  async getStakingLeaderboard(page, pageSize, search) {
639
- const url = this.buildURL(`staking/leaderboard`);
640
- this.appendUrlSearchParams(url, {
641
- page: page.toString(),
642
- page_size: pageSize.toString(),
643
- ...search ? { search } : {}
676
+ const url = this.appendUrlSearchParams(this.buildURL(`staking/leaderboard`), {
677
+ page,
678
+ page_size: pageSize,
679
+ search: search || void 0
644
680
  });
645
- return await this.httpRequest(url.toString(), StakingLeaderboardPage, { parseRoot: true });
681
+ return await this.httpRequest(url, StakingLeaderboardPage, { parseRoot: true });
646
682
  }
647
683
  async getUserLendingPositions(userAddress) {
648
684
  const url = this.buildURL(`users/${userAddress}/lending-positions`);
649
- return await this.httpRequest(url.toString(), LendingPosition.array());
685
+ return await this.httpRequest(url, LendingPosition.array());
650
686
  }
651
687
  async getUserLendingPositionByAddress(userAddress, lendingPositionAddress) {
652
688
  const url = this.buildURL(`users/${userAddress}/lending-positions/${lendingPositionAddress}`);
653
- return await this.httpRequest(url.toString(), LendingPosition);
689
+ return await this.httpRequest(url, LendingPosition);
654
690
  }
655
691
  async getUserTunaPositions(userAddress) {
656
692
  const url = this.buildURL(`users/${userAddress}/tuna-positions`);
657
- return await this.httpRequest(url.toString(), TunaPosition.array());
693
+ return await this.httpRequest(url, TunaPosition.array());
658
694
  }
659
695
  async getUserTunaPositionByAddress(userAddress, tunaPositionAddress) {
660
696
  const url = this.buildURL(`users/${userAddress}/tuna-positions/${tunaPositionAddress}`);
661
- return await this.httpRequest(url.toString(), TunaPosition);
697
+ return await this.httpRequest(url, TunaPosition);
698
+ }
699
+ async getUserTunaSpotPositions(userAddress) {
700
+ const url = this.buildURL(`users/${userAddress}/spot-positions`);
701
+ return await this.httpRequest(url, TunaSpotPosition.array());
702
+ }
703
+ async getUserTunaSpotPositionByAddress(userAddress, tunaSpotPositionAddress) {
704
+ const url = this.buildURL(`users/${userAddress}/spot-positions/${tunaSpotPositionAddress}`);
705
+ return await this.httpRequest(url, TunaSpotPosition);
662
706
  }
663
707
  async getUserLimitOrders(userAddress, poolFilter) {
664
- const url = this.buildURL(`users/${userAddress}/limit-orders`);
665
- if (poolFilter) {
666
- this.appendUrlSearchParams(url, { pool: poolFilter });
667
- }
668
- return await this.httpRequest(url.toString(), LimitOrder.array());
708
+ const url = this.appendUrlSearchParams(this.buildURL(`users/${userAddress}/limit-orders`), {
709
+ pool: poolFilter || void 0
710
+ });
711
+ return await this.httpRequest(url, LimitOrder.array());
669
712
  }
670
713
  async getUserLimitOrderByAddress(userAddress, limitOrderAddress) {
671
714
  const url = this.buildURL(`users/${userAddress}/limit-orders/${limitOrderAddress}`);
672
- return await this.httpRequest(url.toString(), LimitOrder);
715
+ return await this.httpRequest(url, LimitOrder);
673
716
  }
674
717
  async getUserStakingPosition(userAddress) {
675
718
  const url = this.buildURL(`users/${userAddress}/staking-position`);
676
- return await this.httpRequest(url.toString(), StakingPosition);
719
+ return await this.httpRequest(url, StakingPosition);
677
720
  }
678
721
  async getUserStakingPositionHistory(userAddress) {
679
722
  const url = this.buildURL(`users/${userAddress}/staking-position/history`);
680
- return await this.httpRequest(url.toString(), StakingPositionHistoryAction.array());
723
+ return await this.httpRequest(url, StakingPositionHistoryAction.array());
681
724
  }
682
725
  async getFeesStats(from, to, interval) {
683
- const url = this.buildURL(`stats/fees`);
684
- this.appendUrlSearchParams(url, {
726
+ const url = this.appendUrlSearchParams(this.buildURL(`stats/fees`), {
685
727
  from: from.toISOString(),
686
728
  to: to.toISOString(),
687
729
  interval
688
730
  });
689
- return await this.httpRequest(url.toString(), FeesStatsGroup.array());
731
+ return await this.httpRequest(url, FeesStatsGroup.array());
690
732
  }
691
733
  async getStakingRevenueStats(from, to) {
692
- const url = this.buildURL(`stats/staking/revenue`);
693
- this.appendUrlSearchParams(url, {
734
+ const url = this.appendUrlSearchParams(this.buildURL(`stats/staking/revenue`), {
694
735
  from: from.toISOString().split("T")[0],
695
736
  to: to.toISOString().split("T")[0]
696
737
  });
697
- return await this.httpRequest(url.toString(), StakingRevenueStatsGroup.array());
738
+ return await this.httpRequest(url, StakingRevenueStatsGroup.array());
698
739
  }
699
740
  async getUpdatesStream() {
700
741
  const url = this.buildURL(`streams/sse`);
701
- return new EventSource(url.toString());
742
+ return new EventSource(url);
702
743
  }
703
744
  async updateStreamSubscription(streamId, subscription) {
704
745
  const url = this.buildURL(`streams/${streamId}/subscription`);
705
746
  const body = JSON.stringify(snakecaseKeys(subscription, { deep: true }));
706
- return await this.httpRequest(url.toString(), UpdateStreamSubscriptionResult, { method: "PUT", body });
747
+ return await this.httpRequest(url, UpdateStreamSubscriptionResult, { method: "PUT", body });
707
748
  }
708
749
  /* Utility functions */
709
750
  buildURL(endpoint) {
710
- return new URL(
711
- `./v1/${endpoint}`,
712
- // We ensure the `baseURL` ends with a `/` so that URL doesn't resolve the
713
- // path relative to the parent.
714
- `${this.baseURL}${this.baseURL.endsWith("/") ? "" : "/"}`
715
- );
751
+ return `${this.baseURL}${this.baseURL.endsWith("/") ? "" : "/"}v1/${endpoint}`;
716
752
  }
717
753
  appendUrlSearchParams(url, params) {
754
+ const urlSearchParams = new URLSearchParams();
718
755
  Object.entries(params).forEach(([key, value]) => {
719
756
  if (value !== void 0) {
720
- url.searchParams.append(key, String(value));
757
+ urlSearchParams.append(key, String(value));
721
758
  }
722
759
  });
760
+ if (urlSearchParams.size > 0) {
761
+ return `${url}?${urlSearchParams.toString()}`;
762
+ }
763
+ return url;
723
764
  }
724
765
  };
725
766
  export {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@crypticdot/defituna-api",
3
- "version": "1.1.55",
3
+ "version": "1.2.0",
4
4
  "private": false,
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.mjs",
@@ -14,8 +14,8 @@
14
14
  "README.md"
15
15
  ],
16
16
  "devDependencies": {
17
- "@crypticdot/defituna-client": "^2.0.6",
18
- "@crypticdot/eslint-config": "^1.0.0",
17
+ "@crypticdot/defituna-client": "^3.0.2",
18
+ "@crypticdot/eslint-config": "^1.0.2",
19
19
  "@crypticdot/prettier-config": "^1.0.0",
20
20
  "@crypticdot/typescript-config": "^1.0.0",
21
21
  "@solana/kit": "^2.1.0",