@crypticdot/defituna-api 1.1.28 → 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;
@@ -1068,7 +1083,17 @@ declare const LimitOrder$1: z.ZodObject<{
1068
1083
  fillRatio: z.ZodNumber;
1069
1084
  openTxSignature: z.ZodString;
1070
1085
  closeTxSignature: z.ZodNullable<z.ZodString>;
1071
- amount: z.ZodObject<{
1086
+ amountIn: z.ZodObject<{
1087
+ amount: z.ZodBigInt;
1088
+ usd: z.ZodNumber;
1089
+ }, "strip", z.ZodTypeAny, {
1090
+ amount: bigint;
1091
+ usd: number;
1092
+ }, {
1093
+ amount: bigint;
1094
+ usd: number;
1095
+ }>;
1096
+ amountOut: z.ZodObject<{
1072
1097
  amount: z.ZodBigInt;
1073
1098
  usd: z.ZodNumber;
1074
1099
  }, "strip", z.ZodTypeAny, {
@@ -1081,37 +1106,45 @@ declare const LimitOrder$1: z.ZodObject<{
1081
1106
  openedAt: z.ZodDate;
1082
1107
  closedAt: z.ZodNullable<z.ZodDate>;
1083
1108
  }, "strip", z.ZodTypeAny, {
1084
- amount: {
1085
- amount: bigint;
1086
- usd: number;
1087
- };
1088
1109
  mint: string;
1089
1110
  address: string;
1090
1111
  state: "open" | "partially_filled" | "filled" | "complete" | "cancelled";
1091
1112
  pool: string;
1092
1113
  openedAt: Date;
1114
+ closedAt: Date | null;
1115
+ amountIn: {
1116
+ amount: bigint;
1117
+ usd: number;
1118
+ };
1119
+ amountOut: {
1120
+ amount: bigint;
1121
+ usd: number;
1122
+ };
1093
1123
  aToB: boolean;
1094
1124
  tickIndex: number;
1095
1125
  fillRatio: number;
1096
1126
  openTxSignature: string;
1097
1127
  closeTxSignature: string | null;
1098
- closedAt: Date | null;
1099
1128
  }, {
1100
- amount: {
1101
- amount: bigint;
1102
- usd: number;
1103
- };
1104
1129
  mint: string;
1105
1130
  address: string;
1106
1131
  state: "open" | "partially_filled" | "filled" | "complete" | "cancelled";
1107
1132
  pool: string;
1108
1133
  openedAt: Date;
1134
+ closedAt: Date | null;
1135
+ amountIn: {
1136
+ amount: bigint;
1137
+ usd: number;
1138
+ };
1139
+ amountOut: {
1140
+ amount: bigint;
1141
+ usd: number;
1142
+ };
1109
1143
  aToB: boolean;
1110
1144
  tickIndex: number;
1111
1145
  fillRatio: number;
1112
1146
  openTxSignature: string;
1113
1147
  closeTxSignature: string | null;
1114
- closedAt: Date | null;
1115
1148
  }>;
1116
1149
  declare const PoolPriceCandle$1: z.ZodObject<{
1117
1150
  time: z.ZodNumber;
@@ -1132,6 +1165,13 @@ declare const PoolPriceCandle$1: z.ZodObject<{
1132
1165
  high: number;
1133
1166
  low: number;
1134
1167
  }>;
1168
+ declare const UpdateStreamSubscriptionResult: z.ZodObject<{
1169
+ status: z.ZodString;
1170
+ }, "strip", z.ZodTypeAny, {
1171
+ status: string;
1172
+ }, {
1173
+ status: string;
1174
+ }>;
1135
1175
  declare const OrderBookNotificationMeta: z.ZodObject<{
1136
1176
  pool: z.ZodString;
1137
1177
  priceStep: z.ZodNumber;
@@ -1618,16 +1658,23 @@ declare const schemas_OrderBookNotificationMeta: typeof OrderBookNotificationMet
1618
1658
  declare const schemas_PoolPriceUpdateNotification: typeof PoolPriceUpdateNotification;
1619
1659
  declare const schemas_PoolProvider: typeof PoolProvider;
1620
1660
  declare const schemas_PoolProviderSchema: typeof PoolProviderSchema;
1661
+ declare const schemas_PoolSubscriptionTopic: typeof PoolSubscriptionTopic;
1662
+ declare const schemas_PoolSubscriptionTopicSchema: typeof PoolSubscriptionTopicSchema;
1621
1663
  declare const schemas_PoolSwapNotification: typeof PoolSwapNotification;
1622
1664
  declare const schemas_TunaPositionState: typeof TunaPositionState;
1623
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;
1624
1669
  declare namespace schemas {
1625
- 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 };
1626
1671
  }
1627
1672
 
1628
1673
  type PoolProviderType = z.infer<typeof PoolProviderSchema>;
1629
1674
  type TunaPositionStateType = z.infer<typeof TunaPositionStateSchema>;
1630
1675
  type LimitOrderStateType = z.infer<typeof LimitOrderStateSchema>;
1676
+ type PoolSubscriptionTopicType = z.infer<typeof PoolSubscriptionTopicSchema>;
1677
+ type WalletSubscriptionTopicType = z.infer<typeof WalletSubscriptionTopicSchema>;
1631
1678
  type Mint = z.infer<typeof Mint$1>;
1632
1679
  type Market = z.infer<typeof Market$1>;
1633
1680
  type TokenOraclePrice = z.infer<typeof TokenOraclePrice$1>;
@@ -1643,6 +1690,18 @@ type TunaPosition = z.infer<typeof TunaPosition$1>;
1643
1690
  type LimitOrder = z.infer<typeof LimitOrder$1>;
1644
1691
  type PoolPriceCandle = z.infer<typeof PoolPriceCandle$1>;
1645
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
+ };
1646
1705
  type DurationInMs = number;
1647
1706
  declare enum ProviderFilter {
1648
1707
  ORCA = "orca",
@@ -1704,9 +1763,14 @@ declare class TunaApiClient {
1704
1763
  getUserTunaPositionByAddress(userAddress: string, tunaPositionAddress: string): Promise<TunaPosition>;
1705
1764
  getUserLimitOrders(userAddress: string, poolFilter?: string): Promise<LimitOrder[]>;
1706
1765
  getUserLimitOrderByAddress(userAddress: string, limitOrderAddress: string): Promise<LimitOrder>;
1766
+ /**
1767
+ * @deprecated Use getUpdatesStream instead
1768
+ */
1707
1769
  getPoolUpdatesStream(poolAddress: string, priceStep?: number, inverted?: boolean): Promise<EventSource>;
1770
+ getUpdatesStream(): Promise<EventSource>;
1771
+ updateStreamSubscription(streamId: string, subscription: SubscriptionPayload): Promise<unknown>;
1708
1772
  private buildURL;
1709
1773
  private appendUrlSearchParams;
1710
1774
  }
1711
1775
 
1712
- 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;
@@ -1068,7 +1083,17 @@ declare const LimitOrder$1: z.ZodObject<{
1068
1083
  fillRatio: z.ZodNumber;
1069
1084
  openTxSignature: z.ZodString;
1070
1085
  closeTxSignature: z.ZodNullable<z.ZodString>;
1071
- amount: z.ZodObject<{
1086
+ amountIn: z.ZodObject<{
1087
+ amount: z.ZodBigInt;
1088
+ usd: z.ZodNumber;
1089
+ }, "strip", z.ZodTypeAny, {
1090
+ amount: bigint;
1091
+ usd: number;
1092
+ }, {
1093
+ amount: bigint;
1094
+ usd: number;
1095
+ }>;
1096
+ amountOut: z.ZodObject<{
1072
1097
  amount: z.ZodBigInt;
1073
1098
  usd: z.ZodNumber;
1074
1099
  }, "strip", z.ZodTypeAny, {
@@ -1081,37 +1106,45 @@ declare const LimitOrder$1: z.ZodObject<{
1081
1106
  openedAt: z.ZodDate;
1082
1107
  closedAt: z.ZodNullable<z.ZodDate>;
1083
1108
  }, "strip", z.ZodTypeAny, {
1084
- amount: {
1085
- amount: bigint;
1086
- usd: number;
1087
- };
1088
1109
  mint: string;
1089
1110
  address: string;
1090
1111
  state: "open" | "partially_filled" | "filled" | "complete" | "cancelled";
1091
1112
  pool: string;
1092
1113
  openedAt: Date;
1114
+ closedAt: Date | null;
1115
+ amountIn: {
1116
+ amount: bigint;
1117
+ usd: number;
1118
+ };
1119
+ amountOut: {
1120
+ amount: bigint;
1121
+ usd: number;
1122
+ };
1093
1123
  aToB: boolean;
1094
1124
  tickIndex: number;
1095
1125
  fillRatio: number;
1096
1126
  openTxSignature: string;
1097
1127
  closeTxSignature: string | null;
1098
- closedAt: Date | null;
1099
1128
  }, {
1100
- amount: {
1101
- amount: bigint;
1102
- usd: number;
1103
- };
1104
1129
  mint: string;
1105
1130
  address: string;
1106
1131
  state: "open" | "partially_filled" | "filled" | "complete" | "cancelled";
1107
1132
  pool: string;
1108
1133
  openedAt: Date;
1134
+ closedAt: Date | null;
1135
+ amountIn: {
1136
+ amount: bigint;
1137
+ usd: number;
1138
+ };
1139
+ amountOut: {
1140
+ amount: bigint;
1141
+ usd: number;
1142
+ };
1109
1143
  aToB: boolean;
1110
1144
  tickIndex: number;
1111
1145
  fillRatio: number;
1112
1146
  openTxSignature: string;
1113
1147
  closeTxSignature: string | null;
1114
- closedAt: Date | null;
1115
1148
  }>;
1116
1149
  declare const PoolPriceCandle$1: z.ZodObject<{
1117
1150
  time: z.ZodNumber;
@@ -1132,6 +1165,13 @@ declare const PoolPriceCandle$1: z.ZodObject<{
1132
1165
  high: number;
1133
1166
  low: number;
1134
1167
  }>;
1168
+ declare const UpdateStreamSubscriptionResult: z.ZodObject<{
1169
+ status: z.ZodString;
1170
+ }, "strip", z.ZodTypeAny, {
1171
+ status: string;
1172
+ }, {
1173
+ status: string;
1174
+ }>;
1135
1175
  declare const OrderBookNotificationMeta: z.ZodObject<{
1136
1176
  pool: z.ZodString;
1137
1177
  priceStep: z.ZodNumber;
@@ -1618,16 +1658,23 @@ declare const schemas_OrderBookNotificationMeta: typeof OrderBookNotificationMet
1618
1658
  declare const schemas_PoolPriceUpdateNotification: typeof PoolPriceUpdateNotification;
1619
1659
  declare const schemas_PoolProvider: typeof PoolProvider;
1620
1660
  declare const schemas_PoolProviderSchema: typeof PoolProviderSchema;
1661
+ declare const schemas_PoolSubscriptionTopic: typeof PoolSubscriptionTopic;
1662
+ declare const schemas_PoolSubscriptionTopicSchema: typeof PoolSubscriptionTopicSchema;
1621
1663
  declare const schemas_PoolSwapNotification: typeof PoolSwapNotification;
1622
1664
  declare const schemas_TunaPositionState: typeof TunaPositionState;
1623
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;
1624
1669
  declare namespace schemas {
1625
- 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 };
1626
1671
  }
1627
1672
 
1628
1673
  type PoolProviderType = z.infer<typeof PoolProviderSchema>;
1629
1674
  type TunaPositionStateType = z.infer<typeof TunaPositionStateSchema>;
1630
1675
  type LimitOrderStateType = z.infer<typeof LimitOrderStateSchema>;
1676
+ type PoolSubscriptionTopicType = z.infer<typeof PoolSubscriptionTopicSchema>;
1677
+ type WalletSubscriptionTopicType = z.infer<typeof WalletSubscriptionTopicSchema>;
1631
1678
  type Mint = z.infer<typeof Mint$1>;
1632
1679
  type Market = z.infer<typeof Market$1>;
1633
1680
  type TokenOraclePrice = z.infer<typeof TokenOraclePrice$1>;
@@ -1643,6 +1690,18 @@ type TunaPosition = z.infer<typeof TunaPosition$1>;
1643
1690
  type LimitOrder = z.infer<typeof LimitOrder$1>;
1644
1691
  type PoolPriceCandle = z.infer<typeof PoolPriceCandle$1>;
1645
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
+ };
1646
1705
  type DurationInMs = number;
1647
1706
  declare enum ProviderFilter {
1648
1707
  ORCA = "orca",
@@ -1704,9 +1763,14 @@ declare class TunaApiClient {
1704
1763
  getUserTunaPositionByAddress(userAddress: string, tunaPositionAddress: string): Promise<TunaPosition>;
1705
1764
  getUserLimitOrders(userAddress: string, poolFilter?: string): Promise<LimitOrder[]>;
1706
1765
  getUserLimitOrderByAddress(userAddress: string, limitOrderAddress: string): Promise<LimitOrder>;
1766
+ /**
1767
+ * @deprecated Use getUpdatesStream instead
1768
+ */
1707
1769
  getPoolUpdatesStream(poolAddress: string, priceStep?: number, inverted?: boolean): Promise<EventSource>;
1770
+ getUpdatesStream(): Promise<EventSource>;
1771
+ updateStreamSubscription(streamId: string, subscription: SubscriptionPayload): Promise<unknown>;
1708
1772
  private buildURL;
1709
1773
  private appendUrlSearchParams;
1710
1774
  }
1711
1775
 
1712
- 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,10 +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(),
302
- amount: amountWithUsd,
326
+ closeTxSignature: import_zod.z.nullable(import_zod.z.string()),
327
+ amountIn: amountWithUsd,
328
+ amountOut: amountWithUsd,
303
329
  openedAt: import_zod.z.coerce.date(),
304
- closedAt: import_zod.z.coerce.date().nullable()
330
+ closedAt: import_zod.z.nullable(import_zod.z.coerce.date())
305
331
  });
306
332
  var PoolPriceCandle = import_zod.z.object({
307
333
  time: import_zod.z.number(),
@@ -310,6 +336,9 @@ var PoolPriceCandle = import_zod.z.object({
310
336
  high: import_zod.z.number(),
311
337
  low: import_zod.z.number()
312
338
  });
339
+ var UpdateStreamSubscriptionResult = import_zod.z.object({
340
+ status: import_zod.z.string()
341
+ });
313
342
  var createNotificationSchema = (dataSchema, metaSchema) => import_zod.z.object({
314
343
  entity: NotificationEntitySchema,
315
344
  action: NotificationActionSchema,
@@ -373,7 +402,7 @@ var TunaApiClient = class {
373
402
  const response = await fetch(url, {
374
403
  ...options,
375
404
  signal,
376
- headers: { ...this.headers, ...options?.headers }
405
+ headers: { "Content-Type": "application/json", ...this.headers, ...options?.headers }
377
406
  });
378
407
  clearTimeout(abort);
379
408
  if (!response.ok) {
@@ -489,6 +518,9 @@ var TunaApiClient = class {
489
518
  const url = this.buildURL(`users/${userAddress}/limit-orders/${limitOrderAddress}`);
490
519
  return await this.httpRequest(url.toString(), LimitOrder);
491
520
  }
521
+ /**
522
+ * @deprecated Use getUpdatesStream instead
523
+ */
492
524
  async getPoolUpdatesStream(poolAddress, priceStep, inverted) {
493
525
  const url = this.buildURL(`stream`);
494
526
  this.appendUrlSearchParams(url, { pool: poolAddress });
@@ -500,6 +532,15 @@ var TunaApiClient = class {
500
532
  }
501
533
  return new EventSource(url.toString());
502
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
+ }
503
544
  /* Utility functions */
504
545
  buildURL(endpoint) {
505
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,10 +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(),
267
- amount: amountWithUsd,
291
+ closeTxSignature: z.nullable(z.string()),
292
+ amountIn: amountWithUsd,
293
+ amountOut: amountWithUsd,
268
294
  openedAt: z.coerce.date(),
269
- closedAt: z.coerce.date().nullable()
295
+ closedAt: z.nullable(z.coerce.date())
270
296
  });
271
297
  var PoolPriceCandle = z.object({
272
298
  time: z.number(),
@@ -275,6 +301,9 @@ var PoolPriceCandle = z.object({
275
301
  high: z.number(),
276
302
  low: z.number()
277
303
  });
304
+ var UpdateStreamSubscriptionResult = z.object({
305
+ status: z.string()
306
+ });
278
307
  var createNotificationSchema = (dataSchema, metaSchema) => z.object({
279
308
  entity: NotificationEntitySchema,
280
309
  action: NotificationActionSchema,
@@ -338,7 +367,7 @@ var TunaApiClient = class {
338
367
  const response = await fetch(url, {
339
368
  ...options,
340
369
  signal,
341
- headers: { ...this.headers, ...options?.headers }
370
+ headers: { "Content-Type": "application/json", ...this.headers, ...options?.headers }
342
371
  });
343
372
  clearTimeout(abort);
344
373
  if (!response.ok) {
@@ -454,6 +483,9 @@ var TunaApiClient = class {
454
483
  const url = this.buildURL(`users/${userAddress}/limit-orders/${limitOrderAddress}`);
455
484
  return await this.httpRequest(url.toString(), LimitOrder);
456
485
  }
486
+ /**
487
+ * @deprecated Use getUpdatesStream instead
488
+ */
457
489
  async getPoolUpdatesStream(poolAddress, priceStep, inverted) {
458
490
  const url = this.buildURL(`stream`);
459
491
  this.appendUrlSearchParams(url, { pool: poolAddress });
@@ -465,6 +497,15 @@ var TunaApiClient = class {
465
497
  }
466
498
  return new EventSource(url.toString());
467
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
+ }
468
509
  /* Utility functions */
469
510
  buildURL(endpoint) {
470
511
  return new URL(
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@crypticdot/defituna-api",
3
- "version": "1.1.28",
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": {