@crypticdot/defituna-api 1.1.29 → 1.1.30

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.d.mts CHANGED
@@ -26,11 +26,23 @@ declare const LimitOrderState: {
26
26
  readonly COMPLETE: "complete";
27
27
  readonly CANCELLED: "cancelled";
28
28
  };
29
+ declare const PoolSubscriptionTopic: {
30
+ readonly ORDER_BOOK: "order_book";
31
+ readonly POOL_PRICES: "pool_prices";
32
+ readonly POOL_SWAPS: "pool_swaps";
33
+ };
34
+ declare const WalletSubscriptionTopic: {
35
+ readonly TUNA_POSITIONS: "tuna_positions";
36
+ readonly LENDING_POSITIONS: "lending_positions";
37
+ readonly FUSION_LIMIT_ORDERS: "fusion_limit_orders";
38
+ };
29
39
  declare const NotificationEntitySchema: z.ZodEnum<["pool_swap", ...("pool_swap" | "pool_price" | "order_book")[]]>;
30
40
  declare const NotificationActionSchema: z.ZodEnum<["create", ...("create" | "update")[]]>;
31
41
  declare const PoolProviderSchema: z.ZodEnum<["orca", ...("orca" | "fusion")[]]>;
32
42
  declare const TunaPositionStateSchema: z.ZodEnum<["open", ...("open" | "liquidated" | "closed_by_limit_order" | "closed")[]]>;
33
43
  declare const LimitOrderStateSchema: z.ZodEnum<["open", ...("open" | "partially_filled" | "filled" | "complete" | "cancelled")[]]>;
44
+ declare const PoolSubscriptionTopicSchema: z.ZodEnum<["order_book", ...("order_book" | "pool_prices" | "pool_swaps")[]]>;
45
+ declare const WalletSubscriptionTopicSchema: z.ZodEnum<["tuna_positions", ...("tuna_positions" | "lending_positions" | "fusion_limit_orders")[]]>;
34
46
  declare const Mint$1: z.ZodObject<{
35
47
  symbol: z.ZodString;
36
48
  mint: z.ZodString;
@@ -746,6 +758,7 @@ declare const TunaPosition$1: z.ZodObject<{
746
758
  }>;
747
759
  openedAt: z.ZodDate;
748
760
  updatedAtSlot: z.ZodBigInt;
761
+ closedAt: z.ZodNullable<z.ZodDate>;
749
762
  }, "strip", z.ZodTypeAny, {
750
763
  address: string;
751
764
  liquidity: bigint;
@@ -833,6 +846,7 @@ declare const TunaPosition$1: z.ZodObject<{
833
846
  };
834
847
  openedAt: Date;
835
848
  updatedAtSlot: bigint;
849
+ closedAt: Date | null;
836
850
  }, {
837
851
  address: string;
838
852
  liquidity: bigint;
@@ -920,6 +934,7 @@ declare const TunaPosition$1: z.ZodObject<{
920
934
  };
921
935
  openedAt: Date;
922
936
  updatedAtSlot: bigint;
937
+ closedAt: Date | null;
923
938
  }>;
