@covalenthq/client-sdk 2.2.6 → 2.3.1

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.
@@ -5,8 +5,10 @@ import { BitcoinService } from "./services/BitcoinService";
5
5
  import { NftService } from "./services/NftService";
6
6
  import { PricingService } from "./services/PricingService";
7
7
  import { SecurityService } from "./services/SecurityService";
8
+ import { StreamingService } from "./services/StreamingService";
8
9
  import { TransactionService } from "./services/TransactionService";
9
10
  import { type GoldRushClientSettings } from "./utils/types/Generic.types";
11
+ import { type StreamingServiceConfig } from "./utils/types/StreamingService.types";
10
12
  /**
11
13
  * GoldRushClient Class
12
14
  */
@@ -19,6 +21,7 @@ export declare class GoldRushClient {
19
21
  NftService: NftService;
20
22
  PricingService: PricingService;
21
23
  SecurityService: SecurityService;
24
+ StreamingService: StreamingService;
22
25
  TransactionService: TransactionService;
23
- constructor(apiKey: string, settings?: GoldRushClientSettings);
26
+ constructor(apiKey: string, settings?: GoldRushClientSettings, streamingConfig?: StreamingServiceConfig);
24
27
  }
@@ -0,0 +1,151 @@
1
+ import { type NewPairsStreamParams, type NewPairsStreamResponse, type OHLCVPairsStreamParams, type OHLCVPairsStreamResponse, type OHLCVTokensStreamParams, type OHLCVTokensStreamResponse, type StreamingServiceConfig, type StreamSubscriptionOptions, type TokenBalancesStreamParams, type TokenBalancesStreamResponse, type UnsubscribeFunction, type WalletActivityStreamParams, type WalletActivityStreamResponse } from "../utils/types/StreamingService.types";
2
+ import { type Client } from "graphql-ws";
3
+ /**
4
+ * Streaming API Service
5
+ *
6
+ */
7
+ export declare class StreamingService {
8
+ private defaultConfig;
9
+ constructor(apiKey: string, config?: StreamingServiceConfig);
10
+ /**
11
+ * Initialize the streaming connection
12
+ */
13
+ getClient(): Client;
14
+ /**
15
+ * Disconnect from the streaming service
16
+ */
17
+ disconnect(): Promise<void>;
18
+ /**
19
+ * Check if the client is connected
20
+ */
21
+ get isConnected(): boolean;
22
+ /**
23
+ * Subscribe to a custom GraphQL subscription
24
+ * This allows for advanced usage and future extensibility
25
+ *
26
+ * @param query - GraphQL subscription query
27
+ * @param variables - Query variables
28
+ * @param callbacks - Subscription callbacks
29
+ * @returns Unsubscribe function
30
+ */
31
+ rawQuery<T = Array<object>>(query: string, variables: Record<string, unknown>, callbacks: StreamSubscriptionOptions<T>): UnsubscribeFunction;
32
+ /**
33
+ * Subscribe to OHLCV data for specific pairs
34
+ *
35
+ * @param params - Parameters for the OHLCV pairs stream
36
+ * @param callbacks - Subscription callbacks
37
+ * @returns Unsubscribe function
38
+ *
39
+ * @example
40
+ * ```typescript
41
+ * const unsubscribe = streamingService.subscribeToOHLCVPairs(
42
+ * {
43
+ * chain_name: StreamingChain.BASE_MAINNET,
44
+ * pair_addresses: ["0x9c087Eb773291e50CF6c6a90ef0F4500e349B903"],
45
+ * interval: StreamingInterval.ONE_MINUTE,
46
+ * timeframe: StreamingTimeframe.ONE_HOUR
47
+ * },
48
+ * {
49
+ * next: (data) => console.log("OHLCV Data:", data),
50
+ * error: (err) => console.error("Error:", err),
51
+ * complete: () => console.log("Stream completed")
52
+ * }
53
+ * );
54
+ * ```
55
+ */
56
+ subscribeToOHLCVPairs(params: OHLCVPairsStreamParams, callbacks: StreamSubscriptionOptions<OHLCVPairsStreamResponse[]>): UnsubscribeFunction;
57
+ /**
58
+ * Subscribe to OHLCV data for specific tokens
59
+ *
60
+ * @param params - Parameters for the OHLCV tokens stream
61
+ * @param callbacks - Subscription callbacks
62
+ * @returns Unsubscribe function
63
+ *
64
+ * @example
65
+ * ```typescript
66
+ * const unsubscribe = streamingService.subscribeToOHLCVTokens(
67
+ * {
68
+ * chain_name: StreamingChain.BASE_MAINNET,
69
+ * token_addresses: ["0x4B6104755AfB5Da4581B81C552DA3A25608c73B8"],
70
+ * interval: StreamingInterval.ONE_MINUTE,
71
+ * timeframe: StreamingTimeframe.ONE_HOUR
72
+ * },
73
+ * {
74
+ * next: (data) => console.log("OHLCV Token Data:", data),
75
+ * error: (err) => console.error("Error:", err),
76
+ * complete: () => console.log("Stream completed")
77
+ * }
78
+ * );
79
+ * ```
80
+ */
81
+ subscribeToOHLCVTokens(params: OHLCVTokensStreamParams, callbacks: StreamSubscriptionOptions<OHLCVTokensStreamResponse[]>): UnsubscribeFunction;
82
+ /**
83
+ * Subscribe to new DEX pairs created on supported decentralized exchanges
84
+ *
85
+ * @param params - Parameters for the new pairs stream
86
+ * @param callbacks - Subscription callbacks
87
+ * @returns Unsubscribe function
88
+ *
89
+ * @example
90
+ * ```typescript
91
+ * const unsubscribe = streamingService.subscribeToNewPairs(
92
+ * {
93
+ * chain_name: StreamingChain.BASE_MAINNET,
94
+ * protocols: [StreamingProtocol.UNISWAP_V2, StreamingProtocol.UNISWAP_V3]
95
+ * },
96
+ * {
97
+ * next: (data) => console.log("New Pairs:", data),
98
+ * error: (err) => console.error("Error:", err),
99
+ * complete: () => console.log("Stream completed")
100
+ * }
101
+ * );
102
+ * ```
103
+ */
104
+ subscribeToNewPairs(params: NewPairsStreamParams, callbacks: StreamSubscriptionOptions<NewPairsStreamResponse[]>): UnsubscribeFunction;
105
+ /**
106
+ * Subscribe to real-time token balance updates for a specific wallet address
107
+ *
108
+ * @param params - Parameters for the token balances stream
109
+ * @param callbacks - Subscription callbacks
110
+ * @returns Unsubscribe function
111
+ *
112
+ * @example
113
+ * ```typescript
114
+ * const unsubscribe = streamingService.subscribeToTokenBalances(
115
+ * {
116
+ * chain_name: StreamingChain.BASE_MAINNET,
117
+ * wallet_address: "0x198ef79f1f515f02dfe9e3115ed9fc07183f02fc"
118
+ * },
119
+ * {
120
+ * next: (data) => console.log("Token Balances:", data),
121
+ * error: (err) => console.error("Error:", err),
122
+ * complete: () => console.log("Stream completed")
123
+ * }
124
+ * );
125
+ * ```
126
+ */
127
+ subscribeToTokenBalances(params: TokenBalancesStreamParams, callbacks: StreamSubscriptionOptions<TokenBalancesStreamResponse>): UnsubscribeFunction;
128
+ /**
129
+ * Subscribe to real-time wallet activity including transactions, token transfers, and smart contract interactions
130
+ *
131
+ * @param params - Parameters for the wallet activity stream
132
+ * @param callbacks - Subscription callbacks
133
+ * @returns Unsubscribe function
134
+ *
135
+ * @example
136
+ * ```typescript
137
+ * const unsubscribe = streamingService.subscribeToWalletActivity(
138
+ * {
139
+ * chain_name: StreamingChain.BASE_MAINNET,
140
+ * wallet_addresses: ["0x198ef79f1f515f02dfe9e3115ed9fc07183f02fc"]
141
+ * },
142
+ * {
143
+ * next: (data) => console.log("Wallet Activity:", data),
144
+ * error: (err) => console.error("Error:", err),
145
+ * complete: () => console.log("Stream completed")
146
+ * }
147
+ * );
148
+ * ```
149
+ */
150
+ subscribeToWalletActivity(params: WalletActivityStreamParams, callbacks: StreamSubscriptionOptions<WalletActivityStreamResponse[]>): UnsubscribeFunction;
151
+ }
@@ -0,0 +1,201 @@
1
+ import type { ContractMetadata } from "./Generic.types";
2
+ /**
3
+ * Common enums and types for Streaming API
4
+ */
5
+ export declare enum StreamingChain {
6
+ BASE_MAINNET = "BASE_MAINNET",
7
+ ETH_MAINNET = "ETH_MAINNET",
8
+ BSC_MAINNET = "BSC_MAINNET"
9
+ }
10
+ export declare enum StreamingInterval {
11
+ FIFTEEN_SECONDS = "FIFTEEN_SECONDS",
12
+ THIRTY_SECONDS = "THIRTY_SECONDS",
13
+ ONE_MINUTE = "ONE_MINUTE",
14
+ FIVE_MINUTES = "FIVE_MINUTES",
15
+ FIFTEEN_MINUTES = "FIFTEEN_MINUTES",
16
+ THIRTY_MINUTES = "THIRTY_MINUTES",
17
+ ONE_HOUR = "ONE_HOUR",
18
+ FOUR_HOURS = "FOUR_HOURS",
19
+ ONE_DAY = "ONE_DAY"
20
+ }
21
+ export declare enum StreamingTimeframe {
22
+ ONE_MINUTE = "ONE_MINUTE",
23
+ FIVE_MINUTES = "FIVE_MINUTES",
24
+ FIFTEEN_MINUTES = "FIFTEEN_MINUTES",
25
+ THIRTY_MINUTES = "THIRTY_MINUTES",
26
+ ONE_HOUR = "ONE_HOUR",
27
+ FOUR_HOURS = "FOUR_HOURS",
28
+ ONE_DAY = "ONE_DAY",
29
+ ONE_WEEK = "ONE_WEEK",
30
+ ONE_MONTH = "ONE_MONTH"
31
+ }
32
+ export declare enum StreamingProtocol {
33
+ UNISWAP_V2 = "UNISWAP_V2",
34
+ UNISWAP_V3 = "UNISWAP_V3"
35
+ }
36
+ /**
37
+ * OHLCV Pairs Stream Types
38
+ */
39
+ export interface OHLCVPairsStreamParams {
40
+ chain_name: StreamingChain;
41
+ pair_addresses: string[];
42
+ interval: StreamingInterval;
43
+ timeframe: StreamingTimeframe;
44
+ limit?: number;
45
+ }
46
+ export interface OHLCVPairsStreamResponse {
47
+ chain_name: StreamingChain;
48
+ pair_address: string;
49
+ interval: StreamingInterval;
50
+ timeframe: StreamingTimeframe;
51
+ timestamp: string;
52
+ open: number;
53
+ high: number;
54
+ low: number;
55
+ close: number;
56
+ volume: number;
57
+ price_usd: number;
58
+ volume_usd: number;
59
+ base_token: ContractMetadata;
60
+ quote_token: ContractMetadata;
61
+ }
62
+ /**
63
+ * OHLCV Tokens Stream Types
64
+ */
65
+ export interface OHLCVTokensStreamParams {
66
+ chain_name: StreamingChain;
67
+ token_addresses: string[];
68
+ interval: StreamingInterval;
69
+ timeframe: StreamingTimeframe;
70
+ limit?: number;
71
+ }
72
+ export interface OHLCVTokensStreamResponse {
73
+ chain_name: StreamingChain;
74
+ pair_address: string;
75
+ interval: StreamingInterval;
76
+ timeframe: StreamingTimeframe;
77
+ timestamp: string;
78
+ open: number;
79
+ high: number;
80
+ low: number;
81
+ close: number;
82
+ volume: number;
83
+ volume_usd: number;
84
+ quote_rate: number;
85
+ quote_rate_usd: number;
86
+ base_token: ContractMetadata;
87
+ quote_token: ContractMetadata;
88
+ }
89
+ /**
90
+ * New DEX Pairs Stream Types
91
+ */
92
+ export interface NewPairsStreamParams {
93
+ chain_name: StreamingChain;
94
+ protocols: StreamingProtocol[];
95
+ }
96
+ export interface PriceMetrics {
97
+ last_5m: number;
98
+ last_1hr: number;
99
+ last_6hr: number;
100
+ last_24hr: number;
101
+ }
102
+ export interface SwapMetrics {
103
+ last_5m: number;
104
+ last_1hr: number;
105
+ last_6hr: number;
106
+ last_24hr: number;
107
+ }
108
+ export interface NewPairsStreamResponse {
109
+ chain_name: string;
110
+ protocol: string;
111
+ protocol_version: string;
112
+ pair_address: string;
113
+ deployer_address: string;
114
+ tx_hash: string;
115
+ block_signed_at: string;
116
+ liquidity: number;
117
+ supply: number;
118
+ market_cap: number;
119
+ event_name: string;
120
+ quote_rate: number;
121
+ quote_rate_usd: number;
122
+ base_token_metadata: ContractMetadata;
123
+ quote_token_metadata: ContractMetadata;
124
+ pair_metadata: ContractMetadata;
125
+ prices: PriceMetrics;
126
+ swaps: SwapMetrics;
127
+ }
128
+ /**
129
+ * Token Balances Stream Types
130
+ */
131
+ export interface TokenBalancesStreamParams {
132
+ chain_name: StreamingChain;
133
+ wallet_address: string;
134
+ }
135
+ export interface TokenBalanceItem {
136
+ balance: string;
137
+ balance_pretty: number;
138
+ quote_rate_usd: number;
139
+ quote_usd: number;
140
+ metadata: ContractMetadata;
141
+ is_native: boolean;
142
+ }
143
+ export interface TokenBalancesStreamResponse {
144
+ wallet_address: string;
145
+ chain_name: string;
146
+ last_block: number;
147
+ items: TokenBalanceItem[];
148
+ }
149
+ /**
150
+ * Wallet Activity Stream Types
151
+ */
152
+ export interface WalletActivityStreamParams {
153
+ chain_name: StreamingChain;
154
+ wallet_addresses: string[];
155
+ }
156
+ export interface WalletActivityLogItem {
157
+ emitter_address: string;
158
+ log_offset: number;
159
+ data: string;
160
+ topics: string[];
161
+ }
162
+ export interface WalletActivityStreamResponse {
163
+ tx_hash: string;
164
+ from_address: string;
165
+ to_address: string;
166
+ value: number;
167
+ chain_name: string;
168
+ block_signed_at: string;
169
+ block_height: number;
170
+ block_hash: string;
171
+ miner_address: string;
172
+ gas_used: number;
173
+ tx_offset: number;
174
+ successful: boolean;
175
+ decoded_type: string;
176
+ decoded_details?: object;
177
+ logs: WalletActivityLogItem[];
178
+ }
179
+ /**
180
+ * Streaming service configuration
181
+ */
182
+ export interface StreamingServiceConfig {
183
+ shouldRetry?: (retries: number) => boolean;
184
+ maxReconnectAttempts?: number;
185
+ onConnecting?: () => void;
186
+ onOpened?: () => void;
187
+ onClosed?: () => void;
188
+ onError?: (error: any) => void;
189
+ }
190
+ /**
191
+ * Stream subscription options
192
+ */
193
+ export interface StreamSubscriptionOptions<T = Array<object>> {
194
+ next: (payload: T) => void;
195
+ error?: (error: any) => void;
196
+ complete?: () => void;
197
+ }
198
+ /**
199
+ * Unsubscribe function type
200
+ */
201
+ export type UnsubscribeFunction = () => void;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@covalenthq/client-sdk",
3
- "version": "2.2.6",
3
+ "version": "2.3.1",
4
4
  "license": "Apache-2.0",
