@gala-chain/launchpad-sdk 4.0.3 → 4.0.4-beta.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.
- package/EXAMPLES.md +96 -35
- package/README.md +2 -0
- package/dist/index.cjs.js +1 -1
- package/dist/index.esm.js +1 -1
- package/dist/index.js +1 -1
- package/dist/src/LaunchpadSDK.d.ts +750 -72
- package/dist/src/LaunchpadSDK.d.ts.map +1 -1
- package/dist/src/constants/version.generated.d.ts +1 -1
- package/dist/src/constants/version.generated.d.ts.map +1 -1
- package/dist/src/services/DexBackendClient.d.ts +139 -10
- package/dist/src/services/DexBackendClient.d.ts.map +1 -1
- package/dist/src/services/DexQuoteService.d.ts +181 -22
- package/dist/src/services/DexQuoteService.d.ts.map +1 -1
- package/dist/src/services/DexService.d.ts +274 -38
- package/dist/src/services/DexService.d.ts.map +1 -1
- package/dist/src/services/GSwapService.d.ts +555 -246
- package/dist/src/services/GSwapService.d.ts.map +1 -1
- package/dist/src/services/GalaChainGatewayClient.d.ts +139 -41
- package/dist/src/services/GalaChainGatewayClient.d.ts.map +1 -1
- package/dist/src/services/ImageService.d.ts +101 -12
- package/dist/src/services/ImageService.d.ts.map +1 -1
- package/dist/src/services/PoolCacheManager.d.ts +125 -31
- package/dist/src/services/PoolCacheManager.d.ts.map +1 -1
- package/dist/src/services/SignatureService.d.ts +35 -5
- package/dist/src/services/SignatureService.d.ts.map +1 -1
- package/dist/src/services/SwapEventQueue.d.ts +79 -10
- package/dist/src/services/SwapEventQueue.d.ts.map +1 -1
- package/dist/src/services/TokenClassKeyService.d.ts +56 -10
- package/dist/src/services/TokenClassKeyService.d.ts.map +1 -1
- package/dist/src/services/TokenMetadataService.d.ts +407 -31
- package/dist/src/services/TokenMetadataService.d.ts.map +1 -1
- package/dist/src/services/TradeService.d.ts +168 -6
- package/dist/src/services/TradeService.d.ts.map +1 -1
- package/dist/src/services/UserService.d.ts +117 -15
- package/dist/src/services/UserService.d.ts.map +1 -1
- package/package.json +12 -2
- package/API.md +0 -1475
|
@@ -1,15 +1,81 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* TokenMetadataService -
|
|
2
|
+
* TokenMetadataService - Authoritative Token Metadata Resolution
|
|
3
3
|
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
4
|
+
* Provides verified token metadata from GalaChain blockchain, including symbols,
|
|
5
|
+
* decimals, supply caps, and verification status. Uses time-based caching to
|
|
6
|
+
* minimize network calls while ensuring data freshness.
|
|
7
7
|
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
* -
|
|
12
|
-
* -
|
|
8
|
+
* ## Core Responsibility
|
|
9
|
+
*
|
|
10
|
+
* Fetch REAL token metadata from blockchain, never infer from strings:
|
|
11
|
+
* - **Symbol**: Official ticker (ANIME, GDOG, GALA)
|
|
12
|
+
* - **Decimals**: Precision (8 or 18 typically)
|
|
13
|
+
* - **Max Supply**: Token supply cap
|
|
14
|
+
* - **Verification**: Gala verification status
|
|
15
|
+
* - **Name**: Full token name
|
|
16
|
+
*
|
|
17
|
+
* ## Why This Matters
|
|
18
|
+
*
|
|
19
|
+
* **❌ WRONG: Inferring from format strings**
|
|
20
|
+
* ```typescript
|
|
21
|
+
* // DON'T DO THIS
|
|
22
|
+
* const symbol = tokenString.split('|')[2]; // Unreliable!
|
|
23
|
+
* const decimals = 18; // Guessing!
|
|
24
|
+
* ```
|
|
25
|
+
*
|
|
26
|
+
* **✅ CORRECT: Query blockchain**
|
|
27
|
+
* ```typescript
|
|
28
|
+
* // DO THIS
|
|
29
|
+
* const metadata = await tokenMetadataService.resolveTokenMetadata('anime');
|
|
30
|
+
* const symbol = metadata.symbol; // "ANIME" (verified from chain)
|
|
31
|
+
* const decimals = metadata.decimals; // 8 (actual value from chain)
|
|
32
|
+
* ```
|
|
33
|
+
*
|
|
34
|
+
* ## Metadata Immutability
|
|
35
|
+
*
|
|
36
|
+
* **Critical Blockchain Property:**
|
|
37
|
+
* - Token metadata CANNOT be changed after creation
|
|
38
|
+
* - Maximizes trust and predictability
|
|
39
|
+
* - Enables aggressive caching (default 1 hour TTL)
|
|
40
|
+
* - Symbol, decimals, maxSupply are permanent
|
|
41
|
+
*
|
|
42
|
+
* ## Caching Strategy
|
|
43
|
+
*
|
|
44
|
+
* **Time-Based Expiry (default 1 hour):**
|
|
45
|
+
* - First request: Fetch from blockchain (~100ms)
|
|
46
|
+
* - Cached requests: In-memory read (~1ms)
|
|
47
|
+
* - Auto-refresh after TTL expires
|
|
48
|
+
* - Manual cache clearing available
|
|
49
|
+
*
|
|
50
|
+
* **Why Not Permanent Cache:**
|
|
51
|
+
* - New tokens may be created
|
|
52
|
+
* - Verification status can change
|
|
53
|
+
* - Conservative approach for safety
|
|
54
|
+
* - Configurable TTL for different use cases
|
|
55
|
+
*
|
|
56
|
+
* ## Decimals Importance
|
|
57
|
+
*
|
|
58
|
+
* **Amount Formatting:**
|
|
59
|
+
* ```typescript
|
|
60
|
+
* // On-chain amount: "100000000" (8 decimals)
|
|
61
|
+
* // User-friendly: "1.00" tokens
|
|
62
|
+
* // Conversion: amount / 10^decimals
|
|
63
|
+
*
|
|
64
|
+
* const metadata = await service.resolveTokenMetadata('anime');
|
|
65
|
+
* const onChainAmount = "100000000";
|
|
66
|
+
* const userAmount = Number(onChainAmount) / Math.pow(10, metadata.decimals);
|
|
67
|
+
* console.log(userAmount); // 1.0
|
|
68
|
+
* ```
|
|
69
|
+
*
|
|
70
|
+
* **Common Decimal Values:**
|
|
71
|
+
* - GALA: 8 decimals (Bitcoin-style precision)
|
|
72
|
+
* - GUSDC: 6 decimals (matches USDC standard)
|
|
73
|
+
* - WETH: 18 decimals (Ethereum standard)
|
|
74
|
+
* - Launchpad tokens: 8 decimals (default)
|
|
75
|
+
*
|
|
76
|
+
* @packageDocumentation
|
|
77
|
+
* @category Services
|
|
78
|
+
* @since 3.0.0
|
|
13
79
|
*/
|
|
14
80
|
import { LoggerBase } from './BaseService';
|
|
15
81
|
import type { TokenClass } from '../types/gswap.dto';
|
|
@@ -34,45 +100,292 @@ export declare class TokenMetadataService extends LoggerBase {
|
|
|
34
100
|
private cacheExpiry;
|
|
35
101
|
constructor(debugMode?: boolean);
|
|
36
102
|
/**
|
|
37
|
-
* Resolve token metadata from
|
|
103
|
+
* Resolve token metadata from GalaChain blockchain
|
|
104
|
+
*
|
|
105
|
+
* Queries GalaChain for authoritative token metadata including symbol, decimals,
|
|
106
|
+
* supply cap, and verification status. Uses time-based caching (default 1 hour)
|
|
107
|
+
* to minimize network calls while ensuring data freshness.
|
|
108
|
+
*
|
|
109
|
+
* ## Supported Input Formats
|
|
110
|
+
*
|
|
111
|
+
* **Simple Symbol:**
|
|
112
|
+
* ```typescript
|
|
113
|
+
* await service.resolveTokenMetadata('GALA');
|
|
114
|
+
* await service.resolveTokenMetadata('anime');
|
|
115
|
+
* ```
|
|
116
|
+
*
|
|
117
|
+
* **Full Format String:**
|
|
118
|
+
* ```typescript
|
|
119
|
+
* await service.resolveTokenMetadata('GALA|Unit|none|none');
|
|
120
|
+
* await service.resolveTokenMetadata('Token|Unit|ANIME|eth:0x...');
|
|
121
|
+
* ```
|
|
122
|
+
*
|
|
123
|
+
* **TokenClass Object:**
|
|
124
|
+
* ```typescript
|
|
125
|
+
* await service.resolveTokenMetadata({
|
|
126
|
+
* collection: 'Token',
|
|
127
|
+
* category: 'Unit',
|
|
128
|
+
* type: 'ANIME',
|
|
129
|
+
* additionalKey: 'eth:0x...'
|
|
130
|
+
* });
|
|
131
|
+
* ```
|
|
132
|
+
*
|
|
133
|
+
* ## Return Value
|
|
38
134
|
*
|
|
39
|
-
*
|
|
40
|
-
*
|
|
41
|
-
*
|
|
42
|
-
*
|
|
43
|
-
*
|
|
135
|
+
* ```typescript
|
|
136
|
+
* {
|
|
137
|
+
* symbol: "ANIME", // Official ticker
|
|
138
|
+
* decimals: 8, // Precision
|
|
139
|
+
* name: "Anime Token", // Full name
|
|
140
|
+
* maxSupply: "1000000000",// Supply cap
|
|
141
|
+
* verified: true, // Gala verification
|
|
142
|
+
* collection: "Token",
|
|
143
|
+
* category: "Unit",
|
|
144
|
+
* type: "ANIME",
|
|
145
|
+
* additionalKey: "eth:0x..."
|
|
146
|
+
* }
|
|
147
|
+
* ```
|
|
44
148
|
*
|
|
45
|
-
*
|
|
46
|
-
*
|
|
149
|
+
* ## Caching Behavior
|
|
150
|
+
*
|
|
151
|
+
* - **First request**: Fetch from blockchain (~100ms)
|
|
152
|
+
* - **Cached requests**: In-memory read (~1ms)
|
|
153
|
+
* - **Cache expiry**: 1 hour (configurable)
|
|
154
|
+
* - **Auto-refresh**: After TTL expires
|
|
155
|
+
*
|
|
156
|
+
* ## Why Use This vs String Parsing
|
|
157
|
+
*
|
|
158
|
+
* **❌ WRONG: Inferring from strings**
|
|
159
|
+
* ```typescript
|
|
160
|
+
* // Unreliable and error-prone!
|
|
161
|
+
* const parts = tokenString.split('|');
|
|
162
|
+
* const symbol = parts[2]; // Might be wrong!
|
|
163
|
+
* const decimals = 18; // Guessing!
|
|
164
|
+
* ```
|
|
165
|
+
*
|
|
166
|
+
* **✅ CORRECT: Query blockchain**
|
|
167
|
+
* ```typescript
|
|
168
|
+
* // Verified and accurate!
|
|
169
|
+
* const metadata = await service.resolveTokenMetadata('anime');
|
|
170
|
+
* const symbol = metadata.symbol; // "ANIME" (from chain)
|
|
171
|
+
* const decimals = metadata.decimals; // 8 (from chain)
|
|
172
|
+
* ```
|
|
47
173
|
*
|
|
48
174
|
* @param token Token reference (symbol, format string, or TokenClass object)
|
|
49
|
-
* @returns
|
|
175
|
+
* @returns Verified token metadata from blockchain
|
|
176
|
+
*
|
|
177
|
+
* @example
|
|
178
|
+
* ```typescript
|
|
179
|
+
* // Resolve by symbol
|
|
180
|
+
* const metadata = await service.resolveTokenMetadata('anime');
|
|
181
|
+
* console.log('Symbol:', metadata.symbol); // "ANIME"
|
|
182
|
+
* console.log('Decimals:', metadata.decimals); // 8
|
|
183
|
+
*
|
|
184
|
+
* // Format on-chain amount for display
|
|
185
|
+
* const onChainAmount = "100000000"; // 8 zeros
|
|
186
|
+
* const userAmount = Number(onChainAmount) / Math.pow(10, metadata.decimals);
|
|
187
|
+
* console.log('User amount:', userAmount); // 1.0
|
|
188
|
+
* ```
|
|
189
|
+
*
|
|
190
|
+
* @category Metadata Resolution
|
|
191
|
+
* @since 3.0.0
|
|
50
192
|
*/
|
|
51
193
|
resolveTokenMetadata(token: string | TokenClass): Promise<TokenMetadata>;
|
|
52
194
|
/**
|
|
53
|
-
* Get symbol
|
|
195
|
+
* Get token symbol from blockchain
|
|
196
|
+
*
|
|
197
|
+
* Convenience method that resolves full metadata and returns only the symbol.
|
|
198
|
+
* Uses the same caching as `resolveTokenMetadata()`.
|
|
199
|
+
*
|
|
200
|
+
* ## Why This Matters
|
|
201
|
+
*
|
|
202
|
+
* **✅ CORRECT approach (this method):**
|
|
203
|
+
* ```typescript
|
|
204
|
+
* const symbol = await service.getTokenSymbol('anime');
|
|
205
|
+
* console.log(symbol); // "ANIME" (verified from chain)
|
|
206
|
+
* ```
|
|
54
207
|
*
|
|
55
|
-
*
|
|
56
|
-
*
|
|
57
|
-
*
|
|
208
|
+
* **❌ WRONG approach (string parsing):**
|
|
209
|
+
* ```typescript
|
|
210
|
+
* const parts = tokenString.split('|');
|
|
211
|
+
* const symbol = parts[2]; // Unreliable! Might be type, not symbol!
|
|
212
|
+
* ```
|
|
58
213
|
*
|
|
59
|
-
*
|
|
60
|
-
*
|
|
214
|
+
* ## Symbol Use Cases
|
|
215
|
+
*
|
|
216
|
+
* - Display token ticker in UI
|
|
217
|
+
* - Trading pair notation (ANIME/GALA)
|
|
218
|
+
* - Portfolio listings
|
|
219
|
+
* - Search and filtering
|
|
220
|
+
*
|
|
221
|
+
* @param token Token reference (symbol, format string, or TokenClass)
|
|
222
|
+
* @returns Official token symbol from blockchain
|
|
223
|
+
*
|
|
224
|
+
* @example
|
|
225
|
+
* ```typescript
|
|
226
|
+
* const symbol = await service.getTokenSymbol('anime');
|
|
227
|
+
* console.log(`Trading ${symbol}/GALA`); // "Trading ANIME/GALA"
|
|
228
|
+
* ```
|
|
229
|
+
*
|
|
230
|
+
* @category Metadata Resolution
|
|
231
|
+
* @since 3.0.0
|
|
61
232
|
*/
|
|
62
233
|
getTokenSymbol(token: string | TokenClass): Promise<string>;
|
|
63
234
|
/**
|
|
64
|
-
* Get decimals
|
|
235
|
+
* Get token decimals from blockchain
|
|
236
|
+
*
|
|
237
|
+
* Convenience method that resolves full metadata and returns only the decimals.
|
|
238
|
+
* Critical for amount formatting and on-chain → user-friendly conversions.
|
|
239
|
+
*
|
|
240
|
+
* ## Decimals Usage
|
|
241
|
+
*
|
|
242
|
+
* **Amount Conversion:**
|
|
243
|
+
* ```typescript
|
|
244
|
+
* const decimals = await service.getTokenDecimals('anime');
|
|
245
|
+
* const onChainAmount = "100000000"; // 8 zeros
|
|
246
|
+
* const userAmount = Number(onChainAmount) / Math.pow(10, decimals);
|
|
247
|
+
* console.log(userAmount); // 1.0
|
|
248
|
+
* ```
|
|
249
|
+
*
|
|
250
|
+
* **Common Decimal Values:**
|
|
251
|
+
* - GALA: 8 decimals (Bitcoin-style)
|
|
252
|
+
* - GUSDC: 6 decimals (USDC standard)
|
|
253
|
+
* - WETH: 18 decimals (Ethereum standard)
|
|
254
|
+
* - Launchpad tokens: 8 decimals (default)
|
|
255
|
+
*
|
|
256
|
+
* ## Why Decimals Matter
|
|
257
|
+
*
|
|
258
|
+
* **Display Accuracy:**
|
|
259
|
+
* - 8 decimals: Can show 0.00000001 precision
|
|
260
|
+
* - 18 decimals: Can show 0.000000000000000001 precision
|
|
261
|
+
* - Wrong decimals = wrong amounts shown to users
|
|
65
262
|
*
|
|
66
|
-
*
|
|
67
|
-
*
|
|
263
|
+
* **Trading Precision:**
|
|
264
|
+
* - On-chain amounts are integers (no floating point)
|
|
265
|
+
* - Decimals define the scaling factor
|
|
266
|
+
* - 1 token = 10^decimals smallest units
|
|
267
|
+
*
|
|
268
|
+
* @param token Token reference (symbol, format string, or TokenClass)
|
|
269
|
+
* @returns Token decimal precision from blockchain
|
|
270
|
+
*
|
|
271
|
+
* @example
|
|
272
|
+
* ```typescript
|
|
273
|
+
* // Get decimals for amount formatting
|
|
274
|
+
* const decimals = await service.getTokenDecimals('anime');
|
|
275
|
+
* console.log('Decimals:', decimals); // 8
|
|
276
|
+
*
|
|
277
|
+
* // Convert on-chain to user-friendly
|
|
278
|
+
* function formatAmount(onChainAmount: string, decimals: number): string {
|
|
279
|
+
* const amount = Number(onChainAmount) / Math.pow(10, decimals);
|
|
280
|
+
* return amount.toFixed(decimals);
|
|
281
|
+
* }
|
|
282
|
+
*
|
|
283
|
+
* const formatted = formatAmount("100000000", decimals);
|
|
284
|
+
* console.log(formatted); // "1.00000000"
|
|
285
|
+
* ```
|
|
286
|
+
*
|
|
287
|
+
* @category Metadata Resolution
|
|
288
|
+
* @since 3.0.0
|
|
68
289
|
*/
|
|
69
290
|
getTokenDecimals(token: string | TokenClass): Promise<number>;
|
|
70
291
|
/**
|
|
71
|
-
* Clear cache to force fresh queries
|
|
292
|
+
* Clear metadata cache to force fresh blockchain queries
|
|
293
|
+
*
|
|
294
|
+
* Removes cached metadata entries. Can clear entire cache or a specific token.
|
|
295
|
+
* Next request for cleared tokens will fetch fresh data from blockchain.
|
|
296
|
+
*
|
|
297
|
+
* ## Use Cases
|
|
298
|
+
*
|
|
299
|
+
* **Clear All:**
|
|
300
|
+
* - Testing scenarios (fresh state)
|
|
301
|
+
* - Memory management (rare)
|
|
302
|
+
* - Major blockchain upgrade events
|
|
303
|
+
*
|
|
304
|
+
* **Clear Specific:**
|
|
305
|
+
* - Token verification status changed
|
|
306
|
+
* - Suspected stale data
|
|
307
|
+
* - Debugging metadata issues
|
|
308
|
+
*
|
|
309
|
+
* ## When NOT to Clear
|
|
310
|
+
*
|
|
311
|
+
* **Metadata is immutable:**
|
|
312
|
+
* - Symbol never changes
|
|
313
|
+
* - Decimals never change
|
|
314
|
+
* - Max supply never changes
|
|
315
|
+
* - Cache clearing rarely needed
|
|
316
|
+
*
|
|
317
|
+
* **Performance impact:**
|
|
318
|
+
* - Next request requires blockchain call (~100ms)
|
|
319
|
+
* - Only clear if absolutely necessary
|
|
320
|
+
*
|
|
321
|
+
* @param tokenKey Optional token key to clear (clears all if omitted)
|
|
322
|
+
*
|
|
323
|
+
* @example
|
|
324
|
+
* ```typescript
|
|
325
|
+
* // Clear entire cache
|
|
326
|
+
* service.clearCache();
|
|
327
|
+
* console.log('All metadata cache cleared');
|
|
328
|
+
*
|
|
329
|
+
* // Clear specific token
|
|
330
|
+
* service.clearCache('anime');
|
|
331
|
+
* console.log('Cleared cache for anime token');
|
|
332
|
+
* ```
|
|
333
|
+
*
|
|
334
|
+
* @category Cache Management
|
|
335
|
+
* @since 3.0.0
|
|
72
336
|
*/
|
|
73
337
|
clearCache(tokenKey?: string): void;
|
|
74
338
|
/**
|
|
75
|
-
* Get cache statistics
|
|
339
|
+
* Get cache statistics for monitoring and debugging
|
|
340
|
+
*
|
|
341
|
+
* Returns cache metrics including size and all cached token keys.
|
|
342
|
+
* Useful for monitoring cache health and verifying cache behavior.
|
|
343
|
+
*
|
|
344
|
+
* ## Metrics Provided
|
|
345
|
+
*
|
|
346
|
+
* - **size**: Number of cached tokens
|
|
347
|
+
* - **entries**: Array of all cached token keys
|
|
348
|
+
*
|
|
349
|
+
* ## Use Cases
|
|
350
|
+
*
|
|
351
|
+
* **Cache Monitoring:**
|
|
352
|
+
* ```typescript
|
|
353
|
+
* const stats = service.getCacheStats();
|
|
354
|
+
* console.log(`Cache size: ${stats.size} tokens`);
|
|
355
|
+
* console.log(`Memory: ~${stats.size * 0.5}KB`); // Rough estimate
|
|
356
|
+
* ```
|
|
357
|
+
*
|
|
358
|
+
* **Cache Health:**
|
|
359
|
+
* ```typescript
|
|
360
|
+
* // Monitor cache growth
|
|
361
|
+
* setInterval(() => {
|
|
362
|
+
* const stats = service.getCacheStats();
|
|
363
|
+
* if (stats.size > 500) {
|
|
364
|
+
* console.warn('Large metadata cache, consider clearing');
|
|
365
|
+
* }
|
|
366
|
+
* }, 300000); // Every 5 minutes
|
|
367
|
+
* ```
|
|
368
|
+
*
|
|
369
|
+
* **Debugging:**
|
|
370
|
+
* ```typescript
|
|
371
|
+
* const stats = service.getCacheStats();
|
|
372
|
+
* console.log('Cached tokens:', stats.entries);
|
|
373
|
+
* const hasAnime = stats.entries.includes('anime');
|
|
374
|
+
* console.log('Anime cached:', hasAnime);
|
|
375
|
+
* ```
|
|
376
|
+
*
|
|
377
|
+
* @returns Cache statistics with size and entry keys
|
|
378
|
+
*
|
|
379
|
+
* @example
|
|
380
|
+
* ```typescript
|
|
381
|
+
* const stats = service.getCacheStats();
|
|
382
|
+
* console.log('Cache size:', stats.size);
|
|
383
|
+
* console.log('Cached tokens:', stats.entries.join(', '));
|
|
384
|
+
* // Output: "anime, gala, gusdc"
|
|
385
|
+
* ```
|
|
386
|
+
*
|
|
387
|
+
* @category Cache Management
|
|
388
|
+
* @since 3.0.0
|
|
76
389
|
*/
|
|
77
390
|
getCacheStats(): {
|
|
78
391
|
size: number;
|
|
@@ -105,8 +418,71 @@ export declare class TokenMetadataService extends LoggerBase {
|
|
|
105
418
|
*/
|
|
106
419
|
private isCacheExpired;
|
|
107
420
|
/**
|
|
108
|
-
* Set cache expiry duration
|
|
109
|
-
*
|
|
421
|
+
* Set cache expiry duration (time-to-live)
|
|
422
|
+
*
|
|
423
|
+
* Configures how long metadata remains cached before requiring refresh.
|
|
424
|
+
* Default is 1 hour (3,600,000ms). Adjust based on your application's
|
|
425
|
+
* requirements for data freshness vs. performance.
|
|
426
|
+
*
|
|
427
|
+
* ## Recommended TTL Values
|
|
428
|
+
*
|
|
429
|
+
* **Conservative (1 hour - default):**
|
|
430
|
+
* ```typescript
|
|
431
|
+
* service.setCacheExpiry(3600000); // 1 hour
|
|
432
|
+
* // Good balance of freshness and performance
|
|
433
|
+
* // Suitable for most applications
|
|
434
|
+
* ```
|
|
435
|
+
*
|
|
436
|
+
* **Aggressive (1 day):**
|
|
437
|
+
* ```typescript
|
|
438
|
+
* service.setCacheExpiry(86400000); // 24 hours
|
|
439
|
+
* // Maximum performance, minimal refreshes
|
|
440
|
+
* // Safe because metadata is immutable
|
|
441
|
+
* // Best for production apps
|
|
442
|
+
* ```
|
|
443
|
+
*
|
|
444
|
+
* **Fresh (5 minutes):**
|
|
445
|
+
* ```typescript
|
|
446
|
+
* service.setCacheExpiry(300000); // 5 minutes
|
|
447
|
+
* // Frequent refreshes for changing data
|
|
448
|
+
* // Use if verification status updates frequently
|
|
449
|
+
* ```
|
|
450
|
+
*
|
|
451
|
+
* **No Cache (for testing):**
|
|
452
|
+
* ```typescript
|
|
453
|
+
* service.setCacheExpiry(0); // Immediate expiry
|
|
454
|
+
* // Every request fetches from blockchain
|
|
455
|
+
* // Only use for testing/debugging
|
|
456
|
+
* ```
|
|
457
|
+
*
|
|
458
|
+
* ## Trade-offs
|
|
459
|
+
*
|
|
460
|
+
* **Longer TTL (hours/days):**
|
|
461
|
+
* - Pros: Better performance, fewer API calls
|
|
462
|
+
* - Cons: Slightly stale data (verification status)
|
|
463
|
+
* - Safe: Core metadata (symbol, decimals) never changes
|
|
464
|
+
*
|
|
465
|
+
* **Shorter TTL (minutes):**
|
|
466
|
+
* - Pros: Fresher data, catches status changes
|
|
467
|
+
* - Cons: More API calls, higher latency
|
|
468
|
+
* - Rare benefit: Metadata rarely changes
|
|
469
|
+
*
|
|
470
|
+
* @param ms Cache expiry in milliseconds (default: 3600000 = 1 hour)
|
|
471
|
+
*
|
|
472
|
+
* @example
|
|
473
|
+
* ```typescript
|
|
474
|
+
* // Production: Long cache (metadata immutable)
|
|
475
|
+
* service.setCacheExpiry(86400000); // 24 hours
|
|
476
|
+
*
|
|
477
|
+
* // Development: Short cache (debugging)
|
|
478
|
+
* service.setCacheExpiry(60000); // 1 minute
|
|
479
|
+
*
|
|
480
|
+
* // Testing: No cache
|
|
481
|
+
* service.setCacheExpiry(0); // Immediate expiry
|
|
482
|
+
* ```
|
|
483
|
+
*
|
|
484
|
+
* @category Cache Management
|
|
485
|
+
* @since 3.0.0
|
|
110
486
|
*/
|
|
111
487
|
setCacheExpiry(ms: number): void;
|
|
112
488
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TokenMetadataService.d.ts","sourceRoot":"","sources":["../../../src/services/TokenMetadataService.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"TokenMetadataService.d.ts","sourceRoot":"","sources":["../../../src/services/TokenMetadataService.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8EG;AAEH,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAC3C,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAErD,MAAM,WAAW,aAAa;IAC5B,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,QAAQ,EAAE,MAAM,CAAC;IACjB,UAAU,EAAE,MAAM,CAAC;IACnB,QAAQ,EAAE,MAAM,CAAC;IACjB,IAAI,EAAE,MAAM,CAAC;IACb,aAAa,EAAE,MAAM,CAAC;IACtB,QAAQ,EAAE,OAAO,CAAC;CACnB;AAED,MAAM,WAAW,kBAAkB;IACjC,CAAC,GAAG,EAAE,MAAM,GAAG;QACb,IAAI,EAAE,aAAa,CAAC;QACpB,SAAS,EAAE,MAAM,CAAC;KACnB,CAAC;CACH;AAED,qBAAa,oBAAqB,SAAQ,UAAU;IAClD,OAAO,CAAC,KAAK,CAA0B;IACvC,OAAO,CAAC,WAAW,CAAmB;gBAE1B,SAAS,GAAE,OAAe;IAItC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OA0FG;IACG,oBAAoB,CAAC,KAAK,EAAE,MAAM,GAAG,UAAU,GAAG,OAAO,CAAC,aAAa,CAAC;IAyB9E;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OAsCG;IACG,cAAc,CAAC,KAAK,EAAE,MAAM,GAAG,UAAU,GAAG,OAAO,CAAC,MAAM,CAAC;IAKjE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OAuDG;IACG,gBAAgB,CAAC,KAAK,EAAE,MAAM,GAAG,UAAU,GAAG,OAAO,CAAC,MAAM,CAAC;IAKnE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OA6CG;IACH,UAAU,CAAC,QAAQ,CAAC,EAAE,MAAM,GAAG,IAAI;IAUnC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OAmDG;IACH,aAAa,IAAI;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,OAAO,EAAE,MAAM,EAAE,CAAA;KAAE;IAQpD;;;OAGG;IAEH,OAAO,CAAC,WAAW;IAYnB;;;;;;;OAOG;IAEH,OAAO,CAAC,eAAe;IAyDvB;;;;;OAKG;IACH,OAAO,CAAC,mBAAmB;IAa3B;;;OAGG;IACH,OAAO,CAAC,cAAc;IAItB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OAkEG;IACH,cAAc,CAAC,EAAE,EAAE,MAAM,GAAG,IAAI;CAIjC"}
|
|
@@ -16,33 +16,195 @@ import { FetchTradesOptions } from '../types/options.dto';
|
|
|
16
16
|
* Provides methods for:
|
|
17
17
|
* - Fetching trade history with pagination
|
|
18
18
|
* - Filtering trades by token, user, type, date range
|
|
19
|
+
* - Trade statistics and analysis
|
|
20
|
+
* - Buy/sell volume tracking
|
|
19
21
|
*
|
|
20
|
-
* @
|
|
22
|
+
* @category Services
|
|
23
|
+
* @since 3.6.0
|
|
24
|
+
*
|
|
25
|
+
* @example Basic trade history
|
|
21
26
|
* ```typescript
|
|
22
27
|
* const tradeService = new TradeService(httpClient);
|
|
23
28
|
*
|
|
24
29
|
* // Get first page of trades for a token
|
|
25
|
-
* const trades = await tradeService.fetchTrades({ tokenName: "
|
|
30
|
+
* const trades = await tradeService.fetchTrades({ tokenName: "anime" });
|
|
31
|
+
* console.log(`Found ${trades.totalResults} trades across ${trades.totalPages} pages`);
|
|
32
|
+
* ```
|
|
26
33
|
*
|
|
34
|
+
* @example Paginated trade fetching
|
|
35
|
+
* ```typescript
|
|
27
36
|
* // Get specific page with custom limit
|
|
28
37
|
* const moreTrades = await tradeService.fetchTrades({
|
|
29
|
-
* tokenName: "
|
|
38
|
+
* tokenName: "GDOG",
|
|
30
39
|
* page: 2,
|
|
31
40
|
* limit: 20
|
|
32
41
|
* });
|
|
42
|
+
*
|
|
43
|
+
* // Process trades
|
|
44
|
+
* moreTrades.trades.forEach(trade => {
|
|
45
|
+
* console.log(`${trade.type}: ${trade.amount} at ${trade.price}`);
|
|
46
|
+
* });
|
|
47
|
+
* ```
|
|
48
|
+
*
|
|
49
|
+
* @example Filter by trade type
|
|
50
|
+
* ```typescript
|
|
51
|
+
* // Get only buy trades
|
|
52
|
+
* const buys = await tradeService.fetchTrades({
|
|
53
|
+
* tokenName: "GUSDC",
|
|
54
|
+
* tradeType: "buy",
|
|
55
|
+
* limit: 50
|
|
56
|
+
* });
|
|
57
|
+
*
|
|
58
|
+
* // Calculate total buy volume
|
|
59
|
+
* const totalBuyVolume = buys.trades.reduce((sum, t) => sum + parseFloat(t.amount), 0);
|
|
33
60
|
* ```
|
|
34
61
|
*/
|
|
35
62
|
export declare class TradeService extends BaseService {
|
|
63
|
+
/**
|
|
64
|
+
* Creates a TradeService instance
|
|
65
|
+
*
|
|
66
|
+
* @param http Configured HttpClient with authentication
|
|
67
|
+
* @param debugMode Enable debug logging (default: false)
|
|
68
|
+
*
|
|
69
|
+
* @example
|
|
70
|
+
* ```typescript
|
|
71
|
+
* const httpClient = new HttpClient(config);
|
|
72
|
+
* const tradeService = new TradeService(httpClient, true);
|
|
73
|
+
* ```
|
|
74
|
+
*/
|
|
36
75
|
constructor(http: HttpClient, debugMode?: boolean);
|
|
37
76
|
/**
|
|
38
77
|
* Gets trades for a token by its tokenName with pagination
|
|
39
78
|
*
|
|
79
|
+
* Fetches trade history for a specific token with comprehensive pagination
|
|
80
|
+
* support. Returns normalized trade data with metadata including price,
|
|
81
|
+
* amount, timestamp, and trader information.
|
|
82
|
+
*
|
|
40
83
|
* This method provides a clean, intuitive API for fetching token trades
|
|
41
|
-
* using the token name. Follows the same pattern as CommentAPI.
|
|
84
|
+
* using the token name. Follows the same pattern as CommentAPI for consistency.
|
|
85
|
+
*
|
|
86
|
+
* Response includes:
|
|
87
|
+
* - Trade details (type, amount, price, timestamp)
|
|
88
|
+
* - Trader addresses and wallet information
|
|
89
|
+
* - Transaction hashes for verification
|
|
90
|
+
* - Full pagination metadata (page, totalPages, hasNext, hasPrevious)
|
|
91
|
+
*
|
|
92
|
+
* Filtering options (optional):
|
|
93
|
+
* - tradeType: Filter by 'buy' or 'sell'
|
|
94
|
+
* - userAddress: Filter by specific trader
|
|
95
|
+
* - startDate/endDate: Filter by date range
|
|
96
|
+
* - sortOrder: Sort by timestamp (asc/desc)
|
|
42
97
|
*
|
|
43
98
|
* @param options Trade fetching options
|
|
44
|
-
* @
|
|
45
|
-
* @
|
|
99
|
+
* @param options.tokenName Token name to fetch trades for (required)
|
|
100
|
+
* @param options.page Page number (default: 1)
|
|
101
|
+
* @param options.limit Results per page (default: 10, max: 100)
|
|
102
|
+
* @param options.tradeType Filter by trade type ('buy' | 'sell')
|
|
103
|
+
* @param options.userAddress Filter by trader address
|
|
104
|
+
* @param options.startDate Filter by start date
|
|
105
|
+
* @param options.endDate Filter by end date
|
|
106
|
+
* @param options.sortOrder Sort order ('asc' | 'desc')
|
|
107
|
+
* @returns Promise resolving to trades with full pagination metadata
|
|
108
|
+
* @throws {ValidationError} If token name is invalid or empty
|
|
109
|
+
* @throws {ValidationError} If options object is invalid format
|
|
110
|
+
* @throws {ValidationError} If pagination parameters are invalid
|
|
111
|
+
* @throws {ValidationError} If no response from trade service
|
|
112
|
+
*
|
|
113
|
+
* @category Trade Operations
|
|
114
|
+
* @since 3.6.0
|
|
115
|
+
*
|
|
116
|
+
* @example Basic trade history
|
|
117
|
+
* ```typescript
|
|
118
|
+
* const result = await tradeService.fetchTrades({ tokenName: "anime" });
|
|
119
|
+
*
|
|
120
|
+
* console.log(`Page ${result.page} of ${result.totalPages}`);
|
|
121
|
+
* console.log(`Total trades: ${result.totalResults}`);
|
|
122
|
+
*
|
|
123
|
+
* result.trades.forEach(trade => {
|
|
124
|
+
* console.log(`${trade.type}: ${trade.amount} @ ${trade.price} GALA`);
|
|
125
|
+
* console.log(`Trader: ${trade.traderAddress}`);
|
|
126
|
+
* console.log(`Time: ${new Date(trade.timestamp).toLocaleString()}`);
|
|
127
|
+
* });
|
|
128
|
+
* ```
|
|
129
|
+
*
|
|
130
|
+
* @example Paginated trade fetching
|
|
131
|
+
* ```typescript
|
|
132
|
+
* const limit = 20;
|
|
133
|
+
* let page = 1;
|
|
134
|
+
* const allTrades = [];
|
|
135
|
+
*
|
|
136
|
+
* while (true) {
|
|
137
|
+
* const result = await tradeService.fetchTrades({
|
|
138
|
+
* tokenName: "GDOG",
|
|
139
|
+
* page,
|
|
140
|
+
* limit
|
|
141
|
+
* });
|
|
142
|
+
*
|
|
143
|
+
* allTrades.push(...result.trades);
|
|
144
|
+
* if (!result.hasNext) break;
|
|
145
|
+
* page++;
|
|
146
|
+
* }
|
|
147
|
+
*
|
|
148
|
+
* console.log(`Fetched ${allTrades.length} total trades`);
|
|
149
|
+
* ```
|
|
150
|
+
*
|
|
151
|
+
* @example Filter by trade type
|
|
152
|
+
* ```typescript
|
|
153
|
+
* // Get only buy trades
|
|
154
|
+
* const buys = await tradeService.fetchTrades({
|
|
155
|
+
* tokenName: "GUSDC",
|
|
156
|
+
* tradeType: "buy",
|
|
157
|
+
* limit: 50
|
|
158
|
+
* });
|
|
159
|
+
*
|
|
160
|
+
* // Calculate total buy volume
|
|
161
|
+
* const totalBuyVolume = buys.trades.reduce(
|
|
162
|
+
* (sum, trade) => sum + parseFloat(trade.amount),
|
|
163
|
+
* 0
|
|
164
|
+
* );
|
|
165
|
+
* console.log(`Total buy volume: ${totalBuyVolume} GUSDC`);
|
|
166
|
+
* ```
|
|
167
|
+
*
|
|
168
|
+
* @example Filter by date range
|
|
169
|
+
* ```typescript
|
|
170
|
+
* const startDate = new Date('2025-01-01');
|
|
171
|
+
* const endDate = new Date('2025-01-31');
|
|
172
|
+
*
|
|
173
|
+
* const januaryTrades = await tradeService.fetchTrades({
|
|
174
|
+
* tokenName: "anime",
|
|
175
|
+
* startDate,
|
|
176
|
+
* endDate,
|
|
177
|
+
* limit: 100
|
|
178
|
+
* });
|
|
179
|
+
*
|
|
180
|
+
* console.log(`January trades: ${januaryTrades.totalResults}`);
|
|
181
|
+
* ```
|
|
182
|
+
*
|
|
183
|
+
* @example Filter by user address
|
|
184
|
+
* ```typescript
|
|
185
|
+
* const userTrades = await tradeService.fetchTrades({
|
|
186
|
+
* tokenName: "GDOG",
|
|
187
|
+
* userAddress: "eth|0x123...",
|
|
188
|
+
* limit: 100
|
|
189
|
+
* });
|
|
190
|
+
*
|
|
191
|
+
* console.log(`User has ${userTrades.totalResults} trades`);
|
|
192
|
+
*
|
|
193
|
+
* // Calculate user P&L
|
|
194
|
+
* let totalSpent = 0;
|
|
195
|
+
* let totalReceived = 0;
|
|
196
|
+
*
|
|
197
|
+
* userTrades.trades.forEach(trade => {
|
|
198
|
+
* const value = parseFloat(trade.amount) * parseFloat(trade.price);
|
|
199
|
+
* if (trade.type === 'buy') {
|
|
200
|
+
* totalSpent += value;
|
|
201
|
+
* } else {
|
|
202
|
+
* totalReceived += value;
|
|
203
|
+
* }
|
|
204
|
+
* });
|
|
205
|
+
*
|
|
206
|
+
* console.log(`P&L: ${totalReceived - totalSpent} GALA`);
|
|
207
|
+
* ```
|
|
46
208
|
*/
|
|
47
209
|
fetchTrades(options: FetchTradesOptions): Promise<TradesResult>;
|
|
48
210
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TradeService.d.ts","sourceRoot":"","sources":["../../../src/services/TradeService.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAC5C,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAO3C,OAAO,EAEL,YAAY,EAEb,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAAE,kBAAkB,EAAwB,MAAM,sBAAsB,CAAC;AAEhF
|
|
1
|
+
{"version":3,"file":"TradeService.d.ts","sourceRoot":"","sources":["../../../src/services/TradeService.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAC5C,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAO3C,OAAO,EAEL,YAAY,EAEb,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAAE,kBAAkB,EAAwB,MAAM,sBAAsB,CAAC;AAEhF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgDG;AACH,qBAAa,YAAa,SAAQ,WAAW;IAC3C;;;;;;;;;;;OAWG;gBACS,IAAI,EAAE,UAAU,EAAE,SAAS,GAAE,OAAe;IAIxD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OAoIG;IACG,WAAW,CAAC,OAAO,EAAE,kBAAkB,GAAG,OAAO,CAAC,YAAY,CAAC;CA2DtE"}
|