924
939
  declare const PoolSwap$1: z.ZodObject<{
925
940
  id: z.ZodString;
@@ -1096,6 +1111,7 @@ declare const LimitOrder$1: z.ZodObject<{
1096
1111
  state: "open" | "partially_filled" | "filled" | "complete" | "cancelled";
1097
1112
  pool: string;
1098
1113
  openedAt: Date;
1114
+ closedAt: Date | null;
1099
1115
  amountIn: {
1100
1116
  amount: bigint;
1101
1117
  usd: number;
@@ -1109,13 +1125,13 @@ declare const LimitOrder$1: z.ZodObject<{
1109
1125
  fillRatio: number;
1110
1126
  openTxSignature: string;
1111
1127
  closeTxSignature: string | null;
1112
- closedAt: Date | null;
1113
1128
  }, {
1114
1129
  mint: string;
1115
1130
  address: string;
1116
1131
  state: "open" | "partially_filled" | "filled" | "complete" | "cancelled";
1117
1132
  pool: string;
1118
1133
  openedAt: Date;
1134
+ closedAt: Date | null;
1119
1135
  amountIn: {
1120
1136
  amount: bigint;
1121
1137
  usd: number;
@@ -1129,7 +1145,6 @@ declare const LimitOrder$1: z.ZodObject<{
1129
1145
  fillRatio: number;
1130
1146
  openTxSignature: string;
1131
1147
  closeTxSignature: string | null;
1132
- closedAt: Date | null;
1133
1148
  }>;
1134
1149
  declare const PoolPriceCandle$1: z.ZodObject<{
1135
1150
  time: z.ZodNumber;
@@ -1150,6 +1165,13 @@ declare const PoolPriceCandle$1: z.ZodObject<{
1150
1165
  high: number;
1151
1166
  low: number;
1152
1167
  }>;
1168
+ declare const UpdateStreamSubscriptionResult: z.ZodObject<{
1169
+ status: z.ZodString;
1170
+ }, "strip", z.ZodTypeAny, {
1171
+ status: string;
1172
+ }, {
1173
+ status: string;
1174
+ }>;
1153
1175
  declare const OrderBookNotificationMeta: z.ZodObject<{
1154
1176
  pool: z.ZodString;
1155
1177
  priceStep: z.ZodNumber;
@@ -1636,16 +1658,23 @@ declare const schemas_OrderBookNotificationMeta: typeof OrderBookNotificationMet
1636
1658
  declare const schemas_PoolPriceUpdateNotification: typeof PoolPriceUpdateNotification;
1637
1659
  declare const schemas_PoolProvider: typeof PoolProvider;
1638
1660
  declare const schemas_PoolProviderSchema: typeof PoolProviderSchema;
1661
+ declare const schemas_PoolSubscriptionTopic: typeof PoolSubscriptionTopic;
1662
+ declare const schemas_PoolSubscriptionTopicSchema: typeof PoolSubscriptionTopicSchema;
1639
1663
  declare const schemas_PoolSwapNotification: typeof PoolSwapNotification;
1640
1664
  declare const schemas_TunaPositionState: typeof TunaPositionState;
1641
1665
  declare const schemas_TunaPositionStateSchema: typeof TunaPositionStateSchema;
1666
+ declare const schemas_UpdateStreamSubscriptionResult: typeof UpdateStreamSubscriptionResult;
1667
+ declare const schemas_WalletSubscriptionTopic: typeof WalletSubscriptionTopic;
1668
+ declare const schemas_WalletSubscriptionTopicSchema: typeof WalletSubscriptionTopicSchema;
1642
1669
  declare namespace schemas {
1643
- export { LendingPosition$1 as LendingPosition, LimitOrder$1 as LimitOrder, schemas_LimitOrderState as LimitOrderState, schemas_LimitOrderStateSchema as LimitOrderStateSchema, Market$1 as Market, Mint$1 as Mint, schemas_NotificationAction as NotificationAction, schemas_NotificationActionSchema as NotificationActionSchema, schemas_NotificationEntity as NotificationEntity, schemas_NotificationEntitySchema as NotificationEntitySchema, OrderBook$1 as OrderBook, OrderBookEntry$1 as OrderBookEntry, schemas_OrderBookNotification as OrderBookNotification, schemas_OrderBookNotificationMeta as OrderBookNotificationMeta, Pool$1 as Pool, PoolPriceCandle$1 as PoolPriceCandle, PoolPriceUpdate$1 as PoolPriceUpdate, schemas_PoolPriceUpdateNotification as PoolPriceUpdateNotification, schemas_PoolProvider as PoolProvider, schemas_PoolProviderSchema as PoolProviderSchema, PoolSwap$1 as PoolSwap, schemas_PoolSwapNotification as PoolSwapNotification, PoolTicks$1 as PoolTicks, Tick$1 as Tick, TokenOraclePrice$1 as TokenOraclePrice, TunaPosition$1 as TunaPosition, schemas_TunaPositionState as TunaPositionState, schemas_TunaPositionStateSchema as TunaPositionStateSchema, Vault$1 as Vault };
1670
+ export { LendingPosition$1 as LendingPosition, LimitOrder$1 as LimitOrder, schemas_LimitOrderState as LimitOrderState, schemas_LimitOrderStateSchema as LimitOrderStateSchema, Market$1 as Market, Mint$1 as Mint, schemas_NotificationAction as NotificationAction, schemas_NotificationActionSchema as NotificationActionSchema, schemas_NotificationEntity as NotificationEntity, schemas_NotificationEntitySchema as NotificationEntitySchema, OrderBook$1 as OrderBook, OrderBookEntry$1 as OrderBookEntry, schemas_OrderBookNotification as OrderBookNotification, schemas_OrderBookNotificationMeta as OrderBookNotificationMeta, Pool$1 as Pool, PoolPriceCandle$1 as PoolPriceCandle, PoolPriceUpdate$1 as PoolPriceUpdate, schemas_PoolPriceUpdateNotification as PoolPriceUpdateNotification, schemas_PoolProvider as PoolProvider, schemas_PoolProviderSchema as PoolProviderSchema, schemas_PoolSubscriptionTopic as PoolSubscriptionTopic, schemas_PoolSubscriptionTopicSchema as PoolSubscriptionTopicSchema, PoolSwap$1 as PoolSwap, schemas_PoolSwapNotification as PoolSwapNotification, PoolTicks$1 as PoolTicks, Tick$1 as Tick, TokenOraclePrice$1 as TokenOraclePrice, TunaPosition$1 as TunaPosition, schemas_TunaPositionState as TunaPositionState, schemas_TunaPositionStateSchema as TunaPositionStateSchema, schemas_UpdateStreamSubscriptionResult as UpdateStreamSubscriptionResult, Vault$1 as Vault, schemas_WalletSubscriptionTopic as WalletSubscriptionTopic, schemas_WalletSubscriptionTopicSchema as WalletSubscriptionTopicSchema };
1644
1671
  }
1645
1672
 
1646
1673
  type PoolProviderType = z.infer<typeof PoolProviderSchema>;
1647
1674
  type TunaPositionStateType = z.infer<typeof TunaPositionStateSchema>;
1648
1675
  type LimitOrderStateType = z.infer<typeof LimitOrderStateSchema>;
1676
+ type PoolSubscriptionTopicType = z.infer<typeof PoolSubscriptionTopicSchema>;
1677
+ type WalletSubscriptionTopicType = z.infer<typeof WalletSubscriptionTopicSchema>;
1649
1678
  type Mint = z.infer<typeof Mint$1>;
1650
1679
  type Market = z.infer<typeof Market$1>;
1651
1680
  type TokenOraclePrice = z.infer<typeof TokenOraclePrice$1>;
@@ -1661,6 +1690,18 @@ type TunaPosition = z.infer<typeof TunaPosition$1>;
1661
1690
  type LimitOrder = z.infer<typeof LimitOrder$1>;
1662
1691
  type PoolPriceCandle = z.infer<typeof PoolPriceCandle$1>;
1663
1692
  type PoolPriceUpdate = z.infer<typeof PoolPriceUpdate$1>;
1693
+ type SubscriptionPayload = {
1694
+ pools?: {
1695
+ address: string;
1696
+ topics: PoolSubscriptionTopicType[];
1697
+ orderBookPriceStep?: number;
1698
+ isInverted?: boolean;
1699
+ }[];
1700
+ wallet?: {
1701
+ address: string;
1702
+ topics: WalletSubscriptionTopicType[];
1703
+ };
1704
+ };
1664
1705
  type DurationInMs = number;
1665
1706
  declare enum ProviderFilter {
1666
1707
  ORCA = "orca",
@@ -1722,9 +1763,14 @@ declare class TunaApiClient {
1722
1763
  getUserTunaPositionByAddress(userAddress: string, tunaPositionAddress: string): Promise<TunaPosition>;
1723
1764
  getUserLimitOrders(userAddress: string, poolFilter?: string): Promise<LimitOrder[]>;
1724
1765
  getUserLimitOrderByAddress(userAddress: string, limitOrderAddress: string): Promise<LimitOrder>;
1766
+ /**
1767
+ * @deprecated Use getUpdatesStream instead
1768
+ */
1725
1769
  getPoolUpdatesStream(poolAddress: string, priceStep?: number, inverted?: boolean): Promise<EventSource>;
1770
+ getUpdatesStream(): Promise<EventSource>;
1771
+ updateStreamSubscription(streamId: string, subscription: SubscriptionPayload): Promise<unknown>;
1726
1772
  private buildURL;
1727
1773
  private appendUrlSearchParams;
1728
1774
  }
1729
1775
 
1730
- export { type DurationInMs, type GetPoolPriceCandlesOptions, type LendingPosition, type LimitOrder, type LimitOrderStateType, type Market, type Mint, NotificationAction, NotificationEntity, type OrderBook, type OrderBookEntry, type Pool, type PoolPriceCandle, type PoolPriceUpdate, PoolProvider, type PoolProviderType, type PoolSwap, type PoolTicks, ProviderFilter, type Tick, type TokenOraclePrice, TunaApiClient, type TunaApiClientConfig, type TunaPosition, TunaPositionState, type TunaPositionStateType, type Vault, schemas };
1776
+ export { type DurationInMs, type GetPoolPriceCandlesOptions, type LendingPosition, type LimitOrder, type LimitOrderStateType, type Market, type Mint, NotificationAction, NotificationEntity, type OrderBook, type OrderBookEntry, type Pool, type PoolPriceCandle, type PoolPriceUpdate, PoolProvider, type PoolProviderType, type PoolSubscriptionTopicType, type PoolSwap, type PoolTicks, ProviderFilter, type SubscriptionPayload, type Tick, type TokenOraclePrice, TunaApiClient, type TunaApiClientConfig, type TunaPosition, TunaPositionState, type TunaPositionStateType, type Vault, type WalletSubscriptionTopicType, schemas };
package/dist/index.d.ts CHANGED
@@ -26,11 +26,23 @@ declare const LimitOrderState: {
26
26
  readonly COMPLETE: "complete";
27
27
  readonly CANCELLED: "cancelled";
28
28
  };
29
+ declare const PoolSubscriptionTopic: {
30
+ readonly ORDER_BOOK: "order_book";
31
+ readonly POOL_PRICES: "pool_prices";
32
+ readonly POOL_SWAPS: "pool_swaps";
33
+ };
34
+ declare const WalletSubscriptionTopic: {
35
+ readonly TUNA_POSITIONS: "tuna_positions";
36
+ readonly LENDING_POSITIONS: "lending_positions";
37
+ readonly FUSION_LIMIT_ORDERS: "fusion_limit_orders";
38
+ };
29
39
  declare const NotificationEntitySchema: z.ZodEnum<["pool_swap", ...("pool_swap" | "pool_price" | "order_book")[]]>;
30
40
  declare const NotificationActionSchema: z.ZodEnum<["create", ...("create" | "update")[]]>;
31
41
  declare const PoolProviderSchema: z.ZodEnum<["orca", ...("orca" | "fusion")[]]>;
32
42
  declare const TunaPositionStateSchema: z.ZodEnum<["open", ...("open" | "liquidated" | "closed_by_limit_order" | "closed")[]]>;
33
43
  declare const LimitOrderStateSchema: z.ZodEnum<["open", ...("open" | "partially_filled" | "filled" | "complete" | "cancelled")[]]>;
44
+ declare const PoolSubscriptionTopicSchema: z.ZodEnum<["order_book", ...("order_book" | "pool_prices" | "pool_swaps")[]]>;
45
+ declare const WalletSubscriptionTopicSchema: z.ZodEnum<["tuna_positions", ...("tuna_positions" | "lending_positions" | "fusion_limit_orders")[]]>;
34
46
  declare const Mint$1: z.ZodObject<{
35
47
  symbol: z.ZodString;
36
48
  mint: z.ZodString;
@@ -746,6 +758,7 @@ declare const TunaPosition$1: z.ZodObject<{
746
758
  }>;
747
759
  openedAt: z.ZodDate;
748
760
  updatedAtSlot: z.ZodBigInt;
761
+ closedAt: z.ZodNullable<z.ZodDate>;
749
762
  }, "strip", z.ZodTypeAny, {
750
763
  address: string;
751
764
  liquidity: bigint;
@@ -833,6 +846,7 @@ declare const TunaPosition$1: z.ZodObject<{
833
846
  };
834
847
  openedAt: Date;
835
848
  updatedAtSlot: bigint;
849
+ closedAt: Date | null;
836
850
  }, {
837
851
  address: string;
838
852
  liquidity: bigint;
@@ -920,6 +934,7 @@ declare const TunaPosition$1: z.ZodObject<{
920
934
  };
921
935
  openedAt: Date;
922
936
  updatedAtSlot: bigint;
937
+ closedAt: Date | null;
923
938
  }>;
924
939
  declare const PoolSwap$1: z.ZodObject<{
925
940
  id: z.ZodString;
@@ -1096,6 +1111,7 @@ declare const LimitOrder$1: z.ZodObject<{
1096
1111
  state: "open" | "partially_filled" | "filled" | "complete" | "cancelled";
1097
1112
  pool: string;
1098
1113
  openedAt: Date;
1114
+ closedAt: Date | null;
1099
1115
  amountIn: {
1100
1116
  amount: bigint;
1101
1117
  usd: number;
@@ -1109,13 +1125,13 @@ declare const LimitOrder$1: z.ZodObject<{
1109
1125
  fillRatio: number;
1110
1126
  openTxSignature: string;
1111
1127
  closeTxSignature: string | null;
1112
- closedAt: Date | null;
1113
1128
  }, {
1114
1129
  mint: string;
1115
1130
  address: string;
1116
1131
  state: "open" | "partially_filled" | "filled" | "complete" | "cancelled";
1117
1132
  pool: string;
1118
1133
  openedAt: Date;
1134
+ closedAt: Date | null;
1119
1135
  amountIn: {
1120
1136
  amount: bigint;
1121
1137
  usd: number;
@@ -1129,7 +1145,6 @@ declare const LimitOrder$1: z.ZodObject<{
1129
1145
  fillRatio: number;
1130
1146
  openTxSignature: string;
1131
1147
  closeTxSignature: string | null;
1132
- closedAt: Date | null;
1133
1148
  }>;
1134
1149
  declare const PoolPriceCandle$1: z.ZodObject<{
1135
1150
  time: z.ZodNumber;
@@ -1150,6 +1165,13 @@ declare const PoolPriceCandle$1: z.ZodObject<{
1150
1165
  high: number;
1151
1166
  low: number;
1152
1167
  }>;
1168
+ declare const UpdateStreamSubscriptionResult: z.ZodObject<{
1169
+ status: z.ZodString;
1170
+ }, "strip", z.ZodTypeAny, {
1171
+ status: string;
1172
+ }, {
1173
+ status: string;
1174
+ }>;
1153
1175
  declare const OrderBookNotificationMeta: z.ZodObject<{
1154
1176
  pool: z.ZodString;
1155
1177
  priceStep: z.ZodNumber;
@@ -1636,16 +1658,23 @@ declare const schemas_OrderBookNotificationMeta: typeof OrderBookNotificationMet
1636
1658
  declare const schemas_PoolPriceUpdateNotification: typeof PoolPriceUpdateNotification;
1637
1659
  declare const schemas_PoolProvider: typeof PoolProvider;
1638
1660
  declare const schemas_PoolProviderSchema: typeof PoolProviderSchema;
1661
+ declare const schemas_PoolSubscriptionTopic: typeof PoolSubscriptionTopic;
1662
+ declare const schemas_PoolSubscriptionTopicSchema: typeof PoolSubscriptionTopicSchema;
1639
1663
  declare const schemas_PoolSwapNotification: typeof PoolSwapNotification;
1640
1664
  declare const schemas_TunaPositionState: typeof TunaPositionState;
1641
1665
  declare const schemas_TunaPositionStateSchema: typeof TunaPositionStateSchema;
1666
+ declare const schemas_UpdateStreamSubscriptionResult: typeof UpdateStreamSubscriptionResult;
1667
+ declare const schemas_WalletSubscriptionTopic: typeof WalletSubscriptionTopic;
1668
+ declare const schemas_WalletSubscriptionTopicSchema: typeof WalletSubscriptionTopicSchema;
1642
1669
  declare namespace schemas {
1643
- export { LendingPosition$1 as LendingPosition, LimitOrder$1 as LimitOrder, schemas_LimitOrderState as LimitOrderState, schemas_LimitOrderStateSchema as LimitOrderStateSchema, Market$1 as Market, Mint$1 as Mint, schemas_NotificationAction as NotificationAction, schemas_NotificationActionSchema as NotificationActionSchema, schemas_NotificationEntity as NotificationEntity, schemas_NotificationEntitySchema as NotificationEntitySchema, OrderBook$1 as OrderBook, OrderBookEntry$1 as OrderBookEntry, schemas_OrderBookNotification as OrderBookNotification, schemas_OrderBookNotificationMeta as OrderBookNotificationMeta, Pool$1 as Pool, PoolPriceCandle$1 as PoolPriceCandle, PoolPriceUpdate$1 as PoolPriceUpdate, schemas_PoolPriceUpdateNotification as PoolPriceUpdateNotification, schemas_PoolProvider as PoolProvider, schemas_PoolProviderSchema as PoolProviderSchema, PoolSwap$1 as PoolSwap, schemas_PoolSwapNotification as PoolSwapNotification, PoolTicks$1 as PoolTicks, Tick$1 as Tick, TokenOraclePrice$1 as TokenOraclePrice, TunaPosition$1 as TunaPosition, schemas_TunaPositionState as TunaPositionState, schemas_TunaPositionStateSchema as TunaPositionStateSchema, Vault$1 as Vault };
1670
+ export { LendingPosition$1 as LendingPosition, LimitOrder$1 as LimitOrder, schemas_LimitOrderState as LimitOrderState, schemas_LimitOrderStateSchema as LimitOrderStateSchema, Market$1 as Market, Mint$1 as Mint, schemas_NotificationAction as NotificationAction, schemas_NotificationActionSchema as NotificationActionSchema, schemas_NotificationEntity as NotificationEntity, schemas_NotificationEntitySchema as NotificationEntitySchema, OrderBook$1 as OrderBook, OrderBookEntry$1 as OrderBookEntry, schemas_OrderBookNotification as OrderBookNotification, schemas_OrderBookNotificationMeta as OrderBookNotificationMeta, Pool$1 as Pool, PoolPriceCandle$1 as PoolPriceCandle, PoolPriceUpdate$1 as PoolPriceUpdate, schemas_PoolPriceUpdateNotification as PoolPriceUpdateNotification, schemas_PoolProvider as PoolProvider, schemas_PoolProviderSchema as PoolProviderSchema, schemas_PoolSubscriptionTopic as PoolSubscriptionTopic, schemas_PoolSubscriptionTopicSchema as PoolSubscriptionTopicSchema, PoolSwap$1 as PoolSwap, schemas_PoolSwapNotification as PoolSwapNotification, PoolTicks$1 as PoolTicks, Tick$1 as Tick, TokenOraclePrice$1 as TokenOraclePrice, TunaPosition$1 as TunaPosition, schemas_TunaPositionState as TunaPositionState, schemas_TunaPositionStateSchema as TunaPositionStateSchema, schemas_UpdateStreamSubscriptionResult as UpdateStreamSubscriptionResult, Vault$1 as Vault, schemas_WalletSubscriptionTopic as WalletSubscriptionTopic, schemas_WalletSubscriptionTopicSchema as WalletSubscriptionTopicSchema };
1644
1671
  }
1645
1672
 
1646
1673
  type PoolProviderType = z.infer<typeof PoolProviderSchema>;
1647
1674
  type TunaPositionStateType = z.infer<typeof TunaPositionStateSchema>;
1648
1675
  type LimitOrderStateType = z.infer<typeof LimitOrderStateSchema>;
1676
+ type PoolSubscriptionTopicType = z.infer<typeof PoolSubscriptionTopicSchema>;
1677
+ type WalletSubscriptionTopicType = z.infer<typeof WalletSubscriptionTopicSchema>;
1649
1678
  type Mint = z.infer<typeof Mint$1>;
1650
1679
  type Market = z.infer<typeof Market$1>;
1651
1680
  type TokenOraclePrice = z.infer<typeof TokenOraclePrice$1>;
@@ -1661,6 +1690,18 @@ type TunaPosition = z.infer<typeof TunaPosition$1>;
1661
1690
  type LimitOrder = z.infer<typeof LimitOrder$1>;
1662
1691
  type PoolPriceCandle = z.infer<typeof PoolPriceCandle$1>;
1663
1692
  type PoolPriceUpdate = z.infer<typeof PoolPriceUpdate$1>;
1693
+ type SubscriptionPayload = {
1694
+ pools?: {
1695
+ address: string;
1696
+ topics: PoolSubscriptionTopicType[];
1697
+ orderBookPriceStep?: number;
1698
+ isInverted?: boolean;
1699
+ }[];
1700
+ wallet?: {
1701
+ address: string;
1702
+ topics: WalletSubscriptionTopicType[];
1703
+ };
1704
+ };
1664
1705
  type DurationInMs = number;
1665
1706
  declare enum ProviderFilter {
1666
1707
  ORCA = "orca",
@@ -1722,9 +1763,14 @@ declare class TunaApiClient {
1722
1763
  getUserTunaPositionByAddress(userAddress: string, tunaPositionAddress: string): Promise<TunaPosition>;
1723
1764
  getUserLimitOrders(userAddress: string, poolFilter?: string): Promise<LimitOrder[]>;
1724
1765
  getUserLimitOrderByAddress(userAddress: string, limitOrderAddress: string): Promise<LimitOrder>;
1766
+ /**
1767
+ * @deprecated Use getUpdatesStream instead
1768
+ */
1725
1769
  getPoolUpdatesStream(poolAddress: string, priceStep?: number, inverted?: boolean): Promise<EventSource>;
1770
+ getUpdatesStream(): Promise<EventSource>;
1771
+ updateStreamSubscription(streamId: string, subscription: SubscriptionPayload): Promise<unknown>;
1726
1772
  private buildURL;
1727
1773
  private appendUrlSearchParams;
1728
1774
  }
1729
1775
 
1730
- export { type DurationInMs, type GetPoolPriceCandlesOptions, type LendingPosition, type LimitOrder, type LimitOrderStateType, type Market, type Mint, NotificationAction, NotificationEntity, type OrderBook, type OrderBookEntry, type Pool, type PoolPriceCandle, type PoolPriceUpdate, PoolProvider, type PoolProviderType, type PoolSwap, type PoolTicks, ProviderFilter, type Tick, type TokenOraclePrice, TunaApiClient, type TunaApiClientConfig, type TunaPosition, TunaPositionState, type TunaPositionStateType, type Vault, schemas };
1776
+ export { type DurationInMs, type GetPoolPriceCandlesOptions, type LendingPosition, type LimitOrder, type LimitOrderStateType, type Market, type Mint, NotificationAction, NotificationEntity, type OrderBook, type OrderBookEntry, type Pool, type PoolPriceCandle, type PoolPriceUpdate, PoolProvider, type PoolProviderType, type PoolSubscriptionTopicType, type PoolSwap, type PoolTicks, ProviderFilter, type SubscriptionPayload, type Tick, type TokenOraclePrice, TunaApiClient, type TunaApiClientConfig, type TunaPosition, TunaPositionState, type TunaPositionStateType, type Vault, type WalletSubscriptionTopicType, schemas };
package/dist/index.js CHANGED
@@ -41,6 +41,7 @@ module.exports = __toCommonJS(index_exports);
41
41
 
42
42
  // src/client/client.ts
43
43
  var import_camelcase_keys = __toESM(require("camelcase-keys"));
44
+ var import_snakecase_keys = __toESM(require("snakecase-keys"));
44
45
 
45
46
  // src/client/schemas.ts
46
47
  var schemas_exports = {};
@@ -65,6 +66,8 @@ __export(schemas_exports, {
65
66
  PoolPriceUpdateNotification: () => PoolPriceUpdateNotification,
66
67
  PoolProvider: () => PoolProvider,
67
68
  PoolProviderSchema: () => PoolProviderSchema,
69
+ PoolSubscriptionTopic: () => PoolSubscriptionTopic,
70
+ PoolSubscriptionTopicSchema: () => PoolSubscriptionTopicSchema,
68
71
  PoolSwap: () => PoolSwap,
69
72
  PoolSwapNotification: () => PoolSwapNotification,
70
73
  PoolTicks: () => PoolTicks,
@@ -73,7 +76,10 @@ __export(schemas_exports, {
73
76
  TunaPosition: () => TunaPosition,
74
77
  TunaPositionState: () => TunaPositionState,
75
78
  TunaPositionStateSchema: () => TunaPositionStateSchema,
76
- Vault: () => Vault
79
+ UpdateStreamSubscriptionResult: () => UpdateStreamSubscriptionResult,
80
+ Vault: () => Vault,
81
+ WalletSubscriptionTopic: () => WalletSubscriptionTopic,
82
+ WalletSubscriptionTopicSchema: () => WalletSubscriptionTopicSchema
77
83
  });
78
84
  var import_zod = require("zod");
79
85
  var amountWithoutUsd = import_zod.z.object({
@@ -117,11 +123,29 @@ var LimitOrderState = {
117
123
  COMPLETE: "complete",
118
124
  CANCELLED: "cancelled"
119
125
  };
126
+ var PoolSubscriptionTopic = {
127
+ ORDER_BOOK: "order_book",
128
+ POOL_PRICES: "pool_prices",
129
+ POOL_SWAPS: "pool_swaps"
130
+ };
131
+ var WalletSubscriptionTopic = {
132
+ TUNA_POSITIONS: "tuna_positions",
133
+ LENDING_POSITIONS: "lending_positions",
134
+ FUSION_LIMIT_ORDERS: "fusion_limit_orders"
135
+ };
120
136
  var NotificationEntitySchema = import_zod.z.enum([NotificationEntity.POOL_SWAP, ...Object.values(NotificationEntity)]);
121
137
  var NotificationActionSchema = import_zod.z.enum([NotificationAction.CREATE, ...Object.values(NotificationAction)]);
122
138
  var PoolProviderSchema = import_zod.z.enum([PoolProvider.ORCA, ...Object.values(PoolProvider)]);
123
139
  var TunaPositionStateSchema = import_zod.z.enum([TunaPositionState.OPEN, ...Object.values(TunaPositionState)]);
124
140
  var LimitOrderStateSchema = import_zod.z.enum([LimitOrderState.OPEN, ...Object.values(LimitOrderState)]);
141
+ var PoolSubscriptionTopicSchema = import_zod.z.enum([
142
+ PoolSubscriptionTopic.ORDER_BOOK,
143
+ ...Object.values(PoolSubscriptionTopic)
144
+ ]);
145
+ var WalletSubscriptionTopicSchema = import_zod.z.enum([
146
+ WalletSubscriptionTopic.TUNA_POSITIONS,
147
+ ...Object.values(WalletSubscriptionTopic)
148
+ ]);
125
149
  var Mint = import_zod.z.object({
126
150
  symbol: import_zod.z.string(),
127
151
  mint: import_zod.z.string(),
@@ -257,7 +281,8 @@ var TunaPosition = import_zod.z.object({
257
281
  pnlB: tokensPnl,
258
282
  pnlUsd: usdPnl,
259
283
  openedAt: import_zod.z.coerce.date(),
260
- updatedAtSlot: import_zod.z.coerce.bigint()
284
+ updatedAtSlot: import_zod.z.coerce.bigint(),
285
+ closedAt: import_zod.z.nullable(import_zod.z.coerce.date())
261
286
  });
262
287
  var PoolSwap = import_zod.z.object({
263
288
  id: import_zod.z.string(),
@@ -298,11 +323,11 @@ var LimitOrder = import_zod.z.object({
298
323
  tickIndex: import_zod.z.number(),
299
324
  fillRatio: import_zod.z.number(),
300
325
  openTxSignature: import_zod.z.string(),
301
- closeTxSignature: import_zod.z.string().nullable(),
326
+ closeTxSignature: import_zod.z.nullable(import_zod.z.string()),
302
327
  amountIn: amountWithUsd,
303
328
  amountOut: amountWithUsd,
304
329
  openedAt: import_zod.z.coerce.date(),
305
- closedAt: import_zod.z.coerce.date().nullable()
330
+ closedAt: import_zod.z.nullable(import_zod.z.coerce.date())
306
331
  });
307
332
  var PoolPriceCandle = import_zod.z.object({
308
333
  time: import_zod.z.number(),
@@ -311,6 +336,9 @@ var PoolPriceCandle = import_zod.z.object({
311
336
  high: import_zod.z.number(),
312
337
  low: import_zod.z.number()
313
338
  });
339
+ var UpdateStreamSubscriptionResult = import_zod.z.object({
340
+ status: import_zod.z.string()
341
+ });
314
342
  var createNotificationSchema = (dataSchema, metaSchema) => import_zod.z.object({
315
343
  entity: NotificationEntitySchema,
316
344
  action: NotificationActionSchema,
@@ -374,7 +402,7 @@ var TunaApiClient = class {
374
402
  const response = await fetch(url, {
375
403
  ...options,
376
404
  signal,
377
- headers: { ...this.headers, ...options?.headers }
405
+ headers: { "Content-Type": "application/json", ...this.headers, ...options?.headers }
378
406
  });
379
407
  clearTimeout(abort);
380
408
  if (!response.ok) {
@@ -490,6 +518,9 @@ var TunaApiClient = class {
490
518
  const url = this.buildURL(`users/${userAddress}/limit-orders/${limitOrderAddress}`);
491
519
  return await this.httpRequest(url.toString(), LimitOrder);
492
520
  }
521
+ /**
522
+ * @deprecated Use getUpdatesStream instead
523
+ */
493
524
  async getPoolUpdatesStream(poolAddress, priceStep, inverted) {
494
525
  const url = this.buildURL(`stream`);
495
526
  this.appendUrlSearchParams(url, { pool: poolAddress });
@@ -501,6 +532,15 @@ var TunaApiClient = class {
501
532
  }
502
533
  return new EventSource(url.toString());
503
534
  }
535
+ async getUpdatesStream() {
536
+ const url = this.buildURL(`streams/sse`);
537
+ return new EventSource(url.toString());
538
+ }
539
+ async updateStreamSubscription(streamId, subscription) {
540
+ const url = this.buildURL(`streams/${streamId}/subscription`);
541
+ const body = JSON.stringify((0, import_snakecase_keys.default)(subscription, { deep: true }));
542
+ return await this.httpRequest(url.toString(), UpdateStreamSubscriptionResult, { method: "PUT", body });
543
+ }
504
544
  /* Utility functions */
505
545
  buildURL(endpoint) {
506
546
  return new URL(
package/dist/index.mjs CHANGED
@@ -6,6 +6,7 @@ var __export = (target, all) => {
6
6
 
7
7
  // src/client/client.ts
8
8
  import camelcaseKeys from "camelcase-keys";
9
+ import snakecaseKeys from "snakecase-keys";
9
10
 
10
11
  // src/client/schemas.ts
11
12
  var schemas_exports = {};
@@ -30,6 +31,8 @@ __export(schemas_exports, {
30
31
  PoolPriceUpdateNotification: () => PoolPriceUpdateNotification,
31
32
  PoolProvider: () => PoolProvider,
32
33
  PoolProviderSchema: () => PoolProviderSchema,
34
+ PoolSubscriptionTopic: () => PoolSubscriptionTopic,
35
+ PoolSubscriptionTopicSchema: () => PoolSubscriptionTopicSchema,
33
36
  PoolSwap: () => PoolSwap,
34
37
  PoolSwapNotification: () => PoolSwapNotification,
35
38
  PoolTicks: () => PoolTicks,
@@ -38,7 +41,10 @@ __export(schemas_exports, {
38
41
  TunaPosition: () => TunaPosition,
39
42
  TunaPositionState: () => TunaPositionState,
40
43
  TunaPositionStateSchema: () => TunaPositionStateSchema,
41
- Vault: () => Vault
44
+ UpdateStreamSubscriptionResult: () => UpdateStreamSubscriptionResult,
45
+ Vault: () => Vault,
46
+ WalletSubscriptionTopic: () => WalletSubscriptionTopic,
47
+ WalletSubscriptionTopicSchema: () => WalletSubscriptionTopicSchema
42
48
  });
43
49
  import { z } from "zod";
44
50
  var amountWithoutUsd = z.object({
@@ -82,11 +88,29 @@ var LimitOrderState = {
82
88
  COMPLETE: "complete",
83
89
  CANCELLED: "cancelled"
84
90
  };
91
+ var PoolSubscriptionTopic = {
92
+ ORDER_BOOK: "order_book",
93
+ POOL_PRICES: "pool_prices",
94
+ POOL_SWAPS: "pool_swaps"
95
+ };
96
+ var WalletSubscriptionTopic = {
97
+ TUNA_POSITIONS: "tuna_positions",
98
+ LENDING_POSITIONS: "lending_positions",
99
+ FUSION_LIMIT_ORDERS: "fusion_limit_orders"
100
+ };
85
101
  var NotificationEntitySchema = z.enum([NotificationEntity.POOL_SWAP, ...Object.values(NotificationEntity)]);
86
102
  var NotificationActionSchema = z.enum([NotificationAction.CREATE, ...Object.values(NotificationAction)]);
87
103
  var PoolProviderSchema = z.enum([PoolProvider.ORCA, ...Object.values(PoolProvider)]);
88
104
  var TunaPositionStateSchema = z.enum([TunaPositionState.OPEN, ...Object.values(TunaPositionState)]);
89
105
  var LimitOrderStateSchema = z.enum([LimitOrderState.OPEN, ...Object.values(LimitOrderState)]);
106
+ var PoolSubscriptionTopicSchema = z.enum([
107
+ PoolSubscriptionTopic.ORDER_BOOK,
108
+ ...Object.values(PoolSubscriptionTopic)
109
+ ]);
110
+ var WalletSubscriptionTopicSchema = z.enum([
111
+ WalletSubscriptionTopic.TUNA_POSITIONS,
112
+ ...Object.values(WalletSubscriptionTopic)
113
+ ]);
90
114
  var Mint = z.object({
91
115
  symbol: z.string(),
92
116
  mint: z.string(),
@@ -222,7 +246,8 @@ var TunaPosition = z.object({
222
246
  pnlB: tokensPnl,
223
247
  pnlUsd: usdPnl,
224
248
  openedAt: z.coerce.date(),
225
- updatedAtSlot: z.coerce.bigint()
249
+ updatedAtSlot: z.coerce.bigint(),
250
+ closedAt: z.nullable(z.coerce.date())
226
251
  });
227
252
  var PoolSwap = z.object({
228
253
  id: z.string(),
@@ -263,11 +288,11 @@ var LimitOrder = z.object({
263
288
  tickIndex: z.number(),
264
289
  fillRatio: z.number(),
265
290
  openTxSignature: z.string(),
266
- closeTxSignature: z.string().nullable(),
291
+ closeTxSignature: z.nullable(z.string()),
267
292
  amountIn: amountWithUsd,
268
293
  amountOut: amountWithUsd,
269
294
  openedAt: z.coerce.date(),
270
- closedAt: z.coerce.date().nullable()
295
+ closedAt: z.nullable(z.coerce.date())
271
296
  });
272
297
  var PoolPriceCandle = z.object({
273
298
  time: z.number(),
@@ -276,6 +301,9 @@ var PoolPriceCandle = z.object({
276
301
  high: z.number(),
277
302
  low: z.number()
278
303
  });
304
+ var UpdateStreamSubscriptionResult = z.object({
305
+ status: z.string()
306
+ });
279
307
  var createNotificationSchema = (dataSchema, metaSchema) => z.object({
280
308
  entity: NotificationEntitySchema,
281
309
  action: NotificationActionSchema,
@@ -339,7 +367,7 @@ var TunaApiClient = class {
339
367
  const response = await fetch(url, {
340
368
  ...options,
341
369
  signal,
342
- headers: { ...this.headers, ...options?.headers }
370
+ headers: { "Content-Type": "application/json", ...this.headers, ...options?.headers }
343
371
  });
344
372
  clearTimeout(abort);
345
373
  if (!response.ok) {
@@ -455,6 +483,9 @@ var TunaApiClient = class {
455
483
  const url = this.buildURL(`users/${userAddress}/limit-orders/${limitOrderAddress}`);
456
484
  return await this.httpRequest(url.toString(), LimitOrder);
457
485
  }
486
+ /**
487
+ * @deprecated Use getUpdatesStream instead
488
+ */
458
489
  async getPoolUpdatesStream(poolAddress, priceStep, inverted) {
459
490
  const url = this.buildURL(`stream`);
460
491
  this.appendUrlSearchParams(url, { pool: poolAddress });
@@ -466,6 +497,15 @@ var TunaApiClient = class {
466
497
  }
467
498
  return new EventSource(url.toString());
468
499
  }
500
+ async getUpdatesStream() {
501
+ const url = this.buildURL(`streams/sse`);
502
+ return new EventSource(url.toString());
503
+ }
504
+ async updateStreamSubscription(streamId, subscription) {
505
+ const url = this.buildURL(`streams/${streamId}/subscription`);
506
+ const body = JSON.stringify(snakecaseKeys(subscription, { deep: true }));
507
+ return await this.httpRequest(url.toString(), UpdateStreamSubscriptionResult, { method: "PUT", body });
508
+ }
469
509
  /* Utility functions */
470
510
  buildURL(endpoint) {
471
511
  return new URL(
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@crypticdot/defituna-api",
3
- "version": "1.1.29",
3
+ "version": "1.1.30",
4
4
  "private": false,
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.mjs",
@@ -32,6 +32,7 @@
32
32
  },
33
33
  "dependencies": {
34
34
  "camelcase-keys": "^9.1.3",
35
+ "snakecase-keys": "^8.0.1",
35
36
  "zod": "^3.24.1"
36
37
  },
37
38
  "scripts": {