5
5
  "repository": {
6
6
  "type": "git",
@@ -15,7 +15,8 @@
15
15
  },
16
16
  "homepage": "https://github.com/covalenthq/covalent-api-sdk-ts#readme",
17
17
  "dependencies": {
18
- "big.js": "^6.2.1"
18
+ "big.js": "^6.2.1",
19
+ "graphql-ws": "^6.0.5"
19
20
  },
20
21
  "devDependencies": {
21
22
  "@rollup/plugin-commonjs": "^25.0.4",
@@ -25,6 +26,7 @@
25
26
  "@types/big.js": "^6.2.2",
26
27
  "@types/jest": "^29.5.5",
27
28
  "@types/node": "^20",
29
+ "@types/ws": "^8.18.1",
28
30
  "@typescript-eslint/eslint-plugin": "^7.7.1",
29
31
  "@typescript-eslint/parser": "^7.7.1",
30
32
  "dotenv": "^16.4.5",
@@ -39,7 +41,8 @@
39
41
  "rollup-plugin-typescript2": "^0.35.0",
40
42
  "ts-jest": "^29.1.1",
41
43
  "ts-node": "^10.9.2",
42
- "typescript": "^5"
44
+ "typescript": "^5",
45
+ "ws": "^8.18.2"
43
46
  },
44
47
  "scripts": {
45
48
  "test": "jest",